typia 3.5.0-dev.20221222 → 3.5.0-dev.20230124

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 (184) hide show
  1. package/README.md +5 -2
  2. package/lib/executable/internal/TypiaSetupWizard.d.ts +6 -2
  3. package/lib/executable/internal/TypiaSetupWizard.js +23 -22
  4. package/lib/executable/internal/TypiaSetupWizard.js.map +1 -1
  5. package/lib/executable/typia.js +11 -10
  6. package/lib/executable/typia.js.map +1 -1
  7. package/lib/factories/internal/protocols/ProtocolMetadataUtil.d.ts +1 -0
  8. package/lib/factories/internal/protocols/ProtocolMetadataUtil.js +20 -0
  9. package/lib/factories/internal/protocols/ProtocolMetadataUtil.js.map +1 -1
  10. package/lib/factories/internal/protocols/iterate_protocol_map.d.ts +2 -1
  11. package/lib/factories/internal/protocols/iterate_protocol_map.js +7 -4
  12. package/lib/factories/internal/protocols/iterate_protocol_map.js.map +1 -1
  13. package/lib/factories/internal/protocols/iterate_protocol_metadata.js +3 -3
  14. package/lib/factories/internal/protocols/iterate_protocol_metadata.js.map +1 -1
  15. package/lib/factories/internal/protocols/iterate_protocol_repeated.d.ts +2 -1
  16. package/lib/factories/internal/protocols/iterate_protocol_repeated.js +5 -4
  17. package/lib/factories/internal/protocols/iterate_protocol_repeated.js.map +1 -1
  18. package/lib/messages/IProtocolMap.d.ts +5 -0
  19. package/lib/messages/IProtocolMap.js +3 -0
  20. package/lib/messages/IProtocolMap.js.map +1 -0
  21. package/lib/messages/IProtocolProperty.d.ts +2 -1
  22. package/lib/metadata/Metadata.d.ts +1 -0
  23. package/lib/metadata/Metadata.js +145 -51
  24. package/lib/metadata/Metadata.js.map +1 -1
  25. package/lib/programmers/AssertProgrammer.js +1 -1
  26. package/lib/programmers/AssertProgrammer.js.map +1 -1
  27. package/lib/programmers/CheckerProgrammer.d.ts +1 -0
  28. package/lib/programmers/CheckerProgrammer.js +147 -138
  29. package/lib/programmers/CheckerProgrammer.js.map +1 -1
  30. package/lib/programmers/MessageProgrammer.js +7 -2
  31. package/lib/programmers/MessageProgrammer.js.map +1 -1
  32. package/lib/programmers/ValidateProgrammer.js +1 -1
  33. package/lib/programmers/ValidateProgrammer.js.map +1 -1
  34. package/lib/programmers/helpers/UnionExplorer.d.ts +23 -29
  35. package/lib/programmers/helpers/UnionExplorer.js +29 -41
  36. package/lib/programmers/helpers/UnionExplorer.js.map +1 -1
  37. package/lib/programmers/internal/application_array.js +29 -27
  38. package/lib/programmers/internal/application_array.js.map +1 -1
  39. package/lib/programmers/internal/application_object.js +96 -31
  40. package/lib/programmers/internal/application_object.js.map +1 -1
  41. package/lib/programmers/internal/application_schema.js +28 -136
  42. package/lib/programmers/internal/application_schema.js.map +1 -1
  43. package/lib/programmers/internal/application_tuple.js +3 -2
  44. package/lib/programmers/internal/application_tuple.js.map +1 -1
  45. package/lib/programmers/internal/check_array.js +4 -32
  46. package/lib/programmers/internal/check_array.js.map +1 -1
  47. package/lib/programmers/internal/check_array_length.d.ts +1 -0
  48. package/lib/programmers/internal/check_array_length.js +47 -0
  49. package/lib/programmers/internal/check_array_length.js.map +1 -0
  50. package/lib/programmers/internal/check_union_array_like.d.ts +21 -0
  51. package/lib/programmers/internal/check_union_array_like.js +83 -0
  52. package/lib/programmers/internal/check_union_array_like.js.map +1 -0
  53. package/lib/programmers/internal/check_union_tuple.d.ts +1 -0
  54. package/lib/programmers/internal/check_union_tuple.js +11 -0
  55. package/lib/programmers/internal/check_union_tuple.js.map +1 -0
  56. package/lib/schemas/IJsonComponents.d.ts +4 -2
  57. package/lib/schemas/IJsonSchema.d.ts +2 -0
  58. package/package.json +4 -4
  59. package/src/IValidation.ts +21 -21
  60. package/src/Primitive.ts +82 -82
  61. package/src/TypeGuardError.ts +36 -36
  62. package/src/executable/internal/CommandParser.ts +15 -15
  63. package/src/executable/internal/TypiaSetupWizard.ts +30 -21
  64. package/src/executable/typia.ts +48 -46
  65. package/src/factories/CommentFactory.ts +10 -10
  66. package/src/factories/ExpressionFactory.ts +66 -66
  67. package/src/factories/IdentifierFactory.ts +72 -72
  68. package/src/factories/LiteralFactory.ts +44 -44
  69. package/src/factories/StatementFactory.ts +60 -60
  70. package/src/factories/TemplateFactory.ts +56 -56
  71. package/src/factories/TypeFactory.ts +101 -101
  72. package/src/factories/ValueFactory.ts +12 -12
  73. package/src/factories/internal/protocols/ProtocolMetadataUtil.ts +20 -0
  74. package/src/factories/internal/protocols/iterate_protocol_map.ts +9 -3
  75. package/src/factories/internal/protocols/iterate_protocol_metadata.ts +17 -4
  76. package/src/factories/internal/protocols/iterate_protocol_repeated.ts +14 -5
  77. package/src/functional/$every.ts +11 -11
  78. package/src/functional/$guard.ts +35 -35
  79. package/src/functional/$is_email.ts +5 -5
  80. package/src/functional/$is_ipv4.ts +5 -5
  81. package/src/functional/$is_ipv6.ts +5 -5
  82. package/src/functional/$is_url.ts +5 -5
  83. package/src/functional/$is_uuid.ts +5 -5
  84. package/src/functional/$join.ts +50 -50
  85. package/src/functional/$report.ts +15 -15
  86. package/src/functional/$rest.ts +3 -3
  87. package/src/functional/$string.ts +37 -37
  88. package/src/functional/$tail.ts +6 -6
  89. package/src/index.ts +4 -4
  90. package/src/messages/IProtocolMap.ts +5 -0
  91. package/src/messages/IProtocolProperty.ts +3 -1
  92. package/src/metadata/IJsDocTagInfo.ts +10 -10
  93. package/src/metadata/IMetadata.ts +25 -25
  94. package/src/metadata/IMetadataApplication.ts +7 -7
  95. package/src/metadata/IMetadataConstant.ts +16 -16
  96. package/src/metadata/IMetadataEntry.ts +6 -6
  97. package/src/metadata/IMetadataObject.ts +29 -29
  98. package/src/metadata/IMetadataProperty.ts +11 -11
  99. package/src/metadata/Metadata.ts +64 -7
  100. package/src/metadata/MetadataConstant.ts +3 -3
  101. package/src/metadata/MetadataObject.ts +131 -131
  102. package/src/metadata/MetadataProperty.ts +64 -64
  103. package/src/programmers/ApplicationProgrammer.ts +55 -55
  104. package/src/programmers/AssertProgrammer.ts +1 -1
  105. package/src/programmers/CheckerProgrammer.ts +252 -200
  106. package/src/programmers/FeatureProgrammer.ts +327 -327
  107. package/src/programmers/MessageProgrammer.ts +9 -2
  108. package/src/programmers/ValidateProgrammer.ts +1 -1
  109. package/src/programmers/helpers/AtomicPredicator.ts +15 -15
  110. package/src/programmers/helpers/FunctionImporeter.ts +31 -31
  111. package/src/programmers/helpers/IExpressionEntry.ts +10 -10
  112. package/src/programmers/helpers/StringifyJoinder.ts +111 -111
  113. package/src/programmers/helpers/StringifyPredicator.ts +18 -18
  114. package/src/programmers/helpers/UnionExplorer.ts +274 -437
  115. package/src/programmers/helpers/UnionPredicator.ts +81 -81
  116. package/src/programmers/internal/application_array.ts +47 -45
  117. package/src/programmers/internal/application_boolean.ts +17 -17
  118. package/src/programmers/internal/application_constant.ts +29 -29
  119. package/src/programmers/internal/application_default_string.ts +32 -32
  120. package/src/programmers/internal/application_native.ts +29 -29
  121. package/src/programmers/internal/application_number.ts +76 -76
  122. package/src/programmers/internal/application_object.ts +153 -103
  123. package/src/programmers/internal/application_schema.ts +15 -68
  124. package/src/programmers/internal/application_string.ts +49 -49
  125. package/src/programmers/internal/application_templates.ts +27 -27
  126. package/src/programmers/internal/application_tuple.ts +29 -25
  127. package/src/programmers/internal/check_array.ts +22 -44
  128. package/src/programmers/internal/check_array_length.ts +45 -0
  129. package/src/programmers/internal/check_dynamic_properties.ts +146 -146
  130. package/src/programmers/internal/check_everything.ts +25 -25
  131. package/src/programmers/internal/check_length.ts +46 -46
  132. package/src/programmers/internal/check_native.ts +9 -9
  133. package/src/programmers/internal/check_object.ts +42 -42
  134. package/src/programmers/internal/check_string.ts +24 -24
  135. package/src/programmers/internal/check_string_tags.ts +63 -63
  136. package/src/programmers/internal/check_template.ts +50 -50
  137. package/src/programmers/internal/check_union_array_like.ts +242 -0
  138. package/src/programmers/internal/check_union_tuple.ts +33 -0
  139. package/src/programmers/internal/decode_union_object.ts +73 -73
  140. package/src/programmers/internal/feature_object_entries.ts +49 -49
  141. package/src/programmers/internal/metadata_to_pattern.ts +31 -31
  142. package/src/programmers/internal/stringify_dynamic_properties.ts +164 -164
  143. package/src/programmers/internal/stringify_native.ts +8 -8
  144. package/src/programmers/internal/stringify_regular_properties.ts +81 -81
  145. package/src/programmers/internal/template_to_pattern.ts +15 -15
  146. package/src/schemas/IJsonApplication.ts +9 -9
  147. package/src/schemas/IJsonComponents.ts +26 -24
  148. package/src/schemas/IJsonSchema.ts +2 -0
  149. package/src/transform.ts +20 -20
  150. package/src/transformers/ExpressionWithArgumentTransformer.ts +66 -66
  151. package/src/transformers/FileTransformer.ts +49 -49
  152. package/src/transformers/IProject.ts +11 -11
  153. package/src/transformers/NodeTransformer.ts +19 -19
  154. package/src/transformers/features/miscellaneous/ApplicationTransformer.ts +1 -0
  155. package/src/transformers/features/miscellaneous/MetadataTransformer.ts +55 -55
  156. package/src/transformers/features/parsers/AssertParseTransformer.ts +36 -36
  157. package/src/transformers/features/parsers/CreateAssertParseTransformer.ts +32 -32
  158. package/src/transformers/features/parsers/CreateIsParseTransformer.ts +32 -32
  159. package/src/transformers/features/parsers/CreateValidateParseTransformer.ts +32 -32
  160. package/src/transformers/features/parsers/IsParseTransformer.ts +36 -36
  161. package/src/transformers/features/parsers/ValidateParseTransformer.ts +36 -36
  162. package/src/transformers/features/stringifiers/AssertStringifyTransformer.ts +38 -38
  163. package/src/transformers/features/stringifiers/CreateAssertStringifyTransformer.ts +32 -32
  164. package/src/transformers/features/stringifiers/CreateIsStringifyTransformer.ts +32 -32
  165. package/src/transformers/features/stringifiers/CreateStringifyTransformer.ts +31 -31
  166. package/src/transformers/features/stringifiers/CreateValidateStringifyProgrammer.ts +32 -32
  167. package/src/transformers/features/stringifiers/IsStringifyTransformer.ts +38 -38
  168. package/src/transformers/features/stringifiers/ValidateStringifyTransformer.ts +38 -38
  169. package/src/transformers/features/validators/AssertTransformer.ts +43 -43
  170. package/src/transformers/features/validators/CreateAssertTransformer.ts +35 -35
  171. package/src/transformers/features/validators/CreateIsTransformer.ts +35 -35
  172. package/src/transformers/features/validators/CreateValidateTransformer.ts +35 -35
  173. package/src/transformers/features/validators/IsTransformer.ts +43 -43
  174. package/src/transformers/features/validators/ValidateTransformer.ts +43 -43
  175. package/src/typings/Atomic.ts +17 -17
  176. package/src/typings/ClassProperties.ts +5 -5
  177. package/src/typings/OmitNever.ts +3 -3
  178. package/src/typings/SpecialFields.ts +3 -3
  179. package/src/typings/Writable.ts +11 -11
  180. package/src/utils/ArrayUtil.ts +49 -49
  181. package/src/utils/Escaper.ts +50 -50
  182. package/src/utils/MapUtil.ts +14 -14
  183. package/src/utils/PatternUtil.ts +30 -30
  184. package/src/utils/Singleton.ts +17 -17
@@ -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
+ };
@@ -0,0 +1,242 @@
1
+ import ts from "typescript";
2
+
3
+ import { IdentifierFactory } from "../../factories/IdentifierFactory";
4
+ import { StatementFactory } from "../../factories/StatementFactory";
5
+
6
+ import { IMetadataTag } from "../../metadata/IMetadataTag";
7
+
8
+ import { CheckerProgrammer } from "../CheckerProgrammer";
9
+ import { FeatureProgrammer } from "../FeatureProgrammer";
10
+ import { UnionExplorer } from "../helpers/UnionExplorer";
11
+
12
+ export const check_union_array_like =
13
+ <T>(accessor: check_union_array_like.IAccessor<T>) =>
14
+ (props: check_union_array_like.IProps<T>) =>
15
+ (
16
+ input: ts.Expression,
17
+ targets: T[],
18
+ explore: FeatureProgrammer.IExplore,
19
+ tags: IMetadataTag[],
20
+ ) => {
21
+ // ONLY ONE TYPE
22
+ if (targets.length === 1)
23
+ return props.decoder(
24
+ accessor.array(input),
25
+ targets[0]!,
26
+ explore,
27
+ tags,
28
+ );
29
+
30
+ //----
31
+ // LIST UP VARIABLES
32
+ //----
33
+ // TUPLES
34
+ const tupleListVariable: ts.VariableStatement =
35
+ StatementFactory.constant(
36
+ "tupleList",
37
+ ts.factory.createArrayLiteralExpression(
38
+ targets.map((meta) =>
39
+ ts.factory.createArrayLiteralExpression([
40
+ ts.factory.createArrowFunction(
41
+ undefined,
42
+ undefined,
43
+ [IdentifierFactory.parameter("top")],
44
+ undefined,
45
+ undefined,
46
+ props.checker(
47
+ ts.factory.createIdentifier("top"),
48
+ meta,
49
+ {
50
+ ...explore,
51
+ tracable: false,
52
+ postfix: `"[0]"`,
53
+ },
54
+ tags,
55
+ input,
56
+ ),
57
+ ),
58
+ ts.factory.createArrowFunction(
59
+ undefined,
60
+ undefined,
61
+ [IdentifierFactory.parameter("top")],
62
+ undefined,
63
+ undefined,
64
+ props.decoder(
65
+ ts.factory.createIdentifier("top"),
66
+ meta,
67
+ {
68
+ ...explore,
69
+ tracable: true,
70
+ },
71
+ tags,
72
+ ),
73
+ ),
74
+ ]),
75
+ ),
76
+ ),
77
+ );
78
+
79
+ // FILTERED TUPLES
80
+ const filteredVariable = StatementFactory.constant(
81
+ "filtered",
82
+ ts.factory.createCallExpression(
83
+ ts.factory.createIdentifier("tupleList.filter"),
84
+ undefined,
85
+ [
86
+ ts.factory.createArrowFunction(
87
+ undefined,
88
+ undefined,
89
+ [IdentifierFactory.parameter("tuple")],
90
+ undefined,
91
+ undefined,
92
+ ts.factory.createStrictEquality(
93
+ props.success,
94
+ ts.factory.createCallExpression(
95
+ ts.factory.createIdentifier("tuple[0]"),
96
+ undefined,
97
+ [ts.factory.createIdentifier("front")],
98
+ ),
99
+ ),
100
+ ),
101
+ ],
102
+ ),
103
+ );
104
+
105
+ //----
106
+ // STATEMENTS
107
+ //----
108
+ // ONLY ONE TYPE
109
+ const uniqueStatement = ts.factory.createIfStatement(
110
+ ts.factory.createStrictEquality(
111
+ ts.factory.createNumericLiteral(1),
112
+ ts.factory.createIdentifier("filtered.length"),
113
+ ),
114
+ ts.factory.createReturnStatement(
115
+ ts.factory.createCallExpression(
116
+ ts.factory.createIdentifier(`filtered[0][1]`),
117
+ undefined,
118
+ [accessor.array(input)],
119
+ ),
120
+ ),
121
+ );
122
+
123
+ // UNION TYPE
124
+ const forOfStatement = ts.factory.createForOfStatement(
125
+ undefined,
126
+ ts.factory.createVariableDeclarationList(
127
+ [ts.factory.createVariableDeclaration("tuple")],
128
+ ts.NodeFlags.Const,
129
+ ),
130
+ // StatementFactory.variable(ts.NodeFlags.Const, "tuple"),
131
+ ts.factory.createIdentifier("filtered"),
132
+ ts.factory.createIfStatement(
133
+ ts.factory.createCallExpression(
134
+ IdentifierFactory.join(
135
+ ts.factory.createIdentifier("array"),
136
+ "every",
137
+ ),
138
+ undefined,
139
+ [
140
+ ts.factory.createArrowFunction(
141
+ undefined,
142
+ undefined,
143
+ [IdentifierFactory.parameter("value")],
144
+ undefined,
145
+ undefined,
146
+ ts.factory.createStrictEquality(
147
+ props.success,
148
+ ts.factory.createCallExpression(
149
+ ts.factory.createIdentifier("tuple[0]"),
150
+ undefined,
151
+ [ts.factory.createIdentifier("value")],
152
+ ),
153
+ ),
154
+ ),
155
+ ],
156
+ ),
157
+ ts.factory.createReturnStatement(
158
+ ts.factory.createCallExpression(
159
+ ts.factory.createIdentifier(`tuple[1]`),
160
+ undefined,
161
+ [ts.factory.createIdentifier("array")],
162
+ ),
163
+ ),
164
+ ),
165
+ );
166
+ const unionStatement = ts.factory.createIfStatement(
167
+ ts.factory.createLessThan(
168
+ ts.factory.createNumericLiteral(1),
169
+ ts.factory.createIdentifier("filtered.length"),
170
+ ),
171
+ forOfStatement,
172
+ );
173
+
174
+ const block = [
175
+ // ARRAY.LENGTH := 0
176
+ ...(accessor.size !== null
177
+ ? [
178
+ ts.factory.createIfStatement(
179
+ ts.factory.createStrictEquality(
180
+ ts.factory.createNumericLiteral(0),
181
+ accessor.size(input),
182
+ ),
183
+ ts.factory.createReturnStatement(props.empty),
184
+ ),
185
+ ]
186
+ : []),
187
+
188
+ // UNION PREDICATORS
189
+ tupleListVariable,
190
+ StatementFactory.constant("front", accessor.front(input)),
191
+ filteredVariable,
192
+ uniqueStatement,
193
+
194
+ // CONDITIONAL STATEMENTS
195
+ StatementFactory.constant("array", accessor.array(input)),
196
+ unionStatement,
197
+ props.failure(
198
+ input,
199
+ `(${targets.map((t) => accessor.name(t)).join(" | ")})`,
200
+ explore,
201
+ ),
202
+ ];
203
+
204
+ return ts.factory.createCallExpression(
205
+ ts.factory.createArrowFunction(
206
+ undefined,
207
+ undefined,
208
+ [],
209
+ undefined,
210
+ undefined,
211
+ ts.factory.createBlock(block, true),
212
+ ),
213
+ undefined,
214
+ undefined,
215
+ );
216
+ };
217
+ export namespace check_union_array_like {
218
+ export interface IProps<T> {
219
+ checker(
220
+ front: ts.Expression,
221
+ target: T,
222
+ explore: FeatureProgrammer.IExplore,
223
+ tags: IMetadataTag[],
224
+ array: ts.Expression,
225
+ ): ts.Expression;
226
+ decoder: UnionExplorer.Decoder<T>;
227
+ empty: ts.Expression;
228
+ success: ts.Expression;
229
+ failure(
230
+ input: ts.Expression,
231
+ expected: string,
232
+ explore: CheckerProgrammer.IExplore,
233
+ ): ts.Statement;
234
+ }
235
+
236
+ export interface IAccessor<T> {
237
+ name(target: T): string;
238
+ front(input: ts.Expression): ts.Expression;
239
+ array(input: ts.Expression): ts.Expression;
240
+ size: null | ((input: ts.Expression) => ts.Expression);
241
+ }
242
+ }
@@ -0,0 +1,33 @@
1
+ import ts from "typescript";
2
+
3
+ import { IMetadataTag } from "../../metadata/IMetadataTag";
4
+ import { Metadata } from "../../metadata/Metadata";
5
+
6
+ import { IProject } from "../../transformers/IProject";
7
+
8
+ import { CheckerProgrammer } from "../CheckerProgrammer";
9
+ import { FunctionImporter } from "../helpers/FunctionImporeter";
10
+
11
+ /**
12
+ * @internal
13
+ * @todo Faster union checking logic is required
14
+ */
15
+ export const check_union_tuple =
16
+ (
17
+ project: IProject,
18
+ config: CheckerProgrammer.IConfig,
19
+ importer: FunctionImporter,
20
+ ) =>
21
+ (
22
+ _front: ts.Expression,
23
+ elements: Metadata[],
24
+ explore: CheckerProgrammer.IExplore,
25
+ tags: IMetadataTag[],
26
+ array: ts.Expression,
27
+ ) =>
28
+ CheckerProgrammer.decode_tuple(project, config, importer, true)(
29
+ array,
30
+ elements,
31
+ explore,
32
+ tags,
33
+ );
@@ -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
+ }