typia 3.4.21 → 3.4.23
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 +57 -23
- package/lib/programmers/AssertProgrammer.js +79 -70
- package/lib/programmers/AssertProgrammer.js.map +1 -1
- package/lib/programmers/IsProgrammer.d.ts +1 -0
- package/lib/programmers/IsProgrammer.js +4 -0
- package/lib/programmers/IsProgrammer.js.map +1 -1
- package/lib/programmers/ValidateProgrammer.js +68 -59
- package/lib/programmers/ValidateProgrammer.js.map +1 -1
- package/lib/programmers/helpers/OptionPredicator.d.ts +1 -0
- package/lib/programmers/helpers/OptionPredicator.js +4 -0
- package/lib/programmers/helpers/OptionPredicator.js.map +1 -1
- package/lib/programmers/internal/application_schema.js +23 -21
- package/lib/programmers/internal/application_schema.js.map +1 -1
- package/lib/programmers/internal/check_dynamic_properties.js +5 -0
- package/lib/programmers/internal/check_dynamic_properties.js.map +1 -1
- package/lib/programmers/internal/check_object.d.ts +1 -0
- package/lib/programmers/internal/check_object.js.map +1 -1
- package/lib/transformers/ITransformOptions.d.ts +10 -0
- package/package.json +2 -2
- package/src/IValidation.ts +21 -21
- package/src/Primitive.ts +82 -82
- package/src/TypeGuardError.ts +36 -36
- package/src/executable/internal/CommandParser.ts +15 -15
- package/src/factories/CommentFactory.ts +10 -10
- package/src/factories/ExpressionFactory.ts +66 -66
- package/src/factories/IdentifierFactory.ts +72 -72
- package/src/factories/LiteralFactory.ts +44 -44
- package/src/factories/StatementFactory.ts +60 -60
- package/src/factories/TemplateFactory.ts +56 -56
- package/src/factories/TypeFactory.ts +101 -101
- package/src/factories/ValueFactory.ts +12 -12
- package/src/functional/$every.ts +11 -11
- package/src/functional/$is_email.ts +5 -5
- package/src/functional/$is_ipv4.ts +5 -5
- package/src/functional/$is_ipv6.ts +5 -5
- package/src/functional/$is_url.ts +5 -5
- package/src/functional/$is_uuid.ts +5 -5
- package/src/functional/$join.ts +50 -50
- package/src/functional/$report.ts +15 -15
- package/src/functional/$rest.ts +3 -3
- package/src/functional/$string.ts +37 -37
- package/src/functional/$tail.ts +6 -6
- package/src/index.ts +4 -4
- package/src/metadata/IJsDocTagInfo.ts +10 -10
- package/src/metadata/IMetadata.ts +25 -25
- package/src/metadata/IMetadataApplication.ts +7 -7
- package/src/metadata/IMetadataConstant.ts +16 -16
- package/src/metadata/IMetadataEntry.ts +6 -6
- package/src/metadata/IMetadataObject.ts +29 -29
- package/src/metadata/IMetadataProperty.ts +11 -11
- package/src/metadata/MetadataConstant.ts +3 -3
- package/src/metadata/MetadataObject.ts +131 -131
- package/src/metadata/MetadataProperty.ts +64 -64
- package/src/programmers/ApplicationProgrammer.ts +55 -55
- package/src/programmers/AssertProgrammer.ts +36 -29
- package/src/programmers/IsProgrammer.ts +5 -0
- package/src/programmers/ValidateProgrammer.ts +36 -29
- package/src/programmers/helpers/AtomicPredicator.ts +15 -15
- package/src/programmers/helpers/FunctionImporeter.ts +31 -31
- package/src/programmers/helpers/IExpressionEntry.ts +10 -10
- package/src/programmers/helpers/OptionPredicator.ts +4 -0
- package/src/programmers/helpers/StringifyJoinder.ts +111 -111
- package/src/programmers/helpers/StringifyPredicator.ts +18 -18
- package/src/programmers/helpers/UnionPredicator.ts +81 -81
- package/src/programmers/internal/application_array.ts +47 -47
- package/src/programmers/internal/application_boolean.ts +17 -17
- package/src/programmers/internal/application_constant.ts +29 -29
- package/src/programmers/internal/application_default_string.ts +32 -32
- package/src/programmers/internal/application_native.ts +29 -29
- package/src/programmers/internal/application_number.ts +76 -76
- package/src/programmers/internal/application_schema.ts +9 -6
- package/src/programmers/internal/application_string.ts +49 -49
- package/src/programmers/internal/application_templates.ts +27 -27
- package/src/programmers/internal/application_tuple.ts +29 -29
- package/src/programmers/internal/check_dynamic_properties.ts +164 -146
- package/src/programmers/internal/check_everything.ts +25 -25
- package/src/programmers/internal/check_length.ts +46 -46
- package/src/programmers/internal/check_native.ts +9 -9
- package/src/programmers/internal/check_object.ts +43 -42
- package/src/programmers/internal/check_string.ts +24 -24
- package/src/programmers/internal/check_string_tags.ts +63 -63
- package/src/programmers/internal/check_template.ts +50 -50
- package/src/programmers/internal/decode_union_object.ts +73 -73
- package/src/programmers/internal/feature_object_entries.ts +49 -49
- package/src/programmers/internal/metadata_to_pattern.ts +31 -31
- package/src/programmers/internal/stringify_dynamic_properties.ts +164 -164
- package/src/programmers/internal/stringify_native.ts +8 -8
- package/src/programmers/internal/stringify_regular_properties.ts +81 -81
- package/src/programmers/internal/template_to_pattern.ts +15 -15
- package/src/schemas/IJsonApplication.ts +9 -9
- package/src/schemas/IJsonComponents.ts +26 -26
- package/src/transform.ts +20 -20
- package/src/transformers/ExpressionWithArgumentTransformer.ts +66 -66
- package/src/transformers/FileTransformer.ts +49 -49
- package/src/transformers/IProject.ts +11 -11
- package/src/transformers/ITransformOptions.ts +11 -0
- package/src/transformers/NodeTransformer.ts +19 -19
- package/src/transformers/features/miscellaneous/MetadataTransformer.ts +55 -55
- package/src/transformers/features/parsers/AssertParseTransformer.ts +36 -36
- package/src/transformers/features/parsers/CreateAssertParseTransformer.ts +32 -32
- package/src/transformers/features/parsers/CreateIsParseTransformer.ts +32 -32
- package/src/transformers/features/parsers/CreateValidateParseTransformer.ts +32 -32
- package/src/transformers/features/parsers/IsParseTransformer.ts +36 -36
- package/src/transformers/features/parsers/ValidateParseTransformer.ts +36 -36
- package/src/transformers/features/stringifiers/AssertStringifyTransformer.ts +38 -38
- package/src/transformers/features/stringifiers/CreateAssertStringifyTransformer.ts +32 -32
- package/src/transformers/features/stringifiers/CreateIsStringifyTransformer.ts +32 -32
- package/src/transformers/features/stringifiers/CreateStringifyTransformer.ts +31 -31
- package/src/transformers/features/stringifiers/CreateValidateStringifyProgrammer.ts +32 -32
- package/src/transformers/features/stringifiers/IsStringifyTransformer.ts +38 -38
- package/src/transformers/features/stringifiers/ValidateStringifyTransformer.ts +38 -38
- package/src/transformers/features/validators/AssertTransformer.ts +43 -43
- package/src/transformers/features/validators/CreateAssertTransformer.ts +35 -35
- package/src/transformers/features/validators/CreateIsTransformer.ts +35 -35
- package/src/transformers/features/validators/CreateValidateTransformer.ts +35 -35
- package/src/transformers/features/validators/IsTransformer.ts +43 -43
- package/src/transformers/features/validators/ValidateTransformer.ts +43 -43
- package/src/typings/Atomic.ts +17 -17
- package/src/typings/ClassProperties.ts +5 -5
- package/src/typings/OmitNever.ts +3 -3
- package/src/typings/SpecialFields.ts +3 -3
- package/src/typings/Writable.ts +11 -11
- package/src/utils/ArrayUtil.ts +49 -49
- package/src/utils/Escaper.ts +50 -50
- package/src/utils/MapUtil.ts +14 -14
- package/src/utils/PatternUtil.ts +30 -30
- package/src/utils/Singleton.ts +17 -17
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
import { Metadata } from "../../metadata/Metadata";
|
|
2
|
-
import { IJsonSchema } from "../../schemas/IJsonSchema";
|
|
3
|
-
|
|
4
|
-
import { application_default_string } from "./application_default_string";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @internal
|
|
8
|
-
*/
|
|
9
|
-
export const application_string = (
|
|
10
|
-
meta: Metadata,
|
|
11
|
-
attribute: IJsonSchema.IAttribute,
|
|
12
|
-
): IJsonSchema.IString => {
|
|
13
|
-
const output: IJsonSchema.IString = {
|
|
14
|
-
type: "string",
|
|
15
|
-
nullable: meta.nullable,
|
|
16
|
-
...attribute,
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
// FORMAT TAG OF METADATA
|
|
20
|
-
const formatJsdocTag = attribute["x-typia-jsDocTags"]?.find(
|
|
21
|
-
(tag) => tag.name === "format",
|
|
22
|
-
);
|
|
23
|
-
if (formatJsdocTag?.text?.length)
|
|
24
|
-
output.format = formatJsdocTag?.text.map((t) => t.text).join(" ");
|
|
25
|
-
|
|
26
|
-
// REGULAR TAGS COMPATIBLE WITH JSON-SCHEMA
|
|
27
|
-
for (const tag of attribute["x-typia-metaTags"] || []) {
|
|
28
|
-
// RANGE
|
|
29
|
-
if (tag.kind === "minLength") output.minLength = tag.value;
|
|
30
|
-
else if (tag.kind === "maxLength") output.maxLength = tag.value;
|
|
31
|
-
else if (tag.kind === "length") {
|
|
32
|
-
if (tag.minimum !== undefined)
|
|
33
|
-
output.minLength =
|
|
34
|
-
tag.minimum.value + (tag.minimum.include ? 0 : 1);
|
|
35
|
-
if (tag.maximum !== undefined)
|
|
36
|
-
output.maxLength =
|
|
37
|
-
tag.maximum.value - (tag.maximum.include ? 0 : 1);
|
|
38
|
-
}
|
|
39
|
-
// FORMAT AND PATTERN
|
|
40
|
-
else if (tag.kind === "format") output.format = tag.value;
|
|
41
|
-
else if (tag.kind === "pattern") output.pattern = tag.value;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// DEFAULT CONFIGURATION
|
|
45
|
-
output.default = application_default_string(meta, attribute)(output);
|
|
46
|
-
|
|
47
|
-
// RETURNS
|
|
48
|
-
return output;
|
|
49
|
-
};
|
|
1
|
+
import { Metadata } from "../../metadata/Metadata";
|
|
2
|
+
import { IJsonSchema } from "../../schemas/IJsonSchema";
|
|
3
|
+
|
|
4
|
+
import { application_default_string } from "./application_default_string";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
export const application_string = (
|
|
10
|
+
meta: Metadata,
|
|
11
|
+
attribute: IJsonSchema.IAttribute,
|
|
12
|
+
): IJsonSchema.IString => {
|
|
13
|
+
const output: IJsonSchema.IString = {
|
|
14
|
+
type: "string",
|
|
15
|
+
nullable: meta.nullable,
|
|
16
|
+
...attribute,
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
// FORMAT TAG OF METADATA
|
|
20
|
+
const formatJsdocTag = attribute["x-typia-jsDocTags"]?.find(
|
|
21
|
+
(tag) => tag.name === "format",
|
|
22
|
+
);
|
|
23
|
+
if (formatJsdocTag?.text?.length)
|
|
24
|
+
output.format = formatJsdocTag?.text.map((t) => t.text).join(" ");
|
|
25
|
+
|
|
26
|
+
// REGULAR TAGS COMPATIBLE WITH JSON-SCHEMA
|
|
27
|
+
for (const tag of attribute["x-typia-metaTags"] || []) {
|
|
28
|
+
// RANGE
|
|
29
|
+
if (tag.kind === "minLength") output.minLength = tag.value;
|
|
30
|
+
else if (tag.kind === "maxLength") output.maxLength = tag.value;
|
|
31
|
+
else if (tag.kind === "length") {
|
|
32
|
+
if (tag.minimum !== undefined)
|
|
33
|
+
output.minLength =
|
|
34
|
+
tag.minimum.value + (tag.minimum.include ? 0 : 1);
|
|
35
|
+
if (tag.maximum !== undefined)
|
|
36
|
+
output.maxLength =
|
|
37
|
+
tag.maximum.value - (tag.maximum.include ? 0 : 1);
|
|
38
|
+
}
|
|
39
|
+
// FORMAT AND PATTERN
|
|
40
|
+
else if (tag.kind === "format") output.format = tag.value;
|
|
41
|
+
else if (tag.kind === "pattern") output.pattern = tag.value;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// DEFAULT CONFIGURATION
|
|
45
|
+
output.default = application_default_string(meta, attribute)(output);
|
|
46
|
+
|
|
47
|
+
// RETURNS
|
|
48
|
+
return output;
|
|
49
|
+
};
|
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
import { Metadata } from "../../metadata/Metadata";
|
|
2
|
-
import { IJsonSchema } from "../../schemas/IJsonSchema";
|
|
3
|
-
|
|
4
|
-
import { application_default_string } from "./application_default_string";
|
|
5
|
-
import { metadata_to_pattern } from "./metadata_to_pattern";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* @internal
|
|
9
|
-
*/
|
|
10
|
-
export const application_templates = (
|
|
11
|
-
meta: Metadata,
|
|
12
|
-
attribute: IJsonSchema.IAttribute,
|
|
13
|
-
): IJsonSchema.IString => {
|
|
14
|
-
// CONSTRUCT PATTERN
|
|
15
|
-
const output: IJsonSchema.IString = {
|
|
16
|
-
type: "string",
|
|
17
|
-
nullable: meta.nullable,
|
|
18
|
-
...attribute,
|
|
19
|
-
};
|
|
20
|
-
output.pattern = metadata_to_pattern(true)(meta);
|
|
21
|
-
|
|
22
|
-
// DEFAULT VALUE
|
|
23
|
-
output.default = application_default_string(meta, attribute)(output);
|
|
24
|
-
|
|
25
|
-
// RETURNS
|
|
26
|
-
return output;
|
|
27
|
-
};
|
|
1
|
+
import { Metadata } from "../../metadata/Metadata";
|
|
2
|
+
import { IJsonSchema } from "../../schemas/IJsonSchema";
|
|
3
|
+
|
|
4
|
+
import { application_default_string } from "./application_default_string";
|
|
5
|
+
import { metadata_to_pattern } from "./metadata_to_pattern";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export const application_templates = (
|
|
11
|
+
meta: Metadata,
|
|
12
|
+
attribute: IJsonSchema.IAttribute,
|
|
13
|
+
): IJsonSchema.IString => {
|
|
14
|
+
// CONSTRUCT PATTERN
|
|
15
|
+
const output: IJsonSchema.IString = {
|
|
16
|
+
type: "string",
|
|
17
|
+
nullable: meta.nullable,
|
|
18
|
+
...attribute,
|
|
19
|
+
};
|
|
20
|
+
output.pattern = metadata_to_pattern(true)(meta);
|
|
21
|
+
|
|
22
|
+
// DEFAULT VALUE
|
|
23
|
+
output.default = application_default_string(meta, attribute)(output);
|
|
24
|
+
|
|
25
|
+
// RETURNS
|
|
26
|
+
return output;
|
|
27
|
+
};
|
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
import { Metadata } from "../../metadata/Metadata";
|
|
2
|
-
import { IJsonComponents } from "../../schemas/IJsonComponents";
|
|
3
|
-
import { IJsonSchema } from "../../schemas/IJsonSchema";
|
|
4
|
-
|
|
5
|
-
import { ApplicationProgrammer } from "../ApplicationProgrammer";
|
|
6
|
-
import { application_schema } from "./application_schema";
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* @internal
|
|
10
|
-
*/
|
|
11
|
-
export const application_tuple =
|
|
12
|
-
(options: ApplicationProgrammer.IOptions) =>
|
|
13
|
-
(components: IJsonComponents) =>
|
|
14
|
-
(
|
|
15
|
-
items: Array<Metadata>,
|
|
16
|
-
nullable: boolean,
|
|
17
|
-
attribute: IJsonSchema.IAttribute,
|
|
18
|
-
): IJsonSchema.ITuple => ({
|
|
19
|
-
type: "array",
|
|
20
|
-
items: items.map((meta, i) =>
|
|
21
|
-
application_schema(options)(components)(false)(meta.rest ?? meta, {
|
|
22
|
-
...attribute,
|
|
23
|
-
"x-typia-rest":
|
|
24
|
-
i === items.length - 1 ? meta.rest !== null : undefined,
|
|
25
|
-
}),
|
|
26
|
-
),
|
|
27
|
-
nullable,
|
|
28
|
-
...attribute,
|
|
29
|
-
});
|
|
1
|
+
import { Metadata } from "../../metadata/Metadata";
|
|
2
|
+
import { IJsonComponents } from "../../schemas/IJsonComponents";
|
|
3
|
+
import { IJsonSchema } from "../../schemas/IJsonSchema";
|
|
4
|
+
|
|
5
|
+
import { ApplicationProgrammer } from "../ApplicationProgrammer";
|
|
6
|
+
import { application_schema } from "./application_schema";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
export const application_tuple =
|
|
12
|
+
(options: ApplicationProgrammer.IOptions) =>
|
|
13
|
+
(components: IJsonComponents) =>
|
|
14
|
+
(
|
|
15
|
+
items: Array<Metadata>,
|
|
16
|
+
nullable: boolean,
|
|
17
|
+
attribute: IJsonSchema.IAttribute,
|
|
18
|
+
): IJsonSchema.ITuple => ({
|
|
19
|
+
type: "array",
|
|
20
|
+
items: items.map((meta, i) =>
|
|
21
|
+
application_schema(options)(components)(false)(meta.rest ?? meta, {
|
|
22
|
+
...attribute,
|
|
23
|
+
"x-typia-rest":
|
|
24
|
+
i === items.length - 1 ? meta.rest !== null : undefined,
|
|
25
|
+
}),
|
|
26
|
+
),
|
|
27
|
+
nullable,
|
|
28
|
+
...attribute,
|
|
29
|
+
});
|
|
@@ -1,146 +1,164 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { IdentifierFactory } from "../../factories/IdentifierFactory";
|
|
4
|
-
import { StatementFactory } from "../../factories/StatementFactory";
|
|
5
|
-
|
|
6
|
-
import { IExpressionEntry } from "../helpers/IExpressionEntry";
|
|
7
|
-
import { check_everything } from "./check_everything";
|
|
8
|
-
import { check_object } from "./check_object";
|
|
9
|
-
import { metadata_to_pattern } from "./metadata_to_pattern";
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* @internal
|
|
13
|
-
*/
|
|
14
|
-
export const check_dynamic_properties =
|
|
15
|
-
(props: check_object.IProps) =>
|
|
16
|
-
(
|
|
17
|
-
regular: IExpressionEntry[],
|
|
18
|
-
dynamic: IExpressionEntry[],
|
|
19
|
-
): ts.Expression => {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { IdentifierFactory } from "../../factories/IdentifierFactory";
|
|
4
|
+
import { StatementFactory } from "../../factories/StatementFactory";
|
|
5
|
+
|
|
6
|
+
import { IExpressionEntry } from "../helpers/IExpressionEntry";
|
|
7
|
+
import { check_everything } from "./check_everything";
|
|
8
|
+
import { check_object } from "./check_object";
|
|
9
|
+
import { metadata_to_pattern } from "./metadata_to_pattern";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @internal
|
|
13
|
+
*/
|
|
14
|
+
export const check_dynamic_properties =
|
|
15
|
+
(props: check_object.IProps) =>
|
|
16
|
+
(
|
|
17
|
+
regular: IExpressionEntry[],
|
|
18
|
+
dynamic: IExpressionEntry[],
|
|
19
|
+
): ts.Expression => {
|
|
20
|
+
if (
|
|
21
|
+
props.equals === true &&
|
|
22
|
+
props.undefined === false &&
|
|
23
|
+
regular.every((r) => r.meta.required) &&
|
|
24
|
+
dynamic.length === 0
|
|
25
|
+
)
|
|
26
|
+
return ts.factory.createStrictEquality(
|
|
27
|
+
ts.factory.createNumericLiteral(regular.length),
|
|
28
|
+
IdentifierFactory.join(
|
|
29
|
+
ts.factory.createCallExpression(
|
|
30
|
+
ts.factory.createIdentifier("Object.keys"),
|
|
31
|
+
undefined,
|
|
32
|
+
[ts.factory.createIdentifier("input")],
|
|
33
|
+
),
|
|
34
|
+
"length",
|
|
35
|
+
),
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
const criteria = props.entries
|
|
39
|
+
? ts.factory.createCallExpression(props.entries, undefined, [
|
|
40
|
+
ts.factory.createCallExpression(
|
|
41
|
+
ts.factory.createIdentifier("Object.keys"),
|
|
42
|
+
undefined,
|
|
43
|
+
[ts.factory.createIdentifier("input")],
|
|
44
|
+
),
|
|
45
|
+
check_dynamic_property(props)(regular, dynamic),
|
|
46
|
+
])
|
|
47
|
+
: ts.factory.createCallExpression(
|
|
48
|
+
IdentifierFactory.join(
|
|
49
|
+
ts.factory.createCallExpression(
|
|
50
|
+
ts.factory.createIdentifier("Object.keys"),
|
|
51
|
+
undefined,
|
|
52
|
+
[ts.factory.createIdentifier("input")],
|
|
53
|
+
),
|
|
54
|
+
props.assert ? "every" : "map",
|
|
55
|
+
),
|
|
56
|
+
undefined,
|
|
57
|
+
[check_dynamic_property(props)(regular, dynamic)],
|
|
58
|
+
);
|
|
59
|
+
return (props.halt || ((elem) => elem))(
|
|
60
|
+
props.assert ? criteria : check_everything(criteria),
|
|
61
|
+
);
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const check_dynamic_property =
|
|
65
|
+
(props: check_object.IProps) =>
|
|
66
|
+
(regular: IExpressionEntry[], dynamic: IExpressionEntry[]) => {
|
|
67
|
+
//----
|
|
68
|
+
// IF CONDITIONS
|
|
69
|
+
//----
|
|
70
|
+
// PREPARE ASSETS
|
|
71
|
+
const key = ts.factory.createIdentifier("key");
|
|
72
|
+
const value = ts.factory.createIdentifier("value");
|
|
73
|
+
|
|
74
|
+
const statements: ts.Statement[] = [];
|
|
75
|
+
const add = (exp: ts.Expression, output: ts.Expression) =>
|
|
76
|
+
statements.push(
|
|
77
|
+
ts.factory.createIfStatement(
|
|
78
|
+
exp,
|
|
79
|
+
ts.factory.createReturnStatement(output),
|
|
80
|
+
),
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
// GATHER CONDITIONS
|
|
84
|
+
if (props.equals === true && regular.length)
|
|
85
|
+
add(is_regular_property(regular), props.positive);
|
|
86
|
+
statements.push(
|
|
87
|
+
StatementFactory.constant(
|
|
88
|
+
"value",
|
|
89
|
+
ts.factory.createIdentifier("input[key]"),
|
|
90
|
+
),
|
|
91
|
+
);
|
|
92
|
+
add(
|
|
93
|
+
ts.factory.createStrictEquality(
|
|
94
|
+
ts.factory.createIdentifier("undefined"),
|
|
95
|
+
value,
|
|
96
|
+
),
|
|
97
|
+
props.positive,
|
|
98
|
+
);
|
|
99
|
+
for (const entry of dynamic)
|
|
100
|
+
add(
|
|
101
|
+
ts.factory.createCallExpression(
|
|
102
|
+
ts.factory.createIdentifier(
|
|
103
|
+
`RegExp(/${metadata_to_pattern(true)(
|
|
104
|
+
entry.key,
|
|
105
|
+
)}/).test`,
|
|
106
|
+
),
|
|
107
|
+
undefined,
|
|
108
|
+
[key],
|
|
109
|
+
),
|
|
110
|
+
entry.expression,
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
//----
|
|
114
|
+
// FUNCTION BODY
|
|
115
|
+
//----
|
|
116
|
+
// CLOSURE BLOCK
|
|
117
|
+
const block: ts.Block = ts.factory.createBlock(
|
|
118
|
+
[
|
|
119
|
+
...statements,
|
|
120
|
+
ts.factory.createReturnStatement(
|
|
121
|
+
props.equals === true
|
|
122
|
+
? props.superfluous(value)
|
|
123
|
+
: props.positive,
|
|
124
|
+
),
|
|
125
|
+
],
|
|
126
|
+
true,
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
// RETURNS
|
|
130
|
+
return ts.factory.createArrowFunction(
|
|
131
|
+
undefined,
|
|
132
|
+
undefined,
|
|
133
|
+
[IdentifierFactory.parameter("key")],
|
|
134
|
+
undefined,
|
|
135
|
+
undefined,
|
|
136
|
+
block,
|
|
137
|
+
);
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
const is_regular_property = (regular: IExpressionEntry[]) =>
|
|
141
|
+
ts.factory.createCallExpression(
|
|
142
|
+
IdentifierFactory.join(
|
|
143
|
+
ts.factory.createArrayLiteralExpression(
|
|
144
|
+
regular.map((entry) =>
|
|
145
|
+
ts.factory.createStringLiteral(entry.key.getSoleLiteral()!),
|
|
146
|
+
),
|
|
147
|
+
),
|
|
148
|
+
"some",
|
|
149
|
+
),
|
|
150
|
+
undefined,
|
|
151
|
+
[
|
|
152
|
+
ts.factory.createArrowFunction(
|
|
153
|
+
undefined,
|
|
154
|
+
undefined,
|
|
155
|
+
[IdentifierFactory.parameter("prop")],
|
|
156
|
+
undefined,
|
|
157
|
+
undefined,
|
|
158
|
+
ts.factory.createStrictEquality(
|
|
159
|
+
ts.factory.createIdentifier("key"),
|
|
160
|
+
ts.factory.createIdentifier("prop"),
|
|
161
|
+
),
|
|
162
|
+
),
|
|
163
|
+
],
|
|
164
|
+
);
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { IdentifierFactory } from "../../factories/IdentifierFactory";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @internal
|
|
7
|
-
*/
|
|
8
|
-
export const check_everything = (array: ts.Expression) =>
|
|
9
|
-
ts.factory.createCallExpression(
|
|
10
|
-
IdentifierFactory.join(array, "every"),
|
|
11
|
-
undefined,
|
|
12
|
-
[
|
|
13
|
-
ts.factory.createArrowFunction(
|
|
14
|
-
undefined,
|
|
15
|
-
undefined,
|
|
16
|
-
[IdentifierFactory.parameter("flag")],
|
|
17
|
-
undefined,
|
|
18
|
-
undefined,
|
|
19
|
-
ts.factory.createStrictEquality(
|
|
20
|
-
ts.factory.createTrue(),
|
|
21
|
-
ts.factory.createIdentifier("flag"),
|
|
22
|
-
),
|
|
23
|
-
),
|
|
24
|
-
],
|
|
25
|
-
);
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { IdentifierFactory } from "../../factories/IdentifierFactory";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
export const check_everything = (array: ts.Expression) =>
|
|
9
|
+
ts.factory.createCallExpression(
|
|
10
|
+
IdentifierFactory.join(array, "every"),
|
|
11
|
+
undefined,
|
|
12
|
+
[
|
|
13
|
+
ts.factory.createArrowFunction(
|
|
14
|
+
undefined,
|
|
15
|
+
undefined,
|
|
16
|
+
[IdentifierFactory.parameter("flag")],
|
|
17
|
+
undefined,
|
|
18
|
+
undefined,
|
|
19
|
+
ts.factory.createStrictEquality(
|
|
20
|
+
ts.factory.createTrue(),
|
|
21
|
+
ts.factory.createIdentifier("flag"),
|
|
22
|
+
),
|
|
23
|
+
),
|
|
24
|
+
],
|
|
25
|
+
);
|