@sinclair/typebox 0.31.4 → 0.31.6
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 +19 -19
- package/typebox.d.ts +6 -7
- package/typebox.js +4 -4
- package/value/value.d.ts +4 -4
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -277,7 +277,7 @@ The following table lists the supported Json types. These types are fully compat
|
|
|
277
277
|
│ const T = Type.Tuple([ │ type T = [number, number] │ const T = { │
|
|
278
278
|
│ Type.Number(), │ │ type: 'array', │
|
|
279
279
|
│ Type.Number() │ │ items: [{ │
|
|
280
|
-
│ ]) │ │
|
|
280
|
+
│ ]) │ │ type: 'number' │
|
|
281
281
|
│ │ │ }, { │
|
|
282
282
|
│ │ │ type: 'number' │
|
|
283
283
|
│ │ │ }], │
|
|
@@ -312,9 +312,9 @@ The following table lists the supported Json types. These types are fully compat
|
|
|
312
312
|
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
|
|
313
313
|
│ const T = Type.Union([ │ type T = string | number │ const T = { │
|
|
314
314
|
│ Type.String(), │ │ anyOf: [{ │
|
|
315
|
-
│ Type.Number() │ │
|
|
315
|
+
│ Type.Number() │ │ type: 'string' │
|
|
316
316
|
│ ]) │ │ }, { │
|
|
317
|
-
│ │ │
|
|
317
|
+
│ │ │ type: 'number' │
|
|
318
318
|
│ │ │ }] │
|
|
319
319
|
│ │ │ } │
|
|
320
320
|
│ │ │ │
|
|
@@ -472,10 +472,10 @@ The following table lists the supported Json types. These types are fully compat
|
|
|
472
472
|
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
|
|
473
473
|
│ const A = Type.Tuple([ │ type A = [0, 1] │ const T = { │
|
|
474
474
|
│ Type.Literal(0), │ type B = [2, 3] │ type: 'array', │
|
|
475
|
-
│ Type.Literal(1) │ type T = [
|
|
476
|
-
│ ]) │
|
|
477
|
-
│ const B = Type.Tuple([ │
|
|
478
|
-
| Type.Literal(2), │
|
|
475
|
+
│ Type.Literal(1) │ type T = [ │ items: [ │
|
|
476
|
+
│ ]) │ ...A, │ { const: 0 }, │
|
|
477
|
+
│ const B = Type.Tuple([ │ ...B │ { const: 1 }, │
|
|
478
|
+
| Type.Literal(2), │ ] │ { const: 2 }, │
|
|
479
479
|
| Type.Literal(3) │ │ { const: 3 } │
|
|
480
480
|
│ ]) │ │ ], │
|
|
481
481
|
│ const T = Type.Tuple([ │ │ additionalItems: false, │
|
|
@@ -485,26 +485,26 @@ The following table lists the supported Json types. These types are fully compat
|
|
|
485
485
|
│ │ │ │
|
|
486
486
|
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
|
|
487
487
|
│ const T = Type.Uncapitalize( │ type T = Uncapitalize< │ const T = { │
|
|
488
|
-
│ Type.Literal('Hello') │ 'Hello' │
|
|
489
|
-
│ ) │ > │
|
|
488
|
+
│ Type.Literal('Hello') │ 'Hello' │ type: 'string', │
|
|
489
|
+
│ ) │ > │ const: 'hello' │
|
|
490
490
|
│ │ │ } │
|
|
491
491
|
│ │ │ │
|
|
492
492
|
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
|
|
493
493
|
│ const T = Type.Capitalize( │ type T = Capitalize< │ const T = { │
|
|
494
|
-
│ Type.Literal('hello') │ 'hello' │
|
|
495
|
-
│ ) │ > │
|
|
494
|
+
│ Type.Literal('hello') │ 'hello' │ type: 'string', │
|
|
495
|
+
│ ) │ > │ const: 'Hello' │
|
|
496
496
|
│ │ │ } │
|
|
497
497
|
│ │ │ │
|
|
498
498
|
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
|
|
499
499
|
│ const T = Type.Uppercase( │ type T = Uppercase< │ const T = { │
|
|
500
|
-
│ Type.Literal('hello') │ 'hello' │
|
|
501
|
-
│ ) │ > │
|
|
500
|
+
│ Type.Literal('hello') │ 'hello' │ type: 'string', │
|
|
501
|
+
│ ) │ > │ const: 'HELLO' │
|
|
502
502
|
│ │ │ } │
|
|
503
503
|
│ │ │ │
|
|
504
504
|
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
|
|
505
505
|
│ const T = Type.Lowercase( │ type T = Lowercase< │ const T = { │
|
|
506
|
-
│ Type.Literal('HELLO') │ 'HELLO' │
|
|
507
|
-
│ ) │ > │
|
|
506
|
+
│ Type.Literal('HELLO') │ 'HELLO' │ type: 'string', │
|
|
507
|
+
│ ) │ > │ const: 'hello' │
|
|
508
508
|
│ │ │ } │
|
|
509
509
|
│ │ │ │
|
|
510
510
|
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
|
|
@@ -533,26 +533,26 @@ TypeBox provides an extended type set that can be used to create schematics for
|
|
|
533
533
|
│ │ │ │
|
|
534
534
|
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
|
|
535
535
|
│ const T = Type.Constructor([ │ type T = new ( │ const T = { │
|
|
536
|
-
│ Type.String(), │ arg0: string, │ type: '
|
|
536
|
+
│ Type.String(), │ arg0: string, │ type: 'Constructor', │
|
|
537
537
|
│ Type.Number() │ arg0: number │ parameters: [{ │
|
|
538
538
|
│ ], Type.Boolean()) │ ) => boolean │ type: 'string' │
|
|
539
539
|
│ │ │ }, { │
|
|
540
540
|
│ │ │ type: 'number' │
|
|
541
541
|
│ │ │ }], │
|
|
542
|
-
│ │ │
|
|
542
|
+
│ │ │ returns: { │
|
|
543
543
|
│ │ │ type: 'boolean' │
|
|
544
544
|
│ │ │ } │
|
|
545
545
|
│ │ │ } │
|
|
546
546
|
│ │ │ │
|
|
547
547
|
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
|
|
548
548
|
│ const T = Type.Function([ │ type T = ( │ const T = { │
|
|
549
|
-
| Type.String(), │ arg0: string, │ type: '
|
|
549
|
+
| Type.String(), │ arg0: string, │ type: 'Function', │
|
|
550
550
|
│ Type.Number() │ arg1: number │ parameters: [{ │
|
|
551
551
|
│ ], Type.Boolean()) │ ) => boolean │ type: 'string' │
|
|
552
552
|
│ │ │ }, { │
|
|
553
553
|
│ │ │ type: 'number' │
|
|
554
554
|
│ │ │ }], │
|
|
555
|
-
│ │ │
|
|
555
|
+
│ │ │ returns: { │
|
|
556
556
|
│ │ │ type: 'boolean' │
|
|
557
557
|
│ │ │ } │
|
|
558
558
|
│ │ │ } │
|
package/typebox.d.ts
CHANGED
|
@@ -27,7 +27,7 @@ export type Ensure<T> = T extends infer U ? U : never;
|
|
|
27
27
|
export type AssertProperties<T> = T extends TProperties ? T : TProperties;
|
|
28
28
|
export type AssertRest<T, E extends TSchema[] = TSchema[]> = T extends E ? T : [];
|
|
29
29
|
export type AssertType<T, E extends TSchema = TSchema> = T extends E ? T : TNever;
|
|
30
|
-
export type
|
|
30
|
+
export type TReadonlyOptional<T extends TSchema> = TOptional<T> & TReadonly<T>;
|
|
31
31
|
export type TReadonly<T extends TSchema> = T & {
|
|
32
32
|
[Readonly]: 'Readonly';
|
|
33
33
|
};
|
|
@@ -136,7 +136,7 @@ export type TConstructorParameterArray<T extends readonly TSchema[], P extends u
|
|
|
136
136
|
export interface TConstructor<T extends TSchema[] = TSchema[], U extends TSchema = TSchema> extends TSchema {
|
|
137
137
|
[Kind]: 'Constructor';
|
|
138
138
|
static: new (...param: TConstructorParameterArray<T, this['params']>) => Static<U, this['params']>;
|
|
139
|
-
type: '
|
|
139
|
+
type: 'Constructor';
|
|
140
140
|
parameters: T;
|
|
141
141
|
returns: U;
|
|
142
142
|
}
|
|
@@ -189,7 +189,7 @@ export type TFunctionParameters<T extends TSchema[], P extends unknown[]> = [...
|
|
|
189
189
|
export interface TFunction<T extends TSchema[] = TSchema[], U extends TSchema = TSchema> extends TSchema {
|
|
190
190
|
[Kind]: 'Function';
|
|
191
191
|
static: (...param: TFunctionParameters<T, this['params']>) => Static<U, this['params']>;
|
|
192
|
-
type: '
|
|
192
|
+
type: 'Function';
|
|
193
193
|
parameters: T;
|
|
194
194
|
returns: U;
|
|
195
195
|
}
|
|
@@ -328,7 +328,7 @@ export type TPick<T extends TSchema = TSchema, K extends keyof any = keyof any>
|
|
|
328
328
|
export interface TPromise<T extends TSchema = TSchema> extends TSchema {
|
|
329
329
|
[Kind]: 'Promise';
|
|
330
330
|
static: Promise<Static<T, this['params']>>;
|
|
331
|
-
type: '
|
|
331
|
+
type: 'Promise';
|
|
332
332
|
item: TSchema;
|
|
333
333
|
}
|
|
334
334
|
export type TRecordFromUnionLiteralString<K extends TLiteralString, T extends TSchema> = {
|
|
@@ -436,12 +436,11 @@ export interface TTemplateLiteral<T extends TTemplateLiteralKind[] = TTemplateLi
|
|
|
436
436
|
type: 'string';
|
|
437
437
|
pattern: string;
|
|
438
438
|
}
|
|
439
|
-
export type DecodeModifier<D extends TSchema, T extends TSchema> = T extends TReadonly<T> & TOptional<T> ? TReadonly<TOptional<D>> : T extends TReadonly<T> ? TReadonly<D> : T extends TOptional<T> ? TOptional<D> : D;
|
|
440
439
|
export type DecodeProperties<T extends TProperties> = {
|
|
441
440
|
[K in keyof T]: DecodeType<T[K]>;
|
|
442
441
|
};
|
|
443
|
-
export type DecodeRest<T extends TSchema[]> = T extends [infer L, ...infer R] ? [DecodeType<
|
|
444
|
-
export type DecodeType<T extends TSchema> = T extends TTransform<infer _, infer R> ?
|
|
442
|
+
export type DecodeRest<T extends TSchema[]> = T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? [DecodeType<L>, ...DecodeRest<R>] : [];
|
|
443
|
+
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> ? Array<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, DecodeType<R>> : T extends TFunction<infer P extends TSchema[], infer R extends TSchema> ? TFunction<P, DecodeType<R>> : T extends TIntersect<infer S extends TSchema[]> ? TIntersect<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<S> : T extends TUnion<infer S extends TSchema[]> ? TUnion<S> : T);
|
|
445
444
|
export type TransformFunction<T = any, U = any> = (value: T) => U;
|
|
446
445
|
export interface TransformOptions<I extends TSchema = TSchema, O extends unknown = unknown> {
|
|
447
446
|
Decode: TransformFunction<StaticDecode<I>, O>;
|
package/typebox.js
CHANGED
|
@@ -279,7 +279,7 @@ var TypeGuard;
|
|
|
279
279
|
function TConstructor(schema) {
|
|
280
280
|
// prettier-ignore
|
|
281
281
|
return (TKindOf(schema, 'Constructor') &&
|
|
282
|
-
schema.type === '
|
|
282
|
+
schema.type === 'Constructor' &&
|
|
283
283
|
IsOptionalString(schema.$id) &&
|
|
284
284
|
ValueGuard.IsArray(schema.parameters) &&
|
|
285
285
|
schema.parameters.every(schema => TSchema(schema)) &&
|
|
@@ -302,7 +302,7 @@ var TypeGuard;
|
|
|
302
302
|
function TFunction(schema) {
|
|
303
303
|
// prettier-ignore
|
|
304
304
|
return (TKindOf(schema, 'Function') &&
|
|
305
|
-
schema.type === '
|
|
305
|
+
schema.type === 'Function' &&
|
|
306
306
|
IsOptionalString(schema.$id) &&
|
|
307
307
|
ValueGuard.IsArray(schema.parameters) &&
|
|
308
308
|
schema.parameters.every(schema => TSchema(schema)) &&
|
|
@@ -2271,7 +2271,7 @@ class JavaScriptTypeBuilder extends JsonTypeBuilder {
|
|
|
2271
2271
|
/** `[JavaScript]` Creates a Constructor type */
|
|
2272
2272
|
Constructor(parameters, returns, options) {
|
|
2273
2273
|
const [clonedParameters, clonedReturns] = [TypeClone.Rest(parameters), TypeClone.Type(returns)];
|
|
2274
|
-
return this.Create({ ...options, [exports.Kind]: 'Constructor', type: '
|
|
2274
|
+
return this.Create({ ...options, [exports.Kind]: 'Constructor', type: 'Constructor', parameters: clonedParameters, returns: clonedReturns });
|
|
2275
2275
|
}
|
|
2276
2276
|
/** `[JavaScript]` Creates a Date type */
|
|
2277
2277
|
Date(options = {}) {
|
|
@@ -2280,7 +2280,7 @@ class JavaScriptTypeBuilder extends JsonTypeBuilder {
|
|
|
2280
2280
|
/** `[JavaScript]` Creates a Function type */
|
|
2281
2281
|
Function(parameters, returns, options) {
|
|
2282
2282
|
const [clonedParameters, clonedReturns] = [TypeClone.Rest(parameters), TypeClone.Type(returns)];
|
|
2283
|
-
return this.Create({ ...options, [exports.Kind]: 'Function', type: '
|
|
2283
|
+
return this.Create({ ...options, [exports.Kind]: 'Function', type: 'Function', parameters: clonedParameters, returns: clonedReturns });
|
|
2284
2284
|
}
|
|
2285
2285
|
/** `[JavaScript]` Extracts the InstanceType from the given Constructor type */
|
|
2286
2286
|
InstanceType(schema, options = {}) {
|
package/value/value.d.ts
CHANGED
|
@@ -23,13 +23,13 @@ export declare namespace Value {
|
|
|
23
23
|
/** Returns a structural clone of the given value */
|
|
24
24
|
function Clone<T>(value: T): T;
|
|
25
25
|
/** Decodes a value or throws if error */
|
|
26
|
-
function Decode<T extends Types.TSchema
|
|
26
|
+
function Decode<T extends Types.TSchema, D = Types.StaticDecode<T>>(schema: T, references: Types.TSchema[], value: unknown): D;
|
|
27
27
|
/** Decodes a value or throws if error */
|
|
28
|
-
function Decode<T extends Types.TSchema
|
|
28
|
+
function Decode<T extends Types.TSchema, D = Types.StaticDecode<T>>(schema: T, value: unknown): D;
|
|
29
29
|
/** Encodes a value or throws if error */
|
|
30
|
-
function Encode<T extends Types.TSchema
|
|
30
|
+
function Encode<T extends Types.TSchema, E = Types.StaticEncode<T>>(schema: T, references: Types.TSchema[], value: unknown): E;
|
|
31
31
|
/** Encodes a value or throws if error */
|
|
32
|
-
function Encode<T extends Types.TSchema
|
|
32
|
+
function Encode<T extends Types.TSchema, E = Types.StaticEncode<T>>(schema: T, value: unknown): E;
|
|
33
33
|
/** Returns an iterator for each error in this value. */
|
|
34
34
|
function Errors<T extends Types.TSchema>(schema: T, references: Types.TSchema[], value: unknown): ValueErrors.ValueErrorIterator;
|
|
35
35
|
/** Returns an iterator for each error in this value. */
|