/** * Browser-compatible implementation of Node.js Channel. * * Each channel is its own object with its own subscribers. */ interface AsyncLocalStorageLike { run(store: T, callback: () => R): R; } type TransformFunction = (message: M) => S; type MessageFunction = (message: M, name: N) => void; declare class Channel { readonly name: N; private _subscribers; private _stores; constructor(name: N); get hasSubscribers(): boolean; subscribe(subscription: MessageFunction): void; unsubscribe(subscription: MessageFunction): boolean; bindStore(store: AsyncLocalStorageLike, transform?: TransformFunction): void; unbindStore(store: AsyncLocalStorageLike): boolean; publish(message: M): void; runStores any>(message: M, fn: F, thisArg?: ThisParameterType, ...args: Parameters): ReturnType; } /** * Get or create a channel by name. * Matches Node.js channel() API. */ declare function channel(name: string): Channel; declare function channel(name: symbol): Channel; /** * Check if a channel has subscribers. * Matches Node.js hasSubscribers() API. */ declare function hasSubscribers(name: string | symbol): boolean; /** * Browser-compatible implementation of Node.js TracingChannel. * * A TracingChannel is a composite of 5 individual channels: * - start: Published before sync operation * - end: Published after sync operation completes * - asyncStart: Published when async operation's promise starts resolving * - asyncEnd: Published when async operation's promise finishes resolving * - error: Published when operation throws/rejects */ interface Channels { readonly start?: Channel; readonly end?: Channel; readonly asyncStart?: Channel; readonly asyncEnd?: Channel; readonly error?: Channel; } interface ChannelHandlers { start?: (context: M, name: string) => void; end?: (context: M, name: string) => void; asyncStart?: (context: M, name: string) => void; asyncEnd?: (context: M, name: string) => void; error?: (context: M, name: string) => void; } declare class TracingChannel { #private; readonly start?: Channel; readonly end?: Channel; readonly asyncStart?: Channel; readonly asyncEnd?: Channel; readonly error?: Channel; constructor(nameOrChannels: string | Channels); get hasSubscribers(): boolean; subscribe(handlers: ChannelHandlers): void; unsubscribe(handlers: ChannelHandlers): boolean; traceSync any>(fn: F, message: M, thisArg?: ThisParameterType, ...args: Parameters): ReturnType; tracePromise any>(fn: F, message: M, thisArg?: ThisParameterType, ...args: Parameters): Promise>; traceCallback any>(fn: F, position: number | undefined, message: M, thisArg?: ThisParameterType, ...args: Parameters): ReturnType; } /** * dc-browser * * Browser-compatible polyfill for Node.js diagnostics_channel. * Matches the API from Node.js core exactly. */ /** * Subscribe to a channel. * Matches Node.js subscribe() API. */ declare function subscribe(name: string, subscription: MessageFunction): void; declare function subscribe(name: symbol, subscription: MessageFunction): void; /** * Unsubscribe from a channel. * Matches Node.js unsubscribe() API. */ declare function unsubscribe(name: string, subscription: MessageFunction): boolean; declare function unsubscribe(name: symbol, subscription: MessageFunction): boolean; /** * Create a TracingChannel. * Matches Node.js tracingChannel() API. */ declare function tracingChannel(nameOrChannels: string | Channels): TracingChannel; declare const _default: { channel: typeof channel; hasSubscribers: typeof hasSubscribers; subscribe: typeof subscribe; unsubscribe: typeof unsubscribe; tracingChannel: typeof tracingChannel; Channel: typeof Channel; TracingChannel: typeof TracingChannel; }; export { Channel, type ChannelHandlers, type MessageFunction, TracingChannel, type TransformFunction, channel, _default as default, hasSubscribers, subscribe, tracingChannel, unsubscribe };