@nestia/migrate 6.0.6 → 7.0.0-dev.20250605
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/NestiaMigrateApplication.d.ts +23 -0
- package/lib/NestiaMigrateApplication.js +17522 -0
- package/lib/NestiaMigrateApplication.js.map +1 -0
- package/lib/analyzers/NestiaMigrateControllerAnalyzer.d.ts +5 -0
- package/lib/analyzers/{MigrateControllerAnalyzer.js → NestiaMigrateControllerAnalyzer.js} +10 -10
- package/lib/analyzers/NestiaMigrateControllerAnalyzer.js.map +1 -0
- package/lib/archivers/NestiaMigrateFileArchiver.d.ts +8 -0
- package/lib/archivers/NestiaMigrateFileArchiver.js +36 -0
- package/lib/archivers/NestiaMigrateFileArchiver.js.map +1 -0
- package/lib/bundles/NEST_TEMPLATE.d.ts +1 -5
- package/lib/bundles/NEST_TEMPLATE.js +50 -242
- package/lib/bundles/NEST_TEMPLATE.js.map +1 -1
- package/lib/bundles/SDK_TEMPLATE.d.ts +1 -5
- package/lib/bundles/SDK_TEMPLATE.js +23 -107
- package/lib/bundles/SDK_TEMPLATE.js.map +1 -1
- package/lib/{internal/MigrateCommander.d.ts → executable/NestiaMigrateCommander.d.ts} +1 -1
- package/lib/{internal/MigrateCommander.js → executable/NestiaMigrateCommander.js} +23 -21
- package/lib/executable/NestiaMigrateCommander.js.map +1 -0
- package/lib/{internal/MigrateInquirer.d.ts → executable/NestiaMigrateInquirer.d.ts} +2 -1
- package/lib/{internal/MigrateInquirer.js → executable/NestiaMigrateInquirer.js} +22 -9
- package/lib/executable/NestiaMigrateInquirer.js.map +1 -0
- package/lib/executable/migrate.js +2 -2
- package/lib/executable/migrate.js.map +1 -1
- package/lib/index.mjs +10041 -693
- package/lib/index.mjs.map +1 -1
- package/lib/module.d.ts +2 -5
- package/lib/module.js +2 -5
- package/lib/module.js.map +1 -1
- package/lib/programmers/NestiaMigrateApiFileProgrammer.d.ts +13 -0
- package/lib/programmers/NestiaMigrateApiFileProgrammer.js +40 -0
- package/lib/programmers/NestiaMigrateApiFileProgrammer.js.map +1 -0
- package/lib/programmers/NestiaMigrateApiFunctionProgrammer.d.ts +14 -0
- package/lib/programmers/NestiaMigrateApiFunctionProgrammer.js +132 -0
- package/lib/programmers/NestiaMigrateApiFunctionProgrammer.js.map +1 -0
- package/lib/programmers/NestiaMigrateApiNamespaceProgrammer.d.ts +14 -0
- package/lib/programmers/NestiaMigrateApiNamespaceProgrammer.js +237 -0
- package/lib/programmers/NestiaMigrateApiNamespaceProgrammer.js.map +1 -0
- package/lib/programmers/NestiaMigrateApiProgrammer.d.ts +4 -0
- package/lib/programmers/{MigrateApiProgrammer.js → NestiaMigrateApiProgrammer.js} +31 -30
- package/lib/programmers/NestiaMigrateApiProgrammer.js.map +1 -0
- package/lib/programmers/NestiaMigrateApiSimulationProgrammer.d.ts +14 -0
- package/lib/programmers/{MigrateApiSimulationProgrammer.js → NestiaMigrateApiSimulationProgrammer.js} +54 -36
- package/lib/programmers/NestiaMigrateApiSimulationProgrammer.js.map +1 -0
- package/lib/programmers/NestiaMigrateApiStartProgrammer.d.ts +4 -0
- package/lib/programmers/{MigrateApiStartProgrammer.js → NestiaMigrateApiStartProgrammer.js} +23 -20
- package/lib/programmers/NestiaMigrateApiStartProgrammer.js.map +1 -0
- package/lib/programmers/NestiaMigrateDtoProgrammer.d.ts +15 -0
- package/lib/programmers/{MigrateDtoProgrammer.js → NestiaMigrateDtoProgrammer.js} +14 -10
- package/lib/programmers/NestiaMigrateDtoProgrammer.js.map +1 -0
- package/lib/programmers/NestiaMigrateE2eFileProgrammer.d.ts +14 -0
- package/lib/programmers/NestiaMigrateE2eFileProgrammer.js +81 -0
- package/lib/programmers/NestiaMigrateE2eFileProgrammer.js.map +1 -0
- package/lib/programmers/NestiaMigrateE2eProgrammer.d.ts +4 -0
- package/lib/programmers/NestiaMigrateE2eProgrammer.js +32 -0
- package/lib/programmers/NestiaMigrateE2eProgrammer.js.map +1 -0
- package/lib/programmers/{MigrateImportProgrammer.d.ts → NestiaMigrateImportProgrammer.d.ts} +1 -1
- package/lib/programmers/{MigrateImportProgrammer.js → NestiaMigrateImportProgrammer.js} +4 -4
- package/lib/programmers/NestiaMigrateImportProgrammer.js.map +1 -0
- package/lib/programmers/NestiaMigrateNestControllerProgrammer.d.ts +12 -0
- package/lib/programmers/{MigrateNestControllerProgrammer.js → NestiaMigrateNestControllerProgrammer.js} +20 -13
- package/lib/programmers/NestiaMigrateNestControllerProgrammer.js.map +1 -0
- package/lib/programmers/NestiaMigrateNestMethodProgrammer.d.ts +15 -0
- package/lib/programmers/{MigrateNestMethodProgrammer.js → NestiaMigrateNestMethodProgrammer.js} +85 -69
- package/lib/programmers/NestiaMigrateNestMethodProgrammer.js.map +1 -0
- package/lib/programmers/NestiaMigrateNestModuleProgrammer.d.ts +5 -0
- package/lib/programmers/{MigrateNestModuleProgrammer.js → NestiaMigrateNestModuleProgrammer.js} +6 -6
- package/lib/programmers/NestiaMigrateNestModuleProgrammer.js.map +1 -0
- package/lib/programmers/NestiaMigrateNestProgrammer.d.ts +4 -0
- package/lib/programmers/NestiaMigrateNestProgrammer.js +65 -0
- package/lib/programmers/NestiaMigrateNestProgrammer.js.map +1 -0
- package/lib/programmers/NestiaMigrateSchemaProgrammer.d.ts +10 -0
- package/lib/programmers/NestiaMigrateSchemaProgrammer.js +414 -0
- package/lib/programmers/NestiaMigrateSchemaProgrammer.js.map +1 -0
- package/lib/structures/INestiaMigrateConfig.d.ts +10 -0
- package/lib/structures/{IHttpMigrateFile.js → INestiaMigrateConfig.js} +1 -1
- package/lib/structures/INestiaMigrateConfig.js.map +1 -0
- package/lib/structures/INestiaMigrateContext.d.ts +9 -0
- package/lib/structures/INestiaMigrateContext.js +3 -0
- package/lib/structures/INestiaMigrateContext.js.map +1 -0
- package/lib/structures/INestiaMigrateController.d.ts +7 -0
- package/lib/structures/{IHttpMigrateController.js → INestiaMigrateController.js} +1 -1
- package/lib/structures/INestiaMigrateController.js.map +1 -0
- package/lib/structures/{IHttpMigrateDto.d.ts → INestiaMigrateDto.d.ts} +2 -2
- package/lib/structures/{IHttpMigrateRoute.js → INestiaMigrateDto.js} +1 -1
- package/lib/structures/INestiaMigrateDto.js.map +1 -0
- package/lib/structures/{IHttpMigrateFile.d.ts → INestiaMigrateFile.d.ts} +1 -1
- package/lib/structures/{IHttpMigrateDto.js → INestiaMigrateFile.js} +1 -1
- package/lib/structures/INestiaMigrateFile.js.map +1 -0
- package/lib/structures/INestiaMigrateProgram.d.ts +9 -0
- package/lib/structures/INestiaMigrateProgram.js +3 -0
- package/lib/structures/INestiaMigrateProgram.js.map +1 -0
- package/lib/structures/INestiaMigrateSchema.d.ts +4 -0
- package/lib/structures/{IHttpMigrateProgram.js → INestiaMigrateSchema.js} +1 -1
- package/lib/structures/INestiaMigrateSchema.js.map +1 -0
- package/lib/utils/openapi-down-convert/converter.js +2 -2
- package/package.json +8 -8
- package/src/NestiaMigrateApplication.ts +144 -0
- package/src/analyzers/{MigrateControllerAnalyzer.ts → NestiaMigrateControllerAnalyzer.ts} +51 -51
- package/src/archivers/NestiaMigrateFileArchiver.ts +28 -0
- package/src/bundles/NEST_TEMPLATE.ts +50 -242
- package/src/bundles/SDK_TEMPLATE.ts +23 -107
- package/src/{internal/MigrateCommander.ts → executable/NestiaMigrateCommander.ts} +98 -94
- package/src/{internal/MigrateInquirer.ts → executable/NestiaMigrateInquirer.ts} +106 -89
- package/src/executable/bundle.js +129 -127
- 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 -8
- package/src/programmers/NestiaMigrateApiFileProgrammer.ts +55 -0
- package/src/programmers/NestiaMigrateApiFunctionProgrammer.ts +256 -0
- package/src/programmers/NestiaMigrateApiNamespaceProgrammer.ts +524 -0
- package/src/programmers/NestiaMigrateApiProgrammer.ts +107 -0
- package/src/programmers/NestiaMigrateApiSimulationProgrammer.ts +340 -0
- package/src/programmers/NestiaMigrateApiStartProgrammer.ts +198 -0
- package/src/programmers/{MigrateDtoProgrammer.ts → NestiaMigrateDtoProgrammer.ts} +101 -96
- package/src/programmers/NestiaMigrateE2eFileProgrammer.ts +153 -0
- package/src/programmers/NestiaMigrateE2eProgrammer.ts +46 -0
- package/src/programmers/{MigrateImportProgrammer.ts → NestiaMigrateImportProgrammer.ts} +118 -118
- package/src/programmers/NestiaMigrateNestControllerProgrammer.ts +66 -0
- package/src/programmers/NestiaMigrateNestMethodProgrammer.ts +406 -0
- package/src/programmers/{MigrateNestModuleProgrammer.ts → NestiaMigrateNestModuleProgrammer.ts} +65 -65
- package/src/programmers/NestiaMigrateNestProgrammer.ts +88 -0
- package/src/programmers/NestiaMigrateSchemaProgrammer.ts +475 -0
- package/src/structures/INestiaMigrateConfig.ts +10 -0
- package/src/structures/INestiaMigrateContext.ts +15 -0
- package/src/structures/INestiaMigrateController.ts +8 -0
- package/src/structures/{IHttpMigrateDto.ts → INestiaMigrateDto.ts} +8 -8
- package/src/structures/{IHttpMigrateFile.ts → INestiaMigrateFile.ts} +5 -5
- package/src/structures/INestiaMigrateProgram.ts +11 -0
- package/src/structures/INestiaMigrateSchema.ts +4 -0
- 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
- package/lib/MigrateApplication.d.ts +0 -28
- package/lib/MigrateApplication.js +0 -7994
- package/lib/MigrateApplication.js.map +0 -1
- package/lib/analyzers/MigrateApplicationAnalyzer.d.ts +0 -4
- package/lib/analyzers/MigrateApplicationAnalyzer.js +0 -12
- package/lib/analyzers/MigrateApplicationAnalyzer.js.map +0 -1
- package/lib/analyzers/MigrateControllerAnalyzer.d.ts +0 -7
- package/lib/analyzers/MigrateControllerAnalyzer.js.map +0 -1
- package/lib/archivers/MigrateFileArchiver.d.ts +0 -8
- package/lib/archivers/MigrateFileArchiver.js +0 -35
- package/lib/archivers/MigrateFileArchiver.js.map +0 -1
- package/lib/internal/MigrateCommander.js.map +0 -1
- package/lib/internal/MigrateInquirer.js.map +0 -1
- package/lib/programmers/MigrateApiFileProgrammer.d.ts +0 -11
- package/lib/programmers/MigrateApiFileProgrammer.js +0 -30
- package/lib/programmers/MigrateApiFileProgrammer.js.map +0 -1
- package/lib/programmers/MigrateApiFunctionProgrammer.d.ts +0 -9
- package/lib/programmers/MigrateApiFunctionProgrammer.js +0 -102
- package/lib/programmers/MigrateApiFunctionProgrammer.js.map +0 -1
- package/lib/programmers/MigrateApiNamespaceProgrammer.d.ts +0 -9
- package/lib/programmers/MigrateApiNamespaceProgrammer.js +0 -142
- package/lib/programmers/MigrateApiNamespaceProgrammer.js.map +0 -1
- package/lib/programmers/MigrateApiProgrammer.d.ts +0 -5
- package/lib/programmers/MigrateApiProgrammer.js.map +0 -1
- package/lib/programmers/MigrateApiSimulationProgrammer.d.ts +0 -8
- package/lib/programmers/MigrateApiSimulationProgrammer.js.map +0 -1
- package/lib/programmers/MigrateApiStartProgrammer.d.ts +0 -5
- package/lib/programmers/MigrateApiStartProgrammer.js.map +0 -1
- package/lib/programmers/MigrateDtoProgrammer.d.ts +0 -12
- package/lib/programmers/MigrateDtoProgrammer.js.map +0 -1
- package/lib/programmers/MigrateE2eFileProgrammer.d.ts +0 -8
- package/lib/programmers/MigrateE2eFileProgrammer.js +0 -45
- package/lib/programmers/MigrateE2eFileProgrammer.js.map +0 -1
- package/lib/programmers/MigrateE2eProgrammer.d.ts +0 -5
- package/lib/programmers/MigrateE2eProgrammer.js +0 -25
- package/lib/programmers/MigrateE2eProgrammer.js.map +0 -1
- package/lib/programmers/MigrateImportProgrammer.js.map +0 -1
- package/lib/programmers/MigrateNestControllerProgrammer.d.ts +0 -7
- package/lib/programmers/MigrateNestControllerProgrammer.js.map +0 -1
- package/lib/programmers/MigrateNestMethodProgrammer.d.ts +0 -9
- package/lib/programmers/MigrateNestMethodProgrammer.js.map +0 -1
- package/lib/programmers/MigrateNestModuleProgrammer.d.ts +0 -5
- package/lib/programmers/MigrateNestModuleProgrammer.js.map +0 -1
- package/lib/programmers/MigrateNestProgrammer.d.ts +0 -5
- package/lib/programmers/MigrateNestProgrammer.js +0 -69
- package/lib/programmers/MigrateNestProgrammer.js.map +0 -1
- package/lib/programmers/MigrateSchemaProgrammer.d.ts +0 -6
- package/lib/programmers/MigrateSchemaProgrammer.js +0 -335
- package/lib/programmers/MigrateSchemaProgrammer.js.map +0 -1
- package/lib/structures/IHttpMigrateController.d.ts +0 -7
- package/lib/structures/IHttpMigrateController.js.map +0 -1
- package/lib/structures/IHttpMigrateDto.js.map +0 -1
- package/lib/structures/IHttpMigrateFile.js.map +0 -1
- package/lib/structures/IHttpMigrateProgram.d.ts +0 -33
- package/lib/structures/IHttpMigrateProgram.js.map +0 -1
- package/lib/structures/IHttpMigrateRoute.d.ts +0 -1
- package/lib/structures/IHttpMigrateRoute.js.map +0 -1
- package/lib/structures/IHttpMigrateSchema.d.ts +0 -4
- package/lib/structures/IHttpMigrateSchema.js +0 -3
- package/lib/structures/IHttpMigrateSchema.js.map +0 -1
- package/src/MigrateApplication.ts +0 -124
- package/src/analyzers/MigrateApplicationAnalyzer.ts +0 -18
- package/src/archivers/MigrateFileArchiver.ts +0 -38
- package/src/programmers/MigrateApiFileProgrammer.ts +0 -51
- package/src/programmers/MigrateApiFunctionProgrammer.ts +0 -213
- package/src/programmers/MigrateApiNamespaceProgrammer.ts +0 -418
- package/src/programmers/MigrateApiProgrammer.ts +0 -104
- package/src/programmers/MigrateApiSimulationProgrammer.ts +0 -324
- package/src/programmers/MigrateApiStartProgrammer.ts +0 -194
- package/src/programmers/MigrateE2eFileProgrammer.ts +0 -117
- package/src/programmers/MigrateE2eProgrammer.ts +0 -34
- package/src/programmers/MigrateNestControllerProgrammer.ts +0 -57
- package/src/programmers/MigrateNestMethodProgrammer.ts +0 -397
- package/src/programmers/MigrateNestProgrammer.ts +0 -84
- package/src/programmers/MigrateSchemaProgrammer.ts +0 -378
- package/src/structures/IHttpMigrateController.ts +0 -8
- package/src/structures/IHttpMigrateProgram.ts +0 -35
- package/src/structures/IHttpMigrateRoute.ts +0 -1
- package/src/structures/IHttpMigrateSchema.ts +0 -4
@@ -0,0 +1,475 @@
|
|
1
|
+
import { OpenApi } from "@samchon/openapi";
|
2
|
+
import ts from "typescript";
|
3
|
+
import typia from "typia";
|
4
|
+
import { TypeFactory } from "typia/lib/factories/TypeFactory";
|
5
|
+
import { FormatCheatSheet } from "typia/lib/tags/internal/FormatCheatSheet";
|
6
|
+
import { Escaper } from "typia/lib/utils/Escaper";
|
7
|
+
|
8
|
+
import { FilePrinter } from "../utils/FilePrinter";
|
9
|
+
import { OpenApiTypeChecker } from "../utils/OpenApiTypeChecker";
|
10
|
+
import { StringUtil } from "../utils/StringUtil";
|
11
|
+
import { NestiaMigrateImportProgrammer } from "./NestiaMigrateImportProgrammer";
|
12
|
+
|
13
|
+
export namespace NestiaMigrateSchemaProgrammer {
|
14
|
+
/* -----------------------------------------------------------
|
15
|
+
FACADE
|
16
|
+
----------------------------------------------------------- */
|
17
|
+
export const write = (props: {
|
18
|
+
components: OpenApi.IComponents;
|
19
|
+
importer: NestiaMigrateImportProgrammer;
|
20
|
+
schema: OpenApi.IJsonSchema;
|
21
|
+
}): ts.TypeNode => {
|
22
|
+
// CONSIDER ANY TYPE CASE
|
23
|
+
const union: ts.TypeNode[] = [];
|
24
|
+
if (OpenApiTypeChecker.isUnknown(props.schema))
|
25
|
+
return TypeFactory.keyword("any");
|
26
|
+
|
27
|
+
// ITERATION
|
28
|
+
const type: ts.TypeNode = (() => {
|
29
|
+
// ATOMIC
|
30
|
+
if (OpenApiTypeChecker.isConstant(props.schema))
|
31
|
+
return writeConstant({
|
32
|
+
importer: props.importer,
|
33
|
+
schema: props.schema,
|
34
|
+
});
|
35
|
+
else if (OpenApiTypeChecker.isBoolean(props.schema))
|
36
|
+
return writeBoolean({
|
37
|
+
importer: props.importer,
|
38
|
+
schema: props.schema,
|
39
|
+
});
|
40
|
+
else if (OpenApiTypeChecker.isInteger(props.schema))
|
41
|
+
return writeInteger({
|
42
|
+
importer: props.importer,
|
43
|
+
schema: props.schema,
|
44
|
+
});
|
45
|
+
else if (OpenApiTypeChecker.isNumber(props.schema))
|
46
|
+
return writeNumber({
|
47
|
+
importer: props.importer,
|
48
|
+
schema: props.schema,
|
49
|
+
});
|
50
|
+
else if (OpenApiTypeChecker.isString(props.schema))
|
51
|
+
return writeString({
|
52
|
+
importer: props.importer,
|
53
|
+
schema: props.schema,
|
54
|
+
});
|
55
|
+
// INSTANCES
|
56
|
+
else if (OpenApiTypeChecker.isArray(props.schema))
|
57
|
+
return writeArray({
|
58
|
+
components: props.components,
|
59
|
+
importer: props.importer,
|
60
|
+
schema: props.schema,
|
61
|
+
});
|
62
|
+
else if (OpenApiTypeChecker.isTuple(props.schema))
|
63
|
+
return writeTuple({
|
64
|
+
components: props.components,
|
65
|
+
importer: props.importer,
|
66
|
+
schema: props.schema,
|
67
|
+
});
|
68
|
+
else if (OpenApiTypeChecker.isObject(props.schema))
|
69
|
+
return writeObject({
|
70
|
+
components: props.components,
|
71
|
+
importer: props.importer,
|
72
|
+
schema: props.schema,
|
73
|
+
});
|
74
|
+
else if (OpenApiTypeChecker.isReference(props.schema))
|
75
|
+
return writeReference({
|
76
|
+
importer: props.importer,
|
77
|
+
schema: props.schema,
|
78
|
+
});
|
79
|
+
// UNION
|
80
|
+
else if (OpenApiTypeChecker.isOneOf(props.schema))
|
81
|
+
return writeUnion({
|
82
|
+
components: props.components,
|
83
|
+
importer: props.importer,
|
84
|
+
elements: props.schema.oneOf,
|
85
|
+
});
|
86
|
+
else if (OpenApiTypeChecker.isNull(props.schema))
|
87
|
+
return createNode("null");
|
88
|
+
else return TypeFactory.keyword("any");
|
89
|
+
})();
|
90
|
+
union.push(type);
|
91
|
+
|
92
|
+
// DETERMINE
|
93
|
+
if (union.length === 0) return TypeFactory.keyword("any");
|
94
|
+
else if (union.length === 1) return union[0];
|
95
|
+
return ts.factory.createUnionTypeNode(union);
|
96
|
+
};
|
97
|
+
|
98
|
+
/* -----------------------------------------------------------
|
99
|
+
ATOMICS
|
100
|
+
----------------------------------------------------------- */
|
101
|
+
const writeConstant = (props: {
|
102
|
+
importer: NestiaMigrateImportProgrammer;
|
103
|
+
schema: OpenApi.IJsonSchema.IConstant;
|
104
|
+
}): ts.TypeNode => {
|
105
|
+
const intersection: ts.TypeNode[] = [
|
106
|
+
ts.factory.createLiteralTypeNode(
|
107
|
+
typeof props.schema.const === "boolean"
|
108
|
+
? props.schema.const === true
|
109
|
+
? ts.factory.createTrue()
|
110
|
+
: ts.factory.createFalse()
|
111
|
+
: typeof props.schema.const === "number"
|
112
|
+
? props.schema.const < 0
|
113
|
+
? ts.factory.createPrefixUnaryExpression(
|
114
|
+
ts.SyntaxKind.MinusToken,
|
115
|
+
ts.factory.createNumericLiteral(-props.schema.const),
|
116
|
+
)
|
117
|
+
: ts.factory.createNumericLiteral(props.schema.const)
|
118
|
+
: ts.factory.createStringLiteral(props.schema.const),
|
119
|
+
),
|
120
|
+
];
|
121
|
+
writePlugin({
|
122
|
+
importer: props.importer,
|
123
|
+
schema: props.schema,
|
124
|
+
regular: typia.misc.literals<keyof OpenApi.IJsonSchema.IConstant>(),
|
125
|
+
intersection,
|
126
|
+
});
|
127
|
+
return intersection.length === 1
|
128
|
+
? intersection[0]
|
129
|
+
: ts.factory.createIntersectionTypeNode(intersection);
|
130
|
+
};
|
131
|
+
|
132
|
+
const writeBoolean = (props: {
|
133
|
+
importer: NestiaMigrateImportProgrammer;
|
134
|
+
schema: OpenApi.IJsonSchema.IBoolean;
|
135
|
+
}): ts.TypeNode => {
|
136
|
+
const intersection: ts.TypeNode[] = [TypeFactory.keyword("boolean")];
|
137
|
+
writePlugin({
|
138
|
+
importer: props.importer,
|
139
|
+
regular: typia.misc.literals<keyof OpenApi.IJsonSchema.IBoolean>(),
|
140
|
+
intersection,
|
141
|
+
schema: props.schema,
|
142
|
+
});
|
143
|
+
return intersection.length === 1
|
144
|
+
? intersection[0]
|
145
|
+
: ts.factory.createIntersectionTypeNode(intersection);
|
146
|
+
};
|
147
|
+
|
148
|
+
const writeInteger = (props: {
|
149
|
+
importer: NestiaMigrateImportProgrammer;
|
150
|
+
schema: OpenApi.IJsonSchema.IInteger;
|
151
|
+
}): ts.TypeNode =>
|
152
|
+
writeNumeric({
|
153
|
+
factory: () => [
|
154
|
+
TypeFactory.keyword("number"),
|
155
|
+
props.importer.tag("Type", "int32"),
|
156
|
+
],
|
157
|
+
importer: props.importer,
|
158
|
+
schema: props.schema,
|
159
|
+
});
|
160
|
+
|
161
|
+
const writeNumber = (props: {
|
162
|
+
importer: NestiaMigrateImportProgrammer;
|
163
|
+
schema: OpenApi.IJsonSchema.INumber;
|
164
|
+
}): ts.TypeNode =>
|
165
|
+
writeNumeric({
|
166
|
+
factory: () => [TypeFactory.keyword("number")],
|
167
|
+
importer: props.importer,
|
168
|
+
schema: props.schema,
|
169
|
+
});
|
170
|
+
|
171
|
+
const writeNumeric = (props: {
|
172
|
+
factory: () => ts.TypeNode[];
|
173
|
+
importer: NestiaMigrateImportProgrammer;
|
174
|
+
schema: OpenApi.IJsonSchema.IInteger | OpenApi.IJsonSchema.INumber;
|
175
|
+
}): ts.TypeNode => {
|
176
|
+
const intersection: ts.TypeNode[] = props.factory();
|
177
|
+
if (props.schema.default !== undefined)
|
178
|
+
intersection.push(props.importer.tag("Default", props.schema.default));
|
179
|
+
if (props.schema.minimum !== undefined)
|
180
|
+
intersection.push(
|
181
|
+
props.importer.tag(
|
182
|
+
props.schema.exclusiveMinimum ? "ExclusiveMinimum" : "Minimum",
|
183
|
+
props.schema.minimum,
|
184
|
+
),
|
185
|
+
);
|
186
|
+
if (props.schema.maximum !== undefined)
|
187
|
+
intersection.push(
|
188
|
+
props.importer.tag(
|
189
|
+
props.schema.exclusiveMaximum ? "ExclusiveMaximum" : "Maximum",
|
190
|
+
props.schema.maximum,
|
191
|
+
),
|
192
|
+
);
|
193
|
+
if (props.schema.multipleOf !== undefined)
|
194
|
+
intersection.push(
|
195
|
+
props.importer.tag("MultipleOf", props.schema.multipleOf),
|
196
|
+
);
|
197
|
+
writePlugin({
|
198
|
+
importer: props.importer,
|
199
|
+
regular: typia.misc.literals<keyof OpenApi.IJsonSchema.INumber>(),
|
200
|
+
intersection,
|
201
|
+
schema: props.schema,
|
202
|
+
});
|
203
|
+
return intersection.length === 1
|
204
|
+
? intersection[0]
|
205
|
+
: ts.factory.createIntersectionTypeNode(intersection);
|
206
|
+
};
|
207
|
+
|
208
|
+
const writeString = (props: {
|
209
|
+
importer: NestiaMigrateImportProgrammer;
|
210
|
+
schema: OpenApi.IJsonSchema.IString;
|
211
|
+
}): ts.TypeNode => {
|
212
|
+
if (props.schema.format === "binary")
|
213
|
+
return ts.factory.createTypeReferenceNode("File");
|
214
|
+
|
215
|
+
const intersection: ts.TypeNode[] = [TypeFactory.keyword("string")];
|
216
|
+
if (props.schema.default !== undefined)
|
217
|
+
intersection.push(props.importer.tag("Default", props.schema.default));
|
218
|
+
if (props.schema.minLength !== undefined)
|
219
|
+
intersection.push(
|
220
|
+
props.importer.tag("MinLength", props.schema.minLength),
|
221
|
+
);
|
222
|
+
if (props.schema.maxLength !== undefined)
|
223
|
+
intersection.push(
|
224
|
+
props.importer.tag("MaxLength", props.schema.maxLength),
|
225
|
+
);
|
226
|
+
if (props.schema.pattern !== undefined)
|
227
|
+
intersection.push(props.importer.tag("Pattern", props.schema.pattern));
|
228
|
+
if (
|
229
|
+
props.schema.format !== undefined &&
|
230
|
+
(FormatCheatSheet as Record<string, string>)[props.schema.format] !==
|
231
|
+
undefined
|
232
|
+
)
|
233
|
+
intersection.push(props.importer.tag("Format", props.schema.format));
|
234
|
+
if (props.schema.contentMediaType !== undefined)
|
235
|
+
intersection.push(
|
236
|
+
props.importer.tag("ContentMediaType", props.schema.contentMediaType),
|
237
|
+
);
|
238
|
+
writePlugin({
|
239
|
+
importer: props.importer,
|
240
|
+
regular: typia.misc.literals<keyof OpenApi.IJsonSchema.IString>(),
|
241
|
+
intersection,
|
242
|
+
schema: props.schema,
|
243
|
+
});
|
244
|
+
return intersection.length === 1
|
245
|
+
? intersection[0]
|
246
|
+
: ts.factory.createIntersectionTypeNode(intersection);
|
247
|
+
};
|
248
|
+
|
249
|
+
/* -----------------------------------------------------------
|
250
|
+
INSTANCES
|
251
|
+
----------------------------------------------------------- */
|
252
|
+
const writeArray = (props: {
|
253
|
+
components: OpenApi.IComponents;
|
254
|
+
importer: NestiaMigrateImportProgrammer;
|
255
|
+
schema: OpenApi.IJsonSchema.IArray;
|
256
|
+
}): ts.TypeNode => {
|
257
|
+
const intersection: ts.TypeNode[] = [
|
258
|
+
ts.factory.createArrayTypeNode(
|
259
|
+
write({
|
260
|
+
components: props.components,
|
261
|
+
importer: props.importer,
|
262
|
+
schema: props.schema.items,
|
263
|
+
}),
|
264
|
+
),
|
265
|
+
];
|
266
|
+
if (props.schema.minItems !== undefined)
|
267
|
+
intersection.push(props.importer.tag("MinItems", props.schema.minItems));
|
268
|
+
if (props.schema.maxItems !== undefined)
|
269
|
+
intersection.push(props.importer.tag("MaxItems", props.schema.maxItems));
|
270
|
+
if (props.schema.uniqueItems === true)
|
271
|
+
intersection.push(props.importer.tag("UniqueItems"));
|
272
|
+
writePlugin({
|
273
|
+
importer: props.importer,
|
274
|
+
regular: typia.misc.literals<keyof OpenApi.IJsonSchema.IArray>(),
|
275
|
+
intersection,
|
276
|
+
schema: props.schema,
|
277
|
+
});
|
278
|
+
return intersection.length === 1
|
279
|
+
? intersection[0]
|
280
|
+
: ts.factory.createIntersectionTypeNode(intersection);
|
281
|
+
};
|
282
|
+
|
283
|
+
const writeTuple = (props: {
|
284
|
+
components: OpenApi.IComponents;
|
285
|
+
importer: NestiaMigrateImportProgrammer;
|
286
|
+
schema: OpenApi.IJsonSchema.ITuple;
|
287
|
+
}): ts.TypeNode => {
|
288
|
+
const tuple: ts.TypeNode = ts.factory.createTupleTypeNode([
|
289
|
+
...props.schema.prefixItems.map((item) =>
|
290
|
+
write({
|
291
|
+
components: props.components,
|
292
|
+
importer: props.importer,
|
293
|
+
schema: item,
|
294
|
+
}),
|
295
|
+
),
|
296
|
+
...(typeof props.schema.additionalItems === "object" &&
|
297
|
+
props.schema.additionalItems !== null
|
298
|
+
? [
|
299
|
+
ts.factory.createRestTypeNode(
|
300
|
+
write({
|
301
|
+
components: props.components,
|
302
|
+
importer: props.importer,
|
303
|
+
schema: props.schema.additionalItems,
|
304
|
+
}),
|
305
|
+
),
|
306
|
+
]
|
307
|
+
: props.schema.additionalItems === true
|
308
|
+
? [
|
309
|
+
ts.factory.createRestTypeNode(
|
310
|
+
ts.factory.createArrayTypeNode(
|
311
|
+
ts.factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword),
|
312
|
+
),
|
313
|
+
),
|
314
|
+
]
|
315
|
+
: []),
|
316
|
+
]);
|
317
|
+
const intersection: ts.TypeNode[] = [tuple];
|
318
|
+
writePlugin({
|
319
|
+
importer: props.importer,
|
320
|
+
regular: typia.misc.literals<keyof OpenApi.IJsonSchema.ITuple>(),
|
321
|
+
intersection,
|
322
|
+
schema: props.schema,
|
323
|
+
});
|
324
|
+
return intersection.length === 1
|
325
|
+
? intersection[0]
|
326
|
+
: ts.factory.createIntersectionTypeNode(intersection);
|
327
|
+
};
|
328
|
+
|
329
|
+
const writeObject = (props: {
|
330
|
+
components: OpenApi.IComponents;
|
331
|
+
importer: NestiaMigrateImportProgrammer;
|
332
|
+
schema: OpenApi.IJsonSchema.IObject;
|
333
|
+
}): ts.TypeNode => {
|
334
|
+
const regular = () =>
|
335
|
+
ts.factory.createTypeLiteralNode(
|
336
|
+
Object.entries(props.schema.properties ?? [])
|
337
|
+
.map(([key, value], index) => [
|
338
|
+
...(index !== 0 &&
|
339
|
+
(!!value.title?.length || !!value.description?.length)
|
340
|
+
? [ts.factory.createIdentifier("\n") as any]
|
341
|
+
: []),
|
342
|
+
writeRegularProperty({
|
343
|
+
components: props.components,
|
344
|
+
importer: props.importer,
|
345
|
+
required: props.schema.required ?? [],
|
346
|
+
key,
|
347
|
+
value,
|
348
|
+
}),
|
349
|
+
])
|
350
|
+
.flat(),
|
351
|
+
);
|
352
|
+
const dynamic = () =>
|
353
|
+
ts.factory.createTypeLiteralNode([
|
354
|
+
writeDynamicProperty({
|
355
|
+
components: props.components,
|
356
|
+
importer: props.importer,
|
357
|
+
schema: props.schema.additionalProperties as OpenApi.IJsonSchema,
|
358
|
+
}),
|
359
|
+
]);
|
360
|
+
return !!props.schema.properties?.length &&
|
361
|
+
typeof props.schema.additionalProperties === "object"
|
362
|
+
? ts.factory.createIntersectionTypeNode([regular(), dynamic()])
|
363
|
+
: typeof props.schema.additionalProperties === "object"
|
364
|
+
? dynamic()
|
365
|
+
: regular();
|
366
|
+
};
|
367
|
+
|
368
|
+
const writeRegularProperty = (props: {
|
369
|
+
components: OpenApi.IComponents;
|
370
|
+
importer: NestiaMigrateImportProgrammer;
|
371
|
+
required: string[];
|
372
|
+
key: string;
|
373
|
+
value: OpenApi.IJsonSchema;
|
374
|
+
}) =>
|
375
|
+
FilePrinter.description(
|
376
|
+
ts.factory.createPropertySignature(
|
377
|
+
undefined,
|
378
|
+
Escaper.variable(props.key)
|
379
|
+
? ts.factory.createIdentifier(props.key)
|
380
|
+
: ts.factory.createStringLiteral(props.key),
|
381
|
+
props.required.includes(props.key)
|
382
|
+
? undefined
|
383
|
+
: ts.factory.createToken(ts.SyntaxKind.QuestionToken),
|
384
|
+
write({
|
385
|
+
components: props.components,
|
386
|
+
importer: props.importer,
|
387
|
+
schema: props.value,
|
388
|
+
}),
|
389
|
+
),
|
390
|
+
writeComment(props.value),
|
391
|
+
);
|
392
|
+
|
393
|
+
const writeDynamicProperty = (props: {
|
394
|
+
components: OpenApi.IComponents;
|
395
|
+
importer: NestiaMigrateImportProgrammer;
|
396
|
+
schema: OpenApi.IJsonSchema;
|
397
|
+
}) =>
|
398
|
+
FilePrinter.description(
|
399
|
+
ts.factory.createIndexSignature(
|
400
|
+
undefined,
|
401
|
+
[
|
402
|
+
ts.factory.createParameterDeclaration(
|
403
|
+
undefined,
|
404
|
+
undefined,
|
405
|
+
ts.factory.createIdentifier("key"),
|
406
|
+
undefined,
|
407
|
+
TypeFactory.keyword("string"),
|
408
|
+
),
|
409
|
+
],
|
410
|
+
write(props),
|
411
|
+
),
|
412
|
+
writeComment(props.schema),
|
413
|
+
);
|
414
|
+
|
415
|
+
const writeReference = (props: {
|
416
|
+
importer: NestiaMigrateImportProgrammer;
|
417
|
+
schema: OpenApi.IJsonSchema.IReference;
|
418
|
+
}): ts.TypeReferenceNode | ts.KeywordTypeNode => {
|
419
|
+
if (props.schema.$ref.startsWith("#/components/schemas") === false)
|
420
|
+
return TypeFactory.keyword("any");
|
421
|
+
const name: string = props.schema.$ref
|
422
|
+
.split("/")
|
423
|
+
.slice(3)
|
424
|
+
.filter((str) => str.length !== 0)
|
425
|
+
.map(StringUtil.escapeNonVariable)
|
426
|
+
.join("");
|
427
|
+
if (name === "") return TypeFactory.keyword("any");
|
428
|
+
return props.importer.dto(name);
|
429
|
+
};
|
430
|
+
|
431
|
+
/* -----------------------------------------------------------
|
432
|
+
UNIONS
|
433
|
+
----------------------------------------------------------- */
|
434
|
+
const writeUnion = (props: {
|
435
|
+
components: OpenApi.IComponents;
|
436
|
+
importer: NestiaMigrateImportProgrammer;
|
437
|
+
elements: OpenApi.IJsonSchema[];
|
438
|
+
}): ts.UnionTypeNode =>
|
439
|
+
ts.factory.createUnionTypeNode(
|
440
|
+
props.elements.map((schema) =>
|
441
|
+
write({
|
442
|
+
components: props.components,
|
443
|
+
importer: props.importer,
|
444
|
+
schema,
|
445
|
+
}),
|
446
|
+
),
|
447
|
+
);
|
448
|
+
}
|
449
|
+
const createNode = (text: string) => ts.factory.createTypeReferenceNode(text);
|
450
|
+
const writeComment = (schema: OpenApi.IJsonSchema): string =>
|
451
|
+
[
|
452
|
+
...(schema.description?.length ? [schema.description] : []),
|
453
|
+
...(schema.description?.length &&
|
454
|
+
(schema.title !== undefined || schema.deprecated === true)
|
455
|
+
? [""]
|
456
|
+
: []),
|
457
|
+
...(schema.title !== undefined ? [`@title ${schema.title}`] : []),
|
458
|
+
...(schema.deprecated === true ? [`@deprecated`] : []),
|
459
|
+
]
|
460
|
+
.join("\n")
|
461
|
+
.split("*/")
|
462
|
+
.join("*\\/");
|
463
|
+
const writePlugin = (props: {
|
464
|
+
importer: NestiaMigrateImportProgrammer;
|
465
|
+
regular: string[];
|
466
|
+
intersection: ts.TypeNode[];
|
467
|
+
schema: Record<string, any>;
|
468
|
+
}) => {
|
469
|
+
const extra: any = {};
|
470
|
+
for (const [key, value] of Object.entries(props.schema))
|
471
|
+
if (value !== undefined && false === props.regular.includes(key))
|
472
|
+
extra[key] = value;
|
473
|
+
if (Object.keys(extra).length !== 0)
|
474
|
+
props.intersection.push(props.importer.tag("JsonSchemaPlugin", extra));
|
475
|
+
};
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import {
|
2
|
+
IHttpMigrateApplication,
|
3
|
+
IHttpMigrateRoute,
|
4
|
+
OpenApi,
|
5
|
+
} from "@samchon/openapi";
|
6
|
+
|
7
|
+
import { INestiaMigrateConfig } from "./INestiaMigrateConfig";
|
8
|
+
|
9
|
+
export interface INestiaMigrateContext {
|
10
|
+
mode: "nest" | "sdk";
|
11
|
+
document: OpenApi.IDocument;
|
12
|
+
config: INestiaMigrateConfig;
|
13
|
+
routes: IHttpMigrateRoute[];
|
14
|
+
errors: IHttpMigrateApplication.IError[];
|
15
|
+
}
|
@@ -1,8 +1,8 @@
|
|
1
|
-
import { OpenApi } from "@samchon/openapi";
|
2
|
-
|
3
|
-
export interface
|
4
|
-
name: string;
|
5
|
-
location: string;
|
6
|
-
schema: OpenApi.IJsonSchema | null;
|
7
|
-
children:
|
8
|
-
}
|
1
|
+
import { OpenApi } from "@samchon/openapi";
|
2
|
+
|
3
|
+
export interface INestiaMigrateDto {
|
4
|
+
name: string;
|
5
|
+
location: string;
|
6
|
+
schema: OpenApi.IJsonSchema | null;
|
7
|
+
children: INestiaMigrateDto[];
|
8
|
+
}
|
@@ -1,5 +1,5 @@
|
|
1
|
-
export interface
|
2
|
-
location: string;
|
3
|
-
file: string;
|
4
|
-
content: string;
|
5
|
-
}
|
1
|
+
export interface INestiaMigrateFile {
|
2
|
+
location: string;
|
3
|
+
file: string;
|
4
|
+
content: string;
|
5
|
+
}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import { IHttpMigrateApplication, OpenApi } from "@samchon/openapi";
|
2
|
+
|
3
|
+
import { INestiaMigrateConfig } from "./INestiaMigrateConfig";
|
4
|
+
|
5
|
+
export interface INestiaMigrateProgram {
|
6
|
+
mode: "nest" | "sdk";
|
7
|
+
document: OpenApi.IDocument;
|
8
|
+
config: INestiaMigrateConfig;
|
9
|
+
files: Record<string, string>;
|
10
|
+
errors: IHttpMigrateApplication.IError[];
|
11
|
+
}
|
package/src/utils/FilePrinter.ts
CHANGED
@@ -1,38 +1,38 @@
|
|
1
|
-
import ts from "typescript";
|
2
|
-
|
3
|
-
export namespace FilePrinter {
|
4
|
-
export const description = <Node extends ts.Node>(
|
5
|
-
node: Node,
|
6
|
-
comment: string,
|
7
|
-
): Node => {
|
8
|
-
if (comment.length === 0) return node;
|
9
|
-
ts.addSyntheticLeadingComment(
|
10
|
-
node,
|
11
|
-
ts.SyntaxKind.MultiLineCommentTrivia,
|
12
|
-
["*", ...comment.split("\n").map((str) => ` * ${str}`), ""].join("\n"),
|
13
|
-
true,
|
14
|
-
);
|
15
|
-
return node;
|
16
|
-
};
|
17
|
-
|
18
|
-
export const newLine = () =>
|
19
|
-
ts.factory.createExpressionStatement(ts.factory.createIdentifier("\n"));
|
20
|
-
|
21
|
-
export const write = (props: {
|
22
|
-
statements: ts.Statement[];
|
23
|
-
top?: string;
|
24
|
-
}): string => {
|
25
|
-
const script: string = ts
|
26
|
-
.createPrinter({
|
27
|
-
newLine: ts.NewLineKind.LineFeed,
|
28
|
-
})
|
29
|
-
.printFile(
|
30
|
-
ts.factory.createSourceFile(
|
31
|
-
props.statements,
|
32
|
-
ts.factory.createToken(ts.SyntaxKind.EndOfFileToken),
|
33
|
-
ts.NodeFlags.None,
|
34
|
-
),
|
35
|
-
);
|
36
|
-
return (props.top ?? "") + script;
|
37
|
-
};
|
38
|
-
}
|
1
|
+
import ts from "typescript";
|
2
|
+
|
3
|
+
export namespace FilePrinter {
|
4
|
+
export const description = <Node extends ts.Node>(
|
5
|
+
node: Node,
|
6
|
+
comment: string,
|
7
|
+
): Node => {
|
8
|
+
if (comment.length === 0) return node;
|
9
|
+
ts.addSyntheticLeadingComment(
|
10
|
+
node,
|
11
|
+
ts.SyntaxKind.MultiLineCommentTrivia,
|
12
|
+
["*", ...comment.split("\n").map((str) => ` * ${str}`), ""].join("\n"),
|
13
|
+
true,
|
14
|
+
);
|
15
|
+
return node;
|
16
|
+
};
|
17
|
+
|
18
|
+
export const newLine = () =>
|
19
|
+
ts.factory.createExpressionStatement(ts.factory.createIdentifier("\n"));
|
20
|
+
|
21
|
+
export const write = (props: {
|
22
|
+
statements: ts.Statement[];
|
23
|
+
top?: string;
|
24
|
+
}): string => {
|
25
|
+
const script: string = ts
|
26
|
+
.createPrinter({
|
27
|
+
newLine: ts.NewLineKind.LineFeed,
|
28
|
+
})
|
29
|
+
.printFile(
|
30
|
+
ts.factory.createSourceFile(
|
31
|
+
props.statements,
|
32
|
+
ts.factory.createToken(ts.SyntaxKind.EndOfFileToken),
|
33
|
+
ts.NodeFlags.None,
|
34
|
+
),
|
35
|
+
);
|
36
|
+
return (props.top ?? "") + script;
|
37
|
+
};
|
38
|
+
}
|
package/src/utils/MapUtil.ts
CHANGED
@@ -1,13 +1,13 @@
|
|
1
|
-
export namespace MapUtil {
|
2
|
-
export const take =
|
3
|
-
<Key, T>(dict: Map<Key, T>) =>
|
4
|
-
(key: Key) =>
|
5
|
-
(generator: () => T): T => {
|
6
|
-
const oldbie: T | undefined = dict.get(key);
|
7
|
-
if (oldbie) return oldbie;
|
8
|
-
|
9
|
-
const value: T = generator();
|
10
|
-
dict.set(key, value);
|
11
|
-
return value;
|
12
|
-
};
|
13
|
-
}
|
1
|
+
export namespace MapUtil {
|
2
|
+
export const take =
|
3
|
+
<Key, T>(dict: Map<Key, T>) =>
|
4
|
+
(key: Key) =>
|
5
|
+
(generator: () => T): T => {
|
6
|
+
const oldbie: T | undefined = dict.get(key);
|
7
|
+
if (oldbie) return oldbie;
|
8
|
+
|
9
|
+
const value: T = generator();
|
10
|
+
dict.set(key, value);
|
11
|
+
return value;
|
12
|
+
};
|
13
|
+
}
|