@nestia/migrate 7.0.0-dev.20250608 → 7.0.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/README.md +92 -92
- package/lib/analyzers/NestiaMigrateControllerAnalyzer.js +1 -1
- package/lib/analyzers/NestiaMigrateControllerAnalyzer.js.map +1 -1
- package/lib/bundles/NEST_TEMPLATE.js +47 -47
- package/lib/bundles/NEST_TEMPLATE.js.map +1 -1
- package/lib/bundles/SDK_TEMPLATE.js +21 -21
- package/lib/bundles/SDK_TEMPLATE.js.map +1 -1
- package/lib/index.mjs +69 -69
- package/lib/index.mjs.map +1 -1
- package/lib/utils/openapi-down-convert/converter.js +2 -2
- package/package.json +7 -7
- package/src/NestiaMigrateApplication.ts +144 -144
- package/src/analyzers/NestiaMigrateControllerAnalyzer.ts +51 -51
- package/src/archivers/NestiaMigrateFileArchiver.ts +28 -28
- package/src/bundles/NEST_TEMPLATE.ts +47 -47
- package/src/bundles/SDK_TEMPLATE.ts +21 -21
- package/src/executable/NestiaMigrateCommander.ts +98 -98
- package/src/executable/NestiaMigrateInquirer.ts +106 -106
- package/src/executable/bundle.js +129 -129
- package/src/executable/migrate.ts +7 -7
- package/src/factories/TypeLiteralFactory.ts +57 -57
- package/src/index.ts +4 -4
- package/src/module.ts +2 -2
- package/src/programmers/NestiaMigrateApiFileProgrammer.ts +55 -55
- package/src/programmers/NestiaMigrateApiFunctionProgrammer.ts +256 -256
- package/src/programmers/NestiaMigrateApiNamespaceProgrammer.ts +515 -515
- package/src/programmers/NestiaMigrateApiProgrammer.ts +107 -107
- package/src/programmers/NestiaMigrateApiSimulationProgrammer.ts +340 -340
- package/src/programmers/NestiaMigrateApiStartProgrammer.ts +198 -198
- package/src/programmers/NestiaMigrateDtoProgrammer.ts +101 -101
- package/src/programmers/NestiaMigrateE2eFileProgrammer.ts +153 -153
- package/src/programmers/NestiaMigrateE2eProgrammer.ts +46 -46
- package/src/programmers/NestiaMigrateImportProgrammer.ts +118 -118
- package/src/programmers/NestiaMigrateNestControllerProgrammer.ts +66 -66
- package/src/programmers/NestiaMigrateNestMethodProgrammer.ts +406 -406
- package/src/programmers/NestiaMigrateNestModuleProgrammer.ts +65 -65
- package/src/programmers/NestiaMigrateNestProgrammer.ts +88 -88
- package/src/programmers/NestiaMigrateSchemaProgrammer.ts +475 -475
- package/src/structures/INestiaMigrateConfig.ts +10 -10
- package/src/structures/INestiaMigrateContext.ts +15 -15
- package/src/structures/INestiaMigrateController.ts +8 -8
- package/src/structures/INestiaMigrateDto.ts +8 -8
- package/src/structures/INestiaMigrateFile.ts +5 -5
- package/src/structures/INestiaMigrateProgram.ts +11 -11
- package/src/structures/INestiaMigrateSchema.ts +4 -4
- package/src/utils/FilePrinter.ts +38 -38
- package/src/utils/MapUtil.ts +13 -13
- package/src/utils/OpenApiTypeChecker.ts +73 -73
- package/src/utils/SetupWizard.ts +12 -12
- package/src/utils/StringUtil.ts +113 -113
- package/src/utils/openapi-down-convert/RefVisitor.ts +139 -139
- package/src/utils/openapi-down-convert/converter.ts +527 -527
@@ -1,256 +1,256 @@
|
|
1
|
-
import { IHttpMigrateRoute, OpenApi } from "@samchon/openapi";
|
2
|
-
import ts from "typescript";
|
3
|
-
import { IdentifierFactory } from "typia/lib/factories/IdentifierFactory";
|
4
|
-
|
5
|
-
import { INestiaMigrateConfig } from "../structures/INestiaMigrateConfig";
|
6
|
-
import { FilePrinter } from "../utils/FilePrinter";
|
7
|
-
import { NestiaMigrateImportProgrammer } from "./NestiaMigrateImportProgrammer";
|
8
|
-
import { NestiaMigrateSchemaProgrammer } from "./NestiaMigrateSchemaProgrammer";
|
9
|
-
|
10
|
-
export namespace NestiaMigrateApiFunctionProgrammer {
|
11
|
-
export interface IContext {
|
12
|
-
config: INestiaMigrateConfig;
|
13
|
-
components: OpenApi.IComponents;
|
14
|
-
importer: NestiaMigrateImportProgrammer;
|
15
|
-
route: IHttpMigrateRoute;
|
16
|
-
}
|
17
|
-
|
18
|
-
export const write = (ctx: IContext): ts.FunctionDeclaration =>
|
19
|
-
FilePrinter.description(
|
20
|
-
ts.factory.createFunctionDeclaration(
|
21
|
-
[
|
22
|
-
ts.factory.createModifier(ts.SyntaxKind.ExportKeyword),
|
23
|
-
ts.factory.createModifier(ts.SyntaxKind.AsyncKeyword),
|
24
|
-
],
|
25
|
-
undefined,
|
26
|
-
ctx.route.accessor.at(-1)!,
|
27
|
-
undefined,
|
28
|
-
writeParameterDeclarations(ctx),
|
29
|
-
ts.factory.createTypeReferenceNode("Promise", [
|
30
|
-
ts.factory.createTypeReferenceNode(
|
31
|
-
ctx.route.success === null
|
32
|
-
? "void"
|
33
|
-
: `${ctx.route.accessor.at(-1)!}.Response`,
|
34
|
-
),
|
35
|
-
]),
|
36
|
-
ts.factory.createBlock(writeBody(ctx), true),
|
37
|
-
),
|
38
|
-
writeDescription(ctx.config, ctx.route),
|
39
|
-
);
|
40
|
-
|
41
|
-
export const writeParameterDeclarations = (
|
42
|
-
ctx: IContext,
|
43
|
-
): ts.ParameterDeclaration[] => {
|
44
|
-
const connection: ts.ParameterDeclaration = IdentifierFactory.parameter(
|
45
|
-
"connection",
|
46
|
-
ts.factory.createTypeReferenceNode(
|
47
|
-
ctx.importer.external({
|
48
|
-
type: "instance",
|
49
|
-
library: "@nestia/fetcher",
|
50
|
-
name: "IConnection",
|
51
|
-
}),
|
52
|
-
ctx.route.headers
|
53
|
-
? [
|
54
|
-
ts.factory.createTypeReferenceNode(
|
55
|
-
`${ctx.route.accessor.at(-1)!}.Headers`,
|
56
|
-
),
|
57
|
-
]
|
58
|
-
: undefined,
|
59
|
-
),
|
60
|
-
);
|
61
|
-
if (ctx.config.keyword === true) {
|
62
|
-
const isProps: boolean =
|
63
|
-
ctx.route.parameters.length > 0 ||
|
64
|
-
!!ctx.route.query ||
|
65
|
-
!!ctx.route.body;
|
66
|
-
if (isProps === false) return [connection];
|
67
|
-
return [
|
68
|
-
connection,
|
69
|
-
ts.factory.createParameterDeclaration(
|
70
|
-
undefined,
|
71
|
-
undefined,
|
72
|
-
"props",
|
73
|
-
undefined,
|
74
|
-
ts.factory.createTypeReferenceNode(
|
75
|
-
`${ctx.route.accessor.at(-1)!}.Props`,
|
76
|
-
),
|
77
|
-
),
|
78
|
-
];
|
79
|
-
}
|
80
|
-
return [
|
81
|
-
connection,
|
82
|
-
...ctx.route.parameters.map((p) =>
|
83
|
-
IdentifierFactory.parameter(
|
84
|
-
p.key,
|
85
|
-
NestiaMigrateSchemaProgrammer.write({
|
86
|
-
components: ctx.components,
|
87
|
-
importer: ctx.importer,
|
88
|
-
schema: p.schema,
|
89
|
-
}),
|
90
|
-
),
|
91
|
-
),
|
92
|
-
...(ctx.route.query
|
93
|
-
? [
|
94
|
-
IdentifierFactory.parameter(
|
95
|
-
ctx.route.query.key,
|
96
|
-
ts.factory.createTypeReferenceNode(
|
97
|
-
`${ctx.route.accessor.at(-1)!}.Query`,
|
98
|
-
),
|
99
|
-
),
|
100
|
-
]
|
101
|
-
: []),
|
102
|
-
...(ctx.route.body
|
103
|
-
? [
|
104
|
-
IdentifierFactory.parameter(
|
105
|
-
ctx.route.body.key,
|
106
|
-
ts.factory.createTypeReferenceNode(
|
107
|
-
`${ctx.route.accessor.at(-1)!}.Body`,
|
108
|
-
),
|
109
|
-
(ctx.route.body.type === "application/json" ||
|
110
|
-
ctx.route.body.type === "text/plain") &&
|
111
|
-
ctx.route.operation().requestBody?.required === false
|
112
|
-
? ts.factory.createToken(ts.SyntaxKind.QuestionToken)
|
113
|
-
: undefined,
|
114
|
-
),
|
115
|
-
]
|
116
|
-
: []),
|
117
|
-
];
|
118
|
-
};
|
119
|
-
|
120
|
-
const writeDescription = (
|
121
|
-
config: INestiaMigrateConfig,
|
122
|
-
route: IHttpMigrateRoute,
|
123
|
-
): string => {
|
124
|
-
const comment: string = route.comment();
|
125
|
-
return [
|
126
|
-
config.keyword === true
|
127
|
-
? comment.split("@param ").join("@param props.")
|
128
|
-
: comment,
|
129
|
-
`@path ${route.emendedPath}`,
|
130
|
-
`@${config.author?.tag ?? "nestia"} ${config.author?.value ?? "Generated by Nestia - https://github.com/samchon/nestia"}`,
|
131
|
-
].join("\n");
|
132
|
-
};
|
133
|
-
|
134
|
-
const writeBody = (ctx: IContext): ts.Statement[] => {
|
135
|
-
const encrypted: boolean = !!ctx.route.success?.["x-nestia-encrypted"];
|
136
|
-
const contentType: string = ctx.route.body?.type ?? "application/json";
|
137
|
-
|
138
|
-
const property = (key: string): ts.Expression =>
|
139
|
-
ctx.config.keyword === true
|
140
|
-
? IdentifierFactory.access(ts.factory.createIdentifier("props"), key)
|
141
|
-
: ts.factory.createIdentifier(key);
|
142
|
-
const fetch = () =>
|
143
|
-
ts.factory.createCallExpression(
|
144
|
-
IdentifierFactory.access(
|
145
|
-
ts.factory.createIdentifier(
|
146
|
-
ctx.importer.external({
|
147
|
-
type: "instance",
|
148
|
-
library: `@nestia/fetcher/lib/${encrypted ? "EncryptedFetcher" : "PlainFetcher"}`,
|
149
|
-
name: encrypted ? "EncryptedFetcher" : "PlainFetcher",
|
150
|
-
}),
|
151
|
-
),
|
152
|
-
"fetch",
|
153
|
-
),
|
154
|
-
undefined,
|
155
|
-
[
|
156
|
-
contentType && contentType !== "multipart/form-data"
|
157
|
-
? ts.factory.createObjectLiteralExpression(
|
158
|
-
[
|
159
|
-
ts.factory.createSpreadAssignment(
|
160
|
-
ts.factory.createIdentifier("connection"),
|
161
|
-
),
|
162
|
-
ts.factory.createPropertyAssignment(
|
163
|
-
"headers",
|
164
|
-
ts.factory.createObjectLiteralExpression(
|
165
|
-
[
|
166
|
-
ts.factory.createSpreadAssignment(
|
167
|
-
IdentifierFactory.access(
|
168
|
-
ts.factory.createIdentifier("connection"),
|
169
|
-
"headers",
|
170
|
-
),
|
171
|
-
),
|
172
|
-
ts.factory.createPropertyAssignment(
|
173
|
-
ts.factory.createStringLiteral("Content-Type"),
|
174
|
-
ts.factory.createStringLiteral(contentType),
|
175
|
-
),
|
176
|
-
],
|
177
|
-
true,
|
178
|
-
),
|
179
|
-
),
|
180
|
-
],
|
181
|
-
true,
|
182
|
-
)
|
183
|
-
: ts.factory.createIdentifier("connection"),
|
184
|
-
ts.factory.createObjectLiteralExpression(
|
185
|
-
[
|
186
|
-
ts.factory.createSpreadAssignment(
|
187
|
-
IdentifierFactory.access(
|
188
|
-
ts.factory.createIdentifier(ctx.route.accessor.at(-1)!),
|
189
|
-
"METADATA",
|
190
|
-
),
|
191
|
-
),
|
192
|
-
ts.factory.createPropertyAssignment(
|
193
|
-
"path",
|
194
|
-
ts.factory.createCallExpression(
|
195
|
-
IdentifierFactory.access(
|
196
|
-
ts.factory.createIdentifier(ctx.route.accessor.at(-1)!),
|
197
|
-
"path",
|
198
|
-
),
|
199
|
-
undefined,
|
200
|
-
getArguments(ctx, false),
|
201
|
-
),
|
202
|
-
),
|
203
|
-
ts.factory.createPropertyAssignment(
|
204
|
-
"status",
|
205
|
-
ts.factory.createNull(),
|
206
|
-
),
|
207
|
-
],
|
208
|
-
true,
|
209
|
-
),
|
210
|
-
...(ctx.route.body ? [property(ctx.route.body.key)] : []),
|
211
|
-
],
|
212
|
-
);
|
213
|
-
if (ctx.config.simulate !== true)
|
214
|
-
return [ts.factory.createReturnStatement(fetch())];
|
215
|
-
return [
|
216
|
-
ts.factory.createReturnStatement(
|
217
|
-
ts.factory.createConditionalExpression(
|
218
|
-
ts.factory.createIdentifier("!!connection.simulate"),
|
219
|
-
undefined,
|
220
|
-
ts.factory.createCallExpression(
|
221
|
-
ts.factory.createIdentifier(
|
222
|
-
`${ctx.route.accessor.at(-1)!}.simulate`,
|
223
|
-
),
|
224
|
-
[],
|
225
|
-
[
|
226
|
-
ts.factory.createIdentifier("connection"),
|
227
|
-
...getArguments(ctx, true),
|
228
|
-
],
|
229
|
-
),
|
230
|
-
undefined,
|
231
|
-
fetch(),
|
232
|
-
),
|
233
|
-
),
|
234
|
-
];
|
235
|
-
};
|
236
|
-
|
237
|
-
const getArguments = (ctx: IContext, body: boolean): ts.Expression[] => {
|
238
|
-
if (
|
239
|
-
ctx.route.parameters.length === 0 &&
|
240
|
-
ctx.route.query === null &&
|
241
|
-
(body === false || ctx.route.body === null)
|
242
|
-
)
|
243
|
-
return [];
|
244
|
-
else if (ctx.config.keyword === true)
|
245
|
-
return [ts.factory.createIdentifier("props")];
|
246
|
-
return [
|
247
|
-
...ctx.route.parameters.map((p) => ts.factory.createIdentifier(p.key)),
|
248
|
-
...(ctx.route.query
|
249
|
-
? [ts.factory.createIdentifier(ctx.route.query.key)]
|
250
|
-
: []),
|
251
|
-
...(body && ctx.route.body
|
252
|
-
? [ts.factory.createIdentifier(ctx.route.body.key)]
|
253
|
-
: []),
|
254
|
-
];
|
255
|
-
};
|
256
|
-
}
|
1
|
+
import { IHttpMigrateRoute, OpenApi } from "@samchon/openapi";
|
2
|
+
import ts from "typescript";
|
3
|
+
import { IdentifierFactory } from "typia/lib/factories/IdentifierFactory";
|
4
|
+
|
5
|
+
import { INestiaMigrateConfig } from "../structures/INestiaMigrateConfig";
|
6
|
+
import { FilePrinter } from "../utils/FilePrinter";
|
7
|
+
import { NestiaMigrateImportProgrammer } from "./NestiaMigrateImportProgrammer";
|
8
|
+
import { NestiaMigrateSchemaProgrammer } from "./NestiaMigrateSchemaProgrammer";
|
9
|
+
|
10
|
+
export namespace NestiaMigrateApiFunctionProgrammer {
|
11
|
+
export interface IContext {
|
12
|
+
config: INestiaMigrateConfig;
|
13
|
+
components: OpenApi.IComponents;
|
14
|
+
importer: NestiaMigrateImportProgrammer;
|
15
|
+
route: IHttpMigrateRoute;
|
16
|
+
}
|
17
|
+
|
18
|
+
export const write = (ctx: IContext): ts.FunctionDeclaration =>
|
19
|
+
FilePrinter.description(
|
20
|
+
ts.factory.createFunctionDeclaration(
|
21
|
+
[
|
22
|
+
ts.factory.createModifier(ts.SyntaxKind.ExportKeyword),
|
23
|
+
ts.factory.createModifier(ts.SyntaxKind.AsyncKeyword),
|
24
|
+
],
|
25
|
+
undefined,
|
26
|
+
ctx.route.accessor.at(-1)!,
|
27
|
+
undefined,
|
28
|
+
writeParameterDeclarations(ctx),
|
29
|
+
ts.factory.createTypeReferenceNode("Promise", [
|
30
|
+
ts.factory.createTypeReferenceNode(
|
31
|
+
ctx.route.success === null
|
32
|
+
? "void"
|
33
|
+
: `${ctx.route.accessor.at(-1)!}.Response`,
|
34
|
+
),
|
35
|
+
]),
|
36
|
+
ts.factory.createBlock(writeBody(ctx), true),
|
37
|
+
),
|
38
|
+
writeDescription(ctx.config, ctx.route),
|
39
|
+
);
|
40
|
+
|
41
|
+
export const writeParameterDeclarations = (
|
42
|
+
ctx: IContext,
|
43
|
+
): ts.ParameterDeclaration[] => {
|
44
|
+
const connection: ts.ParameterDeclaration = IdentifierFactory.parameter(
|
45
|
+
"connection",
|
46
|
+
ts.factory.createTypeReferenceNode(
|
47
|
+
ctx.importer.external({
|
48
|
+
type: "instance",
|
49
|
+
library: "@nestia/fetcher",
|
50
|
+
name: "IConnection",
|
51
|
+
}),
|
52
|
+
ctx.route.headers
|
53
|
+
? [
|
54
|
+
ts.factory.createTypeReferenceNode(
|
55
|
+
`${ctx.route.accessor.at(-1)!}.Headers`,
|
56
|
+
),
|
57
|
+
]
|
58
|
+
: undefined,
|
59
|
+
),
|
60
|
+
);
|
61
|
+
if (ctx.config.keyword === true) {
|
62
|
+
const isProps: boolean =
|
63
|
+
ctx.route.parameters.length > 0 ||
|
64
|
+
!!ctx.route.query ||
|
65
|
+
!!ctx.route.body;
|
66
|
+
if (isProps === false) return [connection];
|
67
|
+
return [
|
68
|
+
connection,
|
69
|
+
ts.factory.createParameterDeclaration(
|
70
|
+
undefined,
|
71
|
+
undefined,
|
72
|
+
"props",
|
73
|
+
undefined,
|
74
|
+
ts.factory.createTypeReferenceNode(
|
75
|
+
`${ctx.route.accessor.at(-1)!}.Props`,
|
76
|
+
),
|
77
|
+
),
|
78
|
+
];
|
79
|
+
}
|
80
|
+
return [
|
81
|
+
connection,
|
82
|
+
...ctx.route.parameters.map((p) =>
|
83
|
+
IdentifierFactory.parameter(
|
84
|
+
p.key,
|
85
|
+
NestiaMigrateSchemaProgrammer.write({
|
86
|
+
components: ctx.components,
|
87
|
+
importer: ctx.importer,
|
88
|
+
schema: p.schema,
|
89
|
+
}),
|
90
|
+
),
|
91
|
+
),
|
92
|
+
...(ctx.route.query
|
93
|
+
? [
|
94
|
+
IdentifierFactory.parameter(
|
95
|
+
ctx.route.query.key,
|
96
|
+
ts.factory.createTypeReferenceNode(
|
97
|
+
`${ctx.route.accessor.at(-1)!}.Query`,
|
98
|
+
),
|
99
|
+
),
|
100
|
+
]
|
101
|
+
: []),
|
102
|
+
...(ctx.route.body
|
103
|
+
? [
|
104
|
+
IdentifierFactory.parameter(
|
105
|
+
ctx.route.body.key,
|
106
|
+
ts.factory.createTypeReferenceNode(
|
107
|
+
`${ctx.route.accessor.at(-1)!}.Body`,
|
108
|
+
),
|
109
|
+
(ctx.route.body.type === "application/json" ||
|
110
|
+
ctx.route.body.type === "text/plain") &&
|
111
|
+
ctx.route.operation().requestBody?.required === false
|
112
|
+
? ts.factory.createToken(ts.SyntaxKind.QuestionToken)
|
113
|
+
: undefined,
|
114
|
+
),
|
115
|
+
]
|
116
|
+
: []),
|
117
|
+
];
|
118
|
+
};
|
119
|
+
|
120
|
+
const writeDescription = (
|
121
|
+
config: INestiaMigrateConfig,
|
122
|
+
route: IHttpMigrateRoute,
|
123
|
+
): string => {
|
124
|
+
const comment: string = route.comment();
|
125
|
+
return [
|
126
|
+
config.keyword === true
|
127
|
+
? comment.split("@param ").join("@param props.")
|
128
|
+
: comment,
|
129
|
+
`@path ${route.emendedPath}`,
|
130
|
+
`@${config.author?.tag ?? "nestia"} ${config.author?.value ?? "Generated by Nestia - https://github.com/samchon/nestia"}`,
|
131
|
+
].join("\n");
|
132
|
+
};
|
133
|
+
|
134
|
+
const writeBody = (ctx: IContext): ts.Statement[] => {
|
135
|
+
const encrypted: boolean = !!ctx.route.success?.["x-nestia-encrypted"];
|
136
|
+
const contentType: string = ctx.route.body?.type ?? "application/json";
|
137
|
+
|
138
|
+
const property = (key: string): ts.Expression =>
|
139
|
+
ctx.config.keyword === true
|
140
|
+
? IdentifierFactory.access(ts.factory.createIdentifier("props"), key)
|
141
|
+
: ts.factory.createIdentifier(key);
|
142
|
+
const fetch = () =>
|
143
|
+
ts.factory.createCallExpression(
|
144
|
+
IdentifierFactory.access(
|
145
|
+
ts.factory.createIdentifier(
|
146
|
+
ctx.importer.external({
|
147
|
+
type: "instance",
|
148
|
+
library: `@nestia/fetcher/lib/${encrypted ? "EncryptedFetcher" : "PlainFetcher"}`,
|
149
|
+
name: encrypted ? "EncryptedFetcher" : "PlainFetcher",
|
150
|
+
}),
|
151
|
+
),
|
152
|
+
"fetch",
|
153
|
+
),
|
154
|
+
undefined,
|
155
|
+
[
|
156
|
+
contentType && contentType !== "multipart/form-data"
|
157
|
+
? ts.factory.createObjectLiteralExpression(
|
158
|
+
[
|
159
|
+
ts.factory.createSpreadAssignment(
|
160
|
+
ts.factory.createIdentifier("connection"),
|
161
|
+
),
|
162
|
+
ts.factory.createPropertyAssignment(
|
163
|
+
"headers",
|
164
|
+
ts.factory.createObjectLiteralExpression(
|
165
|
+
[
|
166
|
+
ts.factory.createSpreadAssignment(
|
167
|
+
IdentifierFactory.access(
|
168
|
+
ts.factory.createIdentifier("connection"),
|
169
|
+
"headers",
|
170
|
+
),
|
171
|
+
),
|
172
|
+
ts.factory.createPropertyAssignment(
|
173
|
+
ts.factory.createStringLiteral("Content-Type"),
|
174
|
+
ts.factory.createStringLiteral(contentType),
|
175
|
+
),
|
176
|
+
],
|
177
|
+
true,
|
178
|
+
),
|
179
|
+
),
|
180
|
+
],
|
181
|
+
true,
|
182
|
+
)
|
183
|
+
: ts.factory.createIdentifier("connection"),
|
184
|
+
ts.factory.createObjectLiteralExpression(
|
185
|
+
[
|
186
|
+
ts.factory.createSpreadAssignment(
|
187
|
+
IdentifierFactory.access(
|
188
|
+
ts.factory.createIdentifier(ctx.route.accessor.at(-1)!),
|
189
|
+
"METADATA",
|
190
|
+
),
|
191
|
+
),
|
192
|
+
ts.factory.createPropertyAssignment(
|
193
|
+
"path",
|
194
|
+
ts.factory.createCallExpression(
|
195
|
+
IdentifierFactory.access(
|
196
|
+
ts.factory.createIdentifier(ctx.route.accessor.at(-1)!),
|
197
|
+
"path",
|
198
|
+
),
|
199
|
+
undefined,
|
200
|
+
getArguments(ctx, false),
|
201
|
+
),
|
202
|
+
),
|
203
|
+
ts.factory.createPropertyAssignment(
|
204
|
+
"status",
|
205
|
+
ts.factory.createNull(),
|
206
|
+
),
|
207
|
+
],
|
208
|
+
true,
|
209
|
+
),
|
210
|
+
...(ctx.route.body ? [property(ctx.route.body.key)] : []),
|
211
|
+
],
|
212
|
+
);
|
213
|
+
if (ctx.config.simulate !== true)
|
214
|
+
return [ts.factory.createReturnStatement(fetch())];
|
215
|
+
return [
|
216
|
+
ts.factory.createReturnStatement(
|
217
|
+
ts.factory.createConditionalExpression(
|
218
|
+
ts.factory.createIdentifier("!!connection.simulate"),
|
219
|
+
undefined,
|
220
|
+
ts.factory.createCallExpression(
|
221
|
+
ts.factory.createIdentifier(
|
222
|
+
`${ctx.route.accessor.at(-1)!}.simulate`,
|
223
|
+
),
|
224
|
+
[],
|
225
|
+
[
|
226
|
+
ts.factory.createIdentifier("connection"),
|
227
|
+
...getArguments(ctx, true),
|
228
|
+
],
|
229
|
+
),
|
230
|
+
undefined,
|
231
|
+
fetch(),
|
232
|
+
),
|
233
|
+
),
|
234
|
+
];
|
235
|
+
};
|
236
|
+
|
237
|
+
const getArguments = (ctx: IContext, body: boolean): ts.Expression[] => {
|
238
|
+
if (
|
239
|
+
ctx.route.parameters.length === 0 &&
|
240
|
+
ctx.route.query === null &&
|
241
|
+
(body === false || ctx.route.body === null)
|
242
|
+
)
|
243
|
+
return [];
|
244
|
+
else if (ctx.config.keyword === true)
|
245
|
+
return [ts.factory.createIdentifier("props")];
|
246
|
+
return [
|
247
|
+
...ctx.route.parameters.map((p) => ts.factory.createIdentifier(p.key)),
|
248
|
+
...(ctx.route.query
|
249
|
+
? [ts.factory.createIdentifier(ctx.route.query.key)]
|
250
|
+
: []),
|
251
|
+
...(body && ctx.route.body
|
252
|
+
? [ts.factory.createIdentifier(ctx.route.body.key)]
|
253
|
+
: []),
|
254
|
+
];
|
255
|
+
};
|
256
|
+
}
|