@sinclair/typebox 0.27.6 → 0.27.8
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/typebox.d.ts +6 -5
- package/typebox.js +10 -4
package/package.json
CHANGED
package/typebox.d.ts
CHANGED
|
@@ -183,7 +183,7 @@ export type TKeyOfTuple<T extends TSchema> = {
|
|
|
183
183
|
} extends infer U ? UnionToTuple<Exclude<{
|
|
184
184
|
[K in keyof U]: U[K];
|
|
185
185
|
}[keyof U], undefined>> : never;
|
|
186
|
-
export type TKeyOf<T extends TSchema = TSchema> = (T extends
|
|
186
|
+
export type TKeyOf<T extends TSchema = TSchema> = (T extends TRecursive<infer S> ? TKeyOfTuple<S> : T extends TComposite ? TKeyOfTuple<T> : T extends TIntersect ? TKeyOfTuple<T> : T extends TUnion ? TKeyOfTuple<T> : T extends TObject ? TKeyOfTuple<T> : T extends TRecord<infer K> ? [K] : [
|
|
187
187
|
]) extends infer R ? TUnionResult<Assert<R, TSchema[]>> : never;
|
|
188
188
|
export type TLiteralValue = string | number | boolean;
|
|
189
189
|
export interface TLiteral<T extends TLiteralValue = TLiteralValue> extends TSchema {
|
|
@@ -248,7 +248,7 @@ export type TOmitArray<T extends TSchema[], K extends keyof any> = Assert<{
|
|
|
248
248
|
[K2 in keyof T]: TOmit<Assert<T[K2], TSchema>, K>;
|
|
249
249
|
}, TSchema[]>;
|
|
250
250
|
export type TOmitProperties<T extends TProperties, K extends keyof any> = Evaluate<Assert<Omit<T, K>, TProperties>>;
|
|
251
|
-
export type TOmit<T extends TSchema = TSchema, K extends keyof any = keyof any> = T extends TComposite<infer S> ? TComposite<TOmitArray<S, K>> : T extends TIntersect<infer S> ? TIntersect<TOmitArray<S, K>> : T extends TUnion<infer S> ? TUnion<TOmitArray<S, K>> : T extends TObject<infer S> ? TObject<TOmitProperties<S, K>> : T;
|
|
251
|
+
export type TOmit<T extends TSchema = TSchema, K extends keyof any = keyof any> = T extends TRecursive<infer S> ? TRecursive<TOmit<S, K>> : T extends TComposite<infer S> ? TComposite<TOmitArray<S, K>> : T extends TIntersect<infer S> ? TIntersect<TOmitArray<S, K>> : T extends TUnion<infer S> ? TUnion<TOmitArray<S, K>> : T extends TObject<infer S> ? TObject<TOmitProperties<S, K>> : T;
|
|
252
252
|
export type TParameters<T extends TFunction> = TTuple<T['parameters']>;
|
|
253
253
|
export type TPartialObjectArray<T extends TObject[]> = Assert<{
|
|
254
254
|
[K in keyof T]: TPartial<Assert<T[K], TObject>>;
|
|
@@ -259,14 +259,14 @@ export type TPartialArray<T extends TSchema[]> = Assert<{
|
|
|
259
259
|
export type TPartialProperties<T extends TProperties> = Evaluate<Assert<{
|
|
260
260
|
[K in keyof T]: T[K] extends TReadonlyOptional<infer U> ? TReadonlyOptional<U> : T[K] extends TReadonly<infer U> ? TReadonlyOptional<U> : T[K] extends TOptional<infer U> ? TOptional<U> : TOptional<T[K]>;
|
|
261
261
|
}, TProperties>>;
|
|
262
|
-
export type TPartial<T extends TSchema> = T extends TComposite<infer S> ? TComposite<TPartialArray<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;
|
|
262
|
+
export type TPartial<T extends TSchema> = T extends TRecursive<infer S> ? TRecursive<TPartial<S>> : T extends TComposite<infer S> ? TComposite<TPartialArray<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;
|
|
263
263
|
export type TPickArray<T extends TSchema[], K extends keyof any> = {
|
|
264
264
|
[K2 in keyof T]: TPick<Assert<T[K2], TSchema>, K>;
|
|
265
265
|
};
|
|
266
266
|
export type TPickProperties<T extends TProperties, K extends keyof any> = Pick<T, Assert<Extract<K, keyof T>, keyof T>> extends infer R ? ({
|
|
267
267
|
[K in keyof R]: Assert<R[K], TSchema> extends TSchema ? R[K] : never;
|
|
268
268
|
}) : never;
|
|
269
|
-
export type TPick<T extends TSchema = TSchema, K extends keyof any = keyof any> = T extends TComposite<infer S> ? TComposite<TPickArray<S, K>> : T extends TIntersect<infer S> ? TIntersect<TPickArray<S, K>> : T extends TUnion<infer S> ? TUnion<TPickArray<S, K>> : T extends TObject<infer S> ? TObject<TPickProperties<S, K>> : T;
|
|
269
|
+
export type TPick<T extends TSchema = TSchema, K extends keyof any = keyof any> = T extends TRecursive<infer S> ? TRecursive<TPick<S, K>> : T extends TComposite<infer S> ? TComposite<TPickArray<S, K>> : T extends TIntersect<infer S> ? TIntersect<TPickArray<S, K>> : T extends TUnion<infer S> ? TUnion<TPickArray<S, K>> : T extends TObject<infer S> ? TObject<TPickProperties<S, K>> : T;
|
|
270
270
|
export interface TPromise<T extends TSchema = TSchema> extends TSchema {
|
|
271
271
|
[Kind]: 'Promise';
|
|
272
272
|
static: Promise<Static<T, this['params']>>;
|
|
@@ -303,6 +303,7 @@ export interface TThis extends TSchema {
|
|
|
303
303
|
}
|
|
304
304
|
export type TRecursiveReduce<T extends TSchema> = Static<T, [TRecursiveReduce<T>]>;
|
|
305
305
|
export interface TRecursive<T extends TSchema> extends TSchema {
|
|
306
|
+
[Hint]: 'Recursive';
|
|
306
307
|
static: TRecursiveReduce<T>;
|
|
307
308
|
}
|
|
308
309
|
export interface TRef<T extends TSchema = TSchema> extends TSchema {
|
|
@@ -317,7 +318,7 @@ export type TRequiredArray<T extends TSchema[]> = Assert<{
|
|
|
317
318
|
export type TRequiredProperties<T extends TProperties> = Evaluate<Assert<{
|
|
318
319
|
[K in keyof T]: T[K] extends TReadonlyOptional<infer U> ? TReadonly<U> : T[K] extends TReadonly<infer U> ? TReadonly<U> : T[K] extends TOptional<infer U> ? U : T[K];
|
|
319
320
|
}, TProperties>>;
|
|
320
|
-
export type TRequired<T extends TSchema> = T extends TComposite<infer S> ? TComposite<TRequiredArray<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;
|
|
321
|
+
export type TRequired<T extends TSchema> = T extends TRecursive<infer S> ? TRecursive<TRequired<S>> : T extends TComposite<infer S> ? TComposite<TRequiredArray<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;
|
|
321
322
|
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';
|
|
322
323
|
export interface StringOptions<Format extends string> extends SchemaOptions {
|
|
323
324
|
minLength?: number;
|
package/typebox.js
CHANGED
|
@@ -1394,20 +1394,26 @@ var TypeClone;
|
|
|
1394
1394
|
var ObjectMap;
|
|
1395
1395
|
(function (ObjectMap) {
|
|
1396
1396
|
function Intersect(schema, callback) {
|
|
1397
|
+
// prettier-ignore
|
|
1397
1398
|
return exports.Type.Intersect(schema.allOf.map((inner) => Visit(inner, callback)), { ...schema });
|
|
1398
1399
|
}
|
|
1399
1400
|
function Union(schema, callback) {
|
|
1401
|
+
// prettier-ignore
|
|
1400
1402
|
return exports.Type.Union(schema.anyOf.map((inner) => Visit(inner, callback)), { ...schema });
|
|
1401
1403
|
}
|
|
1402
1404
|
function Object(schema, callback) {
|
|
1403
1405
|
return callback(schema);
|
|
1404
1406
|
}
|
|
1405
1407
|
function Visit(schema, callback) {
|
|
1406
|
-
|
|
1408
|
+
// There are cases where users need to map objects with unregistered kinds. Using a TypeGuard here would
|
|
1409
|
+
// prevent sub schema mapping as unregistered kinds will not pass TSchema checks. This is notable in the
|
|
1410
|
+
// case of TObject where unregistered property kinds cause the TObject check to fail. As mapping is only
|
|
1411
|
+
// used for composition, we use explicit checks instead.
|
|
1412
|
+
if (schema[exports.Kind] === 'Intersect')
|
|
1407
1413
|
return Intersect(schema, callback);
|
|
1408
|
-
if (
|
|
1414
|
+
if (schema[exports.Kind] === 'Union')
|
|
1409
1415
|
return Union(schema, callback);
|
|
1410
|
-
if (
|
|
1416
|
+
if (schema[exports.Kind] === 'Object')
|
|
1411
1417
|
return Object(schema, callback);
|
|
1412
1418
|
return schema;
|
|
1413
1419
|
}
|
|
@@ -2049,7 +2055,7 @@ class StandardTypeBuilder extends TypeBuilder {
|
|
|
2049
2055
|
options.$id = `T${TypeOrdinal++}`;
|
|
2050
2056
|
const thisType = callback({ [exports.Kind]: 'This', $ref: `${options.$id}` });
|
|
2051
2057
|
thisType.$id = options.$id;
|
|
2052
|
-
return this.Create({ ...options, ...thisType });
|
|
2058
|
+
return this.Create({ ...options, [exports.Hint]: 'Recursive', ...thisType });
|
|
2053
2059
|
}
|
|
2054
2060
|
/** `[Standard]` Creates a Ref type. The referenced type must contain a $id */
|
|
2055
2061
|
Ref(schema, options = {}) {
|