nest-graph-inspector 0.7.2 → 0.8.0-test.1
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.
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { OnModuleInit, Type } from
|
|
2
|
-
import { ModulesContainer } from
|
|
3
|
-
import type { NestGraphInspectorModuleOptions } from
|
|
4
|
-
import { ModuleMap } from
|
|
5
|
-
import { HttpOutputAdapter } from
|
|
6
|
-
import { FileOutputAdapter } from
|
|
7
|
-
import { JsonOutputAdapter } from
|
|
8
|
-
import { ViewerOutputAdapter } from
|
|
9
|
-
import { RuntimeTraceRecorder } from
|
|
1
|
+
import { OnModuleInit, Type } from "@nestjs/common";
|
|
2
|
+
import { ModulesContainer } from "@nestjs/core";
|
|
3
|
+
import type { NestGraphInspectorModuleOptions } from "./nest-graph-inspector.type";
|
|
4
|
+
import { ModuleMap } from "./types/module-map.type";
|
|
5
|
+
import { HttpOutputAdapter } from "./adapters/http-output.adapter";
|
|
6
|
+
import { FileOutputAdapter } from "./adapters/file-output.adapter";
|
|
7
|
+
import { JsonOutputAdapter } from "./adapters/json-output.adapter";
|
|
8
|
+
import { ViewerOutputAdapter } from "./adapters/viewer-output.adapter";
|
|
9
|
+
import { RuntimeTraceRecorder } from "./runtime-trace.recorder";
|
|
10
10
|
export declare class NestGraphInspectorSetup implements OnModuleInit {
|
|
11
11
|
private readonly options;
|
|
12
12
|
private readonly modulesContainer;
|
|
@@ -84,6 +84,11 @@ export declare class NestGraphInspectorSetup implements OnModuleInit {
|
|
|
84
84
|
private extractMethodParameterTypesFromProject;
|
|
85
85
|
private extractMethodParameterNamesFromFunctionSource;
|
|
86
86
|
private typeToTypeScriptCode;
|
|
87
|
+
private renderTypeSequence;
|
|
88
|
+
private renderObjectType;
|
|
89
|
+
private typeReferenceCode;
|
|
90
|
+
private typeTextWithinLimit;
|
|
91
|
+
private typeFallback;
|
|
87
92
|
private wrapArrayItemType;
|
|
88
93
|
private propertyNameToTypeScriptCode;
|
|
89
94
|
private typeAllowsUndefined;
|
|
@@ -26,6 +26,11 @@ 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
28
|
const runtime_trace_recorder_1 = require("./runtime-trace.recorder");
|
|
29
|
+
const MAX_TYPE_RENDER_DEPTH = 12;
|
|
30
|
+
const MAX_TYPE_RENDER_MEMBERS = 50;
|
|
31
|
+
const MAX_TYPE_RENDER_LENGTH = 8_000;
|
|
32
|
+
const MAX_TYPE_PROPERTY_NAME_LENGTH = 160;
|
|
33
|
+
const MIN_TYPE_RENDER_LENGTH = "unknown".length;
|
|
29
34
|
let NestGraphInspectorSetup = NestGraphInspectorSetup_1 = class NestGraphInspectorSetup {
|
|
30
35
|
options;
|
|
31
36
|
modulesContainer;
|
|
@@ -65,7 +70,7 @@ let NestGraphInspectorSetup = NestGraphInspectorSetup_1 = class NestGraphInspect
|
|
|
65
70
|
this.nestCoreModuleName =
|
|
66
71
|
this.options.nestCoreModuleName ??
|
|
67
72
|
nest_graph_inspector_module_1.defaultOptions.nestCoreModuleName ??
|
|
68
|
-
|
|
73
|
+
"NestJSCoreModule";
|
|
69
74
|
this.nestCoreProviders = [
|
|
70
75
|
...(this.options.nestCoreProviders ??
|
|
71
76
|
nest_graph_inspector_module_1.defaultOptions.nestCoreProviders ??
|
|
@@ -139,11 +144,11 @@ let NestGraphInspectorSetup = NestGraphInspectorSetup_1 = class NestGraphInspect
|
|
|
139
144
|
}
|
|
140
145
|
}
|
|
141
146
|
withDefaultOutputOptions(output) {
|
|
142
|
-
if (output.type !==
|
|
147
|
+
if (output.type !== "viewer") {
|
|
143
148
|
return output;
|
|
144
149
|
}
|
|
145
|
-
const defaultViewerOutput = nest_graph_inspector_module_1.defaultOptions.outputs?.find((defaultOutput) => defaultOutput.type ===
|
|
146
|
-
if (!defaultViewerOutput || defaultViewerOutput.type !==
|
|
150
|
+
const defaultViewerOutput = nest_graph_inspector_module_1.defaultOptions.outputs?.find((defaultOutput) => defaultOutput.type === "viewer");
|
|
151
|
+
if (!defaultViewerOutput || defaultViewerOutput.type !== "viewer") {
|
|
147
152
|
return output;
|
|
148
153
|
}
|
|
149
154
|
return {
|
|
@@ -167,9 +172,9 @@ let NestGraphInspectorSetup = NestGraphInspectorSetup_1 = class NestGraphInspect
|
|
|
167
172
|
};
|
|
168
173
|
}
|
|
169
174
|
getDirectRunHistoryDirPath() {
|
|
170
|
-
const jsonOutput = this.options.outputs?.find((output) => output.type ===
|
|
171
|
-
return jsonOutput?.type ===
|
|
172
|
-
? (0, node_path_1.join)(process.cwd(), (0, node_path_1.dirname)(jsonOutput.path),
|
|
175
|
+
const jsonOutput = this.options.outputs?.find((output) => output.type === "json");
|
|
176
|
+
return jsonOutput?.type === "json"
|
|
177
|
+
? (0, node_path_1.join)(process.cwd(), (0, node_path_1.dirname)(jsonOutput.path), "direct-run", "history")
|
|
173
178
|
: undefined;
|
|
174
179
|
}
|
|
175
180
|
buildModuleMapFromAutoDetect() {
|
|
@@ -185,7 +190,7 @@ let NestGraphInspectorSetup = NestGraphInspectorSetup_1 = class NestGraphInspect
|
|
|
185
190
|
createModuleMapFromModuleTree(moduleTree) {
|
|
186
191
|
const modules = this.flattenModuleTree(moduleTree);
|
|
187
192
|
return {
|
|
188
|
-
version:
|
|
193
|
+
version: "3",
|
|
189
194
|
root: moduleTree.name,
|
|
190
195
|
modules,
|
|
191
196
|
};
|
|
@@ -194,7 +199,7 @@ let NestGraphInspectorSetup = NestGraphInspectorSetup_1 = class NestGraphInspect
|
|
|
194
199
|
for (const moduleRef of this.modulesContainer.values()) {
|
|
195
200
|
const moduleName = this.moduleName(moduleRef);
|
|
196
201
|
if (this.ignoreImport.includes(moduleName) ||
|
|
197
|
-
moduleName ===
|
|
202
|
+
moduleName === "InternalCoreModule") {
|
|
198
203
|
continue;
|
|
199
204
|
}
|
|
200
205
|
for (const importedModule of moduleRef.imports.values()) {
|
|
@@ -203,7 +208,7 @@ let NestGraphInspectorSetup = NestGraphInspectorSetup_1 = class NestGraphInspect
|
|
|
203
208
|
}
|
|
204
209
|
}
|
|
205
210
|
}
|
|
206
|
-
throw new Error(
|
|
211
|
+
throw new Error("Could not auto-detect root module. No module imports NestGraphInspectorModule.");
|
|
207
212
|
}
|
|
208
213
|
resolveModuleTree(moduleRef, visited = new Set()) {
|
|
209
214
|
if (visited.has(moduleRef)) {
|
|
@@ -253,13 +258,13 @@ let NestGraphInspectorSetup = NestGraphInspectorSetup_1 = class NestGraphInspect
|
|
|
253
258
|
}
|
|
254
259
|
this.instrumentRuntimeTraceWrappers({
|
|
255
260
|
moduleName: node.name,
|
|
256
|
-
type:
|
|
261
|
+
type: "provider",
|
|
257
262
|
wrappers: node.moduleRef.providers.values(),
|
|
258
263
|
shouldIgnore: (name) => name === node.name || this.ignoreProvider.includes(name),
|
|
259
264
|
});
|
|
260
265
|
this.instrumentRuntimeTraceWrappers({
|
|
261
266
|
moduleName: node.name,
|
|
262
|
-
type:
|
|
267
|
+
type: "controller",
|
|
263
268
|
wrappers: node.moduleRef.controllers.values(),
|
|
264
269
|
});
|
|
265
270
|
});
|
|
@@ -267,7 +272,7 @@ let NestGraphInspectorSetup = NestGraphInspectorSetup_1 = class NestGraphInspect
|
|
|
267
272
|
instrumentRuntimeTraceWrappers(param) {
|
|
268
273
|
for (const wrapper of param.wrappers) {
|
|
269
274
|
const instance = wrapper.instance;
|
|
270
|
-
if (!instance || typeof instance !==
|
|
275
|
+
if (!instance || typeof instance !== "object") {
|
|
271
276
|
continue;
|
|
272
277
|
}
|
|
273
278
|
const className = this.wrapperClassName(wrapper);
|
|
@@ -292,12 +297,12 @@ let NestGraphInspectorSetup = NestGraphInspectorSetup_1 = class NestGraphInspect
|
|
|
292
297
|
return;
|
|
293
298
|
}
|
|
294
299
|
for (const methodName of Object.getOwnPropertyNames(prototype)) {
|
|
295
|
-
if (methodName ===
|
|
300
|
+
if (methodName === "constructor") {
|
|
296
301
|
continue;
|
|
297
302
|
}
|
|
298
303
|
const descriptor = Object.getOwnPropertyDescriptor(prototype, methodName);
|
|
299
304
|
const method = descriptor?.value;
|
|
300
|
-
if (typeof method !==
|
|
305
|
+
if (typeof method !== "function") {
|
|
301
306
|
continue;
|
|
302
307
|
}
|
|
303
308
|
Object.defineProperty(param.instance, methodName, {
|
|
@@ -449,7 +454,7 @@ let NestGraphInspectorSetup = NestGraphInspectorSetup_1 = class NestGraphInspect
|
|
|
449
454
|
};
|
|
450
455
|
}
|
|
451
456
|
createTsMorphProject() {
|
|
452
|
-
const tsConfigFilePath = (0, node_path_1.join)(process.cwd(),
|
|
457
|
+
const tsConfigFilePath = (0, node_path_1.join)(process.cwd(), "tsconfig.json");
|
|
453
458
|
if (!(0, node_fs_1.existsSync)(tsConfigFilePath)) {
|
|
454
459
|
this.logger.warn(`Could not find tsconfig.json at ${tsConfigFilePath}; JSDoc metadata will be skipped.`);
|
|
455
460
|
return new ts_morph_1.Project();
|
|
@@ -477,7 +482,7 @@ let NestGraphInspectorSetup = NestGraphInspectorSetup_1 = class NestGraphInspect
|
|
|
477
482
|
?.getJsDocs()
|
|
478
483
|
.map((doc) => doc.getCommentText())
|
|
479
484
|
.filter((comment) => !!comment)
|
|
480
|
-
.join(
|
|
485
|
+
.join("\n");
|
|
481
486
|
}
|
|
482
487
|
wrapperClassName(wrapper) {
|
|
483
488
|
if (wrapper.metatype?.name) {
|
|
@@ -485,7 +490,7 @@ let NestGraphInspectorSetup = NestGraphInspectorSetup_1 = class NestGraphInspect
|
|
|
485
490
|
}
|
|
486
491
|
const instance = wrapper.instance;
|
|
487
492
|
if (instance &&
|
|
488
|
-
(typeof instance ===
|
|
493
|
+
(typeof instance === "object" || typeof instance === "function")) {
|
|
489
494
|
return instance.constructor?.name ?? null;
|
|
490
495
|
}
|
|
491
496
|
return null;
|
|
@@ -504,7 +509,7 @@ let NestGraphInspectorSetup = NestGraphInspectorSetup_1 = class NestGraphInspect
|
|
|
504
509
|
for (const depWrapper of ctorDeps) {
|
|
505
510
|
if (depWrapper) {
|
|
506
511
|
const dependencyName = this.resolveDependencyName(depWrapper.token, moduleRef);
|
|
507
|
-
if (dependencyName && dependencyName !==
|
|
512
|
+
if (dependencyName && dependencyName !== "Object") {
|
|
508
513
|
dependencies.add(dependencyName);
|
|
509
514
|
}
|
|
510
515
|
}
|
|
@@ -514,7 +519,7 @@ let NestGraphInspectorSetup = NestGraphInspectorSetup_1 = class NestGraphInspect
|
|
|
514
519
|
const depWrapper = propertyDep?.wrapper;
|
|
515
520
|
if (depWrapper) {
|
|
516
521
|
const dependencyName = this.resolveDependencyName(depWrapper.token, moduleRef);
|
|
517
|
-
if (dependencyName && dependencyName !==
|
|
522
|
+
if (dependencyName && dependencyName !== "Object") {
|
|
518
523
|
dependencies.add(dependencyName);
|
|
519
524
|
}
|
|
520
525
|
}
|
|
@@ -522,7 +527,7 @@ let NestGraphInspectorSetup = NestGraphInspectorSetup_1 = class NestGraphInspect
|
|
|
522
527
|
return [...dependencies];
|
|
523
528
|
}
|
|
524
529
|
resolveInjectionToken(token) {
|
|
525
|
-
if (typeof token ===
|
|
530
|
+
if (typeof token === "object" && token !== null && "token" in token) {
|
|
526
531
|
return token.token;
|
|
527
532
|
}
|
|
528
533
|
return token;
|
|
@@ -557,8 +562,8 @@ let NestGraphInspectorSetup = NestGraphInspectorSetup_1 = class NestGraphInspect
|
|
|
557
562
|
continue;
|
|
558
563
|
}
|
|
559
564
|
const providerInstance = wrapper.instance &&
|
|
560
|
-
(typeof wrapper.instance ===
|
|
561
|
-
typeof wrapper.instance ===
|
|
565
|
+
(typeof wrapper.instance === "object" ||
|
|
566
|
+
typeof wrapper.instance === "function")
|
|
562
567
|
? wrapper.instance
|
|
563
568
|
: null;
|
|
564
569
|
const providerName = wrapper.metatype?.name ||
|
|
@@ -582,7 +587,7 @@ let NestGraphInspectorSetup = NestGraphInspectorSetup_1 = class NestGraphInspect
|
|
|
582
587
|
return true;
|
|
583
588
|
}
|
|
584
589
|
if (wrapper.instance &&
|
|
585
|
-
typeof wrapper.instance ===
|
|
590
|
+
typeof wrapper.instance === "object" &&
|
|
586
591
|
wrapper.instance.constructor === token) {
|
|
587
592
|
return true;
|
|
588
593
|
}
|
|
@@ -624,16 +629,16 @@ let NestGraphInspectorSetup = NestGraphInspectorSetup_1 = class NestGraphInspect
|
|
|
624
629
|
moduleName(moduleRef) {
|
|
625
630
|
return (moduleRef.metatype?.name ||
|
|
626
631
|
this.tokenName(moduleRef.token) ||
|
|
627
|
-
|
|
632
|
+
"AnonymousModule");
|
|
628
633
|
}
|
|
629
634
|
tokenName(token) {
|
|
630
635
|
if (!token)
|
|
631
636
|
return null;
|
|
632
|
-
if (typeof token ===
|
|
637
|
+
if (typeof token === "string")
|
|
633
638
|
return token;
|
|
634
|
-
if (typeof token ===
|
|
639
|
+
if (typeof token === "symbol")
|
|
635
640
|
return token.toString();
|
|
636
|
-
if (typeof token ===
|
|
641
|
+
if (typeof token === "function")
|
|
637
642
|
return token.name;
|
|
638
643
|
return null;
|
|
639
644
|
}
|
|
@@ -682,8 +687,8 @@ let NestGraphInspectorSetup = NestGraphInspectorSetup_1 = class NestGraphInspect
|
|
|
682
687
|
}
|
|
683
688
|
const providerWrapper = [...moduleRef.providers.values()].find((wrapper) => {
|
|
684
689
|
const instance = wrapper.instance &&
|
|
685
|
-
(typeof wrapper.instance ===
|
|
686
|
-
typeof wrapper.instance ===
|
|
690
|
+
(typeof wrapper.instance === "object" ||
|
|
691
|
+
typeof wrapper.instance === "function")
|
|
687
692
|
? wrapper.instance
|
|
688
693
|
: null;
|
|
689
694
|
const resolvedName = wrapper.metatype?.name ||
|
|
@@ -695,7 +700,7 @@ let NestGraphInspectorSetup = NestGraphInspectorSetup_1 = class NestGraphInspect
|
|
|
695
700
|
}
|
|
696
701
|
getDirectRunMethods(instance) {
|
|
697
702
|
if (!instance ||
|
|
698
|
-
(typeof instance !==
|
|
703
|
+
(typeof instance !== "object" && typeof instance !== "function")) {
|
|
699
704
|
return [];
|
|
700
705
|
}
|
|
701
706
|
const prototype = Object.getPrototypeOf(instance);
|
|
@@ -703,11 +708,11 @@ let NestGraphInspectorSetup = NestGraphInspectorSetup_1 = class NestGraphInspect
|
|
|
703
708
|
return [];
|
|
704
709
|
}
|
|
705
710
|
const methods = Object.getOwnPropertyNames(prototype)
|
|
706
|
-
.filter((name) => name !==
|
|
711
|
+
.filter((name) => name !== "constructor")
|
|
707
712
|
.map((name) => {
|
|
708
713
|
const descriptor = Object.getOwnPropertyDescriptor(prototype, name);
|
|
709
714
|
const method = descriptor?.value;
|
|
710
|
-
if (typeof method !==
|
|
715
|
+
if (typeof method !== "function") {
|
|
711
716
|
return null;
|
|
712
717
|
}
|
|
713
718
|
const callable = method;
|
|
@@ -729,7 +734,7 @@ let NestGraphInspectorSetup = NestGraphInspectorSetup_1 = class NestGraphInspect
|
|
|
729
734
|
}
|
|
730
735
|
getDirectRunMethodParameterTypes(param) {
|
|
731
736
|
const { instance, method, methodName } = param;
|
|
732
|
-
const className = typeof instance ===
|
|
737
|
+
const className = typeof instance === "function"
|
|
733
738
|
? instance.name
|
|
734
739
|
: instance.constructor?.name;
|
|
735
740
|
const sourceTypes = className
|
|
@@ -740,9 +745,9 @@ let NestGraphInspectorSetup = NestGraphInspectorSetup_1 = class NestGraphInspect
|
|
|
740
745
|
}
|
|
741
746
|
const runtimeNames = this.extractMethodParameterNamesFromFunctionSource(methodName, method);
|
|
742
747
|
if (!runtimeNames?.length) {
|
|
743
|
-
return
|
|
748
|
+
return "[]";
|
|
744
749
|
}
|
|
745
|
-
return `[${runtimeNames.map((name) => `${name}: unknown`).join(
|
|
750
|
+
return `[${runtimeNames.map((name) => `${name}: unknown`).join(", ")}]`;
|
|
746
751
|
}
|
|
747
752
|
extractMethodParameterTypesFromProject(className, methodName) {
|
|
748
753
|
const targetClass = this.tsMorphProject
|
|
@@ -756,15 +761,15 @@ let NestGraphInspectorSetup = NestGraphInspectorSetup_1 = class NestGraphInspect
|
|
|
756
761
|
const parameters = method.getParameters();
|
|
757
762
|
return `[${parameters
|
|
758
763
|
.map((parameter) => `${parameter.getName()}: ${this.typeToTypeScriptCode(parameter.getType(), parameter)}`)
|
|
759
|
-
.join(
|
|
764
|
+
.join(", ")}]`;
|
|
760
765
|
}
|
|
761
766
|
extractMethodParameterNamesFromFunctionSource(methodName, method) {
|
|
762
767
|
const methodSource = method.toString().trim();
|
|
763
768
|
const project = new ts_morph_1.Project({ useInMemoryFileSystem: true });
|
|
764
769
|
try {
|
|
765
|
-
const sourceFile = project.createSourceFile(
|
|
770
|
+
const sourceFile = project.createSourceFile("direct-run-method.ts", `class DirectRunMethodSource { ${methodSource} }`);
|
|
766
771
|
const names = sourceFile
|
|
767
|
-
.getClassOrThrow(
|
|
772
|
+
.getClassOrThrow("DirectRunMethodSource")
|
|
768
773
|
.getInstanceMethod(methodName)
|
|
769
774
|
?.getParameters()
|
|
770
775
|
.map((parameter) => parameter.getName());
|
|
@@ -775,9 +780,9 @@ let NestGraphInspectorSetup = NestGraphInspectorSetup_1 = class NestGraphInspect
|
|
|
775
780
|
catch {
|
|
776
781
|
}
|
|
777
782
|
try {
|
|
778
|
-
const sourceFile = project.createSourceFile(
|
|
783
|
+
const sourceFile = project.createSourceFile("direct-run-function.ts", `const directRunMethod = ${methodSource};`);
|
|
779
784
|
const initializer = sourceFile
|
|
780
|
-
.getVariableDeclarationOrThrow(
|
|
785
|
+
.getVariableDeclarationOrThrow("directRunMethod")
|
|
781
786
|
.getInitializer();
|
|
782
787
|
const callable = initializer?.asKind(ts_morph_1.SyntaxKind.FunctionExpression) ??
|
|
783
788
|
initializer?.asKind(ts_morph_1.SyntaxKind.ArrowFunction);
|
|
@@ -787,79 +792,209 @@ let NestGraphInspectorSetup = NestGraphInspectorSetup_1 = class NestGraphInspect
|
|
|
787
792
|
return undefined;
|
|
788
793
|
}
|
|
789
794
|
}
|
|
790
|
-
typeToTypeScriptCode(type, enclosingNode,
|
|
795
|
+
typeToTypeScriptCode(type, enclosingNode, state = {
|
|
796
|
+
activeTypes: new Set(),
|
|
797
|
+
depth: 0,
|
|
798
|
+
maxLength: MAX_TYPE_RENDER_LENGTH,
|
|
799
|
+
}) {
|
|
791
800
|
if (type.isAny() || type.isUnknown()) {
|
|
792
|
-
return
|
|
801
|
+
return "unknown";
|
|
793
802
|
}
|
|
794
803
|
if (type.isNever()) {
|
|
795
|
-
return
|
|
804
|
+
return "never";
|
|
796
805
|
}
|
|
797
806
|
if (type.isUndefined()) {
|
|
798
|
-
return
|
|
807
|
+
return "undefined";
|
|
799
808
|
}
|
|
800
809
|
if (type.isVoid()) {
|
|
801
|
-
return
|
|
810
|
+
return "void";
|
|
802
811
|
}
|
|
803
812
|
if (type.isString()) {
|
|
804
|
-
return
|
|
813
|
+
return "string";
|
|
805
814
|
}
|
|
806
815
|
if (type.isNumber()) {
|
|
807
|
-
return
|
|
816
|
+
return "number";
|
|
808
817
|
}
|
|
809
818
|
if (type.isBoolean()) {
|
|
810
|
-
return
|
|
819
|
+
return "boolean";
|
|
811
820
|
}
|
|
812
821
|
if (type.isNull()) {
|
|
813
|
-
return
|
|
822
|
+
return "null";
|
|
814
823
|
}
|
|
815
824
|
if (type.isStringLiteral()) {
|
|
816
|
-
|
|
825
|
+
const literalValue = type.getLiteralValue();
|
|
826
|
+
if (typeof literalValue !== "string" ||
|
|
827
|
+
literalValue.length > Math.floor(state.maxLength / 6)) {
|
|
828
|
+
return "string";
|
|
829
|
+
}
|
|
830
|
+
const literal = JSON.stringify(literalValue);
|
|
831
|
+
return literal.length <= state.maxLength ? literal : "string";
|
|
817
832
|
}
|
|
818
833
|
if (type.isNumberLiteral()) {
|
|
819
|
-
|
|
834
|
+
const literal = String(type.getLiteralValue());
|
|
835
|
+
return literal.length <= state.maxLength ? literal : "number";
|
|
820
836
|
}
|
|
821
837
|
if (type.isBooleanLiteral()) {
|
|
822
|
-
return
|
|
823
|
-
}
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
.
|
|
829
|
-
}
|
|
830
|
-
if (
|
|
831
|
-
return
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
838
|
+
return this.typeTextWithinLimit(type, enclosingNode, state.maxLength);
|
|
839
|
+
}
|
|
840
|
+
const isArray = type.isArray() || type.isReadonlyArray();
|
|
841
|
+
const isComposite = type.isUnion() || type.isTuple() || isArray || type.isObject();
|
|
842
|
+
if (!isComposite) {
|
|
843
|
+
return (this.typeReferenceCode(type) ??
|
|
844
|
+
this.typeTextWithinLimit(type, enclosingNode, state.maxLength));
|
|
845
|
+
}
|
|
846
|
+
if (state.activeTypes.has(type) || state.depth >= MAX_TYPE_RENDER_DEPTH) {
|
|
847
|
+
return this.typeReferenceCode(type) ?? "unknown";
|
|
848
|
+
}
|
|
849
|
+
state.activeTypes.add(type);
|
|
850
|
+
try {
|
|
851
|
+
if (type.isUnion()) {
|
|
852
|
+
const unionTypes = type.getUnionTypes();
|
|
853
|
+
if (unionTypes.length > MAX_TYPE_RENDER_MEMBERS) {
|
|
854
|
+
return "unknown";
|
|
855
|
+
}
|
|
856
|
+
return this.renderTypeSequence({
|
|
857
|
+
types: unionTypes,
|
|
858
|
+
enclosingNode,
|
|
859
|
+
state,
|
|
860
|
+
prefix: "",
|
|
861
|
+
delimiter: " | ",
|
|
862
|
+
suffix: "",
|
|
863
|
+
fallback: "unknown",
|
|
864
|
+
});
|
|
865
|
+
}
|
|
866
|
+
if (type.isTuple()) {
|
|
867
|
+
const tupleTypes = type.getTupleElements();
|
|
868
|
+
if (tupleTypes.length > MAX_TYPE_RENDER_MEMBERS) {
|
|
869
|
+
return this.typeFallback(state.maxLength, "unknown[]");
|
|
870
|
+
}
|
|
871
|
+
return this.renderTypeSequence({
|
|
872
|
+
types: tupleTypes,
|
|
873
|
+
enclosingNode,
|
|
874
|
+
state,
|
|
875
|
+
prefix: "[",
|
|
876
|
+
delimiter: ", ",
|
|
877
|
+
suffix: "]",
|
|
878
|
+
fallback: "unknown[]",
|
|
879
|
+
});
|
|
880
|
+
}
|
|
881
|
+
if (isArray) {
|
|
882
|
+
if (state.maxLength < MIN_TYPE_RENDER_LENGTH + 4) {
|
|
883
|
+
return this.typeFallback(state.maxLength, "unknown[]");
|
|
884
|
+
}
|
|
885
|
+
const itemType = this.typeToTypeScriptCode(type.getArrayElementType() ?? type, enclosingNode, {
|
|
886
|
+
...state,
|
|
887
|
+
depth: state.depth + 1,
|
|
888
|
+
maxLength: state.maxLength - 4,
|
|
889
|
+
});
|
|
890
|
+
return `${this.wrapArrayItemType(itemType)}[]`;
|
|
891
|
+
}
|
|
892
|
+
if (type.getCallSignatures().length > 0) {
|
|
893
|
+
return (this.typeReferenceCode(type) ??
|
|
894
|
+
this.typeTextWithinLimit(type, enclosingNode, state.maxLength));
|
|
895
|
+
}
|
|
896
|
+
const properties = type.getProperties();
|
|
897
|
+
if (properties.length === 0) {
|
|
898
|
+
return (this.typeReferenceCode(type) ??
|
|
899
|
+
this.typeTextWithinLimit(type, enclosingNode, state.maxLength));
|
|
900
|
+
}
|
|
901
|
+
return this.renderObjectType(properties, enclosingNode, state);
|
|
902
|
+
}
|
|
903
|
+
finally {
|
|
904
|
+
state.activeTypes.delete(type);
|
|
905
|
+
}
|
|
906
|
+
}
|
|
907
|
+
renderTypeSequence(param) {
|
|
908
|
+
const { types, enclosingNode, state, prefix, delimiter, suffix, fallback } = param;
|
|
909
|
+
let output = prefix;
|
|
910
|
+
for (let index = 0; index < types.length; index += 1) {
|
|
911
|
+
const remainingTypes = types.length - index - 1;
|
|
912
|
+
const separator = index === 0 ? "" : delimiter;
|
|
913
|
+
const childMaxLength = state.maxLength -
|
|
914
|
+
output.length -
|
|
915
|
+
separator.length -
|
|
916
|
+
suffix.length -
|
|
917
|
+
remainingTypes * (delimiter.length + MIN_TYPE_RENDER_LENGTH);
|
|
918
|
+
if (childMaxLength < MIN_TYPE_RENDER_LENGTH) {
|
|
919
|
+
return this.typeFallback(state.maxLength, fallback);
|
|
920
|
+
}
|
|
921
|
+
output += `${separator}${this.typeToTypeScriptCode(types[index], enclosingNode, {
|
|
922
|
+
...state,
|
|
923
|
+
depth: state.depth + 1,
|
|
924
|
+
maxLength: childMaxLength,
|
|
925
|
+
})}`;
|
|
926
|
+
}
|
|
927
|
+
return `${output}${suffix}`;
|
|
928
|
+
}
|
|
929
|
+
renderObjectType(properties, enclosingNode, state) {
|
|
930
|
+
const maxProperties = Math.min(properties.length, MAX_TYPE_RENDER_MEMBERS);
|
|
931
|
+
const truncation = "[key: string]: unknown";
|
|
932
|
+
const propertyCodes = [];
|
|
933
|
+
let propertyCodesLength = 0;
|
|
934
|
+
let truncated = properties.length > maxProperties;
|
|
935
|
+
for (let index = 0; index < maxProperties; index += 1) {
|
|
936
|
+
const property = properties[index];
|
|
937
|
+
const propertyName = property.getName();
|
|
938
|
+
if (propertyName.length > MAX_TYPE_PROPERTY_NAME_LENGTH) {
|
|
939
|
+
truncated = true;
|
|
940
|
+
break;
|
|
941
|
+
}
|
|
854
942
|
const propertyNode = property.getValueDeclaration() ?? property.getDeclarations()[0];
|
|
855
943
|
const propertyType = property.getTypeAtLocation(propertyNode ?? enclosingNode);
|
|
856
944
|
const optional = property.isOptional() || this.typeAllowsUndefined(propertyType);
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
.
|
|
945
|
+
const propertyPrefix = `${this.propertyNameToTypeScriptCode(propertyName)}${optional ? "?" : ""}: `;
|
|
946
|
+
const separator = propertyCodes.length === 0 ? "" : "; ";
|
|
947
|
+
const reservedTruncationLength = 2 + (propertyCodes.length === 0 ? 0 : 2) + truncation.length;
|
|
948
|
+
const childMaxLength = state.maxLength -
|
|
949
|
+
2 -
|
|
950
|
+
propertyCodesLength -
|
|
951
|
+
separator.length -
|
|
952
|
+
propertyPrefix.length -
|
|
953
|
+
reservedTruncationLength;
|
|
954
|
+
if (childMaxLength < MIN_TYPE_RENDER_LENGTH) {
|
|
955
|
+
truncated = true;
|
|
956
|
+
break;
|
|
957
|
+
}
|
|
958
|
+
const propertyCode = `${propertyPrefix}${this.typeToTypeScriptCode(propertyType, propertyNode ?? enclosingNode, {
|
|
959
|
+
...state,
|
|
960
|
+
depth: state.depth + 1,
|
|
961
|
+
maxLength: childMaxLength,
|
|
962
|
+
})}`;
|
|
963
|
+
propertyCodes.push(propertyCode);
|
|
964
|
+
propertyCodesLength += separator.length + propertyCode.length;
|
|
965
|
+
}
|
|
966
|
+
if (truncated) {
|
|
967
|
+
const separator = propertyCodes.length === 0 ? "" : "; ";
|
|
968
|
+
const output = `{ ${propertyCodes.join("; ")}${separator}${truncation} }`;
|
|
969
|
+
return output.length <= state.maxLength
|
|
970
|
+
? output
|
|
971
|
+
: this.typeFallback(state.maxLength, "unknown");
|
|
972
|
+
}
|
|
973
|
+
const output = `{ ${propertyCodes.join("; ")} }`;
|
|
974
|
+
return output.length <= state.maxLength
|
|
975
|
+
? output
|
|
976
|
+
: this.typeFallback(state.maxLength, "unknown");
|
|
977
|
+
}
|
|
978
|
+
typeReferenceCode(type) {
|
|
979
|
+
const name = type.getAliasSymbol()?.getName() ?? type.getSymbol()?.getName();
|
|
980
|
+
return name && !name.startsWith("__") && /^[A-Za-z_$][\w$]*$/.test(name)
|
|
981
|
+
? name
|
|
982
|
+
: undefined;
|
|
983
|
+
}
|
|
984
|
+
typeTextWithinLimit(type, enclosingNode, maxLength) {
|
|
985
|
+
try {
|
|
986
|
+
const typeText = type.getText(enclosingNode);
|
|
987
|
+
return typeText.length <= maxLength ? typeText : "unknown";
|
|
988
|
+
}
|
|
989
|
+
catch {
|
|
990
|
+
return "unknown";
|
|
991
|
+
}
|
|
992
|
+
}
|
|
993
|
+
typeFallback(maxLength, preferred) {
|
|
994
|
+
return preferred.length <= maxLength ? preferred : "unknown";
|
|
860
995
|
}
|
|
861
996
|
wrapArrayItemType(typeText) {
|
|
862
|
-
return typeText.includes(
|
|
997
|
+
return typeText.includes(" | ") || typeText.includes("&")
|
|
863
998
|
? `(${typeText})`
|
|
864
999
|
: typeText;
|
|
865
1000
|
}
|
|
@@ -897,7 +1032,7 @@ let NestGraphInspectorSetup = NestGraphInspectorSetup_1 = class NestGraphInspect
|
|
|
897
1032
|
const key = this.dependencyNodeKey(moduleName, provider.name);
|
|
898
1033
|
nodes.set(key, {
|
|
899
1034
|
key,
|
|
900
|
-
kind:
|
|
1035
|
+
kind: "provider",
|
|
901
1036
|
moduleName,
|
|
902
1037
|
name: provider.name,
|
|
903
1038
|
});
|
|
@@ -906,7 +1041,7 @@ let NestGraphInspectorSetup = NestGraphInspectorSetup_1 = class NestGraphInspect
|
|
|
906
1041
|
const key = this.dependencyNodeKey(moduleName, controller.name);
|
|
907
1042
|
nodes.set(key, {
|
|
908
1043
|
key,
|
|
909
|
-
kind:
|
|
1044
|
+
kind: "controller",
|
|
910
1045
|
moduleName,
|
|
911
1046
|
name: controller.name,
|
|
912
1047
|
});
|
|
@@ -924,9 +1059,9 @@ let NestGraphInspectorSetup = NestGraphInspectorSetup_1 = class NestGraphInspect
|
|
|
924
1059
|
const cycles = this.findCycles(graph, nextCycleId);
|
|
925
1060
|
return {
|
|
926
1061
|
providers: cycles
|
|
927
|
-
.filter((cycle) => nodes.get(cycle.from)?.kind ===
|
|
1062
|
+
.filter((cycle) => nodes.get(cycle.from)?.kind === "provider")
|
|
928
1063
|
.map((cycle) => this.toProviderCycle(cycle, nodes)),
|
|
929
|
-
controllers: cycles.filter((cycle) => nodes.get(cycle.from)?.kind ===
|
|
1064
|
+
controllers: cycles.filter((cycle) => nodes.get(cycle.from)?.kind === "controller"),
|
|
930
1065
|
};
|
|
931
1066
|
}
|
|
932
1067
|
addDependencyEdges(graph, sourceKey, dependencies, nodes) {
|
|
@@ -982,14 +1117,14 @@ let NestGraphInspectorSetup = NestGraphInspectorSetup_1 = class NestGraphInspect
|
|
|
982
1117
|
getCanonicalCycleKey(path) {
|
|
983
1118
|
const cyclePath = path.slice(0, -1);
|
|
984
1119
|
if (cyclePath.length <= 1) {
|
|
985
|
-
return cyclePath.join(
|
|
1120
|
+
return cyclePath.join("->");
|
|
986
1121
|
}
|
|
987
1122
|
const rotations = cyclePath.map((_, index) => [
|
|
988
1123
|
...cyclePath.slice(index),
|
|
989
1124
|
...cyclePath.slice(0, index),
|
|
990
1125
|
]);
|
|
991
1126
|
return rotations
|
|
992
|
-
.map((rotation) => rotation.join(
|
|
1127
|
+
.map((rotation) => rotation.join("->"))
|
|
993
1128
|
.sort((a, b) => a.localeCompare(b))[0];
|
|
994
1129
|
}
|
|
995
1130
|
toProviderCycle(cycle, nodes) {
|
|
@@ -1006,10 +1141,10 @@ let NestGraphInspectorSetup = NestGraphInspectorSetup_1 = class NestGraphInspect
|
|
|
1006
1141
|
provider: { name: node.name },
|
|
1007
1142
|
};
|
|
1008
1143
|
}
|
|
1009
|
-
const separatorIndex = key.indexOf(
|
|
1144
|
+
const separatorIndex = key.indexOf(":");
|
|
1010
1145
|
if (separatorIndex === -1) {
|
|
1011
1146
|
return {
|
|
1012
|
-
module: { name:
|
|
1147
|
+
module: { name: "" },
|
|
1013
1148
|
provider: { name: key },
|
|
1014
1149
|
};
|
|
1015
1150
|
}
|
|
@@ -1020,9 +1155,9 @@ let NestGraphInspectorSetup = NestGraphInspectorSetup_1 = class NestGraphInspect
|
|
|
1020
1155
|
}
|
|
1021
1156
|
getCycleType(source, target, graph) {
|
|
1022
1157
|
if (source === target || graph.get(target)?.has(source)) {
|
|
1023
|
-
return
|
|
1158
|
+
return "direct";
|
|
1024
1159
|
}
|
|
1025
|
-
return
|
|
1160
|
+
return "indirect";
|
|
1026
1161
|
}
|
|
1027
1162
|
findPath(source, target, graph) {
|
|
1028
1163
|
const visited = new Set();
|
|
@@ -1062,18 +1197,18 @@ let NestGraphInspectorSetup = NestGraphInspectorSetup_1 = class NestGraphInspect
|
|
|
1062
1197
|
return `${moduleName}:${dependencyName}`;
|
|
1063
1198
|
}
|
|
1064
1199
|
enrichDependency(dependency, currentModule) {
|
|
1065
|
-
const colonIndex = dependency.indexOf(
|
|
1200
|
+
const colonIndex = dependency.indexOf(":");
|
|
1066
1201
|
if (colonIndex !== -1) {
|
|
1067
1202
|
return {
|
|
1068
1203
|
providedBy: {
|
|
1069
|
-
type:
|
|
1204
|
+
type: "module",
|
|
1070
1205
|
name: dependency.substring(0, colonIndex),
|
|
1071
1206
|
},
|
|
1072
1207
|
token: dependency.substring(colonIndex + 1),
|
|
1073
1208
|
};
|
|
1074
1209
|
}
|
|
1075
1210
|
return {
|
|
1076
|
-
providedBy: { type:
|
|
1211
|
+
providedBy: { type: "module", name: currentModule },
|
|
1077
1212
|
token: dependency,
|
|
1078
1213
|
};
|
|
1079
1214
|
}
|