@dudousxd/nestjs-diagnostics-redis 0.1.2 → 0.2.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 +6 -0
- package/README.md +15 -8
- package/dist/diagnostics-redis.module.d.ts +18 -1
- package/dist/diagnostics-redis.module.d.ts.map +1 -1
- package/dist/diagnostics-redis.module.js +27 -5
- package/dist/diagnostics-redis.module.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @dudousxd/nestjs-diagnostics-redis
|
|
2
2
|
|
|
3
|
+
## 0.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [`af1dcf1`](https://github.com/DavideCarvalho/nestjs-diagnostics/commit/af1dcf149534b0cc211cd60ac2a470182e71ce44) - Add `DiagnosticsRedisModule.forRootAsync({ imports?, inject?, useFactory })` so the relay's `pub`/`sub` ioredis clients can come from DI instead of a top-level `new Redis(...)`. `forRoot` still works for pre-built connections.
|
|
8
|
+
|
|
3
9
|
## 0.1.2
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -15,20 +15,24 @@ pnpm add @dudousxd/nestjs-diagnostics-redis @dudousxd/nestjs-diagnostics ioredis
|
|
|
15
15
|
## Use (Nest)
|
|
16
16
|
|
|
17
17
|
Supply your own ioredis connections — a publisher and a **separate** subscriber (`redis.duplicate()`,
|
|
18
|
-
since a subscribed connection can't publish):
|
|
18
|
+
since a subscribed connection can't publish). Use `forRootAsync` to pull your Redis client from DI:
|
|
19
19
|
|
|
20
20
|
```ts
|
|
21
|
-
import Redis from 'ioredis';
|
|
21
|
+
import type Redis from 'ioredis';
|
|
22
|
+
import { Module } from '@nestjs/common';
|
|
22
23
|
import { DiagnosticsRedisModule } from '@dudousxd/nestjs-diagnostics-redis';
|
|
23
|
-
|
|
24
|
-
const redis = new Redis(process.env.REDIS_URL);
|
|
24
|
+
import { REDIS, RedisModule } from './redis.module'; // your app's Redis provider
|
|
25
25
|
|
|
26
26
|
@Module({
|
|
27
27
|
imports: [
|
|
28
|
-
DiagnosticsRedisModule.
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
DiagnosticsRedisModule.forRootAsync({
|
|
29
|
+
imports: [RedisModule],
|
|
30
|
+
inject: [REDIS],
|
|
31
|
+
useFactory: (redis: Redis) => ({
|
|
32
|
+
pub: redis,
|
|
33
|
+
sub: redis.duplicate(),
|
|
34
|
+
libs: ['durable', 'notifications'], // forward all events of these libs
|
|
35
|
+
}),
|
|
32
36
|
}),
|
|
33
37
|
],
|
|
34
38
|
})
|
|
@@ -38,6 +42,9 @@ export class AppModule {}
|
|
|
38
42
|
Now an `@OnDiagnostic('durable', 'run.failed')` handler in **another** process fires when a worker
|
|
39
43
|
elsewhere emits it.
|
|
40
44
|
|
|
45
|
+
Already holding the connections? The static `forRoot({ pub, sub, libs })` takes them directly — but
|
|
46
|
+
prefer `forRootAsync` so the relay's clients come from the same DI container as the rest of your app.
|
|
47
|
+
|
|
41
48
|
## Use (manual)
|
|
42
49
|
|
|
43
50
|
```ts
|
|
@@ -2,17 +2,34 @@ import { type DynamicModule } from '@nestjs/common';
|
|
|
2
2
|
import { type DiagnosticsRedisRelayOptions } from './relay.js';
|
|
3
3
|
export interface DiagnosticsRedisModuleOptions extends DiagnosticsRedisRelayOptions {
|
|
4
4
|
}
|
|
5
|
+
/** Async configuration — build the relay options (incl. your ioredis clients) from DI. */
|
|
6
|
+
export interface DiagnosticsRedisModuleAsyncOptions {
|
|
7
|
+
/** Modules to import so the factory can inject their exported providers (e.g. your Redis module). */
|
|
8
|
+
imports?: DynamicModule['imports'];
|
|
9
|
+
inject?: unknown[];
|
|
10
|
+
useFactory: (...args: never[]) => Promise<DiagnosticsRedisModuleOptions> | DiagnosticsRedisModuleOptions;
|
|
11
|
+
}
|
|
5
12
|
/**
|
|
6
13
|
* Import once at the app root to relay diagnostics events across processes over Redis. Supply your
|
|
7
14
|
* `pub` / `sub` ioredis connections (e.g. `redis` and `redis.duplicate()`) and the channel selection.
|
|
8
15
|
* The module manages only the relay's subscriptions — it does NOT open or close your Redis clients.
|
|
9
16
|
*
|
|
10
17
|
* ```ts
|
|
11
|
-
* @Module({
|
|
18
|
+
* @Module({
|
|
19
|
+
* imports: [
|
|
20
|
+
* DiagnosticsRedisModule.forRootAsync({
|
|
21
|
+
* inject: [REDIS],
|
|
22
|
+
* useFactory: (redis: Redis) => ({ pub: redis, sub: redis.duplicate(), libs: ['durable'] }),
|
|
23
|
+
* }),
|
|
24
|
+
* ],
|
|
25
|
+
* })
|
|
12
26
|
* export class AppModule {}
|
|
13
27
|
* ```
|
|
14
28
|
*/
|
|
15
29
|
export declare class DiagnosticsRedisModule {
|
|
30
|
+
/** Static configuration — pass already-built `pub` / `sub` clients and the channel selection. */
|
|
16
31
|
static forRoot(options: DiagnosticsRedisModuleOptions): DynamicModule;
|
|
32
|
+
/** Async configuration — build the options (incl. your ioredis clients) from injected dependencies. */
|
|
33
|
+
static forRootAsync(options: DiagnosticsRedisModuleAsyncOptions): DynamicModule;
|
|
17
34
|
}
|
|
18
35
|
//# sourceMappingURL=diagnostics-redis.module.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"diagnostics-redis.module.d.ts","sourceRoot":"","sources":["../src/diagnostics-redis.module.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,aAAa,
|
|
1
|
+
{"version":3,"file":"diagnostics-redis.module.d.ts","sourceRoot":"","sources":["../src/diagnostics-redis.module.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,aAAa,EAOnB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,KAAK,4BAA4B,EAA+B,MAAM,YAAY,CAAC;AAE5F,MAAM,WAAW,6BAA8B,SAAQ,4BAA4B;CAAG;AAEtF,0FAA0F;AAC1F,MAAM,WAAW,kCAAkC;IACjD,qGAAqG;IACrG,OAAO,CAAC,EAAE,aAAa,CAAC,SAAS,CAAC,CAAC;IACnC,MAAM,CAAC,EAAE,OAAO,EAAE,CAAC;IACnB,UAAU,EAAE,CACV,GAAG,IAAI,EAAE,KAAK,EAAE,KACb,OAAO,CAAC,6BAA6B,CAAC,GAAG,6BAA6B,CAAC;CAC7E;AA2BD;;;;;;;;;;;;;;;;GAgBG;AACH,qBAEa,sBAAsB;IACjC,iGAAiG;IACjG,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,6BAA6B,GAAG,aAAa;IAOrE,uGAAuG;IACvG,MAAM,CAAC,YAAY,CAAC,OAAO,EAAE,kCAAkC,GAAG,aAAa;CAchF"}
|
|
@@ -29,27 +29,49 @@ DiagnosticsRedisStarter = __decorate([
|
|
|
29
29
|
Injectable(),
|
|
30
30
|
__metadata("design:paramtypes", [Object])
|
|
31
31
|
], DiagnosticsRedisStarter);
|
|
32
|
+
/** Starts the relay from whatever is bound to RELAY_OPTIONS — shared by forRoot and forRootAsync. */
|
|
33
|
+
const starterProvider = {
|
|
34
|
+
provide: DiagnosticsRedisStarter,
|
|
35
|
+
useFactory: (opts) => new DiagnosticsRedisStarter(opts),
|
|
36
|
+
inject: [RELAY_OPTIONS],
|
|
37
|
+
};
|
|
32
38
|
/**
|
|
33
39
|
* Import once at the app root to relay diagnostics events across processes over Redis. Supply your
|
|
34
40
|
* `pub` / `sub` ioredis connections (e.g. `redis` and `redis.duplicate()`) and the channel selection.
|
|
35
41
|
* The module manages only the relay's subscriptions — it does NOT open or close your Redis clients.
|
|
36
42
|
*
|
|
37
43
|
* ```ts
|
|
38
|
-
* @Module({
|
|
44
|
+
* @Module({
|
|
45
|
+
* imports: [
|
|
46
|
+
* DiagnosticsRedisModule.forRootAsync({
|
|
47
|
+
* inject: [REDIS],
|
|
48
|
+
* useFactory: (redis: Redis) => ({ pub: redis, sub: redis.duplicate(), libs: ['durable'] }),
|
|
49
|
+
* }),
|
|
50
|
+
* ],
|
|
51
|
+
* })
|
|
39
52
|
* export class AppModule {}
|
|
40
53
|
* ```
|
|
41
54
|
*/
|
|
42
55
|
let DiagnosticsRedisModule = DiagnosticsRedisModule_1 = class DiagnosticsRedisModule {
|
|
56
|
+
/** Static configuration — pass already-built `pub` / `sub` clients and the channel selection. */
|
|
43
57
|
static forRoot(options) {
|
|
44
58
|
return {
|
|
45
59
|
module: DiagnosticsRedisModule_1,
|
|
60
|
+
providers: [{ provide: RELAY_OPTIONS, useValue: options }, starterProvider],
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/** Async configuration — build the options (incl. your ioredis clients) from injected dependencies. */
|
|
64
|
+
static forRootAsync(options) {
|
|
65
|
+
return {
|
|
66
|
+
module: DiagnosticsRedisModule_1,
|
|
67
|
+
imports: options.imports ?? [],
|
|
46
68
|
providers: [
|
|
47
|
-
{ provide: RELAY_OPTIONS, useValue: options },
|
|
48
69
|
{
|
|
49
|
-
provide:
|
|
50
|
-
useFactory:
|
|
51
|
-
inject: [
|
|
70
|
+
provide: RELAY_OPTIONS,
|
|
71
|
+
useFactory: options.useFactory,
|
|
72
|
+
inject: (options.inject ?? []),
|
|
52
73
|
},
|
|
74
|
+
starterProvider,
|
|
53
75
|
],
|
|
54
76
|
};
|
|
55
77
|
}
|
|
@@ -1 +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,
|
|
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,GAIP,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAqC,2BAA2B,EAAE,MAAM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,OAAO,CAAC,MAAM,IAAI,EAAE,CAAU;iBACxC;gBACD,eAAe;aAChB;SACF,CAAC;IACJ,CAAC;CACF,CAAA;AAxBY,sBAAsB;IAFlC,MAAM,EAAE;IACR,MAAM,CAAC,EAAE,CAAC;GACE,sBAAsB,CAwBlC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { createDiagnosticsRedisRelay } from './relay.js';
|
|
2
2
|
export type { ChannelRef, DiagnosticsRedisRelayOptions, RedisLike } from './relay.js';
|
|
3
3
|
export { DiagnosticsRedisModule } from './diagnostics-redis.module.js';
|
|
4
|
-
export type { DiagnosticsRedisModuleOptions } from './diagnostics-redis.module.js';
|
|
4
|
+
export type { DiagnosticsRedisModuleAsyncOptions, DiagnosticsRedisModuleOptions, } from './diagnostics-redis.module.js';
|
|
5
5
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +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,
|
|
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,EACV,kCAAkC,EAClC,6BAA6B,GAC9B,MAAM,+BAA+B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dudousxd/nestjs-diagnostics-redis",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
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": {
|