typia 3.7.0 → 3.7.1-dev.20230406
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 +28 -28
- package/lib/IRandomGenerator.d.ts +11 -0
- package/lib/factories/IdentifierFactory.d.ts +1 -1
- package/lib/factories/IdentifierFactory.js +10 -2
- package/lib/factories/IdentifierFactory.js.map +1 -1
- package/lib/metadata/ICommentTag.d.ts +4 -0
- package/lib/metadata/ICommentTag.js +3 -0
- package/lib/metadata/ICommentTag.js.map +1 -0
- package/lib/programmers/RandomProgrammer.d.ts +1 -1
- package/lib/programmers/RandomProgrammer.js +95 -82
- package/lib/programmers/RandomProgrammer.js.map +1 -1
- package/lib/programmers/helpers/RandomJoiner.d.ts +4 -3
- package/lib/programmers/helpers/RandomJoiner.js +10 -7
- package/lib/programmers/helpers/RandomJoiner.js.map +1 -1
- package/lib/programmers/helpers/RandomRanger.d.ts +1 -1
- package/lib/programmers/internal/application_native.d.ts +1 -4
- package/lib/programmers/internal/application_native.js.map +1 -1
- package/lib/programmers/internal/check_array.js +2 -1
- package/lib/programmers/internal/check_array.js.map +1 -1
- package/lib/programmers/internal/check_array_length.js +20 -23
- package/lib/programmers/internal/check_array_length.js.map +1 -1
- package/lib/programmers/internal/check_custom.d.ts +1 -5
- package/lib/programmers/internal/check_custom.js +5 -15
- package/lib/programmers/internal/check_custom.js.map +1 -1
- package/lib/programmers/internal/check_number.js.map +1 -1
- package/lib/programmers/internal/check_object.d.ts +1 -13
- package/lib/programmers/internal/check_object.js.map +1 -1
- package/lib/programmers/internal/check_union_array_like.d.ts +1 -21
- package/lib/programmers/internal/check_union_array_like.js.map +1 -1
- package/lib/programmers/internal/feature_object_entries.d.ts +1 -10
- package/lib/programmers/internal/feature_object_entries.js.map +1 -1
- package/lib/programmers/internal/get_comment_tags.d.ts +1 -0
- package/lib/programmers/internal/get_comment_tags.js +25 -0
- package/lib/programmers/internal/get_comment_tags.js.map +1 -0
- package/lib/programmers/internal/metadata_to_pattern.d.ts +1 -2
- package/lib/programmers/internal/metadata_to_pattern.js.map +1 -1
- package/lib/programmers/internal/random_custom.d.ts +1 -0
- package/lib/programmers/internal/random_custom.js +20 -0
- package/lib/programmers/internal/random_custom.js.map +1 -0
- package/lib/programmers/internal/stringify_dynamic_properties.js.map +1 -1
- package/lib/programmers/internal/stringify_regular_properties.js.map +1 -1
- package/lib/transformers/CallExpressionTransformer.js +2 -2
- package/lib/transformers/CallExpressionTransformer.js.map +1 -1
- package/lib/transformers/features/miscellaneous/{CreateRandomGenerator.js → CreateRandomTransformer.js} +3 -3
- package/lib/transformers/features/miscellaneous/CreateRandomTransformer.js.map +1 -0
- package/lib/typings/Customizable.d.ts +0 -1
- package/package.json +1 -1
- package/src/IRandomGenerator.ts +16 -0
- package/src/factories/IdentifierFactory.ts +13 -5
- package/src/factories/MetadataTagFactory.ts +6 -6
- package/src/metadata/ICommentTag.ts +4 -0
- package/src/programmers/RandomProgrammer.ts +125 -100
- package/src/programmers/helpers/RandomJoiner.ts +19 -7
- package/src/programmers/helpers/RandomRanger.ts +1 -1
- package/src/programmers/internal/application_native.ts +3 -0
- package/src/programmers/internal/check_array.ts +5 -1
- package/src/programmers/internal/check_array_length.ts +5 -10
- package/src/programmers/internal/check_custom.ts +21 -29
- package/src/programmers/internal/check_number.ts +3 -0
- package/src/programmers/internal/check_object.ts +7 -0
- package/src/programmers/internal/check_union_array_like.ts +7 -0
- package/src/programmers/internal/feature_object_entries.ts +3 -0
- package/src/programmers/internal/get_comment_tags.ts +23 -0
- package/src/programmers/internal/metadata_to_pattern.ts +3 -0
- package/src/programmers/internal/random_custom.ts +30 -0
- package/src/programmers/internal/stringify_dynamic_properties.ts +3 -0
- package/src/programmers/internal/stringify_regular_properties.ts +3 -0
- package/src/transformers/CallExpressionTransformer.ts +1 -1
- package/src/transformers/features/miscellaneous/{CreateRandomGenerator.ts → CreateRandomTransformer.ts} +1 -0
- package/src/typings/Customizable.ts +0 -1
- package/lib/transformers/features/miscellaneous/CreateRandomGenerator.js.map +0 -1
- /package/lib/transformers/features/miscellaneous/{CreateRandomGenerator.d.ts → CreateRandomTransformer.d.ts} +0 -0
|
@@ -51,8 +51,8 @@ export namespace MetadataTagFactory {
|
|
|
51
51
|
) => IMetadataTag | null
|
|
52
52
|
> = {
|
|
53
53
|
/* -----------------------------------------------------------
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
ARRAY
|
|
55
|
+
----------------------------------------------------------- */
|
|
56
56
|
items: (identifier, metadata, text, output) => {
|
|
57
57
|
validate(identifier, metadata, output, "items", "array", [
|
|
58
58
|
"minItems",
|
|
@@ -82,8 +82,8 @@ export namespace MetadataTagFactory {
|
|
|
82
82
|
},
|
|
83
83
|
|
|
84
84
|
/* -----------------------------------------------------------
|
|
85
|
-
|
|
86
|
-
|
|
85
|
+
NUMBER
|
|
86
|
+
----------------------------------------------------------- */
|
|
87
87
|
type: (identifier, metadata, text, output) => {
|
|
88
88
|
validate(identifier, metadata, output, "type", "number", []);
|
|
89
89
|
if (text !== "int" && text !== "uint")
|
|
@@ -168,8 +168,8 @@ export namespace MetadataTagFactory {
|
|
|
168
168
|
},
|
|
169
169
|
|
|
170
170
|
/* -----------------------------------------------------------
|
|
171
|
-
|
|
172
|
-
|
|
171
|
+
STRING
|
|
172
|
+
----------------------------------------------------------- */
|
|
173
173
|
format: (identifier, metadata, str, output) => {
|
|
174
174
|
validate(identifier, metadata, output, "format", "string", [
|
|
175
175
|
"pattern",
|
|
@@ -8,6 +8,7 @@ import { StatementFactory } from "../factories/StatementFactory";
|
|
|
8
8
|
import { TemplateFactory } from "../factories/TemplateFactory";
|
|
9
9
|
import { TypeFactory } from "../factories/TypeFactory";
|
|
10
10
|
|
|
11
|
+
import { ICommentTag } from "../metadata/ICommentTag";
|
|
11
12
|
import { IMetadataTag } from "../metadata/IMetadataTag";
|
|
12
13
|
import { Metadata } from "../metadata/Metadata";
|
|
13
14
|
|
|
@@ -16,11 +17,13 @@ import { IProject } from "../transformers/IProject";
|
|
|
16
17
|
import { FunctionImporter } from "./helpers/FunctionImporeter";
|
|
17
18
|
import { RandomJoiner } from "./helpers/RandomJoiner";
|
|
18
19
|
import { RandomRanger } from "./helpers/RandomRanger";
|
|
20
|
+
import { random_custom } from "./internal/random_custom";
|
|
19
21
|
|
|
20
22
|
export namespace RandomProgrammer {
|
|
21
23
|
export function generate(
|
|
22
24
|
project: IProject,
|
|
23
25
|
modulo: ts.LeftHandSideExpression,
|
|
26
|
+
init?: ts.Expression,
|
|
24
27
|
) {
|
|
25
28
|
const importer: FunctionImporter = new FunctionImporter();
|
|
26
29
|
return (type: ts.Type, name?: string) => {
|
|
@@ -42,7 +45,7 @@ export namespace RandomProgrammer {
|
|
|
42
45
|
const output: ts.Expression = decode(importer)({
|
|
43
46
|
object: false,
|
|
44
47
|
recursive: false,
|
|
45
|
-
})(meta, []);
|
|
48
|
+
})(meta, [], []);
|
|
46
49
|
|
|
47
50
|
return ts.factory.createArrowFunction(
|
|
48
51
|
undefined,
|
|
@@ -53,15 +56,8 @@ export namespace RandomProgrammer {
|
|
|
53
56
|
ts.factory.createTypeReferenceNode(
|
|
54
57
|
"Partial<typia.IRandomGenerator>",
|
|
55
58
|
),
|
|
56
|
-
|
|
57
|
-
ts.factory.
|
|
58
|
-
ts.factory.createAsExpression(
|
|
59
|
-
modulo,
|
|
60
|
-
TypeFactory.keyword("any"),
|
|
61
|
-
),
|
|
62
|
-
),
|
|
63
|
-
"generator",
|
|
64
|
-
),
|
|
59
|
+
init ??
|
|
60
|
+
ts.factory.createToken(ts.SyntaxKind.QuestionToken),
|
|
65
61
|
),
|
|
66
62
|
],
|
|
67
63
|
ts.factory.createTypeReferenceNode(
|
|
@@ -122,7 +118,11 @@ export namespace RandomProgrammer {
|
|
|
122
118
|
const decode =
|
|
123
119
|
(importer: FunctionImporter) =>
|
|
124
120
|
(explore: IExplore) =>
|
|
125
|
-
(
|
|
121
|
+
(
|
|
122
|
+
meta: Metadata,
|
|
123
|
+
tags: IMetadataTag[],
|
|
124
|
+
comments: ICommentTag[],
|
|
125
|
+
): ts.Expression => {
|
|
126
126
|
const expressions: ts.Expression[] = [];
|
|
127
127
|
if (meta.any)
|
|
128
128
|
expressions.push(
|
|
@@ -137,35 +137,41 @@ export namespace RandomProgrammer {
|
|
|
137
137
|
if (meta.nullable === true)
|
|
138
138
|
expressions.push(ts.factory.createNull());
|
|
139
139
|
|
|
140
|
-
//
|
|
140
|
+
// CONSTANT TYPES
|
|
141
141
|
for (const constant of meta.constants)
|
|
142
142
|
for (const value of constant.values)
|
|
143
143
|
expressions.push(decode_atomic(value));
|
|
144
|
+
|
|
145
|
+
// ATOMIC VARIABLES
|
|
144
146
|
for (const template of meta.templates)
|
|
145
147
|
expressions.push(decode_template(importer)(explore)(template));
|
|
146
148
|
for (const atomic of meta.atomics)
|
|
147
149
|
if (atomic === "boolean")
|
|
148
150
|
expressions.push(decode_boolean(importer));
|
|
149
151
|
else if (atomic === "number")
|
|
150
|
-
expressions.push(decode_number(importer)(tags));
|
|
152
|
+
expressions.push(decode_number(importer)(tags)(comments));
|
|
151
153
|
else if (atomic === "string")
|
|
152
|
-
expressions.push(decode_string(importer)(tags));
|
|
154
|
+
expressions.push(decode_string(importer)(tags)(comments));
|
|
153
155
|
else if (atomic === "bigint")
|
|
154
|
-
expressions.push(decode_bigint(importer)(tags));
|
|
156
|
+
expressions.push(decode_bigint(importer)(tags)(comments));
|
|
155
157
|
|
|
156
158
|
// INSTANCE TYPES
|
|
157
159
|
if (meta.resolved)
|
|
158
160
|
expressions.push(
|
|
159
|
-
decode(importer)(explore)(meta.resolved, tags),
|
|
161
|
+
decode(importer)(explore)(meta.resolved, tags, comments),
|
|
160
162
|
);
|
|
161
163
|
for (const t of meta.tuples)
|
|
162
164
|
expressions.push(
|
|
163
|
-
RandomJoiner.tuple(decode(importer)(explore))(
|
|
165
|
+
RandomJoiner.tuple(decode(importer)(explore))(
|
|
166
|
+
t,
|
|
167
|
+
tags,
|
|
168
|
+
comments,
|
|
169
|
+
),
|
|
164
170
|
);
|
|
165
171
|
for (const a of meta.arrays) {
|
|
166
172
|
const array = RandomJoiner.array(COALESCE(importer))(
|
|
167
173
|
decode(importer)(explore),
|
|
168
|
-
)(a, tags);
|
|
174
|
+
)(a, tags, comments);
|
|
169
175
|
expressions.push(
|
|
170
176
|
explore.recursive && a.objects.length
|
|
171
177
|
? ts.factory.createConditionalExpression(
|
|
@@ -214,9 +220,9 @@ export namespace RandomProgrammer {
|
|
|
214
220
|
if (native === "Boolean")
|
|
215
221
|
expressions.push(decode_boolean(importer));
|
|
216
222
|
else if (native === "Number")
|
|
217
|
-
expressions.push(decode_number(importer)(tags));
|
|
223
|
+
expressions.push(decode_number(importer)(tags)(comments));
|
|
218
224
|
else if (native === "String")
|
|
219
|
-
expressions.push(decode_string(importer)(tags));
|
|
225
|
+
expressions.push(decode_string(importer)(tags)(comments));
|
|
220
226
|
else expressions.push(ts.factory.createIdentifier("{}"));
|
|
221
227
|
if (meta.sets.length || meta.maps.length)
|
|
222
228
|
expressions.push(ts.factory.createIdentifier("{}"));
|
|
@@ -269,12 +275,13 @@ export namespace RandomProgrammer {
|
|
|
269
275
|
(explore: IExplore) =>
|
|
270
276
|
(template: Metadata[]) =>
|
|
271
277
|
TemplateFactory.generate(
|
|
272
|
-
template.map((meta) => decode(importer)(explore)(meta, [])),
|
|
278
|
+
template.map((meta) => decode(importer)(explore)(meta, [], [])),
|
|
273
279
|
);
|
|
274
280
|
|
|
275
281
|
const decode_number =
|
|
276
282
|
(importer: FunctionImporter) =>
|
|
277
|
-
(tags: IMetadataTag[])
|
|
283
|
+
(tags: IMetadataTag[]) =>
|
|
284
|
+
(comments: ICommentTag[]): ts.Expression => {
|
|
278
285
|
const type = tags.find(
|
|
279
286
|
(t) => t.kind === "type" && t.value === "uint",
|
|
280
287
|
)
|
|
@@ -282,96 +289,110 @@ export namespace RandomProgrammer {
|
|
|
282
289
|
: tags.find((t) => t.kind === "type" && t.value === "int")
|
|
283
290
|
? "uint"
|
|
284
291
|
: "double";
|
|
285
|
-
return
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
t
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
292
|
+
return random_custom(COALESCE(importer))("number")(comments)(
|
|
293
|
+
RandomRanger.number({
|
|
294
|
+
type,
|
|
295
|
+
transform: (value) =>
|
|
296
|
+
ts.factory.createNumericLiteral(value),
|
|
297
|
+
setter: (args) =>
|
|
298
|
+
ts.factory.createCallExpression(
|
|
299
|
+
type === "double" &&
|
|
300
|
+
tags.every(
|
|
301
|
+
(t) =>
|
|
302
|
+
t.kind !== "multipleOf" &&
|
|
303
|
+
t.kind !== "step",
|
|
304
|
+
)
|
|
305
|
+
? COALESCE(importer)("number")
|
|
306
|
+
: COALESCE(importer)("integer"),
|
|
307
|
+
undefined,
|
|
308
|
+
args.map((val) =>
|
|
309
|
+
ts.factory.createNumericLiteral(val),
|
|
310
|
+
),
|
|
311
|
+
),
|
|
312
|
+
})({
|
|
313
|
+
minimum: 0,
|
|
314
|
+
maximum: 100,
|
|
315
|
+
gap: 10,
|
|
316
|
+
})(tags),
|
|
317
|
+
);
|
|
306
318
|
};
|
|
307
319
|
|
|
308
320
|
const decode_bigint =
|
|
309
321
|
(importer: FunctionImporter) =>
|
|
310
|
-
(tags: IMetadataTag[])
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
:
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
322
|
+
(tags: IMetadataTag[]) =>
|
|
323
|
+
(comments: ICommentTag[]): ts.Expression =>
|
|
324
|
+
random_custom(COALESCE(importer))("bigint")(comments)(
|
|
325
|
+
RandomRanger.number({
|
|
326
|
+
type: tags.find(
|
|
327
|
+
(t) => t.kind === "type" && t.value === "uint",
|
|
328
|
+
)
|
|
329
|
+
? "uint"
|
|
330
|
+
: "int",
|
|
331
|
+
transform: (value) =>
|
|
332
|
+
ts.factory.createCallExpression(
|
|
333
|
+
ts.factory.createIdentifier("BigInt"),
|
|
334
|
+
undefined,
|
|
335
|
+
[ts.factory.createStringLiteral(value.toString())],
|
|
336
|
+
),
|
|
337
|
+
setter: (args) =>
|
|
338
|
+
ts.factory.createCallExpression(
|
|
339
|
+
COALESCE(importer)("bigint"),
|
|
340
|
+
undefined,
|
|
341
|
+
args.map((value) =>
|
|
342
|
+
ts.factory.createCallExpression(
|
|
343
|
+
ts.factory.createIdentifier("BigInt"),
|
|
344
|
+
undefined,
|
|
345
|
+
[
|
|
346
|
+
ts.factory.createStringLiteral(
|
|
347
|
+
value.toString(),
|
|
348
|
+
),
|
|
349
|
+
],
|
|
350
|
+
),
|
|
334
351
|
),
|
|
335
352
|
),
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
353
|
+
})({
|
|
354
|
+
minimum: 0,
|
|
355
|
+
maximum: 100,
|
|
356
|
+
gap: 10,
|
|
357
|
+
})(tags),
|
|
358
|
+
);
|
|
342
359
|
|
|
343
360
|
const decode_string =
|
|
344
361
|
(importer: FunctionImporter) =>
|
|
345
|
-
(tags: IMetadataTag[])
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
362
|
+
(tags: IMetadataTag[]) =>
|
|
363
|
+
(comments: ICommentTag[]): ts.Expression =>
|
|
364
|
+
random_custom(COALESCE(importer))("string")(comments)(
|
|
365
|
+
(() => {
|
|
366
|
+
for (const t of tags)
|
|
367
|
+
if (t.kind === "format")
|
|
368
|
+
return ts.factory.createCallExpression(
|
|
369
|
+
COALESCE(importer)(t.value),
|
|
370
|
+
undefined,
|
|
371
|
+
undefined,
|
|
372
|
+
);
|
|
373
|
+
else if (t.kind === "pattern")
|
|
374
|
+
return ts.factory.createCallExpression(
|
|
375
|
+
COALESCE(importer)("pattern"),
|
|
376
|
+
undefined,
|
|
377
|
+
[ts.factory.createIdentifier(`/${t.value}/`)],
|
|
378
|
+
);
|
|
379
|
+
|
|
380
|
+
const tail = RandomRanger.length(COALESCE(importer))({
|
|
381
|
+
minimum: 5,
|
|
382
|
+
maximum: 25,
|
|
383
|
+
gap: 5,
|
|
384
|
+
})({
|
|
385
|
+
fixed: "length",
|
|
386
|
+
minimum: "minLength",
|
|
387
|
+
maximum: "maxLength",
|
|
388
|
+
})(tags);
|
|
354
389
|
return ts.factory.createCallExpression(
|
|
355
|
-
COALESCE(importer)("
|
|
390
|
+
COALESCE(importer)("string"),
|
|
356
391
|
undefined,
|
|
357
|
-
[
|
|
392
|
+
tail ? [tail] : undefined,
|
|
358
393
|
);
|
|
359
|
-
|
|
360
|
-
const tail = RandomRanger.length(COALESCE(importer))({
|
|
361
|
-
minimum: 5,
|
|
362
|
-
maximum: 25,
|
|
363
|
-
gap: 5,
|
|
364
|
-
})({
|
|
365
|
-
fixed: "length",
|
|
366
|
-
minimum: "minLength",
|
|
367
|
-
maximum: "maxLength",
|
|
368
|
-
})(tags);
|
|
369
|
-
return ts.factory.createCallExpression(
|
|
370
|
-
COALESCE(importer)("string"),
|
|
371
|
-
undefined,
|
|
372
|
-
tail ? [tail] : undefined,
|
|
394
|
+
})(),
|
|
373
395
|
);
|
|
374
|
-
};
|
|
375
396
|
}
|
|
376
397
|
|
|
377
398
|
type Atomic = boolean | number | string | bigint;
|
|
@@ -383,6 +404,10 @@ interface IExplore {
|
|
|
383
404
|
const FUNCTOR = (i: number) => `$ro${i}`;
|
|
384
405
|
const COALESCE = (importer: FunctionImporter) => (name: string) =>
|
|
385
406
|
ExpressionFactory.coalesce(
|
|
386
|
-
ts.factory.
|
|
407
|
+
ts.factory.createPropertyAccessChain(
|
|
408
|
+
ts.factory.createIdentifier("generator"),
|
|
409
|
+
ts.factory.createToken(ts.SyntaxKind.QuestionDotToken),
|
|
410
|
+
ts.factory.createIdentifier(name),
|
|
411
|
+
),
|
|
387
412
|
IdentifierFactory.join(importer.use("generator"), name),
|
|
388
413
|
);
|
|
@@ -3,6 +3,7 @@ import ts from "typescript";
|
|
|
3
3
|
import { StatementFactory } from "../../factories/StatementFactory";
|
|
4
4
|
import { TypeFactory } from "../../factories/TypeFactory";
|
|
5
5
|
|
|
6
|
+
import { ICommentTag } from "../../metadata/ICommentTag";
|
|
6
7
|
import { IMetadataTag } from "../../metadata/IMetadataTag";
|
|
7
8
|
import { Metadata } from "../../metadata/Metadata";
|
|
8
9
|
import { MetadataObject } from "../../metadata/MetadataObject";
|
|
@@ -10,18 +11,20 @@ import { MetadataProperty } from "../../metadata/MetadataProperty";
|
|
|
10
11
|
|
|
11
12
|
import { Escaper } from "../../utils/Escaper";
|
|
12
13
|
|
|
14
|
+
import { get_comment_tags } from "../internal/get_comment_tags";
|
|
13
15
|
import { RandomRanger } from "./RandomRanger";
|
|
14
16
|
|
|
15
17
|
export namespace RandomJoiner {
|
|
16
18
|
export type Decoder = (
|
|
17
19
|
meta: Metadata,
|
|
18
20
|
tags: IMetadataTag[],
|
|
21
|
+
comments: ICommentTag[],
|
|
19
22
|
) => ts.Expression;
|
|
20
23
|
|
|
21
24
|
export const array =
|
|
22
25
|
(coalesce: (method: string) => ts.Expression) =>
|
|
23
26
|
(decoder: Decoder) =>
|
|
24
|
-
(item: Metadata, tags: IMetadataTag[]) => {
|
|
27
|
+
(item: Metadata, tags: IMetadataTag[], comments: ICommentTag[]) => {
|
|
25
28
|
const tail = RandomRanger.length(coalesce)({
|
|
26
29
|
minimum: 0,
|
|
27
30
|
maximum: 3,
|
|
@@ -41,7 +44,7 @@ export namespace RandomJoiner {
|
|
|
41
44
|
[],
|
|
42
45
|
undefined,
|
|
43
46
|
undefined,
|
|
44
|
-
decoder(item, tags),
|
|
47
|
+
decoder(item, tags, comments),
|
|
45
48
|
),
|
|
46
49
|
...(tail ? [tail] : []),
|
|
47
50
|
],
|
|
@@ -49,9 +52,10 @@ export namespace RandomJoiner {
|
|
|
49
52
|
};
|
|
50
53
|
|
|
51
54
|
export const tuple =
|
|
52
|
-
(decoder: Decoder) =>
|
|
55
|
+
(decoder: Decoder) =>
|
|
56
|
+
(items: Metadata[], tags: IMetadataTag[], comments: ICommentTag[]) =>
|
|
53
57
|
ts.factory.createArrayLiteralExpression(
|
|
54
|
-
items.map((i) => decoder(i.rest ?? i, tags)),
|
|
58
|
+
items.map((i) => decoder(i.rest ?? i, tags, comments)),
|
|
55
59
|
true,
|
|
56
60
|
);
|
|
57
61
|
|
|
@@ -77,7 +81,11 @@ export namespace RandomJoiner {
|
|
|
77
81
|
Escaper.variable(str)
|
|
78
82
|
? str
|
|
79
83
|
: ts.factory.createStringLiteral(str),
|
|
80
|
-
decoder(
|
|
84
|
+
decoder(
|
|
85
|
+
p.value,
|
|
86
|
+
p.tags,
|
|
87
|
+
get_comment_tags(false)(p.jsDocTags),
|
|
88
|
+
),
|
|
81
89
|
);
|
|
82
90
|
}),
|
|
83
91
|
true,
|
|
@@ -131,10 +139,14 @@ export namespace RandomJoiner {
|
|
|
131
139
|
ts.factory.createBinaryExpression(
|
|
132
140
|
ts.factory.createElementAccessExpression(
|
|
133
141
|
ts.factory.createIdentifier("output"),
|
|
134
|
-
decoder(p.key, []),
|
|
142
|
+
decoder(p.key, [], []),
|
|
135
143
|
),
|
|
136
144
|
ts.factory.createToken(ts.SyntaxKind.EqualsToken),
|
|
137
|
-
decoder(
|
|
145
|
+
decoder(
|
|
146
|
+
p.value,
|
|
147
|
+
p.tags,
|
|
148
|
+
get_comment_tags(false)(p.jsDocTags),
|
|
149
|
+
),
|
|
138
150
|
),
|
|
139
151
|
),
|
|
140
152
|
ts.factory.createCallExpression(
|
|
@@ -13,7 +13,7 @@ export namespace RandomRanger {
|
|
|
13
13
|
(coalesce: (method: string) => ts.Expression) =>
|
|
14
14
|
(defs: IDefaults) =>
|
|
15
15
|
(acc: length.IAccessors) =>
|
|
16
|
-
(tags: IMetadataTag[]) => {
|
|
16
|
+
(tags: IMetadataTag[]): ts.Expression | undefined => {
|
|
17
17
|
const props = {
|
|
18
18
|
fixed: getter(tags)(acc.fixed),
|
|
19
19
|
minimum: getter(tags)(acc.minimum),
|
|
@@ -3,6 +3,9 @@ import { IJsonComponents } from "../../schemas/IJsonComponents";
|
|
|
3
3
|
import { IJsonSchema } from "../../module";
|
|
4
4
|
import { ApplicationProgrammer } from "../ApplicationProgrammer";
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
6
9
|
export const application_native =
|
|
7
10
|
(options: ApplicationProgrammer.IOptions) =>
|
|
8
11
|
(components: IJsonComponents) =>
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import ts from "typescript";
|
|
2
2
|
|
|
3
3
|
import { ExpressionFactory } from "../../factories/ExpressionFactory";
|
|
4
|
+
import { IdentifierFactory } from "../../factories/IdentifierFactory";
|
|
4
5
|
|
|
5
6
|
import { IJsDocTagInfo } from "../../metadata/IJsDocTagInfo";
|
|
6
7
|
import { IMetadataTag } from "../../metadata/IMetadataTag";
|
|
@@ -20,7 +21,10 @@ export const check_array =
|
|
|
20
21
|
(input: ts.Expression): ICheckEntry => ({
|
|
21
22
|
expression: ExpressionFactory.isArray(input),
|
|
22
23
|
tags: [
|
|
23
|
-
...check_array_length(metaTags)(
|
|
24
|
+
...check_array_length(metaTags)(
|
|
25
|
+
IdentifierFactory.join(input, "length"),
|
|
26
|
+
),
|
|
24
27
|
...check_custom("array", "Array")(importer)(jsDocTags)(input),
|
|
28
|
+
// check custom array for legacy (3.7.0)
|
|
25
29
|
],
|
|
26
30
|
});
|
|
@@ -1,35 +1,30 @@
|
|
|
1
1
|
import ts from "typescript";
|
|
2
2
|
|
|
3
|
-
import { IdentifierFactory } from "../../factories/IdentifierFactory";
|
|
4
|
-
|
|
5
3
|
import { IMetadataTag } from "../../metadata/IMetadataTag";
|
|
6
4
|
|
|
7
|
-
import { ICheckEntry } from "../helpers/ICheckEntry";
|
|
8
|
-
|
|
9
5
|
/**
|
|
10
6
|
* @internal
|
|
11
7
|
*/
|
|
12
8
|
export const check_array_length =
|
|
13
|
-
(
|
|
14
|
-
|
|
15
|
-
tagList
|
|
9
|
+
(metaTags: IMetadataTag[]) => (input: ts.Expression) =>
|
|
10
|
+
metaTags
|
|
16
11
|
.map((tag) => ({
|
|
17
12
|
tag,
|
|
18
13
|
expression:
|
|
19
14
|
tag.kind === "items"
|
|
20
15
|
? ts.factory.createStrictEquality(
|
|
21
16
|
ts.factory.createNumericLiteral(tag.value),
|
|
22
|
-
|
|
17
|
+
input,
|
|
23
18
|
)
|
|
24
19
|
: tag.kind === "minItems"
|
|
25
20
|
? ts.factory.createLessThanEquals(
|
|
26
21
|
ts.factory.createNumericLiteral(tag.value),
|
|
27
|
-
|
|
22
|
+
input,
|
|
28
23
|
)
|
|
29
24
|
: tag.kind === "maxItems"
|
|
30
25
|
? ts.factory.createGreaterThanEquals(
|
|
31
26
|
ts.factory.createNumericLiteral(tag.value),
|
|
32
|
-
|
|
27
|
+
input,
|
|
33
28
|
)
|
|
34
29
|
: null!,
|
|
35
30
|
}))
|
|
@@ -1,41 +1,33 @@
|
|
|
1
1
|
import ts from "typescript";
|
|
2
2
|
|
|
3
|
-
import { MetadataTagFactory } from "../../factories/MetadataTagFactory";
|
|
4
|
-
|
|
5
3
|
import { IJsDocTagInfo } from "../../metadata/IJsDocTagInfo";
|
|
6
4
|
|
|
7
5
|
import { FunctionImporter } from "../helpers/FunctionImporeter";
|
|
8
6
|
import { ICheckEntry } from "../helpers/ICheckEntry";
|
|
7
|
+
import { get_comment_tags } from "./get_comment_tags";
|
|
9
8
|
|
|
9
|
+
/**
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
10
12
|
export const check_custom =
|
|
11
13
|
(type: string, alias?: string) =>
|
|
12
14
|
(importer: FunctionImporter) =>
|
|
13
15
|
(jsDocTags: IJsDocTagInfo[]) =>
|
|
14
16
|
(input: ts.Expression): ICheckEntry.ITag[] =>
|
|
15
|
-
jsDocTags
|
|
16
|
-
|
|
17
|
-
(tag
|
|
18
|
-
tag.
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
undefined,
|
|
33
|
-
[
|
|
34
|
-
ts.factory.createStringLiteral(tag.name),
|
|
35
|
-
ts.factory.createStringLiteral(type),
|
|
36
|
-
ts.factory.createStringLiteral(text),
|
|
37
|
-
input,
|
|
38
|
-
],
|
|
39
|
-
),
|
|
40
|
-
};
|
|
41
|
-
});
|
|
17
|
+
get_comment_tags(true)(jsDocTags).map((tag) => {
|
|
18
|
+
return {
|
|
19
|
+
expected: `${alias ?? type} (@${tag.name}${
|
|
20
|
+
tag.value?.length ? ` ${tag.value}` : ""
|
|
21
|
+
})`,
|
|
22
|
+
expression: ts.factory.createCallExpression(
|
|
23
|
+
importer.use("is_custom"),
|
|
24
|
+
undefined,
|
|
25
|
+
[
|
|
26
|
+
ts.factory.createStringLiteral(tag.name),
|
|
27
|
+
ts.factory.createStringLiteral(type),
|
|
28
|
+
ts.factory.createStringLiteral(tag.value ?? ""),
|
|
29
|
+
input,
|
|
30
|
+
],
|
|
31
|
+
),
|
|
32
|
+
};
|
|
33
|
+
});
|
|
@@ -27,6 +27,10 @@ export const check_object =
|
|
|
27
27
|
);
|
|
28
28
|
return reduce(props)(flags);
|
|
29
29
|
};
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @internal
|
|
33
|
+
*/
|
|
30
34
|
export namespace check_object {
|
|
31
35
|
export interface IProps {
|
|
32
36
|
equals: boolean;
|
|
@@ -40,6 +44,9 @@ export namespace check_object {
|
|
|
40
44
|
}
|
|
41
45
|
}
|
|
42
46
|
|
|
47
|
+
/**
|
|
48
|
+
* @internal
|
|
49
|
+
*/
|
|
43
50
|
const reduce = (props: check_object.IProps) => (expressions: ts.Expression[]) =>
|
|
44
51
|
props.assert
|
|
45
52
|
? expressions.reduce(props.reduce)
|
|
@@ -10,6 +10,9 @@ import { CheckerProgrammer } from "../CheckerProgrammer";
|
|
|
10
10
|
import { FeatureProgrammer } from "../FeatureProgrammer";
|
|
11
11
|
import { UnionExplorer } from "../helpers/UnionExplorer";
|
|
12
12
|
|
|
13
|
+
/**
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
13
16
|
export const check_union_array_like =
|
|
14
17
|
<T>(accessor: check_union_array_like.IAccessor<T>) =>
|
|
15
18
|
(props: check_union_array_like.IProps<T>) =>
|
|
@@ -236,6 +239,10 @@ export const check_union_array_like =
|
|
|
236
239
|
undefined,
|
|
237
240
|
);
|
|
238
241
|
};
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* @internal
|
|
245
|
+
*/
|
|
239
246
|
export namespace check_union_array_like {
|
|
240
247
|
export interface IProps<T> {
|
|
241
248
|
checker(
|