typia 5.0.0-dev.20230823-2 → 5.0.0-dev.2023084

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 (148) hide show
  1. package/lib/factories/MetadataTagFactory.js +4 -2
  2. package/lib/factories/MetadataTagFactory.js.map +1 -1
  3. package/lib/factories/ProtobufFactory.js +2 -1
  4. package/lib/factories/ProtobufFactory.js.map +1 -1
  5. package/lib/factories/internal/metadata/emend_metadata_atomics.js +6 -6
  6. package/lib/factories/internal/metadata/emend_metadata_atomics.js.map +1 -1
  7. package/lib/factories/internal/metadata/iterate_metadata_atomic.js +1 -1
  8. package/lib/factories/internal/metadata/iterate_metadata_atomic.js.map +1 -1
  9. package/lib/programmers/CheckerProgrammer.js +6 -6
  10. package/lib/programmers/CheckerProgrammer.js.map +1 -1
  11. package/lib/programmers/RandomProgrammer.js +5 -5
  12. package/lib/programmers/RandomProgrammer.js.map +1 -1
  13. package/lib/programmers/helpers/AtomicPredicator.js +2 -2
  14. package/lib/programmers/helpers/AtomicPredicator.js.map +1 -1
  15. package/lib/programmers/helpers/ProtobufUtil.js +2 -2
  16. package/lib/programmers/helpers/ProtobufUtil.js.map +1 -1
  17. package/lib/programmers/internal/application_default_string.js +2 -2
  18. package/lib/programmers/internal/application_default_string.js.map +1 -1
  19. package/lib/programmers/internal/application_schema.js +5 -5
  20. package/lib/programmers/internal/application_schema.js.map +1 -1
  21. package/lib/programmers/internal/metadata_to_pattern.js +4 -4
  22. package/lib/programmers/internal/metadata_to_pattern.js.map +1 -1
  23. package/lib/programmers/internal/stringify_dynamic_properties.js +2 -1
  24. package/lib/programmers/internal/stringify_dynamic_properties.js.map +1 -1
  25. package/lib/programmers/json/JsonStringifyProgrammer.js +16 -10
  26. package/lib/programmers/json/JsonStringifyProgrammer.js.map +1 -1
  27. package/lib/programmers/misc/MiscLiteralsProgrammer.js +2 -2
  28. package/lib/programmers/misc/MiscLiteralsProgrammer.js.map +1 -1
  29. package/lib/programmers/protobuf/ProtobufDecodeProgrammer.js +1 -1
  30. package/lib/programmers/protobuf/ProtobufDecodeProgrammer.js.map +1 -1
  31. package/lib/schemas/metadata/IMetadata.d.ts +2 -2
  32. package/lib/schemas/metadata/IMetadataAtomic.d.ts +12 -0
  33. package/lib/schemas/metadata/IMetadataAtomic.js +3 -0
  34. package/lib/schemas/metadata/IMetadataAtomic.js.map +1 -0
  35. package/lib/schemas/metadata/Metadata.d.ts +2 -2
  36. package/lib/schemas/metadata/Metadata.js +49 -44
  37. package/lib/schemas/metadata/Metadata.js.map +1 -1
  38. package/lib/tags/ExclusiveMaximum.d.ts +8 -0
  39. package/lib/tags/ExclusiveMaximum.js +3 -0
  40. package/lib/tags/ExclusiveMaximum.js.map +1 -0
  41. package/lib/tags/ExclusiveMinimum.d.ts +8 -0
  42. package/lib/tags/ExclusiveMinimum.js +3 -0
  43. package/lib/tags/ExclusiveMinimum.js.map +1 -0
  44. package/lib/tags/Format.d.ts +8 -0
  45. package/lib/tags/Format.js +3 -0
  46. package/lib/tags/Format.js.map +1 -0
  47. package/lib/tags/MaxItems.d.ts +8 -0
  48. package/lib/tags/MaxItems.js +3 -0
  49. package/lib/tags/MaxItems.js.map +1 -0
  50. package/lib/tags/MaxLength.d.ts +8 -0
  51. package/lib/tags/MaxLength.js +3 -0
  52. package/lib/tags/MaxLength.js.map +1 -0
  53. package/lib/tags/Maximum.d.ts +8 -0
  54. package/lib/tags/Maximum.js +3 -0
  55. package/lib/tags/Maximum.js.map +1 -0
  56. package/lib/tags/MinItems.d.ts +8 -0
  57. package/lib/tags/MinItems.js +3 -0
  58. package/lib/tags/MinItems.js.map +1 -0
  59. package/lib/tags/MinLength.d.ts +8 -0
  60. package/lib/tags/MinLength.js +3 -0
  61. package/lib/tags/MinLength.js.map +1 -0
  62. package/lib/tags/Minimum.d.ts +8 -0
  63. package/lib/tags/Minimum.js +3 -0
  64. package/lib/tags/Minimum.js.map +1 -0
  65. package/lib/tags/MultipleOf.d.ts +8 -0
  66. package/lib/tags/MultipleOf.js +3 -0
  67. package/lib/tags/MultipleOf.js.map +1 -0
  68. package/lib/tags/Pattern.d.ts +8 -0
  69. package/lib/tags/Pattern.js +3 -0
  70. package/lib/tags/Pattern.js.map +1 -0
  71. package/lib/tags/TagBase.d.ts +10 -0
  72. package/lib/tags/TagBase.js +3 -0
  73. package/lib/tags/TagBase.js.map +1 -0
  74. package/lib/tags/Type.d.ts +13 -0
  75. package/lib/tags/Type.js +3 -0
  76. package/lib/tags/Type.js.map +1 -0
  77. package/lib/tags/index.d.ts +12 -0
  78. package/lib/tags/index.js +29 -0
  79. package/lib/tags/index.js.map +1 -0
  80. package/lib/transformers/features/json/JsonApplicationTransformer.js +1 -1
  81. package/lib/transformers/features/json/JsonApplicationTransformer.js.map +1 -1
  82. package/package.json +1 -1
  83. package/src/Primitive.ts +135 -135
  84. package/src/Resolved.ts +116 -116
  85. package/src/factories/MetadataFactory.ts +46 -46
  86. package/src/factories/MetadataTagFactory.ts +366 -364
  87. package/src/factories/ProtobufFactory.ts +268 -266
  88. package/src/factories/internal/metadata/emend_metadata_atomics.ts +35 -33
  89. package/src/factories/internal/metadata/explore_metadata.ts +38 -38
  90. package/src/factories/internal/metadata/iterate_metadata_atomic.ts +63 -59
  91. package/src/factories/internal/metadata/iterate_metadata_collection.ts +133 -133
  92. package/src/factories/internal/metadata/iterate_metadata_native.ts +210 -210
  93. package/src/factories/internal/metadata/iterate_metadata_resolve.ts +49 -49
  94. package/src/factories/internal/metadata/iterate_metadata_sort.ts +69 -69
  95. package/src/functional/$ProtobufWriter.ts +151 -151
  96. package/src/json.ts +648 -648
  97. package/src/misc.ts +651 -651
  98. package/src/module.ts +709 -709
  99. package/src/programmers/AssertProgrammer.ts +281 -281
  100. package/src/programmers/CheckerProgrammer.ts +1174 -1173
  101. package/src/programmers/IsProgrammer.ts +241 -241
  102. package/src/programmers/RandomProgrammer.ts +874 -874
  103. package/src/programmers/ValidateProgrammer.ts +307 -307
  104. package/src/programmers/helpers/AtomicPredicator.ts +31 -31
  105. package/src/programmers/helpers/FunctionImporeter.ts +91 -91
  106. package/src/programmers/helpers/ProtobufUtil.ts +29 -29
  107. package/src/programmers/helpers/StringifyPredicator.ts +12 -12
  108. package/src/programmers/helpers/disable_function_importer_declare.ts +32 -32
  109. package/src/programmers/internal/application_default_string.ts +37 -33
  110. package/src/programmers/internal/application_resolved.ts +55 -55
  111. package/src/programmers/internal/application_schema.ts +157 -157
  112. package/src/programmers/internal/metadata_to_pattern.ts +34 -34
  113. package/src/programmers/internal/stringify_dynamic_properties.ts +171 -171
  114. package/src/programmers/json/JsonStringifyProgrammer.ts +995 -989
  115. package/src/programmers/misc/MiscAssertCloneProgrammer.ts +71 -71
  116. package/src/programmers/misc/MiscCloneProgrammer.ts +775 -775
  117. package/src/programmers/misc/MiscIsCloneProgrammer.ts +78 -78
  118. package/src/programmers/misc/MiscLiteralsProgrammer.ts +64 -64
  119. package/src/programmers/misc/MiscPruneProgrammer.ts +544 -544
  120. package/src/programmers/misc/MiscValidateCloneProgrammer.ts +85 -85
  121. package/src/programmers/protobuf/ProtobufAssertDecodeProgrammer.ts +75 -75
  122. package/src/programmers/protobuf/ProtobufDecodeProgrammer.ts +673 -673
  123. package/src/programmers/protobuf/ProtobufEncodeProgrammer.ts +814 -814
  124. package/src/programmers/protobuf/ProtobufIsDecodeProgrammer.ts +85 -85
  125. package/src/programmers/protobuf/ProtobufValidateDecodeProgrammer.ts +75 -75
  126. package/src/protobuf.ts +881 -881
  127. package/src/schemas/metadata/IMetadata.ts +27 -28
  128. package/src/schemas/metadata/IMetadataAtomic.ts +13 -0
  129. package/src/schemas/metadata/IMetadataEscaped.ts +6 -6
  130. package/src/schemas/metadata/Metadata.ts +643 -634
  131. package/src/schemas/metadata/MetadataEscaped.ts +51 -51
  132. package/src/tags/ExclusiveMaximum.ts +8 -0
  133. package/src/tags/ExclusiveMinimum.ts +8 -0
  134. package/src/tags/Format.ts +29 -0
  135. package/src/tags/MaxItems.ts +8 -0
  136. package/src/tags/MaxLength.ts +8 -0
  137. package/src/tags/Maximum.ts +8 -0
  138. package/src/tags/MinItems.ts +8 -0
  139. package/src/tags/MinLength.ts +8 -0
  140. package/src/tags/Minimum.ts +8 -0
  141. package/src/tags/MultipleOf.ts +10 -0
  142. package/src/tags/Pattern.ts +8 -0
  143. package/src/tags/TagBase.ts +17 -0
  144. package/src/tags/Type.ts +30 -0
  145. package/src/tags/index.ts +12 -0
  146. package/src/transformers/features/json/JsonApplicationTransformer.ts +111 -111
  147. package/src/transformers/features/misc/MetadataTransformer.ts +53 -53
  148. package/src/utils/RandomGenerator.ts +83 -83
@@ -1,989 +1,995 @@
1
- import ts from "typescript";
2
-
3
- import { ExpressionFactory } from "../../factories/ExpressionFactory";
4
- import { IdentifierFactory } from "../../factories/IdentifierFactory";
5
- import { MetadataCollection } from "../../factories/MetadataCollection";
6
- import { MetadataFactory } from "../../factories/MetadataFactory";
7
- import { StatementFactory } from "../../factories/StatementFactory";
8
- import { TypeFactory } from "../../factories/TypeFactory";
9
- import { ValueFactory } from "../../factories/ValueFactory";
10
-
11
- import { IJsDocTagInfo } from "../../schemas/metadata/IJsDocTagInfo";
12
- import { IMetadataTag } from "../../schemas/metadata/IMetadataTag";
13
- import { Metadata } from "../../schemas/metadata/Metadata";
14
- import { MetadataArray } from "../../schemas/metadata/MetadataArray";
15
- import { MetadataObject } from "../../schemas/metadata/MetadataObject";
16
- import { MetadataTuple } from "../../schemas/metadata/MetadataTuple";
17
-
18
- import { IProject } from "../../transformers/IProject";
19
-
20
- import { Atomic } from "../../typings/Atomic";
21
-
22
- import { ArrayUtil } from "../../utils/ArrayUtil";
23
-
24
- import { FeatureProgrammer } from "../FeatureProgrammer";
25
- import { IsProgrammer } from "../IsProgrammer";
26
- import { AtomicPredicator } from "../helpers/AtomicPredicator";
27
- import { FunctionImporter } from "../helpers/FunctionImporeter";
28
- import { IExpressionEntry } from "../helpers/IExpressionEntry";
29
- import { OptionPredicator } from "../helpers/OptionPredicator";
30
- import { StringifyJoiner } from "../helpers/StringifyJoinder";
31
- import { StringifyPredicator } from "../helpers/StringifyPredicator";
32
- import { UnionExplorer } from "../helpers/UnionExplorer";
33
- import { check_native } from "../internal/check_native";
34
- import { decode_union_object } from "../internal/decode_union_object";
35
- import { feature_object_entries } from "../internal/feature_object_entries";
36
- import { wrap_metadata_rest_tuple } from "../internal/wrap_metadata_rest_tuple";
37
-
38
- export namespace JsonStringifyProgrammer {
39
- /* -----------------------------------------------------------
40
- WRITER
41
- ----------------------------------------------------------- */
42
-
43
- export const write =
44
- (project: IProject) => (modulo: ts.LeftHandSideExpression) => {
45
- const importer: FunctionImporter = new FunctionImporter(
46
- modulo.getText(),
47
- );
48
- const config: FeatureProgrammer.IConfig =
49
- configure(project)(importer);
50
-
51
- return FeatureProgrammer.write(project)({
52
- ...config,
53
- addition: (collection) => [
54
- ...IsProgrammer.write_function_statements(project)(
55
- importer,
56
- )(collection),
57
- ...importer.declare(modulo),
58
- ],
59
- })(importer);
60
- };
61
-
62
- const write_array_functions =
63
- (config: FeatureProgrammer.IConfig) =>
64
- (importer: FunctionImporter) =>
65
- (collection: MetadataCollection): ts.VariableStatement[] =>
66
- collection
67
- .arrays()
68
- .filter((a) => a.recursive)
69
- .map((array, i) =>
70
- StatementFactory.constant(
71
- `${config.prefix}a${i}`,
72
- ts.factory.createArrowFunction(
73
- undefined,
74
- undefined,
75
- FeatureProgrammer.parameterDeclarations(config)(
76
- TypeFactory.keyword("any"),
77
- )(ts.factory.createIdentifier("input")),
78
- TypeFactory.keyword("any"),
79
- undefined,
80
- decode_array_inline(config)(importer)(
81
- ts.factory.createIdentifier("input"),
82
- array,
83
- {
84
- tracable: config.trace,
85
- source: "function",
86
- from: "array",
87
- postfix: "",
88
- },
89
- ),
90
- ),
91
- ),
92
- );
93
-
94
- const write_tuple_functions =
95
- (project: IProject) =>
96
- (config: FeatureProgrammer.IConfig) =>
97
- (importer: FunctionImporter) =>
98
- (collection: MetadataCollection): ts.VariableStatement[] =>
99
- collection
100
- .tuples()
101
- .filter((t) => t.recursive)
102
- .map((tuple, i) =>
103
- StatementFactory.constant(
104
- `${config.prefix}t${i}`,
105
- ts.factory.createArrowFunction(
106
- undefined,
107
- undefined,
108
- FeatureProgrammer.parameterDeclarations(config)(
109
- TypeFactory.keyword("any"),
110
- )(ts.factory.createIdentifier("input")),
111
- TypeFactory.keyword("any"),
112
- undefined,
113
- decode_tuple_inline(project)(config)(importer)(
114
- ts.factory.createIdentifier("input"),
115
- tuple,
116
- {
117
- tracable: config.trace,
118
- source: "function",
119
- from: "array",
120
- postfix: "",
121
- },
122
- ),
123
- ),
124
- ),
125
- );
126
-
127
- /* -----------------------------------------------------------
128
- DECODERS
129
- ----------------------------------------------------------- */
130
- const decode =
131
- (project: IProject) =>
132
- (config: FeatureProgrammer.IConfig) =>
133
- (importer: FunctionImporter) =>
134
- (
135
- input: ts.Expression,
136
- meta: Metadata,
137
- explore: FeatureProgrammer.IExplore,
138
- ): ts.Expression => {
139
- // ANY TYPE
140
- if (meta.any === true)
141
- return wrap_required(
142
- input,
143
- meta,
144
- explore,
145
- )(
146
- wrap_functional(
147
- input,
148
- meta,
149
- explore,
150
- )(
151
- ts.factory.createCallExpression(
152
- ts.factory.createIdentifier("JSON.stringify"),
153
- undefined,
154
- [input],
155
- ),
156
- ),
157
- );
158
-
159
- // ONLY NULL OR UNDEFINED
160
- const size: number = meta.size();
161
- if (
162
- size === 0 &&
163
- (meta.isRequired() === false || meta.nullable === true)
164
- ) {
165
- if (meta.isRequired() === false && meta.nullable === true)
166
- return explore.from === "array"
167
- ? ts.factory.createStringLiteral("null")
168
- : ts.factory.createConditionalExpression(
169
- ts.factory.createStrictEquality(
170
- ts.factory.createNull(),
171
- input,
172
- ),
173
- undefined,
174
- ts.factory.createStringLiteral("null"),
175
- undefined,
176
- ts.factory.createIdentifier("undefined"),
177
- );
178
- else if (meta.isRequired() === false)
179
- return explore.from === "array"
180
- ? ts.factory.createStringLiteral("null")
181
- : ts.factory.createIdentifier("undefined");
182
- else return ts.factory.createStringLiteral("null");
183
- }
184
-
185
- //----
186
- // LIST UP UNION TYPES
187
- //----
188
- const unions: IUnion[] = [];
189
-
190
- // toJSON() METHOD
191
- if (meta.escaped !== null)
192
- unions.push({
193
- type: "resolved",
194
- is: () => IsProgrammer.decode_to_json(false)(input),
195
- value: () =>
196
- decode_to_json(project)(config)(importer)(
197
- input,
198
- meta.escaped!.returns,
199
- explore,
200
- ),
201
- });
202
- else if (meta.functional === true)
203
- unions.push({
204
- type: "functional",
205
- is: () => IsProgrammer.decode_functional(input),
206
- value: () => decode_functional(explore),
207
- });
208
-
209
- // TEMPLATES
210
- if (
211
- meta.templates.length ||
212
- ArrayUtil.has(meta.constants, (c) => c.type === "string")
213
- )
214
- if (AtomicPredicator.template(meta)) {
215
- const partial = Metadata.initialize();
216
- partial.atomics.push("string"),
217
- unions.push({
218
- type: "template literal",
219
- is: () =>
220
- IsProgrammer.decode(project)(importer)(
221
- input,
222
- partial,
223
- explore,
224
- [],
225
- [],
226
- ),
227
- value: () =>
228
- decode_atomic(project)(importer)(
229
- input,
230
- "string",
231
- explore,
232
- ),
233
- });
234
- }
235
-
236
- // CONSTANTS
237
- for (const constant of meta.constants)
238
- if (AtomicPredicator.constant(meta)(constant.type) === false)
239
- continue;
240
- else if (constant.type !== "string")
241
- unions.push({
242
- type: "atomic",
243
- is: () =>
244
- IsProgrammer.decode(project)(importer)(
245
- input,
246
- (() => {
247
- const partial = Metadata.initialize();
248
- partial.atomics.push(constant.type);
249
- return partial;
250
- })(),
251
- explore,
252
- [],
253
- [],
254
- ),
255
- value: () =>
256
- decode_atomic(project)(importer)(
257
- input,
258
- constant.type,
259
- explore,
260
- ),
261
- });
262
- else if (meta.templates.length === 0)
263
- unions.push({
264
- type: "const string",
265
- is: () =>
266
- IsProgrammer.decode(project)(importer)(
267
- input,
268
- (() => {
269
- const partial = Metadata.initialize();
270
- partial.atomics.push("string");
271
- return partial;
272
- })(),
273
- explore,
274
- [],
275
- [],
276
- ),
277
- value: () =>
278
- decode_constant_string(project)(importer)(
279
- input,
280
- [...constant.values] as string[],
281
- explore,
282
- ),
283
- });
284
-
285
- /// ATOMICS
286
- for (const type of meta.atomics)
287
- if (AtomicPredicator.atomic(meta)(type))
288
- unions.push({
289
- type: "atomic",
290
- is: () =>
291
- IsProgrammer.decode(project)(importer)(
292
- input,
293
- (() => {
294
- const partial = Metadata.initialize();
295
- partial.atomics.push(type);
296
- return partial;
297
- })(),
298
- explore,
299
- [],
300
- [],
301
- ),
302
- value: () =>
303
- decode_atomic(project)(importer)(
304
- input,
305
- type,
306
- explore,
307
- ),
308
- });
309
-
310
- // TUPLES
311
- for (const tuple of meta.tuples) {
312
- for (const child of tuple.elements)
313
- if (StringifyPredicator.undefindable(meta))
314
- throw new Error(
315
- `Error on typia.json.stringify(): tuple cannot contain undefined value - (${child.getName()}).`,
316
- );
317
- unions.push({
318
- type: "tuple",
319
- is: () =>
320
- IsProgrammer.decode(project)(importer)(
321
- input,
322
- (() => {
323
- const partial = Metadata.initialize();
324
- partial.tuples.push(tuple);
325
- return partial;
326
- })(),
327
- explore,
328
- [],
329
- [],
330
- ),
331
- value: () =>
332
- decode_tuple(project)(config)(importer)(
333
- input,
334
- tuple,
335
- explore,
336
- ),
337
- });
338
- }
339
-
340
- // ARRAYS
341
- if (meta.arrays.length) {
342
- for (const child of meta.arrays)
343
- if (StringifyPredicator.undefindable(child.value))
344
- throw new Error(
345
- `Error on typia.json.stringify(): array cannot contain undefined value (${child.value.getName()}).`,
346
- );
347
- const value: () => ts.Expression =
348
- meta.arrays.length === 1
349
- ? () =>
350
- decode_array(config)(importer)(
351
- input,
352
- meta.arrays[0]!,
353
- {
354
- ...explore,
355
- from: "array",
356
- },
357
- )
358
- : meta.arrays.some((elem) => elem.value.any)
359
- ? () =>
360
- ts.factory.createCallExpression(
361
- ts.factory.createIdentifier("JSON.stringify"),
362
- undefined,
363
- [input],
364
- )
365
- : () =>
366
- explore_arrays(project)(config)(importer)(
367
- input,
368
- meta.arrays,
369
- {
370
- ...explore,
371
- from: "array",
372
- },
373
- );
374
-
375
- unions.push({
376
- type: "array",
377
- is: () => ExpressionFactory.isArray(input),
378
- value,
379
- });
380
- }
381
-
382
- // BUILT-IN CLASSES
383
- if (meta.natives.length)
384
- for (const native of meta.natives)
385
- unions.push({
386
- type: "object",
387
- is: () => check_native(native)(input),
388
- value: () =>
389
- AtomicPredicator.native(native)
390
- ? decode_atomic(project)(importer)(
391
- input,
392
- native.toLowerCase() as Atomic.Literal,
393
- explore,
394
- )
395
- : ts.factory.createStringLiteral("{}"),
396
- });
397
-
398
- // SETS
399
- if (meta.sets.length)
400
- unions.push({
401
- type: "object",
402
- is: () => ExpressionFactory.isInstanceOf("Set")(input),
403
- value: () => ts.factory.createStringLiteral("{}"),
404
- });
405
-
406
- // MAPS
407
- if (meta.maps.length)
408
- unions.push({
409
- type: "object",
410
- is: () => ExpressionFactory.isInstanceOf("Map")(input),
411
- value: () => ts.factory.createStringLiteral("{}"),
412
- });
413
-
414
- // OBJECTS
415
- if (meta.objects.length)
416
- unions.push({
417
- type: "object",
418
- is: () =>
419
- ExpressionFactory.isObject({
420
- checkNull: true,
421
- checkArray: meta.objects.some((obj) =>
422
- obj.properties.every(
423
- (prop) =>
424
- !prop.key.isSoleLiteral() ||
425
- !prop.value.isRequired(),
426
- ),
427
- ),
428
- })(input),
429
- value: () =>
430
- meta.isParentResolved() === false &&
431
- meta.objects.length === 1 &&
432
- meta.objects[0]!._Is_simple(
433
- explore.from === "top" ? 0 : 1,
434
- )
435
- ? (() => {
436
- const obj: MetadataObject = meta.objects[0]!;
437
- const entries: IExpressionEntry<ts.Expression>[] =
438
- feature_object_entries({
439
- decoder: () =>
440
- decode(project)(config)(importer),
441
- trace: false,
442
- path: false,
443
- })(importer)(obj)(
444
- ts.factory.createAsExpression(
445
- input,
446
- TypeFactory.keyword("any"),
447
- ),
448
- );
449
- return StringifyJoiner.object(importer)(
450
- ts.factory.createAsExpression(
451
- input,
452
- TypeFactory.keyword("any"),
453
- ),
454
- entries,
455
- );
456
- })()
457
- : explore_objects(config)(importer)(input, meta, {
458
- ...explore,
459
- from: "object",
460
- }),
461
- });
462
-
463
- //----
464
- // RETURNS
465
- //----
466
- // CHECK NULL AND UNDEFINED
467
- const wrapper = (output: ts.Expression) =>
468
- wrap_required(
469
- input,
470
- meta,
471
- explore,
472
- )(wrap_nullable(input, meta)(output));
473
-
474
- // DIRECT RETURN
475
- if (unions.length === 0)
476
- return ts.factory.createCallExpression(
477
- ts.factory.createIdentifier("JSON.stringify"),
478
- undefined,
479
- [input],
480
- );
481
- else if (unions.length === 1) return wrapper(unions[0]!.value());
482
-
483
- // RETURN WITH TYPE CHECKING
484
- return wrapper(
485
- ts.factory.createCallExpression(
486
- ts.factory.createArrowFunction(
487
- undefined,
488
- undefined,
489
- [],
490
- undefined,
491
- undefined,
492
- iterate(importer, input, unions, meta.getName()),
493
- ),
494
- undefined,
495
- undefined,
496
- ),
497
- );
498
- };
499
-
500
- const decode_object = (importer: FunctionImporter) =>
501
- FeatureProgrammer.decode_object({
502
- trace: false,
503
- path: false,
504
- prefix: PREFIX,
505
- })(importer);
506
-
507
- const decode_array =
508
- (config: FeatureProgrammer.IConfig) =>
509
- (importer: FunctionImporter) =>
510
- (
511
- input: ts.Expression,
512
- array: MetadataArray,
513
- explore: FeatureProgrammer.IExplore,
514
- ) =>
515
- array.recursive
516
- ? ts.factory.createCallExpression(
517
- ts.factory.createIdentifier(
518
- importer.useLocal(`${config.prefix}a${array.index}`),
519
- ),
520
- undefined,
521
- FeatureProgrammer.argumentsArray(config)({
522
- ...explore,
523
- source: "function",
524
- from: "array",
525
- })(input),
526
- )
527
- : decode_array_inline(config)(importer)(input, array, explore);
528
-
529
- const decode_array_inline =
530
- (config: FeatureProgrammer.IConfig) =>
531
- (importer: FunctionImporter) =>
532
- (
533
- input: ts.Expression,
534
- array: MetadataArray,
535
- explore: FeatureProgrammer.IExplore,
536
- ) =>
537
- FeatureProgrammer.decode_array(config)(importer)(
538
- StringifyJoiner.array,
539
- )(input, array, explore, [], []);
540
-
541
- const decode_tuple =
542
- (project: IProject) =>
543
- (config: FeatureProgrammer.IConfig) =>
544
- (importer: FunctionImporter) =>
545
- (
546
- input: ts.Expression,
547
- tuple: MetadataTuple,
548
- explore: FeatureProgrammer.IExplore,
549
- ): ts.Expression =>
550
- tuple.recursive
551
- ? ts.factory.createCallExpression(
552
- ts.factory.createIdentifier(
553
- importer.useLocal(`${config.prefix}t${tuple.index}`),
554
- ),
555
- undefined,
556
- FeatureProgrammer.argumentsArray(config)({
557
- ...explore,
558
- source: "function",
559
- })(input),
560
- )
561
- : decode_tuple_inline(project)(config)(importer)(
562
- input,
563
- tuple,
564
- explore,
565
- );
566
-
567
- const decode_tuple_inline =
568
- (project: IProject) =>
569
- (config: FeatureProgrammer.IConfig) =>
570
- (importer: FunctionImporter) =>
571
- (
572
- input: ts.Expression,
573
- tuple: MetadataTuple,
574
- explore: FeatureProgrammer.IExplore,
575
- ): ts.Expression => {
576
- const children: ts.Expression[] = tuple.elements
577
- .filter((elem) => elem.rest === null)
578
- .map((elem, index) =>
579
- decode(project)(config)(importer)(
580
- ts.factory.createElementAccessExpression(input, index),
581
- elem,
582
- {
583
- ...explore,
584
- from: "array",
585
- postfix: explore.postfix.length
586
- ? `${explore.postfix.slice(0, -1)}[${index}]"`
587
- : `"[${index}]"`,
588
- },
589
- ),
590
- );
591
- const rest = (() => {
592
- if (tuple.elements.length === 0) return null;
593
- const last = tuple.elements.at(-1)!;
594
- if (last.rest === null) return null;
595
-
596
- const code = decode(project)(config)(importer)(
597
- ts.factory.createCallExpression(
598
- IdentifierFactory.access(input)("slice"),
599
- undefined,
600
- [
601
- ts.factory.createNumericLiteral(
602
- tuple.elements.length - 1,
603
- ),
604
- ],
605
- ),
606
- wrap_metadata_rest_tuple(tuple.elements.at(-1)!.rest!),
607
- {
608
- ...explore,
609
- start: tuple.elements.length - 1,
610
- },
611
- );
612
- return ts.factory.createCallExpression(
613
- importer.use("rest"),
614
- undefined,
615
- [code],
616
- );
617
- })();
618
- return StringifyJoiner.tuple(children, rest);
619
- };
620
-
621
- const decode_atomic =
622
- (project: IProject) =>
623
- (importer: FunctionImporter) =>
624
- (
625
- input: ts.Expression,
626
- type: string,
627
- explore: FeatureProgrammer.IExplore,
628
- ) => {
629
- if (type === "string")
630
- return ts.factory.createCallExpression(
631
- importer.use("string"),
632
- undefined,
633
- [input],
634
- );
635
- else if (
636
- type === "number" &&
637
- OptionPredicator.numeric(project.options)
638
- )
639
- input = ts.factory.createCallExpression(
640
- importer.use("number"),
641
- undefined,
642
- [input],
643
- );
644
-
645
- return explore.from !== "top"
646
- ? input
647
- : ts.factory.createCallExpression(
648
- IdentifierFactory.access(input)("toString"),
649
- undefined,
650
- undefined,
651
- );
652
- };
653
-
654
- const decode_constant_string =
655
- (project: IProject) =>
656
- (importer: FunctionImporter) =>
657
- (
658
- input: ts.Expression,
659
- values: string[],
660
- explore: FeatureProgrammer.IExplore,
661
- ): ts.Expression => {
662
- if (values.every((v) => !StringifyPredicator.require_escape(v)))
663
- return [
664
- ts.factory.createStringLiteral('"'),
665
- input,
666
- ts.factory.createStringLiteral('"'),
667
- ].reduce((x, y) => ts.factory.createAdd(x, y));
668
- else
669
- return decode_atomic(project)(importer)(
670
- input,
671
- "string",
672
- explore,
673
- );
674
- };
675
-
676
- const decode_to_json =
677
- (project: IProject) =>
678
- (config: FeatureProgrammer.IConfig) =>
679
- (importer: FunctionImporter) =>
680
- (
681
- input: ts.Expression,
682
- resolved: Metadata,
683
- explore: FeatureProgrammer.IExplore,
684
- ): ts.Expression => {
685
- return decode(project)(config)(importer)(
686
- ts.factory.createCallExpression(
687
- IdentifierFactory.access(input)("toJSON"),
688
- undefined,
689
- [],
690
- ),
691
- resolved,
692
- explore,
693
- );
694
- };
695
-
696
- const decode_functional = (explore: FeatureProgrammer.IExplore) =>
697
- explore.from === "array"
698
- ? ts.factory.createStringLiteral("null")
699
- : ts.factory.createIdentifier("undefined");
700
-
701
- /* -----------------------------------------------------------
702
- EXPLORERS
703
- ----------------------------------------------------------- */
704
- const explore_objects =
705
- (config: FeatureProgrammer.IConfig) =>
706
- (importer: FunctionImporter) =>
707
- (
708
- input: ts.Expression,
709
- meta: Metadata,
710
- explore: FeatureProgrammer.IExplore,
711
- ) =>
712
- meta.objects.length === 1
713
- ? decode_object(importer)(input, meta.objects[0]!, explore)
714
- : ts.factory.createCallExpression(
715
- ts.factory.createIdentifier(
716
- importer.useLocal(`${PREFIX}u${meta.union_index!}`),
717
- ),
718
- undefined,
719
- FeatureProgrammer.argumentsArray(config)(explore)(input),
720
- );
721
-
722
- const explore_arrays =
723
- (project: IProject) =>
724
- (config: FeatureProgrammer.IConfig) =>
725
- (importer: FunctionImporter) =>
726
- (
727
- input: ts.Expression,
728
- elements: MetadataArray[],
729
- explore: FeatureProgrammer.IExplore,
730
- ): ts.Expression =>
731
- explore_array_like_union_types(config)(importer)(
732
- UnionExplorer.array({
733
- checker: IsProgrammer.decode(project)(importer),
734
- decoder: decode_array(config)(importer),
735
- empty: ts.factory.createStringLiteral("[]"),
736
- success: ts.factory.createTrue(),
737
- failure: (input, expected) =>
738
- create_throw_error(importer)(expected)(input),
739
- }),
740
- )(input, elements, explore);
741
-
742
- const explore_array_like_union_types =
743
- (config: FeatureProgrammer.IConfig) =>
744
- (importer: FunctionImporter) =>
745
- <T extends MetadataArray | MetadataTuple>(
746
- factory: (
747
- parameters: ts.ParameterDeclaration[],
748
- ) => (
749
- input: ts.Expression,
750
- elements: T[],
751
- explore: FeatureProgrammer.IExplore,
752
- tags: IMetadataTag[],
753
- jsDocTags: IJsDocTagInfo[],
754
- ) => ts.ArrowFunction,
755
- ) =>
756
- (
757
- input: ts.Expression,
758
- elements: T[],
759
- explore: FeatureProgrammer.IExplore,
760
- ): ts.Expression => {
761
- const arrow =
762
- (parameters: ts.ParameterDeclaration[]) =>
763
- (explore: FeatureProgrammer.IExplore) =>
764
- (input: ts.Expression): ts.ArrowFunction =>
765
- factory(parameters)(input, elements, explore, [], []);
766
- if (elements.every((e) => e.recursive === false))
767
- ts.factory.createCallExpression(
768
- arrow([])(explore)(input),
769
- undefined,
770
- [],
771
- );
772
-
773
- explore = {
774
- ...explore,
775
- source: "function",
776
- from: "array",
777
- };
778
- return ts.factory.createCallExpression(
779
- ts.factory.createIdentifier(
780
- importer.emplaceUnion(
781
- config.prefix,
782
- elements.map((e) => e.name).join(" | "),
783
- () =>
784
- arrow(
785
- FeatureProgrammer.parameterDeclarations(config)(
786
- TypeFactory.keyword("any"),
787
- )(ts.factory.createIdentifier("input")),
788
- )({
789
- ...explore,
790
- postfix: "",
791
- })(ts.factory.createIdentifier("input")),
792
- ),
793
- ),
794
- undefined,
795
- FeatureProgrammer.argumentsArray(config)(explore)(input),
796
- );
797
- };
798
-
799
- /* -----------------------------------------------------------
800
- RETURN SCRIPTS
801
- ----------------------------------------------------------- */
802
- const wrap_required = (
803
- input: ts.Expression,
804
- meta: Metadata,
805
- explore: FeatureProgrammer.IExplore,
806
- ): ((expression: ts.Expression) => ts.Expression) => {
807
- if (meta.isRequired() === true && meta.any === false)
808
- return (expression) => expression;
809
- return (expression) =>
810
- ts.factory.createConditionalExpression(
811
- ts.factory.createStrictInequality(
812
- ts.factory.createIdentifier("undefined"),
813
- input,
814
- ),
815
- undefined,
816
- expression,
817
- undefined,
818
- explore.from === "array"
819
- ? ts.factory.createStringLiteral("null")
820
- : ts.factory.createIdentifier("undefined"),
821
- );
822
- };
823
-
824
- const wrap_nullable = (
825
- input: ts.Expression,
826
- meta: Metadata,
827
- ): ((expression: ts.Expression) => ts.Expression) => {
828
- if (meta.nullable === false) return (expression) => expression;
829
- return (expression) =>
830
- ts.factory.createConditionalExpression(
831
- ts.factory.createStrictInequality(
832
- ts.factory.createNull(),
833
- input,
834
- ),
835
- undefined,
836
- expression,
837
- undefined,
838
- ts.factory.createStringLiteral("null"),
839
- );
840
- };
841
-
842
- const wrap_functional = (
843
- input: ts.Expression,
844
- meta: Metadata,
845
- explore: FeatureProgrammer.IExplore,
846
- ): ((expression: ts.Expression) => ts.Expression) => {
847
- if (meta.functional === false) return (expression) => expression;
848
- return (expression) =>
849
- ts.factory.createConditionalExpression(
850
- ts.factory.createStrictInequality(
851
- ts.factory.createStringLiteral("function"),
852
- ValueFactory.TYPEOF(input),
853
- ),
854
- undefined,
855
- expression,
856
- undefined,
857
- decode_functional(explore),
858
- );
859
- };
860
-
861
- const iterate = (
862
- importer: FunctionImporter,
863
- input: ts.Expression,
864
- unions: IUnion[],
865
- expected: string,
866
- ) =>
867
- ts.factory.createBlock(
868
- [
869
- ...unions.map((u) =>
870
- ts.factory.createIfStatement(
871
- u.is(),
872
- ts.factory.createReturnStatement(u.value()),
873
- ),
874
- ),
875
- create_throw_error(importer)(expected)(input),
876
- ],
877
- true,
878
- );
879
-
880
- /* -----------------------------------------------------------
881
- CONFIGURATIONS
882
- ----------------------------------------------------------- */
883
- const PREFIX = "$s";
884
-
885
- const configure =
886
- (project: IProject) =>
887
- (importer: FunctionImporter): FeatureProgrammer.IConfig => {
888
- const config: FeatureProgrammer.IConfig = {
889
- types: {
890
- input: (type, name) =>
891
- ts.factory.createTypeReferenceNode(
892
- name ??
893
- TypeFactory.getFullName(project.checker)(type),
894
- ),
895
- output: () => TypeFactory.keyword("string"),
896
- },
897
- prefix: PREFIX,
898
- trace: false,
899
- path: false,
900
- initializer,
901
- decoder: () => decode(project)(config)(importer),
902
- objector: {
903
- checker: () => (input, meta, explore) =>
904
- IsProgrammer.decode(project)(importer)(
905
- input,
906
- meta,
907
- explore,
908
- [],
909
- [],
910
- ),
911
- decoder: () => decode_object(importer),
912
- joiner: StringifyJoiner.object(importer),
913
- unionizer: decode_union_object(
914
- IsProgrammer.decode_object(importer),
915
- )(decode_object(importer))((exp) => exp)(
916
- (value, expected) =>
917
- create_throw_error(importer)(expected)(value),
918
- ),
919
- failure: (input, expected) =>
920
- create_throw_error(importer)(expected)(input),
921
- },
922
- generator: {
923
- arrays: () => write_array_functions(config)(importer),
924
- tuples: () =>
925
- write_tuple_functions(project)(config)(importer),
926
- },
927
- };
928
- return config;
929
- };
930
-
931
- const initializer: FeatureProgrammer.IConfig["initializer"] =
932
- ({ checker }) =>
933
- (type) => {
934
- const collection: MetadataCollection = new MetadataCollection();
935
- const meta: Metadata = MetadataFactory.analyze(checker)({
936
- escape: true,
937
- constant: true,
938
- absorb: true,
939
- validate: (meta) => {
940
- if (meta.atomics.find((str) => str === "bigint"))
941
- throw new Error(NO_BIGINT);
942
- else if (
943
- meta.arrays.some(
944
- (array) => array.value.isRequired() === false,
945
- )
946
- )
947
- throw new Error(NO_UNDEFINED_IN_ARRAY);
948
- },
949
- })(collection)(type);
950
- return [collection, meta];
951
- };
952
-
953
- const create_throw_error =
954
- (importer: FunctionImporter) =>
955
- (expected: string) =>
956
- (value: ts.Expression) =>
957
- ts.factory.createExpressionStatement(
958
- ts.factory.createCallExpression(
959
- importer.use("throws"),
960
- [],
961
- [
962
- ts.factory.createObjectLiteralExpression(
963
- [
964
- ts.factory.createPropertyAssignment(
965
- "expected",
966
- ts.factory.createStringLiteral(expected),
967
- ),
968
- ts.factory.createPropertyAssignment(
969
- "value",
970
- value,
971
- ),
972
- ],
973
- true,
974
- ),
975
- ],
976
- ),
977
- );
978
- }
979
-
980
- interface IUnion {
981
- type: string;
982
- is: () => ts.Expression;
983
- value: () => ts.Expression;
984
- }
985
-
986
- const NO_BIGINT =
987
- "Error on typia.json.stringify(): does not allow bigint type.";
988
- const NO_UNDEFINED_IN_ARRAY =
989
- "Error on typia.json.stringify(): does not allow undefined type in array.";
1
+ import ts from "typescript";
2
+
3
+ import { ExpressionFactory } from "../../factories/ExpressionFactory";
4
+ import { IdentifierFactory } from "../../factories/IdentifierFactory";
5
+ import { MetadataCollection } from "../../factories/MetadataCollection";
6
+ import { MetadataFactory } from "../../factories/MetadataFactory";
7
+ import { StatementFactory } from "../../factories/StatementFactory";
8
+ import { TypeFactory } from "../../factories/TypeFactory";
9
+ import { ValueFactory } from "../../factories/ValueFactory";
10
+
11
+ import { IJsDocTagInfo } from "../../schemas/metadata/IJsDocTagInfo";
12
+ import { IMetadataTag } from "../../schemas/metadata/IMetadataTag";
13
+ import { Metadata } from "../../schemas/metadata/Metadata";
14
+ import { MetadataArray } from "../../schemas/metadata/MetadataArray";
15
+ import { MetadataObject } from "../../schemas/metadata/MetadataObject";
16
+ import { MetadataTuple } from "../../schemas/metadata/MetadataTuple";
17
+
18
+ import { IProject } from "../../transformers/IProject";
19
+
20
+ import { Atomic } from "../../typings/Atomic";
21
+
22
+ import { ArrayUtil } from "../../utils/ArrayUtil";
23
+
24
+ import { FeatureProgrammer } from "../FeatureProgrammer";
25
+ import { IsProgrammer } from "../IsProgrammer";
26
+ import { AtomicPredicator } from "../helpers/AtomicPredicator";
27
+ import { FunctionImporter } from "../helpers/FunctionImporeter";
28
+ import { IExpressionEntry } from "../helpers/IExpressionEntry";
29
+ import { OptionPredicator } from "../helpers/OptionPredicator";
30
+ import { StringifyJoiner } from "../helpers/StringifyJoinder";
31
+ import { StringifyPredicator } from "../helpers/StringifyPredicator";
32
+ import { UnionExplorer } from "../helpers/UnionExplorer";
33
+ import { check_native } from "../internal/check_native";
34
+ import { decode_union_object } from "../internal/decode_union_object";
35
+ import { feature_object_entries } from "../internal/feature_object_entries";
36
+ import { wrap_metadata_rest_tuple } from "../internal/wrap_metadata_rest_tuple";
37
+
38
+ export namespace JsonStringifyProgrammer {
39
+ /* -----------------------------------------------------------
40
+ WRITER
41
+ ----------------------------------------------------------- */
42
+
43
+ export const write =
44
+ (project: IProject) => (modulo: ts.LeftHandSideExpression) => {
45
+ const importer: FunctionImporter = new FunctionImporter(
46
+ modulo.getText(),
47
+ );
48
+ const config: FeatureProgrammer.IConfig =
49
+ configure(project)(importer);
50
+
51
+ return FeatureProgrammer.write(project)({
52
+ ...config,
53
+ addition: (collection) => [
54
+ ...IsProgrammer.write_function_statements(project)(
55
+ importer,
56
+ )(collection),
57
+ ...importer.declare(modulo),
58
+ ],
59
+ })(importer);
60
+ };
61
+
62
+ const write_array_functions =
63
+ (config: FeatureProgrammer.IConfig) =>
64
+ (importer: FunctionImporter) =>
65
+ (collection: MetadataCollection): ts.VariableStatement[] =>
66
+ collection
67
+ .arrays()
68
+ .filter((a) => a.recursive)
69
+ .map((array, i) =>
70
+ StatementFactory.constant(
71
+ `${config.prefix}a${i}`,
72
+ ts.factory.createArrowFunction(
73
+ undefined,
74
+ undefined,
75
+ FeatureProgrammer.parameterDeclarations(config)(
76
+ TypeFactory.keyword("any"),
77
+ )(ts.factory.createIdentifier("input")),
78
+ TypeFactory.keyword("any"),
79
+ undefined,
80
+ decode_array_inline(config)(importer)(
81
+ ts.factory.createIdentifier("input"),
82
+ array,
83
+ {
84
+ tracable: config.trace,
85
+ source: "function",
86
+ from: "array",
87
+ postfix: "",
88
+ },
89
+ ),
90
+ ),
91
+ ),
92
+ );
93
+
94
+ const write_tuple_functions =
95
+ (project: IProject) =>
96
+ (config: FeatureProgrammer.IConfig) =>
97
+ (importer: FunctionImporter) =>
98
+ (collection: MetadataCollection): ts.VariableStatement[] =>
99
+ collection
100
+ .tuples()
101
+ .filter((t) => t.recursive)
102
+ .map((tuple, i) =>
103
+ StatementFactory.constant(
104
+ `${config.prefix}t${i}`,
105
+ ts.factory.createArrowFunction(
106
+ undefined,
107
+ undefined,
108
+ FeatureProgrammer.parameterDeclarations(config)(
109
+ TypeFactory.keyword("any"),
110
+ )(ts.factory.createIdentifier("input")),
111
+ TypeFactory.keyword("any"),
112
+ undefined,
113
+ decode_tuple_inline(project)(config)(importer)(
114
+ ts.factory.createIdentifier("input"),
115
+ tuple,
116
+ {
117
+ tracable: config.trace,
118
+ source: "function",
119
+ from: "array",
120
+ postfix: "",
121
+ },
122
+ ),
123
+ ),
124
+ ),
125
+ );
126
+
127
+ /* -----------------------------------------------------------
128
+ DECODERS
129
+ ----------------------------------------------------------- */
130
+ const decode =
131
+ (project: IProject) =>
132
+ (config: FeatureProgrammer.IConfig) =>
133
+ (importer: FunctionImporter) =>
134
+ (
135
+ input: ts.Expression,
136
+ meta: Metadata,
137
+ explore: FeatureProgrammer.IExplore,
138
+ ): ts.Expression => {
139
+ // ANY TYPE
140
+ if (meta.any === true)
141
+ return wrap_required(
142
+ input,
143
+ meta,
144
+ explore,
145
+ )(
146
+ wrap_functional(
147
+ input,
148
+ meta,
149
+ explore,
150
+ )(
151
+ ts.factory.createCallExpression(
152
+ ts.factory.createIdentifier("JSON.stringify"),
153
+ undefined,
154
+ [input],
155
+ ),
156
+ ),
157
+ );
158
+
159
+ // ONLY NULL OR UNDEFINED
160
+ const size: number = meta.size();
161
+ if (
162
+ size === 0 &&
163
+ (meta.isRequired() === false || meta.nullable === true)
164
+ ) {
165
+ if (meta.isRequired() === false && meta.nullable === true)
166
+ return explore.from === "array"
167
+ ? ts.factory.createStringLiteral("null")
168
+ : ts.factory.createConditionalExpression(
169
+ ts.factory.createStrictEquality(
170
+ ts.factory.createNull(),
171
+ input,
172
+ ),
173
+ undefined,
174
+ ts.factory.createStringLiteral("null"),
175
+ undefined,
176
+ ts.factory.createIdentifier("undefined"),
177
+ );
178
+ else if (meta.isRequired() === false)
179
+ return explore.from === "array"
180
+ ? ts.factory.createStringLiteral("null")
181
+ : ts.factory.createIdentifier("undefined");
182
+ else return ts.factory.createStringLiteral("null");
183
+ }
184
+
185
+ //----
186
+ // LIST UP UNION TYPES
187
+ //----
188
+ const unions: IUnion[] = [];
189
+
190
+ // toJSON() METHOD
191
+ if (meta.escaped !== null)
192
+ unions.push({
193
+ type: "resolved",
194
+ is: () => IsProgrammer.decode_to_json(false)(input),
195
+ value: () =>
196
+ decode_to_json(project)(config)(importer)(
197
+ input,
198
+ meta.escaped!.returns,
199
+ explore,
200
+ ),
201
+ });
202
+ else if (meta.functional === true)
203
+ unions.push({
204
+ type: "functional",
205
+ is: () => IsProgrammer.decode_functional(input),
206
+ value: () => decode_functional(explore),
207
+ });
208
+
209
+ // TEMPLATES
210
+ if (
211
+ meta.templates.length ||
212
+ ArrayUtil.has(meta.constants, (c) => c.type === "string")
213
+ )
214
+ if (AtomicPredicator.template(meta)) {
215
+ const partial = Metadata.initialize();
216
+ partial.atomics.push({ type: "string", tags: [] }),
217
+ unions.push({
218
+ type: "template literal",
219
+ is: () =>
220
+ IsProgrammer.decode(project)(importer)(
221
+ input,
222
+ partial,
223
+ explore,
224
+ [],
225
+ [],
226
+ ),
227
+ value: () =>
228
+ decode_atomic(project)(importer)(
229
+ input,
230
+ "string",
231
+ explore,
232
+ ),
233
+ });
234
+ }
235
+
236
+ // CONSTANTS
237
+ for (const constant of meta.constants)
238
+ if (AtomicPredicator.constant(meta)(constant.type) === false)
239
+ continue;
240
+ else if (constant.type !== "string")
241
+ unions.push({
242
+ type: "atomic",
243
+ is: () =>
244
+ IsProgrammer.decode(project)(importer)(
245
+ input,
246
+ (() => {
247
+ const partial = Metadata.initialize();
248
+ partial.atomics.push({
249
+ type: constant.type,
250
+ tags: [],
251
+ });
252
+ return partial;
253
+ })(),
254
+ explore,
255
+ [],
256
+ [],
257
+ ),
258
+ value: () =>
259
+ decode_atomic(project)(importer)(
260
+ input,
261
+ constant.type,
262
+ explore,
263
+ ),
264
+ });
265
+ else if (meta.templates.length === 0)
266
+ unions.push({
267
+ type: "const string",
268
+ is: () =>
269
+ IsProgrammer.decode(project)(importer)(
270
+ input,
271
+ (() => {
272
+ const partial = Metadata.initialize();
273
+ partial.atomics.push({
274
+ type: "string",
275
+ tags: [],
276
+ });
277
+ return partial;
278
+ })(),
279
+ explore,
280
+ [],
281
+ [],
282
+ ),
283
+ value: () =>
284
+ decode_constant_string(project)(importer)(
285
+ input,
286
+ [...constant.values] as string[],
287
+ explore,
288
+ ),
289
+ });
290
+
291
+ /// ATOMICS
292
+ for (const a of meta.atomics)
293
+ if (AtomicPredicator.atomic(meta)(a.type))
294
+ unions.push({
295
+ type: "atomic",
296
+ is: () =>
297
+ IsProgrammer.decode(project)(importer)(
298
+ input,
299
+ (() => {
300
+ const partial = Metadata.initialize();
301
+ partial.atomics.push(a);
302
+ return partial;
303
+ })(),
304
+ explore,
305
+ [],
306
+ [],
307
+ ),
308
+ value: () =>
309
+ decode_atomic(project)(importer)(
310
+ input,
311
+ a.type,
312
+ explore,
313
+ ),
314
+ });
315
+
316
+ // TUPLES
317
+ for (const tuple of meta.tuples) {
318
+ for (const child of tuple.elements)
319
+ if (StringifyPredicator.undefindable(meta))
320
+ throw new Error(
321
+ `Error on typia.json.stringify(): tuple cannot contain undefined value - (${child.getName()}).`,
322
+ );
323
+ unions.push({
324
+ type: "tuple",
325
+ is: () =>
326
+ IsProgrammer.decode(project)(importer)(
327
+ input,
328
+ (() => {
329
+ const partial = Metadata.initialize();
330
+ partial.tuples.push(tuple);
331
+ return partial;
332
+ })(),
333
+ explore,
334
+ [],
335
+ [],
336
+ ),
337
+ value: () =>
338
+ decode_tuple(project)(config)(importer)(
339
+ input,
340
+ tuple,
341
+ explore,
342
+ ),
343
+ });
344
+ }
345
+
346
+ // ARRAYS
347
+ if (meta.arrays.length) {
348
+ for (const child of meta.arrays)
349
+ if (StringifyPredicator.undefindable(child.value))
350
+ throw new Error(
351
+ `Error on typia.json.stringify(): array cannot contain undefined value (${child.value.getName()}).`,
352
+ );
353
+ const value: () => ts.Expression =
354
+ meta.arrays.length === 1
355
+ ? () =>
356
+ decode_array(config)(importer)(
357
+ input,
358
+ meta.arrays[0]!,
359
+ {
360
+ ...explore,
361
+ from: "array",
362
+ },
363
+ )
364
+ : meta.arrays.some((elem) => elem.value.any)
365
+ ? () =>
366
+ ts.factory.createCallExpression(
367
+ ts.factory.createIdentifier("JSON.stringify"),
368
+ undefined,
369
+ [input],
370
+ )
371
+ : () =>
372
+ explore_arrays(project)(config)(importer)(
373
+ input,
374
+ meta.arrays,
375
+ {
376
+ ...explore,
377
+ from: "array",
378
+ },
379
+ );
380
+
381
+ unions.push({
382
+ type: "array",
383
+ is: () => ExpressionFactory.isArray(input),
384
+ value,
385
+ });
386
+ }
387
+
388
+ // BUILT-IN CLASSES
389
+ if (meta.natives.length)
390
+ for (const native of meta.natives)
391
+ unions.push({
392
+ type: "object",
393
+ is: () => check_native(native)(input),
394
+ value: () =>
395
+ AtomicPredicator.native(native)
396
+ ? decode_atomic(project)(importer)(
397
+ input,
398
+ native.toLowerCase() as Atomic.Literal,
399
+ explore,
400
+ )
401
+ : ts.factory.createStringLiteral("{}"),
402
+ });
403
+
404
+ // SETS
405
+ if (meta.sets.length)
406
+ unions.push({
407
+ type: "object",
408
+ is: () => ExpressionFactory.isInstanceOf("Set")(input),
409
+ value: () => ts.factory.createStringLiteral("{}"),
410
+ });
411
+
412
+ // MAPS
413
+ if (meta.maps.length)
414
+ unions.push({
415
+ type: "object",
416
+ is: () => ExpressionFactory.isInstanceOf("Map")(input),
417
+ value: () => ts.factory.createStringLiteral("{}"),
418
+ });
419
+
420
+ // OBJECTS
421
+ if (meta.objects.length)
422
+ unions.push({
423
+ type: "object",
424
+ is: () =>
425
+ ExpressionFactory.isObject({
426
+ checkNull: true,
427
+ checkArray: meta.objects.some((obj) =>
428
+ obj.properties.every(
429
+ (prop) =>
430
+ !prop.key.isSoleLiteral() ||
431
+ !prop.value.isRequired(),
432
+ ),
433
+ ),
434
+ })(input),
435
+ value: () =>
436
+ meta.isParentResolved() === false &&
437
+ meta.objects.length === 1 &&
438
+ meta.objects[0]!._Is_simple(
439
+ explore.from === "top" ? 0 : 1,
440
+ )
441
+ ? (() => {
442
+ const obj: MetadataObject = meta.objects[0]!;
443
+ const entries: IExpressionEntry<ts.Expression>[] =
444
+ feature_object_entries({
445
+ decoder: () =>
446
+ decode(project)(config)(importer),
447
+ trace: false,
448
+ path: false,
449
+ })(importer)(obj)(
450
+ ts.factory.createAsExpression(
451
+ input,
452
+ TypeFactory.keyword("any"),
453
+ ),
454
+ );
455
+ return StringifyJoiner.object(importer)(
456
+ ts.factory.createAsExpression(
457
+ input,
458
+ TypeFactory.keyword("any"),
459
+ ),
460
+ entries,
461
+ );
462
+ })()
463
+ : explore_objects(config)(importer)(input, meta, {
464
+ ...explore,
465
+ from: "object",
466
+ }),
467
+ });
468
+
469
+ //----
470
+ // RETURNS
471
+ //----
472
+ // CHECK NULL AND UNDEFINED
473
+ const wrapper = (output: ts.Expression) =>
474
+ wrap_required(
475
+ input,
476
+ meta,
477
+ explore,
478
+ )(wrap_nullable(input, meta)(output));
479
+
480
+ // DIRECT RETURN
481
+ if (unions.length === 0)
482
+ return ts.factory.createCallExpression(
483
+ ts.factory.createIdentifier("JSON.stringify"),
484
+ undefined,
485
+ [input],
486
+ );
487
+ else if (unions.length === 1) return wrapper(unions[0]!.value());
488
+
489
+ // RETURN WITH TYPE CHECKING
490
+ return wrapper(
491
+ ts.factory.createCallExpression(
492
+ ts.factory.createArrowFunction(
493
+ undefined,
494
+ undefined,
495
+ [],
496
+ undefined,
497
+ undefined,
498
+ iterate(importer, input, unions, meta.getName()),
499
+ ),
500
+ undefined,
501
+ undefined,
502
+ ),
503
+ );
504
+ };
505
+
506
+ const decode_object = (importer: FunctionImporter) =>
507
+ FeatureProgrammer.decode_object({
508
+ trace: false,
509
+ path: false,
510
+ prefix: PREFIX,
511
+ })(importer);
512
+
513
+ const decode_array =
514
+ (config: FeatureProgrammer.IConfig) =>
515
+ (importer: FunctionImporter) =>
516
+ (
517
+ input: ts.Expression,
518
+ array: MetadataArray,
519
+ explore: FeatureProgrammer.IExplore,
520
+ ) =>
521
+ array.recursive
522
+ ? ts.factory.createCallExpression(
523
+ ts.factory.createIdentifier(
524
+ importer.useLocal(`${config.prefix}a${array.index}`),
525
+ ),
526
+ undefined,
527
+ FeatureProgrammer.argumentsArray(config)({
528
+ ...explore,
529
+ source: "function",
530
+ from: "array",
531
+ })(input),
532
+ )
533
+ : decode_array_inline(config)(importer)(input, array, explore);
534
+
535
+ const decode_array_inline =
536
+ (config: FeatureProgrammer.IConfig) =>
537
+ (importer: FunctionImporter) =>
538
+ (
539
+ input: ts.Expression,
540
+ array: MetadataArray,
541
+ explore: FeatureProgrammer.IExplore,
542
+ ) =>
543
+ FeatureProgrammer.decode_array(config)(importer)(
544
+ StringifyJoiner.array,
545
+ )(input, array, explore, [], []);
546
+
547
+ const decode_tuple =
548
+ (project: IProject) =>
549
+ (config: FeatureProgrammer.IConfig) =>
550
+ (importer: FunctionImporter) =>
551
+ (
552
+ input: ts.Expression,
553
+ tuple: MetadataTuple,
554
+ explore: FeatureProgrammer.IExplore,
555
+ ): ts.Expression =>
556
+ tuple.recursive
557
+ ? ts.factory.createCallExpression(
558
+ ts.factory.createIdentifier(
559
+ importer.useLocal(`${config.prefix}t${tuple.index}`),
560
+ ),
561
+ undefined,
562
+ FeatureProgrammer.argumentsArray(config)({
563
+ ...explore,
564
+ source: "function",
565
+ })(input),
566
+ )
567
+ : decode_tuple_inline(project)(config)(importer)(
568
+ input,
569
+ tuple,
570
+ explore,
571
+ );
572
+
573
+ const decode_tuple_inline =
574
+ (project: IProject) =>
575
+ (config: FeatureProgrammer.IConfig) =>
576
+ (importer: FunctionImporter) =>
577
+ (
578
+ input: ts.Expression,
579
+ tuple: MetadataTuple,
580
+ explore: FeatureProgrammer.IExplore,
581
+ ): ts.Expression => {
582
+ const children: ts.Expression[] = tuple.elements
583
+ .filter((elem) => elem.rest === null)
584
+ .map((elem, index) =>
585
+ decode(project)(config)(importer)(
586
+ ts.factory.createElementAccessExpression(input, index),
587
+ elem,
588
+ {
589
+ ...explore,
590
+ from: "array",
591
+ postfix: explore.postfix.length
592
+ ? `${explore.postfix.slice(0, -1)}[${index}]"`
593
+ : `"[${index}]"`,
594
+ },
595
+ ),
596
+ );
597
+ const rest = (() => {
598
+ if (tuple.elements.length === 0) return null;
599
+ const last = tuple.elements.at(-1)!;
600
+ if (last.rest === null) return null;
601
+
602
+ const code = decode(project)(config)(importer)(
603
+ ts.factory.createCallExpression(
604
+ IdentifierFactory.access(input)("slice"),
605
+ undefined,
606
+ [
607
+ ts.factory.createNumericLiteral(
608
+ tuple.elements.length - 1,
609
+ ),
610
+ ],
611
+ ),
612
+ wrap_metadata_rest_tuple(tuple.elements.at(-1)!.rest!),
613
+ {
614
+ ...explore,
615
+ start: tuple.elements.length - 1,
616
+ },
617
+ );
618
+ return ts.factory.createCallExpression(
619
+ importer.use("rest"),
620
+ undefined,
621
+ [code],
622
+ );
623
+ })();
624
+ return StringifyJoiner.tuple(children, rest);
625
+ };
626
+
627
+ const decode_atomic =
628
+ (project: IProject) =>
629
+ (importer: FunctionImporter) =>
630
+ (
631
+ input: ts.Expression,
632
+ type: string,
633
+ explore: FeatureProgrammer.IExplore,
634
+ ) => {
635
+ if (type === "string")
636
+ return ts.factory.createCallExpression(
637
+ importer.use("string"),
638
+ undefined,
639
+ [input],
640
+ );
641
+ else if (
642
+ type === "number" &&
643
+ OptionPredicator.numeric(project.options)
644
+ )
645
+ input = ts.factory.createCallExpression(
646
+ importer.use("number"),
647
+ undefined,
648
+ [input],
649
+ );
650
+
651
+ return explore.from !== "top"
652
+ ? input
653
+ : ts.factory.createCallExpression(
654
+ IdentifierFactory.access(input)("toString"),
655
+ undefined,
656
+ undefined,
657
+ );
658
+ };
659
+
660
+ const decode_constant_string =
661
+ (project: IProject) =>
662
+ (importer: FunctionImporter) =>
663
+ (
664
+ input: ts.Expression,
665
+ values: string[],
666
+ explore: FeatureProgrammer.IExplore,
667
+ ): ts.Expression => {
668
+ if (values.every((v) => !StringifyPredicator.require_escape(v)))
669
+ return [
670
+ ts.factory.createStringLiteral('"'),
671
+ input,
672
+ ts.factory.createStringLiteral('"'),
673
+ ].reduce((x, y) => ts.factory.createAdd(x, y));
674
+ else
675
+ return decode_atomic(project)(importer)(
676
+ input,
677
+ "string",
678
+ explore,
679
+ );
680
+ };
681
+
682
+ const decode_to_json =
683
+ (project: IProject) =>
684
+ (config: FeatureProgrammer.IConfig) =>
685
+ (importer: FunctionImporter) =>
686
+ (
687
+ input: ts.Expression,
688
+ resolved: Metadata,
689
+ explore: FeatureProgrammer.IExplore,
690
+ ): ts.Expression => {
691
+ return decode(project)(config)(importer)(
692
+ ts.factory.createCallExpression(
693
+ IdentifierFactory.access(input)("toJSON"),
694
+ undefined,
695
+ [],
696
+ ),
697
+ resolved,
698
+ explore,
699
+ );
700
+ };
701
+
702
+ const decode_functional = (explore: FeatureProgrammer.IExplore) =>
703
+ explore.from === "array"
704
+ ? ts.factory.createStringLiteral("null")
705
+ : ts.factory.createIdentifier("undefined");
706
+
707
+ /* -----------------------------------------------------------
708
+ EXPLORERS
709
+ ----------------------------------------------------------- */
710
+ const explore_objects =
711
+ (config: FeatureProgrammer.IConfig) =>
712
+ (importer: FunctionImporter) =>
713
+ (
714
+ input: ts.Expression,
715
+ meta: Metadata,
716
+ explore: FeatureProgrammer.IExplore,
717
+ ) =>
718
+ meta.objects.length === 1
719
+ ? decode_object(importer)(input, meta.objects[0]!, explore)
720
+ : ts.factory.createCallExpression(
721
+ ts.factory.createIdentifier(
722
+ importer.useLocal(`${PREFIX}u${meta.union_index!}`),
723
+ ),
724
+ undefined,
725
+ FeatureProgrammer.argumentsArray(config)(explore)(input),
726
+ );
727
+
728
+ const explore_arrays =
729
+ (project: IProject) =>
730
+ (config: FeatureProgrammer.IConfig) =>
731
+ (importer: FunctionImporter) =>
732
+ (
733
+ input: ts.Expression,
734
+ elements: MetadataArray[],
735
+ explore: FeatureProgrammer.IExplore,
736
+ ): ts.Expression =>
737
+ explore_array_like_union_types(config)(importer)(
738
+ UnionExplorer.array({
739
+ checker: IsProgrammer.decode(project)(importer),
740
+ decoder: decode_array(config)(importer),
741
+ empty: ts.factory.createStringLiteral("[]"),
742
+ success: ts.factory.createTrue(),
743
+ failure: (input, expected) =>
744
+ create_throw_error(importer)(expected)(input),
745
+ }),
746
+ )(input, elements, explore);
747
+
748
+ const explore_array_like_union_types =
749
+ (config: FeatureProgrammer.IConfig) =>
750
+ (importer: FunctionImporter) =>
751
+ <T extends MetadataArray | MetadataTuple>(
752
+ factory: (
753
+ parameters: ts.ParameterDeclaration[],
754
+ ) => (
755
+ input: ts.Expression,
756
+ elements: T[],
757
+ explore: FeatureProgrammer.IExplore,
758
+ tags: IMetadataTag[],
759
+ jsDocTags: IJsDocTagInfo[],
760
+ ) => ts.ArrowFunction,
761
+ ) =>
762
+ (
763
+ input: ts.Expression,
764
+ elements: T[],
765
+ explore: FeatureProgrammer.IExplore,
766
+ ): ts.Expression => {
767
+ const arrow =
768
+ (parameters: ts.ParameterDeclaration[]) =>
769
+ (explore: FeatureProgrammer.IExplore) =>
770
+ (input: ts.Expression): ts.ArrowFunction =>
771
+ factory(parameters)(input, elements, explore, [], []);
772
+ if (elements.every((e) => e.recursive === false))
773
+ ts.factory.createCallExpression(
774
+ arrow([])(explore)(input),
775
+ undefined,
776
+ [],
777
+ );
778
+
779
+ explore = {
780
+ ...explore,
781
+ source: "function",
782
+ from: "array",
783
+ };
784
+ return ts.factory.createCallExpression(
785
+ ts.factory.createIdentifier(
786
+ importer.emplaceUnion(
787
+ config.prefix,
788
+ elements.map((e) => e.name).join(" | "),
789
+ () =>
790
+ arrow(
791
+ FeatureProgrammer.parameterDeclarations(config)(
792
+ TypeFactory.keyword("any"),
793
+ )(ts.factory.createIdentifier("input")),
794
+ )({
795
+ ...explore,
796
+ postfix: "",
797
+ })(ts.factory.createIdentifier("input")),
798
+ ),
799
+ ),
800
+ undefined,
801
+ FeatureProgrammer.argumentsArray(config)(explore)(input),
802
+ );
803
+ };
804
+
805
+ /* -----------------------------------------------------------
806
+ RETURN SCRIPTS
807
+ ----------------------------------------------------------- */
808
+ const wrap_required = (
809
+ input: ts.Expression,
810
+ meta: Metadata,
811
+ explore: FeatureProgrammer.IExplore,
812
+ ): ((expression: ts.Expression) => ts.Expression) => {
813
+ if (meta.isRequired() === true && meta.any === false)
814
+ return (expression) => expression;
815
+ return (expression) =>
816
+ ts.factory.createConditionalExpression(
817
+ ts.factory.createStrictInequality(
818
+ ts.factory.createIdentifier("undefined"),
819
+ input,
820
+ ),
821
+ undefined,
822
+ expression,
823
+ undefined,
824
+ explore.from === "array"
825
+ ? ts.factory.createStringLiteral("null")
826
+ : ts.factory.createIdentifier("undefined"),
827
+ );
828
+ };
829
+
830
+ const wrap_nullable = (
831
+ input: ts.Expression,
832
+ meta: Metadata,
833
+ ): ((expression: ts.Expression) => ts.Expression) => {
834
+ if (meta.nullable === false) return (expression) => expression;
835
+ return (expression) =>
836
+ ts.factory.createConditionalExpression(
837
+ ts.factory.createStrictInequality(
838
+ ts.factory.createNull(),
839
+ input,
840
+ ),
841
+ undefined,
842
+ expression,
843
+ undefined,
844
+ ts.factory.createStringLiteral("null"),
845
+ );
846
+ };
847
+
848
+ const wrap_functional = (
849
+ input: ts.Expression,
850
+ meta: Metadata,
851
+ explore: FeatureProgrammer.IExplore,
852
+ ): ((expression: ts.Expression) => ts.Expression) => {
853
+ if (meta.functional === false) return (expression) => expression;
854
+ return (expression) =>
855
+ ts.factory.createConditionalExpression(
856
+ ts.factory.createStrictInequality(
857
+ ts.factory.createStringLiteral("function"),
858
+ ValueFactory.TYPEOF(input),
859
+ ),
860
+ undefined,
861
+ expression,
862
+ undefined,
863
+ decode_functional(explore),
864
+ );
865
+ };
866
+
867
+ const iterate = (
868
+ importer: FunctionImporter,
869
+ input: ts.Expression,
870
+ unions: IUnion[],
871
+ expected: string,
872
+ ) =>
873
+ ts.factory.createBlock(
874
+ [
875
+ ...unions.map((u) =>
876
+ ts.factory.createIfStatement(
877
+ u.is(),
878
+ ts.factory.createReturnStatement(u.value()),
879
+ ),
880
+ ),
881
+ create_throw_error(importer)(expected)(input),
882
+ ],
883
+ true,
884
+ );
885
+
886
+ /* -----------------------------------------------------------
887
+ CONFIGURATIONS
888
+ ----------------------------------------------------------- */
889
+ const PREFIX = "$s";
890
+
891
+ const configure =
892
+ (project: IProject) =>
893
+ (importer: FunctionImporter): FeatureProgrammer.IConfig => {
894
+ const config: FeatureProgrammer.IConfig = {
895
+ types: {
896
+ input: (type, name) =>
897
+ ts.factory.createTypeReferenceNode(
898
+ name ??
899
+ TypeFactory.getFullName(project.checker)(type),
900
+ ),
901
+ output: () => TypeFactory.keyword("string"),
902
+ },
903
+ prefix: PREFIX,
904
+ trace: false,
905
+ path: false,
906
+ initializer,
907
+ decoder: () => decode(project)(config)(importer),
908
+ objector: {
909
+ checker: () => (input, meta, explore) =>
910
+ IsProgrammer.decode(project)(importer)(
911
+ input,
912
+ meta,
913
+ explore,
914
+ [],
915
+ [],
916
+ ),
917
+ decoder: () => decode_object(importer),
918
+ joiner: StringifyJoiner.object(importer),
919
+ unionizer: decode_union_object(
920
+ IsProgrammer.decode_object(importer),
921
+ )(decode_object(importer))((exp) => exp)(
922
+ (value, expected) =>
923
+ create_throw_error(importer)(expected)(value),
924
+ ),
925
+ failure: (input, expected) =>
926
+ create_throw_error(importer)(expected)(input),
927
+ },
928
+ generator: {
929
+ arrays: () => write_array_functions(config)(importer),
930
+ tuples: () =>
931
+ write_tuple_functions(project)(config)(importer),
932
+ },
933
+ };
934
+ return config;
935
+ };
936
+
937
+ const initializer: FeatureProgrammer.IConfig["initializer"] =
938
+ ({ checker }) =>
939
+ (type) => {
940
+ const collection: MetadataCollection = new MetadataCollection();
941
+ const meta: Metadata = MetadataFactory.analyze(checker)({
942
+ escape: true,
943
+ constant: true,
944
+ absorb: true,
945
+ validate: (meta) => {
946
+ if (meta.atomics.find((a) => a.type === "bigint"))
947
+ throw new Error(NO_BIGINT);
948
+ else if (
949
+ meta.arrays.some(
950
+ (array) => array.value.isRequired() === false,
951
+ )
952
+ )
953
+ throw new Error(NO_UNDEFINED_IN_ARRAY);
954
+ },
955
+ })(collection)(type);
956
+ return [collection, meta];
957
+ };
958
+
959
+ const create_throw_error =
960
+ (importer: FunctionImporter) =>
961
+ (expected: string) =>
962
+ (value: ts.Expression) =>
963
+ ts.factory.createExpressionStatement(
964
+ ts.factory.createCallExpression(
965
+ importer.use("throws"),
966
+ [],
967
+ [
968
+ ts.factory.createObjectLiteralExpression(
969
+ [
970
+ ts.factory.createPropertyAssignment(
971
+ "expected",
972
+ ts.factory.createStringLiteral(expected),
973
+ ),
974
+ ts.factory.createPropertyAssignment(
975
+ "value",
976
+ value,
977
+ ),
978
+ ],
979
+ true,
980
+ ),
981
+ ],
982
+ ),
983
+ );
984
+ }
985
+
986
+ interface IUnion {
987
+ type: string;
988
+ is: () => ts.Expression;
989
+ value: () => ts.Expression;
990
+ }
991
+
992
+ const NO_BIGINT =
993
+ "Error on typia.json.stringify(): does not allow bigint type.";
994
+ const NO_UNDEFINED_IN_ARRAY =
995
+ "Error on typia.json.stringify(): does not allow undefined type in array.";