typia 3.4.15 → 3.5.0-dev.20221222

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 (169) hide show
  1. package/README.md +48 -7
  2. package/lib/factories/MetadataCollection.d.ts +1 -9
  3. package/lib/factories/MetadataCollection.js +2 -75
  4. package/lib/factories/MetadataCollection.js.map +1 -1
  5. package/lib/factories/ProtocolFactory.d.ts +8 -0
  6. package/lib/factories/ProtocolFactory.js +119 -0
  7. package/lib/factories/ProtocolFactory.js.map +1 -0
  8. package/lib/factories/internal/protocols/ProtocolMetadataUtil.d.ts +11 -0
  9. package/lib/factories/internal/protocols/ProtocolMetadataUtil.js +76 -0
  10. package/lib/factories/internal/protocols/ProtocolMetadataUtil.js.map +1 -0
  11. package/lib/factories/internal/protocols/emplace_protocol_object.d.ts +3 -0
  12. package/lib/factories/internal/protocols/emplace_protocol_object.js +47 -0
  13. package/lib/factories/internal/protocols/emplace_protocol_object.js.map +1 -0
  14. package/lib/factories/internal/protocols/emplace_protocol_property.d.ts +4 -0
  15. package/lib/factories/internal/protocols/emplace_protocol_property.js +20 -0
  16. package/lib/factories/internal/protocols/emplace_protocol_property.js.map +1 -0
  17. package/lib/factories/internal/protocols/iterate_protocol_atomic.d.ts +3 -0
  18. package/lib/factories/internal/protocols/iterate_protocol_atomic.js +69 -0
  19. package/lib/factories/internal/protocols/iterate_protocol_atomic.js.map +1 -0
  20. package/lib/factories/internal/protocols/iterate_protocol_constant.d.ts +2 -0
  21. package/lib/factories/internal/protocols/iterate_protocol_constant.js +30 -0
  22. package/lib/factories/internal/protocols/iterate_protocol_constant.js.map +1 -0
  23. package/lib/factories/internal/protocols/iterate_protocol_main.d.ts +3 -0
  24. package/lib/factories/internal/protocols/iterate_protocol_main.js +17 -0
  25. package/lib/factories/internal/protocols/iterate_protocol_main.js.map +1 -0
  26. package/lib/factories/internal/protocols/iterate_protocol_map.d.ts +3 -0
  27. package/lib/factories/internal/protocols/iterate_protocol_map.js +71 -0
  28. package/lib/factories/internal/protocols/iterate_protocol_map.js.map +1 -0
  29. package/lib/factories/internal/protocols/iterate_protocol_metadata.d.ts +5 -0
  30. package/lib/factories/internal/protocols/iterate_protocol_metadata.js +192 -0
  31. package/lib/factories/internal/protocols/iterate_protocol_metadata.js.map +1 -0
  32. package/lib/factories/internal/protocols/iterate_protocol_native.d.ts +2 -0
  33. package/lib/factories/internal/protocols/iterate_protocol_native.js +33 -0
  34. package/lib/factories/internal/protocols/iterate_protocol_native.js.map +1 -0
  35. package/lib/factories/internal/protocols/iterate_protocol_repeated.d.ts +4 -0
  36. package/lib/factories/internal/protocols/iterate_protocol_repeated.js +24 -0
  37. package/lib/factories/internal/protocols/iterate_protocol_repeated.js.map +1 -0
  38. package/lib/factories/internal/protocols/iterate_protocol_tuple.d.ts +3 -0
  39. package/lib/factories/internal/protocols/iterate_protocol_tuple.js +46 -0
  40. package/lib/factories/internal/protocols/iterate_protocol_tuple.js.map +1 -0
  41. package/lib/functional/$proto_bytes.d.ts +2 -0
  42. package/lib/functional/$proto_bytes.js +37 -0
  43. package/lib/functional/$proto_bytes.js.map +1 -0
  44. package/lib/functional/$proto_field.d.ts +10 -0
  45. package/lib/functional/$proto_field.js +42 -0
  46. package/lib/functional/$proto_field.js.map +1 -0
  47. package/lib/functional/$proto_float.d.ts +4 -0
  48. package/lib/functional/$proto_float.js +28 -0
  49. package/lib/functional/$proto_float.js.map +1 -0
  50. package/lib/functional/$proto_i32.d.ts +2 -0
  51. package/lib/functional/$proto_i32.js +23 -0
  52. package/lib/functional/$proto_i32.js.map +1 -0
  53. package/lib/functional/$proto_i64.d.ts +2 -0
  54. package/lib/functional/$proto_i64.js +31 -0
  55. package/lib/functional/$proto_i64.js.map +1 -0
  56. package/lib/functional/$proto_size.d.ts +6 -0
  57. package/lib/functional/$proto_size.js +76 -0
  58. package/lib/functional/$proto_size.js.map +1 -0
  59. package/lib/functional/$proto_string.d.ts +2 -0
  60. package/lib/functional/$proto_string.js +34 -0
  61. package/lib/functional/$proto_string.js.map +1 -0
  62. package/lib/functional/$varint.d.ts +6 -0
  63. package/lib/functional/$varint.js +99 -0
  64. package/lib/functional/$varint.js.map +1 -0
  65. package/lib/functional/$zigzag.d.ts +4 -0
  66. package/lib/functional/$zigzag.js +34 -0
  67. package/lib/functional/$zigzag.js.map +1 -0
  68. package/lib/messages/IProtocolMessage.d.ts +5 -0
  69. package/lib/messages/IProtocolMessage.js +3 -0
  70. package/lib/messages/IProtocolMessage.js.map +1 -0
  71. package/lib/messages/IProtocolProperty.d.ts +11 -0
  72. package/lib/messages/IProtocolProperty.js +3 -0
  73. package/lib/messages/IProtocolProperty.js.map +1 -0
  74. package/lib/metadata/IMetadataTag.d.ts +7 -3
  75. package/lib/metadata/Metadata.js +1 -1
  76. package/lib/metadata/Metadata.js.map +1 -1
  77. package/lib/module.d.ts +2 -0
  78. package/lib/module.js +5 -1
  79. package/lib/module.js.map +1 -1
  80. package/lib/programmers/MessageProgrammer.d.ts +5 -0
  81. package/lib/programmers/MessageProgrammer.js +134 -0
  82. package/lib/programmers/MessageProgrammer.js.map +1 -0
  83. package/lib/programmers/internal/application_object.js +9 -9
  84. package/lib/programmers/internal/application_object.js.map +1 -1
  85. package/lib/programmers/internal/application_schema.js +5 -3
  86. package/lib/programmers/internal/application_schema.js.map +1 -1
  87. package/lib/transformers/CallExpressionTransformer.js +3 -1
  88. package/lib/transformers/CallExpressionTransformer.js.map +1 -1
  89. package/lib/transformers/features/miscellaneous/ApplicationTransformer.js +1 -3
  90. package/lib/transformers/features/miscellaneous/ApplicationTransformer.js.map +1 -1
  91. package/lib/transformers/features/protocols/MessageTransformer.d.ts +5 -0
  92. package/lib/transformers/features/protocols/MessageTransformer.js +17 -0
  93. package/lib/transformers/features/protocols/MessageTransformer.js.map +1 -0
  94. package/lib/utils/NameEncoder.d.ts +4 -0
  95. package/lib/utils/NameEncoder.js +89 -0
  96. package/lib/utils/NameEncoder.js.map +1 -0
  97. package/package.json +2 -3
  98. package/src/executable/internal/TypiaSetupWizard.ts +173 -173
  99. package/src/factories/MetadataCollection.ts +83 -122
  100. package/src/factories/MetadataFactory.ts +47 -47
  101. package/src/factories/MetadataTagFactory.ts +351 -351
  102. package/src/factories/ProtocolFactory.ts +92 -0
  103. package/src/factories/internal/metadata/MetadataHelper.ts +12 -12
  104. package/src/factories/internal/metadata/emplace_metadata_object.ts +140 -140
  105. package/src/factories/internal/metadata/explore_metadata.ts +92 -92
  106. package/src/factories/internal/metadata/iterate_metadata.ts +80 -80
  107. package/src/factories/internal/metadata/iterate_metadata_array.ts +29 -29
  108. package/src/factories/internal/metadata/iterate_metadata_atomic.ts +59 -59
  109. package/src/factories/internal/metadata/iterate_metadata_coalesce.ts +33 -33
  110. package/src/factories/internal/metadata/iterate_metadata_constant.ts +58 -58
  111. package/src/factories/internal/metadata/iterate_metadata_map.ts +41 -41
  112. package/src/factories/internal/metadata/iterate_metadata_native.ts +227 -227
  113. package/src/factories/internal/metadata/iterate_metadata_object.ts +48 -48
  114. package/src/factories/internal/metadata/iterate_metadata_resolve.ts +27 -27
  115. package/src/factories/internal/metadata/iterate_metadata_set.ts +33 -33
  116. package/src/factories/internal/metadata/iterate_metadata_template.ts +38 -38
  117. package/src/factories/internal/metadata/iterate_metadata_tuple.ts +45 -45
  118. package/src/factories/internal/metadata/iterate_metadata_union.ts +59 -59
  119. package/src/factories/internal/protocols/ProtocolMetadataUtil.ts +81 -0
  120. package/src/factories/internal/protocols/emplace_protocol_object.ts +25 -0
  121. package/src/factories/internal/protocols/emplace_protocol_property.ts +12 -0
  122. package/src/factories/internal/protocols/iterate_protocol_atomic.ts +34 -0
  123. package/src/factories/internal/protocols/iterate_protocol_constant.ts +27 -0
  124. package/src/factories/internal/protocols/iterate_protocol_main.ts +19 -0
  125. package/src/factories/internal/protocols/iterate_protocol_map.ts +38 -0
  126. package/src/factories/internal/protocols/iterate_protocol_metadata.ts +76 -0
  127. package/src/factories/internal/protocols/iterate_protocol_native.ts +34 -0
  128. package/src/factories/internal/protocols/iterate_protocol_repeated.ts +25 -0
  129. package/src/factories/internal/protocols/iterate_protocol_tuple.ts +25 -0
  130. package/src/functional/$number.ts +12 -12
  131. package/src/functional/$proto_bytes.ts +25 -0
  132. package/src/functional/$proto_field.ts +30 -0
  133. package/src/functional/$proto_float.ts +37 -0
  134. package/src/functional/$proto_i32.ts +29 -0
  135. package/src/functional/$proto_i64.ts +37 -0
  136. package/src/functional/$proto_size.ts +82 -0
  137. package/src/functional/$proto_string.ts +24 -0
  138. package/src/functional/$varint.ts +130 -0
  139. package/src/functional/$zigzag.ts +39 -0
  140. package/src/messages/IProtocolMessage.ts +6 -0
  141. package/src/messages/IProtocolProperty.ts +11 -0
  142. package/src/metadata/IMetadataTag.ts +137 -122
  143. package/src/metadata/Metadata.ts +479 -477
  144. package/src/module.ts +1547 -1535
  145. package/src/programmers/AssertParseProgrammer.ts +55 -55
  146. package/src/programmers/AssertProgrammer.ts +445 -445
  147. package/src/programmers/AssertStringifyProgrammer.ts +65 -65
  148. package/src/programmers/CheckerProgrammer.ts +810 -810
  149. package/src/programmers/IsParseProgrammer.ts +61 -61
  150. package/src/programmers/IsProgrammer.ts +175 -175
  151. package/src/programmers/IsStringifyProgrammer.ts +69 -69
  152. package/src/programmers/MessageProgrammer.ts +116 -0
  153. package/src/programmers/StringifyProgrammer.ts +762 -762
  154. package/src/programmers/ValidateParseProgrammer.ts +59 -59
  155. package/src/programmers/ValidateProgrammer.ts +237 -237
  156. package/src/programmers/ValidateStringifyProgrammer.ts +80 -80
  157. package/src/programmers/helpers/OptionPredicator.ts +15 -15
  158. package/src/programmers/internal/application_default.ts +17 -17
  159. package/src/programmers/internal/application_object.ts +5 -5
  160. package/src/programmers/internal/application_schema.ts +231 -228
  161. package/src/programmers/internal/check_bigint.ts +85 -85
  162. package/src/programmers/internal/check_number.ts +175 -175
  163. package/src/schemas/IJsonSchema.ts +90 -90
  164. package/src/transformers/CallExpressionTransformer.ts +131 -124
  165. package/src/transformers/ITransformOptions.ts +47 -47
  166. package/src/transformers/features/miscellaneous/ApplicationTransformer.ts +117 -119
  167. package/src/transformers/features/protocols/MessageTransformer.ts +32 -0
  168. package/src/transformers/features/stringifiers/StringifyTransformer.ts +46 -46
  169. package/src/utils/NameEncoder.ts +32 -0
@@ -1,228 +1,231 @@
1
- import { Metadata } from "../../metadata/Metadata";
2
- import { MetadataConstant } from "../../metadata/MetadataConstant";
3
- import { IJsonComponents } from "../../schemas/IJsonComponents";
4
- import { IJsonSchema } from "../../schemas/IJsonSchema";
5
-
6
- import { ArrayUtil } from "../../utils/ArrayUtil";
7
-
8
- import { ApplicationProgrammer } from "../ApplicationProgrammer";
9
- import { AtomicPredicator } from "../helpers/AtomicPredicator";
10
- import { application_array } from "./application_array";
11
- import { application_boolean } from "./application_boolean";
12
- import { application_constant } from "./application_constant";
13
- import { application_native } from "./application_native";
14
- import { application_number } from "./application_number";
15
- import { application_object } from "./application_object";
16
- import { application_string } from "./application_string";
17
- import { application_templates } from "./application_templates";
18
- import { application_tuple } from "./application_tuple";
19
-
20
- /**
21
- * @internal
22
- */
23
- export const application_schema =
24
- (options: ApplicationProgrammer.IOptions) =>
25
- (components: IJsonComponents) =>
26
- <BlockNever extends boolean>(blockNever: BlockNever) =>
27
- (
28
- meta: Metadata,
29
- attribute: IJsonSchema.IAttribute,
30
- ): BlockNever extends true ? IJsonSchema | null : IJsonSchema => {
31
- // VULNERABLE CASE
32
- if (meta.any === true) return {};
33
- else if (meta.nullable && meta.empty())
34
- return { type: "null", ...attribute };
35
-
36
- //----
37
- // GATHER UNION SCHEMAS
38
- //----
39
- const union: IJsonSchema[] = [];
40
-
41
- // toJSON() METHOD
42
- if (meta.resolved !== null) {
43
- const resolved = application_schema(options)(components)(
44
- blockNever,
45
- )(meta.resolved, attribute);
46
- if (resolved !== null) union.push(resolved);
47
- }
48
-
49
- // ATOMIC TYPES
50
- if (meta.templates.length && AtomicPredicator.template(meta))
51
- union.push(application_templates(meta, attribute));
52
- for (const constant of meta.constants) {
53
- if (constant.type === "bigint") throw new Error(NO_BIGINT);
54
- else if (
55
- (constant.type === "string" && meta.templates.length) ||
56
- AtomicPredicator.constant(meta)(constant.type) === false
57
- )
58
- continue;
59
- union.push(
60
- application_constant(constant, meta.nullable, attribute),
61
- );
62
- }
63
- for (const type of meta.atomics) {
64
- if (type === "bigint") throw new Error(NO_BIGINT);
65
- union.push(
66
- type === "string"
67
- ? application_string(meta, attribute)
68
- : type === "boolean"
69
- ? application_boolean(meta.nullable, attribute)
70
- : application_number(meta.nullable, attribute),
71
- );
72
- }
73
-
74
- // ARRAY
75
- for (const schema of meta.arrays.values())
76
- union.push(
77
- application_array(options)(components)(
78
- schema,
79
- meta.nullable,
80
- attribute,
81
- ),
82
- );
83
-
84
- // TUPLE
85
- for (const items of meta.tuples)
86
- if (
87
- options.purpose === "ajv" &&
88
- items.every((i) => i.rest === null)
89
- )
90
- union.push(
91
- application_tuple(options)(components)(
92
- items,
93
- meta.nullable,
94
- attribute,
95
- ),
96
- );
97
- else {
98
- // SWAGGER DOES NOT SUPPORT TUPLE TYPE YET
99
- const merged: Metadata = items.reduce((x, y) =>
100
- merge_metadata(x, y),
101
- );
102
- union.push(
103
- application_array(options)(components)(
104
- merged,
105
- merged?.nullable || false,
106
- attribute,
107
- ),
108
- );
109
- }
110
-
111
- // NATIVES
112
- for (const native of meta.natives)
113
- union.push(
114
- application_native(options)(components)(native)(
115
- meta.nullable,
116
- attribute,
117
- ),
118
- );
119
- if (meta.sets.length)
120
- union.push(
121
- application_native(options)(components)(`Set`)(
122
- meta.nullable,
123
- attribute,
124
- ),
125
- );
126
- if (meta.maps.length)
127
- union.push(
128
- application_native(options)(components)(`Map`)(
129
- meta.nullable,
130
- attribute,
131
- ),
132
- );
133
-
134
- // OBJECT
135
- for (const obj of meta.objects) {
136
- const key: string = obj.name + (meta.nullable ? ".Nullable" : "");
137
- application_object(options)(components)(key, obj, meta.nullable);
138
- union.push(
139
- (options.purpose === "ajv" && obj.recursive
140
- ? recursive
141
- : reference)(`${options.prefix}/${key}`, attribute),
142
- );
143
- }
144
-
145
- //----
146
- // RETURNS
147
- //----
148
- if (union.length === 0) return blockNever === true ? null! : {};
149
- else if (union.length === 1) return union[0]!;
150
- return { oneOf: union, ...attribute };
151
- };
152
-
153
- /**
154
- * @internal
155
- */
156
- const reference = (
157
- $ref: string,
158
- attribute: IJsonSchema.IAttribute,
159
- ): IJsonSchema.IReference => ({
160
- $ref,
161
- ...attribute,
162
- });
163
-
164
- /**
165
- * @internal
166
- */
167
- const recursive = (
168
- $recursiveRef: string,
169
- attribute: IJsonSchema.IAttribute,
170
- ): IJsonSchema.IRecursiveReference => ({
171
- $recursiveRef,
172
- ...attribute,
173
- });
174
-
175
- /**
176
- * @internal
177
- * @todo: not perfect
178
- */
179
- function merge_metadata(x: Metadata, y: Metadata): Metadata {
180
- const output: Metadata = Metadata.create({
181
- any: x.any || y.any,
182
- nullable: x.nullable || y.nullable,
183
- required: x.required && y.required,
184
- functional: x.functional || y.functional,
185
-
186
- resolved:
187
- x.resolved !== null && y.resolved !== null
188
- ? merge_metadata(x.resolved, y.resolved)
189
- : x.resolved || y.resolved,
190
- atomics: [...new Set([...x.atomics, ...y.atomics])],
191
- constants: [...x.constants],
192
- templates: x.templates.slice(),
193
-
194
- rest: null,
195
- arrays: x.arrays.slice(),
196
- tuples: x.tuples.slice(),
197
- objects: x.objects.slice(),
198
-
199
- natives: [...new Set([...x.natives, ...y.natives])],
200
- sets: x.sets.slice(),
201
- maps: x.maps.slice(),
202
- });
203
- for (const constant of y.constants) {
204
- const target: MetadataConstant = ArrayUtil.take(
205
- output.constants,
206
- (elem) => elem.type === constant.type,
207
- () => ({
208
- type: constant.type,
209
- values: [],
210
- }),
211
- );
212
- for (const value of constant.values)
213
- ArrayUtil.add(target.values, value);
214
- }
215
- for (const array of y.arrays)
216
- ArrayUtil.set(output.arrays, array, (elem) => elem.getName());
217
- for (const obj of y.objects)
218
- ArrayUtil.set(output.objects, obj, (elem) => elem.name);
219
-
220
- if (x.rest !== null)
221
- ArrayUtil.set(output.arrays, x.rest, (elem) => elem.getName());
222
- if (y.rest !== null)
223
- ArrayUtil.set(output.arrays, y.rest, (elem) => elem.getName());
224
-
225
- return output;
226
- }
227
-
228
- const NO_BIGINT = "Error on typia.application(): does not allow bigint type.";
1
+ import { Metadata } from "../../metadata/Metadata";
2
+ import { MetadataConstant } from "../../metadata/MetadataConstant";
3
+ import { IJsonComponents } from "../../schemas/IJsonComponents";
4
+ import { IJsonSchema } from "../../schemas/IJsonSchema";
5
+
6
+ import { ArrayUtil } from "../../utils/ArrayUtil";
7
+ import { NameEncoder } from "../../utils/NameEncoder";
8
+
9
+ import { ApplicationProgrammer } from "../ApplicationProgrammer";
10
+ import { AtomicPredicator } from "../helpers/AtomicPredicator";
11
+ import { application_array } from "./application_array";
12
+ import { application_boolean } from "./application_boolean";
13
+ import { application_constant } from "./application_constant";
14
+ import { application_native } from "./application_native";
15
+ import { application_number } from "./application_number";
16
+ import { application_object } from "./application_object";
17
+ import { application_string } from "./application_string";
18
+ import { application_templates } from "./application_templates";
19
+ import { application_tuple } from "./application_tuple";
20
+
21
+ /**
22
+ * @internal
23
+ */
24
+ export const application_schema =
25
+ (options: ApplicationProgrammer.IOptions) =>
26
+ (components: IJsonComponents) =>
27
+ <BlockNever extends boolean>(blockNever: BlockNever) =>
28
+ (
29
+ meta: Metadata,
30
+ attribute: IJsonSchema.IAttribute,
31
+ ): BlockNever extends true ? IJsonSchema | null : IJsonSchema => {
32
+ // VULNERABLE CASE
33
+ if (meta.any === true) return {};
34
+ else if (meta.nullable && meta.empty())
35
+ return { type: "null", ...attribute };
36
+
37
+ //----
38
+ // GATHER UNION SCHEMAS
39
+ //----
40
+ const union: IJsonSchema[] = [];
41
+
42
+ // toJSON() METHOD
43
+ if (meta.resolved !== null) {
44
+ const resolved = application_schema(options)(components)(
45
+ blockNever,
46
+ )(meta.resolved, attribute);
47
+ if (resolved !== null) union.push(resolved);
48
+ }
49
+
50
+ // ATOMIC TYPES
51
+ if (meta.templates.length && AtomicPredicator.template(meta))
52
+ union.push(application_templates(meta, attribute));
53
+ for (const constant of meta.constants) {
54
+ if (constant.type === "bigint") throw new Error(NO_BIGINT);
55
+ else if (
56
+ (constant.type === "string" && meta.templates.length) ||
57
+ AtomicPredicator.constant(meta)(constant.type) === false
58
+ )
59
+ continue;
60
+ union.push(
61
+ application_constant(constant, meta.nullable, attribute),
62
+ );
63
+ }
64
+ for (const type of meta.atomics) {
65
+ if (type === "bigint") throw new Error(NO_BIGINT);
66
+ union.push(
67
+ type === "string"
68
+ ? application_string(meta, attribute)
69
+ : type === "boolean"
70
+ ? application_boolean(meta.nullable, attribute)
71
+ : application_number(meta.nullable, attribute),
72
+ );
73
+ }
74
+
75
+ // ARRAY
76
+ for (const schema of meta.arrays.values())
77
+ union.push(
78
+ application_array(options)(components)(
79
+ schema,
80
+ meta.nullable,
81
+ attribute,
82
+ ),
83
+ );
84
+
85
+ // TUPLE
86
+ for (const items of meta.tuples)
87
+ if (
88
+ options.purpose === "ajv" &&
89
+ items.every((i) => i.rest === null)
90
+ )
91
+ union.push(
92
+ application_tuple(options)(components)(
93
+ items,
94
+ meta.nullable,
95
+ attribute,
96
+ ),
97
+ );
98
+ else {
99
+ // SWAGGER DOES NOT SUPPORT TUPLE TYPE YET
100
+ const merged: Metadata = items.reduce((x, y) =>
101
+ merge_metadata(x, y),
102
+ );
103
+ union.push(
104
+ application_array(options)(components)(
105
+ merged,
106
+ merged?.nullable || false,
107
+ attribute,
108
+ ),
109
+ );
110
+ }
111
+
112
+ // NATIVES
113
+ for (const native of meta.natives)
114
+ union.push(
115
+ application_native(options)(components)(native)(
116
+ meta.nullable,
117
+ attribute,
118
+ ),
119
+ );
120
+ if (meta.sets.length)
121
+ union.push(
122
+ application_native(options)(components)(`Set`)(
123
+ meta.nullable,
124
+ attribute,
125
+ ),
126
+ );
127
+ if (meta.maps.length)
128
+ union.push(
129
+ application_native(options)(components)(`Map`)(
130
+ meta.nullable,
131
+ attribute,
132
+ ),
133
+ );
134
+
135
+ // OBJECT
136
+ for (const obj of meta.objects) {
137
+ const id: string =
138
+ NameEncoder.encode(obj.name) +
139
+ (meta.nullable ? ".Nullable" : "");
140
+ application_object(options)(components)(id, obj, meta.nullable);
141
+ union.push(
142
+ (options.purpose === "ajv" && obj.recursive
143
+ ? recursive
144
+ : reference)(`${options.prefix}/${id}`, attribute),
145
+ );
146
+ }
147
+
148
+ //----
149
+ // RETURNS
150
+ //----
151
+ if (union.length === 0) return blockNever === true ? null! : {};
152
+ else if (union.length === 1) return union[0]!;
153
+ return { oneOf: union, ...attribute };
154
+ };
155
+
156
+ /**
157
+ * @internal
158
+ */
159
+ const reference = (
160
+ $ref: string,
161
+ attribute: IJsonSchema.IAttribute,
162
+ ): IJsonSchema.IReference => ({
163
+ $ref,
164
+ ...attribute,
165
+ });
166
+
167
+ /**
168
+ * @internal
169
+ */
170
+ const recursive = (
171
+ $recursiveRef: string,
172
+ attribute: IJsonSchema.IAttribute,
173
+ ): IJsonSchema.IRecursiveReference => ({
174
+ $recursiveRef,
175
+ ...attribute,
176
+ });
177
+
178
+ /**
179
+ * @internal
180
+ * @todo: not perfect
181
+ */
182
+ function merge_metadata(x: Metadata, y: Metadata): Metadata {
183
+ const output: Metadata = Metadata.create({
184
+ any: x.any || y.any,
185
+ nullable: x.nullable || y.nullable,
186
+ required: x.required && y.required,
187
+ functional: x.functional || y.functional,
188
+
189
+ resolved:
190
+ x.resolved !== null && y.resolved !== null
191
+ ? merge_metadata(x.resolved, y.resolved)
192
+ : x.resolved || y.resolved,
193
+ atomics: [...new Set([...x.atomics, ...y.atomics])],
194
+ constants: [...x.constants],
195
+ templates: x.templates.slice(),
196
+
197
+ rest: null,
198
+ arrays: x.arrays.slice(),
199
+ tuples: x.tuples.slice(),
200
+ objects: x.objects.slice(),
201
+
202
+ natives: [...new Set([...x.natives, ...y.natives])],
203
+ sets: x.sets.slice(),
204
+ maps: x.maps.slice(),
205
+ });
206
+ for (const constant of y.constants) {
207
+ const target: MetadataConstant = ArrayUtil.take(
208
+ output.constants,
209
+ (elem) => elem.type === constant.type,
210
+ () => ({
211
+ type: constant.type,
212
+ values: [],
213
+ }),
214
+ );
215
+ for (const value of constant.values)
216
+ ArrayUtil.add(target.values, value);
217
+ }
218
+ for (const array of y.arrays)
219
+ ArrayUtil.set(output.arrays, array, (elem) => elem.getName());
220
+ for (const obj of y.objects)
221
+ ArrayUtil.set(output.objects, obj, (elem) => elem.name);
222
+
223
+ if (x.rest !== null)
224
+ ArrayUtil.set(output.arrays, x.rest, (elem) => elem.getName());
225
+ if (y.rest !== null)
226
+ ArrayUtil.set(output.arrays, y.rest, (elem) => elem.getName());
227
+
228
+ return output;
229
+ }
230
+
231
+ const NO_BIGINT = "Error on typia.application(): does not allow bigint type.";
@@ -1,85 +1,85 @@
1
- import ts from "typescript";
2
-
3
- import { IMetadataTag } from "../../metadata/IMetadataTag";
4
-
5
- export function check_bigint(input: ts.Expression, tagList: IMetadataTag[]) {
6
- const caster = (value: number) =>
7
- ts.factory.createIdentifier(`${Math.floor(value)}n`);
8
-
9
- // TYPEOF STATEMENT
10
- const conditions: ts.Expression[] = [
11
- ts.factory.createStrictEquality(
12
- ts.factory.createStringLiteral("bigint"),
13
- ts.factory.createTypeOfExpression(input),
14
- ),
15
- ];
16
-
17
- // TAG (RANGE)
18
- for (const tag of tagList)
19
- if (tag.kind === "multipleOf")
20
- conditions.push(
21
- ts.factory.createStrictEquality(
22
- caster(0),
23
- ts.factory.createModulo(input, caster(tag.value)),
24
- ),
25
- );
26
- else if (tag.kind === "step") {
27
- const modulo = () =>
28
- ts.factory.createModulo(input, caster(tag.value));
29
- const minimum = (() => {
30
- for (const tag of tagList)
31
- if (tag.kind === "minimum") return tag.value;
32
- else if (tag.kind === "exclusiveMinimum") return tag.value;
33
- else if (tag.kind === "range" && tag.minimum !== undefined)
34
- return tag.minimum.value;
35
- return undefined;
36
- })();
37
- conditions.push(
38
- ts.factory.createStrictEquality(
39
- caster(0),
40
- minimum !== undefined
41
- ? ts.factory.createSubtract(modulo(), caster(minimum))
42
- : modulo(),
43
- ),
44
- );
45
- } else if (tag.kind === "range") {
46
- if (tag.minimum !== undefined)
47
- conditions.push(
48
- (tag.minimum.include
49
- ? ts.factory.createLessThanEquals
50
- : ts.factory.createLessThan)(
51
- caster(tag.minimum.value),
52
- input,
53
- ),
54
- );
55
- if (tag.maximum !== undefined)
56
- conditions.push(
57
- (tag.maximum.include
58
- ? ts.factory.createLessThanEquals
59
- : ts.factory.createLessThan)(
60
- input,
61
- caster(tag.maximum.value),
62
- ),
63
- );
64
- } else if (tag.kind === "minimum")
65
- conditions.push(
66
- ts.factory.createLessThanEquals(caster(tag.value), input),
67
- );
68
- else if (tag.kind === "maximum")
69
- conditions.push(
70
- ts.factory.createGreaterThanEquals(caster(tag.value), input),
71
- );
72
- else if (tag.kind === "exclusiveMinimum")
73
- conditions.push(
74
- ts.factory.createLessThan(caster(tag.value), input),
75
- );
76
- else if (tag.kind === "exclusiveMaximum")
77
- conditions.push(
78
- ts.factory.createGreaterThan(caster(tag.value), input),
79
- );
80
-
81
- // COMBINATION
82
- return conditions.length === 1
83
- ? conditions[0]!
84
- : conditions.reduce((x, y) => ts.factory.createLogicalAnd(x, y));
85
- }
1
+ import ts from "typescript";
2
+
3
+ import { IMetadataTag } from "../../metadata/IMetadataTag";
4
+
5
+ export function check_bigint(input: ts.Expression, tagList: IMetadataTag[]) {
6
+ const caster = (value: number) =>
7
+ ts.factory.createIdentifier(`${Math.floor(value)}n`);
8
+
9
+ // TYPEOF STATEMENT
10
+ const conditions: ts.Expression[] = [
11
+ ts.factory.createStrictEquality(
12
+ ts.factory.createStringLiteral("bigint"),
13
+ ts.factory.createTypeOfExpression(input),
14
+ ),
15
+ ];
16
+
17
+ // TAG (RANGE)
18
+ for (const tag of tagList)
19
+ if (tag.kind === "multipleOf")
20
+ conditions.push(
21
+ ts.factory.createStrictEquality(
22
+ caster(0),
23
+ ts.factory.createModulo(input, caster(tag.value)),
24
+ ),
25
+ );
26
+ else if (tag.kind === "step") {
27
+ const modulo = () =>
28
+ ts.factory.createModulo(input, caster(tag.value));
29
+ const minimum = (() => {
30
+ for (const tag of tagList)
31
+ if (tag.kind === "minimum") return tag.value;
32
+ else if (tag.kind === "exclusiveMinimum") return tag.value;
33
+ else if (tag.kind === "range" && tag.minimum !== undefined)
34
+ return tag.minimum.value;
35
+ return undefined;
36
+ })();
37
+ conditions.push(
38
+ ts.factory.createStrictEquality(
39
+ caster(0),
40
+ minimum !== undefined
41
+ ? ts.factory.createSubtract(modulo(), caster(minimum))
42
+ : modulo(),
43
+ ),
44
+ );
45
+ } else if (tag.kind === "range") {
46
+ if (tag.minimum !== undefined)
47
+ conditions.push(
48
+ (tag.minimum.include
49
+ ? ts.factory.createLessThanEquals
50
+ : ts.factory.createLessThan)(
51
+ caster(tag.minimum.value),
52
+ input,
53
+ ),
54
+ );
55
+ if (tag.maximum !== undefined)
56
+ conditions.push(
57
+ (tag.maximum.include
58
+ ? ts.factory.createLessThanEquals
59
+ : ts.factory.createLessThan)(
60
+ input,
61
+ caster(tag.maximum.value),
62
+ ),
63
+ );
64
+ } else if (tag.kind === "minimum")
65
+ conditions.push(
66
+ ts.factory.createLessThanEquals(caster(tag.value), input),
67
+ );
68
+ else if (tag.kind === "maximum")
69
+ conditions.push(
70
+ ts.factory.createGreaterThanEquals(caster(tag.value), input),
71
+ );
72
+ else if (tag.kind === "exclusiveMinimum")
73
+ conditions.push(
74
+ ts.factory.createLessThan(caster(tag.value), input),
75
+ );
76
+ else if (tag.kind === "exclusiveMaximum")
77
+ conditions.push(
78
+ ts.factory.createGreaterThan(caster(tag.value), input),
79
+ );
80
+
81
+ // COMBINATION
82
+ return conditions.length === 1
83
+ ? conditions[0]!
84
+ : conditions.reduce((x, y) => ts.factory.createLogicalAnd(x, y));
85
+ }