@microsoft/kiota-abstractions
Version:
Core abstractions for kiota generated libraries in TypeScript and JavaScript
28 lines • 1.17 kB
JavaScript
// A method that creates a ProxyHandler for a generic model T and attaches it to a backing store.
export const createBackedModelProxyHandler = (backingStoreFactory) => {
// Each model has a backing store that is created by the BackingStoreFactorySingleton
const backingStore = backingStoreFactory.createBackingStore();
/**
* The ProxyHandler for the model.
*/
const handler = {
get: (_target, prop) => {
if (prop === "backingStore") {
return backingStore;
}
return backingStore.get(prop.toString());
},
set: (target, prop, value, receiver) => {
if (prop === "backingStore") {
console.warn(`BackingStore - Ignoring attempt to set 'backingStore' property`);
return true;
}
// set the value on the target object as well to allow it to have keys needed for serialization/deserialization
Reflect.set(target, prop, value, receiver);
backingStore.set(prop.toString(), value);
return true;
},
};
return handler;
};
//# sourceMappingURL=backedModelProxy.js.map