@nestia/migrate 0.2.14 → 0.4.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 +2 -2
- package/lib/NestiaMigrateApplication.js +227 -258
- package/lib/NestiaMigrateApplication.js.map +1 -1
- package/lib/bundles/TEMPLATE.js +3 -3
- package/lib/bundles/TEMPLATE.js.map +1 -1
- package/lib/programmers/ControllerProgrammer.js +5 -15
- package/lib/programmers/ControllerProgrammer.js.map +1 -1
- package/lib/programmers/DtoProgrammer.js +8 -13
- package/lib/programmers/DtoProgrammer.js.map +1 -1
- package/lib/programmers/ImportProgrammer.d.ts +9 -3
- package/lib/programmers/ImportProgrammer.js +32 -8
- package/lib/programmers/ImportProgrammer.js.map +1 -1
- package/lib/programmers/MigrateProgrammer.js +5 -5
- package/lib/programmers/MigrateProgrammer.js.map +1 -1
- package/lib/programmers/RouteProgrammer.d.ts +2 -1
- package/lib/programmers/RouteProgrammer.js +19 -19
- package/lib/programmers/RouteProgrammer.js.map +1 -1
- package/lib/programmers/SchemaProgrammer.d.ts +2 -1
- package/lib/programmers/SchemaProgrammer.js +107 -60
- package/lib/programmers/SchemaProgrammer.js.map +1 -1
- package/lib/structures/IMigrateRoute.d.ts +1 -1
- package/lib/structures/ISwaggeSchema.d.ts +4 -1
- package/lib/structures/ISwaggerRoute.d.ts +1 -1
- package/lib/utils/JsonTypeChecker.d.ts +1 -0
- package/lib/utils/JsonTypeChecker.js +1 -0
- package/lib/utils/JsonTypeChecker.js.map +1 -1
- package/package.json +5 -5
- package/src/bundles/TEMPLATE.ts +3 -3
- package/src/programmers/ControllerProgrammer.ts +14 -30
- package/src/programmers/DtoProgrammer.ts +9 -17
- package/src/programmers/ImportProgrammer.ts +44 -13
- package/src/programmers/MigrateProgrammer.ts +5 -5
- package/src/programmers/RouteProgrammer.ts +31 -31
- package/src/programmers/SchemaProgrammer.ts +156 -66
- package/src/structures/IMigrateRoute.ts +1 -1
- package/src/structures/ISwaggeSchema.ts +5 -0
- package/src/structures/ISwaggerRoute.ts +1 -1
- package/src/utils/JsonTypeChecker.ts +4 -0
@@ -3,19 +3,25 @@ import { Escaper } from "typia/lib/utils/Escaper";
|
|
3
3
|
import { ISwaggerSchema } from "../structures/ISwaggeSchema";
|
4
4
|
import { ISwaggerComponents } from "../structures/ISwaggerComponents";
|
5
5
|
import { JsonTypeChecker } from "../utils/JsonTypeChecker";
|
6
|
+
import { ImportProgrammer } from "./ImportProgrammer";
|
6
7
|
|
7
8
|
export namespace SchemaProgrammer {
|
8
9
|
export const write =
|
9
10
|
(components: ISwaggerComponents) =>
|
10
11
|
(references: ISwaggerSchema.IReference[]) =>
|
12
|
+
(importer: ImportProgrammer) =>
|
11
13
|
(schema: ISwaggerSchema): string =>
|
12
|
-
writeSchema(components)(references)(() => () => {})(true)(
|
14
|
+
writeSchema(components)(references)(importer)(() => () => {})(true)(
|
15
|
+
schema,
|
16
|
+
);
|
17
|
+
|
18
|
+
type CommentTagger = (tag: string) => (value?: string) => void;
|
13
19
|
|
14
|
-
type Tagger = (tag: string) => (value?: string) => void;
|
15
20
|
const writeSchema =
|
16
21
|
(components: ISwaggerComponents) =>
|
17
22
|
(references: ISwaggerSchema.IReference[]) =>
|
18
|
-
(
|
23
|
+
(importer: ImportProgrammer) =>
|
24
|
+
(commentTagger: CommentTagger) =>
|
19
25
|
(final: boolean) =>
|
20
26
|
(schema: ISwaggerSchema): string => {
|
21
27
|
// SPECIAL TYPES
|
@@ -27,38 +33,50 @@ export namespace SchemaProgrammer {
|
|
27
33
|
"(" +
|
28
34
|
schema.anyOf
|
29
35
|
.map(
|
30
|
-
writeSchema(components)(references)(
|
31
|
-
|
32
|
-
),
|
36
|
+
writeSchema(components)(references)(importer)(
|
37
|
+
commentTagger,
|
38
|
+
)(false),
|
33
39
|
)
|
34
40
|
.join(" | ") +
|
35
41
|
")"
|
36
42
|
);
|
37
43
|
else if (JsonTypeChecker.isOneOf(schema))
|
38
44
|
return schema.oneOf
|
39
|
-
.map(
|
45
|
+
.map(
|
46
|
+
writeSchema(components)(references)(importer)(
|
47
|
+
commentTagger,
|
48
|
+
)(false),
|
49
|
+
)
|
40
50
|
.join(" | ");
|
41
51
|
// ATOMIC TYPES
|
52
|
+
if (JsonTypeChecker.isNullOnly(schema)) return writeNullOnly();
|
42
53
|
else if (JsonTypeChecker.isBoolean(schema))
|
43
|
-
return writeBoolean(
|
44
|
-
else if (
|
45
|
-
|
46
|
-
|
47
|
-
|
54
|
+
return writeBoolean(importer)(commentTagger)(schema);
|
55
|
+
else if (
|
56
|
+
JsonTypeChecker.isInteger(schema) ||
|
57
|
+
JsonTypeChecker.isNumber(schema)
|
58
|
+
)
|
59
|
+
return writeNumber(importer)(commentTagger)(schema);
|
48
60
|
else if (JsonTypeChecker.isString(schema))
|
49
|
-
return writeString(
|
61
|
+
return writeString(importer)(commentTagger)(schema);
|
50
62
|
// INSTANCE TYPES
|
51
63
|
else if (JsonTypeChecker.isArray(schema))
|
52
|
-
return writeArray(components)(references)(
|
64
|
+
return writeArray(components)(references)(importer)(
|
65
|
+
commentTagger,
|
66
|
+
)(schema);
|
53
67
|
else if (JsonTypeChecker.isObject(schema))
|
54
|
-
return writeObject(components)(references)(
|
68
|
+
return writeObject(components)(references)(importer)(
|
69
|
+
schema,
|
70
|
+
);
|
55
71
|
else if (JsonTypeChecker.isReference(schema)) {
|
56
72
|
references.push(schema);
|
57
|
-
return
|
73
|
+
return importer.dto(
|
74
|
+
schema.$ref.replace(`#/components/schemas/`, ``),
|
75
|
+
);
|
58
76
|
} else return "any";
|
59
77
|
})();
|
60
78
|
if (type === "any" || final === false) return type;
|
61
|
-
return isNullable(components)(schema) ?
|
79
|
+
return isNullable(components)(schema) ? `null | ${type}` : type;
|
62
80
|
};
|
63
81
|
|
64
82
|
const isNullable =
|
@@ -78,105 +96,163 @@ export namespace SchemaProgrammer {
|
|
78
96
|
return (schema as ISwaggerSchema.IString).nullable === true;
|
79
97
|
};
|
80
98
|
|
99
|
+
const writeNullOnly = (): string => "null";
|
100
|
+
|
81
101
|
const writeBoolean =
|
82
|
-
(
|
102
|
+
(importer: ImportProgrammer) =>
|
103
|
+
(tagger: CommentTagger) =>
|
83
104
|
(schema: ISwaggerSchema.IBoolean): string => {
|
84
|
-
if (schema.
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
105
|
+
if (schema.enum?.length) {
|
106
|
+
if (schema.default !== undefined)
|
107
|
+
tagger("default")(schema.default.toString());
|
108
|
+
return schema.enum.join(" | ");
|
109
|
+
}
|
110
|
+
const intersection: string[] = ["boolean"];
|
111
|
+
if (schema.default !== undefined)
|
112
|
+
intersection.push(
|
113
|
+
importer.tag("Default", String(schema.default)),
|
114
|
+
);
|
115
|
+
return intersection.length === 1
|
116
|
+
? intersection[0]
|
117
|
+
: "(" + intersection.join(" & ") + ")";
|
92
118
|
};
|
119
|
+
|
93
120
|
const writeNumber =
|
94
|
-
(
|
121
|
+
(importer: ImportProgrammer) =>
|
122
|
+
(commentTagger: CommentTagger) =>
|
95
123
|
(schema: ISwaggerSchema.IInteger | ISwaggerSchema.INumber): string => {
|
96
|
-
if (schema.
|
97
|
-
|
124
|
+
if (schema.enum?.length) {
|
125
|
+
if (schema.default !== undefined)
|
126
|
+
commentTagger("default")(schema.default.toString());
|
127
|
+
return schema.enum.join(" | ");
|
128
|
+
}
|
98
129
|
|
130
|
+
const intersection: string[] = ["number"];
|
131
|
+
if (schema.default !== undefined)
|
132
|
+
intersection.push(importer.tag("Default", schema.default));
|
133
|
+
if (schema.type === "integer")
|
134
|
+
intersection.push(importer.tag("Type", "int32"));
|
99
135
|
if (schema.minimum !== undefined)
|
100
|
-
|
101
|
-
|
102
|
-
|
136
|
+
intersection.push(
|
137
|
+
importer.tag(
|
138
|
+
schema.exclusiveMinimum
|
139
|
+
? "ExclusiveMinimum"
|
140
|
+
: "Minimum",
|
141
|
+
schema.minimum,
|
142
|
+
),
|
143
|
+
);
|
103
144
|
if (schema.maximum !== undefined)
|
104
|
-
|
105
|
-
|
106
|
-
|
145
|
+
intersection.push(
|
146
|
+
importer.tag(
|
147
|
+
schema.exclusiveMaximum
|
148
|
+
? "ExclusiveMaximum"
|
149
|
+
: "Maximum",
|
150
|
+
schema.maximum,
|
151
|
+
),
|
152
|
+
);
|
107
153
|
if (schema.multipleOf !== undefined)
|
108
|
-
|
109
|
-
|
154
|
+
intersection.push(
|
155
|
+
importer.tag("MultipleOf", schema.multipleOf),
|
156
|
+
);
|
157
|
+
return intersection.length === 1
|
158
|
+
? intersection[0]
|
159
|
+
: "(" + intersection.join(" & ") + ")";
|
110
160
|
};
|
111
161
|
const writeString =
|
112
|
-
(
|
162
|
+
(importer: ImportProgrammer) =>
|
163
|
+
(commentTagger: CommentTagger) =>
|
113
164
|
(schema: ISwaggerSchema.IString): string => {
|
114
|
-
if (schema.
|
115
|
-
|
165
|
+
if (schema.enum?.length) {
|
166
|
+
if (schema.default !== undefined)
|
167
|
+
commentTagger("default")(schema.default.toString());
|
116
168
|
return schema.enum
|
117
169
|
.map((str) => JSON.stringify(str))
|
118
170
|
.join(" | ");
|
171
|
+
}
|
119
172
|
|
173
|
+
const intersection: string[] = ["string"];
|
174
|
+
if (schema.default !== undefined)
|
175
|
+
intersection.push(importer.tag("Default", schema.default));
|
176
|
+
if (schema.format !== undefined && FORMATS.has(schema.format))
|
177
|
+
intersection.push(importer.tag("Format", schema.format));
|
178
|
+
if (schema.pattern !== undefined)
|
179
|
+
intersection.push(importer.tag("Pattern", schema.pattern));
|
120
180
|
if (schema.minLength !== undefined)
|
121
|
-
|
181
|
+
intersection.push(importer.tag("MinLength", schema.minLength));
|
122
182
|
if (schema.maxLength !== undefined)
|
123
|
-
|
124
|
-
|
125
|
-
|
183
|
+
intersection.push(importer.tag("MaxLength", schema.maxLength));
|
184
|
+
return intersection.length === 1
|
185
|
+
? intersection[0]
|
186
|
+
: "(" + intersection.join(" & ") + ")";
|
126
187
|
};
|
127
188
|
|
128
189
|
const writeArray =
|
129
190
|
(components: ISwaggerComponents) =>
|
130
191
|
(references: ISwaggerSchema.IReference[]) =>
|
131
|
-
(
|
132
|
-
(
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
192
|
+
(importer: ImportProgrammer) =>
|
193
|
+
(commentTagger: CommentTagger) =>
|
194
|
+
(schema: ISwaggerSchema.IArray): string => {
|
195
|
+
if (schema["x-typia-tuple"])
|
196
|
+
return `[${schema["x-typia-tuple"].items
|
197
|
+
.map(writeTupleElement(components)(references)(importer))
|
198
|
+
.join(", ")}]`;
|
199
|
+
const intersection: string[] = [
|
200
|
+
`Array<${writeSchema(components)(references)(importer)(
|
201
|
+
commentTagger,
|
202
|
+
)(true)(schema.items)}>`,
|
203
|
+
];
|
204
|
+
if (schema.minItems !== undefined)
|
205
|
+
intersection.push(importer.tag("MinItems", schema.minItems));
|
206
|
+
if (schema.maxItems !== undefined)
|
207
|
+
intersection.push(importer.tag("MaxItems", schema.maxItems));
|
208
|
+
|
209
|
+
return intersection.length === 1
|
210
|
+
? intersection[0]
|
211
|
+
: "(" + intersection.join(" & ") + ")";
|
212
|
+
};
|
140
213
|
const writeTupleElement =
|
141
214
|
(components: ISwaggerComponents) =>
|
142
215
|
(references: ISwaggerSchema.IReference[]) =>
|
216
|
+
(importer: ImportProgrammer) =>
|
143
217
|
(schema: ISwaggerSchema): string => {
|
144
|
-
const name: string = writeSchema(components)(references)(
|
218
|
+
const name: string = writeSchema(components)(references)(importer)(
|
145
219
|
() => () => {},
|
146
220
|
)(true)(schema);
|
147
221
|
return schema["x-typia-optional"]
|
148
222
|
? `${name}?`
|
149
223
|
: schema["x-typia-rest"]
|
150
|
-
? `...${name}`
|
224
|
+
? `...${name}[]`
|
151
225
|
: name;
|
152
226
|
};
|
153
227
|
|
154
228
|
const writeObject =
|
155
229
|
(components: ISwaggerComponents) =>
|
156
230
|
(references: ISwaggerSchema.IReference[]) =>
|
231
|
+
(importer: ImportProgrammer) =>
|
157
232
|
(schema: ISwaggerSchema.IObject): string => {
|
158
233
|
const entries = Object.entries(schema.properties ?? {});
|
159
234
|
return typeof schema.additionalProperties === "object"
|
160
235
|
? entries.length
|
161
|
-
? `${writeStaticObject(components)(references)(
|
236
|
+
? `${writeStaticObject(components)(references)(importer)(
|
162
237
|
schema,
|
163
238
|
)} & ${writeDynamicObject(components)(references)(
|
164
|
-
|
165
|
-
)}`
|
166
|
-
: writeDynamicObject(components)(references)(
|
239
|
+
importer,
|
240
|
+
)(schema.additionalProperties)}`
|
241
|
+
: writeDynamicObject(components)(references)(importer)(
|
167
242
|
schema.additionalProperties,
|
168
243
|
)
|
169
|
-
: writeStaticObject(components)(references)(schema);
|
244
|
+
: writeStaticObject(components)(references)(importer)(schema);
|
170
245
|
};
|
171
246
|
const writeStaticObject =
|
172
247
|
(components: ISwaggerComponents) =>
|
173
248
|
(references: ISwaggerSchema.IReference[]) =>
|
249
|
+
(importer: ImportProgrammer) =>
|
174
250
|
(schema: ISwaggerSchema.IObject): string =>
|
175
251
|
[
|
176
252
|
"{",
|
177
253
|
...Object.entries(schema.properties ?? {})
|
178
254
|
.map(([key, value]) =>
|
179
|
-
writeProperty(components)(references)(key)(
|
255
|
+
writeProperty(components)(references)(importer)(key)(
|
180
256
|
(schema.required ?? []).some((r) => r === key),
|
181
257
|
)(value),
|
182
258
|
)
|
@@ -186,11 +262,12 @@ export namespace SchemaProgrammer {
|
|
186
262
|
const writeDynamicObject =
|
187
263
|
(components: ISwaggerComponents) =>
|
188
264
|
(references: ISwaggerSchema.IReference[]) =>
|
265
|
+
(importer: ImportProgrammer) =>
|
189
266
|
(additional: ISwaggerSchema): string => {
|
190
267
|
return [
|
191
268
|
"{",
|
192
269
|
tab(4)(
|
193
|
-
writeProperty(components)(references)(
|
270
|
+
writeProperty(components)(references)(importer)(
|
194
271
|
"[key: string]",
|
195
272
|
true,
|
196
273
|
)(true)(additional),
|
@@ -202,11 +279,12 @@ export namespace SchemaProgrammer {
|
|
202
279
|
const writeProperty =
|
203
280
|
(components: ISwaggerComponents) =>
|
204
281
|
(references: ISwaggerSchema.IReference[]) =>
|
282
|
+
(importer: ImportProgrammer) =>
|
205
283
|
(key: string, ensureVariable: boolean = false) =>
|
206
284
|
(required: boolean) =>
|
207
285
|
(schema: ISwaggerSchema): string => {
|
208
286
|
const content: string[] = [];
|
209
|
-
const
|
287
|
+
const commentTagger = (tag: string) => (value?: string) => {
|
210
288
|
const exists: boolean =
|
211
289
|
(!!schema.description?.length &&
|
212
290
|
schema.description.includes(`@${tag}`)) ||
|
@@ -222,14 +300,16 @@ export namespace SchemaProgrammer {
|
|
222
300
|
}
|
223
301
|
|
224
302
|
// STARTS FROM TITLE
|
225
|
-
if (schema.title)
|
303
|
+
if (schema.title) commentTagger("@title")(schema.title);
|
226
304
|
|
227
305
|
// GET TYPE WITH SPECIAL TAGS
|
228
306
|
const type: string =
|
229
|
-
writeSchema(components)(references)(
|
307
|
+
writeSchema(components)(references)(importer)(commentTagger)(
|
308
|
+
true,
|
309
|
+
)(schema);
|
230
310
|
|
231
311
|
// ENDS WITH DEPRECATED TAG
|
232
|
-
if (schema.deprecated)
|
312
|
+
if (schema.deprecated) commentTagger("@deprecated")();
|
233
313
|
|
234
314
|
const description: string =
|
235
315
|
content.length === 0
|
@@ -255,3 +335,13 @@ export namespace SchemaProgrammer {
|
|
255
335
|
.map((l) => `${" ".repeat(size)}${l}`)
|
256
336
|
.join("\n");
|
257
337
|
}
|
338
|
+
|
339
|
+
const FORMATS = new Set([
|
340
|
+
"email",
|
341
|
+
"uuid",
|
342
|
+
"ipv4",
|
343
|
+
"ipv6",
|
344
|
+
"url",
|
345
|
+
"date",
|
346
|
+
"date-time",
|
347
|
+
]);
|
@@ -1,5 +1,6 @@
|
|
1
1
|
export type ISwaggerSchema =
|
2
2
|
| ISwaggerSchema.IUnknown
|
3
|
+
| ISwaggerSchema.INullOnly
|
3
4
|
| ISwaggerSchema.IAnyOf
|
4
5
|
| ISwaggerSchema.IOneOf
|
5
6
|
| ISwaggerSchema.IBoolean
|
@@ -13,6 +14,10 @@ export namespace ISwaggerSchema {
|
|
13
14
|
export interface IUnknown extends IAttribute {
|
14
15
|
type?: undefined;
|
15
16
|
}
|
17
|
+
export interface INullOnly extends IAttribute {
|
18
|
+
type: "null";
|
19
|
+
}
|
20
|
+
|
16
21
|
export interface IAnyOf extends IAttribute {
|
17
22
|
anyOf: ISwaggerSchema[];
|
18
23
|
}
|
@@ -9,6 +9,10 @@ export namespace JsonTypeChecker {
|
|
9
9
|
schema: ISwaggerSchema,
|
10
10
|
): schema is ISwaggerSchema.IOneOf => (schema as any).oneOf !== undefined;
|
11
11
|
|
12
|
+
export const isNullOnly = (
|
13
|
+
schema: ISwaggerSchema,
|
14
|
+
): schema is ISwaggerSchema.INullOnly => (schema as any).type === "null";
|
15
|
+
|
12
16
|
export const isBoolean = (
|
13
17
|
schema: ISwaggerSchema,
|
14
18
|
): schema is ISwaggerSchema.IBoolean => (schema as any).type === "boolean";
|