typebox 1.0.14 → 1.0.16

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,9 +1,9 @@
1
1
  import { type StaticDirection, type StaticType } from './static.mjs';
2
2
  import { type TSchema } from './schema.mjs';
3
3
  import { type TProperties } from './properties.mjs';
4
- export type StaticCodec<Direction extends StaticDirection, Context extends TProperties, This extends TProperties, Type extends TSchema, Decoded extends unknown> = Direction extends 'Decode' ? Decoded : StaticType<Direction, Context, This, Type>;
5
- export type TDecodeCallback<Type extends TSchema, Decoded = unknown> = (input: StaticType<'Decode', {}, {}, Type>) => Decoded;
6
- export type TEncodeCallback<Type extends TSchema, Decoded = unknown> = (input: Decoded) => StaticType<'Decode', {}, {}, Type>;
4
+ export type StaticCodec<Stack extends string[], Direction extends StaticDirection, Context extends TProperties, This extends TProperties, Type extends TSchema, Decoded extends unknown> = Direction extends 'Decode' ? Decoded : StaticType<Stack, Direction, Context, This, Type>;
5
+ export type TDecodeCallback<Type extends TSchema, Decoded = unknown> = (input: StaticType<[], 'Decode', {}, {}, Type>) => Decoded;
6
+ export type TEncodeCallback<Type extends TSchema, Decoded = unknown> = (input: Decoded) => StaticType<[], 'Decode', {}, {}, Type>;
7
7
  export type TCodec<Type extends TSchema = TSchema, Decoded extends unknown = unknown> = Type & {
8
8
  '~codec': {
9
9
  encode: TDecodeCallback<Type, Decoded>;
@@ -1,7 +1,7 @@
1
1
  import { type StaticType, type StaticDirection } from './static.mjs';
2
2
  import { type TSchema, type TArrayOptions } from './schema.mjs';
3
3
  import { type TProperties } from './properties.mjs';
4
- export type StaticArray<Direction extends StaticDirection, Context extends TProperties, This extends TProperties, Type extends TSchema, Result = StaticType<Direction, Context, This, Type>[]> = Result;
4
+ export type StaticArray<Stack extends string[], Direction extends StaticDirection, Context extends TProperties, This extends TProperties, Type extends TSchema, Result extends unknown[] = StaticType<Stack, Direction, Context, This, Type>[]> = Result;
5
5
  /** Represents an Array type. */
6
6
  export interface TArray<Type extends TSchema = TSchema> extends TSchema {
7
7
  '~kind': 'Array';
@@ -1,7 +1,7 @@
1
1
  import { type StaticType, type StaticDirection } from './static.mjs';
2
2
  import { type TSchema, type TSchemaOptions } from './schema.mjs';
3
3
  import { type TProperties } from './properties.mjs';
4
- export type StaticAsyncIterator<Direction extends StaticDirection, Context extends TProperties, This extends TProperties, Type extends TSchema, Result = AsyncIterableIterator<StaticType<Direction, Context, This, Type>>> = Result;
4
+ export type StaticAsyncIterator<Stack extends string[], Direction extends StaticDirection, Context extends TProperties, This extends TProperties, Type extends TSchema, Result = AsyncIterableIterator<StaticType<Stack, Direction, Context, This, Type>>> = Result;
5
5
  /** Represents a AsyncIterator. */
6
6
  export interface TAsyncIterator<Type extends TSchema = TSchema> extends TSchema {
7
7
  '~kind': 'AsyncIterator';
@@ -2,7 +2,7 @@ import { type StaticType, type StaticDirection } from './static.mjs';
2
2
  import { type TSchema, type TSchemaOptions } from './schema.mjs';
3
3
  import { type StaticInstantiatedParameters } from './function.mjs';
4
4
  import { type TProperties } from './properties.mjs';
5
- export type StaticConstructor<Direction extends StaticDirection, Context extends TProperties, This extends TProperties, Parameters extends TSchema[], InstanceType extends TSchema, StaticParameters extends unknown[] = StaticInstantiatedParameters<Direction, Context, This, Parameters>, StaticReturnType extends unknown = StaticType<Direction, Context, This, InstanceType>, Result = new (...args: StaticParameters) => StaticReturnType> = Result;
5
+ export type StaticConstructor<Stack extends string[], Direction extends StaticDirection, Context extends TProperties, This extends TProperties, Parameters extends TSchema[], InstanceType extends TSchema, StaticParameters extends unknown[] = StaticInstantiatedParameters<Stack, Direction, Context, This, Parameters>, StaticReturnType extends unknown = StaticType<Stack, Direction, Context, This, InstanceType>, Result = new (...args: StaticParameters) => StaticReturnType> = Result;
6
6
  /** Represents a Constructor type. */
7
7
  export interface TConstructor<Parameters extends TSchema[] = TSchema[], InstanceType extends TSchema = TSchema> extends TSchema {
8
8
  '~kind': 'Constructor';
@@ -1,7 +1,7 @@
1
1
  import { type StaticType, type StaticDirection } from './static.mjs';
2
2
  import { type TSchema, type TSchemaOptions } from './schema.mjs';
3
3
  import { type TProperties } from './properties.mjs';
4
- export type StaticCyclic<Direction extends StaticDirection, Context extends TProperties, This extends TProperties, Defs extends TProperties, Ref extends string, Result extends unknown = Ref extends keyof Defs ? StaticType<Direction, Defs, This, Defs[Ref]> : never> = Result;
4
+ export type StaticCyclic<Stack extends string[], Direction extends StaticDirection, Context extends TProperties, This extends TProperties, Defs extends TProperties, Ref extends string, Result extends unknown = (Ref extends keyof Defs ? StaticType<[...Stack, Ref], Direction, Defs, This, Defs[Ref]> : never)> = Result;
5
5
  /** Represents a Cyclic type. */
6
6
  export interface TCyclic<Defs extends TProperties = TProperties, Ref extends string = string> extends TSchema {
7
7
  '~kind': 'Cyclic';
@@ -3,8 +3,8 @@ import { type TSchema, type TSchemaOptions } from './schema.mjs';
3
3
  import { type TProperties } from './properties.mjs';
4
4
  import { type TTuple } from './tuple.mjs';
5
5
  import { type TInstantiate } from '../engine/instantiate.mjs';
6
- export type StaticInstantiatedParameters<Direction extends StaticDirection, Context extends TProperties, This extends TProperties, Parameters extends TSchema[], Evaluated extends TSchema = TInstantiate<Context, TTuple<Parameters>>, Static extends unknown = StaticType<Direction, Context, This, Evaluated>, Result extends unknown[] = Static extends unknown[] ? Static : []> = Result;
7
- export type StaticFunction<Direction extends StaticDirection, Context extends TProperties, This extends TProperties, Parameters extends TSchema[], ReturnType extends TSchema, StaticParameters extends unknown[] = StaticInstantiatedParameters<Direction, Context, This, Parameters>, StaticReturnType extends unknown = StaticType<Direction, Context, This, ReturnType>, Result = (...args: StaticParameters) => StaticReturnType> = Result;
6
+ export type StaticInstantiatedParameters<Stack extends string[], Direction extends StaticDirection, Context extends TProperties, This extends TProperties, Parameters extends TSchema[], Evaluated extends TSchema = TInstantiate<Context, TTuple<Parameters>>, Static extends unknown = StaticType<Stack, Direction, Context, This, Evaluated>, Result extends unknown[] = Static extends unknown[] ? Static : []> = Result;
7
+ export type StaticFunction<Stack extends string[], Direction extends StaticDirection, Context extends TProperties, This extends TProperties, Parameters extends TSchema[], ReturnType extends TSchema, StaticParameters extends unknown[] = StaticInstantiatedParameters<Stack, Direction, Context, This, Parameters>, StaticReturnType extends unknown = StaticType<Stack, Direction, Context, This, ReturnType>, Result = (...args: StaticParameters) => StaticReturnType> = Result;
8
8
  /** Represents a Function type. */
9
9
  export interface TFunction<Parameters extends TSchema[] = TSchema[], ReturnType extends TSchema = TSchema> extends TSchema {
10
10
  '~kind': 'Function';
@@ -1,7 +1,7 @@
1
1
  import { type StaticType, type StaticDirection } from './static.mjs';
2
2
  import { type TSchema, type TIntersectOptions } from './schema.mjs';
3
3
  import { type TProperties } from './properties.mjs';
4
- export type StaticIntersect<Direction extends StaticDirection, Context extends TProperties, This extends TProperties, Types extends TSchema[], Result extends unknown = unknown> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? StaticIntersect<Direction, Context, This, Right, Result & StaticType<Direction, Context, This, Left>> : Result);
4
+ export type StaticIntersect<Stack extends string[], Direction extends StaticDirection, Context extends TProperties, This extends TProperties, Types extends TSchema[], Result extends unknown = unknown> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? StaticIntersect<Stack, Direction, Context, This, Right, Result & StaticType<Stack, Direction, Context, This, Left>> : Result);
5
5
  /** Represents a logical Intersect type. */
6
6
  export interface TIntersect<Types extends TSchema[] = TSchema[]> extends TSchema {
7
7
  '~kind': 'Intersect';
@@ -1,7 +1,7 @@
1
1
  import { type StaticType, type StaticDirection } from './static.mjs';
2
2
  import { type TSchema, type TSchemaOptions } from './schema.mjs';
3
3
  import { type TProperties } from './properties.mjs';
4
- export type StaticIterator<Direction extends StaticDirection, Context extends TProperties, This extends TProperties, Type extends TSchema, Result = IterableIterator<StaticType<Direction, Context, This, Type>>> = Result;
4
+ export type StaticIterator<Stack extends string[], Direction extends StaticDirection, Context extends TProperties, This extends TProperties, Type extends TSchema, Result = IterableIterator<StaticType<Stack, Direction, Context, This, Type>>> = Result;
5
5
  /** Represents an Iterator. */
6
6
  export interface TIterator<Type extends TSchema = TSchema> extends TSchema {
7
7
  '~kind': 'Iterator';
@@ -1,7 +1,7 @@
1
1
  import { type StaticDirection } from './static.mjs';
2
2
  import { type TSchema, type TObjectOptions } from './schema.mjs';
3
3
  import { type TProperties, type TRequiredArray, type StaticProperties } from './properties.mjs';
4
- export type StaticObject<Direction extends StaticDirection, Context extends TProperties, _This extends TProperties, Properties extends TProperties, Result = keyof Properties extends never ? object : StaticProperties<Direction, Context, Properties, Properties>> = Result;
4
+ export type StaticObject<Stack extends string[], Direction extends StaticDirection, Context extends TProperties, _This extends TProperties, Properties extends TProperties, Result = keyof Properties extends never ? object : StaticProperties<Stack, Direction, Context, Properties, Properties>> = Result;
5
5
  /** Represents an Object type. */
6
6
  export interface TObject<Properties extends TProperties = TProperties> extends TSchema {
7
7
  '~kind': 'Object';
@@ -1,7 +1,7 @@
1
1
  import { type StaticType, type StaticDirection } from './static.mjs';
2
2
  import { type TSchema, type TSchemaOptions } from './schema.mjs';
3
3
  import { type TProperties } from './properties.mjs';
4
- export type StaticPromise<Direction extends StaticDirection, Context extends TProperties, This extends TProperties, Type extends TSchema, Result = Promise<StaticType<Direction, Context, This, Type>>> = Result;
4
+ export type StaticPromise<Stack extends string[], Direction extends StaticDirection, Context extends TProperties, This extends TProperties, Type extends TSchema, Result = Promise<StaticType<Stack, Direction, Context, This, Type>>> = Result;
5
5
  /** Represents a Promise type. */
6
6
  export interface TPromise<Type extends TSchema = TSchema> extends TSchema {
7
7
  '~kind': 'Promise';
@@ -14,10 +14,10 @@ type OptionalKeys<Properties extends TProperties, Result extends PropertyKey = {
14
14
  }[keyof Properties]> = Result;
15
15
  type RequiredKeys<Properties extends TProperties, Result extends PropertyKey = keyof Omit<Properties, ReadonlyOptionalKeys<Properties> | ReadonlyKeys<Properties> | OptionalKeys<Properties>>> = Result;
16
16
  type StaticPropertiesWithModifiers<Properties extends TProperties, PropertiesWithoutModifiers extends Record<PropertyKey, unknown>> = StaticEvaluate<Readonly<Partial<Pick<PropertiesWithoutModifiers, ReadonlyOptionalKeys<Properties>>>> & Readonly<Pick<PropertiesWithoutModifiers, ReadonlyKeys<Properties>>> & Partial<Pick<PropertiesWithoutModifiers, OptionalKeys<Properties>>> & Required<Pick<PropertiesWithoutModifiers, RequiredKeys<Properties>>>>;
17
- type StaticPropertiesWithoutModifiers<Direction extends StaticDirection, Context extends TProperties, This extends TProperties, Properties extends TProperties, Result extends Record<PropertyKey, unknown> = {
18
- [Key in keyof Properties]: StaticType<Direction, Context, This, Properties[Key]>;
17
+ type StaticPropertiesWithoutModifiers<Stack extends string[], Direction extends StaticDirection, Context extends TProperties, This extends TProperties, Properties extends TProperties, Result extends Record<PropertyKey, unknown> = {
18
+ [Key in keyof Properties]: StaticType<Stack, Direction, Context, This, Properties[Key]>;
19
19
  }> = Result;
20
- export type StaticProperties<Direction extends StaticDirection, Context extends TProperties, This extends TProperties, Properties extends TProperties, PropertiesWithoutModifiers extends Record<PropertyKey, unknown> = StaticPropertiesWithoutModifiers<Direction, Context, This, Properties>, PropertiesWithModifiers extends Record<PropertyKey, unknown> = StaticPropertiesWithModifiers<Properties, PropertiesWithoutModifiers>, Result extends Record<PropertyKey, unknown> = {
20
+ export type StaticProperties<Stack extends string[], Direction extends StaticDirection, Context extends TProperties, This extends TProperties, Properties extends TProperties, PropertiesWithoutModifiers extends Record<PropertyKey, unknown> = StaticPropertiesWithoutModifiers<Stack, Direction, Context, This, Properties>, PropertiesWithModifiers extends Record<PropertyKey, unknown> = StaticPropertiesWithModifiers<Properties, PropertiesWithoutModifiers>, Result extends Record<PropertyKey, unknown> = {
21
21
  [Key in keyof PropertiesWithModifiers]: PropertiesWithModifiers[Key];
22
22
  }> = Result;
23
23
  /** Represents a Record<PropertyKey, TSchema> structure. */
@@ -6,7 +6,7 @@ import { type TNumber } from './number.mjs';
6
6
  import { type TString } from './string.mjs';
7
7
  import { type TDeferred } from './deferred.mjs';
8
8
  import { type TInstantiate } from '../engine/instantiate.mjs';
9
- export type StaticRecord<Direction extends StaticDirection, Context extends TProperties, This extends TProperties, Key extends string, Value extends TSchema, StaticValue extends unknown = StaticType<Direction, Context, This, Value>, Result extends Record<PropertyKey, unknown> = (Key extends TStringKey ? Record<string, StaticValue> : Key extends TIntegerKey ? Record<number, StaticValue> : Key extends TNumberKey ? Record<number, StaticValue> : Record<string, StaticValue>)> = Result;
9
+ export type StaticRecord<Stack extends string[], Direction extends StaticDirection, Context extends TProperties, This extends TProperties, Key extends string, Value extends TSchema, StaticValue extends unknown = StaticType<Stack, Direction, Context, This, Value>, Result extends Record<PropertyKey, unknown> = (Key extends TStringKey ? Record<string, StaticValue> : Key extends TIntegerKey ? Record<number, StaticValue> : Key extends TNumberKey ? Record<number, StaticValue> : Record<string, StaticValue>)> = Result;
10
10
  export type TStringKey = typeof StringKey;
11
11
  export type TIntegerKey = typeof IntegerKey;
12
12
  export type TNumberKey = typeof NumberKey;
@@ -1,7 +1,12 @@
1
1
  import { type StaticType, type StaticDirection } from './static.mjs';
2
2
  import { type TSchema, type TSchemaOptions } from './schema.mjs';
3
3
  import { type TProperties } from './properties.mjs';
4
- export type StaticRef<Direction extends StaticDirection, Context extends TProperties, This extends TProperties, Ref extends string, Result extends unknown = Ref extends keyof Context ? StaticType<Direction, Context, This, Context[Ref]> : unknown> = Result;
4
+ import { type TObject } from './object.mjs';
5
+ import { type TUnknown } from './unknown.mjs';
6
+ type CyclicStackLength<Stack extends unknown[], MaxLength extends number, Buffer extends unknown[] = []> = (Stack extends [infer Left, ...infer Right] ? Buffer['length'] extends MaxLength ? false : CyclicStackLength<Right, MaxLength, [...Buffer, Left]> : true);
7
+ type CyclicGuard<Stack extends unknown[], Ref extends string> = (Ref extends Stack[number] ? CyclicStackLength<Stack, 2> : true);
8
+ type StaticGuardedRef<Stack extends string[], Direction extends StaticDirection, Context extends TProperties, This extends TProperties, Ref extends string, Type extends TSchema> = (CyclicGuard<Stack, Ref> extends true ? StaticType<[...Stack, Ref], Direction, Context, This, Type> : any);
9
+ export type StaticRef<Stack extends string[], Direction extends StaticDirection, Context extends TProperties, This extends TProperties, Ref extends string, Target extends TSchema = Ref extends keyof Context ? Context[Ref] : TUnknown, Result extends unknown = Target extends TObject ? StaticType<[], Direction, Context, This, Target> : StaticGuardedRef<Stack, Direction, Context, This, Ref, Target>> = Result;
5
10
  /** Represents a type reference. */
6
11
  export interface TRef<Ref extends string = string> extends TSchema {
7
12
  '~kind': 'Ref';
@@ -11,3 +16,4 @@ export interface TRef<Ref extends string = string> extends TSchema {
11
16
  export declare function Ref<Ref extends string>(ref: Ref, options?: TSchemaOptions): TRef<Ref>;
12
17
  /** Returns true if the given value is TRef. */
13
18
  export declare function IsRef(value: unknown): value is TRef;
19
+ export {};
@@ -36,12 +36,12 @@ export type StaticEvaluate<T> = {
36
36
  [K in keyof T]: T[K];
37
37
  } & {};
38
38
  export type StaticDirection = 'Encode' | 'Decode';
39
- export type StaticType<Direction extends StaticDirection, Context extends TProperties, This extends TProperties, Type extends TSchema> = (Type extends TCodec<infer Type extends TSchema, infer Decoded extends unknown> ? StaticCodec<Direction, Context, This, Type, Decoded> : Type extends TAny ? StaticAny : Type extends TArray<infer Type extends TSchema> ? StaticArray<Direction, Context, This, Type> : Type extends TAsyncIterator<infer Type extends TSchema> ? StaticAsyncIterator<Direction, Context, This, Type> : Type extends TBigInt ? StaticBigInt : Type extends TBoolean ? StaticBoolean : Type extends TConstructor<infer Parameters extends TSchema[], infer ReturnType extends TSchema> ? StaticConstructor<Direction, Context, This, Parameters, ReturnType> : Type extends TEnum<infer Values extends TEnumValue[]> ? StaticEnum<Values> : Type extends TFunction<infer Parameters extends TSchema[], infer ReturnType extends TSchema> ? StaticFunction<Direction, Context, This, Parameters, ReturnType> : Type extends TInteger ? StaticInteger : Type extends TIntersect<infer Types extends TSchema[]> ? StaticIntersect<Direction, Context, This, Types> : Type extends TIterator<infer Types extends TSchema> ? StaticIterator<Direction, Context, This, Types> : Type extends TLiteral<infer Value extends TLiteralValue> ? StaticLiteral<Value> : Type extends TNever ? StaticNever : Type extends TNull ? StaticNull : Type extends TNumber ? StaticNumber : Type extends TObject<infer Properties extends TProperties> ? StaticObject<Direction, Context, This, Properties> : Type extends TPromise<infer Type extends TSchema> ? StaticPromise<Direction, Context, This, Type> : Type extends TRecord<infer Key extends string, infer Value extends TSchema> ? StaticRecord<Direction, Context, This, Key, Value> : Type extends TCyclic<infer Defs extends TProperties, infer Ref extends string> ? StaticCyclic<Direction, Context, This, Defs, Ref> : Type extends TRef<infer Ref extends string> ? StaticRef<Direction, Context, This, Ref> : Type extends TString ? StaticString : Type extends TSymbol ? StaticSymbol : Type extends TTemplateLiteral<infer Pattern extends string> ? StaticTemplateLiteral<Pattern> : Type extends TThis ? StaticThis<Direction, Context, This> : Type extends TTuple<infer Types extends TSchema[]> ? StaticTuple<Direction, Context, This, Types> : Type extends TUndefined ? StaticUndefined : Type extends TUnion<infer Types extends TSchema[]> ? StaticUnion<Direction, Context, This, Types> : Type extends TUnknown ? StaticUnknown : Type extends TUnsafe<infer Type extends unknown> ? StaticUnsafe<Type> : Type extends TVoid ? StaticVoid : XStatic<Type>);
39
+ export type StaticType<Stack extends string[], Direction extends StaticDirection, Context extends TProperties, This extends TProperties, Type extends TSchema> = (Type extends TCodec<infer Type extends TSchema, infer Decoded extends unknown> ? StaticCodec<Stack, Direction, Context, This, Type, Decoded> : Type extends TAny ? StaticAny : Type extends TArray<infer Type extends TSchema> ? StaticArray<Stack, Direction, Context, This, Type> : Type extends TAsyncIterator<infer Type extends TSchema> ? StaticAsyncIterator<Stack, Direction, Context, This, Type> : Type extends TBigInt ? StaticBigInt : Type extends TBoolean ? StaticBoolean : Type extends TConstructor<infer Parameters extends TSchema[], infer ReturnType extends TSchema> ? StaticConstructor<Stack, Direction, Context, This, Parameters, ReturnType> : Type extends TEnum<infer Values extends TEnumValue[]> ? StaticEnum<Values> : Type extends TFunction<infer Parameters extends TSchema[], infer ReturnType extends TSchema> ? StaticFunction<Stack, Direction, Context, This, Parameters, ReturnType> : Type extends TInteger ? StaticInteger : Type extends TIntersect<infer Types extends TSchema[]> ? StaticIntersect<Stack, Direction, Context, This, Types> : Type extends TIterator<infer Types extends TSchema> ? StaticIterator<Stack, Direction, Context, This, Types> : Type extends TLiteral<infer Value extends TLiteralValue> ? StaticLiteral<Value> : Type extends TNever ? StaticNever : Type extends TNull ? StaticNull : Type extends TNumber ? StaticNumber : Type extends TObject<infer Properties extends TProperties> ? StaticObject<Stack, Direction, Context, This, Properties> : Type extends TPromise<infer Type extends TSchema> ? StaticPromise<Stack, Direction, Context, This, Type> : Type extends TRecord<infer Key extends string, infer Value extends TSchema> ? StaticRecord<Stack, Direction, Context, This, Key, Value> : Type extends TCyclic<infer Defs extends TProperties, infer Ref extends string> ? StaticCyclic<Stack, Direction, Context, This, Defs, Ref> : Type extends TRef<infer Ref extends string> ? StaticRef<Stack, Direction, Context, This, Ref> : Type extends TString ? StaticString : Type extends TSymbol ? StaticSymbol : Type extends TTemplateLiteral<infer Pattern extends string> ? StaticTemplateLiteral<Pattern> : Type extends TThis ? StaticThis<Stack, Direction, Context, This> : Type extends TTuple<infer Types extends TSchema[]> ? StaticTuple<Stack, Direction, Context, This, Types> : Type extends TUndefined ? StaticUndefined : Type extends TUnion<infer Types extends TSchema[]> ? StaticUnion<Stack, Direction, Context, This, Types> : Type extends TUnknown ? StaticUnknown : Type extends TUnsafe<infer Type extends unknown> ? StaticUnsafe<Type> : Type extends TVoid ? StaticVoid : XStatic<Type>);
40
40
  /** Infers a static type from a TypeBox type using Parse logic. */
41
- export type StaticParse<Type extends TSchema, Context extends TProperties = {}> = StaticType<'Decode', Context, {}, Type>;
41
+ export type StaticParse<Type extends TSchema, Context extends TProperties = {}> = StaticType<[], 'Decode', Context, {}, Type>;
42
42
  /** Infers a static type from a TypeBox type using Decode logic. */
43
- export type StaticDecode<Type extends TSchema, Context extends TProperties = {}> = StaticType<'Decode', Context, {}, Type>;
43
+ export type StaticDecode<Type extends TSchema, Context extends TProperties = {}> = StaticType<[], 'Decode', Context, {}, Type>;
44
44
  /** Infers a static type from a TypeBox type using Encode logic. */
45
- export type StaticEncode<Type extends TSchema, Context extends TProperties = {}> = StaticType<'Encode', Context, {}, Type>;
45
+ export type StaticEncode<Type extends TSchema, Context extends TProperties = {}> = StaticType<[], 'Encode', Context, {}, Type>;
46
46
  /** Infers a static type from a TypeBox type. */
47
- export type Static<Type extends TSchema, Context extends TProperties = {}> = StaticType<'Encode', Context, {}, Type>;
47
+ export type Static<Type extends TSchema, Context extends TProperties = {}> = StaticType<[], 'Encode', Context, {}, Type>;
@@ -2,7 +2,7 @@ import { type StaticType, type StaticDirection } from './static.mjs';
2
2
  import { type TSchema, type TSchemaOptions } from './schema.mjs';
3
3
  import { type TObject } from './object.mjs';
4
4
  import { type TProperties } from './properties.mjs';
5
- export type StaticThis<Direction extends StaticDirection, Context extends TProperties, This extends TProperties> = (StaticType<Direction, Context, This, TObject<This>>);
5
+ export type StaticThis<Stack extends string[], Direction extends StaticDirection, Context extends TProperties, This extends TProperties> = (StaticType<Stack, Direction, Context, This, TObject<This>>);
6
6
  /** Represents a This type. */
7
7
  export interface TThis extends TSchema {
8
8
  '~kind': 'This';
@@ -5,8 +5,8 @@ import { type TOptional } from './_optional.mjs';
5
5
  import { type TProperties } from './properties.mjs';
6
6
  import { type TReadonly } from './_readonly.mjs';
7
7
  import { type TRest } from './rest.mjs';
8
- type StaticLast<Direction extends StaticDirection, Context extends TProperties, This extends TProperties, Type extends TSchema, Result extends unknown[]> = (Type extends TRest<infer RestType extends TSchema> ? RestType extends TArray<infer ArrayType extends TSchema> ? [...Result, ...TStaticElement<Direction, Context, This, ArrayType>[0][]] : [...Result, never] : [...Result, ...TStaticElement<Direction, Context, This, Type>]);
9
- type TStaticElement<Direction extends StaticDirection, Context extends TProperties, This extends TProperties, Type extends TSchema, IsReadonly extends boolean = Type extends TReadonly ? true : false, IsOptional extends boolean = Type extends TOptional ? true : false, Inferred extends unknown = StaticType<Direction, Context, This, Type>, Result extends [unknown?] = ([
8
+ type StaticLast<Stack extends string[], Direction extends StaticDirection, Context extends TProperties, This extends TProperties, Type extends TSchema, Result extends unknown[]> = (Type extends TRest<infer RestType extends TSchema> ? RestType extends TArray<infer ArrayType extends TSchema> ? [...Result, ...TStaticElement<Stack, Direction, Context, This, ArrayType>[0][]] : [...Result, never] : [...Result, ...TStaticElement<Stack, Direction, Context, This, Type>]);
9
+ type TStaticElement<Stack extends string[], Direction extends StaticDirection, Context extends TProperties, This extends TProperties, Type extends TSchema, IsReadonly extends boolean = Type extends TReadonly ? true : false, IsOptional extends boolean = Type extends TOptional ? true : false, Inferred extends unknown = StaticType<Stack, Direction, Context, This, Type>, Result extends [unknown?] = ([
10
10
  IsReadonly,
11
11
  IsOptional
12
12
  ] extends [true, true] ? [Readonly<Inferred>?] : [
@@ -18,8 +18,8 @@ type TStaticElement<Direction extends StaticDirection, Context extends TProperti
18
18
  ] extends [true, false] ? [Readonly<Inferred>] : [
19
19
  Inferred
20
20
  ])> = Result;
21
- export type TStaticElements<Direction extends StaticDirection, Context extends TProperties, This extends TProperties, Types extends TSchema[], Result extends unknown[] = []> = (Types extends [infer Last extends TSchema] ? StaticLast<Direction, Context, This, Last, Result> : Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TStaticElements<Direction, Context, This, Right, [...Result, ...TStaticElement<Direction, Context, This, Left>]> : Result);
22
- export type StaticTuple<Direction extends StaticDirection, Context extends TProperties, This extends TProperties, Types extends TSchema[], Elements extends unknown[] = TStaticElements<Direction, Context, This, Types>, Result extends unknown[] = Elements> = Result;
21
+ export type TStaticElements<Stack extends string[], Direction extends StaticDirection, Context extends TProperties, This extends TProperties, Types extends TSchema[], Result extends unknown[] = []> = (Types extends [infer Last extends TSchema] ? StaticLast<Stack, Direction, Context, This, Last, Result> : Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TStaticElements<Stack, Direction, Context, This, Right, [...Result, ...TStaticElement<Stack, Direction, Context, This, Left>]> : Result);
22
+ export type StaticTuple<Stack extends string[], Direction extends StaticDirection, Context extends TProperties, This extends TProperties, Types extends TSchema[], Elements extends unknown[] = TStaticElements<Stack, Direction, Context, This, Types>, Result extends unknown[] = Elements> = Result;
23
23
  /** Represents a Tuple type. */
24
24
  export interface TTuple<Types extends TSchema[] = TSchema[]> extends TSchema {
25
25
  '~kind': 'Tuple';
@@ -1,7 +1,7 @@
1
1
  import { type StaticType, type StaticDirection } from './static.mjs';
2
2
  import { type TSchema, type TSchemaOptions } from './schema.mjs';
3
3
  import { type TProperties } from './properties.mjs';
4
- export type StaticUnion<Direction extends StaticDirection, Context extends TProperties, This extends TProperties, Types extends TSchema[], Result extends unknown = never> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? StaticUnion<Direction, Context, This, Right, Result | StaticType<Direction, Context, This, Left>> : Result);
4
+ export type StaticUnion<Stack extends string[], Direction extends StaticDirection, Context extends TProperties, This extends TProperties, Types extends TSchema[], Result extends unknown = never> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? StaticUnion<Stack, Direction, Context, This, Right, Result | StaticType<Stack, Direction, Context, This, Left>> : Result);
5
5
  /** Represents a logical Union type. */
6
6
  export interface TUnion<Types extends TSchema[] = TSchema[]> extends TSchema {
7
7
  '~kind': 'Union';
@@ -1,5 +1,10 @@
1
1
  import type { Static, TProperties, TSchema } from '../../type/index.mjs';
2
2
  export declare class AssertError extends Error {
3
+ readonly cause: {
4
+ source: string;
5
+ errors: object[];
6
+ value: unknown;
7
+ };
3
8
  constructor(source: string, value: unknown, errors: object[]);
4
9
  }
5
10
  /** Asserts the a value matches the given type. This function returns a TypeScript type asserts predicate and will throw AssertError if value does not match. */
@@ -26,6 +26,7 @@ function FromObjectInstance(value) {
26
26
  }
27
27
  return result;
28
28
  }
29
+ Object.create({});
29
30
  // ------------------------------------------------------------------
30
31
  // Object
31
32
  // ------------------------------------------------------------------
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "typebox",
3
3
  "description": "A Runtime Type System for JavaScript",
4
- "version": "1.0.14",
4
+ "version": "1.0.16",
5
5
  "keywords": [
6
6
  "typescript",
7
7
  "jsonschema"