@dudousxd/nestjs-diagnostics-redis 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # @dudousxd/nestjs-diagnostics-redis
2
+
3
+ ## 0.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`283755d`](https://github.com/DavideCarvalho/nestjs-diagnostics/commit/283755dfb78ca0b31ed37abfe56855dff93597a4) - Add `@dudousxd/nestjs-diagnostics-redis`: a consumer-side relay that forwards selected `aviary:<lib>:<event>` diagnostics channels over Redis pub/sub and re-emits remote events onto the local bus, so `@OnDiagnostic` handlers fire across processes. Ships `createDiagnosticsRedisRelay(options)` and a global `DiagnosticsRedisModule`. Loop-safe (nodeId echo suppression + re-emit guard); coded against a minimal `RedisLike` interface (ioredis satisfies it). The diagnostics core stays in-process and untouched.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Davi Carvalho
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,71 @@
1
+ # @dudousxd/nestjs-diagnostics-redis
2
+
3
+ Cross-process transport for [`@dudousxd/nestjs-diagnostics`](https://github.com/DavideCarvalho/nestjs-diagnostics).
4
+ A consumer-side **relay** forwards selected local `aviary:<lib>:<event>` channels onto Redis pub/sub
5
+ and re-emits Redis-received events back onto the local diagnostics bus — so `@OnDiagnostic` handlers
6
+ and `getChannel(...).subscribe(...)` reactions fire **across processes/pods**. The diagnostics core
7
+ stays in-process and untouched; this is entirely opt-in.
8
+
9
+ ## Install
10
+
11
+ ```bash
12
+ pnpm add @dudousxd/nestjs-diagnostics-redis @dudousxd/nestjs-diagnostics ioredis
13
+ ```
14
+
15
+ ## Use (Nest)
16
+
17
+ Supply your own ioredis connections — a publisher and a **separate** subscriber (`redis.duplicate()`,
18
+ since a subscribed connection can't publish):
19
+
20
+ ```ts
21
+ import Redis from 'ioredis';
22
+ import { DiagnosticsRedisModule } from '@dudousxd/nestjs-diagnostics-redis';
23
+
24
+ const redis = new Redis(process.env.REDIS_URL);
25
+
26
+ @Module({
27
+ imports: [
28
+ DiagnosticsRedisModule.forRoot({
29
+ pub: redis,
30
+ sub: redis.duplicate(),
31
+ libs: ['durable', 'notifications'], // forward all events of these libs
32
+ }),
33
+ ],
34
+ })
35
+ export class AppModule {}
36
+ ```
37
+
38
+ Now an `@OnDiagnostic('durable', 'run.failed')` handler in **another** process fires when a worker
39
+ elsewhere emits it.
40
+
41
+ ## Use (manual)
42
+
43
+ ```ts
44
+ import { createDiagnosticsRedisRelay } from '@dudousxd/nestjs-diagnostics-redis';
45
+
46
+ const teardown = createDiagnosticsRedisRelay({
47
+ pub: redis,
48
+ sub: redis.duplicate(),
49
+ channels: [{ lib: 'resilience', event: 'circuit-opened' }], // exact channels
50
+ // or: libs: ['durable'] | all: true
51
+ });
52
+ // ... later
53
+ teardown();
54
+ ```
55
+
56
+ ## How it works
57
+
58
+ - **Forwarder:** subscribes to the selected local channels; each event is published to Redis as
59
+ `{ node, env }` (the diagnostics envelope).
60
+ - **Receiver:** subscribes to the Redis channel; each message from a *different* node is re-emitted
61
+ locally via the diagnostics bus, so all local subscribers fire.
62
+ - **Loop-safe:** the receiver skips its own echoes (`node === nodeId`) and a re-emit guard stops a
63
+ received event from being forwarded back — so two processes never ping-pong.
64
+
65
+ ## Notes
66
+
67
+ - **Payloads cross a process boundary as JSON** — class instances arrive as plain objects (no
68
+ methods/prototype), `Date` as an ISO string. Read fields, not behavior, in cross-process handlers.
69
+ - **Fire-and-forget**, like the in-process bus: no guaranteed delivery, ordering, or replay.
70
+ - The relay never opens or closes your Redis connections — you own their lifecycle. It never throws
71
+ back into `emit()`.
@@ -0,0 +1,18 @@
1
+ import { type DynamicModule } from '@nestjs/common';
2
+ import { type DiagnosticsRedisRelayOptions } from './relay.js';
3
+ export interface DiagnosticsRedisModuleOptions extends DiagnosticsRedisRelayOptions {
4
+ }
5
+ /**
6
+ * Import once at the app root to relay diagnostics events across processes over Redis. Supply your
7
+ * `pub` / `sub` ioredis connections (e.g. `redis` and `redis.duplicate()`) and the channel selection.
8
+ * The module manages only the relay's subscriptions — it does NOT open or close your Redis clients.
9
+ *
10
+ * ```ts
11
+ * @Module({ imports: [DiagnosticsRedisModule.forRoot({ pub: redis, sub: redis.duplicate(), libs: ['durable'] })] })
12
+ * export class AppModule {}
13
+ * ```
14
+ */
15
+ export declare class DiagnosticsRedisModule {
16
+ static forRoot(options: DiagnosticsRedisModuleOptions): DynamicModule;
17
+ }
18
+ //# sourceMappingURL=diagnostics-redis.module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"diagnostics-redis.module.d.ts","sourceRoot":"","sources":["../src/diagnostics-redis.module.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,aAAa,EAMnB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,KAAK,4BAA4B,EAA+B,MAAM,YAAY,CAAC;AAE5F,MAAM,WAAW,6BAA8B,SAAQ,4BAA4B;CAAG;AAoBtF;;;;;;;;;GASG;AACH,qBAEa,sBAAsB;IACjC,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,6BAA6B,GAAG,aAAa;CAatE"}
@@ -0,0 +1,62 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ var DiagnosticsRedisModule_1;
11
+ import { Global, Injectable, Module, } from '@nestjs/common';
12
+ import { createDiagnosticsRedisRelay } from './relay.js';
13
+ const RELAY_OPTIONS = Symbol('diagnostics-redis:options');
14
+ let DiagnosticsRedisStarter = class DiagnosticsRedisStarter {
15
+ options;
16
+ teardown = null;
17
+ constructor(options) {
18
+ this.options = options;
19
+ }
20
+ onApplicationBootstrap() {
21
+ this.teardown = createDiagnosticsRedisRelay(this.options);
22
+ }
23
+ onApplicationShutdown() {
24
+ this.teardown?.();
25
+ this.teardown = null;
26
+ }
27
+ };
28
+ DiagnosticsRedisStarter = __decorate([
29
+ Injectable(),
30
+ __metadata("design:paramtypes", [Object])
31
+ ], DiagnosticsRedisStarter);
32
+ /**
33
+ * Import once at the app root to relay diagnostics events across processes over Redis. Supply your
34
+ * `pub` / `sub` ioredis connections (e.g. `redis` and `redis.duplicate()`) and the channel selection.
35
+ * The module manages only the relay's subscriptions — it does NOT open or close your Redis clients.
36
+ *
37
+ * ```ts
38
+ * @Module({ imports: [DiagnosticsRedisModule.forRoot({ pub: redis, sub: redis.duplicate(), libs: ['durable'] })] })
39
+ * export class AppModule {}
40
+ * ```
41
+ */
42
+ let DiagnosticsRedisModule = DiagnosticsRedisModule_1 = class DiagnosticsRedisModule {
43
+ static forRoot(options) {
44
+ return {
45
+ module: DiagnosticsRedisModule_1,
46
+ providers: [
47
+ { provide: RELAY_OPTIONS, useValue: options },
48
+ {
49
+ provide: DiagnosticsRedisStarter,
50
+ useFactory: (opts) => new DiagnosticsRedisStarter(opts),
51
+ inject: [RELAY_OPTIONS],
52
+ },
53
+ ],
54
+ };
55
+ }
56
+ };
57
+ DiagnosticsRedisModule = DiagnosticsRedisModule_1 = __decorate([
58
+ Global(),
59
+ Module({})
60
+ ], DiagnosticsRedisModule);
61
+ export { DiagnosticsRedisModule };
62
+ //# sourceMappingURL=diagnostics-redis.module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"diagnostics-redis.module.js","sourceRoot":"","sources":["../src/diagnostics-redis.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,OAAO,EAEL,MAAM,EACN,UAAU,EACV,MAAM,GAGP,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAqC,2BAA2B,EAAE,MAAM,YAAY,CAAC;AAI5F,MAAM,aAAa,GAAG,MAAM,CAAC,2BAA2B,CAAC,CAAC;AAE1D,IACM,uBAAuB,GAD7B,MACM,uBAAuB;IAGE;IAFrB,QAAQ,GAAwB,IAAI,CAAC;IAE7C,YAA6B,OAAsC;QAAtC,YAAO,GAAP,OAAO,CAA+B;IAAG,CAAC;IAEvE,sBAAsB;QACpB,IAAI,CAAC,QAAQ,GAAG,2BAA2B,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC5D,CAAC;IAED,qBAAqB;QACnB,IAAI,CAAC,QAAQ,EAAE,EAAE,CAAC;QAClB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;IACvB,CAAC;CACF,CAAA;AAbK,uBAAuB;IAD5B,UAAU,EAAE;;GACP,uBAAuB,CAa5B;AAED;;;;;;;;;GASG;AAGI,IAAM,sBAAsB,8BAA5B,MAAM,sBAAsB;IACjC,MAAM,CAAC,OAAO,CAAC,OAAsC;QACnD,OAAO;YACL,MAAM,EAAE,wBAAsB;YAC9B,SAAS,EAAE;gBACT,EAAE,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,OAAO,EAAE;gBAC7C;oBACE,OAAO,EAAE,uBAAuB;oBAChC,UAAU,EAAE,CAAC,IAAmC,EAAE,EAAE,CAAC,IAAI,uBAAuB,CAAC,IAAI,CAAC;oBACtF,MAAM,EAAE,CAAC,aAAa,CAAC;iBACxB;aACF;SACF,CAAC;IACJ,CAAC;CACF,CAAA;AAdY,sBAAsB;IAFlC,MAAM,EAAE;IACR,MAAM,CAAC,EAAE,CAAC;GACE,sBAAsB,CAclC"}
@@ -0,0 +1,5 @@
1
+ export { createDiagnosticsRedisRelay } from './relay.js';
2
+ export type { ChannelRef, DiagnosticsRedisRelayOptions, RedisLike } from './relay.js';
3
+ export { DiagnosticsRedisModule } from './diagnostics-redis.module.js';
4
+ export type { DiagnosticsRedisModuleOptions } from './diagnostics-redis.module.js';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,MAAM,YAAY,CAAC;AACzD,YAAY,EAAE,UAAU,EAAE,4BAA4B,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEtF,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AACvE,YAAY,EAAE,6BAA6B,EAAE,MAAM,+BAA+B,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export { createDiagnosticsRedisRelay } from './relay.js';
2
+ export { DiagnosticsRedisModule } from './diagnostics-redis.module.js';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,MAAM,YAAY,CAAC;AAGzD,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC"}
@@ -0,0 +1,39 @@
1
+ /** The minimal Redis pub/sub surface the relay uses. An ioredis instance satisfies it structurally. */
2
+ export interface RedisLike {
3
+ publish(channel: string, message: string): unknown;
4
+ subscribe(channel: string, callback?: (err: Error | null, count: number) => void): unknown;
5
+ on(event: 'message', listener: (channel: string, message: string) => void): unknown;
6
+ removeListener(event: 'message', listener: (channel: string, message: string) => void): unknown;
7
+ unsubscribe(channel: string): unknown;
8
+ }
9
+ export interface ChannelRef {
10
+ lib: string;
11
+ event: string;
12
+ }
13
+ export interface DiagnosticsRedisRelayOptions {
14
+ /** Publisher connection. */
15
+ pub: RedisLike;
16
+ /** Subscriber connection (separate from `pub`). For ioredis: `const sub = pub.duplicate()`. */
17
+ sub: RedisLike;
18
+ /** Forward every event of these libs (current + future channels). */
19
+ libs?: string[];
20
+ /** Forward these exact channels, in addition to `libs`. */
21
+ channels?: ChannelRef[];
22
+ /** Forward EVERY aviary channel (current + future). Overrides `libs`/`channels`. Default false. */
23
+ all?: boolean;
24
+ /** Redis channel to relay on. Default 'aviary:diagnostics:relay'. */
25
+ redisChannel?: string;
26
+ /** Unique id for THIS process, for echo suppression. Default a random id. */
27
+ nodeId?: string;
28
+ }
29
+ /**
30
+ * Relay diagnostics events across processes over Redis pub/sub. Forwards selected local
31
+ * `aviary:<lib>:<event>` channels to Redis and re-emits Redis-received events onto the local bus, so
32
+ * `@OnDiagnostic` handlers / `getChannel(...).subscribe(...)` fire cross-process. Loop-safe via nodeId
33
+ * echo suppression and a re-emit guard. Never throws into `emit()` or the Redis handler. Does NOT
34
+ * close the `pub`/`sub` connections — the caller owns them.
35
+ *
36
+ * @returns a teardown that removes all local subscriptions and the Redis message handler.
37
+ */
38
+ export declare function createDiagnosticsRedisRelay(options: DiagnosticsRedisRelayOptions): () => void;
39
+ //# sourceMappingURL=relay.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"relay.d.ts","sourceRoot":"","sources":["../src/relay.ts"],"names":[],"mappings":"AAUA,uGAAuG;AACvG,MAAM,WAAW,SAAS;IACxB,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC;IACnD,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE,KAAK,GAAG,IAAI,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC;IAC3F,EAAE,CAAC,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC;IACpF,cAAc,CAAC,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC;IAChG,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC;CACvC;AAED,MAAM,WAAW,UAAU;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,4BAA4B;IAC3C,4BAA4B;IAC5B,GAAG,EAAE,SAAS,CAAC;IACf,+FAA+F;IAC/F,GAAG,EAAE,SAAS,CAAC;IACf,qEAAqE;IACrE,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,2DAA2D;IAC3D,QAAQ,CAAC,EAAE,UAAU,EAAE,CAAC;IACxB,mGAAmG;IACnG,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,qEAAqE;IACrE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,6EAA6E;IAC7E,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAeD;;;;;;;;GAQG;AACH,wBAAgB,2BAA2B,CAAC,OAAO,EAAE,4BAA4B,GAAG,MAAM,IAAI,CAyF7F"}
package/dist/relay.js ADDED
@@ -0,0 +1,120 @@
1
+ import { randomUUID } from 'node:crypto';
2
+ import { CHANNEL_PREFIX, channelName, getChannel, onChannelRegistered, registeredChannels, } from '@dudousxd/nestjs-diagnostics';
3
+ const DEFAULT_REDIS_CHANNEL = 'aviary:diagnostics:relay';
4
+ /** Strip the `aviary:` prefix and split on the FIRST colon — the event segment may contain dots
5
+ * (e.g. `durable:run.failed`), but the lib/event boundary is the first colon after the prefix. */
6
+ function parseChannelName(name) {
7
+ const prefix = `${CHANNEL_PREFIX}:`;
8
+ if (!name.startsWith(prefix))
9
+ return null;
10
+ const rest = name.slice(prefix.length);
11
+ const idx = rest.indexOf(':');
12
+ if (idx <= 0 || idx === rest.length - 1)
13
+ return null;
14
+ return { lib: rest.slice(0, idx), event: rest.slice(idx + 1) };
15
+ }
16
+ /**
17
+ * Relay diagnostics events across processes over Redis pub/sub. Forwards selected local
18
+ * `aviary:<lib>:<event>` channels to Redis and re-emits Redis-received events onto the local bus, so
19
+ * `@OnDiagnostic` handlers / `getChannel(...).subscribe(...)` fire cross-process. Loop-safe via nodeId
20
+ * echo suppression and a re-emit guard. Never throws into `emit()` or the Redis handler. Does NOT
21
+ * close the `pub`/`sub` connections — the caller owns them.
22
+ *
23
+ * @returns a teardown that removes all local subscriptions and the Redis message handler.
24
+ */
25
+ export function createDiagnosticsRedisRelay(options) {
26
+ const { pub, sub } = options;
27
+ const redisChannel = options.redisChannel ?? DEFAULT_REDIS_CHANNEL;
28
+ const nodeId = options.nodeId ?? randomUUID();
29
+ const forwardAll = options.all === true;
30
+ const libs = options.libs ?? [];
31
+ const exact = options.channels ?? [];
32
+ const subscriptions = [];
33
+ const subscribed = new Set();
34
+ const reEmitting = new WeakSet();
35
+ const forward = (msg) => {
36
+ if (typeof msg !== 'object' || msg === null)
37
+ return;
38
+ if (reEmitting.has(msg))
39
+ return; // a re-emitted remote event — do not send it back
40
+ try {
41
+ pub.publish(redisChannel, JSON.stringify({ node: nodeId, env: msg }));
42
+ }
43
+ catch {
44
+ // never throw back into the synchronous emit() that triggered this
45
+ }
46
+ };
47
+ const subscribeRef = (ref) => {
48
+ const name = channelName(ref.lib, ref.event);
49
+ if (subscribed.has(name))
50
+ return;
51
+ getChannel(ref.lib, ref.event).subscribe(forward);
52
+ subscribed.add(name);
53
+ subscriptions.push({ ref, listener: forward });
54
+ };
55
+ const wildcardMatches = (name) => {
56
+ if (forwardAll)
57
+ return name.startsWith(`${CHANNEL_PREFIX}:`);
58
+ return libs.some((lib) => name.startsWith(`${CHANNEL_PREFIX}:${lib}:`));
59
+ };
60
+ for (const ref of exact)
61
+ subscribeRef(ref);
62
+ const hasWildcard = forwardAll || libs.length > 0;
63
+ if (hasWildcard) {
64
+ for (const name of registeredChannels()) {
65
+ if (wildcardMatches(name)) {
66
+ const ref = parseChannelName(name);
67
+ if (ref)
68
+ subscribeRef(ref);
69
+ }
70
+ }
71
+ }
72
+ const offRegistered = hasWildcard
73
+ ? onChannelRegistered((name) => {
74
+ if (wildcardMatches(name)) {
75
+ const ref = parseChannelName(name);
76
+ if (ref)
77
+ subscribeRef(ref);
78
+ }
79
+ })
80
+ : null;
81
+ const onMessage = (channel, raw) => {
82
+ if (channel !== redisChannel)
83
+ return;
84
+ let parsed;
85
+ try {
86
+ parsed = JSON.parse(raw);
87
+ }
88
+ catch {
89
+ return; // ignore malformed
90
+ }
91
+ if (parsed.node === nodeId)
92
+ return; // our own echo
93
+ const env = parsed.env;
94
+ if (!env || typeof env.lib !== 'string' || typeof env.event !== 'string')
95
+ return;
96
+ reEmitting.add(env);
97
+ try {
98
+ getChannel(env.lib, env.event).publish(env);
99
+ }
100
+ catch {
101
+ // a local subscriber threw — never propagate into the message handler
102
+ }
103
+ finally {
104
+ reEmitting.delete(env);
105
+ }
106
+ };
107
+ sub.subscribe(redisChannel);
108
+ sub.on('message', onMessage);
109
+ return () => {
110
+ for (const { ref, listener } of subscriptions) {
111
+ getChannel(ref.lib, ref.event).unsubscribe(listener);
112
+ }
113
+ subscriptions.length = 0;
114
+ subscribed.clear();
115
+ offRegistered?.();
116
+ sub.removeListener('message', onMessage);
117
+ sub.unsubscribe(redisChannel);
118
+ };
119
+ }
120
+ //# sourceMappingURL=relay.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"relay.js","sourceRoot":"","sources":["../src/relay.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EACL,cAAc,EAEd,WAAW,EACX,UAAU,EACV,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,8BAA8B,CAAC;AAiCtC,MAAM,qBAAqB,GAAG,0BAA0B,CAAC;AAEzD;mGACmG;AACnG,SAAS,gBAAgB,CAAC,IAAY;IACpC,MAAM,MAAM,GAAG,GAAG,cAAc,GAAG,CAAC;IACpC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC;QAAE,OAAO,IAAI,CAAC;IAC1C,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IACvC,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAC9B,IAAI,GAAG,IAAI,CAAC,IAAI,GAAG,KAAK,IAAI,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,IAAI,CAAC;IACrD,OAAO,EAAE,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC,EAAE,CAAC;AACjE,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,2BAA2B,CAAC,OAAqC;IAC/E,MAAM,EAAE,G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E,SAAS,CAAC,CAAC;QACzC,GAAG,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC;IAChC,CAAC,CAAC;AACJ,CAAC"}
package/package.json ADDED
@@ -0,0 +1,76 @@
1
+ {
2
+ "name": "@dudousxd/nestjs-diagnostics-redis",
3
+ "version": "0.1.0",
4
+ "description": "Cross-process transport for @dudousxd/nestjs-diagnostics — relay aviary:<lib>:<event> events over Redis pub/sub so @OnDiagnostic handlers fire across processes.",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/DavideCarvalho/nestjs-diagnostics.git",
9
+ "directory": "packages/redis"
10
+ },
11
+ "author": "Davi Carvalho <davi@goflip.ai>",
12
+ "type": "module",
13
+ "main": "./dist/index.js",
14
+ "types": "./dist/index.d.ts",
15
+ "exports": {
16
+ ".": {
17
+ "types": "./dist/index.d.ts",
18
+ "import": "./dist/index.js",
19
+ "default": "./dist/index.js"
20
+ }
21
+ },
22
+ "files": [
23
+ "dist/",
24
+ "README.md",
25
+ "CHANGELOG.md"
26
+ ],
27
+ "sideEffects": false,
28
+ "dependencies": {
29
+ "@dudousxd/nestjs-diagnostics": "^0.4.0"
30
+ },
31
+ "peerDependencies": {
32
+ "ioredis": "^5",
33
+ "@nestjs/common": "^10 || ^11",
34
+ "@nestjs/core": "^10 || ^11",
35
+ "reflect-metadata": "^0.2"
36
+ },
37
+ "peerDependenciesMeta": {
38
+ "@nestjs/common": {
39
+ "optional": true
40
+ },
41
+ "@nestjs/core": {
42
+ "optional": true
43
+ },
44
+ "reflect-metadata": {
45
+ "optional": true
46
+ }
47
+ },
48
+ "devDependencies": {
49
+ "@nestjs/common": "^11.0.0",
50
+ "@nestjs/core": "^11.0.0",
51
+ "@nestjs/testing": "^11.0.0",
52
+ "@types/node": "^20.0.0",
53
+ "ioredis": "^5.4.2",
54
+ "reflect-metadata": "^0.2.2",
55
+ "typescript": "^5.4.0",
56
+ "vitest": "^3.0.0"
57
+ },
58
+ "engines": {
59
+ "node": ">=20"
60
+ },
61
+ "keywords": [
62
+ "nestjs",
63
+ "diagnostics",
64
+ "diagnostics-channel",
65
+ "redis",
66
+ "transport",
67
+ "cross-process",
68
+ "aviary"
69
+ ],
70
+ "scripts": {
71
+ "build": "tsc -p tsconfig.json",
72
+ "test": "vitest run --passWithNoTests",
73
+ "test:watch": "vitest",
74
+ "typecheck": "tsc -p tsconfig.json --noEmit"
75
+ }
76
+ }