typia 3.4.6 → 3.4.7

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 (119) hide show
  1. package/lib/executable/typia.js +0 -0
  2. package/lib/factories/internal/iterate_metadata.js +1 -1
  3. package/lib/factories/internal/iterate_metadata.js.map +1 -1
  4. package/lib/factories/internal/iterate_metadata_tuple.d.ts +1 -1
  5. package/lib/factories/internal/iterate_metadata_tuple.js +5 -13
  6. package/lib/factories/internal/iterate_metadata_tuple.js.map +1 -1
  7. package/package.json +1 -1
  8. package/src/IValidation.ts +21 -21
  9. package/src/Primitive.ts +82 -82
  10. package/src/TypeGuardError.ts +36 -36
  11. package/src/factories/CommentFactory.ts +10 -10
  12. package/src/factories/ExpressionFactory.ts +52 -52
  13. package/src/factories/IdentifierFactory.ts +72 -72
  14. package/src/factories/LiteralFactory.ts +44 -44
  15. package/src/factories/MetadataCollection.ts +122 -122
  16. package/src/factories/MetadataFactory.ts +46 -46
  17. package/src/factories/StatementFactory.ts +60 -60
  18. package/src/factories/TemplateFactory.ts +56 -56
  19. package/src/factories/TypeFactory.ts +101 -101
  20. package/src/factories/ValueFactory.ts +12 -12
  21. package/src/factories/internal/MetadataHelper.ts +12 -12
  22. package/src/factories/internal/emplace_metadata_object.ts +140 -140
  23. package/src/factories/internal/explore_metadata.ts +91 -91
  24. package/src/factories/internal/iterate_metadata.ts +1 -2
  25. package/src/factories/internal/iterate_metadata_array.ts +29 -29
  26. package/src/factories/internal/iterate_metadata_atomic.ts +59 -59
  27. package/src/factories/internal/iterate_metadata_coalesce.ts +33 -33
  28. package/src/factories/internal/iterate_metadata_constant.ts +58 -58
  29. package/src/factories/internal/iterate_metadata_map.ts +41 -41
  30. package/src/factories/internal/iterate_metadata_object.ts +45 -45
  31. package/src/factories/internal/iterate_metadata_resolve.ts +27 -27
  32. package/src/factories/internal/iterate_metadata_set.ts +33 -33
  33. package/src/factories/internal/iterate_metadata_template.ts +38 -38
  34. package/src/factories/internal/iterate_metadata_tuple.ts +45 -51
  35. package/src/factories/internal/iterate_metadata_union.ts +59 -59
  36. package/src/functional/$every.ts +11 -11
  37. package/src/functional/$guard.ts +35 -35
  38. package/src/functional/$is_email.ts +5 -5
  39. package/src/functional/$is_ipv4.ts +5 -5
  40. package/src/functional/$is_ipv6.ts +5 -5
  41. package/src/functional/$is_url.ts +5 -5
  42. package/src/functional/$is_uuid.ts +5 -5
  43. package/src/functional/$join.ts +50 -50
  44. package/src/functional/$report.ts +15 -15
  45. package/src/functional/$rest.ts +3 -3
  46. package/src/functional/$string.ts +37 -37
  47. package/src/functional/$tail.ts +6 -6
  48. package/src/metadata/IJsDocTagInfo.ts +10 -10
  49. package/src/metadata/IMetadata.ts +25 -25
  50. package/src/metadata/IMetadataApplication.ts +7 -7
  51. package/src/metadata/IMetadataConstant.ts +16 -16
  52. package/src/metadata/IMetadataEntry.ts +6 -6
  53. package/src/metadata/IMetadataObject.ts +29 -29
  54. package/src/metadata/IMetadataProperty.ts +11 -11
  55. package/src/metadata/IMetadataTag.ts +122 -122
  56. package/src/metadata/Metadata.ts +477 -477
  57. package/src/metadata/MetadataConstant.ts +3 -3
  58. package/src/metadata/MetadataObject.ts +131 -131
  59. package/src/metadata/MetadataProperty.ts +64 -64
  60. package/src/programmers/AssertParseProgrammer.ts +45 -45
  61. package/src/programmers/AssertProgrammer.ts +444 -444
  62. package/src/programmers/AssertStringifyProgrammer.ts +45 -45
  63. package/src/programmers/CheckerProgrammer.ts +798 -798
  64. package/src/programmers/FeatureProgrammer.ts +327 -327
  65. package/src/programmers/IsParseProgrammer.ts +51 -51
  66. package/src/programmers/IsProgrammer.ts +169 -169
  67. package/src/programmers/IsStringifyProgrammer.ts +49 -49
  68. package/src/programmers/ValidateParseProgrammer.ts +49 -49
  69. package/src/programmers/ValidateProgrammer.ts +236 -236
  70. package/src/programmers/ValidateStringifyProgrammer.ts +60 -60
  71. package/src/programmers/helpers/AtomicPredicator.ts +15 -15
  72. package/src/programmers/helpers/FunctionImporeter.ts +31 -31
  73. package/src/programmers/helpers/IExpressionEntry.ts +10 -10
  74. package/src/programmers/helpers/OptionPredicator.ts +18 -18
  75. package/src/programmers/helpers/StringifyJoinder.ts +111 -111
  76. package/src/programmers/helpers/StringifyPredicator.ts +18 -18
  77. package/src/programmers/helpers/UnionExplorer.ts +437 -437
  78. package/src/programmers/helpers/UnionPredicator.ts +81 -81
  79. package/src/programmers/internal/application_boolean.ts +17 -17
  80. package/src/programmers/internal/application_constant.ts +29 -29
  81. package/src/programmers/internal/application_default_string.ts +32 -32
  82. package/src/programmers/internal/application_native.ts +29 -29
  83. package/src/programmers/internal/application_schema.ts +221 -221
  84. package/src/programmers/internal/application_templates.ts +27 -27
  85. package/src/programmers/internal/application_tuple.ts +25 -25
  86. package/src/programmers/internal/check_array.ts +44 -44
  87. package/src/programmers/internal/check_dynamic_properties.ts +146 -146
  88. package/src/programmers/internal/check_everything.ts +25 -25
  89. package/src/programmers/internal/check_length.ts +46 -46
  90. package/src/programmers/internal/check_native.ts +9 -9
  91. package/src/programmers/internal/check_number.ts +181 -181
  92. package/src/programmers/internal/check_object.ts +42 -42
  93. package/src/programmers/internal/check_string.ts +24 -24
  94. package/src/programmers/internal/check_string_tags.ts +63 -63
  95. package/src/programmers/internal/check_template.ts +50 -50
  96. package/src/programmers/internal/decode_union_object.ts +73 -73
  97. package/src/programmers/internal/feature_object_entries.ts +49 -49
  98. package/src/programmers/internal/metadata_to_pattern.ts +31 -31
  99. package/src/programmers/internal/stringify_dynamic_properties.ts +164 -164
  100. package/src/programmers/internal/stringify_native.ts +8 -8
  101. package/src/programmers/internal/stringify_regular_properties.ts +81 -81
  102. package/src/programmers/internal/template_to_pattern.ts +15 -15
  103. package/src/schemas/IJsonApplication.ts +9 -9
  104. package/src/transform.ts +20 -20
  105. package/src/transformers/ExpressionWithArgumentTransformer.ts +66 -66
  106. package/src/transformers/FileTransformer.ts +49 -49
  107. package/src/transformers/IProject.ts +11 -11
  108. package/src/transformers/ITransformOptions.ts +4 -4
  109. package/src/transformers/NodeTransformer.ts +19 -19
  110. package/src/typings/Atomic.ts +17 -17
  111. package/src/typings/ClassProperties.ts +5 -5
  112. package/src/typings/OmitNever.ts +3 -3
  113. package/src/typings/SpecialFields.ts +3 -3
  114. package/src/typings/Writable.ts +11 -11
  115. package/src/utils/ArrayUtil.ts +49 -49
  116. package/src/utils/Escaper.ts +50 -50
  117. package/src/utils/MapUtil.ts +14 -14
  118. package/src/utils/PatternUtil.ts +30 -30
  119. package/src/utils/Singleton.ts +17 -17
@@ -1,45 +1,45 @@
1
- import ts from "typescript";
2
-
3
- import { Metadata } from "../../metadata/Metadata";
4
- import { MetadataObject } from "../../metadata/MetadataObject";
5
-
6
- import { ArrayUtil } from "../../utils/ArrayUtil";
7
-
8
- import { MetadataCollection } from "../MetadataCollection";
9
- import { MetadataFactory } from "../MetadataFactory";
10
- import { emplace_metadata_object } from "./emplace_metadata_object";
11
- import { iterate_metadata } from "./iterate_metadata";
12
-
13
- export const iterate_metadata_object =
14
- (checker: ts.TypeChecker) =>
15
- (options: MetadataFactory.IOptions) =>
16
- (collection: MetadataCollection) =>
17
- (meta: Metadata, type: ts.Type, parentResolved: boolean): boolean => {
18
- const filter = (flag: ts.TypeFlags) => (type.getFlags() & flag) !== 0;
19
- if (!filter(ts.TypeFlags.Object) && !type.isIntersection())
20
- return false;
21
-
22
- if (type.isIntersection()) {
23
- const fakeCollection = new MetadataCollection();
24
- const fakeSchema: Metadata = Metadata.initialize();
25
-
26
- type.types.forEach((t) =>
27
- iterate_metadata(checker)(options)(fakeCollection)(
28
- fakeSchema,
29
- t,
30
- parentResolved,
31
- ),
32
- );
33
- if (
34
- fakeSchema.objects.length === 0 ||
35
- fakeSchema.objects.length !== fakeSchema.size()
36
- )
37
- return true;
38
- }
39
-
40
- const obj: MetadataObject = emplace_metadata_object(checker)(options)(
41
- collection,
42
- )(type, meta.nullable);
43
- ArrayUtil.add(meta.objects, obj, (elem) => elem.name === obj.name);
44
- return true;
45
- };
1
+ import ts from "typescript";
2
+
3
+ import { Metadata } from "../../metadata/Metadata";
4
+ import { MetadataObject } from "../../metadata/MetadataObject";
5
+
6
+ import { ArrayUtil } from "../../utils/ArrayUtil";
7
+
8
+ import { MetadataCollection } from "../MetadataCollection";
9
+ import { MetadataFactory } from "../MetadataFactory";
10
+ import { emplace_metadata_object } from "./emplace_metadata_object";
11
+ import { iterate_metadata } from "./iterate_metadata";
12
+
13
+ export const iterate_metadata_object =
14
+ (checker: ts.TypeChecker) =>
15
+ (options: MetadataFactory.IOptions) =>
16
+ (collection: MetadataCollection) =>
17
+ (meta: Metadata, type: ts.Type, parentResolved: boolean): boolean => {
18
+ const filter = (flag: ts.TypeFlags) => (type.getFlags() & flag) !== 0;
19
+ if (!filter(ts.TypeFlags.Object) && !type.isIntersection())
20
+ return false;
21
+
22
+ if (type.isIntersection()) {
23
+ const fakeCollection = new MetadataCollection();
24
+ const fakeSchema: Metadata = Metadata.initialize();
25
+
26
+ type.types.forEach((t) =>
27
+ iterate_metadata(checker)(options)(fakeCollection)(
28
+ fakeSchema,
29
+ t,
30
+ parentResolved,
31
+ ),
32
+ );
33
+ if (
34
+ fakeSchema.objects.length === 0 ||
35
+ fakeSchema.objects.length !== fakeSchema.size()
36
+ )
37
+ return true;
38
+ }
39
+
40
+ const obj: MetadataObject = emplace_metadata_object(checker)(options)(
41
+ collection,
42
+ )(type, meta.nullable);
43
+ ArrayUtil.add(meta.objects, obj, (elem) => elem.name === obj.name);
44
+ return true;
45
+ };
@@ -1,27 +1,27 @@
1
- import ts from "typescript";
2
-
3
- import { Metadata } from "../../metadata/Metadata";
4
-
5
- import { Writable } from "../../typings/Writable";
6
-
7
- import { MetadataCollection } from "../MetadataCollection";
8
- import { MetadataFactory } from "../MetadataFactory";
9
- import { TypeFactory } from "../TypeFactory";
10
- import { explore_metadata } from "./explore_metadata";
11
-
12
- export const iterate_metadata_resolve =
13
- (checker: ts.TypeChecker) =>
14
- (options: MetadataFactory.IOptions) =>
15
- (collection: MetadataCollection) =>
16
- (meta: Metadata, type: ts.Type, parentResolved: boolean): boolean => {
17
- if (options.resolve === true && parentResolved === false) {
18
- const resolved: ts.Type | null = TypeFactory.resolve(checker, type);
19
- if (resolved !== null) {
20
- Writable(meta).resolved = explore_metadata(checker)(options)(
21
- collection,
22
- )(resolved, true);
23
- return true;
24
- }
25
- }
26
- return false;
27
- };
1
+ import ts from "typescript";
2
+
3
+ import { Metadata } from "../../metadata/Metadata";
4
+
5
+ import { Writable } from "../../typings/Writable";
6
+
7
+ import { MetadataCollection } from "../MetadataCollection";
8
+ import { MetadataFactory } from "../MetadataFactory";
9
+ import { TypeFactory } from "../TypeFactory";
10
+ import { explore_metadata } from "./explore_metadata";
11
+
12
+ export const iterate_metadata_resolve =
13
+ (checker: ts.TypeChecker) =>
14
+ (options: MetadataFactory.IOptions) =>
15
+ (collection: MetadataCollection) =>
16
+ (meta: Metadata, type: ts.Type, parentResolved: boolean): boolean => {
17
+ if (options.resolve === true && parentResolved === false) {
18
+ const resolved: ts.Type | null = TypeFactory.resolve(checker, type);
19
+ if (resolved !== null) {
20
+ Writable(meta).resolved = explore_metadata(checker)(options)(
21
+ collection,
22
+ )(resolved, true);
23
+ return true;
24
+ }
25
+ }
26
+ return false;
27
+ };
@@ -1,33 +1,33 @@
1
- import ts from "typescript";
2
-
3
- import { Metadata } from "../../metadata/Metadata";
4
-
5
- import { ArrayUtil } from "../../utils/ArrayUtil";
6
-
7
- import { MetadataCollection } from "../MetadataCollection";
8
- import { MetadataFactory } from "../MetadataFactory";
9
- import { TypeFactory } from "../TypeFactory";
10
- import { explore_metadata } from "./explore_metadata";
11
-
12
- export const iterate_metadata_set =
13
- (checker: ts.TypeChecker) =>
14
- (options: MetadataFactory.IOptions) =>
15
- (collection: MetadataCollection) =>
16
- (meta: Metadata, type: ts.Type): boolean => {
17
- type = checker.getApparentType(type);
18
-
19
- const name = TypeFactory.getFullName(checker, type, type.getSymbol());
20
- const generic = type.aliasSymbol
21
- ? type.aliasTypeArguments
22
- : checker.getTypeArguments(type as ts.TypeReference);
23
- if (name.substring(0, 4) !== "Set<" || generic?.length !== 1)
24
- return false;
25
-
26
- const key: ts.Type = generic[0]!;
27
- ArrayUtil.set(
28
- meta.sets,
29
- explore_metadata(checker)(options)(collection)(key, false),
30
- (elem) => elem.getName(),
31
- );
32
- return true;
33
- };
1
+ import ts from "typescript";
2
+
3
+ import { Metadata } from "../../metadata/Metadata";
4
+
5
+ import { ArrayUtil } from "../../utils/ArrayUtil";
6
+
7
+ import { MetadataCollection } from "../MetadataCollection";
8
+ import { MetadataFactory } from "../MetadataFactory";
9
+ import { TypeFactory } from "../TypeFactory";
10
+ import { explore_metadata } from "./explore_metadata";
11
+
12
+ export const iterate_metadata_set =
13
+ (checker: ts.TypeChecker) =>
14
+ (options: MetadataFactory.IOptions) =>
15
+ (collection: MetadataCollection) =>
16
+ (meta: Metadata, type: ts.Type): boolean => {
17
+ type = checker.getApparentType(type);
18
+
19
+ const name = TypeFactory.getFullName(checker, type, type.getSymbol());
20
+ const generic = type.aliasSymbol
21
+ ? type.aliasTypeArguments
22
+ : checker.getTypeArguments(type as ts.TypeReference);
23
+ if (name.substring(0, 4) !== "Set<" || generic?.length !== 1)
24
+ return false;
25
+
26
+ const key: ts.Type = generic[0]!;
27
+ ArrayUtil.set(
28
+ meta.sets,
29
+ explore_metadata(checker)(options)(collection)(key, false),
30
+ (elem) => elem.getName(),
31
+ );
32
+ return true;
33
+ };
@@ -1,38 +1,38 @@
1
- import ts from "typescript";
2
-
3
- import { Metadata } from "../../metadata/Metadata";
4
-
5
- import { MetadataCollection } from "../MetadataCollection";
6
- import { MetadataFactory } from "../MetadataFactory";
7
- import { MetadataHelper } from "./MetadataHelper";
8
- import { explore_metadata } from "./explore_metadata";
9
-
10
- export const iterate_metadata_template =
11
- (checker: ts.TypeChecker) =>
12
- (options: MetadataFactory.IOptions) =>
13
- (collection: MetadataCollection) =>
14
- (meta: Metadata, type: ts.Type): boolean => {
15
- const filter = (flag: ts.TypeFlags) => (type.getFlags() & flag) !== 0;
16
- if (!filter(ts.TypeFlags.TemplateLiteral)) return false;
17
-
18
- const template: ts.TemplateLiteralType = type as ts.TemplateLiteralType;
19
- const row: Metadata[] = [];
20
-
21
- template.texts.forEach((text, i) => {
22
- // TEXT LITERAL TYPE
23
- if (text !== "") row.push(MetadataHelper.literal_to_metadata(text));
24
-
25
- // BINDED TEMPLATE TYPE
26
- const binded: ts.Type | undefined = template.types[i];
27
- if (binded)
28
- row.push(
29
- explore_metadata(checker)(options)(collection)(
30
- binded,
31
- false,
32
- ),
33
- );
34
- });
35
- meta.templates.push(row);
36
-
37
- return true;
38
- };
1
+ import ts from "typescript";
2
+
3
+ import { Metadata } from "../../metadata/Metadata";
4
+
5
+ import { MetadataCollection } from "../MetadataCollection";
6
+ import { MetadataFactory } from "../MetadataFactory";
7
+ import { MetadataHelper } from "./MetadataHelper";
8
+ import { explore_metadata } from "./explore_metadata";
9
+
10
+ export const iterate_metadata_template =
11
+ (checker: ts.TypeChecker) =>
12
+ (options: MetadataFactory.IOptions) =>
13
+ (collection: MetadataCollection) =>
14
+ (meta: Metadata, type: ts.Type): boolean => {
15
+ const filter = (flag: ts.TypeFlags) => (type.getFlags() & flag) !== 0;
16
+ if (!filter(ts.TypeFlags.TemplateLiteral)) return false;
17
+
18
+ const template: ts.TemplateLiteralType = type as ts.TemplateLiteralType;
19
+ const row: Metadata[] = [];
20
+
21
+ template.texts.forEach((text, i) => {
22
+ // TEXT LITERAL TYPE
23
+ if (text !== "") row.push(MetadataHelper.literal_to_metadata(text));
24
+
25
+ // BINDED TEMPLATE TYPE
26
+ const binded: ts.Type | undefined = template.types[i];
27
+ if (binded)
28
+ row.push(
29
+ explore_metadata(checker)(options)(collection)(
30
+ binded,
31
+ false,
32
+ ),
33
+ );
34
+ });
35
+ meta.templates.push(row);
36
+
37
+ return true;
38
+ };
@@ -1,51 +1,45 @@
1
- import ts from "typescript";
2
-
3
- import { Metadata } from "../../metadata/Metadata";
4
-
5
- import { Writable } from "../../typings/Writable";
6
-
7
- import { ArrayUtil } from "../../utils/ArrayUtil";
8
-
9
- import { MetadataCollection } from "../MetadataCollection";
10
- import { MetadataFactory } from "../MetadataFactory";
11
- import { explore_metadata } from "./explore_metadata";
12
-
13
- export const iterate_metadata_tuple =
14
- (checker: ts.TypeChecker) =>
15
- (options: MetadataFactory.IOptions) =>
16
- (collection: MetadataCollection) =>
17
- (meta: Metadata, type: ts.Type, node: ts.TypeNode): boolean => {
18
- if (!(checker as any).isTupleType(type)) return false;
19
-
20
- while (ts.isTypeReferenceNode(node)) {
21
- const declarations: ts.Declaration[] | undefined = (
22
- node.typeName as any
23
- )?.symbol?.declarations;
24
- if (!declarations?.length) break;
25
-
26
- const alias = declarations[0];
27
- if (!alias || !ts.isTypeAliasDeclaration(alias)) break;
28
- node = alias.type;
29
- }
30
-
31
- const elements = ts.isTupleTypeNode(node) ? node.elements : undefined;
32
- const children: Metadata[] = checker
33
- .getTypeArguments(type as ts.TypeReference)
34
- .map((elem, i) => {
35
- const child: Metadata = explore_metadata(checker)(options)(
36
- collection,
37
- )(elem, false);
38
- if (elements === undefined || !ts.isRestTypeNode(elements[i]!))
39
- return child;
40
-
41
- const wrapper: Metadata = Metadata.initialize();
42
- Writable(wrapper).rest = child;
43
- return wrapper;
44
- });
45
- ArrayUtil.set(meta.tuples, children, join_tuple_names);
46
- return true;
47
- };
48
-
49
- function join_tuple_names(metas: Metadata[]): string {
50
- return `[${metas.map((m) => m.getName).join(", ")}]`;
51
- }
1
+ import ts from "typescript";
2
+
3
+ import { Metadata } from "../../metadata/Metadata";
4
+
5
+ import { Writable } from "../../typings/Writable";
6
+
7
+ import { ArrayUtil } from "../../utils/ArrayUtil";
8
+
9
+ import { MetadataCollection } from "../MetadataCollection";
10
+ import { MetadataFactory } from "../MetadataFactory";
11
+ import { explore_metadata } from "./explore_metadata";
12
+
13
+ export const iterate_metadata_tuple =
14
+ (checker: ts.TypeChecker) =>
15
+ (options: MetadataFactory.IOptions) =>
16
+ (collection: MetadataCollection) =>
17
+ (meta: Metadata, type: ts.TupleType): boolean => {
18
+ if (!(checker as any).isTupleType(type)) return false;
19
+
20
+ const elementFlags: readonly ts.ElementFlags[] =
21
+ type.elementFlags ??
22
+ (type.target as ts.TupleType)?.elementFlags ??
23
+ [];
24
+
25
+ const children: Metadata[] = checker
26
+ .getTypeArguments(type as ts.TypeReference)
27
+ .map((elem, i) => {
28
+ const child: Metadata = explore_metadata(checker)(options)(
29
+ collection,
30
+ )(elem, false);
31
+
32
+ const flag: ts.ElementFlags | undefined = elementFlags[i];
33
+ if (flag !== ts.ElementFlags.Rest) return child;
34
+
35
+ const wrapper: Metadata = Metadata.initialize();
36
+ Writable(wrapper).rest = child;
37
+ return wrapper;
38
+ });
39
+ ArrayUtil.set(meta.tuples, children, join_tuple_names);
40
+ return true;
41
+ };
42
+
43
+ function join_tuple_names(metas: Metadata[]): string {
44
+ return `[${metas.map((m) => m.getName).join(", ")}]`;
45
+ }
@@ -1,59 +1,59 @@
1
- import ts from "typescript";
2
-
3
- import { Metadata } from "../../metadata/Metadata";
4
-
5
- import { Writable } from "../../typings/Writable";
6
-
7
- import { MetadataCollection } from "../MetadataCollection";
8
- import { MetadataFactory } from "../MetadataFactory";
9
- import { TypeFactory } from "../TypeFactory";
10
- import { iterate_metadata } from "./iterate_metadata";
11
-
12
- export const iterate_metadata_union =
13
- (checker: ts.TypeChecker) =>
14
- (options: MetadataFactory.IOptions) =>
15
- (collection: MetadataCollection) =>
16
- (meta: Metadata, type: ts.Type, parentResolved: boolean): boolean => {
17
- if (!type.isUnion()) return false;
18
- else if (options.resolve === false || parentResolved === true) {
19
- type.types.forEach((t) =>
20
- iterate_metadata(checker)(options)(collection)(meta, t, false),
21
- );
22
- return true;
23
- }
24
-
25
- const filter = (flag: ts.TypeFlags, t: ts.Type) =>
26
- (t.getFlags() & flag) !== 0;
27
- const normals: ts.Type[] = [];
28
- const toJsons: ts.Type[] = [];
29
-
30
- for (const individual of type.types) {
31
- if (filter(ts.TypeFlags.Object, individual)) {
32
- const resolved: ts.Type | null = TypeFactory.resolve(
33
- checker,
34
- individual,
35
- );
36
- if (resolved !== null) toJsons.push(resolved);
37
- else normals.push(individual);
38
- } else normals.push(individual);
39
- }
40
- if (toJsons.length !== 0) {
41
- Writable(meta).resolved = (() => {
42
- const union: Metadata = Metadata.initialize();
43
- toJsons.forEach((t) =>
44
- iterate_metadata(checker)(options)(collection)(
45
- meta,
46
- t,
47
- true,
48
- ),
49
- );
50
- if (union.objects.length > 1)
51
- union.union_index = collection.getUnionIndex(union);
52
- return union;
53
- })();
54
- }
55
- normals.forEach((t) =>
56
- iterate_metadata(checker)(options)(collection)(meta, t, false),
57
- );
58
- return true;
59
- };
1
+ import ts from "typescript";
2
+
3
+ import { Metadata } from "../../metadata/Metadata";
4
+
5
+ import { Writable } from "../../typings/Writable";
6
+
7
+ import { MetadataCollection } from "../MetadataCollection";
8
+ import { MetadataFactory } from "../MetadataFactory";
9
+ import { TypeFactory } from "../TypeFactory";
10
+ import { iterate_metadata } from "./iterate_metadata";
11
+
12
+ export const iterate_metadata_union =
13
+ (checker: ts.TypeChecker) =>
14
+ (options: MetadataFactory.IOptions) =>
15
+ (collection: MetadataCollection) =>
16
+ (meta: Metadata, type: ts.Type, parentResolved: boolean): boolean => {
17
+ if (!type.isUnion()) return false;
18
+ else if (options.resolve === false || parentResolved === true) {
19
+ type.types.forEach((t) =>
20
+ iterate_metadata(checker)(options)(collection)(meta, t, false),
21
+ );
22
+ return true;
23
+ }
24
+
25
+ const filter = (flag: ts.TypeFlags, t: ts.Type) =>
26
+ (t.getFlags() & flag) !== 0;
27
+ const normals: ts.Type[] = [];
28
+ const toJsons: ts.Type[] = [];
29
+
30
+ for (const individual of type.types) {
31
+ if (filter(ts.TypeFlags.Object, individual)) {
32
+ const resolved: ts.Type | null = TypeFactory.resolve(
33
+ checker,
34
+ individual,
35
+ );
36
+ if (resolved !== null) toJsons.push(resolved);
37
+ else normals.push(individual);
38
+ } else normals.push(individual);
39
+ }
40
+ if (toJsons.length !== 0) {
41
+ Writable(meta).resolved = (() => {
42
+ const union: Metadata = Metadata.initialize();
43
+ toJsons.forEach((t) =>
44
+ iterate_metadata(checker)(options)(collection)(
45
+ meta,
46
+ t,
47
+ true,
48
+ ),
49
+ );
50
+ if (union.objects.length > 1)
51
+ union.union_index = collection.getUnionIndex(union);
52
+ return union;
53
+ })();
54
+ }
55
+ normals.forEach((t) =>
56
+ iterate_metadata(checker)(options)(collection)(meta, t, false),
57
+ );
58
+ return true;
59
+ };
@@ -1,11 +1,11 @@
1
- import { TypeGuardError } from "../TypeGuardError";
2
-
3
- export const $every = <T>(
4
- array: T[],
5
- pred: (value: T, i: number) => null | Omit<TypeGuardError.IProps, "method">,
6
- ): null | Omit<TypeGuardError.IProps, "method"> => {
7
- let error: null | Omit<TypeGuardError.IProps, "method"> = null;
8
- for (let i: number = 0; i < array.length; ++i)
9
- if (null !== (error = pred(array[i]!, i))) return error;
10
- return null;
11
- };
1
+ import { TypeGuardError } from "../TypeGuardError";
2
+
3
+ export const $every = <T>(
4
+ array: T[],
5
+ pred: (value: T, i: number) => null | Omit<TypeGuardError.IProps, "method">,
6
+ ): null | Omit<TypeGuardError.IProps, "method"> => {
7
+ let error: null | Omit<TypeGuardError.IProps, "method"> = null;
8
+ for (let i: number = 0; i < array.length; ++i)
9
+ if (null !== (error = pred(array[i]!, i))) return error;
10
+ return null;
11
+ };
@@ -1,35 +1,35 @@
1
- import { TypeGuardError } from "../TypeGuardError";
2
-
3
- /* -----------------------------------------------------------
4
- ASSERT V2 -> USE (NULL OR ERROR) CONDITION
5
- ----------------------------------------------------------- */
6
- // /**
7
- // * @internal
8
- // */
9
- // export const $guardV2 =
10
- // (method: string) => (props: Omit<TypeGuardError.IProps, "method">) =>
11
- // new TypeGuardError({
12
- // method,
13
- // path: props.path,
14
- // expected: props.expected,
15
- // value: props.value,
16
- // });
17
-
18
- /* -----------------------------------------------------------
19
- ASSERT V3 -> (CONDITION OR THROW(exceptable): FALSE)
20
- ----------------------------------------------------------- */
21
- /**
22
- * @internal
23
- */
24
- export const $guard =
25
- (method: string) =>
26
- (exceptionable: boolean, props: Omit<TypeGuardError.IProps, "method">) => {
27
- if (exceptionable === true)
28
- throw new TypeGuardError({
29
- method,
30
- path: props.path,
31
- expected: props.expected,
32
- value: props.value,
33
- });
34
- return false;
35
- };
1
+ import { TypeGuardError } from "../TypeGuardError";
2
+
3
+ /* -----------------------------------------------------------
4
+ ASSERT V2 -> USE (NULL OR ERROR) CONDITION
5
+ ----------------------------------------------------------- */
6
+ // /**
7
+ // * @internal
8
+ // */
9
+ // export const $guardV2 =
10
+ // (method: string) => (props: Omit<TypeGuardError.IProps, "method">) =>
11
+ // new TypeGuardError({
12
+ // method,
13
+ // path: props.path,
14
+ // expected: props.expected,
15
+ // value: props.value,
16
+ // });
17
+
18
+ /* -----------------------------------------------------------
19
+ ASSERT V3 -> (CONDITION OR THROW(exceptable): FALSE)
20
+ ----------------------------------------------------------- */
21
+ /**
22
+ * @internal
23
+ */
24
+ export const $guard =
25
+ (method: string) =>
26
+ (exceptionable: boolean, props: Omit<TypeGuardError.IProps, "method">) => {
27
+ if (exceptionable === true)
28
+ throw new TypeGuardError({
29
+ method,
30
+ path: props.path,
31
+ expected: props.expected,
32
+ value: props.value,
33
+ });
34
+ return false;
35
+ };
@@ -1,5 +1,5 @@
1
- export function $is_email(str: string): boolean {
2
- return REGEX.test(str);
3
- }
4
- const REGEX =
5
- /^(([^<>()[\]\.,;:\s@\"]+(\.[^<>()[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i;
1
+ export function $is_email(str: string): boolean {
2
+ return REGEX.test(str);
3
+ }
4
+ const REGEX =
5
+ /^(([^<>()[\]\.,;:\s@\"]+(\.[^<>()[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i;
@@ -1,5 +1,5 @@
1
- export function $is_ipv4(str: string): boolean {
2
- return REGEX.test(str);
3
- }
4
- const REGEX =
5
- /^(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
1
+ export function $is_ipv4(str: string): boolean {
2
+ return REGEX.test(str);
3
+ }
4
+ const REGEX =
5
+ /^(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
@@ -1,5 +1,5 @@
1
- export function $is_ipv6(str: string): boolean {
2
- return REGEX.test(str);
3
- }
4
- const REGEX =
5
- /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/;
1
+ export function $is_ipv6(str: string): boolean {
2
+ return REGEX.test(str);
3
+ }
4
+ const REGEX =
5
+ /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/;
@@ -1,5 +1,5 @@
1
- export function $is_url(str: string): boolean {
2
- return REGEX.test(str);
3
- }
4
- const REGEX =
5
- /^[a-zA-Z0-9]+:\/\/(?:www.)?[-a-zA-Z0-9@:%._+~#=]{1,256}.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_+.~#?&/=]*)$/;
1
+ export function $is_url(str: string): boolean {
2
+ return REGEX.test(str);
3
+ }
4
+ const REGEX =
5
+ /^[a-zA-Z0-9]+:\/\/(?:www.)?[-a-zA-Z0-9@:%._+~#=]{1,256}.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_+.~#?&/=]*)$/;