@sinclair/typebox 0.31.4 → 0.31.5
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 +3 -3
- package/typebox.js +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
|
@@ -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> = {
|
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 = {}) {
|