UNPKG

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