import { assignObjImmutableProp } from "./prop" ; export interface AppEnv { getProperty : AppEnvGetPropertyMethod ; hasProperty : AppEnvHasPropertyMethod ; setProperties : AppEnvSetPropertiesMethod ; setProperty : AppEnvSetPropertyMethod ; } interface AppEnvGetPropertyMethod { ( name , options ? ) : any ; } interface AppEnvHasPropertyMethod { ( name ) : boolean ; } interface AppEnvSetPropertiesMethod { ( properties ) : void ; } interface AppEnvSetPropertyMethod { ( name , value ) : void ; } export interface AppEnvGetPropertyOptions { defaultValue ? : any ; failIfNotExist ? : boolean ; } interface InternalPrivateAPI { properties : { [ key ] : any ; } ; } param propertyName param options name memberof function __getProperty ( propertyName , options = { } ) { const self = this as InternalPrivateAPI ; const { defaultValue = null , failIfNotExist = true } = options ; if ( typeof self . properties [ propertyName ] !== "undefined" ) { return self . properties [ propertyName ] ; } if ( failIfNotExist ) { throw new Error ( `Unable to get application environment property: '${ propertyName }' does not exist` ) ; } return defaultValue ; } param propertyName returns name memberof function __hasProperty ( propertyName ) { const self = this as InternalPrivateAPI ; return typeof self . properties [ propertyName ] !== "undefined" ; } param propertyList name memberof see setProperty function __setProperties ( propertyList ) { const self = this as InternalPrivateAPI ; const setProp = __setProperty . bind ( self ) ; for ( const propertyName in propertyList ) { setProp ( propertyName , propertyList [ propertyName ] ) ; } } param propertyName param propertyValue name memberof function __setProperty ( propertyName , propertyValue ) { const self = this as InternalPrivateAPI ; if ( typeof self . properties [ propertyName ] !== "undefined" ) { throw new Error ( `Unable to set application environment property: '${ propertyName }' already exists` ) ; } assignObjImmutableProp ( self . properties , propertyName , propertyValue ) ; } returns export function createAppEnv ( ) { const env = { } ; const privateEnv = { properties : { } } ; assignObjImmutableProp ( env , "getProperty" , __getProperty . bind ( privateEnv ) ) ; assignObjImmutableProp ( env , "hasProperty" , __hasProperty . bind ( privateEnv ) ) ; assignObjImmutableProp ( env , "setProperties" , __setProperties . bind ( privateEnv ) ) ; assignObjImmutableProp ( env , "setProperty" , __setProperty . bind ( privateEnv ) ) ; return env as AppEnv ; }