@vuex-orm/core
Version:
The Vuex plugin to enable Object-Relational Mapping access to the Vuex Store.
1,678 lines (1,502 loc) • 185 kB
JavaScript
function createCommonjsModule(fn, basedir, module) {
return module = {
path: basedir,
exports: {},
require: function (path, base) {
return commonjsRequire(path, (base === undefined || base === null) ? module.path : base);
}
}, fn(module, module.exports), module.exports;
}
function commonjsRequire () {
throw new Error('Dynamic requires are not currently supported by @rollup/plugin-commonjs');
}
var _global = createCommonjsModule(function (module) {
// https://github.com/zloirock/core-js/issues/86#issuecomment-115759028
var global = module.exports = typeof window != 'undefined' && window.Math == Math
? window : typeof self != 'undefined' && self.Math == Math ? self
// eslint-disable-next-line no-new-func
: Function('return this')();
if (typeof __g == 'number') __g = global; // eslint-disable-line no-undef
});
var _core = createCommonjsModule(function (module) {
var core = module.exports = { version: '2.6.12' };
if (typeof __e == 'number') __e = core; // eslint-disable-line no-undef
});
var _isObject = function (it) {
return typeof it === 'object' ? it !== null : typeof it === 'function';
};
var _anObject = function (it) {
if (!_isObject(it)) throw TypeError(it + ' is not an object!');
return it;
};
var _fails = function (exec) {
try {
return !!exec();
} catch (e) {
return true;
}
};
// Thank's IE8 for his funny defineProperty
var _descriptors = !_fails(function () {
return Object.defineProperty({}, 'a', { get: function () { return 7; } }).a != 7;
});
var document$1 = _global.document;
// typeof document.createElement is 'object' in old IE
var is = _isObject(document$1) && _isObject(document$1.createElement);
var _domCreate = function (it) {
return is ? document$1.createElement(it) : {};
};
var _ie8DomDefine = !_descriptors && !_fails(function () {
return Object.defineProperty(_domCreate('div'), 'a', { get: function () { return 7; } }).a != 7;
});
// 7.1.1 ToPrimitive(input [, PreferredType])
// instead of the ES6 spec version, we didn't implement @@toPrimitive case
// and the second argument - flag - preferred type is a string
var _toPrimitive = function (it, S) {
if (!_isObject(it)) return it;
var fn, val;
if (S && typeof (fn = it.toString) == 'function' && !_isObject(val = fn.call(it))) return val;
if (typeof (fn = it.valueOf) == 'function' && !_isObject(val = fn.call(it))) return val;
if (!S && typeof (fn = it.toString) == 'function' && !_isObject(val = fn.call(it))) return val;
throw TypeError("Can't convert object to primitive value");
};
var dP = Object.defineProperty;
var f$2 = _descriptors ? Object.defineProperty : function defineProperty(O, P, Attributes) {
_anObject(O);
P = _toPrimitive(P, true);
_anObject(Attributes);
if (_ie8DomDefine) try {
return dP(O, P, Attributes);
} catch (e) { /* empty */ }
if ('get' in Attributes || 'set' in Attributes) throw TypeError('Accessors not supported!');
if ('value' in Attributes) O[P] = Attributes.value;
return O;
};
var _objectDp = {
f: f$2
};
var _propertyDesc = function (bitmap, value) {
return {
enumerable: !(bitmap & 1),
configurable: !(bitmap & 2),
writable: !(bitmap & 4),
value: value
};
};
var _hide = _descriptors ? function (object, key, value) {
return _objectDp.f(object, key, _propertyDesc(1, value));
} : function (object, key, value) {
object[key] = value;
return object;
};
var hasOwnProperty = {}.hasOwnProperty;
var _has = function (it, key) {
return hasOwnProperty.call(it, key);
};
var id = 0;
var px = Math.random();
var _uid = function (key) {
return 'Symbol('.concat(key === undefined ? '' : key, ')_', (++id + px).toString(36));
};
var _shared = createCommonjsModule(function (module) {
var SHARED = '__core-js_shared__';
var store = _global[SHARED] || (_global[SHARED] = {});
(module.exports = function (key, value) {
return store[key] || (store[key] = value !== undefined ? value : {});
})('versions', []).push({
version: _core.version,
mode: 'global',
copyright: '© 2020 Denis Pushkarev (zloirock.ru)'
});
});
var _functionToString = _shared('native-function-to-string', Function.toString);
var _redefine = createCommonjsModule(function (module) {
var SRC = _uid('src');
var TO_STRING = 'toString';
var TPL = ('' + _functionToString).split(TO_STRING);
_core.inspectSource = function (it) {
return _functionToString.call(it);
};
(module.exports = function (O, key, val, safe) {
var isFunction = typeof val == 'function';
if (isFunction) _has(val, 'name') || _hide(val, 'name', key);
if (O[key] === val) return;
if (isFunction) _has(val, SRC) || _hide(val, SRC, O[key] ? '' + O[key] : TPL.join(String(key)));
if (O === _global) {
O[key] = val;
} else if (!safe) {
delete O[key];
_hide(O, key, val);
} else if (O[key]) {
O[key] = val;
} else {
_hide(O, key, val);
}
// add fake Function#toString for correct work wrapped methods / constructors with methods like LoDash isNative
})(Function.prototype, TO_STRING, function toString() {
return typeof this == 'function' && this[SRC] || _functionToString.call(this);
});
});
var _aFunction = function (it) {
if (typeof it != 'function') throw TypeError(it + ' is not a function!');
return it;
};
// optional / simple context binding
var _ctx = function (fn, that, length) {
_aFunction(fn);
if (that === undefined) return fn;
switch (length) {
case 1: return function (a) {
return fn.call(that, a);
};
case 2: return function (a, b) {
return fn.call(that, a, b);
};
case 3: return function (a, b, c) {
return fn.call(that, a, b, c);
};
}
return function (/* ...args */) {
return fn.apply(that, arguments);
};
};
var PROTOTYPE$1 = 'prototype';
var $export = function (type, name, source) {
var IS_FORCED = type & $export.F;
var IS_GLOBAL = type & $export.G;
var IS_STATIC = type & $export.S;
var IS_PROTO = type & $export.P;
var IS_BIND = type & $export.B;
var target = IS_GLOBAL ? _global : IS_STATIC ? _global[name] || (_global[name] = {}) : (_global[name] || {})[PROTOTYPE$1];
var exports = IS_GLOBAL ? _core : _core[name] || (_core[name] = {});
var expProto = exports[PROTOTYPE$1] || (exports[PROTOTYPE$1] = {});
var key, own, out, exp;
if (IS_GLOBAL) source = name;
for (key in source) {
// contains in native
own = !IS_FORCED && target && target[key] !== undefined;
// export native or passed
out = (own ? target : source)[key];
// bind timers to global for call from export context
exp = IS_BIND && own ? _ctx(out, _global) : IS_PROTO && typeof out == 'function' ? _ctx(Function.call, out) : out;
// extend global
if (target) _redefine(target, key, out, type & $export.U);
// export
if (exports[key] != out) _hide(exports, key, exp);
if (IS_PROTO && expProto[key] != out) expProto[key] = out;
}
};
_global.core = _core;
// type bitmap
$export.F = 1; // forced
$export.G = 2; // global
$export.S = 4; // static
$export.P = 8; // proto
$export.B = 16; // bind
$export.W = 32; // wrap
$export.U = 64; // safe
$export.R = 128; // real proto method for `library`
var _export = $export;
var toString = {}.toString;
var _cof = function (it) {
return toString.call(it).slice(8, -1);
};
// fallback for non-array-like ES3 and non-enumerable old V8 strings
// eslint-disable-next-line no-prototype-builtins
var _iobject = Object('z').propertyIsEnumerable(0) ? Object : function (it) {
return _cof(it) == 'String' ? it.split('') : Object(it);
};
// 7.2.1 RequireObjectCoercible(argument)
var _defined = function (it) {
if (it == undefined) throw TypeError("Can't call method on " + it);
return it;
};
// to indexed object, toObject with fallback for non-array-like ES3 strings
var _toIobject = function (it) {
return _iobject(_defined(it));
};
// 7.1.4 ToInteger
var ceil = Math.ceil;
var floor = Math.floor;
var _toInteger = function (it) {
return isNaN(it = +it) ? 0 : (it > 0 ? floor : ceil)(it);
};
// 7.1.15 ToLength
var min$1 = Math.min;
var _toLength = function (it) {
return it > 0 ? min$1(_toInteger(it), 0x1fffffffffffff) : 0; // pow(2, 53) - 1 == 9007199254740991
};
var max = Math.max;
var min = Math.min;
var _toAbsoluteIndex = function (index, length) {
index = _toInteger(index);
return index < 0 ? max(index + length, 0) : min(index, length);
};
// false -> Array#indexOf
// true -> Array#includes
var _arrayIncludes = function (IS_INCLUDES) {
return function ($this, el, fromIndex) {
var O = _toIobject($this);
var length = _toLength(O.length);
var index = _toAbsoluteIndex(fromIndex, length);
var value;
// Array#includes uses SameValueZero equality algorithm
// eslint-disable-next-line no-self-compare
if (IS_INCLUDES && el != el) while (length > index) {
value = O[index++];
// eslint-disable-next-line no-self-compare
if (value != value) return true;
// Array#indexOf ignores holes, Array#includes - not
} else for (;length > index; index++) if (IS_INCLUDES || index in O) {
if (O[index] === el) return IS_INCLUDES || index || 0;
} return !IS_INCLUDES && -1;
};
};
var _wks = createCommonjsModule(function (module) {
var store = _shared('wks');
var Symbol = _global.Symbol;
var USE_SYMBOL = typeof Symbol == 'function';
var $exports = module.exports = function (name) {
return store[name] || (store[name] =
USE_SYMBOL && Symbol[name] || (USE_SYMBOL ? Symbol : _uid)('Symbol.' + name));
};
$exports.store = store;
});
// 22.1.3.31 Array.prototype[@@unscopables]
var UNSCOPABLES = _wks('unscopables');
var ArrayProto$1 = Array.prototype;
if (ArrayProto$1[UNSCOPABLES] == undefined) _hide(ArrayProto$1, UNSCOPABLES, {});
var _addToUnscopables = function (key) {
ArrayProto$1[UNSCOPABLES][key] = true;
};
// https://github.com/tc39/Array.prototype.includes
var $includes = _arrayIncludes(true);
_export(_export.P, 'Array', {
includes: function includes(el /* , fromIndex = 0 */) {
return $includes(this, el, arguments.length > 1 ? arguments[1] : undefined);
}
});
_addToUnscopables('includes');
_core.Array.includes;
var shared = _shared('keys');
var _sharedKey = function (key) {
return shared[key] || (shared[key] = _uid(key));
};
var arrayIndexOf = _arrayIncludes(false);
var IE_PROTO$2 = _sharedKey('IE_PROTO');
var _objectKeysInternal = function (object, names) {
var O = _toIobject(object);
var i = 0;
var result = [];
var key;
for (key in O) if (key != IE_PROTO$2) _has(O, key) && result.push(key);
// Don't enum bug & hidden keys
while (names.length > i) if (_has(O, key = names[i++])) {
~arrayIndexOf(result, key) || result.push(key);
}
return result;
};
// IE 8- don't enum bug keys
var _enumBugKeys = (
'constructor,hasOwnProperty,isPrototypeOf,propertyIsEnumerable,toLocaleString,toString,valueOf'
).split(',');
// 19.1.2.14 / 15.2.3.14 Object.keys(O)
var _objectKeys = Object.keys || function keys(O) {
return _objectKeysInternal(O, _enumBugKeys);
};
var f$1 = Object.getOwnPropertySymbols;
var _objectGops = {
f: f$1
};
var f = {}.propertyIsEnumerable;
var _objectPie = {
f: f
};
// 7.1.13 ToObject(argument)
var _toObject = function (it) {
return Object(_defined(it));
};
// 19.1.2.1 Object.assign(target, source, ...)
var $assign = Object.assign;
// should work with symbols and should have deterministic property order (V8 bug)
var _objectAssign = !$assign || _fails(function () {
var A = {};
var B = {};
// eslint-disable-next-line no-undef
var S = Symbol();
var K = 'abcdefghijklmnopqrst';
A[S] = 7;
K.split('').forEach(function (k) { B[k] = k; });
return $assign({}, A)[S] != 7 || Object.keys($assign({}, B)).join('') != K;
}) ? function assign(target, source) { // eslint-disable-line no-unused-vars
var T = _toObject(target);
var aLen = arguments.length;
var index = 1;
var getSymbols = _objectGops.f;
var isEnum = _objectPie.f;
while (aLen > index) {
var S = _iobject(arguments[index++]);
var keys = getSymbols ? _objectKeys(S).concat(getSymbols(S)) : _objectKeys(S);
var length = keys.length;
var j = 0;
var key;
while (length > j) {
key = keys[j++];
if (!_descriptors || isEnum.call(S, key)) T[key] = S[key];
}
} return T;
} : $assign;
// 19.1.3.1 Object.assign(target, source)
_export(_export.S + _export.F, 'Object', { assign: _objectAssign });
_core.Object.assign;
var isEnum = _objectPie.f;
var _objectToArray = function (isEntries) {
return function (it) {
var O = _toIobject(it);
var keys = _objectKeys(O);
var length = keys.length;
var i = 0;
var result = [];
var key;
while (length > i) {
key = keys[i++];
if (!_descriptors || isEnum.call(O, key)) {
result.push(isEntries ? [key, O[key]] : O[key]);
}
}
return result;
};
};
// https://github.com/tc39/proposal-object-values-entries
var $entries = _objectToArray(true);
_export(_export.S, 'Object', {
entries: function entries(it) {
return $entries(it);
}
});
_core.Object.entries;
// https://github.com/tc39/proposal-object-values-entries
var $values = _objectToArray(false);
_export(_export.S, 'Object', {
values: function values(it) {
return $values(it);
}
});
_core.Object.values;
// 7.2.8 IsRegExp(argument)
var MATCH$1 = _wks('match');
var _isRegexp = function (it) {
var isRegExp;
return _isObject(it) && ((isRegExp = it[MATCH$1]) !== undefined ? !!isRegExp : _cof(it) == 'RegExp');
};
// helper for String#{startsWith, endsWith, includes}
var _stringContext = function (that, searchString, NAME) {
if (_isRegexp(searchString)) throw TypeError('String#' + NAME + " doesn't accept regex!");
return String(_defined(that));
};
var MATCH = _wks('match');
var _failsIsRegexp = function (KEY) {
var re = /./;
try {
'/./'[KEY](re);
} catch (e) {
try {
re[MATCH] = false;
return !'/./'[KEY](re);
} catch (f) { /* empty */ }
} return true;
};
var STARTS_WITH = 'startsWith';
var $startsWith = ''[STARTS_WITH];
_export(_export.P + _export.F * _failsIsRegexp(STARTS_WITH), 'String', {
startsWith: function startsWith(searchString /* , position = 0 */) {
var that = _stringContext(this, searchString, STARTS_WITH);
var index = _toLength(Math.min(arguments.length > 1 ? arguments[1] : undefined, that.length));
var search = String(searchString);
return $startsWith
? $startsWith.call(that, search, index)
: that.slice(index, index + search.length) === search;
}
});
_core.String.startsWith;
// true -> String#at
// false -> String#codePointAt
var _stringAt = function (TO_STRING) {
return function (that, pos) {
var s = String(_defined(that));
var i = _toInteger(pos);
var l = s.length;
var a, b;
if (i < 0 || i >= l) return TO_STRING ? '' : undefined;
a = s.charCodeAt(i);
return a < 0xd800 || a > 0xdbff || i + 1 === l || (b = s.charCodeAt(i + 1)) < 0xdc00 || b > 0xdfff
? TO_STRING ? s.charAt(i) : a
: TO_STRING ? s.slice(i, i + 2) : (a - 0xd800 << 10) + (b - 0xdc00) + 0x10000;
};
};
var _iterators = {};
var _objectDps = _descriptors ? Object.defineProperties : function defineProperties(O, Properties) {
_anObject(O);
var keys = _objectKeys(Properties);
var length = keys.length;
var i = 0;
var P;
while (length > i) _objectDp.f(O, P = keys[i++], Properties[P]);
return O;
};
var document = _global.document;
var _html = document && document.documentElement;
// 19.1.2.2 / 15.2.3.5 Object.create(O [, Properties])
var IE_PROTO$1 = _sharedKey('IE_PROTO');
var Empty = function () { /* empty */ };
var PROTOTYPE = 'prototype';
// Create object with fake `null` prototype: use iframe Object with cleared prototype
var createDict = function () {
// Thrash, waste and sodomy: IE GC bug
var iframe = _domCreate('iframe');
var i = _enumBugKeys.length;
var lt = '<';
var gt = '>';
var iframeDocument;
iframe.style.display = 'none';
_html.appendChild(iframe);
iframe.src = 'javascript:'; // eslint-disable-line no-script-url
// createDict = iframe.contentWindow.Object;
// html.removeChild(iframe);
iframeDocument = iframe.contentWindow.document;
iframeDocument.open();
iframeDocument.write(lt + 'script' + gt + 'document.F=Object' + lt + '/script' + gt);
iframeDocument.close();
createDict = iframeDocument.F;
while (i--) delete createDict[PROTOTYPE][_enumBugKeys[i]];
return createDict();
};
var _objectCreate = Object.create || function create(O, Properties) {
var result;
if (O !== null) {
Empty[PROTOTYPE] = _anObject(O);
result = new Empty();
Empty[PROTOTYPE] = null;
// add "__proto__" for Object.getPrototypeOf polyfill
result[IE_PROTO$1] = O;
} else result = createDict();
return Properties === undefined ? result : _objectDps(result, Properties);
};
var def = _objectDp.f;
var TAG$1 = _wks('toStringTag');
var _setToStringTag = function (it, tag, stat) {
if (it && !_has(it = stat ? it : it.prototype, TAG$1)) def(it, TAG$1, { configurable: true, value: tag });
};
var IteratorPrototype = {};
// 25.1.2.1.1 %IteratorPrototype%[@@iterator]()
_hide(IteratorPrototype, _wks('iterator'), function () { return this; });
var _iterCreate = function (Constructor, NAME, next) {
Constructor.prototype = _objectCreate(IteratorPrototype, { next: _propertyDesc(1, next) });
_setToStringTag(Constructor, NAME + ' Iterator');
};
// 19.1.2.9 / 15.2.3.2 Object.getPrototypeOf(O)
var IE_PROTO = _sharedKey('IE_PROTO');
var ObjectProto = Object.prototype;
var _objectGpo = Object.getPrototypeOf || function (O) {
O = _toObject(O);
if (_has(O, IE_PROTO)) return O[IE_PROTO];
if (typeof O.constructor == 'function' && O instanceof O.constructor) {
return O.constructor.prototype;
} return O instanceof Object ? ObjectProto : null;
};
var ITERATOR$3 = _wks('iterator');
var BUGGY = !([].keys && 'next' in [].keys()); // Safari has buggy iterators w/o `next`
var FF_ITERATOR = '@@iterator';
var KEYS = 'keys';
var VALUES = 'values';
var returnThis = function () { return this; };
var _iterDefine = function (Base, NAME, Constructor, next, DEFAULT, IS_SET, FORCED) {
_iterCreate(Constructor, NAME, next);
var getMethod = function (kind) {
if (!BUGGY && kind in proto) return proto[kind];
switch (kind) {
case KEYS: return function keys() { return new Constructor(this, kind); };
case VALUES: return function values() { return new Constructor(this, kind); };
} return function entries() { return new Constructor(this, kind); };
};
var TAG = NAME + ' Iterator';
var DEF_VALUES = DEFAULT == VALUES;
var VALUES_BUG = false;
var proto = Base.prototype;
var $native = proto[ITERATOR$3] || proto[FF_ITERATOR] || DEFAULT && proto[DEFAULT];
var $default = $native || getMethod(DEFAULT);
var $entries = DEFAULT ? !DEF_VALUES ? $default : getMethod('entries') : undefined;
var $anyNative = NAME == 'Array' ? proto.entries || $native : $native;
var methods, key, IteratorPrototype;
// Fix native
if ($anyNative) {
IteratorPrototype = _objectGpo($anyNative.call(new Base()));
if (IteratorPrototype !== Object.prototype && IteratorPrototype.next) {
// Set @@toStringTag to native iterators
_setToStringTag(IteratorPrototype, TAG, true);
// fix for some old engines
if (typeof IteratorPrototype[ITERATOR$3] != 'function') _hide(IteratorPrototype, ITERATOR$3, returnThis);
}
}
// fix Array#{values, @@iterator}.name in V8 / FF
if (DEF_VALUES && $native && $native.name !== VALUES) {
VALUES_BUG = true;
$default = function values() { return $native.call(this); };
}
// Define iterator
if ((BUGGY || VALUES_BUG || !proto[ITERATOR$3])) {
_hide(proto, ITERATOR$3, $default);
}
// Plug for library
_iterators[NAME] = $default;
_iterators[TAG] = returnThis;
if (DEFAULT) {
methods = {
values: DEF_VALUES ? $default : getMethod(VALUES),
keys: IS_SET ? $default : getMethod(KEYS),
entries: $entries
};
if (FORCED) for (key in methods) {
if (!(key in proto)) _redefine(proto, key, methods[key]);
} else _export(_export.P + _export.F * (BUGGY || VALUES_BUG), NAME, methods);
}
return methods;
};
var $at = _stringAt(true);
// 21.1.3.27 String.prototype[@@iterator]()
_iterDefine(String, 'String', function (iterated) {
this._t = String(iterated); // target
this._i = 0; // next index
// 21.1.5.2.1 %StringIteratorPrototype%.next()
}, function () {
var O = this._t;
var index = this._i;
var point;
if (index >= O.length) return { value: undefined, done: true };
point = $at(O, index);
this._i += point.length;
return { value: point, done: false };
});
// call something on iterator step with safe closing on error
var _iterCall = function (iterator, fn, value, entries) {
try {
return entries ? fn(_anObject(value)[0], value[1]) : fn(value);
// 7.4.6 IteratorClose(iterator, completion)
} catch (e) {
var ret = iterator['return'];
if (ret !== undefined) _anObject(ret.call(iterator));
throw e;
}
};
// check on default Array iterator
var ITERATOR$2 = _wks('iterator');
var ArrayProto = Array.prototype;
var _isArrayIter = function (it) {
return it !== undefined && (_iterators.Array === it || ArrayProto[ITERATOR$2] === it);
};
var _createProperty = function (object, index, value) {
if (index in object) _objectDp.f(object, index, _propertyDesc(0, value));
else object[index] = value;
};
// getting tag from 19.1.3.6 Object.prototype.toString()
var TAG = _wks('toStringTag');
// ES3 wrong here
var ARG = _cof(function () { return arguments; }()) == 'Arguments';
// fallback for IE11 Script Access Denied error
var tryGet = function (it, key) {
try {
return it[key];
} catch (e) { /* empty */ }
};
var _classof = function (it) {
var O, T, B;
return it === undefined ? 'Undefined' : it === null ? 'Null'
// @@toStringTag case
: typeof (T = tryGet(O = Object(it), TAG)) == 'string' ? T
// builtinTag case
: ARG ? _cof(O)
// ES3 arguments fallback
: (B = _cof(O)) == 'Object' && typeof O.callee == 'function' ? 'Arguments' : B;
};
var ITERATOR$1 = _wks('iterator');
var core_getIteratorMethod = _core.getIteratorMethod = function (it) {
if (it != undefined) return it[ITERATOR$1]
|| it['@@iterator']
|| _iterators[_classof(it)];
};
var ITERATOR = _wks('iterator');
var SAFE_CLOSING = false;
try {
var riter = [7][ITERATOR]();
riter['return'] = function () { SAFE_CLOSING = true; };
// eslint-disable-next-line no-throw-literal
Array.from(riter, function () { throw 2; });
} catch (e) { /* empty */ }
var _iterDetect = function (exec, skipClosing) {
if (!skipClosing && !SAFE_CLOSING) return false;
var safe = false;
try {
var arr = [7];
var iter = arr[ITERATOR]();
iter.next = function () { return { done: safe = true }; };
arr[ITERATOR] = function () { return iter; };
exec(arr);
} catch (e) { /* empty */ }
return safe;
};
_export(_export.S + _export.F * !_iterDetect(function (iter) { Array.from(iter); }), 'Array', {
// 22.1.2.1 Array.from(arrayLike, mapfn = undefined, thisArg = undefined)
from: function from(arrayLike /* , mapfn = undefined, thisArg = undefined */) {
var O = _toObject(arrayLike);
var C = typeof this == 'function' ? this : Array;
var aLen = arguments.length;
var mapfn = aLen > 1 ? arguments[1] : undefined;
var mapping = mapfn !== undefined;
var index = 0;
var iterFn = core_getIteratorMethod(O);
var length, result, step, iterator;
if (mapping) mapfn = _ctx(mapfn, aLen > 2 ? arguments[2] : undefined, 2);
// if object isn't iterable or it's array with default iterator - use simple case
if (iterFn != undefined && !(C == Array && _isArrayIter(iterFn))) {
for (iterator = iterFn.call(O), result = new C(); !(step = iterator.next()).done; index++) {
_createProperty(result, index, mapping ? _iterCall(iterator, mapfn, [step.value, index], true) : step.value);
}
} else {
length = _toLength(O.length);
for (result = new C(length); length > index; index++) {
_createProperty(result, index, mapping ? mapfn(O[index], index) : O[index]);
}
}
result.length = index;
return result;
}
});
_core.Array.from;
// 7.2.2 IsArray(argument)
var _isArray = Array.isArray || function isArray(arg) {
return _cof(arg) == 'Array';
};
var SPECIES = _wks('species');
var _arraySpeciesConstructor = function (original) {
var C;
if (_isArray(original)) {
C = original.constructor;
// cross-realm fallback
if (typeof C == 'function' && (C === Array || _isArray(C.prototype))) C = undefined;
if (_isObject(C)) {
C = C[SPECIES];
if (C === null) C = undefined;
}
} return C === undefined ? Array : C;
};
// 9.4.2.3 ArraySpeciesCreate(originalArray, length)
var _arraySpeciesCreate = function (original, length) {
return new (_arraySpeciesConstructor(original))(length);
};
// 0 -> Array#forEach
// 1 -> Array#map
// 2 -> Array#filter
// 3 -> Array#some
// 4 -> Array#every
// 5 -> Array#find
// 6 -> Array#findIndex
var _arrayMethods = function (TYPE, $create) {
var IS_MAP = TYPE == 1;
var IS_FILTER = TYPE == 2;
var IS_SOME = TYPE == 3;
var IS_EVERY = TYPE == 4;
var IS_FIND_INDEX = TYPE == 6;
var NO_HOLES = TYPE == 5 || IS_FIND_INDEX;
var create = $create || _arraySpeciesCreate;
return function ($this, callbackfn, that) {
var O = _toObject($this);
var self = _iobject(O);
var f = _ctx(callbackfn, that, 3);
var length = _toLength(self.length);
var index = 0;
var result = IS_MAP ? create($this, length) : IS_FILTER ? create($this, 0) : undefined;
var val, res;
for (;length > index; index++) if (NO_HOLES || index in self) {
val = self[index];
res = f(val, index, O);
if (TYPE) {
if (IS_MAP) result[index] = res; // map
else if (res) switch (TYPE) {
case 3: return true; // some
case 5: return val; // find
case 6: return index; // findIndex
case 2: result.push(val); // filter
} else if (IS_EVERY) return false; // every
}
}
return IS_FIND_INDEX ? -1 : IS_SOME || IS_EVERY ? IS_EVERY : result;
};
};
// 22.1.3.8 Array.prototype.find(predicate, thisArg = undefined)
var $find = _arrayMethods(5);
var KEY = 'find';
var forced = true;
// Shouldn't skip holes
if (KEY in []) Array(1)[KEY](function () { forced = false; });
_export(_export.P + _export.F * forced, 'Array', {
find: function find(callbackfn /* , that = undefined */) {
return $find(this, callbackfn, arguments.length > 1 ? arguments[1] : undefined);
}
});
_addToUnscopables(KEY);
_core.Array.find;
class Container {
/**
* Register the store instance.
*/
static register(store) {
this.store = store;
}
}
var install = (database, options = {}) => {
const namespace = options.namespace || 'entities';
return (store) => {
database.start(store, namespace);
Container.register(store);
};
};
/**
* Check if the given value is the type of array.
*/
function isArray(value) {
return Array.isArray(value);
}
/**
* Gets the size of collection by returning its length for array-like values
* or the number of own enumerable string keyed properties for objects.
*/
function size(collection) {
return isArray(collection)
? collection.length
: Object.keys(collection).length;
}
/**
* Check if the given array or object is empty.
*/
function isEmpty(collection) {
return size(collection) === 0;
}
/**
* Iterates over own enumerable string keyed properties of an object and
* invokes `iteratee` for each property.
*/
function forOwn(object, iteratee) {
Object.keys(object).forEach((key) => iteratee(object[key], key, object));
}
/**
* Creates an array of values by running each element in collection thru
* iteratee. The iteratee is invoked with three arguments:
* (value, key, collection).
*/
function map(object, iteratee) {
const result = [];
for (const key in object) {
result.push(iteratee(object[key], key, object));
}
return result;
}
/**
* Creates an object with the same keys as object and values generated by
* running each own enumerable string keyed property of object thru
* iteratee. The iteratee is invoked with three arguments:
* (value, key, object).
*/
function mapValues(object, iteratee) {
const newObject = Object.assign({}, object);
return Object.keys(object).reduce((records, key) => {
records[key] = iteratee(object[key], key, object);
return records;
}, newObject);
}
/**
* Creates an object composed of keys generated from the results of running
* each element of collection by the given key.
*/
function keyBy(collection, key) {
const o = {};
collection.forEach((item) => {
o[item[key]] = item;
});
return o;
}
/**
* Creates an array of elements, sorted in specified order by the results
* of running each element in a collection thru each iteratee.
*/
function orderBy(collection, iteratees, directions) {
let index = -1;
const result = collection.map((value) => {
const criteria = iteratees.map((iteratee) => {
return typeof iteratee === 'function' ? iteratee(value) : value[iteratee];
});
return { criteria, index: ++index, value };
});
return baseSortBy(result, (object, other) => {
return compareMultiple(object, other, directions);
});
}
/**
* Creates an array of elements, sorted in ascending order by the results of
* running each element in a collection thru each iteratee. This method
* performs a stable sort, that is, it preserves the original sort order
* of equal elements.
*/
function baseSortBy(array, comparer) {
let length = array.length;
array.sort(comparer);
const newArray = [];
while (length--) {
newArray[length] = array[length].value;
}
return newArray;
}
/**
* Used by `orderBy` to compare multiple properties of a value to another
* and stable sort them.
*
* If `orders` is unspecified, all values are sorted in ascending order.
* Otherwise, specify an order of "desc" for descending or "asc" for
* ascending sort order of corresponding values.
*/
function compareMultiple(object, other, orders) {
let index = -1;
const objCriteria = object.criteria;
const othCriteria = other.criteria;
const length = objCriteria.length;
const ordersLength = orders.length;
while (++index < length) {
const result = compareAscending(objCriteria[index], othCriteria[index]);
if (result) {
if (index >= ordersLength) {
return result;
}
const order = orders[index];
return result * (order === 'desc' ? -1 : 1);
}
}
return object.index - other.index;
}
/**
* Compares values to sort them in ascending order.
*/
function compareAscending(value, other) {
if (value !== other) {
const valIsDefined = value !== undefined;
const valIsNull = value === null;
const valIsReflexive = value === value;
const othIsDefined = other !== undefined;
const othIsNull = other === null;
const othIsReflexive = other === other;
if (typeof value !== 'number' || typeof other !== 'number') {
value = String(value);
other = String(other);
}
if ((!othIsNull && value > other) ||
(valIsNull && othIsDefined && othIsReflexive) ||
(!valIsDefined && othIsReflexive) ||
!valIsReflexive) {
return 1;
}
if ((!valIsNull && value < other) ||
(othIsNull && valIsDefined && valIsReflexive) ||
(!othIsDefined && valIsReflexive) ||
!othIsReflexive) {
return -1;
}
}
return 0;
}
/**
* Creates an object composed of keys generated from the results of running
* each element of collection thru iteratee.
*/
function groupBy(collection, iteratee) {
return collection.reduce((records, record) => {
const key = iteratee(record);
if (records[key] === undefined) {
records[key] = [];
}
records[key].push(record);
return records;
}, {});
}
/**
* Deep clone the given target object.
*/
function cloneDeep(target) {
if (target === null) {
return target;
}
if (isArray(target)) {
const cp = [];
target.forEach((v) => cp.push(v));
return cp.map((n) => cloneDeep(n));
}
if (typeof target === 'object' && target !== {}) {
const cp = { ...target };
Object.keys(cp).forEach((k) => (cp[k] = cloneDeep(cp[k])));
return cp;
}
return target;
}
var Utils = {
isArray,
size,
isEmpty,
forOwn,
map,
mapValues,
keyBy,
orderBy,
groupBy,
cloneDeep
};
class Uid$1 {
/**
* Generate an UUID.
*/
static make() {
this.count++;
return `${this.prefix}${this.count}`;
}
/**
* Reset the count to 0.
*/
static reset() {
this.count = 0;
}
}
/**
* Count to create a unique id.
*/
Uid$1.count = 0;
/**
* Prefix string to be used for the id.
*/
Uid$1.prefix = '$uid';
class Attribute {
/**
* Create a new attribute instance.
*/
constructor(model) {
this.model = model;
}
}
class Type extends Attribute {
/**
* Create a new type instance.
*/
constructor(model, value, mutator) {
super(model); /* istanbul ignore next */
/**
* Whether if the attribute can accept `null` as a value.
*/
this.isNullable = false;
this.value = value;
this.mutator = mutator;
}
/**
* Set `isNullable` to be `true`.
*/
nullable() {
this.isNullable = true;
return this;
}
/**
* Mutate the given value by mutator.
*/
mutate(value, key) {
const mutator = this.mutator || this.model.mutators()[key];
return mutator ? mutator(value) : value;
}
}
class Attr extends Type {
/**
* Create a new attr instance.
*/
constructor(model, value, mutator) {
/* istanbul ignore next */
super(model, value, mutator);
}
/**
* Make value to be set to model property. This method is used when
* instantiating a model or creating a plain object from a model.
*/
make(value, _parent, key) {
value = value !== undefined ? value : this.value;
// Default Value might be a function (taking no parameter).
let localValue = value;
if (typeof value === 'function') {
localValue = value();
}
return this.mutate(localValue, key);
}
}
class String$1 extends Type {
/**
* Create a new string instance.
*/
constructor(model, value, mutator) {
/* istanbul ignore next */
super(model, value, mutator);
}
/**
* Convert given value to the appropriate value for the attribute.
*/
make(value, _parent, key) {
return this.mutate(this.fix(value), key);
}
/**
* Convert given value to the string.
*/
fix(value) {
if (value === undefined) {
return this.value;
}
if (typeof value === 'string') {
return value;
}
if (value === null && this.isNullable) {
return value;
}
return value + '';
}
}
class Number extends Type {
/**
* Create a new number instance.
*/
constructor(model, value, mutator) {
/* istanbul ignore next */
super(model, value, mutator);
}
/**
* Convert given value to the appropriate value for the attribute.
*/
make(value, _parent, key) {
return this.mutate(this.fix(value), key);
}
/**
* Transform given data to the number.
*/
fix(value) {
if (value === undefined) {
return this.value;
}
if (typeof value === 'number') {
return value;
}
if (typeof value === 'string') {
return parseFloat(value);
}
if (typeof value === 'boolean') {
return value ? 1 : 0;
}
if (value === null && this.isNullable) {
return value;
}
return 0;
}
}
class Boolean extends Type {
/**
* Create a new number instance.
*/
constructor(model, value, mutator) {
/* istanbul ignore next */
super(model, value, mutator);
}
/**
* Convert given value to the appropriate value for the attribute.
*/
make(value, _parent, key) {
return this.mutate(this.fix(value), key);
}
/**
* Transform given data to the boolean.
*/
fix(value) {
if (value === undefined) {
return this.value;
}
if (typeof value === 'boolean') {
return value;
}
if (typeof value === 'string') {
if (value.length === 0) {
return false;
}
const int = parseInt(value, 0);
return isNaN(int) ? true : !!int;
}
if (typeof value === 'number') {
return !!value;
}
if (value === null && this.isNullable) {
return value;
}
return false;
}
}
class Uid extends Type {
/**
* Create a new uid instance.
*/
constructor(model, value) {
/* istanbul ignore next */
super(model, value);
}
/**
* Convert given value to the appropriate value for the attribute.
*/
make(value) {
if (typeof value === 'number' || typeof value === 'string') {
return value;
}
if (typeof this.value === 'function') {
return this.value();
}
return Uid$1.make();
}
}
class Relation extends Attribute {
/**
* Get relation query instance with constraint attached.
*/
getRelation(query, name, constraints) {
const relation = query.newQuery(name);
constraints.forEach((constraint) => {
constraint(relation);
});
return relation;
}
/**
* Get specified keys from the given collection.
*/
getKeys(collection, key) {
return collection.reduce((models, model) => {
if (model[key] === null || model[key] === undefined) {
return models;
}
models.push(model[key]);
return models;
}, []);
}
/**
* Create a new indexed map for the single relation by specified key.
*/
mapSingleRelations(collection, key) {
const relations = new Map();
collection.forEach((record) => {
const id = record[key];
!relations.get(id) && relations.set(id, record);
});
return relations;
}
/**
* Create a new indexed map for the many relation by specified key.
*/
mapManyRelations(collection, key) {
const relations = new Map();
collection.forEach((record) => {
const id = record[key];
let ownerKeys = relations.get(id);
if (!ownerKeys) {
ownerKeys = [];
relations.set(id, ownerKeys);
}
ownerKeys.push(record);
});
return relations;
}
/**
* Create a new indexed map for relations with order constraints.
*/
mapRelationsByOrders(collection, relations, ownerKey, relationKey) {
const records = {};
relations.forEach((related, id) => {
collection
.filter((record) => record[relationKey] === id)
.forEach((record) => {
const id = record[ownerKey];
if (!records[id]) {
records[id] = [];
}
records[id] = records[id].concat(related);
});
});
return records;
}
/**
* Check if the given record is a single relation, which is an object.
*/
isOneRelation(record) {
if (!isArray(record) && record !== null && typeof record === 'object') {
return true;
}
return false;
}
/**
* Check if the given records is a many relation, which is an array
* of object.
*/
isManyRelation(records) {
if (!isArray(records)) {
return false;
}
if (records.length < 1) {
return false;
}
return true;
}
/**
* Wrap the given object into a model instance.
*/
makeOneRelation(record, model) {
if (!this.isOneRelation(record)) {
return null;
}
const relatedModel = model.getModelFromRecord(record) || model;
return new relatedModel(record);
}
/**
* Wrap the given records into a collection of model instances.
*/
makeManyRelation(records, model) {
if (!this.isManyRelation(records)) {
return [];
}
return records
.filter((record) => {
return this.isOneRelation(record);
})
.map((record) => {
const relatedModel = model.getModelFromRecord(record) || model;
return new relatedModel(record);
});
}
}
class HasOne extends Relation {
/**
* Create a new has one instance.
*/
constructor(model, related, foreignKey, localKey) {
super(model); /* istanbul ignore next */
this.related = this.model.relation(related);
this.foreignKey = foreignKey;
this.localKey = localKey;
}
/**
* Define the normalizr schema for the relationship.
*/
define(schema) {
return schema.one(this.related);
}
/**
* Attach the relational key to the related data. For example,
* when User has one Phone, it will attach value to the
* `user_id` field of Phone record.
*/
attach(key, record, data) {
// Check if the record has local key set. If not, set the local key to be
// the id value. This happens if the user defines the custom local key
// and didn't include it in the data being normalized.
if (!record[this.localKey]) {
record[this.localKey] = this.model.getIndexIdFromRecord(record);
}
// Then set the foreign key of the related record if it exists to be the
// local key of this record.
const related = data[this.related.entity] && data[this.related.entity][key];
if (related) {
related[this.foreignKey] = record[this.localKey];
}
}
/**
* Make value to be set to model property. This method is used when
* instantiating a model or creating a plain object from a model.
*/
make(value, _parent, _key) {
return this.makeOneRelation(value, this.related);
}
/**
* Load the has one relationship for the collection.
*/
load(query, collection, name, constraints) {
const relation = this.getRelation(query, this.related.entity, constraints);
this.addEagerConstraints(relation, collection);
this.match(collection, relation.get(), name);
}
/**
* Set the constraints for an eager load of the relation.
*/
addEagerConstraints(relation, collection) {
relation.whereFk(this.foreignKey, this.getKeys(collection, this.localKey));
}
/**
* Match the eagerly loaded results to their parents.
*/
match(collection, relations, name) {
const dictionary = this.buildDictionary(relations);
collection.forEach((model) => {
const id = model[this.localKey];
const relation = dictionary[id];
model[name] = relation || null;
});
}
/**
* Build model dictionary keyed by the relation's foreign key.
*/
buildDictionary(relations) {
return relations.reduce((dictionary, relation) => {
const key = relation[this.foreignKey];
dictionary[key] = relation;
return dictionary;
}, {});
}
}
class BelongsTo extends Relation {
/**
* Create a new belongs to instance.
*/
constructor(model, parent, foreignKey, ownerKey) {
super(model); /* istanbul ignore next */
this.parent = this.model.relation(parent);
this.foreignKey = foreignKey;
this.ownerKey = ownerKey;
}
/**
* Define the normalizr schema for the relationship.
*/
define(schema) {
return schema.one(this.parent);
}
/**
* Attach the relational key to the given data. For example, when Post
* belongs to User, it will attach value to the `user_id` field of
* Post record.
*/
attach(key, record, data) {
// See if the record has the foreign key, if yes, it means the user has
// provided the key explicitly so do nothing and return.
if (record[this.foreignKey] !== undefined) {
return;
}
// If there is no foreign key, let's set it here.
record[this.foreignKey] =
data[this.parent.entity] && data[this.parent.entity][key]
? data[this.parent.entity][key][this.ownerKey]
: key;
}
/**
* Convert given value to the appropriate value for the attribute.
*/
make(value, _parent, _key) {
return this.makeOneRelation(value, this.parent);
}
/**
* Load the belongs to relationship for the collection.
*/
load(query, collection, name, constraints) {
const relation = this.getRelation(query, this.parent.entity, constraints);
this.addEagerConstraints(relation, collection);
this.match(collection, relation.get(), name);
}
/**
* Set the constraints for an eager load of the relation.
*/
addEagerConstraints(relation, collection) {
relation.whereFk(this.ownerKey, this.getKeys(collection, this.foreignKey));
}
/**
* Match the eagerly loaded results to their parents.
*/
match(collection, relations, name) {
const dictionary = this.buildDictionary(relations);
collection.forEach((model) => {
const id = model[this.foreignKey];
const relation = id !== null ? dictionary[id] : null;
model[name] = relation || null;
});
}
/**
* Build model dictionary keyed by the relation's foreign key.
*/
buildDictionary(relations) {
return relations.reduce((dictionary, relation) => {
const key = relation[this.ownerKey];
dictionary[key] = relation;
return dictionary;
}, {});
}
}
class HasMany extends Relation {
/**
* Create a new has many instance.
*/
constructor(model, related, foreignKey, localKey) {
super(model); /* istanbul ignore next */
this.related = this.model.relation(related);
this.foreignKey = foreignKey;
this.localKey = localKey;
}
/**
* Define the normalizr schema for the relationship.
*/
define(schema) {
return schema.many(this.related);
}
/**
* Attach the relational key to the given data.
*/
attach(key, record, data) {
key.forEach((index) => {
const related = data[this.related.entity];
if (!related ||
!related[index] ||
related[index][this.foreignKey] !== undefined) {
return;
}
related[index][this.foreignKey] = record[this.localKey];
});
}
/**
* Convert given value to the appropriate value for the attribute.
*/
make(value, _parent, _key) {
return this.makeManyRelation(value, this.related);
}
/**
* Load the has many relationship for the collection.
*/
load(query, collection, name, constraints) {
const relation = this.getRelation(query, this.related.entity, constraints);
this.addEagerConstraints(relation, collection);
this.match(collection, relation.get(), name);
}
/**
* Set the constraints for an eager load of the relation.
*/
addEagerConstraints(relation, collection) {
relation.whereFk(this.foreignKey, this.getKeys(collection, this.localKey));
}
/**
* Match the eagerly loaded results to their parents.
*/
match(collection, relations, name) {
const dictionary = this.buildDictionary(relations);
collection.forEach((model) => {
const id = model[this.localKey];
const relation = dictionary[id];
model[name] = relation || [];
});
}
/**
* Build model dictionary keyed by the relation's foreign key.
*/
buildDictionary(relations) {
return relations.reduce((diction