@@ -31,28 +31,17 @@ THE SOFTWARE.
3131import { Memory } from '../../../system/memory/index.ts'
3232import { type TSchema , type TSchemaOptions } from '../../types/schema.ts'
3333import { type TProperties } from '../../types/properties.ts'
34- import { type TAny , IsAny } from '../../types/any.ts'
35- import { type TArray , IsArray } from '../../types/array.ts'
3634import { type TCyclic , IsCyclic } from '../../types/cyclic.ts'
3735import { type TIntersect , IsIntersect } from '../../types/intersect.ts'
38- import { type TNever , Never } from '../../types/never.ts'
39- import { type TObject , IsObject } from '../../types/object.ts'
40- import { type TRecord , IsRecord } from '../../types/record.ts'
41- import { type TTuple , IsTuple } from '../../types/tuple.ts'
4236import { type TUnion , IsUnion } from '../../types/union.ts'
4337import { type TKeyOfDeferred , KeyOfDeferred } from '../../action/keyof.ts'
44- import { type TState , type TInstantiateType , type TCanInstantiate , InstantiateType , CanInstantiate } from '../instantiate.ts'
45-
38+ import { type TState , type TInstantiateType , type TCanInstantiateFast , InstantiateType , CanInstantiateFast } from '../instantiate.ts'
4639import { type TCollapseToObject , CollapseToObject } from '../object/index.ts'
4740
4841// ------------------------------------------------------------------
4942// Computed
5043// ------------------------------------------------------------------
51- import { type TFromAny , FromAny } from './from-any.ts'
52- import { type TFromArray , FromArray } from './from-array.ts'
53- import { type TFromObject , FromObject } from './from-object.ts'
54- import { type TFromRecord , FromRecord } from './from-record.ts'
55- import { type TFromTuple , FromTuple } from './from-tuple.ts'
44+ import { type TFromType , FromType } from './from-type.ts'
5645
5746// ------------------------------------------------------------------
5847//
@@ -67,69 +56,36 @@ import { type TFromTuple, FromTuple } from './from-tuple.ts'
6756//
6857// ------------------------------------------------------------------
6958type TNormalizeType < Type extends TSchema ,
70- Result extends TSchema = (
71- Type extends TCyclic | TIntersect | TUnion ? TCollapseToObject < Type > :
72- Type
73- )
59+ Result extends TSchema = ( Type extends TCyclic | TIntersect | TUnion ? TCollapseToObject < Type > : Type )
7460> = Result
7561function NormalizeType < Type extends TSchema > ( type : Type ) : TNormalizeType < Type > {
76- const result = (
77- IsCyclic ( type ) || IsIntersect ( type ) || IsUnion ( type ) ? CollapseToObject ( type ) :
78- type
79- )
62+ const result = ( IsCyclic ( type ) || IsIntersect ( type ) || IsUnion ( type ) ? CollapseToObject ( type ) : type )
8063 return result as never
8164}
8265// ------------------------------------------------------------------
8366// Action
8467// ------------------------------------------------------------------
8568export type TKeyOfAction < Type extends TSchema ,
86- Normal extends TSchema = TNormalizeType < Type >
87- > = (
88- Normal extends TAny ? TFromAny :
89- Normal extends TArray < infer Type extends TSchema > ? TFromArray < Type > :
90- Normal extends TObject < infer Properties extends TProperties > ? TFromObject < Properties > :
91- Normal extends TRecord ? TFromRecord < Normal > :
92- Normal extends TTuple < infer Types extends TSchema [ ] > ? TFromTuple < Types > :
93- TNever
94- )
95- export function KeyOfAction < Type extends TSchema > ( type : Type ) : TKeyOfAction < Type > {
96- const normal = NormalizeType ( type )
69+ Result extends TSchema = TCanInstantiateFast < [ Type ] > extends true
70+ ? TFromType < TNormalizeType < Type > >
71+ : TKeyOfDeferred < Type >
72+ > = Result
73+ export function KeyOfAction < Type extends TSchema > ( type : Type , options : TSchemaOptions ) : TKeyOfAction < Type > {
9774 return (
98- IsAny ( normal ) ? FromAny ( ) :
99- IsArray ( normal ) ? FromArray ( normal . items ) :
100- IsObject ( normal ) ? FromObject ( normal . properties ) :
101- IsRecord ( normal ) ? FromRecord ( normal ) :
102- IsTuple ( normal ) ? FromTuple ( normal . items ) :
103- Never ( )
75+ CanInstantiateFast ( [ type ] )
76+ ? Memory . Update ( FromType ( NormalizeType ( type ) ) , { } , options )
77+ : KeyOfDeferred ( type , options )
10478 ) as never
10579}
10680// ------------------------------------------------------------------
107- // Immediate
81+ // Instantiate
10882// ------------------------------------------------------------------
109- export type TKeyOfImmediate < Context extends TProperties , State extends TState , Type extends TSchema ,
83+ export type TKeyOfInstantiate < Context extends TProperties , State extends TState , Type extends TSchema ,
11084 InstantiatedType extends TSchema = TInstantiateType < Context , State , Type >
11185> = TKeyOfAction < InstantiatedType >
112-
113- export function KeyOfImmediate < Context extends TProperties , State extends TState , Type extends TSchema >
114- ( context : Context , state : State , type : Type , options : TSchemaOptions ) :
115- TKeyOfImmediate < Context , State , Type > {
116- const instantiatedType = InstantiateType ( context , state , type )
117- return Memory . Update ( KeyOfAction ( instantiatedType ) , { } , options ) as never
118- }
119- // ------------------------------------------------------------------
120- // Instantiate
121- // ------------------------------------------------------------------
122- export type TKeyOfInstantiate < Context extends TProperties , State extends TState , Type extends TSchema > =
123- TCanInstantiate < Context , [ Type ] > extends true
124- ? TKeyOfImmediate < Context , State , Type >
125- : TKeyOfDeferred < Type >
126-
12786export function KeyOfInstantiate < Context extends TProperties , State extends TState , Type extends TSchema >
12887 ( context : Context , state : State , type : Type , options : TSchemaOptions ) :
12988 TKeyOfInstantiate < Context , State , Type > {
130- return (
131- CanInstantiate ( context , [ type ] )
132- ? KeyOfImmediate ( context , state , type , options )
133- : KeyOfDeferred ( type , options )
134- ) as never
89+ const instantiatedType = InstantiateType ( context , state , type )
90+ return KeyOfAction ( instantiatedType , options ) as never
13591}
0 commit comments