typebox 1.2.2 → 1.2.3
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.
- package/build/type/action/conditional.d.mts +2 -3
- package/build/type/action/conditional.mjs +2 -1
- package/build/type/action/mapped.d.mts +2 -3
- package/build/type/action/mapped.mjs +2 -1
- package/build/type/engine/call/instantiate.d.mts +1 -3
- package/build/type/engine/call/instantiate.mjs +3 -2
- package/build/type/engine/constructor_parameters/instantiate.d.mts +3 -4
- package/build/type/engine/constructor_parameters/instantiate.mjs +2 -1
- package/build/type/engine/cyclic/instantiate.d.mts +2 -5
- package/build/type/engine/cyclic/instantiate.mjs +3 -2
- package/build/type/engine/instantiate.d.mts +5 -5
- package/build/type/engine/instantiate.mjs +4 -1
- package/build/type/engine/interface/instantiate.d.mts +3 -6
- package/build/type/engine/module/instantiate.d.mts +1 -3
- package/build/type/engine/module/instantiate.mjs +2 -1
- package/build/type/engine/parameters/instantiate.d.mts +3 -4
- package/build/type/engine/parameters/instantiate.mjs +2 -1
- package/build/type/engine/ref/instantiate.d.mts +3 -3
- package/build/type/engine/ref/instantiate.mjs +6 -6
- package/build/type/extends/tuple.d.mts +3 -6
- package/build/type/extends/tuple.mjs +3 -2
- package/build/type/script/script.d.mts +3 -4
- package/build/type/script/script.mjs +3 -2
- package/build/type/types/call.d.mts +3 -3
- package/build/type/types/call.mjs +3 -2
- package/package.json +1 -1
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { type TSchema, type TSchemaOptions } from '../types/schema.mjs';
|
|
2
2
|
import { type TDeferred } from '../types/deferred.mjs';
|
|
3
3
|
import { type TConditionalAction } from '../engine/conditional/instantiate.mjs';
|
|
4
|
+
import { type TState } from '../engine/instantiate.mjs';
|
|
4
5
|
/** Creates a deferred Conditional action. */
|
|
5
6
|
export type TConditionalDeferred<Left extends TSchema, Right extends TSchema, True extends TSchema, False extends TSchema> = (TDeferred<'Conditional', [Left, Right, True, False]>);
|
|
6
7
|
/** Creates a deferred Conditional action. */
|
|
7
8
|
export declare function ConditionalDeferred<Left extends TSchema, Right extends TSchema, True extends TSchema, False extends TSchema>(left: Left, right: Right, true_: True, false_: False, options?: TSchemaOptions): TConditionalDeferred<Left, Right, True, False>;
|
|
8
9
|
/** Applies a Conditional action to the given types. */
|
|
9
|
-
export type TConditional<Left extends TSchema, Right extends TSchema, True extends TSchema, False extends TSchema> = (TConditionalAction<{},
|
|
10
|
-
callstack: [];
|
|
11
|
-
}, Left, Right, True, False>);
|
|
10
|
+
export type TConditional<Left extends TSchema, Right extends TSchema, True extends TSchema, False extends TSchema> = (TConditionalAction<{}, TState<[], []>, Left, Right, True, False>);
|
|
12
11
|
/** Applies a Conditional action to the given types. */
|
|
13
12
|
export declare function Conditional<Left extends TSchema, Right extends TSchema, True extends TSchema, False extends TSchema>(left: Left, right: Right, true_: True, false_: False, options?: TSchemaOptions): TConditional<Left, Right, True, False>;
|
|
@@ -2,11 +2,12 @@
|
|
|
2
2
|
// deno-fmt-ignore-file
|
|
3
3
|
import { Deferred } from '../types/deferred.mjs';
|
|
4
4
|
import { ConditionalAction } from '../engine/conditional/instantiate.mjs';
|
|
5
|
+
import { State } from '../engine/instantiate.mjs';
|
|
5
6
|
/** Creates a deferred Conditional action. */
|
|
6
7
|
export function ConditionalDeferred(left, right, true_, false_, options = {}) {
|
|
7
8
|
return Deferred('Conditional', [left, right, true_, false_], options);
|
|
8
9
|
}
|
|
9
10
|
/** Applies a Conditional action to the given types. */
|
|
10
11
|
export function Conditional(left, right, true_, false_, options = {}) {
|
|
11
|
-
return ConditionalAction({},
|
|
12
|
+
return ConditionalAction({}, State([], []), left, right, true_, false_, options);
|
|
12
13
|
}
|
|
@@ -2,13 +2,12 @@ import { type TSchema, type TSchemaOptions } from '../types/schema.mjs';
|
|
|
2
2
|
import { type TIdentifier } from '../types/identifier.mjs';
|
|
3
3
|
import { type TDeferred } from '../types/deferred.mjs';
|
|
4
4
|
import { type TMappedAction } from '../engine/mapped/instantiate.mjs';
|
|
5
|
+
import { type TState } from '../engine/instantiate.mjs';
|
|
5
6
|
/** Creates a deferred Mapped action. */
|
|
6
7
|
export type TMappedDeferred<Identifier extends TIdentifier, Type extends TSchema, As extends TSchema, Property extends TSchema> = (TDeferred<'Mapped', [Identifier, Type, As, Property]>);
|
|
7
8
|
/** Creates a deferred Mapped action. */
|
|
8
9
|
export declare function MappedDeferred<Identifier extends TIdentifier, Type extends TSchema, As extends TSchema, Property extends TSchema>(identifier: Identifier, type: Type, as: As, property: Property, options?: TSchemaOptions): TMappedDeferred<Identifier, Type, As, Property>;
|
|
9
10
|
/** Applies a Mapped action using the given types. */
|
|
10
|
-
export type TMapped<Identifier extends TIdentifier, Type extends TSchema, As extends TSchema, Property extends TSchema> = (TMappedAction<{},
|
|
11
|
-
callstack: [];
|
|
12
|
-
}, Identifier, Type, As, Property>);
|
|
11
|
+
export type TMapped<Identifier extends TIdentifier, Type extends TSchema, As extends TSchema, Property extends TSchema> = (TMappedAction<{}, TState<[], []>, Identifier, Type, As, Property>);
|
|
13
12
|
/** Applies a Mapped action using the given types. */
|
|
14
13
|
export declare function Mapped<Identifier extends TIdentifier, Type extends TSchema, As extends TSchema, Property extends TSchema>(identifier: Identifier, type: Type, as: As, property: Property, options?: TSchemaOptions): TMapped<Identifier, Type, As, Property>;
|
|
@@ -2,11 +2,12 @@
|
|
|
2
2
|
// deno-fmt-ignore-file
|
|
3
3
|
import { Deferred } from '../types/deferred.mjs';
|
|
4
4
|
import { MappedAction } from '../engine/mapped/instantiate.mjs';
|
|
5
|
+
import { State } from '../engine/instantiate.mjs';
|
|
5
6
|
/** Creates a deferred Mapped action. */
|
|
6
7
|
export function MappedDeferred(identifier, type, as, property, options = {}) {
|
|
7
8
|
return Deferred('Mapped', [identifier, type, as, property], options);
|
|
8
9
|
}
|
|
9
10
|
/** Applies a Mapped action using the given types. */
|
|
10
11
|
export function Mapped(identifier, type, as, property, options = {}) {
|
|
11
|
-
return MappedAction({},
|
|
12
|
+
return MappedAction({}, State([], []), identifier, type, as, property, options);
|
|
12
13
|
}
|
|
@@ -13,9 +13,7 @@ import { type TResolveTarget } from './resolve_target.mjs';
|
|
|
13
13
|
import { type TResolveArgumentsContext } from './resolve_arguments.mjs';
|
|
14
14
|
type TPeek<State extends TState, Result extends string = State['callstack'] extends [...infer _ extends string[], infer Top extends string] ? Top : ''> = Result;
|
|
15
15
|
type TIsTailCall<State extends TState, Name extends string, Result extends boolean = TPeek<State> extends Name ? true : false> = Result;
|
|
16
|
-
type TCallDispatch<Context extends TProperties, State extends TState, Target extends TRef, Parameters extends TParameter[], Expression extends TSchema, Arguments extends TSchema[], ArgumentsContext extends TProperties = TResolveArgumentsContext<Context, State, Parameters, Arguments>, ReturnType extends TSchema = TInstantiateType<ArgumentsContext,
|
|
17
|
-
callstack: [...State['callstack'], Target['$ref']];
|
|
18
|
-
}, Expression>> = TInstantiateType<Context, State, ReturnType>;
|
|
16
|
+
type TCallDispatch<Context extends TProperties, State extends TState, Target extends TRef, Parameters extends TParameter[], Expression extends TSchema, Arguments extends TSchema[], ArgumentsContext extends TProperties = TResolveArgumentsContext<Context, State, Parameters, Arguments>, ReturnType extends TSchema = TInstantiateType<ArgumentsContext, TState<[...State['callstack'], Target['$ref']], State['visited']>, Expression>> = TInstantiateType<ArgumentsContext, TState<[], []>, ReturnType>;
|
|
19
17
|
type TCallDistributed<Context extends TProperties, State extends TState, Target extends TRef, Parameters extends TParameter[], Expression extends TSchema, DistributedArguments extends TSchema[][], Result extends TSchema[] = []> = (DistributedArguments extends [infer Arguments extends TSchema[], ...infer DistributedArguments extends TSchema[][]] ? TCallDispatch<Context, State, Target, Parameters, Expression, Arguments> extends infer ReturnType extends TSchema ? TCallDistributed<Context, State, Target, Parameters, Expression, DistributedArguments, [...Result, ReturnType]> : never : Result);
|
|
20
18
|
type TCallImmediate<Context extends TProperties, State extends TState, Target extends TRef, Parameters extends TParameter[], Expression extends TSchema, InstantiatedArguments extends TSchema[], DistributedArguments extends TSchema[][] = TDistributeArguments<Parameters, InstantiatedArguments, Expression>, ReturnTypes extends TSchema[] = TCallDistributed<Context, State, Target, Parameters, Expression, DistributedArguments>, Result extends TSchema = ReturnTypes['length'] extends 1 ? ReturnTypes[0] : TEvaluateUnion<ReturnTypes>> = Result;
|
|
21
19
|
export type TCallInstantiate<Context extends TProperties, State extends TState, Target extends TSchema, Arguments extends TSchema[], InstantiatedArguments extends TSchema[] = TInstantiateTypes<Context, State, Arguments>, Resolved extends [string, TSchema] = TResolveTarget<Context, Target, Arguments>, Name extends string = Resolved[0], Type extends TSchema = Resolved[1], Result extends TSchema = (Type extends TGeneric<infer Parameters extends TParameter[], infer Expression extends TSchema> ? TIsTailCall<State, Name> extends true ? TCallConstruct<TRef<Name>, InstantiatedArguments> : TCallImmediate<Context, State, TRef<Name>, Parameters, Expression, InstantiatedArguments> : TCallConstruct<Target, InstantiatedArguments>)> = Result;
|
|
@@ -6,6 +6,7 @@ import { IsGeneric } from '../../types/generic.mjs';
|
|
|
6
6
|
import { EvaluateUnion } from '../evaluate/index.mjs';
|
|
7
7
|
import { InstantiateType } from '../instantiate.mjs';
|
|
8
8
|
import { InstantiateTypes } from '../instantiate.mjs';
|
|
9
|
+
import { State } from '../instantiate.mjs';
|
|
9
10
|
// ------------------------------------------------------------------
|
|
10
11
|
// Infrastructure
|
|
11
12
|
// ------------------------------------------------------------------
|
|
@@ -22,8 +23,8 @@ function IsTailCall(state, name) {
|
|
|
22
23
|
}
|
|
23
24
|
function CallDispatch(context, state, target, parameters, expression, arguments_) {
|
|
24
25
|
const argumentsContext = ResolveArgumentsContext(context, state, parameters, arguments_);
|
|
25
|
-
const returnType = InstantiateType(argumentsContext,
|
|
26
|
-
return InstantiateType(
|
|
26
|
+
const returnType = InstantiateType(argumentsContext, State([...state['callstack'], target['$ref']], state['visited']), expression);
|
|
27
|
+
return InstantiateType(argumentsContext, State([], []), returnType);
|
|
27
28
|
}
|
|
28
29
|
function CallDistributed(context, state, target, parameters, expression, distributedArguments) {
|
|
29
30
|
return distributedArguments.reduce((result, arguments_) => [...result, CallDispatch(context, state, target, parameters, expression, arguments_)], []);
|
|
@@ -3,11 +3,10 @@ import { type TProperties } from '../../types/properties.mjs';
|
|
|
3
3
|
import { type TConstructor } from '../../types/constructor.mjs';
|
|
4
4
|
import { type TTuple } from '../../types/tuple.mjs';
|
|
5
5
|
import { type TConstructorParametersDeferred } from '../../action/constructor_parameters.mjs';
|
|
6
|
-
import { type
|
|
6
|
+
import { type TInstantiateType, type TCanInstantiate } from '../instantiate.mjs';
|
|
7
7
|
import { type TInstantiateElements } from '../instantiate.mjs';
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}, Parameters>, Result extends TSchema = TTuple<InstantiatedParameters>> = Result;
|
|
8
|
+
import { type TState } from '../instantiate.mjs';
|
|
9
|
+
type TConstructorParametersOperation<Type extends TSchema, Parameters extends TSchema[] = Type extends TConstructor ? Type['parameters'] : [], InstantiatedParameters extends TSchema[] = TInstantiateElements<{}, TState<[], []>, Parameters>, Result extends TSchema = TTuple<InstantiatedParameters>> = Result;
|
|
11
10
|
export type TConstructorParametersAction<Type extends TSchema, Result extends TSchema = TCanInstantiate<[Type]> extends true ? TConstructorParametersOperation<Type> : TConstructorParametersDeferred<Type>> = Result;
|
|
12
11
|
export declare function ConstructorParametersAction<Type extends TSchema>(type: Type, options: TSchemaOptions): TConstructorParametersAction<Type>;
|
|
13
12
|
export type TConstructorParametersInstantiate<Context extends TProperties, State extends TState, Type extends TSchema, InstantiatedType extends TSchema = TInstantiateType<Context, State, Type>> = TConstructorParametersAction<InstantiatedType>;
|
|
@@ -6,9 +6,10 @@ import { Tuple } from '../../types/tuple.mjs';
|
|
|
6
6
|
import { ConstructorParametersDeferred } from '../../action/constructor_parameters.mjs';
|
|
7
7
|
import { InstantiateType, CanInstantiate } from '../instantiate.mjs';
|
|
8
8
|
import { InstantiateElements } from '../instantiate.mjs';
|
|
9
|
+
import { State } from '../instantiate.mjs';
|
|
9
10
|
function ConstructorParametersOperation(type) {
|
|
10
11
|
const parameters = IsConstructor(type) ? type['parameters'] : [];
|
|
11
|
-
const instantiatedParameters = InstantiateElements({},
|
|
12
|
+
const instantiatedParameters = InstantiateElements({}, State([], []), parameters);
|
|
12
13
|
const result = Tuple(instantiatedParameters);
|
|
13
14
|
return result;
|
|
14
15
|
}
|
|
@@ -6,12 +6,9 @@ import { type TCyclicDependencies } from '../cyclic/dependencies.mjs';
|
|
|
6
6
|
import { type TInterfaceDeferred } from '../../action/index.mjs';
|
|
7
7
|
import { type TInstantiateProperties } from '../instantiate.mjs';
|
|
8
8
|
import { type TInstantiateTypes } from '../instantiate.mjs';
|
|
9
|
+
import { type TState } from '../instantiate.mjs';
|
|
9
10
|
import { type TEvaluateIntersect } from '../evaluate/evaluate.mjs';
|
|
10
|
-
type TCyclicInterface<Context extends TProperties, Heritage extends TSchema[], Properties extends TProperties, InstantiatedHeritage extends TSchema[] = TInstantiateTypes<Context, {
|
|
11
|
-
callstack: [];
|
|
12
|
-
}, Heritage>, instantiatedProperties extends TProperties = TInstantiateProperties<{}, {
|
|
13
|
-
callstack: [];
|
|
14
|
-
}, Properties>, EvaluatedInterface extends TSchema = TEvaluateIntersect<[...InstantiatedHeritage, TObject<instantiatedProperties>]>> = EvaluatedInterface;
|
|
11
|
+
type TCyclicInterface<Context extends TProperties, Heritage extends TSchema[], Properties extends TProperties, InstantiatedHeritage extends TSchema[] = TInstantiateTypes<Context, TState<[], []>, Heritage>, instantiatedProperties extends TProperties = TInstantiateProperties<{}, TState<[], []>, Properties>, EvaluatedInterface extends TSchema = TEvaluateIntersect<[...InstantiatedHeritage, TObject<instantiatedProperties>]>> = EvaluatedInterface;
|
|
15
12
|
type TCyclicDefinitions<Context extends TProperties, Dependencies extends string[], Result extends TProperties = {
|
|
16
13
|
[Key in Extract<keyof Context, Dependencies[number]>]: Context[Key] extends TInterfaceDeferred<infer Heritage extends TSchema[], infer Properties extends TProperties> ? TCyclicInterface<Context, Heritage, Properties> : Context[Key];
|
|
17
14
|
}> = Result;
|
|
@@ -7,10 +7,11 @@ import { CyclicDependencies } from '../cyclic/dependencies.mjs';
|
|
|
7
7
|
import { IsInterfaceDeferred } from '../../action/index.mjs';
|
|
8
8
|
import { InstantiateProperties } from '../instantiate.mjs';
|
|
9
9
|
import { InstantiateTypes } from '../instantiate.mjs';
|
|
10
|
+
import { State } from '../instantiate.mjs';
|
|
10
11
|
import { EvaluateIntersect } from '../evaluate/evaluate.mjs';
|
|
11
12
|
function CyclicInterface(context, heritage, properties) {
|
|
12
|
-
const instantiatedHeritage = InstantiateTypes(context,
|
|
13
|
-
const instantiatedProperties = InstantiateProperties({},
|
|
13
|
+
const instantiatedHeritage = InstantiateTypes(context, State([], []), heritage);
|
|
14
|
+
const instantiatedProperties = InstantiateProperties({}, State([], []), properties);
|
|
14
15
|
const evaluatedInterface = EvaluateIntersect([...instantiatedHeritage, Object(instantiatedProperties)]);
|
|
15
16
|
return evaluatedInterface;
|
|
16
17
|
}
|
|
@@ -52,9 +52,11 @@ import { type TUncapitalizeInstantiate } from './intrinsics/instantiate.mjs';
|
|
|
52
52
|
import { type TUppercaseInstantiate } from './intrinsics/instantiate.mjs';
|
|
53
53
|
import { type TWithInstantiate } from './with/instantiate.mjs';
|
|
54
54
|
import { type TRestSpread } from './rest/index.mjs';
|
|
55
|
-
export interface TState {
|
|
56
|
-
callstack:
|
|
55
|
+
export interface TState<CallStack extends string[] = string[], Visited extends string[] = string[]> {
|
|
56
|
+
callstack: CallStack;
|
|
57
|
+
visited: Visited;
|
|
57
58
|
}
|
|
59
|
+
export declare function State<CallStack extends string[], Visited extends string[]>(callstack: CallStack, visited: Visited): TState<CallStack, Visited>;
|
|
58
60
|
export type TCanInstantiate<Types extends TSchema[]> = Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? Left extends TRef ? false : TCanInstantiate<Right> : true;
|
|
59
61
|
export declare function CanInstantiate<Types extends TSchema[]>(types: [...Types]): TCanInstantiate<Types>;
|
|
60
62
|
type ModifierAction = 'add' | 'remove' | 'none';
|
|
@@ -158,9 +160,7 @@ type TInstantiateDeferred<Context extends TProperties, State extends TState, Act
|
|
|
158
160
|
export type TInstantiateType<Context extends TProperties, State extends TState, Input extends TSchema, Immutable extends boolean = Input extends TImmutable ? true : false, Modifiers extends [TSchema, ModifierAction, ModifierAction] = TModifierActions<Input, Input extends TReadonly<Input> ? 'add' : 'none', Input extends TOptional<Input> ? 'add' : 'none'>, Type extends TSchema = Modifiers[0], Instantiated extends TSchema = (Type extends TRef<infer Ref extends string> ? TRefInstantiate<Context, State, Type, 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 TDependent<infer If extends TSchema, infer Then extends TSchema, infer Else extends TSchema> ? TDependent<TInstantiateType<Context, State, If>, TInstantiateType<Context, State, Then>, TInstantiateType<Context, State, Else>> : 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 = Immutable extends true ? TImmutable<Instantiated> : Instantiated, WithModifiers extends TSchema = TApplyReadonly<Modifiers[1], TApplyOptional<Modifiers[2], WithImmutable>>> = WithModifiers;
|
|
159
161
|
export declare function InstantiateType<Context extends TProperties, State extends TState, Type extends TSchema>(context: Context, state: State, input: Type): TInstantiateType<Context, State, Type>;
|
|
160
162
|
/** Instantiates computed schematics using the given context and type. */
|
|
161
|
-
export type TInstantiate<Context extends TProperties, Type extends TSchema> = (TInstantiateType<Context,
|
|
162
|
-
callstack: [];
|
|
163
|
-
}, Type>);
|
|
163
|
+
export type TInstantiate<Context extends TProperties, Type extends TSchema> = (TInstantiateType<Context, TState<[], []>, Type>);
|
|
164
164
|
/** Instantiates computed schematics using the given context and type. */
|
|
165
165
|
export declare function Instantiate<Context extends TProperties, Type extends TSchema>(context: Context, type: Type): TInstantiate<Context, Type>;
|
|
166
166
|
export {};
|
|
@@ -65,6 +65,9 @@ import { UncapitalizeInstantiate } from './intrinsics/instantiate.mjs';
|
|
|
65
65
|
import { UppercaseInstantiate } from './intrinsics/instantiate.mjs';
|
|
66
66
|
import { WithInstantiate } from './with/instantiate.mjs';
|
|
67
67
|
import { RestSpread } from './rest/index.mjs';
|
|
68
|
+
export function State(callstack, visited) {
|
|
69
|
+
return { callstack, visited };
|
|
70
|
+
}
|
|
68
71
|
export function CanInstantiate(types) {
|
|
69
72
|
return Guard.TakeLeft(types, (left, right) => IsRef(left)
|
|
70
73
|
? false
|
|
@@ -157,5 +160,5 @@ export function InstantiateType(context, state, input) {
|
|
|
157
160
|
}
|
|
158
161
|
/** Instantiates computed schematics using the given context and type. */
|
|
159
162
|
export function Instantiate(context, type) {
|
|
160
|
-
return InstantiateType(context,
|
|
163
|
+
return InstantiateType(context, State([], []), type);
|
|
161
164
|
}
|
|
@@ -3,16 +3,13 @@ import { type TProperties } from '../../types/properties.mjs';
|
|
|
3
3
|
import { type TObject } from '../../types/object.mjs';
|
|
4
4
|
import { type TEvaluateIntersect } from '../evaluate/evaluate.mjs';
|
|
5
5
|
import { type TInterfaceDeferred } from '../../action/index.mjs';
|
|
6
|
-
import { type
|
|
6
|
+
import { type TCanInstantiate } from '../instantiate.mjs';
|
|
7
7
|
import { type TInstantiateProperties } from '../instantiate.mjs';
|
|
8
8
|
import { type TInstantiateTypes } from '../instantiate.mjs';
|
|
9
|
+
import { type TState } from '../instantiate.mjs';
|
|
9
10
|
type TInterfaceOperation<Heritage extends TSchema[], Properties extends TProperties, Result extends TSchema = TEvaluateIntersect<[...Heritage, TObject<Properties>]>> = Result;
|
|
10
11
|
export type TInterfaceAction<Heritage extends TSchema[], Properties extends TProperties, Result extends TSchema = TCanInstantiate<Heritage> extends true ? TInterfaceOperation<Heritage, Properties> : TInterfaceDeferred<Heritage, Properties>> = Result;
|
|
11
12
|
export declare function InterfaceAction<Heritage extends TSchema[], Properties extends TProperties>(heritage: [...Heritage], properties: Properties, options: TSchemaOptions): TInterfaceAction<Heritage, Properties>;
|
|
12
|
-
export type TInterfaceInstantiate<Context extends TProperties, State extends TState, Heritage extends TSchema[], Properties extends TProperties, InstantiatedHeritage extends TSchema[] = TInstantiateTypes<Context,
|
|
13
|
-
callstack: [];
|
|
14
|
-
}, Heritage>, InstantiatedProperties extends TProperties = TInstantiateProperties<Context, {
|
|
15
|
-
callstack: [];
|
|
16
|
-
}, Properties>> = TInterfaceAction<InstantiatedHeritage, InstantiatedProperties>;
|
|
13
|
+
export type TInterfaceInstantiate<Context extends TProperties, State extends TState, Heritage extends TSchema[], Properties extends TProperties, InstantiatedHeritage extends TSchema[] = TInstantiateTypes<Context, State, Heritage>, InstantiatedProperties extends TProperties = TInstantiateProperties<Context, State, Properties>> = TInterfaceAction<InstantiatedHeritage, InstantiatedProperties>;
|
|
17
14
|
export declare function InterfaceInstantiate<Context extends TProperties, State extends TState, Heritage extends TSchema[], Properties extends TProperties>(context: Context, state: State, heritage: [...Heritage], properties: Properties, options: TSchemaOptions): TInterfaceInstantiate<Context, State, Heritage, Properties>;
|
|
18
15
|
export {};
|
|
@@ -9,9 +9,7 @@ type TInstantiateCyclics<Context extends TProperties, CyclicKeys extends string[
|
|
|
9
9
|
[Key in Extract<keyof Context, CyclicKeys[number]>]: TInstantiateCyclic<Context, Key, Context[Key]>;
|
|
10
10
|
}> = Result;
|
|
11
11
|
type TInstantiateNonCyclics<Context extends TProperties, CyclicKeys extends string[], Result extends TProperties = {
|
|
12
|
-
[Key in Exclude<keyof Context, CyclicKeys[number]>]: TInstantiateType<Context,
|
|
13
|
-
callstack: [];
|
|
14
|
-
}, Context[Key]>;
|
|
12
|
+
[Key in Exclude<keyof Context, CyclicKeys[number]>]: TInstantiateType<Context, TState<[], []>, Context[Key]>;
|
|
15
13
|
}> = Result;
|
|
16
14
|
type TInstantiateModule<Context extends TProperties, CyclicCandidates extends string[] = TCyclicCandidates<Context>, InstantiatedCyclics extends TProperties = TInstantiateCyclics<Context, CyclicCandidates>, InstantiatedNonCyclics extends TProperties = TInstantiateNonCyclics<Context, CyclicCandidates>, InstantiatedModule extends TProperties = InstantiatedCyclics & InstantiatedNonCyclics> = {
|
|
17
15
|
[Key in keyof InstantiatedModule]: InstantiatedModule[Key];
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// deno-fmt-ignore-file
|
|
3
3
|
import { Guard } from '../../../guard/index.mjs';
|
|
4
4
|
import { Memory } from '../../../system/memory/index.mjs';
|
|
5
|
+
import { State } from '../instantiate.mjs';
|
|
5
6
|
// ------------------------------------------------------------------
|
|
6
7
|
// Module: Instantiation Infrastructure
|
|
7
8
|
// ------------------------------------------------------------------
|
|
@@ -17,7 +18,7 @@ function InstantiateCyclics(context, cyclicKeys) {
|
|
|
17
18
|
function InstantiateNonCyclics(context, cyclicKeys) {
|
|
18
19
|
const keys = Guard.Keys(context).filter(key => !cyclicKeys.includes(key));
|
|
19
20
|
return keys.reduce((result, key) => {
|
|
20
|
-
return { ...result, [key]: InstantiateType(context,
|
|
21
|
+
return { ...result, [key]: InstantiateType(context, State([], []), context[key]) };
|
|
21
22
|
}, {});
|
|
22
23
|
}
|
|
23
24
|
function InstantiateModule(context, options) {
|
|
@@ -3,11 +3,10 @@ import { type TProperties } from '../../types/properties.mjs';
|
|
|
3
3
|
import { type TFunction } from '../../types/function.mjs';
|
|
4
4
|
import { type TTuple } from '../../types/tuple.mjs';
|
|
5
5
|
import { type TParametersDeferred } from '../../action/parameters.mjs';
|
|
6
|
-
import { type
|
|
6
|
+
import { type TInstantiateType, type TCanInstantiate } from '../instantiate.mjs';
|
|
7
7
|
import { type TInstantiateElements } from '../instantiate.mjs';
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}, Parameters>, Result extends TSchema = TTuple<InstantiatedParameters>> = Result;
|
|
8
|
+
import { type TState } from '../instantiate.mjs';
|
|
9
|
+
type TParametersOperation<Type extends TSchema, Parameters extends TSchema[] = Type extends TFunction ? Type['parameters'] : [], InstantiatedParameters extends TSchema[] = TInstantiateElements<{}, TState<[], []>, Parameters>, Result extends TSchema = TTuple<InstantiatedParameters>> = Result;
|
|
11
10
|
export type TParametersAction<Type extends TSchema, Result extends TSchema = TCanInstantiate<[Type]> extends true ? TParametersOperation<Type> : TParametersDeferred<Type>> = Result;
|
|
12
11
|
export declare function ParametersAction<Type extends TSchema>(type: Type, options: TSchemaOptions): TParametersAction<Type>;
|
|
13
12
|
export type TParametersInstantiate<Context extends TProperties, State extends TState, Type extends TSchema, InstantiatedType extends TSchema = TInstantiateType<Context, State, Type>> = TParametersAction<InstantiatedType>;
|
|
@@ -6,9 +6,10 @@ import { Tuple } from '../../types/tuple.mjs';
|
|
|
6
6
|
import { ParametersDeferred } from '../../action/parameters.mjs';
|
|
7
7
|
import { InstantiateType, CanInstantiate } from '../instantiate.mjs';
|
|
8
8
|
import { InstantiateElements } from '../instantiate.mjs';
|
|
9
|
+
import { State } from '../instantiate.mjs';
|
|
9
10
|
function ParametersOperation(type) {
|
|
10
11
|
const parameters = IsFunction(type) ? type['parameters'] : [];
|
|
11
|
-
const instantiatedParameters = InstantiateElements({},
|
|
12
|
+
const instantiatedParameters = InstantiateElements({}, State([], []), parameters);
|
|
12
13
|
const result = Tuple(instantiatedParameters);
|
|
13
14
|
return result;
|
|
14
15
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type TProperties } from '../../types/properties.mjs';
|
|
2
|
-
import { type
|
|
3
|
-
import { type TCyclicCheck } from '../cyclic/check.mjs';
|
|
2
|
+
import { type TInstantiateType } from '../instantiate.mjs';
|
|
4
3
|
import { type TRef } from '../../types/ref.mjs';
|
|
5
|
-
|
|
4
|
+
import { type TState } from '../instantiate.mjs';
|
|
5
|
+
export type TRefInstantiate<Context extends TProperties, State extends TState, Type extends TRef, Ref extends string> = (Ref extends State['visited'][number] ? Type : Ref extends keyof Context ? TInstantiateType<Context, TState<State['callstack'], [...State['visited'], Ref]>, Context[Ref]> : Type);
|
|
6
6
|
export declare function RefInstantiate<Context extends TProperties, State extends TState, Type extends TRef, Ref extends string>(context: Context, state: State, type: Type, ref: Ref): TRefInstantiate<Context, State, Type, Ref>;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// deno-fmt-ignore-file
|
|
2
2
|
import { InstantiateType } from '../instantiate.mjs';
|
|
3
|
-
import {
|
|
3
|
+
import { State } from '../instantiate.mjs';
|
|
4
4
|
export function RefInstantiate(context, state, type, ref) {
|
|
5
|
-
return (ref
|
|
6
|
-
?
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
return (state.visited.includes(ref)
|
|
6
|
+
? type
|
|
7
|
+
: ref in context
|
|
8
|
+
? InstantiateType(context, State(state['callstack'], [...state['visited'], ref]), context[ref])
|
|
9
|
+
: type);
|
|
10
10
|
}
|
|
@@ -6,6 +6,7 @@ import { type TExtendsLeft } from './extends_left.mjs';
|
|
|
6
6
|
import { type TExtendsRight } from './extends_right.mjs';
|
|
7
7
|
import * as Result from './result.mjs';
|
|
8
8
|
import { type TInstantiateElements } from '../engine/instantiate.mjs';
|
|
9
|
+
import { type TState } from '../engine/instantiate.mjs';
|
|
9
10
|
import { type TTryRestInferable, type TTryInferable, type TInferable, type TInferTupleResult, type TInferUnionResult } from './inference.mjs';
|
|
10
11
|
type TReverse<Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TReverse<Right, [Left, ...Result]> : Result);
|
|
11
12
|
type TApplyReverse<Types extends TSchema[], Reversed extends boolean> = Reversed extends true ? TReverse<Types> : Types;
|
|
@@ -14,12 +15,8 @@ type TElementsCompare<Inferred extends TProperties, Reversed extends boolean, Le
|
|
|
14
15
|
type TElementsLeft<Inferred extends TProperties, Reversed extends boolean, LeftRest extends TSchema[], Right extends TSchema, RightRest extends TSchema[], Inferable extends TInferable | undefined = TTryRestInferable<Right>> = (Inferable extends TInferable ? TInferTupleResult<Inferred, Inferable['name'], TApplyReverse<LeftRest, Reversed>, Inferable['type']> : LeftRest extends [infer Head extends TSchema, ...infer Tail extends TSchema[]] ? TElementsCompare<Inferred, Reversed, Head, Tail, Right, RightRest> : Result.TExtendsFalse);
|
|
15
16
|
type TElementsRight<Inferred extends TProperties, Reversed extends boolean, LeftRest extends TSchema[], RightRest extends TSchema[]> = (RightRest extends [infer Head extends TSchema, ...infer Tail extends TSchema[]] ? TElementsLeft<Inferred, Reversed, LeftRest, Head, Tail> : LeftRest['length'] extends 0 ? Result.TExtendsTrue<Inferred> : Result.TExtendsFalse);
|
|
16
17
|
type TElements<Inferred extends TProperties, Reversed extends boolean, LeftRest extends TSchema[], RightRest extends TSchema[]> = TElementsRight<Inferred, Reversed, LeftRest, RightRest>;
|
|
17
|
-
type TExtendsTupleToTuple<Inferred extends TProperties, Left extends TSchema[], Right extends TSchema[], InstantiatedRight extends TSchema[] = TInstantiateElements<Inferred,
|
|
18
|
-
callstack: [];
|
|
19
|
-
}, Right>, Reversed extends boolean = TReversed<InstantiatedRight>> = TElements<Inferred, Reversed, TApplyReverse<Left, Reversed>, TApplyReverse<InstantiatedRight, Reversed>>;
|
|
18
|
+
type TExtendsTupleToTuple<Inferred extends TProperties, Left extends TSchema[], Right extends TSchema[], InstantiatedRight extends TSchema[] = TInstantiateElements<Inferred, TState<[], []>, Right>, Reversed extends boolean = TReversed<InstantiatedRight>> = TElements<Inferred, Reversed, TApplyReverse<Left, Reversed>, TApplyReverse<InstantiatedRight, Reversed>>;
|
|
20
19
|
type TExtendsTupleToArray<Inferred extends TProperties, Left extends TSchema[], Right extends TSchema, Inferrable extends TInferable | undefined = TTryInferable<Right>> = (Inferrable extends TInferable ? TInferUnionResult<Inferred, Inferrable['name'], Left, Inferrable['type']> : Left extends [infer Head extends TSchema, ...infer Tail extends TSchema[]] ? TExtendsLeft<Inferred, Head, Right> extends Result.TExtendsTrueLike<infer Inferred extends TProperties> ? TExtendsTupleToArray<Inferred, Tail, Right> : Result.TExtendsFalse : Result.TExtendsTrue<Inferred>);
|
|
21
|
-
export type TExtendsTuple<Inferred extends TProperties, Left extends TSchema[], Right extends TSchema, InstantiatedLeft extends TSchema[] = TInstantiateElements<Inferred,
|
|
22
|
-
callstack: [];
|
|
23
|
-
}, Left>> = (Right extends TTuple<infer Types extends TSchema[]> ? TExtendsTupleToTuple<Inferred, InstantiatedLeft, Types> : Right extends TArray<infer Type extends TSchema> ? TExtendsTupleToArray<Inferred, InstantiatedLeft, Type> : TExtendsRight<Inferred, TTuple<InstantiatedLeft>, Right>);
|
|
20
|
+
export type TExtendsTuple<Inferred extends TProperties, Left extends TSchema[], Right extends TSchema, InstantiatedLeft extends TSchema[] = TInstantiateElements<Inferred, TState<[], []>, Left>> = (Right extends TTuple<infer Types extends TSchema[]> ? TExtendsTupleToTuple<Inferred, InstantiatedLeft, Types> : Right extends TArray<infer Type extends TSchema> ? TExtendsTupleToArray<Inferred, InstantiatedLeft, Type> : TExtendsRight<Inferred, TTuple<InstantiatedLeft>, Right>);
|
|
24
21
|
export declare function ExtendsTuple<Inferred extends TProperties, Left extends TSchema[], Right extends TSchema>(inferred: Inferred, left: Left, right: Right): TExtendsTuple<Inferred, Left, Right>;
|
|
25
22
|
export {};
|
|
@@ -7,6 +7,7 @@ import { ExtendsLeft } from './extends_left.mjs';
|
|
|
7
7
|
import { ExtendsRight } from './extends_right.mjs';
|
|
8
8
|
import * as Result from './result.mjs';
|
|
9
9
|
import { InstantiateElements } from '../engine/instantiate.mjs';
|
|
10
|
+
import { State } from '../engine/instantiate.mjs';
|
|
10
11
|
// ----------------------------------------------------------------------------
|
|
11
12
|
// Inference
|
|
12
13
|
// ----------------------------------------------------------------------------
|
|
@@ -42,7 +43,7 @@ function Elements(inferred, reversed, leftRest, rightRest) {
|
|
|
42
43
|
return ElementsRight(inferred, reversed, leftRest, rightRest);
|
|
43
44
|
}
|
|
44
45
|
function ExtendsTupleToTuple(inferred, left, right) {
|
|
45
|
-
const instantiatedRight = InstantiateElements(inferred,
|
|
46
|
+
const instantiatedRight = InstantiateElements(inferred, State([], []), right);
|
|
46
47
|
const reversed = Reversed(instantiatedRight);
|
|
47
48
|
return Elements(inferred, reversed, ApplyReverse(left, reversed), ApplyReverse(instantiatedRight, reversed));
|
|
48
49
|
}
|
|
@@ -53,7 +54,7 @@ function ExtendsTupleToArray(inferred, left, right) {
|
|
|
53
54
|
: Guard.TakeLeft(left, (head, tail) => Result.Match(ExtendsLeft(inferred, head, right), inferred => ExtendsTupleToArray(inferred, tail, right), () => Result.ExtendsFalse()), () => Result.ExtendsTrue(inferred)));
|
|
54
55
|
}
|
|
55
56
|
export function ExtendsTuple(inferred, left, right) {
|
|
56
|
-
const instantiatedLeft = InstantiateElements(inferred,
|
|
57
|
+
const instantiatedLeft = InstantiateElements(inferred, State([], []), left);
|
|
57
58
|
return (IsTuple(right) ? ExtendsTupleToTuple(inferred, instantiatedLeft, right.items) :
|
|
58
59
|
IsArray(right) ? ExtendsTupleToArray(inferred, instantiatedLeft, right.items) :
|
|
59
60
|
ExtendsRight(inferred, Tuple(instantiatedLeft), right));
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import type { TArrayOptions, TIntersectOptions, TNumberOptions, TObjectOptions, TStringOptions, TTupleOptions } from '../../type/index.mjs';
|
|
2
|
-
import { type TInstantiateType } from '../engine/instantiate.mjs';
|
|
3
2
|
import { type TNever, type TSchema, type TProperties } from '../types/index.mjs';
|
|
3
|
+
import { type TInstantiateType } from '../engine/instantiate.mjs';
|
|
4
|
+
import { type TState } from '../engine/instantiate.mjs';
|
|
4
5
|
import * as Parser from './parser.mjs';
|
|
5
6
|
export type TScriptOptions = TArrayOptions | TIntersectOptions | TNumberOptions | TObjectOptions | TStringOptions | TTupleOptions;
|
|
6
7
|
/** Parses a string-based TypeScript type expression into a TypeBox type. */
|
|
7
|
-
export type TScript<Context extends TProperties, Input extends string> = (Parser.TScript<Input> extends [infer Type extends TSchema, string] ? TInstantiateType<Context,
|
|
8
|
-
callstack: [];
|
|
9
|
-
}, Type> : TNever);
|
|
8
|
+
export type TScript<Context extends TProperties, Input extends string> = (Parser.TScript<Input> extends [infer Type extends TSchema, string] ? TInstantiateType<Context, TState<[], []>, Type> : TNever);
|
|
10
9
|
/** Parses a type from a TypeScript type expression */
|
|
11
10
|
export declare function Script<Script extends string>(input: Script): TScript<{}, Script>;
|
|
12
11
|
/** Parses a type from a TypeScript type expression */
|
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
import { Arguments } from '../../system/arguments/index.mjs';
|
|
4
4
|
import { Memory } from '../../system/memory/index.mjs';
|
|
5
5
|
import { Guard } from '../../guard/index.mjs';
|
|
6
|
-
import { InstantiateType } from '../engine/instantiate.mjs';
|
|
7
6
|
import { Never } from '../types/index.mjs';
|
|
7
|
+
import { InstantiateType } from '../engine/instantiate.mjs';
|
|
8
|
+
import { State } from '../engine/instantiate.mjs';
|
|
8
9
|
import * as Parser from './parser.mjs';
|
|
9
10
|
/** Parses a type from a TypeScript type expression */
|
|
10
11
|
export function Script(...args) {
|
|
@@ -15,7 +16,7 @@ export function Script(...args) {
|
|
|
15
16
|
});
|
|
16
17
|
const result = Parser.Script(input);
|
|
17
18
|
const parsed = Guard.IsArray(result) && Guard.IsEqual(result.length, 2)
|
|
18
|
-
? InstantiateType(context,
|
|
19
|
+
? InstantiateType(context, State([], []), result[0])
|
|
19
20
|
: Never();
|
|
20
21
|
return Memory.Update(parsed, {}, options);
|
|
21
22
|
}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { type TSchema } from './schema.mjs';
|
|
2
2
|
import { type TCallInstantiate } from '../engine/call/instantiate.mjs';
|
|
3
|
+
import { type TState } from '../engine/instantiate.mjs';
|
|
3
4
|
/** Represents a deferred generic Call */
|
|
4
5
|
export interface TCall<Target extends TSchema = TSchema, Arguments extends TSchema[] = TSchema[]> extends TSchema {
|
|
5
6
|
'~kind': 'Call';
|
|
7
|
+
type: 'call';
|
|
6
8
|
target: Target;
|
|
7
9
|
arguments: Arguments;
|
|
8
10
|
}
|
|
9
11
|
export type TCallConstruct<Target extends TSchema, Arguments extends TSchema[], Result extends TSchema = TCall<Target, Arguments>> = Result;
|
|
10
12
|
export declare function CallConstruct<Target extends TSchema, Arguments extends TSchema[]>(target: Target, arguments_: [...Arguments]): TCallConstruct<Target, Arguments>;
|
|
11
13
|
/** Creates a Call type. */
|
|
12
|
-
export declare function Call<Target extends TSchema, Arguments extends TSchema[]>(target: Target, arguments_: [...Arguments]): TCallInstantiate<{},
|
|
13
|
-
callstack: [];
|
|
14
|
-
}, Target, Arguments>;
|
|
14
|
+
export declare function Call<Target extends TSchema, Arguments extends TSchema[]>(target: Target, arguments_: [...Arguments]): TCallInstantiate<{}, TState<[], []>, Target, Arguments>;
|
|
15
15
|
/** Returns true if the given type is a TCall. */
|
|
16
16
|
export declare function IsCall(value: unknown): value is TCall;
|
|
@@ -3,15 +3,16 @@
|
|
|
3
3
|
import { Memory } from '../../system/memory/index.mjs';
|
|
4
4
|
import { IsKind } from './schema.mjs';
|
|
5
5
|
import { CallInstantiate } from '../engine/call/instantiate.mjs';
|
|
6
|
+
import { State } from '../engine/instantiate.mjs';
|
|
6
7
|
export function CallConstruct(target, arguments_) {
|
|
7
|
-
return Memory.Create({ ['~kind']: 'Call' }, { target, arguments: arguments_ }, {});
|
|
8
|
+
return Memory.Create({ ['~kind']: 'Call' }, { type: 'call', target, arguments: arguments_ }, {});
|
|
8
9
|
}
|
|
9
10
|
// ------------------------------------------------------------------
|
|
10
11
|
// Factory
|
|
11
12
|
// ------------------------------------------------------------------
|
|
12
13
|
/** Creates a Call type. */
|
|
13
14
|
export function Call(target, arguments_) {
|
|
14
|
-
return CallInstantiate({},
|
|
15
|
+
return CallInstantiate({}, State([], []), target, arguments_);
|
|
15
16
|
}
|
|
16
17
|
// ------------------------------------------------------------------
|
|
17
18
|
// Guard
|