typebox 1.0.34 → 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.
Files changed (35) hide show
  1. package/build/type/engine/instantiate.d.mts +2 -1
  2. package/build/type/engine/instantiate.mjs +5 -1
  3. package/build/type/engine/keyof/from-any.d.mts +6 -0
  4. package/build/type/engine/keyof/from-any.mjs +8 -0
  5. package/build/type/engine/keyof/from-array.d.mts +1 -1
  6. package/build/type/engine/keyof/from-array.mjs +1 -1
  7. package/build/type/engine/keyof/instantiate.d.mts +4 -2
  8. package/build/type/engine/keyof/instantiate.mjs +9 -6
  9. package/build/type/extends/array.d.mts +15 -2
  10. package/build/type/extends/array.mjs +16 -4
  11. package/build/type/extends/extends-left.d.mts +1 -1
  12. package/build/type/extends/extends-left.mjs +1 -1
  13. package/build/type/extends/literal.d.mts +2 -1
  14. package/build/type/extends/literal.mjs +4 -1
  15. package/build/type/script/mapping.d.mts +8 -4
  16. package/build/type/script/mapping.mjs +6 -0
  17. package/build/type/script/parser.d.mts +7 -3
  18. package/build/type/script/parser.mjs +5 -3
  19. package/build/type/types/_immutable.d.mts +16 -0
  20. package/build/type/types/_immutable.mjs +26 -0
  21. package/build/type/types/_readonly.d.mts +2 -2
  22. package/build/type/types/_readonly.mjs +3 -3
  23. package/build/type/types/_refine.mjs +1 -1
  24. package/build/type/types/array.d.mts +2 -1
  25. package/build/type/types/base.mjs +11 -5
  26. package/build/type/types/index.d.mts +1 -0
  27. package/build/type/types/index.mjs +1 -0
  28. package/build/type/types/literal.d.mts +9 -0
  29. package/build/type/types/literal.mjs +22 -1
  30. package/build/type/types/static.d.mts +1 -1
  31. package/build/type/types/tuple.d.mts +2 -1
  32. package/build/typebox.d.mts +1 -0
  33. package/build/typebox.mjs +1 -0
  34. package/package.json +2 -2
  35. package/readme.md +1 -1
@@ -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) {
@@ -0,0 +1,6 @@
1
+ import { type TNumber } from '../../types/number.mjs';
2
+ import { type TString } from '../../types/string.mjs';
3
+ import { type TSymbol } from '../../types/symbol.mjs';
4
+ import { type TUnion } from '../../types/union.mjs';
5
+ export type TFromAny<Result = TUnion<[TNumber, TString, TSymbol]>> = Result;
6
+ export declare function FromAny(): TFromAny;
@@ -0,0 +1,8 @@
1
+ // deno-fmt-ignore-file
2
+ import { Number } from '../../types/number.mjs';
3
+ import { String } from '../../types/string.mjs';
4
+ import { Symbol } from '../../types/symbol.mjs';
5
+ import { Union } from '../../types/union.mjs';
6
+ export function FromAny() {
7
+ return Union([Number(), String(), Symbol()]);
8
+ }
@@ -1,4 +1,4 @@
1
1
  import { type TSchema } from '../../types/index.mjs';
2
- import { type TNumber } from "../../types/number.mjs";
2
+ import { type TNumber } from '../../types/number.mjs';
3
3
  export type TFromArray<_Type extends TSchema> = TNumber;
4
4
  export declare function FromArray<_Type extends TSchema>(_type: _Type): TFromArray<_Type>;
@@ -1,5 +1,5 @@
1
1
  // deno-fmt-ignore-file
2
- import { Number } from "../../types/number.mjs";
2
+ import { Number } from '../../types/number.mjs';
3
3
  export function FromArray(_type) {
4
4
  return Number();
5
5
  }
@@ -1,5 +1,6 @@
1
1
  import { type TSchema, type TSchemaOptions } from '../../types/schema.mjs';
2
2
  import { type TProperties } from '../../types/properties.mjs';
3
+ import { type TAny } from '../../types/any.mjs';
3
4
  import { type TArray } from '../../types/array.mjs';
4
5
  import { type TCyclic } from '../../types/cyclic.mjs';
5
6
  import { type TIntersect } from '../../types/intersect.mjs';
@@ -11,12 +12,13 @@ import { type TUnion } from '../../types/union.mjs';
11
12
  import { type TKeyOfDeferred } from '../../action/keyof.mjs';
12
13
  import { type TState, type TInstantiateType, type TCanInstantiate } from '../instantiate.mjs';
13
14
  import { type TCollapseToObject } from '../object/index.mjs';
14
- import { type TFromArray } from "./from-array.mjs";
15
+ import { type TFromAny } from './from-any.mjs';
16
+ import { type TFromArray } from './from-array.mjs';
15
17
  import { type TFromObject } from './from-object.mjs';
16
18
  import { type TFromRecord } from './from-record.mjs';
17
19
  import { type TFromTuple } from './from-tuple.mjs';
18
20
  type TNormalizeType<Type extends TSchema, Result extends TSchema = (Type extends TCyclic | TIntersect | TUnion ? TCollapseToObject<Type> : Type)> = Result;
19
- export type TKeyOfAction<Type extends TSchema, Normalized extends TSchema = TNormalizeType<Type>> = (Normalized extends TArray<infer Type extends TSchema> ? TFromArray<Type> : Normalized extends TObject<infer Properties extends TProperties> ? TFromObject<Properties> : Normalized extends TRecord ? TFromRecord<Normalized> : Normalized extends TTuple<infer Types extends TSchema[]> ? TFromTuple<Types> : TNever);
21
+ export type TKeyOfAction<Type extends TSchema, Normal extends TSchema = TNormalizeType<Type>> = (Normal extends TAny ? TFromAny : Normal extends TArray<infer Type extends TSchema> ? TFromArray<Type> : Normal extends TObject<infer Properties extends TProperties> ? TFromObject<Properties> : Normal extends TRecord ? TFromRecord<Normal> : Normal extends TTuple<infer Types extends TSchema[]> ? TFromTuple<Types> : TNever);
20
22
  export declare function KeyOfAction<Type extends TSchema>(type: Type): TKeyOfAction<Type>;
21
23
  export type TKeyOfImmediate<Context extends TProperties, State extends TState, Type extends TSchema, InstantiatedType extends TSchema = TInstantiateType<Context, State, Type>> = TKeyOfAction<InstantiatedType>;
22
24
  export declare function KeyOfImmediate<Context extends TProperties, State extends TState, Type extends TSchema>(context: Context, state: State, type: Type, options: TSchemaOptions): TKeyOfImmediate<Context, State, Type>;
@@ -1,5 +1,6 @@
1
1
  // deno-fmt-ignore-file
2
2
  import { Memory } from '../../../system/memory/index.mjs';
3
+ import { IsAny } from '../../types/any.mjs';
3
4
  import { IsArray } from '../../types/array.mjs';
4
5
  import { IsCyclic } from '../../types/cyclic.mjs';
5
6
  import { IsIntersect } from '../../types/intersect.mjs';
@@ -14,7 +15,8 @@ import { CollapseToObject } from '../object/index.mjs';
14
15
  // ------------------------------------------------------------------
15
16
  // Computed
16
17
  // ------------------------------------------------------------------
17
- import { FromArray } from "./from-array.mjs";
18
+ import { FromAny } from './from-any.mjs';
19
+ import { FromArray } from './from-array.mjs';
18
20
  import { FromObject } from './from-object.mjs';
19
21
  import { FromRecord } from './from-record.mjs';
20
22
  import { FromTuple } from './from-tuple.mjs';
@@ -25,11 +27,12 @@ function NormalizeType(type) {
25
27
  }
26
28
  export function KeyOfAction(type) {
27
29
  const normal = NormalizeType(type);
28
- return (IsArray(normal) ? FromArray(normal.items) :
29
- IsObject(normal) ? FromObject(normal.properties) :
30
- IsRecord(normal) ? FromRecord(normal) :
31
- IsTuple(normal) ? FromTuple(normal.items) :
32
- Never());
30
+ return (IsAny(normal) ? FromAny() :
31
+ IsArray(normal) ? FromArray(normal.items) :
32
+ IsObject(normal) ? FromObject(normal.properties) :
33
+ IsRecord(normal) ? FromRecord(normal) :
34
+ IsTuple(normal) ? FromTuple(normal.items) :
35
+ Never());
33
36
  }
34
37
  export function KeyOfImmediate(context, state, type, options) {
35
38
  const instantiatedType = InstantiateType(context, state, 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
@@ -99,6 +99,8 @@ export type TGenericCallArgumentsMapping<Input extends [unknown, unknown, unknow
99
99
  export declare function GenericCallArgumentsMapping(input: [unknown, unknown, unknown]): unknown;
100
100
  export type TGenericCallMapping<Input extends [unknown, unknown], Result = Input extends [infer Ref extends string, infer Arguments extends T.TSchema[]] ? TIntrinsicOrCall<Ref, Arguments> : never> = Result;
101
101
  export declare function GenericCallMapping(input: [unknown, unknown]): unknown;
102
+ export type TOptionalSemiColonMapping<Input extends [unknown] | []> = null;
103
+ export declare function OptionalSemiColonMapping(input: [unknown] | []): unknown;
102
104
  export type TKeywordStringMapping<Input extends 'string'> = (T.TString);
103
105
  export declare function KeywordStringMapping(input: 'string'): unknown;
104
106
  export type TKeywordNumberMapping<Input extends 'number'> = (T.TNumber);
@@ -172,6 +174,8 @@ export type TExprTailMapping<Input extends [unknown, unknown, unknown] | []> = (
172
174
  export declare function ExprTailMapping(input: [unknown, unknown, unknown] | []): unknown;
173
175
  export type TExprMapping<Input extends [unknown, unknown]> = (Input extends [infer Left extends T.TSchema, infer Rest extends unknown[]] ? TExprBinaryMapping<Left, Rest> : []);
174
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;
175
179
  export type TExprPipeMapping<Input extends [unknown, unknown]> = (Input extends ['|', infer Type extends T.TSchema] ? Type : never);
176
180
  export declare function ExprPipeMapping(input: [unknown, unknown]): unknown;
177
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);
@@ -267,8 +271,8 @@ export type TMappedOptionalMapping<Input extends [unknown, unknown] | [unknown]
267
271
  export declare function MappedOptionalMapping(input: [unknown, unknown] | [unknown] | []): unknown;
268
272
  export type TMappedAsMapping<Input extends [unknown, unknown] | []> = (Input extends ['as', infer Type extends T.TSchema] ? [Type] : []);
269
273
  export declare function MappedAsMapping(input: [unknown, unknown] | []): unknown;
270
- export type TMappedMapping<Input extends [unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown]> = (Input extends ['{', infer Readonly extends TModifierOperation, '[', infer Key extends string, 'in', infer Union extends T.TSchema, infer As extends T.TSchema[], ']', infer Optional extends TModifierOperation, ':', infer Type extends T.TSchema, '}'] ? (As extends [infer As extends T.TSchema] ? C.TMappedDeferred<T.TIdentifier<Key>, Union, As, TApplyReadonly<Readonly, TApplyOptional<Optional, Type>>> : C.TMappedDeferred<T.TIdentifier<Key>, Union, T.TRef<Key>, TApplyReadonly<Readonly, TApplyOptional<Optional, Type>>>) : never);
271
- export declare function MappedMapping(input: [unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown]): unknown;
274
+ export type TMappedMapping<Input extends [unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown]> = (Input extends ['{', infer Readonly extends TModifierOperation, '[', infer Key extends string, 'in', infer Union extends T.TSchema, infer As extends T.TSchema[], ']', infer Optional extends TModifierOperation, ':', infer Type extends T.TSchema, null, '}'] ? (As extends [infer As extends T.TSchema] ? C.TMappedDeferred<T.TIdentifier<Key>, Union, As, TApplyReadonly<Readonly, TApplyOptional<Optional, Type>>> : C.TMappedDeferred<T.TIdentifier<Key>, Union, T.TRef<Key>, TApplyReadonly<Readonly, TApplyOptional<Optional, Type>>>) : never);
275
+ export declare function MappedMapping(input: [unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown]): unknown;
272
276
  export type TReferenceMapping<Input extends string, Result extends T.TSchema = T.TRef<Input>> = Result;
273
277
  export declare function ReferenceMapping(input: string): unknown;
274
278
  export type TOptionsMapping<Input extends [unknown, unknown, unknown, unknown, unknown, unknown]> = (Input extends ['Options', '<', infer Type extends T.TSchema, ',', infer Options extends T.TSchemaOptions, '>'] ? C.TOptionsDeferred<Type, Options> : never);
@@ -349,8 +353,8 @@ export type TModuleDeclarationDelimiterMapping<Input extends [unknown, unknown]
349
353
  export declare function ModuleDeclarationDelimiterMapping(input: [unknown, unknown] | [unknown]): unknown;
350
354
  export type TModuleDeclarationListMapping<Input extends [unknown, unknown]> = (TPropertiesReduce<TDelimited<Input>>);
351
355
  export declare function ModuleDeclarationListMapping(input: [unknown, unknown]): unknown;
352
- export type TModuleDeclarationMapping<Input extends [unknown, unknown]> = (Input extends [null, infer ModuleDeclaration extends T.TProperties] ? ModuleDeclaration : never);
353
- export declare function ModuleDeclarationMapping(input: [unknown, unknown]): unknown;
356
+ export type TModuleDeclarationMapping<Input extends [unknown, unknown, unknown]> = (Input extends [null, infer ModuleDeclaration extends T.TProperties, null] ? ModuleDeclaration : never);
357
+ export declare function ModuleDeclarationMapping(input: [unknown, unknown, unknown]): unknown;
354
358
  export type TModuleMapping<Input extends [unknown, unknown]> = (Input extends [infer ModuleDeclaration extends T.TProperties, infer ModuleDeclarationList extends [T.TProperties, T.TProperties]] ? C.TModuleDeferred<Memory.TAssign<ModuleDeclaration, ModuleDeclarationList[0]>> : never);
355
359
  export declare function ModuleMapping(input: [unknown, unknown]): unknown;
356
360
  export type TScriptMapping<Input extends unknown> = (Input);
@@ -84,6 +84,9 @@ export function GenericCallArgumentsMapping(input) {
84
84
  export function GenericCallMapping(input) {
85
85
  return IntrinsicOrCall(input[0], input[1]);
86
86
  }
87
+ export function OptionalSemiColonMapping(input) {
88
+ return null;
89
+ }
87
90
  export function KeywordStringMapping(input) {
88
91
  return T.String();
89
92
  }
@@ -235,6 +238,9 @@ export function ExprMapping(input) {
235
238
  const [left, rest] = input;
236
239
  return ExprBinaryMapping(left, rest);
237
240
  }
241
+ export function ExprReadonlyMapping(input) {
242
+ return T.ImmutableAdd(input[1]);
243
+ }
238
244
  export function ExprPipeMapping(input) {
239
245
  return input[1];
240
246
  }
@@ -12,6 +12,7 @@ export type TGenericCallArgumentList_0<Input extends string, Result extends unkn
12
12
  export type TGenericCallArgumentList<Input extends string> = (TGenericCallArgumentList_0<Input> extends [infer _0, infer Input extends string] ? (((TType<Input> extends [infer _0, infer Input extends string] ? [[_0], Input] : []) extends [infer _0, infer Input extends string] ? [_0, Input] : [[], Input] extends [infer _0, infer Input extends string] ? [_0, Input] : []) extends [infer _1, infer Input extends string] ? [[_0, _1], Input] : []) : []) extends [infer _0 extends [unknown, unknown], infer Input extends string] ? [S.TGenericCallArgumentListMapping<_0>, Input] : [];
13
13
  export type TGenericCallArguments<Input extends string> = (Token.TConst<'<', Input> extends [infer _0, infer Input extends string] ? (TGenericCallArgumentList<Input> extends [infer _1, infer Input extends string] ? (Token.TConst<'>', Input> extends [infer _2, infer Input extends string] ? [[_0, _1, _2], Input] : []) : []) : []) extends [infer _0 extends [unknown, unknown, unknown], infer Input extends string] ? [S.TGenericCallArgumentsMapping<_0>, Input] : [];
14
14
  export type TGenericCall<Input extends string> = (Token.TIdent<Input> extends [infer _0, infer Input extends string] ? (TGenericCallArguments<Input> extends [infer _1, infer Input extends string] ? [[_0, _1], Input] : []) : []) extends [infer _0 extends [unknown, unknown], infer Input extends string] ? [S.TGenericCallMapping<_0>, Input] : [];
15
+ export type TOptionalSemiColon<Input extends string> = ((Token.TConst<';', Input> extends [infer _0, infer Input extends string] ? [[_0], 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] | [], infer Input extends string] ? [S.TOptionalSemiColonMapping<_0>, Input] : [];
15
16
  export type TKeywordString<Input extends string> = Token.TConst<'string', Input> extends [infer _0 extends 'string', infer Input extends string] ? [S.TKeywordStringMapping<_0>, Input] : [];
16
17
  export type TKeywordNumber<Input extends string> = Token.TConst<'number', Input> extends [infer _0 extends 'number', infer Input extends string] ? [S.TKeywordNumberMapping<_0>, Input] : [];
17
18
  export type TKeywordBoolean<Input extends string> = Token.TConst<'boolean', Input> extends [infer _0 extends 'boolean', infer Input extends string] ? [S.TKeywordBooleanMapping<_0>, Input] : [];
@@ -47,10 +48,11 @@ export type TExprTermTail<Input extends string> = ((Token.TConst<'&', Input> ext
47
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] : [];
48
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] : [];
49
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] : [];
50
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] : [];
51
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] : [];
52
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] : [];
53
- 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] : [];
54
56
  export type TPropertyKeyNumber<Input extends string> = Token.TNumber<Input> extends [infer _0 extends string, infer Input extends string] ? [S.TPropertyKeyNumberMapping<_0>, Input] : [];
55
57
  export type TPropertyKeyIdent<Input extends string> = Token.TIdent<Input> extends [infer _0 extends string, infer Input extends string] ? [S.TPropertyKeyIdentMapping<_0>, Input] : [];
56
58
  export type TPropertyKeyQuoted<Input extends string> = Token.TString<['\'', '\"'], Input> extends [infer _0 extends string, infer Input extends string] ? [S.TPropertyKeyQuotedMapping<_0>, Input] : [];
@@ -86,7 +88,7 @@ export type TConstructor<Input extends string> = (Token.TConst<'new', Input> ext
86
88
  export type TMappedReadonly<Input extends string> = ((Token.TConst<'+', Input> extends [infer _0, infer Input extends string] ? (Token.TConst<'readonly', Input> extends [infer _1, infer Input extends string] ? [[_0, _1], Input] : []) : []) extends [infer _0, infer Input extends string] ? [_0, Input] : (Token.TConst<'-', Input> extends [infer _0, infer Input extends string] ? (Token.TConst<'readonly', Input> extends [infer _1, infer Input extends string] ? [[_0, _1], Input] : []) : []) extends [infer _0, infer Input extends string] ? [_0, Input] : (Token.TConst<'readonly', Input> extends [infer _0, infer Input extends string] ? [[_0], 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.TMappedReadonlyMapping<_0>, Input] : [];
87
89
  export type TMappedOptional<Input extends string> = ((Token.TConst<'+', Input> extends [infer _0, infer Input extends string] ? (Token.TConst<'?', Input> extends [infer _1, infer Input extends string] ? [[_0, _1], Input] : []) : []) extends [infer _0, infer Input extends string] ? [_0, Input] : (Token.TConst<'-', Input> extends [infer _0, infer Input extends string] ? (Token.TConst<'?', Input> extends [infer _1, infer Input extends string] ? [[_0, _1], Input] : []) : []) extends [infer _0, infer Input extends string] ? [_0, Input] : (Token.TConst<'?', Input> extends [infer _0, infer Input extends string] ? [[_0], 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.TMappedOptionalMapping<_0>, Input] : [];
88
90
  export type TMappedAs<Input extends string> = ((Token.TConst<'as', Input> extends [infer _0, infer Input extends string] ? (TType<Input> extends [infer _1, infer Input extends string] ? [[_0, _1], 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] | [], infer Input extends string] ? [S.TMappedAsMapping<_0>, Input] : [];
89
- export type TMapped<Input extends string> = (Token.TConst<'{', Input> extends [infer _0, infer Input extends string] ? (TMappedReadonly<Input> extends [infer _1, infer Input extends string] ? (Token.TConst<'[', Input> extends [infer _2, infer Input extends string] ? (Token.TIdent<Input> extends [infer _3, infer Input extends string] ? (Token.TConst<'in', Input> extends [infer _4, infer Input extends string] ? (TType<Input> extends [infer _5, infer Input extends string] ? (TMappedAs<Input> extends [infer _6, infer Input extends string] ? (Token.TConst<']', Input> extends [infer _7, infer Input extends string] ? (TMappedOptional<Input> extends [infer _8, infer Input extends string] ? (Token.TConst<':', Input> extends [infer _9, infer Input extends string] ? (TType<Input> extends [infer _10, infer Input extends string] ? (Token.TConst<'}', Input> extends [infer _11, infer Input extends string] ? [[_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11], Input] : []) : []) : []) : []) : []) : []) : []) : []) : []) : []) : []) : []) extends [infer _0 extends [unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown], infer Input extends string] ? [S.TMappedMapping<_0>, Input] : [];
91
+ export type TMapped<Input extends string> = (Token.TConst<'{', Input> extends [infer _0, infer Input extends string] ? (TMappedReadonly<Input> extends [infer _1, infer Input extends string] ? (Token.TConst<'[', Input> extends [infer _2, infer Input extends string] ? (Token.TIdent<Input> extends [infer _3, infer Input extends string] ? (Token.TConst<'in', Input> extends [infer _4, infer Input extends string] ? (TType<Input> extends [infer _5, infer Input extends string] ? (TMappedAs<Input> extends [infer _6, infer Input extends string] ? (Token.TConst<']', Input> extends [infer _7, infer Input extends string] ? (TMappedOptional<Input> extends [infer _8, infer Input extends string] ? (Token.TConst<':', Input> extends [infer _9, infer Input extends string] ? (TType<Input> extends [infer _10, infer Input extends string] ? (TOptionalSemiColon<Input> extends [infer _11, infer Input extends string] ? (Token.TConst<'}', Input> extends [infer _12, infer Input extends string] ? [[_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12], Input] : []) : []) : []) : []) : []) : []) : []) : []) : []) : []) : []) : []) : []) extends [infer _0 extends [unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown], infer Input extends string] ? [S.TMappedMapping<_0>, Input] : [];
90
92
  export type TReference<Input extends string> = Token.TIdent<Input> extends [infer _0 extends string, infer Input extends string] ? [S.TReferenceMapping<_0>, Input] : [];
91
93
  export type TOptions<Input extends string> = (Token.TConst<'Options', 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] ? (Token.TConst<',', Input> extends [infer _3, infer Input extends string] ? (TJsonObject<Input> extends [infer _4, infer Input extends string] ? (Token.TConst<'>', Input> extends [infer _5, infer Input extends string] ? [[_0, _1, _2, _3, _4, _5], Input] : []) : []) : []) : []) : []) : []) extends [infer _0 extends [unknown, unknown, unknown, unknown, unknown, unknown], infer Input extends string] ? [S.TOptionsMapping<_0>, Input] : [];
92
94
  export type TJsonNumber<Input extends string> = Token.TNumber<Input> extends [infer _0 extends string, infer Input extends string] ? [S.TJsonNumberMapping<_0>, Input] : [];
@@ -124,7 +126,7 @@ export type TExportKeyword<Input extends string> = ((Token.TConst<'export', Inpu
124
126
  export type TModuleDeclarationDelimiter<Input extends string> = ((Token.TConst<';', Input> extends [infer _0, infer Input extends string] ? (Token.TConst<'\n', Input> extends [infer _1, infer Input extends string] ? [[_0, _1], Input] : []) : []) extends [infer _0, infer Input extends string] ? [_0, Input] : (Token.TConst<';', Input> extends [infer _0, infer Input extends string] ? [[_0], Input] : []) extends [infer _0, infer Input extends string] ? [_0, Input] : (Token.TConst<'\n', Input> extends [infer _0, infer Input extends string] ? [[_0], Input] : []) extends [infer _0, infer Input extends string] ? [_0, Input] : []) extends [infer _0 extends [unknown, unknown] | [unknown], infer Input extends string] ? [S.TModuleDeclarationDelimiterMapping<_0>, Input] : [];
125
127
  export type TModuleDeclarationList_0<Input extends string, Result extends unknown[] = []> = (TModuleDeclaration<Input> extends [infer _0, infer Input extends string] ? (TModuleDeclarationDelimiter<Input> extends [infer _1, infer Input extends string] ? [[_0, _1], Input] : []) : []) extends [infer _0, infer Input extends string] ? TModuleDeclarationList_0<Input, [...Result, _0]> : [Result, Input];
126
128
  export type TModuleDeclarationList<Input extends string> = (TModuleDeclarationList_0<Input> extends [infer _0, infer Input extends string] ? (((TModuleDeclaration<Input> extends [infer _0, infer Input extends string] ? [[_0], Input] : []) extends [infer _0, infer Input extends string] ? [_0, Input] : [[], Input] extends [infer _0, infer Input extends string] ? [_0, Input] : []) extends [infer _1, infer Input extends string] ? [[_0, _1], Input] : []) : []) extends [infer _0 extends [unknown, unknown], infer Input extends string] ? [S.TModuleDeclarationListMapping<_0>, Input] : [];
127
- export type TModuleDeclaration<Input extends string> = (TExportKeyword<Input> extends [infer _0, infer Input extends string] ? ((TInterfaceDeclarationGeneric<Input> extends [infer _0, infer Input extends string] ? [_0, Input] : TInterfaceDeclaration<Input> extends [infer _0, infer Input extends string] ? [_0, Input] : TTypeAliasDeclarationGeneric<Input> extends [infer _0, infer Input extends string] ? [_0, Input] : TTypeAliasDeclaration<Input> extends [infer _0, infer Input extends string] ? [_0, Input] : []) extends [infer _1, infer Input extends string] ? [[_0, _1], Input] : []) : []) extends [infer _0 extends [unknown, unknown], infer Input extends string] ? [S.TModuleDeclarationMapping<_0>, Input] : [];
129
+ export type TModuleDeclaration<Input extends string> = (TExportKeyword<Input> extends [infer _0, infer Input extends string] ? ((TInterfaceDeclarationGeneric<Input> extends [infer _0, infer Input extends string] ? [_0, Input] : TInterfaceDeclaration<Input> extends [infer _0, infer Input extends string] ? [_0, Input] : TTypeAliasDeclarationGeneric<Input> extends [infer _0, infer Input extends string] ? [_0, Input] : TTypeAliasDeclaration<Input> extends [infer _0, infer Input extends string] ? [_0, Input] : []) extends [infer _1, infer Input extends string] ? (TOptionalSemiColon<Input> extends [infer _2, infer Input extends string] ? [[_0, _1, _2], Input] : []) : []) : []) extends [infer _0 extends [unknown, unknown, unknown], infer Input extends string] ? [S.TModuleDeclarationMapping<_0>, Input] : [];
128
130
  export type TModule<Input extends string> = (TModuleDeclaration<Input> extends [infer _0, infer Input extends string] ? (TModuleDeclarationList<Input> extends [infer _1, infer Input extends string] ? [[_0, _1], Input] : []) : []) extends [infer _0 extends [unknown, unknown], infer Input extends string] ? [S.TModuleMapping<_0>, Input] : [];
129
131
  export type TScript<Input extends string> = (TModule<Input> extends [infer _0, infer Input extends string] ? [_0, Input] : TGenericType<Input> extends [infer _0, infer Input extends string] ? [_0, Input] : TType<Input> extends [infer _0, infer Input extends string] ? [_0, Input] : []) extends [infer _0 extends unknown, infer Input extends string] ? [S.TScriptMapping<_0>, Input] : [];
130
132
  export declare const GenericParameterExtendsEquals: (input: string) => [unknown, string] | [];
@@ -139,6 +141,7 @@ export declare const GenericCallArgumentList_0: (input: string, result?: unknown
139
141
  export declare const GenericCallArgumentList: (input: string) => [unknown, string] | [];
140
142
  export declare const GenericCallArguments: (input: string) => [unknown, string] | [];
141
143
  export declare const GenericCall: (input: string) => [unknown, string] | [];
144
+ export declare const OptionalSemiColon: (input: string) => [unknown, string] | [];
142
145
  export declare const KeywordString: (input: string) => [unknown, string] | [];
143
146
  export declare const KeywordNumber: (input: string) => [unknown, string] | [];
144
147
  export declare const KeywordBoolean: (input: string) => [unknown, string] | [];
@@ -174,6 +177,7 @@ export declare const ExprTermTail: (input: string) => [unknown, string] | [];
174
177
  export declare const ExprTerm: (input: string) => [unknown, string] | [];
175
178
  export declare const ExprTail: (input: string) => [unknown, string] | [];
176
179
  export declare const Expr: (input: string) => [unknown, string] | [];
180
+ export declare const ExprReadonly: (input: string) => [unknown, string] | [];
177
181
  export declare const ExprPipe: (input: string) => [unknown, string] | [];
178
182
  export declare const GenericType: (input: string) => [unknown, string] | [];
179
183
  export declare const InferType: (input: string) => [unknown, string] | [];
@@ -15,6 +15,7 @@ export const GenericCallArgumentList_0 = (input, result = []) => If(If(Type(inpu
15
15
  export const GenericCallArgumentList = (input) => If(If(GenericCallArgumentList_0(input), ([_0, input]) => If(If(If(Type(input), ([_0, input]) => [[_0], input]), ([_0, input]) => [_0, input], () => If([[], input], ([_0, input]) => [_0, input], () => [])), ([_1, input]) => [[_0, _1], input])), ([_0, input]) => [S.GenericCallArgumentListMapping(_0), input]);
16
16
  export const GenericCallArguments = (input) => If(If(Token.Const('<', input), ([_0, input]) => If(GenericCallArgumentList(input), ([_1, input]) => If(Token.Const('>', input), ([_2, input]) => [[_0, _1, _2], input]))), ([_0, input]) => [S.GenericCallArgumentsMapping(_0), input]);
17
17
  export const GenericCall = (input) => If(If(Token.Ident(input), ([_0, input]) => If(GenericCallArguments(input), ([_1, input]) => [[_0, _1], input])), ([_0, input]) => [S.GenericCallMapping(_0), input]);
18
+ export const OptionalSemiColon = (input) => If(If(If(Token.Const(';', input), ([_0, input]) => [[_0], input]), ([_0, input]) => [_0, input], () => If([[], input], ([_0, input]) => [_0, input], () => [])), ([_0, input]) => [S.OptionalSemiColonMapping(_0), input]);
18
19
  export const KeywordString = (input) => If(Token.Const('string', input), ([_0, input]) => [S.KeywordStringMapping(_0), input]);
19
20
  export const KeywordNumber = (input) => If(Token.Const('number', input), ([_0, input]) => [S.KeywordNumberMapping(_0), input]);
20
21
  export const KeywordBoolean = (input) => If(Token.Const('boolean', input), ([_0, input]) => [S.KeywordBooleanMapping(_0), input]);
@@ -50,10 +51,11 @@ export const ExprTermTail = (input) => If(If(If(Token.Const('&', input), ([_0, i
50
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]);
51
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]);
52
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]);
53
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]);
54
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]);
55
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]);
56
- 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]);
57
59
  export const PropertyKeyNumber = (input) => If(Token.Number(input), ([_0, input]) => [S.PropertyKeyNumberMapping(_0), input]);
58
60
  export const PropertyKeyIdent = (input) => If(Token.Ident(input), ([_0, input]) => [S.PropertyKeyIdentMapping(_0), input]);
59
61
  export const PropertyKeyQuoted = (input) => If(Token.String(['\'', '\"'], input), ([_0, input]) => [S.PropertyKeyQuotedMapping(_0), input]);
@@ -89,7 +91,7 @@ export const Constructor = (input) => If(If(Token.Const('new', input), ([_0, inp
89
91
  export const MappedReadonly = (input) => If(If(If(Token.Const('+', input), ([_0, input]) => If(Token.Const('readonly', input), ([_1, input]) => [[_0, _1], input])), ([_0, input]) => [_0, input], () => If(If(Token.Const('-', input), ([_0, input]) => If(Token.Const('readonly', input), ([_1, input]) => [[_0, _1], input])), ([_0, input]) => [_0, input], () => If(If(Token.Const('readonly', input), ([_0, input]) => [[_0], input]), ([_0, input]) => [_0, input], () => If([[], input], ([_0, input]) => [_0, input], () => [])))), ([_0, input]) => [S.MappedReadonlyMapping(_0), input]);
90
92
  export const MappedOptional = (input) => If(If(If(Token.Const('+', input), ([_0, input]) => If(Token.Const('?', input), ([_1, input]) => [[_0, _1], input])), ([_0, input]) => [_0, input], () => If(If(Token.Const('-', input), ([_0, input]) => If(Token.Const('?', input), ([_1, input]) => [[_0, _1], input])), ([_0, input]) => [_0, input], () => If(If(Token.Const('?', input), ([_0, input]) => [[_0], input]), ([_0, input]) => [_0, input], () => If([[], input], ([_0, input]) => [_0, input], () => [])))), ([_0, input]) => [S.MappedOptionalMapping(_0), input]);
91
93
  export const MappedAs = (input) => If(If(If(Token.Const('as', input), ([_0, input]) => If(Type(input), ([_1, input]) => [[_0, _1], input])), ([_0, input]) => [_0, input], () => If([[], input], ([_0, input]) => [_0, input], () => [])), ([_0, input]) => [S.MappedAsMapping(_0), input]);
92
- export const Mapped = (input) => If(If(Token.Const('{', input), ([_0, input]) => If(MappedReadonly(input), ([_1, input]) => If(Token.Const('[', input), ([_2, input]) => If(Token.Ident(input), ([_3, input]) => If(Token.Const('in', input), ([_4, input]) => If(Type(input), ([_5, input]) => If(MappedAs(input), ([_6, input]) => If(Token.Const(']', input), ([_7, input]) => If(MappedOptional(input), ([_8, input]) => If(Token.Const(':', input), ([_9, input]) => If(Type(input), ([_10, input]) => If(Token.Const('}', input), ([_11, input]) => [[_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11], input])))))))))))), ([_0, input]) => [S.MappedMapping(_0), input]);
94
+ export const Mapped = (input) => If(If(Token.Const('{', input), ([_0, input]) => If(MappedReadonly(input), ([_1, input]) => If(Token.Const('[', input), ([_2, input]) => If(Token.Ident(input), ([_3, input]) => If(Token.Const('in', input), ([_4, input]) => If(Type(input), ([_5, input]) => If(MappedAs(input), ([_6, input]) => If(Token.Const(']', input), ([_7, input]) => If(MappedOptional(input), ([_8, input]) => If(Token.Const(':', input), ([_9, input]) => If(Type(input), ([_10, input]) => If(OptionalSemiColon(input), ([_11, input]) => If(Token.Const('}', input), ([_12, input]) => [[_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12], input]))))))))))))), ([_0, input]) => [S.MappedMapping(_0), input]);
93
95
  export const Reference = (input) => If(Token.Ident(input), ([_0, input]) => [S.ReferenceMapping(_0), input]);
94
96
  export const Options = (input) => If(If(Token.Const('Options', input), ([_0, input]) => If(Token.Const('<', input), ([_1, input]) => If(Type(input), ([_2, input]) => If(Token.Const(',', input), ([_3, input]) => If(JsonObject(input), ([_4, input]) => If(Token.Const('>', input), ([_5, input]) => [[_0, _1, _2, _3, _4, _5], input])))))), ([_0, input]) => [S.OptionsMapping(_0), input]);
95
97
  export const JsonNumber = (input) => If(Token.Number(input), ([_0, input]) => [S.JsonNumberMapping(_0), input]);
@@ -127,6 +129,6 @@ export const ExportKeyword = (input) => If(If(If(Token.Const('export', input), (
127
129
  export const ModuleDeclarationDelimiter = (input) => If(If(If(Token.Const(';', input), ([_0, input]) => If(Token.Const('\n', input), ([_1, input]) => [[_0, _1], input])), ([_0, input]) => [_0, input], () => If(If(Token.Const(';', input), ([_0, input]) => [[_0], input]), ([_0, input]) => [_0, input], () => If(If(Token.Const('\n', input), ([_0, input]) => [[_0], input]), ([_0, input]) => [_0, input], () => []))), ([_0, input]) => [S.ModuleDeclarationDelimiterMapping(_0), input]);
128
130
  export const ModuleDeclarationList_0 = (input, result = []) => If(If(ModuleDeclaration(input), ([_0, input]) => If(ModuleDeclarationDelimiter(input), ([_1, input]) => [[_0, _1], input])), ([_0, input]) => ModuleDeclarationList_0(input, [...result, _0]), () => [result, input]);
129
131
  export const ModuleDeclarationList = (input) => If(If(ModuleDeclarationList_0(input), ([_0, input]) => If(If(If(ModuleDeclaration(input), ([_0, input]) => [[_0], input]), ([_0, input]) => [_0, input], () => If([[], input], ([_0, input]) => [_0, input], () => [])), ([_1, input]) => [[_0, _1], input])), ([_0, input]) => [S.ModuleDeclarationListMapping(_0), input]);
130
- export const ModuleDeclaration = (input) => If(If(ExportKeyword(input), ([_0, input]) => If(If(InterfaceDeclarationGeneric(input), ([_0, input]) => [_0, input], () => If(InterfaceDeclaration(input), ([_0, input]) => [_0, input], () => If(TypeAliasDeclarationGeneric(input), ([_0, input]) => [_0, input], () => If(TypeAliasDeclaration(input), ([_0, input]) => [_0, input], () => [])))), ([_1, input]) => [[_0, _1], input])), ([_0, input]) => [S.ModuleDeclarationMapping(_0), input]);
132
+ export const ModuleDeclaration = (input) => If(If(ExportKeyword(input), ([_0, input]) => If(If(InterfaceDeclarationGeneric(input), ([_0, input]) => [_0, input], () => If(InterfaceDeclaration(input), ([_0, input]) => [_0, input], () => If(TypeAliasDeclarationGeneric(input), ([_0, input]) => [_0, input], () => If(TypeAliasDeclaration(input), ([_0, input]) => [_0, input], () => [])))), ([_1, input]) => If(OptionalSemiColon(input), ([_2, input]) => [[_0, _1, _2], input]))), ([_0, input]) => [S.ModuleDeclarationMapping(_0), input]);
131
133
  export const Module = (input) => If(If(ModuleDeclaration(input), ([_0, input]) => If(ModuleDeclarationList(input), ([_1, input]) => [[_0, _1], input])), ([_0, input]) => [S.ModuleMapping(_0), input]);
132
134
  export const Script = (input) => If(If(Module(input), ([_0, input]) => [_0, input], () => If(GenericType(input), ([_0, input]) => [_0, input], () => If(Type(input), ([_0, input]) => [_0, input], () => []))), ([_0, input]) => [S.ScriptMapping(_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.34",
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