@nestia/sdk 2.4.7 → 2.5.0-dev.20240128
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/lib/generates/internal/SdkFileProgrammer.js +23 -10
- package/lib/generates/internal/SdkFileProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkFunctionProgrammer.d.ts +6 -1
- package/lib/generates/internal/SdkFunctionProgrammer.js +73 -323
- package/lib/generates/internal/SdkFunctionProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkNamespaceProgrammer.d.ts +11 -0
- package/lib/generates/internal/SdkNamespaceProgrammer.js +175 -0
- package/lib/generates/internal/SdkNamespaceProgrammer.js.map +1 -0
- package/lib/generates/internal/SdkRouteProgrammer.d.ts +7 -0
- package/lib/generates/internal/SdkRouteProgrammer.js +55 -0
- package/lib/generates/internal/SdkRouteProgrammer.js.map +1 -0
- package/lib/generates/internal/SdkSimulationProgrammer.d.ts +7 -1
- package/lib/generates/internal/SdkSimulationProgrammer.js +98 -88
- package/lib/generates/internal/SdkSimulationProgrammer.js.map +1 -1
- package/lib/utils/ImportDictionary.d.ts +2 -0
- package/lib/utils/ImportDictionary.js +45 -0
- package/lib/utils/ImportDictionary.js.map +1 -1
- package/lib/utils/NodeUtil.d.ts +5 -0
- package/lib/utils/NodeUtil.js +16 -0
- package/lib/utils/NodeUtil.js.map +1 -0
- package/package.json +6 -3
- package/src/analyses/ConfigAnalyzer.ts +147 -147
- package/src/analyses/ControllerAnalyzer.ts +390 -390
- package/src/analyses/PathAnalyzer.ts +110 -110
- package/src/analyses/ReflectAnalyzer.ts +464 -464
- package/src/generates/SwaggerGenerator.ts +376 -376
- package/src/generates/internal/SdkFileProgrammer.ts +42 -13
- package/src/generates/internal/SdkFunctionProgrammer.ts +176 -475
- package/src/generates/internal/SdkNamespaceProgrammer.ts +495 -0
- package/src/generates/internal/SdkRouteProgrammer.ts +82 -0
- package/src/generates/internal/SdkSimulationProgrammer.ts +359 -133
- package/src/generates/internal/SwaggerSchemaGenerator.ts +444 -444
- package/src/utils/ImportDictionary.ts +72 -0
- package/src/utils/NodeUtil.ts +19 -0
|
@@ -2,6 +2,9 @@ import path from "path";
|
|
|
2
2
|
import { HashMap } from "tstl/container/HashMap";
|
|
3
3
|
import { HashSet } from "tstl/container/HashSet";
|
|
4
4
|
import { Pair } from "tstl/utility/Pair";
|
|
5
|
+
import ts from "typescript";
|
|
6
|
+
|
|
7
|
+
import { NodeUtil } from "./NodeUtil";
|
|
5
8
|
|
|
6
9
|
export class ImportDictionary {
|
|
7
10
|
private readonly components_: HashMap<Pair<string, boolean>, IComposition> =
|
|
@@ -52,6 +55,75 @@ export class ImportDictionary {
|
|
|
52
55
|
return props.instance ?? file;
|
|
53
56
|
}
|
|
54
57
|
|
|
58
|
+
public toStatements(outDir: string): ts.Statement[] {
|
|
59
|
+
const external: ts.ImportDeclaration[] = [];
|
|
60
|
+
const internal: ts.ImportDeclaration[] = [];
|
|
61
|
+
|
|
62
|
+
const locator = (str: string) => {
|
|
63
|
+
const location: string = path.relative(outDir, str).split("\\").join("/");
|
|
64
|
+
const index: number = location.lastIndexOf(NODE_MODULES);
|
|
65
|
+
return index === -1
|
|
66
|
+
? location.startsWith("..")
|
|
67
|
+
? location
|
|
68
|
+
: `./${location}`
|
|
69
|
+
: location.substring(index + NODE_MODULES.length);
|
|
70
|
+
};
|
|
71
|
+
const enroll =
|
|
72
|
+
(filter: (str: string) => boolean) =>
|
|
73
|
+
(container: ts.ImportDeclaration[]) => {
|
|
74
|
+
const compositions: IComposition[] = this.components_
|
|
75
|
+
.toJSON()
|
|
76
|
+
.filter((c) => filter(c.second.location))
|
|
77
|
+
.map((e) => ({
|
|
78
|
+
...e.second,
|
|
79
|
+
location: locator(e.second.location),
|
|
80
|
+
}))
|
|
81
|
+
.sort((a, b) => a.location.localeCompare(b.location));
|
|
82
|
+
for (const c of compositions) {
|
|
83
|
+
const brackets: string[] = [];
|
|
84
|
+
if (c.default) brackets.push(c.name ?? c.location);
|
|
85
|
+
if (c.elements.empty() === false)
|
|
86
|
+
brackets.push(
|
|
87
|
+
`{ ${c.elements
|
|
88
|
+
.toJSON()
|
|
89
|
+
.sort((a, b) => a.localeCompare(b))
|
|
90
|
+
.join(", ")} }`,
|
|
91
|
+
);
|
|
92
|
+
container.push(
|
|
93
|
+
ts.factory.createImportDeclaration(
|
|
94
|
+
undefined,
|
|
95
|
+
ts.factory.createImportClause(
|
|
96
|
+
c.type,
|
|
97
|
+
c.default
|
|
98
|
+
? ts.factory.createIdentifier(c.name ?? c.location)
|
|
99
|
+
: undefined,
|
|
100
|
+
c.elements.empty() === false
|
|
101
|
+
? ts.factory.createNamedImports(
|
|
102
|
+
[...c.elements].map((elem) =>
|
|
103
|
+
ts.factory.createImportSpecifier(
|
|
104
|
+
false,
|
|
105
|
+
undefined,
|
|
106
|
+
ts.factory.createIdentifier(elem),
|
|
107
|
+
),
|
|
108
|
+
),
|
|
109
|
+
)
|
|
110
|
+
: undefined,
|
|
111
|
+
),
|
|
112
|
+
ts.factory.createStringLiteral(c.location),
|
|
113
|
+
),
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
enroll((str) => str.indexOf(NODE_MODULES) !== -1)(external);
|
|
119
|
+
enroll((str) => str.indexOf(NODE_MODULES) === -1)(internal);
|
|
120
|
+
return [
|
|
121
|
+
...external,
|
|
122
|
+
...(external.length && internal.length ? [NodeUtil.enter()] : []),
|
|
123
|
+
...internal,
|
|
124
|
+
];
|
|
125
|
+
}
|
|
126
|
+
|
|
55
127
|
public toScript(outDir: string): string {
|
|
56
128
|
const external: string[] = [];
|
|
57
129
|
const internal: string[] = [];
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
export namespace NodeUtil {
|
|
4
|
+
export const description = <Node extends ts.Node>(
|
|
5
|
+
node: Node,
|
|
6
|
+
comment: string,
|
|
7
|
+
): Node => {
|
|
8
|
+
ts.addSyntheticLeadingComment(
|
|
9
|
+
node,
|
|
10
|
+
ts.SyntaxKind.MultiLineCommentTrivia,
|
|
11
|
+
["*", ...comment.split("\n").map((str) => ` * ${str}`), ""].join("\n"),
|
|
12
|
+
true,
|
|
13
|
+
);
|
|
14
|
+
return node;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const enter = () =>
|
|
18
|
+
ts.factory.createExpressionStatement(ts.factory.createIdentifier("\n"));
|
|
19
|
+
}
|