typebox 1.0.19 → 1.0.20
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/build/schema/types/static.d.mts +44 -42
- package/package.json +1 -1
|
@@ -11,63 +11,63 @@ import type { XPatternProperties } from './patternProperties.mjs';
|
|
|
11
11
|
import type { XPrefixItems } from './prefixItems.mjs';
|
|
12
12
|
import type { XProperties } from './properties.mjs';
|
|
13
13
|
import type { XRequired } from './required.mjs';
|
|
14
|
-
export type
|
|
14
|
+
export type XStaticStandardSchemaV1<Validator extends XStandardValidatorV1, ValidateResult extends unknown = ReturnType<Validator['validate']>, RemoveAsync extends unknown = Exclude<ValidateResult, Promise<any>>, RemoveIssue extends unknown = Exclude<RemoveAsync, {
|
|
15
15
|
issues: any;
|
|
16
16
|
}>, Result extends unknown = RemoveIssue extends {
|
|
17
17
|
value: infer Value;
|
|
18
18
|
} ? Value : unknown> = Result;
|
|
19
|
-
type
|
|
19
|
+
type XStaticAdditionalProperties<Schema extends XSchemaLike, Result extends Record<PropertyKey, unknown> = (Schema extends true ? {
|
|
20
20
|
[key: string]: unknown;
|
|
21
21
|
} : Schema extends false ? {} : {
|
|
22
|
-
[key: string]:
|
|
22
|
+
[key: string]: XStaticType<Schema>;
|
|
23
23
|
})> = Result;
|
|
24
|
-
type
|
|
25
|
-
type
|
|
26
|
-
type
|
|
27
|
-
type
|
|
28
|
-
type
|
|
29
|
-
type
|
|
30
|
-
type
|
|
31
|
-
type
|
|
32
|
-
type
|
|
33
|
-
[Key in keyof Properties]:
|
|
24
|
+
type XStaticAllOf<Schemas extends XSchemaLike[], Result extends unknown = unknown> = Schemas extends [infer Left extends XSchemaLike, ...infer Right extends XSchemaLike[]] ? XStaticAllOf<Right, XStaticType<Left> & Result> : Result;
|
|
25
|
+
type XStaticAnyOf<Schemas extends XSchemaLike[], Result extends unknown = never> = Schemas extends [infer Left extends XSchemaLike, ...infer Right extends XSchemaLike[]] ? XStaticAnyOf<Right, XStaticType<Left> | Result> : Result;
|
|
26
|
+
type XStaticConst<Value extends unknown> = Value;
|
|
27
|
+
type XStaticEnum<Values extends unknown[], Result extends unknown = never> = Values extends [infer Left extends unknown, ...infer Right extends unknown[]] ? XStaticEnum<Right, Left | Result> : Result;
|
|
28
|
+
type XStaticItemsUnsized<Schema extends XSchemaLike> = XStaticType<Schema>[];
|
|
29
|
+
type XStaticItemsSized<Schema extends XSchemaLike[], Result extends unknown[] = []> = Schema extends [infer Left extends XSchemaLike, ...infer Right extends XSchemaLike[]] ? XStaticItemsSized<Right, [...Result, XStaticType<Left>]> : Result;
|
|
30
|
+
type XStaticItems<Schemas extends XSchemaLike[] | XSchemaLike, Result extends unknown = (Schemas extends XSchemaLike[] ? XStaticItemsSized<[...Schemas]> : Schemas extends XSchemaLike ? XStaticItemsUnsized<Schemas> : never)> = Result;
|
|
31
|
+
type XStaticOneOf<Schemas extends XSchemaLike[], Result extends unknown = never> = Schemas extends [infer Left extends XSchemaLike, ...infer Right extends XSchemaLike[]] ? XStaticOneOf<Right, XStaticType<Left> | Result> : Result;
|
|
32
|
+
type XStaticPatternProperties<Properties extends Record<PropertyKey, XSchemaLike> = Record<PropertyKey, XSchemaLike>, InferredProperties extends Record<PropertyKey, unknown> = {
|
|
33
|
+
[Key in keyof Properties]: XStaticType<Properties[Key]>;
|
|
34
34
|
}, EvaluatedProperties extends unknown = {
|
|
35
35
|
[key: string]: InferredProperties[keyof InferredProperties];
|
|
36
36
|
}> = EvaluatedProperties;
|
|
37
|
-
type
|
|
38
|
-
type
|
|
37
|
+
type XStaticPrefixItems<Schemas extends XSchemaLike[], Result extends unknown[] = []> = Schemas extends [infer Left extends XSchemaLike, ...infer Right extends XSchemaLike[]] ? XStaticPrefixItems<Right, [...Result, XStaticType<Left>]> : Result;
|
|
38
|
+
type XStaticProperties<Properties extends Record<PropertyKey, XSchemaLike>, Readonly extends Record<PropertyKey, unknown> = {
|
|
39
39
|
readonly [Key in keyof Properties as Properties[Key] extends {
|
|
40
40
|
readOnly: true;
|
|
41
|
-
} ? Key : never]?:
|
|
41
|
+
} ? Key : never]?: XStaticType<Properties[Key]>;
|
|
42
42
|
}, Standard extends Record<PropertyKey, unknown> = {
|
|
43
43
|
[Key in keyof Properties as Properties[Key] extends {
|
|
44
44
|
readOnly: true;
|
|
45
|
-
} ? never : Key]?:
|
|
45
|
+
} ? never : Key]?: XStaticType<Properties[Key]>;
|
|
46
46
|
}, Result extends Record<PropertyKey, unknown> = Readonly & Standard> = Result;
|
|
47
47
|
type RequiredSelectProperty<Properties extends Record<PropertyKey, XSchemaLike>, Key extends string, Result extends Record<PropertyKey, unknown> = (Key extends keyof Properties ? Properties[Key] extends {
|
|
48
48
|
readOnly: true;
|
|
49
49
|
} ? {
|
|
50
|
-
readonly [_ in Key]:
|
|
50
|
+
readonly [_ in Key]: XStaticType<Properties[Key]>;
|
|
51
51
|
} : {
|
|
52
|
-
[_ in Key]:
|
|
52
|
+
[_ in Key]: XStaticType<Properties[Key]>;
|
|
53
53
|
} : {
|
|
54
54
|
[_ in Key]: unknown;
|
|
55
55
|
})> = Result;
|
|
56
56
|
type RequiredSelectProperties<Properties extends Record<PropertyKey, XSchemaLike>, Keys extends string[], Result extends Record<PropertyKey, unknown> = {}> = Keys extends [infer Left extends string, ...infer Right extends string[]] ? RequiredSelectProperties<Properties, Right, Result & RequiredSelectProperty<Properties, Left>> : Result;
|
|
57
57
|
type RequiredGetProperties<Schema extends XSchemaLike, Result extends Record<PropertyKey, unknown> = (Schema extends XProperties<infer Properties extends Record<PropertyKey, XSchemaLike>> ? Properties : {})> = Result;
|
|
58
|
-
type
|
|
59
|
-
type
|
|
60
|
-
Schema extends XAdditionalProperties<infer Type extends XSchemaLike> ?
|
|
61
|
-
Schema extends XAllOf<infer Types extends XSchemaLike[]> ?
|
|
62
|
-
Schema extends XAnyOf<infer Types extends XSchemaLike[]> ?
|
|
63
|
-
Schema extends XConst<infer Value extends unknown> ?
|
|
64
|
-
Schema extends XEnum<infer Values extends unknown[]> ?
|
|
65
|
-
Schema extends XItems<infer Types extends XSchemaLike[] | XSchemaLike> ?
|
|
66
|
-
Schema extends XOneOf<infer Types extends XSchemaLike[]> ?
|
|
67
|
-
Schema extends XPatternProperties<infer Properties extends Record<PropertyKey, XSchemaLike>> ?
|
|
68
|
-
Schema extends XPrefixItems<infer Types extends XSchemaLike[]> ?
|
|
69
|
-
Schema extends XProperties<infer Properties extends Record<PropertyKey, XSchemaLike>> ?
|
|
70
|
-
Schema extends XRequired<infer Keys extends string[]> ?
|
|
58
|
+
type XStaticRequired<Schema extends XSchemaLike, Keys extends string[], Properties extends Record<PropertyKey, XSchemaLike> = RequiredGetProperties<Schema>, Result extends Record<PropertyKey, unknown> = RequiredSelectProperties<Properties, Keys>> = Result;
|
|
59
|
+
type XStaticKeywords<Schema, Result extends unknown[] = [
|
|
60
|
+
Schema extends XAdditionalProperties<infer Type extends XSchemaLike> ? XStaticAdditionalProperties<Type> : unknown,
|
|
61
|
+
Schema extends XAllOf<infer Types extends XSchemaLike[]> ? XStaticAllOf<Types> : unknown,
|
|
62
|
+
Schema extends XAnyOf<infer Types extends XSchemaLike[]> ? XStaticAnyOf<Types> : unknown,
|
|
63
|
+
Schema extends XConst<infer Value extends unknown> ? XStaticConst<Value> : unknown,
|
|
64
|
+
Schema extends XEnum<infer Values extends unknown[]> ? XStaticEnum<Values> : unknown,
|
|
65
|
+
Schema extends XItems<infer Types extends XSchemaLike[] | XSchemaLike> ? XStaticItems<Types> : unknown,
|
|
66
|
+
Schema extends XOneOf<infer Types extends XSchemaLike[]> ? XStaticOneOf<Types> : unknown,
|
|
67
|
+
Schema extends XPatternProperties<infer Properties extends Record<PropertyKey, XSchemaLike>> ? XStaticPatternProperties<Properties> : unknown,
|
|
68
|
+
Schema extends XPrefixItems<infer Types extends XSchemaLike[]> ? XStaticPrefixItems<Types> : unknown,
|
|
69
|
+
Schema extends XProperties<infer Properties extends Record<PropertyKey, XSchemaLike>> ? XStaticProperties<Properties> : unknown,
|
|
70
|
+
Schema extends XRequired<infer Keys extends string[]> ? XStaticRequired<Schema, Keys> : unknown,
|
|
71
71
|
Schema extends {
|
|
72
72
|
type: 'array';
|
|
73
73
|
} ? {} : unknown,
|
|
@@ -99,17 +99,19 @@ type StaticXKeywords<Schema, Result extends unknown[] = [
|
|
|
99
99
|
type: 'undefined';
|
|
100
100
|
} ? undefined : unknown
|
|
101
101
|
]> = Result;
|
|
102
|
-
type
|
|
103
|
-
type
|
|
104
|
-
type StaticXNonReadonlyArray<Schema extends unknown, Result extends unknown[] = StaticXNonReadonly<Schema>[]> = Result;
|
|
105
|
-
type StaticXNonReadonlyObject<Schema extends object, Result extends Record<PropertyKey, unknown> = {
|
|
106
|
-
-readonly [K in keyof Schema]: StaticXNonReadonly<Schema[K]>;
|
|
107
|
-
}> = Result;
|
|
108
|
-
type StaticXNonReadonly<Schema> = (Schema extends readonly [...infer Rest extends unknown[]] ? StaticXNonReadonlyTuple<Rest> : Schema extends readonly (infer U)[] ? StaticXNonReadonlyArray<U> : Schema extends object ? StaticXNonReadonlyObject<Schema> : Schema);
|
|
109
|
-
type StaticXEvaluate<Schema extends unknown, Result extends unknown = Schema extends object ? {
|
|
102
|
+
type XStaticKeywordIntersect<Schemas extends unknown[], Result extends unknown = unknown> = (Schemas extends [infer Left extends unknown, ...infer Right extends unknown[]] ? XStaticKeywordIntersect<Right, Result & Left> : Result);
|
|
103
|
+
type XStaticEvaluate<Schema extends unknown, Result extends unknown = Schema extends object ? {
|
|
110
104
|
[Key in keyof Schema]: Schema[Key];
|
|
111
105
|
} : Schema> = Result;
|
|
112
|
-
type
|
|
106
|
+
type XStaticJsonSchema<Schema extends unknown, Keywords extends unknown[] = XStaticKeywords<Schema>, Intersect extends unknown = XStaticKeywordIntersect<Keywords>, Result extends unknown = XStaticEvaluate<Intersect>> = Result;
|
|
107
|
+
/** Statically infers a JSON Schema or Standard Schema */
|
|
108
|
+
export type XStaticType<Schema extends XSchemaLike, Result extends unknown = (Schema extends XStandardSchemaV1<infer Validator extends XStandardValidatorV1> ? XStaticStandardSchemaV1<Validator> : XStaticJsonSchema<Schema>)> = Result;
|
|
109
|
+
type XStaticMutableTuple<Schemas extends readonly unknown[]> = (Schemas extends [infer Left, ...infer Right extends unknown[]] ? [XStaticMutable<Left>, ...XStaticMutableTuple<Right>] : []);
|
|
110
|
+
type XStaticMutableArray<Schema extends unknown, Result extends unknown[] = XStaticMutable<Schema>[]> = Result;
|
|
111
|
+
type XStaticMutableObject<Schema extends object, Result extends Record<PropertyKey, unknown> = {
|
|
112
|
+
-readonly [K in keyof Schema]: XStaticMutable<Schema[K]>;
|
|
113
|
+
}> = Result;
|
|
114
|
+
type XStaticMutable<Schema> = (Schema extends XStandardSchemaV1 ? Schema : Schema extends readonly [...infer Schemas extends unknown[]] ? XStaticMutableTuple<Schemas> : Schema extends readonly (infer Schema)[] ? XStaticMutableArray<Schema> : Schema extends object ? XStaticMutableObject<Schema> : Schema);
|
|
113
115
|
/** Statically infers a JSON Schema or Standard Schema */
|
|
114
|
-
export type XStatic<Schema extends XSchemaLike,
|
|
116
|
+
export type XStatic<Schema extends XSchemaLike, Mutable extends XSchemaLike = XStaticMutable<Schema>, Result extends unknown = XStaticType<Mutable>> = Result;
|
|
115
117
|
export {};
|