import { PropertyFactory , BaseProperty , ContainerProperty , NodeProperty , } from "@fluid-experimental/property-properties" ; import { PropertyProxy , proxySymbol } from "./propertyProxy" ; import { PropertyProxyErrors } from "./errors" ; import { Utilities , forceType } from "./utilities" ; import { ProxyType , ReferenceType } from "./interfaces" ; hidden export const proxyHandler = { param target The Object that references a non-collection type
     *  external the Proxy handles.
     *  param key return { Object | external get ( target , key ) { let asteriskFound = false ; let caretFound = false ; if ( ! ( target . getProperty ( ) . has ( key ) ) ) { asteriskFound = Utilities . containsAsterisk ( key ) ; caretFound = Utilities . containsCaret ( key ) ; if ( asteriskFound || caretFound ) { key = key . slice ( 0 , - 1 ) ; } } if ( target . getProperty ( ) . has ( key ) ) { if ( asteriskFound ) { return PropertyProxy . proxify ( target . getProperty ( ) . get ( key , { referenceResolutionMode : BaseProperty . REFERENCE_RESOLUTION . NO_LEAFS } ) ! ) ; } else { return Utilities . proxifyInternal ( target . getProperty ( ) , key , caretFound ) ; } } return Reflect . get ( target , key ) ; } , /**
     * The set trap that handles assigning of values to properties. In case the underlying
     *  external is a  external * and the key does not yet exist an insertion happens.
     *  param target The Object that references a non-collection type
     *  external the Proxy handles.
     *  param key param value return set ( target , key , value ) { const asteriskFound = Utilities . containsAsterisk ( key ) ; if ( asteriskFound ) { key = key . slice ( 0 , - 1 ) ; } if ( target . getProperty ( ) . has ( key ) ) { const property = target . getProperty ( ) ; let propertyAtKey = property . get ( key , { referenceResolutionMode : BaseProperty . REFERENCE_RESOLUTION . NEVER } ) ! ; const isReferenceProperty = PropertyFactory . instanceOf ( propertyAtKey , "Reference" ) ; if ( ! asteriskFound && isReferenceProperty && forceType < ReferenceType > ( propertyAtKey ) ) { Utilities . setValueOfReferencedProperty ( propertyAtKey , undefined , value ) ; } else { if ( asteriskFound ) { if ( ! isReferenceProperty ) { throw new Error ( PropertyProxyErrors . NON_REFERENCE_ASSIGN ) ; } } else { propertyAtKey = property . get ( key ) ! ; } Utilities . assign ( propertyAtKey , value ) ; } return true ; } else { const property = target . getProperty ( ) ; if ( property . isDynamic ( ) && forceType < NodeProperty > ( property ) ) { property . insert ( key , Utilities . prepareElementForInsertion ( property , value ) ) ; return true ; } else { throw new Error ( PropertyProxyErrors . NON_DYNAMIC_INSERT ) ; } } } , param target The Object that references a non-collection type
     *  external the Proxy handles.
     *  param key return { Boolean } deleteProperty ( target , key ) { const property = target . getProperty ( ) ; if ( property . isDynamic ( ) && property . has ( key ) && forceType < NodeProperty > ( property ) ) { property . remove ( key ) ; return true ; } else { throw new Error ( PropertyProxyErrors . NON_DYNAMIC_REMOVE ) ; } } , param target The Object that references a non-collection type
     *  external the Proxy handles.
     *  param key return getOwnPropertyDescriptor ( target , key ) { if ( Reflect . has ( target . getProperty ( ) . getEntriesReadOnly ( ) , key ) && forceType < string > ( key ) ) { return { configurable : true , enumerable : true , value : PropertyProxy . proxify ( target . getProperty ( ) ) [ key ] , writable : true } ; } else if ( key === proxySymbol ) { return { configurable : true , enumerable : true , value : key , writable : false } ; } else { return undefined ; } } , param target The Object that references a non-collection type
     *  external the Proxy handles.
     *  param key return has : ( target , key ) => Reflect . has ( target . getProperty ( ) . getEntriesReadOnly ( ) , key ) || key === proxySymbol , param target The Object that references a non-collection type
     *  external * the Proxy handles.
     *  return The array containing the IDs of the  external .
      ownKeys : ( target ) => Reflect . ownKeys ( target . getProperty ( ) . getEntriesReadOnly ( ) ) } ;