typebox 1.1.38 → 1.2.0
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/guard/guard.d.mts +2 -2
- package/build/guard/guard.mjs +2 -2
- package/build/type/action/index.d.mts +1 -1
- package/build/type/action/index.mjs +1 -1
- package/build/type/action/with.d.mts +21 -0
- package/build/type/action/with.mjs +19 -0
- package/build/type/engine/enum/index.d.mts +0 -1
- package/build/type/engine/enum/index.mjs +0 -1
- package/build/type/engine/evaluate/evaluate.d.mts +15 -3
- package/build/type/engine/evaluate/evaluate.mjs +30 -6
- package/build/type/engine/exclude/operation.d.mts +5 -6
- package/build/type/engine/exclude/operation.mjs +11 -12
- package/build/type/engine/extract/operation.d.mts +5 -6
- package/build/type/engine/extract/operation.mjs +11 -12
- package/build/type/engine/index.d.mts +1 -1
- package/build/type/engine/index.mjs +1 -1
- package/build/type/engine/indexable/from_dependent.d.mts +5 -0
- package/build/type/engine/indexable/from_dependent.mjs +8 -0
- package/build/type/engine/indexable/from_enum.d.mts +3 -3
- package/build/type/engine/indexable/from_enum.mjs +4 -4
- package/build/type/engine/indexable/from_template_literal.d.mts +2 -2
- package/build/type/engine/indexable/from_template_literal.mjs +3 -3
- package/build/type/engine/indexable/from_type.d.mts +3 -1
- package/build/type/engine/indexable/from_type.mjs +9 -6
- package/build/type/engine/indexed/instantiate.d.mts +2 -1
- package/build/type/engine/indexed/instantiate.mjs +2 -1
- package/build/type/engine/instantiate.d.mts +7 -6
- package/build/type/engine/instantiate.mjs +23 -21
- package/build/type/engine/intrinsics/from_template_literal.d.mts +2 -2
- package/build/type/engine/intrinsics/from_template_literal.mjs +3 -3
- package/build/type/engine/keyof/instantiate.d.mts +2 -1
- package/build/type/engine/keyof/instantiate.mjs +2 -1
- package/build/type/engine/mapped/mapped_operation.d.mts +4 -4
- package/build/type/engine/mapped/mapped_operation.mjs +3 -3
- package/build/type/engine/mapped/mapped_variants.d.mts +5 -4
- package/build/type/engine/mapped/mapped_variants.mjs +10 -5
- package/build/type/engine/object/from_dependent.d.mts +5 -0
- package/build/type/engine/object/from_dependent.mjs +8 -0
- package/build/type/engine/object/from_type.d.mts +3 -1
- package/build/type/engine/object/from_type.mjs +8 -5
- package/build/type/engine/partial/from_dependent.d.mts +5 -0
- package/build/type/engine/partial/from_dependent.mjs +8 -0
- package/build/type/engine/partial/from_intersect.d.mts +1 -1
- package/build/type/engine/partial/from_intersect.mjs +3 -2
- package/build/type/engine/partial/from_type.d.mts +3 -1
- package/build/type/engine/partial/from_type.mjs +7 -4
- package/build/type/engine/readonly_object/from_dependent.d.mts +5 -0
- package/build/type/engine/readonly_object/from_dependent.mjs +8 -0
- package/build/type/engine/readonly_object/from_intersect.d.mts +1 -1
- package/build/type/engine/readonly_object/from_intersect.mjs +3 -2
- package/build/type/engine/readonly_object/from_type.d.mts +3 -1
- package/build/type/engine/readonly_object/from_type.mjs +8 -5
- package/build/type/engine/record/from_key_enum.d.mts +2 -2
- package/build/type/engine/record/from_key_enum.mjs +2 -2
- package/build/type/engine/record/from_key_template_literal.d.mts +2 -2
- package/build/type/engine/record/from_key_template_literal.mjs +2 -2
- package/build/type/engine/required/from_dependent.d.mts +5 -0
- package/build/type/engine/required/from_dependent.mjs +8 -0
- package/build/type/engine/required/from_intersect.d.mts +1 -1
- package/build/type/engine/required/from_intersect.mjs +3 -2
- package/build/type/engine/required/from_type.d.mts +3 -1
- package/build/type/engine/required/from_type.mjs +7 -4
- package/build/type/engine/template_literal/encode.d.mts +2 -2
- package/build/type/engine/template_literal/encode.mjs +4 -4
- package/build/type/engine/with/instantiate.d.mts +8 -0
- package/build/type/engine/{options → with}/instantiate.mjs +5 -5
- package/build/type/extends/dependent.d.mts +6 -0
- package/build/type/extends/dependent.mjs +6 -0
- package/build/type/extends/enum.d.mts +4 -4
- package/build/type/extends/enum.mjs +3 -2
- package/build/type/extends/extends_left.d.mts +3 -1
- package/build/type/extends/extends_left.mjs +23 -20
- package/build/type/extends/extends_right.d.mts +7 -5
- package/build/type/extends/extends_right.mjs +18 -13
- package/build/type/extends/template_literal.d.mts +3 -3
- package/build/type/extends/template_literal.mjs +3 -3
- package/build/type/script/mapping.d.mts +7 -7
- package/build/type/script/mapping.mjs +30 -23
- package/build/type/script/parser.d.mts +6 -4
- package/build/type/script/parser.mjs +4 -3
- package/build/type/types/dependent.d.mts +17 -0
- package/build/type/types/dependent.mjs +24 -0
- package/build/type/types/enum.d.mts +1 -1
- package/build/type/types/index.d.mts +1 -0
- package/build/type/types/index.mjs +1 -0
- package/build/type/types/static.d.mts +2 -1
- package/build/typebox.d.mts +2 -1
- package/build/typebox.mjs +2 -1
- package/build/value/clean/from_intersect.mjs +2 -2
- package/build/value/clone/clone.mjs +17 -3
- package/build/value/convert/from_enum.mjs +3 -4
- package/build/value/convert/from_template_literal.d.mts +1 -1
- package/build/value/convert/from_template_literal.mjs +2 -3
- package/build/value/create/from_enum.mjs +2 -2
- package/build/value/repair/from_enum.mjs +2 -3
- package/package.json +29 -29
- package/readme.md +51 -20
- package/build/type/action/options.d.mts +0 -11
- package/build/type/action/options.mjs +0 -11
- package/build/type/engine/enum/enum_to_union.d.mts +0 -14
- package/build/type/engine/enum/enum_to_union.mjs +0 -24
- package/build/type/engine/options/instantiate.d.mts +0 -8
- /package/build/type/engine/{options → with}/index.d.mts +0 -0
- /package/build/type/engine/{options → with}/index.mjs +0 -0
|
@@ -17,6 +17,7 @@ import { Constructor, IsConstructor, ConstructorOptions } from '../types/constru
|
|
|
17
17
|
import { Deferred, IsDeferred } from '../types/deferred.mjs';
|
|
18
18
|
import { _Function_, IsFunction, FunctionOptions } from '../types/function.mjs';
|
|
19
19
|
import { IsCall } from '../types/call.mjs';
|
|
20
|
+
import { Dependent, IsDependent, DependentOptions } from '../types/dependent.mjs';
|
|
20
21
|
import { Intersect, IsIntersect, IntersectOptions } from '../types/intersect.mjs';
|
|
21
22
|
import { Iterator, IsIterator, IteratorOptions } from '../types/iterator.mjs';
|
|
22
23
|
import { Object, IsObject, ObjectOptions } from '../types/object.mjs';
|
|
@@ -51,7 +52,6 @@ import { MappedInstantiate } from './mapped/instantiate.mjs';
|
|
|
51
52
|
import { ModuleInstantiate } from './module/instantiate.mjs';
|
|
52
53
|
import { NonNullableInstantiate } from './non_nullable/instantiate.mjs';
|
|
53
54
|
import { OmitInstantiate } from './omit/instantiate.mjs';
|
|
54
|
-
import { OptionsInstantiate } from './options/instantiate.mjs';
|
|
55
55
|
import { ParametersInstantiate } from './parameters/instantiate.mjs';
|
|
56
56
|
import { PartialInstantiate } from './partial/instantiate.mjs';
|
|
57
57
|
import { PickInstantiate } from './pick/instantiate.mjs';
|
|
@@ -63,6 +63,7 @@ import { ReturnTypeInstantiate } from './return_type/instantiate.mjs';
|
|
|
63
63
|
import { TemplateLiteralInstantiate } from './template_literal/instantiate.mjs';
|
|
64
64
|
import { UncapitalizeInstantiate } from './intrinsics/instantiate.mjs';
|
|
65
65
|
import { UppercaseInstantiate } from './intrinsics/instantiate.mjs';
|
|
66
|
+
import { WithInstantiate } from './with/instantiate.mjs';
|
|
66
67
|
import { RestSpread } from './rest/index.mjs';
|
|
67
68
|
export function CanInstantiate(types) {
|
|
68
69
|
return Guard.TakeLeft(types, (left, right) => IsRef(left)
|
|
@@ -116,17 +117,17 @@ function InstantiateDeferred(context, state, action, parameters, options) {
|
|
|
116
117
|
Guard.IsEqual(action, 'Module') ? ModuleInstantiate(context, state, parameters[0], options) :
|
|
117
118
|
Guard.IsEqual(action, 'NonNullable') ? NonNullableInstantiate(context, state, parameters[0], options) :
|
|
118
119
|
Guard.IsEqual(action, 'Pick') ? PickInstantiate(context, state, parameters[0], parameters[1], options) :
|
|
119
|
-
Guard.IsEqual(action, '
|
|
120
|
-
Guard.IsEqual(action, '
|
|
121
|
-
Guard.IsEqual(action, '
|
|
122
|
-
Guard.IsEqual(action, '
|
|
123
|
-
Guard.IsEqual(action, '
|
|
124
|
-
Guard.IsEqual(action, '
|
|
125
|
-
Guard.IsEqual(action, '
|
|
126
|
-
Guard.IsEqual(action, '
|
|
127
|
-
Guard.IsEqual(action, '
|
|
128
|
-
Guard.IsEqual(action, '
|
|
129
|
-
Guard.IsEqual(action, '
|
|
120
|
+
Guard.IsEqual(action, 'Parameters') ? ParametersInstantiate(context, state, parameters[0], options) :
|
|
121
|
+
Guard.IsEqual(action, 'Partial') ? PartialInstantiate(context, state, parameters[0], options) :
|
|
122
|
+
Guard.IsEqual(action, 'Omit') ? OmitInstantiate(context, state, parameters[0], parameters[1], options) :
|
|
123
|
+
Guard.IsEqual(action, 'ReadonlyObject') ? ReadonlyObjectInstantiate(context, state, parameters[0], options) :
|
|
124
|
+
Guard.IsEqual(action, 'Record') ? RecordInstantiate(context, state, parameters[0], parameters[1], options) :
|
|
125
|
+
Guard.IsEqual(action, 'Required') ? RequiredInstantiate(context, state, parameters[0], options) :
|
|
126
|
+
Guard.IsEqual(action, 'ReturnType') ? ReturnTypeInstantiate(context, state, parameters[0], options) :
|
|
127
|
+
Guard.IsEqual(action, 'TemplateLiteral') ? TemplateLiteralInstantiate(context, state, parameters[0], options) :
|
|
128
|
+
Guard.IsEqual(action, 'Uncapitalize') ? UncapitalizeInstantiate(context, state, parameters[0], options) :
|
|
129
|
+
Guard.IsEqual(action, 'Uppercase') ? UppercaseInstantiate(context, state, parameters[0], options) :
|
|
130
|
+
Guard.IsEqual(action, 'With') ? WithInstantiate(context, state, parameters[0], parameters[1]) :
|
|
130
131
|
Deferred(action, parameters, options));
|
|
131
132
|
}
|
|
132
133
|
export function InstantiateType(context, state, input) {
|
|
@@ -140,15 +141,16 @@ export function InstantiateType(context, state, input) {
|
|
|
140
141
|
IsConstructor(type) ? Constructor(InstantiateTypes(context, state, type.parameters), InstantiateType(context, state, type.instanceType), ConstructorOptions(type)) :
|
|
141
142
|
IsDeferred(type) ? InstantiateDeferred(context, state, type.action, type.parameters, type.options) :
|
|
142
143
|
IsFunction(type) ? _Function_(InstantiateTypes(context, state, type.parameters), InstantiateType(context, state, type.returnType), FunctionOptions(type)) :
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
type)
|
|
144
|
+
IsDependent(type) ? Dependent(InstantiateType(context, state, type.if), InstantiateType(context, state, type.then), InstantiateType(context, state, type.else), DependentOptions(type)) :
|
|
145
|
+
IsIntersect(type) ? Intersect(InstantiateTypes(context, state, type.allOf), IntersectOptions(type)) :
|
|
146
|
+
IsIterator(type) ? Iterator(InstantiateType(context, state, type.iteratorItems), IteratorOptions(type)) :
|
|
147
|
+
IsObject(type) ? Object(InstantiateProperties(context, state, type.properties), ObjectOptions(type)) :
|
|
148
|
+
IsPromise(type) ? _Promise_(InstantiateType(context, state, type.item), PromiseOptions(type)) :
|
|
149
|
+
IsRecord(type) ? RecordFromPattern(RecordPattern(type), InstantiateType(context, state, RecordValue(type))) :
|
|
150
|
+
IsRest(type) ? Rest(InstantiateType(context, state, type.items)) :
|
|
151
|
+
IsTuple(type) ? Tuple(InstantiateElements(context, state, type.items), TupleOptions(type)) :
|
|
152
|
+
IsUnion(type) ? Union(InstantiateTypes(context, state, type.anyOf), UnionOptions(type)) :
|
|
153
|
+
type);
|
|
152
154
|
const withImmutable = immutable ? Immutable(instantiated) : instantiated;
|
|
153
155
|
const withModifiers = ApplyReadonly(modifiers[1], ApplyOptional(modifiers[2], withImmutable));
|
|
154
156
|
return withModifiers;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type TSchema } from '../../types/schema.mjs';
|
|
2
2
|
import { type TMappingType, type TMappingFunc } from './mapping.mjs';
|
|
3
|
-
import { type TTemplateLiteralDecode } from '../template_literal/decode.mjs';
|
|
4
3
|
import { type TFromType } from './from_type.mjs';
|
|
5
|
-
|
|
4
|
+
import { type TEvaluateTemplateLiteral } from '../evaluate/index.mjs';
|
|
5
|
+
export type TFromTemplateLiteral<Mapping extends TMappingType, Pattern extends string, Evaluated extends TSchema = TEvaluateTemplateLiteral<Pattern>, Result extends TSchema = TFromType<Mapping, Evaluated>> = Result;
|
|
6
6
|
export declare function FromTemplateLiteral(mapping: TMappingFunc, pattern: string): TSchema;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// deno-fmt-ignore-file
|
|
2
|
-
import { TemplateLiteralDecode } from '../template_literal/decode.mjs';
|
|
3
2
|
import { FromType } from './from_type.mjs';
|
|
3
|
+
import { EvaluateTemplateLiteral } from '../evaluate/index.mjs';
|
|
4
4
|
export function FromTemplateLiteral(mapping, pattern) {
|
|
5
|
-
const
|
|
6
|
-
const result = FromType(mapping,
|
|
5
|
+
const evaluated = EvaluateTemplateLiteral(pattern);
|
|
6
|
+
const result = FromType(mapping, evaluated);
|
|
7
7
|
return result;
|
|
8
8
|
}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { type TSchema, type TSchemaOptions } from '../../types/schema.mjs';
|
|
2
2
|
import { type TProperties } from '../../types/properties.mjs';
|
|
3
3
|
import { type TCyclic } from '../../types/cyclic.mjs';
|
|
4
|
+
import { type TDependent } from '../../types/dependent.mjs';
|
|
4
5
|
import { type TIntersect } from '../../types/intersect.mjs';
|
|
5
6
|
import { type TUnion } from '../../types/union.mjs';
|
|
6
7
|
import { type TKeyOfDeferred } from '../../action/keyof.mjs';
|
|
7
8
|
import { type TState, type TInstantiateType, type TCanInstantiate } from '../instantiate.mjs';
|
|
8
9
|
import { type TCollapseToObject } from '../object/index.mjs';
|
|
9
10
|
import { type TFromType } from './from_type.mjs';
|
|
10
|
-
type TNormalizeType<Type extends TSchema, Result extends TSchema = (Type extends TCyclic | TIntersect | TUnion ? TCollapseToObject<Type> : Type)> = Result;
|
|
11
|
+
type TNormalizeType<Type extends TSchema, Result extends TSchema = (Type extends TCyclic | TDependent | TIntersect | TUnion ? TCollapseToObject<Type> : Type)> = Result;
|
|
11
12
|
export type TKeyOfAction<Type extends TSchema, Result extends TSchema = TCanInstantiate<[Type]> extends true ? TFromType<TNormalizeType<Type>> : TKeyOfDeferred<Type>> = Result;
|
|
12
13
|
export declare function KeyOfAction<Type extends TSchema>(type: Type, options: TSchemaOptions): TKeyOfAction<Type>;
|
|
13
14
|
export type TKeyOfInstantiate<Context extends TProperties, State extends TState, Type extends TSchema, InstantiatedType extends TSchema = TInstantiateType<Context, State, Type>> = TKeyOfAction<InstantiatedType>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// deno-fmt-ignore-file
|
|
2
2
|
import { Memory } from '../../../system/memory/index.mjs';
|
|
3
3
|
import { IsCyclic } from '../../types/cyclic.mjs';
|
|
4
|
+
import { IsDependent } from '../../types/dependent.mjs';
|
|
4
5
|
import { IsIntersect } from '../../types/intersect.mjs';
|
|
5
6
|
import { IsUnion } from '../../types/union.mjs';
|
|
6
7
|
import { KeyOfDeferred } from '../../action/keyof.mjs';
|
|
@@ -11,7 +12,7 @@ import { CollapseToObject } from '../object/index.mjs';
|
|
|
11
12
|
// ------------------------------------------------------------------
|
|
12
13
|
import { FromType } from './from_type.mjs';
|
|
13
14
|
function NormalizeType(type) {
|
|
14
|
-
const result = (IsCyclic(type) || IsIntersect(type) || IsUnion(type) ? CollapseToObject(type) : type);
|
|
15
|
+
const result = (IsCyclic(type) || IsDependent(type) || IsIntersect(type) || IsUnion(type) ? CollapseToObject(type) : type);
|
|
15
16
|
return result;
|
|
16
17
|
}
|
|
17
18
|
export function KeyOfAction(type, options) {
|
|
@@ -5,11 +5,11 @@ import { type TObject } from '../../types/object.mjs';
|
|
|
5
5
|
import { type TProperties } from '../../types/properties.mjs';
|
|
6
6
|
import { type TIdentifier } from '../../types/identifier.mjs';
|
|
7
7
|
import { type TTemplateLiteral } from '../../types/template_literal.mjs';
|
|
8
|
-
import { type
|
|
9
|
-
import { type
|
|
10
|
-
import { type
|
|
8
|
+
import { type TInstantiateType, type TState } from '../instantiate.mjs';
|
|
9
|
+
import { type TEvaluateIntersect } from '../evaluate/evaluate.mjs';
|
|
10
|
+
import { type TEvaluateTemplateLiteral } from '../evaluate/evaluate.mjs';
|
|
11
11
|
import { type TMappedVariants } from './mapped_variants.mjs';
|
|
12
|
-
type TCanonicalAs<InstantiatedAs extends TSchema, Result extends TSchema = InstantiatedAs extends TTemplateLiteral<infer Pattern extends string> ?
|
|
12
|
+
type TCanonicalAs<InstantiatedAs extends TSchema, Result extends TSchema = InstantiatedAs extends TTemplateLiteral<infer Pattern extends string> ? TEvaluateTemplateLiteral<Pattern> : InstantiatedAs> = Result;
|
|
13
13
|
type TMappedVariant<Context extends TProperties, State extends TState, Identifier extends TIdentifier, Variant extends TSchema, As extends TSchema, Property extends TSchema, VariantContext extends TProperties = Memory.TAssign<Context, {
|
|
14
14
|
[_ in Identifier['name']]: Variant;
|
|
15
15
|
}>, InstantiatedAs extends TSchema = TInstantiateType<VariantContext, State, As>, CanonicalAs extends TSchema = TCanonicalAs<InstantiatedAs>, InstantiatedProperty extends TSchema = TInstantiateType<VariantContext, State, Property>, Result extends TProperties = CanonicalAs extends TLiteral<string | number> ? {
|
|
@@ -4,13 +4,13 @@ import { Memory } from '../../../system/memory/index.mjs';
|
|
|
4
4
|
import { IsLiteralNumber, IsLiteralString } from '../../types/literal.mjs';
|
|
5
5
|
import { Object } from '../../types/object.mjs';
|
|
6
6
|
import { IsTemplateLiteral } from '../../types/template_literal.mjs';
|
|
7
|
-
import { TemplateLiteralDecode } from '../template_literal/decode.mjs';
|
|
8
7
|
import { InstantiateType } from '../instantiate.mjs';
|
|
9
|
-
import { EvaluateIntersect } from '../evaluate/
|
|
8
|
+
import { EvaluateIntersect } from '../evaluate/evaluate.mjs';
|
|
9
|
+
import { EvaluateTemplateLiteral } from '../evaluate/evaluate.mjs';
|
|
10
10
|
import { MappedVariants } from './mapped_variants.mjs';
|
|
11
11
|
function CanonicalAs(instantiatedAs) {
|
|
12
12
|
const result = IsTemplateLiteral(instantiatedAs)
|
|
13
|
-
?
|
|
13
|
+
? EvaluateTemplateLiteral(instantiatedAs.pattern)
|
|
14
14
|
: instantiatedAs;
|
|
15
15
|
return result;
|
|
16
16
|
}
|
|
@@ -3,12 +3,13 @@ import { type TLiteral, type TLiteralValue } from '../../types/literal.mjs';
|
|
|
3
3
|
import { type TEnum, type TEnumValue } from '../../types/enum.mjs';
|
|
4
4
|
import { type TTemplateLiteral } from '../../types/template_literal.mjs';
|
|
5
5
|
import { type TUnion } from '../../types/union.mjs';
|
|
6
|
-
import { type
|
|
7
|
-
import { type
|
|
8
|
-
type TFromTemplateLiteral<Pattern extends string,
|
|
6
|
+
import { type TEvaluateEnum } from '../evaluate/evaluate.mjs';
|
|
7
|
+
import { type TEvaluateTemplateLiteral } from '../evaluate/evaluate.mjs';
|
|
8
|
+
type TFromTemplateLiteral<Pattern extends string, Evaluated extends TSchema = TEvaluateTemplateLiteral<Pattern>, Result extends TSchema[] = TFromType<Evaluated>> = Result;
|
|
9
9
|
type TFromUnion<Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TFromUnion<Right, [...Result, ...TFromType<Left>]> : Result);
|
|
10
|
+
type TFromEnum<Values extends TEnumValue[], Evaluated extends TSchema = TEvaluateEnum<Values>, Result extends TSchema[] = TFromType<Evaluated>> = Result;
|
|
10
11
|
type TFromLiteral<Value extends TLiteralValue, Result extends TSchema[] = Value extends number ? [TLiteral<`${Value}`>] : [TLiteral<Value>]> = Result;
|
|
11
|
-
type TFromType<Type extends TSchema, Result extends TSchema[] = (Type extends TEnum<infer Values extends TEnumValue[]> ?
|
|
12
|
+
type TFromType<Type extends TSchema, Result extends TSchema[] = (Type extends TEnum<infer Values extends TEnumValue[]> ? TFromEnum<Values> : Type extends TLiteral<infer Value extends number> ? TFromLiteral<Value> : Type extends TTemplateLiteral<infer Pattern extends string> ? TFromTemplateLiteral<Pattern> : Type extends TUnion<infer Types extends TSchema[]> ? TFromUnion<Types> : [
|
|
12
13
|
Type
|
|
13
14
|
])> = Result;
|
|
14
15
|
export type TMappedVariants<Type extends TSchema, Result extends TSchema[] = TFromType<Type>> = Result;
|
|
@@ -4,11 +4,11 @@ import { Literal, IsLiteral } from '../../types/literal.mjs';
|
|
|
4
4
|
import { IsEnum } from '../../types/enum.mjs';
|
|
5
5
|
import { IsTemplateLiteral } from '../../types/template_literal.mjs';
|
|
6
6
|
import { IsUnion } from '../../types/union.mjs';
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
7
|
+
import { EvaluateEnum } from '../evaluate/evaluate.mjs';
|
|
8
|
+
import { EvaluateTemplateLiteral } from '../evaluate/evaluate.mjs';
|
|
9
9
|
function FromTemplateLiteral(pattern) {
|
|
10
|
-
const
|
|
11
|
-
const result = FromType(
|
|
10
|
+
const evaluated = EvaluateTemplateLiteral(pattern);
|
|
11
|
+
const result = FromType(evaluated);
|
|
12
12
|
return result;
|
|
13
13
|
}
|
|
14
14
|
function FromUnion(types) {
|
|
@@ -16,12 +16,17 @@ function FromUnion(types) {
|
|
|
16
16
|
return [...result, ...FromType(left)];
|
|
17
17
|
}, []);
|
|
18
18
|
}
|
|
19
|
+
function FromEnum(values) {
|
|
20
|
+
const evaluated = EvaluateEnum(values);
|
|
21
|
+
const result = FromType(evaluated);
|
|
22
|
+
return result;
|
|
23
|
+
}
|
|
19
24
|
function FromLiteral(value) {
|
|
20
25
|
const result = Guard.IsNumber(value) ? [Literal(`${value}`)] : [Literal(value)];
|
|
21
26
|
return result;
|
|
22
27
|
}
|
|
23
28
|
function FromType(type) {
|
|
24
|
-
const result = (IsEnum(type) ?
|
|
29
|
+
const result = (IsEnum(type) ? FromEnum(type.enum) :
|
|
25
30
|
IsLiteral(type) ? FromLiteral(type.const) :
|
|
26
31
|
IsTemplateLiteral(type) ? FromTemplateLiteral(type.pattern) :
|
|
27
32
|
IsUnion(type) ? FromUnion(type.anyOf) :
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type TSchema } from '../../types/schema.mjs';
|
|
2
|
+
import { type TFromType } from './from_type.mjs';
|
|
3
|
+
import { type TEvaluateDependent } from '../evaluate/evaluate.mjs';
|
|
4
|
+
export type TFromDependent<If extends TSchema, Then extends TSchema, Else extends TSchema, Evaluated extends TSchema = TEvaluateDependent<If, Then, Else>, Result extends TSchema = TFromType<Evaluated>> = Result;
|
|
5
|
+
export declare function FromDependent<If extends TSchema, Then extends TSchema, Else extends TSchema>(if_: If, then_: Then, else_: Else): TFromDependent<If, Then, Else>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// deno-fmt-ignore-file
|
|
2
|
+
import { FromType } from './from_type.mjs';
|
|
3
|
+
import { EvaluateDependent } from '../evaluate/evaluate.mjs';
|
|
4
|
+
export function FromDependent(if_, then_, else_) {
|
|
5
|
+
const evaluated = EvaluateDependent(if_, then_, else_);
|
|
6
|
+
const result = FromType(evaluated);
|
|
7
|
+
return result;
|
|
8
|
+
}
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { type TSchema } from '../../types/schema.mjs';
|
|
2
2
|
import { type TCyclic } from '../../types/cyclic.mjs';
|
|
3
|
+
import { type TDependent } from '../../types/dependent.mjs';
|
|
3
4
|
import { type TIntersect } from '../../types/intersect.mjs';
|
|
4
5
|
import { type TProperties } from '../../types/properties.mjs';
|
|
5
6
|
import { type TObject } from '../../types/object.mjs';
|
|
6
7
|
import { type TTuple } from '../../types/tuple.mjs';
|
|
7
8
|
import { type TUnion } from '../../types/union.mjs';
|
|
8
9
|
import { type TFromCyclic } from './from_cyclic.mjs';
|
|
10
|
+
import { type TFromDependent } from './from_dependent.mjs';
|
|
9
11
|
import { type TFromIntersect } from './from_intersect.mjs';
|
|
10
12
|
import { type TFromObject } from './from_object.mjs';
|
|
11
13
|
import { type TFromTuple } from './from_tuple.mjs';
|
|
12
14
|
import { type TFromUnion } from './from_union.mjs';
|
|
13
|
-
export type TFromType<Type extends TSchema, Result extends TProperties = (Type extends TCyclic<infer Defs extends TProperties, infer Ref extends string> ? TFromCyclic<Defs, Ref> : Type extends TIntersect<infer Types extends TSchema[]> ? TFromIntersect<Types> : Type extends TUnion<infer Types extends TSchema[]> ? TFromUnion<Types> : Type extends TTuple<infer Types extends TSchema[]> ? TFromTuple<Types> : Type extends TObject<infer Properties extends TProperties> ? TFromObject<Properties> : {})> = Result;
|
|
15
|
+
export type TFromType<Type extends TSchema, Result extends TProperties = (Type extends TCyclic<infer Defs extends TProperties, infer Ref extends string> ? TFromCyclic<Defs, Ref> : Type extends TDependent<infer If extends TSchema, infer Then extends TSchema, infer Else extends TSchema> ? TFromDependent<If, Then, Else> : Type extends TIntersect<infer Types extends TSchema[]> ? TFromIntersect<Types> : Type extends TUnion<infer Types extends TSchema[]> ? TFromUnion<Types> : Type extends TTuple<infer Types extends TSchema[]> ? TFromTuple<Types> : Type extends TObject<infer Properties extends TProperties> ? TFromObject<Properties> : {})> = Result;
|
|
14
16
|
export declare function FromType<Type extends TSchema>(type: Type): TFromType<Type>;
|
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
// deno-lint-ignore-file ban-types
|
|
2
2
|
// deno-fmt-ignore-file
|
|
3
3
|
import { IsCyclic } from '../../types/cyclic.mjs';
|
|
4
|
+
import { IsDependent } from '../../types/dependent.mjs';
|
|
4
5
|
import { IsIntersect } from '../../types/intersect.mjs';
|
|
5
6
|
import { IsObject } from '../../types/object.mjs';
|
|
6
7
|
import { IsTuple } from '../../types/tuple.mjs';
|
|
7
8
|
import { IsUnion } from '../../types/union.mjs';
|
|
8
9
|
import { FromCyclic } from './from_cyclic.mjs';
|
|
10
|
+
import { FromDependent } from './from_dependent.mjs';
|
|
9
11
|
import { FromIntersect } from './from_intersect.mjs';
|
|
10
12
|
import { FromObject } from './from_object.mjs';
|
|
11
13
|
import { FromTuple } from './from_tuple.mjs';
|
|
12
14
|
import { FromUnion } from './from_union.mjs';
|
|
13
15
|
export function FromType(type) {
|
|
14
16
|
return (IsCyclic(type) ? FromCyclic(type.$defs, type.$ref) :
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
IsDependent(type) ? FromDependent(type.if, type.then, type.else) :
|
|
18
|
+
IsIntersect(type) ? FromIntersect(type.allOf) :
|
|
19
|
+
IsUnion(type) ? FromUnion(type.anyOf) :
|
|
20
|
+
IsTuple(type) ? FromTuple(type.items) :
|
|
21
|
+
IsObject(type) ? FromObject(type.properties) :
|
|
22
|
+
{});
|
|
20
23
|
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type TSchema } from '../../types/schema.mjs';
|
|
2
|
+
import { type TFromType } from './from_type.mjs';
|
|
3
|
+
import { type TEvaluateDependent } from '../evaluate/evaluate.mjs';
|
|
4
|
+
export type TFromDependent<If extends TSchema, Then extends TSchema, Else extends TSchema, Evaluated extends TSchema = TEvaluateDependent<If, Then, Else>, Result extends TSchema = TFromType<Evaluated>> = Result;
|
|
5
|
+
export declare function FromDependent<If extends TSchema, Then extends TSchema, Else extends TSchema>(if_: If, then_: Then, else_: Else): TFromDependent<If, Then, Else>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// deno-fmt-ignore-file
|
|
2
|
+
import { FromType } from './from_type.mjs';
|
|
3
|
+
import { EvaluateDependent } from '../evaluate/evaluate.mjs';
|
|
4
|
+
export function FromDependent(if_, then_, else_) {
|
|
5
|
+
const evaluated = EvaluateDependent(if_, then_, else_);
|
|
6
|
+
const result = FromType(evaluated);
|
|
7
|
+
return result;
|
|
8
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type TSchema } from '../../types/schema.mjs';
|
|
2
2
|
import { type TFromType } from './from_type.mjs';
|
|
3
3
|
import { type TEvaluateIntersect } from '../evaluate/evaluate.mjs';
|
|
4
|
-
export type TFromIntersect<Types extends TSchema[],
|
|
4
|
+
export type TFromIntersect<Types extends TSchema[], Evaluated extends TSchema = TEvaluateIntersect<Types>, Result extends TSchema = TFromType<Evaluated>> = Result;
|
|
5
5
|
export declare function FromIntersect<Types extends TSchema[]>(types: [...Types]): TFromIntersect<Types>;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { FromType } from './from_type.mjs';
|
|
3
3
|
import { EvaluateIntersect } from '../evaluate/evaluate.mjs';
|
|
4
4
|
export function FromIntersect(types) {
|
|
5
|
-
const
|
|
6
|
-
|
|
5
|
+
const evaluated = EvaluateIntersect(types);
|
|
6
|
+
const result = FromType(evaluated);
|
|
7
|
+
return result;
|
|
7
8
|
}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { type TSchema } from '../../types/schema.mjs';
|
|
2
2
|
import { type TCyclic } from '../../types/cyclic.mjs';
|
|
3
|
+
import { type TDependent } from '../../types/dependent.mjs';
|
|
3
4
|
import { type TIntersect } from '../../types/intersect.mjs';
|
|
4
5
|
import { type TObject } from '../../types/object.mjs';
|
|
5
6
|
import { type TProperties } from '../../types/properties.mjs';
|
|
6
7
|
import { type TUnion } from '../../types/union.mjs';
|
|
7
8
|
import { type TFromCyclic } from './from_cyclic.mjs';
|
|
9
|
+
import { type TFromDependent } from './from_dependent.mjs';
|
|
8
10
|
import { type TFromIntersect } from './from_intersect.mjs';
|
|
9
11
|
import { type TFromUnion } from './from_union.mjs';
|
|
10
12
|
import { type TFromObject } from './from_object.mjs';
|
|
11
|
-
export type TFromType<Type extends TSchema> = (Type extends TCyclic<infer Defs extends TProperties, infer Ref extends string> ? TFromCyclic<Defs, Ref> : Type extends TIntersect<infer Types extends TSchema[]> ? TFromIntersect<Types> : Type extends TUnion<infer Types extends TSchema[]> ? TFromUnion<Types> : Type extends TObject<infer Properties extends TProperties> ? TFromObject<Properties> : TObject<{}>);
|
|
13
|
+
export type TFromType<Type extends TSchema> = (Type extends TCyclic<infer Defs extends TProperties, infer Ref extends string> ? TFromCyclic<Defs, Ref> : Type extends TDependent<infer If extends TSchema, infer Then extends TSchema, infer Else extends TSchema> ? TFromDependent<If, Then, Else> : Type extends TIntersect<infer Types extends TSchema[]> ? TFromIntersect<Types> : Type extends TUnion<infer Types extends TSchema[]> ? TFromUnion<Types> : Type extends TObject<infer Properties extends TProperties> ? TFromObject<Properties> : TObject<{}>);
|
|
12
14
|
export declare function FromType<Type extends TSchema>(type: Type): TFromType<Type>;
|
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
// deno-lint-ignore-file ban-types
|
|
2
2
|
// deno-fmt-ignore-file
|
|
3
3
|
import { IsCyclic } from '../../types/cyclic.mjs';
|
|
4
|
+
import { IsDependent } from '../../types/dependent.mjs';
|
|
4
5
|
import { IsIntersect } from '../../types/intersect.mjs';
|
|
5
6
|
import { Object, IsObject } from '../../types/object.mjs';
|
|
6
7
|
import { IsUnion } from '../../types/union.mjs';
|
|
7
8
|
import { FromCyclic } from './from_cyclic.mjs';
|
|
9
|
+
import { FromDependent } from './from_dependent.mjs';
|
|
8
10
|
import { FromIntersect } from './from_intersect.mjs';
|
|
9
11
|
import { FromUnion } from './from_union.mjs';
|
|
10
12
|
import { FromObject } from './from_object.mjs';
|
|
11
13
|
export function FromType(type) {
|
|
12
14
|
return (IsCyclic(type) ? FromCyclic(type.$defs, type.$ref) :
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
IsDependent(type) ? FromDependent(type.if, type.then, type.else) :
|
|
16
|
+
IsIntersect(type) ? FromIntersect(type.allOf) :
|
|
17
|
+
IsUnion(type) ? FromUnion(type.anyOf) :
|
|
18
|
+
IsObject(type) ? FromObject(type.properties) :
|
|
19
|
+
Object({}));
|
|
17
20
|
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type TSchema } from '../../types/schema.mjs';
|
|
2
|
+
import { type TFromType } from './from_type.mjs';
|
|
3
|
+
import { type TEvaluateDependent } from '../evaluate/evaluate.mjs';
|
|
4
|
+
export type TFromDependent<If extends TSchema, Then extends TSchema, Else extends TSchema, Evaluated extends TSchema = TEvaluateDependent<If, Then, Else>, Result extends TSchema = TFromType<Evaluated>> = Result;
|
|
5
|
+
export declare function FromDependent<If extends TSchema, Then extends TSchema, Else extends TSchema>(if_: If, then_: Then, else_: Else): TFromDependent<If, Then, Else>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// deno-fmt-ignore-file
|
|
2
|
+
import { FromType } from './from_type.mjs';
|
|
3
|
+
import { EvaluateDependent } from '../evaluate/evaluate.mjs';
|
|
4
|
+
export function FromDependent(if_, then_, else_) {
|
|
5
|
+
const evaluated = EvaluateDependent(if_, then_, else_);
|
|
6
|
+
const result = FromType(evaluated);
|
|
7
|
+
return result;
|
|
8
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type TSchema } from '../../types/schema.mjs';
|
|
2
2
|
import { type TFromType } from './from_type.mjs';
|
|
3
3
|
import { type TEvaluateIntersect } from '../evaluate/evaluate.mjs';
|
|
4
|
-
export type TFromIntersect<Types extends TSchema[],
|
|
4
|
+
export type TFromIntersect<Types extends TSchema[], Evaluated extends TSchema = TEvaluateIntersect<Types>, Result extends TSchema = TFromType<Evaluated>> = Result;
|
|
5
5
|
export declare function FromIntersect<Types extends TSchema[]>(types: [...Types]): TFromIntersect<Types>;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { FromType } from './from_type.mjs';
|
|
3
3
|
import { EvaluateIntersect } from '../evaluate/evaluate.mjs';
|
|
4
4
|
export function FromIntersect(types) {
|
|
5
|
-
const
|
|
6
|
-
|
|
5
|
+
const evaluated = EvaluateIntersect(types);
|
|
6
|
+
const result = FromType(evaluated);
|
|
7
|
+
return result;
|
|
7
8
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type TSchema } from '../../types/schema.mjs';
|
|
2
2
|
import { type TArray } from '../../types/array.mjs';
|
|
3
3
|
import { type TCyclic } from '../../types/cyclic.mjs';
|
|
4
|
+
import { type TDependent } from '../../types/dependent.mjs';
|
|
4
5
|
import { type TIntersect } from '../../types/intersect.mjs';
|
|
5
6
|
import { type TObject } from '../../types/object.mjs';
|
|
6
7
|
import { type TProperties } from '../../types/properties.mjs';
|
|
@@ -8,9 +9,10 @@ import { type TTuple } from '../../types/tuple.mjs';
|
|
|
8
9
|
import { type TUnion } from '../../types/union.mjs';
|
|
9
10
|
import { type TFromArray } from './from_array.mjs';
|
|
10
11
|
import { type TFromCyclic } from './from_cyclic.mjs';
|
|
12
|
+
import { type TFromDependent } from './from_dependent.mjs';
|
|
11
13
|
import { type TFromIntersect } from './from_intersect.mjs';
|
|
12
14
|
import { type TFromObject } from './from_object.mjs';
|
|
13
15
|
import { type TFromTuple } from './from_tuple.mjs';
|
|
14
16
|
import { type TFromUnion } from './from_union.mjs';
|
|
15
|
-
export type TFromType<Type extends TSchema> = (Type extends TArray<infer Type extends TSchema> ? TFromArray<Type> : Type extends TCyclic<infer Defs extends TProperties, infer Ref extends string> ? TFromCyclic<Defs, Ref> : Type extends TIntersect<infer Types extends TSchema[]> ? TFromIntersect<Types> : Type extends TObject<infer Properties extends TProperties> ? TFromObject<Properties> : Type extends TTuple<infer Types extends TSchema[]> ? TFromTuple<Types> : Type extends TUnion<infer Types extends TSchema[]> ? TFromUnion<Types> : Type);
|
|
17
|
+
export type TFromType<Type extends TSchema> = (Type extends TArray<infer Type extends TSchema> ? TFromArray<Type> : Type extends TCyclic<infer Defs extends TProperties, infer Ref extends string> ? TFromCyclic<Defs, Ref> : Type extends TDependent<infer If extends TSchema, infer Then extends TSchema, infer Else extends TSchema> ? TFromDependent<If, Then, Else> : Type extends TIntersect<infer Types extends TSchema[]> ? TFromIntersect<Types> : Type extends TObject<infer Properties extends TProperties> ? TFromObject<Properties> : Type extends TTuple<infer Types extends TSchema[]> ? TFromTuple<Types> : Type extends TUnion<infer Types extends TSchema[]> ? TFromUnion<Types> : Type);
|
|
16
18
|
export declare function FromType<Type extends TSchema>(type: Type): TFromType<Type>;
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
// deno-fmt-ignore-file
|
|
2
2
|
import { IsArray } from '../../types/array.mjs';
|
|
3
3
|
import { IsCyclic } from '../../types/cyclic.mjs';
|
|
4
|
+
import { IsDependent } from '../../types/dependent.mjs';
|
|
4
5
|
import { IsIntersect } from '../../types/intersect.mjs';
|
|
5
6
|
import { IsObject } from '../../types/object.mjs';
|
|
6
7
|
import { IsTuple } from '../../types/tuple.mjs';
|
|
7
8
|
import { IsUnion } from '../../types/union.mjs';
|
|
8
9
|
import { FromArray } from './from_array.mjs';
|
|
9
10
|
import { FromCyclic } from './from_cyclic.mjs';
|
|
11
|
+
import { FromDependent } from './from_dependent.mjs';
|
|
10
12
|
import { FromIntersect } from './from_intersect.mjs';
|
|
11
13
|
import { FromObject } from './from_object.mjs';
|
|
12
14
|
import { FromTuple } from './from_tuple.mjs';
|
|
@@ -14,9 +16,10 @@ import { FromUnion } from './from_union.mjs';
|
|
|
14
16
|
export function FromType(type) {
|
|
15
17
|
return (IsArray(type) ? FromArray(type.items) :
|
|
16
18
|
IsCyclic(type) ? FromCyclic(type.$defs, type.$ref) :
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
type)
|
|
19
|
+
IsDependent(type) ? FromDependent(type.if, type.then, type.else) :
|
|
20
|
+
IsIntersect(type) ? FromIntersect(type.allOf) :
|
|
21
|
+
IsObject(type) ? FromObject(type.properties) :
|
|
22
|
+
IsTuple(type) ? FromTuple(type.items) :
|
|
23
|
+
IsUnion(type) ? FromUnion(type.anyOf) :
|
|
24
|
+
type);
|
|
22
25
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type TSchema } from '../../types/index.mjs';
|
|
2
2
|
import { type TEnumValue } from '../../types/enum.mjs';
|
|
3
|
-
import { type TEnumValuesToUnion } from '../enum/enum_to_union.mjs';
|
|
4
3
|
import { type TFromKey } from './from_key.mjs';
|
|
5
|
-
|
|
4
|
+
import { type TEvaluateEnum } from '../evaluate/evaluate.mjs';
|
|
5
|
+
export type TFromEnumKey<Values extends TEnumValue[], Value extends TSchema, UnionKey extends TSchema = TEvaluateEnum<Values>, Result extends TSchema = TFromKey<UnionKey, Value>> = Result;
|
|
6
6
|
export declare function FromEnumKey<Values extends TEnumValue[], Value extends TSchema>(values: [...Values], value: Value): TFromEnumKey<Values, Value>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// deno-fmt-ignore-file
|
|
2
|
-
import { EnumValuesToUnion } from '../enum/enum_to_union.mjs';
|
|
3
2
|
import { FromKey } from './from_key.mjs';
|
|
3
|
+
import { EvaluateEnum } from '../evaluate/evaluate.mjs';
|
|
4
4
|
export function FromEnumKey(values, value) {
|
|
5
|
-
const unionKey =
|
|
5
|
+
const unionKey = EvaluateEnum(values);
|
|
6
6
|
const result = FromKey(unionKey, value);
|
|
7
7
|
return result;
|
|
8
8
|
}
|
|
@@ -3,6 +3,6 @@ import { type TRecord } from '../../types/record.mjs';
|
|
|
3
3
|
import { type TFromKey } from './from_key.mjs';
|
|
4
4
|
import { type TParsePatternIntoTypes } from '../patterns/pattern.mjs';
|
|
5
5
|
import { type TIsTemplateLiteralFinite } from '../template_literal/is_finite.mjs';
|
|
6
|
-
import { type
|
|
7
|
-
export type TFromTemplateKey<Pattern extends string, Value extends TSchema, Types extends TSchema[] = TParsePatternIntoTypes<Pattern>, Finite extends boolean = TIsTemplateLiteralFinite<Types>, Result extends TSchema = Finite extends true ? TFromKey<
|
|
6
|
+
import { type TEvaluateTemplateLiteral } from '../evaluate/evaluate.mjs';
|
|
7
|
+
export type TFromTemplateKey<Pattern extends string, Value extends TSchema, Types extends TSchema[] = TParsePatternIntoTypes<Pattern>, Finite extends boolean = TIsTemplateLiteralFinite<Types>, Result extends TSchema = Finite extends true ? TFromKey<TEvaluateTemplateLiteral<Pattern>, Value> : TRecord<Pattern, Value>> = Result;
|
|
8
8
|
export declare function FromTemplateKey<Pattern extends string, Value extends TSchema>(pattern: Pattern, value: Value): TFromTemplateKey<Pattern, Value>;
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
import { FromKey } from './from_key.mjs';
|
|
3
3
|
import { ParsePatternIntoTypes } from '../patterns/pattern.mjs';
|
|
4
4
|
import { IsTemplateLiteralFinite } from '../template_literal/is_finite.mjs';
|
|
5
|
-
import {
|
|
5
|
+
import { EvaluateTemplateLiteral } from '../evaluate/evaluate.mjs';
|
|
6
6
|
import { CreateRecord } from './record_create.mjs';
|
|
7
7
|
export function FromTemplateKey(pattern, value) {
|
|
8
8
|
const types = ParsePatternIntoTypes(pattern);
|
|
9
9
|
const finite = IsTemplateLiteralFinite(types);
|
|
10
|
-
const result = finite ? FromKey(
|
|
10
|
+
const result = finite ? FromKey(EvaluateTemplateLiteral(pattern), value) : CreateRecord(pattern, value);
|
|
11
11
|
return result;
|
|
12
12
|
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type TSchema } from '../../types/schema.mjs';
|
|
2
|
+
import { type TFromType } from './from_type.mjs';
|
|
3
|
+
import { type TEvaluateDependent } from '../evaluate/evaluate.mjs';
|
|
4
|
+
export type TFromDependent<If extends TSchema, Then extends TSchema, Else extends TSchema, Evaluated extends TSchema = TEvaluateDependent<If, Then, Else>, Result extends TSchema = TFromType<Evaluated>> = Result;
|
|
5
|
+
export declare function FromDependent<If extends TSchema, Then extends TSchema, Else extends TSchema>(if_: If, then_: Then, else_: Else): TFromDependent<If, Then, Else>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// deno-fmt-ignore-file
|
|
2
|
+
import { FromType } from './from_type.mjs';
|
|
3
|
+
import { EvaluateDependent } from '../evaluate/evaluate.mjs';
|
|
4
|
+
export function FromDependent(if_, then_, else_) {
|
|
5
|
+
const evaluated = EvaluateDependent(if_, then_, else_);
|
|
6
|
+
const result = FromType(evaluated);
|
|
7
|
+
return result;
|
|
8
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type TSchema } from '../../types/schema.mjs';
|
|
2
2
|
import { type TFromType } from './from_type.mjs';
|
|
3
3
|
import { type TEvaluateIntersect } from '../evaluate/evaluate.mjs';
|
|
4
|
-
export type TFromIntersect<Types extends TSchema[],
|
|
4
|
+
export type TFromIntersect<Types extends TSchema[], Evaluated extends TSchema = TEvaluateIntersect<Types>, Result extends TSchema = TFromType<Evaluated>> = Result;
|
|
5
5
|
export declare function FromIntersect<Types extends TSchema[]>(types: [...Types]): TFromIntersect<Types>;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { FromType } from './from_type.mjs';
|
|
3
3
|
import { EvaluateIntersect } from '../evaluate/evaluate.mjs';
|
|
4
4
|
export function FromIntersect(types) {
|
|
5
|
-
const
|
|
6
|
-
|
|
5
|
+
const evaluated = EvaluateIntersect(types);
|
|
6
|
+
const result = FromType(evaluated);
|
|
7
|
+
return result;
|
|
7
8
|
}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { type TSchema } from '../../types/schema.mjs';
|
|
2
2
|
import { type TCyclic } from '../../types/cyclic.mjs';
|
|
3
|
+
import { type TDependent } from '../../types/dependent.mjs';
|
|
3
4
|
import { type TIntersect } from '../../types/intersect.mjs';
|
|
4
5
|
import { type TObject } from '../../types/object.mjs';
|
|
5
6
|
import { type TProperties } from '../../types/properties.mjs';
|
|
6
7
|
import { type TUnion } from '../../types/union.mjs';
|
|
7
8
|
import { type TFromCyclic } from './from_cyclic.mjs';
|
|
9
|
+
import { type TFromDependent } from './from_dependent.mjs';
|
|
8
10
|
import { type TFromIntersect } from './from_intersect.mjs';
|
|
9
11
|
import { type TFromUnion } from './from_union.mjs';
|
|
10
12
|
import { type TFromObject } from './from_object.mjs';
|
|
11
|
-
export type TFromType<Type extends TSchema> = (Type extends TCyclic<infer Defs extends TProperties, infer Ref extends string> ? TFromCyclic<Defs, Ref> : Type extends TIntersect<infer Types extends TSchema[]> ? TFromIntersect<Types> : Type extends TUnion<infer Types extends TSchema[]> ? TFromUnion<Types> : Type extends TObject<infer Properties extends TProperties> ? TFromObject<Properties> : TObject<{}>);
|
|
13
|
+
export type TFromType<Type extends TSchema> = (Type extends TCyclic<infer Defs extends TProperties, infer Ref extends string> ? TFromCyclic<Defs, Ref> : Type extends TDependent<infer If extends TSchema, infer Then extends TSchema, infer Else extends TSchema> ? TFromDependent<If, Then, Else> : Type extends TIntersect<infer Types extends TSchema[]> ? TFromIntersect<Types> : Type extends TUnion<infer Types extends TSchema[]> ? TFromUnion<Types> : Type extends TObject<infer Properties extends TProperties> ? TFromObject<Properties> : TObject<{}>);
|
|
12
14
|
export declare function FromType<Type extends TSchema>(type: Type): TFromType<Type>;
|