@nestia/migrate 4.5.2 → 4.6.1-dev.20250117

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