@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.
Files changed (69) hide show
  1. package/lib/MigrateApplication.d.ts +1 -0
  2. package/lib/MigrateApplication.js +843 -893
  3. package/lib/MigrateApplication.js.map +1 -1
  4. package/lib/analyzers/MigrateAnalyzer.js +5 -2
  5. package/lib/analyzers/MigrateAnalyzer.js.map +1 -1
  6. package/lib/analyzers/MigrateControllerAnalyzer.d.ts +2 -2
  7. package/lib/analyzers/MigrateControllerAnalyzer.js +14 -88
  8. package/lib/analyzers/MigrateControllerAnalyzer.js.map +1 -1
  9. package/lib/bundles/NEST_TEMPLATE.js +21 -6
  10. package/lib/bundles/NEST_TEMPLATE.js.map +1 -1
  11. package/lib/bundles/SDK_TEMPLATE.js +1 -1
  12. package/lib/bundles/SDK_TEMPLATE.js.map +1 -1
  13. package/lib/executable/bundle.js +1 -1
  14. package/lib/internal/MigrateCommander.js +5 -2
  15. package/lib/internal/MigrateCommander.js.map +1 -1
  16. package/lib/programmers/MigrateApiFileProgrammer.d.ts +2 -9
  17. package/lib/programmers/MigrateApiFileProgrammer.js +4 -4
  18. package/lib/programmers/MigrateApiFileProgrammer.js.map +1 -1
  19. package/lib/programmers/MigrateApiFunctionProgrammer.d.ts +2 -8
  20. package/lib/programmers/MigrateApiFunctionProgrammer.js +33 -30
  21. package/lib/programmers/MigrateApiFunctionProgrammer.js.map +1 -1
  22. package/lib/programmers/MigrateApiNamespaceProgrammer.d.ts +2 -8
  23. package/lib/programmers/MigrateApiNamespaceProgrammer.js +31 -37
  24. package/lib/programmers/MigrateApiNamespaceProgrammer.js.map +1 -1
  25. package/lib/programmers/MigrateApiProgrammer.js +19 -70
  26. package/lib/programmers/MigrateApiProgrammer.js.map +1 -1
  27. package/lib/programmers/MigrateApiSimulatationProgrammer.d.ts +2 -8
  28. package/lib/programmers/MigrateApiSimulatationProgrammer.js +16 -16
  29. package/lib/programmers/MigrateApiSimulatationProgrammer.js.map +1 -1
  30. package/lib/programmers/MigrateApiStartProgrammer.js +1 -1
  31. package/lib/programmers/MigrateApiStartProgrammer.js.map +1 -1
  32. package/lib/programmers/MigrateE2eProgrammer.js +1 -3
  33. package/lib/programmers/MigrateE2eProgrammer.js.map +1 -1
  34. package/lib/programmers/MigrateNestMethodProgrammer.js +4 -4
  35. package/lib/programmers/MigrateNestMethodProgrammer.js.map +1 -1
  36. package/lib/programmers/MigrateNestProgrammer.js +27 -23
  37. package/lib/programmers/MigrateNestProgrammer.js.map +1 -1
  38. package/lib/programmers/MigrateSchemaProgrammer.js +22 -22
  39. package/lib/structures/IMigrateProgram.d.ts +8 -8
  40. package/lib/structures/IMigrateRoute.d.ts +1 -46
  41. package/lib/utils/OpenApiTypeChecker.d.ts +1 -1
  42. package/lib/utils/StringUtil.d.ts +0 -4
  43. package/lib/utils/StringUtil.js +0 -31
  44. package/lib/utils/StringUtil.js.map +1 -1
  45. package/lib/utils/openapi-down-convert/RefVisitor.js +4 -5
  46. package/lib/utils/openapi-down-convert/RefVisitor.js.map +1 -1
  47. package/package.json +11 -8
  48. package/src/MigrateApplication.ts +3 -2
  49. package/src/analyzers/MigrateAnalyzer.ts +10 -5
  50. package/src/analyzers/MigrateControllerAnalyzer.ts +17 -122
  51. package/src/bundles/NEST_TEMPLATE.ts +21 -6
  52. package/src/bundles/SDK_TEMPLATE.ts +1 -1
  53. package/src/internal/MigrateCommander.ts +8 -2
  54. package/src/programmers/MigrateApiFileProgrammer.ts +10 -14
  55. package/src/programmers/MigrateApiFunctionProgrammer.ts +43 -41
  56. package/src/programmers/MigrateApiNamespaceProgrammer.ts +33 -51
  57. package/src/programmers/MigrateApiProgrammer.ts +26 -95
  58. package/src/programmers/MigrateApiSimulatationProgrammer.ts +17 -25
  59. package/src/programmers/MigrateApiStartProgrammer.ts +1 -1
  60. package/src/programmers/MigrateE2eProgrammer.ts +1 -3
  61. package/src/programmers/MigrateNestMethodProgrammer.ts +4 -4
  62. package/src/programmers/MigrateNestProgrammer.ts +10 -4
  63. package/src/structures/IMigrateProgram.ts +8 -8
  64. package/src/structures/IMigrateRoute.ts +1 -51
  65. package/src/utils/StringUtil.ts +0 -42
  66. package/lib/analyzers/MigrateMethodAnalyzer.d.ts +0 -9
  67. package/lib/analyzers/MigrateMethodAnalyzer.js +0 -304
  68. package/lib/analyzers/MigrateMethodAnalyzer.js.map +0 -1
  69. 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
- (props: IProps): ts.FunctionDeclaration =>
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
- props.alias,
24
+ route.accessor.at(-1)!,
32
25
  undefined,
33
- writeParameterDeclarations(components)(importer)(props),
26
+ writeParameterDeclarations(components)(importer)(route),
34
27
  ts.factory.createTypeReferenceNode("Promise", [
35
28
  ts.factory.createTypeReferenceNode(
36
- props.route.success === null ? "void" : `${props.alias}.Output`,
29
+ route.success === null
30
+ ? "void"
31
+ : `${route.accessor.at(-1)!}.Output`,
37
32
  ),
38
33
  ]),
39
- ts.factory.createBlock(writeBody(config)(importer)(props), true),
34
+ ts.factory.createBlock(writeBody(config)(importer)(route), true),
40
35
  ),
41
- writeDescription(props),
36
+ writeDescription(route),
42
37
  );
43
38
 
44
39
  export const writeParameterDeclarations =
45
40
  (components: OpenApi.IComponents) =>
46
41
  (importer: MigrateImportProgrammer) =>
47
- (props: IProps): ts.ParameterDeclaration[] => [
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
- props.route.headers
57
- ? [ts.factory.createTypeReferenceNode(`${props.alias}.Headers`)]
51
+ route.headers
52
+ ? [
53
+ ts.factory.createTypeReferenceNode(
54
+ `${route.accessor.at(-1)!}.Headers`,
55
+ ),
56
+ ]
58
57
  : undefined,
59
58
  ),
60
59
  ),
61
- ...props.route.parameters.map((p) =>
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
- ...(props.route.query
66
+ ...(route.query
68
67
  ? [
69
68
  IdentifierFactory.parameter(
70
- props.route.query.key,
71
- ts.factory.createTypeReferenceNode(`${props.alias}.Query`),
69
+ route.query.key,
70
+ ts.factory.createTypeReferenceNode(
71
+ `${route.accessor.at(-1)!}.Query`,
72
+ ),
72
73
  ),
73
74
  ]
74
75
  : []),
75
- ...(props.route.body
76
+ ...(route.body
76
77
  ? [
77
78
  IdentifierFactory.parameter(
78
- props.route.body.key,
79
- ts.factory.createTypeReferenceNode(`${props.alias}.Input`),
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 = (props: IProps): string =>
88
+ const writeDescription = (route: IMigrateRoute): string =>
86
89
  [
87
- props.route.comment(),
88
- `@controller ${props.controller.name}`,
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
- (props: IProps): ts.Statement[] => {
97
- const encrypted: boolean = !!props.route.success?.["x-nestia-encrypted"];
98
- const contentType: string = props.route.body?.type ?? "application/json";
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(props.alias),
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(props.alias),
153
+ ts.factory.createIdentifier(route.accessor.at(-1)!),
152
154
  )("path"),
153
155
  undefined,
154
156
  [
155
- ...props.route.parameters.map((p) =>
157
+ ...route.parameters.map((p) =>
156
158
  ts.factory.createIdentifier(p.key),
157
159
  ),
158
- ...(props.route.query
159
- ? [ts.factory.createIdentifier(props.route.query.key)]
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
- ...(props.route.body
172
- ? [ts.factory.createIdentifier(props.route.body.key)]
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(`${props.alias}.simulate`),
186
+ ts.factory.createIdentifier(`${route.accessor.at(-1)!}.simulate`),
185
187
  [],
186
188
  [
187
189
  "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] : []),
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
- (props: IProps): ts.ModuleDeclaration => {
28
- const types = writeTypes(components)(importer)(props.route);
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(props.alias),
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)(props),
28
+ writeMetadata(components)(importer)(route),
36
29
  FilePrinter.newLine(),
37
- writePath(components)(importer)(props),
30
+ writePath(components)(importer)(route),
38
31
  ...(config.simulate
39
32
  ? [
40
33
  MigrateApiSimulatationProgrammer.random(components)(importer)(
41
- props,
34
+ route,
42
35
  ),
43
36
  MigrateApiSimulatationProgrammer.simulate(components)(importer)(
44
- props,
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 = (props: IProps) =>
46
+ export const writePathCallExpression = (route: IMigrateRoute) =>
54
47
  ts.factory.createCallExpression(
55
- ts.factory.createIdentifier(`${props.alias}.path`),
48
+ ts.factory.createIdentifier(`${route.accessor.at(-1)!}.path`),
56
49
  undefined,
57
50
  [
58
- ...props.route.parameters.map((p) =>
59
- ts.factory.createIdentifier(p.key),
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
- (props: IProps): ts.VariableStatement =>
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(props)),
115
+ ts.factory.createStringLiteral(getPath(route)),
129
116
  ),
130
117
  ts.factory.createPropertyAssignment(
131
118
  "request",
132
- props.route.body
119
+ route.body
133
120
  ? LiteralFactory.generate({
134
- type: props.route.body.type,
135
- encrypted: !!props.route.body["x-nestia-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
- props.route.method.toUpperCase() !== "HEAD"
128
+ route.method.toUpperCase() !== "HEAD"
142
129
  ? LiteralFactory.generate({
143
- type: props.route.success?.type ?? "application/json",
144
- encrypted: !!props.route.success?.["x-nestia-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
- ...(props.route.success?.type ===
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
- props.route.success.schema,
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
- (props: IProps): ts.VariableStatement => {
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
- ...props.route.parameters.map((p) =>
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
- ...(props.route.query
182
+ ...(route.query
197
183
  ? [
198
184
  IdentifierFactory.parameter(
199
- props.route.query.key,
185
+ route.query.key,
200
186
  ts.factory.createTypeReferenceNode(
201
- `${props.alias}.Query`,
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(props);
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
- props.route.parameters.find((p) => p.name === name)!.key,
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 (!props.route.query) return out(template());
227
+ if (!route.query) return out(template());
242
228
 
243
229
  const computeName = (str: string): string =>
244
- props.route.parameters.find((p) => p.key === str) !== undefined
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(props.route.query.key),
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 = (props: MigrateApiNamespaceProgrammer.IProps) =>
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, IPointer, hash } from "tstl";
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
- // GROUP BY NAMESPACES
18
- const dict: HashMap<string[], MigrateApiFileProgrammer.IProps> = collect(
19
- ({ controller, route }) =>
20
- [...controller.path.split("/"), ...route.path.split("/")]
21
- .filter((str) => !!str.length && str[0] !== ":")
22
- .map(StringUtil.normalize)
23
- .map((str) => (Escaper.variable(str) ? str : `_${str}`)),
24
- )(program);
25
-
26
- // EMEND NAMES
27
- for (const { second: props } of dict)
28
- props.entries.forEach((entry, i) => {
29
- entry.alias = StringUtil.escapeDuplicate([
30
- ...props.children,
31
- ...props.entries.filter((_, j) => i !== j).map((e) => e.alias),
32
- ])(entry.alias);
33
- entry.route.accessor = [...props.namespace, entry.alias];
34
-
35
- const parameters: { name: string; key: string }[] = [
36
- ...entry.route.parameters,
37
- ...(entry.route.body ? [entry.route.body] : []),
38
- ...(entry.route.headers ? [entry.route.headers] : []),
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
- (props: IProps) => {
24
- const output = props.route.success
17
+ (route: IMigrateRoute) => {
18
+ const output = route.success
25
19
  ? MigrateSchemaProgrammer.write(components)(importer)(
26
- props.route.success.schema,
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
- (props: IProps): ts.VariableStatement => {
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
- )(props),
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)(props),
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
- (props: IProps): ts.Statement[] => {
118
+ (route: IMigrateRoute): ts.Statement[] => {
127
119
  const parameters = [
128
- ...props.route.parameters.map((p) => ({
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
- ...(props.route.query
125
+ ...(route.query
134
126
  ? [
135
127
  {
136
128
  category: "query",
137
- name: props.route.query.key,
129
+ name: route.query.key,
138
130
  schema: MigrateSchemaProgrammer.write(components)(importer)(
139
- props.route.query.schema,
131
+ route.query.schema,
140
132
  ),
141
133
  },
142
134
  ]
143
135
  : []),
144
- ...(props.route.body
136
+ ...(route.body
145
137
  ? [
146
138
  {
147
139
  category: "body",
148
- name: props.route.body.key,
140
+ name: route.body.key,
149
141
  schema: MigrateSchemaProgrammer.write(components)(importer)(
150
- props.route.body.schema,
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(props),
176
+ MigrateApiNamespaceProgrammer.writePathCallExpression(route),
185
177
  ),
186
178
  ts.factory.createPropertyAssignment(
187
179
  "contentType",
188
180
  ts.factory.createStringLiteral(
189
- props.route.success?.type ?? "application/json",
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.controllers.map((c) => c.routes).flat()));
18
+ )(pick(program.routes));
19
19
  const statements: ts.Statement[] = [
20
20
  ...importer.toStatements(
21
21
  (name) => `@ORGANIZATION/PROJECT-api/lib/structures/${name}`,