@nestia/migrate 0.13.0 → 0.13.1

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 (31) hide show
  1. package/lib/MigrateApplication.js +45 -9
  2. package/lib/MigrateApplication.js.map +1 -1
  3. package/lib/analyzers/MigrateMethodAnalyzer.js +19 -3
  4. package/lib/analyzers/MigrateMethodAnalyzer.js.map +1 -1
  5. package/lib/bundles/NEST_TEMPLATE.js +2 -2
  6. package/lib/bundles/SDK_TEMPLATE.js +1 -1
  7. package/lib/internal/MigrateCommander.js.map +1 -1
  8. package/lib/programmers/MigrateSchemaProgrammer.js +3 -4
  9. package/lib/programmers/MigrateSchemaProgrammer.js.map +1 -1
  10. package/package.json +79 -79
  11. package/src/analyzers/MigrateControllerAnalyzer.ts +137 -137
  12. package/src/analyzers/MigrateMethodAnalyzer.ts +383 -363
  13. package/src/bundles/NEST_TEMPLATE.ts +2 -2
  14. package/src/bundles/SDK_TEMPLATE.ts +1 -1
  15. package/src/internal/MigrateCommander.ts +76 -70
  16. package/src/module.ts +8 -8
  17. package/src/programmers/MigrateApiFileProgrammer.ts +53 -53
  18. package/src/programmers/MigrateApiFunctionProgrammer.ts +199 -199
  19. package/src/programmers/MigrateApiNamespaceProgrammer.ts +431 -431
  20. package/src/programmers/MigrateApiProgrammer.ts +172 -172
  21. package/src/programmers/MigrateApiSimulatationProgrammer.ts +327 -327
  22. package/src/programmers/MigrateDtoProgrammer.ts +77 -77
  23. package/src/programmers/MigrateE2eFileProgrammer.ts +117 -117
  24. package/src/programmers/MigrateE2eProgrammer.ts +36 -36
  25. package/src/programmers/MigrateNestControllerProgrammer.ts +50 -50
  26. package/src/programmers/MigrateNestMethodProgrammer.ts +249 -249
  27. package/src/programmers/MigrateNestProgrammer.ts +74 -74
  28. package/src/structures/IMigrateDto.ts +8 -8
  29. package/src/structures/IMigrateProgram.ts +27 -27
  30. package/src/structures/IMigrateRoute.ts +51 -51
  31. package/src/utils/OpenApiTypeChecker.ts +73 -73
@@ -1,172 +1,172 @@
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.document.components,
62
- )(props),
63
- }),
64
- }));
65
- if (program.mode === "sdk")
66
- output.push(
67
- ...[
68
- ...MigrateDtoProgrammer.compose(
69
- program.document.components,
70
- ).entries(),
71
- ].map(([key, value]) => ({
72
- location: "src/structures",
73
- file: `${key}.ts`,
74
- content: FilePrinter.write({
75
- statements: writeDtoFile(key, value),
76
- }),
77
- })),
78
- );
79
- return output;
80
- };
81
-
82
- const writeDtoFile = (
83
- key: string,
84
- modulo: MigrateDtoProgrammer.IModule,
85
- ): ts.Statement[] => {
86
- const importer = new MigrateImportProgrammer();
87
- const statements: ts.Statement[] = iterate(importer)(modulo);
88
- if (statements.length === 0) return [];
89
-
90
- return [
91
- ...importer.toStatements((name) => `./${name}`, key),
92
- ...(importer.empty() ? [] : [FilePrinter.newLine()]),
93
- ...statements,
94
- ];
95
- };
96
-
97
- const iterate =
98
- (importer: MigrateImportProgrammer) =>
99
- (modulo: MigrateDtoProgrammer.IModule): ts.Statement[] => {
100
- const output: ts.Statement[] = [];
101
- if (modulo.programmer !== null) output.push(modulo.programmer(importer));
102
- if (modulo.children.size) {
103
- const internal: ts.Statement[] = [];
104
- for (const child of modulo.children.values())
105
- internal.push(...iterate(importer)(child));
106
- output.push(
107
- ts.factory.createModuleDeclaration(
108
- [ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],
109
- ts.factory.createIdentifier(modulo.name),
110
- ts.factory.createModuleBlock(internal),
111
- ts.NodeFlags.Namespace,
112
- ),
113
- );
114
- }
115
- return output;
116
- };
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
- }
168
-
169
- const Functional = {
170
- hashCode: (x: string[]) => hash(x.join(".")),
171
- equals: (a: string[], b: string[]) => a.join(".") === b.join("."),
172
- };
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.document.components,
62
+ )(props),
63
+ }),
64
+ }));
65
+ if (program.mode === "sdk")
66
+ output.push(
67
+ ...[
68
+ ...MigrateDtoProgrammer.compose(
69
+ program.document.components,
70
+ ).entries(),
71
+ ].map(([key, value]) => ({
72
+ location: "src/structures",
73
+ file: `${key}.ts`,
74
+ content: FilePrinter.write({
75
+ statements: writeDtoFile(key, value),
76
+ }),
77
+ })),
78
+ );
79
+ return output;
80
+ };
81
+
82
+ const writeDtoFile = (
83
+ key: string,
84
+ modulo: MigrateDtoProgrammer.IModule,
85
+ ): ts.Statement[] => {
86
+ const importer = new MigrateImportProgrammer();
87
+ const statements: ts.Statement[] = iterate(importer)(modulo);
88
+ if (statements.length === 0) return [];
89
+
90
+ return [
91
+ ...importer.toStatements((name) => `./${name}`, key),
92
+ ...(importer.empty() ? [] : [FilePrinter.newLine()]),
93
+ ...statements,
94
+ ];
95
+ };
96
+
97
+ const iterate =
98
+ (importer: MigrateImportProgrammer) =>
99
+ (modulo: MigrateDtoProgrammer.IModule): ts.Statement[] => {
100
+ const output: ts.Statement[] = [];
101
+ if (modulo.programmer !== null) output.push(modulo.programmer(importer));
102
+ if (modulo.children.size) {
103
+ const internal: ts.Statement[] = [];
104
+ for (const child of modulo.children.values())
105
+ internal.push(...iterate(importer)(child));
106
+ output.push(
107
+ ts.factory.createModuleDeclaration(
108
+ [ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],
109
+ ts.factory.createIdentifier(modulo.name),
110
+ ts.factory.createModuleBlock(internal),
111
+ ts.NodeFlags.Namespace,
112
+ ),
113
+ );
114
+ }
115
+ return output;
116
+ };
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
+ }
168
+
169
+ const Functional = {
170
+ hashCode: (x: string[]) => hash(x.join(".")),
171
+ equals: (a: string[], b: string[]) => a.join(".") === b.join("."),
172
+ };