@sinclair/typebox 0.31.0-dev-2 → 0.31.0
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 +424 -433
- package/typebox.d.ts +66 -64
- package/typebox.js +43 -43
package/typebox.d.ts
CHANGED
|
@@ -331,22 +331,32 @@ export interface TPromise<T extends TSchema = TSchema> extends TSchema {
|
|
|
331
331
|
type: 'promise';
|
|
332
332
|
item: TSchema;
|
|
333
333
|
}
|
|
334
|
-
export type
|
|
335
|
-
[_ in
|
|
334
|
+
export type TRecordFromUnionLiteralString<K extends TLiteralString, T extends TSchema> = {
|
|
335
|
+
[_ in K['const']]: T;
|
|
336
|
+
};
|
|
337
|
+
export type TRecordFromUnionLiteralNumber<K extends TLiteralNumber, T extends TSchema> = {
|
|
338
|
+
[_ in K['const']]: T;
|
|
339
|
+
};
|
|
340
|
+
export type TRecordFromUnionRest<K extends TSchema[], T extends TSchema> = K extends [infer L, ...infer R] ? (L extends TUnion<infer S> ? TRecordFromUnionRest<S, T> & TRecordFromUnionRest<AssertRest<R>, T> : L extends TLiteralString ? TRecordFromUnionLiteralString<L, T> & TRecordFromUnionRest<AssertRest<R>, T> : L extends TLiteralNumber ? TRecordFromUnionLiteralNumber<L, T> & TRecordFromUnionRest<AssertRest<R>, T> : {}) : {};
|
|
341
|
+
export type TRecordFromUnion<K extends TSchema[], T extends TSchema> = Ensure<TObject<AssertProperties<Evaluate<TRecordFromUnionRest<K, T>>>>>;
|
|
342
|
+
export type TRecordFromTemplateLiteralKeyInfinite<T extends TSchema> = Ensure<TRecord<TString, T>>;
|
|
343
|
+
export type TRecordFromTemplateLiteralKeyFinite<K extends TTemplateLiteral, T extends TSchema, I = Static<K>> = Ensure<TObject<Evaluate<{
|
|
344
|
+
[_ in Assert<I, string>]: T;
|
|
336
345
|
}>>>;
|
|
337
|
-
export type
|
|
338
|
-
export type
|
|
339
|
-
[
|
|
340
|
-
}>> : never;
|
|
341
|
-
export type RecordLiteralType<K extends TLiteral<string | number>, T extends TSchema> = Ensure<TObject<{
|
|
342
|
-
[K2 in K['const']]: T;
|
|
346
|
+
export type TRecordFromTemplateLiteralKey<K extends TTemplateLiteral, T extends TSchema> = IsTemplateLiteralFinite<K> extends false ? TRecordFromTemplateLiteralKeyInfinite<T> : TRecordFromTemplateLiteralKeyFinite<K, T>;
|
|
347
|
+
export type TRecordFromLiteralStringKey<K extends TLiteralString, T extends TSchema> = Ensure<TObject<{
|
|
348
|
+
[_ in K['const']]: T;
|
|
343
349
|
}>>;
|
|
344
|
-
export type
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
export
|
|
350
|
+
export type TRecordFromLiteralNumberKey<K extends TLiteralNumber, T extends TSchema> = Ensure<TObject<{
|
|
351
|
+
[_ in K['const']]: T;
|
|
352
|
+
}>>;
|
|
353
|
+
export type TRecordFromStringKey<K extends TString, T extends TSchema> = Ensure<TRecord<K, T>>;
|
|
354
|
+
export type TRecordFromNumberKey<K extends TNumber, T extends TSchema> = Ensure<TRecord<K, T>>;
|
|
355
|
+
export type TRecordFromIntegerKey<K extends TInteger, T extends TSchema> = Ensure<TRecord<K, T>>;
|
|
356
|
+
export type TRecordResolve<K extends TSchema, T extends TSchema> = K extends TUnion<infer S> ? TRecordFromUnion<S, T> : K extends TTemplateLiteral ? TRecordFromTemplateLiteralKey<K, T> : K extends TLiteralString ? TRecordFromLiteralStringKey<K, T> : K extends TLiteralNumber ? TRecordFromLiteralNumberKey<K, T> : K extends TString ? TRecordFromStringKey<K, T> : K extends TNumber ? TRecordFromNumberKey<K, T> : K extends TInteger ? TRecordFromIntegerKey<K, T> : TNever;
|
|
357
|
+
export interface TRecord<K extends TSchema = TSchema, T extends TSchema = TSchema> extends TSchema {
|
|
348
358
|
[Kind]: 'Record';
|
|
349
|
-
static: Record<Static<K>, Static<T, this['params']>>;
|
|
359
|
+
static: Record<Assert<Static<K>, string | number>, Static<T, this['params']>>;
|
|
350
360
|
type: 'object';
|
|
351
361
|
patternProperties: {
|
|
352
362
|
[pattern: string]: T;
|
|
@@ -562,97 +572,97 @@ export declare class TypeGuardUnknownTypeError extends TypeBoxError {
|
|
|
562
572
|
}
|
|
563
573
|
/** Provides functions to test if JavaScript values are TypeBox types */
|
|
564
574
|
export declare namespace TypeGuard {
|
|
565
|
-
/** Returns true if the given
|
|
575
|
+
/** Returns true if the given value is TAny */
|
|
566
576
|
function TAny(schema: unknown): schema is TAny;
|
|
567
|
-
/** Returns true if the given
|
|
577
|
+
/** Returns true if the given value is TArray */
|
|
568
578
|
function TArray(schema: unknown): schema is TArray;
|
|
569
|
-
/** Returns true if the given
|
|
579
|
+
/** Returns true if the given value is TAsyncIterator */
|
|
570
580
|
function TAsyncIterator(schema: unknown): schema is TAsyncIterator;
|
|
571
|
-
/** Returns true if the given
|
|
581
|
+
/** Returns true if the given value is TBigInt */
|
|
572
582
|
function TBigInt(schema: unknown): schema is TBigInt;
|
|
573
|
-
/** Returns true if the given
|
|
583
|
+
/** Returns true if the given value is TBoolean */
|
|
574
584
|
function TBoolean(schema: unknown): schema is TBoolean;
|
|
575
|
-
/** Returns true if the given
|
|
585
|
+
/** Returns true if the given value is TConstructor */
|
|
576
586
|
function TConstructor(schema: unknown): schema is TConstructor;
|
|
577
|
-
/** Returns true if the given
|
|
587
|
+
/** Returns true if the given value is TDate */
|
|
578
588
|
function TDate(schema: unknown): schema is TDate;
|
|
579
|
-
/** Returns true if the given
|
|
589
|
+
/** Returns true if the given value is TFunction */
|
|
580
590
|
function TFunction(schema: unknown): schema is TFunction;
|
|
581
|
-
/** Returns true if the given
|
|
591
|
+
/** Returns true if the given value is TInteger */
|
|
582
592
|
function TInteger(schema: unknown): schema is TInteger;
|
|
583
|
-
/** Returns true if the given
|
|
593
|
+
/** Returns true if the given value is TIntersect */
|
|
584
594
|
function TIntersect(schema: unknown): schema is TIntersect;
|
|
585
|
-
/** Returns true if the given
|
|
595
|
+
/** Returns true if the given value is TIterator */
|
|
586
596
|
function TIterator(schema: unknown): schema is TIterator;
|
|
587
|
-
/** Returns true if the given
|
|
597
|
+
/** Returns true if the given value is a TKind with the given name. */
|
|
588
598
|
function TKindOf<T extends string>(schema: unknown, kind: T): schema is Record<PropertyKey, unknown> & {
|
|
589
599
|
[Kind]: T;
|
|
590
600
|
};
|
|
591
|
-
/** Returns true if the given
|
|
601
|
+
/** Returns true if the given value is TKind */
|
|
592
602
|
function TKind(schema: unknown): schema is Record<PropertyKey, unknown> & {
|
|
593
603
|
[Kind]: string;
|
|
594
604
|
};
|
|
595
|
-
/** Returns true if the given
|
|
605
|
+
/** Returns true if the given value is TLiteral<string> */
|
|
596
606
|
function TLiteralString(schema: unknown): schema is TLiteral<string>;
|
|
597
|
-
/** Returns true if the given
|
|
607
|
+
/** Returns true if the given value is TLiteral<number> */
|
|
598
608
|
function TLiteralNumber(schema: unknown): schema is TLiteral<number>;
|
|
599
|
-
/** Returns true if the given
|
|
609
|
+
/** Returns true if the given value is TLiteral<boolean> */
|
|
600
610
|
function TLiteralBoolean(schema: unknown): schema is TLiteral<boolean>;
|
|
601
|
-
/** Returns true if the given
|
|
611
|
+
/** Returns true if the given value is TLiteral */
|
|
602
612
|
function TLiteral(schema: unknown): schema is TLiteral;
|
|
603
|
-
/** Returns true if the given
|
|
613
|
+
/** Returns true if the given value is TNever */
|
|
604
614
|
function TNever(schema: unknown): schema is TNever;
|
|
605
|
-
/** Returns true if the given
|
|
615
|
+
/** Returns true if the given value is TNot */
|
|
606
616
|
function TNot(schema: unknown): schema is TNot;
|
|
607
|
-
/** Returns true if the given
|
|
617
|
+
/** Returns true if the given value is TNull */
|
|
608
618
|
function TNull(schema: unknown): schema is TNull;
|
|
609
|
-
/** Returns true if the given
|
|
619
|
+
/** Returns true if the given value is TNumber */
|
|
610
620
|
function TNumber(schema: unknown): schema is TNumber;
|
|
611
|
-
/** Returns true if the given
|
|
621
|
+
/** Returns true if the given value is TObject */
|
|
612
622
|
function TObject(schema: unknown): schema is TObject;
|
|
613
|
-
/** Returns true if the given
|
|
623
|
+
/** Returns true if the given value is TPromise */
|
|
614
624
|
function TPromise(schema: unknown): schema is TPromise;
|
|
615
|
-
/** Returns true if the given
|
|
625
|
+
/** Returns true if the given value is TRecord */
|
|
616
626
|
function TRecord(schema: unknown): schema is TRecord;
|
|
617
|
-
/** Returns true if this
|
|
627
|
+
/** Returns true if this value is TRecursive */
|
|
618
628
|
function TRecursive(schema: unknown): schema is {
|
|
619
629
|
[Hint]: 'Recursive';
|
|
620
630
|
};
|
|
621
|
-
/** Returns true if the given
|
|
631
|
+
/** Returns true if the given value is TRef */
|
|
622
632
|
function TRef(schema: unknown): schema is TRef;
|
|
623
|
-
/** Returns true if the given
|
|
633
|
+
/** Returns true if the given value is TString */
|
|
624
634
|
function TString(schema: unknown): schema is TString;
|
|
625
|
-
/** Returns true if the given
|
|
635
|
+
/** Returns true if the given value is TSymbol */
|
|
626
636
|
function TSymbol(schema: unknown): schema is TSymbol;
|
|
627
|
-
/** Returns true if the given
|
|
637
|
+
/** Returns true if the given value is TTemplateLiteral */
|
|
628
638
|
function TTemplateLiteral(schema: unknown): schema is TTemplateLiteral;
|
|
629
|
-
/** Returns true if the given
|
|
639
|
+
/** Returns true if the given value is TThis */
|
|
630
640
|
function TThis(schema: unknown): schema is TThis;
|
|
631
|
-
/** Returns true of this
|
|
641
|
+
/** Returns true of this value is TTransform */
|
|
632
642
|
function TTransform(schema: unknown): schema is {
|
|
633
643
|
[Transform]: TransformOptions;
|
|
634
644
|
};
|
|
635
|
-
/** Returns true if the given
|
|
645
|
+
/** Returns true if the given value is TTuple */
|
|
636
646
|
function TTuple(schema: unknown): schema is TTuple;
|
|
637
|
-
/** Returns true if the given
|
|
647
|
+
/** Returns true if the given value is TUndefined */
|
|
638
648
|
function TUndefined(schema: unknown): schema is TUndefined;
|
|
639
|
-
/** Returns true if the given
|
|
649
|
+
/** Returns true if the given value is TUnion<Literal<string | number>[]> */
|
|
640
650
|
function TUnionLiteral(schema: unknown): schema is TUnion<TLiteral[]>;
|
|
641
|
-
/** Returns true if the given
|
|
651
|
+
/** Returns true if the given value is TUnion */
|
|
642
652
|
function TUnion(schema: unknown): schema is TUnion;
|
|
643
|
-
/** Returns true if the given
|
|
653
|
+
/** Returns true if the given value is TUint8Array */
|
|
644
654
|
function TUint8Array(schema: unknown): schema is TUint8Array;
|
|
645
|
-
/** Returns true if the given
|
|
655
|
+
/** Returns true if the given value is TUnknown */
|
|
646
656
|
function TUnknown(schema: unknown): schema is TUnknown;
|
|
647
|
-
/** Returns true if the given
|
|
657
|
+
/** Returns true if the given value is a raw TUnsafe */
|
|
648
658
|
function TUnsafe(schema: unknown): schema is TUnsafe<unknown>;
|
|
649
|
-
/** Returns true if the given
|
|
659
|
+
/** Returns true if the given value is TVoid */
|
|
650
660
|
function TVoid(schema: unknown): schema is TVoid;
|
|
651
|
-
/** Returns true if this
|
|
661
|
+
/** Returns true if this value has a Readonly symbol */
|
|
652
662
|
function TReadonly<T extends TSchema>(schema: T): schema is TReadonly<T>;
|
|
653
|
-
/** Returns true if this
|
|
663
|
+
/** Returns true if this value has a Optional symbol */
|
|
654
664
|
function TOptional<T extends TSchema>(schema: T): schema is TOptional<T>;
|
|
655
|
-
/** Returns true if the given
|
|
665
|
+
/** Returns true if the given value is TSchema */
|
|
656
666
|
function TSchema(schema: unknown): schema is TSchema;
|
|
657
667
|
}
|
|
658
668
|
/** Fast undefined check used for properties of type undefined */
|
|
@@ -859,15 +869,7 @@ export declare class JsonTypeBuilder extends TypeBuilder {
|
|
|
859
869
|
/** `[Json]` Constructs a type whose keys are picked from the given type */
|
|
860
870
|
Pick<T extends TSchema, K extends TNever>(schema: T, key: K, options?: SchemaOptions): TPick<T, never>;
|
|
861
871
|
/** `[Json]` Creates a Record type */
|
|
862
|
-
Record<K extends
|
|
863
|
-
/** `[Json]` Creates a Record type */
|
|
864
|
-
Record<K extends TLiteral<string | number>, T extends TSchema>(key: K, schema: T, options?: ObjectOptions): RecordLiteralType<K, T>;
|
|
865
|
-
/** `[Json]` Creates a Record type */
|
|
866
|
-
Record<K extends TTemplateLiteral, T extends TSchema>(key: K, schema: T, options?: ObjectOptions): RecordTemplateLiteralType<K, T>;
|
|
867
|
-
/** `[Json]` Creates a Record type */
|
|
868
|
-
Record<K extends TInteger | TNumber, T extends TSchema>(key: K, schema: T, options?: ObjectOptions): RecordNumberType<K, T>;
|
|
869
|
-
/** `[Json]` Creates a Record type */
|
|
870
|
-
Record<K extends TString, T extends TSchema>(key: K, schema: T, options?: ObjectOptions): RecordStringType<K, T>;
|
|
872
|
+
Record<K extends TSchema, T extends TSchema>(key: K, schema: T, options?: ObjectOptions): TRecordResolve<K, T>;
|
|
871
873
|
/** `[Json]` Creates a Recursive type */
|
|
872
874
|
Recursive<T extends TSchema>(callback: (thisType: TThis) => T, options?: SchemaOptions): TRecursive<T>;
|
|
873
875
|
/** `[Json]` Creates a Ref type. The referenced type must contain a $id */
|
package/typebox.js
CHANGED
|
@@ -224,14 +224,14 @@ var TypeGuard;
|
|
|
224
224
|
function IsOptionalSchema(value) {
|
|
225
225
|
return ValueGuard.IsUndefined(value) || TSchema(value);
|
|
226
226
|
}
|
|
227
|
-
/** Returns true if the given
|
|
227
|
+
/** Returns true if the given value is TAny */
|
|
228
228
|
function TAny(schema) {
|
|
229
229
|
// prettier-ignore
|
|
230
230
|
return (TKindOf(schema, 'Any') &&
|
|
231
231
|
IsOptionalString(schema.$id));
|
|
232
232
|
}
|
|
233
233
|
TypeGuard.TAny = TAny;
|
|
234
|
-
/** Returns true if the given
|
|
234
|
+
/** Returns true if the given value is TArray */
|
|
235
235
|
function TArray(schema) {
|
|
236
236
|
return (TKindOf(schema, 'Array') &&
|
|
237
237
|
schema.type === 'array' &&
|
|
@@ -245,7 +245,7 @@ var TypeGuard;
|
|
|
245
245
|
IsOptionalNumber(schema.maxContains));
|
|
246
246
|
}
|
|
247
247
|
TypeGuard.TArray = TArray;
|
|
248
|
-
/** Returns true if the given
|
|
248
|
+
/** Returns true if the given value is TAsyncIterator */
|
|
249
249
|
function TAsyncIterator(schema) {
|
|
250
250
|
// prettier-ignore
|
|
251
251
|
return (TKindOf(schema, 'AsyncIterator') &&
|
|
@@ -254,7 +254,7 @@ var TypeGuard;
|
|
|
254
254
|
TSchema(schema.items));
|
|
255
255
|
}
|
|
256
256
|
TypeGuard.TAsyncIterator = TAsyncIterator;
|
|
257
|
-
/** Returns true if the given
|
|
257
|
+
/** Returns true if the given value is TBigInt */
|
|
258
258
|
function TBigInt(schema) {
|
|
259
259
|
// prettier-ignore
|
|
260
260
|
return (TKindOf(schema, 'BigInt') &&
|
|
@@ -267,7 +267,7 @@ var TypeGuard;
|
|
|
267
267
|
IsOptionalBigInt(schema.multipleOf));
|
|
268
268
|
}
|
|
269
269
|
TypeGuard.TBigInt = TBigInt;
|
|
270
|
-
/** Returns true if the given
|
|
270
|
+
/** Returns true if the given value is TBoolean */
|
|
271
271
|
function TBoolean(schema) {
|
|
272
272
|
// prettier-ignore
|
|
273
273
|
return (TKindOf(schema, 'Boolean') &&
|
|
@@ -275,7 +275,7 @@ var TypeGuard;
|
|
|
275
275
|
IsOptionalString(schema.$id));
|
|
276
276
|
}
|
|
277
277
|
TypeGuard.TBoolean = TBoolean;
|
|
278
|
-
/** Returns true if the given
|
|
278
|
+
/** Returns true if the given value is TConstructor */
|
|
279
279
|
function TConstructor(schema) {
|
|
280
280
|
// prettier-ignore
|
|
281
281
|
return (TKindOf(schema, 'Constructor') &&
|
|
@@ -286,7 +286,7 @@ var TypeGuard;
|
|
|
286
286
|
TSchema(schema.returns));
|
|
287
287
|
}
|
|
288
288
|
TypeGuard.TConstructor = TConstructor;
|
|
289
|
-
/** Returns true if the given
|
|
289
|
+
/** Returns true if the given value is TDate */
|
|
290
290
|
function TDate(schema) {
|
|
291
291
|
return (TKindOf(schema, 'Date') &&
|
|
292
292
|
schema.type === 'Date' &&
|
|
@@ -298,7 +298,7 @@ var TypeGuard;
|
|
|
298
298
|
IsOptionalNumber(schema.multipleOfTimestamp));
|
|
299
299
|
}
|
|
300
300
|
TypeGuard.TDate = TDate;
|
|
301
|
-
/** Returns true if the given
|
|
301
|
+
/** Returns true if the given value is TFunction */
|
|
302
302
|
function TFunction(schema) {
|
|
303
303
|
// prettier-ignore
|
|
304
304
|
return (TKindOf(schema, 'Function') &&
|
|
@@ -309,7 +309,7 @@ var TypeGuard;
|
|
|
309
309
|
TSchema(schema.returns));
|
|
310
310
|
}
|
|
311
311
|
TypeGuard.TFunction = TFunction;
|
|
312
|
-
/** Returns true if the given
|
|
312
|
+
/** Returns true if the given value is TInteger */
|
|
313
313
|
function TInteger(schema) {
|
|
314
314
|
return (TKindOf(schema, 'Integer') &&
|
|
315
315
|
schema.type === 'integer' &&
|
|
@@ -321,7 +321,7 @@ var TypeGuard;
|
|
|
321
321
|
IsOptionalNumber(schema.multipleOf));
|
|
322
322
|
}
|
|
323
323
|
TypeGuard.TInteger = TInteger;
|
|
324
|
-
/** Returns true if the given
|
|
324
|
+
/** Returns true if the given value is TIntersect */
|
|
325
325
|
function TIntersect(schema) {
|
|
326
326
|
// prettier-ignore
|
|
327
327
|
return (TKindOf(schema, 'Intersect') &&
|
|
@@ -333,7 +333,7 @@ var TypeGuard;
|
|
|
333
333
|
IsOptionalString(schema.$id));
|
|
334
334
|
}
|
|
335
335
|
TypeGuard.TIntersect = TIntersect;
|
|
336
|
-
/** Returns true if the given
|
|
336
|
+
/** Returns true if the given value is TIterator */
|
|
337
337
|
function TIterator(schema) {
|
|
338
338
|
// prettier-ignore
|
|
339
339
|
return (TKindOf(schema, 'Iterator') &&
|
|
@@ -342,32 +342,32 @@ var TypeGuard;
|
|
|
342
342
|
TSchema(schema.items));
|
|
343
343
|
}
|
|
344
344
|
TypeGuard.TIterator = TIterator;
|
|
345
|
-
/** Returns true if the given
|
|
345
|
+
/** Returns true if the given value is a TKind with the given name. */
|
|
346
346
|
function TKindOf(schema, kind) {
|
|
347
347
|
return TKind(schema) && schema[exports.Kind] === kind;
|
|
348
348
|
}
|
|
349
349
|
TypeGuard.TKindOf = TKindOf;
|
|
350
|
-
/** Returns true if the given
|
|
350
|
+
/** Returns true if the given value is TKind */
|
|
351
351
|
function TKind(schema) {
|
|
352
352
|
return ValueGuard.IsObject(schema) && exports.Kind in schema && ValueGuard.IsString(schema[exports.Kind]);
|
|
353
353
|
}
|
|
354
354
|
TypeGuard.TKind = TKind;
|
|
355
|
-
/** Returns true if the given
|
|
355
|
+
/** Returns true if the given value is TLiteral<string> */
|
|
356
356
|
function TLiteralString(schema) {
|
|
357
357
|
return TLiteral(schema) && ValueGuard.IsString(schema.const);
|
|
358
358
|
}
|
|
359
359
|
TypeGuard.TLiteralString = TLiteralString;
|
|
360
|
-
/** Returns true if the given
|
|
360
|
+
/** Returns true if the given value is TLiteral<number> */
|
|
361
361
|
function TLiteralNumber(schema) {
|
|
362
362
|
return TLiteral(schema) && ValueGuard.IsNumber(schema.const);
|
|
363
363
|
}
|
|
364
364
|
TypeGuard.TLiteralNumber = TLiteralNumber;
|
|
365
|
-
/** Returns true if the given
|
|
365
|
+
/** Returns true if the given value is TLiteral<boolean> */
|
|
366
366
|
function TLiteralBoolean(schema) {
|
|
367
367
|
return TLiteral(schema) && ValueGuard.IsBoolean(schema.const);
|
|
368
368
|
}
|
|
369
369
|
TypeGuard.TLiteralBoolean = TLiteralBoolean;
|
|
370
|
-
/** Returns true if the given
|
|
370
|
+
/** Returns true if the given value is TLiteral */
|
|
371
371
|
function TLiteral(schema) {
|
|
372
372
|
// prettier-ignore
|
|
373
373
|
return (TKindOf(schema, 'Literal') &&
|
|
@@ -376,7 +376,7 @@ var TypeGuard;
|
|
|
376
376
|
ValueGuard.IsString(schema.const)));
|
|
377
377
|
}
|
|
378
378
|
TypeGuard.TLiteral = TLiteral;
|
|
379
|
-
/** Returns true if the given
|
|
379
|
+
/** Returns true if the given value is TNever */
|
|
380
380
|
function TNever(schema) {
|
|
381
381
|
// prettier-ignore
|
|
382
382
|
return (TKindOf(schema, 'Never') &&
|
|
@@ -384,14 +384,14 @@ var TypeGuard;
|
|
|
384
384
|
Object.getOwnPropertyNames(schema.not).length === 0);
|
|
385
385
|
}
|
|
386
386
|
TypeGuard.TNever = TNever;
|
|
387
|
-
/** Returns true if the given
|
|
387
|
+
/** Returns true if the given value is TNot */
|
|
388
388
|
function TNot(schema) {
|
|
389
389
|
// prettier-ignore
|
|
390
390
|
return (TKindOf(schema, 'Not') &&
|
|
391
391
|
TSchema(schema.not));
|
|
392
392
|
}
|
|
393
393
|
TypeGuard.TNot = TNot;
|
|
394
|
-
/** Returns true if the given
|
|
394
|
+
/** Returns true if the given value is TNull */
|
|
395
395
|
function TNull(schema) {
|
|
396
396
|
// prettier-ignore
|
|
397
397
|
return (TKindOf(schema, 'Null') &&
|
|
@@ -399,7 +399,7 @@ var TypeGuard;
|
|
|
399
399
|
IsOptionalString(schema.$id));
|
|
400
400
|
}
|
|
401
401
|
TypeGuard.TNull = TNull;
|
|
402
|
-
/** Returns true if the given
|
|
402
|
+
/** Returns true if the given value is TNumber */
|
|
403
403
|
function TNumber(schema) {
|
|
404
404
|
return (TKindOf(schema, 'Number') &&
|
|
405
405
|
schema.type === 'number' &&
|
|
@@ -411,7 +411,7 @@ var TypeGuard;
|
|
|
411
411
|
IsOptionalNumber(schema.multipleOf));
|
|
412
412
|
}
|
|
413
413
|
TypeGuard.TNumber = TNumber;
|
|
414
|
-
/** Returns true if the given
|
|
414
|
+
/** Returns true if the given value is TObject */
|
|
415
415
|
function TObject(schema) {
|
|
416
416
|
// prettier-ignore
|
|
417
417
|
return (TKindOf(schema, 'Object') &&
|
|
@@ -424,7 +424,7 @@ var TypeGuard;
|
|
|
424
424
|
Object.entries(schema.properties).every(([key, schema]) => IsControlCharacterFree(key) && TSchema(schema)));
|
|
425
425
|
}
|
|
426
426
|
TypeGuard.TObject = TObject;
|
|
427
|
-
/** Returns true if the given
|
|
427
|
+
/** Returns true if the given value is TPromise */
|
|
428
428
|
function TPromise(schema) {
|
|
429
429
|
// prettier-ignore
|
|
430
430
|
return (TKindOf(schema, 'Promise') &&
|
|
@@ -433,7 +433,7 @@ var TypeGuard;
|
|
|
433
433
|
TSchema(schema.item));
|
|
434
434
|
}
|
|
435
435
|
TypeGuard.TPromise = TPromise;
|
|
436
|
-
/** Returns true if the given
|
|
436
|
+
/** Returns true if the given value is TRecord */
|
|
437
437
|
function TRecord(schema) {
|
|
438
438
|
// prettier-ignore
|
|
439
439
|
return (TKindOf(schema, 'Record') &&
|
|
@@ -450,12 +450,12 @@ var TypeGuard;
|
|
|
450
450
|
})(schema));
|
|
451
451
|
}
|
|
452
452
|
TypeGuard.TRecord = TRecord;
|
|
453
|
-
/** Returns true if this
|
|
453
|
+
/** Returns true if this value is TRecursive */
|
|
454
454
|
function TRecursive(schema) {
|
|
455
455
|
return ValueGuard.IsObject(schema) && exports.Hint in schema && schema[exports.Hint] === 'Recursive';
|
|
456
456
|
}
|
|
457
457
|
TypeGuard.TRecursive = TRecursive;
|
|
458
|
-
/** Returns true if the given
|
|
458
|
+
/** Returns true if the given value is TRef */
|
|
459
459
|
function TRef(schema) {
|
|
460
460
|
// prettier-ignore
|
|
461
461
|
return (TKindOf(schema, 'Ref') &&
|
|
@@ -463,7 +463,7 @@ var TypeGuard;
|
|
|
463
463
|
ValueGuard.IsString(schema.$ref));
|
|
464
464
|
}
|
|
465
465
|
TypeGuard.TRef = TRef;
|
|
466
|
-
/** Returns true if the given
|
|
466
|
+
/** Returns true if the given value is TString */
|
|
467
467
|
function TString(schema) {
|
|
468
468
|
// prettier-ignore
|
|
469
469
|
return (TKindOf(schema, 'String') &&
|
|
@@ -475,7 +475,7 @@ var TypeGuard;
|
|
|
475
475
|
IsOptionalFormat(schema.format));
|
|
476
476
|
}
|
|
477
477
|
TypeGuard.TString = TString;
|
|
478
|
-
/** Returns true if the given
|
|
478
|
+
/** Returns true if the given value is TSymbol */
|
|
479
479
|
function TSymbol(schema) {
|
|
480
480
|
// prettier-ignore
|
|
481
481
|
return (TKindOf(schema, 'Symbol') &&
|
|
@@ -483,7 +483,7 @@ var TypeGuard;
|
|
|
483
483
|
IsOptionalString(schema.$id));
|
|
484
484
|
}
|
|
485
485
|
TypeGuard.TSymbol = TSymbol;
|
|
486
|
-
/** Returns true if the given
|
|
486
|
+
/** Returns true if the given value is TTemplateLiteral */
|
|
487
487
|
function TTemplateLiteral(schema) {
|
|
488
488
|
// prettier-ignore
|
|
489
489
|
return (TKindOf(schema, 'TemplateLiteral') &&
|
|
@@ -493,7 +493,7 @@ var TypeGuard;
|
|
|
493
493
|
schema.pattern[schema.pattern.length - 1] === '$');
|
|
494
494
|
}
|
|
495
495
|
TypeGuard.TTemplateLiteral = TTemplateLiteral;
|
|
496
|
-
/** Returns true if the given
|
|
496
|
+
/** Returns true if the given value is TThis */
|
|
497
497
|
function TThis(schema) {
|
|
498
498
|
// prettier-ignore
|
|
499
499
|
return (TKindOf(schema, 'This') &&
|
|
@@ -501,12 +501,12 @@ var TypeGuard;
|
|
|
501
501
|
ValueGuard.IsString(schema.$ref));
|
|
502
502
|
}
|
|
503
503
|
TypeGuard.TThis = TThis;
|
|
504
|
-
/** Returns true of this
|
|
504
|
+
/** Returns true of this value is TTransform */
|
|
505
505
|
function TTransform(schema) {
|
|
506
506
|
return ValueGuard.IsObject(schema) && exports.Transform in schema;
|
|
507
507
|
}
|
|
508
508
|
TypeGuard.TTransform = TTransform;
|
|
509
|
-
/** Returns true if the given
|
|
509
|
+
/** Returns true if the given value is TTuple */
|
|
510
510
|
function TTuple(schema) {
|
|
511
511
|
// prettier-ignore
|
|
512
512
|
return (TKindOf(schema, 'Tuple') &&
|
|
@@ -522,7 +522,7 @@ var TypeGuard;
|
|
|
522
522
|
schema.items.every(schema => TSchema(schema)))));
|
|
523
523
|
}
|
|
524
524
|
TypeGuard.TTuple = TTuple;
|
|
525
|
-
/** Returns true if the given
|
|
525
|
+
/** Returns true if the given value is TUndefined */
|
|
526
526
|
function TUndefined(schema) {
|
|
527
527
|
// prettier-ignore
|
|
528
528
|
return (TKindOf(schema, 'Undefined') &&
|
|
@@ -530,12 +530,12 @@ var TypeGuard;
|
|
|
530
530
|
IsOptionalString(schema.$id));
|
|
531
531
|
}
|
|
532
532
|
TypeGuard.TUndefined = TUndefined;
|
|
533
|
-
/** Returns true if the given
|
|
533
|
+
/** Returns true if the given value is TUnion<Literal<string | number>[]> */
|
|
534
534
|
function TUnionLiteral(schema) {
|
|
535
535
|
return TUnion(schema) && schema.anyOf.every((schema) => TLiteralString(schema) || TLiteralNumber(schema));
|
|
536
536
|
}
|
|
537
537
|
TypeGuard.TUnionLiteral = TUnionLiteral;
|
|
538
|
-
/** Returns true if the given
|
|
538
|
+
/** Returns true if the given value is TUnion */
|
|
539
539
|
function TUnion(schema) {
|
|
540
540
|
// prettier-ignore
|
|
541
541
|
return (TKindOf(schema, 'Union') &&
|
|
@@ -545,7 +545,7 @@ var TypeGuard;
|
|
|
545
545
|
schema.anyOf.every(schema => TSchema(schema)));
|
|
546
546
|
}
|
|
547
547
|
TypeGuard.TUnion = TUnion;
|
|
548
|
-
/** Returns true if the given
|
|
548
|
+
/** Returns true if the given value is TUint8Array */
|
|
549
549
|
function TUint8Array(schema) {
|
|
550
550
|
// prettier-ignore
|
|
551
551
|
return (TKindOf(schema, 'Uint8Array') &&
|
|
@@ -555,19 +555,19 @@ var TypeGuard;
|
|
|
555
555
|
IsOptionalNumber(schema.maxByteLength));
|
|
556
556
|
}
|
|
557
557
|
TypeGuard.TUint8Array = TUint8Array;
|
|
558
|
-
/** Returns true if the given
|
|
558
|
+
/** Returns true if the given value is TUnknown */
|
|
559
559
|
function TUnknown(schema) {
|
|
560
560
|
// prettier-ignore
|
|
561
561
|
return (TKindOf(schema, 'Unknown') &&
|
|
562
562
|
IsOptionalString(schema.$id));
|
|
563
563
|
}
|
|
564
564
|
TypeGuard.TUnknown = TUnknown;
|
|
565
|
-
/** Returns true if the given
|
|
565
|
+
/** Returns true if the given value is a raw TUnsafe */
|
|
566
566
|
function TUnsafe(schema) {
|
|
567
567
|
return TKindOf(schema, 'Unsafe');
|
|
568
568
|
}
|
|
569
569
|
TypeGuard.TUnsafe = TUnsafe;
|
|
570
|
-
/** Returns true if the given
|
|
570
|
+
/** Returns true if the given value is TVoid */
|
|
571
571
|
function TVoid(schema) {
|
|
572
572
|
// prettier-ignore
|
|
573
573
|
return (TKindOf(schema, 'Void') &&
|
|
@@ -575,17 +575,17 @@ var TypeGuard;
|
|
|
575
575
|
IsOptionalString(schema.$id));
|
|
576
576
|
}
|
|
577
577
|
TypeGuard.TVoid = TVoid;
|
|
578
|
-
/** Returns true if this
|
|
578
|
+
/** Returns true if this value has a Readonly symbol */
|
|
579
579
|
function TReadonly(schema) {
|
|
580
580
|
return ValueGuard.IsObject(schema) && schema[exports.Readonly] === 'Readonly';
|
|
581
581
|
}
|
|
582
582
|
TypeGuard.TReadonly = TReadonly;
|
|
583
|
-
/** Returns true if this
|
|
583
|
+
/** Returns true if this value has a Optional symbol */
|
|
584
584
|
function TOptional(schema) {
|
|
585
585
|
return ValueGuard.IsObject(schema) && schema[exports.Optional] === 'Optional';
|
|
586
586
|
}
|
|
587
587
|
TypeGuard.TOptional = TOptional;
|
|
588
|
-
/** Returns true if the given
|
|
588
|
+
/** Returns true if the given value is TSchema */
|
|
589
589
|
function TSchema(schema) {
|
|
590
590
|
return (ValueGuard.IsObject(schema) &&
|
|
591
591
|
(TAny(schema) ||
|
|
@@ -2148,7 +2148,7 @@ class JsonTypeBuilder extends TypeBuilder {
|
|
|
2148
2148
|
const pattern = ValueGuard.IsUndefined(key.pattern) ? exports.PatternStringExact : key.pattern;
|
|
2149
2149
|
return this.Create({ ...options, [exports.Kind]: 'Record', type: 'object', patternProperties: { [pattern]: TypeClone.Type(schema) } });
|
|
2150
2150
|
})() :
|
|
2151
|
-
this.
|
|
2151
|
+
this.Never());
|
|
2152
2152
|
}
|
|
2153
2153
|
/** `[Json]` Creates a Recursive type */
|
|
2154
2154
|
Recursive(callback, options = {}) {
|