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,445 +1,445 @@
1
- import ts from "typescript";
2
-
3
- import { IdentifierFactory } from "../factories/IdentifierFactory";
4
-
5
- // import { StatementFactory } from "../factories/StatementFactory";
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_object } from "./internal/check_object";
13
-
14
- // /* -----------------------------------------------------------
15
- // ASSERT V2 -> USE (NULL OR ERROR) CONDITION
16
- // ----------------------------------------------------------- */
17
- // export namespace AssertProgrammerV2 {
18
- // export const generate =
19
- // (
20
- // project: IProject,
21
- // modulo: ts.LeftHandSideExpression,
22
- // equals: boolean = false,
23
- // ) =>
24
- // (type: ts.Type) => {
25
- // const importer: FunctionImporter = new FunctionImporter();
26
- // const guardV2: ts.Expression = importer.use("guardV2");
27
-
28
- // const program: ts.ArrowFunction = CheckerProgrammer.generate(
29
- // project,
30
- // {
31
- // functors: "$ao",
32
- // unioners: "$au",
33
- // path: true,
34
- // trace: true,
35
- // numeric: OptionPredicator.numeric(project.options),
36
- // equals,
37
- // combiner,
38
- // joiner: joiner(equals)(importer),
39
- // success: ts.factory.createNull(),
40
- // },
41
- // importer,
42
- // )(type);
43
-
44
- // return ts.factory.createArrowFunction(
45
- // undefined,
46
- // undefined,
47
- // [IdentifierFactory.parameter("input")],
48
- // undefined,
49
- // undefined,
50
- // ts.factory.createBlock(
51
- // [
52
- // ...importer.declare(modulo),
53
- // StatementFactory.constant(
54
- // "error",
55
- // ts.factory.createCallExpression(
56
- // program,
57
- // undefined,
58
- // [
59
- // ValueFactory.INPUT(),
60
- // ts.factory.createStringLiteral("$input"),
61
- // ],
62
- // ),
63
- // ),
64
- // ts.factory.createIfStatement(
65
- // ts.factory.createStrictInequality(
66
- // ts.factory.createNull(),
67
- // ts.factory.createIdentifier("error"),
68
- // ),
69
- // ts.factory.createThrowStatement(
70
- // ts.factory.createCallExpression(
71
- // guardV2,
72
- // undefined,
73
- // [ts.factory.createIdentifier("error")],
74
- // ),
75
- // ),
76
- // ),
77
- // ts.factory.createReturnStatement(ValueFactory.INPUT()),
78
- // ],
79
- // true,
80
- // ),
81
- // );
82
- // };
83
-
84
- // const combiner: CheckerProgrammer.IConfig.Combiner = (
85
- // explore: CheckerProgrammer.IExplore,
86
- // ) => {
87
- // const path: string = explore.postfix
88
- // ? `path + ${explore.postfix}`
89
- // : "path";
90
- // return (logic) => (input, binaries, expected) =>
91
- // binaries
92
- // .map((binary) =>
93
- // binary.combined
94
- // ? binary.expression
95
- // : ts.factory.createParenthesizedExpression(
96
- // ts.factory.createConditionalExpression(
97
- // binary.expression,
98
- // undefined,
99
- // ts.factory.createNull(),
100
- // undefined,
101
- // create_exception_props(
102
- // ts.factory.createIdentifier(path),
103
- // expected,
104
- // input,
105
- // ),
106
- // ),
107
- // ),
108
- // )
109
- // .reduce(
110
- // logic === "and"
111
- // ? ts.factory.createLogicalOr
112
- // : ts.factory.createLogicalAnd,
113
- // );
114
- // };
115
-
116
- // const assert_object = (equals: boolean) => (importer: FunctionImporter) =>
117
- // check_object({
118
- // equals,
119
- // assert: true,
120
- // reduce: ts.factory.createLogicalOr,
121
- // positive: ts.factory.createNull(),
122
- // superfluous: (value) =>
123
- // create_exception_props(
124
- // ts.factory.createAdd(
125
- // ts.factory.createIdentifier("path"),
126
- // ts.factory.createCallExpression(
127
- // importer.use("join"),
128
- // undefined,
129
- // [ts.factory.createIdentifier("key")],
130
- // ),
131
- // ),
132
- // "undefined",
133
- // value,
134
- // ),
135
- // entries: importer.use("every"),
136
- // halt: (expr) =>
137
- // ts.factory.createConditionalExpression(
138
- // ts.factory.createStrictEquality(
139
- // ts.factory.createFalse(),
140
- // ts.factory.createIdentifier("exceptionable"),
141
- // ),
142
- // undefined,
143
- // ts.factory.createNull(),
144
- // undefined,
145
- // expr,
146
- // ),
147
- // });
148
-
149
- // const joiner =
150
- // (equals: boolean) =>
151
- // (importer: FunctionImporter): CheckerProgrammer.IConfig.IJoiner => ({
152
- // object: assert_object(equals)(importer),
153
- // array: (input, arrow) =>
154
- // ts.factory.createCallExpression(
155
- // importer.use("every"),
156
- // undefined,
157
- // [input, arrow],
158
- // ),
159
- // failure: (value, expected, explore) =>
160
- // create_exception_props(
161
- // ts.factory.createIdentifier(
162
- // explore?.postfix ? `path + ${explore.postfix}` : "path",
163
- // ),
164
- // expected,
165
- // value,
166
- // ),
167
- // is: (exp) =>
168
- // ts.factory.createStrictEquality(
169
- // ts.factory.createNull(),
170
- // ts.factory.createParenthesizedExpression(exp),
171
- // ),
172
- // required: (value) =>
173
- // ts.factory.createConditionalExpression(
174
- // value,
175
- // undefined,
176
- // ts.factory.createNull(),
177
- // undefined,
178
- // create_exception_props(
179
- // ts.factory.createStringLiteral(""),
180
- // "not undefined",
181
- // value,
182
- // ),
183
- // ),
184
- // full: equals
185
- // ? undefined
186
- // : (condition) => (input, expected) =>
187
- // ts.factory.createConditionalExpression(
188
- // ts.factory.createStrictEquality(
189
- // ts.factory.createNull(),
190
- // condition,
191
- // ),
192
- // undefined,
193
- // ts.factory.createNull(),
194
- // undefined,
195
- // create_exception_props(
196
- // ts.factory.createIdentifier("path"),
197
- // expected,
198
- // input,
199
- // ),
200
- // ),
201
- // });
202
-
203
- // function create_exception_props(
204
- // path: ts.Expression,
205
- // expected: string,
206
- // value: ts.Expression,
207
- // ): ts.ObjectLiteralExpression {
208
- // return ts.factory.createObjectLiteralExpression(
209
- // [
210
- // ts.factory.createPropertyAssignment("path", path),
211
- // ts.factory.createPropertyAssignment(
212
- // "expected",
213
- // ts.factory.createStringLiteral(expected),
214
- // ),
215
- // ts.factory.createPropertyAssignment("value", value),
216
- // ],
217
- // true,
218
- // );
219
- // }
220
- // }
221
-
222
- /* -----------------------------------------------------------
223
- ASSERT V3 -> (CONDITION OR THROW(exceptable): FALSE)
224
- ----------------------------------------------------------- */
225
- export namespace AssertProgrammer {
226
- export const generate =
227
- (
228
- project: IProject,
229
- modulo: ts.LeftHandSideExpression,
230
- equals: boolean = false,
231
- ) =>
232
- (type: ts.Type) => {
233
- const importer: FunctionImporter = new FunctionImporter();
234
- const program: ts.ArrowFunction = CheckerProgrammer.generate(
235
- project,
236
- {
237
- functors: "$ao",
238
- unioners: "$au",
239
- path: true,
240
- trace: true,
241
- numeric: OptionPredicator.numeric(project.options),
242
- equals,
243
- combiner: combiner(equals)(importer),
244
- joiner: joiner(equals)(importer),
245
- success: ts.factory.createTrue(),
246
- },
247
- importer,
248
- )(type);
249
-
250
- return ts.factory.createArrowFunction(
251
- undefined,
252
- undefined,
253
- [IdentifierFactory.parameter("input")],
254
- undefined,
255
- undefined,
256
- ts.factory.createBlock(
257
- [
258
- ...importer.declare(modulo),
259
- ts.factory.createExpressionStatement(
260
- ts.factory.createCallExpression(
261
- program,
262
- undefined,
263
- [
264
- ts.factory.createIdentifier("input"),
265
- ts.factory.createStringLiteral("$input"),
266
- ts.factory.createTrue(),
267
- ],
268
- ),
269
- ),
270
- ts.factory.createReturnStatement(
271
- ts.factory.createIdentifier("input"),
272
- ),
273
- ],
274
- true,
275
- ),
276
- );
277
- };
278
-
279
- const combiner =
280
- (equals: boolean) =>
281
- (importer: FunctionImporter): CheckerProgrammer.IConfig.Combiner =>
282
- (explore: CheckerProgrammer.IExplore) => {
283
- if (explore.tracable === false && explore.from !== "top")
284
- return IsProgrammer.CONFIG({
285
- object: assert_object(equals)(importer),
286
- numeric: true,
287
- }).combiner(explore);
288
-
289
- const path: string = explore.postfix
290
- ? `path + ${explore.postfix}`
291
- : "path";
292
- return (logic) => (input, binaries, expected) =>
293
- logic === "and"
294
- ? binaries
295
- .map((binary) =>
296
- binary.combined
297
- ? binary.expression
298
- : ts.factory.createLogicalOr(
299
- binary.expression,
300
- create_guard_call(importer)(
301
- explore.source === "top"
302
- ? ts.factory.createTrue()
303
- : ts.factory.createIdentifier(
304
- "exceptionable",
305
- ),
306
- )(
307
- ts.factory.createIdentifier(path),
308
- expected,
309
- input,
310
- ),
311
- ),
312
- )
313
- .reduce(ts.factory.createLogicalAnd)
314
- : (() => {
315
- const addicted = binaries.slice();
316
- if (
317
- addicted[addicted.length - 1]!.combined === false
318
- ) {
319
- addicted.push({
320
- combined: true,
321
- expression: create_guard_call(importer)(
322
- explore.source === "top"
323
- ? ts.factory.createTrue()
324
- : ts.factory.createIdentifier(
325
- "exceptionable",
326
- ),
327
- )(
328
- ts.factory.createIdentifier(path),
329
- expected,
330
- input,
331
- ),
332
- });
333
- }
334
- return addicted
335
- .map((b) => b.expression)
336
- .reduce(ts.factory.createLogicalOr);
337
- })();
338
-
339
- // ts.factory.createLogicalOr(
340
- // binaries
341
- // .map((binary) => binary.expression)
342
- // .reduce(ts.factory.createLogicalOr),
343
- // create_guard_call(importer)(
344
- // explore.source === "top"
345
- // ? ts.factory.createTrue()
346
- // : ts.factory.createIdentifier(
347
- // "exceptionable",
348
- // ),
349
- // )(ts.factory.createIdentifier(path), expected, input),
350
- // );
351
- };
352
-
353
- const assert_object = (equals: boolean) => (importer: FunctionImporter) =>
354
- check_object({
355
- equals,
356
- assert: true,
357
- reduce: ts.factory.createLogicalAnd,
358
- positive: ts.factory.createTrue(),
359
- superfluous: (value) =>
360
- create_guard_call(importer)()(
361
- ts.factory.createAdd(
362
- ts.factory.createIdentifier("path"),
363
- ts.factory.createCallExpression(
364
- importer.use("join"),
365
- undefined,
366
- [ts.factory.createIdentifier("key")],
367
- ),
368
- ),
369
- "undefined",
370
- value,
371
- ),
372
- halt: (expr) =>
373
- ts.factory.createLogicalOr(
374
- ts.factory.createStrictEquality(
375
- ts.factory.createFalse(),
376
- ts.factory.createIdentifier("exceptionable"),
377
- ),
378
- expr,
379
- ),
380
- });
381
-
382
- const joiner =
383
- (equals: boolean) =>
384
- (importer: FunctionImporter): CheckerProgrammer.IConfig.IJoiner => ({
385
- object: assert_object(equals)(importer),
386
- array: (input, arrow) =>
387
- ts.factory.createCallExpression(
388
- IdentifierFactory.join(input, "every"),
389
- undefined,
390
- [arrow],
391
- ),
392
- failure: (value, expected, explore) =>
393
- create_guard_call(importer)(
394
- explore?.from === "top"
395
- ? ts.factory.createTrue()
396
- : ts.factory.createIdentifier("exceptionable"),
397
- )(
398
- ts.factory.createIdentifier(
399
- explore?.postfix ? `path + ${explore.postfix}` : "path",
400
- ),
401
- expected,
402
- value,
403
- ),
404
- full: equals
405
- ? undefined
406
- : (condition) => (input, expected, explore) =>
407
- ts.factory.createLogicalOr(
408
- condition,
409
- create_guard_call(importer)(
410
- explore.from === "top"
411
- ? ts.factory.createTrue()
412
- : ts.factory.createIdentifier(
413
- "exceptionable",
414
- ),
415
- )(
416
- ts.factory.createIdentifier("path"),
417
- expected,
418
- input,
419
- ),
420
- ),
421
- });
422
-
423
- const create_guard_call =
424
- (importer: FunctionImporter) =>
425
- (exceptionable?: ts.Expression) =>
426
- (
427
- path: ts.Expression,
428
- expected: string,
429
- value: ts.Expression,
430
- ): ts.Expression =>
431
- ts.factory.createCallExpression(importer.use("guard"), undefined, [
432
- exceptionable || ts.factory.createIdentifier("exceptionable"),
433
- ts.factory.createObjectLiteralExpression(
434
- [
435
- ts.factory.createPropertyAssignment("path", path),
436
- ts.factory.createPropertyAssignment(
437
- "expected",
438
- ts.factory.createStringLiteral(expected),
439
- ),
440
- ts.factory.createPropertyAssignment("value", value),
441
- ],
442
- true,
443
- ),
444
- ]);
445
- }
1
+ import ts from "typescript";
2
+
3
+ import { IdentifierFactory } from "../factories/IdentifierFactory";
4
+
5
+ // import { StatementFactory } from "../factories/StatementFactory";
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_object } from "./internal/check_object";
13
+
14
+ // /* -----------------------------------------------------------
15
+ // ASSERT V2 -> USE (NULL OR ERROR) CONDITION
16
+ // ----------------------------------------------------------- */
17
+ // export namespace AssertProgrammerV2 {
18
+ // export const generate =
19
+ // (
20
+ // project: IProject,
21
+ // modulo: ts.LeftHandSideExpression,
22
+ // equals: boolean = false,
23
+ // ) =>
24
+ // (type: ts.Type) => {
25
+ // const importer: FunctionImporter = new FunctionImporter();
26
+ // const guardV2: ts.Expression = importer.use("guardV2");
27
+
28
+ // const program: ts.ArrowFunction = CheckerProgrammer.generate(
29
+ // project,
30
+ // {
31
+ // functors: "$ao",
32
+ // unioners: "$au",
33
+ // path: true,
34
+ // trace: true,
35
+ // numeric: OptionPredicator.numeric(project.options),
36
+ // equals,
37
+ // combiner,
38
+ // joiner: joiner(equals)(importer),
39
+ // success: ts.factory.createNull(),
40
+ // },
41
+ // importer,
42
+ // )(type);
43
+
44
+ // return ts.factory.createArrowFunction(
45
+ // undefined,
46
+ // undefined,
47
+ // [IdentifierFactory.parameter("input")],
48
+ // undefined,
49
+ // undefined,
50
+ // ts.factory.createBlock(
51
+ // [
52
+ // ...importer.declare(modulo),
53
+ // StatementFactory.constant(
54
+ // "error",
55
+ // ts.factory.createCallExpression(
56
+ // program,
57
+ // undefined,
58
+ // [
59
+ // ValueFactory.INPUT(),
60
+ // ts.factory.createStringLiteral("$input"),
61
+ // ],
62
+ // ),
63
+ // ),
64
+ // ts.factory.createIfStatement(
65
+ // ts.factory.createStrictInequality(
66
+ // ts.factory.createNull(),
67
+ // ts.factory.createIdentifier("error"),
68
+ // ),
69
+ // ts.factory.createThrowStatement(
70
+ // ts.factory.createCallExpression(
71
+ // guardV2,
72
+ // undefined,
73
+ // [ts.factory.createIdentifier("error")],
74
+ // ),
75
+ // ),
76
+ // ),
77
+ // ts.factory.createReturnStatement(ValueFactory.INPUT()),
78
+ // ],
79
+ // true,
80
+ // ),
81
+ // );
82
+ // };
83
+
84
+ // const combiner: CheckerProgrammer.IConfig.Combiner = (
85
+ // explore: CheckerProgrammer.IExplore,
86
+ // ) => {
87
+ // const path: string = explore.postfix
88
+ // ? `path + ${explore.postfix}`
89
+ // : "path";
90
+ // return (logic) => (input, binaries, expected) =>
91
+ // binaries
92
+ // .map((binary) =>
93
+ // binary.combined
94
+ // ? binary.expression
95
+ // : ts.factory.createParenthesizedExpression(
96
+ // ts.factory.createConditionalExpression(
97
+ // binary.expression,
98
+ // undefined,
99
+ // ts.factory.createNull(),
100
+ // undefined,
101
+ // create_exception_props(
102
+ // ts.factory.createIdentifier(path),
103
+ // expected,
104
+ // input,
105
+ // ),
106
+ // ),
107
+ // ),
108
+ // )
109
+ // .reduce(
110
+ // logic === "and"
111
+ // ? ts.factory.createLogicalOr
112
+ // : ts.factory.createLogicalAnd,
113
+ // );
114
+ // };
115
+
116
+ // const assert_object = (equals: boolean) => (importer: FunctionImporter) =>
117
+ // check_object({
118
+ // equals,
119
+ // assert: true,
120
+ // reduce: ts.factory.createLogicalOr,
121
+ // positive: ts.factory.createNull(),
122
+ // superfluous: (value) =>
123
+ // create_exception_props(
124
+ // ts.factory.createAdd(
125
+ // ts.factory.createIdentifier("path"),
126
+ // ts.factory.createCallExpression(
127
+ // importer.use("join"),
128
+ // undefined,
129
+ // [ts.factory.createIdentifier("key")],
130
+ // ),
131
+ // ),
132
+ // "undefined",
133
+ // value,
134
+ // ),
135
+ // entries: importer.use("every"),
136
+ // halt: (expr) =>
137
+ // ts.factory.createConditionalExpression(
138
+ // ts.factory.createStrictEquality(
139
+ // ts.factory.createFalse(),
140
+ // ts.factory.createIdentifier("exceptionable"),
141
+ // ),
142
+ // undefined,
143
+ // ts.factory.createNull(),
144
+ // undefined,
145
+ // expr,
146
+ // ),
147
+ // });
148
+
149
+ // const joiner =
150
+ // (equals: boolean) =>
151
+ // (importer: FunctionImporter): CheckerProgrammer.IConfig.IJoiner => ({
152
+ // object: assert_object(equals)(importer),
153
+ // array: (input, arrow) =>
154
+ // ts.factory.createCallExpression(
155
+ // importer.use("every"),
156
+ // undefined,
157
+ // [input, arrow],
158
+ // ),
159
+ // failure: (value, expected, explore) =>
160
+ // create_exception_props(
161
+ // ts.factory.createIdentifier(
162
+ // explore?.postfix ? `path + ${explore.postfix}` : "path",
163
+ // ),
164
+ // expected,
165
+ // value,
166
+ // ),
167
+ // is: (exp) =>
168
+ // ts.factory.createStrictEquality(
169
+ // ts.factory.createNull(),
170
+ // ts.factory.createParenthesizedExpression(exp),
171
+ // ),
172
+ // required: (value) =>
173
+ // ts.factory.createConditionalExpression(
174
+ // value,
175
+ // undefined,
176
+ // ts.factory.createNull(),
177
+ // undefined,
178
+ // create_exception_props(
179
+ // ts.factory.createStringLiteral(""),
180
+ // "not undefined",
181
+ // value,
182
+ // ),
183
+ // ),
184
+ // full: equals
185
+ // ? undefined
186
+ // : (condition) => (input, expected) =>
187
+ // ts.factory.createConditionalExpression(
188
+ // ts.factory.createStrictEquality(
189
+ // ts.factory.createNull(),
190
+ // condition,
191
+ // ),
192
+ // undefined,
193
+ // ts.factory.createNull(),
194
+ // undefined,
195
+ // create_exception_props(
196
+ // ts.factory.createIdentifier("path"),
197
+ // expected,
198
+ // input,
199
+ // ),
200
+ // ),
201
+ // });
202
+
203
+ // function create_exception_props(
204
+ // path: ts.Expression,
205
+ // expected: string,
206
+ // value: ts.Expression,
207
+ // ): ts.ObjectLiteralExpression {
208
+ // return ts.factory.createObjectLiteralExpression(
209
+ // [
210
+ // ts.factory.createPropertyAssignment("path", path),
211
+ // ts.factory.createPropertyAssignment(
212
+ // "expected",
213
+ // ts.factory.createStringLiteral(expected),
214
+ // ),
215
+ // ts.factory.createPropertyAssignment("value", value),
216
+ // ],
217
+ // true,
218
+ // );
219
+ // }
220
+ // }
221
+
222
+ /* -----------------------------------------------------------
223
+ ASSERT V3 -> (CONDITION OR THROW(exceptable): FALSE)
224
+ ----------------------------------------------------------- */
225
+ export namespace AssertProgrammer {
226
+ export const generate =
227
+ (
228
+ project: IProject,
229
+ modulo: ts.LeftHandSideExpression,
230
+ equals: boolean = false,
231
+ ) =>
232
+ (type: ts.Type) => {
233
+ const importer: FunctionImporter = new FunctionImporter();
234
+ const program: ts.ArrowFunction = CheckerProgrammer.generate(
235
+ project,
236
+ {
237
+ functors: "$ao",
238
+ unioners: "$au",
239
+ path: true,
240
+ trace: true,
241
+ numeric: OptionPredicator.numeric(project.options),
242
+ equals,
243
+ combiner: combiner(equals)(importer),
244
+ joiner: joiner(equals)(importer),
245
+ success: ts.factory.createTrue(),
246
+ },
247
+ importer,
248
+ )(type);
249
+
250
+ return ts.factory.createArrowFunction(
251
+ undefined,
252
+ undefined,
253
+ [IdentifierFactory.parameter("input")],
254
+ undefined,
255
+ undefined,
256
+ ts.factory.createBlock(
257
+ [
258
+ ...importer.declare(modulo),
259
+ ts.factory.createExpressionStatement(
260
+ ts.factory.createCallExpression(
261
+ program,
262
+ undefined,
263
+ [
264
+ ts.factory.createIdentifier("input"),
265
+ ts.factory.createStringLiteral("$input"),
266
+ ts.factory.createTrue(),
267
+ ],
268
+ ),
269
+ ),
270
+ ts.factory.createReturnStatement(
271
+ ts.factory.createIdentifier("input"),
272
+ ),
273
+ ],
274
+ true,
275
+ ),
276
+ );
277
+ };
278
+
279
+ const combiner =
280
+ (equals: boolean) =>
281
+ (importer: FunctionImporter): CheckerProgrammer.IConfig.Combiner =>
282
+ (explore: CheckerProgrammer.IExplore) => {
283
+ if (explore.tracable === false && explore.from !== "top")
284
+ return IsProgrammer.CONFIG({
285
+ object: assert_object(equals)(importer),
286
+ numeric: true,
287
+ }).combiner(explore);
288
+
289
+ const path: string = explore.postfix
290
+ ? `path + ${explore.postfix}`
291
+ : "path";
292
+ return (logic) => (input, binaries, expected) =>
293
+ logic === "and"
294
+ ? binaries
295
+ .map((binary) =>
296
+ binary.combined
297
+ ? binary.expression
298
+ : ts.factory.createLogicalOr(
299
+ binary.expression,
300
+ create_guard_call(importer)(
301
+ explore.source === "top"
302
+ ? ts.factory.createTrue()
303
+ : ts.factory.createIdentifier(
304
+ "exceptionable",
305
+ ),
306
+ )(
307
+ ts.factory.createIdentifier(path),
308
+ expected,
309
+ input,
310
+ ),
311
+ ),
312
+ )
313
+ .reduce(ts.factory.createLogicalAnd)
314
+ : (() => {
315
+ const addicted = binaries.slice();
316
+ if (
317
+ addicted[addicted.length - 1]!.combined === false
318
+ ) {
319
+ addicted.push({
320
+ combined: true,
321
+ expression: create_guard_call(importer)(
322
+ explore.source === "top"
323
+ ? ts.factory.createTrue()
324
+ : ts.factory.createIdentifier(
325
+ "exceptionable",
326
+ ),
327
+ )(
328
+ ts.factory.createIdentifier(path),
329
+ expected,
330
+ input,
331
+ ),
332
+ });
333
+ }
334
+ return addicted
335
+ .map((b) => b.expression)
336
+ .reduce(ts.factory.createLogicalOr);
337
+ })();
338
+
339
+ // ts.factory.createLogicalOr(
340
+ // binaries
341
+ // .map((binary) => binary.expression)
342
+ // .reduce(ts.factory.createLogicalOr),
343
+ // create_guard_call(importer)(
344
+ // explore.source === "top"
345
+ // ? ts.factory.createTrue()
346
+ // : ts.factory.createIdentifier(
347
+ // "exceptionable",
348
+ // ),
349
+ // )(ts.factory.createIdentifier(path), expected, input),
350
+ // );
351
+ };
352
+
353
+ const assert_object = (equals: boolean) => (importer: FunctionImporter) =>
354
+ check_object({
355
+ equals,
356
+ assert: true,
357
+ reduce: ts.factory.createLogicalAnd,
358
+ positive: ts.factory.createTrue(),
359
+ superfluous: (value) =>
360
+ create_guard_call(importer)()(
361
+ ts.factory.createAdd(
362
+ ts.factory.createIdentifier("path"),
363
+ ts.factory.createCallExpression(
364
+ importer.use("join"),
365
+ undefined,
366
+ [ts.factory.createIdentifier("key")],
367
+ ),
368
+ ),
369
+ "undefined",
370
+ value,
371
+ ),
372
+ halt: (expr) =>
373
+ ts.factory.createLogicalOr(
374
+ ts.factory.createStrictEquality(
375
+ ts.factory.createFalse(),
376
+ ts.factory.createIdentifier("exceptionable"),
377
+ ),
378
+ expr,
379
+ ),
380
+ });
381
+
382
+ const joiner =
383
+ (equals: boolean) =>
384
+ (importer: FunctionImporter): CheckerProgrammer.IConfig.IJoiner => ({
385
+ object: assert_object(equals)(importer),
386
+ array: (input, arrow) =>
387
+ ts.factory.createCallExpression(
388
+ IdentifierFactory.join(input, "every"),
389
+ undefined,
390
+ [arrow],
391
+ ),
392
+ failure: (value, expected, explore) =>
393
+ create_guard_call(importer)(
394
+ explore?.from === "top"
395
+ ? ts.factory.createTrue()
396
+ : ts.factory.createIdentifier("exceptionable"),
397
+ )(
398
+ ts.factory.createIdentifier(
399
+ explore?.postfix ? `path + ${explore.postfix}` : "path",
400
+ ),
401
+ expected,
402
+ value,
403
+ ),
404
+ full: equals
405
+ ? undefined
406
+ : (condition) => (input, expected, explore) =>
407
+ ts.factory.createLogicalOr(
408
+ condition,
409
+ create_guard_call(importer)(
410
+ explore.from === "top"
411
+ ? ts.factory.createTrue()
412
+ : ts.factory.createIdentifier(
413
+ "exceptionable",
414
+ ),
415
+ )(
416
+ ts.factory.createIdentifier("path"),
417
+ expected,
418
+ input,
419
+ ),
420
+ ),
421
+ });
422
+
423
+ const create_guard_call =
424
+ (importer: FunctionImporter) =>
425
+ (exceptionable?: ts.Expression) =>
426
+ (
427
+ path: ts.Expression,
428
+ expected: string,
429
+ value: ts.Expression,
430
+ ): ts.Expression =>
431
+ ts.factory.createCallExpression(importer.use("guard"), undefined, [
432
+ exceptionable || ts.factory.createIdentifier("exceptionable"),
433
+ ts.factory.createObjectLiteralExpression(
434
+ [
435
+ ts.factory.createPropertyAssignment("path", path),
436
+ ts.factory.createPropertyAssignment(
437
+ "expected",
438
+ ts.factory.createStringLiteral(expected),
439
+ ),
440
+ ts.factory.createPropertyAssignment("value", value),
441
+ ],
442
+ true,
443
+ ),
444
+ ]);
445
+ }