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