@nestia/migrate 0.7.5 → 0.7.6

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 (114) hide show
  1. package/lib/MigrateApplication.d.ts +9 -2
  2. package/lib/MigrateApplication.js +14 -8
  3. package/lib/MigrateApplication.js.map +1 -1
  4. package/lib/analyzers/MigrateAnalyzer.js +2 -2
  5. package/lib/analyzers/MigrateAnalyzer.js.map +1 -1
  6. package/lib/analyzers/{ControllerAnalyzer.d.ts → MigrateControllerAnalyzer.d.ts} +1 -1
  7. package/lib/analyzers/{ControllerAnalyzer.js → MigrateControllerAnalyzer.js} +11 -9
  8. package/lib/analyzers/MigrateControllerAnalyzer.js.map +1 -0
  9. package/lib/analyzers/{MethodAnalyzer.d.ts → MigrateMethodAnalyzer.d.ts} +1 -1
  10. package/lib/analyzers/{MethodAnalyzer.js → MigrateMethodAnalyzer.js} +26 -25
  11. package/lib/analyzers/MigrateMethodAnalyzer.js.map +1 -0
  12. package/lib/archivers/{FileArchiver.d.ts → MigrateFileArchiver.d.ts} +1 -1
  13. package/lib/archivers/{FileArchiver.js → MigrateFileArchiver.js} +6 -6
  14. package/lib/archivers/MigrateFileArchiver.js.map +1 -0
  15. package/lib/bundles/SDK_TEMPLATE.js +0 -5
  16. package/lib/bundles/SDK_TEMPLATE.js.map +1 -1
  17. package/lib/executable/bundle.js +1 -0
  18. package/lib/executable/bundle.js.map +1 -1
  19. package/lib/internal/MigrateCommander.js +3 -3
  20. package/lib/internal/MigrateCommander.js.map +1 -1
  21. package/lib/programmers/{ApiFileProgrammer.d.ts → MigrateApiFileProgrammer.d.ts} +1 -1
  22. package/lib/programmers/MigrateApiFileProgrammer.js +28 -0
  23. package/lib/programmers/MigrateApiFileProgrammer.js.map +1 -0
  24. package/lib/programmers/{ApiFunctionProgrammer.d.ts → MigrateApiFunctionProgrammer.d.ts} +4 -4
  25. package/lib/programmers/{ApiFunctionProgrammer.js → MigrateApiFunctionProgrammer.js} +10 -10
  26. package/lib/programmers/MigrateApiFunctionProgrammer.js.map +1 -0
  27. package/lib/programmers/{ApiNamespaceProgrammer.d.ts → MigrateApiNamespaceProgrammer.d.ts} +3 -3
  28. package/lib/programmers/{ApiNamespaceProgrammer.js → MigrateApiNamespaceProgrammer.js} +19 -19
  29. package/lib/programmers/MigrateApiNamespaceProgrammer.js.map +1 -0
  30. package/lib/programmers/{ApiProgrammer.d.ts → MigrateApiProgrammer.d.ts} +1 -1
  31. package/lib/programmers/{ApiProgrammer.js → MigrateApiProgrammer.js} +25 -20
  32. package/lib/programmers/MigrateApiProgrammer.js.map +1 -0
  33. package/lib/programmers/{ApiSimulatationProgrammer.d.ts → MigrateApiSimulatationProgrammer.d.ts} +4 -4
  34. package/lib/programmers/{ApiSimulatationProgrammer.js → MigrateApiSimulatationProgrammer.js} +16 -16
  35. package/lib/programmers/MigrateApiSimulatationProgrammer.js.map +1 -0
  36. package/lib/programmers/{DtoProgrammer.d.ts → MigrateDtoProgrammer.d.ts} +3 -3
  37. package/lib/programmers/{DtoProgrammer.js → MigrateDtoProgrammer.js} +8 -8
  38. package/lib/programmers/MigrateDtoProgrammer.js.map +1 -0
  39. package/lib/programmers/{ImportProgrammer.d.ts → MigrateImportProgrammer.d.ts} +3 -3
  40. package/lib/programmers/{ImportProgrammer.js → MigrateImportProgrammer.js} +7 -5
  41. package/lib/programmers/MigrateImportProgrammer.js.map +1 -0
  42. package/lib/programmers/{NestControllerProgrammer.d.ts → MigrateNestControllerProgrammer.d.ts} +1 -1
  43. package/lib/programmers/{NestControllerProgrammer.js → MigrateNestControllerProgrammer.js} +11 -11
  44. package/lib/programmers/MigrateNestControllerProgrammer.js.map +1 -0
  45. package/lib/programmers/{NestMethodProgrammer.d.ts → MigrateNestMethodProgrammer.d.ts} +3 -3
  46. package/lib/programmers/{NestMethodProgrammer.js → MigrateNestMethodProgrammer.js} +13 -11
  47. package/lib/programmers/MigrateNestMethodProgrammer.js.map +1 -0
  48. package/lib/programmers/{NestModuleProgrammer.d.ts → MigrateNestModuleProgrammer.d.ts} +1 -1
  49. package/lib/programmers/{NestModuleProgrammer.js → MigrateNestModuleProgrammer.js} +8 -8
  50. package/lib/programmers/MigrateNestModuleProgrammer.js.map +1 -0
  51. package/lib/programmers/{NestProgrammer.d.ts → MigrateNestProgrammer.d.ts} +1 -1
  52. package/lib/programmers/{NestProgrammer.js → MigrateNestProgrammer.js} +17 -15
  53. package/lib/programmers/MigrateNestProgrammer.js.map +1 -0
  54. package/lib/programmers/{SchemaProgrammer.d.ts → MigrateSchemaProgrammer.d.ts} +3 -3
  55. package/lib/programmers/{SchemaProgrammer.js → MigrateSchemaProgrammer.js} +23 -23
  56. package/lib/programmers/MigrateSchemaProgrammer.js.map +1 -0
  57. package/lib/structures/IMigrateRoute.d.ts +1 -0
  58. package/lib/utils/FilePrinter.d.ts +1 -1
  59. package/lib/utils/FilePrinter.js +1 -1
  60. package/lib/utils/FilePrinter.js.map +1 -1
  61. package/lib/utils/{JsonTypeChecker.d.ts → SwaggerTypeChecker.d.ts} +1 -1
  62. package/lib/utils/SwaggerTypeChecker.js +34 -0
  63. package/lib/utils/SwaggerTypeChecker.js.map +1 -0
  64. package/package.json +68 -68
  65. package/src/IMigrateConfig.ts +4 -4
  66. package/src/MigrateApplication.ts +48 -35
  67. package/src/analyzers/MigrateAnalyzer.ts +13 -13
  68. package/src/analyzers/{ControllerAnalyzer.ts → MigrateControllerAnalyzer.ts} +122 -123
  69. package/src/analyzers/{MethodAnalyzer.ts → MigrateMethodAnalyzer.ts} +348 -347
  70. package/src/archivers/{FileArchiver.ts → MigrateFileArchiver.ts} +38 -38
  71. package/src/bundles/SDK_TEMPLATE.ts +0 -5
  72. package/src/executable/bundle.ts +109 -108
  73. package/src/executable/migrate.ts +7 -7
  74. package/src/internal/MigrateCommander.ts +51 -52
  75. package/src/internal/MigrateInquirer.ts +79 -79
  76. package/src/module.ts +4 -4
  77. package/src/programmers/{ApiFileProgrammer.ts → MigrateApiFileProgrammer.ts} +53 -53
  78. package/src/programmers/{ApiFunctionProgrammer.ts → MigrateApiFunctionProgrammer.ts} +203 -203
  79. package/src/programmers/{ApiNamespaceProgrammer.ts → MigrateApiNamespaceProgrammer.ts} +430 -418
  80. package/src/programmers/{ApiProgrammer.ts → MigrateApiProgrammer.ts} +132 -128
  81. package/src/programmers/{ApiSimulatationProgrammer.ts → MigrateApiSimulatationProgrammer.ts} +328 -328
  82. package/src/programmers/{DtoProgrammer.ts → MigrateDtoProgrammer.ts} +78 -74
  83. package/src/programmers/{ImportProgrammer.ts → MigrateImportProgrammer.ts} +116 -114
  84. package/src/programmers/{NestControllerProgrammer.ts → MigrateNestControllerProgrammer.ts} +50 -48
  85. package/src/programmers/{NestMethodProgrammer.ts → MigrateNestMethodProgrammer.ts} +249 -243
  86. package/src/programmers/{NestModuleProgrammer.ts → MigrateNestModuleProgrammer.ts} +62 -62
  87. package/src/programmers/{NestProgrammer.ts → MigrateNestProgrammer.ts} +74 -74
  88. package/src/programmers/{SchemaProgrammer.ts → MigrateSchemaProgrammer.ts} +257 -255
  89. package/src/structures/IMigrateProgram.ts +9 -9
  90. package/src/structures/IMigrateRoute.ts +46 -45
  91. package/src/structures/ISwaggeSchema.ts +90 -90
  92. package/src/structures/ISwaggerInfo.ts +80 -80
  93. package/src/utils/FilePrinter.ts +36 -36
  94. package/src/utils/SetupWizard.ts +12 -12
  95. package/src/utils/StringUtil.ts +60 -60
  96. package/src/utils/{JsonTypeChecker.ts → SwaggerTypeChecker.ts} +67 -67
  97. package/lib/analyzers/ControllerAnalyzer.js.map +0 -1
  98. package/lib/analyzers/MethodAnalyzer.js.map +0 -1
  99. package/lib/archivers/FileArchiver.js.map +0 -1
  100. package/lib/programmers/ApiFileProgrammer.js +0 -28
  101. package/lib/programmers/ApiFileProgrammer.js.map +0 -1
  102. package/lib/programmers/ApiFunctionProgrammer.js.map +0 -1
  103. package/lib/programmers/ApiNamespaceProgrammer.js.map +0 -1
  104. package/lib/programmers/ApiProgrammer.js.map +0 -1
  105. package/lib/programmers/ApiSimulatationProgrammer.js.map +0 -1
  106. package/lib/programmers/DtoProgrammer.js.map +0 -1
  107. package/lib/programmers/ImportProgrammer.js.map +0 -1
  108. package/lib/programmers/NestControllerProgrammer.js.map +0 -1
  109. package/lib/programmers/NestMethodProgrammer.js.map +0 -1
  110. package/lib/programmers/NestModuleProgrammer.js.map +0 -1
  111. package/lib/programmers/NestProgrammer.js.map +0 -1
  112. package/lib/programmers/SchemaProgrammer.js.map +0 -1
  113. package/lib/utils/JsonTypeChecker.js +0 -34
  114. package/lib/utils/JsonTypeChecker.js.map +0 -1
@@ -1,243 +1,249 @@
1
- import ts from "typescript";
2
- import { ExpressionFactory } from "typia/lib/factories/ExpressionFactory";
3
- import { IdentifierFactory } from "typia/lib/factories/IdentifierFactory";
4
- import { TypeFactory } from "typia/lib/factories/TypeFactory";
5
-
6
- import { IMigrateRoute } from "../structures/IMigrateRoute";
7
- import { ISwaggerSchema } from "../structures/ISwaggeSchema";
8
- import { ISwaggerComponents } from "../structures/ISwaggerComponents";
9
- import { FilePrinter } from "../utils/FilePrinter";
10
- import { StringUtil } from "../utils/StringUtil";
11
- import { ImportProgrammer } from "./ImportProgrammer";
12
- import { SchemaProgrammer } from "./SchemaProgrammer";
13
-
14
- export namespace NestMethodProgrammer {
15
- export const write =
16
- (components: ISwaggerComponents) =>
17
- (importer: ImportProgrammer) =>
18
- (route: IMigrateRoute): ts.MethodDeclaration => {
19
- const output: ts.TypeNode = route.success
20
- ? SchemaProgrammer.write(components)(importer)(route.success.schema)
21
- : TypeFactory.keyword("void");
22
-
23
- const method: ts.MethodDeclaration = ts.factory.createMethodDeclaration(
24
- [
25
- ...writeMethodDecorators(components)(importer)(route),
26
- ts.factory.createToken(ts.SyntaxKind.PublicKeyword),
27
- ts.factory.createToken(ts.SyntaxKind.AsyncKeyword),
28
- ],
29
- undefined,
30
- route.name,
31
- undefined,
32
- undefined,
33
- writeParameters(components)(importer)(route),
34
- ts.factory.createTypeReferenceNode("Promise", [output]),
35
- ts.factory.createBlock(
36
- [
37
- ...[
38
- ...route.parameters.map((p) => StringUtil.normalize(p.key)),
39
- ...(route.headers ? ["headers"] : []),
40
- ...(route.query ? ["query"] : []),
41
- ...(route.body ? ["body"] : []),
42
- ].map((str) =>
43
- ts.factory.createExpressionStatement(
44
- ts.factory.createIdentifier(str),
45
- ),
46
- ),
47
- ts.factory.createReturnStatement(
48
- ts.factory.createCallExpression(
49
- IdentifierFactory.access(
50
- ts.factory.createIdentifier(
51
- importer.external({
52
- type: "default",
53
- library: "typia",
54
- name: "typia",
55
- }),
56
- ),
57
- )("random"),
58
- [output],
59
- undefined,
60
- ),
61
- ),
62
- ],
63
- true,
64
- ),
65
- );
66
- return FilePrinter.description(method, writeDescription(route));
67
- };
68
-
69
- const writeDescription = (method: IMigrateRoute): string =>
70
- [
71
- ...(method.description?.length ? [method.description.length, ""] : []),
72
- ...(method.deprecated ? ["@deprecated"] : []),
73
- ...method.tags.map((value) => `@tag ${value}`),
74
- "@nestia Generated by Nestia - https://github.com/samchon/nestia",
75
- ].join("\n");
76
-
77
- const writeMethodDecorators =
78
- (components: ISwaggerComponents) =>
79
- (importer: ImportProgrammer) =>
80
- (route: IMigrateRoute): ts.Decorator[] => {
81
- const external =
82
- (lib: string) =>
83
- (instance: string): ts.Identifier =>
84
- ts.factory.createIdentifier(
85
- importer.external({
86
- type: "instance",
87
- library: lib,
88
- name: instance,
89
- }),
90
- );
91
- const router = (instance: string) =>
92
- ts.factory.createDecorator(
93
- ts.factory.createCallExpression(
94
- IdentifierFactory.access(external("@nestia/core")(instance))(
95
- StringUtil.capitalize(route.method),
96
- ),
97
- [],
98
- [ts.factory.createStringLiteral(route.path)],
99
- ),
100
- );
101
-
102
- const decorators: ts.Decorator[] = [];
103
- if (route.success?.["x-nestia-encrypted"])
104
- decorators.push(router("EncryptedRoute"));
105
- else if (route.success?.type === "text/plain")
106
- decorators.push(
107
- ts.factory.createDecorator(
108
- ts.factory.createCallExpression(
109
- external("@nestjs/common")(StringUtil.capitalize(route.method)),
110
- [],
111
- [ts.factory.createStringLiteral(route.path)],
112
- ),
113
- ),
114
- );
115
- else if (route.success?.type === "application/x-www-form-urlencoded")
116
- decorators.push(router("TypedQuery"));
117
- else if (route.success?.type === "application/json")
118
- decorators.push(router("TypedRoute"));
119
- else if (route.method === "head")
120
- decorators.push(
121
- ts.factory.createDecorator(
122
- ts.factory.createCallExpression(
123
- external("@nestjs/common")("Head"),
124
- [],
125
- [ts.factory.createStringLiteral(route.path)],
126
- ),
127
- ),
128
- );
129
- for (const [key, value] of Object.entries(route.exceptions ?? {}))
130
- decorators.push(
131
- ts.factory.createDecorator(
132
- ts.factory.createCallExpression(
133
- external("@nestia/core")("TypedException"),
134
- [SchemaProgrammer.write(components)(importer)(value.schema)],
135
- [
136
- isNaN(Number(key))
137
- ? ts.factory.createStringLiteral(key)
138
- : ExpressionFactory.number(Number(key)),
139
- ...(value.description?.length
140
- ? [ts.factory.createStringLiteral(value.description)]
141
- : []),
142
- ],
143
- ),
144
- ),
145
- );
146
- return decorators;
147
- };
148
-
149
- const writeParameters =
150
- (components: ISwaggerComponents) =>
151
- (importer: ImportProgrammer) =>
152
- (route: IMigrateRoute): ts.ParameterDeclaration[] => [
153
- ...route.parameters.map(({ key, schema: value }) =>
154
- ts.factory.createParameterDeclaration(
155
- [
156
- ts.factory.createDecorator(
157
- ts.factory.createCallExpression(
158
- ts.factory.createIdentifier(
159
- importer.external({
160
- type: "instance",
161
- library: "@nestia/core",
162
- name: "TypedParam",
163
- }),
164
- ),
165
- undefined,
166
- [ts.factory.createStringLiteral(key)],
167
- ),
168
- ),
169
- ],
170
- undefined,
171
- StringUtil.normalize(key),
172
- undefined,
173
- SchemaProgrammer.write(components)(importer)(value),
174
- ),
175
- ),
176
- ...(route.headers
177
- ? [
178
- writeDtoParameter({ method: "TypedHeaders", variable: "headers" })(
179
- components,
180
- )(importer)(route.headers.schema),
181
- ]
182
- : []),
183
- ...(route.query
184
- ? [
185
- writeDtoParameter({ method: "TypedQuery", variable: "query" })(
186
- components,
187
- )(importer)(route.query.schema),
188
- ]
189
- : []),
190
- ...(route.body
191
- ? [
192
- writeDtoParameter({
193
- method: route.body["x-nestia-encrypted"]
194
- ? "EncryptedBody"
195
- : route.body.type === "application/json"
196
- ? "TypedBody"
197
- : route.body.type === "application/x-www-form-urlencoded"
198
- ? ["TypedQuery", "Body"]
199
- : route.body.type === "text/plain"
200
- ? "PlainBody"
201
- : route.body.type === "multipart/form-data"
202
- ? ["TypedFormData", "Body"]
203
- : "TypedBody",
204
- variable: "body",
205
- })(components)(importer)(route.body.schema),
206
- ]
207
- : []),
208
- ];
209
-
210
- const writeDtoParameter =
211
- (accessor: { method: string | [string, string]; variable: string }) =>
212
- (components: ISwaggerComponents) =>
213
- (importer: ImportProgrammer) =>
214
- (schema: ISwaggerSchema): ts.ParameterDeclaration => {
215
- const instance = ts.factory.createIdentifier(
216
- importer.external({
217
- type: "instance",
218
- library: "@nestia/core",
219
- name:
220
- typeof accessor.method === "string"
221
- ? accessor.method
222
- : accessor.method[0],
223
- }),
224
- );
225
- return ts.factory.createParameterDeclaration(
226
- [
227
- ts.factory.createDecorator(
228
- ts.factory.createCallExpression(
229
- typeof accessor.method === "string"
230
- ? instance
231
- : IdentifierFactory.access(instance)(accessor.method[1]),
232
- undefined,
233
- undefined,
234
- ),
235
- ),
236
- ],
237
- undefined,
238
- StringUtil.normalize(accessor.variable),
239
- undefined,
240
- SchemaProgrammer.write(components)(importer)(schema),
241
- );
242
- };
243
- }
1
+ import ts from "typescript";
2
+ import { ExpressionFactory } from "typia/lib/factories/ExpressionFactory";
3
+ import { IdentifierFactory } from "typia/lib/factories/IdentifierFactory";
4
+ import { TypeFactory } from "typia/lib/factories/TypeFactory";
5
+
6
+ import { IMigrateRoute } from "../structures/IMigrateRoute";
7
+ import { ISwaggerSchema } from "../structures/ISwaggeSchema";
8
+ import { ISwaggerComponents } from "../structures/ISwaggerComponents";
9
+ import { FilePrinter } from "../utils/FilePrinter";
10
+ import { StringUtil } from "../utils/StringUtil";
11
+ import { MigrateImportProgrammer } from "./MigrateImportProgrammer";
12
+ import { MigrateSchemaProgrammer } from "./MigrateSchemaProgrammer";
13
+
14
+ export namespace MigrateNestMethodProgrammer {
15
+ export const write =
16
+ (components: ISwaggerComponents) =>
17
+ (importer: MigrateImportProgrammer) =>
18
+ (route: IMigrateRoute): ts.MethodDeclaration => {
19
+ const output: ts.TypeNode = route.success
20
+ ? MigrateSchemaProgrammer.write(components)(importer)(
21
+ route.success.schema,
22
+ )
23
+ : TypeFactory.keyword("void");
24
+
25
+ const method: ts.MethodDeclaration = ts.factory.createMethodDeclaration(
26
+ [
27
+ ...writeMethodDecorators(components)(importer)(route),
28
+ ts.factory.createToken(ts.SyntaxKind.PublicKeyword),
29
+ ts.factory.createToken(ts.SyntaxKind.AsyncKeyword),
30
+ ],
31
+ undefined,
32
+ route.name,
33
+ undefined,
34
+ undefined,
35
+ writeParameters(components)(importer)(route),
36
+ ts.factory.createTypeReferenceNode("Promise", [output]),
37
+ ts.factory.createBlock(
38
+ [
39
+ ...[
40
+ ...route.parameters.map((p) => StringUtil.normalize(p.key)),
41
+ ...(route.headers ? ["headers"] : []),
42
+ ...(route.query ? ["query"] : []),
43
+ ...(route.body ? ["body"] : []),
44
+ ].map((str) =>
45
+ ts.factory.createExpressionStatement(
46
+ ts.factory.createIdentifier(str),
47
+ ),
48
+ ),
49
+ ts.factory.createReturnStatement(
50
+ ts.factory.createCallExpression(
51
+ IdentifierFactory.access(
52
+ ts.factory.createIdentifier(
53
+ importer.external({
54
+ type: "default",
55
+ library: "typia",
56
+ name: "typia",
57
+ }),
58
+ ),
59
+ )("random"),
60
+ [output],
61
+ undefined,
62
+ ),
63
+ ),
64
+ ],
65
+ true,
66
+ ),
67
+ );
68
+ return FilePrinter.description(method, writeDescription(route));
69
+ };
70
+
71
+ const writeDescription = (method: IMigrateRoute): string =>
72
+ [
73
+ ...(method.description?.length ? [method.description.length, ""] : []),
74
+ ...(method.deprecated ? ["@deprecated"] : []),
75
+ ...method.tags.map((value) => `@tag ${value}`),
76
+ "@nestia Generated by Nestia - https://github.com/samchon/nestia",
77
+ ].join("\n");
78
+
79
+ const writeMethodDecorators =
80
+ (components: ISwaggerComponents) =>
81
+ (importer: MigrateImportProgrammer) =>
82
+ (route: IMigrateRoute): ts.Decorator[] => {
83
+ const external =
84
+ (lib: string) =>
85
+ (instance: string): ts.Identifier =>
86
+ ts.factory.createIdentifier(
87
+ importer.external({
88
+ type: "instance",
89
+ library: lib,
90
+ name: instance,
91
+ }),
92
+ );
93
+ const router = (instance: string) =>
94
+ ts.factory.createDecorator(
95
+ ts.factory.createCallExpression(
96
+ IdentifierFactory.access(external("@nestia/core")(instance))(
97
+ StringUtil.capitalize(route.method),
98
+ ),
99
+ [],
100
+ [ts.factory.createStringLiteral(route.path)],
101
+ ),
102
+ );
103
+
104
+ const decorators: ts.Decorator[] = [];
105
+ if (route.success?.["x-nestia-encrypted"])
106
+ decorators.push(router("EncryptedRoute"));
107
+ else if (route.success?.type === "text/plain")
108
+ decorators.push(
109
+ ts.factory.createDecorator(
110
+ ts.factory.createCallExpression(
111
+ external("@nestjs/common")(StringUtil.capitalize(route.method)),
112
+ [],
113
+ [ts.factory.createStringLiteral(route.path)],
114
+ ),
115
+ ),
116
+ );
117
+ else if (route.success?.type === "application/x-www-form-urlencoded")
118
+ decorators.push(router("TypedQuery"));
119
+ else if (route.success?.type === "application/json")
120
+ decorators.push(router("TypedRoute"));
121
+ else if (route.method === "head")
122
+ decorators.push(
123
+ ts.factory.createDecorator(
124
+ ts.factory.createCallExpression(
125
+ external("@nestjs/common")("Head"),
126
+ [],
127
+ [ts.factory.createStringLiteral(route.path)],
128
+ ),
129
+ ),
130
+ );
131
+ for (const [key, value] of Object.entries(route.exceptions ?? {}))
132
+ decorators.push(
133
+ ts.factory.createDecorator(
134
+ ts.factory.createCallExpression(
135
+ external("@nestia/core")("TypedException"),
136
+ [
137
+ MigrateSchemaProgrammer.write(components)(importer)(
138
+ value.schema,
139
+ ),
140
+ ],
141
+ [
142
+ isNaN(Number(key))
143
+ ? ts.factory.createStringLiteral(key)
144
+ : ExpressionFactory.number(Number(key)),
145
+ ...(value.description?.length
146
+ ? [ts.factory.createStringLiteral(value.description)]
147
+ : []),
148
+ ],
149
+ ),
150
+ ),
151
+ );
152
+ return decorators;
153
+ };
154
+
155
+ const writeParameters =
156
+ (components: ISwaggerComponents) =>
157
+ (importer: MigrateImportProgrammer) =>
158
+ (route: IMigrateRoute): ts.ParameterDeclaration[] => [
159
+ ...route.parameters.map(({ key, schema: value }) =>
160
+ ts.factory.createParameterDeclaration(
161
+ [
162
+ ts.factory.createDecorator(
163
+ ts.factory.createCallExpression(
164
+ ts.factory.createIdentifier(
165
+ importer.external({
166
+ type: "instance",
167
+ library: "@nestia/core",
168
+ name: "TypedParam",
169
+ }),
170
+ ),
171
+ undefined,
172
+ [ts.factory.createStringLiteral(key)],
173
+ ),
174
+ ),
175
+ ],
176
+ undefined,
177
+ StringUtil.normalize(key),
178
+ undefined,
179
+ MigrateSchemaProgrammer.write(components)(importer)(value),
180
+ ),
181
+ ),
182
+ ...(route.headers
183
+ ? [
184
+ writeDtoParameter({ method: "TypedHeaders", variable: "headers" })(
185
+ components,
186
+ )(importer)(route.headers.schema),
187
+ ]
188
+ : []),
189
+ ...(route.query
190
+ ? [
191
+ writeDtoParameter({ method: "TypedQuery", variable: "query" })(
192
+ components,
193
+ )(importer)(route.query.schema),
194
+ ]
195
+ : []),
196
+ ...(route.body
197
+ ? [
198
+ writeDtoParameter({
199
+ method: route.body["x-nestia-encrypted"]
200
+ ? "EncryptedBody"
201
+ : route.body.type === "application/json"
202
+ ? "TypedBody"
203
+ : route.body.type === "application/x-www-form-urlencoded"
204
+ ? ["TypedQuery", "Body"]
205
+ : route.body.type === "text/plain"
206
+ ? "PlainBody"
207
+ : route.body.type === "multipart/form-data"
208
+ ? ["TypedFormData", "Body"]
209
+ : "TypedBody",
210
+ variable: "body",
211
+ })(components)(importer)(route.body.schema),
212
+ ]
213
+ : []),
214
+ ];
215
+
216
+ const writeDtoParameter =
217
+ (accessor: { method: string | [string, string]; variable: string }) =>
218
+ (components: ISwaggerComponents) =>
219
+ (importer: MigrateImportProgrammer) =>
220
+ (schema: ISwaggerSchema): ts.ParameterDeclaration => {
221
+ const instance = ts.factory.createIdentifier(
222
+ importer.external({
223
+ type: "instance",
224
+ library: "@nestia/core",
225
+ name:
226
+ typeof accessor.method === "string"
227
+ ? accessor.method
228
+ : accessor.method[0],
229
+ }),
230
+ );
231
+ return ts.factory.createParameterDeclaration(
232
+ [
233
+ ts.factory.createDecorator(
234
+ ts.factory.createCallExpression(
235
+ typeof accessor.method === "string"
236
+ ? instance
237
+ : IdentifierFactory.access(instance)(accessor.method[1]),
238
+ undefined,
239
+ undefined,
240
+ ),
241
+ ),
242
+ ],
243
+ undefined,
244
+ StringUtil.normalize(accessor.variable),
245
+ undefined,
246
+ MigrateSchemaProgrammer.write(components)(importer)(schema),
247
+ );
248
+ };
249
+ }
@@ -1,62 +1,62 @@
1
- import ts from "typescript";
2
-
3
- import { IMigrateController } from "../structures/IMigrateController";
4
- import { FilePrinter } from "../utils/FilePrinter";
5
-
6
- export namespace NestModuleProgrammer {
7
- export const write = (controllers: IMigrateController[]): ts.Statement[] => [
8
- $import("@nestjs/common")("Module"),
9
- ...(controllers.length ? [FilePrinter.enter()] : []),
10
- ...controllers.map((c) =>
11
- $import(`${c.location.replace("src/", "./")}/${c.name}`)(c.name),
12
- ),
13
- ...(controllers.length ? [FilePrinter.enter()] : []),
14
- ts.factory.createClassDeclaration(
15
- [
16
- ts.factory.createDecorator(
17
- ts.factory.createCallExpression(
18
- ts.factory.createIdentifier("Module"),
19
- undefined,
20
- [
21
- ts.factory.createObjectLiteralExpression(
22
- [
23
- ts.factory.createPropertyAssignment(
24
- ts.factory.createIdentifier("controllers"),
25
- ts.factory.createArrayLiteralExpression(
26
- controllers.map((c) =>
27
- ts.factory.createIdentifier(c.name),
28
- ),
29
- ),
30
- ),
31
- ],
32
- true,
33
- ),
34
- ],
35
- ),
36
- ),
37
- ts.factory.createToken(ts.SyntaxKind.ExportKeyword),
38
- ],
39
- "MyModule",
40
- undefined,
41
- undefined,
42
- [],
43
- ),
44
- ];
45
- }
46
-
47
- const $import = (file: string) => (instance: string) =>
48
- ts.factory.createImportDeclaration(
49
- undefined,
50
- ts.factory.createImportClause(
51
- false,
52
- undefined,
53
- ts.factory.createNamedImports([
54
- ts.factory.createImportSpecifier(
55
- false,
56
- undefined,
57
- ts.factory.createIdentifier(instance),
58
- ),
59
- ]),
60
- ),
61
- ts.factory.createStringLiteral(file),
62
- );
1
+ import ts from "typescript";
2
+
3
+ import { IMigrateController } from "../structures/IMigrateController";
4
+ import { FilePrinter } from "../utils/FilePrinter";
5
+
6
+ export namespace MigrateNestModuleProgrammer {
7
+ export const write = (controllers: IMigrateController[]): ts.Statement[] => [
8
+ $import("@nestjs/common")("Module"),
9
+ ...(controllers.length ? [FilePrinter.newLine()] : []),
10
+ ...controllers.map((c) =>
11
+ $import(`${c.location.replace("src/", "./")}/${c.name}`)(c.name),
12
+ ),
13
+ ...(controllers.length ? [FilePrinter.newLine()] : []),
14
+ ts.factory.createClassDeclaration(
15
+ [
16
+ ts.factory.createDecorator(
17
+ ts.factory.createCallExpression(
18
+ ts.factory.createIdentifier("Module"),
19
+ undefined,
20
+ [
21
+ ts.factory.createObjectLiteralExpression(
22
+ [
23
+ ts.factory.createPropertyAssignment(
24
+ ts.factory.createIdentifier("controllers"),
25
+ ts.factory.createArrayLiteralExpression(
26
+ controllers.map((c) =>
27
+ ts.factory.createIdentifier(c.name),
28
+ ),
29
+ ),
30
+ ),
31
+ ],
32
+ true,
33
+ ),
34
+ ],
35
+ ),
36
+ ),
37
+ ts.factory.createToken(ts.SyntaxKind.ExportKeyword),
38
+ ],
39
+ "MyModule",
40
+ undefined,
41
+ undefined,
42
+ [],
43
+ ),
44
+ ];
45
+ }
46
+
47
+ const $import = (file: string) => (instance: string) =>
48
+ ts.factory.createImportDeclaration(
49
+ undefined,
50
+ ts.factory.createImportClause(
51
+ false,
52
+ undefined,
53
+ ts.factory.createNamedImports([
54
+ ts.factory.createImportSpecifier(
55
+ false,
56
+ undefined,
57
+ ts.factory.createIdentifier(instance),
58
+ ),
59
+ ]),
60
+ ),
61
+ ts.factory.createStringLiteral(file),
62
+ );