nest-graph-inspector 0.6.0 → 0.7.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.
Files changed (76) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +8 -56
  3. package/dist/adapters/direct-run-output.adapter.d.ts +18 -0
  4. package/{src → dist}/adapters/direct-run-output.adapter.js +91 -31
  5. package/{src → dist}/adapters/file-output.adapter.js +4 -1
  6. package/{src → dist}/adapters/http-output.adapter.d.ts +0 -1
  7. package/{src → dist}/adapters/http-output.adapter.js +3 -5
  8. package/{src → dist}/adapters/http-serve.adapter.js +0 -1
  9. package/{src → dist}/adapters/json-output.adapter.js +0 -1
  10. package/{src → dist}/adapters/proxy.adapter.js +0 -1
  11. package/{src → dist}/adapters/viewer-output.adapter.d.ts +4 -1
  12. package/{src → dist}/adapters/viewer-output.adapter.js +30 -4
  13. package/{src → dist}/index.d.ts +1 -0
  14. package/{src → dist}/index.js +1 -1
  15. package/dist/inspector-endpoint-info.d.ts +7 -0
  16. package/dist/inspector-endpoint-info.js +31 -0
  17. package/{src → dist}/nest-graph-inspector.config.js +0 -1
  18. package/{src → dist}/nest-graph-inspector.module.js +2 -1
  19. package/{src → dist}/nest-graph-inspector.setup.d.ts +8 -1
  20. package/{src → dist}/nest-graph-inspector.setup.js +105 -23
  21. package/dist/nest-graph-inspector.type.js +2 -0
  22. package/{src → dist}/ports/output.adapter.js +0 -1
  23. package/{src → dist}/ports/proxy.gateway.js +0 -1
  24. package/dist/runtime-trace.recorder.d.ts +42 -0
  25. package/dist/runtime-trace.recorder.js +299 -0
  26. package/dist/types/direct-run.type.d.ts +75 -0
  27. package/{src → dist}/types/direct-run.type.js +0 -1
  28. package/{src → dist}/types/graph-output.schema.js +0 -1
  29. package/dist/types/graph-output.type.js +2 -0
  30. package/dist/types/module-controller.type.js +2 -0
  31. package/{src → dist}/types/module-map.type.js +0 -1
  32. package/dist/types/module-provider.type.js +2 -0
  33. package/{src → dist}/types/module.type.js +0 -1
  34. package/package.json +24 -8
  35. package/src/adapters/direct-run-output.adapter.d.ts +0 -10
  36. package/src/adapters/direct-run-output.adapter.js.map +0 -1
  37. package/src/adapters/file-output.adapter.js.map +0 -1
  38. package/src/adapters/http-output.adapter.js.map +0 -1
  39. package/src/adapters/http-serve.adapter.js.map +0 -1
  40. package/src/adapters/json-output.adapter.js.map +0 -1
  41. package/src/adapters/proxy.adapter.js.map +0 -1
  42. package/src/adapters/viewer-output.adapter.js.map +0 -1
  43. package/src/index.js.map +0 -1
  44. package/src/nest-graph-inspector.config.js.map +0 -1
  45. package/src/nest-graph-inspector.module.js.map +0 -1
  46. package/src/nest-graph-inspector.setup.js.map +0 -1
  47. package/src/nest-graph-inspector.type.js +0 -3
  48. package/src/nest-graph-inspector.type.js.map +0 -1
  49. package/src/ports/output.adapter.js.map +0 -1
  50. package/src/ports/proxy.gateway.js.map +0 -1
  51. package/src/types/direct-run.type.d.ts +0 -13
  52. package/src/types/direct-run.type.js.map +0 -1
  53. package/src/types/graph-output.schema.js.map +0 -1
  54. package/src/types/graph-output.type.js +0 -3
  55. package/src/types/graph-output.type.js.map +0 -1
  56. package/src/types/module-controller.type.js +0 -3
  57. package/src/types/module-controller.type.js.map +0 -1
  58. package/src/types/module-map.type.js.map +0 -1
  59. package/src/types/module-provider.type.js +0 -3
  60. package/src/types/module-provider.type.js.map +0 -1
  61. package/src/types/module.type.js.map +0 -1
  62. /package/{src → dist}/adapters/file-output.adapter.d.ts +0 -0
  63. /package/{src → dist}/adapters/http-serve.adapter.d.ts +0 -0
  64. /package/{src → dist}/adapters/json-output.adapter.d.ts +0 -0
  65. /package/{src → dist}/adapters/proxy.adapter.d.ts +0 -0
  66. /package/{src → dist}/nest-graph-inspector.config.d.ts +0 -0
  67. /package/{src → dist}/nest-graph-inspector.module.d.ts +0 -0
  68. /package/{src → dist}/nest-graph-inspector.type.d.ts +0 -0
  69. /package/{src → dist}/ports/output.adapter.d.ts +0 -0
  70. /package/{src → dist}/ports/proxy.gateway.d.ts +0 -0
  71. /package/{src → dist}/types/graph-output.schema.d.ts +0 -0
  72. /package/{src → dist}/types/graph-output.type.d.ts +0 -0
  73. /package/{src → dist}/types/module-controller.type.d.ts +0 -0
  74. /package/{src → dist}/types/module-map.type.d.ts +0 -0
  75. /package/{src → dist}/types/module-provider.type.d.ts +0 -0
  76. /package/{src → dist}/types/module.type.d.ts +0 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Abdul Aziz Al Basyir
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 CHANGED
@@ -1,49 +1,14 @@
1
- <p align="center">
2
- <a href="https://albasyir.github.io/nest-graph-inspector/" target="_blank"><img src="https://albasyir.github.io/nest-graph-inspector/logo.png" width="120" alt="Nest Graph Inspector Logo" /></a>
3
- </p>
1
+ # Nest Graph Inspector
4
2
 
5
- <h1 align="center">Nest Graph Inspector</h1>
3
+ Nest Graph Inspector reads a NestJS runtime container and generates a dependency graph of modules, providers, controllers, and their relationships.
6
4
 
7
- <p align="center">
8
- <a href="https://www.npmjs.com/package/nest-graph-inspector" target="_blank"><img src="https://img.shields.io/npm/v/nest-graph-inspector.svg" alt="NPM Version" /></a>
9
- <a href="https://github.com/albasyir/nest-graph-inspector/blob/main/LICENSE" target="_blank"><img src="https://img.shields.io/npm/l/nest-graph-inspector.svg" alt="Package License" /></a>
10
- <a href="https://github.com/albasyir/nest-graph-inspector" target="_blank"><img src="https://img.shields.io/github/stars/albasyir/nest-graph-inspector?style=social" alt="Github Stars" /></a>
11
- </p>
12
-
13
- Nest Graph Inspector reads your NestJS runtime container and generates a dependency graph of modules, providers, controllers, and their relationships.
14
-
15
- ### Preview
16
-
17
- This is a static preview. [**Try the interactive viewer with AI Chat →**](https://albasyir.github.io/nest-graph-inspector/view/)
18
-
19
- > "Load Example" to see result without installing it
20
-
21
- ## Why It Matters
22
-
23
- Shipping speed depends on confidence. Teams need runtime visibility to trace impact, find architecture issues early, and ship safer changes.
24
-
25
- - **Ship Changes Faster** — trace impact in minutes, not meetings, before touching critical providers or modules
26
- - **Cut Regression Risk** — catch circular and high-coupling patterns before they become release blockers
27
- - **Make PR Reviews Concrete** — replace assumptions with runtime-backed module and provider-level evidence
28
- - **Onboard With Real Context** — give new engineers a live map of how the system actually connects and behaves
29
- - **Find Architecture Issues Early** — use Issue Finder to surface structural problems before they grow into production incidents
30
-
31
- ## Feature List
32
-
33
- - **Dependency Graph** — visualize modules, providers, controllers, imports, and dependency edges from the running app
34
- - **Circular Detection** — surface circular relationships early so teams can resolve risky loops before release
35
- - **Relation Focus** — coming soon: focus provider/module pairs to see how they relate and where dependencies connect
36
- - **Context-Aware AI Assistant** — ask graph and trace questions in plain language with context-aware answers, always free in the viewer
37
- - **Process Sequence** — coming soon: generate sequence diagrams from an entry point to completion flow
38
- - **Direct Run** — coming soon: execute runtime-resolved services and functions directly from graph context
39
-
40
- ## Quick Start
5
+ ## Install
41
6
 
42
7
  ```bash
43
- npm install nest-graph-inspector
8
+ npm install nest-graph-inspector
44
9
  ```
45
10
 
46
- > it's not only NPM, see [installation](https://albasyir.github.io/nest-graph-inspector/getting-started) for other package manager
11
+ ## Usage
47
12
 
48
13
  ```ts
49
14
  import { Module } from '@nestjs/common';
@@ -52,24 +17,11 @@ import { NestGraphInspectorModule } from 'nest-graph-inspector';
52
17
  @Module({
53
18
  imports: [NestGraphInspectorModule],
54
19
  })
55
- export class RootModule {}
20
+ export class AppModule {}
56
21
  ```
57
22
 
58
- Start your app — the viewer URL will be printed in your console.
59
-
60
- > For full configuration options and output types, see the **[documentation →](https://albasyir.github.io/nest-graph-inspector/getting-started)**
23
+ Start the Nest application to print the viewer URL.
61
24
 
62
25
  ## Documentation
63
26
 
64
- Full setup guide, configuration options, and use cases are available on the documentation site.
65
-
66
- <p align="center">
67
- <a href="https://albasyir.github.io/nest-graph-inspector/"><strong>📖 View Documentation →</strong></a>
68
- </p>
69
-
70
- ## Stay in touch
71
-
72
- - [Documentation](https://albasyir.github.io/nest-graph-inspector/)
73
- - [NPM Package](https://www.npmjs.com/package/nest-graph-inspector)
74
- - [GitHub Repository](https://github.com/albasyir/nest-graph-inspector)
75
- - [Maintainer, Abdul Aziz Al Basyir](https://github.com/albasyir)
27
+ See the [project documentation](https://albasyir.github.io/nest-graph-inspector/) for configuration options and output types.
@@ -0,0 +1,18 @@
1
+ import { HttpServeAdapter } from './http-serve.adapter';
2
+ import { RuntimeTraceRecorder } from '../runtime-trace.recorder';
3
+ import type { RuntimeTrace } from '../types/direct-run.type';
4
+ export declare class DirectRunOutputAdapter {
5
+ private readonly httpServeAdapter;
6
+ private readonly runtimeTraceRecorder;
7
+ constructor(httpServeAdapter: HttpServeAdapter, runtimeTraceRecorder: RuntimeTraceRecorder);
8
+ createRoute(path: string, instanceLookup: (moduleName: string, providerName: string) => unknown, onComplete?: (trace: RuntimeTrace) => void | Promise<void>): import("./http-serve.adapter").HttpServeRoute;
9
+ createHistoriesRoute(path: string): import("./http-serve.adapter").HttpServeRoute;
10
+ createHistoryIndexRoute(path: string): import("./http-serve.adapter").HttpServeRoute;
11
+ createHistoryTraceRoute(path: string): import("./http-serve.adapter").HttpServeRoute;
12
+ private readJsonBody;
13
+ private resolveArgs;
14
+ private badRequest;
15
+ private notFound;
16
+ private traceIdFromPath;
17
+ private historyIndexItem;
18
+ }
@@ -12,12 +12,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.DirectRunOutputAdapter = void 0;
13
13
  const common_1 = require("@nestjs/common");
14
14
  const http_serve_adapter_1 = require("./http-serve.adapter");
15
+ const runtime_trace_recorder_1 = require("../runtime-trace.recorder");
15
16
  let DirectRunOutputAdapter = class DirectRunOutputAdapter {
16
17
  httpServeAdapter;
17
- constructor(httpServeAdapter) {
18
+ runtimeTraceRecorder;
19
+ constructor(httpServeAdapter, runtimeTraceRecorder) {
18
20
  this.httpServeAdapter = httpServeAdapter;
21
+ this.runtimeTraceRecorder = runtimeTraceRecorder;
19
22
  }
20
- createRoute(path, instanceLookup) {
23
+ createRoute(path, instanceLookup, onComplete) {
21
24
  return this.httpServeAdapter.post(path, async ({ request }) => {
22
25
  const body = await this.readJsonBody(request);
23
26
  const moduleName = typeof body.module === 'string' ? body.module : '';
@@ -38,29 +41,76 @@ let DirectRunOutputAdapter = class DirectRunOutputAdapter {
38
41
  if (!argsResult.ok) {
39
42
  return argsResult.response;
40
43
  }
41
- try {
42
- const result = await method.call(instance, ...argsResult.args);
43
- const payload = {
44
- ok: true,
45
- method: methodName,
46
- result,
47
- };
48
- return {
49
- statusCode: 200,
50
- body: payload,
51
- };
52
- }
53
- catch (error) {
54
- const payload = {
55
- ok: false,
56
- method: methodName,
57
- error: error instanceof Error ? error.message : 'Direct run failed.',
58
- };
59
- return {
60
- statusCode: 500,
61
- body: payload,
62
- };
44
+ const traceIdentity = this.runtimeTraceRecorder.start({
45
+ moduleName,
46
+ providerName,
47
+ methodName,
48
+ args: argsResult.args,
49
+ });
50
+ const invokeMethod = async () => (await method.call(instance, ...argsResult.args));
51
+ const payload = await (async () => {
52
+ try {
53
+ const result = this.runtimeTraceRecorder.runWithContext
54
+ ? await this.runtimeTraceRecorder.runWithContext(traceIdentity, invokeMethod)
55
+ : await invokeMethod();
56
+ const runtimeTrace = await this.runtimeTraceRecorder.finishSuccess(traceIdentity, result);
57
+ return {
58
+ ok: true,
59
+ method: methodName,
60
+ result,
61
+ runId: traceIdentity.runId,
62
+ traceId: traceIdentity.traceId,
63
+ runtimeTrace,
64
+ };
65
+ }
66
+ catch (error) {
67
+ const runtimeTrace = await this.runtimeTraceRecorder.finishError(traceIdentity, error);
68
+ return {
69
+ ok: false,
70
+ method: methodName,
71
+ error: error instanceof Error ? error.message : 'Direct run failed.',
72
+ runId: traceIdentity.runId,
73
+ traceId: traceIdentity.traceId,
74
+ runtimeTrace,
75
+ };
76
+ }
77
+ })();
78
+ if (payload.runtimeTrace && onComplete) {
79
+ await onComplete(payload.runtimeTrace);
63
80
  }
81
+ return {
82
+ statusCode: 200,
83
+ body: payload,
84
+ };
85
+ }, {
86
+ responseHeaders: {
87
+ 'content-type': 'application/json; charset=utf-8',
88
+ },
89
+ });
90
+ }
91
+ createHistoriesRoute(path) {
92
+ return this.httpServeAdapter.get(path, () => this.runtimeTraceRecorder.getCompletedTraces(), {
93
+ responseHeaders: {
94
+ 'content-type': 'application/json; charset=utf-8',
95
+ },
96
+ });
97
+ }
98
+ createHistoryIndexRoute(path) {
99
+ return this.httpServeAdapter.get(path, () => this.runtimeTraceRecorder
100
+ .getCompletedTraces()
101
+ .map((trace) => this.historyIndexItem(trace)), {
102
+ responseHeaders: {
103
+ 'content-type': 'application/json; charset=utf-8',
104
+ },
105
+ });
106
+ }
107
+ createHistoryTraceRoute(path) {
108
+ return this.httpServeAdapter.get(`${path}/*`, ({ request }) => {
109
+ const traceId = this.traceIdFromPath(request.url ?? '', path);
110
+ const trace = traceId
111
+ ? this.runtimeTraceRecorder.getCompletedTrace(traceId)
112
+ : undefined;
113
+ return trace ?? this.notFound(`Trace ${traceId || ''} is unavailable.`);
64
114
  }, {
65
115
  responseHeaders: {
66
116
  'content-type': 'application/json; charset=utf-8',
@@ -101,11 +151,7 @@ let DirectRunOutputAdapter = class DirectRunOutputAdapter {
101
151
  }
102
152
  return {
103
153
  ok: true,
104
- args: parameterCount === 1
105
- ? [input]
106
- : Array.isArray(input)
107
- ? input
108
- : [input],
154
+ args: parameterCount === 1 ? [input] : Array.isArray(input) ? input : [input],
109
155
  };
110
156
  }
111
157
  badRequest(message) {
@@ -126,10 +172,24 @@ let DirectRunOutputAdapter = class DirectRunOutputAdapter {
126
172
  },
127
173
  };
128
174
  }
175
+ traceIdFromPath(url, basePath) {
176
+ const path = new URL(url, 'http://localhost').pathname;
177
+ const traceId = decodeURIComponent(path.slice(`${basePath.replace(/\/$/, '')}/`.length));
178
+ return traceId.replace(/\.json$/, '');
179
+ }
180
+ historyIndexItem(trace) {
181
+ return {
182
+ traceId: trace.traceId,
183
+ entrypoint: trace.entrypoint,
184
+ startedAt: trace.startedAt,
185
+ status: trace.status,
186
+ totalDurationMs: trace.totalDurationMs,
187
+ };
188
+ }
129
189
  };
130
190
  exports.DirectRunOutputAdapter = DirectRunOutputAdapter;
131
191
  exports.DirectRunOutputAdapter = DirectRunOutputAdapter = __decorate([
132
192
  (0, common_1.Injectable)(),
133
- __metadata("design:paramtypes", [http_serve_adapter_1.HttpServeAdapter])
193
+ __metadata("design:paramtypes", [http_serve_adapter_1.HttpServeAdapter,
194
+ runtime_trace_recorder_1.RuntimeTraceRecorder])
134
195
  ], DirectRunOutputAdapter);
135
- //# sourceMappingURL=direct-run-output.adapter.js.map
@@ -10,14 +10,18 @@ exports.FileOutputAdapter = void 0;
10
10
  const promises_1 = require("node:fs/promises");
11
11
  const common_1 = require("@nestjs/common");
12
12
  const node_path_1 = require("node:path");
13
+ const inspector_endpoint_info_1 = require("../inspector-endpoint-info");
13
14
  let FileOutputAdapter = class FileOutputAdapter {
14
15
  markdownTitle = 'NestJS Dependency Graph';
15
16
  arrowDirectionDescription = 'Arrow direction: `A --> B` means `A` depends on `B`.';
16
17
  nestCoreModuleName = 'NestJSCoreModule';
17
18
  async execute(graphOutput, config) {
18
19
  const filePath = (0, node_path_1.join)(process.cwd(), config.path);
20
+ const informationFilePath = (0, node_path_1.join)((0, node_path_1.dirname)(filePath), 'information.json');
19
21
  const markdownText = this.buildMarkdownText(graphOutput);
22
+ const inspectorEndpointInfo = await (0, inspector_endpoint_info_1.createInspectorEndpointInfo)(true);
20
23
  await (0, promises_1.mkdir)((0, node_path_1.dirname)(filePath), { recursive: true });
24
+ await (0, promises_1.writeFile)(informationFilePath, JSON.stringify(inspectorEndpointInfo, null, 2), 'utf8');
21
25
  await (0, promises_1.writeFile)(filePath, markdownText, 'utf8');
22
26
  return {
23
27
  message: `Graph inspector markdown output was written to ${filePath}`,
@@ -292,4 +296,3 @@ exports.FileOutputAdapter = FileOutputAdapter;
292
296
  exports.FileOutputAdapter = FileOutputAdapter = __decorate([
293
297
  (0, common_1.Injectable)()
294
298
  ], FileOutputAdapter);
295
- //# sourceMappingURL=file-output.adapter.js.map
@@ -12,7 +12,6 @@ interface HttpOutputInternalOptions {
12
12
  export declare class HttpOutputAdapter implements OutputAdapter<HttpOutputConfig> {
13
13
  private readonly fileOutputAdapter;
14
14
  private readonly httpServeAdapter;
15
- private static readonly inspectorEndpointInfo;
16
15
  static readonly defaultConfig: Readonly<Required<Pick<HttpOutputConfig, 'host' | 'port'>>>;
17
16
  constructor(fileOutputAdapter: FileOutputAdapter, httpServeAdapter: HttpServeAdapter);
18
17
  execute(graphOutput: GraphOutput, config: HttpOutputConfig & HttpOutputInternalOptions): Promise<{
@@ -12,6 +12,7 @@ var HttpOutputAdapter_1;
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
13
  exports.HttpOutputAdapter = void 0;
14
14
  const common_1 = require("@nestjs/common");
15
+ const inspector_endpoint_info_1 = require("../inspector-endpoint-info");
15
16
  const graph_output_schema_1 = require("../types/graph-output.schema");
16
17
  const file_output_adapter_1 = require("./file-output.adapter");
17
18
  const http_serve_adapter_1 = require("./http-serve.adapter");
@@ -19,9 +20,6 @@ let HttpOutputAdapter = class HttpOutputAdapter {
19
20
  static { HttpOutputAdapter_1 = this; }
20
21
  fileOutputAdapter;
21
22
  httpServeAdapter;
22
- static inspectorEndpointInfo = {
23
- for: 'nest-graph-inspector',
24
- };
25
23
  static defaultConfig = {
26
24
  host: '0.0.0.0',
27
25
  port: 53371,
@@ -37,6 +35,7 @@ let HttpOutputAdapter = class HttpOutputAdapter {
37
35
  const jsonOutputPath = this.joinPath(path, 'output.json');
38
36
  const jsonSchemaOutputPath = this.joinPath(path, 'output.schema.json');
39
37
  const markdownOutputPath = this.joinPath(path, 'output.md');
38
+ const inspectorEndpointInfo = await (0, inspector_endpoint_info_1.createInspectorEndpointInfo)(false);
40
39
  const isReuseHttpAdapter = !!config.httpAdapter;
41
40
  const httpAdapter = config.httpAdapter ?? this.httpServeAdapter;
42
41
  const registration = httpAdapter.register({
@@ -44,7 +43,7 @@ let HttpOutputAdapter = class HttpOutputAdapter {
44
43
  host: config.host,
45
44
  port: config.port,
46
45
  }, [
47
- httpAdapter.get(informationOutputPath, () => HttpOutputAdapter_1.inspectorEndpointInfo, {
46
+ httpAdapter.get(informationOutputPath, () => inspectorEndpointInfo, {
48
47
  responseHeaders: {
49
48
  'content-type': 'application/json; charset=utf-8',
50
49
  },
@@ -98,4 +97,3 @@ exports.HttpOutputAdapter = HttpOutputAdapter = HttpOutputAdapter_1 = __decorate
98
97
  __metadata("design:paramtypes", [file_output_adapter_1.FileOutputAdapter,
99
98
  http_serve_adapter_1.HttpServeAdapter])
100
99
  ], HttpOutputAdapter);
101
- //# sourceMappingURL=http-output.adapter.js.map
@@ -311,4 +311,3 @@ exports.HttpServeAdapter = HttpServeAdapter;
311
311
  exports.HttpServeAdapter = HttpServeAdapter = __decorate([
312
312
  (0, common_1.Injectable)()
313
313
  ], HttpServeAdapter);
314
- //# sourceMappingURL=http-serve.adapter.js.map
@@ -25,4 +25,3 @@ exports.JsonOutputAdapter = JsonOutputAdapter;
25
25
  exports.JsonOutputAdapter = JsonOutputAdapter = __decorate([
26
26
  (0, common_1.Injectable)()
27
27
  ], JsonOutputAdapter);
28
- //# sourceMappingURL=json-output.adapter.js.map
@@ -168,4 +168,3 @@ exports.ProxyAdapter = ProxyAdapter;
168
168
  exports.ProxyAdapter = ProxyAdapter = __decorate([
169
169
  (0, common_1.Injectable)()
170
170
  ], ProxyAdapter);
171
- //# sourceMappingURL=proxy.adapter.js.map
@@ -5,6 +5,7 @@ import { HttpOutputAdapter } from './http-output.adapter';
5
5
  import { ProxyAdapter } from './proxy.adapter';
6
6
  import { HttpServeAdapter } from './http-serve.adapter';
7
7
  import { DirectRunOutputAdapter } from './direct-run-output.adapter';
8
+ import { RuntimeTraceRecorder } from '../runtime-trace.recorder';
8
9
  type ViewerOutputConfig = Extract<NestGraphInspectorOutput, {
9
10
  type: 'viewer';
10
11
  }>;
@@ -13,13 +14,15 @@ export declare class ViewerOutputAdapter implements OutputAdapter<ViewerOutputCo
13
14
  private readonly proxyAdapter;
14
15
  private readonly httpServeAdapter;
15
16
  private readonly directRunOutputAdapter;
17
+ private readonly runtimeTraceRecorder;
16
18
  private readonly viewerBaseUrl;
17
- constructor(httpOutputAdapter: HttpOutputAdapter, proxyAdapter: ProxyAdapter, httpServeAdapter: HttpServeAdapter, directRunOutputAdapter: DirectRunOutputAdapter);
19
+ constructor(httpOutputAdapter: HttpOutputAdapter, proxyAdapter: ProxyAdapter, httpServeAdapter: HttpServeAdapter, directRunOutputAdapter: DirectRunOutputAdapter, runtimeTraceRecorder: RuntimeTraceRecorder);
18
20
  execute(graphOutput: GraphOutput, config: ViewerOutputConfig): Promise<{
19
21
  message: string;
20
22
  }>;
21
23
  private httpOrigin;
22
24
  private ollamaProxyOptions;
23
25
  private viewerCorsOptions;
26
+ private writeHistoryFiles;
24
27
  }
25
28
  export {};
@@ -15,18 +15,23 @@ const http_output_adapter_1 = require("./http-output.adapter");
15
15
  const proxy_adapter_1 = require("./proxy.adapter");
16
16
  const http_serve_adapter_1 = require("./http-serve.adapter");
17
17
  const direct_run_output_adapter_1 = require("./direct-run-output.adapter");
18
+ const promises_1 = require("node:fs/promises");
19
+ const node_path_1 = require("node:path");
20
+ const runtime_trace_recorder_1 = require("../runtime-trace.recorder");
18
21
  let ViewerOutputAdapter = class ViewerOutputAdapter {
19
22
  httpOutputAdapter;
20
23
  proxyAdapter;
21
24
  httpServeAdapter;
22
25
  directRunOutputAdapter;
26
+ runtimeTraceRecorder;
23
27
  viewerBaseUrl = process.env.____DEV_VIEWER_BASE_URL ||
24
28
  'https://albasyir.github.io/nest-graph-inspector';
25
- constructor(httpOutputAdapter, proxyAdapter, httpServeAdapter, directRunOutputAdapter) {
29
+ constructor(httpOutputAdapter, proxyAdapter, httpServeAdapter, directRunOutputAdapter, runtimeTraceRecorder) {
26
30
  this.httpOutputAdapter = httpOutputAdapter;
27
31
  this.proxyAdapter = proxyAdapter;
28
32
  this.httpServeAdapter = httpServeAdapter;
29
33
  this.directRunOutputAdapter = directRunOutputAdapter;
34
+ this.runtimeTraceRecorder = runtimeTraceRecorder;
30
35
  }
31
36
  async execute(graphOutput, config) {
32
37
  const internalConfig = config;
@@ -53,7 +58,14 @@ let ViewerOutputAdapter = class ViewerOutputAdapter {
53
58
  origin: this.httpOrigin(config),
54
59
  host: config.host,
55
60
  port: config.port,
56
- }, [this.directRunOutputAdapter.createRoute(internalConfig.directRun.path, (moduleName, providerName) => internalConfig.directRun?.instanceLookup(moduleName, providerName))]);
61
+ }, [
62
+ this.directRunOutputAdapter.createRoute(internalConfig.directRun.path, (moduleName, providerName) => internalConfig.directRun?.instanceLookup(moduleName, providerName), internalConfig.directRun.historyDirPath
63
+ ? (trace) => this.writeHistoryFiles(internalConfig.directRun.historyDirPath, trace)
64
+ : undefined),
65
+ this.directRunOutputAdapter.createHistoriesRoute(`${internalConfig.directRun.path}/histories`),
66
+ this.directRunOutputAdapter.createHistoryIndexRoute(`${internalConfig.directRun.path}/history/index.json`),
67
+ this.directRunOutputAdapter.createHistoryTraceRoute(`${internalConfig.directRun.path}/history`),
68
+ ]);
57
69
  }
58
70
  try {
59
71
  await this.httpServeAdapter.serve();
@@ -86,6 +98,20 @@ let ViewerOutputAdapter = class ViewerOutputAdapter {
86
98
  origins: [new URL(this.viewerBaseUrl).origin],
87
99
  };
88
100
  }
101
+ async writeHistoryFiles(dirPath, trace) {
102
+ const traceIndex = this.runtimeTraceRecorder
103
+ .getCompletedTraces()
104
+ .map((item) => ({
105
+ traceId: item.traceId,
106
+ entrypoint: item.entrypoint,
107
+ startedAt: item.startedAt,
108
+ status: item.status,
109
+ totalDurationMs: item.totalDurationMs,
110
+ }));
111
+ await (0, promises_1.mkdir)(dirPath, { recursive: true });
112
+ await (0, promises_1.writeFile)((0, node_path_1.join)(dirPath, `${trace.traceId}.json`), JSON.stringify(trace, null, 2));
113
+ await (0, promises_1.writeFile)((0, node_path_1.join)(dirPath, 'index.json'), JSON.stringify(traceIndex, null, 2));
114
+ }
89
115
  };
90
116
  exports.ViewerOutputAdapter = ViewerOutputAdapter;
91
117
  exports.ViewerOutputAdapter = ViewerOutputAdapter = __decorate([
@@ -93,6 +119,6 @@ exports.ViewerOutputAdapter = ViewerOutputAdapter = __decorate([
93
119
  __metadata("design:paramtypes", [http_output_adapter_1.HttpOutputAdapter,
94
120
  proxy_adapter_1.ProxyAdapter,
95
121
  http_serve_adapter_1.HttpServeAdapter,
96
- direct_run_output_adapter_1.DirectRunOutputAdapter])
122
+ direct_run_output_adapter_1.DirectRunOutputAdapter,
123
+ runtime_trace_recorder_1.RuntimeTraceRecorder])
97
124
  ], ViewerOutputAdapter);
98
- //# sourceMappingURL=viewer-output.adapter.js.map
@@ -2,3 +2,4 @@ export * from './nest-graph-inspector.module';
2
2
  export * from './nest-graph-inspector.type';
3
3
  export * from './types/graph-output.schema';
4
4
  export * from './types/graph-output.type';
5
+ export * from './types/direct-run.type';
@@ -18,4 +18,4 @@ __exportStar(require("./nest-graph-inspector.module"), exports);
18
18
  __exportStar(require("./nest-graph-inspector.type"), exports);
19
19
  __exportStar(require("./types/graph-output.schema"), exports);
20
20
  __exportStar(require("./types/graph-output.type"), exports);
21
- //# sourceMappingURL=index.js.map
21
+ __exportStar(require("./types/direct-run.type"), exports);
@@ -0,0 +1,7 @@
1
+ export declare const createInspectorEndpointInfo: (isStatic: boolean) => Promise<{
2
+ for: string;
3
+ 'is-static': boolean;
4
+ version: string;
5
+ latestVersion: string | null;
6
+ isLatestVersion: boolean;
7
+ }>;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createInspectorEndpointInfo = void 0;
4
+ const { version } = require('../package.json');
5
+ let latestVersionPromise;
6
+ const createInspectorEndpointInfo = async (isStatic) => {
7
+ const latestVersion = await getLatestVersion();
8
+ return {
9
+ for: 'nest-graph-inspector',
10
+ 'is-static': isStatic,
11
+ version,
12
+ latestVersion,
13
+ isLatestVersion: latestVersion === version,
14
+ };
15
+ };
16
+ exports.createInspectorEndpointInfo = createInspectorEndpointInfo;
17
+ const getLatestVersion = () => (latestVersionPromise ??= fetch('https://registry.npmjs.org/nest-graph-inspector/latest')
18
+ .then(async (response) => {
19
+ if (!response.ok) {
20
+ return null;
21
+ }
22
+ const metadata = await response.json();
23
+ return (typeof metadata === 'object' &&
24
+ metadata !== null &&
25
+ 'version' in metadata &&
26
+ typeof metadata.version === 'string' &&
27
+ metadata.version
28
+ ? metadata.version
29
+ : null);
30
+ })
31
+ .catch(() => null));
@@ -6,4 +6,3 @@ const common_1 = require("@nestjs/common");
6
6
  _a = new common_1.ConfigurableModuleBuilder()
7
7
  .setClassMethodName('forRoot')
8
8
  .build(), exports.ConfigurableModuleClass = _a.ConfigurableModuleClass, exports.MODULE_OPTIONS_TOKEN = _a.MODULE_OPTIONS_TOKEN;
9
- //# sourceMappingURL=nest-graph-inspector.config.js.map
@@ -17,6 +17,7 @@ const viewer_output_adapter_1 = require("./adapters/viewer-output.adapter");
17
17
  const proxy_adapter_1 = require("./adapters/proxy.adapter");
18
18
  const http_serve_adapter_1 = require("./adapters/http-serve.adapter");
19
19
  const direct_run_output_adapter_1 = require("./adapters/direct-run-output.adapter");
20
+ const runtime_trace_recorder_1 = require("./runtime-trace.recorder");
20
21
  exports.defaultOptions = {
21
22
  outputs: [
22
23
  {
@@ -58,9 +59,9 @@ exports.NestGraphInspectorModule = NestGraphInspectorModule = __decorate([
58
59
  http_serve_adapter_1.HttpServeAdapter,
59
60
  http_output_adapter_1.HttpOutputAdapter,
60
61
  proxy_adapter_1.ProxyAdapter,
62
+ runtime_trace_recorder_1.RuntimeTraceRecorder,
61
63
  direct_run_output_adapter_1.DirectRunOutputAdapter,
62
64
  viewer_output_adapter_1.ViewerOutputAdapter,
63
65
  ],
64
66
  })
65
67
  ], NestGraphInspectorModule);
66
- //# sourceMappingURL=nest-graph-inspector.module.js.map
@@ -6,6 +6,7 @@ import { HttpOutputAdapter } from './adapters/http-output.adapter';
6
6
  import { FileOutputAdapter } from './adapters/file-output.adapter';
7
7
  import { JsonOutputAdapter } from './adapters/json-output.adapter';
8
8
  import { ViewerOutputAdapter } from './adapters/viewer-output.adapter';
9
+ import { RuntimeTraceRecorder } from './runtime-trace.recorder';
9
10
  export declare class NestGraphInspectorSetup implements OnModuleInit {
10
11
  private readonly options;
11
12
  private readonly modulesContainer;
@@ -13,6 +14,7 @@ export declare class NestGraphInspectorSetup implements OnModuleInit {
13
14
  private readonly fileOutputAdapter;
14
15
  private readonly jsonOutputAdapter;
15
16
  private readonly viewerOutputAdapter;
17
+ private readonly runtimeTraceRecorder;
16
18
  private readonly logger;
17
19
  private readonly outputAdapters;
18
20
  private readonly ignoreProvider;
@@ -20,7 +22,8 @@ export declare class NestGraphInspectorSetup implements OnModuleInit {
20
22
  private readonly nestCoreModuleName;
21
23
  private readonly nestCoreProviders;
22
24
  private readonly tsMorphProject;
23
- constructor(options: NestGraphInspectorModuleOptions, modulesContainer: ModulesContainer, httpOutputAdapter: HttpOutputAdapter, fileOutputAdapter: FileOutputAdapter, jsonOutputAdapter: JsonOutputAdapter, viewerOutputAdapter: ViewerOutputAdapter);
25
+ private readonly runtimeTraceInstrumentedInstances;
26
+ constructor(options: NestGraphInspectorModuleOptions, modulesContainer: ModulesContainer, httpOutputAdapter: HttpOutputAdapter, fileOutputAdapter: FileOutputAdapter, jsonOutputAdapter: JsonOutputAdapter, viewerOutputAdapter: ViewerOutputAdapter, runtimeTraceRecorder: RuntimeTraceRecorder);
24
27
  onModuleInit(): Promise<void>;
25
28
  private inspectAndPublishGraph;
26
29
  private get hasOutput();
@@ -34,6 +37,7 @@ export declare class NestGraphInspectorSetup implements OnModuleInit {
34
37
  private publishSingleOutput;
35
38
  private withDefaultOutputOptions;
36
39
  private mergeViewerDirectRunOptions;
40
+ private getDirectRunHistoryDirPath;
37
41
  buildModuleMapFromAutoDetect(): ModuleMap;
38
42
  buildModuleMap(rootModuleClass: Type<unknown>): ModuleMap;
39
43
  private createModuleMapFromModuleTree;
@@ -41,6 +45,9 @@ export declare class NestGraphInspectorSetup implements OnModuleInit {
41
45
  private resolveModuleTree;
42
46
  private createModuleTreeReference;
43
47
  private resolveModuleMembers;
48
+ private instrumentRuntimeTrace;
49
+ private instrumentRuntimeTraceWrappers;
50
+ private instrumentRuntimeTraceInstance;
44
51
  private appendNestCoreModule;
45
52
  private findUsedNestCoreProvidersFromTree;
46
53
  private flattenModuleTree;