import { Factory , FactoryConfig , AttributeFunction , Config , ArrayFactory , } from "./index" ; import { DiffProperties , ArrayElement } from "./utils" ; import { compute } from "./compute" ; import { DerivedFunction } from "./derive" ; import { FACTORY_FUNCTION_KEY } from "./define" ; type Merge < Base , Result > = DiffProperties < Result , Base > & Partial < Base > ; type ExtendConfig < Base , Result > = { [ Key in keyof Merge < Base , Result > ] : Merge < Base , Result > [ Key ] | AttributeFunction < Merge < Base , Result > [ Key ] > | Factory < Merge < Base , Result > [ Key ] > | DerivedFunction < Result , Merge < Base , Result > [ Key ] > | ArrayFactory < ArrayElement < Merge < Base , Result > [ Key ] > > ; } ; param base param config function extend < Base , Result extends Base > ( base , config ) { let invocations = 0 ; const factory = ( override = { } ) => { invocations ++ ; let result = base ( override as FactoryConfig < Base > ) as Result ; let computedKeys = [ ] ; const values = Object . assign ( { } , config , override ) as Config < Result > ; for ( let key in values ) { compute ( key , values , result , invocations , [ ] , override , computedKeys ) ; } return result ; } ; factory . __cooky_cutter = FACTORY_FUNCTION_KEY as typeof FACTORY_FUNCTION_KEY ; factory . resetSequence = ( ) => { invocations = 0 ; } ; return factory ; } export { extend , ExtendConfig } ;