@nestia/migrate 0.13.0-dev.20240411-2 → 0.13.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.
Files changed (33) hide show
  1. package/lib/MigrateApplication.js +812 -710
  2. package/lib/MigrateApplication.js.map +1 -1
  3. package/lib/analyzers/MigrateMethodAnalyzer.js +19 -3
  4. package/lib/analyzers/MigrateMethodAnalyzer.js.map +1 -1
  5. package/lib/bundles/NEST_TEMPLATE.js +2 -2
  6. package/lib/bundles/NEST_TEMPLATE.js.map +1 -1
  7. package/lib/bundles/SDK_TEMPLATE.js +1 -1
  8. package/lib/bundles/SDK_TEMPLATE.js.map +1 -1
  9. package/lib/internal/MigrateCommander.js.map +1 -1
  10. package/lib/programmers/MigrateSchemaProgrammer.js +25 -26
  11. package/lib/programmers/MigrateSchemaProgrammer.js.map +1 -1
  12. package/package.json +79 -79
  13. package/src/analyzers/MigrateControllerAnalyzer.ts +137 -137
  14. package/src/analyzers/MigrateMethodAnalyzer.ts +383 -363
  15. package/src/bundles/NEST_TEMPLATE.ts +2 -2
  16. package/src/bundles/SDK_TEMPLATE.ts +1 -1
  17. package/src/internal/MigrateCommander.ts +76 -70
  18. package/src/module.ts +8 -8
  19. package/src/programmers/MigrateApiFileProgrammer.ts +53 -53
  20. package/src/programmers/MigrateApiFunctionProgrammer.ts +199 -199
  21. package/src/programmers/MigrateApiNamespaceProgrammer.ts +431 -431
  22. package/src/programmers/MigrateApiProgrammer.ts +172 -172
  23. package/src/programmers/MigrateApiSimulatationProgrammer.ts +327 -327
  24. package/src/programmers/MigrateDtoProgrammer.ts +77 -77
  25. package/src/programmers/MigrateE2eFileProgrammer.ts +117 -117
  26. package/src/programmers/MigrateE2eProgrammer.ts +36 -36
  27. package/src/programmers/MigrateNestControllerProgrammer.ts +50 -50
  28. package/src/programmers/MigrateNestMethodProgrammer.ts +249 -249
  29. package/src/programmers/MigrateNestProgrammer.ts +74 -74
  30. package/src/structures/IMigrateDto.ts +8 -8
  31. package/src/structures/IMigrateProgram.ts +27 -27
  32. package/src/structures/IMigrateRoute.ts +51 -51
  33. package/src/utils/OpenApiTypeChecker.ts +73 -73
@@ -1,199 +1,199 @@
1
- import { OpenApi } from "@samchon/openapi";
2
- import ts from "typescript";
3
- import { IdentifierFactory } from "typia/lib/factories/IdentifierFactory";
4
-
5
- import { IMigrateController } from "../structures/IMigrateController";
6
- import { IMigrateProgram } from "../structures/IMigrateProgram";
7
- import { IMigrateRoute } from "../structures/IMigrateRoute";
8
- import { FilePrinter } from "../utils/FilePrinter";
9
- import { MigrateImportProgrammer } from "./MigrateImportProgrammer";
10
- import { MigrateSchemaProgrammer } from "./MigrateSchemaProgrammer";
11
-
12
- export namespace MigrateApiFunctionProgrammer {
13
- export interface IProps {
14
- controller: IMigrateController;
15
- route: IMigrateRoute;
16
- alias: string;
17
- }
18
-
19
- export const write =
20
- (config: IMigrateProgram.IConfig) =>
21
- (components: OpenApi.IComponents) =>
22
- (importer: MigrateImportProgrammer) =>
23
- (props: IProps): ts.FunctionDeclaration =>
24
- FilePrinter.description(
25
- ts.factory.createFunctionDeclaration(
26
- [
27
- ts.factory.createModifier(ts.SyntaxKind.ExportKeyword),
28
- ts.factory.createModifier(ts.SyntaxKind.AsyncKeyword),
29
- ],
30
- undefined,
31
- props.alias,
32
- undefined,
33
- writeParameterDeclarations(components)(importer)(props),
34
- ts.factory.createTypeReferenceNode("Promise", [
35
- ts.factory.createTypeReferenceNode(
36
- props.route.success === null ? "void" : `${props.alias}.Output`,
37
- ),
38
- ]),
39
- ts.factory.createBlock(writeBody(config)(importer)(props), true),
40
- ),
41
- writeDescription(props),
42
- );
43
-
44
- export const writeParameterDeclarations =
45
- (components: OpenApi.IComponents) =>
46
- (importer: MigrateImportProgrammer) =>
47
- (props: IProps): ts.ParameterDeclaration[] => [
48
- IdentifierFactory.parameter(
49
- "connection",
50
- ts.factory.createTypeReferenceNode(
51
- importer.external({
52
- type: "instance",
53
- library: "@nestia/fetcher",
54
- name: "IConnection",
55
- }),
56
- props.route.headers
57
- ? [ts.factory.createTypeReferenceNode(`${props.alias}.Headers`)]
58
- : undefined,
59
- ),
60
- ),
61
- ...props.route.parameters.map((p) =>
62
- IdentifierFactory.parameter(
63
- p.key,
64
- MigrateSchemaProgrammer.write(components)(importer)(p.schema),
65
- ),
66
- ),
67
- ...(props.route.query
68
- ? [
69
- IdentifierFactory.parameter(
70
- props.route.query.key,
71
- ts.factory.createTypeReferenceNode(`${props.alias}.Query`),
72
- ),
73
- ]
74
- : []),
75
- ...(props.route.body
76
- ? [
77
- IdentifierFactory.parameter(
78
- props.route.body.key,
79
- ts.factory.createTypeReferenceNode(`${props.alias}.Input`),
80
- ),
81
- ]
82
- : []),
83
- ];
84
-
85
- const writeDescription = (props: IProps): string =>
86
- [
87
- props.route.comment(),
88
- `@controller ${props.controller.name}`,
89
- `@path ${props.route.path}`,
90
- "@nestia Generated by Nestia - https://github.com/samchon/nestia",
91
- ].join("\n");
92
-
93
- const writeBody =
94
- (config: IMigrateProgram.IConfig) =>
95
- (importer: MigrateImportProgrammer) =>
96
- (props: IProps): ts.Statement[] => {
97
- const encrypted: boolean = !!props.route.success?.["x-nestia-encrypted"];
98
- const contentType: string = props.route.body?.type ?? "application/json";
99
-
100
- const caller = () =>
101
- ts.factory.createCallExpression(
102
- IdentifierFactory.access(
103
- ts.factory.createIdentifier(
104
- importer.external({
105
- type: "instance",
106
- library: `@nestia/fetcher/lib/${encrypted ? "EncryptedFetcher" : "PlainFetcher"}`,
107
- name: encrypted ? "EncryptedFetcher" : "PlainFetcher",
108
- }),
109
- ),
110
- )("fetch"),
111
- undefined,
112
- [
113
- contentType && contentType !== "multipart/form-data"
114
- ? ts.factory.createObjectLiteralExpression(
115
- [
116
- ts.factory.createSpreadAssignment(
117
- ts.factory.createIdentifier("connection"),
118
- ),
119
- ts.factory.createPropertyAssignment(
120
- "headers",
121
- ts.factory.createObjectLiteralExpression(
122
- [
123
- ts.factory.createSpreadAssignment(
124
- IdentifierFactory.access(
125
- ts.factory.createIdentifier("connection"),
126
- )("headers"),
127
- ),
128
- ts.factory.createPropertyAssignment(
129
- ts.factory.createStringLiteral("Content-Type"),
130
- ts.factory.createStringLiteral(contentType),
131
- ),
132
- ],
133
- true,
134
- ),
135
- ),
136
- ],
137
- true,
138
- )
139
- : ts.factory.createIdentifier("connection"),
140
- ts.factory.createObjectLiteralExpression(
141
- [
142
- ts.factory.createSpreadAssignment(
143
- IdentifierFactory.access(
144
- ts.factory.createIdentifier(props.alias),
145
- )("METADATA"),
146
- ),
147
- ts.factory.createPropertyAssignment(
148
- "path",
149
- ts.factory.createCallExpression(
150
- IdentifierFactory.access(
151
- ts.factory.createIdentifier(props.alias),
152
- )("path"),
153
- undefined,
154
- [
155
- ...props.route.parameters.map((p) =>
156
- ts.factory.createIdentifier(p.key),
157
- ),
158
- ...(props.route.query
159
- ? [ts.factory.createIdentifier(props.route.query.key)]
160
- : []),
161
- ],
162
- ),
163
- ),
164
- ts.factory.createPropertyAssignment(
165
- "status",
166
- ts.factory.createNull(),
167
- ),
168
- ],
169
- true,
170
- ),
171
- ...(props.route.body
172
- ? [ts.factory.createIdentifier(props.route.body.key)]
173
- : []),
174
- ],
175
- );
176
- if (config.simulate !== true)
177
- return [ts.factory.createReturnStatement(caller())];
178
- return [
179
- ts.factory.createReturnStatement(
180
- ts.factory.createConditionalExpression(
181
- ts.factory.createIdentifier("!!connection.simulate"),
182
- undefined,
183
- ts.factory.createCallExpression(
184
- ts.factory.createIdentifier(`${props.alias}.simulate`),
185
- [],
186
- [
187
- "connection",
188
- ...props.route.parameters.map((p) => p.key),
189
- ...(props.route.query ? [props.route.query.key] : []),
190
- ...(props.route.body ? [props.route.body.key] : []),
191
- ].map((key) => ts.factory.createIdentifier(key)),
192
- ),
193
- undefined,
194
- caller(),
195
- ),
196
- ),
197
- ];
198
- };
199
- }
1
+ import { OpenApi } from "@samchon/openapi";
2
+ import ts from "typescript";
3
+ import { IdentifierFactory } from "typia/lib/factories/IdentifierFactory";
4
+
5
+ import { IMigrateController } from "../structures/IMigrateController";
6
+ import { IMigrateProgram } from "../structures/IMigrateProgram";
7
+ import { IMigrateRoute } from "../structures/IMigrateRoute";
8
+ import { FilePrinter } from "../utils/FilePrinter";
9
+ import { MigrateImportProgrammer } from "./MigrateImportProgrammer";
10
+ import { MigrateSchemaProgrammer } from "./MigrateSchemaProgrammer";
11
+
12
+ export namespace MigrateApiFunctionProgrammer {
13
+ export interface IProps {
14
+ controller: IMigrateController;
15
+ route: IMigrateRoute;
16
+ alias: string;
17
+ }
18
+
19
+ export const write =
20
+ (config: IMigrateProgram.IConfig) =>
21
+ (components: OpenApi.IComponents) =>
22
+ (importer: MigrateImportProgrammer) =>
23
+ (props: IProps): ts.FunctionDeclaration =>
24
+ FilePrinter.description(
25
+ ts.factory.createFunctionDeclaration(
26
+ [
27
+ ts.factory.createModifier(ts.SyntaxKind.ExportKeyword),
28
+ ts.factory.createModifier(ts.SyntaxKind.AsyncKeyword),
29
+ ],
30
+ undefined,
31
+ props.alias,
32
+ undefined,
33
+ writeParameterDeclarations(components)(importer)(props),
34
+ ts.factory.createTypeReferenceNode("Promise", [
35
+ ts.factory.createTypeReferenceNode(
36
+ props.route.success === null ? "void" : `${props.alias}.Output`,
37
+ ),
38
+ ]),
39
+ ts.factory.createBlock(writeBody(config)(importer)(props), true),
40
+ ),
41
+ writeDescription(props),
42
+ );
43
+
44
+ export const writeParameterDeclarations =
45
+ (components: OpenApi.IComponents) =>
46
+ (importer: MigrateImportProgrammer) =>
47
+ (props: IProps): ts.ParameterDeclaration[] => [
48
+ IdentifierFactory.parameter(
49
+ "connection",
50
+ ts.factory.createTypeReferenceNode(
51
+ importer.external({
52
+ type: "instance",
53
+ library: "@nestia/fetcher",
54
+ name: "IConnection",
55
+ }),
56
+ props.route.headers
57
+ ? [ts.factory.createTypeReferenceNode(`${props.alias}.Headers`)]
58
+ : undefined,
59
+ ),
60
+ ),
61
+ ...props.route.parameters.map((p) =>
62
+ IdentifierFactory.parameter(
63
+ p.key,
64
+ MigrateSchemaProgrammer.write(components)(importer)(p.schema),
65
+ ),
66
+ ),
67
+ ...(props.route.query
68
+ ? [
69
+ IdentifierFactory.parameter(
70
+ props.route.query.key,
71
+ ts.factory.createTypeReferenceNode(`${props.alias}.Query`),
72
+ ),
73
+ ]
74
+ : []),
75
+ ...(props.route.body
76
+ ? [
77
+ IdentifierFactory.parameter(
78
+ props.route.body.key,
79
+ ts.factory.createTypeReferenceNode(`${props.alias}.Input`),
80
+ ),
81
+ ]
82
+ : []),
83
+ ];
84
+
85
+ const writeDescription = (props: IProps): string =>
86
+ [
87
+ props.route.comment(),
88
+ `@controller ${props.controller.name}`,
89
+ `@path ${props.route.path}`,
90
+ "@nestia Generated by Nestia - https://github.com/samchon/nestia",
91
+ ].join("\n");
92
+
93
+ const writeBody =
94
+ (config: IMigrateProgram.IConfig) =>
95
+ (importer: MigrateImportProgrammer) =>
96
+ (props: IProps): ts.Statement[] => {
97
+ const encrypted: boolean = !!props.route.success?.["x-nestia-encrypted"];
98
+ const contentType: string = props.route.body?.type ?? "application/json";
99
+
100
+ const caller = () =>
101
+ ts.factory.createCallExpression(
102
+ IdentifierFactory.access(
103
+ ts.factory.createIdentifier(
104
+ importer.external({
105
+ type: "instance",
106
+ library: `@nestia/fetcher/lib/${encrypted ? "EncryptedFetcher" : "PlainFetcher"}`,
107
+ name: encrypted ? "EncryptedFetcher" : "PlainFetcher",
108
+ }),
109
+ ),
110
+ )("fetch"),
111
+ undefined,
112
+ [
113
+ contentType && contentType !== "multipart/form-data"
114
+ ? ts.factory.createObjectLiteralExpression(
115
+ [
116
+ ts.factory.createSpreadAssignment(
117
+ ts.factory.createIdentifier("connection"),
118
+ ),
119
+ ts.factory.createPropertyAssignment(
120
+ "headers",
121
+ ts.factory.createObjectLiteralExpression(
122
+ [
123
+ ts.factory.createSpreadAssignment(
124
+ IdentifierFactory.access(
125
+ ts.factory.createIdentifier("connection"),
126
+ )("headers"),
127
+ ),
128
+ ts.factory.createPropertyAssignment(
129
+ ts.factory.createStringLiteral("Content-Type"),
130
+ ts.factory.createStringLiteral(contentType),
131
+ ),
132
+ ],
133
+ true,
134
+ ),
135
+ ),
136
+ ],
137
+ true,
138
+ )
139
+ : ts.factory.createIdentifier("connection"),
140
+ ts.factory.createObjectLiteralExpression(
141
+ [
142
+ ts.factory.createSpreadAssignment(
143
+ IdentifierFactory.access(
144
+ ts.factory.createIdentifier(props.alias),
145
+ )("METADATA"),
146
+ ),
147
+ ts.factory.createPropertyAssignment(
148
+ "path",
149
+ ts.factory.createCallExpression(
150
+ IdentifierFactory.access(
151
+ ts.factory.createIdentifier(props.alias),
152
+ )("path"),
153
+ undefined,
154
+ [
155
+ ...props.route.parameters.map((p) =>
156
+ ts.factory.createIdentifier(p.key),
157
+ ),
158
+ ...(props.route.query
159
+ ? [ts.factory.createIdentifier(props.route.query.key)]
160
+ : []),
161
+ ],
162
+ ),
163
+ ),
164
+ ts.factory.createPropertyAssignment(
165
+ "status",
166
+ ts.factory.createNull(),
167
+ ),
168
+ ],
169
+ true,
170
+ ),
171
+ ...(props.route.body
172
+ ? [ts.factory.createIdentifier(props.route.body.key)]
173
+ : []),
174
+ ],
175
+ );
176
+ if (config.simulate !== true)
177
+ return [ts.factory.createReturnStatement(caller())];
178
+ return [
179
+ ts.factory.createReturnStatement(
180
+ ts.factory.createConditionalExpression(
181
+ ts.factory.createIdentifier("!!connection.simulate"),
182
+ undefined,
183
+ ts.factory.createCallExpression(
184
+ ts.factory.createIdentifier(`${props.alias}.simulate`),
185
+ [],
186
+ [
187
+ "connection",
188
+ ...props.route.parameters.map((p) => p.key),
189
+ ...(props.route.query ? [props.route.query.key] : []),
190
+ ...(props.route.body ? [props.route.body.key] : []),
191
+ ].map((key) => ts.factory.createIdentifier(key)),
192
+ ),
193
+ undefined,
194
+ caller(),
195
+ ),
196
+ ),
197
+ ];
198
+ };
199
+ }