@nestia/migrate 0.11.4 → 0.11.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 (53) hide show
  1. package/lib/bundles/NEST_TEMPLATE.js +5 -5
  2. package/lib/bundles/NEST_TEMPLATE.js.map +1 -1
  3. package/lib/bundles/SDK_TEMPLATE.js +29 -4
  4. package/lib/bundles/SDK_TEMPLATE.js.map +1 -1
  5. package/lib/utils/openapi-down-convert/converter.js +2 -2
  6. package/package.json +2 -2
  7. package/src/MigrateApplication.ts +81 -81
  8. package/src/analyzers/MigrateAnalyzer.ts +9 -9
  9. package/src/analyzers/MigrateControllerAnalyzer.ts +135 -135
  10. package/src/analyzers/MigrateMethodAnalyzer.ts +439 -439
  11. package/src/archivers/MigrateFileArchiver.ts +38 -38
  12. package/src/bundles/NEST_TEMPLATE.ts +5 -5
  13. package/src/bundles/SDK_TEMPLATE.ts +29 -4
  14. package/src/executable/bundle.ts +110 -110
  15. package/src/internal/MigrateCommander.ts +70 -70
  16. package/src/internal/MigrateInquirer.ts +86 -86
  17. package/src/module.ts +14 -14
  18. package/src/programmers/MigrateApiFileProgrammer.ts +53 -53
  19. package/src/programmers/MigrateApiFunctionProgrammer.ts +199 -199
  20. package/src/programmers/MigrateApiNamespaceProgrammer.ts +431 -431
  21. package/src/programmers/MigrateApiProgrammer.ts +170 -170
  22. package/src/programmers/MigrateApiSimulatationProgrammer.ts +327 -327
  23. package/src/programmers/MigrateApiStartProgrammer.ts +194 -194
  24. package/src/programmers/MigrateDtoProgrammer.ts +78 -78
  25. package/src/programmers/MigrateE2eFileProgrammer.ts +117 -117
  26. package/src/programmers/MigrateE2eProgrammer.ts +36 -36
  27. package/src/programmers/MigrateImportProgrammer.ts +121 -121
  28. package/src/programmers/MigrateNestControllerProgrammer.ts +50 -50
  29. package/src/programmers/MigrateNestMethodProgrammer.ts +250 -250
  30. package/src/programmers/MigrateNestModuleProgrammer.ts +63 -63
  31. package/src/programmers/MigrateNestProgrammer.ts +74 -74
  32. package/src/programmers/MigrateSchemaProgrammer.ts +267 -267
  33. package/src/structures/IMigrateDto.ts +8 -8
  34. package/src/structures/IMigrateProgram.ts +27 -27
  35. package/src/structures/IMigrateRoute.ts +51 -51
  36. package/src/structures/ISwagger.ts +23 -23
  37. package/src/structures/ISwaggerComponents.ts +14 -14
  38. package/src/structures/ISwaggerRoute.ts +20 -20
  39. package/src/structures/ISwaggerRouteBodyContent.ts +15 -15
  40. package/src/structures/ISwaggerRouteParameter.ts +14 -14
  41. package/src/structures/ISwaggerRouteRequestBody.ts +12 -12
  42. package/src/structures/ISwaggerRouteResponse.ts +11 -11
  43. package/src/structures/ISwaggerSchema.ts +90 -90
  44. package/src/structures/ISwaggerSecurityScheme.ts +47 -47
  45. package/src/structures/ISwaggerV20.ts +10 -10
  46. package/src/structures/ISwaggerV31.ts +10 -10
  47. package/src/utils/FilePrinter.ts +36 -36
  48. package/src/utils/OpenApiConverter.ts +19 -19
  49. package/src/utils/StringUtil.ts +60 -60
  50. package/src/utils/SwaggerComponentsExplorer.ts +43 -43
  51. package/src/utils/SwaggerTypeChecker.ts +67 -67
  52. package/src/utils/openapi-down-convert/RefVisitor.ts +139 -139
  53. package/src/utils/openapi-down-convert/converter.ts +527 -527
@@ -1,170 +1,170 @@
1
- import { HashMap, IPointer, hash } from "tstl";
2
- import ts from "typescript";
3
- import { Escaper } from "typia/lib/utils/Escaper";
4
-
5
- import { IMigrateController } from "../structures/IMigrateController";
6
- import { IMigrateFile } from "../structures/IMigrateFile";
7
- import { IMigrateProgram } from "../structures/IMigrateProgram";
8
- import { IMigrateRoute } from "../structures/IMigrateRoute";
9
- import { FilePrinter } from "../utils/FilePrinter";
10
- import { StringUtil } from "../utils/StringUtil";
11
- import { MigrateApiFileProgrammer } from "./MigrateApiFileProgrammer";
12
- import { MigrateDtoProgrammer } from "./MigrateDtoProgrammer";
13
- import { MigrateImportProgrammer } from "./MigrateImportProgrammer";
14
-
15
- export namespace MigrateApiProgrammer {
16
- 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)),
48
- );
49
- });
50
-
51
- // // GROUP BY NAMESPACES AGAIN
52
- // const refined: HashMap<string[], MigrateApiFileProgrammer.IProps> =
53
- // collect(({ route }) => route.accessor.slice(0, -1))(program);
54
-
55
- // DO GENERATE
56
- const output: IMigrateFile[] = [...dict].map(({ second: props }) => ({
57
- location: `src/${program.mode === "nest" ? "api/" : ""}functional/${props.namespace.join("/")}`,
58
- file: "index.ts",
59
- content: FilePrinter.write({
60
- statements: MigrateApiFileProgrammer.write(program)(
61
- program.swagger.components,
62
- )(props),
63
- }),
64
- }));
65
- if (program.mode === "sdk")
66
- output.push(
67
- ...[
68
- ...MigrateDtoProgrammer.compose(program.swagger.components).entries(),
69
- ].map(([key, value]) => ({
70
- location: "src/structures",
71
- file: `${key}.ts`,
72
- content: FilePrinter.write({
73
- statements: writeDtoFile(key, value),
74
- }),
75
- })),
76
- );
77
- return output;
78
- };
79
-
80
- const writeDtoFile = (
81
- key: string,
82
- modulo: MigrateDtoProgrammer.IModule,
83
- ): ts.Statement[] => {
84
- const importer = new MigrateImportProgrammer();
85
- const statements: ts.Statement[] = iterate(importer)(modulo);
86
- if (statements.length === 0) return [];
87
-
88
- return [
89
- ...importer.toStatements((name) => `./${name}`, key),
90
- ...(importer.empty() ? [] : [FilePrinter.newLine()]),
91
- ...statements,
92
- ];
93
- };
94
-
95
- const iterate =
96
- (importer: MigrateImportProgrammer) =>
97
- (modulo: MigrateDtoProgrammer.IModule): ts.Statement[] => {
98
- const output: ts.Statement[] = [];
99
- if (modulo.programmer !== null) output.push(modulo.programmer(importer));
100
- if (modulo.children.size) {
101
- const internal: ts.Statement[] = [];
102
- for (const child of modulo.children.values())
103
- internal.push(...iterate(importer)(child));
104
- output.push(
105
- ts.factory.createModuleDeclaration(
106
- [ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],
107
- ts.factory.createIdentifier(modulo.name),
108
- ts.factory.createModuleBlock(internal),
109
- ts.NodeFlags.Namespace,
110
- ),
111
- );
112
- }
113
- return output;
114
- };
115
-
116
- const collect =
117
- (
118
- getter: (props: {
119
- controller: IMigrateController;
120
- route: IMigrateRoute;
121
- }) => string[],
122
- ) =>
123
- (
124
- program: IMigrateProgram,
125
- ): HashMap<string[], MigrateApiFileProgrammer.IProps> => {
126
- const dict: HashMap<string[], MigrateApiFileProgrammer.IProps> =
127
- new HashMap(Functional.hashCode, Functional.equals);
128
- for (const controller of program.controllers)
129
- for (const route of controller.routes) {
130
- const namespace: string[] = getter({ controller, route });
131
- const last: IPointer<MigrateApiFileProgrammer.IProps> = {
132
- value: dict.take(namespace, () => ({
133
- namespace,
134
- children: new Set(),
135
- entries: [],
136
- })),
137
- };
138
- last.value.entries.push({
139
- controller,
140
- route,
141
- alias: route.name,
142
- });
143
- namespace.slice(0, -1).forEach((_i, i, array) => {
144
- const partial: string[] = namespace.slice(0, array.length - i);
145
- const props: MigrateApiFileProgrammer.IProps = dict.take(
146
- partial,
147
- () => ({
148
- namespace: partial,
149
- children: new Set(),
150
- entries: [],
151
- }),
152
- );
153
- props.children.add(last.value.namespace.at(-1)!);
154
- last.value = props;
155
- });
156
- const top = dict.take([], () => ({
157
- namespace: [],
158
- children: new Set(),
159
- entries: [],
160
- }));
161
- if (namespace.length) top.children.add(namespace[0]);
162
- }
163
- return dict;
164
- };
165
- }
166
-
167
- const Functional = {
168
- hashCode: (x: string[]) => hash(x.join(".")),
169
- equals: (a: string[], b: string[]) => a.join(".") === b.join("."),
170
- };
1
+ import { HashMap, IPointer, hash } from "tstl";
2
+ import ts from "typescript";
3
+ import { Escaper } from "typia/lib/utils/Escaper";
4
+
5
+ import { IMigrateController } from "../structures/IMigrateController";
6
+ import { IMigrateFile } from "../structures/IMigrateFile";
7
+ import { IMigrateProgram } from "../structures/IMigrateProgram";
8
+ import { IMigrateRoute } from "../structures/IMigrateRoute";
9
+ import { FilePrinter } from "../utils/FilePrinter";
10
+ import { StringUtil } from "../utils/StringUtil";
11
+ import { MigrateApiFileProgrammer } from "./MigrateApiFileProgrammer";
12
+ import { MigrateDtoProgrammer } from "./MigrateDtoProgrammer";
13
+ import { MigrateImportProgrammer } from "./MigrateImportProgrammer";
14
+
15
+ export namespace MigrateApiProgrammer {
16
+ 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)),
48
+ );
49
+ });
50
+
51
+ // // GROUP BY NAMESPACES AGAIN
52
+ // const refined: HashMap<string[], MigrateApiFileProgrammer.IProps> =
53
+ // collect(({ route }) => route.accessor.slice(0, -1))(program);
54
+
55
+ // DO GENERATE
56
+ const output: IMigrateFile[] = [...dict].map(({ second: props }) => ({
57
+ location: `src/${program.mode === "nest" ? "api/" : ""}functional/${props.namespace.join("/")}`,
58
+ file: "index.ts",
59
+ content: FilePrinter.write({
60
+ statements: MigrateApiFileProgrammer.write(program)(
61
+ program.swagger.components,
62
+ )(props),
63
+ }),
64
+ }));
65
+ if (program.mode === "sdk")
66
+ output.push(
67
+ ...[
68
+ ...MigrateDtoProgrammer.compose(program.swagger.components).entries(),
69
+ ].map(([key, value]) => ({
70
+ location: "src/structures",
71
+ file: `${key}.ts`,
72
+ content: FilePrinter.write({
73
+ statements: writeDtoFile(key, value),
74
+ }),
75
+ })),
76
+ );
77
+ return output;
78
+ };
79
+
80
+ const writeDtoFile = (
81
+ key: string,
82
+ modulo: MigrateDtoProgrammer.IModule,
83
+ ): ts.Statement[] => {
84
+ const importer = new MigrateImportProgrammer();
85
+ const statements: ts.Statement[] = iterate(importer)(modulo);
86
+ if (statements.length === 0) return [];
87
+
88
+ return [
89
+ ...importer.toStatements((name) => `./${name}`, key),
90
+ ...(importer.empty() ? [] : [FilePrinter.newLine()]),
91
+ ...statements,
92
+ ];
93
+ };
94
+
95
+ const iterate =
96
+ (importer: MigrateImportProgrammer) =>
97
+ (modulo: MigrateDtoProgrammer.IModule): ts.Statement[] => {
98
+ const output: ts.Statement[] = [];
99
+ if (modulo.programmer !== null) output.push(modulo.programmer(importer));
100
+ if (modulo.children.size) {
101
+ const internal: ts.Statement[] = [];
102
+ for (const child of modulo.children.values())
103
+ internal.push(...iterate(importer)(child));
104
+ output.push(
105
+ ts.factory.createModuleDeclaration(
106
+ [ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],
107
+ ts.factory.createIdentifier(modulo.name),
108
+ ts.factory.createModuleBlock(internal),
109
+ ts.NodeFlags.Namespace,
110
+ ),
111
+ );
112
+ }
113
+ return output;
114
+ };
115
+
116
+ const collect =
117
+ (
118
+ getter: (props: {
119
+ controller: IMigrateController;
120
+ route: IMigrateRoute;
121
+ }) => string[],
122
+ ) =>
123
+ (
124
+ program: IMigrateProgram,
125
+ ): HashMap<string[], MigrateApiFileProgrammer.IProps> => {
126
+ const dict: HashMap<string[], MigrateApiFileProgrammer.IProps> =
127
+ new HashMap(Functional.hashCode, Functional.equals);
128
+ for (const controller of program.controllers)
129
+ for (const route of controller.routes) {
130
+ const namespace: string[] = getter({ controller, route });
131
+ const last: IPointer<MigrateApiFileProgrammer.IProps> = {
132
+ value: dict.take(namespace, () => ({
133
+ namespace,
134
+ children: new Set(),
135
+ entries: [],
136
+ })),
137
+ };
138
+ last.value.entries.push({
139
+ controller,
140
+ route,
141
+ alias: route.name,
142
+ });
143
+ namespace.slice(0, -1).forEach((_i, i, array) => {
144
+ const partial: string[] = namespace.slice(0, array.length - i);
145
+ const props: MigrateApiFileProgrammer.IProps = dict.take(
146
+ partial,
147
+ () => ({
148
+ namespace: partial,
149
+ children: new Set(),
150
+ entries: [],
151
+ }),
152
+ );
153
+ props.children.add(last.value.namespace.at(-1)!);
154
+ last.value = props;
155
+ });
156
+ const top = dict.take([], () => ({
157
+ namespace: [],
158
+ children: new Set(),
159
+ entries: [],
160
+ }));
161
+ if (namespace.length) top.children.add(namespace[0]);
162
+ }
163
+ return dict;
164
+ };
165
+ }
166
+
167
+ const Functional = {
168
+ hashCode: (x: string[]) => hash(x.join(".")),
169
+ equals: (a: string[], b: string[]) => a.join(".") === b.join("."),
170
+ };