typia 7.0.0-dev.20240923 → 7.0.0-dev.20240928

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 (57) hide show
  1. package/lib/index.mjs +1 -0
  2. package/lib/index.mjs.map +1 -1
  3. package/lib/programmers/AssertProgrammer.d.ts +1 -1
  4. package/lib/programmers/AssertProgrammer.js +169 -127
  5. package/lib/programmers/AssertProgrammer.js.map +1 -1
  6. package/lib/programmers/CheckerProgrammer.d.ts +70 -15
  7. package/lib/programmers/CheckerProgrammer.js +998 -638
  8. package/lib/programmers/CheckerProgrammer.js.map +1 -1
  9. package/lib/programmers/FeatureProgrammer.d.ts +7 -3
  10. package/lib/programmers/FeatureProgrammer.js +17 -17
  11. package/lib/programmers/FeatureProgrammer.js.map +1 -1
  12. package/lib/programmers/IsProgrammer.d.ts +25 -4
  13. package/lib/programmers/IsProgrammer.js +54 -39
  14. package/lib/programmers/IsProgrammer.js.map +1 -1
  15. package/lib/programmers/ValidateProgrammer.js +110 -97
  16. package/lib/programmers/ValidateProgrammer.js.map +1 -1
  17. package/lib/programmers/helpers/UnionExplorer.d.ts +1 -1
  18. package/lib/programmers/json/JsonStringifyProgrammer.js +71 -38
  19. package/lib/programmers/json/JsonStringifyProgrammer.js.map +1 -1
  20. package/lib/programmers/llm/LlmApplicationProgrammer.js +16 -2
  21. package/lib/programmers/llm/LlmApplicationProgrammer.js.map +1 -1
  22. package/lib/programmers/misc/MiscCloneProgrammer.js +504 -406
  23. package/lib/programmers/misc/MiscCloneProgrammer.js.map +1 -1
  24. package/lib/programmers/misc/MiscLiteralsProgrammer.js +3 -3
  25. package/lib/programmers/misc/MiscLiteralsProgrammer.js.map +1 -1
  26. package/lib/programmers/misc/MiscPruneProgrammer.js +365 -301
  27. package/lib/programmers/misc/MiscPruneProgrammer.js.map +1 -1
  28. package/lib/programmers/notations/NotationGeneralProgrammer.js +62 -15
  29. package/lib/programmers/notations/NotationGeneralProgrammer.js.map +1 -1
  30. package/lib/programmers/protobuf/ProtobufEncodeProgrammer.js +17 -3
  31. package/lib/programmers/protobuf/ProtobufEncodeProgrammer.js.map +1 -1
  32. package/lib/tags/Example.d.ts +14 -0
  33. package/lib/tags/Example.js +3 -0
  34. package/lib/tags/Example.js.map +1 -0
  35. package/lib/tags/Examples.d.ts +10 -0
  36. package/lib/tags/Examples.js +3 -0
  37. package/lib/tags/Examples.js.map +1 -0
  38. package/lib/tags/index.d.ts +2 -0
  39. package/lib/tags/index.js +2 -0
  40. package/lib/tags/index.js.map +1 -1
  41. package/package.json +2 -2
  42. package/src/programmers/AssertProgrammer.ts +185 -143
  43. package/src/programmers/CheckerProgrammer.ts +1380 -998
  44. package/src/programmers/FeatureProgrammer.ts +40 -34
  45. package/src/programmers/IsProgrammer.ts +94 -66
  46. package/src/programmers/ValidateProgrammer.ts +149 -137
  47. package/src/programmers/helpers/UnionExplorer.ts +1 -1
  48. package/src/programmers/json/JsonStringifyProgrammer.ts +60 -38
  49. package/src/programmers/llm/LlmApplicationProgrammer.ts +51 -32
  50. package/src/programmers/misc/MiscCloneProgrammer.ts +775 -600
  51. package/src/programmers/misc/MiscLiteralsProgrammer.ts +4 -4
  52. package/src/programmers/misc/MiscPruneProgrammer.ts +532 -415
  53. package/src/programmers/notations/NotationGeneralProgrammer.ts +64 -26
  54. package/src/programmers/protobuf/ProtobufEncodeProgrammer.ts +16 -9
  55. package/src/tags/Example.ts +17 -0
  56. package/src/tags/Examples.ts +16 -0
  57. package/src/tags/index.ts +20 -18
@@ -11,6 +11,7 @@ import { CheckerProgrammer } from "./CheckerProgrammer";
11
11
  import { FeatureProgrammer } from "./FeatureProgrammer";
12
12
  import { IsProgrammer } from "./IsProgrammer";
13
13
  import { FunctionImporter } from "./helpers/FunctionImporter";
14
+ import { IExpressionEntry } from "./helpers/IExpressionEntry";
14
15
  import { OptionPredicator } from "./helpers/OptionPredicator";
15
16
  import { check_object } from "./internal/check_object";
16
17
 
@@ -24,8 +25,8 @@ export namespace AssertProgrammer {
24
25
  }
25
26
 
26
27
  export const decompose = (props: {
27
- context: ITypiaContext;
28
28
  config: IConfig;
29
+ context: ITypiaContext;
29
30
  importer: FunctionImporter;
30
31
  type: ts.Type;
31
32
  name: string | undefined;
@@ -45,33 +46,34 @@ export namespace AssertProgrammer {
45
46
  trace: true,
46
47
  numeric: OptionPredicator.numeric(props.context.options),
47
48
  equals: props.config.equals,
48
- atomist: (explore) => (entry) => (input) =>
49
+ atomist: (next) =>
49
50
  [
50
- ...(entry.expression ? [entry.expression] : []),
51
- ...(entry.conditions.length === 0
51
+ ...(next.entry.expression ? [next.entry.expression] : []),
52
+ ...(next.entry.conditions.length === 0
52
53
  ? []
53
- : entry.conditions.length === 1
54
- ? entry.conditions[0]!.map((cond) =>
54
+ : next.entry.conditions.length === 1
55
+ ? next.entry.conditions[0]!.map((cond) =>
55
56
  ts.factory.createLogicalOr(
56
57
  cond.expression,
57
- create_guard_call(props.importer)(
58
- explore.from === "top"
59
- ? ts.factory.createTrue()
60
- : ts.factory.createIdentifier("_exceptionable"),
61
- )(
62
- ts.factory.createIdentifier(
63
- explore.postfix
64
- ? `_path + ${explore.postfix}`
58
+ create_guard_call({
59
+ importer: props.importer,
60
+ exceptionable:
61
+ next.explore.from === "top"
62
+ ? ts.factory.createTrue()
63
+ : ts.factory.createIdentifier("_exceptionable"),
64
+ path: ts.factory.createIdentifier(
65
+ next.explore.postfix
66
+ ? `_path + ${next.explore.postfix}`
65
67
  : "_path",
66
68
  ),
67
- cond.expected,
68
- input,
69
- ),
69
+ expected: cond.expected,
70
+ input: next.input,
71
+ }),
70
72
  ),
71
73
  )
72
74
  : [
73
75
  ts.factory.createLogicalOr(
74
- entry.conditions
76
+ next.entry.conditions
75
77
  .map((set) =>
76
78
  set
77
79
  .map((s) => s.expression)
@@ -80,24 +82,25 @@ export namespace AssertProgrammer {
80
82
  ),
81
83
  )
82
84
  .reduce((a, b) => ts.factory.createLogicalOr(a, b)),
83
- create_guard_call(props.importer)(
84
- explore.from === "top"
85
- ? ts.factory.createTrue()
86
- : ts.factory.createIdentifier("_exceptionable"),
87
- )(
88
- ts.factory.createIdentifier(
89
- explore.postfix
90
- ? `_path + ${explore.postfix}`
85
+ create_guard_call({
86
+ importer: props.importer,
87
+ exceptionable:
88
+ next.explore.from === "top"
89
+ ? ts.factory.createTrue()
90
+ : ts.factory.createIdentifier("_exceptionable"),
91
+ path: ts.factory.createIdentifier(
92
+ next.explore.postfix
93
+ ? `_path + ${next.explore.postfix}`
91
94
  : "_path",
92
95
  ),
93
- entry.expected,
94
- input,
95
- ),
96
+ expected: next.entry.expected,
97
+ input: next.input,
98
+ }),
96
99
  ),
97
100
  ]),
98
101
  ].reduce((x, y) => ts.factory.createLogicalAnd(x, y)),
99
- combiner: combiner(props.config.equals)(props.context)(props.importer),
100
- joiner: joiner(props.config.equals)(props.context)(props.importer),
102
+ combiner: combiner(props),
103
+ joiner: joiner(props),
101
104
  success: ts.factory.createTrue(),
102
105
  },
103
106
  });
@@ -176,7 +179,6 @@ export namespace AssertProgrammer {
176
179
  true,
177
180
  ),
178
181
  );
179
-
180
182
  return {
181
183
  functions: {
182
184
  ...is.functions,
@@ -208,45 +210,63 @@ export namespace AssertProgrammer {
208
210
  };
209
211
 
210
212
  const combiner =
211
- (equals: boolean) =>
212
- (project: ITypiaContext) =>
213
- (importer: FunctionImporter): CheckerProgrammer.IConfig.Combiner =>
214
- (explore: CheckerProgrammer.IExplore) => {
215
- if (explore.tracable === false)
213
+ (props: {
214
+ config: IConfig;
215
+ context: ITypiaContext;
216
+ importer: FunctionImporter;
217
+ }): CheckerProgrammer.IConfig.Combiner =>
218
+ (next) => {
219
+ if (next.explore.tracable === false)
216
220
  return IsProgrammer.configure({
217
- object: assert_object(equals)(project)(importer),
221
+ object: (v) =>
222
+ assert_object({
223
+ config: props.config,
224
+ context: props.context,
225
+ importer: props.importer,
226
+ entries: v.entries,
227
+ input: v.input,
228
+ }),
218
229
  numeric: true,
219
- })(project)(importer).combiner(explore);
230
+ })(props.context)(props.importer).combiner(next);
220
231
 
221
- const path: string = explore.postfix
222
- ? `_path + ${explore.postfix}`
232
+ const path: string = next.explore.postfix
233
+ ? `_path + ${next.explore.postfix}`
223
234
  : "_path";
224
- return (logic) => (input, binaries, expected) =>
225
- logic === "and"
226
- ? binaries
227
- .map((binary) =>
228
- binary.combined
229
- ? binary.expression
230
- : ts.factory.createLogicalOr(
231
- binary.expression,
232
- create_guard_call(importer)(
233
- explore.source === "top"
235
+ return next.logic === "and"
236
+ ? next.binaries
237
+ .map((binary) =>
238
+ binary.combined
239
+ ? binary.expression
240
+ : ts.factory.createLogicalOr(
241
+ binary.expression,
242
+ create_guard_call({
243
+ importer: props.importer,
244
+ exceptionable:
245
+ next.explore.source === "top"
234
246
  ? ts.factory.createTrue()
235
247
  : ts.factory.createIdentifier("_exceptionable"),
236
- )(ts.factory.createIdentifier(path), expected, input),
237
- ),
238
- )
239
- .reduce(ts.factory.createLogicalAnd)
240
- : ts.factory.createLogicalOr(
241
- binaries
242
- .map((binary) => binary.expression)
243
- .reduce(ts.factory.createLogicalOr),
244
- create_guard_call(importer)(
245
- explore.source === "top"
248
+ path: ts.factory.createIdentifier(path),
249
+ expected: next.expected,
250
+ input: next.input,
251
+ }),
252
+ ),
253
+ )
254
+ .reduce(ts.factory.createLogicalAnd)
255
+ : ts.factory.createLogicalOr(
256
+ next.binaries
257
+ .map((binary) => binary.expression)
258
+ .reduce(ts.factory.createLogicalOr),
259
+ create_guard_call({
260
+ importer: props.importer,
261
+ exceptionable:
262
+ next.explore.source === "top"
246
263
  ? ts.factory.createTrue()
247
264
  : ts.factory.createIdentifier("_exceptionable"),
248
- )(ts.factory.createIdentifier(path), expected, input),
249
- );
265
+ path: ts.factory.createIdentifier(path),
266
+ expected: next.expected,
267
+ input: next.input,
268
+ }),
269
+ );
250
270
  // : (() => {
251
271
  // const addicted = binaries.slice();
252
272
  // if (
@@ -273,96 +293,118 @@ export namespace AssertProgrammer {
273
293
  // })();
274
294
  };
275
295
 
276
- const assert_object =
277
- (equals: boolean) =>
278
- (project: ITypiaContext) =>
279
- (importer: FunctionImporter) =>
280
- check_object({
281
- equals,
282
- assert: true,
283
- undefined: true,
284
- reduce: ts.factory.createLogicalAnd,
285
- positive: ts.factory.createTrue(),
286
- superfluous: (value) =>
287
- create_guard_call(importer)()(
288
- ts.factory.createAdd(
289
- ts.factory.createIdentifier("_path"),
290
- ts.factory.createCallExpression(importer.use("join"), undefined, [
291
- ts.factory.createIdentifier("key"),
292
- ]),
296
+ const assert_object = (props: {
297
+ config: IConfig;
298
+ context: ITypiaContext;
299
+ importer: FunctionImporter;
300
+ entries: IExpressionEntry<ts.Expression>[];
301
+ input: ts.Expression;
302
+ }) =>
303
+ check_object({
304
+ equals: props.config.equals,
305
+ assert: true,
306
+ undefined: true,
307
+ reduce: ts.factory.createLogicalAnd,
308
+ positive: ts.factory.createTrue(),
309
+ superfluous: (input) =>
310
+ create_guard_call({
311
+ importer: props.importer,
312
+ path: ts.factory.createAdd(
313
+ ts.factory.createIdentifier("_path"),
314
+ ts.factory.createCallExpression(
315
+ props.importer.use("join"),
316
+ undefined,
317
+ [ts.factory.createIdentifier("key")],
293
318
  ),
294
- "undefined",
295
- value,
296
319
  ),
297
- halt: (expr) =>
298
- ts.factory.createLogicalOr(
299
- ts.factory.createStrictEquality(
300
- ts.factory.createFalse(),
301
- ts.factory.createIdentifier("_exceptionable"),
302
- ),
303
- expr,
320
+ expected: "undefined",
321
+ input,
322
+ }),
323
+ halt: (expr) =>
324
+ ts.factory.createLogicalOr(
325
+ ts.factory.createStrictEquality(
326
+ ts.factory.createFalse(),
327
+ ts.factory.createIdentifier("_exceptionable"),
304
328
  ),
305
- })(project)(importer);
306
-
307
- const joiner =
308
- (equals: boolean) =>
309
- (project: ITypiaContext) =>
310
- (importer: FunctionImporter): CheckerProgrammer.IConfig.IJoiner => ({
311
- object: assert_object(equals)(project)(importer),
312
- array: (props) =>
313
- ts.factory.createCallExpression(
314
- IdentifierFactory.access(props.input)("every"),
315
- undefined,
316
- [props.arrow],
329
+ expr,
317
330
  ),
318
- failure: (value, expected, explore) =>
319
- create_guard_call(importer)(
320
- explore?.from === "top"
331
+ })(props.context)(props.importer)({
332
+ input: props.input,
333
+ entries: props.entries,
334
+ });
335
+
336
+ const joiner = (props: {
337
+ config: IConfig;
338
+ context: ITypiaContext;
339
+ importer: FunctionImporter;
340
+ }): CheckerProgrammer.IConfig.IJoiner => ({
341
+ object: (next) =>
342
+ assert_object({
343
+ config: props.config,
344
+ context: props.context,
345
+ importer: props.importer,
346
+ entries: next.entries,
347
+ input: next.input,
348
+ }),
349
+ array: (props) =>
350
+ ts.factory.createCallExpression(
351
+ IdentifierFactory.access(props.input)("every"),
352
+ undefined,
353
+ [props.arrow],
354
+ ),
355
+ failure: (next) =>
356
+ create_guard_call({
357
+ importer: props.importer,
358
+ exceptionable:
359
+ next.explore?.from === "top"
321
360
  ? ts.factory.createTrue()
322
361
  : ts.factory.createIdentifier("_exceptionable"),
323
- )(
324
- ts.factory.createIdentifier(
325
- explore?.postfix ? `_path + ${explore.postfix}` : "_path",
326
- ),
327
- expected,
328
- value,
362
+ path: ts.factory.createIdentifier(
363
+ next.explore?.postfix ? `_path + ${next.explore.postfix}` : "_path",
329
364
  ),
330
- full: equals
331
- ? undefined
332
- : (condition) => (input, expected, explore) =>
333
- ts.factory.createLogicalOr(
334
- condition,
335
- create_guard_call(importer)(
336
- explore.from === "top"
365
+ expected: next.expected,
366
+ input: next.input,
367
+ }),
368
+ full: props.config.equals
369
+ ? undefined
370
+ : (next) =>
371
+ ts.factory.createLogicalOr(
372
+ next.condition,
373
+ create_guard_call({
374
+ importer: props.importer,
375
+ exceptionable:
376
+ next.explore.from === "top"
337
377
  ? ts.factory.createTrue()
338
378
  : ts.factory.createIdentifier("_exceptionable"),
339
- )(ts.factory.createIdentifier("_path"), expected, input),
340
- ),
341
- });
379
+ path: ts.factory.createIdentifier("_path"),
380
+ expected: next.expected,
381
+ input: next.input,
382
+ }),
383
+ ),
384
+ });
342
385
 
343
- const create_guard_call =
344
- (importer: FunctionImporter) =>
345
- (exceptionable?: ts.Expression) =>
346
- (
347
- path: ts.Expression,
348
- expected: string,
349
- value: ts.Expression,
350
- ): ts.Expression =>
351
- ts.factory.createCallExpression(importer.use("guard"), undefined, [
352
- exceptionable ?? ts.factory.createIdentifier("_exceptionable"),
353
- ts.factory.createObjectLiteralExpression(
354
- [
355
- ts.factory.createPropertyAssignment("path", path),
356
- ts.factory.createPropertyAssignment(
357
- "expected",
358
- ts.factory.createStringLiteral(expected),
359
- ),
360
- ts.factory.createPropertyAssignment("value", value),
361
- ],
362
- true,
363
- ),
364
- ts.factory.createIdentifier("_errorFactory"),
365
- ]);
386
+ const create_guard_call = (props: {
387
+ importer: FunctionImporter;
388
+ expected: string;
389
+ input: ts.Expression;
390
+ path: ts.Expression;
391
+ exceptionable?: ts.Expression;
392
+ }): ts.Expression =>
393
+ ts.factory.createCallExpression(props.importer.use("guard"), undefined, [
394
+ props.exceptionable ?? ts.factory.createIdentifier("_exceptionable"),
395
+ ts.factory.createObjectLiteralExpression(
396
+ [
397
+ ts.factory.createPropertyAssignment("path", props.path),
398
+ ts.factory.createPropertyAssignment(
399
+ "expected",
400
+ ts.factory.createStringLiteral(props.expected),
401
+ ),
402
+ ts.factory.createPropertyAssignment("value", props.input),
403
+ ],
404
+ true,
405
+ ),
406
+ ts.factory.createIdentifier("_errorFactory"),
407
+ ]);
366
408
 
367
409
  export namespace Guardian {
368
410
  export const identifier = () => ts.factory.createIdentifier("errorFactory");