typia 3.7.2 → 3.7.3
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/lib/programmers/AssertProgrammer.js +4 -2
- package/lib/programmers/AssertProgrammer.js.map +1 -1
- package/lib/programmers/ValidateProgrammer.js +3 -2
- package/lib/programmers/ValidateProgrammer.js.map +1 -1
- package/package.json +4 -2
- package/src/IRandomGenerator.ts +33 -33
- package/src/factories/IdentifierFactory.ts +81 -81
- package/src/factories/MetadataTagFactory.ts +302 -302
- package/src/metadata/ICommentTag.ts +4 -4
- package/src/programmers/AssertProgrammer.ts +38 -10
- package/src/programmers/LiteralsProgrammer.ts +65 -65
- package/src/programmers/RandomProgrammer.ts +413 -413
- package/src/programmers/ValidateProgrammer.ts +36 -9
- package/src/programmers/helpers/RandomJoiner.ts +161 -161
- package/src/programmers/helpers/RandomRanger.ts +216 -216
- package/src/programmers/internal/application_native.ts +32 -32
- package/src/programmers/internal/check_array.ts +30 -30
- package/src/programmers/internal/check_array_length.ts +35 -35
- package/src/programmers/internal/check_custom.ts +33 -33
- package/src/programmers/internal/check_number.ts +177 -177
- package/src/programmers/internal/check_object.ts +55 -55
- package/src/programmers/internal/check_union_array_like.ts +272 -272
- package/src/programmers/internal/feature_object_entries.ts +63 -63
- package/src/programmers/internal/get_comment_tags.ts +23 -23
- package/src/programmers/internal/metadata_to_pattern.ts +34 -34
- package/src/programmers/internal/random_custom.ts +30 -30
- package/src/programmers/internal/stringify_dynamic_properties.ts +168 -168
- package/src/programmers/internal/stringify_regular_properties.ts +84 -84
- package/src/transformers/CallExpressionTransformer.ts +174 -174
- package/src/transformers/features/miscellaneous/CreateRandomTransformer.ts +41 -41
- package/src/transformers/features/miscellaneous/LiteralsTransformer.ts +30 -30
- package/src/typings/Customizable.ts +5 -5
|
@@ -79,6 +79,21 @@ export namespace ValidateProgrammer {
|
|
|
79
79
|
undefined,
|
|
80
80
|
ts.factory.createBlock(
|
|
81
81
|
[
|
|
82
|
+
StatementFactory.constant(
|
|
83
|
+
"__is",
|
|
84
|
+
IsProgrammer.generate(
|
|
85
|
+
project,
|
|
86
|
+
modulo,
|
|
87
|
+
equals,
|
|
88
|
+
)(
|
|
89
|
+
type,
|
|
90
|
+
name ??
|
|
91
|
+
TypeFactory.getFullName(
|
|
92
|
+
project.checker,
|
|
93
|
+
type,
|
|
94
|
+
),
|
|
95
|
+
),
|
|
96
|
+
),
|
|
82
97
|
StatementFactory.constant(
|
|
83
98
|
"errors",
|
|
84
99
|
ts.factory.createAsExpression(
|
|
@@ -105,15 +120,27 @@ export namespace ValidateProgrammer {
|
|
|
105
120
|
),
|
|
106
121
|
),
|
|
107
122
|
...importer.declare(modulo),
|
|
108
|
-
ts.factory.
|
|
109
|
-
ts.factory.
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
ts.factory.
|
|
115
|
-
|
|
116
|
-
|
|
123
|
+
ts.factory.createIfStatement(
|
|
124
|
+
ts.factory.createStrictEquality(
|
|
125
|
+
ts.factory.createFalse(),
|
|
126
|
+
ts.factory.createCallExpression(
|
|
127
|
+
ts.factory.createIdentifier("__is"),
|
|
128
|
+
undefined,
|
|
129
|
+
[ts.factory.createIdentifier("input")],
|
|
130
|
+
),
|
|
131
|
+
),
|
|
132
|
+
ts.factory.createExpressionStatement(
|
|
133
|
+
ts.factory.createCallExpression(
|
|
134
|
+
program,
|
|
135
|
+
undefined,
|
|
136
|
+
[
|
|
137
|
+
ts.factory.createIdentifier("input"),
|
|
138
|
+
ts.factory.createStringLiteral(
|
|
139
|
+
"$input",
|
|
140
|
+
),
|
|
141
|
+
ts.factory.createTrue(),
|
|
142
|
+
],
|
|
143
|
+
),
|
|
117
144
|
),
|
|
118
145
|
),
|
|
119
146
|
StatementFactory.constant(
|
|
@@ -1,161 +1,161 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { StatementFactory } from "../../factories/StatementFactory";
|
|
4
|
-
import { TypeFactory } from "../../factories/TypeFactory";
|
|
5
|
-
|
|
6
|
-
import { ICommentTag } from "../../metadata/ICommentTag";
|
|
7
|
-
import { IMetadataTag } from "../../metadata/IMetadataTag";
|
|
8
|
-
import { Metadata } from "../../metadata/Metadata";
|
|
9
|
-
import { MetadataObject } from "../../metadata/MetadataObject";
|
|
10
|
-
import { MetadataProperty } from "../../metadata/MetadataProperty";
|
|
11
|
-
|
|
12
|
-
import { Escaper } from "../../utils/Escaper";
|
|
13
|
-
|
|
14
|
-
import { get_comment_tags } from "../internal/get_comment_tags";
|
|
15
|
-
import { RandomRanger } from "./RandomRanger";
|
|
16
|
-
|
|
17
|
-
export namespace RandomJoiner {
|
|
18
|
-
export type Decoder = (
|
|
19
|
-
meta: Metadata,
|
|
20
|
-
tags: IMetadataTag[],
|
|
21
|
-
comments: ICommentTag[],
|
|
22
|
-
) => ts.Expression;
|
|
23
|
-
|
|
24
|
-
export const array =
|
|
25
|
-
(coalesce: (method: string) => ts.Expression) =>
|
|
26
|
-
(decoder: Decoder) =>
|
|
27
|
-
(item: Metadata, tags: IMetadataTag[], comments: ICommentTag[]) => {
|
|
28
|
-
const tail = RandomRanger.length(coalesce)({
|
|
29
|
-
minimum: 0,
|
|
30
|
-
maximum: 3,
|
|
31
|
-
gap: 3,
|
|
32
|
-
})({
|
|
33
|
-
fixed: "items",
|
|
34
|
-
minimum: "minItems",
|
|
35
|
-
maximum: "maxItems",
|
|
36
|
-
})(tags);
|
|
37
|
-
return ts.factory.createCallExpression(
|
|
38
|
-
coalesce("array"),
|
|
39
|
-
undefined,
|
|
40
|
-
[
|
|
41
|
-
ts.factory.createArrowFunction(
|
|
42
|
-
undefined,
|
|
43
|
-
undefined,
|
|
44
|
-
[],
|
|
45
|
-
undefined,
|
|
46
|
-
undefined,
|
|
47
|
-
decoder(item, tags, comments),
|
|
48
|
-
),
|
|
49
|
-
...(tail ? [tail] : []),
|
|
50
|
-
],
|
|
51
|
-
);
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
export const tuple =
|
|
55
|
-
(decoder: Decoder) =>
|
|
56
|
-
(items: Metadata[], tags: IMetadataTag[], comments: ICommentTag[]) =>
|
|
57
|
-
ts.factory.createArrayLiteralExpression(
|
|
58
|
-
items.map((i) => decoder(i.rest ?? i, tags, comments)),
|
|
59
|
-
true,
|
|
60
|
-
);
|
|
61
|
-
|
|
62
|
-
export const object =
|
|
63
|
-
(coalesce: (method: string) => ts.Expression) =>
|
|
64
|
-
(decoder: Decoder) =>
|
|
65
|
-
(obj: MetadataObject): ts.ConciseBody => {
|
|
66
|
-
if (obj.properties.length === 0)
|
|
67
|
-
return ts.factory.createIdentifier("{}");
|
|
68
|
-
|
|
69
|
-
// LIST UP PROPERTIES
|
|
70
|
-
const regular = obj.properties.filter((p) => p.key.isSoleLiteral());
|
|
71
|
-
const dynamic = obj.properties.filter(
|
|
72
|
-
(p) => !p.key.isSoleLiteral(),
|
|
73
|
-
);
|
|
74
|
-
|
|
75
|
-
// REGULAR OBJECT
|
|
76
|
-
const literal: ts.ObjectLiteralExpression =
|
|
77
|
-
ts.factory.createObjectLiteralExpression(
|
|
78
|
-
regular.map((p) => {
|
|
79
|
-
const str: string = p.key.getSoleLiteral()!;
|
|
80
|
-
return ts.factory.createPropertyAssignment(
|
|
81
|
-
Escaper.variable(str)
|
|
82
|
-
? str
|
|
83
|
-
: ts.factory.createStringLiteral(str),
|
|
84
|
-
decoder(
|
|
85
|
-
p.value,
|
|
86
|
-
p.tags,
|
|
87
|
-
get_comment_tags(false)(p.jsDocTags),
|
|
88
|
-
),
|
|
89
|
-
);
|
|
90
|
-
}),
|
|
91
|
-
true,
|
|
92
|
-
);
|
|
93
|
-
if (dynamic.length === 0) return literal;
|
|
94
|
-
|
|
95
|
-
const properties: ts.Statement[] = dynamic.map((p) =>
|
|
96
|
-
ts.factory.createExpressionStatement(
|
|
97
|
-
dynamicProperty(coalesce)(decoder)(p),
|
|
98
|
-
),
|
|
99
|
-
);
|
|
100
|
-
return ts.factory.createBlock(
|
|
101
|
-
[
|
|
102
|
-
StatementFactory.constant(
|
|
103
|
-
"output",
|
|
104
|
-
ts.factory.createAsExpression(
|
|
105
|
-
literal,
|
|
106
|
-
TypeFactory.keyword("any"),
|
|
107
|
-
),
|
|
108
|
-
),
|
|
109
|
-
...(obj.recursive
|
|
110
|
-
? [
|
|
111
|
-
ts.factory.createIfStatement(
|
|
112
|
-
ts.factory.createGreaterThanEquals(
|
|
113
|
-
ts.factory.createNumericLiteral(5),
|
|
114
|
-
ts.factory.createIdentifier("_depth"),
|
|
115
|
-
),
|
|
116
|
-
ts.factory.createBlock(properties, true),
|
|
117
|
-
),
|
|
118
|
-
]
|
|
119
|
-
: properties),
|
|
120
|
-
ts.factory.createReturnStatement(
|
|
121
|
-
ts.factory.createIdentifier("output"),
|
|
122
|
-
),
|
|
123
|
-
],
|
|
124
|
-
true,
|
|
125
|
-
);
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
const dynamicProperty =
|
|
129
|
-
(coalesce: (method: string) => ts.Expression) =>
|
|
130
|
-
(decoder: Decoder) =>
|
|
131
|
-
(p: MetadataProperty) =>
|
|
132
|
-
ts.factory.createCallExpression(coalesce("array"), undefined, [
|
|
133
|
-
ts.factory.createArrowFunction(
|
|
134
|
-
undefined,
|
|
135
|
-
undefined,
|
|
136
|
-
[],
|
|
137
|
-
undefined,
|
|
138
|
-
undefined,
|
|
139
|
-
ts.factory.createBinaryExpression(
|
|
140
|
-
ts.factory.createElementAccessExpression(
|
|
141
|
-
ts.factory.createIdentifier("output"),
|
|
142
|
-
decoder(p.key, [], []),
|
|
143
|
-
),
|
|
144
|
-
ts.factory.createToken(ts.SyntaxKind.EqualsToken),
|
|
145
|
-
decoder(
|
|
146
|
-
p.value,
|
|
147
|
-
p.tags,
|
|
148
|
-
get_comment_tags(false)(p.jsDocTags),
|
|
149
|
-
),
|
|
150
|
-
),
|
|
151
|
-
),
|
|
152
|
-
ts.factory.createCallExpression(
|
|
153
|
-
coalesce("integer"),
|
|
154
|
-
undefined,
|
|
155
|
-
[
|
|
156
|
-
ts.factory.createNumericLiteral(0),
|
|
157
|
-
ts.factory.createNumericLiteral(3),
|
|
158
|
-
],
|
|
159
|
-
),
|
|
160
|
-
]);
|
|
161
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { StatementFactory } from "../../factories/StatementFactory";
|
|
4
|
+
import { TypeFactory } from "../../factories/TypeFactory";
|
|
5
|
+
|
|
6
|
+
import { ICommentTag } from "../../metadata/ICommentTag";
|
|
7
|
+
import { IMetadataTag } from "../../metadata/IMetadataTag";
|
|
8
|
+
import { Metadata } from "../../metadata/Metadata";
|
|
9
|
+
import { MetadataObject } from "../../metadata/MetadataObject";
|
|
10
|
+
import { MetadataProperty } from "../../metadata/MetadataProperty";
|
|
11
|
+
|
|
12
|
+
import { Escaper } from "../../utils/Escaper";
|
|
13
|
+
|
|
14
|
+
import { get_comment_tags } from "../internal/get_comment_tags";
|
|
15
|
+
import { RandomRanger } from "./RandomRanger";
|
|
16
|
+
|
|
17
|
+
export namespace RandomJoiner {
|
|
18
|
+
export type Decoder = (
|
|
19
|
+
meta: Metadata,
|
|
20
|
+
tags: IMetadataTag[],
|
|
21
|
+
comments: ICommentTag[],
|
|
22
|
+
) => ts.Expression;
|
|
23
|
+
|
|
24
|
+
export const array =
|
|
25
|
+
(coalesce: (method: string) => ts.Expression) =>
|
|
26
|
+
(decoder: Decoder) =>
|
|
27
|
+
(item: Metadata, tags: IMetadataTag[], comments: ICommentTag[]) => {
|
|
28
|
+
const tail = RandomRanger.length(coalesce)({
|
|
29
|
+
minimum: 0,
|
|
30
|
+
maximum: 3,
|
|
31
|
+
gap: 3,
|
|
32
|
+
})({
|
|
33
|
+
fixed: "items",
|
|
34
|
+
minimum: "minItems",
|
|
35
|
+
maximum: "maxItems",
|
|
36
|
+
})(tags);
|
|
37
|
+
return ts.factory.createCallExpression(
|
|
38
|
+
coalesce("array"),
|
|
39
|
+
undefined,
|
|
40
|
+
[
|
|
41
|
+
ts.factory.createArrowFunction(
|
|
42
|
+
undefined,
|
|
43
|
+
undefined,
|
|
44
|
+
[],
|
|
45
|
+
undefined,
|
|
46
|
+
undefined,
|
|
47
|
+
decoder(item, tags, comments),
|
|
48
|
+
),
|
|
49
|
+
...(tail ? [tail] : []),
|
|
50
|
+
],
|
|
51
|
+
);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export const tuple =
|
|
55
|
+
(decoder: Decoder) =>
|
|
56
|
+
(items: Metadata[], tags: IMetadataTag[], comments: ICommentTag[]) =>
|
|
57
|
+
ts.factory.createArrayLiteralExpression(
|
|
58
|
+
items.map((i) => decoder(i.rest ?? i, tags, comments)),
|
|
59
|
+
true,
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
export const object =
|
|
63
|
+
(coalesce: (method: string) => ts.Expression) =>
|
|
64
|
+
(decoder: Decoder) =>
|
|
65
|
+
(obj: MetadataObject): ts.ConciseBody => {
|
|
66
|
+
if (obj.properties.length === 0)
|
|
67
|
+
return ts.factory.createIdentifier("{}");
|
|
68
|
+
|
|
69
|
+
// LIST UP PROPERTIES
|
|
70
|
+
const regular = obj.properties.filter((p) => p.key.isSoleLiteral());
|
|
71
|
+
const dynamic = obj.properties.filter(
|
|
72
|
+
(p) => !p.key.isSoleLiteral(),
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
// REGULAR OBJECT
|
|
76
|
+
const literal: ts.ObjectLiteralExpression =
|
|
77
|
+
ts.factory.createObjectLiteralExpression(
|
|
78
|
+
regular.map((p) => {
|
|
79
|
+
const str: string = p.key.getSoleLiteral()!;
|
|
80
|
+
return ts.factory.createPropertyAssignment(
|
|
81
|
+
Escaper.variable(str)
|
|
82
|
+
? str
|
|
83
|
+
: ts.factory.createStringLiteral(str),
|
|
84
|
+
decoder(
|
|
85
|
+
p.value,
|
|
86
|
+
p.tags,
|
|
87
|
+
get_comment_tags(false)(p.jsDocTags),
|
|
88
|
+
),
|
|
89
|
+
);
|
|
90
|
+
}),
|
|
91
|
+
true,
|
|
92
|
+
);
|
|
93
|
+
if (dynamic.length === 0) return literal;
|
|
94
|
+
|
|
95
|
+
const properties: ts.Statement[] = dynamic.map((p) =>
|
|
96
|
+
ts.factory.createExpressionStatement(
|
|
97
|
+
dynamicProperty(coalesce)(decoder)(p),
|
|
98
|
+
),
|
|
99
|
+
);
|
|
100
|
+
return ts.factory.createBlock(
|
|
101
|
+
[
|
|
102
|
+
StatementFactory.constant(
|
|
103
|
+
"output",
|
|
104
|
+
ts.factory.createAsExpression(
|
|
105
|
+
literal,
|
|
106
|
+
TypeFactory.keyword("any"),
|
|
107
|
+
),
|
|
108
|
+
),
|
|
109
|
+
...(obj.recursive
|
|
110
|
+
? [
|
|
111
|
+
ts.factory.createIfStatement(
|
|
112
|
+
ts.factory.createGreaterThanEquals(
|
|
113
|
+
ts.factory.createNumericLiteral(5),
|
|
114
|
+
ts.factory.createIdentifier("_depth"),
|
|
115
|
+
),
|
|
116
|
+
ts.factory.createBlock(properties, true),
|
|
117
|
+
),
|
|
118
|
+
]
|
|
119
|
+
: properties),
|
|
120
|
+
ts.factory.createReturnStatement(
|
|
121
|
+
ts.factory.createIdentifier("output"),
|
|
122
|
+
),
|
|
123
|
+
],
|
|
124
|
+
true,
|
|
125
|
+
);
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
const dynamicProperty =
|
|
129
|
+
(coalesce: (method: string) => ts.Expression) =>
|
|
130
|
+
(decoder: Decoder) =>
|
|
131
|
+
(p: MetadataProperty) =>
|
|
132
|
+
ts.factory.createCallExpression(coalesce("array"), undefined, [
|
|
133
|
+
ts.factory.createArrowFunction(
|
|
134
|
+
undefined,
|
|
135
|
+
undefined,
|
|
136
|
+
[],
|
|
137
|
+
undefined,
|
|
138
|
+
undefined,
|
|
139
|
+
ts.factory.createBinaryExpression(
|
|
140
|
+
ts.factory.createElementAccessExpression(
|
|
141
|
+
ts.factory.createIdentifier("output"),
|
|
142
|
+
decoder(p.key, [], []),
|
|
143
|
+
),
|
|
144
|
+
ts.factory.createToken(ts.SyntaxKind.EqualsToken),
|
|
145
|
+
decoder(
|
|
146
|
+
p.value,
|
|
147
|
+
p.tags,
|
|
148
|
+
get_comment_tags(false)(p.jsDocTags),
|
|
149
|
+
),
|
|
150
|
+
),
|
|
151
|
+
),
|
|
152
|
+
ts.factory.createCallExpression(
|
|
153
|
+
coalesce("integer"),
|
|
154
|
+
undefined,
|
|
155
|
+
[
|
|
156
|
+
ts.factory.createNumericLiteral(0),
|
|
157
|
+
ts.factory.createNumericLiteral(3),
|
|
158
|
+
],
|
|
159
|
+
),
|
|
160
|
+
]);
|
|
161
|
+
}
|