@nestia/migrate 0.13.16 → 0.14.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/lib/MigrateApplication.d.ts +1 -0
- package/lib/MigrateApplication.js +843 -893
- package/lib/MigrateApplication.js.map +1 -1
- package/lib/analyzers/MigrateAnalyzer.js +5 -2
- package/lib/analyzers/MigrateAnalyzer.js.map +1 -1
- package/lib/analyzers/MigrateControllerAnalyzer.d.ts +2 -2
- package/lib/analyzers/MigrateControllerAnalyzer.js +14 -88
- package/lib/analyzers/MigrateControllerAnalyzer.js.map +1 -1
- package/lib/bundles/NEST_TEMPLATE.js +21 -6
- 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/executable/bundle.js +1 -1
- package/lib/internal/MigrateCommander.js +5 -2
- package/lib/internal/MigrateCommander.js.map +1 -1
- package/lib/programmers/MigrateApiFileProgrammer.d.ts +2 -9
- package/lib/programmers/MigrateApiFileProgrammer.js +4 -4
- package/lib/programmers/MigrateApiFileProgrammer.js.map +1 -1
- package/lib/programmers/MigrateApiFunctionProgrammer.d.ts +2 -8
- package/lib/programmers/MigrateApiFunctionProgrammer.js +33 -30
- package/lib/programmers/MigrateApiFunctionProgrammer.js.map +1 -1
- package/lib/programmers/MigrateApiNamespaceProgrammer.d.ts +2 -8
- package/lib/programmers/MigrateApiNamespaceProgrammer.js +31 -37
- package/lib/programmers/MigrateApiNamespaceProgrammer.js.map +1 -1
- package/lib/programmers/MigrateApiProgrammer.js +19 -70
- package/lib/programmers/MigrateApiProgrammer.js.map +1 -1
- package/lib/programmers/MigrateApiSimulatationProgrammer.d.ts +2 -8
- package/lib/programmers/MigrateApiSimulatationProgrammer.js +16 -16
- package/lib/programmers/MigrateApiSimulatationProgrammer.js.map +1 -1
- package/lib/programmers/MigrateApiStartProgrammer.js +1 -1
- package/lib/programmers/MigrateApiStartProgrammer.js.map +1 -1
- package/lib/programmers/MigrateE2eProgrammer.js +1 -3
- package/lib/programmers/MigrateE2eProgrammer.js.map +1 -1
- package/lib/programmers/MigrateNestMethodProgrammer.js +4 -4
- package/lib/programmers/MigrateNestMethodProgrammer.js.map +1 -1
- package/lib/programmers/MigrateNestProgrammer.js +27 -23
- package/lib/programmers/MigrateNestProgrammer.js.map +1 -1
- package/lib/programmers/MigrateSchemaProgrammer.js +22 -22
- package/lib/structures/IMigrateProgram.d.ts +8 -8
- package/lib/structures/IMigrateRoute.d.ts +1 -46
- package/lib/utils/OpenApiTypeChecker.d.ts +1 -1
- package/lib/utils/StringUtil.d.ts +0 -4
- package/lib/utils/StringUtil.js +0 -31
- package/lib/utils/StringUtil.js.map +1 -1
- package/lib/utils/openapi-down-convert/RefVisitor.js +4 -5
- package/lib/utils/openapi-down-convert/RefVisitor.js.map +1 -1
- package/package.json +11 -8
- package/src/MigrateApplication.ts +3 -2
- package/src/analyzers/MigrateAnalyzer.ts +10 -5
- package/src/analyzers/MigrateControllerAnalyzer.ts +17 -122
- package/src/bundles/NEST_TEMPLATE.ts +21 -6
- package/src/bundles/SDK_TEMPLATE.ts +1 -1
- package/src/internal/MigrateCommander.ts +8 -2
- package/src/programmers/MigrateApiFileProgrammer.ts +10 -14
- package/src/programmers/MigrateApiFunctionProgrammer.ts +43 -41
- package/src/programmers/MigrateApiNamespaceProgrammer.ts +33 -51
- package/src/programmers/MigrateApiProgrammer.ts +26 -95
- package/src/programmers/MigrateApiSimulatationProgrammer.ts +17 -25
- package/src/programmers/MigrateApiStartProgrammer.ts +1 -1
- package/src/programmers/MigrateE2eProgrammer.ts +1 -3
- package/src/programmers/MigrateNestMethodProgrammer.ts +4 -4
- package/src/programmers/MigrateNestProgrammer.ts +10 -4
- package/src/structures/IMigrateProgram.ts +8 -8
- package/src/structures/IMigrateRoute.ts +1 -51
- package/src/utils/StringUtil.ts +0 -42
- package/lib/analyzers/MigrateMethodAnalyzer.d.ts +0 -9
- package/lib/analyzers/MigrateMethodAnalyzer.js +0 -304
- package/lib/analyzers/MigrateMethodAnalyzer.js.map +0 -1
- package/src/analyzers/MigrateMethodAnalyzer.ts +0 -387
@@ -2,7 +2,6 @@ import { OpenApi } from "@samchon/openapi";
|
|
2
2
|
import ts from "typescript";
|
3
3
|
import { IdentifierFactory } from "typia/lib/factories/IdentifierFactory";
|
4
4
|
|
5
|
-
import { IMigrateController } from "../structures/IMigrateController";
|
6
5
|
import { IMigrateProgram } from "../structures/IMigrateProgram";
|
7
6
|
import { IMigrateRoute } from "../structures/IMigrateRoute";
|
8
7
|
import { FilePrinter } from "../utils/FilePrinter";
|
@@ -10,17 +9,11 @@ import { MigrateImportProgrammer } from "./MigrateImportProgrammer";
|
|
10
9
|
import { MigrateSchemaProgrammer } from "./MigrateSchemaProgrammer";
|
11
10
|
|
12
11
|
export namespace MigrateApiFunctionProgrammer {
|
13
|
-
export interface IProps {
|
14
|
-
controller: IMigrateController;
|
15
|
-
route: IMigrateRoute;
|
16
|
-
alias: string;
|
17
|
-
}
|
18
|
-
|
19
12
|
export const write =
|
20
13
|
(config: IMigrateProgram.IConfig) =>
|
21
14
|
(components: OpenApi.IComponents) =>
|
22
15
|
(importer: MigrateImportProgrammer) =>
|
23
|
-
(
|
16
|
+
(route: IMigrateRoute): ts.FunctionDeclaration =>
|
24
17
|
FilePrinter.description(
|
25
18
|
ts.factory.createFunctionDeclaration(
|
26
19
|
[
|
@@ -28,23 +21,25 @@ export namespace MigrateApiFunctionProgrammer {
|
|
28
21
|
ts.factory.createModifier(ts.SyntaxKind.AsyncKeyword),
|
29
22
|
],
|
30
23
|
undefined,
|
31
|
-
|
24
|
+
route.accessor.at(-1)!,
|
32
25
|
undefined,
|
33
|
-
writeParameterDeclarations(components)(importer)(
|
26
|
+
writeParameterDeclarations(components)(importer)(route),
|
34
27
|
ts.factory.createTypeReferenceNode("Promise", [
|
35
28
|
ts.factory.createTypeReferenceNode(
|
36
|
-
|
29
|
+
route.success === null
|
30
|
+
? "void"
|
31
|
+
: `${route.accessor.at(-1)!}.Output`,
|
37
32
|
),
|
38
33
|
]),
|
39
|
-
ts.factory.createBlock(writeBody(config)(importer)(
|
34
|
+
ts.factory.createBlock(writeBody(config)(importer)(route), true),
|
40
35
|
),
|
41
|
-
writeDescription(
|
36
|
+
writeDescription(route),
|
42
37
|
);
|
43
38
|
|
44
39
|
export const writeParameterDeclarations =
|
45
40
|
(components: OpenApi.IComponents) =>
|
46
41
|
(importer: MigrateImportProgrammer) =>
|
47
|
-
(
|
42
|
+
(route: IMigrateRoute): ts.ParameterDeclaration[] => [
|
48
43
|
IdentifierFactory.parameter(
|
49
44
|
"connection",
|
50
45
|
ts.factory.createTypeReferenceNode(
|
@@ -53,49 +48,56 @@ export namespace MigrateApiFunctionProgrammer {
|
|
53
48
|
library: "@nestia/fetcher",
|
54
49
|
name: "IConnection",
|
55
50
|
}),
|
56
|
-
|
57
|
-
? [
|
51
|
+
route.headers
|
52
|
+
? [
|
53
|
+
ts.factory.createTypeReferenceNode(
|
54
|
+
`${route.accessor.at(-1)!}.Headers`,
|
55
|
+
),
|
56
|
+
]
|
58
57
|
: undefined,
|
59
58
|
),
|
60
59
|
),
|
61
|
-
...
|
60
|
+
...route.parameters.map((p) =>
|
62
61
|
IdentifierFactory.parameter(
|
63
62
|
p.key,
|
64
63
|
MigrateSchemaProgrammer.write(components)(importer)(p.schema),
|
65
64
|
),
|
66
65
|
),
|
67
|
-
...(
|
66
|
+
...(route.query
|
68
67
|
? [
|
69
68
|
IdentifierFactory.parameter(
|
70
|
-
|
71
|
-
ts.factory.createTypeReferenceNode(
|
69
|
+
route.query.key,
|
70
|
+
ts.factory.createTypeReferenceNode(
|
71
|
+
`${route.accessor.at(-1)!}.Query`,
|
72
|
+
),
|
72
73
|
),
|
73
74
|
]
|
74
75
|
: []),
|
75
|
-
...(
|
76
|
+
...(route.body
|
76
77
|
? [
|
77
78
|
IdentifierFactory.parameter(
|
78
|
-
|
79
|
-
ts.factory.createTypeReferenceNode(
|
79
|
+
route.body.key,
|
80
|
+
ts.factory.createTypeReferenceNode(
|
81
|
+
`${route.accessor.at(-1)!}.Input`,
|
82
|
+
),
|
80
83
|
),
|
81
84
|
]
|
82
85
|
: []),
|
83
86
|
];
|
84
87
|
|
85
|
-
const writeDescription = (
|
88
|
+
const writeDescription = (route: IMigrateRoute): string =>
|
86
89
|
[
|
87
|
-
|
88
|
-
`@
|
89
|
-
`@path ${props.route.path}`,
|
90
|
+
route.comment(),
|
91
|
+
`@path ${route.emendedPath}`,
|
90
92
|
"@nestia Generated by Nestia - https://github.com/samchon/nestia",
|
91
93
|
].join("\n");
|
92
94
|
|
93
95
|
const writeBody =
|
94
96
|
(config: IMigrateProgram.IConfig) =>
|
95
97
|
(importer: MigrateImportProgrammer) =>
|
96
|
-
(
|
97
|
-
const encrypted: boolean = !!
|
98
|
-
const contentType: string =
|
98
|
+
(route: IMigrateRoute): ts.Statement[] => {
|
99
|
+
const encrypted: boolean = !!route.success?.["x-nestia-encrypted"];
|
100
|
+
const contentType: string = route.body?.type ?? "application/json";
|
99
101
|
|
100
102
|
const caller = () =>
|
101
103
|
ts.factory.createCallExpression(
|
@@ -141,22 +143,22 @@ export namespace MigrateApiFunctionProgrammer {
|
|
141
143
|
[
|
142
144
|
ts.factory.createSpreadAssignment(
|
143
145
|
IdentifierFactory.access(
|
144
|
-
ts.factory.createIdentifier(
|
146
|
+
ts.factory.createIdentifier(route.accessor.at(-1)!),
|
145
147
|
)("METADATA"),
|
146
148
|
),
|
147
149
|
ts.factory.createPropertyAssignment(
|
148
150
|
"path",
|
149
151
|
ts.factory.createCallExpression(
|
150
152
|
IdentifierFactory.access(
|
151
|
-
ts.factory.createIdentifier(
|
153
|
+
ts.factory.createIdentifier(route.accessor.at(-1)!),
|
152
154
|
)("path"),
|
153
155
|
undefined,
|
154
156
|
[
|
155
|
-
...
|
157
|
+
...route.parameters.map((p) =>
|
156
158
|
ts.factory.createIdentifier(p.key),
|
157
159
|
),
|
158
|
-
...(
|
159
|
-
? [ts.factory.createIdentifier(
|
160
|
+
...(route.query
|
161
|
+
? [ts.factory.createIdentifier(route.query.key)]
|
160
162
|
: []),
|
161
163
|
],
|
162
164
|
),
|
@@ -168,8 +170,8 @@ export namespace MigrateApiFunctionProgrammer {
|
|
168
170
|
],
|
169
171
|
true,
|
170
172
|
),
|
171
|
-
...(
|
172
|
-
? [ts.factory.createIdentifier(
|
173
|
+
...(route.body
|
174
|
+
? [ts.factory.createIdentifier(route.body.key)]
|
173
175
|
: []),
|
174
176
|
],
|
175
177
|
);
|
@@ -181,13 +183,13 @@ export namespace MigrateApiFunctionProgrammer {
|
|
181
183
|
ts.factory.createIdentifier("!!connection.simulate"),
|
182
184
|
undefined,
|
183
185
|
ts.factory.createCallExpression(
|
184
|
-
ts.factory.createIdentifier(`${
|
186
|
+
ts.factory.createIdentifier(`${route.accessor.at(-1)!}.simulate`),
|
185
187
|
[],
|
186
188
|
[
|
187
189
|
"connection",
|
188
|
-
...
|
189
|
-
...(
|
190
|
-
...(
|
190
|
+
...route.parameters.map((p) => p.key),
|
191
|
+
...(route.query ? [route.query.key] : []),
|
192
|
+
...(route.body ? [route.body.key] : []),
|
191
193
|
].map((key) => ts.factory.createIdentifier(key)),
|
192
194
|
),
|
193
195
|
undefined,
|
@@ -5,7 +5,6 @@ import { IdentifierFactory } from "typia/lib/factories/IdentifierFactory";
|
|
5
5
|
import { LiteralFactory } from "typia/lib/factories/LiteralFactory";
|
6
6
|
import { TypeFactory } from "typia/lib/factories/TypeFactory";
|
7
7
|
|
8
|
-
import { IMigrateController } from "../structures/IMigrateController";
|
9
8
|
import { IMigrateProgram } from "../structures/IMigrateProgram";
|
10
9
|
import { IMigrateRoute } from "../structures/IMigrateRoute";
|
11
10
|
import { FilePrinter } from "../utils/FilePrinter";
|
@@ -14,34 +13,28 @@ import { MigrateImportProgrammer } from "./MigrateImportProgrammer";
|
|
14
13
|
import { MigrateSchemaProgrammer } from "./MigrateSchemaProgrammer";
|
15
14
|
|
16
15
|
export namespace MigrateApiNamespaceProgrammer {
|
17
|
-
export interface IProps {
|
18
|
-
controller: IMigrateController;
|
19
|
-
route: IMigrateRoute;
|
20
|
-
alias: string;
|
21
|
-
}
|
22
|
-
|
23
16
|
export const write =
|
24
17
|
(config: IMigrateProgram.IConfig) =>
|
25
18
|
(components: OpenApi.IComponents) =>
|
26
19
|
(importer: MigrateImportProgrammer) =>
|
27
|
-
(
|
28
|
-
const types = writeTypes(components)(importer)(
|
20
|
+
(route: IMigrateRoute): ts.ModuleDeclaration => {
|
21
|
+
const types = writeTypes(components)(importer)(route);
|
29
22
|
return ts.factory.createModuleDeclaration(
|
30
23
|
[ts.factory.createToken(ts.SyntaxKind.ExportKeyword)],
|
31
|
-
ts.factory.createIdentifier(
|
24
|
+
ts.factory.createIdentifier(route.accessor.at(-1)!),
|
32
25
|
ts.factory.createModuleBlock([
|
33
26
|
...types,
|
34
27
|
...(types.length ? [FilePrinter.newLine()] : []),
|
35
|
-
writeMetadata(components)(importer)(
|
28
|
+
writeMetadata(components)(importer)(route),
|
36
29
|
FilePrinter.newLine(),
|
37
|
-
writePath(components)(importer)(
|
30
|
+
writePath(components)(importer)(route),
|
38
31
|
...(config.simulate
|
39
32
|
? [
|
40
33
|
MigrateApiSimulatationProgrammer.random(components)(importer)(
|
41
|
-
|
34
|
+
route,
|
42
35
|
),
|
43
36
|
MigrateApiSimulatationProgrammer.simulate(components)(importer)(
|
44
|
-
|
37
|
+
route,
|
45
38
|
),
|
46
39
|
]
|
47
40
|
: []),
|
@@ -50,17 +43,13 @@ export namespace MigrateApiNamespaceProgrammer {
|
|
50
43
|
);
|
51
44
|
};
|
52
45
|
|
53
|
-
export const writePathCallExpression = (
|
46
|
+
export const writePathCallExpression = (route: IMigrateRoute) =>
|
54
47
|
ts.factory.createCallExpression(
|
55
|
-
ts.factory.createIdentifier(`${
|
48
|
+
ts.factory.createIdentifier(`${route.accessor.at(-1)!}.path`),
|
56
49
|
undefined,
|
57
50
|
[
|
58
|
-
...
|
59
|
-
|
60
|
-
),
|
61
|
-
...(props.route.query
|
62
|
-
? [ts.factory.createIdentifier(props.route.query.key)]
|
63
|
-
: []),
|
51
|
+
...route.parameters.map((p) => ts.factory.createIdentifier(p.key)),
|
52
|
+
...(route.query ? [ts.factory.createIdentifier(route.query.key)] : []),
|
64
53
|
],
|
65
54
|
);
|
66
55
|
|
@@ -112,41 +101,38 @@ export namespace MigrateApiNamespaceProgrammer {
|
|
112
101
|
const writeMetadata =
|
113
102
|
(components: OpenApi.IComponents) =>
|
114
103
|
(importer: MigrateImportProgrammer) =>
|
115
|
-
(
|
104
|
+
(route: IMigrateRoute): ts.VariableStatement =>
|
116
105
|
constant("METADATA")(
|
117
106
|
ts.factory.createAsExpression(
|
118
107
|
ts.factory.createObjectLiteralExpression(
|
119
108
|
[
|
120
109
|
ts.factory.createPropertyAssignment(
|
121
110
|
"method",
|
122
|
-
ts.factory.createStringLiteral(
|
123
|
-
props.route.method.toUpperCase(),
|
124
|
-
),
|
111
|
+
ts.factory.createStringLiteral(route.method.toUpperCase()),
|
125
112
|
),
|
126
113
|
ts.factory.createPropertyAssignment(
|
127
114
|
"path",
|
128
|
-
ts.factory.createStringLiteral(getPath(
|
115
|
+
ts.factory.createStringLiteral(getPath(route)),
|
129
116
|
),
|
130
117
|
ts.factory.createPropertyAssignment(
|
131
118
|
"request",
|
132
|
-
|
119
|
+
route.body
|
133
120
|
? LiteralFactory.generate({
|
134
|
-
type:
|
135
|
-
encrypted: !!
|
121
|
+
type: route.body.type,
|
122
|
+
encrypted: !!route.body["x-nestia-encrypted"],
|
136
123
|
})
|
137
124
|
: ts.factory.createNull(),
|
138
125
|
),
|
139
126
|
ts.factory.createPropertyAssignment(
|
140
127
|
"response",
|
141
|
-
|
128
|
+
route.method.toUpperCase() !== "HEAD"
|
142
129
|
? LiteralFactory.generate({
|
143
|
-
type:
|
144
|
-
encrypted: !!
|
130
|
+
type: route.success?.type ?? "application/json",
|
131
|
+
encrypted: !!route.success?.["x-nestia-encrypted"],
|
145
132
|
})
|
146
133
|
: ts.factory.createNull(),
|
147
134
|
),
|
148
|
-
...(
|
149
|
-
"application/x-www-form-urlencoded"
|
135
|
+
...(route.success?.type === "application/x-www-form-urlencoded"
|
150
136
|
? [
|
151
137
|
ts.factory.createPropertyAssignment(
|
152
138
|
"parseQuery",
|
@@ -160,7 +146,7 @@ export namespace MigrateApiNamespaceProgrammer {
|
|
160
146
|
),
|
161
147
|
[
|
162
148
|
MigrateSchemaProgrammer.write(components)(importer)(
|
163
|
-
|
149
|
+
route.success.schema,
|
164
150
|
),
|
165
151
|
],
|
166
152
|
undefined,
|
@@ -180,25 +166,25 @@ export namespace MigrateApiNamespaceProgrammer {
|
|
180
166
|
const writePath =
|
181
167
|
(components: OpenApi.IComponents) =>
|
182
168
|
(importer: MigrateImportProgrammer) =>
|
183
|
-
(
|
169
|
+
(route: IMigrateRoute): ts.VariableStatement => {
|
184
170
|
const out = (body: ts.ConciseBody) =>
|
185
171
|
constant("path")(
|
186
172
|
ts.factory.createArrowFunction(
|
187
173
|
[],
|
188
174
|
[],
|
189
175
|
[
|
190
|
-
...
|
176
|
+
...route.parameters.map((p) =>
|
191
177
|
IdentifierFactory.parameter(
|
192
178
|
p.key,
|
193
179
|
MigrateSchemaProgrammer.write(components)(importer)(p.schema),
|
194
180
|
),
|
195
181
|
),
|
196
|
-
...(
|
182
|
+
...(route.query
|
197
183
|
? [
|
198
184
|
IdentifierFactory.parameter(
|
199
|
-
|
185
|
+
route.query.key,
|
200
186
|
ts.factory.createTypeReferenceNode(
|
201
|
-
`${
|
187
|
+
`${route.accessor.at(-1)!}.Query`,
|
202
188
|
),
|
203
189
|
),
|
204
190
|
]
|
@@ -210,7 +196,7 @@ export namespace MigrateApiNamespaceProgrammer {
|
|
210
196
|
),
|
211
197
|
);
|
212
198
|
const template = () => {
|
213
|
-
const path: string = getPath(
|
199
|
+
const path: string = getPath(route);
|
214
200
|
const splitted: string[] = path.split(":");
|
215
201
|
if (splitted.length === 1) return ts.factory.createStringLiteral(path);
|
216
202
|
return ts.factory.createTemplateExpression(
|
@@ -224,7 +210,7 @@ export namespace MigrateApiNamespaceProgrammer {
|
|
224
210
|
[
|
225
211
|
ts.factory.createBinaryExpression(
|
226
212
|
ts.factory.createIdentifier(
|
227
|
-
|
213
|
+
route.parameters.find((p) => p.name === name)!.key,
|
228
214
|
),
|
229
215
|
ts.factory.createToken(ts.SyntaxKind.QuestionQuestionToken),
|
230
216
|
ts.factory.createStringLiteral("null"),
|
@@ -238,10 +224,10 @@ export namespace MigrateApiNamespaceProgrammer {
|
|
238
224
|
}),
|
239
225
|
);
|
240
226
|
};
|
241
|
-
if (!
|
227
|
+
if (!route.query) return out(template());
|
242
228
|
|
243
229
|
const computeName = (str: string): string =>
|
244
|
-
|
230
|
+
route.parameters.find((p) => p.key === str) !== undefined
|
245
231
|
? computeName("_" + str)
|
246
232
|
: str;
|
247
233
|
const variables: string = computeName("variables");
|
@@ -286,7 +272,7 @@ export namespace MigrateApiNamespaceProgrammer {
|
|
286
272
|
undefined,
|
287
273
|
[
|
288
274
|
ts.factory.createAsExpression(
|
289
|
-
ts.factory.createIdentifier(
|
275
|
+
ts.factory.createIdentifier(route.query.key),
|
290
276
|
TypeFactory.keyword("any"),
|
291
277
|
),
|
292
278
|
],
|
@@ -409,11 +395,7 @@ const constant = (name: string) => (expression: ts.Expression) =>
|
|
409
395
|
ts.NodeFlags.Const,
|
410
396
|
),
|
411
397
|
);
|
412
|
-
const getPath = (
|
413
|
-
"/" +
|
414
|
-
[...props.controller.path.split("/"), ...props.route.path.split("/")]
|
415
|
-
.filter((str) => !!str.length)
|
416
|
-
.join("/");
|
398
|
+
const getPath = (route: IMigrateRoute) => "/" + route.emendedPath;
|
417
399
|
const local = (name: string) => (type: string) => (expression: ts.Expression) =>
|
418
400
|
ts.factory.createVariableStatement(
|
419
401
|
[],
|
@@ -1,56 +1,42 @@
|
|
1
|
-
import { HashMap,
|
1
|
+
import { HashMap, hash } from "tstl";
|
2
2
|
import ts from "typescript";
|
3
|
-
import { Escaper } from "typia/lib/utils/Escaper";
|
4
3
|
|
5
|
-
import { IMigrateController } from "../structures/IMigrateController";
|
6
4
|
import { IMigrateFile } from "../structures/IMigrateFile";
|
7
5
|
import { IMigrateProgram } from "../structures/IMigrateProgram";
|
8
|
-
import { IMigrateRoute } from "../structures/IMigrateRoute";
|
9
6
|
import { FilePrinter } from "../utils/FilePrinter";
|
10
|
-
import { StringUtil } from "../utils/StringUtil";
|
11
7
|
import { MigrateApiFileProgrammer } from "./MigrateApiFileProgrammer";
|
12
8
|
import { MigrateDtoProgrammer } from "./MigrateDtoProgrammer";
|
13
9
|
import { MigrateImportProgrammer } from "./MigrateImportProgrammer";
|
14
10
|
|
15
11
|
export namespace MigrateApiProgrammer {
|
16
12
|
export const write = (program: IMigrateProgram): IMigrateFile[] => {
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
...(entry.route.query ? [entry.route.query] : []),
|
40
|
-
];
|
41
|
-
parameters.forEach(
|
42
|
-
(p, i) =>
|
43
|
-
(p.key = StringUtil.escapeDuplicate([
|
44
|
-
"connection",
|
45
|
-
entry.alias,
|
46
|
-
...parameters.filter((_, j) => i !== j).map((y) => y.key),
|
47
|
-
])(p.key)),
|
13
|
+
const dict: HashMap<string[], MigrateApiFileProgrammer.IProps> =
|
14
|
+
new HashMap(
|
15
|
+
(x) => hash(x.join(".")),
|
16
|
+
(x, y) => x.length === y.length && x.join(".") === y.join("."),
|
17
|
+
);
|
18
|
+
for (const route of program.routes) {
|
19
|
+
const namespace: string[] = route.accessor.slice(0, -1);
|
20
|
+
let last: MigrateApiFileProgrammer.IProps = dict.take(namespace, () => ({
|
21
|
+
namespace,
|
22
|
+
routes: [],
|
23
|
+
children: new Set(),
|
24
|
+
}));
|
25
|
+
last.routes.push(route);
|
26
|
+
namespace.forEach((_s, i, array) => {
|
27
|
+
const partial: string[] = namespace.slice(0, array.length - i - 1);
|
28
|
+
const props: MigrateApiFileProgrammer.IProps = dict.take(
|
29
|
+
partial,
|
30
|
+
() => ({
|
31
|
+
namespace: partial,
|
32
|
+
children: new Set(),
|
33
|
+
routes: [],
|
34
|
+
}),
|
48
35
|
);
|
36
|
+
props.children.add(last.namespace.at(-1)!);
|
37
|
+
last = props;
|
49
38
|
});
|
50
|
-
|
51
|
-
// // GROUP BY NAMESPACES AGAIN
|
52
|
-
// const refined: HashMap<string[], MigrateApiFileProgrammer.IProps> =
|
53
|
-
// collect(({ route }) => route.accessor.slice(0, -1))(program);
|
39
|
+
}
|
54
40
|
|
55
41
|
// DO GENERATE
|
56
42
|
const output: IMigrateFile[] = [...dict].map(({ second: props }) => ({
|
@@ -114,59 +100,4 @@ export namespace MigrateApiProgrammer {
|
|
114
100
|
}
|
115
101
|
return output;
|
116
102
|
};
|
117
|
-
|
118
|
-
const collect =
|
119
|
-
(
|
120
|
-
getter: (props: {
|
121
|
-
controller: IMigrateController;
|
122
|
-
route: IMigrateRoute;
|
123
|
-
}) => string[],
|
124
|
-
) =>
|
125
|
-
(
|
126
|
-
program: IMigrateProgram,
|
127
|
-
): HashMap<string[], MigrateApiFileProgrammer.IProps> => {
|
128
|
-
const dict: HashMap<string[], MigrateApiFileProgrammer.IProps> =
|
129
|
-
new HashMap(Functional.hashCode, Functional.equals);
|
130
|
-
for (const controller of program.controllers)
|
131
|
-
for (const route of controller.routes) {
|
132
|
-
const namespace: string[] = getter({ controller, route });
|
133
|
-
const last: IPointer<MigrateApiFileProgrammer.IProps> = {
|
134
|
-
value: dict.take(namespace, () => ({
|
135
|
-
namespace,
|
136
|
-
children: new Set(),
|
137
|
-
entries: [],
|
138
|
-
})),
|
139
|
-
};
|
140
|
-
last.value.entries.push({
|
141
|
-
controller,
|
142
|
-
route,
|
143
|
-
alias: route.name,
|
144
|
-
});
|
145
|
-
namespace.slice(0, -1).forEach((_i, i, array) => {
|
146
|
-
const partial: string[] = namespace.slice(0, array.length - i);
|
147
|
-
const props: MigrateApiFileProgrammer.IProps = dict.take(
|
148
|
-
partial,
|
149
|
-
() => ({
|
150
|
-
namespace: partial,
|
151
|
-
children: new Set(),
|
152
|
-
entries: [],
|
153
|
-
}),
|
154
|
-
);
|
155
|
-
props.children.add(last.value.namespace.at(-1)!);
|
156
|
-
last.value = props;
|
157
|
-
});
|
158
|
-
const top = dict.take([], () => ({
|
159
|
-
namespace: [],
|
160
|
-
children: new Set(),
|
161
|
-
entries: [],
|
162
|
-
}));
|
163
|
-
if (namespace.length) top.children.add(namespace[0]);
|
164
|
-
}
|
165
|
-
return dict;
|
166
|
-
};
|
167
103
|
}
|
168
|
-
|
169
|
-
const Functional = {
|
170
|
-
hashCode: (x: string[]) => hash(x.join(".")),
|
171
|
-
equals: (a: string[], b: string[]) => a.join(".") === b.join("."),
|
172
|
-
};
|
@@ -4,7 +4,6 @@ import { IdentifierFactory } from "typia/lib/factories/IdentifierFactory";
|
|
4
4
|
import { StatementFactory } from "typia/lib/factories/StatementFactory";
|
5
5
|
import { TypeFactory } from "typia/lib/factories/TypeFactory";
|
6
6
|
|
7
|
-
import { IMigrateController } from "../structures/IMigrateController";
|
8
7
|
import { IMigrateRoute } from "../structures/IMigrateRoute";
|
9
8
|
import { MigrateApiFunctionProgrammer } from "./MigrateApiFunctionProgrammer";
|
10
9
|
import { MigrateApiNamespaceProgrammer } from "./MigrateApiNamespaceProgrammer";
|
@@ -12,18 +11,13 @@ import { MigrateImportProgrammer } from "./MigrateImportProgrammer";
|
|
12
11
|
import { MigrateSchemaProgrammer } from "./MigrateSchemaProgrammer";
|
13
12
|
|
14
13
|
export namespace MigrateApiSimulatationProgrammer {
|
15
|
-
export interface IProps {
|
16
|
-
controller: IMigrateController;
|
17
|
-
route: IMigrateRoute;
|
18
|
-
alias: string;
|
19
|
-
}
|
20
14
|
export const random =
|
21
15
|
(components: OpenApi.IComponents) =>
|
22
16
|
(importer: MigrateImportProgrammer) =>
|
23
|
-
(
|
24
|
-
const output =
|
17
|
+
(route: IMigrateRoute) => {
|
18
|
+
const output = route.success
|
25
19
|
? MigrateSchemaProgrammer.write(components)(importer)(
|
26
|
-
|
20
|
+
route.success.schema,
|
27
21
|
)
|
28
22
|
: TypeFactory.keyword("void");
|
29
23
|
return constant("random")(
|
@@ -72,7 +66,7 @@ export namespace MigrateApiSimulatationProgrammer {
|
|
72
66
|
export const simulate =
|
73
67
|
(components: OpenApi.IComponents) =>
|
74
68
|
(importer: MigrateImportProgrammer) =>
|
75
|
-
(
|
69
|
+
(route: IMigrateRoute): ts.VariableStatement => {
|
76
70
|
const caller = () =>
|
77
71
|
ts.factory.createCallExpression(
|
78
72
|
ts.factory.createIdentifier("random"),
|
@@ -104,14 +98,12 @@ export namespace MigrateApiSimulatationProgrammer {
|
|
104
98
|
undefined,
|
105
99
|
MigrateApiFunctionProgrammer.writeParameterDeclarations(components)(
|
106
100
|
importer,
|
107
|
-
)(
|
108
|
-
ts.factory.createTypeReferenceNode(
|
109
|
-
props.route.success ? "Output" : "void",
|
110
|
-
),
|
101
|
+
)(route),
|
102
|
+
ts.factory.createTypeReferenceNode(route.success ? "Output" : "void"),
|
111
103
|
undefined,
|
112
104
|
ts.factory.createBlock(
|
113
105
|
[
|
114
|
-
...assert(components)(importer)(
|
106
|
+
...assert(components)(importer)(route),
|
115
107
|
ts.factory.createReturnStatement(caller()),
|
116
108
|
],
|
117
109
|
true,
|
@@ -123,31 +115,31 @@ export namespace MigrateApiSimulatationProgrammer {
|
|
123
115
|
const assert =
|
124
116
|
(components: OpenApi.IComponents) =>
|
125
117
|
(importer: MigrateImportProgrammer) =>
|
126
|
-
(
|
118
|
+
(route: IMigrateRoute): ts.Statement[] => {
|
127
119
|
const parameters = [
|
128
|
-
...
|
120
|
+
...route.parameters.map((p) => ({
|
129
121
|
category: "param",
|
130
122
|
name: p.key,
|
131
123
|
schema: MigrateSchemaProgrammer.write(components)(importer)(p.schema),
|
132
124
|
})),
|
133
|
-
...(
|
125
|
+
...(route.query
|
134
126
|
? [
|
135
127
|
{
|
136
128
|
category: "query",
|
137
|
-
name:
|
129
|
+
name: route.query.key,
|
138
130
|
schema: MigrateSchemaProgrammer.write(components)(importer)(
|
139
|
-
|
131
|
+
route.query.schema,
|
140
132
|
),
|
141
133
|
},
|
142
134
|
]
|
143
135
|
: []),
|
144
|
-
...(
|
136
|
+
...(route.body
|
145
137
|
? [
|
146
138
|
{
|
147
139
|
category: "body",
|
148
|
-
name:
|
140
|
+
name: route.body.key,
|
149
141
|
schema: MigrateSchemaProgrammer.write(components)(importer)(
|
150
|
-
|
142
|
+
route.body.schema,
|
151
143
|
),
|
152
144
|
},
|
153
145
|
]
|
@@ -181,12 +173,12 @@ export namespace MigrateApiSimulatationProgrammer {
|
|
181
173
|
),
|
182
174
|
ts.factory.createPropertyAssignment(
|
183
175
|
"path",
|
184
|
-
MigrateApiNamespaceProgrammer.writePathCallExpression(
|
176
|
+
MigrateApiNamespaceProgrammer.writePathCallExpression(route),
|
185
177
|
),
|
186
178
|
ts.factory.createPropertyAssignment(
|
187
179
|
"contentType",
|
188
180
|
ts.factory.createStringLiteral(
|
189
|
-
|
181
|
+
route.success?.type ?? "application/json",
|
190
182
|
),
|
191
183
|
),
|
192
184
|
],
|
@@ -15,7 +15,7 @@ export namespace MigrateApiStartProgrammer {
|
|
15
15
|
const importer: MigrateImportProgrammer = new MigrateImportProgrammer();
|
16
16
|
const main: ts.VariableStatement = writeMain(program)(program.document)(
|
17
17
|
importer,
|
18
|
-
)(pick(program.
|
18
|
+
)(pick(program.routes));
|
19
19
|
const statements: ts.Statement[] = [
|
20
20
|
...importer.toStatements(
|
21
21
|
(name) => `@ORGANIZATION/PROJECT-api/lib/structures/${name}`,
|