@nestia/migrate 11.0.0-dev.20260316 → 11.0.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 (39) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +93 -93
  3. package/lib/NestiaMigrateApplication.js +341 -341
  4. package/lib/bundles/NEST_TEMPLATE.js +48 -48
  5. package/lib/bundles/NEST_TEMPLATE.js.map +1 -1
  6. package/lib/bundles/SDK_TEMPLATE.js +21 -21
  7. package/lib/bundles/SDK_TEMPLATE.js.map +1 -1
  8. package/lib/index.mjs +469 -469
  9. package/lib/index.mjs.map +1 -1
  10. package/package.json +5 -5
  11. package/src/NestiaMigrateApplication.ts +168 -168
  12. package/src/analyzers/NestiaMigrateControllerAnalyzer.ts +51 -51
  13. package/src/bundles/NEST_TEMPLATE.ts +48 -48
  14. package/src/bundles/SDK_TEMPLATE.ts +21 -21
  15. package/src/executable/NestiaMigrateCommander.ts +104 -104
  16. package/src/executable/NestiaMigrateInquirer.ts +106 -106
  17. package/src/executable/bundle.js +125 -125
  18. package/src/factories/TypeLiteralFactory.ts +57 -57
  19. package/src/module.ts +7 -7
  20. package/src/programmers/NestiaMigrateApiFileProgrammer.ts +55 -55
  21. package/src/programmers/NestiaMigrateApiFunctionProgrammer.ts +347 -347
  22. package/src/programmers/NestiaMigrateApiNamespaceProgrammer.ts +517 -517
  23. package/src/programmers/NestiaMigrateApiSimulationProgrammer.ts +308 -308
  24. package/src/programmers/NestiaMigrateApiStartProgrammer.ts +197 -197
  25. package/src/programmers/NestiaMigrateDtoProgrammer.ts +98 -98
  26. package/src/programmers/NestiaMigrateE2eFileProgrammer.ts +153 -153
  27. package/src/programmers/NestiaMigrateE2eProgrammer.ts +48 -48
  28. package/src/programmers/NestiaMigrateImportProgrammer.ts +118 -118
  29. package/src/programmers/NestiaMigrateNestControllerProgrammer.ts +69 -69
  30. package/src/programmers/NestiaMigrateNestMethodProgrammer.ts +409 -409
  31. package/src/programmers/NestiaMigrateSchemaProgrammer.ts +465 -465
  32. package/src/programmers/index.ts +15 -15
  33. package/src/structures/INestiaMigrateContext.ts +9 -9
  34. package/src/structures/INestiaMigrateController.ts +8 -8
  35. package/src/structures/INestiaMigrateDto.ts +8 -8
  36. package/src/structures/INestiaMigrateProgram.ts +11 -11
  37. package/src/structures/index.ts +4 -4
  38. package/src/utils/FilePrinter.ts +49 -49
  39. package/src/utils/StringUtil.ts +114 -114
@@ -1,197 +1,197 @@
1
- import { IdentifierFactory, StatementFactory } from "@typia/core";
2
- import { IHttpMigrateRoute } from "@typia/interface";
3
- import ts from "typescript";
4
-
5
- import { INestiaMigrateContext } from "../structures/INestiaMigrateContext";
6
- import { FilePrinter } from "../utils/FilePrinter";
7
- import { NestiaMigrateE2eFunctionProgrammer } from "./NestiaMigrateE2eFileProgrammer";
8
- import { NestiaMigrateImportProgrammer } from "./NestiaMigrateImportProgrammer";
9
-
10
- export namespace NestiaMigrateApiStartProgrammer {
11
- export const write = (
12
- context: INestiaMigrateContext,
13
- ): Record<string, string> => {
14
- const importer: NestiaMigrateImportProgrammer =
15
- new NestiaMigrateImportProgrammer();
16
- const main: ts.VariableStatement = writeMain(
17
- context,
18
- importer,
19
- pick(context.application.routes),
20
- );
21
- const statements: ts.Statement[] = [
22
- ...importer.toStatements(
23
- (name) => `@ORGANIZATION/PROJECT-api/lib/structures/${name}`,
24
- ),
25
- FilePrinter.newLine(),
26
- ts.factory.createImportDeclaration(
27
- undefined,
28
- ts.factory.createImportClause(
29
- false,
30
- undefined,
31
- ts.factory.createNamedImports([
32
- ts.factory.createImportSpecifier(
33
- false,
34
- undefined,
35
- ts.factory.createIdentifier("TestGlobal"),
36
- ),
37
- ]),
38
- ),
39
- ts.factory.createStringLiteral("./TestGlobal"),
40
- undefined,
41
- ),
42
- FilePrinter.newLine(),
43
- main,
44
- ts.factory.createExpressionStatement(writeStarter()),
45
- ];
46
- return {
47
- "test/start.ts": FilePrinter.write({ statements }),
48
- };
49
- };
50
-
51
- const writeMain = (
52
- ctx: INestiaMigrateContext,
53
- importer: NestiaMigrateImportProgrammer,
54
- route: IHttpMigrateRoute,
55
- ): ts.VariableStatement =>
56
- StatementFactory.constant({
57
- name: "main",
58
- value: ts.factory.createArrowFunction(
59
- [ts.factory.createToken(ts.SyntaxKind.AsyncKeyword)],
60
- undefined,
61
- [],
62
- undefined,
63
- undefined,
64
- ts.factory.createBlock(
65
- [
66
- writeConnection(ctx, importer),
67
- ...NestiaMigrateE2eFunctionProgrammer.writeBody({
68
- config: ctx.config,
69
- components: ctx.application.document().components,
70
- importer,
71
- route,
72
- }),
73
- ],
74
- true,
75
- ),
76
- ),
77
- });
78
-
79
- const writeConnection = (
80
- ctx: INestiaMigrateContext,
81
- importer: NestiaMigrateImportProgrammer,
82
- ): ts.VariableStatement =>
83
- ts.factory.createVariableStatement(
84
- undefined,
85
- ts.factory.createVariableDeclarationList(
86
- [
87
- ts.factory.createVariableDeclaration(
88
- "connection",
89
- undefined,
90
- ts.factory.createTypeReferenceNode(
91
- ts.factory.createQualifiedName(
92
- ts.factory.createIdentifier(
93
- importer.external({
94
- type: "default",
95
- library: "@ORGANIZATION/PROJECT-api",
96
- name: "api",
97
- }),
98
- ),
99
- ts.factory.createIdentifier("IConnection"),
100
- ),
101
- ),
102
- ts.factory.createObjectLiteralExpression(
103
- [
104
- ts.factory.createSpreadAssignment(
105
- ts.factory.createCallExpression(
106
- ts.factory.createPropertyAccessExpression(
107
- ts.factory.createIdentifier("TestGlobal"),
108
- "connection",
109
- ),
110
- undefined,
111
- undefined,
112
- ),
113
- ),
114
- ...(ctx.application.document().servers?.[0]?.url?.length
115
- ? [
116
- ts.factory.createPropertyAssignment(
117
- "host",
118
- ts.factory.createStringLiteral(
119
- ctx.application.document().servers![0]!.url,
120
- ),
121
- ),
122
- ]
123
- : []),
124
- ...(ctx.config.simulate === true
125
- ? [
126
- ts.factory.createPropertyAssignment(
127
- "simulate",
128
- ts.factory.createTrue(),
129
- ),
130
- ]
131
- : []),
132
- ],
133
- true,
134
- ),
135
- ),
136
- ],
137
- ts.NodeFlags.Const,
138
- ),
139
- );
140
-
141
- const writeStarter = (): ts.CallExpression =>
142
- ts.factory.createCallExpression(
143
- ts.factory.createPropertyAccessExpression(
144
- ts.factory.createCallExpression(
145
- ts.factory.createIdentifier("main"),
146
- undefined,
147
- undefined,
148
- ),
149
- "catch",
150
- ),
151
- undefined,
152
- [
153
- ts.factory.createArrowFunction(
154
- undefined,
155
- undefined,
156
- [IdentifierFactory.parameter("exp")],
157
- undefined,
158
- undefined,
159
- ts.factory.createBlock(
160
- [
161
- ts.factory.createExpressionStatement(
162
- ts.factory.createCallExpression(
163
- ts.factory.createPropertyAccessExpression(
164
- ts.factory.createIdentifier("console"),
165
- "log",
166
- ),
167
- undefined,
168
- [ts.factory.createIdentifier("exp")],
169
- ),
170
- ),
171
- ts.factory.createExpressionStatement(
172
- ts.factory.createCallExpression(
173
- ts.factory.createPropertyAccessExpression(
174
- ts.factory.createIdentifier("process"),
175
- "exit",
176
- ),
177
- undefined,
178
- [
179
- ts.factory.createPrefixMinus(
180
- ts.factory.createNumericLiteral("1"),
181
- ),
182
- ],
183
- ),
184
- ),
185
- ],
186
- true,
187
- ),
188
- ),
189
- ],
190
- );
191
- }
192
-
193
- const pick = <T>(array: T[]): T => {
194
- const rand: number = Math.random() * array.length;
195
- const index: number = Math.min(array.length - 1, Math.floor(rand));
196
- return array[index]!;
197
- };
1
+ import { IdentifierFactory, StatementFactory } from "@typia/core";
2
+ import { IHttpMigrateRoute } from "@typia/interface";
3
+ import ts from "typescript";
4
+
5
+ import { INestiaMigrateContext } from "../structures/INestiaMigrateContext";
6
+ import { FilePrinter } from "../utils/FilePrinter";
7
+ import { NestiaMigrateE2eFunctionProgrammer } from "./NestiaMigrateE2eFileProgrammer";
8
+ import { NestiaMigrateImportProgrammer } from "./NestiaMigrateImportProgrammer";
9
+
10
+ export namespace NestiaMigrateApiStartProgrammer {
11
+ export const write = (
12
+ context: INestiaMigrateContext,
13
+ ): Record<string, string> => {
14
+ const importer: NestiaMigrateImportProgrammer =
15
+ new NestiaMigrateImportProgrammer();
16
+ const main: ts.VariableStatement = writeMain(
17
+ context,
18
+ importer,
19
+ pick(context.application.routes),
20
+ );
21
+ const statements: ts.Statement[] = [
22
+ ...importer.toStatements(
23
+ (name) => `@ORGANIZATION/PROJECT-api/lib/structures/${name}`,
24
+ ),
25
+ FilePrinter.newLine(),
26
+ ts.factory.createImportDeclaration(
27
+ undefined,
28
+ ts.factory.createImportClause(
29
+ false,
30
+ undefined,
31
+ ts.factory.createNamedImports([
32
+ ts.factory.createImportSpecifier(
33
+ false,
34
+ undefined,
35
+ ts.factory.createIdentifier("TestGlobal"),
36
+ ),
37
+ ]),
38
+ ),
39
+ ts.factory.createStringLiteral("./TestGlobal"),
40
+ undefined,
41
+ ),
42
+ FilePrinter.newLine(),
43
+ main,
44
+ ts.factory.createExpressionStatement(writeStarter()),
45
+ ];
46
+ return {
47
+ "test/start.ts": FilePrinter.write({ statements }),
48
+ };
49
+ };
50
+
51
+ const writeMain = (
52
+ ctx: INestiaMigrateContext,
53
+ importer: NestiaMigrateImportProgrammer,
54
+ route: IHttpMigrateRoute,
55
+ ): ts.VariableStatement =>
56
+ StatementFactory.constant({
57
+ name: "main",
58
+ value: ts.factory.createArrowFunction(
59
+ [ts.factory.createToken(ts.SyntaxKind.AsyncKeyword)],
60
+ undefined,
61
+ [],
62
+ undefined,
63
+ undefined,
64
+ ts.factory.createBlock(
65
+ [
66
+ writeConnection(ctx, importer),
67
+ ...NestiaMigrateE2eFunctionProgrammer.writeBody({
68
+ config: ctx.config,
69
+ components: ctx.application.document().components,
70
+ importer,
71
+ route,
72
+ }),
73
+ ],
74
+ true,
75
+ ),
76
+ ),
77
+ });
78
+
79
+ const writeConnection = (
80
+ ctx: INestiaMigrateContext,
81
+ importer: NestiaMigrateImportProgrammer,
82
+ ): ts.VariableStatement =>
83
+ ts.factory.createVariableStatement(
84
+ undefined,
85
+ ts.factory.createVariableDeclarationList(
86
+ [
87
+ ts.factory.createVariableDeclaration(
88
+ "connection",
89
+ undefined,
90
+ ts.factory.createTypeReferenceNode(
91
+ ts.factory.createQualifiedName(
92
+ ts.factory.createIdentifier(
93
+ importer.external({
94
+ type: "default",
95
+ library: "@ORGANIZATION/PROJECT-api",
96
+ name: "api",
97
+ }),
98
+ ),
99
+ ts.factory.createIdentifier("IConnection"),
100
+ ),
101
+ ),
102
+ ts.factory.createObjectLiteralExpression(
103
+ [
104
+ ts.factory.createSpreadAssignment(
105
+ ts.factory.createCallExpression(
106
+ ts.factory.createPropertyAccessExpression(
107
+ ts.factory.createIdentifier("TestGlobal"),
108
+ "connection",
109
+ ),
110
+ undefined,
111
+ undefined,
112
+ ),
113
+ ),
114
+ ...(ctx.application.document().servers?.[0]?.url?.length
115
+ ? [
116
+ ts.factory.createPropertyAssignment(
117
+ "host",
118
+ ts.factory.createStringLiteral(
119
+ ctx.application.document().servers![0]!.url,
120
+ ),
121
+ ),
122
+ ]
123
+ : []),
124
+ ...(ctx.config.simulate === true
125
+ ? [
126
+ ts.factory.createPropertyAssignment(
127
+ "simulate",
128
+ ts.factory.createTrue(),
129
+ ),
130
+ ]
131
+ : []),
132
+ ],
133
+ true,
134
+ ),
135
+ ),
136
+ ],
137
+ ts.NodeFlags.Const,
138
+ ),
139
+ );
140
+
141
+ const writeStarter = (): ts.CallExpression =>
142
+ ts.factory.createCallExpression(
143
+ ts.factory.createPropertyAccessExpression(
144
+ ts.factory.createCallExpression(
145
+ ts.factory.createIdentifier("main"),
146
+ undefined,
147
+ undefined,
148
+ ),
149
+ "catch",
150
+ ),
151
+ undefined,
152
+ [
153
+ ts.factory.createArrowFunction(
154
+ undefined,
155
+ undefined,
156
+ [IdentifierFactory.parameter("exp")],
157
+ undefined,
158
+ undefined,
159
+ ts.factory.createBlock(
160
+ [
161
+ ts.factory.createExpressionStatement(
162
+ ts.factory.createCallExpression(
163
+ ts.factory.createPropertyAccessExpression(
164
+ ts.factory.createIdentifier("console"),
165
+ "log",
166
+ ),
167
+ undefined,
168
+ [ts.factory.createIdentifier("exp")],
169
+ ),
170
+ ),
171
+ ts.factory.createExpressionStatement(
172
+ ts.factory.createCallExpression(
173
+ ts.factory.createPropertyAccessExpression(
174
+ ts.factory.createIdentifier("process"),
175
+ "exit",
176
+ ),
177
+ undefined,
178
+ [
179
+ ts.factory.createPrefixMinus(
180
+ ts.factory.createNumericLiteral("1"),
181
+ ),
182
+ ],
183
+ ),
184
+ ),
185
+ ],
186
+ true,
187
+ ),
188
+ ),
189
+ ],
190
+ );
191
+ }
192
+
193
+ const pick = <T>(array: T[]): T => {
194
+ const rand: number = Math.random() * array.length;
195
+ const index: number = Math.min(array.length - 1, Math.floor(rand));
196
+ return array[index]!;
197
+ };
@@ -1,98 +1,98 @@
1
- import { OpenApi } from "@typia/interface";
2
- import { IPointer } from "tstl";
3
- import ts from "typescript";
4
-
5
- import { INestiaMigrateConfig } from "../structures/INestiaMigrateConfig";
6
- import { FilePrinter } from "../utils/FilePrinter";
7
- import { MapUtil } from "../utils/MapUtil";
8
- import { StringUtil } from "../utils/StringUtil";
9
- import { NestiaMigrateImportProgrammer } from "./NestiaMigrateImportProgrammer";
10
- import { NestiaMigrateSchemaProgrammer } from "./NestiaMigrateSchemaProgrammer";
11
-
12
- export namespace NestiaMigrateDtoProgrammer {
13
- export interface IModule {
14
- name: string;
15
- children: Map<string, IModule>;
16
- programmer:
17
- | null
18
- | ((importer: NestiaMigrateImportProgrammer) => ts.TypeAliasDeclaration);
19
- }
20
-
21
- export const compose = (props: {
22
- config: INestiaMigrateConfig;
23
- components: OpenApi.IComponents;
24
- }): Map<string, IModule> => {
25
- const dict: Map<string, IModule> = new Map();
26
- for (const [key, value] of Object.entries(props.components.schemas ?? {})) {
27
- const emendedKey: string = key
28
- .split("/")
29
- .filter((str) => str.length !== 0)
30
- .map(StringUtil.escapeNonVariable)
31
- .join("");
32
- prepare(dict)(emendedKey)((importer) =>
33
- writeAlias(props.config)(props.components)(importer)(emendedKey, value),
34
- );
35
- }
36
- return dict;
37
- };
38
-
39
- const prepare =
40
- (dict: Map<string, IModule>) =>
41
- (name: string) =>
42
- (
43
- programmer: (
44
- importer: NestiaMigrateImportProgrammer,
45
- ) => ts.TypeAliasDeclaration,
46
- ) => {
47
- const accessors: string[] = name.split(".");
48
- const modulo: IPointer<IModule> = { value: null! };
49
-
50
- accessors.forEach((acc, i) => {
51
- modulo.value = MapUtil.take(dict)(acc)(() => ({
52
- name: acc,
53
- children: new Map(),
54
- programmer: null,
55
- }));
56
- if (i === accessors.length - 1) modulo.value.programmer = programmer;
57
- dict = modulo.value.children;
58
- });
59
- return modulo!;
60
- };
61
-
62
- const writeAlias =
63
- (config: INestiaMigrateConfig) =>
64
- (components: OpenApi.IComponents) =>
65
- (importer: NestiaMigrateImportProgrammer) =>
66
- (key: string, value: OpenApi.IJsonSchema) =>
67
- FilePrinter.description(
68
- ts.factory.createTypeAliasDeclaration(
69
- [ts.factory.createToken(ts.SyntaxKind.ExportKeyword)],
70
- key.split(".").at(-1)!,
71
- [],
72
- NestiaMigrateSchemaProgrammer.write({
73
- components,
74
- importer,
75
- schema: value,
76
- }),
77
- ),
78
- writeComment(config)(value, key.indexOf(".") === -1),
79
- );
80
- }
81
-
82
- const writeComment =
83
- (config: INestiaMigrateConfig) =>
84
- (schema: OpenApi.IJsonSchema, top: boolean): string =>
85
- [
86
- ...(schema.description?.length ? [schema.description] : []),
87
- ...(schema.description?.length &&
88
- (schema.title !== undefined || schema.deprecated === true)
89
- ? [""]
90
- : []),
91
- ...(schema.title !== undefined ? [`@title ${schema.title}`] : []),
92
- ...(schema.deprecated === true ? [`@deprecated`] : []),
93
- ...(top
94
- ? [
95
- `@${config.author?.tag ?? "nestia"} ${config.author?.value ?? "Generated by Nestia - https://github.com/samchon/nestia"}`,
96
- ]
97
- : []),
98
- ].join("\n");
1
+ import { OpenApi } from "@typia/interface";
2
+ import { IPointer } from "tstl";
3
+ import ts from "typescript";
4
+
5
+ import { INestiaMigrateConfig } from "../structures/INestiaMigrateConfig";
6
+ import { FilePrinter } from "../utils/FilePrinter";
7
+ import { MapUtil } from "../utils/MapUtil";
8
+ import { StringUtil } from "../utils/StringUtil";
9
+ import { NestiaMigrateImportProgrammer } from "./NestiaMigrateImportProgrammer";
10
+ import { NestiaMigrateSchemaProgrammer } from "./NestiaMigrateSchemaProgrammer";
11
+
12
+ export namespace NestiaMigrateDtoProgrammer {
13
+ export interface IModule {
14
+ name: string;
15
+ children: Map<string, IModule>;
16
+ programmer:
17
+ | null
18
+ | ((importer: NestiaMigrateImportProgrammer) => ts.TypeAliasDeclaration);
19
+ }
20
+
21
+ export const compose = (props: {
22
+ config: INestiaMigrateConfig;
23
+ components: OpenApi.IComponents;
24
+ }): Map<string, IModule> => {
25
+ const dict: Map<string, IModule> = new Map();
26
+ for (const [key, value] of Object.entries(props.components.schemas ?? {})) {
27
+ const emendedKey: string = key
28
+ .split("/")
29
+ .filter((str) => str.length !== 0)
30
+ .map(StringUtil.escapeNonVariable)
31
+ .join("");
32
+ prepare(dict)(emendedKey)((importer) =>
33
+ writeAlias(props.config)(props.components)(importer)(emendedKey, value),
34
+ );
35
+ }
36
+ return dict;
37
+ };
38
+
39
+ const prepare =
40
+ (dict: Map<string, IModule>) =>
41
+ (name: string) =>
42
+ (
43
+ programmer: (
44
+ importer: NestiaMigrateImportProgrammer,
45
+ ) => ts.TypeAliasDeclaration,
46
+ ) => {
47
+ const accessors: string[] = name.split(".");
48
+ const modulo: IPointer<IModule> = { value: null! };
49
+
50
+ accessors.forEach((acc, i) => {
51
+ modulo.value = MapUtil.take(dict)(acc)(() => ({
52
+ name: acc,
53
+ children: new Map(),
54
+ programmer: null,
55
+ }));
56
+ if (i === accessors.length - 1) modulo.value.programmer = programmer;
57
+ dict = modulo.value.children;
58
+ });
59
+ return modulo!;
60
+ };
61
+
62
+ const writeAlias =
63
+ (config: INestiaMigrateConfig) =>
64
+ (components: OpenApi.IComponents) =>
65
+ (importer: NestiaMigrateImportProgrammer) =>
66
+ (key: string, value: OpenApi.IJsonSchema) =>
67
+ FilePrinter.description(
68
+ ts.factory.createTypeAliasDeclaration(
69
+ [ts.factory.createToken(ts.SyntaxKind.ExportKeyword)],
70
+ key.split(".").at(-1)!,
71
+ [],
72
+ NestiaMigrateSchemaProgrammer.write({
73
+ components,
74
+ importer,
75
+ schema: value,
76
+ }),
77
+ ),
78
+ writeComment(config)(value, key.indexOf(".") === -1),
79
+ );
80
+ }
81
+
82
+ const writeComment =
83
+ (config: INestiaMigrateConfig) =>
84
+ (schema: OpenApi.IJsonSchema, top: boolean): string =>
85
+ [
86
+ ...(schema.description?.length ? [schema.description] : []),
87
+ ...(schema.description?.length &&
88
+ (schema.title !== undefined || schema.deprecated === true)
89
+ ? [""]
90
+ : []),
91
+ ...(schema.title !== undefined ? [`@title ${schema.title}`] : []),
92
+ ...(schema.deprecated === true ? [`@deprecated`] : []),
93
+ ...(top
94
+ ? [
95
+ `@${config.author?.tag ?? "nestia"} ${config.author?.value ?? "Generated by Nestia - https://github.com/samchon/nestia"}`,
96
+ ]
97
+ : []),
98
+ ].join("\n");