@typia/interface 12.0.0-dev.20260307-2 → 12.0.0-dev.20260310
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/http/IHttpLlmController.d.ts +5 -5
- package/lib/schema/IJsonParseResult.d.ts +1 -3
- package/lib/schema/ILlmApplication.d.ts +1 -1
- package/lib/schema/ILlmController.d.ts +2 -5
- package/lib/schema/ILlmFunction.d.ts +35 -9
- package/package.json +1 -1
- package/src/http/IHttpConnection.ts +200 -200
- package/src/http/IHttpLlmApplication.ts +72 -72
- package/src/http/IHttpLlmController.ts +96 -96
- package/src/http/IHttpLlmFunction.ts +34 -34
- package/src/http/IHttpMigrateApplication.ts +48 -48
- package/src/http/IHttpMigrateRoute.ts +165 -165
- package/src/http/IHttpResponse.ts +42 -42
- package/src/http/index.ts +7 -7
- package/src/index.ts +9 -9
- package/src/metadata/IJsDocTagInfo.ts +25 -25
- package/src/metadata/IMetadataComponents.ts +24 -24
- package/src/metadata/IMetadataSchema.ts +293 -293
- package/src/metadata/IMetadataSchemaCollection.ts +20 -20
- package/src/metadata/IMetadataSchemaUnit.ts +20 -20
- package/src/metadata/IMetadataTypeTag.ts +39 -39
- package/src/metadata/index.ts +6 -6
- package/src/openapi/OpenApi.ts +643 -643
- package/src/openapi/OpenApiV3.ts +655 -655
- package/src/openapi/OpenApiV3_1.ts +735 -735
- package/src/openapi/SwaggerV2.ts +559 -559
- package/src/openapi/index.ts +4 -4
- package/src/protobuf/ProtobufWire.ts +51 -51
- package/src/protobuf/index.ts +1 -1
- package/src/schema/IJsonParseResult.ts +134 -136
- package/src/schema/IJsonSchemaApplication.ts +274 -274
- package/src/schema/IJsonSchemaAttribute.ts +158 -158
- package/src/schema/IJsonSchemaCollection.ts +123 -123
- package/src/schema/IJsonSchemaTransformError.ts +86 -86
- package/src/schema/IJsonSchemaUnit.ts +120 -120
- package/src/schema/ILlmApplication.ts +99 -99
- package/src/schema/ILlmController.ts +54 -57
- package/src/schema/ILlmFunction.ts +145 -118
- package/src/schema/ILlmSchema.ts +484 -484
- package/src/schema/IResult.ts +84 -84
- package/src/schema/IValidation.ts +134 -134
- package/src/schema/index.ts +14 -14
- package/src/tags/Constant.ts +49 -49
- package/src/tags/ContentMediaType.ts +40 -40
- package/src/tags/Default.ts +50 -50
- package/src/tags/Example.ts +48 -48
- package/src/tags/Examples.ts +50 -50
- package/src/tags/ExclusiveMaximum.ts +46 -46
- package/src/tags/ExclusiveMinimum.ts +46 -46
- package/src/tags/Format.ts +76 -76
- package/src/tags/JsonSchemaPlugin.ts +45 -45
- package/src/tags/MaxItems.ts +39 -39
- package/src/tags/MaxLength.ts +37 -37
- package/src/tags/Maximum.ts +44 -44
- package/src/tags/MinItems.ts +39 -39
- package/src/tags/MinLength.ts +37 -37
- package/src/tags/Minimum.ts +44 -44
- package/src/tags/MultipleOf.ts +54 -54
- package/src/tags/Pattern.ts +59 -59
- package/src/tags/Sequence.ts +43 -43
- package/src/tags/TagBase.ts +131 -131
- package/src/tags/Type.ts +70 -70
- package/src/tags/UniqueItems.ts +44 -44
- package/src/tags/index.ts +21 -21
- package/src/typings/AssertionGuard.ts +12 -12
- package/src/typings/Atomic.ts +21 -21
- package/src/typings/CamelCase.ts +75 -75
- package/src/typings/ClassProperties.ts +15 -15
- package/src/typings/DeepPartial.ts +39 -39
- package/src/typings/OmitNever.ts +12 -12
- package/src/typings/PascalCase.ts +71 -71
- package/src/typings/Primitive.ts +71 -71
- package/src/typings/ProtobufAtomic.ts +30 -30
- package/src/typings/Resolved.ts +58 -58
- package/src/typings/SnakeCase.ts +126 -126
- package/src/typings/SpecialFields.ts +13 -13
- package/src/typings/ValidationPipe.ts +20 -20
- package/src/typings/index.ts +14 -14
- package/src/typings/internal/Equal.ts +14 -14
- package/src/typings/internal/IsTuple.ts +17 -17
- package/src/typings/internal/NativeClass.ts +31 -31
- package/src/typings/internal/ValueOf.ts +29 -29
- package/src/utils/IRandomGenerator.ts +105 -105
- package/src/utils/IReadableURLSearchParams.ts +25 -25
- package/src/utils/index.ts +2 -2
package/src/tags/MultipleOf.ts
CHANGED
|
@@ -1,54 +1,54 @@
|
|
|
1
|
-
import { TagBase } from "./TagBase";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Divisibility constraint (value % divisor === 0).
|
|
5
|
-
*
|
|
6
|
-
* `MultipleOf<N>` is a type tag that validates numeric values are exactly
|
|
7
|
-
* divisible by the specified divisor with no remainder. Apply it to `number` or
|
|
8
|
-
* `bigint` properties using TypeScript intersection types.
|
|
9
|
-
*
|
|
10
|
-
* Common use cases:
|
|
11
|
-
*
|
|
12
|
-
* - `MultipleOf<2>` for even numbers
|
|
13
|
-
* - `MultipleOf<0.01>` for currency with 2 decimal places
|
|
14
|
-
* - `MultipleOf<100>` for values in hundreds
|
|
15
|
-
*
|
|
16
|
-
* This constraint can be combined with other numeric constraints like
|
|
17
|
-
* {@link Minimum} and {@link Maximum}. Multiple `MultipleOf` constraints on the
|
|
18
|
-
* same property are allowed (all must pass).
|
|
19
|
-
*
|
|
20
|
-
* The constraint is enforced at runtime by `typia.is()`, `typia.assert()`, and
|
|
21
|
-
* `typia.validate()`. It generates `multipleOf` in JSON Schema output.
|
|
22
|
-
*
|
|
23
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
24
|
-
* @example
|
|
25
|
-
* interface Currency {
|
|
26
|
-
* // Must be exact cents (0.01, 0.02, ..., 1.00, 1.01, ...)
|
|
27
|
-
* amount: number & MultipleOf<0.01>;
|
|
28
|
-
* }
|
|
29
|
-
* interface Pagination {
|
|
30
|
-
* // Page size must be multiple of 10
|
|
31
|
-
* pageSize: number & MultipleOf<10>;
|
|
32
|
-
* }
|
|
33
|
-
*
|
|
34
|
-
* @template Value The divisor (value must be evenly divisible by this)
|
|
35
|
-
*/
|
|
36
|
-
export type MultipleOf<Value extends number | bigint> = TagBase<{
|
|
37
|
-
target: Value extends bigint ? "bigint" : "number";
|
|
38
|
-
kind: "multipleOf";
|
|
39
|
-
value: Value;
|
|
40
|
-
validate: `$input % ${Cast<Value>} === ${Value extends bigint
|
|
41
|
-
? Cast<0n>
|
|
42
|
-
: 0}`;
|
|
43
|
-
exclusive: true;
|
|
44
|
-
schema: Value extends bigint
|
|
45
|
-
? { multipleOf: Numeric<Value> }
|
|
46
|
-
: { multipleOf: Value };
|
|
47
|
-
}>;
|
|
48
|
-
|
|
49
|
-
type Cast<Value extends number | bigint> = Value extends number
|
|
50
|
-
? Value
|
|
51
|
-
: `BigInt(${Value})`;
|
|
52
|
-
type Numeric<T extends bigint> = `${T}` extends `${infer N extends number}`
|
|
53
|
-
? N
|
|
54
|
-
: never;
|
|
1
|
+
import { TagBase } from "./TagBase";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Divisibility constraint (value % divisor === 0).
|
|
5
|
+
*
|
|
6
|
+
* `MultipleOf<N>` is a type tag that validates numeric values are exactly
|
|
7
|
+
* divisible by the specified divisor with no remainder. Apply it to `number` or
|
|
8
|
+
* `bigint` properties using TypeScript intersection types.
|
|
9
|
+
*
|
|
10
|
+
* Common use cases:
|
|
11
|
+
*
|
|
12
|
+
* - `MultipleOf<2>` for even numbers
|
|
13
|
+
* - `MultipleOf<0.01>` for currency with 2 decimal places
|
|
14
|
+
* - `MultipleOf<100>` for values in hundreds
|
|
15
|
+
*
|
|
16
|
+
* This constraint can be combined with other numeric constraints like
|
|
17
|
+
* {@link Minimum} and {@link Maximum}. Multiple `MultipleOf` constraints on the
|
|
18
|
+
* same property are allowed (all must pass).
|
|
19
|
+
*
|
|
20
|
+
* The constraint is enforced at runtime by `typia.is()`, `typia.assert()`, and
|
|
21
|
+
* `typia.validate()`. It generates `multipleOf` in JSON Schema output.
|
|
22
|
+
*
|
|
23
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
24
|
+
* @example
|
|
25
|
+
* interface Currency {
|
|
26
|
+
* // Must be exact cents (0.01, 0.02, ..., 1.00, 1.01, ...)
|
|
27
|
+
* amount: number & MultipleOf<0.01>;
|
|
28
|
+
* }
|
|
29
|
+
* interface Pagination {
|
|
30
|
+
* // Page size must be multiple of 10
|
|
31
|
+
* pageSize: number & MultipleOf<10>;
|
|
32
|
+
* }
|
|
33
|
+
*
|
|
34
|
+
* @template Value The divisor (value must be evenly divisible by this)
|
|
35
|
+
*/
|
|
36
|
+
export type MultipleOf<Value extends number | bigint> = TagBase<{
|
|
37
|
+
target: Value extends bigint ? "bigint" : "number";
|
|
38
|
+
kind: "multipleOf";
|
|
39
|
+
value: Value;
|
|
40
|
+
validate: `$input % ${Cast<Value>} === ${Value extends bigint
|
|
41
|
+
? Cast<0n>
|
|
42
|
+
: 0}`;
|
|
43
|
+
exclusive: true;
|
|
44
|
+
schema: Value extends bigint
|
|
45
|
+
? { multipleOf: Numeric<Value> }
|
|
46
|
+
: { multipleOf: Value };
|
|
47
|
+
}>;
|
|
48
|
+
|
|
49
|
+
type Cast<Value extends number | bigint> = Value extends number
|
|
50
|
+
? Value
|
|
51
|
+
: `BigInt(${Value})`;
|
|
52
|
+
type Numeric<T extends bigint> = `${T}` extends `${infer N extends number}`
|
|
53
|
+
? N
|
|
54
|
+
: never;
|
package/src/tags/Pattern.ts
CHANGED
|
@@ -1,59 +1,59 @@
|
|
|
1
|
-
import { TagBase } from "./TagBase";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Regular expression pattern constraint for strings.
|
|
5
|
-
*
|
|
6
|
-
* `Pattern<Regex>` is a type tag that validates string values match the
|
|
7
|
-
* specified regular expression pattern. Apply it to `string` properties using
|
|
8
|
-
* TypeScript intersection types.
|
|
9
|
-
*
|
|
10
|
-
* This constraint is **mutually exclusive** with {@link Format} - you cannot use
|
|
11
|
-
* both on the same property. Use `Pattern` for custom regex validation, or
|
|
12
|
-
* `Format` for standard formats (email, uuid, etc.).
|
|
13
|
-
*
|
|
14
|
-
* The pattern should be a valid JavaScript regular expression string without
|
|
15
|
-
* the surrounding slashes. The entire string must match (implicit `^` and `$`
|
|
16
|
-
* anchors).
|
|
17
|
-
*
|
|
18
|
-
* The constraint is enforced at runtime by `typia.is()`, `typia.assert()`, and
|
|
19
|
-
* `typia.validate()`. It generates `pattern` in JSON Schema output.
|
|
20
|
-
*
|
|
21
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
22
|
-
* @example
|
|
23
|
-
* interface Product {
|
|
24
|
-
* // SKU format: 3 letters, dash, 4 digits
|
|
25
|
-
* sku: string & Pattern<"^[A-Z]{3}-[0-9]{4}$">;
|
|
26
|
-
* // Phone number: digits and optional dashes
|
|
27
|
-
* phone: string & Pattern<"^[0-9-]+$">;
|
|
28
|
-
* }
|
|
29
|
-
*
|
|
30
|
-
* @template Value Regular expression pattern as a string literal
|
|
31
|
-
*/
|
|
32
|
-
export type Pattern<Value extends string> = TagBase<{
|
|
33
|
-
target: "string";
|
|
34
|
-
kind: "pattern";
|
|
35
|
-
value: Value;
|
|
36
|
-
validate: `RegExp("${Serialize<Value>}").test($input)`;
|
|
37
|
-
exclusive: ["format", "pattern"];
|
|
38
|
-
schema: {
|
|
39
|
-
pattern: Value;
|
|
40
|
-
};
|
|
41
|
-
}>;
|
|
42
|
-
|
|
43
|
-
type Serialize<T extends string, Output extends string = ""> = string extends T
|
|
44
|
-
? never
|
|
45
|
-
: T extends ""
|
|
46
|
-
? Output
|
|
47
|
-
: T extends `${infer P}${infer R}`
|
|
48
|
-
? Serialize<R, `${Output}${P extends keyof Escaper ? Escaper[P] : P}`>
|
|
49
|
-
: never;
|
|
50
|
-
|
|
51
|
-
type Escaper = {
|
|
52
|
-
'"': '\\"';
|
|
53
|
-
"\\": "\\\\";
|
|
54
|
-
"\b": "\\b";
|
|
55
|
-
"\f": "\\f";
|
|
56
|
-
"\n": "\\n";
|
|
57
|
-
"\r": "\\r";
|
|
58
|
-
"\t": "\\t";
|
|
59
|
-
};
|
|
1
|
+
import { TagBase } from "./TagBase";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Regular expression pattern constraint for strings.
|
|
5
|
+
*
|
|
6
|
+
* `Pattern<Regex>` is a type tag that validates string values match the
|
|
7
|
+
* specified regular expression pattern. Apply it to `string` properties using
|
|
8
|
+
* TypeScript intersection types.
|
|
9
|
+
*
|
|
10
|
+
* This constraint is **mutually exclusive** with {@link Format} - you cannot use
|
|
11
|
+
* both on the same property. Use `Pattern` for custom regex validation, or
|
|
12
|
+
* `Format` for standard formats (email, uuid, etc.).
|
|
13
|
+
*
|
|
14
|
+
* The pattern should be a valid JavaScript regular expression string without
|
|
15
|
+
* the surrounding slashes. The entire string must match (implicit `^` and `$`
|
|
16
|
+
* anchors).
|
|
17
|
+
*
|
|
18
|
+
* The constraint is enforced at runtime by `typia.is()`, `typia.assert()`, and
|
|
19
|
+
* `typia.validate()`. It generates `pattern` in JSON Schema output.
|
|
20
|
+
*
|
|
21
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
22
|
+
* @example
|
|
23
|
+
* interface Product {
|
|
24
|
+
* // SKU format: 3 letters, dash, 4 digits
|
|
25
|
+
* sku: string & Pattern<"^[A-Z]{3}-[0-9]{4}$">;
|
|
26
|
+
* // Phone number: digits and optional dashes
|
|
27
|
+
* phone: string & Pattern<"^[0-9-]+$">;
|
|
28
|
+
* }
|
|
29
|
+
*
|
|
30
|
+
* @template Value Regular expression pattern as a string literal
|
|
31
|
+
*/
|
|
32
|
+
export type Pattern<Value extends string> = TagBase<{
|
|
33
|
+
target: "string";
|
|
34
|
+
kind: "pattern";
|
|
35
|
+
value: Value;
|
|
36
|
+
validate: `RegExp("${Serialize<Value>}").test($input)`;
|
|
37
|
+
exclusive: ["format", "pattern"];
|
|
38
|
+
schema: {
|
|
39
|
+
pattern: Value;
|
|
40
|
+
};
|
|
41
|
+
}>;
|
|
42
|
+
|
|
43
|
+
type Serialize<T extends string, Output extends string = ""> = string extends T
|
|
44
|
+
? never
|
|
45
|
+
: T extends ""
|
|
46
|
+
? Output
|
|
47
|
+
: T extends `${infer P}${infer R}`
|
|
48
|
+
? Serialize<R, `${Output}${P extends keyof Escaper ? Escaper[P] : P}`>
|
|
49
|
+
: never;
|
|
50
|
+
|
|
51
|
+
type Escaper = {
|
|
52
|
+
'"': '\\"';
|
|
53
|
+
"\\": "\\\\";
|
|
54
|
+
"\b": "\\b";
|
|
55
|
+
"\f": "\\f";
|
|
56
|
+
"\n": "\\n";
|
|
57
|
+
"\r": "\\r";
|
|
58
|
+
"\t": "\\t";
|
|
59
|
+
};
|
package/src/tags/Sequence.ts
CHANGED
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
import { TagBase } from "./TagBase";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Protocol Buffer field number assignment.
|
|
5
|
-
*
|
|
6
|
-
* `Sequence<N>` is a type tag that assigns a unique field number for Protocol
|
|
7
|
-
* Buffer serialization. In protobuf, each field in a message must have a unique
|
|
8
|
-
* numeric identifier that's used in the binary encoding.
|
|
9
|
-
*
|
|
10
|
-
* Field number guidelines:
|
|
11
|
-
*
|
|
12
|
-
* - **1-15**: Use one byte in encoding (ideal for frequently-used fields)
|
|
13
|
-
* - **16-2047**: Use two bytes
|
|
14
|
-
* - **2048-536,870,911**: Use more bytes (avoid for efficiency)
|
|
15
|
-
* - **19000-19999**: Reserved by Protocol Buffers (cannot use)
|
|
16
|
-
*
|
|
17
|
-
* If not specified, typia auto-assigns field numbers. Use `Sequence` when you
|
|
18
|
-
* need stable field numbers for backward compatibility or when integrating with
|
|
19
|
-
* existing protobuf schemas.
|
|
20
|
-
*
|
|
21
|
-
* This tag is used by `typia.protobuf.encode()` and `typia.protobuf.decode()`.
|
|
22
|
-
* The field number also appears in JSON Schema as `x-protobuf-sequence`.
|
|
23
|
-
*
|
|
24
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
25
|
-
* @example
|
|
26
|
-
* interface Message {
|
|
27
|
-
* // Frequently accessed fields use low numbers
|
|
28
|
-
* id: (number & Sequence<1>) & Type<"uint32">;
|
|
29
|
-
* name: string & Sequence<2>;
|
|
30
|
-
* // Less common fields use higher numbers
|
|
31
|
-
* metadata: (Record<string, string> & Sequence<100>) | undefined;
|
|
32
|
-
* }
|
|
33
|
-
*
|
|
34
|
-
* @template N Field number (1 to 536,870,911, excluding 19000-19999)
|
|
35
|
-
*/
|
|
36
|
-
export type Sequence<N extends number> = TagBase<{
|
|
37
|
-
target: "boolean" | "bigint" | "number" | "string" | "array" | "object";
|
|
38
|
-
kind: "sequence";
|
|
39
|
-
value: N;
|
|
40
|
-
schema: {
|
|
41
|
-
"x-protobuf-sequence": N;
|
|
42
|
-
};
|
|
43
|
-
}>;
|
|
1
|
+
import { TagBase } from "./TagBase";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Protocol Buffer field number assignment.
|
|
5
|
+
*
|
|
6
|
+
* `Sequence<N>` is a type tag that assigns a unique field number for Protocol
|
|
7
|
+
* Buffer serialization. In protobuf, each field in a message must have a unique
|
|
8
|
+
* numeric identifier that's used in the binary encoding.
|
|
9
|
+
*
|
|
10
|
+
* Field number guidelines:
|
|
11
|
+
*
|
|
12
|
+
* - **1-15**: Use one byte in encoding (ideal for frequently-used fields)
|
|
13
|
+
* - **16-2047**: Use two bytes
|
|
14
|
+
* - **2048-536,870,911**: Use more bytes (avoid for efficiency)
|
|
15
|
+
* - **19000-19999**: Reserved by Protocol Buffers (cannot use)
|
|
16
|
+
*
|
|
17
|
+
* If not specified, typia auto-assigns field numbers. Use `Sequence` when you
|
|
18
|
+
* need stable field numbers for backward compatibility or when integrating with
|
|
19
|
+
* existing protobuf schemas.
|
|
20
|
+
*
|
|
21
|
+
* This tag is used by `typia.protobuf.encode()` and `typia.protobuf.decode()`.
|
|
22
|
+
* The field number also appears in JSON Schema as `x-protobuf-sequence`.
|
|
23
|
+
*
|
|
24
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
25
|
+
* @example
|
|
26
|
+
* interface Message {
|
|
27
|
+
* // Frequently accessed fields use low numbers
|
|
28
|
+
* id: (number & Sequence<1>) & Type<"uint32">;
|
|
29
|
+
* name: string & Sequence<2>;
|
|
30
|
+
* // Less common fields use higher numbers
|
|
31
|
+
* metadata: (Record<string, string> & Sequence<100>) | undefined;
|
|
32
|
+
* }
|
|
33
|
+
*
|
|
34
|
+
* @template N Field number (1 to 536,870,911, excluding 19000-19999)
|
|
35
|
+
*/
|
|
36
|
+
export type Sequence<N extends number> = TagBase<{
|
|
37
|
+
target: "boolean" | "bigint" | "number" | "string" | "array" | "object";
|
|
38
|
+
kind: "sequence";
|
|
39
|
+
value: N;
|
|
40
|
+
schema: {
|
|
41
|
+
"x-protobuf-sequence": N;
|
|
42
|
+
};
|
|
43
|
+
}>;
|
package/src/tags/TagBase.ts
CHANGED
|
@@ -1,131 +1,131 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Base type for all typia validation tags.
|
|
3
|
-
*
|
|
4
|
-
* `TagBase` is the foundation for all typia type tags (constraints like
|
|
5
|
-
* `Minimum`, `MaxLength`, `Format`, etc.). It attaches compile-time metadata to
|
|
6
|
-
* TypeScript types using a phantom property pattern.
|
|
7
|
-
*
|
|
8
|
-
* The typia transformer reads these tags at compile time and generates
|
|
9
|
-
* appropriate runtime validation code. The tags themselves have no runtime
|
|
10
|
-
* presence - they exist only in the type system.
|
|
11
|
-
*
|
|
12
|
-
* This is an internal implementation detail. Use the specific tag types (e.g.,
|
|
13
|
-
* {@link Minimum}, {@link Format}, {@link Pattern}) rather than `TagBase`
|
|
14
|
-
* directly.
|
|
15
|
-
*
|
|
16
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
17
|
-
* @template Props Tag properties defining validation behavior and schema output
|
|
18
|
-
*/
|
|
19
|
-
export type TagBase<
|
|
20
|
-
Props extends TagBase.IProps<any, any, any, any, any, any>,
|
|
21
|
-
> = {
|
|
22
|
-
/**
|
|
23
|
-
* Compile-time marker property for typia transformer.
|
|
24
|
-
*
|
|
25
|
-
* This phantom property carries tag metadata in the type system. It is never
|
|
26
|
-
* assigned at runtime - it exists only for the transformer to read during
|
|
27
|
-
* compilation.
|
|
28
|
-
*/
|
|
29
|
-
"typia.tag"?: Props;
|
|
30
|
-
};
|
|
31
|
-
export namespace TagBase {
|
|
32
|
-
/**
|
|
33
|
-
* Configuration interface for validation tag properties.
|
|
34
|
-
*
|
|
35
|
-
* Defines all the metadata a validation tag can specify, including what types
|
|
36
|
-
* it applies to, how to validate values, and what to output in JSON Schema.
|
|
37
|
-
*
|
|
38
|
-
* @template Target Which primitive type(s) this tag can be applied to
|
|
39
|
-
* @template Kind Unique identifier for this tag type
|
|
40
|
-
* @template Value The constraint value specified by the user
|
|
41
|
-
* @template Validate The validation expression to generate
|
|
42
|
-
* @template Exclusive Whether this tag conflicts with others
|
|
43
|
-
* @template Schema Additional JSON Schema properties to output
|
|
44
|
-
*/
|
|
45
|
-
export interface IProps<
|
|
46
|
-
Target extends
|
|
47
|
-
| "boolean"
|
|
48
|
-
| "bigint"
|
|
49
|
-
| "number"
|
|
50
|
-
| "string"
|
|
51
|
-
| "array"
|
|
52
|
-
| "object",
|
|
53
|
-
Kind extends string,
|
|
54
|
-
Value extends boolean | bigint | number | string | undefined,
|
|
55
|
-
Validate extends
|
|
56
|
-
| string
|
|
57
|
-
| {
|
|
58
|
-
[key in Target]?: string;
|
|
59
|
-
},
|
|
60
|
-
Exclusive extends boolean | string[],
|
|
61
|
-
Schema extends object | undefined,
|
|
62
|
-
> {
|
|
63
|
-
/**
|
|
64
|
-
* Target primitive type(s) this tag applies to.
|
|
65
|
-
*
|
|
66
|
-
* The transformer will error if the tag is applied to a property of a
|
|
67
|
-
* different type. For example, `MinLength` targets `"string"` and cannot be
|
|
68
|
-
* applied to numbers.
|
|
69
|
-
*/
|
|
70
|
-
target: Target;
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Unique identifier for this tag type.
|
|
74
|
-
*
|
|
75
|
-
* Used internally to identify the constraint kind. Examples: `"minimum"`,
|
|
76
|
-
* `"maxLength"`, `"format"`, `"pattern"`.
|
|
77
|
-
*/
|
|
78
|
-
kind: Kind;
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* User-configured constraint value.
|
|
82
|
-
*
|
|
83
|
-
* The value provided by the user when applying the tag. For `Minimum<5>`,
|
|
84
|
-
* this would be `5`. For `Format<"email">`, this would be `"email"`.
|
|
85
|
-
*/
|
|
86
|
-
value: Value;
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Validation expression template.
|
|
90
|
-
*
|
|
91
|
-
* JavaScript expression string that validates the input value. Use `$input`
|
|
92
|
-
* as a placeholder for the actual value. The expression is inserted into
|
|
93
|
-
* the generated validation function.
|
|
94
|
-
*
|
|
95
|
-
* Can be a single string or an object mapping target types to different
|
|
96
|
-
* expressions (for tags supporting multiple types).
|
|
97
|
-
*
|
|
98
|
-
* @example
|
|
99
|
-
* `"5 <= $input"`; // For Minimum<5>
|
|
100
|
-
*
|
|
101
|
-
* @example
|
|
102
|
-
* `"$input.length <= 10"`; // For MaxLength<10>
|
|
103
|
-
*/
|
|
104
|
-
validate?: Validate;
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Tag exclusivity configuration.
|
|
108
|
-
*
|
|
109
|
-
* Controls which other tags cannot be combined with this one:
|
|
110
|
-
*
|
|
111
|
-
* - `true`: No duplicate tags of the same kind allowed
|
|
112
|
-
* - `string[]`: List of incompatible tag kinds
|
|
113
|
-
* - `false` (default): No exclusivity restrictions
|
|
114
|
-
*
|
|
115
|
-
* For example, `Minimum` and `ExclusiveMinimum` are mutually exclusive -
|
|
116
|
-
* only one can be applied to a property.
|
|
117
|
-
*
|
|
118
|
-
* @default false
|
|
119
|
-
*/
|
|
120
|
-
exclusive?: Exclusive | string[];
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* Additional JSON Schema properties to output.
|
|
124
|
-
*
|
|
125
|
-
* Object containing schema properties to merge into the generated JSON
|
|
126
|
-
* Schema for the annotated type. For `Minimum<5>`, this would be `{
|
|
127
|
-
* minimum: 5 }`.
|
|
128
|
-
*/
|
|
129
|
-
schema?: Schema;
|
|
130
|
-
}
|
|
131
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Base type for all typia validation tags.
|
|
3
|
+
*
|
|
4
|
+
* `TagBase` is the foundation for all typia type tags (constraints like
|
|
5
|
+
* `Minimum`, `MaxLength`, `Format`, etc.). It attaches compile-time metadata to
|
|
6
|
+
* TypeScript types using a phantom property pattern.
|
|
7
|
+
*
|
|
8
|
+
* The typia transformer reads these tags at compile time and generates
|
|
9
|
+
* appropriate runtime validation code. The tags themselves have no runtime
|
|
10
|
+
* presence - they exist only in the type system.
|
|
11
|
+
*
|
|
12
|
+
* This is an internal implementation detail. Use the specific tag types (e.g.,
|
|
13
|
+
* {@link Minimum}, {@link Format}, {@link Pattern}) rather than `TagBase`
|
|
14
|
+
* directly.
|
|
15
|
+
*
|
|
16
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
17
|
+
* @template Props Tag properties defining validation behavior and schema output
|
|
18
|
+
*/
|
|
19
|
+
export type TagBase<
|
|
20
|
+
Props extends TagBase.IProps<any, any, any, any, any, any>,
|
|
21
|
+
> = {
|
|
22
|
+
/**
|
|
23
|
+
* Compile-time marker property for typia transformer.
|
|
24
|
+
*
|
|
25
|
+
* This phantom property carries tag metadata in the type system. It is never
|
|
26
|
+
* assigned at runtime - it exists only for the transformer to read during
|
|
27
|
+
* compilation.
|
|
28
|
+
*/
|
|
29
|
+
"typia.tag"?: Props;
|
|
30
|
+
};
|
|
31
|
+
export namespace TagBase {
|
|
32
|
+
/**
|
|
33
|
+
* Configuration interface for validation tag properties.
|
|
34
|
+
*
|
|
35
|
+
* Defines all the metadata a validation tag can specify, including what types
|
|
36
|
+
* it applies to, how to validate values, and what to output in JSON Schema.
|
|
37
|
+
*
|
|
38
|
+
* @template Target Which primitive type(s) this tag can be applied to
|
|
39
|
+
* @template Kind Unique identifier for this tag type
|
|
40
|
+
* @template Value The constraint value specified by the user
|
|
41
|
+
* @template Validate The validation expression to generate
|
|
42
|
+
* @template Exclusive Whether this tag conflicts with others
|
|
43
|
+
* @template Schema Additional JSON Schema properties to output
|
|
44
|
+
*/
|
|
45
|
+
export interface IProps<
|
|
46
|
+
Target extends
|
|
47
|
+
| "boolean"
|
|
48
|
+
| "bigint"
|
|
49
|
+
| "number"
|
|
50
|
+
| "string"
|
|
51
|
+
| "array"
|
|
52
|
+
| "object",
|
|
53
|
+
Kind extends string,
|
|
54
|
+
Value extends boolean | bigint | number | string | undefined,
|
|
55
|
+
Validate extends
|
|
56
|
+
| string
|
|
57
|
+
| {
|
|
58
|
+
[key in Target]?: string;
|
|
59
|
+
},
|
|
60
|
+
Exclusive extends boolean | string[],
|
|
61
|
+
Schema extends object | undefined,
|
|
62
|
+
> {
|
|
63
|
+
/**
|
|
64
|
+
* Target primitive type(s) this tag applies to.
|
|
65
|
+
*
|
|
66
|
+
* The transformer will error if the tag is applied to a property of a
|
|
67
|
+
* different type. For example, `MinLength` targets `"string"` and cannot be
|
|
68
|
+
* applied to numbers.
|
|
69
|
+
*/
|
|
70
|
+
target: Target;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Unique identifier for this tag type.
|
|
74
|
+
*
|
|
75
|
+
* Used internally to identify the constraint kind. Examples: `"minimum"`,
|
|
76
|
+
* `"maxLength"`, `"format"`, `"pattern"`.
|
|
77
|
+
*/
|
|
78
|
+
kind: Kind;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* User-configured constraint value.
|
|
82
|
+
*
|
|
83
|
+
* The value provided by the user when applying the tag. For `Minimum<5>`,
|
|
84
|
+
* this would be `5`. For `Format<"email">`, this would be `"email"`.
|
|
85
|
+
*/
|
|
86
|
+
value: Value;
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Validation expression template.
|
|
90
|
+
*
|
|
91
|
+
* JavaScript expression string that validates the input value. Use `$input`
|
|
92
|
+
* as a placeholder for the actual value. The expression is inserted into
|
|
93
|
+
* the generated validation function.
|
|
94
|
+
*
|
|
95
|
+
* Can be a single string or an object mapping target types to different
|
|
96
|
+
* expressions (for tags supporting multiple types).
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* `"5 <= $input"`; // For Minimum<5>
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* `"$input.length <= 10"`; // For MaxLength<10>
|
|
103
|
+
*/
|
|
104
|
+
validate?: Validate;
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Tag exclusivity configuration.
|
|
108
|
+
*
|
|
109
|
+
* Controls which other tags cannot be combined with this one:
|
|
110
|
+
*
|
|
111
|
+
* - `true`: No duplicate tags of the same kind allowed
|
|
112
|
+
* - `string[]`: List of incompatible tag kinds
|
|
113
|
+
* - `false` (default): No exclusivity restrictions
|
|
114
|
+
*
|
|
115
|
+
* For example, `Minimum` and `ExclusiveMinimum` are mutually exclusive -
|
|
116
|
+
* only one can be applied to a property.
|
|
117
|
+
*
|
|
118
|
+
* @default false
|
|
119
|
+
*/
|
|
120
|
+
exclusive?: Exclusive | string[];
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Additional JSON Schema properties to output.
|
|
124
|
+
*
|
|
125
|
+
* Object containing schema properties to merge into the generated JSON
|
|
126
|
+
* Schema for the annotated type. For `Minimum<5>`, this would be `{
|
|
127
|
+
* minimum: 5 }`.
|
|
128
|
+
*/
|
|
129
|
+
schema?: Schema;
|
|
130
|
+
}
|
|
131
|
+
}
|