@dudousxd/nestjs-diagnostics
Version:
A standard convention for @dudousxd/nestjs-* libs to emit observability events over node:diagnostics_channel.
44 lines • 2.03 kB
TypeScript
/**
* A process-wide registry of every `aviary:<lib>:<event>` channel name created or
* emitted through this package.
*
* `node:diagnostics_channel` has no wildcard subscription: you can only subscribe
* to a channel by its exact name. A generic observer (the Telescope watcher) that
* wants to record *all* diagnostics therefore needs to (a) subscribe to every
* channel that exists now and (b) be told when a new one appears. This registry
* provides both: {@link registeredChannels} for the current set and
* {@link onChannelRegistered} for future additions.
*/
/**
* Record a channel name, notifying {@link onChannelRegistered} listeners the first
* time it is seen. Idempotent: re-registering an existing name is a no-op.
* Called by {@link getChannel}/{@link emit} so every channel touched through this
* package is discoverable.
*/
export declare function registerChannel(name: string): void;
/** A snapshot of every `aviary:<lib>:<event>` channel registered so far. */
export declare function registeredChannels(): string[];
/**
* Subscribe to channel registrations. The callback fires once per channel name
* registered *after* this call. Returns an unsubscribe function.
*
* Note: this does NOT replay existing channels — a generic watcher should pair
* it with {@link registeredChannels} to cover current + future names:
*
* ```ts
* for (const name of registeredChannels()) subscribe(name);
* const off = onChannelRegistered(subscribe);
* ```
*/
export declare function onChannelRegistered(cb: (name: string) => void): () => void;
/**
* Register a callback run by {@link resetRegistry}. Used internally by
* {@link getChannel}'s memo cache; not part of the public contract.
*/
export declare function onRegistryReset(cb: () => void): void;
/**
* Test-only: forget every registered channel and listener. Not part of the
* public contract — exposed so suites can assert registration in isolation.
*/
export declare function resetRegistry(): void;
//# sourceMappingURL=registry.d.ts.map