typia 9.7.0 → 9.7.1
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/lib/programmers/json/JsonStringifyProgrammer.js +2 -2
- package/lib/programmers/json/JsonStringifyProgrammer.js.map +1 -1
- package/lib/programmers/json/JsonStringifyProgrammer.mjs +2 -2
- package/lib/tags/Constant.d.mts +32 -0
- package/lib/tags/Constant.d.ts +32 -0
- package/lib/tags/ContentMediaType.d.mts +17 -0
- package/lib/tags/ContentMediaType.d.ts +17 -0
- package/lib/tags/Default.d.mts +30 -0
- package/lib/tags/Default.d.ts +30 -0
- package/lib/tags/Example.d.mts +32 -0
- package/lib/tags/Example.d.ts +32 -0
- package/lib/tags/Examples.d.mts +40 -0
- package/lib/tags/Examples.d.ts +40 -0
- package/lib/tags/ExclusiveMaximum.d.mts +18 -0
- package/lib/tags/ExclusiveMaximum.d.ts +18 -0
- package/lib/tags/ExclusiveMinimum.d.mts +18 -0
- package/lib/tags/ExclusiveMinimum.d.ts +18 -0
- package/lib/tags/Format.d.mts +24 -0
- package/lib/tags/Format.d.ts +24 -0
- package/lib/tags/JsonSchemaPlugin.d.mts +26 -0
- package/lib/tags/JsonSchemaPlugin.d.ts +26 -0
- package/lib/tags/MaxItems.d.mts +19 -0
- package/lib/tags/MaxItems.d.ts +19 -0
- package/lib/tags/MaxLength.d.mts +12 -0
- package/lib/tags/MaxLength.d.ts +12 -0
- package/lib/tags/Maximum.d.mts +18 -0
- package/lib/tags/Maximum.d.ts +18 -0
- package/lib/tags/MinItems.d.mts +19 -0
- package/lib/tags/MinItems.d.ts +19 -0
- package/lib/tags/MinLength.d.mts +12 -0
- package/lib/tags/MinLength.d.ts +12 -0
- package/lib/tags/Minimum.d.mts +18 -0
- package/lib/tags/Minimum.d.ts +18 -0
- package/lib/tags/MultipleOf.d.mts +18 -0
- package/lib/tags/MultipleOf.d.ts +18 -0
- package/lib/tags/Pattern.d.mts +15 -0
- package/lib/tags/Pattern.d.ts +15 -0
- package/lib/tags/Sequence.d.mts +25 -0
- package/lib/tags/Sequence.d.ts +25 -0
- package/lib/tags/TagBase.d.mts +27 -0
- package/lib/tags/TagBase.d.ts +27 -0
- package/lib/tags/Type.d.mts +26 -0
- package/lib/tags/Type.d.ts +26 -0
- package/lib/tags/UniqueItems.d.mts +19 -0
- package/lib/tags/UniqueItems.d.ts +19 -0
- package/lib/transformers/ImportTransformer.js +119 -1
- package/lib/transformers/ImportTransformer.js.map +1 -1
- package/lib/transformers/ImportTransformer.mjs +119 -1
- package/package.json +1 -1
- package/src/IRandomGenerator.ts +13 -5
- package/src/programmers/json/JsonStringifyProgrammer.ts +2 -2
- package/src/tags/Constant.ts +32 -0
- package/src/tags/ContentMediaType.ts +17 -0
- package/src/tags/Default.ts +30 -0
- package/src/tags/Example.ts +32 -0
- package/src/tags/Examples.ts +40 -0
- package/src/tags/ExclusiveMaximum.ts +18 -0
- package/src/tags/ExclusiveMinimum.ts +18 -0
- package/src/tags/Format.ts +24 -0
- package/src/tags/JsonSchemaPlugin.ts +26 -0
- package/src/tags/MaxItems.ts +19 -0
- package/src/tags/MaxLength.ts +12 -0
- package/src/tags/Maximum.ts +18 -0
- package/src/tags/MinItems.ts +19 -0
- package/src/tags/MinLength.ts +12 -0
- package/src/tags/Minimum.ts +18 -0
- package/src/tags/MultipleOf.ts +18 -0
- package/src/tags/Pattern.ts +15 -0
- package/src/tags/Sequence.ts +25 -0
- package/src/tags/TagBase.ts +27 -0
- package/src/tags/Type.ts +26 -0
- package/src/tags/UniqueItems.ts +19 -0
- package/src/transformers/ImportTransformer.ts +178 -1
package/lib/tags/Format.d.ts
CHANGED
|
@@ -1,4 +1,28 @@
|
|
|
1
1
|
import type { TagBase } from "./TagBase";
|
|
2
|
+
/**
|
|
3
|
+
* String format constraint tag.
|
|
4
|
+
*
|
|
5
|
+
* Validates strings against predefined formats for common use cases.
|
|
6
|
+
* This tag provides built-in validation for standard string formats without
|
|
7
|
+
* needing to write custom regular expressions.
|
|
8
|
+
*
|
|
9
|
+
* Examples:
|
|
10
|
+
* type Email = string & Format<"email">; // user@example.com
|
|
11
|
+
* type WebURL = string & Format<"url">; // https://example.com
|
|
12
|
+
* type DateTime = string & Format<"date-time">; // 2024-01-15T10:30:00Z
|
|
13
|
+
*
|
|
14
|
+
* Supported formats include:
|
|
15
|
+
* - Network: email, url, hostname, ipv4, ipv6, uri
|
|
16
|
+
* - Identifiers: uuid, byte, password
|
|
17
|
+
* - Date/Time: date, time, date-time, duration
|
|
18
|
+
* - Data: json-pointer, regex
|
|
19
|
+
* - Internationalized: idn-email, idn-hostname, iri
|
|
20
|
+
*
|
|
21
|
+
* Note: This tag is mutually exclusive with the Pattern tag. You cannot use both
|
|
22
|
+
* Format and Pattern on the same type.
|
|
23
|
+
*
|
|
24
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
25
|
+
*/
|
|
2
26
|
export type Format<Value extends Format.Value> = TagBase<{
|
|
3
27
|
target: "string";
|
|
4
28
|
kind: "format";
|
|
@@ -1,4 +1,30 @@
|
|
|
1
1
|
import { TagBase } from "./TagBase";
|
|
2
|
+
/**
|
|
3
|
+
* Injects custom properties into generated JSON Schema.
|
|
4
|
+
*
|
|
5
|
+
* The JsonSchemaPlugin tag allows you to add vendor-specific extensions or custom metadata
|
|
6
|
+
* to the generated JSON Schema output. These properties are merged at the root level of
|
|
7
|
+
* the schema and are commonly used for documentation, tooling hints, or API-specific metadata.
|
|
8
|
+
* The custom properties only affect schema generation and do not impact runtime validation.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* // Add OpenAPI vendor extensions
|
|
13
|
+
* type UserId = string & JsonSchemaPlugin<{
|
|
14
|
+
* "x-internal-id": true,
|
|
15
|
+
* "x-deprecated": "Use UUID instead"
|
|
16
|
+
* }>;
|
|
17
|
+
*
|
|
18
|
+
* // Add custom documentation metadata
|
|
19
|
+
* type Price = number & JsonSchemaPlugin<{
|
|
20
|
+
* "x-format": "currency",
|
|
21
|
+
* "x-example": 19.99
|
|
22
|
+
* }>;
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @template Schema - Object containing custom properties to add to the JSON Schema
|
|
26
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
27
|
+
*/
|
|
2
28
|
export type JsonSchemaPlugin<Schema extends object> = TagBase<{
|
|
3
29
|
target: "string" | "boolean" | "bigint" | "number" | "array" | "object";
|
|
4
30
|
kind: "jsonPlugin";
|
|
@@ -1,4 +1,30 @@
|
|
|
1
1
|
import { TagBase } from "./TagBase";
|
|
2
|
+
/**
|
|
3
|
+
* Injects custom properties into generated JSON Schema.
|
|
4
|
+
*
|
|
5
|
+
* The JsonSchemaPlugin tag allows you to add vendor-specific extensions or custom metadata
|
|
6
|
+
* to the generated JSON Schema output. These properties are merged at the root level of
|
|
7
|
+
* the schema and are commonly used for documentation, tooling hints, or API-specific metadata.
|
|
8
|
+
* The custom properties only affect schema generation and do not impact runtime validation.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* // Add OpenAPI vendor extensions
|
|
13
|
+
* type UserId = string & JsonSchemaPlugin<{
|
|
14
|
+
* "x-internal-id": true,
|
|
15
|
+
* "x-deprecated": "Use UUID instead"
|
|
16
|
+
* }>;
|
|
17
|
+
*
|
|
18
|
+
* // Add custom documentation metadata
|
|
19
|
+
* type Price = number & JsonSchemaPlugin<{
|
|
20
|
+
* "x-format": "currency",
|
|
21
|
+
* "x-example": 19.99
|
|
22
|
+
* }>;
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @template Schema - Object containing custom properties to add to the JSON Schema
|
|
26
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
27
|
+
*/
|
|
2
28
|
export type JsonSchemaPlugin<Schema extends object> = TagBase<{
|
|
3
29
|
target: "string" | "boolean" | "bigint" | "number" | "array" | "object";
|
|
4
30
|
kind: "jsonPlugin";
|
package/lib/tags/MaxItems.d.mts
CHANGED
|
@@ -1,4 +1,23 @@
|
|
|
1
1
|
import { TagBase } from "./TagBase";
|
|
2
|
+
/**
|
|
3
|
+
* Maximum items validation tag for arrays.
|
|
4
|
+
*
|
|
5
|
+
* Enforces that an array contains at most the specified number of items.
|
|
6
|
+
* This tag is useful for limiting array sizes, such as restricting the
|
|
7
|
+
* number of uploaded files, limiting selections in a form, or capping
|
|
8
|
+
* the size of collections to prevent performance issues.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* // Allow maximum 5 file uploads
|
|
12
|
+
* type FileList = File[] & MaxItems<5>;
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* // Limit tags to 10 items
|
|
16
|
+
* type ProductTags = string[] & MaxItems<10>;
|
|
17
|
+
*
|
|
18
|
+
* @template Value - The maximum number of items allowed
|
|
19
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
20
|
+
*/
|
|
2
21
|
export type MaxItems<Value extends number> = TagBase<{
|
|
3
22
|
target: "array";
|
|
4
23
|
kind: "maxItems";
|
package/lib/tags/MaxItems.d.ts
CHANGED
|
@@ -1,4 +1,23 @@
|
|
|
1
1
|
import { TagBase } from "./TagBase";
|
|
2
|
+
/**
|
|
3
|
+
* Maximum items validation tag for arrays.
|
|
4
|
+
*
|
|
5
|
+
* Enforces that an array contains at most the specified number of items.
|
|
6
|
+
* This tag is useful for limiting array sizes, such as restricting the
|
|
7
|
+
* number of uploaded files, limiting selections in a form, or capping
|
|
8
|
+
* the size of collections to prevent performance issues.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* // Allow maximum 5 file uploads
|
|
12
|
+
* type FileList = File[] & MaxItems<5>;
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* // Limit tags to 10 items
|
|
16
|
+
* type ProductTags = string[] & MaxItems<10>;
|
|
17
|
+
*
|
|
18
|
+
* @template Value - The maximum number of items allowed
|
|
19
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
20
|
+
*/
|
|
2
21
|
export type MaxItems<Value extends number> = TagBase<{
|
|
3
22
|
target: "array";
|
|
4
23
|
kind: "maxItems";
|
package/lib/tags/MaxLength.d.mts
CHANGED
|
@@ -1,4 +1,16 @@
|
|
|
1
1
|
import { TagBase } from "./TagBase";
|
|
2
|
+
/**
|
|
3
|
+
* String maximum length constraint tag.
|
|
4
|
+
*
|
|
5
|
+
* Validates that a string's length is less than or equal to the specified value.
|
|
6
|
+
* This tag enforces an upper limit on the number of characters in a string.
|
|
7
|
+
*
|
|
8
|
+
* Examples:
|
|
9
|
+
* type ShortComment = string & MaxLength<200>; // Comment limited to 200 characters
|
|
10
|
+
* type ZipCode = string & MaxLength<10>; // Zip code with max 10 characters
|
|
11
|
+
*
|
|
12
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
13
|
+
*/
|
|
2
14
|
export type MaxLength<Value extends number> = TagBase<{
|
|
3
15
|
target: "string";
|
|
4
16
|
kind: "maxLength";
|
package/lib/tags/MaxLength.d.ts
CHANGED
|
@@ -1,4 +1,16 @@
|
|
|
1
1
|
import { TagBase } from "./TagBase";
|
|
2
|
+
/**
|
|
3
|
+
* String maximum length constraint tag.
|
|
4
|
+
*
|
|
5
|
+
* Validates that a string's length is less than or equal to the specified value.
|
|
6
|
+
* This tag enforces an upper limit on the number of characters in a string.
|
|
7
|
+
*
|
|
8
|
+
* Examples:
|
|
9
|
+
* type ShortComment = string & MaxLength<200>; // Comment limited to 200 characters
|
|
10
|
+
* type ZipCode = string & MaxLength<10>; // Zip code with max 10 characters
|
|
11
|
+
*
|
|
12
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
13
|
+
*/
|
|
2
14
|
export type MaxLength<Value extends number> = TagBase<{
|
|
3
15
|
target: "string";
|
|
4
16
|
kind: "maxLength";
|
package/lib/tags/Maximum.d.mts
CHANGED
|
@@ -1,4 +1,22 @@
|
|
|
1
1
|
import { TagBase } from "./TagBase";
|
|
2
|
+
/**
|
|
3
|
+
* Maximum value constraint tag.
|
|
4
|
+
*
|
|
5
|
+
* Enforces that a numeric value must be less than or equal to the specified maximum.
|
|
6
|
+
* This constraint validates that the input value satisfies: input <= maximum.
|
|
7
|
+
*
|
|
8
|
+
* Example usage:
|
|
9
|
+
* ```typescript
|
|
10
|
+
* type Percentage = number & tags.Maximum<100>; // Must be <= 100
|
|
11
|
+
* type SmallInt = bigint & tags.Maximum<255n>; // BigInt must be <= 255
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* Note: This tag is mutually exclusive with ExclusiveMaximum. You cannot apply both
|
|
15
|
+
* Maximum and ExclusiveMaximum constraints to the same property.
|
|
16
|
+
*
|
|
17
|
+
* @template Value - The maximum value constraint (number or bigint literal)
|
|
18
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
19
|
+
*/
|
|
2
20
|
export type Maximum<Value extends number | bigint> = TagBase<{
|
|
3
21
|
target: Value extends bigint ? "bigint" : "number";
|
|
4
22
|
kind: "maximum";
|
package/lib/tags/Maximum.d.ts
CHANGED
|
@@ -1,4 +1,22 @@
|
|
|
1
1
|
import { TagBase } from "./TagBase";
|
|
2
|
+
/**
|
|
3
|
+
* Maximum value constraint tag.
|
|
4
|
+
*
|
|
5
|
+
* Enforces that a numeric value must be less than or equal to the specified maximum.
|
|
6
|
+
* This constraint validates that the input value satisfies: input <= maximum.
|
|
7
|
+
*
|
|
8
|
+
* Example usage:
|
|
9
|
+
* ```typescript
|
|
10
|
+
* type Percentage = number & tags.Maximum<100>; // Must be <= 100
|
|
11
|
+
* type SmallInt = bigint & tags.Maximum<255n>; // BigInt must be <= 255
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* Note: This tag is mutually exclusive with ExclusiveMaximum. You cannot apply both
|
|
15
|
+
* Maximum and ExclusiveMaximum constraints to the same property.
|
|
16
|
+
*
|
|
17
|
+
* @template Value - The maximum value constraint (number or bigint literal)
|
|
18
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
19
|
+
*/
|
|
2
20
|
export type Maximum<Value extends number | bigint> = TagBase<{
|
|
3
21
|
target: Value extends bigint ? "bigint" : "number";
|
|
4
22
|
kind: "maximum";
|
package/lib/tags/MinItems.d.mts
CHANGED
|
@@ -1,4 +1,23 @@
|
|
|
1
1
|
import { TagBase } from "./TagBase";
|
|
2
|
+
/**
|
|
3
|
+
* Minimum items validation tag for arrays.
|
|
4
|
+
*
|
|
5
|
+
* Enforces that an array contains at least the specified number of items.
|
|
6
|
+
* This tag is useful for ensuring arrays have a minimum length requirement,
|
|
7
|
+
* such as requiring at least one item in a list or a minimum number of
|
|
8
|
+
* selections in a multi-choice field.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* // Require at least 1 item in the array
|
|
12
|
+
* type Tags = string[] & MinItems<1>;
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* // Require at least 3 selections
|
|
16
|
+
* type MultipleChoice = number[] & MinItems<3>;
|
|
17
|
+
*
|
|
18
|
+
* @template Value - The minimum number of items required
|
|
19
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
20
|
+
*/
|
|
2
21
|
export type MinItems<Value extends number> = TagBase<{
|
|
3
22
|
target: "array";
|
|
4
23
|
kind: "minItems";
|
package/lib/tags/MinItems.d.ts
CHANGED
|
@@ -1,4 +1,23 @@
|
|
|
1
1
|
import { TagBase } from "./TagBase";
|
|
2
|
+
/**
|
|
3
|
+
* Minimum items validation tag for arrays.
|
|
4
|
+
*
|
|
5
|
+
* Enforces that an array contains at least the specified number of items.
|
|
6
|
+
* This tag is useful for ensuring arrays have a minimum length requirement,
|
|
7
|
+
* such as requiring at least one item in a list or a minimum number of
|
|
8
|
+
* selections in a multi-choice field.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* // Require at least 1 item in the array
|
|
12
|
+
* type Tags = string[] & MinItems<1>;
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* // Require at least 3 selections
|
|
16
|
+
* type MultipleChoice = number[] & MinItems<3>;
|
|
17
|
+
*
|
|
18
|
+
* @template Value - The minimum number of items required
|
|
19
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
20
|
+
*/
|
|
2
21
|
export type MinItems<Value extends number> = TagBase<{
|
|
3
22
|
target: "array";
|
|
4
23
|
kind: "minItems";
|
package/lib/tags/MinLength.d.mts
CHANGED
|
@@ -1,4 +1,16 @@
|
|
|
1
1
|
import { TagBase } from "./TagBase";
|
|
2
|
+
/**
|
|
3
|
+
* String minimum length constraint tag.
|
|
4
|
+
*
|
|
5
|
+
* Validates that a string's length is greater than or equal to the specified value.
|
|
6
|
+
* This tag ensures that string values meet a minimum character count requirement.
|
|
7
|
+
*
|
|
8
|
+
* Examples:
|
|
9
|
+
* type Username = string & MinLength<3>; // Username must be at least 3 characters
|
|
10
|
+
* type Password = string & MinLength<8>; // Password must be at least 8 characters
|
|
11
|
+
*
|
|
12
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
13
|
+
*/
|
|
2
14
|
export type MinLength<Value extends number> = TagBase<{
|
|
3
15
|
target: "string";
|
|
4
16
|
kind: "minLength";
|
package/lib/tags/MinLength.d.ts
CHANGED
|
@@ -1,4 +1,16 @@
|
|
|
1
1
|
import { TagBase } from "./TagBase";
|
|
2
|
+
/**
|
|
3
|
+
* String minimum length constraint tag.
|
|
4
|
+
*
|
|
5
|
+
* Validates that a string's length is greater than or equal to the specified value.
|
|
6
|
+
* This tag ensures that string values meet a minimum character count requirement.
|
|
7
|
+
*
|
|
8
|
+
* Examples:
|
|
9
|
+
* type Username = string & MinLength<3>; // Username must be at least 3 characters
|
|
10
|
+
* type Password = string & MinLength<8>; // Password must be at least 8 characters
|
|
11
|
+
*
|
|
12
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
13
|
+
*/
|
|
2
14
|
export type MinLength<Value extends number> = TagBase<{
|
|
3
15
|
target: "string";
|
|
4
16
|
kind: "minLength";
|
package/lib/tags/Minimum.d.mts
CHANGED
|
@@ -1,4 +1,22 @@
|
|
|
1
1
|
import { TagBase } from "./TagBase";
|
|
2
|
+
/**
|
|
3
|
+
* Minimum value constraint tag.
|
|
4
|
+
*
|
|
5
|
+
* Enforces that a numeric value must be greater than or equal to the specified minimum.
|
|
6
|
+
* This constraint validates that the input value satisfies: input >= minimum.
|
|
7
|
+
*
|
|
8
|
+
* Example usage:
|
|
9
|
+
* ```typescript
|
|
10
|
+
* type Age = number & tags.Minimum<0>; // Age must be 0 or greater
|
|
11
|
+
* type Balance = bigint & tags.Minimum<0n>; // BigInt balance must be non-negative
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* Note: This tag is mutually exclusive with ExclusiveMinimum. You cannot apply both
|
|
15
|
+
* Minimum and ExclusiveMinimum constraints to the same property.
|
|
16
|
+
*
|
|
17
|
+
* @template Value - The minimum value constraint (number or bigint literal)
|
|
18
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
19
|
+
*/
|
|
2
20
|
export type Minimum<Value extends number | bigint> = TagBase<{
|
|
3
21
|
target: Value extends bigint ? "bigint" : "number";
|
|
4
22
|
kind: "minimum";
|
package/lib/tags/Minimum.d.ts
CHANGED
|
@@ -1,4 +1,22 @@
|
|
|
1
1
|
import { TagBase } from "./TagBase";
|
|
2
|
+
/**
|
|
3
|
+
* Minimum value constraint tag.
|
|
4
|
+
*
|
|
5
|
+
* Enforces that a numeric value must be greater than or equal to the specified minimum.
|
|
6
|
+
* This constraint validates that the input value satisfies: input >= minimum.
|
|
7
|
+
*
|
|
8
|
+
* Example usage:
|
|
9
|
+
* ```typescript
|
|
10
|
+
* type Age = number & tags.Minimum<0>; // Age must be 0 or greater
|
|
11
|
+
* type Balance = bigint & tags.Minimum<0n>; // BigInt balance must be non-negative
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* Note: This tag is mutually exclusive with ExclusiveMinimum. You cannot apply both
|
|
15
|
+
* Minimum and ExclusiveMinimum constraints to the same property.
|
|
16
|
+
*
|
|
17
|
+
* @template Value - The minimum value constraint (number or bigint literal)
|
|
18
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
19
|
+
*/
|
|
2
20
|
export type Minimum<Value extends number | bigint> = TagBase<{
|
|
3
21
|
target: Value extends bigint ? "bigint" : "number";
|
|
4
22
|
kind: "minimum";
|
|
@@ -1,4 +1,22 @@
|
|
|
1
1
|
import { TagBase } from "./TagBase";
|
|
2
|
+
/**
|
|
3
|
+
* Multiple of constraint tag.
|
|
4
|
+
*
|
|
5
|
+
* Enforces that a numeric value must be an exact multiple of the specified divisor.
|
|
6
|
+
* This constraint validates that the input value satisfies: input % divisor === 0.
|
|
7
|
+
*
|
|
8
|
+
* Example usage:
|
|
9
|
+
* ```typescript
|
|
10
|
+
* type EvenNumber = number & tags.MultipleOf<2>; // Must be even (2, 4, 6, ...)
|
|
11
|
+
* type DollarAmount = number & tags.MultipleOf<0.01>; // Must be in cents
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* Common use cases include validating even/odd numbers, currency amounts,
|
|
15
|
+
* time intervals, or any value that must align to specific increments.
|
|
16
|
+
*
|
|
17
|
+
* @template Value - The divisor value that input must be a multiple of (number or bigint literal)
|
|
18
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
19
|
+
*/
|
|
2
20
|
export type MultipleOf<Value extends number | bigint> = TagBase<{
|
|
3
21
|
target: Value extends bigint ? "bigint" : "number";
|
|
4
22
|
kind: "multipleOf";
|
package/lib/tags/MultipleOf.d.ts
CHANGED
|
@@ -1,4 +1,22 @@
|
|
|
1
1
|
import { TagBase } from "./TagBase";
|
|
2
|
+
/**
|
|
3
|
+
* Multiple of constraint tag.
|
|
4
|
+
*
|
|
5
|
+
* Enforces that a numeric value must be an exact multiple of the specified divisor.
|
|
6
|
+
* This constraint validates that the input value satisfies: input % divisor === 0.
|
|
7
|
+
*
|
|
8
|
+
* Example usage:
|
|
9
|
+
* ```typescript
|
|
10
|
+
* type EvenNumber = number & tags.MultipleOf<2>; // Must be even (2, 4, 6, ...)
|
|
11
|
+
* type DollarAmount = number & tags.MultipleOf<0.01>; // Must be in cents
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* Common use cases include validating even/odd numbers, currency amounts,
|
|
15
|
+
* time intervals, or any value that must align to specific increments.
|
|
16
|
+
*
|
|
17
|
+
* @template Value - The divisor value that input must be a multiple of (number or bigint literal)
|
|
18
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
19
|
+
*/
|
|
2
20
|
export type MultipleOf<Value extends number | bigint> = TagBase<{
|
|
3
21
|
target: Value extends bigint ? "bigint" : "number";
|
|
4
22
|
kind: "multipleOf";
|
package/lib/tags/Pattern.d.mts
CHANGED
|
@@ -1,4 +1,19 @@
|
|
|
1
1
|
import { TagBase } from "./TagBase";
|
|
2
|
+
/**
|
|
3
|
+
* String pattern (regular expression) constraint tag.
|
|
4
|
+
*
|
|
5
|
+
* Validates that a string matches a specified regular expression pattern.
|
|
6
|
+
* Use this tag to enforce custom string formats through regex validation.
|
|
7
|
+
*
|
|
8
|
+
* Examples:
|
|
9
|
+
* type PhoneNumber = string & Pattern<"^\\d{3}-\\d{3}-\\d{4}$">; // 123-456-7890
|
|
10
|
+
* type HexColor = string & Pattern<"^#[0-9A-Fa-f]{6}$">; // #FF5733
|
|
11
|
+
*
|
|
12
|
+
* Note: This tag is mutually exclusive with the Format tag. You cannot use both
|
|
13
|
+
* Pattern and Format on the same type.
|
|
14
|
+
*
|
|
15
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
16
|
+
*/
|
|
2
17
|
export type Pattern<Value extends string> = TagBase<{
|
|
3
18
|
target: "string";
|
|
4
19
|
kind: "pattern";
|
package/lib/tags/Pattern.d.ts
CHANGED
|
@@ -1,4 +1,19 @@
|
|
|
1
1
|
import { TagBase } from "./TagBase";
|
|
2
|
+
/**
|
|
3
|
+
* String pattern (regular expression) constraint tag.
|
|
4
|
+
*
|
|
5
|
+
* Validates that a string matches a specified regular expression pattern.
|
|
6
|
+
* Use this tag to enforce custom string formats through regex validation.
|
|
7
|
+
*
|
|
8
|
+
* Examples:
|
|
9
|
+
* type PhoneNumber = string & Pattern<"^\\d{3}-\\d{3}-\\d{4}$">; // 123-456-7890
|
|
10
|
+
* type HexColor = string & Pattern<"^#[0-9A-Fa-f]{6}$">; // #FF5733
|
|
11
|
+
*
|
|
12
|
+
* Note: This tag is mutually exclusive with the Format tag. You cannot use both
|
|
13
|
+
* Pattern and Format on the same type.
|
|
14
|
+
*
|
|
15
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
16
|
+
*/
|
|
2
17
|
export type Pattern<Value extends string> = TagBase<{
|
|
3
18
|
target: "string";
|
|
4
19
|
kind: "pattern";
|
package/lib/tags/Sequence.d.mts
CHANGED
|
@@ -1,4 +1,29 @@
|
|
|
1
1
|
import { TagBase } from "./TagBase";
|
|
2
|
+
/**
|
|
3
|
+
* Assigns unique field numbers for Protocol Buffer serialization.
|
|
4
|
+
*
|
|
5
|
+
* In Protocol Buffer encoding, each field in a message must have a unique numeric identifier.
|
|
6
|
+
* The Sequence tag assigns these field numbers to TypeScript properties, enabling proper
|
|
7
|
+
* Protocol Buffer serialization and deserialization. Field numbers 1-15 require only one
|
|
8
|
+
* byte to encode, making them ideal for frequently used fields. Numbers 19000-19999 are
|
|
9
|
+
* reserved by the Protocol Buffer specification and should not be used.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* interface User {
|
|
14
|
+
* id: string & Sequence<1>; // Most frequent field uses 1
|
|
15
|
+
* email: string & Sequence<2>; // Common fields use low numbers
|
|
16
|
+
* createdAt: number & Sequence<3>;
|
|
17
|
+
* metadata?: object & Sequence<10>; // Optional fields work too
|
|
18
|
+
* }
|
|
19
|
+
*
|
|
20
|
+
* // Generate Protocol Buffer message
|
|
21
|
+
* const message = typia.protobuf.message<User>();
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @template N - Field number (positive integer from 1 to 536,870,911, excluding 19000-19999)
|
|
25
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
26
|
+
*/
|
|
2
27
|
export type Sequence<N extends number> = TagBase<{
|
|
3
28
|
target: "boolean" | "bigint" | "number" | "string" | "array" | "object";
|
|
4
29
|
kind: "sequence";
|
package/lib/tags/Sequence.d.ts
CHANGED
|
@@ -1,4 +1,29 @@
|
|
|
1
1
|
import { TagBase } from "./TagBase";
|
|
2
|
+
/**
|
|
3
|
+
* Assigns unique field numbers for Protocol Buffer serialization.
|
|
4
|
+
*
|
|
5
|
+
* In Protocol Buffer encoding, each field in a message must have a unique numeric identifier.
|
|
6
|
+
* The Sequence tag assigns these field numbers to TypeScript properties, enabling proper
|
|
7
|
+
* Protocol Buffer serialization and deserialization. Field numbers 1-15 require only one
|
|
8
|
+
* byte to encode, making them ideal for frequently used fields. Numbers 19000-19999 are
|
|
9
|
+
* reserved by the Protocol Buffer specification and should not be used.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* interface User {
|
|
14
|
+
* id: string & Sequence<1>; // Most frequent field uses 1
|
|
15
|
+
* email: string & Sequence<2>; // Common fields use low numbers
|
|
16
|
+
* createdAt: number & Sequence<3>;
|
|
17
|
+
* metadata?: object & Sequence<10>; // Optional fields work too
|
|
18
|
+
* }
|
|
19
|
+
*
|
|
20
|
+
* // Generate Protocol Buffer message
|
|
21
|
+
* const message = typia.protobuf.message<User>();
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @template N - Field number (positive integer from 1 to 536,870,911, excluding 19000-19999)
|
|
25
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
26
|
+
*/
|
|
2
27
|
export type Sequence<N extends number> = TagBase<{
|
|
3
28
|
target: "boolean" | "bigint" | "number" | "string" | "array" | "object";
|
|
4
29
|
kind: "sequence";
|
package/lib/tags/TagBase.d.mts
CHANGED
|
@@ -1,3 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base type for all validation tags in typia.
|
|
3
|
+
*
|
|
4
|
+
* TagBase provides the foundation for all typia's validation tags. It attaches
|
|
5
|
+
* metadata to TypeScript types that typia's transformer processes at compile-time
|
|
6
|
+
* to generate optimized runtime validation code.
|
|
7
|
+
*
|
|
8
|
+
* @template Props - Tag properties that define validation behavior
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* // Custom tag example
|
|
13
|
+
* type MyCustomTag<Value extends number> = TagBase<{
|
|
14
|
+
* target: "number";
|
|
15
|
+
* kind: "MyCustom";
|
|
16
|
+
* value: Value;
|
|
17
|
+
* validate: `$input === ${Value}`;
|
|
18
|
+
* }>;
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
22
|
+
*/
|
|
1
23
|
export type TagBase<Props extends TagBase.IProps<any, any, any, any, any, any>> = {
|
|
2
24
|
/**
|
|
3
25
|
* This is a dummy property for compilation.
|
|
@@ -7,6 +29,11 @@ export type TagBase<Props extends TagBase.IProps<any, any, any, any, any, any>>
|
|
|
7
29
|
"typia.tag"?: Props;
|
|
8
30
|
};
|
|
9
31
|
export declare namespace TagBase {
|
|
32
|
+
/**
|
|
33
|
+
* Properties interface for validation tags.
|
|
34
|
+
*
|
|
35
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
36
|
+
*/
|
|
10
37
|
interface IProps<Target extends "boolean" | "bigint" | "number" | "string" | "array" | "object", Kind extends string, Value extends boolean | bigint | number | string | undefined, Validate extends string | {
|
|
11
38
|
[key in Target]?: string;
|
|
12
39
|
}, Exclusive extends boolean | string[], Schema extends object | undefined> {
|
package/lib/tags/TagBase.d.ts
CHANGED
|
@@ -1,3 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base type for all validation tags in typia.
|
|
3
|
+
*
|
|
4
|
+
* TagBase provides the foundation for all typia's validation tags. It attaches
|
|
5
|
+
* metadata to TypeScript types that typia's transformer processes at compile-time
|
|
6
|
+
* to generate optimized runtime validation code.
|
|
7
|
+
*
|
|
8
|
+
* @template Props - Tag properties that define validation behavior
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* // Custom tag example
|
|
13
|
+
* type MyCustomTag<Value extends number> = TagBase<{
|
|
14
|
+
* target: "number";
|
|
15
|
+
* kind: "MyCustom";
|
|
16
|
+
* value: Value;
|
|
17
|
+
* validate: `$input === ${Value}`;
|
|
18
|
+
* }>;
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
22
|
+
*/
|
|
1
23
|
export type TagBase<Props extends TagBase.IProps<any, any, any, any, any, any>> = {
|
|
2
24
|
/**
|
|
3
25
|
* This is a dummy property for compilation.
|
|
@@ -7,6 +29,11 @@ export type TagBase<Props extends TagBase.IProps<any, any, any, any, any, any>>
|
|
|
7
29
|
"typia.tag"?: Props;
|
|
8
30
|
};
|
|
9
31
|
export declare namespace TagBase {
|
|
32
|
+
/**
|
|
33
|
+
* Properties interface for validation tags.
|
|
34
|
+
*
|
|
35
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
36
|
+
*/
|
|
10
37
|
interface IProps<Target extends "boolean" | "bigint" | "number" | "string" | "array" | "object", Kind extends string, Value extends boolean | bigint | number | string | undefined, Validate extends string | {
|
|
11
38
|
[key in Target]?: string;
|
|
12
39
|
}, Exclusive extends boolean | string[], Schema extends object | undefined> {
|
package/lib/tags/Type.d.mts
CHANGED
|
@@ -1,4 +1,30 @@
|
|
|
1
1
|
import { TagBase } from "./TagBase";
|
|
2
|
+
/**
|
|
3
|
+
* Type tag for specifying numeric bit-width representations.
|
|
4
|
+
*
|
|
5
|
+
* Constrains numeric types to specific bit-width formats used in systems programming
|
|
6
|
+
* and protocol buffers. Ensures numbers conform to platform-specific representations.
|
|
7
|
+
*
|
|
8
|
+
* Supported types:
|
|
9
|
+
* - `int32`: 32-bit signed integer (-2^31 to 2^31-1)
|
|
10
|
+
* - `uint32`: 32-bit unsigned integer (0 to 2^32-1)
|
|
11
|
+
* - `int64`: 64-bit signed integer (supports both bigint and number)
|
|
12
|
+
* - `uint64`: 64-bit unsigned integer (supports both bigint and number)
|
|
13
|
+
* - `float`: 32-bit floating point (single precision)
|
|
14
|
+
* - `double`: 64-bit floating point (double precision, default JS number)
|
|
15
|
+
*
|
|
16
|
+
* @template Value - The numeric type representation
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* type Score = number & Type<"int32">; // -2,147,483,648 to 2,147,483,647
|
|
21
|
+
* type UserId = number & Type<"uint32">; // 0 to 4,294,967,295
|
|
22
|
+
* type FileSize = bigint & Type<"int64">; // Large file sizes
|
|
23
|
+
* type Coordinate = number & Type<"double">; // High precision coordinates
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
27
|
+
*/
|
|
2
28
|
export type Type<Value extends "int32" | "uint32" | "int64" | "uint64" | "float" | "double"> = TagBase<{
|
|
3
29
|
target: Value extends "int64" | "uint64" ? "bigint" | "number" : "number";
|
|
4
30
|
kind: "type";
|
package/lib/tags/Type.d.ts
CHANGED
|
@@ -1,4 +1,30 @@
|
|
|
1
1
|
import { TagBase } from "./TagBase";
|
|
2
|
+
/**
|
|
3
|
+
* Type tag for specifying numeric bit-width representations.
|
|
4
|
+
*
|
|
5
|
+
* Constrains numeric types to specific bit-width formats used in systems programming
|
|
6
|
+
* and protocol buffers. Ensures numbers conform to platform-specific representations.
|
|
7
|
+
*
|
|
8
|
+
* Supported types:
|
|
9
|
+
* - `int32`: 32-bit signed integer (-2^31 to 2^31-1)
|
|
10
|
+
* - `uint32`: 32-bit unsigned integer (0 to 2^32-1)
|
|
11
|
+
* - `int64`: 64-bit signed integer (supports both bigint and number)
|
|
12
|
+
* - `uint64`: 64-bit unsigned integer (supports both bigint and number)
|
|
13
|
+
* - `float`: 32-bit floating point (single precision)
|
|
14
|
+
* - `double`: 64-bit floating point (double precision, default JS number)
|
|
15
|
+
*
|
|
16
|
+
* @template Value - The numeric type representation
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* type Score = number & Type<"int32">; // -2,147,483,648 to 2,147,483,647
|
|
21
|
+
* type UserId = number & Type<"uint32">; // 0 to 4,294,967,295
|
|
22
|
+
* type FileSize = bigint & Type<"int64">; // Large file sizes
|
|
23
|
+
* type Coordinate = number & Type<"double">; // High precision coordinates
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
27
|
+
*/
|
|
2
28
|
export type Type<Value extends "int32" | "uint32" | "int64" | "uint64" | "float" | "double"> = TagBase<{
|
|
3
29
|
target: Value extends "int64" | "uint64" ? "bigint" | "number" : "number";
|
|
4
30
|
kind: "type";
|