@dudousxd/nestjs-diagnostics-redis 0.2.3 → 0.2.4

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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # @dudousxd/nestjs-diagnostics-redis
2
2
 
3
+ ## 0.2.4
4
+
5
+ ### Patch Changes
6
+
7
+ - [#64](https://github.com/DavideCarvalho/nestjs-diagnostics/pull/64) [`4306143`](https://github.com/DavideCarvalho/nestjs-diagnostics/commit/43061439ba0e7aba4f506b9d54aa8640a9c47ecb) Thanks [@DavideCarvalho](https://github.com/DavideCarvalho)! - Forward relayed events off the emitter's call stack. `emit()` no longer serializes and publishes to Redis synchronously: selected events are queued and, once per event loop turn, sent in emit order as a single pipeline (one Redis message per event, same wire format). Queued events are published when the relay is torn down.
8
+
3
9
  ## 0.2.3
4
10
 
5
11
  ### Patch Changes
package/README.md CHANGED
@@ -63,7 +63,10 @@ teardown();
63
63
  ## How it works
64
64
 
65
65
  - **Forwarder:** subscribes to the selected local channels; each event is published to Redis as
66
- `{ node, env }` (the diagnostics envelope).
66
+ `{ node, env }` (the diagnostics envelope). `emit()` only queues the event: the queue is
67
+ serialized and published once per event loop turn (`setImmediate`), in emit order, as a single
68
+ pipeline when `pub` has `pipeline()` (ioredis does) and one `publish` per event otherwise. Still
69
+ one Redis message per event. The teardown publishes anything still queued before unsubscribing.
67
70
  - **Receiver:** subscribes to the Redis channel; each message from a *different* node is re-emitted
68
71
  locally via the diagnostics bus, so all local subscribers fire.
69
72
  - **Loop-safe:** the receiver skips its own echoes (`node === nodeId`) and a re-emit guard stops a
@@ -74,5 +77,9 @@ teardown();
74
77
  - **Payloads cross a process boundary as JSON** — class instances arrive as plain objects (no
75
78
  methods/prototype), `Date` as an ISO string. Read fields, not behavior, in cross-process handlers.
76
79
  - **Fire-and-forget**, like the in-process bus: no guaranteed delivery, ordering, or replay.
80
+ - **The payload is serialized at the end of the turn**, not inside `emit()`. A payload object the
81
+ emitter mutates synchronously after `emit()` is relayed with its state at flush time, which is
82
+ also the state in-process subscribers holding the same reference see. A payload that can't be
83
+ serialized (a circular reference) drops only that event.
77
84
  - The relay never opens or closes your Redis connections — you own their lifecycle. It never throws
78
85
  back into `emit()`.
package/dist/relay.d.ts CHANGED
@@ -1,11 +1,18 @@
1
1
  /** The minimal Redis pub/sub surface the relay uses. An ioredis instance satisfies it structurally. */
2
2
  export interface RedisLike {
3
3
  publish(channel: string, message: string): unknown;
4
+ /** When present, a tick's forwarded events go out as one pipeline instead of one round trip each. */
5
+ pipeline?(): RedisPipelineLike;
4
6
  subscribe(channel: string, callback?: (err: Error | null, count: number) => void): unknown;
5
7
  on(event: 'message', listener: (channel: string, message: string) => void): unknown;
6
8
  removeListener(event: 'message', listener: (channel: string, message: string) => void): unknown;
7
9
  unsubscribe(channel: string): unknown;
8
10
  }
11
+ /** The slice of an ioredis pipeline the relay uses to batch publishes. */
12
+ export interface RedisPipelineLike {
13
+ publish(channel: string, message: string): unknown;
14
+ exec(): unknown;
15
+ }
9
16
  export interface ChannelRef {
10
17
  lib: string;
11
18
  event: string;
@@ -33,7 +40,12 @@ export interface DiagnosticsRedisRelayOptions {
33
40
  * echo suppression and a re-emit guard. Never throws into `emit()` or the Redis handler. Does NOT
34
41
  * close the `pub`/`sub` connections — the caller owns them.
35
42
  *
36
- * @returns a teardown that removes all local subscriptions and the Redis message handler.
43
+ * Forwarding happens off the emitter's call stack: selected events are queued and, once per event
44
+ * loop turn, serialized and published in emit order (one Redis message per event, sent as a single
45
+ * pipeline when `pub` supports it).
46
+ *
47
+ * @returns a teardown that publishes any queued events, then removes all local subscriptions and
48
+ * the Redis message handler.
37
49
  */
38
50
  export declare function createDiagnosticsRedisRelay(options: DiagnosticsRedisRelayOptions): () => void;
39
51
  //# sourceMappingURL=relay.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"relay.d.ts","sourceRoot":"","sources":["../src/relay.ts"],"names":[],"mappings":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;IACtB,6EAA6E;IAC7E,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAeD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,2BAA2B,CAAC,OAAO,EAAE,4BAA4B,GAAG,MAAM,IAAI,CA6H7F"}
package/dist/relay.js CHANGED
@@ -20,7 +20,12 @@ function parseChannelName(name) {
20
20
  * echo suppression and a re-emit guard. Never throws into `emit()` or the Redis handler. Does NOT
21
21
  * close the `pub`/`sub` connections — the caller owns them.
22
22
  *
23
- * @returns a teardown that removes all local subscriptions and the Redis message handler.
23
+ * Forwarding happens off the emitter's call stack: selected events are queued and, once per event
24
+ * loop turn, serialized and published in emit order (one Redis message per event, sent as a single
25
+ * pipeline when `pub` supports it).
26
+ *
27
+ * @returns a teardown that publishes any queued events, then removes all local subscriptions and
28
+ * the Redis message handler.
24
29
  */
25
30
  export function createDiagnosticsRedisRelay(options) {
26
31
  const { pub, sub } = options;
@@ -32,17 +37,54 @@ export function createDiagnosticsRedisRelay(options) {
32
37
  const subscriptions = [];
33
38
  const subscribed = new Set();
34
39
  const reEmitting = new WeakSet();
40
+ const pending = [];
41
+ let scheduled = null;
42
+ const publishOne = (message) => {
43
+ try {
44
+ pub.publish(redisChannel, message);
45
+ }
46
+ catch {
47
+ // a failing publish drops only its own event
48
+ }
49
+ };
50
+ const flush = () => {
51
+ if (scheduled !== null) {
52
+ clearImmediate(scheduled);
53
+ scheduled = null;
54
+ }
55
+ if (pending.length === 0)
56
+ return;
57
+ const messages = [];
58
+ for (const env of pending.splice(0)) {
59
+ try {
60
+ messages.push(JSON.stringify({ node: nodeId, env }));
61
+ }
62
+ catch {
63
+ // an unserializable event is dropped without affecting the rest of the batch
64
+ }
65
+ }
66
+ if (messages.length > 1 && typeof pub.pipeline === 'function') {
67
+ try {
68
+ const pipeline = pub.pipeline();
69
+ for (const message of messages)
70
+ pipeline.publish(redisChannel, message);
71
+ pipeline.exec();
72
+ }
73
+ catch {
74
+ // never throw out of the flush
75
+ }
76
+ return;
77
+ }
78
+ for (const message of messages)
79
+ publishOne(message);
80
+ };
35
81
  const forward = (msg) => {
36
82
  if (typeof msg !== 'object' || msg === null)
37
83
  return;
38
84
  if (reEmitting.has(msg))
39
85
  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
- }
86
+ pending.push(msg);
87
+ scheduled ??= setImmediate(flush);
46
88
  };
47
89
  const subscribeRef = (ref) => {
48
90
  const name = channelName(ref.lib, ref.event);
@@ -107,6 +149,7 @@ export function createDiagnosticsRedisRelay(options) {
107
149
  sub.subscribe(redisChannel);
108
150
  sub.on('message', onMessage);
109
151
  return () => {
152
+ flush();
110
153
  for (const { ref, listener } of subscriptions) {
111
154
  getChannel(ref.lib, ref.event).unsubscribe(listener);
112
155
  }
package/dist/relay.js.map CHANGED
@@ -1 +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,CA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AClB,GAAG,CAAC,cAAc,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;QACzC,GAAG,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC;IAChC,CAAC,CAAC;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dudousxd/nestjs-diagnostics-redis",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
4
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
5
  "license": "MIT",
6
6
  "repository": {
@@ -8,6 +8,20 @@
8
8
  "url": "git+https://github.com/DavideCarvalho/nestjs-diagnostics.git",
9
9
  "directory": "packages/redis"
10
10
  },
11
+ "homepage": "https://davidecarvalho.github.io/aviary/docs/diagnostics",
12
+ "bugs": {
13
+ "url": "https://github.com/DavideCarvalho/nestjs-diagnostics/issues"
14
+ },
15
+ "keywords": [
16
+ "nestjs",
17
+ "diagnostics",
18
+ "diagnostics-channel",
19
+ "redis",
20
+ "transport",
21
+ "cross-process",
22
+ "aviary",
23
+ "tanstack-intent"
24
+ ],
11
25
  "author": "Davi Carvalho <davi@goflip.ai>",
12
26
  "type": "module",
13
27
  "main": "./dist/index.js",
@@ -27,7 +41,7 @@
27
41
  ],
28
42
  "sideEffects": false,
29
43
  "dependencies": {
30
- "@dudousxd/nestjs-diagnostics": "^0.7.1"
44
+ "@dudousxd/nestjs-diagnostics": "^0.7.2"
31
45
  },
32
46
  "peerDependencies": {
33
47
  "ioredis": "^5",
@@ -47,28 +61,18 @@
47
61
  }
48
62
  },
49
63
  "devDependencies": {
50
- "@nestjs/common": "^12.0.1",
51
- "@nestjs/core": "^12.0.1",
52
- "@nestjs/testing": "^12.0.1",
53
- "@types/node": "^20.0.0",
54
- "ioredis": "^5.4.2",
55
- "reflect-metadata": "^0.2.2",
56
- "typescript": "^5.4.0",
57
- "vitest": "^3.0.0"
64
+ "@nestjs/common": "12.0.4",
65
+ "@nestjs/core": "12.0.4",
66
+ "@nestjs/testing": "12.0.4",
67
+ "@types/node": "20.19.43",
68
+ "ioredis": "5.11.1",
69
+ "reflect-metadata": "0.2.2",
70
+ "typescript": "5.9.3",
71
+ "vitest": "3.2.7"
58
72
  },
59
73
  "engines": {
60
74
  "node": ">=20"
61
75
  },
62
- "keywords": [
63
- "nestjs",
64
- "diagnostics",
65
- "diagnostics-channel",
66
- "redis",
67
- "transport",
68
- "cross-process",
69
- "aviary",
70
- "tanstack-intent"
71
- ],
72
76
  "scripts": {
73
77
  "build": "tsc -p tsconfig.json",
74
78
  "test": "vitest run --passWithNoTests",
@@ -79,9 +79,10 @@ Source: `packages/redis/src/relay.ts` (`wildcardMatches`, `subscribeRef`, `Diagn
79
79
 
80
80
  ### 2. Manual relay outside Nest
81
81
 
82
- `createDiagnosticsRedisRelay(options)` returns a `teardown()` that removes all
83
- local subscriptions and the Redis message handler. It never opens or closes your
84
- Redis connections — you own their lifecycle:
82
+ `createDiagnosticsRedisRelay(options)` returns a `teardown()` that first
83
+ publishes any queued events, then removes all local subscriptions and the Redis
84
+ message handler. It never opens or closes your Redis connections — you own their
85
+ lifecycle:
85
86
 
86
87
  ```ts
87
88
  import { createDiagnosticsRedisRelay } from '@dudousxd/nestjs-diagnostics-redis';
@@ -95,7 +96,13 @@ const teardown = createDiagnosticsRedisRelay({
95
96
  teardown();
96
97
  ```
97
98
 
98
- Source: `packages/redis/src/relay.ts` (`createDiagnosticsRedisRelay`).
99
+ Forwarding is batched off the emitter's call stack: `emit()` only queues the
100
+ event, and the queue is serialized and published once per event loop turn in emit
101
+ order (one Redis message per event, unchanged wire format) — via a single
102
+ pipeline when the turn queued more than one event and `pub` supports
103
+ `pipeline()`, otherwise one `publish` per message.
104
+
105
+ Source: `packages/redis/src/relay.ts` (`createDiagnosticsRedisRelay` `forward`/`flush`).
99
106
 
100
107
  ### 3. Loop-safety
101
108
 
@@ -162,7 +169,8 @@ DiagnosticsRedisModule.forRoot({ pub: redis, sub: redis.duplicate(), libs: ['dur
162
169
  // e.g. in your Redis provider's onApplicationShutdown: await redis.quit();
163
170
  ```
164
171
 
165
- The relay teardown removes only its own subscriptions and Redis message handler;
166
- it never opens or closes `pub`/`sub`. Manage their lifecycle in your own provider.
172
+ The relay teardown first publishes any queued events, then removes its own
173
+ subscriptions and Redis message handler; it never opens or closes `pub`/`sub`.
174
+ Manage their lifecycle in your own provider.
167
175
  Source: `packages/redis/src/diagnostics-redis.module.ts` (`DiagnosticsRedisStarter` teardown),
168
176
  `packages/redis/src/relay.ts` (return teardown).