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.
Files changed (127) hide show
  1. package/README.md +57 -23
  2. package/lib/programmers/AssertProgrammer.js +79 -70
  3. package/lib/programmers/AssertProgrammer.js.map +1 -1
  4. package/lib/programmers/IsProgrammer.d.ts +1 -0
  5. package/lib/programmers/IsProgrammer.js +4 -0
  6. package/lib/programmers/IsProgrammer.js.map +1 -1
  7. package/lib/programmers/ValidateProgrammer.js +68 -59
  8. package/lib/programmers/ValidateProgrammer.js.map +1 -1
  9. package/lib/programmers/helpers/OptionPredicator.d.ts +1 -0
  10. package/lib/programmers/helpers/OptionPredicator.js +4 -0
  11. package/lib/programmers/helpers/OptionPredicator.js.map +1 -1
  12. package/lib/programmers/internal/application_schema.js +23 -21
  13. package/lib/programmers/internal/application_schema.js.map +1 -1
  14. package/lib/programmers/internal/check_dynamic_properties.js +5 -0
  15. package/lib/programmers/internal/check_dynamic_properties.js.map +1 -1
  16. package/lib/programmers/internal/check_object.d.ts +1 -0
  17. package/lib/programmers/internal/check_object.js.map +1 -1
  18. package/lib/transformers/ITransformOptions.d.ts +10 -0
  19. package/package.json +2 -2
  20. package/src/IValidation.ts +21 -21
  21. package/src/Primitive.ts +82 -82
  22. package/src/TypeGuardError.ts +36 -36
  23. package/src/executable/internal/CommandParser.ts +15 -15
  24. package/src/factories/CommentFactory.ts +10 -10
  25. package/src/factories/ExpressionFactory.ts +66 -66
  26. package/src/factories/IdentifierFactory.ts +72 -72
  27. package/src/factories/LiteralFactory.ts +44 -44
  28. package/src/factories/StatementFactory.ts +60 -60
  29. package/src/factories/TemplateFactory.ts +56 -56
  30. package/src/factories/TypeFactory.ts +101 -101
  31. package/src/factories/ValueFactory.ts +12 -12
  32. package/src/functional/$every.ts +11 -11
  33. package/src/functional/$is_email.ts +5 -5
  34. package/src/functional/$is_ipv4.ts +5 -5
  35. package/src/functional/$is_ipv6.ts +5 -5
  36. package/src/functional/$is_url.ts +5 -5
  37. package/src/functional/$is_uuid.ts +5 -5
  38. package/src/functional/$join.ts +50 -50
  39. package/src/functional/$report.ts +15 -15
  40. package/src/functional/$rest.ts +3 -3
  41. package/src/functional/$string.ts +37 -37
  42. package/src/functional/$tail.ts +6 -6
  43. package/src/index.ts +4 -4
  44. package/src/metadata/IJsDocTagInfo.ts +10 -10
  45. package/src/metadata/IMetadata.ts +25 -25
  46. package/src/metadata/IMetadataApplication.ts +7 -7
  47. package/src/metadata/IMetadataConstant.ts +16 -16
  48. package/src/metadata/IMetadataEntry.ts +6 -6
  49. package/src/metadata/IMetadataObject.ts +29 -29
  50. package/src/metadata/IMetadataProperty.ts +11 -11
  51. package/src/metadata/MetadataConstant.ts +3 -3
  52. package/src/metadata/MetadataObject.ts +131 -131
  53. package/src/metadata/MetadataProperty.ts +64 -64
  54. package/src/programmers/ApplicationProgrammer.ts +55 -55
  55. package/src/programmers/AssertProgrammer.ts +36 -29
  56. package/src/programmers/IsProgrammer.ts +5 -0
  57. package/src/programmers/ValidateProgrammer.ts +36 -29
  58. package/src/programmers/helpers/AtomicPredicator.ts +15 -15
  59. package/src/programmers/helpers/FunctionImporeter.ts +31 -31
  60. package/src/programmers/helpers/IExpressionEntry.ts +10 -10
  61. package/src/programmers/helpers/OptionPredicator.ts +4 -0
  62. package/src/programmers/helpers/StringifyJoinder.ts +111 -111
  63. package/src/programmers/helpers/StringifyPredicator.ts +18 -18
  64. package/src/programmers/helpers/UnionPredicator.ts +81 -81
  65. package/src/programmers/internal/application_array.ts +47 -47
  66. package/src/programmers/internal/application_boolean.ts +17 -17
  67. package/src/programmers/internal/application_constant.ts +29 -29
  68. package/src/programmers/internal/application_default_string.ts +32 -32
  69. package/src/programmers/internal/application_native.ts +29 -29
  70. package/src/programmers/internal/application_number.ts +76 -76
  71. package/src/programmers/internal/application_schema.ts +9 -6
  72. package/src/programmers/internal/application_string.ts +49 -49
  73. package/src/programmers/internal/application_templates.ts +27 -27
  74. package/src/programmers/internal/application_tuple.ts +29 -29
  75. package/src/programmers/internal/check_dynamic_properties.ts +164 -146
  76. package/src/programmers/internal/check_everything.ts +25 -25
  77. package/src/programmers/internal/check_length.ts +46 -46
  78. package/src/programmers/internal/check_native.ts +9 -9
  79. package/src/programmers/internal/check_object.ts +43 -42
  80. package/src/programmers/internal/check_string.ts +24 -24
  81. package/src/programmers/internal/check_string_tags.ts +63 -63
  82. package/src/programmers/internal/check_template.ts +50 -50
  83. package/src/programmers/internal/decode_union_object.ts +73 -73
  84. package/src/programmers/internal/feature_object_entries.ts +49 -49
  85. package/src/programmers/internal/metadata_to_pattern.ts +31 -31
  86. package/src/programmers/internal/stringify_dynamic_properties.ts +164 -164
  87. package/src/programmers/internal/stringify_native.ts +8 -8
  88. package/src/programmers/internal/stringify_regular_properties.ts +81 -81
  89. package/src/programmers/internal/template_to_pattern.ts +15 -15
  90. package/src/schemas/IJsonApplication.ts +9 -9
  91. package/src/schemas/IJsonComponents.ts +26 -26
  92. package/src/transform.ts +20 -20
  93. package/src/transformers/ExpressionWithArgumentTransformer.ts +66 -66
  94. package/src/transformers/FileTransformer.ts +49 -49
  95. package/src/transformers/IProject.ts +11 -11
  96. package/src/transformers/ITransformOptions.ts +11 -0
  97. package/src/transformers/NodeTransformer.ts +19 -19
  98. package/src/transformers/features/miscellaneous/MetadataTransformer.ts +55 -55
  99. package/src/transformers/features/parsers/AssertParseTransformer.ts +36 -36
  100. package/src/transformers/features/parsers/CreateAssertParseTransformer.ts +32 -32
  101. package/src/transformers/features/parsers/CreateIsParseTransformer.ts +32 -32
  102. package/src/transformers/features/parsers/CreateValidateParseTransformer.ts +32 -32
  103. package/src/transformers/features/parsers/IsParseTransformer.ts +36 -36
  104. package/src/transformers/features/parsers/ValidateParseTransformer.ts +36 -36
  105. package/src/transformers/features/stringifiers/AssertStringifyTransformer.ts +38 -38
  106. package/src/transformers/features/stringifiers/CreateAssertStringifyTransformer.ts +32 -32
  107. package/src/transformers/features/stringifiers/CreateIsStringifyTransformer.ts +32 -32
  108. package/src/transformers/features/stringifiers/CreateStringifyTransformer.ts +31 -31
  109. package/src/transformers/features/stringifiers/CreateValidateStringifyProgrammer.ts +32 -32
  110. package/src/transformers/features/stringifiers/IsStringifyTransformer.ts +38 -38
  111. package/src/transformers/features/stringifiers/ValidateStringifyTransformer.ts +38 -38
  112. package/src/transformers/features/validators/AssertTransformer.ts +43 -43
  113. package/src/transformers/features/validators/CreateAssertTransformer.ts +35 -35
  114. package/src/transformers/features/validators/CreateIsTransformer.ts +35 -35
  115. package/src/transformers/features/validators/CreateValidateTransformer.ts +35 -35
  116. package/src/transformers/features/validators/IsTransformer.ts +43 -43
  117. package/src/transformers/features/validators/ValidateTransformer.ts +43 -43
  118. package/src/typings/Atomic.ts +17 -17
  119. package/src/typings/ClassProperties.ts +5 -5
  120. package/src/typings/OmitNever.ts +3 -3
  121. package/src/typings/SpecialFields.ts +3 -3
  122. package/src/typings/Writable.ts +11 -11
  123. package/src/utils/ArrayUtil.ts +49 -49
  124. package/src/utils/Escaper.ts +50 -50
  125. package/src/utils/MapUtil.ts +14 -14
  126. package/src/utils/PatternUtil.ts +30 -30
  127. package/src/utils/Singleton.ts +17 -17
@@ -1,46 +1,46 @@
1
- import ts from "typescript";
2
-
3
- import { IMetadataTag } from "../../metadata/IMetadataTag";
4
-
5
- /**
6
- * @internal
7
- */
8
- export function check_length(
9
- conditions: ts.Expression[],
10
- length: ts.Expression,
11
- tag: Omit<IMetadataTag.ILength, "kind">,
12
- ) {
13
- if (
14
- tag.minimum !== undefined &&
15
- tag.maximum !== undefined &&
16
- tag.minimum.value === tag.maximum.value &&
17
- tag.minimum.include === true &&
18
- tag.maximum.include === true
19
- ) {
20
- conditions.push(
21
- ts.factory.createStrictEquality(
22
- ts.factory.createNumericLiteral(tag.minimum.value),
23
- length,
24
- ),
25
- );
26
- } else {
27
- if (tag.minimum !== undefined)
28
- conditions.push(
29
- (tag.minimum.include
30
- ? ts.factory.createLessThanEquals
31
- : ts.factory.createLessThan)(
32
- ts.factory.createNumericLiteral(tag.minimum.value),
33
- length,
34
- ),
35
- );
36
- if (tag.maximum !== undefined)
37
- conditions.push(
38
- (tag.maximum.include
39
- ? ts.factory.createGreaterThanEquals
40
- : ts.factory.createGreaterThan)(
41
- ts.factory.createNumericLiteral(tag.maximum.value),
42
- length,
43
- ),
44
- );
45
- }
46
- }
1
+ import ts from "typescript";
2
+
3
+ import { IMetadataTag } from "../../metadata/IMetadataTag";
4
+
5
+ /**
6
+ * @internal
7
+ */
8
+ export function check_length(
9
+ conditions: ts.Expression[],
10
+ length: ts.Expression,
11
+ tag: Omit<IMetadataTag.ILength, "kind">,
12
+ ) {
13
+ if (
14
+ tag.minimum !== undefined &&
15
+ tag.maximum !== undefined &&
16
+ tag.minimum.value === tag.maximum.value &&
17
+ tag.minimum.include === true &&
18
+ tag.maximum.include === true
19
+ ) {
20
+ conditions.push(
21
+ ts.factory.createStrictEquality(
22
+ ts.factory.createNumericLiteral(tag.minimum.value),
23
+ length,
24
+ ),
25
+ );
26
+ } else {
27
+ if (tag.minimum !== undefined)
28
+ conditions.push(
29
+ (tag.minimum.include
30
+ ? ts.factory.createLessThanEquals
31
+ : ts.factory.createLessThan)(
32
+ ts.factory.createNumericLiteral(tag.minimum.value),
33
+ length,
34
+ ),
35
+ );
36
+ if (tag.maximum !== undefined)
37
+ conditions.push(
38
+ (tag.maximum.include
39
+ ? ts.factory.createGreaterThanEquals
40
+ : ts.factory.createGreaterThan)(
41
+ ts.factory.createNumericLiteral(tag.maximum.value),
42
+ length,
43
+ ),
44
+ );
45
+ }
46
+ }
@@ -1,9 +1,9 @@
1
- import ts from "typescript";
2
-
3
- import { ExpressionFactory } from "../../factories/ExpressionFactory";
4
-
5
- /**
6
- * @internal
7
- */
8
- export const check_native = (type: string) => (input: ts.Expression) =>
9
- ExpressionFactory.isInstanceOf(input, type);
1
+ import ts from "typescript";
2
+
3
+ import { ExpressionFactory } from "../../factories/ExpressionFactory";
4
+
5
+ /**
6
+ * @internal
7
+ */
8
+ export const check_native = (type: string) => (input: ts.Expression) =>
9
+ ExpressionFactory.isInstanceOf(input, type);
@@ -1,42 +1,43 @@
1
- import ts from "typescript";
2
-
3
- import { IExpressionEntry } from "../helpers/IExpressionEntry";
4
- import { check_dynamic_properties } from "./check_dynamic_properties";
5
- import { check_everything } from "./check_everything";
6
-
7
- /**
8
- * @internal
9
- */
10
- export const check_object =
11
- (props: check_object.IProps) => (entries: IExpressionEntry[]) => {
12
- // PREPARE ASSETS
13
- const regular = entries.filter((entry) => entry.key.isSoleLiteral());
14
- const dynamic = entries.filter((entry) => !entry.key.isSoleLiteral());
15
- const flags: ts.Expression[] = regular.map((entry) => entry.expression);
16
-
17
- // REGULAR WITHOUT DYNAMIC PROPERTIES
18
- if (props.equals === false && dynamic.length === 0)
19
- return regular.length === 0 ? props.positive : reduce(props)(flags);
20
-
21
- // CHECK DYNAMIC PROPERTIES
22
- flags.push(check_dynamic_properties(props)(regular, dynamic));
23
- return reduce(props)(flags);
24
- };
25
- export namespace check_object {
26
- export interface IProps {
27
- equals: boolean;
28
- assert: boolean;
29
- halt?: (exp: ts.Expression) => ts.Expression;
30
- reduce: (a: ts.Expression, b: ts.Expression) => ts.Expression;
31
- positive: ts.Expression;
32
- superfluous: (value: ts.Expression) => ts.Expression;
33
- entries?: ts.Identifier;
34
- }
35
- }
36
-
37
- const reduce = (props: check_object.IProps) => (expressions: ts.Expression[]) =>
38
- props.assert
39
- ? expressions.reduce(props.reduce)
40
- : check_everything(
41
- ts.factory.createArrayLiteralExpression(expressions),
42
- );
1
+ import ts from "typescript";
2
+
3
+ import { IExpressionEntry } from "../helpers/IExpressionEntry";
4
+ import { check_dynamic_properties } from "./check_dynamic_properties";
5
+ import { check_everything } from "./check_everything";
6
+
7
+ /**
8
+ * @internal
9
+ */
10
+ export const check_object =
11
+ (props: check_object.IProps) => (entries: IExpressionEntry[]) => {
12
+ // PREPARE ASSETS
13
+ const regular = entries.filter((entry) => entry.key.isSoleLiteral());
14
+ const dynamic = entries.filter((entry) => !entry.key.isSoleLiteral());
15
+ const flags: ts.Expression[] = regular.map((entry) => entry.expression);
16
+
17
+ // REGULAR WITHOUT DYNAMIC PROPERTIES
18
+ if (props.equals === false && dynamic.length === 0)
19
+ return regular.length === 0 ? props.positive : reduce(props)(flags);
20
+
21
+ // CHECK DYNAMIC PROPERTIES
22
+ flags.push(check_dynamic_properties(props)(regular, dynamic));
23
+ return reduce(props)(flags);
24
+ };
25
+ export namespace check_object {
26
+ export interface IProps {
27
+ equals: boolean;
28
+ assert: boolean;
29
+ undefined: boolean;
30
+ halt?: (exp: ts.Expression) => ts.Expression;
31
+ reduce: (a: ts.Expression, b: ts.Expression) => ts.Expression;
32
+ positive: ts.Expression;
33
+ superfluous: (value: ts.Expression) => ts.Expression;
34
+ entries?: ts.Identifier;
35
+ }
36
+ }
37
+
38
+ const reduce = (props: check_object.IProps) => (expressions: ts.Expression[]) =>
39
+ props.assert
40
+ ? expressions.reduce(props.reduce)
41
+ : check_everything(
42
+ ts.factory.createArrayLiteralExpression(expressions),
43
+ );
@@ -1,24 +1,24 @@
1
- import ts from "typescript";
2
-
3
- import { IMetadataTag } from "../../metadata/IMetadataTag";
4
-
5
- import { FunctionImporter } from "../helpers/FunctionImporeter";
6
- import { check_string_tags } from "./check_string_tags";
7
-
8
- /**
9
- * @internal
10
- */
11
- export function check_string(importer: FunctionImporter) {
12
- return function (input: ts.Expression, tagList: IMetadataTag[]) {
13
- const conditions: ts.Expression[] = [
14
- ts.factory.createStrictEquality(
15
- ts.factory.createStringLiteral("string"),
16
- ts.factory.createTypeOfExpression(input),
17
- ),
18
- ...check_string_tags(importer)(input, tagList),
19
- ];
20
- return conditions.length === 1
21
- ? conditions[0]!
22
- : conditions.reduce((x, y) => ts.factory.createLogicalAnd(x, y));
23
- };
24
- }
1
+ import ts from "typescript";
2
+
3
+ import { IMetadataTag } from "../../metadata/IMetadataTag";
4
+
5
+ import { FunctionImporter } from "../helpers/FunctionImporeter";
6
+ import { check_string_tags } from "./check_string_tags";
7
+
8
+ /**
9
+ * @internal
10
+ */
11
+ export function check_string(importer: FunctionImporter) {
12
+ return function (input: ts.Expression, tagList: IMetadataTag[]) {
13
+ const conditions: ts.Expression[] = [
14
+ ts.factory.createStrictEquality(
15
+ ts.factory.createStringLiteral("string"),
16
+ ts.factory.createTypeOfExpression(input),
17
+ ),
18
+ ...check_string_tags(importer)(input, tagList),
19
+ ];
20
+ return conditions.length === 1
21
+ ? conditions[0]!
22
+ : conditions.reduce((x, y) => ts.factory.createLogicalAnd(x, y));
23
+ };
24
+ }
@@ -1,63 +1,63 @@
1
- import ts from "typescript";
2
-
3
- import { IdentifierFactory } from "../../factories/IdentifierFactory";
4
-
5
- import { IMetadataTag } from "../../metadata/IMetadataTag";
6
-
7
- import { FunctionImporter } from "../helpers/FunctionImporeter";
8
- import { check_length } from "./check_length";
9
-
10
- /**
11
- * @internal
12
- */
13
- export const check_string_tags =
14
- (importer: FunctionImporter) =>
15
- (input: ts.Expression, tagList: IMetadataTag[]) => {
16
- const conditions: ts.Expression[] = [];
17
- for (const tag of tagList)
18
- if (tag.kind === "format")
19
- conditions.push(
20
- ts.factory.createStrictEquality(
21
- ts.factory.createTrue(),
22
- ts.factory.createCallExpression(
23
- importer.use(`is_${tag.value}`),
24
- undefined,
25
- [input],
26
- ),
27
- ),
28
- );
29
- else if (tag.kind === "pattern")
30
- conditions.push(
31
- ts.factory.createStrictEquality(
32
- ts.factory.createTrue(),
33
- ts.factory.createCallExpression(
34
- ts.factory.createIdentifier(
35
- `RegExp(/${tag.value}/).test`,
36
- ),
37
- undefined,
38
- [input],
39
- ),
40
- ),
41
- );
42
- else if (tag.kind === "minLength")
43
- conditions.push(
44
- ts.factory.createLessThanEquals(
45
- ts.factory.createNumericLiteral(tag.value),
46
- IdentifierFactory.join(input, "length"),
47
- ),
48
- );
49
- else if (tag.kind === "maxLength")
50
- conditions.push(
51
- ts.factory.createGreaterThanEquals(
52
- ts.factory.createNumericLiteral(tag.value),
53
- IdentifierFactory.join(input, "length"),
54
- ),
55
- );
56
- else if (tag.kind === "length")
57
- check_length(
58
- conditions,
59
- IdentifierFactory.join(input, "length"),
60
- tag,
61
- );
62
- return conditions;
63
- };
1
+ import ts from "typescript";
2
+
3
+ import { IdentifierFactory } from "../../factories/IdentifierFactory";
4
+
5
+ import { IMetadataTag } from "../../metadata/IMetadataTag";
6
+
7
+ import { FunctionImporter } from "../helpers/FunctionImporeter";
8
+ import { check_length } from "./check_length";
9
+
10
+ /**
11
+ * @internal
12
+ */
13
+ export const check_string_tags =
14
+ (importer: FunctionImporter) =>
15
+ (input: ts.Expression, tagList: IMetadataTag[]) => {
16
+ const conditions: ts.Expression[] = [];
17
+ for (const tag of tagList)
18
+ if (tag.kind === "format")
19
+ conditions.push(
20
+ ts.factory.createStrictEquality(
21
+ ts.factory.createTrue(),
22
+ ts.factory.createCallExpression(
23
+ importer.use(`is_${tag.value}`),
24
+ undefined,
25
+ [input],
26
+ ),
27
+ ),
28
+ );
29
+ else if (tag.kind === "pattern")
30
+ conditions.push(
31
+ ts.factory.createStrictEquality(
32
+ ts.factory.createTrue(),
33
+ ts.factory.createCallExpression(
34
+ ts.factory.createIdentifier(
35
+ `RegExp(/${tag.value}/).test`,
36
+ ),
37
+ undefined,
38
+ [input],
39
+ ),
40
+ ),
41
+ );
42
+ else if (tag.kind === "minLength")
43
+ conditions.push(
44
+ ts.factory.createLessThanEquals(
45
+ ts.factory.createNumericLiteral(tag.value),
46
+ IdentifierFactory.join(input, "length"),
47
+ ),
48
+ );
49
+ else if (tag.kind === "maxLength")
50
+ conditions.push(
51
+ ts.factory.createGreaterThanEquals(
52
+ ts.factory.createNumericLiteral(tag.value),
53
+ IdentifierFactory.join(input, "length"),
54
+ ),
55
+ );
56
+ else if (tag.kind === "length")
57
+ check_length(
58
+ conditions,
59
+ IdentifierFactory.join(input, "length"),
60
+ tag,
61
+ );
62
+ return conditions;
63
+ };
@@ -1,50 +1,50 @@
1
- import ts from "typescript";
2
-
3
- import { IMetadataTag } from "../../metadata/IMetadataTag";
4
- import { Metadata } from "../../metadata/Metadata";
5
-
6
- import { FunctionImporter } from "../helpers/FunctionImporeter";
7
- import { check_string_tags } from "./check_string_tags";
8
- import { template_to_pattern } from "./template_to_pattern";
9
-
10
- /**
11
- * @internal
12
- */
13
- export const check_template =
14
- (importer: FunctionImporter) =>
15
- (
16
- input: ts.Expression,
17
- templates: Metadata[][],
18
- tagList: IMetadataTag[],
19
- ) => {
20
- // TYPEOF STRING & TAGS
21
- const conditions: ts.Expression[] = [
22
- ts.factory.createStrictEquality(
23
- ts.factory.createStringLiteral("string"),
24
- ts.factory.createTypeOfExpression(input),
25
- ),
26
- ...check_string_tags(importer)(input, tagList),
27
- ];
28
-
29
- // TEMPLATES
30
- const internal = templates.map((tpl) =>
31
- ts.factory.createStrictEquality(
32
- ts.factory.createTrue(),
33
- ts.factory.createCallExpression(
34
- ts.factory.createIdentifier(
35
- `RegExp(/${template_to_pattern(true)(tpl)}/).test`,
36
- ),
37
- undefined,
38
- [input],
39
- ),
40
- ),
41
- );
42
- conditions.push(
43
- internal.length === 1
44
- ? internal[0]!
45
- : internal.reduce((x, y) => ts.factory.createLogicalOr(x, y)),
46
- );
47
-
48
- // COMBINATION
49
- return conditions.reduce((x, y) => ts.factory.createLogicalAnd(x, y));
50
- };
1
+ import ts from "typescript";
2
+
3
+ import { IMetadataTag } from "../../metadata/IMetadataTag";
4
+ import { Metadata } from "../../metadata/Metadata";
5
+
6
+ import { FunctionImporter } from "../helpers/FunctionImporeter";
7
+ import { check_string_tags } from "./check_string_tags";
8
+ import { template_to_pattern } from "./template_to_pattern";
9
+
10
+ /**
11
+ * @internal
12
+ */
13
+ export const check_template =
14
+ (importer: FunctionImporter) =>
15
+ (
16
+ input: ts.Expression,
17
+ templates: Metadata[][],
18
+ tagList: IMetadataTag[],
19
+ ) => {
20
+ // TYPEOF STRING & TAGS
21
+ const conditions: ts.Expression[] = [
22
+ ts.factory.createStrictEquality(
23
+ ts.factory.createStringLiteral("string"),
24
+ ts.factory.createTypeOfExpression(input),
25
+ ),
26
+ ...check_string_tags(importer)(input, tagList),
27
+ ];
28
+
29
+ // TEMPLATES
30
+ const internal = templates.map((tpl) =>
31
+ ts.factory.createStrictEquality(
32
+ ts.factory.createTrue(),
33
+ ts.factory.createCallExpression(
34
+ ts.factory.createIdentifier(
35
+ `RegExp(/${template_to_pattern(true)(tpl)}/).test`,
36
+ ),
37
+ undefined,
38
+ [input],
39
+ ),
40
+ ),
41
+ );
42
+ conditions.push(
43
+ internal.length === 1
44
+ ? internal[0]!
45
+ : internal.reduce((x, y) => ts.factory.createLogicalOr(x, y)),
46
+ );
47
+
48
+ // COMBINATION
49
+ return conditions.reduce((x, y) => ts.factory.createLogicalAnd(x, y));
50
+ };
@@ -1,73 +1,73 @@
1
- import ts from "typescript";
2
-
3
- import { MetadataObject } from "../../metadata/MetadataObject";
4
-
5
- import { FeatureProgrammer } from "../FeatureProgrammer";
6
-
7
- /**
8
- * @internal
9
- */
10
- export const decode_union_object =
11
- (
12
- checker: (
13
- input: ts.Expression,
14
- obj: MetadataObject,
15
- explore: FeatureProgrammer.IExplore,
16
- ) => ts.Expression,
17
- ) =>
18
- (
19
- decoder: (
20
- input: ts.Expression,
21
- obj: MetadataObject,
22
- explore: FeatureProgrammer.IExplore,
23
- ) => ts.Expression,
24
- ) =>
25
- (success: (exp: ts.Expression) => ts.Expression) =>
26
- (escaper: (value: ts.Expression, expected: string) => ts.Statement) =>
27
- (
28
- input: ts.Expression,
29
- targets: MetadataObject[],
30
- explore: FeatureProgrammer.IExplore,
31
- ): ts.CallExpression =>
32
- ts.factory.createCallExpression(
33
- ts.factory.createArrowFunction(
34
- undefined,
35
- undefined,
36
- [],
37
- undefined,
38
- undefined,
39
- iterate(escaper)(
40
- input,
41
- targets.map((obj) => ({
42
- type: "object",
43
- is: () => success(checker(input, obj, explore)),
44
- value: () => decoder(input, obj, explore),
45
- })),
46
- `(${targets.map((t) => t.name).join(" | ")})`,
47
- ),
48
- ),
49
- undefined,
50
- undefined,
51
- );
52
-
53
- const iterate =
54
- (escaper: (value: ts.Expression, expected: string) => ts.Statement) =>
55
- (input: ts.Expression, unions: IUnion[], expected: string) =>
56
- ts.factory.createBlock(
57
- [
58
- ...unions.map((u) =>
59
- ts.factory.createIfStatement(
60
- u.is(),
61
- ts.factory.createReturnStatement(u.value()),
62
- ),
63
- ),
64
- escaper(input, expected),
65
- ],
66
- true,
67
- );
68
-
69
- interface IUnion {
70
- type: string;
71
- is: () => ts.Expression;
72
- value: () => ts.Expression;
73
- }
1
+ import ts from "typescript";
2
+
3
+ import { MetadataObject } from "../../metadata/MetadataObject";
4
+
5
+ import { FeatureProgrammer } from "../FeatureProgrammer";
6
+
7
+ /**
8
+ * @internal
9
+ */
10
+ export const decode_union_object =
11
+ (
12
+ checker: (
13
+ input: ts.Expression,
14
+ obj: MetadataObject,
15
+ explore: FeatureProgrammer.IExplore,
16
+ ) => ts.Expression,
17
+ ) =>
18
+ (
19
+ decoder: (
20
+ input: ts.Expression,
21
+ obj: MetadataObject,
22
+ explore: FeatureProgrammer.IExplore,
23
+ ) => ts.Expression,
24
+ ) =>
25
+ (success: (exp: ts.Expression) => ts.Expression) =>
26
+ (escaper: (value: ts.Expression, expected: string) => ts.Statement) =>
27
+ (
28
+ input: ts.Expression,
29
+ targets: MetadataObject[],
30
+ explore: FeatureProgrammer.IExplore,
31
+ ): ts.CallExpression =>
32
+ ts.factory.createCallExpression(
33
+ ts.factory.createArrowFunction(
34
+ undefined,
35
+ undefined,
36
+ [],
37
+ undefined,
38
+ undefined,
39
+ iterate(escaper)(
40
+ input,
41
+ targets.map((obj) => ({
42
+ type: "object",
43
+ is: () => success(checker(input, obj, explore)),
44
+ value: () => decoder(input, obj, explore),
45
+ })),
46
+ `(${targets.map((t) => t.name).join(" | ")})`,
47
+ ),
48
+ ),
49
+ undefined,
50
+ undefined,
51
+ );
52
+
53
+ const iterate =
54
+ (escaper: (value: ts.Expression, expected: string) => ts.Statement) =>
55
+ (input: ts.Expression, unions: IUnion[], expected: string) =>
56
+ ts.factory.createBlock(
57
+ [
58
+ ...unions.map((u) =>
59
+ ts.factory.createIfStatement(
60
+ u.is(),
61
+ ts.factory.createReturnStatement(u.value()),
62
+ ),
63
+ ),
64
+ escaper(input, expected),
65
+ ],
66
+ true,
67
+ );
68
+
69
+ interface IUnion {
70
+ type: string;
71
+ is: () => ts.Expression;
72
+ value: () => ts.Expression;
73
+ }