import { ArrayPropConfiguration } from './decorators/array-prop' ; import { PropConfiguration } from './decorators/prop' ; import { RestConfiguration } from './decorators/rest' ; import { RestgooseModel } from './restgoose-model' ; import { Constructor } from './types' ; export declare interface RestModelEntry < T extends RestgooseModel > { type : Constructor < T > ; restConfig : RestConfiguration < T > ; } export declare interface RestPropEntry < T extends RestgooseModel > { type : Constructor < T | Number | String | Boolean | Date > ; config : PropConfiguration < T > ; name : string ; restConfig ? : RestConfiguration < T > ; } export declare interface HookEntry { type : 'pre' | 'post' ; action : string ; method : ( ... args ) => any ; } const hooks = new Map < string , HookEntry [ ] > ( ) ; const models = new Map < string , RestModelEntry < any > > ( ) ; const properties = new Map < string , Map < string , RestPropEntry < any > > > ( ) ; const RestRegistry = { registerModel < T extends RestgooseModel > ( modelType , config ) { models . set ( modelType . name , { type : modelType , restConfig : config , } ) ; } , registerProperty < T extends RestgooseModel , S extends RestgooseModel > ( modelType , propertyKey , Type , config ) { if ( ! properties . has ( modelType . name ) ) { properties . set ( modelType . name , new Map < string , RestPropEntry < any > > ( ) ) ; } const entry = properties . get ( modelType . name ) . get ( propertyKey ) || { type : Type , name : propertyKey , config : null , } ; entry . config = config ; properties . get ( modelType . name ) . set ( propertyKey , entry ) ; } , registerHook < T extends RestgooseModel > ( modelType , type , action , method ) { if ( ! hooks . has ( modelType . name ) ) { hooks . set ( modelType . name , [ ] ) ; } const hooksArray = hooks . get ( modelType . name ) ; hooksArray . push ( { type : type , action : action , method : method , } ) ; } , registerSubrest < T extends RestgooseModel > ( modelType , propertyKey , config ) { if ( ! properties . has ( modelType . name ) ) { properties . set ( modelType . name , new Map < string , RestPropEntry < any > > ( ) ) ; } const entry = properties . get ( modelType . name ) . get ( propertyKey ) || { type : modelType , name : propertyKey , config : null , } ; entry . restConfig = config ; properties . get ( modelType . name ) . set ( propertyKey , entry ) ; } , getModel < T extends RestgooseModel > ( modelType ) { return models . get ( modelType . name ) ; } , listModels ( ) { return models . values ( ) ; } , listHooksOf < T extends RestgooseModel > ( modelType ) { const map = hooks . get ( modelType . name ) ; return map || [ ] ; } , listPropertiesOf < T extends RestgooseModel > ( modelType ) { const map = properties . get ( modelType . name ) ; if ( map ) { return map . values ( ) ; } else { return [ ] ; } } , listSubrestsOf < T extends RestgooseModel > ( modelType ) { const map = properties . get ( modelType . name ) ; if ( map ) { const out = [ ] ; for ( const entry of map . values ( ) ) { if ( entry . restConfig ) { out . push ( entry ) ; } } return out ; } else { return [ ] ; } } , } ; export { RestRegistry } ;