typebox 1.2.2 → 1.2.4
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/_add_immutable.d.mts +11 -0
- package/build/type/action/_add_immutable.mjs +11 -0
- package/build/type/action/_add_optional.d.mts +11 -0
- package/build/type/action/_add_optional.mjs +11 -0
- package/build/type/action/_add_readonly.d.mts +11 -0
- package/build/type/action/_add_readonly.mjs +11 -0
- package/build/type/action/_remove_immutable.d.mts +11 -0
- package/build/type/action/_remove_immutable.mjs +11 -0
- package/build/type/action/_remove_optional.d.mts +11 -0
- package/build/type/action/_remove_optional.mjs +11 -0
- package/build/type/action/_remove_readonly.d.mts +11 -0
- package/build/type/action/_remove_readonly.mjs +11 -0
- package/build/type/action/conditional.d.mts +2 -3
- package/build/type/action/conditional.mjs +2 -1
- package/build/type/action/index.d.mts +6 -2
- package/build/type/action/index.mjs +6 -2
- 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/evaluate/composite.d.mts +10 -6
- package/build/type/engine/evaluate/composite.mjs +10 -6
- package/build/type/engine/immutable/instantiate_add.d.mts +10 -0
- package/build/type/engine/immutable/instantiate_add.mjs +14 -0
- package/build/type/engine/immutable/instantiate_remove.d.mts +10 -0
- package/build/type/engine/immutable/instantiate_remove.mjs +14 -0
- package/build/type/engine/instantiate.d.mts +37 -20
- package/build/type/engine/instantiate.mjs +65 -62
- 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/optional/instantiate_add.d.mts +10 -0
- package/build/type/engine/optional/instantiate_add.mjs +14 -0
- package/build/type/engine/optional/instantiate_remove.d.mts +10 -0
- package/build/type/engine/optional/instantiate_remove.mjs +14 -0
- package/build/type/engine/parameters/instantiate.d.mts +3 -4
- package/build/type/engine/parameters/instantiate.mjs +2 -1
- package/build/type/engine/partial/from_object.d.mts +2 -2
- package/build/type/engine/partial/from_object.mjs +2 -2
- package/build/type/engine/readonly/instantiate_add.d.mts +10 -0
- package/build/type/engine/readonly/instantiate_add.mjs +14 -0
- package/build/type/engine/readonly/instantiate_remove.d.mts +10 -0
- package/build/type/engine/readonly/instantiate_remove.mjs +14 -0
- package/build/type/engine/readonly_object/from_array.d.mts +2 -2
- package/build/type/engine/readonly_object/from_array.mjs +2 -2
- package/build/type/engine/readonly_object/from_object.d.mts +2 -2
- package/build/type/engine/readonly_object/from_object.mjs +2 -2
- package/build/type/engine/readonly_object/from_tuple.d.mts +2 -2
- package/build/type/engine/readonly_object/from_tuple.mjs +2 -2
- package/build/type/engine/ref/instantiate.d.mts +3 -3
- package/build/type/engine/ref/instantiate.mjs +6 -6
- package/build/type/engine/required/from_object.d.mts +2 -2
- package/build/type/engine/required/from_object.mjs +2 -2
- package/build/type/engine/template_literal/is_pattern.mjs +1 -0
- package/build/type/extends/tuple.d.mts +3 -6
- package/build/type/extends/tuple.mjs +3 -2
- package/build/type/script/mapping.d.mts +42 -42
- package/build/type/script/mapping.mjs +46 -46
- package/build/type/script/script.d.mts +3 -4
- package/build/type/script/script.mjs +3 -2
- package/build/type/types/_immutable.d.mts +2 -9
- package/build/type/types/_immutable.mjs +2 -10
- package/build/type/types/_optional.d.mts +2 -9
- package/build/type/types/_optional.mjs +2 -11
- package/build/type/types/_readonly.d.mts +2 -9
- package/build/type/types/_readonly.mjs +2 -10
- package/build/type/types/call.d.mts +3 -3
- package/build/type/types/call.mjs +3 -2
- package/build/type/types/deferred.d.mts +1 -0
- package/build/type/types/deferred.mjs +1 -1
- package/package.json +1 -1
- package/build/type/action/_optional.d.mts +0 -19
- package/build/type/action/_optional.mjs +0 -40
- package/build/type/action/_readonly.d.mts +0 -19
- package/build/type/action/_readonly.mjs +0 -40
|
@@ -2,12 +2,6 @@
|
|
|
2
2
|
// deno-lint-ignore-file
|
|
3
3
|
import { Guard } from '../../guard/index.mjs';
|
|
4
4
|
// ------------------------------------------------------------------
|
|
5
|
-
// Modifiers
|
|
6
|
-
// ------------------------------------------------------------------
|
|
7
|
-
import { IsImmutable, Immutable } from '../types/_immutable.mjs';
|
|
8
|
-
import { IsOptional, OptionalAdd, OptionalRemove } from '../types/_optional.mjs';
|
|
9
|
-
import { IsReadonly, ReadonlyAdd, ReadonlyRemove } from '../types/_readonly.mjs';
|
|
10
|
-
// ------------------------------------------------------------------
|
|
11
5
|
// Types
|
|
12
6
|
// ------------------------------------------------------------------
|
|
13
7
|
import { IsBase } from '../types/base.mjs';
|
|
@@ -28,10 +22,17 @@ import { Union, IsUnion, UnionOptions } from '../types/union.mjs';
|
|
|
28
22
|
import { IsRef } from '../types/ref.mjs';
|
|
29
23
|
import { Rest, IsRest } from '../types/rest.mjs';
|
|
30
24
|
// ------------------------------------------------------------------
|
|
31
|
-
// Modifier
|
|
25
|
+
// Modifier Instantiate
|
|
32
26
|
// ------------------------------------------------------------------
|
|
33
|
-
import {
|
|
34
|
-
import {
|
|
27
|
+
import { AddImmutableInstantiate } from './immutable/instantiate_add.mjs';
|
|
28
|
+
import { RemoveImmutableInstantiate } from './immutable/instantiate_remove.mjs';
|
|
29
|
+
import { AddReadonlyInstantiate } from './readonly/instantiate_add.mjs';
|
|
30
|
+
import { RemoveReadonlyInstantiate } from './readonly/instantiate_remove.mjs';
|
|
31
|
+
import { AddOptionalInstantiate } from './optional/instantiate_add.mjs';
|
|
32
|
+
import { RemoveOptionalInstantiate } from './optional/instantiate_remove.mjs';
|
|
33
|
+
import { Optional, IsOptional } from '../types/_optional.mjs';
|
|
34
|
+
import { Immutable, IsImmutable } from '../types/_immutable.mjs';
|
|
35
|
+
import { Readonly, IsReadonly } from '../types/_readonly.mjs';
|
|
35
36
|
// ------------------------------------------------------------------
|
|
36
37
|
// Instantiate
|
|
37
38
|
// ------------------------------------------------------------------
|
|
@@ -65,28 +66,14 @@ import { UncapitalizeInstantiate } from './intrinsics/instantiate.mjs';
|
|
|
65
66
|
import { UppercaseInstantiate } from './intrinsics/instantiate.mjs';
|
|
66
67
|
import { WithInstantiate } from './with/instantiate.mjs';
|
|
67
68
|
import { RestSpread } from './rest/index.mjs';
|
|
69
|
+
export function State(callstack, visited) {
|
|
70
|
+
return { callstack, visited };
|
|
71
|
+
}
|
|
68
72
|
export function CanInstantiate(types) {
|
|
69
73
|
return Guard.TakeLeft(types, (left, right) => IsRef(left)
|
|
70
74
|
? false
|
|
71
75
|
: CanInstantiate(right), () => true);
|
|
72
76
|
}
|
|
73
|
-
function ModifierActions(type, readonly, optional) {
|
|
74
|
-
return (IsReadonlyRemoveAction(type) ? ModifierActions(type.type, 'remove', optional) :
|
|
75
|
-
IsOptionalRemoveAction(type) ? ModifierActions(type.type, readonly, 'remove') :
|
|
76
|
-
IsReadonlyAddAction(type) ? ModifierActions(type.type, 'add', optional) :
|
|
77
|
-
IsOptionalAddAction(type) ? ModifierActions(type.type, readonly, 'add') :
|
|
78
|
-
[type, readonly, optional]);
|
|
79
|
-
}
|
|
80
|
-
function ApplyReadonly(action, type) {
|
|
81
|
-
return (Guard.IsEqual(action, 'remove') ? ReadonlyRemove(type) :
|
|
82
|
-
Guard.IsEqual(action, 'add') ? ReadonlyAdd(type) :
|
|
83
|
-
type);
|
|
84
|
-
}
|
|
85
|
-
function ApplyOptional(action, type) {
|
|
86
|
-
return (Guard.IsEqual(action, 'remove') ? OptionalRemove(type) :
|
|
87
|
-
Guard.IsEqual(action, 'add') ? OptionalAdd(type) :
|
|
88
|
-
type);
|
|
89
|
-
}
|
|
90
77
|
export function InstantiateProperties(context, state, properties) {
|
|
91
78
|
return Guard.Keys(properties).reduce((result, key) => {
|
|
92
79
|
return { ...result, [key]: InstantiateType(context, state, properties[key]) };
|
|
@@ -101,40 +88,47 @@ export function InstantiateTypes(context, state, types) {
|
|
|
101
88
|
return types.map(type => InstantiateType(context, state, type));
|
|
102
89
|
}
|
|
103
90
|
function InstantiateDeferred(context, state, action, parameters, options) {
|
|
104
|
-
return (
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
91
|
+
return (
|
|
92
|
+
// Modifier Actions
|
|
93
|
+
Guard.IsEqual(action, 'AddImmutable') ? AddImmutableInstantiate(context, state, parameters[0], options) :
|
|
94
|
+
Guard.IsEqual(action, 'RemoveImmutable') ? RemoveImmutableInstantiate(context, state, parameters[0], options) :
|
|
95
|
+
Guard.IsEqual(action, 'AddReadonly') ? AddReadonlyInstantiate(context, state, parameters[0], options) :
|
|
96
|
+
Guard.IsEqual(action, 'RemoveReadonly') ? RemoveReadonlyInstantiate(context, state, parameters[0], options) :
|
|
97
|
+
Guard.IsEqual(action, 'AddOptional') ? AddOptionalInstantiate(context, state, parameters[0], options) :
|
|
98
|
+
Guard.IsEqual(action, 'RemoveOptional') ? RemoveOptionalInstantiate(context, state, parameters[0], options) :
|
|
99
|
+
// Actions
|
|
100
|
+
Guard.IsEqual(action, 'Awaited') ? AwaitedInstantiate(context, state, parameters[0], options) :
|
|
101
|
+
Guard.IsEqual(action, 'Capitalize') ? CapitalizeInstantiate(context, state, parameters[0], options) :
|
|
102
|
+
Guard.IsEqual(action, 'Conditional') ? ConditionalInstantiate(context, state, parameters[0], parameters[1], parameters[2], parameters[3], options) :
|
|
103
|
+
Guard.IsEqual(action, 'ConstructorParameters') ? ConstructorParametersInstantiate(context, state, parameters[0], options) :
|
|
104
|
+
Guard.IsEqual(action, 'Evaluate') ? EvaluateInstantiate(context, state, parameters[0], options) :
|
|
105
|
+
Guard.IsEqual(action, 'Exclude') ? ExcludeInstantiate(context, state, parameters[0], parameters[1], options) :
|
|
106
|
+
Guard.IsEqual(action, 'Extract') ? ExtractInstantiate(context, state, parameters[0], parameters[1], options) :
|
|
107
|
+
Guard.IsEqual(action, 'Index') ? IndexInstantiate(context, state, parameters[0], parameters[1], options) :
|
|
108
|
+
Guard.IsEqual(action, 'InstanceType') ? InstanceTypeInstantiate(context, state, parameters[0], options) :
|
|
109
|
+
Guard.IsEqual(action, 'Interface') ? InterfaceInstantiate(context, state, parameters[0], parameters[1], options) :
|
|
110
|
+
Guard.IsEqual(action, 'KeyOf') ? KeyOfInstantiate(context, state, parameters[0], options) :
|
|
111
|
+
Guard.IsEqual(action, 'Lowercase') ? LowercaseInstantiate(context, state, parameters[0], options) :
|
|
112
|
+
Guard.IsEqual(action, 'Mapped') ? MappedInstantiate(context, state, parameters[0], parameters[1], parameters[2], parameters[3], options) :
|
|
113
|
+
Guard.IsEqual(action, 'Module') ? ModuleInstantiate(context, state, parameters[0], options) :
|
|
114
|
+
Guard.IsEqual(action, 'NonNullable') ? NonNullableInstantiate(context, state, parameters[0], options) :
|
|
115
|
+
Guard.IsEqual(action, 'Pick') ? PickInstantiate(context, state, parameters[0], parameters[1], options) :
|
|
116
|
+
Guard.IsEqual(action, 'Parameters') ? ParametersInstantiate(context, state, parameters[0], options) :
|
|
117
|
+
Guard.IsEqual(action, 'Partial') ? PartialInstantiate(context, state, parameters[0], options) :
|
|
118
|
+
Guard.IsEqual(action, 'Omit') ? OmitInstantiate(context, state, parameters[0], parameters[1], options) :
|
|
119
|
+
Guard.IsEqual(action, 'ReadonlyObject') ? ReadonlyObjectInstantiate(context, state, parameters[0], options) :
|
|
120
|
+
Guard.IsEqual(action, 'Record') ? RecordInstantiate(context, state, parameters[0], parameters[1], options) :
|
|
121
|
+
Guard.IsEqual(action, 'Required') ? RequiredInstantiate(context, state, parameters[0], options) :
|
|
122
|
+
Guard.IsEqual(action, 'ReturnType') ? ReturnTypeInstantiate(context, state, parameters[0], options) :
|
|
123
|
+
Guard.IsEqual(action, 'TemplateLiteral') ? TemplateLiteralInstantiate(context, state, parameters[0], options) :
|
|
124
|
+
Guard.IsEqual(action, 'Uncapitalize') ? UncapitalizeInstantiate(context, state, parameters[0], options) :
|
|
125
|
+
Guard.IsEqual(action, 'Uppercase') ? UppercaseInstantiate(context, state, parameters[0], options) :
|
|
126
|
+
Guard.IsEqual(action, 'With') ? WithInstantiate(context, state, parameters[0], parameters[1]) :
|
|
127
|
+
Deferred(action, parameters, options));
|
|
132
128
|
}
|
|
133
|
-
export function
|
|
134
|
-
|
|
135
|
-
const
|
|
136
|
-
const type = IsBase(modifiers[0]) ? modifiers[0].Clone() : modifiers[0];
|
|
137
|
-
const instantiated = (IsRef(type) ? RefInstantiate(context, state, type, type.$ref) :
|
|
129
|
+
export function InstantiateImmediate(context, state, type) {
|
|
130
|
+
type = (IsBase(type) ? type.Clone() : type);
|
|
131
|
+
const result = (IsRef(type) ? RefInstantiate(context, state, type, type.$ref) :
|
|
138
132
|
IsArray(type) ? _Array_(InstantiateType(context, state, type.items), ArrayOptions(type)) :
|
|
139
133
|
IsAsyncIterator(type) ? AsyncIterator(InstantiateType(context, state, type.iteratorItems), AsyncIteratorOptions(type)) :
|
|
140
134
|
IsCall(type) ? CallInstantiate(context, state, type.target, type.arguments) :
|
|
@@ -151,11 +145,20 @@ export function InstantiateType(context, state, input) {
|
|
|
151
145
|
IsTuple(type) ? Tuple(InstantiateElements(context, state, type.items), TupleOptions(type)) :
|
|
152
146
|
IsUnion(type) ? Union(InstantiateTypes(context, state, type.anyOf), UnionOptions(type)) :
|
|
153
147
|
type);
|
|
154
|
-
|
|
155
|
-
|
|
148
|
+
return result;
|
|
149
|
+
}
|
|
150
|
+
function WithModifiers(type, instantiatedType) {
|
|
151
|
+
const withImmutable = IsImmutable(type) ? Immutable(instantiatedType) : instantiatedType;
|
|
152
|
+
const withReadonly = IsReadonly(type) ? Readonly(withImmutable) : withImmutable;
|
|
153
|
+
const withOptional = IsOptional(type) ? Optional(withReadonly) : withReadonly;
|
|
154
|
+
return withOptional;
|
|
155
|
+
}
|
|
156
|
+
export function InstantiateType(context, state, type) {
|
|
157
|
+
const instantiatedType = InstantiateImmediate(context, state, type);
|
|
158
|
+
const withModifiers = IsDeferred(type) ? instantiatedType : WithModifiers(type, instantiatedType);
|
|
156
159
|
return withModifiers;
|
|
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) {
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type TSchema, type TSchemaOptions } from '../../types/schema.mjs';
|
|
2
|
+
import { type TProperties } from '../../types/properties.mjs';
|
|
3
|
+
import { type TOptional } from '../../types/_optional.mjs';
|
|
4
|
+
import { type TState, type TInstantiateType } from '../instantiate.mjs';
|
|
5
|
+
type TAddOptionalOperation<Type extends TSchema, Result extends TSchema = `~optional` extends keyof Type ? Type : TOptional<Type>> = Result;
|
|
6
|
+
export type TAddOptionalAction<Type extends TSchema, Result extends TSchema = TAddOptionalOperation<Type>> = Result;
|
|
7
|
+
export declare function AddOptionalAction<Type extends TSchema>(type: Type, options: TSchemaOptions): TAddOptionalAction<Type>;
|
|
8
|
+
export type TAddOptionalInstantiate<Context extends TProperties, State extends TState, Type extends TSchema, InstantiateType extends TSchema = TInstantiateType<Context, State, Type>> = TAddOptionalAction<InstantiateType>;
|
|
9
|
+
export declare function AddOptionalInstantiate<Context extends TProperties, State extends TState, Type extends TSchema>(context: Context, state: State, type: Type, options: TSchemaOptions): TAddOptionalInstantiate<Context, State, Type>;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// deno-fmt-ignore-file
|
|
2
|
+
import { Memory } from '../../../system/memory/index.mjs';
|
|
3
|
+
import { InstantiateType } from '../instantiate.mjs';
|
|
4
|
+
function AddOptionalOperation(type) {
|
|
5
|
+
return Memory.Update(type, { '~optional': true }, {});
|
|
6
|
+
}
|
|
7
|
+
export function AddOptionalAction(type, options) {
|
|
8
|
+
const result = Memory.Update(AddOptionalOperation(type), {}, options);
|
|
9
|
+
return result;
|
|
10
|
+
}
|
|
11
|
+
export function AddOptionalInstantiate(context, state, type, options) {
|
|
12
|
+
const instantiatedType = InstantiateType(context, state, type);
|
|
13
|
+
return AddOptionalAction(instantiatedType, options);
|
|
14
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type TSchema, type TSchemaOptions } from '../../types/schema.mjs';
|
|
2
|
+
import { type TProperties } from '../../types/properties.mjs';
|
|
3
|
+
import { type TOptional } from '../../types/_optional.mjs';
|
|
4
|
+
import { type TState, type TInstantiateType } from '../instantiate.mjs';
|
|
5
|
+
type TRemoveOptionalOperation<Type extends TSchema, Result extends TSchema = Type extends TOptional<infer Type extends TSchema> ? Type : Type> = Result;
|
|
6
|
+
export type TRemoveOptionalAction<Type extends TSchema, Result extends TSchema = TRemoveOptionalOperation<Type>> = Result;
|
|
7
|
+
export declare function RemoveOptionalAction<Type extends TSchema>(type: Type, options: TSchemaOptions): TRemoveOptionalAction<Type>;
|
|
8
|
+
export type TRemoveOptionalInstantiate<Context extends TProperties, State extends TState, Type extends TSchema, InstantiateType extends TSchema = TInstantiateType<Context, State, Type>> = TRemoveOptionalAction<InstantiateType>;
|
|
9
|
+
export declare function RemoveOptionalInstantiate<Context extends TProperties, State extends TState, Type extends TSchema>(context: Context, state: State, type: Type, options: TSchemaOptions): TRemoveOptionalInstantiate<Context, State, Type>;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// deno-fmt-ignore-file
|
|
2
|
+
import { Memory } from '../../../system/memory/index.mjs';
|
|
3
|
+
import { InstantiateType } from '../instantiate.mjs';
|
|
4
|
+
function RemoveOptionalOperation(type) {
|
|
5
|
+
return Memory.Discard(type, ['~optional']);
|
|
6
|
+
}
|
|
7
|
+
export function RemoveOptionalAction(type, options) {
|
|
8
|
+
const result = Memory.Update(RemoveOptionalOperation(type), {}, options);
|
|
9
|
+
return result;
|
|
10
|
+
}
|
|
11
|
+
export function RemoveOptionalInstantiate(context, state, type, options) {
|
|
12
|
+
const instantiatedType = InstantiateType(context, state, type);
|
|
13
|
+
return RemoveOptionalAction(instantiatedType, options);
|
|
14
|
+
}
|
|
@@ -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,8 +1,8 @@
|
|
|
1
1
|
import { type TSchema } from '../../types/schema.mjs';
|
|
2
2
|
import { type TObject } from '../../types/object.mjs';
|
|
3
|
-
import { type
|
|
3
|
+
import { type TAddOptional } from '../../action/_add_optional.mjs';
|
|
4
4
|
import { type TProperties } from '../../types/properties.mjs';
|
|
5
5
|
export type TFromObject<Properties extends TProperties, Mapped extends TProperties = {
|
|
6
|
-
[Key in keyof Properties]:
|
|
6
|
+
[Key in keyof Properties]: TAddOptional<Properties[Key]>;
|
|
7
7
|
}, Result extends TSchema = TObject<Mapped>> = Result;
|
|
8
8
|
export declare function FromObject<Properties extends TProperties>(properties: Properties): TFromObject<Properties>;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// deno-fmt-ignore-file
|
|
2
2
|
import { Guard } from '../../../guard/index.mjs';
|
|
3
3
|
import { Object } from '../../types/object.mjs';
|
|
4
|
-
import {
|
|
4
|
+
import { AddOptional } from '../../action/_add_optional.mjs';
|
|
5
5
|
export function FromObject(properties) {
|
|
6
6
|
const mapped = Guard.Keys(properties).reduce((result, left) => {
|
|
7
|
-
return { ...result, [left]:
|
|
7
|
+
return { ...result, [left]: AddOptional(properties[left]) };
|
|
8
8
|
}, {});
|
|
9
9
|
const result = Object(mapped);
|
|
10
10
|
return result;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type TSchema, type TSchemaOptions } from '../../types/schema.mjs';
|
|
2
|
+
import { type TProperties } from '../../types/properties.mjs';
|
|
3
|
+
import { type TReadonly } from '../../types/_readonly.mjs';
|
|
4
|
+
import { type TState, type TInstantiateType } from '../instantiate.mjs';
|
|
5
|
+
type TAddReadonlyOperation<Type extends TSchema, Result extends TSchema = `~readonly` extends keyof Type ? Type : TReadonly<Type>> = Result;
|
|
6
|
+
export type TAddReadonlyAction<Type extends TSchema, Result extends TSchema = TAddReadonlyOperation<Type>> = Result;
|
|
7
|
+
export declare function AddReadonlyAction<Type extends TSchema>(type: Type, options: TSchemaOptions): TAddReadonlyAction<Type>;
|
|
8
|
+
export type TAddReadonlyInstantiate<Context extends TProperties, State extends TState, Type extends TSchema, InstantiateType extends TSchema = TInstantiateType<Context, State, Type>> = TAddReadonlyAction<InstantiateType>;
|
|
9
|
+
export declare function AddReadonlyInstantiate<Context extends TProperties, State extends TState, Type extends TSchema>(context: Context, state: State, type: Type, options: TSchemaOptions): TAddReadonlyInstantiate<Context, State, Type>;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// deno-fmt-ignore-file
|
|
2
|
+
import { Memory } from '../../../system/memory/index.mjs';
|
|
3
|
+
import { InstantiateType } from '../instantiate.mjs';
|
|
4
|
+
function AddReadonlyOperation(type) {
|
|
5
|
+
return Memory.Update(type, { '~readonly': true }, {});
|
|
6
|
+
}
|
|
7
|
+
export function AddReadonlyAction(type, options) {
|
|
8
|
+
const result = Memory.Update(AddReadonlyOperation(type), {}, options);
|
|
9
|
+
return result;
|
|
10
|
+
}
|
|
11
|
+
export function AddReadonlyInstantiate(context, state, type, options) {
|
|
12
|
+
const instantiatedType = InstantiateType(context, state, type);
|
|
13
|
+
return AddReadonlyAction(instantiatedType, options);
|
|
14
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type TSchema, type TSchemaOptions } from '../../types/schema.mjs';
|
|
2
|
+
import { type TProperties } from '../../types/properties.mjs';
|
|
3
|
+
import { type TReadonly } from '../../types/_readonly.mjs';
|
|
4
|
+
import { type TState, type TInstantiateType } from '../instantiate.mjs';
|
|
5
|
+
type TRemoveReadonlyOperation<Type extends TSchema, Result extends TSchema = Type extends TReadonly<infer Type extends TSchema> ? Type : Type> = Result;
|
|
6
|
+
export type TRemoveReadonlyAction<Type extends TSchema, Result extends TSchema = TRemoveReadonlyOperation<Type>> = Result;
|
|
7
|
+
export declare function RemoveReadonlyAction<Type extends TSchema>(type: Type, options: TSchemaOptions): TRemoveReadonlyAction<Type>;
|
|
8
|
+
export type TRemoveReadonlyInstantiate<Context extends TProperties, State extends TState, Type extends TSchema, InstantiateType extends TSchema = TInstantiateType<Context, State, Type>> = TRemoveReadonlyAction<InstantiateType>;
|
|
9
|
+
export declare function RemoveReadonlyInstantiate<Context extends TProperties, State extends TState, Type extends TSchema>(context: Context, state: State, type: Type, options: TSchemaOptions): TRemoveReadonlyInstantiate<Context, State, Type>;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// deno-fmt-ignore-file
|
|
2
|
+
import { Memory } from '../../../system/memory/index.mjs';
|
|
3
|
+
import { InstantiateType } from '../instantiate.mjs';
|
|
4
|
+
function RemoveReadonlyOperation(type) {
|
|
5
|
+
return Memory.Discard(type, ['~readonly']);
|
|
6
|
+
}
|
|
7
|
+
export function RemoveReadonlyAction(type, options) {
|
|
8
|
+
const result = Memory.Update(RemoveReadonlyOperation(type), {}, options);
|
|
9
|
+
return result;
|
|
10
|
+
}
|
|
11
|
+
export function RemoveReadonlyInstantiate(context, state, type, options) {
|
|
12
|
+
const instantiatedType = InstantiateType(context, state, type);
|
|
13
|
+
return RemoveReadonlyAction(instantiatedType, options);
|
|
14
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type TSchema } from '../../types/schema.mjs';
|
|
2
2
|
import { type TArray } from '../../types/array.mjs';
|
|
3
|
-
import { type
|
|
4
|
-
export type TFromArray<Type extends TSchema, Result extends TSchema =
|
|
3
|
+
import { type TAddImmutable } from '../../action/_add_immutable.mjs';
|
|
4
|
+
export type TFromArray<Type extends TSchema, Result extends TSchema = TAddImmutable<TArray<Type>>> = Result;
|
|
5
5
|
export declare function FromArray<Type extends TSchema>(type: Type): TFromArray<Type>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// deno-fmt-ignore-file
|
|
2
2
|
import { Array } from '../../types/array.mjs';
|
|
3
|
-
import {
|
|
3
|
+
import { AddImmutable } from '../../action/_add_immutable.mjs';
|
|
4
4
|
export function FromArray(type) {
|
|
5
|
-
const result =
|
|
5
|
+
const result = AddImmutable(Array(type));
|
|
6
6
|
return result;
|
|
7
7
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { type TSchema } from '../../types/schema.mjs';
|
|
2
2
|
import { type TObject } from '../../types/object.mjs';
|
|
3
|
-
import { type
|
|
3
|
+
import { type TAddReadonly } from '../../action/_add_readonly.mjs';
|
|
4
4
|
import { type TProperties } from '../../types/properties.mjs';
|
|
5
5
|
export type TFromObject<Properties extends TProperties, Mapped extends TProperties = {
|
|
6
|
-
[Key in keyof Properties]:
|
|
6
|
+
[Key in keyof Properties]: TAddReadonly<Properties[Key]>;
|
|
7
7
|
}, Result extends TSchema = TObject<Mapped>> = Result;
|
|
8
8
|
export declare function FromObject<Properties extends TProperties>(properties: Properties): TFromObject<Properties>;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// deno-fmt-ignore-file
|
|
2
2
|
import { Guard } from '../../../guard/index.mjs';
|
|
3
3
|
import { Object } from '../../types/object.mjs';
|
|
4
|
-
import {
|
|
4
|
+
import { AddReadonly } from '../../action/_add_readonly.mjs';
|
|
5
5
|
export function FromObject(properties) {
|
|
6
6
|
const mapped = Guard.Keys(properties).reduce((result, left) => {
|
|
7
|
-
return { ...result, [left]:
|
|
7
|
+
return { ...result, [left]: AddReadonly(properties[left]) };
|
|
8
8
|
}, {});
|
|
9
9
|
const result = Object(mapped);
|
|
10
10
|
return result;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type TSchema } from '../../types/schema.mjs';
|
|
2
2
|
import { type TTuple } from '../../types/tuple.mjs';
|
|
3
|
-
import { type
|
|
4
|
-
export type TFromTuple<Types extends TSchema[], Result extends TSchema =
|
|
3
|
+
import { type TAddImmutable } from '../../action/_add_immutable.mjs';
|
|
4
|
+
export type TFromTuple<Types extends TSchema[], Result extends TSchema = TAddImmutable<TTuple<Types>>> = Result;
|
|
5
5
|
export declare function FromTuple<Types extends TSchema[]>(types: [...Types]): TFromTuple<Types>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// deno-fmt-ignore-file
|
|
2
2
|
import { Tuple } from '../../types/tuple.mjs';
|
|
3
|
-
import {
|
|
3
|
+
import { AddImmutable } from '../../action/_add_immutable.mjs';
|
|
4
4
|
export function FromTuple(types) {
|
|
5
|
-
const result =
|
|
5
|
+
const result = AddImmutable(Tuple(types));
|
|
6
6
|
return result;
|
|
7
7
|
}
|
|
@@ -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
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { type TSchema } from '../../types/schema.mjs';
|
|
2
2
|
import { type TObject } from '../../types/object.mjs';
|
|
3
|
-
import { type
|
|
3
|
+
import { type TRemoveOptional } from '../../action/_remove_optional.mjs';
|
|
4
4
|
import { type TProperties } from '../../types/properties.mjs';
|
|
5
5
|
export type TFromObject<Properties extends TProperties, Mapped extends TProperties = {
|
|
6
|
-
[Key in keyof Properties]:
|
|
6
|
+
[Key in keyof Properties]: TRemoveOptional<Properties[Key]>;
|
|
7
7
|
}, Result extends TSchema = TObject<Mapped>> = Result;
|
|
8
8
|
export declare function FromObject<Properties extends TProperties>(properties: Properties): TFromObject<Properties>;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// deno-fmt-ignore-file
|
|
2
2
|
import { Guard } from '../../../guard/index.mjs';
|
|
3
3
|
import { Object } from '../../types/object.mjs';
|
|
4
|
-
import {
|
|
4
|
+
import { RemoveOptional } from '../../action/_remove_optional.mjs';
|
|
5
5
|
export function FromObject(properties) {
|
|
6
6
|
const mapped = Guard.Keys(properties).reduce((result, left) => {
|
|
7
|
-
return { ...result, [left]:
|
|
7
|
+
return { ...result, [left]: RemoveOptional(properties[left]) };
|
|
8
8
|
}, {});
|
|
9
9
|
const result = Object(mapped);
|
|
10
10
|
return result;
|
|
@@ -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));
|