@autobe/compiler 0.30.0-dev.20260315 → 0.30.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/LICENSE +661 -661
- package/lib/database/validateDatabaseApplication.js +318 -318
- package/lib/raw/AutoBeCompilerCommonTemplate.js +5 -5
- package/lib/raw/AutoBeCompilerCommonTemplate.js.map +1 -1
- package/lib/raw/AutoBeCompilerInterfaceTemplate.js +4 -4
- package/lib/raw/AutoBeCompilerInterfaceTemplate.js.map +1 -1
- package/lib/raw/AutoBeCompilerRealizeTemplate.js +27 -27
- package/lib/raw/AutoBeCompilerRealizeTemplate.js.map +1 -1
- package/lib/raw/AutoBeCompilerRealizeTemplateOfPostgres.js +4 -4
- package/lib/raw/AutoBeCompilerRealizeTemplateOfPostgres.js.map +1 -1
- package/lib/raw/AutoBeCompilerRealizeTemplateOfSQLite.js +4 -4
- package/lib/raw/AutoBeCompilerRealizeTemplateOfSQLite.js.map +1 -1
- package/lib/raw/AutoBeCompilerTestTemplate.js +8 -8
- package/lib/raw/AutoBeCompilerTestTemplate.js.map +1 -1
- package/lib/raw/nestjs.json +1640 -1640
- package/lib/raw/test.json +130 -130
- package/package.json +4 -4
- package/src/AutoBeCompiler.ts +93 -93
- package/src/AutoBeTypeScriptCompiler.ts +136 -136
- package/src/database/AutoBeDatabaseCompiler.ts +48 -48
- package/src/database/validateDatabaseApplication.ts +873 -873
- package/src/index.ts +5 -5
- package/src/interface/AutoBeInterfaceCompiler.ts +79 -79
- package/src/raw/AutoBeCompilerCommonTemplate.ts +5 -5
- package/src/raw/AutoBeCompilerInterfaceTemplate.ts +4 -4
- package/src/raw/AutoBeCompilerRealizeTemplate.ts +27 -27
- package/src/raw/AutoBeCompilerRealizeTemplateOfPostgres.ts +4 -4
- package/src/raw/AutoBeCompilerRealizeTemplateOfSQLite.ts +4 -4
- package/src/raw/AutoBeCompilerTestTemplate.ts +8 -8
- package/src/raw/nestjs.json +1640 -1640
- package/src/raw/test.json +130 -130
- package/src/realize/AutoBeRealizeCompiler.ts +42 -42
- package/src/realize/testRealizeProject.ts +78 -78
- package/src/realize/writeRealizeControllers.ts +217 -217
- package/src/test/AutoBeTestCompiler.ts +112 -112
- package/src/test/programmers/AutoBeTestAccessorProgrammer.ts +42 -42
- package/src/test/programmers/AutoBeTestFunctionalProgrammer.ts +87 -87
- package/src/test/programmers/AutoBeTestLiteralProgrammer.ts +65 -65
- package/src/test/programmers/AutoBeTestOperatorProgrammer.ts +84 -84
- package/src/test/programmers/AutoBeTestPredicateProgrammer.ts +131 -131
- package/src/test/programmers/AutoBeTestRandomProgrammer.ts +304 -304
- package/src/test/programmers/AutoBeTestStatementProgrammer.ts +154 -154
- package/src/test/programmers/IAutoBeTestApiFunction.ts +6 -6
- package/src/test/programmers/IAutoBeTestProgrammerContext.ts +11 -11
- package/src/test/programmers/writeTestExpression.ts +29 -29
- package/src/test/programmers/writeTestFunction.ts +103 -103
- package/src/test/programmers/writeTestStatement.ts +19 -19
- package/src/utils/ArrayUtil.ts +21 -21
- package/src/utils/FilePrinter.ts +67 -67
- package/src/utils/ProcessUtil.ts +14 -14
- package/src/utils/shrinkCompileResult.ts +16 -16
- package/README.md +0 -261
|
@@ -1,304 +1,304 @@
|
|
|
1
|
-
import { AutoBeTest } from "@autobe/interface";
|
|
2
|
-
import ts from "typescript";
|
|
3
|
-
|
|
4
|
-
import { IAutoBeTestProgrammerContext } from "./IAutoBeTestProgrammerContext";
|
|
5
|
-
import { writeTestExpression } from "./writeTestExpression";
|
|
6
|
-
|
|
7
|
-
export namespace AutoBeTestRandomProgrammer {
|
|
8
|
-
export const pickRandom = (
|
|
9
|
-
ctx: IAutoBeTestProgrammerContext,
|
|
10
|
-
expr: AutoBeTest.IPickRandom,
|
|
11
|
-
): ts.CallExpression =>
|
|
12
|
-
ts.factory.createCallExpression(
|
|
13
|
-
ts.factory.createPropertyAccessExpression(
|
|
14
|
-
ts.factory.createIdentifier(
|
|
15
|
-
ctx.importer.external({
|
|
16
|
-
type: "instance",
|
|
17
|
-
library: "@nestia/e2e",
|
|
18
|
-
name: "RandomGenerator",
|
|
19
|
-
}),
|
|
20
|
-
),
|
|
21
|
-
"pick",
|
|
22
|
-
),
|
|
23
|
-
undefined,
|
|
24
|
-
[writeTestExpression(ctx, expr.array)],
|
|
25
|
-
);
|
|
26
|
-
|
|
27
|
-
export const sampleRandom = (
|
|
28
|
-
ctx: IAutoBeTestProgrammerContext,
|
|
29
|
-
expr: AutoBeTest.ISampleRandom,
|
|
30
|
-
): ts.CallExpression =>
|
|
31
|
-
ts.factory.createCallExpression(
|
|
32
|
-
ts.factory.createPropertyAccessExpression(
|
|
33
|
-
ts.factory.createIdentifier(
|
|
34
|
-
ctx.importer.external({
|
|
35
|
-
type: "instance",
|
|
36
|
-
library: "@nestia/e2e",
|
|
37
|
-
name: "RandomGenerator",
|
|
38
|
-
}),
|
|
39
|
-
),
|
|
40
|
-
"sample",
|
|
41
|
-
),
|
|
42
|
-
undefined,
|
|
43
|
-
[
|
|
44
|
-
writeTestExpression(ctx, expr.array),
|
|
45
|
-
writeTestExpression(ctx, expr.count),
|
|
46
|
-
],
|
|
47
|
-
);
|
|
48
|
-
|
|
49
|
-
export const booleanRandom = (
|
|
50
|
-
_ctx: IAutoBeTestProgrammerContext,
|
|
51
|
-
expr: AutoBeTest.IBooleanRandom,
|
|
52
|
-
): ts.BinaryExpression =>
|
|
53
|
-
ts.factory.createLessThanEquals(
|
|
54
|
-
ts.factory.createCallExpression(
|
|
55
|
-
ts.factory.createPropertyAccessExpression(
|
|
56
|
-
ts.factory.createIdentifier("Math"),
|
|
57
|
-
"random",
|
|
58
|
-
),
|
|
59
|
-
undefined,
|
|
60
|
-
undefined,
|
|
61
|
-
),
|
|
62
|
-
ts.factory.createNumericLiteral(expr.probability ?? 0.5),
|
|
63
|
-
);
|
|
64
|
-
|
|
65
|
-
export const integerRandom = (
|
|
66
|
-
ctx: IAutoBeTestProgrammerContext,
|
|
67
|
-
expr: AutoBeTest.IIntegerRandom,
|
|
68
|
-
): ts.CallExpression => {
|
|
69
|
-
const intersection: ts.TypeNode[] = [
|
|
70
|
-
ts.factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword),
|
|
71
|
-
createTypiaTag(ctx, "Type", [
|
|
72
|
-
ts.factory.createLiteralTypeNode(
|
|
73
|
-
ts.factory.createStringLiteral("int32"),
|
|
74
|
-
),
|
|
75
|
-
]),
|
|
76
|
-
];
|
|
77
|
-
if (expr.minimum !== null && expr.minimum !== undefined)
|
|
78
|
-
intersection.push(
|
|
79
|
-
createTypiaTag(ctx, "Minimum", [
|
|
80
|
-
ts.factory.createLiteralTypeNode(
|
|
81
|
-
ts.factory.createNumericLiteral(expr.minimum),
|
|
82
|
-
),
|
|
83
|
-
]),
|
|
84
|
-
);
|
|
85
|
-
if (expr.maximum !== null && expr.maximum !== undefined)
|
|
86
|
-
intersection.push(
|
|
87
|
-
createTypiaTag(ctx, "Maximum", [
|
|
88
|
-
ts.factory.createLiteralTypeNode(
|
|
89
|
-
ts.factory.createNumericLiteral(expr.maximum),
|
|
90
|
-
),
|
|
91
|
-
]),
|
|
92
|
-
);
|
|
93
|
-
if (expr.multipleOf !== null && expr.multipleOf !== undefined)
|
|
94
|
-
intersection.push(
|
|
95
|
-
createTypiaTag(ctx, "MultipleOf", [
|
|
96
|
-
ts.factory.createLiteralTypeNode(
|
|
97
|
-
ts.factory.createNumericLiteral(expr.multipleOf),
|
|
98
|
-
),
|
|
99
|
-
]),
|
|
100
|
-
);
|
|
101
|
-
return createTypiaRandom(ctx, intersection);
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
export const numberRandom = (
|
|
105
|
-
ctx: IAutoBeTestProgrammerContext,
|
|
106
|
-
expr: AutoBeTest.INumberRandom,
|
|
107
|
-
): ts.CallExpression => {
|
|
108
|
-
const intersection: ts.TypeNode[] = [
|
|
109
|
-
ts.factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword),
|
|
110
|
-
];
|
|
111
|
-
if (expr.minimum !== null && expr.minimum !== undefined)
|
|
112
|
-
intersection.push(
|
|
113
|
-
createTypiaTag(ctx, "Minimum", [
|
|
114
|
-
ts.factory.createLiteralTypeNode(
|
|
115
|
-
ts.factory.createNumericLiteral(expr.minimum),
|
|
116
|
-
),
|
|
117
|
-
]),
|
|
118
|
-
);
|
|
119
|
-
if (expr.maximum !== null && expr.maximum !== undefined)
|
|
120
|
-
intersection.push(
|
|
121
|
-
createTypiaTag(ctx, "Maximum", [
|
|
122
|
-
ts.factory.createLiteralTypeNode(
|
|
123
|
-
ts.factory.createNumericLiteral(expr.maximum),
|
|
124
|
-
),
|
|
125
|
-
]),
|
|
126
|
-
);
|
|
127
|
-
if (expr.multipleOf !== null && expr.multipleOf !== undefined)
|
|
128
|
-
intersection.push(
|
|
129
|
-
createTypiaTag(ctx, "MultipleOf", [
|
|
130
|
-
ts.factory.createLiteralTypeNode(
|
|
131
|
-
ts.factory.createNumericLiteral(expr.multipleOf),
|
|
132
|
-
),
|
|
133
|
-
]),
|
|
134
|
-
);
|
|
135
|
-
return createTypiaRandom(ctx, intersection);
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
export const stringRandom = (
|
|
139
|
-
ctx: IAutoBeTestProgrammerContext,
|
|
140
|
-
expr: AutoBeTest.IStringRandom,
|
|
141
|
-
): ts.CallExpression => {
|
|
142
|
-
const intersection: ts.TypeNode[] = [
|
|
143
|
-
ts.factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword),
|
|
144
|
-
];
|
|
145
|
-
if (expr.minLength !== null && expr.minLength !== undefined)
|
|
146
|
-
intersection.push(
|
|
147
|
-
createTypiaTag(ctx, "MinLength", [
|
|
148
|
-
ts.factory.createLiteralTypeNode(
|
|
149
|
-
ts.factory.createNumericLiteral(expr.minLength),
|
|
150
|
-
),
|
|
151
|
-
]),
|
|
152
|
-
);
|
|
153
|
-
if (expr.maxLength !== null && expr.maxLength !== undefined)
|
|
154
|
-
intersection.push(
|
|
155
|
-
createTypiaTag(ctx, "MaxLength", [
|
|
156
|
-
ts.factory.createLiteralTypeNode(
|
|
157
|
-
ts.factory.createNumericLiteral(expr.maxLength),
|
|
158
|
-
),
|
|
159
|
-
]),
|
|
160
|
-
);
|
|
161
|
-
return createTypiaRandom(ctx, intersection);
|
|
162
|
-
};
|
|
163
|
-
|
|
164
|
-
export const formatRandom = (
|
|
165
|
-
ctx: IAutoBeTestProgrammerContext,
|
|
166
|
-
expr: AutoBeTest.IFormatRandom,
|
|
167
|
-
): ts.CallExpression =>
|
|
168
|
-
ts.factory.createCallExpression(
|
|
169
|
-
ts.factory.createPropertyAccessExpression(
|
|
170
|
-
ts.factory.createIdentifier(
|
|
171
|
-
ctx.importer.external({
|
|
172
|
-
type: "default",
|
|
173
|
-
library: "typia",
|
|
174
|
-
name: "typia",
|
|
175
|
-
}),
|
|
176
|
-
),
|
|
177
|
-
"random",
|
|
178
|
-
),
|
|
179
|
-
[
|
|
180
|
-
ts.factory.createIntersectionTypeNode([
|
|
181
|
-
ts.factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword),
|
|
182
|
-
ts.factory.createTypeReferenceNode(
|
|
183
|
-
ts.factory.createQualifiedName(
|
|
184
|
-
ts.factory.createIdentifier(
|
|
185
|
-
ctx.importer.external({
|
|
186
|
-
type: "instance",
|
|
187
|
-
library: "typia",
|
|
188
|
-
name: "tags",
|
|
189
|
-
}),
|
|
190
|
-
),
|
|
191
|
-
ts.factory.createIdentifier("Format"),
|
|
192
|
-
),
|
|
193
|
-
[
|
|
194
|
-
ts.factory.createLiteralTypeNode(
|
|
195
|
-
ts.factory.createStringLiteral(expr.format),
|
|
196
|
-
),
|
|
197
|
-
],
|
|
198
|
-
),
|
|
199
|
-
]),
|
|
200
|
-
],
|
|
201
|
-
[],
|
|
202
|
-
);
|
|
203
|
-
|
|
204
|
-
export const patternRandom = (
|
|
205
|
-
ctx: IAutoBeTestProgrammerContext,
|
|
206
|
-
expr: AutoBeTest.IPatternRandom,
|
|
207
|
-
): ts.CallExpression =>
|
|
208
|
-
ts.factory.createCallExpression(
|
|
209
|
-
ts.factory.createPropertyAccessExpression(
|
|
210
|
-
ts.factory.createIdentifier(
|
|
211
|
-
ctx.importer.external({
|
|
212
|
-
type: "default",
|
|
213
|
-
library: "typia",
|
|
214
|
-
name: "typia",
|
|
215
|
-
}),
|
|
216
|
-
),
|
|
217
|
-
"random",
|
|
218
|
-
),
|
|
219
|
-
[
|
|
220
|
-
ts.factory.createIntersectionTypeNode([
|
|
221
|
-
ts.factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword),
|
|
222
|
-
ts.factory.createTypeReferenceNode(
|
|
223
|
-
ts.factory.createQualifiedName(
|
|
224
|
-
ts.factory.createIdentifier(
|
|
225
|
-
ctx.importer.external({
|
|
226
|
-
type: "instance",
|
|
227
|
-
library: "typia",
|
|
228
|
-
name: "tags",
|
|
229
|
-
}),
|
|
230
|
-
),
|
|
231
|
-
ts.factory.createIdentifier("Pattern"),
|
|
232
|
-
),
|
|
233
|
-
[
|
|
234
|
-
ts.factory.createLiteralTypeNode(
|
|
235
|
-
ts.factory.createStringLiteral(expr.pattern),
|
|
236
|
-
),
|
|
237
|
-
],
|
|
238
|
-
),
|
|
239
|
-
]),
|
|
240
|
-
],
|
|
241
|
-
[],
|
|
242
|
-
);
|
|
243
|
-
|
|
244
|
-
export const keywordRandom = (
|
|
245
|
-
ctx: IAutoBeTestProgrammerContext,
|
|
246
|
-
expr: AutoBeTest.IKeywordRandom,
|
|
247
|
-
): ts.Expression =>
|
|
248
|
-
ts.factory.createCallExpression(
|
|
249
|
-
ts.factory.createPropertyAccessExpression(
|
|
250
|
-
ts.factory.createIdentifier(
|
|
251
|
-
ctx.importer.external({
|
|
252
|
-
type: "instance",
|
|
253
|
-
library: "@nestia/e2e",
|
|
254
|
-
name: "RandomGenerator",
|
|
255
|
-
}),
|
|
256
|
-
),
|
|
257
|
-
expr.keyword,
|
|
258
|
-
),
|
|
259
|
-
undefined,
|
|
260
|
-
undefined,
|
|
261
|
-
);
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
const createTypiaTag = (
|
|
265
|
-
ctx: IAutoBeTestProgrammerContext,
|
|
266
|
-
name: string,
|
|
267
|
-
typeArguments: ts.TypeNode[],
|
|
268
|
-
) =>
|
|
269
|
-
ts.factory.createTypeReferenceNode(
|
|
270
|
-
ts.factory.createQualifiedName(
|
|
271
|
-
ts.factory.createIdentifier(
|
|
272
|
-
ctx.importer.external({
|
|
273
|
-
type: "instance",
|
|
274
|
-
library: "typia",
|
|
275
|
-
name: "tags",
|
|
276
|
-
}),
|
|
277
|
-
),
|
|
278
|
-
ts.factory.createIdentifier(name),
|
|
279
|
-
),
|
|
280
|
-
typeArguments,
|
|
281
|
-
);
|
|
282
|
-
|
|
283
|
-
const createTypiaRandom = (
|
|
284
|
-
ctx: IAutoBeTestProgrammerContext,
|
|
285
|
-
typeArguments: ts.TypeNode[] = [],
|
|
286
|
-
) =>
|
|
287
|
-
ts.factory.createCallExpression(
|
|
288
|
-
ts.factory.createPropertyAccessExpression(
|
|
289
|
-
ts.factory.createIdentifier(
|
|
290
|
-
ctx.importer.external({
|
|
291
|
-
type: "default",
|
|
292
|
-
library: "typia",
|
|
293
|
-
name: "typia",
|
|
294
|
-
}),
|
|
295
|
-
),
|
|
296
|
-
"random",
|
|
297
|
-
),
|
|
298
|
-
typeArguments.length === 0
|
|
299
|
-
? undefined
|
|
300
|
-
: typeArguments.length === 1
|
|
301
|
-
? typeArguments
|
|
302
|
-
: [ts.factory.createIntersectionTypeNode(typeArguments)],
|
|
303
|
-
undefined,
|
|
304
|
-
);
|
|
1
|
+
import { AutoBeTest } from "@autobe/interface";
|
|
2
|
+
import ts from "typescript";
|
|
3
|
+
|
|
4
|
+
import { IAutoBeTestProgrammerContext } from "./IAutoBeTestProgrammerContext";
|
|
5
|
+
import { writeTestExpression } from "./writeTestExpression";
|
|
6
|
+
|
|
7
|
+
export namespace AutoBeTestRandomProgrammer {
|
|
8
|
+
export const pickRandom = (
|
|
9
|
+
ctx: IAutoBeTestProgrammerContext,
|
|
10
|
+
expr: AutoBeTest.IPickRandom,
|
|
11
|
+
): ts.CallExpression =>
|
|
12
|
+
ts.factory.createCallExpression(
|
|
13
|
+
ts.factory.createPropertyAccessExpression(
|
|
14
|
+
ts.factory.createIdentifier(
|
|
15
|
+
ctx.importer.external({
|
|
16
|
+
type: "instance",
|
|
17
|
+
library: "@nestia/e2e",
|
|
18
|
+
name: "RandomGenerator",
|
|
19
|
+
}),
|
|
20
|
+
),
|
|
21
|
+
"pick",
|
|
22
|
+
),
|
|
23
|
+
undefined,
|
|
24
|
+
[writeTestExpression(ctx, expr.array)],
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
export const sampleRandom = (
|
|
28
|
+
ctx: IAutoBeTestProgrammerContext,
|
|
29
|
+
expr: AutoBeTest.ISampleRandom,
|
|
30
|
+
): ts.CallExpression =>
|
|
31
|
+
ts.factory.createCallExpression(
|
|
32
|
+
ts.factory.createPropertyAccessExpression(
|
|
33
|
+
ts.factory.createIdentifier(
|
|
34
|
+
ctx.importer.external({
|
|
35
|
+
type: "instance",
|
|
36
|
+
library: "@nestia/e2e",
|
|
37
|
+
name: "RandomGenerator",
|
|
38
|
+
}),
|
|
39
|
+
),
|
|
40
|
+
"sample",
|
|
41
|
+
),
|
|
42
|
+
undefined,
|
|
43
|
+
[
|
|
44
|
+
writeTestExpression(ctx, expr.array),
|
|
45
|
+
writeTestExpression(ctx, expr.count),
|
|
46
|
+
],
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
export const booleanRandom = (
|
|
50
|
+
_ctx: IAutoBeTestProgrammerContext,
|
|
51
|
+
expr: AutoBeTest.IBooleanRandom,
|
|
52
|
+
): ts.BinaryExpression =>
|
|
53
|
+
ts.factory.createLessThanEquals(
|
|
54
|
+
ts.factory.createCallExpression(
|
|
55
|
+
ts.factory.createPropertyAccessExpression(
|
|
56
|
+
ts.factory.createIdentifier("Math"),
|
|
57
|
+
"random",
|
|
58
|
+
),
|
|
59
|
+
undefined,
|
|
60
|
+
undefined,
|
|
61
|
+
),
|
|
62
|
+
ts.factory.createNumericLiteral(expr.probability ?? 0.5),
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
export const integerRandom = (
|
|
66
|
+
ctx: IAutoBeTestProgrammerContext,
|
|
67
|
+
expr: AutoBeTest.IIntegerRandom,
|
|
68
|
+
): ts.CallExpression => {
|
|
69
|
+
const intersection: ts.TypeNode[] = [
|
|
70
|
+
ts.factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword),
|
|
71
|
+
createTypiaTag(ctx, "Type", [
|
|
72
|
+
ts.factory.createLiteralTypeNode(
|
|
73
|
+
ts.factory.createStringLiteral("int32"),
|
|
74
|
+
),
|
|
75
|
+
]),
|
|
76
|
+
];
|
|
77
|
+
if (expr.minimum !== null && expr.minimum !== undefined)
|
|
78
|
+
intersection.push(
|
|
79
|
+
createTypiaTag(ctx, "Minimum", [
|
|
80
|
+
ts.factory.createLiteralTypeNode(
|
|
81
|
+
ts.factory.createNumericLiteral(expr.minimum),
|
|
82
|
+
),
|
|
83
|
+
]),
|
|
84
|
+
);
|
|
85
|
+
if (expr.maximum !== null && expr.maximum !== undefined)
|
|
86
|
+
intersection.push(
|
|
87
|
+
createTypiaTag(ctx, "Maximum", [
|
|
88
|
+
ts.factory.createLiteralTypeNode(
|
|
89
|
+
ts.factory.createNumericLiteral(expr.maximum),
|
|
90
|
+
),
|
|
91
|
+
]),
|
|
92
|
+
);
|
|
93
|
+
if (expr.multipleOf !== null && expr.multipleOf !== undefined)
|
|
94
|
+
intersection.push(
|
|
95
|
+
createTypiaTag(ctx, "MultipleOf", [
|
|
96
|
+
ts.factory.createLiteralTypeNode(
|
|
97
|
+
ts.factory.createNumericLiteral(expr.multipleOf),
|
|
98
|
+
),
|
|
99
|
+
]),
|
|
100
|
+
);
|
|
101
|
+
return createTypiaRandom(ctx, intersection);
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
export const numberRandom = (
|
|
105
|
+
ctx: IAutoBeTestProgrammerContext,
|
|
106
|
+
expr: AutoBeTest.INumberRandom,
|
|
107
|
+
): ts.CallExpression => {
|
|
108
|
+
const intersection: ts.TypeNode[] = [
|
|
109
|
+
ts.factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword),
|
|
110
|
+
];
|
|
111
|
+
if (expr.minimum !== null && expr.minimum !== undefined)
|
|
112
|
+
intersection.push(
|
|
113
|
+
createTypiaTag(ctx, "Minimum", [
|
|
114
|
+
ts.factory.createLiteralTypeNode(
|
|
115
|
+
ts.factory.createNumericLiteral(expr.minimum),
|
|
116
|
+
),
|
|
117
|
+
]),
|
|
118
|
+
);
|
|
119
|
+
if (expr.maximum !== null && expr.maximum !== undefined)
|
|
120
|
+
intersection.push(
|
|
121
|
+
createTypiaTag(ctx, "Maximum", [
|
|
122
|
+
ts.factory.createLiteralTypeNode(
|
|
123
|
+
ts.factory.createNumericLiteral(expr.maximum),
|
|
124
|
+
),
|
|
125
|
+
]),
|
|
126
|
+
);
|
|
127
|
+
if (expr.multipleOf !== null && expr.multipleOf !== undefined)
|
|
128
|
+
intersection.push(
|
|
129
|
+
createTypiaTag(ctx, "MultipleOf", [
|
|
130
|
+
ts.factory.createLiteralTypeNode(
|
|
131
|
+
ts.factory.createNumericLiteral(expr.multipleOf),
|
|
132
|
+
),
|
|
133
|
+
]),
|
|
134
|
+
);
|
|
135
|
+
return createTypiaRandom(ctx, intersection);
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
export const stringRandom = (
|
|
139
|
+
ctx: IAutoBeTestProgrammerContext,
|
|
140
|
+
expr: AutoBeTest.IStringRandom,
|
|
141
|
+
): ts.CallExpression => {
|
|
142
|
+
const intersection: ts.TypeNode[] = [
|
|
143
|
+
ts.factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword),
|
|
144
|
+
];
|
|
145
|
+
if (expr.minLength !== null && expr.minLength !== undefined)
|
|
146
|
+
intersection.push(
|
|
147
|
+
createTypiaTag(ctx, "MinLength", [
|
|
148
|
+
ts.factory.createLiteralTypeNode(
|
|
149
|
+
ts.factory.createNumericLiteral(expr.minLength),
|
|
150
|
+
),
|
|
151
|
+
]),
|
|
152
|
+
);
|
|
153
|
+
if (expr.maxLength !== null && expr.maxLength !== undefined)
|
|
154
|
+
intersection.push(
|
|
155
|
+
createTypiaTag(ctx, "MaxLength", [
|
|
156
|
+
ts.factory.createLiteralTypeNode(
|
|
157
|
+
ts.factory.createNumericLiteral(expr.maxLength),
|
|
158
|
+
),
|
|
159
|
+
]),
|
|
160
|
+
);
|
|
161
|
+
return createTypiaRandom(ctx, intersection);
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
export const formatRandom = (
|
|
165
|
+
ctx: IAutoBeTestProgrammerContext,
|
|
166
|
+
expr: AutoBeTest.IFormatRandom,
|
|
167
|
+
): ts.CallExpression =>
|
|
168
|
+
ts.factory.createCallExpression(
|
|
169
|
+
ts.factory.createPropertyAccessExpression(
|
|
170
|
+
ts.factory.createIdentifier(
|
|
171
|
+
ctx.importer.external({
|
|
172
|
+
type: "default",
|
|
173
|
+
library: "typia",
|
|
174
|
+
name: "typia",
|
|
175
|
+
}),
|
|
176
|
+
),
|
|
177
|
+
"random",
|
|
178
|
+
),
|
|
179
|
+
[
|
|
180
|
+
ts.factory.createIntersectionTypeNode([
|
|
181
|
+
ts.factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword),
|
|
182
|
+
ts.factory.createTypeReferenceNode(
|
|
183
|
+
ts.factory.createQualifiedName(
|
|
184
|
+
ts.factory.createIdentifier(
|
|
185
|
+
ctx.importer.external({
|
|
186
|
+
type: "instance",
|
|
187
|
+
library: "typia",
|
|
188
|
+
name: "tags",
|
|
189
|
+
}),
|
|
190
|
+
),
|
|
191
|
+
ts.factory.createIdentifier("Format"),
|
|
192
|
+
),
|
|
193
|
+
[
|
|
194
|
+
ts.factory.createLiteralTypeNode(
|
|
195
|
+
ts.factory.createStringLiteral(expr.format),
|
|
196
|
+
),
|
|
197
|
+
],
|
|
198
|
+
),
|
|
199
|
+
]),
|
|
200
|
+
],
|
|
201
|
+
[],
|
|
202
|
+
);
|
|
203
|
+
|
|
204
|
+
export const patternRandom = (
|
|
205
|
+
ctx: IAutoBeTestProgrammerContext,
|
|
206
|
+
expr: AutoBeTest.IPatternRandom,
|
|
207
|
+
): ts.CallExpression =>
|
|
208
|
+
ts.factory.createCallExpression(
|
|
209
|
+
ts.factory.createPropertyAccessExpression(
|
|
210
|
+
ts.factory.createIdentifier(
|
|
211
|
+
ctx.importer.external({
|
|
212
|
+
type: "default",
|
|
213
|
+
library: "typia",
|
|
214
|
+
name: "typia",
|
|
215
|
+
}),
|
|
216
|
+
),
|
|
217
|
+
"random",
|
|
218
|
+
),
|
|
219
|
+
[
|
|
220
|
+
ts.factory.createIntersectionTypeNode([
|
|
221
|
+
ts.factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword),
|
|
222
|
+
ts.factory.createTypeReferenceNode(
|
|
223
|
+
ts.factory.createQualifiedName(
|
|
224
|
+
ts.factory.createIdentifier(
|
|
225
|
+
ctx.importer.external({
|
|
226
|
+
type: "instance",
|
|
227
|
+
library: "typia",
|
|
228
|
+
name: "tags",
|
|
229
|
+
}),
|
|
230
|
+
),
|
|
231
|
+
ts.factory.createIdentifier("Pattern"),
|
|
232
|
+
),
|
|
233
|
+
[
|
|
234
|
+
ts.factory.createLiteralTypeNode(
|
|
235
|
+
ts.factory.createStringLiteral(expr.pattern),
|
|
236
|
+
),
|
|
237
|
+
],
|
|
238
|
+
),
|
|
239
|
+
]),
|
|
240
|
+
],
|
|
241
|
+
[],
|
|
242
|
+
);
|
|
243
|
+
|
|
244
|
+
export const keywordRandom = (
|
|
245
|
+
ctx: IAutoBeTestProgrammerContext,
|
|
246
|
+
expr: AutoBeTest.IKeywordRandom,
|
|
247
|
+
): ts.Expression =>
|
|
248
|
+
ts.factory.createCallExpression(
|
|
249
|
+
ts.factory.createPropertyAccessExpression(
|
|
250
|
+
ts.factory.createIdentifier(
|
|
251
|
+
ctx.importer.external({
|
|
252
|
+
type: "instance",
|
|
253
|
+
library: "@nestia/e2e",
|
|
254
|
+
name: "RandomGenerator",
|
|
255
|
+
}),
|
|
256
|
+
),
|
|
257
|
+
expr.keyword,
|
|
258
|
+
),
|
|
259
|
+
undefined,
|
|
260
|
+
undefined,
|
|
261
|
+
);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
const createTypiaTag = (
|
|
265
|
+
ctx: IAutoBeTestProgrammerContext,
|
|
266
|
+
name: string,
|
|
267
|
+
typeArguments: ts.TypeNode[],
|
|
268
|
+
) =>
|
|
269
|
+
ts.factory.createTypeReferenceNode(
|
|
270
|
+
ts.factory.createQualifiedName(
|
|
271
|
+
ts.factory.createIdentifier(
|
|
272
|
+
ctx.importer.external({
|
|
273
|
+
type: "instance",
|
|
274
|
+
library: "typia",
|
|
275
|
+
name: "tags",
|
|
276
|
+
}),
|
|
277
|
+
),
|
|
278
|
+
ts.factory.createIdentifier(name),
|
|
279
|
+
),
|
|
280
|
+
typeArguments,
|
|
281
|
+
);
|
|
282
|
+
|
|
283
|
+
const createTypiaRandom = (
|
|
284
|
+
ctx: IAutoBeTestProgrammerContext,
|
|
285
|
+
typeArguments: ts.TypeNode[] = [],
|
|
286
|
+
) =>
|
|
287
|
+
ts.factory.createCallExpression(
|
|
288
|
+
ts.factory.createPropertyAccessExpression(
|
|
289
|
+
ts.factory.createIdentifier(
|
|
290
|
+
ctx.importer.external({
|
|
291
|
+
type: "default",
|
|
292
|
+
library: "typia",
|
|
293
|
+
name: "typia",
|
|
294
|
+
}),
|
|
295
|
+
),
|
|
296
|
+
"random",
|
|
297
|
+
),
|
|
298
|
+
typeArguments.length === 0
|
|
299
|
+
? undefined
|
|
300
|
+
: typeArguments.length === 1
|
|
301
|
+
? typeArguments
|
|
302
|
+
: [ts.factory.createIntersectionTypeNode(typeArguments)],
|
|
303
|
+
undefined,
|
|
304
|
+
);
|