feat: init

This commit is contained in:
2026-02-13 22:02:30 +01:00
commit 8f9ff830fb
16711 changed files with 3307340 additions and 0 deletions

View File

@@ -0,0 +1,18 @@
import type nodeDiagnosticsChannel from "node:diagnostics_channel";
export declare const getChannels: unknown;
export declare class Channel<
StoreType,
ContextType
> implements nodeDiagnosticsChannel.Channel<StoreType, ContextType> {
readonly __unenv__: true;
name: nodeDiagnosticsChannel.Channel["name"];
get hasSubscribers();
_subscribers: nodeDiagnosticsChannel.ChannelListener[];
constructor(name: nodeDiagnosticsChannel.Channel["name"]);
subscribe(onMessage: nodeDiagnosticsChannel.ChannelListener);
unsubscribe(onMessage: nodeDiagnosticsChannel.ChannelListener);
publish(message: unknown): void;
bindStore();
unbindStore();
runStores();
}

View File

@@ -0,0 +1,40 @@
import { createNotImplementedError } from "../../../_internal/utils.mjs";
const channels = {};
export const getChannels = () => channels;
export class Channel {
__unenv__ = true;
name;
get hasSubscribers() {
return this._subscribers.length > 0;
}
_subscribers;
constructor(name) {
this.name = name;
this._subscribers = [];
const channels = getChannels();
channels[name] = this;
}
subscribe(onMessage) {
this._subscribers.push(onMessage);
}
unsubscribe(onMessage) {
const index = this._subscribers.indexOf(onMessage);
if (index === -1) return false;
this._subscribers.splice(index, 1);
return true;
}
publish(message) {
for (const subscriber of this._subscribers) {
subscriber(message, this.name);
}
}
bindStore() {
throw createNotImplementedError("Channel.bindStore");
}
unbindStore() {
throw createNotImplementedError("Channel.unbindStore");
}
runStores() {
throw createNotImplementedError("Channel.runStores");
}
}

View File

@@ -0,0 +1,19 @@
import type nodeDagnosticsChannel from "node:diagnostics_channel";
import { Channel } from "./channel.mjs";
export declare class TracingChannel<
StoreType = unknown,
ContextType extends object = object
> implements nodeDagnosticsChannel.TracingChannel<StoreType, ContextType> {
readonly __unenv__: true;
asyncEnd: Channel<StoreType, ContextType>;
asyncStart: Channel<StoreType, ContextType>;
end: Channel<StoreType, ContextType>;
error: Channel<StoreType, ContextType>;
start: Channel<StoreType, ContextType>;
constructor(nameOrChannels: string | nodeDagnosticsChannel.TracingChannelCollection<StoreType, ContextType>);
subscribe(handlers: nodeDagnosticsChannel.TracingChannelSubscribers<ContextType>): void;
unsubscribe(handlers: nodeDagnosticsChannel.TracingChannelSubscribers<ContextType>): void;
traceSync();
tracePromise();
traceCallback();
}

View File

@@ -0,0 +1,48 @@
import { createNotImplementedError } from "../../../_internal/utils.mjs";
import { Channel } from "./channel.mjs";
export class TracingChannel {
__unenv__ = true;
asyncEnd = new Channel("asyncEnd");
asyncStart = new Channel("asyncStart");
end = new Channel("end");
error = new Channel("error");
start = new Channel("start");
constructor(nameOrChannels) {
if (typeof nameOrChannels === "string") {
this.asyncEnd = new Channel(`trace:${nameOrChannels}:asyncEnd`);
this.asyncStart = new Channel(`trace:${nameOrChannels}:asyncStart`);
this.end = new Channel(`trace:${nameOrChannels}:end`);
this.error = new Channel(`trace:${nameOrChannels}:error`);
this.start = new Channel(`trace:${nameOrChannels}:start`);
} else {
this.asyncStart = nameOrChannels.asyncStart;
this.asyncEnd = nameOrChannels.asyncEnd;
this.end = nameOrChannels.end;
this.error = nameOrChannels.error;
this.start = nameOrChannels.start;
}
}
subscribe(handlers) {
this.asyncEnd?.subscribe(handlers.asyncEnd);
this.asyncStart?.subscribe(handlers.asyncStart);
this.end?.subscribe(handlers.end);
this.error?.subscribe(handlers.error);
this.start?.subscribe(handlers.start);
}
unsubscribe(handlers) {
this.asyncEnd?.unsubscribe(handlers.asyncEnd);
this.asyncStart?.unsubscribe(handlers.asyncStart);
this.end?.unsubscribe(handlers.end);
this.error?.unsubscribe(handlers.error);
this.start?.unsubscribe(handlers.start);
}
traceSync() {
throw createNotImplementedError("TracingChannel.traceSync");
}
tracePromise() {
throw createNotImplementedError("TracingChannel.tracePromise");
}
traceCallback() {
throw createNotImplementedError("TracingChannel.traceCallback");
}
}