typia 9.7.2 → 10.0.0-dev.20251107

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 (116) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +153 -153
  3. package/lib/factories/ProtobufFactory.js +1 -1
  4. package/lib/factories/ProtobufFactory.mjs +1 -1
  5. package/lib/programmers/internal/json_schema_station.d.mts +2 -2
  6. package/lib/programmers/internal/json_schema_station.d.ts +2 -2
  7. package/lib/programmers/llm/LlmApplicationProgrammer.js +5 -1
  8. package/lib/programmers/llm/LlmApplicationProgrammer.js.map +1 -1
  9. package/lib/programmers/llm/LlmApplicationProgrammer.mjs +5 -1
  10. package/lib/programmers/llm/LlmSchemaProgrammer.js +1 -4
  11. package/lib/programmers/llm/LlmSchemaProgrammer.js.map +1 -1
  12. package/lib/programmers/llm/LlmSchemaProgrammer.mjs +1 -35
  13. package/package.json +121 -121
  14. package/src/AssertionGuard.ts +41 -41
  15. package/src/CamelCase.ts +75 -75
  16. package/src/IRandomGenerator.ts +337 -337
  17. package/src/IReadableURLSearchParams.ts +9 -9
  18. package/src/PascalCase.ts +71 -71
  19. package/src/Primitive.ts +90 -90
  20. package/src/Resolved.ts +72 -72
  21. package/src/SnakeCase.ts +127 -127
  22. package/src/TypeGuardError.ts +216 -216
  23. package/src/factories/MetadataCollection.ts +270 -270
  24. package/src/factories/MetadataCommentTagFactory.ts +632 -632
  25. package/src/factories/MetadataFactory.ts +402 -402
  26. package/src/factories/ProtobufFactory.ts +873 -873
  27. package/src/functional.ts +705 -705
  28. package/src/http.ts +972 -972
  29. package/src/internal/_ProtobufReader.ts +188 -188
  30. package/src/internal/_ProtobufSizer.ts +137 -137
  31. package/src/internal/_ProtobufWriter.ts +135 -135
  32. package/src/internal/_jsonStringifyString.ts +42 -42
  33. package/src/json.ts +643 -643
  34. package/src/llm.ts +615 -615
  35. package/src/misc.ts +594 -594
  36. package/src/module.ts +889 -889
  37. package/src/notations.ts +751 -751
  38. package/src/programmers/FeatureProgrammer.ts +605 -605
  39. package/src/programmers/ImportProgrammer.ts +179 -179
  40. package/src/programmers/RandomProgrammer.ts +1195 -1195
  41. package/src/programmers/helpers/ProtobufWire.ts +34 -34
  42. package/src/programmers/internal/check_array_length.ts +43 -43
  43. package/src/programmers/internal/check_bigint.ts +46 -46
  44. package/src/programmers/internal/check_dynamic_key.ts +197 -197
  45. package/src/programmers/internal/check_dynamic_properties.ts +231 -231
  46. package/src/programmers/internal/check_everything.ts +21 -21
  47. package/src/programmers/internal/check_native.ts +23 -23
  48. package/src/programmers/internal/check_number.ts +108 -108
  49. package/src/programmers/internal/check_object.ts +72 -72
  50. package/src/programmers/internal/check_string.ts +46 -46
  51. package/src/programmers/internal/check_template.ts +46 -46
  52. package/src/programmers/internal/check_union_array_like.ts +331 -331
  53. package/src/programmers/internal/decode_union_object.ts +110 -110
  54. package/src/programmers/internal/feature_object_entries.ts +59 -59
  55. package/src/programmers/internal/json_schema_escaped.ts +78 -78
  56. package/src/programmers/internal/json_schema_object.ts +150 -150
  57. package/src/programmers/internal/json_schema_station.ts +2 -2
  58. package/src/programmers/internal/metadata_to_pattern.ts +40 -40
  59. package/src/programmers/internal/postfix_of_tuple.ts +3 -3
  60. package/src/programmers/internal/prune_object_properties.ts +69 -69
  61. package/src/programmers/internal/stringify_dynamic_properties.ts +158 -158
  62. package/src/programmers/internal/stringify_native.ts +5 -5
  63. package/src/programmers/internal/stringify_regular_properties.ts +77 -77
  64. package/src/programmers/internal/template_to_pattern.ts +21 -21
  65. package/src/programmers/internal/wrap_metadata_rest_tuple.ts +21 -21
  66. package/src/programmers/json/JsonStringifyProgrammer.ts +1124 -1124
  67. package/src/programmers/llm/LlmApplicationProgrammer.ts +10 -1
  68. package/src/programmers/llm/LlmSchemaProgrammer.ts +2 -7
  69. package/src/protobuf.ts +820 -820
  70. package/src/reflect.ts +46 -46
  71. package/src/schemas/json/IJsonApplication.ts +77 -77
  72. package/src/schemas/json/IJsonSchemaCollection.ts +212 -212
  73. package/src/schemas/json/IJsonSchemaUnit.ts +263 -263
  74. package/src/schemas/metadata/IMetadataTypeTag.ts +14 -14
  75. package/src/schemas/metadata/Metadata.ts +669 -669
  76. package/src/schemas/metadata/MetadataAliasType.ts +57 -57
  77. package/src/schemas/metadata/MetadataApplication.ts +40 -40
  78. package/src/schemas/metadata/MetadataArray.ts +47 -47
  79. package/src/schemas/metadata/MetadataArrayType.ts +51 -51
  80. package/src/schemas/metadata/MetadataAtomic.ts +85 -85
  81. package/src/schemas/metadata/MetadataEscaped.ts +45 -45
  82. package/src/schemas/metadata/MetadataFunction.ts +45 -45
  83. package/src/schemas/metadata/MetadataObject.ts +46 -46
  84. package/src/schemas/metadata/MetadataObjectType.ts +137 -137
  85. package/src/schemas/metadata/MetadataParameter.ts +52 -52
  86. package/src/schemas/metadata/MetadataProperty.ts +53 -53
  87. package/src/schemas/metadata/MetadataTemplate.ts +78 -78
  88. package/src/schemas/metadata/MetadataTuple.ts +28 -28
  89. package/src/schemas/metadata/MetadataTupleType.ts +61 -61
  90. package/src/tags/Constant.ts +47 -47
  91. package/src/tags/ContentMediaType.ts +27 -27
  92. package/src/tags/Default.ts +52 -52
  93. package/src/tags/Example.ts +56 -56
  94. package/src/tags/Examples.ts +56 -56
  95. package/src/tags/ExclusiveMaximum.ts +44 -44
  96. package/src/tags/ExclusiveMinimum.ts +44 -44
  97. package/src/tags/Format.ts +78 -78
  98. package/src/tags/JsonSchemaPlugin.ts +36 -36
  99. package/src/tags/MaxItems.ts +31 -31
  100. package/src/tags/MaxLength.ts +25 -25
  101. package/src/tags/Maximum.ts +39 -39
  102. package/src/tags/MinItems.ts +31 -31
  103. package/src/tags/MinLength.ts +25 -25
  104. package/src/tags/Minimum.ts +39 -39
  105. package/src/tags/MultipleOf.ts +42 -42
  106. package/src/tags/Pattern.ts +49 -49
  107. package/src/tags/Sequence.ts +37 -37
  108. package/src/tags/TagBase.ts +102 -102
  109. package/src/tags/Type.ts +64 -64
  110. package/src/tags/UniqueItems.ts +34 -34
  111. package/src/tags/internal/FormatCheatSheet.ts +71 -71
  112. package/src/transformers/ITransformOptions.ts +70 -70
  113. package/src/transformers/ImportTransformer.ts +253 -253
  114. package/src/transformers/NoTransformConfigurationError.ts +16 -16
  115. package/src/transformers/features/llm/LlmApplicationTransformer.ts +224 -224
  116. package/src/typings/Equal.ts +18 -18
package/src/functional.ts CHANGED
@@ -1,705 +1,705 @@
1
- import { NoTransformConfigurationError } from "./transformers/NoTransformConfigurationError";
2
-
3
- import { IValidation } from "./IValidation";
4
- import { TypeGuardError } from "./TypeGuardError";
5
-
6
- /* ===========================================================
7
- FUNCTIONAL
8
- - ASSERT
9
- - IS
10
- - VALIDATE
11
- ==============================================================
12
- ASSERT
13
- ----------------------------------------------------------- */
14
- /**
15
- * Asserts a function.
16
- *
17
- * Asserts a function, by wrapping the function and checking its parameters and
18
- * return value through {@link assert} function. If some parameter or return
19
- * value does not match the expected type, it throws an {@link TypeGuardError} or
20
- * a custom error generated by the _errorFactory_ parameter.
21
- *
22
- * For reference, {@link TypeGuardError.path} would be a little bit different
23
- * with individual {@link assert} function. If the {@link TypeGuardError} occurs
24
- * from some parameter, the path would start from `$input.parameters[number]`.
25
- * Otherwise the path would start from `$input.return`.
26
- *
27
- * - `$input.parameters[0].~`
28
- * - `$input.return.~`
29
- *
30
- * By the way, if what you want is not just finding the 1st type error through
31
- * assertion, but also finding every type errors, then use
32
- * {@link validateFunction} instead. Otherwise, what you want is just asserting
33
- * parameters or return value only, you can use {@link assertParameters} or
34
- * {@link assertReturn} instead.
35
- *
36
- * On the other hand, if don't want to allow any superfluous properties, utilize
37
- * {@link assertEqualsFunction} or {@link validateEqualsFunction} instead.
38
- *
39
- * @author Jeongho Nam - https://github.com/samchon
40
- * @template T Target function type
41
- * @param func Target function to assert
42
- * @param errorFactory Custom error factory. Default is `TypeGuardError`
43
- * @returns The wrapper function with type assertions
44
- * @throws A {@link TypeGuardError} or a custom error generated by _errorFactory_
45
- */
46
- export function assertFunction<T extends (...args: any[]) => any>(
47
- func: T,
48
- errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
49
- ): T;
50
-
51
- /** @internal */
52
- export function assertFunction(): never {
53
- NoTransformConfigurationError("functional.assertFunction");
54
- }
55
-
56
- /**
57
- * Asserts parameters.
58
- *
59
- * Asserts a function, by wrapping the function and checking its parameters
60
- * through {@link assert} function. If some parameter does not match the expected
61
- * type, it throws an {@link TypeGuardError} or a custom error generated by the
62
- * _errorFactory_ parameter.
63
- *
64
- * For reference, {@link TypeGuardError.path} would be a little bit different
65
- * with individual {@link assert} function. If the {@link TypeGuardError} occurs
66
- * from some parameter, the path would start from `$input.parameters[number]`.
67
- *
68
- * By the way, if what you want is not just finding the 1st type error through
69
- * assertion, but also finding every type errors, then use
70
- * {@link validateParameters} instead. Otherwise, what you want is not only
71
- * asserting parameters, but also asserting return value, you can use
72
- * {@link assertFunction} instead.
73
- *
74
- * On the other hand, if don't want to allow any superfluous properties, utilize
75
- * {@link assertEqualsParameters} or {@link validateEqualsParameters} instead.
76
- *
77
- * @author Jeongho Nam - https://github.com/samchon
78
- * @template T Target function type
79
- * @param func Target function to assert
80
- * @param errorFactory Custom error factory. Default is `TypeGuardError`
81
- * @returns The wrapper function with type assertions
82
- * @throws A {@link TypeGuardError} or a custom error generated by _errorFactory_
83
- */
84
- export function assertParameters<T extends (...args: any[]) => any>(
85
- func: T,
86
- errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
87
- ): T;
88
-
89
- /** @internal */
90
- export function assertParameters(): never {
91
- NoTransformConfigurationError("functional.assertParameters");
92
- }
93
-
94
- /**
95
- * Asserts return value.
96
- *
97
- * Asserts a function, by wrapping the function and checking its return value
98
- * through {@link assert} function. If the return value does not match the
99
- * expected type, it throws an {@link TypeGuardError} or a custom error generated
100
- * by the _errorFactory_ parameter.
101
- *
102
- * For reference, {@link TypeGuardError.path} would be a little bit different
103
- * with individual {@link assert} function. If the {@link TypeGuardError} occurs
104
- * from the return value, the path would start from `$input.return`.
105
- *
106
- * By the way, if what you want is not just finding the 1st type error through
107
- * assertion, but also finding every type errors, then use {@link validateReturn}
108
- * instead. Otherwise, what you want is not only asserting return value, but
109
- * also asserting parameters, you can use {@link assertFunction} instead.
110
- *
111
- * On the other hand, if don't want to allow any superfluous properties, utilize
112
- * {@link assertEqualsReturn} or {@link validateEqualsReturn} instead.
113
- *
114
- * @author Jeongho Nam - https://github.com/samchon
115
- * @template T Target function type
116
- * @param func Target function to assert
117
- * @param errorFactory Custom error factory. Default is `TypeGuardError`
118
- * @returns The wrapper function with type assertions
119
- * @throws A {@link TypeGuardError} or a custom error generated by _errorFactory_
120
- */
121
- export function assertReturn<T extends (...args: any[]) => any>(
122
- func: T,
123
- errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
124
- ): T;
125
-
126
- /** @internal */
127
- export function assertReturn(): never {
128
- NoTransformConfigurationError("functional.assertReturn");
129
- }
130
-
131
- /**
132
- * Asserts a function with strict equality.
133
- *
134
- * Asserts a function with strict equality, by wrapping the function and
135
- * checking its parameters and return value through {@link assertEquals}
136
- * function. If some parameter or return value does not match the expected type,
137
- * it throws an {@link TypeGuardError} or a custom error generated by the
138
- * _errorFactory_ parameter.
139
- *
140
- * For reference, {@link TypeGuardError.path} would be a little bit different
141
- * with individual {@link assertEquals} function. If the {@link TypeGuardError}
142
- * occurs from some parameter, the path would start from
143
- * `$input.parameters[number]`. Otherwise the path would start from
144
- * `$input.return`.
145
- *
146
- * - `$input.parameters[0].~`
147
- * - `$input.return.~`
148
- *
149
- * By the way, if what you want is not just finding the 1st type error through
150
- * assertion, but also finding every type errors, then use
151
- * {@link validateEqualsFunction} instead. Otherwise, what you want is just
152
- * asserting parameters or return value only, you can use
153
- * {@link assertEqualsParameters} or {@link assertEqualsReturn} instead.
154
- *
155
- * On the other hand, if you want to allow any superfluous properties, utilize
156
- * {@link assertFunction} or {@link validateFunction} instead.
157
- *
158
- * @author Jeongho Nam - https://github.com/samchon
159
- * @template T Target function type
160
- * @param func Target function to assert
161
- * @param errorFactory Custom error factory. Default is `TypeGuardError`
162
- * @returns The wrapper function with type assertions
163
- * @throws A {@link TypeGuardError} or a custom error generated by _errorFactory_
164
- */
165
- export function assertEqualsFunction<T extends (...args: any[]) => any>(
166
- func: T,
167
- errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
168
- ): T;
169
-
170
- /** @internal */
171
- export function assertEqualsFunction(): never {
172
- NoTransformConfigurationError("functional.assertEqualsFunction");
173
- }
174
-
175
- /**
176
- * Asserts parameters with strict equality.
177
- *
178
- * Asserts a function, by wrapping the function and checking its parameters
179
- * through {@link assertEquals} function. If some parameter does not match the
180
- * expected type, it throws an {@link TypeGuardError} or a custom error generated
181
- * by the _errorFactory_ parameter.
182
- *
183
- * For reference, {@link TypeGuardError.path} would be a little bit different
184
- * with individual {@link assertEquals} function. If the {@link TypeGuardError}
185
- * occurs from some parameter, the path would start from
186
- * `$input.parameters[number]`.
187
- *
188
- * By the way, if what you want is not just finding the 1st type error through
189
- * assertion, but also finding every type errors, then use
190
- * {@link validateEqualsParameters} instead. Otherwise, what you want is not only
191
- * asserting parameters, but also asserting return value, you can use
192
- * {@link assertEqualsFunction} instead.
193
- *
194
- * On the other hand, if you want to allow any superfluous properties, utilize
195
- * {@link assertParameters} or {@link validateParameters} instead.
196
- *
197
- * @author Jeongho Nam - https://github.com/samchon
198
- * @template T Target function type
199
- * @param func Target function to assert
200
- * @param errorFactory Custom error factory. Default is `TypeGuardError`
201
- * @returns The wrapper function with type assertions
202
- * @throws A {@link TypeGuardError} or a custom error generated by _errorFactory_
203
- */
204
- export function assertEqualsParameters<T extends (...args: any[]) => any>(
205
- func: T,
206
- errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
207
- ): T;
208
-
209
- /** @internal */
210
- export function assertEqualsParameters(): never {
211
- NoTransformConfigurationError("functional.assertEqualsParameters");
212
- }
213
-
214
- /**
215
- * Asserts return value with strict equality.
216
- *
217
- * Asserts a function, by wrapping the function and checking its return value
218
- * through {@link assertEquals} function. If the return value does not match the
219
- * expected type, it throws an {@link TypeGuardError} or a custom error generated
220
- * by the _errorFactory_ parameter.
221
- *
222
- * For reference, {@link TypeGuardError.path} would be a little bit different
223
- * with individual {@link assertEquals} function. If the {@link TypeGuardError}
224
- * occurs from the return value, the path would start from `$input.return`.
225
- *
226
- * By the way, if what you want is not just finding the 1st type error through
227
- * assertion, but also finding every type errors, then use
228
- * {@link validateEqualsReturn} instead. Otherwise, what you want is not only
229
- * asserting return value, but also asserting parameters, you can use
230
- * {@link assertEqualsFunction} instead.
231
- *
232
- * On the other hand, if you want to allow any superfluous properties, utilize
233
- * {@link assertReturn} or {@link validateReturn} instead.
234
- *
235
- * @author Jeongho Nam - https://github.com/samchon
236
- * @template T Target function type
237
- * @param func Target function to assert
238
- * @param errorFactory Custom error factory. Default is `TypeGuardError`
239
- * @returns The wrapper function with type assertions
240
- * @throws A {@link TypeGuardError} or a custom error generated by _errorFactory_
241
- */
242
- export function assertEqualsReturn<T extends (...args: any[]) => any>(
243
- func: T,
244
- errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
245
- ): T;
246
-
247
- /** @internal */
248
- export function assertEqualsReturn(): never {
249
- NoTransformConfigurationError("functional.assertEqualsReturn");
250
- }
251
-
252
- /* -----------------------------------------------------------
253
- IS
254
- ----------------------------------------------------------- */
255
- /**
256
- * Tests a function.
257
- *
258
- * Tests a function, by wrapping the function and checking its parameters and
259
- * return value through {@link is} function. If some parameter or return value
260
- * does not match the expected type, it returns `null`. Otherwise there's no
261
- * type error, it returns the result of the function.
262
- *
263
- * By the way, if you want is not just testing type checking, but also finding
264
- * detailed type error reason(s), then use {@link assertFunction} or
265
- * {@link validateFunction} instead.
266
- *
267
- * On the other hand, if you don't want to allow any superfluous properties,
268
- * utilize {@link equalsFunction}, {@link assertEqualsFunction} or
269
- * {@link validateEqualsFunction} instead.
270
- *
271
- * @author Jeongho Nam - https://github.com/samchon
272
- * @template T Target function type
273
- * @param func Target function to test
274
- * @returns The wrapper function with type tests
275
- */
276
- export function isFunction<T extends (...args: any[]) => any>(
277
- func: T,
278
- ): T extends (...args: infer Arguments) => infer Output
279
- ? Output extends Promise<infer R>
280
- ? (...args: Arguments) => Promise<R | null>
281
- : (...args: Arguments) => Output | null
282
- : never;
283
-
284
- /** @internal */
285
- export function isFunction(): never {
286
- NoTransformConfigurationError("functional.isFunction");
287
- }
288
-
289
- /**
290
- * Tests parameters.
291
- *
292
- * Tests a function, by wrapping the function and checking its parameters
293
- * through {@link is} function. If some parameter does not match the expected
294
- * type, it returns `null`. Otherwise there's no type error, it returns the
295
- * result of the function.
296
- *
297
- * By the way, if you want is not just testing type checking, but also finding
298
- * detailed type error reason(s), then use {@link assertParameters} or
299
- * {@link validateParameters} instead.
300
- *
301
- * On the other hand, if you don't want to allow any superfluous properties,
302
- * utilize {@link equalsParameters}, {@link assertEqualsParameters} or
303
- * {@link validateEqualsParameters} instead.
304
- *
305
- * @author Jeongho Nam - https://github.com/samchon
306
- * @template T Target function type
307
- * @param func Target function to test
308
- * @returns The wrapper function with type tests
309
- */
310
- export function isParameters<T extends (...args: any[]) => any>(
311
- func: T,
312
- ): T extends (...args: infer Arguments) => infer Output
313
- ? Output extends Promise<infer R>
314
- ? (...args: Arguments) => Promise<R | null>
315
- : (...args: Arguments) => Output | null
316
- : never;
317
-
318
- /** @internal */
319
- export function isParameters(): never {
320
- NoTransformConfigurationError("functional.isParameters");
321
- }
322
-
323
- /**
324
- * Tests return value.
325
- *
326
- * Tests a function, by wrapping the function and checking its return value
327
- * through {@link is} function. If the return value does not match the expected
328
- * type, it returns `null`. Otherwise there's no type error, it returns the
329
- * result of the function.
330
- *
331
- * By the way, if you want is not just testing type checking, but also finding
332
- * detailed type error reason(s), then use {@link assertReturn} or
333
- * {@link validateReturn} instead.
334
- *
335
- * On the other hand, if you don't want to allow any superfluous properties,
336
- * utilize {@link equalsReturn}, {@link assertEqualsReturn} or
337
- * {@link validateEqualsReturn} instead.
338
- *
339
- * @author Jeongho Nam - https://github.com/samchon
340
- * @template T Target function type
341
- * @param func Target function to test
342
- * @returns The wrapper function with type tests
343
- */
344
- export function isReturn<T extends (...args: any[]) => any>(
345
- func: T,
346
- ): T extends (...args: infer Arguments) => infer Output
347
- ? Output extends Promise<infer R>
348
- ? (...args: Arguments) => Promise<R | null>
349
- : (...args: Arguments) => Output | null
350
- : never;
351
-
352
- /** @internal */
353
- export function isReturn(): never {
354
- NoTransformConfigurationError("functional.isReturn");
355
- }
356
-
357
- /**
358
- * Tests a function with strict equality.
359
- *
360
- * Tests a function with strict equality, by wrapping the function and checking
361
- * its parameters and return value through {@link isEquals} function. If some
362
- * parameter or return value does not match the expected type, it returns
363
- * `null`. Otherwise there's no type error, it returns the result of the
364
- * function.
365
- *
366
- * By the way, if you want is not just testing type checking, but also finding
367
- * detailed type error reason(s), then use {@link assertEqualsFunction} or
368
- * {@link validateEqualsFunction} instead.
369
- *
370
- * On the other hand, if you want to allow any superfluous properties, utilize
371
- * {@link isFunction}, {@link assertFunction} or {@link validateFunction} instead.
372
- *
373
- * @author Jeongho Nam - https://github.com/samchon
374
- * @template T Target function type
375
- * @param func Target function to test
376
- * @returns The wrapper function with type tests
377
- */
378
- export function equalsFunction<T extends (...args: any[]) => any>(
379
- func: T,
380
- ): T extends (...args: infer Arguments) => infer Output
381
- ? Output extends Promise<infer R>
382
- ? (...args: Arguments) => Promise<R | null>
383
- : (...args: Arguments) => Output | null
384
- : never;
385
-
386
- /** @internal */
387
- export function equalsFunction(): never {
388
- NoTransformConfigurationError("functional.equalsFunction");
389
- }
390
-
391
- /**
392
- * Tests parameters with strict equality.
393
- *
394
- * Tests a function, by wrapping the function and checking its parameters
395
- * through {@link isEquals} function. If some parameter does not match the
396
- * expected type, it returns `null`. Otherwise there's no type error, it returns
397
- * the result of the function.
398
- *
399
- * By the way, if you want is not just testing type checking, but also finding
400
- * detailed type error reason(s), then use {@link assertEqualsParameters} or
401
- * {@link validateEqualsParameters} instead.
402
- *
403
- * @author Jeongho Nam - https://github.com/samchon
404
- * @template T Target function type
405
- * @param func Target function to test
406
- * @returns The wrapper function with type tests
407
- */
408
- export function equalsParameters<T extends (...args: any[]) => any>(
409
- func: T,
410
- ): T extends (...args: infer Arguments) => infer Output
411
- ? Output extends Promise<infer R>
412
- ? (...args: Arguments) => Promise<R | null>
413
- : (...args: Arguments) => Output | null
414
- : never;
415
-
416
- /** @internal */
417
- export function equalsParameters(): never {
418
- NoTransformConfigurationError("functional.equalsParameters");
419
- }
420
-
421
- /**
422
- * Tests return value with strict equality.
423
- *
424
- * Tests a function, by wrapping the function and checking its return value
425
- * through {@link isEquals} function. If the return value does not match the
426
- * expected type, it returns `null`. Otherwise there's no type error, it returns
427
- * the result of the function.
428
- *
429
- * By the way, if you want is not just testing type checking, but also finding
430
- * detailed type error reason(s), then use {@link assertEqualsReturn} or
431
- * {@link validateEqualsReturn} instead.
432
- *
433
- * On the other hand, if you want to allow any superfluous properties, utilize
434
- * {@link isReturn}, {@link assertReturn} or {@link validateReturn} instead.
435
- *
436
- * @author Jeongho Nam - https://github.com/samchon
437
- * @template T Target function type
438
- * @param func Target function to test
439
- * @returns The wrapper function with type tests
440
- */
441
- export function equalsReturn<T extends (...args: any[]) => any>(
442
- func: T,
443
- ): T extends (...args: infer Arguments) => infer Output
444
- ? Output extends Promise<infer R>
445
- ? (...args: Arguments) => Promise<R | null>
446
- : (...args: Arguments) => Output | null
447
- : never;
448
-
449
- /** @internal */
450
- export function equalsReturn(): never {
451
- NoTransformConfigurationError("functional.equalsReturn");
452
- }
453
-
454
- /* -----------------------------------------------------------
455
- VALIDATE
456
- ----------------------------------------------------------- */
457
- /**
458
- * Validates a function.
459
- *
460
- * Validates a function, by wrapping the function and checking its parameters
461
- * and return value through {@link validate} function. If some parameter or
462
- * return value does not match the expected type, it returns
463
- * {@link IValidation.IError} typed object. Otherwise there's no type error, it
464
- * returns {@link IValidation.ISuccess} typed object instead.
465
- *
466
- * For reference, {@link IValidation.IError.path} would be a little bit different
467
- * with individual {@link validate} function. If the {@link IValidation.IError}
468
- * occurs from some parameter, the path would start from
469
- * `$input.parameters[number]`. Otherwise the path would start from
470
- * `$input.return`.
471
- *
472
- * - `$input.parameters[0].~`
473
- * - `$input.return.~`
474
- *
475
- * By the way, if what you want is not finding every type errors, but just
476
- * finding the 1st type error, then use {@link assertFunction} instead.
477
- * Otherwise, what you want is just validating parameters or return value only,
478
- * you can use {@link validateParameters} or {@link validateReturn} instead.
479
- *
480
- * On the other hand, if you don't want to allow any superfluous properties,
481
- * utilize {@link validateEqualsFunction} or {@link assertEqualsFunction}
482
- * instead.
483
- *
484
- * @author Jeongho Nam - https://github.com/samchon
485
- * @template T Target function type
486
- * @param func Target function to validate
487
- * @returns The wrapper function with type validations
488
- */
489
- export function validateFunction<T extends (...args: any[]) => any>(
490
- func: T,
491
- ): T extends (...args: infer Arguments) => infer Output
492
- ? Output extends Promise<infer R>
493
- ? (...args: Arguments) => Promise<IValidation<R>>
494
- : (...args: Arguments) => IValidation<Output>
495
- : never;
496
-
497
- /** @internal */
498
- export function validateFunction(): never {
499
- NoTransformConfigurationError("functional.validateFunction");
500
- }
501
-
502
- /**
503
- * Validates parameters.
504
- *
505
- * Validates a function, by wrapping the function and checking its parameters
506
- * through {@link validate} function. If some parameter does not match the
507
- * expected type, it returns {@link IValidation.IError} typed object. Otherwise
508
- * there's no type error, it returns {@link IValidation.ISuccess} typed object
509
- * instead.
510
- *
511
- * For reference, {@link IValidation.IError.path} would be a little bit different
512
- * with individual {@link validate} function. If the {@link IValidation.IError}
513
- * occurs from some parameter, the path would start from
514
- * `$input.parameters[number]`.
515
- *
516
- * By the way, if what you want is not finding every type errors, but just
517
- * finding the 1st type error, then use {@link assertParameters} instead.
518
- * Otherwise, what you want is not only validating parameters, but also
519
- * validating return value, you can use {@link validateFunction} instead.
520
- *
521
- * On the other hand, if you don't want to allow any superfluous properties,
522
- * utilize {@link validateEqualsParameters} or {@link assertEqualsParameters}
523
- * instead.
524
- *
525
- * @author Jeongho Nam - https://github.com/samchon
526
- * @template T Target function type
527
- * @param func Target function to validate
528
- * @returns The wrapper function with type validations
529
- */
530
- export function validateParameters<T extends (...args: any[]) => any>(
531
- func: T,
532
- ): T extends (...args: infer Arguments) => infer Output
533
- ? Output extends Promise<infer R>
534
- ? (...args: Arguments) => Promise<IValidation<R>>
535
- : (...args: Arguments) => IValidation<Output>
536
- : never;
537
-
538
- /** @internal */
539
- export function validateParameters(): never {
540
- NoTransformConfigurationError("functional.validateParameters");
541
- }
542
-
543
- /**
544
- * Validates return value.
545
- *
546
- * Validates a function, by wrapping the function and checking its return value
547
- * through {@link validate} function. If the return value does not match the
548
- * expected type, it returns {@link IValidation.IError} typed object. Otherwise
549
- * there's no type error, it returns {@link IValidation.ISuccess} typed object
550
- * instead.
551
- *
552
- * For reference, {@link IValidation.IError.path} would be a little bit different
553
- * with individual {@link validate} function. If the {@link IValidation.IError}
554
- * occurs from the return value, the path would start from `$input.return`.
555
- *
556
- * By the way, if what you want is not finding every type errors, but just
557
- * finding the 1st type error, then use {@link assertReturn} instead. Otherwise,
558
- * what you want is not only validating return value, but also validating
559
- * parameters, you can use {@link validateFunction} instead.
560
- *
561
- * On the other hand, if you don't want to allow any superfluous properties,
562
- * utilize {@link validateEqualsReturn} or {@link assertEqualsReturn} instead.
563
- *
564
- * @author Jeongho Nam - https://github.com/samchon
565
- * @template T Target function type
566
- * @param func Target function to validate
567
- * @returns The wrapper function with type validations
568
- */
569
- export function validateReturn<T extends (...args: any[]) => any>(
570
- func: T,
571
- ): T extends (...args: infer Arguments) => infer Output
572
- ? Output extends Promise<infer R>
573
- ? (...args: Arguments) => Promise<IValidation<R>>
574
- : (...args: Arguments) => IValidation<Output>
575
- : never;
576
-
577
- /** @internal */
578
- export function validateReturn(): never {
579
- NoTransformConfigurationError("functional.validateReturn");
580
- }
581
-
582
- /**
583
- * Validates a function with strict equality.
584
- *
585
- * Validates a function with strict equality, by wrapping the function and
586
- * checking its parameters and return value through {@link validateEquals}
587
- * function. If some parameter or return value does not match the expected type,
588
- * it returns {@link IValidation.IError} typed object. Otherwise there's no type
589
- * error, it returns {@link IValidation.ISuccess} typed object instead.
590
- *
591
- * For reference, {@link IValidation.IError.path} would be a little bit different
592
- * with individual {@link validateEquals} function. If the
593
- * {@link IValidation.IError} occurs from some parameter, the path would start
594
- * from `$input.parameters[number]`. Otherwise the path would start from
595
- * `$input.return`.
596
- *
597
- * - `$input.parameters[0].~`
598
- * - `$input.return.~`
599
- *
600
- * By the way, if what you want is not finding every type errors, but just
601
- * finding the 1st type error, then use {@link assertEqualsFunction} instead.
602
- * Otherwise, what you want is just validating parameters or return value only,
603
- * you can use {@link validateEqualsParameters} or {@link validateEqualsReturn}
604
- * instead.
605
- *
606
- * On the other hand, if you want to allow any superfluous properties, utilize
607
- * {@link validateFunction} or {@link assertFunction} instead.
608
- *
609
- * @author Jeongho Nam - https://github.com/samchon
610
- * @template T Target function type
611
- * @param func Target function to validate
612
- * @returns The wrapper function with type validations
613
- */
614
- export function validateEqualsFunction<T extends (...args: any[]) => any>(
615
- func: T,
616
- ): T extends (...args: infer Arguments) => infer Output
617
- ? Output extends Promise<infer R>
618
- ? (...args: Arguments) => Promise<IValidation<R>>
619
- : (...args: Arguments) => IValidation<Output>
620
- : never;
621
-
622
- /** @internal */
623
- export function validateEqualsFunction(): never {
624
- NoTransformConfigurationError("functional.validateEqualsFunction");
625
- }
626
-
627
- /**
628
- * Validates parameters with strict equality.
629
- *
630
- * Validates a function, by wrapping the function and checking its parameters
631
- * through {@link validateEquals} function. If some parameter does not match the
632
- * expected type, it returns {@link IValidation.IError} typed object. Otherwise
633
- * there's no type error, it returns {@link IValidation.ISuccess} typed object
634
- * instead.
635
- *
636
- * For reference, {@link IValidation.IError.path} would be a little bit different
637
- * with individual {@link validateEquals} function. If the
638
- * {@link IValidation.IError} occurs from some parameter, the path would start
639
- * from `$input.parameters[number]`.
640
- *
641
- * By the way, if what you want is not finding every type errors, but just
642
- * finding the 1st type error, then use {@link assertEqualsParameters} instead.
643
- * Otherwise, what you want is not only validating parameters, but also
644
- * validating return value, you can use {@link validateEqualsFunction} instead.
645
- *
646
- * On the other hand, if you want to allow any superfluous properties, utilize
647
- * {@link validateParameters} or {@link assertParameters} instead.
648
- *
649
- * @author Jeongho Nam - https://github.com/samchon
650
- * @template T Target function type
651
- * @param func Target function to validate
652
- * @returns The wrapper function with type validations
653
- */
654
- export function validateEqualsParameters<T extends (...args: any[]) => any>(
655
- func: T,
656
- ): T extends (...args: infer Arguments) => infer Output
657
- ? Output extends Promise<infer R>
658
- ? (...args: Arguments) => Promise<IValidation<R>>
659
- : (...args: Arguments) => IValidation<Output>
660
- : never;
661
-
662
- /** @internal */
663
- export function validateEqualsParameters(): never {
664
- NoTransformConfigurationError("functional.validateEqualsParameters");
665
- }
666
-
667
- /**
668
- * Validates return value with strict equality.
669
- *
670
- * Validates a function, by wrapping the function and checking its return value
671
- * through {@link validateEquals} function. If the return value does not match
672
- * the expected type, it returns {@link IValidation.IError} typed object.
673
- * Otherwise there's no type error, it returns {@link IValidation.ISuccess} typed
674
- * object instead.
675
- *
676
- * For reference, {@link IValidation.IError.path} would be a little bit different
677
- * with individual {@link validateEquals} function. If the
678
- * {@link IValidation.IError} occurs from the return value, the path would start
679
- * from `$input.return`.
680
- *
681
- * By the way, if what you want is not finding every type errors, but just
682
- * finding the 1st type error, then use {@link assertEqualsReturn} instead.
683
- * Otherwise, what you want is not only validating return value, but also
684
- * validating parameters, you can use {@link validateEqualsFunction} instead.
685
- *
686
- * On the other hand, if you want to allow any superfluous properties, utilize
687
- * {@link validateReturn} or {@link assertReturn} instead.
688
- *
689
- * @author Jeongho Nam - https://github.com/samchon
690
- * @template T Target function type
691
- * @param func Target function to validate
692
- * @returns The wrapper function with type validations
693
- */
694
- export function validateEqualsReturn<T extends (...args: any[]) => any>(
695
- func: T,
696
- ): T extends (...args: infer Arguments) => infer Output
697
- ? Output extends Promise<infer R>
698
- ? (...args: Arguments) => Promise<IValidation<R>>
699
- : (...args: Arguments) => IValidation<Output>
700
- : never;
701
-
702
- /** @internal */
703
- export function validateEqualsReturn(): never {
704
- NoTransformConfigurationError("functional.validateEqualsReturn");
705
- }
1
+ import { NoTransformConfigurationError } from "./transformers/NoTransformConfigurationError";
2
+
3
+ import { IValidation } from "./IValidation";
4
+ import { TypeGuardError } from "./TypeGuardError";
5
+
6
+ /* ===========================================================
7
+ FUNCTIONAL
8
+ - ASSERT
9
+ - IS
10
+ - VALIDATE
11
+ ==============================================================
12
+ ASSERT
13
+ ----------------------------------------------------------- */
14
+ /**
15
+ * Asserts a function.
16
+ *
17
+ * Asserts a function, by wrapping the function and checking its parameters and
18
+ * return value through {@link assert} function. If some parameter or return
19
+ * value does not match the expected type, it throws an {@link TypeGuardError} or
20
+ * a custom error generated by the _errorFactory_ parameter.
21
+ *
22
+ * For reference, {@link TypeGuardError.path} would be a little bit different
23
+ * with individual {@link assert} function. If the {@link TypeGuardError} occurs
24
+ * from some parameter, the path would start from `$input.parameters[number]`.
25
+ * Otherwise the path would start from `$input.return`.
26
+ *
27
+ * - `$input.parameters[0].~`
28
+ * - `$input.return.~`
29
+ *
30
+ * By the way, if what you want is not just finding the 1st type error through
31
+ * assertion, but also finding every type errors, then use
32
+ * {@link validateFunction} instead. Otherwise, what you want is just asserting
33
+ * parameters or return value only, you can use {@link assertParameters} or
34
+ * {@link assertReturn} instead.
35
+ *
36
+ * On the other hand, if don't want to allow any superfluous properties, utilize
37
+ * {@link assertEqualsFunction} or {@link validateEqualsFunction} instead.
38
+ *
39
+ * @author Jeongho Nam - https://github.com/samchon
40
+ * @template T Target function type
41
+ * @param func Target function to assert
42
+ * @param errorFactory Custom error factory. Default is `TypeGuardError`
43
+ * @returns The wrapper function with type assertions
44
+ * @throws A {@link TypeGuardError} or a custom error generated by _errorFactory_
45
+ */
46
+ export function assertFunction<T extends (...args: any[]) => any>(
47
+ func: T,
48
+ errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
49
+ ): T;
50
+
51
+ /** @internal */
52
+ export function assertFunction(): never {
53
+ NoTransformConfigurationError("functional.assertFunction");
54
+ }
55
+
56
+ /**
57
+ * Asserts parameters.
58
+ *
59
+ * Asserts a function, by wrapping the function and checking its parameters
60
+ * through {@link assert} function. If some parameter does not match the expected
61
+ * type, it throws an {@link TypeGuardError} or a custom error generated by the
62
+ * _errorFactory_ parameter.
63
+ *
64
+ * For reference, {@link TypeGuardError.path} would be a little bit different
65
+ * with individual {@link assert} function. If the {@link TypeGuardError} occurs
66
+ * from some parameter, the path would start from `$input.parameters[number]`.
67
+ *
68
+ * By the way, if what you want is not just finding the 1st type error through
69
+ * assertion, but also finding every type errors, then use
70
+ * {@link validateParameters} instead. Otherwise, what you want is not only
71
+ * asserting parameters, but also asserting return value, you can use
72
+ * {@link assertFunction} instead.
73
+ *
74
+ * On the other hand, if don't want to allow any superfluous properties, utilize
75
+ * {@link assertEqualsParameters} or {@link validateEqualsParameters} instead.
76
+ *
77
+ * @author Jeongho Nam - https://github.com/samchon
78
+ * @template T Target function type
79
+ * @param func Target function to assert
80
+ * @param errorFactory Custom error factory. Default is `TypeGuardError`
81
+ * @returns The wrapper function with type assertions
82
+ * @throws A {@link TypeGuardError} or a custom error generated by _errorFactory_
83
+ */
84
+ export function assertParameters<T extends (...args: any[]) => any>(
85
+ func: T,
86
+ errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
87
+ ): T;
88
+
89
+ /** @internal */
90
+ export function assertParameters(): never {
91
+ NoTransformConfigurationError("functional.assertParameters");
92
+ }
93
+
94
+ /**
95
+ * Asserts return value.
96
+ *
97
+ * Asserts a function, by wrapping the function and checking its return value
98
+ * through {@link assert} function. If the return value does not match the
99
+ * expected type, it throws an {@link TypeGuardError} or a custom error generated
100
+ * by the _errorFactory_ parameter.
101
+ *
102
+ * For reference, {@link TypeGuardError.path} would be a little bit different
103
+ * with individual {@link assert} function. If the {@link TypeGuardError} occurs
104
+ * from the return value, the path would start from `$input.return`.
105
+ *
106
+ * By the way, if what you want is not just finding the 1st type error through
107
+ * assertion, but also finding every type errors, then use {@link validateReturn}
108
+ * instead. Otherwise, what you want is not only asserting return value, but
109
+ * also asserting parameters, you can use {@link assertFunction} instead.
110
+ *
111
+ * On the other hand, if don't want to allow any superfluous properties, utilize
112
+ * {@link assertEqualsReturn} or {@link validateEqualsReturn} instead.
113
+ *
114
+ * @author Jeongho Nam - https://github.com/samchon
115
+ * @template T Target function type
116
+ * @param func Target function to assert
117
+ * @param errorFactory Custom error factory. Default is `TypeGuardError`
118
+ * @returns The wrapper function with type assertions
119
+ * @throws A {@link TypeGuardError} or a custom error generated by _errorFactory_
120
+ */
121
+ export function assertReturn<T extends (...args: any[]) => any>(
122
+ func: T,
123
+ errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
124
+ ): T;
125
+
126
+ /** @internal */
127
+ export function assertReturn(): never {
128
+ NoTransformConfigurationError("functional.assertReturn");
129
+ }
130
+
131
+ /**
132
+ * Asserts a function with strict equality.
133
+ *
134
+ * Asserts a function with strict equality, by wrapping the function and
135
+ * checking its parameters and return value through {@link assertEquals}
136
+ * function. If some parameter or return value does not match the expected type,
137
+ * it throws an {@link TypeGuardError} or a custom error generated by the
138
+ * _errorFactory_ parameter.
139
+ *
140
+ * For reference, {@link TypeGuardError.path} would be a little bit different
141
+ * with individual {@link assertEquals} function. If the {@link TypeGuardError}
142
+ * occurs from some parameter, the path would start from
143
+ * `$input.parameters[number]`. Otherwise the path would start from
144
+ * `$input.return`.
145
+ *
146
+ * - `$input.parameters[0].~`
147
+ * - `$input.return.~`
148
+ *
149
+ * By the way, if what you want is not just finding the 1st type error through
150
+ * assertion, but also finding every type errors, then use
151
+ * {@link validateEqualsFunction} instead. Otherwise, what you want is just
152
+ * asserting parameters or return value only, you can use
153
+ * {@link assertEqualsParameters} or {@link assertEqualsReturn} instead.
154
+ *
155
+ * On the other hand, if you want to allow any superfluous properties, utilize
156
+ * {@link assertFunction} or {@link validateFunction} instead.
157
+ *
158
+ * @author Jeongho Nam - https://github.com/samchon
159
+ * @template T Target function type
160
+ * @param func Target function to assert
161
+ * @param errorFactory Custom error factory. Default is `TypeGuardError`
162
+ * @returns The wrapper function with type assertions
163
+ * @throws A {@link TypeGuardError} or a custom error generated by _errorFactory_
164
+ */
165
+ export function assertEqualsFunction<T extends (...args: any[]) => any>(
166
+ func: T,
167
+ errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
168
+ ): T;
169
+
170
+ /** @internal */
171
+ export function assertEqualsFunction(): never {
172
+ NoTransformConfigurationError("functional.assertEqualsFunction");
173
+ }
174
+
175
+ /**
176
+ * Asserts parameters with strict equality.
177
+ *
178
+ * Asserts a function, by wrapping the function and checking its parameters
179
+ * through {@link assertEquals} function. If some parameter does not match the
180
+ * expected type, it throws an {@link TypeGuardError} or a custom error generated
181
+ * by the _errorFactory_ parameter.
182
+ *
183
+ * For reference, {@link TypeGuardError.path} would be a little bit different
184
+ * with individual {@link assertEquals} function. If the {@link TypeGuardError}
185
+ * occurs from some parameter, the path would start from
186
+ * `$input.parameters[number]`.
187
+ *
188
+ * By the way, if what you want is not just finding the 1st type error through
189
+ * assertion, but also finding every type errors, then use
190
+ * {@link validateEqualsParameters} instead. Otherwise, what you want is not only
191
+ * asserting parameters, but also asserting return value, you can use
192
+ * {@link assertEqualsFunction} instead.
193
+ *
194
+ * On the other hand, if you want to allow any superfluous properties, utilize
195
+ * {@link assertParameters} or {@link validateParameters} instead.
196
+ *
197
+ * @author Jeongho Nam - https://github.com/samchon
198
+ * @template T Target function type
199
+ * @param func Target function to assert
200
+ * @param errorFactory Custom error factory. Default is `TypeGuardError`
201
+ * @returns The wrapper function with type assertions
202
+ * @throws A {@link TypeGuardError} or a custom error generated by _errorFactory_
203
+ */
204
+ export function assertEqualsParameters<T extends (...args: any[]) => any>(
205
+ func: T,
206
+ errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
207
+ ): T;
208
+
209
+ /** @internal */
210
+ export function assertEqualsParameters(): never {
211
+ NoTransformConfigurationError("functional.assertEqualsParameters");
212
+ }
213
+
214
+ /**
215
+ * Asserts return value with strict equality.
216
+ *
217
+ * Asserts a function, by wrapping the function and checking its return value
218
+ * through {@link assertEquals} function. If the return value does not match the
219
+ * expected type, it throws an {@link TypeGuardError} or a custom error generated
220
+ * by the _errorFactory_ parameter.
221
+ *
222
+ * For reference, {@link TypeGuardError.path} would be a little bit different
223
+ * with individual {@link assertEquals} function. If the {@link TypeGuardError}
224
+ * occurs from the return value, the path would start from `$input.return`.
225
+ *
226
+ * By the way, if what you want is not just finding the 1st type error through
227
+ * assertion, but also finding every type errors, then use
228
+ * {@link validateEqualsReturn} instead. Otherwise, what you want is not only
229
+ * asserting return value, but also asserting parameters, you can use
230
+ * {@link assertEqualsFunction} instead.
231
+ *
232
+ * On the other hand, if you want to allow any superfluous properties, utilize
233
+ * {@link assertReturn} or {@link validateReturn} instead.
234
+ *
235
+ * @author Jeongho Nam - https://github.com/samchon
236
+ * @template T Target function type
237
+ * @param func Target function to assert
238
+ * @param errorFactory Custom error factory. Default is `TypeGuardError`
239
+ * @returns The wrapper function with type assertions
240
+ * @throws A {@link TypeGuardError} or a custom error generated by _errorFactory_
241
+ */
242
+ export function assertEqualsReturn<T extends (...args: any[]) => any>(
243
+ func: T,
244
+ errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
245
+ ): T;
246
+
247
+ /** @internal */
248
+ export function assertEqualsReturn(): never {
249
+ NoTransformConfigurationError("functional.assertEqualsReturn");
250
+ }
251
+
252
+ /* -----------------------------------------------------------
253
+ IS
254
+ ----------------------------------------------------------- */
255
+ /**
256
+ * Tests a function.
257
+ *
258
+ * Tests a function, by wrapping the function and checking its parameters and
259
+ * return value through {@link is} function. If some parameter or return value
260
+ * does not match the expected type, it returns `null`. Otherwise there's no
261
+ * type error, it returns the result of the function.
262
+ *
263
+ * By the way, if you want is not just testing type checking, but also finding
264
+ * detailed type error reason(s), then use {@link assertFunction} or
265
+ * {@link validateFunction} instead.
266
+ *
267
+ * On the other hand, if you don't want to allow any superfluous properties,
268
+ * utilize {@link equalsFunction}, {@link assertEqualsFunction} or
269
+ * {@link validateEqualsFunction} instead.
270
+ *
271
+ * @author Jeongho Nam - https://github.com/samchon
272
+ * @template T Target function type
273
+ * @param func Target function to test
274
+ * @returns The wrapper function with type tests
275
+ */
276
+ export function isFunction<T extends (...args: any[]) => any>(
277
+ func: T,
278
+ ): T extends (...args: infer Arguments) => infer Output
279
+ ? Output extends Promise<infer R>
280
+ ? (...args: Arguments) => Promise<R | null>
281
+ : (...args: Arguments) => Output | null
282
+ : never;
283
+
284
+ /** @internal */
285
+ export function isFunction(): never {
286
+ NoTransformConfigurationError("functional.isFunction");
287
+ }
288
+
289
+ /**
290
+ * Tests parameters.
291
+ *
292
+ * Tests a function, by wrapping the function and checking its parameters
293
+ * through {@link is} function. If some parameter does not match the expected
294
+ * type, it returns `null`. Otherwise there's no type error, it returns the
295
+ * result of the function.
296
+ *
297
+ * By the way, if you want is not just testing type checking, but also finding
298
+ * detailed type error reason(s), then use {@link assertParameters} or
299
+ * {@link validateParameters} instead.
300
+ *
301
+ * On the other hand, if you don't want to allow any superfluous properties,
302
+ * utilize {@link equalsParameters}, {@link assertEqualsParameters} or
303
+ * {@link validateEqualsParameters} instead.
304
+ *
305
+ * @author Jeongho Nam - https://github.com/samchon
306
+ * @template T Target function type
307
+ * @param func Target function to test
308
+ * @returns The wrapper function with type tests
309
+ */
310
+ export function isParameters<T extends (...args: any[]) => any>(
311
+ func: T,
312
+ ): T extends (...args: infer Arguments) => infer Output
313
+ ? Output extends Promise<infer R>
314
+ ? (...args: Arguments) => Promise<R | null>
315
+ : (...args: Arguments) => Output | null
316
+ : never;
317
+
318
+ /** @internal */
319
+ export function isParameters(): never {
320
+ NoTransformConfigurationError("functional.isParameters");
321
+ }
322
+
323
+ /**
324
+ * Tests return value.
325
+ *
326
+ * Tests a function, by wrapping the function and checking its return value
327
+ * through {@link is} function. If the return value does not match the expected
328
+ * type, it returns `null`. Otherwise there's no type error, it returns the
329
+ * result of the function.
330
+ *
331
+ * By the way, if you want is not just testing type checking, but also finding
332
+ * detailed type error reason(s), then use {@link assertReturn} or
333
+ * {@link validateReturn} instead.
334
+ *
335
+ * On the other hand, if you don't want to allow any superfluous properties,
336
+ * utilize {@link equalsReturn}, {@link assertEqualsReturn} or
337
+ * {@link validateEqualsReturn} instead.
338
+ *
339
+ * @author Jeongho Nam - https://github.com/samchon
340
+ * @template T Target function type
341
+ * @param func Target function to test
342
+ * @returns The wrapper function with type tests
343
+ */
344
+ export function isReturn<T extends (...args: any[]) => any>(
345
+ func: T,
346
+ ): T extends (...args: infer Arguments) => infer Output
347
+ ? Output extends Promise<infer R>
348
+ ? (...args: Arguments) => Promise<R | null>
349
+ : (...args: Arguments) => Output | null
350
+ : never;
351
+
352
+ /** @internal */
353
+ export function isReturn(): never {
354
+ NoTransformConfigurationError("functional.isReturn");
355
+ }
356
+
357
+ /**
358
+ * Tests a function with strict equality.
359
+ *
360
+ * Tests a function with strict equality, by wrapping the function and checking
361
+ * its parameters and return value through {@link isEquals} function. If some
362
+ * parameter or return value does not match the expected type, it returns
363
+ * `null`. Otherwise there's no type error, it returns the result of the
364
+ * function.
365
+ *
366
+ * By the way, if you want is not just testing type checking, but also finding
367
+ * detailed type error reason(s), then use {@link assertEqualsFunction} or
368
+ * {@link validateEqualsFunction} instead.
369
+ *
370
+ * On the other hand, if you want to allow any superfluous properties, utilize
371
+ * {@link isFunction}, {@link assertFunction} or {@link validateFunction} instead.
372
+ *
373
+ * @author Jeongho Nam - https://github.com/samchon
374
+ * @template T Target function type
375
+ * @param func Target function to test
376
+ * @returns The wrapper function with type tests
377
+ */
378
+ export function equalsFunction<T extends (...args: any[]) => any>(
379
+ func: T,
380
+ ): T extends (...args: infer Arguments) => infer Output
381
+ ? Output extends Promise<infer R>
382
+ ? (...args: Arguments) => Promise<R | null>
383
+ : (...args: Arguments) => Output | null
384
+ : never;
385
+
386
+ /** @internal */
387
+ export function equalsFunction(): never {
388
+ NoTransformConfigurationError("functional.equalsFunction");
389
+ }
390
+
391
+ /**
392
+ * Tests parameters with strict equality.
393
+ *
394
+ * Tests a function, by wrapping the function and checking its parameters
395
+ * through {@link isEquals} function. If some parameter does not match the
396
+ * expected type, it returns `null`. Otherwise there's no type error, it returns
397
+ * the result of the function.
398
+ *
399
+ * By the way, if you want is not just testing type checking, but also finding
400
+ * detailed type error reason(s), then use {@link assertEqualsParameters} or
401
+ * {@link validateEqualsParameters} instead.
402
+ *
403
+ * @author Jeongho Nam - https://github.com/samchon
404
+ * @template T Target function type
405
+ * @param func Target function to test
406
+ * @returns The wrapper function with type tests
407
+ */
408
+ export function equalsParameters<T extends (...args: any[]) => any>(
409
+ func: T,
410
+ ): T extends (...args: infer Arguments) => infer Output
411
+ ? Output extends Promise<infer R>
412
+ ? (...args: Arguments) => Promise<R | null>
413
+ : (...args: Arguments) => Output | null
414
+ : never;
415
+
416
+ /** @internal */
417
+ export function equalsParameters(): never {
418
+ NoTransformConfigurationError("functional.equalsParameters");
419
+ }
420
+
421
+ /**
422
+ * Tests return value with strict equality.
423
+ *
424
+ * Tests a function, by wrapping the function and checking its return value
425
+ * through {@link isEquals} function. If the return value does not match the
426
+ * expected type, it returns `null`. Otherwise there's no type error, it returns
427
+ * the result of the function.
428
+ *
429
+ * By the way, if you want is not just testing type checking, but also finding
430
+ * detailed type error reason(s), then use {@link assertEqualsReturn} or
431
+ * {@link validateEqualsReturn} instead.
432
+ *
433
+ * On the other hand, if you want to allow any superfluous properties, utilize
434
+ * {@link isReturn}, {@link assertReturn} or {@link validateReturn} instead.
435
+ *
436
+ * @author Jeongho Nam - https://github.com/samchon
437
+ * @template T Target function type
438
+ * @param func Target function to test
439
+ * @returns The wrapper function with type tests
440
+ */
441
+ export function equalsReturn<T extends (...args: any[]) => any>(
442
+ func: T,
443
+ ): T extends (...args: infer Arguments) => infer Output
444
+ ? Output extends Promise<infer R>
445
+ ? (...args: Arguments) => Promise<R | null>
446
+ : (...args: Arguments) => Output | null
447
+ : never;
448
+
449
+ /** @internal */
450
+ export function equalsReturn(): never {
451
+ NoTransformConfigurationError("functional.equalsReturn");
452
+ }
453
+
454
+ /* -----------------------------------------------------------
455
+ VALIDATE
456
+ ----------------------------------------------------------- */
457
+ /**
458
+ * Validates a function.
459
+ *
460
+ * Validates a function, by wrapping the function and checking its parameters
461
+ * and return value through {@link validate} function. If some parameter or
462
+ * return value does not match the expected type, it returns
463
+ * {@link IValidation.IError} typed object. Otherwise there's no type error, it
464
+ * returns {@link IValidation.ISuccess} typed object instead.
465
+ *
466
+ * For reference, {@link IValidation.IError.path} would be a little bit different
467
+ * with individual {@link validate} function. If the {@link IValidation.IError}
468
+ * occurs from some parameter, the path would start from
469
+ * `$input.parameters[number]`. Otherwise the path would start from
470
+ * `$input.return`.
471
+ *
472
+ * - `$input.parameters[0].~`
473
+ * - `$input.return.~`
474
+ *
475
+ * By the way, if what you want is not finding every type errors, but just
476
+ * finding the 1st type error, then use {@link assertFunction} instead.
477
+ * Otherwise, what you want is just validating parameters or return value only,
478
+ * you can use {@link validateParameters} or {@link validateReturn} instead.
479
+ *
480
+ * On the other hand, if you don't want to allow any superfluous properties,
481
+ * utilize {@link validateEqualsFunction} or {@link assertEqualsFunction}
482
+ * instead.
483
+ *
484
+ * @author Jeongho Nam - https://github.com/samchon
485
+ * @template T Target function type
486
+ * @param func Target function to validate
487
+ * @returns The wrapper function with type validations
488
+ */
489
+ export function validateFunction<T extends (...args: any[]) => any>(
490
+ func: T,
491
+ ): T extends (...args: infer Arguments) => infer Output
492
+ ? Output extends Promise<infer R>
493
+ ? (...args: Arguments) => Promise<IValidation<R>>
494
+ : (...args: Arguments) => IValidation<Output>
495
+ : never;
496
+
497
+ /** @internal */
498
+ export function validateFunction(): never {
499
+ NoTransformConfigurationError("functional.validateFunction");
500
+ }
501
+
502
+ /**
503
+ * Validates parameters.
504
+ *
505
+ * Validates a function, by wrapping the function and checking its parameters
506
+ * through {@link validate} function. If some parameter does not match the
507
+ * expected type, it returns {@link IValidation.IError} typed object. Otherwise
508
+ * there's no type error, it returns {@link IValidation.ISuccess} typed object
509
+ * instead.
510
+ *
511
+ * For reference, {@link IValidation.IError.path} would be a little bit different
512
+ * with individual {@link validate} function. If the {@link IValidation.IError}
513
+ * occurs from some parameter, the path would start from
514
+ * `$input.parameters[number]`.
515
+ *
516
+ * By the way, if what you want is not finding every type errors, but just
517
+ * finding the 1st type error, then use {@link assertParameters} instead.
518
+ * Otherwise, what you want is not only validating parameters, but also
519
+ * validating return value, you can use {@link validateFunction} instead.
520
+ *
521
+ * On the other hand, if you don't want to allow any superfluous properties,
522
+ * utilize {@link validateEqualsParameters} or {@link assertEqualsParameters}
523
+ * instead.
524
+ *
525
+ * @author Jeongho Nam - https://github.com/samchon
526
+ * @template T Target function type
527
+ * @param func Target function to validate
528
+ * @returns The wrapper function with type validations
529
+ */
530
+ export function validateParameters<T extends (...args: any[]) => any>(
531
+ func: T,
532
+ ): T extends (...args: infer Arguments) => infer Output
533
+ ? Output extends Promise<infer R>
534
+ ? (...args: Arguments) => Promise<IValidation<R>>
535
+ : (...args: Arguments) => IValidation<Output>
536
+ : never;
537
+
538
+ /** @internal */
539
+ export function validateParameters(): never {
540
+ NoTransformConfigurationError("functional.validateParameters");
541
+ }
542
+
543
+ /**
544
+ * Validates return value.
545
+ *
546
+ * Validates a function, by wrapping the function and checking its return value
547
+ * through {@link validate} function. If the return value does not match the
548
+ * expected type, it returns {@link IValidation.IError} typed object. Otherwise
549
+ * there's no type error, it returns {@link IValidation.ISuccess} typed object
550
+ * instead.
551
+ *
552
+ * For reference, {@link IValidation.IError.path} would be a little bit different
553
+ * with individual {@link validate} function. If the {@link IValidation.IError}
554
+ * occurs from the return value, the path would start from `$input.return`.
555
+ *
556
+ * By the way, if what you want is not finding every type errors, but just
557
+ * finding the 1st type error, then use {@link assertReturn} instead. Otherwise,
558
+ * what you want is not only validating return value, but also validating
559
+ * parameters, you can use {@link validateFunction} instead.
560
+ *
561
+ * On the other hand, if you don't want to allow any superfluous properties,
562
+ * utilize {@link validateEqualsReturn} or {@link assertEqualsReturn} instead.
563
+ *
564
+ * @author Jeongho Nam - https://github.com/samchon
565
+ * @template T Target function type
566
+ * @param func Target function to validate
567
+ * @returns The wrapper function with type validations
568
+ */
569
+ export function validateReturn<T extends (...args: any[]) => any>(
570
+ func: T,
571
+ ): T extends (...args: infer Arguments) => infer Output
572
+ ? Output extends Promise<infer R>
573
+ ? (...args: Arguments) => Promise<IValidation<R>>
574
+ : (...args: Arguments) => IValidation<Output>
575
+ : never;
576
+
577
+ /** @internal */
578
+ export function validateReturn(): never {
579
+ NoTransformConfigurationError("functional.validateReturn");
580
+ }
581
+
582
+ /**
583
+ * Validates a function with strict equality.
584
+ *
585
+ * Validates a function with strict equality, by wrapping the function and
586
+ * checking its parameters and return value through {@link validateEquals}
587
+ * function. If some parameter or return value does not match the expected type,
588
+ * it returns {@link IValidation.IError} typed object. Otherwise there's no type
589
+ * error, it returns {@link IValidation.ISuccess} typed object instead.
590
+ *
591
+ * For reference, {@link IValidation.IError.path} would be a little bit different
592
+ * with individual {@link validateEquals} function. If the
593
+ * {@link IValidation.IError} occurs from some parameter, the path would start
594
+ * from `$input.parameters[number]`. Otherwise the path would start from
595
+ * `$input.return`.
596
+ *
597
+ * - `$input.parameters[0].~`
598
+ * - `$input.return.~`
599
+ *
600
+ * By the way, if what you want is not finding every type errors, but just
601
+ * finding the 1st type error, then use {@link assertEqualsFunction} instead.
602
+ * Otherwise, what you want is just validating parameters or return value only,
603
+ * you can use {@link validateEqualsParameters} or {@link validateEqualsReturn}
604
+ * instead.
605
+ *
606
+ * On the other hand, if you want to allow any superfluous properties, utilize
607
+ * {@link validateFunction} or {@link assertFunction} instead.
608
+ *
609
+ * @author Jeongho Nam - https://github.com/samchon
610
+ * @template T Target function type
611
+ * @param func Target function to validate
612
+ * @returns The wrapper function with type validations
613
+ */
614
+ export function validateEqualsFunction<T extends (...args: any[]) => any>(
615
+ func: T,
616
+ ): T extends (...args: infer Arguments) => infer Output
617
+ ? Output extends Promise<infer R>
618
+ ? (...args: Arguments) => Promise<IValidation<R>>
619
+ : (...args: Arguments) => IValidation<Output>
620
+ : never;
621
+
622
+ /** @internal */
623
+ export function validateEqualsFunction(): never {
624
+ NoTransformConfigurationError("functional.validateEqualsFunction");
625
+ }
626
+
627
+ /**
628
+ * Validates parameters with strict equality.
629
+ *
630
+ * Validates a function, by wrapping the function and checking its parameters
631
+ * through {@link validateEquals} function. If some parameter does not match the
632
+ * expected type, it returns {@link IValidation.IError} typed object. Otherwise
633
+ * there's no type error, it returns {@link IValidation.ISuccess} typed object
634
+ * instead.
635
+ *
636
+ * For reference, {@link IValidation.IError.path} would be a little bit different
637
+ * with individual {@link validateEquals} function. If the
638
+ * {@link IValidation.IError} occurs from some parameter, the path would start
639
+ * from `$input.parameters[number]`.
640
+ *
641
+ * By the way, if what you want is not finding every type errors, but just
642
+ * finding the 1st type error, then use {@link assertEqualsParameters} instead.
643
+ * Otherwise, what you want is not only validating parameters, but also
644
+ * validating return value, you can use {@link validateEqualsFunction} instead.
645
+ *
646
+ * On the other hand, if you want to allow any superfluous properties, utilize
647
+ * {@link validateParameters} or {@link assertParameters} instead.
648
+ *
649
+ * @author Jeongho Nam - https://github.com/samchon
650
+ * @template T Target function type
651
+ * @param func Target function to validate
652
+ * @returns The wrapper function with type validations
653
+ */
654
+ export function validateEqualsParameters<T extends (...args: any[]) => any>(
655
+ func: T,
656
+ ): T extends (...args: infer Arguments) => infer Output
657
+ ? Output extends Promise<infer R>
658
+ ? (...args: Arguments) => Promise<IValidation<R>>
659
+ : (...args: Arguments) => IValidation<Output>
660
+ : never;
661
+
662
+ /** @internal */
663
+ export function validateEqualsParameters(): never {
664
+ NoTransformConfigurationError("functional.validateEqualsParameters");
665
+ }
666
+
667
+ /**
668
+ * Validates return value with strict equality.
669
+ *
670
+ * Validates a function, by wrapping the function and checking its return value
671
+ * through {@link validateEquals} function. If the return value does not match
672
+ * the expected type, it returns {@link IValidation.IError} typed object.
673
+ * Otherwise there's no type error, it returns {@link IValidation.ISuccess} typed
674
+ * object instead.
675
+ *
676
+ * For reference, {@link IValidation.IError.path} would be a little bit different
677
+ * with individual {@link validateEquals} function. If the
678
+ * {@link IValidation.IError} occurs from the return value, the path would start
679
+ * from `$input.return`.
680
+ *
681
+ * By the way, if what you want is not finding every type errors, but just
682
+ * finding the 1st type error, then use {@link assertEqualsReturn} instead.
683
+ * Otherwise, what you want is not only validating return value, but also
684
+ * validating parameters, you can use {@link validateEqualsFunction} instead.
685
+ *
686
+ * On the other hand, if you want to allow any superfluous properties, utilize
687
+ * {@link validateReturn} or {@link assertReturn} instead.
688
+ *
689
+ * @author Jeongho Nam - https://github.com/samchon
690
+ * @template T Target function type
691
+ * @param func Target function to validate
692
+ * @returns The wrapper function with type validations
693
+ */
694
+ export function validateEqualsReturn<T extends (...args: any[]) => any>(
695
+ func: T,
696
+ ): T extends (...args: infer Arguments) => infer Output
697
+ ? Output extends Promise<infer R>
698
+ ? (...args: Arguments) => Promise<IValidation<R>>
699
+ : (...args: Arguments) => IValidation<Output>
700
+ : never;
701
+
702
+ /** @internal */
703
+ export function validateEqualsReturn(): never {
704
+ NoTransformConfigurationError("functional.validateEqualsReturn");
705
+ }