import { wrap , getCurrent } from './globalStack' ; class export default class Setup { private type { ( 'START' | 'READY' ) } memberof private state : 'START' | 'READY' = 'READY' ; /**
     * Get the current recorded setup object.
     */ public static getCurrent < T extends Setup > ( ) { return getCurrent < T > ( ) ; } param map param name param val protected add ( map , name , val ) { if ( this . state !== 'START' ) { throw new Error ( `Wrong setup state while calling 'add' method: ${ this . state }.` ) ; } const item = map [ name ] ; if ( item ) { item . push ( val ) ; } else { map [ name ] = [ val ] ; } } /**
     * Start executing setup flow.
     */ protected start ( ) { if ( this . state !== 'READY' ) { throw new Error ( `Wrong setup state while calling 'start' method: ${ this . state }.` ) ; } this . state = 'START' ; } /**
     * Clear the data when the setup flow finishes executing.
     */ protected clear ( ) { this . state = 'READY' ; } param setupFn public wrap < R > ( setupFn ) { try { this . start ( ) ; const result = wrap ( this , setupFn ) ; return result ; } catch ( e ) { throw e ; } finally { this . clear ( ) ; } } }