typia 4.1.8-dev.20230726 → 4.1.8

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 (159) hide show
  1. package/package.json +1 -1
  2. package/src/factories/MetadataCollection.ts +255 -255
  3. package/src/factories/MetadataFactory.ts +30 -30
  4. package/src/factories/MetadataTagFactory.ts +355 -355
  5. package/src/factories/internal/metadata/MetadataHelper.ts +12 -12
  6. package/src/factories/internal/metadata/emend_metadata_atomics.ts +33 -33
  7. package/src/factories/internal/metadata/emplace_metadata_alias.ts +40 -40
  8. package/src/factories/internal/metadata/emplace_metadata_array.ts +34 -34
  9. package/src/factories/internal/metadata/emplace_metadata_object.ts +136 -136
  10. package/src/factories/internal/metadata/emplace_metadata_tuple.ts +50 -50
  11. package/src/factories/internal/metadata/explore_metadata.ts +40 -40
  12. package/src/factories/internal/metadata/iterate_metadata.ts +81 -81
  13. package/src/factories/internal/metadata/iterate_metadata_alias.ts +30 -30
  14. package/src/factories/internal/metadata/iterate_metadata_array.ts +24 -24
  15. package/src/factories/internal/metadata/iterate_metadata_atomic.ts +59 -59
  16. package/src/factories/internal/metadata/iterate_metadata_coalesce.ts +33 -33
  17. package/src/factories/internal/metadata/iterate_metadata_collection.ts +133 -133
  18. package/src/factories/internal/metadata/iterate_metadata_constant.ts +58 -58
  19. package/src/factories/internal/metadata/iterate_metadata_intersection.ts +83 -83
  20. package/src/factories/internal/metadata/iterate_metadata_map.ts +41 -41
  21. package/src/factories/internal/metadata/iterate_metadata_native.ts +219 -219
  22. package/src/factories/internal/metadata/iterate_metadata_object.ts +43 -43
  23. package/src/factories/internal/metadata/iterate_metadata_resolve.ts +49 -49
  24. package/src/factories/internal/metadata/iterate_metadata_set.ts +33 -33
  25. package/src/factories/internal/metadata/iterate_metadata_sort.ts +69 -69
  26. package/src/factories/internal/metadata/iterate_metadata_tag.ts +31 -31
  27. package/src/factories/internal/metadata/iterate_metadata_template.ts +38 -38
  28. package/src/factories/internal/metadata/iterate_metadata_tuple.ts +24 -24
  29. package/src/factories/internal/metadata/iterate_metadata_union.ts +24 -24
  30. package/src/functional/$number.ts +12 -12
  31. package/src/metadata/ICommentTag.ts +4 -4
  32. package/src/metadata/IJsDocTagInfo.ts +10 -10
  33. package/src/metadata/IMetadata.ts +28 -28
  34. package/src/metadata/IMetadataAlias.ts +14 -14
  35. package/src/metadata/IMetadataApplication.ts +7 -7
  36. package/src/metadata/IMetadataArray.ts +10 -10
  37. package/src/metadata/IMetadataCollection.ts +11 -11
  38. package/src/metadata/IMetadataConstant.ts +16 -16
  39. package/src/metadata/IMetadataDictionary.ts +14 -14
  40. package/src/metadata/IMetadataEntry.ts +6 -6
  41. package/src/metadata/IMetadataObject.ts +18 -18
  42. package/src/metadata/IMetadataProperty.ts +11 -11
  43. package/src/metadata/IMetadataResolved.ts +6 -6
  44. package/src/metadata/IMetadataTag.ts +105 -105
  45. package/src/metadata/IMetadataTuple.ts +10 -10
  46. package/src/metadata/Metadata.ts +605 -605
  47. package/src/metadata/MetadataAlias.ts +66 -66
  48. package/src/metadata/MetadataArray.ts +55 -55
  49. package/src/metadata/MetadataConstant.ts +3 -3
  50. package/src/metadata/MetadataObject.ts +129 -129
  51. package/src/metadata/MetadataProperty.ts +64 -64
  52. package/src/metadata/MetadataResolved.ts +51 -51
  53. package/src/metadata/MetadataTuple.ts +53 -53
  54. package/src/module.ts +2038 -2038
  55. package/src/programmers/ApplicationProgrammer.ts +47 -47
  56. package/src/programmers/AssertCloneProgrammer.ts +71 -71
  57. package/src/programmers/AssertParseProgrammer.ts +66 -66
  58. package/src/programmers/AssertPruneProgrammer.ts +68 -68
  59. package/src/programmers/AssertStringifyProgrammer.ts +66 -66
  60. package/src/programmers/CheckerProgrammer.ts +1182 -1182
  61. package/src/programmers/CloneProgrammer.ts +587 -587
  62. package/src/programmers/FeatureProgrammer.ts +495 -495
  63. package/src/programmers/IsCloneProgrammer.ts +78 -78
  64. package/src/programmers/IsParseProgrammer.ts +72 -72
  65. package/src/programmers/IsProgrammer.ts +239 -239
  66. package/src/programmers/IsPruneProgrammer.ts +73 -73
  67. package/src/programmers/IsStringifyProgrammer.ts +76 -76
  68. package/src/programmers/LiteralsProgrammer.ts +63 -63
  69. package/src/programmers/PruneProgrammer.ts +542 -542
  70. package/src/programmers/RandomProgrammer.ts +581 -581
  71. package/src/programmers/StringifyProgrammer.ts +978 -978
  72. package/src/programmers/ValidateCloneProgrammer.ts +85 -85
  73. package/src/programmers/ValidateParseProgrammer.ts +70 -70
  74. package/src/programmers/ValidatePruneProgrammer.ts +78 -78
  75. package/src/programmers/ValidateStringifyProgrammer.ts +84 -84
  76. package/src/programmers/helpers/AtomicPredicator.ts +31 -31
  77. package/src/programmers/helpers/IExpressionEntry.ts +12 -12
  78. package/src/programmers/helpers/PruneJoiner.ts +143 -143
  79. package/src/programmers/helpers/RandomJoiner.ts +173 -173
  80. package/src/programmers/helpers/RandomRanger.ts +216 -216
  81. package/src/programmers/helpers/StringifyPredicator.ts +13 -13
  82. package/src/programmers/helpers/UnionExplorer.ts +301 -301
  83. package/src/programmers/helpers/UnionPredicator.ts +81 -81
  84. package/src/programmers/internal/application_alias.ts +66 -66
  85. package/src/programmers/internal/application_array.ts +30 -30
  86. package/src/programmers/internal/application_constant.ts +26 -26
  87. package/src/programmers/internal/application_default.ts +17 -17
  88. package/src/programmers/internal/application_default_string.ts +33 -33
  89. package/src/programmers/internal/application_native.ts +39 -39
  90. package/src/programmers/internal/application_number.ts +74 -74
  91. package/src/programmers/internal/application_object.ts +162 -162
  92. package/src/programmers/internal/application_resolved.ts +55 -55
  93. package/src/programmers/internal/application_schema.ts +157 -157
  94. package/src/programmers/internal/application_string.ts +44 -44
  95. package/src/programmers/internal/application_templates.ts +25 -25
  96. package/src/programmers/internal/application_tuple.ts +57 -57
  97. package/src/programmers/internal/check_array.ts +30 -30
  98. package/src/programmers/internal/check_array_length.ts +35 -35
  99. package/src/programmers/internal/check_bigint.ts +82 -82
  100. package/src/programmers/internal/check_custom.ts +31 -31
  101. package/src/programmers/internal/check_number.ts +177 -177
  102. package/src/programmers/internal/check_string.ts +25 -25
  103. package/src/programmers/internal/check_string_tags.ts +67 -67
  104. package/src/programmers/internal/check_template.ts +56 -56
  105. package/src/programmers/internal/check_union_array_like.ts +329 -329
  106. package/src/programmers/internal/decode_union_object.ts +73 -73
  107. package/src/programmers/internal/feature_object_entries.ts +63 -63
  108. package/src/programmers/internal/get_comment_tags.ts +23 -23
  109. package/src/programmers/internal/metadata_to_pattern.ts +34 -34
  110. package/src/programmers/internal/prune_object_properties.ts +60 -60
  111. package/src/programmers/internal/random_custom.ts +29 -29
  112. package/src/programmers/internal/stringify_regular_properties.ts +83 -83
  113. package/src/programmers/internal/template_to_pattern.ts +15 -15
  114. package/src/programmers/internal/wrap_metadata_rest_tuple.ts +16 -16
  115. package/src/schemas/IJsonApplication.ts +8 -8
  116. package/src/schemas/IJsonComponents.ts +33 -33
  117. package/src/schemas/IJsonSchema.ts +133 -133
  118. package/src/transformers/CallExpressionTransformer.ts +179 -179
  119. package/src/transformers/features/miscellaneous/ApplicationTransformer.ts +104 -104
  120. package/src/transformers/features/miscellaneous/AssertCloneTransformer.ts +9 -9
  121. package/src/transformers/features/miscellaneous/AssertPruneTransformer.ts +9 -9
  122. package/src/transformers/features/miscellaneous/CloneTransformer.ts +9 -9
  123. package/src/transformers/features/miscellaneous/CreateAssertCloneTransformer.ts +9 -9
  124. package/src/transformers/features/miscellaneous/CreateAssertPruneTransformer.ts +9 -9
  125. package/src/transformers/features/miscellaneous/CreateCloneTransformer.ts +9 -9
  126. package/src/transformers/features/miscellaneous/CreateIsCloneTransformer.ts +9 -9
  127. package/src/transformers/features/miscellaneous/CreateIsPruneTransformer.ts +9 -9
  128. package/src/transformers/features/miscellaneous/CreatePruneTransformer.ts +9 -9
  129. package/src/transformers/features/miscellaneous/CreateRandomTransformer.ts +39 -39
  130. package/src/transformers/features/miscellaneous/CreateValidateCloneTransformer.ts +9 -9
  131. package/src/transformers/features/miscellaneous/CreateValidatePruneTransformer.ts +9 -9
  132. package/src/transformers/features/miscellaneous/IsCloneTransformer.ts +9 -9
  133. package/src/transformers/features/miscellaneous/IsPruneTransformer.ts +9 -9
  134. package/src/transformers/features/miscellaneous/LiteralsTransformer.ts +28 -28
  135. package/src/transformers/features/miscellaneous/MetadataTransformer.ts +53 -53
  136. package/src/transformers/features/miscellaneous/PruneTransformer.ts +9 -9
  137. package/src/transformers/features/miscellaneous/RandomTransformer.ts +42 -42
  138. package/src/transformers/features/miscellaneous/ValidateCloneTransformer.ts +9 -9
  139. package/src/transformers/features/miscellaneous/ValidatePruneTransformer.ts +9 -9
  140. package/src/transformers/features/parsers/AssertParseTransformer.ts +9 -9
  141. package/src/transformers/features/parsers/CreateAssertParseTransformer.ts +9 -9
  142. package/src/transformers/features/parsers/CreateIsParseTransformer.ts +9 -9
  143. package/src/transformers/features/parsers/CreateValidateParseTransformer.ts +9 -9
  144. package/src/transformers/features/parsers/IsParseTransformer.ts +9 -9
  145. package/src/transformers/features/parsers/ValidateParseTransformer.ts +9 -9
  146. package/src/transformers/features/stringifiers/AssertStringifyTransformer.ts +10 -10
  147. package/src/transformers/features/stringifiers/CreateAssertStringifyTransformer.ts +12 -12
  148. package/src/transformers/features/stringifiers/CreateIsStringifyTransformer.ts +9 -9
  149. package/src/transformers/features/stringifiers/CreateStringifyTransformer.ts +9 -9
  150. package/src/transformers/features/stringifiers/CreateValidateStringifyProgrammer.ts +12 -12
  151. package/src/transformers/features/stringifiers/IsStringifyTransformer.ts +9 -9
  152. package/src/transformers/features/stringifiers/StringifyTransformer.ts +9 -9
  153. package/src/transformers/features/stringifiers/ValidateStringifyTransformer.ts +10 -10
  154. package/src/transformers/features/validators/AssertTransformer.ts +11 -11
  155. package/src/transformers/features/validators/CreateAssertTransformer.ts +13 -13
  156. package/src/transformers/features/validators/CreateIsTransformer.ts +11 -11
  157. package/src/transformers/features/validators/CreateValidateTransformer.ts +13 -13
  158. package/src/transformers/features/validators/IsTransformer.ts +11 -11
  159. package/src/transformers/features/validators/ValidateTransformer.ts +11 -11
@@ -1,12 +1,12 @@
1
- import { Metadata } from "../../../metadata/Metadata";
2
-
3
- export namespace MetadataHelper {
4
- export const literal_to_metadata = (key: string): Metadata => {
5
- const metadata: Metadata = Metadata.initialize();
6
- metadata.constants.push({
7
- type: "string",
8
- values: [key],
9
- });
10
- return metadata;
11
- };
12
- }
1
+ import { Metadata } from "../../../metadata/Metadata";
2
+
3
+ export namespace MetadataHelper {
4
+ export const literal_to_metadata = (key: string): Metadata => {
5
+ const metadata: Metadata = Metadata.initialize();
6
+ metadata.constants.push({
7
+ type: "string",
8
+ values: [key],
9
+ });
10
+ return metadata;
11
+ };
12
+ }
@@ -1,33 +1,33 @@
1
- import { Metadata } from "../../../metadata/Metadata";
2
-
3
- import { ArrayUtil } from "../../../utils/ArrayUtil";
4
-
5
- export const emend_metadata_atomics = (meta: Metadata) => {
6
- // ATOMICS
7
- for (const type of meta.atomics) {
8
- const index: number = meta.constants.findIndex((c) => c.type === type);
9
- if (index !== -1) meta.constants.splice(index, 1);
10
- }
11
-
12
- // BOOLEAN
13
- {
14
- const index: number = meta.constants.findIndex(
15
- (c) => c.type === "boolean",
16
- );
17
- if (index !== -1 && meta.constants[index]!.values.length === 2) {
18
- meta.constants.splice(index, 1);
19
- ArrayUtil.take(
20
- meta.atomics,
21
- (type) => type === "boolean",
22
- () => "boolean",
23
- );
24
- }
25
- }
26
-
27
- // TEMPLATE
28
- if (
29
- meta.templates.length &&
30
- meta.atomics.find((type) => type === "string") !== undefined
31
- )
32
- meta.templates.splice(0, meta.templates.length);
33
- };
1
+ import { Metadata } from "../../../metadata/Metadata";
2
+
3
+ import { ArrayUtil } from "../../../utils/ArrayUtil";
4
+
5
+ export const emend_metadata_atomics = (meta: Metadata) => {
6
+ // ATOMICS
7
+ for (const type of meta.atomics) {
8
+ const index: number = meta.constants.findIndex((c) => c.type === type);
9
+ if (index !== -1) meta.constants.splice(index, 1);
10
+ }
11
+
12
+ // BOOLEAN
13
+ {
14
+ const index: number = meta.constants.findIndex(
15
+ (c) => c.type === "boolean",
16
+ );
17
+ if (index !== -1 && meta.constants[index]!.values.length === 2) {
18
+ meta.constants.splice(index, 1);
19
+ ArrayUtil.take(
20
+ meta.atomics,
21
+ (type) => type === "boolean",
22
+ () => "boolean",
23
+ );
24
+ }
25
+ }
26
+
27
+ // TEMPLATE
28
+ if (
29
+ meta.templates.length &&
30
+ meta.atomics.find((type) => type === "string") !== undefined
31
+ )
32
+ meta.templates.splice(0, meta.templates.length);
33
+ };
@@ -1,40 +1,40 @@
1
- import ts from "typescript";
2
-
3
- import { Metadata } from "../../../metadata/Metadata";
4
- import { MetadataAlias } from "../../../metadata/MetadataAlias";
5
-
6
- import { ArrayUtil } from "../../../utils/ArrayUtil";
7
-
8
- import { MetadataCollection } from "../../MetadataCollection";
9
- import { MetadataFactory } from "../../MetadataFactory";
10
- import { MetadataTagFactory } from "../../MetadataTagFactory";
11
- import { explore_metadata } from "./explore_metadata";
12
-
13
- export const emplace_metadata_alias =
14
- (checker: ts.TypeChecker) =>
15
- (options: MetadataFactory.IOptions) =>
16
- (collection: MetadataCollection) =>
17
- (type: ts.Type, nullable: boolean): MetadataAlias => {
18
- // CHECK EXISTENCE
19
- const [alias, newbie, closure] = collection.emplaceAlias(
20
- checker,
21
- type,
22
- type.aliasSymbol!,
23
- );
24
- ArrayUtil.add(alias.nullables, nullable);
25
- if (newbie === false) return alias;
26
-
27
- // CONSTRUCT VALUE TYPE
28
- const value: Metadata = explore_metadata(checker)(options)(collection)(
29
- type,
30
- false,
31
- true,
32
- );
33
- closure(value);
34
- alias.tags.push(
35
- ...MetadataTagFactory.generate(value)(alias.jsDocTags)(
36
- () => alias.name,
37
- ),
38
- );
39
- return alias;
40
- };
1
+ import ts from "typescript";
2
+
3
+ import { Metadata } from "../../../metadata/Metadata";
4
+ import { MetadataAlias } from "../../../metadata/MetadataAlias";
5
+
6
+ import { ArrayUtil } from "../../../utils/ArrayUtil";
7
+
8
+ import { MetadataCollection } from "../../MetadataCollection";
9
+ import { MetadataFactory } from "../../MetadataFactory";
10
+ import { MetadataTagFactory } from "../../MetadataTagFactory";
11
+ import { explore_metadata } from "./explore_metadata";
12
+
13
+ export const emplace_metadata_alias =
14
+ (checker: ts.TypeChecker) =>
15
+ (options: MetadataFactory.IOptions) =>
16
+ (collection: MetadataCollection) =>
17
+ (type: ts.Type, nullable: boolean): MetadataAlias => {
18
+ // CHECK EXISTENCE
19
+ const [alias, newbie, closure] = collection.emplaceAlias(
20
+ checker,
21
+ type,
22
+ type.aliasSymbol!,
23
+ );
24
+ ArrayUtil.add(alias.nullables, nullable);
25
+ if (newbie === false) return alias;
26
+
27
+ // CONSTRUCT VALUE TYPE
28
+ const value: Metadata = explore_metadata(checker)(options)(collection)(
29
+ type,
30
+ false,
31
+ true,
32
+ );
33
+ closure(value);
34
+ alias.tags.push(
35
+ ...MetadataTagFactory.generate(value)(alias.jsDocTags)(
36
+ () => alias.name,
37
+ ),
38
+ );
39
+ return alias;
40
+ };
@@ -1,34 +1,34 @@
1
- import ts from "typescript";
2
-
3
- import { Metadata } from "../../../metadata/Metadata";
4
- import { MetadataArray } from "../../../metadata/MetadataArray";
5
-
6
- import { ArrayUtil } from "../../../utils/ArrayUtil";
7
-
8
- import { MetadataCollection } from "../../MetadataCollection";
9
- import { MetadataFactory } from "../../MetadataFactory";
10
- import { explore_metadata } from "./explore_metadata";
11
-
12
- export const emplace_metadata_array =
13
- (checker: ts.TypeChecker) =>
14
- (options: MetadataFactory.IOptions) =>
15
- (collection: MetadataCollection) =>
16
- (type: ts.Type, nullable: boolean): MetadataArray => {
17
- // CHECK EXISTENCE
18
- const [array, newbie, setValue] = collection.emplaceArray(
19
- checker,
20
- type,
21
- );
22
- ArrayUtil.add(array.nullables, nullable);
23
- if (newbie === false) return array;
24
-
25
- // CONSTRUCT VALUE TYPE
26
- const value: Metadata = explore_metadata(checker)(options)(collection)(
27
- type.getNumberIndexType()!,
28
- false,
29
- false,
30
- );
31
- setValue(value);
32
-
33
- return array;
34
- };
1
+ import ts from "typescript";
2
+
3
+ import { Metadata } from "../../../metadata/Metadata";
4
+ import { MetadataArray } from "../../../metadata/MetadataArray";
5
+
6
+ import { ArrayUtil } from "../../../utils/ArrayUtil";
7
+
8
+ import { MetadataCollection } from "../../MetadataCollection";
9
+ import { MetadataFactory } from "../../MetadataFactory";
10
+ import { explore_metadata } from "./explore_metadata";
11
+
12
+ export const emplace_metadata_array =
13
+ (checker: ts.TypeChecker) =>
14
+ (options: MetadataFactory.IOptions) =>
15
+ (collection: MetadataCollection) =>
16
+ (type: ts.Type, nullable: boolean): MetadataArray => {
17
+ // CHECK EXISTENCE
18
+ const [array, newbie, setValue] = collection.emplaceArray(
19
+ checker,
20
+ type,
21
+ );
22
+ ArrayUtil.add(array.nullables, nullable);
23
+ if (newbie === false) return array;
24
+
25
+ // CONSTRUCT VALUE TYPE
26
+ const value: Metadata = explore_metadata(checker)(options)(collection)(
27
+ type.getNumberIndexType()!,
28
+ false,
29
+ false,
30
+ );
31
+ setValue(value);
32
+
33
+ return array;
34
+ };
@@ -1,136 +1,136 @@
1
- import ts from "typescript";
2
-
3
- import { Metadata } from "../../../metadata/Metadata";
4
- import { MetadataObject } from "../../../metadata/MetadataObject";
5
- import { MetadataProperty } from "../../../metadata/MetadataProperty";
6
-
7
- import { Writable } from "../../../typings/Writable";
8
-
9
- import { ArrayUtil } from "../../../utils/ArrayUtil";
10
-
11
- import { CommentFactory } from "../../CommentFactory";
12
- import { MetadataCollection } from "../../MetadataCollection";
13
- import { MetadataFactory } from "../../MetadataFactory";
14
- import { MetadataHelper } from "./MetadataHelper";
15
- import { explore_metadata } from "./explore_metadata";
16
-
17
- export const emplace_metadata_object =
18
- (checker: ts.TypeChecker) =>
19
- (options: MetadataFactory.IOptions) =>
20
- (collection: MetadataCollection) =>
21
- (parent: ts.Type, nullable: boolean): MetadataObject => {
22
- // EMPLACE OBJECT
23
- const [obj, newbie] = collection.emplace(checker, parent);
24
- ArrayUtil.add(obj.nullables, nullable, (elem) => elem === nullable);
25
-
26
- if (newbie === false) return obj;
27
-
28
- // PREPARE ASSETS
29
- const isClass: boolean = parent.isClass();
30
- const pred: (node: ts.Declaration) => boolean = isClass
31
- ? (node) => {
32
- const kind: ts.SyntaxKind | undefined = node
33
- .getChildren()[0]
34
- ?.getChildren()[0]?.kind;
35
- return (
36
- kind !== ts.SyntaxKind.PrivateKeyword &&
37
- kind !== ts.SyntaxKind.ProtectedKeyword &&
38
- (ts.isParameter(node) || isProperty(node))
39
- );
40
- }
41
- : (node) => isProperty(node);
42
-
43
- const insert =
44
- (key: Metadata) =>
45
- (value: Metadata) =>
46
- (
47
- symbol: ts.Symbol | undefined,
48
- filter?: (doc: ts.JSDocTagInfo) => boolean,
49
- ): MetadataProperty => {
50
- // COMMENTS AND TAGS
51
- const description: string | null = symbol
52
- ? CommentFactory.description(symbol) ?? null
53
- : null;
54
- const jsDocTags: ts.JSDocTagInfo[] = (
55
- symbol?.getJsDocTags() ?? []
56
- ).filter(filter ?? (() => true));
57
-
58
- // THE PROPERTY
59
- const property = MetadataProperty.create({
60
- key,
61
- value,
62
- description,
63
- jsDocTags,
64
- tags: [],
65
- });
66
- obj.properties.push(property);
67
- return property;
68
- };
69
-
70
- //----
71
- // REGULAR PROPERTIES
72
- //----
73
- for (const prop of parent.getApparentProperties()) {
74
- // CHECK INTERNAL TAG
75
- if (
76
- (prop.getJsDocTags(checker) ?? []).find(
77
- (tag) => tag.name === "internal",
78
- ) !== undefined
79
- )
80
- continue;
81
-
82
- // CHECK NODE IS A FORMAL PROPERTY
83
- const [node, type] = (() => {
84
- const node = (prop.getDeclarations() ?? [])[0] as
85
- | ts.PropertyDeclaration
86
- | undefined;
87
- const type: ts.Type | undefined = node
88
- ? checker.getTypeOfSymbolAtLocation(prop, node)
89
- : "getTypeOfPropertyOfType" in checker
90
- ? (checker as any).getTypeOfPropertyOfType(
91
- parent,
92
- prop.name,
93
- )
94
- : undefined;
95
- return [node, type];
96
- })();
97
- if ((node && pred(node) === false) || type === undefined) continue;
98
-
99
- // GET EXACT TYPE
100
- const key: Metadata = MetadataHelper.literal_to_metadata(prop.name);
101
- const value: Metadata = explore_metadata(checker)(options)(
102
- collection,
103
- )(type, false);
104
-
105
- // OPTIONAL, BUT CAN BE RQUIRED BY `Required<T>` TYPE
106
- if (node?.questionToken) Writable(value).optional = true;
107
- insert(key)(value)(prop);
108
- }
109
-
110
- //----
111
- // DYNAMIC PROPERTIES
112
- //----
113
- for (const index of checker.getIndexInfosOfType(parent)) {
114
- // GET EXACT TYPE
115
- const analyzer = (type: ts.Type) =>
116
- explore_metadata(checker)(options)(collection)(type, false);
117
- const key: Metadata = analyzer(index.keyType);
118
- const value: Metadata = analyzer(index.type);
119
-
120
- // INSERT WITH REQUIRED CONFIGURATION
121
- insert(key)(value)(
122
- index.declaration?.parent
123
- ? checker.getSymbolAtLocation(index.declaration.parent)
124
- : undefined,
125
- (doc) => doc.name !== "default",
126
- );
127
- }
128
-
129
- return obj;
130
- };
131
-
132
- const isProperty = (node: ts.Declaration) =>
133
- ts.isPropertyDeclaration(node) ||
134
- ts.isPropertyAssignment(node) ||
135
- ts.isPropertySignature(node) ||
136
- ts.isTypeLiteralNode(node);
1
+ import ts from "typescript";
2
+
3
+ import { Metadata } from "../../../metadata/Metadata";
4
+ import { MetadataObject } from "../../../metadata/MetadataObject";
5
+ import { MetadataProperty } from "../../../metadata/MetadataProperty";
6
+
7
+ import { Writable } from "../../../typings/Writable";
8
+
9
+ import { ArrayUtil } from "../../../utils/ArrayUtil";
10
+
11
+ import { CommentFactory } from "../../CommentFactory";
12
+ import { MetadataCollection } from "../../MetadataCollection";
13
+ import { MetadataFactory } from "../../MetadataFactory";
14
+ import { MetadataHelper } from "./MetadataHelper";
15
+ import { explore_metadata } from "./explore_metadata";
16
+
17
+ export const emplace_metadata_object =
18
+ (checker: ts.TypeChecker) =>
19
+ (options: MetadataFactory.IOptions) =>
20
+ (collection: MetadataCollection) =>
21
+ (parent: ts.Type, nullable: boolean): MetadataObject => {
22
+ // EMPLACE OBJECT
23
+ const [obj, newbie] = collection.emplace(checker, parent);
24
+ ArrayUtil.add(obj.nullables, nullable, (elem) => elem === nullable);
25
+
26
+ if (newbie === false) return obj;
27
+
28
+ // PREPARE ASSETS
29
+ const isClass: boolean = parent.isClass();
30
+ const pred: (node: ts.Declaration) => boolean = isClass
31
+ ? (node) => {
32
+ const kind: ts.SyntaxKind | undefined = node
33
+ .getChildren()[0]
34
+ ?.getChildren()[0]?.kind;
35
+ return (
36
+ kind !== ts.SyntaxKind.PrivateKeyword &&
37
+ kind !== ts.SyntaxKind.ProtectedKeyword &&
38
+ (ts.isParameter(node) || isProperty(node))
39
+ );
40
+ }
41
+ : (node) => isProperty(node);
42
+
43
+ const insert =
44
+ (key: Metadata) =>
45
+ (value: Metadata) =>
46
+ (
47
+ symbol: ts.Symbol | undefined,
48
+ filter?: (doc: ts.JSDocTagInfo) => boolean,
49
+ ): MetadataProperty => {
50
+ // COMMENTS AND TAGS
51
+ const description: string | null = symbol
52
+ ? CommentFactory.description(symbol) ?? null
53
+ : null;
54
+ const jsDocTags: ts.JSDocTagInfo[] = (
55
+ symbol?.getJsDocTags() ?? []
56
+ ).filter(filter ?? (() => true));
57
+
58
+ // THE PROPERTY
59
+ const property = MetadataProperty.create({
60
+ key,
61
+ value,
62
+ description,
63
+ jsDocTags,
64
+ tags: [],
65
+ });
66
+ obj.properties.push(property);
67
+ return property;
68
+ };
69
+
70
+ //----
71
+ // REGULAR PROPERTIES
72
+ //----
73
+ for (const prop of parent.getApparentProperties()) {
74
+ // CHECK INTERNAL TAG
75
+ if (
76
+ (prop.getJsDocTags(checker) ?? []).find(
77
+ (tag) => tag.name === "internal",
78
+ ) !== undefined
79
+ )
80
+ continue;
81
+
82
+ // CHECK NODE IS A FORMAL PROPERTY
83
+ const [node, type] = (() => {
84
+ const node = (prop.getDeclarations() ?? [])[0] as
85
+ | ts.PropertyDeclaration
86
+ | undefined;
87
+ const type: ts.Type | undefined = node
88
+ ? checker.getTypeOfSymbolAtLocation(prop, node)
89
+ : "getTypeOfPropertyOfType" in checker
90
+ ? (checker as any).getTypeOfPropertyOfType(
91
+ parent,
92
+ prop.name,
93
+ )
94
+ : undefined;
95
+ return [node, type];
96
+ })();
97
+ if ((node && pred(node) === false) || type === undefined) continue;
98
+
99
+ // GET EXACT TYPE
100
+ const key: Metadata = MetadataHelper.literal_to_metadata(prop.name);
101
+ const value: Metadata = explore_metadata(checker)(options)(
102
+ collection,
103
+ )(type, false);
104
+
105
+ // OPTIONAL, BUT CAN BE RQUIRED BY `Required<T>` TYPE
106
+ if (node?.questionToken) Writable(value).optional = true;
107
+ insert(key)(value)(prop);
108
+ }
109
+
110
+ //----
111
+ // DYNAMIC PROPERTIES
112
+ //----
113
+ for (const index of checker.getIndexInfosOfType(parent)) {
114
+ // GET EXACT TYPE
115
+ const analyzer = (type: ts.Type) =>
116
+ explore_metadata(checker)(options)(collection)(type, false);
117
+ const key: Metadata = analyzer(index.keyType);
118
+ const value: Metadata = analyzer(index.type);
119
+
120
+ // INSERT WITH REQUIRED CONFIGURATION
121
+ insert(key)(value)(
122
+ index.declaration?.parent
123
+ ? checker.getSymbolAtLocation(index.declaration.parent)
124
+ : undefined,
125
+ (doc) => doc.name !== "default",
126
+ );
127
+ }
128
+
129
+ return obj;
130
+ };
131
+
132
+ const isProperty = (node: ts.Declaration) =>
133
+ ts.isPropertyDeclaration(node) ||
134
+ ts.isPropertyAssignment(node) ||
135
+ ts.isPropertySignature(node) ||
136
+ ts.isTypeLiteralNode(node);
@@ -1,50 +1,50 @@
1
- import ts from "typescript";
2
-
3
- import { Metadata } from "../../../metadata/Metadata";
4
- import { MetadataTuple } from "../../../metadata/MetadataTuple";
5
-
6
- import { Writable } from "../../../typings/Writable";
7
-
8
- import { ArrayUtil } from "../../../utils/ArrayUtil";
9
-
10
- import { MetadataCollection } from "../../MetadataCollection";
11
- import { MetadataFactory } from "../../MetadataFactory";
12
- import { explore_metadata } from "./explore_metadata";
13
-
14
- export const emplace_metadata_tuple =
15
- (checker: ts.TypeChecker) =>
16
- (options: MetadataFactory.IOptions) =>
17
- (collection: MetadataCollection) =>
18
- (type: ts.TupleType, nullable: boolean): MetadataTuple => {
19
- // CHECK EXISTENCE
20
- const [tuple, newbie, closure] = collection.emplaceTuple(checker, type);
21
- ArrayUtil.add(tuple.nullables, nullable);
22
- if (newbie === false) return tuple;
23
-
24
- // CONSTRUCT ELEMENT TYPES
25
- const flagList: readonly ts.ElementFlags[] =
26
- type.elementFlags ??
27
- (type.target as ts.TupleType)?.elementFlags ??
28
- [];
29
- const elements: Metadata[] = checker
30
- .getTypeArguments(type as ts.TypeReference)
31
- .map((elem, i) => {
32
- const child: Metadata = explore_metadata(checker)(options)(
33
- collection,
34
- )(elem, false, false);
35
-
36
- // CHECK OPTIONAL
37
- const flag: ts.ElementFlags | undefined = flagList[i];
38
- if (flag === ts.ElementFlags.Optional)
39
- Writable(child).optional = true;
40
-
41
- // REST TYPE
42
- if (flag !== ts.ElementFlags.Rest) return child;
43
- const wrapper: Metadata = Metadata.initialize();
44
- Writable(wrapper).rest = child;
45
- return wrapper;
46
- });
47
- closure(elements);
48
-
49
- return tuple;
50
- };
1
+ import ts from "typescript";
2
+
3
+ import { Metadata } from "../../../metadata/Metadata";
4
+ import { MetadataTuple } from "../../../metadata/MetadataTuple";
5
+
6
+ import { Writable } from "../../../typings/Writable";
7
+
8
+ import { ArrayUtil } from "../../../utils/ArrayUtil";
9
+
10
+ import { MetadataCollection } from "../../MetadataCollection";
11
+ import { MetadataFactory } from "../../MetadataFactory";
12
+ import { explore_metadata } from "./explore_metadata";
13
+
14
+ export const emplace_metadata_tuple =
15
+ (checker: ts.TypeChecker) =>
16
+ (options: MetadataFactory.IOptions) =>
17
+ (collection: MetadataCollection) =>
18
+ (type: ts.TupleType, nullable: boolean): MetadataTuple => {
19
+ // CHECK EXISTENCE
20
+ const [tuple, newbie, closure] = collection.emplaceTuple(checker, type);
21
+ ArrayUtil.add(tuple.nullables, nullable);
22
+ if (newbie === false) return tuple;
23
+
24
+ // CONSTRUCT ELEMENT TYPES
25
+ const flagList: readonly ts.ElementFlags[] =
26
+ type.elementFlags ??
27
+ (type.target as ts.TupleType)?.elementFlags ??
28
+ [];
29
+ const elements: Metadata[] = checker
30
+ .getTypeArguments(type as ts.TypeReference)
31
+ .map((elem, i) => {
32
+ const child: Metadata = explore_metadata(checker)(options)(
33
+ collection,
34
+ )(elem, false, false);
35
+
36
+ // CHECK OPTIONAL
37
+ const flag: ts.ElementFlags | undefined = flagList[i];
38
+ if (flag === ts.ElementFlags.Optional)
39
+ Writable(child).optional = true;
40
+
41
+ // REST TYPE
42
+ if (flag !== ts.ElementFlags.Rest) return child;
43
+ const wrapper: Metadata = Metadata.initialize();
44
+ Writable(wrapper).rest = child;
45
+ return wrapper;
46
+ });
47
+ closure(elements);
48
+
49
+ return tuple;
50
+ };