@nestia/migrate 4.6.1-dev.20250117 → 4.6.1

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 (49) hide show
  1. package/README.md +87 -87
  2. package/lib/bundles/NEST_TEMPLATE.js +66 -66
  3. package/lib/bundles/NEST_TEMPLATE.js.map +1 -1
  4. package/lib/bundles/SDK_TEMPLATE.js +30 -30
  5. package/lib/bundles/SDK_TEMPLATE.js.map +1 -1
  6. package/lib/index.mjs +92 -92
  7. package/lib/utils/openapi-down-convert/converter.js +2 -2
  8. package/package.json +6 -6
  9. package/src/MigrateApplication.ts +107 -107
  10. package/src/analyzers/MigrateApplicationAnalyzer.ts +18 -18
  11. package/src/analyzers/MigrateControllerAnalyzer.ts +51 -51
  12. package/src/archivers/MigrateFileArchiver.ts +38 -38
  13. package/src/bundles/NEST_TEMPLATE.ts +66 -66
  14. package/src/bundles/SDK_TEMPLATE.ts +30 -30
  15. package/src/executable/bundle.js +125 -125
  16. package/src/executable/migrate.ts +7 -7
  17. package/src/factories/TypeLiteralFactory.ts +57 -57
  18. package/src/index.ts +4 -4
  19. package/src/internal/MigrateCommander.ts +86 -86
  20. package/src/internal/MigrateInquirer.ts +89 -89
  21. package/src/module.ts +8 -8
  22. package/src/programmers/MigrateApiFileProgrammer.ts +49 -49
  23. package/src/programmers/MigrateApiFunctionProgrammer.ts +210 -210
  24. package/src/programmers/MigrateApiNamespaceProgrammer.ts +417 -417
  25. package/src/programmers/MigrateApiProgrammer.ts +103 -103
  26. package/src/programmers/MigrateApiSimulatationProgrammer.ts +324 -324
  27. package/src/programmers/MigrateApiStartProgrammer.ts +194 -194
  28. package/src/programmers/MigrateDtoProgrammer.ts +87 -87
  29. package/src/programmers/MigrateE2eFileProgrammer.ts +117 -117
  30. package/src/programmers/MigrateE2eProgrammer.ts +34 -34
  31. package/src/programmers/MigrateImportProgrammer.ts +118 -118
  32. package/src/programmers/MigrateNestControllerProgrammer.ts +50 -50
  33. package/src/programmers/MigrateNestMethodProgrammer.ts +393 -393
  34. package/src/programmers/MigrateNestModuleProgrammer.ts +65 -65
  35. package/src/programmers/MigrateNestProgrammer.ts +81 -81
  36. package/src/programmers/MigrateSchemaProgrammer.ts +373 -373
  37. package/src/structures/IHttpMigrateController.ts +8 -8
  38. package/src/structures/IHttpMigrateDto.ts +8 -8
  39. package/src/structures/IHttpMigrateFile.ts +5 -5
  40. package/src/structures/IHttpMigrateProgram.ts +27 -27
  41. package/src/structures/IHttpMigrateRoute.ts +1 -1
  42. package/src/structures/IHttpMigrateSchema.ts +4 -4
  43. package/src/utils/FilePrinter.ts +36 -36
  44. package/src/utils/MapUtil.ts +13 -13
  45. package/src/utils/OpenApiTypeChecker.ts +73 -73
  46. package/src/utils/SetupWizard.ts +12 -12
  47. package/src/utils/StringUtil.ts +113 -113
  48. package/src/utils/openapi-down-convert/RefVisitor.ts +139 -139
  49. package/src/utils/openapi-down-convert/converter.ts +527 -527
@@ -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
+ }