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.
- package/LICENSE +21 -21
- package/README.md +153 -153
- package/lib/factories/ProtobufFactory.js +1 -1
- package/lib/factories/ProtobufFactory.mjs +1 -1
- package/lib/programmers/internal/json_schema_station.d.mts +2 -2
- package/lib/programmers/internal/json_schema_station.d.ts +2 -2
- package/lib/programmers/llm/LlmApplicationProgrammer.js +5 -1
- package/lib/programmers/llm/LlmApplicationProgrammer.js.map +1 -1
- package/lib/programmers/llm/LlmApplicationProgrammer.mjs +5 -1
- package/lib/programmers/llm/LlmSchemaProgrammer.js +1 -4
- package/lib/programmers/llm/LlmSchemaProgrammer.js.map +1 -1
- package/lib/programmers/llm/LlmSchemaProgrammer.mjs +1 -35
- package/package.json +121 -121
- package/src/AssertionGuard.ts +41 -41
- package/src/CamelCase.ts +75 -75
- package/src/IRandomGenerator.ts +337 -337
- package/src/IReadableURLSearchParams.ts +9 -9
- package/src/PascalCase.ts +71 -71
- package/src/Primitive.ts +90 -90
- package/src/Resolved.ts +72 -72
- package/src/SnakeCase.ts +127 -127
- package/src/TypeGuardError.ts +216 -216
- package/src/factories/MetadataCollection.ts +270 -270
- package/src/factories/MetadataCommentTagFactory.ts +632 -632
- package/src/factories/MetadataFactory.ts +402 -402
- package/src/factories/ProtobufFactory.ts +873 -873
- package/src/functional.ts +705 -705
- package/src/http.ts +972 -972
- package/src/internal/_ProtobufReader.ts +188 -188
- package/src/internal/_ProtobufSizer.ts +137 -137
- package/src/internal/_ProtobufWriter.ts +135 -135
- package/src/internal/_jsonStringifyString.ts +42 -42
- package/src/json.ts +643 -643
- package/src/llm.ts +615 -615
- package/src/misc.ts +594 -594
- package/src/module.ts +889 -889
- package/src/notations.ts +751 -751
- package/src/programmers/FeatureProgrammer.ts +605 -605
- package/src/programmers/ImportProgrammer.ts +179 -179
- package/src/programmers/RandomProgrammer.ts +1195 -1195
- package/src/programmers/helpers/ProtobufWire.ts +34 -34
- package/src/programmers/internal/check_array_length.ts +43 -43
- package/src/programmers/internal/check_bigint.ts +46 -46
- package/src/programmers/internal/check_dynamic_key.ts +197 -197
- package/src/programmers/internal/check_dynamic_properties.ts +231 -231
- package/src/programmers/internal/check_everything.ts +21 -21
- package/src/programmers/internal/check_native.ts +23 -23
- package/src/programmers/internal/check_number.ts +108 -108
- package/src/programmers/internal/check_object.ts +72 -72
- package/src/programmers/internal/check_string.ts +46 -46
- package/src/programmers/internal/check_template.ts +46 -46
- package/src/programmers/internal/check_union_array_like.ts +331 -331
- package/src/programmers/internal/decode_union_object.ts +110 -110
- package/src/programmers/internal/feature_object_entries.ts +59 -59
- package/src/programmers/internal/json_schema_escaped.ts +78 -78
- package/src/programmers/internal/json_schema_object.ts +150 -150
- package/src/programmers/internal/json_schema_station.ts +2 -2
- package/src/programmers/internal/metadata_to_pattern.ts +40 -40
- package/src/programmers/internal/postfix_of_tuple.ts +3 -3
- package/src/programmers/internal/prune_object_properties.ts +69 -69
- package/src/programmers/internal/stringify_dynamic_properties.ts +158 -158
- package/src/programmers/internal/stringify_native.ts +5 -5
- package/src/programmers/internal/stringify_regular_properties.ts +77 -77
- package/src/programmers/internal/template_to_pattern.ts +21 -21
- package/src/programmers/internal/wrap_metadata_rest_tuple.ts +21 -21
- package/src/programmers/json/JsonStringifyProgrammer.ts +1124 -1124
- package/src/programmers/llm/LlmApplicationProgrammer.ts +10 -1
- package/src/programmers/llm/LlmSchemaProgrammer.ts +2 -7
- package/src/protobuf.ts +820 -820
- package/src/reflect.ts +46 -46
- package/src/schemas/json/IJsonApplication.ts +77 -77
- package/src/schemas/json/IJsonSchemaCollection.ts +212 -212
- package/src/schemas/json/IJsonSchemaUnit.ts +263 -263
- package/src/schemas/metadata/IMetadataTypeTag.ts +14 -14
- package/src/schemas/metadata/Metadata.ts +669 -669
- package/src/schemas/metadata/MetadataAliasType.ts +57 -57
- package/src/schemas/metadata/MetadataApplication.ts +40 -40
- package/src/schemas/metadata/MetadataArray.ts +47 -47
- package/src/schemas/metadata/MetadataArrayType.ts +51 -51
- package/src/schemas/metadata/MetadataAtomic.ts +85 -85
- package/src/schemas/metadata/MetadataEscaped.ts +45 -45
- package/src/schemas/metadata/MetadataFunction.ts +45 -45
- package/src/schemas/metadata/MetadataObject.ts +46 -46
- package/src/schemas/metadata/MetadataObjectType.ts +137 -137
- package/src/schemas/metadata/MetadataParameter.ts +52 -52
- package/src/schemas/metadata/MetadataProperty.ts +53 -53
- package/src/schemas/metadata/MetadataTemplate.ts +78 -78
- package/src/schemas/metadata/MetadataTuple.ts +28 -28
- package/src/schemas/metadata/MetadataTupleType.ts +61 -61
- package/src/tags/Constant.ts +47 -47
- package/src/tags/ContentMediaType.ts +27 -27
- package/src/tags/Default.ts +52 -52
- package/src/tags/Example.ts +56 -56
- package/src/tags/Examples.ts +56 -56
- package/src/tags/ExclusiveMaximum.ts +44 -44
- package/src/tags/ExclusiveMinimum.ts +44 -44
- package/src/tags/Format.ts +78 -78
- package/src/tags/JsonSchemaPlugin.ts +36 -36
- package/src/tags/MaxItems.ts +31 -31
- package/src/tags/MaxLength.ts +25 -25
- package/src/tags/Maximum.ts +39 -39
- package/src/tags/MinItems.ts +31 -31
- package/src/tags/MinLength.ts +25 -25
- package/src/tags/Minimum.ts +39 -39
- package/src/tags/MultipleOf.ts +42 -42
- package/src/tags/Pattern.ts +49 -49
- package/src/tags/Sequence.ts +37 -37
- package/src/tags/TagBase.ts +102 -102
- package/src/tags/Type.ts +64 -64
- package/src/tags/UniqueItems.ts +34 -34
- package/src/tags/internal/FormatCheatSheet.ts +71 -71
- package/src/transformers/ITransformOptions.ts +70 -70
- package/src/transformers/ImportTransformer.ts +253 -253
- package/src/transformers/NoTransformConfigurationError.ts +16 -16
- package/src/transformers/features/llm/LlmApplicationTransformer.ts +224 -224
- package/src/typings/Equal.ts +18 -18
package/src/tags/MaxItems.ts
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
import { TagBase } from "./TagBase";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Maximum items validation tag for arrays.
|
|
5
|
-
*
|
|
6
|
-
* Enforces that an array contains at most the specified number of items. This
|
|
7
|
-
* tag is useful for limiting array sizes, such as restricting the number of
|
|
8
|
-
* uploaded files, limiting selections in a form, or capping the size of
|
|
9
|
-
* collections to prevent performance issues.
|
|
10
|
-
*
|
|
11
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
12
|
-
* @example
|
|
13
|
-
* // Allow maximum 5 file uploads
|
|
14
|
-
* type FileList = File[] & MaxItems<5>;
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* // Limit tags to 10 items
|
|
18
|
-
* type ProductTags = string[] & MaxItems<10>;
|
|
19
|
-
*
|
|
20
|
-
* @template Value - The maximum number of items allowed
|
|
21
|
-
*/
|
|
22
|
-
export type MaxItems<Value extends number> = TagBase<{
|
|
23
|
-
target: "array";
|
|
24
|
-
kind: "maxItems";
|
|
25
|
-
value: Value;
|
|
26
|
-
validate: `$input.length <= ${Value}`;
|
|
27
|
-
exclusive: true;
|
|
28
|
-
schema: {
|
|
29
|
-
maxItems: Value;
|
|
30
|
-
};
|
|
31
|
-
}>;
|
|
1
|
+
import { TagBase } from "./TagBase";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Maximum items validation tag for arrays.
|
|
5
|
+
*
|
|
6
|
+
* Enforces that an array contains at most the specified number of items. This
|
|
7
|
+
* tag is useful for limiting array sizes, such as restricting the number of
|
|
8
|
+
* uploaded files, limiting selections in a form, or capping the size of
|
|
9
|
+
* collections to prevent performance issues.
|
|
10
|
+
*
|
|
11
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
12
|
+
* @example
|
|
13
|
+
* // Allow maximum 5 file uploads
|
|
14
|
+
* type FileList = File[] & MaxItems<5>;
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* // Limit tags to 10 items
|
|
18
|
+
* type ProductTags = string[] & MaxItems<10>;
|
|
19
|
+
*
|
|
20
|
+
* @template Value - The maximum number of items allowed
|
|
21
|
+
*/
|
|
22
|
+
export type MaxItems<Value extends number> = TagBase<{
|
|
23
|
+
target: "array";
|
|
24
|
+
kind: "maxItems";
|
|
25
|
+
value: Value;
|
|
26
|
+
validate: `$input.length <= ${Value}`;
|
|
27
|
+
exclusive: true;
|
|
28
|
+
schema: {
|
|
29
|
+
maxItems: Value;
|
|
30
|
+
};
|
|
31
|
+
}>;
|
package/src/tags/MaxLength.ts
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import { TagBase } from "./TagBase";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* String maximum length constraint tag.
|
|
5
|
-
*
|
|
6
|
-
* Validates that a string's length is less than or equal to the specified
|
|
7
|
-
* value. This tag enforces an upper limit on the number of characters in a
|
|
8
|
-
* string.
|
|
9
|
-
*
|
|
10
|
-
* Examples: type ShortComment = string & MaxLength<200>; // Comment limited to
|
|
11
|
-
* 200 characters type ZipCode = string & MaxLength<10>; // Zip code with max 10
|
|
12
|
-
* characters
|
|
13
|
-
*
|
|
14
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
15
|
-
*/
|
|
16
|
-
export type MaxLength<Value extends number> = TagBase<{
|
|
17
|
-
target: "string";
|
|
18
|
-
kind: "maxLength";
|
|
19
|
-
value: Value;
|
|
20
|
-
validate: `$input.length <= ${Value}`;
|
|
21
|
-
exclusive: true;
|
|
22
|
-
schema: {
|
|
23
|
-
maxLength: Value;
|
|
24
|
-
};
|
|
25
|
-
}>;
|
|
1
|
+
import { TagBase } from "./TagBase";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* String maximum length constraint tag.
|
|
5
|
+
*
|
|
6
|
+
* Validates that a string's length is less than or equal to the specified
|
|
7
|
+
* value. This tag enforces an upper limit on the number of characters in a
|
|
8
|
+
* string.
|
|
9
|
+
*
|
|
10
|
+
* Examples: type ShortComment = string & MaxLength<200>; // Comment limited to
|
|
11
|
+
* 200 characters type ZipCode = string & MaxLength<10>; // Zip code with max 10
|
|
12
|
+
* characters
|
|
13
|
+
*
|
|
14
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
15
|
+
*/
|
|
16
|
+
export type MaxLength<Value extends number> = TagBase<{
|
|
17
|
+
target: "string";
|
|
18
|
+
kind: "maxLength";
|
|
19
|
+
value: Value;
|
|
20
|
+
validate: `$input.length <= ${Value}`;
|
|
21
|
+
exclusive: true;
|
|
22
|
+
schema: {
|
|
23
|
+
maxLength: Value;
|
|
24
|
+
};
|
|
25
|
+
}>;
|
package/src/tags/Maximum.ts
CHANGED
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
import { TagBase } from "./TagBase";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Maximum value constraint tag.
|
|
5
|
-
*
|
|
6
|
-
* Enforces that a numeric value must be less than or equal to the specified
|
|
7
|
-
* maximum. This constraint validates that the input value satisfies: input <=
|
|
8
|
-
* maximum.
|
|
9
|
-
*
|
|
10
|
-
* Example usage:
|
|
11
|
-
*
|
|
12
|
-
* ```typescript
|
|
13
|
-
* type Percentage = number & tags.Maximum<100>; // Must be <= 100
|
|
14
|
-
* type SmallInt = bigint & tags.Maximum<255n>; // BigInt must be <= 255
|
|
15
|
-
* ```
|
|
16
|
-
*
|
|
17
|
-
* Note: This tag is mutually exclusive with ExclusiveMaximum. You cannot apply
|
|
18
|
-
* both Maximum and ExclusiveMaximum constraints to the same property.
|
|
19
|
-
*
|
|
20
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
21
|
-
* @template Value - The maximum value constraint (number or bigint literal)
|
|
22
|
-
*/
|
|
23
|
-
export type Maximum<Value extends number | bigint> = TagBase<{
|
|
24
|
-
target: Value extends bigint ? "bigint" : "number";
|
|
25
|
-
kind: "maximum";
|
|
26
|
-
value: Value;
|
|
27
|
-
validate: `$input <= ${Cast<Value>}`;
|
|
28
|
-
exclusive: ["maximum", "exclusiveMaximum"];
|
|
29
|
-
schema: Value extends bigint
|
|
30
|
-
? { maximum: Numeric<Value> }
|
|
31
|
-
: { maximum: Value };
|
|
32
|
-
}>;
|
|
33
|
-
|
|
34
|
-
type Cast<Value extends number | bigint> = Value extends number
|
|
35
|
-
? Value
|
|
36
|
-
: `BigInt(${Value})`;
|
|
37
|
-
type Numeric<T extends bigint> = `${T}` extends `${infer N extends number}`
|
|
38
|
-
? N
|
|
39
|
-
: never;
|
|
1
|
+
import { TagBase } from "./TagBase";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Maximum value constraint tag.
|
|
5
|
+
*
|
|
6
|
+
* Enforces that a numeric value must be less than or equal to the specified
|
|
7
|
+
* maximum. This constraint validates that the input value satisfies: input <=
|
|
8
|
+
* maximum.
|
|
9
|
+
*
|
|
10
|
+
* Example usage:
|
|
11
|
+
*
|
|
12
|
+
* ```typescript
|
|
13
|
+
* type Percentage = number & tags.Maximum<100>; // Must be <= 100
|
|
14
|
+
* type SmallInt = bigint & tags.Maximum<255n>; // BigInt must be <= 255
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* Note: This tag is mutually exclusive with ExclusiveMaximum. You cannot apply
|
|
18
|
+
* both Maximum and ExclusiveMaximum constraints to the same property.
|
|
19
|
+
*
|
|
20
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
21
|
+
* @template Value - The maximum value constraint (number or bigint literal)
|
|
22
|
+
*/
|
|
23
|
+
export type Maximum<Value extends number | bigint> = TagBase<{
|
|
24
|
+
target: Value extends bigint ? "bigint" : "number";
|
|
25
|
+
kind: "maximum";
|
|
26
|
+
value: Value;
|
|
27
|
+
validate: `$input <= ${Cast<Value>}`;
|
|
28
|
+
exclusive: ["maximum", "exclusiveMaximum"];
|
|
29
|
+
schema: Value extends bigint
|
|
30
|
+
? { maximum: Numeric<Value> }
|
|
31
|
+
: { maximum: Value };
|
|
32
|
+
}>;
|
|
33
|
+
|
|
34
|
+
type Cast<Value extends number | bigint> = Value extends number
|
|
35
|
+
? Value
|
|
36
|
+
: `BigInt(${Value})`;
|
|
37
|
+
type Numeric<T extends bigint> = `${T}` extends `${infer N extends number}`
|
|
38
|
+
? N
|
|
39
|
+
: never;
|
package/src/tags/MinItems.ts
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
import { TagBase } from "./TagBase";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Minimum items validation tag for arrays.
|
|
5
|
-
*
|
|
6
|
-
* Enforces that an array contains at least the specified number of items. This
|
|
7
|
-
* tag is useful for ensuring arrays have a minimum length requirement, such as
|
|
8
|
-
* requiring at least one item in a list or a minimum number of selections in a
|
|
9
|
-
* multi-choice field.
|
|
10
|
-
*
|
|
11
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
12
|
-
* @example
|
|
13
|
-
* // Require at least 1 item in the array
|
|
14
|
-
* type Tags = string[] & MinItems<1>;
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* // Require at least 3 selections
|
|
18
|
-
* type MultipleChoice = number[] & MinItems<3>;
|
|
19
|
-
*
|
|
20
|
-
* @template Value - The minimum number of items required
|
|
21
|
-
*/
|
|
22
|
-
export type MinItems<Value extends number> = TagBase<{
|
|
23
|
-
target: "array";
|
|
24
|
-
kind: "minItems";
|
|
25
|
-
value: Value;
|
|
26
|
-
validate: `${Value} <= $input.length`;
|
|
27
|
-
exclusive: true;
|
|
28
|
-
schema: {
|
|
29
|
-
minItems: Value;
|
|
30
|
-
};
|
|
31
|
-
}>;
|
|
1
|
+
import { TagBase } from "./TagBase";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Minimum items validation tag for arrays.
|
|
5
|
+
*
|
|
6
|
+
* Enforces that an array contains at least the specified number of items. This
|
|
7
|
+
* tag is useful for ensuring arrays have a minimum length requirement, such as
|
|
8
|
+
* requiring at least one item in a list or a minimum number of selections in a
|
|
9
|
+
* multi-choice field.
|
|
10
|
+
*
|
|
11
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
12
|
+
* @example
|
|
13
|
+
* // Require at least 1 item in the array
|
|
14
|
+
* type Tags = string[] & MinItems<1>;
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* // Require at least 3 selections
|
|
18
|
+
* type MultipleChoice = number[] & MinItems<3>;
|
|
19
|
+
*
|
|
20
|
+
* @template Value - The minimum number of items required
|
|
21
|
+
*/
|
|
22
|
+
export type MinItems<Value extends number> = TagBase<{
|
|
23
|
+
target: "array";
|
|
24
|
+
kind: "minItems";
|
|
25
|
+
value: Value;
|
|
26
|
+
validate: `${Value} <= $input.length`;
|
|
27
|
+
exclusive: true;
|
|
28
|
+
schema: {
|
|
29
|
+
minItems: Value;
|
|
30
|
+
};
|
|
31
|
+
}>;
|
package/src/tags/MinLength.ts
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import { TagBase } from "./TagBase";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* String minimum length constraint tag.
|
|
5
|
-
*
|
|
6
|
-
* Validates that a string's length is greater than or equal to the specified
|
|
7
|
-
* value. This tag ensures that string values meet a minimum character count
|
|
8
|
-
* requirement.
|
|
9
|
-
*
|
|
10
|
-
* Examples: type Username = string & MinLength<3>; // Username must be at least
|
|
11
|
-
* 3 characters type Password = string & MinLength<8>; // Password must be at
|
|
12
|
-
* least 8 characters
|
|
13
|
-
*
|
|
14
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
15
|
-
*/
|
|
16
|
-
export type MinLength<Value extends number> = TagBase<{
|
|
17
|
-
target: "string";
|
|
18
|
-
kind: "minLength";
|
|
19
|
-
value: Value;
|
|
20
|
-
validate: `${Value} <= $input.length`;
|
|
21
|
-
exclusive: true;
|
|
22
|
-
schema: {
|
|
23
|
-
minLength: Value;
|
|
24
|
-
};
|
|
25
|
-
}>;
|
|
1
|
+
import { TagBase } from "./TagBase";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* String minimum length constraint tag.
|
|
5
|
+
*
|
|
6
|
+
* Validates that a string's length is greater than or equal to the specified
|
|
7
|
+
* value. This tag ensures that string values meet a minimum character count
|
|
8
|
+
* requirement.
|
|
9
|
+
*
|
|
10
|
+
* Examples: type Username = string & MinLength<3>; // Username must be at least
|
|
11
|
+
* 3 characters type Password = string & MinLength<8>; // Password must be at
|
|
12
|
+
* least 8 characters
|
|
13
|
+
*
|
|
14
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
15
|
+
*/
|
|
16
|
+
export type MinLength<Value extends number> = TagBase<{
|
|
17
|
+
target: "string";
|
|
18
|
+
kind: "minLength";
|
|
19
|
+
value: Value;
|
|
20
|
+
validate: `${Value} <= $input.length`;
|
|
21
|
+
exclusive: true;
|
|
22
|
+
schema: {
|
|
23
|
+
minLength: Value;
|
|
24
|
+
};
|
|
25
|
+
}>;
|
package/src/tags/Minimum.ts
CHANGED
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
import { TagBase } from "./TagBase";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Minimum value constraint tag.
|
|
5
|
-
*
|
|
6
|
-
* Enforces that a numeric value must be greater than or equal to the specified
|
|
7
|
-
* minimum. This constraint validates that the input value satisfies: input >=
|
|
8
|
-
* minimum.
|
|
9
|
-
*
|
|
10
|
-
* Example usage:
|
|
11
|
-
*
|
|
12
|
-
* ```typescript
|
|
13
|
-
* type Age = number & tags.Minimum<0>; // Age must be 0 or greater
|
|
14
|
-
* type Balance = bigint & tags.Minimum<0n>; // BigInt balance must be non-negative
|
|
15
|
-
* ```
|
|
16
|
-
*
|
|
17
|
-
* Note: This tag is mutually exclusive with ExclusiveMinimum. You cannot apply
|
|
18
|
-
* both Minimum and ExclusiveMinimum constraints to the same property.
|
|
19
|
-
*
|
|
20
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
21
|
-
* @template Value - The minimum value constraint (number or bigint literal)
|
|
22
|
-
*/
|
|
23
|
-
export type Minimum<Value extends number | bigint> = TagBase<{
|
|
24
|
-
target: Value extends bigint ? "bigint" : "number";
|
|
25
|
-
kind: "minimum";
|
|
26
|
-
value: Value;
|
|
27
|
-
validate: `${Cast<Value>} <= $input`;
|
|
28
|
-
exclusive: ["minimum", "exclusiveMinimum"];
|
|
29
|
-
schema: Value extends bigint
|
|
30
|
-
? { minimum: Numeric<Value> }
|
|
31
|
-
: { minimum: Value };
|
|
32
|
-
}>;
|
|
33
|
-
|
|
34
|
-
type Cast<Value extends number | bigint> = Value extends number
|
|
35
|
-
? Value
|
|
36
|
-
: `BigInt(${Value})`;
|
|
37
|
-
type Numeric<T extends bigint> = `${T}` extends `${infer N extends number}`
|
|
38
|
-
? N
|
|
39
|
-
: never;
|
|
1
|
+
import { TagBase } from "./TagBase";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Minimum value constraint tag.
|
|
5
|
+
*
|
|
6
|
+
* Enforces that a numeric value must be greater than or equal to the specified
|
|
7
|
+
* minimum. This constraint validates that the input value satisfies: input >=
|
|
8
|
+
* minimum.
|
|
9
|
+
*
|
|
10
|
+
* Example usage:
|
|
11
|
+
*
|
|
12
|
+
* ```typescript
|
|
13
|
+
* type Age = number & tags.Minimum<0>; // Age must be 0 or greater
|
|
14
|
+
* type Balance = bigint & tags.Minimum<0n>; // BigInt balance must be non-negative
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* Note: This tag is mutually exclusive with ExclusiveMinimum. You cannot apply
|
|
18
|
+
* both Minimum and ExclusiveMinimum constraints to the same property.
|
|
19
|
+
*
|
|
20
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
21
|
+
* @template Value - The minimum value constraint (number or bigint literal)
|
|
22
|
+
*/
|
|
23
|
+
export type Minimum<Value extends number | bigint> = TagBase<{
|
|
24
|
+
target: Value extends bigint ? "bigint" : "number";
|
|
25
|
+
kind: "minimum";
|
|
26
|
+
value: Value;
|
|
27
|
+
validate: `${Cast<Value>} <= $input`;
|
|
28
|
+
exclusive: ["minimum", "exclusiveMinimum"];
|
|
29
|
+
schema: Value extends bigint
|
|
30
|
+
? { minimum: Numeric<Value> }
|
|
31
|
+
: { minimum: Value };
|
|
32
|
+
}>;
|
|
33
|
+
|
|
34
|
+
type Cast<Value extends number | bigint> = Value extends number
|
|
35
|
+
? Value
|
|
36
|
+
: `BigInt(${Value})`;
|
|
37
|
+
type Numeric<T extends bigint> = `${T}` extends `${infer N extends number}`
|
|
38
|
+
? N
|
|
39
|
+
: never;
|
package/src/tags/MultipleOf.ts
CHANGED
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
import { TagBase } from "./TagBase";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Multiple of constraint tag.
|
|
5
|
-
*
|
|
6
|
-
* Enforces that a numeric value must be an exact multiple of the specified
|
|
7
|
-
* divisor. This constraint validates that the input value satisfies: input %
|
|
8
|
-
* divisor === 0.
|
|
9
|
-
*
|
|
10
|
-
* Example usage:
|
|
11
|
-
*
|
|
12
|
-
* ```typescript
|
|
13
|
-
* type EvenNumber = number & tags.MultipleOf<2>; // Must be even (2, 4, 6, ...)
|
|
14
|
-
* type DollarAmount = number & tags.MultipleOf<0.01>; // Must be in cents
|
|
15
|
-
* ```
|
|
16
|
-
*
|
|
17
|
-
* Common use cases include validating even/odd numbers, currency amounts, time
|
|
18
|
-
* intervals, or any value that must align to specific increments.
|
|
19
|
-
*
|
|
20
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
21
|
-
* @template Value - The divisor value that input must be a multiple of (number
|
|
22
|
-
* or bigint literal)
|
|
23
|
-
*/
|
|
24
|
-
export type MultipleOf<Value extends number | bigint> = TagBase<{
|
|
25
|
-
target: Value extends bigint ? "bigint" : "number";
|
|
26
|
-
kind: "multipleOf";
|
|
27
|
-
value: Value;
|
|
28
|
-
validate: `$input % ${Cast<Value>} === ${Value extends bigint
|
|
29
|
-
? Cast<0n>
|
|
30
|
-
: 0}`;
|
|
31
|
-
exclusive: true;
|
|
32
|
-
schema: Value extends bigint
|
|
33
|
-
? { multipleOf: Numeric<Value> }
|
|
34
|
-
: { multipleOf: Value };
|
|
35
|
-
}>;
|
|
36
|
-
|
|
37
|
-
type Cast<Value extends number | bigint> = Value extends number
|
|
38
|
-
? Value
|
|
39
|
-
: `BigInt(${Value})`;
|
|
40
|
-
type Numeric<T extends bigint> = `${T}` extends `${infer N extends number}`
|
|
41
|
-
? N
|
|
42
|
-
: never;
|
|
1
|
+
import { TagBase } from "./TagBase";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Multiple of constraint tag.
|
|
5
|
+
*
|
|
6
|
+
* Enforces that a numeric value must be an exact multiple of the specified
|
|
7
|
+
* divisor. This constraint validates that the input value satisfies: input %
|
|
8
|
+
* divisor === 0.
|
|
9
|
+
*
|
|
10
|
+
* Example usage:
|
|
11
|
+
*
|
|
12
|
+
* ```typescript
|
|
13
|
+
* type EvenNumber = number & tags.MultipleOf<2>; // Must be even (2, 4, 6, ...)
|
|
14
|
+
* type DollarAmount = number & tags.MultipleOf<0.01>; // Must be in cents
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* Common use cases include validating even/odd numbers, currency amounts, time
|
|
18
|
+
* intervals, or any value that must align to specific increments.
|
|
19
|
+
*
|
|
20
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
21
|
+
* @template Value - The divisor value that input must be a multiple of (number
|
|
22
|
+
* or bigint literal)
|
|
23
|
+
*/
|
|
24
|
+
export type MultipleOf<Value extends number | bigint> = TagBase<{
|
|
25
|
+
target: Value extends bigint ? "bigint" : "number";
|
|
26
|
+
kind: "multipleOf";
|
|
27
|
+
value: Value;
|
|
28
|
+
validate: `$input % ${Cast<Value>} === ${Value extends bigint
|
|
29
|
+
? Cast<0n>
|
|
30
|
+
: 0}`;
|
|
31
|
+
exclusive: true;
|
|
32
|
+
schema: Value extends bigint
|
|
33
|
+
? { multipleOf: Numeric<Value> }
|
|
34
|
+
: { multipleOf: Value };
|
|
35
|
+
}>;
|
|
36
|
+
|
|
37
|
+
type Cast<Value extends number | bigint> = Value extends number
|
|
38
|
+
? Value
|
|
39
|
+
: `BigInt(${Value})`;
|
|
40
|
+
type Numeric<T extends bigint> = `${T}` extends `${infer N extends number}`
|
|
41
|
+
? N
|
|
42
|
+
: never;
|
package/src/tags/Pattern.ts
CHANGED
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
import { TagBase } from "./TagBase";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* String pattern (regular expression) constraint tag.
|
|
5
|
-
*
|
|
6
|
-
* Validates that a string matches a specified regular expression pattern. Use
|
|
7
|
-
* this tag to enforce custom string formats through regex validation.
|
|
8
|
-
*
|
|
9
|
-
* Examples:
|
|
10
|
-
*
|
|
11
|
-
* ```ts
|
|
12
|
-
* type PhoneNumber = string & Pattern<"^\d{3}-\d{3}-\d{4}$">; // 123-456-7890
|
|
13
|
-
* type HexColor = string & Pattern<"^#[0-9A-Fa-f]{6}$">; // #FF5733
|
|
14
|
-
* ```
|
|
15
|
-
*
|
|
16
|
-
* Note: This tag is mutually exclusive with the Format tag. You cannot use both
|
|
17
|
-
* Pattern and Format on the same type.
|
|
18
|
-
*
|
|
19
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
20
|
-
*/
|
|
21
|
-
export type Pattern<Value extends string> = TagBase<{
|
|
22
|
-
target: "string";
|
|
23
|
-
kind: "pattern";
|
|
24
|
-
value: Value;
|
|
25
|
-
validate: `RegExp("${Serialize<Value>}").test($input)`;
|
|
26
|
-
exclusive: ["format", "pattern"];
|
|
27
|
-
schema: {
|
|
28
|
-
pattern: Value;
|
|
29
|
-
};
|
|
30
|
-
}>;
|
|
31
|
-
|
|
32
|
-
/// reference: https://github.com/type-challenges/type-challenges/issues/22394#issuecomment-1397158205
|
|
33
|
-
type Serialize<T extends string, Output extends string = ""> = string extends T
|
|
34
|
-
? never
|
|
35
|
-
: T extends ""
|
|
36
|
-
? Output
|
|
37
|
-
: T extends `${infer P}${infer R}`
|
|
38
|
-
? Serialize<R, `${Output}${P extends keyof Escaper ? Escaper[P] : P}`>
|
|
39
|
-
: never;
|
|
40
|
-
|
|
41
|
-
type Escaper = {
|
|
42
|
-
'"': '\\"';
|
|
43
|
-
"\\": "\\\\";
|
|
44
|
-
"\b": "\\b";
|
|
45
|
-
"\f": "\\f";
|
|
46
|
-
"\n": "\\n";
|
|
47
|
-
"\r": "\\r";
|
|
48
|
-
"\t": "\\t";
|
|
49
|
-
};
|
|
1
|
+
import { TagBase } from "./TagBase";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* String pattern (regular expression) constraint tag.
|
|
5
|
+
*
|
|
6
|
+
* Validates that a string matches a specified regular expression pattern. Use
|
|
7
|
+
* this tag to enforce custom string formats through regex validation.
|
|
8
|
+
*
|
|
9
|
+
* Examples:
|
|
10
|
+
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* type PhoneNumber = string & Pattern<"^\d{3}-\d{3}-\d{4}$">; // 123-456-7890
|
|
13
|
+
* type HexColor = string & Pattern<"^#[0-9A-Fa-f]{6}$">; // #FF5733
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* Note: This tag is mutually exclusive with the Format tag. You cannot use both
|
|
17
|
+
* Pattern and Format on the same type.
|
|
18
|
+
*
|
|
19
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
20
|
+
*/
|
|
21
|
+
export type Pattern<Value extends string> = TagBase<{
|
|
22
|
+
target: "string";
|
|
23
|
+
kind: "pattern";
|
|
24
|
+
value: Value;
|
|
25
|
+
validate: `RegExp("${Serialize<Value>}").test($input)`;
|
|
26
|
+
exclusive: ["format", "pattern"];
|
|
27
|
+
schema: {
|
|
28
|
+
pattern: Value;
|
|
29
|
+
};
|
|
30
|
+
}>;
|
|
31
|
+
|
|
32
|
+
/// reference: https://github.com/type-challenges/type-challenges/issues/22394#issuecomment-1397158205
|
|
33
|
+
type Serialize<T extends string, Output extends string = ""> = string extends T
|
|
34
|
+
? never
|
|
35
|
+
: T extends ""
|
|
36
|
+
? Output
|
|
37
|
+
: T extends `${infer P}${infer R}`
|
|
38
|
+
? Serialize<R, `${Output}${P extends keyof Escaper ? Escaper[P] : P}`>
|
|
39
|
+
: never;
|
|
40
|
+
|
|
41
|
+
type Escaper = {
|
|
42
|
+
'"': '\\"';
|
|
43
|
+
"\\": "\\\\";
|
|
44
|
+
"\b": "\\b";
|
|
45
|
+
"\f": "\\f";
|
|
46
|
+
"\n": "\\n";
|
|
47
|
+
"\r": "\\r";
|
|
48
|
+
"\t": "\\t";
|
|
49
|
+
};
|
package/src/tags/Sequence.ts
CHANGED
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
import { TagBase } from "./TagBase";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Assigns unique field numbers for Protocol Buffer serialization.
|
|
5
|
-
*
|
|
6
|
-
* In Protocol Buffer encoding, each field in a message must have a unique
|
|
7
|
-
* numeric identifier. The Sequence tag assigns these field numbers to
|
|
8
|
-
* TypeScript properties, enabling proper Protocol Buffer serialization and
|
|
9
|
-
* deserialization. Field numbers 1-15 require only one byte to encode, making
|
|
10
|
-
* them ideal for frequently used fields. Numbers 19000-19999 are reserved by
|
|
11
|
-
* the Protocol Buffer specification and should not be used.
|
|
12
|
-
*
|
|
13
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
14
|
-
* @example
|
|
15
|
-
* ```typescript
|
|
16
|
-
* interface User {
|
|
17
|
-
* id: string & Sequence<1>; // Most frequent field uses 1
|
|
18
|
-
* email: string & Sequence<2>; // Common fields use low numbers
|
|
19
|
-
* createdAt: number & Sequence<3>;
|
|
20
|
-
* metadata?: object & Sequence<10>; // Optional fields work too
|
|
21
|
-
* }
|
|
22
|
-
*
|
|
23
|
-
* // Generate Protocol Buffer message
|
|
24
|
-
* const message = typia.protobuf.message<User>();
|
|
25
|
-
* ```
|
|
26
|
-
*
|
|
27
|
-
* @template N - Field number (positive integer from 1 to 536,870,911, excluding
|
|
28
|
-
* 19000-19999)
|
|
29
|
-
*/
|
|
30
|
-
export type Sequence<N extends number> = TagBase<{
|
|
31
|
-
target: "boolean" | "bigint" | "number" | "string" | "array" | "object";
|
|
32
|
-
kind: "sequence";
|
|
33
|
-
value: N;
|
|
34
|
-
schema: {
|
|
35
|
-
"x-protobuf-sequence": N;
|
|
36
|
-
};
|
|
37
|
-
}>;
|
|
1
|
+
import { TagBase } from "./TagBase";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Assigns unique field numbers for Protocol Buffer serialization.
|
|
5
|
+
*
|
|
6
|
+
* In Protocol Buffer encoding, each field in a message must have a unique
|
|
7
|
+
* numeric identifier. The Sequence tag assigns these field numbers to
|
|
8
|
+
* TypeScript properties, enabling proper Protocol Buffer serialization and
|
|
9
|
+
* deserialization. Field numbers 1-15 require only one byte to encode, making
|
|
10
|
+
* them ideal for frequently used fields. Numbers 19000-19999 are reserved by
|
|
11
|
+
* the Protocol Buffer specification and should not be used.
|
|
12
|
+
*
|
|
13
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* interface User {
|
|
17
|
+
* id: string & Sequence<1>; // Most frequent field uses 1
|
|
18
|
+
* email: string & Sequence<2>; // Common fields use low numbers
|
|
19
|
+
* createdAt: number & Sequence<3>;
|
|
20
|
+
* metadata?: object & Sequence<10>; // Optional fields work too
|
|
21
|
+
* }
|
|
22
|
+
*
|
|
23
|
+
* // Generate Protocol Buffer message
|
|
24
|
+
* const message = typia.protobuf.message<User>();
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @template N - Field number (positive integer from 1 to 536,870,911, excluding
|
|
28
|
+
* 19000-19999)
|
|
29
|
+
*/
|
|
30
|
+
export type Sequence<N extends number> = TagBase<{
|
|
31
|
+
target: "boolean" | "bigint" | "number" | "string" | "array" | "object";
|
|
32
|
+
kind: "sequence";
|
|
33
|
+
value: N;
|
|
34
|
+
schema: {
|
|
35
|
+
"x-protobuf-sequence": N;
|
|
36
|
+
};
|
|
37
|
+
}>;
|