golden-path
Version:
1,127 lines (931 loc) • 27.9 kB
JavaScript
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
//
var shallowequal = function shallowEqual(objA, objB, compare, compareContext) {
var ret = compare ? compare.call(compareContext, objA, objB) : void 0;
if (ret !== void 0) {
return !!ret;
}
if (objA === objB) {
return true;
}
if (typeof objA !== "object" || !objA || typeof objB !== "object" || !objB) {
return false;
}
var keysA = Object.keys(objA);
var keysB = Object.keys(objB);
if (keysA.length !== keysB.length) {
return false;
}
var bHasOwnProperty = Object.prototype.hasOwnProperty.bind(objB); // Test for A's keys different from B.
for (var idx = 0; idx < keysA.length; idx++) {
var key = keysA[idx];
if (!bHasOwnProperty(key)) {
return false;
}
var valueA = objA[key];
var valueB = objB[key];
ret = compare ? compare.call(compareContext, valueA, valueB, key) : void 0;
if (ret === false || ret === void 0 && valueA !== valueB) {
return false;
}
}
return true;
};
function _objectWithoutPropertiesLoose(source, excluded) {
if (source == null) return {};
var target = {};
var sourceKeys = Object.keys(source);
var key, i;
for (i = 0; i < sourceKeys.length; i++) {
key = sourceKeys[i];
if (excluded.indexOf(key) >= 0) continue;
target[key] = source[key];
}
return target;
}
function _objectWithoutProperties(source, excluded) {
if (source == null) return {};
var target = _objectWithoutPropertiesLoose(source, excluded);
var key, i;
if (Object.getOwnPropertySymbols) {
var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
for (i = 0; i < sourceSymbolKeys.length; i++) {
key = sourceSymbolKeys[i];
if (excluded.indexOf(key) >= 0) continue;
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
target[key] = source[key];
}
}
return target;
}
function _toConsumableArray(arr) {
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
}
function _arrayWithoutHoles(arr) {
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
}
function _iterableToArray(iter) {
if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter);
}
function _unsupportedIterableToArray(o, minLen) {
if (!o) return;
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
var n = Object.prototype.toString.call(o).slice(8, -1);
if (n === "Object" && o.constructor) n = o.constructor.name;
if (n === "Map" || n === "Set") return Array.from(o);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
}
function _arrayLikeToArray(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
return arr2;
}
function _nonIterableSpread() {
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _isPlaceholder(a) {
return a != null && typeof a === 'object' && a['@@functional/placeholder'] === true;
}
/**
* Optimized internal one-arity curry function.
*
* @private
* @category Function
* @param {Function} fn The function to curry.
* @return {Function} The curried function.
*/
function _curry1(fn) {
return function f1(a) {
if (arguments.length === 0 || _isPlaceholder(a)) {
return f1;
} else {
return fn.apply(this, arguments);
}
};
}
/**
* Optimized internal two-arity curry function.
*
* @private
* @category Function
* @param {Function} fn The function to curry.
* @return {Function} The curried function.
*/
function _curry2(fn) {
return function f2(a, b) {
switch (arguments.length) {
case 0:
return f2;
case 1:
return _isPlaceholder(a) ? f2 : _curry1(function (_b) {
return fn(a, _b);
});
default:
return _isPlaceholder(a) && _isPlaceholder(b) ? f2 : _isPlaceholder(a) ? _curry1(function (_a) {
return fn(_a, b);
}) : _isPlaceholder(b) ? _curry1(function (_b) {
return fn(a, _b);
}) : fn(a, b);
}
};
}
function _arity(n, fn) {
/* eslint-disable no-unused-vars */
switch (n) {
case 0:
return function () {
return fn.apply(this, arguments);
};
case 1:
return function (a0) {
return fn.apply(this, arguments);
};
case 2:
return function (a0, a1) {
return fn.apply(this, arguments);
};
case 3:
return function (a0, a1, a2) {
return fn.apply(this, arguments);
};
case 4:
return function (a0, a1, a2, a3) {
return fn.apply(this, arguments);
};
case 5:
return function (a0, a1, a2, a3, a4) {
return fn.apply(this, arguments);
};
case 6:
return function (a0, a1, a2, a3, a4, a5) {
return fn.apply(this, arguments);
};
case 7:
return function (a0, a1, a2, a3, a4, a5, a6) {
return fn.apply(this, arguments);
};
case 8:
return function (a0, a1, a2, a3, a4, a5, a6, a7) {
return fn.apply(this, arguments);
};
case 9:
return function (a0, a1, a2, a3, a4, a5, a6, a7, a8) {
return fn.apply(this, arguments);
};
case 10:
return function (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) {
return fn.apply(this, arguments);
};
default:
throw new Error('First argument to _arity must be a non-negative integer no greater than ten');
}
}
/**
* Internal curryN function.
*
* @private
* @category Function
* @param {Number} length The arity of the curried function.
* @param {Array} received An array of arguments received thus far.
* @param {Function} fn The function to curry.
* @return {Function} The curried function.
*/
function _curryN(length, received, fn) {
return function () {
var combined = [];
var argsIdx = 0;
var left = length;
var combinedIdx = 0;
while (combinedIdx < received.length || argsIdx < arguments.length) {
var result;
if (combinedIdx < received.length && (!_isPlaceholder(received[combinedIdx]) || argsIdx >= arguments.length)) {
result = received[combinedIdx];
} else {
result = arguments[argsIdx];
argsIdx += 1;
}
combined[combinedIdx] = result;
if (!_isPlaceholder(result)) {
left -= 1;
}
combinedIdx += 1;
}
return left <= 0 ? fn.apply(this, combined) : _arity(left, _curryN(length, combined, fn));
};
}
/**
* Returns a curried equivalent of the provided function, with the specified
* arity. The curried function has two unusual capabilities. First, its
* arguments needn't be provided one at a time. If `g` is `R.curryN(3, f)`, the
* following are equivalent:
*
* - `g(1)(2)(3)`
* - `g(1)(2, 3)`
* - `g(1, 2)(3)`
* - `g(1, 2, 3)`
*
* Secondly, the special placeholder value [`R.__`](#__) may be used to specify
* "gaps", allowing partial application of any combination of arguments,
* regardless of their positions. If `g` is as above and `_` is [`R.__`](#__),
* the following are equivalent:
*
* - `g(1, 2, 3)`
* - `g(_, 2, 3)(1)`
* - `g(_, _, 3)(1)(2)`
* - `g(_, _, 3)(1, 2)`
* - `g(_, 2)(1)(3)`
* - `g(_, 2)(1, 3)`
* - `g(_, 2)(_, 3)(1)`
*
* @func
* @memberOf R
* @since v0.5.0
* @category Function
* @sig Number -> (* -> a) -> (* -> a)
* @param {Number} length The arity for the returned function.
* @param {Function} fn The function to curry.
* @return {Function} A new, curried function.
* @see R.curry
* @example
*
* const sumArgs = (...args) => R.sum(args);
*
* const curriedAddFourNumbers = R.curryN(4, sumArgs);
* const f = curriedAddFourNumbers(1, 2);
* const g = f(3);
* g(4); //=> 10
*/
var curryN = /*#__PURE__*/_curry2(function curryN(length, fn) {
if (length === 1) {
return _curry1(fn);
}
return _arity(length, _curryN(length, [], fn));
});
var curryN$1 = curryN;
/**
* Optimized internal three-arity curry function.
*
* @private
* @category Function
* @param {Function} fn The function to curry.
* @return {Function} The curried function.
*/
function _curry3(fn) {
return function f3(a, b, c) {
switch (arguments.length) {
case 0:
return f3;
case 1:
return _isPlaceholder(a) ? f3 : _curry2(function (_b, _c) {
return fn(a, _b, _c);
});
case 2:
return _isPlaceholder(a) && _isPlaceholder(b) ? f3 : _isPlaceholder(a) ? _curry2(function (_a, _c) {
return fn(_a, b, _c);
}) : _isPlaceholder(b) ? _curry2(function (_b, _c) {
return fn(a, _b, _c);
}) : _curry1(function (_c) {
return fn(a, b, _c);
});
default:
return _isPlaceholder(a) && _isPlaceholder(b) && _isPlaceholder(c) ? f3 : _isPlaceholder(a) && _isPlaceholder(b) ? _curry2(function (_a, _b) {
return fn(_a, _b, c);
}) : _isPlaceholder(a) && _isPlaceholder(c) ? _curry2(function (_a, _c) {
return fn(_a, b, _c);
}) : _isPlaceholder(b) && _isPlaceholder(c) ? _curry2(function (_b, _c) {
return fn(a, _b, _c);
}) : _isPlaceholder(a) ? _curry1(function (_a) {
return fn(_a, b, c);
}) : _isPlaceholder(b) ? _curry1(function (_b) {
return fn(a, _b, c);
}) : _isPlaceholder(c) ? _curry1(function (_c) {
return fn(a, b, _c);
}) : fn(a, b, c);
}
};
}
/**
* Tests whether or not an object is an array.
*
* @private
* @param {*} val The object to test.
* @return {Boolean} `true` if `val` is an array, `false` otherwise.
* @example
*
* _isArray([]); //=> true
* _isArray(null); //=> false
* _isArray({}); //=> false
*/
var _isArray = Array.isArray || function _isArray(val) {
return val != null && val.length >= 0 && Object.prototype.toString.call(val) === '[object Array]';
};
function _isString(x) {
return Object.prototype.toString.call(x) === '[object String]';
}
function _has(prop, obj) {
return Object.prototype.hasOwnProperty.call(obj, prop);
}
/**
* Determine if the passed argument is an integer.
*
* @private
* @param {*} n
* @category Type
* @return {Boolean}
*/
var _isInteger = Number.isInteger || function _isInteger(n) {
return n << 0 === n;
};
/**
* Returns the nth element of the given list or string. If n is negative the
* element at index length + n is returned.
*
* @func
* @memberOf R
* @since v0.1.0
* @category List
* @sig Number -> [a] -> a | Undefined
* @sig Number -> String -> String
* @param {Number} offset
* @param {*} list
* @return {*}
* @example
*
* const list = ['foo', 'bar', 'baz', 'quux'];
* R.nth(1, list); //=> 'bar'
* R.nth(-1, list); //=> 'quux'
* R.nth(-99, list); //=> undefined
*
* R.nth(2, 'abc'); //=> 'c'
* R.nth(3, 'abc'); //=> ''
* @symb R.nth(-1, [a, b, c]) = c
* @symb R.nth(0, [a, b, c]) = a
* @symb R.nth(1, [a, b, c]) = b
*/
var nth = /*#__PURE__*/_curry2(function nth(offset, list) {
var idx = offset < 0 ? list.length + offset : offset;
return _isString(list) ? list.charAt(idx) : list[idx];
});
var nth$1 = nth;
/**
* Retrieves the values at given paths of an object.
*
* @func
* @memberOf R
* @since v0.27.1
* @category Object
* @typedefn Idx = [String | Int]
* @sig [Idx] -> {a} -> [a | Undefined]
* @param {Array} pathsArray The array of paths to be fetched.
* @param {Object} obj The object to retrieve the nested properties from.
* @return {Array} A list consisting of values at paths specified by "pathsArray".
* @see R.path
* @example
*
* R.paths([['a', 'b'], ['p', 0, 'q']], {a: {b: 2}, p: [{q: 3}]}); //=> [2, 3]
* R.paths([['a', 'b'], ['p', 'r']], {a: {b: 2}, p: [{q: 3}]}); //=> [2, undefined]
*/
var paths = /*#__PURE__*/_curry2(function paths(pathsArray, obj) {
return pathsArray.map(function (paths) {
var val = obj;
var idx = 0;
var p;
while (idx < paths.length) {
if (val == null) {
return;
}
p = paths[idx];
val = _isInteger(p) ? nth$1(p, val) : val[p];
idx += 1;
}
return val;
});
});
var paths$1 = paths;
/**
* Retrieve the value at a given path.
*
* @func
* @memberOf R
* @since v0.2.0
* @category Object
* @typedefn Idx = String | Int
* @sig [Idx] -> {a} -> a | Undefined
* @param {Array} path The path to use.
* @param {Object} obj The object to retrieve the nested property from.
* @return {*} The data at `path`.
* @see R.prop, R.nth
* @example
*
* R.path(['a', 'b'], {a: {b: 2}}); //=> 2
* R.path(['a', 'b'], {c: {b: 2}}); //=> undefined
* R.path(['a', 'b', 0], {a: {b: [1, 2, 3]}}); //=> 1
* R.path(['a', 'b', -2], {a: {b: [1, 2, 3]}}); //=> 2
*/
var path = /*#__PURE__*/_curry2(function path(pathAr, obj) {
return paths$1([pathAr], obj)[0];
});
var rPath = path;
/**
* Makes a shallow clone of an object, setting or overriding the specified
* property with the given value. Note that this copies and flattens prototype
* properties onto the new object as well. All non-primitive properties are
* copied by reference.
*
* @func
* @memberOf R
* @since v0.8.0
* @category Object
* @sig String -> a -> {k: v} -> {k: v}
* @param {String} prop The property name to set
* @param {*} val The new value
* @param {Object} obj The object to clone
* @return {Object} A new object equivalent to the original except for the changed property.
* @see R.dissoc, R.pick
* @example
*
* R.assoc('c', 3, {a: 1, b: 2}); //=> {a: 1, b: 2, c: 3}
*/
var assoc = /*#__PURE__*/_curry3(function assoc(prop, val, obj) {
var result = {};
for (var p in obj) {
result[p] = obj[p];
}
result[prop] = val;
return result;
});
var assoc$1 = assoc;
/**
* Checks if the input value is `null` or `undefined`.
*
* @func
* @memberOf R
* @since v0.9.0
* @category Type
* @sig * -> Boolean
* @param {*} x The value to test.
* @return {Boolean} `true` if `x` is `undefined` or `null`, otherwise `false`.
* @example
*
* R.isNil(null); //=> true
* R.isNil(undefined); //=> true
* R.isNil(0); //=> false
* R.isNil([]); //=> false
*/
var isNil = /*#__PURE__*/_curry1(function isNil(x) {
return x == null;
});
var isNil$1 = isNil;
/**
* Makes a shallow clone of an object, setting or overriding the nodes required
* to create the given path, and placing the specific value at the tail end of
* that path. Note that this copies and flattens prototype properties onto the
* new object as well. All non-primitive properties are copied by reference.
*
* @func
* @memberOf R
* @since v0.8.0
* @category Object
* @typedefn Idx = String | Int
* @sig [Idx] -> a -> {a} -> {a}
* @param {Array} path the path to set
* @param {*} val The new value
* @param {Object} obj The object to clone
* @return {Object} A new object equivalent to the original except along the specified path.
* @see R.dissocPath
* @example
*
* R.assocPath(['a', 'b', 'c'], 42, {a: {b: {c: 0}}}); //=> {a: {b: {c: 42}}}
*
* // Any missing or non-object keys in path will be overridden
* R.assocPath(['a', 'b', 'c'], 42, {a: 5}); //=> {a: {b: {c: 42}}}
*/
var assocPath = /*#__PURE__*/_curry3(function assocPath(path, val, obj) {
if (path.length === 0) {
return val;
}
var idx = path[0];
if (path.length > 1) {
var nextObj = !isNil$1(obj) && _has(idx, obj) ? obj[idx] : _isInteger(path[1]) ? [] : {};
val = assocPath(Array.prototype.slice.call(path, 1), val, nextObj);
}
if (_isInteger(idx) && _isArray(obj)) {
var arr = [].concat(obj);
arr[idx] = val;
return arr;
} else {
return assoc$1(idx, val, obj);
}
});
var assocPath$1 = assocPath;
/**
* Returns a curried equivalent of the provided function. The curried function
* has two unusual capabilities. First, its arguments needn't be provided one
* at a time. If `f` is a ternary function and `g` is `R.curry(f)`, the
* following are equivalent:
*
* - `g(1)(2)(3)`
* - `g(1)(2, 3)`
* - `g(1, 2)(3)`
* - `g(1, 2, 3)`
*
* Secondly, the special placeholder value [`R.__`](#__) may be used to specify
* "gaps", allowing partial application of any combination of arguments,
* regardless of their positions. If `g` is as above and `_` is [`R.__`](#__),
* the following are equivalent:
*
* - `g(1, 2, 3)`
* - `g(_, 2, 3)(1)`
* - `g(_, _, 3)(1)(2)`
* - `g(_, _, 3)(1, 2)`
* - `g(_, 2)(1)(3)`
* - `g(_, 2)(1, 3)`
* - `g(_, 2)(_, 3)(1)`
*
* @func
* @memberOf R
* @since v0.1.0
* @category Function
* @sig (* -> a) -> (* -> a)
* @param {Function} fn The function to curry.
* @return {Function} A new, curried function.
* @see R.curryN, R.partial
* @example
*
* const addFourNumbers = (a, b, c, d) => a + b + c + d;
*
* const curriedAddFourNumbers = R.curry(addFourNumbers);
* const f = curriedAddFourNumbers(1, 2);
* const g = f(3);
* g(4); //=> 10
*/
var curry = /*#__PURE__*/_curry1(function curry(fn) {
return curryN$1(fn.length, fn);
});
var curry$1 = curry;
var TOKEN_HASH = '@t!@#$%^&*_+/.><,';
var normalizeBuffer = function normalizeBuffer(buffer) {
var numericBuffer = +buffer;
if (!Number.isNaN(numericBuffer)) {
return numericBuffer;
}
return buffer;
};
var parseIt = function parseIt(value) {
if (value === 'true') {
return true;
}
if (value === 'false') {
return false;
}
if (value === 'undefined') {
return undefined;
}
if (value === 'null') {
return null;
}
var parsedToNumeric = +value;
if (!Number.isNaN(parsedToNumeric)) {
return parsedToNumeric;
} // If a string.
if (['\'', '"', '`'].some(function (x) {
return value[0] === x && value[value.length - 1] === x;
})) {
return value.slice(1, value.length - 1);
}
return value;
};
var EQUALITY_SYMBOLS = {
'!=': function _(x, y) {
return x !== y;
},
'=': function _(x, y) {
return x === y;
},
'>': function _(x, y) {
return x > y;
},
'>=': function _(x, y) {
return x >= y;
},
'<': function _(x, y) {
return x < y;
},
'<=': function _(x, y) {
return x <= y;
}
};
var resolvePath = function resolvePath(unResolvedPath, object) {
var path = [];
var i = 0;
var buffer = '';
var conditions = [];
var isCacheablePath = true;
var conditionIndex = 0;
var isUserInput = false;
var isGreedyQuery = false;
var _loop = function _loop() {
var isLast = i === unResolvedPath.length - 1;
var token = unResolvedPath[i];
var nextToken = unResolvedPath[i + 1];
var normalizedBuffer = normalizeBuffer(buffer);
var preValueArray = void 0;
var arrayIndex = void 0;
var satisfyTheQuery = function satisfyTheQuery(item) {
return conditions.every(function (_ref) {
var logicSymbol = _ref.logicSymbol,
prop = _ref.prop,
value = _ref.value;
var operator = EQUALITY_SYMBOLS[logicSymbol];
return operator(item[prop], value);
});
};
var getGreedyPaths = function getGreedyPaths() {
var preValueArray = rPath(path, object) || [];
var ids = preValueArray.reduce(function (acc, item, idx) {
if (satisfyTheQuery(item)) {
return [].concat(_toConsumableArray(acc), [idx]);
}
return acc;
}, []);
if (ids.length === 0) {
return {
isGreedy: true,
notExist: true
};
} else {
var finalPaths = [];
var results = ids.map(function (id) {
// When we've such a greedy query:
// `array*[id=1].friends[name="Alex"]`
// and this query match multiple items in the array
// then we need to grab the ids and duplicate the update among all of them.
// In this code we reach the point where we resolve this query to:
//
// `array.0.friends*[name="Alex"]`
// `array.1.friends*[name="Alex"]`
//
// and then we want to send all of them back to the resolvePath in order
// to continue with the next conditional path.
// Some sort of recursive solution.
//
// In the next phase the second greedy query will be resolved as well.
// `array.0.friends.3`
// `array.0.friends.5`
// `array.1.friends.4`
// `array.1.friends.8`
//
var newPath = path.join('.');
var restOfPath = unResolvedPath.slice(i + 1);
if (path.length > 0) {
newPath += '.';
}
newPath += id;
if (restOfPath[i] !== '.') {
newPath += '.';
}
newPath += restOfPath;
return resolvePath(newPath, object);
});
results.forEach(function (_ref2) {
var path = _ref2.path,
notExist = _ref2.notExist,
paths = _ref2.paths;
if (notExist) {
return;
}
if (path) {
finalPaths.push(path);
}
if (paths) {
finalPaths = finalPaths.concat(paths);
}
});
return {
isGreedy: true,
notExist: finalPaths.length === 0,
paths: finalPaths
};
}
};
var isTokenHash = token === TOKEN_HASH[0] && unResolvedPath.slice(i, TOKEN_HASH.length + i) === TOKEN_HASH;
if (isTokenHash) {
if (!isUserInput) {
isUserInput = true; // Skip token hash
i += TOKEN_HASH.length;
return "continue";
} else {
isUserInput = false; // Skip token hash
i += TOKEN_HASH.length;
return "continue";
}
} // While being in token hash then add to buffer and continue to next loop.
if (isUserInput) {
buffer += token;
i++;
return "continue";
}
switch (token) {
case '.':
if (buffer) {
path.push(normalizedBuffer);
}
if (isGreedyQuery) {
return {
v: getGreedyPaths()
};
}
isGreedyQuery = false; // Reset conditions state
conditions = [];
conditionIndex = 0;
buffer = '';
break;
case '[':
isCacheablePath = false;
if (buffer) {
path.push(normalizedBuffer);
}
buffer = '';
break;
case '!':
case '=':
case '>':
case '<':
isCacheablePath = false;
conditions[conditionIndex] = {
prop: buffer,
logicSymbol: token
};
if (token === '>' && nextToken === '=') {
conditions[conditionIndex].logicSymbol = '>='; // Skip next token
i++;
}
if (token === '<' && nextToken === '=') {
conditions[conditionIndex].logicSymbol = '<='; // Skip next token
i++;
}
if (token === '!' && nextToken === '=') {
conditions[conditionIndex].logicSymbol = '!='; // Skip next token
i++;
}
buffer = '';
break;
case '*':
isCacheablePath = false;
isGreedyQuery = true;
if (isLast) {
return {
v: getGreedyPaths()
};
}
break;
case ']':
isCacheablePath = false;
if (!conditions[conditionIndex].value) {
conditions[conditionIndex].value = parseIt(buffer);
}
if (nextToken === '[') {
conditionIndex++;
buffer = ''; // Skip next token and move iterator to the next
i += 2;
return "continue";
}
preValueArray = rPath(path, object) || [];
if (isGreedyQuery) {
return {
v: getGreedyPaths()
};
}
arrayIndex = preValueArray.findIndex(satisfyTheQuery);
if (arrayIndex === -1) {
return {
v: {
path,
notExist: true
}
};
}
path.push(arrayIndex);
buffer = ''; // Reset conditions state
conditions = [];
conditionIndex = 0;
break;
default:
buffer += token;
if (isLast) {
path.push(normalizeBuffer(buffer));
}
break;
}
i++;
};
while (i < unResolvedPath.length) {
var _ret = _loop();
if (_ret === "continue") continue;
if (typeof _ret === "object") return _ret.v;
}
return {
path,
isCacheablePath
};
};
var shallowEqual = shallowequal;
var pathResolverCache = new Map();
var cachedResolvePath = function cachedResolvePath(unResolvedPath, object) {
var isPathResolutionCached = pathResolverCache.has(unResolvedPath);
if (isPathResolutionCached) {
return pathResolverCache.get(unResolvedPath);
}
var resolved;
try {
resolved = resolvePath(unResolvedPath, object);
} catch (err) {
throw new Error("Golden Path :: Error while resolving the path \"".concat(unResolvedPath, "\" - Please check the Golden Path Syntax"));
}
var _resolved = resolved,
isCacheablePath = _resolved.isCacheablePath,
resolvedPathConfig = _objectWithoutProperties(_resolved, ["isCacheablePath"]);
if (isCacheablePath) {
pathResolverCache.set(unResolvedPath, resolvedPathConfig);
}
return resolvedPathConfig;
};
var update = curry$1(function (unResolvedPath, value, object) {
var _cachedResolvePath = cachedResolvePath(unResolvedPath, object),
path = _cachedResolvePath.path,
paths = _cachedResolvePath.paths,
notExist = _cachedResolvePath.notExist;
if (notExist) {
return object;
}
if (path && !paths) {
paths = [path];
}
var objectResult = object;
var newVal = value;
if (paths) {
paths.forEach(function (p) {
if (typeof value === 'function') {
newVal = value(rPath(p, object));
}
var isSameValue = shallowEqual(rPath(p, objectResult), newVal);
if (isSameValue) {
return;
}
objectResult = assocPath$1(p, newVal, objectResult);
});
}
return objectResult;
});
var weakMap = new WeakMap();
var EMPTY_ARRAY = [];
Object.freeze(EMPTY_ARRAY);
var get = curry$1(function (unResolvedPath, object) {
var objectsWeakMap = weakMap.get(object);
if (objectsWeakMap) {
var isValueCached = objectsWeakMap.has(unResolvedPath);
if (isValueCached) {
return objectsWeakMap.get(unResolvedPath);
}
}
var value = function () {
var _cachedResolvePath2 = cachedResolvePath(unResolvedPath, object),
path = _cachedResolvePath2.path,
paths = _cachedResolvePath2.paths,
notExist = _cachedResolvePath2.notExist,
isGreedy = _cachedResolvePath2.isGreedy;
if (notExist) {
return isGreedy ? EMPTY_ARRAY : undefined;
}
if (path) {
return rPath(path, object);
}
if (paths) {
return paths.map(function (p) {
return rPath(p, object);
});
}
}();
if (!objectsWeakMap) {
if (typeof object === 'object' && !!object) {
var map = new Map();
map.set(unResolvedPath, value);
weakMap.set(object, map);
}
} else {
objectsWeakMap.set(unResolvedPath, value);
}
return value;
});
var v = function v(value) {
return "".concat(TOKEN_HASH).concat(value).concat(TOKEN_HASH);
};
var clearPathResolverCache = function clearPathResolverCache() {
return pathResolverCache.clear();
};
exports.TOKEN_HASH = TOKEN_HASH;
exports.clearPathResolverCache = clearPathResolverCache;
exports.get = get;
exports.update = update;
exports.v = v;