@@ -11,3 +11,3 @@ import { type TSchema, type TSchemaOptions } from '../../types/schema.mjs'; | ||
| import { type TFromType } from './from_type.mjs'; | ||
| type TNormalizeType<Type extends TSchema, Result extends TSchema = (Type extends TCyclic | TDependent | TIntersect | TUnion ? TCollapseToObject<Type> : Type)> = Result; | ||
| type TNormalizeType<Type extends TSchema, Result extends TSchema = (Type extends TCyclic ? TCollapseToObject<Type> : Type extends TDependent ? TCollapseToObject<Type> : Type extends TIntersect ? TCollapseToObject<Type> : Type extends TUnion ? TCollapseToObject<Type> : Type)> = Result; | ||
| export type TIndexAction<Type extends TSchema, Indexer extends TSchema, Result extends TSchema = TCanInstantiate<[Type, Indexer]> extends true ? TFromType<TNormalizeType<Type>, Indexer> : TIndexDeferred<Type, Indexer>> = Result; | ||
@@ -14,0 +14,0 @@ export declare function IndexAction<Type extends TSchema, Indexer extends TSchema>(type: Type, indexer: Indexer, options: TSchemaOptions): TIndexAction<Type, Indexer>; |
@@ -12,4 +12,6 @@ // deno-fmt-ignore-file | ||
| function NormalizeType(type) { | ||
| const result = (IsCyclic(type) || IsDependent(type) || IsIntersect(type) || IsUnion(type) ? CollapseToObject(type) : | ||
| type); | ||
| const result = (IsCyclic(type) || | ||
| IsDependent(type) || | ||
| IsIntersect(type) || | ||
| IsUnion(type)) ? CollapseToObject(type) : type; | ||
| return result; | ||
@@ -16,0 +18,0 @@ } |
@@ -0,1 +1,4 @@ | ||
| import { type TAddImmutableAction } from './immutable/instantiate_add.mjs'; | ||
| import { type TAddReadonlyAction } from './readonly/instantiate_add.mjs'; | ||
| import { type TAddOptionalAction } from './optional/instantiate_add.mjs'; | ||
| import { type TSchema } from '../types/schema.mjs'; | ||
@@ -74,2 +77,3 @@ import { type TArray } from '../types/array.mjs'; | ||
| export declare function InstantiateTypes<Context extends TProperties, State extends TState, Types extends TSchema[]>(context: Context, state: State, types: [...Types]): TInstantiateTypes<Context, State, Types>; | ||
| type TWithModifiers<Type extends TSchema, InstantiatedType extends TSchema, WithOptional extends TSchema = Type extends TOptional ? TAddOptionalAction<InstantiatedType> : InstantiatedType, WithReadonly extends TSchema = Type extends TReadonly ? TAddReadonlyAction<WithOptional> : WithOptional, WithImmutable extends TSchema = Type extends TImmutable ? TAddImmutableAction<WithReadonly> : WithReadonly> = WithImmutable; | ||
| type TInstantiateDeferred<Context extends TProperties, State extends TState, Action extends string, Parameters extends TSchema[]> = ([ | ||
@@ -175,7 +179,5 @@ Action, | ||
| ] extends ['With', [infer Type extends TSchema, infer Options extends TSchema]] ? TWithInstantiate<Context, State, Type, Options> : TDeferred<Action, Parameters>); | ||
| export type TInstantiateImmediate<Context extends TProperties, State extends TState, Type extends TSchema, Result 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)> = Result; | ||
| export declare function InstantiateImmediate<Context extends TProperties, State extends TState, Type extends TSchema>(context: Context, state: State, type: Type): TInstantiateImmediate<Context, State, Type>; | ||
| type TWithModifiers<Type extends TSchema, InstantiatedType extends TSchema, WithImmutable extends TSchema = Type extends TImmutable ? TImmutable<InstantiatedType> : InstantiatedType, WithReadonly extends TSchema = Type extends TReadonly ? TReadonly<WithImmutable> : WithImmutable, WithOptional extends TSchema = Type extends TOptional ? TOptional<WithReadonly> : WithReadonly> = WithOptional; | ||
| export type TInstantiateType<Context extends TProperties, State extends TState, Type extends TSchema, InstantiatedType extends TSchema = TInstantiateImmediate<Context, State, Type>, WithModifiers extends TSchema = Type extends TDeferred ? InstantiatedType : TWithModifiers<Type, InstantiatedType>> = WithModifiers; | ||
| export declare function InstantiateType<Context extends TProperties, State extends TState, Type extends TSchema>(context: TProperties, state: TState, type: Type): TInstantiateType<Context, State, Type>; | ||
| type TInstantiateImmediate<Context extends TProperties, State extends TState, Type extends TSchema, InstantiatedType 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 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), WithModifiers extends TSchema = TWithModifiers<Type, InstantiatedType>> = WithModifiers; | ||
| export type TInstantiateType<Context extends TProperties, State extends TState, Type extends TSchema, Result extends TSchema = Type extends TDeferred<infer Action extends string, infer Types extends TSchema[]> ? TInstantiateDeferred<Context, State, Action, Types> : TInstantiateImmediate<Context, State, Type>> = Result; | ||
| export declare function InstantiateType<Context extends TProperties, State extends TState, Type extends TSchema>(context: Context, state: State, type: Type): TInstantiateImmediate<Context, State, Type>; | ||
| /** Instantiates computed schematics using the given context and type. */ | ||
@@ -182,0 +184,0 @@ export type TInstantiate<Context extends TProperties, Type extends TSchema> = (TInstantiateType<Context, TState<[], []>, Type>); |
@@ -5,5 +5,7 @@ // deno-fmt-ignore-file | ||
| // ------------------------------------------------------------------ | ||
| // Types | ||
| // Modifiers | ||
| // ------------------------------------------------------------------ | ||
| import { IsBase } from '../types/base.mjs'; | ||
| import { AddImmutableAction } from './immutable/instantiate_add.mjs'; | ||
| import { AddReadonlyAction } from './readonly/instantiate_add.mjs'; | ||
| import { AddOptionalAction } from './optional/instantiate_add.mjs'; | ||
| import { _Array_, IsArray, ArrayOptions } from '../types/array.mjs'; | ||
@@ -34,5 +36,5 @@ import { AsyncIterator, IsAsyncIterator, AsyncIteratorOptions } from '../types/async_iterator.mjs'; | ||
| import { RemoveOptionalInstantiate } from './optional/instantiate_remove.mjs'; | ||
| import { Optional, IsOptional } from '../types/_optional.mjs'; | ||
| import { Immutable, IsImmutable } from '../types/_immutable.mjs'; | ||
| import { Readonly, IsReadonly } from '../types/_readonly.mjs'; | ||
| import { IsOptional } from '../types/_optional.mjs'; | ||
| import { IsImmutable } from '../types/_immutable.mjs'; | ||
| import { IsReadonly } from '../types/_readonly.mjs'; | ||
| // ------------------------------------------------------------------ | ||
@@ -92,5 +94,11 @@ // Instantiate | ||
| } | ||
| function WithModifiers(type, instantiatedType) { | ||
| const withOptional = IsOptional(type) ? AddOptionalAction(instantiatedType, {}) : instantiatedType; | ||
| const withReadonly = IsReadonly(type) ? AddReadonlyAction(withOptional, {}) : withOptional; | ||
| const withImmutable = IsImmutable(type) ? AddImmutableAction(withReadonly, {}) : withReadonly; | ||
| return withImmutable; | ||
| } | ||
| function InstantiateDeferred(context, state, action, parameters, options) { | ||
| return ( | ||
| // Modifier Actions | ||
| // Modifiers | ||
| Guard.IsEqual(action, 'AddImmutable') ? AddImmutableInstantiate(context, state, parameters[0], options) : | ||
@@ -132,5 +140,4 @@ Guard.IsEqual(action, 'RemoveImmutable') ? RemoveImmutableInstantiate(context, state, parameters[0], options) : | ||
| } | ||
| export function InstantiateImmediate(context, state, type) { | ||
| type = (IsBase(type) ? type.Clone() : type); | ||
| const result = (IsRef(type) ? RefInstantiate(context, state, type, type.$ref) : | ||
| function InstantiateImmediate(context, state, type) { | ||
| const instantiatedType = (IsRef(type) ? RefInstantiate(context, state, type, type.$ref) : | ||
| IsArray(type) ? _Array_(InstantiateType(context, state, type.items), ArrayOptions(type)) : | ||
@@ -140,26 +147,21 @@ IsAsyncIterator(type) ? AsyncIterator(InstantiateType(context, state, type.iteratorItems), AsyncIteratorOptions(type)) : | ||
| IsConstructor(type) ? Constructor(InstantiateTypes(context, state, type.parameters), InstantiateType(context, state, type.instanceType), ConstructorOptions(type)) : | ||
| IsDeferred(type) ? InstantiateDeferred(context, state, type.action, type.parameters, type.options) : | ||
| IsFunction(type) ? _Function_(InstantiateTypes(context, state, type.parameters), InstantiateType(context, state, type.returnType), FunctionOptions(type)) : | ||
| IsDependent(type) ? Dependent(InstantiateType(context, state, type.if), InstantiateType(context, state, type.then), InstantiateType(context, state, type.else), DependentOptions(type)) : | ||
| IsIntersect(type) ? Intersect(InstantiateTypes(context, state, type.allOf), IntersectOptions(type)) : | ||
| IsIterator(type) ? Iterator(InstantiateType(context, state, type.iteratorItems), IteratorOptions(type)) : | ||
| IsObject(type) ? Object(InstantiateProperties(context, state, type.properties), ObjectOptions(type)) : | ||
| IsPromise(type) ? _Promise_(InstantiateType(context, state, type.item), PromiseOptions(type)) : | ||
| IsRecord(type) ? RecordFromPattern(RecordPattern(type), InstantiateType(context, state, RecordValue(type))) : | ||
| IsRest(type) ? Rest(InstantiateType(context, state, type.items)) : | ||
| IsTuple(type) ? Tuple(InstantiateElements(context, state, type.items), TupleOptions(type)) : | ||
| IsUnion(type) ? Union(InstantiateTypes(context, state, type.anyOf), UnionOptions(type)) : | ||
| type); | ||
| return result; | ||
| IsFunction(type) ? _Function_(InstantiateTypes(context, state, type.parameters), InstantiateType(context, state, type.returnType), FunctionOptions(type)) : | ||
| IsDependent(type) ? Dependent(InstantiateType(context, state, type.if), InstantiateType(context, state, type.then), InstantiateType(context, state, type.else), DependentOptions(type)) : | ||
| IsIntersect(type) ? Intersect(InstantiateTypes(context, state, type.allOf), IntersectOptions(type)) : | ||
| IsIterator(type) ? Iterator(InstantiateType(context, state, type.iteratorItems), IteratorOptions(type)) : | ||
| IsObject(type) ? Object(InstantiateProperties(context, state, type.properties), ObjectOptions(type)) : | ||
| IsPromise(type) ? _Promise_(InstantiateType(context, state, type.item), PromiseOptions(type)) : | ||
| IsRecord(type) ? RecordFromPattern(RecordPattern(type), InstantiateType(context, state, RecordValue(type))) : | ||
| IsRest(type) ? Rest(InstantiateType(context, state, type.items)) : | ||
| IsTuple(type) ? Tuple(InstantiateElements(context, state, type.items), TupleOptions(type)) : | ||
| IsUnion(type) ? Union(InstantiateTypes(context, state, type.anyOf), UnionOptions(type)) : | ||
| type); | ||
| const withModifiers = WithModifiers(type, instantiatedType); | ||
| return withModifiers; | ||
| } | ||
| function WithModifiers(type, instantiatedType) { | ||
| const withImmutable = IsImmutable(type) ? Immutable(instantiatedType) : instantiatedType; | ||
| const withReadonly = IsReadonly(type) ? Readonly(withImmutable) : withImmutable; | ||
| const withOptional = IsOptional(type) ? Optional(withReadonly) : withReadonly; | ||
| return withOptional; | ||
| } | ||
| export function InstantiateType(context, state, type) { | ||
| const instantiatedType = InstantiateImmediate(context, state, type); | ||
| const withModifiers = IsDeferred(type) ? instantiatedType : WithModifiers(type, instantiatedType); | ||
| return withModifiers; | ||
| const result = IsDeferred(type) | ||
| ? InstantiateDeferred(context, state, type.action, type.parameters, type.options) | ||
| : InstantiateImmediate(context, state, type); | ||
| return result; | ||
| } | ||
@@ -166,0 +168,0 @@ /** Instantiates computed schematics using the given context and type. */ |
@@ -11,3 +11,3 @@ import { type TSchema, type TSchemaOptions } from '../../types/schema.mjs'; | ||
| import { type TFromType } from './from_type.mjs'; | ||
| type TNormalizeType<Type extends TSchema, Result extends TSchema = (Type extends TCyclic | TDependent | TIntersect | TUnion ? TCollapseToObject<Type> : Type)> = Result; | ||
| type TNormalizeType<Type extends TSchema, Result extends TSchema = (Type extends TCyclic ? TCollapseToObject<Type> : Type extends TDependent ? TCollapseToObject<Type> : Type extends TIntersect ? TCollapseToObject<Type> : Type extends TUnion ? TCollapseToObject<Type> : Type)> = Result; | ||
| export type TKeyOfAction<Type extends TSchema, Result extends TSchema = TCanInstantiate<[Type]> extends true ? TFromType<TNormalizeType<Type>> : TKeyOfDeferred<Type>> = Result; | ||
@@ -14,0 +14,0 @@ export declare function KeyOfAction<Type extends TSchema>(type: Type, options: TSchemaOptions): TKeyOfAction<Type>; |
@@ -15,3 +15,6 @@ // deno-fmt-ignore-file | ||
| function NormalizeType(type) { | ||
| const result = (IsCyclic(type) || IsDependent(type) || IsIntersect(type) || IsUnion(type) ? CollapseToObject(type) : type); | ||
| const result = (IsCyclic(type) || | ||
| IsDependent(type) || | ||
| IsIntersect(type) || | ||
| IsUnion(type)) ? CollapseToObject(type) : type; | ||
| return result; | ||
@@ -18,0 +21,0 @@ } |
+1
-1
| { | ||
| "name": "typebox", | ||
| "description": "Json Schema Type Builder with Static Type Resolution for TypeScript", | ||
| "version": "1.2.18", | ||
| "version": "1.2.19", | ||
| "keywords": [ | ||
@@ -6,0 +6,0 @@ "typescript", |
1512851
0.02%17265
0.04%