typia 9.7.2 → 10.0.0-dev.20251107

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 (116) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +153 -153
  3. package/lib/factories/ProtobufFactory.js +1 -1
  4. package/lib/factories/ProtobufFactory.mjs +1 -1
  5. package/lib/programmers/internal/json_schema_station.d.mts +2 -2
  6. package/lib/programmers/internal/json_schema_station.d.ts +2 -2
  7. package/lib/programmers/llm/LlmApplicationProgrammer.js +5 -1
  8. package/lib/programmers/llm/LlmApplicationProgrammer.js.map +1 -1
  9. package/lib/programmers/llm/LlmApplicationProgrammer.mjs +5 -1
  10. package/lib/programmers/llm/LlmSchemaProgrammer.js +1 -4
  11. package/lib/programmers/llm/LlmSchemaProgrammer.js.map +1 -1
  12. package/lib/programmers/llm/LlmSchemaProgrammer.mjs +1 -35
  13. package/package.json +121 -121
  14. package/src/AssertionGuard.ts +41 -41
  15. package/src/CamelCase.ts +75 -75
  16. package/src/IRandomGenerator.ts +337 -337
  17. package/src/IReadableURLSearchParams.ts +9 -9
  18. package/src/PascalCase.ts +71 -71
  19. package/src/Primitive.ts +90 -90
  20. package/src/Resolved.ts +72 -72
  21. package/src/SnakeCase.ts +127 -127
  22. package/src/TypeGuardError.ts +216 -216
  23. package/src/factories/MetadataCollection.ts +270 -270
  24. package/src/factories/MetadataCommentTagFactory.ts +632 -632
  25. package/src/factories/MetadataFactory.ts +402 -402
  26. package/src/factories/ProtobufFactory.ts +873 -873
  27. package/src/functional.ts +705 -705
  28. package/src/http.ts +972 -972
  29. package/src/internal/_ProtobufReader.ts +188 -188
  30. package/src/internal/_ProtobufSizer.ts +137 -137
  31. package/src/internal/_ProtobufWriter.ts +135 -135
  32. package/src/internal/_jsonStringifyString.ts +42 -42
  33. package/src/json.ts +643 -643
  34. package/src/llm.ts +615 -615
  35. package/src/misc.ts +594 -594
  36. package/src/module.ts +889 -889
  37. package/src/notations.ts +751 -751
  38. package/src/programmers/FeatureProgrammer.ts +605 -605
  39. package/src/programmers/ImportProgrammer.ts +179 -179
  40. package/src/programmers/RandomProgrammer.ts +1195 -1195
  41. package/src/programmers/helpers/ProtobufWire.ts +34 -34
  42. package/src/programmers/internal/check_array_length.ts +43 -43
  43. package/src/programmers/internal/check_bigint.ts +46 -46
  44. package/src/programmers/internal/check_dynamic_key.ts +197 -197
  45. package/src/programmers/internal/check_dynamic_properties.ts +231 -231
  46. package/src/programmers/internal/check_everything.ts +21 -21
  47. package/src/programmers/internal/check_native.ts +23 -23
  48. package/src/programmers/internal/check_number.ts +108 -108
  49. package/src/programmers/internal/check_object.ts +72 -72
  50. package/src/programmers/internal/check_string.ts +46 -46
  51. package/src/programmers/internal/check_template.ts +46 -46
  52. package/src/programmers/internal/check_union_array_like.ts +331 -331
  53. package/src/programmers/internal/decode_union_object.ts +110 -110
  54. package/src/programmers/internal/feature_object_entries.ts +59 -59
  55. package/src/programmers/internal/json_schema_escaped.ts +78 -78
  56. package/src/programmers/internal/json_schema_object.ts +150 -150
  57. package/src/programmers/internal/json_schema_station.ts +2 -2
  58. package/src/programmers/internal/metadata_to_pattern.ts +40 -40
  59. package/src/programmers/internal/postfix_of_tuple.ts +3 -3
  60. package/src/programmers/internal/prune_object_properties.ts +69 -69
  61. package/src/programmers/internal/stringify_dynamic_properties.ts +158 -158
  62. package/src/programmers/internal/stringify_native.ts +5 -5
  63. package/src/programmers/internal/stringify_regular_properties.ts +77 -77
  64. package/src/programmers/internal/template_to_pattern.ts +21 -21
  65. package/src/programmers/internal/wrap_metadata_rest_tuple.ts +21 -21
  66. package/src/programmers/json/JsonStringifyProgrammer.ts +1124 -1124
  67. package/src/programmers/llm/LlmApplicationProgrammer.ts +10 -1
  68. package/src/programmers/llm/LlmSchemaProgrammer.ts +2 -7
  69. package/src/protobuf.ts +820 -820
  70. package/src/reflect.ts +46 -46
  71. package/src/schemas/json/IJsonApplication.ts +77 -77
  72. package/src/schemas/json/IJsonSchemaCollection.ts +212 -212
  73. package/src/schemas/json/IJsonSchemaUnit.ts +263 -263
  74. package/src/schemas/metadata/IMetadataTypeTag.ts +14 -14
  75. package/src/schemas/metadata/Metadata.ts +669 -669
  76. package/src/schemas/metadata/MetadataAliasType.ts +57 -57
  77. package/src/schemas/metadata/MetadataApplication.ts +40 -40
  78. package/src/schemas/metadata/MetadataArray.ts +47 -47
  79. package/src/schemas/metadata/MetadataArrayType.ts +51 -51
  80. package/src/schemas/metadata/MetadataAtomic.ts +85 -85
  81. package/src/schemas/metadata/MetadataEscaped.ts +45 -45
  82. package/src/schemas/metadata/MetadataFunction.ts +45 -45
  83. package/src/schemas/metadata/MetadataObject.ts +46 -46
  84. package/src/schemas/metadata/MetadataObjectType.ts +137 -137
  85. package/src/schemas/metadata/MetadataParameter.ts +52 -52
  86. package/src/schemas/metadata/MetadataProperty.ts +53 -53
  87. package/src/schemas/metadata/MetadataTemplate.ts +78 -78
  88. package/src/schemas/metadata/MetadataTuple.ts +28 -28
  89. package/src/schemas/metadata/MetadataTupleType.ts +61 -61
  90. package/src/tags/Constant.ts +47 -47
  91. package/src/tags/ContentMediaType.ts +27 -27
  92. package/src/tags/Default.ts +52 -52
  93. package/src/tags/Example.ts +56 -56
  94. package/src/tags/Examples.ts +56 -56
  95. package/src/tags/ExclusiveMaximum.ts +44 -44
  96. package/src/tags/ExclusiveMinimum.ts +44 -44
  97. package/src/tags/Format.ts +78 -78
  98. package/src/tags/JsonSchemaPlugin.ts +36 -36
  99. package/src/tags/MaxItems.ts +31 -31
  100. package/src/tags/MaxLength.ts +25 -25
  101. package/src/tags/Maximum.ts +39 -39
  102. package/src/tags/MinItems.ts +31 -31
  103. package/src/tags/MinLength.ts +25 -25
  104. package/src/tags/Minimum.ts +39 -39
  105. package/src/tags/MultipleOf.ts +42 -42
  106. package/src/tags/Pattern.ts +49 -49
  107. package/src/tags/Sequence.ts +37 -37
  108. package/src/tags/TagBase.ts +102 -102
  109. package/src/tags/Type.ts +64 -64
  110. package/src/tags/UniqueItems.ts +34 -34
  111. package/src/tags/internal/FormatCheatSheet.ts +71 -71
  112. package/src/transformers/ITransformOptions.ts +70 -70
  113. package/src/transformers/ImportTransformer.ts +253 -253
  114. package/src/transformers/NoTransformConfigurationError.ts +16 -16
  115. package/src/transformers/features/llm/LlmApplicationTransformer.ts +224 -224
  116. package/src/typings/Equal.ts +18 -18
@@ -1,78 +1,78 @@
1
- import { ClassProperties } from "../../typings/ClassProperties";
2
-
3
- import { IMetadataDictionary } from "./IMetadataDictionary";
4
- import { IMetadataTemplate } from "./IMetadataTemplate";
5
- import { IMetadataTypeTag } from "./IMetadataTypeTag";
6
- import { Metadata } from "./Metadata";
7
-
8
- export class MetadataTemplate {
9
- public readonly row: Metadata[];
10
- public readonly tags: IMetadataTypeTag[][];
11
-
12
- private name_?: string;
13
-
14
- private constructor(props: ClassProperties<MetadataTemplate>) {
15
- this.row = props.row.map(Metadata.create);
16
- this.tags = props.tags;
17
- }
18
-
19
- public static create(
20
- props: ClassProperties<MetadataTemplate>,
21
- ): MetadataTemplate {
22
- return new MetadataTemplate(props);
23
- }
24
-
25
- public static from(
26
- json: IMetadataTemplate,
27
- dict: IMetadataDictionary,
28
- ): MetadataTemplate {
29
- return new MetadataTemplate({
30
- row: json.row.map((m) => Metadata.from(m, dict)),
31
- tags: json.tags,
32
- });
33
- }
34
-
35
- public getName(): string {
36
- return (this.name_ ??= getName(this));
37
- }
38
-
39
- /** @internal */
40
- public getBaseName(): string {
41
- return (
42
- "`" +
43
- this.row
44
- .map((child) =>
45
- child.isConstant() && child.size() === 1
46
- ? child.constants[0]!.values[0]!.value
47
- : `$\{${child.getName()}\}`,
48
- )
49
- .join("")
50
- .split("`")
51
- .join("\\`") +
52
- "`"
53
- );
54
- }
55
-
56
- public toJSON(): IMetadataTemplate {
57
- return {
58
- row: this.row.map((m) => m.toJSON()),
59
- tags: this.tags,
60
- };
61
- }
62
- }
63
-
64
- const getName = (template: MetadataTemplate): string => {
65
- const base: string = template.getBaseName();
66
- if (!template.tags?.length) return base;
67
- else if (template.tags.length === 1) {
68
- const str: string = [base, ...template.tags[0]!.map((t) => t.name)].join(
69
- " & ",
70
- );
71
- return `(${str})`;
72
- }
73
- const rows: string[] = template.tags.map((row) => {
74
- const str: string = row.map((t) => t.name).join(" & ");
75
- return row.length === 1 ? str : `(${str})`;
76
- });
77
- return `(${base} & (${rows.join(" | ")}))`;
78
- };
1
+ import { ClassProperties } from "../../typings/ClassProperties";
2
+
3
+ import { IMetadataDictionary } from "./IMetadataDictionary";
4
+ import { IMetadataTemplate } from "./IMetadataTemplate";
5
+ import { IMetadataTypeTag } from "./IMetadataTypeTag";
6
+ import { Metadata } from "./Metadata";
7
+
8
+ export class MetadataTemplate {
9
+ public readonly row: Metadata[];
10
+ public readonly tags: IMetadataTypeTag[][];
11
+
12
+ private name_?: string;
13
+
14
+ private constructor(props: ClassProperties<MetadataTemplate>) {
15
+ this.row = props.row.map(Metadata.create);
16
+ this.tags = props.tags;
17
+ }
18
+
19
+ public static create(
20
+ props: ClassProperties<MetadataTemplate>,
21
+ ): MetadataTemplate {
22
+ return new MetadataTemplate(props);
23
+ }
24
+
25
+ public static from(
26
+ json: IMetadataTemplate,
27
+ dict: IMetadataDictionary,
28
+ ): MetadataTemplate {
29
+ return new MetadataTemplate({
30
+ row: json.row.map((m) => Metadata.from(m, dict)),
31
+ tags: json.tags,
32
+ });
33
+ }
34
+
35
+ public getName(): string {
36
+ return (this.name_ ??= getName(this));
37
+ }
38
+
39
+ /** @internal */
40
+ public getBaseName(): string {
41
+ return (
42
+ "`" +
43
+ this.row
44
+ .map((child) =>
45
+ child.isConstant() && child.size() === 1
46
+ ? child.constants[0]!.values[0]!.value
47
+ : `$\{${child.getName()}\}`,
48
+ )
49
+ .join("")
50
+ .split("`")
51
+ .join("\\`") +
52
+ "`"
53
+ );
54
+ }
55
+
56
+ public toJSON(): IMetadataTemplate {
57
+ return {
58
+ row: this.row.map((m) => m.toJSON()),
59
+ tags: this.tags,
60
+ };
61
+ }
62
+ }
63
+
64
+ const getName = (template: MetadataTemplate): string => {
65
+ const base: string = template.getBaseName();
66
+ if (!template.tags?.length) return base;
67
+ else if (template.tags.length === 1) {
68
+ const str: string = [base, ...template.tags[0]!.map((t) => t.name)].join(
69
+ " & ",
70
+ );
71
+ return `(${str})`;
72
+ }
73
+ const rows: string[] = template.tags.map((row) => {
74
+ const str: string = row.map((t) => t.name).join(" & ");
75
+ return row.length === 1 ? str : `(${str})`;
76
+ });
77
+ return `(${base} & (${rows.join(" | ")}))`;
78
+ };
@@ -1,28 +1,28 @@
1
- import { ClassProperties } from "../../typings/ClassProperties";
2
-
3
- import { IMetadataTuple } from "./IMetadataTuple";
4
- import { IMetadataTypeTag } from "./IMetadataTypeTag";
5
- import { MetadataTupleType } from "./MetadataTupleType";
6
-
7
- export class MetadataTuple {
8
- public readonly type: MetadataTupleType;
9
- public readonly tags: IMetadataTypeTag[][];
10
-
11
- /** @ignore */
12
- private constructor(props: ClassProperties<MetadataTuple>) {
13
- this.type = props.type;
14
- this.tags = props.tags;
15
- }
16
-
17
- /** @internal */
18
- public static create(props: ClassProperties<MetadataTuple>): MetadataTuple {
19
- return new MetadataTuple(props);
20
- }
21
-
22
- public toJSON(): IMetadataTuple {
23
- return {
24
- name: this.type.name,
25
- tags: this.tags.map((row) => row.slice()),
26
- };
27
- }
28
- }
1
+ import { ClassProperties } from "../../typings/ClassProperties";
2
+
3
+ import { IMetadataTuple } from "./IMetadataTuple";
4
+ import { IMetadataTypeTag } from "./IMetadataTypeTag";
5
+ import { MetadataTupleType } from "./MetadataTupleType";
6
+
7
+ export class MetadataTuple {
8
+ public readonly type: MetadataTupleType;
9
+ public readonly tags: IMetadataTypeTag[][];
10
+
11
+ /** @ignore */
12
+ private constructor(props: ClassProperties<MetadataTuple>) {
13
+ this.type = props.type;
14
+ this.tags = props.tags;
15
+ }
16
+
17
+ /** @internal */
18
+ public static create(props: ClassProperties<MetadataTuple>): MetadataTuple {
19
+ return new MetadataTuple(props);
20
+ }
21
+
22
+ public toJSON(): IMetadataTuple {
23
+ return {
24
+ name: this.type.name,
25
+ tags: this.tags.map((row) => row.slice()),
26
+ };
27
+ }
28
+ }
@@ -1,61 +1,61 @@
1
- import { ClassProperties } from "../../typings/ClassProperties";
2
-
3
- import { IMetadataTupleType } from "./IMetadataTupleType";
4
- import { Metadata } from "./Metadata";
5
-
6
- export class MetadataTupleType {
7
- public readonly name: string;
8
- public readonly elements: Metadata[];
9
-
10
- public readonly index: number | null;
11
- public readonly recursive: boolean;
12
- public readonly nullables: boolean[];
13
-
14
- /** @internal */
15
- public of_map?: boolean;
16
-
17
- /** @internal */
18
- private constructor(props: ClassProperties<MetadataTupleType>) {
19
- this.name = props.name;
20
- this.elements = props.elements;
21
- this.index = props.index;
22
- this.recursive = props.recursive;
23
- this.nullables = props.nullables;
24
- }
25
-
26
- /** @internal */
27
- public static _From_without_elements(
28
- props: Omit<IMetadataTupleType, "elements">,
29
- ): MetadataTupleType {
30
- return MetadataTupleType.create({
31
- name: props.name,
32
- index: props.index,
33
- elements: null!,
34
- recursive: props.recursive,
35
- nullables: props.nullables.slice(),
36
- });
37
- }
38
-
39
- public static create(
40
- props: ClassProperties<MetadataTupleType>,
41
- ): MetadataTupleType {
42
- return new MetadataTupleType(props);
43
- }
44
-
45
- public isRest(): boolean {
46
- return (
47
- this.elements.length > 0 &&
48
- this.elements[this.elements.length - 1]!.rest !== null
49
- );
50
- }
51
-
52
- public toJSON(): IMetadataTupleType {
53
- return {
54
- name: this.name,
55
- index: this.index,
56
- elements: this.elements.map((elem) => elem.toJSON()),
57
- recursive: this.recursive,
58
- nullables: this.nullables.slice(),
59
- };
60
- }
61
- }
1
+ import { ClassProperties } from "../../typings/ClassProperties";
2
+
3
+ import { IMetadataTupleType } from "./IMetadataTupleType";
4
+ import { Metadata } from "./Metadata";
5
+
6
+ export class MetadataTupleType {
7
+ public readonly name: string;
8
+ public readonly elements: Metadata[];
9
+
10
+ public readonly index: number | null;
11
+ public readonly recursive: boolean;
12
+ public readonly nullables: boolean[];
13
+
14
+ /** @internal */
15
+ public of_map?: boolean;
16
+
17
+ /** @internal */
18
+ private constructor(props: ClassProperties<MetadataTupleType>) {
19
+ this.name = props.name;
20
+ this.elements = props.elements;
21
+ this.index = props.index;
22
+ this.recursive = props.recursive;
23
+ this.nullables = props.nullables;
24
+ }
25
+
26
+ /** @internal */
27
+ public static _From_without_elements(
28
+ props: Omit<IMetadataTupleType, "elements">,
29
+ ): MetadataTupleType {
30
+ return MetadataTupleType.create({
31
+ name: props.name,
32
+ index: props.index,
33
+ elements: null!,
34
+ recursive: props.recursive,
35
+ nullables: props.nullables.slice(),
36
+ });
37
+ }
38
+
39
+ public static create(
40
+ props: ClassProperties<MetadataTupleType>,
41
+ ): MetadataTupleType {
42
+ return new MetadataTupleType(props);
43
+ }
44
+
45
+ public isRest(): boolean {
46
+ return (
47
+ this.elements.length > 0 &&
48
+ this.elements[this.elements.length - 1]!.rest !== null
49
+ );
50
+ }
51
+
52
+ public toJSON(): IMetadataTupleType {
53
+ return {
54
+ name: this.name,
55
+ index: this.index,
56
+ elements: this.elements.map((elem) => elem.toJSON()),
57
+ recursive: this.recursive,
58
+ nullables: this.nullables.slice(),
59
+ };
60
+ }
61
+ }
@@ -1,47 +1,47 @@
1
- import { TagBase } from "./TagBase";
2
-
3
- /**
4
- * Constant tag that adds title and description metadata to literal types.
5
- *
6
- * This tag enhances literal values with human-readable documentation without
7
- * changing their runtime type. It's particularly useful for enum-like values
8
- * where you want to provide context about what each value represents.
9
- *
10
- * The metadata appears in generated JSON Schema, making API documentation more
11
- * descriptive and helping developers understand the meaning of specific
12
- * constant values.
13
- *
14
- * @author Jeongho Nam - https://github.com/samchon
15
- * @example
16
- * ```typescript
17
- * type Status =
18
- * | Constant<"active", { title: "Active", description: "User is currently active" }>
19
- * | Constant<"inactive", { title: "Inactive", description: "User account is disabled" }>
20
- * | Constant<"pending", { title: "Pending", description: "Awaiting verification" }>;
21
- * ```;
22
- *
23
- * @example
24
- * ```typescript
25
- * interface Config {
26
- * debugLevel: Constant<0, { title: "Off", description: "No debug output" }>
27
- * | Constant<1, { title: "Basic", description: "Basic logging" }>
28
- * | Constant<2, { title: "Verbose", description: "Detailed debug info" }>;
29
- * }
30
- * ```;
31
- *
32
- * @template Value The literal value (boolean, number, string, or bigint)
33
- * @template Content Metadata with optional title and description
34
- */
35
- export type Constant<
36
- Value extends boolean | number | string | bigint,
37
- Content extends {
38
- title?: string | undefined;
39
- description?: string | undefined;
40
- },
41
- > = Value &
42
- TagBase<{
43
- target: "string" | "boolean" | "number" | "bigint";
44
- kind: "constant";
45
- value: undefined;
46
- schema: Content;
47
- }>;
1
+ import { TagBase } from "./TagBase";
2
+
3
+ /**
4
+ * Constant tag that adds title and description metadata to literal types.
5
+ *
6
+ * This tag enhances literal values with human-readable documentation without
7
+ * changing their runtime type. It's particularly useful for enum-like values
8
+ * where you want to provide context about what each value represents.
9
+ *
10
+ * The metadata appears in generated JSON Schema, making API documentation more
11
+ * descriptive and helping developers understand the meaning of specific
12
+ * constant values.
13
+ *
14
+ * @author Jeongho Nam - https://github.com/samchon
15
+ * @example
16
+ * ```typescript
17
+ * type Status =
18
+ * | Constant<"active", { title: "Active", description: "User is currently active" }>
19
+ * | Constant<"inactive", { title: "Inactive", description: "User account is disabled" }>
20
+ * | Constant<"pending", { title: "Pending", description: "Awaiting verification" }>;
21
+ * ```;
22
+ *
23
+ * @example
24
+ * ```typescript
25
+ * interface Config {
26
+ * debugLevel: Constant<0, { title: "Off", description: "No debug output" }>
27
+ * | Constant<1, { title: "Basic", description: "Basic logging" }>
28
+ * | Constant<2, { title: "Verbose", description: "Detailed debug info" }>;
29
+ * }
30
+ * ```;
31
+ *
32
+ * @template Value The literal value (boolean, number, string, or bigint)
33
+ * @template Content Metadata with optional title and description
34
+ */
35
+ export type Constant<
36
+ Value extends boolean | number | string | bigint,
37
+ Content extends {
38
+ title?: string | undefined;
39
+ description?: string | undefined;
40
+ },
41
+ > = Value &
42
+ TagBase<{
43
+ target: "string" | "boolean" | "number" | "bigint";
44
+ kind: "constant";
45
+ value: undefined;
46
+ schema: Content;
47
+ }>;
@@ -1,27 +1,27 @@
1
- import { TagBase } from "./TagBase";
2
-
3
- /**
4
- * String content media type constraint tag.
5
- *
6
- * Specifies the MIME type of string content for proper interpretation. This tag
7
- * serves as metadata to indicate how the string content should be interpreted,
8
- * but does not perform validation on the content itself.
9
- *
10
- * Examples: type JsonData = string & ContentMediaType<"application/json">; //
11
- * JSON string type Base64Image = string & ContentMediaType<"image/png">; //
12
- * Base64 PNG type XmlContent = string & ContentMediaType<"application/xml">; //
13
- * XML data
14
- *
15
- * Common MIME types: application/json, text/html, image/jpeg, image/png,
16
- * application/pdf, text/plain, application/xml, and many more.
17
- *
18
- * @author Jeongho Nam - https://github.com/samchon
19
- */
20
- export type ContentMediaType<Value extends string> = TagBase<{
21
- target: "string";
22
- kind: "contentMediaType";
23
- value: undefined;
24
- schema: {
25
- contentMediaType: Value;
26
- };
27
- }>;
1
+ import { TagBase } from "./TagBase";
2
+
3
+ /**
4
+ * String content media type constraint tag.
5
+ *
6
+ * Specifies the MIME type of string content for proper interpretation. This tag
7
+ * serves as metadata to indicate how the string content should be interpreted,
8
+ * but does not perform validation on the content itself.
9
+ *
10
+ * Examples: type JsonData = string & ContentMediaType<"application/json">; //
11
+ * JSON string type Base64Image = string & ContentMediaType<"image/png">; //
12
+ * Base64 PNG type XmlContent = string & ContentMediaType<"application/xml">; //
13
+ * XML data
14
+ *
15
+ * Common MIME types: application/json, text/html, image/jpeg, image/png,
16
+ * application/pdf, text/plain, application/xml, and many more.
17
+ *
18
+ * @author Jeongho Nam - https://github.com/samchon
19
+ */
20
+ export type ContentMediaType<Value extends string> = TagBase<{
21
+ target: "string";
22
+ kind: "contentMediaType";
23
+ value: undefined;
24
+ schema: {
25
+ contentMediaType: Value;
26
+ };
27
+ }>;
@@ -1,52 +1,52 @@
1
- import { TagBase } from "./TagBase";
2
-
3
- /**
4
- * Default value tag that specifies a default value for properties.
5
- *
6
- * When a property is not provided during validation, this tag instructs typia
7
- * to use the specified default value. This is useful for optional properties
8
- * that should have a specific fallback value.
9
- *
10
- * Supported types: boolean, bigint, number, and string primitives. Note:
11
- * Default values are applied during validation, not at compile time.
12
- *
13
- * @author Jeongho Nam - https://github.com/samchon
14
- * @example
15
- * ```typescript
16
- * interface User {
17
- * name: string;
18
- * active: boolean & Default<true>; // defaults to true if not provided
19
- * retries: number & Default<3>; // defaults to 3 if not provided
20
- * }
21
- * ```;
22
- *
23
- * @example
24
- * ```typescript
25
- * interface Config {
26
- * timeout: bigint & Default<5000n>; // defaults to 5000n
27
- * prefix: string & Default<"user_">; // defaults to "user_"
28
- * }
29
- * ```;
30
- *
31
- * @template Value The default value (boolean, bigint, number, or string)
32
- */
33
- export type Default<Value extends boolean | bigint | number | string> =
34
- TagBase<{
35
- target: Value extends boolean
36
- ? "boolean"
37
- : Value extends bigint
38
- ? "bigint"
39
- : Value extends number
40
- ? "number"
41
- : "string";
42
- kind: "default";
43
- value: Value;
44
- exclusive: true;
45
- schema: Value extends bigint
46
- ? { default: Numeric<Value> }
47
- : { default: Value };
48
- }>;
49
-
50
- type Numeric<T extends bigint> = `${T}` extends `${infer N extends number}`
51
- ? N
52
- : never;
1
+ import { TagBase } from "./TagBase";
2
+
3
+ /**
4
+ * Default value tag that specifies a default value for properties.
5
+ *
6
+ * When a property is not provided during validation, this tag instructs typia
7
+ * to use the specified default value. This is useful for optional properties
8
+ * that should have a specific fallback value.
9
+ *
10
+ * Supported types: boolean, bigint, number, and string primitives. Note:
11
+ * Default values are applied during validation, not at compile time.
12
+ *
13
+ * @author Jeongho Nam - https://github.com/samchon
14
+ * @example
15
+ * ```typescript
16
+ * interface User {
17
+ * name: string;
18
+ * active: boolean & Default<true>; // defaults to true if not provided
19
+ * retries: number & Default<3>; // defaults to 3 if not provided
20
+ * }
21
+ * ```;
22
+ *
23
+ * @example
24
+ * ```typescript
25
+ * interface Config {
26
+ * timeout: bigint & Default<5000n>; // defaults to 5000n
27
+ * prefix: string & Default<"user_">; // defaults to "user_"
28
+ * }
29
+ * ```;
30
+ *
31
+ * @template Value The default value (boolean, bigint, number, or string)
32
+ */
33
+ export type Default<Value extends boolean | bigint | number | string> =
34
+ TagBase<{
35
+ target: Value extends boolean
36
+ ? "boolean"
37
+ : Value extends bigint
38
+ ? "bigint"
39
+ : Value extends number
40
+ ? "number"
41
+ : "string";
42
+ kind: "default";
43
+ value: Value;
44
+ exclusive: true;
45
+ schema: Value extends bigint
46
+ ? { default: Numeric<Value> }
47
+ : { default: Value };
48
+ }>;
49
+
50
+ type Numeric<T extends bigint> = `${T}` extends `${infer N extends number}`
51
+ ? N
52
+ : never;