typia 5.1.2-dev.20230927 → 5.1.3-dev.20230927

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 (56) hide show
  1. package/lib/factories/MetadataTypeTagFactory.d.ts +2 -2
  2. package/lib/factories/MetadataTypeTagFactory.js +19 -11
  3. package/lib/factories/MetadataTypeTagFactory.js.map +1 -1
  4. package/lib/factories/internal/metadata/emend_metadata_atomics.js +4 -2
  5. package/lib/factories/internal/metadata/emend_metadata_atomics.js.map +1 -1
  6. package/lib/factories/internal/metadata/iterate_metadata_intersection.js +70 -22
  7. package/lib/factories/internal/metadata/iterate_metadata_intersection.js.map +1 -1
  8. package/lib/programmers/internal/application_boolean.js +12 -1
  9. package/lib/programmers/internal/application_boolean.js.map +1 -1
  10. package/lib/programmers/internal/application_number.js +5 -2
  11. package/lib/programmers/internal/application_number.js.map +1 -1
  12. package/lib/programmers/internal/application_schema.js +7 -6
  13. package/lib/programmers/internal/application_schema.js.map +1 -1
  14. package/lib/programmers/internal/application_string.js +4 -1
  15. package/lib/programmers/internal/application_string.js.map +1 -1
  16. package/lib/programmers/internal/check_array_length.js +4 -1
  17. package/lib/programmers/internal/check_array_length.js.map +1 -1
  18. package/lib/programmers/internal/check_bigint.js +4 -1
  19. package/lib/programmers/internal/check_bigint.js.map +1 -1
  20. package/lib/programmers/internal/check_number.js +4 -1
  21. package/lib/programmers/internal/check_number.js.map +1 -1
  22. package/lib/programmers/internal/check_string.js +4 -1
  23. package/lib/programmers/internal/check_string.js.map +1 -1
  24. package/lib/schemas/json/IJsonSchema.d.ts +1 -0
  25. package/lib/schemas/metadata/IMetadataTypeTag.d.ts +2 -2
  26. package/lib/schemas/metadata/Metadata.js.map +1 -1
  27. package/lib/tags/Default.d.ts +7 -0
  28. package/lib/tags/Default.js +3 -0
  29. package/lib/tags/Default.js.map +1 -0
  30. package/lib/tags/Format.d.ts +1 -1
  31. package/lib/tags/Pattern.d.ts +1 -0
  32. package/lib/tags/TagBase.d.ts +2 -2
  33. package/lib/tags/index.d.ts +1 -0
  34. package/lib/tags/index.js +1 -0
  35. package/lib/tags/index.js.map +1 -1
  36. package/package.json +1 -1
  37. package/src/factories/MetadataTypeTagFactory.ts +24 -12
  38. package/src/factories/internal/metadata/emend_metadata_atomics.ts +3 -2
  39. package/src/factories/internal/metadata/iterate_metadata_intersection.ts +79 -17
  40. package/src/programmers/internal/application_boolean.ts +24 -9
  41. package/src/programmers/internal/application_number.ts +3 -1
  42. package/src/programmers/internal/application_schema.ts +11 -6
  43. package/src/programmers/internal/application_string.ts +4 -1
  44. package/src/programmers/internal/check_array_length.ts +11 -8
  45. package/src/programmers/internal/check_bigint.ts +11 -8
  46. package/src/programmers/internal/check_number.ts +43 -40
  47. package/src/programmers/internal/check_string.ts +11 -8
  48. package/src/schemas/json/IJsonSchema.ts +3 -1
  49. package/src/schemas/metadata/IMetadataConstant.ts +9 -0
  50. package/src/schemas/metadata/IMetadataTypeTag.ts +2 -2
  51. package/src/schemas/metadata/Metadata.ts +1 -0
  52. package/src/tags/Default.ts +15 -0
  53. package/src/tags/Format.ts +1 -1
  54. package/src/tags/Pattern.ts +1 -0
  55. package/src/tags/TagBase.ts +2 -2
  56. package/src/tags/index.ts +1 -0
@@ -80,13 +80,11 @@ export const application_schema =
80
80
  for (const a of meta.atomics)
81
81
  if (a.type === "bigint") throw new TypeError(NO_BIGINT);
82
82
  else if (a.type === "boolean")
83
- insert(application_boolean(attribute));
83
+ application_boolean(a)(attribute).forEach(insert);
84
84
  else if (a.type === "number")
85
- application_number(a)(attribute).forEach((s) => insert(s));
85
+ application_number(a)(attribute).forEach(insert);
86
86
  else if (a.type === "string")
87
- application_string(meta)(a)(attribute).forEach((s) =>
88
- insert(s),
89
- );
87
+ application_string(meta)(a)(attribute).forEach(insert);
90
88
 
91
89
  // ARRAY
92
90
  for (const array of meta.arrays)
@@ -105,7 +103,14 @@ export const application_schema =
105
103
  if (meta.atomics.some((a) => a.type === type)) continue;
106
104
  else if (type === "bigint") throw new TypeError(NO_BIGINT);
107
105
  else if (type === "boolean")
108
- insert(application_boolean(attribute));
106
+ insert(
107
+ application_boolean(
108
+ MetadataAtomic.create({
109
+ type: "boolean",
110
+ tags: [],
111
+ }),
112
+ )(attribute)[0]!,
113
+ );
109
114
  else if (type === "number")
110
115
  insert(
111
116
  application_number(
@@ -18,7 +18,8 @@ export const application_string =
18
18
  type: "string",
19
19
  };
20
20
  const out = (schema: IJsonSchema.IString) => {
21
- schema.default = application_default_string(meta)(attribute)(base);
21
+ schema.default ??=
22
+ application_default_string(meta)(attribute)(base);
22
23
  return schema;
23
24
  };
24
25
  if (atomic.tags.length === 0) return [out(base)];
@@ -46,6 +47,8 @@ const application_string_tags =
46
47
  else if (tag.kind === "format" && typeof tag.value === "string")
47
48
  base.format = tag.value;
48
49
  else if (tag.kind === "pattern") base.pattern = tag.value;
50
+ else if (tag.kind === "default" && typeof tag.value === "string")
51
+ base.default = tag.value;
49
52
  base["x-typia-typeTags"] = row;
50
53
  return base;
51
54
  };
@@ -31,11 +31,14 @@ const check_string_type_tags =
31
31
  (project: IProject) =>
32
32
  (matrix: IMetadataTypeTag[][]) =>
33
33
  (input: ts.Expression): ICheckEntry.ICondition[][] =>
34
- matrix.map((row) =>
35
- row.map((tag) => ({
36
- expected: `Array<> & ${tag.name}`,
37
- expression: ExpressionFactory.transpile(project.context)(
38
- tag.validate,
39
- )(input),
40
- })),
41
- );
34
+ matrix
35
+ .map((row) => row.filter((tag) => !!tag.validate))
36
+ .filter((row) => !!row.length)
37
+ .map((row) =>
38
+ row.map((tag) => ({
39
+ expected: `Array<> & ${tag.name}`,
40
+ expression: ExpressionFactory.transpile(project.context)(
41
+ tag.validate!,
42
+ )(input),
43
+ })),
44
+ );
@@ -35,11 +35,14 @@ const check_bigint_type_tags =
35
35
  (project: IProject) =>
36
36
  (atomic: MetadataAtomic) =>
37
37
  (input: ts.Expression): ICheckEntry.ICondition[][] =>
38
- atomic.tags.map((row) =>
39
- row.map((tag) => ({
40
- expected: `bigint & ${tag.name}`,
41
- expression: ExpressionFactory.transpile(project.context)(
42
- tag.validate,
43
- )(input),
44
- })),
45
- );
38
+ atomic.tags
39
+ .map((row) => row.filter((tag) => !!tag.validate))
40
+ .filter((row) => !!row.length)
41
+ .map((row) =>
42
+ row.map((tag) => ({
43
+ expected: `bigint & ${tag.name}`,
44
+ expression: ExpressionFactory.transpile(project.context)(
45
+ tag.validate!,
46
+ )(input),
47
+ })),
48
+ );
@@ -60,46 +60,49 @@ const check_numeric_type_tags =
60
60
  (atomic: MetadataAtomic) =>
61
61
  (addition: ts.Expression | null) =>
62
62
  (input: ts.Expression): ICheckEntry.ICondition[][] =>
63
- atomic.tags.map((row) => [
64
- ...(addition === null
65
- ? []
66
- : row.some(
67
- (tag) =>
68
- tag.kind === "type" &&
69
- (tag.value === "int32" ||
70
- tag.value === "uint32" ||
71
- tag.value === "int64" ||
72
- tag.value === "uint64" ||
73
- tag.value === "float"),
74
- ) ||
75
- row.some(
76
- (tag) =>
77
- tag.kind === "multipleOf" &&
78
- typeof tag.value === "number",
79
- ) ||
80
- (row.some(
81
- (tag) =>
82
- (tag.kind === "minimum" ||
83
- tag.kind === "exclusiveMinimum") &&
84
- typeof tag.value === "number",
85
- ) &&
63
+ atomic.tags
64
+ .map((row) => row.filter((tag) => !!tag.validate))
65
+ .filter((row) => !!row.length)
66
+ .map((row) => [
67
+ ...(addition === null
68
+ ? []
69
+ : row.some(
70
+ (tag) =>
71
+ tag.kind === "type" &&
72
+ (tag.value === "int32" ||
73
+ tag.value === "uint32" ||
74
+ tag.value === "int64" ||
75
+ tag.value === "uint64" ||
76
+ tag.value === "float"),
77
+ ) ||
86
78
  row.some(
87
79
  (tag) =>
88
- (tag.kind === "maximum" ||
89
- tag.kind === "exclusiveMaximum") &&
80
+ tag.kind === "multipleOf" &&
81
+ typeof tag.value === "number",
82
+ ) ||
83
+ (row.some(
84
+ (tag) =>
85
+ (tag.kind === "minimum" ||
86
+ tag.kind === "exclusiveMinimum") &&
90
87
  typeof tag.value === "number",
91
- ))
92
- ? []
93
- : [
94
- {
95
- expected: "number",
96
- expression: addition!,
97
- },
98
- ]),
99
- ...row.map((tag) => ({
100
- expected: `number & ${tag.name}`,
101
- expression: ExpressionFactory.transpile(project.context)(
102
- tag.validate,
103
- )(input),
104
- })),
105
- ]);
88
+ ) &&
89
+ row.some(
90
+ (tag) =>
91
+ (tag.kind === "maximum" ||
92
+ tag.kind === "exclusiveMaximum") &&
93
+ typeof tag.value === "number",
94
+ ))
95
+ ? []
96
+ : [
97
+ {
98
+ expected: "number",
99
+ expression: addition!,
100
+ },
101
+ ]),
102
+ ...row.map((tag) => ({
103
+ expected: `number & ${tag.name}`,
104
+ expression: ExpressionFactory.transpile(project.context)(
105
+ tag.validate!,
106
+ )(input),
107
+ })),
108
+ ]);
@@ -35,11 +35,14 @@ const check_string_type_tags =
35
35
  (project: IProject) =>
36
36
  (atomic: MetadataAtomic) =>
37
37
  (input: ts.Expression): ICheckEntry.ICondition[][] =>
38
- atomic.tags.map((row) =>
39
- row.map((tag) => ({
40
- expected: `string & ${tag.name}`,
41
- expression: ExpressionFactory.transpile(project.context)(
42
- tag.validate,
43
- )(input),
44
- })),
45
- );
38
+ atomic.tags
39
+ .map((row) => row.filter((tag) => !!tag.validate))
40
+ .filter((row) => !!row.length)
41
+ .map((row) =>
42
+ row.map((tag) => ({
43
+ expected: `string & ${tag.name}`,
44
+ expression: ExpressionFactory.transpile(project.context)(
45
+ tag.validate!,
46
+ )(input),
47
+ })),
48
+ );
@@ -60,7 +60,9 @@ export namespace IJsonSchema {
60
60
  multipleOf?: number & Type<"int32">;
61
61
  "x-typia-typeTags"?: IMetadataTypeTag[];
62
62
  }
63
- export interface IBoolean extends IAtomic<"boolean"> {}
63
+ export interface IBoolean extends IAtomic<"boolean"> {
64
+ "x-typia-typeTags"?: IMetadataTypeTag[];
65
+ }
64
66
 
65
67
  /* -----------------------------------------------------------
66
68
  OBJECTS
@@ -1,5 +1,7 @@
1
1
  import { Atomic } from "../../typings/Atomic";
2
2
 
3
+ import { IMetadataTypeTag } from "./IMetadataTypeTag";
4
+
3
5
  export type IMetadataConstant =
4
6
  | IMetadataConstant.IBase<"boolean", boolean>
5
7
  | IMetadataConstant.IBase<"number", number>
@@ -12,5 +14,12 @@ export namespace IMetadataConstant {
12
14
  > {
13
15
  type: Type;
14
16
  values: Value[];
17
+
18
+ /**
19
+ * @internal
20
+ */
21
+ tags?: Type extends "boolean"
22
+ ? IMetadataTypeTag[][] | undefined
23
+ : never;
15
24
  }
16
25
  }
@@ -1,8 +1,8 @@
1
1
  export interface IMetadataTypeTag {
2
- target: "bigint" | "number" | "string" | "array";
2
+ target: "boolean" | "bigint" | "number" | "string" | "array";
3
3
  name: string;
4
4
  kind: string;
5
5
  value: any;
6
- validate: string;
6
+ validate: string | undefined;
7
7
  exclusive: boolean | string[];
8
8
  }
@@ -44,6 +44,7 @@ export class Metadata {
44
44
  /** @internal */ private parent_resolved_: boolean = false;
45
45
  /** @internal */ public union_index?: number;
46
46
  /** @internal */ public fixed_?: number | null;
47
+ /** @internal */ public boolean_literal_intersected_?: boolean;
47
48
 
48
49
  /* -----------------------------------------------------------
49
50
  CONSTRUCTORS
@@ -0,0 +1,15 @@
1
+ import { TagBase } from "./TagBase";
2
+
3
+ export type Default<Value extends boolean | bigint | number | string> =
4
+ TagBase<{
5
+ target: Value extends boolean
6
+ ? "boolean"
7
+ : Value extends bigint
8
+ ? "bigint"
9
+ : Value extends number
10
+ ? "number"
11
+ : "string";
12
+ kind: "default";
13
+ value: Value;
14
+ exclusive: true;
15
+ }>;
@@ -26,5 +26,5 @@ export type Format<
26
26
  : Value extends "date"
27
27
  ? `/^(\\d{4})-(\\d{2})-(\\d{2})$/.test($input)`
28
28
  : `!isNaN(new Date($input).getTime())`;
29
- exclusive: ["pattern"];
29
+ exclusive: ["format", "pattern"];
30
30
  }>;
@@ -5,4 +5,5 @@ export type Pattern<Value extends string> = TagBase<{
5
5
  kind: "pattern";
6
6
  value: Value;
7
7
  validate: `/${Value}/.test($input)`;
8
+ exclusive: ["format", "pattern"];
8
9
  }>;
@@ -8,7 +8,7 @@ export type TagBase<Props extends TagBase.IProps<any, any, any, any, any>> = {
8
8
  };
9
9
  export namespace TagBase {
10
10
  export interface IProps<
11
- Target extends "bigint" | "number" | "string" | "array",
11
+ Target extends "boolean" | "bigint" | "number" | "string" | "array",
12
12
  Kind extends string,
13
13
  Value extends boolean | bigint | number | string | undefined,
14
14
  Validate extends
@@ -51,7 +51,7 @@ export namespace TagBase {
51
51
  * occured. So, define it with confidence. Compiler will block all your
52
52
  * mistakes.
53
53
  */
54
- validate: Validate;
54
+ validate?: Validate;
55
55
 
56
56
  /**
57
57
  * Exclusive option.
package/src/tags/index.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export * from "./Default";
1
2
  export * from "./ExclusiveMaximum";
2
3
  export * from "./ExclusiveMinimum";
3
4
  export * from "./Format";