@sinclair/typebox 0.31.22 → 0.31.24
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/package.json +1 -1
- package/readme.md +1 -1
- package/typebox.d.ts +21 -19
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -1608,10 +1608,10 @@ The following is a list of community packages that offer general tooling, extend
|
|
|
1608
1608
|
| [feathersjs](https://github.com/feathersjs/feathers) | The API and real-time application framework |
|
|
1609
1609
|
| [fetch-typebox](https://github.com/erfanium/fetch-typebox) | Drop-in replacement for fetch that brings easy integration with TypeBox |
|
|
1610
1610
|
| [h3-typebox](https://github.com/kevinmarrec/h3-typebox) | Schema validation utilities for h3 using TypeBox & Ajv |
|
|
1611
|
+
| [http-wizard](https://github.com/flodlc/http-wizard) | Type safe http client library for Fastify |
|
|
1611
1612
|
| [openapi-box](https://github.com/geut/openapi-box) | Generate TypeBox types from OpenApi IDL + Http client library |
|
|
1612
1613
|
| [schema2typebox](https://github.com/xddq/schema2typebox) | Creating TypeBox code from Json Schemas |
|
|
1613
1614
|
| [ts2typebox](https://github.com/xddq/ts2typebox) | Creating TypeBox code from Typescript types |
|
|
1614
|
-
| [typebox-client](https://github.com/flodlc/typebox-client) | Type safe http client library for Fastify |
|
|
1615
1615
|
| [typebox-form-parser](https://github.com/jtlapp/typebox-form-parser) | Parses form and query data based on TypeBox schemas |
|
|
1616
1616
|
| [typebox-validators](https://github.com/jtlapp/typebox-validators) | Advanced validators supporting discriminated and heterogeneous unions |
|
|
1617
1617
|
|
package/typebox.d.ts
CHANGED
|
@@ -104,9 +104,10 @@ export interface TArray<T extends TSchema = TSchema> extends TSchema, ArrayOptio
|
|
|
104
104
|
type: 'array';
|
|
105
105
|
items: T;
|
|
106
106
|
}
|
|
107
|
+
export type TAsyncIteratorResolve<T extends TSchema, P extends unknown[]> = Ensure<AsyncIterableIterator<Static<T, P>>>;
|
|
107
108
|
export interface TAsyncIterator<T extends TSchema = TSchema> extends TSchema {
|
|
108
109
|
[Kind]: 'AsyncIterator';
|
|
109
|
-
static:
|
|
110
|
+
static: TAsyncIteratorResolve<T, this['params']>;
|
|
110
111
|
type: 'AsyncIterator';
|
|
111
112
|
items: T;
|
|
112
113
|
}
|
|
@@ -122,7 +123,7 @@ export interface TBoolean extends TSchema {
|
|
|
122
123
|
static: boolean;
|
|
123
124
|
type: 'boolean';
|
|
124
125
|
}
|
|
125
|
-
export type TConstructorParameters<T extends TConstructor<TSchema[], TSchema>> = TTuple<T['parameters']
|
|
126
|
+
export type TConstructorParameters<T extends TConstructor<TSchema[], TSchema>> = Ensure<TTuple<T['parameters']>>;
|
|
126
127
|
export type TInstanceType<T extends TConstructor<TSchema[], TSchema>> = T['returns'];
|
|
127
128
|
export type TCompositeKeys<T extends TObject[]> = T extends [infer L, ...infer R] ? keyof Assert<L, TObject>['properties'] | TCompositeKeys<Assert<R, TObject[]>> : never;
|
|
128
129
|
export type TCompositeIndex<T extends TIntersect<TObject[]>, K extends string[]> = K extends [infer L, ...infer R] ? {
|
|
@@ -130,12 +131,12 @@ export type TCompositeIndex<T extends TIntersect<TObject[]>, K extends string[]>
|
|
|
130
131
|
} & TCompositeIndex<T, Assert<R, string[]>> : {};
|
|
131
132
|
export type TCompositeReduce<T extends TObject[]> = UnionToTuple<TCompositeKeys<T>> extends infer K ? Evaluate<TCompositeIndex<TIntersect<T>, Assert<K, string[]>>> : {};
|
|
132
133
|
export type TComposite<T extends TObject[]> = TIntersect<T> extends TIntersect ? TObject<TCompositeReduce<T>> : TObject<{}>;
|
|
133
|
-
export type
|
|
134
|
-
|
|
135
|
-
|
|
134
|
+
export type TConstructorReturnTypeResolve<T extends TSchema, P extends unknown[]> = Static<T, P>;
|
|
135
|
+
export type TConstructorParametersResolve<T extends TSchema[], P extends unknown[]> = T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? [Static<L, P>, ...TFunctionParametersResolve<R, P>] : [];
|
|
136
|
+
export type TConstructorResolve<T extends TSchema[], U extends TSchema, P extends unknown[]> = Ensure<new (...param: TConstructorParametersResolve<T, P>) => TConstructorReturnTypeResolve<U, P>>;
|
|
136
137
|
export interface TConstructor<T extends TSchema[] = TSchema[], U extends TSchema = TSchema> extends TSchema {
|
|
137
138
|
[Kind]: 'Constructor';
|
|
138
|
-
static:
|
|
139
|
+
static: TConstructorResolve<T, U, this['params']>;
|
|
139
140
|
type: 'Constructor';
|
|
140
141
|
parameters: T;
|
|
141
142
|
returns: U;
|
|
@@ -183,12 +184,12 @@ export type TExtractArray<T extends TSchema[], U extends TSchema> = AssertRest<U
|
|
|
183
184
|
[K in keyof T]: Static<AssertType<T[K]>> extends Static<U> ? T[K] : never;
|
|
184
185
|
}[number]>> extends infer R ? UnionType<AssertRest<R>> : never;
|
|
185
186
|
export type TExtract<T extends TSchema, U extends TSchema> = T extends TTemplateLiteral ? TExtractTemplateLiteral<T, U> : T extends TUnion<infer S> ? TExtractArray<S, U> : T extends U ? T : T;
|
|
186
|
-
export type
|
|
187
|
-
|
|
188
|
-
|
|
187
|
+
export type TFunctionReturnTypeResolve<T extends TSchema, P extends unknown[]> = Static<T, P>;
|
|
188
|
+
export type TFunctionParametersResolve<T extends TSchema[], P extends unknown[]> = T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? [Static<L, P>, ...TFunctionParametersResolve<R, P>] : [];
|
|
189
|
+
export type TFunctionResolve<T extends TSchema[], U extends TSchema, P extends unknown[]> = Ensure<(...param: TFunctionParametersResolve<T, P>) => TFunctionReturnTypeResolve<U, P>>;
|
|
189
190
|
export interface TFunction<T extends TSchema[] = TSchema[], U extends TSchema = TSchema> extends TSchema {
|
|
190
191
|
[Kind]: 'Function';
|
|
191
|
-
static:
|
|
192
|
+
static: TFunctionResolve<T, U, this['params']>;
|
|
192
193
|
type: 'Function';
|
|
193
194
|
parameters: T;
|
|
194
195
|
returns: U;
|
|
@@ -223,9 +224,10 @@ export interface TIntersect<T extends TSchema[] = TSchema[]> extends TSchema, In
|
|
|
223
224
|
type?: 'object';
|
|
224
225
|
allOf: [...T];
|
|
225
226
|
}
|
|
227
|
+
export type TIteratorResolve<T extends TSchema, P extends unknown[]> = Ensure<IterableIterator<Static<T, P>>>;
|
|
226
228
|
export interface TIterator<T extends TSchema = TSchema> extends TSchema {
|
|
227
229
|
[Kind]: 'Iterator';
|
|
228
|
-
static:
|
|
230
|
+
static: TIteratorResolve<T, this['params']>;
|
|
229
231
|
type: 'Iterator';
|
|
230
232
|
items: T;
|
|
231
233
|
}
|
|
@@ -315,7 +317,7 @@ export type TPartialRest<T extends TSchema[]> = AssertRest<{
|
|
|
315
317
|
[K in keyof T]: TPartial<AssertType<T[K]>>;
|
|
316
318
|
}>;
|
|
317
319
|
export type TPartialProperties<T extends TProperties> = Evaluate<AssertProperties<{
|
|
318
|
-
[K in keyof T]: TOptional<T[K]>;
|
|
320
|
+
[K in keyof T]: T[K] extends (TReadonlyOptional<infer S>) ? TReadonlyOptional<S> : T[K] extends (TReadonly<infer S>) ? TReadonlyOptional<S> : T[K] extends (TOptional<infer S>) ? TOptional<S> : TOptional<T[K]>;
|
|
319
321
|
}>>;
|
|
320
322
|
export type TPartial<T extends TSchema> = T extends TRecursive<infer S> ? TRecursive<TPartial<S>> : T extends TIntersect<infer S> ? TIntersect<TPartialRest<S>> : T extends TUnion<infer S> ? TUnion<TPartialRest<S>> : T extends TObject<infer S> ? TObject<TPartialProperties<S>> : T;
|
|
321
323
|
export type TPickProperties<T extends TProperties, K extends keyof any> = Pick<T, Assert<Extract<K, keyof T>, keyof T>> extends infer R ? ({
|
|
@@ -387,7 +389,7 @@ export type TRequiredRest<T extends TSchema[]> = AssertRest<{
|
|
|
387
389
|
[K in keyof T]: TRequired<AssertType<T[K]>>;
|
|
388
390
|
}>;
|
|
389
391
|
export type TRequiredProperties<T extends TProperties> = Evaluate<AssertProperties<{
|
|
390
|
-
[K in keyof T]: T[K] extends TOptional<infer S> ? S : T[K];
|
|
392
|
+
[K in keyof T]: T[K] extends (TReadonlyOptional<infer S>) ? TReadonly<S> : T[K] extends (TReadonly<infer S>) ? TReadonly<S> : T[K] extends (TOptional<infer S>) ? S : T[K];
|
|
391
393
|
}>>;
|
|
392
394
|
export type TRequired<T extends TSchema> = T extends TRecursive<infer S> ? TRecursive<TRequired<S>> : T extends TIntersect<infer S> ? TIntersect<TRequiredRest<S>> : T extends TUnion<infer S> ? TUnion<TRequiredRest<S>> : T extends TObject<infer S> ? TObject<TRequiredProperties<S>> : T;
|
|
393
395
|
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' | ({} & string);
|
|
@@ -443,7 +445,7 @@ export type DecodeProperties<T extends TProperties> = {
|
|
|
443
445
|
[K in keyof T]: DecodeType<T[K]>;
|
|
444
446
|
};
|
|
445
447
|
export type DecodeRest<T extends TSchema[]> = T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? [DecodeType<L>, ...DecodeRest<R>] : [];
|
|
446
|
-
export type DecodeType<T extends TSchema> = (T extends TOptional<infer S extends TSchema> ? TOptional<DecodeType<S>> : T extends TReadonly<infer S extends TSchema> ? TReadonly<DecodeType<S>> : T extends TTransform<infer _, infer R> ? TUnsafe<R> : T extends TArray<infer S extends TSchema> ? TArray<DecodeType<S>> : T extends TAsyncIterator<infer S extends TSchema> ? TAsyncIterator<DecodeType<S>> : T extends TConstructor<infer P extends TSchema[], infer R extends TSchema> ? TConstructor<P
|
|
448
|
+
export type DecodeType<T extends TSchema> = (T extends TOptional<infer S extends TSchema> ? TOptional<DecodeType<S>> : T extends TReadonly<infer S extends TSchema> ? TReadonly<DecodeType<S>> : T extends TTransform<infer _, infer R> ? TUnsafe<R> : T extends TArray<infer S extends TSchema> ? TArray<DecodeType<S>> : T extends TAsyncIterator<infer S extends TSchema> ? TAsyncIterator<DecodeType<S>> : T extends TConstructor<infer P extends TSchema[], infer R extends TSchema> ? TConstructor<DecodeRest<P>, DecodeType<R>> : T extends TEnum<infer S> ? TEnum<S> : T extends TFunction<infer P extends TSchema[], infer R extends TSchema> ? TFunction<DecodeRest<P>, DecodeType<R>> : T extends TIntersect<infer S extends TSchema[]> ? TIntersect<DecodeRest<S>> : T extends TIterator<infer S extends TSchema> ? TIterator<DecodeType<S>> : T extends TNot<infer S extends TSchema> ? TNot<DecodeType<S>> : T extends TObject<infer S> ? TObject<Evaluate<DecodeProperties<S>>> : T extends TPromise<infer S extends TSchema> ? TPromise<DecodeType<S>> : T extends TRecord<infer K, infer S> ? TRecord<K, DecodeType<S>> : T extends TRecursive<infer S extends TSchema> ? TRecursive<DecodeType<S>> : T extends TRef<infer S extends TSchema> ? TRef<DecodeType<S>> : T extends TTuple<infer S extends TSchema[]> ? TTuple<DecodeRest<S>> : T extends TUnion<infer S extends TSchema[]> ? TUnion<DecodeRest<S>> : T);
|
|
447
449
|
export type TransformFunction<T = any, U = any> = (value: T) => U;
|
|
448
450
|
export interface TransformOptions<I extends TSchema = TSchema, O extends unknown = unknown> {
|
|
449
451
|
Decode: TransformFunction<StaticDecode<I>, O>;
|
|
@@ -509,11 +511,11 @@ export interface TVoid extends TSchema {
|
|
|
509
511
|
static: void;
|
|
510
512
|
type: 'void';
|
|
511
513
|
}
|
|
512
|
-
/** Creates
|
|
514
|
+
/** Creates an decoded static type from a TypeBox type */
|
|
513
515
|
export type StaticDecode<T extends TSchema, P extends unknown[] = []> = Static<DecodeType<T>, P>;
|
|
514
|
-
/** Creates
|
|
516
|
+
/** Creates an encoded static type from a TypeBox type */
|
|
515
517
|
export type StaticEncode<T extends TSchema, P extends unknown[] = []> = Static<T, P>;
|
|
516
|
-
/** Creates
|
|
518
|
+
/** Creates a static type from a TypeBox type */
|
|
517
519
|
export type Static<T extends TSchema, P extends unknown[] = []> = (T & {
|
|
518
520
|
params: P;
|
|
519
521
|
})['static'];
|
|
@@ -918,7 +920,7 @@ export declare class JavaScriptTypeBuilder extends JsonTypeBuilder {
|
|
|
918
920
|
/** `[JavaScript]` Creates a BigInt type */
|
|
919
921
|
BigInt(options?: NumericOptions<bigint>): TBigInt;
|
|
920
922
|
/** `[JavaScript]` Extracts the ConstructorParameters from the given Constructor type */
|
|
921
|
-
ConstructorParameters<T extends TConstructor<
|
|
923
|
+
ConstructorParameters<T extends TConstructor<TSchema[], TSchema>>(schema: T, options?: SchemaOptions): TConstructorParameters<T>;
|
|
922
924
|
/** `[JavaScript]` Creates a Constructor type */
|
|
923
925
|
Constructor<T extends TSchema[], U extends TSchema>(parameters: [...T], returns: U, options?: SchemaOptions): TConstructor<T, U>;
|
|
924
926
|
/** `[JavaScript]` Creates a Date type */
|
|
@@ -930,7 +932,7 @@ export declare class JavaScriptTypeBuilder extends JsonTypeBuilder {
|
|
|
930
932
|
/** `[JavaScript]` Creates an Iterator type */
|
|
931
933
|
Iterator<T extends TSchema>(items: T, options?: SchemaOptions): TIterator<T>;
|
|
932
934
|
/** `[JavaScript]` Extracts the Parameters from the given Function type */
|
|
933
|
-
Parameters<T extends TFunction<
|
|
935
|
+
Parameters<T extends TFunction<TSchema[], TSchema>>(schema: T, options?: SchemaOptions): TParameters<T>;
|
|
934
936
|
/** `[JavaScript]` Creates a Promise type */
|
|
935
937
|
Promise<T extends TSchema>(item: T, options?: SchemaOptions): TPromise<T>;
|
|
936
938
|
/** `[JavaScript]` Creates a String type from a Regular Expression pattern */
|