Files
bare-operating-system/packages/bare-os-seeder/kernel/lib/bare/bundles/bareDiagnosticsChannel.js
T
2026-04-04 01:20:57 -04:00

156 lines
6.4 KiB
JavaScript

var __bare_os_bundle_exports__ = (() => {
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __commonJS = (cb, mod) => function __require() {
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
};
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// ../../node_modules/bare-diagnostics-channel/index.js
var require_bare_diagnostics_channel = __commonJS({
"../../node_modules/bare-diagnostics-channel/index.js"(exports, module) {
var DiagnosticsChannel = class _DiagnosticsChannel {
static _channels = /* @__PURE__ */ new Map();
constructor(name) {
this._name = name;
this._subscribers = [];
_DiagnosticsChannel._channels.set(name, this);
}
get name() {
return this._name;
}
get hasSubscribers() {
return this._subscribers.length > 0;
}
subscribe(subscription) {
this._subscribers = [...this._subscribers, subscription];
}
unsubscribe(subscription) {
const i = this._subscribers.indexOf(subscription);
if (i === -1) return false;
this._subscribers = [
...this._subscribers.slice(0, i),
...this._subscribers.slice(i + 1)
];
return true;
}
publish(data) {
const subscribers = this._subscribers;
for (let i = 0, n = subscribers.length; i < n; i++) {
try {
subscribers[i](data, this._name);
} catch (err) {
setImmediate(() => {
throw err;
});
}
}
}
};
module.exports = exports = DiagnosticsChannel;
exports.Channel = DiagnosticsChannel;
function channel(name) {
const channel2 = DiagnosticsChannel._channels.get(name);
if (channel2 !== void 0) return channel2;
return new DiagnosticsChannel(name);
}
exports.channel = channel;
exports.subscribe = function subscribe(name, subscription) {
return channel(name).subscribe(subscription);
};
exports.unsubscribe = function unsubscribe(name, subscription) {
return channel(name).unsubscribe(subscription);
};
exports.hasSubscribers = function hasSubscribers(name) {
const channel2 = DiagnosticsChannel._channels.get(name);
if (channel2 === void 0) return false;
return channel2.hasSubscribers;
};
var TracingChannel = class {
constructor(nameOrChannels) {
if (typeof nameOrChannels === "string") {
this.start = channel(`tracing:${nameOrChannels}:start`);
this.end = channel(`tracing:${nameOrChannels}:end`);
this.error = channel(`tracing:${nameOrChannels}:error`);
} else {
this.start = nameOrChannels.start;
this.end = nameOrChannels.end;
this.error = nameOrChannels.error;
}
}
get hasSubscribers() {
return this.start.hasSubscribers || this.end.hasSubscribers || this.error.hasSubscribers;
}
subscribe(subscriptions) {
const events = ["start", "end", "error"];
for (const event of events) {
const subscription = subscriptions[event];
if (subscription) this[event].subscribe(subscription);
}
}
unsubscribe(subscriptions) {
const events = ["start", "end", "error"];
return events.reduce((done, event) => {
const subscription = subscriptions[event];
if (subscription) {
return this[event].unsubscribe(subscription) && done;
} else {
return done;
}
}, true);
}
traceSync(fn, context = {}, thisArg, ...args) {
try {
this.start.publish(context);
context.result = fn.call(thisArg, ...args);
return context.result;
} catch (err) {
context.error = err;
this.error.publish(context);
} finally {
this.end.publish(context);
}
}
};
function tracingChannel(nameOrChannels) {
return new TracingChannel(nameOrChannels);
}
exports.tracingChannel = tracingChannel;
}
});
// ../../bare-lib-entry-bareDiagnosticsChannel.js
var bare_lib_entry_bareDiagnosticsChannel_exports = {};
__export(bare_lib_entry_bareDiagnosticsChannel_exports, {
default: () => bare_lib_entry_bareDiagnosticsChannel_default
});
var import_bare_diagnostics_channel = __toESM(require_bare_diagnostics_channel());
var bare_lib_entry_bareDiagnosticsChannel_default = import_bare_diagnostics_channel.default;
return __toCommonJS(bare_lib_entry_bareDiagnosticsChannel_exports);
})();
;(function(){var g=globalThis;var s="__bare_os_stdlib__";g[s]=g[s]||{};var e=typeof __bare_os_bundle_exports__!=="undefined"?__bare_os_bundle_exports__:void 0;var v=e!=null&&typeof e==="object"&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e;g[s]["bareDiagnosticsChannel"]=v;})();