import { assert } from './auxiliaries' ; /**
 * Utility class to replicate the structure of all alterable properties of a class to. This was initially designed
 * to be used in combination with an `alterable` decorator (but instance-based property decoration does not work
 * yet). For now though, this is used for explicit alterable structure replication and management.
 * ```
 * const alterable = {
 *     any: false,
 *     data: { any: false, alpha: false, beta: false },
 *     modifier: false };
 *
 * const altered = Object.assign(new ChangeLookup(), alterable);
 * altered.alter('data.beta');
 * if(altered.data.any) { ... }
 * ```
 */ export class ChangeLookup { /**
     * Also allow for string-based index access in TypeScript.
     */ [ index ] : boolean | any ; param path param property protected static alter ( path , property ) { assert ( property . hasOwnProperty ( 'any' ) , `expected alterable object to provide 'any' key` ) ; property . any = true ; const names = path . split ( '.' ) ; const name = names . shift ( ) ! ; assert ( name === '' || property . hasOwnProperty ( name ) , `expected object to have key '${ name }' in order to capture alterations` ) ; if ( name !== '' && typeof property [ name ] !== 'object' ) { property [ name ] = true ; return ; } if ( name !== '' && names . length > 0 ) { ChangeLookup . alter ( names . join ( '.' ) , property [ name ] ) ; return ; } const parent = name !== '' ? property [ name ] : property ; for ( const child of Object . getOwnPropertyNames ( parent ) ) { if ( child === 'any' ) { continue ; } ChangeLookup . alter ( child , parent ) ; } } param property protected static reset ( property ) { for ( const name of Object . getOwnPropertyNames ( property ) ) { if ( typeof property [ name ] === 'object' ) { ChangeLookup . reset ( property [ name ] ) ; continue ; } property [ name ] = false ; } } param path alter ( path ) { return ChangeLookup . alter ( path , this ) ; } /**
     * Reset all alteration states to false.
     */ reset ( ) { return ChangeLookup . reset ( this ) ; } }