@sinclair/typebox 0.30.0-dev-6 → 0.30.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.
Files changed (3) hide show
  1. package/package.json +1 -1
  2. package/readme.md +1 -1
  3. package/typebox.d.ts +17 -14
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sinclair/typebox",
3
- "version": "0.30.0-dev-6",
3
+ "version": "0.30.0",
4
4
  "description": "JSONSchema Type Builder with Static Type Resolution for TypeScript",
5
5
  "keywords": [
6
6
  "typescript",
package/readme.md CHANGED
@@ -110,7 +110,7 @@ License MIT
110
110
  - [Types](#typesystem-types)
111
111
  - [Formats](#typesystem-formats)
112
112
  - [Policies](#typesystem-policies)
113
- - [Transform](#Transform)
113
+ - [Transform](#transform)
114
114
  - [Ecosystem](#ecosystem)
115
115
  - [Benchmark](#benchmark)
116
116
  - [Compile](#benchmark-compile)
package/typebox.d.ts CHANGED
@@ -43,7 +43,6 @@ export type IntersectType<T extends TSchema[]> = T extends [] ? TNever : T exten
43
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
- export type Key = string | number;
47
46
  export interface SchemaOptions {
48
47
  $schema?: string;
49
48
  /** Id for this schema */
@@ -191,14 +190,14 @@ export interface TFunction<T extends TSchema[] = TSchema[], U extends TSchema =
191
190
  parameters: T;
192
191
  returns: U;
193
192
  }
194
- export type TIndexRest<T extends TSchema[], K extends Key> = T extends [infer L, ...infer R] ? [TIndexType<AssertType<L>, K>, ...TIndexRest<AssertRest<R>, K>] : [];
195
- export type TIndexProperty<T extends TProperties, K extends Key> = K extends keyof T ? [T[K]] : [];
196
- export type TIndexTuple<T extends TSchema[], K extends Key> = K extends keyof T ? [T[K]] : [];
197
- export type TIndexType<T extends TSchema, K extends Key> = T extends TRecursive<infer S> ? TIndexType<S, K> : T extends TIntersect<infer S> ? IntersectType<AssertRest<Discard<Flat<TIndexRest<S, K>>, TNever>>> : T extends TUnion<infer S> ? UnionType<AssertRest<Flat<TIndexRest<S, K>>>> : T extends TObject<infer S> ? UnionType<AssertRest<Flat<TIndexProperty<S, K>>>> : T extends TTuple<infer S> ? UnionType<AssertRest<Flat<TIndexTuple<S, K>>>> : [
193
+ export type TIndexRest<T extends TSchema[], K extends TPropertyKey> = T extends [infer L, ...infer R] ? [TIndexType<AssertType<L>, K>, ...TIndexRest<AssertRest<R>, K>] : [];
194
+ export type TIndexProperty<T extends TProperties, K extends TPropertyKey> = K extends keyof T ? [T[K]] : [];
195
+ export type TIndexTuple<T extends TSchema[], K extends TPropertyKey> = K extends keyof T ? [T[K]] : [];
196
+ export type TIndexType<T extends TSchema, K extends TPropertyKey> = T extends TRecursive<infer S> ? TIndexType<S, K> : T extends TIntersect<infer S> ? IntersectType<AssertRest<Discard<Flat<TIndexRest<S, K>>, TNever>>> : T extends TUnion<infer S> ? UnionType<AssertRest<Flat<TIndexRest<S, K>>>> : T extends TObject<infer S> ? UnionType<AssertRest<Flat<TIndexProperty<S, K>>>> : T extends TTuple<infer S> ? UnionType<AssertRest<Flat<TIndexTuple<S, K>>>> : [
198
197
  ];
199
- export type TIndexRestMany<T extends TSchema, K extends Key[]> = K extends [infer L, ...infer R] ? [TIndexType<T, Assert<L, Key>>, ...TIndexRestMany<T, Assert<R, Key[]>>] : [
198
+ export type TIndexRestMany<T extends TSchema, K extends TPropertyKey[]> = K extends [infer L, ...infer R] ? [TIndexType<T, Assert<L, TPropertyKey>>, ...TIndexRestMany<T, Assert<R, TPropertyKey[]>>] : [
200
199
  ];
201
- export type TIndex<T extends TSchema, K extends Key[]> = T extends TRecursive<infer S> ? TIndex<S, K> : T extends TIntersect ? UnionType<Flat<TIndexRestMany<T, K>>> : T extends TUnion ? UnionType<Flat<TIndexRestMany<T, K>>> : T extends TObject ? UnionType<Flat<TIndexRestMany<T, K>>> : T extends TTuple ? UnionType<Flat<TIndexRestMany<T, K>>> : TNever;
200
+ export type TIndex<T extends TSchema, K extends TPropertyKey[]> = T extends TRecursive<infer S> ? TIndex<S, K> : T extends TIntersect ? UnionType<Flat<TIndexRestMany<T, K>>> : T extends TUnion ? UnionType<Flat<TIndexRestMany<T, K>>> : T extends TObject ? UnionType<Flat<TIndexRestMany<T, K>>> : T extends TTuple ? UnionType<Flat<TIndexRestMany<T, K>>> : TNever;
202
201
  export interface TInteger extends TSchema, NumericOptions<number> {
203
202
  [Kind]: 'Integer';
204
203
  static: number;
@@ -231,7 +230,10 @@ export type TKeyOfIndices<T extends TSchema[]> = AssertRest<TKeyOfIndicesArray<T
231
230
  } : []>;
232
231
  export type TKeyOf<T extends TSchema = TSchema> = (T extends TRecursive<infer S> ? TKeyOfProperties<S> : T extends TIntersect ? TKeyOfProperties<T> : T extends TUnion ? TKeyOfProperties<T> : T extends TObject ? TKeyOfProperties<T> : T extends TTuple<infer K> ? TKeyOfIndices<K> : T extends TArray ? [TNumber] : T extends TRecord<infer K> ? [K] : [
233
232
  ]) extends infer R ? UnionType<AssertRest<R>> : never;
234
- export type TLiteralValue = string | number | boolean;
233
+ export type TLiteralValue = boolean | number | string;
234
+ export type TLiteralBoolean = TLiteral<boolean>;
235
+ export type TLiteralNumber = TLiteral<number>;
236
+ export type TLiteralString = TLiteral<string>;
235
237
  export interface TLiteral<T extends TLiteralValue = TLiteralValue> extends TSchema {
236
238
  [Kind]: 'Literal';
237
239
  static: T;
@@ -271,7 +273,8 @@ export type PropertiesReducer<T extends TProperties, R extends Record<keyof any,
271
273
  export type PropertiesReduce<T extends TProperties, P extends unknown[]> = PropertiesReducer<T, {
272
274
  [K in keyof T]: Static<T[K], P>;
273
275
  }>;
274
- export type TProperties = Record<keyof any, TSchema>;
276
+ export type TPropertyKey = string | number;
277
+ export type TProperties = Record<TPropertyKey, TSchema>;
275
278
  export type ObjectProperties<T> = T extends TObject<infer U> ? U : never;
276
279
  export type ObjectPropertyKeys<T> = T extends TObject<infer U> ? keyof U : never;
277
280
  export type TAdditionalProperties = undefined | TSchema | boolean;
@@ -405,7 +408,7 @@ export type TTemplateLiteralConst<T, Acc extends string> = T extends TUnion<infe
405
408
  [K in keyof U]: TTemplateLiteralUnion<Assert<[U[K]], TTemplateLiteralKind[]>, Acc>;
406
409
  }[number] : T extends TTemplateLiteral ? `${Static<T>}` : T extends TLiteral<infer U> ? `${U}` : T extends TString ? `${string}` : T extends TNumber ? `${number}` : T extends TBigInt ? `${bigint}` : T extends TBoolean ? `${boolean}` : never;
407
410
  export type TTemplateLiteralUnion<T extends TTemplateLiteralKind[], Acc extends string = ''> = T extends [infer L, ...infer R] ? `${TTemplateLiteralConst<L, Acc>}${TTemplateLiteralUnion<Assert<R, TTemplateLiteralKind[]>, Acc>}` : Acc;
408
- export type TTemplateLiteralKeyRest<T extends TTemplateLiteral> = Assert<UnionToTuple<Static<T>>, Key[]>;
411
+ export type TTemplateLiteralKeyRest<T extends TTemplateLiteral> = Assert<UnionToTuple<Static<T>>, TPropertyKey[]>;
409
412
  export interface TTemplateLiteral<T extends TTemplateLiteralKind[] = TTemplateLiteralKind[]> extends TSchema {
410
413
  [Kind]: 'TemplateLiteral';
411
414
  static: TTemplateLiteralUnion<T>;
@@ -621,7 +624,7 @@ export declare namespace TypeClone {
621
624
  function Clone<T extends TSchema>(schema: T, options?: SchemaOptions): T;
622
625
  }
623
626
  export declare namespace IndexedAccessor {
624
- function Resolve(schema: TSchema, keys: Key[], options?: SchemaOptions): TSchema;
627
+ function Resolve(schema: TSchema, keys: TPropertyKey[], options?: SchemaOptions): TSchema;
625
628
  }
626
629
  export declare namespace ObjectMap {
627
630
  function Map<T = TSchema>(schema: TSchema, callback: (object: TObject) => TObject, options: SchemaOptions): T;
@@ -721,11 +724,11 @@ export declare class StandardTypeBuilder extends TypeBuilder {
721
724
  /** `[Standard]` Returns an Indexed property type for the given keys */
722
725
  Index<T extends TSchema, K extends TTemplateLiteral>(schema: T, keys: K, options?: SchemaOptions): TIndex<T, TTemplateLiteralKeyRest<K>>;
723
726
  /** `[Standard]` Returns an Indexed property type for the given keys */
724
- Index<T extends TSchema, K extends TLiteral<Key>>(schema: T, keys: K, options?: SchemaOptions): TIndex<T, [K['const']]>;
727
+ Index<T extends TSchema, K extends TLiteral<TPropertyKey>>(schema: T, keys: K, options?: SchemaOptions): TIndex<T, [K['const']]>;
725
728
  /** `[Standard]` Returns an Indexed property type for the given keys */
726
- Index<T extends TSchema, K extends (keyof Static<T>)[]>(schema: T, keys: [...K], options?: SchemaOptions): TIndex<T, Assert<K, Key[]>>;
729
+ Index<T extends TSchema, K extends (keyof Static<T>)[]>(schema: T, keys: [...K], options?: SchemaOptions): TIndex<T, Assert<K, TPropertyKey[]>>;
727
730
  /** `[Standard]` Returns an Indexed property type for the given keys */
728
- Index<T extends TSchema, K extends TUnion<TLiteral<Key>[]>>(schema: T, keys: K, options?: SchemaOptions): TIndex<T, TUnionLiteralKeyRest<K>>;
731
+ Index<T extends TSchema, K extends TUnion<TLiteral<TPropertyKey>[]>>(schema: T, keys: K, options?: SchemaOptions): TIndex<T, TUnionLiteralKeyRest<K>>;
729
732
  /** `[Standard]` Returns an Indexed property type for the given keys */
730
733
  Index<T extends TSchema, K extends TSchema>(schema: T, key: K, options?: SchemaOptions): TSchema;
731
734
  /** `[Standard]` Creates an Integer type */