typia 3.4.15 → 3.5.0-dev.20221222

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 (169) hide show
  1. package/README.md +48 -7
  2. package/lib/factories/MetadataCollection.d.ts +1 -9
  3. package/lib/factories/MetadataCollection.js +2 -75
  4. package/lib/factories/MetadataCollection.js.map +1 -1
  5. package/lib/factories/ProtocolFactory.d.ts +8 -0
  6. package/lib/factories/ProtocolFactory.js +119 -0
  7. package/lib/factories/ProtocolFactory.js.map +1 -0
  8. package/lib/factories/internal/protocols/ProtocolMetadataUtil.d.ts +11 -0
  9. package/lib/factories/internal/protocols/ProtocolMetadataUtil.js +76 -0
  10. package/lib/factories/internal/protocols/ProtocolMetadataUtil.js.map +1 -0
  11. package/lib/factories/internal/protocols/emplace_protocol_object.d.ts +3 -0
  12. package/lib/factories/internal/protocols/emplace_protocol_object.js +47 -0
  13. package/lib/factories/internal/protocols/emplace_protocol_object.js.map +1 -0
  14. package/lib/factories/internal/protocols/emplace_protocol_property.d.ts +4 -0
  15. package/lib/factories/internal/protocols/emplace_protocol_property.js +20 -0
  16. package/lib/factories/internal/protocols/emplace_protocol_property.js.map +1 -0
  17. package/lib/factories/internal/protocols/iterate_protocol_atomic.d.ts +3 -0
  18. package/lib/factories/internal/protocols/iterate_protocol_atomic.js +69 -0
  19. package/lib/factories/internal/protocols/iterate_protocol_atomic.js.map +1 -0
  20. package/lib/factories/internal/protocols/iterate_protocol_constant.d.ts +2 -0
  21. package/lib/factories/internal/protocols/iterate_protocol_constant.js +30 -0
  22. package/lib/factories/internal/protocols/iterate_protocol_constant.js.map +1 -0
  23. package/lib/factories/internal/protocols/iterate_protocol_main.d.ts +3 -0
  24. package/lib/factories/internal/protocols/iterate_protocol_main.js +17 -0
  25. package/lib/factories/internal/protocols/iterate_protocol_main.js.map +1 -0
  26. package/lib/factories/internal/protocols/iterate_protocol_map.d.ts +3 -0
  27. package/lib/factories/internal/protocols/iterate_protocol_map.js +71 -0
  28. package/lib/factories/internal/protocols/iterate_protocol_map.js.map +1 -0
  29. package/lib/factories/internal/protocols/iterate_protocol_metadata.d.ts +5 -0
  30. package/lib/factories/internal/protocols/iterate_protocol_metadata.js +192 -0
  31. package/lib/factories/internal/protocols/iterate_protocol_metadata.js.map +1 -0
  32. package/lib/factories/internal/protocols/iterate_protocol_native.d.ts +2 -0
  33. package/lib/factories/internal/protocols/iterate_protocol_native.js +33 -0
  34. package/lib/factories/internal/protocols/iterate_protocol_native.js.map +1 -0
  35. package/lib/factories/internal/protocols/iterate_protocol_repeated.d.ts +4 -0
  36. package/lib/factories/internal/protocols/iterate_protocol_repeated.js +24 -0
  37. package/lib/factories/internal/protocols/iterate_protocol_repeated.js.map +1 -0
  38. package/lib/factories/internal/protocols/iterate_protocol_tuple.d.ts +3 -0
  39. package/lib/factories/internal/protocols/iterate_protocol_tuple.js +46 -0
  40. package/lib/factories/internal/protocols/iterate_protocol_tuple.js.map +1 -0
  41. package/lib/functional/$proto_bytes.d.ts +2 -0
  42. package/lib/functional/$proto_bytes.js +37 -0
  43. package/lib/functional/$proto_bytes.js.map +1 -0
  44. package/lib/functional/$proto_field.d.ts +10 -0
  45. package/lib/functional/$proto_field.js +42 -0
  46. package/lib/functional/$proto_field.js.map +1 -0
  47. package/lib/functional/$proto_float.d.ts +4 -0
  48. package/lib/functional/$proto_float.js +28 -0
  49. package/lib/functional/$proto_float.js.map +1 -0
  50. package/lib/functional/$proto_i32.d.ts +2 -0
  51. package/lib/functional/$proto_i32.js +23 -0
  52. package/lib/functional/$proto_i32.js.map +1 -0
  53. package/lib/functional/$proto_i64.d.ts +2 -0
  54. package/lib/functional/$proto_i64.js +31 -0
  55. package/lib/functional/$proto_i64.js.map +1 -0
  56. package/lib/functional/$proto_size.d.ts +6 -0
  57. package/lib/functional/$proto_size.js +76 -0
  58. package/lib/functional/$proto_size.js.map +1 -0
  59. package/lib/functional/$proto_string.d.ts +2 -0
  60. package/lib/functional/$proto_string.js +34 -0
  61. package/lib/functional/$proto_string.js.map +1 -0
  62. package/lib/functional/$varint.d.ts +6 -0
  63. package/lib/functional/$varint.js +99 -0
  64. package/lib/functional/$varint.js.map +1 -0
  65. package/lib/functional/$zigzag.d.ts +4 -0
  66. package/lib/functional/$zigzag.js +34 -0
  67. package/lib/functional/$zigzag.js.map +1 -0
  68. package/lib/messages/IProtocolMessage.d.ts +5 -0
  69. package/lib/messages/IProtocolMessage.js +3 -0
  70. package/lib/messages/IProtocolMessage.js.map +1 -0
  71. package/lib/messages/IProtocolProperty.d.ts +11 -0
  72. package/lib/messages/IProtocolProperty.js +3 -0
  73. package/lib/messages/IProtocolProperty.js.map +1 -0
  74. package/lib/metadata/IMetadataTag.d.ts +7 -3
  75. package/lib/metadata/Metadata.js +1 -1
  76. package/lib/metadata/Metadata.js.map +1 -1
  77. package/lib/module.d.ts +2 -0
  78. package/lib/module.js +5 -1
  79. package/lib/module.js.map +1 -1
  80. package/lib/programmers/MessageProgrammer.d.ts +5 -0
  81. package/lib/programmers/MessageProgrammer.js +134 -0
  82. package/lib/programmers/MessageProgrammer.js.map +1 -0
  83. package/lib/programmers/internal/application_object.js +9 -9
  84. package/lib/programmers/internal/application_object.js.map +1 -1
  85. package/lib/programmers/internal/application_schema.js +5 -3
  86. package/lib/programmers/internal/application_schema.js.map +1 -1
  87. package/lib/transformers/CallExpressionTransformer.js +3 -1
  88. package/lib/transformers/CallExpressionTransformer.js.map +1 -1
  89. package/lib/transformers/features/miscellaneous/ApplicationTransformer.js +1 -3
  90. package/lib/transformers/features/miscellaneous/ApplicationTransformer.js.map +1 -1
  91. package/lib/transformers/features/protocols/MessageTransformer.d.ts +5 -0
  92. package/lib/transformers/features/protocols/MessageTransformer.js +17 -0
  93. package/lib/transformers/features/protocols/MessageTransformer.js.map +1 -0
  94. package/lib/utils/NameEncoder.d.ts +4 -0
  95. package/lib/utils/NameEncoder.js +89 -0
  96. package/lib/utils/NameEncoder.js.map +1 -0
  97. package/package.json +2 -3
  98. package/src/executable/internal/TypiaSetupWizard.ts +173 -173
  99. package/src/factories/MetadataCollection.ts +83 -122
  100. package/src/factories/MetadataFactory.ts +47 -47
  101. package/src/factories/MetadataTagFactory.ts +351 -351
  102. package/src/factories/ProtocolFactory.ts +92 -0
  103. package/src/factories/internal/metadata/MetadataHelper.ts +12 -12
  104. package/src/factories/internal/metadata/emplace_metadata_object.ts +140 -140
  105. package/src/factories/internal/metadata/explore_metadata.ts +92 -92
  106. package/src/factories/internal/metadata/iterate_metadata.ts +80 -80
  107. package/src/factories/internal/metadata/iterate_metadata_array.ts +29 -29
  108. package/src/factories/internal/metadata/iterate_metadata_atomic.ts +59 -59
  109. package/src/factories/internal/metadata/iterate_metadata_coalesce.ts +33 -33
  110. package/src/factories/internal/metadata/iterate_metadata_constant.ts +58 -58
  111. package/src/factories/internal/metadata/iterate_metadata_map.ts +41 -41
  112. package/src/factories/internal/metadata/iterate_metadata_native.ts +227 -227
  113. package/src/factories/internal/metadata/iterate_metadata_object.ts +48 -48
  114. package/src/factories/internal/metadata/iterate_metadata_resolve.ts +27 -27
  115. package/src/factories/internal/metadata/iterate_metadata_set.ts +33 -33
  116. package/src/factories/internal/metadata/iterate_metadata_template.ts +38 -38
  117. package/src/factories/internal/metadata/iterate_metadata_tuple.ts +45 -45
  118. package/src/factories/internal/metadata/iterate_metadata_union.ts +59 -59
  119. package/src/factories/internal/protocols/ProtocolMetadataUtil.ts +81 -0
  120. package/src/factories/internal/protocols/emplace_protocol_object.ts +25 -0
  121. package/src/factories/internal/protocols/emplace_protocol_property.ts +12 -0
  122. package/src/factories/internal/protocols/iterate_protocol_atomic.ts +34 -0
  123. package/src/factories/internal/protocols/iterate_protocol_constant.ts +27 -0
  124. package/src/factories/internal/protocols/iterate_protocol_main.ts +19 -0
  125. package/src/factories/internal/protocols/iterate_protocol_map.ts +38 -0
  126. package/src/factories/internal/protocols/iterate_protocol_metadata.ts +76 -0
  127. package/src/factories/internal/protocols/iterate_protocol_native.ts +34 -0
  128. package/src/factories/internal/protocols/iterate_protocol_repeated.ts +25 -0
  129. package/src/factories/internal/protocols/iterate_protocol_tuple.ts +25 -0
  130. package/src/functional/$number.ts +12 -12
  131. package/src/functional/$proto_bytes.ts +25 -0
  132. package/src/functional/$proto_field.ts +30 -0
  133. package/src/functional/$proto_float.ts +37 -0
  134. package/src/functional/$proto_i32.ts +29 -0
  135. package/src/functional/$proto_i64.ts +37 -0
  136. package/src/functional/$proto_size.ts +82 -0
  137. package/src/functional/$proto_string.ts +24 -0
  138. package/src/functional/$varint.ts +130 -0
  139. package/src/functional/$zigzag.ts +39 -0
  140. package/src/messages/IProtocolMessage.ts +6 -0
  141. package/src/messages/IProtocolProperty.ts +11 -0
  142. package/src/metadata/IMetadataTag.ts +137 -122
  143. package/src/metadata/Metadata.ts +479 -477
  144. package/src/module.ts +1547 -1535
  145. package/src/programmers/AssertParseProgrammer.ts +55 -55
  146. package/src/programmers/AssertProgrammer.ts +445 -445
  147. package/src/programmers/AssertStringifyProgrammer.ts +65 -65
  148. package/src/programmers/CheckerProgrammer.ts +810 -810
  149. package/src/programmers/IsParseProgrammer.ts +61 -61
  150. package/src/programmers/IsProgrammer.ts +175 -175
  151. package/src/programmers/IsStringifyProgrammer.ts +69 -69
  152. package/src/programmers/MessageProgrammer.ts +116 -0
  153. package/src/programmers/StringifyProgrammer.ts +762 -762
  154. package/src/programmers/ValidateParseProgrammer.ts +59 -59
  155. package/src/programmers/ValidateProgrammer.ts +237 -237
  156. package/src/programmers/ValidateStringifyProgrammer.ts +80 -80
  157. package/src/programmers/helpers/OptionPredicator.ts +15 -15
  158. package/src/programmers/internal/application_default.ts +17 -17
  159. package/src/programmers/internal/application_object.ts +5 -5
  160. package/src/programmers/internal/application_schema.ts +231 -228
  161. package/src/programmers/internal/check_bigint.ts +85 -85
  162. package/src/programmers/internal/check_number.ts +175 -175
  163. package/src/schemas/IJsonSchema.ts +90 -90
  164. package/src/transformers/CallExpressionTransformer.ts +131 -124
  165. package/src/transformers/ITransformOptions.ts +47 -47
  166. package/src/transformers/features/miscellaneous/ApplicationTransformer.ts +117 -119
  167. package/src/transformers/features/protocols/MessageTransformer.ts +32 -0
  168. package/src/transformers/features/stringifiers/StringifyTransformer.ts +46 -46
  169. package/src/utils/NameEncoder.ts +32 -0
@@ -1,59 +1,59 @@
1
- import ts from "typescript";
2
-
3
- import { IdentifierFactory } from "../factories/IdentifierFactory";
4
- import { StatementFactory } from "../factories/StatementFactory";
5
-
6
- import { IProject } from "../transformers/IProject";
7
-
8
- import { ValidateProgrammer } from "./ValidateProgrammer";
9
-
10
- export namespace ValidateParseProgrammer {
11
- export const generate =
12
- (project: IProject, modulo: ts.LeftHandSideExpression) =>
13
- (type: ts.Type) =>
14
- ts.factory.createArrowFunction(
15
- undefined,
16
- undefined,
17
- [IdentifierFactory.parameter("input")],
18
- undefined,
19
- undefined,
20
- ts.factory.createBlock([
21
- StatementFactory.constant(
22
- "validate",
23
- ValidateProgrammer.generate(
24
- {
25
- ...project,
26
- options: {
27
- ...project.options,
28
- functional: false,
29
- numeric: false,
30
- },
31
- },
32
- modulo,
33
- )(type),
34
- ),
35
- ts.factory.createExpressionStatement(
36
- ts.factory.createBinaryExpression(
37
- ts.factory.createIdentifier("input"),
38
- ts.SyntaxKind.EqualsToken,
39
- ts.factory.createCallExpression(
40
- ts.factory.createIdentifier("JSON.parse"),
41
- undefined,
42
- [ts.factory.createIdentifier("input")],
43
- ),
44
- ),
45
- ),
46
- StatementFactory.constant(
47
- "output",
48
- ts.factory.createCallExpression(
49
- ts.factory.createIdentifier("validate"),
50
- undefined,
51
- [ts.factory.createIdentifier("input")],
52
- ),
53
- ),
54
- ts.factory.createReturnStatement(
55
- ts.factory.createIdentifier("output"),
56
- ),
57
- ]),
58
- );
59
- }
1
+ import ts from "typescript";
2
+
3
+ import { IdentifierFactory } from "../factories/IdentifierFactory";
4
+ import { StatementFactory } from "../factories/StatementFactory";
5
+
6
+ import { IProject } from "../transformers/IProject";
7
+
8
+ import { ValidateProgrammer } from "./ValidateProgrammer";
9
+
10
+ export namespace ValidateParseProgrammer {
11
+ export const generate =
12
+ (project: IProject, modulo: ts.LeftHandSideExpression) =>
13
+ (type: ts.Type) =>
14
+ ts.factory.createArrowFunction(
15
+ undefined,
16
+ undefined,
17
+ [IdentifierFactory.parameter("input")],
18
+ undefined,
19
+ undefined,
20
+ ts.factory.createBlock([
21
+ StatementFactory.constant(
22
+ "validate",
23
+ ValidateProgrammer.generate(
24
+ {
25
+ ...project,
26
+ options: {
27
+ ...project.options,
28
+ functional: false,
29
+ numeric: false,
30
+ },
31
+ },
32
+ modulo,
33
+ )(type),
34
+ ),
35
+ ts.factory.createExpressionStatement(
36
+ ts.factory.createBinaryExpression(
37
+ ts.factory.createIdentifier("input"),
38
+ ts.SyntaxKind.EqualsToken,
39
+ ts.factory.createCallExpression(
40
+ ts.factory.createIdentifier("JSON.parse"),
41
+ undefined,
42
+ [ts.factory.createIdentifier("input")],
43
+ ),
44
+ ),
45
+ ),
46
+ StatementFactory.constant(
47
+ "output",
48
+ ts.factory.createCallExpression(
49
+ ts.factory.createIdentifier("validate"),
50
+ undefined,
51
+ [ts.factory.createIdentifier("input")],
52
+ ),
53
+ ),
54
+ ts.factory.createReturnStatement(
55
+ ts.factory.createIdentifier("output"),
56
+ ),
57
+ ]),
58
+ );
59
+ }
@@ -1,237 +1,237 @@
1
- import ts from "typescript";
2
-
3
- import { IdentifierFactory } from "../factories/IdentifierFactory";
4
- import { StatementFactory } from "../factories/StatementFactory";
5
-
6
- import { IProject } from "../transformers/IProject";
7
-
8
- import { CheckerProgrammer } from "./CheckerProgrammer";
9
- import { IsProgrammer } from "./IsProgrammer";
10
- import { FunctionImporter } from "./helpers/FunctionImporeter";
11
- import { OptionPredicator } from "./helpers/OptionPredicator";
12
- import { check_everything } from "./internal/check_everything";
13
- import { check_object } from "./internal/check_object";
14
-
15
- export namespace ValidateProgrammer {
16
- export const generate =
17
- (
18
- project: IProject,
19
- modulo: ts.LeftHandSideExpression,
20
- equals: boolean = false,
21
- ) =>
22
- (type: ts.Type) => {
23
- const importer: FunctionImporter = new FunctionImporter();
24
- const program: ts.ArrowFunction = CheckerProgrammer.generate(
25
- project,
26
- {
27
- functors: "$vo",
28
- unioners: "$vu",
29
- path: true,
30
- trace: true,
31
- numeric: OptionPredicator.numeric(project.options),
32
- equals,
33
- combiner: combine(equals)(importer),
34
- joiner: joiner(equals)(importer),
35
- success: ts.factory.createTrue(),
36
- },
37
- importer,
38
- )(type);
39
-
40
- return ts.factory.createArrowFunction(
41
- undefined,
42
- undefined,
43
- [IdentifierFactory.parameter("input")],
44
- undefined,
45
- undefined,
46
- ts.factory.createBlock(
47
- [
48
- StatementFactory.constant(
49
- "errors",
50
- ts.factory.createArrayLiteralExpression([]),
51
- ),
52
- StatementFactory.constant(
53
- "$report",
54
- ts.factory.createCallExpression(
55
- IdentifierFactory.join(modulo, "report"),
56
- [],
57
- [ts.factory.createIdentifier("errors")],
58
- ),
59
- ),
60
- ...importer.declare(modulo),
61
- ts.factory.createExpressionStatement(
62
- ts.factory.createCallExpression(
63
- program,
64
- undefined,
65
- [
66
- ts.factory.createIdentifier("input"),
67
- ts.factory.createStringLiteral("$input"),
68
- ts.factory.createTrue(),
69
- ],
70
- ),
71
- ),
72
- StatementFactory.constant(
73
- "success",
74
- ts.factory.createStrictEquality(
75
- ts.factory.createNumericLiteral(0),
76
- ts.factory.createIdentifier("errors.length"),
77
- ),
78
- ),
79
- ts.factory.createReturnStatement(create_output()),
80
- ],
81
- true,
82
- ),
83
- );
84
- };
85
- }
86
-
87
- const combine =
88
- (equals: boolean) =>
89
- (importer: FunctionImporter): CheckerProgrammer.IConfig.Combiner =>
90
- (explore: CheckerProgrammer.IExplore) => {
91
- if (explore.tracable === false && explore.from !== "top")
92
- return IsProgrammer.CONFIG({
93
- object: validate_object(equals)(importer),
94
- numeric: true,
95
- }).combiner(explore);
96
-
97
- const path: string = explore.postfix
98
- ? `path + ${explore.postfix}`
99
- : "path";
100
- return (logic) => (input, binaries, expected) =>
101
- logic === "and"
102
- ? binaries
103
- .map((binary) =>
104
- binary.combined
105
- ? binary.expression
106
- : ts.factory.createLogicalOr(
107
- binary.expression,
108
- create_report_call(
109
- explore.source === "top"
110
- ? ts.factory.createTrue()
111
- : ts.factory.createIdentifier(
112
- "exceptionable",
113
- ),
114
- )(
115
- ts.factory.createIdentifier(path),
116
- expected,
117
- input,
118
- ),
119
- ),
120
- )
121
- .reduce(ts.factory.createLogicalAnd)
122
- : ts.factory.createLogicalOr(
123
- binaries
124
- .map((binary) => binary.expression)
125
- .reduce(ts.factory.createLogicalOr),
126
- create_report_call(
127
- explore.source === "top"
128
- ? ts.factory.createTrue()
129
- : ts.factory.createIdentifier("exceptionable"),
130
- )(ts.factory.createIdentifier(path), expected, input),
131
- );
132
- };
133
-
134
- const validate_object = (equals: boolean) => (importer: FunctionImporter) =>
135
- check_object({
136
- equals,
137
- assert: false,
138
- reduce: ts.factory.createLogicalAnd,
139
- positive: ts.factory.createTrue(),
140
- superfluous: (value) =>
141
- create_report_call()(
142
- ts.factory.createAdd(
143
- ts.factory.createIdentifier("path"),
144
- ts.factory.createCallExpression(
145
- importer.use("join"),
146
- undefined,
147
- [ts.factory.createIdentifier("key")],
148
- ),
149
- ),
150
- "undefined",
151
- value,
152
- ),
153
- halt: (expr) =>
154
- ts.factory.createLogicalOr(
155
- ts.factory.createStrictEquality(
156
- ts.factory.createFalse(),
157
- ts.factory.createIdentifier("exceptionable"),
158
- ),
159
- expr,
160
- ),
161
- });
162
-
163
- const joiner =
164
- (equals: boolean) =>
165
- (importer: FunctionImporter): CheckerProgrammer.IConfig.IJoiner => ({
166
- object: validate_object(equals)(importer),
167
- array: (input, arrow) =>
168
- check_everything(
169
- ts.factory.createCallExpression(
170
- IdentifierFactory.join(input, "map"),
171
- undefined,
172
- [arrow],
173
- ),
174
- ),
175
- failure: (value, expected, explore) =>
176
- create_report_call(
177
- explore?.from === "top"
178
- ? ts.factory.createTrue()
179
- : ts.factory.createIdentifier("exceptionable"),
180
- )(
181
- ts.factory.createIdentifier(
182
- explore?.postfix ? `path + ${explore.postfix}` : "path",
183
- ),
184
- expected,
185
- value,
186
- ),
187
- tuple: (binaries) =>
188
- check_everything(
189
- ts.factory.createArrayLiteralExpression(binaries, true),
190
- ),
191
- });
192
-
193
- function create_output() {
194
- return ts.factory.createObjectLiteralExpression(
195
- [
196
- ts.factory.createShorthandPropertyAssignment("success"),
197
- ts.factory.createShorthandPropertyAssignment("errors"),
198
- ts.factory.createPropertyAssignment(
199
- "data",
200
- ts.factory.createConditionalExpression(
201
- ts.factory.createIdentifier("success"),
202
- undefined,
203
- ts.factory.createIdentifier("input"),
204
- undefined,
205
- ts.factory.createIdentifier("undefined"),
206
- ),
207
- ),
208
- ],
209
- true,
210
- );
211
- }
212
-
213
- const create_report_call =
214
- (exceptionable?: ts.Expression) =>
215
- (
216
- path: ts.Expression,
217
- expected: string,
218
- value: ts.Expression,
219
- ): ts.Expression =>
220
- ts.factory.createCallExpression(
221
- ts.factory.createIdentifier("$report"),
222
- undefined,
223
- [
224
- exceptionable || ts.factory.createIdentifier("exceptionable"),
225
- ts.factory.createObjectLiteralExpression(
226
- [
227
- ts.factory.createPropertyAssignment("path", path),
228
- ts.factory.createPropertyAssignment(
229
- "expected",
230
- ts.factory.createStringLiteral(expected),
231
- ),
232
- ts.factory.createPropertyAssignment("value", value),
233
- ],
234
- true,
235
- ),
236
- ],
237
- );
1
+ import ts from "typescript";
2
+
3
+ import { IdentifierFactory } from "../factories/IdentifierFactory";
4
+ import { StatementFactory } from "../factories/StatementFactory";
5
+
6
+ import { IProject } from "../transformers/IProject";
7
+
8
+ import { CheckerProgrammer } from "./CheckerProgrammer";
9
+ import { IsProgrammer } from "./IsProgrammer";
10
+ import { FunctionImporter } from "./helpers/FunctionImporeter";
11
+ import { OptionPredicator } from "./helpers/OptionPredicator";
12
+ import { check_everything } from "./internal/check_everything";
13
+ import { check_object } from "./internal/check_object";
14
+
15
+ export namespace ValidateProgrammer {
16
+ export const generate =
17
+ (
18
+ project: IProject,
19
+ modulo: ts.LeftHandSideExpression,
20
+ equals: boolean = false,
21
+ ) =>
22
+ (type: ts.Type) => {
23
+ const importer: FunctionImporter = new FunctionImporter();
24
+ const program: ts.ArrowFunction = CheckerProgrammer.generate(
25
+ project,
26
+ {
27
+ functors: "$vo",
28
+ unioners: "$vu",
29
+ path: true,
30
+ trace: true,
31
+ numeric: OptionPredicator.numeric(project.options),
32
+ equals,
33
+ combiner: combine(equals)(importer),
34
+ joiner: joiner(equals)(importer),
35
+ success: ts.factory.createTrue(),
36
+ },
37
+ importer,
38
+ )(type);
39
+
40
+ return ts.factory.createArrowFunction(
41
+ undefined,
42
+ undefined,
43
+ [IdentifierFactory.parameter("input")],
44
+ undefined,
45
+ undefined,
46
+ ts.factory.createBlock(
47
+ [
48
+ StatementFactory.constant(
49
+ "errors",
50
+ ts.factory.createArrayLiteralExpression([]),
51
+ ),
52
+ StatementFactory.constant(
53
+ "$report",
54
+ ts.factory.createCallExpression(
55
+ IdentifierFactory.join(modulo, "report"),
56
+ [],
57
+ [ts.factory.createIdentifier("errors")],
58
+ ),
59
+ ),
60
+ ...importer.declare(modulo),
61
+ ts.factory.createExpressionStatement(
62
+ ts.factory.createCallExpression(
63
+ program,
64
+ undefined,
65
+ [
66
+ ts.factory.createIdentifier("input"),
67
+ ts.factory.createStringLiteral("$input"),
68
+ ts.factory.createTrue(),
69
+ ],
70
+ ),
71
+ ),
72
+ StatementFactory.constant(
73
+ "success",
74
+ ts.factory.createStrictEquality(
75
+ ts.factory.createNumericLiteral(0),
76
+ ts.factory.createIdentifier("errors.length"),
77
+ ),
78
+ ),
79
+ ts.factory.createReturnStatement(create_output()),
80
+ ],
81
+ true,
82
+ ),
83
+ );
84
+ };
85
+ }
86
+
87
+ const combine =
88
+ (equals: boolean) =>
89
+ (importer: FunctionImporter): CheckerProgrammer.IConfig.Combiner =>
90
+ (explore: CheckerProgrammer.IExplore) => {
91
+ if (explore.tracable === false && explore.from !== "top")
92
+ return IsProgrammer.CONFIG({
93
+ object: validate_object(equals)(importer),
94
+ numeric: true,
95
+ }).combiner(explore);
96
+
97
+ const path: string = explore.postfix
98
+ ? `path + ${explore.postfix}`
99
+ : "path";
100
+ return (logic) => (input, binaries, expected) =>
101
+ logic === "and"
102
+ ? binaries
103
+ .map((binary) =>
104
+ binary.combined
105
+ ? binary.expression
106
+ : ts.factory.createLogicalOr(
107
+ binary.expression,
108
+ create_report_call(
109
+ explore.source === "top"
110
+ ? ts.factory.createTrue()
111
+ : ts.factory.createIdentifier(
112
+ "exceptionable",
113
+ ),
114
+ )(
115
+ ts.factory.createIdentifier(path),
116
+ expected,
117
+ input,
118
+ ),
119
+ ),
120
+ )
121
+ .reduce(ts.factory.createLogicalAnd)
122
+ : ts.factory.createLogicalOr(
123
+ binaries
124
+ .map((binary) => binary.expression)
125
+ .reduce(ts.factory.createLogicalOr),
126
+ create_report_call(
127
+ explore.source === "top"
128
+ ? ts.factory.createTrue()
129
+ : ts.factory.createIdentifier("exceptionable"),
130
+ )(ts.factory.createIdentifier(path), expected, input),
131
+ );
132
+ };
133
+
134
+ const validate_object = (equals: boolean) => (importer: FunctionImporter) =>
135
+ check_object({
136
+ equals,
137
+ assert: false,
138
+ reduce: ts.factory.createLogicalAnd,
139
+ positive: ts.factory.createTrue(),
140
+ superfluous: (value) =>
141
+ create_report_call()(
142
+ ts.factory.createAdd(
143
+ ts.factory.createIdentifier("path"),
144
+ ts.factory.createCallExpression(
145
+ importer.use("join"),
146
+ undefined,
147
+ [ts.factory.createIdentifier("key")],
148
+ ),
149
+ ),
150
+ "undefined",
151
+ value,
152
+ ),
153
+ halt: (expr) =>
154
+ ts.factory.createLogicalOr(
155
+ ts.factory.createStrictEquality(
156
+ ts.factory.createFalse(),
157
+ ts.factory.createIdentifier("exceptionable"),
158
+ ),
159
+ expr,
160
+ ),
161
+ });
162
+
163
+ const joiner =
164
+ (equals: boolean) =>
165
+ (importer: FunctionImporter): CheckerProgrammer.IConfig.IJoiner => ({
166
+ object: validate_object(equals)(importer),
167
+ array: (input, arrow) =>
168
+ check_everything(
169
+ ts.factory.createCallExpression(
170
+ IdentifierFactory.join(input, "map"),
171
+ undefined,
172
+ [arrow],
173
+ ),
174
+ ),
175
+ failure: (value, expected, explore) =>
176
+ create_report_call(
177
+ explore?.from === "top"
178
+ ? ts.factory.createTrue()
179
+ : ts.factory.createIdentifier("exceptionable"),
180
+ )(
181
+ ts.factory.createIdentifier(
182
+ explore?.postfix ? `path + ${explore.postfix}` : "path",
183
+ ),
184
+ expected,
185
+ value,
186
+ ),
187
+ tuple: (binaries) =>
188
+ check_everything(
189
+ ts.factory.createArrayLiteralExpression(binaries, true),
190
+ ),
191
+ });
192
+
193
+ function create_output() {
194
+ return ts.factory.createObjectLiteralExpression(
195
+ [
196
+ ts.factory.createShorthandPropertyAssignment("success"),
197
+ ts.factory.createShorthandPropertyAssignment("errors"),
198
+ ts.factory.createPropertyAssignment(
199
+ "data",
200
+ ts.factory.createConditionalExpression(
201
+ ts.factory.createIdentifier("success"),
202
+ undefined,
203
+ ts.factory.createIdentifier("input"),
204
+ undefined,
205
+ ts.factory.createIdentifier("undefined"),
206
+ ),
207
+ ),
208
+ ],
209
+ true,
210
+ );
211
+ }
212
+
213
+ const create_report_call =
214
+ (exceptionable?: ts.Expression) =>
215
+ (
216
+ path: ts.Expression,
217
+ expected: string,
218
+ value: ts.Expression,
219
+ ): ts.Expression =>
220
+ ts.factory.createCallExpression(
221
+ ts.factory.createIdentifier("$report"),
222
+ undefined,
223
+ [
224
+ exceptionable || ts.factory.createIdentifier("exceptionable"),
225
+ ts.factory.createObjectLiteralExpression(
226
+ [
227
+ ts.factory.createPropertyAssignment("path", path),
228
+ ts.factory.createPropertyAssignment(
229
+ "expected",
230
+ ts.factory.createStringLiteral(expected),
231
+ ),
232
+ ts.factory.createPropertyAssignment("value", value),
233
+ ],
234
+ true,
235
+ ),
236
+ ],
237
+ );