typia 3.4.26 → 3.4.28

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 (30) hide show
  1. package/lib/factories/internal/metadata/iterate_metadata_native.js +0 -3
  2. package/lib/factories/internal/metadata/iterate_metadata_native.js.map +1 -1
  3. package/lib/programmers/AssertProgrammer.js +71 -79
  4. package/lib/programmers/AssertProgrammer.js.map +1 -1
  5. package/lib/programmers/CheckerProgrammer.js +21 -16
  6. package/lib/programmers/CheckerProgrammer.js.map +1 -1
  7. package/lib/programmers/StringifyProgrammer.js +24 -17
  8. package/lib/programmers/StringifyProgrammer.js.map +1 -1
  9. package/lib/programmers/ValidateProgrammer.js +60 -68
  10. package/lib/programmers/ValidateProgrammer.js.map +1 -1
  11. package/lib/programmers/helpers/AtomicPredicator.d.ts +2 -0
  12. package/lib/programmers/helpers/AtomicPredicator.js +9 -1
  13. package/lib/programmers/helpers/AtomicPredicator.js.map +1 -1
  14. package/lib/programmers/internal/application_schema.js +18 -7
  15. package/lib/programmers/internal/application_schema.js.map +1 -1
  16. package/lib/programmers/internal/check_dynamic_properties.js.map +1 -1
  17. package/lib/programmers/internal/check_native.js +9 -1
  18. package/lib/programmers/internal/check_native.js.map +1 -1
  19. package/lib/transformers/ITransformOptions.d.ts +4 -0
  20. package/package.json +3 -2
  21. package/src/factories/internal/metadata/iterate_metadata_native.ts +0 -5
  22. package/src/programmers/AssertProgrammer.ts +30 -36
  23. package/src/programmers/CheckerProgrammer.ts +16 -11
  24. package/src/programmers/StringifyProgrammer.ts +40 -27
  25. package/src/programmers/ValidateProgrammer.ts +30 -36
  26. package/src/programmers/helpers/AtomicPredicator.ts +17 -1
  27. package/src/programmers/internal/application_schema.ts +30 -20
  28. package/src/programmers/internal/check_dynamic_properties.ts +1 -0
  29. package/src/programmers/internal/check_native.ts +14 -2
  30. package/src/transformers/ITransformOptions.ts +4 -0
@@ -12,6 +12,8 @@ import { MetadataObject } from "../metadata/MetadataObject";
12
12
 
13
13
  import { IProject } from "../transformers/IProject";
14
14
 
15
+ import { Atomic } from "../typings/Atomic";
16
+
15
17
  import { ArrayUtil } from "../utils/ArrayUtil";
16
18
 
17
19
  import { FeatureProgrammer } from "./FeatureProgrammer";
@@ -23,6 +25,7 @@ import { OptionPredicator } from "./helpers/OptionPredicator";
23
25
  import { StringifyJoiner } from "./helpers/StringifyJoinder";
24
26
  import { StringifyPredicator } from "./helpers/StringifyPredicator";
25
27
  import { UnionExplorer } from "./helpers/UnionExplorer";
28
+ import { check_native } from "./internal/check_native";
26
29
  import { decode_union_object } from "./internal/decode_union_object";
27
30
  import { feature_object_entries } from "./internal/feature_object_entries";
28
31
 
@@ -177,10 +180,9 @@ export namespace StringifyProgrammer {
177
180
 
178
181
  // CONSTANTS
179
182
  for (const constant of meta.constants)
180
- if (
181
- constant.type !== "string" &&
182
- AtomicPredicator.constant(meta)(constant.type)
183
- )
183
+ if (AtomicPredicator.constant(meta)(constant.type) === false)
184
+ continue;
185
+ else if (constant.type !== "string")
184
186
  unions.push({
185
187
  type: "atomic",
186
188
  is: () =>
@@ -223,28 +225,31 @@ export namespace StringifyProgrammer {
223
225
  explore,
224
226
  ),
225
227
  });
228
+
229
+ /// ATOMICS
226
230
  for (const type of meta.atomics)
227
- unions.push({
228
- type: "atomic",
229
- is: () =>
230
- IsProgrammer.decode(project, importer)(
231
- input,
232
- (() => {
233
- const partial = Metadata.initialize();
234
- partial.atomics.push(type);
235
- return partial;
236
- })(),
237
- explore,
238
- [],
239
- ),
240
- value: () =>
241
- decode_atomic(project, importer)(
242
- input,
243
- type,
244
- explore,
245
- tags,
246
- ),
247
- });
231
+ if (AtomicPredicator.atomic(meta)(type))
232
+ unions.push({
233
+ type: "atomic",
234
+ is: () =>
235
+ IsProgrammer.decode(project, importer)(
236
+ input,
237
+ (() => {
238
+ const partial = Metadata.initialize();
239
+ partial.atomics.push(type);
240
+ return partial;
241
+ })(),
242
+ explore,
243
+ [],
244
+ ),
245
+ value: () =>
246
+ decode_atomic(project, importer)(
247
+ input,
248
+ type,
249
+ explore,
250
+ tags,
251
+ ),
252
+ });
248
253
 
249
254
  // TUPLES
250
255
  for (const tuple of meta.tuples) {
@@ -315,8 +320,16 @@ export namespace StringifyProgrammer {
315
320
  for (const native of meta.natives)
316
321
  unions.push({
317
322
  type: "object",
318
- is: () => ExpressionFactory.isInstanceOf(input, native),
319
- value: () => ts.factory.createStringLiteral("{}"),
323
+ is: () => check_native(native)(input),
324
+ value: () =>
325
+ AtomicPredicator.native(native)
326
+ ? decode_atomic(project, importer)(
327
+ input,
328
+ native.toLowerCase() as Atomic.Literal,
329
+ explore,
330
+ tags,
331
+ )
332
+ : ts.factory.createStringLiteral("{}"),
320
333
  });
321
334
 
322
335
  // SETS
@@ -4,7 +4,6 @@ import { IdentifierFactory } from "../factories/IdentifierFactory";
4
4
  import { StatementFactory } from "../factories/StatementFactory";
5
5
 
6
6
  import { IProject } from "../transformers/IProject";
7
- import { ITransformOptions } from "../transformers/ITransformOptions";
8
7
 
9
8
  import { CheckerProgrammer } from "./CheckerProgrammer";
10
9
  import { IsProgrammer } from "./IsProgrammer";
@@ -31,8 +30,8 @@ export namespace ValidateProgrammer {
31
30
  trace: true,
32
31
  numeric: OptionPredicator.numeric(project.options),
33
32
  equals,
34
- combiner: combine(project.options)(equals)(importer),
35
- joiner: joiner(project.options)(equals)(importer),
33
+ combiner: combine(equals)(importer),
34
+ joiner: joiner(equals)(importer),
36
35
  success: ts.factory.createTrue(),
37
36
  },
38
37
  importer,
@@ -86,13 +85,12 @@ export namespace ValidateProgrammer {
86
85
  }
87
86
 
88
87
  const combine =
89
- (options: ITransformOptions) =>
90
88
  (equals: boolean) =>
91
89
  (importer: FunctionImporter): CheckerProgrammer.IConfig.Combiner =>
92
90
  (explore: CheckerProgrammer.IExplore) => {
93
91
  if (explore.tracable === false)
94
92
  return IsProgrammer.CONFIG({
95
- object: validate_object(options)(equals)(importer),
93
+ object: validate_object(equals)(importer),
96
94
  numeric: true,
97
95
  })(importer).combiner(explore);
98
96
 
@@ -133,44 +131,40 @@ const combine =
133
131
  );
134
132
  };
135
133
 
136
- const validate_object =
137
- (options: ITransformOptions) =>
138
- (equals: boolean) =>
139
- (importer: FunctionImporter) =>
140
- check_object({
141
- equals,
142
- undefined: OptionPredicator.undefined(options),
143
- assert: false,
144
- reduce: ts.factory.createLogicalAnd,
145
- positive: ts.factory.createTrue(),
146
- superfluous: (value) =>
147
- create_report_call()(
148
- ts.factory.createAdd(
149
- ts.factory.createIdentifier("path"),
150
- ts.factory.createCallExpression(
151
- importer.use("join"),
152
- undefined,
153
- [ts.factory.createIdentifier("key")],
154
- ),
134
+ const validate_object = (equals: boolean) => (importer: FunctionImporter) =>
135
+ check_object({
136
+ equals,
137
+ undefined: true,
138
+ assert: false,
139
+ reduce: ts.factory.createLogicalAnd,
140
+ positive: ts.factory.createTrue(),
141
+ superfluous: (value) =>
142
+ create_report_call()(
143
+ ts.factory.createAdd(
144
+ ts.factory.createIdentifier("path"),
145
+ ts.factory.createCallExpression(
146
+ importer.use("join"),
147
+ undefined,
148
+ [ts.factory.createIdentifier("key")],
155
149
  ),
156
- "undefined",
157
- value,
158
150
  ),
159
- halt: (expr) =>
160
- ts.factory.createLogicalOr(
161
- ts.factory.createStrictEquality(
162
- ts.factory.createFalse(),
163
- ts.factory.createIdentifier("exceptionable"),
164
- ),
165
- expr,
151
+ "undefined",
152
+ value,
153
+ ),
154
+ halt: (expr) =>
155
+ ts.factory.createLogicalOr(
156
+ ts.factory.createStrictEquality(
157
+ ts.factory.createFalse(),
158
+ ts.factory.createIdentifier("exceptionable"),
166
159
  ),
167
- })(importer);
160
+ expr,
161
+ ),
162
+ })(importer);
168
163
 
169
164
  const joiner =
170
- (options: ITransformOptions) =>
171
165
  (equals: boolean) =>
172
166
  (importer: FunctionImporter): CheckerProgrammer.IConfig.IJoiner => ({
173
- object: validate_object(options)(equals)(importer),
167
+ object: validate_object(equals)(importer),
174
168
  array: (input, arrow) =>
175
169
  check_everything(
176
170
  ts.factory.createCallExpression(
@@ -8,8 +8,24 @@ export namespace AtomicPredicator {
8
8
  export const constant =
9
9
  (meta: Metadata) =>
10
10
  (name: Atomic.Literal): boolean =>
11
- !ArrayUtil.has(meta.atomics, (atomic) => atomic === name);
11
+ !ArrayUtil.has(meta.atomics, (atomic) => atomic === name) &&
12
+ !ArrayUtil.has(
13
+ meta.natives,
14
+ (native) => native.toLowerCase() === name,
15
+ );
16
+
17
+ export const atomic =
18
+ (meta: Metadata) =>
19
+ (name: Atomic.Literal): boolean =>
20
+ !ArrayUtil.has(
21
+ meta.natives,
22
+ (native) => native.toLowerCase() === name,
23
+ );
24
+
25
+ export const native = (name: string) => LIKE.has(name.toLowerCase());
12
26
 
13
27
  export const template = (meta: Metadata): boolean =>
14
28
  !ArrayUtil.has(meta.atomics, (type) => type === "string");
15
29
  }
30
+
31
+ const LIKE = new Set(["boolean", "number", "string"]);
@@ -46,27 +46,28 @@ export const application_schema =
46
46
  // ATOMIC TYPES
47
47
  if (meta.templates.length && AtomicPredicator.template(meta))
48
48
  union.push(application_templates(meta, attribute));
49
- for (const constant of meta.constants) {
49
+ for (const constant of meta.constants)
50
50
  if (constant.type === "bigint") throw new Error(NO_BIGINT);
51
51
  else if (
52
52
  (constant.type === "string" && meta.templates.length) ||
53
53
  AtomicPredicator.constant(meta)(constant.type) === false
54
54
  )
55
55
  continue;
56
- union.push(
57
- application_constant(constant, meta.nullable, attribute),
58
- );
59
- }
60
- for (const type of meta.atomics) {
56
+ else
57
+ union.push(
58
+ application_constant(constant, meta.nullable, attribute),
59
+ );
60
+ for (const type of meta.atomics)
61
61
  if (type === "bigint") throw new Error(NO_BIGINT);
62
- union.push(
63
- type === "string"
64
- ? application_string(meta, attribute)
65
- : type === "boolean"
66
- ? application_boolean(meta.nullable, attribute)
67
- : application_number(meta.nullable, attribute),
68
- );
69
- }
62
+ else if (AtomicPredicator.atomic(meta)(type) === false) continue;
63
+ else
64
+ union.push(
65
+ type === "string"
66
+ ? application_string(meta, attribute)
67
+ : type === "boolean"
68
+ ? application_boolean(meta.nullable, attribute)
69
+ : application_number(meta.nullable, attribute),
70
+ );
70
71
 
71
72
  // ARRAY
72
73
  for (const schema of meta.arrays.values())
@@ -109,12 +110,21 @@ export const application_schema =
109
110
 
110
111
  // NATIVES
111
112
  for (const native of meta.natives)
112
- union.push(
113
- application_native(options)(components)(native)(
114
- meta.nullable,
115
- attribute,
116
- ),
117
- );
113
+ if (AtomicPredicator.native(native))
114
+ union.push(
115
+ native === "String"
116
+ ? application_string(meta, attribute)
117
+ : native === "Boolean"
118
+ ? application_boolean(meta.nullable, attribute)
119
+ : application_number(meta.nullable, attribute),
120
+ );
121
+ else
122
+ union.push(
123
+ application_native(options)(components)(native)(
124
+ meta.nullable,
125
+ attribute,
126
+ ),
127
+ );
118
128
  if (meta.sets.length)
119
129
  union.push(
120
130
  application_native(options)(components)(`Set`)(
@@ -128,6 +128,7 @@ const check_dynamic_property =
128
128
  ),
129
129
  props.positive,
130
130
  );
131
+
131
132
  for (const entry of dynamic)
132
133
  add(
133
134
  ts.factory.createCallExpression(
@@ -5,5 +5,17 @@ import { ExpressionFactory } from "../../factories/ExpressionFactory";
5
5
  /**
6
6
  * @internal
7
7
  */
8
- export const check_native = (type: string) => (input: ts.Expression) =>
9
- ExpressionFactory.isInstanceOf(input, type);
8
+ export const check_native = (type: string) => (input: ts.Expression) => {
9
+ const instanceOf = ExpressionFactory.isInstanceOf(input, type);
10
+ return ATOMIC_LIKE.has(type)
11
+ ? ts.factory.createLogicalOr(
12
+ ts.factory.createStrictEquality(
13
+ ts.factory.createStringLiteral(type.toLowerCase()),
14
+ ts.factory.createTypeOfExpression(input),
15
+ ),
16
+ instanceOf,
17
+ )
18
+ : instanceOf;
19
+ };
20
+
21
+ const ATOMIC_LIKE = new Set(["Boolean", "Number", "String"]);
@@ -52,6 +52,10 @@ export interface ITransformOptions {
52
52
  * issue when validating without allowing superfluous properties. Should undefined
53
53
  * value assigned superfluous property be allowed or not?
54
54
  *
55
+ * Note that, this option only works on {@link equals} function. Other function
56
+ * like {@link assertEquals} or {@link validateEquals} would ignore this option
57
+ * value and always allow the `undefined` value.
58
+ *
55
59
  * @default true
56
60
  */
57
61
  undefined?: boolean;