UNPKG

115 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, '__esModule', { value: true });
4
5function createCommonjsModule(fn, module) {
6 return module = { exports: {} }, fn(module, module.exports), module.exports;
7}
8
9var _global = createCommonjsModule(function (module) {
10// https://github.com/zloirock/core-js/issues/86#issuecomment-115759028
11var global = module.exports = typeof window != 'undefined' && window.Math == Math
12 ? window : typeof self != 'undefined' && self.Math == Math ? self
13 // eslint-disable-next-line no-new-func
14 : Function('return this')();
15if (typeof __g == 'number') __g = global; // eslint-disable-line no-undef
16});
17
18var _core = createCommonjsModule(function (module) {
19var core = module.exports = { version: '2.5.7' };
20if (typeof __e == 'number') __e = core; // eslint-disable-line no-undef
21});
22var _core_1 = _core.version;
23
24var _isObject = function (it) {
25 return typeof it === 'object' ? it !== null : typeof it === 'function';
26};
27
28var _anObject = function (it) {
29 if (!_isObject(it)) throw TypeError(it + ' is not an object!');
30 return it;
31};
32
33var _fails = function (exec) {
34 try {
35 return !!exec();
36 } catch (e) {
37 return true;
38 }
39};
40
41// Thank's IE8 for his funny defineProperty
42var _descriptors = !_fails(function () {
43 return Object.defineProperty({}, 'a', { get: function () { return 7; } }).a != 7;
44});
45
46var document$1 = _global.document;
47// typeof document.createElement is 'object' in old IE
48var is = _isObject(document$1) && _isObject(document$1.createElement);
49var _domCreate = function (it) {
50 return is ? document$1.createElement(it) : {};
51};
52
53var _ie8DomDefine = !_descriptors && !_fails(function () {
54 return Object.defineProperty(_domCreate('div'), 'a', { get: function () { return 7; } }).a != 7;
55});
56
57// 7.1.1 ToPrimitive(input [, PreferredType])
58
59// instead of the ES6 spec version, we didn't implement @@toPrimitive case
60// and the second argument - flag - preferred type is a string
61var _toPrimitive = function (it, S) {
62 if (!_isObject(it)) return it;
63 var fn, val;
64 if (S && typeof (fn = it.toString) == 'function' && !_isObject(val = fn.call(it))) return val;
65 if (typeof (fn = it.valueOf) == 'function' && !_isObject(val = fn.call(it))) return val;
66 if (!S && typeof (fn = it.toString) == 'function' && !_isObject(val = fn.call(it))) return val;
67 throw TypeError("Can't convert object to primitive value");
68};
69
70var dP = Object.defineProperty;
71
72var f = _descriptors ? Object.defineProperty : function defineProperty(O, P, Attributes) {
73 _anObject(O);
74 P = _toPrimitive(P, true);
75 _anObject(Attributes);
76 if (_ie8DomDefine) try {
77 return dP(O, P, Attributes);
78 } catch (e) { /* empty */ }
79 if ('get' in Attributes || 'set' in Attributes) throw TypeError('Accessors not supported!');
80 if ('value' in Attributes) O[P] = Attributes.value;
81 return O;
82};
83
84var _objectDp = {
85 f: f
86};
87
88var _propertyDesc = function (bitmap, value) {
89 return {
90 enumerable: !(bitmap & 1),
91 configurable: !(bitmap & 2),
92 writable: !(bitmap & 4),
93 value: value
94 };
95};
96
97var _hide = _descriptors ? function (object, key, value) {
98 return _objectDp.f(object, key, _propertyDesc(1, value));
99} : function (object, key, value) {
100 object[key] = value;
101 return object;
102};
103
104var hasOwnProperty = {}.hasOwnProperty;
105var _has = function (it, key) {
106 return hasOwnProperty.call(it, key);
107};
108
109var id = 0;
110var px = Math.random();
111var _uid = function (key) {
112 return 'Symbol('.concat(key === undefined ? '' : key, ')_', (++id + px).toString(36));
113};
114
115var _redefine = createCommonjsModule(function (module) {
116var SRC = _uid('src');
117var TO_STRING = 'toString';
118var $toString = Function[TO_STRING];
119var TPL = ('' + $toString).split(TO_STRING);
120
121_core.inspectSource = function (it) {
122 return $toString.call(it);
123};
124
125(module.exports = function (O, key, val, safe) {
126 var isFunction = typeof val == 'function';
127 if (isFunction) _has(val, 'name') || _hide(val, 'name', key);
128 if (O[key] === val) return;
129 if (isFunction) _has(val, SRC) || _hide(val, SRC, O[key] ? '' + O[key] : TPL.join(String(key)));
130 if (O === _global) {
131 O[key] = val;
132 } else if (!safe) {
133 delete O[key];
134 _hide(O, key, val);
135 } else if (O[key]) {
136 O[key] = val;
137 } else {
138 _hide(O, key, val);
139 }
140// add fake Function#toString for correct work wrapped methods / constructors with methods like LoDash isNative
141})(Function.prototype, TO_STRING, function toString() {
142 return typeof this == 'function' && this[SRC] || $toString.call(this);
143});
144});
145
146var _aFunction = function (it) {
147 if (typeof it != 'function') throw TypeError(it + ' is not a function!');
148 return it;
149};
150
151// optional / simple context binding
152
153var _ctx = function (fn, that, length) {
154 _aFunction(fn);
155 if (that === undefined) return fn;
156 switch (length) {
157 case 1: return function (a) {
158 return fn.call(that, a);
159 };
160 case 2: return function (a, b) {
161 return fn.call(that, a, b);
162 };
163 case 3: return function (a, b, c) {
164 return fn.call(that, a, b, c);
165 };
166 }
167 return function (/* ...args */) {
168 return fn.apply(that, arguments);
169 };
170};
171
172var PROTOTYPE = 'prototype';
173
174var $export = function (type, name, source) {
175 var IS_FORCED = type & $export.F;
176 var IS_GLOBAL = type & $export.G;
177 var IS_STATIC = type & $export.S;
178 var IS_PROTO = type & $export.P;
179 var IS_BIND = type & $export.B;
180 var target = IS_GLOBAL ? _global : IS_STATIC ? _global[name] || (_global[name] = {}) : (_global[name] || {})[PROTOTYPE];
181 var exports = IS_GLOBAL ? _core : _core[name] || (_core[name] = {});
182 var expProto = exports[PROTOTYPE] || (exports[PROTOTYPE] = {});
183 var key, own, out, exp;
184 if (IS_GLOBAL) source = name;
185 for (key in source) {
186 // contains in native
187 own = !IS_FORCED && target && target[key] !== undefined;
188 // export native or passed
189 out = (own ? target : source)[key];
190 // bind timers to global for call from export context
191 exp = IS_BIND && own ? _ctx(out, _global) : IS_PROTO && typeof out == 'function' ? _ctx(Function.call, out) : out;
192 // extend global
193 if (target) _redefine(target, key, out, type & $export.U);
194 // export
195 if (exports[key] != out) _hide(exports, key, exp);
196 if (IS_PROTO && expProto[key] != out) expProto[key] = out;
197 }
198};
199_global.core = _core;
200// type bitmap
201$export.F = 1; // forced
202$export.G = 2; // global
203$export.S = 4; // static
204$export.P = 8; // proto
205$export.B = 16; // bind
206$export.W = 32; // wrap
207$export.U = 64; // safe
208$export.R = 128; // real proto method for `library`
209var _export = $export;
210
211var toString = {}.toString;
212
213var _cof = function (it) {
214 return toString.call(it).slice(8, -1);
215};
216
217// fallback for non-array-like ES3 and non-enumerable old V8 strings
218
219// eslint-disable-next-line no-prototype-builtins
220var _iobject = Object('z').propertyIsEnumerable(0) ? Object : function (it) {
221 return _cof(it) == 'String' ? it.split('') : Object(it);
222};
223
224// 7.2.1 RequireObjectCoercible(argument)
225var _defined = function (it) {
226 if (it == undefined) throw TypeError("Can't call method on " + it);
227 return it;
228};
229
230// to indexed object, toObject with fallback for non-array-like ES3 strings
231
232
233var _toIobject = function (it) {
234 return _iobject(_defined(it));
235};
236
237// 7.1.4 ToInteger
238var ceil = Math.ceil;
239var floor = Math.floor;
240var _toInteger = function (it) {
241 return isNaN(it = +it) ? 0 : (it > 0 ? floor : ceil)(it);
242};
243
244// 7.1.15 ToLength
245
246var min = Math.min;
247var _toLength = function (it) {
248 return it > 0 ? min(_toInteger(it), 0x1fffffffffffff) : 0; // pow(2, 53) - 1 == 9007199254740991
249};
250
251var max = Math.max;
252var min$1 = Math.min;
253var _toAbsoluteIndex = function (index, length) {
254 index = _toInteger(index);
255 return index < 0 ? max(index + length, 0) : min$1(index, length);
256};
257
258// false -> Array#indexOf
259// true -> Array#includes
260
261
262
263var _arrayIncludes = function (IS_INCLUDES) {
264 return function ($this, el, fromIndex) {
265 var O = _toIobject($this);
266 var length = _toLength(O.length);
267 var index = _toAbsoluteIndex(fromIndex, length);
268 var value;
269 // Array#includes uses SameValueZero equality algorithm
270 // eslint-disable-next-line no-self-compare
271 if (IS_INCLUDES && el != el) while (length > index) {
272 value = O[index++];
273 // eslint-disable-next-line no-self-compare
274 if (value != value) return true;
275 // Array#indexOf ignores holes, Array#includes - not
276 } else for (;length > index; index++) if (IS_INCLUDES || index in O) {
277 if (O[index] === el) return IS_INCLUDES || index || 0;
278 } return !IS_INCLUDES && -1;
279 };
280};
281
282var _library = false;
283
284var _shared = createCommonjsModule(function (module) {
285var SHARED = '__core-js_shared__';
286var store = _global[SHARED] || (_global[SHARED] = {});
287
288(module.exports = function (key, value) {
289 return store[key] || (store[key] = value !== undefined ? value : {});
290})('versions', []).push({
291 version: _core.version,
292 mode: 'global',
293 copyright: '© 2018 Denis Pushkarev (zloirock.ru)'
294});
295});
296
297var shared = _shared('keys');
298
299var _sharedKey = function (key) {
300 return shared[key] || (shared[key] = _uid(key));
301};
302
303var arrayIndexOf = _arrayIncludes(false);
304var IE_PROTO = _sharedKey('IE_PROTO');
305
306var _objectKeysInternal = function (object, names) {
307 var O = _toIobject(object);
308 var i = 0;
309 var result = [];
310 var key;
311 for (key in O) if (key != IE_PROTO) _has(O, key) && result.push(key);
312 // Don't enum bug & hidden keys
313 while (names.length > i) if (_has(O, key = names[i++])) {
314 ~arrayIndexOf(result, key) || result.push(key);
315 }
316 return result;
317};
318
319// IE 8- don't enum bug keys
320var _enumBugKeys = (
321 'constructor,hasOwnProperty,isPrototypeOf,propertyIsEnumerable,toLocaleString,toString,valueOf'
322).split(',');
323
324// 19.1.2.14 / 15.2.3.14 Object.keys(O)
325
326
327
328var _objectKeys = Object.keys || function keys(O) {
329 return _objectKeysInternal(O, _enumBugKeys);
330};
331
332var f$1 = Object.getOwnPropertySymbols;
333
334var _objectGops = {
335 f: f$1
336};
337
338var f$2 = {}.propertyIsEnumerable;
339
340var _objectPie = {
341 f: f$2
342};
343
344// 7.1.13 ToObject(argument)
345
346var _toObject = function (it) {
347 return Object(_defined(it));
348};
349
350// 19.1.2.1 Object.assign(target, source, ...)
351
352
353
354
355
356var $assign = Object.assign;
357
358// should work with symbols and should have deterministic property order (V8 bug)
359var _objectAssign = !$assign || _fails(function () {
360 var A = {};
361 var B = {};
362 // eslint-disable-next-line no-undef
363 var S = Symbol();
364 var K = 'abcdefghijklmnopqrst';
365 A[S] = 7;
366 K.split('').forEach(function (k) { B[k] = k; });
367 return $assign({}, A)[S] != 7 || Object.keys($assign({}, B)).join('') != K;
368}) ? function assign(target, source) { // eslint-disable-line no-unused-vars
369 var T = _toObject(target);
370 var aLen = arguments.length;
371 var index = 1;
372 var getSymbols = _objectGops.f;
373 var isEnum = _objectPie.f;
374 while (aLen > index) {
375 var S = _iobject(arguments[index++]);
376 var keys = getSymbols ? _objectKeys(S).concat(getSymbols(S)) : _objectKeys(S);
377 var length = keys.length;
378 var j = 0;
379 var key;
380 while (length > j) if (isEnum.call(S, key = keys[j++])) T[key] = S[key];
381 } return T;
382} : $assign;
383
384// 19.1.3.1 Object.assign(target, source)
385
386
387_export(_export.S + _export.F, 'Object', { assign: _objectAssign });
388
389function _typeof(obj) {
390 if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
391 _typeof = function (obj) {
392 return typeof obj;
393 };
394 } else {
395 _typeof = function (obj) {
396 return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
397 };
398 }
399
400 return _typeof(obj);
401}
402
403function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
404 try {
405 var info = gen[key](arg);
406 var value = info.value;
407 } catch (error) {
408 reject(error);
409 return;
410 }
411
412 if (info.done) {
413 resolve(value);
414 } else {
415 Promise.resolve(value).then(_next, _throw);
416 }
417}
418
419function _asyncToGenerator(fn) {
420 return function () {
421 var self = this,
422 args = arguments;
423 return new Promise(function (resolve, reject) {
424 var gen = fn.apply(self, args);
425
426 function _next(value) {
427 asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
428 }
429
430 function _throw(err) {
431 asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
432 }
433
434 _next(undefined);
435 });
436 };
437}
438
439function _classCallCheck(instance, Constructor) {
440 if (!(instance instanceof Constructor)) {
441 throw new TypeError("Cannot call a class as a function");
442 }
443}
444
445function _defineProperties(target, props) {
446 for (var i = 0; i < props.length; i++) {
447 var descriptor = props[i];
448 descriptor.enumerable = descriptor.enumerable || false;
449 descriptor.configurable = true;
450 if ("value" in descriptor) descriptor.writable = true;
451 Object.defineProperty(target, descriptor.key, descriptor);
452 }
453}
454
455function _createClass(Constructor, protoProps, staticProps) {
456 if (protoProps) _defineProperties(Constructor.prototype, protoProps);
457 if (staticProps) _defineProperties(Constructor, staticProps);
458 return Constructor;
459}
460
461function _defineProperty(obj, key, value) {
462 if (key in obj) {
463 Object.defineProperty(obj, key, {
464 value: value,
465 enumerable: true,
466 configurable: true,
467 writable: true
468 });
469 } else {
470 obj[key] = value;
471 }
472
473 return obj;
474}
475
476function _toConsumableArray(arr) {
477 return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread();
478}
479
480function _arrayWithoutHoles(arr) {
481 if (Array.isArray(arr)) {
482 for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];
483
484 return arr2;
485 }
486}
487
488function _iterableToArray(iter) {
489 if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter);
490}
491
492function _nonIterableSpread() {
493 throw new TypeError("Invalid attempt to spread non-iterable instance");
494}
495
496/**
497 * @class Model
498 * @namespace Daux.Core
499 */
500var Model =
501/*#__PURE__*/
502function () {
503 function Model() {
504 _classCallCheck(this, Model);
505 }
506
507 _createClass(Model, null, [{
508 key: "deserialize",
509
510 /**
511 * @param {Object} record
512 * @return {Object} Deserialized record
513 * @function
514 */
515 value: function deserialize(record) {
516 return Object.assign({}, record);
517 }
518 }, {
519 key: "attributes",
520
521 /**
522 * @type {Array}
523 */
524 get: function get() {
525 return [];
526 }
527 /**
528 * @type {Object}
529 */
530
531 }, {
532 key: "relationship",
533 get: function get() {
534 return {};
535 }
536 }]);
537
538 return Model;
539}();
540
541var _wks = createCommonjsModule(function (module) {
542var store = _shared('wks');
543
544var Symbol = _global.Symbol;
545var USE_SYMBOL = typeof Symbol == 'function';
546
547var $exports = module.exports = function (name) {
548 return store[name] || (store[name] =
549 USE_SYMBOL && Symbol[name] || (USE_SYMBOL ? Symbol : _uid)('Symbol.' + name));
550};
551
552$exports.store = store;
553});
554
555// 22.1.3.31 Array.prototype[@@unscopables]
556var UNSCOPABLES = _wks('unscopables');
557var ArrayProto = Array.prototype;
558if (ArrayProto[UNSCOPABLES] == undefined) _hide(ArrayProto, UNSCOPABLES, {});
559var _addToUnscopables = function (key) {
560 ArrayProto[UNSCOPABLES][key] = true;
561};
562
563// https://github.com/tc39/Array.prototype.includes
564
565var $includes = _arrayIncludes(true);
566
567_export(_export.P, 'Array', {
568 includes: function includes(el /* , fromIndex = 0 */) {
569 return $includes(this, el, arguments.length > 1 ? arguments[1] : undefined);
570 }
571});
572
573_addToUnscopables('includes');
574
575// 7.2.8 IsRegExp(argument)
576
577
578var MATCH = _wks('match');
579var _isRegexp = function (it) {
580 var isRegExp;
581 return _isObject(it) && ((isRegExp = it[MATCH]) !== undefined ? !!isRegExp : _cof(it) == 'RegExp');
582};
583
584// helper for String#{startsWith, endsWith, includes}
585
586
587
588var _stringContext = function (that, searchString, NAME) {
589 if (_isRegexp(searchString)) throw TypeError('String#' + NAME + " doesn't accept regex!");
590 return String(_defined(that));
591};
592
593var MATCH$1 = _wks('match');
594var _failsIsRegexp = function (KEY) {
595 var re = /./;
596 try {
597 '/./'[KEY](re);
598 } catch (e) {
599 try {
600 re[MATCH$1] = false;
601 return !'/./'[KEY](re);
602 } catch (f) { /* empty */ }
603 } return true;
604};
605
606var INCLUDES = 'includes';
607
608_export(_export.P + _export.F * _failsIsRegexp(INCLUDES), 'String', {
609 includes: function includes(searchString /* , position = 0 */) {
610 return !!~_stringContext(this, searchString, INCLUDES)
611 .indexOf(searchString, arguments.length > 1 ? arguments[1] : undefined);
612 }
613});
614
615var _objectDps = _descriptors ? Object.defineProperties : function defineProperties(O, Properties) {
616 _anObject(O);
617 var keys = _objectKeys(Properties);
618 var length = keys.length;
619 var i = 0;
620 var P;
621 while (length > i) _objectDp.f(O, P = keys[i++], Properties[P]);
622 return O;
623};
624
625var document$2 = _global.document;
626var _html = document$2 && document$2.documentElement;
627
628// 19.1.2.2 / 15.2.3.5 Object.create(O [, Properties])
629
630
631
632var IE_PROTO$1 = _sharedKey('IE_PROTO');
633var Empty = function () { /* empty */ };
634var PROTOTYPE$1 = 'prototype';
635
636// Create object with fake `null` prototype: use iframe Object with cleared prototype
637var createDict = function () {
638 // Thrash, waste and sodomy: IE GC bug
639 var iframe = _domCreate('iframe');
640 var i = _enumBugKeys.length;
641 var lt = '<';
642 var gt = '>';
643 var iframeDocument;
644 iframe.style.display = 'none';
645 _html.appendChild(iframe);
646 iframe.src = 'javascript:'; // eslint-disable-line no-script-url
647 // createDict = iframe.contentWindow.Object;
648 // html.removeChild(iframe);
649 iframeDocument = iframe.contentWindow.document;
650 iframeDocument.open();
651 iframeDocument.write(lt + 'script' + gt + 'document.F=Object' + lt + '/script' + gt);
652 iframeDocument.close();
653 createDict = iframeDocument.F;
654 while (i--) delete createDict[PROTOTYPE$1][_enumBugKeys[i]];
655 return createDict();
656};
657
658var _objectCreate = Object.create || function create(O, Properties) {
659 var result;
660 if (O !== null) {
661 Empty[PROTOTYPE$1] = _anObject(O);
662 result = new Empty();
663 Empty[PROTOTYPE$1] = null;
664 // add "__proto__" for Object.getPrototypeOf polyfill
665 result[IE_PROTO$1] = O;
666 } else result = createDict();
667 return Properties === undefined ? result : _objectDps(result, Properties);
668};
669
670var _redefineAll = function (target, src, safe) {
671 for (var key in src) _redefine(target, key, src[key], safe);
672 return target;
673};
674
675var _anInstance = function (it, Constructor, name, forbiddenField) {
676 if (!(it instanceof Constructor) || (forbiddenField !== undefined && forbiddenField in it)) {
677 throw TypeError(name + ': incorrect invocation!');
678 } return it;
679};
680
681// call something on iterator step with safe closing on error
682
683var _iterCall = function (iterator, fn, value, entries) {
684 try {
685 return entries ? fn(_anObject(value)[0], value[1]) : fn(value);
686 // 7.4.6 IteratorClose(iterator, completion)
687 } catch (e) {
688 var ret = iterator['return'];
689 if (ret !== undefined) _anObject(ret.call(iterator));
690 throw e;
691 }
692};
693
694var _iterators = {};
695
696// check on default Array iterator
697
698var ITERATOR = _wks('iterator');
699var ArrayProto$1 = Array.prototype;
700
701var _isArrayIter = function (it) {
702 return it !== undefined && (_iterators.Array === it || ArrayProto$1[ITERATOR] === it);
703};
704
705// getting tag from 19.1.3.6 Object.prototype.toString()
706
707var TAG = _wks('toStringTag');
708// ES3 wrong here
709var ARG = _cof(function () { return arguments; }()) == 'Arguments';
710
711// fallback for IE11 Script Access Denied error
712var tryGet = function (it, key) {
713 try {
714 return it[key];
715 } catch (e) { /* empty */ }
716};
717
718var _classof = function (it) {
719 var O, T, B;
720 return it === undefined ? 'Undefined' : it === null ? 'Null'
721 // @@toStringTag case
722 : typeof (T = tryGet(O = Object(it), TAG)) == 'string' ? T
723 // builtinTag case
724 : ARG ? _cof(O)
725 // ES3 arguments fallback
726 : (B = _cof(O)) == 'Object' && typeof O.callee == 'function' ? 'Arguments' : B;
727};
728
729var ITERATOR$1 = _wks('iterator');
730
731var core_getIteratorMethod = _core.getIteratorMethod = function (it) {
732 if (it != undefined) return it[ITERATOR$1]
733 || it['@@iterator']
734 || _iterators[_classof(it)];
735};
736
737var _forOf = createCommonjsModule(function (module) {
738var BREAK = {};
739var RETURN = {};
740var exports = module.exports = function (iterable, entries, fn, that, ITERATOR) {
741 var iterFn = ITERATOR ? function () { return iterable; } : core_getIteratorMethod(iterable);
742 var f = _ctx(fn, that, entries ? 2 : 1);
743 var index = 0;
744 var length, step, iterator, result;
745 if (typeof iterFn != 'function') throw TypeError(iterable + ' is not iterable!');
746 // fast case for arrays with default iterator
747 if (_isArrayIter(iterFn)) for (length = _toLength(iterable.length); length > index; index++) {
748 result = entries ? f(_anObject(step = iterable[index])[0], step[1]) : f(iterable[index]);
749 if (result === BREAK || result === RETURN) return result;
750 } else for (iterator = iterFn.call(iterable); !(step = iterator.next()).done;) {
751 result = _iterCall(iterator, f, step.value, entries);
752 if (result === BREAK || result === RETURN) return result;
753 }
754};
755exports.BREAK = BREAK;
756exports.RETURN = RETURN;
757});
758
759var def = _objectDp.f;
760
761var TAG$1 = _wks('toStringTag');
762
763var _setToStringTag = function (it, tag, stat) {
764 if (it && !_has(it = stat ? it : it.prototype, TAG$1)) def(it, TAG$1, { configurable: true, value: tag });
765};
766
767var IteratorPrototype = {};
768
769// 25.1.2.1.1 %IteratorPrototype%[@@iterator]()
770_hide(IteratorPrototype, _wks('iterator'), function () { return this; });
771
772var _iterCreate = function (Constructor, NAME, next) {
773 Constructor.prototype = _objectCreate(IteratorPrototype, { next: _propertyDesc(1, next) });
774 _setToStringTag(Constructor, NAME + ' Iterator');
775};
776
777// 19.1.2.9 / 15.2.3.2 Object.getPrototypeOf(O)
778
779
780var IE_PROTO$2 = _sharedKey('IE_PROTO');
781var ObjectProto = Object.prototype;
782
783var _objectGpo = Object.getPrototypeOf || function (O) {
784 O = _toObject(O);
785 if (_has(O, IE_PROTO$2)) return O[IE_PROTO$2];
786 if (typeof O.constructor == 'function' && O instanceof O.constructor) {
787 return O.constructor.prototype;
788 } return O instanceof Object ? ObjectProto : null;
789};
790
791var ITERATOR$2 = _wks('iterator');
792var BUGGY = !([].keys && 'next' in [].keys()); // Safari has buggy iterators w/o `next`
793var FF_ITERATOR = '@@iterator';
794var KEYS = 'keys';
795var VALUES = 'values';
796
797var returnThis = function () { return this; };
798
799var _iterDefine = function (Base, NAME, Constructor, next, DEFAULT, IS_SET, FORCED) {
800 _iterCreate(Constructor, NAME, next);
801 var getMethod = function (kind) {
802 if (!BUGGY && kind in proto) return proto[kind];
803 switch (kind) {
804 case KEYS: return function keys() { return new Constructor(this, kind); };
805 case VALUES: return function values() { return new Constructor(this, kind); };
806 } return function entries() { return new Constructor(this, kind); };
807 };
808 var TAG = NAME + ' Iterator';
809 var DEF_VALUES = DEFAULT == VALUES;
810 var VALUES_BUG = false;
811 var proto = Base.prototype;
812 var $native = proto[ITERATOR$2] || proto[FF_ITERATOR] || DEFAULT && proto[DEFAULT];
813 var $default = $native || getMethod(DEFAULT);
814 var $entries = DEFAULT ? !DEF_VALUES ? $default : getMethod('entries') : undefined;
815 var $anyNative = NAME == 'Array' ? proto.entries || $native : $native;
816 var methods, key, IteratorPrototype;
817 // Fix native
818 if ($anyNative) {
819 IteratorPrototype = _objectGpo($anyNative.call(new Base()));
820 if (IteratorPrototype !== Object.prototype && IteratorPrototype.next) {
821 // Set @@toStringTag to native iterators
822 _setToStringTag(IteratorPrototype, TAG, true);
823 // fix for some old engines
824 if (!_library && typeof IteratorPrototype[ITERATOR$2] != 'function') _hide(IteratorPrototype, ITERATOR$2, returnThis);
825 }
826 }
827 // fix Array#{values, @@iterator}.name in V8 / FF
828 if (DEF_VALUES && $native && $native.name !== VALUES) {
829 VALUES_BUG = true;
830 $default = function values() { return $native.call(this); };
831 }
832 // Define iterator
833 if ((!_library || FORCED) && (BUGGY || VALUES_BUG || !proto[ITERATOR$2])) {
834 _hide(proto, ITERATOR$2, $default);
835 }
836 // Plug for library
837 _iterators[NAME] = $default;
838 _iterators[TAG] = returnThis;
839 if (DEFAULT) {
840 methods = {
841 values: DEF_VALUES ? $default : getMethod(VALUES),
842 keys: IS_SET ? $default : getMethod(KEYS),
843 entries: $entries
844 };
845 if (FORCED) for (key in methods) {
846 if (!(key in proto)) _redefine(proto, key, methods[key]);
847 } else _export(_export.P + _export.F * (BUGGY || VALUES_BUG), NAME, methods);
848 }
849 return methods;
850};
851
852var _iterStep = function (done, value) {
853 return { value: value, done: !!done };
854};
855
856var SPECIES = _wks('species');
857
858var _setSpecies = function (KEY) {
859 var C = _global[KEY];
860 if (_descriptors && C && !C[SPECIES]) _objectDp.f(C, SPECIES, {
861 configurable: true,
862 get: function () { return this; }
863 });
864};
865
866var _meta = createCommonjsModule(function (module) {
867var META = _uid('meta');
868
869
870var setDesc = _objectDp.f;
871var id = 0;
872var isExtensible = Object.isExtensible || function () {
873 return true;
874};
875var FREEZE = !_fails(function () {
876 return isExtensible(Object.preventExtensions({}));
877});
878var setMeta = function (it) {
879 setDesc(it, META, { value: {
880 i: 'O' + ++id, // object ID
881 w: {} // weak collections IDs
882 } });
883};
884var fastKey = function (it, create) {
885 // return primitive with prefix
886 if (!_isObject(it)) return typeof it == 'symbol' ? it : (typeof it == 'string' ? 'S' : 'P') + it;
887 if (!_has(it, META)) {
888 // can't set metadata to uncaught frozen object
889 if (!isExtensible(it)) return 'F';
890 // not necessary to add metadata
891 if (!create) return 'E';
892 // add missing metadata
893 setMeta(it);
894 // return object ID
895 } return it[META].i;
896};
897var getWeak = function (it, create) {
898 if (!_has(it, META)) {
899 // can't set metadata to uncaught frozen object
900 if (!isExtensible(it)) return true;
901 // not necessary to add metadata
902 if (!create) return false;
903 // add missing metadata
904 setMeta(it);
905 // return hash weak collections IDs
906 } return it[META].w;
907};
908// add metadata on freeze-family methods calling
909var onFreeze = function (it) {
910 if (FREEZE && meta.NEED && isExtensible(it) && !_has(it, META)) setMeta(it);
911 return it;
912};
913var meta = module.exports = {
914 KEY: META,
915 NEED: false,
916 fastKey: fastKey,
917 getWeak: getWeak,
918 onFreeze: onFreeze
919};
920});
921var _meta_1 = _meta.KEY;
922var _meta_2 = _meta.NEED;
923var _meta_3 = _meta.fastKey;
924var _meta_4 = _meta.getWeak;
925var _meta_5 = _meta.onFreeze;
926
927var _validateCollection = function (it, TYPE) {
928 if (!_isObject(it) || it._t !== TYPE) throw TypeError('Incompatible receiver, ' + TYPE + ' required!');
929 return it;
930};
931
932var dP$1 = _objectDp.f;
933
934
935
936
937
938
939
940
941
942var fastKey = _meta.fastKey;
943
944var SIZE = _descriptors ? '_s' : 'size';
945
946var getEntry = function (that, key) {
947 // fast case
948 var index = fastKey(key);
949 var entry;
950 if (index !== 'F') return that._i[index];
951 // frozen object case
952 for (entry = that._f; entry; entry = entry.n) {
953 if (entry.k == key) return entry;
954 }
955};
956
957var _collectionStrong = {
958 getConstructor: function (wrapper, NAME, IS_MAP, ADDER) {
959 var C = wrapper(function (that, iterable) {
960 _anInstance(that, C, NAME, '_i');
961 that._t = NAME; // collection type
962 that._i = _objectCreate(null); // index
963 that._f = undefined; // first entry
964 that._l = undefined; // last entry
965 that[SIZE] = 0; // size
966 if (iterable != undefined) _forOf(iterable, IS_MAP, that[ADDER], that);
967 });
968 _redefineAll(C.prototype, {
969 // 23.1.3.1 Map.prototype.clear()
970 // 23.2.3.2 Set.prototype.clear()
971 clear: function clear() {
972 for (var that = _validateCollection(this, NAME), data = that._i, entry = that._f; entry; entry = entry.n) {
973 entry.r = true;
974 if (entry.p) entry.p = entry.p.n = undefined;
975 delete data[entry.i];
976 }
977 that._f = that._l = undefined;
978 that[SIZE] = 0;
979 },
980 // 23.1.3.3 Map.prototype.delete(key)
981 // 23.2.3.4 Set.prototype.delete(value)
982 'delete': function (key) {
983 var that = _validateCollection(this, NAME);
984 var entry = getEntry(that, key);
985 if (entry) {
986 var next = entry.n;
987 var prev = entry.p;
988 delete that._i[entry.i];
989 entry.r = true;
990 if (prev) prev.n = next;
991 if (next) next.p = prev;
992 if (that._f == entry) that._f = next;
993 if (that._l == entry) that._l = prev;
994 that[SIZE]--;
995 } return !!entry;
996 },
997 // 23.2.3.6 Set.prototype.forEach(callbackfn, thisArg = undefined)
998 // 23.1.3.5 Map.prototype.forEach(callbackfn, thisArg = undefined)
999 forEach: function forEach(callbackfn /* , that = undefined */) {
1000 _validateCollection(this, NAME);
1001 var f = _ctx(callbackfn, arguments.length > 1 ? arguments[1] : undefined, 3);
1002 var entry;
1003 while (entry = entry ? entry.n : this._f) {
1004 f(entry.v, entry.k, this);
1005 // revert to the last existing entry
1006 while (entry && entry.r) entry = entry.p;
1007 }
1008 },
1009 // 23.1.3.7 Map.prototype.has(key)
1010 // 23.2.3.7 Set.prototype.has(value)
1011 has: function has(key) {
1012 return !!getEntry(_validateCollection(this, NAME), key);
1013 }
1014 });
1015 if (_descriptors) dP$1(C.prototype, 'size', {
1016 get: function () {
1017 return _validateCollection(this, NAME)[SIZE];
1018 }
1019 });
1020 return C;
1021 },
1022 def: function (that, key, value) {
1023 var entry = getEntry(that, key);
1024 var prev, index;
1025 // change existing entry
1026 if (entry) {
1027 entry.v = value;
1028 // create new entry
1029 } else {
1030 that._l = entry = {
1031 i: index = fastKey(key, true), // <- index
1032 k: key, // <- key
1033 v: value, // <- value
1034 p: prev = that._l, // <- previous entry
1035 n: undefined, // <- next entry
1036 r: false // <- removed
1037 };
1038 if (!that._f) that._f = entry;
1039 if (prev) prev.n = entry;
1040 that[SIZE]++;
1041 // add to index
1042 if (index !== 'F') that._i[index] = entry;
1043 } return that;
1044 },
1045 getEntry: getEntry,
1046 setStrong: function (C, NAME, IS_MAP) {
1047 // add .keys, .values, .entries, [@@iterator]
1048 // 23.1.3.4, 23.1.3.8, 23.1.3.11, 23.1.3.12, 23.2.3.5, 23.2.3.8, 23.2.3.10, 23.2.3.11
1049 _iterDefine(C, NAME, function (iterated, kind) {
1050 this._t = _validateCollection(iterated, NAME); // target
1051 this._k = kind; // kind
1052 this._l = undefined; // previous
1053 }, function () {
1054 var that = this;
1055 var kind = that._k;
1056 var entry = that._l;
1057 // revert to the last existing entry
1058 while (entry && entry.r) entry = entry.p;
1059 // get next entry
1060 if (!that._t || !(that._l = entry = entry ? entry.n : that._t._f)) {
1061 // or finish the iteration
1062 that._t = undefined;
1063 return _iterStep(1);
1064 }
1065 // return step by kind
1066 if (kind == 'keys') return _iterStep(0, entry.k);
1067 if (kind == 'values') return _iterStep(0, entry.v);
1068 return _iterStep(0, [entry.k, entry.v]);
1069 }, IS_MAP ? 'entries' : 'values', !IS_MAP, true);
1070
1071 // add [@@species], 23.1.2.2, 23.2.2.2
1072 _setSpecies(NAME);
1073 }
1074};
1075
1076var ITERATOR$3 = _wks('iterator');
1077var SAFE_CLOSING = false;
1078
1079try {
1080 var riter = [7][ITERATOR$3]();
1081 riter['return'] = function () { SAFE_CLOSING = true; };
1082} catch (e) { /* empty */ }
1083
1084var _iterDetect = function (exec, skipClosing) {
1085 if (!skipClosing && !SAFE_CLOSING) return false;
1086 var safe = false;
1087 try {
1088 var arr = [7];
1089 var iter = arr[ITERATOR$3]();
1090 iter.next = function () { return { done: safe = true }; };
1091 arr[ITERATOR$3] = function () { return iter; };
1092 exec(arr);
1093 } catch (e) { /* empty */ }
1094 return safe;
1095};
1096
1097var gOPD = Object.getOwnPropertyDescriptor;
1098
1099var f$3 = _descriptors ? gOPD : function getOwnPropertyDescriptor(O, P) {
1100 O = _toIobject(O);
1101 P = _toPrimitive(P, true);
1102 if (_ie8DomDefine) try {
1103 return gOPD(O, P);
1104 } catch (e) { /* empty */ }
1105 if (_has(O, P)) return _propertyDesc(!_objectPie.f.call(O, P), O[P]);
1106};
1107
1108var _objectGopd = {
1109 f: f$3
1110};
1111
1112// Works with __proto__ only. Old v8 can't work with null proto objects.
1113/* eslint-disable no-proto */
1114
1115
1116var check = function (O, proto) {
1117 _anObject(O);
1118 if (!_isObject(proto) && proto !== null) throw TypeError(proto + ": can't set as prototype!");
1119};
1120var _setProto = {
1121 set: Object.setPrototypeOf || ('__proto__' in {} ? // eslint-disable-line
1122 function (test, buggy, set) {
1123 try {
1124 set = _ctx(Function.call, _objectGopd.f(Object.prototype, '__proto__').set, 2);
1125 set(test, []);
1126 buggy = !(test instanceof Array);
1127 } catch (e) { buggy = true; }
1128 return function setPrototypeOf(O, proto) {
1129 check(O, proto);
1130 if (buggy) O.__proto__ = proto;
1131 else set(O, proto);
1132 return O;
1133 };
1134 }({}, false) : undefined),
1135 check: check
1136};
1137
1138var setPrototypeOf = _setProto.set;
1139var _inheritIfRequired = function (that, target, C) {
1140 var S = target.constructor;
1141 var P;
1142 if (S !== C && typeof S == 'function' && (P = S.prototype) !== C.prototype && _isObject(P) && setPrototypeOf) {
1143 setPrototypeOf(that, P);
1144 } return that;
1145};
1146
1147var _collection = function (NAME, wrapper, methods, common, IS_MAP, IS_WEAK) {
1148 var Base = _global[NAME];
1149 var C = Base;
1150 var ADDER = IS_MAP ? 'set' : 'add';
1151 var proto = C && C.prototype;
1152 var O = {};
1153 var fixMethod = function (KEY) {
1154 var fn = proto[KEY];
1155 _redefine(proto, KEY,
1156 KEY == 'delete' ? function (a) {
1157 return IS_WEAK && !_isObject(a) ? false : fn.call(this, a === 0 ? 0 : a);
1158 } : KEY == 'has' ? function has(a) {
1159 return IS_WEAK && !_isObject(a) ? false : fn.call(this, a === 0 ? 0 : a);
1160 } : KEY == 'get' ? function get(a) {
1161 return IS_WEAK && !_isObject(a) ? undefined : fn.call(this, a === 0 ? 0 : a);
1162 } : KEY == 'add' ? function add(a) { fn.call(this, a === 0 ? 0 : a); return this; }
1163 : function set(a, b) { fn.call(this, a === 0 ? 0 : a, b); return this; }
1164 );
1165 };
1166 if (typeof C != 'function' || !(IS_WEAK || proto.forEach && !_fails(function () {
1167 new C().entries().next();
1168 }))) {
1169 // create collection constructor
1170 C = common.getConstructor(wrapper, NAME, IS_MAP, ADDER);
1171 _redefineAll(C.prototype, methods);
1172 _meta.NEED = true;
1173 } else {
1174 var instance = new C();
1175 // early implementations not supports chaining
1176 var HASNT_CHAINING = instance[ADDER](IS_WEAK ? {} : -0, 1) != instance;
1177 // V8 ~ Chromium 40- weak-collections throws on primitives, but should return false
1178 var THROWS_ON_PRIMITIVES = _fails(function () { instance.has(1); });
1179 // most early implementations doesn't supports iterables, most modern - not close it correctly
1180 var ACCEPT_ITERABLES = _iterDetect(function (iter) { new C(iter); }); // eslint-disable-line no-new
1181 // for early implementations -0 and +0 not the same
1182 var BUGGY_ZERO = !IS_WEAK && _fails(function () {
1183 // V8 ~ Chromium 42- fails only with 5+ elements
1184 var $instance = new C();
1185 var index = 5;
1186 while (index--) $instance[ADDER](index, index);
1187 return !$instance.has(-0);
1188 });
1189 if (!ACCEPT_ITERABLES) {
1190 C = wrapper(function (target, iterable) {
1191 _anInstance(target, C, NAME);
1192 var that = _inheritIfRequired(new Base(), target, C);
1193 if (iterable != undefined) _forOf(iterable, IS_MAP, that[ADDER], that);
1194 return that;
1195 });
1196 C.prototype = proto;
1197 proto.constructor = C;
1198 }
1199 if (THROWS_ON_PRIMITIVES || BUGGY_ZERO) {
1200 fixMethod('delete');
1201 fixMethod('has');
1202 IS_MAP && fixMethod('get');
1203 }
1204 if (BUGGY_ZERO || HASNT_CHAINING) fixMethod(ADDER);
1205 // weak collections should not contains .clear method
1206 if (IS_WEAK && proto.clear) delete proto.clear;
1207 }
1208
1209 _setToStringTag(C, NAME);
1210
1211 O[NAME] = C;
1212 _export(_export.G + _export.W + _export.F * (C != Base), O);
1213
1214 if (!IS_WEAK) common.setStrong(C, NAME, IS_MAP);
1215
1216 return C;
1217};
1218
1219var SET = 'Set';
1220
1221// 23.2 Set Objects
1222var es6_set = _collection(SET, function (get) {
1223 return function Set() { return get(this, arguments.length > 0 ? arguments[0] : undefined); };
1224}, {
1225 // 23.2.3.1 Set.prototype.add(value)
1226 add: function add(value) {
1227 return _collectionStrong.def(_validateCollection(this, SET), value = value === 0 ? 0 : value, value);
1228 }
1229}, _collectionStrong);
1230
1231// 7.2.2 IsArray(argument)
1232
1233var _isArray = Array.isArray || function isArray(arg) {
1234 return _cof(arg) == 'Array';
1235};
1236
1237var SPECIES$1 = _wks('species');
1238
1239var _arraySpeciesConstructor = function (original) {
1240 var C;
1241 if (_isArray(original)) {
1242 C = original.constructor;
1243 // cross-realm fallback
1244 if (typeof C == 'function' && (C === Array || _isArray(C.prototype))) C = undefined;
1245 if (_isObject(C)) {
1246 C = C[SPECIES$1];
1247 if (C === null) C = undefined;
1248 }
1249 } return C === undefined ? Array : C;
1250};
1251
1252// 9.4.2.3 ArraySpeciesCreate(originalArray, length)
1253
1254
1255var _arraySpeciesCreate = function (original, length) {
1256 return new (_arraySpeciesConstructor(original))(length);
1257};
1258
1259// 0 -> Array#forEach
1260// 1 -> Array#map
1261// 2 -> Array#filter
1262// 3 -> Array#some
1263// 4 -> Array#every
1264// 5 -> Array#find
1265// 6 -> Array#findIndex
1266
1267
1268
1269
1270
1271var _arrayMethods = function (TYPE, $create) {
1272 var IS_MAP = TYPE == 1;
1273 var IS_FILTER = TYPE == 2;
1274 var IS_SOME = TYPE == 3;
1275 var IS_EVERY = TYPE == 4;
1276 var IS_FIND_INDEX = TYPE == 6;
1277 var NO_HOLES = TYPE == 5 || IS_FIND_INDEX;
1278 var create = $create || _arraySpeciesCreate;
1279 return function ($this, callbackfn, that) {
1280 var O = _toObject($this);
1281 var self = _iobject(O);
1282 var f = _ctx(callbackfn, that, 3);
1283 var length = _toLength(self.length);
1284 var index = 0;
1285 var result = IS_MAP ? create($this, length) : IS_FILTER ? create($this, 0) : undefined;
1286 var val, res;
1287 for (;length > index; index++) if (NO_HOLES || index in self) {
1288 val = self[index];
1289 res = f(val, index, O);
1290 if (TYPE) {
1291 if (IS_MAP) result[index] = res; // map
1292 else if (res) switch (TYPE) {
1293 case 3: return true; // some
1294 case 5: return val; // find
1295 case 6: return index; // findIndex
1296 case 2: result.push(val); // filter
1297 } else if (IS_EVERY) return false; // every
1298 }
1299 }
1300 return IS_FIND_INDEX ? -1 : IS_SOME || IS_EVERY ? IS_EVERY : result;
1301 };
1302};
1303
1304// 22.1.3.8 Array.prototype.find(predicate, thisArg = undefined)
1305
1306var $find = _arrayMethods(5);
1307var KEY = 'find';
1308var forced = true;
1309// Shouldn't skip holes
1310if (KEY in []) Array(1)[KEY](function () { forced = false; });
1311_export(_export.P + _export.F * forced, 'Array', {
1312 find: function find(callbackfn /* , that = undefined */) {
1313 return $find(this, callbackfn, arguments.length > 1 ? arguments[1] : undefined);
1314 }
1315});
1316_addToUnscopables(KEY);
1317
1318// 21.2.5.3 get RegExp.prototype.flags
1319
1320var _flags = function () {
1321 var that = _anObject(this);
1322 var result = '';
1323 if (that.global) result += 'g';
1324 if (that.ignoreCase) result += 'i';
1325 if (that.multiline) result += 'm';
1326 if (that.unicode) result += 'u';
1327 if (that.sticky) result += 'y';
1328 return result;
1329};
1330
1331// 21.2.5.3 get RegExp.prototype.flags()
1332if (_descriptors && /./g.flags != 'g') _objectDp.f(RegExp.prototype, 'flags', {
1333 configurable: true,
1334 get: _flags
1335});
1336
1337var TO_STRING = 'toString';
1338var $toString = /./[TO_STRING];
1339
1340var define = function (fn) {
1341 _redefine(RegExp.prototype, TO_STRING, fn, true);
1342};
1343
1344// 21.2.5.14 RegExp.prototype.toString()
1345if (_fails(function () { return $toString.call({ source: 'a', flags: 'b' }) != '/a/b'; })) {
1346 define(function toString() {
1347 var R = _anObject(this);
1348 return '/'.concat(R.source, '/',
1349 'flags' in R ? R.flags : !_descriptors && R instanceof RegExp ? _flags.call(R) : undefined);
1350 });
1351// FF44- RegExp#toString has a wrong name
1352} else if ($toString.name != TO_STRING) {
1353 define(function toString() {
1354 return $toString.call(this);
1355 });
1356}
1357
1358// most Object methods by ES6 should accept primitives
1359
1360
1361
1362var _objectSap = function (KEY, exec) {
1363 var fn = (_core.Object || {})[KEY] || Object[KEY];
1364 var exp = {};
1365 exp[KEY] = exec(fn);
1366 _export(_export.S + _export.F * _fails(function () { fn(1); }), 'Object', exp);
1367};
1368
1369// 19.1.2.14 Object.keys(O)
1370
1371
1372
1373_objectSap('keys', function () {
1374 return function keys(it) {
1375 return _objectKeys(_toObject(it));
1376 };
1377});
1378
1379// 7.3.20 SpeciesConstructor(O, defaultConstructor)
1380
1381
1382var SPECIES$2 = _wks('species');
1383var _speciesConstructor = function (O, D) {
1384 var C = _anObject(O).constructor;
1385 var S;
1386 return C === undefined || (S = _anObject(C)[SPECIES$2]) == undefined ? D : _aFunction(S);
1387};
1388
1389// fast apply, http://jsperf.lnkit.com/fast-apply/5
1390var _invoke = function (fn, args, that) {
1391 var un = that === undefined;
1392 switch (args.length) {
1393 case 0: return un ? fn()
1394 : fn.call(that);
1395 case 1: return un ? fn(args[0])
1396 : fn.call(that, args[0]);
1397 case 2: return un ? fn(args[0], args[1])
1398 : fn.call(that, args[0], args[1]);
1399 case 3: return un ? fn(args[0], args[1], args[2])
1400 : fn.call(that, args[0], args[1], args[2]);
1401 case 4: return un ? fn(args[0], args[1], args[2], args[3])
1402 : fn.call(that, args[0], args[1], args[2], args[3]);
1403 } return fn.apply(that, args);
1404};
1405
1406var process = _global.process;
1407var setTask = _global.setImmediate;
1408var clearTask = _global.clearImmediate;
1409var MessageChannel = _global.MessageChannel;
1410var Dispatch = _global.Dispatch;
1411var counter = 0;
1412var queue = {};
1413var ONREADYSTATECHANGE = 'onreadystatechange';
1414var defer, channel, port;
1415var run = function () {
1416 var id = +this;
1417 // eslint-disable-next-line no-prototype-builtins
1418 if (queue.hasOwnProperty(id)) {
1419 var fn = queue[id];
1420 delete queue[id];
1421 fn();
1422 }
1423};
1424var listener = function (event) {
1425 run.call(event.data);
1426};
1427// Node.js 0.9+ & IE10+ has setImmediate, otherwise:
1428if (!setTask || !clearTask) {
1429 setTask = function setImmediate(fn) {
1430 var args = [];
1431 var i = 1;
1432 while (arguments.length > i) args.push(arguments[i++]);
1433 queue[++counter] = function () {
1434 // eslint-disable-next-line no-new-func
1435 _invoke(typeof fn == 'function' ? fn : Function(fn), args);
1436 };
1437 defer(counter);
1438 return counter;
1439 };
1440 clearTask = function clearImmediate(id) {
1441 delete queue[id];
1442 };
1443 // Node.js 0.8-
1444 if (_cof(process) == 'process') {
1445 defer = function (id) {
1446 process.nextTick(_ctx(run, id, 1));
1447 };
1448 // Sphere (JS game engine) Dispatch API
1449 } else if (Dispatch && Dispatch.now) {
1450 defer = function (id) {
1451 Dispatch.now(_ctx(run, id, 1));
1452 };
1453 // Browsers with MessageChannel, includes WebWorkers
1454 } else if (MessageChannel) {
1455 channel = new MessageChannel();
1456 port = channel.port2;
1457 channel.port1.onmessage = listener;
1458 defer = _ctx(port.postMessage, port, 1);
1459 // Browsers with postMessage, skip WebWorkers
1460 // IE8 has postMessage, but it's sync & typeof its postMessage is 'object'
1461 } else if (_global.addEventListener && typeof postMessage == 'function' && !_global.importScripts) {
1462 defer = function (id) {
1463 _global.postMessage(id + '', '*');
1464 };
1465 _global.addEventListener('message', listener, false);
1466 // IE8-
1467 } else if (ONREADYSTATECHANGE in _domCreate('script')) {
1468 defer = function (id) {
1469 _html.appendChild(_domCreate('script'))[ONREADYSTATECHANGE] = function () {
1470 _html.removeChild(this);
1471 run.call(id);
1472 };
1473 };
1474 // Rest old browsers
1475 } else {
1476 defer = function (id) {
1477 setTimeout(_ctx(run, id, 1), 0);
1478 };
1479 }
1480}
1481var _task = {
1482 set: setTask,
1483 clear: clearTask
1484};
1485
1486var macrotask = _task.set;
1487var Observer = _global.MutationObserver || _global.WebKitMutationObserver;
1488var process$1 = _global.process;
1489var Promise$1 = _global.Promise;
1490var isNode = _cof(process$1) == 'process';
1491
1492var _microtask = function () {
1493 var head, last, notify;
1494
1495 var flush = function () {
1496 var parent, fn;
1497 if (isNode && (parent = process$1.domain)) parent.exit();
1498 while (head) {
1499 fn = head.fn;
1500 head = head.next;
1501 try {
1502 fn();
1503 } catch (e) {
1504 if (head) notify();
1505 else last = undefined;
1506 throw e;
1507 }
1508 } last = undefined;
1509 if (parent) parent.enter();
1510 };
1511
1512 // Node.js
1513 if (isNode) {
1514 notify = function () {
1515 process$1.nextTick(flush);
1516 };
1517 // browsers with MutationObserver, except iOS Safari - https://github.com/zloirock/core-js/issues/339
1518 } else if (Observer && !(_global.navigator && _global.navigator.standalone)) {
1519 var toggle = true;
1520 var node = document.createTextNode('');
1521 new Observer(flush).observe(node, { characterData: true }); // eslint-disable-line no-new
1522 notify = function () {
1523 node.data = toggle = !toggle;
1524 };
1525 // environments with maybe non-completely correct, but existent Promise
1526 } else if (Promise$1 && Promise$1.resolve) {
1527 // Promise.resolve without an argument throws an error in LG WebOS 2
1528 var promise = Promise$1.resolve(undefined);
1529 notify = function () {
1530 promise.then(flush);
1531 };
1532 // for other environments - macrotask based on:
1533 // - setImmediate
1534 // - MessageChannel
1535 // - window.postMessag
1536 // - onreadystatechange
1537 // - setTimeout
1538 } else {
1539 notify = function () {
1540 // strange IE + webpack dev server bug - use .call(global)
1541 macrotask.call(_global, flush);
1542 };
1543 }
1544
1545 return function (fn) {
1546 var task = { fn: fn, next: undefined };
1547 if (last) last.next = task;
1548 if (!head) {
1549 head = task;
1550 notify();
1551 } last = task;
1552 };
1553};
1554
1555// 25.4.1.5 NewPromiseCapability(C)
1556
1557
1558function PromiseCapability(C) {
1559 var resolve, reject;
1560 this.promise = new C(function ($$resolve, $$reject) {
1561 if (resolve !== undefined || reject !== undefined) throw TypeError('Bad Promise constructor');
1562 resolve = $$resolve;
1563 reject = $$reject;
1564 });
1565 this.resolve = _aFunction(resolve);
1566 this.reject = _aFunction(reject);
1567}
1568
1569var f$4 = function (C) {
1570 return new PromiseCapability(C);
1571};
1572
1573var _newPromiseCapability = {
1574 f: f$4
1575};
1576
1577var _perform = function (exec) {
1578 try {
1579 return { e: false, v: exec() };
1580 } catch (e) {
1581 return { e: true, v: e };
1582 }
1583};
1584
1585var navigator = _global.navigator;
1586
1587var _userAgent = navigator && navigator.userAgent || '';
1588
1589var _promiseResolve = function (C, x) {
1590 _anObject(C);
1591 if (_isObject(x) && x.constructor === C) return x;
1592 var promiseCapability = _newPromiseCapability.f(C);
1593 var resolve = promiseCapability.resolve;
1594 resolve(x);
1595 return promiseCapability.promise;
1596};
1597
1598var task = _task.set;
1599var microtask = _microtask();
1600
1601
1602
1603
1604var PROMISE = 'Promise';
1605var TypeError$1 = _global.TypeError;
1606var process$2 = _global.process;
1607var versions = process$2 && process$2.versions;
1608var v8 = versions && versions.v8 || '';
1609var $Promise = _global[PROMISE];
1610var isNode$1 = _classof(process$2) == 'process';
1611var empty = function () { /* empty */ };
1612var Internal, newGenericPromiseCapability, OwnPromiseCapability, Wrapper;
1613var newPromiseCapability = newGenericPromiseCapability = _newPromiseCapability.f;
1614
1615var USE_NATIVE = !!function () {
1616 try {
1617 // correct subclassing with @@species support
1618 var promise = $Promise.resolve(1);
1619 var FakePromise = (promise.constructor = {})[_wks('species')] = function (exec) {
1620 exec(empty, empty);
1621 };
1622 // unhandled rejections tracking support, NodeJS Promise without it fails @@species test
1623 return (isNode$1 || typeof PromiseRejectionEvent == 'function')
1624 && promise.then(empty) instanceof FakePromise
1625 // v8 6.6 (Node 10 and Chrome 66) have a bug with resolving custom thenables
1626 // https://bugs.chromium.org/p/chromium/issues/detail?id=830565
1627 // we can't detect it synchronously, so just check versions
1628 && v8.indexOf('6.6') !== 0
1629 && _userAgent.indexOf('Chrome/66') === -1;
1630 } catch (e) { /* empty */ }
1631}();
1632
1633// helpers
1634var isThenable = function (it) {
1635 var then;
1636 return _isObject(it) && typeof (then = it.then) == 'function' ? then : false;
1637};
1638var notify = function (promise, isReject) {
1639 if (promise._n) return;
1640 promise._n = true;
1641 var chain = promise._c;
1642 microtask(function () {
1643 var value = promise._v;
1644 var ok = promise._s == 1;
1645 var i = 0;
1646 var run = function (reaction) {
1647 var handler = ok ? reaction.ok : reaction.fail;
1648 var resolve = reaction.resolve;
1649 var reject = reaction.reject;
1650 var domain = reaction.domain;
1651 var result, then, exited;
1652 try {
1653 if (handler) {
1654 if (!ok) {
1655 if (promise._h == 2) onHandleUnhandled(promise);
1656 promise._h = 1;
1657 }
1658 if (handler === true) result = value;
1659 else {
1660 if (domain) domain.enter();
1661 result = handler(value); // may throw
1662 if (domain) {
1663 domain.exit();
1664 exited = true;
1665 }
1666 }
1667 if (result === reaction.promise) {
1668 reject(TypeError$1('Promise-chain cycle'));
1669 } else if (then = isThenable(result)) {
1670 then.call(result, resolve, reject);
1671 } else resolve(result);
1672 } else reject(value);
1673 } catch (e) {
1674 if (domain && !exited) domain.exit();
1675 reject(e);
1676 }
1677 };
1678 while (chain.length > i) run(chain[i++]); // variable length - can't use forEach
1679 promise._c = [];
1680 promise._n = false;
1681 if (isReject && !promise._h) onUnhandled(promise);
1682 });
1683};
1684var onUnhandled = function (promise) {
1685 task.call(_global, function () {
1686 var value = promise._v;
1687 var unhandled = isUnhandled(promise);
1688 var result, handler, console;
1689 if (unhandled) {
1690 result = _perform(function () {
1691 if (isNode$1) {
1692 process$2.emit('unhandledRejection', value, promise);
1693 } else if (handler = _global.onunhandledrejection) {
1694 handler({ promise: promise, reason: value });
1695 } else if ((console = _global.console) && console.error) {
1696 console.error('Unhandled promise rejection', value);
1697 }
1698 });
1699 // Browsers should not trigger `rejectionHandled` event if it was handled here, NodeJS - should
1700 promise._h = isNode$1 || isUnhandled(promise) ? 2 : 1;
1701 } promise._a = undefined;
1702 if (unhandled && result.e) throw result.v;
1703 });
1704};
1705var isUnhandled = function (promise) {
1706 return promise._h !== 1 && (promise._a || promise._c).length === 0;
1707};
1708var onHandleUnhandled = function (promise) {
1709 task.call(_global, function () {
1710 var handler;
1711 if (isNode$1) {
1712 process$2.emit('rejectionHandled', promise);
1713 } else if (handler = _global.onrejectionhandled) {
1714 handler({ promise: promise, reason: promise._v });
1715 }
1716 });
1717};
1718var $reject = function (value) {
1719 var promise = this;
1720 if (promise._d) return;
1721 promise._d = true;
1722 promise = promise._w || promise; // unwrap
1723 promise._v = value;
1724 promise._s = 2;
1725 if (!promise._a) promise._a = promise._c.slice();
1726 notify(promise, true);
1727};
1728var $resolve = function (value) {
1729 var promise = this;
1730 var then;
1731 if (promise._d) return;
1732 promise._d = true;
1733 promise = promise._w || promise; // unwrap
1734 try {
1735 if (promise === value) throw TypeError$1("Promise can't be resolved itself");
1736 if (then = isThenable(value)) {
1737 microtask(function () {
1738 var wrapper = { _w: promise, _d: false }; // wrap
1739 try {
1740 then.call(value, _ctx($resolve, wrapper, 1), _ctx($reject, wrapper, 1));
1741 } catch (e) {
1742 $reject.call(wrapper, e);
1743 }
1744 });
1745 } else {
1746 promise._v = value;
1747 promise._s = 1;
1748 notify(promise, false);
1749 }
1750 } catch (e) {
1751 $reject.call({ _w: promise, _d: false }, e); // wrap
1752 }
1753};
1754
1755// constructor polyfill
1756if (!USE_NATIVE) {
1757 // 25.4.3.1 Promise(executor)
1758 $Promise = function Promise(executor) {
1759 _anInstance(this, $Promise, PROMISE, '_h');
1760 _aFunction(executor);
1761 Internal.call(this);
1762 try {
1763 executor(_ctx($resolve, this, 1), _ctx($reject, this, 1));
1764 } catch (err) {
1765 $reject.call(this, err);
1766 }
1767 };
1768 // eslint-disable-next-line no-unused-vars
1769 Internal = function Promise(executor) {
1770 this._c = []; // <- awaiting reactions
1771 this._a = undefined; // <- checked in isUnhandled reactions
1772 this._s = 0; // <- state
1773 this._d = false; // <- done
1774 this._v = undefined; // <- value
1775 this._h = 0; // <- rejection state, 0 - default, 1 - handled, 2 - unhandled
1776 this._n = false; // <- notify
1777 };
1778 Internal.prototype = _redefineAll($Promise.prototype, {
1779 // 25.4.5.3 Promise.prototype.then(onFulfilled, onRejected)
1780 then: function then(onFulfilled, onRejected) {
1781 var reaction = newPromiseCapability(_speciesConstructor(this, $Promise));
1782 reaction.ok = typeof onFulfilled == 'function' ? onFulfilled : true;
1783 reaction.fail = typeof onRejected == 'function' && onRejected;
1784 reaction.domain = isNode$1 ? process$2.domain : undefined;
1785 this._c.push(reaction);
1786 if (this._a) this._a.push(reaction);
1787 if (this._s) notify(this, false);
1788 return reaction.promise;
1789 },
1790 // 25.4.5.1 Promise.prototype.catch(onRejected)
1791 'catch': function (onRejected) {
1792 return this.then(undefined, onRejected);
1793 }
1794 });
1795 OwnPromiseCapability = function () {
1796 var promise = new Internal();
1797 this.promise = promise;
1798 this.resolve = _ctx($resolve, promise, 1);
1799 this.reject = _ctx($reject, promise, 1);
1800 };
1801 _newPromiseCapability.f = newPromiseCapability = function (C) {
1802 return C === $Promise || C === Wrapper
1803 ? new OwnPromiseCapability(C)
1804 : newGenericPromiseCapability(C);
1805 };
1806}
1807
1808_export(_export.G + _export.W + _export.F * !USE_NATIVE, { Promise: $Promise });
1809_setToStringTag($Promise, PROMISE);
1810_setSpecies(PROMISE);
1811Wrapper = _core[PROMISE];
1812
1813// statics
1814_export(_export.S + _export.F * !USE_NATIVE, PROMISE, {
1815 // 25.4.4.5 Promise.reject(r)
1816 reject: function reject(r) {
1817 var capability = newPromiseCapability(this);
1818 var $$reject = capability.reject;
1819 $$reject(r);
1820 return capability.promise;
1821 }
1822});
1823_export(_export.S + _export.F * (_library || !USE_NATIVE), PROMISE, {
1824 // 25.4.4.6 Promise.resolve(x)
1825 resolve: function resolve(x) {
1826 return _promiseResolve(_library && this === Wrapper ? $Promise : this, x);
1827 }
1828});
1829_export(_export.S + _export.F * !(USE_NATIVE && _iterDetect(function (iter) {
1830 $Promise.all(iter)['catch'](empty);
1831})), PROMISE, {
1832 // 25.4.4.1 Promise.all(iterable)
1833 all: function all(iterable) {
1834 var C = this;
1835 var capability = newPromiseCapability(C);
1836 var resolve = capability.resolve;
1837 var reject = capability.reject;
1838 var result = _perform(function () {
1839 var values = [];
1840 var index = 0;
1841 var remaining = 1;
1842 _forOf(iterable, false, function (promise) {
1843 var $index = index++;
1844 var alreadyCalled = false;
1845 values.push(undefined);
1846 remaining++;
1847 C.resolve(promise).then(function (value) {
1848 if (alreadyCalled) return;
1849 alreadyCalled = true;
1850 values[$index] = value;
1851 --remaining || resolve(values);
1852 }, reject);
1853 });
1854 --remaining || resolve(values);
1855 });
1856 if (result.e) reject(result.v);
1857 return capability.promise;
1858 },
1859 // 25.4.4.4 Promise.race(iterable)
1860 race: function race(iterable) {
1861 var C = this;
1862 var capability = newPromiseCapability(C);
1863 var reject = capability.reject;
1864 var result = _perform(function () {
1865 _forOf(iterable, false, function (promise) {
1866 C.resolve(promise).then(capability.resolve, reject);
1867 });
1868 });
1869 if (result.e) reject(result.v);
1870 return capability.promise;
1871 }
1872});
1873
1874// 22.1.3.4 Array.prototype.entries()
1875// 22.1.3.13 Array.prototype.keys()
1876// 22.1.3.29 Array.prototype.values()
1877// 22.1.3.30 Array.prototype[@@iterator]()
1878var es6_array_iterator = _iterDefine(Array, 'Array', function (iterated, kind) {
1879 this._t = _toIobject(iterated); // target
1880 this._i = 0; // next index
1881 this._k = kind; // kind
1882// 22.1.5.2.1 %ArrayIteratorPrototype%.next()
1883}, function () {
1884 var O = this._t;
1885 var kind = this._k;
1886 var index = this._i++;
1887 if (!O || index >= O.length) {
1888 this._t = undefined;
1889 return _iterStep(1);
1890 }
1891 if (kind == 'keys') return _iterStep(0, index);
1892 if (kind == 'values') return _iterStep(0, O[index]);
1893 return _iterStep(0, [index, O[index]]);
1894}, 'values');
1895
1896// argumentsList[@@iterator] is %ArrayProto_values% (9.4.4.6, 9.4.4.7)
1897_iterators.Arguments = _iterators.Array;
1898
1899_addToUnscopables('keys');
1900_addToUnscopables('values');
1901_addToUnscopables('entries');
1902
1903// true -> String#at
1904// false -> String#codePointAt
1905var _stringAt = function (TO_STRING) {
1906 return function (that, pos) {
1907 var s = String(_defined(that));
1908 var i = _toInteger(pos);
1909 var l = s.length;
1910 var a, b;
1911 if (i < 0 || i >= l) return TO_STRING ? '' : undefined;
1912 a = s.charCodeAt(i);
1913 return a < 0xd800 || a > 0xdbff || i + 1 === l || (b = s.charCodeAt(i + 1)) < 0xdc00 || b > 0xdfff
1914 ? TO_STRING ? s.charAt(i) : a
1915 : TO_STRING ? s.slice(i, i + 2) : (a - 0xd800 << 10) + (b - 0xdc00) + 0x10000;
1916 };
1917};
1918
1919var $at = _stringAt(true);
1920
1921// 21.1.3.27 String.prototype[@@iterator]()
1922_iterDefine(String, 'String', function (iterated) {
1923 this._t = String(iterated); // target
1924 this._i = 0; // next index
1925// 21.1.5.2.1 %StringIteratorPrototype%.next()
1926}, function () {
1927 var O = this._t;
1928 var index = this._i;
1929 var point;
1930 if (index >= O.length) return { value: undefined, done: true };
1931 point = $at(O, index);
1932 this._i += point.length;
1933 return { value: point, done: false };
1934});
1935
1936var ITERATOR$4 = _wks('iterator');
1937var TO_STRING_TAG = _wks('toStringTag');
1938var ArrayValues = _iterators.Array;
1939
1940var DOMIterables = {
1941 CSSRuleList: true, // TODO: Not spec compliant, should be false.
1942 CSSStyleDeclaration: false,
1943 CSSValueList: false,
1944 ClientRectList: false,
1945 DOMRectList: false,
1946 DOMStringList: false,
1947 DOMTokenList: true,
1948 DataTransferItemList: false,
1949 FileList: false,
1950 HTMLAllCollection: false,
1951 HTMLCollection: false,
1952 HTMLFormElement: false,
1953 HTMLSelectElement: false,
1954 MediaList: true, // TODO: Not spec compliant, should be false.
1955 MimeTypeArray: false,
1956 NamedNodeMap: false,
1957 NodeList: true,
1958 PaintRequestList: false,
1959 Plugin: false,
1960 PluginArray: false,
1961 SVGLengthList: false,
1962 SVGNumberList: false,
1963 SVGPathSegList: false,
1964 SVGPointList: false,
1965 SVGStringList: false,
1966 SVGTransformList: false,
1967 SourceBufferList: false,
1968 StyleSheetList: true, // TODO: Not spec compliant, should be false.
1969 TextTrackCueList: false,
1970 TextTrackList: false,
1971 TouchList: false
1972};
1973
1974for (var collections = _objectKeys(DOMIterables), i = 0; i < collections.length; i++) {
1975 var NAME = collections[i];
1976 var explicit = DOMIterables[NAME];
1977 var Collection = _global[NAME];
1978 var proto = Collection && Collection.prototype;
1979 var key;
1980 if (proto) {
1981 if (!proto[ITERATOR$4]) _hide(proto, ITERATOR$4, ArrayValues);
1982 if (!proto[TO_STRING_TAG]) _hide(proto, TO_STRING_TAG, NAME);
1983 _iterators[NAME] = ArrayValues;
1984 if (explicit) for (key in es6_array_iterator) if (!proto[key]) _redefine(proto, key, es6_array_iterator[key], true);
1985 }
1986}
1987
1988var runtime = createCommonjsModule(function (module) {
1989/**
1990 * Copyright (c) 2014-present, Facebook, Inc.
1991 *
1992 * This source code is licensed under the MIT license found in the
1993 * LICENSE file in the root directory of this source tree.
1994 */
1995
1996!(function(global) {
1997
1998 var Op = Object.prototype;
1999 var hasOwn = Op.hasOwnProperty;
2000 var undefined; // More compressible than void 0.
2001 var $Symbol = typeof Symbol === "function" ? Symbol : {};
2002 var iteratorSymbol = $Symbol.iterator || "@@iterator";
2003 var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator";
2004 var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
2005 var runtime = global.regeneratorRuntime;
2006 if (runtime) {
2007 {
2008 // If regeneratorRuntime is defined globally and we're in a module,
2009 // make the exports object identical to regeneratorRuntime.
2010 module.exports = runtime;
2011 }
2012 // Don't bother evaluating the rest of this file if the runtime was
2013 // already defined globally.
2014 return;
2015 }
2016
2017 // Define the runtime globally (as expected by generated code) as either
2018 // module.exports (if we're in a module) or a new, empty object.
2019 runtime = global.regeneratorRuntime = module.exports;
2020
2021 function wrap(innerFn, outerFn, self, tryLocsList) {
2022 // If outerFn provided and outerFn.prototype is a Generator, then outerFn.prototype instanceof Generator.
2023 var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator;
2024 var generator = Object.create(protoGenerator.prototype);
2025 var context = new Context(tryLocsList || []);
2026
2027 // The ._invoke method unifies the implementations of the .next,
2028 // .throw, and .return methods.
2029 generator._invoke = makeInvokeMethod(innerFn, self, context);
2030
2031 return generator;
2032 }
2033 runtime.wrap = wrap;
2034
2035 // Try/catch helper to minimize deoptimizations. Returns a completion
2036 // record like context.tryEntries[i].completion. This interface could
2037 // have been (and was previously) designed to take a closure to be
2038 // invoked without arguments, but in all the cases we care about we
2039 // already have an existing method we want to call, so there's no need
2040 // to create a new function object. We can even get away with assuming
2041 // the method takes exactly one argument, since that happens to be true
2042 // in every case, so we don't have to touch the arguments object. The
2043 // only additional allocation required is the completion record, which
2044 // has a stable shape and so hopefully should be cheap to allocate.
2045 function tryCatch(fn, obj, arg) {
2046 try {
2047 return { type: "normal", arg: fn.call(obj, arg) };
2048 } catch (err) {
2049 return { type: "throw", arg: err };
2050 }
2051 }
2052
2053 var GenStateSuspendedStart = "suspendedStart";
2054 var GenStateSuspendedYield = "suspendedYield";
2055 var GenStateExecuting = "executing";
2056 var GenStateCompleted = "completed";
2057
2058 // Returning this object from the innerFn has the same effect as
2059 // breaking out of the dispatch switch statement.
2060 var ContinueSentinel = {};
2061
2062 // Dummy constructor functions that we use as the .constructor and
2063 // .constructor.prototype properties for functions that return Generator
2064 // objects. For full spec compliance, you may wish to configure your
2065 // minifier not to mangle the names of these two functions.
2066 function Generator() {}
2067 function GeneratorFunction() {}
2068 function GeneratorFunctionPrototype() {}
2069
2070 // This is a polyfill for %IteratorPrototype% for environments that
2071 // don't natively support it.
2072 var IteratorPrototype = {};
2073 IteratorPrototype[iteratorSymbol] = function () {
2074 return this;
2075 };
2076
2077 var getProto = Object.getPrototypeOf;
2078 var NativeIteratorPrototype = getProto && getProto(getProto(values([])));
2079 if (NativeIteratorPrototype &&
2080 NativeIteratorPrototype !== Op &&
2081 hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) {
2082 // This environment has a native %IteratorPrototype%; use it instead
2083 // of the polyfill.
2084 IteratorPrototype = NativeIteratorPrototype;
2085 }
2086
2087 var Gp = GeneratorFunctionPrototype.prototype =
2088 Generator.prototype = Object.create(IteratorPrototype);
2089 GeneratorFunction.prototype = Gp.constructor = GeneratorFunctionPrototype;
2090 GeneratorFunctionPrototype.constructor = GeneratorFunction;
2091 GeneratorFunctionPrototype[toStringTagSymbol] =
2092 GeneratorFunction.displayName = "GeneratorFunction";
2093
2094 // Helper for defining the .next, .throw, and .return methods of the
2095 // Iterator interface in terms of a single ._invoke method.
2096 function defineIteratorMethods(prototype) {
2097 ["next", "throw", "return"].forEach(function(method) {
2098 prototype[method] = function(arg) {
2099 return this._invoke(method, arg);
2100 };
2101 });
2102 }
2103
2104 runtime.isGeneratorFunction = function(genFun) {
2105 var ctor = typeof genFun === "function" && genFun.constructor;
2106 return ctor
2107 ? ctor === GeneratorFunction ||
2108 // For the native GeneratorFunction constructor, the best we can
2109 // do is to check its .name property.
2110 (ctor.displayName || ctor.name) === "GeneratorFunction"
2111 : false;
2112 };
2113
2114 runtime.mark = function(genFun) {
2115 if (Object.setPrototypeOf) {
2116 Object.setPrototypeOf(genFun, GeneratorFunctionPrototype);
2117 } else {
2118 genFun.__proto__ = GeneratorFunctionPrototype;
2119 if (!(toStringTagSymbol in genFun)) {
2120 genFun[toStringTagSymbol] = "GeneratorFunction";
2121 }
2122 }
2123 genFun.prototype = Object.create(Gp);
2124 return genFun;
2125 };
2126
2127 // Within the body of any async function, `await x` is transformed to
2128 // `yield regeneratorRuntime.awrap(x)`, so that the runtime can test
2129 // `hasOwn.call(value, "__await")` to determine if the yielded value is
2130 // meant to be awaited.
2131 runtime.awrap = function(arg) {
2132 return { __await: arg };
2133 };
2134
2135 function AsyncIterator(generator) {
2136 function invoke(method, arg, resolve, reject) {
2137 var record = tryCatch(generator[method], generator, arg);
2138 if (record.type === "throw") {
2139 reject(record.arg);
2140 } else {
2141 var result = record.arg;
2142 var value = result.value;
2143 if (value &&
2144 typeof value === "object" &&
2145 hasOwn.call(value, "__await")) {
2146 return Promise.resolve(value.__await).then(function(value) {
2147 invoke("next", value, resolve, reject);
2148 }, function(err) {
2149 invoke("throw", err, resolve, reject);
2150 });
2151 }
2152
2153 return Promise.resolve(value).then(function(unwrapped) {
2154 // When a yielded Promise is resolved, its final value becomes
2155 // the .value of the Promise<{value,done}> result for the
2156 // current iteration. If the Promise is rejected, however, the
2157 // result for this iteration will be rejected with the same
2158 // reason. Note that rejections of yielded Promises are not
2159 // thrown back into the generator function, as is the case
2160 // when an awaited Promise is rejected. This difference in
2161 // behavior between yield and await is important, because it
2162 // allows the consumer to decide what to do with the yielded
2163 // rejection (swallow it and continue, manually .throw it back
2164 // into the generator, abandon iteration, whatever). With
2165 // await, by contrast, there is no opportunity to examine the
2166 // rejection reason outside the generator function, so the
2167 // only option is to throw it from the await expression, and
2168 // let the generator function handle the exception.
2169 result.value = unwrapped;
2170 resolve(result);
2171 }, reject);
2172 }
2173 }
2174
2175 var previousPromise;
2176
2177 function enqueue(method, arg) {
2178 function callInvokeWithMethodAndArg() {
2179 return new Promise(function(resolve, reject) {
2180 invoke(method, arg, resolve, reject);
2181 });
2182 }
2183
2184 return previousPromise =
2185 // If enqueue has been called before, then we want to wait until
2186 // all previous Promises have been resolved before calling invoke,
2187 // so that results are always delivered in the correct order. If
2188 // enqueue has not been called before, then it is important to
2189 // call invoke immediately, without waiting on a callback to fire,
2190 // so that the async generator function has the opportunity to do
2191 // any necessary setup in a predictable way. This predictability
2192 // is why the Promise constructor synchronously invokes its
2193 // executor callback, and why async functions synchronously
2194 // execute code before the first await. Since we implement simple
2195 // async functions in terms of async generators, it is especially
2196 // important to get this right, even though it requires care.
2197 previousPromise ? previousPromise.then(
2198 callInvokeWithMethodAndArg,
2199 // Avoid propagating failures to Promises returned by later
2200 // invocations of the iterator.
2201 callInvokeWithMethodAndArg
2202 ) : callInvokeWithMethodAndArg();
2203 }
2204
2205 // Define the unified helper method that is used to implement .next,
2206 // .throw, and .return (see defineIteratorMethods).
2207 this._invoke = enqueue;
2208 }
2209
2210 defineIteratorMethods(AsyncIterator.prototype);
2211 AsyncIterator.prototype[asyncIteratorSymbol] = function () {
2212 return this;
2213 };
2214 runtime.AsyncIterator = AsyncIterator;
2215
2216 // Note that simple async functions are implemented on top of
2217 // AsyncIterator objects; they just return a Promise for the value of
2218 // the final result produced by the iterator.
2219 runtime.async = function(innerFn, outerFn, self, tryLocsList) {
2220 var iter = new AsyncIterator(
2221 wrap(innerFn, outerFn, self, tryLocsList)
2222 );
2223
2224 return runtime.isGeneratorFunction(outerFn)
2225 ? iter // If outerFn is a generator, return the full iterator.
2226 : iter.next().then(function(result) {
2227 return result.done ? result.value : iter.next();
2228 });
2229 };
2230
2231 function makeInvokeMethod(innerFn, self, context) {
2232 var state = GenStateSuspendedStart;
2233
2234 return function invoke(method, arg) {
2235 if (state === GenStateExecuting) {
2236 throw new Error("Generator is already running");
2237 }
2238
2239 if (state === GenStateCompleted) {
2240 if (method === "throw") {
2241 throw arg;
2242 }
2243
2244 // Be forgiving, per 25.3.3.3.3 of the spec:
2245 // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorresume
2246 return doneResult();
2247 }
2248
2249 context.method = method;
2250 context.arg = arg;
2251
2252 while (true) {
2253 var delegate = context.delegate;
2254 if (delegate) {
2255 var delegateResult = maybeInvokeDelegate(delegate, context);
2256 if (delegateResult) {
2257 if (delegateResult === ContinueSentinel) continue;
2258 return delegateResult;
2259 }
2260 }
2261
2262 if (context.method === "next") {
2263 // Setting context._sent for legacy support of Babel's
2264 // function.sent implementation.
2265 context.sent = context._sent = context.arg;
2266
2267 } else if (context.method === "throw") {
2268 if (state === GenStateSuspendedStart) {
2269 state = GenStateCompleted;
2270 throw context.arg;
2271 }
2272
2273 context.dispatchException(context.arg);
2274
2275 } else if (context.method === "return") {
2276 context.abrupt("return", context.arg);
2277 }
2278
2279 state = GenStateExecuting;
2280
2281 var record = tryCatch(innerFn, self, context);
2282 if (record.type === "normal") {
2283 // If an exception is thrown from innerFn, we leave state ===
2284 // GenStateExecuting and loop back for another invocation.
2285 state = context.done
2286 ? GenStateCompleted
2287 : GenStateSuspendedYield;
2288
2289 if (record.arg === ContinueSentinel) {
2290 continue;
2291 }
2292
2293 return {
2294 value: record.arg,
2295 done: context.done
2296 };
2297
2298 } else if (record.type === "throw") {
2299 state = GenStateCompleted;
2300 // Dispatch the exception by looping back around to the
2301 // context.dispatchException(context.arg) call above.
2302 context.method = "throw";
2303 context.arg = record.arg;
2304 }
2305 }
2306 };
2307 }
2308
2309 // Call delegate.iterator[context.method](context.arg) and handle the
2310 // result, either by returning a { value, done } result from the
2311 // delegate iterator, or by modifying context.method and context.arg,
2312 // setting context.delegate to null, and returning the ContinueSentinel.
2313 function maybeInvokeDelegate(delegate, context) {
2314 var method = delegate.iterator[context.method];
2315 if (method === undefined) {
2316 // A .throw or .return when the delegate iterator has no .throw
2317 // method always terminates the yield* loop.
2318 context.delegate = null;
2319
2320 if (context.method === "throw") {
2321 if (delegate.iterator.return) {
2322 // If the delegate iterator has a return method, give it a
2323 // chance to clean up.
2324 context.method = "return";
2325 context.arg = undefined;
2326 maybeInvokeDelegate(delegate, context);
2327
2328 if (context.method === "throw") {
2329 // If maybeInvokeDelegate(context) changed context.method from
2330 // "return" to "throw", let that override the TypeError below.
2331 return ContinueSentinel;
2332 }
2333 }
2334
2335 context.method = "throw";
2336 context.arg = new TypeError(
2337 "The iterator does not provide a 'throw' method");
2338 }
2339
2340 return ContinueSentinel;
2341 }
2342
2343 var record = tryCatch(method, delegate.iterator, context.arg);
2344
2345 if (record.type === "throw") {
2346 context.method = "throw";
2347 context.arg = record.arg;
2348 context.delegate = null;
2349 return ContinueSentinel;
2350 }
2351
2352 var info = record.arg;
2353
2354 if (! info) {
2355 context.method = "throw";
2356 context.arg = new TypeError("iterator result is not an object");
2357 context.delegate = null;
2358 return ContinueSentinel;
2359 }
2360
2361 if (info.done) {
2362 // Assign the result of the finished delegate to the temporary
2363 // variable specified by delegate.resultName (see delegateYield).
2364 context[delegate.resultName] = info.value;
2365
2366 // Resume execution at the desired location (see delegateYield).
2367 context.next = delegate.nextLoc;
2368
2369 // If context.method was "throw" but the delegate handled the
2370 // exception, let the outer generator proceed normally. If
2371 // context.method was "next", forget context.arg since it has been
2372 // "consumed" by the delegate iterator. If context.method was
2373 // "return", allow the original .return call to continue in the
2374 // outer generator.
2375 if (context.method !== "return") {
2376 context.method = "next";
2377 context.arg = undefined;
2378 }
2379
2380 } else {
2381 // Re-yield the result returned by the delegate method.
2382 return info;
2383 }
2384
2385 // The delegate iterator is finished, so forget it and continue with
2386 // the outer generator.
2387 context.delegate = null;
2388 return ContinueSentinel;
2389 }
2390
2391 // Define Generator.prototype.{next,throw,return} in terms of the
2392 // unified ._invoke helper method.
2393 defineIteratorMethods(Gp);
2394
2395 Gp[toStringTagSymbol] = "Generator";
2396
2397 // A Generator should always return itself as the iterator object when the
2398 // @@iterator function is called on it. Some browsers' implementations of the
2399 // iterator prototype chain incorrectly implement this, causing the Generator
2400 // object to not be returned from this call. This ensures that doesn't happen.
2401 // See https://github.com/facebook/regenerator/issues/274 for more details.
2402 Gp[iteratorSymbol] = function() {
2403 return this;
2404 };
2405
2406 Gp.toString = function() {
2407 return "[object Generator]";
2408 };
2409
2410 function pushTryEntry(locs) {
2411 var entry = { tryLoc: locs[0] };
2412
2413 if (1 in locs) {
2414 entry.catchLoc = locs[1];
2415 }
2416
2417 if (2 in locs) {
2418 entry.finallyLoc = locs[2];
2419 entry.afterLoc = locs[3];
2420 }
2421
2422 this.tryEntries.push(entry);
2423 }
2424
2425 function resetTryEntry(entry) {
2426 var record = entry.completion || {};
2427 record.type = "normal";
2428 delete record.arg;
2429 entry.completion = record;
2430 }
2431
2432 function Context(tryLocsList) {
2433 // The root entry object (effectively a try statement without a catch
2434 // or a finally block) gives us a place to store values thrown from
2435 // locations where there is no enclosing try statement.
2436 this.tryEntries = [{ tryLoc: "root" }];
2437 tryLocsList.forEach(pushTryEntry, this);
2438 this.reset(true);
2439 }
2440
2441 runtime.keys = function(object) {
2442 var keys = [];
2443 for (var key in object) {
2444 keys.push(key);
2445 }
2446 keys.reverse();
2447
2448 // Rather than returning an object with a next method, we keep
2449 // things simple and return the next function itself.
2450 return function next() {
2451 while (keys.length) {
2452 var key = keys.pop();
2453 if (key in object) {
2454 next.value = key;
2455 next.done = false;
2456 return next;
2457 }
2458 }
2459
2460 // To avoid creating an additional object, we just hang the .value
2461 // and .done properties off the next function object itself. This
2462 // also ensures that the minifier will not anonymize the function.
2463 next.done = true;
2464 return next;
2465 };
2466 };
2467
2468 function values(iterable) {
2469 if (iterable) {
2470 var iteratorMethod = iterable[iteratorSymbol];
2471 if (iteratorMethod) {
2472 return iteratorMethod.call(iterable);
2473 }
2474
2475 if (typeof iterable.next === "function") {
2476 return iterable;
2477 }
2478
2479 if (!isNaN(iterable.length)) {
2480 var i = -1, next = function next() {
2481 while (++i < iterable.length) {
2482 if (hasOwn.call(iterable, i)) {
2483 next.value = iterable[i];
2484 next.done = false;
2485 return next;
2486 }
2487 }
2488
2489 next.value = undefined;
2490 next.done = true;
2491
2492 return next;
2493 };
2494
2495 return next.next = next;
2496 }
2497 }
2498
2499 // Return an iterator with no values.
2500 return { next: doneResult };
2501 }
2502 runtime.values = values;
2503
2504 function doneResult() {
2505 return { value: undefined, done: true };
2506 }
2507
2508 Context.prototype = {
2509 constructor: Context,
2510
2511 reset: function(skipTempReset) {
2512 this.prev = 0;
2513 this.next = 0;
2514 // Resetting context._sent for legacy support of Babel's
2515 // function.sent implementation.
2516 this.sent = this._sent = undefined;
2517 this.done = false;
2518 this.delegate = null;
2519
2520 this.method = "next";
2521 this.arg = undefined;
2522
2523 this.tryEntries.forEach(resetTryEntry);
2524
2525 if (!skipTempReset) {
2526 for (var name in this) {
2527 // Not sure about the optimal order of these conditions:
2528 if (name.charAt(0) === "t" &&
2529 hasOwn.call(this, name) &&
2530 !isNaN(+name.slice(1))) {
2531 this[name] = undefined;
2532 }
2533 }
2534 }
2535 },
2536
2537 stop: function() {
2538 this.done = true;
2539
2540 var rootEntry = this.tryEntries[0];
2541 var rootRecord = rootEntry.completion;
2542 if (rootRecord.type === "throw") {
2543 throw rootRecord.arg;
2544 }
2545
2546 return this.rval;
2547 },
2548
2549 dispatchException: function(exception) {
2550 if (this.done) {
2551 throw exception;
2552 }
2553
2554 var context = this;
2555 function handle(loc, caught) {
2556 record.type = "throw";
2557 record.arg = exception;
2558 context.next = loc;
2559
2560 if (caught) {
2561 // If the dispatched exception was caught by a catch block,
2562 // then let that catch block handle the exception normally.
2563 context.method = "next";
2564 context.arg = undefined;
2565 }
2566
2567 return !! caught;
2568 }
2569
2570 for (var i = this.tryEntries.length - 1; i >= 0; --i) {
2571 var entry = this.tryEntries[i];
2572 var record = entry.completion;
2573
2574 if (entry.tryLoc === "root") {
2575 // Exception thrown outside of any try block that could handle
2576 // it, so set the completion value of the entire function to
2577 // throw the exception.
2578 return handle("end");
2579 }
2580
2581 if (entry.tryLoc <= this.prev) {
2582 var hasCatch = hasOwn.call(entry, "catchLoc");
2583 var hasFinally = hasOwn.call(entry, "finallyLoc");
2584
2585 if (hasCatch && hasFinally) {
2586 if (this.prev < entry.catchLoc) {
2587 return handle(entry.catchLoc, true);
2588 } else if (this.prev < entry.finallyLoc) {
2589 return handle(entry.finallyLoc);
2590 }
2591
2592 } else if (hasCatch) {
2593 if (this.prev < entry.catchLoc) {
2594 return handle(entry.catchLoc, true);
2595 }
2596
2597 } else if (hasFinally) {
2598 if (this.prev < entry.finallyLoc) {
2599 return handle(entry.finallyLoc);
2600 }
2601
2602 } else {
2603 throw new Error("try statement without catch or finally");
2604 }
2605 }
2606 }
2607 },
2608
2609 abrupt: function(type, arg) {
2610 for (var i = this.tryEntries.length - 1; i >= 0; --i) {
2611 var entry = this.tryEntries[i];
2612 if (entry.tryLoc <= this.prev &&
2613 hasOwn.call(entry, "finallyLoc") &&
2614 this.prev < entry.finallyLoc) {
2615 var finallyEntry = entry;
2616 break;
2617 }
2618 }
2619
2620 if (finallyEntry &&
2621 (type === "break" ||
2622 type === "continue") &&
2623 finallyEntry.tryLoc <= arg &&
2624 arg <= finallyEntry.finallyLoc) {
2625 // Ignore the finally entry if control is not jumping to a
2626 // location outside the try/catch block.
2627 finallyEntry = null;
2628 }
2629
2630 var record = finallyEntry ? finallyEntry.completion : {};
2631 record.type = type;
2632 record.arg = arg;
2633
2634 if (finallyEntry) {
2635 this.method = "next";
2636 this.next = finallyEntry.finallyLoc;
2637 return ContinueSentinel;
2638 }
2639
2640 return this.complete(record);
2641 },
2642
2643 complete: function(record, afterLoc) {
2644 if (record.type === "throw") {
2645 throw record.arg;
2646 }
2647
2648 if (record.type === "break" ||
2649 record.type === "continue") {
2650 this.next = record.arg;
2651 } else if (record.type === "return") {
2652 this.rval = this.arg = record.arg;
2653 this.method = "return";
2654 this.next = "end";
2655 } else if (record.type === "normal" && afterLoc) {
2656 this.next = afterLoc;
2657 }
2658
2659 return ContinueSentinel;
2660 },
2661
2662 finish: function(finallyLoc) {
2663 for (var i = this.tryEntries.length - 1; i >= 0; --i) {
2664 var entry = this.tryEntries[i];
2665 if (entry.finallyLoc === finallyLoc) {
2666 this.complete(entry.completion, entry.afterLoc);
2667 resetTryEntry(entry);
2668 return ContinueSentinel;
2669 }
2670 }
2671 },
2672
2673 "catch": function(tryLoc) {
2674 for (var i = this.tryEntries.length - 1; i >= 0; --i) {
2675 var entry = this.tryEntries[i];
2676 if (entry.tryLoc === tryLoc) {
2677 var record = entry.completion;
2678 if (record.type === "throw") {
2679 var thrown = record.arg;
2680 resetTryEntry(entry);
2681 }
2682 return thrown;
2683 }
2684 }
2685
2686 // The context.catch method must only be called with a location
2687 // argument that corresponds to a known catch block.
2688 throw new Error("illegal catch attempt");
2689 },
2690
2691 delegateYield: function(iterable, resultName, nextLoc) {
2692 this.delegate = {
2693 iterator: values(iterable),
2694 resultName: resultName,
2695 nextLoc: nextLoc
2696 };
2697
2698 if (this.method === "next") {
2699 // Deliberately forget the last sent value so that we don't
2700 // accidentally pass it on to the delegate.
2701 this.arg = undefined;
2702 }
2703
2704 return ContinueSentinel;
2705 }
2706 };
2707})(
2708 // In sloppy mode, unbound `this` refers to the global object, fallback to
2709 // Function constructor if we're in global strict mode. That is sadly a form
2710 // of indirect eval which violates Content Security Policy.
2711 (function() { return this })() || Function("return this")()
2712);
2713});
2714
2715/**
2716 * @class Batch
2717 * @namespace Daux.Core
2718 */
2719var Batch =
2720/*#__PURE__*/
2721function () {
2722 /**
2723 * @param {Service.Store} store
2724 */
2725 function Batch(store) {
2726 _classCallCheck(this, Batch);
2727
2728 this.store = store;
2729 this.queues = [];
2730 }
2731 /**
2732 * @param {string} type
2733 * @param {Array.<Object>} records
2734 * @function
2735 */
2736
2737
2738 _createClass(Batch, [{
2739 key: "set",
2740 value: function set(type, records) {
2741 this.queues.push({
2742 operation: 'set',
2743 data: {
2744 type: type,
2745 records: records
2746 }
2747 });
2748 }
2749 /**
2750 * @param {string} type
2751 * @param {string} id
2752 * @param {Object} attribute
2753 * @function
2754 */
2755
2756 }, {
2757 key: "update",
2758 value: function update(type, id, attribute) {
2759 this.queues.push({
2760 operation: 'update',
2761 data: {
2762 type: type,
2763 id: id,
2764 attribute: attribute
2765 }
2766 });
2767 }
2768 /**
2769 * @param {string} type
2770 * @param {string} id
2771 * @function
2772 */
2773
2774 }, {
2775 key: "delete",
2776 value: function _delete(type, id) {
2777 this.queues.push({
2778 operation: 'delete',
2779 data: {
2780 type: type,
2781 id: id
2782 }
2783 });
2784 }
2785 /**
2786 * @param {Object} [option]
2787 * @function
2788 */
2789
2790 }, {
2791 key: "commit",
2792 value: function commit(option) {
2793 var _this = this;
2794
2795 this.queues.forEach(function (_ref, index) {
2796 var operation = _ref.operation,
2797 data = _ref.data;
2798 var finalOption = option;
2799
2800 if (!finalOption) {
2801 var isBackgroundOperation = index !== _this.queues.length - 1;
2802 finalOption = {
2803 isBackgroundOperation: isBackgroundOperation
2804 };
2805 }
2806
2807 if (operation === 'set') {
2808 _this.store.set(data.type, data.records, finalOption);
2809 } else if (operation === 'update') {
2810 _this.store.update(data.type, data.id, data.attribute, finalOption);
2811 } else if (operation === 'delete') {
2812 _this.store.delete(data.type, data.id, finalOption);
2813 }
2814 });
2815 this.queues = [];
2816 }
2817 }]);
2818
2819 return Batch;
2820}();
2821
2822/**
2823 * @param {Object} model
2824 * @param {string} type
2825 * @param {string} attribute
2826 * @return {string} Cardinality
2827 * @function
2828 */
2829function getCardinality(model, type, attribute) {
2830 var meta = model[type].relationship[attribute];
2831
2832 if (meta.kind === 'belongsTo') {
2833 if (meta.inverse) {
2834 var inverseMeta = model[meta.type].relationship[meta.inverse];
2835
2836 if (inverseMeta.kind === 'belongsTo') {
2837 return 'oneToOne';
2838 }
2839
2840 return 'oneToMany';
2841 }
2842
2843 return 'oneToNone';
2844 }
2845
2846 if (meta.inverse) {
2847 var _inverseMeta = model[meta.type].relationship[meta.inverse];
2848
2849 if (_inverseMeta.kind === 'belongsTo') {
2850 return 'oneToMany';
2851 }
2852
2853 return 'manyToMany';
2854 }
2855
2856 return 'manyToNone';
2857}
2858
2859/**
2860 * @param {Daux.Core.Model} model
2861 * @return {Object} Default record
2862 */
2863function getDefaultRecord(model) {
2864 var defaultRecord = {};
2865 model.attributes.forEach(function (attribute) {
2866 defaultRecord[attribute] = null;
2867 });
2868 Object.keys(model.relationship).forEach(function (relationshipKey) {
2869 if (model.relationship[relationshipKey].kind === 'belongsTo') {
2870 defaultRecord[relationshipKey] = null;
2871 } else {
2872 defaultRecord[relationshipKey] = [];
2873 }
2874 });
2875 return defaultRecord;
2876}
2877
2878/**
2879 * @param {Object} record
2880 * @return {string|null} Record ID
2881 * @function
2882 */
2883function normalizeBelongsTo(record) {
2884 if (typeof record === 'string' || record === null) {
2885 return record;
2886 }
2887
2888 if (_typeof(record) === 'object') {
2889 return record.id;
2890 }
2891
2892 return null;
2893}
2894/**
2895 * @param {Array.<Object>} records
2896 * @return {Array.<string>} Record IDs
2897 * @function
2898 */
2899
2900
2901function normalizeHasMany(records) {
2902 if (Array.isArray(records)) {
2903 return records.map(function (record) {
2904 if (typeof record === 'string') {
2905 return record;
2906 }
2907
2908 return record.id;
2909 });
2910 }
2911
2912 return [];
2913}
2914/**
2915 * @param {Daux.Core.Model} model
2916 * @param {Object} record
2917 * @return {Object} Normalized record
2918 */
2919
2920
2921function normalize(model, record) {
2922 var normalizedRecord = {
2923 id: record.id
2924 };
2925 model.attributes.forEach(function (attribute) {
2926 normalizedRecord[attribute] = Object.prototype.hasOwnProperty.call(record, attribute) ? record[attribute] : null;
2927 });
2928 Object.keys(model.relationship).forEach(function (relationshipKey) {
2929 if (model.relationship[relationshipKey].kind === 'belongsTo') {
2930 normalizedRecord[relationshipKey] = normalizeBelongsTo(record[relationshipKey]);
2931 } else {
2932 normalizedRecord[relationshipKey] = normalizeHasMany(record[relationshipKey]);
2933 }
2934 });
2935 return normalizedRecord;
2936}
2937
2938/**
2939 * @class Store
2940 * @namespace Daux.Core
2941 */
2942
2943var Store =
2944/*#__PURE__*/
2945function () {
2946 /**
2947 * @callback fetch
2948 * @return {Promise} Resolves with the records
2949 */
2950
2951 /**
2952 * @param {Object} model
2953 * @function
2954 */
2955 function Store(model) {
2956 _classCallCheck(this, Store);
2957
2958 this.model = model;
2959 this.state = this.buildInitialState();
2960 this.subscription = {};
2961 }
2962 /**
2963 * @param {string} type
2964 * @param {Object} record
2965 * @param {Object} [option={}]
2966 * @function
2967 */
2968
2969
2970 _createClass(Store, [{
2971 key: "set",
2972 value: function set(type, record) {
2973 var option = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
2974
2975 if (record.id) {
2976 var modelForType = this.model[type];
2977 var deserializedRecord = option.isDeserialized ? record : modelForType.deserialize(record);
2978
2979 if (deserializedRecord) {
2980 var normalizedRecord = normalize(modelForType, deserializedRecord);
2981 this.state[type].data[normalizedRecord.id] = normalizedRecord;
2982 this.syncAddedRelationships(type, deserializedRecord);
2983
2984 if (!option.isBackgroundOperation) {
2985 this.triggerSubscriptions();
2986 }
2987 }
2988 } else {
2989 throw new Error('Record to set has no ID');
2990 }
2991 }
2992 /**
2993 * @param {string} type
2994 * @param {string} id
2995 * @param {Object} attribute
2996 * @param {Object} [option={}]
2997 * @function
2998 */
2999
3000 }, {
3001 key: "update",
3002 value: function update(type, id, attribute) {
3003 var option = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
3004 var cachedRecord = this.getStateForRecord(type, id);
3005
3006 if (cachedRecord) {
3007 var modelForType = this.model[type];
3008 var updatedRecord = modelForType.deserialize(Object.assign({}, cachedRecord, attribute, {
3009 id: id
3010 }));
3011 this.set(type, updatedRecord, {
3012 isBackgroundOperation: true,
3013 isDeserialized: true
3014 });
3015 this.syncRemovedRelationships(type, updatedRecord, cachedRecord);
3016
3017 if (!option.isBackgroundOperation) {
3018 this.triggerSubscriptions();
3019 }
3020 } else {
3021 throw new Error('Record doesn\'t exist');
3022 }
3023 }
3024 /**
3025 * @param {string} type
3026 * @param {string} id
3027 * @param {Object} [option={}]
3028 * @function
3029 */
3030
3031 }, {
3032 key: "delete",
3033 value: function _delete(type, id) {
3034 var option = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
3035 var cachedRecord = this.getStateForRecord(type, id);
3036
3037 if (cachedRecord) {
3038 var modelForType = this.model[type];
3039 var defaultRecord = getDefaultRecord(modelForType, type);
3040 this.update(type, id, defaultRecord, {
3041 isBackgroundOperation: true
3042 });
3043 delete this.state[type].data[id];
3044
3045 if (!option.isBackgroundOperation) {
3046 this.triggerSubscriptions();
3047 }
3048 } else {
3049 throw new Error('Record doesn\'t exist');
3050 }
3051 }
3052 /**
3053 * @param {string} type
3054 * @param {string} id
3055 * @param {option} [option={}]
3056 * @return {Object} Record
3057 * @function
3058 */
3059
3060 }, {
3061 key: "get",
3062 value: function () {
3063 var _get$$1 = _asyncToGenerator(
3064 /*#__PURE__*/
3065 regeneratorRuntime.mark(function _callee(type, id) {
3066 var option,
3067 record,
3068 recordState,
3069 _args = arguments;
3070 return regeneratorRuntime.wrap(function _callee$(_context) {
3071 while (1) {
3072 switch (_context.prev = _context.next) {
3073 case 0:
3074 option = _args.length > 2 && _args[2] !== undefined ? _args[2] : {};
3075
3076 if (!(!this.isRecordAttributePopulated(type, id) && option.fetch)) {
3077 _context.next = 8;
3078 break;
3079 }
3080
3081 _context.next = 4;
3082 return option.fetch();
3083
3084 case 4:
3085 record = _context.sent;
3086
3087 if (record) {
3088 _context.next = 7;
3089 break;
3090 }
3091
3092 return _context.abrupt("return", null);
3093
3094 case 7:
3095 this.set(type, record, {
3096 isBackgroundOperation: true
3097 });
3098
3099 case 8:
3100 recordState = this.getStateForRecord(type, id);
3101
3102 if (!(recordState && option.include)) {
3103 _context.next = 12;
3104 break;
3105 }
3106
3107 _context.next = 12;
3108 return this.includeRelationships(type, recordState, option);
3109
3110 case 12:
3111 return _context.abrupt("return", this.getCachedRecord(type, id));
3112
3113 case 13:
3114 case "end":
3115 return _context.stop();
3116 }
3117 }
3118 }, _callee, this);
3119 }));
3120
3121 return function get(_x, _x2) {
3122 return _get$$1.apply(this, arguments);
3123 };
3124 }()
3125 /**
3126 * @param {string} type
3127 * @param {option} [option={}]
3128 * @return {Array.<Object>} Records
3129 * @function
3130 */
3131
3132 }, {
3133 key: "getAll",
3134 value: function () {
3135 var _getAll = _asyncToGenerator(
3136 /*#__PURE__*/
3137 regeneratorRuntime.mark(function _callee2(type) {
3138 var _this = this;
3139
3140 var option,
3141 records,
3142 _args2 = arguments;
3143 return regeneratorRuntime.wrap(function _callee2$(_context2) {
3144 while (1) {
3145 switch (_context2.prev = _context2.next) {
3146 case 0:
3147 option = _args2.length > 1 && _args2[1] !== undefined ? _args2[1] : {};
3148
3149 if (!(option.fetch && !this.state[type].isDataComplete)) {
3150 _context2.next = 10;
3151 break;
3152 }
3153
3154 _context2.next = 4;
3155 return option.fetch();
3156
3157 case 4:
3158 _context2.t0 = _context2.sent;
3159
3160 if (_context2.t0) {
3161 _context2.next = 7;
3162 break;
3163 }
3164
3165 _context2.t0 = [];
3166
3167 case 7:
3168 records = _context2.t0;
3169 records.forEach(function (record) {
3170 return _this.set(type, record, {
3171 isBackgroundOperation: true
3172 });
3173 });
3174 this.state[type].isDataComplete = true;
3175
3176 case 10:
3177 return _context2.abrupt("return", Promise.all(Object.keys(this.state[type].data).map(function (id) {
3178 return _this.get(type, id, {
3179 include: option.include
3180 });
3181 })));
3182
3183 case 11:
3184 case "end":
3185 return _context2.stop();
3186 }
3187 }
3188 }, _callee2, this);
3189 }));
3190
3191 return function getAll(_x3) {
3192 return _getAll.apply(this, arguments);
3193 };
3194 }()
3195 /**
3196 * @param {string} type
3197 * @param {option} [option={}]
3198 * @return {Array.<Object>} Records
3199 * @function
3200 */
3201
3202 }, {
3203 key: "query",
3204 value: function () {
3205 var _query = _asyncToGenerator(
3206 /*#__PURE__*/
3207 regeneratorRuntime.mark(function _callee3(type) {
3208 var _this2 = this;
3209
3210 var option,
3211 records,
3212 _args3 = arguments;
3213 return regeneratorRuntime.wrap(function _callee3$(_context3) {
3214 while (1) {
3215 switch (_context3.prev = _context3.next) {
3216 case 0:
3217 option = _args3.length > 1 && _args3[1] !== undefined ? _args3[1] : {};
3218 _context3.next = 3;
3219 return option.fetch();
3220
3221 case 3:
3222 _context3.t0 = _context3.sent;
3223
3224 if (_context3.t0) {
3225 _context3.next = 6;
3226 break;
3227 }
3228
3229 _context3.t0 = [];
3230
3231 case 6:
3232 records = _context3.t0;
3233 records.forEach(function (record) {
3234 return _this2.set(type, record, {
3235 isBackgroundOperation: true
3236 });
3237 });
3238 return _context3.abrupt("return", Promise.all(records.map(function (record) {
3239 return _this2.get(type, record.id, {
3240 include: option.include
3241 });
3242 })));
3243
3244 case 9:
3245 case "end":
3246 return _context3.stop();
3247 }
3248 }
3249 }, _callee3, this);
3250 }));
3251
3252 return function query(_x4) {
3253 return _query.apply(this, arguments);
3254 };
3255 }()
3256 /**
3257 * @callback subscriptionCallback
3258 */
3259
3260 /**
3261 * @param {subscriptionCallback} callback
3262 * @param {string} [id=Math.random().toString(32).slice(2).substr(0, 5)]
3263 * @return {Function} Unsubscribe function
3264 * @function
3265 */
3266
3267 }, {
3268 key: "subscribe",
3269 value: function subscribe(callback) {
3270 var _this3 = this;
3271
3272 var id = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Math.random().toString(32).slice(2).substr(0, 5);
3273 this.subscription[id] = callback;
3274 return function () {
3275 return delete _this3.subscription[id];
3276 };
3277 }
3278 /**
3279 * @return {Daux.Core.Batch} Batch instance
3280 * @function
3281 */
3282
3283 }, {
3284 key: "batch",
3285 value: function batch() {
3286 return new Batch(this);
3287 }
3288 /**
3289 * @return {Object} State
3290 * @private
3291 * @function
3292 */
3293
3294 }, {
3295 key: "buildInitialState",
3296 value: function buildInitialState() {
3297 var model = this.model;
3298 var state = {};
3299 Object.keys(model).forEach(function (modelKey) {
3300 state[modelKey] = {
3301 isDataComplete: false,
3302 data: {}
3303 };
3304 });
3305 return state;
3306 }
3307 /**
3308 * @param {string} type
3309 * @param {string} id
3310 * @param {number} [nestLevel=0]
3311 * @return {Object} State for record
3312 * @private
3313 * @function
3314 */
3315
3316 }, {
3317 key: "getCachedRecord",
3318 value: function getCachedRecord(type, id) {
3319 var _this4 = this;
3320
3321 var nestLevel = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
3322
3323 if (this.state[type].data[id]) {
3324 var cachedRecord = Object.assign({}, this.state[type].data[id]);
3325 var modelForType = this.model[type];
3326 Object.keys(modelForType.relationship).forEach(function (relationshipKey) {
3327 var descriptor = modelForType.relationship[relationshipKey];
3328
3329 if (descriptor.kind === 'belongsTo' && cachedRecord[relationshipKey]) {
3330 var belongsToId = cachedRecord[relationshipKey];
3331
3332 if (nestLevel < 1) {
3333 cachedRecord[relationshipKey] = _this4.getCachedRecord(descriptor.type, belongsToId, nestLevel + 1);
3334 } else {
3335 cachedRecord[relationshipKey] = Object.assign({}, _this4.state[descriptor.type].data[belongsToId]);
3336 }
3337 } else if (descriptor.kind === 'hasMany' && cachedRecord[relationshipKey].length > 0) {
3338 cachedRecord[relationshipKey] = cachedRecord[relationshipKey].map(function (hasManyId) {
3339 if (nestLevel < 1) {
3340 return _this4.getCachedRecord(descriptor.type, hasManyId, nestLevel + 1);
3341 }
3342
3343 return Object.assign({}, _this4.state[descriptor.type].data[hasManyId]);
3344 });
3345 }
3346 });
3347 return cachedRecord;
3348 }
3349
3350 return null;
3351 }
3352 /**
3353 * @param {string} type
3354 * @param {string} id
3355 * @return {Object} State for record
3356 * @private
3357 * @function
3358 */
3359
3360 }, {
3361 key: "getStateForRecord",
3362 value: function getStateForRecord(type, id) {
3363 return this.state[type].data[id] || null;
3364 }
3365 /**
3366 * @param {string} type
3367 * @param {string} id
3368 * @return {boolean} True if populated. Otherwise, false.
3369 * @private
3370 * @function
3371 */
3372
3373 }, {
3374 key: "isRecordAttributePopulated",
3375 value: function isRecordAttributePopulated(type, id) {
3376 var currentRecordState = this.getStateForRecord(type, id);
3377
3378 if (currentRecordState) {
3379 var attributes = this.model[type].attributes;
3380 var populatedAttribute = attributes.find(function (key) {
3381 if (currentRecordState[key] === null || Array.isArray(currentRecordState[key]) && currentRecordState[key].length === 0) {
3382 return false;
3383 }
3384
3385 return true;
3386 });
3387 return populatedAttribute;
3388 }
3389
3390 return false;
3391 }
3392 /**
3393 * @param {string} type
3394 * @param {Object} record
3395 * @param {Object} option
3396 * @param {string} key
3397 * @param {string} descriptor
3398 * @private
3399 * @function
3400 */
3401
3402 }, {
3403 key: "includeRelationship",
3404 value: function () {
3405 var _includeRelationship = _asyncToGenerator(
3406 /*#__PURE__*/
3407 regeneratorRuntime.mark(function _callee4(type, record, option, key, descriptor) {
3408 var _this5 = this;
3409
3410 var includedData, _includedData, includedDataIds, uniqueHasManyIds;
3411
3412 return regeneratorRuntime.wrap(function _callee4$(_context4) {
3413 while (1) {
3414 switch (_context4.prev = _context4.next) {
3415 case 0:
3416 if (!(descriptor.kind === 'belongsTo')) {
3417 _context4.next = 9;
3418 break;
3419 }
3420
3421 if (!(record[key] === null || !this.isRecordAttributePopulated(descriptor.type, record[key]))) {
3422 _context4.next = 7;
3423 break;
3424 }
3425
3426 _context4.next = 4;
3427 return option.include[key](record);
3428
3429 case 4:
3430 includedData = _context4.sent;
3431 this.set(descriptor.type, includedData, {
3432 isBackgroundOperation: true
3433 });
3434 this.update(type, record.id, _defineProperty({}, key, includedData.id), {
3435 isBackgroundOperation: true
3436 });
3437
3438 case 7:
3439 _context4.next = 17;
3440 break;
3441
3442 case 9:
3443 if (!(descriptor.kind === 'hasMany')) {
3444 _context4.next = 17;
3445 break;
3446 }
3447
3448 _context4.next = 12;
3449 return option.include[key](record);
3450
3451 case 12:
3452 _includedData = _context4.sent;
3453
3454 _includedData.forEach(function (data) {
3455 return _this5.set(descriptor.type, data, {
3456 isBackgroundOperation: true
3457 });
3458 });
3459
3460 includedDataIds = _includedData.map(function (data) {
3461 return data.id;
3462 });
3463 uniqueHasManyIds = _toConsumableArray(new Set(_toConsumableArray(record[key]).concat(_toConsumableArray(includedDataIds))));
3464 this.update(type, record.id, _defineProperty({}, key, uniqueHasManyIds), {
3465 isBackgroundOperation: true
3466 });
3467
3468 case 17:
3469 case "end":
3470 return _context4.stop();
3471 }
3472 }
3473 }, _callee4, this);
3474 }));
3475
3476 return function includeRelationship(_x5, _x6, _x7, _x8, _x9) {
3477 return _includeRelationship.apply(this, arguments);
3478 };
3479 }()
3480 /**
3481 * @param {string} type
3482 * @param {Object} record
3483 * @param {Object} option
3484 * @private
3485 * @function
3486 */
3487
3488 }, {
3489 key: "includeRelationships",
3490 value: function () {
3491 var _includeRelationships = _asyncToGenerator(
3492 /*#__PURE__*/
3493 regeneratorRuntime.mark(function _callee5(type, record, option) {
3494 var _this6 = this;
3495
3496 var relationship, includes;
3497 return regeneratorRuntime.wrap(function _callee5$(_context5) {
3498 while (1) {
3499 switch (_context5.prev = _context5.next) {
3500 case 0:
3501 relationship = this.model[type].relationship;
3502 includes = [];
3503 Object.keys(relationship).forEach(function (key) {
3504 if (option.include[key]) {
3505 includes.push(_this6.includeRelationship(type, record, option, key, relationship[key]));
3506 }
3507 });
3508 _context5.next = 5;
3509 return Promise.all(includes);
3510
3511 case 5:
3512 case "end":
3513 return _context5.stop();
3514 }
3515 }
3516 }, _callee5, this);
3517 }));
3518
3519 return function includeRelationships(_x10, _x11, _x12) {
3520 return _includeRelationships.apply(this, arguments);
3521 };
3522 }()
3523 /**
3524 * @param {string} type
3525 * @param {Object} record
3526 * @param {string} belongsToAttribute
3527 * @private
3528 * @function
3529 */
3530
3531 }, {
3532 key: "syncAddedBelongsTo",
3533 value: function syncAddedBelongsTo(type, record, belongsToAttribute) {
3534 var cardinality = getCardinality(this.model, type, belongsToAttribute);
3535 var descriptor = this.model[type].relationship[belongsToAttribute];
3536 var recordToSync;
3537
3538 if (_typeof(record[belongsToAttribute]) === 'object' && record[belongsToAttribute] !== null) {
3539 recordToSync = this.model[descriptor.type].deserialize(record[belongsToAttribute]);
3540 } else {
3541 recordToSync = {
3542 id: record[belongsToAttribute]
3543 };
3544 }
3545
3546 if (cardinality === 'oneToOne') {
3547 var cachedRecord = this.getStateForRecord(descriptor.type, recordToSync.id);
3548
3549 if (!cachedRecord || !cachedRecord[descriptor.inverse]) {
3550 var newRecord = Object.assign(recordToSync, _defineProperty({}, descriptor.inverse, record.id));
3551 this.set(descriptor.type, newRecord, {
3552 isBackgroundOperation: true
3553 });
3554 }
3555 } else if (cardinality === 'oneToMany') {
3556 var _cachedRecord = this.getStateForRecord(descriptor.type, recordToSync.id);
3557
3558 if (!_cachedRecord) {
3559 var _newRecord = Object.assign(recordToSync, _defineProperty({}, descriptor.inverse, [record.id]));
3560
3561 this.set(descriptor.type, _newRecord, {
3562 isBackgroundOperation: true
3563 });
3564 } else if (!_cachedRecord[descriptor.inverse].find(function (id) {
3565 return id === record.id;
3566 })) {
3567 _cachedRecord[descriptor.inverse].push(record.id);
3568 }
3569 } else {
3570 var _cachedRecord2 = this.getStateForRecord(descriptor.type, recordToSync.id) || {};
3571
3572 var _newRecord2 = Object.assign(_cachedRecord2, recordToSync);
3573
3574 this.set(descriptor.type, _newRecord2, {
3575 isBackgroundOperation: true
3576 });
3577 }
3578 }
3579 /**
3580 * @param {string} type
3581 * @param {Object} record
3582 * @param {string} hasManyAttribute
3583 * @private
3584 * @function
3585 */
3586
3587 }, {
3588 key: "syncAddedHasMany",
3589 value: function syncAddedHasMany(type, record, hasManyAttribute) {
3590 var _this7 = this;
3591
3592 var recordsToSync = record[hasManyAttribute];
3593
3594 if (Array.isArray(recordsToSync)) {
3595 recordsToSync.forEach(function (item) {
3596 var cardinality = getCardinality(_this7.model, type, hasManyAttribute);
3597 var descriptor = _this7.model[type].relationship[hasManyAttribute];
3598 var recordToSync;
3599
3600 if (_typeof(item) === 'object' && item !== null) {
3601 recordToSync = _this7.model[descriptor.type].deserialize(item);
3602 } else {
3603 recordToSync = {
3604 id: item
3605 };
3606 }
3607
3608 if (cardinality === 'oneToMany') {
3609 var cachedRecord = _this7.getStateForRecord(descriptor.type, recordToSync.id);
3610
3611 if (!cachedRecord) {
3612 var newRecord = Object.assign(recordToSync, _defineProperty({}, descriptor.inverse, record.id));
3613
3614 _this7.set(descriptor.type, newRecord, {
3615 isBackgroundOperation: true
3616 });
3617 } else {
3618 cachedRecord[descriptor.inverse] = record.id;
3619 }
3620 } else if (cardinality === 'manyToMany') {
3621 var _cachedRecord3 = _this7.getStateForRecord(descriptor.type, recordToSync.id);
3622
3623 if (!_cachedRecord3) {
3624 var _newRecord3 = Object.assign(recordToSync, _defineProperty({}, descriptor.inverse, [record.id]));
3625
3626 _this7.set(descriptor.type, _newRecord3, {
3627 isBackgroundOperation: true
3628 });
3629 } else if (!_cachedRecord3[descriptor.inverse].find(function (id) {
3630 return id === record.id;
3631 })) {
3632 _cachedRecord3[descriptor.inverse].push(record.id);
3633 }
3634 } else {
3635 var _cachedRecord4 = _this7.getStateForRecord(descriptor.type, recordToSync.id) || {};
3636
3637 var _newRecord4 = Object.assign(_cachedRecord4, recordToSync);
3638
3639 _this7.set(descriptor.type, _newRecord4, {
3640 isBackgroundOperation: true
3641 });
3642 }
3643 });
3644 }
3645 }
3646 /**
3647 * @param {string} type
3648 * @param {Object} record
3649 * @param {string} hasManyAttribute
3650 * @private
3651 * @function
3652 */
3653
3654 }, {
3655 key: "syncExistingHasMany",
3656 value: function syncExistingHasMany(type, record, hasManyAttribute) {
3657 var cardinality = getCardinality(this.model, type, hasManyAttribute);
3658 var descriptor = this.model[type].relationship[hasManyAttribute];
3659 var inverseData = this.state[descriptor.type].data;
3660 var recordId = _typeof(record) === 'object' && record !== null ? record.id : record;
3661
3662 if (cardinality === 'oneToMany') {
3663 var currentHasManyState = this.state[type].data[recordId][hasManyAttribute];
3664 var inverseIds = Object.keys(this.state[descriptor.type].data).filter(function (id) {
3665 return inverseData[id][descriptor.inverse] === recordId;
3666 });
3667 inverseIds.forEach(function (id) {
3668 if (!currentHasManyState.includes(id)) {
3669 currentHasManyState.push(id);
3670 }
3671 });
3672 } else if (cardinality === 'manyToMany') {
3673 var _currentHasManyState = this.state[type].data[recordId][hasManyAttribute];
3674
3675 var _inverseIds = Object.keys(this.state[descriptor.type].data).filter(function (id) {
3676 return inverseData[id][descriptor.inverse].includes(recordId);
3677 });
3678
3679 _inverseIds.forEach(function (id) {
3680 if (!_currentHasManyState.includes(id)) {
3681 _currentHasManyState.push(id);
3682 }
3683 });
3684 }
3685 }
3686 /**
3687 * @param {string} type
3688 * @param {Object} record
3689 * @private
3690 * @function
3691 */
3692
3693 }, {
3694 key: "syncAddedRelationships",
3695 value: function syncAddedRelationships(type, record) {
3696 var _this8 = this;
3697
3698 Object.keys(this.model[type].relationship).forEach(function (relationshipKey) {
3699 var kind = _this8.model[type].relationship[relationshipKey].kind;
3700
3701 if (record[relationshipKey]) {
3702 if (kind === 'belongsTo') {
3703 _this8.syncAddedBelongsTo(type, record, relationshipKey);
3704 } else {
3705 _this8.syncAddedHasMany(type, record, relationshipKey);
3706 }
3707 } else if (kind === 'hasMany') {
3708 _this8.syncExistingHasMany(type, record, relationshipKey);
3709 }
3710 });
3711 }
3712 /**
3713 * @param {string} type
3714 * @param {Object} currentRecord
3715 * @param {Object} oldRecord
3716 * @param {string} key
3717 * @param {Object} descriptor
3718 * @private
3719 * @function
3720 */
3721
3722 }, {
3723 key: "syncRemovedBelongsToRelationship",
3724 value: function syncRemovedBelongsToRelationship(type, currentRecord, oldRecord, key, descriptor) {
3725 if (currentRecord[key] === null && currentRecord[key] !== oldRecord[key]) {
3726 var inverseRecord = this.getStateForRecord(descriptor.type, oldRecord[key]);
3727
3728 if (inverseRecord) {
3729 var cardinality = getCardinality(this.model, type, key);
3730
3731 if (cardinality === 'oneToOne') {
3732 inverseRecord[descriptor.inverse] = null;
3733 } else if (cardinality === 'oneToMany') {
3734 inverseRecord[descriptor.inverse] = inverseRecord[descriptor.inverse].filter(function (id) {
3735 return id !== oldRecord.id;
3736 });
3737 }
3738 }
3739 }
3740 }
3741 /**
3742 * @param {string} type
3743 * @param {Object} currentRecord
3744 * @param {Object} oldRecord
3745 * @param {string} key
3746 * @param {Object} descriptor
3747 * @private
3748 * @function
3749 */
3750
3751 }, {
3752 key: "syncRemovedHasManyRelationship",
3753 value: function syncRemovedHasManyRelationship(type, currentRecord, oldRecord, key, descriptor) {
3754 var _this9 = this;
3755
3756 var removedRecords = oldRecord[key].filter(function (record) {
3757 return !currentRecord[key].includes(record);
3758 });
3759 removedRecords.forEach(function (removedRecord) {
3760 var inverseRecord = _this9.getStateForRecord(descriptor.type, removedRecord);
3761
3762 if (inverseRecord) {
3763 var cardinality = getCardinality(_this9.model, type, key);
3764
3765 if (cardinality === 'oneToMany') {
3766 inverseRecord[descriptor.inverse] = null;
3767 } else if (cardinality === 'manyToMany') {
3768 inverseRecord[descriptor.inverse] = inverseRecord[descriptor.inverse].filter(function (id) {
3769 return id !== oldRecord.id;
3770 });
3771 }
3772 }
3773 });
3774 }
3775 /**
3776 * @param {string} type
3777 * @param {Object} currentRecord
3778 * @param {Object} oldRecord
3779 * @private
3780 * @function
3781 */
3782
3783 }, {
3784 key: "syncRemovedRelationships",
3785 value: function syncRemovedRelationships(type, currentRecord, oldRecord) {
3786 var _this10 = this;
3787
3788 var model = this.model[type];
3789 Object.keys(model.relationship).forEach(function (attributeKey) {
3790 var descriptor = model.relationship[attributeKey];
3791
3792 if (descriptor.kind === 'belongsTo') {
3793 _this10.syncRemovedBelongsToRelationship(type, currentRecord, oldRecord, attributeKey, descriptor);
3794 } else if (descriptor.kind === 'hasMany') {
3795 _this10.syncRemovedHasManyRelationship(type, currentRecord, oldRecord, attributeKey, descriptor);
3796 }
3797 });
3798 }
3799 /**
3800 * @private
3801 * @function
3802 */
3803
3804 }, {
3805 key: "triggerSubscriptions",
3806 value: function triggerSubscriptions() {
3807 var _this11 = this;
3808
3809 Object.keys(this.subscription).forEach(function (key) {
3810 try {
3811 _this11.subscription[key]();
3812 } catch (error) {
3813 delete _this11.subscription[key];
3814 }
3815 });
3816 }
3817 }]);
3818
3819 return Store;
3820}();
3821
3822exports.Model = Model;
3823exports.Store = Store;