import { SDKLogger } from './Logger' ; const throwReAssignError = ( prop ) => { SDKLogger . error ( `${ prop } cannot be reassigned to different values or point to different objects with mutate = false` ) ; } ; const immutableObjectTraps = { get ( target , prop ) { const value = target [ prop ] ; if ( isProxyable ( value ) ) { return createProxyInDev ( value ) ; } else { return value ; } } , set ( _1 , prop , _2 ) { throwReAssignError ( prop ) ; return true ; } , deleteProperty ( _1 , prop ) { throwReAssignError ( prop ) ; return true ; } , defineProperty ( _1 , prop , _2 ) { throwReAssignError ( prop ) ; return true ; } } ; const immutableArrayTraps = { get ( target , prop ) { const value = target [ prop ] ; if ( isProxyable ( value ) ) { return createProxyInDev ( value ) ; } else { return value ; } } , set ( _1 , prop , _2 ) { throwReAssignError ( prop ) ; return true ; } , deleteProperty ( _1 , prop ) { throwReAssignError ( prop ) ; return true ; } , defineProperty ( _ , prop ) { throwReAssignError ( prop ) ; return true ; } } ; const isProxyable = < T > ( value ) => { if ( ! value ) { return false ; } if ( typeof value !== 'object' ) { return false ; } if ( Array . isArray ( value ) ) { return true ; } const proto = Object . getPrototypeOf ( value ) ; return proto === null || proto === Object . prototype ; } ; const createProxyInDev = < T extends object > ( target ) : T => { if ( Array . isArray ( target ) ) { return new Proxy ( target , immutableArrayTraps ) ; } return new Proxy ( target , immutableObjectTraps ) ; } ; let port = < T extends object > ( target ) => target ; if ( process . env . NODE_ENV !== 'production' ) { port = createProxyInDev ; } export const createProxy = port ;