@politie/sherlock-proxy
Version:
A proxy extension to Sherlock.
2 lines • 4.83 kB
JavaScript
import{__generator as r}from"tslib";import{utils as t,isDerivable as e,_internal as n,isSettableDerivable as i,lens as u}from"@politie/sherlock";var o=Symbol("isDerivableProxy");function c(r){return!0===r[o]}var a=function(){function e(){this.$$derivable=void 0}return Object.defineProperty(e.prototype,"$derivable",{get:function(){var r=this.$proxyDescriptor;return r.$$derivable||(r.$$derivable=function(r,t){if(!t)return r;var e=t.get,n=t.set;return n&&i(r)?u({get:e,set:function(t,e){r.set(n.call(this,t,e))}},r).autoCache():r.derive(e).autoCache()}(r.$target,r.$lens&&r.$lens()))},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"$value",{get:function(){var r=this.$proxyDescriptor;try{return r.$derivable.get()}catch(t){throw Object.assign(Error("error while getting ".concat(r.$expression||"$value",": ").concat(n.isError(t)&&t.message)),{jse_cause:t})}},set:function(r){var t=this.$proxyDescriptor,e=t.$derivable,u=t.$expression;if(!i(e))throw Error("".concat(u||"$value"," is readonly"));try{e.set(r)}catch(r){throw Object.assign(Error("error while setting ".concat(u||"$value",": ").concat(n.isError(r)&&r.message)),{jse_cause:r})}},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"$targetValue",{get:function(){var r=this.$proxyDescriptor;try{return r.$target.get()}catch(t){throw Object.assign(Error("error while getting ".concat(r.$expression||"$targetValue",": ").concat(n.isError(t)&&t.message)),{jse_cause:t})}},set:function(r){var t=this.$proxyDescriptor,e=t.$target,u=t.$expression;if(!i(e))throw Error("".concat(u||"$targetValue"," is readonly"));try{e.set(r)}catch(r){throw Object.assign(Error("error while setting ".concat(u||"$targetValue",": ").concat(n.isError(r)&&r.message)),{jse_cause:r})}},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"$proxyDescriptor",{get:function(){return this},enumerable:!1,configurable:!0}),e.prototype.$create=function(r,e,n){var i=t.clone(this.$proxyDescriptor);return i.$target=r,Object.getOwnPropertyNames(i).filter((function(r){return r.startsWith("$$")})).forEach((function(r){return i[r]=void 0})),i.$expression=e,i.$path=n,new Proxy(i,s)},e.prototype.$pluck=function(r){var t=this.$proxyDescriptor;return t.$create(t.$derivable.pluck(r),h(t.$expression,r),b(t.$path,r))},e.prototype.$pluckableKeys=function(){var r=this.$proxyDescriptor.$value;return"object"==typeof r?Reflect.ownKeys(r):[]},e.prototype.$length=function(){var r=this.$proxyDescriptor.$targetValue;return Array.isArray(r)?r.length:void 0},e.prototype.$and=function(r){return this.$proxyDescriptor.$derivable.and(f(r))},e.prototype.$or=function(r){return this.$proxyDescriptor.$derivable.or(f(r))},e.prototype.$not=function(){return this.$proxyDescriptor.$derivable.not()},e.prototype.$is=function(r){return this.$proxyDescriptor.$derivable.is(f(r))},e.prototype.$derive=function(){var r=this.$proxyDescriptor.$derivable;return r.derive.apply(r,arguments)},e.prototype.$react=function(r,t){return this.$proxyDescriptor.$derivable.react(r,t)},e.prototype.toJSON=function(){return this.$proxyDescriptor.$value},Object.defineProperty(e.prototype,Symbol.toStringTag,{get:function(){return"DerivableProxy"},enumerable:!1,configurable:!0}),e.prototype[Symbol.iterator]=function(){var t,e,n,i;return r(this,(function(r){switch(r.label){case 0:if(t=this.$proxyDescriptor,void 0===(e=t.$length()))throw n=t.$expression,Object.assign(Error("".concat(n||"object"," is not iterable")),{value:t.$value,expression:n});i=0,r.label=1;case 1:return i<e?[4,t.$pluck(i)]:[3,4];case 2:r.sent(),r.label=3;case 3:return i++,[3,1];case 4:return[2]}}))},Object.defineProperty(e.prototype,"length",{get:function(){return this.$proxyDescriptor.$length()},enumerable:!1,configurable:!0}),e}();function f(r){return c(r)?r.$derivable:r}a.prototype[o]=!0;var s={get:function(r,t,e){return"$proxyDescriptor"===t?r:l(r,t)?r.$pluck.call(e,t):Reflect.get(r,t,e)},set:function(r,t,n,i){if(l(r,t)){var u=r.$pluck.call(i,t);return n&&c(n)?u.$targetValue=n.$targetValue:u.$value=n&&e(n)?n.get():n,!0}return Reflect.set(r,t,n,i)},has:function(r,t){return t===Symbol.iterator?void 0!==r.$length():l(r,t)},getOwnPropertyDescriptor:function(r,t){if(l(r,t))return{get:function(){return this[t]},set:function(r){this[t]=r},configurable:!0,enumerable:!0}},ownKeys:function(r){return r.$pluckableKeys()}};function l(r,t){return"number"==typeof t||"string"==typeof t&&"$"!==t[0]&&!Reflect.has(r,t)}function h(r,t){return void 0===r&&(r=""),"string"==typeof t&&/^[a-z_][a-z_0-9]*$/i.test(t)?r+"."+t:"string"==typeof t?r+'["'+t.replace(/\\/g,"\\\\").replace(/\"/g,'\\"')+'"]':r+"["+t+"]"}function b(r,t){return void 0===r&&(r=[]),r.concat(t)}export{a as ProxyDescriptor,h as extendExpression,b as extendPath,c as isDerivableProxy,f as unwrapProxy};
//# sourceMappingURL=sherlock-proxy.esm.min.js.map