typia 3.7.0-dev.20230331 → 3.7.0-dev.20230401
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/functional/$dictionary.d.ts +1 -1
- package/lib/programmers/AssertProgrammer.js +11 -0
- package/lib/programmers/AssertProgrammer.js.map +1 -1
- package/lib/programmers/CheckerProgrammer.d.ts +2 -0
- package/lib/programmers/CheckerProgrammer.js +11 -12
- package/lib/programmers/CheckerProgrammer.js.map +1 -1
- package/lib/programmers/IsProgrammer.js +30 -0
- package/lib/programmers/IsProgrammer.js.map +1 -1
- package/lib/programmers/ValidateProgrammer.js +11 -0
- package/lib/programmers/ValidateProgrammer.js.map +1 -1
- package/lib/programmers/helpers/ICheckEntry.d.ts +11 -0
- package/lib/programmers/helpers/ICheckEntry.js +3 -0
- package/lib/programmers/helpers/ICheckEntry.js.map +1 -0
- package/lib/programmers/internal/check_array.js +7 -11
- package/lib/programmers/internal/check_array.js.map +1 -1
- package/lib/programmers/internal/check_array_length.js +23 -36
- package/lib/programmers/internal/check_array_length.js.map +1 -1
- package/lib/programmers/internal/check_bigint.d.ts +1 -5
- package/lib/programmers/internal/check_bigint.js +67 -61
- package/lib/programmers/internal/check_bigint.js.map +1 -1
- package/lib/programmers/internal/check_custom.d.ts +2 -1
- package/lib/programmers/internal/check_custom.js +26 -16
- package/lib/programmers/internal/check_custom.js.map +1 -1
- package/lib/programmers/internal/check_number.js +88 -64
- package/lib/programmers/internal/check_number.js.map +1 -1
- package/lib/programmers/internal/check_string.js +9 -9
- package/lib/programmers/internal/check_string.js.map +1 -1
- package/lib/programmers/internal/check_string_tags.js +63 -24
- package/lib/programmers/internal/check_string_tags.js.map +1 -1
- package/lib/programmers/internal/check_template.js +23 -11
- package/lib/programmers/internal/check_template.js.map +1 -1
- package/lib/typings/Customizable.d.ts +0 -1
- package/package.json +1 -1
- package/src/programmers/AssertProgrammer.ts +24 -0
- package/src/programmers/CheckerProgrammer.ts +45 -46
- package/src/programmers/IsProgrammer.ts +5 -0
- package/src/programmers/ValidateProgrammer.ts +24 -0
- package/src/programmers/helpers/ICheckEntry.ts +12 -0
- package/src/programmers/internal/check_array.ts +10 -15
- package/src/programmers/internal/check_array_length.ts +31 -35
- package/src/programmers/internal/check_bigint.ts +60 -62
- package/src/programmers/internal/check_custom.ts +25 -16
- package/src/programmers/internal/check_number.ts +102 -83
- package/src/programmers/internal/check_string.ts +14 -19
- package/src/programmers/internal/check_string_tags.ts +23 -13
- package/src/programmers/internal/check_template.ts +16 -7
- package/src/typings/Customizable.ts +0 -1
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import ts from "typescript";
|
|
2
2
|
|
|
3
|
+
import { IJsDocTagInfo } from "../../metadata/IJsDocTagInfo";
|
|
3
4
|
import { IMetadataTag } from "../../metadata/IMetadataTag";
|
|
4
5
|
|
|
5
6
|
import { IProject } from "../../transformers/IProject";
|
|
6
7
|
|
|
7
8
|
import { FunctionImporter } from "../helpers/FunctionImporeter";
|
|
9
|
+
import { ICheckEntry } from "../helpers/ICheckEntry";
|
|
8
10
|
import { OptionPredicator } from "../helpers/OptionPredicator";
|
|
9
11
|
import { check_custom } from "./check_custom";
|
|
10
12
|
|
|
@@ -12,60 +14,16 @@ import { check_custom } from "./check_custom";
|
|
|
12
14
|
* @internal
|
|
13
15
|
*/
|
|
14
16
|
export const check_number =
|
|
15
|
-
(
|
|
17
|
+
(project: IProject, numeric: boolean) =>
|
|
16
18
|
(importer: FunctionImporter) =>
|
|
17
|
-
(
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
) => {
|
|
22
|
-
// TYPEOF STATEMENT
|
|
23
|
-
const conditions: ts.Expression[] = [
|
|
24
|
-
ts.factory.createStrictEquality(
|
|
25
|
-
ts.factory.createStringLiteral("number"),
|
|
26
|
-
ts.factory.createTypeOfExpression(input),
|
|
27
|
-
),
|
|
28
|
-
];
|
|
29
|
-
|
|
30
|
-
// CHECK FINITE AND NAN
|
|
31
|
-
const finite: boolean =
|
|
32
|
-
(!!metaTags.find(
|
|
33
|
-
(tag) =>
|
|
34
|
-
tag.kind === "minimum" || tag.kind === "exclusiveMinimum",
|
|
35
|
-
) &&
|
|
36
|
-
!!metaTags.find(
|
|
37
|
-
(tag) =>
|
|
38
|
-
tag.kind === "maximum" ||
|
|
39
|
-
tag.kind === "exclusiveMaximum",
|
|
40
|
-
)) ||
|
|
41
|
-
!!metaTags.find(
|
|
42
|
-
(tag) => tag.kind === "step" || tag.kind === "multipleOf",
|
|
43
|
-
);
|
|
44
|
-
|
|
45
|
-
if (numeric === true && finite === false)
|
|
46
|
-
if (OptionPredicator.finite(options))
|
|
47
|
-
conditions.push(
|
|
48
|
-
ts.factory.createCallExpression(
|
|
49
|
-
ts.factory.createIdentifier("Number.isFinite"),
|
|
50
|
-
undefined,
|
|
51
|
-
[input],
|
|
52
|
-
),
|
|
53
|
-
);
|
|
54
|
-
else if (OptionPredicator.numeric(options))
|
|
55
|
-
conditions.push(
|
|
56
|
-
ts.factory.createLogicalNot(
|
|
57
|
-
ts.factory.createCallExpression(
|
|
58
|
-
ts.factory.createIdentifier("Number.isNaN"),
|
|
59
|
-
undefined,
|
|
60
|
-
[input],
|
|
61
|
-
),
|
|
62
|
-
),
|
|
63
|
-
);
|
|
64
|
-
|
|
65
|
-
// TAG (RANGE)
|
|
19
|
+
(metaTags: IMetadataTag[]) =>
|
|
20
|
+
(jsDocTag: IJsDocTagInfo[]) =>
|
|
21
|
+
(input: ts.Expression): ICheckEntry => {
|
|
22
|
+
const entries: [IMetadataTag, ts.Expression][] = [];
|
|
66
23
|
for (const tag of metaTags)
|
|
67
24
|
if (tag.kind === "type") {
|
|
68
|
-
|
|
25
|
+
entries.push([
|
|
26
|
+
tag,
|
|
69
27
|
ts.factory.createStrictEquality(
|
|
70
28
|
ts.factory.createCallExpression(
|
|
71
29
|
ts.factory.createIdentifier("parseInt"),
|
|
@@ -74,16 +32,18 @@ export const check_number =
|
|
|
74
32
|
),
|
|
75
33
|
input,
|
|
76
34
|
),
|
|
77
|
-
);
|
|
35
|
+
]);
|
|
78
36
|
if (tag.value === "uint")
|
|
79
|
-
|
|
37
|
+
entries.push([
|
|
38
|
+
tag,
|
|
80
39
|
ts.factory.createLessThanEquals(
|
|
81
40
|
ts.factory.createNumericLiteral(0),
|
|
82
41
|
input,
|
|
83
42
|
),
|
|
84
|
-
);
|
|
43
|
+
]);
|
|
85
44
|
} else if (tag.kind === "multipleOf")
|
|
86
|
-
|
|
45
|
+
entries.push([
|
|
46
|
+
tag,
|
|
87
47
|
ts.factory.createStrictEquality(
|
|
88
48
|
ts.factory.createNumericLiteral(0),
|
|
89
49
|
ts.factory.createModulo(
|
|
@@ -91,64 +51,123 @@ export const check_number =
|
|
|
91
51
|
ts.factory.createNumericLiteral(tag.value),
|
|
92
52
|
),
|
|
93
53
|
),
|
|
94
|
-
);
|
|
54
|
+
]);
|
|
95
55
|
else if (tag.kind === "step") {
|
|
96
|
-
const modulo = (
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
conditions.push(
|
|
56
|
+
const modulo = ts.factory.createModulo(
|
|
57
|
+
input,
|
|
58
|
+
ts.factory.createNumericLiteral(tag.value),
|
|
59
|
+
);
|
|
60
|
+
const minimum =
|
|
61
|
+
(metaTags.find(
|
|
62
|
+
(tag) =>
|
|
63
|
+
tag.kind === "minimum" ||
|
|
64
|
+
tag.kind === "exclusiveMinimum",
|
|
65
|
+
)?.value as number | undefined) ?? undefined;
|
|
66
|
+
entries.push([
|
|
67
|
+
tag,
|
|
109
68
|
ts.factory.createStrictEquality(
|
|
110
69
|
ts.factory.createNumericLiteral(0),
|
|
111
70
|
minimum !== undefined
|
|
112
71
|
? ts.factory.createSubtract(
|
|
113
|
-
modulo
|
|
72
|
+
modulo,
|
|
114
73
|
ts.factory.createNumericLiteral(minimum),
|
|
115
74
|
)
|
|
116
|
-
: modulo
|
|
75
|
+
: modulo,
|
|
117
76
|
),
|
|
118
|
-
);
|
|
77
|
+
]);
|
|
119
78
|
} else if (tag.kind === "minimum")
|
|
120
|
-
|
|
79
|
+
entries.push([
|
|
80
|
+
tag,
|
|
121
81
|
ts.factory.createLessThanEquals(
|
|
122
82
|
ts.factory.createNumericLiteral(tag.value),
|
|
123
83
|
input,
|
|
124
84
|
),
|
|
125
|
-
);
|
|
85
|
+
]);
|
|
126
86
|
else if (tag.kind === "maximum")
|
|
127
|
-
|
|
87
|
+
entries.push([
|
|
88
|
+
tag,
|
|
128
89
|
ts.factory.createGreaterThanEquals(
|
|
129
90
|
ts.factory.createNumericLiteral(tag.value),
|
|
130
91
|
input,
|
|
131
92
|
),
|
|
132
|
-
);
|
|
93
|
+
]);
|
|
133
94
|
else if (tag.kind === "exclusiveMinimum")
|
|
134
|
-
|
|
95
|
+
entries.push([
|
|
96
|
+
tag,
|
|
135
97
|
ts.factory.createLessThan(
|
|
136
98
|
ts.factory.createNumericLiteral(tag.value),
|
|
137
99
|
input,
|
|
138
100
|
),
|
|
139
|
-
);
|
|
101
|
+
]);
|
|
140
102
|
else if (tag.kind === "exclusiveMaximum")
|
|
141
|
-
|
|
103
|
+
entries.push([
|
|
104
|
+
tag,
|
|
142
105
|
ts.factory.createGreaterThan(
|
|
143
106
|
ts.factory.createNumericLiteral(tag.value),
|
|
144
107
|
input,
|
|
145
108
|
),
|
|
146
|
-
);
|
|
109
|
+
]);
|
|
110
|
+
|
|
111
|
+
return {
|
|
112
|
+
expression: is_number(project, numeric)(metaTags)(input),
|
|
113
|
+
tags: [
|
|
114
|
+
...entries.map(([tag, expression]) => ({
|
|
115
|
+
expected: `number (@${tag.kind} ${tag.value})`,
|
|
116
|
+
expression,
|
|
117
|
+
})),
|
|
118
|
+
...check_custom("number")(importer)(jsDocTag)(input),
|
|
119
|
+
],
|
|
120
|
+
};
|
|
121
|
+
};
|
|
147
122
|
|
|
148
|
-
|
|
149
|
-
|
|
123
|
+
const is_number =
|
|
124
|
+
({ options }: IProject, numeric: boolean) =>
|
|
125
|
+
(metaTags: IMetadataTag[]) =>
|
|
126
|
+
(input: ts.Expression) => {
|
|
127
|
+
// TYPEOF STATEMENT
|
|
128
|
+
const conditions: ts.Expression[] = [
|
|
129
|
+
ts.factory.createStrictEquality(
|
|
130
|
+
ts.factory.createStringLiteral("number"),
|
|
131
|
+
ts.factory.createTypeOfExpression(input),
|
|
132
|
+
),
|
|
133
|
+
];
|
|
134
|
+
|
|
135
|
+
// CHECK FINITE AND NAN
|
|
136
|
+
const finite: boolean =
|
|
137
|
+
(!!metaTags.find(
|
|
138
|
+
(tag) =>
|
|
139
|
+
tag.kind === "minimum" || tag.kind === "exclusiveMinimum",
|
|
140
|
+
) &&
|
|
141
|
+
!!metaTags.find(
|
|
142
|
+
(tag) =>
|
|
143
|
+
tag.kind === "maximum" ||
|
|
144
|
+
tag.kind === "exclusiveMaximum",
|
|
145
|
+
)) ||
|
|
146
|
+
!!metaTags.find(
|
|
147
|
+
(tag) => tag.kind === "step" || tag.kind === "multipleOf",
|
|
148
|
+
);
|
|
149
|
+
|
|
150
|
+
if (numeric === true && finite === false)
|
|
151
|
+
if (OptionPredicator.finite(options))
|
|
152
|
+
conditions.push(
|
|
153
|
+
ts.factory.createCallExpression(
|
|
154
|
+
ts.factory.createIdentifier("Number.isFinite"),
|
|
155
|
+
undefined,
|
|
156
|
+
[input],
|
|
157
|
+
),
|
|
158
|
+
);
|
|
159
|
+
else if (OptionPredicator.numeric(options))
|
|
160
|
+
conditions.push(
|
|
161
|
+
ts.factory.createLogicalNot(
|
|
162
|
+
ts.factory.createCallExpression(
|
|
163
|
+
ts.factory.createIdentifier("Number.isNaN"),
|
|
164
|
+
undefined,
|
|
165
|
+
[input],
|
|
166
|
+
),
|
|
167
|
+
),
|
|
168
|
+
);
|
|
150
169
|
|
|
151
|
-
//
|
|
170
|
+
// COMBINATE
|
|
152
171
|
return conditions.length === 1
|
|
153
172
|
? conditions[0]!
|
|
154
173
|
: conditions.reduce((x, y) => ts.factory.createLogicalAnd(x, y));
|
|
@@ -9,22 +9,17 @@ import { check_string_tags } from "./check_string_tags";
|
|
|
9
9
|
/**
|
|
10
10
|
* @internal
|
|
11
11
|
*/
|
|
12
|
-
export
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
ts.factory.
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
),
|
|
23
|
-
...
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return conditions.length === 1
|
|
27
|
-
? conditions[0]!
|
|
28
|
-
: conditions.reduce((x, y) => ts.factory.createLogicalAnd(x, y));
|
|
29
|
-
};
|
|
30
|
-
}
|
|
12
|
+
export const check_string =
|
|
13
|
+
(importer: FunctionImporter) =>
|
|
14
|
+
(metaTags: IMetadataTag[]) =>
|
|
15
|
+
(jsDocTags: ts.JSDocTagInfo[]) =>
|
|
16
|
+
(input: ts.Expression) => ({
|
|
17
|
+
expression: ts.factory.createStrictEquality(
|
|
18
|
+
ts.factory.createStringLiteral("string"),
|
|
19
|
+
ts.factory.createTypeOfExpression(input),
|
|
20
|
+
),
|
|
21
|
+
tags: [
|
|
22
|
+
...check_string_tags(importer)(metaTags)(input),
|
|
23
|
+
...check_custom("string")(importer)(jsDocTags)(input),
|
|
24
|
+
],
|
|
25
|
+
});
|
|
@@ -5,17 +5,20 @@ import { IdentifierFactory } from "../../factories/IdentifierFactory";
|
|
|
5
5
|
import { IMetadataTag } from "../../metadata/IMetadataTag";
|
|
6
6
|
|
|
7
7
|
import { FunctionImporter } from "../helpers/FunctionImporeter";
|
|
8
|
+
import { ICheckEntry } from "../helpers/ICheckEntry";
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* @internal
|
|
11
12
|
*/
|
|
12
13
|
export const check_string_tags =
|
|
13
14
|
(importer: FunctionImporter) =>
|
|
14
|
-
(
|
|
15
|
-
|
|
15
|
+
(tagList: IMetadataTag[]) =>
|
|
16
|
+
(input: ts.Expression): ICheckEntry.ITag[] => {
|
|
17
|
+
const conditions: [IMetadataTag, ts.Expression][] = [];
|
|
16
18
|
for (const tag of tagList)
|
|
17
19
|
if (tag.kind === "format")
|
|
18
|
-
conditions.push(
|
|
20
|
+
conditions.push([
|
|
21
|
+
tag,
|
|
19
22
|
ts.factory.createStrictEquality(
|
|
20
23
|
ts.factory.createTrue(),
|
|
21
24
|
ts.factory.createCallExpression(
|
|
@@ -24,9 +27,10 @@ export const check_string_tags =
|
|
|
24
27
|
[input],
|
|
25
28
|
),
|
|
26
29
|
),
|
|
27
|
-
);
|
|
30
|
+
]);
|
|
28
31
|
else if (tag.kind === "pattern")
|
|
29
|
-
conditions.push(
|
|
32
|
+
conditions.push([
|
|
33
|
+
tag,
|
|
30
34
|
ts.factory.createStrictEquality(
|
|
31
35
|
ts.factory.createTrue(),
|
|
32
36
|
ts.factory.createCallExpression(
|
|
@@ -37,27 +41,33 @@ export const check_string_tags =
|
|
|
37
41
|
[input],
|
|
38
42
|
),
|
|
39
43
|
),
|
|
40
|
-
);
|
|
44
|
+
]);
|
|
41
45
|
else if (tag.kind === "length")
|
|
42
|
-
conditions.push(
|
|
46
|
+
conditions.push([
|
|
47
|
+
tag,
|
|
43
48
|
ts.factory.createStrictEquality(
|
|
44
49
|
ts.factory.createNumericLiteral(tag.value),
|
|
45
50
|
IdentifierFactory.join(input, "length"),
|
|
46
51
|
),
|
|
47
|
-
);
|
|
52
|
+
]);
|
|
48
53
|
else if (tag.kind === "minLength")
|
|
49
|
-
conditions.push(
|
|
54
|
+
conditions.push([
|
|
55
|
+
tag,
|
|
50
56
|
ts.factory.createLessThanEquals(
|
|
51
57
|
ts.factory.createNumericLiteral(tag.value),
|
|
52
58
|
IdentifierFactory.join(input, "length"),
|
|
53
59
|
),
|
|
54
|
-
);
|
|
60
|
+
]);
|
|
55
61
|
else if (tag.kind === "maxLength")
|
|
56
|
-
conditions.push(
|
|
62
|
+
conditions.push([
|
|
63
|
+
tag,
|
|
57
64
|
ts.factory.createGreaterThanEquals(
|
|
58
65
|
ts.factory.createNumericLiteral(tag.value),
|
|
59
66
|
IdentifierFactory.join(input, "length"),
|
|
60
67
|
),
|
|
61
|
-
);
|
|
62
|
-
return conditions
|
|
68
|
+
]);
|
|
69
|
+
return conditions.map(([tag, expression]) => ({
|
|
70
|
+
expected: `string (@${tag.kind} ${tag.value})`,
|
|
71
|
+
expression,
|
|
72
|
+
}));
|
|
63
73
|
};
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import ts from "typescript";
|
|
2
2
|
|
|
3
|
+
import { IJsDocTagInfo } from "../../metadata/IJsDocTagInfo";
|
|
3
4
|
import { IMetadataTag } from "../../metadata/IMetadataTag";
|
|
4
5
|
import { Metadata } from "../../metadata/Metadata";
|
|
5
6
|
|
|
6
7
|
import { FunctionImporter } from "../helpers/FunctionImporeter";
|
|
8
|
+
import { ICheckEntry } from "../helpers/ICheckEntry";
|
|
9
|
+
import { check_custom } from "./check_custom";
|
|
7
10
|
import { check_string_tags } from "./check_string_tags";
|
|
8
11
|
import { template_to_pattern } from "./template_to_pattern";
|
|
9
12
|
|
|
@@ -12,18 +15,16 @@ import { template_to_pattern } from "./template_to_pattern";
|
|
|
12
15
|
*/
|
|
13
16
|
export const check_template =
|
|
14
17
|
(importer: FunctionImporter) =>
|
|
15
|
-
(
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
) => {
|
|
18
|
+
(metaTags: IMetadataTag[]) =>
|
|
19
|
+
(jsDocTags: IJsDocTagInfo[]) =>
|
|
20
|
+
(templates: Metadata[][]) =>
|
|
21
|
+
(input: ts.Expression): ICheckEntry => {
|
|
20
22
|
// TYPEOF STRING & TAGS
|
|
21
23
|
const conditions: ts.Expression[] = [
|
|
22
24
|
ts.factory.createStrictEquality(
|
|
23
25
|
ts.factory.createStringLiteral("string"),
|
|
24
26
|
ts.factory.createTypeOfExpression(input),
|
|
25
27
|
),
|
|
26
|
-
...check_string_tags(importer)(input, tagList),
|
|
27
28
|
];
|
|
28
29
|
|
|
29
30
|
// TEMPLATES
|
|
@@ -46,5 +47,13 @@ export const check_template =
|
|
|
46
47
|
);
|
|
47
48
|
|
|
48
49
|
// COMBINATION
|
|
49
|
-
return
|
|
50
|
+
return {
|
|
51
|
+
expression: conditions.reduce((x, y) =>
|
|
52
|
+
ts.factory.createLogicalAnd(x, y),
|
|
53
|
+
),
|
|
54
|
+
tags: [
|
|
55
|
+
...check_string_tags(importer)(metaTags)(input),
|
|
56
|
+
...check_custom("string")(importer)(jsDocTags)(input),
|
|
57
|
+
],
|
|
58
|
+
};
|
|
50
59
|
};
|