nest-graph-inspector 0.8.0-test.1 → 0.8.0-test.2

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/README.md CHANGED
@@ -22,6 +22,28 @@ export class AppModule {}
22
22
 
23
23
  Start the Nest application to print the viewer URL.
24
24
 
25
+ ## Viewer graph endpoint
26
+
27
+ Viewer output installs its HTTP routes during Nest bootstrap but defers container
28
+ inspection until graph data is requested. This avoids a graph scan when the
29
+ viewer is never opened.
30
+
31
+ For a viewer configured with `path` (default: `/__graph-inspector`) and its
32
+ configured `origin`/`host`/`port`, clients use these existing endpoints:
33
+
34
+ - `GET {origin}{path}/output.json` generates the graph on the first request and
35
+ returns the `GraphOutput` JSON. Later requests reuse the generated graph for
36
+ the lifetime of the inspector.
37
+ - `GET {origin}{path}/output.md` generates the same graph if necessary and
38
+ returns its Markdown representation.
39
+ - `GET {origin}{path}/information.json` and
40
+ `GET {origin}{path}/output.schema.json` are available immediately and do not
41
+ trigger graph discovery.
42
+
43
+ No viewer-specific request body, query parameter, or UI handshake is required:
44
+ requesting `output.json` is the graph-publication trigger. If discovery fails,
45
+ the endpoint returns HTTP 500; a later request can retry discovery.
46
+
25
47
  ## Documentation
26
48
 
27
49
  See the [project documentation](https://albasyir.github.io/nest-graph-inspector/) for configuration options and output types.
@@ -0,0 +1,71 @@
1
+ import { ModulesContainer } from "@nestjs/core";
2
+ import type { Module } from "@nestjs/core/injector/module";
3
+ import type { NestGraphInspectorModuleOptions } from "../nest-graph-inspector.type";
4
+ import { ModuleController } from "../types/module-controller.type";
5
+ import { ModuleProvider } from "../types/module-provider.type";
6
+ import { RuntimeTraceRecorder } from "../runtime-trace.recorder";
7
+ export type ModuleTree = {
8
+ name: string;
9
+ jsdoc?: string;
10
+ moduleRef: Module | null;
11
+ imports: string[];
12
+ exports: string[];
13
+ providers: ModuleProvider[];
14
+ providerInstances: Map<string, unknown>;
15
+ controllers: ModuleController[];
16
+ children: ModuleTree[];
17
+ };
18
+ export declare class DiscoveryAdapter {
19
+ private readonly options;
20
+ private readonly modulesContainer;
21
+ private readonly runtimeTraceRecorder;
22
+ private readonly logger;
23
+ private readonly ignoreProvider;
24
+ private readonly ignoreImport;
25
+ private readonly nestCoreModuleName;
26
+ private readonly nestCoreProviders;
27
+ private readonly tsMorphProject;
28
+ private readonly runtimeTraceInstrumentedInstances;
29
+ private cachedTree;
30
+ constructor(options: NestGraphInspectorModuleOptions, modulesContainer: ModulesContainer, runtimeTraceRecorder: RuntimeTraceRecorder);
31
+ scan(): ModuleTree;
32
+ get tree(): ModuleTree;
33
+ private getRootModule;
34
+ private getRootModuleFromClass;
35
+ private getModuleTree;
36
+ private findRootModule;
37
+ private resolveModuleTree;
38
+ private createModuleTreeReference;
39
+ private resolveModuleMembers;
40
+ private instrumentRuntimeTrace;
41
+ private instrumentRuntimeTraceWrappers;
42
+ private instrumentRuntimeTraceInstance;
43
+ private appendNestCoreModule;
44
+ private findUsedNestCoreProvidersFromTree;
45
+ private walkModuleTree;
46
+ private shouldIgnoreModule;
47
+ private extractNestCoreProviderName;
48
+ private extractImports;
49
+ private extractExports;
50
+ private extractProviders;
51
+ private extractProviderInstances;
52
+ private extractControllers;
53
+ private extractModuleMembers;
54
+ private extractModuleMember;
55
+ private createTsMorphProject;
56
+ private extractModuleJsDoc;
57
+ private extractClassJsDoc;
58
+ private extractClassJsDocByName;
59
+ private wrapperClassName;
60
+ private extractDependencies;
61
+ private resolveInjectionToken;
62
+ private resolveDependencyName;
63
+ private findProviderDependencyNameByToken;
64
+ private isSameProviderToken;
65
+ private exportedNames;
66
+ private exportName;
67
+ private isExportedProviderToken;
68
+ private formatDependencyName;
69
+ private moduleName;
70
+ private tokenName;
71
+ }
@@ -0,0 +1,542 @@
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
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ var DiscoveryAdapter_1;
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.DiscoveryAdapter = void 0;
17
+ const node_fs_1 = require("node:fs");
18
+ const node_path_1 = require("node:path");
19
+ const common_1 = require("@nestjs/common");
20
+ const core_1 = require("@nestjs/core");
21
+ const nest_graph_inspector_config_1 = require("../nest-graph-inspector.config");
22
+ const nest_graph_inspector_module_1 = require("../nest-graph-inspector.module");
23
+ const runtime_trace_recorder_1 = require("../runtime-trace.recorder");
24
+ const ts_morph_1 = require("ts-morph");
25
+ let DiscoveryAdapter = DiscoveryAdapter_1 = class DiscoveryAdapter {
26
+ options;
27
+ modulesContainer;
28
+ runtimeTraceRecorder;
29
+ logger = new common_1.Logger(DiscoveryAdapter_1.name);
30
+ ignoreProvider;
31
+ ignoreImport;
32
+ nestCoreModuleName;
33
+ nestCoreProviders;
34
+ tsMorphProject = this.createTsMorphProject();
35
+ runtimeTraceInstrumentedInstances = new WeakSet();
36
+ cachedTree;
37
+ constructor(options, modulesContainer, runtimeTraceRecorder) {
38
+ this.options = options;
39
+ this.modulesContainer = modulesContainer;
40
+ this.runtimeTraceRecorder = runtimeTraceRecorder;
41
+ this.ignoreProvider = [
42
+ ...(this.options.ignoreProvider ?? nest_graph_inspector_module_1.defaultOptions.ignoreProvider ?? []),
43
+ ];
44
+ this.ignoreImport = [
45
+ ...(this.options.ignoreImport ?? nest_graph_inspector_module_1.defaultOptions.ignoreImport ?? []),
46
+ ];
47
+ this.nestCoreModuleName =
48
+ this.options.nestCoreModuleName ??
49
+ nest_graph_inspector_module_1.defaultOptions.nestCoreModuleName ??
50
+ "NestJSCoreModule";
51
+ this.nestCoreProviders = [
52
+ ...(this.options.nestCoreProviders ??
53
+ nest_graph_inspector_module_1.defaultOptions.nestCoreProviders ??
54
+ []),
55
+ ];
56
+ }
57
+ scan() {
58
+ if (!this.cachedTree) {
59
+ this.cachedTree = this.getModuleTree(this.getRootModule());
60
+ }
61
+ return this.cachedTree;
62
+ }
63
+ get tree() {
64
+ if (!this.cachedTree) {
65
+ throw new Error("Discovery tree is unavailable before scan() is called.");
66
+ }
67
+ return this.cachedTree;
68
+ }
69
+ getRootModule() {
70
+ const rootModuleClass = this.options.rootModule;
71
+ return rootModuleClass
72
+ ? this.getRootModuleFromClass(rootModuleClass)
73
+ : this.findRootModule();
74
+ }
75
+ getRootModuleFromClass(rootModuleClass) {
76
+ const root = [...this.modulesContainer.values()].find((m) => m.metatype === rootModuleClass);
77
+ if (!root) {
78
+ throw new Error(`Root module not found: ${rootModuleClass.name}`);
79
+ }
80
+ return root;
81
+ }
82
+ getModuleTree(rootModule) {
83
+ const moduleTree = this.resolveModuleTree(rootModule);
84
+ this.resolveModuleMembers(moduleTree);
85
+ this.instrumentRuntimeTrace(moduleTree);
86
+ this.appendNestCoreModule(moduleTree);
87
+ return moduleTree;
88
+ }
89
+ findRootModule() {
90
+ for (const moduleRef of this.modulesContainer.values()) {
91
+ const moduleName = this.moduleName(moduleRef);
92
+ if (this.ignoreImport.includes(moduleName) ||
93
+ moduleName === "InternalCoreModule") {
94
+ continue;
95
+ }
96
+ for (const importedModule of moduleRef.imports.values()) {
97
+ if (importedModule.metatype === nest_graph_inspector_module_1.NestGraphInspectorModule) {
98
+ return moduleRef;
99
+ }
100
+ }
101
+ }
102
+ throw new Error("Could not auto-detect root module. No module imports NestGraphInspectorModule.");
103
+ }
104
+ resolveModuleTree(moduleRef, visited = new Set()) {
105
+ if (visited.has(moduleRef)) {
106
+ return this.createModuleTreeReference(moduleRef);
107
+ }
108
+ visited.add(moduleRef);
109
+ return {
110
+ name: this.moduleName(moduleRef),
111
+ jsdoc: this.extractModuleJsDoc(moduleRef),
112
+ moduleRef,
113
+ imports: [],
114
+ exports: [],
115
+ providers: [],
116
+ providerInstances: new Map(),
117
+ controllers: [],
118
+ children: [...moduleRef.imports.values()]
119
+ .filter((childModule) => !this.shouldIgnoreModule(childModule))
120
+ .map((childModule) => this.resolveModuleTree(childModule, visited)),
121
+ };
122
+ }
123
+ createModuleTreeReference(moduleRef) {
124
+ return {
125
+ name: this.moduleName(moduleRef),
126
+ jsdoc: this.extractModuleJsDoc(moduleRef),
127
+ moduleRef,
128
+ imports: [],
129
+ exports: [],
130
+ providers: [],
131
+ providerInstances: new Map(),
132
+ controllers: [],
133
+ children: [],
134
+ };
135
+ }
136
+ resolveModuleMembers(moduleTree) {
137
+ this.walkModuleTree(moduleTree, (node) => {
138
+ if (!node.moduleRef) {
139
+ return;
140
+ }
141
+ node.imports = node.children.map((child) => child.name);
142
+ node.exports = this.extractExports(node.moduleRef);
143
+ node.providers = this.extractProviders(node.moduleRef, node.name);
144
+ node.providerInstances = this.extractProviderInstances(node.moduleRef, node.providers);
145
+ node.controllers = this.extractControllers(node.moduleRef, node.name);
146
+ });
147
+ }
148
+ instrumentRuntimeTrace(moduleTree) {
149
+ this.walkModuleTree(moduleTree, (node) => {
150
+ if (!node.moduleRef) {
151
+ return;
152
+ }
153
+ this.instrumentRuntimeTraceWrappers({
154
+ moduleName: node.name,
155
+ type: "provider",
156
+ wrappers: node.moduleRef.providers.values(),
157
+ shouldIgnore: (name) => name === node.name || this.ignoreProvider.includes(name),
158
+ });
159
+ this.instrumentRuntimeTraceWrappers({
160
+ moduleName: node.name,
161
+ type: "controller",
162
+ wrappers: node.moduleRef.controllers.values(),
163
+ });
164
+ });
165
+ }
166
+ instrumentRuntimeTraceWrappers(param) {
167
+ for (const wrapper of param.wrappers) {
168
+ const instance = wrapper.instance;
169
+ if (!instance || typeof instance !== "object") {
170
+ continue;
171
+ }
172
+ const className = this.wrapperClassName(wrapper);
173
+ if (!className || param.shouldIgnore?.(className)) {
174
+ continue;
175
+ }
176
+ this.instrumentRuntimeTraceInstance({
177
+ instance,
178
+ moduleName: param.moduleName,
179
+ className,
180
+ type: param.type,
181
+ });
182
+ }
183
+ }
184
+ instrumentRuntimeTraceInstance(param) {
185
+ if (this.runtimeTraceInstrumentedInstances.has(param.instance)) {
186
+ return;
187
+ }
188
+ this.runtimeTraceInstrumentedInstances.add(param.instance);
189
+ const prototype = Object.getPrototypeOf(param.instance);
190
+ if (!prototype) {
191
+ return;
192
+ }
193
+ for (const methodName of Object.getOwnPropertyNames(prototype)) {
194
+ if (methodName === "constructor") {
195
+ continue;
196
+ }
197
+ const descriptor = Object.getOwnPropertyDescriptor(prototype, methodName);
198
+ const method = descriptor?.value;
199
+ if (typeof method !== "function") {
200
+ continue;
201
+ }
202
+ Object.defineProperty(param.instance, methodName, {
203
+ configurable: true,
204
+ writable: true,
205
+ value: (...args) => this.runtimeTraceRecorder.recordSpan({
206
+ name: `${param.className}.${methodName}`,
207
+ type: param.type,
208
+ moduleName: param.moduleName,
209
+ className: param.className,
210
+ methodName,
211
+ args: this.runtimeTraceRecorder.previewValue(args),
212
+ }, () => method.apply(param.instance, args)),
213
+ });
214
+ }
215
+ }
216
+ appendNestCoreModule(moduleTree) {
217
+ const usedProviders = this.findUsedNestCoreProvidersFromTree(moduleTree);
218
+ if (!usedProviders.length) {
219
+ return;
220
+ }
221
+ moduleTree.children.push({
222
+ name: this.nestCoreModuleName,
223
+ moduleRef: null,
224
+ imports: [],
225
+ exports: [...usedProviders],
226
+ providers: usedProviders.map((name) => ({
227
+ name,
228
+ dependencies: [],
229
+ })),
230
+ providerInstances: new Map(),
231
+ controllers: [],
232
+ children: [],
233
+ });
234
+ }
235
+ findUsedNestCoreProvidersFromTree(moduleTree) {
236
+ const usedProviders = new Set();
237
+ this.walkModuleTree(moduleTree, (node) => {
238
+ for (const provider of node.providers) {
239
+ for (const dependencyName of provider.dependencies) {
240
+ const nestCoreProviderName = this.extractNestCoreProviderName(dependencyName);
241
+ if (nestCoreProviderName) {
242
+ usedProviders.add(nestCoreProviderName);
243
+ }
244
+ }
245
+ }
246
+ for (const controller of node.controllers) {
247
+ for (const dependencyName of controller.dependencies) {
248
+ const nestCoreProviderName = this.extractNestCoreProviderName(dependencyName);
249
+ if (nestCoreProviderName) {
250
+ usedProviders.add(nestCoreProviderName);
251
+ }
252
+ }
253
+ }
254
+ });
255
+ return this.nestCoreProviders.filter((providerName) => usedProviders.has(providerName));
256
+ }
257
+ walkModuleTree(moduleTree, visit) {
258
+ visit(moduleTree);
259
+ for (const child of moduleTree.children) {
260
+ this.walkModuleTree(child, visit);
261
+ }
262
+ }
263
+ shouldIgnoreModule(moduleRef) {
264
+ return this.ignoreImport.includes(this.moduleName(moduleRef));
265
+ }
266
+ extractNestCoreProviderName(dependencyName) {
267
+ const prefix = `${this.nestCoreModuleName}:`;
268
+ if (!dependencyName.startsWith(prefix)) {
269
+ return null;
270
+ }
271
+ const providerName = dependencyName.slice(prefix.length);
272
+ if (!providerName) {
273
+ return null;
274
+ }
275
+ if (!this.nestCoreProviders.includes(providerName)) {
276
+ return null;
277
+ }
278
+ return providerName;
279
+ }
280
+ extractImports(moduleRef) {
281
+ return [...moduleRef.imports.values()]
282
+ .map((importedModuleRef) => this.moduleName(importedModuleRef))
283
+ .filter((importName) => !this.ignoreImport.includes(importName));
284
+ }
285
+ extractExports(moduleRef) {
286
+ return [...moduleRef.exports.values()]
287
+ .map((exportedItem) => this.exportName(exportedItem))
288
+ .filter((exportName) => !!exportName && !this.ignoreProvider.includes(exportName));
289
+ }
290
+ extractProviders(moduleRef, moduleName) {
291
+ return this.extractModuleMembers({
292
+ wrappers: moduleRef.providers.values(),
293
+ moduleRef,
294
+ extract: (wrapper) => this.extractModuleMember({
295
+ wrapper,
296
+ moduleRef,
297
+ shouldIgnore: (name) => this.ignoreProvider.includes(name),
298
+ }),
299
+ shouldSkip: (provider) => provider.name === moduleName,
300
+ });
301
+ }
302
+ extractProviderInstances(moduleRef, providers) {
303
+ const providerNames = new Set(providers.map((provider) => provider.name));
304
+ const providerInstances = new Map();
305
+ for (const wrapper of moduleRef.providers.values()) {
306
+ const name = this.wrapperClassName(wrapper) || this.tokenName(wrapper.token);
307
+ if (name && providerNames.has(name)) {
308
+ providerInstances.set(name, wrapper.instance);
309
+ }
310
+ }
311
+ return providerInstances;
312
+ }
313
+ extractControllers(moduleRef, moduleName) {
314
+ return this.extractModuleMembers({
315
+ wrappers: moduleRef.controllers.values(),
316
+ moduleRef,
317
+ extract: (wrapper) => this.extractModuleMember({ wrapper, moduleRef }),
318
+ });
319
+ }
320
+ extractModuleMembers(param) {
321
+ return [...param.wrappers].reduce((items, wrapper) => {
322
+ const executableWrapper = wrapper;
323
+ const item = param.extract(executableWrapper, param.moduleRef);
324
+ if (item) {
325
+ if (param.shouldSkip?.(item)) {
326
+ return items;
327
+ }
328
+ items.push(item);
329
+ }
330
+ return items;
331
+ }, []);
332
+ }
333
+ extractModuleMember(param) {
334
+ const { wrapper, moduleRef, shouldIgnore = () => false } = param;
335
+ const name = this.wrapperClassName(wrapper) || this.tokenName(wrapper.token);
336
+ if (!name || shouldIgnore(name)) {
337
+ return null;
338
+ }
339
+ const jsdoc = this.extractClassJsDoc(wrapper);
340
+ return {
341
+ name,
342
+ ...(jsdoc ? { jsdoc } : {}),
343
+ dependencies: this.extractDependencies(wrapper, moduleRef),
344
+ };
345
+ }
346
+ createTsMorphProject() {
347
+ const tsConfigFilePath = (0, node_path_1.join)(process.cwd(), "tsconfig.json");
348
+ if (!(0, node_fs_1.existsSync)(tsConfigFilePath)) {
349
+ this.logger.warn(`Could not find tsconfig.json at ${tsConfigFilePath}; JSDoc metadata will be skipped.`);
350
+ return new ts_morph_1.Project();
351
+ }
352
+ return new ts_morph_1.Project({
353
+ tsConfigFilePath,
354
+ skipAddingFilesFromTsConfig: false,
355
+ });
356
+ }
357
+ extractModuleJsDoc(moduleRef) {
358
+ return moduleRef.metatype
359
+ ? this.extractClassJsDocByName(moduleRef.metatype.name)
360
+ : undefined;
361
+ }
362
+ extractClassJsDoc(wrapper) {
363
+ const className = this.wrapperClassName(wrapper);
364
+ return className ? this.extractClassJsDocByName(className) : undefined;
365
+ }
366
+ extractClassJsDocByName(className) {
367
+ const targetClass = this.tsMorphProject
368
+ .getSourceFiles()
369
+ .flatMap((sourceFile) => sourceFile.getClasses())
370
+ .find((classDeclaration) => classDeclaration.getName() === className);
371
+ return targetClass
372
+ ?.getJsDocs()
373
+ .map((doc) => doc.getCommentText())
374
+ .filter((comment) => !!comment)
375
+ .join("\n");
376
+ }
377
+ wrapperClassName(wrapper) {
378
+ if (wrapper.metatype?.name) {
379
+ return wrapper.metatype.name;
380
+ }
381
+ const instance = wrapper.instance;
382
+ if (instance &&
383
+ (typeof instance === "object" || typeof instance === "function")) {
384
+ return instance.constructor?.name ?? null;
385
+ }
386
+ return null;
387
+ }
388
+ extractDependencies(wrapper, moduleRef) {
389
+ const dependencies = new Set();
390
+ if (Array.isArray(wrapper?.inject)) {
391
+ for (const token of wrapper.inject) {
392
+ const dependencyName = this.resolveDependencyName(this.resolveInjectionToken(token), moduleRef);
393
+ if (dependencyName) {
394
+ dependencies.add(dependencyName);
395
+ }
396
+ }
397
+ }
398
+ const ctorDeps = wrapper.getCtorMetadata?.() ?? [];
399
+ for (const depWrapper of ctorDeps) {
400
+ if (depWrapper) {
401
+ const dependencyName = this.resolveDependencyName(depWrapper.token, moduleRef);
402
+ if (dependencyName && dependencyName !== "Object") {
403
+ dependencies.add(dependencyName);
404
+ }
405
+ }
406
+ }
407
+ const propertyDeps = wrapper.getPropertiesMetadata?.() ?? [];
408
+ for (const propertyDep of propertyDeps) {
409
+ const depWrapper = propertyDep?.wrapper;
410
+ if (depWrapper) {
411
+ const dependencyName = this.resolveDependencyName(depWrapper.token, moduleRef);
412
+ if (dependencyName && dependencyName !== "Object") {
413
+ dependencies.add(dependencyName);
414
+ }
415
+ }
416
+ }
417
+ return [...dependencies];
418
+ }
419
+ resolveInjectionToken(token) {
420
+ if (typeof token === "object" && token !== null && "token" in token) {
421
+ return token.token;
422
+ }
423
+ return token;
424
+ }
425
+ resolveDependencyName(token, moduleRef) {
426
+ const tokenName = this.tokenName(token);
427
+ if (!tokenName) {
428
+ return null;
429
+ }
430
+ if (this.nestCoreProviders.includes(tokenName)) {
431
+ return `${this.nestCoreModuleName}:${tokenName}`;
432
+ }
433
+ const ownProviderDependencyName = this.findProviderDependencyNameByToken(moduleRef, token, false);
434
+ if (ownProviderDependencyName) {
435
+ return ownProviderDependencyName;
436
+ }
437
+ for (const importedModuleRef of moduleRef.imports.values()) {
438
+ if (!this.isExportedProviderToken(importedModuleRef, token)) {
439
+ continue;
440
+ }
441
+ const importedProviderDependencyName = this.findProviderDependencyNameByToken(importedModuleRef, token, true);
442
+ if (importedProviderDependencyName) {
443
+ return importedProviderDependencyName;
444
+ }
445
+ }
446
+ return this.formatDependencyName(tokenName, moduleRef);
447
+ }
448
+ findProviderDependencyNameByToken(moduleRef, token, includeModulePrefix) {
449
+ const moduleName = this.moduleName(moduleRef);
450
+ for (const wrapper of moduleRef.providers.values()) {
451
+ if (!this.isSameProviderToken(wrapper, token)) {
452
+ continue;
453
+ }
454
+ const providerInstance = wrapper.instance &&
455
+ (typeof wrapper.instance === "object" ||
456
+ typeof wrapper.instance === "function")
457
+ ? wrapper.instance
458
+ : null;
459
+ const providerName = wrapper.metatype?.name ||
460
+ providerInstance?.constructor?.name ||
461
+ this.tokenName(wrapper.token);
462
+ if (!providerName) {
463
+ return null;
464
+ }
465
+ if (includeModulePrefix) {
466
+ return `${moduleName}:${providerName}`;
467
+ }
468
+ return providerName;
469
+ }
470
+ return null;
471
+ }
472
+ isSameProviderToken(wrapper, token) {
473
+ if (wrapper?.token === token) {
474
+ return true;
475
+ }
476
+ if (wrapper?.metatype === token) {
477
+ return true;
478
+ }
479
+ if (wrapper.instance &&
480
+ typeof wrapper.instance === "object" &&
481
+ wrapper.instance.constructor === token) {
482
+ return true;
483
+ }
484
+ return false;
485
+ }
486
+ exportedNames(moduleRef) {
487
+ return new Set([...moduleRef.exports.values()]
488
+ .map((exportedItem) => this.exportName(exportedItem))
489
+ .filter((exportName) => !!exportName));
490
+ }
491
+ exportName(exportedItem) {
492
+ return this.tokenName(exportedItem);
493
+ }
494
+ isExportedProviderToken(moduleRef, token) {
495
+ const tokenName = this.tokenName(token);
496
+ for (const exportedItem of moduleRef.exports.values()) {
497
+ if (exportedItem === token) {
498
+ return true;
499
+ }
500
+ if (tokenName && this.exportName(exportedItem) === tokenName) {
501
+ return true;
502
+ }
503
+ }
504
+ return false;
505
+ }
506
+ formatDependencyName(dependencyName, moduleRef) {
507
+ if (this.nestCoreProviders.includes(dependencyName)) {
508
+ return `${this.nestCoreModuleName}:${dependencyName}`;
509
+ }
510
+ for (const importedModuleRef of moduleRef.imports.values()) {
511
+ const importedModuleName = this.moduleName(importedModuleRef);
512
+ const exportedNames = this.exportedNames(importedModuleRef);
513
+ if (exportedNames.has(dependencyName)) {
514
+ return `${importedModuleName}:${dependencyName}`;
515
+ }
516
+ }
517
+ return dependencyName;
518
+ }
519
+ moduleName(moduleRef) {
520
+ return (moduleRef.metatype?.name ||
521
+ this.tokenName(moduleRef.token) ||
522
+ "AnonymousModule");
523
+ }
524
+ tokenName(token) {
525
+ if (!token)
526
+ return null;
527
+ if (typeof token === "string")
528
+ return token;
529
+ if (typeof token === "symbol")
530
+ return token.toString();
531
+ if (typeof token === "function")
532
+ return token.name;
533
+ return null;
534
+ }
535
+ };
536
+ exports.DiscoveryAdapter = DiscoveryAdapter;
537
+ exports.DiscoveryAdapter = DiscoveryAdapter = DiscoveryAdapter_1 = __decorate([
538
+ (0, common_1.Injectable)(),
539
+ __param(0, (0, common_1.Inject)(nest_graph_inspector_config_1.MODULE_OPTIONS_TOKEN)),
540
+ __metadata("design:paramtypes", [Object, core_1.ModulesContainer,
541
+ runtime_trace_recorder_1.RuntimeTraceRecorder])
542
+ ], DiscoveryAdapter);
@@ -6,6 +6,7 @@ import { HttpServeAdapter } from './http-serve.adapter';
6
6
  type HttpOutputConfig = Extract<NestGraphInspectorOutput, {
7
7
  type: 'http';
8
8
  }>;
9
+ export type GraphOutputSource = GraphOutput | (() => GraphOutput | Promise<GraphOutput>);
9
10
  interface HttpOutputInternalOptions {
10
11
  httpAdapter?: HttpServeAdapter;
11
12
  }
@@ -14,10 +15,11 @@ export declare class HttpOutputAdapter implements OutputAdapter<HttpOutputConfig
14
15
  private readonly httpServeAdapter;
15
16
  static readonly defaultConfig: Readonly<Required<Pick<HttpOutputConfig, 'host' | 'port'>>>;
16
17
  constructor(fileOutputAdapter: FileOutputAdapter, httpServeAdapter: HttpServeAdapter);
17
- execute(graphOutput: GraphOutput, config: HttpOutputConfig & HttpOutputInternalOptions): Promise<{
18
+ execute(graphOutput: GraphOutputSource, config: HttpOutputConfig & HttpOutputInternalOptions): Promise<{
18
19
  message: string;
19
20
  }>;
20
21
  normalizePath(path?: string): string;
22
+ private resolveGraphOutput;
21
23
  private get httpOrigin();
22
24
  private joinPath;
23
25
  }
@@ -48,7 +48,7 @@ let HttpOutputAdapter = class HttpOutputAdapter {
48
48
  'content-type': 'application/json; charset=utf-8',
49
49
  },
50
50
  }),
51
- httpAdapter.get(jsonOutputPath, () => graphOutput, {
51
+ httpAdapter.get(jsonOutputPath, () => this.resolveGraphOutput(graphOutput), {
52
52
  responseHeaders: {
53
53
  'content-type': 'application/json; charset=utf-8',
54
54
  },
@@ -58,7 +58,7 @@ let HttpOutputAdapter = class HttpOutputAdapter {
58
58
  'content-type': 'application/schema+json; charset=utf-8',
59
59
  },
60
60
  }),
61
- httpAdapter.get(markdownOutputPath, () => this.fileOutputAdapter.buildMarkdownText(graphOutput), {
61
+ httpAdapter.get(markdownOutputPath, async () => this.fileOutputAdapter.buildMarkdownText(await this.resolveGraphOutput(graphOutput)), {
62
62
  responseHeaders: {
63
63
  'content-type': 'text/markdown; charset=utf-8',
64
64
  },
@@ -83,6 +83,11 @@ let HttpOutputAdapter = class HttpOutputAdapter {
83
83
  normalizePath(path = '/__nest-graph-inspector') {
84
84
  return path.startsWith('/') ? path : `/${path}`;
85
85
  }
86
+ async resolveGraphOutput(graphOutput) {
87
+ return typeof graphOutput === 'function'
88
+ ? graphOutput()
89
+ : graphOutput;
90
+ }
86
91
  get httpOrigin() {
87
92
  const { host, port } = HttpOutputAdapter_1.defaultConfig;
88
93
  return `http://${host}:${port}`;