nest-graph-inspector 0.5.2 → 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 (72) 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/dist/adapters/direct-run-output.adapter.js +195 -0
  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.d.ts +2 -0
  9. package/{src → dist}/adapters/http-serve.adapter.js +16 -1
  10. package/{src → dist}/adapters/json-output.adapter.js +0 -1
  11. package/{src → dist}/adapters/proxy.adapter.js +0 -1
  12. package/{src → dist}/adapters/viewer-output.adapter.d.ts +6 -1
  13. package/{src → dist}/adapters/viewer-output.adapter.js +41 -3
  14. package/{src → dist}/index.d.ts +1 -0
  15. package/{src → dist}/index.js +1 -1
  16. package/dist/inspector-endpoint-info.d.ts +7 -0
  17. package/dist/inspector-endpoint-info.js +31 -0
  18. package/{src → dist}/nest-graph-inspector.config.js +0 -1
  19. package/{src → dist}/nest-graph-inspector.module.js +7 -1
  20. package/{src → dist}/nest-graph-inspector.setup.d.ts +19 -1
  21. package/{src → dist}/nest-graph-inspector.setup.js +303 -3
  22. package/{src → dist}/nest-graph-inspector.type.d.ts +4 -0
  23. package/dist/nest-graph-inspector.type.js +2 -0
  24. package/{src → dist}/ports/output.adapter.js +0 -1
  25. package/{src → dist}/ports/proxy.gateway.js +0 -1
  26. package/dist/runtime-trace.recorder.d.ts +42 -0
  27. package/dist/runtime-trace.recorder.js +299 -0
  28. package/dist/types/direct-run.type.d.ts +75 -0
  29. package/dist/types/direct-run.type.js +2 -0
  30. package/{src → dist}/types/graph-output.schema.d.ts +29 -0
  31. package/{src → dist}/types/graph-output.schema.js +29 -1
  32. package/{src → dist}/types/graph-output.type.d.ts +2 -0
  33. package/dist/types/graph-output.type.js +2 -0
  34. package/dist/types/module-controller.type.js +2 -0
  35. package/{src → dist}/types/module-map.type.js +0 -1
  36. package/dist/types/module-provider.type.js +2 -0
  37. package/{src → dist}/types/module.type.js +0 -1
  38. package/package.json +24 -8
  39. package/src/adapters/file-output.adapter.js.map +0 -1
  40. package/src/adapters/http-output.adapter.js.map +0 -1
  41. package/src/adapters/http-serve.adapter.js.map +0 -1
  42. package/src/adapters/json-output.adapter.js.map +0 -1
  43. package/src/adapters/proxy.adapter.js.map +0 -1
  44. package/src/adapters/viewer-output.adapter.js.map +0 -1
  45. package/src/index.js.map +0 -1
  46. package/src/nest-graph-inspector.config.js.map +0 -1
  47. package/src/nest-graph-inspector.module.js.map +0 -1
  48. package/src/nest-graph-inspector.setup.js.map +0 -1
  49. package/src/nest-graph-inspector.type.js +0 -3
  50. package/src/nest-graph-inspector.type.js.map +0 -1
  51. package/src/ports/output.adapter.js.map +0 -1
  52. package/src/ports/proxy.gateway.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/json-output.adapter.d.ts +0 -0
  64. /package/{src → dist}/adapters/proxy.adapter.d.ts +0 -0
  65. /package/{src → dist}/nest-graph-inspector.config.d.ts +0 -0
  66. /package/{src → dist}/nest-graph-inspector.module.d.ts +0 -0
  67. /package/{src → dist}/ports/output.adapter.d.ts +0 -0
  68. /package/{src → dist}/ports/proxy.gateway.d.ts +0 -0
  69. /package/{src → dist}/types/module-controller.type.d.ts +0 -0
  70. /package/{src → dist}/types/module-map.type.d.ts +0 -0
  71. /package/{src → dist}/types/module-provider.type.d.ts +0 -0
  72. /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
+ }
@@ -0,0 +1,195 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ 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;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.DirectRunOutputAdapter = void 0;
13
+ const common_1 = require("@nestjs/common");
14
+ const http_serve_adapter_1 = require("./http-serve.adapter");
15
+ const runtime_trace_recorder_1 = require("../runtime-trace.recorder");
16
+ let DirectRunOutputAdapter = class DirectRunOutputAdapter {
17
+ httpServeAdapter;
18
+ runtimeTraceRecorder;
19
+ constructor(httpServeAdapter, runtimeTraceRecorder) {
20
+ this.httpServeAdapter = httpServeAdapter;
21
+ this.runtimeTraceRecorder = runtimeTraceRecorder;
22
+ }
23
+ createRoute(path, instanceLookup, onComplete) {
24
+ return this.httpServeAdapter.post(path, async ({ request }) => {
25
+ const body = await this.readJsonBody(request);
26
+ const moduleName = typeof body.module === 'string' ? body.module : '';
27
+ const providerName = typeof body.provider === 'string' ? body.provider : '';
28
+ const methodName = typeof body.method === 'string' ? body.method : '';
29
+ if (!moduleName || !providerName || !methodName) {
30
+ return this.badRequest('module, provider, and method are required.');
31
+ }
32
+ const instance = instanceLookup(moduleName, providerName);
33
+ if (!instance) {
34
+ return this.notFound(`Provider ${moduleName}:${providerName} is unavailable.`);
35
+ }
36
+ const method = instance[methodName];
37
+ if (typeof method !== 'function') {
38
+ return this.badRequest(`Method ${methodName} is unavailable for direct run.`);
39
+ }
40
+ const argsResult = this.resolveArgs(body, methodName, method.length);
41
+ if (!argsResult.ok) {
42
+ return argsResult.response;
43
+ }
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);
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.`);
114
+ }, {
115
+ responseHeaders: {
116
+ 'content-type': 'application/json; charset=utf-8',
117
+ },
118
+ });
119
+ }
120
+ async readJsonBody(request) {
121
+ let body = '';
122
+ for await (const chunk of request) {
123
+ body += typeof chunk === 'string' ? chunk : chunk.toString('utf8');
124
+ }
125
+ if (!body.trim()) {
126
+ return {};
127
+ }
128
+ try {
129
+ return JSON.parse(body);
130
+ }
131
+ catch {
132
+ return {};
133
+ }
134
+ }
135
+ resolveArgs(body, methodName, parameterCount) {
136
+ if (!Object.prototype.hasOwnProperty.call(body, 'args')) {
137
+ if (parameterCount > 0) {
138
+ return {
139
+ ok: false,
140
+ response: this.badRequest(`Method ${methodName} requires arguments. Send args as JSON in the request body.`),
141
+ };
142
+ }
143
+ return { ok: true, args: [] };
144
+ }
145
+ const input = body.args;
146
+ if (parameterCount > 1 && !Array.isArray(input)) {
147
+ return {
148
+ ok: false,
149
+ response: this.badRequest(`Method ${methodName} expects ${parameterCount} arguments. Send args as a JSON array.`),
150
+ };
151
+ }
152
+ return {
153
+ ok: true,
154
+ args: parameterCount === 1 ? [input] : Array.isArray(input) ? input : [input],
155
+ };
156
+ }
157
+ badRequest(message) {
158
+ return {
159
+ statusCode: 400,
160
+ body: {
161
+ ok: false,
162
+ error: message,
163
+ },
164
+ };
165
+ }
166
+ notFound(message) {
167
+ return {
168
+ statusCode: 404,
169
+ body: {
170
+ ok: false,
171
+ error: message,
172
+ },
173
+ };
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
+ }
189
+ };
190
+ exports.DirectRunOutputAdapter = DirectRunOutputAdapter;
191
+ exports.DirectRunOutputAdapter = DirectRunOutputAdapter = __decorate([
192
+ (0, common_1.Injectable)(),
193
+ __metadata("design:paramtypes", [http_serve_adapter_1.HttpServeAdapter,
194
+ runtime_trace_recorder_1.RuntimeTraceRecorder])
195
+ ], DirectRunOutputAdapter);
@@ -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
@@ -52,6 +52,8 @@ export declare class HttpServeAdapter implements OnModuleDestroy {
52
52
  private headerValue;
53
53
  private contentTypeHeader;
54
54
  private setCorsHeaders;
55
+ private sendCorsPreflight;
56
+ private isCorsPreflightRequest;
55
57
  private resolveDynamicPort;
56
58
  private normalizeOrigin;
57
59
  private normalizePath;
@@ -93,6 +93,10 @@ let HttpServeAdapter = class HttpServeAdapter {
93
93
  this.setCorsHeaders(res);
94
94
  const route = this.route(originUrl, routes, req);
95
95
  if (!route) {
96
+ if (this.isCorsPreflightRequest(req)) {
97
+ this.sendCorsPreflight(res);
98
+ return;
99
+ }
96
100
  this.sendText(res, 404, 'Not Found');
97
101
  return;
98
102
  }
@@ -250,8 +254,20 @@ let HttpServeAdapter = class HttpServeAdapter {
250
254
  }
251
255
  setCorsHeaders(res) {
252
256
  res.setHeader('Access-Control-Allow-Origin', '*');
257
+ res.setHeader('Access-Control-Allow-Methods', 'GET,POST,PUT,PATCH,DELETE,OPTIONS');
253
258
  res.setHeader('Access-Control-Allow-Headers', '*');
254
259
  }
260
+ sendCorsPreflight(res) {
261
+ res.writeHead(204, {
262
+ 'content-length': 0,
263
+ });
264
+ res.end();
265
+ }
266
+ isCorsPreflightRequest(req) {
267
+ return (req.method === 'OPTIONS' &&
268
+ typeof req.headers.origin === 'string' &&
269
+ typeof req.headers['access-control-request-method'] === 'string');
270
+ }
255
271
  resolveDynamicPort(state) {
256
272
  if (state.originUrl.port !== '0') {
257
273
  return;
@@ -295,4 +311,3 @@ exports.HttpServeAdapter = HttpServeAdapter;
295
311
  exports.HttpServeAdapter = HttpServeAdapter = __decorate([
296
312
  (0, common_1.Injectable)()
297
313
  ], HttpServeAdapter);
298
- //# 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
@@ -4,6 +4,8 @@ import type { GraphOutput } from '../types/graph-output.type';
4
4
  import { HttpOutputAdapter } from './http-output.adapter';
5
5
  import { ProxyAdapter } from './proxy.adapter';
6
6
  import { HttpServeAdapter } from './http-serve.adapter';
7
+ import { DirectRunOutputAdapter } from './direct-run-output.adapter';
8
+ import { RuntimeTraceRecorder } from '../runtime-trace.recorder';
7
9
  type ViewerOutputConfig = Extract<NestGraphInspectorOutput, {
8
10
  type: 'viewer';
9
11
  }>;
@@ -11,13 +13,16 @@ export declare class ViewerOutputAdapter implements OutputAdapter<ViewerOutputCo
11
13
  private readonly httpOutputAdapter;
12
14
  private readonly proxyAdapter;
13
15
  private readonly httpServeAdapter;
16
+ private readonly directRunOutputAdapter;
17
+ private readonly runtimeTraceRecorder;
14
18
  private readonly viewerBaseUrl;
15
- constructor(httpOutputAdapter: HttpOutputAdapter, proxyAdapter: ProxyAdapter, httpServeAdapter: HttpServeAdapter);
19
+ constructor(httpOutputAdapter: HttpOutputAdapter, proxyAdapter: ProxyAdapter, httpServeAdapter: HttpServeAdapter, directRunOutputAdapter: DirectRunOutputAdapter, runtimeTraceRecorder: RuntimeTraceRecorder);
16
20
  execute(graphOutput: GraphOutput, config: ViewerOutputConfig): Promise<{
17
21
  message: string;
18
22
  }>;
19
23
  private httpOrigin;
20
24
  private ollamaProxyOptions;
21
25
  private viewerCorsOptions;
26
+ private writeHistoryFiles;
22
27
  }
23
28
  export {};
@@ -14,18 +14,27 @@ const common_1 = require("@nestjs/common");
14
14
  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
+ 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");
17
21
  let ViewerOutputAdapter = class ViewerOutputAdapter {
18
22
  httpOutputAdapter;
19
23
  proxyAdapter;
20
24
  httpServeAdapter;
25
+ directRunOutputAdapter;
26
+ runtimeTraceRecorder;
21
27
  viewerBaseUrl = process.env.____DEV_VIEWER_BASE_URL ||
22
28
  'https://albasyir.github.io/nest-graph-inspector';
23
- constructor(httpOutputAdapter, proxyAdapter, httpServeAdapter) {
29
+ constructor(httpOutputAdapter, proxyAdapter, httpServeAdapter, directRunOutputAdapter, runtimeTraceRecorder) {
24
30
  this.httpOutputAdapter = httpOutputAdapter;
25
31
  this.proxyAdapter = proxyAdapter;
26
32
  this.httpServeAdapter = httpServeAdapter;
33
+ this.directRunOutputAdapter = directRunOutputAdapter;
34
+ this.runtimeTraceRecorder = runtimeTraceRecorder;
27
35
  }
28
36
  async execute(graphOutput, config) {
37
+ const internalConfig = config;
29
38
  const path = this.httpOutputAdapter.normalizePath(config.path ?? '/__graph-inspector');
30
39
  const ollama = this.ollamaProxyOptions(config);
31
40
  await this.httpOutputAdapter.execute(graphOutput, {
@@ -44,6 +53,20 @@ let ViewerOutputAdapter = class ViewerOutputAdapter {
44
53
  httpAdapter: this.httpServeAdapter,
45
54
  pathPrefix: ollama.path,
46
55
  });
56
+ if (internalConfig.directRun?.path) {
57
+ this.httpServeAdapter.register({
58
+ origin: this.httpOrigin(config),
59
+ host: config.host,
60
+ port: config.port,
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
+ ]);
69
+ }
47
70
  try {
48
71
  await this.httpServeAdapter.serve();
49
72
  }
@@ -75,12 +98,27 @@ let ViewerOutputAdapter = class ViewerOutputAdapter {
75
98
  origins: [new URL(this.viewerBaseUrl).origin],
76
99
  };
77
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
+ }
78
115
  };
79
116
  exports.ViewerOutputAdapter = ViewerOutputAdapter;
80
117
  exports.ViewerOutputAdapter = ViewerOutputAdapter = __decorate([
81
118
  (0, common_1.Injectable)(),
82
119
  __metadata("design:paramtypes", [http_output_adapter_1.HttpOutputAdapter,
83
120
  proxy_adapter_1.ProxyAdapter,
84
- http_serve_adapter_1.HttpServeAdapter])
121
+ http_serve_adapter_1.HttpServeAdapter,
122
+ direct_run_output_adapter_1.DirectRunOutputAdapter,
123
+ runtime_trace_recorder_1.RuntimeTraceRecorder])
85
124
  ], ViewerOutputAdapter);
86
- //# 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
@@ -16,6 +16,8 @@ const http_output_adapter_1 = require("./adapters/http-output.adapter");
16
16
  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
+ const direct_run_output_adapter_1 = require("./adapters/direct-run-output.adapter");
20
+ const runtime_trace_recorder_1 = require("./runtime-trace.recorder");
19
21
  exports.defaultOptions = {
20
22
  outputs: [
21
23
  {
@@ -25,6 +27,9 @@ exports.defaultOptions = {
25
27
  origin: 'http://localhost:11434',
26
28
  path: '/ollama',
27
29
  },
30
+ directRun: {
31
+ path: '/direct-run',
32
+ },
28
33
  },
29
34
  ],
30
35
  ignoreProvider: ['ModuleRef', 'ApplicationConfig'],
@@ -54,8 +59,9 @@ exports.NestGraphInspectorModule = NestGraphInspectorModule = __decorate([
54
59
  http_serve_adapter_1.HttpServeAdapter,
55
60
  http_output_adapter_1.HttpOutputAdapter,
56
61
  proxy_adapter_1.ProxyAdapter,
62
+ runtime_trace_recorder_1.RuntimeTraceRecorder,
63
+ direct_run_output_adapter_1.DirectRunOutputAdapter,
57
64
  viewer_output_adapter_1.ViewerOutputAdapter,
58
65
  ],
59
66
  })
60
67
  ], NestGraphInspectorModule);
61
- //# sourceMappingURL=nest-graph-inspector.module.js.map