UNPKG

@dudousxd/nestjs-diagnostics

Version:

A standard convention for @dudousxd/nestjs-* libs to emit observability events over node:diagnostics_channel.

83 lines • 6.05 kB
import type { DiagnosticEvent } from './types.js'; /** * The first-party NestJS packages publish raw events on `node:diagnostics_channel` * under the fixed convention `nestjs:<lib>:<type>`: no envelope, no traceId. This * file is the ONE place their channel lists live. Each list was read from the * published tarball of the version in {@link OFFICIAL_PACKAGE_VERSIONS}, and * `test/official.spec.ts` re-reads the installed (pinned) packages and fails when * a channel is added, renamed or removed. * * Aviary never publishes on `nestjs:*`. It only subscribes, through * {@link subscribeOfficial}. `aviary:*` is for what the official packages don't emit. */ export declare const OFFICIAL_CHANNEL_PREFIX = "nestjs"; /** `nestjs:<lib>:<type>`, the first-party channel name. */ export type OfficialChannelName<L extends string, T extends string> = `nestjs:${L}:${T}`; type ChannelMap<L extends string, T extends readonly string[]> = { readonly [K in T[number]]: OfficialChannelName<L, K>; }; /** `@nestjs/resilience`: the 9 fixed channels of `events/resilience.channels.js`. */ export declare const NESTJS_RESILIENCE_CHANNELS: ChannelMap<"resilience", readonly ["retry", "timeout", "circuit-open", "circuit-half-open", "circuit-closed", "circuit-rejected", "bulkhead-rejected", "rate-limited", "fallback"]>; /** `@nestjs/workflows`: `channelFor(event.type)` over the 19 `WorkflowEvent` types. */ export declare const NESTJS_WORKFLOWS_CHANNELS: ChannelMap<"workflows", readonly ["workflow-started", "workflow-resumed", "workflow-suspended", "workflow-compensating", "workflow-completed", "workflow-failed", "workflow-cancelled", "workflow-compensation-failed", "step-completed", "step-failed", "step-compensated", "child-started", "signal-received", "signal-timed-out", "journal-large", "custom-status", "workflow-retried", "workflow-deleted", "schedule-skipped"]>; /** `@nestjs/authentication`: `channelFor(event.type)` over the 13 `AuthenticationEvent` types. */ export declare const NESTJS_AUTHENTICATION_CHANNELS: ChannelMap<"authentication", readonly ["sign-in", "sign-out", "mfa-verified", "mfa-failed", "mfa-enabled", "mfa-disabled", "recovery-codes-generated", "refresh-token-reused", "password-reset-requested", "password-reset", "email-verified", "magic-link-refused", "session-touch-failed"]>; /** `@nestjs/authorization`: the single `deniedChannel`. */ export declare const NESTJS_AUTHORIZATION_CHANNELS: ChannelMap<"authorization", readonly ["denied"]>; /** `@nestjs/mail`: `channels.sent` and `channels.failed`. */ export declare const NESTJS_MAIL_CHANNELS: ChannelMap<"mail", readonly ["sent", "failed"]>; /** Every known first-party lib → its `type → channel name` map. */ export declare const OFFICIAL_CHANNELS: Readonly<{ resilience: ChannelMap<"resilience", readonly ["retry", "timeout", "circuit-open", "circuit-half-open", "circuit-closed", "circuit-rejected", "bulkhead-rejected", "rate-limited", "fallback"]>; workflows: ChannelMap<"workflows", readonly ["workflow-started", "workflow-resumed", "workflow-suspended", "workflow-compensating", "workflow-completed", "workflow-failed", "workflow-cancelled", "workflow-compensation-failed", "step-completed", "step-failed", "step-compensated", "child-started", "signal-received", "signal-timed-out", "journal-large", "custom-status", "workflow-retried", "workflow-deleted", "schedule-skipped"]>; authentication: ChannelMap<"authentication", readonly ["sign-in", "sign-out", "mfa-verified", "mfa-failed", "mfa-enabled", "mfa-disabled", "recovery-codes-generated", "refresh-token-reused", "password-reset-requested", "password-reset", "email-verified", "magic-link-refused", "session-touch-failed"]>; authorization: ChannelMap<"authorization", readonly ["denied"]>; mail: ChannelMap<"mail", readonly ["sent", "failed"]>; }>; /** The official package version each list above was verified against. */ export declare const OFFICIAL_PACKAGE_VERSIONS: Readonly<{ resilience: string; workflows: string; authentication: string; authorization: string; mail: string; }>; /** A first-party lib whose channels are listed here. */ export type OfficialLib = keyof typeof OFFICIAL_CHANNELS; /** The event types `L` publishes, e.g. `'retry' | 'timeout' | …` for `'resilience'`. */ export type OfficialType<L extends OfficialLib> = keyof (typeof OFFICIAL_CHANNELS)[L] & string; /** Every first-party channel name, flattened. */ export declare function officialChannelNames(): string[]; /** * The Aviary envelope wrapped around an official payload: the usual * {@link DiagnosticEvent} plus `source: 'nestjs'`, so an observer that records * both kinds can tell them apart. Aviary's own `emit()` envelopes carry no * `source`. */ export interface OfficialDiagnosticEvent<TPayload = unknown> extends DiagnosticEvent<TPayload> { source: 'nestjs'; } /** Receives each wrapped official event and the `nestjs:*` channel it came from. */ export type OfficialListener = (event: OfficialDiagnosticEvent, channel: string) => void; /** * Subscribe to first-party `nestjs:<lib>:<type>` channels and receive each raw * payload wrapped in the Aviary envelope `{ v, ts, lib, event, traceId, payload, * source: 'nestjs' }`: * * - `traceId` comes from the registered context accessor. Official publishers run * subscribers synchronously in the caller's async context, so it is the * request's traceId; * - `durationMs` is copied from the payload when it carries a numeric one * (e.g. workflows' `step-completed`). * * Returns an unsubscribe function. A throwing `fn` never reaches the official * publisher. Subscribing only reads `nestjs:*`; Aviary never publishes there. * * ```ts * const off = subscribeOfficial('resilience', ['retry', 'circuit-open'], (e) => log(e)); * subscribeOfficial('authentication', 'all', record); * ``` */ export declare function subscribeOfficial<L extends OfficialLib>(lib: L, types: readonly OfficialType<L>[] | 'all', fn: OfficialListener): () => void; export {}; //# sourceMappingURL=official.d.ts.map