@sinclair/typebox 0.24.51 → 0.24.52

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