typia 5.2.4-dev.20231023 → 5.2.5-dev.20231105
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/internal/metadata/emplace_metadata_object.js +24 -0
- package/lib/factories/internal/metadata/emplace_metadata_object.js.map +1 -1
- package/lib/functional/$stoll.d.ts +1 -0
- package/lib/functional/$stoll.js +14 -0
- package/lib/functional/$stoll.js.map +1 -0
- package/lib/functional/Namespace.js +4 -10
- package/lib/functional/Namespace.js.map +1 -1
- package/lib/programmers/AssertProgrammer.js +71 -63
- package/lib/programmers/AssertProgrammer.js.map +1 -1
- package/lib/programmers/IsProgrammer.d.ts +2 -2
- package/lib/programmers/IsProgrammer.js +66 -64
- package/lib/programmers/IsProgrammer.js.map +1 -1
- package/lib/programmers/ValidateProgrammer.js +50 -46
- package/lib/programmers/ValidateProgrammer.js.map +1 -1
- package/lib/programmers/internal/check_dynamic_key.d.ts +5 -0
- package/lib/programmers/internal/check_dynamic_key.js +158 -0
- package/lib/programmers/internal/check_dynamic_key.js.map +1 -0
- package/lib/programmers/internal/check_dynamic_properties.js +69 -61
- package/lib/programmers/internal/check_dynamic_properties.js.map +1 -1
- package/lib/programmers/internal/check_object.js +11 -9
- package/lib/programmers/internal/check_object.js.map +1 -1
- package/lib/programmers/json/JsonStringifyProgrammer.js +1 -1
- package/lib/programmers/json/JsonStringifyProgrammer.js.map +1 -1
- package/lib/programmers/misc/MiscCloneProgrammer.js +1 -1
- package/lib/programmers/misc/MiscCloneProgrammer.js.map +1 -1
- package/lib/programmers/misc/MiscPruneProgrammer.js +1 -1
- package/lib/programmers/misc/MiscPruneProgrammer.js.map +1 -1
- package/lib/programmers/notations/NotationGeneralProgrammer.js +1 -1
- package/lib/programmers/notations/NotationGeneralProgrammer.js.map +1 -1
- package/lib/programmers/protobuf/ProtobufEncodeProgrammer.js +1 -1
- package/lib/programmers/protobuf/ProtobufEncodeProgrammer.js.map +1 -1
- package/package.json +1 -1
- package/src/CamelCase.ts +116 -116
- package/src/PascalCase.ts +116 -116
- package/src/Primitive.ts +135 -135
- package/src/Resolved.ts +116 -116
- package/src/SnakeCase.ts +156 -156
- package/src/executable/TypiaSetupWizard.ts +142 -142
- package/src/executable/setup/CommandExecutor.ts +8 -8
- package/src/factories/JsonMetadataFactory.ts +50 -50
- package/src/factories/MetadataCollection.ts +282 -282
- package/src/factories/internal/metadata/emplace_metadata_object.ts +28 -0
- package/src/functional/$convention.ts +40 -40
- package/src/functional/$stoll.ts +8 -0
- package/src/functional/Namespace.ts +168 -164
- package/src/module.ts +662 -662
- package/src/notations.ts +855 -855
- package/src/programmers/AssertProgrammer.ts +36 -31
- package/src/programmers/IsProgrammer.ts +13 -7
- package/src/programmers/ValidateProgrammer.ts +34 -31
- package/src/programmers/helpers/AtomicPredicator.ts +31 -31
- package/src/programmers/helpers/NotationJoiner.ts +146 -146
- package/src/programmers/internal/check_dynamic_key.ts +178 -0
- package/src/programmers/internal/check_dynamic_properties.ts +19 -12
- package/src/programmers/internal/check_object.ts +8 -1
- package/src/programmers/json/JsonStringifyProgrammer.ts +1 -1
- package/src/programmers/misc/MiscCloneProgrammer.ts +790 -790
- package/src/programmers/misc/MiscPruneProgrammer.ts +552 -552
- package/src/programmers/notations/NotationAssertGeneralProgrammer.ts +72 -72
- package/src/programmers/notations/NotationGeneralProgrammer.ts +720 -720
- package/src/programmers/notations/NotationIsGeneralProgrammer.ts +79 -79
- package/src/programmers/notations/NotationValidateGeneralProgrammer.ts +88 -88
- package/src/programmers/protobuf/ProtobufEncodeProgrammer.ts +1 -1
- package/src/transformers/CallExpressionTransformer.ts +380 -380
- package/src/transformers/features/json/JsonAssertParseTransformer.ts +10 -10
- package/src/transformers/features/json/JsonAssertStringifyTransformer.ts +10 -10
- package/src/transformers/features/json/JsonCreateAssertParseTransformer.ts +12 -12
- package/src/transformers/features/json/JsonCreateAssertStringifyTransformer.ts +12 -12
- package/src/transformers/features/json/JsonCreateIsParseTransformer.ts +9 -9
- package/src/transformers/features/json/JsonCreateIsStringifyTransformer.ts +12 -12
- package/src/transformers/features/json/JsonCreateStringifyTransformer.ts +9 -9
- package/src/transformers/features/json/JsonCreateValidateParseTransformer.ts +12 -12
- package/src/transformers/features/json/JsonCreateValidateStringifyProgrammer.ts +12 -12
- package/src/transformers/features/json/JsonIsParseTransformer.ts +9 -9
- package/src/transformers/features/json/JsonIsStringifyTransformer.ts +10 -10
- package/src/transformers/features/json/JsonStringifyTransformer.ts +9 -9
- package/src/transformers/features/json/JsonValidateParseTransformer.ts +10 -10
- package/src/transformers/features/json/JsonValidateStringifyTransformer.ts +10 -10
- package/src/transformers/features/misc/MiscAssertCloneTransformer.ts +10 -10
- package/src/transformers/features/misc/MiscAssertPruneTransformer.ts +10 -10
- package/src/transformers/features/misc/MiscCloneTransformer.ts +9 -9
- package/src/transformers/features/misc/MiscCreateAssertCloneTransformer.ts +12 -12
- package/src/transformers/features/misc/MiscCreateAssertPruneTransformer.ts +12 -12
- package/src/transformers/features/misc/MiscCreateCloneTransformer.ts +9 -9
- package/src/transformers/features/misc/MiscCreateIsCloneTransformer.ts +9 -9
- package/src/transformers/features/misc/MiscCreateIsPruneTransformer.ts +9 -9
- package/src/transformers/features/misc/MiscCreatePruneTransformer.ts +9 -9
- package/src/transformers/features/misc/MiscCreateValidateCloneTransformer.ts +12 -12
- package/src/transformers/features/misc/MiscCreateValidatePruneTransformer.ts +12 -12
- package/src/transformers/features/misc/MiscIsCloneTransformer.ts +9 -9
- package/src/transformers/features/misc/MiscIsPruneTransformer.ts +9 -9
- package/src/transformers/features/misc/MiscPruneTransformer.ts +9 -9
- package/src/transformers/features/misc/MiscValidateCloneTransformer.ts +10 -10
- package/src/transformers/features/misc/MiscValidatePruneTransformer.ts +10 -10
- package/src/transformers/features/notations/NotationAssertGeneralTransformer.ts +15 -15
- package/src/transformers/features/notations/NotationCreateAssertGeneralTransformer.ts +15 -15
- package/src/transformers/features/notations/NotationCreateGeneralTransformer.ts +15 -15
- package/src/transformers/features/notations/NotationCreateIsGeneralTransformer.ts +15 -15
- package/src/transformers/features/notations/NotationCreateValidateGeneralTransformer.ts +17 -17
- package/src/transformers/features/notations/NotationGeneralTransformer.ts +11 -11
- package/src/transformers/features/notations/NotationIsGeneralTransformer.ts +15 -15
- package/src/transformers/features/notations/NotationValidateGeneralTransformer.ts +17 -17
- package/src/transformers/features/protobuf/ProtobufCreateAssertDecodeTransformer.ts +12 -12
- package/src/transformers/features/protobuf/ProtobufCreateAssertEncodeTransformer.ts +12 -12
- package/src/transformers/features/protobuf/ProtobufCreateDecodeTransformer.ts +9 -9
- package/src/transformers/features/protobuf/ProtobufCreateEncodeTransformer.ts +9 -9
- package/src/transformers/features/protobuf/ProtobufCreateIsDecodeTransformer.ts +12 -12
- package/src/transformers/features/protobuf/ProtobufCreateIsEncodeTransformer.ts +12 -12
- package/src/transformers/features/protobuf/ProtobufCreateValidateDecodeTransformer.ts +12 -12
- package/src/transformers/features/protobuf/ProtobufCreateValidateEncodeTransformer.ts +12 -12
- package/src/utils/NamingConvention.ts +91 -91
- package/src/utils/StringUtil.ts +4 -4
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { Metadata } from "../../schemas/metadata/Metadata";
|
|
4
|
+
|
|
5
|
+
import { IProject } from "../../transformers/IProject";
|
|
6
|
+
|
|
7
|
+
import { FunctionImporter } from "../helpers/FunctionImporeter";
|
|
8
|
+
import { ICheckEntry } from "../helpers/ICheckEntry";
|
|
9
|
+
import { check_bigint } from "./check_bigint";
|
|
10
|
+
import { check_number } from "./check_number";
|
|
11
|
+
import { check_string } from "./check_string";
|
|
12
|
+
import { check_template } from "./check_template";
|
|
13
|
+
|
|
14
|
+
export const check_dynamic_key =
|
|
15
|
+
(project: IProject) =>
|
|
16
|
+
(importer: FunctionImporter) =>
|
|
17
|
+
(input: ts.Expression, metadata: Metadata): ts.Expression => {
|
|
18
|
+
// IF PURE STRING EXISTS, THEN SKIP VALIDATION
|
|
19
|
+
if (
|
|
20
|
+
(metadata.atomics.length !== 0 &&
|
|
21
|
+
metadata.atomics.some(
|
|
22
|
+
(a) =>
|
|
23
|
+
a.type === "string" &&
|
|
24
|
+
a.tags.filter((row) =>
|
|
25
|
+
row.every((t) => t.validate !== undefined),
|
|
26
|
+
).length === 0,
|
|
27
|
+
)) ||
|
|
28
|
+
(metadata.natives.length !== 0 &&
|
|
29
|
+
metadata.natives.some((type) => type === "String"))
|
|
30
|
+
)
|
|
31
|
+
return ts.factory.createTrue();
|
|
32
|
+
|
|
33
|
+
const conditions: ts.Expression[] = [];
|
|
34
|
+
|
|
35
|
+
// NULLISH COALESCING
|
|
36
|
+
if (metadata.nullable === true)
|
|
37
|
+
conditions.push(
|
|
38
|
+
ts.factory.createStrictEquality(
|
|
39
|
+
ts.factory.createStringLiteral("null"),
|
|
40
|
+
input,
|
|
41
|
+
),
|
|
42
|
+
);
|
|
43
|
+
if (metadata.isRequired() === false)
|
|
44
|
+
conditions.push(
|
|
45
|
+
ts.factory.createStrictEquality(
|
|
46
|
+
ts.factory.createStringLiteral("undefined"),
|
|
47
|
+
input,
|
|
48
|
+
),
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
// ATOMICS
|
|
52
|
+
for (const atom of metadata.atomics)
|
|
53
|
+
if (atom.type === "boolean")
|
|
54
|
+
conditions.push(
|
|
55
|
+
ts.factory.createLogicalOr(
|
|
56
|
+
ts.factory.createStrictEquality(
|
|
57
|
+
ts.factory.createStringLiteral("false"),
|
|
58
|
+
input,
|
|
59
|
+
),
|
|
60
|
+
ts.factory.createStrictEquality(
|
|
61
|
+
ts.factory.createStringLiteral("true"),
|
|
62
|
+
input,
|
|
63
|
+
),
|
|
64
|
+
),
|
|
65
|
+
);
|
|
66
|
+
else if (atom.type === "bigint")
|
|
67
|
+
conditions.push(
|
|
68
|
+
ts.factory.createLogicalAnd(
|
|
69
|
+
ts.factory.createCallExpression(
|
|
70
|
+
importer.use("is_bigint_string"),
|
|
71
|
+
undefined,
|
|
72
|
+
[input],
|
|
73
|
+
),
|
|
74
|
+
atomist(
|
|
75
|
+
check_bigint(project)(atom)(
|
|
76
|
+
ts.factory.createCallExpression(
|
|
77
|
+
ts.factory.createIdentifier("BigInt"),
|
|
78
|
+
undefined,
|
|
79
|
+
[input],
|
|
80
|
+
),
|
|
81
|
+
),
|
|
82
|
+
),
|
|
83
|
+
),
|
|
84
|
+
);
|
|
85
|
+
else if (atom.type === "number")
|
|
86
|
+
conditions.push(
|
|
87
|
+
atomist(
|
|
88
|
+
check_number(project, true)(atom)(
|
|
89
|
+
ts.factory.createCallExpression(
|
|
90
|
+
ts.factory.createIdentifier("Number"),
|
|
91
|
+
undefined,
|
|
92
|
+
[input],
|
|
93
|
+
),
|
|
94
|
+
),
|
|
95
|
+
),
|
|
96
|
+
);
|
|
97
|
+
else conditions.push(atomist(check_string(project)(atom)(input)));
|
|
98
|
+
|
|
99
|
+
// CONSTANTS
|
|
100
|
+
for (const constant of metadata.constants)
|
|
101
|
+
for (const value of constant.values)
|
|
102
|
+
conditions.push(
|
|
103
|
+
ts.factory.createStrictEquality(
|
|
104
|
+
ts.factory.createStringLiteral(String(value)),
|
|
105
|
+
input,
|
|
106
|
+
),
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
// TEMPLATES
|
|
110
|
+
if (!!metadata.templates.length)
|
|
111
|
+
conditions.push(atomist(check_template(metadata.templates)(input)));
|
|
112
|
+
|
|
113
|
+
// NATIVES
|
|
114
|
+
for (const native of metadata.natives)
|
|
115
|
+
if (native === "Boolean")
|
|
116
|
+
conditions.push(
|
|
117
|
+
ts.factory.createLogicalOr(
|
|
118
|
+
ts.factory.createStrictEquality(
|
|
119
|
+
ts.factory.createStringLiteral("false"),
|
|
120
|
+
input,
|
|
121
|
+
),
|
|
122
|
+
ts.factory.createStrictEquality(
|
|
123
|
+
ts.factory.createStringLiteral("true"),
|
|
124
|
+
input,
|
|
125
|
+
),
|
|
126
|
+
),
|
|
127
|
+
);
|
|
128
|
+
else if (native === "BigInt")
|
|
129
|
+
conditions.push(
|
|
130
|
+
ts.factory.createCallExpression(
|
|
131
|
+
importer.use("is_bigint_string"),
|
|
132
|
+
undefined,
|
|
133
|
+
[input],
|
|
134
|
+
),
|
|
135
|
+
);
|
|
136
|
+
else if (native === "Number")
|
|
137
|
+
conditions.push(
|
|
138
|
+
ts.factory.createStrictEquality(
|
|
139
|
+
ts.factory.createFalse(),
|
|
140
|
+
ts.factory.createCallExpression(
|
|
141
|
+
ts.factory.createIdentifier("Number.isNaN"),
|
|
142
|
+
undefined,
|
|
143
|
+
[
|
|
144
|
+
ts.factory.createCallExpression(
|
|
145
|
+
ts.factory.createIdentifier("Number"),
|
|
146
|
+
undefined,
|
|
147
|
+
[input],
|
|
148
|
+
),
|
|
149
|
+
],
|
|
150
|
+
),
|
|
151
|
+
),
|
|
152
|
+
);
|
|
153
|
+
|
|
154
|
+
return conditions.length === 0
|
|
155
|
+
? ts.factory.createTrue()
|
|
156
|
+
: conditions.length === 1
|
|
157
|
+
? conditions[0]!
|
|
158
|
+
: conditions.reduce(ts.factory.createLogicalOr);
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
const atomist = (entry: ICheckEntry) => {
|
|
162
|
+
return [
|
|
163
|
+
...(entry.expression ? [entry.expression] : []),
|
|
164
|
+
...(entry.conditions.length === 0
|
|
165
|
+
? []
|
|
166
|
+
: [
|
|
167
|
+
entry.conditions
|
|
168
|
+
.map((set) =>
|
|
169
|
+
set
|
|
170
|
+
.map((s) => s.expression)
|
|
171
|
+
.reduce((a, b) =>
|
|
172
|
+
ts.factory.createLogicalAnd(a, b),
|
|
173
|
+
),
|
|
174
|
+
)
|
|
175
|
+
.reduce((a, b) => ts.factory.createLogicalOr(a, b)),
|
|
176
|
+
]),
|
|
177
|
+
].reduce((x, y) => ts.factory.createLogicalAnd(x, y));
|
|
178
|
+
};
|
|
@@ -3,17 +3,20 @@ import ts from "typescript";
|
|
|
3
3
|
import { IdentifierFactory } from "../../factories/IdentifierFactory";
|
|
4
4
|
import { StatementFactory } from "../../factories/StatementFactory";
|
|
5
5
|
|
|
6
|
+
import { IProject } from "../../transformers/IProject";
|
|
7
|
+
|
|
6
8
|
import { FunctionImporter } from "../helpers/FunctionImporeter";
|
|
7
9
|
import { IExpressionEntry } from "../helpers/IExpressionEntry";
|
|
10
|
+
import { check_dynamic_key } from "./check_dynamic_key";
|
|
8
11
|
import { check_everything } from "./check_everything";
|
|
9
12
|
import { check_object } from "./check_object";
|
|
10
|
-
import { metadata_to_pattern } from "./metadata_to_pattern";
|
|
11
13
|
|
|
12
14
|
/**
|
|
13
15
|
* @internal
|
|
14
16
|
*/
|
|
15
17
|
export const check_dynamic_properties =
|
|
16
18
|
(props: check_object.IProps) =>
|
|
19
|
+
(project: IProject) =>
|
|
17
20
|
(importer: FunctionImporter) =>
|
|
18
21
|
(
|
|
19
22
|
input: ts.Expression,
|
|
@@ -64,7 +67,11 @@ export const check_dynamic_properties =
|
|
|
64
67
|
undefined,
|
|
65
68
|
[input],
|
|
66
69
|
),
|
|
67
|
-
check_dynamic_property(props)(
|
|
70
|
+
check_dynamic_property(props)(project)(importer)(
|
|
71
|
+
input,
|
|
72
|
+
regular,
|
|
73
|
+
dynamic,
|
|
74
|
+
),
|
|
68
75
|
])
|
|
69
76
|
: ts.factory.createCallExpression(
|
|
70
77
|
IdentifierFactory.access(
|
|
@@ -75,7 +82,13 @@ export const check_dynamic_properties =
|
|
|
75
82
|
),
|
|
76
83
|
)(props.assert ? "every" : "map"),
|
|
77
84
|
undefined,
|
|
78
|
-
[
|
|
85
|
+
[
|
|
86
|
+
check_dynamic_property(props)(project)(importer)(
|
|
87
|
+
input,
|
|
88
|
+
regular,
|
|
89
|
+
dynamic,
|
|
90
|
+
),
|
|
91
|
+
],
|
|
79
92
|
);
|
|
80
93
|
const right: ts.Expression = (props.halt || ((elem) => elem))(
|
|
81
94
|
props.assert ? criteria : check_everything(criteria),
|
|
@@ -89,6 +102,8 @@ export const check_dynamic_properties =
|
|
|
89
102
|
|
|
90
103
|
const check_dynamic_property =
|
|
91
104
|
(props: check_object.IProps) =>
|
|
105
|
+
(project: IProject) =>
|
|
106
|
+
(importer: FunctionImporter) =>
|
|
92
107
|
(
|
|
93
108
|
input: ts.Expression,
|
|
94
109
|
regular: IExpressionEntry<ts.Expression>[],
|
|
@@ -129,15 +144,7 @@ const check_dynamic_property =
|
|
|
129
144
|
|
|
130
145
|
for (const entry of dynamic)
|
|
131
146
|
add(
|
|
132
|
-
|
|
133
|
-
ts.factory.createIdentifier(
|
|
134
|
-
`RegExp(/${metadata_to_pattern(true)(
|
|
135
|
-
entry.key,
|
|
136
|
-
)}/).test`,
|
|
137
|
-
),
|
|
138
|
-
undefined,
|
|
139
|
-
[key],
|
|
140
|
-
),
|
|
147
|
+
check_dynamic_key(project)(importer)(key, entry.key),
|
|
141
148
|
entry.expression,
|
|
142
149
|
);
|
|
143
150
|
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import ts from "typescript";
|
|
2
2
|
|
|
3
|
+
import { IProject } from "../../transformers/IProject";
|
|
4
|
+
|
|
3
5
|
import { FunctionImporter } from "../helpers/FunctionImporeter";
|
|
4
6
|
import { IExpressionEntry } from "../helpers/IExpressionEntry";
|
|
5
7
|
import { check_dynamic_properties } from "./check_dynamic_properties";
|
|
@@ -10,6 +12,7 @@ import { check_everything } from "./check_everything";
|
|
|
10
12
|
*/
|
|
11
13
|
export const check_object =
|
|
12
14
|
(props: check_object.IProps) =>
|
|
15
|
+
(project: IProject) =>
|
|
13
16
|
(importer: FunctionImporter) =>
|
|
14
17
|
(input: ts.Expression, entries: IExpressionEntry<ts.Expression>[]) => {
|
|
15
18
|
// PREPARE ASSETS
|
|
@@ -23,7 +26,11 @@ export const check_object =
|
|
|
23
26
|
|
|
24
27
|
// CHECK DYNAMIC PROPERTIES
|
|
25
28
|
flags.push(
|
|
26
|
-
check_dynamic_properties(props)(importer)(
|
|
29
|
+
check_dynamic_properties(props)(project)(importer)(
|
|
30
|
+
input,
|
|
31
|
+
regular,
|
|
32
|
+
dynamic,
|
|
33
|
+
),
|
|
27
34
|
);
|
|
28
35
|
return reduce(props)(flags);
|
|
29
36
|
};
|
|
@@ -905,7 +905,7 @@ export namespace JsonStringifyProgrammer {
|
|
|
905
905
|
decoder: () => decode_object(importer),
|
|
906
906
|
joiner: StringifyJoiner.object(importer),
|
|
907
907
|
unionizer: decode_union_object(
|
|
908
|
-
IsProgrammer.decode_object(importer),
|
|
908
|
+
IsProgrammer.decode_object(project)(importer),
|
|
909
909
|
)(decode_object(importer))((exp) => exp)(
|
|
910
910
|
(value, expected) =>
|
|
911
911
|
create_throw_error(importer)(expected)(value),
|