typia 7.0.0-dev.20241009-2 → 7.0.0-dev.20241010
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/factories/JsonMetadataFactory.d.ts +5 -1
- package/lib/factories/JsonMetadataFactory.js +4 -1
- package/lib/factories/JsonMetadataFactory.js.map +1 -1
- package/lib/internal/{$httpFormDataReadArray.js → $httpFormdataReadArray.js} +1 -1
- package/lib/internal/$httpFormdataReadArray.js.map +1 -0
- package/lib/programmers/CheckerProgrammer.js +4 -1
- package/lib/programmers/CheckerProgrammer.js.map +1 -1
- package/lib/programmers/FeatureProgrammer.d.ts +4 -1
- package/lib/programmers/FeatureProgrammer.js +2 -2
- package/lib/programmers/FeatureProgrammer.js.map +1 -1
- package/lib/programmers/RandomProgrammer.js +12 -9
- package/lib/programmers/RandomProgrammer.js.map +1 -1
- package/lib/programmers/TypiaProgrammer.js +4 -1
- package/lib/programmers/TypiaProgrammer.js.map +1 -1
- package/lib/programmers/internal/prune_object_properties.js +3 -2
- package/lib/programmers/internal/prune_object_properties.js.map +1 -1
- package/lib/programmers/json/JsonAssertParseProgrammer.js +2 -2
- package/lib/programmers/json/JsonAssertParseProgrammer.js.map +1 -1
- package/lib/programmers/misc/MiscCloneProgrammer.js +4 -1
- package/lib/programmers/misc/MiscCloneProgrammer.js.map +1 -1
- package/lib/programmers/misc/MiscPruneProgrammer.js +4 -1
- package/lib/programmers/misc/MiscPruneProgrammer.js.map +1 -1
- package/lib/programmers/notations/NotationGeneralProgrammer.js +4 -1
- package/lib/programmers/notations/NotationGeneralProgrammer.js.map +1 -1
- package/lib/programmers/protobuf/ProtobufDecodeProgrammer.js +1 -1
- package/lib/programmers/protobuf/ProtobufDecodeProgrammer.js.map +1 -1
- package/lib/transformers/FileTransformer.js +0 -6
- package/lib/transformers/FileTransformer.js.map +1 -1
- package/lib/transformers/ImportTransformer.d.ts +4 -1
- package/lib/transformers/ImportTransformer.js +34 -30
- package/lib/transformers/ImportTransformer.js.map +1 -1
- package/package.json +1 -1
- package/src/IRandomGenerator.ts +49 -49
- package/src/factories/ExpressionFactory.ts +164 -164
- package/src/factories/JsonMetadataFactory.ts +25 -15
- package/src/factories/LiteralFactory.ts +50 -50
- package/src/factories/MetadataCommentTagFactory.ts +650 -650
- package/src/functional.ts +750 -750
- package/src/http.ts +1042 -1042
- package/src/internal/$IProtobufWriter.ts +18 -18
- package/src/internal/$ProtobufReader.ts +194 -194
- package/src/internal/$ProtobufSizer.ts +151 -151
- package/src/internal/$ProtobufWriter.ts +145 -145
- package/src/internal/$accessExpressionAsString.ts +46 -46
- package/src/internal/$assertGuard.ts +13 -13
- package/src/internal/$functionalTypeGuardErrorFactory.ts +4 -4
- package/src/internal/$httpFormDataReadBigint.ts +18 -18
- package/src/internal/$httpFormDataReadBlob.ts +10 -10
- package/src/internal/$httpFormDataReadBoolean.ts +16 -16
- package/src/internal/$httpFormDataReadFile.ts +10 -10
- package/src/internal/$httpFormDataReadNumber.ts +15 -15
- package/src/internal/$httpFormDataReadString.ts +10 -10
- package/src/internal/{$httpFormDataReadArray.ts → $httpFormdataReadArray.ts} +4 -4
- package/src/internal/$httpHeaderReadBigint.ts +10 -10
- package/src/internal/$httpHeaderReadBoolean.ts +8 -8
- package/src/internal/$httpHeaderReadNumber.ts +7 -7
- package/src/internal/$httpParameterBigint.ts +10 -10
- package/src/internal/$httpParameterBoolean.ts +8 -8
- package/src/internal/$httpParameterNumber.ts +7 -7
- package/src/internal/$httpParameterString.ts +2 -2
- package/src/internal/$httpQueryParseURLSearchParams.ts +10 -10
- package/src/internal/$httpQueryReadArray.ts +4 -4
- package/src/internal/$httpQueryReadBigint.ts +12 -12
- package/src/internal/$httpQueryReadBoolean.ts +14 -14
- package/src/internal/$httpQueryReadNumber.ts +9 -9
- package/src/internal/$httpQueryReadString.ts +4 -4
- package/src/internal/$isBetween.ts +2 -2
- package/src/internal/$isBigintString.ts +8 -8
- package/src/internal/$jsonStringifyNumber.ts +12 -12
- package/src/internal/$jsonStringifyRest.ts +3 -3
- package/src/internal/$jsonStringifyString.ts +42 -42
- package/src/internal/$jsonStringifyTail.ts +2 -2
- package/src/internal/$llmApplicationFinalize.ts +18 -18
- package/src/internal/$miscCloneAny.ts +48 -48
- package/src/internal/$notationAny.ts +37 -37
- package/src/internal/$notationCamel.ts +13 -13
- package/src/internal/$notationPascal.ts +8 -8
- package/src/internal/$notationSnake.ts +43 -43
- package/src/internal/$randomArray.ts +21 -21
- package/src/internal/$randomBigint.ts +6 -6
- package/src/internal/$randomBoolean.ts +1 -1
- package/src/internal/$randomFormatByte.ts +3 -3
- package/src/internal/$randomFormatDate.ts +18 -18
- package/src/internal/$randomFormatDatetime.ts +16 -16
- package/src/internal/$randomFormatDuration.ts +27 -27
- package/src/internal/$randomFormatEmail.ts +11 -11
- package/src/internal/$randomFormatHostname.ts +6 -6
- package/src/internal/$randomFormatIdnEmail.ts +3 -3
- package/src/internal/$randomFormatIdnHostname.ts +3 -3
- package/src/internal/$randomFormatIpv4.ts +11 -11
- package/src/internal/$randomFormatIpv6.ts +11 -11
- package/src/internal/$randomFormatIri.ts +3 -3
- package/src/internal/$randomFormatIriReference.ts +3 -3
- package/src/internal/$randomFormatJsonPointer.ts +7 -7
- package/src/internal/$randomFormatPassword.ts +8 -8
- package/src/internal/$randomFormatRegex.ts +4 -4
- package/src/internal/$randomFormatRelativeJsonPointer.ts +8 -8
- package/src/internal/$randomFormatTime.ts +14 -14
- package/src/internal/$randomFormatUri.ts +3 -3
- package/src/internal/$randomFormatUriReference.ts +3 -3
- package/src/internal/$randomFormatUriTemplate.ts +3 -3
- package/src/internal/$randomFormatUrl.ts +11 -11
- package/src/internal/$randomFormatUuid.ts +6 -6
- package/src/internal/$randomInteger.ts +47 -47
- package/src/internal/$randomNumber.ts +74 -74
- package/src/internal/$randomPattern.ts +10 -10
- package/src/internal/$randomPick.ts +9 -9
- package/src/internal/$randomString.ts +24 -24
- package/src/internal/$throwTypeGuardError.ts +5 -5
- package/src/internal/$validateReport.ts +13 -13
- package/src/internal/private/$__notationCapitalize.ts +2 -2
- package/src/internal/private/$__notationUnsnake.ts +24 -24
- package/src/json.ts +651 -651
- package/src/llm.ts +178 -178
- package/src/misc.ts +658 -658
- package/src/module.ts +933 -933
- package/src/notations.ts +827 -827
- package/src/programmers/CheckerProgrammer.ts +4 -1
- package/src/programmers/FeatureProgrammer.ts +619 -616
- package/src/programmers/RandomProgrammer.ts +24 -16
- package/src/programmers/TypiaProgrammer.ts +4 -1
- package/src/programmers/functional/FunctionalAssertFunctionProgrammer.ts +153 -153
- package/src/programmers/functional/FunctionalAssertParametersProgrammer.ts +125 -125
- package/src/programmers/functional/FunctionalAssertReturnProgrammer.ts +115 -115
- package/src/programmers/functional/FunctionalValidateFunctionProgrammer.ts +119 -119
- package/src/programmers/functional/FunctionalValidateParametersProgrammer.ts +274 -274
- package/src/programmers/functional/FunctionalValidateReturnProgrammer.ts +135 -135
- package/src/programmers/helpers/FunctionProgrammer.ts +67 -67
- package/src/programmers/helpers/RandomJoiner.ts +168 -168
- package/src/programmers/helpers/StringifyJoinder.ts +115 -115
- package/src/programmers/helpers/disable_function_programmer_declare.ts +32 -32
- package/src/programmers/internal/check_dynamic_key.ts +201 -201
- package/src/programmers/internal/check_dynamic_properties.ts +208 -208
- package/src/programmers/internal/check_object.ts +75 -75
- package/src/programmers/internal/feature_object_entries.ts +61 -61
- package/src/programmers/internal/prune_object_properties.ts +71 -63
- package/src/programmers/json/JsonAssertParseProgrammer.ts +14 -11
- package/src/programmers/llm/LlmApplicationProgrammer.ts +235 -235
- package/src/programmers/llm/LlmSchemaProgrammer.ts +51 -51
- package/src/programmers/misc/MiscCloneProgrammer.ts +4 -1
- package/src/programmers/misc/MiscPruneProgrammer.ts +4 -1
- package/src/programmers/notations/NotationGeneralProgrammer.ts +4 -1
- package/src/programmers/protobuf/ProtobufDecodeProgrammer.ts +1 -1
- package/src/protobuf.ts +868 -868
- package/src/reflect.ts +57 -57
- package/src/transformers/FileTransformer.ts +0 -6
- package/src/transformers/ImportTransformer.ts +59 -44
- package/src/utils/NamingConvention.ts +94 -94
- package/src/utils/StringUtil.ts +16 -16
- package/lib/internal/$httpFormDataReadArray.js.map +0 -1
- /package/lib/internal/{$httpFormDataReadArray.d.ts → $httpFormdataReadArray.d.ts} +0 -0
|
@@ -1,201 +1,201 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { Metadata } from "../../schemas/metadata/Metadata";
|
|
4
|
-
|
|
5
|
-
import { ITypiaContext } from "../../transformers/ITypiaContext";
|
|
6
|
-
|
|
7
|
-
import { ICheckEntry } from "../helpers/ICheckEntry";
|
|
8
|
-
import { check_bigint } from "./check_bigint";
|
|
9
|
-
import { check_number } from "./check_number";
|
|
10
|
-
import { check_string } from "./check_string";
|
|
11
|
-
import { check_template } from "./check_template";
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* @internal
|
|
15
|
-
*/
|
|
16
|
-
export const check_dynamic_key = (props: {
|
|
17
|
-
context: ITypiaContext;
|
|
18
|
-
metadata: Metadata;
|
|
19
|
-
input: ts.Expression;
|
|
20
|
-
}): ts.Expression => {
|
|
21
|
-
// IF PURE STRING EXISTS, THEN SKIP VALIDATION
|
|
22
|
-
if (
|
|
23
|
-
(props.metadata.atomics.length !== 0 &&
|
|
24
|
-
props.metadata.atomics.some(
|
|
25
|
-
(a) =>
|
|
26
|
-
a.type === "string" &&
|
|
27
|
-
a.tags.filter((row) => row.every((t) => t.validate !== undefined))
|
|
28
|
-
.length === 0,
|
|
29
|
-
)) ||
|
|
30
|
-
(props.metadata.natives.length !== 0 &&
|
|
31
|
-
props.metadata.natives.some((type) => type === "String"))
|
|
32
|
-
)
|
|
33
|
-
return ts.factory.createTrue();
|
|
34
|
-
|
|
35
|
-
const conditions: ts.Expression[] = [];
|
|
36
|
-
|
|
37
|
-
// NULLISH COALESCING
|
|
38
|
-
if (props.metadata.nullable === true)
|
|
39
|
-
conditions.push(
|
|
40
|
-
ts.factory.createStrictEquality(
|
|
41
|
-
ts.factory.createStringLiteral("null"),
|
|
42
|
-
props.input,
|
|
43
|
-
),
|
|
44
|
-
);
|
|
45
|
-
if (props.metadata.isRequired() === false)
|
|
46
|
-
conditions.push(
|
|
47
|
-
ts.factory.createStrictEquality(
|
|
48
|
-
ts.factory.createStringLiteral("undefined"),
|
|
49
|
-
props.input,
|
|
50
|
-
),
|
|
51
|
-
);
|
|
52
|
-
|
|
53
|
-
// ATOMICS
|
|
54
|
-
for (const atom of props.metadata.atomics)
|
|
55
|
-
if (atom.type === "boolean")
|
|
56
|
-
conditions.push(
|
|
57
|
-
ts.factory.createLogicalOr(
|
|
58
|
-
ts.factory.createStrictEquality(
|
|
59
|
-
ts.factory.createStringLiteral("false"),
|
|
60
|
-
props.input,
|
|
61
|
-
),
|
|
62
|
-
ts.factory.createStrictEquality(
|
|
63
|
-
ts.factory.createStringLiteral("true"),
|
|
64
|
-
props.input,
|
|
65
|
-
),
|
|
66
|
-
),
|
|
67
|
-
);
|
|
68
|
-
else if (atom.type === "bigint")
|
|
69
|
-
conditions.push(
|
|
70
|
-
ts.factory.createLogicalAnd(
|
|
71
|
-
ts.factory.createCallExpression(
|
|
72
|
-
props.context.importer.internal("isBigintString"),
|
|
73
|
-
undefined,
|
|
74
|
-
[props.input],
|
|
75
|
-
),
|
|
76
|
-
atomist(
|
|
77
|
-
check_bigint({
|
|
78
|
-
context: props.context,
|
|
79
|
-
atomic: atom,
|
|
80
|
-
input: ts.factory.createCallExpression(
|
|
81
|
-
ts.factory.createIdentifier("BigInt"),
|
|
82
|
-
undefined,
|
|
83
|
-
[props.input],
|
|
84
|
-
),
|
|
85
|
-
}),
|
|
86
|
-
),
|
|
87
|
-
),
|
|
88
|
-
);
|
|
89
|
-
else if (atom.type === "number")
|
|
90
|
-
conditions.push(
|
|
91
|
-
atomist(
|
|
92
|
-
check_number({
|
|
93
|
-
context: props.context,
|
|
94
|
-
numeric: true,
|
|
95
|
-
atomic: atom,
|
|
96
|
-
input: ts.factory.createCallExpression(
|
|
97
|
-
ts.factory.createIdentifier("Number"),
|
|
98
|
-
undefined,
|
|
99
|
-
[props.input],
|
|
100
|
-
),
|
|
101
|
-
}),
|
|
102
|
-
),
|
|
103
|
-
);
|
|
104
|
-
else
|
|
105
|
-
conditions.push(
|
|
106
|
-
atomist(
|
|
107
|
-
check_string({
|
|
108
|
-
context: props.context,
|
|
109
|
-
atomic: atom,
|
|
110
|
-
input: props.input,
|
|
111
|
-
}),
|
|
112
|
-
),
|
|
113
|
-
);
|
|
114
|
-
|
|
115
|
-
// CONSTANTS
|
|
116
|
-
for (const constant of props.metadata.constants)
|
|
117
|
-
for (const { value } of constant.values)
|
|
118
|
-
conditions.push(
|
|
119
|
-
ts.factory.createStrictEquality(
|
|
120
|
-
ts.factory.createStringLiteral(String(value)),
|
|
121
|
-
props.input,
|
|
122
|
-
),
|
|
123
|
-
);
|
|
124
|
-
|
|
125
|
-
// TEMPLATES
|
|
126
|
-
if (!!props.metadata.templates.length)
|
|
127
|
-
conditions.push(
|
|
128
|
-
atomist(
|
|
129
|
-
check_template({
|
|
130
|
-
templates: props.metadata.templates,
|
|
131
|
-
input: props.input,
|
|
132
|
-
}),
|
|
133
|
-
),
|
|
134
|
-
);
|
|
135
|
-
|
|
136
|
-
// NATIVES
|
|
137
|
-
for (const native of props.metadata.natives)
|
|
138
|
-
if (native === "Boolean")
|
|
139
|
-
conditions.push(
|
|
140
|
-
ts.factory.createLogicalOr(
|
|
141
|
-
ts.factory.createStrictEquality(
|
|
142
|
-
ts.factory.createStringLiteral("false"),
|
|
143
|
-
props.input,
|
|
144
|
-
),
|
|
145
|
-
ts.factory.createStrictEquality(
|
|
146
|
-
ts.factory.createStringLiteral("true"),
|
|
147
|
-
props.input,
|
|
148
|
-
),
|
|
149
|
-
),
|
|
150
|
-
);
|
|
151
|
-
else if (native === "BigInt")
|
|
152
|
-
conditions.push(
|
|
153
|
-
ts.factory.createCallExpression(
|
|
154
|
-
props.context.importer.internal("isBigintString"),
|
|
155
|
-
undefined,
|
|
156
|
-
[props.input],
|
|
157
|
-
),
|
|
158
|
-
);
|
|
159
|
-
else if (native === "Number")
|
|
160
|
-
conditions.push(
|
|
161
|
-
ts.factory.createStrictEquality(
|
|
162
|
-
ts.factory.createFalse(),
|
|
163
|
-
ts.factory.createCallExpression(
|
|
164
|
-
ts.factory.createIdentifier("Number.isNaN"),
|
|
165
|
-
undefined,
|
|
166
|
-
[
|
|
167
|
-
ts.factory.createCallExpression(
|
|
168
|
-
ts.factory.createIdentifier("Number"),
|
|
169
|
-
undefined,
|
|
170
|
-
[props.input],
|
|
171
|
-
),
|
|
172
|
-
],
|
|
173
|
-
),
|
|
174
|
-
),
|
|
175
|
-
);
|
|
176
|
-
|
|
177
|
-
return conditions.length === 0
|
|
178
|
-
? ts.factory.createTrue()
|
|
179
|
-
: conditions.length === 1
|
|
180
|
-
? conditions[0]!
|
|
181
|
-
: conditions.reduce(ts.factory.createLogicalOr);
|
|
182
|
-
};
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* @internal
|
|
186
|
-
*/
|
|
187
|
-
const atomist = (entry: ICheckEntry) =>
|
|
188
|
-
[
|
|
189
|
-
...(entry.expression ? [entry.expression] : []),
|
|
190
|
-
...(entry.conditions.length === 0
|
|
191
|
-
? []
|
|
192
|
-
: [
|
|
193
|
-
entry.conditions
|
|
194
|
-
.map((set) =>
|
|
195
|
-
set
|
|
196
|
-
.map((s) => s.expression)
|
|
197
|
-
.reduce((a, b) => ts.factory.createLogicalAnd(a, b)),
|
|
198
|
-
)
|
|
199
|
-
.reduce((a, b) => ts.factory.createLogicalOr(a, b)),
|
|
200
|
-
]),
|
|
201
|
-
].reduce((x, y) => ts.factory.createLogicalAnd(x, y));
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { Metadata } from "../../schemas/metadata/Metadata";
|
|
4
|
+
|
|
5
|
+
import { ITypiaContext } from "../../transformers/ITypiaContext";
|
|
6
|
+
|
|
7
|
+
import { ICheckEntry } from "../helpers/ICheckEntry";
|
|
8
|
+
import { check_bigint } from "./check_bigint";
|
|
9
|
+
import { check_number } from "./check_number";
|
|
10
|
+
import { check_string } from "./check_string";
|
|
11
|
+
import { check_template } from "./check_template";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
export const check_dynamic_key = (props: {
|
|
17
|
+
context: ITypiaContext;
|
|
18
|
+
metadata: Metadata;
|
|
19
|
+
input: ts.Expression;
|
|
20
|
+
}): ts.Expression => {
|
|
21
|
+
// IF PURE STRING EXISTS, THEN SKIP VALIDATION
|
|
22
|
+
if (
|
|
23
|
+
(props.metadata.atomics.length !== 0 &&
|
|
24
|
+
props.metadata.atomics.some(
|
|
25
|
+
(a) =>
|
|
26
|
+
a.type === "string" &&
|
|
27
|
+
a.tags.filter((row) => row.every((t) => t.validate !== undefined))
|
|
28
|
+
.length === 0,
|
|
29
|
+
)) ||
|
|
30
|
+
(props.metadata.natives.length !== 0 &&
|
|
31
|
+
props.metadata.natives.some((type) => type === "String"))
|
|
32
|
+
)
|
|
33
|
+
return ts.factory.createTrue();
|
|
34
|
+
|
|
35
|
+
const conditions: ts.Expression[] = [];
|
|
36
|
+
|
|
37
|
+
// NULLISH COALESCING
|
|
38
|
+
if (props.metadata.nullable === true)
|
|
39
|
+
conditions.push(
|
|
40
|
+
ts.factory.createStrictEquality(
|
|
41
|
+
ts.factory.createStringLiteral("null"),
|
|
42
|
+
props.input,
|
|
43
|
+
),
|
|
44
|
+
);
|
|
45
|
+
if (props.metadata.isRequired() === false)
|
|
46
|
+
conditions.push(
|
|
47
|
+
ts.factory.createStrictEquality(
|
|
48
|
+
ts.factory.createStringLiteral("undefined"),
|
|
49
|
+
props.input,
|
|
50
|
+
),
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
// ATOMICS
|
|
54
|
+
for (const atom of props.metadata.atomics)
|
|
55
|
+
if (atom.type === "boolean")
|
|
56
|
+
conditions.push(
|
|
57
|
+
ts.factory.createLogicalOr(
|
|
58
|
+
ts.factory.createStrictEquality(
|
|
59
|
+
ts.factory.createStringLiteral("false"),
|
|
60
|
+
props.input,
|
|
61
|
+
),
|
|
62
|
+
ts.factory.createStrictEquality(
|
|
63
|
+
ts.factory.createStringLiteral("true"),
|
|
64
|
+
props.input,
|
|
65
|
+
),
|
|
66
|
+
),
|
|
67
|
+
);
|
|
68
|
+
else if (atom.type === "bigint")
|
|
69
|
+
conditions.push(
|
|
70
|
+
ts.factory.createLogicalAnd(
|
|
71
|
+
ts.factory.createCallExpression(
|
|
72
|
+
props.context.importer.internal("isBigintString"),
|
|
73
|
+
undefined,
|
|
74
|
+
[props.input],
|
|
75
|
+
),
|
|
76
|
+
atomist(
|
|
77
|
+
check_bigint({
|
|
78
|
+
context: props.context,
|
|
79
|
+
atomic: atom,
|
|
80
|
+
input: ts.factory.createCallExpression(
|
|
81
|
+
ts.factory.createIdentifier("BigInt"),
|
|
82
|
+
undefined,
|
|
83
|
+
[props.input],
|
|
84
|
+
),
|
|
85
|
+
}),
|
|
86
|
+
),
|
|
87
|
+
),
|
|
88
|
+
);
|
|
89
|
+
else if (atom.type === "number")
|
|
90
|
+
conditions.push(
|
|
91
|
+
atomist(
|
|
92
|
+
check_number({
|
|
93
|
+
context: props.context,
|
|
94
|
+
numeric: true,
|
|
95
|
+
atomic: atom,
|
|
96
|
+
input: ts.factory.createCallExpression(
|
|
97
|
+
ts.factory.createIdentifier("Number"),
|
|
98
|
+
undefined,
|
|
99
|
+
[props.input],
|
|
100
|
+
),
|
|
101
|
+
}),
|
|
102
|
+
),
|
|
103
|
+
);
|
|
104
|
+
else
|
|
105
|
+
conditions.push(
|
|
106
|
+
atomist(
|
|
107
|
+
check_string({
|
|
108
|
+
context: props.context,
|
|
109
|
+
atomic: atom,
|
|
110
|
+
input: props.input,
|
|
111
|
+
}),
|
|
112
|
+
),
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
// CONSTANTS
|
|
116
|
+
for (const constant of props.metadata.constants)
|
|
117
|
+
for (const { value } of constant.values)
|
|
118
|
+
conditions.push(
|
|
119
|
+
ts.factory.createStrictEquality(
|
|
120
|
+
ts.factory.createStringLiteral(String(value)),
|
|
121
|
+
props.input,
|
|
122
|
+
),
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
// TEMPLATES
|
|
126
|
+
if (!!props.metadata.templates.length)
|
|
127
|
+
conditions.push(
|
|
128
|
+
atomist(
|
|
129
|
+
check_template({
|
|
130
|
+
templates: props.metadata.templates,
|
|
131
|
+
input: props.input,
|
|
132
|
+
}),
|
|
133
|
+
),
|
|
134
|
+
);
|
|
135
|
+
|
|
136
|
+
// NATIVES
|
|
137
|
+
for (const native of props.metadata.natives)
|
|
138
|
+
if (native === "Boolean")
|
|
139
|
+
conditions.push(
|
|
140
|
+
ts.factory.createLogicalOr(
|
|
141
|
+
ts.factory.createStrictEquality(
|
|
142
|
+
ts.factory.createStringLiteral("false"),
|
|
143
|
+
props.input,
|
|
144
|
+
),
|
|
145
|
+
ts.factory.createStrictEquality(
|
|
146
|
+
ts.factory.createStringLiteral("true"),
|
|
147
|
+
props.input,
|
|
148
|
+
),
|
|
149
|
+
),
|
|
150
|
+
);
|
|
151
|
+
else if (native === "BigInt")
|
|
152
|
+
conditions.push(
|
|
153
|
+
ts.factory.createCallExpression(
|
|
154
|
+
props.context.importer.internal("isBigintString"),
|
|
155
|
+
undefined,
|
|
156
|
+
[props.input],
|
|
157
|
+
),
|
|
158
|
+
);
|
|
159
|
+
else if (native === "Number")
|
|
160
|
+
conditions.push(
|
|
161
|
+
ts.factory.createStrictEquality(
|
|
162
|
+
ts.factory.createFalse(),
|
|
163
|
+
ts.factory.createCallExpression(
|
|
164
|
+
ts.factory.createIdentifier("Number.isNaN"),
|
|
165
|
+
undefined,
|
|
166
|
+
[
|
|
167
|
+
ts.factory.createCallExpression(
|
|
168
|
+
ts.factory.createIdentifier("Number"),
|
|
169
|
+
undefined,
|
|
170
|
+
[props.input],
|
|
171
|
+
),
|
|
172
|
+
],
|
|
173
|
+
),
|
|
174
|
+
),
|
|
175
|
+
);
|
|
176
|
+
|
|
177
|
+
return conditions.length === 0
|
|
178
|
+
? ts.factory.createTrue()
|
|
179
|
+
: conditions.length === 1
|
|
180
|
+
? conditions[0]!
|
|
181
|
+
: conditions.reduce(ts.factory.createLogicalOr);
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* @internal
|
|
186
|
+
*/
|
|
187
|
+
const atomist = (entry: ICheckEntry) =>
|
|
188
|
+
[
|
|
189
|
+
...(entry.expression ? [entry.expression] : []),
|
|
190
|
+
...(entry.conditions.length === 0
|
|
191
|
+
? []
|
|
192
|
+
: [
|
|
193
|
+
entry.conditions
|
|
194
|
+
.map((set) =>
|
|
195
|
+
set
|
|
196
|
+
.map((s) => s.expression)
|
|
197
|
+
.reduce((a, b) => ts.factory.createLogicalAnd(a, b)),
|
|
198
|
+
)
|
|
199
|
+
.reduce((a, b) => ts.factory.createLogicalOr(a, b)),
|
|
200
|
+
]),
|
|
201
|
+
].reduce((x, y) => ts.factory.createLogicalAnd(x, y));
|