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
|
@@ -1,78 +1,78 @@
|
|
|
1
|
-
import { ClassProperties } from "../../typings/ClassProperties";
|
|
2
|
-
|
|
3
|
-
import { IMetadataDictionary } from "./IMetadataDictionary";
|
|
4
|
-
import { IMetadataTemplate } from "./IMetadataTemplate";
|
|
5
|
-
import { IMetadataTypeTag } from "./IMetadataTypeTag";
|
|
6
|
-
import { Metadata } from "./Metadata";
|
|
7
|
-
|
|
8
|
-
export class MetadataTemplate {
|
|
9
|
-
public readonly row: Metadata[];
|
|
10
|
-
public readonly tags: IMetadataTypeTag[][];
|
|
11
|
-
|
|
12
|
-
private name_?: string;
|
|
13
|
-
|
|
14
|
-
private constructor(props: ClassProperties<MetadataTemplate>) {
|
|
15
|
-
this.row = props.row.map(Metadata.create);
|
|
16
|
-
this.tags = props.tags;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
public static create(
|
|
20
|
-
props: ClassProperties<MetadataTemplate>,
|
|
21
|
-
): MetadataTemplate {
|
|
22
|
-
return new MetadataTemplate(props);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
public static from(
|
|
26
|
-
json: IMetadataTemplate,
|
|
27
|
-
dict: IMetadataDictionary,
|
|
28
|
-
): MetadataTemplate {
|
|
29
|
-
return new MetadataTemplate({
|
|
30
|
-
row: json.row.map((m) => Metadata.from(m, dict)),
|
|
31
|
-
tags: json.tags,
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
public getName(): string {
|
|
36
|
-
return (this.name_ ??= getName(this));
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/** @internal */
|
|
40
|
-
public getBaseName(): string {
|
|
41
|
-
return (
|
|
42
|
-
"`" +
|
|
43
|
-
this.row
|
|
44
|
-
.map((child) =>
|
|
45
|
-
child.isConstant() && child.size() === 1
|
|
46
|
-
? child.constants[0]!.values[0]!.value
|
|
47
|
-
: `$\{${child.getName()}\}`,
|
|
48
|
-
)
|
|
49
|
-
.join("")
|
|
50
|
-
.split("`")
|
|
51
|
-
.join("\\`") +
|
|
52
|
-
"`"
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
public toJSON(): IMetadataTemplate {
|
|
57
|
-
return {
|
|
58
|
-
row: this.row.map((m) => m.toJSON()),
|
|
59
|
-
tags: this.tags,
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const getName = (template: MetadataTemplate): string => {
|
|
65
|
-
const base: string = template.getBaseName();
|
|
66
|
-
if (!template.tags?.length) return base;
|
|
67
|
-
else if (template.tags.length === 1) {
|
|
68
|
-
const str: string = [base, ...template.tags[0]!.map((t) => t.name)].join(
|
|
69
|
-
" & ",
|
|
70
|
-
);
|
|
71
|
-
return `(${str})`;
|
|
72
|
-
}
|
|
73
|
-
const rows: string[] = template.tags.map((row) => {
|
|
74
|
-
const str: string = row.map((t) => t.name).join(" & ");
|
|
75
|
-
return row.length === 1 ? str : `(${str})`;
|
|
76
|
-
});
|
|
77
|
-
return `(${base} & (${rows.join(" | ")}))`;
|
|
78
|
-
};
|
|
1
|
+
import { ClassProperties } from "../../typings/ClassProperties";
|
|
2
|
+
|
|
3
|
+
import { IMetadataDictionary } from "./IMetadataDictionary";
|
|
4
|
+
import { IMetadataTemplate } from "./IMetadataTemplate";
|
|
5
|
+
import { IMetadataTypeTag } from "./IMetadataTypeTag";
|
|
6
|
+
import { Metadata } from "./Metadata";
|
|
7
|
+
|
|
8
|
+
export class MetadataTemplate {
|
|
9
|
+
public readonly row: Metadata[];
|
|
10
|
+
public readonly tags: IMetadataTypeTag[][];
|
|
11
|
+
|
|
12
|
+
private name_?: string;
|
|
13
|
+
|
|
14
|
+
private constructor(props: ClassProperties<MetadataTemplate>) {
|
|
15
|
+
this.row = props.row.map(Metadata.create);
|
|
16
|
+
this.tags = props.tags;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public static create(
|
|
20
|
+
props: ClassProperties<MetadataTemplate>,
|
|
21
|
+
): MetadataTemplate {
|
|
22
|
+
return new MetadataTemplate(props);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public static from(
|
|
26
|
+
json: IMetadataTemplate,
|
|
27
|
+
dict: IMetadataDictionary,
|
|
28
|
+
): MetadataTemplate {
|
|
29
|
+
return new MetadataTemplate({
|
|
30
|
+
row: json.row.map((m) => Metadata.from(m, dict)),
|
|
31
|
+
tags: json.tags,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
public getName(): string {
|
|
36
|
+
return (this.name_ ??= getName(this));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** @internal */
|
|
40
|
+
public getBaseName(): string {
|
|
41
|
+
return (
|
|
42
|
+
"`" +
|
|
43
|
+
this.row
|
|
44
|
+
.map((child) =>
|
|
45
|
+
child.isConstant() && child.size() === 1
|
|
46
|
+
? child.constants[0]!.values[0]!.value
|
|
47
|
+
: `$\{${child.getName()}\}`,
|
|
48
|
+
)
|
|
49
|
+
.join("")
|
|
50
|
+
.split("`")
|
|
51
|
+
.join("\\`") +
|
|
52
|
+
"`"
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
public toJSON(): IMetadataTemplate {
|
|
57
|
+
return {
|
|
58
|
+
row: this.row.map((m) => m.toJSON()),
|
|
59
|
+
tags: this.tags,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const getName = (template: MetadataTemplate): string => {
|
|
65
|
+
const base: string = template.getBaseName();
|
|
66
|
+
if (!template.tags?.length) return base;
|
|
67
|
+
else if (template.tags.length === 1) {
|
|
68
|
+
const str: string = [base, ...template.tags[0]!.map((t) => t.name)].join(
|
|
69
|
+
" & ",
|
|
70
|
+
);
|
|
71
|
+
return `(${str})`;
|
|
72
|
+
}
|
|
73
|
+
const rows: string[] = template.tags.map((row) => {
|
|
74
|
+
const str: string = row.map((t) => t.name).join(" & ");
|
|
75
|
+
return row.length === 1 ? str : `(${str})`;
|
|
76
|
+
});
|
|
77
|
+
return `(${base} & (${rows.join(" | ")}))`;
|
|
78
|
+
};
|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
import { ClassProperties } from "../../typings/ClassProperties";
|
|
2
|
-
|
|
3
|
-
import { IMetadataTuple } from "./IMetadataTuple";
|
|
4
|
-
import { IMetadataTypeTag } from "./IMetadataTypeTag";
|
|
5
|
-
import { MetadataTupleType } from "./MetadataTupleType";
|
|
6
|
-
|
|
7
|
-
export class MetadataTuple {
|
|
8
|
-
public readonly type: MetadataTupleType;
|
|
9
|
-
public readonly tags: IMetadataTypeTag[][];
|
|
10
|
-
|
|
11
|
-
/** @ignore */
|
|
12
|
-
private constructor(props: ClassProperties<MetadataTuple>) {
|
|
13
|
-
this.type = props.type;
|
|
14
|
-
this.tags = props.tags;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/** @internal */
|
|
18
|
-
public static create(props: ClassProperties<MetadataTuple>): MetadataTuple {
|
|
19
|
-
return new MetadataTuple(props);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
public toJSON(): IMetadataTuple {
|
|
23
|
-
return {
|
|
24
|
-
name: this.type.name,
|
|
25
|
-
tags: this.tags.map((row) => row.slice()),
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
}
|
|
1
|
+
import { ClassProperties } from "../../typings/ClassProperties";
|
|
2
|
+
|
|
3
|
+
import { IMetadataTuple } from "./IMetadataTuple";
|
|
4
|
+
import { IMetadataTypeTag } from "./IMetadataTypeTag";
|
|
5
|
+
import { MetadataTupleType } from "./MetadataTupleType";
|
|
6
|
+
|
|
7
|
+
export class MetadataTuple {
|
|
8
|
+
public readonly type: MetadataTupleType;
|
|
9
|
+
public readonly tags: IMetadataTypeTag[][];
|
|
10
|
+
|
|
11
|
+
/** @ignore */
|
|
12
|
+
private constructor(props: ClassProperties<MetadataTuple>) {
|
|
13
|
+
this.type = props.type;
|
|
14
|
+
this.tags = props.tags;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** @internal */
|
|
18
|
+
public static create(props: ClassProperties<MetadataTuple>): MetadataTuple {
|
|
19
|
+
return new MetadataTuple(props);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
public toJSON(): IMetadataTuple {
|
|
23
|
+
return {
|
|
24
|
+
name: this.type.name,
|
|
25
|
+
tags: this.tags.map((row) => row.slice()),
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -1,61 +1,61 @@
|
|
|
1
|
-
import { ClassProperties } from "../../typings/ClassProperties";
|
|
2
|
-
|
|
3
|
-
import { IMetadataTupleType } from "./IMetadataTupleType";
|
|
4
|
-
import { Metadata } from "./Metadata";
|
|
5
|
-
|
|
6
|
-
export class MetadataTupleType {
|
|
7
|
-
public readonly name: string;
|
|
8
|
-
public readonly elements: Metadata[];
|
|
9
|
-
|
|
10
|
-
public readonly index: number | null;
|
|
11
|
-
public readonly recursive: boolean;
|
|
12
|
-
public readonly nullables: boolean[];
|
|
13
|
-
|
|
14
|
-
/** @internal */
|
|
15
|
-
public of_map?: boolean;
|
|
16
|
-
|
|
17
|
-
/** @internal */
|
|
18
|
-
private constructor(props: ClassProperties<MetadataTupleType>) {
|
|
19
|
-
this.name = props.name;
|
|
20
|
-
this.elements = props.elements;
|
|
21
|
-
this.index = props.index;
|
|
22
|
-
this.recursive = props.recursive;
|
|
23
|
-
this.nullables = props.nullables;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/** @internal */
|
|
27
|
-
public static _From_without_elements(
|
|
28
|
-
props: Omit<IMetadataTupleType, "elements">,
|
|
29
|
-
): MetadataTupleType {
|
|
30
|
-
return MetadataTupleType.create({
|
|
31
|
-
name: props.name,
|
|
32
|
-
index: props.index,
|
|
33
|
-
elements: null!,
|
|
34
|
-
recursive: props.recursive,
|
|
35
|
-
nullables: props.nullables.slice(),
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
public static create(
|
|
40
|
-
props: ClassProperties<MetadataTupleType>,
|
|
41
|
-
): MetadataTupleType {
|
|
42
|
-
return new MetadataTupleType(props);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
public isRest(): boolean {
|
|
46
|
-
return (
|
|
47
|
-
this.elements.length > 0 &&
|
|
48
|
-
this.elements[this.elements.length - 1]!.rest !== null
|
|
49
|
-
);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
public toJSON(): IMetadataTupleType {
|
|
53
|
-
return {
|
|
54
|
-
name: this.name,
|
|
55
|
-
index: this.index,
|
|
56
|
-
elements: this.elements.map((elem) => elem.toJSON()),
|
|
57
|
-
recursive: this.recursive,
|
|
58
|
-
nullables: this.nullables.slice(),
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
}
|
|
1
|
+
import { ClassProperties } from "../../typings/ClassProperties";
|
|
2
|
+
|
|
3
|
+
import { IMetadataTupleType } from "./IMetadataTupleType";
|
|
4
|
+
import { Metadata } from "./Metadata";
|
|
5
|
+
|
|
6
|
+
export class MetadataTupleType {
|
|
7
|
+
public readonly name: string;
|
|
8
|
+
public readonly elements: Metadata[];
|
|
9
|
+
|
|
10
|
+
public readonly index: number | null;
|
|
11
|
+
public readonly recursive: boolean;
|
|
12
|
+
public readonly nullables: boolean[];
|
|
13
|
+
|
|
14
|
+
/** @internal */
|
|
15
|
+
public of_map?: boolean;
|
|
16
|
+
|
|
17
|
+
/** @internal */
|
|
18
|
+
private constructor(props: ClassProperties<MetadataTupleType>) {
|
|
19
|
+
this.name = props.name;
|
|
20
|
+
this.elements = props.elements;
|
|
21
|
+
this.index = props.index;
|
|
22
|
+
this.recursive = props.recursive;
|
|
23
|
+
this.nullables = props.nullables;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** @internal */
|
|
27
|
+
public static _From_without_elements(
|
|
28
|
+
props: Omit<IMetadataTupleType, "elements">,
|
|
29
|
+
): MetadataTupleType {
|
|
30
|
+
return MetadataTupleType.create({
|
|
31
|
+
name: props.name,
|
|
32
|
+
index: props.index,
|
|
33
|
+
elements: null!,
|
|
34
|
+
recursive: props.recursive,
|
|
35
|
+
nullables: props.nullables.slice(),
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
public static create(
|
|
40
|
+
props: ClassProperties<MetadataTupleType>,
|
|
41
|
+
): MetadataTupleType {
|
|
42
|
+
return new MetadataTupleType(props);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
public isRest(): boolean {
|
|
46
|
+
return (
|
|
47
|
+
this.elements.length > 0 &&
|
|
48
|
+
this.elements[this.elements.length - 1]!.rest !== null
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
public toJSON(): IMetadataTupleType {
|
|
53
|
+
return {
|
|
54
|
+
name: this.name,
|
|
55
|
+
index: this.index,
|
|
56
|
+
elements: this.elements.map((elem) => elem.toJSON()),
|
|
57
|
+
recursive: this.recursive,
|
|
58
|
+
nullables: this.nullables.slice(),
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
}
|
package/src/tags/Constant.ts
CHANGED
|
@@ -1,47 +1,47 @@
|
|
|
1
|
-
import { TagBase } from "./TagBase";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Constant tag that adds title and description metadata to literal types.
|
|
5
|
-
*
|
|
6
|
-
* This tag enhances literal values with human-readable documentation without
|
|
7
|
-
* changing their runtime type. It's particularly useful for enum-like values
|
|
8
|
-
* where you want to provide context about what each value represents.
|
|
9
|
-
*
|
|
10
|
-
* The metadata appears in generated JSON Schema, making API documentation more
|
|
11
|
-
* descriptive and helping developers understand the meaning of specific
|
|
12
|
-
* constant values.
|
|
13
|
-
*
|
|
14
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
15
|
-
* @example
|
|
16
|
-
* ```typescript
|
|
17
|
-
* type Status =
|
|
18
|
-
* | Constant<"active", { title: "Active", description: "User is currently active" }>
|
|
19
|
-
* | Constant<"inactive", { title: "Inactive", description: "User account is disabled" }>
|
|
20
|
-
* | Constant<"pending", { title: "Pending", description: "Awaiting verification" }>;
|
|
21
|
-
* ```;
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* ```typescript
|
|
25
|
-
* interface Config {
|
|
26
|
-
* debugLevel: Constant<0, { title: "Off", description: "No debug output" }>
|
|
27
|
-
* | Constant<1, { title: "Basic", description: "Basic logging" }>
|
|
28
|
-
* | Constant<2, { title: "Verbose", description: "Detailed debug info" }>;
|
|
29
|
-
* }
|
|
30
|
-
* ```;
|
|
31
|
-
*
|
|
32
|
-
* @template Value The literal value (boolean, number, string, or bigint)
|
|
33
|
-
* @template Content Metadata with optional title and description
|
|
34
|
-
*/
|
|
35
|
-
export type Constant<
|
|
36
|
-
Value extends boolean | number | string | bigint,
|
|
37
|
-
Content extends {
|
|
38
|
-
title?: string | undefined;
|
|
39
|
-
description?: string | undefined;
|
|
40
|
-
},
|
|
41
|
-
> = Value &
|
|
42
|
-
TagBase<{
|
|
43
|
-
target: "string" | "boolean" | "number" | "bigint";
|
|
44
|
-
kind: "constant";
|
|
45
|
-
value: undefined;
|
|
46
|
-
schema: Content;
|
|
47
|
-
}>;
|
|
1
|
+
import { TagBase } from "./TagBase";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Constant tag that adds title and description metadata to literal types.
|
|
5
|
+
*
|
|
6
|
+
* This tag enhances literal values with human-readable documentation without
|
|
7
|
+
* changing their runtime type. It's particularly useful for enum-like values
|
|
8
|
+
* where you want to provide context about what each value represents.
|
|
9
|
+
*
|
|
10
|
+
* The metadata appears in generated JSON Schema, making API documentation more
|
|
11
|
+
* descriptive and helping developers understand the meaning of specific
|
|
12
|
+
* constant values.
|
|
13
|
+
*
|
|
14
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* type Status =
|
|
18
|
+
* | Constant<"active", { title: "Active", description: "User is currently active" }>
|
|
19
|
+
* | Constant<"inactive", { title: "Inactive", description: "User account is disabled" }>
|
|
20
|
+
* | Constant<"pending", { title: "Pending", description: "Awaiting verification" }>;
|
|
21
|
+
* ```;
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* interface Config {
|
|
26
|
+
* debugLevel: Constant<0, { title: "Off", description: "No debug output" }>
|
|
27
|
+
* | Constant<1, { title: "Basic", description: "Basic logging" }>
|
|
28
|
+
* | Constant<2, { title: "Verbose", description: "Detailed debug info" }>;
|
|
29
|
+
* }
|
|
30
|
+
* ```;
|
|
31
|
+
*
|
|
32
|
+
* @template Value The literal value (boolean, number, string, or bigint)
|
|
33
|
+
* @template Content Metadata with optional title and description
|
|
34
|
+
*/
|
|
35
|
+
export type Constant<
|
|
36
|
+
Value extends boolean | number | string | bigint,
|
|
37
|
+
Content extends {
|
|
38
|
+
title?: string | undefined;
|
|
39
|
+
description?: string | undefined;
|
|
40
|
+
},
|
|
41
|
+
> = Value &
|
|
42
|
+
TagBase<{
|
|
43
|
+
target: "string" | "boolean" | "number" | "bigint";
|
|
44
|
+
kind: "constant";
|
|
45
|
+
value: undefined;
|
|
46
|
+
schema: Content;
|
|
47
|
+
}>;
|
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
import { TagBase } from "./TagBase";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* String content media type constraint tag.
|
|
5
|
-
*
|
|
6
|
-
* Specifies the MIME type of string content for proper interpretation. This tag
|
|
7
|
-
* serves as metadata to indicate how the string content should be interpreted,
|
|
8
|
-
* but does not perform validation on the content itself.
|
|
9
|
-
*
|
|
10
|
-
* Examples: type JsonData = string & ContentMediaType<"application/json">; //
|
|
11
|
-
* JSON string type Base64Image = string & ContentMediaType<"image/png">; //
|
|
12
|
-
* Base64 PNG type XmlContent = string & ContentMediaType<"application/xml">; //
|
|
13
|
-
* XML data
|
|
14
|
-
*
|
|
15
|
-
* Common MIME types: application/json, text/html, image/jpeg, image/png,
|
|
16
|
-
* application/pdf, text/plain, application/xml, and many more.
|
|
17
|
-
*
|
|
18
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
19
|
-
*/
|
|
20
|
-
export type ContentMediaType<Value extends string> = TagBase<{
|
|
21
|
-
target: "string";
|
|
22
|
-
kind: "contentMediaType";
|
|
23
|
-
value: undefined;
|
|
24
|
-
schema: {
|
|
25
|
-
contentMediaType: Value;
|
|
26
|
-
};
|
|
27
|
-
}>;
|
|
1
|
+
import { TagBase } from "./TagBase";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* String content media type constraint tag.
|
|
5
|
+
*
|
|
6
|
+
* Specifies the MIME type of string content for proper interpretation. This tag
|
|
7
|
+
* serves as metadata to indicate how the string content should be interpreted,
|
|
8
|
+
* but does not perform validation on the content itself.
|
|
9
|
+
*
|
|
10
|
+
* Examples: type JsonData = string & ContentMediaType<"application/json">; //
|
|
11
|
+
* JSON string type Base64Image = string & ContentMediaType<"image/png">; //
|
|
12
|
+
* Base64 PNG type XmlContent = string & ContentMediaType<"application/xml">; //
|
|
13
|
+
* XML data
|
|
14
|
+
*
|
|
15
|
+
* Common MIME types: application/json, text/html, image/jpeg, image/png,
|
|
16
|
+
* application/pdf, text/plain, application/xml, and many more.
|
|
17
|
+
*
|
|
18
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
19
|
+
*/
|
|
20
|
+
export type ContentMediaType<Value extends string> = TagBase<{
|
|
21
|
+
target: "string";
|
|
22
|
+
kind: "contentMediaType";
|
|
23
|
+
value: undefined;
|
|
24
|
+
schema: {
|
|
25
|
+
contentMediaType: Value;
|
|
26
|
+
};
|
|
27
|
+
}>;
|
package/src/tags/Default.ts
CHANGED
|
@@ -1,52 +1,52 @@
|
|
|
1
|
-
import { TagBase } from "./TagBase";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Default value tag that specifies a default value for properties.
|
|
5
|
-
*
|
|
6
|
-
* When a property is not provided during validation, this tag instructs typia
|
|
7
|
-
* to use the specified default value. This is useful for optional properties
|
|
8
|
-
* that should have a specific fallback value.
|
|
9
|
-
*
|
|
10
|
-
* Supported types: boolean, bigint, number, and string primitives. Note:
|
|
11
|
-
* Default values are applied during validation, not at compile time.
|
|
12
|
-
*
|
|
13
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
14
|
-
* @example
|
|
15
|
-
* ```typescript
|
|
16
|
-
* interface User {
|
|
17
|
-
* name: string;
|
|
18
|
-
* active: boolean & Default<true>; // defaults to true if not provided
|
|
19
|
-
* retries: number & Default<3>; // defaults to 3 if not provided
|
|
20
|
-
* }
|
|
21
|
-
* ```;
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* ```typescript
|
|
25
|
-
* interface Config {
|
|
26
|
-
* timeout: bigint & Default<5000n>; // defaults to 5000n
|
|
27
|
-
* prefix: string & Default<"user_">; // defaults to "user_"
|
|
28
|
-
* }
|
|
29
|
-
* ```;
|
|
30
|
-
*
|
|
31
|
-
* @template Value The default value (boolean, bigint, number, or string)
|
|
32
|
-
*/
|
|
33
|
-
export type Default<Value extends boolean | bigint | number | string> =
|
|
34
|
-
TagBase<{
|
|
35
|
-
target: Value extends boolean
|
|
36
|
-
? "boolean"
|
|
37
|
-
: Value extends bigint
|
|
38
|
-
? "bigint"
|
|
39
|
-
: Value extends number
|
|
40
|
-
? "number"
|
|
41
|
-
: "string";
|
|
42
|
-
kind: "default";
|
|
43
|
-
value: Value;
|
|
44
|
-
exclusive: true;
|
|
45
|
-
schema: Value extends bigint
|
|
46
|
-
? { default: Numeric<Value> }
|
|
47
|
-
: { default: Value };
|
|
48
|
-
}>;
|
|
49
|
-
|
|
50
|
-
type Numeric<T extends bigint> = `${T}` extends `${infer N extends number}`
|
|
51
|
-
? N
|
|
52
|
-
: never;
|
|
1
|
+
import { TagBase } from "./TagBase";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Default value tag that specifies a default value for properties.
|
|
5
|
+
*
|
|
6
|
+
* When a property is not provided during validation, this tag instructs typia
|
|
7
|
+
* to use the specified default value. This is useful for optional properties
|
|
8
|
+
* that should have a specific fallback value.
|
|
9
|
+
*
|
|
10
|
+
* Supported types: boolean, bigint, number, and string primitives. Note:
|
|
11
|
+
* Default values are applied during validation, not at compile time.
|
|
12
|
+
*
|
|
13
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* interface User {
|
|
17
|
+
* name: string;
|
|
18
|
+
* active: boolean & Default<true>; // defaults to true if not provided
|
|
19
|
+
* retries: number & Default<3>; // defaults to 3 if not provided
|
|
20
|
+
* }
|
|
21
|
+
* ```;
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* interface Config {
|
|
26
|
+
* timeout: bigint & Default<5000n>; // defaults to 5000n
|
|
27
|
+
* prefix: string & Default<"user_">; // defaults to "user_"
|
|
28
|
+
* }
|
|
29
|
+
* ```;
|
|
30
|
+
*
|
|
31
|
+
* @template Value The default value (boolean, bigint, number, or string)
|
|
32
|
+
*/
|
|
33
|
+
export type Default<Value extends boolean | bigint | number | string> =
|
|
34
|
+
TagBase<{
|
|
35
|
+
target: Value extends boolean
|
|
36
|
+
? "boolean"
|
|
37
|
+
: Value extends bigint
|
|
38
|
+
? "bigint"
|
|
39
|
+
: Value extends number
|
|
40
|
+
? "number"
|
|
41
|
+
: "string";
|
|
42
|
+
kind: "default";
|
|
43
|
+
value: Value;
|
|
44
|
+
exclusive: true;
|
|
45
|
+
schema: Value extends bigint
|
|
46
|
+
? { default: Numeric<Value> }
|
|
47
|
+
: { default: Value };
|
|
48
|
+
}>;
|
|
49
|
+
|
|
50
|
+
type Numeric<T extends bigint> = `${T}` extends `${infer N extends number}`
|
|
51
|
+
? N
|
|
52
|
+
: never;
|