@nestia/migrate 0.7.6 → 0.7.7

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 (68) hide show
  1. package/lib/MigrateApplication.js +7 -4
  2. package/lib/MigrateApplication.js.map +1 -1
  3. package/lib/analyzers/MigrateAnalyzer.d.ts +2 -3
  4. package/lib/analyzers/MigrateAnalyzer.js +1 -5
  5. package/lib/analyzers/MigrateAnalyzer.js.map +1 -1
  6. package/lib/analyzers/MigrateControllerAnalyzer.d.ts +2 -2
  7. package/lib/analyzers/MigrateControllerAnalyzer.js +22 -13
  8. package/lib/analyzers/MigrateControllerAnalyzer.js.map +1 -1
  9. package/lib/analyzers/MigrateMethodAnalyzer.d.ts +2 -2
  10. package/lib/analyzers/MigrateMethodAnalyzer.js +16 -16
  11. package/lib/analyzers/MigrateMethodAnalyzer.js.map +1 -1
  12. package/lib/module.d.ts +8 -0
  13. package/lib/module.js +8 -0
  14. package/lib/module.js.map +1 -1
  15. package/lib/programmers/MigrateApiFileProgrammer.d.ts +2 -2
  16. package/lib/programmers/MigrateApiFileProgrammer.js.map +1 -1
  17. package/lib/programmers/MigrateApiFunctionProgrammer.d.ts +2 -2
  18. package/lib/programmers/MigrateApiFunctionProgrammer.js.map +1 -1
  19. package/lib/programmers/MigrateApiNamespaceProgrammer.d.ts +2 -2
  20. package/lib/programmers/MigrateApiNamespaceProgrammer.js.map +1 -1
  21. package/lib/programmers/MigrateApiProgrammer.js +3 -3
  22. package/lib/programmers/MigrateApiProgrammer.js.map +1 -1
  23. package/lib/programmers/MigrateImportProgrammer.js +5 -5
  24. package/lib/programmers/MigrateImportProgrammer.js.map +1 -1
  25. package/lib/programmers/MigrateSchemaProgrammer.d.ts +1 -1
  26. package/lib/structures/IMigrateDto.d.ts +1 -1
  27. package/lib/structures/IMigrateProgram.d.ts +20 -4
  28. package/lib/structures/IMigrateRoute.d.ts +1 -1
  29. package/lib/structures/ISwaggerComponents.d.ts +1 -1
  30. package/lib/structures/ISwaggerRoute.d.ts +1 -1
  31. package/lib/structures/{ISwaggeSchema.js → ISwaggerSchema.js} +1 -1
  32. package/lib/structures/ISwaggerSchema.js.map +1 -0
  33. package/lib/utils/SwaggerTypeChecker.d.ts +1 -1
  34. package/package.json +1 -1
  35. package/src/MigrateApplication.ts +54 -48
  36. package/src/analyzers/MigrateAnalyzer.ts +9 -13
  37. package/src/analyzers/MigrateControllerAnalyzer.ts +139 -122
  38. package/src/analyzers/MigrateMethodAnalyzer.ts +350 -348
  39. package/src/archivers/MigrateFileArchiver.ts +38 -38
  40. package/src/executable/bundle.ts +109 -109
  41. package/src/internal/MigrateCommander.ts +51 -51
  42. package/src/module.ts +10 -0
  43. package/src/programmers/MigrateApiFileProgrammer.ts +53 -53
  44. package/src/programmers/MigrateApiFunctionProgrammer.ts +203 -203
  45. package/src/programmers/MigrateApiNamespaceProgrammer.ts +430 -430
  46. package/src/programmers/MigrateApiProgrammer.ts +132 -132
  47. package/src/programmers/MigrateApiSimulatationProgrammer.ts +328 -328
  48. package/src/programmers/MigrateDtoProgrammer.ts +78 -78
  49. package/src/programmers/MigrateImportProgrammer.ts +114 -116
  50. package/src/programmers/MigrateNestControllerProgrammer.ts +50 -50
  51. package/src/programmers/MigrateNestMethodProgrammer.ts +249 -249
  52. package/src/programmers/MigrateNestModuleProgrammer.ts +62 -62
  53. package/src/programmers/MigrateNestProgrammer.ts +74 -74
  54. package/src/programmers/MigrateSchemaProgrammer.ts +257 -257
  55. package/src/structures/IMigrateDto.ts +1 -1
  56. package/src/structures/IMigrateProgram.ts +20 -4
  57. package/src/structures/IMigrateRoute.ts +46 -46
  58. package/src/structures/ISwaggerComponents.ts +1 -1
  59. package/src/structures/ISwaggerRoute.ts +1 -1
  60. package/src/utils/FilePrinter.ts +36 -36
  61. package/src/utils/SwaggerTypeChecker.ts +67 -67
  62. package/lib/IMigrateConfig.d.ts +0 -4
  63. package/lib/IMigrateConfig.js +0 -3
  64. package/lib/IMigrateConfig.js.map +0 -1
  65. package/lib/structures/ISwaggeSchema.js.map +0 -1
  66. package/src/IMigrateConfig.ts +0 -4
  67. /package/lib/structures/{ISwaggeSchema.d.ts → ISwaggerSchema.d.ts} +0 -0
  68. /package/src/structures/{ISwaggeSchema.ts → ISwaggerSchema.ts} +0 -0
@@ -1,132 +1,132 @@
1
- import { HashMap, IPointer, hash } from "tstl";
2
- import ts from "typescript";
3
- import { Escaper } from "typia/lib/utils/Escaper";
4
-
5
- import { IMigrateProgram } from "../module";
6
- import { IMigrateFile } from "../structures/IMigrateFile";
7
- import { FilePrinter } from "../utils/FilePrinter";
8
- import { StringUtil } from "../utils/StringUtil";
9
- import { MigrateApiFileProgrammer } from "./MigrateApiFileProgrammer";
10
- import { MigrateDtoProgrammer } from "./MigrateDtoProgrammer";
11
- import { MigrateImportProgrammer } from "./MigrateImportProgrammer";
12
-
13
- export namespace MigrateApiProgrammer {
14
- export const write = (program: IMigrateProgram): IMigrateFile[] => {
15
- const dict: HashMap<string[], MigrateApiFileProgrammer.IProps> =
16
- new HashMap(
17
- (x) => hash(x.join(".")),
18
- (a, b) => a.join(".") === b.join("."),
19
- );
20
- for (const controller of program.controllers)
21
- for (const route of controller.routes) {
22
- const namespace: string[] = [
23
- ...controller.path.split("/"),
24
- ...route.path.split("/"),
25
- ]
26
- .filter((str) => !!str.length && str[0] !== ":")
27
- .map(StringUtil.normalize)
28
- .map((str) => (Escaper.variable(str) ? str : `_${str}`));
29
- const last: IPointer<MigrateApiFileProgrammer.IProps> = {
30
- value: dict.take(namespace, () => ({
31
- namespace,
32
- children: new Set(),
33
- entries: [],
34
- })),
35
- };
36
- last.value.entries.push({
37
- controller,
38
- route,
39
- alias: route.name,
40
- });
41
- namespace.slice(0, -1).forEach((_i, i, array) => {
42
- const partial: string[] = namespace.slice(0, array.length - i);
43
- const props: MigrateApiFileProgrammer.IProps = dict.take(
44
- partial,
45
- () => ({
46
- namespace: partial,
47
- children: new Set(),
48
- entries: [],
49
- }),
50
- );
51
- props.children.add(last.value.namespace.at(-1)!);
52
- last.value = props;
53
- });
54
- const top = dict.take([], () => ({
55
- namespace: [],
56
- children: new Set(),
57
- entries: [],
58
- }));
59
- if (namespace.length) top.children.add(namespace[0]);
60
- }
61
- for (const { second: props } of dict)
62
- props.entries.forEach((entry, i) => {
63
- entry.alias = StringUtil.escapeDuplicate([
64
- ...props.children,
65
- ...entry.route.parameters.map((p) => p.key),
66
- ...(entry.route.body ? [entry.route.body.key] : []),
67
- ...(entry.route.query ? [entry.route.query.key] : []),
68
- ...props.entries.filter((_, j) => i !== j).map((e) => e.alias),
69
- ])(entry.alias);
70
- entry.route.accessor = [...props.namespace, entry.alias];
71
- });
72
-
73
- const output: IMigrateFile[] = [...dict].map(({ second: props }) => ({
74
- location: `src/${program.config.mode === "nest" ? "api/" : ""}functional/${props.namespace.join("/")}`,
75
- file: "index.ts",
76
- content: FilePrinter.write({
77
- statements: MigrateApiFileProgrammer.write(program.config)(
78
- program.swagger.components,
79
- )(props),
80
- }),
81
- }));
82
- if (program.config.mode === "sdk")
83
- output.push(
84
- ...[
85
- ...MigrateDtoProgrammer.write(program.swagger.components).entries(),
86
- ].map(([key, value]) => ({
87
- location: "src/structures",
88
- file: `${key}.ts`,
89
- content: FilePrinter.write({
90
- statements: writeDtoFile(key, value),
91
- }),
92
- })),
93
- );
94
- return output;
95
- };
96
-
97
- const writeDtoFile = (
98
- key: string,
99
- modulo: MigrateDtoProgrammer.IModule,
100
- ): ts.Statement[] => {
101
- const importer = new MigrateImportProgrammer();
102
- const statements: ts.Statement[] = iterate(importer)(modulo);
103
- if (statements.length === 0) return [];
104
-
105
- return [
106
- ...importer.toStatements((name) => `./${name}`, key),
107
- ...(importer.empty() ? [] : [FilePrinter.newLine()]),
108
- ...statements,
109
- ];
110
- };
111
-
112
- const iterate =
113
- (importer: MigrateImportProgrammer) =>
114
- (modulo: MigrateDtoProgrammer.IModule): ts.Statement[] => {
115
- const output: ts.Statement[] = [];
116
- if (modulo.programmer !== null) output.push(modulo.programmer(importer));
117
- if (modulo.children.size) {
118
- const internal: ts.Statement[] = [];
119
- for (const child of modulo.children.values())
120
- internal.push(...iterate(importer)(child));
121
- output.push(
122
- ts.factory.createModuleDeclaration(
123
- [ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],
124
- ts.factory.createIdentifier(modulo.name),
125
- ts.factory.createModuleBlock(internal),
126
- ts.NodeFlags.Namespace,
127
- ),
128
- );
129
- }
130
- return output;
131
- };
132
- }
1
+ import { HashMap, IPointer, hash } from "tstl";
2
+ import ts from "typescript";
3
+ import { Escaper } from "typia/lib/utils/Escaper";
4
+
5
+ import { IMigrateProgram } from "../module";
6
+ import { IMigrateFile } from "../structures/IMigrateFile";
7
+ import { FilePrinter } from "../utils/FilePrinter";
8
+ import { StringUtil } from "../utils/StringUtil";
9
+ import { MigrateApiFileProgrammer } from "./MigrateApiFileProgrammer";
10
+ import { MigrateDtoProgrammer } from "./MigrateDtoProgrammer";
11
+ import { MigrateImportProgrammer } from "./MigrateImportProgrammer";
12
+
13
+ export namespace MigrateApiProgrammer {
14
+ export const write = (program: IMigrateProgram): IMigrateFile[] => {
15
+ const dict: HashMap<string[], MigrateApiFileProgrammer.IProps> =
16
+ new HashMap(
17
+ (x) => hash(x.join(".")),
18
+ (a, b) => a.join(".") === b.join("."),
19
+ );
20
+ for (const controller of program.controllers)
21
+ for (const route of controller.routes) {
22
+ const namespace: string[] = [
23
+ ...controller.path.split("/"),
24
+ ...route.path.split("/"),
25
+ ]
26
+ .filter((str) => !!str.length && str[0] !== ":")
27
+ .map(StringUtil.normalize)
28
+ .map((str) => (Escaper.variable(str) ? str : `_${str}`));
29
+ const last: IPointer<MigrateApiFileProgrammer.IProps> = {
30
+ value: dict.take(namespace, () => ({
31
+ namespace,
32
+ children: new Set(),
33
+ entries: [],
34
+ })),
35
+ };
36
+ last.value.entries.push({
37
+ controller,
38
+ route,
39
+ alias: route.name,
40
+ });
41
+ namespace.slice(0, -1).forEach((_i, i, array) => {
42
+ const partial: string[] = namespace.slice(0, array.length - i);
43
+ const props: MigrateApiFileProgrammer.IProps = dict.take(
44
+ partial,
45
+ () => ({
46
+ namespace: partial,
47
+ children: new Set(),
48
+ entries: [],
49
+ }),
50
+ );
51
+ props.children.add(last.value.namespace.at(-1)!);
52
+ last.value = props;
53
+ });
54
+ const top = dict.take([], () => ({
55
+ namespace: [],
56
+ children: new Set(),
57
+ entries: [],
58
+ }));
59
+ if (namespace.length) top.children.add(namespace[0]);
60
+ }
61
+ for (const { second: props } of dict)
62
+ props.entries.forEach((entry, i) => {
63
+ entry.alias = StringUtil.escapeDuplicate([
64
+ ...props.children,
65
+ ...entry.route.parameters.map((p) => p.key),
66
+ ...(entry.route.body ? [entry.route.body.key] : []),
67
+ ...(entry.route.query ? [entry.route.query.key] : []),
68
+ ...props.entries.filter((_, j) => i !== j).map((e) => e.alias),
69
+ ])(entry.alias);
70
+ entry.route.accessor = [...props.namespace, entry.alias];
71
+ });
72
+
73
+ const output: IMigrateFile[] = [...dict].map(({ second: props }) => ({
74
+ location: `src/${program.mode === "nest" ? "api/" : ""}functional/${props.namespace.join("/")}`,
75
+ file: "index.ts",
76
+ content: FilePrinter.write({
77
+ statements: MigrateApiFileProgrammer.write(program)(
78
+ program.swagger.components,
79
+ )(props),
80
+ }),
81
+ }));
82
+ if (program.mode === "sdk")
83
+ output.push(
84
+ ...[
85
+ ...MigrateDtoProgrammer.write(program.swagger.components).entries(),
86
+ ].map(([key, value]) => ({
87
+ location: "src/structures",
88
+ file: `${key}.ts`,
89
+ content: FilePrinter.write({
90
+ statements: writeDtoFile(key, value),
91
+ }),
92
+ })),
93
+ );
94
+ return output;
95
+ };
96
+
97
+ const writeDtoFile = (
98
+ key: string,
99
+ modulo: MigrateDtoProgrammer.IModule,
100
+ ): ts.Statement[] => {
101
+ const importer = new MigrateImportProgrammer();
102
+ const statements: ts.Statement[] = iterate(importer)(modulo);
103
+ if (statements.length === 0) return [];
104
+
105
+ return [
106
+ ...importer.toStatements((name) => `./${name}`, key),
107
+ ...(importer.empty() ? [] : [FilePrinter.newLine()]),
108
+ ...statements,
109
+ ];
110
+ };
111
+
112
+ const iterate =
113
+ (importer: MigrateImportProgrammer) =>
114
+ (modulo: MigrateDtoProgrammer.IModule): ts.Statement[] => {
115
+ const output: ts.Statement[] = [];
116
+ if (modulo.programmer !== null) output.push(modulo.programmer(importer));
117
+ if (modulo.children.size) {
118
+ const internal: ts.Statement[] = [];
119
+ for (const child of modulo.children.values())
120
+ internal.push(...iterate(importer)(child));
121
+ output.push(
122
+ ts.factory.createModuleDeclaration(
123
+ [ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],
124
+ ts.factory.createIdentifier(modulo.name),
125
+ ts.factory.createModuleBlock(internal),
126
+ ts.NodeFlags.Namespace,
127
+ ),
128
+ );
129
+ }
130
+ return output;
131
+ };
132
+ }