@sinclair/typebox 0.32.16 → 0.32.18

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.
@@ -1,3 +1,4 @@
1
+ import { type TUnsafe } from '../type/unsafe/index.mjs';
1
2
  import { TypeBoxError } from '../type/error/index.mjs';
2
3
  export declare class TypeSystemDuplicateTypeKind extends TypeBoxError {
3
4
  constructor(kind: string);
@@ -5,10 +6,11 @@ export declare class TypeSystemDuplicateTypeKind extends TypeBoxError {
5
6
  export declare class TypeSystemDuplicateFormat extends TypeBoxError {
6
7
  constructor(kind: string);
7
8
  }
9
+ export type TypeFactoryFunction<Type, Options = Record<PropertyKey, unknown>> = (options?: Partial<Options>) => TUnsafe<Type>;
8
10
  /** Creates user defined types and formats and provides overrides for value checking behaviours */
9
11
  export declare namespace TypeSystem {
10
12
  /** Creates a new type */
11
- function Type<Type, Options = Record<PropertyKey, unknown>>(kind: string, check: (options: Options, value: unknown) => boolean): (options?: Partial<Options>) => import("src/type/unsafe/unsafe.mjs").TUnsafe<Type>;
13
+ function Type<Type, Options = Record<PropertyKey, unknown>>(kind: string, check: (options: Options, value: unknown) => boolean): TypeFactoryFunction<Type, Options>;
12
14
  /** Creates a new string format */
13
15
  function Format<F extends string>(format: F, check: (value: string) => boolean): F;
14
16
  }
@@ -15,9 +15,6 @@ export class TypeSystemDuplicateFormat extends TypeBoxError {
15
15
  super(`Duplicate string format '${kind}' detected`);
16
16
  }
17
17
  }
18
- // ------------------------------------------------------------------
19
- // TypeSystem
20
- // ------------------------------------------------------------------
21
18
  /** Creates user defined types and formats and provides overrides for value checking behaviours */
22
19
  export var TypeSystem;
23
20
  (function (TypeSystem) {
@@ -24,8 +24,9 @@ export type TDecodeProperties<T extends TProperties> = {
24
24
  };
25
25
  export type TDecodeRest<T extends TSchema[], Acc extends TSchema[] = []> = T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TDecodeRest<R, [...Acc, TDecodeType<L>]> : Acc;
26
26
  export type TDecodeType<T extends TSchema> = (T extends TOptional<infer S extends TSchema> ? TOptional<TDecodeType<S>> : T extends TReadonly<infer S extends TSchema> ? TReadonly<TDecodeType<S>> : T extends TTransform<infer _, infer R> ? TUnsafe<R> : T extends TArray<infer S extends TSchema> ? TArray<TDecodeType<S>> : T extends TAsyncIterator<infer S extends TSchema> ? TAsyncIterator<TDecodeType<S>> : T extends TConstructor<infer P extends TSchema[], infer R extends TSchema> ? TConstructor<TDecodeRest<P>, TDecodeType<R>> : T extends TEnum<infer S> ? TEnum<S> : T extends TFunction<infer P extends TSchema[], infer R extends TSchema> ? TFunction<TDecodeRest<P>, TDecodeType<R>> : T extends TIntersect<infer S extends TSchema[]> ? TIntersect<TDecodeRest<S>> : T extends TIterator<infer S extends TSchema> ? TIterator<TDecodeType<S>> : T extends TNot<infer S extends TSchema> ? TNot<TDecodeType<S>> : T extends TObject<infer S> ? TObject<Evaluate<TDecodeProperties<S>>> : T extends TPromise<infer S extends TSchema> ? TPromise<TDecodeType<S>> : T extends TRecord<infer K, infer S> ? TRecord<K, TDecodeType<S>> : T extends TRecursive<infer S extends TSchema> ? TRecursive<TDecodeType<S>> : T extends TRef<infer S extends TSchema> ? TRef<TDecodeType<S>> : T extends TTuple<infer S extends TSchema[]> ? TTuple<TDecodeRest<S>> : T extends TUnion<infer S extends TSchema[]> ? TUnion<TDecodeRest<S>> : T);
27
+ export type StaticDecodeIsAny<T> = boolean extends (T extends TSchema ? true : false) ? true : false;
27
28
  /** Creates an decoded static type from a TypeBox type */
28
- export type StaticDecode<T extends TSchema, P extends unknown[] = []> = Static<TDecodeType<T>, P>;
29
+ export type StaticDecode<T extends TSchema, P extends unknown[] = []> = StaticDecodeIsAny<T> extends true ? unknown : Static<TDecodeType<T>, P>;
29
30
  /** Creates an encoded static type from a TypeBox type */
30
31
  export type StaticEncode<T extends TSchema, P extends unknown[] = []> = Static<T, P>;
31
32
  /** Creates a static type from a TypeBox type */
@@ -1,3 +1,4 @@
1
+ import { type TUnsafe } from '../type/unsafe/index';
1
2
  import { TypeBoxError } from '../type/error/index';
2
3
  export declare class TypeSystemDuplicateTypeKind extends TypeBoxError {
3
4
  constructor(kind: string);
@@ -5,10 +6,11 @@ export declare class TypeSystemDuplicateTypeKind extends TypeBoxError {
5
6
  export declare class TypeSystemDuplicateFormat extends TypeBoxError {
6
7
  constructor(kind: string);
7
8
  }
9
+ export type TypeFactoryFunction<Type, Options = Record<PropertyKey, unknown>> = (options?: Partial<Options>) => TUnsafe<Type>;
8
10
  /** Creates user defined types and formats and provides overrides for value checking behaviours */
9
11
  export declare namespace TypeSystem {
10
12
  /** Creates a new type */
11
- function Type<Type, Options = Record<PropertyKey, unknown>>(kind: string, check: (options: Options, value: unknown) => boolean): (options?: Partial<Options>) => import("src/type/unsafe/unsafe").TUnsafe<Type>;
13
+ function Type<Type, Options = Record<PropertyKey, unknown>>(kind: string, check: (options: Options, value: unknown) => boolean): TypeFactoryFunction<Type, Options>;
12
14
  /** Creates a new string format */
13
15
  function Format<F extends string>(format: F, check: (value: string) => boolean): F;
14
16
  }
@@ -21,9 +21,6 @@ class TypeSystemDuplicateFormat extends index_4.TypeBoxError {
21
21
  }
22
22
  }
23
23
  exports.TypeSystemDuplicateFormat = TypeSystemDuplicateFormat;
24
- // ------------------------------------------------------------------
25
- // TypeSystem
26
- // ------------------------------------------------------------------
27
24
  /** Creates user defined types and formats and provides overrides for value checking behaviours */
28
25
  var TypeSystem;
29
26
  (function (TypeSystem) {
@@ -24,8 +24,9 @@ export type TDecodeProperties<T extends TProperties> = {
24
24
  };
25
25
  export type TDecodeRest<T extends TSchema[], Acc extends TSchema[] = []> = T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TDecodeRest<R, [...Acc, TDecodeType<L>]> : Acc;
26
26
  export type TDecodeType<T extends TSchema> = (T extends TOptional<infer S extends TSchema> ? TOptional<TDecodeType<S>> : T extends TReadonly<infer S extends TSchema> ? TReadonly<TDecodeType<S>> : T extends TTransform<infer _, infer R> ? TUnsafe<R> : T extends TArray<infer S extends TSchema> ? TArray<TDecodeType<S>> : T extends TAsyncIterator<infer S extends TSchema> ? TAsyncIterator<TDecodeType<S>> : T extends TConstructor<infer P extends TSchema[], infer R extends TSchema> ? TConstructor<TDecodeRest<P>, TDecodeType<R>> : T extends TEnum<infer S> ? TEnum<S> : T extends TFunction<infer P extends TSchema[], infer R extends TSchema> ? TFunction<TDecodeRest<P>, TDecodeType<R>> : T extends TIntersect<infer S extends TSchema[]> ? TIntersect<TDecodeRest<S>> : T extends TIterator<infer S extends TSchema> ? TIterator<TDecodeType<S>> : T extends TNot<infer S extends TSchema> ? TNot<TDecodeType<S>> : T extends TObject<infer S> ? TObject<Evaluate<TDecodeProperties<S>>> : T extends TPromise<infer S extends TSchema> ? TPromise<TDecodeType<S>> : T extends TRecord<infer K, infer S> ? TRecord<K, TDecodeType<S>> : T extends TRecursive<infer S extends TSchema> ? TRecursive<TDecodeType<S>> : T extends TRef<infer S extends TSchema> ? TRef<TDecodeType<S>> : T extends TTuple<infer S extends TSchema[]> ? TTuple<TDecodeRest<S>> : T extends TUnion<infer S extends TSchema[]> ? TUnion<TDecodeRest<S>> : T);
27
+ export type StaticDecodeIsAny<T> = boolean extends (T extends TSchema ? true : false) ? true : false;
27
28
  /** Creates an decoded static type from a TypeBox type */
28
- export type StaticDecode<T extends TSchema, P extends unknown[] = []> = Static<TDecodeType<T>, P>;
29
+ export type StaticDecode<T extends TSchema, P extends unknown[] = []> = StaticDecodeIsAny<T> extends true ? unknown : Static<TDecodeType<T>, P>;
29
30
  /** Creates an encoded static type from a TypeBox type */
30
31
  export type StaticEncode<T extends TSchema, P extends unknown[] = []> = Static<T, P>;
31
32
  /** Creates a static type from a TypeBox type */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sinclair/typebox",
3
- "version": "0.32.16",
3
+ "version": "0.32.18",
4
4
  "description": "Json Schema Type Builder with Static Type Resolution for TypeScript",
5
5
  "keywords": [
6
6
  "typescript",