@sinclair/typebox 0.25.23 → 0.26.0-dev
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/compiler/compiler.d.ts +9 -4
- package/compiler/compiler.js +160 -119
- package/errors/errors.d.ts +56 -46
- package/errors/errors.js +234 -149
- package/package.json +1 -6
- package/readme.md +395 -396
- package/system/system.d.ts +9 -6
- package/system/system.js +17 -17
- package/typebox.d.ts +386 -162
- package/typebox.js +1710 -229
- package/value/cast.d.ts +2 -2
- package/value/cast.js +120 -192
- package/value/check.d.ts +1 -1
- package/value/check.js +162 -107
- package/value/convert.d.ts +13 -0
- package/value/convert.js +345 -0
- package/value/create.d.ts +6 -2
- package/value/create.js +149 -107
- package/{hash → value}/hash.js +39 -14
- package/value/index.d.ts +1 -0
- package/value/index.js +3 -1
- package/value/value.d.ts +2 -8
- package/value/value.js +20 -14
- package/conditional/conditional.d.ts +0 -17
- package/conditional/conditional.js +0 -91
- package/conditional/index.d.ts +0 -2
- package/conditional/index.js +0 -45
- package/conditional/structural.d.ts +0 -11
- package/conditional/structural.js +0 -685
- package/custom/custom.d.ts +0 -12
- package/custom/custom.js +0 -55
- package/custom/index.d.ts +0 -1
- package/custom/index.js +0 -44
- package/format/format.d.ts +0 -12
- package/format/format.js +0 -55
- package/format/index.d.ts +0 -1
- package/format/index.js +0 -44
- package/guard/guard.d.ts +0 -60
- package/guard/guard.js +0 -440
- package/guard/index.d.ts +0 -1
- package/guard/index.js +0 -44
- package/hash/index.d.ts +0 -1
- package/hash/index.js +0 -44
- /package/{hash → value}/hash.d.ts +0 -0
package/typebox.d.ts
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
export declare const Kind: unique symbol;
|
|
2
2
|
export declare const Hint: unique symbol;
|
|
3
3
|
export declare const Modifier: unique symbol;
|
|
4
|
+
export type TupleToIntersect<T extends any[]> = T extends [infer I] ? I : T extends [infer I, ...infer R] ? I & TupleToIntersect<R> : never;
|
|
5
|
+
export type TupleToUnion<T extends any[]> = {
|
|
6
|
+
[K in keyof T]: T[K];
|
|
7
|
+
}[number];
|
|
8
|
+
export type UnionToIntersect<U> = (U extends unknown ? (arg: U) => 0 : never) extends (arg: infer I) => 0 ? I : never;
|
|
9
|
+
export type UnionLast<U> = UnionToIntersect<U extends unknown ? (x: U) => 0 : never> extends (x: infer L) => 0 ? L : never;
|
|
10
|
+
export type UnionToTuple<U, L = UnionLast<U>> = [U] extends [never] ? [] : [...UnionToTuple<Exclude<U, L>>, L];
|
|
11
|
+
export type Assert<T, E> = T extends E ? T : never;
|
|
12
|
+
export type Evaluate<T> = T extends infer O ? {
|
|
13
|
+
[K in keyof O]: O[K];
|
|
14
|
+
} : never;
|
|
15
|
+
export type Ensure<T> = T extends infer U ? U : never;
|
|
4
16
|
export type TModifier = TReadonlyOptional<TSchema> | TOptional<TSchema> | TReadonly<TSchema>;
|
|
5
17
|
export type TReadonly<T extends TSchema> = T & {
|
|
6
18
|
[Modifier]: 'Readonly';
|
|
@@ -14,33 +26,35 @@ export type TReadonlyOptional<T extends TSchema> = T & {
|
|
|
14
26
|
export interface SchemaOptions {
|
|
15
27
|
$schema?: string;
|
|
16
28
|
/** Id for this schema */
|
|
17
|
-
$id?: string;
|
|
29
|
+
readonly $id?: string;
|
|
18
30
|
/** Title of this schema */
|
|
19
31
|
title?: string;
|
|
20
32
|
/** Description of this schema */
|
|
21
33
|
description?: string;
|
|
22
34
|
/** Default value for this schema */
|
|
23
35
|
default?: any;
|
|
24
|
-
/** Example values matching this schema
|
|
36
|
+
/** Example values matching this schema */
|
|
25
37
|
examples?: any;
|
|
26
38
|
[prop: string]: any;
|
|
27
39
|
}
|
|
28
|
-
export interface
|
|
40
|
+
export interface TKind {
|
|
29
41
|
[Kind]: string;
|
|
42
|
+
}
|
|
43
|
+
export interface TSchema extends SchemaOptions, TKind {
|
|
30
44
|
[Hint]?: string;
|
|
31
45
|
[Modifier]?: string;
|
|
32
46
|
params: unknown[];
|
|
33
47
|
static: unknown;
|
|
34
48
|
}
|
|
35
|
-
export type TAnySchema = TSchema | TAny | TArray | TBoolean | TConstructor | TDate | TEnum | TFunction | TInteger | TLiteral | TNull | TNumber | TObject | TPromise | TRecord |
|
|
36
|
-
export interface NumericOptions extends SchemaOptions {
|
|
37
|
-
exclusiveMaximum?: number;
|
|
38
|
-
exclusiveMinimum?: number;
|
|
39
|
-
maximum?: number;
|
|
40
|
-
minimum?: number;
|
|
41
|
-
multipleOf?: number;
|
|
42
|
-
}
|
|
49
|
+
export type TAnySchema = TSchema | TAny | TArray | TBigInt | TBoolean | TConstructor | TDate | TEnum | TFunction | TInteger | TIntersect | TLiteral | TNot | TNull | TNumber | TObject | TPromise | TRecord | TRef | TSelf | TString | TSymbol | TTuple | TUndefined | TUnion | TUint8Array | TUnknown | TVoid;
|
|
43
50
|
export type TNumeric = TInteger | TNumber;
|
|
51
|
+
export interface NumericOptions<N extends number | bigint> extends SchemaOptions {
|
|
52
|
+
exclusiveMaximum?: N;
|
|
53
|
+
exclusiveMinimum?: N;
|
|
54
|
+
maximum?: N;
|
|
55
|
+
minimum?: N;
|
|
56
|
+
multipleOf?: N;
|
|
57
|
+
}
|
|
44
58
|
export interface TAny extends TSchema {
|
|
45
59
|
[Kind]: 'Any';
|
|
46
60
|
static: any;
|
|
@@ -52,23 +66,38 @@ export interface ArrayOptions extends SchemaOptions {
|
|
|
52
66
|
}
|
|
53
67
|
export interface TArray<T extends TSchema = TSchema> extends TSchema, ArrayOptions {
|
|
54
68
|
[Kind]: 'Array';
|
|
55
|
-
static:
|
|
69
|
+
static: Static<T, this['params']>[];
|
|
56
70
|
type: 'array';
|
|
57
71
|
items: T;
|
|
58
72
|
}
|
|
73
|
+
export interface TBigInt extends TSchema, NumericOptions<bigint> {
|
|
74
|
+
[Kind]: 'BigInt';
|
|
75
|
+
static: bigint;
|
|
76
|
+
type: 'null';
|
|
77
|
+
typeOf: 'BigInt';
|
|
78
|
+
}
|
|
59
79
|
export interface TBoolean extends TSchema {
|
|
60
80
|
[Kind]: 'Boolean';
|
|
61
81
|
static: boolean;
|
|
62
82
|
type: 'boolean';
|
|
63
83
|
}
|
|
64
84
|
export type TConstructorParameters<T extends TConstructor<TSchema[], TSchema>> = TTuple<T['parameters']>;
|
|
85
|
+
export type TDeref<T> = T extends TRef<infer U> ? TDeref<U> : T;
|
|
65
86
|
export type TInstanceType<T extends TConstructor<TSchema[], TSchema>> = T['returns'];
|
|
66
|
-
export type
|
|
67
|
-
|
|
87
|
+
export type TCompositeUnion<Left extends TSchema, Right extends TSchema> = Ensure<TUnion<[Left, Right]>>;
|
|
88
|
+
export type TCompositeMerge<T extends TObject, Output extends Record<any, TSchema>> = Evaluate<{
|
|
89
|
+
[Key in keyof T['properties']]: Key extends keyof Output ? TCompositeUnion<T['properties'][Key], Output[Key]> : T['properties'][Key];
|
|
90
|
+
} & {
|
|
91
|
+
[Key in keyof Output]: Key extends keyof T['properties'] ? TCompositeUnion<T['properties'][Key], Output[Key]> : Output[Key];
|
|
92
|
+
}>;
|
|
93
|
+
export type TCompositeReduce<T extends TObject[], Output extends {}> = T extends [infer L, ...infer R] ? TCompositeReduce<[...Assert<R, TObject[]>], TCompositeMerge<Assert<L, TObject>, Output>> : T extends [] ? Output : never;
|
|
94
|
+
export type TComposite<T extends TObject[]> = Ensure<TObject<TCompositeReduce<T, {}>>>;
|
|
95
|
+
export type TConstructorParameterArray<T extends readonly TSchema[], P extends unknown[]> = [...{
|
|
96
|
+
[K in keyof T]: Static<Assert<T[K], TSchema>, P>;
|
|
68
97
|
}];
|
|
69
98
|
export interface TConstructor<T extends TSchema[] = TSchema[], U extends TSchema = TSchema> extends TSchema {
|
|
70
99
|
[Kind]: 'Constructor';
|
|
71
|
-
static: new (...param:
|
|
100
|
+
static: new (...param: TConstructorParameterArray<T, this['params']>) => Static<U, this['params']>;
|
|
72
101
|
type: 'object';
|
|
73
102
|
instanceOf: 'Constructor';
|
|
74
103
|
parameters: T;
|
|
@@ -90,52 +119,60 @@ export interface TEnumOption<T> {
|
|
|
90
119
|
type: 'number' | 'string';
|
|
91
120
|
const: T;
|
|
92
121
|
}
|
|
122
|
+
export type TEnumStatic<T extends Record<string, string | number>> = T[keyof T];
|
|
93
123
|
export interface TEnum<T extends Record<string, string | number> = Record<string, string | number>> extends TSchema {
|
|
94
124
|
[Kind]: 'Union';
|
|
95
|
-
static: T
|
|
125
|
+
static: TEnumStatic<T>;
|
|
96
126
|
anyOf: TLiteral<string | number>[];
|
|
97
127
|
}
|
|
98
|
-
export type
|
|
99
|
-
export type
|
|
100
|
-
|
|
101
|
-
|
|
128
|
+
export type TExtends<L extends TSchema, R extends TSchema, T extends TSchema, U extends TSchema> = (Static<L> extends Static<R> ? T : U) extends infer O ? UnionToTuple<O> extends [infer X, infer Y] ? TUnion<[Assert<X, TSchema>, Assert<Y, TSchema>]> : Assert<O, TSchema> : never;
|
|
129
|
+
export type TExcludeArray<T extends TSchema[], U extends TSchema> = Assert<UnionToTuple<{
|
|
130
|
+
[K in keyof T]: Static<Assert<T[K], TSchema>> extends Static<U> ? never : T[K];
|
|
131
|
+
}[number]>, TSchema[]> extends infer R ? TExcludeResult<Assert<R, TSchema[]>> : never;
|
|
132
|
+
export type TExcludeResult<T extends TSchema[]> = T extends [] ? TNever : T extends [infer S] ? S : TUnion<T>;
|
|
133
|
+
export type TExclude<T extends TSchema, U extends TSchema> = T extends TUnion<infer S> ? TExcludeArray<S, U> : T extends U ? TNever : T;
|
|
134
|
+
export type TExtractArray<T extends TSchema[], U extends TSchema> = Assert<UnionToTuple<{
|
|
135
|
+
[K in keyof T]: Static<Assert<T[K], TSchema>> extends Static<U> ? T[K] : never;
|
|
136
|
+
}[number]>, TSchema[]> extends infer R ? TExtractResult<Assert<R, TSchema[]>> : never;
|
|
137
|
+
export type TExtractResult<T extends TSchema[]> = T extends [] ? TNever : T extends [infer S] ? S : TUnion<T>;
|
|
138
|
+
export type TExtract<T extends TSchema, U extends TSchema> = T extends TUnion<infer S> ? TExtractArray<S, U> : T extends U ? T : TNever;
|
|
139
|
+
export type TFunctionParameters<T extends readonly TSchema[], P extends unknown[]> = [...{
|
|
140
|
+
[K in keyof T]: Static<Assert<T[K], TSchema>, P>;
|
|
102
141
|
}];
|
|
103
142
|
export interface TFunction<T extends readonly TSchema[] = TSchema[], U extends TSchema = TSchema> extends TSchema {
|
|
104
143
|
[Kind]: 'Function';
|
|
105
|
-
static: (...param:
|
|
144
|
+
static: (...param: TFunctionParameters<T, this['params']>) => Static<U, this['params']>;
|
|
106
145
|
type: 'object';
|
|
107
146
|
instanceOf: 'Function';
|
|
108
147
|
parameters: T;
|
|
109
148
|
returns: U;
|
|
110
149
|
}
|
|
111
|
-
export interface TInteger extends TSchema, NumericOptions {
|
|
150
|
+
export interface TInteger extends TSchema, NumericOptions<number> {
|
|
112
151
|
[Kind]: 'Integer';
|
|
113
152
|
static: number;
|
|
114
153
|
type: 'integer';
|
|
115
154
|
}
|
|
116
|
-
export type
|
|
117
|
-
export
|
|
118
|
-
|
|
119
|
-
};
|
|
120
|
-
export type IntersectProperties<T extends readonly TObject[]> = {
|
|
121
|
-
[K in keyof T]: T[K] extends TObject<infer P> ? P : {};
|
|
122
|
-
};
|
|
123
|
-
export interface TIntersect<T extends TObject[] = TObject[]> extends TObject {
|
|
124
|
-
static: IntersectReduce<unknown, IntersectEvaluate<T, this['params']>>;
|
|
125
|
-
properties: IntersectReduce<unknown, IntersectProperties<T>>;
|
|
155
|
+
export type TUnevaluatedProperties = undefined | TSchema | boolean;
|
|
156
|
+
export interface IntersectOptions extends SchemaOptions {
|
|
157
|
+
unevaluatedProperties?: TUnevaluatedProperties;
|
|
126
158
|
}
|
|
127
|
-
export type
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
export
|
|
131
|
-
[
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
[
|
|
135
|
-
}
|
|
136
|
-
export
|
|
137
|
-
|
|
138
|
-
|
|
159
|
+
export type TIntersectStatic<T extends TSchema[], P extends unknown[]> = TupleToIntersect<{
|
|
160
|
+
[K in keyof T]: Static<Assert<T[K], TSchema>, P>;
|
|
161
|
+
}>;
|
|
162
|
+
export interface TIntersect<T extends TSchema[] = TSchema[]> extends TSchema, IntersectOptions {
|
|
163
|
+
[Kind]: 'Intersect';
|
|
164
|
+
type?: 'object';
|
|
165
|
+
static: TIntersectStatic<T, this['params']>;
|
|
166
|
+
allOf: [...T];
|
|
167
|
+
}
|
|
168
|
+
export type TKeyOfTuple<T extends TSchema> = {
|
|
169
|
+
[K in keyof Static<T>]: TLiteral<Assert<K, TLiteralValue>>;
|
|
170
|
+
} extends infer U ? UnionToTuple<Exclude<{
|
|
171
|
+
[K in keyof U]: U[K];
|
|
172
|
+
}[keyof U], undefined>> : never;
|
|
173
|
+
export type TKeyOf<T extends TSchema = TSchema> = (T extends TIntersect ? TKeyOfTuple<T> : T extends TUnion ? TKeyOfTuple<T> : T extends TObject ? TKeyOfTuple<T> : [
|
|
174
|
+
]) extends infer R ? R extends [] ? TNever : TUnion<Assert<R, TSchema[]>> : never;
|
|
175
|
+
export type TLiteralValue = string | number | boolean | bigint;
|
|
139
176
|
export interface TLiteral<T extends TLiteralValue = TLiteralValue> extends TSchema {
|
|
140
177
|
[Kind]: 'Literal';
|
|
141
178
|
static: T;
|
|
@@ -152,12 +189,20 @@ export interface TNever extends TSchema {
|
|
|
152
189
|
const: true;
|
|
153
190
|
}];
|
|
154
191
|
}
|
|
192
|
+
export type TNotStatic<_ extends TSchema = TSchema, T extends TSchema = TSchema> = Static<T>;
|
|
193
|
+
export interface TNot<Not extends TSchema = TSchema, T extends TSchema = TSchema> extends TSchema {
|
|
194
|
+
[Kind]: 'Not';
|
|
195
|
+
static: TNotStatic<Not, T>;
|
|
196
|
+
allOf: [{
|
|
197
|
+
not: Not;
|
|
198
|
+
}, T];
|
|
199
|
+
}
|
|
155
200
|
export interface TNull extends TSchema {
|
|
156
201
|
[Kind]: 'Null';
|
|
157
202
|
static: null;
|
|
158
203
|
type: 'null';
|
|
159
204
|
}
|
|
160
|
-
export interface TNumber extends TSchema, NumericOptions {
|
|
205
|
+
export interface TNumber extends TSchema, NumericOptions<number> {
|
|
161
206
|
[Kind]: 'Number';
|
|
162
207
|
static: number;
|
|
163
208
|
type: 'number';
|
|
@@ -172,18 +217,11 @@ export type OptionalPropertyKeys<T extends TProperties> = {
|
|
|
172
217
|
[K in keyof T]: T[K] extends TOptional<TSchema> ? K : never;
|
|
173
218
|
}[keyof T];
|
|
174
219
|
export type RequiredPropertyKeys<T extends TProperties> = keyof Omit<T, ReadonlyOptionalPropertyKeys<T> | ReadonlyPropertyKeys<T> | OptionalPropertyKeys<T>>;
|
|
175
|
-
export type PropertiesReducer<T extends TProperties, R extends Record<keyof any, unknown>> = (Readonly<Partial<Pick<R, ReadonlyOptionalPropertyKeys<T>>>> & Readonly<Pick<R, ReadonlyPropertyKeys<T>>> & Partial<Pick<R, OptionalPropertyKeys<T>>> & Required<Pick<R, RequiredPropertyKeys<T>>>)
|
|
176
|
-
[K in keyof O]: O[K];
|
|
177
|
-
} : never;
|
|
220
|
+
export type PropertiesReducer<T extends TProperties, R extends Record<keyof any, unknown>> = Evaluate<(Readonly<Partial<Pick<R, ReadonlyOptionalPropertyKeys<T>>>> & Readonly<Pick<R, ReadonlyPropertyKeys<T>>> & Partial<Pick<R, OptionalPropertyKeys<T>>> & Required<Pick<R, RequiredPropertyKeys<T>>>)>;
|
|
178
221
|
export type PropertiesReduce<T extends TProperties, P extends unknown[]> = PropertiesReducer<T, {
|
|
179
222
|
[K in keyof T]: Static<T[K], P>;
|
|
180
223
|
}>;
|
|
181
|
-
export type
|
|
182
|
-
[X in Static<K>]: T;
|
|
183
|
-
} : never;
|
|
184
|
-
export interface TProperties {
|
|
185
|
-
[key: string]: TSchema;
|
|
186
|
-
}
|
|
224
|
+
export type TProperties = Record<keyof any, TSchema>;
|
|
187
225
|
export type ObjectProperties<T> = T extends TObject<infer U> ? U : never;
|
|
188
226
|
export type ObjectPropertyKeys<T> = T extends TObject<infer U> ? keyof U : never;
|
|
189
227
|
export type TAdditionalProperties = undefined | TSchema | boolean;
|
|
@@ -200,30 +238,45 @@ export interface TObject<T extends TProperties = TProperties> extends TSchema, O
|
|
|
200
238
|
properties: T;
|
|
201
239
|
required?: string[];
|
|
202
240
|
}
|
|
203
|
-
export
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
export
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
241
|
+
export type TOmitArray<T extends TSchema[], K extends keyof any> = Assert<{
|
|
242
|
+
[K2 in keyof T]: TOmit<Assert<T[K2], TSchema>, K>;
|
|
243
|
+
}, TSchema[]>;
|
|
244
|
+
export type TOmitProperties<T extends TProperties, K extends keyof any> = Evaluate<Assert<Omit<T, K>, TProperties>>;
|
|
245
|
+
export type TOmit<T extends TSchema, K extends keyof any> = T extends TIntersect<infer S> ? TIntersect<TOmitArray<S, K>> : T extends TUnion<infer S> ? TUnion<TOmitArray<S, K>> : T extends TObject<infer S> ? TObject<TOmitProperties<S, K>> : T;
|
|
246
|
+
export type TParameters<T extends TFunction> = TTuple<T['parameters']>;
|
|
247
|
+
export type TPartialArray<T extends TSchema[]> = Assert<{
|
|
248
|
+
[K in keyof T]: TPartial<Assert<T[K], TSchema>>;
|
|
249
|
+
}, TSchema[]>;
|
|
250
|
+
export type TPartialProperties<T extends TProperties> = Evaluate<Assert<{
|
|
251
|
+
[K in keyof T]: T[K] extends TReadonlyOptional<infer U> ? TReadonlyOptional<U> : T[K] extends TReadonly<infer U> ? TReadonlyOptional<U> : T[K] extends TOptional<infer U> ? TOptional<U> : TOptional<T[K]>;
|
|
252
|
+
}, TProperties>>;
|
|
253
|
+
export type TPartial<T extends TSchema> = T extends TIntersect<infer S> ? TIntersect<TPartialArray<S>> : T extends TUnion<infer S> ? TUnion<TPartialArray<S>> : T extends TObject<infer S> ? TObject<TPartialProperties<S>> : T;
|
|
254
|
+
export type TPickArray<T extends TSchema[], K extends keyof any> = {
|
|
255
|
+
[K2 in keyof T]: TPick<Assert<T[K2], TSchema>, K>;
|
|
256
|
+
};
|
|
257
|
+
export type TPickProperties<T extends TProperties, K extends keyof any> = Pick<T, Assert<Extract<K, keyof T>, keyof T>> extends infer R ? ({
|
|
258
|
+
[K in keyof R]: Assert<R[K], TSchema> extends TSchema ? R[K] : never;
|
|
259
|
+
}) : never;
|
|
260
|
+
export type TPick<T extends TSchema, K extends keyof any> = T extends TIntersect<infer S> ? TIntersect<TPickArray<S, K>> : T extends TUnion<infer S> ? TUnion<TPickArray<S, K>> : T extends TObject<infer S> ? TObject<TPickProperties<S, K>> : T;
|
|
261
|
+
export type TPromiseStatic<T extends TSchema, P extends unknown[]> = Promise<Static<T, P>>;
|
|
216
262
|
export interface TPromise<T extends TSchema = TSchema> extends TSchema {
|
|
217
263
|
[Kind]: 'Promise';
|
|
218
|
-
static:
|
|
264
|
+
static: TPromiseStatic<T, this['params']>;
|
|
219
265
|
type: 'object';
|
|
220
266
|
instanceOf: 'Promise';
|
|
221
267
|
item: TSchema;
|
|
222
268
|
}
|
|
223
269
|
export type TRecordKey = TString | TNumeric | TUnion<TLiteral<any>[]>;
|
|
270
|
+
export type TRecordPropertiesFromUnionLiteral<K extends TUnion<TLiteral<string | number>[]>, T extends TSchema> = Static<K> extends string ? {
|
|
271
|
+
[X in Static<K>]: T;
|
|
272
|
+
} : never;
|
|
273
|
+
export type TRecordPropertiesFromLiteral<K extends TLiteral<string | number>, T extends TSchema> = Evaluate<{
|
|
274
|
+
[K2 in K['const']]: T;
|
|
275
|
+
}>;
|
|
276
|
+
export type TRecordStatic<K extends TRecordKey, T extends TSchema, P extends unknown[]> = Record<Static<K>, Static<T, P>>;
|
|
224
277
|
export interface TRecord<K extends TRecordKey = TRecordKey, T extends TSchema = TSchema> extends TSchema {
|
|
225
278
|
[Kind]: 'Record';
|
|
226
|
-
static:
|
|
279
|
+
static: TRecordStatic<K, T, this['params']>;
|
|
227
280
|
type: 'object';
|
|
228
281
|
patternProperties: {
|
|
229
282
|
[pattern: string]: T;
|
|
@@ -239,17 +292,20 @@ export type TRecursiveReduce<T extends TSchema> = Static<T, [TRecursiveReduce<T>
|
|
|
239
292
|
export interface TRecursive<T extends TSchema> extends TSchema {
|
|
240
293
|
static: TRecursiveReduce<T>;
|
|
241
294
|
}
|
|
295
|
+
export type TRefStatic<T extends TSchema, P extends unknown[]> = Static<T, P>;
|
|
242
296
|
export interface TRef<T extends TSchema = TSchema> extends TSchema {
|
|
243
297
|
[Kind]: 'Ref';
|
|
244
|
-
static:
|
|
298
|
+
static: TRefStatic<T, this['params']>;
|
|
245
299
|
$ref: string;
|
|
246
300
|
}
|
|
247
|
-
export
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
301
|
+
export type TReturnType<T extends TFunction> = T['returns'];
|
|
302
|
+
export type TRequiredArray<T extends TSchema[]> = Assert<{
|
|
303
|
+
[K in keyof T]: TRequired<Assert<T[K], TSchema>>;
|
|
304
|
+
}, TSchema[]>;
|
|
305
|
+
export type TRequiredProperties<T extends TProperties> = Evaluate<Assert<{
|
|
306
|
+
[K in keyof T]: T[K] extends TReadonlyOptional<infer U> ? TReadonly<U> : T[K] extends TReadonly<infer U> ? TReadonly<U> : T[K] extends TOptional<infer U> ? U : T[K];
|
|
307
|
+
}, TProperties>>;
|
|
308
|
+
export type TRequired<T extends TSchema> = T extends TIntersect<infer S> ? TIntersect<TRequiredArray<S>> : T extends TUnion<infer S> ? TUnion<TRequiredArray<S>> : T extends TObject<infer S> ? TObject<TRequiredProperties<S>> : T;
|
|
253
309
|
export type StringFormatOption = 'date-time' | 'time' | 'date' | 'email' | 'idn-email' | 'hostname' | 'idn-hostname' | 'ipv4' | 'ipv6' | 'uri' | 'uri-reference' | 'iri' | 'uuid' | 'iri-reference' | 'uri-template' | 'json-pointer' | 'relative-json-pointer' | 'regex';
|
|
254
310
|
export interface StringOptions<Format extends string> extends SchemaOptions {
|
|
255
311
|
minLength?: number;
|
|
@@ -264,12 +320,20 @@ export interface TString<Format extends string = string> extends TSchema, String
|
|
|
264
320
|
static: string;
|
|
265
321
|
type: 'string';
|
|
266
322
|
}
|
|
267
|
-
export type
|
|
323
|
+
export type SymbolValue = string | number | undefined;
|
|
324
|
+
export interface TSymbol extends TSchema, SchemaOptions {
|
|
325
|
+
[Kind]: 'Symbol';
|
|
326
|
+
static: symbol;
|
|
327
|
+
type: 'null';
|
|
328
|
+
typeOf: 'Symbol';
|
|
329
|
+
}
|
|
330
|
+
export type TTupleIntoArray<T extends TTuple<TSchema[]>> = T extends TTuple<infer R> ? Assert<R, TSchema[]> : never;
|
|
331
|
+
export type TTupleStatic<T extends TSchema[], P extends unknown[]> = {
|
|
332
|
+
[K in keyof T]: T[K] extends TSchema ? Static<T[K], P> : T[K];
|
|
333
|
+
};
|
|
268
334
|
export interface TTuple<T extends TSchema[] = TSchema[]> extends TSchema {
|
|
269
335
|
[Kind]: 'Tuple';
|
|
270
|
-
static:
|
|
271
|
-
[K in keyof T]: T[K] extends TSchema ? Static<T[K], this['params']> : T[K];
|
|
272
|
-
};
|
|
336
|
+
static: TTupleStatic<T, this['params']>;
|
|
273
337
|
type: 'array';
|
|
274
338
|
items?: T;
|
|
275
339
|
additionalItems?: false;
|
|
@@ -282,6 +346,10 @@ export interface TUndefined extends TSchema {
|
|
|
282
346
|
type: 'null';
|
|
283
347
|
typeOf: 'Undefined';
|
|
284
348
|
}
|
|
349
|
+
export type TUnionOfLiteralArray<T extends TLiteral<string>[]> = {
|
|
350
|
+
[K in keyof T]: Assert<T[K], TLiteral>['const'];
|
|
351
|
+
}[number];
|
|
352
|
+
export type TUnionOfLiteral<T extends TUnion<TLiteral<string>[]>> = TUnionOfLiteralArray<T['anyOf']>;
|
|
285
353
|
export interface TUnion<T extends TSchema[] = TSchema[]> extends TSchema {
|
|
286
354
|
[Kind]: 'Union';
|
|
287
355
|
static: {
|
|
@@ -320,103 +388,259 @@ export interface TVoid extends TSchema {
|
|
|
320
388
|
export type Static<T extends TSchema, P extends unknown[] = []> = (T & {
|
|
321
389
|
params: P;
|
|
322
390
|
})['static'];
|
|
391
|
+
export type TypeRegistryValidationFunction<TSchema> = (schema: TSchema, value: unknown) => boolean;
|
|
392
|
+
export declare namespace TypeRegistry {
|
|
393
|
+
/** Clears all user defined types */
|
|
394
|
+
function Clear(): void;
|
|
395
|
+
/** Returns true if this registry contains this kind */
|
|
396
|
+
function Has(kind: string): boolean;
|
|
397
|
+
/** Sets a validation function for a user defined type */
|
|
398
|
+
function Set<TSchema = unknown>(kind: string, func: TypeRegistryValidationFunction<TSchema>): void;
|
|
399
|
+
/** Gets a custom validation function for a user defined type */
|
|
400
|
+
function Get(kind: string): TypeRegistryValidationFunction<any> | undefined;
|
|
401
|
+
}
|
|
402
|
+
export declare namespace ReferenceRegistry {
|
|
403
|
+
/** Clears the reference registry */
|
|
404
|
+
function Clear(): void;
|
|
405
|
+
/** Returns true if this registry contains this schema */
|
|
406
|
+
function Has(schema: TSchema): boolean;
|
|
407
|
+
/** Sets this schema on this registry if a $id exists */
|
|
408
|
+
function Set(schema: TSchema): void;
|
|
409
|
+
/** Dereferences the schema one level deep */
|
|
410
|
+
function DerefOne(schema: TSchema): TSchema;
|
|
411
|
+
/** Dereferences the schema recursively */
|
|
412
|
+
function Deref(schema: TSchema): TSchema;
|
|
413
|
+
}
|
|
414
|
+
export type FormatRegistryValidationFunction = (value: string) => boolean;
|
|
415
|
+
/** Provides functions to create user defined string formats */
|
|
416
|
+
export declare namespace FormatRegistry {
|
|
417
|
+
/** Clears all user defined string formats */
|
|
418
|
+
function Clear(): void;
|
|
419
|
+
/** Returns true if the user defined string format exists */
|
|
420
|
+
function Has(format: string): boolean;
|
|
421
|
+
/** Sets a validation function for a user defined string format */
|
|
422
|
+
function Set(format: string, func: FormatRegistryValidationFunction): void;
|
|
423
|
+
/** Gets a validation function for a user defined string format */
|
|
424
|
+
function Get(format: string): FormatRegistryValidationFunction | undefined;
|
|
425
|
+
}
|
|
426
|
+
export declare class TypeGuardUnknownTypeError extends Error {
|
|
427
|
+
readonly schema: unknown;
|
|
428
|
+
constructor(schema: unknown);
|
|
429
|
+
}
|
|
430
|
+
export declare namespace TypeGuard {
|
|
431
|
+
/** Returns true if the given schema is TAny */
|
|
432
|
+
function TAny(schema: unknown): schema is TAny;
|
|
433
|
+
/** Returns true if the given schema is TArray */
|
|
434
|
+
function TArray(schema: unknown): schema is TArray;
|
|
435
|
+
/** Returns true if the given schema is TSymbol */
|
|
436
|
+
function TBigInt(schema: unknown): schema is TBigInt;
|
|
437
|
+
/** Returns true if the given schema is TBoolean */
|
|
438
|
+
function TBoolean(schema: unknown): schema is TBoolean;
|
|
439
|
+
/** Returns true if the given schema is TConstructor */
|
|
440
|
+
function TConstructor(schema: unknown): schema is TConstructor;
|
|
441
|
+
/** Returns true if the given schema is TDate */
|
|
442
|
+
function TDate(schema: unknown): schema is TDate;
|
|
443
|
+
/** Returns true if the given schema is TFunction */
|
|
444
|
+
function TFunction(schema: unknown): schema is TFunction;
|
|
445
|
+
/** Returns true if the given schema is TInteger */
|
|
446
|
+
function TInteger(schema: unknown): schema is TInteger;
|
|
447
|
+
/** Returns true if the given schema is TIntersect */
|
|
448
|
+
function TIntersect(schema: unknown): schema is TIntersect;
|
|
449
|
+
/** Returns true if the given schema is TKind */
|
|
450
|
+
function TKind(schema: unknown): schema is Record<typeof Kind | string, unknown>;
|
|
451
|
+
/** Returns true if the given schema is TLiteral */
|
|
452
|
+
function TLiteral(schema: unknown): schema is TLiteral;
|
|
453
|
+
/** Returns true if the given schema is TNever */
|
|
454
|
+
function TNever(schema: unknown): schema is TNever;
|
|
455
|
+
/** Returns true if the given schema is TNot */
|
|
456
|
+
function TNot(schema: unknown): schema is TNot;
|
|
457
|
+
/** Returns true if the given schema is TNull */
|
|
458
|
+
function TNull(schema: unknown): schema is TNull;
|
|
459
|
+
/** Returns true if the given schema is TNumber */
|
|
460
|
+
function TNumber(schema: unknown): schema is TNumber;
|
|
461
|
+
/** Returns true if the given schema is TObject */
|
|
462
|
+
function TObject(schema: unknown): schema is TObject;
|
|
463
|
+
/** Returns true if the given schema is TPromise */
|
|
464
|
+
function TPromise(schema: unknown): schema is TPromise;
|
|
465
|
+
/** Returns true if the given schema is TRecord */
|
|
466
|
+
function TRecord(schema: unknown): schema is TRecord;
|
|
467
|
+
/** Returns true if the given schema is TSelf */
|
|
468
|
+
function TSelf(schema: unknown): schema is TSelf;
|
|
469
|
+
/** Returns true if the given schema is TRef */
|
|
470
|
+
function TRef(schema: unknown): schema is TRef;
|
|
471
|
+
/** Returns true if the given schema is TString */
|
|
472
|
+
function TString(schema: unknown): schema is TString;
|
|
473
|
+
/** Returns true if the given schema is TSymbol */
|
|
474
|
+
function TSymbol(schema: unknown): schema is TSymbol;
|
|
475
|
+
/** Returns true if the given schema is TTuple */
|
|
476
|
+
function TTuple(schema: unknown): schema is TTuple;
|
|
477
|
+
/** Returns true if the given schema is TUndefined */
|
|
478
|
+
function TUndefined(schema: unknown): schema is TUndefined;
|
|
479
|
+
/** Returns true if the given schema is TUnion */
|
|
480
|
+
function TUnion(schema: unknown): schema is TUnion;
|
|
481
|
+
/** Returns true if the given schema is TUnion<Literal<string>[]> */
|
|
482
|
+
function TUnionLiteral(schema: unknown): schema is TUnion<TLiteral<string>[]>;
|
|
483
|
+
/** Returns true if the given schema is TUint8Array */
|
|
484
|
+
function TUint8Array(schema: unknown): schema is TUint8Array;
|
|
485
|
+
/** Returns true if the given schema is TUnknown */
|
|
486
|
+
function TUnknown(schema: unknown): schema is TUnknown;
|
|
487
|
+
/** Returns true if the given schema is TVoid */
|
|
488
|
+
function TVoid(schema: unknown): schema is TVoid;
|
|
489
|
+
/** Returns true if this schema has the ReadonlyOptional modifier */
|
|
490
|
+
function TReadonlyOptional<T extends TSchema>(schema: T): schema is TReadonlyOptional<T>;
|
|
491
|
+
/** Returns true if this schema has the Readonly modifier */
|
|
492
|
+
function TReadonly<T extends TSchema>(schema: T): schema is TReadonly<T>;
|
|
493
|
+
/** Returns true if this schema has the Optional modifier */
|
|
494
|
+
function TOptional<T extends TSchema>(schema: T): schema is TOptional<T>;
|
|
495
|
+
/** Returns true if the given schema is TSchema */
|
|
496
|
+
function TSchema(schema: unknown): schema is TSchema;
|
|
497
|
+
}
|
|
498
|
+
export declare namespace ExtendsUndefined {
|
|
499
|
+
/** Fast undefined check for properties of type undefined */
|
|
500
|
+
function Check(schema: TSchema): boolean;
|
|
501
|
+
}
|
|
502
|
+
export declare enum TypeExtendsResult {
|
|
503
|
+
Union = 0,
|
|
504
|
+
True = 1,
|
|
505
|
+
False = 2
|
|
506
|
+
}
|
|
507
|
+
export declare namespace TypeExtends {
|
|
508
|
+
function Extends(left: TSchema, right: TSchema): TypeExtendsResult;
|
|
509
|
+
}
|
|
510
|
+
/** Specialized Clone for Types. */
|
|
511
|
+
export declare namespace TypeClone {
|
|
512
|
+
function Clone<T extends TSchema | TProperties>(schema: T, options: SchemaOptions): T;
|
|
513
|
+
}
|
|
514
|
+
export declare namespace ObjectMap {
|
|
515
|
+
function Map<T = TSchema>(schema: TSchema, callback: (object: TObject) => TObject, options: SchemaOptions): T;
|
|
516
|
+
}
|
|
517
|
+
export declare namespace KeyResolver {
|
|
518
|
+
function Resolve<T extends TSchema>(schema: T): string[];
|
|
519
|
+
}
|
|
323
520
|
export declare class TypeBuilder {
|
|
324
|
-
/** Creates a
|
|
325
|
-
|
|
326
|
-
/**
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
/** `
|
|
521
|
+
/** `[Utility]` Creates a schema without `static` and `params` types */
|
|
522
|
+
protected Create<T>(schema: Omit<T, 'static' | 'params'>): T;
|
|
523
|
+
/** `[Standard]` Omits compositing symbols from this schema */
|
|
524
|
+
Strict<T extends TSchema>(schema: T): T;
|
|
525
|
+
}
|
|
526
|
+
export declare class StandardTypeBuilder extends TypeBuilder {
|
|
527
|
+
/** `[Modifier]` Creates a Optional property */
|
|
528
|
+
Optional<T extends TSchema>(schema: T): TOptional<T>;
|
|
529
|
+
/** `[Modifier]` Creates a ReadonlyOptional property */
|
|
530
|
+
ReadonlyOptional<T extends TSchema>(schema: T): TReadonlyOptional<T>;
|
|
531
|
+
/** `[Modifier]` Creates a Readonly object or property */
|
|
532
|
+
Readonly<T extends TSchema>(schema: T): TReadonly<T>;
|
|
533
|
+
/** `[Standard]` Creates an Any type */
|
|
331
534
|
Any(options?: SchemaOptions): TAny;
|
|
332
|
-
/** `Standard` Creates
|
|
535
|
+
/** `[Standard]` Creates an Array type */
|
|
333
536
|
Array<T extends TSchema>(items: T, options?: ArrayOptions): TArray<T>;
|
|
334
|
-
/** `Standard` Creates a
|
|
537
|
+
/** `[Standard]` Creates a Boolean type */
|
|
335
538
|
Boolean(options?: SchemaOptions): TBoolean;
|
|
336
|
-
/** `
|
|
337
|
-
|
|
338
|
-
/** `
|
|
339
|
-
|
|
340
|
-
/** `
|
|
341
|
-
Constructor<T extends TSchema[], U extends TSchema>(parameters: [...T], returns: U, options?: SchemaOptions): TConstructor<T, U>;
|
|
342
|
-
/** `Extended` Creates a Date type */
|
|
343
|
-
Date(options?: DateOptions): TDate;
|
|
344
|
-
/** `Standard` Creates a enum type */
|
|
539
|
+
/** `[Standard]` Creates a Composite object type that will Union any overlapping properties of the given Object array */
|
|
540
|
+
Composite<T extends TObject[]>(schemas: [...T], options?: ObjectOptions): TComposite<T>;
|
|
541
|
+
/** `[Standard]` Dereferences the given TRef to its target type */
|
|
542
|
+
Deref<T extends TRef>(schema: T): TDeref<T>;
|
|
543
|
+
/** `[Standard]` Creates a Enum type */
|
|
345
544
|
Enum<T extends Record<string, string | number>>(item: T, options?: SchemaOptions): TEnum<T>;
|
|
346
|
-
/** `
|
|
347
|
-
|
|
348
|
-
/** `
|
|
349
|
-
|
|
350
|
-
/** `
|
|
351
|
-
|
|
352
|
-
/** `Standard` Creates
|
|
353
|
-
Integer(options?: NumericOptions): TInteger;
|
|
354
|
-
/** `Standard` Creates a
|
|
355
|
-
Intersect
|
|
356
|
-
/** `Standard` Creates a
|
|
357
|
-
|
|
358
|
-
|
|
545
|
+
/** `[Standard]` A conditional type expression that will return the true type if the left extends the right */
|
|
546
|
+
Extends<L extends TSchema, R extends TSchema, T extends TSchema, U extends TSchema>(left: L, right: R, trueType: T, falseType: U, options?: SchemaOptions): TExtends<L, R, T, U>;
|
|
547
|
+
/** `[Standard]` Excludes from left any type that is not assignable to the right. */
|
|
548
|
+
Exclude<L extends TSchema, R extends TSchema>(left: L, right: R, options?: SchemaOptions): TExclude<L, R>;
|
|
549
|
+
/** `[Standard]` Extracts from left any type that is assignable to the right. */
|
|
550
|
+
Extract<L extends TSchema, R extends TSchema>(left: L, right: R, options?: SchemaOptions): TExtract<L, R>;
|
|
551
|
+
/** `[Standard]` Creates an Integer type */
|
|
552
|
+
Integer(options?: NumericOptions<number>): TInteger;
|
|
553
|
+
/** `[Standard]` Creates a Intersect type */
|
|
554
|
+
Intersect(allOf: [], options?: SchemaOptions): TNever;
|
|
555
|
+
/** `[Standard]` Creates a Intersect type */
|
|
556
|
+
Intersect<T extends [TSchema]>(allOf: [...T], options?: SchemaOptions): T[0];
|
|
557
|
+
Intersect<T extends TSchema[]>(allOf: [...T], options?: IntersectOptions): TIntersect<T>;
|
|
558
|
+
/** `[Standard]` Creates a KeyOf type */
|
|
559
|
+
KeyOf<T extends TSchema>(schema: T, options?: SchemaOptions): TKeyOf<T>;
|
|
560
|
+
/** `[Standard]` Creates a Literal type */
|
|
359
561
|
Literal<T extends TLiteralValue>(value: T, options?: SchemaOptions): TLiteral<T>;
|
|
360
|
-
/** `Standard` Creates a
|
|
562
|
+
/** `[Standard]` Creates a Never type */
|
|
361
563
|
Never(options?: SchemaOptions): TNever;
|
|
362
|
-
/** `Standard` Creates a
|
|
564
|
+
/** `[Standard]` Creates a Not type. The first argument is the disallowed type, the second is the allowed. */
|
|
565
|
+
Not<N extends TSchema, T extends TSchema>(not: N, schema: T, options?: SchemaOptions): TNot<N, T>;
|
|
566
|
+
/** `[Standard]` Creates a Null type */
|
|
363
567
|
Null(options?: SchemaOptions): TNull;
|
|
364
|
-
/** `Standard` Creates a
|
|
365
|
-
Number(options?: NumericOptions): TNumber;
|
|
366
|
-
/** `Standard` Creates
|
|
568
|
+
/** `[Standard]` Creates a Number type */
|
|
569
|
+
Number(options?: NumericOptions<number>): TNumber;
|
|
570
|
+
/** `[Standard]` Creates a Object type */
|
|
367
571
|
Object<T extends TProperties>(properties: T, options?: ObjectOptions): TObject<T>;
|
|
368
|
-
/** `Standard` Creates a
|
|
369
|
-
Omit<T extends
|
|
370
|
-
/** `Standard` Creates a
|
|
371
|
-
Omit<T extends
|
|
372
|
-
/** `
|
|
373
|
-
|
|
374
|
-
/** `Standard` Creates
|
|
375
|
-
|
|
376
|
-
/** `Standard` Creates a
|
|
377
|
-
Pick<T extends
|
|
378
|
-
/** `Standard` Creates
|
|
379
|
-
|
|
380
|
-
/** `
|
|
381
|
-
|
|
382
|
-
/** `Standard` Creates
|
|
383
|
-
Record<K extends TUnion<TLiteral[]>, T extends TSchema>(key: K, schema: T, options?: ObjectOptions): TObject<TRecordProperties<K, T>>;
|
|
384
|
-
/** `Standard` Creates a record type */
|
|
572
|
+
/** `[Standard]` Creates a mapped type whose keys are omitted from the given type */
|
|
573
|
+
Omit<T extends TSchema, K extends (keyof Static<T>)[]>(schema: T, keys: readonly [...K], options?: SchemaOptions): TOmit<T, K[number]>;
|
|
574
|
+
/** `[Standard]` Creates a mapped type whose keys are omitted from the given type */
|
|
575
|
+
Omit<T extends TSchema, K extends TUnion<TLiteral<string>[]>>(schema: T, keys: K, options?: SchemaOptions): TOmit<T, TUnionOfLiteral<K>>;
|
|
576
|
+
/** `[Standard]` Creates a mapped type where all properties are Optional */
|
|
577
|
+
Partial<T extends TSchema>(schema: T, options?: ObjectOptions): TPartial<T>;
|
|
578
|
+
/** `[Standard]` Creates a mapped type whose keys are picked from the given type */
|
|
579
|
+
Pick<T extends TSchema, K extends (keyof Static<T>)[]>(schema: T, keys: readonly [...K], options?: SchemaOptions): TPick<T, K[number]>;
|
|
580
|
+
/** `[Standard]` Creates a mapped type whose keys are picked from the given type */
|
|
581
|
+
Pick<T extends TSchema, K extends TUnion<TLiteral<string>[]>>(schema: T, keys: K, options?: SchemaOptions): TPick<T, TUnionOfLiteral<K>>;
|
|
582
|
+
/** `[Standard]` Creates an Object type from the given Literal Union */
|
|
583
|
+
Record<K extends TUnion<TLiteral<string | number>[]>, T extends TSchema>(key: K, schema: T, options?: ObjectOptions): TObject<TRecordPropertiesFromUnionLiteral<K, T>>;
|
|
584
|
+
/** `[Standard]` Creates an Object type from the given Literal Union */
|
|
585
|
+
Record<K extends TLiteral<string | number>, T extends TSchema>(key: K, schema: T, options?: ObjectOptions): TObject<TRecordPropertiesFromLiteral<K, T>>;
|
|
586
|
+
/** `[Standard]` Creates a Record type */
|
|
385
587
|
Record<K extends TString | TNumeric, T extends TSchema>(key: K, schema: T, options?: ObjectOptions): TRecord<K, T>;
|
|
386
|
-
/** `Standard` Creates
|
|
588
|
+
/** `[Standard]` Creates a Recursive type */
|
|
387
589
|
Recursive<T extends TSchema>(callback: (self: TSelf) => T, options?: SchemaOptions): TRecursive<T>;
|
|
388
|
-
/** `Standard` Creates a
|
|
590
|
+
/** `[Standard]` Creates a Ref type. The referenced type must contain a $id */
|
|
389
591
|
Ref<T extends TSchema>(schema: T, options?: SchemaOptions): TRef<T>;
|
|
390
|
-
/** `Standard` Creates a
|
|
391
|
-
|
|
392
|
-
/** `Standard` Creates
|
|
393
|
-
Required<T extends TObject>(schema: T, options?: SchemaOptions): TRequired<T>;
|
|
394
|
-
/** `Extended` Creates a type from this functions return type */
|
|
395
|
-
ReturnType<T extends TFunction<any[], any>>(schema: T, options?: SchemaOptions): TReturnType<T>;
|
|
396
|
-
/** Removes Kind and Modifier symbol property keys from this schema */
|
|
397
|
-
Strict<T extends TSchema>(schema: T): T;
|
|
398
|
-
/** `Standard` Creates a string type */
|
|
592
|
+
/** `[Standard]` Creates a mapped type where all properties are Required */
|
|
593
|
+
Required<T extends TSchema>(schema: T, options?: SchemaOptions): TRequired<T>;
|
|
594
|
+
/** `[Standard]` Creates a String type */
|
|
399
595
|
String<Format extends string>(options?: StringOptions<StringFormatOption | Format>): TString<Format>;
|
|
400
|
-
/** `Standard` Creates a
|
|
596
|
+
/** `[Standard]` Creates a Tuple type */
|
|
401
597
|
Tuple<T extends TSchema[]>(items: [...T], options?: SchemaOptions): TTuple<T>;
|
|
402
|
-
/** `
|
|
403
|
-
|
|
404
|
-
/** `Standard` Creates a
|
|
405
|
-
Union(
|
|
406
|
-
/** `Standard` Creates a
|
|
407
|
-
Union<T extends TSchema[]>(
|
|
408
|
-
/** `
|
|
409
|
-
Uint8Array(options?: Uint8ArrayOptions): TUint8Array;
|
|
410
|
-
/** `Standard` Creates an unknown type */
|
|
598
|
+
/** `[Standard]` Creates a Union type */
|
|
599
|
+
Union(anyOf: [], options?: SchemaOptions): TNever;
|
|
600
|
+
/** `[Standard]` Creates a Union type */
|
|
601
|
+
Union<T extends [TSchema]>(anyOf: [...T], options?: SchemaOptions): T[0];
|
|
602
|
+
/** `[Standard]` Creates a Union type */
|
|
603
|
+
Union<T extends TSchema[]>(anyOf: [...T], options?: SchemaOptions): TUnion<T>;
|
|
604
|
+
/** `[Standard]` Creates an Unknown type */
|
|
411
605
|
Unknown(options?: SchemaOptions): TUnknown;
|
|
412
|
-
/** `Standard` Creates a
|
|
606
|
+
/** `[Standard]` Creates a Unsafe type that infers for the generic argument */
|
|
413
607
|
Unsafe<T>(options?: UnsafeOptions): TUnsafe<T>;
|
|
414
|
-
|
|
608
|
+
}
|
|
609
|
+
export declare class ExtendedTypeBuilder extends StandardTypeBuilder {
|
|
610
|
+
/** `[Extended]` Creates a BigInt */
|
|
611
|
+
BigInt(options?: NumericOptions<bigint>): TBigInt;
|
|
612
|
+
/** `[Extended]` Extracts the ConstructorParameters from the given Constructor type */
|
|
613
|
+
ConstructorParameters<T extends TConstructor<any[], any>>(schema: T, options?: SchemaOptions): TConstructorParameters<T>;
|
|
614
|
+
/** `[Extended]` Creates a Constructor type */
|
|
615
|
+
Constructor<T extends TTuple<TSchema[]>, U extends TSchema>(parameters: T, returns: U, options?: SchemaOptions): TConstructor<TTupleIntoArray<T>, U>;
|
|
616
|
+
/** `[Extended]` Creates a Constructor type */
|
|
617
|
+
Constructor<T extends TSchema[], U extends TSchema>(parameters: [...T], returns: U, options?: SchemaOptions): TConstructor<T, U>;
|
|
618
|
+
/** `[Extended]` Creates a Date type */
|
|
619
|
+
Date(options?: DateOptions): TDate;
|
|
620
|
+
/** `[Extended]` Creates a Function type */
|
|
621
|
+
Function<T extends TTuple<TSchema[]>, U extends TSchema>(parameters: T, returns: U, options?: SchemaOptions): TFunction<TTupleIntoArray<T>, U>;
|
|
622
|
+
/** `[Extended]` Creates a Function type */
|
|
623
|
+
Function<T extends TSchema[], U extends TSchema>(parameters: [...T], returns: U, options?: SchemaOptions): TFunction<T, U>;
|
|
624
|
+
/** `[Extended]` Extracts the InstanceType from the given Constructor */
|
|
625
|
+
InstanceType<T extends TConstructor<any[], any>>(schema: T, options?: SchemaOptions): TInstanceType<T>;
|
|
626
|
+
/** `[Extended]` Extracts the Parameters from the given Function type */
|
|
627
|
+
Parameters<T extends TFunction<any[], any>>(schema: T, options?: SchemaOptions): TParameters<T>;
|
|
628
|
+
/** `[Extended]` Creates a Promise type */
|
|
629
|
+
Promise<T extends TSchema>(item: T, options?: SchemaOptions): TPromise<T>;
|
|
630
|
+
/** `[Extended]` Creates a regular expression type */
|
|
631
|
+
RegEx(regex: RegExp, options?: SchemaOptions): TString;
|
|
632
|
+
/** `[Extended]` Extracts the ReturnType from the given Function */
|
|
633
|
+
ReturnType<T extends TFunction<any[], any>>(schema: T, options?: SchemaOptions): TReturnType<T>;
|
|
634
|
+
/** `[Extended]` Creates a Symbol type */
|
|
635
|
+
Symbol(options?: SchemaOptions): TSymbol;
|
|
636
|
+
/** `[Extended]` Creates a Undefined type */
|
|
637
|
+
Undefined(options?: SchemaOptions): TUndefined;
|
|
638
|
+
/** `[Extended]` Creates a Uint8Array type */
|
|
639
|
+
Uint8Array(options?: Uint8ArrayOptions): TUint8Array;
|
|
640
|
+
/** `[Extended]` Creates a Void type */
|
|
415
641
|
Void(options?: SchemaOptions): TVoid;
|
|
416
|
-
/** Use this function to return TSchema with static and params omitted */
|
|
417
|
-
protected Create<T>(schema: Omit<T, 'static' | 'params'>): T;
|
|
418
|
-
/** Clones the given value */
|
|
419
|
-
protected Clone(value: any): any;
|
|
420
642
|
}
|
|
421
|
-
/** JSON Schema
|
|
422
|
-
export declare const
|
|
643
|
+
/** JSON Schema TypeBuilder with Static Resolution for TypeScript */
|
|
644
|
+
export declare const StandardType: StandardTypeBuilder;
|
|
645
|
+
/** JSON Schema TypeBuilder with Static Resolution for TypeScript */
|
|
646
|
+
export declare const Type: ExtendedTypeBuilder;
|