vue-laravel-crud 1.4.7 → 1.4.8

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.
@@ -6179,11 +6179,11 @@ function bind(fn, thisArg) {
6179
6179
 
6180
6180
  // utils is a library of generic helper functions non-specific to axios
6181
6181
 
6182
- const {toString: toString$1} = Object.prototype;
6182
+ const {toString: toString$2} = Object.prototype;
6183
6183
  const {getPrototypeOf} = Object;
6184
6184
 
6185
6185
  const kindOf = (cache => thing => {
6186
- const str = toString$1.call(thing);
6186
+ const str = toString$2.call(thing);
6187
6187
  return cache[str] || (cache[str] = str.slice(8, -1).toLowerCase());
6188
6188
  })(Object.create(null));
6189
6189
 
@@ -6201,7 +6201,7 @@ const typeOfTest = type => thing => typeof thing === type;
6201
6201
  *
6202
6202
  * @returns {boolean} True if value is an Array, otherwise false
6203
6203
  */
6204
- const {isArray: isArray$1} = Array;
6204
+ const {isArray: isArray$2} = Array;
6205
6205
 
6206
6206
  /**
6207
6207
  * Determine if a value is undefined
@@ -6366,7 +6366,7 @@ const isFormData = (thing) => {
6366
6366
  const pattern = '[object FormData]';
6367
6367
  return thing && (
6368
6368
  (typeof FormData === 'function' && thing instanceof FormData) ||
6369
- toString$1.call(thing) === pattern ||
6369
+ toString$2.call(thing) === pattern ||
6370
6370
  (isFunction(thing.toString) && thing.toString() === pattern)
6371
6371
  );
6372
6372
  };
@@ -6420,7 +6420,7 @@ function forEach(obj, fn, {allOwnKeys = false} = {}) {
6420
6420
  obj = [obj];
6421
6421
  }
6422
6422
 
6423
- if (isArray$1(obj)) {
6423
+ if (isArray$2(obj)) {
6424
6424
  // Iterate over array values
6425
6425
  for (i = 0, l = obj.length; i < l; i++) {
6426
6426
  fn.call(null, obj[i], i, obj);
@@ -6452,13 +6452,13 @@ function findKey(obj, key) {
6452
6452
  return null;
6453
6453
  }
6454
6454
 
6455
- const _global = (() => {
6455
+ const _global$1 = (() => {
6456
6456
  /*eslint no-undef:0*/
6457
6457
  if (typeof globalThis !== "undefined") return globalThis;
6458
6458
  return typeof self !== "undefined" ? self : (typeof window !== 'undefined' ? window : global$1)
6459
6459
  })();
6460
6460
 
6461
- const isContextDefined = (context) => !isUndefined(context) && context !== _global;
6461
+ const isContextDefined = (context) => !isUndefined(context) && context !== _global$1;
6462
6462
 
6463
6463
  /**
6464
6464
  * Accepts varargs expecting each argument to be an object, then
@@ -6487,7 +6487,7 @@ function merge(/* obj1, obj2, obj3, ... */) {
6487
6487
  result[targetKey] = merge(result[targetKey], val);
6488
6488
  } else if (isPlainObject(val)) {
6489
6489
  result[targetKey] = merge({}, val);
6490
- } else if (isArray$1(val)) {
6490
+ } else if (isArray$2(val)) {
6491
6491
  result[targetKey] = val.slice();
6492
6492
  } else {
6493
6493
  result[targetKey] = val;
@@ -6617,7 +6617,7 @@ const endsWith = (str, searchString, position) => {
6617
6617
  */
6618
6618
  const toArray = (thing) => {
6619
6619
  if (!thing) return null;
6620
- if (isArray$1(thing)) return thing;
6620
+ if (isArray$2(thing)) return thing;
6621
6621
  let i = thing.length;
6622
6622
  if (!isNumber(i)) return null;
6623
6623
  const arr = new Array(i);
@@ -6695,7 +6695,7 @@ const toCamelCase = str => {
6695
6695
  };
6696
6696
 
6697
6697
  /* Creating a function that will check if an object has a property. */
6698
- const hasOwnProperty = (({hasOwnProperty}) => (obj, prop) => hasOwnProperty.call(obj, prop))(Object.prototype);
6698
+ const hasOwnProperty$1 = (({hasOwnProperty}) => (obj, prop) => hasOwnProperty.call(obj, prop))(Object.prototype);
6699
6699
 
6700
6700
  /**
6701
6701
  * Determine if a value is a RegExp object
@@ -6759,7 +6759,7 @@ const toObjectSet = (arrayOrString, delimiter) => {
6759
6759
  });
6760
6760
  };
6761
6761
 
6762
- isArray$1(arrayOrString) ? define(arrayOrString) : define(String(arrayOrString).split(delimiter));
6762
+ isArray$2(arrayOrString) ? define(arrayOrString) : define(String(arrayOrString).split(delimiter));
6763
6763
 
6764
6764
  return obj;
6765
6765
  };
@@ -6814,7 +6814,7 @@ const toJSONObject = (obj) => {
6814
6814
 
6815
6815
  if(!('toJSON' in source)) {
6816
6816
  stack[i] = source;
6817
- const target = isArray$1(source) ? [] : {};
6817
+ const target = isArray$2(source) ? [] : {};
6818
6818
 
6819
6819
  forEach(source, (value, key) => {
6820
6820
  const reducedValue = visit(value, i + 1);
@@ -6834,7 +6834,7 @@ const toJSONObject = (obj) => {
6834
6834
  };
6835
6835
 
6836
6836
  var utils = {
6837
- isArray: isArray$1,
6837
+ isArray: isArray$2,
6838
6838
  isArrayBuffer,
6839
6839
  isBuffer: isBuffer$1,
6840
6840
  isFormData,
@@ -6868,8 +6868,8 @@ var utils = {
6868
6868
  forEachEntry,
6869
6869
  matchAll,
6870
6870
  isHTMLForm,
6871
- hasOwnProperty,
6872
- hasOwnProp: hasOwnProperty, // an alias to avoid ESLint no-prototype-builtins detection
6871
+ hasOwnProperty: hasOwnProperty$1,
6872
+ hasOwnProp: hasOwnProperty$1, // an alias to avoid ESLint no-prototype-builtins detection
6873
6873
  reduceDescriptors,
6874
6874
  freezeMethods,
6875
6875
  toObjectSet,
@@ -6877,7 +6877,7 @@ var utils = {
6877
6877
  noop,
6878
6878
  toFiniteNumber,
6879
6879
  findKey,
6880
- global: _global,
6880
+ global: _global$1,
6881
6881
  isContextDefined,
6882
6882
  ALPHABET,
6883
6883
  generateString,
@@ -7080,10 +7080,10 @@ function write (buffer, value, offset, isLE, mLen, nBytes) {
7080
7080
  buffer[offset + i - d] |= s * 128;
7081
7081
  }
7082
7082
 
7083
- var toString = {}.toString;
7083
+ var toString$1 = {}.toString;
7084
7084
 
7085
- var isArray = Array.isArray || function (arr) {
7086
- return toString.call(arr) == '[object Array]';
7085
+ var isArray$1 = Array.isArray || function (arr) {
7086
+ return toString$1.call(arr) == '[object Array]';
7087
7087
  };
7088
7088
 
7089
7089
  /*!
@@ -7364,7 +7364,7 @@ function fromObject (that, obj) {
7364
7364
  return fromArrayLike(that, obj)
7365
7365
  }
7366
7366
 
7367
- if (obj.type === 'Buffer' && isArray(obj.data)) {
7367
+ if (obj.type === 'Buffer' && isArray$1(obj.data)) {
7368
7368
  return fromArrayLike(that, obj.data)
7369
7369
  }
7370
7370
  }
@@ -7429,7 +7429,7 @@ Buffer.isEncoding = function isEncoding (encoding) {
7429
7429
  };
7430
7430
 
7431
7431
  Buffer.concat = function concat (list, length) {
7432
- if (!isArray(list)) {
7432
+ if (!isArray$1(list)) {
7433
7433
  throw new TypeError('"list" argument must be an Array of Buffers')
7434
7434
  }
7435
7435
 
@@ -7751,7 +7751,7 @@ function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
7751
7751
  if (val.length === 0) {
7752
7752
  return -1
7753
7753
  }
7754
- return arrayIndexOf(buffer, val, byteOffset, encoding, dir)
7754
+ return arrayIndexOf$1(buffer, val, byteOffset, encoding, dir)
7755
7755
  } else if (typeof val === 'number') {
7756
7756
  val = val & 0xFF; // Search for a byte value [0-255]
7757
7757
  if (Buffer.TYPED_ARRAY_SUPPORT &&
@@ -7762,13 +7762,13 @@ function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
7762
7762
  return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset)
7763
7763
  }
7764
7764
  }
7765
- return arrayIndexOf(buffer, [ val ], byteOffset, encoding, dir)
7765
+ return arrayIndexOf$1(buffer, [ val ], byteOffset, encoding, dir)
7766
7766
  }
7767
7767
 
7768
7768
  throw new TypeError('val must be string, number or Buffer')
7769
7769
  }
7770
7770
 
7771
- function arrayIndexOf (arr, val, byteOffset, encoding, dir) {
7771
+ function arrayIndexOf$1 (arr, val, byteOffset, encoding, dir) {
7772
7772
  var indexSize = 1;
7773
7773
  var arrLength = arr.length;
7774
7774
  var valLength = val.length;
@@ -11324,7 +11324,7 @@ axios.HttpStatusCode = HttpStatusCode;
11324
11324
 
11325
11325
  axios.default = axios;
11326
11326
 
11327
- function commonjsRequire(path) {
11327
+ function commonjsRequire$1(path) {
11328
11328
  throw new Error('Could not dynamically require "' + path + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.');
11329
11329
  }
11330
11330
 
@@ -13426,7 +13426,7 @@ var moment$1 = {
13426
13426
  ) {
13427
13427
  try {
13428
13428
  oldLocale = globalLocale._abbr;
13429
- aliasedRequire = commonjsRequire;
13429
+ aliasedRequire = commonjsRequire$1;
13430
13430
  aliasedRequire('./locale/' + name);
13431
13431
  getSetGlobalLocale(oldLocale);
13432
13432
  } catch (e) {
@@ -17015,9 +17015,3157 @@ var moment$1 = {
17015
17015
 
17016
17016
  var moment = momentExports;
17017
17017
 
17018
+ function createCommonjsModule(fn, basedir, module) {
17019
+ return module = {
17020
+ path: basedir,
17021
+ exports: {},
17022
+ require: function (path, base) {
17023
+ return commonjsRequire(path, (base === undefined || base === null) ? module.path : base);
17024
+ }
17025
+ }, fn(module, module.exports), module.exports;
17026
+ }
17027
+
17028
+ function commonjsRequire () {
17029
+ throw new Error('Dynamic requires are not currently supported by @rollup/plugin-commonjs');
17030
+ }
17031
+
17032
+ var _global = createCommonjsModule(function (module) {
17033
+ // https://github.com/zloirock/core-js/issues/86#issuecomment-115759028
17034
+ var global = module.exports = typeof window != 'undefined' && window.Math == Math
17035
+ ? window : typeof self != 'undefined' && self.Math == Math ? self
17036
+ // eslint-disable-next-line no-new-func
17037
+ : Function('return this')();
17038
+ if (typeof __g == 'number') __g = global; // eslint-disable-line no-undef
17039
+ });
17040
+
17041
+ var _core = createCommonjsModule(function (module) {
17042
+ var core = module.exports = { version: '2.6.12' };
17043
+ if (typeof __e == 'number') __e = core; // eslint-disable-line no-undef
17044
+ });
17045
+
17046
+ var _isObject = function (it) {
17047
+ return typeof it === 'object' ? it !== null : typeof it === 'function';
17048
+ };
17049
+
17050
+ var _anObject = function (it) {
17051
+ if (!_isObject(it)) throw TypeError(it + ' is not an object!');
17052
+ return it;
17053
+ };
17054
+
17055
+ var _fails = function (exec) {
17056
+ try {
17057
+ return !!exec();
17058
+ } catch (e) {
17059
+ return true;
17060
+ }
17061
+ };
17062
+
17063
+ // Thank's IE8 for his funny defineProperty
17064
+ var _descriptors = !_fails(function () {
17065
+ return Object.defineProperty({}, 'a', { get: function () { return 7; } }).a != 7;
17066
+ });
17067
+
17068
+ var document$1 = _global.document;
17069
+ // typeof document.createElement is 'object' in old IE
17070
+ var is = _isObject(document$1) && _isObject(document$1.createElement);
17071
+ var _domCreate = function (it) {
17072
+ return is ? document$1.createElement(it) : {};
17073
+ };
17074
+
17075
+ var _ie8DomDefine = !_descriptors && !_fails(function () {
17076
+ return Object.defineProperty(_domCreate('div'), 'a', { get: function () { return 7; } }).a != 7;
17077
+ });
17078
+
17079
+ // 7.1.1 ToPrimitive(input [, PreferredType])
17080
+
17081
+ // instead of the ES6 spec version, we didn't implement @@toPrimitive case
17082
+ // and the second argument - flag - preferred type is a string
17083
+ var _toPrimitive = function (it, S) {
17084
+ if (!_isObject(it)) return it;
17085
+ var fn, val;
17086
+ if (S && typeof (fn = it.toString) == 'function' && !_isObject(val = fn.call(it))) return val;
17087
+ if (typeof (fn = it.valueOf) == 'function' && !_isObject(val = fn.call(it))) return val;
17088
+ if (!S && typeof (fn = it.toString) == 'function' && !_isObject(val = fn.call(it))) return val;
17089
+ throw TypeError("Can't convert object to primitive value");
17090
+ };
17091
+
17092
+ var dP = Object.defineProperty;
17093
+
17094
+ var f$2 = _descriptors ? Object.defineProperty : function defineProperty(O, P, Attributes) {
17095
+ _anObject(O);
17096
+ P = _toPrimitive(P, true);
17097
+ _anObject(Attributes);
17098
+ if (_ie8DomDefine) try {
17099
+ return dP(O, P, Attributes);
17100
+ } catch (e) { /* empty */ }
17101
+ if ('get' in Attributes || 'set' in Attributes) throw TypeError('Accessors not supported!');
17102
+ if ('value' in Attributes) O[P] = Attributes.value;
17103
+ return O;
17104
+ };
17105
+
17106
+ var _objectDp = {
17107
+ f: f$2
17108
+ };
17109
+
17110
+ var _propertyDesc = function (bitmap, value) {
17111
+ return {
17112
+ enumerable: !(bitmap & 1),
17113
+ configurable: !(bitmap & 2),
17114
+ writable: !(bitmap & 4),
17115
+ value: value
17116
+ };
17117
+ };
17118
+
17119
+ var _hide = _descriptors ? function (object, key, value) {
17120
+ return _objectDp.f(object, key, _propertyDesc(1, value));
17121
+ } : function (object, key, value) {
17122
+ object[key] = value;
17123
+ return object;
17124
+ };
17125
+
17126
+ var hasOwnProperty = {}.hasOwnProperty;
17127
+ var _has = function (it, key) {
17128
+ return hasOwnProperty.call(it, key);
17129
+ };
17130
+
17131
+ var id = 0;
17132
+ var px = Math.random();
17133
+ var _uid = function (key) {
17134
+ return 'Symbol('.concat(key === undefined ? '' : key, ')_', (++id + px).toString(36));
17135
+ };
17136
+
17137
+ var _shared = createCommonjsModule(function (module) {
17138
+ var SHARED = '__core-js_shared__';
17139
+ var store = _global[SHARED] || (_global[SHARED] = {});
17140
+
17141
+ (module.exports = function (key, value) {
17142
+ return store[key] || (store[key] = value !== undefined ? value : {});
17143
+ })('versions', []).push({
17144
+ version: _core.version,
17145
+ mode: 'global',
17146
+ copyright: '© 2020 Denis Pushkarev (zloirock.ru)'
17147
+ });
17148
+ });
17149
+
17150
+ var _functionToString = _shared('native-function-to-string', Function.toString);
17151
+
17152
+ var _redefine = createCommonjsModule(function (module) {
17153
+ var SRC = _uid('src');
17154
+
17155
+ var TO_STRING = 'toString';
17156
+ var TPL = ('' + _functionToString).split(TO_STRING);
17157
+
17158
+ _core.inspectSource = function (it) {
17159
+ return _functionToString.call(it);
17160
+ };
17161
+
17162
+ (module.exports = function (O, key, val, safe) {
17163
+ var isFunction = typeof val == 'function';
17164
+ if (isFunction) _has(val, 'name') || _hide(val, 'name', key);
17165
+ if (O[key] === val) return;
17166
+ if (isFunction) _has(val, SRC) || _hide(val, SRC, O[key] ? '' + O[key] : TPL.join(String(key)));
17167
+ if (O === _global) {
17168
+ O[key] = val;
17169
+ } else if (!safe) {
17170
+ delete O[key];
17171
+ _hide(O, key, val);
17172
+ } else if (O[key]) {
17173
+ O[key] = val;
17174
+ } else {
17175
+ _hide(O, key, val);
17176
+ }
17177
+ // add fake Function#toString for correct work wrapped methods / constructors with methods like LoDash isNative
17178
+ })(Function.prototype, TO_STRING, function toString() {
17179
+ return typeof this == 'function' && this[SRC] || _functionToString.call(this);
17180
+ });
17181
+ });
17182
+
17183
+ var _aFunction = function (it) {
17184
+ if (typeof it != 'function') throw TypeError(it + ' is not a function!');
17185
+ return it;
17186
+ };
17187
+
17188
+ // optional / simple context binding
17189
+
17190
+ var _ctx = function (fn, that, length) {
17191
+ _aFunction(fn);
17192
+ if (that === undefined) return fn;
17193
+ switch (length) {
17194
+ case 1: return function (a) {
17195
+ return fn.call(that, a);
17196
+ };
17197
+ case 2: return function (a, b) {
17198
+ return fn.call(that, a, b);
17199
+ };
17200
+ case 3: return function (a, b, c) {
17201
+ return fn.call(that, a, b, c);
17202
+ };
17203
+ }
17204
+ return function (/* ...args */) {
17205
+ return fn.apply(that, arguments);
17206
+ };
17207
+ };
17208
+
17209
+ var PROTOTYPE$1 = 'prototype';
17210
+
17211
+ var $export = function (type, name, source) {
17212
+ var IS_FORCED = type & $export.F;
17213
+ var IS_GLOBAL = type & $export.G;
17214
+ var IS_STATIC = type & $export.S;
17215
+ var IS_PROTO = type & $export.P;
17216
+ var IS_BIND = type & $export.B;
17217
+ var target = IS_GLOBAL ? _global : IS_STATIC ? _global[name] || (_global[name] = {}) : (_global[name] || {})[PROTOTYPE$1];
17218
+ var exports = IS_GLOBAL ? _core : _core[name] || (_core[name] = {});
17219
+ var expProto = exports[PROTOTYPE$1] || (exports[PROTOTYPE$1] = {});
17220
+ var key, own, out, exp;
17221
+ if (IS_GLOBAL) source = name;
17222
+ for (key in source) {
17223
+ // contains in native
17224
+ own = !IS_FORCED && target && target[key] !== undefined;
17225
+ // export native or passed
17226
+ out = (own ? target : source)[key];
17227
+ // bind timers to global for call from export context
17228
+ exp = IS_BIND && own ? _ctx(out, _global) : IS_PROTO && typeof out == 'function' ? _ctx(Function.call, out) : out;
17229
+ // extend global
17230
+ if (target) _redefine(target, key, out, type & $export.U);
17231
+ // export
17232
+ if (exports[key] != out) _hide(exports, key, exp);
17233
+ if (IS_PROTO && expProto[key] != out) expProto[key] = out;
17234
+ }
17235
+ };
17236
+ _global.core = _core;
17237
+ // type bitmap
17238
+ $export.F = 1; // forced
17239
+ $export.G = 2; // global
17240
+ $export.S = 4; // static
17241
+ $export.P = 8; // proto
17242
+ $export.B = 16; // bind
17243
+ $export.W = 32; // wrap
17244
+ $export.U = 64; // safe
17245
+ $export.R = 128; // real proto method for `library`
17246
+ var _export = $export;
17247
+
17248
+ var toString = {}.toString;
17249
+
17250
+ var _cof = function (it) {
17251
+ return toString.call(it).slice(8, -1);
17252
+ };
17253
+
17254
+ // fallback for non-array-like ES3 and non-enumerable old V8 strings
17255
+
17256
+ // eslint-disable-next-line no-prototype-builtins
17257
+ var _iobject = Object('z').propertyIsEnumerable(0) ? Object : function (it) {
17258
+ return _cof(it) == 'String' ? it.split('') : Object(it);
17259
+ };
17260
+
17261
+ // 7.2.1 RequireObjectCoercible(argument)
17262
+ var _defined = function (it) {
17263
+ if (it == undefined) throw TypeError("Can't call method on " + it);
17264
+ return it;
17265
+ };
17266
+
17267
+ // to indexed object, toObject with fallback for non-array-like ES3 strings
17268
+
17269
+
17270
+ var _toIobject = function (it) {
17271
+ return _iobject(_defined(it));
17272
+ };
17273
+
17274
+ // 7.1.4 ToInteger
17275
+ var ceil = Math.ceil;
17276
+ var floor = Math.floor;
17277
+ var _toInteger = function (it) {
17278
+ return isNaN(it = +it) ? 0 : (it > 0 ? floor : ceil)(it);
17279
+ };
17280
+
17281
+ // 7.1.15 ToLength
17282
+
17283
+ var min$1 = Math.min;
17284
+ var _toLength = function (it) {
17285
+ return it > 0 ? min$1(_toInteger(it), 0x1fffffffffffff) : 0; // pow(2, 53) - 1 == 9007199254740991
17286
+ };
17287
+
17288
+ var max = Math.max;
17289
+ var min = Math.min;
17290
+ var _toAbsoluteIndex = function (index, length) {
17291
+ index = _toInteger(index);
17292
+ return index < 0 ? max(index + length, 0) : min(index, length);
17293
+ };
17294
+
17295
+ // false -> Array#indexOf
17296
+ // true -> Array#includes
17297
+
17298
+
17299
+
17300
+ var _arrayIncludes = function (IS_INCLUDES) {
17301
+ return function ($this, el, fromIndex) {
17302
+ var O = _toIobject($this);
17303
+ var length = _toLength(O.length);
17304
+ var index = _toAbsoluteIndex(fromIndex, length);
17305
+ var value;
17306
+ // Array#includes uses SameValueZero equality algorithm
17307
+ // eslint-disable-next-line no-self-compare
17308
+ if (IS_INCLUDES && el != el) while (length > index) {
17309
+ value = O[index++];
17310
+ // eslint-disable-next-line no-self-compare
17311
+ if (value != value) return true;
17312
+ // Array#indexOf ignores holes, Array#includes - not
17313
+ } else for (;length > index; index++) if (IS_INCLUDES || index in O) {
17314
+ if (O[index] === el) return IS_INCLUDES || index || 0;
17315
+ } return !IS_INCLUDES && -1;
17316
+ };
17317
+ };
17318
+
17319
+ var _wks = createCommonjsModule(function (module) {
17320
+ var store = _shared('wks');
17321
+
17322
+ var Symbol = _global.Symbol;
17323
+ var USE_SYMBOL = typeof Symbol == 'function';
17324
+
17325
+ var $exports = module.exports = function (name) {
17326
+ return store[name] || (store[name] =
17327
+ USE_SYMBOL && Symbol[name] || (USE_SYMBOL ? Symbol : _uid)('Symbol.' + name));
17328
+ };
17329
+
17330
+ $exports.store = store;
17331
+ });
17332
+
17333
+ // 22.1.3.31 Array.prototype[@@unscopables]
17334
+ var UNSCOPABLES = _wks('unscopables');
17335
+ var ArrayProto$1 = Array.prototype;
17336
+ if (ArrayProto$1[UNSCOPABLES] == undefined) _hide(ArrayProto$1, UNSCOPABLES, {});
17337
+ var _addToUnscopables = function (key) {
17338
+ ArrayProto$1[UNSCOPABLES][key] = true;
17339
+ };
17340
+
17341
+ // https://github.com/tc39/Array.prototype.includes
17342
+
17343
+ var $includes = _arrayIncludes(true);
17344
+
17345
+ _export(_export.P, 'Array', {
17346
+ includes: function includes(el /* , fromIndex = 0 */) {
17347
+ return $includes(this, el, arguments.length > 1 ? arguments[1] : undefined);
17348
+ }
17349
+ });
17350
+
17351
+ _addToUnscopables('includes');
17352
+
17353
+ _core.Array.includes;
17354
+
17355
+ var shared = _shared('keys');
17356
+
17357
+ var _sharedKey = function (key) {
17358
+ return shared[key] || (shared[key] = _uid(key));
17359
+ };
17360
+
17361
+ var arrayIndexOf = _arrayIncludes(false);
17362
+ var IE_PROTO$2 = _sharedKey('IE_PROTO');
17363
+
17364
+ var _objectKeysInternal = function (object, names) {
17365
+ var O = _toIobject(object);
17366
+ var i = 0;
17367
+ var result = [];
17368
+ var key;
17369
+ for (key in O) if (key != IE_PROTO$2) _has(O, key) && result.push(key);
17370
+ // Don't enum bug & hidden keys
17371
+ while (names.length > i) if (_has(O, key = names[i++])) {
17372
+ ~arrayIndexOf(result, key) || result.push(key);
17373
+ }
17374
+ return result;
17375
+ };
17376
+
17377
+ // IE 8- don't enum bug keys
17378
+ var _enumBugKeys = (
17379
+ 'constructor,hasOwnProperty,isPrototypeOf,propertyIsEnumerable,toLocaleString,toString,valueOf'
17380
+ ).split(',');
17381
+
17382
+ // 19.1.2.14 / 15.2.3.14 Object.keys(O)
17383
+
17384
+
17385
+
17386
+ var _objectKeys = Object.keys || function keys(O) {
17387
+ return _objectKeysInternal(O, _enumBugKeys);
17388
+ };
17389
+
17390
+ var f$1 = Object.getOwnPropertySymbols;
17391
+
17392
+ var _objectGops = {
17393
+ f: f$1
17394
+ };
17395
+
17396
+ var f = {}.propertyIsEnumerable;
17397
+
17398
+ var _objectPie = {
17399
+ f: f
17400
+ };
17401
+
17402
+ // 7.1.13 ToObject(argument)
17403
+
17404
+ var _toObject = function (it) {
17405
+ return Object(_defined(it));
17406
+ };
17407
+
17408
+ // 19.1.2.1 Object.assign(target, source, ...)
17409
+
17410
+
17411
+
17412
+
17413
+
17414
+
17415
+ var $assign = Object.assign;
17416
+
17417
+ // should work with symbols and should have deterministic property order (V8 bug)
17418
+ var _objectAssign = !$assign || _fails(function () {
17419
+ var A = {};
17420
+ var B = {};
17421
+ // eslint-disable-next-line no-undef
17422
+ var S = Symbol();
17423
+ var K = 'abcdefghijklmnopqrst';
17424
+ A[S] = 7;
17425
+ K.split('').forEach(function (k) { B[k] = k; });
17426
+ return $assign({}, A)[S] != 7 || Object.keys($assign({}, B)).join('') != K;
17427
+ }) ? function assign(target, source) { // eslint-disable-line no-unused-vars
17428
+ var T = _toObject(target);
17429
+ var aLen = arguments.length;
17430
+ var index = 1;
17431
+ var getSymbols = _objectGops.f;
17432
+ var isEnum = _objectPie.f;
17433
+ while (aLen > index) {
17434
+ var S = _iobject(arguments[index++]);
17435
+ var keys = getSymbols ? _objectKeys(S).concat(getSymbols(S)) : _objectKeys(S);
17436
+ var length = keys.length;
17437
+ var j = 0;
17438
+ var key;
17439
+ while (length > j) {
17440
+ key = keys[j++];
17441
+ if (!_descriptors || isEnum.call(S, key)) T[key] = S[key];
17442
+ }
17443
+ } return T;
17444
+ } : $assign;
17445
+
17446
+ // 19.1.3.1 Object.assign(target, source)
17447
+
17448
+
17449
+ _export(_export.S + _export.F, 'Object', { assign: _objectAssign });
17450
+
17451
+ _core.Object.assign;
17452
+
17453
+ var isEnum = _objectPie.f;
17454
+ var _objectToArray = function (isEntries) {
17455
+ return function (it) {
17456
+ var O = _toIobject(it);
17457
+ var keys = _objectKeys(O);
17458
+ var length = keys.length;
17459
+ var i = 0;
17460
+ var result = [];
17461
+ var key;
17462
+ while (length > i) {
17463
+ key = keys[i++];
17464
+ if (!_descriptors || isEnum.call(O, key)) {
17465
+ result.push(isEntries ? [key, O[key]] : O[key]);
17466
+ }
17467
+ }
17468
+ return result;
17469
+ };
17470
+ };
17471
+
17472
+ // https://github.com/tc39/proposal-object-values-entries
17473
+
17474
+ var $entries = _objectToArray(true);
17475
+
17476
+ _export(_export.S, 'Object', {
17477
+ entries: function entries(it) {
17478
+ return $entries(it);
17479
+ }
17480
+ });
17481
+
17482
+ _core.Object.entries;
17483
+
17484
+ // https://github.com/tc39/proposal-object-values-entries
17485
+
17486
+ var $values = _objectToArray(false);
17487
+
17488
+ _export(_export.S, 'Object', {
17489
+ values: function values(it) {
17490
+ return $values(it);
17491
+ }
17492
+ });
17493
+
17494
+ _core.Object.values;
17495
+
17496
+ // 7.2.8 IsRegExp(argument)
17497
+
17498
+
17499
+ var MATCH$1 = _wks('match');
17500
+ var _isRegexp = function (it) {
17501
+ var isRegExp;
17502
+ return _isObject(it) && ((isRegExp = it[MATCH$1]) !== undefined ? !!isRegExp : _cof(it) == 'RegExp');
17503
+ };
17504
+
17505
+ // helper for String#{startsWith, endsWith, includes}
17506
+
17507
+
17508
+
17509
+ var _stringContext = function (that, searchString, NAME) {
17510
+ if (_isRegexp(searchString)) throw TypeError('String#' + NAME + " doesn't accept regex!");
17511
+ return String(_defined(that));
17512
+ };
17513
+
17514
+ var MATCH = _wks('match');
17515
+ var _failsIsRegexp = function (KEY) {
17516
+ var re = /./;
17517
+ try {
17518
+ '/./'[KEY](re);
17519
+ } catch (e) {
17520
+ try {
17521
+ re[MATCH] = false;
17522
+ return !'/./'[KEY](re);
17523
+ } catch (f) { /* empty */ }
17524
+ } return true;
17525
+ };
17526
+
17527
+ var STARTS_WITH = 'startsWith';
17528
+ var $startsWith = ''[STARTS_WITH];
17529
+
17530
+ _export(_export.P + _export.F * _failsIsRegexp(STARTS_WITH), 'String', {
17531
+ startsWith: function startsWith(searchString /* , position = 0 */) {
17532
+ var that = _stringContext(this, searchString, STARTS_WITH);
17533
+ var index = _toLength(Math.min(arguments.length > 1 ? arguments[1] : undefined, that.length));
17534
+ var search = String(searchString);
17535
+ return $startsWith
17536
+ ? $startsWith.call(that, search, index)
17537
+ : that.slice(index, index + search.length) === search;
17538
+ }
17539
+ });
17540
+
17541
+ _core.String.startsWith;
17542
+
17543
+ // true -> String#at
17544
+ // false -> String#codePointAt
17545
+ var _stringAt = function (TO_STRING) {
17546
+ return function (that, pos) {
17547
+ var s = String(_defined(that));
17548
+ var i = _toInteger(pos);
17549
+ var l = s.length;
17550
+ var a, b;
17551
+ if (i < 0 || i >= l) return TO_STRING ? '' : undefined;
17552
+ a = s.charCodeAt(i);
17553
+ return a < 0xd800 || a > 0xdbff || i + 1 === l || (b = s.charCodeAt(i + 1)) < 0xdc00 || b > 0xdfff
17554
+ ? TO_STRING ? s.charAt(i) : a
17555
+ : TO_STRING ? s.slice(i, i + 2) : (a - 0xd800 << 10) + (b - 0xdc00) + 0x10000;
17556
+ };
17557
+ };
17558
+
17559
+ var _iterators = {};
17560
+
17561
+ var _objectDps = _descriptors ? Object.defineProperties : function defineProperties(O, Properties) {
17562
+ _anObject(O);
17563
+ var keys = _objectKeys(Properties);
17564
+ var length = keys.length;
17565
+ var i = 0;
17566
+ var P;
17567
+ while (length > i) _objectDp.f(O, P = keys[i++], Properties[P]);
17568
+ return O;
17569
+ };
17570
+
17571
+ var document$2 = _global.document;
17572
+ var _html = document$2 && document$2.documentElement;
17573
+
17574
+ // 19.1.2.2 / 15.2.3.5 Object.create(O [, Properties])
17575
+
17576
+
17577
+
17578
+ var IE_PROTO$1 = _sharedKey('IE_PROTO');
17579
+ var Empty = function () { /* empty */ };
17580
+ var PROTOTYPE = 'prototype';
17581
+
17582
+ // Create object with fake `null` prototype: use iframe Object with cleared prototype
17583
+ var createDict = function () {
17584
+ // Thrash, waste and sodomy: IE GC bug
17585
+ var iframe = _domCreate('iframe');
17586
+ var i = _enumBugKeys.length;
17587
+ var lt = '<';
17588
+ var gt = '>';
17589
+ var iframeDocument;
17590
+ iframe.style.display = 'none';
17591
+ _html.appendChild(iframe);
17592
+ iframe.src = 'javascript:'; // eslint-disable-line no-script-url
17593
+ // createDict = iframe.contentWindow.Object;
17594
+ // html.removeChild(iframe);
17595
+ iframeDocument = iframe.contentWindow.document;
17596
+ iframeDocument.open();
17597
+ iframeDocument.write(lt + 'script' + gt + 'document.F=Object' + lt + '/script' + gt);
17598
+ iframeDocument.close();
17599
+ createDict = iframeDocument.F;
17600
+ while (i--) delete createDict[PROTOTYPE][_enumBugKeys[i]];
17601
+ return createDict();
17602
+ };
17603
+
17604
+ var _objectCreate = Object.create || function create(O, Properties) {
17605
+ var result;
17606
+ if (O !== null) {
17607
+ Empty[PROTOTYPE] = _anObject(O);
17608
+ result = new Empty();
17609
+ Empty[PROTOTYPE] = null;
17610
+ // add "__proto__" for Object.getPrototypeOf polyfill
17611
+ result[IE_PROTO$1] = O;
17612
+ } else result = createDict();
17613
+ return Properties === undefined ? result : _objectDps(result, Properties);
17614
+ };
17615
+
17616
+ var def = _objectDp.f;
17617
+
17618
+ var TAG$1 = _wks('toStringTag');
17619
+
17620
+ var _setToStringTag = function (it, tag, stat) {
17621
+ if (it && !_has(it = stat ? it : it.prototype, TAG$1)) def(it, TAG$1, { configurable: true, value: tag });
17622
+ };
17623
+
17624
+ var IteratorPrototype = {};
17625
+
17626
+ // 25.1.2.1.1 %IteratorPrototype%[@@iterator]()
17627
+ _hide(IteratorPrototype, _wks('iterator'), function () { return this; });
17628
+
17629
+ var _iterCreate = function (Constructor, NAME, next) {
17630
+ Constructor.prototype = _objectCreate(IteratorPrototype, { next: _propertyDesc(1, next) });
17631
+ _setToStringTag(Constructor, NAME + ' Iterator');
17632
+ };
17633
+
17634
+ // 19.1.2.9 / 15.2.3.2 Object.getPrototypeOf(O)
17635
+
17636
+
17637
+ var IE_PROTO = _sharedKey('IE_PROTO');
17638
+ var ObjectProto = Object.prototype;
17639
+
17640
+ var _objectGpo = Object.getPrototypeOf || function (O) {
17641
+ O = _toObject(O);
17642
+ if (_has(O, IE_PROTO)) return O[IE_PROTO];
17643
+ if (typeof O.constructor == 'function' && O instanceof O.constructor) {
17644
+ return O.constructor.prototype;
17645
+ } return O instanceof Object ? ObjectProto : null;
17646
+ };
17647
+
17648
+ var ITERATOR$3 = _wks('iterator');
17649
+ var BUGGY = !([].keys && 'next' in [].keys()); // Safari has buggy iterators w/o `next`
17650
+ var FF_ITERATOR = '@@iterator';
17651
+ var KEYS = 'keys';
17652
+ var VALUES = 'values';
17653
+
17654
+ var returnThis = function () { return this; };
17655
+
17656
+ var _iterDefine = function (Base, NAME, Constructor, next, DEFAULT, IS_SET, FORCED) {
17657
+ _iterCreate(Constructor, NAME, next);
17658
+ var getMethod = function (kind) {
17659
+ if (!BUGGY && kind in proto) return proto[kind];
17660
+ switch (kind) {
17661
+ case KEYS: return function keys() { return new Constructor(this, kind); };
17662
+ case VALUES: return function values() { return new Constructor(this, kind); };
17663
+ } return function entries() { return new Constructor(this, kind); };
17664
+ };
17665
+ var TAG = NAME + ' Iterator';
17666
+ var DEF_VALUES = DEFAULT == VALUES;
17667
+ var VALUES_BUG = false;
17668
+ var proto = Base.prototype;
17669
+ var $native = proto[ITERATOR$3] || proto[FF_ITERATOR] || DEFAULT && proto[DEFAULT];
17670
+ var $default = $native || getMethod(DEFAULT);
17671
+ var $entries = DEFAULT ? !DEF_VALUES ? $default : getMethod('entries') : undefined;
17672
+ var $anyNative = NAME == 'Array' ? proto.entries || $native : $native;
17673
+ var methods, key, IteratorPrototype;
17674
+ // Fix native
17675
+ if ($anyNative) {
17676
+ IteratorPrototype = _objectGpo($anyNative.call(new Base()));
17677
+ if (IteratorPrototype !== Object.prototype && IteratorPrototype.next) {
17678
+ // Set @@toStringTag to native iterators
17679
+ _setToStringTag(IteratorPrototype, TAG, true);
17680
+ // fix for some old engines
17681
+ if (typeof IteratorPrototype[ITERATOR$3] != 'function') _hide(IteratorPrototype, ITERATOR$3, returnThis);
17682
+ }
17683
+ }
17684
+ // fix Array#{values, @@iterator}.name in V8 / FF
17685
+ if (DEF_VALUES && $native && $native.name !== VALUES) {
17686
+ VALUES_BUG = true;
17687
+ $default = function values() { return $native.call(this); };
17688
+ }
17689
+ // Define iterator
17690
+ if ((BUGGY || VALUES_BUG || !proto[ITERATOR$3])) {
17691
+ _hide(proto, ITERATOR$3, $default);
17692
+ }
17693
+ // Plug for library
17694
+ _iterators[NAME] = $default;
17695
+ _iterators[TAG] = returnThis;
17696
+ if (DEFAULT) {
17697
+ methods = {
17698
+ values: DEF_VALUES ? $default : getMethod(VALUES),
17699
+ keys: IS_SET ? $default : getMethod(KEYS),
17700
+ entries: $entries
17701
+ };
17702
+ if (FORCED) for (key in methods) {
17703
+ if (!(key in proto)) _redefine(proto, key, methods[key]);
17704
+ } else _export(_export.P + _export.F * (BUGGY || VALUES_BUG), NAME, methods);
17705
+ }
17706
+ return methods;
17707
+ };
17708
+
17709
+ var $at = _stringAt(true);
17710
+
17711
+ // 21.1.3.27 String.prototype[@@iterator]()
17712
+ _iterDefine(String, 'String', function (iterated) {
17713
+ this._t = String(iterated); // target
17714
+ this._i = 0; // next index
17715
+ // 21.1.5.2.1 %StringIteratorPrototype%.next()
17716
+ }, function () {
17717
+ var O = this._t;
17718
+ var index = this._i;
17719
+ var point;
17720
+ if (index >= O.length) return { value: undefined, done: true };
17721
+ point = $at(O, index);
17722
+ this._i += point.length;
17723
+ return { value: point, done: false };
17724
+ });
17725
+
17726
+ // call something on iterator step with safe closing on error
17727
+
17728
+ var _iterCall = function (iterator, fn, value, entries) {
17729
+ try {
17730
+ return entries ? fn(_anObject(value)[0], value[1]) : fn(value);
17731
+ // 7.4.6 IteratorClose(iterator, completion)
17732
+ } catch (e) {
17733
+ var ret = iterator['return'];
17734
+ if (ret !== undefined) _anObject(ret.call(iterator));
17735
+ throw e;
17736
+ }
17737
+ };
17738
+
17739
+ // check on default Array iterator
17740
+
17741
+ var ITERATOR$2 = _wks('iterator');
17742
+ var ArrayProto = Array.prototype;
17743
+
17744
+ var _isArrayIter = function (it) {
17745
+ return it !== undefined && (_iterators.Array === it || ArrayProto[ITERATOR$2] === it);
17746
+ };
17747
+
17748
+ var _createProperty = function (object, index, value) {
17749
+ if (index in object) _objectDp.f(object, index, _propertyDesc(0, value));
17750
+ else object[index] = value;
17751
+ };
17752
+
17753
+ // getting tag from 19.1.3.6 Object.prototype.toString()
17754
+
17755
+ var TAG = _wks('toStringTag');
17756
+ // ES3 wrong here
17757
+ var ARG = _cof(function () { return arguments; }()) == 'Arguments';
17758
+
17759
+ // fallback for IE11 Script Access Denied error
17760
+ var tryGet = function (it, key) {
17761
+ try {
17762
+ return it[key];
17763
+ } catch (e) { /* empty */ }
17764
+ };
17765
+
17766
+ var _classof = function (it) {
17767
+ var O, T, B;
17768
+ return it === undefined ? 'Undefined' : it === null ? 'Null'
17769
+ // @@toStringTag case
17770
+ : typeof (T = tryGet(O = Object(it), TAG)) == 'string' ? T
17771
+ // builtinTag case
17772
+ : ARG ? _cof(O)
17773
+ // ES3 arguments fallback
17774
+ : (B = _cof(O)) == 'Object' && typeof O.callee == 'function' ? 'Arguments' : B;
17775
+ };
17776
+
17777
+ var ITERATOR$1 = _wks('iterator');
17778
+
17779
+ var core_getIteratorMethod = _core.getIteratorMethod = function (it) {
17780
+ if (it != undefined) return it[ITERATOR$1]
17781
+ || it['@@iterator']
17782
+ || _iterators[_classof(it)];
17783
+ };
17784
+
17785
+ var ITERATOR = _wks('iterator');
17786
+ var SAFE_CLOSING = false;
17787
+
17788
+ try {
17789
+ var riter = [7][ITERATOR]();
17790
+ riter['return'] = function () { SAFE_CLOSING = true; };
17791
+ // eslint-disable-next-line no-throw-literal
17792
+ Array.from(riter, function () { throw 2; });
17793
+ } catch (e) { /* empty */ }
17794
+
17795
+ var _iterDetect = function (exec, skipClosing) {
17796
+ if (!skipClosing && !SAFE_CLOSING) return false;
17797
+ var safe = false;
17798
+ try {
17799
+ var arr = [7];
17800
+ var iter = arr[ITERATOR]();
17801
+ iter.next = function () { return { done: safe = true }; };
17802
+ arr[ITERATOR] = function () { return iter; };
17803
+ exec(arr);
17804
+ } catch (e) { /* empty */ }
17805
+ return safe;
17806
+ };
17807
+
17808
+ _export(_export.S + _export.F * !_iterDetect(function (iter) { Array.from(iter); }), 'Array', {
17809
+ // 22.1.2.1 Array.from(arrayLike, mapfn = undefined, thisArg = undefined)
17810
+ from: function from(arrayLike /* , mapfn = undefined, thisArg = undefined */) {
17811
+ var O = _toObject(arrayLike);
17812
+ var C = typeof this == 'function' ? this : Array;
17813
+ var aLen = arguments.length;
17814
+ var mapfn = aLen > 1 ? arguments[1] : undefined;
17815
+ var mapping = mapfn !== undefined;
17816
+ var index = 0;
17817
+ var iterFn = core_getIteratorMethod(O);
17818
+ var length, result, step, iterator;
17819
+ if (mapping) mapfn = _ctx(mapfn, aLen > 2 ? arguments[2] : undefined, 2);
17820
+ // if object isn't iterable or it's array with default iterator - use simple case
17821
+ if (iterFn != undefined && !(C == Array && _isArrayIter(iterFn))) {
17822
+ for (iterator = iterFn.call(O), result = new C(); !(step = iterator.next()).done; index++) {
17823
+ _createProperty(result, index, mapping ? _iterCall(iterator, mapfn, [step.value, index], true) : step.value);
17824
+ }
17825
+ } else {
17826
+ length = _toLength(O.length);
17827
+ for (result = new C(length); length > index; index++) {
17828
+ _createProperty(result, index, mapping ? mapfn(O[index], index) : O[index]);
17829
+ }
17830
+ }
17831
+ result.length = index;
17832
+ return result;
17833
+ }
17834
+ });
17835
+
17836
+ _core.Array.from;
17837
+
17838
+ // 7.2.2 IsArray(argument)
17839
+
17840
+ var _isArray = Array.isArray || function isArray(arg) {
17841
+ return _cof(arg) == 'Array';
17842
+ };
17843
+
17844
+ var SPECIES = _wks('species');
17845
+
17846
+ var _arraySpeciesConstructor = function (original) {
17847
+ var C;
17848
+ if (_isArray(original)) {
17849
+ C = original.constructor;
17850
+ // cross-realm fallback
17851
+ if (typeof C == 'function' && (C === Array || _isArray(C.prototype))) C = undefined;
17852
+ if (_isObject(C)) {
17853
+ C = C[SPECIES];
17854
+ if (C === null) C = undefined;
17855
+ }
17856
+ } return C === undefined ? Array : C;
17857
+ };
17858
+
17859
+ // 9.4.2.3 ArraySpeciesCreate(originalArray, length)
17860
+
17861
+
17862
+ var _arraySpeciesCreate = function (original, length) {
17863
+ return new (_arraySpeciesConstructor(original))(length);
17864
+ };
17865
+
17866
+ // 0 -> Array#forEach
17867
+ // 1 -> Array#map
17868
+ // 2 -> Array#filter
17869
+ // 3 -> Array#some
17870
+ // 4 -> Array#every
17871
+ // 5 -> Array#find
17872
+ // 6 -> Array#findIndex
17873
+
17874
+
17875
+
17876
+
17877
+
17878
+ var _arrayMethods = function (TYPE, $create) {
17879
+ var IS_MAP = TYPE == 1;
17880
+ var IS_FILTER = TYPE == 2;
17881
+ var IS_SOME = TYPE == 3;
17882
+ var IS_EVERY = TYPE == 4;
17883
+ var IS_FIND_INDEX = TYPE == 6;
17884
+ var NO_HOLES = TYPE == 5 || IS_FIND_INDEX;
17885
+ var create = $create || _arraySpeciesCreate;
17886
+ return function ($this, callbackfn, that) {
17887
+ var O = _toObject($this);
17888
+ var self = _iobject(O);
17889
+ var f = _ctx(callbackfn, that, 3);
17890
+ var length = _toLength(self.length);
17891
+ var index = 0;
17892
+ var result = IS_MAP ? create($this, length) : IS_FILTER ? create($this, 0) : undefined;
17893
+ var val, res;
17894
+ for (;length > index; index++) if (NO_HOLES || index in self) {
17895
+ val = self[index];
17896
+ res = f(val, index, O);
17897
+ if (TYPE) {
17898
+ if (IS_MAP) result[index] = res; // map
17899
+ else if (res) switch (TYPE) {
17900
+ case 3: return true; // some
17901
+ case 5: return val; // find
17902
+ case 6: return index; // findIndex
17903
+ case 2: result.push(val); // filter
17904
+ } else if (IS_EVERY) return false; // every
17905
+ }
17906
+ }
17907
+ return IS_FIND_INDEX ? -1 : IS_SOME || IS_EVERY ? IS_EVERY : result;
17908
+ };
17909
+ };
17910
+
17911
+ // 22.1.3.8 Array.prototype.find(predicate, thisArg = undefined)
17912
+
17913
+ var $find = _arrayMethods(5);
17914
+ var KEY = 'find';
17915
+ var forced = true;
17916
+ // Shouldn't skip holes
17917
+ if (KEY in []) Array(1)[KEY](function () { forced = false; });
17918
+ _export(_export.P + _export.F * forced, 'Array', {
17919
+ find: function find(callbackfn /* , that = undefined */) {
17920
+ return $find(this, callbackfn, arguments.length > 1 ? arguments[1] : undefined);
17921
+ }
17922
+ });
17923
+ _addToUnscopables(KEY);
17924
+
17925
+ _core.Array.find;
17926
+
17927
+ class Container {
17928
+ /**
17929
+ * Register the store instance.
17930
+ */
17931
+ static register(store) {
17932
+ this.store = store;
17933
+ }
17934
+ }
17935
+
17936
+ /**
17937
+ * Check if the given value is the type of array.
17938
+ */
17939
+ function isArray(value) {
17940
+ return Array.isArray(value);
17941
+ }
17942
+ /**
17943
+ * Gets the size of collection by returning its length for array-like values
17944
+ * or the number of own enumerable string keyed properties for objects.
17945
+ */
17946
+ function size(collection) {
17947
+ return isArray(collection)
17948
+ ? collection.length
17949
+ : Object.keys(collection).length;
17950
+ }
17951
+ /**
17952
+ * Check if the given array or object is empty.
17953
+ */
17954
+ function isEmpty(collection) {
17955
+ return size(collection) === 0;
17956
+ }
17957
+ /**
17958
+ * Iterates over own enumerable string keyed properties of an object and
17959
+ * invokes `iteratee` for each property.
17960
+ */
17961
+ function forOwn(object, iteratee) {
17962
+ Object.keys(object).forEach((key) => iteratee(object[key], key, object));
17963
+ }
17964
+ /**
17965
+ * Creates an array of values by running each element in collection thru
17966
+ * iteratee. The iteratee is invoked with three arguments:
17967
+ * (value, key, collection).
17968
+ */
17969
+ function map(object, iteratee) {
17970
+ const result = [];
17971
+ for (const key in object) {
17972
+ result.push(iteratee(object[key], key, object));
17973
+ }
17974
+ return result;
17975
+ }
17976
+ /**
17977
+ * Creates an object with the same keys as object and values generated by
17978
+ * running each own enumerable string keyed property of object thru
17979
+ * iteratee. The iteratee is invoked with three arguments:
17980
+ * (value, key, object).
17981
+ */
17982
+ function mapValues(object, iteratee) {
17983
+ const newObject = Object.assign({}, object);
17984
+ return Object.keys(object).reduce((records, key) => {
17985
+ records[key] = iteratee(object[key], key, object);
17986
+ return records;
17987
+ }, newObject);
17988
+ }
17989
+ /**
17990
+ * Creates an object composed of keys generated from the results of running
17991
+ * each element of collection by the given key.
17992
+ */
17993
+ function keyBy(collection, key) {
17994
+ const o = {};
17995
+ collection.forEach((item) => {
17996
+ o[item[key]] = item;
17997
+ });
17998
+ return o;
17999
+ }
18000
+ /**
18001
+ * Creates an array of elements, sorted in specified order by the results
18002
+ * of running each element in a collection thru each iteratee.
18003
+ */
18004
+ function orderBy(collection, iteratees, directions) {
18005
+ let index = -1;
18006
+ const result = collection.map((value) => {
18007
+ const criteria = iteratees.map((iteratee) => {
18008
+ return typeof iteratee === 'function' ? iteratee(value) : value[iteratee];
18009
+ });
18010
+ return { criteria, index: ++index, value };
18011
+ });
18012
+ return baseSortBy(result, (object, other) => {
18013
+ return compareMultiple(object, other, directions);
18014
+ });
18015
+ }
18016
+ /**
18017
+ * Creates an array of elements, sorted in ascending order by the results of
18018
+ * running each element in a collection thru each iteratee. This method
18019
+ * performs a stable sort, that is, it preserves the original sort order
18020
+ * of equal elements.
18021
+ */
18022
+ function baseSortBy(array, comparer) {
18023
+ let length = array.length;
18024
+ array.sort(comparer);
18025
+ const newArray = [];
18026
+ while (length--) {
18027
+ newArray[length] = array[length].value;
18028
+ }
18029
+ return newArray;
18030
+ }
18031
+ /**
18032
+ * Used by `orderBy` to compare multiple properties of a value to another
18033
+ * and stable sort them.
18034
+ *
18035
+ * If `orders` is unspecified, all values are sorted in ascending order.
18036
+ * Otherwise, specify an order of "desc" for descending or "asc" for
18037
+ * ascending sort order of corresponding values.
18038
+ */
18039
+ function compareMultiple(object, other, orders) {
18040
+ let index = -1;
18041
+ const objCriteria = object.criteria;
18042
+ const othCriteria = other.criteria;
18043
+ const length = objCriteria.length;
18044
+ const ordersLength = orders.length;
18045
+ while (++index < length) {
18046
+ const result = compareAscending(objCriteria[index], othCriteria[index]);
18047
+ if (result) {
18048
+ if (index >= ordersLength) {
18049
+ return result;
18050
+ }
18051
+ const order = orders[index];
18052
+ return result * (order === 'desc' ? -1 : 1);
18053
+ }
18054
+ }
18055
+ return object.index - other.index;
18056
+ }
18057
+ /**
18058
+ * Compares values to sort them in ascending order.
18059
+ */
18060
+ function compareAscending(value, other) {
18061
+ if (value !== other) {
18062
+ const valIsDefined = value !== undefined;
18063
+ const valIsNull = value === null;
18064
+ const valIsReflexive = value === value;
18065
+ const othIsDefined = other !== undefined;
18066
+ const othIsNull = other === null;
18067
+ const othIsReflexive = other === other;
18068
+ if (typeof value !== 'number' || typeof other !== 'number') {
18069
+ value = String(value);
18070
+ other = String(other);
18071
+ }
18072
+ if ((!othIsNull && value > other) ||
18073
+ (valIsNull && othIsDefined && othIsReflexive) ||
18074
+ (!valIsDefined && othIsReflexive) ||
18075
+ !valIsReflexive) {
18076
+ return 1;
18077
+ }
18078
+ if ((!valIsNull && value < other) ||
18079
+ (othIsNull && valIsDefined && valIsReflexive) ||
18080
+ (!othIsDefined && valIsReflexive) ||
18081
+ !othIsReflexive) {
18082
+ return -1;
18083
+ }
18084
+ }
18085
+ return 0;
18086
+ }
18087
+ /**
18088
+ * Creates an object composed of keys generated from the results of running
18089
+ * each element of collection thru iteratee.
18090
+ */
18091
+ function groupBy(collection, iteratee) {
18092
+ return collection.reduce((records, record) => {
18093
+ const key = iteratee(record);
18094
+ if (records[key] === undefined) {
18095
+ records[key] = [];
18096
+ }
18097
+ records[key].push(record);
18098
+ return records;
18099
+ }, {});
18100
+ }
18101
+ /**
18102
+ * Deep clone the given target object.
18103
+ */
18104
+ function cloneDeep(target) {
18105
+ if (target === null) {
18106
+ return target;
18107
+ }
18108
+ if (isArray(target)) {
18109
+ const cp = [];
18110
+ target.forEach((v) => cp.push(v));
18111
+ return cp.map((n) => cloneDeep(n));
18112
+ }
18113
+ if (typeof target === 'object' && target !== {}) {
18114
+ const cp = { ...target };
18115
+ Object.keys(cp).forEach((k) => (cp[k] = cloneDeep(cp[k])));
18116
+ return cp;
18117
+ }
18118
+ return target;
18119
+ }
18120
+ var Utils = {
18121
+ isArray,
18122
+ size,
18123
+ isEmpty,
18124
+ forOwn,
18125
+ map,
18126
+ mapValues,
18127
+ keyBy,
18128
+ orderBy,
18129
+ groupBy,
18130
+ cloneDeep
18131
+ };
18132
+
18133
+ class Uid$1 {
18134
+ /**
18135
+ * Generate an UUID.
18136
+ */
18137
+ static make() {
18138
+ this.count++;
18139
+ return `${this.prefix}${this.count}`;
18140
+ }
18141
+ /**
18142
+ * Reset the count to 0.
18143
+ */
18144
+ static reset() {
18145
+ this.count = 0;
18146
+ }
18147
+ }
18148
+ /**
18149
+ * Count to create a unique id.
18150
+ */
18151
+ Uid$1.count = 0;
18152
+ /**
18153
+ * Prefix string to be used for the id.
18154
+ */
18155
+ Uid$1.prefix = '$uid';
18156
+
18157
+ class Attribute {
18158
+ /**
18159
+ * Create a new attribute instance.
18160
+ */
18161
+ constructor(model) {
18162
+ this.model = model;
18163
+ }
18164
+ }
18165
+
18166
+ class Type extends Attribute {
18167
+ /**
18168
+ * Create a new type instance.
18169
+ */
18170
+ constructor(model, value, mutator) {
18171
+ super(model); /* istanbul ignore next */
18172
+ /**
18173
+ * Whether if the attribute can accept `null` as a value.
18174
+ */
18175
+ this.isNullable = false;
18176
+ this.value = value;
18177
+ this.mutator = mutator;
18178
+ }
18179
+ /**
18180
+ * Set `isNullable` to be `true`.
18181
+ */
18182
+ nullable() {
18183
+ this.isNullable = true;
18184
+ return this;
18185
+ }
18186
+ /**
18187
+ * Mutate the given value by mutator.
18188
+ */
18189
+ mutate(value, key) {
18190
+ const mutator = this.mutator || this.model.mutators()[key];
18191
+ return mutator ? mutator(value) : value;
18192
+ }
18193
+ }
18194
+
18195
+ class Attr extends Type {
18196
+ /**
18197
+ * Create a new attr instance.
18198
+ */
18199
+ constructor(model, value, mutator) {
18200
+ /* istanbul ignore next */
18201
+ super(model, value, mutator);
18202
+ }
18203
+ /**
18204
+ * Make value to be set to model property. This method is used when
18205
+ * instantiating a model or creating a plain object from a model.
18206
+ */
18207
+ make(value, _parent, key) {
18208
+ value = value !== undefined ? value : this.value;
18209
+ // Default Value might be a function (taking no parameter).
18210
+ let localValue = value;
18211
+ if (typeof value === 'function') {
18212
+ localValue = value();
18213
+ }
18214
+ return this.mutate(localValue, key);
18215
+ }
18216
+ }
18217
+
18218
+ class String$1 extends Type {
18219
+ /**
18220
+ * Create a new string instance.
18221
+ */
18222
+ constructor(model, value, mutator) {
18223
+ /* istanbul ignore next */
18224
+ super(model, value, mutator);
18225
+ }
18226
+ /**
18227
+ * Convert given value to the appropriate value for the attribute.
18228
+ */
18229
+ make(value, _parent, key) {
18230
+ return this.mutate(this.fix(value), key);
18231
+ }
18232
+ /**
18233
+ * Convert given value to the string.
18234
+ */
18235
+ fix(value) {
18236
+ if (value === undefined) {
18237
+ return this.value;
18238
+ }
18239
+ if (typeof value === 'string') {
18240
+ return value;
18241
+ }
18242
+ if (value === null && this.isNullable) {
18243
+ return value;
18244
+ }
18245
+ return value + '';
18246
+ }
18247
+ }
18248
+
18249
+ class Number$1 extends Type {
18250
+ /**
18251
+ * Create a new number instance.
18252
+ */
18253
+ constructor(model, value, mutator) {
18254
+ /* istanbul ignore next */
18255
+ super(model, value, mutator);
18256
+ }
18257
+ /**
18258
+ * Convert given value to the appropriate value for the attribute.
18259
+ */
18260
+ make(value, _parent, key) {
18261
+ return this.mutate(this.fix(value), key);
18262
+ }
18263
+ /**
18264
+ * Transform given data to the number.
18265
+ */
18266
+ fix(value) {
18267
+ if (value === undefined) {
18268
+ return this.value;
18269
+ }
18270
+ if (typeof value === 'number') {
18271
+ return value;
18272
+ }
18273
+ if (typeof value === 'string') {
18274
+ return parseFloat(value);
18275
+ }
18276
+ if (typeof value === 'boolean') {
18277
+ return value ? 1 : 0;
18278
+ }
18279
+ if (value === null && this.isNullable) {
18280
+ return value;
18281
+ }
18282
+ return 0;
18283
+ }
18284
+ }
18285
+
18286
+ class Boolean$1 extends Type {
18287
+ /**
18288
+ * Create a new number instance.
18289
+ */
18290
+ constructor(model, value, mutator) {
18291
+ /* istanbul ignore next */
18292
+ super(model, value, mutator);
18293
+ }
18294
+ /**
18295
+ * Convert given value to the appropriate value for the attribute.
18296
+ */
18297
+ make(value, _parent, key) {
18298
+ return this.mutate(this.fix(value), key);
18299
+ }
18300
+ /**
18301
+ * Transform given data to the boolean.
18302
+ */
18303
+ fix(value) {
18304
+ if (value === undefined) {
18305
+ return this.value;
18306
+ }
18307
+ if (typeof value === 'boolean') {
18308
+ return value;
18309
+ }
18310
+ if (typeof value === 'string') {
18311
+ if (value.length === 0) {
18312
+ return false;
18313
+ }
18314
+ const int = parseInt(value, 0);
18315
+ return isNaN(int) ? true : !!int;
18316
+ }
18317
+ if (typeof value === 'number') {
18318
+ return !!value;
18319
+ }
18320
+ if (value === null && this.isNullable) {
18321
+ return value;
18322
+ }
18323
+ return false;
18324
+ }
18325
+ }
18326
+
18327
+ class Uid extends Type {
18328
+ /**
18329
+ * Create a new uid instance.
18330
+ */
18331
+ constructor(model, value) {
18332
+ /* istanbul ignore next */
18333
+ super(model, value);
18334
+ }
18335
+ /**
18336
+ * Convert given value to the appropriate value for the attribute.
18337
+ */
18338
+ make(value) {
18339
+ if (typeof value === 'number' || typeof value === 'string') {
18340
+ return value;
18341
+ }
18342
+ if (typeof this.value === 'function') {
18343
+ return this.value();
18344
+ }
18345
+ return Uid$1.make();
18346
+ }
18347
+ }
18348
+
18349
+ class Relation extends Attribute {
18350
+ /**
18351
+ * Get relation query instance with constraint attached.
18352
+ */
18353
+ getRelation(query, name, constraints) {
18354
+ const relation = query.newQuery(name);
18355
+ constraints.forEach((constraint) => {
18356
+ constraint(relation);
18357
+ });
18358
+ return relation;
18359
+ }
18360
+ /**
18361
+ * Get specified keys from the given collection.
18362
+ */
18363
+ getKeys(collection, key) {
18364
+ return collection.reduce((models, model) => {
18365
+ if (model[key] === null || model[key] === undefined) {
18366
+ return models;
18367
+ }
18368
+ models.push(model[key]);
18369
+ return models;
18370
+ }, []);
18371
+ }
18372
+ /**
18373
+ * Create a new indexed map for the single relation by specified key.
18374
+ */
18375
+ mapSingleRelations(collection, key) {
18376
+ const relations = new Map();
18377
+ collection.forEach((record) => {
18378
+ const id = record[key];
18379
+ !relations.get(id) && relations.set(id, record);
18380
+ });
18381
+ return relations;
18382
+ }
18383
+ /**
18384
+ * Create a new indexed map for the many relation by specified key.
18385
+ */
18386
+ mapManyRelations(collection, key) {
18387
+ const relations = new Map();
18388
+ collection.forEach((record) => {
18389
+ const id = record[key];
18390
+ let ownerKeys = relations.get(id);
18391
+ if (!ownerKeys) {
18392
+ ownerKeys = [];
18393
+ relations.set(id, ownerKeys);
18394
+ }
18395
+ ownerKeys.push(record);
18396
+ });
18397
+ return relations;
18398
+ }
18399
+ /**
18400
+ * Create a new indexed map for relations with order constraints.
18401
+ */
18402
+ mapRelationsByOrders(collection, relations, ownerKey, relationKey) {
18403
+ const records = {};
18404
+ relations.forEach((related, id) => {
18405
+ collection
18406
+ .filter((record) => record[relationKey] === id)
18407
+ .forEach((record) => {
18408
+ const id = record[ownerKey];
18409
+ if (!records[id]) {
18410
+ records[id] = [];
18411
+ }
18412
+ records[id] = records[id].concat(related);
18413
+ });
18414
+ });
18415
+ return records;
18416
+ }
18417
+ /**
18418
+ * Check if the given record is a single relation, which is an object.
18419
+ */
18420
+ isOneRelation(record) {
18421
+ if (!isArray(record) && record !== null && typeof record === 'object') {
18422
+ return true;
18423
+ }
18424
+ return false;
18425
+ }
18426
+ /**
18427
+ * Check if the given records is a many relation, which is an array
18428
+ * of object.
18429
+ */
18430
+ isManyRelation(records) {
18431
+ if (!isArray(records)) {
18432
+ return false;
18433
+ }
18434
+ if (records.length < 1) {
18435
+ return false;
18436
+ }
18437
+ return true;
18438
+ }
18439
+ /**
18440
+ * Wrap the given object into a model instance.
18441
+ */
18442
+ makeOneRelation(record, model) {
18443
+ if (!this.isOneRelation(record)) {
18444
+ return null;
18445
+ }
18446
+ const relatedModel = model.getModelFromRecord(record) || model;
18447
+ return new relatedModel(record);
18448
+ }
18449
+ /**
18450
+ * Wrap the given records into a collection of model instances.
18451
+ */
18452
+ makeManyRelation(records, model) {
18453
+ if (!this.isManyRelation(records)) {
18454
+ return [];
18455
+ }
18456
+ return records
18457
+ .filter((record) => {
18458
+ return this.isOneRelation(record);
18459
+ })
18460
+ .map((record) => {
18461
+ const relatedModel = model.getModelFromRecord(record) || model;
18462
+ return new relatedModel(record);
18463
+ });
18464
+ }
18465
+ }
18466
+
18467
+ class HasOne extends Relation {
18468
+ /**
18469
+ * Create a new has one instance.
18470
+ */
18471
+ constructor(model, related, foreignKey, localKey) {
18472
+ super(model); /* istanbul ignore next */
18473
+ this.related = this.model.relation(related);
18474
+ this.foreignKey = foreignKey;
18475
+ this.localKey = localKey;
18476
+ }
18477
+ /**
18478
+ * Define the normalizr schema for the relationship.
18479
+ */
18480
+ define(schema) {
18481
+ return schema.one(this.related);
18482
+ }
18483
+ /**
18484
+ * Attach the relational key to the related data. For example,
18485
+ * when User has one Phone, it will attach value to the
18486
+ * `user_id` field of Phone record.
18487
+ */
18488
+ attach(key, record, data) {
18489
+ // Check if the record has local key set. If not, set the local key to be
18490
+ // the id value. This happens if the user defines the custom local key
18491
+ // and didn't include it in the data being normalized.
18492
+ if (!record[this.localKey]) {
18493
+ record[this.localKey] = this.model.getIndexIdFromRecord(record);
18494
+ }
18495
+ // Then set the foreign key of the related record if it exists to be the
18496
+ // local key of this record.
18497
+ const related = data[this.related.entity] && data[this.related.entity][key];
18498
+ if (related) {
18499
+ related[this.foreignKey] = record[this.localKey];
18500
+ }
18501
+ }
18502
+ /**
18503
+ * Make value to be set to model property. This method is used when
18504
+ * instantiating a model or creating a plain object from a model.
18505
+ */
18506
+ make(value, _parent, _key) {
18507
+ return this.makeOneRelation(value, this.related);
18508
+ }
18509
+ /**
18510
+ * Load the has one relationship for the collection.
18511
+ */
18512
+ load(query, collection, name, constraints) {
18513
+ const relation = this.getRelation(query, this.related.entity, constraints);
18514
+ this.addEagerConstraints(relation, collection);
18515
+ this.match(collection, relation.get(), name);
18516
+ }
18517
+ /**
18518
+ * Set the constraints for an eager load of the relation.
18519
+ */
18520
+ addEagerConstraints(relation, collection) {
18521
+ relation.whereFk(this.foreignKey, this.getKeys(collection, this.localKey));
18522
+ }
18523
+ /**
18524
+ * Match the eagerly loaded results to their parents.
18525
+ */
18526
+ match(collection, relations, name) {
18527
+ const dictionary = this.buildDictionary(relations);
18528
+ collection.forEach((model) => {
18529
+ const id = model[this.localKey];
18530
+ const relation = dictionary[id];
18531
+ model[name] = relation || null;
18532
+ });
18533
+ }
18534
+ /**
18535
+ * Build model dictionary keyed by the relation's foreign key.
18536
+ */
18537
+ buildDictionary(relations) {
18538
+ return relations.reduce((dictionary, relation) => {
18539
+ const key = relation[this.foreignKey];
18540
+ dictionary[key] = relation;
18541
+ return dictionary;
18542
+ }, {});
18543
+ }
18544
+ }
18545
+
18546
+ class BelongsTo extends Relation {
18547
+ /**
18548
+ * Create a new belongs to instance.
18549
+ */
18550
+ constructor(model, parent, foreignKey, ownerKey) {
18551
+ super(model); /* istanbul ignore next */
18552
+ this.parent = this.model.relation(parent);
18553
+ this.foreignKey = foreignKey;
18554
+ this.ownerKey = ownerKey;
18555
+ }
18556
+ /**
18557
+ * Define the normalizr schema for the relationship.
18558
+ */
18559
+ define(schema) {
18560
+ return schema.one(this.parent);
18561
+ }
18562
+ /**
18563
+ * Attach the relational key to the given data. For example, when Post
18564
+ * belongs to User, it will attach value to the `user_id` field of
18565
+ * Post record.
18566
+ */
18567
+ attach(key, record, data) {
18568
+ // See if the record has the foreign key, if yes, it means the user has
18569
+ // provided the key explicitly so do nothing and return.
18570
+ if (record[this.foreignKey] !== undefined) {
18571
+ return;
18572
+ }
18573
+ // If there is no foreign key, let's set it here.
18574
+ record[this.foreignKey] =
18575
+ data[this.parent.entity] && data[this.parent.entity][key]
18576
+ ? data[this.parent.entity][key][this.ownerKey]
18577
+ : key;
18578
+ }
18579
+ /**
18580
+ * Convert given value to the appropriate value for the attribute.
18581
+ */
18582
+ make(value, _parent, _key) {
18583
+ return this.makeOneRelation(value, this.parent);
18584
+ }
18585
+ /**
18586
+ * Load the belongs to relationship for the collection.
18587
+ */
18588
+ load(query, collection, name, constraints) {
18589
+ const relation = this.getRelation(query, this.parent.entity, constraints);
18590
+ this.addEagerConstraints(relation, collection);
18591
+ this.match(collection, relation.get(), name);
18592
+ }
18593
+ /**
18594
+ * Set the constraints for an eager load of the relation.
18595
+ */
18596
+ addEagerConstraints(relation, collection) {
18597
+ relation.whereFk(this.ownerKey, this.getKeys(collection, this.foreignKey));
18598
+ }
18599
+ /**
18600
+ * Match the eagerly loaded results to their parents.
18601
+ */
18602
+ match(collection, relations, name) {
18603
+ const dictionary = this.buildDictionary(relations);
18604
+ collection.forEach((model) => {
18605
+ const id = model[this.foreignKey];
18606
+ const relation = id !== null ? dictionary[id] : null;
18607
+ model[name] = relation || null;
18608
+ });
18609
+ }
18610
+ /**
18611
+ * Build model dictionary keyed by the relation's foreign key.
18612
+ */
18613
+ buildDictionary(relations) {
18614
+ return relations.reduce((dictionary, relation) => {
18615
+ const key = relation[this.ownerKey];
18616
+ dictionary[key] = relation;
18617
+ return dictionary;
18618
+ }, {});
18619
+ }
18620
+ }
18621
+
18622
+ class HasMany extends Relation {
18623
+ /**
18624
+ * Create a new has many instance.
18625
+ */
18626
+ constructor(model, related, foreignKey, localKey) {
18627
+ super(model); /* istanbul ignore next */
18628
+ this.related = this.model.relation(related);
18629
+ this.foreignKey = foreignKey;
18630
+ this.localKey = localKey;
18631
+ }
18632
+ /**
18633
+ * Define the normalizr schema for the relationship.
18634
+ */
18635
+ define(schema) {
18636
+ return schema.many(this.related);
18637
+ }
18638
+ /**
18639
+ * Attach the relational key to the given data.
18640
+ */
18641
+ attach(key, record, data) {
18642
+ key.forEach((index) => {
18643
+ const related = data[this.related.entity];
18644
+ if (!related ||
18645
+ !related[index] ||
18646
+ related[index][this.foreignKey] !== undefined) {
18647
+ return;
18648
+ }
18649
+ related[index][this.foreignKey] = record[this.localKey];
18650
+ });
18651
+ }
18652
+ /**
18653
+ * Convert given value to the appropriate value for the attribute.
18654
+ */
18655
+ make(value, _parent, _key) {
18656
+ return this.makeManyRelation(value, this.related);
18657
+ }
18658
+ /**
18659
+ * Load the has many relationship for the collection.
18660
+ */
18661
+ load(query, collection, name, constraints) {
18662
+ const relation = this.getRelation(query, this.related.entity, constraints);
18663
+ this.addEagerConstraints(relation, collection);
18664
+ this.match(collection, relation.get(), name);
18665
+ }
18666
+ /**
18667
+ * Set the constraints for an eager load of the relation.
18668
+ */
18669
+ addEagerConstraints(relation, collection) {
18670
+ relation.whereFk(this.foreignKey, this.getKeys(collection, this.localKey));
18671
+ }
18672
+ /**
18673
+ * Match the eagerly loaded results to their parents.
18674
+ */
18675
+ match(collection, relations, name) {
18676
+ const dictionary = this.buildDictionary(relations);
18677
+ collection.forEach((model) => {
18678
+ const id = model[this.localKey];
18679
+ const relation = dictionary[id];
18680
+ model[name] = relation || [];
18681
+ });
18682
+ }
18683
+ /**
18684
+ * Build model dictionary keyed by the relation's foreign key.
18685
+ */
18686
+ buildDictionary(relations) {
18687
+ return relations.reduce((dictionary, relation) => {
18688
+ const key = relation[this.foreignKey];
18689
+ if (!dictionary[key]) {
18690
+ dictionary[key] = [];
18691
+ }
18692
+ dictionary[key].push(relation);
18693
+ return dictionary;
18694
+ }, {});
18695
+ }
18696
+ }
18697
+
18698
+ class HasManyBy extends Relation {
18699
+ /**
18700
+ * Create a new has many by instance.
18701
+ */
18702
+ constructor(model, parent, foreignKey, ownerKey) {
18703
+ super(model); /* istanbul ignore next */
18704
+ this.parent = this.model.relation(parent);
18705
+ this.foreignKey = foreignKey;
18706
+ this.ownerKey = ownerKey;
18707
+ }
18708
+ /**
18709
+ * Define the normalizr schema for the relationship.
18710
+ */
18711
+ define(schema) {
18712
+ return schema.many(this.parent);
18713
+ }
18714
+ /**
18715
+ * Attach the relational key to the given data.
18716
+ */
18717
+ attach(key, record, _data) {
18718
+ if (key.length === 0) {
18719
+ return;
18720
+ }
18721
+ record[this.foreignKey] = key.map((parentId) => {
18722
+ return this.parent.getIdFromRecord(_data[this.parent.entity][parentId]);
18723
+ });
18724
+ }
18725
+ /**
18726
+ * Convert given value to the appropriate value for the attribute.
18727
+ */
18728
+ make(value, _parent, _key) {
18729
+ return this.makeManyRelation(value, this.parent);
18730
+ }
18731
+ /**
18732
+ * Load the has many by relationship for the collection.
18733
+ */
18734
+ load(query, collection, name, constraints) {
18735
+ const relatedQuery = this.getRelation(query, this.parent.entity, constraints);
18736
+ this.addConstraintForHasManyBy(relatedQuery, collection);
18737
+ const relations = this.mapSingleRelations(relatedQuery.get(), this.ownerKey);
18738
+ collection.forEach((item) => {
18739
+ const related = this.getRelatedRecords(relations, item[this.foreignKey]);
18740
+ item[name] = related;
18741
+ });
18742
+ }
18743
+ /**
18744
+ * Set the constraints for an eager load of the relation.
18745
+ */
18746
+ addConstraintForHasManyBy(query, collection) {
18747
+ const keys = collection.reduce((keys, item) => {
18748
+ return keys.concat(item[this.foreignKey]);
18749
+ }, []);
18750
+ query.where(this.ownerKey, keys);
18751
+ }
18752
+ /**
18753
+ * Get related records.
18754
+ */
18755
+ getRelatedRecords(relations, keys) {
18756
+ const records = [];
18757
+ relations.forEach((record, id) => {
18758
+ if (keys.indexOf(id) !== -1) {
18759
+ records.push(record);
18760
+ }
18761
+ });
18762
+ return records;
18763
+ }
18764
+ }
18765
+
18766
+ class HasManyThrough extends Relation {
18767
+ /**
18768
+ * Create a new has many through instance.
18769
+ */
18770
+ constructor(model, related, through, firstKey, secondKey, localKey, secondLocalKey) {
18771
+ super(model); /* istanbul ignore next */
18772
+ this.related = this.model.relation(related);
18773
+ this.through = this.model.relation(through);
18774
+ this.firstKey = firstKey;
18775
+ this.secondKey = secondKey;
18776
+ this.localKey = localKey;
18777
+ this.secondLocalKey = secondLocalKey;
18778
+ }
18779
+ /**
18780
+ * Define the normalizr schema for the relationship.
18781
+ */
18782
+ define(schema) {
18783
+ return schema.many(this.related);
18784
+ }
18785
+ /**
18786
+ * Attach the relational key to the given data. Since has many through
18787
+ * relationship doesn't have any foreign key, it would do nothing.
18788
+ */
18789
+ attach(_key, _record, _data) {
18790
+ return;
18791
+ }
18792
+ /**
18793
+ * Convert given value to the appropriate value for the attribute.
18794
+ */
18795
+ make(value, _parent, _key) {
18796
+ return this.makeManyRelation(value, this.related);
18797
+ }
18798
+ /**
18799
+ * Load the has many through relationship for the collection.
18800
+ */
18801
+ load(query, collection, name, constraints) {
18802
+ const relatedQuery = this.getRelation(query, this.related.entity, constraints);
18803
+ const throughQuery = query.newQuery(this.through.entity);
18804
+ this.addEagerConstraintForThrough(throughQuery, collection);
18805
+ const throughs = throughQuery.get();
18806
+ this.addEagerConstraintForRelated(relatedQuery, throughs);
18807
+ const relateds = this.mapThroughRelations(throughs, relatedQuery);
18808
+ collection.forEach((item) => {
18809
+ const related = relateds[item[this.localKey]];
18810
+ item[name] = related || [];
18811
+ });
18812
+ }
18813
+ /**
18814
+ * Set the constraints for the through relation.
18815
+ */
18816
+ addEagerConstraintForThrough(query, collection) {
18817
+ query.where(this.firstKey, this.getKeys(collection, this.localKey));
18818
+ }
18819
+ /**
18820
+ * Set the constraints for the related relation.
18821
+ */
18822
+ addEagerConstraintForRelated(query, collection) {
18823
+ query.where(this.secondKey, this.getKeys(collection, this.secondLocalKey));
18824
+ }
18825
+ /**
18826
+ * Create a new indexed map for the through relation.
18827
+ */
18828
+ mapThroughRelations(throughs, relatedQuery) {
18829
+ const relations = this.mapManyRelations(relatedQuery.get(), this.secondKey);
18830
+ return throughs.reduce((records, record) => {
18831
+ const id = record[this.firstKey];
18832
+ if (!records[id]) {
18833
+ records[id] = [];
18834
+ }
18835
+ const related = relations.get(record[this.secondLocalKey]);
18836
+ if (related === undefined) {
18837
+ return records;
18838
+ }
18839
+ records[id] = records[id].concat(related);
18840
+ return records;
18841
+ }, {});
18842
+ }
18843
+ }
18844
+
18845
+ class BelongsToMany extends Relation {
18846
+ /**
18847
+ * Create a new belongs to instance.
18848
+ */
18849
+ constructor(model, related, pivot, foreignPivotKey, relatedPivotKey, parentKey, relatedKey) {
18850
+ super(model); /* istanbul ignore next */
18851
+ /**
18852
+ * The key name of the pivot data.
18853
+ */
18854
+ this.pivotKey = 'pivot';
18855
+ this.related = this.model.relation(related);
18856
+ this.pivot = this.model.relation(pivot);
18857
+ this.foreignPivotKey = foreignPivotKey;
18858
+ this.relatedPivotKey = relatedPivotKey;
18859
+ this.parentKey = parentKey;
18860
+ this.relatedKey = relatedKey;
18861
+ }
18862
+ /**
18863
+ * Specify the custom pivot accessor to use for the relationship.
18864
+ */
18865
+ as(accessor) {
18866
+ this.pivotKey = accessor;
18867
+ return this;
18868
+ }
18869
+ /**
18870
+ * Define the normalizr schema for the relationship.
18871
+ */
18872
+ define(schema) {
18873
+ return schema.many(this.related);
18874
+ }
18875
+ /**
18876
+ * Attach the relational key to the given data. Since belongs to many
18877
+ * relationship doesn't have any foreign key, it would do nothing.
18878
+ */
18879
+ attach(_key, _record, _data) {
18880
+ return;
18881
+ }
18882
+ /**
18883
+ * Convert given value to the appropriate value for the attribute.
18884
+ */
18885
+ make(value, _parent, _key) {
18886
+ return this.makeManyRelation(value, this.related);
18887
+ }
18888
+ /**
18889
+ * Load the belongs to relationship for the record.
18890
+ */
18891
+ load(query, collection, name, constraints) {
18892
+ const relatedQuery = this.getRelation(query, this.related.entity, constraints);
18893
+ const pivotQuery = query.newQuery(this.pivot.entity);
18894
+ this.addEagerConstraintForPivot(pivotQuery, collection);
18895
+ const pivots = pivotQuery.get();
18896
+ this.addEagerConstraintForRelated(relatedQuery, pivots);
18897
+ const relateds = this.mapPivotRelations(pivots, relatedQuery);
18898
+ collection.forEach((item) => {
18899
+ const related = relateds[item[this.parentKey]];
18900
+ item[name] = related || [];
18901
+ });
18902
+ }
18903
+ /**
18904
+ * Set the constraints for the pivot relation.
18905
+ */
18906
+ addEagerConstraintForPivot(query, collection) {
18907
+ query.whereFk(this.foreignPivotKey, this.getKeys(collection, this.parentKey));
18908
+ }
18909
+ /**
18910
+ * Set the constraints for the related relation.
18911
+ */
18912
+ addEagerConstraintForRelated(query, collection) {
18913
+ query.whereFk(this.relatedKey, this.getKeys(collection, this.relatedPivotKey));
18914
+ }
18915
+ /**
18916
+ * Create a new indexed map for the pivot relation.
18917
+ */
18918
+ mapPivotRelations(pivots, relatedQuery) {
18919
+ const relations = this.mapManyRelations(relatedQuery.get(), this.relatedKey);
18920
+ if (relatedQuery.orders.length) {
18921
+ return this.mapRelationsByOrders(pivots, relations, this.foreignPivotKey, this.relatedPivotKey);
18922
+ }
18923
+ return pivots.reduce((records, record) => {
18924
+ const id = record[this.foreignPivotKey];
18925
+ if (!records[id]) {
18926
+ records[id] = [];
18927
+ }
18928
+ const related = relations.get(record[this.relatedPivotKey]);
18929
+ if (related) {
18930
+ records[id] = records[id].concat(related.map((model) => {
18931
+ model[this.pivotKey] = record;
18932
+ return model;
18933
+ }));
18934
+ }
18935
+ return records;
18936
+ }, {});
18937
+ }
18938
+ /**
18939
+ * Create pivot records for the given records if needed.
18940
+ */
18941
+ createPivots(parent, data, key) {
18942
+ if (!Utils.isArray(this.pivot.primaryKey))
18943
+ return data;
18944
+ Utils.forOwn(data[parent.entity], (record) => {
18945
+ const related = record[key];
18946
+ if (related === undefined || related.length === 0) {
18947
+ return;
18948
+ }
18949
+ this.createPivotRecord(data, record, related);
18950
+ });
18951
+ return data;
18952
+ }
18953
+ /**
18954
+ * Create a pivot record.
18955
+ */
18956
+ createPivotRecord(data, record, related) {
18957
+ related.forEach((id) => {
18958
+ const parentId = record[this.parentKey];
18959
+ const relatedId = data[this.related.entity][id][this.relatedKey];
18960
+ const pivotKey = JSON.stringify([
18961
+ this.pivot.primaryKey[0] === this.foreignPivotKey
18962
+ ? parentId
18963
+ : relatedId,
18964
+ this.pivot.primaryKey[1] === this.foreignPivotKey ? parentId : relatedId
18965
+ ]);
18966
+ const pivotRecord = data[this.pivot.entity]
18967
+ ? data[this.pivot.entity][pivotKey]
18968
+ : {};
18969
+ const pivotData = data[this.related.entity][id][this.pivotKey] || {};
18970
+ data[this.pivot.entity] = {
18971
+ ...data[this.pivot.entity],
18972
+ [pivotKey]: {
18973
+ ...pivotRecord,
18974
+ ...pivotData,
18975
+ $id: pivotKey,
18976
+ [this.foreignPivotKey]: parentId,
18977
+ [this.relatedPivotKey]: relatedId
18978
+ }
18979
+ };
18980
+ });
18981
+ }
18982
+ }
18983
+
18984
+ class MorphTo extends Relation {
18985
+ /**
18986
+ * Create a new morph to instance.
18987
+ */
18988
+ constructor(model, id, type) {
18989
+ super(model); /* istanbul ignore next */
18990
+ this.id = id;
18991
+ this.type = type;
18992
+ }
18993
+ /**
18994
+ * Define the normalizr schema for the relationship.
18995
+ */
18996
+ define(schema) {
18997
+ return schema.union((_value, parentValue) => parentValue[this.type]);
18998
+ }
18999
+ /**
19000
+ * Attach the relational key to the given record. Since morph to
19001
+ * relationship doesn't have any foreign key, it would do nothing.
19002
+ */
19003
+ attach(_key, _record, _data) {
19004
+ return;
19005
+ }
19006
+ /**
19007
+ * Convert given value to the appropriate value for the attribute.
19008
+ */
19009
+ make(value, parent, _key) {
19010
+ const related = parent[this.type];
19011
+ try {
19012
+ const model = this.model.relation(related);
19013
+ return this.makeOneRelation(value, model);
19014
+ }
19015
+ catch (_a) {
19016
+ return null;
19017
+ }
19018
+ }
19019
+ /**
19020
+ * Load the morph to relationship for the collection.
19021
+ */
19022
+ load(query, collection, name, constraints) {
19023
+ const types = this.getTypes(collection);
19024
+ const relations = types.reduce((related, type) => {
19025
+ const relatedQuery = this.getRelation(query, type, constraints);
19026
+ related[type] = this.mapSingleRelations(relatedQuery.get(), '$id');
19027
+ return related;
19028
+ }, {});
19029
+ collection.forEach((item) => {
19030
+ const id = item[this.id];
19031
+ const type = item[this.type];
19032
+ const related = relations[type].get(String(id));
19033
+ item[name] = related || null;
19034
+ });
19035
+ }
19036
+ /**
19037
+ * Get all types from the collection.
19038
+ */
19039
+ getTypes(collection) {
19040
+ return collection.reduce((types, item) => {
19041
+ const type = item[this.type];
19042
+ !types.includes(type) && types.push(type);
19043
+ return types;
19044
+ }, []);
19045
+ }
19046
+ }
19047
+
19048
+ class MorphOne extends Relation {
19049
+ /**
19050
+ * Create a new belongs to instance.
19051
+ */
19052
+ constructor(model, related, id, type, localKey) {
19053
+ super(model); /* istanbul ignore next */
19054
+ this.related = this.model.relation(related);
19055
+ this.id = id;
19056
+ this.type = type;
19057
+ this.localKey = localKey;
19058
+ }
19059
+ /**
19060
+ * Define the normalizr schema for the relationship.
19061
+ */
19062
+ define(schema) {
19063
+ return schema.one(this.related);
19064
+ }
19065
+ /**
19066
+ * Attach the relational key to the given data.
19067
+ */
19068
+ attach(key, record, data) {
19069
+ const relatedRecord = data[this.related.entity][key];
19070
+ relatedRecord[this.id] =
19071
+ relatedRecord[this.id] || this.related.getIdFromRecord(record);
19072
+ relatedRecord[this.type] = relatedRecord[this.type] || this.model.entity;
19073
+ }
19074
+ /**
19075
+ * Convert given value to the appropriate value for the attribute.
19076
+ */
19077
+ make(value, _parent, _key) {
19078
+ return this.makeOneRelation(value, this.related);
19079
+ }
19080
+ /**
19081
+ * Load the morph many relationship for the record.
19082
+ */
19083
+ load(query, collection, name, constraints) {
19084
+ const relatedQuery = this.getRelation(query, this.related.entity, constraints);
19085
+ this.addEagerConstraintForMorphOne(relatedQuery, collection, query.entity);
19086
+ const relations = this.mapSingleRelations(relatedQuery.get(), this.id);
19087
+ collection.forEach((item) => {
19088
+ const related = relations.get(item[this.localKey]);
19089
+ item[name] = related || null;
19090
+ });
19091
+ }
19092
+ /**
19093
+ * Set the constraints for an eager load of the relation.
19094
+ */
19095
+ addEagerConstraintForMorphOne(query, collection, type) {
19096
+ query
19097
+ .whereFk(this.type, type)
19098
+ .whereFk(this.id, this.getKeys(collection, this.localKey));
19099
+ }
19100
+ }
19101
+
19102
+ class MorphMany extends Relation {
19103
+ /**
19104
+ * Create a new belongs to instance.
19105
+ */
19106
+ constructor(model, related, id, type, localKey) {
19107
+ super(model); /* istanbul ignore next */
19108
+ this.related = this.model.relation(related);
19109
+ this.id = id;
19110
+ this.type = type;
19111
+ this.localKey = localKey;
19112
+ }
19113
+ /**
19114
+ * Define the normalizr schema for the relationship.
19115
+ */
19116
+ define(schema) {
19117
+ return schema.many(this.related);
19118
+ }
19119
+ /**
19120
+ * Attach the relational key to the given data.
19121
+ */
19122
+ attach(key, record, data) {
19123
+ const relatedItems = data[this.related.entity];
19124
+ key.forEach((id) => {
19125
+ const relatedItem = relatedItems[id];
19126
+ relatedItem[this.id] =
19127
+ relatedItem[this.id] || this.related.getIdFromRecord(record);
19128
+ relatedItem[this.type] = relatedItem[this.type] || this.model.entity;
19129
+ });
19130
+ }
19131
+ /**
19132
+ * Convert given value to the appropriate value for the attribute.
19133
+ */
19134
+ make(value, _parent, _key) {
19135
+ return this.makeManyRelation(value, this.related);
19136
+ }
19137
+ /**
19138
+ * Load the morph many relationship for the record.
19139
+ */
19140
+ load(query, collection, name, constraints) {
19141
+ const relatedQuery = this.getRelation(query, this.related.entity, constraints);
19142
+ this.addEagerConstraintForMorphMany(relatedQuery, collection, query.entity);
19143
+ const relations = this.mapManyRelations(relatedQuery.get(), this.id);
19144
+ collection.forEach((item) => {
19145
+ const related = relations.get(item[this.localKey]);
19146
+ item[name] = related || [];
19147
+ });
19148
+ }
19149
+ /**
19150
+ * Set the constraints for an eager load of the relation.
19151
+ */
19152
+ addEagerConstraintForMorphMany(query, collection, type) {
19153
+ query
19154
+ .whereFk(this.type, type)
19155
+ .whereFk(this.id, this.getKeys(collection, this.localKey));
19156
+ }
19157
+ }
19158
+
19159
+ class MorphToMany extends Relation {
19160
+ /**
19161
+ * Create a new belongs to instance.
19162
+ */
19163
+ constructor(model, related, pivot, relatedId, id, type, parentKey, relatedKey) {
19164
+ super(model); /* istanbul ignore next */
19165
+ /**
19166
+ * The key name of the pivot data.
19167
+ */
19168
+ this.pivotKey = 'pivot';
19169
+ this.related = this.model.relation(related);
19170
+ this.pivot = this.model.relation(pivot);
19171
+ this.relatedId = relatedId;
19172
+ this.id = id;
19173
+ this.type = type;
19174
+ this.parentKey = parentKey;
19175
+ this.relatedKey = relatedKey;
19176
+ }
19177
+ /**
19178
+ * Specify the custom pivot accessor to use for the relationship.
19179
+ */
19180
+ as(accessor) {
19181
+ this.pivotKey = accessor;
19182
+ return this;
19183
+ }
19184
+ /**
19185
+ * Define the normalizr schema for the relationship.
19186
+ */
19187
+ define(schema) {
19188
+ return schema.many(this.related);
19189
+ }
19190
+ /**
19191
+ * Attach the relational key to the given record. Since morph to many
19192
+ * relationship doesn't have any foreign key, it would do nothing.
19193
+ */
19194
+ attach(_key, _record, _data) {
19195
+ return;
19196
+ }
19197
+ /**
19198
+ * Convert given value to the appropriate value for the attribute.
19199
+ */
19200
+ make(value, _parent, _key) {
19201
+ return this.makeManyRelation(value, this.related);
19202
+ }
19203
+ /**
19204
+ * Load the morph to many relationship for the collection.
19205
+ */
19206
+ load(query, collection, name, constraints) {
19207
+ const relatedQuery = this.getRelation(query, this.related.entity, constraints);
19208
+ const pivotQuery = query.newQuery(this.pivot.entity);
19209
+ this.addEagerConstraintForPivot(pivotQuery, collection, query.entity);
19210
+ const pivots = pivotQuery.get();
19211
+ this.addEagerConstraintForRelated(relatedQuery, pivots);
19212
+ const relateds = this.mapPivotRelations(pivots, relatedQuery);
19213
+ collection.forEach((item) => {
19214
+ const related = relateds[item[this.parentKey]];
19215
+ item[name] = related || [];
19216
+ });
19217
+ }
19218
+ /**
19219
+ * Set the constraints for the pivot relation.
19220
+ */
19221
+ addEagerConstraintForPivot(query, collection, type) {
19222
+ query
19223
+ .whereFk(this.type, type)
19224
+ .whereFk(this.id, this.getKeys(collection, this.parentKey));
19225
+ }
19226
+ /**
19227
+ * Set the constraints for the related relation.
19228
+ */
19229
+ addEagerConstraintForRelated(query, collection) {
19230
+ query.whereFk(this.relatedKey, this.getKeys(collection, this.relatedId));
19231
+ }
19232
+ /**
19233
+ * Create a new indexed map for the pivot relation.
19234
+ */
19235
+ mapPivotRelations(pivots, relatedQuery) {
19236
+ const relations = this.mapManyRelations(relatedQuery.get(), this.relatedKey);
19237
+ if (relatedQuery.orders.length) {
19238
+ return this.mapRelationsByOrders(pivots, relations, this.id, this.relatedId);
19239
+ }
19240
+ return pivots.reduce((records, record) => {
19241
+ const id = record[this.id];
19242
+ if (!records[id]) {
19243
+ records[id] = [];
19244
+ }
19245
+ const related = relations.get(record[this.relatedId]);
19246
+ /* istanbul ignore if */
19247
+ if (related === undefined || related.length === 0) {
19248
+ return records;
19249
+ }
19250
+ records[id] = records[id].concat(related.map((model) => {
19251
+ model[this.pivotKey] = record;
19252
+ return model;
19253
+ }));
19254
+ return records;
19255
+ }, {});
19256
+ }
19257
+ /**
19258
+ * Create pivot records for the given records if needed.
19259
+ */
19260
+ createPivots(parent, data, key) {
19261
+ Utils.forOwn(data[parent.entity], (record) => {
19262
+ const relatedIds = parent
19263
+ .query()
19264
+ .newQuery(this.pivot.entity)
19265
+ .where(this.id, record[this.parentKey])
19266
+ .where(this.type, parent.entity)
19267
+ .get();
19268
+ const relateds = (record[key] || []).filter((relatedId) => !relatedIds.includes(relatedId));
19269
+ if (!Utils.isArray(relateds) || relateds.length === 0) {
19270
+ return;
19271
+ }
19272
+ this.createPivotRecord(parent, data, record, relateds);
19273
+ });
19274
+ return data;
19275
+ }
19276
+ /**
19277
+ * Create a pivot record.
19278
+ */
19279
+ createPivotRecord(parent, data, record, related) {
19280
+ related.forEach((id) => {
19281
+ const parentId = record[this.parentKey];
19282
+ const relatedId = data[this.related.entity][id][this.relatedKey];
19283
+ const pivotKey = `${parentId}_${id}_${parent.entity}`;
19284
+ const pivotData = data[this.related.entity][id][this.pivotKey] || {};
19285
+ data[this.pivot.entity] = {
19286
+ ...data[this.pivot.entity],
19287
+ [pivotKey]: {
19288
+ ...pivotData,
19289
+ $id: pivotKey,
19290
+ [this.relatedId]: relatedId,
19291
+ [this.id]: parentId,
19292
+ [this.type]: parent.entity
19293
+ }
19294
+ };
19295
+ });
19296
+ }
19297
+ }
19298
+
19299
+ class MorphedByMany extends Relation {
19300
+ /**
19301
+ * Create a new belongs to instance.
19302
+ */
19303
+ constructor(model, related, pivot, relatedId, id, type, parentKey, relatedKey) {
19304
+ super(model); /* istanbul ignore next */
19305
+ /**
19306
+ * The key name of the pivot data.
19307
+ */
19308
+ this.pivotKey = 'pivot';
19309
+ this.related = this.model.relation(related);
19310
+ this.pivot = this.model.relation(pivot);
19311
+ this.relatedId = relatedId;
19312
+ this.id = id;
19313
+ this.type = type;
19314
+ this.parentKey = parentKey;
19315
+ this.relatedKey = relatedKey;
19316
+ }
19317
+ /**
19318
+ * Specify the custom pivot accessor to use for the relationship.
19319
+ */
19320
+ as(accessor) {
19321
+ this.pivotKey = accessor;
19322
+ return this;
19323
+ }
19324
+ /**
19325
+ * Define the normalizr schema for the relationship.
19326
+ */
19327
+ define(schema) {
19328
+ return schema.many(this.related);
19329
+ }
19330
+ /**
19331
+ * Attach the relational key to the given data. Since morphed by many
19332
+ * relationship doesn't have any foreign key, it would do nothing.
19333
+ */
19334
+ attach(_key, _record, _data) {
19335
+ return;
19336
+ }
19337
+ /**
19338
+ * Make value to be set to model property. This method is used when
19339
+ * instantiating a model or creating a plain object from a model.
19340
+ */
19341
+ make(value, _parent, _key) {
19342
+ return this.makeManyRelation(value, this.related);
19343
+ }
19344
+ /**
19345
+ * Load the morph many relationship for the record.
19346
+ */
19347
+ load(query, collection, name, constraints) {
19348
+ const relatedQuery = this.getRelation(query, this.related.entity, constraints);
19349
+ const pivotQuery = query.newQuery(this.pivot.entity);
19350
+ this.addEagerConstraintForPivot(pivotQuery, collection, this.related.entity);
19351
+ const pivots = pivotQuery.get();
19352
+ this.addEagerConstraintForRelated(relatedQuery, pivots);
19353
+ const relateds = this.mapPivotRelations(pivots, relatedQuery);
19354
+ collection.forEach((item) => {
19355
+ const related = relateds[item[this.parentKey]];
19356
+ item[name] = related || [];
19357
+ });
19358
+ }
19359
+ /**
19360
+ * Set the constraints for the pivot relation.
19361
+ */
19362
+ addEagerConstraintForPivot(query, collection, type) {
19363
+ query
19364
+ .whereFk(this.type, type)
19365
+ .whereFk(this.relatedId, this.getKeys(collection, this.parentKey));
19366
+ }
19367
+ /**
19368
+ * Set the constraints for the related relation.
19369
+ */
19370
+ addEagerConstraintForRelated(query, collection) {
19371
+ query.whereFk(this.relatedKey, this.getKeys(collection, this.id));
19372
+ }
19373
+ /**
19374
+ * Create a new indexed map for the pivot relation.
19375
+ */
19376
+ mapPivotRelations(pivots, relatedQuery) {
19377
+ const relations = this.mapManyRelations(relatedQuery.get(), this.relatedKey);
19378
+ if (relatedQuery.orders.length) {
19379
+ return this.mapRelationsByOrders(pivots, relations, this.relatedId, this.id);
19380
+ }
19381
+ return pivots.reduce((records, record) => {
19382
+ const id = record[this.relatedId];
19383
+ if (!records[id]) {
19384
+ records[id] = [];
19385
+ }
19386
+ const related = relations.get(record[this.id]);
19387
+ /* istanbul ignore if */
19388
+ if (related === undefined || related.length === 0) {
19389
+ return records;
19390
+ }
19391
+ records[id] = records[id].concat(related.map((model) => {
19392
+ model[this.pivotKey] = record;
19393
+ return model;
19394
+ }));
19395
+ return records;
19396
+ }, {});
19397
+ }
19398
+ /**
19399
+ * Create pivot records for the given records if needed.
19400
+ */
19401
+ createPivots(parent, data, key) {
19402
+ Utils.forOwn(data[parent.entity], (record) => {
19403
+ const related = record[key];
19404
+ if (!Utils.isArray(related)) {
19405
+ return;
19406
+ }
19407
+ this.createPivotRecord(data, record, related);
19408
+ });
19409
+ return data;
19410
+ }
19411
+ /**
19412
+ * Create a pivot record.
19413
+ */
19414
+ createPivotRecord(data, record, related) {
19415
+ related.forEach((id) => {
19416
+ const parentId = record[this.parentKey];
19417
+ const pivotKey = `${id}_${parentId}_${this.related.entity}`;
19418
+ const pivotData = data[this.related.entity][id][this.pivotKey] || {};
19419
+ data[this.pivot.entity] = {
19420
+ ...data[this.pivot.entity],
19421
+ [pivotKey]: {
19422
+ ...pivotData,
19423
+ $id: pivotKey,
19424
+ [this.relatedId]: parentId,
19425
+ [this.id]: this.model.getIdFromRecord(data[this.related.entity][id]),
19426
+ [this.type]: this.related.entity
19427
+ }
19428
+ };
19429
+ });
19430
+ }
19431
+ }
19432
+
19433
+ const defaultOption = {
19434
+ relations: true
19435
+ };
19436
+ /**
19437
+ * Serialize the given model to attributes. This method will ignore
19438
+ * relationships, and it includes the index id.
19439
+ */
19440
+ function toAttributes(model) {
19441
+ const record = toJson(model, { relations: false });
19442
+ record.$id = model.$id;
19443
+ return record;
19444
+ }
19445
+ /**
19446
+ * Serialize given model POJO.
19447
+ */
19448
+ function toJson(model, option = {}) {
19449
+ option = { ...defaultOption, ...option };
19450
+ const record = {};
19451
+ const fields = model.$fields();
19452
+ for (const key in fields) {
19453
+ const f = fields[key];
19454
+ const v = model[key];
19455
+ if (f instanceof Relation) {
19456
+ record[key] = option.relations ? relation(v) : emptyRelation(v);
19457
+ continue;
19458
+ }
19459
+ record[key] = value(model[key]);
19460
+ }
19461
+ return record;
19462
+ }
19463
+ /**
19464
+ * Serialize given value.
19465
+ */
19466
+ function value(v) {
19467
+ if (v === null) {
19468
+ return null;
19469
+ }
19470
+ if (isArray(v)) {
19471
+ return array(v);
19472
+ }
19473
+ if (typeof v === 'object') {
19474
+ return object(v);
19475
+ }
19476
+ return v;
19477
+ }
19478
+ /**
19479
+ * Serialize an array into json.
19480
+ */
19481
+ function array(a) {
19482
+ return a.map((v) => value(v));
19483
+ }
19484
+ /**
19485
+ * Serialize an object into json.
19486
+ */
19487
+ function object(o) {
19488
+ const obj = {};
19489
+ for (const key in o) {
19490
+ obj[key] = value(o[key]);
19491
+ }
19492
+ return obj;
19493
+ }
19494
+ function relation(relation) {
19495
+ if (relation === null) {
19496
+ return null;
19497
+ }
19498
+ if (isArray(relation)) {
19499
+ return relation.map((model) => model.$toJson());
19500
+ }
19501
+ return relation.$toJson();
19502
+ }
19503
+ function emptyRelation(relation) {
19504
+ return isArray(relation) ? [] : null;
19505
+ }
19506
+
19507
+ class Model {
19508
+ /**
19509
+ * Create a new model instance.
19510
+ */
19511
+ constructor(record) {
19512
+ /**
19513
+ * The index ID for the model.
19514
+ */
19515
+ this.$id = null;
19516
+ this.$fill(record);
19517
+ }
19518
+ /**
19519
+ * The definition of the fields of the model and its relations.
19520
+ */
19521
+ static fields() {
19522
+ return {};
19523
+ }
19524
+ /**
19525
+ * Create an attr attribute.
19526
+ */
19527
+ static attr(value, mutator) {
19528
+ return new Attr(this, value, mutator);
19529
+ }
19530
+ /**
19531
+ * Create a string attribute.
19532
+ */
19533
+ static string(value, mutator) {
19534
+ return new String$1(this, value, mutator);
19535
+ }
19536
+ /**
19537
+ * Create a number attribute.
19538
+ */
19539
+ static number(value, mutator) {
19540
+ return new Number$1(this, value, mutator);
19541
+ }
19542
+ /**
19543
+ * Create a boolean attribute.
19544
+ */
19545
+ static boolean(value, mutator) {
19546
+ return new Boolean$1(this, value, mutator);
19547
+ }
19548
+ /**
19549
+ * Create an uid attribute.
19550
+ */
19551
+ static uid(value) {
19552
+ return new Uid(this, value);
19553
+ }
19554
+ /**
19555
+ * @deprecated Use `uid` attribute instead.
19556
+ */
19557
+ static increment() {
19558
+ /* istanbul ignore next */
19559
+ {
19560
+ console.warn('[Vuex ORM] Attribute type `increment` has been deprecated and replaced with `uid`.');
19561
+ }
19562
+ return this.uid();
19563
+ }
19564
+ /**
19565
+ * Create a has one relationship.
19566
+ */
19567
+ static hasOne(related, foreignKey, localKey) {
19568
+ return new HasOne(this, related, foreignKey, this.localKey(localKey));
19569
+ }
19570
+ /**
19571
+ * Create a belongs to relationship.
19572
+ */
19573
+ static belongsTo(parent, foreignKey, ownerKey) {
19574
+ return new BelongsTo(this, parent, foreignKey, this.relation(parent).localKey(ownerKey));
19575
+ }
19576
+ /**
19577
+ * Create a has many relationship.
19578
+ */
19579
+ static hasMany(related, foreignKey, localKey) {
19580
+ return new HasMany(this, related, foreignKey, this.localKey(localKey));
19581
+ }
19582
+ /**
19583
+ * Create a has many by relationship.
19584
+ */
19585
+ static hasManyBy(parent, foreignKey, ownerKey) {
19586
+ return new HasManyBy(this, parent, foreignKey, this.relation(parent).localKey(ownerKey));
19587
+ }
19588
+ /**
19589
+ * Create a has many through relationship.
19590
+ */
19591
+ static hasManyThrough(related, through, firstKey, secondKey, localKey, secondLocalKey) {
19592
+ return new HasManyThrough(this, related, through, firstKey, secondKey, this.localKey(localKey), this.relation(through).localKey(secondLocalKey));
19593
+ }
19594
+ /**
19595
+ * Create a belongs to many relationship.
19596
+ */
19597
+ static belongsToMany(related, pivot, foreignPivotKey, relatedPivotKey, parentKey, relatedKey) {
19598
+ return new BelongsToMany(this, related, pivot, foreignPivotKey, relatedPivotKey, this.localKey(parentKey), this.relation(related).localKey(relatedKey));
19599
+ }
19600
+ /**
19601
+ * Create a morph to relationship.
19602
+ */
19603
+ static morphTo(id, type) {
19604
+ return new MorphTo(this, id, type);
19605
+ }
19606
+ /**
19607
+ * Create a morph one relationship.
19608
+ */
19609
+ static morphOne(related, id, type, localKey) {
19610
+ return new MorphOne(this, related, id, type, this.localKey(localKey));
19611
+ }
19612
+ /**
19613
+ * Create a morph many relationship.
19614
+ */
19615
+ static morphMany(related, id, type, localKey) {
19616
+ return new MorphMany(this, related, id, type, this.localKey(localKey));
19617
+ }
19618
+ /**
19619
+ * Create a morph to many relationship.
19620
+ */
19621
+ static morphToMany(related, pivot, relatedId, id, type, parentKey, relatedKey) {
19622
+ return new MorphToMany(this, related, pivot, relatedId, id, type, this.localKey(parentKey), this.relation(related).localKey(relatedKey));
19623
+ }
19624
+ /**
19625
+ * Create a morphed by many relationship.
19626
+ */
19627
+ static morphedByMany(related, pivot, relatedId, id, type, parentKey, relatedKey) {
19628
+ return new MorphedByMany(this, related, pivot, relatedId, id, type, this.localKey(parentKey), this.relation(related).localKey(relatedKey));
19629
+ }
19630
+ /**
19631
+ * Mutators to mutate matching fields when instantiating the model.
19632
+ */
19633
+ static mutators() {
19634
+ return {};
19635
+ }
19636
+ /**
19637
+ * Types mapping used to dispatch entities based on their discriminator field
19638
+ */
19639
+ static types() {
19640
+ return {};
19641
+ }
19642
+ /**
19643
+ * Get the store instance from the container.
19644
+ */
19645
+ static store() {
19646
+ return Container.store;
19647
+ }
19648
+ /**
19649
+ * Get the database instance from store.
19650
+ */
19651
+ static database() {
19652
+ return this.store().$db();
19653
+ }
19654
+ /**
19655
+ * Create a namespaced method name for Vuex Module from the given
19656
+ * method name.
19657
+ */
19658
+ static namespace(method) {
19659
+ return `${this.database().namespace}/${this.entity}/${method}`;
19660
+ }
19661
+ /**
19662
+ * Call Vuex Getters.
19663
+ */
19664
+ static getters(method) {
19665
+ return this.store().getters[this.namespace(method)];
19666
+ }
19667
+ /**
19668
+ * Dispatch Vuex Action.
19669
+ */
19670
+ static dispatch(method, payload) {
19671
+ return this.store().dispatch(this.namespace(method), payload);
19672
+ }
19673
+ /**
19674
+ * Commit Vuex Mutation.
19675
+ */
19676
+ static commit(callback) {
19677
+ this.store().commit(`${this.database().namespace}/$mutate`, {
19678
+ entity: this.entity,
19679
+ callback
19680
+ });
19681
+ }
19682
+ /**
19683
+ * Get the Model schema definition from the cache.
19684
+ */
19685
+ static getFields() {
19686
+ if (!this.cachedFields) {
19687
+ this.cachedFields = {};
19688
+ }
19689
+ if (this.cachedFields[this.entity]) {
19690
+ return this.cachedFields[this.entity];
19691
+ }
19692
+ this.cachedFields[this.entity] = this.fields();
19693
+ return this.cachedFields[this.entity];
19694
+ }
19695
+ /**
19696
+ * Get all records.
19697
+ */
19698
+ static all() {
19699
+ return this.getters('all')();
19700
+ }
19701
+ /**
19702
+ * Find a record.
19703
+ */
19704
+ static find(id) {
19705
+ return this.getters('find')(id);
19706
+ }
19707
+ /**
19708
+ * Get the record of the given array of ids.
19709
+ */
19710
+ static findIn(idList) {
19711
+ return this.getters('findIn')(idList);
19712
+ }
19713
+ /**
19714
+ * Get query instance.
19715
+ */
19716
+ static query() {
19717
+ return this.getters('query')();
19718
+ }
19719
+ /**
19720
+ * Check wether the associated database contains data.
19721
+ */
19722
+ static exists() {
19723
+ return this.query().exists();
19724
+ }
19725
+ /**
19726
+ * Create new data with all fields filled by default values.
19727
+ */
19728
+ static new() {
19729
+ return this.dispatch('new');
19730
+ }
19731
+ /**
19732
+ * Save given data to the store by replacing all existing records in the
19733
+ * store. If you want to save data without replacing existing records,
19734
+ * use the `insert` method instead.
19735
+ */
19736
+ static create(payload) {
19737
+ return this.dispatch('create', payload);
19738
+ }
19739
+ /**
19740
+ * Insert records.
19741
+ */
19742
+ static insert(payload) {
19743
+ return this.dispatch('insert', payload);
19744
+ }
19745
+ /**
19746
+ * Update records.
19747
+ */
19748
+ static update(payload) {
19749
+ return this.dispatch('update', payload);
19750
+ }
19751
+ /**
19752
+ * Insert or update records.
19753
+ */
19754
+ static insertOrUpdate(payload) {
19755
+ return this.dispatch('insertOrUpdate', payload);
19756
+ }
19757
+ static delete(payload) {
19758
+ return this.dispatch('delete', payload);
19759
+ }
19760
+ /**
19761
+ * Delete all records from the store.
19762
+ */
19763
+ static deleteAll() {
19764
+ return this.dispatch('deleteAll');
19765
+ }
19766
+ /**
19767
+ * Check if the given key is the primary key. If the model has composite
19768
+ * primary key, this method is going to check if the given key is included
19769
+ * in the composite key.
19770
+ */
19771
+ static isPrimaryKey(key) {
19772
+ if (!Utils.isArray(this.primaryKey)) {
19773
+ return this.primaryKey === key;
19774
+ }
19775
+ return this.primaryKey.includes(key);
19776
+ }
19777
+ /**
19778
+ * Check if the primary key is a composite key.
19779
+ */
19780
+ static isCompositePrimaryKey() {
19781
+ return Utils.isArray(this.primaryKey);
19782
+ }
19783
+ /**
19784
+ * Get the id (value of primary key) from teh given record. If primary key is
19785
+ * not present, or it is invalid primary key value, which is other than
19786
+ * `string` or `number`, it's going to return `null`.
19787
+ *
19788
+ * If the model has composite key, it's going to return array of ids. If any
19789
+ * composite key missing, it will return `null`.
19790
+ */
19791
+ static getIdFromRecord(record) {
19792
+ const key = this.primaryKey;
19793
+ if (typeof key === 'string') {
19794
+ return this.getIdFromValue(record[key]);
19795
+ }
19796
+ const ids = key.reduce((keys, k) => {
19797
+ const id = this.getIdFromValue(record[k]);
19798
+ id !== null && keys.push(id);
19799
+ return keys;
19800
+ }, []);
19801
+ return ids.length === key.length ? ids : null;
19802
+ }
19803
+ /**
19804
+ * Get correct index id, which is `string` | `number`, from the given value.
19805
+ */
19806
+ static getIdFromValue(value) {
19807
+ if (typeof value === 'string' && value !== '') {
19808
+ return value;
19809
+ }
19810
+ if (typeof value === 'number') {
19811
+ return value;
19812
+ }
19813
+ return null;
19814
+ }
19815
+ /**
19816
+ * Get the index ID value from the given record. An index ID is a value that
19817
+ * used as a key for records within the Vuex Store.
19818
+ *
19819
+ * Most of the time, it's same as the value for the Model's primary key but
19820
+ * it's always `string`, even if the primary key value is `number`.
19821
+ *
19822
+ * If the Model has a composite primary key, each value corresponding to
19823
+ * those primary key will be stringified and become a single string value
19824
+ * such as `'[1,2]'`.
19825
+ *
19826
+ * If the primary key is not present at the given record, it returns `null`.
19827
+ * For the composite primary key, every key must exist at a given record,
19828
+ * or it will return `null`.
19829
+ */
19830
+ static getIndexIdFromRecord(record) {
19831
+ const id = this.getIdFromRecord(record);
19832
+ if (id === null) {
19833
+ return null;
19834
+ }
19835
+ if (Utils.isArray(id)) {
19836
+ return JSON.stringify(id);
19837
+ }
19838
+ return String(id);
19839
+ }
19840
+ /**
19841
+ * Get local key to pass to the attributes.
19842
+ */
19843
+ static localKey(key) {
19844
+ if (key) {
19845
+ return key;
19846
+ }
19847
+ return typeof this.primaryKey === 'string' ? this.primaryKey : 'id';
19848
+ }
19849
+ /**
19850
+ * Get the model object that matches the given record type. The method is for
19851
+ * getting the correct model object when the model has any inheritance
19852
+ * children model.
19853
+ *
19854
+ * For example, if a User Model have `static types()` declared, and if you
19855
+ * pass record with `{ type: 'admin' }`, then the method will likely to
19856
+ * return SuperUser class.
19857
+ */
19858
+ static getModelFromRecord(record) {
19859
+ // If the given record is already a model instance, return the
19860
+ // model object.
19861
+ if (record instanceof this) {
19862
+ return record.$self();
19863
+ }
19864
+ // Else, get the corresponding model for the type value if there's any.
19865
+ return this.getTypeModel(record[this.typeKey]);
19866
+ }
19867
+ /**
19868
+ * Get a model from the container.
19869
+ */
19870
+ static relation(model) {
19871
+ if (typeof model !== 'string') {
19872
+ return model;
19873
+ }
19874
+ return this.database().model(model);
19875
+ }
19876
+ /**
19877
+ * Get all `belongsToMany` fields from the schema.
19878
+ */
19879
+ static pivotFields() {
19880
+ const fields = [];
19881
+ Utils.forOwn(this.getFields(), (field, key) => {
19882
+ if (field instanceof BelongsToMany ||
19883
+ field instanceof MorphToMany ||
19884
+ field instanceof MorphedByMany) {
19885
+ fields.push({ [key]: field });
19886
+ }
19887
+ });
19888
+ return fields;
19889
+ }
19890
+ /**
19891
+ * Check if fields contains the `belongsToMany` field type.
19892
+ */
19893
+ static hasPivotFields() {
19894
+ return this.pivotFields().length > 0;
19895
+ }
19896
+ /**
19897
+ * Check if the current model has a type definition
19898
+ */
19899
+ static hasTypes() {
19900
+ return Object.keys(this.types()).length > 0;
19901
+ }
19902
+ /**
19903
+ * Get the model corresponding to the given type name. If it can't be found,
19904
+ * it'll return `null`.
19905
+ */
19906
+ static getTypeModel(name) {
19907
+ const model = this.types()[name];
19908
+ if (!model) {
19909
+ return null;
19910
+ }
19911
+ return model;
19912
+ }
19913
+ /**
19914
+ * Given a Model, this returns the corresponding key in the InheritanceTypes mapping
19915
+ */
19916
+ static getTypeKeyValueFromModel(model) {
19917
+ const modelToCheck = model || this;
19918
+ const types = this.types();
19919
+ for (const type in types) {
19920
+ if (types[type].entity === modelToCheck.entity) {
19921
+ return type;
19922
+ }
19923
+ }
19924
+ return null;
19925
+ }
19926
+ /**
19927
+ * Tries to find a Relation field in all types defined in the InheritanceTypes mapping
19928
+ */
19929
+ static findRelationInSubTypes(relationName) {
19930
+ const types = this.types();
19931
+ for (const type in types) {
19932
+ const fields = types[type].getFields();
19933
+ for (const fieldName in fields) {
19934
+ if (fieldName === relationName &&
19935
+ fields[fieldName] instanceof Relation) {
19936
+ return fields[fieldName];
19937
+ }
19938
+ }
19939
+ }
19940
+ return null;
19941
+ }
19942
+ /**
19943
+ * Fill any missing fields in the given record with the default value defined
19944
+ * in the model schema.
19945
+ */
19946
+ static hydrate(record) {
19947
+ return new this(record).$getAttributes();
19948
+ }
19949
+ /**
19950
+ * Get the constructor of this model.
19951
+ */
19952
+ $self() {
19953
+ return this.constructor;
19954
+ }
19955
+ /**
19956
+ * Get the primary key for the model.
19957
+ */
19958
+ $primaryKey() {
19959
+ return this.$self().primaryKey;
19960
+ }
19961
+ /**
19962
+ * The definition of the fields of the model and its relations.
19963
+ */
19964
+ $fields() {
19965
+ return this.$self().getFields();
19966
+ }
19967
+ /**
19968
+ * Set index id.
19969
+ */
19970
+ $setIndexId(id) {
19971
+ this.$id = id;
19972
+ return this;
19973
+ }
19974
+ /**
19975
+ * Get the store instance from the container.
19976
+ */
19977
+ $store() {
19978
+ return this.$self().store();
19979
+ }
19980
+ /**
19981
+ * Create a namespaced method name for Vuex Module from the given
19982
+ * method name.
19983
+ */
19984
+ $namespace(method) {
19985
+ return this.$self().namespace(method);
19986
+ }
19987
+ /**
19988
+ * Call Vuex Getetrs.
19989
+ */
19990
+ $getters(method) {
19991
+ return this.$self().getters(method);
19992
+ }
19993
+ /**
19994
+ * Dispatch Vuex Action.
19995
+ */
19996
+ async $dispatch(method, payload) {
19997
+ return this.$self().dispatch(method, payload);
19998
+ }
19999
+ /**
20000
+ * Get all records.
20001
+ */
20002
+ $all() {
20003
+ return this.$getters('all')();
20004
+ }
20005
+ /**
20006
+ * Find a record.
20007
+ */
20008
+ $find(id) {
20009
+ return this.$getters('find')(id);
20010
+ }
20011
+ /**
20012
+ * Find record of the given array of ids.
20013
+ */
20014
+ $findIn(idList) {
20015
+ return this.$getters('findIn')(idList);
20016
+ }
20017
+ /**
20018
+ * Get query instance.
20019
+ */
20020
+ $query() {
20021
+ return this.$getters('query')();
20022
+ }
20023
+ /**
20024
+ * Create records.
20025
+ */
20026
+ async $create(payload) {
20027
+ return this.$dispatch('create', payload);
20028
+ }
20029
+ /**
20030
+ * Create records.
20031
+ */
20032
+ async $insert(payload) {
20033
+ return this.$dispatch('insert', payload);
20034
+ }
20035
+ /**
20036
+ * Update records.
20037
+ */
20038
+ async $update(payload) {
20039
+ if (Utils.isArray(payload)) {
20040
+ return this.$dispatch('update', payload);
20041
+ }
20042
+ if (payload.where !== undefined) {
20043
+ return this.$dispatch('update', payload);
20044
+ }
20045
+ if (this.$self().getIndexIdFromRecord(payload) === null) {
20046
+ return this.$dispatch('update', {
20047
+ where: this.$self().getIdFromRecord(this),
20048
+ data: payload
20049
+ });
20050
+ }
20051
+ return this.$dispatch('update', payload);
20052
+ }
20053
+ /**
20054
+ * Insert or update records.
20055
+ */
20056
+ async $insertOrUpdate(payload) {
20057
+ return this.$dispatch('insertOrUpdate', payload);
20058
+ }
20059
+ /**
20060
+ * Save record.
20061
+ */
20062
+ async $save() {
20063
+ const fields = this.$self().getFields();
20064
+ const record = Object.keys(fields).reduce((record, key) => {
20065
+ if (fields[key] instanceof Type) {
20066
+ record[key] = this[key];
20067
+ }
20068
+ return record;
20069
+ }, {});
20070
+ const records = await this.$dispatch('insertOrUpdate', { data: record });
20071
+ this.$fill(records[this.$self().entity][0]);
20072
+ return this;
20073
+ }
20074
+ /**
20075
+ * Delete records that matches the given condition.
20076
+ */
20077
+ async $delete() {
20078
+ const primaryKey = this.$primaryKey();
20079
+ if (!Utils.isArray(primaryKey)) {
20080
+ return this.$dispatch('delete', this[primaryKey]);
20081
+ }
20082
+ return this.$dispatch('delete', (model) => {
20083
+ return primaryKey.every((id) => model[id] === this[id]);
20084
+ });
20085
+ }
20086
+ /**
20087
+ * Delete all records.
20088
+ */
20089
+ async $deleteAll() {
20090
+ return this.$dispatch('deleteAll');
20091
+ }
20092
+ /**
20093
+ * Fill the model instance with the given record. If no record were passed,
20094
+ * or if the record has any missing fields, each value of the fields will
20095
+ * be filled with its default value defined at model fields definition.
20096
+ */
20097
+ $fill(record = {}) {
20098
+ const fields = this.$fields();
20099
+ for (const key in fields) {
20100
+ const field = fields[key];
20101
+ const value = record[key];
20102
+ this[key] = field.make(value, record, key);
20103
+ }
20104
+ // If the record contains index id, set it to the model.
20105
+ record.$id !== undefined && this.$setIndexId(record.$id);
20106
+ }
20107
+ /**
20108
+ * Generate missing primary ids and index id.
20109
+ */
20110
+ $generateId() {
20111
+ return this.$generatePrimaryId().$generateIndexId();
20112
+ }
20113
+ /**
20114
+ * Generate any missing primary ids.
20115
+ */
20116
+ $generatePrimaryId() {
20117
+ const key = this.$self().primaryKey;
20118
+ const keys = Utils.isArray(key) ? key : [key];
20119
+ keys.forEach((k) => {
20120
+ if (this[k] === undefined || this[k] === null) {
20121
+ this[k] = Uid$1.make();
20122
+ }
20123
+ });
20124
+ return this;
20125
+ }
20126
+ /**
20127
+ * Generate index id from current model attributes.
20128
+ */
20129
+ $generateIndexId() {
20130
+ return this.$setIndexId(this.$getIndexIdFromAttributes());
20131
+ }
20132
+ /**
20133
+ * Get index id based on current model attributes.
20134
+ */
20135
+ $getIndexIdFromAttributes() {
20136
+ return this.$self().getIndexIdFromRecord(this);
20137
+ }
20138
+ /**
20139
+ * Get all of the current attributes on the model. It includes index id
20140
+ * value as well. This method is mainly used when saving a model to
20141
+ * the store.
20142
+ */
20143
+ $getAttributes() {
20144
+ return toAttributes(this);
20145
+ }
20146
+ /**
20147
+ * Serialize field values into json.
20148
+ */
20149
+ $toJson() {
20150
+ return toJson(this);
20151
+ }
20152
+ }
20153
+ /**
20154
+ * The primary key to be used for the model.
20155
+ */
20156
+ Model.primaryKey = 'id';
20157
+ /**
20158
+ * The discriminator key to be used for the model when inheritance is used
20159
+ */
20160
+ Model.typeKey = 'type';
20161
+ /**
20162
+ * Vuex Store state definition.
20163
+ */
20164
+ Model.state = {};
20165
+
17018
20166
  var e=[],t=[];function n(n,r){if(n&&"undefined"!=typeof document){var a,s=!0===r.prepend?"prepend":"append",d=!0===r.singleTag,i="string"==typeof r.container?document.querySelector(r.container):document.getElementsByTagName("head")[0];if(d){var u=e.indexOf(i);-1===u&&(u=e.push(i)-1,t[u]={}),a=t[u]&&t[u][s]?t[u][s]:t[u][s]=c();}else a=c();65279===n.charCodeAt(0)&&(n=n.substring(1)),a.styleSheet?a.styleSheet.cssText+=n:a.appendChild(document.createTextNode(n));}function c(){var e=document.createElement("style");if(e.setAttribute("type","text/css"),r.attributes)for(var t=Object.keys(r.attributes),n=0;n<t.length;n++)e.setAttribute(t[n],r.attributes[t[n]]);var a="prepend"===s?"afterbegin":"beforeend";return i.insertAdjacentElement(a,e),e}}
17019
20167
 
17020
- var css = "tr td[data-v-55366deb]:last-child,\ntr td[data-v-55366deb]:first-child {\n width: 1%;\n white-space: nowrap; }\n\n.crud-pagination[data-v-55366deb] {\n display: flex;\n justify-content: center; }\n\n.crud-header[data-v-55366deb] {\n display: flex;\n justify-content: space-between;\n max-height: 3rem; }\n .crud-header[data-v-55366deb] .crud-title[data-v-55366deb] {\n margin: 0; }\n .crud-header[data-v-55366deb] .crud-search[data-v-55366deb] {\n max-width: 15rem; }\n .crud-header[data-v-55366deb] .crud-search[data-v-55366deb] .btn[data-v-55366deb] {\n border-top-left-radius: 0;\n border-bottom-left-radius: 0;\n border-top-right-radius: 0.375rem;\n border-bottom-right-radius: 0.375rem; }\n .crud-header[data-v-55366deb] .crud-search[data-v-55366deb] .btn[data-v-55366deb].open[data-v-55366deb] {\n border-top-right-radius: 0;\n border-bottom-right-radius: 0; }\n .crud-header[data-v-55366deb] .table-options[data-v-55366deb] {\n margin-bottom: 1rem;\n display: flex;\n align-items: center;\n justify-content: flex-end; }\n\n.custom-control[data-v-55366deb] {\n position: relative;\n top: -15px; }\n\n@media (min-width: 992px) {\n .table[data-v-55366deb] {\n table-layout: auto; }\n .table[data-v-55366deb] tbody[data-v-55366deb] td[data-v-55366deb] {\n overflow: scroll;\n -ms-overflow-style: none;\n /* IE and Edge */\n scrollbar-width: none;\n /* Firefox */ }\n .table[data-v-55366deb] tbody[data-v-55366deb] td[data-v-55366deb]::-webkit-scrollbar {\n display: none; } }\n";
20168
+ var css = "tr td[data-v-a30060f8]:last-child,\ntr td[data-v-a30060f8]:first-child {\n width: 1%;\n white-space: nowrap; }\n\n.crud-pagination[data-v-a30060f8] {\n display: flex;\n justify-content: center; }\n\n.crud-header[data-v-a30060f8] {\n display: flex;\n justify-content: space-between;\n max-height: 3rem; }\n .crud-header[data-v-a30060f8] .crud-title[data-v-a30060f8] {\n margin: 0; }\n .crud-header[data-v-a30060f8] .crud-search[data-v-a30060f8] {\n max-width: 15rem; }\n .crud-header[data-v-a30060f8] .crud-search[data-v-a30060f8] .btn[data-v-a30060f8] {\n border-top-left-radius: 0;\n border-bottom-left-radius: 0;\n border-top-right-radius: 0.375rem;\n border-bottom-right-radius: 0.375rem; }\n .crud-header[data-v-a30060f8] .crud-search[data-v-a30060f8] .btn[data-v-a30060f8].open[data-v-a30060f8] {\n border-top-right-radius: 0;\n border-bottom-right-radius: 0; }\n .crud-header[data-v-a30060f8] .table-options[data-v-a30060f8] {\n margin-bottom: 1rem;\n display: flex;\n align-items: center;\n justify-content: flex-end; }\n\n.custom-control[data-v-a30060f8] {\n position: relative;\n top: -15px; }\n\n@media (min-width: 992px) {\n .table[data-v-a30060f8] {\n table-layout: auto; }\n .table[data-v-a30060f8] tbody[data-v-a30060f8] td[data-v-a30060f8] {\n overflow: scroll;\n -ms-overflow-style: none;\n /* IE and Edge */\n scrollbar-width: none;\n /* Firefox */ }\n .table[data-v-a30060f8] tbody[data-v-a30060f8] td[data-v-a30060f8]::-webkit-scrollbar {\n display: none; } }\n";
17021
20169
  n(css, {});
17022
20170
 
17023
20171
  function normalizeComponent (
@@ -17113,8 +20261,6 @@ function normalizeComponent (
17113
20261
  }
17114
20262
  }
17115
20263
 
17116
- //import { Model, Collection } from 'vue-mc';
17117
-
17118
20264
  const _sfc_main = {
17119
20265
  name: "VueLaravelCrud",
17120
20266
  components: {
@@ -17149,8 +20295,7 @@ const _sfc_main = {
17149
20295
  MODE_CARDS: 2,
17150
20296
  MODE_CUSTOM: 3
17151
20297
  },
17152
- useMc: false,
17153
- collection
20298
+ useVuexORM: false
17154
20299
  };
17155
20300
  },
17156
20301
  watch: {
@@ -17365,14 +20510,12 @@ const _sfc_main = {
17365
20510
  }
17366
20511
  },
17367
20512
  mounted() {
17368
- /*if (this.model instanceof Model) {
17369
- this.useMc = true;
17370
- this.collection = new Collection();
17371
- } else {*/
17372
- this.item = this.model;
17373
- this.itemDefault = JSON.parse(JSON.stringify(this.item));
17374
- //}
17375
-
20513
+ if (this.model instanceof Model) {
20514
+ this.useVuexORM = true;
20515
+ } else {
20516
+ this.item = this.model;
20517
+ this.itemDefault = JSON.parse(JSON.stringify(this.item));
20518
+ }
17376
20519
  this.internalFilters = [];
17377
20520
  this.setupFilters();
17378
20521
  if (this.ajax) {
@@ -17410,7 +20553,7 @@ const _sfc_main = {
17410
20553
  },*/
17411
20554
 
17412
20555
  finalFilters() {
17413
- return this.filters.concat(this.filter).concat(this.internalFilter);
20556
+ return [...this.filters, ...this.filter, ...this.internalFilter];
17414
20557
  },
17415
20558
  internalFilter() {
17416
20559
  let filter = [];
@@ -17616,7 +20759,7 @@ const _sfc_main = {
17616
20759
  return;
17617
20760
  }
17618
20761
  this.$emit("beforeFetch", {});
17619
- if (this.useMc) ;
20762
+ if (this.useVuexORM) ;
17620
20763
  this.loading = true;
17621
20764
  axios.get(this.apiUrl + "/" + this.modelName, {
17622
20765
  params: {
@@ -18747,7 +21890,7 @@ var _sfc_render = function render() {
18747
21890
  })], 2)], 1);
18748
21891
  };
18749
21892
  var _sfc_staticRenderFns = [];
18750
- var __component__ = /*#__PURE__*/normalizeComponent(_sfc_main, _sfc_render, _sfc_staticRenderFns, false, null, "55366deb", null, null);
21893
+ var __component__ = /*#__PURE__*/normalizeComponent(_sfc_main, _sfc_render, _sfc_staticRenderFns, false, null, "a30060f8", null, null);
18751
21894
  var component = __component__.exports;
18752
21895
 
18753
21896
  // Import vue component