@sinclair/typebox 0.31.21 → 0.31.23
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 +1 -1
- package/typebox.d.ts +6 -4
- package/typebox.js +2 -0
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -1608,10 +1608,10 @@ The following is a list of community packages that offer general tooling, extend
|
|
|
1608
1608
|
| [feathersjs](https://github.com/feathersjs/feathers) | The API and real-time application framework |
|
|
1609
1609
|
| [fetch-typebox](https://github.com/erfanium/fetch-typebox) | Drop-in replacement for fetch that brings easy integration with TypeBox |
|
|
1610
1610
|
| [h3-typebox](https://github.com/kevinmarrec/h3-typebox) | Schema validation utilities for h3 using TypeBox & Ajv |
|
|
1611
|
+
| [http-wizard](https://github.com/flodlc/http-wizard) | Type safe http client library for Fastify |
|
|
1611
1612
|
| [openapi-box](https://github.com/geut/openapi-box) | Generate TypeBox types from OpenApi IDL + Http client library |
|
|
1612
1613
|
| [schema2typebox](https://github.com/xddq/schema2typebox) | Creating TypeBox code from Json Schemas |
|
|
1613
1614
|
| [ts2typebox](https://github.com/xddq/ts2typebox) | Creating TypeBox code from Typescript types |
|
|
1614
|
-
| [typebox-client](https://github.com/flodlc/typebox-client) | Type safe http client library for Fastify |
|
|
1615
1615
|
| [typebox-form-parser](https://github.com/jtlapp/typebox-form-parser) | Parses form and query data based on TypeBox schemas |
|
|
1616
1616
|
| [typebox-validators](https://github.com/jtlapp/typebox-validators) | Advanced validators supporting discriminated and heterogeneous unions |
|
|
1617
1617
|
|
package/typebox.d.ts
CHANGED
|
@@ -315,7 +315,7 @@ export type TPartialRest<T extends TSchema[]> = AssertRest<{
|
|
|
315
315
|
[K in keyof T]: TPartial<AssertType<T[K]>>;
|
|
316
316
|
}>;
|
|
317
317
|
export type TPartialProperties<T extends TProperties> = Evaluate<AssertProperties<{
|
|
318
|
-
[K in keyof T]: TOptional<T[K]>;
|
|
318
|
+
[K in keyof T]: T[K] extends (TReadonlyOptional<infer S>) ? TReadonlyOptional<S> : T[K] extends (TReadonly<infer S>) ? TReadonlyOptional<S> : T[K] extends (TOptional<infer S>) ? TOptional<S> : TOptional<T[K]>;
|
|
319
319
|
}>>;
|
|
320
320
|
export type TPartial<T extends TSchema> = T extends TRecursive<infer S> ? TRecursive<TPartial<S>> : T extends TIntersect<infer S> ? TIntersect<TPartialRest<S>> : T extends TUnion<infer S> ? TUnion<TPartialRest<S>> : T extends TObject<infer S> ? TObject<TPartialProperties<S>> : T;
|
|
321
321
|
export type TPickProperties<T extends TProperties, K extends keyof any> = Pick<T, Assert<Extract<K, keyof T>, keyof T>> extends infer R ? ({
|
|
@@ -337,7 +337,9 @@ export type TRecordFromUnionLiteralString<K extends TLiteralString, T extends TS
|
|
|
337
337
|
export type TRecordFromUnionLiteralNumber<K extends TLiteralNumber, T extends TSchema> = {
|
|
338
338
|
[_ in K['const']]: T;
|
|
339
339
|
};
|
|
340
|
-
export type TRecordFromEnumKey<K extends
|
|
340
|
+
export type TRecordFromEnumKey<K extends Record<string, string | number>, T extends TSchema> = Ensure<TObject<{
|
|
341
|
+
[_ in K[keyof K]]: T;
|
|
342
|
+
}>>;
|
|
341
343
|
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> : {}) : {};
|
|
342
344
|
export type TRecordFromUnion<K extends TSchema[], T extends TSchema> = Ensure<TObject<AssertProperties<Evaluate<TRecordFromUnionRest<K, T>>>>>;
|
|
343
345
|
export type TRecordFromTemplateLiteralKeyInfinite<K extends TTemplateLiteral, T extends TSchema> = Ensure<TRecord<K, T>>;
|
|
@@ -354,7 +356,7 @@ export type TRecordFromLiteralNumberKey<K extends TLiteralNumber, T extends TSch
|
|
|
354
356
|
export type TRecordFromStringKey<K extends TString, T extends TSchema> = Ensure<TRecord<K, T>>;
|
|
355
357
|
export type TRecordFromNumberKey<K extends TNumber, T extends TSchema> = Ensure<TRecord<K, T>>;
|
|
356
358
|
export type TRecordFromIntegerKey<K extends TInteger, T extends TSchema> = Ensure<TRecord<K, T>>;
|
|
357
|
-
export type TRecordResolve<K extends TSchema, T extends TSchema> = K extends TEnum<infer
|
|
359
|
+
export type TRecordResolve<K extends TSchema, T extends TSchema> = K extends TEnum<infer S> ? TRecordFromEnumKey<S, T> : 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;
|
|
358
360
|
export interface TRecord<K extends TSchema = TSchema, T extends TSchema = TSchema> extends TSchema {
|
|
359
361
|
[Kind]: 'Record';
|
|
360
362
|
static: Record<Assert<Static<K>, string | number>, Static<T, this['params']>>;
|
|
@@ -385,7 +387,7 @@ export type TRequiredRest<T extends TSchema[]> = AssertRest<{
|
|
|
385
387
|
[K in keyof T]: TRequired<AssertType<T[K]>>;
|
|
386
388
|
}>;
|
|
387
389
|
export type TRequiredProperties<T extends TProperties> = Evaluate<AssertProperties<{
|
|
388
|
-
[K in keyof T]: T[K] extends TOptional<infer S> ? S : T[K];
|
|
390
|
+
[K in keyof T]: T[K] extends (TReadonlyOptional<infer S>) ? TReadonly<S> : T[K] extends (TReadonly<infer S>) ? TReadonly<S> : T[K] extends (TOptional<infer S>) ? S : T[K];
|
|
389
391
|
}>>;
|
|
390
392
|
export type TRequired<T extends TSchema> = T extends TRecursive<infer S> ? TRecursive<TRequired<S>> : T extends TIntersect<infer S> ? TIntersect<TRequiredRest<S>> : T extends TUnion<infer S> ? TUnion<TRequiredRest<S>> : T extends TObject<infer S> ? TObject<TRequiredProperties<S>> : T;
|
|
391
393
|
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);
|
package/typebox.js
CHANGED
|
@@ -1941,6 +1941,8 @@ class JsonTypeBuilder extends TypeBuilder {
|
|
|
1941
1941
|
}
|
|
1942
1942
|
/** `[Json]` Creates a Enum type */
|
|
1943
1943
|
Enum(item, options = {}) {
|
|
1944
|
+
if (ValueGuard.IsUndefined(item))
|
|
1945
|
+
return this.Throw('Enum undefined or empty');
|
|
1944
1946
|
// prettier-ignore
|
|
1945
1947
|
const values1 = Object.getOwnPropertyNames(item).filter((key) => isNaN(key)).map((key) => item[key]);
|
|
1946
1948
|
const values2 = [...new Set(values1)];
|