@sinclair/typebox 0.25.23 → 0.25.25
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 +25 -28
- package/compiler/compiler.js +495 -495
- package/compiler/index.d.ts +2 -2
- package/compiler/index.js +47 -47
- package/conditional/conditional.d.ts +17 -17
- package/conditional/conditional.js +91 -91
- package/conditional/index.d.ts +2 -2
- package/conditional/index.js +45 -45
- package/conditional/structural.d.ts +11 -11
- package/conditional/structural.js +685 -685
- package/custom/custom.d.ts +12 -12
- package/custom/custom.js +55 -55
- package/custom/index.d.ts +1 -1
- package/custom/index.js +44 -44
- package/errors/errors.d.ts +67 -67
- package/errors/errors.js +472 -468
- package/errors/index.d.ts +1 -1
- package/errors/index.js +44 -44
- package/format/format.d.ts +12 -12
- package/format/format.js +55 -55
- package/format/index.d.ts +1 -1
- package/format/index.js +44 -44
- package/guard/extends.d.ts +10 -0
- package/guard/extends.js +50 -0
- package/guard/guard.d.ts +60 -60
- package/guard/guard.js +440 -440
- package/guard/index.d.ts +2 -1
- package/guard/index.js +45 -44
- package/hash/hash.d.ts +8 -8
- package/hash/hash.js +183 -183
- package/hash/index.d.ts +1 -1
- package/hash/index.js +44 -44
- package/license +22 -22
- package/package.json +55 -52
- package/readme.md +1237 -1325
- package/system/index.d.ts +1 -1
- package/system/index.js +44 -44
- package/system/system.d.ts +17 -17
- package/system/system.js +69 -69
- package/typebox.d.ts +422 -422
- package/typebox.js +388 -388
- package/value/cast.d.ts +26 -26
- package/value/cast.js +415 -420
- package/value/check.d.ts +8 -8
- package/value/check.js +405 -395
- package/value/clone.d.ts +3 -3
- package/value/clone.js +71 -71
- package/value/create.d.ts +14 -14
- package/value/create.js +378 -388
- package/value/delta.d.ts +43 -43
- package/value/delta.js +204 -204
- package/value/equal.d.ts +3 -3
- package/value/equal.js +80 -80
- package/value/index.d.ts +4 -4
- package/value/index.js +53 -53
- package/value/is.d.ts +11 -11
- package/value/is.js +53 -53
- package/value/pointer.d.ts +24 -24
- package/value/pointer.js +142 -142
- package/value/value.d.ts +32 -32
- package/value/value.js +87 -87
package/typebox.d.ts
CHANGED
|
@@ -1,422 +1,422 @@
|
|
|
1
|
-
export declare const Kind: unique symbol;
|
|
2
|
-
export declare const Hint: unique symbol;
|
|
3
|
-
export declare const Modifier: unique symbol;
|
|
4
|
-
export type TModifier = TReadonlyOptional<TSchema> | TOptional<TSchema> | TReadonly<TSchema>;
|
|
5
|
-
export type TReadonly<T extends TSchema> = T & {
|
|
6
|
-
[Modifier]: 'Readonly';
|
|
7
|
-
};
|
|
8
|
-
export type TOptional<T extends TSchema> = T & {
|
|
9
|
-
[Modifier]: 'Optional';
|
|
10
|
-
};
|
|
11
|
-
export type TReadonlyOptional<T extends TSchema> = T & {
|
|
12
|
-
[Modifier]: 'ReadonlyOptional';
|
|
13
|
-
};
|
|
14
|
-
export interface SchemaOptions {
|
|
15
|
-
$schema?: string;
|
|
16
|
-
/** Id for this schema */
|
|
17
|
-
$id?: string;
|
|
18
|
-
/** Title of this schema */
|
|
19
|
-
title?: string;
|
|
20
|
-
/** Description of this schema */
|
|
21
|
-
description?: string;
|
|
22
|
-
/** Default value for this schema */
|
|
23
|
-
default?: any;
|
|
24
|
-
/** Example values matching this schema. */
|
|
25
|
-
examples?: any;
|
|
26
|
-
[prop: string]: any;
|
|
27
|
-
}
|
|
28
|
-
export interface TSchema extends SchemaOptions {
|
|
29
|
-
[Kind]: string;
|
|
30
|
-
[Hint]?: string;
|
|
31
|
-
[Modifier]?: string;
|
|
32
|
-
params: unknown[];
|
|
33
|
-
static: unknown;
|
|
34
|
-
}
|
|
35
|
-
export type TAnySchema = TSchema | TAny | TArray | TBoolean | TConstructor | TDate | TEnum | TFunction | TInteger | TLiteral | TNull | TNumber | TObject | TPromise | TRecord | TSelf | TRef | TString | TTuple | TUndefined | TUnion | TUint8Array | TUnknown | TVoid;
|
|
36
|
-
export interface NumericOptions extends SchemaOptions {
|
|
37
|
-
exclusiveMaximum?: number;
|
|
38
|
-
exclusiveMinimum?: number;
|
|
39
|
-
maximum?: number;
|
|
40
|
-
minimum?: number;
|
|
41
|
-
multipleOf?: number;
|
|
42
|
-
}
|
|
43
|
-
export type TNumeric = TInteger | TNumber;
|
|
44
|
-
export interface TAny extends TSchema {
|
|
45
|
-
[Kind]: 'Any';
|
|
46
|
-
static: any;
|
|
47
|
-
}
|
|
48
|
-
export interface ArrayOptions extends SchemaOptions {
|
|
49
|
-
uniqueItems?: boolean;
|
|
50
|
-
minItems?: number;
|
|
51
|
-
maxItems?: number;
|
|
52
|
-
}
|
|
53
|
-
export interface TArray<T extends TSchema = TSchema> extends TSchema, ArrayOptions {
|
|
54
|
-
[Kind]: 'Array';
|
|
55
|
-
static: Array<Static<T, this['params']>>;
|
|
56
|
-
type: 'array';
|
|
57
|
-
items: T;
|
|
58
|
-
}
|
|
59
|
-
export interface TBoolean extends TSchema {
|
|
60
|
-
[Kind]: 'Boolean';
|
|
61
|
-
static: boolean;
|
|
62
|
-
type: 'boolean';
|
|
63
|
-
}
|
|
64
|
-
export type TConstructorParameters<T extends TConstructor<TSchema[], TSchema>> = TTuple<T['parameters']>;
|
|
65
|
-
export type TInstanceType<T extends TConstructor<TSchema[], TSchema>> = T['returns'];
|
|
66
|
-
export type StaticContructorParameters<T extends readonly TSchema[], P extends unknown[]> = [...{
|
|
67
|
-
[K in keyof T]: T[K] extends TSchema ? Static<T[K], P> : never;
|
|
68
|
-
}];
|
|
69
|
-
export interface TConstructor<T extends TSchema[] = TSchema[], U extends TSchema = TSchema> extends TSchema {
|
|
70
|
-
[Kind]: 'Constructor';
|
|
71
|
-
static: new (...param: StaticContructorParameters<T, this['params']>) => Static<U, this['params']>;
|
|
72
|
-
type: 'object';
|
|
73
|
-
instanceOf: 'Constructor';
|
|
74
|
-
parameters: T;
|
|
75
|
-
returns: U;
|
|
76
|
-
}
|
|
77
|
-
export interface DateOptions extends SchemaOptions {
|
|
78
|
-
exclusiveMaximumTimestamp?: number;
|
|
79
|
-
exclusiveMinimumTimestamp?: number;
|
|
80
|
-
maximumTimestamp?: number;
|
|
81
|
-
minimumTimestamp?: number;
|
|
82
|
-
}
|
|
83
|
-
export interface TDate extends TSchema, DateOptions {
|
|
84
|
-
[Kind]: 'Date';
|
|
85
|
-
static: Date;
|
|
86
|
-
type: 'object';
|
|
87
|
-
instanceOf: 'Date';
|
|
88
|
-
}
|
|
89
|
-
export interface TEnumOption<T> {
|
|
90
|
-
type: 'number' | 'string';
|
|
91
|
-
const: T;
|
|
92
|
-
}
|
|
93
|
-
export interface TEnum<T extends Record<string, string | number> = Record<string, string | number>> extends TSchema {
|
|
94
|
-
[Kind]: 'Union';
|
|
95
|
-
static: T[keyof T];
|
|
96
|
-
anyOf: TLiteral<string | number>[];
|
|
97
|
-
}
|
|
98
|
-
export type TParameters<T extends TFunction> = TTuple<T['parameters']>;
|
|
99
|
-
export type TReturnType<T extends TFunction> = T['returns'];
|
|
100
|
-
export type StaticFunctionParameters<T extends readonly TSchema[], P extends unknown[]> = [...{
|
|
101
|
-
[K in keyof T]: T[K] extends TSchema ? Static<T[K], P> : never;
|
|
102
|
-
}];
|
|
103
|
-
export interface TFunction<T extends readonly TSchema[] = TSchema[], U extends TSchema = TSchema> extends TSchema {
|
|
104
|
-
[Kind]: 'Function';
|
|
105
|
-
static: (...param: StaticFunctionParameters<T, this['params']>) => Static<U, this['params']>;
|
|
106
|
-
type: 'object';
|
|
107
|
-
instanceOf: 'Function';
|
|
108
|
-
parameters: T;
|
|
109
|
-
returns: U;
|
|
110
|
-
}
|
|
111
|
-
export interface TInteger extends TSchema, NumericOptions {
|
|
112
|
-
[Kind]: 'Integer';
|
|
113
|
-
static: number;
|
|
114
|
-
type: 'integer';
|
|
115
|
-
}
|
|
116
|
-
export type IntersectReduce<I extends unknown, T extends readonly any[]> = T extends [infer A, ...infer B] ? IntersectReduce<I & A, B> : I extends object ? I : {};
|
|
117
|
-
export type IntersectEvaluate<T extends readonly TSchema[], P extends unknown[]> = {
|
|
118
|
-
[K in keyof T]: T[K] extends TSchema ? Static<T[K], P> : never;
|
|
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>>;
|
|
126
|
-
}
|
|
127
|
-
export type UnionToIntersect<U> = (U extends unknown ? (arg: U) => 0 : never) extends (arg: infer I) => 0 ? I : never;
|
|
128
|
-
export type UnionLast<U> = UnionToIntersect<U extends unknown ? (x: U) => 0 : never> extends (x: infer L) => 0 ? L : never;
|
|
129
|
-
export type UnionToTuple<U, L = UnionLast<U>> = [U] extends [never] ? [] : [...UnionToTuple<Exclude<U, L>>, L];
|
|
130
|
-
export type UnionStringLiteralToTuple<T> = T extends TUnion<infer L> ? {
|
|
131
|
-
[I in keyof L]: L[I] extends TLiteral<infer C> ? C : never;
|
|
132
|
-
} : never;
|
|
133
|
-
export type UnionLiteralsFromObject<T extends TObject> = {
|
|
134
|
-
[K in ObjectPropertyKeys<T>]: TLiteral<K>;
|
|
135
|
-
} extends infer R ? UnionToTuple<R[keyof R]> : never;
|
|
136
|
-
export interface TKeyOf<T extends TObject> extends TUnion<UnionLiteralsFromObject<T>> {
|
|
137
|
-
}
|
|
138
|
-
export type TLiteralValue = string | number | boolean;
|
|
139
|
-
export interface TLiteral<T extends TLiteralValue = TLiteralValue> extends TSchema {
|
|
140
|
-
[Kind]: 'Literal';
|
|
141
|
-
static: T;
|
|
142
|
-
const: T;
|
|
143
|
-
}
|
|
144
|
-
export interface TNever extends TSchema {
|
|
145
|
-
[Kind]: 'Never';
|
|
146
|
-
static: never;
|
|
147
|
-
allOf: [{
|
|
148
|
-
type: 'boolean';
|
|
149
|
-
const: false;
|
|
150
|
-
}, {
|
|
151
|
-
type: 'boolean';
|
|
152
|
-
const: true;
|
|
153
|
-
}];
|
|
154
|
-
}
|
|
155
|
-
export interface TNull extends TSchema {
|
|
156
|
-
[Kind]: 'Null';
|
|
157
|
-
static: null;
|
|
158
|
-
type: 'null';
|
|
159
|
-
}
|
|
160
|
-
export interface TNumber extends TSchema, NumericOptions {
|
|
161
|
-
[Kind]: 'Number';
|
|
162
|
-
static: number;
|
|
163
|
-
type: 'number';
|
|
164
|
-
}
|
|
165
|
-
export type ReadonlyOptionalPropertyKeys<T extends TProperties> = {
|
|
166
|
-
[K in keyof T]: T[K] extends TReadonlyOptional<TSchema> ? K : never;
|
|
167
|
-
}[keyof T];
|
|
168
|
-
export type ReadonlyPropertyKeys<T extends TProperties> = {
|
|
169
|
-
[K in keyof T]: T[K] extends TReadonly<TSchema> ? K : never;
|
|
170
|
-
}[keyof T];
|
|
171
|
-
export type OptionalPropertyKeys<T extends TProperties> = {
|
|
172
|
-
[K in keyof T]: T[K] extends TOptional<TSchema> ? K : never;
|
|
173
|
-
}[keyof T];
|
|
174
|
-
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>>>) extends infer O ? {
|
|
176
|
-
[K in keyof O]: O[K];
|
|
177
|
-
} : never;
|
|
178
|
-
export type PropertiesReduce<T extends TProperties, P extends unknown[]> = PropertiesReducer<T, {
|
|
179
|
-
[K in keyof T]: Static<T[K], P>;
|
|
180
|
-
}>;
|
|
181
|
-
export type TRecordProperties<K extends TUnion<TLiteral[]>, T extends TSchema> = Static<K> extends string ? {
|
|
182
|
-
[X in Static<K>]: T;
|
|
183
|
-
} : never;
|
|
184
|
-
export interface TProperties {
|
|
185
|
-
[key: string]: TSchema;
|
|
186
|
-
}
|
|
187
|
-
export type ObjectProperties<T> = T extends TObject<infer U> ? U : never;
|
|
188
|
-
export type ObjectPropertyKeys<T> = T extends TObject<infer U> ? keyof U : never;
|
|
189
|
-
export type TAdditionalProperties = undefined | TSchema | boolean;
|
|
190
|
-
export interface ObjectOptions extends SchemaOptions {
|
|
191
|
-
additionalProperties?: TAdditionalProperties;
|
|
192
|
-
minProperties?: number;
|
|
193
|
-
maxProperties?: number;
|
|
194
|
-
}
|
|
195
|
-
export interface TObject<T extends TProperties = TProperties> extends TSchema, ObjectOptions {
|
|
196
|
-
[Kind]: 'Object';
|
|
197
|
-
static: PropertiesReduce<T, this['params']>;
|
|
198
|
-
additionalProperties?: TAdditionalProperties;
|
|
199
|
-
type: 'object';
|
|
200
|
-
properties: T;
|
|
201
|
-
required?: string[];
|
|
202
|
-
}
|
|
203
|
-
export interface TOmit<T extends TObject, Properties extends ObjectPropertyKeys<T>[]> extends TObject, ObjectOptions {
|
|
204
|
-
static: Omit<Static<T, this['params']>, Properties[number]>;
|
|
205
|
-
properties: T extends TObject ? Omit<T['properties'], Properties[number]> : never;
|
|
206
|
-
}
|
|
207
|
-
export interface TPartial<T extends TObject> extends TObject {
|
|
208
|
-
static: Partial<Static<T, this['params']>>;
|
|
209
|
-
properties: {
|
|
210
|
-
[K in keyof T['properties']]: T['properties'][K] extends TReadonlyOptional<infer U> ? TReadonlyOptional<U> : T['properties'][K] extends TReadonly<infer U> ? TReadonlyOptional<U> : T['properties'][K] extends TOptional<infer U> ? TOptional<U> : TOptional<T['properties'][K]>;
|
|
211
|
-
};
|
|
212
|
-
}
|
|
213
|
-
export type TPick<T extends TObject, Properties extends ObjectPropertyKeys<T>[]> = TObject<{
|
|
214
|
-
[K in Properties[number]]: T['properties'][K];
|
|
215
|
-
}>;
|
|
216
|
-
export interface TPromise<T extends TSchema = TSchema> extends TSchema {
|
|
217
|
-
[Kind]: 'Promise';
|
|
218
|
-
static: Promise<Static<T, this['params']>>;
|
|
219
|
-
type: 'object';
|
|
220
|
-
instanceOf: 'Promise';
|
|
221
|
-
item: TSchema;
|
|
222
|
-
}
|
|
223
|
-
export type TRecordKey = TString | TNumeric | TUnion<TLiteral<any>[]>;
|
|
224
|
-
export interface TRecord<K extends TRecordKey = TRecordKey, T extends TSchema = TSchema> extends TSchema {
|
|
225
|
-
[Kind]: 'Record';
|
|
226
|
-
static: Record<Static<K>, Static<T, this['params']>>;
|
|
227
|
-
type: 'object';
|
|
228
|
-
patternProperties: {
|
|
229
|
-
[pattern: string]: T;
|
|
230
|
-
};
|
|
231
|
-
additionalProperties: false;
|
|
232
|
-
}
|
|
233
|
-
export interface TSelf extends TSchema {
|
|
234
|
-
[Kind]: 'Self';
|
|
235
|
-
static: this['params'][0];
|
|
236
|
-
$ref: string;
|
|
237
|
-
}
|
|
238
|
-
export type TRecursiveReduce<T extends TSchema> = Static<T, [TRecursiveReduce<T>]>;
|
|
239
|
-
export interface TRecursive<T extends TSchema> extends TSchema {
|
|
240
|
-
static: TRecursiveReduce<T>;
|
|
241
|
-
}
|
|
242
|
-
export interface TRef<T extends TSchema = TSchema> extends TSchema {
|
|
243
|
-
[Kind]: 'Ref';
|
|
244
|
-
static: Static<T, this['params']>;
|
|
245
|
-
$ref: string;
|
|
246
|
-
}
|
|
247
|
-
export interface TRequired<T extends TObject | TRef<TObject>> extends TObject {
|
|
248
|
-
static: Required<Static<T, this['params']>>;
|
|
249
|
-
properties: {
|
|
250
|
-
[K in keyof T['properties']]: T['properties'][K] extends TReadonlyOptional<infer U> ? TReadonly<U> : T['properties'][K] extends TReadonly<infer U> ? TReadonly<U> : T['properties'][K] extends TOptional<infer U> ? U : T['properties'][K];
|
|
251
|
-
};
|
|
252
|
-
}
|
|
253
|
-
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
|
-
export interface StringOptions<Format extends string> extends SchemaOptions {
|
|
255
|
-
minLength?: number;
|
|
256
|
-
maxLength?: number;
|
|
257
|
-
pattern?: string;
|
|
258
|
-
format?: Format;
|
|
259
|
-
contentEncoding?: '7bit' | '8bit' | 'binary' | 'quoted-printable' | 'base64';
|
|
260
|
-
contentMediaType?: string;
|
|
261
|
-
}
|
|
262
|
-
export interface TString<Format extends string = string> extends TSchema, StringOptions<Format> {
|
|
263
|
-
[Kind]: 'String';
|
|
264
|
-
static: string;
|
|
265
|
-
type: 'string';
|
|
266
|
-
}
|
|
267
|
-
export type TupleToArray<T extends TTuple<TSchema[]>> = T extends TTuple<infer R> ? R : never;
|
|
268
|
-
export interface TTuple<T extends TSchema[] = TSchema[]> extends TSchema {
|
|
269
|
-
[Kind]: 'Tuple';
|
|
270
|
-
static: {
|
|
271
|
-
[K in keyof T]: T[K] extends TSchema ? Static<T[K], this['params']> : T[K];
|
|
272
|
-
};
|
|
273
|
-
type: 'array';
|
|
274
|
-
items?: T;
|
|
275
|
-
additionalItems?: false;
|
|
276
|
-
minItems: number;
|
|
277
|
-
maxItems: number;
|
|
278
|
-
}
|
|
279
|
-
export interface TUndefined extends TSchema {
|
|
280
|
-
[Kind]: 'Undefined';
|
|
281
|
-
static: undefined;
|
|
282
|
-
type: 'null';
|
|
283
|
-
typeOf: 'Undefined';
|
|
284
|
-
}
|
|
285
|
-
export interface TUnion<T extends TSchema[] = TSchema[]> extends TSchema {
|
|
286
|
-
[Kind]: 'Union';
|
|
287
|
-
static: {
|
|
288
|
-
[K in keyof T]: T[K] extends TSchema ? Static<T[K], this['params']> : never;
|
|
289
|
-
}[number];
|
|
290
|
-
anyOf: T;
|
|
291
|
-
}
|
|
292
|
-
export interface Uint8ArrayOptions extends SchemaOptions {
|
|
293
|
-
maxByteLength?: number;
|
|
294
|
-
minByteLength?: number;
|
|
295
|
-
}
|
|
296
|
-
export interface TUint8Array extends TSchema, Uint8ArrayOptions {
|
|
297
|
-
[Kind]: 'Uint8Array';
|
|
298
|
-
static: Uint8Array;
|
|
299
|
-
instanceOf: 'Uint8Array';
|
|
300
|
-
type: 'object';
|
|
301
|
-
}
|
|
302
|
-
export interface TUnknown extends TSchema {
|
|
303
|
-
[Kind]: 'Unknown';
|
|
304
|
-
static: unknown;
|
|
305
|
-
}
|
|
306
|
-
export interface UnsafeOptions extends SchemaOptions {
|
|
307
|
-
[Kind]?: string;
|
|
308
|
-
}
|
|
309
|
-
export interface TUnsafe<T> extends TSchema {
|
|
310
|
-
[Kind]: string;
|
|
311
|
-
static: T;
|
|
312
|
-
}
|
|
313
|
-
export interface TVoid extends TSchema {
|
|
314
|
-
[Kind]: 'Void';
|
|
315
|
-
static: void;
|
|
316
|
-
type: 'null';
|
|
317
|
-
typeOf: 'Void';
|
|
318
|
-
}
|
|
319
|
-
/** Creates a static type from a TypeBox type */
|
|
320
|
-
export type Static<T extends TSchema, P extends unknown[] = []> = (T & {
|
|
321
|
-
params: P;
|
|
322
|
-
})['static'];
|
|
323
|
-
export declare class TypeBuilder {
|
|
324
|
-
/** Creates a readonly optional property */
|
|
325
|
-
ReadonlyOptional<T extends TSchema>(item: T): TReadonlyOptional<T>;
|
|
326
|
-
/** Creates a readonly property */
|
|
327
|
-
Readonly<T extends TSchema>(item: T): TReadonly<T>;
|
|
328
|
-
/** Creates a optional property */
|
|
329
|
-
Optional<T extends TSchema>(item: T): TOptional<T>;
|
|
330
|
-
/** `Standard` Creates a any type */
|
|
331
|
-
Any(options?: SchemaOptions): TAny;
|
|
332
|
-
/** `Standard` Creates a array type */
|
|
333
|
-
Array<T extends TSchema>(items: T, options?: ArrayOptions): TArray<T>;
|
|
334
|
-
/** `Standard` Creates a boolean type */
|
|
335
|
-
Boolean(options?: SchemaOptions): TBoolean;
|
|
336
|
-
/** `Extended` Creates a tuple type from this constructors parameters */
|
|
337
|
-
ConstructorParameters<T extends TConstructor<any[], any>>(schema: T, options?: SchemaOptions): TConstructorParameters<T>;
|
|
338
|
-
/** `Extended` Creates a constructor type */
|
|
339
|
-
Constructor<T extends TTuple<TSchema[]>, U extends TSchema>(parameters: T, returns: U, options?: SchemaOptions): TConstructor<TupleToArray<T>, U>;
|
|
340
|
-
/** `Extended` Creates a constructor type */
|
|
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 */
|
|
345
|
-
Enum<T extends Record<string, string | number>>(item: T, options?: SchemaOptions): TEnum<T>;
|
|
346
|
-
/** `Extended` Creates a function type */
|
|
347
|
-
Function<T extends TTuple<TSchema[]>, U extends TSchema>(parameters: T, returns: U, options?: SchemaOptions): TFunction<TupleToArray<T>, U>;
|
|
348
|
-
/** `Extended` Creates a function type */
|
|
349
|
-
Function<T extends TSchema[], U extends TSchema>(parameters: [...T], returns: U, options?: SchemaOptions): TFunction<T, U>;
|
|
350
|
-
/** `Extended` Creates a type from this constructors instance type */
|
|
351
|
-
InstanceType<T extends TConstructor<any[], any>>(schema: T, options?: SchemaOptions): TInstanceType<T>;
|
|
352
|
-
/** `Standard` Creates a integer type */
|
|
353
|
-
Integer(options?: NumericOptions): TInteger;
|
|
354
|
-
/** `Standard` Creates a intersect type. */
|
|
355
|
-
Intersect<T extends TObject[]>(objects: [...T], options?: ObjectOptions): TIntersect<T>;
|
|
356
|
-
/** `Standard` Creates a keyof type */
|
|
357
|
-
KeyOf<T extends TObject>(object: T, options?: SchemaOptions): TKeyOf<T>;
|
|
358
|
-
/** `Standard` Creates a literal type. */
|
|
359
|
-
Literal<T extends TLiteralValue>(value: T, options?: SchemaOptions): TLiteral<T>;
|
|
360
|
-
/** `Standard` Creates a never type */
|
|
361
|
-
Never(options?: SchemaOptions): TNever;
|
|
362
|
-
/** `Standard` Creates a null type */
|
|
363
|
-
Null(options?: SchemaOptions): TNull;
|
|
364
|
-
/** `Standard` Creates a number type */
|
|
365
|
-
Number(options?: NumericOptions): TNumber;
|
|
366
|
-
/** `Standard` Creates an object type */
|
|
367
|
-
Object<T extends TProperties>(properties: T, options?: ObjectOptions): TObject<T>;
|
|
368
|
-
/** `Standard` Creates a new object type whose keys are omitted from the given source type */
|
|
369
|
-
Omit<T extends TObject, K extends TUnion<TLiteral<string>[]>>(schema: T, keys: K, options?: ObjectOptions): TOmit<T, UnionStringLiteralToTuple<K>>;
|
|
370
|
-
/** `Standard` Creates a new object type whose keys are omitted from the given source type */
|
|
371
|
-
Omit<T extends TObject, K extends ObjectPropertyKeys<T>[]>(schema: T, keys: readonly [...K], options?: ObjectOptions): TOmit<T, K>;
|
|
372
|
-
/** `Extended` Creates a tuple type from this functions parameters */
|
|
373
|
-
Parameters<T extends TFunction<any[], any>>(schema: T, options?: SchemaOptions): TParameters<T>;
|
|
374
|
-
/** `Standard` Creates an object type whose properties are all optional */
|
|
375
|
-
Partial<T extends TObject>(schema: T, options?: ObjectOptions): TPartial<T>;
|
|
376
|
-
/** `Standard` Creates a new object type whose keys are picked from the given source type */
|
|
377
|
-
Pick<T extends TObject, K extends TUnion<TLiteral<string>[]>>(schema: T, keys: K, options?: ObjectOptions): TPick<T, UnionStringLiteralToTuple<K>>;
|
|
378
|
-
/** `Standard` Creates a new object type whose keys are picked from the given source type */
|
|
379
|
-
Pick<T extends TObject, K extends ObjectPropertyKeys<T>[]>(schema: T, keys: readonly [...K], options?: ObjectOptions): TPick<T, K>;
|
|
380
|
-
/** `Extended` Creates a Promise type */
|
|
381
|
-
Promise<T extends TSchema>(item: T, options?: SchemaOptions): TPromise<T>;
|
|
382
|
-
/** `Standard` Creates an object whose properties are derived from the given string literal union. */
|
|
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 */
|
|
385
|
-
Record<K extends TString | TNumeric, T extends TSchema>(key: K, schema: T, options?: ObjectOptions): TRecord<K, T>;
|
|
386
|
-
/** `Standard` Creates recursive type */
|
|
387
|
-
Recursive<T extends TSchema>(callback: (self: TSelf) => T, options?: SchemaOptions): TRecursive<T>;
|
|
388
|
-
/** `Standard` Creates a reference type. The referenced type must contain a $id. */
|
|
389
|
-
Ref<T extends TSchema>(schema: T, options?: SchemaOptions): TRef<T>;
|
|
390
|
-
/** `Standard` Creates a string type from a regular expression */
|
|
391
|
-
RegEx(regex: RegExp, options?: SchemaOptions): TString;
|
|
392
|
-
/** `Standard` Creates an object type whose properties are all required */
|
|
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 */
|
|
399
|
-
String<Format extends string>(options?: StringOptions<StringFormatOption | Format>): TString<Format>;
|
|
400
|
-
/** `Standard` Creates a tuple type */
|
|
401
|
-
Tuple<T extends TSchema[]>(items: [...T], options?: SchemaOptions): TTuple<T>;
|
|
402
|
-
/** `Extended` Creates a undefined type */
|
|
403
|
-
Undefined(options?: SchemaOptions): TUndefined;
|
|
404
|
-
/** `Standard` Creates a union type */
|
|
405
|
-
Union(items: [], options?: SchemaOptions): TNever;
|
|
406
|
-
/** `Standard` Creates a union type */
|
|
407
|
-
Union<T extends TSchema[]>(items: [...T], options?: SchemaOptions): TUnion<T>;
|
|
408
|
-
/** `Extended` Creates a Uint8Array type */
|
|
409
|
-
Uint8Array(options?: Uint8ArrayOptions): TUint8Array;
|
|
410
|
-
/** `Standard` Creates an unknown type */
|
|
411
|
-
Unknown(options?: SchemaOptions): TUnknown;
|
|
412
|
-
/** `Standard` Creates a user defined schema that infers as type T */
|
|
413
|
-
Unsafe<T>(options?: UnsafeOptions): TUnsafe<T>;
|
|
414
|
-
/** `Extended` Creates a void type */
|
|
415
|
-
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
|
-
}
|
|
421
|
-
/** JSON Schema Type Builder with Static Type Resolution for TypeScript */
|
|
422
|
-
export declare const Type: TypeBuilder;
|
|
1
|
+
export declare const Kind: unique symbol;
|
|
2
|
+
export declare const Hint: unique symbol;
|
|
3
|
+
export declare const Modifier: unique symbol;
|
|
4
|
+
export type TModifier = TReadonlyOptional<TSchema> | TOptional<TSchema> | TReadonly<TSchema>;
|
|
5
|
+
export type TReadonly<T extends TSchema> = T & {
|
|
6
|
+
[Modifier]: 'Readonly';
|
|
7
|
+
};
|
|
8
|
+
export type TOptional<T extends TSchema> = T & {
|
|
9
|
+
[Modifier]: 'Optional';
|
|
10
|
+
};
|
|
11
|
+
export type TReadonlyOptional<T extends TSchema> = T & {
|
|
12
|
+
[Modifier]: 'ReadonlyOptional';
|
|
13
|
+
};
|
|
14
|
+
export interface SchemaOptions {
|
|
15
|
+
$schema?: string;
|
|
16
|
+
/** Id for this schema */
|
|
17
|
+
$id?: string;
|
|
18
|
+
/** Title of this schema */
|
|
19
|
+
title?: string;
|
|
20
|
+
/** Description of this schema */
|
|
21
|
+
description?: string;
|
|
22
|
+
/** Default value for this schema */
|
|
23
|
+
default?: any;
|
|
24
|
+
/** Example values matching this schema. */
|
|
25
|
+
examples?: any;
|
|
26
|
+
[prop: string]: any;
|
|
27
|
+
}
|
|
28
|
+
export interface TSchema extends SchemaOptions {
|
|
29
|
+
[Kind]: string;
|
|
30
|
+
[Hint]?: string;
|
|
31
|
+
[Modifier]?: string;
|
|
32
|
+
params: unknown[];
|
|
33
|
+
static: unknown;
|
|
34
|
+
}
|
|
35
|
+
export type TAnySchema = TSchema | TAny | TArray | TBoolean | TConstructor | TDate | TEnum | TFunction | TInteger | TLiteral | TNull | TNumber | TObject | TPromise | TRecord | TSelf | TRef | TString | TTuple | TUndefined | TUnion | TUint8Array | TUnknown | TVoid;
|
|
36
|
+
export interface NumericOptions extends SchemaOptions {
|
|
37
|
+
exclusiveMaximum?: number;
|
|
38
|
+
exclusiveMinimum?: number;
|
|
39
|
+
maximum?: number;
|
|
40
|
+
minimum?: number;
|
|
41
|
+
multipleOf?: number;
|
|
42
|
+
}
|
|
43
|
+
export type TNumeric = TInteger | TNumber;
|
|
44
|
+
export interface TAny extends TSchema {
|
|
45
|
+
[Kind]: 'Any';
|
|
46
|
+
static: any;
|
|
47
|
+
}
|
|
48
|
+
export interface ArrayOptions extends SchemaOptions {
|
|
49
|
+
uniqueItems?: boolean;
|
|
50
|
+
minItems?: number;
|
|
51
|
+
maxItems?: number;
|
|
52
|
+
}
|
|
53
|
+
export interface TArray<T extends TSchema = TSchema> extends TSchema, ArrayOptions {
|
|
54
|
+
[Kind]: 'Array';
|
|
55
|
+
static: Array<Static<T, this['params']>>;
|
|
56
|
+
type: 'array';
|
|
57
|
+
items: T;
|
|
58
|
+
}
|
|
59
|
+
export interface TBoolean extends TSchema {
|
|
60
|
+
[Kind]: 'Boolean';
|
|
61
|
+
static: boolean;
|
|
62
|
+
type: 'boolean';
|
|
63
|
+
}
|
|
64
|
+
export type TConstructorParameters<T extends TConstructor<TSchema[], TSchema>> = TTuple<T['parameters']>;
|
|
65
|
+
export type TInstanceType<T extends TConstructor<TSchema[], TSchema>> = T['returns'];
|
|
66
|
+
export type StaticContructorParameters<T extends readonly TSchema[], P extends unknown[]> = [...{
|
|
67
|
+
[K in keyof T]: T[K] extends TSchema ? Static<T[K], P> : never;
|
|
68
|
+
}];
|
|
69
|
+
export interface TConstructor<T extends TSchema[] = TSchema[], U extends TSchema = TSchema> extends TSchema {
|
|
70
|
+
[Kind]: 'Constructor';
|
|
71
|
+
static: new (...param: StaticContructorParameters<T, this['params']>) => Static<U, this['params']>;
|
|
72
|
+
type: 'object';
|
|
73
|
+
instanceOf: 'Constructor';
|
|
74
|
+
parameters: T;
|
|
75
|
+
returns: U;
|
|
76
|
+
}
|
|
77
|
+
export interface DateOptions extends SchemaOptions {
|
|
78
|
+
exclusiveMaximumTimestamp?: number;
|
|
79
|
+
exclusiveMinimumTimestamp?: number;
|
|
80
|
+
maximumTimestamp?: number;
|
|
81
|
+
minimumTimestamp?: number;
|
|
82
|
+
}
|
|
83
|
+
export interface TDate extends TSchema, DateOptions {
|
|
84
|
+
[Kind]: 'Date';
|
|
85
|
+
static: Date;
|
|
86
|
+
type: 'object';
|
|
87
|
+
instanceOf: 'Date';
|
|
88
|
+
}
|
|
89
|
+
export interface TEnumOption<T> {
|
|
90
|
+
type: 'number' | 'string';
|
|
91
|
+
const: T;
|
|
92
|
+
}
|
|
93
|
+
export interface TEnum<T extends Record<string, string | number> = Record<string, string | number>> extends TSchema {
|
|
94
|
+
[Kind]: 'Union';
|
|
95
|
+
static: T[keyof T];
|
|
96
|
+
anyOf: TLiteral<string | number>[];
|
|
97
|
+
}
|
|
98
|
+
export type TParameters<T extends TFunction> = TTuple<T['parameters']>;
|
|
99
|
+
export type TReturnType<T extends TFunction> = T['returns'];
|
|
100
|
+
export type StaticFunctionParameters<T extends readonly TSchema[], P extends unknown[]> = [...{
|
|
101
|
+
[K in keyof T]: T[K] extends TSchema ? Static<T[K], P> : never;
|
|
102
|
+
}];
|
|
103
|
+
export interface TFunction<T extends readonly TSchema[] = TSchema[], U extends TSchema = TSchema> extends TSchema {
|
|
104
|
+
[Kind]: 'Function';
|
|
105
|
+
static: (...param: StaticFunctionParameters<T, this['params']>) => Static<U, this['params']>;
|
|
106
|
+
type: 'object';
|
|
107
|
+
instanceOf: 'Function';
|
|
108
|
+
parameters: T;
|
|
109
|
+
returns: U;
|
|
110
|
+
}
|
|
111
|
+
export interface TInteger extends TSchema, NumericOptions {
|
|
112
|
+
[Kind]: 'Integer';
|
|
113
|
+
static: number;
|
|
114
|
+
type: 'integer';
|
|
115
|
+
}
|
|
116
|
+
export type IntersectReduce<I extends unknown, T extends readonly any[]> = T extends [infer A, ...infer B] ? IntersectReduce<I & A, B> : I extends object ? I : {};
|
|
117
|
+
export type IntersectEvaluate<T extends readonly TSchema[], P extends unknown[]> = {
|
|
118
|
+
[K in keyof T]: T[K] extends TSchema ? Static<T[K], P> : never;
|
|
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>>;
|
|
126
|
+
}
|
|
127
|
+
export type UnionToIntersect<U> = (U extends unknown ? (arg: U) => 0 : never) extends (arg: infer I) => 0 ? I : never;
|
|
128
|
+
export type UnionLast<U> = UnionToIntersect<U extends unknown ? (x: U) => 0 : never> extends (x: infer L) => 0 ? L : never;
|
|
129
|
+
export type UnionToTuple<U, L = UnionLast<U>> = [U] extends [never] ? [] : [...UnionToTuple<Exclude<U, L>>, L];
|
|
130
|
+
export type UnionStringLiteralToTuple<T> = T extends TUnion<infer L> ? {
|
|
131
|
+
[I in keyof L]: L[I] extends TLiteral<infer C> ? C : never;
|
|
132
|
+
} : never;
|
|
133
|
+
export type UnionLiteralsFromObject<T extends TObject> = {
|
|
134
|
+
[K in ObjectPropertyKeys<T>]: TLiteral<K>;
|
|
135
|
+
} extends infer R ? UnionToTuple<R[keyof R]> : never;
|
|
136
|
+
export interface TKeyOf<T extends TObject> extends TUnion<UnionLiteralsFromObject<T>> {
|
|
137
|
+
}
|
|
138
|
+
export type TLiteralValue = string | number | boolean;
|
|
139
|
+
export interface TLiteral<T extends TLiteralValue = TLiteralValue> extends TSchema {
|
|
140
|
+
[Kind]: 'Literal';
|
|
141
|
+
static: T;
|
|
142
|
+
const: T;
|
|
143
|
+
}
|
|
144
|
+
export interface TNever extends TSchema {
|
|
145
|
+
[Kind]: 'Never';
|
|
146
|
+
static: never;
|
|
147
|
+
allOf: [{
|
|
148
|
+
type: 'boolean';
|
|
149
|
+
const: false;
|
|
150
|
+
}, {
|
|
151
|
+
type: 'boolean';
|
|
152
|
+
const: true;
|
|
153
|
+
}];
|
|
154
|
+
}
|
|
155
|
+
export interface TNull extends TSchema {
|
|
156
|
+
[Kind]: 'Null';
|
|
157
|
+
static: null;
|
|
158
|
+
type: 'null';
|
|
159
|
+
}
|
|
160
|
+
export interface TNumber extends TSchema, NumericOptions {
|
|
161
|
+
[Kind]: 'Number';
|
|
162
|
+
static: number;
|
|
163
|
+
type: 'number';
|
|
164
|
+
}
|
|
165
|
+
export type ReadonlyOptionalPropertyKeys<T extends TProperties> = {
|
|
166
|
+
[K in keyof T]: T[K] extends TReadonlyOptional<TSchema> ? K : never;
|
|
167
|
+
}[keyof T];
|
|
168
|
+
export type ReadonlyPropertyKeys<T extends TProperties> = {
|
|
169
|
+
[K in keyof T]: T[K] extends TReadonly<TSchema> ? K : never;
|
|
170
|
+
}[keyof T];
|
|
171
|
+
export type OptionalPropertyKeys<T extends TProperties> = {
|
|
172
|
+
[K in keyof T]: T[K] extends TOptional<TSchema> ? K : never;
|
|
173
|
+
}[keyof T];
|
|
174
|
+
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>>>) extends infer O ? {
|
|
176
|
+
[K in keyof O]: O[K];
|
|
177
|
+
} : never;
|
|
178
|
+
export type PropertiesReduce<T extends TProperties, P extends unknown[]> = PropertiesReducer<T, {
|
|
179
|
+
[K in keyof T]: Static<T[K], P>;
|
|
180
|
+
}>;
|
|
181
|
+
export type TRecordProperties<K extends TUnion<TLiteral[]>, T extends TSchema> = Static<K> extends string ? {
|
|
182
|
+
[X in Static<K>]: T;
|
|
183
|
+
} : never;
|
|
184
|
+
export interface TProperties {
|
|
185
|
+
[key: string]: TSchema;
|
|
186
|
+
}
|
|
187
|
+
export type ObjectProperties<T> = T extends TObject<infer U> ? U : never;
|
|
188
|
+
export type ObjectPropertyKeys<T> = T extends TObject<infer U> ? keyof U : never;
|
|
189
|
+
export type TAdditionalProperties = undefined | TSchema | boolean;
|
|
190
|
+
export interface ObjectOptions extends SchemaOptions {
|
|
191
|
+
additionalProperties?: TAdditionalProperties;
|
|
192
|
+
minProperties?: number;
|
|
193
|
+
maxProperties?: number;
|
|
194
|
+
}
|
|
195
|
+
export interface TObject<T extends TProperties = TProperties> extends TSchema, ObjectOptions {
|
|
196
|
+
[Kind]: 'Object';
|
|
197
|
+
static: PropertiesReduce<T, this['params']>;
|
|
198
|
+
additionalProperties?: TAdditionalProperties;
|
|
199
|
+
type: 'object';
|
|
200
|
+
properties: T;
|
|
201
|
+
required?: string[];
|
|
202
|
+
}
|
|
203
|
+
export interface TOmit<T extends TObject, Properties extends ObjectPropertyKeys<T>[]> extends TObject, ObjectOptions {
|
|
204
|
+
static: Omit<Static<T, this['params']>, Properties[number]>;
|
|
205
|
+
properties: T extends TObject ? Omit<T['properties'], Properties[number]> : never;
|
|
206
|
+
}
|
|
207
|
+
export interface TPartial<T extends TObject> extends TObject {
|
|
208
|
+
static: Partial<Static<T, this['params']>>;
|
|
209
|
+
properties: {
|
|
210
|
+
[K in keyof T['properties']]: T['properties'][K] extends TReadonlyOptional<infer U> ? TReadonlyOptional<U> : T['properties'][K] extends TReadonly<infer U> ? TReadonlyOptional<U> : T['properties'][K] extends TOptional<infer U> ? TOptional<U> : TOptional<T['properties'][K]>;
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
export type TPick<T extends TObject, Properties extends ObjectPropertyKeys<T>[]> = TObject<{
|
|
214
|
+
[K in Properties[number]]: T['properties'][K];
|
|
215
|
+
}>;
|
|
216
|
+
export interface TPromise<T extends TSchema = TSchema> extends TSchema {
|
|
217
|
+
[Kind]: 'Promise';
|
|
218
|
+
static: Promise<Static<T, this['params']>>;
|
|
219
|
+
type: 'object';
|
|
220
|
+
instanceOf: 'Promise';
|
|
221
|
+
item: TSchema;
|
|
222
|
+
}
|
|
223
|
+
export type TRecordKey = TString | TNumeric | TUnion<TLiteral<any>[]>;
|
|
224
|
+
export interface TRecord<K extends TRecordKey = TRecordKey, T extends TSchema = TSchema> extends TSchema {
|
|
225
|
+
[Kind]: 'Record';
|
|
226
|
+
static: Record<Static<K>, Static<T, this['params']>>;
|
|
227
|
+
type: 'object';
|
|
228
|
+
patternProperties: {
|
|
229
|
+
[pattern: string]: T;
|
|
230
|
+
};
|
|
231
|
+
additionalProperties: false;
|
|
232
|
+
}
|
|
233
|
+
export interface TSelf extends TSchema {
|
|
234
|
+
[Kind]: 'Self';
|
|
235
|
+
static: this['params'][0];
|
|
236
|
+
$ref: string;
|
|
237
|
+
}
|
|
238
|
+
export type TRecursiveReduce<T extends TSchema> = Static<T, [TRecursiveReduce<T>]>;
|
|
239
|
+
export interface TRecursive<T extends TSchema> extends TSchema {
|
|
240
|
+
static: TRecursiveReduce<T>;
|
|
241
|
+
}
|
|
242
|
+
export interface TRef<T extends TSchema = TSchema> extends TSchema {
|
|
243
|
+
[Kind]: 'Ref';
|
|
244
|
+
static: Static<T, this['params']>;
|
|
245
|
+
$ref: string;
|
|
246
|
+
}
|
|
247
|
+
export interface TRequired<T extends TObject | TRef<TObject>> extends TObject {
|
|
248
|
+
static: Required<Static<T, this['params']>>;
|
|
249
|
+
properties: {
|
|
250
|
+
[K in keyof T['properties']]: T['properties'][K] extends TReadonlyOptional<infer U> ? TReadonly<U> : T['properties'][K] extends TReadonly<infer U> ? TReadonly<U> : T['properties'][K] extends TOptional<infer U> ? U : T['properties'][K];
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
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
|
+
export interface StringOptions<Format extends string> extends SchemaOptions {
|
|
255
|
+
minLength?: number;
|
|
256
|
+
maxLength?: number;
|
|
257
|
+
pattern?: string;
|
|
258
|
+
format?: Format;
|
|
259
|
+
contentEncoding?: '7bit' | '8bit' | 'binary' | 'quoted-printable' | 'base64';
|
|
260
|
+
contentMediaType?: string;
|
|
261
|
+
}
|
|
262
|
+
export interface TString<Format extends string = string> extends TSchema, StringOptions<Format> {
|
|
263
|
+
[Kind]: 'String';
|
|
264
|
+
static: string;
|
|
265
|
+
type: 'string';
|
|
266
|
+
}
|
|
267
|
+
export type TupleToArray<T extends TTuple<TSchema[]>> = T extends TTuple<infer R> ? R : never;
|
|
268
|
+
export interface TTuple<T extends TSchema[] = TSchema[]> extends TSchema {
|
|
269
|
+
[Kind]: 'Tuple';
|
|
270
|
+
static: {
|
|
271
|
+
[K in keyof T]: T[K] extends TSchema ? Static<T[K], this['params']> : T[K];
|
|
272
|
+
};
|
|
273
|
+
type: 'array';
|
|
274
|
+
items?: T;
|
|
275
|
+
additionalItems?: false;
|
|
276
|
+
minItems: number;
|
|
277
|
+
maxItems: number;
|
|
278
|
+
}
|
|
279
|
+
export interface TUndefined extends TSchema {
|
|
280
|
+
[Kind]: 'Undefined';
|
|
281
|
+
static: undefined;
|
|
282
|
+
type: 'null';
|
|
283
|
+
typeOf: 'Undefined';
|
|
284
|
+
}
|
|
285
|
+
export interface TUnion<T extends TSchema[] = TSchema[]> extends TSchema {
|
|
286
|
+
[Kind]: 'Union';
|
|
287
|
+
static: {
|
|
288
|
+
[K in keyof T]: T[K] extends TSchema ? Static<T[K], this['params']> : never;
|
|
289
|
+
}[number];
|
|
290
|
+
anyOf: T;
|
|
291
|
+
}
|
|
292
|
+
export interface Uint8ArrayOptions extends SchemaOptions {
|
|
293
|
+
maxByteLength?: number;
|
|
294
|
+
minByteLength?: number;
|
|
295
|
+
}
|
|
296
|
+
export interface TUint8Array extends TSchema, Uint8ArrayOptions {
|
|
297
|
+
[Kind]: 'Uint8Array';
|
|
298
|
+
static: Uint8Array;
|
|
299
|
+
instanceOf: 'Uint8Array';
|
|
300
|
+
type: 'object';
|
|
301
|
+
}
|
|
302
|
+
export interface TUnknown extends TSchema {
|
|
303
|
+
[Kind]: 'Unknown';
|
|
304
|
+
static: unknown;
|
|
305
|
+
}
|
|
306
|
+
export interface UnsafeOptions extends SchemaOptions {
|
|
307
|
+
[Kind]?: string;
|
|
308
|
+
}
|
|
309
|
+
export interface TUnsafe<T> extends TSchema {
|
|
310
|
+
[Kind]: string;
|
|
311
|
+
static: T;
|
|
312
|
+
}
|
|
313
|
+
export interface TVoid extends TSchema {
|
|
314
|
+
[Kind]: 'Void';
|
|
315
|
+
static: void;
|
|
316
|
+
type: 'null';
|
|
317
|
+
typeOf: 'Void';
|
|
318
|
+
}
|
|
319
|
+
/** Creates a static type from a TypeBox type */
|
|
320
|
+
export type Static<T extends TSchema, P extends unknown[] = []> = (T & {
|
|
321
|
+
params: P;
|
|
322
|
+
})['static'];
|
|
323
|
+
export declare class TypeBuilder {
|
|
324
|
+
/** Creates a readonly optional property */
|
|
325
|
+
ReadonlyOptional<T extends TSchema>(item: T): TReadonlyOptional<T>;
|
|
326
|
+
/** Creates a readonly property */
|
|
327
|
+
Readonly<T extends TSchema>(item: T): TReadonly<T>;
|
|
328
|
+
/** Creates a optional property */
|
|
329
|
+
Optional<T extends TSchema>(item: T): TOptional<T>;
|
|
330
|
+
/** `Standard` Creates a any type */
|
|
331
|
+
Any(options?: SchemaOptions): TAny;
|
|
332
|
+
/** `Standard` Creates a array type */
|
|
333
|
+
Array<T extends TSchema>(items: T, options?: ArrayOptions): TArray<T>;
|
|
334
|
+
/** `Standard` Creates a boolean type */
|
|
335
|
+
Boolean(options?: SchemaOptions): TBoolean;
|
|
336
|
+
/** `Extended` Creates a tuple type from this constructors parameters */
|
|
337
|
+
ConstructorParameters<T extends TConstructor<any[], any>>(schema: T, options?: SchemaOptions): TConstructorParameters<T>;
|
|
338
|
+
/** `Extended` Creates a constructor type */
|
|
339
|
+
Constructor<T extends TTuple<TSchema[]>, U extends TSchema>(parameters: T, returns: U, options?: SchemaOptions): TConstructor<TupleToArray<T>, U>;
|
|
340
|
+
/** `Extended` Creates a constructor type */
|
|
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 */
|
|
345
|
+
Enum<T extends Record<string, string | number>>(item: T, options?: SchemaOptions): TEnum<T>;
|
|
346
|
+
/** `Extended` Creates a function type */
|
|
347
|
+
Function<T extends TTuple<TSchema[]>, U extends TSchema>(parameters: T, returns: U, options?: SchemaOptions): TFunction<TupleToArray<T>, U>;
|
|
348
|
+
/** `Extended` Creates a function type */
|
|
349
|
+
Function<T extends TSchema[], U extends TSchema>(parameters: [...T], returns: U, options?: SchemaOptions): TFunction<T, U>;
|
|
350
|
+
/** `Extended` Creates a type from this constructors instance type */
|
|
351
|
+
InstanceType<T extends TConstructor<any[], any>>(schema: T, options?: SchemaOptions): TInstanceType<T>;
|
|
352
|
+
/** `Standard` Creates a integer type */
|
|
353
|
+
Integer(options?: NumericOptions): TInteger;
|
|
354
|
+
/** `Standard` Creates a intersect type. */
|
|
355
|
+
Intersect<T extends TObject[]>(objects: [...T], options?: ObjectOptions): TIntersect<T>;
|
|
356
|
+
/** `Standard` Creates a keyof type */
|
|
357
|
+
KeyOf<T extends TObject>(object: T, options?: SchemaOptions): TKeyOf<T>;
|
|
358
|
+
/** `Standard` Creates a literal type. */
|
|
359
|
+
Literal<T extends TLiteralValue>(value: T, options?: SchemaOptions): TLiteral<T>;
|
|
360
|
+
/** `Standard` Creates a never type */
|
|
361
|
+
Never(options?: SchemaOptions): TNever;
|
|
362
|
+
/** `Standard` Creates a null type */
|
|
363
|
+
Null(options?: SchemaOptions): TNull;
|
|
364
|
+
/** `Standard` Creates a number type */
|
|
365
|
+
Number(options?: NumericOptions): TNumber;
|
|
366
|
+
/** `Standard` Creates an object type */
|
|
367
|
+
Object<T extends TProperties>(properties: T, options?: ObjectOptions): TObject<T>;
|
|
368
|
+
/** `Standard` Creates a new object type whose keys are omitted from the given source type */
|
|
369
|
+
Omit<T extends TObject, K extends TUnion<TLiteral<string>[]>>(schema: T, keys: K, options?: ObjectOptions): TOmit<T, UnionStringLiteralToTuple<K>>;
|
|
370
|
+
/** `Standard` Creates a new object type whose keys are omitted from the given source type */
|
|
371
|
+
Omit<T extends TObject, K extends ObjectPropertyKeys<T>[]>(schema: T, keys: readonly [...K], options?: ObjectOptions): TOmit<T, K>;
|
|
372
|
+
/** `Extended` Creates a tuple type from this functions parameters */
|
|
373
|
+
Parameters<T extends TFunction<any[], any>>(schema: T, options?: SchemaOptions): TParameters<T>;
|
|
374
|
+
/** `Standard` Creates an object type whose properties are all optional */
|
|
375
|
+
Partial<T extends TObject>(schema: T, options?: ObjectOptions): TPartial<T>;
|
|
376
|
+
/** `Standard` Creates a new object type whose keys are picked from the given source type */
|
|
377
|
+
Pick<T extends TObject, K extends TUnion<TLiteral<string>[]>>(schema: T, keys: K, options?: ObjectOptions): TPick<T, UnionStringLiteralToTuple<K>>;
|
|
378
|
+
/** `Standard` Creates a new object type whose keys are picked from the given source type */
|
|
379
|
+
Pick<T extends TObject, K extends ObjectPropertyKeys<T>[]>(schema: T, keys: readonly [...K], options?: ObjectOptions): TPick<T, K>;
|
|
380
|
+
/** `Extended` Creates a Promise type */
|
|
381
|
+
Promise<T extends TSchema>(item: T, options?: SchemaOptions): TPromise<T>;
|
|
382
|
+
/** `Standard` Creates an object whose properties are derived from the given string literal union. */
|
|
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 */
|
|
385
|
+
Record<K extends TString | TNumeric, T extends TSchema>(key: K, schema: T, options?: ObjectOptions): TRecord<K, T>;
|
|
386
|
+
/** `Standard` Creates recursive type */
|
|
387
|
+
Recursive<T extends TSchema>(callback: (self: TSelf) => T, options?: SchemaOptions): TRecursive<T>;
|
|
388
|
+
/** `Standard` Creates a reference type. The referenced type must contain a $id. */
|
|
389
|
+
Ref<T extends TSchema>(schema: T, options?: SchemaOptions): TRef<T>;
|
|
390
|
+
/** `Standard` Creates a string type from a regular expression */
|
|
391
|
+
RegEx(regex: RegExp, options?: SchemaOptions): TString;
|
|
392
|
+
/** `Standard` Creates an object type whose properties are all required */
|
|
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 */
|
|
399
|
+
String<Format extends string>(options?: StringOptions<StringFormatOption | Format>): TString<Format>;
|
|
400
|
+
/** `Standard` Creates a tuple type */
|
|
401
|
+
Tuple<T extends TSchema[]>(items: [...T], options?: SchemaOptions): TTuple<T>;
|
|
402
|
+
/** `Extended` Creates a undefined type */
|
|
403
|
+
Undefined(options?: SchemaOptions): TUndefined;
|
|
404
|
+
/** `Standard` Creates a union type */
|
|
405
|
+
Union(items: [], options?: SchemaOptions): TNever;
|
|
406
|
+
/** `Standard` Creates a union type */
|
|
407
|
+
Union<T extends TSchema[]>(items: [...T], options?: SchemaOptions): TUnion<T>;
|
|
408
|
+
/** `Extended` Creates a Uint8Array type */
|
|
409
|
+
Uint8Array(options?: Uint8ArrayOptions): TUint8Array;
|
|
410
|
+
/** `Standard` Creates an unknown type */
|
|
411
|
+
Unknown(options?: SchemaOptions): TUnknown;
|
|
412
|
+
/** `Standard` Creates a user defined schema that infers as type T */
|
|
413
|
+
Unsafe<T>(options?: UnsafeOptions): TUnsafe<T>;
|
|
414
|
+
/** `Extended` Creates a void type */
|
|
415
|
+
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
|
+
}
|
|
421
|
+
/** JSON Schema Type Builder with Static Type Resolution for TypeScript */
|
|
422
|
+
export declare const Type: TypeBuilder;
|