@dudousxd/nestjs-diagnostics 0.3.0 → 0.4.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 CHANGED
@@ -1,5 +1,15 @@
1
1
  # @dudousxd/nestjs-diagnostics
2
2
 
3
+ ## 0.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`5d035d1`](https://github.com/DavideCarvalho/nestjs-diagnostics/commit/5d035d11263b40b2af1aaa18c1ffc6f03ec66df3) - Add the `@dudousxd/nestjs-diagnostics/nestjs` subpath: `@OnDiagnostic(lib, event?)`,
8
+ `DiagnosticsModule.forRoot()`, and a `DiscoveryService` explorer that subscribes
9
+ diagnostics channels to provider methods for ergonomic, DI-friendly in-app
10
+ reactions. `@nestjs/*` are optional peers; the main barrel stays
11
+ framework-agnostic.
12
+
3
13
  ## 0.3.0
4
14
 
5
15
  ### Minor Changes
package/README.md CHANGED
@@ -98,6 +98,40 @@ watcher records every diagnostic event in the Telescope dashboard.
98
98
  | `CONTEXT_ACCESSOR` | Shared DI token for the optional context accessor. |
99
99
  | `DiagnosticEvent`, `EmitOptions`, `ContextAccessor` | Types. |
100
100
 
101
+ ## Reacting to events in NestJS — `@OnDiagnostic`
102
+
103
+ The `@dudousxd/nestjs-diagnostics/nestjs` subpath adds an ergonomic way to react
104
+ to any `aviary:<lib>:<event>` in a NestJS app — no extra event library. Register
105
+ the module once, then decorate provider methods:
106
+
107
+ ```ts
108
+ import { Module } from '@nestjs/common';
109
+ import { DiagnosticsModule } from '@dudousxd/nestjs-diagnostics/nestjs';
110
+
111
+ @Module({ imports: [DiagnosticsModule.forRoot()] })
112
+ export class AppModule {}
113
+ ```
114
+
115
+ ```ts
116
+ import { Injectable } from '@nestjs/common';
117
+ import { OnDiagnostic } from '@dudousxd/nestjs-diagnostics/nestjs';
118
+ import type { DiagnosticEvent } from '@dudousxd/nestjs-diagnostics';
119
+
120
+ @Injectable()
121
+ export class Reactions {
122
+ @OnDiagnostic('resilience', 'circuit-opened') // one exact channel
123
+ onCircuitOpen(e: DiagnosticEvent) { /* … */ }
124
+
125
+ @OnDiagnostic('resilience') // every aviary:resilience:* channel
126
+ onAnyResilience(e: DiagnosticEvent) { /* … */ }
127
+ }
128
+ ```
129
+
130
+ A handler runs on the DI-resolved instance (injected dependencies work). A
131
+ handler that throws or rejects is logged and swallowed — it can never break the
132
+ code that emitted. `@nestjs/common` + `@nestjs/core` are optional peers; the main
133
+ barrel stays framework-agnostic.
134
+
101
135
  ## License
102
136
 
103
137
  MIT
@@ -0,0 +1,20 @@
1
+ import { type OnApplicationBootstrap, type OnApplicationShutdown } from '@nestjs/common';
2
+ import { DiscoveryService, MetadataScanner } from '@nestjs/core';
3
+ export declare class DiagnosticsExplorer implements OnApplicationBootstrap, OnApplicationShutdown {
4
+ private readonly discovery;
5
+ private readonly scanner;
6
+ private readonly logger;
7
+ private readonly subscriptions;
8
+ private readonly wildcards;
9
+ private offChannelRegistered;
10
+ constructor(discovery: DiscoveryService, scanner: MetadataScanner);
11
+ onApplicationBootstrap(): void;
12
+ onApplicationShutdown(): void;
13
+ /** Subscribe once to `name`; the listener fans the envelope into `invoke`. */
14
+ private subscribe;
15
+ /** Invoke a handler, swallowing sync throws and async rejections so a buggy
16
+ * reaction can never break the synchronous `emit()` that triggered it. */
17
+ private safeInvoke;
18
+ private logError;
19
+ }
20
+ //# sourceMappingURL=diagnostics.explorer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"diagnostics.explorer.d.ts","sourceRoot":"","sources":["../../src/nestjs/diagnostics.explorer.ts"],"names":[],"mappings":"AACA,OAAO,EAIL,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,EAC3B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAQjE,qBACa,mBAAoB,YAAW,sBAAsB,EAAE,qBAAqB;IAO3D,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC3B,OAAO,CAAC,QAAQ,CAAC,OAAO;IAPnD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAqC;IAC5D,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAiE;IAC/F,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAiD;IAC3E,OAAO,CAAC,oBAAoB,CAA6B;gBAGZ,SAAS,EAAE,gBAAgB,EAC5B,OAAO,EAAE,eAAe;IAGpE,sBAAsB,IAAI,IAAI;IA+B9B,qBAAqB,IAAI,IAAI;IAU7B,8EAA8E;IAC9E,OAAO,CAAC,SAAS;IAMjB;+EAC2E;IAC3E,OAAO,CAAC,UAAU;IAgBlB,OAAO,CAAC,QAAQ;CAIjB"}
@@ -0,0 +1,105 @@
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 __param = (this && this.__param) || function (paramIndex, decorator) {
11
+ return function (target, key) { decorator(target, key, paramIndex); }
12
+ };
13
+ import diagnostics_channel from 'node:diagnostics_channel';
14
+ import { Inject, Injectable, Logger, } from '@nestjs/common';
15
+ import { DiscoveryService, MetadataScanner } from '@nestjs/core';
16
+ import { CHANNEL_PREFIX, channelName } from '../channel.js';
17
+ import { onChannelRegistered, registeredChannels } from '../registry.js';
18
+ import { ON_DIAGNOSTIC_META } from './on-diagnostic.decorator.js';
19
+ let DiagnosticsExplorer = class DiagnosticsExplorer {
20
+ discovery;
21
+ scanner;
22
+ logger = new Logger('DiagnosticsExplorer');
23
+ subscriptions = [];
24
+ wildcards = [];
25
+ offChannelRegistered = null;
26
+ constructor(discovery, scanner) {
27
+ this.discovery = discovery;
28
+ this.scanner = scanner;
29
+ }
30
+ onApplicationBootstrap() {
31
+ for (const wrapper of this.discovery.getProviders()) {
32
+ const instance = wrapper.instance;
33
+ if (!instance || typeof instance !== 'object')
34
+ continue;
35
+ const proto = Object.getPrototypeOf(instance);
36
+ for (const methodName of this.scanner.getAllMethodNames(proto)) {
37
+ const metas = Reflect.getMetadata(ON_DIAGNOSTIC_META, proto, methodName);
38
+ if (!metas?.length)
39
+ continue;
40
+ for (const meta of metas) {
41
+ const invoke = (event) => this.safeInvoke(instance, methodName, event);
42
+ if (meta.event !== undefined) {
43
+ this.subscribe(channelName(meta.lib, meta.event), invoke);
44
+ }
45
+ else {
46
+ const prefix = `${CHANNEL_PREFIX}:${meta.lib}:`;
47
+ this.wildcards.push({ prefix, invoke });
48
+ for (const name of registeredChannels()) {
49
+ if (name.startsWith(prefix))
50
+ this.subscribe(name, invoke);
51
+ }
52
+ }
53
+ }
54
+ }
55
+ }
56
+ this.offChannelRegistered = onChannelRegistered((name) => {
57
+ for (const w of this.wildcards) {
58
+ if (name.startsWith(w.prefix))
59
+ this.subscribe(name, w.invoke);
60
+ }
61
+ });
62
+ }
63
+ onApplicationShutdown() {
64
+ this.offChannelRegistered?.();
65
+ this.offChannelRegistered = null;
66
+ for (const { name, listener } of this.subscriptions) {
67
+ diagnostics_channel.channel(name).unsubscribe(listener);
68
+ }
69
+ this.subscriptions.length = 0;
70
+ this.wildcards.length = 0;
71
+ }
72
+ /** Subscribe once to `name`; the listener fans the envelope into `invoke`. */
73
+ subscribe(name, invoke) {
74
+ const listener = (msg) => invoke(msg);
75
+ diagnostics_channel.channel(name).subscribe(listener);
76
+ this.subscriptions.push({ name, listener });
77
+ }
78
+ /** Invoke a handler, swallowing sync throws and async rejections so a buggy
79
+ * reaction can never break the synchronous `emit()` that triggered it. */
80
+ safeInvoke(instance, methodName, event) {
81
+ try {
82
+ const fn = instance[methodName];
83
+ const result = fn.call(instance, event);
84
+ if (result != null && typeof result.then === 'function') {
85
+ result.catch((err) => this.logError(methodName, err));
86
+ }
87
+ }
88
+ catch (err) {
89
+ this.logError(methodName, err);
90
+ }
91
+ }
92
+ logError(methodName, err) {
93
+ const message = err instanceof Error ? err.message : String(err);
94
+ this.logger.error(`@OnDiagnostic ${methodName} handler failed: ${message}`);
95
+ }
96
+ };
97
+ DiagnosticsExplorer = __decorate([
98
+ Injectable(),
99
+ __param(0, Inject(DiscoveryService)),
100
+ __param(1, Inject(MetadataScanner)),
101
+ __metadata("design:paramtypes", [DiscoveryService,
102
+ MetadataScanner])
103
+ ], DiagnosticsExplorer);
104
+ export { DiagnosticsExplorer };
105
+ //# sourceMappingURL=diagnostics.explorer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"diagnostics.explorer.js","sourceRoot":"","sources":["../../src/nestjs/diagnostics.explorer.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,mBAAmB,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EACL,MAAM,EACN,UAAU,EACV,MAAM,GAGP,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAEzE,OAAO,EAAE,kBAAkB,EAAyB,MAAM,8BAA8B,CAAC;AAKlF,IAAM,mBAAmB,GAAzB,MAAM,mBAAmB;IAOe;IACD;IAP3B,MAAM,GAAG,IAAI,MAAM,CAAC,qBAAqB,CAAC,CAAC;IAC3C,aAAa,GAA8D,EAAE,CAAC;IAC9E,SAAS,GAA8C,EAAE,CAAC;IACnE,oBAA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IACnE,UAAU,CAChB,QAAiC,EACjC,UAAkB,EAClB,KAAsB;QAEtB,IAAI,CAAC;YACH,MAAM,EAAE,GAAG,QAAQ,CAAC,UAAU,CAAoC,CAAC;YACnE,MAAM,MAAM,GAAG,EAAE,CAAC,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;YACxC,IAAI,MAAM,IAAI,IAAI,IAAI,OAAQ,MAA2B,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;gBAC7E,MAA2B,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC,CAAC;YAC9E,CAAC;QACH,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,IAAI,CAAC,QAAQ,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC;QACjC,CAAC;IACH,CAAC;IAEO,QAAQ,CAAC,UAAkB,EAAE,GAAY;QAC/C,MAAM,OAAO,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACjE,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,iBAAiB,UAAU,oBAAoB,OAAO,EAAE,CAAC,CAAC;IAC9E,CAAC;CACF,CAAA;AAjFY,mBAAmB;IAD/B,UAAU,EAAE;IAQR,WAAA,MAAM,CAAC,gBAAgB,CAAC,CAAA;IACxB,WAAA,MAAM,CAAC,eAAe,CAAC,CAAA;qCAD8B,gBAAgB;QACnB,eAAe;GARzD,mBAAmB,CAiF/B"}
@@ -0,0 +1,6 @@
1
+ import { type DynamicModule } from '@nestjs/common';
2
+ export declare class DiagnosticsModule {
3
+ /** Register once at the app root; enables `@OnDiagnostic` on any provider. */
4
+ static forRoot(): DynamicModule;
5
+ }
6
+ //# sourceMappingURL=diagnostics.module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"diagnostics.module.d.ts","sourceRoot":"","sources":["../../src/nestjs/diagnostics.module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAU,MAAM,gBAAgB,CAAC;AAI5D,qBACa,iBAAiB;IAC5B,8EAA8E;IAC9E,MAAM,CAAC,OAAO,IAAI,aAAa;CAQhC"}
@@ -0,0 +1,26 @@
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 DiagnosticsModule_1;
8
+ import { Module } from '@nestjs/common';
9
+ import { DiscoveryModule } from '@nestjs/core';
10
+ import { DiagnosticsExplorer } from './diagnostics.explorer.js';
11
+ let DiagnosticsModule = DiagnosticsModule_1 = class DiagnosticsModule {
12
+ /** Register once at the app root; enables `@OnDiagnostic` on any provider. */
13
+ static forRoot() {
14
+ return {
15
+ module: DiagnosticsModule_1,
16
+ global: true,
17
+ imports: [DiscoveryModule],
18
+ providers: [DiagnosticsExplorer],
19
+ };
20
+ }
21
+ };
22
+ DiagnosticsModule = DiagnosticsModule_1 = __decorate([
23
+ Module({})
24
+ ], DiagnosticsModule);
25
+ export { DiagnosticsModule };
26
+ //# sourceMappingURL=diagnostics.module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"diagnostics.module.js","sourceRoot":"","sources":["../../src/nestjs/diagnostics.module.ts"],"names":[],"mappings":";;;;;;;AAAA,OAAO,EAAsB,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAGzD,IAAM,iBAAiB,yBAAvB,MAAM,iBAAiB;IAC5B,8EAA8E;IAC9E,MAAM,CAAC,OAAO;QACZ,OAAO;YACL,MAAM,EAAE,mBAAiB;YACzB,MAAM,EAAE,IAAI;YACZ,OAAO,EAAE,CAAC,eAAe,CAAC;YAC1B,SAAS,EAAE,CAAC,mBAAmB,CAAC;SACjC,CAAC;IACJ,CAAC;CACF,CAAA;AAVY,iBAAiB;IAD7B,MAAM,CAAC,EAAE,CAAC;GACE,iBAAiB,CAU7B"}
@@ -0,0 +1,5 @@
1
+ export { ON_DIAGNOSTIC_META, OnDiagnostic } from './on-diagnostic.decorator.js';
2
+ export type { OnDiagnosticMeta } from './on-diagnostic.decorator.js';
3
+ export { DiagnosticsModule } from './diagnostics.module.js';
4
+ export { DiagnosticsExplorer } from './diagnostics.explorer.js';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/nestjs/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAChF,YAAY,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC"}
@@ -0,0 +1,4 @@
1
+ export { ON_DIAGNOSTIC_META, OnDiagnostic } from './on-diagnostic.decorator.js';
2
+ export { DiagnosticsModule } from './diagnostics.module.js';
3
+ export { DiagnosticsExplorer } from './diagnostics.explorer.js';
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/nestjs/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAEhF,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC"}
@@ -0,0 +1,18 @@
1
+ /** Metadata key under which a method's @OnDiagnostic subscriptions accumulate. */
2
+ export declare const ON_DIAGNOSTIC_META: unique symbol;
3
+ /** One subscription declared on a method. `event` omitted = every event of `lib`. */
4
+ export interface OnDiagnosticMeta {
5
+ lib: string;
6
+ event?: string;
7
+ }
8
+ /**
9
+ * Subscribe a provider method to a diagnostics channel. Requires
10
+ * `DiagnosticsModule.forRoot()` to be imported so the explorer wires it up.
11
+ *
12
+ * - `@OnDiagnostic('resilience', 'circuit-opened')` — the exact channel.
13
+ * - `@OnDiagnostic('resilience')` — every `aviary:resilience:*` channel (current + future).
14
+ *
15
+ * Stackable: apply more than once to react to several channels with one method.
16
+ */
17
+ export declare function OnDiagnostic(lib: string, event?: string): MethodDecorator;
18
+ //# sourceMappingURL=on-diagnostic.decorator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"on-diagnostic.decorator.d.ts","sourceRoot":"","sources":["../../src/nestjs/on-diagnostic.decorator.ts"],"names":[],"mappings":"AAAA,kFAAkF;AAClF,eAAO,MAAM,kBAAkB,eAA2B,CAAC;AAE3D,qFAAqF;AACrF,MAAM,WAAW,gBAAgB;IAC/B,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,eAAe,CAQzE"}
@@ -0,0 +1,20 @@
1
+ /** Metadata key under which a method's @OnDiagnostic subscriptions accumulate. */
2
+ export const ON_DIAGNOSTIC_META = Symbol('diagnostics:on');
3
+ /**
4
+ * Subscribe a provider method to a diagnostics channel. Requires
5
+ * `DiagnosticsModule.forRoot()` to be imported so the explorer wires it up.
6
+ *
7
+ * - `@OnDiagnostic('resilience', 'circuit-opened')` — the exact channel.
8
+ * - `@OnDiagnostic('resilience')` — every `aviary:resilience:*` channel (current + future).
9
+ *
10
+ * Stackable: apply more than once to react to several channels with one method.
11
+ */
12
+ export function OnDiagnostic(lib, event) {
13
+ return (target, key) => {
14
+ const existing = Reflect.getMetadata(ON_DIAGNOSTIC_META, target, key) ??
15
+ [];
16
+ const meta = { lib, ...(event !== undefined ? { event } : {}) };
17
+ Reflect.defineMetadata(ON_DIAGNOSTIC_META, [...existing, meta], target, key);
18
+ };
19
+ }
20
+ //# sourceMappingURL=on-diagnostic.decorator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"on-diagnostic.decorator.js","sourceRoot":"","sources":["../../src/nestjs/on-diagnostic.decorator.ts"],"names":[],"mappings":"AAAA,kFAAkF;AAClF,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC;AAQ3D;;;;;;;;GAQG;AACH,MAAM,UAAU,YAAY,CAAC,GAAW,EAAE,KAAc;IACtD,OAAO,CAAC,MAAM,EAAE,GAAG,EAAE,EAAE;QACrB,MAAM,QAAQ,GACX,OAAO,CAAC,WAAW,CAAC,kBAAkB,EAAE,MAAM,EAAE,GAAG,CAAoC;YACxF,EAAE,CAAC;QACL,MAAM,IAAI,GAAqB,EAAE,GAAG,EAAE,GAAG,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC;QAClF,OAAO,CAAC,cAAc,CAAC,kBAAkB,EAAE,CAAC,GAAG,QAAQ,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC;IAC/E,CAAC,CAAC;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dudousxd/nestjs-diagnostics",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "A standard convention for @dudousxd/nestjs-* libs to emit observability events over node:diagnostics_channel.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -17,6 +17,27 @@
17
17
  "types": "./dist/index.d.ts",
18
18
  "import": "./dist/index.js",
19
19
  "default": "./dist/index.js"
20
+ },
21
+ "./nestjs": {
22
+ "types": "./dist/nestjs/index.d.ts",
23
+ "import": "./dist/nestjs/index.js",
24
+ "default": "./dist/nestjs/index.js"
25
+ }
26
+ },
27
+ "peerDependencies": {
28
+ "@nestjs/common": "^10 || ^11",
29
+ "@nestjs/core": "^10 || ^11",
30
+ "reflect-metadata": "^0.2"
31
+ },
32
+ "peerDependenciesMeta": {
33
+ "@nestjs/common": {
34
+ "optional": true
35
+ },
36
+ "@nestjs/core": {
37
+ "optional": true
38
+ },
39
+ "reflect-metadata": {
40
+ "optional": true
20
41
  }
21
42
  },
22
43
  "files": [
@@ -36,8 +57,13 @@
36
57
  "**/trace.ts"
37
58
  ],
38
59
  "devDependencies": {
60
+ "@nestjs/common": "^11",
61
+ "@nestjs/core": "^11",
62
+ "@nestjs/testing": "^11",
39
63
  "@types/node": "^20.0.0",
64
+ "reflect-metadata": "^0.2",
40
65
  "typescript": "^5.4.0",
66
+ "unplugin-swc": "^1.5.1",
41
67
  "vitest": "^3.0.0"
42
68
  },
43
69
  "engines": {