@nestia/migrate 0.13.17 → 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 (67) hide show
  1. package/lib/MigrateApplication.d.ts +1 -0
  2. package/lib/MigrateApplication.js +823 -873
  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 +3 -3
  10. package/lib/bundles/SDK_TEMPLATE.js +1 -1
  11. package/lib/executable/bundle.js +1 -1
  12. package/lib/internal/MigrateCommander.js +5 -2
  13. package/lib/internal/MigrateCommander.js.map +1 -1
  14. package/lib/programmers/MigrateApiFileProgrammer.d.ts +2 -9
  15. package/lib/programmers/MigrateApiFileProgrammer.js +4 -4
  16. package/lib/programmers/MigrateApiFileProgrammer.js.map +1 -1
  17. package/lib/programmers/MigrateApiFunctionProgrammer.d.ts +2 -8
  18. package/lib/programmers/MigrateApiFunctionProgrammer.js +33 -30
  19. package/lib/programmers/MigrateApiFunctionProgrammer.js.map +1 -1
  20. package/lib/programmers/MigrateApiNamespaceProgrammer.d.ts +2 -8
  21. package/lib/programmers/MigrateApiNamespaceProgrammer.js +31 -37
  22. package/lib/programmers/MigrateApiNamespaceProgrammer.js.map +1 -1
  23. package/lib/programmers/MigrateApiProgrammer.js +19 -70
  24. package/lib/programmers/MigrateApiProgrammer.js.map +1 -1
  25. package/lib/programmers/MigrateApiSimulatationProgrammer.d.ts +2 -8
  26. package/lib/programmers/MigrateApiSimulatationProgrammer.js +16 -16
  27. package/lib/programmers/MigrateApiSimulatationProgrammer.js.map +1 -1
  28. package/lib/programmers/MigrateApiStartProgrammer.js +1 -1
  29. package/lib/programmers/MigrateApiStartProgrammer.js.map +1 -1
  30. package/lib/programmers/MigrateE2eProgrammer.js +1 -3
  31. package/lib/programmers/MigrateE2eProgrammer.js.map +1 -1
  32. package/lib/programmers/MigrateNestMethodProgrammer.js +4 -4
  33. package/lib/programmers/MigrateNestMethodProgrammer.js.map +1 -1
  34. package/lib/programmers/MigrateNestProgrammer.js +27 -23
  35. package/lib/programmers/MigrateNestProgrammer.js.map +1 -1
  36. package/lib/programmers/MigrateSchemaProgrammer.js +22 -22
  37. package/lib/structures/IMigrateProgram.d.ts +8 -8
  38. package/lib/structures/IMigrateRoute.d.ts +1 -46
  39. package/lib/utils/OpenApiTypeChecker.d.ts +1 -1
  40. package/lib/utils/StringUtil.d.ts +0 -4
  41. package/lib/utils/StringUtil.js +0 -31
  42. package/lib/utils/StringUtil.js.map +1 -1
  43. package/lib/utils/openapi-down-convert/RefVisitor.js +4 -5
  44. package/lib/utils/openapi-down-convert/RefVisitor.js.map +1 -1
  45. package/package.json +8 -8
  46. package/src/MigrateApplication.ts +3 -2
  47. package/src/analyzers/MigrateAnalyzer.ts +10 -5
  48. package/src/analyzers/MigrateControllerAnalyzer.ts +17 -122
  49. package/src/bundles/NEST_TEMPLATE.ts +3 -3
  50. package/src/bundles/SDK_TEMPLATE.ts +1 -1
  51. package/src/internal/MigrateCommander.ts +8 -2
  52. package/src/programmers/MigrateApiFileProgrammer.ts +10 -14
  53. package/src/programmers/MigrateApiFunctionProgrammer.ts +43 -41
  54. package/src/programmers/MigrateApiNamespaceProgrammer.ts +33 -51
  55. package/src/programmers/MigrateApiProgrammer.ts +26 -95
  56. package/src/programmers/MigrateApiSimulatationProgrammer.ts +17 -25
  57. package/src/programmers/MigrateApiStartProgrammer.ts +1 -1
  58. package/src/programmers/MigrateE2eProgrammer.ts +1 -3
  59. package/src/programmers/MigrateNestMethodProgrammer.ts +4 -4
  60. package/src/programmers/MigrateNestProgrammer.ts +10 -4
  61. package/src/structures/IMigrateProgram.ts +8 -8
  62. package/src/structures/IMigrateRoute.ts +1 -51
  63. package/src/utils/StringUtil.ts +0 -42
  64. package/lib/analyzers/MigrateMethodAnalyzer.d.ts +0 -9
  65. package/lib/analyzers/MigrateMethodAnalyzer.js +0 -304
  66. package/lib/analyzers/MigrateMethodAnalyzer.js.map +0 -1
  67. package/src/analyzers/MigrateMethodAnalyzer.ts +0 -387
@@ -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}`,
@@ -10,9 +10,7 @@ import { MigrateImportProgrammer } from "./MigrateImportProgrammer";
10
10
 
11
11
  export namespace MigrateE2eProgrammer {
12
12
  export const write = (program: IMigrateProgram): IMigrateFile[] =>
13
- program.controllers
14
- .map((c) => c.routes.map(writeFile(program.document.components)))
15
- .flat();
13
+ program.routes.map(writeFile(program.document.components));
16
14
 
17
15
  const writeFile =
18
16
  (components: OpenApi.IComponents) =>
@@ -28,7 +28,7 @@ export namespace MigrateNestMethodProgrammer {
28
28
  ts.factory.createToken(ts.SyntaxKind.AsyncKeyword),
29
29
  ],
30
30
  undefined,
31
- route.name,
31
+ route.accessor.at(-1)!,
32
32
  undefined,
33
33
  undefined,
34
34
  writeParameters(components)(importer)(route),
@@ -36,7 +36,7 @@ export namespace MigrateNestMethodProgrammer {
36
36
  ts.factory.createBlock(
37
37
  [
38
38
  ...[
39
- ...route.parameters.map((p) => StringUtil.normalize(p.key)),
39
+ ...route.parameters.map((p) => p.key),
40
40
  ...(route.headers ? ["headers"] : []),
41
41
  ...(route.query ? ["query"] : []),
42
42
  ...(route.body ? ["body"] : []),
@@ -174,7 +174,7 @@ export namespace MigrateNestMethodProgrammer {
174
174
  ),
175
175
  ],
176
176
  undefined,
177
- StringUtil.normalize(key),
177
+ key,
178
178
  undefined,
179
179
  MigrateSchemaProgrammer.write(components)(importer)(value),
180
180
  ),
@@ -241,7 +241,7 @@ export namespace MigrateNestMethodProgrammer {
241
241
  ),
242
242
  ],
243
243
  undefined,
244
- StringUtil.normalize(accessor.variable),
244
+ accessor.variable,
245
245
  undefined,
246
246
  MigrateSchemaProgrammer.write(components)(importer)(schema),
247
247
  );
@@ -1,5 +1,7 @@
1
1
  import ts from "typescript";
2
2
 
3
+ import { MigrateControllerAnalyzer } from "../analyzers/MigrateControllerAnalyzer";
4
+ import { IMigrateController } from "../structures/IMigrateController";
3
5
  import { IMigrateFile } from "../structures/IMigrateFile";
4
6
  import { IMigrateProgram } from "../structures/IMigrateProgram";
5
7
  import { FilePrinter } from "../utils/FilePrinter";
@@ -9,14 +11,17 @@ import { MigrateNestControllerProgrammer } from "./MigrateNestControllerProgramm
9
11
  import { MigrateNestModuleProgrammer } from "./MigrateNestModuleProgrammer";
10
12
 
11
13
  export namespace MigrateNestProgrammer {
12
- export const write = (program: IMigrateProgram): IMigrateFile[] =>
13
- [
14
+ export const write = (program: IMigrateProgram): IMigrateFile[] => {
15
+ const controllers: IMigrateController[] = MigrateControllerAnalyzer.analyze(
16
+ program.routes,
17
+ );
18
+ return [
14
19
  {
15
20
  location: "src",
16
21
  file: "MyModule.ts",
17
- statements: MigrateNestModuleProgrammer.write(program.controllers),
22
+ statements: MigrateNestModuleProgrammer.write(controllers),
18
23
  },
19
- ...program.controllers.map((c) => ({
24
+ ...controllers.map((c) => ({
20
25
  location: c.location,
21
26
  file: `${c.name}.ts`,
22
27
  statements: MigrateNestControllerProgrammer.write(
@@ -35,6 +40,7 @@ export namespace MigrateNestProgrammer {
35
40
  file: o.file,
36
41
  content: FilePrinter.write({ statements: o.statements }),
37
42
  }));
43
+ };
38
44
 
39
45
  const writeDtoFile = (
40
46
  key: string,
@@ -1,27 +1,27 @@
1
1
  import { OpenApi } from "@samchon/openapi";
2
2
 
3
- import { IMigrateController } from "./IMigrateController";
4
3
  import { IMigrateRoute } from "./IMigrateRoute";
5
4
 
6
5
  export interface IMigrateProgram extends IMigrateProgram.IProps {
7
- controllers: IMigrateController[];
6
+ routes: IMigrateRoute[];
7
+ errors: IMigrateProgram.IError[];
8
8
  }
9
9
  export namespace IMigrateProgram {
10
- export type Dictionary = Map<OpenApi.IOperation, IEntry>;
11
- export interface IEntry {
12
- controller: IMigrateController;
13
- route: IMigrateRoute;
14
- }
15
10
  export interface IProps {
16
11
  mode: "nest" | "sdk";
17
12
  simulate: boolean;
18
13
  e2e: boolean;
19
14
  document: OpenApi.IDocument;
20
- dictionary: Dictionary;
21
15
  }
22
16
  export interface IConfig {
23
17
  mode: "nest" | "sdk";
24
18
  simulate: boolean;
25
19
  e2e: boolean;
26
20
  }
21
+ export interface IError {
22
+ method: string;
23
+ path: string;
24
+ operation: () => OpenApi.IOperation;
25
+ messages: string[];
26
+ }
27
27
  }
@@ -1,51 +1 @@
1
- import { OpenApi } from "@samchon/openapi";
2
-
3
- export interface IMigrateRoute {
4
- name: string;
5
- originalPath: string;
6
- path: string;
7
- method: string;
8
- accessor: string[];
9
- parameters: IMigrateRoute.IParameter[];
10
- headers: IMigrateRoute.IHeaders | null;
11
- query: IMigrateRoute.IQuery | null;
12
- body: IMigrateRoute.IBody | null;
13
- success: IMigrateRoute.IBody | null;
14
- exceptions: Record<string, IMigrateRoute.IException>;
15
- comment: () => string;
16
- tags: string[];
17
- deprecated: boolean;
18
- }
19
- export namespace IMigrateRoute {
20
- export interface IParameter {
21
- name: string;
22
- key: string;
23
- schema: OpenApi.IJsonSchema;
24
- description?: string;
25
- }
26
- export interface IHeaders {
27
- name: string;
28
- key: string;
29
- schema: OpenApi.IJsonSchema;
30
- }
31
- export interface IQuery {
32
- name: string;
33
- key: string;
34
- schema: OpenApi.IJsonSchema;
35
- }
36
- export interface IBody {
37
- name: string;
38
- key: string;
39
- type:
40
- | "text/plain"
41
- | "application/json"
42
- | "application/x-www-form-urlencoded"
43
- | "multipart/form-data";
44
- schema: OpenApi.IJsonSchema;
45
- "x-nestia-encrypted"?: boolean;
46
- }
47
- export interface IException {
48
- description?: string;
49
- schema: OpenApi.IJsonSchema;
50
- }
51
- }
1
+ export { IMigrateRoute } from "@samchon/openapi";