@sinclair/typebox 0.23.5 → 0.24.2

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/typebox.d.ts CHANGED
@@ -1,351 +1,363 @@
1
- export declare const ReadonlyOptionalModifier: unique symbol;
2
- export declare const OptionalModifier: unique symbol;
3
- export declare const ReadonlyModifier: unique symbol;
1
+ export declare const Kind: unique symbol;
2
+ export declare const Modifier: unique symbol;
4
3
  export declare type TModifier = TReadonlyOptional<TSchema> | TOptional<TSchema> | TReadonly<TSchema>;
5
- export declare type TReadonlyOptional<T extends TSchema> = T & {
6
- modifier: typeof ReadonlyOptionalModifier;
4
+ export declare type TReadonly<T extends TSchema> = T & {
5
+ [Modifier]: 'Readonly';
7
6
  };
8
7
  export declare type TOptional<T extends TSchema> = T & {
9
- modifier: typeof OptionalModifier;
8
+ [Modifier]: 'Optional';
10
9
  };
11
- export declare type TReadonly<T extends TSchema> = T & {
12
- modifier: typeof ReadonlyModifier;
10
+ export declare type TReadonlyOptional<T extends TSchema> = T & {
11
+ [Modifier]: 'ReadonlyOptional';
13
12
  };
14
- export declare const NamespaceKind: unique symbol;
15
- export declare const KeyOfKind: unique symbol;
16
- export declare const IntersectKind: unique symbol;
17
- export declare const UnionKind: unique symbol;
18
- export declare const TupleKind: unique symbol;
19
- export declare const ObjectKind: unique symbol;
20
- export declare const RecordKind: unique symbol;
21
- export declare const ArrayKind: unique symbol;
22
- export declare const EnumKind: unique symbol;
23
- export declare const LiteralKind: unique symbol;
24
- export declare const StringKind: unique symbol;
25
- export declare const NumberKind: unique symbol;
26
- export declare const IntegerKind: unique symbol;
27
- export declare const BooleanKind: unique symbol;
28
- export declare const NullKind: unique symbol;
29
- export declare const UnknownKind: unique symbol;
30
- export declare const AnyKind: unique symbol;
31
- export declare const RefKind: unique symbol;
32
- export interface CustomOptions {
13
+ export interface DesignType {
14
+ type: string;
15
+ [props: string]: any;
16
+ }
17
+ export interface SchemaOptions {
18
+ $schema?: string;
19
+ /** Id for this schema */
33
20
  $id?: string;
21
+ /** Title of this schema */
34
22
  title?: string;
23
+ /** Description of this schema */
35
24
  description?: string;
25
+ /** Default value hint for this schema */
36
26
  default?: any;
27
+ /** Example values matching this schema. */
37
28
  examples?: any;
29
+ /** Design metadata for this schema */
30
+ design?: DesignType;
38
31
  [prop: string]: any;
39
32
  }
40
- 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';
41
- export declare type StringOptions<TFormat extends string> = {
42
- minLength?: number;
43
- maxLength?: number;
44
- pattern?: string;
45
- format?: TFormat;
46
- contentEncoding?: '7bit' | '8bit' | 'binary' | 'quoted-printable' | 'base64';
47
- contentMediaType?: string;
48
- } & CustomOptions;
49
- export declare type ArrayOptions = {
50
- uniqueItems?: boolean;
51
- minItems?: number;
52
- maxItems?: number;
53
- } & CustomOptions;
54
- export declare type NumberOptions = {
33
+ export interface TSchema extends SchemaOptions {
34
+ [Kind]: string;
35
+ [Modifier]?: string;
36
+ params: unknown[];
37
+ static: unknown;
38
+ }
39
+ 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;
40
+ export interface NumericOptions extends SchemaOptions {
55
41
  exclusiveMaximum?: number;
56
42
  exclusiveMinimum?: number;
57
43
  maximum?: number;
58
44
  minimum?: number;
59
45
  multipleOf?: number;
60
- } & CustomOptions;
61
- export declare type IntersectOptions = {
62
- unevaluatedProperties?: boolean;
63
- } & CustomOptions;
64
- export declare type ObjectOptions = {
65
- additionalProperties?: boolean;
66
- minProperties?: number;
67
- maxProperties?: number;
68
- } & CustomOptions;
69
- export declare type TDefinitions = {
70
- [key: string]: TSchema;
71
- };
72
- export declare type TNamespace<T extends TDefinitions> = {
73
- kind: typeof NamespaceKind;
74
- $defs: T;
75
- } & CustomOptions;
76
- export interface TSchema {
77
- $static: unknown;
78
- }
79
- export declare type TEnumType = Record<string, string | number>;
80
- export declare type TKey = string | number | symbol;
81
- export declare type TValue = string | number | boolean;
82
- export declare type TRecordKey = TString | TNumber | TKeyOf<any> | TUnion<any>;
83
- export declare type TEnumKey<T = TKey> = {
46
+ }
47
+ export declare type TNumeric = TInteger | TNumber;
48
+ export interface TAny extends TSchema {
49
+ [Kind]: 'Any';
50
+ static: any;
51
+ }
52
+ export interface ArrayOptions extends SchemaOptions {
53
+ uniqueItems?: boolean;
54
+ minItems?: number;
55
+ maxItems?: number;
56
+ }
57
+ export interface TArray<T extends TSchema = TSchema> extends TSchema, ArrayOptions {
58
+ [Kind]: 'Array';
59
+ static: Array<Static<T, this['params']>>;
60
+ type: 'array';
61
+ items: T;
62
+ }
63
+ export interface TBoolean extends TSchema {
64
+ [Kind]: 'Boolean';
65
+ static: boolean;
66
+ type: 'boolean';
67
+ }
68
+ export declare type TContructorParameters<T extends readonly TSchema[], P extends unknown[]> = [...{
69
+ [K in keyof T]: T[K] extends TSchema ? Static<T[K], P> : never;
70
+ }];
71
+ export interface TConstructor<T extends TSchema[] = TSchema[], U extends TSchema = TSchema> extends TSchema {
72
+ [Kind]: 'Constructor';
73
+ static: new (...param: TContructorParameters<T, this['params']>) => Static<U, this['params']>;
74
+ type: 'constructor';
75
+ parameters: T;
76
+ returns: U;
77
+ }
78
+ export interface TEnumOption<T> {
84
79
  type: 'number' | 'string';
85
80
  const: T;
81
+ }
82
+ export interface TEnum<T extends Record<string, string | number> = Record<string, string | number>> extends TSchema {
83
+ [Kind]: 'Union';
84
+ static: T[keyof T];
85
+ anyOf: TLiteral<string | number>[];
86
+ }
87
+ export declare type TFunctionParameters<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: TFunctionParameters<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 IntersectEvaluate<T extends readonly TSchema[], P extends unknown[]> = {
103
+ [K in keyof T]: T[K] extends TSchema ? Static<T[K], P> : never;
86
104
  };
105
+ 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 : {};
106
+ export interface TIntersect<T extends TObject[] = TObject[]> extends TObject {
107
+ static: IntersectReduce<unknown, IntersectEvaluate<T, this['params']>>;
108
+ properties: Record<keyof IntersectReduce<unknown, IntersectEvaluate<T, this['params']>>, TSchema>;
109
+ }
110
+ declare type UnionToIntersect<U> = (U extends unknown ? (arg: U) => 0 : never) extends (arg: infer I) => 0 ? I : never;
111
+ declare type UnionLast<U> = UnionToIntersect<U extends unknown ? (x: U) => 0 : never> extends (x: infer L) => 0 ? L : never;
112
+ declare type UnionToTuple<U, L = UnionLast<U>> = [U] extends [never] ? [] : [...UnionToTuple<Exclude<U, L>>, L];
113
+ export declare type TKeyOf<T extends TObject> = {
114
+ [K in ObjectPropertyKeys<T>]: TLiteral<K>;
115
+ } extends infer R ? UnionToTuple<R[keyof R]> : never;
116
+ export declare type TLiteralValue = string | number | boolean;
117
+ export interface TLiteral<T extends TLiteralValue = TLiteralValue> extends TSchema {
118
+ [Kind]: 'Literal';
119
+ static: T;
120
+ const: T;
121
+ }
122
+ export interface TNull extends TSchema {
123
+ [Kind]: 'Null';
124
+ static: null;
125
+ type: 'null';
126
+ }
127
+ export interface TNumber extends TSchema, NumericOptions {
128
+ [Kind]: 'Number';
129
+ static: number;
130
+ type: 'number';
131
+ }
132
+ export declare type ReadonlyOptionalPropertyKeys<T extends TProperties> = {
133
+ [K in keyof T]: T[K] extends TReadonlyOptional<TSchema> ? K : never;
134
+ }[keyof T];
135
+ export declare type ReadonlyPropertyKeys<T extends TProperties> = {
136
+ [K in keyof T]: T[K] extends TReadonly<TSchema> ? K : never;
137
+ }[keyof T];
138
+ export declare type OptionalPropertyKeys<T extends TProperties> = {
139
+ [K in keyof T]: T[K] extends TOptional<TSchema> ? K : never;
140
+ }[keyof T];
141
+ export declare type RequiredPropertyKeys<T extends TProperties> = keyof Omit<T, ReadonlyOptionalPropertyKeys<T> | ReadonlyPropertyKeys<T> | OptionalPropertyKeys<T>>;
142
+ export declare type PropertiesReduce<T extends TProperties, P extends unknown[]> = {
143
+ readonly [K in ReadonlyOptionalPropertyKeys<T>]?: Static<T[K], P>;
144
+ } & {
145
+ readonly [K in ReadonlyPropertyKeys<T>]: Static<T[K], P>;
146
+ } & {
147
+ [K in OptionalPropertyKeys<T>]?: Static<T[K], P>;
148
+ } & {
149
+ [K in RequiredPropertyKeys<T>]: Static<T[K], P>;
150
+ } extends infer R ? {
151
+ [K in keyof R]: R[K];
152
+ } : never;
153
+ export declare type TRecordProperties<K extends TUnion<TLiteral[]>, T extends TSchema> = Static<K> extends string ? {
154
+ [X in Static<K>]: T;
155
+ } : never;
87
156
  export interface TProperties {
88
157
  [key: string]: TSchema;
89
158
  }
90
- export interface TRecord<K extends TRecordKey, T extends TSchema> extends TSchema, ObjectOptions {
91
- $static: StaticRecord<K, T>;
92
- kind: typeof RecordKind;
93
- type: 'object';
94
- patternProperties: {
95
- [pattern: string]: T;
96
- };
97
- }
98
- export interface TTuple<T extends TSchema[]> extends TSchema, CustomOptions {
99
- $static: StaticTuple<T>;
100
- kind: typeof TupleKind;
101
- type: 'array';
102
- items?: T;
103
- additionalItems?: false;
104
- minItems: number;
105
- maxItems: number;
159
+ export declare type ObjectProperties<T> = T extends TObject<infer U> ? U : never;
160
+ export declare type ObjectPropertyKeys<T> = T extends TObject<infer U> ? keyof U : never;
161
+ export interface ObjectOptions extends SchemaOptions {
162
+ additionalProperties?: boolean;
163
+ minProperties?: number;
164
+ maxProperties?: number;
106
165
  }
107
- export interface TObject<T extends TProperties> extends TSchema, ObjectOptions {
108
- $static: StaticObject<T>;
109
- kind: typeof ObjectKind;
166
+ export interface TObject<T extends TProperties = TProperties> extends TSchema, ObjectOptions {
167
+ [Kind]: 'Object';
168
+ static: PropertiesReduce<T, this['params']>;
110
169
  type: 'object';
111
170
  properties: T;
112
171
  required?: string[];
113
172
  }
114
- export interface TUnion<T extends TSchema[]> extends TSchema, CustomOptions {
115
- $static: StaticUnion<T>;
116
- kind: typeof UnionKind;
117
- anyOf: T;
173
+ export interface TOmit<T extends TObject, Properties extends ObjectPropertyKeys<T>[]> extends TObject, ObjectOptions {
174
+ static: Omit<Static<T, this['params']>, Properties[number]>;
175
+ properties: T extends TObject ? Omit<T['properties'], Properties[number]> : never;
118
176
  }
119
- export interface TIntersect<T extends TSchema[]> extends TSchema, IntersectOptions {
120
- $static: StaticIntersect<T>;
121
- kind: typeof IntersectKind;
122
- type: 'object';
123
- allOf: T;
177
+ export interface TPartial<T extends TObject> extends TObject {
178
+ static: Partial<Static<T, this['params']>>;
124
179
  }
125
- export interface TKeyOf<T extends TKey[]> extends TSchema, CustomOptions {
126
- $static: StaticKeyOf<T>;
127
- kind: typeof KeyOfKind;
128
- type: 'string';
129
- enum: T;
180
+ export interface TPick<T extends TObject, Properties extends ObjectPropertyKeys<T>[]> extends TObject, ObjectOptions {
181
+ static: Pick<Static<T, this['params']>, Properties[number]>;
182
+ properties: ObjectProperties<T>;
130
183
  }
131
- export interface TArray<T extends TSchema> extends TSchema, ArrayOptions {
132
- $static: StaticArray<T>;
133
- kind: typeof ArrayKind;
134
- type: 'array';
135
- items: T;
184
+ export interface TPromise<T extends TSchema = TSchema> extends TSchema {
185
+ [Kind]: 'Promise';
186
+ static: Promise<Static<T, this['params']>>;
187
+ type: 'promise';
188
+ item: TSchema;
136
189
  }
137
- export interface TLiteral<T extends TValue> extends TSchema, CustomOptions {
138
- $static: StaticLiteral<T>;
139
- kind: typeof LiteralKind;
140
- const: T;
190
+ export declare type TRecordKey = TString | TNumber | TUnion<TLiteral<any>[]>;
191
+ export interface TRecord<K extends TRecordKey = TRecordKey, T extends TSchema = TSchema> extends TSchema {
192
+ [Kind]: 'Record';
193
+ static: Record<Static<K>, Static<T, this['params']>>;
194
+ type: 'object';
195
+ patternProperties: {
196
+ [pattern: string]: T;
197
+ };
198
+ additionalProperties: false;
141
199
  }
142
- export interface TEnum<T extends TEnumKey[]> extends TSchema, CustomOptions {
143
- $static: StaticEnum<T>;
144
- kind: typeof EnumKind;
145
- anyOf: T;
200
+ export interface TSelf extends TSchema {
201
+ [Kind]: 'Self';
202
+ static: this['params'][0];
203
+ $ref: string;
204
+ }
205
+ export declare type TRecursiveReduce<T extends TSchema> = Static<T, [TRecursiveReduce<T>]>;
206
+ export interface TRecursive<T extends TSchema> extends TSchema {
207
+ static: TRecursiveReduce<T>;
146
208
  }
147
- export interface TRef<T extends TSchema> extends TSchema, CustomOptions {
148
- $static: Static<T>;
149
- kind: typeof RefKind;
209
+ export interface TRef<T extends TSchema = TSchema> extends TSchema {
210
+ [Kind]: 'Ref';
211
+ static: Static<T, this['params']>;
150
212
  $ref: string;
151
213
  }
214
+ export interface TRequired<T extends TObject | TRef<TObject>> extends TObject {
215
+ static: Required<Static<T, this['params']>>;
216
+ }
217
+ 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';
218
+ export interface StringOptions<TFormat extends string> extends SchemaOptions {
219
+ minLength?: number;
220
+ maxLength?: number;
221
+ pattern?: string;
222
+ format?: TFormat;
223
+ contentEncoding?: '7bit' | '8bit' | 'binary' | 'quoted-printable' | 'base64';
224
+ contentMediaType?: string;
225
+ }
152
226
  export interface TString extends TSchema, StringOptions<string> {
153
- $static: string;
154
- kind: typeof StringKind;
227
+ [Kind]: 'String';
228
+ static: string;
155
229
  type: 'string';
156
230
  }
157
- export interface TNumber extends TSchema, NumberOptions {
158
- $static: number;
159
- kind: typeof NumberKind;
160
- type: 'number';
231
+ export interface TTuple<T extends TSchema[] = TSchema[]> extends TSchema {
232
+ [Kind]: 'Tuple';
233
+ static: {
234
+ [K in keyof T]: T[K] extends TSchema ? Static<T[K], this['params']> : T[K];
235
+ };
236
+ type: 'array';
237
+ items?: T;
238
+ additionalItems?: false;
239
+ minItems: number;
240
+ maxItems: number;
161
241
  }
162
- export interface TInteger extends TSchema, NumberOptions {
163
- $static: number;
164
- kind: typeof IntegerKind;
165
- type: 'integer';
242
+ export interface TUndefined extends TSchema {
243
+ [Kind]: 'Undefined';
244
+ specialized: 'Undefined';
245
+ static: undefined;
246
+ type: 'object';
166
247
  }
167
- export interface TBoolean extends TSchema, CustomOptions {
168
- $static: boolean;
169
- kind: typeof BooleanKind;
170
- type: 'boolean';
248
+ export interface TUnion<T extends TSchema[] = TSchema[]> extends TSchema {
249
+ [Kind]: 'Union';
250
+ static: {
251
+ [K in keyof T]: T[K] extends TSchema ? Static<T[K], this['params']> : never;
252
+ }[number];
253
+ anyOf: T;
171
254
  }
172
- export interface TNull extends TSchema, CustomOptions {
173
- $static: null;
174
- kind: typeof NullKind;
175
- type: 'null';
255
+ export interface Uint8ArrayOptions extends SchemaOptions {
256
+ maxByteLength?: number;
257
+ minByteLength?: number;
176
258
  }
177
- export interface TUnknown extends TSchema, CustomOptions {
178
- $static: unknown;
179
- kind: typeof UnknownKind;
180
- }
181
- export interface TAny extends TSchema, CustomOptions {
182
- $static: any;
183
- kind: typeof AnyKind;
184
- }
185
- export declare const ConstructorKind: unique symbol;
186
- export declare const FunctionKind: unique symbol;
187
- export declare const PromiseKind: unique symbol;
188
- export declare const UndefinedKind: unique symbol;
189
- export declare const VoidKind: unique symbol;
190
- export interface TConstructor<T extends TSchema[], U extends TSchema> extends TSchema, CustomOptions {
191
- $static: StaticConstructor<T, U>;
192
- kind: typeof ConstructorKind;
193
- type: 'constructor';
194
- arguments: TSchema[];
195
- returns: TSchema;
259
+ export interface TUint8Array extends TSchema, Uint8ArrayOptions {
260
+ [Kind]: 'Uint8Array';
261
+ static: Uint8Array;
262
+ specialized: 'Uint8Array';
263
+ type: 'object';
196
264
  }
197
- export interface TFunction<T extends TSchema[], U extends TSchema> extends TSchema, CustomOptions {
198
- $static: StaticFunction<T, U>;
199
- kind: typeof FunctionKind;
200
- type: 'function';
201
- arguments: TSchema[];
202
- returns: TSchema;
265
+ export interface TUnknown extends TSchema {
266
+ [Kind]: 'Unknown';
267
+ static: unknown;
203
268
  }
204
- export interface TPromise<T extends TSchema> extends TSchema, CustomOptions {
205
- $static: StaticPromise<T>;
206
- kind: typeof PromiseKind;
207
- type: 'promise';
208
- item: TSchema;
269
+ export interface UnsafeOptions extends SchemaOptions {
270
+ [Kind]?: string;
209
271
  }
210
- export interface TUndefined extends TSchema, CustomOptions {
211
- $static: undefined;
212
- kind: typeof UndefinedKind;
213
- type: 'undefined';
214
- }
215
- export interface TVoid extends TSchema, CustomOptions {
216
- $static: void;
217
- kind: typeof VoidKind;
218
- type: 'void';
219
- }
220
- export declare type Selectable = TObject<TProperties> | TRef<TObject<TProperties>>;
221
- export declare type SelectablePropertyKeys<T extends Selectable> = T extends TObject<infer U> ? keyof U : T extends TRef<TObject<infer U>> ? keyof U : never;
222
- export declare type SelectableProperties<T extends Selectable> = T extends TObject<infer U> ? U : T extends TRef<TObject<infer U>> ? U : never;
223
- export declare type UnionToIntersect<U> = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never;
224
- export declare type StaticReadonlyOptionalPropertyKeys<T extends TProperties> = {
225
- [K in keyof T]: T[K] extends TReadonlyOptional<TSchema> ? K : never;
226
- }[keyof T];
227
- export declare type StaticReadonlyPropertyKeys<T extends TProperties> = {
228
- [K in keyof T]: T[K] extends TReadonly<TSchema> ? K : never;
229
- }[keyof T];
230
- export declare type StaticOptionalPropertyKeys<T extends TProperties> = {
231
- [K in keyof T]: T[K] extends TOptional<TSchema> ? K : never;
232
- }[keyof T];
233
- export declare type StaticRequiredPropertyKeys<T extends TProperties> = keyof Omit<T, StaticReadonlyOptionalPropertyKeys<T> | StaticReadonlyPropertyKeys<T> | StaticOptionalPropertyKeys<T>>;
234
- export declare type StaticIntersectEvaluate<T extends readonly TSchema[]> = {
235
- [K in keyof T]: T[K] extends TSchema ? Static<T[K]> : never;
236
- };
237
- export declare type StaticIntersectReduce<I extends unknown, T extends readonly any[]> = T extends [infer A, ...infer B] ? StaticIntersectReduce<I & A, B> : I;
238
- export declare type StaticRequired<T extends TProperties> = {
239
- [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];
240
- };
241
- export declare type StaticPartial<T extends TProperties> = {
242
- [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]>;
243
- };
244
- export declare type StaticProperties<T extends TProperties> = {
245
- readonly [K in StaticReadonlyOptionalPropertyKeys<T>]?: Static<T[K]>;
246
- } & {
247
- readonly [K in StaticReadonlyPropertyKeys<T>]: Static<T[K]>;
248
- } & {
249
- [K in StaticOptionalPropertyKeys<T>]?: Static<T[K]>;
250
- } & {
251
- [K in StaticRequiredPropertyKeys<T>]: Static<T[K]>;
252
- };
253
- export declare type StaticRecord<K extends TRecordKey, T extends TSchema> = K extends TString ? Record<string, Static<T>> : K extends TNumber ? Record<number, Static<T>> : K extends TKeyOf<TKey[]> ? Record<K['$static'], Static<T>> : K extends TUnion<TSchema[]> ? Record<K['$static'], Static<T>> : never;
254
- export declare type StaticEnum<T> = T extends TEnumKey<infer U>[] ? U : never;
255
- export declare type StaticKeyOf<T extends TKey[]> = T extends Array<infer K> ? K : never;
256
- export declare type StaticIntersect<T extends readonly TSchema[]> = StaticIntersectReduce<unknown, StaticIntersectEvaluate<T>>;
257
- export declare type StaticUnion<T extends readonly TSchema[]> = {
258
- [K in keyof T]: T[K] extends TSchema ? Static<T[K]> : never;
259
- }[number];
260
- export declare type StaticTuple<T extends readonly TSchema[]> = {
261
- [K in keyof T]: T[K] extends TSchema ? Static<T[K]> : never;
262
- };
263
- export declare type StaticObject<T extends TProperties> = StaticProperties<T> extends infer I ? {
264
- [K in keyof I]: I[K];
265
- } : never;
266
- export declare type StaticArray<T extends TSchema> = Array<Static<T>>;
267
- export declare type StaticLiteral<T extends TValue> = T;
268
- export declare type StaticParameters<T extends readonly TSchema[]> = {
269
- [K in keyof T]: T[K] extends TSchema ? Static<T[K]> : never;
270
- };
271
- export declare type StaticConstructor<T extends readonly TSchema[], U extends TSchema> = new (...args: [...StaticParameters<T>]) => Static<U>;
272
- export declare type StaticFunction<T extends readonly TSchema[], U extends TSchema> = (...args: [...StaticParameters<T>]) => Static<U>;
273
- export declare type StaticPromise<T extends TSchema> = Promise<Static<T>>;
274
- export declare type Static<T extends TSchema> = T['$static'];
272
+ export interface TUnsafe<T> extends TSchema {
273
+ [Kind]: string;
274
+ static: T;
275
+ }
276
+ export interface TVoid extends TSchema {
277
+ [Kind]: 'Void';
278
+ static: void;
279
+ type: 'null';
280
+ }
281
+ /** Creates a static type from a TypeBox type */
282
+ export declare type Static<T extends TSchema, P extends unknown[] = []> = (T & {
283
+ params: P;
284
+ })['static'];
275
285
  export declare class TypeBuilder {
276
- protected readonly schemas: Map<string, TSchema>;
277
- constructor();
278
- /** `Standard` Modifies an object property to be both readonly and optional */
286
+ /** Creates a readonly optional property */
279
287
  ReadonlyOptional<T extends TSchema>(item: T): TReadonlyOptional<T>;
280
- /** `Standard` Modifies an object property to be readonly */
288
+ /** Creates a readonly property */
281
289
  Readonly<T extends TSchema>(item: T): TReadonly<T>;
282
- /** `Standard` Modifies an object property to be optional */
290
+ /** Creates a optional property */
283
291
  Optional<T extends TSchema>(item: T): TOptional<T>;
284
- /** `Standard` Creates a type type */
285
- Tuple<T extends TSchema[]>(items: [...T], options?: CustomOptions): TTuple<T>;
286
- /** `Standard` Creates an object type with the given properties */
287
- Object<T extends TProperties>(properties: T, options?: ObjectOptions): TObject<T>;
288
- /** `Standard` Creates an intersect type. */
289
- Intersect<T extends TSchema[]>(items: [...T], options?: IntersectOptions): TIntersect<T>;
290
- /** `Standard` Creates a union type */
291
- Union<T extends TSchema[]>(items: [...T], options?: CustomOptions): TUnion<T>;
292
- /** `Standard` Creates an array type */
292
+ /** Creates a any type */
293
+ Any(options?: SchemaOptions): TAny;
294
+ /** Creates a array type */
293
295
  Array<T extends TSchema>(items: T, options?: ArrayOptions): TArray<T>;
294
- /** `Standard` Creates an enum type from a TypeScript enum */
295
- Enum<T extends TEnumType>(item: T, options?: CustomOptions): TEnum<TEnumKey<T[keyof T]>[]>;
296
- /** `Standard` Creates a literal type. Supports string, number and boolean values only */
297
- Literal<T extends TValue>(value: T, options?: CustomOptions): TLiteral<T>;
298
- /** `Standard` Creates a string type */
296
+ /** Creates a boolean type */
297
+ Boolean(options?: SchemaOptions): TBoolean;
298
+ /** Creates a constructor type */
299
+ Constructor<T extends TSchema[], U extends TSchema>(parameters: [...T], returns: U, options?: SchemaOptions): TConstructor<T, U>;
300
+ /** Creates a enum type */
301
+ Enum<T extends Record<string, string | number>>(item: T, options?: SchemaOptions): TEnum<T>;
302
+ /** Creates a function type */
303
+ Function<T extends readonly TSchema[], U extends TSchema>(parameters: [...T], returns: U, options?: SchemaOptions): TFunction<T, U>;
304
+ /** Creates a integer type */
305
+ Integer(options?: NumericOptions): TInteger;
306
+ /** Creates a intersect type. */
307
+ Intersect<T extends TObject[]>(objects: [...T], options?: ObjectOptions): TIntersect<T>;
308
+ /** Creates a keyof type */
309
+ KeyOf<T extends TObject>(object: T, options?: SchemaOptions): TUnion<TKeyOf<T>>;
310
+ /** Creates a literal type. */
311
+ Literal<T extends TLiteralValue>(value: T, options?: SchemaOptions): TLiteral<T>;
312
+ /** Creates a null type */
313
+ Null(options?: SchemaOptions): TNull;
314
+ /** Creates a number type */
315
+ Number(options?: NumericOptions): TNumber;
316
+ /** Creates an object type with the given properties */
317
+ Object<T extends TProperties>(properties: T, options?: ObjectOptions): TObject<T>;
318
+ /** Creates a new object whose properties are omitted from the given object */
319
+ Omit<T extends TObject, Properties extends Array<ObjectPropertyKeys<T>>>(schema: T, keys: [...Properties], options?: ObjectOptions): TOmit<T, Properties>;
320
+ /** Creates an object type whose properties are all optional */
321
+ Partial<T extends TObject>(schema: T, options?: ObjectOptions): TPartial<T>;
322
+ /** Creates a new object whose properties are picked from the given object */
323
+ Pick<T extends TObject, Properties extends Array<ObjectPropertyKeys<T>>>(schema: T, keys: [...Properties], options?: ObjectOptions): TPick<T, Properties>;
324
+ /** Creates a promise type. This type cannot be represented in schema. */
325
+ Promise<T extends TSchema>(item: T, options?: SchemaOptions): TPromise<T>;
326
+ /** Creates an object whose properties are derived from the given string literal union. */
327
+ Record<K extends TUnion<TLiteral[]>, T extends TSchema>(key: K, schema: T, options?: ObjectOptions): TObject<TRecordProperties<K, T>>;
328
+ /** Creates a record type */
329
+ Record<K extends TString | TNumber, T extends TSchema>(key: K, schema: T, options?: ObjectOptions): TRecord<K, T>;
330
+ /** Creates a recursive object type */
331
+ Recursive<T extends TSchema>(callback: (self: TSelf) => T, options?: SchemaOptions): TRecursive<T>;
332
+ /** Creates a reference schema */
333
+ Ref<T extends TSchema>(schema: T, options?: SchemaOptions): TRef<T>;
334
+ /** Creates a string type from a regular expression */
335
+ RegEx(regex: RegExp, options?: SchemaOptions): TString;
336
+ /** Creates an object type whose properties are all required */
337
+ Required<T extends TObject>(schema: T, options?: SchemaOptions): TRequired<T>;
338
+ /** Removes Kind and Modifier symbol property keys from this schema */
339
+ Strict<T extends TSchema>(schema: T): T;
340
+ /** Creates a string type */
299
341
  String<TCustomFormatOption extends string>(options?: StringOptions<StringFormatOption | TCustomFormatOption>): TString;
300
- /** `Standard` Creates a string type from a regular expression */
301
- RegEx(regex: RegExp, options?: CustomOptions): TString;
302
- /** `Standard` Creates a number type */
303
- Number(options?: NumberOptions): TNumber;
304
- /** `Standard` Creates an integer type */
305
- Integer(options?: NumberOptions): TInteger;
306
- /** `Standard` Creates a boolean type */
307
- Boolean(options?: CustomOptions): TBoolean;
308
- /** `Standard` Creates a null type */
309
- Null(options?: CustomOptions): TNull;
310
- /** `Standard` Creates an unknown type */
311
- Unknown(options?: CustomOptions): TUnknown;
312
- /** `Standard` Creates an any type */
313
- Any(options?: CustomOptions): TAny;
314
- /** `Standard` Creates a record type */
315
- Record<K extends TRecordKey, T extends TSchema>(key: K, value: T, options?: ObjectOptions): TRecord<K, T>;
316
- /** `Standard` Creates a keyof type from the given object */
317
- KeyOf<T extends TObject<TProperties> | TRef<TObject<TProperties>>>(object: T, options?: CustomOptions): TKeyOf<SelectablePropertyKeys<T>[]>;
318
- /** `Standard` Makes all properties in the given object type required */
319
- Required<T extends TObject<TProperties> | TRef<TObject<TProperties>>>(object: T, options?: ObjectOptions): TObject<StaticRequired<T['properties']>>;
320
- /** `Standard` Makes all properties in the given object type optional */
321
- Partial<T extends TObject<TProperties> | TRef<TObject<TProperties>>>(object: T, options?: ObjectOptions): TObject<StaticPartial<T['properties']>>;
322
- /** `Standard` Picks property keys from the given object type */
323
- Pick<T extends TObject<TProperties> | TRef<TObject<TProperties>>, K extends SelectablePropertyKeys<T>[]>(object: T, keys: [...K], options?: ObjectOptions): TObject<Pick<SelectableProperties<T>, K[number]>>;
324
- /** `Standard` Omits property keys from the given object type */
325
- Omit<T extends TObject<TProperties> | TRef<TObject<TProperties>>, K extends SelectablePropertyKeys<T>[]>(object: T, keys: [...K], options?: ObjectOptions): TObject<Omit<SelectableProperties<T>, K[number]>>;
326
- /** `Standard` Omits the `kind` and `modifier` properties from the underlying schema */
327
- Strict<T extends TSchema>(schema: T, options?: CustomOptions): T;
328
- /** `Extended` Creates a constructor type */
329
- Constructor<T extends TSchema[], U extends TSchema>(args: [...T], returns: U, options?: CustomOptions): TConstructor<T, U>;
330
- /** `Extended` Creates a function type */
331
- Function<T extends TSchema[], U extends TSchema>(args: [...T], returns: U, options?: CustomOptions): TFunction<T, U>;
332
- /** `Extended` Creates a promise type */
333
- Promise<T extends TSchema>(item: T, options?: CustomOptions): TPromise<T>;
334
- /** `Extended` Creates a undefined type */
335
- Undefined(options?: CustomOptions): TUndefined;
336
- /** `Extended` Creates a void type */
337
- Void(options?: CustomOptions): TVoid;
338
- /** `Standard` Creates a namespace for a set of related types */
339
- Namespace<T extends TDefinitions>($defs: T, options?: CustomOptions): TNamespace<T>;
340
- /** `Standard` References a type within a namespace. The referenced namespace must specify an `$id` */
341
- Ref<T extends TNamespace<TDefinitions>, K extends keyof T['$defs']>(namespace: T, key: K): TRef<T['$defs'][K]>;
342
- /** `Standard` References type. The referenced type must specify an `$id` */
343
- Ref<T extends TSchema>(schema: T): TRef<T>;
344
- /** `Experimental` Creates a recursive type */
345
- Rec<T extends TSchema>(callback: (self: TAny) => T, options?: CustomOptions): T;
346
- /** Conditionally stores and schema if it contains an $id and returns */
347
- protected Store<T extends TSchema | TNamespace<TDefinitions>, S = Omit<T, '$static'>>(schema: S): T;
348
- /** Conditionally dereferences a schema if RefKind. Otherwise return argument */
349
- protected Deref<T extends TSchema>(schema: T): any;
342
+ /** Creates a tuple type */
343
+ Tuple<T extends TSchema[]>(items: [...T], options?: SchemaOptions): TTuple<T>;
344
+ /** Creates a undefined type */
345
+ Undefined(options?: SchemaOptions): TUndefined;
346
+ /** Creates a union type */
347
+ Union<T extends TSchema[]>(items: [...T], options?: SchemaOptions): TUnion<T>;
348
+ /** Creates a Uint8Array type */
349
+ Uint8Array(options?: Uint8ArrayOptions): TUint8Array;
350
+ /** Creates an unknown type */
351
+ Unknown(options?: SchemaOptions): TUnknown;
352
+ /** Creates a user defined schema that infers as type T */
353
+ Unsafe<T>(options?: UnsafeOptions): TUnsafe<T>;
354
+ /** Creates a void type */
355
+ Void(options?: SchemaOptions): TVoid;
356
+ /** Use this function to return TSchema with static and params omitted */
357
+ protected Create<T>(schema: Omit<T, 'static' | 'params'>): T;
358
+ /** Clones the given value */
359
+ protected Clone(value: any): any;
350
360
  }
361
+ /** JSON Schema Type Builder with Static Type Resolution for TypeScript */
351
362
  export declare const Type: TypeBuilder;
363
+ export {};