/**
 * Browser-compatible implementation of Node.js Channel.
 *
 * Each channel is its own object with its own subscribers.
 */
interface AsyncLocalStorageLike<T> {
    run<R>(store: T, callback: () => R): R;
}
type TransformFunction<M, S> = (message: M) => S;
type MessageFunction<M, N> = (message: M, name: N) => void;
declare class Channel<M = any, N = string> {
    readonly name: N;
    private _subscribers;
    private _stores;
    constructor(name: N);
    get hasSubscribers(): boolean;
    subscribe(subscription: MessageFunction<M, N>): void;
    unsubscribe(subscription: MessageFunction<M, N>): boolean;
    bindStore<T>(store: AsyncLocalStorageLike<T>, transform?: TransformFunction<M, T>): void;
    unbindStore<T>(store: AsyncLocalStorageLike<T>): boolean;
    publish(message: M): void;
    runStores<F extends (...args: any[]) => any>(message: M, fn: F, thisArg?: ThisParameterType<F>, ...args: Parameters<F>): ReturnType<F>;
}

/**
 * Get or create a channel by name.
 * Matches Node.js channel() API.
 */
declare function channel<M>(name: string): Channel<M, string>;
declare function channel<M>(name: symbol): Channel<M, symbol>;
/**
 * 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<M> {
    readonly start?: Channel<M>;
    readonly end?: Channel<M>;
    readonly asyncStart?: Channel<M>;
    readonly asyncEnd?: Channel<M>;
    readonly error?: Channel<M>;
}
interface ChannelHandlers<M> {
    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<M> {
    #private;
    readonly start?: Channel<M>;
    readonly end?: Channel<M>;
    readonly asyncStart?: Channel<M>;
    readonly asyncEnd?: Channel<M>;
    readonly error?: Channel<M>;
    constructor(nameOrChannels: string | Channels<M>);
    get hasSubscribers(): boolean;
    subscribe(handlers: ChannelHandlers<M>): void;
    unsubscribe(handlers: ChannelHandlers<M>): boolean;
    traceSync<F extends (...args: any[]) => any>(fn: F, message: M, thisArg?: ThisParameterType<F>, ...args: Parameters<F>): ReturnType<F>;
    tracePromise<F extends (...args: any[]) => any>(fn: F, message: M, thisArg?: ThisParameterType<F>, ...args: Parameters<F>): Promise<ReturnType<F>>;
    traceCallback<F extends (...args: any[]) => any>(fn: F, position: number | undefined, message: M, thisArg?: ThisParameterType<F>, ...args: Parameters<F>): ReturnType<F>;
}

/**
 * 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<M>(name: string, subscription: MessageFunction<M, string>): void;
declare function subscribe<M>(name: symbol, subscription: MessageFunction<M, symbol>): void;
/**
 * Unsubscribe from a channel.
 * Matches Node.js unsubscribe() API.
 */
declare function unsubscribe<M>(name: string, subscription: MessageFunction<M, string>): boolean;
declare function unsubscribe<M>(name: symbol, subscription: MessageFunction<M, symbol>): boolean;
/**
 * Create a TracingChannel.
 * Matches Node.js tracingChannel() API.
 */
declare function tracingChannel<M>(nameOrChannels: string | Channels<M>): TracingChannel<M>;

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 };
