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
@@ -0,0 +1,45 @@
1
+ import ts from "typescript";
2
+
3
+ import { IdentifierFactory } from "../../factories/IdentifierFactory";
4
+
5
+ import { IMetadataTag } from "../../metadata/IMetadataTag";
6
+
7
+ import { check_length } from "./check_length";
8
+
9
+ /**
10
+ * @internal
11
+ */
12
+ export function check_array_length(
13
+ input: ts.Expression,
14
+ tagList: IMetadataTag[],
15
+ ): ts.Expression | null {
16
+ const conditions: ts.Expression[] = [];
17
+
18
+ // CHECK TAGS
19
+ for (const tag of tagList)
20
+ if (tag.kind === "minItems")
21
+ conditions.push(
22
+ ts.factory.createLessThanEquals(
23
+ ts.factory.createNumericLiteral(tag.value),
24
+ IdentifierFactory.join(input, "length"),
25
+ ),
26
+ );
27
+ else if (tag.kind === "maxItems")
28
+ conditions.push(
29
+ ts.factory.createGreaterThanEquals(
30
+ ts.factory.createNumericLiteral(tag.value),
31
+ IdentifierFactory.join(input, "length"),
32
+ ),
33
+ );
34
+ else if (tag.kind === "items")
35
+ check_length(
36
+ conditions,
37
+ IdentifierFactory.join(input, "length"),
38
+ tag,
39
+ );
40
+
41
+ // COMBINATION
42
+ return conditions.length
43
+ ? conditions.reduce((x, y) => ts.factory.createLogicalAnd(x, y))
44
+ : null;
45
+ }
@@ -1,146 +1,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
- const criteria = props.entries
21
- ? ts.factory.createCallExpression(props.entries, undefined, [
22
- ts.factory.createCallExpression(
23
- ts.factory.createIdentifier("Object.keys"),
24
- undefined,
25
- [ts.factory.createIdentifier("input")],
26
- ),
27
- check_dynamic_property(props)(regular, dynamic),
28
- ])
29
- : ts.factory.createCallExpression(
30
- IdentifierFactory.join(
31
- ts.factory.createCallExpression(
32
- ts.factory.createIdentifier("Object.keys"),
33
- undefined,
34
- [ts.factory.createIdentifier("input")],
35
- ),
36
- props.assert ? "every" : "map",
37
- ),
38
- undefined,
39
- [check_dynamic_property(props)(regular, dynamic)],
40
- );
41
- return (props.halt || ((elem) => elem))(
42
- props.assert ? criteria : check_everything(criteria),
43
- );
44
- };
45
-
46
- const check_dynamic_property =
47
- (props: check_object.IProps) =>
48
- (regular: IExpressionEntry[], dynamic: IExpressionEntry[]) => {
49
- //----
50
- // IF CONDITIONS
51
- //----
52
- // PREPARE ASSETS
53
- const key = ts.factory.createIdentifier("key");
54
- const value = ts.factory.createIdentifier("value");
55
-
56
- const statements: ts.Statement[] = [];
57
- const add = (exp: ts.Expression, output: ts.Expression) =>
58
- statements.push(
59
- ts.factory.createIfStatement(
60
- exp,
61
- ts.factory.createReturnStatement(output),
62
- ),
63
- );
64
-
65
- // GATHER CONDITIONS
66
- if (props.equals === true && regular.length)
67
- add(is_regular_property(regular), props.positive);
68
- statements.push(
69
- StatementFactory.constant(
70
- "value",
71
- ts.factory.createIdentifier("input[key]"),
72
- ),
73
- );
74
- add(
75
- ts.factory.createStrictEquality(
76
- ts.factory.createIdentifier("undefined"),
77
- value,
78
- ),
79
- props.positive,
80
- );
81
- for (const entry of dynamic)
82
- add(
83
- ts.factory.createCallExpression(
84
- ts.factory.createIdentifier(
85
- `RegExp(/${metadata_to_pattern(true)(
86
- entry.key,
87
- )}/).test`,
88
- ),
89
- undefined,
90
- [key],
91
- ),
92
- entry.expression,
93
- );
94
-
95
- //----
96
- // FUNCTION BODY
97
- //----
98
- // CLOSURE BLOCK
99
- const block: ts.Block = ts.factory.createBlock(
100
- [
101
- ...statements,
102
- ts.factory.createReturnStatement(
103
- props.equals === true
104
- ? props.superfluous(value)
105
- : props.positive,
106
- ),
107
- ],
108
- true,
109
- );
110
-
111
- // RETURNS
112
- return ts.factory.createArrowFunction(
113
- undefined,
114
- undefined,
115
- [IdentifierFactory.parameter("key")],
116
- undefined,
117
- undefined,
118
- block,
119
- );
120
- };
121
-
122
- const is_regular_property = (regular: IExpressionEntry[]) =>
123
- ts.factory.createCallExpression(
124
- IdentifierFactory.join(
125
- ts.factory.createArrayLiteralExpression(
126
- regular.map((entry) =>
127
- ts.factory.createStringLiteral(entry.key.getSoleLiteral()!),
128
- ),
129
- ),
130
- "some",
131
- ),
132
- undefined,
133
- [
134
- ts.factory.createArrowFunction(
135
- undefined,
136
- undefined,
137
- [IdentifierFactory.parameter("prop")],
138
- undefined,
139
- undefined,
140
- ts.factory.createStrictEquality(
141
- ts.factory.createIdentifier("key"),
142
- ts.factory.createIdentifier("prop"),
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
+ const criteria = props.entries
21
+ ? ts.factory.createCallExpression(props.entries, undefined, [
22
+ ts.factory.createCallExpression(
23
+ ts.factory.createIdentifier("Object.keys"),
24
+ undefined,
25
+ [ts.factory.createIdentifier("input")],
26
+ ),
27
+ check_dynamic_property(props)(regular, dynamic),
28
+ ])
29
+ : ts.factory.createCallExpression(
30
+ IdentifierFactory.join(
31
+ ts.factory.createCallExpression(
32
+ ts.factory.createIdentifier("Object.keys"),
33
+ undefined,
34
+ [ts.factory.createIdentifier("input")],
35
+ ),
36
+ props.assert ? "every" : "map",
37
+ ),
38
+ undefined,
39
+ [check_dynamic_property(props)(regular, dynamic)],
40
+ );
41
+ return (props.halt || ((elem) => elem))(
42
+ props.assert ? criteria : check_everything(criteria),
43
+ );
44
+ };
45
+
46
+ const check_dynamic_property =
47
+ (props: check_object.IProps) =>
48
+ (regular: IExpressionEntry[], dynamic: IExpressionEntry[]) => {
49
+ //----
50
+ // IF CONDITIONS
51
+ //----
52
+ // PREPARE ASSETS
53
+ const key = ts.factory.createIdentifier("key");
54
+ const value = ts.factory.createIdentifier("value");
55
+
56
+ const statements: ts.Statement[] = [];
57
+ const add = (exp: ts.Expression, output: ts.Expression) =>
58
+ statements.push(
59
+ ts.factory.createIfStatement(
60
+ exp,
61
+ ts.factory.createReturnStatement(output),
62
+ ),
63
+ );
64
+
65
+ // GATHER CONDITIONS
66
+ if (props.equals === true && regular.length)
67
+ add(is_regular_property(regular), props.positive);
68
+ statements.push(
69
+ StatementFactory.constant(
70
+ "value",
71
+ ts.factory.createIdentifier("input[key]"),
72
+ ),
73
+ );
74
+ add(
75
+ ts.factory.createStrictEquality(
76
+ ts.factory.createIdentifier("undefined"),
77
+ value,
78
+ ),
79
+ props.positive,
80
+ );
81
+ for (const entry of dynamic)
82
+ add(
83
+ ts.factory.createCallExpression(
84
+ ts.factory.createIdentifier(
85
+ `RegExp(/${metadata_to_pattern(true)(
86
+ entry.key,
87
+ )}/).test`,
88
+ ),
89
+ undefined,
90
+ [key],
91
+ ),
92
+ entry.expression,
93
+ );
94
+
95
+ //----
96
+ // FUNCTION BODY
97
+ //----
98
+ // CLOSURE BLOCK
99
+ const block: ts.Block = ts.factory.createBlock(
100
+ [
101
+ ...statements,
102
+ ts.factory.createReturnStatement(
103
+ props.equals === true
104
+ ? props.superfluous(value)
105
+ : props.positive,
106
+ ),
107
+ ],
108
+ true,
109
+ );
110
+
111
+ // RETURNS
112
+ return ts.factory.createArrowFunction(
113
+ undefined,
114
+ undefined,
115
+ [IdentifierFactory.parameter("key")],
116
+ undefined,
117
+ undefined,
118
+ block,
119
+ );
120
+ };
121
+
122
+ const is_regular_property = (regular: IExpressionEntry[]) =>
123
+ ts.factory.createCallExpression(
124
+ IdentifierFactory.join(
125
+ ts.factory.createArrayLiteralExpression(
126
+ regular.map((entry) =>
127
+ ts.factory.createStringLiteral(entry.key.getSoleLiteral()!),
128
+ ),
129
+ ),
130
+ "some",
131
+ ),
132
+ undefined,
133
+ [
134
+ ts.factory.createArrowFunction(
135
+ undefined,
136
+ undefined,
137
+ [IdentifierFactory.parameter("prop")],
138
+ undefined,
139
+ undefined,
140
+ ts.factory.createStrictEquality(
141
+ ts.factory.createIdentifier("key"),
142
+ ts.factory.createIdentifier("prop"),
143
+ ),
144
+ ),
145
+ ],
146
+ );
@@ -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
+ );
@@ -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,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
- 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
+ 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,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
+ }