vue-laravel-crud 1.4.12 → 1.4.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/vue-laravel-crud.esm.js +37 -3178
- package/dist/vue-laravel-crud.min.js +3 -3
- package/dist/vue-laravel-crud.ssr.js +40 -3179
- package/package.json +5 -2
- package/src/vue-laravel-crud.vue +14 -4
|
@@ -6557,11 +6557,11 @@ var draggable = /*@__PURE__*/getDefaultExportFromCjs(vuedraggable_umdExports);va
|
|
|
6557
6557
|
};
|
|
6558
6558
|
}// utils is a library of generic helper functions non-specific to axios
|
|
6559
6559
|
|
|
6560
|
-
const {toString: toString$
|
|
6560
|
+
const {toString: toString$1} = Object.prototype;
|
|
6561
6561
|
const {getPrototypeOf} = Object;
|
|
6562
6562
|
|
|
6563
6563
|
const kindOf = (cache => thing => {
|
|
6564
|
-
const str = toString$
|
|
6564
|
+
const str = toString$1.call(thing);
|
|
6565
6565
|
return cache[str] || (cache[str] = str.slice(8, -1).toLowerCase());
|
|
6566
6566
|
})(Object.create(null));
|
|
6567
6567
|
|
|
@@ -6579,7 +6579,7 @@ const typeOfTest = type => thing => typeof thing === type;
|
|
|
6579
6579
|
*
|
|
6580
6580
|
* @returns {boolean} True if value is an Array, otherwise false
|
|
6581
6581
|
*/
|
|
6582
|
-
const {isArray: isArray$
|
|
6582
|
+
const {isArray: isArray$1} = Array;
|
|
6583
6583
|
|
|
6584
6584
|
/**
|
|
6585
6585
|
* Determine if a value is undefined
|
|
@@ -6744,7 +6744,7 @@ const isFormData = (thing) => {
|
|
|
6744
6744
|
const pattern = '[object FormData]';
|
|
6745
6745
|
return thing && (
|
|
6746
6746
|
(typeof FormData === 'function' && thing instanceof FormData) ||
|
|
6747
|
-
toString$
|
|
6747
|
+
toString$1.call(thing) === pattern ||
|
|
6748
6748
|
(isFunction(thing.toString) && thing.toString() === pattern)
|
|
6749
6749
|
);
|
|
6750
6750
|
};
|
|
@@ -6798,7 +6798,7 @@ function forEach(obj, fn, {allOwnKeys = false} = {}) {
|
|
|
6798
6798
|
obj = [obj];
|
|
6799
6799
|
}
|
|
6800
6800
|
|
|
6801
|
-
if (isArray$
|
|
6801
|
+
if (isArray$1(obj)) {
|
|
6802
6802
|
// Iterate over array values
|
|
6803
6803
|
for (i = 0, l = obj.length; i < l; i++) {
|
|
6804
6804
|
fn.call(null, obj[i], i, obj);
|
|
@@ -6830,13 +6830,13 @@ function findKey(obj, key) {
|
|
|
6830
6830
|
return null;
|
|
6831
6831
|
}
|
|
6832
6832
|
|
|
6833
|
-
const _global
|
|
6833
|
+
const _global = (() => {
|
|
6834
6834
|
/*eslint no-undef:0*/
|
|
6835
6835
|
if (typeof globalThis !== "undefined") return globalThis;
|
|
6836
6836
|
return typeof self !== "undefined" ? self : (typeof window !== 'undefined' ? window : global$1)
|
|
6837
6837
|
})();
|
|
6838
6838
|
|
|
6839
|
-
const isContextDefined = (context) => !isUndefined(context) && context !== _global
|
|
6839
|
+
const isContextDefined = (context) => !isUndefined(context) && context !== _global;
|
|
6840
6840
|
|
|
6841
6841
|
/**
|
|
6842
6842
|
* Accepts varargs expecting each argument to be an object, then
|
|
@@ -6865,7 +6865,7 @@ function merge(/* obj1, obj2, obj3, ... */) {
|
|
|
6865
6865
|
result[targetKey] = merge(result[targetKey], val);
|
|
6866
6866
|
} else if (isPlainObject(val)) {
|
|
6867
6867
|
result[targetKey] = merge({}, val);
|
|
6868
|
-
} else if (isArray$
|
|
6868
|
+
} else if (isArray$1(val)) {
|
|
6869
6869
|
result[targetKey] = val.slice();
|
|
6870
6870
|
} else {
|
|
6871
6871
|
result[targetKey] = val;
|
|
@@ -6995,7 +6995,7 @@ const endsWith = (str, searchString, position) => {
|
|
|
6995
6995
|
*/
|
|
6996
6996
|
const toArray = (thing) => {
|
|
6997
6997
|
if (!thing) return null;
|
|
6998
|
-
if (isArray$
|
|
6998
|
+
if (isArray$1(thing)) return thing;
|
|
6999
6999
|
let i = thing.length;
|
|
7000
7000
|
if (!isNumber(i)) return null;
|
|
7001
7001
|
const arr = new Array(i);
|
|
@@ -7073,7 +7073,7 @@ const toCamelCase = str => {
|
|
|
7073
7073
|
};
|
|
7074
7074
|
|
|
7075
7075
|
/* Creating a function that will check if an object has a property. */
|
|
7076
|
-
const hasOwnProperty
|
|
7076
|
+
const hasOwnProperty = (({hasOwnProperty}) => (obj, prop) => hasOwnProperty.call(obj, prop))(Object.prototype);
|
|
7077
7077
|
|
|
7078
7078
|
/**
|
|
7079
7079
|
* Determine if a value is a RegExp object
|
|
@@ -7137,7 +7137,7 @@ const toObjectSet = (arrayOrString, delimiter) => {
|
|
|
7137
7137
|
});
|
|
7138
7138
|
};
|
|
7139
7139
|
|
|
7140
|
-
isArray$
|
|
7140
|
+
isArray$1(arrayOrString) ? define(arrayOrString) : define(String(arrayOrString).split(delimiter));
|
|
7141
7141
|
|
|
7142
7142
|
return obj;
|
|
7143
7143
|
};
|
|
@@ -7192,7 +7192,7 @@ const toJSONObject = (obj) => {
|
|
|
7192
7192
|
|
|
7193
7193
|
if(!('toJSON' in source)) {
|
|
7194
7194
|
stack[i] = source;
|
|
7195
|
-
const target = isArray$
|
|
7195
|
+
const target = isArray$1(source) ? [] : {};
|
|
7196
7196
|
|
|
7197
7197
|
forEach(source, (value, key) => {
|
|
7198
7198
|
const reducedValue = visit(value, i + 1);
|
|
@@ -7212,7 +7212,7 @@ const toJSONObject = (obj) => {
|
|
|
7212
7212
|
};
|
|
7213
7213
|
|
|
7214
7214
|
var utils = {
|
|
7215
|
-
isArray: isArray$
|
|
7215
|
+
isArray: isArray$1,
|
|
7216
7216
|
isArrayBuffer,
|
|
7217
7217
|
isBuffer: isBuffer$1,
|
|
7218
7218
|
isFormData,
|
|
@@ -7246,8 +7246,8 @@ var utils = {
|
|
|
7246
7246
|
forEachEntry,
|
|
7247
7247
|
matchAll,
|
|
7248
7248
|
isHTMLForm,
|
|
7249
|
-
hasOwnProperty
|
|
7250
|
-
hasOwnProp: hasOwnProperty
|
|
7249
|
+
hasOwnProperty,
|
|
7250
|
+
hasOwnProp: hasOwnProperty, // an alias to avoid ESLint no-prototype-builtins detection
|
|
7251
7251
|
reduceDescriptors,
|
|
7252
7252
|
freezeMethods,
|
|
7253
7253
|
toObjectSet,
|
|
@@ -7255,7 +7255,7 @@ var utils = {
|
|
|
7255
7255
|
noop,
|
|
7256
7256
|
toFiniteNumber,
|
|
7257
7257
|
findKey,
|
|
7258
|
-
global: _global
|
|
7258
|
+
global: _global,
|
|
7259
7259
|
isContextDefined,
|
|
7260
7260
|
ALPHABET,
|
|
7261
7261
|
generateString,
|
|
@@ -7456,10 +7456,10 @@ function write (buffer, value, offset, isLE, mLen, nBytes) {
|
|
|
7456
7456
|
buffer[offset + i - d] |= s * 128;
|
|
7457
7457
|
}
|
|
7458
7458
|
|
|
7459
|
-
var toString
|
|
7459
|
+
var toString = {}.toString;
|
|
7460
7460
|
|
|
7461
|
-
var isArray
|
|
7462
|
-
return toString
|
|
7461
|
+
var isArray = Array.isArray || function (arr) {
|
|
7462
|
+
return toString.call(arr) == '[object Array]';
|
|
7463
7463
|
};
|
|
7464
7464
|
|
|
7465
7465
|
/*!
|
|
@@ -7740,7 +7740,7 @@ function fromObject (that, obj) {
|
|
|
7740
7740
|
return fromArrayLike(that, obj)
|
|
7741
7741
|
}
|
|
7742
7742
|
|
|
7743
|
-
if (obj.type === 'Buffer' && isArray
|
|
7743
|
+
if (obj.type === 'Buffer' && isArray(obj.data)) {
|
|
7744
7744
|
return fromArrayLike(that, obj.data)
|
|
7745
7745
|
}
|
|
7746
7746
|
}
|
|
@@ -7805,7 +7805,7 @@ Buffer.isEncoding = function isEncoding (encoding) {
|
|
|
7805
7805
|
};
|
|
7806
7806
|
|
|
7807
7807
|
Buffer.concat = function concat (list, length) {
|
|
7808
|
-
if (!isArray
|
|
7808
|
+
if (!isArray(list)) {
|
|
7809
7809
|
throw new TypeError('"list" argument must be an Array of Buffers')
|
|
7810
7810
|
}
|
|
7811
7811
|
|
|
@@ -8127,7 +8127,7 @@ function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
|
|
|
8127
8127
|
if (val.length === 0) {
|
|
8128
8128
|
return -1
|
|
8129
8129
|
}
|
|
8130
|
-
return arrayIndexOf
|
|
8130
|
+
return arrayIndexOf(buffer, val, byteOffset, encoding, dir)
|
|
8131
8131
|
} else if (typeof val === 'number') {
|
|
8132
8132
|
val = val & 0xFF; // Search for a byte value [0-255]
|
|
8133
8133
|
if (Buffer.TYPED_ARRAY_SUPPORT &&
|
|
@@ -8138,13 +8138,13 @@ function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
|
|
|
8138
8138
|
return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset)
|
|
8139
8139
|
}
|
|
8140
8140
|
}
|
|
8141
|
-
return arrayIndexOf
|
|
8141
|
+
return arrayIndexOf(buffer, [ val ], byteOffset, encoding, dir)
|
|
8142
8142
|
}
|
|
8143
8143
|
|
|
8144
8144
|
throw new TypeError('val must be string, number or Buffer')
|
|
8145
8145
|
}
|
|
8146
8146
|
|
|
8147
|
-
function arrayIndexOf
|
|
8147
|
+
function arrayIndexOf (arr, val, byteOffset, encoding, dir) {
|
|
8148
8148
|
var indexSize = 1;
|
|
8149
8149
|
var arrLength = arr.length;
|
|
8150
8150
|
var valLength = val.length;
|
|
@@ -11620,7 +11620,7 @@ axios.formToJSON = thing => formDataToJSON(utils.isHTMLForm(thing) ? new FormDat
|
|
|
11620
11620
|
|
|
11621
11621
|
axios.HttpStatusCode = HttpStatusCode;
|
|
11622
11622
|
|
|
11623
|
-
axios.default = axios;function commonjsRequire
|
|
11623
|
+
axios.default = axios;function commonjsRequire(path) {
|
|
11624
11624
|
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.');
|
|
11625
11625
|
}var momentExports = {};
|
|
11626
11626
|
var moment$1 = {
|
|
@@ -13718,7 +13718,7 @@ var moment$1 = {
|
|
|
13718
13718
|
) {
|
|
13719
13719
|
try {
|
|
13720
13720
|
oldLocale = globalLocale._abbr;
|
|
13721
|
-
aliasedRequire = commonjsRequire
|
|
13721
|
+
aliasedRequire = commonjsRequire;
|
|
13722
13722
|
aliasedRequire('./locale/' + name);
|
|
13723
13723
|
getSetGlobalLocale(oldLocale);
|
|
13724
13724
|
} catch (e) {
|
|
@@ -17305,3153 +17305,7 @@ var moment$1 = {
|
|
|
17305
17305
|
})));
|
|
17306
17306
|
} (moment$1));
|
|
17307
17307
|
|
|
17308
|
-
var moment = momentExports;function
|
|
17309
|
-
return module = {
|
|
17310
|
-
path: basedir,
|
|
17311
|
-
exports: {},
|
|
17312
|
-
require: function (path, base) {
|
|
17313
|
-
return commonjsRequire(path, (base === undefined || base === null) ? module.path : base);
|
|
17314
|
-
}
|
|
17315
|
-
}, fn(module, module.exports), module.exports;
|
|
17316
|
-
}
|
|
17317
|
-
|
|
17318
|
-
function commonjsRequire () {
|
|
17319
|
-
throw new Error('Dynamic requires are not currently supported by @rollup/plugin-commonjs');
|
|
17320
|
-
}
|
|
17321
|
-
|
|
17322
|
-
var _global = createCommonjsModule(function (module) {
|
|
17323
|
-
// https://github.com/zloirock/core-js/issues/86#issuecomment-115759028
|
|
17324
|
-
var global = module.exports = typeof window != 'undefined' && window.Math == Math
|
|
17325
|
-
? window : typeof self != 'undefined' && self.Math == Math ? self
|
|
17326
|
-
// eslint-disable-next-line no-new-func
|
|
17327
|
-
: Function('return this')();
|
|
17328
|
-
if (typeof __g == 'number') __g = global; // eslint-disable-line no-undef
|
|
17329
|
-
});
|
|
17330
|
-
|
|
17331
|
-
var _core = createCommonjsModule(function (module) {
|
|
17332
|
-
var core = module.exports = { version: '2.6.12' };
|
|
17333
|
-
if (typeof __e == 'number') __e = core; // eslint-disable-line no-undef
|
|
17334
|
-
});
|
|
17335
|
-
|
|
17336
|
-
var _isObject = function (it) {
|
|
17337
|
-
return typeof it === 'object' ? it !== null : typeof it === 'function';
|
|
17338
|
-
};
|
|
17339
|
-
|
|
17340
|
-
var _anObject = function (it) {
|
|
17341
|
-
if (!_isObject(it)) throw TypeError(it + ' is not an object!');
|
|
17342
|
-
return it;
|
|
17343
|
-
};
|
|
17344
|
-
|
|
17345
|
-
var _fails = function (exec) {
|
|
17346
|
-
try {
|
|
17347
|
-
return !!exec();
|
|
17348
|
-
} catch (e) {
|
|
17349
|
-
return true;
|
|
17350
|
-
}
|
|
17351
|
-
};
|
|
17352
|
-
|
|
17353
|
-
// Thank's IE8 for his funny defineProperty
|
|
17354
|
-
var _descriptors = !_fails(function () {
|
|
17355
|
-
return Object.defineProperty({}, 'a', { get: function () { return 7; } }).a != 7;
|
|
17356
|
-
});
|
|
17357
|
-
|
|
17358
|
-
var document$1 = _global.document;
|
|
17359
|
-
// typeof document.createElement is 'object' in old IE
|
|
17360
|
-
var is = _isObject(document$1) && _isObject(document$1.createElement);
|
|
17361
|
-
var _domCreate = function (it) {
|
|
17362
|
-
return is ? document$1.createElement(it) : {};
|
|
17363
|
-
};
|
|
17364
|
-
|
|
17365
|
-
var _ie8DomDefine = !_descriptors && !_fails(function () {
|
|
17366
|
-
return Object.defineProperty(_domCreate('div'), 'a', { get: function () { return 7; } }).a != 7;
|
|
17367
|
-
});
|
|
17368
|
-
|
|
17369
|
-
// 7.1.1 ToPrimitive(input [, PreferredType])
|
|
17370
|
-
|
|
17371
|
-
// instead of the ES6 spec version, we didn't implement @@toPrimitive case
|
|
17372
|
-
// and the second argument - flag - preferred type is a string
|
|
17373
|
-
var _toPrimitive = function (it, S) {
|
|
17374
|
-
if (!_isObject(it)) return it;
|
|
17375
|
-
var fn, val;
|
|
17376
|
-
if (S && typeof (fn = it.toString) == 'function' && !_isObject(val = fn.call(it))) return val;
|
|
17377
|
-
if (typeof (fn = it.valueOf) == 'function' && !_isObject(val = fn.call(it))) return val;
|
|
17378
|
-
if (!S && typeof (fn = it.toString) == 'function' && !_isObject(val = fn.call(it))) return val;
|
|
17379
|
-
throw TypeError("Can't convert object to primitive value");
|
|
17380
|
-
};
|
|
17381
|
-
|
|
17382
|
-
var dP = Object.defineProperty;
|
|
17383
|
-
|
|
17384
|
-
var f$2 = _descriptors ? Object.defineProperty : function defineProperty(O, P, Attributes) {
|
|
17385
|
-
_anObject(O);
|
|
17386
|
-
P = _toPrimitive(P, true);
|
|
17387
|
-
_anObject(Attributes);
|
|
17388
|
-
if (_ie8DomDefine) try {
|
|
17389
|
-
return dP(O, P, Attributes);
|
|
17390
|
-
} catch (e) { /* empty */ }
|
|
17391
|
-
if ('get' in Attributes || 'set' in Attributes) throw TypeError('Accessors not supported!');
|
|
17392
|
-
if ('value' in Attributes) O[P] = Attributes.value;
|
|
17393
|
-
return O;
|
|
17394
|
-
};
|
|
17395
|
-
|
|
17396
|
-
var _objectDp = {
|
|
17397
|
-
f: f$2
|
|
17398
|
-
};
|
|
17399
|
-
|
|
17400
|
-
var _propertyDesc = function (bitmap, value) {
|
|
17401
|
-
return {
|
|
17402
|
-
enumerable: !(bitmap & 1),
|
|
17403
|
-
configurable: !(bitmap & 2),
|
|
17404
|
-
writable: !(bitmap & 4),
|
|
17405
|
-
value: value
|
|
17406
|
-
};
|
|
17407
|
-
};
|
|
17408
|
-
|
|
17409
|
-
var _hide = _descriptors ? function (object, key, value) {
|
|
17410
|
-
return _objectDp.f(object, key, _propertyDesc(1, value));
|
|
17411
|
-
} : function (object, key, value) {
|
|
17412
|
-
object[key] = value;
|
|
17413
|
-
return object;
|
|
17414
|
-
};
|
|
17415
|
-
|
|
17416
|
-
var hasOwnProperty = {}.hasOwnProperty;
|
|
17417
|
-
var _has = function (it, key) {
|
|
17418
|
-
return hasOwnProperty.call(it, key);
|
|
17419
|
-
};
|
|
17420
|
-
|
|
17421
|
-
var id = 0;
|
|
17422
|
-
var px = Math.random();
|
|
17423
|
-
var _uid = function (key) {
|
|
17424
|
-
return 'Symbol('.concat(key === undefined ? '' : key, ')_', (++id + px).toString(36));
|
|
17425
|
-
};
|
|
17426
|
-
|
|
17427
|
-
var _shared = createCommonjsModule(function (module) {
|
|
17428
|
-
var SHARED = '__core-js_shared__';
|
|
17429
|
-
var store = _global[SHARED] || (_global[SHARED] = {});
|
|
17430
|
-
|
|
17431
|
-
(module.exports = function (key, value) {
|
|
17432
|
-
return store[key] || (store[key] = value !== undefined ? value : {});
|
|
17433
|
-
})('versions', []).push({
|
|
17434
|
-
version: _core.version,
|
|
17435
|
-
mode: 'global',
|
|
17436
|
-
copyright: '© 2020 Denis Pushkarev (zloirock.ru)'
|
|
17437
|
-
});
|
|
17438
|
-
});
|
|
17439
|
-
|
|
17440
|
-
var _functionToString = _shared('native-function-to-string', Function.toString);
|
|
17441
|
-
|
|
17442
|
-
var _redefine = createCommonjsModule(function (module) {
|
|
17443
|
-
var SRC = _uid('src');
|
|
17444
|
-
|
|
17445
|
-
var TO_STRING = 'toString';
|
|
17446
|
-
var TPL = ('' + _functionToString).split(TO_STRING);
|
|
17447
|
-
|
|
17448
|
-
_core.inspectSource = function (it) {
|
|
17449
|
-
return _functionToString.call(it);
|
|
17450
|
-
};
|
|
17451
|
-
|
|
17452
|
-
(module.exports = function (O, key, val, safe) {
|
|
17453
|
-
var isFunction = typeof val == 'function';
|
|
17454
|
-
if (isFunction) _has(val, 'name') || _hide(val, 'name', key);
|
|
17455
|
-
if (O[key] === val) return;
|
|
17456
|
-
if (isFunction) _has(val, SRC) || _hide(val, SRC, O[key] ? '' + O[key] : TPL.join(String(key)));
|
|
17457
|
-
if (O === _global) {
|
|
17458
|
-
O[key] = val;
|
|
17459
|
-
} else if (!safe) {
|
|
17460
|
-
delete O[key];
|
|
17461
|
-
_hide(O, key, val);
|
|
17462
|
-
} else if (O[key]) {
|
|
17463
|
-
O[key] = val;
|
|
17464
|
-
} else {
|
|
17465
|
-
_hide(O, key, val);
|
|
17466
|
-
}
|
|
17467
|
-
// add fake Function#toString for correct work wrapped methods / constructors with methods like LoDash isNative
|
|
17468
|
-
})(Function.prototype, TO_STRING, function toString() {
|
|
17469
|
-
return typeof this == 'function' && this[SRC] || _functionToString.call(this);
|
|
17470
|
-
});
|
|
17471
|
-
});
|
|
17472
|
-
|
|
17473
|
-
var _aFunction = function (it) {
|
|
17474
|
-
if (typeof it != 'function') throw TypeError(it + ' is not a function!');
|
|
17475
|
-
return it;
|
|
17476
|
-
};
|
|
17477
|
-
|
|
17478
|
-
// optional / simple context binding
|
|
17479
|
-
|
|
17480
|
-
var _ctx = function (fn, that, length) {
|
|
17481
|
-
_aFunction(fn);
|
|
17482
|
-
if (that === undefined) return fn;
|
|
17483
|
-
switch (length) {
|
|
17484
|
-
case 1: return function (a) {
|
|
17485
|
-
return fn.call(that, a);
|
|
17486
|
-
};
|
|
17487
|
-
case 2: return function (a, b) {
|
|
17488
|
-
return fn.call(that, a, b);
|
|
17489
|
-
};
|
|
17490
|
-
case 3: return function (a, b, c) {
|
|
17491
|
-
return fn.call(that, a, b, c);
|
|
17492
|
-
};
|
|
17493
|
-
}
|
|
17494
|
-
return function (/* ...args */) {
|
|
17495
|
-
return fn.apply(that, arguments);
|
|
17496
|
-
};
|
|
17497
|
-
};
|
|
17498
|
-
|
|
17499
|
-
var PROTOTYPE$1 = 'prototype';
|
|
17500
|
-
|
|
17501
|
-
var $export = function (type, name, source) {
|
|
17502
|
-
var IS_FORCED = type & $export.F;
|
|
17503
|
-
var IS_GLOBAL = type & $export.G;
|
|
17504
|
-
var IS_STATIC = type & $export.S;
|
|
17505
|
-
var IS_PROTO = type & $export.P;
|
|
17506
|
-
var IS_BIND = type & $export.B;
|
|
17507
|
-
var target = IS_GLOBAL ? _global : IS_STATIC ? _global[name] || (_global[name] = {}) : (_global[name] || {})[PROTOTYPE$1];
|
|
17508
|
-
var exports = IS_GLOBAL ? _core : _core[name] || (_core[name] = {});
|
|
17509
|
-
var expProto = exports[PROTOTYPE$1] || (exports[PROTOTYPE$1] = {});
|
|
17510
|
-
var key, own, out, exp;
|
|
17511
|
-
if (IS_GLOBAL) source = name;
|
|
17512
|
-
for (key in source) {
|
|
17513
|
-
// contains in native
|
|
17514
|
-
own = !IS_FORCED && target && target[key] !== undefined;
|
|
17515
|
-
// export native or passed
|
|
17516
|
-
out = (own ? target : source)[key];
|
|
17517
|
-
// bind timers to global for call from export context
|
|
17518
|
-
exp = IS_BIND && own ? _ctx(out, _global) : IS_PROTO && typeof out == 'function' ? _ctx(Function.call, out) : out;
|
|
17519
|
-
// extend global
|
|
17520
|
-
if (target) _redefine(target, key, out, type & $export.U);
|
|
17521
|
-
// export
|
|
17522
|
-
if (exports[key] != out) _hide(exports, key, exp);
|
|
17523
|
-
if (IS_PROTO && expProto[key] != out) expProto[key] = out;
|
|
17524
|
-
}
|
|
17525
|
-
};
|
|
17526
|
-
_global.core = _core;
|
|
17527
|
-
// type bitmap
|
|
17528
|
-
$export.F = 1; // forced
|
|
17529
|
-
$export.G = 2; // global
|
|
17530
|
-
$export.S = 4; // static
|
|
17531
|
-
$export.P = 8; // proto
|
|
17532
|
-
$export.B = 16; // bind
|
|
17533
|
-
$export.W = 32; // wrap
|
|
17534
|
-
$export.U = 64; // safe
|
|
17535
|
-
$export.R = 128; // real proto method for `library`
|
|
17536
|
-
var _export = $export;
|
|
17537
|
-
|
|
17538
|
-
var toString = {}.toString;
|
|
17539
|
-
|
|
17540
|
-
var _cof = function (it) {
|
|
17541
|
-
return toString.call(it).slice(8, -1);
|
|
17542
|
-
};
|
|
17543
|
-
|
|
17544
|
-
// fallback for non-array-like ES3 and non-enumerable old V8 strings
|
|
17545
|
-
|
|
17546
|
-
// eslint-disable-next-line no-prototype-builtins
|
|
17547
|
-
var _iobject = Object('z').propertyIsEnumerable(0) ? Object : function (it) {
|
|
17548
|
-
return _cof(it) == 'String' ? it.split('') : Object(it);
|
|
17549
|
-
};
|
|
17550
|
-
|
|
17551
|
-
// 7.2.1 RequireObjectCoercible(argument)
|
|
17552
|
-
var _defined = function (it) {
|
|
17553
|
-
if (it == undefined) throw TypeError("Can't call method on " + it);
|
|
17554
|
-
return it;
|
|
17555
|
-
};
|
|
17556
|
-
|
|
17557
|
-
// to indexed object, toObject with fallback for non-array-like ES3 strings
|
|
17558
|
-
|
|
17559
|
-
|
|
17560
|
-
var _toIobject = function (it) {
|
|
17561
|
-
return _iobject(_defined(it));
|
|
17562
|
-
};
|
|
17563
|
-
|
|
17564
|
-
// 7.1.4 ToInteger
|
|
17565
|
-
var ceil = Math.ceil;
|
|
17566
|
-
var floor = Math.floor;
|
|
17567
|
-
var _toInteger = function (it) {
|
|
17568
|
-
return isNaN(it = +it) ? 0 : (it > 0 ? floor : ceil)(it);
|
|
17569
|
-
};
|
|
17570
|
-
|
|
17571
|
-
// 7.1.15 ToLength
|
|
17572
|
-
|
|
17573
|
-
var min$1 = Math.min;
|
|
17574
|
-
var _toLength = function (it) {
|
|
17575
|
-
return it > 0 ? min$1(_toInteger(it), 0x1fffffffffffff) : 0; // pow(2, 53) - 1 == 9007199254740991
|
|
17576
|
-
};
|
|
17577
|
-
|
|
17578
|
-
var max = Math.max;
|
|
17579
|
-
var min = Math.min;
|
|
17580
|
-
var _toAbsoluteIndex = function (index, length) {
|
|
17581
|
-
index = _toInteger(index);
|
|
17582
|
-
return index < 0 ? max(index + length, 0) : min(index, length);
|
|
17583
|
-
};
|
|
17584
|
-
|
|
17585
|
-
// false -> Array#indexOf
|
|
17586
|
-
// true -> Array#includes
|
|
17587
|
-
|
|
17588
|
-
|
|
17589
|
-
|
|
17590
|
-
var _arrayIncludes = function (IS_INCLUDES) {
|
|
17591
|
-
return function ($this, el, fromIndex) {
|
|
17592
|
-
var O = _toIobject($this);
|
|
17593
|
-
var length = _toLength(O.length);
|
|
17594
|
-
var index = _toAbsoluteIndex(fromIndex, length);
|
|
17595
|
-
var value;
|
|
17596
|
-
// Array#includes uses SameValueZero equality algorithm
|
|
17597
|
-
// eslint-disable-next-line no-self-compare
|
|
17598
|
-
if (IS_INCLUDES && el != el) while (length > index) {
|
|
17599
|
-
value = O[index++];
|
|
17600
|
-
// eslint-disable-next-line no-self-compare
|
|
17601
|
-
if (value != value) return true;
|
|
17602
|
-
// Array#indexOf ignores holes, Array#includes - not
|
|
17603
|
-
} else for (;length > index; index++) if (IS_INCLUDES || index in O) {
|
|
17604
|
-
if (O[index] === el) return IS_INCLUDES || index || 0;
|
|
17605
|
-
} return !IS_INCLUDES && -1;
|
|
17606
|
-
};
|
|
17607
|
-
};
|
|
17608
|
-
|
|
17609
|
-
var _wks = createCommonjsModule(function (module) {
|
|
17610
|
-
var store = _shared('wks');
|
|
17611
|
-
|
|
17612
|
-
var Symbol = _global.Symbol;
|
|
17613
|
-
var USE_SYMBOL = typeof Symbol == 'function';
|
|
17614
|
-
|
|
17615
|
-
var $exports = module.exports = function (name) {
|
|
17616
|
-
return store[name] || (store[name] =
|
|
17617
|
-
USE_SYMBOL && Symbol[name] || (USE_SYMBOL ? Symbol : _uid)('Symbol.' + name));
|
|
17618
|
-
};
|
|
17619
|
-
|
|
17620
|
-
$exports.store = store;
|
|
17621
|
-
});
|
|
17622
|
-
|
|
17623
|
-
// 22.1.3.31 Array.prototype[@@unscopables]
|
|
17624
|
-
var UNSCOPABLES = _wks('unscopables');
|
|
17625
|
-
var ArrayProto$1 = Array.prototype;
|
|
17626
|
-
if (ArrayProto$1[UNSCOPABLES] == undefined) _hide(ArrayProto$1, UNSCOPABLES, {});
|
|
17627
|
-
var _addToUnscopables = function (key) {
|
|
17628
|
-
ArrayProto$1[UNSCOPABLES][key] = true;
|
|
17629
|
-
};
|
|
17630
|
-
|
|
17631
|
-
// https://github.com/tc39/Array.prototype.includes
|
|
17632
|
-
|
|
17633
|
-
var $includes = _arrayIncludes(true);
|
|
17634
|
-
|
|
17635
|
-
_export(_export.P, 'Array', {
|
|
17636
|
-
includes: function includes(el /* , fromIndex = 0 */) {
|
|
17637
|
-
return $includes(this, el, arguments.length > 1 ? arguments[1] : undefined);
|
|
17638
|
-
}
|
|
17639
|
-
});
|
|
17640
|
-
|
|
17641
|
-
_addToUnscopables('includes');
|
|
17642
|
-
|
|
17643
|
-
_core.Array.includes;
|
|
17644
|
-
|
|
17645
|
-
var shared = _shared('keys');
|
|
17646
|
-
|
|
17647
|
-
var _sharedKey = function (key) {
|
|
17648
|
-
return shared[key] || (shared[key] = _uid(key));
|
|
17649
|
-
};
|
|
17650
|
-
|
|
17651
|
-
var arrayIndexOf = _arrayIncludes(false);
|
|
17652
|
-
var IE_PROTO$2 = _sharedKey('IE_PROTO');
|
|
17653
|
-
|
|
17654
|
-
var _objectKeysInternal = function (object, names) {
|
|
17655
|
-
var O = _toIobject(object);
|
|
17656
|
-
var i = 0;
|
|
17657
|
-
var result = [];
|
|
17658
|
-
var key;
|
|
17659
|
-
for (key in O) if (key != IE_PROTO$2) _has(O, key) && result.push(key);
|
|
17660
|
-
// Don't enum bug & hidden keys
|
|
17661
|
-
while (names.length > i) if (_has(O, key = names[i++])) {
|
|
17662
|
-
~arrayIndexOf(result, key) || result.push(key);
|
|
17663
|
-
}
|
|
17664
|
-
return result;
|
|
17665
|
-
};
|
|
17666
|
-
|
|
17667
|
-
// IE 8- don't enum bug keys
|
|
17668
|
-
var _enumBugKeys = (
|
|
17669
|
-
'constructor,hasOwnProperty,isPrototypeOf,propertyIsEnumerable,toLocaleString,toString,valueOf'
|
|
17670
|
-
).split(',');
|
|
17671
|
-
|
|
17672
|
-
// 19.1.2.14 / 15.2.3.14 Object.keys(O)
|
|
17673
|
-
|
|
17674
|
-
|
|
17675
|
-
|
|
17676
|
-
var _objectKeys = Object.keys || function keys(O) {
|
|
17677
|
-
return _objectKeysInternal(O, _enumBugKeys);
|
|
17678
|
-
};
|
|
17679
|
-
|
|
17680
|
-
var f$1 = Object.getOwnPropertySymbols;
|
|
17681
|
-
|
|
17682
|
-
var _objectGops = {
|
|
17683
|
-
f: f$1
|
|
17684
|
-
};
|
|
17685
|
-
|
|
17686
|
-
var f = {}.propertyIsEnumerable;
|
|
17687
|
-
|
|
17688
|
-
var _objectPie = {
|
|
17689
|
-
f: f
|
|
17690
|
-
};
|
|
17691
|
-
|
|
17692
|
-
// 7.1.13 ToObject(argument)
|
|
17693
|
-
|
|
17694
|
-
var _toObject = function (it) {
|
|
17695
|
-
return Object(_defined(it));
|
|
17696
|
-
};
|
|
17697
|
-
|
|
17698
|
-
// 19.1.2.1 Object.assign(target, source, ...)
|
|
17699
|
-
|
|
17700
|
-
|
|
17701
|
-
|
|
17702
|
-
|
|
17703
|
-
|
|
17704
|
-
|
|
17705
|
-
var $assign = Object.assign;
|
|
17706
|
-
|
|
17707
|
-
// should work with symbols and should have deterministic property order (V8 bug)
|
|
17708
|
-
var _objectAssign = !$assign || _fails(function () {
|
|
17709
|
-
var A = {};
|
|
17710
|
-
var B = {};
|
|
17711
|
-
// eslint-disable-next-line no-undef
|
|
17712
|
-
var S = Symbol();
|
|
17713
|
-
var K = 'abcdefghijklmnopqrst';
|
|
17714
|
-
A[S] = 7;
|
|
17715
|
-
K.split('').forEach(function (k) { B[k] = k; });
|
|
17716
|
-
return $assign({}, A)[S] != 7 || Object.keys($assign({}, B)).join('') != K;
|
|
17717
|
-
}) ? function assign(target, source) { // eslint-disable-line no-unused-vars
|
|
17718
|
-
var T = _toObject(target);
|
|
17719
|
-
var aLen = arguments.length;
|
|
17720
|
-
var index = 1;
|
|
17721
|
-
var getSymbols = _objectGops.f;
|
|
17722
|
-
var isEnum = _objectPie.f;
|
|
17723
|
-
while (aLen > index) {
|
|
17724
|
-
var S = _iobject(arguments[index++]);
|
|
17725
|
-
var keys = getSymbols ? _objectKeys(S).concat(getSymbols(S)) : _objectKeys(S);
|
|
17726
|
-
var length = keys.length;
|
|
17727
|
-
var j = 0;
|
|
17728
|
-
var key;
|
|
17729
|
-
while (length > j) {
|
|
17730
|
-
key = keys[j++];
|
|
17731
|
-
if (!_descriptors || isEnum.call(S, key)) T[key] = S[key];
|
|
17732
|
-
}
|
|
17733
|
-
} return T;
|
|
17734
|
-
} : $assign;
|
|
17735
|
-
|
|
17736
|
-
// 19.1.3.1 Object.assign(target, source)
|
|
17737
|
-
|
|
17738
|
-
|
|
17739
|
-
_export(_export.S + _export.F, 'Object', { assign: _objectAssign });
|
|
17740
|
-
|
|
17741
|
-
_core.Object.assign;
|
|
17742
|
-
|
|
17743
|
-
var isEnum = _objectPie.f;
|
|
17744
|
-
var _objectToArray = function (isEntries) {
|
|
17745
|
-
return function (it) {
|
|
17746
|
-
var O = _toIobject(it);
|
|
17747
|
-
var keys = _objectKeys(O);
|
|
17748
|
-
var length = keys.length;
|
|
17749
|
-
var i = 0;
|
|
17750
|
-
var result = [];
|
|
17751
|
-
var key;
|
|
17752
|
-
while (length > i) {
|
|
17753
|
-
key = keys[i++];
|
|
17754
|
-
if (!_descriptors || isEnum.call(O, key)) {
|
|
17755
|
-
result.push(isEntries ? [key, O[key]] : O[key]);
|
|
17756
|
-
}
|
|
17757
|
-
}
|
|
17758
|
-
return result;
|
|
17759
|
-
};
|
|
17760
|
-
};
|
|
17761
|
-
|
|
17762
|
-
// https://github.com/tc39/proposal-object-values-entries
|
|
17763
|
-
|
|
17764
|
-
var $entries = _objectToArray(true);
|
|
17765
|
-
|
|
17766
|
-
_export(_export.S, 'Object', {
|
|
17767
|
-
entries: function entries(it) {
|
|
17768
|
-
return $entries(it);
|
|
17769
|
-
}
|
|
17770
|
-
});
|
|
17771
|
-
|
|
17772
|
-
_core.Object.entries;
|
|
17773
|
-
|
|
17774
|
-
// https://github.com/tc39/proposal-object-values-entries
|
|
17775
|
-
|
|
17776
|
-
var $values = _objectToArray(false);
|
|
17777
|
-
|
|
17778
|
-
_export(_export.S, 'Object', {
|
|
17779
|
-
values: function values(it) {
|
|
17780
|
-
return $values(it);
|
|
17781
|
-
}
|
|
17782
|
-
});
|
|
17783
|
-
|
|
17784
|
-
_core.Object.values;
|
|
17785
|
-
|
|
17786
|
-
// 7.2.8 IsRegExp(argument)
|
|
17787
|
-
|
|
17788
|
-
|
|
17789
|
-
var MATCH$1 = _wks('match');
|
|
17790
|
-
var _isRegexp = function (it) {
|
|
17791
|
-
var isRegExp;
|
|
17792
|
-
return _isObject(it) && ((isRegExp = it[MATCH$1]) !== undefined ? !!isRegExp : _cof(it) == 'RegExp');
|
|
17793
|
-
};
|
|
17794
|
-
|
|
17795
|
-
// helper for String#{startsWith, endsWith, includes}
|
|
17796
|
-
|
|
17797
|
-
|
|
17798
|
-
|
|
17799
|
-
var _stringContext = function (that, searchString, NAME) {
|
|
17800
|
-
if (_isRegexp(searchString)) throw TypeError('String#' + NAME + " doesn't accept regex!");
|
|
17801
|
-
return String(_defined(that));
|
|
17802
|
-
};
|
|
17803
|
-
|
|
17804
|
-
var MATCH = _wks('match');
|
|
17805
|
-
var _failsIsRegexp = function (KEY) {
|
|
17806
|
-
var re = /./;
|
|
17807
|
-
try {
|
|
17808
|
-
'/./'[KEY](re);
|
|
17809
|
-
} catch (e) {
|
|
17810
|
-
try {
|
|
17811
|
-
re[MATCH] = false;
|
|
17812
|
-
return !'/./'[KEY](re);
|
|
17813
|
-
} catch (f) { /* empty */ }
|
|
17814
|
-
} return true;
|
|
17815
|
-
};
|
|
17816
|
-
|
|
17817
|
-
var STARTS_WITH = 'startsWith';
|
|
17818
|
-
var $startsWith = ''[STARTS_WITH];
|
|
17819
|
-
|
|
17820
|
-
_export(_export.P + _export.F * _failsIsRegexp(STARTS_WITH), 'String', {
|
|
17821
|
-
startsWith: function startsWith(searchString /* , position = 0 */) {
|
|
17822
|
-
var that = _stringContext(this, searchString, STARTS_WITH);
|
|
17823
|
-
var index = _toLength(Math.min(arguments.length > 1 ? arguments[1] : undefined, that.length));
|
|
17824
|
-
var search = String(searchString);
|
|
17825
|
-
return $startsWith
|
|
17826
|
-
? $startsWith.call(that, search, index)
|
|
17827
|
-
: that.slice(index, index + search.length) === search;
|
|
17828
|
-
}
|
|
17829
|
-
});
|
|
17830
|
-
|
|
17831
|
-
_core.String.startsWith;
|
|
17832
|
-
|
|
17833
|
-
// true -> String#at
|
|
17834
|
-
// false -> String#codePointAt
|
|
17835
|
-
var _stringAt = function (TO_STRING) {
|
|
17836
|
-
return function (that, pos) {
|
|
17837
|
-
var s = String(_defined(that));
|
|
17838
|
-
var i = _toInteger(pos);
|
|
17839
|
-
var l = s.length;
|
|
17840
|
-
var a, b;
|
|
17841
|
-
if (i < 0 || i >= l) return TO_STRING ? '' : undefined;
|
|
17842
|
-
a = s.charCodeAt(i);
|
|
17843
|
-
return a < 0xd800 || a > 0xdbff || i + 1 === l || (b = s.charCodeAt(i + 1)) < 0xdc00 || b > 0xdfff
|
|
17844
|
-
? TO_STRING ? s.charAt(i) : a
|
|
17845
|
-
: TO_STRING ? s.slice(i, i + 2) : (a - 0xd800 << 10) + (b - 0xdc00) + 0x10000;
|
|
17846
|
-
};
|
|
17847
|
-
};
|
|
17848
|
-
|
|
17849
|
-
var _iterators = {};
|
|
17850
|
-
|
|
17851
|
-
var _objectDps = _descriptors ? Object.defineProperties : function defineProperties(O, Properties) {
|
|
17852
|
-
_anObject(O);
|
|
17853
|
-
var keys = _objectKeys(Properties);
|
|
17854
|
-
var length = keys.length;
|
|
17855
|
-
var i = 0;
|
|
17856
|
-
var P;
|
|
17857
|
-
while (length > i) _objectDp.f(O, P = keys[i++], Properties[P]);
|
|
17858
|
-
return O;
|
|
17859
|
-
};
|
|
17860
|
-
|
|
17861
|
-
var document$2 = _global.document;
|
|
17862
|
-
var _html = document$2 && document$2.documentElement;
|
|
17863
|
-
|
|
17864
|
-
// 19.1.2.2 / 15.2.3.5 Object.create(O [, Properties])
|
|
17865
|
-
|
|
17866
|
-
|
|
17867
|
-
|
|
17868
|
-
var IE_PROTO$1 = _sharedKey('IE_PROTO');
|
|
17869
|
-
var Empty = function () { /* empty */ };
|
|
17870
|
-
var PROTOTYPE = 'prototype';
|
|
17871
|
-
|
|
17872
|
-
// Create object with fake `null` prototype: use iframe Object with cleared prototype
|
|
17873
|
-
var createDict = function () {
|
|
17874
|
-
// Thrash, waste and sodomy: IE GC bug
|
|
17875
|
-
var iframe = _domCreate('iframe');
|
|
17876
|
-
var i = _enumBugKeys.length;
|
|
17877
|
-
var lt = '<';
|
|
17878
|
-
var gt = '>';
|
|
17879
|
-
var iframeDocument;
|
|
17880
|
-
iframe.style.display = 'none';
|
|
17881
|
-
_html.appendChild(iframe);
|
|
17882
|
-
iframe.src = 'javascript:'; // eslint-disable-line no-script-url
|
|
17883
|
-
// createDict = iframe.contentWindow.Object;
|
|
17884
|
-
// html.removeChild(iframe);
|
|
17885
|
-
iframeDocument = iframe.contentWindow.document;
|
|
17886
|
-
iframeDocument.open();
|
|
17887
|
-
iframeDocument.write(lt + 'script' + gt + 'document.F=Object' + lt + '/script' + gt);
|
|
17888
|
-
iframeDocument.close();
|
|
17889
|
-
createDict = iframeDocument.F;
|
|
17890
|
-
while (i--) delete createDict[PROTOTYPE][_enumBugKeys[i]];
|
|
17891
|
-
return createDict();
|
|
17892
|
-
};
|
|
17893
|
-
|
|
17894
|
-
var _objectCreate = Object.create || function create(O, Properties) {
|
|
17895
|
-
var result;
|
|
17896
|
-
if (O !== null) {
|
|
17897
|
-
Empty[PROTOTYPE] = _anObject(O);
|
|
17898
|
-
result = new Empty();
|
|
17899
|
-
Empty[PROTOTYPE] = null;
|
|
17900
|
-
// add "__proto__" for Object.getPrototypeOf polyfill
|
|
17901
|
-
result[IE_PROTO$1] = O;
|
|
17902
|
-
} else result = createDict();
|
|
17903
|
-
return Properties === undefined ? result : _objectDps(result, Properties);
|
|
17904
|
-
};
|
|
17905
|
-
|
|
17906
|
-
var def = _objectDp.f;
|
|
17907
|
-
|
|
17908
|
-
var TAG$1 = _wks('toStringTag');
|
|
17909
|
-
|
|
17910
|
-
var _setToStringTag = function (it, tag, stat) {
|
|
17911
|
-
if (it && !_has(it = stat ? it : it.prototype, TAG$1)) def(it, TAG$1, { configurable: true, value: tag });
|
|
17912
|
-
};
|
|
17913
|
-
|
|
17914
|
-
var IteratorPrototype = {};
|
|
17915
|
-
|
|
17916
|
-
// 25.1.2.1.1 %IteratorPrototype%[@@iterator]()
|
|
17917
|
-
_hide(IteratorPrototype, _wks('iterator'), function () { return this; });
|
|
17918
|
-
|
|
17919
|
-
var _iterCreate = function (Constructor, NAME, next) {
|
|
17920
|
-
Constructor.prototype = _objectCreate(IteratorPrototype, { next: _propertyDesc(1, next) });
|
|
17921
|
-
_setToStringTag(Constructor, NAME + ' Iterator');
|
|
17922
|
-
};
|
|
17923
|
-
|
|
17924
|
-
// 19.1.2.9 / 15.2.3.2 Object.getPrototypeOf(O)
|
|
17925
|
-
|
|
17926
|
-
|
|
17927
|
-
var IE_PROTO = _sharedKey('IE_PROTO');
|
|
17928
|
-
var ObjectProto = Object.prototype;
|
|
17929
|
-
|
|
17930
|
-
var _objectGpo = Object.getPrototypeOf || function (O) {
|
|
17931
|
-
O = _toObject(O);
|
|
17932
|
-
if (_has(O, IE_PROTO)) return O[IE_PROTO];
|
|
17933
|
-
if (typeof O.constructor == 'function' && O instanceof O.constructor) {
|
|
17934
|
-
return O.constructor.prototype;
|
|
17935
|
-
} return O instanceof Object ? ObjectProto : null;
|
|
17936
|
-
};
|
|
17937
|
-
|
|
17938
|
-
var ITERATOR$3 = _wks('iterator');
|
|
17939
|
-
var BUGGY = !([].keys && 'next' in [].keys()); // Safari has buggy iterators w/o `next`
|
|
17940
|
-
var FF_ITERATOR = '@@iterator';
|
|
17941
|
-
var KEYS = 'keys';
|
|
17942
|
-
var VALUES = 'values';
|
|
17943
|
-
|
|
17944
|
-
var returnThis = function () { return this; };
|
|
17945
|
-
|
|
17946
|
-
var _iterDefine = function (Base, NAME, Constructor, next, DEFAULT, IS_SET, FORCED) {
|
|
17947
|
-
_iterCreate(Constructor, NAME, next);
|
|
17948
|
-
var getMethod = function (kind) {
|
|
17949
|
-
if (!BUGGY && kind in proto) return proto[kind];
|
|
17950
|
-
switch (kind) {
|
|
17951
|
-
case KEYS: return function keys() { return new Constructor(this, kind); };
|
|
17952
|
-
case VALUES: return function values() { return new Constructor(this, kind); };
|
|
17953
|
-
} return function entries() { return new Constructor(this, kind); };
|
|
17954
|
-
};
|
|
17955
|
-
var TAG = NAME + ' Iterator';
|
|
17956
|
-
var DEF_VALUES = DEFAULT == VALUES;
|
|
17957
|
-
var VALUES_BUG = false;
|
|
17958
|
-
var proto = Base.prototype;
|
|
17959
|
-
var $native = proto[ITERATOR$3] || proto[FF_ITERATOR] || DEFAULT && proto[DEFAULT];
|
|
17960
|
-
var $default = $native || getMethod(DEFAULT);
|
|
17961
|
-
var $entries = DEFAULT ? !DEF_VALUES ? $default : getMethod('entries') : undefined;
|
|
17962
|
-
var $anyNative = NAME == 'Array' ? proto.entries || $native : $native;
|
|
17963
|
-
var methods, key, IteratorPrototype;
|
|
17964
|
-
// Fix native
|
|
17965
|
-
if ($anyNative) {
|
|
17966
|
-
IteratorPrototype = _objectGpo($anyNative.call(new Base()));
|
|
17967
|
-
if (IteratorPrototype !== Object.prototype && IteratorPrototype.next) {
|
|
17968
|
-
// Set @@toStringTag to native iterators
|
|
17969
|
-
_setToStringTag(IteratorPrototype, TAG, true);
|
|
17970
|
-
// fix for some old engines
|
|
17971
|
-
if (typeof IteratorPrototype[ITERATOR$3] != 'function') _hide(IteratorPrototype, ITERATOR$3, returnThis);
|
|
17972
|
-
}
|
|
17973
|
-
}
|
|
17974
|
-
// fix Array#{values, @@iterator}.name in V8 / FF
|
|
17975
|
-
if (DEF_VALUES && $native && $native.name !== VALUES) {
|
|
17976
|
-
VALUES_BUG = true;
|
|
17977
|
-
$default = function values() { return $native.call(this); };
|
|
17978
|
-
}
|
|
17979
|
-
// Define iterator
|
|
17980
|
-
if ((BUGGY || VALUES_BUG || !proto[ITERATOR$3])) {
|
|
17981
|
-
_hide(proto, ITERATOR$3, $default);
|
|
17982
|
-
}
|
|
17983
|
-
// Plug for library
|
|
17984
|
-
_iterators[NAME] = $default;
|
|
17985
|
-
_iterators[TAG] = returnThis;
|
|
17986
|
-
if (DEFAULT) {
|
|
17987
|
-
methods = {
|
|
17988
|
-
values: DEF_VALUES ? $default : getMethod(VALUES),
|
|
17989
|
-
keys: IS_SET ? $default : getMethod(KEYS),
|
|
17990
|
-
entries: $entries
|
|
17991
|
-
};
|
|
17992
|
-
if (FORCED) for (key in methods) {
|
|
17993
|
-
if (!(key in proto)) _redefine(proto, key, methods[key]);
|
|
17994
|
-
} else _export(_export.P + _export.F * (BUGGY || VALUES_BUG), NAME, methods);
|
|
17995
|
-
}
|
|
17996
|
-
return methods;
|
|
17997
|
-
};
|
|
17998
|
-
|
|
17999
|
-
var $at = _stringAt(true);
|
|
18000
|
-
|
|
18001
|
-
// 21.1.3.27 String.prototype[@@iterator]()
|
|
18002
|
-
_iterDefine(String, 'String', function (iterated) {
|
|
18003
|
-
this._t = String(iterated); // target
|
|
18004
|
-
this._i = 0; // next index
|
|
18005
|
-
// 21.1.5.2.1 %StringIteratorPrototype%.next()
|
|
18006
|
-
}, function () {
|
|
18007
|
-
var O = this._t;
|
|
18008
|
-
var index = this._i;
|
|
18009
|
-
var point;
|
|
18010
|
-
if (index >= O.length) return { value: undefined, done: true };
|
|
18011
|
-
point = $at(O, index);
|
|
18012
|
-
this._i += point.length;
|
|
18013
|
-
return { value: point, done: false };
|
|
18014
|
-
});
|
|
18015
|
-
|
|
18016
|
-
// call something on iterator step with safe closing on error
|
|
18017
|
-
|
|
18018
|
-
var _iterCall = function (iterator, fn, value, entries) {
|
|
18019
|
-
try {
|
|
18020
|
-
return entries ? fn(_anObject(value)[0], value[1]) : fn(value);
|
|
18021
|
-
// 7.4.6 IteratorClose(iterator, completion)
|
|
18022
|
-
} catch (e) {
|
|
18023
|
-
var ret = iterator['return'];
|
|
18024
|
-
if (ret !== undefined) _anObject(ret.call(iterator));
|
|
18025
|
-
throw e;
|
|
18026
|
-
}
|
|
18027
|
-
};
|
|
18028
|
-
|
|
18029
|
-
// check on default Array iterator
|
|
18030
|
-
|
|
18031
|
-
var ITERATOR$2 = _wks('iterator');
|
|
18032
|
-
var ArrayProto = Array.prototype;
|
|
18033
|
-
|
|
18034
|
-
var _isArrayIter = function (it) {
|
|
18035
|
-
return it !== undefined && (_iterators.Array === it || ArrayProto[ITERATOR$2] === it);
|
|
18036
|
-
};
|
|
18037
|
-
|
|
18038
|
-
var _createProperty = function (object, index, value) {
|
|
18039
|
-
if (index in object) _objectDp.f(object, index, _propertyDesc(0, value));
|
|
18040
|
-
else object[index] = value;
|
|
18041
|
-
};
|
|
18042
|
-
|
|
18043
|
-
// getting tag from 19.1.3.6 Object.prototype.toString()
|
|
18044
|
-
|
|
18045
|
-
var TAG = _wks('toStringTag');
|
|
18046
|
-
// ES3 wrong here
|
|
18047
|
-
var ARG = _cof(function () { return arguments; }()) == 'Arguments';
|
|
18048
|
-
|
|
18049
|
-
// fallback for IE11 Script Access Denied error
|
|
18050
|
-
var tryGet = function (it, key) {
|
|
18051
|
-
try {
|
|
18052
|
-
return it[key];
|
|
18053
|
-
} catch (e) { /* empty */ }
|
|
18054
|
-
};
|
|
18055
|
-
|
|
18056
|
-
var _classof = function (it) {
|
|
18057
|
-
var O, T, B;
|
|
18058
|
-
return it === undefined ? 'Undefined' : it === null ? 'Null'
|
|
18059
|
-
// @@toStringTag case
|
|
18060
|
-
: typeof (T = tryGet(O = Object(it), TAG)) == 'string' ? T
|
|
18061
|
-
// builtinTag case
|
|
18062
|
-
: ARG ? _cof(O)
|
|
18063
|
-
// ES3 arguments fallback
|
|
18064
|
-
: (B = _cof(O)) == 'Object' && typeof O.callee == 'function' ? 'Arguments' : B;
|
|
18065
|
-
};
|
|
18066
|
-
|
|
18067
|
-
var ITERATOR$1 = _wks('iterator');
|
|
18068
|
-
|
|
18069
|
-
var core_getIteratorMethod = _core.getIteratorMethod = function (it) {
|
|
18070
|
-
if (it != undefined) return it[ITERATOR$1]
|
|
18071
|
-
|| it['@@iterator']
|
|
18072
|
-
|| _iterators[_classof(it)];
|
|
18073
|
-
};
|
|
18074
|
-
|
|
18075
|
-
var ITERATOR = _wks('iterator');
|
|
18076
|
-
var SAFE_CLOSING = false;
|
|
18077
|
-
|
|
18078
|
-
try {
|
|
18079
|
-
var riter = [7][ITERATOR]();
|
|
18080
|
-
riter['return'] = function () { SAFE_CLOSING = true; };
|
|
18081
|
-
// eslint-disable-next-line no-throw-literal
|
|
18082
|
-
Array.from(riter, function () { throw 2; });
|
|
18083
|
-
} catch (e) { /* empty */ }
|
|
18084
|
-
|
|
18085
|
-
var _iterDetect = function (exec, skipClosing) {
|
|
18086
|
-
if (!skipClosing && !SAFE_CLOSING) return false;
|
|
18087
|
-
var safe = false;
|
|
18088
|
-
try {
|
|
18089
|
-
var arr = [7];
|
|
18090
|
-
var iter = arr[ITERATOR]();
|
|
18091
|
-
iter.next = function () { return { done: safe = true }; };
|
|
18092
|
-
arr[ITERATOR] = function () { return iter; };
|
|
18093
|
-
exec(arr);
|
|
18094
|
-
} catch (e) { /* empty */ }
|
|
18095
|
-
return safe;
|
|
18096
|
-
};
|
|
18097
|
-
|
|
18098
|
-
_export(_export.S + _export.F * !_iterDetect(function (iter) { Array.from(iter); }), 'Array', {
|
|
18099
|
-
// 22.1.2.1 Array.from(arrayLike, mapfn = undefined, thisArg = undefined)
|
|
18100
|
-
from: function from(arrayLike /* , mapfn = undefined, thisArg = undefined */) {
|
|
18101
|
-
var O = _toObject(arrayLike);
|
|
18102
|
-
var C = typeof this == 'function' ? this : Array;
|
|
18103
|
-
var aLen = arguments.length;
|
|
18104
|
-
var mapfn = aLen > 1 ? arguments[1] : undefined;
|
|
18105
|
-
var mapping = mapfn !== undefined;
|
|
18106
|
-
var index = 0;
|
|
18107
|
-
var iterFn = core_getIteratorMethod(O);
|
|
18108
|
-
var length, result, step, iterator;
|
|
18109
|
-
if (mapping) mapfn = _ctx(mapfn, aLen > 2 ? arguments[2] : undefined, 2);
|
|
18110
|
-
// if object isn't iterable or it's array with default iterator - use simple case
|
|
18111
|
-
if (iterFn != undefined && !(C == Array && _isArrayIter(iterFn))) {
|
|
18112
|
-
for (iterator = iterFn.call(O), result = new C(); !(step = iterator.next()).done; index++) {
|
|
18113
|
-
_createProperty(result, index, mapping ? _iterCall(iterator, mapfn, [step.value, index], true) : step.value);
|
|
18114
|
-
}
|
|
18115
|
-
} else {
|
|
18116
|
-
length = _toLength(O.length);
|
|
18117
|
-
for (result = new C(length); length > index; index++) {
|
|
18118
|
-
_createProperty(result, index, mapping ? mapfn(O[index], index) : O[index]);
|
|
18119
|
-
}
|
|
18120
|
-
}
|
|
18121
|
-
result.length = index;
|
|
18122
|
-
return result;
|
|
18123
|
-
}
|
|
18124
|
-
});
|
|
18125
|
-
|
|
18126
|
-
_core.Array.from;
|
|
18127
|
-
|
|
18128
|
-
// 7.2.2 IsArray(argument)
|
|
18129
|
-
|
|
18130
|
-
var _isArray = Array.isArray || function isArray(arg) {
|
|
18131
|
-
return _cof(arg) == 'Array';
|
|
18132
|
-
};
|
|
18133
|
-
|
|
18134
|
-
var SPECIES = _wks('species');
|
|
18135
|
-
|
|
18136
|
-
var _arraySpeciesConstructor = function (original) {
|
|
18137
|
-
var C;
|
|
18138
|
-
if (_isArray(original)) {
|
|
18139
|
-
C = original.constructor;
|
|
18140
|
-
// cross-realm fallback
|
|
18141
|
-
if (typeof C == 'function' && (C === Array || _isArray(C.prototype))) C = undefined;
|
|
18142
|
-
if (_isObject(C)) {
|
|
18143
|
-
C = C[SPECIES];
|
|
18144
|
-
if (C === null) C = undefined;
|
|
18145
|
-
}
|
|
18146
|
-
} return C === undefined ? Array : C;
|
|
18147
|
-
};
|
|
18148
|
-
|
|
18149
|
-
// 9.4.2.3 ArraySpeciesCreate(originalArray, length)
|
|
18150
|
-
|
|
18151
|
-
|
|
18152
|
-
var _arraySpeciesCreate = function (original, length) {
|
|
18153
|
-
return new (_arraySpeciesConstructor(original))(length);
|
|
18154
|
-
};
|
|
18155
|
-
|
|
18156
|
-
// 0 -> Array#forEach
|
|
18157
|
-
// 1 -> Array#map
|
|
18158
|
-
// 2 -> Array#filter
|
|
18159
|
-
// 3 -> Array#some
|
|
18160
|
-
// 4 -> Array#every
|
|
18161
|
-
// 5 -> Array#find
|
|
18162
|
-
// 6 -> Array#findIndex
|
|
18163
|
-
|
|
18164
|
-
|
|
18165
|
-
|
|
18166
|
-
|
|
18167
|
-
|
|
18168
|
-
var _arrayMethods = function (TYPE, $create) {
|
|
18169
|
-
var IS_MAP = TYPE == 1;
|
|
18170
|
-
var IS_FILTER = TYPE == 2;
|
|
18171
|
-
var IS_SOME = TYPE == 3;
|
|
18172
|
-
var IS_EVERY = TYPE == 4;
|
|
18173
|
-
var IS_FIND_INDEX = TYPE == 6;
|
|
18174
|
-
var NO_HOLES = TYPE == 5 || IS_FIND_INDEX;
|
|
18175
|
-
var create = $create || _arraySpeciesCreate;
|
|
18176
|
-
return function ($this, callbackfn, that) {
|
|
18177
|
-
var O = _toObject($this);
|
|
18178
|
-
var self = _iobject(O);
|
|
18179
|
-
var f = _ctx(callbackfn, that, 3);
|
|
18180
|
-
var length = _toLength(self.length);
|
|
18181
|
-
var index = 0;
|
|
18182
|
-
var result = IS_MAP ? create($this, length) : IS_FILTER ? create($this, 0) : undefined;
|
|
18183
|
-
var val, res;
|
|
18184
|
-
for (;length > index; index++) if (NO_HOLES || index in self) {
|
|
18185
|
-
val = self[index];
|
|
18186
|
-
res = f(val, index, O);
|
|
18187
|
-
if (TYPE) {
|
|
18188
|
-
if (IS_MAP) result[index] = res; // map
|
|
18189
|
-
else if (res) switch (TYPE) {
|
|
18190
|
-
case 3: return true; // some
|
|
18191
|
-
case 5: return val; // find
|
|
18192
|
-
case 6: return index; // findIndex
|
|
18193
|
-
case 2: result.push(val); // filter
|
|
18194
|
-
} else if (IS_EVERY) return false; // every
|
|
18195
|
-
}
|
|
18196
|
-
}
|
|
18197
|
-
return IS_FIND_INDEX ? -1 : IS_SOME || IS_EVERY ? IS_EVERY : result;
|
|
18198
|
-
};
|
|
18199
|
-
};
|
|
18200
|
-
|
|
18201
|
-
// 22.1.3.8 Array.prototype.find(predicate, thisArg = undefined)
|
|
18202
|
-
|
|
18203
|
-
var $find = _arrayMethods(5);
|
|
18204
|
-
var KEY = 'find';
|
|
18205
|
-
var forced = true;
|
|
18206
|
-
// Shouldn't skip holes
|
|
18207
|
-
if (KEY in []) Array(1)[KEY](function () { forced = false; });
|
|
18208
|
-
_export(_export.P + _export.F * forced, 'Array', {
|
|
18209
|
-
find: function find(callbackfn /* , that = undefined */) {
|
|
18210
|
-
return $find(this, callbackfn, arguments.length > 1 ? arguments[1] : undefined);
|
|
18211
|
-
}
|
|
18212
|
-
});
|
|
18213
|
-
_addToUnscopables(KEY);
|
|
18214
|
-
|
|
18215
|
-
_core.Array.find;
|
|
18216
|
-
|
|
18217
|
-
class Container {
|
|
18218
|
-
/**
|
|
18219
|
-
* Register the store instance.
|
|
18220
|
-
*/
|
|
18221
|
-
static register(store) {
|
|
18222
|
-
this.store = store;
|
|
18223
|
-
}
|
|
18224
|
-
}
|
|
18225
|
-
|
|
18226
|
-
/**
|
|
18227
|
-
* Check if the given value is the type of array.
|
|
18228
|
-
*/
|
|
18229
|
-
function isArray(value) {
|
|
18230
|
-
return Array.isArray(value);
|
|
18231
|
-
}
|
|
18232
|
-
/**
|
|
18233
|
-
* Gets the size of collection by returning its length for array-like values
|
|
18234
|
-
* or the number of own enumerable string keyed properties for objects.
|
|
18235
|
-
*/
|
|
18236
|
-
function size(collection) {
|
|
18237
|
-
return isArray(collection)
|
|
18238
|
-
? collection.length
|
|
18239
|
-
: Object.keys(collection).length;
|
|
18240
|
-
}
|
|
18241
|
-
/**
|
|
18242
|
-
* Check if the given array or object is empty.
|
|
18243
|
-
*/
|
|
18244
|
-
function isEmpty(collection) {
|
|
18245
|
-
return size(collection) === 0;
|
|
18246
|
-
}
|
|
18247
|
-
/**
|
|
18248
|
-
* Iterates over own enumerable string keyed properties of an object and
|
|
18249
|
-
* invokes `iteratee` for each property.
|
|
18250
|
-
*/
|
|
18251
|
-
function forOwn(object, iteratee) {
|
|
18252
|
-
Object.keys(object).forEach((key) => iteratee(object[key], key, object));
|
|
18253
|
-
}
|
|
18254
|
-
/**
|
|
18255
|
-
* Creates an array of values by running each element in collection thru
|
|
18256
|
-
* iteratee. The iteratee is invoked with three arguments:
|
|
18257
|
-
* (value, key, collection).
|
|
18258
|
-
*/
|
|
18259
|
-
function map(object, iteratee) {
|
|
18260
|
-
const result = [];
|
|
18261
|
-
for (const key in object) {
|
|
18262
|
-
result.push(iteratee(object[key], key, object));
|
|
18263
|
-
}
|
|
18264
|
-
return result;
|
|
18265
|
-
}
|
|
18266
|
-
/**
|
|
18267
|
-
* Creates an object with the same keys as object and values generated by
|
|
18268
|
-
* running each own enumerable string keyed property of object thru
|
|
18269
|
-
* iteratee. The iteratee is invoked with three arguments:
|
|
18270
|
-
* (value, key, object).
|
|
18271
|
-
*/
|
|
18272
|
-
function mapValues(object, iteratee) {
|
|
18273
|
-
const newObject = Object.assign({}, object);
|
|
18274
|
-
return Object.keys(object).reduce((records, key) => {
|
|
18275
|
-
records[key] = iteratee(object[key], key, object);
|
|
18276
|
-
return records;
|
|
18277
|
-
}, newObject);
|
|
18278
|
-
}
|
|
18279
|
-
/**
|
|
18280
|
-
* Creates an object composed of keys generated from the results of running
|
|
18281
|
-
* each element of collection by the given key.
|
|
18282
|
-
*/
|
|
18283
|
-
function keyBy(collection, key) {
|
|
18284
|
-
const o = {};
|
|
18285
|
-
collection.forEach((item) => {
|
|
18286
|
-
o[item[key]] = item;
|
|
18287
|
-
});
|
|
18288
|
-
return o;
|
|
18289
|
-
}
|
|
18290
|
-
/**
|
|
18291
|
-
* Creates an array of elements, sorted in specified order by the results
|
|
18292
|
-
* of running each element in a collection thru each iteratee.
|
|
18293
|
-
*/
|
|
18294
|
-
function orderBy(collection, iteratees, directions) {
|
|
18295
|
-
let index = -1;
|
|
18296
|
-
const result = collection.map((value) => {
|
|
18297
|
-
const criteria = iteratees.map((iteratee) => {
|
|
18298
|
-
return typeof iteratee === 'function' ? iteratee(value) : value[iteratee];
|
|
18299
|
-
});
|
|
18300
|
-
return { criteria, index: ++index, value };
|
|
18301
|
-
});
|
|
18302
|
-
return baseSortBy(result, (object, other) => {
|
|
18303
|
-
return compareMultiple(object, other, directions);
|
|
18304
|
-
});
|
|
18305
|
-
}
|
|
18306
|
-
/**
|
|
18307
|
-
* Creates an array of elements, sorted in ascending order by the results of
|
|
18308
|
-
* running each element in a collection thru each iteratee. This method
|
|
18309
|
-
* performs a stable sort, that is, it preserves the original sort order
|
|
18310
|
-
* of equal elements.
|
|
18311
|
-
*/
|
|
18312
|
-
function baseSortBy(array, comparer) {
|
|
18313
|
-
let length = array.length;
|
|
18314
|
-
array.sort(comparer);
|
|
18315
|
-
const newArray = [];
|
|
18316
|
-
while (length--) {
|
|
18317
|
-
newArray[length] = array[length].value;
|
|
18318
|
-
}
|
|
18319
|
-
return newArray;
|
|
18320
|
-
}
|
|
18321
|
-
/**
|
|
18322
|
-
* Used by `orderBy` to compare multiple properties of a value to another
|
|
18323
|
-
* and stable sort them.
|
|
18324
|
-
*
|
|
18325
|
-
* If `orders` is unspecified, all values are sorted in ascending order.
|
|
18326
|
-
* Otherwise, specify an order of "desc" for descending or "asc" for
|
|
18327
|
-
* ascending sort order of corresponding values.
|
|
18328
|
-
*/
|
|
18329
|
-
function compareMultiple(object, other, orders) {
|
|
18330
|
-
let index = -1;
|
|
18331
|
-
const objCriteria = object.criteria;
|
|
18332
|
-
const othCriteria = other.criteria;
|
|
18333
|
-
const length = objCriteria.length;
|
|
18334
|
-
const ordersLength = orders.length;
|
|
18335
|
-
while (++index < length) {
|
|
18336
|
-
const result = compareAscending(objCriteria[index], othCriteria[index]);
|
|
18337
|
-
if (result) {
|
|
18338
|
-
if (index >= ordersLength) {
|
|
18339
|
-
return result;
|
|
18340
|
-
}
|
|
18341
|
-
const order = orders[index];
|
|
18342
|
-
return result * (order === 'desc' ? -1 : 1);
|
|
18343
|
-
}
|
|
18344
|
-
}
|
|
18345
|
-
return object.index - other.index;
|
|
18346
|
-
}
|
|
18347
|
-
/**
|
|
18348
|
-
* Compares values to sort them in ascending order.
|
|
18349
|
-
*/
|
|
18350
|
-
function compareAscending(value, other) {
|
|
18351
|
-
if (value !== other) {
|
|
18352
|
-
const valIsDefined = value !== undefined;
|
|
18353
|
-
const valIsNull = value === null;
|
|
18354
|
-
const valIsReflexive = value === value;
|
|
18355
|
-
const othIsDefined = other !== undefined;
|
|
18356
|
-
const othIsNull = other === null;
|
|
18357
|
-
const othIsReflexive = other === other;
|
|
18358
|
-
if (typeof value !== 'number' || typeof other !== 'number') {
|
|
18359
|
-
value = String(value);
|
|
18360
|
-
other = String(other);
|
|
18361
|
-
}
|
|
18362
|
-
if ((!othIsNull && value > other) ||
|
|
18363
|
-
(valIsNull && othIsDefined && othIsReflexive) ||
|
|
18364
|
-
(!valIsDefined && othIsReflexive) ||
|
|
18365
|
-
!valIsReflexive) {
|
|
18366
|
-
return 1;
|
|
18367
|
-
}
|
|
18368
|
-
if ((!valIsNull && value < other) ||
|
|
18369
|
-
(othIsNull && valIsDefined && valIsReflexive) ||
|
|
18370
|
-
(!othIsDefined && valIsReflexive) ||
|
|
18371
|
-
!othIsReflexive) {
|
|
18372
|
-
return -1;
|
|
18373
|
-
}
|
|
18374
|
-
}
|
|
18375
|
-
return 0;
|
|
18376
|
-
}
|
|
18377
|
-
/**
|
|
18378
|
-
* Creates an object composed of keys generated from the results of running
|
|
18379
|
-
* each element of collection thru iteratee.
|
|
18380
|
-
*/
|
|
18381
|
-
function groupBy(collection, iteratee) {
|
|
18382
|
-
return collection.reduce((records, record) => {
|
|
18383
|
-
const key = iteratee(record);
|
|
18384
|
-
if (records[key] === undefined) {
|
|
18385
|
-
records[key] = [];
|
|
18386
|
-
}
|
|
18387
|
-
records[key].push(record);
|
|
18388
|
-
return records;
|
|
18389
|
-
}, {});
|
|
18390
|
-
}
|
|
18391
|
-
/**
|
|
18392
|
-
* Deep clone the given target object.
|
|
18393
|
-
*/
|
|
18394
|
-
function cloneDeep(target) {
|
|
18395
|
-
if (target === null) {
|
|
18396
|
-
return target;
|
|
18397
|
-
}
|
|
18398
|
-
if (isArray(target)) {
|
|
18399
|
-
const cp = [];
|
|
18400
|
-
target.forEach((v) => cp.push(v));
|
|
18401
|
-
return cp.map((n) => cloneDeep(n));
|
|
18402
|
-
}
|
|
18403
|
-
if (typeof target === 'object' && target !== {}) {
|
|
18404
|
-
const cp = { ...target };
|
|
18405
|
-
Object.keys(cp).forEach((k) => (cp[k] = cloneDeep(cp[k])));
|
|
18406
|
-
return cp;
|
|
18407
|
-
}
|
|
18408
|
-
return target;
|
|
18409
|
-
}
|
|
18410
|
-
var Utils = {
|
|
18411
|
-
isArray,
|
|
18412
|
-
size,
|
|
18413
|
-
isEmpty,
|
|
18414
|
-
forOwn,
|
|
18415
|
-
map,
|
|
18416
|
-
mapValues,
|
|
18417
|
-
keyBy,
|
|
18418
|
-
orderBy,
|
|
18419
|
-
groupBy,
|
|
18420
|
-
cloneDeep
|
|
18421
|
-
};
|
|
18422
|
-
|
|
18423
|
-
class Uid$1 {
|
|
18424
|
-
/**
|
|
18425
|
-
* Generate an UUID.
|
|
18426
|
-
*/
|
|
18427
|
-
static make() {
|
|
18428
|
-
this.count++;
|
|
18429
|
-
return `${this.prefix}${this.count}`;
|
|
18430
|
-
}
|
|
18431
|
-
/**
|
|
18432
|
-
* Reset the count to 0.
|
|
18433
|
-
*/
|
|
18434
|
-
static reset() {
|
|
18435
|
-
this.count = 0;
|
|
18436
|
-
}
|
|
18437
|
-
}
|
|
18438
|
-
/**
|
|
18439
|
-
* Count to create a unique id.
|
|
18440
|
-
*/
|
|
18441
|
-
Uid$1.count = 0;
|
|
18442
|
-
/**
|
|
18443
|
-
* Prefix string to be used for the id.
|
|
18444
|
-
*/
|
|
18445
|
-
Uid$1.prefix = '$uid';
|
|
18446
|
-
|
|
18447
|
-
class Attribute {
|
|
18448
|
-
/**
|
|
18449
|
-
* Create a new attribute instance.
|
|
18450
|
-
*/
|
|
18451
|
-
constructor(model) {
|
|
18452
|
-
this.model = model;
|
|
18453
|
-
}
|
|
18454
|
-
}
|
|
18455
|
-
|
|
18456
|
-
class Type extends Attribute {
|
|
18457
|
-
/**
|
|
18458
|
-
* Create a new type instance.
|
|
18459
|
-
*/
|
|
18460
|
-
constructor(model, value, mutator) {
|
|
18461
|
-
super(model); /* istanbul ignore next */
|
|
18462
|
-
/**
|
|
18463
|
-
* Whether if the attribute can accept `null` as a value.
|
|
18464
|
-
*/
|
|
18465
|
-
this.isNullable = false;
|
|
18466
|
-
this.value = value;
|
|
18467
|
-
this.mutator = mutator;
|
|
18468
|
-
}
|
|
18469
|
-
/**
|
|
18470
|
-
* Set `isNullable` to be `true`.
|
|
18471
|
-
*/
|
|
18472
|
-
nullable() {
|
|
18473
|
-
this.isNullable = true;
|
|
18474
|
-
return this;
|
|
18475
|
-
}
|
|
18476
|
-
/**
|
|
18477
|
-
* Mutate the given value by mutator.
|
|
18478
|
-
*/
|
|
18479
|
-
mutate(value, key) {
|
|
18480
|
-
const mutator = this.mutator || this.model.mutators()[key];
|
|
18481
|
-
return mutator ? mutator(value) : value;
|
|
18482
|
-
}
|
|
18483
|
-
}
|
|
18484
|
-
|
|
18485
|
-
class Attr extends Type {
|
|
18486
|
-
/**
|
|
18487
|
-
* Create a new attr instance.
|
|
18488
|
-
*/
|
|
18489
|
-
constructor(model, value, mutator) {
|
|
18490
|
-
/* istanbul ignore next */
|
|
18491
|
-
super(model, value, mutator);
|
|
18492
|
-
}
|
|
18493
|
-
/**
|
|
18494
|
-
* Make value to be set to model property. This method is used when
|
|
18495
|
-
* instantiating a model or creating a plain object from a model.
|
|
18496
|
-
*/
|
|
18497
|
-
make(value, _parent, key) {
|
|
18498
|
-
value = value !== undefined ? value : this.value;
|
|
18499
|
-
// Default Value might be a function (taking no parameter).
|
|
18500
|
-
let localValue = value;
|
|
18501
|
-
if (typeof value === 'function') {
|
|
18502
|
-
localValue = value();
|
|
18503
|
-
}
|
|
18504
|
-
return this.mutate(localValue, key);
|
|
18505
|
-
}
|
|
18506
|
-
}
|
|
18507
|
-
|
|
18508
|
-
class String$1 extends Type {
|
|
18509
|
-
/**
|
|
18510
|
-
* Create a new string instance.
|
|
18511
|
-
*/
|
|
18512
|
-
constructor(model, value, mutator) {
|
|
18513
|
-
/* istanbul ignore next */
|
|
18514
|
-
super(model, value, mutator);
|
|
18515
|
-
}
|
|
18516
|
-
/**
|
|
18517
|
-
* Convert given value to the appropriate value for the attribute.
|
|
18518
|
-
*/
|
|
18519
|
-
make(value, _parent, key) {
|
|
18520
|
-
return this.mutate(this.fix(value), key);
|
|
18521
|
-
}
|
|
18522
|
-
/**
|
|
18523
|
-
* Convert given value to the string.
|
|
18524
|
-
*/
|
|
18525
|
-
fix(value) {
|
|
18526
|
-
if (value === undefined) {
|
|
18527
|
-
return this.value;
|
|
18528
|
-
}
|
|
18529
|
-
if (typeof value === 'string') {
|
|
18530
|
-
return value;
|
|
18531
|
-
}
|
|
18532
|
-
if (value === null && this.isNullable) {
|
|
18533
|
-
return value;
|
|
18534
|
-
}
|
|
18535
|
-
return value + '';
|
|
18536
|
-
}
|
|
18537
|
-
}
|
|
18538
|
-
|
|
18539
|
-
class Number$1 extends Type {
|
|
18540
|
-
/**
|
|
18541
|
-
* Create a new number instance.
|
|
18542
|
-
*/
|
|
18543
|
-
constructor(model, value, mutator) {
|
|
18544
|
-
/* istanbul ignore next */
|
|
18545
|
-
super(model, value, mutator);
|
|
18546
|
-
}
|
|
18547
|
-
/**
|
|
18548
|
-
* Convert given value to the appropriate value for the attribute.
|
|
18549
|
-
*/
|
|
18550
|
-
make(value, _parent, key) {
|
|
18551
|
-
return this.mutate(this.fix(value), key);
|
|
18552
|
-
}
|
|
18553
|
-
/**
|
|
18554
|
-
* Transform given data to the number.
|
|
18555
|
-
*/
|
|
18556
|
-
fix(value) {
|
|
18557
|
-
if (value === undefined) {
|
|
18558
|
-
return this.value;
|
|
18559
|
-
}
|
|
18560
|
-
if (typeof value === 'number') {
|
|
18561
|
-
return value;
|
|
18562
|
-
}
|
|
18563
|
-
if (typeof value === 'string') {
|
|
18564
|
-
return parseFloat(value);
|
|
18565
|
-
}
|
|
18566
|
-
if (typeof value === 'boolean') {
|
|
18567
|
-
return value ? 1 : 0;
|
|
18568
|
-
}
|
|
18569
|
-
if (value === null && this.isNullable) {
|
|
18570
|
-
return value;
|
|
18571
|
-
}
|
|
18572
|
-
return 0;
|
|
18573
|
-
}
|
|
18574
|
-
}
|
|
18575
|
-
|
|
18576
|
-
class Boolean$1 extends Type {
|
|
18577
|
-
/**
|
|
18578
|
-
* Create a new number instance.
|
|
18579
|
-
*/
|
|
18580
|
-
constructor(model, value, mutator) {
|
|
18581
|
-
/* istanbul ignore next */
|
|
18582
|
-
super(model, value, mutator);
|
|
18583
|
-
}
|
|
18584
|
-
/**
|
|
18585
|
-
* Convert given value to the appropriate value for the attribute.
|
|
18586
|
-
*/
|
|
18587
|
-
make(value, _parent, key) {
|
|
18588
|
-
return this.mutate(this.fix(value), key);
|
|
18589
|
-
}
|
|
18590
|
-
/**
|
|
18591
|
-
* Transform given data to the boolean.
|
|
18592
|
-
*/
|
|
18593
|
-
fix(value) {
|
|
18594
|
-
if (value === undefined) {
|
|
18595
|
-
return this.value;
|
|
18596
|
-
}
|
|
18597
|
-
if (typeof value === 'boolean') {
|
|
18598
|
-
return value;
|
|
18599
|
-
}
|
|
18600
|
-
if (typeof value === 'string') {
|
|
18601
|
-
if (value.length === 0) {
|
|
18602
|
-
return false;
|
|
18603
|
-
}
|
|
18604
|
-
const int = parseInt(value, 0);
|
|
18605
|
-
return isNaN(int) ? true : !!int;
|
|
18606
|
-
}
|
|
18607
|
-
if (typeof value === 'number') {
|
|
18608
|
-
return !!value;
|
|
18609
|
-
}
|
|
18610
|
-
if (value === null && this.isNullable) {
|
|
18611
|
-
return value;
|
|
18612
|
-
}
|
|
18613
|
-
return false;
|
|
18614
|
-
}
|
|
18615
|
-
}
|
|
18616
|
-
|
|
18617
|
-
class Uid extends Type {
|
|
18618
|
-
/**
|
|
18619
|
-
* Create a new uid instance.
|
|
18620
|
-
*/
|
|
18621
|
-
constructor(model, value) {
|
|
18622
|
-
/* istanbul ignore next */
|
|
18623
|
-
super(model, value);
|
|
18624
|
-
}
|
|
18625
|
-
/**
|
|
18626
|
-
* Convert given value to the appropriate value for the attribute.
|
|
18627
|
-
*/
|
|
18628
|
-
make(value) {
|
|
18629
|
-
if (typeof value === 'number' || typeof value === 'string') {
|
|
18630
|
-
return value;
|
|
18631
|
-
}
|
|
18632
|
-
if (typeof this.value === 'function') {
|
|
18633
|
-
return this.value();
|
|
18634
|
-
}
|
|
18635
|
-
return Uid$1.make();
|
|
18636
|
-
}
|
|
18637
|
-
}
|
|
18638
|
-
|
|
18639
|
-
class Relation extends Attribute {
|
|
18640
|
-
/**
|
|
18641
|
-
* Get relation query instance with constraint attached.
|
|
18642
|
-
*/
|
|
18643
|
-
getRelation(query, name, constraints) {
|
|
18644
|
-
const relation = query.newQuery(name);
|
|
18645
|
-
constraints.forEach((constraint) => {
|
|
18646
|
-
constraint(relation);
|
|
18647
|
-
});
|
|
18648
|
-
return relation;
|
|
18649
|
-
}
|
|
18650
|
-
/**
|
|
18651
|
-
* Get specified keys from the given collection.
|
|
18652
|
-
*/
|
|
18653
|
-
getKeys(collection, key) {
|
|
18654
|
-
return collection.reduce((models, model) => {
|
|
18655
|
-
if (model[key] === null || model[key] === undefined) {
|
|
18656
|
-
return models;
|
|
18657
|
-
}
|
|
18658
|
-
models.push(model[key]);
|
|
18659
|
-
return models;
|
|
18660
|
-
}, []);
|
|
18661
|
-
}
|
|
18662
|
-
/**
|
|
18663
|
-
* Create a new indexed map for the single relation by specified key.
|
|
18664
|
-
*/
|
|
18665
|
-
mapSingleRelations(collection, key) {
|
|
18666
|
-
const relations = new Map();
|
|
18667
|
-
collection.forEach((record) => {
|
|
18668
|
-
const id = record[key];
|
|
18669
|
-
!relations.get(id) && relations.set(id, record);
|
|
18670
|
-
});
|
|
18671
|
-
return relations;
|
|
18672
|
-
}
|
|
18673
|
-
/**
|
|
18674
|
-
* Create a new indexed map for the many relation by specified key.
|
|
18675
|
-
*/
|
|
18676
|
-
mapManyRelations(collection, key) {
|
|
18677
|
-
const relations = new Map();
|
|
18678
|
-
collection.forEach((record) => {
|
|
18679
|
-
const id = record[key];
|
|
18680
|
-
let ownerKeys = relations.get(id);
|
|
18681
|
-
if (!ownerKeys) {
|
|
18682
|
-
ownerKeys = [];
|
|
18683
|
-
relations.set(id, ownerKeys);
|
|
18684
|
-
}
|
|
18685
|
-
ownerKeys.push(record);
|
|
18686
|
-
});
|
|
18687
|
-
return relations;
|
|
18688
|
-
}
|
|
18689
|
-
/**
|
|
18690
|
-
* Create a new indexed map for relations with order constraints.
|
|
18691
|
-
*/
|
|
18692
|
-
mapRelationsByOrders(collection, relations, ownerKey, relationKey) {
|
|
18693
|
-
const records = {};
|
|
18694
|
-
relations.forEach((related, id) => {
|
|
18695
|
-
collection
|
|
18696
|
-
.filter((record) => record[relationKey] === id)
|
|
18697
|
-
.forEach((record) => {
|
|
18698
|
-
const id = record[ownerKey];
|
|
18699
|
-
if (!records[id]) {
|
|
18700
|
-
records[id] = [];
|
|
18701
|
-
}
|
|
18702
|
-
records[id] = records[id].concat(related);
|
|
18703
|
-
});
|
|
18704
|
-
});
|
|
18705
|
-
return records;
|
|
18706
|
-
}
|
|
18707
|
-
/**
|
|
18708
|
-
* Check if the given record is a single relation, which is an object.
|
|
18709
|
-
*/
|
|
18710
|
-
isOneRelation(record) {
|
|
18711
|
-
if (!isArray(record) && record !== null && typeof record === 'object') {
|
|
18712
|
-
return true;
|
|
18713
|
-
}
|
|
18714
|
-
return false;
|
|
18715
|
-
}
|
|
18716
|
-
/**
|
|
18717
|
-
* Check if the given records is a many relation, which is an array
|
|
18718
|
-
* of object.
|
|
18719
|
-
*/
|
|
18720
|
-
isManyRelation(records) {
|
|
18721
|
-
if (!isArray(records)) {
|
|
18722
|
-
return false;
|
|
18723
|
-
}
|
|
18724
|
-
if (records.length < 1) {
|
|
18725
|
-
return false;
|
|
18726
|
-
}
|
|
18727
|
-
return true;
|
|
18728
|
-
}
|
|
18729
|
-
/**
|
|
18730
|
-
* Wrap the given object into a model instance.
|
|
18731
|
-
*/
|
|
18732
|
-
makeOneRelation(record, model) {
|
|
18733
|
-
if (!this.isOneRelation(record)) {
|
|
18734
|
-
return null;
|
|
18735
|
-
}
|
|
18736
|
-
const relatedModel = model.getModelFromRecord(record) || model;
|
|
18737
|
-
return new relatedModel(record);
|
|
18738
|
-
}
|
|
18739
|
-
/**
|
|
18740
|
-
* Wrap the given records into a collection of model instances.
|
|
18741
|
-
*/
|
|
18742
|
-
makeManyRelation(records, model) {
|
|
18743
|
-
if (!this.isManyRelation(records)) {
|
|
18744
|
-
return [];
|
|
18745
|
-
}
|
|
18746
|
-
return records
|
|
18747
|
-
.filter((record) => {
|
|
18748
|
-
return this.isOneRelation(record);
|
|
18749
|
-
})
|
|
18750
|
-
.map((record) => {
|
|
18751
|
-
const relatedModel = model.getModelFromRecord(record) || model;
|
|
18752
|
-
return new relatedModel(record);
|
|
18753
|
-
});
|
|
18754
|
-
}
|
|
18755
|
-
}
|
|
18756
|
-
|
|
18757
|
-
class HasOne extends Relation {
|
|
18758
|
-
/**
|
|
18759
|
-
* Create a new has one instance.
|
|
18760
|
-
*/
|
|
18761
|
-
constructor(model, related, foreignKey, localKey) {
|
|
18762
|
-
super(model); /* istanbul ignore next */
|
|
18763
|
-
this.related = this.model.relation(related);
|
|
18764
|
-
this.foreignKey = foreignKey;
|
|
18765
|
-
this.localKey = localKey;
|
|
18766
|
-
}
|
|
18767
|
-
/**
|
|
18768
|
-
* Define the normalizr schema for the relationship.
|
|
18769
|
-
*/
|
|
18770
|
-
define(schema) {
|
|
18771
|
-
return schema.one(this.related);
|
|
18772
|
-
}
|
|
18773
|
-
/**
|
|
18774
|
-
* Attach the relational key to the related data. For example,
|
|
18775
|
-
* when User has one Phone, it will attach value to the
|
|
18776
|
-
* `user_id` field of Phone record.
|
|
18777
|
-
*/
|
|
18778
|
-
attach(key, record, data) {
|
|
18779
|
-
// Check if the record has local key set. If not, set the local key to be
|
|
18780
|
-
// the id value. This happens if the user defines the custom local key
|
|
18781
|
-
// and didn't include it in the data being normalized.
|
|
18782
|
-
if (!record[this.localKey]) {
|
|
18783
|
-
record[this.localKey] = this.model.getIndexIdFromRecord(record);
|
|
18784
|
-
}
|
|
18785
|
-
// Then set the foreign key of the related record if it exists to be the
|
|
18786
|
-
// local key of this record.
|
|
18787
|
-
const related = data[this.related.entity] && data[this.related.entity][key];
|
|
18788
|
-
if (related) {
|
|
18789
|
-
related[this.foreignKey] = record[this.localKey];
|
|
18790
|
-
}
|
|
18791
|
-
}
|
|
18792
|
-
/**
|
|
18793
|
-
* Make value to be set to model property. This method is used when
|
|
18794
|
-
* instantiating a model or creating a plain object from a model.
|
|
18795
|
-
*/
|
|
18796
|
-
make(value, _parent, _key) {
|
|
18797
|
-
return this.makeOneRelation(value, this.related);
|
|
18798
|
-
}
|
|
18799
|
-
/**
|
|
18800
|
-
* Load the has one relationship for the collection.
|
|
18801
|
-
*/
|
|
18802
|
-
load(query, collection, name, constraints) {
|
|
18803
|
-
const relation = this.getRelation(query, this.related.entity, constraints);
|
|
18804
|
-
this.addEagerConstraints(relation, collection);
|
|
18805
|
-
this.match(collection, relation.get(), name);
|
|
18806
|
-
}
|
|
18807
|
-
/**
|
|
18808
|
-
* Set the constraints for an eager load of the relation.
|
|
18809
|
-
*/
|
|
18810
|
-
addEagerConstraints(relation, collection) {
|
|
18811
|
-
relation.whereFk(this.foreignKey, this.getKeys(collection, this.localKey));
|
|
18812
|
-
}
|
|
18813
|
-
/**
|
|
18814
|
-
* Match the eagerly loaded results to their parents.
|
|
18815
|
-
*/
|
|
18816
|
-
match(collection, relations, name) {
|
|
18817
|
-
const dictionary = this.buildDictionary(relations);
|
|
18818
|
-
collection.forEach((model) => {
|
|
18819
|
-
const id = model[this.localKey];
|
|
18820
|
-
const relation = dictionary[id];
|
|
18821
|
-
model[name] = relation || null;
|
|
18822
|
-
});
|
|
18823
|
-
}
|
|
18824
|
-
/**
|
|
18825
|
-
* Build model dictionary keyed by the relation's foreign key.
|
|
18826
|
-
*/
|
|
18827
|
-
buildDictionary(relations) {
|
|
18828
|
-
return relations.reduce((dictionary, relation) => {
|
|
18829
|
-
const key = relation[this.foreignKey];
|
|
18830
|
-
dictionary[key] = relation;
|
|
18831
|
-
return dictionary;
|
|
18832
|
-
}, {});
|
|
18833
|
-
}
|
|
18834
|
-
}
|
|
18835
|
-
|
|
18836
|
-
class BelongsTo extends Relation {
|
|
18837
|
-
/**
|
|
18838
|
-
* Create a new belongs to instance.
|
|
18839
|
-
*/
|
|
18840
|
-
constructor(model, parent, foreignKey, ownerKey) {
|
|
18841
|
-
super(model); /* istanbul ignore next */
|
|
18842
|
-
this.parent = this.model.relation(parent);
|
|
18843
|
-
this.foreignKey = foreignKey;
|
|
18844
|
-
this.ownerKey = ownerKey;
|
|
18845
|
-
}
|
|
18846
|
-
/**
|
|
18847
|
-
* Define the normalizr schema for the relationship.
|
|
18848
|
-
*/
|
|
18849
|
-
define(schema) {
|
|
18850
|
-
return schema.one(this.parent);
|
|
18851
|
-
}
|
|
18852
|
-
/**
|
|
18853
|
-
* Attach the relational key to the given data. For example, when Post
|
|
18854
|
-
* belongs to User, it will attach value to the `user_id` field of
|
|
18855
|
-
* Post record.
|
|
18856
|
-
*/
|
|
18857
|
-
attach(key, record, data) {
|
|
18858
|
-
// See if the record has the foreign key, if yes, it means the user has
|
|
18859
|
-
// provided the key explicitly so do nothing and return.
|
|
18860
|
-
if (record[this.foreignKey] !== undefined) {
|
|
18861
|
-
return;
|
|
18862
|
-
}
|
|
18863
|
-
// If there is no foreign key, let's set it here.
|
|
18864
|
-
record[this.foreignKey] =
|
|
18865
|
-
data[this.parent.entity] && data[this.parent.entity][key]
|
|
18866
|
-
? data[this.parent.entity][key][this.ownerKey]
|
|
18867
|
-
: key;
|
|
18868
|
-
}
|
|
18869
|
-
/**
|
|
18870
|
-
* Convert given value to the appropriate value for the attribute.
|
|
18871
|
-
*/
|
|
18872
|
-
make(value, _parent, _key) {
|
|
18873
|
-
return this.makeOneRelation(value, this.parent);
|
|
18874
|
-
}
|
|
18875
|
-
/**
|
|
18876
|
-
* Load the belongs to relationship for the collection.
|
|
18877
|
-
*/
|
|
18878
|
-
load(query, collection, name, constraints) {
|
|
18879
|
-
const relation = this.getRelation(query, this.parent.entity, constraints);
|
|
18880
|
-
this.addEagerConstraints(relation, collection);
|
|
18881
|
-
this.match(collection, relation.get(), name);
|
|
18882
|
-
}
|
|
18883
|
-
/**
|
|
18884
|
-
* Set the constraints for an eager load of the relation.
|
|
18885
|
-
*/
|
|
18886
|
-
addEagerConstraints(relation, collection) {
|
|
18887
|
-
relation.whereFk(this.ownerKey, this.getKeys(collection, this.foreignKey));
|
|
18888
|
-
}
|
|
18889
|
-
/**
|
|
18890
|
-
* Match the eagerly loaded results to their parents.
|
|
18891
|
-
*/
|
|
18892
|
-
match(collection, relations, name) {
|
|
18893
|
-
const dictionary = this.buildDictionary(relations);
|
|
18894
|
-
collection.forEach((model) => {
|
|
18895
|
-
const id = model[this.foreignKey];
|
|
18896
|
-
const relation = id !== null ? dictionary[id] : null;
|
|
18897
|
-
model[name] = relation || null;
|
|
18898
|
-
});
|
|
18899
|
-
}
|
|
18900
|
-
/**
|
|
18901
|
-
* Build model dictionary keyed by the relation's foreign key.
|
|
18902
|
-
*/
|
|
18903
|
-
buildDictionary(relations) {
|
|
18904
|
-
return relations.reduce((dictionary, relation) => {
|
|
18905
|
-
const key = relation[this.ownerKey];
|
|
18906
|
-
dictionary[key] = relation;
|
|
18907
|
-
return dictionary;
|
|
18908
|
-
}, {});
|
|
18909
|
-
}
|
|
18910
|
-
}
|
|
18911
|
-
|
|
18912
|
-
class HasMany extends Relation {
|
|
18913
|
-
/**
|
|
18914
|
-
* Create a new has many instance.
|
|
18915
|
-
*/
|
|
18916
|
-
constructor(model, related, foreignKey, localKey) {
|
|
18917
|
-
super(model); /* istanbul ignore next */
|
|
18918
|
-
this.related = this.model.relation(related);
|
|
18919
|
-
this.foreignKey = foreignKey;
|
|
18920
|
-
this.localKey = localKey;
|
|
18921
|
-
}
|
|
18922
|
-
/**
|
|
18923
|
-
* Define the normalizr schema for the relationship.
|
|
18924
|
-
*/
|
|
18925
|
-
define(schema) {
|
|
18926
|
-
return schema.many(this.related);
|
|
18927
|
-
}
|
|
18928
|
-
/**
|
|
18929
|
-
* Attach the relational key to the given data.
|
|
18930
|
-
*/
|
|
18931
|
-
attach(key, record, data) {
|
|
18932
|
-
key.forEach((index) => {
|
|
18933
|
-
const related = data[this.related.entity];
|
|
18934
|
-
if (!related ||
|
|
18935
|
-
!related[index] ||
|
|
18936
|
-
related[index][this.foreignKey] !== undefined) {
|
|
18937
|
-
return;
|
|
18938
|
-
}
|
|
18939
|
-
related[index][this.foreignKey] = record[this.localKey];
|
|
18940
|
-
});
|
|
18941
|
-
}
|
|
18942
|
-
/**
|
|
18943
|
-
* Convert given value to the appropriate value for the attribute.
|
|
18944
|
-
*/
|
|
18945
|
-
make(value, _parent, _key) {
|
|
18946
|
-
return this.makeManyRelation(value, this.related);
|
|
18947
|
-
}
|
|
18948
|
-
/**
|
|
18949
|
-
* Load the has many relationship for the collection.
|
|
18950
|
-
*/
|
|
18951
|
-
load(query, collection, name, constraints) {
|
|
18952
|
-
const relation = this.getRelation(query, this.related.entity, constraints);
|
|
18953
|
-
this.addEagerConstraints(relation, collection);
|
|
18954
|
-
this.match(collection, relation.get(), name);
|
|
18955
|
-
}
|
|
18956
|
-
/**
|
|
18957
|
-
* Set the constraints for an eager load of the relation.
|
|
18958
|
-
*/
|
|
18959
|
-
addEagerConstraints(relation, collection) {
|
|
18960
|
-
relation.whereFk(this.foreignKey, this.getKeys(collection, this.localKey));
|
|
18961
|
-
}
|
|
18962
|
-
/**
|
|
18963
|
-
* Match the eagerly loaded results to their parents.
|
|
18964
|
-
*/
|
|
18965
|
-
match(collection, relations, name) {
|
|
18966
|
-
const dictionary = this.buildDictionary(relations);
|
|
18967
|
-
collection.forEach((model) => {
|
|
18968
|
-
const id = model[this.localKey];
|
|
18969
|
-
const relation = dictionary[id];
|
|
18970
|
-
model[name] = relation || [];
|
|
18971
|
-
});
|
|
18972
|
-
}
|
|
18973
|
-
/**
|
|
18974
|
-
* Build model dictionary keyed by the relation's foreign key.
|
|
18975
|
-
*/
|
|
18976
|
-
buildDictionary(relations) {
|
|
18977
|
-
return relations.reduce((dictionary, relation) => {
|
|
18978
|
-
const key = relation[this.foreignKey];
|
|
18979
|
-
if (!dictionary[key]) {
|
|
18980
|
-
dictionary[key] = [];
|
|
18981
|
-
}
|
|
18982
|
-
dictionary[key].push(relation);
|
|
18983
|
-
return dictionary;
|
|
18984
|
-
}, {});
|
|
18985
|
-
}
|
|
18986
|
-
}
|
|
18987
|
-
|
|
18988
|
-
class HasManyBy extends Relation {
|
|
18989
|
-
/**
|
|
18990
|
-
* Create a new has many by instance.
|
|
18991
|
-
*/
|
|
18992
|
-
constructor(model, parent, foreignKey, ownerKey) {
|
|
18993
|
-
super(model); /* istanbul ignore next */
|
|
18994
|
-
this.parent = this.model.relation(parent);
|
|
18995
|
-
this.foreignKey = foreignKey;
|
|
18996
|
-
this.ownerKey = ownerKey;
|
|
18997
|
-
}
|
|
18998
|
-
/**
|
|
18999
|
-
* Define the normalizr schema for the relationship.
|
|
19000
|
-
*/
|
|
19001
|
-
define(schema) {
|
|
19002
|
-
return schema.many(this.parent);
|
|
19003
|
-
}
|
|
19004
|
-
/**
|
|
19005
|
-
* Attach the relational key to the given data.
|
|
19006
|
-
*/
|
|
19007
|
-
attach(key, record, _data) {
|
|
19008
|
-
if (key.length === 0) {
|
|
19009
|
-
return;
|
|
19010
|
-
}
|
|
19011
|
-
record[this.foreignKey] = key.map((parentId) => {
|
|
19012
|
-
return this.parent.getIdFromRecord(_data[this.parent.entity][parentId]);
|
|
19013
|
-
});
|
|
19014
|
-
}
|
|
19015
|
-
/**
|
|
19016
|
-
* Convert given value to the appropriate value for the attribute.
|
|
19017
|
-
*/
|
|
19018
|
-
make(value, _parent, _key) {
|
|
19019
|
-
return this.makeManyRelation(value, this.parent);
|
|
19020
|
-
}
|
|
19021
|
-
/**
|
|
19022
|
-
* Load the has many by relationship for the collection.
|
|
19023
|
-
*/
|
|
19024
|
-
load(query, collection, name, constraints) {
|
|
19025
|
-
const relatedQuery = this.getRelation(query, this.parent.entity, constraints);
|
|
19026
|
-
this.addConstraintForHasManyBy(relatedQuery, collection);
|
|
19027
|
-
const relations = this.mapSingleRelations(relatedQuery.get(), this.ownerKey);
|
|
19028
|
-
collection.forEach((item) => {
|
|
19029
|
-
const related = this.getRelatedRecords(relations, item[this.foreignKey]);
|
|
19030
|
-
item[name] = related;
|
|
19031
|
-
});
|
|
19032
|
-
}
|
|
19033
|
-
/**
|
|
19034
|
-
* Set the constraints for an eager load of the relation.
|
|
19035
|
-
*/
|
|
19036
|
-
addConstraintForHasManyBy(query, collection) {
|
|
19037
|
-
const keys = collection.reduce((keys, item) => {
|
|
19038
|
-
return keys.concat(item[this.foreignKey]);
|
|
19039
|
-
}, []);
|
|
19040
|
-
query.where(this.ownerKey, keys);
|
|
19041
|
-
}
|
|
19042
|
-
/**
|
|
19043
|
-
* Get related records.
|
|
19044
|
-
*/
|
|
19045
|
-
getRelatedRecords(relations, keys) {
|
|
19046
|
-
const records = [];
|
|
19047
|
-
relations.forEach((record, id) => {
|
|
19048
|
-
if (keys.indexOf(id) !== -1) {
|
|
19049
|
-
records.push(record);
|
|
19050
|
-
}
|
|
19051
|
-
});
|
|
19052
|
-
return records;
|
|
19053
|
-
}
|
|
19054
|
-
}
|
|
19055
|
-
|
|
19056
|
-
class HasManyThrough extends Relation {
|
|
19057
|
-
/**
|
|
19058
|
-
* Create a new has many through instance.
|
|
19059
|
-
*/
|
|
19060
|
-
constructor(model, related, through, firstKey, secondKey, localKey, secondLocalKey) {
|
|
19061
|
-
super(model); /* istanbul ignore next */
|
|
19062
|
-
this.related = this.model.relation(related);
|
|
19063
|
-
this.through = this.model.relation(through);
|
|
19064
|
-
this.firstKey = firstKey;
|
|
19065
|
-
this.secondKey = secondKey;
|
|
19066
|
-
this.localKey = localKey;
|
|
19067
|
-
this.secondLocalKey = secondLocalKey;
|
|
19068
|
-
}
|
|
19069
|
-
/**
|
|
19070
|
-
* Define the normalizr schema for the relationship.
|
|
19071
|
-
*/
|
|
19072
|
-
define(schema) {
|
|
19073
|
-
return schema.many(this.related);
|
|
19074
|
-
}
|
|
19075
|
-
/**
|
|
19076
|
-
* Attach the relational key to the given data. Since has many through
|
|
19077
|
-
* relationship doesn't have any foreign key, it would do nothing.
|
|
19078
|
-
*/
|
|
19079
|
-
attach(_key, _record, _data) {
|
|
19080
|
-
return;
|
|
19081
|
-
}
|
|
19082
|
-
/**
|
|
19083
|
-
* Convert given value to the appropriate value for the attribute.
|
|
19084
|
-
*/
|
|
19085
|
-
make(value, _parent, _key) {
|
|
19086
|
-
return this.makeManyRelation(value, this.related);
|
|
19087
|
-
}
|
|
19088
|
-
/**
|
|
19089
|
-
* Load the has many through relationship for the collection.
|
|
19090
|
-
*/
|
|
19091
|
-
load(query, collection, name, constraints) {
|
|
19092
|
-
const relatedQuery = this.getRelation(query, this.related.entity, constraints);
|
|
19093
|
-
const throughQuery = query.newQuery(this.through.entity);
|
|
19094
|
-
this.addEagerConstraintForThrough(throughQuery, collection);
|
|
19095
|
-
const throughs = throughQuery.get();
|
|
19096
|
-
this.addEagerConstraintForRelated(relatedQuery, throughs);
|
|
19097
|
-
const relateds = this.mapThroughRelations(throughs, relatedQuery);
|
|
19098
|
-
collection.forEach((item) => {
|
|
19099
|
-
const related = relateds[item[this.localKey]];
|
|
19100
|
-
item[name] = related || [];
|
|
19101
|
-
});
|
|
19102
|
-
}
|
|
19103
|
-
/**
|
|
19104
|
-
* Set the constraints for the through relation.
|
|
19105
|
-
*/
|
|
19106
|
-
addEagerConstraintForThrough(query, collection) {
|
|
19107
|
-
query.where(this.firstKey, this.getKeys(collection, this.localKey));
|
|
19108
|
-
}
|
|
19109
|
-
/**
|
|
19110
|
-
* Set the constraints for the related relation.
|
|
19111
|
-
*/
|
|
19112
|
-
addEagerConstraintForRelated(query, collection) {
|
|
19113
|
-
query.where(this.secondKey, this.getKeys(collection, this.secondLocalKey));
|
|
19114
|
-
}
|
|
19115
|
-
/**
|
|
19116
|
-
* Create a new indexed map for the through relation.
|
|
19117
|
-
*/
|
|
19118
|
-
mapThroughRelations(throughs, relatedQuery) {
|
|
19119
|
-
const relations = this.mapManyRelations(relatedQuery.get(), this.secondKey);
|
|
19120
|
-
return throughs.reduce((records, record) => {
|
|
19121
|
-
const id = record[this.firstKey];
|
|
19122
|
-
if (!records[id]) {
|
|
19123
|
-
records[id] = [];
|
|
19124
|
-
}
|
|
19125
|
-
const related = relations.get(record[this.secondLocalKey]);
|
|
19126
|
-
if (related === undefined) {
|
|
19127
|
-
return records;
|
|
19128
|
-
}
|
|
19129
|
-
records[id] = records[id].concat(related);
|
|
19130
|
-
return records;
|
|
19131
|
-
}, {});
|
|
19132
|
-
}
|
|
19133
|
-
}
|
|
19134
|
-
|
|
19135
|
-
class BelongsToMany extends Relation {
|
|
19136
|
-
/**
|
|
19137
|
-
* Create a new belongs to instance.
|
|
19138
|
-
*/
|
|
19139
|
-
constructor(model, related, pivot, foreignPivotKey, relatedPivotKey, parentKey, relatedKey) {
|
|
19140
|
-
super(model); /* istanbul ignore next */
|
|
19141
|
-
/**
|
|
19142
|
-
* The key name of the pivot data.
|
|
19143
|
-
*/
|
|
19144
|
-
this.pivotKey = 'pivot';
|
|
19145
|
-
this.related = this.model.relation(related);
|
|
19146
|
-
this.pivot = this.model.relation(pivot);
|
|
19147
|
-
this.foreignPivotKey = foreignPivotKey;
|
|
19148
|
-
this.relatedPivotKey = relatedPivotKey;
|
|
19149
|
-
this.parentKey = parentKey;
|
|
19150
|
-
this.relatedKey = relatedKey;
|
|
19151
|
-
}
|
|
19152
|
-
/**
|
|
19153
|
-
* Specify the custom pivot accessor to use for the relationship.
|
|
19154
|
-
*/
|
|
19155
|
-
as(accessor) {
|
|
19156
|
-
this.pivotKey = accessor;
|
|
19157
|
-
return this;
|
|
19158
|
-
}
|
|
19159
|
-
/**
|
|
19160
|
-
* Define the normalizr schema for the relationship.
|
|
19161
|
-
*/
|
|
19162
|
-
define(schema) {
|
|
19163
|
-
return schema.many(this.related);
|
|
19164
|
-
}
|
|
19165
|
-
/**
|
|
19166
|
-
* Attach the relational key to the given data. Since belongs to many
|
|
19167
|
-
* relationship doesn't have any foreign key, it would do nothing.
|
|
19168
|
-
*/
|
|
19169
|
-
attach(_key, _record, _data) {
|
|
19170
|
-
return;
|
|
19171
|
-
}
|
|
19172
|
-
/**
|
|
19173
|
-
* Convert given value to the appropriate value for the attribute.
|
|
19174
|
-
*/
|
|
19175
|
-
make(value, _parent, _key) {
|
|
19176
|
-
return this.makeManyRelation(value, this.related);
|
|
19177
|
-
}
|
|
19178
|
-
/**
|
|
19179
|
-
* Load the belongs to relationship for the record.
|
|
19180
|
-
*/
|
|
19181
|
-
load(query, collection, name, constraints) {
|
|
19182
|
-
const relatedQuery = this.getRelation(query, this.related.entity, constraints);
|
|
19183
|
-
const pivotQuery = query.newQuery(this.pivot.entity);
|
|
19184
|
-
this.addEagerConstraintForPivot(pivotQuery, collection);
|
|
19185
|
-
const pivots = pivotQuery.get();
|
|
19186
|
-
this.addEagerConstraintForRelated(relatedQuery, pivots);
|
|
19187
|
-
const relateds = this.mapPivotRelations(pivots, relatedQuery);
|
|
19188
|
-
collection.forEach((item) => {
|
|
19189
|
-
const related = relateds[item[this.parentKey]];
|
|
19190
|
-
item[name] = related || [];
|
|
19191
|
-
});
|
|
19192
|
-
}
|
|
19193
|
-
/**
|
|
19194
|
-
* Set the constraints for the pivot relation.
|
|
19195
|
-
*/
|
|
19196
|
-
addEagerConstraintForPivot(query, collection) {
|
|
19197
|
-
query.whereFk(this.foreignPivotKey, this.getKeys(collection, this.parentKey));
|
|
19198
|
-
}
|
|
19199
|
-
/**
|
|
19200
|
-
* Set the constraints for the related relation.
|
|
19201
|
-
*/
|
|
19202
|
-
addEagerConstraintForRelated(query, collection) {
|
|
19203
|
-
query.whereFk(this.relatedKey, this.getKeys(collection, this.relatedPivotKey));
|
|
19204
|
-
}
|
|
19205
|
-
/**
|
|
19206
|
-
* Create a new indexed map for the pivot relation.
|
|
19207
|
-
*/
|
|
19208
|
-
mapPivotRelations(pivots, relatedQuery) {
|
|
19209
|
-
const relations = this.mapManyRelations(relatedQuery.get(), this.relatedKey);
|
|
19210
|
-
if (relatedQuery.orders.length) {
|
|
19211
|
-
return this.mapRelationsByOrders(pivots, relations, this.foreignPivotKey, this.relatedPivotKey);
|
|
19212
|
-
}
|
|
19213
|
-
return pivots.reduce((records, record) => {
|
|
19214
|
-
const id = record[this.foreignPivotKey];
|
|
19215
|
-
if (!records[id]) {
|
|
19216
|
-
records[id] = [];
|
|
19217
|
-
}
|
|
19218
|
-
const related = relations.get(record[this.relatedPivotKey]);
|
|
19219
|
-
if (related) {
|
|
19220
|
-
records[id] = records[id].concat(related.map((model) => {
|
|
19221
|
-
model[this.pivotKey] = record;
|
|
19222
|
-
return model;
|
|
19223
|
-
}));
|
|
19224
|
-
}
|
|
19225
|
-
return records;
|
|
19226
|
-
}, {});
|
|
19227
|
-
}
|
|
19228
|
-
/**
|
|
19229
|
-
* Create pivot records for the given records if needed.
|
|
19230
|
-
*/
|
|
19231
|
-
createPivots(parent, data, key) {
|
|
19232
|
-
if (!Utils.isArray(this.pivot.primaryKey))
|
|
19233
|
-
return data;
|
|
19234
|
-
Utils.forOwn(data[parent.entity], (record) => {
|
|
19235
|
-
const related = record[key];
|
|
19236
|
-
if (related === undefined || related.length === 0) {
|
|
19237
|
-
return;
|
|
19238
|
-
}
|
|
19239
|
-
this.createPivotRecord(data, record, related);
|
|
19240
|
-
});
|
|
19241
|
-
return data;
|
|
19242
|
-
}
|
|
19243
|
-
/**
|
|
19244
|
-
* Create a pivot record.
|
|
19245
|
-
*/
|
|
19246
|
-
createPivotRecord(data, record, related) {
|
|
19247
|
-
related.forEach((id) => {
|
|
19248
|
-
const parentId = record[this.parentKey];
|
|
19249
|
-
const relatedId = data[this.related.entity][id][this.relatedKey];
|
|
19250
|
-
const pivotKey = JSON.stringify([
|
|
19251
|
-
this.pivot.primaryKey[0] === this.foreignPivotKey
|
|
19252
|
-
? parentId
|
|
19253
|
-
: relatedId,
|
|
19254
|
-
this.pivot.primaryKey[1] === this.foreignPivotKey ? parentId : relatedId
|
|
19255
|
-
]);
|
|
19256
|
-
const pivotRecord = data[this.pivot.entity]
|
|
19257
|
-
? data[this.pivot.entity][pivotKey]
|
|
19258
|
-
: {};
|
|
19259
|
-
const pivotData = data[this.related.entity][id][this.pivotKey] || {};
|
|
19260
|
-
data[this.pivot.entity] = {
|
|
19261
|
-
...data[this.pivot.entity],
|
|
19262
|
-
[pivotKey]: {
|
|
19263
|
-
...pivotRecord,
|
|
19264
|
-
...pivotData,
|
|
19265
|
-
$id: pivotKey,
|
|
19266
|
-
[this.foreignPivotKey]: parentId,
|
|
19267
|
-
[this.relatedPivotKey]: relatedId
|
|
19268
|
-
}
|
|
19269
|
-
};
|
|
19270
|
-
});
|
|
19271
|
-
}
|
|
19272
|
-
}
|
|
19273
|
-
|
|
19274
|
-
class MorphTo extends Relation {
|
|
19275
|
-
/**
|
|
19276
|
-
* Create a new morph to instance.
|
|
19277
|
-
*/
|
|
19278
|
-
constructor(model, id, type) {
|
|
19279
|
-
super(model); /* istanbul ignore next */
|
|
19280
|
-
this.id = id;
|
|
19281
|
-
this.type = type;
|
|
19282
|
-
}
|
|
19283
|
-
/**
|
|
19284
|
-
* Define the normalizr schema for the relationship.
|
|
19285
|
-
*/
|
|
19286
|
-
define(schema) {
|
|
19287
|
-
return schema.union((_value, parentValue) => parentValue[this.type]);
|
|
19288
|
-
}
|
|
19289
|
-
/**
|
|
19290
|
-
* Attach the relational key to the given record. Since morph to
|
|
19291
|
-
* relationship doesn't have any foreign key, it would do nothing.
|
|
19292
|
-
*/
|
|
19293
|
-
attach(_key, _record, _data) {
|
|
19294
|
-
return;
|
|
19295
|
-
}
|
|
19296
|
-
/**
|
|
19297
|
-
* Convert given value to the appropriate value for the attribute.
|
|
19298
|
-
*/
|
|
19299
|
-
make(value, parent, _key) {
|
|
19300
|
-
const related = parent[this.type];
|
|
19301
|
-
try {
|
|
19302
|
-
const model = this.model.relation(related);
|
|
19303
|
-
return this.makeOneRelation(value, model);
|
|
19304
|
-
}
|
|
19305
|
-
catch (_a) {
|
|
19306
|
-
return null;
|
|
19307
|
-
}
|
|
19308
|
-
}
|
|
19309
|
-
/**
|
|
19310
|
-
* Load the morph to relationship for the collection.
|
|
19311
|
-
*/
|
|
19312
|
-
load(query, collection, name, constraints) {
|
|
19313
|
-
const types = this.getTypes(collection);
|
|
19314
|
-
const relations = types.reduce((related, type) => {
|
|
19315
|
-
const relatedQuery = this.getRelation(query, type, constraints);
|
|
19316
|
-
related[type] = this.mapSingleRelations(relatedQuery.get(), '$id');
|
|
19317
|
-
return related;
|
|
19318
|
-
}, {});
|
|
19319
|
-
collection.forEach((item) => {
|
|
19320
|
-
const id = item[this.id];
|
|
19321
|
-
const type = item[this.type];
|
|
19322
|
-
const related = relations[type].get(String(id));
|
|
19323
|
-
item[name] = related || null;
|
|
19324
|
-
});
|
|
19325
|
-
}
|
|
19326
|
-
/**
|
|
19327
|
-
* Get all types from the collection.
|
|
19328
|
-
*/
|
|
19329
|
-
getTypes(collection) {
|
|
19330
|
-
return collection.reduce((types, item) => {
|
|
19331
|
-
const type = item[this.type];
|
|
19332
|
-
!types.includes(type) && types.push(type);
|
|
19333
|
-
return types;
|
|
19334
|
-
}, []);
|
|
19335
|
-
}
|
|
19336
|
-
}
|
|
19337
|
-
|
|
19338
|
-
class MorphOne extends Relation {
|
|
19339
|
-
/**
|
|
19340
|
-
* Create a new belongs to instance.
|
|
19341
|
-
*/
|
|
19342
|
-
constructor(model, related, id, type, localKey) {
|
|
19343
|
-
super(model); /* istanbul ignore next */
|
|
19344
|
-
this.related = this.model.relation(related);
|
|
19345
|
-
this.id = id;
|
|
19346
|
-
this.type = type;
|
|
19347
|
-
this.localKey = localKey;
|
|
19348
|
-
}
|
|
19349
|
-
/**
|
|
19350
|
-
* Define the normalizr schema for the relationship.
|
|
19351
|
-
*/
|
|
19352
|
-
define(schema) {
|
|
19353
|
-
return schema.one(this.related);
|
|
19354
|
-
}
|
|
19355
|
-
/**
|
|
19356
|
-
* Attach the relational key to the given data.
|
|
19357
|
-
*/
|
|
19358
|
-
attach(key, record, data) {
|
|
19359
|
-
const relatedRecord = data[this.related.entity][key];
|
|
19360
|
-
relatedRecord[this.id] =
|
|
19361
|
-
relatedRecord[this.id] || this.related.getIdFromRecord(record);
|
|
19362
|
-
relatedRecord[this.type] = relatedRecord[this.type] || this.model.entity;
|
|
19363
|
-
}
|
|
19364
|
-
/**
|
|
19365
|
-
* Convert given value to the appropriate value for the attribute.
|
|
19366
|
-
*/
|
|
19367
|
-
make(value, _parent, _key) {
|
|
19368
|
-
return this.makeOneRelation(value, this.related);
|
|
19369
|
-
}
|
|
19370
|
-
/**
|
|
19371
|
-
* Load the morph many relationship for the record.
|
|
19372
|
-
*/
|
|
19373
|
-
load(query, collection, name, constraints) {
|
|
19374
|
-
const relatedQuery = this.getRelation(query, this.related.entity, constraints);
|
|
19375
|
-
this.addEagerConstraintForMorphOne(relatedQuery, collection, query.entity);
|
|
19376
|
-
const relations = this.mapSingleRelations(relatedQuery.get(), this.id);
|
|
19377
|
-
collection.forEach((item) => {
|
|
19378
|
-
const related = relations.get(item[this.localKey]);
|
|
19379
|
-
item[name] = related || null;
|
|
19380
|
-
});
|
|
19381
|
-
}
|
|
19382
|
-
/**
|
|
19383
|
-
* Set the constraints for an eager load of the relation.
|
|
19384
|
-
*/
|
|
19385
|
-
addEagerConstraintForMorphOne(query, collection, type) {
|
|
19386
|
-
query
|
|
19387
|
-
.whereFk(this.type, type)
|
|
19388
|
-
.whereFk(this.id, this.getKeys(collection, this.localKey));
|
|
19389
|
-
}
|
|
19390
|
-
}
|
|
19391
|
-
|
|
19392
|
-
class MorphMany extends Relation {
|
|
19393
|
-
/**
|
|
19394
|
-
* Create a new belongs to instance.
|
|
19395
|
-
*/
|
|
19396
|
-
constructor(model, related, id, type, localKey) {
|
|
19397
|
-
super(model); /* istanbul ignore next */
|
|
19398
|
-
this.related = this.model.relation(related);
|
|
19399
|
-
this.id = id;
|
|
19400
|
-
this.type = type;
|
|
19401
|
-
this.localKey = localKey;
|
|
19402
|
-
}
|
|
19403
|
-
/**
|
|
19404
|
-
* Define the normalizr schema for the relationship.
|
|
19405
|
-
*/
|
|
19406
|
-
define(schema) {
|
|
19407
|
-
return schema.many(this.related);
|
|
19408
|
-
}
|
|
19409
|
-
/**
|
|
19410
|
-
* Attach the relational key to the given data.
|
|
19411
|
-
*/
|
|
19412
|
-
attach(key, record, data) {
|
|
19413
|
-
const relatedItems = data[this.related.entity];
|
|
19414
|
-
key.forEach((id) => {
|
|
19415
|
-
const relatedItem = relatedItems[id];
|
|
19416
|
-
relatedItem[this.id] =
|
|
19417
|
-
relatedItem[this.id] || this.related.getIdFromRecord(record);
|
|
19418
|
-
relatedItem[this.type] = relatedItem[this.type] || this.model.entity;
|
|
19419
|
-
});
|
|
19420
|
-
}
|
|
19421
|
-
/**
|
|
19422
|
-
* Convert given value to the appropriate value for the attribute.
|
|
19423
|
-
*/
|
|
19424
|
-
make(value, _parent, _key) {
|
|
19425
|
-
return this.makeManyRelation(value, this.related);
|
|
19426
|
-
}
|
|
19427
|
-
/**
|
|
19428
|
-
* Load the morph many relationship for the record.
|
|
19429
|
-
*/
|
|
19430
|
-
load(query, collection, name, constraints) {
|
|
19431
|
-
const relatedQuery = this.getRelation(query, this.related.entity, constraints);
|
|
19432
|
-
this.addEagerConstraintForMorphMany(relatedQuery, collection, query.entity);
|
|
19433
|
-
const relations = this.mapManyRelations(relatedQuery.get(), this.id);
|
|
19434
|
-
collection.forEach((item) => {
|
|
19435
|
-
const related = relations.get(item[this.localKey]);
|
|
19436
|
-
item[name] = related || [];
|
|
19437
|
-
});
|
|
19438
|
-
}
|
|
19439
|
-
/**
|
|
19440
|
-
* Set the constraints for an eager load of the relation.
|
|
19441
|
-
*/
|
|
19442
|
-
addEagerConstraintForMorphMany(query, collection, type) {
|
|
19443
|
-
query
|
|
19444
|
-
.whereFk(this.type, type)
|
|
19445
|
-
.whereFk(this.id, this.getKeys(collection, this.localKey));
|
|
19446
|
-
}
|
|
19447
|
-
}
|
|
19448
|
-
|
|
19449
|
-
class MorphToMany extends Relation {
|
|
19450
|
-
/**
|
|
19451
|
-
* Create a new belongs to instance.
|
|
19452
|
-
*/
|
|
19453
|
-
constructor(model, related, pivot, relatedId, id, type, parentKey, relatedKey) {
|
|
19454
|
-
super(model); /* istanbul ignore next */
|
|
19455
|
-
/**
|
|
19456
|
-
* The key name of the pivot data.
|
|
19457
|
-
*/
|
|
19458
|
-
this.pivotKey = 'pivot';
|
|
19459
|
-
this.related = this.model.relation(related);
|
|
19460
|
-
this.pivot = this.model.relation(pivot);
|
|
19461
|
-
this.relatedId = relatedId;
|
|
19462
|
-
this.id = id;
|
|
19463
|
-
this.type = type;
|
|
19464
|
-
this.parentKey = parentKey;
|
|
19465
|
-
this.relatedKey = relatedKey;
|
|
19466
|
-
}
|
|
19467
|
-
/**
|
|
19468
|
-
* Specify the custom pivot accessor to use for the relationship.
|
|
19469
|
-
*/
|
|
19470
|
-
as(accessor) {
|
|
19471
|
-
this.pivotKey = accessor;
|
|
19472
|
-
return this;
|
|
19473
|
-
}
|
|
19474
|
-
/**
|
|
19475
|
-
* Define the normalizr schema for the relationship.
|
|
19476
|
-
*/
|
|
19477
|
-
define(schema) {
|
|
19478
|
-
return schema.many(this.related);
|
|
19479
|
-
}
|
|
19480
|
-
/**
|
|
19481
|
-
* Attach the relational key to the given record. Since morph to many
|
|
19482
|
-
* relationship doesn't have any foreign key, it would do nothing.
|
|
19483
|
-
*/
|
|
19484
|
-
attach(_key, _record, _data) {
|
|
19485
|
-
return;
|
|
19486
|
-
}
|
|
19487
|
-
/**
|
|
19488
|
-
* Convert given value to the appropriate value for the attribute.
|
|
19489
|
-
*/
|
|
19490
|
-
make(value, _parent, _key) {
|
|
19491
|
-
return this.makeManyRelation(value, this.related);
|
|
19492
|
-
}
|
|
19493
|
-
/**
|
|
19494
|
-
* Load the morph to many relationship for the collection.
|
|
19495
|
-
*/
|
|
19496
|
-
load(query, collection, name, constraints) {
|
|
19497
|
-
const relatedQuery = this.getRelation(query, this.related.entity, constraints);
|
|
19498
|
-
const pivotQuery = query.newQuery(this.pivot.entity);
|
|
19499
|
-
this.addEagerConstraintForPivot(pivotQuery, collection, query.entity);
|
|
19500
|
-
const pivots = pivotQuery.get();
|
|
19501
|
-
this.addEagerConstraintForRelated(relatedQuery, pivots);
|
|
19502
|
-
const relateds = this.mapPivotRelations(pivots, relatedQuery);
|
|
19503
|
-
collection.forEach((item) => {
|
|
19504
|
-
const related = relateds[item[this.parentKey]];
|
|
19505
|
-
item[name] = related || [];
|
|
19506
|
-
});
|
|
19507
|
-
}
|
|
19508
|
-
/**
|
|
19509
|
-
* Set the constraints for the pivot relation.
|
|
19510
|
-
*/
|
|
19511
|
-
addEagerConstraintForPivot(query, collection, type) {
|
|
19512
|
-
query
|
|
19513
|
-
.whereFk(this.type, type)
|
|
19514
|
-
.whereFk(this.id, this.getKeys(collection, this.parentKey));
|
|
19515
|
-
}
|
|
19516
|
-
/**
|
|
19517
|
-
* Set the constraints for the related relation.
|
|
19518
|
-
*/
|
|
19519
|
-
addEagerConstraintForRelated(query, collection) {
|
|
19520
|
-
query.whereFk(this.relatedKey, this.getKeys(collection, this.relatedId));
|
|
19521
|
-
}
|
|
19522
|
-
/**
|
|
19523
|
-
* Create a new indexed map for the pivot relation.
|
|
19524
|
-
*/
|
|
19525
|
-
mapPivotRelations(pivots, relatedQuery) {
|
|
19526
|
-
const relations = this.mapManyRelations(relatedQuery.get(), this.relatedKey);
|
|
19527
|
-
if (relatedQuery.orders.length) {
|
|
19528
|
-
return this.mapRelationsByOrders(pivots, relations, this.id, this.relatedId);
|
|
19529
|
-
}
|
|
19530
|
-
return pivots.reduce((records, record) => {
|
|
19531
|
-
const id = record[this.id];
|
|
19532
|
-
if (!records[id]) {
|
|
19533
|
-
records[id] = [];
|
|
19534
|
-
}
|
|
19535
|
-
const related = relations.get(record[this.relatedId]);
|
|
19536
|
-
/* istanbul ignore if */
|
|
19537
|
-
if (related === undefined || related.length === 0) {
|
|
19538
|
-
return records;
|
|
19539
|
-
}
|
|
19540
|
-
records[id] = records[id].concat(related.map((model) => {
|
|
19541
|
-
model[this.pivotKey] = record;
|
|
19542
|
-
return model;
|
|
19543
|
-
}));
|
|
19544
|
-
return records;
|
|
19545
|
-
}, {});
|
|
19546
|
-
}
|
|
19547
|
-
/**
|
|
19548
|
-
* Create pivot records for the given records if needed.
|
|
19549
|
-
*/
|
|
19550
|
-
createPivots(parent, data, key) {
|
|
19551
|
-
Utils.forOwn(data[parent.entity], (record) => {
|
|
19552
|
-
const relatedIds = parent
|
|
19553
|
-
.query()
|
|
19554
|
-
.newQuery(this.pivot.entity)
|
|
19555
|
-
.where(this.id, record[this.parentKey])
|
|
19556
|
-
.where(this.type, parent.entity)
|
|
19557
|
-
.get();
|
|
19558
|
-
const relateds = (record[key] || []).filter((relatedId) => !relatedIds.includes(relatedId));
|
|
19559
|
-
if (!Utils.isArray(relateds) || relateds.length === 0) {
|
|
19560
|
-
return;
|
|
19561
|
-
}
|
|
19562
|
-
this.createPivotRecord(parent, data, record, relateds);
|
|
19563
|
-
});
|
|
19564
|
-
return data;
|
|
19565
|
-
}
|
|
19566
|
-
/**
|
|
19567
|
-
* Create a pivot record.
|
|
19568
|
-
*/
|
|
19569
|
-
createPivotRecord(parent, data, record, related) {
|
|
19570
|
-
related.forEach((id) => {
|
|
19571
|
-
const parentId = record[this.parentKey];
|
|
19572
|
-
const relatedId = data[this.related.entity][id][this.relatedKey];
|
|
19573
|
-
const pivotKey = `${parentId}_${id}_${parent.entity}`;
|
|
19574
|
-
const pivotData = data[this.related.entity][id][this.pivotKey] || {};
|
|
19575
|
-
data[this.pivot.entity] = {
|
|
19576
|
-
...data[this.pivot.entity],
|
|
19577
|
-
[pivotKey]: {
|
|
19578
|
-
...pivotData,
|
|
19579
|
-
$id: pivotKey,
|
|
19580
|
-
[this.relatedId]: relatedId,
|
|
19581
|
-
[this.id]: parentId,
|
|
19582
|
-
[this.type]: parent.entity
|
|
19583
|
-
}
|
|
19584
|
-
};
|
|
19585
|
-
});
|
|
19586
|
-
}
|
|
19587
|
-
}
|
|
19588
|
-
|
|
19589
|
-
class MorphedByMany extends Relation {
|
|
19590
|
-
/**
|
|
19591
|
-
* Create a new belongs to instance.
|
|
19592
|
-
*/
|
|
19593
|
-
constructor(model, related, pivot, relatedId, id, type, parentKey, relatedKey) {
|
|
19594
|
-
super(model); /* istanbul ignore next */
|
|
19595
|
-
/**
|
|
19596
|
-
* The key name of the pivot data.
|
|
19597
|
-
*/
|
|
19598
|
-
this.pivotKey = 'pivot';
|
|
19599
|
-
this.related = this.model.relation(related);
|
|
19600
|
-
this.pivot = this.model.relation(pivot);
|
|
19601
|
-
this.relatedId = relatedId;
|
|
19602
|
-
this.id = id;
|
|
19603
|
-
this.type = type;
|
|
19604
|
-
this.parentKey = parentKey;
|
|
19605
|
-
this.relatedKey = relatedKey;
|
|
19606
|
-
}
|
|
19607
|
-
/**
|
|
19608
|
-
* Specify the custom pivot accessor to use for the relationship.
|
|
19609
|
-
*/
|
|
19610
|
-
as(accessor) {
|
|
19611
|
-
this.pivotKey = accessor;
|
|
19612
|
-
return this;
|
|
19613
|
-
}
|
|
19614
|
-
/**
|
|
19615
|
-
* Define the normalizr schema for the relationship.
|
|
19616
|
-
*/
|
|
19617
|
-
define(schema) {
|
|
19618
|
-
return schema.many(this.related);
|
|
19619
|
-
}
|
|
19620
|
-
/**
|
|
19621
|
-
* Attach the relational key to the given data. Since morphed by many
|
|
19622
|
-
* relationship doesn't have any foreign key, it would do nothing.
|
|
19623
|
-
*/
|
|
19624
|
-
attach(_key, _record, _data) {
|
|
19625
|
-
return;
|
|
19626
|
-
}
|
|
19627
|
-
/**
|
|
19628
|
-
* Make value to be set to model property. This method is used when
|
|
19629
|
-
* instantiating a model or creating a plain object from a model.
|
|
19630
|
-
*/
|
|
19631
|
-
make(value, _parent, _key) {
|
|
19632
|
-
return this.makeManyRelation(value, this.related);
|
|
19633
|
-
}
|
|
19634
|
-
/**
|
|
19635
|
-
* Load the morph many relationship for the record.
|
|
19636
|
-
*/
|
|
19637
|
-
load(query, collection, name, constraints) {
|
|
19638
|
-
const relatedQuery = this.getRelation(query, this.related.entity, constraints);
|
|
19639
|
-
const pivotQuery = query.newQuery(this.pivot.entity);
|
|
19640
|
-
this.addEagerConstraintForPivot(pivotQuery, collection, this.related.entity);
|
|
19641
|
-
const pivots = pivotQuery.get();
|
|
19642
|
-
this.addEagerConstraintForRelated(relatedQuery, pivots);
|
|
19643
|
-
const relateds = this.mapPivotRelations(pivots, relatedQuery);
|
|
19644
|
-
collection.forEach((item) => {
|
|
19645
|
-
const related = relateds[item[this.parentKey]];
|
|
19646
|
-
item[name] = related || [];
|
|
19647
|
-
});
|
|
19648
|
-
}
|
|
19649
|
-
/**
|
|
19650
|
-
* Set the constraints for the pivot relation.
|
|
19651
|
-
*/
|
|
19652
|
-
addEagerConstraintForPivot(query, collection, type) {
|
|
19653
|
-
query
|
|
19654
|
-
.whereFk(this.type, type)
|
|
19655
|
-
.whereFk(this.relatedId, this.getKeys(collection, this.parentKey));
|
|
19656
|
-
}
|
|
19657
|
-
/**
|
|
19658
|
-
* Set the constraints for the related relation.
|
|
19659
|
-
*/
|
|
19660
|
-
addEagerConstraintForRelated(query, collection) {
|
|
19661
|
-
query.whereFk(this.relatedKey, this.getKeys(collection, this.id));
|
|
19662
|
-
}
|
|
19663
|
-
/**
|
|
19664
|
-
* Create a new indexed map for the pivot relation.
|
|
19665
|
-
*/
|
|
19666
|
-
mapPivotRelations(pivots, relatedQuery) {
|
|
19667
|
-
const relations = this.mapManyRelations(relatedQuery.get(), this.relatedKey);
|
|
19668
|
-
if (relatedQuery.orders.length) {
|
|
19669
|
-
return this.mapRelationsByOrders(pivots, relations, this.relatedId, this.id);
|
|
19670
|
-
}
|
|
19671
|
-
return pivots.reduce((records, record) => {
|
|
19672
|
-
const id = record[this.relatedId];
|
|
19673
|
-
if (!records[id]) {
|
|
19674
|
-
records[id] = [];
|
|
19675
|
-
}
|
|
19676
|
-
const related = relations.get(record[this.id]);
|
|
19677
|
-
/* istanbul ignore if */
|
|
19678
|
-
if (related === undefined || related.length === 0) {
|
|
19679
|
-
return records;
|
|
19680
|
-
}
|
|
19681
|
-
records[id] = records[id].concat(related.map((model) => {
|
|
19682
|
-
model[this.pivotKey] = record;
|
|
19683
|
-
return model;
|
|
19684
|
-
}));
|
|
19685
|
-
return records;
|
|
19686
|
-
}, {});
|
|
19687
|
-
}
|
|
19688
|
-
/**
|
|
19689
|
-
* Create pivot records for the given records if needed.
|
|
19690
|
-
*/
|
|
19691
|
-
createPivots(parent, data, key) {
|
|
19692
|
-
Utils.forOwn(data[parent.entity], (record) => {
|
|
19693
|
-
const related = record[key];
|
|
19694
|
-
if (!Utils.isArray(related)) {
|
|
19695
|
-
return;
|
|
19696
|
-
}
|
|
19697
|
-
this.createPivotRecord(data, record, related);
|
|
19698
|
-
});
|
|
19699
|
-
return data;
|
|
19700
|
-
}
|
|
19701
|
-
/**
|
|
19702
|
-
* Create a pivot record.
|
|
19703
|
-
*/
|
|
19704
|
-
createPivotRecord(data, record, related) {
|
|
19705
|
-
related.forEach((id) => {
|
|
19706
|
-
const parentId = record[this.parentKey];
|
|
19707
|
-
const pivotKey = `${id}_${parentId}_${this.related.entity}`;
|
|
19708
|
-
const pivotData = data[this.related.entity][id][this.pivotKey] || {};
|
|
19709
|
-
data[this.pivot.entity] = {
|
|
19710
|
-
...data[this.pivot.entity],
|
|
19711
|
-
[pivotKey]: {
|
|
19712
|
-
...pivotData,
|
|
19713
|
-
$id: pivotKey,
|
|
19714
|
-
[this.relatedId]: parentId,
|
|
19715
|
-
[this.id]: this.model.getIdFromRecord(data[this.related.entity][id]),
|
|
19716
|
-
[this.type]: this.related.entity
|
|
19717
|
-
}
|
|
19718
|
-
};
|
|
19719
|
-
});
|
|
19720
|
-
}
|
|
19721
|
-
}
|
|
19722
|
-
|
|
19723
|
-
const defaultOption = {
|
|
19724
|
-
relations: true
|
|
19725
|
-
};
|
|
19726
|
-
/**
|
|
19727
|
-
* Serialize the given model to attributes. This method will ignore
|
|
19728
|
-
* relationships, and it includes the index id.
|
|
19729
|
-
*/
|
|
19730
|
-
function toAttributes(model) {
|
|
19731
|
-
const record = toJson(model, { relations: false });
|
|
19732
|
-
record.$id = model.$id;
|
|
19733
|
-
return record;
|
|
19734
|
-
}
|
|
19735
|
-
/**
|
|
19736
|
-
* Serialize given model POJO.
|
|
19737
|
-
*/
|
|
19738
|
-
function toJson(model, option = {}) {
|
|
19739
|
-
option = { ...defaultOption, ...option };
|
|
19740
|
-
const record = {};
|
|
19741
|
-
const fields = model.$fields();
|
|
19742
|
-
for (const key in fields) {
|
|
19743
|
-
const f = fields[key];
|
|
19744
|
-
const v = model[key];
|
|
19745
|
-
if (f instanceof Relation) {
|
|
19746
|
-
record[key] = option.relations ? relation(v) : emptyRelation(v);
|
|
19747
|
-
continue;
|
|
19748
|
-
}
|
|
19749
|
-
record[key] = value(model[key]);
|
|
19750
|
-
}
|
|
19751
|
-
return record;
|
|
19752
|
-
}
|
|
19753
|
-
/**
|
|
19754
|
-
* Serialize given value.
|
|
19755
|
-
*/
|
|
19756
|
-
function value(v) {
|
|
19757
|
-
if (v === null) {
|
|
19758
|
-
return null;
|
|
19759
|
-
}
|
|
19760
|
-
if (isArray(v)) {
|
|
19761
|
-
return array(v);
|
|
19762
|
-
}
|
|
19763
|
-
if (typeof v === 'object') {
|
|
19764
|
-
return object(v);
|
|
19765
|
-
}
|
|
19766
|
-
return v;
|
|
19767
|
-
}
|
|
19768
|
-
/**
|
|
19769
|
-
* Serialize an array into json.
|
|
19770
|
-
*/
|
|
19771
|
-
function array(a) {
|
|
19772
|
-
return a.map((v) => value(v));
|
|
19773
|
-
}
|
|
19774
|
-
/**
|
|
19775
|
-
* Serialize an object into json.
|
|
19776
|
-
*/
|
|
19777
|
-
function object(o) {
|
|
19778
|
-
const obj = {};
|
|
19779
|
-
for (const key in o) {
|
|
19780
|
-
obj[key] = value(o[key]);
|
|
19781
|
-
}
|
|
19782
|
-
return obj;
|
|
19783
|
-
}
|
|
19784
|
-
function relation(relation) {
|
|
19785
|
-
if (relation === null) {
|
|
19786
|
-
return null;
|
|
19787
|
-
}
|
|
19788
|
-
if (isArray(relation)) {
|
|
19789
|
-
return relation.map((model) => model.$toJson());
|
|
19790
|
-
}
|
|
19791
|
-
return relation.$toJson();
|
|
19792
|
-
}
|
|
19793
|
-
function emptyRelation(relation) {
|
|
19794
|
-
return isArray(relation) ? [] : null;
|
|
19795
|
-
}
|
|
19796
|
-
|
|
19797
|
-
class Model {
|
|
19798
|
-
/**
|
|
19799
|
-
* Create a new model instance.
|
|
19800
|
-
*/
|
|
19801
|
-
constructor(record) {
|
|
19802
|
-
/**
|
|
19803
|
-
* The index ID for the model.
|
|
19804
|
-
*/
|
|
19805
|
-
this.$id = null;
|
|
19806
|
-
this.$fill(record);
|
|
19807
|
-
}
|
|
19808
|
-
/**
|
|
19809
|
-
* The definition of the fields of the model and its relations.
|
|
19810
|
-
*/
|
|
19811
|
-
static fields() {
|
|
19812
|
-
return {};
|
|
19813
|
-
}
|
|
19814
|
-
/**
|
|
19815
|
-
* Create an attr attribute.
|
|
19816
|
-
*/
|
|
19817
|
-
static attr(value, mutator) {
|
|
19818
|
-
return new Attr(this, value, mutator);
|
|
19819
|
-
}
|
|
19820
|
-
/**
|
|
19821
|
-
* Create a string attribute.
|
|
19822
|
-
*/
|
|
19823
|
-
static string(value, mutator) {
|
|
19824
|
-
return new String$1(this, value, mutator);
|
|
19825
|
-
}
|
|
19826
|
-
/**
|
|
19827
|
-
* Create a number attribute.
|
|
19828
|
-
*/
|
|
19829
|
-
static number(value, mutator) {
|
|
19830
|
-
return new Number$1(this, value, mutator);
|
|
19831
|
-
}
|
|
19832
|
-
/**
|
|
19833
|
-
* Create a boolean attribute.
|
|
19834
|
-
*/
|
|
19835
|
-
static boolean(value, mutator) {
|
|
19836
|
-
return new Boolean$1(this, value, mutator);
|
|
19837
|
-
}
|
|
19838
|
-
/**
|
|
19839
|
-
* Create an uid attribute.
|
|
19840
|
-
*/
|
|
19841
|
-
static uid(value) {
|
|
19842
|
-
return new Uid(this, value);
|
|
19843
|
-
}
|
|
19844
|
-
/**
|
|
19845
|
-
* @deprecated Use `uid` attribute instead.
|
|
19846
|
-
*/
|
|
19847
|
-
static increment() {
|
|
19848
|
-
/* istanbul ignore next */
|
|
19849
|
-
{
|
|
19850
|
-
console.warn('[Vuex ORM] Attribute type `increment` has been deprecated and replaced with `uid`.');
|
|
19851
|
-
}
|
|
19852
|
-
return this.uid();
|
|
19853
|
-
}
|
|
19854
|
-
/**
|
|
19855
|
-
* Create a has one relationship.
|
|
19856
|
-
*/
|
|
19857
|
-
static hasOne(related, foreignKey, localKey) {
|
|
19858
|
-
return new HasOne(this, related, foreignKey, this.localKey(localKey));
|
|
19859
|
-
}
|
|
19860
|
-
/**
|
|
19861
|
-
* Create a belongs to relationship.
|
|
19862
|
-
*/
|
|
19863
|
-
static belongsTo(parent, foreignKey, ownerKey) {
|
|
19864
|
-
return new BelongsTo(this, parent, foreignKey, this.relation(parent).localKey(ownerKey));
|
|
19865
|
-
}
|
|
19866
|
-
/**
|
|
19867
|
-
* Create a has many relationship.
|
|
19868
|
-
*/
|
|
19869
|
-
static hasMany(related, foreignKey, localKey) {
|
|
19870
|
-
return new HasMany(this, related, foreignKey, this.localKey(localKey));
|
|
19871
|
-
}
|
|
19872
|
-
/**
|
|
19873
|
-
* Create a has many by relationship.
|
|
19874
|
-
*/
|
|
19875
|
-
static hasManyBy(parent, foreignKey, ownerKey) {
|
|
19876
|
-
return new HasManyBy(this, parent, foreignKey, this.relation(parent).localKey(ownerKey));
|
|
19877
|
-
}
|
|
19878
|
-
/**
|
|
19879
|
-
* Create a has many through relationship.
|
|
19880
|
-
*/
|
|
19881
|
-
static hasManyThrough(related, through, firstKey, secondKey, localKey, secondLocalKey) {
|
|
19882
|
-
return new HasManyThrough(this, related, through, firstKey, secondKey, this.localKey(localKey), this.relation(through).localKey(secondLocalKey));
|
|
19883
|
-
}
|
|
19884
|
-
/**
|
|
19885
|
-
* Create a belongs to many relationship.
|
|
19886
|
-
*/
|
|
19887
|
-
static belongsToMany(related, pivot, foreignPivotKey, relatedPivotKey, parentKey, relatedKey) {
|
|
19888
|
-
return new BelongsToMany(this, related, pivot, foreignPivotKey, relatedPivotKey, this.localKey(parentKey), this.relation(related).localKey(relatedKey));
|
|
19889
|
-
}
|
|
19890
|
-
/**
|
|
19891
|
-
* Create a morph to relationship.
|
|
19892
|
-
*/
|
|
19893
|
-
static morphTo(id, type) {
|
|
19894
|
-
return new MorphTo(this, id, type);
|
|
19895
|
-
}
|
|
19896
|
-
/**
|
|
19897
|
-
* Create a morph one relationship.
|
|
19898
|
-
*/
|
|
19899
|
-
static morphOne(related, id, type, localKey) {
|
|
19900
|
-
return new MorphOne(this, related, id, type, this.localKey(localKey));
|
|
19901
|
-
}
|
|
19902
|
-
/**
|
|
19903
|
-
* Create a morph many relationship.
|
|
19904
|
-
*/
|
|
19905
|
-
static morphMany(related, id, type, localKey) {
|
|
19906
|
-
return new MorphMany(this, related, id, type, this.localKey(localKey));
|
|
19907
|
-
}
|
|
19908
|
-
/**
|
|
19909
|
-
* Create a morph to many relationship.
|
|
19910
|
-
*/
|
|
19911
|
-
static morphToMany(related, pivot, relatedId, id, type, parentKey, relatedKey) {
|
|
19912
|
-
return new MorphToMany(this, related, pivot, relatedId, id, type, this.localKey(parentKey), this.relation(related).localKey(relatedKey));
|
|
19913
|
-
}
|
|
19914
|
-
/**
|
|
19915
|
-
* Create a morphed by many relationship.
|
|
19916
|
-
*/
|
|
19917
|
-
static morphedByMany(related, pivot, relatedId, id, type, parentKey, relatedKey) {
|
|
19918
|
-
return new MorphedByMany(this, related, pivot, relatedId, id, type, this.localKey(parentKey), this.relation(related).localKey(relatedKey));
|
|
19919
|
-
}
|
|
19920
|
-
/**
|
|
19921
|
-
* Mutators to mutate matching fields when instantiating the model.
|
|
19922
|
-
*/
|
|
19923
|
-
static mutators() {
|
|
19924
|
-
return {};
|
|
19925
|
-
}
|
|
19926
|
-
/**
|
|
19927
|
-
* Types mapping used to dispatch entities based on their discriminator field
|
|
19928
|
-
*/
|
|
19929
|
-
static types() {
|
|
19930
|
-
return {};
|
|
19931
|
-
}
|
|
19932
|
-
/**
|
|
19933
|
-
* Get the store instance from the container.
|
|
19934
|
-
*/
|
|
19935
|
-
static store() {
|
|
19936
|
-
return Container.store;
|
|
19937
|
-
}
|
|
19938
|
-
/**
|
|
19939
|
-
* Get the database instance from store.
|
|
19940
|
-
*/
|
|
19941
|
-
static database() {
|
|
19942
|
-
return this.store().$db();
|
|
19943
|
-
}
|
|
19944
|
-
/**
|
|
19945
|
-
* Create a namespaced method name for Vuex Module from the given
|
|
19946
|
-
* method name.
|
|
19947
|
-
*/
|
|
19948
|
-
static namespace(method) {
|
|
19949
|
-
return `${this.database().namespace}/${this.entity}/${method}`;
|
|
19950
|
-
}
|
|
19951
|
-
/**
|
|
19952
|
-
* Call Vuex Getters.
|
|
19953
|
-
*/
|
|
19954
|
-
static getters(method) {
|
|
19955
|
-
return this.store().getters[this.namespace(method)];
|
|
19956
|
-
}
|
|
19957
|
-
/**
|
|
19958
|
-
* Dispatch Vuex Action.
|
|
19959
|
-
*/
|
|
19960
|
-
static dispatch(method, payload) {
|
|
19961
|
-
return this.store().dispatch(this.namespace(method), payload);
|
|
19962
|
-
}
|
|
19963
|
-
/**
|
|
19964
|
-
* Commit Vuex Mutation.
|
|
19965
|
-
*/
|
|
19966
|
-
static commit(callback) {
|
|
19967
|
-
this.store().commit(`${this.database().namespace}/$mutate`, {
|
|
19968
|
-
entity: this.entity,
|
|
19969
|
-
callback
|
|
19970
|
-
});
|
|
19971
|
-
}
|
|
19972
|
-
/**
|
|
19973
|
-
* Get the Model schema definition from the cache.
|
|
19974
|
-
*/
|
|
19975
|
-
static getFields() {
|
|
19976
|
-
if (!this.cachedFields) {
|
|
19977
|
-
this.cachedFields = {};
|
|
19978
|
-
}
|
|
19979
|
-
if (this.cachedFields[this.entity]) {
|
|
19980
|
-
return this.cachedFields[this.entity];
|
|
19981
|
-
}
|
|
19982
|
-
this.cachedFields[this.entity] = this.fields();
|
|
19983
|
-
return this.cachedFields[this.entity];
|
|
19984
|
-
}
|
|
19985
|
-
/**
|
|
19986
|
-
* Get all records.
|
|
19987
|
-
*/
|
|
19988
|
-
static all() {
|
|
19989
|
-
return this.getters('all')();
|
|
19990
|
-
}
|
|
19991
|
-
/**
|
|
19992
|
-
* Find a record.
|
|
19993
|
-
*/
|
|
19994
|
-
static find(id) {
|
|
19995
|
-
return this.getters('find')(id);
|
|
19996
|
-
}
|
|
19997
|
-
/**
|
|
19998
|
-
* Get the record of the given array of ids.
|
|
19999
|
-
*/
|
|
20000
|
-
static findIn(idList) {
|
|
20001
|
-
return this.getters('findIn')(idList);
|
|
20002
|
-
}
|
|
20003
|
-
/**
|
|
20004
|
-
* Get query instance.
|
|
20005
|
-
*/
|
|
20006
|
-
static query() {
|
|
20007
|
-
return this.getters('query')();
|
|
20008
|
-
}
|
|
20009
|
-
/**
|
|
20010
|
-
* Check wether the associated database contains data.
|
|
20011
|
-
*/
|
|
20012
|
-
static exists() {
|
|
20013
|
-
return this.query().exists();
|
|
20014
|
-
}
|
|
20015
|
-
/**
|
|
20016
|
-
* Create new data with all fields filled by default values.
|
|
20017
|
-
*/
|
|
20018
|
-
static new() {
|
|
20019
|
-
return this.dispatch('new');
|
|
20020
|
-
}
|
|
20021
|
-
/**
|
|
20022
|
-
* Save given data to the store by replacing all existing records in the
|
|
20023
|
-
* store. If you want to save data without replacing existing records,
|
|
20024
|
-
* use the `insert` method instead.
|
|
20025
|
-
*/
|
|
20026
|
-
static create(payload) {
|
|
20027
|
-
return this.dispatch('create', payload);
|
|
20028
|
-
}
|
|
20029
|
-
/**
|
|
20030
|
-
* Insert records.
|
|
20031
|
-
*/
|
|
20032
|
-
static insert(payload) {
|
|
20033
|
-
return this.dispatch('insert', payload);
|
|
20034
|
-
}
|
|
20035
|
-
/**
|
|
20036
|
-
* Update records.
|
|
20037
|
-
*/
|
|
20038
|
-
static update(payload) {
|
|
20039
|
-
return this.dispatch('update', payload);
|
|
20040
|
-
}
|
|
20041
|
-
/**
|
|
20042
|
-
* Insert or update records.
|
|
20043
|
-
*/
|
|
20044
|
-
static insertOrUpdate(payload) {
|
|
20045
|
-
return this.dispatch('insertOrUpdate', payload);
|
|
20046
|
-
}
|
|
20047
|
-
static delete(payload) {
|
|
20048
|
-
return this.dispatch('delete', payload);
|
|
20049
|
-
}
|
|
20050
|
-
/**
|
|
20051
|
-
* Delete all records from the store.
|
|
20052
|
-
*/
|
|
20053
|
-
static deleteAll() {
|
|
20054
|
-
return this.dispatch('deleteAll');
|
|
20055
|
-
}
|
|
20056
|
-
/**
|
|
20057
|
-
* Check if the given key is the primary key. If the model has composite
|
|
20058
|
-
* primary key, this method is going to check if the given key is included
|
|
20059
|
-
* in the composite key.
|
|
20060
|
-
*/
|
|
20061
|
-
static isPrimaryKey(key) {
|
|
20062
|
-
if (!Utils.isArray(this.primaryKey)) {
|
|
20063
|
-
return this.primaryKey === key;
|
|
20064
|
-
}
|
|
20065
|
-
return this.primaryKey.includes(key);
|
|
20066
|
-
}
|
|
20067
|
-
/**
|
|
20068
|
-
* Check if the primary key is a composite key.
|
|
20069
|
-
*/
|
|
20070
|
-
static isCompositePrimaryKey() {
|
|
20071
|
-
return Utils.isArray(this.primaryKey);
|
|
20072
|
-
}
|
|
20073
|
-
/**
|
|
20074
|
-
* Get the id (value of primary key) from teh given record. If primary key is
|
|
20075
|
-
* not present, or it is invalid primary key value, which is other than
|
|
20076
|
-
* `string` or `number`, it's going to return `null`.
|
|
20077
|
-
*
|
|
20078
|
-
* If the model has composite key, it's going to return array of ids. If any
|
|
20079
|
-
* composite key missing, it will return `null`.
|
|
20080
|
-
*/
|
|
20081
|
-
static getIdFromRecord(record) {
|
|
20082
|
-
const key = this.primaryKey;
|
|
20083
|
-
if (typeof key === 'string') {
|
|
20084
|
-
return this.getIdFromValue(record[key]);
|
|
20085
|
-
}
|
|
20086
|
-
const ids = key.reduce((keys, k) => {
|
|
20087
|
-
const id = this.getIdFromValue(record[k]);
|
|
20088
|
-
id !== null && keys.push(id);
|
|
20089
|
-
return keys;
|
|
20090
|
-
}, []);
|
|
20091
|
-
return ids.length === key.length ? ids : null;
|
|
20092
|
-
}
|
|
20093
|
-
/**
|
|
20094
|
-
* Get correct index id, which is `string` | `number`, from the given value.
|
|
20095
|
-
*/
|
|
20096
|
-
static getIdFromValue(value) {
|
|
20097
|
-
if (typeof value === 'string' && value !== '') {
|
|
20098
|
-
return value;
|
|
20099
|
-
}
|
|
20100
|
-
if (typeof value === 'number') {
|
|
20101
|
-
return value;
|
|
20102
|
-
}
|
|
20103
|
-
return null;
|
|
20104
|
-
}
|
|
20105
|
-
/**
|
|
20106
|
-
* Get the index ID value from the given record. An index ID is a value that
|
|
20107
|
-
* used as a key for records within the Vuex Store.
|
|
20108
|
-
*
|
|
20109
|
-
* Most of the time, it's same as the value for the Model's primary key but
|
|
20110
|
-
* it's always `string`, even if the primary key value is `number`.
|
|
20111
|
-
*
|
|
20112
|
-
* If the Model has a composite primary key, each value corresponding to
|
|
20113
|
-
* those primary key will be stringified and become a single string value
|
|
20114
|
-
* such as `'[1,2]'`.
|
|
20115
|
-
*
|
|
20116
|
-
* If the primary key is not present at the given record, it returns `null`.
|
|
20117
|
-
* For the composite primary key, every key must exist at a given record,
|
|
20118
|
-
* or it will return `null`.
|
|
20119
|
-
*/
|
|
20120
|
-
static getIndexIdFromRecord(record) {
|
|
20121
|
-
const id = this.getIdFromRecord(record);
|
|
20122
|
-
if (id === null) {
|
|
20123
|
-
return null;
|
|
20124
|
-
}
|
|
20125
|
-
if (Utils.isArray(id)) {
|
|
20126
|
-
return JSON.stringify(id);
|
|
20127
|
-
}
|
|
20128
|
-
return String(id);
|
|
20129
|
-
}
|
|
20130
|
-
/**
|
|
20131
|
-
* Get local key to pass to the attributes.
|
|
20132
|
-
*/
|
|
20133
|
-
static localKey(key) {
|
|
20134
|
-
if (key) {
|
|
20135
|
-
return key;
|
|
20136
|
-
}
|
|
20137
|
-
return typeof this.primaryKey === 'string' ? this.primaryKey : 'id';
|
|
20138
|
-
}
|
|
20139
|
-
/**
|
|
20140
|
-
* Get the model object that matches the given record type. The method is for
|
|
20141
|
-
* getting the correct model object when the model has any inheritance
|
|
20142
|
-
* children model.
|
|
20143
|
-
*
|
|
20144
|
-
* For example, if a User Model have `static types()` declared, and if you
|
|
20145
|
-
* pass record with `{ type: 'admin' }`, then the method will likely to
|
|
20146
|
-
* return SuperUser class.
|
|
20147
|
-
*/
|
|
20148
|
-
static getModelFromRecord(record) {
|
|
20149
|
-
// If the given record is already a model instance, return the
|
|
20150
|
-
// model object.
|
|
20151
|
-
if (record instanceof this) {
|
|
20152
|
-
return record.$self();
|
|
20153
|
-
}
|
|
20154
|
-
// Else, get the corresponding model for the type value if there's any.
|
|
20155
|
-
return this.getTypeModel(record[this.typeKey]);
|
|
20156
|
-
}
|
|
20157
|
-
/**
|
|
20158
|
-
* Get a model from the container.
|
|
20159
|
-
*/
|
|
20160
|
-
static relation(model) {
|
|
20161
|
-
if (typeof model !== 'string') {
|
|
20162
|
-
return model;
|
|
20163
|
-
}
|
|
20164
|
-
return this.database().model(model);
|
|
20165
|
-
}
|
|
20166
|
-
/**
|
|
20167
|
-
* Get all `belongsToMany` fields from the schema.
|
|
20168
|
-
*/
|
|
20169
|
-
static pivotFields() {
|
|
20170
|
-
const fields = [];
|
|
20171
|
-
Utils.forOwn(this.getFields(), (field, key) => {
|
|
20172
|
-
if (field instanceof BelongsToMany ||
|
|
20173
|
-
field instanceof MorphToMany ||
|
|
20174
|
-
field instanceof MorphedByMany) {
|
|
20175
|
-
fields.push({ [key]: field });
|
|
20176
|
-
}
|
|
20177
|
-
});
|
|
20178
|
-
return fields;
|
|
20179
|
-
}
|
|
20180
|
-
/**
|
|
20181
|
-
* Check if fields contains the `belongsToMany` field type.
|
|
20182
|
-
*/
|
|
20183
|
-
static hasPivotFields() {
|
|
20184
|
-
return this.pivotFields().length > 0;
|
|
20185
|
-
}
|
|
20186
|
-
/**
|
|
20187
|
-
* Check if the current model has a type definition
|
|
20188
|
-
*/
|
|
20189
|
-
static hasTypes() {
|
|
20190
|
-
return Object.keys(this.types()).length > 0;
|
|
20191
|
-
}
|
|
20192
|
-
/**
|
|
20193
|
-
* Get the model corresponding to the given type name. If it can't be found,
|
|
20194
|
-
* it'll return `null`.
|
|
20195
|
-
*/
|
|
20196
|
-
static getTypeModel(name) {
|
|
20197
|
-
const model = this.types()[name];
|
|
20198
|
-
if (!model) {
|
|
20199
|
-
return null;
|
|
20200
|
-
}
|
|
20201
|
-
return model;
|
|
20202
|
-
}
|
|
20203
|
-
/**
|
|
20204
|
-
* Given a Model, this returns the corresponding key in the InheritanceTypes mapping
|
|
20205
|
-
*/
|
|
20206
|
-
static getTypeKeyValueFromModel(model) {
|
|
20207
|
-
const modelToCheck = model || this;
|
|
20208
|
-
const types = this.types();
|
|
20209
|
-
for (const type in types) {
|
|
20210
|
-
if (types[type].entity === modelToCheck.entity) {
|
|
20211
|
-
return type;
|
|
20212
|
-
}
|
|
20213
|
-
}
|
|
20214
|
-
return null;
|
|
20215
|
-
}
|
|
20216
|
-
/**
|
|
20217
|
-
* Tries to find a Relation field in all types defined in the InheritanceTypes mapping
|
|
20218
|
-
*/
|
|
20219
|
-
static findRelationInSubTypes(relationName) {
|
|
20220
|
-
const types = this.types();
|
|
20221
|
-
for (const type in types) {
|
|
20222
|
-
const fields = types[type].getFields();
|
|
20223
|
-
for (const fieldName in fields) {
|
|
20224
|
-
if (fieldName === relationName &&
|
|
20225
|
-
fields[fieldName] instanceof Relation) {
|
|
20226
|
-
return fields[fieldName];
|
|
20227
|
-
}
|
|
20228
|
-
}
|
|
20229
|
-
}
|
|
20230
|
-
return null;
|
|
20231
|
-
}
|
|
20232
|
-
/**
|
|
20233
|
-
* Fill any missing fields in the given record with the default value defined
|
|
20234
|
-
* in the model schema.
|
|
20235
|
-
*/
|
|
20236
|
-
static hydrate(record) {
|
|
20237
|
-
return new this(record).$getAttributes();
|
|
20238
|
-
}
|
|
20239
|
-
/**
|
|
20240
|
-
* Get the constructor of this model.
|
|
20241
|
-
*/
|
|
20242
|
-
$self() {
|
|
20243
|
-
return this.constructor;
|
|
20244
|
-
}
|
|
20245
|
-
/**
|
|
20246
|
-
* Get the primary key for the model.
|
|
20247
|
-
*/
|
|
20248
|
-
$primaryKey() {
|
|
20249
|
-
return this.$self().primaryKey;
|
|
20250
|
-
}
|
|
20251
|
-
/**
|
|
20252
|
-
* The definition of the fields of the model and its relations.
|
|
20253
|
-
*/
|
|
20254
|
-
$fields() {
|
|
20255
|
-
return this.$self().getFields();
|
|
20256
|
-
}
|
|
20257
|
-
/**
|
|
20258
|
-
* Set index id.
|
|
20259
|
-
*/
|
|
20260
|
-
$setIndexId(id) {
|
|
20261
|
-
this.$id = id;
|
|
20262
|
-
return this;
|
|
20263
|
-
}
|
|
20264
|
-
/**
|
|
20265
|
-
* Get the store instance from the container.
|
|
20266
|
-
*/
|
|
20267
|
-
$store() {
|
|
20268
|
-
return this.$self().store();
|
|
20269
|
-
}
|
|
20270
|
-
/**
|
|
20271
|
-
* Create a namespaced method name for Vuex Module from the given
|
|
20272
|
-
* method name.
|
|
20273
|
-
*/
|
|
20274
|
-
$namespace(method) {
|
|
20275
|
-
return this.$self().namespace(method);
|
|
20276
|
-
}
|
|
20277
|
-
/**
|
|
20278
|
-
* Call Vuex Getetrs.
|
|
20279
|
-
*/
|
|
20280
|
-
$getters(method) {
|
|
20281
|
-
return this.$self().getters(method);
|
|
20282
|
-
}
|
|
20283
|
-
/**
|
|
20284
|
-
* Dispatch Vuex Action.
|
|
20285
|
-
*/
|
|
20286
|
-
async $dispatch(method, payload) {
|
|
20287
|
-
return this.$self().dispatch(method, payload);
|
|
20288
|
-
}
|
|
20289
|
-
/**
|
|
20290
|
-
* Get all records.
|
|
20291
|
-
*/
|
|
20292
|
-
$all() {
|
|
20293
|
-
return this.$getters('all')();
|
|
20294
|
-
}
|
|
20295
|
-
/**
|
|
20296
|
-
* Find a record.
|
|
20297
|
-
*/
|
|
20298
|
-
$find(id) {
|
|
20299
|
-
return this.$getters('find')(id);
|
|
20300
|
-
}
|
|
20301
|
-
/**
|
|
20302
|
-
* Find record of the given array of ids.
|
|
20303
|
-
*/
|
|
20304
|
-
$findIn(idList) {
|
|
20305
|
-
return this.$getters('findIn')(idList);
|
|
20306
|
-
}
|
|
20307
|
-
/**
|
|
20308
|
-
* Get query instance.
|
|
20309
|
-
*/
|
|
20310
|
-
$query() {
|
|
20311
|
-
return this.$getters('query')();
|
|
20312
|
-
}
|
|
20313
|
-
/**
|
|
20314
|
-
* Create records.
|
|
20315
|
-
*/
|
|
20316
|
-
async $create(payload) {
|
|
20317
|
-
return this.$dispatch('create', payload);
|
|
20318
|
-
}
|
|
20319
|
-
/**
|
|
20320
|
-
* Create records.
|
|
20321
|
-
*/
|
|
20322
|
-
async $insert(payload) {
|
|
20323
|
-
return this.$dispatch('insert', payload);
|
|
20324
|
-
}
|
|
20325
|
-
/**
|
|
20326
|
-
* Update records.
|
|
20327
|
-
*/
|
|
20328
|
-
async $update(payload) {
|
|
20329
|
-
if (Utils.isArray(payload)) {
|
|
20330
|
-
return this.$dispatch('update', payload);
|
|
20331
|
-
}
|
|
20332
|
-
if (payload.where !== undefined) {
|
|
20333
|
-
return this.$dispatch('update', payload);
|
|
20334
|
-
}
|
|
20335
|
-
if (this.$self().getIndexIdFromRecord(payload) === null) {
|
|
20336
|
-
return this.$dispatch('update', {
|
|
20337
|
-
where: this.$self().getIdFromRecord(this),
|
|
20338
|
-
data: payload
|
|
20339
|
-
});
|
|
20340
|
-
}
|
|
20341
|
-
return this.$dispatch('update', payload);
|
|
20342
|
-
}
|
|
20343
|
-
/**
|
|
20344
|
-
* Insert or update records.
|
|
20345
|
-
*/
|
|
20346
|
-
async $insertOrUpdate(payload) {
|
|
20347
|
-
return this.$dispatch('insertOrUpdate', payload);
|
|
20348
|
-
}
|
|
20349
|
-
/**
|
|
20350
|
-
* Save record.
|
|
20351
|
-
*/
|
|
20352
|
-
async $save() {
|
|
20353
|
-
const fields = this.$self().getFields();
|
|
20354
|
-
const record = Object.keys(fields).reduce((record, key) => {
|
|
20355
|
-
if (fields[key] instanceof Type) {
|
|
20356
|
-
record[key] = this[key];
|
|
20357
|
-
}
|
|
20358
|
-
return record;
|
|
20359
|
-
}, {});
|
|
20360
|
-
const records = await this.$dispatch('insertOrUpdate', { data: record });
|
|
20361
|
-
this.$fill(records[this.$self().entity][0]);
|
|
20362
|
-
return this;
|
|
20363
|
-
}
|
|
20364
|
-
/**
|
|
20365
|
-
* Delete records that matches the given condition.
|
|
20366
|
-
*/
|
|
20367
|
-
async $delete() {
|
|
20368
|
-
const primaryKey = this.$primaryKey();
|
|
20369
|
-
if (!Utils.isArray(primaryKey)) {
|
|
20370
|
-
return this.$dispatch('delete', this[primaryKey]);
|
|
20371
|
-
}
|
|
20372
|
-
return this.$dispatch('delete', (model) => {
|
|
20373
|
-
return primaryKey.every((id) => model[id] === this[id]);
|
|
20374
|
-
});
|
|
20375
|
-
}
|
|
20376
|
-
/**
|
|
20377
|
-
* Delete all records.
|
|
20378
|
-
*/
|
|
20379
|
-
async $deleteAll() {
|
|
20380
|
-
return this.$dispatch('deleteAll');
|
|
20381
|
-
}
|
|
20382
|
-
/**
|
|
20383
|
-
* Fill the model instance with the given record. If no record were passed,
|
|
20384
|
-
* or if the record has any missing fields, each value of the fields will
|
|
20385
|
-
* be filled with its default value defined at model fields definition.
|
|
20386
|
-
*/
|
|
20387
|
-
$fill(record = {}) {
|
|
20388
|
-
const fields = this.$fields();
|
|
20389
|
-
for (const key in fields) {
|
|
20390
|
-
const field = fields[key];
|
|
20391
|
-
const value = record[key];
|
|
20392
|
-
this[key] = field.make(value, record, key);
|
|
20393
|
-
}
|
|
20394
|
-
// If the record contains index id, set it to the model.
|
|
20395
|
-
record.$id !== undefined && this.$setIndexId(record.$id);
|
|
20396
|
-
}
|
|
20397
|
-
/**
|
|
20398
|
-
* Generate missing primary ids and index id.
|
|
20399
|
-
*/
|
|
20400
|
-
$generateId() {
|
|
20401
|
-
return this.$generatePrimaryId().$generateIndexId();
|
|
20402
|
-
}
|
|
20403
|
-
/**
|
|
20404
|
-
* Generate any missing primary ids.
|
|
20405
|
-
*/
|
|
20406
|
-
$generatePrimaryId() {
|
|
20407
|
-
const key = this.$self().primaryKey;
|
|
20408
|
-
const keys = Utils.isArray(key) ? key : [key];
|
|
20409
|
-
keys.forEach((k) => {
|
|
20410
|
-
if (this[k] === undefined || this[k] === null) {
|
|
20411
|
-
this[k] = Uid$1.make();
|
|
20412
|
-
}
|
|
20413
|
-
});
|
|
20414
|
-
return this;
|
|
20415
|
-
}
|
|
20416
|
-
/**
|
|
20417
|
-
* Generate index id from current model attributes.
|
|
20418
|
-
*/
|
|
20419
|
-
$generateIndexId() {
|
|
20420
|
-
return this.$setIndexId(this.$getIndexIdFromAttributes());
|
|
20421
|
-
}
|
|
20422
|
-
/**
|
|
20423
|
-
* Get index id based on current model attributes.
|
|
20424
|
-
*/
|
|
20425
|
-
$getIndexIdFromAttributes() {
|
|
20426
|
-
return this.$self().getIndexIdFromRecord(this);
|
|
20427
|
-
}
|
|
20428
|
-
/**
|
|
20429
|
-
* Get all of the current attributes on the model. It includes index id
|
|
20430
|
-
* value as well. This method is mainly used when saving a model to
|
|
20431
|
-
* the store.
|
|
20432
|
-
*/
|
|
20433
|
-
$getAttributes() {
|
|
20434
|
-
return toAttributes(this);
|
|
20435
|
-
}
|
|
20436
|
-
/**
|
|
20437
|
-
* Serialize field values into json.
|
|
20438
|
-
*/
|
|
20439
|
-
$toJson() {
|
|
20440
|
-
return toJson(this);
|
|
20441
|
-
}
|
|
20442
|
-
}
|
|
20443
|
-
/**
|
|
20444
|
-
* The primary key to be used for the model.
|
|
20445
|
-
*/
|
|
20446
|
-
Model.primaryKey = 'id';
|
|
20447
|
-
/**
|
|
20448
|
-
* The discriminator key to be used for the model when inheritance is used
|
|
20449
|
-
*/
|
|
20450
|
-
Model.typeKey = 'type';
|
|
20451
|
-
/**
|
|
20452
|
-
* Vuex Store state definition.
|
|
20453
|
-
*/
|
|
20454
|
-
Model.state = {};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}}var css = "tr td[data-v-fa834ca3]:last-child,\ntr td[data-v-fa834ca3]:first-child {\n width: 1%;\n white-space: nowrap; }\n\n.crud-pagination[data-v-fa834ca3] {\n display: flex;\n justify-content: center; }\n\n.crud-header[data-v-fa834ca3] {\n display: flex;\n justify-content: space-between;\n max-height: 3rem; }\n .crud-header[data-v-fa834ca3] .crud-title[data-v-fa834ca3] {\n margin: 0; }\n .crud-header[data-v-fa834ca3] .crud-search[data-v-fa834ca3] {\n max-width: 15rem; }\n .crud-header[data-v-fa834ca3] .crud-search[data-v-fa834ca3] .btn[data-v-fa834ca3] {\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-fa834ca3] .crud-search[data-v-fa834ca3] .btn[data-v-fa834ca3].open[data-v-fa834ca3] {\n border-top-right-radius: 0;\n border-bottom-right-radius: 0; }\n .crud-header[data-v-fa834ca3] .table-options[data-v-fa834ca3] {\n margin-bottom: 1rem;\n display: flex;\n align-items: center;\n justify-content: flex-end; }\n\n.custom-control[data-v-fa834ca3] {\n position: relative;\n top: -15px; }\n\n@media (min-width: 992px) {\n .table[data-v-fa834ca3] {\n table-layout: auto; }\n .table[data-v-fa834ca3] tbody[data-v-fa834ca3] td[data-v-fa834ca3] {\n overflow: scroll;\n -ms-overflow-style: none;\n /* IE and Edge */\n scrollbar-width: none;\n /* Firefox */ }\n .table[data-v-fa834ca3] tbody[data-v-fa834ca3] td[data-v-fa834ca3]::-webkit-scrollbar {\n display: none; } }\n";
|
|
17308
|
+
var moment = momentExports;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}}var css = "tr td[data-v-cc7b4474]:last-child,\ntr td[data-v-cc7b4474]:first-child {\n width: 1%;\n white-space: nowrap; }\n\n.crud-pagination[data-v-cc7b4474] {\n display: flex;\n justify-content: center; }\n\n.crud-header[data-v-cc7b4474] {\n display: flex;\n justify-content: space-between;\n max-height: 3rem; }\n .crud-header[data-v-cc7b4474] .crud-title[data-v-cc7b4474] {\n margin: 0; }\n .crud-header[data-v-cc7b4474] .crud-search[data-v-cc7b4474] {\n max-width: 15rem; }\n .crud-header[data-v-cc7b4474] .crud-search[data-v-cc7b4474] .btn[data-v-cc7b4474] {\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-cc7b4474] .crud-search[data-v-cc7b4474] .btn[data-v-cc7b4474].open[data-v-cc7b4474] {\n border-top-right-radius: 0;\n border-bottom-right-radius: 0; }\n .crud-header[data-v-cc7b4474] .table-options[data-v-cc7b4474] {\n margin-bottom: 1rem;\n display: flex;\n align-items: center;\n justify-content: flex-end; }\n\n.custom-control[data-v-cc7b4474] {\n position: relative;\n top: -15px; }\n\n@media (min-width: 992px) {\n .table[data-v-cc7b4474] {\n table-layout: auto; }\n .table[data-v-cc7b4474] tbody[data-v-cc7b4474] td[data-v-cc7b4474] {\n overflow: scroll;\n -ms-overflow-style: none;\n /* IE and Edge */\n scrollbar-width: none;\n /* Firefox */ }\n .table[data-v-cc7b4474] tbody[data-v-cc7b4474] td[data-v-cc7b4474]::-webkit-scrollbar {\n display: none; } }\n";
|
|
20455
17309
|
n(css, {});function normalizeComponent (
|
|
20456
17310
|
scriptExports,
|
|
20457
17311
|
render,
|
|
@@ -20595,7 +17449,7 @@ n(css, {});function normalizeComponent (
|
|
|
20595
17449
|
modelName: String,
|
|
20596
17450
|
title: String,
|
|
20597
17451
|
model: {
|
|
20598
|
-
type: Object |
|
|
17452
|
+
type: Object | Function,
|
|
20599
17453
|
default: function _default() {
|
|
20600
17454
|
return {
|
|
20601
17455
|
id: 0
|
|
@@ -21055,7 +17909,7 @@ n(css, {});function normalizeComponent (
|
|
|
21055
17909
|
var _arguments = arguments,
|
|
21056
17910
|
_this8 = this;
|
|
21057
17911
|
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
21058
|
-
var page;
|
|
17912
|
+
var page, result;
|
|
21059
17913
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
21060
17914
|
while (1) switch (_context.prev = _context.next) {
|
|
21061
17915
|
case 0:
|
|
@@ -21063,12 +17917,19 @@ n(css, {});function normalizeComponent (
|
|
|
21063
17917
|
_this8.loading = true;
|
|
21064
17918
|
_this8.$emit("beforeFetch", {});
|
|
21065
17919
|
_context.next = 5;
|
|
21066
|
-
return _this8.model.api().
|
|
17920
|
+
return _this8.model.api().get('', {
|
|
17921
|
+
params: {
|
|
17922
|
+
page: page,
|
|
17923
|
+
limit: _this8.pagination.perPage,
|
|
17924
|
+
filters: JSON.stringify(_this8.finalFilters)
|
|
17925
|
+
}
|
|
17926
|
+
});
|
|
21067
17927
|
case 5:
|
|
21068
|
-
|
|
17928
|
+
result = _context.sent;
|
|
17929
|
+
_this8.collection = result.entities[_this8.model.entity];
|
|
21069
17930
|
console.debug("fetch page vuex ", page, _this8.collection);
|
|
21070
17931
|
_this8.loading = false;
|
|
21071
|
-
case
|
|
17932
|
+
case 9:
|
|
21072
17933
|
case "end":
|
|
21073
17934
|
return _context.stop();
|
|
21074
17935
|
}
|
|
@@ -22248,7 +19109,7 @@ var _sfc_render = function render() {
|
|
|
22248
19109
|
})], 2)], 1);
|
|
22249
19110
|
};
|
|
22250
19111
|
var _sfc_staticRenderFns = [];
|
|
22251
|
-
var __component__ = /*#__PURE__*/normalizeComponent(_sfc_main, _sfc_render, _sfc_staticRenderFns, false, null, "
|
|
19112
|
+
var __component__ = /*#__PURE__*/normalizeComponent(_sfc_main, _sfc_render, _sfc_staticRenderFns, false, null, "cc7b4474", null, null);
|
|
22252
19113
|
var component$1 = __component__.exports;// Import vue component
|
|
22253
19114
|
|
|
22254
19115
|
// Default export is installable instance of component.
|