@nestia/migrate 11.2.1 → 11.3.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.
- package/lib/bundles/NEST_TEMPLATE.js +2 -2
- package/lib/bundles/NEST_TEMPLATE.js.map +1 -1
- package/lib/bundles/SDK_TEMPLATE.js +1 -1
- package/lib/bundles/SDK_TEMPLATE.js.map +1 -1
- package/lib/factories/ExpressionFactory.d.ts +9 -0
- package/lib/factories/ExpressionFactory.js +16 -0
- package/lib/factories/ExpressionFactory.js.map +1 -0
- package/lib/factories/IdentifierFactory.d.ts +11 -0
- package/lib/factories/IdentifierFactory.js +36 -0
- package/lib/factories/IdentifierFactory.js.map +1 -0
- package/lib/factories/LiteralFactory.d.ts +9 -0
- package/lib/factories/LiteralFactory.js +52 -0
- package/lib/factories/LiteralFactory.js.map +1 -0
- package/lib/factories/StatementFactory.d.ts +12 -0
- package/lib/factories/StatementFactory.js +20 -0
- package/lib/factories/StatementFactory.js.map +1 -0
- package/lib/factories/TypeFactory.d.ts +8 -0
- package/lib/factories/TypeFactory.js +25 -0
- package/lib/factories/TypeFactory.js.map +1 -0
- package/lib/factories/TypeLiteralFactory.d.ts +2 -2
- package/lib/factories/TypeLiteralFactory.js +12 -15
- package/lib/factories/TypeLiteralFactory.js.map +1 -1
- package/lib/factories/index.d.ts +5 -0
- package/lib/factories/index.js +22 -0
- package/lib/factories/index.js.map +1 -0
- package/lib/index.mjs +171 -126
- package/lib/index.mjs.map +1 -1
- package/lib/programmers/NestiaMigrateApiFileProgrammer.d.ts +2 -2
- package/lib/programmers/NestiaMigrateApiFileProgrammer.js +2 -5
- package/lib/programmers/NestiaMigrateApiFileProgrammer.js.map +1 -1
- package/lib/programmers/NestiaMigrateApiFunctionProgrammer.d.ts +3 -3
- package/lib/programmers/NestiaMigrateApiFunctionProgrammer.js +45 -48
- package/lib/programmers/NestiaMigrateApiFunctionProgrammer.js.map +1 -1
- package/lib/programmers/NestiaMigrateApiNamespaceProgrammer.d.ts +3 -3
- package/lib/programmers/NestiaMigrateApiNamespaceProgrammer.js +59 -62
- package/lib/programmers/NestiaMigrateApiNamespaceProgrammer.js.map +1 -1
- package/lib/programmers/NestiaMigrateApiProgrammer.js +2 -5
- package/lib/programmers/NestiaMigrateApiProgrammer.js.map +1 -1
- package/lib/programmers/NestiaMigrateApiSimulationProgrammer.d.ts +3 -3
- package/lib/programmers/NestiaMigrateApiSimulationProgrammer.js +36 -39
- package/lib/programmers/NestiaMigrateApiSimulationProgrammer.js.map +1 -1
- package/lib/programmers/NestiaMigrateApiStartProgrammer.js +20 -23
- package/lib/programmers/NestiaMigrateApiStartProgrammer.js.map +1 -1
- package/lib/programmers/NestiaMigrateDtoProgrammer.d.ts +2 -2
- package/lib/programmers/NestiaMigrateDtoProgrammer.js +2 -5
- package/lib/programmers/NestiaMigrateDtoProgrammer.js.map +1 -1
- package/lib/programmers/NestiaMigrateE2eFileProgrammer.d.ts +3 -3
- package/lib/programmers/NestiaMigrateE2eFileProgrammer.js +23 -26
- package/lib/programmers/NestiaMigrateE2eFileProgrammer.js.map +1 -1
- package/lib/programmers/NestiaMigrateE2eProgrammer.js.map +1 -1
- package/lib/programmers/NestiaMigrateImportProgrammer.d.ts +4 -4
- package/lib/programmers/NestiaMigrateImportProgrammer.js +11 -14
- package/lib/programmers/NestiaMigrateImportProgrammer.js.map +1 -1
- package/lib/programmers/NestiaMigrateNestControllerProgrammer.d.ts +2 -2
- package/lib/programmers/NestiaMigrateNestControllerProgrammer.js +5 -8
- package/lib/programmers/NestiaMigrateNestControllerProgrammer.js.map +1 -1
- package/lib/programmers/NestiaMigrateNestMethodProgrammer.d.ts +2 -2
- package/lib/programmers/NestiaMigrateNestMethodProgrammer.js +32 -37
- package/lib/programmers/NestiaMigrateNestMethodProgrammer.js.map +1 -1
- package/lib/programmers/NestiaMigrateNestModuleProgrammer.d.ts +2 -2
- package/lib/programmers/NestiaMigrateNestModuleProgrammer.js +9 -12
- package/lib/programmers/NestiaMigrateNestModuleProgrammer.js.map +1 -1
- package/lib/programmers/NestiaMigrateNestProgrammer.js +2 -5
- package/lib/programmers/NestiaMigrateNestProgrammer.js.map +1 -1
- package/lib/programmers/NestiaMigrateSchemaProgrammer.d.ts +2 -2
- package/lib/programmers/NestiaMigrateSchemaProgrammer.js +44 -43
- package/lib/programmers/NestiaMigrateSchemaProgrammer.js.map +1 -1
- package/lib/structures/INestiaMigrateConfig.d.ts +2 -2
- package/lib/utils/FilePrinter.d.ts +4 -4
- package/lib/utils/FilePrinter.js +9 -11
- package/lib/utils/FilePrinter.js.map +1 -1
- package/package.json +8 -7
- package/src/bundles/NEST_TEMPLATE.ts +2 -2
- package/src/bundles/SDK_TEMPLATE.ts +1 -1
- package/src/factories/ExpressionFactory.ts +30 -0
- package/src/factories/IdentifierFactory.ts +69 -0
- package/src/factories/LiteralFactory.ts +61 -0
- package/src/factories/StatementFactory.ts +40 -0
- package/src/factories/TypeFactory.ts +33 -0
- package/src/factories/TypeLiteralFactory.ts +17 -17
- package/src/factories/index.ts +5 -0
- package/src/programmers/NestiaMigrateApiFileProgrammer.ts +6 -7
- package/src/programmers/NestiaMigrateApiFunctionProgrammer.ts +81 -74
- package/src/programmers/NestiaMigrateApiNamespaceProgrammer.ts +143 -142
- package/src/programmers/NestiaMigrateApiProgrammer.ts +11 -11
- package/src/programmers/NestiaMigrateApiSimulationProgrammer.ts +71 -66
- package/src/programmers/NestiaMigrateApiStartProgrammer.ts +58 -52
- package/src/programmers/NestiaMigrateDtoProgrammer.ts +5 -5
- package/src/programmers/NestiaMigrateE2eFileProgrammer.ts +41 -34
- package/src/programmers/NestiaMigrateE2eProgrammer.ts +8 -9
- package/src/programmers/NestiaMigrateImportProgrammer.ts +22 -22
- package/src/programmers/NestiaMigrateNestControllerProgrammer.ts +8 -8
- package/src/programmers/NestiaMigrateNestMethodProgrammer.ts +68 -68
- package/src/programmers/NestiaMigrateNestModuleProgrammer.ts +18 -20
- package/src/programmers/NestiaMigrateNestProgrammer.ts +14 -14
- package/src/programmers/NestiaMigrateSchemaProgrammer.ts +67 -59
- package/src/structures/INestiaMigrateConfig.ts +2 -2
- package/src/utils/FilePrinter.ts +20 -21
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { type Statement, SyntaxKind, factory } from "@ttsc/factory";
|
|
2
2
|
|
|
3
3
|
import { INestiaMigrateController } from "../structures/INestiaMigrateController";
|
|
4
4
|
import { FilePrinter } from "../utils/FilePrinter";
|
|
@@ -6,28 +6,26 @@ import { FilePrinter } from "../utils/FilePrinter";
|
|
|
6
6
|
export namespace NestiaMigrateNestModuleProgrammer {
|
|
7
7
|
export const write = (
|
|
8
8
|
controllers: INestiaMigrateController[],
|
|
9
|
-
):
|
|
9
|
+
): Statement[] => [
|
|
10
10
|
$import("@nestjs/common")("Module"),
|
|
11
11
|
...(controllers.length ? [FilePrinter.newLine()] : []),
|
|
12
12
|
...controllers.map((c) =>
|
|
13
13
|
$import(`${c.location.replace("src/", "./")}/${c.name}`)(c.name),
|
|
14
14
|
),
|
|
15
15
|
...(controllers.length ? [FilePrinter.newLine()] : []),
|
|
16
|
-
|
|
16
|
+
factory.createClassDeclaration(
|
|
17
17
|
[
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
factory.createDecorator(
|
|
19
|
+
factory.createCallExpression(
|
|
20
|
+
factory.createIdentifier("Module"),
|
|
21
21
|
undefined,
|
|
22
22
|
[
|
|
23
|
-
|
|
23
|
+
factory.createObjectLiteralExpression(
|
|
24
24
|
[
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
controllers.map((c) =>
|
|
29
|
-
ts.factory.createIdentifier(c.name),
|
|
30
|
-
),
|
|
25
|
+
factory.createPropertyAssignment(
|
|
26
|
+
factory.createIdentifier("controllers"),
|
|
27
|
+
factory.createArrayLiteralExpression(
|
|
28
|
+
controllers.map((c) => factory.createIdentifier(c.name)),
|
|
31
29
|
true,
|
|
32
30
|
),
|
|
33
31
|
),
|
|
@@ -37,7 +35,7 @@ export namespace NestiaMigrateNestModuleProgrammer {
|
|
|
37
35
|
],
|
|
38
36
|
),
|
|
39
37
|
),
|
|
40
|
-
|
|
38
|
+
factory.createToken(SyntaxKind.ExportKeyword),
|
|
41
39
|
],
|
|
42
40
|
"MyModule",
|
|
43
41
|
undefined,
|
|
@@ -48,18 +46,18 @@ export namespace NestiaMigrateNestModuleProgrammer {
|
|
|
48
46
|
}
|
|
49
47
|
|
|
50
48
|
const $import = (file: string) => (instance: string) =>
|
|
51
|
-
|
|
49
|
+
factory.createImportDeclaration(
|
|
52
50
|
undefined,
|
|
53
|
-
|
|
51
|
+
factory.createImportClause(
|
|
54
52
|
false,
|
|
55
53
|
undefined,
|
|
56
|
-
|
|
57
|
-
|
|
54
|
+
factory.createNamedImports([
|
|
55
|
+
factory.createImportSpecifier(
|
|
58
56
|
false,
|
|
59
57
|
undefined,
|
|
60
|
-
|
|
58
|
+
factory.createIdentifier(instance),
|
|
61
59
|
),
|
|
62
60
|
]),
|
|
63
61
|
),
|
|
64
|
-
|
|
62
|
+
factory.createStringLiteral(file),
|
|
65
63
|
);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { NodeFlags, type Statement, SyntaxKind, factory } from "@ttsc/factory";
|
|
2
2
|
|
|
3
3
|
import { NestiaMigrateControllerAnalyzer } from "../analyzers/NestiaMigrateControllerAnalyzer";
|
|
4
4
|
import { INestiaMigrateContext } from "../structures/INestiaMigrateContext";
|
|
@@ -15,7 +15,7 @@ export namespace NestiaMigrateNestProgrammer {
|
|
|
15
15
|
): Record<string, string> => {
|
|
16
16
|
const controllers: INestiaMigrateController[] =
|
|
17
17
|
NestiaMigrateControllerAnalyzer.analyze(context.application.routes);
|
|
18
|
-
const statements: [string,
|
|
18
|
+
const statements: [string, Statement[]][] = [
|
|
19
19
|
["src/MyModule.ts", NestiaMigrateNestModuleProgrammer.write(controllers)],
|
|
20
20
|
...controllers.map(
|
|
21
21
|
(c) =>
|
|
@@ -26,7 +26,7 @@ export namespace NestiaMigrateNestProgrammer {
|
|
|
26
26
|
components: context.application.document().components,
|
|
27
27
|
controller: c,
|
|
28
28
|
}),
|
|
29
|
-
] satisfies [string,
|
|
29
|
+
] satisfies [string, Statement[]],
|
|
30
30
|
),
|
|
31
31
|
...[
|
|
32
32
|
...NestiaMigrateDtoProgrammer.compose({
|
|
@@ -37,7 +37,7 @@ export namespace NestiaMigrateNestProgrammer {
|
|
|
37
37
|
([key, value]) =>
|
|
38
38
|
[`src/api/structures/${key}.ts`, writeDtoFile(key, value)] satisfies [
|
|
39
39
|
string,
|
|
40
|
-
|
|
40
|
+
Statement[],
|
|
41
41
|
],
|
|
42
42
|
),
|
|
43
43
|
];
|
|
@@ -52,9 +52,9 @@ export namespace NestiaMigrateNestProgrammer {
|
|
|
52
52
|
const writeDtoFile = (
|
|
53
53
|
key: string,
|
|
54
54
|
modulo: NestiaMigrateDtoProgrammer.IModule,
|
|
55
|
-
):
|
|
55
|
+
): Statement[] => {
|
|
56
56
|
const importer = new NestiaMigrateImportProgrammer();
|
|
57
|
-
const statements:
|
|
57
|
+
const statements: Statement[] = iterate(importer)(modulo);
|
|
58
58
|
if (statements.length === 0) return [];
|
|
59
59
|
|
|
60
60
|
return [
|
|
@@ -66,19 +66,19 @@ export namespace NestiaMigrateNestProgrammer {
|
|
|
66
66
|
|
|
67
67
|
const iterate =
|
|
68
68
|
(importer: NestiaMigrateImportProgrammer) =>
|
|
69
|
-
(modulo: NestiaMigrateDtoProgrammer.IModule):
|
|
70
|
-
const output:
|
|
69
|
+
(modulo: NestiaMigrateDtoProgrammer.IModule): Statement[] => {
|
|
70
|
+
const output: Statement[] = [];
|
|
71
71
|
if (modulo.programmer !== null) output.push(modulo.programmer(importer));
|
|
72
72
|
if (modulo.children.size) {
|
|
73
|
-
const internal:
|
|
73
|
+
const internal: Statement[] = [];
|
|
74
74
|
for (const child of modulo.children.values())
|
|
75
75
|
internal.push(...iterate(importer)(child));
|
|
76
76
|
output.push(
|
|
77
|
-
|
|
78
|
-
[
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
77
|
+
factory.createModuleDeclaration(
|
|
78
|
+
[factory.createModifier(SyntaxKind.ExportKeyword)],
|
|
79
|
+
factory.createIdentifier(modulo.name),
|
|
80
|
+
factory.createModuleBlock(internal),
|
|
81
|
+
NodeFlags.Namespace,
|
|
82
82
|
),
|
|
83
83
|
);
|
|
84
84
|
}
|
|
@@ -1,8 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
type KeywordTypeNode,
|
|
3
|
+
SyntaxKind,
|
|
4
|
+
type TypeNode,
|
|
5
|
+
type TypeReferenceNode,
|
|
6
|
+
type UnionTypeNode,
|
|
7
|
+
factory,
|
|
8
|
+
} from "@ttsc/factory";
|
|
9
|
+
import { FormatCheatSheet } from "@typia/core";
|
|
2
10
|
import { NamingConvention, OpenApiTypeChecker } from "@typia/utils";
|
|
3
|
-
import ts from "typescript";
|
|
4
11
|
import typia, { OpenApi } from "typia";
|
|
5
12
|
|
|
13
|
+
import { TypeFactory } from "../factories";
|
|
6
14
|
import { FilePrinter } from "../utils/FilePrinter";
|
|
7
15
|
import { StringUtil } from "../utils/StringUtil";
|
|
8
16
|
import { NestiaMigrateImportProgrammer } from "./NestiaMigrateImportProgrammer";
|
|
@@ -15,14 +23,14 @@ export namespace NestiaMigrateSchemaProgrammer {
|
|
|
15
23
|
components: OpenApi.IComponents;
|
|
16
24
|
importer: NestiaMigrateImportProgrammer;
|
|
17
25
|
schema: OpenApi.IJsonSchema;
|
|
18
|
-
}):
|
|
26
|
+
}): TypeNode => {
|
|
19
27
|
// CONSIDER ANY TYPE CASE
|
|
20
|
-
const union:
|
|
28
|
+
const union: TypeNode[] = [];
|
|
21
29
|
if (OpenApiTypeChecker.isUnknown(props.schema))
|
|
22
30
|
return TypeFactory.keyword("any");
|
|
23
31
|
|
|
24
32
|
// ITERATION
|
|
25
|
-
const type:
|
|
33
|
+
const type: TypeNode = (() => {
|
|
26
34
|
// ATOMIC
|
|
27
35
|
if (OpenApiTypeChecker.isConstant(props.schema))
|
|
28
36
|
return writeConstant({
|
|
@@ -86,7 +94,7 @@ export namespace NestiaMigrateSchemaProgrammer {
|
|
|
86
94
|
// DETERMINE
|
|
87
95
|
if (union.length === 0) return TypeFactory.keyword("any");
|
|
88
96
|
else if (union.length === 1) return union[0]!;
|
|
89
|
-
return
|
|
97
|
+
return factory.createUnionTypeNode(union);
|
|
90
98
|
};
|
|
91
99
|
|
|
92
100
|
/* -----------------------------------------------------------
|
|
@@ -95,29 +103,29 @@ export namespace NestiaMigrateSchemaProgrammer {
|
|
|
95
103
|
const writeConstant = (props: {
|
|
96
104
|
importer: NestiaMigrateImportProgrammer;
|
|
97
105
|
schema: OpenApi.IJsonSchema.IConstant;
|
|
98
|
-
}):
|
|
99
|
-
return
|
|
106
|
+
}): TypeNode => {
|
|
107
|
+
return factory.createLiteralTypeNode(
|
|
100
108
|
typeof props.schema.const === "boolean"
|
|
101
109
|
? props.schema.const === true
|
|
102
|
-
?
|
|
103
|
-
:
|
|
110
|
+
? factory.createTrue()
|
|
111
|
+
: factory.createFalse()
|
|
104
112
|
: typeof props.schema.const === "number"
|
|
105
113
|
? props.schema.const < 0
|
|
106
|
-
?
|
|
107
|
-
|
|
108
|
-
|
|
114
|
+
? factory.createPrefixUnaryExpression(
|
|
115
|
+
SyntaxKind.MinusToken,
|
|
116
|
+
factory.createNumericLiteral(-props.schema.const),
|
|
109
117
|
)
|
|
110
|
-
:
|
|
111
|
-
:
|
|
118
|
+
: factory.createNumericLiteral(props.schema.const)
|
|
119
|
+
: factory.createStringLiteral(props.schema.const),
|
|
112
120
|
);
|
|
113
121
|
};
|
|
114
122
|
|
|
115
|
-
const writeBoolean = ():
|
|
123
|
+
const writeBoolean = (): TypeNode => TypeFactory.keyword("boolean");
|
|
116
124
|
|
|
117
125
|
const writeInteger = (props: {
|
|
118
126
|
importer: NestiaMigrateImportProgrammer;
|
|
119
127
|
schema: OpenApi.IJsonSchema.IInteger;
|
|
120
|
-
}):
|
|
128
|
+
}): TypeNode =>
|
|
121
129
|
writeNumeric({
|
|
122
130
|
factory: () => [
|
|
123
131
|
TypeFactory.keyword("number"),
|
|
@@ -130,7 +138,7 @@ export namespace NestiaMigrateSchemaProgrammer {
|
|
|
130
138
|
const writeNumber = (props: {
|
|
131
139
|
importer: NestiaMigrateImportProgrammer;
|
|
132
140
|
schema: OpenApi.IJsonSchema.INumber;
|
|
133
|
-
}):
|
|
141
|
+
}): TypeNode =>
|
|
134
142
|
writeNumeric({
|
|
135
143
|
factory: () => [TypeFactory.keyword("number")],
|
|
136
144
|
importer: props.importer,
|
|
@@ -138,11 +146,11 @@ export namespace NestiaMigrateSchemaProgrammer {
|
|
|
138
146
|
});
|
|
139
147
|
|
|
140
148
|
const writeNumeric = (props: {
|
|
141
|
-
factory: () =>
|
|
149
|
+
factory: () => TypeNode[];
|
|
142
150
|
importer: NestiaMigrateImportProgrammer;
|
|
143
151
|
schema: OpenApi.IJsonSchema.IInteger | OpenApi.IJsonSchema.INumber;
|
|
144
|
-
}):
|
|
145
|
-
const intersection:
|
|
152
|
+
}): TypeNode => {
|
|
153
|
+
const intersection: TypeNode[] = props.factory();
|
|
146
154
|
if (props.schema.default !== undefined)
|
|
147
155
|
intersection.push(props.importer.tag("Default", props.schema.default));
|
|
148
156
|
if (props.schema.minimum !== undefined)
|
|
@@ -165,17 +173,17 @@ export namespace NestiaMigrateSchemaProgrammer {
|
|
|
165
173
|
);
|
|
166
174
|
return intersection.length === 1
|
|
167
175
|
? intersection[0]!
|
|
168
|
-
:
|
|
176
|
+
: factory.createIntersectionTypeNode(intersection);
|
|
169
177
|
};
|
|
170
178
|
|
|
171
179
|
const writeString = (props: {
|
|
172
180
|
importer: NestiaMigrateImportProgrammer;
|
|
173
181
|
schema: OpenApi.IJsonSchema.IString;
|
|
174
|
-
}):
|
|
182
|
+
}): TypeNode => {
|
|
175
183
|
if (props.schema.format === "binary")
|
|
176
|
-
return
|
|
184
|
+
return factory.createTypeReferenceNode("File");
|
|
177
185
|
|
|
178
|
-
const intersection:
|
|
186
|
+
const intersection: TypeNode[] = [TypeFactory.keyword("string")];
|
|
179
187
|
if (props.schema.default !== undefined)
|
|
180
188
|
intersection.push(props.importer.tag("Default", props.schema.default));
|
|
181
189
|
if (props.schema.minLength !== undefined)
|
|
@@ -200,7 +208,7 @@ export namespace NestiaMigrateSchemaProgrammer {
|
|
|
200
208
|
);
|
|
201
209
|
return intersection.length === 1
|
|
202
210
|
? intersection[0]!
|
|
203
|
-
:
|
|
211
|
+
: factory.createIntersectionTypeNode(intersection);
|
|
204
212
|
};
|
|
205
213
|
|
|
206
214
|
/* -----------------------------------------------------------
|
|
@@ -210,9 +218,9 @@ export namespace NestiaMigrateSchemaProgrammer {
|
|
|
210
218
|
components: OpenApi.IComponents;
|
|
211
219
|
importer: NestiaMigrateImportProgrammer;
|
|
212
220
|
schema: OpenApi.IJsonSchema.IArray;
|
|
213
|
-
}):
|
|
214
|
-
const intersection:
|
|
215
|
-
|
|
221
|
+
}): TypeNode => {
|
|
222
|
+
const intersection: TypeNode[] = [
|
|
223
|
+
factory.createArrayTypeNode(
|
|
216
224
|
write({
|
|
217
225
|
components: props.components,
|
|
218
226
|
importer: props.importer,
|
|
@@ -228,15 +236,15 @@ export namespace NestiaMigrateSchemaProgrammer {
|
|
|
228
236
|
intersection.push(props.importer.tag("UniqueItems"));
|
|
229
237
|
return intersection.length === 1
|
|
230
238
|
? intersection[0]!
|
|
231
|
-
:
|
|
239
|
+
: factory.createIntersectionTypeNode(intersection);
|
|
232
240
|
};
|
|
233
241
|
|
|
234
242
|
const writeTuple = (props: {
|
|
235
243
|
components: OpenApi.IComponents;
|
|
236
244
|
importer: NestiaMigrateImportProgrammer;
|
|
237
245
|
schema: OpenApi.IJsonSchema.ITuple;
|
|
238
|
-
}):
|
|
239
|
-
|
|
246
|
+
}): TypeNode =>
|
|
247
|
+
factory.createTupleTypeNode([
|
|
240
248
|
...props.schema.prefixItems.map((item) =>
|
|
241
249
|
write({
|
|
242
250
|
components: props.components,
|
|
@@ -247,7 +255,7 @@ export namespace NestiaMigrateSchemaProgrammer {
|
|
|
247
255
|
...(typeof props.schema.additionalItems === "object" &&
|
|
248
256
|
props.schema.additionalItems !== null
|
|
249
257
|
? [
|
|
250
|
-
|
|
258
|
+
factory.createRestTypeNode(
|
|
251
259
|
write({
|
|
252
260
|
components: props.components,
|
|
253
261
|
importer: props.importer,
|
|
@@ -257,9 +265,9 @@ export namespace NestiaMigrateSchemaProgrammer {
|
|
|
257
265
|
]
|
|
258
266
|
: props.schema.additionalItems === true
|
|
259
267
|
? [
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
268
|
+
factory.createRestTypeNode(
|
|
269
|
+
factory.createArrayTypeNode(
|
|
270
|
+
factory.createKeywordTypeNode(SyntaxKind.AnyKeyword),
|
|
263
271
|
),
|
|
264
272
|
),
|
|
265
273
|
]
|
|
@@ -270,14 +278,14 @@ export namespace NestiaMigrateSchemaProgrammer {
|
|
|
270
278
|
components: OpenApi.IComponents;
|
|
271
279
|
importer: NestiaMigrateImportProgrammer;
|
|
272
280
|
schema: OpenApi.IJsonSchema.IObject;
|
|
273
|
-
}):
|
|
281
|
+
}): TypeNode => {
|
|
274
282
|
const regular = () =>
|
|
275
|
-
|
|
283
|
+
factory.createTypeLiteralNode(
|
|
276
284
|
Object.entries(props.schema.properties ?? [])
|
|
277
285
|
.map(([key, value], index) => [
|
|
278
286
|
...(index !== 0 &&
|
|
279
287
|
(!!value.title?.length || !!value.description?.length)
|
|
280
|
-
? [
|
|
288
|
+
? [factory.createIdentifier("\n") as any]
|
|
281
289
|
: []),
|
|
282
290
|
writeRegularProperty({
|
|
283
291
|
components: props.components,
|
|
@@ -290,7 +298,7 @@ export namespace NestiaMigrateSchemaProgrammer {
|
|
|
290
298
|
.flat(),
|
|
291
299
|
);
|
|
292
300
|
const dynamic = () =>
|
|
293
|
-
|
|
301
|
+
factory.createTypeLiteralNode([
|
|
294
302
|
writeDynamicProperty({
|
|
295
303
|
components: props.components,
|
|
296
304
|
importer: props.importer,
|
|
@@ -299,7 +307,7 @@ export namespace NestiaMigrateSchemaProgrammer {
|
|
|
299
307
|
]);
|
|
300
308
|
return !!props.schema.properties?.length &&
|
|
301
309
|
typeof props.schema.additionalProperties === "object"
|
|
302
|
-
?
|
|
310
|
+
? factory.createIntersectionTypeNode([regular(), dynamic()])
|
|
303
311
|
: typeof props.schema.additionalProperties === "object"
|
|
304
312
|
? dynamic()
|
|
305
313
|
: regular();
|
|
@@ -312,32 +320,32 @@ export namespace NestiaMigrateSchemaProgrammer {
|
|
|
312
320
|
key: string;
|
|
313
321
|
value: OpenApi.IJsonSchema;
|
|
314
322
|
}) => {
|
|
315
|
-
const valueTypeNode:
|
|
323
|
+
const valueTypeNode: TypeNode = write({
|
|
316
324
|
components: props.components,
|
|
317
325
|
importer: props.importer,
|
|
318
326
|
schema: props.value,
|
|
319
327
|
});
|
|
320
328
|
return FilePrinter.description(
|
|
321
|
-
|
|
329
|
+
factory.createPropertySignature(
|
|
322
330
|
props.value.readOnly
|
|
323
|
-
? [
|
|
331
|
+
? [factory.createToken(SyntaxKind.ReadonlyKeyword)]
|
|
324
332
|
: undefined,
|
|
325
333
|
NamingConvention.variable(props.key)
|
|
326
|
-
?
|
|
327
|
-
:
|
|
334
|
+
? factory.createIdentifier(props.key)
|
|
335
|
+
: factory.createStringLiteral(props.key),
|
|
328
336
|
props.required.includes(props.key)
|
|
329
337
|
? undefined
|
|
330
|
-
:
|
|
338
|
+
: factory.createToken(SyntaxKind.QuestionToken),
|
|
331
339
|
props.required.includes(props.key)
|
|
332
340
|
? valueTypeNode
|
|
333
|
-
:
|
|
334
|
-
?
|
|
341
|
+
: valueTypeNode.kind === "UnionTypeNode"
|
|
342
|
+
? factory.createUnionTypeNode([
|
|
335
343
|
...valueTypeNode.types,
|
|
336
|
-
|
|
344
|
+
factory.createTypeReferenceNode("undefined"),
|
|
337
345
|
])
|
|
338
|
-
:
|
|
346
|
+
: factory.createUnionTypeNode([
|
|
339
347
|
valueTypeNode,
|
|
340
|
-
|
|
348
|
+
factory.createTypeReferenceNode("undefined"),
|
|
341
349
|
]),
|
|
342
350
|
),
|
|
343
351
|
writeComment(props.value),
|
|
@@ -350,13 +358,13 @@ export namespace NestiaMigrateSchemaProgrammer {
|
|
|
350
358
|
schema: OpenApi.IJsonSchema;
|
|
351
359
|
}) =>
|
|
352
360
|
FilePrinter.description(
|
|
353
|
-
|
|
361
|
+
factory.createIndexSignature(
|
|
354
362
|
undefined,
|
|
355
363
|
[
|
|
356
|
-
|
|
364
|
+
factory.createParameterDeclaration(
|
|
357
365
|
undefined,
|
|
358
366
|
undefined,
|
|
359
|
-
|
|
367
|
+
factory.createIdentifier("key"),
|
|
360
368
|
undefined,
|
|
361
369
|
TypeFactory.keyword("string"),
|
|
362
370
|
),
|
|
@@ -369,7 +377,7 @@ export namespace NestiaMigrateSchemaProgrammer {
|
|
|
369
377
|
const writeReference = (props: {
|
|
370
378
|
importer: NestiaMigrateImportProgrammer;
|
|
371
379
|
schema: OpenApi.IJsonSchema.IReference;
|
|
372
|
-
}):
|
|
380
|
+
}): TypeReferenceNode | KeywordTypeNode => {
|
|
373
381
|
if (props.schema.$ref.startsWith("#/components/schemas") === false)
|
|
374
382
|
return TypeFactory.keyword("any");
|
|
375
383
|
const name: string = props.schema.$ref
|
|
@@ -389,8 +397,8 @@ export namespace NestiaMigrateSchemaProgrammer {
|
|
|
389
397
|
components: OpenApi.IComponents;
|
|
390
398
|
importer: NestiaMigrateImportProgrammer;
|
|
391
399
|
elements: OpenApi.IJsonSchema[];
|
|
392
|
-
}):
|
|
393
|
-
|
|
400
|
+
}): UnionTypeNode =>
|
|
401
|
+
factory.createUnionTypeNode(
|
|
394
402
|
props.elements.map((schema) =>
|
|
395
403
|
write({
|
|
396
404
|
components: props.components,
|
|
@@ -400,7 +408,7 @@ export namespace NestiaMigrateSchemaProgrammer {
|
|
|
400
408
|
),
|
|
401
409
|
);
|
|
402
410
|
}
|
|
403
|
-
const createNode = (text: string) =>
|
|
411
|
+
const createNode = (text: string) => factory.createTypeReferenceNode(text);
|
|
404
412
|
|
|
405
413
|
const writeComment = (schema: OpenApi.IJsonSchema): string => {
|
|
406
414
|
interface IPlugin {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { type MethodDeclaration } from "@ttsc/factory";
|
|
2
2
|
|
|
3
3
|
import { NestiaMigrateNestMethodProgrammer } from "../programmers/NestiaMigrateNestMethodProgrammer";
|
|
4
4
|
|
|
@@ -14,6 +14,6 @@ export interface INestiaMigrateConfig {
|
|
|
14
14
|
programmer?: {
|
|
15
15
|
controllerMethod?: (
|
|
16
16
|
ctx: NestiaMigrateNestMethodProgrammer.IContext,
|
|
17
|
-
) =>
|
|
17
|
+
) => MethodDeclaration;
|
|
18
18
|
};
|
|
19
19
|
}
|
package/src/utils/FilePrinter.ts
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {
|
|
2
|
+
type Node,
|
|
3
|
+
type Statement,
|
|
4
|
+
SyntaxKind,
|
|
5
|
+
TsPrinter,
|
|
6
|
+
addSyntheticLeadingComment,
|
|
7
|
+
factory,
|
|
8
|
+
} from "@ttsc/factory";
|
|
2
9
|
|
|
3
10
|
export namespace FilePrinter {
|
|
4
|
-
export const description = <
|
|
5
|
-
node: Node,
|
|
6
|
-
comment: string,
|
|
7
|
-
): Node => {
|
|
11
|
+
export const description = <T extends Node>(node: T, comment: string): T => {
|
|
8
12
|
if (comment.length === 0) return node;
|
|
9
|
-
|
|
13
|
+
addSyntheticLeadingComment(
|
|
10
14
|
node,
|
|
11
|
-
|
|
15
|
+
SyntaxKind.MultiLineCommentTrivia,
|
|
12
16
|
[
|
|
13
17
|
"*",
|
|
14
18
|
...comment
|
|
@@ -26,24 +30,19 @@ export namespace FilePrinter {
|
|
|
26
30
|
return node;
|
|
27
31
|
};
|
|
28
32
|
|
|
29
|
-
|
|
30
|
-
|
|
33
|
+
// A blank-line spacer between statements. An empty identifier prints as a
|
|
34
|
+
// single empty line; wrapping it in an `ExpressionStatement` (as the legacy
|
|
35
|
+
// code did) would append a stray `;` at statement level.
|
|
36
|
+
export const newLine = (): Statement =>
|
|
37
|
+
factory.createIdentifier("") as unknown as Statement;
|
|
31
38
|
|
|
32
39
|
export const write = (props: {
|
|
33
|
-
statements:
|
|
40
|
+
statements: Statement[];
|
|
34
41
|
top?: string;
|
|
35
42
|
}): string => {
|
|
36
|
-
const script: string =
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
})
|
|
40
|
-
.printFile(
|
|
41
|
-
ts.factory.createSourceFile(
|
|
42
|
-
props.statements,
|
|
43
|
-
ts.factory.createToken(ts.SyntaxKind.EndOfFileToken),
|
|
44
|
-
ts.NodeFlags.None,
|
|
45
|
-
),
|
|
46
|
-
);
|
|
43
|
+
const script: string = new TsPrinter({
|
|
44
|
+
newLine: "\n",
|
|
45
|
+
}).printFile(undefined, props.statements);
|
|
47
46
|
return (props.top ?? "") + script;
|
|
48
47
|
};
|
|
49
48
|
}
|