typebox 1.0.35 → 1.0.36

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 TImmutable } from '../types/_immutable.mjs';
1
2
  import { type TOptional, TOptionalAdd, TOptionalRemove } from '../types/_optional.mjs';
2
3
  import { type TReadonly, TReadonlyAdd, TReadonlyRemove } from '../types/_readonly.mjs';
3
4
  import { type TSchema } from '../types/schema.mjs';
@@ -151,7 +152,7 @@ type TInstantiateDeferred<Context extends TProperties, State extends TState, Act
151
152
  Action,
152
153
  Parameters
153
154
  ] extends ['Uppercase', [infer Type extends TSchema]] ? TUppercaseInstantiate<Context, State, Type> : TDeferred<Action, Parameters>);
154
- export type TInstantiateType<Context extends TProperties, State extends TState, Input extends TSchema, ModifierState extends [TSchema, ModifierAction, ModifierAction] = TModifierActions<Input, Input extends TReadonly<Input> ? 'add' : 'none', Input extends TOptional<Input> ? 'add' : 'none'>, Type extends TSchema = ModifierState[0], Instantiated extends TSchema = (Type extends TRef<infer Ref extends string> ? TRefInstantiate<Context, State, Ref> : Type extends TArray<infer Type extends TSchema> ? TArray<TInstantiateType<Context, State, Type>> : Type extends TAsyncIterator<infer Type extends TSchema> ? TAsyncIterator<TInstantiateType<Context, State, Type>> : Type extends TCall<infer Target extends TSchema, infer Parameters extends TSchema[]> ? TCallInstantiate<Context, State, Target, Parameters> : Type extends TConstructor<infer Parameters extends TSchema[], infer InstanceType extends TSchema> ? TConstructor<TInstantiateTypes<Context, State, Parameters>, TInstantiateType<Context, State, InstanceType>> : Type extends TDeferred<infer Action extends string, infer Types extends TSchema[]> ? TInstantiateDeferred<Context, State, Action, Types> : Type extends TFunction<infer Parameters extends TSchema[], infer ReturnType extends TSchema> ? TFunction<TInstantiateTypes<Context, State, Parameters>, TInstantiateType<Context, State, ReturnType>> : Type extends TIntersect<infer Types extends TSchema[]> ? TIntersect<TInstantiateTypes<Context, State, Types>> : Type extends TIterator<infer Type extends TSchema> ? TIterator<TInstantiateType<Context, State, Type>> : Type extends TObject<infer Properties extends TProperties> ? TObject<TInstantiateProperties<Context, State, Properties>> : Type extends TPromise<infer Type extends TSchema> ? TPromise<TInstantiateType<Context, State, Type>> : Type extends TRecord<infer Key extends string, infer Type extends TSchema> ? TRecord<Key, TInstantiateType<Context, State, Type>> : Type extends TRest<infer Type extends TSchema> ? TRest<TInstantiateType<Context, State, Type>> : Type extends TTuple<infer Types extends TSchema[]> ? TTuple<TInstantiateElements<Context, State, Types>> : Type extends TUnion<infer Types extends TSchema[]> ? TUnion<TInstantiateTypes<Context, State, Types>> : Type)> = TApplyReadonly<ModifierState[1], TApplyOptional<ModifierState[2], Instantiated>>;
155
+ export type TInstantiateType<Context extends TProperties, State extends TState, Input extends TSchema, IsImmutable extends boolean = Input extends TImmutable ? true : false, ModifierState extends [TSchema, ModifierAction, ModifierAction] = TModifierActions<Input, Input extends TReadonly<Input> ? 'add' : 'none', Input extends TOptional<Input> ? 'add' : 'none'>, Type extends TSchema = ModifierState[0], Instantiated extends TSchema = (Type extends TRef<infer Ref extends string> ? TRefInstantiate<Context, State, Ref> : Type extends TArray<infer Type extends TSchema> ? TArray<TInstantiateType<Context, State, Type>> : Type extends TAsyncIterator<infer Type extends TSchema> ? TAsyncIterator<TInstantiateType<Context, State, Type>> : Type extends TCall<infer Target extends TSchema, infer Parameters extends TSchema[]> ? TCallInstantiate<Context, State, Target, Parameters> : Type extends TConstructor<infer Parameters extends TSchema[], infer InstanceType extends TSchema> ? TConstructor<TInstantiateTypes<Context, State, Parameters>, TInstantiateType<Context, State, InstanceType>> : Type extends TDeferred<infer Action extends string, infer Types extends TSchema[]> ? TInstantiateDeferred<Context, State, Action, Types> : Type extends TFunction<infer Parameters extends TSchema[], infer ReturnType extends TSchema> ? TFunction<TInstantiateTypes<Context, State, Parameters>, TInstantiateType<Context, State, ReturnType>> : Type extends TIntersect<infer Types extends TSchema[]> ? TIntersect<TInstantiateTypes<Context, State, Types>> : Type extends TIterator<infer Type extends TSchema> ? TIterator<TInstantiateType<Context, State, Type>> : Type extends TObject<infer Properties extends TProperties> ? TObject<TInstantiateProperties<Context, State, Properties>> : Type extends TPromise<infer Type extends TSchema> ? TPromise<TInstantiateType<Context, State, Type>> : Type extends TRecord<infer Key extends string, infer Type extends TSchema> ? TRecord<Key, TInstantiateType<Context, State, Type>> : Type extends TRest<infer Type extends TSchema> ? TRest<TInstantiateType<Context, State, Type>> : Type extends TTuple<infer Types extends TSchema[]> ? TTuple<TInstantiateElements<Context, State, Types>> : Type extends TUnion<infer Types extends TSchema[]> ? TUnion<TInstantiateTypes<Context, State, Types>> : Type), WithImmutable extends TSchema = IsImmutable extends true ? TImmutable<Instantiated> : Instantiated, WithModifiers extends TSchema = TApplyReadonly<ModifierState[1], TApplyOptional<ModifierState[2], WithImmutable>>> = WithModifiers;
155
156
  export declare function InstantiateType<Context extends TProperties, State extends TState, Type extends TSchema>(context: Context, state: State, input: Type): TInstantiateType<Context, State, Type>;
156
157
  /** Instantiates computed schematics using the given context and type. */
157
158
  export type TInstantiate<Context extends TProperties, Type extends TSchema> = (TInstantiateType<Context, {
@@ -4,6 +4,7 @@ import { Guard } from '../../guard/index.mjs';
4
4
  // ------------------------------------------------------------------
5
5
  // Modifiers
6
6
  // ------------------------------------------------------------------
7
+ import { IsImmutable, Immutable } from '../types/_immutable.mjs';
7
8
  import { IsOptional, OptionalAdd, OptionalRemove } from '../types/_optional.mjs';
8
9
  import { IsReadonly, ReadonlyAdd, ReadonlyRemove } from '../types/_readonly.mjs';
9
10
  // ------------------------------------------------------------------
@@ -139,6 +140,7 @@ function InstantiateDeferred(context, state, action, parameters, options) {
139
140
  Deferred(action, parameters, options));
140
141
  }
141
142
  export function InstantiateType(context, state, input) {
143
+ const isImmutable = IsImmutable(input);
142
144
  const modifierActions = ModifierActions(input, IsReadonly(input) ? 'add' : 'none', IsOptional(input) ? 'add' : 'none');
143
145
  const type = modifierActions[0];
144
146
  const instantiated = (IsRef(type) ? RefInstantiate(context, state, type.$ref) :
@@ -157,7 +159,9 @@ export function InstantiateType(context, state, input) {
157
159
  IsTuple(type) ? Tuple(InstantiateElements(context, state, type.items), TupleOptions(type)) :
158
160
  IsUnion(type) ? Union(InstantiateTypes(context, state, type.anyOf), UnionOptions(type)) :
159
161
  type);
160
- return ApplyReadonly(modifierActions[1], ApplyOptional(modifierActions[2], instantiated));
162
+ const withImmutable = isImmutable ? Immutable(instantiated) : instantiated;
163
+ const withModifiers = ApplyReadonly(modifierActions[1], ApplyOptional(modifierActions[2], withImmutable));
164
+ return withModifiers;
161
165
  }
162
166
  /** Instantiates computed schematics using the given context and type. */
163
167
  export function Instantiate(context, type) {
@@ -1,7 +1,20 @@
1
1
  import { type TSchema } from '../types/schema.mjs';
2
2
  import { type TProperties } from '../types/properties.mjs';
3
3
  import { type TArray } from '../types/array.mjs';
4
+ import { type TImmutable } from '../types/_immutable.mjs';
4
5
  import { type TExtendsRight } from './extends-right.mjs';
5
6
  import { type TExtendsLeft } from './extends-left.mjs';
6
- export type TExtendsArray<Inferred extends TProperties, Left extends TSchema, Right extends TSchema> = (Right extends TArray<infer Type extends TSchema> ? TExtendsLeft<Inferred, Left, Type> : TExtendsRight<Inferred, TArray<Left>, Right>);
7
- export declare function ExtendsArray<Inferred extends TProperties, Left extends TSchema, Right extends TSchema>(inferred: Inferred, left: Left, right: Right): TExtendsArray<Inferred, Left, Right>;
7
+ import * as Result from './result.mjs';
8
+ type TExtendsImmutable<Left extends TSchema, Right extends TSchema, IsImmutableLeft extends boolean = Left extends TImmutable ? true : false, IsImmutableRight extends boolean = Right extends TImmutable ? true : false, Result extends boolean = [
9
+ IsImmutableLeft,
10
+ IsImmutableRight
11
+ ] extends [true, true] ? true : [
12
+ IsImmutableLeft,
13
+ IsImmutableRight
14
+ ] extends [false, true] ? true : [
15
+ IsImmutableLeft,
16
+ IsImmutableRight
17
+ ] extends [true, false] ? false : true> = Result;
18
+ export type TExtendsArray<Inferred extends TProperties, ArrayLeft extends TSchema, Left extends TSchema, Right extends TSchema> = (Right extends TArray<infer Type extends TSchema> ? TExtendsImmutable<ArrayLeft, Right> extends true ? TExtendsLeft<Inferred, Left, Type> : Result.TExtendsFalse : TExtendsRight<Inferred, ArrayLeft, Right>);
19
+ export declare function ExtendsArray<Inferred extends TProperties, ArrayLeft extends TSchema, Left extends TSchema, Right extends TSchema>(inferred: Inferred, arrayLeft: ArrayLeft, left: Left, right: Right): TExtendsArray<Inferred, ArrayLeft, Left, Right>;
20
+ export {};
@@ -1,9 +1,21 @@
1
1
  // deno-fmt-ignore-file
2
- import { Array, IsArray } from '../types/array.mjs';
2
+ import { IsArray } from '../types/array.mjs';
3
+ import { IsImmutable } from '../types/_immutable.mjs';
3
4
  import { ExtendsRight } from './extends-right.mjs';
4
5
  import { ExtendsLeft } from './extends-left.mjs';
5
- export function ExtendsArray(inferred, left, right) {
6
+ import * as Result from './result.mjs';
7
+ function ExtendsImmutable(left, right) {
8
+ const isImmutableLeft = IsImmutable(left);
9
+ const isImmutableRight = IsImmutable(right);
10
+ return (isImmutableLeft && isImmutableRight ? true :
11
+ !isImmutableLeft && isImmutableRight ? true :
12
+ isImmutableLeft && !isImmutableRight ? false :
13
+ true);
14
+ }
15
+ export function ExtendsArray(inferred, arrayLeft, left, right) {
6
16
  return (IsArray(right)
7
- ? ExtendsLeft(inferred, left, right.items)
8
- : ExtendsRight(inferred, Array(left), right));
17
+ ? ExtendsImmutable(arrayLeft, right)
18
+ ? ExtendsLeft(inferred, left, right.items)
19
+ : Result.ExtendsFalse()
20
+ : ExtendsRight(inferred, arrayLeft, right));
9
21
  }
@@ -51,5 +51,5 @@ import { type TProperties } from '../types/properties.mjs';
51
51
  import { type TUnion } from '../types/union.mjs';
52
52
  import { type TVoid } from '../types/void.mjs';
53
53
  import * as Result from './result.mjs';
54
- export type TExtendsLeft<Inferred extends TProperties, Left extends TSchema, Right extends TSchema> = (Left extends TAny ? TExtendsAny<Inferred, Left, Right> : Left extends TArray<infer Type extends TSchema> ? TExtendsArray<Inferred, Type, Right> : Left extends TAsyncIterator<infer Type extends TSchema> ? TExtendsAsyncIterator<Inferred, Type, Right> : Left extends TBigInt ? TExtendsBigInt<Inferred, Left, Right> : Left extends TBoolean ? TExtendsBoolean<Inferred, Left, Right> : Left extends TConstructor<infer Parameters extends TSchema[], infer InstanceType extends TSchema> ? TExtendsConstructor<Inferred, Parameters, InstanceType, Right> : Left extends TEnum<infer Values extends TEnumValue[]> ? TExtendsEnum<Inferred, TEnum<Values>, Right> : Left extends TFunction<infer Parameters extends TSchema[], infer ReturnType extends TSchema> ? TExtendsFunction<Inferred, Parameters, ReturnType, Right> : Left extends TInteger ? TExtendsInteger<Inferred, Left, Right> : Left extends TIntersect<infer Types extends TSchema[]> ? TExtendsIntersect<Inferred, Types, Right> : Left extends TIterator<infer Type extends TSchema> ? TExtendsIterator<Inferred, Type, Right> : Left extends TLiteral ? TExtendsLiteral<Inferred, Left, Right> : Left extends TNever ? TExtendsNever<Inferred, Left, Right> : Left extends TNull ? TExtendsNull<Inferred, Left, Right> : Left extends TNumber ? TExtendsNumber<Inferred, Left, Right> : Left extends TObject<infer Properties extends TProperties> ? TExtendsObject<Inferred, Properties, Right> : Left extends TPromise<infer Type extends TSchema> ? TExtendsPromise<Inferred, Type, Right> : Left extends TString ? TExtendsString<Inferred, Left, Right> : Left extends TSymbol ? TExtendsSymbol<Inferred, Left, Right> : Left extends TTemplateLiteral<infer Pattern extends string> ? TExtendsTemplateLiteral<Inferred, Pattern, Right> : Left extends TTuple<infer Types extends TSchema[]> ? TExtendsTuple<Inferred, Types, Right> : Left extends TUndefined ? TExtendsUndefined<Inferred, Left, Right> : Left extends TUnion<infer Types extends TSchema[]> ? TExtendsUnion<Inferred, Types, Right> : Left extends TUnknown ? TExtendsUnknown<Inferred, Left, Right> : Left extends TVoid ? TExtendsVoid<Inferred, Left, Right> : Result.TExtendsFalse);
54
+ export type TExtendsLeft<Inferred extends TProperties, Left extends TSchema, Right extends TSchema> = (Left extends TAny ? TExtendsAny<Inferred, Left, Right> : Left extends TArray<infer Items extends TSchema> ? TExtendsArray<Inferred, Left, Items, Right> : Left extends TAsyncIterator<infer Type extends TSchema> ? TExtendsAsyncIterator<Inferred, Type, Right> : Left extends TBigInt ? TExtendsBigInt<Inferred, Left, Right> : Left extends TBoolean ? TExtendsBoolean<Inferred, Left, Right> : Left extends TConstructor<infer Parameters extends TSchema[], infer InstanceType extends TSchema> ? TExtendsConstructor<Inferred, Parameters, InstanceType, Right> : Left extends TEnum<infer Values extends TEnumValue[]> ? TExtendsEnum<Inferred, TEnum<Values>, Right> : Left extends TFunction<infer Parameters extends TSchema[], infer ReturnType extends TSchema> ? TExtendsFunction<Inferred, Parameters, ReturnType, Right> : Left extends TInteger ? TExtendsInteger<Inferred, Left, Right> : Left extends TIntersect<infer Types extends TSchema[]> ? TExtendsIntersect<Inferred, Types, Right> : Left extends TIterator<infer Type extends TSchema> ? TExtendsIterator<Inferred, Type, Right> : Left extends TLiteral ? TExtendsLiteral<Inferred, Left, Right> : Left extends TNever ? TExtendsNever<Inferred, Left, Right> : Left extends TNull ? TExtendsNull<Inferred, Left, Right> : Left extends TNumber ? TExtendsNumber<Inferred, Left, Right> : Left extends TObject<infer Properties extends TProperties> ? TExtendsObject<Inferred, Properties, Right> : Left extends TPromise<infer Type extends TSchema> ? TExtendsPromise<Inferred, Type, Right> : Left extends TString ? TExtendsString<Inferred, Left, Right> : Left extends TSymbol ? TExtendsSymbol<Inferred, Left, Right> : Left extends TTemplateLiteral<infer Pattern extends string> ? TExtendsTemplateLiteral<Inferred, Pattern, Right> : Left extends TTuple<infer Types extends TSchema[]> ? TExtendsTuple<Inferred, Types, Right> : Left extends TUndefined ? TExtendsUndefined<Inferred, Left, Right> : Left extends TUnion<infer Types extends TSchema[]> ? TExtendsUnion<Inferred, Types, Right> : Left extends TUnknown ? TExtendsUnknown<Inferred, Left, Right> : Left extends TVoid ? TExtendsVoid<Inferred, Left, Right> : Result.TExtendsFalse);
55
55
  export declare function ExtendsLeft<Inferred extends TProperties, Left extends TSchema, Right extends TSchema>(inferred: Inferred, left: Left, right: Right): TExtendsLeft<Inferred, Left, Right>;
@@ -55,7 +55,7 @@ import { IsVoid } from '../types/void.mjs';
55
55
  import * as Result from './result.mjs';
56
56
  export function ExtendsLeft(inferred, left, right) {
57
57
  return (IsAny(left) ? ExtendsAny(inferred, left, right) :
58
- IsArray(left) ? ExtendsArray(inferred, left.items, right) :
58
+ IsArray(left) ? ExtendsArray(inferred, left, left.items, right) :
59
59
  IsAsyncIterator(left) ? ExtendsAsyncIterator(inferred, left.iteratorItems, right) :
60
60
  IsBigInt(left) ? ExtendsBigInt(inferred, left, right) :
61
61
  IsBoolean(left) ? ExtendsBoolean(inferred, left, right) :
@@ -1,3 +1,4 @@
1
+ import { TUnreachable } from '../../system/unreachable/unreachable.mjs';
1
2
  import { type TSchema } from '../types/schema.mjs';
2
3
  import { type TProperties } from '../types/properties.mjs';
3
4
  import { type TLiteral, type TLiteralValue } from '../types/literal.mjs';
@@ -12,6 +13,6 @@ type TExtendsLiteralBigInt<Inferred extends TProperties, Left extends bigint, Ri
12
13
  type TExtendsLiteralBoolean<Inferred extends TProperties, Left extends boolean, Right extends TSchema> = (Right extends TLiteral<infer Value extends boolean> ? TExtendsLiteralValue<Inferred, Left, Value> : Right extends TBoolean ? Result.TExtendsTrue<Inferred> : TExtendsRight<Inferred, TLiteral<Left>, Right>);
13
14
  type TExtendsLiteralNumber<Inferred extends TProperties, Left extends number, Right extends TSchema> = (Right extends TLiteral<infer Value extends number> ? TExtendsLiteralValue<Inferred, Left, Value> : Right extends TNumber ? Result.TExtendsTrue<Inferred> : TExtendsRight<Inferred, TLiteral<Left>, Right>);
14
15
  type TExtendsLiteralString<Inferred extends TProperties, Left extends string, Right extends TSchema> = (Right extends TLiteral<infer Value extends string> ? TExtendsLiteralValue<Inferred, Left, Value> : Right extends TString ? Result.TExtendsTrue<Inferred> : TExtendsRight<Inferred, TLiteral<Left>, Right>);
15
- export type TExtendsLiteral<Inferred extends TProperties, Left extends TLiteral, Right extends TSchema> = (Left extends TLiteral<infer Value extends bigint> ? TExtendsLiteralBigInt<Inferred, Value, Right> : Left extends TLiteral<infer Value extends boolean> ? TExtendsLiteralBoolean<Inferred, Value, Right> : Left extends TLiteral<infer Value extends number> ? TExtendsLiteralNumber<Inferred, Value, Right> : Left extends TLiteral<infer Value extends string> ? TExtendsLiteralString<Inferred, Value, Right> : TExtendsRight<Inferred, Left, Right>);
16
+ export type TExtendsLiteral<Inferred extends TProperties, Left extends TLiteral, Right extends TSchema> = (Left extends TLiteral<infer Value extends bigint> ? TExtendsLiteralBigInt<Inferred, Value, Right> : Left extends TLiteral<infer Value extends boolean> ? TExtendsLiteralBoolean<Inferred, Value, Right> : Left extends TLiteral<infer Value extends number> ? TExtendsLiteralNumber<Inferred, Value, Right> : Left extends TLiteral<infer Value extends string> ? TExtendsLiteralString<Inferred, Value, Right> : TUnreachable);
16
17
  export declare function ExtendsLiteral<Inferred extends TProperties, Left extends TLiteral, Right extends TSchema>(inferred: TProperties, left: Left, right: Right): TExtendsLiteral<Inferred, Left, Right>;
17
18
  export {};
@@ -1,4 +1,5 @@
1
1
  // deno-fmt-ignore-file
2
+ import { Unreachable } from '../../system/unreachable/unreachable.mjs';
2
3
  import { Guard } from '../../guard/index.mjs';
3
4
  import { IsLiteral, Literal } from '../types/literal.mjs';
4
5
  import { IsBigInt } from '../types/bigint.mjs';
@@ -37,5 +38,7 @@ export function ExtendsLiteral(inferred, left, right) {
37
38
  Guard.IsBoolean(left.const) ? ExtendsLiteralBoolean(inferred, left.const, right) :
38
39
  Guard.IsNumber(left.const) ? ExtendsLiteralNumber(inferred, left.const, right) :
39
40
  Guard.IsString(left.const) ? ExtendsLiteralString(inferred, left.const, right) :
40
- ExtendsRight(inferred, left, right));
41
+ Unreachable() // ExtendsRight(inferred, left, right)
42
+ );
41
43
  }
44
+ // deno-coverage-ignore-stop
@@ -174,6 +174,8 @@ export type TExprTailMapping<Input extends [unknown, unknown, unknown] | []> = (
174
174
  export declare function ExprTailMapping(input: [unknown, unknown, unknown] | []): unknown;
175
175
  export type TExprMapping<Input extends [unknown, unknown]> = (Input extends [infer Left extends T.TSchema, infer Rest extends unknown[]] ? TExprBinaryMapping<Left, Rest> : []);
176
176
  export declare function ExprMapping(input: [unknown, unknown]): unknown;
177
+ export type TExprReadonlyMapping<Input extends [unknown, unknown]> = (Input extends ['readonly', infer Type extends T.TSchema] ? T.TImmutableAdd<Type> : never);
178
+ export declare function ExprReadonlyMapping(input: [unknown, unknown]): unknown;
177
179
  export type TExprPipeMapping<Input extends [unknown, unknown]> = (Input extends ['|', infer Type extends T.TSchema] ? Type : never);
178
180
  export declare function ExprPipeMapping(input: [unknown, unknown]): unknown;
179
181
  export type TGenericTypeMapping<Input extends [unknown, unknown, unknown]> = (Input extends [infer Arguments extends T.TParameter[], '=', infer Type extends T.TSchema] ? T.TGeneric<Arguments, Type> : never);
@@ -238,6 +238,9 @@ export function ExprMapping(input) {
238
238
  const [left, rest] = input;
239
239
  return ExprBinaryMapping(left, rest);
240
240
  }
241
+ export function ExprReadonlyMapping(input) {
242
+ return T.ImmutableAdd(input[1]);
243
+ }
241
244
  export function ExprPipeMapping(input) {
242
245
  return input[1];
243
246
  }
@@ -48,10 +48,11 @@ export type TExprTermTail<Input extends string> = ((Token.TConst<'&', Input> ext
48
48
  export type TExprTerm<Input extends string> = (TFactor<Input> extends [infer _0, infer Input extends string] ? (TExprTermTail<Input> extends [infer _1, infer Input extends string] ? [[_0, _1], Input] : []) : []) extends [infer _0 extends [unknown, unknown], infer Input extends string] ? [S.TExprTermMapping<_0>, Input] : [];
49
49
  export type TExprTail<Input extends string> = ((Token.TConst<'|', Input> extends [infer _0, infer Input extends string] ? (TExprTerm<Input> extends [infer _1, infer Input extends string] ? (TExprTail<Input> extends [infer _2, infer Input extends string] ? [[_0, _1, _2], Input] : []) : []) : []) extends [infer _0, infer Input extends string] ? [_0, Input] : [[], Input] extends [infer _0, infer Input extends string] ? [_0, Input] : []) extends [infer _0 extends [unknown, unknown, unknown] | [], infer Input extends string] ? [S.TExprTailMapping<_0>, Input] : [];
50
50
  export type TExpr<Input extends string> = (TExprTerm<Input> extends [infer _0, infer Input extends string] ? (TExprTail<Input> extends [infer _1, infer Input extends string] ? [[_0, _1], Input] : []) : []) extends [infer _0 extends [unknown, unknown], infer Input extends string] ? [S.TExprMapping<_0>, Input] : [];
51
+ export type TExprReadonly<Input extends string> = (Token.TConst<'readonly', Input> extends [infer _0, infer Input extends string] ? (TExpr<Input> extends [infer _1, infer Input extends string] ? [[_0, _1], Input] : []) : []) extends [infer _0 extends [unknown, unknown], infer Input extends string] ? [S.TExprReadonlyMapping<_0>, Input] : [];
51
52
  export type TExprPipe<Input extends string> = (Token.TConst<'|', Input> extends [infer _0, infer Input extends string] ? (TExpr<Input> extends [infer _1, infer Input extends string] ? [[_0, _1], Input] : []) : []) extends [infer _0 extends [unknown, unknown], infer Input extends string] ? [S.TExprPipeMapping<_0>, Input] : [];
52
53
  export type TGenericType<Input extends string> = (TGenericParameters<Input> extends [infer _0, infer Input extends string] ? (Token.TConst<'=', Input> extends [infer _1, infer Input extends string] ? (TType<Input> extends [infer _2, infer Input extends string] ? [[_0, _1, _2], Input] : []) : []) : []) extends [infer _0 extends [unknown, unknown, unknown], infer Input extends string] ? [S.TGenericTypeMapping<_0>, Input] : [];
53
54
  export type TInferType<Input extends string> = ((Token.TConst<'infer', Input> extends [infer _0, infer Input extends string] ? (Token.TIdent<Input> extends [infer _1, infer Input extends string] ? (Token.TConst<'extends', Input> extends [infer _2, infer Input extends string] ? (TExpr<Input> extends [infer _3, infer Input extends string] ? [[_0, _1, _2, _3], Input] : []) : []) : []) : []) extends [infer _0, infer Input extends string] ? [_0, Input] : (Token.TConst<'infer', Input> extends [infer _0, infer Input extends string] ? (Token.TIdent<Input> extends [infer _1, infer Input extends string] ? [[_0, _1], Input] : []) : []) extends [infer _0, infer Input extends string] ? [_0, Input] : []) extends [infer _0 extends [unknown, unknown, unknown, unknown] | [unknown, unknown], infer Input extends string] ? [S.TInferTypeMapping<_0>, Input] : [];
54
- export type TType<Input extends string> = (TInferType<Input> extends [infer _0, infer Input extends string] ? [_0, Input] : TExprPipe<Input> extends [infer _0, infer Input extends string] ? [_0, Input] : TExpr<Input> extends [infer _0, infer Input extends string] ? [_0, Input] : []) extends [infer _0 extends unknown, infer Input extends string] ? [S.TTypeMapping<_0>, Input] : [];
55
+ export type TType<Input extends string> = (TInferType<Input> extends [infer _0, infer Input extends string] ? [_0, Input] : TExprPipe<Input> extends [infer _0, infer Input extends string] ? [_0, Input] : TExprReadonly<Input> extends [infer _0, infer Input extends string] ? [_0, Input] : TExpr<Input> extends [infer _0, infer Input extends string] ? [_0, Input] : []) extends [infer _0 extends unknown, infer Input extends string] ? [S.TTypeMapping<_0>, Input] : [];
55
56
  export type TPropertyKeyNumber<Input extends string> = Token.TNumber<Input> extends [infer _0 extends string, infer Input extends string] ? [S.TPropertyKeyNumberMapping<_0>, Input] : [];
56
57
  export type TPropertyKeyIdent<Input extends string> = Token.TIdent<Input> extends [infer _0 extends string, infer Input extends string] ? [S.TPropertyKeyIdentMapping<_0>, Input] : [];
57
58
  export type TPropertyKeyQuoted<Input extends string> = Token.TString<['\'', '\"'], Input> extends [infer _0 extends string, infer Input extends string] ? [S.TPropertyKeyQuotedMapping<_0>, Input] : [];
@@ -176,6 +177,7 @@ export declare const ExprTermTail: (input: string) => [unknown, string] | [];
176
177
  export declare const ExprTerm: (input: string) => [unknown, string] | [];
177
178
  export declare const ExprTail: (input: string) => [unknown, string] | [];
178
179
  export declare const Expr: (input: string) => [unknown, string] | [];
180
+ export declare const ExprReadonly: (input: string) => [unknown, string] | [];
179
181
  export declare const ExprPipe: (input: string) => [unknown, string] | [];
180
182
  export declare const GenericType: (input: string) => [unknown, string] | [];
181
183
  export declare const InferType: (input: string) => [unknown, string] | [];
@@ -51,10 +51,11 @@ export const ExprTermTail = (input) => If(If(If(Token.Const('&', input), ([_0, i
51
51
  export const ExprTerm = (input) => If(If(Factor(input), ([_0, input]) => If(ExprTermTail(input), ([_1, input]) => [[_0, _1], input])), ([_0, input]) => [S.ExprTermMapping(_0), input]);
52
52
  export const ExprTail = (input) => If(If(If(Token.Const('|', input), ([_0, input]) => If(ExprTerm(input), ([_1, input]) => If(ExprTail(input), ([_2, input]) => [[_0, _1, _2], input]))), ([_0, input]) => [_0, input], () => If([[], input], ([_0, input]) => [_0, input], () => [])), ([_0, input]) => [S.ExprTailMapping(_0), input]);
53
53
  export const Expr = (input) => If(If(ExprTerm(input), ([_0, input]) => If(ExprTail(input), ([_1, input]) => [[_0, _1], input])), ([_0, input]) => [S.ExprMapping(_0), input]);
54
+ export const ExprReadonly = (input) => If(If(Token.Const('readonly', input), ([_0, input]) => If(Expr(input), ([_1, input]) => [[_0, _1], input])), ([_0, input]) => [S.ExprReadonlyMapping(_0), input]);
54
55
  export const ExprPipe = (input) => If(If(Token.Const('|', input), ([_0, input]) => If(Expr(input), ([_1, input]) => [[_0, _1], input])), ([_0, input]) => [S.ExprPipeMapping(_0), input]);
55
56
  export const GenericType = (input) => If(If(GenericParameters(input), ([_0, input]) => If(Token.Const('=', input), ([_1, input]) => If(Type(input), ([_2, input]) => [[_0, _1, _2], input]))), ([_0, input]) => [S.GenericTypeMapping(_0), input]);
56
57
  export const InferType = (input) => If(If(If(Token.Const('infer', input), ([_0, input]) => If(Token.Ident(input), ([_1, input]) => If(Token.Const('extends', input), ([_2, input]) => If(Expr(input), ([_3, input]) => [[_0, _1, _2, _3], input])))), ([_0, input]) => [_0, input], () => If(If(Token.Const('infer', input), ([_0, input]) => If(Token.Ident(input), ([_1, input]) => [[_0, _1], input])), ([_0, input]) => [_0, input], () => [])), ([_0, input]) => [S.InferTypeMapping(_0), input]);
57
- export const Type = (input) => If(If(InferType(input), ([_0, input]) => [_0, input], () => If(ExprPipe(input), ([_0, input]) => [_0, input], () => If(Expr(input), ([_0, input]) => [_0, input], () => []))), ([_0, input]) => [S.TypeMapping(_0), input]);
58
+ export const Type = (input) => If(If(InferType(input), ([_0, input]) => [_0, input], () => If(ExprPipe(input), ([_0, input]) => [_0, input], () => If(ExprReadonly(input), ([_0, input]) => [_0, input], () => If(Expr(input), ([_0, input]) => [_0, input], () => [])))), ([_0, input]) => [S.TypeMapping(_0), input]);
58
59
  export const PropertyKeyNumber = (input) => If(Token.Number(input), ([_0, input]) => [S.PropertyKeyNumberMapping(_0), input]);
59
60
  export const PropertyKeyIdent = (input) => If(Token.Ident(input), ([_0, input]) => [S.PropertyKeyIdentMapping(_0), input]);
60
61
  export const PropertyKeyQuoted = (input) => If(Token.String(['\'', '\"'], input), ([_0, input]) => [S.PropertyKeyQuotedMapping(_0), input]);
@@ -0,0 +1,16 @@
1
+ import { type TSchema } from './schema.mjs';
2
+ /** Removes Immutable from the given type. */
3
+ export type TImmutableRemove<Type extends TSchema, Result extends TSchema = Type extends TImmutable<infer Type extends TSchema> ? Type : Type> = Result;
4
+ /** Removes Immutable from the given type. */
5
+ export declare function ImmutableRemove<Type extends TSchema>(type: Type): TImmutableRemove<Type>;
6
+ /** Adds Immutable to the given type. */
7
+ export type TImmutableAdd<Type extends TSchema = TSchema> = ('~immutable' extends keyof Type ? Type : TImmutable<Type>);
8
+ /** Adds Immutable to the given type. */
9
+ export declare function ImmutableAdd<Type extends TSchema>(type: Type): TImmutableAdd<Type>;
10
+ export type TImmutable<Type extends TSchema = TSchema> = (Type & {
11
+ '~immutable': true;
12
+ });
13
+ /** Applies an Immutable modifier to the given type. */
14
+ export declare function Immutable<Type extends TSchema>(type: Type): TImmutableAdd<Type>;
15
+ /** Returns true if the given value is a TImmutable */
16
+ export declare function IsImmutable(value: unknown): value is TImmutable<TSchema>;
@@ -0,0 +1,26 @@
1
+ // deno-fmt-ignore-file
2
+ import { Memory } from '../../system/memory/index.mjs';
3
+ import { Guard } from '../../guard/index.mjs';
4
+ import { IsSchema } from './schema.mjs';
5
+ /** Removes Immutable from the given type. */
6
+ export function ImmutableRemove(type) {
7
+ return Memory.Discard(type, ['~immutable']);
8
+ }
9
+ /** Adds Immutable to the given type. */
10
+ export function ImmutableAdd(type) {
11
+ return Memory.Update(type, { '~immutable': true }, {});
12
+ }
13
+ // ------------------------------------------------------------------
14
+ // Factory
15
+ // ------------------------------------------------------------------
16
+ /** Applies an Immutable modifier to the given type. */
17
+ export function Immutable(type) {
18
+ return ImmutableAdd(type);
19
+ }
20
+ // ------------------------------------------------------------------
21
+ // Guard
22
+ // ------------------------------------------------------------------
23
+ /** Returns true if the given value is a TImmutable */
24
+ export function IsImmutable(value) {
25
+ return IsSchema(value) && Guard.HasPropertyKey(value, '~immutable');
26
+ }
@@ -4,11 +4,11 @@ export type TReadonlyRemove<Type extends TSchema, Result extends TSchema = Type
4
4
  /** Removes Readaonly from the given type. */
5
5
  export declare function ReadonlyRemove<Type extends TSchema>(type: Type): TReadonlyRemove<Type>;
6
6
  /** Adds Readonly to the given type. */
7
- export type TReadonlyAdd<Type extends TSchema = TSchema> = ('readOnly' extends keyof Type ? Type : TReadonly<Type>);
7
+ export type TReadonlyAdd<Type extends TSchema = TSchema> = ('~readonly' extends keyof Type ? Type : TReadonly<Type>);
8
8
  /** Adds Readonly to the given type. */
9
9
  export declare function ReadonlyAdd<Type extends TSchema>(type: Type): TReadonlyAdd<Type>;
10
10
  export type TReadonly<Type extends TSchema = TSchema> = (Type & {
11
- readOnly: true;
11
+ '~readonly': true;
12
12
  });
13
13
  /** Applies an Readonly modifier to the given type. */
14
14
  export declare function Readonly<Type extends TSchema>(type: Type): TReadonlyAdd<Type>;
@@ -4,11 +4,11 @@ import { Guard } from '../../guard/index.mjs';
4
4
  import { IsSchema } from './schema.mjs';
5
5
  /** Removes Readaonly from the given type. */
6
6
  export function ReadonlyRemove(type) {
7
- return Memory.Discard(type, ['readOnly']);
7
+ return Memory.Discard(type, ['~readonly']);
8
8
  }
9
9
  /** Adds Readonly to the given type. */
10
10
  export function ReadonlyAdd(type) {
11
- return Memory.Update(type, {}, { 'readOnly': true });
11
+ return Memory.Update(type, { '~readonly': true }, {});
12
12
  }
13
13
  // ------------------------------------------------------------------
14
14
  // Factory
@@ -22,5 +22,5 @@ export function Readonly(type) {
22
22
  // ------------------------------------------------------------------
23
23
  /** Returns true if the given value is a TReadonly */
24
24
  export function IsReadonly(value) {
25
- return IsSchema(value) && Guard.HasPropertyKey(value, 'readOnly');
25
+ return IsSchema(value) && Guard.HasPropertyKey(value, '~readonly');
26
26
  }
@@ -5,7 +5,7 @@ import { IsSchema } from './schema.mjs';
5
5
  /** Applies a Refine check to the given type. */
6
6
  export function RefineAdd(type, refinement) {
7
7
  const refinements = IsRefine(type) ? [...type['~refine'], refinement] : [refinement];
8
- return Memory.Update(type, {}, { '~refine': refinements });
8
+ return Memory.Update(type, { '~refine': refinements }, {});
9
9
  }
10
10
  /** Applies a Refine check to the given type. */
11
11
  export function Refine(type, refine, message = 'error') {
@@ -1,7 +1,8 @@
1
1
  import { type StaticType, type StaticDirection } from './static.mjs';
2
2
  import { type TSchema, type TArrayOptions } from './schema.mjs';
3
+ import { type TImmutable } from './_immutable.mjs';
3
4
  import { type TProperties } from './properties.mjs';
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
+ export type StaticArray<Stack extends string[], Direction extends StaticDirection, Context extends TProperties, This extends TProperties, Array extends TSchema, Item extends TSchema, Result extends readonly unknown[] = Array extends TImmutable ? readonly StaticType<Stack, Direction, Context, This, Item>[] : StaticType<Stack, Direction, Context, This, Item>[]> = Result;
5
6
  /** Represents an Array type. */
6
7
  export interface TArray<Type extends TSchema = TSchema> extends TSchema {
7
8
  '~kind': 'Array';
@@ -21,16 +21,22 @@ export class NotImplemented extends Error {
21
21
  /** Base class for creating extension types. */
22
22
  export class Base {
23
23
  constructor() {
24
- Object.defineProperty(this, '~kind', {
24
+ const configuration = {
25
25
  enumerable: Settings.Get().enumerableKind,
26
26
  writable: false,
27
27
  configurable: false,
28
+ };
29
+ globalThis.Object.defineProperty(this, '~kind', {
30
+ ...configuration,
28
31
  value: 'Base'
29
32
  });
30
- this['~guard'] = {
31
- check: (value) => this.Check(value),
32
- errors: (value) => this.Errors(value)
33
- };
33
+ globalThis.Object.defineProperty(this, '~guard', {
34
+ ...configuration,
35
+ value: {
36
+ check: (value) => this.Check(value),
37
+ errors: (value) => this.Errors(value)
38
+ }
39
+ });
34
40
  }
35
41
  /** Checks a value or returns false if invalid */
36
42
  Check(value) {
@@ -1,4 +1,5 @@
1
1
  export * from './_codec.mjs';
2
+ export * from './_immutable.mjs';
2
3
  export * from './_optional.mjs';
3
4
  export * from './_readonly.mjs';
4
5
  export * from './_refine.mjs';
@@ -2,6 +2,7 @@
2
2
  // Extensions
3
3
  // ------------------------------------------------------------------
4
4
  export * from './_codec.mjs';
5
+ export * from './_immutable.mjs';
5
6
  export * from './_optional.mjs';
6
7
  export * from './_readonly.mjs';
7
8
  export * from './_refine.mjs';
@@ -1,9 +1,18 @@
1
1
  import { type TSchema, type TSchemaOptions } from './schema.mjs';
2
+ export declare class InvalidLiteralValue extends Error {
3
+ readonly cause: {
4
+ value: unknown;
5
+ };
6
+ constructor(value: unknown);
7
+ }
2
8
  export type StaticLiteral<Value extends TLiteralValue> = (Value);
9
+ export type TLiteralTypeName<Value extends TLiteralValue> = (Value extends bigint ? 'bigint' : Value extends boolean ? 'boolean' : Value extends number ? 'number' : Value extends string ? 'string' : never);
10
+ export declare function LiteralTypeName<Value extends TLiteralValue>(value: Value): TLiteralTypeName<Value>;
3
11
  export type TLiteralValue = string | number | boolean | bigint;
4
12
  /** Represents a Literal type. */
5
13
  export interface TLiteral<Value extends TLiteralValue = TLiteralValue> extends TSchema {
6
14
  '~kind': 'Literal';
15
+ type: TLiteralTypeName<Value>;
7
16
  const: Value;
8
17
  }
9
18
  /** Creates a Literal type. */
@@ -3,11 +3,32 @@ import { Memory } from '../../system/memory/index.mjs';
3
3
  import { Guard } from '../../guard/index.mjs';
4
4
  import { IsKind } from './schema.mjs';
5
5
  // ------------------------------------------------------------------
6
+ // InvalidLiteralValue
7
+ // ------------------------------------------------------------------
8
+ export class InvalidLiteralValue extends Error {
9
+ constructor(value) {
10
+ super(`Invalid Literal value`);
11
+ Object.defineProperty(this, 'cause', {
12
+ value: { value },
13
+ writable: false,
14
+ configurable: false,
15
+ enumerable: false
16
+ });
17
+ }
18
+ }
19
+ export function LiteralTypeName(value) {
20
+ return (Guard.IsBigInt(value) ? 'bigint' :
21
+ Guard.IsBoolean(value) ? 'boolean' :
22
+ Guard.IsNumber(value) ? 'number' :
23
+ Guard.IsString(value) ? 'string' :
24
+ (() => { throw new InvalidLiteralValue(value); })());
25
+ }
26
+ // ------------------------------------------------------------------
6
27
  // Factory
7
28
  // ------------------------------------------------------------------
8
29
  /** Creates a Literal type. */
9
30
  export function Literal(value, options) {
10
- return Memory.Create({ '~kind': 'Literal' }, { const: value }, options);
31
+ return Memory.Create({ '~kind': 'Literal' }, { type: LiteralTypeName(value), const: value }, options);
11
32
  }
12
33
  // ------------------------------------------------------------------
13
34
  // Guards
@@ -36,7 +36,7 @@ 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<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>);
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 Items extends TSchema> ? StaticArray<Stack, Direction, Context, This, Type, Items> : 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 Items extends TSchema[]> ? StaticTuple<Stack, Direction, Context, This, Type, Items> : 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
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. */
@@ -3,6 +3,7 @@ import { type TSchema, type TTupleOptions } from './schema.mjs';
3
3
  import { type TArray } from './array.mjs';
4
4
  import { type TOptional } from './_optional.mjs';
5
5
  import { type TProperties } from './properties.mjs';
6
+ import { type TImmutable } from './_immutable.mjs';
6
7
  import { type TReadonly } from './_readonly.mjs';
7
8
  import { type TRest } from './rest.mjs';
8
9
  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>]);
@@ -19,7 +20,7 @@ type TStaticElement<Stack extends string[], Direction extends StaticDirection, C
19
20
  Inferred
20
21
  ])> = Result;
21
22
  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
+ export type StaticTuple<Stack extends string[], Direction extends StaticDirection, Context extends TProperties, This extends TProperties, Tuple extends TSchema, Items extends TSchema[], Elements extends unknown[] = TStaticElements<Stack, Direction, Context, This, Items>, Result extends readonly unknown[] = (Tuple extends TImmutable ? readonly [...Elements] : Elements)> = Result;
23
24
  /** Represents a Tuple type. */
24
25
  export interface TTuple<Types extends TSchema[] = TSchema[]> extends TSchema {
25
26
  '~kind': 'Tuple';
@@ -26,6 +26,7 @@ export { ReturnType, type TReturnType, type TReturnTypeDeferred } from './type/a
26
26
  export { type TUncapitalize, type TUncapitalizeDeferred, Uncapitalize } from './type/action/uncapitalize.mjs';
27
27
  export { type TUppercase, type TUppercaseDeferred, Uppercase } from './type/action/uppercase.mjs';
28
28
  export { Codec, Decode, DecodeBuilder, Encode, EncodeBuilder, IsCodec, type TCodec } from './type/types/_codec.mjs';
29
+ export { Immutable, IsImmutable, type TImmutable } from './type/types/_immutable.mjs';
29
30
  export { IsOptional, Optional, type TOptional } from './type/types/_optional.mjs';
30
31
  export { IsReadonly, Readonly, type TReadonly } from './type/types/_readonly.mjs';
31
32
  export { IsRefine, Refine, type TRefine, type TRefineCallback, type TRefinement } from './type/types/_refine.mjs';
package/build/typebox.mjs CHANGED
@@ -41,6 +41,7 @@ export { Uppercase } from './type/action/uppercase.mjs';
41
41
  // Extension
42
42
  // ------------------------------------------------------------------
43
43
  export { Codec, Decode, DecodeBuilder, Encode, EncodeBuilder, IsCodec } from './type/types/_codec.mjs';
44
+ export { Immutable, IsImmutable } from './type/types/_immutable.mjs';
44
45
  export { IsOptional, Optional } from './type/types/_optional.mjs';
45
46
  export { IsReadonly, Readonly } from './type/types/_readonly.mjs';
46
47
  export { IsRefine, Refine } from './type/types/_refine.mjs';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "typebox",
3
- "description": "A Runtime Type System for JavaScript",
4
- "version": "1.0.35",
3
+ "description": "Json Schema Type Builder with Static Type Resolution for TypeScript",
4
+ "version": "1.0.36",
5
5
  "keywords": [
6
6
  "typescript",
7
7
  "jsonschema"
package/readme.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  <h1>TypeBox</h1>
4
4
 
5
- <p>A Runtime Type System for JavaScript</p>
5
+ <p>Json Schema Type Builder with Static Type Resolution for TypeScript</p>
6
6
 
7
7
  <img src="typebox.png" />
8
8