@nestia/migrate 4.6.1-dev.20250117 → 4.6.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.
- package/README.md +92 -87
- package/lib/MigrateApplication.js +3 -3
- package/lib/bundles/NEST_TEMPLATE.js +84 -64
- package/lib/bundles/NEST_TEMPLATE.js.map +1 -1
- package/lib/bundles/SDK_TEMPLATE.js +30 -30
- package/lib/bundles/SDK_TEMPLATE.js.map +1 -1
- package/lib/index.mjs +118 -102
- package/lib/index.mjs.map +1 -1
- package/lib/programmers/MigrateApiNamespaceProgrammer.js +6 -6
- package/lib/programmers/MigrateApiNamespaceProgrammer.js.map +1 -1
- package/lib/programmers/{MigrateApiSimulatationProgrammer.d.ts → MigrateApiSimulationProgrammer.d.ts} +1 -1
- package/lib/programmers/{MigrateApiSimulatationProgrammer.js → MigrateApiSimulationProgrammer.js} +7 -7
- package/lib/programmers/MigrateApiSimulationProgrammer.js.map +1 -0
- package/lib/utils/openapi-down-convert/converter.js +2 -2
- package/package.json +6 -6
- package/src/MigrateApplication.ts +107 -107
- package/src/analyzers/MigrateApplicationAnalyzer.ts +18 -18
- package/src/analyzers/MigrateControllerAnalyzer.ts +51 -51
- package/src/archivers/MigrateFileArchiver.ts +38 -38
- package/src/bundles/NEST_TEMPLATE.ts +84 -64
- package/src/bundles/SDK_TEMPLATE.ts +30 -30
- package/src/executable/bundle.js +125 -125
- package/src/executable/migrate.ts +7 -7
- package/src/factories/TypeLiteralFactory.ts +57 -57
- package/src/index.ts +4 -4
- package/src/internal/MigrateCommander.ts +86 -86
- package/src/internal/MigrateInquirer.ts +89 -89
- package/src/module.ts +8 -8
- package/src/programmers/MigrateApiFileProgrammer.ts +49 -49
- package/src/programmers/MigrateApiFunctionProgrammer.ts +210 -210
- package/src/programmers/MigrateApiNamespaceProgrammer.ts +417 -417
- package/src/programmers/MigrateApiProgrammer.ts +103 -103
- package/src/programmers/{MigrateApiSimulatationProgrammer.ts → MigrateApiSimulationProgrammer.ts} +324 -324
- package/src/programmers/MigrateApiStartProgrammer.ts +194 -194
- package/src/programmers/MigrateDtoProgrammer.ts +87 -87
- package/src/programmers/MigrateE2eFileProgrammer.ts +117 -117
- package/src/programmers/MigrateE2eProgrammer.ts +34 -34
- package/src/programmers/MigrateImportProgrammer.ts +118 -118
- package/src/programmers/MigrateNestControllerProgrammer.ts +50 -50
- package/src/programmers/MigrateNestMethodProgrammer.ts +393 -393
- package/src/programmers/MigrateNestModuleProgrammer.ts +65 -65
- package/src/programmers/MigrateNestProgrammer.ts +81 -81
- package/src/programmers/MigrateSchemaProgrammer.ts +373 -373
- package/src/structures/IHttpMigrateController.ts +8 -8
- package/src/structures/IHttpMigrateDto.ts +8 -8
- package/src/structures/IHttpMigrateFile.ts +5 -5
- package/src/structures/IHttpMigrateProgram.ts +27 -27
- package/src/structures/IHttpMigrateRoute.ts +1 -1
- package/src/structures/IHttpMigrateSchema.ts +4 -4
- package/src/utils/FilePrinter.ts +36 -36
- 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/programmers/MigrateApiSimulatationProgrammer.js.map +0 -1
@@ -1,139 +1,139 @@
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
2
|
-
|
3
|
-
/**
|
4
|
-
* Recursively walk a JSON object and invoke a callback function
|
5
|
-
* on each `{ "$ref" : "path" }` object found
|
6
|
-
*/
|
7
|
-
|
8
|
-
/**
|
9
|
-
* Represents a JSON Reference object, such as
|
10
|
-
* `{"$ref": "#/components/schemas/problemResponse" }`
|
11
|
-
*/
|
12
|
-
export interface RefObject {
|
13
|
-
$ref: string;
|
14
|
-
}
|
15
|
-
|
16
|
-
/**
|
17
|
-
* JsonNode represents a node within the OpenAPI object
|
18
|
-
*/
|
19
|
-
export type JsonNode = object | [] | string | boolean | null | number;
|
20
|
-
|
21
|
-
/** A JSON Schema object in an API def */
|
22
|
-
export type SchemaObject = object;
|
23
|
-
|
24
|
-
/**
|
25
|
-
* Function signature for the visitRefObjects callback
|
26
|
-
*/
|
27
|
-
export type RefVisitor = (node: RefObject) => JsonNode;
|
28
|
-
/**
|
29
|
-
* Function signature for the visitSchemaObjects callback
|
30
|
-
*/
|
31
|
-
export type SchemaVisitor = (node: SchemaObject) => SchemaObject;
|
32
|
-
|
33
|
-
/**
|
34
|
-
/**
|
35
|
-
* Function signature for the walkObject callback
|
36
|
-
*/
|
37
|
-
export type ObjectVisitor = (node: object) => JsonNode;
|
38
|
-
|
39
|
-
/**
|
40
|
-
* Test if a JSON node is a `{ $ref: "uri" }` object
|
41
|
-
*/
|
42
|
-
export function isRef(node: any): boolean {
|
43
|
-
return (
|
44
|
-
node !== null &&
|
45
|
-
typeof node === "object" &&
|
46
|
-
node.hasOwnProperty("$ref") &&
|
47
|
-
typeof node["$ref"] === "string"
|
48
|
-
);
|
49
|
-
}
|
50
|
-
|
51
|
-
/**
|
52
|
-
* Walk a JSON object and apply `schemaCallback` when a JSON schema is found.
|
53
|
-
* JSON Schema objects are items in components/schemas or in an item named `schema`
|
54
|
-
* @param node a node in the OpenAPI document
|
55
|
-
* @param schemaCallback the function to call on JSON schema objects
|
56
|
-
* @return the modified (annotated) node
|
57
|
-
*/
|
58
|
-
export function visitSchemaObjects(
|
59
|
-
node: any,
|
60
|
-
schemaCallback: SchemaVisitor,
|
61
|
-
): any {
|
62
|
-
const objectVisitor = (node: any): JsonNode => {
|
63
|
-
if (node.hasOwnProperty("schema")) {
|
64
|
-
const schema = node["schema"];
|
65
|
-
if (schema != null && typeof schema === "object") {
|
66
|
-
node["schema"] = schemaCallback(schema);
|
67
|
-
}
|
68
|
-
} else if (node.hasOwnProperty("schemas")) {
|
69
|
-
const schemas = node["schemas"];
|
70
|
-
if (schemas != null && typeof schemas === "object") {
|
71
|
-
for (const schemaName in schemas) {
|
72
|
-
const schema = schemas[schemaName];
|
73
|
-
const newSchema = schemaCallback(schema);
|
74
|
-
schemas[schemaName] = newSchema;
|
75
|
-
}
|
76
|
-
}
|
77
|
-
}
|
78
|
-
return node;
|
79
|
-
};
|
80
|
-
return walkObject(node, objectVisitor);
|
81
|
-
}
|
82
|
-
|
83
|
-
/**
|
84
|
-
* Walk a JSON object and apply `refCallback` when a JSON `{$ref: url }` is found
|
85
|
-
* @param node a node in the OpenAPI document
|
86
|
-
* @param refCallback the function to call on JSON `$ref` objects
|
87
|
-
* @return the modified (annotated) node
|
88
|
-
*/
|
89
|
-
export function visitRefObjects(node: any, refCallback: RefVisitor): any {
|
90
|
-
const objectVisitor = (node: object): JsonNode => {
|
91
|
-
if (isRef(node)) {
|
92
|
-
return refCallback(node as RefObject);
|
93
|
-
}
|
94
|
-
return node;
|
95
|
-
};
|
96
|
-
return walkObject(node, objectVisitor);
|
97
|
-
}
|
98
|
-
|
99
|
-
/**
|
100
|
-
* Walk a JSON object or array and apply objectCallback when a JSON object is found
|
101
|
-
* @param node a node in the OpenAPI document
|
102
|
-
* @param objectCallback the function to call on JSON objects
|
103
|
-
* @param nav tracks where we are in the original document
|
104
|
-
* @return the modified (annotated) node
|
105
|
-
*/
|
106
|
-
export function walkObject(
|
107
|
-
node: object,
|
108
|
-
objectCallback: ObjectVisitor,
|
109
|
-
): JsonNode {
|
110
|
-
return walkObj(node);
|
111
|
-
|
112
|
-
function walkObj(node: any): JsonNode {
|
113
|
-
const object = objectCallback(node);
|
114
|
-
if (object !== null && typeof object === "object") {
|
115
|
-
const keys = [...Object.keys(node)]; // make copy since this code may re-enter objects
|
116
|
-
for (const key of keys) {
|
117
|
-
const val = node[key];
|
118
|
-
if (Array.isArray(val)) {
|
119
|
-
node[key] = walkArray(val as []);
|
120
|
-
} else if (val !== null && typeof val === "object") {
|
121
|
-
node[key] = walkObj(val);
|
122
|
-
}
|
123
|
-
}
|
124
|
-
}
|
125
|
-
return object;
|
126
|
-
}
|
127
|
-
|
128
|
-
function walkArray(array: JsonNode[]): JsonNode[] {
|
129
|
-
for (let index = 0; index < array.length; index += 1) {
|
130
|
-
const val = array[index] as JsonNode;
|
131
|
-
if (val !== null && typeof val === "object") {
|
132
|
-
array[index] = walkObj(val) as object;
|
133
|
-
} else if (Array.isArray(val)) {
|
134
|
-
array[index] = walkArray(val as JsonNode[]) as [];
|
135
|
-
}
|
136
|
-
}
|
137
|
-
return array;
|
138
|
-
}
|
139
|
-
}
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
2
|
+
|
3
|
+
/**
|
4
|
+
* Recursively walk a JSON object and invoke a callback function
|
5
|
+
* on each `{ "$ref" : "path" }` object found
|
6
|
+
*/
|
7
|
+
|
8
|
+
/**
|
9
|
+
* Represents a JSON Reference object, such as
|
10
|
+
* `{"$ref": "#/components/schemas/problemResponse" }`
|
11
|
+
*/
|
12
|
+
export interface RefObject {
|
13
|
+
$ref: string;
|
14
|
+
}
|
15
|
+
|
16
|
+
/**
|
17
|
+
* JsonNode represents a node within the OpenAPI object
|
18
|
+
*/
|
19
|
+
export type JsonNode = object | [] | string | boolean | null | number;
|
20
|
+
|
21
|
+
/** A JSON Schema object in an API def */
|
22
|
+
export type SchemaObject = object;
|
23
|
+
|
24
|
+
/**
|
25
|
+
* Function signature for the visitRefObjects callback
|
26
|
+
*/
|
27
|
+
export type RefVisitor = (node: RefObject) => JsonNode;
|
28
|
+
/**
|
29
|
+
* Function signature for the visitSchemaObjects callback
|
30
|
+
*/
|
31
|
+
export type SchemaVisitor = (node: SchemaObject) => SchemaObject;
|
32
|
+
|
33
|
+
/**
|
34
|
+
/**
|
35
|
+
* Function signature for the walkObject callback
|
36
|
+
*/
|
37
|
+
export type ObjectVisitor = (node: object) => JsonNode;
|
38
|
+
|
39
|
+
/**
|
40
|
+
* Test if a JSON node is a `{ $ref: "uri" }` object
|
41
|
+
*/
|
42
|
+
export function isRef(node: any): boolean {
|
43
|
+
return (
|
44
|
+
node !== null &&
|
45
|
+
typeof node === "object" &&
|
46
|
+
node.hasOwnProperty("$ref") &&
|
47
|
+
typeof node["$ref"] === "string"
|
48
|
+
);
|
49
|
+
}
|
50
|
+
|
51
|
+
/**
|
52
|
+
* Walk a JSON object and apply `schemaCallback` when a JSON schema is found.
|
53
|
+
* JSON Schema objects are items in components/schemas or in an item named `schema`
|
54
|
+
* @param node a node in the OpenAPI document
|
55
|
+
* @param schemaCallback the function to call on JSON schema objects
|
56
|
+
* @return the modified (annotated) node
|
57
|
+
*/
|
58
|
+
export function visitSchemaObjects(
|
59
|
+
node: any,
|
60
|
+
schemaCallback: SchemaVisitor,
|
61
|
+
): any {
|
62
|
+
const objectVisitor = (node: any): JsonNode => {
|
63
|
+
if (node.hasOwnProperty("schema")) {
|
64
|
+
const schema = node["schema"];
|
65
|
+
if (schema != null && typeof schema === "object") {
|
66
|
+
node["schema"] = schemaCallback(schema);
|
67
|
+
}
|
68
|
+
} else if (node.hasOwnProperty("schemas")) {
|
69
|
+
const schemas = node["schemas"];
|
70
|
+
if (schemas != null && typeof schemas === "object") {
|
71
|
+
for (const schemaName in schemas) {
|
72
|
+
const schema = schemas[schemaName];
|
73
|
+
const newSchema = schemaCallback(schema);
|
74
|
+
schemas[schemaName] = newSchema;
|
75
|
+
}
|
76
|
+
}
|
77
|
+
}
|
78
|
+
return node;
|
79
|
+
};
|
80
|
+
return walkObject(node, objectVisitor);
|
81
|
+
}
|
82
|
+
|
83
|
+
/**
|
84
|
+
* Walk a JSON object and apply `refCallback` when a JSON `{$ref: url }` is found
|
85
|
+
* @param node a node in the OpenAPI document
|
86
|
+
* @param refCallback the function to call on JSON `$ref` objects
|
87
|
+
* @return the modified (annotated) node
|
88
|
+
*/
|
89
|
+
export function visitRefObjects(node: any, refCallback: RefVisitor): any {
|
90
|
+
const objectVisitor = (node: object): JsonNode => {
|
91
|
+
if (isRef(node)) {
|
92
|
+
return refCallback(node as RefObject);
|
93
|
+
}
|
94
|
+
return node;
|
95
|
+
};
|
96
|
+
return walkObject(node, objectVisitor);
|
97
|
+
}
|
98
|
+
|
99
|
+
/**
|
100
|
+
* Walk a JSON object or array and apply objectCallback when a JSON object is found
|
101
|
+
* @param node a node in the OpenAPI document
|
102
|
+
* @param objectCallback the function to call on JSON objects
|
103
|
+
* @param nav tracks where we are in the original document
|
104
|
+
* @return the modified (annotated) node
|
105
|
+
*/
|
106
|
+
export function walkObject(
|
107
|
+
node: object,
|
108
|
+
objectCallback: ObjectVisitor,
|
109
|
+
): JsonNode {
|
110
|
+
return walkObj(node);
|
111
|
+
|
112
|
+
function walkObj(node: any): JsonNode {
|
113
|
+
const object = objectCallback(node);
|
114
|
+
if (object !== null && typeof object === "object") {
|
115
|
+
const keys = [...Object.keys(node)]; // make copy since this code may re-enter objects
|
116
|
+
for (const key of keys) {
|
117
|
+
const val = node[key];
|
118
|
+
if (Array.isArray(val)) {
|
119
|
+
node[key] = walkArray(val as []);
|
120
|
+
} else if (val !== null && typeof val === "object") {
|
121
|
+
node[key] = walkObj(val);
|
122
|
+
}
|
123
|
+
}
|
124
|
+
}
|
125
|
+
return object;
|
126
|
+
}
|
127
|
+
|
128
|
+
function walkArray(array: JsonNode[]): JsonNode[] {
|
129
|
+
for (let index = 0; index < array.length; index += 1) {
|
130
|
+
const val = array[index] as JsonNode;
|
131
|
+
if (val !== null && typeof val === "object") {
|
132
|
+
array[index] = walkObj(val) as object;
|
133
|
+
} else if (Array.isArray(val)) {
|
134
|
+
array[index] = walkArray(val as JsonNode[]) as [];
|
135
|
+
}
|
136
|
+
}
|
137
|
+
return array;
|
138
|
+
}
|
139
|
+
}
|