@nestia/migrate 0.21.4 → 4.2.0-dev.20241211-2

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/README.md +87 -87
  2. package/lib/MigrateApplication.js +5 -3
  3. package/lib/MigrateApplication.js.map +1 -1
  4. package/lib/bundles/NEST_TEMPLATE.js +66 -66
  5. package/lib/bundles/NEST_TEMPLATE.js.map +1 -1
  6. package/lib/bundles/SDK_TEMPLATE.js +30 -30
  7. package/lib/bundles/SDK_TEMPLATE.js.map +1 -1
  8. package/lib/executable/migrate.js +0 -0
  9. package/lib/index.mjs +97 -95
  10. package/lib/index.mjs.map +1 -1
  11. package/lib/utils/openapi-down-convert/converter.js +2 -2
  12. package/package.json +3 -3
  13. package/src/MigrateApplication.ts +107 -107
  14. package/src/analyzers/MigrateAnalyzer.ts +18 -18
  15. package/src/analyzers/MigrateControllerAnalyzer.ts +40 -40
  16. package/src/archivers/MigrateFileArchiver.ts +38 -38
  17. package/src/bundles/NEST_TEMPLATE.ts +66 -66
  18. package/src/bundles/SDK_TEMPLATE.ts +30 -30
  19. package/src/executable/bundle.js +125 -125
  20. package/src/executable/migrate.ts +7 -7
  21. package/src/factories/TypeLiteralFactory.ts +57 -57
  22. package/src/index.ts +4 -4
  23. package/src/internal/MigrateCommander.ts +86 -86
  24. package/src/internal/MigrateInquirer.ts +89 -89
  25. package/src/module.ts +8 -8
  26. package/src/programmers/MigrateApiFileProgrammer.ts +49 -49
  27. package/src/programmers/MigrateApiFunctionProgrammer.ts +210 -210
  28. package/src/programmers/MigrateApiNamespaceProgrammer.ts +417 -417
  29. package/src/programmers/MigrateApiProgrammer.ts +103 -103
  30. package/src/programmers/MigrateApiSimulatationProgrammer.ts +324 -324
  31. package/src/programmers/MigrateApiStartProgrammer.ts +194 -194
  32. package/src/programmers/MigrateDtoProgrammer.ts +87 -87
  33. package/src/programmers/MigrateE2eFileProgrammer.ts +117 -117
  34. package/src/programmers/MigrateE2eProgrammer.ts +34 -34
  35. package/src/programmers/MigrateImportProgrammer.ts +118 -118
  36. package/src/programmers/MigrateNestControllerProgrammer.ts +50 -50
  37. package/src/programmers/MigrateNestMethodProgrammer.ts +371 -371
  38. package/src/programmers/MigrateNestModuleProgrammer.ts +65 -65
  39. package/src/programmers/MigrateNestProgrammer.ts +79 -79
  40. package/src/programmers/MigrateSchemaProgrammer.ts +373 -373
  41. package/src/structures/IHttpMigrateController.ts +8 -8
  42. package/src/structures/IHttpMigrateDto.ts +8 -8
  43. package/src/structures/IHttpMigrateFile.ts +5 -5
  44. package/src/structures/IHttpMigrateProgram.ts +27 -27
  45. package/src/structures/IHttpMigrateRoute.ts +1 -1
  46. package/src/structures/IHttpMigrateSchema.ts +4 -4
  47. package/src/utils/FilePrinter.ts +36 -36
  48. package/src/utils/MapUtil.ts +13 -13
  49. package/src/utils/OpenApiTypeChecker.ts +73 -73
  50. package/src/utils/SetupWizard.ts +12 -12
  51. package/src/utils/StringUtil.ts +113 -113
  52. package/src/utils/openapi-down-convert/RefVisitor.ts +139 -139
  53. package/src/utils/openapi-down-convert/converter.ts +527 -527
@@ -1,103 +1,103 @@
1
- import { HashMap, hash } from "tstl";
2
- import ts from "typescript";
3
-
4
- import { IHttpMigrateFile } from "../structures/IHttpMigrateFile";
5
- import { IHttpMigrateProgram } from "../structures/IHttpMigrateProgram";
6
- import { FilePrinter } from "../utils/FilePrinter";
7
- import { MigrateApiFileProgrammer } from "./MigrateApiFileProgrammer";
8
- import { MigrateDtoProgrammer } from "./MigrateDtoProgrammer";
9
- import { MigrateImportProgrammer } from "./MigrateImportProgrammer";
10
-
11
- export namespace MigrateApiProgrammer {
12
- export const write = (program: IHttpMigrateProgram): IHttpMigrateFile[] => {
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
- }),
35
- );
36
- props.children.add(last.namespace.at(-1)!);
37
- last = props;
38
- });
39
- }
40
-
41
- // DO GENERATE
42
- const output: IHttpMigrateFile[] = [...dict].map(({ second: props }) => ({
43
- location: `src/${program.mode === "nest" ? "api/" : ""}functional/${props.namespace.join("/")}`,
44
- file: "index.ts",
45
- content: FilePrinter.write({
46
- statements: MigrateApiFileProgrammer.write(program)(
47
- program.document.components,
48
- )(props),
49
- }),
50
- }));
51
- if (program.mode === "sdk")
52
- output.push(
53
- ...[
54
- ...MigrateDtoProgrammer.compose(
55
- program.document.components,
56
- ).entries(),
57
- ].map(([key, value]) => ({
58
- location: "src/structures",
59
- file: `${key}.ts`,
60
- content: FilePrinter.write({
61
- statements: writeDtoFile(key, value),
62
- }),
63
- })),
64
- );
65
- return output;
66
- };
67
-
68
- const writeDtoFile = (
69
- key: string,
70
- modulo: MigrateDtoProgrammer.IModule,
71
- ): ts.Statement[] => {
72
- const importer = new MigrateImportProgrammer();
73
- const statements: ts.Statement[] = iterate(importer)(modulo);
74
- if (statements.length === 0) return [];
75
-
76
- return [
77
- ...importer.toStatements((name) => `./${name}`, key),
78
- ...(importer.empty() ? [] : [FilePrinter.newLine()]),
79
- ...statements,
80
- ];
81
- };
82
-
83
- const iterate =
84
- (importer: MigrateImportProgrammer) =>
85
- (modulo: MigrateDtoProgrammer.IModule): ts.Statement[] => {
86
- const output: ts.Statement[] = [];
87
- if (modulo.programmer !== null) output.push(modulo.programmer(importer));
88
- if (modulo.children.size) {
89
- const internal: ts.Statement[] = [];
90
- for (const child of modulo.children.values())
91
- internal.push(...iterate(importer)(child));
92
- output.push(
93
- ts.factory.createModuleDeclaration(
94
- [ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],
95
- ts.factory.createIdentifier(modulo.name),
96
- ts.factory.createModuleBlock(internal),
97
- ts.NodeFlags.Namespace,
98
- ),
99
- );
100
- }
101
- return output;
102
- };
103
- }
1
+ import { HashMap, hash } from "tstl";
2
+ import ts from "typescript";
3
+
4
+ import { IHttpMigrateFile } from "../structures/IHttpMigrateFile";
5
+ import { IHttpMigrateProgram } from "../structures/IHttpMigrateProgram";
6
+ import { FilePrinter } from "../utils/FilePrinter";
7
+ import { MigrateApiFileProgrammer } from "./MigrateApiFileProgrammer";
8
+ import { MigrateDtoProgrammer } from "./MigrateDtoProgrammer";
9
+ import { MigrateImportProgrammer } from "./MigrateImportProgrammer";
10
+
11
+ export namespace MigrateApiProgrammer {
12
+ export const write = (program: IHttpMigrateProgram): IHttpMigrateFile[] => {
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
+ }),
35
+ );
36
+ props.children.add(last.namespace.at(-1)!);
37
+ last = props;
38
+ });
39
+ }
40
+
41
+ // DO GENERATE
42
+ const output: IHttpMigrateFile[] = [...dict].map(({ second: props }) => ({
43
+ location: `src/${program.mode === "nest" ? "api/" : ""}functional/${props.namespace.join("/")}`,
44
+ file: "index.ts",
45
+ content: FilePrinter.write({
46
+ statements: MigrateApiFileProgrammer.write(program)(
47
+ program.document.components,
48
+ )(props),
49
+ }),
50
+ }));
51
+ if (program.mode === "sdk")
52
+ output.push(
53
+ ...[
54
+ ...MigrateDtoProgrammer.compose(
55
+ program.document.components,
56
+ ).entries(),
57
+ ].map(([key, value]) => ({
58
+ location: "src/structures",
59
+ file: `${key}.ts`,
60
+ content: FilePrinter.write({
61
+ statements: writeDtoFile(key, value),
62
+ }),
63
+ })),
64
+ );
65
+ return output;
66
+ };
67
+
68
+ const writeDtoFile = (
69
+ key: string,
70
+ modulo: MigrateDtoProgrammer.IModule,
71
+ ): ts.Statement[] => {
72
+ const importer = new MigrateImportProgrammer();
73
+ const statements: ts.Statement[] = iterate(importer)(modulo);
74
+ if (statements.length === 0) return [];
75
+
76
+ return [
77
+ ...importer.toStatements((name) => `./${name}`, key),
78
+ ...(importer.empty() ? [] : [FilePrinter.newLine()]),
79
+ ...statements,
80
+ ];
81
+ };
82
+
83
+ const iterate =
84
+ (importer: MigrateImportProgrammer) =>
85
+ (modulo: MigrateDtoProgrammer.IModule): ts.Statement[] => {
86
+ const output: ts.Statement[] = [];
87
+ if (modulo.programmer !== null) output.push(modulo.programmer(importer));
88
+ if (modulo.children.size) {
89
+ const internal: ts.Statement[] = [];
90
+ for (const child of modulo.children.values())
91
+ internal.push(...iterate(importer)(child));
92
+ output.push(
93
+ ts.factory.createModuleDeclaration(
94
+ [ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],
95
+ ts.factory.createIdentifier(modulo.name),
96
+ ts.factory.createModuleBlock(internal),
97
+ ts.NodeFlags.Namespace,
98
+ ),
99
+ );
100
+ }
101
+ return output;
102
+ };
103
+ }