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/Example.ts
CHANGED
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
import { TagBase } from "./TagBase";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Example value tag that provides a single example value for documentation.
|
|
5
|
-
*
|
|
6
|
-
* This tag adds an example value to your JSON Schema, which is useful for API
|
|
7
|
-
* documentation, client code generation, and helping developers understand
|
|
8
|
-
* expected data formats. The example doesn't affect runtime validation.
|
|
9
|
-
*
|
|
10
|
-
* Use Example for a single representative value. For multiple named examples,
|
|
11
|
-
* use the Examples tag instead.
|
|
12
|
-
*
|
|
13
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
14
|
-
* @example
|
|
15
|
-
* ```typescript
|
|
16
|
-
* interface Product {
|
|
17
|
-
* name: string & Example<"iPhone 15 Pro">;
|
|
18
|
-
* price: number & Example<999.99>;
|
|
19
|
-
* inStock: boolean & Example<true>;
|
|
20
|
-
* }
|
|
21
|
-
* ```;
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* ```typescript
|
|
25
|
-
* interface User {
|
|
26
|
-
* profile: {
|
|
27
|
-
* bio: string;
|
|
28
|
-
* tags: string[];
|
|
29
|
-
* } & Example<{ bio: "Software engineer", tags: ["typescript", "react"] }>;
|
|
30
|
-
* }
|
|
31
|
-
* ```;
|
|
32
|
-
*
|
|
33
|
-
* @template Value The example value (primitives, objects, arrays, or null)
|
|
34
|
-
*/
|
|
35
|
-
export type Example<
|
|
36
|
-
Value extends
|
|
37
|
-
| boolean
|
|
38
|
-
| bigint
|
|
39
|
-
| number
|
|
40
|
-
| string
|
|
41
|
-
| object
|
|
42
|
-
| Array<unknown>
|
|
43
|
-
| null,
|
|
44
|
-
> = TagBase<{
|
|
45
|
-
target: "boolean" | "bigint" | "number" | "string" | "array" | "object";
|
|
46
|
-
kind: "example";
|
|
47
|
-
value: Value;
|
|
48
|
-
exclusive: true;
|
|
49
|
-
schema: Value extends bigint
|
|
50
|
-
? { example: Numeric<Value> }
|
|
51
|
-
: { example: Value };
|
|
52
|
-
}>;
|
|
53
|
-
|
|
54
|
-
type Numeric<T extends bigint> = `${T}` extends `${infer N extends number}`
|
|
55
|
-
? N
|
|
56
|
-
: never;
|
|
1
|
+
import { TagBase } from "./TagBase";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Example value tag that provides a single example value for documentation.
|
|
5
|
+
*
|
|
6
|
+
* This tag adds an example value to your JSON Schema, which is useful for API
|
|
7
|
+
* documentation, client code generation, and helping developers understand
|
|
8
|
+
* expected data formats. The example doesn't affect runtime validation.
|
|
9
|
+
*
|
|
10
|
+
* Use Example for a single representative value. For multiple named examples,
|
|
11
|
+
* use the Examples tag instead.
|
|
12
|
+
*
|
|
13
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* interface Product {
|
|
17
|
+
* name: string & Example<"iPhone 15 Pro">;
|
|
18
|
+
* price: number & Example<999.99>;
|
|
19
|
+
* inStock: boolean & Example<true>;
|
|
20
|
+
* }
|
|
21
|
+
* ```;
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* interface User {
|
|
26
|
+
* profile: {
|
|
27
|
+
* bio: string;
|
|
28
|
+
* tags: string[];
|
|
29
|
+
* } & Example<{ bio: "Software engineer", tags: ["typescript", "react"] }>;
|
|
30
|
+
* }
|
|
31
|
+
* ```;
|
|
32
|
+
*
|
|
33
|
+
* @template Value The example value (primitives, objects, arrays, or null)
|
|
34
|
+
*/
|
|
35
|
+
export type Example<
|
|
36
|
+
Value extends
|
|
37
|
+
| boolean
|
|
38
|
+
| bigint
|
|
39
|
+
| number
|
|
40
|
+
| string
|
|
41
|
+
| object
|
|
42
|
+
| Array<unknown>
|
|
43
|
+
| null,
|
|
44
|
+
> = TagBase<{
|
|
45
|
+
target: "boolean" | "bigint" | "number" | "string" | "array" | "object";
|
|
46
|
+
kind: "example";
|
|
47
|
+
value: Value;
|
|
48
|
+
exclusive: true;
|
|
49
|
+
schema: Value extends bigint
|
|
50
|
+
? { example: Numeric<Value> }
|
|
51
|
+
: { example: Value };
|
|
52
|
+
}>;
|
|
53
|
+
|
|
54
|
+
type Numeric<T extends bigint> = `${T}` extends `${infer N extends number}`
|
|
55
|
+
? N
|
|
56
|
+
: never;
|
package/src/tags/Examples.ts
CHANGED
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
import { TagBase } from "./TagBase";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Multiple examples tag that provides named example values for documentation.
|
|
5
|
-
*
|
|
6
|
-
* Unlike the Example tag which provides a single example, Examples allows you
|
|
7
|
-
* to provide multiple labeled examples. This is particularly useful when you
|
|
8
|
-
* want to show different scenarios or use cases for the same type.
|
|
9
|
-
*
|
|
10
|
-
* The examples are added to JSON Schema as an object where keys are descriptive
|
|
11
|
-
* names and values are the example data. This helps in API documentation and
|
|
12
|
-
* test case generation.
|
|
13
|
-
*
|
|
14
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
15
|
-
* @example
|
|
16
|
-
* ```typescript
|
|
17
|
-
* interface PaymentRequest {
|
|
18
|
-
* amount: number & Examples<{
|
|
19
|
-
* small: 10.50,
|
|
20
|
-
* medium: 99.99,
|
|
21
|
-
* large: 1000.00
|
|
22
|
-
* }>;
|
|
23
|
-
* }
|
|
24
|
-
* ```;
|
|
25
|
-
*
|
|
26
|
-
* @example
|
|
27
|
-
* ```typescript
|
|
28
|
-
* interface UserStatus {
|
|
29
|
-
* state: string & Examples<{
|
|
30
|
-
* active: "active",
|
|
31
|
-
* inactive: "inactive",
|
|
32
|
-
* suspended: "suspended"
|
|
33
|
-
* }>;
|
|
34
|
-
* profile: object & Examples<{
|
|
35
|
-
* basic: { name: "John", age: 25 },
|
|
36
|
-
* detailed: { name: "Jane", age: 30, bio: "Developer", verified: true }
|
|
37
|
-
* }>;
|
|
38
|
-
* }
|
|
39
|
-
* ```;
|
|
40
|
-
*
|
|
41
|
-
* @template Value A record object mapping example names to example values
|
|
42
|
-
*/
|
|
43
|
-
export type Examples<
|
|
44
|
-
Value extends Record<
|
|
45
|
-
string,
|
|
46
|
-
boolean | bigint | number | string | object | Array<unknown> | null
|
|
47
|
-
>,
|
|
48
|
-
> = TagBase<{
|
|
49
|
-
target: "boolean" | "bigint" | "number" | "string" | "array" | "object";
|
|
50
|
-
kind: "examples";
|
|
51
|
-
value: Value;
|
|
52
|
-
exclusive: true;
|
|
53
|
-
schema: {
|
|
54
|
-
examples: Value;
|
|
55
|
-
};
|
|
56
|
-
}>;
|
|
1
|
+
import { TagBase } from "./TagBase";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Multiple examples tag that provides named example values for documentation.
|
|
5
|
+
*
|
|
6
|
+
* Unlike the Example tag which provides a single example, Examples allows you
|
|
7
|
+
* to provide multiple labeled examples. This is particularly useful when you
|
|
8
|
+
* want to show different scenarios or use cases for the same type.
|
|
9
|
+
*
|
|
10
|
+
* The examples are added to JSON Schema as an object where keys are descriptive
|
|
11
|
+
* names and values are the example data. This helps in API documentation and
|
|
12
|
+
* test case generation.
|
|
13
|
+
*
|
|
14
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* interface PaymentRequest {
|
|
18
|
+
* amount: number & Examples<{
|
|
19
|
+
* small: 10.50,
|
|
20
|
+
* medium: 99.99,
|
|
21
|
+
* large: 1000.00
|
|
22
|
+
* }>;
|
|
23
|
+
* }
|
|
24
|
+
* ```;
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* interface UserStatus {
|
|
29
|
+
* state: string & Examples<{
|
|
30
|
+
* active: "active",
|
|
31
|
+
* inactive: "inactive",
|
|
32
|
+
* suspended: "suspended"
|
|
33
|
+
* }>;
|
|
34
|
+
* profile: object & Examples<{
|
|
35
|
+
* basic: { name: "John", age: 25 },
|
|
36
|
+
* detailed: { name: "Jane", age: 30, bio: "Developer", verified: true }
|
|
37
|
+
* }>;
|
|
38
|
+
* }
|
|
39
|
+
* ```;
|
|
40
|
+
*
|
|
41
|
+
* @template Value A record object mapping example names to example values
|
|
42
|
+
*/
|
|
43
|
+
export type Examples<
|
|
44
|
+
Value extends Record<
|
|
45
|
+
string,
|
|
46
|
+
boolean | bigint | number | string | object | Array<unknown> | null
|
|
47
|
+
>,
|
|
48
|
+
> = TagBase<{
|
|
49
|
+
target: "boolean" | "bigint" | "number" | "string" | "array" | "object";
|
|
50
|
+
kind: "examples";
|
|
51
|
+
value: Value;
|
|
52
|
+
exclusive: true;
|
|
53
|
+
schema: {
|
|
54
|
+
examples: Value;
|
|
55
|
+
};
|
|
56
|
+
}>;
|
|
@@ -1,44 +1,44 @@
|
|
|
1
|
-
import { TagBase } from "./TagBase";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Exclusive maximum value constraint tag.
|
|
5
|
-
*
|
|
6
|
-
* Enforces that a numeric value must be strictly less than the specified
|
|
7
|
-
* maximum (not equal). This constraint validates that the input value
|
|
8
|
-
* satisfies: input < maximum.
|
|
9
|
-
*
|
|
10
|
-
* Example usage:
|
|
11
|
-
*
|
|
12
|
-
* ```typescript
|
|
13
|
-
* type Discount = number & tags.ExclusiveMaximum<100>; // Must be < 100
|
|
14
|
-
* type ByteValue = bigint & tags.ExclusiveMaximum<256n>; // Must be < 256
|
|
15
|
-
* ```
|
|
16
|
-
*
|
|
17
|
-
* Note: This tag is mutually exclusive with Maximum. You cannot apply both
|
|
18
|
-
* ExclusiveMaximum and Maximum constraints to the same property.
|
|
19
|
-
*
|
|
20
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
21
|
-
* @template Value - The exclusive maximum value constraint (number or bigint
|
|
22
|
-
* literal)
|
|
23
|
-
*/
|
|
24
|
-
export type ExclusiveMaximum<Value extends number | bigint> = TagBase<{
|
|
25
|
-
target: Value extends bigint ? "bigint" : "number";
|
|
26
|
-
kind: "exclusiveMaximum";
|
|
27
|
-
value: Value;
|
|
28
|
-
validate: `$input < ${Cast<Value>}`;
|
|
29
|
-
exclusive: ["exclusiveMaximum", "maximum"];
|
|
30
|
-
schema: Value extends bigint
|
|
31
|
-
? {
|
|
32
|
-
exclusiveMaximum: Numeric<Value>;
|
|
33
|
-
}
|
|
34
|
-
: {
|
|
35
|
-
exclusiveMaximum: Value;
|
|
36
|
-
};
|
|
37
|
-
}>;
|
|
38
|
-
|
|
39
|
-
type Cast<Value extends number | bigint> = Value extends number
|
|
40
|
-
? Value
|
|
41
|
-
: `BigInt(${Value})`;
|
|
42
|
-
type Numeric<T extends bigint> = `${T}` extends `${infer N extends number}`
|
|
43
|
-
? N
|
|
44
|
-
: never;
|
|
1
|
+
import { TagBase } from "./TagBase";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Exclusive maximum value constraint tag.
|
|
5
|
+
*
|
|
6
|
+
* Enforces that a numeric value must be strictly less than the specified
|
|
7
|
+
* maximum (not equal). This constraint validates that the input value
|
|
8
|
+
* satisfies: input < maximum.
|
|
9
|
+
*
|
|
10
|
+
* Example usage:
|
|
11
|
+
*
|
|
12
|
+
* ```typescript
|
|
13
|
+
* type Discount = number & tags.ExclusiveMaximum<100>; // Must be < 100
|
|
14
|
+
* type ByteValue = bigint & tags.ExclusiveMaximum<256n>; // Must be < 256
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* Note: This tag is mutually exclusive with Maximum. You cannot apply both
|
|
18
|
+
* ExclusiveMaximum and Maximum constraints to the same property.
|
|
19
|
+
*
|
|
20
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
21
|
+
* @template Value - The exclusive maximum value constraint (number or bigint
|
|
22
|
+
* literal)
|
|
23
|
+
*/
|
|
24
|
+
export type ExclusiveMaximum<Value extends number | bigint> = TagBase<{
|
|
25
|
+
target: Value extends bigint ? "bigint" : "number";
|
|
26
|
+
kind: "exclusiveMaximum";
|
|
27
|
+
value: Value;
|
|
28
|
+
validate: `$input < ${Cast<Value>}`;
|
|
29
|
+
exclusive: ["exclusiveMaximum", "maximum"];
|
|
30
|
+
schema: Value extends bigint
|
|
31
|
+
? {
|
|
32
|
+
exclusiveMaximum: Numeric<Value>;
|
|
33
|
+
}
|
|
34
|
+
: {
|
|
35
|
+
exclusiveMaximum: Value;
|
|
36
|
+
};
|
|
37
|
+
}>;
|
|
38
|
+
|
|
39
|
+
type Cast<Value extends number | bigint> = Value extends number
|
|
40
|
+
? Value
|
|
41
|
+
: `BigInt(${Value})`;
|
|
42
|
+
type Numeric<T extends bigint> = `${T}` extends `${infer N extends number}`
|
|
43
|
+
? N
|
|
44
|
+
: never;
|
|
@@ -1,44 +1,44 @@
|
|
|
1
|
-
import { TagBase } from "./TagBase";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Exclusive minimum value constraint tag.
|
|
5
|
-
*
|
|
6
|
-
* Enforces that a numeric value must be strictly greater than the specified
|
|
7
|
-
* minimum (not equal). This constraint validates that the input value
|
|
8
|
-
* satisfies: input > minimum.
|
|
9
|
-
*
|
|
10
|
-
* Example usage:
|
|
11
|
-
*
|
|
12
|
-
* ```typescript
|
|
13
|
-
* type PositiveNumber = number & tags.ExclusiveMinimum<0>; // Must be > 0
|
|
14
|
-
* type LargeCount = bigint & tags.ExclusiveMinimum<999n>; // Must be > 999
|
|
15
|
-
* ```
|
|
16
|
-
*
|
|
17
|
-
* Note: This tag is mutually exclusive with Minimum. You cannot apply both
|
|
18
|
-
* ExclusiveMinimum and Minimum constraints to the same property.
|
|
19
|
-
*
|
|
20
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
21
|
-
* @template Value - The exclusive minimum value constraint (number or bigint
|
|
22
|
-
* literal)
|
|
23
|
-
*/
|
|
24
|
-
export type ExclusiveMinimum<Value extends number | bigint> = TagBase<{
|
|
25
|
-
target: Value extends bigint ? "bigint" : "number";
|
|
26
|
-
kind: "exclusiveMinimum";
|
|
27
|
-
value: Value;
|
|
28
|
-
validate: `${Cast<Value>} < $input`;
|
|
29
|
-
exclusive: ["exclusiveMinimum", "minimum"];
|
|
30
|
-
schema: Value extends bigint
|
|
31
|
-
? {
|
|
32
|
-
exclusiveMinimum: Numeric<Value>;
|
|
33
|
-
}
|
|
34
|
-
: {
|
|
35
|
-
exclusiveMinimum: Value;
|
|
36
|
-
};
|
|
37
|
-
}>;
|
|
38
|
-
|
|
39
|
-
type Cast<Value extends number | bigint> = Value extends number
|
|
40
|
-
? Value
|
|
41
|
-
: `BigInt(${Value})`;
|
|
42
|
-
type Numeric<T extends bigint> = `${T}` extends `${infer N extends number}`
|
|
43
|
-
? N
|
|
44
|
-
: never;
|
|
1
|
+
import { TagBase } from "./TagBase";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Exclusive minimum value constraint tag.
|
|
5
|
+
*
|
|
6
|
+
* Enforces that a numeric value must be strictly greater than the specified
|
|
7
|
+
* minimum (not equal). This constraint validates that the input value
|
|
8
|
+
* satisfies: input > minimum.
|
|
9
|
+
*
|
|
10
|
+
* Example usage:
|
|
11
|
+
*
|
|
12
|
+
* ```typescript
|
|
13
|
+
* type PositiveNumber = number & tags.ExclusiveMinimum<0>; // Must be > 0
|
|
14
|
+
* type LargeCount = bigint & tags.ExclusiveMinimum<999n>; // Must be > 999
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* Note: This tag is mutually exclusive with Minimum. You cannot apply both
|
|
18
|
+
* ExclusiveMinimum and Minimum constraints to the same property.
|
|
19
|
+
*
|
|
20
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
21
|
+
* @template Value - The exclusive minimum value constraint (number or bigint
|
|
22
|
+
* literal)
|
|
23
|
+
*/
|
|
24
|
+
export type ExclusiveMinimum<Value extends number | bigint> = TagBase<{
|
|
25
|
+
target: Value extends bigint ? "bigint" : "number";
|
|
26
|
+
kind: "exclusiveMinimum";
|
|
27
|
+
value: Value;
|
|
28
|
+
validate: `${Cast<Value>} < $input`;
|
|
29
|
+
exclusive: ["exclusiveMinimum", "minimum"];
|
|
30
|
+
schema: Value extends bigint
|
|
31
|
+
? {
|
|
32
|
+
exclusiveMinimum: Numeric<Value>;
|
|
33
|
+
}
|
|
34
|
+
: {
|
|
35
|
+
exclusiveMinimum: Value;
|
|
36
|
+
};
|
|
37
|
+
}>;
|
|
38
|
+
|
|
39
|
+
type Cast<Value extends number | bigint> = Value extends number
|
|
40
|
+
? Value
|
|
41
|
+
: `BigInt(${Value})`;
|
|
42
|
+
type Numeric<T extends bigint> = `${T}` extends `${infer N extends number}`
|
|
43
|
+
? N
|
|
44
|
+
: never;
|
package/src/tags/Format.ts
CHANGED
|
@@ -1,78 +1,78 @@
|
|
|
1
|
-
import type { TagBase } from "./TagBase";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* String format constraint tag.
|
|
5
|
-
*
|
|
6
|
-
* Validates strings against predefined formats for common use cases. This tag
|
|
7
|
-
* provides built-in validation for standard string formats without needing to
|
|
8
|
-
* write custom regular expressions.
|
|
9
|
-
*
|
|
10
|
-
* Examples:
|
|
11
|
-
*
|
|
12
|
-
* ```ts
|
|
13
|
-
* Type Email = string & Format<"email">; // user@example.com
|
|
14
|
-
* Type WebURL = string & Format<"url">; // https://example.com
|
|
15
|
-
* Type DateTime = string & Format<"date-time">; // 2024-01-15T10:30:00Z
|
|
16
|
-
* ```
|
|
17
|
-
*
|
|
18
|
-
* Supported formats include:
|
|
19
|
-
*
|
|
20
|
-
* - Network: email, url, hostname, ipv4, ipv6, uri
|
|
21
|
-
* - Identifiers: uuid, byte, password
|
|
22
|
-
* - Date/Time: date, time, date-time, duration
|
|
23
|
-
* - Data: json-pointer, regex
|
|
24
|
-
* - Internationalized: idn-email, idn-hostname, iri
|
|
25
|
-
*
|
|
26
|
-
* Note: This tag is mutually exclusive with the Pattern tag. You cannot use
|
|
27
|
-
* both Format and Pattern on the same type.
|
|
28
|
-
*
|
|
29
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
30
|
-
*/
|
|
31
|
-
export type Format<Value extends Format.Value> = TagBase<{
|
|
32
|
-
target: "string";
|
|
33
|
-
kind: "format";
|
|
34
|
-
value: Value;
|
|
35
|
-
validate: `$importInternal("isFormat${PascalizeString<Value>}")($input)`;
|
|
36
|
-
exclusive: ["format", "pattern"];
|
|
37
|
-
schema: {
|
|
38
|
-
format: Value;
|
|
39
|
-
};
|
|
40
|
-
}>;
|
|
41
|
-
export namespace Format {
|
|
42
|
-
export type Value =
|
|
43
|
-
| "byte"
|
|
44
|
-
| "password"
|
|
45
|
-
| "regex"
|
|
46
|
-
| "uuid"
|
|
47
|
-
| "email"
|
|
48
|
-
| "hostname"
|
|
49
|
-
| "idn-email"
|
|
50
|
-
| "idn-hostname"
|
|
51
|
-
| "iri"
|
|
52
|
-
| "iri-reference"
|
|
53
|
-
| "ipv4"
|
|
54
|
-
| "ipv6"
|
|
55
|
-
| "uri"
|
|
56
|
-
| "uri-reference"
|
|
57
|
-
| "uri-template"
|
|
58
|
-
| "url"
|
|
59
|
-
| "date-time"
|
|
60
|
-
| "date"
|
|
61
|
-
| "time"
|
|
62
|
-
| "duration"
|
|
63
|
-
| "json-pointer"
|
|
64
|
-
| "relative-json-pointer";
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
type PascalizeString<Key extends string> = Key extends `-${infer R}`
|
|
68
|
-
? `${PascalizeString<R>}`
|
|
69
|
-
: Key extends `${infer _F}-${infer _R}`
|
|
70
|
-
? PascalizeSnakeString<Key>
|
|
71
|
-
: Capitalize<Key>;
|
|
72
|
-
type PascalizeSnakeString<Key extends string> = Key extends `-${infer R}`
|
|
73
|
-
? PascalizeSnakeString<R>
|
|
74
|
-
: Key extends `${infer F}${infer M}-${infer R}`
|
|
75
|
-
? `${Uppercase<F>}${Lowercase<M>}${PascalizeSnakeString<R>}`
|
|
76
|
-
: Key extends `${infer F}${infer R}`
|
|
77
|
-
? `${Uppercase<F>}${Lowercase<R>}`
|
|
78
|
-
: Key;
|
|
1
|
+
import type { TagBase } from "./TagBase";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* String format constraint tag.
|
|
5
|
+
*
|
|
6
|
+
* Validates strings against predefined formats for common use cases. This tag
|
|
7
|
+
* provides built-in validation for standard string formats without needing to
|
|
8
|
+
* write custom regular expressions.
|
|
9
|
+
*
|
|
10
|
+
* Examples:
|
|
11
|
+
*
|
|
12
|
+
* ```ts
|
|
13
|
+
* Type Email = string & Format<"email">; // user@example.com
|
|
14
|
+
* Type WebURL = string & Format<"url">; // https://example.com
|
|
15
|
+
* Type DateTime = string & Format<"date-time">; // 2024-01-15T10:30:00Z
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* Supported formats include:
|
|
19
|
+
*
|
|
20
|
+
* - Network: email, url, hostname, ipv4, ipv6, uri
|
|
21
|
+
* - Identifiers: uuid, byte, password
|
|
22
|
+
* - Date/Time: date, time, date-time, duration
|
|
23
|
+
* - Data: json-pointer, regex
|
|
24
|
+
* - Internationalized: idn-email, idn-hostname, iri
|
|
25
|
+
*
|
|
26
|
+
* Note: This tag is mutually exclusive with the Pattern tag. You cannot use
|
|
27
|
+
* both Format and Pattern on the same type.
|
|
28
|
+
*
|
|
29
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
30
|
+
*/
|
|
31
|
+
export type Format<Value extends Format.Value> = TagBase<{
|
|
32
|
+
target: "string";
|
|
33
|
+
kind: "format";
|
|
34
|
+
value: Value;
|
|
35
|
+
validate: `$importInternal("isFormat${PascalizeString<Value>}")($input)`;
|
|
36
|
+
exclusive: ["format", "pattern"];
|
|
37
|
+
schema: {
|
|
38
|
+
format: Value;
|
|
39
|
+
};
|
|
40
|
+
}>;
|
|
41
|
+
export namespace Format {
|
|
42
|
+
export type Value =
|
|
43
|
+
| "byte"
|
|
44
|
+
| "password"
|
|
45
|
+
| "regex"
|
|
46
|
+
| "uuid"
|
|
47
|
+
| "email"
|
|
48
|
+
| "hostname"
|
|
49
|
+
| "idn-email"
|
|
50
|
+
| "idn-hostname"
|
|
51
|
+
| "iri"
|
|
52
|
+
| "iri-reference"
|
|
53
|
+
| "ipv4"
|
|
54
|
+
| "ipv6"
|
|
55
|
+
| "uri"
|
|
56
|
+
| "uri-reference"
|
|
57
|
+
| "uri-template"
|
|
58
|
+
| "url"
|
|
59
|
+
| "date-time"
|
|
60
|
+
| "date"
|
|
61
|
+
| "time"
|
|
62
|
+
| "duration"
|
|
63
|
+
| "json-pointer"
|
|
64
|
+
| "relative-json-pointer";
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
type PascalizeString<Key extends string> = Key extends `-${infer R}`
|
|
68
|
+
? `${PascalizeString<R>}`
|
|
69
|
+
: Key extends `${infer _F}-${infer _R}`
|
|
70
|
+
? PascalizeSnakeString<Key>
|
|
71
|
+
: Capitalize<Key>;
|
|
72
|
+
type PascalizeSnakeString<Key extends string> = Key extends `-${infer R}`
|
|
73
|
+
? PascalizeSnakeString<R>
|
|
74
|
+
: Key extends `${infer F}${infer M}-${infer R}`
|
|
75
|
+
? `${Uppercase<F>}${Lowercase<M>}${PascalizeSnakeString<R>}`
|
|
76
|
+
: Key extends `${infer F}${infer R}`
|
|
77
|
+
? `${Uppercase<F>}${Lowercase<R>}`
|
|
78
|
+
: Key;
|
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
import { TagBase } from "./TagBase";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Injects custom properties into generated JSON Schema.
|
|
5
|
-
*
|
|
6
|
-
* The JsonSchemaPlugin tag allows you to add vendor-specific extensions or
|
|
7
|
-
* custom metadata to the generated JSON Schema output. These properties are
|
|
8
|
-
* merged at the root level of the schema and are commonly used for
|
|
9
|
-
* documentation, tooling hints, or API-specific metadata. The custom properties
|
|
10
|
-
* only affect schema generation and do not impact runtime validation.
|
|
11
|
-
*
|
|
12
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
13
|
-
* @example
|
|
14
|
-
* ```typescript
|
|
15
|
-
* // Add OpenAPI vendor extensions
|
|
16
|
-
* type UserId = string & JsonSchemaPlugin<{
|
|
17
|
-
* "x-internal-id": true,
|
|
18
|
-
* "x-deprecated": "Use UUID instead"
|
|
19
|
-
* }>;
|
|
20
|
-
*
|
|
21
|
-
* // Add custom documentation metadata
|
|
22
|
-
* type Price = number & JsonSchemaPlugin<{
|
|
23
|
-
* "x-format": "currency",
|
|
24
|
-
* "x-example": 19.99
|
|
25
|
-
* }>;
|
|
26
|
-
* ```
|
|
27
|
-
*
|
|
28
|
-
* @template Schema - Object containing custom properties to add to the JSON
|
|
29
|
-
* Schema
|
|
30
|
-
*/
|
|
31
|
-
export type JsonSchemaPlugin<Schema extends object> = TagBase<{
|
|
32
|
-
target: "string" | "boolean" | "bigint" | "number" | "array" | "object";
|
|
33
|
-
kind: "jsonPlugin";
|
|
34
|
-
value: undefined;
|
|
35
|
-
schema: Schema;
|
|
36
|
-
}>;
|
|
1
|
+
import { TagBase } from "./TagBase";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Injects custom properties into generated JSON Schema.
|
|
5
|
+
*
|
|
6
|
+
* The JsonSchemaPlugin tag allows you to add vendor-specific extensions or
|
|
7
|
+
* custom metadata to the generated JSON Schema output. These properties are
|
|
8
|
+
* merged at the root level of the schema and are commonly used for
|
|
9
|
+
* documentation, tooling hints, or API-specific metadata. The custom properties
|
|
10
|
+
* only affect schema generation and do not impact runtime validation.
|
|
11
|
+
*
|
|
12
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* // Add OpenAPI vendor extensions
|
|
16
|
+
* type UserId = string & JsonSchemaPlugin<{
|
|
17
|
+
* "x-internal-id": true,
|
|
18
|
+
* "x-deprecated": "Use UUID instead"
|
|
19
|
+
* }>;
|
|
20
|
+
*
|
|
21
|
+
* // Add custom documentation metadata
|
|
22
|
+
* type Price = number & JsonSchemaPlugin<{
|
|
23
|
+
* "x-format": "currency",
|
|
24
|
+
* "x-example": 19.99
|
|
25
|
+
* }>;
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @template Schema - Object containing custom properties to add to the JSON
|
|
29
|
+
* Schema
|
|
30
|
+
*/
|
|
31
|
+
export type JsonSchemaPlugin<Schema extends object> = TagBase<{
|
|
32
|
+
target: "string" | "boolean" | "bigint" | "number" | "array" | "object";
|
|
33
|
+
kind: "jsonPlugin";
|
|
34
|
+
value: undefined;
|
|
35
|
+
schema: Schema;
|
|
36
|
+
}>;
|