@sinclair/typebox 0.29.5 → 0.30.0-dev-1
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/compiler/compiler.d.ts +7 -4
- package/compiler/compiler.js +208 -194
- package/errors/errors.d.ts +65 -60
- package/errors/errors.js +515 -492
- package/package.json +14 -2
- package/readme.md +161 -169
- package/system/system.js +0 -6
- package/typebox.d.ts +99 -52
- package/typebox.js +496 -573
- package/value/cast.d.ts +5 -4
- package/value/cast.js +255 -260
- package/value/check.d.ts +4 -3
- package/value/check.js +412 -397
- package/value/clone.d.ts +2 -3
- package/value/clone.js +62 -42
- package/value/convert.d.ts +5 -4
- package/value/convert.js +305 -318
- package/value/create.d.ts +6 -6
- package/value/create.js +388 -376
- package/value/delta.d.ts +2 -4
- package/value/delta.js +121 -130
- package/value/equal.d.ts +2 -3
- package/value/equal.js +48 -51
- package/value/guard.d.ts +44 -0
- package/value/guard.js +146 -0
- package/value/hash.d.ts +14 -3
- package/value/hash.js +124 -166
- package/value/index.d.ts +3 -4
- package/value/index.js +6 -20
- package/value/mutate.d.ts +2 -4
- package/value/mutate.js +75 -67
- package/value/pointer.js +8 -2
- package/value/value.d.ts +15 -15
- package/value/value.js +27 -27
- package/value/is.d.ts +0 -11
- package/value/is.js +0 -53
package/typebox.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export declare const
|
|
1
|
+
export declare const Readonly: unique symbol;
|
|
2
|
+
export declare const Optional: unique symbol;
|
|
2
3
|
export declare const Hint: unique symbol;
|
|
3
4
|
export declare const Kind: unique symbol;
|
|
4
5
|
export declare const PatternBoolean = "(true|false)";
|
|
@@ -25,22 +26,21 @@ export type Ensure<T> = T extends infer U ? U : never;
|
|
|
25
26
|
export type AssertProperties<T> = T extends TProperties ? T : TProperties;
|
|
26
27
|
export type AssertRest<T, E extends TSchema[] = TSchema[]> = T extends E ? T : [];
|
|
27
28
|
export type AssertType<T, E extends TSchema = TSchema> = T extends E ? T : TNever;
|
|
28
|
-
export type TModifier =
|
|
29
|
+
export type TModifier = TOptional<TSchema> | TReadonly<TSchema>;
|
|
29
30
|
export type TReadonly<T extends TSchema> = T & {
|
|
30
|
-
[
|
|
31
|
+
[Readonly]: 'Readonly';
|
|
31
32
|
};
|
|
32
33
|
export type TOptional<T extends TSchema> = T & {
|
|
33
|
-
[
|
|
34
|
+
[Optional]: 'Optional';
|
|
34
35
|
};
|
|
35
|
-
export type
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
export type
|
|
39
|
-
export type
|
|
40
|
-
export type IntersectOptional<T extends TSchema[]> = T extends [infer L, ...infer R] ? L extends TOptional<AssertType<L>> | TReadonlyOptional<AssertType<L>> ? IntersectOptional<AssertRest<R>> : false : true;
|
|
36
|
+
export type ReadonlyUnwrapType<T extends TSchema> = T extends TReadonly<infer S> ? ReadonlyUnwrapType<S> : T extends TOptional<infer S> ? TOptional<ReadonlyUnwrapType<S>> : T;
|
|
37
|
+
export type ReadonlyUnwrapRest<T extends TSchema[]> = T extends [infer L, ...infer R] ? L extends TReadonly<infer S> ? [ReadonlyUnwrapType<AssertType<S>>, ...ReadonlyUnwrapRest<AssertRest<R>>] : [L, ...ReadonlyUnwrapRest<AssertRest<R>>] : [];
|
|
38
|
+
export type OptionalUnwrapType<T extends TSchema> = T extends TReadonly<infer S> ? TReadonly<OptionalUnwrapType<S>> : T extends TOptional<infer S> ? OptionalUnwrapType<S> : T;
|
|
39
|
+
export type OptionalUnwrapRest<T extends TSchema[]> = T extends [infer L, ...infer R] ? L extends TOptional<infer S> ? [OptionalUnwrapType<AssertType<S>>, ...OptionalUnwrapRest<AssertRest<R>>] : [L, ...OptionalUnwrapRest<AssertRest<R>>] : [];
|
|
40
|
+
export type IntersectOptional<T extends TSchema[]> = T extends [infer L, ...infer R] ? L extends TOptional<AssertType<L>> ? IntersectOptional<AssertRest<R>> : false : true;
|
|
41
41
|
export type IntersectResolve<T extends TSchema[], U = OptionalUnwrapRest<AssertRest<T>>> = IntersectOptional<AssertRest<T>> extends true ? TOptional<TIntersect<AssertRest<U>>> : TIntersect<AssertRest<U>>;
|
|
42
42
|
export type IntersectType<T extends TSchema[]> = T extends [] ? TNever : T extends [TSchema] ? AssertType<T[0]> : IntersectResolve<T>;
|
|
43
|
-
export type UnionOptional<T extends TSchema[]> = T extends [infer L, ...infer R] ? L extends (TOptional<AssertType<L>>
|
|
43
|
+
export type UnionOptional<T extends TSchema[]> = T extends [infer L, ...infer R] ? L extends (TOptional<AssertType<L>>) ? true : UnionOptional<AssertRest<R>> : false;
|
|
44
44
|
export type UnionResolve<T extends TSchema[], U = OptionalUnwrapRest<AssertRest<T>>> = UnionOptional<AssertRest<T>> extends true ? TOptional<TUnion<AssertRest<U>>> : TUnion<AssertRest<U>>;
|
|
45
45
|
export type UnionType<T extends TSchema[]> = T extends [] ? TNever : T extends [TSchema] ? AssertType<T[0]> : UnionResolve<T>;
|
|
46
46
|
export type Key = string | number;
|
|
@@ -56,18 +56,23 @@ export interface SchemaOptions {
|
|
|
56
56
|
default?: any;
|
|
57
57
|
/** Example values matching this schema */
|
|
58
58
|
examples?: any;
|
|
59
|
+
/** Optional annotation for readOnly */
|
|
60
|
+
readOnly?: boolean;
|
|
61
|
+
/** Optional annotation for writeOnly */
|
|
62
|
+
writeOnly?: boolean;
|
|
59
63
|
[prop: string]: any;
|
|
60
64
|
}
|
|
61
65
|
export interface TKind {
|
|
62
66
|
[Kind]: string;
|
|
63
67
|
}
|
|
64
68
|
export interface TSchema extends SchemaOptions, TKind {
|
|
65
|
-
[
|
|
69
|
+
[Readonly]?: string;
|
|
70
|
+
[Optional]?: string;
|
|
66
71
|
[Hint]?: string;
|
|
67
72
|
params: unknown[];
|
|
68
73
|
static: unknown;
|
|
69
74
|
}
|
|
70
|
-
export type TAnySchema = TSchema | TAny | TArray | TBigInt | TBoolean | TConstructor | TDate | TEnum | TFunction | TInteger | TIntersect | TLiteral | TNot | TNull | TNumber | TObject | TPromise | TRecord | TRef | TString | TSymbol | TTemplateLiteral | TThis | TTuple | TUndefined | TUnion | TUint8Array | TUnknown | TVoid;
|
|
75
|
+
export type TAnySchema = TSchema | TAny | TArray | TAsyncIterator | TBigInt | TBoolean | TConstructor | TDate | TEnum | TFunction | TInteger | TIntersect | TIterator | TLiteral | TNot | TNull | TNumber | TObject | TPromise | TRecord | TRef | TString | TSymbol | TTemplateLiteral | TThis | TTuple | TUndefined | TUnion | TUint8Array | TUnknown | TVoid;
|
|
71
76
|
export interface NumericOptions<N extends number | bigint> extends SchemaOptions {
|
|
72
77
|
exclusiveMaximum?: N;
|
|
73
78
|
exclusiveMinimum?: N;
|
|
@@ -80,9 +85,12 @@ export interface TAny extends TSchema {
|
|
|
80
85
|
static: any;
|
|
81
86
|
}
|
|
82
87
|
export interface ArrayOptions extends SchemaOptions {
|
|
83
|
-
uniqueItems?: boolean;
|
|
84
88
|
minItems?: number;
|
|
85
89
|
maxItems?: number;
|
|
90
|
+
contains?: TSchema;
|
|
91
|
+
minContains?: number;
|
|
92
|
+
maxContains?: number;
|
|
93
|
+
uniqueItems?: boolean;
|
|
86
94
|
}
|
|
87
95
|
export interface TArray<T extends TSchema = TSchema> extends TSchema, ArrayOptions {
|
|
88
96
|
[Kind]: 'Array';
|
|
@@ -90,11 +98,16 @@ export interface TArray<T extends TSchema = TSchema> extends TSchema, ArrayOptio
|
|
|
90
98
|
type: 'array';
|
|
91
99
|
items: T;
|
|
92
100
|
}
|
|
101
|
+
export interface TAsyncIterator<T extends TSchema = TSchema> extends TSchema {
|
|
102
|
+
[Kind]: 'AsyncIterator';
|
|
103
|
+
static: AsyncIterableIterator<Static<T, this['params']>>;
|
|
104
|
+
type: 'AsyncIterator';
|
|
105
|
+
items: T;
|
|
106
|
+
}
|
|
93
107
|
export interface TBigInt extends TSchema, NumericOptions<bigint> {
|
|
94
108
|
[Kind]: 'BigInt';
|
|
95
109
|
static: bigint;
|
|
96
|
-
type: '
|
|
97
|
-
typeOf: 'BigInt';
|
|
110
|
+
type: 'bigint';
|
|
98
111
|
}
|
|
99
112
|
export interface TBoolean extends TSchema {
|
|
100
113
|
[Kind]: 'Boolean';
|
|
@@ -115,8 +128,7 @@ export type TConstructorParameterArray<T extends readonly TSchema[], P extends u
|
|
|
115
128
|
export interface TConstructor<T extends TSchema[] = TSchema[], U extends TSchema = TSchema> extends TSchema {
|
|
116
129
|
[Kind]: 'Constructor';
|
|
117
130
|
static: new (...param: TConstructorParameterArray<T, this['params']>) => Static<U, this['params']>;
|
|
118
|
-
type: '
|
|
119
|
-
instanceOf: 'Constructor';
|
|
131
|
+
type: 'constructor';
|
|
120
132
|
parameters: T;
|
|
121
133
|
returns: U;
|
|
122
134
|
}
|
|
@@ -129,8 +141,7 @@ export interface DateOptions extends SchemaOptions {
|
|
|
129
141
|
export interface TDate extends TSchema, DateOptions {
|
|
130
142
|
[Kind]: 'Date';
|
|
131
143
|
static: Date;
|
|
132
|
-
type: '
|
|
133
|
-
instanceOf: 'Date';
|
|
144
|
+
type: 'date';
|
|
134
145
|
}
|
|
135
146
|
export interface TEnumOption<T> {
|
|
136
147
|
type: 'number' | 'string';
|
|
@@ -158,14 +169,13 @@ export type TExtractArray<T extends TSchema[], U extends TSchema> = AssertRest<U
|
|
|
158
169
|
[K in keyof T]: Static<AssertType<T[K]>> extends Static<U> ? T[K] : never;
|
|
159
170
|
}[number]>> extends infer R ? UnionType<AssertRest<R>> : never;
|
|
160
171
|
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;
|
|
161
|
-
export type TFunctionParameters<T extends
|
|
172
|
+
export type TFunctionParameters<T extends TSchema[], P extends unknown[]> = [...{
|
|
162
173
|
[K in keyof T]: Static<AssertType<T[K]>, P>;
|
|
163
174
|
}];
|
|
164
|
-
export interface TFunction<T extends
|
|
175
|
+
export interface TFunction<T extends TSchema[] = TSchema[], U extends TSchema = TSchema> extends TSchema {
|
|
165
176
|
[Kind]: 'Function';
|
|
166
177
|
static: (...param: TFunctionParameters<T, this['params']>) => Static<U, this['params']>;
|
|
167
|
-
type: '
|
|
168
|
-
instanceOf: 'Function';
|
|
178
|
+
type: 'function';
|
|
169
179
|
parameters: T;
|
|
170
180
|
returns: U;
|
|
171
181
|
}
|
|
@@ -194,6 +204,12 @@ export interface TIntersect<T extends TSchema[] = TSchema[]> extends TSchema, In
|
|
|
194
204
|
type?: 'object';
|
|
195
205
|
allOf: [...T];
|
|
196
206
|
}
|
|
207
|
+
export interface TIterator<T extends TSchema = TSchema> extends TSchema {
|
|
208
|
+
[Kind]: 'Iterator';
|
|
209
|
+
static: IterableIterator<Static<T, this['params']>>;
|
|
210
|
+
type: 'Iterator';
|
|
211
|
+
items: T;
|
|
212
|
+
}
|
|
197
213
|
export type TKeyOfProperties<T extends TSchema> = Discard<Static<T> extends infer S ? UnionToTuple<{
|
|
198
214
|
[K in keyof S]: TLiteral<Assert<K, TLiteralValue>>;
|
|
199
215
|
}[keyof S]> : [], undefined>;
|
|
@@ -230,13 +246,13 @@ export interface TNumber extends TSchema, NumericOptions<number> {
|
|
|
230
246
|
type: 'number';
|
|
231
247
|
}
|
|
232
248
|
export type ReadonlyOptionalPropertyKeys<T extends TProperties> = {
|
|
233
|
-
[K in keyof T]: T[K] extends
|
|
249
|
+
[K in keyof T]: T[K] extends TReadonly<TSchema> ? (T[K] extends TOptional<T[K]> ? K : never) : never;
|
|
234
250
|
}[keyof T];
|
|
235
251
|
export type ReadonlyPropertyKeys<T extends TProperties> = {
|
|
236
|
-
[K in keyof T]: T[K] extends TReadonly<TSchema> ? K : never;
|
|
252
|
+
[K in keyof T]: T[K] extends TReadonly<TSchema> ? (T[K] extends TOptional<T[K]> ? never : K) : never;
|
|
237
253
|
}[keyof T];
|
|
238
254
|
export type OptionalPropertyKeys<T extends TProperties> = {
|
|
239
|
-
[K in keyof T]: T[K] extends TOptional<TSchema> ? K : never;
|
|
255
|
+
[K in keyof T]: T[K] extends TOptional<TSchema> ? (T[K] extends TReadonly<T[K]> ? never : K) : never;
|
|
240
256
|
}[keyof T];
|
|
241
257
|
export type RequiredPropertyKeys<T extends TProperties> = keyof Omit<T, ReadonlyOptionalPropertyKeys<T> | ReadonlyPropertyKeys<T> | OptionalPropertyKeys<T>>;
|
|
242
258
|
export type PropertiesReducer<T extends TProperties, R extends Record<keyof any, unknown>> = Evaluate<(Readonly<Partial<Pick<R, ReadonlyOptionalPropertyKeys<T>>>> & Readonly<Pick<R, ReadonlyPropertyKeys<T>>> & Partial<Pick<R, OptionalPropertyKeys<T>>> & Required<Pick<R, RequiredPropertyKeys<T>>>)>;
|
|
@@ -273,7 +289,7 @@ export type TPartialArray<T extends TSchema[]> = AssertRest<{
|
|
|
273
289
|
[K in keyof T]: TPartial<AssertType<T[K]>>;
|
|
274
290
|
}>;
|
|
275
291
|
export type TPartialProperties<T extends TProperties> = Evaluate<AssertProperties<{
|
|
276
|
-
[K in keyof T]:
|
|
292
|
+
[K in keyof T]: TOptional<T[K]>;
|
|
277
293
|
}>>;
|
|
278
294
|
export type TPartial<T extends TSchema> = T extends TRecursive<infer S> ? TRecursive<TPartial<S>> : T extends TIntersect<infer S> ? TIntersect<TPartialArray<S>> : T extends TUnion<infer S> ? TUnion<TPartialArray<S>> : T extends TObject<infer S> ? TObject<TPartialProperties<S>> : T;
|
|
279
295
|
export type TPickArray<T extends TSchema[], K extends keyof any> = {
|
|
@@ -286,8 +302,7 @@ export type TPick<T extends TSchema = TSchema, K extends keyof any = keyof any>
|
|
|
286
302
|
export interface TPromise<T extends TSchema = TSchema> extends TSchema {
|
|
287
303
|
[Kind]: 'Promise';
|
|
288
304
|
static: Promise<Static<T, this['params']>>;
|
|
289
|
-
type: '
|
|
290
|
-
instanceOf: 'Promise';
|
|
305
|
+
type: 'promise';
|
|
291
306
|
item: TSchema;
|
|
292
307
|
}
|
|
293
308
|
export type RecordTemplateLiteralObjectType<K extends TTemplateLiteral, T extends TSchema> = Ensure<TObject<Evaluate<{
|
|
@@ -333,7 +348,7 @@ export type TRequiredArray<T extends TSchema[]> = AssertRest<{
|
|
|
333
348
|
[K in keyof T]: TRequired<AssertType<T[K]>>;
|
|
334
349
|
}>;
|
|
335
350
|
export type TRequiredProperties<T extends TProperties> = Evaluate<AssertProperties<{
|
|
336
|
-
[K in keyof T]: T[K] extends
|
|
351
|
+
[K in keyof T]: T[K] extends TOptional<infer S> ? S : T[K];
|
|
337
352
|
}>>;
|
|
338
353
|
export type TRequired<T extends TSchema> = T extends TRecursive<infer S> ? TRecursive<TRequired<S>> : T extends TIntersect<infer S> ? TIntersect<TRequiredArray<S>> : T extends TUnion<infer S> ? TUnion<TRequiredArray<S>> : T extends TObject<infer S> ? TObject<TRequiredProperties<S>> : T;
|
|
339
354
|
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);
|
|
@@ -355,8 +370,7 @@ export type SymbolValue = string | number | undefined;
|
|
|
355
370
|
export interface TSymbol extends TSchema, SchemaOptions {
|
|
356
371
|
[Kind]: 'Symbol';
|
|
357
372
|
static: symbol;
|
|
358
|
-
type: '
|
|
359
|
-
typeOf: 'Symbol';
|
|
373
|
+
type: 'symbol';
|
|
360
374
|
}
|
|
361
375
|
export type TTemplateLiteralDslParserUnionLiteral<T extends string> = T extends `${infer L}|${infer R}` ? [TLiteral<Trim<L>>, ...TTemplateLiteralDslParserUnionLiteral<R>] : T extends `${infer L}` ? [TLiteral<Trim<L>>] : [
|
|
362
376
|
];
|
|
@@ -394,8 +408,7 @@ export interface TTuple<T extends TSchema[] = TSchema[]> extends TSchema {
|
|
|
394
408
|
export interface TUndefined extends TSchema {
|
|
395
409
|
[Kind]: 'Undefined';
|
|
396
410
|
static: undefined;
|
|
397
|
-
type: '
|
|
398
|
-
typeOf: 'Undefined';
|
|
411
|
+
type: 'undefined';
|
|
399
412
|
}
|
|
400
413
|
export type TLiteralUnionReduce<T extends TLiteral<string | number>[]> = T extends [infer L, ...infer R] ? [Assert<L, TLiteral<string | number>>['const'], ...TLiteralUnionReduce<Assert<R, TLiteral<string | number>[]>>] : [
|
|
401
414
|
];
|
|
@@ -418,8 +431,7 @@ export interface Uint8ArrayOptions extends SchemaOptions {
|
|
|
418
431
|
export interface TUint8Array extends TSchema, Uint8ArrayOptions {
|
|
419
432
|
[Kind]: 'Uint8Array';
|
|
420
433
|
static: Uint8Array;
|
|
421
|
-
|
|
422
|
-
type: 'object';
|
|
434
|
+
type: 'uint8array';
|
|
423
435
|
}
|
|
424
436
|
export interface TUnknown extends TSchema {
|
|
425
437
|
[Kind]: 'Unknown';
|
|
@@ -435,8 +447,7 @@ export interface TUnsafe<T> extends TSchema {
|
|
|
435
447
|
export interface TVoid extends TSchema {
|
|
436
448
|
[Kind]: 'Void';
|
|
437
449
|
static: void;
|
|
438
|
-
type: '
|
|
439
|
-
typeOf: 'Void';
|
|
450
|
+
type: 'void';
|
|
440
451
|
}
|
|
441
452
|
/** Infers a static type from a TypeBox type */
|
|
442
453
|
export type Static<T extends TSchema, P extends unknown[] = []> = (T & {
|
|
@@ -449,6 +460,8 @@ export declare namespace TypeRegistry {
|
|
|
449
460
|
function Entries(): Map<string, TypeRegistryValidationFunction<any>>;
|
|
450
461
|
/** Clears all user defined types */
|
|
451
462
|
function Clear(): void;
|
|
463
|
+
/** Deletes a registered type */
|
|
464
|
+
function Delete(kind: string): boolean;
|
|
452
465
|
/** Returns true if this registry contains this kind */
|
|
453
466
|
function Has(kind: string): boolean;
|
|
454
467
|
/** Sets a validation function for a user defined type */
|
|
@@ -463,6 +476,8 @@ export declare namespace FormatRegistry {
|
|
|
463
476
|
function Entries(): Map<string, FormatRegistryValidationFunction>;
|
|
464
477
|
/** Clears all user defined string formats */
|
|
465
478
|
function Clear(): void;
|
|
479
|
+
/** Deletes a registered format */
|
|
480
|
+
function Delete(format: string): boolean;
|
|
466
481
|
/** Returns true if the user defined string format exists */
|
|
467
482
|
function Has(format: string): boolean;
|
|
468
483
|
/** Sets a validation function for a user defined string format */
|
|
@@ -470,6 +485,16 @@ export declare namespace FormatRegistry {
|
|
|
470
485
|
/** Gets a validation function for a user defined string format */
|
|
471
486
|
function Get(format: string): FormatRegistryValidationFunction | undefined;
|
|
472
487
|
}
|
|
488
|
+
export declare namespace ValueGuard {
|
|
489
|
+
function IsObject(value: unknown): value is Record<PropertyKey, unknown>;
|
|
490
|
+
function IsArray(value: unknown): value is unknown[];
|
|
491
|
+
function IsBoolean(value: unknown): value is boolean;
|
|
492
|
+
function IsNull(value: unknown): value is null;
|
|
493
|
+
function IsUndefined(value: unknown): value is undefined;
|
|
494
|
+
function IsBigInt(value: unknown): value is bigint;
|
|
495
|
+
function IsNumber(value: unknown): value is number;
|
|
496
|
+
function IsString(value: unknown): value is string;
|
|
497
|
+
}
|
|
473
498
|
export declare class TypeGuardUnknownTypeError extends Error {
|
|
474
499
|
readonly schema: unknown;
|
|
475
500
|
constructor(schema: unknown);
|
|
@@ -480,6 +505,8 @@ export declare namespace TypeGuard {
|
|
|
480
505
|
function TAny(schema: unknown): schema is TAny;
|
|
481
506
|
/** Returns true if the given schema is TArray */
|
|
482
507
|
function TArray(schema: unknown): schema is TArray;
|
|
508
|
+
/** Returns true if the given schema is TAsyncIterator */
|
|
509
|
+
function TAsyncIterator(schema: unknown): schema is TAsyncIterator;
|
|
483
510
|
/** Returns true if the given schema is TBigInt */
|
|
484
511
|
function TBigInt(schema: unknown): schema is TBigInt;
|
|
485
512
|
/** Returns true if the given schema is TBoolean */
|
|
@@ -494,8 +521,16 @@ export declare namespace TypeGuard {
|
|
|
494
521
|
function TInteger(schema: unknown): schema is TInteger;
|
|
495
522
|
/** Returns true if the given schema is TIntersect */
|
|
496
523
|
function TIntersect(schema: unknown): schema is TIntersect;
|
|
524
|
+
/** Returns true if the given schema is TIterator */
|
|
525
|
+
function TIterator(schema: unknown): schema is TIterator;
|
|
526
|
+
/** Returns true if the given schema is a TKind with the given name. */
|
|
527
|
+
function TKindOf<T extends string>(schema: unknown, kind: T): schema is Record<PropertyKey, unknown> & {
|
|
528
|
+
[Kind]: T;
|
|
529
|
+
};
|
|
497
530
|
/** Returns true if the given schema is TKind */
|
|
498
|
-
function TKind(schema: unknown): schema is Record<
|
|
531
|
+
function TKind(schema: unknown): schema is Record<PropertyKey, unknown> & {
|
|
532
|
+
[Kind]: string;
|
|
533
|
+
};
|
|
499
534
|
/** Returns true if the given schema is TLiteral<string> */
|
|
500
535
|
function TLiteralString(schema: unknown): schema is TLiteral<string>;
|
|
501
536
|
/** Returns true if the given schema is TLiteral<number> */
|
|
@@ -544,8 +579,6 @@ export declare namespace TypeGuard {
|
|
|
544
579
|
function TUnsafe(schema: unknown): schema is TUnsafe<unknown>;
|
|
545
580
|
/** Returns true if the given schema is TVoid */
|
|
546
581
|
function TVoid(schema: unknown): schema is TVoid;
|
|
547
|
-
/** Returns true if this schema has the ReadonlyOptional modifier */
|
|
548
|
-
function TReadonlyOptional<T extends TSchema>(schema: T): schema is TReadonlyOptional<T>;
|
|
549
582
|
/** Returns true if this schema has the Readonly modifier */
|
|
550
583
|
function TReadonly<T extends TSchema>(schema: T): schema is TReadonly<T>;
|
|
551
584
|
/** Returns true if this schema has the Optional modifier */
|
|
@@ -634,16 +667,18 @@ export declare namespace TemplateLiteralDslParser {
|
|
|
634
667
|
export declare class TypeBuilder {
|
|
635
668
|
/** `[Utility]` Creates a schema without `static` and `params` types */
|
|
636
669
|
protected Create<T>(schema: Omit<T, 'static' | 'params'>): T;
|
|
670
|
+
/** `[Utility]` Discards a property key from the given schema */
|
|
671
|
+
protected Discard(schema: TSchema, key: PropertyKey): TSchema;
|
|
637
672
|
/** `[Standard]` Omits compositing symbols from this schema */
|
|
638
673
|
Strict<T extends TSchema>(schema: T): T;
|
|
639
674
|
}
|
|
640
675
|
export declare class StandardTypeBuilder extends TypeBuilder {
|
|
641
|
-
/** `[
|
|
642
|
-
|
|
643
|
-
/** `[
|
|
644
|
-
ReadonlyOptional<T extends TSchema>(schema: T): TReadonlyOptional<T>;
|
|
645
|
-
/** `[Modifier]` Creates a Readonly object or property */
|
|
676
|
+
/** `[Standard]` Creates a Readonly and Optional property */
|
|
677
|
+
ReadonlyOptional<T extends TSchema>(schema: T): TReadonly<TOptional<T>>;
|
|
678
|
+
/** `[Standard]` Creates a Readonly property */
|
|
646
679
|
Readonly<T extends TSchema>(schema: T): TReadonly<T>;
|
|
680
|
+
/** `[Standard]` Creates an Optional property */
|
|
681
|
+
Optional<T extends TSchema>(schema: T): TOptional<T>;
|
|
647
682
|
/** `[Standard]` Creates an Any type */
|
|
648
683
|
Any(options?: SchemaOptions): TAny;
|
|
649
684
|
/** `[Standard]` Creates an Array type */
|
|
@@ -731,14 +766,16 @@ export declare class StandardTypeBuilder extends TypeBuilder {
|
|
|
731
766
|
Recursive<T extends TSchema>(callback: (thisType: TThis) => T, options?: SchemaOptions): TRecursive<T>;
|
|
732
767
|
/** `[Standard]` Creates a Ref type. The referenced type must contain a $id */
|
|
733
768
|
Ref<T extends TSchema>(schema: T, options?: SchemaOptions): TRef<T>;
|
|
769
|
+
/** `[Standard]` Creates a Ref type. */
|
|
770
|
+
Ref<T extends TSchema>($ref: string, options?: SchemaOptions): TRef<T>;
|
|
734
771
|
/** `[Standard]` Creates a mapped type where all properties are Required */
|
|
735
772
|
Required<T extends TSchema>(schema: T, options?: SchemaOptions): TRequired<T>;
|
|
736
773
|
/** `[Standard]` Returns a schema array which allows types to compose with the JavaScript spread operator */
|
|
737
774
|
Rest<T extends TSchema>(schema: T): TRest<T>;
|
|
738
775
|
/** `[Standard]` Creates a String type */
|
|
739
776
|
String(options?: StringOptions): TString;
|
|
740
|
-
/** `[
|
|
741
|
-
TemplateLiteral<T extends string>(
|
|
777
|
+
/** `[Standard]` Creates a template literal type from template dsl string */
|
|
778
|
+
TemplateLiteral<T extends string>(templateDsl: T, options?: SchemaOptions): TTemplateLiteralDslParser<T>;
|
|
742
779
|
/** `[Standard]` Creates a template literal type */
|
|
743
780
|
TemplateLiteral<T extends TTemplateLiteralKind[]>(kinds: [...T], options?: SchemaOptions): TTemplateLiteral<T>;
|
|
744
781
|
/** `[Standard]` Creates a Tuple type */
|
|
@@ -757,6 +794,8 @@ export declare class StandardTypeBuilder extends TypeBuilder {
|
|
|
757
794
|
Unsafe<T>(options?: UnsafeOptions): TUnsafe<T>;
|
|
758
795
|
}
|
|
759
796
|
export declare class ExtendedTypeBuilder extends StandardTypeBuilder {
|
|
797
|
+
/** `[Extended]` Creates a AsyncIterator type */
|
|
798
|
+
AsyncIterator<T extends TSchema>(items: T, options?: SchemaOptions): TAsyncIterator<T>;
|
|
760
799
|
/** `[Extended]` Creates a BigInt type */
|
|
761
800
|
BigInt(options?: NumericOptions<bigint>): TBigInt;
|
|
762
801
|
/** `[Extended]` Extracts the ConstructorParameters from the given Constructor type */
|
|
@@ -769,11 +808,19 @@ export declare class ExtendedTypeBuilder extends StandardTypeBuilder {
|
|
|
769
808
|
Function<T extends TSchema[], U extends TSchema>(parameters: [...T], returns: U, options?: SchemaOptions): TFunction<T, U>;
|
|
770
809
|
/** `[Extended]` Extracts the InstanceType from the given Constructor */
|
|
771
810
|
InstanceType<T extends TConstructor<any[], any>>(schema: T, options?: SchemaOptions): TInstanceType<T>;
|
|
811
|
+
/** `[Extended]` Creates an Iterator type */
|
|
812
|
+
Iterator<T extends TSchema>(items: T, options?: SchemaOptions): TIterator<T>;
|
|
772
813
|
/** `[Extended]` Extracts the Parameters from the given Function type */
|
|
773
814
|
Parameters<T extends TFunction<any[], any>>(schema: T, options?: SchemaOptions): TParameters<T>;
|
|
774
815
|
/** `[Extended]` Creates a Promise type */
|
|
775
816
|
Promise<T extends TSchema>(item: T, options?: SchemaOptions): TPromise<T>;
|
|
776
|
-
/** `[Extended]` Creates a
|
|
817
|
+
/** `[Extended]` Creates a String pattern type from Regular Expression */
|
|
818
|
+
RegExp(pattern: string, options?: SchemaOptions): TString;
|
|
819
|
+
/** `[Extended]` Creates a String pattern type from Regular Expression */
|
|
820
|
+
RegExp(regex: RegExp, options?: SchemaOptions): TString;
|
|
821
|
+
/**
|
|
822
|
+
* @deprecated Use `Type.RegExp`
|
|
823
|
+
*/
|
|
777
824
|
RegEx(regex: RegExp, options?: SchemaOptions): TString;
|
|
778
825
|
/** `[Extended]` Extracts the ReturnType from the given Function */
|
|
779
826
|
ReturnType<T extends TFunction<any[], any>>(schema: T, options?: SchemaOptions): TReturnType<T>;
|
|
@@ -786,7 +833,7 @@ export declare class ExtendedTypeBuilder extends StandardTypeBuilder {
|
|
|
786
833
|
/** `[Extended]` Creates a Void type */
|
|
787
834
|
Void(options?: SchemaOptions): TVoid;
|
|
788
835
|
}
|
|
789
|
-
/** JSON Schema
|
|
836
|
+
/** JSON Schema Type Builder with Static Resolution for TypeScript */
|
|
790
837
|
export declare const StandardType: StandardTypeBuilder;
|
|
791
|
-
/** JSON Schema
|
|
838
|
+
/** JSON Schema Type Builder with Static Resolution for TypeScript */
|
|
792
839
|
export declare const Type: ExtendedTypeBuilder;
|