typia 5.2.7-dev.20231109 → 5.3.0-dev.20231117
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.
- package/lib/AssertionGuard.d.ts +1 -0
- package/lib/{schemas/metadata/IMetadataCollection.js → AssertionGuard.js} +1 -1
- package/lib/AssertionGuard.js.map +1 -0
- package/lib/factories/MetadataCollection.d.ts +2 -2
- package/lib/factories/MetadataFactory.js +3 -2
- package/lib/factories/MetadataFactory.js.map +1 -1
- package/lib/factories/internal/metadata/MetadataHelper.js +3 -2
- package/lib/factories/internal/metadata/MetadataHelper.js.map +1 -1
- package/lib/factories/internal/metadata/iterate_metadata_constant.js +13 -8
- package/lib/factories/internal/metadata/iterate_metadata_constant.js.map +1 -1
- package/lib/factories/internal/metadata/iterate_metadata_intersection.js +8 -5
- package/lib/factories/internal/metadata/iterate_metadata_intersection.js.map +1 -1
- package/lib/functional/$from.d.ts +3 -0
- package/lib/functional/$from.js +9 -0
- package/lib/functional/$from.js.map +1 -0
- package/lib/functional/Namespace.js +7 -0
- package/lib/functional/Namespace.js.map +1 -1
- package/lib/module.d.ts +209 -0
- package/lib/module.js +23 -5
- package/lib/module.js.map +1 -1
- package/lib/programmers/AssertProgrammer.d.ts +4 -1
- package/lib/programmers/AssertProgrammer.js +16 -9
- package/lib/programmers/AssertProgrammer.js.map +1 -1
- package/lib/programmers/helpers/ProtobufUtil.js.map +1 -1
- package/lib/programmers/internal/check_string.js +7 -4
- package/lib/programmers/internal/check_string.js.map +1 -1
- package/lib/programmers/internal/metadata_to_pattern.js +3 -1
- package/lib/programmers/internal/metadata_to_pattern.js.map +1 -1
- package/lib/reflect.d.ts +3 -0
- package/lib/reflect.js +13 -0
- package/lib/reflect.js.map +1 -0
- package/lib/schemas/metadata/IMetadataApplication.d.ts +2 -2
- package/lib/schemas/metadata/{IMetadataCollection.d.ts → IMetadataComponents.d.ts} +1 -1
- package/lib/schemas/metadata/IMetadataComponents.js +3 -0
- package/lib/schemas/metadata/IMetadataComponents.js.map +1 -0
- package/lib/schemas/metadata/IMetadataConstant.d.ts +1 -1
- package/lib/schemas/metadata/IMetadataTypeTag.d.ts +2 -2
- package/lib/schemas/metadata/Metadata.d.ts +2 -2
- package/lib/schemas/metadata/Metadata.js +81 -167
- package/lib/schemas/metadata/Metadata.js.map +1 -1
- package/lib/schemas/metadata/MetadataAlias.js +1 -1
- package/lib/schemas/metadata/MetadataAlias.js.map +1 -1
- package/lib/schemas/metadata/MetadataApplication.d.ts +13 -0
- package/lib/schemas/metadata/MetadataApplication.js +30 -0
- package/lib/schemas/metadata/MetadataApplication.js.map +1 -0
- package/lib/schemas/metadata/MetadataArrayType.js +1 -1
- package/lib/schemas/metadata/MetadataArrayType.js.map +1 -1
- package/lib/schemas/metadata/MetadataAtomic.d.ts +1 -0
- package/lib/schemas/metadata/MetadataAtomic.js +28 -1
- package/lib/schemas/metadata/MetadataAtomic.js.map +1 -1
- package/lib/schemas/metadata/MetadataComponents.d.ts +16 -0
- package/lib/schemas/metadata/MetadataComponents.js +151 -0
- package/lib/schemas/metadata/MetadataComponents.js.map +1 -0
- package/lib/schemas/metadata/MetadataConstant.d.ts +9 -1
- package/lib/schemas/metadata/MetadataConstant.js +29 -0
- package/lib/schemas/metadata/MetadataConstant.js.map +1 -1
- package/lib/schemas/metadata/MetadataEscaped.js +4 -4
- package/lib/schemas/metadata/MetadataEscaped.js.map +1 -1
- package/lib/schemas/metadata/MetadataObject.js +2 -2
- package/lib/schemas/metadata/MetadataObject.js.map +1 -1
- package/lib/schemas/metadata/MetadataProperty.js +4 -4
- package/lib/schemas/metadata/MetadataProperty.js.map +1 -1
- package/lib/schemas/metadata/MetadataTupleType.js +1 -1
- package/lib/schemas/metadata/MetadataTupleType.js.map +1 -1
- package/lib/transformers/CallExpressionTransformer.js +35 -8
- package/lib/transformers/CallExpressionTransformer.js.map +1 -1
- package/lib/transformers/features/AssertTransformer.d.ts +4 -1
- package/lib/transformers/features/AssertTransformer.js +9 -3
- package/lib/transformers/features/AssertTransformer.js.map +1 -1
- package/lib/transformers/features/CreateAssertTransformer.d.ts +4 -1
- package/lib/transformers/features/CreateAssertTransformer.js +9 -3
- package/lib/transformers/features/CreateAssertTransformer.js.map +1 -1
- package/lib/transformers/features/reflect/ReflectMetadataTransformer.d.ts +5 -0
- package/lib/transformers/features/reflect/ReflectMetadataTransformer.js +58 -0
- package/lib/transformers/features/reflect/ReflectMetadataTransformer.js.map +1 -0
- package/package.json +1 -1
- package/src/AssertionGuard.ts +1 -0
- package/src/factories/MetadataCollection.ts +2 -2
- package/src/factories/MetadataFactory.ts +7 -4
- package/src/factories/internal/metadata/MetadataHelper.ts +7 -4
- package/src/factories/internal/metadata/iterate_metadata_constant.ts +10 -8
- package/src/factories/internal/metadata/iterate_metadata_intersection.ts +9 -8
- package/src/functional/$from.ts +5 -0
- package/src/functional/Namespace.ts +7 -0
- package/src/module.ts +253 -19
- package/src/programmers/AssertProgrammer.ts +31 -11
- package/src/programmers/helpers/ProtobufUtil.ts +3 -2
- package/src/programmers/internal/check_string.ts +5 -2
- package/src/programmers/internal/metadata_to_pattern.ts +3 -1
- package/src/reflect.ts +24 -0
- package/src/schemas/metadata/IMetadataApplication.ts +2 -2
- package/src/schemas/metadata/{IMetadataCollection.ts → IMetadataComponents.ts} +1 -1
- package/src/schemas/metadata/IMetadataConstant.ts +1 -1
- package/src/schemas/metadata/IMetadataTypeTag.ts +2 -2
- package/src/schemas/metadata/Metadata.ts +17 -85
- package/src/schemas/metadata/MetadataAlias.ts +1 -1
- package/src/schemas/metadata/MetadataApplication.ts +44 -0
- package/src/schemas/metadata/MetadataArrayType.ts +1 -1
- package/src/schemas/metadata/MetadataAtomic.ts +28 -1
- package/src/schemas/metadata/MetadataComponents.ts +98 -0
- package/src/schemas/metadata/MetadataConstant.ts +44 -1
- package/src/schemas/metadata/MetadataEscaped.ts +4 -4
- package/src/schemas/metadata/MetadataObject.ts +2 -2
- package/src/schemas/metadata/MetadataProperty.ts +4 -7
- package/src/schemas/metadata/MetadataTupleType.ts +1 -1
- package/src/transformers/CallExpressionTransformer.ts +25 -8
- package/src/transformers/features/AssertTransformer.ts +11 -3
- package/src/transformers/features/CreateAssertTransformer.ts +9 -3
- package/src/transformers/features/{misc/MetadataTransformer.ts → reflect/ReflectMetadataTransformer.ts} +19 -5
- package/lib/schemas/metadata/IMetadataCollection.js.map +0 -1
- package/lib/transformers/features/misc/MetadataTransformer.d.ts +0 -5
- package/lib/transformers/features/misc/MetadataTransformer.js +0 -54
- package/lib/transformers/features/misc/MetadataTransformer.js.map +0 -1
package/src/module.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Namespace } from "./functional/Namespace";
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
|
|
3
|
+
import { AssertionGuard } from "./AssertionGuard";
|
|
5
4
|
import { IRandomGenerator } from "./IRandomGenerator";
|
|
6
5
|
import { IValidation } from "./IValidation";
|
|
7
6
|
import { Resolved } from "./Resolved";
|
|
@@ -11,11 +10,13 @@ export * as json from "./json";
|
|
|
11
10
|
export * as misc from "./misc";
|
|
12
11
|
export * as notations from "./notations";
|
|
13
12
|
export * as protobuf from "./protobuf";
|
|
13
|
+
export * as reflect from "./reflect";
|
|
14
14
|
export * as tags from "./tags";
|
|
15
15
|
|
|
16
16
|
export * from "./schemas/json/IJsonApplication";
|
|
17
17
|
export * from "./schemas/json/IJsonComponents";
|
|
18
18
|
export * from "./schemas/json/IJsonSchema";
|
|
19
|
+
export * from "./AssertionGuard";
|
|
19
20
|
export * from "./IRandomGenerator";
|
|
20
21
|
export * from "./IValidation";
|
|
21
22
|
export * from "./TypeGuardError";
|
|
@@ -39,6 +40,8 @@ export * from "./SnakeCase";
|
|
|
39
40
|
* If what you want is not asserting but just knowing whether the parametric value is
|
|
40
41
|
* following the type `T` or not, you can choose the {@link is} function instead.
|
|
41
42
|
* Otherwise you want to know all the errors, {@link validate} is the way to go.
|
|
43
|
+
* Also, if you want to automatically cast the parametric value to the type `T`
|
|
44
|
+
* when no problem (perform the assertion guard of type).
|
|
42
45
|
*
|
|
43
46
|
* On the other and, if you don't want to allow any superfluous property that is not
|
|
44
47
|
* enrolled to the type `T`, you can use {@link assertEquals} function instead.
|
|
@@ -83,6 +86,66 @@ export function assert(): never {
|
|
|
83
86
|
}
|
|
84
87
|
Object.assign(assert, Namespace.assert("assert"));
|
|
85
88
|
|
|
89
|
+
/**
|
|
90
|
+
* Assertion guard of a value type.
|
|
91
|
+
*
|
|
92
|
+
* Asserts a parametric value type and throws a {@link TypeGuardError} with detailed
|
|
93
|
+
* reason, if the parametric value is not following the type `T`. Otherwise, the
|
|
94
|
+
* value is following the type `T`, nothing would be returned, but the input value
|
|
95
|
+
* would be automatically casted to the type `T`. This is the concept of
|
|
96
|
+
* "assertion guard" of a value type.
|
|
97
|
+
*
|
|
98
|
+
* If what you want is not asserting but just knowing whether the parametric value is
|
|
99
|
+
* following the type `T` or not, you can choose the {@link is} function instead.
|
|
100
|
+
* Otherwise you want to know all the errors, {@link validate} is the way to go.
|
|
101
|
+
* Also, if you want to returns the parametric value when no problem, you can use
|
|
102
|
+
* {@link assert} function instead.
|
|
103
|
+
*
|
|
104
|
+
* On the other and, if you don't want to allow any superfluous property that is not
|
|
105
|
+
* enrolled to the type `T`, you can use {@link assertGuardEquals} function instead.
|
|
106
|
+
*
|
|
107
|
+
* @template T Type of the input value
|
|
108
|
+
* @param input A value to be asserted
|
|
109
|
+
* @throws A {@link TypeGuardError} instance with detailed reason
|
|
110
|
+
*
|
|
111
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
112
|
+
*/
|
|
113
|
+
export function assertGuard<T>(input: T): asserts input is T;
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Assertion guard of a value type.
|
|
117
|
+
*
|
|
118
|
+
* Asserts a parametric value type and throws a {@link TypeGuardError} with detailed
|
|
119
|
+
* reason, if the parametric value is not following the type `T`. Otherwise, the
|
|
120
|
+
* value is following the type `T`, nothing would be returned, but the input value
|
|
121
|
+
* would be automatically casted to the type `T`. This is the concept of
|
|
122
|
+
* "assertion guard" of a value type.
|
|
123
|
+
*
|
|
124
|
+
* If what you want is not asserting but just knowing whether the parametric value is
|
|
125
|
+
* following the type `T` or not, you can choose the {@link is} function instead.
|
|
126
|
+
* Otherwise you want to know all the errors, {@link validate} is the way to go.
|
|
127
|
+
* Also, if you want to returns the parametric value when no problem, you can use
|
|
128
|
+
* {@link assert} function instead.
|
|
129
|
+
*
|
|
130
|
+
* On the other and, if you don't want to allow any superfluous property that is not
|
|
131
|
+
* enrolled to the type `T`, you can use {@link assertGuardEquals} function instead.
|
|
132
|
+
*
|
|
133
|
+
* @template T Type of the input value
|
|
134
|
+
* @param input A value to be asserted
|
|
135
|
+
* @throws A {@link TypeGuardError} instance with detailed reason
|
|
136
|
+
*
|
|
137
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
138
|
+
*/
|
|
139
|
+
export function assertGuard<T>(input: unknown): asserts input is T;
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* @internal
|
|
143
|
+
*/
|
|
144
|
+
export function assertGuard(): never {
|
|
145
|
+
halt("assertGuard");
|
|
146
|
+
}
|
|
147
|
+
Object.assign(assertGuard, Namespace.assert("assertGuard"));
|
|
148
|
+
|
|
86
149
|
/**
|
|
87
150
|
* Tests a value type.
|
|
88
151
|
*
|
|
@@ -258,6 +321,72 @@ export function assertEquals(): never {
|
|
|
258
321
|
}
|
|
259
322
|
Object.assign(assertEquals, Namespace.assert("assertEquals"));
|
|
260
323
|
|
|
324
|
+
/**
|
|
325
|
+
* Assertion guard of a type with equality.
|
|
326
|
+
*
|
|
327
|
+
* Asserts a parametric value type and throws a {@link TypeGuardError} with detailed
|
|
328
|
+
* reason, if the parametric value is not following the type `T` or some superfluous
|
|
329
|
+
* property that is not listed on the type `T` has been found.
|
|
330
|
+
*
|
|
331
|
+
* Otherwise, the value is following the type `T` without any superfluous property,
|
|
332
|
+
* nothing would be returned, but the input value would be automatically casted to
|
|
333
|
+
* the type `T`. This is the concept of "assertion guard" of a value type.
|
|
334
|
+
*
|
|
335
|
+
* If what you want is not asserting but just knowing whether the parametric value is
|
|
336
|
+
* following the type `T` or not, you can choose the {@link equals} function instead.
|
|
337
|
+
* Otherwise, you want to know all the errors, {@link validateEquals} is the way to go.
|
|
338
|
+
* Also, if you want to returns the parametric value when no problem, you can use
|
|
339
|
+
* {@link assert} function instead.
|
|
340
|
+
*
|
|
341
|
+
* On the other hand, if you want to allow superfluous property that is not enrolled
|
|
342
|
+
* to the type `T`, you can use {@link assertEquals} function instead.
|
|
343
|
+
*
|
|
344
|
+
* @template T Type of the input value
|
|
345
|
+
* @param input A value to be asserted
|
|
346
|
+
* @returns Parametric input value casted as `T`
|
|
347
|
+
* @throws A {@link TypeGuardError} instance with detailed reason
|
|
348
|
+
*
|
|
349
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
350
|
+
*/
|
|
351
|
+
export function assertGuardEquals<T>(input: T): asserts input is T;
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* Assertion guard of a type with equality.
|
|
355
|
+
*
|
|
356
|
+
* Asserts a parametric value type and throws a {@link TypeGuardError} with detailed
|
|
357
|
+
* reason, if the parametric value is not following the type `T` or some superfluous
|
|
358
|
+
* property that is not listed on the type `T` has been found.
|
|
359
|
+
*
|
|
360
|
+
* Otherwise, the value is following the type `T` without any superfluous property,
|
|
361
|
+
* nothing would be returned, but the input value would be automatically casted to
|
|
362
|
+
* the type `T`. This is the concept of "assertion guard" of a value type.
|
|
363
|
+
*
|
|
364
|
+
* If what you want is not asserting but just knowing whether the parametric value is
|
|
365
|
+
* following the type `T` or not, you can choose the {@link equals} function instead.
|
|
366
|
+
* Otherwise, you want to know all the errors, {@link validateEquals} is the way to go.
|
|
367
|
+
* Also, if you want to returns the parametric value when no problem, you can use
|
|
368
|
+
* {@link assertEquals} function instead.
|
|
369
|
+
*
|
|
370
|
+
* On the other hand, if you want to allow superfluous property that is not enrolled
|
|
371
|
+
* to the type `T`, you can use {@link assertGuard} function instead.
|
|
372
|
+
*
|
|
373
|
+
* @template T Type of the input value
|
|
374
|
+
* @param input A value to be asserted
|
|
375
|
+
* @returns Parametric input value casted as `T`
|
|
376
|
+
* @throws A {@link TypeGuardError} instance with detailed reason
|
|
377
|
+
*
|
|
378
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
379
|
+
*/
|
|
380
|
+
export function assertGuardEquals<T>(input: unknown): asserts input is T;
|
|
381
|
+
|
|
382
|
+
/**
|
|
383
|
+
* @internal
|
|
384
|
+
*/
|
|
385
|
+
export function assertGuardEquals(): never {
|
|
386
|
+
halt("assertGuardEquals");
|
|
387
|
+
}
|
|
388
|
+
Object.assign(assertGuardEquals, Namespace.assert("assertGuardEquals"));
|
|
389
|
+
|
|
261
390
|
/**
|
|
262
391
|
* Tests equality between a value and its type.
|
|
263
392
|
*
|
|
@@ -425,23 +554,6 @@ export function random(): never {
|
|
|
425
554
|
}
|
|
426
555
|
Object.assign(random, Namespace.random());
|
|
427
556
|
|
|
428
|
-
/**
|
|
429
|
-
* @internal
|
|
430
|
-
*/
|
|
431
|
-
export function metadata(): never;
|
|
432
|
-
|
|
433
|
-
/**
|
|
434
|
-
* @internal
|
|
435
|
-
*/
|
|
436
|
-
export function metadata<Types extends unknown[]>(): IMetadataApplication;
|
|
437
|
-
|
|
438
|
-
/**
|
|
439
|
-
* @internal
|
|
440
|
-
*/
|
|
441
|
-
export function metadata(): never {
|
|
442
|
-
halt("metadata");
|
|
443
|
-
}
|
|
444
|
-
|
|
445
557
|
/* -----------------------------------------------------------
|
|
446
558
|
FACTORY FUNCTIONS
|
|
447
559
|
----------------------------------------------------------- */
|
|
@@ -474,6 +586,65 @@ export function createAssert<T>(): (input: unknown) => T {
|
|
|
474
586
|
}
|
|
475
587
|
Object.assign(createAssert, assert);
|
|
476
588
|
|
|
589
|
+
/**
|
|
590
|
+
* Creates a reusable {@link assertGuard} function.
|
|
591
|
+
*
|
|
592
|
+
* Note that, you've to declare the variable type of the factory function caller
|
|
593
|
+
* like below. If you don't declare the variable type, compilation error be thrown.
|
|
594
|
+
* This is the special rule of the TypeScript compiler.
|
|
595
|
+
*
|
|
596
|
+
* ```typescript
|
|
597
|
+
* // MUST DECLARE THE VARIABLE TYPE
|
|
598
|
+
* const func: typia.AssertionGuard<number> = typia.createAssertGuard<number>();
|
|
599
|
+
*
|
|
600
|
+
* // IF NOT, COMPILATION ERROR BE OCCURED
|
|
601
|
+
* const func = typia.createAssertGuard<number>();
|
|
602
|
+
* ```
|
|
603
|
+
*
|
|
604
|
+
* > *Assertions require every name in the call target to be declared with an*
|
|
605
|
+
* > *explicit type annotation.*
|
|
606
|
+
*
|
|
607
|
+
* @danger You must configure the generic argument `T`
|
|
608
|
+
* @returns Nothing until you configure the generic argument `T`
|
|
609
|
+
* @throws compile error
|
|
610
|
+
*
|
|
611
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
612
|
+
*/
|
|
613
|
+
export function createAssertGuard(): never;
|
|
614
|
+
|
|
615
|
+
/**
|
|
616
|
+
* Creates a reusable {@link assertGuard} function.
|
|
617
|
+
*
|
|
618
|
+
* Note that, you've to declare the variable type of the factory function caller
|
|
619
|
+
* like below. If you don't declare the variable type, compilation error be thrown.
|
|
620
|
+
* This is the special rule of the TypeScript compiler.
|
|
621
|
+
*
|
|
622
|
+
* ```typescript
|
|
623
|
+
* // MUST DECLARE THE VARIABLE TYPE
|
|
624
|
+
* const func: typia.AssertionGuard<number> = typia.createAssertGuard<number>();
|
|
625
|
+
*
|
|
626
|
+
* // IF NOT, COMPILATION ERROR BE OCCURED
|
|
627
|
+
* const func = typia.createAssertGuard<number>();
|
|
628
|
+
* ```
|
|
629
|
+
*
|
|
630
|
+
* > *Assertions require every name in the call target to be declared with an*
|
|
631
|
+
* > *explicit type annotation.*
|
|
632
|
+
*
|
|
633
|
+
* @returns Nothing until you configure the generic argument `T`
|
|
634
|
+
* @throws compile error
|
|
635
|
+
*
|
|
636
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
637
|
+
*/
|
|
638
|
+
export function createAssertGuard<T>(): (input: unknown) => AssertionGuard<T>;
|
|
639
|
+
|
|
640
|
+
/**
|
|
641
|
+
* @internal
|
|
642
|
+
*/
|
|
643
|
+
export function createAssertGuard<T>(): (input: unknown) => AssertionGuard<T> {
|
|
644
|
+
halt("createAssertGuard");
|
|
645
|
+
}
|
|
646
|
+
Object.assign(createAssertGuard, assertGuard);
|
|
647
|
+
|
|
477
648
|
/**
|
|
478
649
|
* Creates a reusable {@link is} function.
|
|
479
650
|
*
|
|
@@ -561,6 +732,69 @@ export function createAssertEquals<T>(): (input: unknown) => T {
|
|
|
561
732
|
}
|
|
562
733
|
Object.assign(createAssertEquals, assertEquals);
|
|
563
734
|
|
|
735
|
+
/**
|
|
736
|
+
* Creates a reusable {@link assertGuardEquals} function.
|
|
737
|
+
*
|
|
738
|
+
* Note that, you've to declare the variable type of the factory function caller
|
|
739
|
+
* like below. If you don't declare the variable type, compilation error be thrown.
|
|
740
|
+
* This is the special rule of the TypeScript compiler.
|
|
741
|
+
*
|
|
742
|
+
* ```typescript
|
|
743
|
+
* // MUST DECLARE THE VARIABLE TYPE
|
|
744
|
+
* const func: typia.AssertionGuard<number> = typia.createAssertGuardEquals<number>();
|
|
745
|
+
*
|
|
746
|
+
* // IF NOT, COMPILATION ERROR BE OCCURED
|
|
747
|
+
* const func = typia.createAssertGuardEquals<number>();
|
|
748
|
+
* ```
|
|
749
|
+
*
|
|
750
|
+
* > *Assertions require every name in the call target to be declared with an*
|
|
751
|
+
* > *explicit type annotation.*
|
|
752
|
+
*
|
|
753
|
+
* @danger You must configure the generic argument `T`
|
|
754
|
+
* @returns Nothing until you configure the generic argument `T`
|
|
755
|
+
* @throws compile error
|
|
756
|
+
*
|
|
757
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
758
|
+
*/
|
|
759
|
+
export function createAssertGuardEquals(): never;
|
|
760
|
+
|
|
761
|
+
/**
|
|
762
|
+
* Creates a reusable {@link assertGuardEquals} function.
|
|
763
|
+
*
|
|
764
|
+
* Note that, you've to declare the variable type of the factory function caller
|
|
765
|
+
* like below. If you don't declare the variable type, compilation error be thrown.
|
|
766
|
+
* This is the special rule of the TypeScript compiler.
|
|
767
|
+
*
|
|
768
|
+
* ```typescript
|
|
769
|
+
* // MUST DECLARE THE VARIABLE TYPE
|
|
770
|
+
* const func: typia.AssertionGuard<number> = typia.createAssertGuardEquals<number>();
|
|
771
|
+
*
|
|
772
|
+
* // IF NOT, COMPILATION ERROR BE OCCURED
|
|
773
|
+
* const func = typia.createAssertGuardEquals<number>();
|
|
774
|
+
* ```
|
|
775
|
+
*
|
|
776
|
+
* > *Assertions require every name in the call target to be declared with an*
|
|
777
|
+
* > *explicit type annotation.*
|
|
778
|
+
*
|
|
779
|
+
* @returns Nothing until you configure the generic argument `T`
|
|
780
|
+
* @throws compile error
|
|
781
|
+
*
|
|
782
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
783
|
+
*/
|
|
784
|
+
export function createAssertGuardEquals<T>(): (
|
|
785
|
+
input: unknown,
|
|
786
|
+
) => AssertionGuard<T>;
|
|
787
|
+
|
|
788
|
+
/**
|
|
789
|
+
* @internal
|
|
790
|
+
*/
|
|
791
|
+
export function createAssertGuardEquals<T>(): (
|
|
792
|
+
input: unknown,
|
|
793
|
+
) => AssertionGuard<T> {
|
|
794
|
+
halt("createAssertGuardEquals");
|
|
795
|
+
}
|
|
796
|
+
Object.assign(createAssertGuardEquals, assertGuardEquals);
|
|
797
|
+
|
|
564
798
|
/**
|
|
565
799
|
* Creates a reusable {@link equals} function.
|
|
566
800
|
*
|
|
@@ -16,12 +16,16 @@ export namespace AssertProgrammer {
|
|
|
16
16
|
export const write =
|
|
17
17
|
(project: IProject) =>
|
|
18
18
|
(modulo: ts.LeftHandSideExpression) =>
|
|
19
|
-
(equals: boolean) =>
|
|
19
|
+
(props: boolean | { equals: boolean; guard: boolean }) =>
|
|
20
20
|
(type: ts.Type, name?: string) => {
|
|
21
|
+
// TO SUPPORT LEGACY FEATURE
|
|
22
|
+
if (typeof props === "boolean")
|
|
23
|
+
props = { equals: props, guard: false };
|
|
24
|
+
|
|
21
25
|
const importer: FunctionImporter = new FunctionImporter(
|
|
22
26
|
modulo.getText(),
|
|
23
27
|
);
|
|
24
|
-
const is = IsProgrammer.write(project)(modulo, true)(equals)(
|
|
28
|
+
const is = IsProgrammer.write(project)(modulo, true)(props.equals)(
|
|
25
29
|
type,
|
|
26
30
|
name ?? TypeFactory.getFullName(project.checker)(type),
|
|
27
31
|
);
|
|
@@ -30,7 +34,7 @@ export namespace AssertProgrammer {
|
|
|
30
34
|
path: true,
|
|
31
35
|
trace: true,
|
|
32
36
|
numeric: OptionPredicator.numeric(project.options),
|
|
33
|
-
equals,
|
|
37
|
+
equals: props.equals,
|
|
34
38
|
atomist: (explore) => (entry) => (input) =>
|
|
35
39
|
[
|
|
36
40
|
...(entry.expression ? [entry.expression] : []),
|
|
@@ -91,8 +95,8 @@ export namespace AssertProgrammer {
|
|
|
91
95
|
),
|
|
92
96
|
]),
|
|
93
97
|
].reduce((x, y) => ts.factory.createLogicalAnd(x, y)),
|
|
94
|
-
combiner: combiner(equals)(project)(importer),
|
|
95
|
-
joiner: joiner(equals)(project)(importer),
|
|
98
|
+
combiner: combiner(props.equals)(project)(importer),
|
|
99
|
+
joiner: joiner(props.equals)(project)(importer),
|
|
96
100
|
success: ts.factory.createTrue(),
|
|
97
101
|
addition: () => importer.declare(modulo),
|
|
98
102
|
})(importer)(type, name);
|
|
@@ -106,9 +110,21 @@ export namespace AssertProgrammer {
|
|
|
106
110
|
TypeFactory.keyword("any"),
|
|
107
111
|
),
|
|
108
112
|
],
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
113
|
+
props.guard
|
|
114
|
+
? ts.factory.createTypePredicateNode(
|
|
115
|
+
ts.factory.createToken(ts.SyntaxKind.AssertsKeyword),
|
|
116
|
+
ts.factory.createIdentifier("input"),
|
|
117
|
+
ts.factory.createTypeReferenceNode(
|
|
118
|
+
name ??
|
|
119
|
+
TypeFactory.getFullName(project.checker)(
|
|
120
|
+
type,
|
|
121
|
+
),
|
|
122
|
+
),
|
|
123
|
+
)
|
|
124
|
+
: ts.factory.createTypeReferenceNode(
|
|
125
|
+
name ??
|
|
126
|
+
TypeFactory.getFullName(project.checker)(type),
|
|
127
|
+
),
|
|
112
128
|
undefined,
|
|
113
129
|
ts.factory.createBlock(
|
|
114
130
|
[
|
|
@@ -137,9 +153,13 @@ export namespace AssertProgrammer {
|
|
|
137
153
|
),
|
|
138
154
|
undefined,
|
|
139
155
|
),
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
156
|
+
...(props.guard === false
|
|
157
|
+
? [
|
|
158
|
+
ts.factory.createReturnStatement(
|
|
159
|
+
ts.factory.createIdentifier(`input`),
|
|
160
|
+
),
|
|
161
|
+
]
|
|
162
|
+
: []),
|
|
143
163
|
],
|
|
144
164
|
true,
|
|
145
165
|
),
|
|
@@ -26,7 +26,7 @@ export namespace ProtobufUtil {
|
|
|
26
26
|
if (c.type === "boolean") set.add("bool");
|
|
27
27
|
else if (c.type === "bigint") set.add("uint64");
|
|
28
28
|
else if (c.type === "number")
|
|
29
|
-
set.add(deduce_numeric_type(c.values));
|
|
29
|
+
set.add(deduce_numeric_type(c.values as number[]));
|
|
30
30
|
else if (c.type === "string") set.add("string");
|
|
31
31
|
for (const atomic of meta.atomics)
|
|
32
32
|
if (atomic.type === "boolean") set.add("bool");
|
|
@@ -42,7 +42,8 @@ export namespace ProtobufUtil {
|
|
|
42
42
|
export const getNumbers = (meta: Metadata) => {
|
|
43
43
|
const set: Set<ProtobufAtomic.Numeric> = new Set();
|
|
44
44
|
for (const c of meta.constants)
|
|
45
|
-
if (c.type === "number")
|
|
45
|
+
if (c.type === "number")
|
|
46
|
+
set.add(deduce_numeric_type(c.values as number[]));
|
|
46
47
|
for (const atomic of meta.atomics)
|
|
47
48
|
if (atomic.type === "number")
|
|
48
49
|
decode_number(atomic.tags).forEach((t) => set.add(t));
|
|
@@ -40,8 +40,11 @@ const check_string_type_tags =
|
|
|
40
40
|
.map((row) =>
|
|
41
41
|
row.map((tag) => ({
|
|
42
42
|
expected: `string & ${tag.name}`,
|
|
43
|
-
expression:
|
|
44
|
-
tag.
|
|
43
|
+
expression: (
|
|
44
|
+
tag.predicate ??
|
|
45
|
+
ExpressionFactory.transpile(project.context)(
|
|
46
|
+
tag.validate!,
|
|
47
|
+
)
|
|
45
48
|
)(input),
|
|
46
49
|
})),
|
|
47
50
|
);
|
|
@@ -18,7 +18,9 @@ export const metadata_to_pattern =
|
|
|
18
18
|
meta.constants.map((c) => {
|
|
19
19
|
if (c.type !== "string")
|
|
20
20
|
return c.values.map((v) => v.toString());
|
|
21
|
-
return c.values.map((str) =>
|
|
21
|
+
return (c.values as string[]).map((str) =>
|
|
22
|
+
PatternUtil.escape(str),
|
|
23
|
+
);
|
|
22
24
|
}),
|
|
23
25
|
);
|
|
24
26
|
for (const a of meta.atomics)
|
package/src/reflect.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Namespace } from "./functional/Namespace";
|
|
2
|
+
|
|
3
|
+
import { MetadataApplication } from "./schemas/metadata/MetadataApplication";
|
|
4
|
+
|
|
5
|
+
export function metadata(): never;
|
|
6
|
+
|
|
7
|
+
export function metadata<Types extends unknown[]>(): MetadataApplication;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
export function metadata(): never {
|
|
13
|
+
halt("metadata");
|
|
14
|
+
}
|
|
15
|
+
Object.assign(metadata, Namespace.reflect.metadata());
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
function halt(name: string): never {
|
|
21
|
+
throw new Error(
|
|
22
|
+
`Error on typia.reflect.${name}(): no transform has been configured. Read and follow https://typia.io/docs/setup please.`,
|
|
23
|
+
);
|
|
24
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { IMetadata } from "./IMetadata";
|
|
2
|
-
import {
|
|
2
|
+
import { IMetadataComponents } from "./IMetadataComponents";
|
|
3
3
|
|
|
4
4
|
export interface IMetadataApplication {
|
|
5
5
|
metadatas: IMetadata[];
|
|
6
|
-
|
|
6
|
+
components: IMetadataComponents;
|
|
7
7
|
}
|
|
@@ -3,7 +3,7 @@ import { IMetadataArrayType } from "./IMetadataArrayType";
|
|
|
3
3
|
import { IMetadataObject } from "./IMetadataObject";
|
|
4
4
|
import { IMetadataTupleType } from "./IMetadataTupleType";
|
|
5
5
|
|
|
6
|
-
export interface
|
|
6
|
+
export interface IMetadataComponents {
|
|
7
7
|
objects: IMetadataObject[];
|
|
8
8
|
aliases: IMetadataAlias[];
|
|
9
9
|
arrays: IMetadataArrayType[];
|
|
@@ -6,7 +6,7 @@ export type IMetadataConstant =
|
|
|
6
6
|
| IMetadataConstant.IBase<"boolean", boolean>
|
|
7
7
|
| IMetadataConstant.IBase<"number", number>
|
|
8
8
|
| IMetadataConstant.IBase<"string", string>
|
|
9
|
-
| IMetadataConstant.IBase<"bigint",
|
|
9
|
+
| IMetadataConstant.IBase<"bigint", string>;
|
|
10
10
|
export namespace IMetadataConstant {
|
|
11
11
|
export interface IBase<
|
|
12
12
|
Type extends Atomic.Literal,
|
|
@@ -4,9 +4,9 @@ export interface IMetadataTypeTag {
|
|
|
4
4
|
target: "boolean" | "bigint" | "number" | "string" | "array";
|
|
5
5
|
name: string;
|
|
6
6
|
kind: string;
|
|
7
|
-
value: any;
|
|
8
|
-
validate: string | undefined;
|
|
9
7
|
exclusive: boolean | string[];
|
|
8
|
+
value?: any;
|
|
9
|
+
validate?: string | undefined;
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* @internal
|