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.
- package/LICENSE +21 -0
- package/README.md +8 -56
- package/dist/adapters/direct-run-output.adapter.d.ts +18 -0
- package/dist/adapters/direct-run-output.adapter.js +195 -0
- package/{src → dist}/adapters/file-output.adapter.js +4 -1
- package/{src → dist}/adapters/http-output.adapter.d.ts +0 -1
- package/{src → dist}/adapters/http-output.adapter.js +3 -5
- package/{src → dist}/adapters/http-serve.adapter.d.ts +2 -0
- package/{src → dist}/adapters/http-serve.adapter.js +16 -1
- package/{src → dist}/adapters/json-output.adapter.js +0 -1
- package/{src → dist}/adapters/proxy.adapter.js +0 -1
- package/{src → dist}/adapters/viewer-output.adapter.d.ts +6 -1
- package/{src → dist}/adapters/viewer-output.adapter.js +41 -3
- package/{src → dist}/index.d.ts +1 -0
- package/{src → dist}/index.js +1 -1
- package/dist/inspector-endpoint-info.d.ts +7 -0
- package/dist/inspector-endpoint-info.js +31 -0
- package/{src → dist}/nest-graph-inspector.config.js +0 -1
- package/{src → dist}/nest-graph-inspector.module.js +7 -1
- package/{src → dist}/nest-graph-inspector.setup.d.ts +19 -1
- package/{src → dist}/nest-graph-inspector.setup.js +303 -3
- package/{src → dist}/nest-graph-inspector.type.d.ts +4 -0
- package/dist/nest-graph-inspector.type.js +2 -0
- package/{src → dist}/ports/output.adapter.js +0 -1
- package/{src → dist}/ports/proxy.gateway.js +0 -1
- package/dist/runtime-trace.recorder.d.ts +42 -0
- package/dist/runtime-trace.recorder.js +299 -0
- package/dist/types/direct-run.type.d.ts +75 -0
- package/dist/types/direct-run.type.js +2 -0
- package/{src → dist}/types/graph-output.schema.d.ts +29 -0
- package/{src → dist}/types/graph-output.schema.js +29 -1
- package/{src → dist}/types/graph-output.type.d.ts +2 -0
- package/dist/types/graph-output.type.js +2 -0
- package/dist/types/module-controller.type.js +2 -0
- package/{src → dist}/types/module-map.type.js +0 -1
- package/dist/types/module-provider.type.js +2 -0
- package/{src → dist}/types/module.type.js +0 -1
- package/package.json +24 -8
- package/src/adapters/file-output.adapter.js.map +0 -1
- package/src/adapters/http-output.adapter.js.map +0 -1
- package/src/adapters/http-serve.adapter.js.map +0 -1
- package/src/adapters/json-output.adapter.js.map +0 -1
- package/src/adapters/proxy.adapter.js.map +0 -1
- package/src/adapters/viewer-output.adapter.js.map +0 -1
- package/src/index.js.map +0 -1
- package/src/nest-graph-inspector.config.js.map +0 -1
- package/src/nest-graph-inspector.module.js.map +0 -1
- package/src/nest-graph-inspector.setup.js.map +0 -1
- package/src/nest-graph-inspector.type.js +0 -3
- package/src/nest-graph-inspector.type.js.map +0 -1
- package/src/ports/output.adapter.js.map +0 -1
- package/src/ports/proxy.gateway.js.map +0 -1
- package/src/types/graph-output.schema.js.map +0 -1
- package/src/types/graph-output.type.js +0 -3
- package/src/types/graph-output.type.js.map +0 -1
- package/src/types/module-controller.type.js +0 -3
- package/src/types/module-controller.type.js.map +0 -1
- package/src/types/module-map.type.js.map +0 -1
- package/src/types/module-provider.type.js +0 -3
- package/src/types/module-provider.type.js.map +0 -1
- package/src/types/module.type.js.map +0 -1
- /package/{src → dist}/adapters/file-output.adapter.d.ts +0 -0
- /package/{src → dist}/adapters/json-output.adapter.d.ts +0 -0
- /package/{src → dist}/adapters/proxy.adapter.d.ts +0 -0
- /package/{src → dist}/nest-graph-inspector.config.d.ts +0 -0
- /package/{src → dist}/nest-graph-inspector.module.d.ts +0 -0
- /package/{src → dist}/ports/output.adapter.d.ts +0 -0
- /package/{src → dist}/ports/proxy.gateway.d.ts +0 -0
- /package/{src → dist}/types/module-controller.type.d.ts +0 -0
- /package/{src → dist}/types/module-map.type.d.ts +0 -0
- /package/{src → dist}/types/module-provider.type.d.ts +0 -0
- /package/{src → dist}/types/module.type.d.ts +0 -0
|
@@ -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
|
-
|
|
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();
|
|
@@ -33,6 +36,8 @@ export declare class NestGraphInspectorSetup implements OnModuleInit {
|
|
|
33
36
|
private publishOutputs;
|
|
34
37
|
private publishSingleOutput;
|
|
35
38
|
private withDefaultOutputOptions;
|
|
39
|
+
private mergeViewerDirectRunOptions;
|
|
40
|
+
private getDirectRunHistoryDirPath;
|
|
36
41
|
buildModuleMapFromAutoDetect(): ModuleMap;
|
|
37
42
|
buildModuleMap(rootModuleClass: Type<unknown>): ModuleMap;
|
|
38
43
|
private createModuleMapFromModuleTree;
|
|
@@ -40,6 +45,9 @@ export declare class NestGraphInspectorSetup implements OnModuleInit {
|
|
|
40
45
|
private resolveModuleTree;
|
|
41
46
|
private createModuleTreeReference;
|
|
42
47
|
private resolveModuleMembers;
|
|
48
|
+
private instrumentRuntimeTrace;
|
|
49
|
+
private instrumentRuntimeTraceWrappers;
|
|
50
|
+
private instrumentRuntimeTraceInstance;
|
|
43
51
|
private appendNestCoreModule;
|
|
44
52
|
private findUsedNestCoreProvidersFromTree;
|
|
45
53
|
private flattenModuleTree;
|
|
@@ -69,6 +77,16 @@ export declare class NestGraphInspectorSetup implements OnModuleInit {
|
|
|
69
77
|
private moduleName;
|
|
70
78
|
private tokenName;
|
|
71
79
|
private enrichModuleMap;
|
|
80
|
+
private resolveDirectRunProviderMeta;
|
|
81
|
+
private findDirectRunProviderInstance;
|
|
82
|
+
private getDirectRunMethods;
|
|
83
|
+
private getDirectRunMethodParameterTypes;
|
|
84
|
+
private extractMethodParameterTypesFromProject;
|
|
85
|
+
private extractMethodParameterNamesFromFunctionSource;
|
|
86
|
+
private typeToTypeScriptCode;
|
|
87
|
+
private wrapArrayItemType;
|
|
88
|
+
private propertyNameToTypeScriptCode;
|
|
89
|
+
private typeAllowsUndefined;
|
|
72
90
|
private findGraphCycles;
|
|
73
91
|
private findModuleCycles;
|
|
74
92
|
private findDependencyCycles;
|
|
@@ -25,6 +25,7 @@ const file_output_adapter_1 = require("./adapters/file-output.adapter");
|
|
|
25
25
|
const json_output_adapter_1 = require("./adapters/json-output.adapter");
|
|
26
26
|
const viewer_output_adapter_1 = require("./adapters/viewer-output.adapter");
|
|
27
27
|
const ts_morph_1 = require("ts-morph");
|
|
28
|
+
const runtime_trace_recorder_1 = require("./runtime-trace.recorder");
|
|
28
29
|
let NestGraphInspectorSetup = NestGraphInspectorSetup_1 = class NestGraphInspectorSetup {
|
|
29
30
|
options;
|
|
30
31
|
modulesContainer;
|
|
@@ -32,6 +33,7 @@ let NestGraphInspectorSetup = NestGraphInspectorSetup_1 = class NestGraphInspect
|
|
|
32
33
|
fileOutputAdapter;
|
|
33
34
|
jsonOutputAdapter;
|
|
34
35
|
viewerOutputAdapter;
|
|
36
|
+
runtimeTraceRecorder;
|
|
35
37
|
logger = new common_1.Logger(NestGraphInspectorSetup_1.name);
|
|
36
38
|
outputAdapters;
|
|
37
39
|
ignoreProvider;
|
|
@@ -39,13 +41,15 @@ let NestGraphInspectorSetup = NestGraphInspectorSetup_1 = class NestGraphInspect
|
|
|
39
41
|
nestCoreModuleName;
|
|
40
42
|
nestCoreProviders;
|
|
41
43
|
tsMorphProject = this.createTsMorphProject();
|
|
42
|
-
|
|
44
|
+
runtimeTraceInstrumentedInstances = new WeakSet();
|
|
45
|
+
constructor(options, modulesContainer, httpOutputAdapter, fileOutputAdapter, jsonOutputAdapter, viewerOutputAdapter, runtimeTraceRecorder) {
|
|
43
46
|
this.options = options;
|
|
44
47
|
this.modulesContainer = modulesContainer;
|
|
45
48
|
this.httpOutputAdapter = httpOutputAdapter;
|
|
46
49
|
this.fileOutputAdapter = fileOutputAdapter;
|
|
47
50
|
this.jsonOutputAdapter = jsonOutputAdapter;
|
|
48
51
|
this.viewerOutputAdapter = viewerOutputAdapter;
|
|
52
|
+
this.runtimeTraceRecorder = runtimeTraceRecorder;
|
|
49
53
|
this.outputAdapters = {
|
|
50
54
|
http: this.httpOutputAdapter,
|
|
51
55
|
markdown: this.fileOutputAdapter,
|
|
@@ -98,6 +102,7 @@ let NestGraphInspectorSetup = NestGraphInspectorSetup_1 = class NestGraphInspect
|
|
|
98
102
|
getModuleTree(rootModule) {
|
|
99
103
|
const moduleTree = this.resolveModuleTree(rootModule);
|
|
100
104
|
this.resolveModuleMembers(moduleTree);
|
|
105
|
+
this.instrumentRuntimeTrace(moduleTree);
|
|
101
106
|
this.appendNestCoreModule(moduleTree);
|
|
102
107
|
return moduleTree;
|
|
103
108
|
}
|
|
@@ -147,8 +152,26 @@ let NestGraphInspectorSetup = NestGraphInspectorSetup_1 = class NestGraphInspect
|
|
|
147
152
|
...defaultViewerOutput.ollama,
|
|
148
153
|
...output.ollama,
|
|
149
154
|
},
|
|
155
|
+
directRun: this.mergeViewerDirectRunOptions(defaultViewerOutput.directRun, output.directRun),
|
|
150
156
|
};
|
|
151
157
|
}
|
|
158
|
+
mergeViewerDirectRunOptions(defaultOptions, outputOptions) {
|
|
159
|
+
const path = outputOptions?.path ?? defaultOptions?.path;
|
|
160
|
+
if (!path) {
|
|
161
|
+
return undefined;
|
|
162
|
+
}
|
|
163
|
+
return {
|
|
164
|
+
path,
|
|
165
|
+
historyDirPath: this.getDirectRunHistoryDirPath(),
|
|
166
|
+
instanceLookup: (moduleName, providerName) => this.findDirectRunProviderInstance(moduleName, providerName),
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
getDirectRunHistoryDirPath() {
|
|
170
|
+
const jsonOutput = this.options.outputs?.find((output) => output.type === 'json');
|
|
171
|
+
return jsonOutput?.type === 'json'
|
|
172
|
+
? (0, node_path_1.join)(process.cwd(), (0, node_path_1.dirname)(jsonOutput.path), 'direct-run', 'history')
|
|
173
|
+
: undefined;
|
|
174
|
+
}
|
|
152
175
|
buildModuleMapFromAutoDetect() {
|
|
153
176
|
const root = this.findRootModule();
|
|
154
177
|
const moduleTree = this.getModuleTree(root);
|
|
@@ -223,6 +246,74 @@ let NestGraphInspectorSetup = NestGraphInspectorSetup_1 = class NestGraphInspect
|
|
|
223
246
|
node.controllers = this.extractControllers(node.moduleRef, node.name);
|
|
224
247
|
});
|
|
225
248
|
}
|
|
249
|
+
instrumentRuntimeTrace(moduleTree) {
|
|
250
|
+
this.walkModuleTree(moduleTree, (node) => {
|
|
251
|
+
if (!node.moduleRef) {
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
this.instrumentRuntimeTraceWrappers({
|
|
255
|
+
moduleName: node.name,
|
|
256
|
+
type: 'provider',
|
|
257
|
+
wrappers: node.moduleRef.providers.values(),
|
|
258
|
+
shouldIgnore: (name) => name === node.name || this.ignoreProvider.includes(name),
|
|
259
|
+
});
|
|
260
|
+
this.instrumentRuntimeTraceWrappers({
|
|
261
|
+
moduleName: node.name,
|
|
262
|
+
type: 'controller',
|
|
263
|
+
wrappers: node.moduleRef.controllers.values(),
|
|
264
|
+
});
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
instrumentRuntimeTraceWrappers(param) {
|
|
268
|
+
for (const wrapper of param.wrappers) {
|
|
269
|
+
const instance = wrapper.instance;
|
|
270
|
+
if (!instance || typeof instance !== 'object') {
|
|
271
|
+
continue;
|
|
272
|
+
}
|
|
273
|
+
const className = this.wrapperClassName(wrapper);
|
|
274
|
+
if (!className || param.shouldIgnore?.(className)) {
|
|
275
|
+
continue;
|
|
276
|
+
}
|
|
277
|
+
this.instrumentRuntimeTraceInstance({
|
|
278
|
+
instance,
|
|
279
|
+
moduleName: param.moduleName,
|
|
280
|
+
className,
|
|
281
|
+
type: param.type,
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
instrumentRuntimeTraceInstance(param) {
|
|
286
|
+
if (this.runtimeTraceInstrumentedInstances.has(param.instance)) {
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
this.runtimeTraceInstrumentedInstances.add(param.instance);
|
|
290
|
+
const prototype = Object.getPrototypeOf(param.instance);
|
|
291
|
+
if (!prototype) {
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
for (const methodName of Object.getOwnPropertyNames(prototype)) {
|
|
295
|
+
if (methodName === 'constructor') {
|
|
296
|
+
continue;
|
|
297
|
+
}
|
|
298
|
+
const descriptor = Object.getOwnPropertyDescriptor(prototype, methodName);
|
|
299
|
+
const method = descriptor?.value;
|
|
300
|
+
if (typeof method !== 'function') {
|
|
301
|
+
continue;
|
|
302
|
+
}
|
|
303
|
+
Object.defineProperty(param.instance, methodName, {
|
|
304
|
+
configurable: true,
|
|
305
|
+
writable: true,
|
|
306
|
+
value: (...args) => this.runtimeTraceRecorder.recordSpan({
|
|
307
|
+
name: `${param.className}.${methodName}`,
|
|
308
|
+
type: param.type,
|
|
309
|
+
moduleName: param.moduleName,
|
|
310
|
+
className: param.className,
|
|
311
|
+
methodName,
|
|
312
|
+
args: this.runtimeTraceRecorder.previewValue(args),
|
|
313
|
+
}, () => method.apply(param.instance, args)),
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
}
|
|
226
317
|
appendNestCoreModule(moduleTree) {
|
|
227
318
|
const usedProviders = this.findUsedNestCoreProvidersFromTree(moduleTree);
|
|
228
319
|
if (!usedProviders.length) {
|
|
@@ -557,6 +648,7 @@ let NestGraphInspectorSetup = NestGraphInspectorSetup_1 = class NestGraphInspect
|
|
|
557
648
|
providers: moduleData.providers.map((provider) => ({
|
|
558
649
|
...provider,
|
|
559
650
|
dependencies: provider.dependencies.map((dep) => this.enrichDependency(dep, moduleName)),
|
|
651
|
+
directRun: this.resolveDirectRunProviderMeta(provider.name, moduleName),
|
|
560
652
|
})),
|
|
561
653
|
controllers: moduleData.controllers.map((controller) => ({
|
|
562
654
|
...controller,
|
|
@@ -570,6 +662,214 @@ let NestGraphInspectorSetup = NestGraphInspectorSetup_1 = class NestGraphInspect
|
|
|
570
662
|
cycles: this.findGraphCycles(enrichedModules),
|
|
571
663
|
};
|
|
572
664
|
}
|
|
665
|
+
resolveDirectRunProviderMeta(providerName, moduleName) {
|
|
666
|
+
const instance = this.findDirectRunProviderInstance(moduleName, providerName);
|
|
667
|
+
if (!instance) {
|
|
668
|
+
return undefined;
|
|
669
|
+
}
|
|
670
|
+
const methods = this.getDirectRunMethods(instance);
|
|
671
|
+
if (!methods.length) {
|
|
672
|
+
return undefined;
|
|
673
|
+
}
|
|
674
|
+
return {
|
|
675
|
+
methods,
|
|
676
|
+
};
|
|
677
|
+
}
|
|
678
|
+
findDirectRunProviderInstance(moduleName, providerName) {
|
|
679
|
+
const moduleRef = [...this.modulesContainer.values()].find((candidate) => this.moduleName(candidate) === moduleName);
|
|
680
|
+
if (!moduleRef) {
|
|
681
|
+
return undefined;
|
|
682
|
+
}
|
|
683
|
+
const providerWrapper = [...moduleRef.providers.values()].find((wrapper) => {
|
|
684
|
+
const instance = wrapper.instance &&
|
|
685
|
+
(typeof wrapper.instance === 'object' ||
|
|
686
|
+
typeof wrapper.instance === 'function')
|
|
687
|
+
? wrapper.instance
|
|
688
|
+
: null;
|
|
689
|
+
const resolvedName = wrapper.metatype?.name ||
|
|
690
|
+
instance?.constructor?.name ||
|
|
691
|
+
this.tokenName(wrapper.token);
|
|
692
|
+
return resolvedName === providerName;
|
|
693
|
+
});
|
|
694
|
+
return providerWrapper?.instance;
|
|
695
|
+
}
|
|
696
|
+
getDirectRunMethods(instance) {
|
|
697
|
+
if (!instance ||
|
|
698
|
+
(typeof instance !== 'object' && typeof instance !== 'function')) {
|
|
699
|
+
return [];
|
|
700
|
+
}
|
|
701
|
+
const prototype = Object.getPrototypeOf(instance);
|
|
702
|
+
if (!prototype || prototype === Object.prototype) {
|
|
703
|
+
return [];
|
|
704
|
+
}
|
|
705
|
+
const methods = Object.getOwnPropertyNames(prototype)
|
|
706
|
+
.filter((name) => name !== 'constructor')
|
|
707
|
+
.map((name) => {
|
|
708
|
+
const candidate = prototype[name];
|
|
709
|
+
if (typeof candidate !== 'function') {
|
|
710
|
+
return null;
|
|
711
|
+
}
|
|
712
|
+
const method = candidate;
|
|
713
|
+
const parameterTypes = this.getDirectRunMethodParameterTypes({
|
|
714
|
+
instance,
|
|
715
|
+
method,
|
|
716
|
+
methodName: name,
|
|
717
|
+
});
|
|
718
|
+
return {
|
|
719
|
+
name,
|
|
720
|
+
parameterTypes,
|
|
721
|
+
};
|
|
722
|
+
})
|
|
723
|
+
.filter((method) => method !== null)
|
|
724
|
+
.sort((left, right) => left.name.localeCompare(right.name));
|
|
725
|
+
return [
|
|
726
|
+
...new Map(methods.map((method) => [method.name, method])).values(),
|
|
727
|
+
];
|
|
728
|
+
}
|
|
729
|
+
getDirectRunMethodParameterTypes(param) {
|
|
730
|
+
const { instance, method, methodName } = param;
|
|
731
|
+
const className = typeof instance === 'function'
|
|
732
|
+
? instance.name
|
|
733
|
+
: instance.constructor?.name;
|
|
734
|
+
const sourceTypes = className
|
|
735
|
+
? this.extractMethodParameterTypesFromProject(className, methodName)
|
|
736
|
+
: undefined;
|
|
737
|
+
if (sourceTypes) {
|
|
738
|
+
return sourceTypes;
|
|
739
|
+
}
|
|
740
|
+
const runtimeNames = this.extractMethodParameterNamesFromFunctionSource(methodName, method);
|
|
741
|
+
if (!runtimeNames?.length) {
|
|
742
|
+
return '[]';
|
|
743
|
+
}
|
|
744
|
+
return `[${runtimeNames.map((name) => `${name}: unknown`).join(', ')}]`;
|
|
745
|
+
}
|
|
746
|
+
extractMethodParameterTypesFromProject(className, methodName) {
|
|
747
|
+
const targetClass = this.tsMorphProject
|
|
748
|
+
.getSourceFiles()
|
|
749
|
+
.flatMap((sourceFile) => sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.ClassDeclaration))
|
|
750
|
+
.find((classDeclaration) => classDeclaration.getName() === className);
|
|
751
|
+
const method = targetClass?.getInstanceMethod(methodName);
|
|
752
|
+
if (!method) {
|
|
753
|
+
return undefined;
|
|
754
|
+
}
|
|
755
|
+
const parameters = method.getParameters();
|
|
756
|
+
return `[${parameters
|
|
757
|
+
.map((parameter) => `${parameter.getName()}: ${this.typeToTypeScriptCode(parameter.getType(), parameter)}`)
|
|
758
|
+
.join(', ')}]`;
|
|
759
|
+
}
|
|
760
|
+
extractMethodParameterNamesFromFunctionSource(methodName, method) {
|
|
761
|
+
const methodSource = method.toString().trim();
|
|
762
|
+
const project = new ts_morph_1.Project({ useInMemoryFileSystem: true });
|
|
763
|
+
try {
|
|
764
|
+
const sourceFile = project.createSourceFile('direct-run-method.ts', `class DirectRunMethodSource { ${methodSource} }`);
|
|
765
|
+
const names = sourceFile
|
|
766
|
+
.getClassOrThrow('DirectRunMethodSource')
|
|
767
|
+
.getInstanceMethod(methodName)
|
|
768
|
+
?.getParameters()
|
|
769
|
+
.map((parameter) => parameter.getName());
|
|
770
|
+
if (names) {
|
|
771
|
+
return names;
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
catch {
|
|
775
|
+
}
|
|
776
|
+
try {
|
|
777
|
+
const sourceFile = project.createSourceFile('direct-run-function.ts', `const directRunMethod = ${methodSource};`);
|
|
778
|
+
const initializer = sourceFile
|
|
779
|
+
.getVariableDeclarationOrThrow('directRunMethod')
|
|
780
|
+
.getInitializer();
|
|
781
|
+
const callable = initializer?.asKind(ts_morph_1.SyntaxKind.FunctionExpression) ??
|
|
782
|
+
initializer?.asKind(ts_morph_1.SyntaxKind.ArrowFunction);
|
|
783
|
+
return callable?.getParameters().map((parameter) => parameter.getName());
|
|
784
|
+
}
|
|
785
|
+
catch {
|
|
786
|
+
return undefined;
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
typeToTypeScriptCode(type, enclosingNode, seenTypeTexts = new Set()) {
|
|
790
|
+
if (type.isAny() || type.isUnknown()) {
|
|
791
|
+
return 'unknown';
|
|
792
|
+
}
|
|
793
|
+
if (type.isNever()) {
|
|
794
|
+
return 'never';
|
|
795
|
+
}
|
|
796
|
+
if (type.isUndefined()) {
|
|
797
|
+
return 'undefined';
|
|
798
|
+
}
|
|
799
|
+
if (type.isVoid()) {
|
|
800
|
+
return 'void';
|
|
801
|
+
}
|
|
802
|
+
if (type.isString()) {
|
|
803
|
+
return 'string';
|
|
804
|
+
}
|
|
805
|
+
if (type.isNumber()) {
|
|
806
|
+
return 'number';
|
|
807
|
+
}
|
|
808
|
+
if (type.isBoolean()) {
|
|
809
|
+
return 'boolean';
|
|
810
|
+
}
|
|
811
|
+
if (type.isNull()) {
|
|
812
|
+
return 'null';
|
|
813
|
+
}
|
|
814
|
+
if (type.isStringLiteral()) {
|
|
815
|
+
return JSON.stringify(type.getLiteralValue());
|
|
816
|
+
}
|
|
817
|
+
if (type.isNumberLiteral()) {
|
|
818
|
+
return String(type.getLiteralValue());
|
|
819
|
+
}
|
|
820
|
+
if (type.isBooleanLiteral()) {
|
|
821
|
+
return type.getText(enclosingNode);
|
|
822
|
+
}
|
|
823
|
+
if (type.isUnion()) {
|
|
824
|
+
return type
|
|
825
|
+
.getUnionTypes()
|
|
826
|
+
.map((unionType) => this.typeToTypeScriptCode(unionType, enclosingNode, new Set(seenTypeTexts)))
|
|
827
|
+
.join(' | ');
|
|
828
|
+
}
|
|
829
|
+
if (type.isTuple()) {
|
|
830
|
+
return `[${type
|
|
831
|
+
.getTupleElements()
|
|
832
|
+
.map((tupleType) => this.typeToTypeScriptCode(tupleType, enclosingNode, new Set(seenTypeTexts)))
|
|
833
|
+
.join(', ')}]`;
|
|
834
|
+
}
|
|
835
|
+
if (type.isArray() || type.isReadonlyArray()) {
|
|
836
|
+
const itemType = this.typeToTypeScriptCode(type.getArrayElementType() ?? type, enclosingNode, new Set(seenTypeTexts));
|
|
837
|
+
return `${this.wrapArrayItemType(itemType)}[]`;
|
|
838
|
+
}
|
|
839
|
+
if (!type.isObject() || type.getCallSignatures().length > 0) {
|
|
840
|
+
return type.getText(enclosingNode);
|
|
841
|
+
}
|
|
842
|
+
const typeText = type.getText(enclosingNode);
|
|
843
|
+
if (seenTypeTexts.has(typeText)) {
|
|
844
|
+
return typeText;
|
|
845
|
+
}
|
|
846
|
+
seenTypeTexts.add(typeText);
|
|
847
|
+
const properties = type.getProperties();
|
|
848
|
+
if (properties.length === 0) {
|
|
849
|
+
return typeText;
|
|
850
|
+
}
|
|
851
|
+
return `{ ${properties
|
|
852
|
+
.map((property) => {
|
|
853
|
+
const propertyNode = property.getValueDeclaration() ?? property.getDeclarations()[0];
|
|
854
|
+
const propertyType = property.getTypeAtLocation(propertyNode ?? enclosingNode);
|
|
855
|
+
const optional = property.isOptional() || this.typeAllowsUndefined(propertyType);
|
|
856
|
+
return `${this.propertyNameToTypeScriptCode(property.getName())}${optional ? '?' : ''}: ${this.typeToTypeScriptCode(propertyType, propertyNode ?? enclosingNode, new Set(seenTypeTexts))}`;
|
|
857
|
+
})
|
|
858
|
+
.join('; ')} }`;
|
|
859
|
+
}
|
|
860
|
+
wrapArrayItemType(typeText) {
|
|
861
|
+
return typeText.includes(' | ') || typeText.includes('&')
|
|
862
|
+
? `(${typeText})`
|
|
863
|
+
: typeText;
|
|
864
|
+
}
|
|
865
|
+
propertyNameToTypeScriptCode(name) {
|
|
866
|
+
return /^[A-Za-z_$][\w$]*$/.test(name) ? name : JSON.stringify(name);
|
|
867
|
+
}
|
|
868
|
+
typeAllowsUndefined(type) {
|
|
869
|
+
return (type.isUndefined() ||
|
|
870
|
+
(type.isUnion() &&
|
|
871
|
+
type.getUnionTypes().some((unionType) => unionType.isUndefined())));
|
|
872
|
+
}
|
|
573
873
|
findGraphCycles(modules) {
|
|
574
874
|
let nextId = 1;
|
|
575
875
|
const nextCycleId = () => nextId++;
|
|
@@ -785,6 +1085,6 @@ exports.NestGraphInspectorSetup = NestGraphInspectorSetup = NestGraphInspectorSe
|
|
|
785
1085
|
http_output_adapter_1.HttpOutputAdapter,
|
|
786
1086
|
file_output_adapter_1.FileOutputAdapter,
|
|
787
1087
|
json_output_adapter_1.JsonOutputAdapter,
|
|
788
|
-
viewer_output_adapter_1.ViewerOutputAdapter
|
|
1088
|
+
viewer_output_adapter_1.ViewerOutputAdapter,
|
|
1089
|
+
runtime_trace_recorder_1.RuntimeTraceRecorder])
|
|
789
1090
|
], NestGraphInspectorSetup);
|
|
790
|
-
//# sourceMappingURL=nest-graph-inspector.setup.js.map
|
|
@@ -3,6 +3,9 @@ export type NestGraphInspectorOllamaProxyOptions = {
|
|
|
3
3
|
origin?: string;
|
|
4
4
|
path?: string;
|
|
5
5
|
};
|
|
6
|
+
export type NestGraphInspectorViewerDirectRunOptions = {
|
|
7
|
+
path?: string;
|
|
8
|
+
};
|
|
6
9
|
export type NestGraphInspectorOutput = {
|
|
7
10
|
type: 'viewer';
|
|
8
11
|
origin?: string;
|
|
@@ -10,6 +13,7 @@ export type NestGraphInspectorOutput = {
|
|
|
10
13
|
port?: number;
|
|
11
14
|
path?: string;
|
|
12
15
|
ollama?: NestGraphInspectorOllamaProxyOptions;
|
|
16
|
+
directRun?: NestGraphInspectorViewerDirectRunOptions;
|
|
13
17
|
} | {
|
|
14
18
|
type: 'markdown';
|
|
15
19
|
path: string;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { DirectRunTraceRecorder, RuntimeTrace, RuntimeTraceHandle, RuntimeTraceSpanType, RuntimeTraceStartContext } from './types/direct-run.type';
|
|
2
|
+
type RuntimeTraceSpanInput = {
|
|
3
|
+
name: string;
|
|
4
|
+
type: RuntimeTraceSpanType;
|
|
5
|
+
moduleName?: string;
|
|
6
|
+
className?: string;
|
|
7
|
+
methodName?: string;
|
|
8
|
+
resource?: string;
|
|
9
|
+
args?: unknown;
|
|
10
|
+
metadata?: Record<string, string | number | boolean | null>;
|
|
11
|
+
};
|
|
12
|
+
export declare class RuntimeTraceRecorder implements DirectRunTraceRecorder {
|
|
13
|
+
private readonly activeContextStorage;
|
|
14
|
+
private readonly activeSpanStackStorage;
|
|
15
|
+
private readonly completedTraces;
|
|
16
|
+
private readonly activeSpans;
|
|
17
|
+
private readonly pendingSpans;
|
|
18
|
+
start(context: RuntimeTraceStartContext): RuntimeTraceHandle;
|
|
19
|
+
finishSuccess(handle: RuntimeTraceHandle, result: unknown): Promise<RuntimeTrace>;
|
|
20
|
+
finishError(handle: RuntimeTraceHandle, error: unknown): Promise<RuntimeTrace>;
|
|
21
|
+
getCompletedTrace(traceId: string): RuntimeTrace | undefined;
|
|
22
|
+
getCompletedTraces(): RuntimeTrace[];
|
|
23
|
+
runWithContext<T>(handle: RuntimeTraceHandle, callback: () => Promise<T>): Promise<T>;
|
|
24
|
+
recordSpan<T>(span: RuntimeTraceSpanInput, callback: () => T): T;
|
|
25
|
+
private finishTrace;
|
|
26
|
+
private pushSpan;
|
|
27
|
+
private updateSpan;
|
|
28
|
+
private trackPendingSpan;
|
|
29
|
+
private waitForPendingSpans;
|
|
30
|
+
private markPendingSpansNotAwaited;
|
|
31
|
+
private isRootSpan;
|
|
32
|
+
private buildFallbackTrace;
|
|
33
|
+
private persistCompletedTrace;
|
|
34
|
+
private isPromiseLike;
|
|
35
|
+
private classifyProviderType;
|
|
36
|
+
private resolveErrorName;
|
|
37
|
+
private resolveErrorMessage;
|
|
38
|
+
summarizeValue(value: unknown): string | null;
|
|
39
|
+
previewValue(value: unknown): unknown;
|
|
40
|
+
private errorResult;
|
|
41
|
+
}
|
|
42
|
+
export {};
|