@politie/sherlock-proxy 3.4.15 → 3.4.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@politie/sherlock-proxy",
3
- "version": "3.4.15",
3
+ "version": "3.4.16",
4
4
  "description": "A proxy extension to Sherlock.",
5
5
  "main": "sherlock-proxy.cjs.js",
6
6
  "module": "sherlock-proxy.esm.js",
@@ -38,6 +38,6 @@
38
38
  "tslib": "^2.2.0"
39
39
  },
40
40
  "peerDependencies": {
41
- "@politie/sherlock": "3.4.15"
41
+ "@politie/sherlock": "3.4.16"
42
42
  }
43
43
  }
package/proxy.d.ts CHANGED
@@ -126,7 +126,7 @@ export interface DerivableProxyLens<T, V> {
126
126
  get: (targetValue: T) => V;
127
127
  set?: (newValue: V, targetValue: T | undefined) => T;
128
128
  }
129
- export declare type MaybePacked<T> = T | Derivable<T> | DerivableProxy<T>;
129
+ export type MaybePacked<T> = T | Derivable<T> | DerivableProxy<T>;
130
130
  export declare function unwrapProxy<W>(obj: MaybePacked<W>): W | Derivable<W>;
131
131
  /**
132
132
  * Extends an expression with a property access. Automatically uses bracket notation where appropriate and escapes
@@ -51,7 +51,7 @@ var ProxyDescriptor = /** @class */ (function () {
51
51
  }
52
52
  catch (e) {
53
53
  // istanbul ignore next: for debug purposes
54
- throw Object.assign(new Error("error while getting " + (pd.$expression || '$value') + ": " + (sherlock._internal.isError(e) && e.message)), { jse_cause: e });
54
+ throw Object.assign(new Error("error while getting ".concat(pd.$expression || '$value', ": ").concat(sherlock._internal.isError(e) && e.message)), { jse_cause: e });
55
55
  }
56
56
  },
57
57
  set: function (newValue) {
@@ -59,13 +59,13 @@ var ProxyDescriptor = /** @class */ (function () {
59
59
  var atom = pd.$derivable;
60
60
  var expression = pd.$expression;
61
61
  if (!sherlock.isSettableDerivable(atom)) {
62
- throw new Error((expression || '$value') + " is readonly");
62
+ throw new Error("".concat(expression || '$value', " is readonly"));
63
63
  }
64
64
  try {
65
65
  atom.set(newValue);
66
66
  }
67
67
  catch (e) {
68
- throw Object.assign(new Error("error while setting " + (expression || '$value') + ": " + (sherlock._internal.isError(e) && e.message)), { jse_cause: e });
68
+ throw Object.assign(new Error("error while setting ".concat(expression || '$value', ": ").concat(sherlock._internal.isError(e) && e.message)), { jse_cause: e });
69
69
  }
70
70
  },
71
71
  enumerable: false,
@@ -82,7 +82,7 @@ var ProxyDescriptor = /** @class */ (function () {
82
82
  }
83
83
  catch (e) {
84
84
  // istanbul ignore next: for debug purposes
85
- throw Object.assign(new Error("error while getting " + (pd.$expression || '$targetValue') + ": " + (sherlock._internal.isError(e) && e.message)), { jse_cause: e });
85
+ throw Object.assign(new Error("error while getting ".concat(pd.$expression || '$targetValue', ": ").concat(sherlock._internal.isError(e) && e.message)), { jse_cause: e });
86
86
  }
87
87
  },
88
88
  set: function (newValue) {
@@ -90,13 +90,13 @@ var ProxyDescriptor = /** @class */ (function () {
90
90
  var atom = pd.$target;
91
91
  var expression = pd.$expression;
92
92
  if (!sherlock.isSettableDerivable(atom)) {
93
- throw new Error((expression || '$targetValue') + " is readonly");
93
+ throw new Error("".concat(expression || '$targetValue', " is readonly"));
94
94
  }
95
95
  try {
96
96
  atom.set(newValue);
97
97
  }
98
98
  catch (e) {
99
- throw Object.assign(new Error("error while setting " + (expression || '$targetValue') + ": " + (sherlock._internal.isError(e) && e.message)), { jse_cause: e });
99
+ throw Object.assign(new Error("error while setting ".concat(expression || '$targetValue', ": ").concat(sherlock._internal.isError(e) && e.message)), { jse_cause: e });
100
100
  }
101
101
  },
102
102
  enumerable: false,
@@ -193,7 +193,7 @@ var ProxyDescriptor = /** @class */ (function () {
193
193
  length = pd.$length();
194
194
  if (length === undefined) {
195
195
  expression = pd.$expression;
196
- throw Object.assign(new Error((expression || 'object') + " is not iterable"), { value: pd.$value, expression: expression });
196
+ throw Object.assign(new Error("".concat(expression || 'object', " is not iterable")), { value: pd.$value, expression: expression });
197
197
  }
198
198
  i = 0;
199
199
  _a.label = 1;
@@ -1 +1 @@
1
- {"version":3,"file":"sherlock-proxy.cjs.js","sources":["../../extensions/sherlock-proxy/proxy.ts"],"sourcesContent":["import { Derivable, isDerivable, isSettableDerivable, lens, ReactorOptions, utils, _internal } from '@politie/sherlock';\n\n/**\n * The base interface for DerivableProxies. Defines only the $-properties and $-methods. Any property accessed with a number or\n * that doesn't start with a $-sign returns a new DerivableProxy.\n */\nexport interface DerivableProxy<V> {\n /** The current value that this Proxy represents. Can be expensive to calculate and is often writable. */\n $value: V;\n\n /** A string representation of this proxy's path from the root ProxyDescriptor. */\n $expression?: string;\n\n /**\n * An array representation of this proxy's path from the root ProxyDescriptor. Useful for programatically walking down the root\n * Descriptor's object tree to reacquire a target proxy.\n */\n $path?: Array<string | number>;\n\n /** {@see Derivable#and} */\n $and<W>(other: MaybePacked<W>): Derivable<V | W>;\n\n /** {@see Derivable#or} */\n $or<W>(other: MaybePacked<W>): Derivable<V | W>;\n\n /** {@see Derivable#not} */\n $not(): Derivable<boolean>;\n\n /** {@see Derivable#is} */\n $is(other: MaybePacked<any>): Derivable<boolean>;\n\n /** {@see Derivable#derive} */\n $derive<R>(f: (v: V) => R): Derivable<R>;\n $derive<R, P1>(f: (v: V, p1: P1) => R, p1: MaybePacked<P1>): Derivable<R>;\n $derive<R, P1, P2>(f: (v: V, p1: P1, p2: P2) => R, p1: MaybePacked<P1>, p2: MaybePacked<P2>): Derivable<R>;\n $derive<R, P>(f: (v: V, ...ps: P[]) => R, ...ps: Array<MaybePacked<P>>): Derivable<R>;\n\n /** {@see Derivable#react} */\n $react(reaction: (value: V, stop: () => void) => void, options?: Partial<ReactorOptions<V>>): () => void;\n}\n\nconst IS_DERIVABLE_PROXY = Symbol('isDerivableProxy');\n\n/**\n * Returns whether obj is a DerivableProxy.\n *\n * @param obj the object to test\n */\nexport function isDerivableProxy(obj: any): obj is DerivableProxy<any> {\n return obj[IS_DERIVABLE_PROXY] === true;\n}\n\n/**\n * A ProxyDescriptor must be used to create DerivableProxies. It can be used in two ways, either create a new descriptor and\n * change any implementation details (if needed) or create a subclass to extend the behavior. Use the {@link #$create} method\n * to create a DerivableProxy.\n *\n * Note that `this` in methods points to the created proxy, so only methods and properties that start with a $-sign can be accessed\n * without trouble.\n *\n * Note also that properties that start with two $-signs are cleared on $create.\n */\nexport class ProxyDescriptor<V = any, T = V> {\n /**\n * The target derivable (the input to the proxy and the {@link #$create} method). The actual values that can be seen by methods\n * on the Proxy can be influenced by providing a {@link #$lens}.\n */\n $target!: Derivable<T>;\n\n /**\n * The expression that represents the path to the current Proxy.\n */\n $expression?: string;\n\n /**\n * The path to the current Proxy.\n */\n $path?: Array<string | number>;\n\n /**\n * The derivable that is the input to all default methods on the Proxy and the {@link #$value} property.\n */\n get $derivable(): Derivable<V> {\n const pd = this.$proxyDescriptor;\n return pd.$$derivable || (pd.$$derivable = createDerivable(pd.$target, pd.$lens && pd.$lens()));\n }\n private $$derivable?: Derivable<V> = undefined;\n\n /**\n * The current value of the DerivableProxy. Can be expensive to calculate. When the target is settable (is an Atom) then $value\n * is writable.\n */\n get $value() {\n const pd = this.$proxyDescriptor;\n try {\n return pd.$derivable.get();\n } catch (e) {\n // istanbul ignore next: for debug purposes\n throw Object.assign(new Error(`error while getting ${pd.$expression || '$value'}: ${_internal.isError(e) && e.message}`), { jse_cause: e });\n }\n }\n set $value(newValue) {\n const pd = this.$proxyDescriptor;\n const atom = pd.$derivable;\n const expression = pd.$expression;\n if (!isSettableDerivable(atom)) {\n throw new Error(`${expression || '$value'} is readonly`);\n }\n try {\n atom.set(newValue);\n } catch (e) {\n throw Object.assign(new Error(`error while setting ${expression || '$value'}: ${_internal.isError(e) && e.message}`), { jse_cause: e });\n }\n }\n\n /**\n * The current value of the target Derivable that was used to create the DerivableProxy.\n */\n get $targetValue() {\n const pd = this.$proxyDescriptor;\n try {\n return pd.$target.get();\n } catch (e) {\n // istanbul ignore next: for debug purposes\n throw Object.assign(\n new Error(`error while getting ${pd.$expression || '$targetValue'}: ${_internal.isError(e) && e.message}`),\n { jse_cause: e },\n );\n }\n }\n set $targetValue(newValue) {\n const pd = this.$proxyDescriptor;\n const atom = pd.$target;\n const expression = pd.$expression;\n if (!isSettableDerivable(atom)) {\n throw new Error(`${expression || '$targetValue'} is readonly`);\n }\n try {\n atom.set(newValue);\n } catch (e) {\n throw Object.assign(new Error(`error while setting ${expression || '$targetValue'}: ${_internal.isError(e) && e.message}`), { jse_cause: e });\n }\n }\n\n /**\n * In methods of a ProxyDescriptor, `this` is bound to the Proxy Object. Therefore, only $-properties and $-methods can be\n * accessed safely. Use $proxyDescriptor to get access to the ProxyDescriptor Object to prevent the ProxyHandler from messing\n * with your logic.\n */\n protected get $proxyDescriptor() { return this; }\n\n /**\n * An optional method that can return an optional lens to this proxy. Is used to transform the values before accessed by the\n * consumer of the Proxy (either through $value or one of the other methods).\n */\n $lens?(): DerivableProxyLens<T, V> | undefined;\n\n /**\n * Wrap a Derivable as DerivableProxy using this ProxyDescriptor.\n *\n * @param obj the object to wrap\n * @param expression the new expression to the created DerivableProxy\n * @param path the new path to the created DerivableProxy\n */\n $create(obj: Derivable<T>, expression?: string, path?: Array<string | number>): DerivableProxy<V> {\n const descriptor: ProxyDescriptor = utils.clone(this.$proxyDescriptor);\n descriptor.$target = obj;\n Object.getOwnPropertyNames(descriptor)\n .filter(prop => prop.startsWith('$$'))\n .forEach(prop => descriptor[prop] = undefined);\n descriptor.$expression = expression;\n descriptor.$path = path;\n return new Proxy(descriptor, proxyHandler) as any;\n }\n\n /**\n * The $pluck method is the implementation of the pluck mechanism of DerivableProxy. Replace this method to change the\n * pluck behavior. It should return a DerivableProxy.\n *\n * @param prop the property to pluck of the wrapped derivable\n */\n $pluck(prop: string | number): DerivableProxy<V> {\n const pd = this.$proxyDescriptor;\n return pd.$create(pd.$derivable.pluck(prop), extendExpression(pd.$expression, prop), extendPath(pd.$path, prop));\n }\n\n /**\n * The $pluckableKeys returns a list of properties that can be plucked from this object. Returned keys are guaranteed to\n * result in a usable DerivableProxy when used with $pluck. Is used for `for ... in` and `Object.keys(...)` logic.\n */\n $pluckableKeys() {\n const value = this.$proxyDescriptor.$value;\n return typeof value === 'object' ? Reflect.ownKeys(value as any) : [];\n }\n\n /**\n * Method that determines whether the current object is iterable and if so, how many elements it contains. During iteration\n * {@link #pluck} is called with indices up to but not including the result of `$length()`.\n */\n $length(): number | undefined {\n const maybeArray = this.$proxyDescriptor.$targetValue;\n return Array.isArray(maybeArray) ? maybeArray.length : undefined;\n }\n\n $and(other: MaybePacked<any>) {\n return this.$proxyDescriptor.$derivable.and(unwrapProxy(other));\n }\n\n $or(other: MaybePacked<any>) {\n return this.$proxyDescriptor.$derivable.or(unwrapProxy(other));\n }\n\n $not() {\n return this.$proxyDescriptor.$derivable.not();\n }\n\n $is(other: MaybePacked<any>) {\n return this.$proxyDescriptor.$derivable.is(unwrapProxy(other));\n }\n\n $derive() {\n const target = this.$proxyDescriptor.$derivable;\n return target.derive.apply(target, arguments as any);\n }\n\n $react(reaction: (value: V, stop: () => void) => void, options?: Partial<ReactorOptions<any>>): () => void {\n return this.$proxyDescriptor.$derivable.react(reaction, options);\n }\n\n toJSON() {\n return this.$proxyDescriptor.$value;\n }\n\n get [Symbol.toStringTag]() {\n return 'DerivableProxy';\n }\n\n *[Symbol.iterator](): IterableIterator<DerivableProxy<V>> {\n const pd = this.$proxyDescriptor;\n const length = pd.$length();\n if (length === undefined) {\n const expression = pd.$expression;\n throw Object.assign(new Error(`${expression || 'object'} is not iterable`), { value: pd.$value, expression });\n }\n for (let i = 0; i < length; i++) {\n yield pd.$pluck(i)!;\n }\n }\n\n get length() {\n return this.$proxyDescriptor.$length();\n }\n}\nProxyDescriptor.prototype[IS_DERIVABLE_PROXY] = true;\n\nfunction createDerivable<V, T>(target: Derivable<T>, proxyLens?: DerivableProxyLens<T, V>): Derivable<V> {\n if (!proxyLens) {\n return target as any;\n }\n const { get, set } = proxyLens;\n if (!set || !isSettableDerivable(target)) {\n return target.derive(get).autoCache();\n }\n return lens({\n get,\n set(newValue, targetValue) {\n target.set(set.call(this, newValue, targetValue));\n }\n }, target).autoCache();\n}\n\nexport interface DerivableProxyLens<T, V> {\n get: (targetValue: T) => V;\n set?: (newValue: V, targetValue: T | undefined) => T;\n}\n\nexport type MaybePacked<T> = T | Derivable<T> | DerivableProxy<T>;\n\nexport function unwrapProxy<W>(obj: MaybePacked<W>): W | Derivable<W> {\n if (isDerivableProxy(obj)) {\n return (obj as any).$derivable;\n }\n return obj;\n}\n\nconst proxyHandler: ProxyHandler<ProxyDescriptor> = {\n get(target, prop, receiver) {\n if (prop === '$proxyDescriptor') {\n return target;\n }\n if (isPluckableProperty(target, prop)) {\n return target.$pluck.call(receiver, prop as string | number);\n }\n return Reflect.get(target, prop, receiver);\n },\n set(target, prop, newValue, receiver) {\n if (isPluckableProperty(target, prop)) {\n const plucked = target.$pluck.call(receiver, prop as string | number) as ProxyDescriptor;\n if (newValue && isDerivableProxy(newValue)) {\n plucked.$targetValue = (newValue as any).$targetValue;\n } else {\n plucked.$value = newValue && isDerivable(newValue) ? newValue.get() : newValue;\n }\n return true;\n }\n return Reflect.set(target, prop, newValue, receiver);\n },\n has(target, prop) {\n if (prop === Symbol.iterator) {\n return target.$length() !== undefined;\n }\n return isPluckableProperty(target, prop);\n },\n getOwnPropertyDescriptor(target, prop) {\n if (isPluckableProperty(target, prop)) {\n return {\n get() { return this[prop]; },\n set(newValue) { this[prop] = newValue; },\n configurable: true,\n enumerable: true,\n };\n }\n return undefined;\n },\n ownKeys(target) {\n return target.$pluckableKeys();\n },\n};\n\nfunction isPluckableProperty(target: ProxyDescriptor, prop: PropertyKey) {\n return typeof prop === 'number' || typeof prop === 'string' && prop[0] !== '$' && !Reflect.has(target, prop);\n}\n\n/**\n * Extends an expression with a property access. Automatically uses bracket notation where appropriate and escapes\n * strings in brackets to give a realistic combined expression.\n *\n * @param expression the (optional) expression to extend\n * @param property the property that should be appended to the expression\n */\nexport function extendExpression(expression = '', property: string | number) {\n if (typeof property === 'string' && /^[a-z_][a-z_0-9]*$/i.test(property)) {\n return expression + '.' + property;\n }\n if (typeof property === 'string') {\n return expression + '[\"' + property.replace(/\\\\/g, '\\\\\\\\').replace(/\\\"/g, '\\\\\"') + '\"]';\n }\n return expression + '[' + property + ']';\n}\n\n/**\n * Extends a path with a property access.\n *\n * @param path the (optional) path to extend\n * @param property the property that should be appended to the path\n */\nexport function extendPath(path: Array<string | number> = [], property: string | number) {\n return path.concat(property);\n}\n"],"names":["_internal","isSettableDerivable","utils","lens","isDerivable"],"mappings":";;;;;;;AAyCA,IAAM,kBAAkB,GAAG,MAAM,CAAC,kBAAkB,CAAC,CAAC;AAEtD;;;;;SAKgB,gBAAgB,CAAC,GAAQ;IACrC,OAAO,GAAG,CAAC,kBAAkB,CAAC,KAAK,IAAI,CAAC;AAC5C,CAAC;AAED;;;;;;;;;;;IAUA;QAwBY,gBAAW,GAAkB,SAAS,CAAC;KAsKlD;IA1KG,sBAAI,uCAAU;;;;aAAd;YACI,IAAM,EAAE,GAAG,IAAI,CAAC,gBAAgB,CAAC;YACjC,OAAO,EAAE,CAAC,WAAW,KAAK,EAAE,CAAC,WAAW,GAAG,eAAe,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,KAAK,IAAI,EAAE,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;SACnG;;;OAAA;IAOD,sBAAI,mCAAM;;;;;aAAV;YACI,IAAM,EAAE,GAAG,IAAI,CAAC,gBAAgB,CAAC;YACjC,IAAI;gBACA,OAAO,EAAE,CAAC,UAAU,CAAC,GAAG,EAAE,CAAC;aAC9B;YAAC,OAAO,CAAC,EAAE;;gBAER,MAAM,MAAM,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,0BAAuB,EAAE,CAAC,WAAW,IAAI,QAAQ,YAAKA,kBAAS,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,OAAO,CAAE,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UAAe,EAAE,QAAyB;IAA1C,2BAAA,EAAA,eAAe;IAC5C,IAAI,OAAO,QAAQ,KAAK,QAAQ,IAAI,qBAAqB,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE;QACtE,OAAO,UAAU,GAAG,GAAG,GAAG,QAAQ,CAAC;KACtC;IACD,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE;QAC9B,OAAO,UAAU,GAAG,IAAI,GAAG,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,IAAI,CAAC;KAC3F;IACD,OAAO,UAAU,GAAG,GAAG,GAAG,QAAQ,GAAG,GAAG,CAAC;AAC7C,CAAC;AAED;;;;;;SAMgB,UAAU,CAAC,IAAiC,EAAE,QAAyB;IAA5D,qBAAA,EAAA,SAAiC;IACxD,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;AACjC;;;;;;;;"}
1
+ {"version":3,"file":"sherlock-proxy.cjs.js","sources":["../../extensions/sherlock-proxy/proxy.ts"],"sourcesContent":["import { Derivable, isDerivable, isSettableDerivable, lens, ReactorOptions, utils, _internal } from '@politie/sherlock';\n\n/**\n * The base interface for DerivableProxies. Defines only the $-properties and $-methods. Any property accessed with a number or\n * that doesn't start with a $-sign returns a new DerivableProxy.\n */\nexport interface DerivableProxy<V> {\n /** The current value that this Proxy represents. Can be expensive to calculate and is often writable. */\n $value: V;\n\n /** A string representation of this proxy's path from the root ProxyDescriptor. */\n $expression?: string;\n\n /**\n * An array representation of this proxy's path from the root ProxyDescriptor. Useful for programatically walking down the root\n * Descriptor's object tree to reacquire a target proxy.\n */\n $path?: Array<string | number>;\n\n /** {@see Derivable#and} */\n $and<W>(other: MaybePacked<W>): Derivable<V | W>;\n\n /** {@see Derivable#or} */\n $or<W>(other: MaybePacked<W>): Derivable<V | W>;\n\n /** {@see Derivable#not} */\n $not(): Derivable<boolean>;\n\n /** {@see Derivable#is} */\n $is(other: MaybePacked<any>): Derivable<boolean>;\n\n /** {@see Derivable#derive} */\n $derive<R>(f: (v: V) => R): Derivable<R>;\n $derive<R, P1>(f: (v: V, p1: P1) => R, p1: MaybePacked<P1>): Derivable<R>;\n $derive<R, P1, P2>(f: (v: V, p1: P1, p2: P2) => R, p1: MaybePacked<P1>, p2: MaybePacked<P2>): Derivable<R>;\n $derive<R, P>(f: (v: V, ...ps: P[]) => R, ...ps: Array<MaybePacked<P>>): Derivable<R>;\n\n /** {@see Derivable#react} */\n $react(reaction: (value: V, stop: () => void) => void, options?: Partial<ReactorOptions<V>>): () => void;\n}\n\nconst IS_DERIVABLE_PROXY = Symbol('isDerivableProxy');\n\n/**\n * Returns whether obj is a DerivableProxy.\n *\n * @param obj the object to test\n */\nexport function isDerivableProxy(obj: any): obj is DerivableProxy<any> {\n return obj[IS_DERIVABLE_PROXY] === true;\n}\n\n/**\n * A ProxyDescriptor must be used to create DerivableProxies. It can be used in two ways, either create a new descriptor and\n * change any implementation details (if needed) or create a subclass to extend the behavior. Use the {@link #$create} method\n * to create a DerivableProxy.\n *\n * Note that `this` in methods points to the created proxy, so only methods and properties that start with a $-sign can be accessed\n * without trouble.\n *\n * Note also that properties that start with two $-signs are cleared on $create.\n */\nexport class ProxyDescriptor<V = any, T = V> {\n /**\n * The target derivable (the input to the proxy and the {@link #$create} method). The actual values that can be seen by methods\n * on the Proxy can be influenced by providing a {@link #$lens}.\n */\n $target!: Derivable<T>;\n\n /**\n * The expression that represents the path to the current Proxy.\n */\n $expression?: string;\n\n /**\n * The path to the current Proxy.\n */\n $path?: Array<string | number>;\n\n /**\n * The derivable that is the input to all default methods on the Proxy and the {@link #$value} property.\n */\n get $derivable(): Derivable<V> {\n const pd = this.$proxyDescriptor;\n return pd.$$derivable || (pd.$$derivable = createDerivable(pd.$target, pd.$lens && pd.$lens()));\n }\n private $$derivable?: Derivable<V> = undefined;\n\n /**\n * The current value of the DerivableProxy. Can be expensive to calculate. When the target is settable (is an Atom) then $value\n * is writable.\n */\n get $value() {\n const pd = this.$proxyDescriptor;\n try {\n return pd.$derivable.get();\n } catch (e) {\n // istanbul ignore next: for debug purposes\n throw Object.assign(new Error(`error while getting ${pd.$expression || '$value'}: ${_internal.isError(e) && e.message}`), { jse_cause: e });\n }\n }\n set $value(newValue) {\n const pd = this.$proxyDescriptor;\n const atom = pd.$derivable;\n const expression = pd.$expression;\n if (!isSettableDerivable(atom)) {\n throw new Error(`${expression || '$value'} is readonly`);\n }\n try {\n atom.set(newValue);\n } catch (e) {\n throw Object.assign(new Error(`error while setting ${expression || '$value'}: ${_internal.isError(e) && e.message}`), { jse_cause: e });\n }\n }\n\n /**\n * The current value of the target Derivable that was used to create the DerivableProxy.\n */\n get $targetValue() {\n const pd = this.$proxyDescriptor;\n try {\n return pd.$target.get();\n } catch (e) {\n // istanbul ignore next: for debug purposes\n throw Object.assign(\n new Error(`error while getting ${pd.$expression || '$targetValue'}: ${_internal.isError(e) && e.message}`),\n { jse_cause: e },\n );\n }\n }\n set $targetValue(newValue) {\n const pd = this.$proxyDescriptor;\n const atom = pd.$target;\n const expression = pd.$expression;\n if (!isSettableDerivable(atom)) {\n throw new Error(`${expression || '$targetValue'} is readonly`);\n }\n try {\n atom.set(newValue);\n } catch (e) {\n throw Object.assign(new Error(`error while setting ${expression || '$targetValue'}: ${_internal.isError(e) && e.message}`), { jse_cause: e });\n }\n }\n\n /**\n * In methods of a ProxyDescriptor, `this` is bound to the Proxy Object. Therefore, only $-properties and $-methods can be\n * accessed safely. Use $proxyDescriptor to get access to the ProxyDescriptor Object to prevent the ProxyHandler from messing\n * with your logic.\n */\n protected get $proxyDescriptor() { return this; }\n\n /**\n * An optional method that can return an optional lens to this proxy. Is used to transform the values before accessed by the\n * consumer of the Proxy (either through $value or one of the other methods).\n */\n $lens?(): DerivableProxyLens<T, V> | undefined;\n\n /**\n * Wrap a Derivable as DerivableProxy using this ProxyDescriptor.\n *\n * @param obj the object to wrap\n * @param expression the new expression to the created DerivableProxy\n * @param path the new path to the created DerivableProxy\n */\n $create(obj: Derivable<T>, expression?: string, path?: Array<string | number>): DerivableProxy<V> {\n const descriptor: ProxyDescriptor = utils.clone(this.$proxyDescriptor);\n descriptor.$target = obj;\n Object.getOwnPropertyNames(descriptor)\n .filter(prop => prop.startsWith('$$'))\n .forEach(prop => descriptor[prop] = undefined);\n descriptor.$expression = expression;\n descriptor.$path = path;\n return new Proxy(descriptor, proxyHandler) as any;\n }\n\n /**\n * The $pluck method is the implementation of the pluck mechanism of DerivableProxy. Replace this method to change the\n * pluck behavior. It should return a DerivableProxy.\n *\n * @param prop the property to pluck of the wrapped derivable\n */\n $pluck(prop: string | number): DerivableProxy<V> {\n const pd = this.$proxyDescriptor;\n return pd.$create(pd.$derivable.pluck(prop), extendExpression(pd.$expression, prop), extendPath(pd.$path, prop));\n }\n\n /**\n * The $pluckableKeys returns a list of properties that can be plucked from this object. Returned keys are guaranteed to\n * result in a usable DerivableProxy when used with $pluck. Is used for `for ... in` and `Object.keys(...)` logic.\n */\n $pluckableKeys() {\n const value = this.$proxyDescriptor.$value;\n return typeof value === 'object' ? Reflect.ownKeys(value as any) : [];\n }\n\n /**\n * Method that determines whether the current object is iterable and if so, how many elements it contains. During iteration\n * {@link #pluck} is called with indices up to but not including the result of `$length()`.\n */\n $length(): number | undefined {\n const maybeArray = this.$proxyDescriptor.$targetValue;\n return Array.isArray(maybeArray) ? maybeArray.length : undefined;\n }\n\n $and(other: MaybePacked<any>) {\n return this.$proxyDescriptor.$derivable.and(unwrapProxy(other));\n }\n\n $or(other: MaybePacked<any>) {\n return this.$proxyDescriptor.$derivable.or(unwrapProxy(other));\n }\n\n $not() {\n return this.$proxyDescriptor.$derivable.not();\n }\n\n $is(other: MaybePacked<any>) {\n return this.$proxyDescriptor.$derivable.is(unwrapProxy(other));\n }\n\n $derive() {\n const target = this.$proxyDescriptor.$derivable;\n return target.derive.apply(target, arguments as any);\n }\n\n $react(reaction: (value: V, stop: () => void) => void, options?: Partial<ReactorOptions<any>>): () => void {\n return this.$proxyDescriptor.$derivable.react(reaction, options);\n }\n\n toJSON() {\n return this.$proxyDescriptor.$value;\n }\n\n get [Symbol.toStringTag]() {\n return 'DerivableProxy';\n }\n\n *[Symbol.iterator](): IterableIterator<DerivableProxy<V>> {\n const pd = this.$proxyDescriptor;\n const length = pd.$length();\n if (length === undefined) {\n const expression = pd.$expression;\n throw Object.assign(new Error(`${expression || 'object'} is not iterable`), { value: pd.$value, expression });\n }\n for (let i = 0; i < length; i++) {\n yield pd.$pluck(i)!;\n }\n }\n\n get length() {\n return this.$proxyDescriptor.$length();\n }\n}\nProxyDescriptor.prototype[IS_DERIVABLE_PROXY] = true;\n\nfunction createDerivable<V, T>(target: Derivable<T>, proxyLens?: DerivableProxyLens<T, V>): Derivable<V> {\n if (!proxyLens) {\n return target as any;\n }\n const { get, set } = proxyLens;\n if (!set || !isSettableDerivable(target)) {\n return target.derive(get).autoCache();\n }\n return lens({\n get,\n set(newValue, targetValue) {\n target.set(set.call(this, newValue, targetValue));\n }\n }, target).autoCache();\n}\n\nexport interface DerivableProxyLens<T, V> {\n get: (targetValue: T) => V;\n set?: (newValue: V, targetValue: T | undefined) => T;\n}\n\nexport type MaybePacked<T> = T | Derivable<T> | DerivableProxy<T>;\n\nexport function unwrapProxy<W>(obj: MaybePacked<W>): W | Derivable<W> {\n if (isDerivableProxy(obj)) {\n return (obj as any).$derivable;\n }\n return obj;\n}\n\nconst proxyHandler: ProxyHandler<ProxyDescriptor> = {\n get(target, prop, receiver) {\n if (prop === '$proxyDescriptor') {\n return target;\n }\n if (isPluckableProperty(target, prop)) {\n return target.$pluck.call(receiver, prop as string | number);\n }\n return Reflect.get(target, prop, receiver);\n },\n set(target, prop, newValue, receiver) {\n if (isPluckableProperty(target, prop)) {\n const plucked = target.$pluck.call(receiver, prop as string | number) as ProxyDescriptor;\n if (newValue && isDerivableProxy(newValue)) {\n plucked.$targetValue = (newValue as any).$targetValue;\n } else {\n plucked.$value = newValue && isDerivable(newValue) ? newValue.get() : newValue;\n }\n return true;\n }\n return Reflect.set(target, prop, newValue, receiver);\n },\n has(target, prop) {\n if (prop === Symbol.iterator) {\n return target.$length() !== undefined;\n }\n return isPluckableProperty(target, prop);\n },\n getOwnPropertyDescriptor(target, prop) {\n if (isPluckableProperty(target, prop)) {\n return {\n get() { return this[prop]; },\n set(newValue) { this[prop] = newValue; },\n configurable: true,\n enumerable: true,\n };\n }\n return undefined;\n },\n ownKeys(target) {\n return target.$pluckableKeys();\n },\n};\n\nfunction isPluckableProperty(target: ProxyDescriptor, prop: PropertyKey) {\n return typeof prop === 'number' || typeof prop === 'string' && prop[0] !== '$' && !Reflect.has(target, prop);\n}\n\n/**\n * Extends an expression with a property access. Automatically uses bracket notation where appropriate and escapes\n * strings in brackets to give a realistic combined expression.\n *\n * @param expression the (optional) expression to extend\n * @param property the property that should be appended to the expression\n */\nexport function extendExpression(expression = '', property: string | number) {\n if (typeof property === 'string' && /^[a-z_][a-z_0-9]*$/i.test(property)) {\n return expression + '.' + property;\n }\n if (typeof property === 'string') {\n return expression + '[\"' + property.replace(/\\\\/g, '\\\\\\\\').replace(/\\\"/g, '\\\\\"') + '\"]';\n }\n return expression + '[' + property + ']';\n}\n\n/**\n * Extends a path with a property access.\n *\n * @param path the (optional) path to extend\n * @param property the property that should be appended to the path\n */\nexport function extendPath(path: Array<string | number> = [], property: string | number) {\n return path.concat(property);\n}\n"],"names":["_internal","isSettableDerivable","utils","lens","isDerivable"],"mappings":";;;;;;;AAyCA,IAAM,kBAAkB,GAAG,MAAM,CAAC,kBAAkB,CAAC,CAAC;AAEtD;;;;AAIG;AACG,SAAU,gBAAgB,CAAC,GAAQ,EAAA;AACrC,IAAA,OAAO,GAAG,CAAC,kBAAkB,CAAC,KAAK,IAAI,CAAC;AAC5C,CAAC;AAED;;;;;;;;;AASG;AACH,IAAA,eAAA,kBAAA,YAAA;AAAA,IAAA,SAAA,eAAA,GAAA;QAwBY,IAAW,CAAA,WA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("tslib"),t=require("@politie/sherlock"),e=Symbol("isDerivableProxy");function n(r){return!0===r[e]}var i=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,e){if(!e)return r;var n=e.get,i=e.set;return i&&t.isSettableDerivable(r)?t.lens({get:n,set:function(t,e){r.set(i.call(this,t,e))}},r).autoCache():r.derive(n).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(e){throw Object.assign(Error("error while getting "+(r.$expression||"$value")+": "+(t._internal.isError(e)&&e.message)),{jse_cause:e})}},set:function(r){var e=this.$proxyDescriptor,n=e.$derivable,i=e.$expression;if(!t.isSettableDerivable(n))throw Error((i||"$value")+" is readonly");try{n.set(r)}catch(r){throw Object.assign(Error("error while setting "+(i||"$value")+": "+(t._internal.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(e){throw Object.assign(Error("error while getting "+(r.$expression||"$targetValue")+": "+(t._internal.isError(e)&&e.message)),{jse_cause:e})}},set:function(r){var e=this.$proxyDescriptor,n=e.$target,i=e.$expression;if(!t.isSettableDerivable(n))throw Error((i||"$targetValue")+" is readonly");try{n.set(r)}catch(r){throw Object.assign(Error("error while setting "+(i||"$targetValue")+": "+(t._internal.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.utils.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,o)},e.prototype.$pluck=function(r){var t=this.$proxyDescriptor;return t.$create(t.$derivable.pluck(r),s(t.$expression,r),a(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(u(r))},e.prototype.$or=function(r){return this.$proxyDescriptor.$derivable.or(u(r))},e.prototype.$not=function(){return this.$proxyDescriptor.$derivable.not()},e.prototype.$is=function(r){return this.$proxyDescriptor.$derivable.is(u(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.__generator(this,(function(r){switch(r.label){case 0:if(t=this.$proxyDescriptor,void 0===(e=t.$length()))throw n=t.$expression,Object.assign(Error((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 u(r){return n(r)?r.$derivable:r}i.prototype[e]=!0;var o={get:function(r,t,e){return"$proxyDescriptor"===t?r:c(r,t)?r.$pluck.call(e,t):Reflect.get(r,t,e)},set:function(r,e,i,u){if(c(r,e)){var o=r.$pluck.call(u,e);return i&&n(i)?o.$targetValue=i.$targetValue:o.$value=i&&t.isDerivable(i)?i.get():i,!0}return Reflect.set(r,e,i,u)},has:function(r,t){return t===Symbol.iterator?void 0!==r.$length():c(r,t)},getOwnPropertyDescriptor:function(r,t){if(c(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 c(r,t){return"number"==typeof t||"string"==typeof t&&"$"!==t[0]&&!Reflect.has(r,t)}function s(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 a(r,t){return void 0===r&&(r=[]),r.concat(t)}exports.ProxyDescriptor=i,exports.extendExpression=s,exports.extendPath=a,exports.isDerivableProxy=n,exports.unwrapProxy=u;
1
+ Object.defineProperty(exports,"__esModule",{value:!0});var r=require("tslib"),t=require("@politie/sherlock"),e=Symbol("isDerivableProxy");function n(r){return!0===r[e]}var i=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,e){if(!e)return r;var n=e.get,i=e.set;return i&&t.isSettableDerivable(r)?t.lens({get:n,set:function(t,e){r.set(i.call(this,t,e))}},r).autoCache():r.derive(n).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(e){throw Object.assign(Error("error while getting ".concat(r.$expression||"$value",": ").concat(t._internal.isError(e)&&e.message)),{jse_cause:e})}},set:function(r){var e=this.$proxyDescriptor,n=e.$derivable,i=e.$expression;if(!t.isSettableDerivable(n))throw Error("".concat(i||"$value"," is readonly"));try{n.set(r)}catch(r){throw Object.assign(Error("error while setting ".concat(i||"$value",": ").concat(t._internal.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(e){throw Object.assign(Error("error while getting ".concat(r.$expression||"$targetValue",": ").concat(t._internal.isError(e)&&e.message)),{jse_cause:e})}},set:function(r){var e=this.$proxyDescriptor,n=e.$target,i=e.$expression;if(!t.isSettableDerivable(n))throw Error("".concat(i||"$targetValue"," is readonly"));try{n.set(r)}catch(r){throw Object.assign(Error("error while setting ".concat(i||"$targetValue",": ").concat(t._internal.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.utils.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,o)},e.prototype.$pluck=function(r){var t=this.$proxyDescriptor;return t.$create(t.$derivable.pluck(r),s(t.$expression,r),a(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(u(r))},e.prototype.$or=function(r){return this.$proxyDescriptor.$derivable.or(u(r))},e.prototype.$not=function(){return this.$proxyDescriptor.$derivable.not()},e.prototype.$is=function(r){return this.$proxyDescriptor.$derivable.is(u(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.__generator(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 u(r){return n(r)?r.$derivable:r}i.prototype[e]=!0;var o={get:function(r,t,e){return"$proxyDescriptor"===t?r:c(r,t)?r.$pluck.call(e,t):Reflect.get(r,t,e)},set:function(r,e,i,u){if(c(r,e)){var o=r.$pluck.call(u,e);return i&&n(i)?o.$targetValue=i.$targetValue:o.$value=i&&t.isDerivable(i)?i.get():i,!0}return Reflect.set(r,e,i,u)},has:function(r,t){return t===Symbol.iterator?void 0!==r.$length():c(r,t)},getOwnPropertyDescriptor:function(r,t){if(c(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 c(r,t){return"number"==typeof t||"string"==typeof t&&"$"!==t[0]&&!Reflect.has(r,t)}function s(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 a(r,t){return void 0===r&&(r=[]),r.concat(t)}exports.ProxyDescriptor=i,exports.extendExpression=s,exports.extendPath=a,exports.isDerivableProxy=n,exports.unwrapProxy=u;
2
2
  //# sourceMappingURL=sherlock-proxy.cjs.min.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"sherlock-proxy.cjs.min.js","names":["IS_DERIVABLE_PROXY","Symbol","isDerivableProxy","obj","ProxyDescriptor","this","$$derivable","undefined","Object","defineProperty","prototype","pd","$proxyDescriptor","target","proxyLens","get","set","isSettableDerivable","lens","newValue","targetValue","call","autoCache","derive","createDerivable","$target","$lens","$derivable","e","assign","Error","$expression","_internal","isError","message","jse_cause","atom","expression","$create","path","descriptor","utils","clone","getOwnPropertyNames","filter","prop","startsWith","forEach","$path","Proxy","proxyHandler","$pluck","pluck","extendExpression","extendPath","$pluckableKeys","value","$value","Reflect","ownKeys","$length","maybeArray","$targetValue","Array","isArray","length","$and","other","and","unwrapProxy","$or","or","$not","not","$is","is","$derive","apply","arguments","$react","reaction","options","react","toJSON","toStringTag","iterator","i","_a","sent","receiver","isPluckableProperty","plucked","isDerivable","has","getOwnPropertyDescriptor","configurable","enumerable","property","test","replace","concat"],"sources":["../../extensions/sherlock-proxy/proxy.ts"],"sourcesContent":["import { Derivable, isDerivable, isSettableDerivable, lens, ReactorOptions, utils, _internal } from '@politie/sherlock';\n\n/**\n * The base interface for DerivableProxies. Defines only the $-properties and $-methods. Any property accessed with a number or\n * that doesn't start with a $-sign returns a new DerivableProxy.\n */\nexport interface DerivableProxy<V> {\n /** The current value that this Proxy represents. Can be expensive to calculate and is often writable. */\n $value: V;\n\n /** A string representation of this proxy's path from the root ProxyDescriptor. */\n $expression?: string;\n\n /**\n * An array representation of this proxy's path from the root ProxyDescriptor. Useful for programatically walking down the root\n * Descriptor's object tree to reacquire a target proxy.\n */\n $path?: Array<string | number>;\n\n /** {@see Derivable#and} */\n $and<W>(other: MaybePacked<W>): Derivable<V | W>;\n\n /** {@see Derivable#or} */\n $or<W>(other: MaybePacked<W>): Derivable<V | W>;\n\n /** {@see Derivable#not} */\n $not(): Derivable<boolean>;\n\n /** {@see Derivable#is} */\n $is(other: MaybePacked<any>): Derivable<boolean>;\n\n /** {@see Derivable#derive} */\n $derive<R>(f: (v: V) => R): Derivable<R>;\n $derive<R, P1>(f: (v: V, p1: P1) => R, p1: MaybePacked<P1>): Derivable<R>;\n $derive<R, P1, P2>(f: (v: V, p1: P1, p2: P2) => R, p1: MaybePacked<P1>, p2: MaybePacked<P2>): Derivable<R>;\n $derive<R, P>(f: (v: V, ...ps: P[]) => R, ...ps: Array<MaybePacked<P>>): Derivable<R>;\n\n /** {@see Derivable#react} */\n $react(reaction: (value: V, stop: () => void) => void, options?: Partial<ReactorOptions<V>>): () => void;\n}\n\nconst IS_DERIVABLE_PROXY = Symbol('isDerivableProxy');\n\n/**\n * Returns whether obj is a DerivableProxy.\n *\n * @param obj the object to test\n */\nexport function isDerivableProxy(obj: any): obj is DerivableProxy<any> {\n return obj[IS_DERIVABLE_PROXY] === true;\n}\n\n/**\n * A ProxyDescriptor must be used to create DerivableProxies. It can be used in two ways, either create a new descriptor and\n * change any implementation details (if needed) or create a subclass to extend the behavior. Use the {@link #$create} method\n * to create a DerivableProxy.\n *\n * Note that `this` in methods points to the created proxy, so only methods and properties that start with a $-sign can be accessed\n * without trouble.\n *\n * Note also that properties that start with two $-signs are cleared on $create.\n */\nexport class ProxyDescriptor<V = any, T = V> {\n /**\n * The target derivable (the input to the proxy and the {@link #$create} method). The actual values that can be seen by methods\n * on the Proxy can be influenced by providing a {@link #$lens}.\n */\n $target!: Derivable<T>;\n\n /**\n * The expression that represents the path to the current Proxy.\n */\n $expression?: string;\n\n /**\n * The path to the current Proxy.\n */\n $path?: Array<string | number>;\n\n /**\n * The derivable that is the input to all default methods on the Proxy and the {@link #$value} property.\n */\n get $derivable(): Derivable<V> {\n const pd = this.$proxyDescriptor;\n return pd.$$derivable || (pd.$$derivable = createDerivable(pd.$target, pd.$lens && pd.$lens()));\n }\n private $$derivable?: Derivable<V> = undefined;\n\n /**\n * The current value of the DerivableProxy. Can be expensive to calculate. When the target is settable (is an Atom) then $value\n * is writable.\n */\n get $value() {\n const pd = this.$proxyDescriptor;\n try {\n return pd.$derivable.get();\n } catch (e) {\n // istanbul ignore next: for debug purposes\n throw Object.assign(new Error(`error while getting ${pd.$expression || '$value'}: ${_internal.isError(e) && e.message}`), { jse_cause: e });\n }\n }\n set $value(newValue) {\n const pd = this.$proxyDescriptor;\n const atom = pd.$derivable;\n const expression = pd.$expression;\n if (!isSettableDerivable(atom)) {\n throw new Error(`${expression || '$value'} is readonly`);\n }\n try {\n atom.set(newValue);\n } catch (e) {\n throw Object.assign(new Error(`error while setting ${expression || '$value'}: ${_internal.isError(e) && e.message}`), { jse_cause: e });\n }\n }\n\n /**\n * The current value of the target Derivable that was used to create the DerivableProxy.\n */\n get $targetValue() {\n const pd = this.$proxyDescriptor;\n try {\n return pd.$target.get();\n } catch (e) {\n // istanbul ignore next: for debug purposes\n throw Object.assign(\n new Error(`error while getting ${pd.$expression || '$targetValue'}: ${_internal.isError(e) && e.message}`),\n { jse_cause: e },\n );\n }\n }\n set $targetValue(newValue) {\n const pd = this.$proxyDescriptor;\n const atom = pd.$target;\n const expression = pd.$expression;\n if (!isSettableDerivable(atom)) {\n throw new Error(`${expression || '$targetValue'} is readonly`);\n }\n try {\n atom.set(newValue);\n } catch (e) {\n throw Object.assign(new Error(`error while setting ${expression || '$targetValue'}: ${_internal.isError(e) && e.message}`), { jse_cause: e });\n }\n }\n\n /**\n * In methods of a ProxyDescriptor, `this` is bound to the Proxy Object. Therefore, only $-properties and $-methods can be\n * accessed safely. Use $proxyDescriptor to get access to the ProxyDescriptor Object to prevent the ProxyHandler from messing\n * with your logic.\n */\n protected get $proxyDescriptor() { return this; }\n\n /**\n * An optional method that can return an optional lens to this proxy. Is used to transform the values before accessed by the\n * consumer of the Proxy (either through $value or one of the other methods).\n */\n $lens?(): DerivableProxyLens<T, V> | undefined;\n\n /**\n * Wrap a Derivable as DerivableProxy using this ProxyDescriptor.\n *\n * @param obj the object to wrap\n * @param expression the new expression to the created DerivableProxy\n * @param path the new path to the created DerivableProxy\n */\n $create(obj: Derivable<T>, expression?: string, path?: Array<string | number>): DerivableProxy<V> {\n const descriptor: ProxyDescriptor = utils.clone(this.$proxyDescriptor);\n descriptor.$target = obj;\n Object.getOwnPropertyNames(descriptor)\n .filter(prop => prop.startsWith('$$'))\n .forEach(prop => descriptor[prop] = undefined);\n descriptor.$expression = expression;\n descriptor.$path = path;\n return new Proxy(descriptor, proxyHandler) as any;\n }\n\n /**\n * The $pluck method is the implementation of the pluck mechanism of DerivableProxy. Replace this method to change the\n * pluck behavior. It should return a DerivableProxy.\n *\n * @param prop the property to pluck of the wrapped derivable\n */\n $pluck(prop: string | number): DerivableProxy<V> {\n const pd = this.$proxyDescriptor;\n return pd.$create(pd.$derivable.pluck(prop), extendExpression(pd.$expression, prop), extendPath(pd.$path, prop));\n }\n\n /**\n * The $pluckableKeys returns a list of properties that can be plucked from this object. Returned keys are guaranteed to\n * result in a usable DerivableProxy when used with $pluck. Is used for `for ... in` and `Object.keys(...)` logic.\n */\n $pluckableKeys() {\n const value = this.$proxyDescriptor.$value;\n return typeof value === 'object' ? Reflect.ownKeys(value as any) : [];\n }\n\n /**\n * Method that determines whether the current object is iterable and if so, how many elements it contains. During iteration\n * {@link #pluck} is called with indices up to but not including the result of `$length()`.\n */\n $length(): number | undefined {\n const maybeArray = this.$proxyDescriptor.$targetValue;\n return Array.isArray(maybeArray) ? maybeArray.length : undefined;\n }\n\n $and(other: MaybePacked<any>) {\n return this.$proxyDescriptor.$derivable.and(unwrapProxy(other));\n }\n\n $or(other: MaybePacked<any>) {\n return this.$proxyDescriptor.$derivable.or(unwrapProxy(other));\n }\n\n $not() {\n return this.$proxyDescriptor.$derivable.not();\n }\n\n $is(other: MaybePacked<any>) {\n return this.$proxyDescriptor.$derivable.is(unwrapProxy(other));\n }\n\n $derive() {\n const target = this.$proxyDescriptor.$derivable;\n return target.derive.apply(target, arguments as any);\n }\n\n $react(reaction: (value: V, stop: () => void) => void, options?: Partial<ReactorOptions<any>>): () => void {\n return this.$proxyDescriptor.$derivable.react(reaction, options);\n }\n\n toJSON() {\n return this.$proxyDescriptor.$value;\n }\n\n get [Symbol.toStringTag]() {\n return 'DerivableProxy';\n }\n\n *[Symbol.iterator](): IterableIterator<DerivableProxy<V>> {\n const pd = this.$proxyDescriptor;\n const length = pd.$length();\n if (length === undefined) {\n const expression = pd.$expression;\n throw Object.assign(new Error(`${expression || 'object'} is not iterable`), { value: pd.$value, expression });\n }\n for (let i = 0; i < length; i++) {\n yield pd.$pluck(i)!;\n }\n }\n\n get length() {\n return this.$proxyDescriptor.$length();\n }\n}\nProxyDescriptor.prototype[IS_DERIVABLE_PROXY] = true;\n\nfunction createDerivable<V, T>(target: Derivable<T>, proxyLens?: DerivableProxyLens<T, V>): Derivable<V> {\n if (!proxyLens) {\n return target as any;\n }\n const { get, set } = proxyLens;\n if (!set || !isSettableDerivable(target)) {\n return target.derive(get).autoCache();\n }\n return lens({\n get,\n set(newValue, targetValue) {\n target.set(set.call(this, newValue, targetValue));\n }\n }, target).autoCache();\n}\n\nexport interface DerivableProxyLens<T, V> {\n get: (targetValue: T) => V;\n set?: (newValue: V, targetValue: T | undefined) => T;\n}\n\nexport type MaybePacked<T> = T | Derivable<T> | DerivableProxy<T>;\n\nexport function unwrapProxy<W>(obj: MaybePacked<W>): W | Derivable<W> {\n if (isDerivableProxy(obj)) {\n return (obj as any).$derivable;\n }\n return obj;\n}\n\nconst proxyHandler: ProxyHandler<ProxyDescriptor> = {\n get(target, prop, receiver) {\n if (prop === '$proxyDescriptor') {\n return target;\n }\n if (isPluckableProperty(target, prop)) {\n return target.$pluck.call(receiver, prop as string | number);\n }\n return Reflect.get(target, prop, receiver);\n },\n set(target, prop, newValue, receiver) {\n if (isPluckableProperty(target, prop)) {\n const plucked = target.$pluck.call(receiver, prop as string | number) as ProxyDescriptor;\n if (newValue && isDerivableProxy(newValue)) {\n plucked.$targetValue = (newValue as any).$targetValue;\n } else {\n plucked.$value = newValue && isDerivable(newValue) ? newValue.get() : newValue;\n }\n return true;\n }\n return Reflect.set(target, prop, newValue, receiver);\n },\n has(target, prop) {\n if (prop === Symbol.iterator) {\n return target.$length() !== undefined;\n }\n return isPluckableProperty(target, prop);\n },\n getOwnPropertyDescriptor(target, prop) {\n if (isPluckableProperty(target, prop)) {\n return {\n get() { return this[prop]; },\n set(newValue) { this[prop] = newValue; },\n configurable: true,\n enumerable: true,\n };\n }\n return undefined;\n },\n ownKeys(target) {\n return target.$pluckableKeys();\n },\n};\n\nfunction isPluckableProperty(target: ProxyDescriptor, prop: PropertyKey) {\n return typeof prop === 'number' || typeof prop === 'string' && prop[0] !== '$' && !Reflect.has(target, prop);\n}\n\n/**\n * Extends an expression with a property access. Automatically uses bracket notation where appropriate and escapes\n * strings in brackets to give a realistic combined expression.\n *\n * @param expression the (optional) expression to extend\n * @param property the property that should be appended to the expression\n */\nexport function extendExpression(expression = '', property: string | number) {\n if (typeof property === 'string' && /^[a-z_][a-z_0-9]*$/i.test(property)) {\n return expression + '.' + property;\n }\n if (typeof property === 'string') {\n return expression + '[\"' + property.replace(/\\\\/g, '\\\\\\\\').replace(/\\\"/g, '\\\\\"') + '\"]';\n }\n return expression + '[' + property + ']';\n}\n\n/**\n * Extends a path with a property access.\n *\n * @param path the (optional) path to extend\n * @param property the property that should be appended to the path\n */\nexport function extendPath(path: Array<string | number> = [], property: string | number) {\n return path.concat(property);\n}\n"],"mappings":"6GAyCMA,EAAqBC,OAAO,oB,SAOlBC,EAAiBC,GAC7B,OAAmC,IAA5BA,EAAIH,EACf,C,iBAYA,SAAAI,IAwBYC,KAAAC,iBAA6BC,C,CAsKzC,OA1KIC,OAAAC,eAAIL,EAAAM,UAAA,aAAU,C,IAAd,WACI,IAAMC,EAAKN,KAAKO,iBAChB,OAAOD,EAAGL,cAAgBK,EAAGL,YA2KrC,SAA+BO,EAAsBC,GACjD,IAAKA,EACD,OAAOD,EAEH,IAAAE,EAAaD,EAASC,IAAjBC,EAAQF,EAASE,IAC9B,OAAKA,GAAQC,sBAAoBJ,GAG1BK,OAAK,CACRH,IAAGA,EACHC,IAAG,SAACG,EAAUC,GACVP,EAAOG,IAAIA,EAAIK,KAAKhB,KAAMc,EAAUC,G,GAEzCP,GAAQS,YAPAT,EAAOU,OAAOR,GAAKO,WAQlC,CAzLmDE,CAAgBb,EAAGc,QAASd,EAAGe,OAASf,EAAGe,S,kCAQ1FlB,OAAAC,eAAIL,EAAAM,UAAA,SAAM,C,IAAV,WACI,IAAMC,EAAKN,KAAKO,iBAChB,IACI,OAAOD,EAAGgB,WAAWZ,K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IAAS5C,OAAOoF,cACY9E,IAArBM,EAAO+C,UAEX8B,EAAoB7E,EAAQgC,E,EAEvCiD,yBAAwB,SAACjF,EAAQgC,GAC7B,GAAI6C,EAAoB7E,EAAQgC,GAC5B,MAAO,CACH9B,IAAG,WAAK,OAAOV,KAAKwC,EAAM,EAC1B7B,IAAG,SAACG,GAAYd,KAAKwC,GAAQ1B,CAAS,EACtC4E,cAAc,EACdC,YAAY,E,EAKxBrC,QAAO,SAAC9C,GACJ,OAAOA,EAAO0C,gB,GAItB,SAASmC,EAAoB7E,EAAyBgC,GAClD,MAAuB,iBAATA,GAAqC,iBAATA,GAAiC,MAAZA,EAAK,KAAea,QAAQmC,IAAIhF,EAAQgC,EAC3G,C,SASgBQ,EAAiBhB,EAAiB4D,GAC9C,YAD6B,IAAA5D,MAAA,IACL,iBAAb4D,GAAyB,sBAAsBC,KAAKD,GACpD5D,EAAa,IAAM4D,EAEN,iBAAbA,EACA5D,EAAa,KAAO4D,EAASE,QAAQ,MAAO,QAAQA,QAAQ,MAAO,OAAS,KAEhF9D,EAAa,IAAM4D,EAAW,GACzC,C,SAQgB3C,EAAWf,EAAmC0D,GAC1D,YADuB,IAAA1D,MAAA,IAChBA,EAAK6D,OAAOH,EACvB,C"}
1
+ {"version":3,"file":"sherlock-proxy.cjs.min.js","names":["IS_DERIVABLE_PROXY","Symbol","isDerivableProxy","obj","ProxyDescriptor","this","$$derivable","undefined","Object","defineProperty","prototype","get","pd","$proxyDescriptor","target","proxyLens","set","isSettableDerivable","lens","newValue","targetValue","call","autoCache","derive","createDerivable","$target","$lens","$derivable","e","assign","Error","concat","$expression","_internal","isError","message","jse_cause","atom","expression","$create","path","descriptor","utils","clone","getOwnPropertyNames","filter","prop","startsWith","forEach","$path","Proxy","proxyHandler","$pluck","pluck","extendExpression","extendPath","$pluckableKeys","value","$value","Reflect","ownKeys","$length","maybeArray","$targetValue","Array","isArray","length","$and","other","and","unwrapProxy","$or","or","$not","not","$is","is","$derive","apply","arguments","$react","reaction","options","react","toJSON","toStringTag","iterator","i","_a","sent","receiver","isPluckableProperty","plucked","isDerivable","has","getOwnPropertyDescriptor","configurable","enumerable","property","test","replace"],"sources":["../../extensions/sherlock-proxy/proxy.ts"],"sourcesContent":["import { Derivable, isDerivable, isSettableDerivable, lens, ReactorOptions, utils, _internal } from '@politie/sherlock';\n\n/**\n * The base interface for DerivableProxies. Defines only the $-properties and $-methods. Any property accessed with a number or\n * that doesn't start with a $-sign returns a new DerivableProxy.\n */\nexport interface DerivableProxy<V> {\n /** The current value that this Proxy represents. Can be expensive to calculate and is often writable. */\n $value: V;\n\n /** A string representation of this proxy's path from the root ProxyDescriptor. */\n $expression?: string;\n\n /**\n * An array representation of this proxy's path from the root ProxyDescriptor. Useful for programatically walking down the root\n * Descriptor's object tree to reacquire a target proxy.\n */\n $path?: Array<string | number>;\n\n /** {@see Derivable#and} */\n $and<W>(other: MaybePacked<W>): Derivable<V | W>;\n\n /** {@see Derivable#or} */\n $or<W>(other: MaybePacked<W>): Derivable<V | W>;\n\n /** {@see Derivable#not} */\n $not(): Derivable<boolean>;\n\n /** {@see Derivable#is} */\n $is(other: MaybePacked<any>): Derivable<boolean>;\n\n /** {@see Derivable#derive} */\n $derive<R>(f: (v: V) => R): Derivable<R>;\n $derive<R, P1>(f: (v: V, p1: P1) => R, p1: MaybePacked<P1>): Derivable<R>;\n $derive<R, P1, P2>(f: (v: V, p1: P1, p2: P2) => R, p1: MaybePacked<P1>, p2: MaybePacked<P2>): Derivable<R>;\n $derive<R, P>(f: (v: V, ...ps: P[]) => R, ...ps: Array<MaybePacked<P>>): Derivable<R>;\n\n /** {@see Derivable#react} */\n $react(reaction: (value: V, stop: () => void) => void, options?: Partial<ReactorOptions<V>>): () => void;\n}\n\nconst IS_DERIVABLE_PROXY = Symbol('isDerivableProxy');\n\n/**\n * Returns whether obj is a DerivableProxy.\n *\n * @param obj the object to test\n */\nexport function isDerivableProxy(obj: any): obj is DerivableProxy<any> {\n return obj[IS_DERIVABLE_PROXY] === true;\n}\n\n/**\n * A ProxyDescriptor must be used to create DerivableProxies. It can be used in two ways, either create a new descriptor and\n * change any implementation details (if needed) or create a subclass to extend the behavior. Use the {@link #$create} method\n * to create a DerivableProxy.\n *\n * Note that `this` in methods points to the created proxy, so only methods and properties that start with a $-sign can be accessed\n * without trouble.\n *\n * Note also that properties that start with two $-signs are cleared on $create.\n */\nexport class ProxyDescriptor<V = any, T = V> {\n /**\n * The target derivable (the input to the proxy and the {@link #$create} method). The actual values that can be seen by methods\n * on the Proxy can be influenced by providing a {@link #$lens}.\n */\n $target!: Derivable<T>;\n\n /**\n * The expression that represents the path to the current Proxy.\n */\n $expression?: string;\n\n /**\n * The path to the current Proxy.\n */\n $path?: Array<string | number>;\n\n /**\n * The derivable that is the input to all default methods on the Proxy and the {@link #$value} property.\n */\n get $derivable(): Derivable<V> {\n const pd = this.$proxyDescriptor;\n return pd.$$derivable || (pd.$$derivable = createDerivable(pd.$target, pd.$lens && pd.$lens()));\n }\n private $$derivable?: Derivable<V> = undefined;\n\n /**\n * The current value of the DerivableProxy. Can be expensive to calculate. When the target is settable (is an Atom) then $value\n * is writable.\n */\n get $value() {\n const pd = this.$proxyDescriptor;\n try {\n return pd.$derivable.get();\n } catch (e) {\n // istanbul ignore next: for debug purposes\n throw Object.assign(new Error(`error while getting ${pd.$expression || '$value'}: ${_internal.isError(e) && e.message}`), { jse_cause: e });\n }\n }\n set $value(newValue) {\n const pd = this.$proxyDescriptor;\n const atom = pd.$derivable;\n const expression = pd.$expression;\n if (!isSettableDerivable(atom)) {\n throw new Error(`${expression || '$value'} is readonly`);\n }\n try {\n atom.set(newValue);\n } catch (e) {\n throw Object.assign(new Error(`error while setting ${expression || '$value'}: ${_internal.isError(e) && e.message}`), { jse_cause: e });\n }\n }\n\n /**\n * The current value of the target Derivable that was used to create the DerivableProxy.\n */\n get $targetValue() {\n const pd = this.$proxyDescriptor;\n try {\n return pd.$target.get();\n } catch (e) {\n // istanbul ignore next: for debug purposes\n throw Object.assign(\n new Error(`error while getting ${pd.$expression || '$targetValue'}: ${_internal.isError(e) && e.message}`),\n { jse_cause: e },\n );\n }\n }\n set $targetValue(newValue) {\n const pd = this.$proxyDescriptor;\n const atom = pd.$target;\n const expression = pd.$expression;\n if (!isSettableDerivable(atom)) {\n throw new Error(`${expression || '$targetValue'} is readonly`);\n }\n try {\n atom.set(newValue);\n } catch (e) {\n throw Object.assign(new Error(`error while setting ${expression || '$targetValue'}: ${_internal.isError(e) && e.message}`), { jse_cause: e });\n }\n }\n\n /**\n * In methods of a ProxyDescriptor, `this` is bound to the Proxy Object. Therefore, only $-properties and $-methods can be\n * accessed safely. Use $proxyDescriptor to get access to the ProxyDescriptor Object to prevent the ProxyHandler from messing\n * with your logic.\n */\n protected get $proxyDescriptor() { return this; }\n\n /**\n * An optional method that can return an optional lens to this proxy. Is used to transform the values before accessed by the\n * consumer of the Proxy (either through $value or one of the other methods).\n */\n $lens?(): DerivableProxyLens<T, V> | undefined;\n\n /**\n * Wrap a Derivable as DerivableProxy using this ProxyDescriptor.\n *\n * @param obj the object to wrap\n * @param expression the new expression to the created DerivableProxy\n * @param path the new path to the created DerivableProxy\n */\n $create(obj: Derivable<T>, expression?: string, path?: Array<string | number>): DerivableProxy<V> {\n const descriptor: ProxyDescriptor = utils.clone(this.$proxyDescriptor);\n descriptor.$target = obj;\n Object.getOwnPropertyNames(descriptor)\n .filter(prop => prop.startsWith('$$'))\n .forEach(prop => descriptor[prop] = undefined);\n descriptor.$expression = expression;\n descriptor.$path = path;\n return new Proxy(descriptor, proxyHandler) as any;\n }\n\n /**\n * The $pluck method is the implementation of the pluck mechanism of DerivableProxy. Replace this method to change the\n * pluck behavior. It should return a DerivableProxy.\n *\n * @param prop the property to pluck of the wrapped derivable\n */\n $pluck(prop: string | number): DerivableProxy<V> {\n const pd = this.$proxyDescriptor;\n return pd.$create(pd.$derivable.pluck(prop), extendExpression(pd.$expression, prop), extendPath(pd.$path, prop));\n }\n\n /**\n * The $pluckableKeys returns a list of properties that can be plucked from this object. Returned keys are guaranteed to\n * result in a usable DerivableProxy when used with $pluck. Is used for `for ... in` and `Object.keys(...)` logic.\n */\n $pluckableKeys() {\n const value = this.$proxyDescriptor.$value;\n return typeof value === 'object' ? Reflect.ownKeys(value as any) : [];\n }\n\n /**\n * Method that determines whether the current object is iterable and if so, how many elements it contains. During iteration\n * {@link #pluck} is called with indices up to but not including the result of `$length()`.\n */\n $length(): number | undefined {\n const maybeArray = this.$proxyDescriptor.$targetValue;\n return Array.isArray(maybeArray) ? maybeArray.length : undefined;\n }\n\n $and(other: MaybePacked<any>) {\n return this.$proxyDescriptor.$derivable.and(unwrapProxy(other));\n }\n\n $or(other: MaybePacked<any>) {\n return this.$proxyDescriptor.$derivable.or(unwrapProxy(other));\n }\n\n $not() {\n return this.$proxyDescriptor.$derivable.not();\n }\n\n $is(other: MaybePacked<any>) {\n return this.$proxyDescriptor.$derivable.is(unwrapProxy(other));\n }\n\n $derive() {\n const target = this.$proxyDescriptor.$derivable;\n return target.derive.apply(target, arguments as any);\n }\n\n $react(reaction: (value: V, stop: () => void) => void, options?: Partial<ReactorOptions<any>>): () => void {\n return this.$proxyDescriptor.$derivable.react(reaction, options);\n }\n\n toJSON() {\n return this.$proxyDescriptor.$value;\n }\n\n get [Symbol.toStringTag]() {\n return 'DerivableProxy';\n }\n\n *[Symbol.iterator](): IterableIterator<DerivableProxy<V>> {\n const pd = this.$proxyDescriptor;\n const length = pd.$length();\n if (length === undefined) {\n const expression = pd.$expression;\n throw Object.assign(new Error(`${expression || 'object'} is not iterable`), { value: pd.$value, expression });\n }\n for (let i = 0; i < length; i++) {\n yield pd.$pluck(i)!;\n }\n }\n\n get length() {\n return this.$proxyDescriptor.$length();\n }\n}\nProxyDescriptor.prototype[IS_DERIVABLE_PROXY] = true;\n\nfunction createDerivable<V, T>(target: Derivable<T>, proxyLens?: DerivableProxyLens<T, V>): Derivable<V> {\n if (!proxyLens) {\n return target as any;\n }\n const { get, set } = proxyLens;\n if (!set || !isSettableDerivable(target)) {\n return target.derive(get).autoCache();\n }\n return lens({\n get,\n set(newValue, targetValue) {\n target.set(set.call(this, newValue, targetValue));\n }\n }, target).autoCache();\n}\n\nexport interface DerivableProxyLens<T, V> {\n get: (targetValue: T) => V;\n set?: (newValue: V, targetValue: T | undefined) => T;\n}\n\nexport type MaybePacked<T> = T | Derivable<T> | DerivableProxy<T>;\n\nexport function unwrapProxy<W>(obj: MaybePacked<W>): W | Derivable<W> {\n if (isDerivableProxy(obj)) {\n return (obj as any).$derivable;\n }\n return obj;\n}\n\nconst proxyHandler: ProxyHandler<ProxyDescriptor> = {\n get(target, prop, receiver) {\n if (prop === '$proxyDescriptor') {\n return target;\n }\n if (isPluckableProperty(target, prop)) {\n return target.$pluck.call(receiver, prop as string | number);\n }\n return Reflect.get(target, prop, receiver);\n },\n set(target, prop, newValue, receiver) {\n if (isPluckableProperty(target, prop)) {\n const plucked = target.$pluck.call(receiver, prop as string | number) as ProxyDescriptor;\n if (newValue && isDerivableProxy(newValue)) {\n plucked.$targetValue = (newValue as any).$targetValue;\n } else {\n plucked.$value = newValue && isDerivable(newValue) ? newValue.get() : newValue;\n }\n return true;\n }\n return Reflect.set(target, prop, newValue, receiver);\n },\n has(target, prop) {\n if (prop === Symbol.iterator) {\n return target.$length() !== undefined;\n }\n return isPluckableProperty(target, prop);\n },\n getOwnPropertyDescriptor(target, prop) {\n if (isPluckableProperty(target, prop)) {\n return {\n get() { return this[prop]; },\n set(newValue) { this[prop] = newValue; },\n configurable: true,\n enumerable: true,\n };\n }\n return undefined;\n },\n ownKeys(target) {\n return target.$pluckableKeys();\n },\n};\n\nfunction isPluckableProperty(target: ProxyDescriptor, prop: PropertyKey) {\n return typeof prop === 'number' || typeof prop === 'string' && prop[0] !== '$' && !Reflect.has(target, prop);\n}\n\n/**\n * Extends an expression with a property access. Automatically uses bracket notation where appropriate and escapes\n * strings in brackets to give a realistic combined expression.\n *\n * @param expression the (optional) expression to extend\n * @param property the property that should be appended to the expression\n */\nexport function extendExpression(expression = '', property: string | number) {\n if (typeof property === 'string' && /^[a-z_][a-z_0-9]*$/i.test(property)) {\n return expression + '.' + property;\n }\n if (typeof property === 'string') {\n return expression + '[\"' + property.replace(/\\\\/g, '\\\\\\\\').replace(/\\\"/g, '\\\\\"') + '\"]';\n }\n return expression + '[' + property + ']';\n}\n\n/**\n * Extends a path with a property access.\n *\n * @param path the (optional) path to extend\n * @param property the property that should be appended to the path\n */\nexport function extendPath(path: Array<string | number> = [], property: string | number) {\n return path.concat(property);\n}\n"],"mappings":"6GAyCMA,EAAqBC,OAAO,oBAO5B,SAAUC,EAAiBC,GAC7B,OAAmC,IAA5BA,EAAIH,EACf,CAYA,IAAAI,EAAA,oBAAAA,IAwBYC,KAAWC,iBAAkBC,C,CAsKzC,OA1KIC,OAAAC,eAAIL,EAAUM,UAAA,cAAdC,IAAA,WACI,IAAMC,EAAKP,KAAKQ,iBAChB,OAAOD,EAAGN,cAAgBM,EAAGN,YA2KrC,SAA+BQ,EAAsBC,GACjD,IAAKA,EACD,OAAOD,EAEH,IAAAH,EAAaI,EAASJ,IAAjBK,EAAQD,EAASC,IAC9B,OAAKA,GAAQC,sBAAoBH,GAG1BI,OAAK,CACRP,IAAGA,EACHK,IAAG,SAACG,EAAUC,GACVN,EAAOE,IAAIA,EAAIK,KAAKhB,KAAMc,EAAUC,G,GAEzCN,GAAQQ,YAPAR,EAAOS,OAAOZ,GAAKW,WAQlC,CAzLmDE,CAAgBZ,EAAGa,QAASb,EAAGc,OAASd,EAAGc,S,kCAQ1FlB,OAAAC,eAAIL,EAAMM,UAAA,UAAVC,IAAA,WACI,IAAMC,EAAKP,KAAKQ,iBAChB,IACI,OAAOD,EAAGe,WAAWhB,KACxB,CAAC,MAAOiB,GAEL,MAAMpB,OAAOqB,OAAWC,MAAM,uBAAuBC,OAAAnB,EAAGoB,aAAe,SAAQ,MAAAD,OAAKE,YAAUC,QAAQN,IAAMA,EAAEO,UAAY,CAAEC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CI,IAAG,SAAChF,EAAQgC,GACR,OAAIA,IAAS7C,OAAOqF,cACY/E,IAArBO,EAAO+C,UAEX8B,EAAoB7E,EAAQgC,E,EAEvCiD,yBAAwB,SAACjF,EAAQgC,GAC7B,GAAI6C,EAAoB7E,EAAQgC,GAC5B,MAAO,CACHnC,IAAG,WAAK,OAAON,KAAKyC,EAAM,EAC1B9B,IAAG,SAACG,GAAYd,KAAKyC,GAAQ3B,CAAS,EACtC6E,cAAc,EACdC,YAAY,E,EAKxBrC,QAAO,SAAC9C,GACJ,OAAOA,EAAO0C,gB,GAItB,SAASmC,EAAoB7E,EAAyBgC,GAClD,MAAuB,iBAATA,GAAqC,iBAATA,GAAiC,MAAZA,EAAK,KAAea,QAAQmC,IAAIhF,EAAQgC,EAC3G,CASgB,SAAAQ,EAAiBhB,EAAiB4D,GAC9C,YAD6B,IAAA5D,MAAe,IACpB,iBAAb4D,GAAyB,sBAAsBC,KAAKD,GACpD5D,EAAa,IAAM4D,EAEN,iBAAbA,EACA5D,EAAa,KAAO4D,EAASE,QAAQ,MAAO,QAAQA,QAAQ,MAAO,OAAS,KAEhF9D,EAAa,IAAM4D,EAAW,GACzC,CAQgB,SAAA3C,EAAWf,EAAmC0D,GAC1D,YADuB,IAAA1D,MAAiC,IACjDA,EAAKT,OAAOmE,EACvB,C","ignoreList":[]}
@@ -1,5 +1,5 @@
1
1
  import { __generator } from 'tslib';
2
- import { _internal, isSettableDerivable, utils, lens, isDerivable } from '@politie/sherlock';
2
+ import { utils, isDerivable, _internal, isSettableDerivable, lens } from '@politie/sherlock';
3
3
 
4
4
  var IS_DERIVABLE_PROXY = Symbol('isDerivableProxy');
5
5
  /**
@@ -47,7 +47,7 @@ var ProxyDescriptor = /** @class */ (function () {
47
47
  }
48
48
  catch (e) {
49
49
  // istanbul ignore next: for debug purposes
50
- throw Object.assign(new Error("error while getting " + (pd.$expression || '$value') + ": " + (_internal.isError(e) && e.message)), { jse_cause: e });
50
+ throw Object.assign(new Error("error while getting ".concat(pd.$expression || '$value', ": ").concat(_internal.isError(e) && e.message)), { jse_cause: e });
51
51
  }
52
52
  },
53
53
  set: function (newValue) {
@@ -55,13 +55,13 @@ var ProxyDescriptor = /** @class */ (function () {
55
55
  var atom = pd.$derivable;
56
56
  var expression = pd.$expression;
57
57
  if (!isSettableDerivable(atom)) {
58
- throw new Error((expression || '$value') + " is readonly");
58
+ throw new Error("".concat(expression || '$value', " is readonly"));
59
59
  }
60
60
  try {
61
61
  atom.set(newValue);
62
62
  }
63
63
  catch (e) {
64
- throw Object.assign(new Error("error while setting " + (expression || '$value') + ": " + (_internal.isError(e) && e.message)), { jse_cause: e });
64
+ throw Object.assign(new Error("error while setting ".concat(expression || '$value', ": ").concat(_internal.isError(e) && e.message)), { jse_cause: e });
65
65
  }
66
66
  },
67
67
  enumerable: false,
@@ -78,7 +78,7 @@ var ProxyDescriptor = /** @class */ (function () {
78
78
  }
79
79
  catch (e) {
80
80
  // istanbul ignore next: for debug purposes
81
- throw Object.assign(new Error("error while getting " + (pd.$expression || '$targetValue') + ": " + (_internal.isError(e) && e.message)), { jse_cause: e });
81
+ throw Object.assign(new Error("error while getting ".concat(pd.$expression || '$targetValue', ": ").concat(_internal.isError(e) && e.message)), { jse_cause: e });
82
82
  }
83
83
  },
84
84
  set: function (newValue) {
@@ -86,13 +86,13 @@ var ProxyDescriptor = /** @class */ (function () {
86
86
  var atom = pd.$target;
87
87
  var expression = pd.$expression;
88
88
  if (!isSettableDerivable(atom)) {
89
- throw new Error((expression || '$targetValue') + " is readonly");
89
+ throw new Error("".concat(expression || '$targetValue', " is readonly"));
90
90
  }
91
91
  try {
92
92
  atom.set(newValue);
93
93
  }
94
94
  catch (e) {
95
- throw Object.assign(new Error("error while setting " + (expression || '$targetValue') + ": " + (_internal.isError(e) && e.message)), { jse_cause: e });
95
+ throw Object.assign(new Error("error while setting ".concat(expression || '$targetValue', ": ").concat(_internal.isError(e) && e.message)), { jse_cause: e });
96
96
  }
97
97
  },
98
98
  enumerable: false,
@@ -189,7 +189,7 @@ var ProxyDescriptor = /** @class */ (function () {
189
189
  length = pd.$length();
190
190
  if (length === undefined) {
191
191
  expression = pd.$expression;
192
- throw Object.assign(new Error((expression || 'object') + " is not iterable"), { value: pd.$value, expression: expression });
192
+ throw Object.assign(new Error("".concat(expression || 'object', " is not iterable")), { value: pd.$value, expression: expression });
193
193
  }
194
194
  i = 0;
195
195
  _a.label = 1;
@@ -1 +1 @@
1
- {"version":3,"file":"sherlock-proxy.esm.js","sources":["../../extensions/sherlock-proxy/proxy.ts"],"sourcesContent":["import { Derivable, isDerivable, isSettableDerivable, lens, ReactorOptions, utils, _internal } from '@politie/sherlock';\n\n/**\n * The base interface for DerivableProxies. Defines only the $-properties and $-methods. Any property accessed with a number or\n * that doesn't start with a $-sign returns a new DerivableProxy.\n */\nexport interface DerivableProxy<V> {\n /** The current value that this Proxy represents. Can be expensive to calculate and is often writable. */\n $value: V;\n\n /** A string representation of this proxy's path from the root ProxyDescriptor. */\n $expression?: string;\n\n /**\n * An array representation of this proxy's path from the root ProxyDescriptor. Useful for programatically walking down the root\n * Descriptor's object tree to reacquire a target proxy.\n */\n $path?: Array<string | number>;\n\n /** {@see Derivable#and} */\n $and<W>(other: MaybePacked<W>): Derivable<V | W>;\n\n /** {@see Derivable#or} */\n $or<W>(other: MaybePacked<W>): Derivable<V | W>;\n\n /** {@see Derivable#not} */\n $not(): Derivable<boolean>;\n\n /** {@see Derivable#is} */\n $is(other: MaybePacked<any>): Derivable<boolean>;\n\n /** {@see Derivable#derive} */\n $derive<R>(f: (v: V) => R): Derivable<R>;\n $derive<R, P1>(f: (v: V, p1: P1) => R, p1: MaybePacked<P1>): Derivable<R>;\n $derive<R, P1, P2>(f: (v: V, p1: P1, p2: P2) => R, p1: MaybePacked<P1>, p2: MaybePacked<P2>): Derivable<R>;\n $derive<R, P>(f: (v: V, ...ps: P[]) => R, ...ps: Array<MaybePacked<P>>): Derivable<R>;\n\n /** {@see Derivable#react} */\n $react(reaction: (value: V, stop: () => void) => void, options?: Partial<ReactorOptions<V>>): () => void;\n}\n\nconst IS_DERIVABLE_PROXY = Symbol('isDerivableProxy');\n\n/**\n * Returns whether obj is a DerivableProxy.\n *\n * @param obj the object to test\n */\nexport function isDerivableProxy(obj: any): obj is DerivableProxy<any> {\n return obj[IS_DERIVABLE_PROXY] === true;\n}\n\n/**\n * A ProxyDescriptor must be used to create DerivableProxies. It can be used in two ways, either create a new descriptor and\n * change any implementation details (if needed) or create a subclass to extend the behavior. Use the {@link #$create} method\n * to create a DerivableProxy.\n *\n * Note that `this` in methods points to the created proxy, so only methods and properties that start with a $-sign can be accessed\n * without trouble.\n *\n * Note also that properties that start with two $-signs are cleared on $create.\n */\nexport class ProxyDescriptor<V = any, T = V> {\n /**\n * The target derivable (the input to the proxy and the {@link #$create} method). The actual values that can be seen by methods\n * on the Proxy can be influenced by providing a {@link #$lens}.\n */\n $target!: Derivable<T>;\n\n /**\n * The expression that represents the path to the current Proxy.\n */\n $expression?: string;\n\n /**\n * The path to the current Proxy.\n */\n $path?: Array<string | number>;\n\n /**\n * The derivable that is the input to all default methods on the Proxy and the {@link #$value} property.\n */\n get $derivable(): Derivable<V> {\n const pd = this.$proxyDescriptor;\n return pd.$$derivable || (pd.$$derivable = createDerivable(pd.$target, pd.$lens && pd.$lens()));\n }\n private $$derivable?: Derivable<V> = undefined;\n\n /**\n * The current value of the DerivableProxy. Can be expensive to calculate. When the target is settable (is an Atom) then $value\n * is writable.\n */\n get $value() {\n const pd = this.$proxyDescriptor;\n try {\n return pd.$derivable.get();\n } catch (e) {\n // istanbul ignore next: for debug purposes\n throw Object.assign(new Error(`error while getting ${pd.$expression || '$value'}: ${_internal.isError(e) && e.message}`), { jse_cause: e });\n }\n }\n set $value(newValue) {\n const pd = this.$proxyDescriptor;\n const atom = pd.$derivable;\n const expression = pd.$expression;\n if (!isSettableDerivable(atom)) {\n throw new Error(`${expression || '$value'} is readonly`);\n }\n try {\n atom.set(newValue);\n } catch (e) {\n throw Object.assign(new Error(`error while setting ${expression || '$value'}: ${_internal.isError(e) && e.message}`), { jse_cause: e });\n }\n }\n\n /**\n * The current value of the target Derivable that was used to create the DerivableProxy.\n */\n get $targetValue() {\n const pd = this.$proxyDescriptor;\n try {\n return pd.$target.get();\n } catch (e) {\n // istanbul ignore next: for debug purposes\n throw Object.assign(\n new Error(`error while getting ${pd.$expression || '$targetValue'}: ${_internal.isError(e) && e.message}`),\n { jse_cause: e },\n );\n }\n }\n set $targetValue(newValue) {\n const pd = this.$proxyDescriptor;\n const atom = pd.$target;\n const expression = pd.$expression;\n if (!isSettableDerivable(atom)) {\n throw new Error(`${expression || '$targetValue'} is readonly`);\n }\n try {\n atom.set(newValue);\n } catch (e) {\n throw Object.assign(new Error(`error while setting ${expression || '$targetValue'}: ${_internal.isError(e) && e.message}`), { jse_cause: e });\n }\n }\n\n /**\n * In methods of a ProxyDescriptor, `this` is bound to the Proxy Object. Therefore, only $-properties and $-methods can be\n * accessed safely. Use $proxyDescriptor to get access to the ProxyDescriptor Object to prevent the ProxyHandler from messing\n * with your logic.\n */\n protected get $proxyDescriptor() { return this; }\n\n /**\n * An optional method that can return an optional lens to this proxy. Is used to transform the values before accessed by the\n * consumer of the Proxy (either through $value or one of the other methods).\n */\n $lens?(): DerivableProxyLens<T, V> | undefined;\n\n /**\n * Wrap a Derivable as DerivableProxy using this ProxyDescriptor.\n *\n * @param obj the object to wrap\n * @param expression the new expression to the created DerivableProxy\n * @param path the new path to the created DerivableProxy\n */\n $create(obj: Derivable<T>, expression?: string, path?: Array<string | number>): DerivableProxy<V> {\n const descriptor: ProxyDescriptor = utils.clone(this.$proxyDescriptor);\n descriptor.$target = obj;\n Object.getOwnPropertyNames(descriptor)\n .filter(prop => prop.startsWith('$$'))\n .forEach(prop => descriptor[prop] = undefined);\n descriptor.$expression = expression;\n descriptor.$path = path;\n return new Proxy(descriptor, proxyHandler) as any;\n }\n\n /**\n * The $pluck method is the implementation of the pluck mechanism of DerivableProxy. Replace this method to change the\n * pluck behavior. It should return a DerivableProxy.\n *\n * @param prop the property to pluck of the wrapped derivable\n */\n $pluck(prop: string | number): DerivableProxy<V> {\n const pd = this.$proxyDescriptor;\n return pd.$create(pd.$derivable.pluck(prop), extendExpression(pd.$expression, prop), extendPath(pd.$path, prop));\n }\n\n /**\n * The $pluckableKeys returns a list of properties that can be plucked from this object. Returned keys are guaranteed to\n * result in a usable DerivableProxy when used with $pluck. Is used for `for ... in` and `Object.keys(...)` logic.\n */\n $pluckableKeys() {\n const value = this.$proxyDescriptor.$value;\n return typeof value === 'object' ? Reflect.ownKeys(value as any) : [];\n }\n\n /**\n * Method that determines whether the current object is iterable and if so, how many elements it contains. During iteration\n * {@link #pluck} is called with indices up to but not including the result of `$length()`.\n */\n $length(): number | undefined {\n const maybeArray = this.$proxyDescriptor.$targetValue;\n return Array.isArray(maybeArray) ? maybeArray.length : undefined;\n }\n\n $and(other: MaybePacked<any>) {\n return this.$proxyDescriptor.$derivable.and(unwrapProxy(other));\n }\n\n $or(other: MaybePacked<any>) {\n return this.$proxyDescriptor.$derivable.or(unwrapProxy(other));\n }\n\n $not() {\n return this.$proxyDescriptor.$derivable.not();\n }\n\n $is(other: MaybePacked<any>) {\n return this.$proxyDescriptor.$derivable.is(unwrapProxy(other));\n }\n\n $derive() {\n const target = this.$proxyDescriptor.$derivable;\n return target.derive.apply(target, arguments as any);\n }\n\n $react(reaction: (value: V, stop: () => void) => void, options?: Partial<ReactorOptions<any>>): () => void {\n return this.$proxyDescriptor.$derivable.react(reaction, options);\n }\n\n toJSON() {\n return this.$proxyDescriptor.$value;\n }\n\n get [Symbol.toStringTag]() {\n return 'DerivableProxy';\n }\n\n *[Symbol.iterator](): IterableIterator<DerivableProxy<V>> {\n const pd = this.$proxyDescriptor;\n const length = pd.$length();\n if (length === undefined) {\n const expression = pd.$expression;\n throw Object.assign(new Error(`${expression || 'object'} is not iterable`), { value: pd.$value, expression });\n }\n for (let i = 0; i < length; i++) {\n yield pd.$pluck(i)!;\n }\n }\n\n get length() {\n return this.$proxyDescriptor.$length();\n }\n}\nProxyDescriptor.prototype[IS_DERIVABLE_PROXY] = true;\n\nfunction createDerivable<V, T>(target: Derivable<T>, proxyLens?: DerivableProxyLens<T, V>): Derivable<V> {\n if (!proxyLens) {\n return target as any;\n }\n const { get, set } = proxyLens;\n if (!set || !isSettableDerivable(target)) {\n return target.derive(get).autoCache();\n }\n return lens({\n get,\n set(newValue, targetValue) {\n target.set(set.call(this, newValue, targetValue));\n }\n }, target).autoCache();\n}\n\nexport interface DerivableProxyLens<T, V> {\n get: (targetValue: T) => V;\n set?: (newValue: V, targetValue: T | undefined) => T;\n}\n\nexport type MaybePacked<T> = T | Derivable<T> | DerivableProxy<T>;\n\nexport function unwrapProxy<W>(obj: MaybePacked<W>): W | Derivable<W> {\n if (isDerivableProxy(obj)) {\n return (obj as any).$derivable;\n }\n return obj;\n}\n\nconst proxyHandler: ProxyHandler<ProxyDescriptor> = {\n get(target, prop, receiver) {\n if (prop === '$proxyDescriptor') {\n return target;\n }\n if (isPluckableProperty(target, prop)) {\n return target.$pluck.call(receiver, prop as string | number);\n }\n return Reflect.get(target, prop, receiver);\n },\n set(target, prop, newValue, receiver) {\n if (isPluckableProperty(target, prop)) {\n const plucked = target.$pluck.call(receiver, prop as string | number) as ProxyDescriptor;\n if (newValue && isDerivableProxy(newValue)) {\n plucked.$targetValue = (newValue as any).$targetValue;\n } else {\n plucked.$value = newValue && isDerivable(newValue) ? newValue.get() : newValue;\n }\n return true;\n }\n return Reflect.set(target, prop, newValue, receiver);\n },\n has(target, prop) {\n if (prop === Symbol.iterator) {\n return target.$length() !== undefined;\n }\n return isPluckableProperty(target, prop);\n },\n getOwnPropertyDescriptor(target, prop) {\n if (isPluckableProperty(target, prop)) {\n return {\n get() { return this[prop]; },\n set(newValue) { this[prop] = newValue; },\n configurable: true,\n enumerable: true,\n };\n }\n return undefined;\n },\n ownKeys(target) {\n return target.$pluckableKeys();\n },\n};\n\nfunction isPluckableProperty(target: ProxyDescriptor, prop: PropertyKey) {\n return typeof prop === 'number' || typeof prop === 'string' && prop[0] !== '$' && !Reflect.has(target, prop);\n}\n\n/**\n * Extends an expression with a property access. Automatically uses bracket notation where appropriate and escapes\n * strings in brackets to give a realistic combined expression.\n *\n * @param expression the (optional) expression to extend\n * @param property the property that should be appended to the expression\n */\nexport function extendExpression(expression = '', property: string | number) {\n if (typeof property === 'string' && /^[a-z_][a-z_0-9]*$/i.test(property)) {\n return expression + '.' + property;\n }\n if (typeof property === 'string') {\n return expression + '[\"' + property.replace(/\\\\/g, '\\\\\\\\').replace(/\\\"/g, '\\\\\"') + '\"]';\n }\n return expression + '[' + property + ']';\n}\n\n/**\n * Extends a path with a property access.\n *\n * @param path the (optional) path to extend\n * @param property the property that should be appended to the path\n */\nexport function extendPath(path: Array<string | number> = [], property: string | number) {\n return path.concat(property);\n}\n"],"names":[],"mappings":";;;AAyCA,IAAM,kBAAkB,GAAG,MAAM,CAAC,kBAAkB,CAAC,CAAC;AAEtD;;;;;SAKgB,gBAAgB,CAAC,GAAQ;IACrC,OAAO,GAAG,CAAC,kBAAkB,CAAC,KAAK,IAAI,CAAC;AAC5C,CAAC;AAED;;;;;;;;;;;IAUA;QAwBY,gBAAW,GAAkB,SAAS,CAAC;KAsKlD;IA1KG,sBAAI,uCAAU;;;;aAAd;YACI,IAAM,EAAE,GAAG,IAAI,CAAC,gBAAgB,CAAC;YACjC,OAAO,EAAE,CAAC,WAAW,KAAK,EAAE,CAAC,WAAW,GAAG,eAAe,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,KAAK,IAAI,EAAE,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;SACnG;;;OAAA;IAOD,sBAAI,mCAAM;;;;;aAAV;YACI,IAAM,EAAE,GAAG,IAAI,CAAC,gBAAgB,CAAC;YACjC,IAAI;gBACA,OAAO,EAAE,CAAC,UAAU,CAAC,GAAG,EAAE,CAAC;aAC9B;YAAC,OAAO,CAAC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,QAAQ,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;AACjH,CAAC;AAED;;;;;;;SAOgB,gBAAgB,CAAC,UAAe,EAAE,QAAyB;IAA1C,2BAAA,EAAA,eAAe;IAC5C,IAAI,OAAO,QAAQ,KAAK,QAAQ,IAAI,qBAAqB,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE;QACtE,OAAO,UAAU,GAAG,GAAG,GAAG,QAAQ,CAAC;KACtC;IACD,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE;QAC9B,OAAO,UAAU,GAAG,IAAI,GAAG,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,IAAI,CAAC;KAC3F;IACD,OAAO,UAAU,GAAG,GAAG,GAAG,QAAQ,GAAG,GAAG,CAAC;AAC7C,CAAC;AAED;;;;;;SAMgB,UAAU,CAAC,IAAiC,EAAE,QAAyB;IAA5D,qBAAA,EAAA,SAAiC;IACxD,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;AACjC;;;;"}
1
+ {"version":3,"file":"sherlock-proxy.esm.js","sources":["../../extensions/sherlock-proxy/proxy.ts"],"sourcesContent":["import { Derivable, isDerivable, isSettableDerivable, lens, ReactorOptions, utils, _internal } from '@politie/sherlock';\n\n/**\n * The base interface for DerivableProxies. Defines only the $-properties and $-methods. Any property accessed with a number or\n * that doesn't start with a $-sign returns a new DerivableProxy.\n */\nexport interface DerivableProxy<V> {\n /** The current value that this Proxy represents. Can be expensive to calculate and is often writable. */\n $value: V;\n\n /** A string representation of this proxy's path from the root ProxyDescriptor. */\n $expression?: string;\n\n /**\n * An array representation of this proxy's path from the root ProxyDescriptor. Useful for programatically walking down the root\n * Descriptor's object tree to reacquire a target proxy.\n */\n $path?: Array<string | number>;\n\n /** {@see Derivable#and} */\n $and<W>(other: MaybePacked<W>): Derivable<V | W>;\n\n /** {@see Derivable#or} */\n $or<W>(other: MaybePacked<W>): Derivable<V | W>;\n\n /** {@see Derivable#not} */\n $not(): Derivable<boolean>;\n\n /** {@see Derivable#is} */\n $is(other: MaybePacked<any>): Derivable<boolean>;\n\n /** {@see Derivable#derive} */\n $derive<R>(f: (v: V) => R): Derivable<R>;\n $derive<R, P1>(f: (v: V, p1: P1) => R, p1: MaybePacked<P1>): Derivable<R>;\n $derive<R, P1, P2>(f: (v: V, p1: P1, p2: P2) => R, p1: MaybePacked<P1>, p2: MaybePacked<P2>): Derivable<R>;\n $derive<R, P>(f: (v: V, ...ps: P[]) => R, ...ps: Array<MaybePacked<P>>): Derivable<R>;\n\n /** {@see Derivable#react} */\n $react(reaction: (value: V, stop: () => void) => void, options?: Partial<ReactorOptions<V>>): () => void;\n}\n\nconst IS_DERIVABLE_PROXY = Symbol('isDerivableProxy');\n\n/**\n * Returns whether obj is a DerivableProxy.\n *\n * @param obj the object to test\n */\nexport function isDerivableProxy(obj: any): obj is DerivableProxy<any> {\n return obj[IS_DERIVABLE_PROXY] === true;\n}\n\n/**\n * A ProxyDescriptor must be used to create DerivableProxies. It can be used in two ways, either create a new descriptor and\n * change any implementation details (if needed) or create a subclass to extend the behavior. Use the {@link #$create} method\n * to create a DerivableProxy.\n *\n * Note that `this` in methods points to the created proxy, so only methods and properties that start with a $-sign can be accessed\n * without trouble.\n *\n * Note also that properties that start with two $-signs are cleared on $create.\n */\nexport class ProxyDescriptor<V = any, T = V> {\n /**\n * The target derivable (the input to the proxy and the {@link #$create} method). The actual values that can be seen by methods\n * on the Proxy can be influenced by providing a {@link #$lens}.\n */\n $target!: Derivable<T>;\n\n /**\n * The expression that represents the path to the current Proxy.\n */\n $expression?: string;\n\n /**\n * The path to the current Proxy.\n */\n $path?: Array<string | number>;\n\n /**\n * The derivable that is the input to all default methods on the Proxy and the {@link #$value} property.\n */\n get $derivable(): Derivable<V> {\n const pd = this.$proxyDescriptor;\n return pd.$$derivable || (pd.$$derivable = createDerivable(pd.$target, pd.$lens && pd.$lens()));\n }\n private $$derivable?: Derivable<V> = undefined;\n\n /**\n * The current value of the DerivableProxy. Can be expensive to calculate. When the target is settable (is an Atom) then $value\n * is writable.\n */\n get $value() {\n const pd = this.$proxyDescriptor;\n try {\n return pd.$derivable.get();\n } catch (e) {\n // istanbul ignore next: for debug purposes\n throw Object.assign(new Error(`error while getting ${pd.$expression || '$value'}: ${_internal.isError(e) && e.message}`), { jse_cause: e });\n }\n }\n set $value(newValue) {\n const pd = this.$proxyDescriptor;\n const atom = pd.$derivable;\n const expression = pd.$expression;\n if (!isSettableDerivable(atom)) {\n throw new Error(`${expression || '$value'} is readonly`);\n }\n try {\n atom.set(newValue);\n } catch (e) {\n throw Object.assign(new Error(`error while setting ${expression || '$value'}: ${_internal.isError(e) && e.message}`), { jse_cause: e });\n }\n }\n\n /**\n * The current value of the target Derivable that was used to create the DerivableProxy.\n */\n get $targetValue() {\n const pd = this.$proxyDescriptor;\n try {\n return pd.$target.get();\n } catch (e) {\n // istanbul ignore next: for debug purposes\n throw Object.assign(\n new Error(`error while getting ${pd.$expression || '$targetValue'}: ${_internal.isError(e) && e.message}`),\n { jse_cause: e },\n );\n }\n }\n set $targetValue(newValue) {\n const pd = this.$proxyDescriptor;\n const atom = pd.$target;\n const expression = pd.$expression;\n if (!isSettableDerivable(atom)) {\n throw new Error(`${expression || '$targetValue'} is readonly`);\n }\n try {\n atom.set(newValue);\n } catch (e) {\n throw Object.assign(new Error(`error while setting ${expression || '$targetValue'}: ${_internal.isError(e) && e.message}`), { jse_cause: e });\n }\n }\n\n /**\n * In methods of a ProxyDescriptor, `this` is bound to the Proxy Object. Therefore, only $-properties and $-methods can be\n * accessed safely. Use $proxyDescriptor to get access to the ProxyDescriptor Object to prevent the ProxyHandler from messing\n * with your logic.\n */\n protected get $proxyDescriptor() { return this; }\n\n /**\n * An optional method that can return an optional lens to this proxy. Is used to transform the values before accessed by the\n * consumer of the Proxy (either through $value or one of the other methods).\n */\n $lens?(): DerivableProxyLens<T, V> | undefined;\n\n /**\n * Wrap a Derivable as DerivableProxy using this ProxyDescriptor.\n *\n * @param obj the object to wrap\n * @param expression the new expression to the created DerivableProxy\n * @param path the new path to the created DerivableProxy\n */\n $create(obj: Derivable<T>, expression?: string, path?: Array<string | number>): DerivableProxy<V> {\n const descriptor: ProxyDescriptor = utils.clone(this.$proxyDescriptor);\n descriptor.$target = obj;\n Object.getOwnPropertyNames(descriptor)\n .filter(prop => prop.startsWith('$$'))\n .forEach(prop => descriptor[prop] = undefined);\n descriptor.$expression = expression;\n descriptor.$path = path;\n return new Proxy(descriptor, proxyHandler) as any;\n }\n\n /**\n * The $pluck method is the implementation of the pluck mechanism of DerivableProxy. Replace this method to change the\n * pluck behavior. It should return a DerivableProxy.\n *\n * @param prop the property to pluck of the wrapped derivable\n */\n $pluck(prop: string | number): DerivableProxy<V> {\n const pd = this.$proxyDescriptor;\n return pd.$create(pd.$derivable.pluck(prop), extendExpression(pd.$expression, prop), extendPath(pd.$path, prop));\n }\n\n /**\n * The $pluckableKeys returns a list of properties that can be plucked from this object. Returned keys are guaranteed to\n * result in a usable DerivableProxy when used with $pluck. Is used for `for ... in` and `Object.keys(...)` logic.\n */\n $pluckableKeys() {\n const value = this.$proxyDescriptor.$value;\n return typeof value === 'object' ? Reflect.ownKeys(value as any) : [];\n }\n\n /**\n * Method that determines whether the current object is iterable and if so, how many elements it contains. During iteration\n * {@link #pluck} is called with indices up to but not including the result of `$length()`.\n */\n $length(): number | undefined {\n const maybeArray = this.$proxyDescriptor.$targetValue;\n return Array.isArray(maybeArray) ? maybeArray.length : undefined;\n }\n\n $and(other: MaybePacked<any>) {\n return this.$proxyDescriptor.$derivable.and(unwrapProxy(other));\n }\n\n $or(other: MaybePacked<any>) {\n return this.$proxyDescriptor.$derivable.or(unwrapProxy(other));\n }\n\n $not() {\n return this.$proxyDescriptor.$derivable.not();\n }\n\n $is(other: MaybePacked<any>) {\n return this.$proxyDescriptor.$derivable.is(unwrapProxy(other));\n }\n\n $derive() {\n const target = this.$proxyDescriptor.$derivable;\n return target.derive.apply(target, arguments as any);\n }\n\n $react(reaction: (value: V, stop: () => void) => void, options?: Partial<ReactorOptions<any>>): () => void {\n return this.$proxyDescriptor.$derivable.react(reaction, options);\n }\n\n toJSON() {\n return this.$proxyDescriptor.$value;\n }\n\n get [Symbol.toStringTag]() {\n return 'DerivableProxy';\n }\n\n *[Symbol.iterator](): IterableIterator<DerivableProxy<V>> {\n const pd = this.$proxyDescriptor;\n const length = pd.$length();\n if (length === undefined) {\n const expression = pd.$expression;\n throw Object.assign(new Error(`${expression || 'object'} is not iterable`), { value: pd.$value, expression });\n }\n for (let i = 0; i < length; i++) {\n yield pd.$pluck(i)!;\n }\n }\n\n get length() {\n return this.$proxyDescriptor.$length();\n }\n}\nProxyDescriptor.prototype[IS_DERIVABLE_PROXY] = true;\n\nfunction createDerivable<V, T>(target: Derivable<T>, proxyLens?: DerivableProxyLens<T, V>): Derivable<V> {\n if (!proxyLens) {\n return target as any;\n }\n const { get, set } = proxyLens;\n if (!set || !isSettableDerivable(target)) {\n return target.derive(get).autoCache();\n }\n return lens({\n get,\n set(newValue, targetValue) {\n target.set(set.call(this, newValue, targetValue));\n }\n }, target).autoCache();\n}\n\nexport interface DerivableProxyLens<T, V> {\n get: (targetValue: T) => V;\n set?: (newValue: V, targetValue: T | undefined) => T;\n}\n\nexport type MaybePacked<T> = T | Derivable<T> | DerivableProxy<T>;\n\nexport function unwrapProxy<W>(obj: MaybePacked<W>): W | Derivable<W> {\n if (isDerivableProxy(obj)) {\n return (obj as any).$derivable;\n }\n return obj;\n}\n\nconst proxyHandler: ProxyHandler<ProxyDescriptor> = {\n get(target, prop, receiver) {\n if (prop === '$proxyDescriptor') {\n return target;\n }\n if (isPluckableProperty(target, prop)) {\n return target.$pluck.call(receiver, prop as string | number);\n }\n return Reflect.get(target, prop, receiver);\n },\n set(target, prop, newValue, receiver) {\n if (isPluckableProperty(target, prop)) {\n const plucked = target.$pluck.call(receiver, prop as string | number) as ProxyDescriptor;\n if (newValue && isDerivableProxy(newValue)) {\n plucked.$targetValue = (newValue as any).$targetValue;\n } else {\n plucked.$value = newValue && isDerivable(newValue) ? newValue.get() : newValue;\n }\n return true;\n }\n return Reflect.set(target, prop, newValue, receiver);\n },\n has(target, prop) {\n if (prop === Symbol.iterator) {\n return target.$length() !== undefined;\n }\n return isPluckableProperty(target, prop);\n },\n getOwnPropertyDescriptor(target, prop) {\n if (isPluckableProperty(target, prop)) {\n return {\n get() { return this[prop]; },\n set(newValue) { this[prop] = newValue; },\n configurable: true,\n enumerable: true,\n };\n }\n return undefined;\n },\n ownKeys(target) {\n return target.$pluckableKeys();\n },\n};\n\nfunction isPluckableProperty(target: ProxyDescriptor, prop: PropertyKey) {\n return typeof prop === 'number' || typeof prop === 'string' && prop[0] !== '$' && !Reflect.has(target, prop);\n}\n\n/**\n * Extends an expression with a property access. Automatically uses bracket notation where appropriate and escapes\n * strings in brackets to give a realistic combined expression.\n *\n * @param expression the (optional) expression to extend\n * @param property the property that should be appended to the expression\n */\nexport function extendExpression(expression = '', property: string | number) {\n if (typeof property === 'string' && /^[a-z_][a-z_0-9]*$/i.test(property)) {\n return expression + '.' + property;\n }\n if (typeof property === 'string') {\n return expression + '[\"' + property.replace(/\\\\/g, '\\\\\\\\').replace(/\\\"/g, '\\\\\"') + '\"]';\n }\n return expression + '[' + property + ']';\n}\n\n/**\n * Extends a path with a property access.\n *\n * @param path the (optional) path to extend\n * @param property the property that should be appended to the path\n */\nexport function extendPath(path: Array<string | number> = [], property: string | number) {\n return path.concat(property);\n}\n"],"names":[],"mappings":";;;AAyCA,IAAM,kBAAkB,GAAG,MAAM,CAAC,kBAAkB,CAAC,CAAC;AAEtD;;;;AAIG;AACG,SAAU,gBAAgB,CAAC,GAAQ,EAAA;AACrC,IAAA,OAAO,GAAG,CAAC,kBAAkB,CAAC,KAAK,IAAI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,MAAM,CAAC,QAAQ,CAAC,CAAC;AACjC;;;;"}
@@ -1,2 +1,2 @@
1
- import{__generator as r}from"tslib";import{_internal as t,isSettableDerivable as e,utils as n,lens as i,isDerivable as u}from"@politie/sherlock";var o=Symbol("isDerivableProxy");function c(r){return!0===r[o]}var a=function(){function u(){this.$$derivable=void 0}return Object.defineProperty(u.prototype,"$derivable",{get:function(){var r=this.$proxyDescriptor;return r.$$derivable||(r.$$derivable=function(r,t){if(!t)return r;var n=t.get,u=t.set;return u&&e(r)?i({get:n,set:function(t,e){r.set(u.call(this,t,e))}},r).autoCache():r.derive(n).autoCache()}(r.$target,r.$lens&&r.$lens()))},enumerable:!1,configurable:!0}),Object.defineProperty(u.prototype,"$value",{get:function(){var r=this.$proxyDescriptor;try{return r.$derivable.get()}catch(e){throw Object.assign(Error("error while getting "+(r.$expression||"$value")+": "+(t.isError(e)&&e.message)),{jse_cause:e})}},set:function(r){var n=this.$proxyDescriptor,i=n.$derivable,u=n.$expression;if(!e(i))throw Error((u||"$value")+" is readonly");try{i.set(r)}catch(r){throw Object.assign(Error("error while setting "+(u||"$value")+": "+(t.isError(r)&&r.message)),{jse_cause:r})}},enumerable:!1,configurable:!0}),Object.defineProperty(u.prototype,"$targetValue",{get:function(){var r=this.$proxyDescriptor;try{return r.$target.get()}catch(e){throw Object.assign(Error("error while getting "+(r.$expression||"$targetValue")+": "+(t.isError(e)&&e.message)),{jse_cause:e})}},set:function(r){var n=this.$proxyDescriptor,i=n.$target,u=n.$expression;if(!e(i))throw Error((u||"$targetValue")+" is readonly");try{i.set(r)}catch(r){throw Object.assign(Error("error while setting "+(u||"$targetValue")+": "+(t.isError(r)&&r.message)),{jse_cause:r})}},enumerable:!1,configurable:!0}),Object.defineProperty(u.prototype,"$proxyDescriptor",{get:function(){return this},enumerable:!1,configurable:!0}),u.prototype.$create=function(r,t,e){var i=n.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=t,i.$path=e,new Proxy(i,s)},u.prototype.$pluck=function(r){var t=this.$proxyDescriptor;return t.$create(t.$derivable.pluck(r),h(t.$expression,r),b(t.$path,r))},u.prototype.$pluckableKeys=function(){var r=this.$proxyDescriptor.$value;return"object"==typeof r?Reflect.ownKeys(r):[]},u.prototype.$length=function(){var r=this.$proxyDescriptor.$targetValue;return Array.isArray(r)?r.length:void 0},u.prototype.$and=function(r){return this.$proxyDescriptor.$derivable.and(f(r))},u.prototype.$or=function(r){return this.$proxyDescriptor.$derivable.or(f(r))},u.prototype.$not=function(){return this.$proxyDescriptor.$derivable.not()},u.prototype.$is=function(r){return this.$proxyDescriptor.$derivable.is(f(r))},u.prototype.$derive=function(){var r=this.$proxyDescriptor.$derivable;return r.derive.apply(r,arguments)},u.prototype.$react=function(r,t){return this.$proxyDescriptor.$derivable.react(r,t)},u.prototype.toJSON=function(){return this.$proxyDescriptor.$value},Object.defineProperty(u.prototype,Symbol.toStringTag,{get:function(){return"DerivableProxy"},enumerable:!1,configurable:!0}),u.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((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(u.prototype,"length",{get:function(){return this.$proxyDescriptor.$length()},enumerable:!1,configurable:!0}),u}();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,e,n){if(l(r,t)){var i=r.$pluck.call(n,t);return e&&c(e)?i.$targetValue=e.$targetValue:i.$value=e&&u(e)?e.get():e,!0}return Reflect.set(r,t,e,n)},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};
1
+ 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};
2
2
  //# sourceMappingURL=sherlock-proxy.esm.min.js.map