dexie 4.4.1 → 4.4.2-pr2297.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/dexie.js CHANGED
@@ -4,7 +4,7 @@
4
4
  *
5
5
  * By David Fahlander, david.fahlander@gmail.com
6
6
  *
7
- * Version 4.4.1, Wed Mar 25 2026
7
+ * Version 4.4.2-pr2297.2, Thu Apr 16 2026
8
8
  *
9
9
  * https://dexie.org
10
10
  *
@@ -54,10 +54,13 @@
54
54
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
55
55
  };
56
56
 
57
- var _global = typeof globalThis !== 'undefined' ? globalThis :
58
- typeof self !== 'undefined' ? self :
59
- typeof window !== 'undefined' ? window :
60
- global;
57
+ var _global = typeof globalThis !== 'undefined'
58
+ ? globalThis
59
+ : typeof self !== 'undefined'
60
+ ? self
61
+ : typeof window !== 'undefined'
62
+ ? window
63
+ : global;
61
64
 
62
65
  var keys = Object.keys;
63
66
  var isArray = Array.isArray;
@@ -80,32 +83,38 @@
80
83
  function props(proto, extension) {
81
84
  if (typeof extension === 'function')
82
85
  extension = extension(getProto(proto));
83
- (typeof Reflect === "undefined" ? keys : Reflect.ownKeys)(extension).forEach(function (key) {
86
+ (typeof Reflect === 'undefined' ? keys : Reflect.ownKeys)(extension).forEach(function (key) {
84
87
  setProp(proto, key, extension[key]);
85
88
  });
86
89
  }
87
90
  var defineProperty = Object.defineProperty;
88
91
  function setProp(obj, prop, functionOrGetSet, options) {
89
- defineProperty(obj, prop, extend(functionOrGetSet && hasOwn(functionOrGetSet, "get") && typeof functionOrGetSet.get === 'function' ?
90
- { get: functionOrGetSet.get, set: functionOrGetSet.set, configurable: true } :
91
- { value: functionOrGetSet, configurable: true, writable: true }, options));
92
+ defineProperty(obj, prop, extend(functionOrGetSet &&
93
+ hasOwn(functionOrGetSet, 'get') &&
94
+ typeof functionOrGetSet.get === 'function'
95
+ ? {
96
+ get: functionOrGetSet.get,
97
+ set: functionOrGetSet.set,
98
+ configurable: true,
99
+ }
100
+ : { value: functionOrGetSet, configurable: true, writable: true }, options));
92
101
  }
93
102
  function derive(Child) {
94
103
  return {
95
104
  from: function (Parent) {
96
105
  Child.prototype = Object.create(Parent.prototype);
97
- setProp(Child.prototype, "constructor", Child);
106
+ setProp(Child.prototype, 'constructor', Child);
98
107
  return {
99
- extend: props.bind(null, Child.prototype)
108
+ extend: props.bind(null, Child.prototype),
100
109
  };
101
- }
110
+ },
102
111
  };
103
112
  }
104
113
  var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
105
114
  function getPropertyDescriptor(obj, prop) {
106
115
  var pd = getOwnPropertyDescriptor(obj, prop);
107
116
  var proto;
108
- return pd || (proto = getProto(obj)) && getPropertyDescriptor(proto, prop);
117
+ return pd || ((proto = getProto(obj)) && getPropertyDescriptor(proto, prop));
109
118
  }
110
119
  var _slice = [].slice;
111
120
  function slice(args, start, end) {
@@ -116,7 +125,7 @@
116
125
  }
117
126
  function assert(b) {
118
127
  if (!b)
119
- throw new Error("Assertion Failed");
128
+ throw new Error('Assertion Failed');
120
129
  }
121
130
  function asap$1(fn) {
122
131
  if (_global.setImmediate)
@@ -148,7 +157,9 @@
148
157
  var period = keyPath.indexOf('.');
149
158
  if (period !== -1) {
150
159
  var innerObj = obj[keyPath.substr(0, period)];
151
- return innerObj == null ? undefined : getByKeyPath(innerObj, keyPath.substr(period + 1));
160
+ return innerObj == null
161
+ ? undefined
162
+ : getByKeyPath(innerObj, keyPath.substr(period + 1));
152
163
  }
153
164
  return undefined;
154
165
  }
@@ -168,7 +179,7 @@
168
179
  if (period !== -1) {
169
180
  var currentKeyPath = keyPath.substr(0, period);
170
181
  var remainingKeyPath = keyPath.substr(period + 1);
171
- if (remainingKeyPath === "")
182
+ if (remainingKeyPath === '')
172
183
  if (value === undefined) {
173
184
  if (isArray(obj) && !isNaN(parseInt(currentKeyPath)))
174
185
  obj.splice(currentKeyPath, 1);
@@ -180,7 +191,7 @@
180
191
  else {
181
192
  var innerObj = obj[currentKeyPath];
182
193
  if (!innerObj || !hasOwn(obj, currentKeyPath))
183
- innerObj = (obj[currentKeyPath] = {});
194
+ innerObj = obj[currentKeyPath] = {};
184
195
  setByKeyPath(innerObj, remainingKeyPath, value);
185
196
  }
186
197
  }
@@ -216,15 +227,22 @@
216
227
  function flatten(a) {
217
228
  return concat.apply([], a);
218
229
  }
219
- var intrinsicTypeNames = "BigUint64Array,BigInt64Array,Array,Boolean,String,Date,RegExp,Blob,File,FileList,FileSystemFileHandle,FileSystemDirectoryHandle,ArrayBuffer,DataView,Uint8ClampedArray,ImageBitmap,ImageData,Map,Set,CryptoKey"
220
- .split(',').concat(flatten([8, 16, 32, 64].map(function (num) { return ["Int", "Uint", "Float"].map(function (t) { return t + num + "Array"; }); }))).filter(function (t) { return _global[t]; });
230
+ var intrinsicTypeNames = 'BigUint64Array,BigInt64Array,Array,Boolean,String,Date,RegExp,Blob,File,FileList,FileSystemFileHandle,FileSystemDirectoryHandle,ArrayBuffer,DataView,Uint8ClampedArray,ImageBitmap,ImageData,Map,Set,CryptoKey'
231
+ .split(',')
232
+ .concat(flatten([8, 16, 32, 64].map(function (num) {
233
+ return ['Int', 'Uint', 'Float'].map(function (t) { return t + num + 'Array'; });
234
+ })))
235
+ .filter(function (t) { return _global[t]; });
221
236
  var intrinsicTypes = new Set(intrinsicTypeNames.map(function (t) { return _global[t]; }));
222
237
  function cloneSimpleObjectTree(o) {
223
238
  var rv = {};
224
239
  for (var k in o)
225
240
  if (hasOwn(o, k)) {
226
241
  var v = o[k];
227
- rv[k] = !v || typeof v !== 'object' || intrinsicTypes.has(v.constructor) ? v : cloneSimpleObjectTree(v);
242
+ rv[k] =
243
+ !v || typeof v !== 'object' || intrinsicTypes.has(v.constructor)
244
+ ? v
245
+ : cloneSimpleObjectTree(v);
228
246
  }
229
247
  return rv;
230
248
  }
@@ -267,13 +285,15 @@
267
285
  function toStringTag(o) {
268
286
  return toString.call(o).slice(8, -1);
269
287
  }
270
- var iteratorSymbol = typeof Symbol !== 'undefined' ?
271
- Symbol.iterator :
272
- '@@iterator';
273
- var getIteratorOf = typeof iteratorSymbol === "symbol" ? function (x) {
274
- var i;
275
- return x != null && (i = x[iteratorSymbol]) && i.apply(x);
276
- } : function () { return null; };
288
+ var iteratorSymbol = typeof Symbol !== 'undefined' ? Symbol.iterator : '@@iterator';
289
+ var getIteratorOf = typeof iteratorSymbol === 'symbol'
290
+ ? function (x) {
291
+ var i;
292
+ return x != null && (i = x[iteratorSymbol]) && i.apply(x);
293
+ }
294
+ : function () {
295
+ return null;
296
+ };
277
297
  function delArrayItem(a, x) {
278
298
  var i = a.indexOf(x);
279
299
  if (i >= 0)
@@ -290,7 +310,7 @@
290
310
  return [arrayLike];
291
311
  if ((it = getIteratorOf(arrayLike))) {
292
312
  a = [];
293
- while ((x = it.next()), !x.done)
313
+ while (((x = it.next()), !x.done))
294
314
  a.push(x.value);
295
315
  return a;
296
316
  }
@@ -331,7 +351,7 @@
331
351
  'Internal',
332
352
  'DatabaseClosed',
333
353
  'PrematureCommit',
334
- 'ForeignAwait'
354
+ 'ForeignAwait',
335
355
  ];
336
356
  var idbDomErrorNames = [
337
357
  'Unknown',
@@ -347,28 +367,34 @@
347
367
  'Timeout',
348
368
  'QuotaExceeded',
349
369
  'Syntax',
350
- 'DataClone'
370
+ 'DataClone',
351
371
  ];
352
372
  var errorList = dexieErrorNames.concat(idbDomErrorNames);
353
373
  var defaultTexts = {
354
- VersionChanged: "Database version changed by other database connection",
355
- DatabaseClosed: "Database has been closed",
356
- Abort: "Transaction aborted",
357
- TransactionInactive: "Transaction has already completed or failed",
358
- MissingAPI: "IndexedDB API missing. Please visit https://tinyurl.com/y2uuvskb"
374
+ VersionChanged: 'Database version changed by other database connection',
375
+ DatabaseClosed: 'Database has been closed',
376
+ Abort: 'Transaction aborted',
377
+ TransactionInactive: 'Transaction has already completed or failed',
378
+ MissingAPI: 'IndexedDB API missing. Please visit https://tinyurl.com/y2uuvskb',
359
379
  };
360
380
  function DexieError(name, msg) {
361
381
  this.name = name;
362
382
  this.message = msg;
363
383
  }
364
- derive(DexieError).from(Error).extend({
365
- toString: function () { return this.name + ": " + this.message; }
384
+ derive(DexieError)
385
+ .from(Error)
386
+ .extend({
387
+ toString: function () {
388
+ return this.name + ': ' + this.message;
389
+ },
366
390
  });
367
391
  function getMultiErrorMessage(msg, failures) {
368
- return msg + ". Errors: " + Object.keys(failures)
369
- .map(function (key) { return failures[key].toString(); })
370
- .filter(function (v, i, s) { return s.indexOf(v) === i; })
371
- .join('\n');
392
+ return (msg +
393
+ '. Errors: ' +
394
+ Object.keys(failures)
395
+ .map(function (key) { return failures[key].toString(); })
396
+ .filter(function (v, i, s) { return s.indexOf(v) === i; })
397
+ .join('\n'));
372
398
  }
373
399
  function ModifyError(msg, failures, successCount, failedKeys) {
374
400
  this.failures = failures;
@@ -378,16 +404,16 @@
378
404
  }
379
405
  derive(ModifyError).from(DexieError);
380
406
  function BulkError(msg, failures) {
381
- this.name = "BulkError";
407
+ this.name = 'BulkError';
382
408
  this.failures = Object.keys(failures).map(function (pos) { return failures[pos]; });
383
409
  this.failuresByPos = failures;
384
410
  this.message = getMultiErrorMessage(msg, this.failures);
385
411
  }
386
412
  derive(BulkError).from(DexieError);
387
- var errnames = errorList.reduce(function (obj, name) { return (obj[name] = name + "Error", obj); }, {});
413
+ var errnames = errorList.reduce(function (obj, name) { return ((obj[name] = name + 'Error'), obj); }, {});
388
414
  var BaseException = DexieError;
389
415
  var exceptions = errorList.reduce(function (obj, name) {
390
- var fullName = name + "Error";
416
+ var fullName = name + 'Error';
391
417
  function DexieError(msgOrInner, inner) {
392
418
  this.name = fullName;
393
419
  if (!msgOrInner) {
@@ -411,23 +437,30 @@
411
437
  exceptions.Type = TypeError;
412
438
  exceptions.Range = RangeError;
413
439
  var exceptionMap = idbDomErrorNames.reduce(function (obj, name) {
414
- obj[name + "Error"] = exceptions[name];
440
+ obj[name + 'Error'] = exceptions[name];
415
441
  return obj;
416
442
  }, {});
417
443
  function mapError(domError, message) {
418
- if (!domError || domError instanceof DexieError || domError instanceof TypeError || domError instanceof SyntaxError || !domError.name || !exceptionMap[domError.name])
444
+ if (!domError ||
445
+ domError instanceof DexieError ||
446
+ domError instanceof TypeError ||
447
+ domError instanceof SyntaxError ||
448
+ !domError.name ||
449
+ !exceptionMap[domError.name])
419
450
  return domError;
420
451
  var rv = new exceptionMap[domError.name](message || domError.message, domError);
421
- if ("stack" in domError) {
422
- setProp(rv, "stack", { get: function () {
452
+ if ('stack' in domError) {
453
+ setProp(rv, 'stack', {
454
+ get: function () {
423
455
  return this.inner.stack;
424
- } });
456
+ },
457
+ });
425
458
  }
426
459
  return rv;
427
460
  }
428
461
  var fullNameExceptions = errorList.reduce(function (obj, name) {
429
- if (["Syntax", "Type", "Range"].indexOf(name) === -1)
430
- obj[name + "Error"] = exceptions[name];
462
+ if (['Syntax', 'Type', 'Range'].indexOf(name) === -1)
463
+ obj[name + 'Error'] = exceptions[name];
431
464
  return obj;
432
465
  }, {});
433
466
  fullNameExceptions.ModifyError = ModifyError;
@@ -435,7 +468,9 @@
435
468
  fullNameExceptions.BulkError = BulkError;
436
469
 
437
470
  function nop() { }
438
- function mirror(val) { return val; }
471
+ function mirror(val) {
472
+ return val;
473
+ }
439
474
  function pureFunctionChain(f1, f2) {
440
475
  if (f1 == null || f1 === mirror)
441
476
  return f2;
@@ -462,7 +497,9 @@
462
497
  this.onerror = null;
463
498
  var res2 = f2.apply(this, arguments);
464
499
  if (onsuccess)
465
- this.onsuccess = this.onsuccess ? callBoth(onsuccess, this.onsuccess) : onsuccess;
500
+ this.onsuccess = this.onsuccess
501
+ ? callBoth(onsuccess, this.onsuccess)
502
+ : onsuccess;
466
503
  if (onerror)
467
504
  this.onerror = this.onerror ? callBoth(onerror, this.onerror) : onerror;
468
505
  return res2 !== undefined ? res2 : res;
@@ -478,7 +515,9 @@
478
515
  this.onsuccess = this.onerror = null;
479
516
  f2.apply(this, arguments);
480
517
  if (onsuccess)
481
- this.onsuccess = this.onsuccess ? callBoth(onsuccess, this.onsuccess) : onsuccess;
518
+ this.onsuccess = this.onsuccess
519
+ ? callBoth(onsuccess, this.onsuccess)
520
+ : onsuccess;
482
521
  if (onerror)
483
522
  this.onerror = this.onerror ? callBoth(onerror, this.onerror) : onerror;
484
523
  };
@@ -495,12 +534,16 @@
495
534
  this.onerror = null;
496
535
  var res2 = f2.apply(this, arguments);
497
536
  if (onsuccess)
498
- this.onsuccess = this.onsuccess ? callBoth(onsuccess, this.onsuccess) : onsuccess;
537
+ this.onsuccess = this.onsuccess
538
+ ? callBoth(onsuccess, this.onsuccess)
539
+ : onsuccess;
499
540
  if (onerror)
500
541
  this.onerror = this.onerror ? callBoth(onerror, this.onerror) : onerror;
501
- return res === undefined ?
502
- (res2 === undefined ? undefined : res2) :
503
- (extend(res, res2));
542
+ return res === undefined
543
+ ? res2 === undefined
544
+ ? undefined
545
+ : res2
546
+ : extend(res, res2);
504
547
  };
505
548
  }
506
549
  function reverseStoppableEventChain(f1, f2) {
@@ -536,18 +579,14 @@
536
579
  }
537
580
 
538
581
  var INTERNAL = {};
539
- var ZONE_ECHO_LIMIT = 100, _a$1 = typeof Promise === 'undefined' ?
540
- [] :
541
- (function () {
582
+ var ZONE_ECHO_LIMIT = 100, _a$1 = typeof Promise === 'undefined'
583
+ ? []
584
+ : (function () {
542
585
  var globalP = Promise.resolve();
543
586
  if (typeof crypto === 'undefined' || !crypto.subtle)
544
587
  return [globalP, getProto(globalP), globalP];
545
- var nativeP = crypto.subtle.digest("SHA-512", new Uint8Array([0]));
546
- return [
547
- nativeP,
548
- getProto(nativeP),
549
- globalP
550
- ];
588
+ var nativeP = crypto.subtle.digest('SHA-512', new Uint8Array([0]));
589
+ return [nativeP, getProto(nativeP), globalP];
551
590
  })(), resolvedNativePromise = _a$1[0], nativePromiseProto = _a$1[1], resolvedGlobalPromise = _a$1[2], nativePromiseThen = nativePromiseProto && nativePromiseProto.then;
552
591
  var NativePromise = resolvedNativePromise && resolvedNativePromise.constructor;
553
592
  var patchGlobalPromise = !!resolvedGlobalPromise;
@@ -574,7 +613,7 @@
574
613
  onunhandled: nop,
575
614
  pgp: false,
576
615
  env: {},
577
- finalize: nop
616
+ finalize: nop,
578
617
  };
579
618
  var PSD = globalPSD;
580
619
  var microtickQueue = [];
@@ -618,15 +657,15 @@
618
657
  return then;
619
658
  },
620
659
  set: function (value) {
621
- setProp(this, 'then', value && value.prototype === INTERNAL ?
622
- thenProp :
623
- {
660
+ setProp(this, 'then', value && value.prototype === INTERNAL
661
+ ? thenProp
662
+ : {
624
663
  get: function () {
625
664
  return value;
626
665
  },
627
- set: thenProp.set
666
+ set: thenProp.set,
628
667
  });
629
- }
668
+ },
630
669
  };
631
670
  props(DexiePromise.prototype, {
632
671
  then: thenProp,
@@ -637,9 +676,10 @@
637
676
  if (arguments.length === 1)
638
677
  return this.then(null, onRejected);
639
678
  var type = arguments[0], handler = arguments[1];
640
- return typeof type === 'function' ? this.then(null, function (err) {
641
- return err instanceof type ? handler(err) : PromiseReject(err);
642
- })
679
+ return typeof type === 'function'
680
+ ? this.then(null, function (err) {
681
+ return err instanceof type ? handler(err) : PromiseReject(err);
682
+ })
643
683
  : this.then(null, function (err) {
644
684
  return err && err.name === type ? handler(err) : PromiseReject(err);
645
685
  });
@@ -653,12 +693,13 @@
653
693
  },
654
694
  timeout: function (ms, msg) {
655
695
  var _this = this;
656
- return ms < Infinity ?
657
- new DexiePromise(function (resolve, reject) {
696
+ return ms < Infinity
697
+ ? new DexiePromise(function (resolve, reject) {
658
698
  var handle = setTimeout(function () { return reject(new exceptions.Timeout(msg)); }, ms);
659
699
  _this.then(resolve, reject).finally(clearTimeout.bind(null, handle));
660
- }) : this;
661
- }
700
+ })
701
+ : this;
702
+ },
662
703
  });
663
704
  if (typeof Symbol !== 'undefined' && Symbol.toStringTag)
664
705
  setProp(DexiePromise.prototype, Symbol.toStringTag, 'Dexie.Promise');
@@ -672,17 +713,20 @@
672
713
  }
673
714
  props(DexiePromise, {
674
715
  all: function () {
675
- var values = getArrayOf.apply(null, arguments)
716
+ var values = getArrayOf
717
+ .apply(null, arguments)
676
718
  .map(onPossibleParallellAsync);
677
719
  return new DexiePromise(function (resolve, reject) {
678
720
  if (values.length === 0)
679
721
  resolve([]);
680
722
  var remaining = values.length;
681
- values.forEach(function (a, i) { return DexiePromise.resolve(a).then(function (x) {
682
- values[i] = x;
683
- if (!--remaining)
684
- resolve(values);
685
- }, reject); });
723
+ values.forEach(function (a, i) {
724
+ return DexiePromise.resolve(a).then(function (x) {
725
+ values[i] = x;
726
+ if (!--remaining)
727
+ resolve(values);
728
+ }, reject);
729
+ });
686
730
  });
687
731
  },
688
732
  resolve: function (value) {
@@ -697,25 +741,31 @@
697
741
  },
698
742
  reject: PromiseReject,
699
743
  race: function () {
700
- var values = getArrayOf.apply(null, arguments).map(onPossibleParallellAsync);
744
+ var values = getArrayOf
745
+ .apply(null, arguments)
746
+ .map(onPossibleParallellAsync);
701
747
  return new DexiePromise(function (resolve, reject) {
702
748
  values.map(function (value) { return DexiePromise.resolve(value).then(resolve, reject); });
703
749
  });
704
750
  },
705
751
  PSD: {
706
752
  get: function () { return PSD; },
707
- set: function (value) { return PSD = value; }
753
+ set: function (value) { return (PSD = value); },
708
754
  },
709
755
  totalEchoes: { get: function () { return totalEchoes; } },
710
756
  newPSD: newScope,
711
757
  usePSD: usePSD,
712
758
  scheduler: {
713
759
  get: function () { return asap; },
714
- set: function (value) { asap = value; }
760
+ set: function (value) {
761
+ asap = value;
762
+ },
715
763
  },
716
764
  rejectionMapper: {
717
765
  get: function () { return rejectionMapper; },
718
- set: function (value) { rejectionMapper = value; }
766
+ set: function (value) {
767
+ rejectionMapper = value;
768
+ },
719
769
  },
720
770
  follow: function (fn, zoneProps) {
721
771
  return new DexiePromise(function (resolve, reject) {
@@ -726,40 +776,51 @@
726
776
  psd.finalize = callBoth(function () {
727
777
  var _this = this;
728
778
  run_at_end_of_this_or_next_physical_tick(function () {
729
- _this.unhandleds.length === 0 ? resolve() : reject(_this.unhandleds[0]);
779
+ _this.unhandleds.length === 0
780
+ ? resolve()
781
+ : reject(_this.unhandleds[0]);
730
782
  });
731
783
  }, psd.finalize);
732
784
  fn();
733
785
  }, zoneProps, resolve, reject);
734
786
  });
735
- }
787
+ },
736
788
  });
737
789
  if (NativePromise) {
738
790
  if (NativePromise.allSettled)
739
- setProp(DexiePromise, "allSettled", function () {
740
- var possiblePromises = getArrayOf.apply(null, arguments).map(onPossibleParallellAsync);
791
+ setProp(DexiePromise, 'allSettled', function () {
792
+ var possiblePromises = getArrayOf
793
+ .apply(null, arguments)
794
+ .map(onPossibleParallellAsync);
741
795
  return new DexiePromise(function (resolve) {
742
796
  if (possiblePromises.length === 0)
743
797
  resolve([]);
744
798
  var remaining = possiblePromises.length;
745
799
  var results = new Array(remaining);
746
- possiblePromises.forEach(function (p, i) { return DexiePromise.resolve(p).then(function (value) { return results[i] = { status: "fulfilled", value: value }; }, function (reason) { return results[i] = { status: "rejected", reason: reason }; })
747
- .then(function () { return --remaining || resolve(results); }); });
800
+ possiblePromises.forEach(function (p, i) {
801
+ return DexiePromise.resolve(p)
802
+ .then(function (value) { return (results[i] = { status: 'fulfilled', value: value }); }, function (reason) { return (results[i] = { status: 'rejected', reason: reason }); })
803
+ .then(function () { return --remaining || resolve(results); });
804
+ });
748
805
  });
749
806
  });
750
807
  if (NativePromise.any && typeof AggregateError !== 'undefined')
751
- setProp(DexiePromise, "any", function () {
752
- var possiblePromises = getArrayOf.apply(null, arguments).map(onPossibleParallellAsync);
808
+ setProp(DexiePromise, 'any', function () {
809
+ var possiblePromises = getArrayOf
810
+ .apply(null, arguments)
811
+ .map(onPossibleParallellAsync);
753
812
  return new DexiePromise(function (resolve, reject) {
754
813
  if (possiblePromises.length === 0)
755
814
  reject(new AggregateError([]));
756
815
  var remaining = possiblePromises.length;
757
816
  var failures = new Array(remaining);
758
- possiblePromises.forEach(function (p, i) { return DexiePromise.resolve(p).then(function (value) { return resolve(value); }, function (failure) {
759
- failures[i] = failure;
760
- if (!--remaining)
761
- reject(new AggregateError(failures));
762
- }); });
817
+ possiblePromises.forEach(function (p, i) {
818
+ return DexiePromise.resolve(p).then(function (value) { return resolve(value); }, function (failure) {
819
+ failures[i] = failure;
820
+ if (!--remaining)
821
+ reject(new AggregateError(failures));
822
+ });
823
+ });
763
824
  });
764
825
  });
765
826
  if (NativePromise.withResolvers)
@@ -775,9 +836,9 @@
775
836
  var shouldExecuteTick = promise._lib && beginMicroTickScope();
776
837
  if (value && typeof value.then === 'function') {
777
838
  executePromiseTask(promise, function (resolve, reject) {
778
- value instanceof DexiePromise ?
779
- value._then(resolve, reject) :
780
- value.then(resolve, reject);
839
+ value instanceof DexiePromise
840
+ ? value._then(resolve, reject)
841
+ : value.then(resolve, reject);
781
842
  });
782
843
  }
783
844
  else {
@@ -840,7 +901,10 @@
840
901
  var ret, value = promise._value;
841
902
  if (!promise._state && rejectingErrors.length)
842
903
  rejectingErrors = [];
843
- ret = debug && promise._consoleTask ? promise._consoleTask.run(function () { return cb(value); }) : cb(value);
904
+ ret =
905
+ debug && promise._consoleTask
906
+ ? promise._consoleTask.run(function () { return cb(value); })
907
+ : cb(value);
844
908
  if (!promise._state && rejectingErrors.indexOf(value) === -1) {
845
909
  markErrorAsHandled(promise);
846
910
  }
@@ -951,16 +1015,22 @@
951
1015
  psd.global = false;
952
1016
  psd.id = ++zone_id_counter;
953
1017
  globalPSD.env;
954
- psd.env = patchGlobalPromise ? {
955
- Promise: DexiePromise,
956
- PromiseProp: { value: DexiePromise, configurable: true, writable: true },
957
- all: DexiePromise.all,
958
- race: DexiePromise.race,
959
- allSettled: DexiePromise.allSettled,
960
- any: DexiePromise.any,
961
- resolve: DexiePromise.resolve,
962
- reject: DexiePromise.reject,
963
- } : {};
1018
+ psd.env = patchGlobalPromise
1019
+ ? {
1020
+ Promise: DexiePromise,
1021
+ PromiseProp: {
1022
+ value: DexiePromise,
1023
+ configurable: true,
1024
+ writable: true,
1025
+ },
1026
+ all: DexiePromise.all,
1027
+ race: DexiePromise.race,
1028
+ allSettled: DexiePromise.allSettled,
1029
+ any: DexiePromise.any,
1030
+ resolve: DexiePromise.resolve,
1031
+ reject: DexiePromise.reject,
1032
+ }
1033
+ : {};
964
1034
  if (props)
965
1035
  extend(psd, props);
966
1036
  ++parent.ref;
@@ -991,7 +1061,9 @@
991
1061
  incrementExpectedAwaits = decrementExpectedAwaits = nop;
992
1062
  }
993
1063
  function onPossibleParallellAsync(possiblePromise) {
994
- if (task.echoes && possiblePromise && possiblePromise.constructor === NativePromise) {
1064
+ if (task.echoes &&
1065
+ possiblePromise &&
1066
+ possiblePromise.constructor === NativePromise) {
995
1067
  incrementExpectedAwaits();
996
1068
  return possiblePromise.then(function (x) {
997
1069
  decrementExpectedAwaits();
@@ -1018,7 +1090,9 @@
1018
1090
  }
1019
1091
  function switchToZone(targetZone, bEnteringZone) {
1020
1092
  var currentZone = PSD;
1021
- if (bEnteringZone ? task.echoes && (!zoneEchoes++ || targetZone !== PSD) : zoneEchoes && (!--zoneEchoes || targetZone !== PSD)) {
1093
+ if (bEnteringZone
1094
+ ? task.echoes && (!zoneEchoes++ || targetZone !== PSD)
1095
+ : zoneEchoes && (!--zoneEchoes || targetZone !== PSD)) {
1022
1096
  queueMicrotask(bEnteringZone ? zoneEnterEcho.bind(null, targetZone) : zoneLeaveEcho);
1023
1097
  }
1024
1098
  if (targetZone === PSD)
@@ -1044,16 +1118,18 @@
1044
1118
  }
1045
1119
  function snapShot() {
1046
1120
  var GlobalPromise = _global.Promise;
1047
- return patchGlobalPromise ? {
1048
- Promise: GlobalPromise,
1049
- PromiseProp: Object.getOwnPropertyDescriptor(_global, "Promise"),
1050
- all: GlobalPromise.all,
1051
- race: GlobalPromise.race,
1052
- allSettled: GlobalPromise.allSettled,
1053
- any: GlobalPromise.any,
1054
- resolve: GlobalPromise.resolve,
1055
- reject: GlobalPromise.reject,
1056
- } : {};
1121
+ return patchGlobalPromise
1122
+ ? {
1123
+ Promise: GlobalPromise,
1124
+ PromiseProp: Object.getOwnPropertyDescriptor(_global, 'Promise'),
1125
+ all: GlobalPromise.all,
1126
+ race: GlobalPromise.race,
1127
+ allSettled: GlobalPromise.allSettled,
1128
+ any: GlobalPromise.any,
1129
+ resolve: GlobalPromise.resolve,
1130
+ reject: GlobalPromise.reject,
1131
+ }
1132
+ : {};
1057
1133
  }
1058
1134
  function usePSD(psd, fn, a1, a2, a3) {
1059
1135
  var outerScope = PSD;
@@ -1066,20 +1142,22 @@
1066
1142
  }
1067
1143
  }
1068
1144
  function nativeAwaitCompatibleWrap(fn, zone, possibleAwait, cleanup) {
1069
- return typeof fn !== 'function' ? fn : function () {
1070
- var outerZone = PSD;
1071
- if (possibleAwait)
1072
- incrementExpectedAwaits();
1073
- switchToZone(zone, true);
1074
- try {
1075
- return fn.apply(this, arguments);
1076
- }
1077
- finally {
1078
- switchToZone(outerZone, false);
1079
- if (cleanup)
1080
- queueMicrotask(decrementExpectedAwaits);
1081
- }
1082
- };
1145
+ return typeof fn !== 'function'
1146
+ ? fn
1147
+ : function () {
1148
+ var outerZone = PSD;
1149
+ if (possibleAwait)
1150
+ incrementExpectedAwaits();
1151
+ switchToZone(zone, true);
1152
+ try {
1153
+ return fn.apply(this, arguments);
1154
+ }
1155
+ finally {
1156
+ switchToZone(outerZone, false);
1157
+ if (cleanup)
1158
+ queueMicrotask(decrementExpectedAwaits);
1159
+ }
1160
+ };
1083
1161
  }
1084
1162
  function execInGlobalContext(cb) {
1085
1163
  if (Promise === NativePromise && task.echoes === 0) {
@@ -1096,8 +1174,16 @@
1096
1174
  }
1097
1175
  var rejection = DexiePromise.reject;
1098
1176
 
1099
- function tempTransaction(db, mode, storeNames, fn) {
1100
- if (!db.idbdb || (!db._state.openComplete && (!PSD.letThrough && !db._vip))) {
1177
+ function isWebKitInjectKeyError(ex) {
1178
+ return ((ex === null || ex === void 0 ? void 0 : ex.name) === 'UnknownError' &&
1179
+ typeof (ex === null || ex === void 0 ? void 0 : ex.message) === 'string' &&
1180
+ ex.message.includes('inject key'));
1181
+ }
1182
+ var WEBKIT_INJECT_KEY_MAX_RETRIES = 7;
1183
+ var WEBKIT_INJECT_KEY_BASE_DELAY_MS = 100;
1184
+ function tempTransaction(db, mode, storeNames, fn, _webkitRetry) {
1185
+ if (_webkitRetry === void 0) { _webkitRetry = 0; }
1186
+ if (!db.idbdb || (!db._state.openComplete && !PSD.letThrough && !db._vip)) {
1101
1187
  if (db._state.openComplete) {
1102
1188
  return rejection(new exceptions.DatabaseClosed(db._state.dbOpenError));
1103
1189
  }
@@ -1106,7 +1192,9 @@
1106
1192
  return rejection(new exceptions.DatabaseClosed());
1107
1193
  db.open().catch(nop);
1108
1194
  }
1109
- return db._state.dbReadyPromise.then(function () { return tempTransaction(db, mode, storeNames, fn); });
1195
+ return db._state.dbReadyPromise.then(function () {
1196
+ return tempTransaction(db, mode, storeNames, fn);
1197
+ });
1110
1198
  }
1111
1199
  else {
1112
1200
  var trans = db._createTransaction(mode, storeNames, db._dbSchema);
@@ -1115,45 +1203,66 @@
1115
1203
  db._state.PR1398_maxLoop = 3;
1116
1204
  }
1117
1205
  catch (ex) {
1118
- if (ex.name === errnames.InvalidState && db.isOpen() && --db._state.PR1398_maxLoop > 0) {
1206
+ if (ex.name === errnames.InvalidState &&
1207
+ db.isOpen() &&
1208
+ --db._state.PR1398_maxLoop > 0) {
1119
1209
  console.warn('Dexie: Need to reopen db');
1120
1210
  db.close({ disableAutoOpen: false });
1121
1211
  return db.open().then(function () { return tempTransaction(db, mode, storeNames, fn); });
1122
1212
  }
1123
1213
  return rejection(ex);
1124
1214
  }
1125
- return trans._promise(mode, function (resolve, reject) {
1215
+ return trans
1216
+ ._promise(mode, function (resolve, reject) {
1126
1217
  return newScope(function () {
1127
1218
  PSD.trans = trans;
1128
1219
  return fn(resolve, reject, trans);
1129
1220
  });
1130
- }).then(function (result) {
1221
+ })
1222
+ .then(function (result) {
1131
1223
  if (mode === 'readwrite')
1132
1224
  try {
1133
1225
  trans.idbtrans.commit();
1134
1226
  }
1135
1227
  catch (_a) { }
1136
- return mode === 'readonly' ? result : trans._completion.then(function () { return result; });
1228
+ return mode === 'readonly'
1229
+ ? result
1230
+ : trans._completion.then(function () { return result; });
1231
+ })
1232
+ .catch(function (ex) {
1233
+ if (isWebKitInjectKeyError(ex) &&
1234
+ _webkitRetry < WEBKIT_INJECT_KEY_MAX_RETRIES) {
1235
+ var delay_1 = WEBKIT_INJECT_KEY_BASE_DELAY_MS * Math.pow(1.5, _webkitRetry);
1236
+ if (_webkitRetry === 0) {
1237
+ console.warn('Dexie: WebKit "Cannot inject key" workaround — retrying transaction');
1238
+ }
1239
+ return new Promise(function (resolve) { return setTimeout(resolve, delay_1); }).then(function () {
1240
+ return tempTransaction(db, mode, storeNames, fn, _webkitRetry + 1);
1241
+ });
1242
+ }
1243
+ return rejection(ex);
1137
1244
  });
1138
1245
  }
1139
1246
  }
1140
1247
 
1141
- var DEXIE_VERSION = '4.4.1';
1248
+ var DEXIE_VERSION = '4.4.2-pr2297.2';
1142
1249
  var maxString = String.fromCharCode(65535);
1143
1250
  var minKey = -Infinity;
1144
- var INVALID_KEY_ARGUMENT = "Invalid key provided. Keys must be of type string, number, Date or Array<string | number | Date>.";
1145
- var STRING_EXPECTED = "String expected.";
1251
+ var INVALID_KEY_ARGUMENT = 'Invalid key provided. Keys must be of type string, number, Date or Array<string | number | Date>.';
1252
+ var STRING_EXPECTED = 'String expected.';
1146
1253
  var DEFAULT_MAX_CONNECTIONS = 1000;
1147
1254
  var DBNAMES_DB = '__dbnames';
1148
1255
  var READONLY = 'readonly';
1149
1256
  var READWRITE = 'readwrite';
1150
1257
 
1151
1258
  function combine(filter1, filter2) {
1152
- return filter1 ?
1153
- filter2 ?
1154
- function () { return filter1.apply(this, arguments) && filter2.apply(this, arguments); } :
1155
- filter1 :
1156
- filter2;
1259
+ return filter1
1260
+ ? filter2
1261
+ ? function () {
1262
+ return (filter1.apply(this, arguments) && filter2.apply(this, arguments));
1263
+ }
1264
+ : filter1
1265
+ : filter2;
1157
1266
  }
1158
1267
 
1159
1268
  var AnyRange = {
@@ -1161,13 +1270,13 @@
1161
1270
  lower: -Infinity,
1162
1271
  lowerOpen: false,
1163
1272
  upper: [[]],
1164
- upperOpen: false
1273
+ upperOpen: false,
1165
1274
  };
1166
1275
 
1167
1276
  function workaroundForUndefinedPrimKey(keyPath) {
1168
- return typeof keyPath === "string" && !/\./.test(keyPath)
1277
+ return typeof keyPath === 'string' && !/\./.test(keyPath)
1169
1278
  ? function (obj) {
1170
- if (obj[keyPath] === undefined && (keyPath in obj)) {
1279
+ if (obj[keyPath] === undefined && keyPath in obj) {
1171
1280
  obj = deepClone(obj);
1172
1281
  delete obj[keyPath];
1173
1282
  }
@@ -1272,11 +1381,11 @@
1272
1381
 
1273
1382
  var PropModification = (function () {
1274
1383
  function PropModification(spec) {
1275
- this["@@propmod"] = spec;
1384
+ this['@@propmod'] = spec;
1276
1385
  }
1277
1386
  PropModification.prototype.execute = function (value) {
1278
1387
  var _a;
1279
- var spec = this["@@propmod"];
1388
+ var spec = this['@@propmod'];
1280
1389
  if (spec.add !== undefined) {
1281
1390
  var term = spec.add;
1282
1391
  if (isArray(term)) {
@@ -1297,7 +1406,9 @@
1297
1406
  if (spec.remove !== undefined) {
1298
1407
  var subtrahend_1 = spec.remove;
1299
1408
  if (isArray(subtrahend_1)) {
1300
- return isArray(value) ? value.filter(function (item) { return !subtrahend_1.includes(item); }).sort() : [];
1409
+ return isArray(value)
1410
+ ? value.filter(function (item) { return !subtrahend_1.includes(item); }).sort()
1411
+ : [];
1301
1412
  }
1302
1413
  if (typeof subtrahend_1 === 'number')
1303
1414
  return Number(value) - subtrahend_1;
@@ -1312,7 +1423,9 @@
1312
1423
  throw new TypeError("Invalid subtrahend ".concat(subtrahend_1));
1313
1424
  }
1314
1425
  var prefixToReplace = (_a = spec.replacePrefix) === null || _a === void 0 ? void 0 : _a[0];
1315
- if (prefixToReplace && typeof value === 'string' && value.startsWith(prefixToReplace)) {
1426
+ if (prefixToReplace &&
1427
+ typeof value === 'string' &&
1428
+ value.startsWith(prefixToReplace)) {
1316
1429
  return spec.replacePrefix[1] + value.substring(prefixToReplace.length);
1317
1430
  }
1318
1431
  return value;
@@ -1346,19 +1459,24 @@
1346
1459
  Table.prototype._trans = function (mode, fn, writeLocked) {
1347
1460
  var trans = this._tx || PSD.trans;
1348
1461
  var tableName = this.name;
1349
- var task = debug && typeof console !== 'undefined' && console.createTask && console.createTask("Dexie: ".concat(mode === 'readonly' ? 'read' : 'write', " ").concat(this.name));
1462
+ var task = debug &&
1463
+ typeof console !== 'undefined' &&
1464
+ console.createTask &&
1465
+ console.createTask("Dexie: ".concat(mode === 'readonly' ? 'read' : 'write', " ").concat(this.name));
1350
1466
  function checkTableInTransaction(resolve, reject, trans) {
1351
1467
  if (!trans.schema[tableName])
1352
- throw new exceptions.NotFound("Table " + tableName + " not part of transaction");
1468
+ throw new exceptions.NotFound('Table ' + tableName + ' not part of transaction');
1353
1469
  return fn(trans.idbtrans, trans);
1354
1470
  }
1355
1471
  var wasRootExec = beginMicroTickScope();
1356
1472
  try {
1357
- var p = trans && trans.db._novip === this.db._novip ?
1358
- trans === PSD.trans ?
1359
- trans._promise(mode, checkTableInTransaction, writeLocked) :
1360
- newScope(function () { return trans._promise(mode, checkTableInTransaction, writeLocked); }, { trans: trans, transless: PSD.transless || PSD }) :
1361
- tempTransaction(this.db, mode, [this.name], checkTableInTransaction);
1473
+ var p = trans && trans.db._novip === this.db._novip
1474
+ ? trans === PSD.trans
1475
+ ? trans._promise(mode, checkTableInTransaction, writeLocked)
1476
+ : newScope(function () {
1477
+ return trans._promise(mode, checkTableInTransaction, writeLocked);
1478
+ }, { trans: trans, transless: PSD.transless || PSD })
1479
+ : tempTransaction(this.db, mode, [this.name], checkTableInTransaction);
1362
1480
  if (task) {
1363
1481
  p._consoleTask = task;
1364
1482
  p = p.catch(function (err) {
@@ -1380,7 +1498,8 @@
1380
1498
  if (keyOrCrit == null)
1381
1499
  return rejection(new exceptions.Type("Invalid argument to Table.get()"));
1382
1500
  return this._trans('readonly', function (trans) {
1383
- return _this.core.get({ trans: trans, key: keyOrCrit })
1501
+ return _this.core
1502
+ .get({ trans: trans, key: keyOrCrit })
1384
1503
  .then(function (res) { return _this.hook.reading.fire(res); });
1385
1504
  }).then(cb);
1386
1505
  };
@@ -1391,10 +1510,10 @@
1391
1510
  return new this.db.WhereClause(this, "[".concat(indexOrCrit.join('+'), "]"));
1392
1511
  var keyPaths = keys(indexOrCrit);
1393
1512
  if (keyPaths.length === 1)
1394
- return this
1395
- .where(keyPaths[0])
1396
- .equals(indexOrCrit[keyPaths[0]]);
1397
- var compoundIndex = this.schema.indexes.concat(this.schema.primKey).filter(function (ix) {
1513
+ return this.where(keyPaths[0]).equals(indexOrCrit[keyPaths[0]]);
1514
+ var compoundIndex = this.schema.indexes
1515
+ .concat(this.schema.primKey)
1516
+ .filter(function (ix) {
1398
1517
  if (ix.compound &&
1399
1518
  keyPaths.every(function (keyPath) { return ix.keyPath.indexOf(keyPath) >= 0; })) {
1400
1519
  for (var i = 0; i < keyPaths.length; ++i) {
@@ -1404,12 +1523,11 @@
1404
1523
  return true;
1405
1524
  }
1406
1525
  return false;
1407
- }).sort(function (a, b) { return a.keyPath.length - b.keyPath.length; })[0];
1526
+ })
1527
+ .sort(function (a, b) { return a.keyPath.length - b.keyPath.length; })[0];
1408
1528
  if (compoundIndex && this.db._maxKey !== maxString) {
1409
1529
  var keyPathsInValidOrder = compoundIndex.keyPath.slice(0, keyPaths.length);
1410
- return this
1411
- .where(keyPathsInValidOrder)
1412
- .equals(keyPathsInValidOrder.map(function (kp) { return indexOrCrit[kp]; }));
1530
+ return this.where(keyPathsInValidOrder).equals(keyPathsInValidOrder.map(function (kp) { return indexOrCrit[kp]; }));
1413
1531
  }
1414
1532
  if (!compoundIndex && debug)
1415
1533
  console.warn("The query ".concat(JSON.stringify(indexOrCrit), " on ").concat(this.name, " would benefit from a ") +
@@ -1424,21 +1542,24 @@
1424
1542
  var value = indexOrCrit[keyPath];
1425
1543
  return [
1426
1544
  prevIndex || index,
1427
- prevIndex || !index ?
1428
- combine(prevFilterFn, index && index.multi ?
1429
- function (x) {
1545
+ prevIndex || !index
1546
+ ? combine(prevFilterFn, index && index.multi
1547
+ ? function (x) {
1430
1548
  var prop = getByKeyPath(x, keyPath);
1431
- return isArray(prop) && prop.some(function (item) { return equals(value, item); });
1432
- } : function (x) { return equals(value, getByKeyPath(x, keyPath)); })
1433
- : prevFilterFn
1549
+ return (isArray(prop) &&
1550
+ prop.some(function (item) { return equals(value, item); }));
1551
+ }
1552
+ : function (x) { return equals(value, getByKeyPath(x, keyPath)); })
1553
+ : prevFilterFn,
1434
1554
  ];
1435
1555
  }, [null, null]), idx = _a[0], filterFunction = _a[1];
1436
- return idx ?
1437
- this.where(idx.name).equals(indexOrCrit[idx.keyPath])
1438
- .filter(filterFunction) :
1439
- compoundIndex ?
1440
- this.filter(filterFunction) :
1441
- this.where(keyPaths).equals('');
1556
+ return idx
1557
+ ? this.where(idx.name)
1558
+ .equals(indexOrCrit[idx.keyPath])
1559
+ .filter(filterFunction)
1560
+ : compoundIndex
1561
+ ? this.filter(filterFunction)
1562
+ : this.where(keyPaths).equals('');
1442
1563
  };
1443
1564
  Table.prototype.filter = function (filterFunction) {
1444
1565
  return this.toCollection().and(filterFunction);
@@ -1462,9 +1583,7 @@
1462
1583
  return new this.db.Collection(new this.db.WhereClause(this));
1463
1584
  };
1464
1585
  Table.prototype.orderBy = function (index) {
1465
- return new this.db.Collection(new this.db.WhereClause(this, isArray(index) ?
1466
- "[".concat(index.join('+'), "]") :
1467
- index));
1586
+ return new this.db.Collection(new this.db.WhereClause(this, isArray(index) ? "[".concat(index.join('+'), "]") : index));
1468
1587
  };
1469
1588
  Table.prototype.reverse = function () {
1470
1589
  return this.toCollection().reverse();
@@ -1479,17 +1598,23 @@
1479
1598
  return _super !== null && _super.apply(this, arguments) || this;
1480
1599
  }
1481
1600
  Object.defineProperty(class_1.prototype, "db", {
1482
- get: function () { return db; },
1601
+ get: function () {
1602
+ return db;
1603
+ },
1483
1604
  enumerable: false,
1484
1605
  configurable: true
1485
1606
  });
1486
- class_1.prototype.table = function () { return tableName; };
1607
+ class_1.prototype.table = function () {
1608
+ return tableName;
1609
+ };
1487
1610
  return class_1;
1488
1611
  }(constructor));
1489
1612
  }
1490
1613
  var inheritedProps = new Set();
1491
1614
  for (var proto = constructor.prototype; proto; proto = getProto(proto)) {
1492
- Object.getOwnPropertyNames(proto).forEach(function (propName) { return inheritedProps.add(propName); });
1615
+ Object.getOwnPropertyNames(proto).forEach(function (propName) {
1616
+ return inheritedProps.add(propName);
1617
+ });
1493
1618
  }
1494
1619
  var readHook = function (obj) {
1495
1620
  if (!obj)
@@ -1507,7 +1632,7 @@
1507
1632
  this.hook.reading.unsubscribe(this.schema.readHook);
1508
1633
  }
1509
1634
  this.schema.readHook = readHook;
1510
- this.hook("reading", readHook);
1635
+ this.hook('reading', readHook);
1511
1636
  return constructor;
1512
1637
  };
1513
1638
  Table.prototype.defineClass = function () {
@@ -1524,8 +1649,16 @@
1524
1649
  objToAdd = workaroundForUndefinedPrimKey(keyPath)(obj);
1525
1650
  }
1526
1651
  return this._trans('readwrite', function (trans) {
1527
- return _this.core.mutate({ trans: trans, type: 'add', keys: key != null ? [key] : null, values: [objToAdd] });
1528
- }).then(function (res) { return res.numFailures ? DexiePromise.reject(res.failures[0]) : res.lastResult; })
1652
+ return _this.core.mutate({
1653
+ trans: trans,
1654
+ type: 'add',
1655
+ keys: key != null ? [key] : null,
1656
+ values: [objToAdd],
1657
+ });
1658
+ })
1659
+ .then(function (res) {
1660
+ return res.numFailures ? DexiePromise.reject(res.failures[0]) : res.lastResult;
1661
+ })
1529
1662
  .then(function (lastResult) {
1530
1663
  if (keyPath) {
1531
1664
  try {
@@ -1545,14 +1678,18 @@
1545
1678
  applyUpdateSpec(obj, modifications);
1546
1679
  if (keyPath)
1547
1680
  setByKeyPath(obj, keyPath, key);
1548
- return _this.core.mutate({
1681
+ return _this.core
1682
+ .mutate({
1549
1683
  trans: trans,
1550
1684
  type: 'put',
1551
1685
  values: [obj],
1552
1686
  keys: [key],
1553
1687
  upsert: true,
1554
- updates: { keys: [key], changeSpecs: [modifications] }
1555
- }).then(function (res) { return res.numFailures ? DexiePromise.reject(res.failures[0]) : !!existing; });
1688
+ updates: { keys: [key], changeSpecs: [modifications] },
1689
+ })
1690
+ .then(function (res) {
1691
+ return res.numFailures ? DexiePromise.reject(res.failures[0]) : !!existing;
1692
+ });
1556
1693
  });
1557
1694
  });
1558
1695
  };
@@ -1560,11 +1697,11 @@
1560
1697
  if (typeof keyOrObject === 'object' && !isArray(keyOrObject)) {
1561
1698
  var key = getByKeyPath(keyOrObject, this.schema.primKey.keyPath);
1562
1699
  if (key === undefined)
1563
- return rejection(new exceptions.InvalidArgument("Given object does not contain its primary key"));
1564
- return this.where(":id").equals(key).modify(modifications);
1700
+ return rejection(new exceptions.InvalidArgument('Given object does not contain its primary key'));
1701
+ return this.where(':id').equals(key).modify(modifications);
1565
1702
  }
1566
1703
  else {
1567
- return this.where(":id").equals(keyOrObject).modify(modifications);
1704
+ return this.where(':id').equals(keyOrObject).modify(modifications);
1568
1705
  }
1569
1706
  };
1570
1707
  Table.prototype.put = function (obj, key) {
@@ -1574,8 +1711,17 @@
1574
1711
  if (keyPath && auto) {
1575
1712
  objToAdd = workaroundForUndefinedPrimKey(keyPath)(obj);
1576
1713
  }
1577
- return this._trans('readwrite', function (trans) { return _this.core.mutate({ trans: trans, type: 'put', values: [objToAdd], keys: key != null ? [key] : null }); })
1578
- .then(function (res) { return res.numFailures ? DexiePromise.reject(res.failures[0]) : res.lastResult; })
1714
+ return this._trans('readwrite', function (trans) {
1715
+ return _this.core.mutate({
1716
+ trans: trans,
1717
+ type: 'put',
1718
+ values: [objToAdd],
1719
+ keys: key != null ? [key] : null,
1720
+ });
1721
+ })
1722
+ .then(function (res) {
1723
+ return res.numFailures ? DexiePromise.reject(res.failures[0]) : res.lastResult;
1724
+ })
1579
1725
  .then(function (lastResult) {
1580
1726
  if (keyPath) {
1581
1727
  try {
@@ -1588,41 +1734,60 @@
1588
1734
  };
1589
1735
  Table.prototype.delete = function (key) {
1590
1736
  var _this = this;
1591
- return this._trans('readwrite', function (trans) { return _this.core.mutate({ trans: trans, type: 'delete', keys: [key] })
1592
- .then(function (res) { return builtInDeletionTrigger(_this, [key], res); })
1593
- .then(function (res) { return res.numFailures ? DexiePromise.reject(res.failures[0]) : undefined; }); });
1737
+ return this._trans('readwrite', function (trans) {
1738
+ return _this.core
1739
+ .mutate({ trans: trans, type: 'delete', keys: [key] })
1740
+ .then(function (res) { return builtInDeletionTrigger(_this, [key], res); })
1741
+ .then(function (res) {
1742
+ return res.numFailures ? DexiePromise.reject(res.failures[0]) : undefined;
1743
+ });
1744
+ });
1594
1745
  };
1595
1746
  Table.prototype.clear = function () {
1596
1747
  var _this = this;
1597
- return this._trans('readwrite', function (trans) { return _this.core.mutate({ trans: trans, type: 'deleteRange', range: AnyRange })
1598
- .then(function (res) { return builtInDeletionTrigger(_this, null, res); }); })
1599
- .then(function (res) { return res.numFailures ? DexiePromise.reject(res.failures[0]) : undefined; });
1748
+ return this._trans('readwrite', function (trans) {
1749
+ return _this.core
1750
+ .mutate({ trans: trans, type: 'deleteRange', range: AnyRange })
1751
+ .then(function (res) { return builtInDeletionTrigger(_this, null, res); });
1752
+ }).then(function (res) {
1753
+ return res.numFailures ? DexiePromise.reject(res.failures[0]) : undefined;
1754
+ });
1600
1755
  };
1601
1756
  Table.prototype.bulkGet = function (keys) {
1602
1757
  var _this = this;
1603
1758
  return this._trans('readonly', function (trans) {
1604
- return _this.core.getMany({
1759
+ return _this.core
1760
+ .getMany({
1605
1761
  keys: keys,
1606
- trans: trans
1607
- }).then(function (result) { return result.map(function (res) { return _this.hook.reading.fire(res); }); });
1762
+ trans: trans,
1763
+ })
1764
+ .then(function (result) { return result.map(function (res) { return _this.hook.reading.fire(res); }); });
1608
1765
  });
1609
1766
  };
1610
1767
  Table.prototype.bulkAdd = function (objects, keysOrOptions, options) {
1611
1768
  var _this = this;
1612
1769
  var keys = Array.isArray(keysOrOptions) ? keysOrOptions : undefined;
1613
- options = options || (keys ? undefined : keysOrOptions);
1770
+ options =
1771
+ options || (keys ? undefined : keysOrOptions);
1614
1772
  var wantResults = options ? options.allKeys : undefined;
1615
1773
  return this._trans('readwrite', function (trans) {
1616
1774
  var _a = _this.schema.primKey, auto = _a.auto, keyPath = _a.keyPath;
1617
1775
  if (keyPath && keys)
1618
- throw new exceptions.InvalidArgument("bulkAdd(): keys argument invalid on tables with inbound keys");
1776
+ throw new exceptions.InvalidArgument('bulkAdd(): keys argument invalid on tables with inbound keys');
1619
1777
  if (keys && keys.length !== objects.length)
1620
- throw new exceptions.InvalidArgument("Arguments objects and keys must have the same length");
1778
+ throw new exceptions.InvalidArgument('Arguments objects and keys must have the same length');
1621
1779
  var numObjects = objects.length;
1622
- var objectsToAdd = keyPath && auto ?
1623
- objects.map(workaroundForUndefinedPrimKey(keyPath)) :
1624
- objects;
1625
- return _this.core.mutate({ trans: trans, type: 'add', keys: keys, values: objectsToAdd, wantResults: wantResults })
1780
+ var objectsToAdd = keyPath && auto
1781
+ ? objects.map(workaroundForUndefinedPrimKey(keyPath))
1782
+ : objects;
1783
+ return _this.core
1784
+ .mutate({
1785
+ trans: trans,
1786
+ type: 'add',
1787
+ keys: keys,
1788
+ values: objectsToAdd,
1789
+ wantResults: wantResults,
1790
+ })
1626
1791
  .then(function (_a) {
1627
1792
  var numFailures = _a.numFailures, results = _a.results, lastResult = _a.lastResult, failures = _a.failures;
1628
1793
  var result = wantResults ? results : lastResult;
@@ -1635,19 +1800,27 @@
1635
1800
  Table.prototype.bulkPut = function (objects, keysOrOptions, options) {
1636
1801
  var _this = this;
1637
1802
  var keys = Array.isArray(keysOrOptions) ? keysOrOptions : undefined;
1638
- options = options || (keys ? undefined : keysOrOptions);
1803
+ options =
1804
+ options || (keys ? undefined : keysOrOptions);
1639
1805
  var wantResults = options ? options.allKeys : undefined;
1640
1806
  return this._trans('readwrite', function (trans) {
1641
1807
  var _a = _this.schema.primKey, auto = _a.auto, keyPath = _a.keyPath;
1642
1808
  if (keyPath && keys)
1643
- throw new exceptions.InvalidArgument("bulkPut(): keys argument invalid on tables with inbound keys");
1809
+ throw new exceptions.InvalidArgument('bulkPut(): keys argument invalid on tables with inbound keys');
1644
1810
  if (keys && keys.length !== objects.length)
1645
- throw new exceptions.InvalidArgument("Arguments objects and keys must have the same length");
1811
+ throw new exceptions.InvalidArgument('Arguments objects and keys must have the same length');
1646
1812
  var numObjects = objects.length;
1647
- var objectsToPut = keyPath && auto ?
1648
- objects.map(workaroundForUndefinedPrimKey(keyPath)) :
1649
- objects;
1650
- return _this.core.mutate({ trans: trans, type: 'put', keys: keys, values: objectsToPut, wantResults: wantResults })
1813
+ var objectsToPut = keyPath && auto
1814
+ ? objects.map(workaroundForUndefinedPrimKey(keyPath))
1815
+ : objects;
1816
+ return _this.core
1817
+ .mutate({
1818
+ trans: trans,
1819
+ type: 'put',
1820
+ keys: keys,
1821
+ values: objectsToPut,
1822
+ wantResults: wantResults,
1823
+ })
1651
1824
  .then(function (_a) {
1652
1825
  var numFailures = _a.numFailures, results = _a.results, lastResult = _a.lastResult, failures = _a.failures;
1653
1826
  var result = wantResults ? results : lastResult;
@@ -1697,8 +1870,8 @@
1697
1870
  values: resultObjs,
1698
1871
  updates: {
1699
1872
  keys: keys,
1700
- changeSpecs: changeSpecs
1701
- }
1873
+ changeSpecs: changeSpecs,
1874
+ },
1702
1875
  })
1703
1876
  .then(function (_a) {
1704
1877
  var numFailures = _a.numFailures, failures = _a.failures;
@@ -1722,7 +1895,8 @@
1722
1895
  var _this = this;
1723
1896
  var numKeys = keys.length;
1724
1897
  return this._trans('readwrite', function (trans) {
1725
- return _this.core.mutate({ trans: trans, type: 'delete', keys: keys })
1898
+ return _this.core
1899
+ .mutate({ trans: trans, type: 'delete', keys: keys })
1726
1900
  .then(function (res) { return builtInDeletionTrigger(_this, keys, res); });
1727
1901
  }).then(function (_a) {
1728
1902
  var numFailures = _a.numFailures, lastResult = _a.lastResult, failures = _a.failures;
@@ -1744,7 +1918,7 @@
1744
1918
  evs[eventName].subscribe.apply(null, args);
1745
1919
  return ctx;
1746
1920
  }
1747
- else if (typeof (eventName) === 'string') {
1921
+ else if (typeof eventName === 'string') {
1748
1922
  return evs[eventName];
1749
1923
  }
1750
1924
  };
@@ -1770,9 +1944,11 @@
1770
1944
  }
1771
1945
  },
1772
1946
  unsubscribe: function (cb) {
1773
- context.subscribers = context.subscribers.filter(function (fn) { return fn !== cb; });
1947
+ context.subscribers = context.subscribers.filter(function (fn) {
1948
+ return fn !== cb;
1949
+ });
1774
1950
  context.fire = context.subscribers.reduce(chainFunction, defaultFunction);
1775
- }
1951
+ },
1776
1952
  };
1777
1953
  evs[eventName] = rv[eventName] = context;
1778
1954
  return context;
@@ -1796,7 +1972,7 @@
1796
1972
  });
1797
1973
  }
1798
1974
  else
1799
- throw new exceptions.InvalidArgument("Invalid event config");
1975
+ throw new exceptions.InvalidArgument('Invalid event config');
1800
1976
  });
1801
1977
  }
1802
1978
  }
@@ -1812,18 +1988,20 @@
1812
1988
  this._tx = trans;
1813
1989
  this.name = name;
1814
1990
  this.schema = tableSchema;
1815
- this.hook = db._allTables[name] ? db._allTables[name].hook : Events(null, {
1816
- "creating": [hookCreatingChain, nop],
1817
- "reading": [pureFunctionChain, mirror],
1818
- "updating": [hookUpdatingChain, nop],
1819
- "deleting": [hookDeletingChain, nop]
1820
- });
1991
+ this.hook = db._allTables[name]
1992
+ ? db._allTables[name].hook
1993
+ : Events(null, {
1994
+ creating: [hookCreatingChain, nop],
1995
+ reading: [pureFunctionChain, mirror],
1996
+ updating: [hookUpdatingChain, nop],
1997
+ deleting: [hookDeletingChain, nop],
1998
+ });
1821
1999
  });
1822
2000
  }
1823
2001
 
1824
2002
  function isPlainKeyRange(ctx, ignoreLimitFilter) {
1825
- return !(ctx.filter || ctx.algorithm || ctx.or) &&
1826
- (ignoreLimitFilter ? ctx.justLimit : !ctx.replayFilter);
2003
+ return (!(ctx.filter || ctx.algorithm || ctx.or) &&
2004
+ (ignoreLimitFilter ? ctx.justLimit : !ctx.replayFilter));
1827
2005
  }
1828
2006
  function addFilter(ctx, fn) {
1829
2007
  ctx.filter = combine(ctx.filter, fn);
@@ -1841,7 +2019,11 @@
1841
2019
  return coreSchema.primaryKey;
1842
2020
  var index = coreSchema.getIndexByKeyPath(ctx.index);
1843
2021
  if (!index)
1844
- throw new exceptions.Schema("KeyPath " + ctx.index + " on object store " + coreSchema.name + " is not indexed");
2022
+ throw new exceptions.Schema('KeyPath ' +
2023
+ ctx.index +
2024
+ ' on object store ' +
2025
+ coreSchema.name +
2026
+ ' is not indexed');
1845
2027
  return index;
1846
2028
  }
1847
2029
  function openCursor(ctx, coreTable, trans) {
@@ -1853,19 +2035,22 @@
1853
2035
  unique: !!ctx.unique,
1854
2036
  query: {
1855
2037
  index: index,
1856
- range: ctx.range
1857
- }
2038
+ range: ctx.range,
2039
+ },
1858
2040
  });
1859
2041
  }
1860
2042
  function iter(ctx, fn, coreTrans, coreTable) {
1861
- var filter = ctx.replayFilter ? combine(ctx.filter, ctx.replayFilter()) : ctx.filter;
2043
+ var filter = ctx.replayFilter
2044
+ ? combine(ctx.filter, ctx.replayFilter())
2045
+ : ctx.filter;
1862
2046
  if (!ctx.or) {
1863
2047
  return iterate(openCursor(ctx, coreTable, coreTrans), combine(ctx.algorithm, filter), fn, !ctx.keysOnly && ctx.valueMapper);
1864
2048
  }
1865
2049
  else {
1866
2050
  var set_1 = {};
1867
2051
  var union = function (item, cursor, advance) {
1868
- if (!filter || filter(cursor, advance, function (result) { return cursor.stop(result); }, function (err) { return cursor.fail(err); })) {
2052
+ if (!filter ||
2053
+ filter(cursor, advance, function (result) { return cursor.stop(result); }, function (err) { return cursor.fail(err); })) {
1869
2054
  var primaryKey = cursor.primaryKey;
1870
2055
  var key = '' + primaryKey;
1871
2056
  if (key === '[object ArrayBuffer]')
@@ -1878,7 +2063,7 @@
1878
2063
  };
1879
2064
  return Promise.all([
1880
2065
  ctx.or._iterate(union, coreTrans),
1881
- iterate(openCursor(ctx, coreTable, coreTrans), ctx.algorithm, union, !ctx.keysOnly && ctx.valueMapper)
2066
+ iterate(openCursor(ctx, coreTable, coreTrans), ctx.algorithm, union, !ctx.keysOnly && ctx.valueMapper),
1882
2067
  ]);
1883
2068
  }
1884
2069
  }
@@ -1889,8 +2074,15 @@
1889
2074
  if (cursor) {
1890
2075
  return cursor.start(function () {
1891
2076
  var c = function () { return cursor.continue(); };
1892
- if (!filter || filter(cursor, function (advancer) { return c = advancer; }, function (val) { cursor.stop(val); c = nop; }, function (e) { cursor.fail(e); c = nop; }))
1893
- wrappedFn(cursor.value, cursor, function (advancer) { return c = advancer; });
2077
+ if (!filter ||
2078
+ filter(cursor, function (advancer) { return (c = advancer); }, function (val) {
2079
+ cursor.stop(val);
2080
+ c = nop;
2081
+ }, function (e) {
2082
+ cursor.fail(e);
2083
+ c = nop;
2084
+ }))
2085
+ wrappedFn(cursor.value, cursor, function (advancer) { return (c = advancer); });
1894
2086
  c();
1895
2087
  });
1896
2088
  }
@@ -1902,15 +2094,15 @@
1902
2094
  }
1903
2095
  Collection.prototype._read = function (fn, cb) {
1904
2096
  var ctx = this._ctx;
1905
- return ctx.error ?
1906
- ctx.table._trans(null, rejection.bind(null, ctx.error)) :
1907
- ctx.table._trans('readonly', fn).then(cb);
2097
+ return ctx.error
2098
+ ? ctx.table._trans(null, rejection.bind(null, ctx.error))
2099
+ : ctx.table._trans('readonly', fn).then(cb);
1908
2100
  };
1909
2101
  Collection.prototype._write = function (fn) {
1910
2102
  var ctx = this._ctx;
1911
- return ctx.error ?
1912
- ctx.table._trans(null, rejection.bind(null, ctx.error)) :
1913
- ctx.table._trans('readwrite', fn, "locked");
2103
+ return ctx.error
2104
+ ? ctx.table._trans(null, rejection.bind(null, ctx.error))
2105
+ : ctx.table._trans('readwrite', fn, 'locked');
1914
2106
  };
1915
2107
  Collection.prototype._addAlgorithm = function (fn) {
1916
2108
  var ctx = this._ctx;
@@ -1940,18 +2132,22 @@
1940
2132
  var ctx = _this._ctx;
1941
2133
  var coreTable = ctx.table.core;
1942
2134
  if (isPlainKeyRange(ctx, true)) {
1943
- return coreTable.count({
2135
+ return coreTable
2136
+ .count({
1944
2137
  trans: trans,
1945
2138
  query: {
1946
2139
  index: getIndexOrStore(ctx, coreTable.schema),
1947
- range: ctx.range
1948
- }
1949
- }).then(function (count) { return Math.min(count, ctx.limit); });
2140
+ range: ctx.range,
2141
+ },
2142
+ })
2143
+ .then(function (count) { return Math.min(count, ctx.limit); });
1950
2144
  }
1951
2145
  else {
1952
2146
  var count = 0;
1953
- return iter(ctx, function () { ++count; return false; }, trans, coreTable)
1954
- .then(function () { return count; });
2147
+ return iter(ctx, function () {
2148
+ ++count;
2149
+ return false;
2150
+ }, trans, coreTable).then(function () { return count; });
1955
2151
  }
1956
2152
  }).then(cb);
1957
2153
  };
@@ -1962,13 +2158,13 @@
1962
2158
  return getval(obj[parts[i]], i - 1);
1963
2159
  return obj[lastPart];
1964
2160
  }
1965
- var order = this._ctx.dir === "next" ? 1 : -1;
2161
+ var order = this._ctx.dir === 'next' ? 1 : -1;
1966
2162
  function sorter(a, b) {
1967
2163
  var aVal = getval(a, lastIndex), bVal = getval(b, lastIndex);
1968
2164
  return cmp(aVal, bVal) * order;
1969
2165
  }
1970
2166
  return this.toArray(function (a) {
1971
- return a.sort(sorter);
2167
+ return a.slice().sort(sorter);
1972
2168
  }).then(cb);
1973
2169
  };
1974
2170
  Collection.prototype.toArray = function (cb) {
@@ -1978,16 +2174,18 @@
1978
2174
  if (isPlainKeyRange(ctx, true) && ctx.limit > 0) {
1979
2175
  var valueMapper_1 = ctx.valueMapper;
1980
2176
  var index = getIndexOrStore(ctx, ctx.table.core.schema);
1981
- return ctx.table.core.query({
2177
+ return ctx.table.core
2178
+ .query({
1982
2179
  trans: trans,
1983
2180
  limit: ctx.limit,
1984
2181
  values: true,
1985
2182
  direction: ctx.dir === 'prev' ? 'prev' : undefined,
1986
2183
  query: {
1987
2184
  index: index,
1988
- range: ctx.range
1989
- }
1990
- }).then(function (_a) {
2185
+ range: ctx.range,
2186
+ },
2187
+ })
2188
+ .then(function (_a) {
1991
2189
  var result = _a.result;
1992
2190
  return valueMapper_1 ? result.map(valueMapper_1) : result;
1993
2191
  });
@@ -2024,7 +2222,7 @@
2024
2222
  else {
2025
2223
  addReplayFilter(ctx, function () {
2026
2224
  var offsetLeft = offset;
2027
- return function () { return (--offsetLeft < 0); };
2225
+ return function () { return --offsetLeft < 0; };
2028
2226
  });
2029
2227
  }
2030
2228
  return this;
@@ -2054,7 +2252,11 @@
2054
2252
  return this;
2055
2253
  };
2056
2254
  Collection.prototype.first = function (cb) {
2057
- return this.limit(1).toArray(function (a) { return a[0]; }).then(cb);
2255
+ return this.limit(1)
2256
+ .toArray(function (a) {
2257
+ return a[0];
2258
+ })
2259
+ .then(cb);
2058
2260
  };
2059
2261
  Collection.prototype.last = function (cb) {
2060
2262
  return this.reverse().first(cb);
@@ -2073,7 +2275,7 @@
2073
2275
  return new this.db.WhereClause(this._ctx.table, indexName, this);
2074
2276
  };
2075
2277
  Collection.prototype.reverse = function () {
2076
- this._ctx.dir = (this._ctx.dir === "prev" ? "next" : "prev");
2278
+ this._ctx.dir = this._ctx.dir === 'prev' ? 'next' : 'prev';
2077
2279
  if (this._ondirectionchange)
2078
2280
  this._ondirectionchange(this._ctx.dir);
2079
2281
  return this;
@@ -2084,16 +2286,20 @@
2084
2286
  Collection.prototype.eachKey = function (cb) {
2085
2287
  var ctx = this._ctx;
2086
2288
  ctx.keysOnly = !ctx.isMatch;
2087
- return this.each(function (val, cursor) { cb(cursor.key, cursor); });
2289
+ return this.each(function (val, cursor) {
2290
+ cb(cursor.key, cursor);
2291
+ });
2088
2292
  };
2089
2293
  Collection.prototype.eachUniqueKey = function (cb) {
2090
- this._ctx.unique = "unique";
2294
+ this._ctx.unique = 'unique';
2091
2295
  return this.eachKey(cb);
2092
2296
  };
2093
2297
  Collection.prototype.eachPrimaryKey = function (cb) {
2094
2298
  var ctx = this._ctx;
2095
2299
  ctx.keysOnly = !ctx.isMatch;
2096
- return this.each(function (val, cursor) { cb(cursor.primaryKey, cursor); });
2300
+ return this.each(function (val, cursor) {
2301
+ cb(cursor.primaryKey, cursor);
2302
+ });
2097
2303
  };
2098
2304
  Collection.prototype.keys = function (cb) {
2099
2305
  var ctx = this._ctx;
@@ -2101,9 +2307,11 @@
2101
2307
  var a = [];
2102
2308
  return this.each(function (item, cursor) {
2103
2309
  a.push(cursor.key);
2104
- }).then(function () {
2310
+ })
2311
+ .then(function () {
2105
2312
  return a;
2106
- }).then(cb);
2313
+ })
2314
+ .then(cb);
2107
2315
  };
2108
2316
  Collection.prototype.primaryKeys = function (cb) {
2109
2317
  var ctx = this._ctx;
@@ -2117,28 +2325,36 @@
2117
2325
  direction: ctx.dir === 'prev' ? 'prev' : undefined,
2118
2326
  query: {
2119
2327
  index: index,
2120
- range: ctx.range
2121
- }
2328
+ range: ctx.range,
2329
+ },
2122
2330
  });
2123
- }).then(function (_a) {
2331
+ })
2332
+ .then(function (_a) {
2124
2333
  var result = _a.result;
2125
2334
  return result;
2126
- }).then(cb);
2335
+ })
2336
+ .then(cb);
2127
2337
  }
2128
2338
  ctx.keysOnly = !ctx.isMatch;
2129
2339
  var a = [];
2130
2340
  return this.each(function (item, cursor) {
2131
2341
  a.push(cursor.primaryKey);
2132
- }).then(function () {
2342
+ })
2343
+ .then(function () {
2133
2344
  return a;
2134
- }).then(cb);
2345
+ })
2346
+ .then(cb);
2135
2347
  };
2136
2348
  Collection.prototype.uniqueKeys = function (cb) {
2137
- this._ctx.unique = "unique";
2349
+ this._ctx.unique = 'unique';
2138
2350
  return this.keys(cb);
2139
2351
  };
2140
2352
  Collection.prototype.firstKey = function (cb) {
2141
- return this.limit(1).keys(function (a) { return a[0]; }).then(cb);
2353
+ return this.limit(1)
2354
+ .keys(function (a) {
2355
+ return a[0];
2356
+ })
2357
+ .then(cb);
2142
2358
  };
2143
2359
  Collection.prototype.lastKey = function (cb) {
2144
2360
  return this.reverse().firstKey(cb);
@@ -2173,7 +2389,8 @@
2173
2389
  var modifyChunkSize = _this.db._options.modifyChunkSize;
2174
2390
  if (modifyChunkSize) {
2175
2391
  if (typeof modifyChunkSize == 'object') {
2176
- limit = modifyChunkSize[coreTable.name] || modifyChunkSize['*'] || 200;
2392
+ limit =
2393
+ modifyChunkSize[coreTable.name] || modifyChunkSize['*'] || 200;
2177
2394
  }
2178
2395
  else {
2179
2396
  limit = modifyChunkSize;
@@ -2191,21 +2408,25 @@
2191
2408
  }
2192
2409
  };
2193
2410
  var isUnconditionalDelete = changes === deleteCallback;
2194
- return _this.clone().primaryKeys().then(function (keys) {
2411
+ return _this.clone()
2412
+ .primaryKeys()
2413
+ .then(function (keys) {
2195
2414
  var criteria = isPlainKeyRange(ctx) &&
2196
2415
  ctx.limit === Infinity &&
2197
2416
  (typeof changes !== 'function' || isUnconditionalDelete) && {
2198
2417
  index: ctx.index,
2199
- range: ctx.range
2418
+ range: ctx.range,
2200
2419
  };
2201
2420
  var nextChunk = function (offset) {
2202
2421
  var count = Math.min(limit, keys.length - offset);
2203
2422
  var keysInChunk = keys.slice(offset, offset + count);
2204
- return (isUnconditionalDelete ? Promise.resolve([]) : coreTable.getMany({
2205
- trans: trans,
2206
- keys: keysInChunk,
2207
- cache: "immutable"
2208
- })).then(function (values) {
2423
+ return (isUnconditionalDelete
2424
+ ? Promise.resolve([])
2425
+ : coreTable.getMany({
2426
+ trans: trans,
2427
+ keys: keysInChunk,
2428
+ cache: 'immutable',
2429
+ })).then(function (values) {
2209
2430
  var addValues = [];
2210
2431
  var putValues = [];
2211
2432
  var putKeys = outbound ? [] : null;
@@ -2215,13 +2436,14 @@
2215
2436
  var origValue = values[i];
2216
2437
  var ctx_1 = {
2217
2438
  value: deepClone(origValue),
2218
- primKey: keys[offset + i]
2439
+ primKey: keys[offset + i],
2219
2440
  };
2220
2441
  if (modifyer.call(ctx_1, ctx_1.value, ctx_1) !== false) {
2221
2442
  if (ctx_1.value == null) {
2222
2443
  deleteKeys.push(keys[offset + i]);
2223
2444
  }
2224
- else if (!outbound && cmp(extractKey(origValue), extractKey(ctx_1.value)) !== 0) {
2445
+ else if (!outbound &&
2446
+ cmp(extractKey(origValue), extractKey(ctx_1.value)) !== 0) {
2225
2447
  deleteKeys.push(keys[offset + i]);
2226
2448
  addValues.push(ctx_1.value);
2227
2449
  }
@@ -2233,38 +2455,53 @@
2233
2455
  }
2234
2456
  }
2235
2457
  return Promise.resolve(addValues.length > 0 &&
2236
- coreTable.mutate({ trans: trans, type: 'add', values: addValues })
2458
+ coreTable
2459
+ .mutate({ trans: trans, type: 'add', values: addValues })
2237
2460
  .then(function (res) {
2238
2461
  for (var pos in res.failures) {
2239
2462
  deleteKeys.splice(parseInt(pos), 1);
2240
2463
  }
2241
2464
  applyMutateResult(addValues.length, res);
2242
- })).then(function () { return (putValues.length > 0 || (criteria && typeof changes === 'object')) &&
2243
- coreTable.mutate({
2244
- trans: trans,
2245
- type: 'put',
2246
- keys: putKeys,
2247
- values: putValues,
2248
- criteria: criteria,
2249
- changeSpec: typeof changes !== 'function'
2250
- && changes,
2251
- isAdditionalChunk: offset > 0
2252
- }).then(function (res) { return applyMutateResult(putValues.length, res); }); }).then(function () { return (deleteKeys.length > 0 || (criteria && isUnconditionalDelete)) &&
2253
- coreTable.mutate({
2254
- trans: trans,
2255
- type: 'delete',
2256
- keys: deleteKeys,
2257
- criteria: criteria,
2258
- isAdditionalChunk: offset > 0
2259
- }).then(function (res) { return builtInDeletionTrigger(ctx.table, deleteKeys, res); })
2260
- .then(function (res) { return applyMutateResult(deleteKeys.length, res); }); }).then(function () {
2261
- return keys.length > offset + count && nextChunk(offset + limit);
2465
+ }))
2466
+ .then(function () {
2467
+ return (putValues.length > 0 ||
2468
+ (criteria && typeof changes === 'object')) &&
2469
+ coreTable
2470
+ .mutate({
2471
+ trans: trans,
2472
+ type: 'put',
2473
+ keys: putKeys,
2474
+ values: putValues,
2475
+ criteria: criteria,
2476
+ changeSpec: typeof changes !== 'function' && changes,
2477
+ isAdditionalChunk: offset > 0,
2478
+ })
2479
+ .then(function (res) { return applyMutateResult(putValues.length, res); });
2480
+ })
2481
+ .then(function () {
2482
+ return (deleteKeys.length > 0 ||
2483
+ (criteria && isUnconditionalDelete)) &&
2484
+ coreTable
2485
+ .mutate({
2486
+ trans: trans,
2487
+ type: 'delete',
2488
+ keys: deleteKeys,
2489
+ criteria: criteria,
2490
+ isAdditionalChunk: offset > 0,
2491
+ })
2492
+ .then(function (res) {
2493
+ return builtInDeletionTrigger(ctx.table, deleteKeys, res);
2494
+ })
2495
+ .then(function (res) { return applyMutateResult(deleteKeys.length, res); });
2496
+ })
2497
+ .then(function () {
2498
+ return (keys.length > offset + count && nextChunk(offset + limit));
2262
2499
  });
2263
2500
  });
2264
2501
  };
2265
2502
  return nextChunk(0).then(function () {
2266
2503
  if (totalFailures.length > 0)
2267
- throw new ModifyError("Error modifying one or more objects", totalFailures, successCount, failedKeys);
2504
+ throw new ModifyError('Error modifying one or more objects', totalFailures, successCount, failedKeys);
2268
2505
  return keys.length;
2269
2506
  });
2270
2507
  });
@@ -2279,12 +2516,15 @@
2279
2516
  return this._write(function (trans) {
2280
2517
  var primaryKey = ctx.table.core.schema.primaryKey;
2281
2518
  var coreRange = range;
2282
- return ctx.table.core.count({ trans: trans, query: { index: primaryKey, range: coreRange } }).then(function (count) {
2283
- return ctx.table.core.mutate({ trans: trans, type: 'deleteRange', range: coreRange })
2519
+ return ctx.table.core
2520
+ .count({ trans: trans, query: { index: primaryKey, range: coreRange } })
2521
+ .then(function (count) {
2522
+ return ctx.table.core
2523
+ .mutate({ trans: trans, type: 'deleteRange', range: coreRange })
2284
2524
  .then(function (_a) {
2285
2525
  var failures = _a.failures, numFailures = _a.numFailures;
2286
2526
  if (numFailures)
2287
- throw new ModifyError("Could not delete some values", Object.keys(failures).map(function (pos) { return failures[pos]; }), count - numFailures);
2527
+ throw new ModifyError('Could not delete some values', Object.keys(failures).map(function (pos) { return failures[pos]; }), count - numFailures);
2288
2528
  return count - numFailures;
2289
2529
  });
2290
2530
  });
@@ -2294,7 +2534,7 @@
2294
2534
  };
2295
2535
  return Collection;
2296
2536
  }());
2297
- var deleteCallback = function (value, ctx) { return ctx.value = null; };
2537
+ var deleteCallback = function (value, ctx) { return (ctx.value = null); };
2298
2538
 
2299
2539
  function createCollectionConstructor(db) {
2300
2540
  return makeClassConstructor(Collection.prototype, function Collection(whereClause, keyRangeGenerator) {
@@ -2313,11 +2553,13 @@
2313
2553
  this._ctx = {
2314
2554
  table: table,
2315
2555
  index: whereCtx.index,
2316
- isPrimKey: (!whereCtx.index || (table.schema.primKey.keyPath && whereCtx.index === table.schema.primKey.name)),
2556
+ isPrimKey: !whereCtx.index ||
2557
+ (table.schema.primKey.keyPath &&
2558
+ whereCtx.index === table.schema.primKey.name),
2317
2559
  range: keyRange,
2318
2560
  keysOnly: false,
2319
- dir: "next",
2320
- unique: "",
2561
+ dir: 'next',
2562
+ unique: '',
2321
2563
  algorithm: null,
2322
2564
  filter: null,
2323
2565
  replayFilter: null,
@@ -2327,7 +2569,7 @@
2327
2569
  limit: Infinity,
2328
2570
  error: error,
2329
2571
  or: whereCtx.or,
2330
- valueMapper: readingHook !== mirror ? readingHook : null
2572
+ valueMapper: readingHook !== mirror ? readingHook : null,
2331
2573
  };
2332
2574
  });
2333
2575
  }
@@ -2340,24 +2582,24 @@
2340
2582
  }
2341
2583
 
2342
2584
  function fail(collectionOrWhereClause, err, T) {
2343
- var collection = collectionOrWhereClause instanceof WhereClause ?
2344
- new collectionOrWhereClause.Collection(collectionOrWhereClause) :
2345
- collectionOrWhereClause;
2585
+ var collection = collectionOrWhereClause instanceof WhereClause
2586
+ ? new collectionOrWhereClause.Collection(collectionOrWhereClause)
2587
+ : collectionOrWhereClause;
2346
2588
  collection._ctx.error = T ? new T(err) : new TypeError(err);
2347
2589
  return collection;
2348
2590
  }
2349
2591
  function emptyCollection(whereClause) {
2350
- return new whereClause.Collection(whereClause, function () { return rangeEqual(""); }).limit(0);
2592
+ return new whereClause.Collection(whereClause, function () { return rangeEqual(''); }).limit(0);
2351
2593
  }
2352
2594
  function upperFactory(dir) {
2353
- return dir === "next" ?
2354
- function (s) { return s.toUpperCase(); } :
2355
- function (s) { return s.toLowerCase(); };
2595
+ return dir === 'next'
2596
+ ? function (s) { return s.toUpperCase(); }
2597
+ : function (s) { return s.toLowerCase(); };
2356
2598
  }
2357
2599
  function lowerFactory(dir) {
2358
- return dir === "next" ?
2359
- function (s) { return s.toLowerCase(); } :
2360
- function (s) { return s.toUpperCase(); };
2600
+ return dir === 'next'
2601
+ ? function (s) { return s.toLowerCase(); }
2602
+ : function (s) { return s.toUpperCase(); };
2361
2603
  }
2362
2604
  function nextCasing(key, lowerKey, upperNeedle, lowerNeedle, cmp, dir) {
2363
2605
  var length = Math.min(key.length, lowerNeedle.length);
@@ -2376,11 +2618,13 @@
2376
2618
  if (cmp(key[i], lwrKeyChar) < 0)
2377
2619
  llp = i;
2378
2620
  }
2379
- if (length < lowerNeedle.length && dir === "next")
2621
+ if (length < lowerNeedle.length && dir === 'next')
2380
2622
  return key + upperNeedle.substr(key.length);
2381
- if (length < key.length && dir === "prev")
2623
+ if (length < key.length && dir === 'prev')
2382
2624
  return key.substr(0, upperNeedle.length);
2383
- return (llp < 0 ? null : key.substr(0, llp) + lowerNeedle[llp] + upperNeedle.substr(llp + 1));
2625
+ return llp < 0
2626
+ ? null
2627
+ : key.substr(0, llp) + lowerNeedle[llp] + upperNeedle.substr(llp + 1);
2384
2628
  }
2385
2629
  function addIgnoreCaseAlgorithm(whereClause, match, needles, suffix) {
2386
2630
  var upper, lower, compare, upperNeedles, lowerNeedles, direction, nextKeySuffix, needlesLen = needles.length;
@@ -2390,19 +2634,27 @@
2390
2634
  function initDirection(dir) {
2391
2635
  upper = upperFactory(dir);
2392
2636
  lower = lowerFactory(dir);
2393
- compare = (dir === "next" ? simpleCompare : simpleCompareReverse);
2394
- var needleBounds = needles.map(function (needle) {
2637
+ compare = dir === 'next' ? simpleCompare : simpleCompareReverse;
2638
+ var needleBounds = needles
2639
+ .map(function (needle) {
2395
2640
  return { lower: lower(needle), upper: upper(needle) };
2396
- }).sort(function (a, b) {
2641
+ })
2642
+ .sort(function (a, b) {
2397
2643
  return compare(a.lower, b.lower);
2398
2644
  });
2399
- upperNeedles = needleBounds.map(function (nb) { return nb.upper; });
2400
- lowerNeedles = needleBounds.map(function (nb) { return nb.lower; });
2645
+ upperNeedles = needleBounds.map(function (nb) {
2646
+ return nb.upper;
2647
+ });
2648
+ lowerNeedles = needleBounds.map(function (nb) {
2649
+ return nb.lower;
2650
+ });
2401
2651
  direction = dir;
2402
- nextKeySuffix = (dir === "next" ? "" : suffix);
2652
+ nextKeySuffix = dir === 'next' ? '' : suffix;
2403
2653
  }
2404
- initDirection("next");
2405
- var c = new whereClause.Collection(whereClause, function () { return createRange(upperNeedles[0], lowerNeedles[needlesLen - 1] + suffix); });
2654
+ initDirection('next');
2655
+ var c = new whereClause.Collection(whereClause, function () {
2656
+ return createRange(upperNeedles[0], lowerNeedles[needlesLen - 1] + suffix);
2657
+ });
2406
2658
  c._ondirectionchange = function (direction) {
2407
2659
  initDirection(direction);
2408
2660
  };
@@ -2421,12 +2673,15 @@
2421
2673
  var casing = nextCasing(key, lowerKey, upperNeedles[i], lowerNeedles[i], compare, direction);
2422
2674
  if (casing === null && lowestPossibleCasing === null)
2423
2675
  firstPossibleNeedle = i + 1;
2424
- else if (lowestPossibleCasing === null || compare(lowestPossibleCasing, casing) > 0) {
2676
+ else if (lowestPossibleCasing === null ||
2677
+ compare(lowestPossibleCasing, casing) > 0) {
2425
2678
  lowestPossibleCasing = casing;
2426
2679
  }
2427
2680
  }
2428
2681
  if (lowestPossibleCasing !== null) {
2429
- advance(function () { cursor.continue(lowestPossibleCasing + nextKeySuffix); });
2682
+ advance(function () {
2683
+ cursor.continue(lowestPossibleCasing + nextKeySuffix);
2684
+ });
2430
2685
  }
2431
2686
  else {
2432
2687
  advance(resolve);
@@ -2442,14 +2697,14 @@
2442
2697
  lower: lower,
2443
2698
  upper: upper,
2444
2699
  lowerOpen: lowerOpen,
2445
- upperOpen: upperOpen
2700
+ upperOpen: upperOpen,
2446
2701
  };
2447
2702
  }
2448
2703
  function rangeEqual(value) {
2449
2704
  return {
2450
2705
  type: 1 ,
2451
2706
  lower: value,
2452
- upper: value
2707
+ upper: value,
2453
2708
  };
2454
2709
  }
2455
2710
 
@@ -2467,10 +2722,14 @@
2467
2722
  includeLower = includeLower !== false;
2468
2723
  includeUpper = includeUpper === true;
2469
2724
  try {
2470
- if ((this._cmp(lower, upper) > 0) ||
2471
- (this._cmp(lower, upper) === 0 && (includeLower || includeUpper) && !(includeLower && includeUpper)))
2725
+ if (this._cmp(lower, upper) > 0 ||
2726
+ (this._cmp(lower, upper) === 0 &&
2727
+ (includeLower || includeUpper) &&
2728
+ !(includeLower && includeUpper)))
2472
2729
  return emptyCollection(this);
2473
- return new this.Collection(this, function () { return createRange(lower, upper, !includeLower, !includeUpper); });
2730
+ return new this.Collection(this, function () {
2731
+ return createRange(lower, upper, !includeLower, !includeUpper);
2732
+ });
2474
2733
  }
2475
2734
  catch (e) {
2476
2735
  return fail(this, INVALID_KEY_ARGUMENT);
@@ -2489,12 +2748,16 @@
2489
2748
  WhereClause.prototype.aboveOrEqual = function (value) {
2490
2749
  if (value == null)
2491
2750
  return fail(this, INVALID_KEY_ARGUMENT);
2492
- return new this.Collection(this, function () { return createRange(value, undefined, false); });
2751
+ return new this.Collection(this, function () {
2752
+ return createRange(value, undefined, false);
2753
+ });
2493
2754
  };
2494
2755
  WhereClause.prototype.below = function (value) {
2495
2756
  if (value == null)
2496
2757
  return fail(this, INVALID_KEY_ARGUMENT);
2497
- return new this.Collection(this, function () { return createRange(undefined, value, false, true); });
2758
+ return new this.Collection(this, function () {
2759
+ return createRange(undefined, value, false, true);
2760
+ });
2498
2761
  };
2499
2762
  WhereClause.prototype.belowOrEqual = function (value) {
2500
2763
  if (value == null)
@@ -2507,18 +2770,18 @@
2507
2770
  return this.between(str, str + maxString, true, true);
2508
2771
  };
2509
2772
  WhereClause.prototype.startsWithIgnoreCase = function (str) {
2510
- if (str === "")
2773
+ if (str === '')
2511
2774
  return this.startsWith(str);
2512
2775
  return addIgnoreCaseAlgorithm(this, function (x, a) { return x.indexOf(a[0]) === 0; }, [str], maxString);
2513
2776
  };
2514
2777
  WhereClause.prototype.equalsIgnoreCase = function (str) {
2515
- return addIgnoreCaseAlgorithm(this, function (x, a) { return x === a[0]; }, [str], "");
2778
+ return addIgnoreCaseAlgorithm(this, function (x, a) { return x === a[0]; }, [str], '');
2516
2779
  };
2517
2780
  WhereClause.prototype.anyOfIgnoreCase = function () {
2518
2781
  var set = getArrayOf.apply(NO_CHAR_ARRAY, arguments);
2519
2782
  if (set.length === 0)
2520
2783
  return emptyCollection(this);
2521
- return addIgnoreCaseAlgorithm(this, function (x, a) { return a.indexOf(x) !== -1; }, set, "");
2784
+ return addIgnoreCaseAlgorithm(this, function (x, a) { return a.indexOf(x) !== -1; }, set, '');
2522
2785
  };
2523
2786
  WhereClause.prototype.startsWithAnyOfIgnoreCase = function () {
2524
2787
  var set = getArrayOf.apply(NO_CHAR_ARRAY, arguments);
@@ -2538,11 +2801,11 @@
2538
2801
  }
2539
2802
  if (set.length === 0)
2540
2803
  return emptyCollection(this);
2541
- var c = new this.Collection(this, function () { return createRange(set[0], set[set.length - 1]); });
2804
+ var c = new this.Collection(this, function () {
2805
+ return createRange(set[0], set[set.length - 1]);
2806
+ });
2542
2807
  c._ondirectionchange = function (direction) {
2543
- compare = (direction === "next" ?
2544
- _this._ascending :
2545
- _this._descending);
2808
+ compare = direction === 'next' ? _this._ascending : _this._descending;
2546
2809
  set.sort(compare);
2547
2810
  };
2548
2811
  var i = 0;
@@ -2559,14 +2822,19 @@
2559
2822
  return true;
2560
2823
  }
2561
2824
  else {
2562
- advance(function () { cursor.continue(set[i]); });
2825
+ advance(function () {
2826
+ cursor.continue(set[i]);
2827
+ });
2563
2828
  return false;
2564
2829
  }
2565
2830
  });
2566
2831
  return c;
2567
2832
  };
2568
2833
  WhereClause.prototype.notEqual = function (value) {
2569
- return this.inAnyRange([[minKey, value], [value, this.db._maxKey]], { includeLowers: false, includeUppers: false });
2834
+ return this.inAnyRange([
2835
+ [minKey, value],
2836
+ [value, this.db._maxKey],
2837
+ ], { includeLowers: false, includeUppers: false });
2570
2838
  };
2571
2839
  WhereClause.prototype.noneOf = function () {
2572
2840
  var set = getArrayOf.apply(NO_CHAR_ARRAY, arguments);
@@ -2578,11 +2846,14 @@
2578
2846
  catch (e) {
2579
2847
  return fail(this, INVALID_KEY_ARGUMENT);
2580
2848
  }
2581
- var ranges = set.reduce(function (res, val) { return res ?
2582
- res.concat([[res[res.length - 1][1], val]]) :
2583
- [[minKey, val]]; }, null);
2849
+ var ranges = set.reduce(function (res, val) {
2850
+ return res ? res.concat([[res[res.length - 1][1], val]]) : [[minKey, val]];
2851
+ }, null);
2584
2852
  ranges.push([set[set.length - 1], this.db._maxKey]);
2585
- return this.inAnyRange(ranges, { includeLowers: false, includeUppers: false });
2853
+ return this.inAnyRange(ranges, {
2854
+ includeLowers: false,
2855
+ includeUppers: false,
2856
+ });
2586
2857
  };
2587
2858
  WhereClause.prototype.inAnyRange = function (ranges, options) {
2588
2859
  var _this = this;
@@ -2594,7 +2865,7 @@
2594
2865
  range[1] !== undefined &&
2595
2866
  ascending(range[0], range[1]) <= 0;
2596
2867
  })) {
2597
- return fail(this, "First argument to inAnyRange() must be an Array of two-value Arrays [lower,upper] where upper must not be lower than lower", exceptions.InvalidArgument);
2868
+ return fail(this, 'First argument to inAnyRange() must be an Array of two-value Arrays [lower,upper] where upper must not be lower than lower', exceptions.InvalidArgument);
2598
2869
  }
2599
2870
  var includeLowers = !options || options.includeLowers !== false;
2600
2871
  var includeUppers = options && options.includeUppers === true;
@@ -2613,7 +2884,9 @@
2613
2884
  return ranges;
2614
2885
  }
2615
2886
  var sortDirection = ascending;
2616
- function rangeSorter(a, b) { return sortDirection(a[0], b[0]); }
2887
+ function rangeSorter(a, b) {
2888
+ return sortDirection(a[0], b[0]);
2889
+ }
2617
2890
  var set;
2618
2891
  try {
2619
2892
  set = ranges.reduce(addRange, []);
@@ -2623,19 +2896,21 @@
2623
2896
  return fail(this, INVALID_KEY_ARGUMENT);
2624
2897
  }
2625
2898
  var rangePos = 0;
2626
- var keyIsBeyondCurrentEntry = includeUppers ?
2627
- function (key) { return ascending(key, set[rangePos][1]) > 0; } :
2628
- function (key) { return ascending(key, set[rangePos][1]) >= 0; };
2629
- var keyIsBeforeCurrentEntry = includeLowers ?
2630
- function (key) { return descending(key, set[rangePos][0]) > 0; } :
2631
- function (key) { return descending(key, set[rangePos][0]) >= 0; };
2899
+ var keyIsBeyondCurrentEntry = includeUppers
2900
+ ? function (key) { return ascending(key, set[rangePos][1]) > 0; }
2901
+ : function (key) { return ascending(key, set[rangePos][1]) >= 0; };
2902
+ var keyIsBeforeCurrentEntry = includeLowers
2903
+ ? function (key) { return descending(key, set[rangePos][0]) > 0; }
2904
+ : function (key) { return descending(key, set[rangePos][0]) >= 0; };
2632
2905
  function keyWithinCurrentRange(key) {
2633
2906
  return !keyIsBeyondCurrentEntry(key) && !keyIsBeforeCurrentEntry(key);
2634
2907
  }
2635
2908
  var checkKey = keyIsBeyondCurrentEntry;
2636
- var c = new this.Collection(this, function () { return createRange(set[0][0], set[set.length - 1][1], !includeLowers, !includeUppers); });
2909
+ var c = new this.Collection(this, function () {
2910
+ return createRange(set[0][0], set[set.length - 1][1], !includeLowers, !includeUppers);
2911
+ });
2637
2912
  c._ondirectionchange = function (direction) {
2638
- if (direction === "next") {
2913
+ if (direction === 'next') {
2639
2914
  checkKey = keyIsBeyondCurrentEntry;
2640
2915
  sortDirection = ascending;
2641
2916
  }
@@ -2657,7 +2932,8 @@
2657
2932
  if (keyWithinCurrentRange(key)) {
2658
2933
  return true;
2659
2934
  }
2660
- else if (_this._cmp(key, set[rangePos][1]) === 0 || _this._cmp(key, set[rangePos][0]) === 0) {
2935
+ else if (_this._cmp(key, set[rangePos][1]) === 0 ||
2936
+ _this._cmp(key, set[rangePos][0]) === 0) {
2661
2937
  return false;
2662
2938
  }
2663
2939
  else {
@@ -2675,7 +2951,7 @@
2675
2951
  WhereClause.prototype.startsWithAnyOf = function () {
2676
2952
  var set = getArrayOf.apply(NO_CHAR_ARRAY, arguments);
2677
2953
  if (!set.every(function (s) { return typeof s === 'string'; })) {
2678
- return fail(this, "startsWithAnyOf() only works with strings");
2954
+ return fail(this, 'startsWithAnyOf() only works with strings');
2679
2955
  }
2680
2956
  if (set.length === 0)
2681
2957
  return emptyCollection(this);
@@ -2689,13 +2965,13 @@
2689
2965
  this.db = db;
2690
2966
  this._ctx = {
2691
2967
  table: table,
2692
- index: index === ":id" ? null : index,
2693
- or: orCollection
2968
+ index: index === ':id' ? null : index,
2969
+ or: orCollection,
2694
2970
  };
2695
2971
  this._cmp = this._ascending = cmp;
2696
2972
  this._descending = function (a, b) { return cmp(b, a); };
2697
- this._max = function (a, b) { return cmp(a, b) > 0 ? a : b; };
2698
- this._min = function (a, b) { return cmp(a, b) < 0 ? a : b; };
2973
+ this._max = function (a, b) { return (cmp(a, b) > 0 ? a : b); };
2974
+ this._min = function (a, b) { return (cmp(a, b) < 0 ? a : b); };
2699
2975
  this._IDBKeyRange = db._deps.IDBKeyRange;
2700
2976
  if (!this._IDBKeyRange)
2701
2977
  throw new exceptions.MissingAPI();
@@ -2757,9 +3033,9 @@
2757
3033
  assert(!this.idbtrans);
2758
3034
  if (!idbtrans && !idbdb) {
2759
3035
  switch (dbOpenError && dbOpenError.name) {
2760
- case "DatabaseClosedError":
3036
+ case 'DatabaseClosedError':
2761
3037
  throw new exceptions.DatabaseClosed(dbOpenError);
2762
- case "MissingAPIError":
3038
+ case 'MissingAPIError':
2763
3039
  throw new exceptions.MissingAPI(dbOpenError.message, dbOpenError);
2764
3040
  default:
2765
3041
  throw new exceptions.OpenFailed(dbOpenError);
@@ -2768,10 +3044,13 @@
2768
3044
  if (!this.active)
2769
3045
  throw new exceptions.TransactionInactive();
2770
3046
  assert(this._completion._state === null);
2771
- idbtrans = this.idbtrans = idbtrans ||
2772
- (this.db.core
2773
- ? this.db.core.transaction(this.storeNames, this.mode, { durability: this.chromeTransactionDurability })
2774
- : idbdb.transaction(this.storeNames, this.mode, { durability: this.chromeTransactionDurability }));
3047
+ idbtrans = this.idbtrans =
3048
+ idbtrans ||
3049
+ (this.db.core
3050
+ ? this.db.core.transaction(this.storeNames, this.mode, { durability: this.chromeTransactionDurability })
3051
+ : idbdb.transaction(this.storeNames, this.mode, {
3052
+ durability: this.chromeTransactionDurability,
3053
+ }));
2775
3054
  idbtrans.onerror = wrap(function (ev) {
2776
3055
  preventDefault(ev);
2777
3056
  _this._reject(idbtrans.error);
@@ -2780,13 +3059,13 @@
2780
3059
  preventDefault(ev);
2781
3060
  _this.active && _this._reject(new exceptions.Abort(idbtrans.error));
2782
3061
  _this.active = false;
2783
- _this.on("abort").fire(ev);
3062
+ _this.on('abort').fire(ev);
2784
3063
  });
2785
3064
  idbtrans.oncomplete = wrap(function () {
2786
3065
  _this.active = false;
2787
3066
  _this._resolve();
2788
3067
  if ('mutatedParts' in idbtrans) {
2789
- globalEvents.storagemutated.fire(idbtrans["mutatedParts"]);
3068
+ globalEvents.storagemutated.fire(idbtrans['mutatedParts']);
2790
3069
  }
2791
3070
  });
2792
3071
  return this;
@@ -2794,14 +3073,17 @@
2794
3073
  Transaction.prototype._promise = function (mode, fn, bWriteLock) {
2795
3074
  var _this = this;
2796
3075
  if (mode === 'readwrite' && this.mode !== 'readwrite')
2797
- return rejection(new exceptions.ReadOnly("Transaction is readonly"));
3076
+ return rejection(new exceptions.ReadOnly('Transaction is readonly'));
2798
3077
  if (!this.active)
2799
3078
  return rejection(new exceptions.TransactionInactive());
2800
3079
  if (this._locked()) {
2801
3080
  return new DexiePromise(function (resolve, reject) {
2802
- _this._blockedFuncs.push([function () {
3081
+ _this._blockedFuncs.push([
3082
+ function () {
2803
3083
  _this._promise(mode, fn, bWriteLock).then(resolve, reject);
2804
- }, PSD]);
3084
+ },
3085
+ PSD,
3086
+ ]);
2805
3087
  });
2806
3088
  }
2807
3089
  else if (bWriteLock) {
@@ -2843,14 +3125,16 @@
2843
3125
  (function spin() {
2844
3126
  ++root._spinCount;
2845
3127
  while (root._waitingQueue.length)
2846
- (root._waitingQueue.shift())();
3128
+ root._waitingQueue.shift()();
2847
3129
  if (root._waitingFor)
2848
3130
  store.get(-Infinity).onsuccess = spin;
2849
- }());
3131
+ })();
2850
3132
  }
2851
3133
  var currentWaitPromise = root._waitingFor;
2852
3134
  return new DexiePromise(function (resolve, reject) {
2853
- promise.then(function (res) { return root._waitingQueue.push(wrap(resolve.bind(null, res))); }, function (err) { return root._waitingQueue.push(wrap(reject.bind(null, err))); }).finally(function () {
3135
+ promise
3136
+ .then(function (res) { return root._waitingQueue.push(wrap(resolve.bind(null, res))); }, function (err) { return root._waitingQueue.push(wrap(reject.bind(null, err))); })
3137
+ .finally(function () {
2854
3138
  if (root._waitingFor === currentWaitPromise) {
2855
3139
  root._waitingFor = null;
2856
3140
  }
@@ -2866,12 +3150,12 @@
2866
3150
  }
2867
3151
  };
2868
3152
  Transaction.prototype.table = function (tableName) {
2869
- var memoizedTables = (this._memoizedTables || (this._memoizedTables = {}));
3153
+ var memoizedTables = this._memoizedTables || (this._memoizedTables = {});
2870
3154
  if (hasOwn(memoizedTables, tableName))
2871
3155
  return memoizedTables[tableName];
2872
3156
  var tableSchema = this.schema[tableName];
2873
3157
  if (!tableSchema) {
2874
- throw new exceptions.NotFound("Table " + tableName + " not part of transaction");
3158
+ throw new exceptions.NotFound('Table ' + tableName + ' not part of transaction');
2875
3159
  }
2876
3160
  var transactionBoundTable = new this.db.Table(tableName, tableSchema, this);
2877
3161
  transactionBoundTable.core = this.db.core.table(tableName);
@@ -2897,7 +3181,7 @@
2897
3181
  this.schema = dbschema;
2898
3182
  this.chromeTransactionDurability = chromeTransactionDurability;
2899
3183
  this.idbtrans = null;
2900
- this.on = Events(this, "complete", "error", "abort");
3184
+ this.on = Events(this, 'complete', 'error', 'abort');
2901
3185
  this.parent = parent || null;
2902
3186
  this.active = true;
2903
3187
  this._reculock = 0;
@@ -2918,9 +3202,9 @@
2918
3202
  var wasActive = _this.active;
2919
3203
  _this.active = false;
2920
3204
  _this.on.error.fire(e);
2921
- _this.parent ?
2922
- _this.parent._reject(e) :
2923
- wasActive && _this.idbtrans && _this.idbtrans.abort();
3205
+ _this.parent
3206
+ ? _this.parent._reject(e)
3207
+ : wasActive && _this.idbtrans && _this.idbtrans.abort();
2924
3208
  return rejection(e);
2925
3209
  });
2926
3210
  });
@@ -2934,14 +3218,19 @@
2934
3218
  multi: multi,
2935
3219
  auto: auto,
2936
3220
  compound: compound,
2937
- src: (unique && !isPrimKey ? '&' : '') + (multi ? '*' : '') + (auto ? "++" : "") + nameFromKeyPath(keyPath),
2938
- type: type
3221
+ src: (unique && !isPrimKey ? '&' : '') +
3222
+ (multi ? '*' : '') +
3223
+ (auto ? '++' : '') +
3224
+ nameFromKeyPath(keyPath),
3225
+ type: type,
2939
3226
  };
2940
3227
  }
2941
3228
  function nameFromKeyPath(keyPath) {
2942
- return typeof keyPath === 'string' ?
2943
- keyPath :
2944
- keyPath ? ('[' + [].join.call(keyPath, '+') + ']') : "";
3229
+ return typeof keyPath === 'string'
3230
+ ? keyPath
3231
+ : keyPath
3232
+ ? '[' + [].join.call(keyPath, '+') + ']'
3233
+ : '';
2945
3234
  }
2946
3235
 
2947
3236
  function createTableSchema(name, primKey, indexes) {
@@ -2995,22 +3284,22 @@
2995
3284
  }
2996
3285
  var _id_counter = 0;
2997
3286
  function getKeyPathAlias(keyPath) {
2998
- return keyPath == null ?
2999
- ":id" :
3000
- typeof keyPath === 'string' ?
3001
- keyPath :
3002
- "[".concat(keyPath.join('+'), "]");
3287
+ return keyPath == null
3288
+ ? ':id'
3289
+ : typeof keyPath === 'string'
3290
+ ? keyPath
3291
+ : "[".concat(keyPath.join('+'), "]");
3003
3292
  }
3004
3293
  function createDBCore(db, IdbKeyRange, tmpTrans) {
3005
3294
  function extractSchema(db, trans) {
3006
3295
  var tables = arrayify(db.objectStoreNames);
3007
- var tempStore = tables.length > 0
3008
- ? trans.objectStore(tables[0])
3009
- : {};
3296
+ var tempStore = tables.length > 0 ? trans.objectStore(tables[0]) : {};
3010
3297
  return {
3011
3298
  schema: {
3012
3299
  name: db.name,
3013
- tables: tables.map(function (table) { return trans.objectStore(table); }).map(function (store) {
3300
+ tables: tables
3301
+ .map(function (table) { return trans.objectStore(table); })
3302
+ .map(function (store) {
3014
3303
  var keyPath = store.keyPath, autoIncrement = store.autoIncrement;
3015
3304
  var compound = isArray(keyPath);
3016
3305
  var outbound = keyPath == null;
@@ -3025,9 +3314,10 @@
3025
3314
  keyPath: keyPath,
3026
3315
  autoIncrement: autoIncrement,
3027
3316
  unique: true,
3028
- extractKey: getKeyExtractor(keyPath)
3317
+ extractKey: getKeyExtractor(keyPath),
3029
3318
  },
3030
- indexes: arrayify(store.indexNames).map(function (indexName) { return store.index(indexName); })
3319
+ indexes: arrayify(store.indexNames)
3320
+ .map(function (indexName) { return store.index(indexName); })
3031
3321
  .map(function (index) {
3032
3322
  var name = index.name, unique = index.unique, multiEntry = index.multiEntry, keyPath = index.keyPath;
3033
3323
  var compound = isArray(keyPath);
@@ -3037,40 +3327,44 @@
3037
3327
  keyPath: keyPath,
3038
3328
  unique: unique,
3039
3329
  multiEntry: multiEntry,
3040
- extractKey: getKeyExtractor(keyPath)
3330
+ extractKey: getKeyExtractor(keyPath),
3041
3331
  };
3042
3332
  indexByKeyPath[getKeyPathAlias(keyPath)] = result;
3043
3333
  return result;
3044
3334
  }),
3045
- getIndexByKeyPath: function (keyPath) { return indexByKeyPath[getKeyPathAlias(keyPath)]; }
3335
+ getIndexByKeyPath: function (keyPath) {
3336
+ return indexByKeyPath[getKeyPathAlias(keyPath)];
3337
+ },
3046
3338
  };
3047
- indexByKeyPath[":id"] = result.primaryKey;
3339
+ indexByKeyPath[':id'] = result.primaryKey;
3048
3340
  if (keyPath != null) {
3049
3341
  indexByKeyPath[getKeyPathAlias(keyPath)] = result.primaryKey;
3050
3342
  }
3051
3343
  return result;
3052
- })
3344
+ }),
3053
3345
  },
3054
- hasGetAll: tables.length > 0 && ('getAll' in tempStore) &&
3055
- !(typeof navigator !== 'undefined' && /Safari/.test(navigator.userAgent) &&
3346
+ hasGetAll: tables.length > 0 &&
3347
+ 'getAll' in tempStore &&
3348
+ !(typeof navigator !== 'undefined' &&
3349
+ /Safari/.test(navigator.userAgent) &&
3056
3350
  !/(Chrome\/|Edge\/)/.test(navigator.userAgent) &&
3057
3351
  [].concat(navigator.userAgent.match(/Safari\/(\d*)/))[1] < 604),
3058
- hasIdb3Features: 'getAllRecords' in tempStore
3352
+ hasIdb3Features: 'getAllRecords' in tempStore,
3059
3353
  };
3060
3354
  }
3061
3355
  function makeIDBKeyRange(range) {
3062
3356
  if (range.type === 3 )
3063
3357
  return null;
3064
3358
  if (range.type === 4 )
3065
- throw new Error("Cannot convert never type to IDBKeyRange");
3359
+ throw new Error('Cannot convert never type to IDBKeyRange');
3066
3360
  var lower = range.lower, upper = range.upper, lowerOpen = range.lowerOpen, upperOpen = range.upperOpen;
3067
- var idbRange = lower === undefined ?
3068
- upper === undefined ?
3069
- null :
3070
- IdbKeyRange.upperBound(upper, !!upperOpen) :
3071
- upper === undefined ?
3072
- IdbKeyRange.lowerBound(lower, !!lowerOpen) :
3073
- IdbKeyRange.bound(lower, upper, !!lowerOpen, !!upperOpen);
3361
+ var idbRange = lower === undefined
3362
+ ? upper === undefined
3363
+ ? null
3364
+ : IdbKeyRange.upperBound(upper, !!upperOpen)
3365
+ : upper === undefined
3366
+ ? IdbKeyRange.lowerBound(lower, !!lowerOpen)
3367
+ : IdbKeyRange.bound(lower, upper, !!lowerOpen, !!upperOpen);
3074
3368
  return idbRange;
3075
3369
  }
3076
3370
  function createDbCoreTable(tableSchema) {
@@ -3081,15 +3375,20 @@
3081
3375
  resolve = wrap(resolve);
3082
3376
  var store = trans.objectStore(tableName);
3083
3377
  var outbound = store.keyPath == null;
3084
- var isAddOrPut = type === "put" || type === "add";
3378
+ var isAddOrPut = type === 'put' || type === 'add';
3085
3379
  if (!isAddOrPut && type !== 'delete' && type !== 'deleteRange')
3086
- throw new Error("Invalid operation type: " + type);
3380
+ throw new Error('Invalid operation type: ' + type);
3087
3381
  var length = (keys || values || { length: 1 }).length;
3088
3382
  if (keys && values && keys.length !== values.length) {
3089
- throw new Error("Given keys array must have same length as given values array.");
3383
+ throw new Error('Given keys array must have same length as given values array.');
3090
3384
  }
3091
3385
  if (length === 0)
3092
- return resolve({ numFailures: 0, failures: {}, results: [], lastResult: undefined });
3386
+ return resolve({
3387
+ numFailures: 0,
3388
+ failures: {},
3389
+ results: [],
3390
+ lastResult: undefined,
3391
+ });
3093
3392
  var req;
3094
3393
  var reqs = [];
3095
3394
  var failures = [];
@@ -3100,29 +3399,34 @@
3100
3399
  };
3101
3400
  if (type === 'deleteRange') {
3102
3401
  if (range.type === 4 )
3103
- return resolve({ numFailures: numFailures, failures: failures, results: [], lastResult: undefined });
3402
+ return resolve({
3403
+ numFailures: numFailures,
3404
+ failures: failures,
3405
+ results: [],
3406
+ lastResult: undefined,
3407
+ });
3104
3408
  if (range.type === 3 )
3105
- reqs.push(req = store.clear());
3409
+ reqs.push((req = store.clear()));
3106
3410
  else
3107
- reqs.push(req = store.delete(makeIDBKeyRange(range)));
3411
+ reqs.push((req = store.delete(makeIDBKeyRange(range))));
3108
3412
  }
3109
3413
  else {
3110
- var _a = isAddOrPut ?
3111
- outbound ?
3112
- [values, keys] :
3113
- [values, null] :
3114
- [keys, null], args1 = _a[0], args2 = _a[1];
3414
+ var _a = isAddOrPut
3415
+ ? outbound
3416
+ ? [values, keys]
3417
+ : [values, null]
3418
+ : [keys, null], args1 = _a[0], args2 = _a[1];
3115
3419
  if (isAddOrPut) {
3116
3420
  for (var i = 0; i < length; ++i) {
3117
- reqs.push(req = (args2 && args2[i] !== undefined ?
3118
- store[type](args1[i], args2[i]) :
3119
- store[type](args1[i])));
3421
+ reqs.push((req = (args2 && args2[i] !== undefined
3422
+ ? store[type](args1[i], args2[i])
3423
+ : store[type](args1[i]))));
3120
3424
  req.onerror = errorHandler;
3121
3425
  }
3122
3426
  }
3123
3427
  else {
3124
3428
  for (var i = 0; i < length; ++i) {
3125
- reqs.push(req = store[type](args1[i]));
3429
+ reqs.push((req = store[type](args1[i])));
3126
3430
  req.onerror = errorHandler;
3127
3431
  }
3128
3432
  }
@@ -3133,8 +3437,8 @@
3133
3437
  resolve({
3134
3438
  numFailures: numFailures,
3135
3439
  failures: failures,
3136
- results: type === "delete" ? keys : reqs.map(function (req) { return req.result; }),
3137
- lastResult: lastResult
3440
+ results: type === 'delete' ? keys : reqs.map(function (req) { return req.result; }),
3441
+ lastResult: lastResult,
3138
3442
  });
3139
3443
  };
3140
3444
  req.onerror = function (event) {
@@ -3150,19 +3454,17 @@
3150
3454
  resolve = wrap(resolve);
3151
3455
  var index = query.index, range = query.range;
3152
3456
  var store = trans.objectStore(tableName);
3153
- var source = index.isPrimaryKey ?
3154
- store :
3155
- store.index(index.name);
3156
- var direction = reverse ?
3157
- unique ?
3158
- "prevunique" :
3159
- "prev" :
3160
- unique ?
3161
- "nextunique" :
3162
- "next";
3163
- var req = values || !('openKeyCursor' in source) ?
3164
- source.openCursor(makeIDBKeyRange(range), direction) :
3165
- source.openKeyCursor(makeIDBKeyRange(range), direction);
3457
+ var source = index.isPrimaryKey ? store : store.index(index.name);
3458
+ var direction = reverse
3459
+ ? unique
3460
+ ? 'prevunique'
3461
+ : 'prev'
3462
+ : unique
3463
+ ? 'nextunique'
3464
+ : 'next';
3465
+ var req = values || !('openKeyCursor' in source)
3466
+ ? source.openCursor(makeIDBKeyRange(range), direction)
3467
+ : source.openKeyCursor(makeIDBKeyRange(range), direction);
3166
3468
  req.onerror = eventRejectHandler(reject);
3167
3469
  req.onsuccess = wrap(function (ev) {
3168
3470
  var cursor = req.result;
@@ -3177,15 +3479,25 @@
3177
3479
  if (_cursorContinuePrimaryKey)
3178
3480
  _cursorContinuePrimaryKey = _cursorContinuePrimaryKey.bind(cursor);
3179
3481
  var _cursorAdvance = cursor.advance.bind(cursor);
3180
- var doThrowCursorIsNotStarted = function () { throw new Error("Cursor not started"); };
3181
- var doThrowCursorIsStopped = function () { throw new Error("Cursor not stopped"); };
3482
+ var doThrowCursorIsNotStarted = function () {
3483
+ throw new Error('Cursor not started');
3484
+ };
3485
+ var doThrowCursorIsStopped = function () {
3486
+ throw new Error('Cursor not stopped');
3487
+ };
3182
3488
  cursor.trans = trans;
3183
- cursor.stop = cursor.continue = cursor.continuePrimaryKey = cursor.advance = doThrowCursorIsNotStarted;
3489
+ cursor.stop =
3490
+ cursor.continue =
3491
+ cursor.continuePrimaryKey =
3492
+ cursor.advance =
3493
+ doThrowCursorIsNotStarted;
3184
3494
  cursor.fail = wrap(reject);
3185
3495
  cursor.next = function () {
3186
3496
  var _this = this;
3187
3497
  var gotOne = 1;
3188
- return this.start(function () { return gotOne-- ? _this.continue() : _this.stop(); }).then(function () { return _this; });
3498
+ return this.start(function () {
3499
+ return gotOne-- ? _this.continue() : _this.stop();
3500
+ }).then(function () { return _this; });
3189
3501
  };
3190
3502
  cursor.start = function (callback) {
3191
3503
  var iterationPromise = new Promise(function (resolveIteration, rejectIteration) {
@@ -3193,7 +3505,11 @@
3193
3505
  req.onerror = eventRejectHandler(rejectIteration);
3194
3506
  cursor.fail = rejectIteration;
3195
3507
  cursor.stop = function (value) {
3196
- cursor.stop = cursor.continue = cursor.continuePrimaryKey = cursor.advance = doThrowCursorIsStopped;
3508
+ cursor.stop =
3509
+ cursor.continue =
3510
+ cursor.continuePrimaryKey =
3511
+ cursor.advance =
3512
+ doThrowCursorIsStopped;
3197
3513
  resolveIteration(value);
3198
3514
  };
3199
3515
  });
@@ -3208,7 +3524,9 @@
3208
3524
  }
3209
3525
  else {
3210
3526
  cursor.done = true;
3211
- cursor.start = function () { throw new Error("Cursor behind last entry"); };
3527
+ cursor.start = function () {
3528
+ throw new Error('Cursor behind last entry');
3529
+ };
3212
3530
  cursor.stop();
3213
3531
  }
3214
3532
  };
@@ -3244,26 +3562,28 @@
3244
3562
  var options = {
3245
3563
  query: idbKeyRange,
3246
3564
  count: nonInfinitLimit,
3247
- direction: direction
3565
+ direction: direction,
3248
3566
  };
3249
- var req = values ?
3250
- source.getAll(options) :
3251
- source.getAllKeys(options);
3567
+ var req = values
3568
+ ? source.getAll(options)
3569
+ : source.getAllKeys(options);
3252
3570
  req.onsuccess = function (event) { return resolve({ result: event.target.result }); };
3253
3571
  req.onerror = eventRejectHandler(reject);
3254
3572
  }
3255
3573
  else if (hasGetAll && direction === 'next') {
3256
- var req = values ?
3257
- source.getAll(idbKeyRange, nonInfinitLimit) :
3258
- source.getAllKeys(idbKeyRange, nonInfinitLimit);
3259
- req.onsuccess = function (event) { return resolve({ result: event.target.result }); };
3574
+ var req = values
3575
+ ? source.getAll(idbKeyRange, nonInfinitLimit)
3576
+ : source.getAllKeys(idbKeyRange, nonInfinitLimit);
3577
+ req.onsuccess = function (event) {
3578
+ return resolve({ result: event.target.result });
3579
+ };
3260
3580
  req.onerror = eventRejectHandler(reject);
3261
3581
  }
3262
3582
  else {
3263
3583
  var count_1 = 0;
3264
- var req_1 = values || !('openKeyCursor' in source) ?
3265
- source.openCursor(idbKeyRange, direction) :
3266
- source.openKeyCursor(idbKeyRange, direction);
3584
+ var req_1 = values || !('openKeyCursor' in source)
3585
+ ? source.openCursor(idbKeyRange, direction)
3586
+ : source.openKeyCursor(idbKeyRange, direction);
3267
3587
  var result_1 = [];
3268
3588
  req_1.onsuccess = function () {
3269
3589
  var cursor = req_1.result;
@@ -3335,18 +3655,22 @@
3335
3655
  var source = index.isPrimaryKey ? store : store.index(index.name);
3336
3656
  var idbKeyRange = makeIDBKeyRange(range);
3337
3657
  var req = idbKeyRange ? source.count(idbKeyRange) : source.count();
3338
- req.onsuccess = wrap(function (ev) { return resolve(ev.target.result); });
3658
+ req.onsuccess = wrap(function (ev) {
3659
+ return resolve(ev.target.result);
3660
+ });
3339
3661
  req.onerror = eventRejectHandler(reject);
3340
3662
  });
3341
- }
3663
+ },
3342
3664
  };
3343
3665
  }
3344
3666
  var _a = extractSchema(db, tmpTrans), schema = _a.schema, hasGetAll = _a.hasGetAll, hasIdb3Features = _a.hasIdb3Features;
3345
- var tables = schema.tables.map(function (tableSchema) { return createDbCoreTable(tableSchema); });
3667
+ var tables = schema.tables.map(function (tableSchema) {
3668
+ return createDbCoreTable(tableSchema);
3669
+ });
3346
3670
  var tableMap = {};
3347
- tables.forEach(function (table) { return tableMap[table.name] = table; });
3671
+ tables.forEach(function (table) { return (tableMap[table.name] = table); });
3348
3672
  return {
3349
- stack: "dbcore",
3673
+ stack: 'dbcore',
3350
3674
  transaction: db.transaction.bind(db),
3351
3675
  table: function (name) {
3352
3676
  var result = tableMap[name];
@@ -3356,7 +3680,7 @@
3356
3680
  },
3357
3681
  MIN_KEY: -Infinity,
3358
3682
  MAX_KEY: getMaxKey(IdbKeyRange),
3359
- schema: schema
3683
+ schema: schema,
3360
3684
  };
3361
3685
  }
3362
3686
 
@@ -3370,7 +3694,7 @@
3370
3694
  var IDBKeyRange = _a.IDBKeyRange; _a.indexedDB;
3371
3695
  var dbcore = createMiddlewareStack(createDBCore(idbdb, IDBKeyRange, tmpTrans), middlewares.dbcore);
3372
3696
  return {
3373
- dbcore: dbcore
3697
+ dbcore: dbcore,
3374
3698
  };
3375
3699
  }
3376
3700
  function generateMiddlewareStacks(db, tmpTrans) {
@@ -3393,13 +3717,20 @@
3393
3717
  var schema = dbschema[tableName];
3394
3718
  objs.forEach(function (obj) {
3395
3719
  var propDesc = getPropertyDescriptor(obj, tableName);
3396
- if (!propDesc || ("value" in propDesc && propDesc.value === undefined)) {
3720
+ if (!propDesc || ('value' in propDesc && propDesc.value === undefined)) {
3397
3721
  if (obj === db.Transaction.prototype || obj instanceof db.Transaction) {
3398
3722
  setProp(obj, tableName, {
3399
- get: function () { return this.table(tableName); },
3723
+ get: function () {
3724
+ return this.table(tableName);
3725
+ },
3400
3726
  set: function (value) {
3401
- defineProperty(this, tableName, { value: value, writable: true, configurable: true, enumerable: true });
3402
- }
3727
+ defineProperty(this, tableName, {
3728
+ value: value,
3729
+ writable: true,
3730
+ configurable: true,
3731
+ enumerable: true,
3732
+ });
3733
+ },
3403
3734
  });
3404
3735
  }
3405
3736
  else {
@@ -3422,8 +3753,9 @@
3422
3753
  }
3423
3754
  function runUpgraders(db, oldVersion, idbUpgradeTrans, reject) {
3424
3755
  var globalSchema = db._dbSchema;
3425
- if (idbUpgradeTrans.objectStoreNames.contains('$meta') && !globalSchema.$meta) {
3426
- globalSchema.$meta = createTableSchema("$meta", parseIndexSyntax("")[0], []);
3756
+ if (idbUpgradeTrans.objectStoreNames.contains('$meta') &&
3757
+ !globalSchema.$meta) {
3758
+ globalSchema.$meta = createTableSchema('$meta', parseIndexSyntax('')[0], []);
3427
3759
  db._storeNames.push('$meta');
3428
3760
  }
3429
3761
  var trans = db._createTransaction('readwrite', db._storeNames, globalSchema);
@@ -3444,15 +3776,20 @@
3444
3776
  else {
3445
3777
  generateMiddlewareStacks(db, idbUpgradeTrans);
3446
3778
  return getExistingVersion(db, trans, oldVersion)
3447
- .then(function (oldVersion) { return updateTablesAndIndexes(db, oldVersion, trans, idbUpgradeTrans); })
3779
+ .then(function (oldVersion) {
3780
+ return updateTablesAndIndexes(db, oldVersion, trans, idbUpgradeTrans);
3781
+ })
3448
3782
  .catch(rejectTransaction);
3449
3783
  }
3450
3784
  });
3451
3785
  }
3452
3786
  function patchCurrentVersion(db, idbUpgradeTrans) {
3453
3787
  createMissingTables(db._dbSchema, idbUpgradeTrans);
3454
- if (idbUpgradeTrans.db.version % 10 === 0 && !idbUpgradeTrans.objectStoreNames.contains('$meta')) {
3455
- idbUpgradeTrans.db.createObjectStore('$meta').add(Math.ceil((idbUpgradeTrans.db.version / 10) - 1), 'version');
3788
+ if (idbUpgradeTrans.db.version % 10 === 0 &&
3789
+ !idbUpgradeTrans.objectStoreNames.contains('$meta')) {
3790
+ idbUpgradeTrans.db
3791
+ .createObjectStore('$meta')
3792
+ .add(Math.ceil(idbUpgradeTrans.db.version / 10 - 1), 'version');
3456
3793
  }
3457
3794
  var globalSchema = buildGlobalSchema(db, db.idbdb, idbUpgradeTrans);
3458
3795
  adjustToExistingIndexNames(db, db._dbSchema, idbUpgradeTrans);
@@ -3478,7 +3815,10 @@
3478
3815
  }
3479
3816
  function getExistingVersion(db, trans, oldVersion) {
3480
3817
  if (trans.storeNames.includes('$meta')) {
3481
- return trans.table('$meta').get('version').then(function (metaVersion) {
3818
+ return trans
3819
+ .table('$meta')
3820
+ .get('version')
3821
+ .then(function (metaVersion) {
3482
3822
  return metaVersion != null ? metaVersion : oldVersion;
3483
3823
  });
3484
3824
  }
@@ -3489,7 +3829,7 @@
3489
3829
  function updateTablesAndIndexes(db, oldVersion, trans, idbUpgradeTrans) {
3490
3830
  var queue = [];
3491
3831
  var versions = db._versions;
3492
- var globalSchema = db._dbSchema = buildGlobalSchema(db, db.idbdb, idbUpgradeTrans);
3832
+ var globalSchema = (db._dbSchema = buildGlobalSchema(db, db.idbdb, idbUpgradeTrans));
3493
3833
  var versToRun = versions.filter(function (v) { return v._cfg.version >= oldVersion; });
3494
3834
  if (versToRun.length === 0) {
3495
3835
  return DexiePromise.resolve();
@@ -3507,7 +3847,7 @@
3507
3847
  });
3508
3848
  diff.change.forEach(function (change) {
3509
3849
  if (change.recreate) {
3510
- throw new exceptions.Upgrade("Not yet support for changing primary key");
3850
+ throw new exceptions.Upgrade('Not yet support for changing primary key');
3511
3851
  }
3512
3852
  else {
3513
3853
  var store_1 = idbUpgradeTrans.objectStore(change.name);
@@ -3544,8 +3884,9 @@
3544
3884
  }
3545
3885
  }
3546
3886
  });
3547
- return (returnValue_1 && typeof returnValue_1.then === 'function' ?
3548
- DexiePromise.resolve(returnValue_1) : promiseFollowed.then(function () { return returnValue_1; }));
3887
+ return returnValue_1 && typeof returnValue_1.then === 'function'
3888
+ ? DexiePromise.resolve(returnValue_1)
3889
+ : promiseFollowed.then(function () { return returnValue_1; });
3549
3890
  }
3550
3891
  });
3551
3892
  queue.push(function (idbtrans) {
@@ -3569,8 +3910,9 @@
3569
3910
  });
3570
3911
  });
3571
3912
  function runQueue() {
3572
- return queue.length ? DexiePromise.resolve(queue.shift()(trans.idbtrans)).then(runQueue) :
3573
- DexiePromise.resolve();
3913
+ return queue.length
3914
+ ? DexiePromise.resolve(queue.shift()(trans.idbtrans)).then(runQueue)
3915
+ : DexiePromise.resolve();
3574
3916
  }
3575
3917
  return runQueue().then(function () {
3576
3918
  createMissingTables(globalSchema, idbUpgradeTrans);
@@ -3580,7 +3922,7 @@
3580
3922
  var diff = {
3581
3923
  del: [],
3582
3924
  add: [],
3583
- change: []
3925
+ change: [],
3584
3926
  };
3585
3927
  var table;
3586
3928
  for (table in oldSchema) {
@@ -3599,11 +3941,12 @@
3599
3941
  recreate: false,
3600
3942
  del: [],
3601
3943
  add: [],
3602
- change: []
3944
+ change: [],
3603
3945
  };
3604
- if ((
3605
- '' + (oldDef.primKey.keyPath || '')) !== ('' + (newDef.primKey.keyPath || '')) ||
3606
- (oldDef.primKey.auto !== newDef.primKey.auto)) {
3946
+ if (
3947
+ '' + (oldDef.primKey.keyPath || '') !==
3948
+ '' + (newDef.primKey.keyPath || '') ||
3949
+ oldDef.primKey.auto !== newDef.primKey.auto) {
3607
3950
  change.recreate = true;
3608
3951
  diff.change.push(change);
3609
3952
  }
@@ -3622,7 +3965,9 @@
3622
3965
  else if (oldIdx.src !== newIdx.src)
3623
3966
  change.change.push(newIdx);
3624
3967
  }
3625
- if (change.del.length > 0 || change.add.length > 0 || change.change.length > 0) {
3968
+ if (change.del.length > 0 ||
3969
+ change.add.length > 0 ||
3970
+ change.change.length > 0) {
3626
3971
  diff.change.push(change);
3627
3972
  }
3628
3973
  }
@@ -3631,9 +3976,9 @@
3631
3976
  return diff;
3632
3977
  }
3633
3978
  function createTable(idbtrans, tableName, primKey, indexes) {
3634
- var store = idbtrans.db.createObjectStore(tableName, primKey.keyPath ?
3635
- { keyPath: primKey.keyPath, autoIncrement: primKey.auto } :
3636
- { autoIncrement: primKey.auto });
3979
+ var store = idbtrans.db.createObjectStore(tableName, primKey.keyPath
3980
+ ? { keyPath: primKey.keyPath, autoIncrement: primKey.auto }
3981
+ : { autoIncrement: primKey.auto });
3637
3982
  indexes.forEach(function (idx) { return addIndex(store, idx); });
3638
3983
  return store;
3639
3984
  }
@@ -3647,12 +3992,17 @@
3647
3992
  });
3648
3993
  }
3649
3994
  function deleteRemovedTables(newSchema, idbtrans) {
3650
- [].slice.call(idbtrans.db.objectStoreNames).forEach(function (storeName) {
3995
+ [].slice
3996
+ .call(idbtrans.db.objectStoreNames)
3997
+ .forEach(function (storeName) {
3651
3998
  return newSchema[storeName] == null && idbtrans.db.deleteObjectStore(storeName);
3652
3999
  });
3653
4000
  }
3654
4001
  function addIndex(store, idx) {
3655
- store.createIndex(idx.name, idx.keyPath, { unique: idx.unique, multiEntry: idx.multi });
4002
+ store.createIndex(idx.name, idx.keyPath, {
4003
+ unique: idx.unique,
4004
+ multiEntry: idx.multi,
4005
+ });
3656
4006
  }
3657
4007
  function buildGlobalSchema(db, idbdb, tmpTrans) {
3658
4008
  var globalSchema = {};
@@ -3660,12 +4010,12 @@
3660
4010
  dbStoreNames.forEach(function (storeName) {
3661
4011
  var store = tmpTrans.objectStore(storeName);
3662
4012
  var keyPath = store.keyPath;
3663
- var primKey = createIndexSpec(nameFromKeyPath(keyPath), keyPath || "", true, false, !!store.autoIncrement, keyPath && typeof keyPath !== "string", true);
4013
+ var primKey = createIndexSpec(nameFromKeyPath(keyPath), keyPath || '', true, false, !!store.autoIncrement, keyPath && typeof keyPath !== 'string', true);
3664
4014
  var indexes = [];
3665
4015
  for (var j = 0; j < store.indexNames.length; ++j) {
3666
4016
  var idbindex = store.index(store.indexNames[j]);
3667
4017
  keyPath = idbindex.keyPath;
3668
- var index = createIndexSpec(idbindex.name, keyPath, !!idbindex.unique, !!idbindex.multiEntry, false, keyPath && typeof keyPath !== "string", false);
4018
+ var index = createIndexSpec(idbindex.name, keyPath, !!idbindex.unique, !!idbindex.multiEntry, false, keyPath && typeof keyPath !== 'string', false);
3669
4019
  indexes.push(index);
3670
4020
  }
3671
4021
  globalSchema[storeName] = createTableSchema(storeName, primKey, indexes);
@@ -3674,14 +4024,15 @@
3674
4024
  }
3675
4025
  function readGlobalSchema(db, idbdb, tmpTrans) {
3676
4026
  db.verno = idbdb.version / 10;
3677
- var globalSchema = db._dbSchema = buildGlobalSchema(db, idbdb, tmpTrans);
4027
+ var globalSchema = (db._dbSchema = buildGlobalSchema(db, idbdb, tmpTrans));
3678
4028
  db._storeNames = slice(idbdb.objectStoreNames, 0);
3679
4029
  setApiOnPlace(db, [db._allTables], keys(globalSchema), globalSchema);
3680
4030
  }
3681
4031
  function verifyInstalledSchema(db, tmpTrans) {
3682
4032
  var installedSchema = buildGlobalSchema(db, db.idbdb, tmpTrans);
3683
4033
  var diff = getSchemaDiff(installedSchema, db._dbSchema);
3684
- return !(diff.add.length || diff.change.some(function (ch) { return ch.add.length || ch.change.length; }));
4034
+ return !(diff.add.length ||
4035
+ diff.change.some(function (ch) { return ch.add.length || ch.change.length; }));
3685
4036
  }
3686
4037
  function adjustToExistingIndexNames(db, schema, idbtrans) {
3687
4038
  var storeNames = idbtrans.db.objectStoreNames;
@@ -3692,7 +4043,9 @@
3692
4043
  for (var j = 0; j < store.indexNames.length; ++j) {
3693
4044
  var indexName = store.indexNames[j];
3694
4045
  var keyPath = store.index(indexName).keyPath;
3695
- var dexieName = typeof keyPath === 'string' ? keyPath : "[" + slice(keyPath).join('+') + "]";
4046
+ var dexieName = typeof keyPath === 'string'
4047
+ ? keyPath
4048
+ : '[' + slice(keyPath).join('+') + ']';
3696
4049
  if (schema[storeName]) {
3697
4050
  var indexSpec = schema[storeName].idxByName[dexieName];
3698
4051
  if (indexSpec) {
@@ -3703,9 +4056,11 @@
3703
4056
  }
3704
4057
  }
3705
4058
  }
3706
- if (typeof navigator !== 'undefined' && /Safari/.test(navigator.userAgent) &&
4059
+ if (typeof navigator !== 'undefined' &&
4060
+ /Safari/.test(navigator.userAgent) &&
3707
4061
  !/(Chrome\/|Edge\/)/.test(navigator.userAgent) &&
3708
- _global.WorkerGlobalScope && _global instanceof _global.WorkerGlobalScope &&
4062
+ _global.WorkerGlobalScope &&
4063
+ _global instanceof _global.WorkerGlobalScope &&
3709
4064
  [].concat(navigator.userAgent.match(/Safari\/(\d*)/))[1] < 604) {
3710
4065
  db._hasGetAll = false;
3711
4066
  }
@@ -3716,8 +4071,10 @@
3716
4071
  var typeSplit = index.split(':');
3717
4072
  var type = (_a = typeSplit[1]) === null || _a === void 0 ? void 0 : _a.trim();
3718
4073
  index = typeSplit[0].trim();
3719
- var name = index.replace(/([&*]|\+\+)/g, "");
3720
- var keyPath = /^\[/.test(name) ? name.match(/^\[(.*)\]$/)[1].split('+') : name;
4074
+ var name = index.replace(/([&*]|\+\+)/g, '');
4075
+ var keyPath = /^\[/.test(name)
4076
+ ? name.match(/^\[(.*)\]$/)[1].split('+')
4077
+ : name;
3721
4078
  return createIndexSpec(name, keyPath || null, /\&/.test(index), /\*/.test(index), /\+\+/.test(index), isArray(keyPath), indexNum === 0, type);
3722
4079
  });
3723
4080
  }
@@ -3788,14 +4145,15 @@
3788
4145
  storesSource: null,
3789
4146
  dbschema: {},
3790
4147
  tables: {},
3791
- contentUpgrade: null
4148
+ contentUpgrade: null,
3792
4149
  };
3793
4150
  });
3794
4151
  }
3795
4152
 
3796
4153
  var connections = createConnectionsManager();
3797
4154
  function createConnectionsManager() {
3798
- if (typeof FinalizationRegistry !== 'undefined' && typeof WeakRef !== 'undefined') {
4155
+ if (typeof FinalizationRegistry !== 'undefined' &&
4156
+ typeof WeakRef !== 'undefined') {
3799
4157
  var _refs_1 = new Set();
3800
4158
  var _registry_1 = new FinalizationRegistry(function (ref) {
3801
4159
  _refs_1.delete(ref);
@@ -3851,19 +4209,19 @@
3851
4209
  }
3852
4210
 
3853
4211
  function getDbNamesTable(indexedDB, IDBKeyRange) {
3854
- var dbNamesDB = indexedDB["_dbNamesDB"];
4212
+ var dbNamesDB = indexedDB['_dbNamesDB'];
3855
4213
  if (!dbNamesDB) {
3856
- dbNamesDB = indexedDB["_dbNamesDB"] = new Dexie$1(DBNAMES_DB, {
4214
+ dbNamesDB = indexedDB['_dbNamesDB'] = new Dexie$1(DBNAMES_DB, {
3857
4215
  addons: [],
3858
4216
  indexedDB: indexedDB,
3859
4217
  IDBKeyRange: IDBKeyRange,
3860
4218
  });
3861
- dbNamesDB.version(1).stores({ dbnames: "name" });
4219
+ dbNamesDB.version(1).stores({ dbnames: 'name' });
3862
4220
  }
3863
- return dbNamesDB.table("dbnames");
4221
+ return dbNamesDB.table('dbnames');
3864
4222
  }
3865
4223
  function hasDatabasesNative(indexedDB) {
3866
- return indexedDB && typeof indexedDB.databases === "function";
4224
+ return indexedDB && typeof indexedDB.databases === 'function';
3867
4225
  }
3868
4226
  function getDatabaseNames(_a) {
3869
4227
  var indexedDB = _a.indexedDB, IDBKeyRange = _a.IDBKeyRange;
@@ -3911,15 +4269,17 @@
3911
4269
 
3912
4270
  var _a;
3913
4271
  function isEmptyRange(node) {
3914
- return !("from" in node);
4272
+ return !('from' in node);
3915
4273
  }
3916
4274
  var RangeSet = function (fromOrTree, to) {
3917
4275
  if (this) {
3918
- extend(this, arguments.length ? { d: 1, from: fromOrTree, to: arguments.length > 1 ? to : fromOrTree } : { d: 0 });
4276
+ extend(this, arguments.length
4277
+ ? { d: 1, from: fromOrTree, to: arguments.length > 1 ? to : fromOrTree }
4278
+ : { d: 0 });
3919
4279
  }
3920
4280
  else {
3921
4281
  var rv = new RangeSet();
3922
- if (fromOrTree && ("d" in fromOrTree)) {
4282
+ if (fromOrTree && 'd' in fromOrTree) {
3923
4283
  extend(rv, fromOrTree);
3924
4284
  }
3925
4285
  return rv;
@@ -4019,7 +4379,9 @@
4019
4379
  return false;
4020
4380
  }
4021
4381
  function getRangeSetIterator(node) {
4022
- var state = isEmptyRange(node) ? null : { s: 0, n: node };
4382
+ var state = isEmptyRange(node)
4383
+ ? null
4384
+ : { s: 0, n: node };
4023
4385
  return {
4024
4386
  next: function (key) {
4025
4387
  var keyProvided = arguments.length > 0;
@@ -4056,9 +4418,9 @@
4056
4418
  function rebalance(target) {
4057
4419
  var _a, _b;
4058
4420
  var diff = (((_a = target.r) === null || _a === void 0 ? void 0 : _a.d) || 0) - (((_b = target.l) === null || _b === void 0 ? void 0 : _b.d) || 0);
4059
- var r = diff > 1 ? "r" : diff < -1 ? "l" : "";
4421
+ var r = diff > 1 ? 'r' : diff < -1 ? 'l' : '';
4060
4422
  if (r) {
4061
- var l = r === "r" ? "l" : "r";
4423
+ var l = r === 'r' ? 'l' : 'r';
4062
4424
  var rootClone = __assign({}, target);
4063
4425
  var oldRootRight = target[r];
4064
4426
  target.from = oldRootRight.from;
@@ -4086,7 +4448,9 @@
4086
4448
  }
4087
4449
 
4088
4450
  function obsSetsOverlap(os1, os2) {
4089
- return os1.all || os2.all || Object.keys(os1).some(function (key) { return os2[key] && rangesOverlap(os2[key], os1[key]); });
4451
+ return (os1.all ||
4452
+ os2.all ||
4453
+ Object.keys(os1).some(function (key) { return os2[key] && rangesOverlap(os2[key], os1[key]); }));
4090
4454
  }
4091
4455
 
4092
4456
  var cache = {};
@@ -4156,9 +4520,9 @@
4156
4520
  var state = db._state;
4157
4521
  var indexedDB = db._deps.indexedDB;
4158
4522
  if (state.isBeingOpened || db.idbdb)
4159
- return state.dbReadyPromise.then(function () { return state.dbOpenError ?
4160
- rejection(state.dbOpenError) :
4161
- db; });
4523
+ return state.dbReadyPromise.then(function () {
4524
+ return state.dbOpenError ? rejection(state.dbOpenError) : db;
4525
+ });
4162
4526
  state.isBeingOpened = true;
4163
4527
  state.dbOpenError = null;
4164
4528
  state.openComplete = false;
@@ -4171,97 +4535,102 @@
4171
4535
  }
4172
4536
  var resolveDbReady = state.dbReadyResolve,
4173
4537
  upgradeTransaction = null, wasCreated = false;
4174
- var tryOpenDB = function () { return new DexiePromise(function (resolve, reject) {
4175
- throwIfCancelled();
4176
- if (!indexedDB)
4177
- throw new exceptions.MissingAPI();
4178
- var dbName = db.name;
4179
- var req = state.autoSchema || !nativeVerToOpen ?
4180
- indexedDB.open(dbName) :
4181
- indexedDB.open(dbName, nativeVerToOpen);
4182
- if (!req)
4183
- throw new exceptions.MissingAPI();
4184
- req.onerror = eventRejectHandler(reject);
4185
- req.onblocked = wrap(db._fireOnBlocked);
4186
- req.onupgradeneeded = wrap(function (e) {
4187
- upgradeTransaction = req.transaction;
4188
- if (state.autoSchema && !db._options.allowEmptyDB) {
4189
- req.onerror = preventDefault;
4190
- upgradeTransaction.abort();
4191
- req.result.close();
4192
- var delreq = indexedDB.deleteDatabase(dbName);
4193
- delreq.onsuccess = delreq.onerror = wrap(function () {
4194
- reject(new exceptions.NoSuchDatabase("Database ".concat(dbName, " doesnt exist")));
4195
- });
4196
- }
4197
- else {
4198
- upgradeTransaction.onerror = eventRejectHandler(reject);
4199
- var oldVer = e.oldVersion > Math.pow(2, 62) ? 0 : e.oldVersion;
4200
- wasCreated = oldVer < 1;
4201
- db.idbdb = req.result;
4202
- if (schemaPatchMode) {
4203
- patchCurrentVersion(db, upgradeTransaction);
4538
+ var tryOpenDB = function () {
4539
+ return new DexiePromise(function (resolve, reject) {
4540
+ throwIfCancelled();
4541
+ if (!indexedDB)
4542
+ throw new exceptions.MissingAPI();
4543
+ var dbName = db.name;
4544
+ var req = state.autoSchema || !nativeVerToOpen
4545
+ ? indexedDB.open(dbName)
4546
+ : indexedDB.open(dbName, nativeVerToOpen);
4547
+ if (!req)
4548
+ throw new exceptions.MissingAPI();
4549
+ req.onerror = eventRejectHandler(reject);
4550
+ req.onblocked = wrap(db._fireOnBlocked);
4551
+ req.onupgradeneeded = wrap(function (e) {
4552
+ upgradeTransaction = req.transaction;
4553
+ if (state.autoSchema && !db._options.allowEmptyDB) {
4554
+ req.onerror = preventDefault;
4555
+ upgradeTransaction.abort();
4556
+ req.result.close();
4557
+ var delreq = indexedDB.deleteDatabase(dbName);
4558
+ delreq.onsuccess = delreq.onerror = wrap(function () {
4559
+ reject(new exceptions.NoSuchDatabase("Database ".concat(dbName, " doesnt exist")));
4560
+ });
4204
4561
  }
4205
- runUpgraders(db, oldVer / 10, upgradeTransaction, reject);
4206
- }
4207
- }, reject);
4208
- req.onsuccess = wrap(function () {
4209
- upgradeTransaction = null;
4210
- var idbdb = db.idbdb = req.result;
4211
- var objectStoreNames = slice(idbdb.objectStoreNames);
4212
- if (objectStoreNames.length > 0)
4213
- try {
4214
- var tmpTrans = idbdb.transaction(safariMultiStoreFix(objectStoreNames), 'readonly');
4215
- if (state.autoSchema)
4216
- readGlobalSchema(db, idbdb, tmpTrans);
4217
- else {
4218
- adjustToExistingIndexNames(db, db._dbSchema, tmpTrans);
4219
- if (!verifyInstalledSchema(db, tmpTrans) && !schemaPatchMode) {
4220
- console.warn("Dexie SchemaDiff: Schema was extended without increasing the number passed to db.version(). Dexie will add missing parts and increment native version number to workaround this.");
4221
- idbdb.close();
4222
- nativeVerToOpen = idbdb.version + 1;
4223
- schemaPatchMode = true;
4224
- return resolve(tryOpenDB());
4225
- }
4562
+ else {
4563
+ upgradeTransaction.onerror = eventRejectHandler(reject);
4564
+ var oldVer = e.oldVersion > Math.pow(2, 62) ? 0 : e.oldVersion;
4565
+ wasCreated = oldVer < 1;
4566
+ db.idbdb = req.result;
4567
+ if (schemaPatchMode) {
4568
+ patchCurrentVersion(db, upgradeTransaction);
4226
4569
  }
4227
- generateMiddlewareStacks(db, tmpTrans);
4228
- }
4229
- catch (e) {
4230
- }
4231
- connections.add(db);
4232
- idbdb.onversionchange = wrap(function (ev) {
4233
- state.vcFired = true;
4234
- db.on("versionchange").fire(ev);
4235
- });
4236
- idbdb.onclose = wrap(function () {
4237
- db.close({ disableAutoOpen: false });
4238
- });
4239
- if (wasCreated)
4240
- _onDatabaseCreated(db._deps, dbName);
4241
- resolve();
4242
- }, reject);
4243
- }).catch(function (err) {
4244
- switch (err === null || err === void 0 ? void 0 : err.name) {
4245
- case "UnknownError":
4246
- if (state.PR1398_maxLoop > 0) {
4247
- state.PR1398_maxLoop--;
4248
- console.warn('Dexie: Workaround for Chrome UnknownError on open()');
4249
- return tryOpenDB();
4250
- }
4251
- break;
4252
- case "VersionError":
4253
- if (nativeVerToOpen > 0) {
4254
- nativeVerToOpen = 0;
4255
- return tryOpenDB();
4570
+ runUpgraders(db, oldVer / 10, upgradeTransaction, reject);
4256
4571
  }
4257
- break;
4258
- }
4259
- return DexiePromise.reject(err);
4260
- }); };
4572
+ }, reject);
4573
+ req.onsuccess = wrap(function () {
4574
+ upgradeTransaction = null;
4575
+ var idbdb = (db.idbdb = req.result);
4576
+ var objectStoreNames = slice(idbdb.objectStoreNames);
4577
+ if (objectStoreNames.length > 0)
4578
+ try {
4579
+ var tmpTrans = idbdb.transaction(safariMultiStoreFix(objectStoreNames), 'readonly');
4580
+ if (state.autoSchema)
4581
+ readGlobalSchema(db, idbdb, tmpTrans);
4582
+ else {
4583
+ adjustToExistingIndexNames(db, db._dbSchema, tmpTrans);
4584
+ if (!verifyInstalledSchema(db, tmpTrans) && !schemaPatchMode) {
4585
+ console.warn("Dexie SchemaDiff: Schema was extended without increasing the number passed to db.version(). Dexie will add missing parts and increment native version number to workaround this.");
4586
+ idbdb.close();
4587
+ nativeVerToOpen = idbdb.version + 1;
4588
+ schemaPatchMode = true;
4589
+ return resolve(tryOpenDB());
4590
+ }
4591
+ }
4592
+ generateMiddlewareStacks(db, tmpTrans);
4593
+ }
4594
+ catch (e) {
4595
+ }
4596
+ connections.add(db);
4597
+ idbdb.onversionchange = wrap(function (ev) {
4598
+ state.vcFired = true;
4599
+ db.on('versionchange').fire(ev);
4600
+ });
4601
+ idbdb.onclose = wrap(function () {
4602
+ db.close({ disableAutoOpen: false });
4603
+ });
4604
+ if (wasCreated)
4605
+ _onDatabaseCreated(db._deps, dbName);
4606
+ resolve();
4607
+ }, reject);
4608
+ }).catch(function (err) {
4609
+ switch (err === null || err === void 0 ? void 0 : err.name) {
4610
+ case 'UnknownError':
4611
+ if (state.PR1398_maxLoop > 0) {
4612
+ state.PR1398_maxLoop--;
4613
+ console.warn('Dexie: Workaround for Chrome UnknownError on open()');
4614
+ return tryOpenDB();
4615
+ }
4616
+ break;
4617
+ case 'VersionError':
4618
+ if (nativeVerToOpen > 0) {
4619
+ nativeVerToOpen = 0;
4620
+ return tryOpenDB();
4621
+ }
4622
+ break;
4623
+ }
4624
+ return DexiePromise.reject(err);
4625
+ });
4626
+ };
4261
4627
  return DexiePromise.race([
4262
4628
  openCanceller,
4263
- (typeof navigator === 'undefined' ? DexiePromise.resolve() : idbReady()).then(tryOpenDB)
4264
- ]).then(function () {
4629
+ (typeof navigator === 'undefined'
4630
+ ? DexiePromise.resolve()
4631
+ : idbReady()).then(tryOpenDB),
4632
+ ])
4633
+ .then(function () {
4265
4634
  throwIfCancelled();
4266
4635
  state.onReadyBeingFired = [];
4267
4636
  return DexiePromise.resolve(vip(function () { return db.on.ready.fire(db.vip); })).then(function fireRemainders() {
@@ -4271,12 +4640,14 @@
4271
4640
  return DexiePromise.resolve(vip(function () { return remainders_1(db.vip); })).then(fireRemainders);
4272
4641
  }
4273
4642
  });
4274
- }).finally(function () {
4643
+ })
4644
+ .finally(function () {
4275
4645
  if (state.openCanceller === openCanceller) {
4276
4646
  state.onReadyBeingFired = null;
4277
4647
  state.isBeingOpened = false;
4278
4648
  }
4279
- }).catch(function (err) {
4649
+ })
4650
+ .catch(function (err) {
4280
4651
  state.dbOpenError = err;
4281
4652
  try {
4282
4653
  upgradeTransaction && upgradeTransaction.abort();
@@ -4286,16 +4657,19 @@
4286
4657
  db._close();
4287
4658
  }
4288
4659
  return rejection(err);
4289
- }).finally(function () {
4660
+ })
4661
+ .finally(function () {
4290
4662
  state.openComplete = true;
4291
4663
  resolveDbReady();
4292
- }).then(function () {
4664
+ })
4665
+ .then(function () {
4293
4666
  if (wasCreated) {
4294
4667
  var everything_1 = {};
4295
4668
  db.tables.forEach(function (table) {
4296
4669
  table.schema.indexes.forEach(function (idx) {
4297
4670
  if (idx.name)
4298
- everything_1["idb://".concat(db.name, "/").concat(table.name, "/").concat(idx.name)] = new RangeSet(-Infinity, [[[]]]);
4671
+ everything_1["idb://".concat(db.name, "/").concat(table.name, "/").concat(idx.name)] =
4672
+ new RangeSet(-Infinity, [[[]]]);
4299
4673
  });
4300
4674
  everything_1["idb://".concat(db.name, "/").concat(table.name, "/")] = everything_1["idb://".concat(db.name, "/").concat(table.name, "/:dels")] = new RangeSet(-Infinity, [[[]]]);
4301
4675
  });
@@ -4311,10 +4685,13 @@
4311
4685
  function step(getNext) {
4312
4686
  return function (val) {
4313
4687
  var next = getNext(val), value = next.value;
4314
- return next.done ? value :
4315
- (!value || typeof value.then !== 'function' ?
4316
- isArray(value) ? Promise.all(value).then(onSuccess, onError) : onSuccess(value) :
4317
- value.then(onSuccess, onError));
4688
+ return next.done
4689
+ ? value
4690
+ : !value || typeof value.then !== 'function'
4691
+ ? isArray(value)
4692
+ ? Promise.all(value).then(onSuccess, onError)
4693
+ : onSuccess(value)
4694
+ : value.then(onSuccess, onError);
4318
4695
  };
4319
4696
  }
4320
4697
  return step(callNext)();
@@ -4323,7 +4700,7 @@
4323
4700
  function extractTransactionArgs(mode, _tableArgs_, scopeFunc) {
4324
4701
  var i = arguments.length;
4325
4702
  if (i < 2)
4326
- throw new exceptions.InvalidArgument("Too few arguments");
4703
+ throw new exceptions.InvalidArgument('Too few arguments');
4327
4704
  var args = new Array(i - 1);
4328
4705
  while (--i)
4329
4706
  args[i - 1] = arguments[i];
@@ -4338,7 +4715,7 @@
4338
4715
  trans.explicit = true;
4339
4716
  var zoneProps = {
4340
4717
  trans: trans,
4341
- transless: transless
4718
+ transless: transless,
4342
4719
  };
4343
4720
  if (parentTransaction) {
4344
4721
  trans.idbtrans = parentTransaction.idbtrans;
@@ -4350,10 +4727,16 @@
4350
4727
  db._state.PR1398_maxLoop = 3;
4351
4728
  }
4352
4729
  catch (ex) {
4353
- if (ex.name === errnames.InvalidState && db.isOpen() && --db._state.PR1398_maxLoop > 0) {
4730
+ if (ex.name === errnames.InvalidState &&
4731
+ db.isOpen() &&
4732
+ --db._state.PR1398_maxLoop > 0) {
4354
4733
  console.warn('Dexie: Need to reopen db');
4355
4734
  db.close({ disableAutoOpen: false });
4356
- return db.open().then(function () { return enterTransactionScope(db, mode, storeNames, null, scopeFunc); });
4735
+ return db
4736
+ .open()
4737
+ .then(function () {
4738
+ return enterTransactionScope(db, mode, storeNames, null, scopeFunc);
4739
+ });
4357
4740
  }
4358
4741
  return rejection(ex);
4359
4742
  }
@@ -4370,20 +4753,27 @@
4370
4753
  var decrementor = decrementExpectedAwaits.bind(null, null);
4371
4754
  returnValue.then(decrementor, decrementor);
4372
4755
  }
4373
- else if (typeof returnValue.next === 'function' && typeof returnValue.throw === 'function') {
4756
+ else if (typeof returnValue.next === 'function' &&
4757
+ typeof returnValue.throw === 'function') {
4374
4758
  returnValue = awaitIterator(returnValue);
4375
4759
  }
4376
4760
  }
4377
4761
  }, zoneProps);
4378
- return (returnValue && typeof returnValue.then === 'function' ?
4379
- DexiePromise.resolve(returnValue).then(function (x) { return trans.active ?
4380
- x
4381
- : rejection(new exceptions.PrematureCommit("Transaction committed too early. See http://bit.ly/2kdckMn")); })
4382
- : promiseFollowed.then(function () { return returnValue; })).then(function (x) {
4762
+ return (returnValue && typeof returnValue.then === 'function'
4763
+ ?
4764
+ DexiePromise.resolve(returnValue).then(function (x) {
4765
+ return trans.active
4766
+ ? x
4767
+ : rejection(new exceptions.PrematureCommit('Transaction committed too early. See http://bit.ly/2kdckMn'));
4768
+ })
4769
+ :
4770
+ promiseFollowed.then(function () { return returnValue; }))
4771
+ .then(function (x) {
4383
4772
  if (parentTransaction)
4384
4773
  trans._resolve();
4385
4774
  return trans._completion.then(function () { return x; });
4386
- }).catch(function (e) {
4775
+ })
4776
+ .catch(function (e) {
4387
4777
  trans._reject(e);
4388
4778
  return rejection(e);
4389
4779
  });
@@ -4404,8 +4794,13 @@
4404
4794
  var allVirtualIndexes = [];
4405
4795
  function addVirtualIndexes(keyPath, keyTail, lowLevelIndex) {
4406
4796
  var keyPathAlias = getKeyPathAlias(keyPath);
4407
- var indexList = (indexLookup[keyPathAlias] = indexLookup[keyPathAlias] || []);
4408
- var keyLength = keyPath == null ? 0 : typeof keyPath === 'string' ? 1 : keyPath.length;
4797
+ var indexList = (indexLookup[keyPathAlias] =
4798
+ indexLookup[keyPathAlias] || []);
4799
+ var keyLength = keyPath == null
4800
+ ? 0
4801
+ : typeof keyPath === 'string'
4802
+ ? 1
4803
+ : keyPath.length;
4409
4804
  var isVirtual = keyTail > 0;
4410
4805
  var virtualIndex = __assign(__assign({}, lowLevelIndex), { name: isVirtual
4411
4806
  ? "".concat(keyPathAlias, "(virtual-from:").concat(lowLevelIndex.name, ")")
@@ -4415,16 +4810,16 @@
4415
4810
  allVirtualIndexes.push(virtualIndex);
4416
4811
  }
4417
4812
  if (keyLength > 1) {
4418
- var virtualKeyPath = keyLength === 2 ?
4419
- keyPath[0] :
4420
- keyPath.slice(0, keyLength - 1);
4813
+ var virtualKeyPath = keyLength === 2
4814
+ ? keyPath[0]
4815
+ : keyPath.slice(0, keyLength - 1);
4421
4816
  addVirtualIndexes(virtualKeyPath, keyTail + 1, lowLevelIndex);
4422
4817
  }
4423
4818
  indexList.sort(function (a, b) { return a.keyTail - b.keyTail; });
4424
4819
  return virtualIndex;
4425
4820
  }
4426
4821
  var primaryKey = addVirtualIndexes(schema.primaryKey.keyPath, 0, schema.primaryKey);
4427
- indexLookup[":id"] = [primaryKey];
4822
+ indexLookup[':id'] = [primaryKey];
4428
4823
  for (var _i = 0, _a = schema.indexes; _i < _a.length; _i++) {
4429
4824
  var index = _a[_i];
4430
4825
  addVirtualIndexes(index.keyPath, 0, index);
@@ -4435,80 +4830,82 @@
4435
4830
  }
4436
4831
  function translateRange(range, keyTail) {
4437
4832
  return {
4438
- type: range.type === 1 ?
4439
- 2 :
4440
- range.type,
4833
+ type: range.type === 1
4834
+ ? 2
4835
+ : range.type,
4441
4836
  lower: pad(range.lower, range.lowerOpen ? down.MAX_KEY : down.MIN_KEY, keyTail),
4442
4837
  lowerOpen: true,
4443
4838
  upper: pad(range.upper, range.upperOpen ? down.MIN_KEY : down.MAX_KEY, keyTail),
4444
- upperOpen: true
4839
+ upperOpen: true,
4445
4840
  };
4446
4841
  }
4447
4842
  function translateRequest(req) {
4448
4843
  var index = req.query.index;
4449
- return index.isVirtual ? __assign(__assign({}, req), { query: {
4450
- index: index.lowLevelIndex,
4451
- range: translateRange(req.query.range, index.keyTail)
4452
- } }) : req;
4844
+ return index.isVirtual
4845
+ ? __assign(__assign({}, req), { query: {
4846
+ index: index.lowLevelIndex,
4847
+ range: translateRange(req.query.range, index.keyTail),
4848
+ } }) : req;
4453
4849
  }
4454
4850
  var result = __assign(__assign({}, table), { schema: __assign(__assign({}, schema), { primaryKey: primaryKey, indexes: allVirtualIndexes, getIndexByKeyPath: findBestIndex }), count: function (req) {
4455
4851
  return table.count(translateRequest(req));
4456
4852
  }, query: function (req) {
4457
4853
  return table.query(translateRequest(req));
4458
4854
  }, openCursor: function (req) {
4459
- var _a = req.query.index, keyTail = _a.keyTail, isVirtual = _a.isVirtual, keyLength = _a.keyLength;
4855
+ var _a = req.query
4856
+ .index, keyTail = _a.keyTail, isVirtual = _a.isVirtual, keyLength = _a.keyLength;
4460
4857
  if (!isVirtual)
4461
4858
  return table.openCursor(req);
4462
4859
  function createVirtualCursor(cursor) {
4463
4860
  function _continue(key) {
4464
- key != null ?
4465
- cursor.continue(pad(key, req.reverse ? down.MAX_KEY : down.MIN_KEY, keyTail)) :
4466
- req.unique ?
4467
- cursor.continue(cursor.key.slice(0, keyLength)
4468
- .concat(req.reverse
4469
- ? down.MIN_KEY
4470
- : down.MAX_KEY, keyTail)) :
4471
- cursor.continue();
4861
+ key != null
4862
+ ? cursor.continue(pad(key, req.reverse ? down.MAX_KEY : down.MIN_KEY, keyTail))
4863
+ : req.unique
4864
+ ? cursor.continue(cursor.key
4865
+ .slice(0, keyLength)
4866
+ .concat(req.reverse ? down.MIN_KEY : down.MAX_KEY, keyTail))
4867
+ : cursor.continue();
4472
4868
  }
4473
4869
  var virtualCursor = Object.create(cursor, {
4474
4870
  continue: { value: _continue },
4475
4871
  continuePrimaryKey: {
4476
4872
  value: function (key, primaryKey) {
4477
4873
  cursor.continuePrimaryKey(pad(key, down.MAX_KEY, keyTail), primaryKey);
4478
- }
4874
+ },
4479
4875
  },
4480
4876
  primaryKey: {
4481
4877
  get: function () {
4482
4878
  return cursor.primaryKey;
4483
- }
4879
+ },
4484
4880
  },
4485
4881
  key: {
4486
4882
  get: function () {
4487
4883
  var key = cursor.key;
4488
- return keyLength === 1 ?
4489
- key[0] :
4490
- key.slice(0, keyLength);
4491
- }
4884
+ return keyLength === 1
4885
+ ? key[0]
4886
+ : key.slice(0, keyLength);
4887
+ },
4492
4888
  },
4493
4889
  value: {
4494
4890
  get: function () {
4495
4891
  return cursor.value;
4496
- }
4497
- }
4892
+ },
4893
+ },
4498
4894
  });
4499
4895
  return virtualCursor;
4500
4896
  }
4501
- return table.openCursor(translateRequest(req))
4897
+ return table
4898
+ .openCursor(translateRequest(req))
4502
4899
  .then(function (cursor) { return cursor && createVirtualCursor(cursor); });
4503
4900
  } });
4504
4901
  return result;
4505
4902
  } });
4506
4903
  }
4507
4904
  var virtualIndexMiddleware = {
4508
- stack: "dbcore",
4509
- name: "VirtualIndexMiddleware",
4905
+ stack: 'dbcore',
4906
+ name: 'VirtualIndexMiddleware',
4510
4907
  level: 1,
4511
- create: createVirtualIndexMiddleware
4908
+ create: createVirtualIndexMiddleware,
4512
4909
  };
4513
4910
 
4514
4911
  function getObjectDiff(a, b, rv, prfx) {
@@ -4552,127 +4949,155 @@
4552
4949
  }
4553
4950
 
4554
4951
  var hooksMiddleware = {
4555
- stack: "dbcore",
4556
- name: "HooksMiddleware",
4952
+ stack: 'dbcore',
4953
+ name: 'HooksMiddleware',
4557
4954
  level: 2,
4558
- create: function (downCore) { return (__assign(__assign({}, downCore), { table: function (tableName) {
4559
- var downTable = downCore.table(tableName);
4560
- var primaryKey = downTable.schema.primaryKey;
4561
- var tableMiddleware = __assign(__assign({}, downTable), { mutate: function (req) {
4562
- var dxTrans = PSD.trans;
4563
- var _a = dxTrans.table(tableName).hook, deleting = _a.deleting, creating = _a.creating, updating = _a.updating;
4564
- switch (req.type) {
4565
- case 'add':
4566
- if (creating.fire === nop)
4567
- break;
4568
- return dxTrans._promise('readwrite', function () { return addPutOrDelete(req); }, true);
4569
- case 'put':
4570
- if (creating.fire === nop && updating.fire === nop)
4571
- break;
4572
- return dxTrans._promise('readwrite', function () { return addPutOrDelete(req); }, true);
4573
- case 'delete':
4574
- if (deleting.fire === nop)
4575
- break;
4576
- return dxTrans._promise('readwrite', function () { return addPutOrDelete(req); }, true);
4577
- case 'deleteRange':
4578
- if (deleting.fire === nop)
4579
- break;
4580
- return dxTrans._promise('readwrite', function () { return deleteRange(req); }, true);
4581
- }
4582
- return downTable.mutate(req);
4583
- function addPutOrDelete(req) {
4955
+ create: function (downCore) {
4956
+ return (__assign(__assign({}, downCore), { table: function (tableName) {
4957
+ var downTable = downCore.table(tableName);
4958
+ var primaryKey = downTable.schema.primaryKey;
4959
+ var tableMiddleware = __assign(__assign({}, downTable), { mutate: function (req) {
4584
4960
  var dxTrans = PSD.trans;
4585
- var keys = req.keys || getEffectiveKeys(primaryKey, req);
4586
- if (!keys)
4587
- throw new Error("Keys missing");
4588
- req = req.type === 'add' || req.type === 'put' ? __assign(__assign({}, req), { keys: keys }) : __assign({}, req);
4589
- if (req.type !== 'delete')
4590
- req.values = __spreadArray([], req.values, true);
4591
- if (req.keys)
4592
- req.keys = __spreadArray([], req.keys, true);
4593
- return getExistingValues(downTable, req, keys).then(function (existingValues) {
4594
- var contexts = keys.map(function (key, i) {
4595
- var existingValue = existingValues[i];
4596
- var ctx = { onerror: null, onsuccess: null };
4597
- if (req.type === 'delete') {
4598
- deleting.fire.call(ctx, key, existingValue, dxTrans);
4599
- }
4600
- else if (req.type === 'add' || existingValue === undefined) {
4601
- var generatedPrimaryKey = creating.fire.call(ctx, key, req.values[i], dxTrans);
4602
- if (key == null && generatedPrimaryKey != null) {
4603
- key = generatedPrimaryKey;
4604
- req.keys[i] = key;
4605
- if (!primaryKey.outbound) {
4606
- setByKeyPath(req.values[i], primaryKey.keyPath, key);
4607
- }
4961
+ var _a = dxTrans.table(tableName).hook, deleting = _a.deleting, creating = _a.creating, updating = _a.updating;
4962
+ switch (req.type) {
4963
+ case 'add':
4964
+ if (creating.fire === nop)
4965
+ break;
4966
+ return dxTrans._promise('readwrite', function () { return addPutOrDelete(req); }, true);
4967
+ case 'put':
4968
+ if (creating.fire === nop && updating.fire === nop)
4969
+ break;
4970
+ return dxTrans._promise('readwrite', function () { return addPutOrDelete(req); }, true);
4971
+ case 'delete':
4972
+ if (deleting.fire === nop)
4973
+ break;
4974
+ return dxTrans._promise('readwrite', function () { return addPutOrDelete(req); }, true);
4975
+ case 'deleteRange':
4976
+ if (deleting.fire === nop)
4977
+ break;
4978
+ return dxTrans._promise('readwrite', function () { return deleteRange(req); }, true);
4979
+ }
4980
+ return downTable.mutate(req);
4981
+ function addPutOrDelete(req) {
4982
+ var dxTrans = PSD.trans;
4983
+ var keys = req.keys || getEffectiveKeys(primaryKey, req);
4984
+ if (!keys)
4985
+ throw new Error('Keys missing');
4986
+ req =
4987
+ req.type === 'add' || req.type === 'put'
4988
+ ? __assign(__assign({}, req), { keys: keys }) : __assign({}, req);
4989
+ if (req.type !== 'delete')
4990
+ req.values = __spreadArray([], req.values, true);
4991
+ if (req.keys)
4992
+ req.keys = __spreadArray([], req.keys, true);
4993
+ return getExistingValues(downTable, req, keys).then(function (existingValues) {
4994
+ var contexts = keys.map(function (key, i) {
4995
+ var existingValue = existingValues[i];
4996
+ var ctx = { onerror: null, onsuccess: null };
4997
+ if (req.type === 'delete') {
4998
+ deleting.fire.call(ctx, key, existingValue, dxTrans);
4608
4999
  }
4609
- }
4610
- else {
4611
- var objectDiff = getObjectDiff(existingValue, req.values[i]);
4612
- var additionalChanges_1 = updating.fire.call(ctx, objectDiff, key, existingValue, dxTrans);
4613
- if (additionalChanges_1) {
4614
- var requestedValue_1 = req.values[i];
4615
- Object.keys(additionalChanges_1).forEach(function (keyPath) {
4616
- if (hasOwn(requestedValue_1, keyPath)) {
4617
- requestedValue_1[keyPath] = additionalChanges_1[keyPath];
4618
- }
4619
- else {
4620
- setByKeyPath(requestedValue_1, keyPath, additionalChanges_1[keyPath]);
5000
+ else if (req.type === 'add' ||
5001
+ existingValue === undefined) {
5002
+ var generatedPrimaryKey = creating.fire.call(ctx, key, req.values[i], dxTrans);
5003
+ if (key == null && generatedPrimaryKey != null) {
5004
+ key = generatedPrimaryKey;
5005
+ req.keys[i] = key;
5006
+ if (!primaryKey.outbound) {
5007
+ setByKeyPath(req.values[i], primaryKey.keyPath, key);
4621
5008
  }
4622
- });
5009
+ }
4623
5010
  }
4624
- }
4625
- return ctx;
5011
+ else {
5012
+ var objectDiff = getObjectDiff(existingValue, req.values[i]);
5013
+ var additionalChanges_1 = updating.fire.call(ctx, objectDiff, key, existingValue, dxTrans);
5014
+ if (additionalChanges_1) {
5015
+ var requestedValue_1 = req.values[i];
5016
+ Object.keys(additionalChanges_1).forEach(function (keyPath) {
5017
+ if (hasOwn(requestedValue_1, keyPath)) {
5018
+ requestedValue_1[keyPath] =
5019
+ additionalChanges_1[keyPath];
5020
+ }
5021
+ else {
5022
+ setByKeyPath(requestedValue_1, keyPath, additionalChanges_1[keyPath]);
5023
+ }
5024
+ });
5025
+ }
5026
+ }
5027
+ return ctx;
5028
+ });
5029
+ return downTable
5030
+ .mutate(req)
5031
+ .then(function (_a) {
5032
+ var failures = _a.failures, results = _a.results, numFailures = _a.numFailures, lastResult = _a.lastResult;
5033
+ for (var i = 0; i < keys.length; ++i) {
5034
+ var primKey = results ? results[i] : keys[i];
5035
+ var ctx = contexts[i];
5036
+ if (primKey == null) {
5037
+ ctx.onerror && ctx.onerror(failures[i]);
5038
+ }
5039
+ else {
5040
+ ctx.onsuccess &&
5041
+ ctx.onsuccess(req.type === 'put' && existingValues[i]
5042
+ ? req.values[i]
5043
+ : primKey
5044
+ );
5045
+ }
5046
+ }
5047
+ return { failures: failures, results: results, numFailures: numFailures, lastResult: lastResult };
5048
+ })
5049
+ .catch(function (error) {
5050
+ contexts.forEach(function (ctx) { return ctx.onerror && ctx.onerror(error); });
5051
+ return Promise.reject(error);
5052
+ });
4626
5053
  });
4627
- return downTable.mutate(req).then(function (_a) {
4628
- var failures = _a.failures, results = _a.results, numFailures = _a.numFailures, lastResult = _a.lastResult;
4629
- for (var i = 0; i < keys.length; ++i) {
4630
- var primKey = results ? results[i] : keys[i];
4631
- var ctx = contexts[i];
4632
- if (primKey == null) {
4633
- ctx.onerror && ctx.onerror(failures[i]);
5054
+ }
5055
+ function deleteRange(req) {
5056
+ return deleteNextChunk(req.trans, req.range, 10000);
5057
+ }
5058
+ function deleteNextChunk(trans, range, limit) {
5059
+ return downTable
5060
+ .query({
5061
+ trans: trans,
5062
+ values: false,
5063
+ query: { index: primaryKey, range: range },
5064
+ limit: limit,
5065
+ })
5066
+ .then(function (_a) {
5067
+ var result = _a.result;
5068
+ return addPutOrDelete({
5069
+ type: 'delete',
5070
+ keys: result,
5071
+ trans: trans,
5072
+ }).then(function (res) {
5073
+ if (res.numFailures > 0)
5074
+ return Promise.reject(res.failures[0]);
5075
+ if (result.length < limit) {
5076
+ return {
5077
+ failures: [],
5078
+ numFailures: 0,
5079
+ lastResult: undefined,
5080
+ };
4634
5081
  }
4635
5082
  else {
4636
- ctx.onsuccess && ctx.onsuccess(req.type === 'put' && existingValues[i] ?
4637
- req.values[i] :
4638
- primKey
4639
- );
5083
+ return deleteNextChunk(trans, __assign(__assign({}, range), { lower: result[result.length - 1], lowerOpen: true }), limit);
4640
5084
  }
4641
- }
4642
- return { failures: failures, results: results, numFailures: numFailures, lastResult: lastResult };
4643
- }).catch(function (error) {
4644
- contexts.forEach(function (ctx) { return ctx.onerror && ctx.onerror(error); });
4645
- return Promise.reject(error);
4646
- });
4647
- });
4648
- }
4649
- function deleteRange(req) {
4650
- return deleteNextChunk(req.trans, req.range, 10000);
4651
- }
4652
- function deleteNextChunk(trans, range, limit) {
4653
- return downTable.query({ trans: trans, values: false, query: { index: primaryKey, range: range }, limit: limit })
4654
- .then(function (_a) {
4655
- var result = _a.result;
4656
- return addPutOrDelete({ type: 'delete', keys: result, trans: trans }).then(function (res) {
4657
- if (res.numFailures > 0)
4658
- return Promise.reject(res.failures[0]);
4659
- if (result.length < limit) {
4660
- return { failures: [], numFailures: 0, lastResult: undefined };
4661
- }
4662
- else {
4663
- return deleteNextChunk(trans, __assign(__assign({}, range), { lower: result[result.length - 1], lowerOpen: true }), limit);
4664
- }
5085
+ });
4665
5086
  });
4666
- });
4667
- }
4668
- } });
4669
- return tableMiddleware;
4670
- } })); }
5087
+ }
5088
+ } });
5089
+ return tableMiddleware;
5090
+ } }));
5091
+ },
4671
5092
  };
4672
5093
  function getExistingValues(table, req, effectiveKeys) {
4673
- return req.type === "add"
5094
+ return req.type === 'add'
4674
5095
  ? Promise.resolve([])
4675
- : table.getMany({ trans: req.trans, keys: effectiveKeys, cache: "immutable" });
5096
+ : table.getMany({
5097
+ trans: req.trans,
5098
+ keys: effectiveKeys,
5099
+ cache: 'immutable',
5100
+ });
4676
5101
  }
4677
5102
 
4678
5103
  function getFromTransactionCache(keys, cache, clone) {
@@ -4695,7 +5120,7 @@
4695
5120
  }
4696
5121
  }
4697
5122
  var cacheExistingValuesMiddleware = {
4698
- stack: "dbcore",
5123
+ stack: 'dbcore',
4699
5124
  level: -1,
4700
5125
  create: function (core) {
4701
5126
  return {
@@ -4705,20 +5130,20 @@
4705
5130
  if (!req.cache) {
4706
5131
  return table.getMany(req);
4707
5132
  }
4708
- var cachedResult = getFromTransactionCache(req.keys, req.trans["_cache"], req.cache === "clone");
5133
+ var cachedResult = getFromTransactionCache(req.keys, req.trans['_cache'], req.cache === 'clone');
4709
5134
  if (cachedResult) {
4710
5135
  return DexiePromise.resolve(cachedResult);
4711
5136
  }
4712
5137
  return table.getMany(req).then(function (res) {
4713
- req.trans["_cache"] = {
5138
+ req.trans['_cache'] = {
4714
5139
  keys: req.keys,
4715
- values: req.cache === "clone" ? deepClone(res) : res,
5140
+ values: req.cache === 'clone' ? deepClone(res) : res,
4716
5141
  };
4717
5142
  return res;
4718
5143
  });
4719
5144
  }, mutate: function (req) {
4720
- if (req.type !== "add")
4721
- req.trans["_cache"] = null;
5145
+ if (req.type !== 'add')
5146
+ req.trans['_cache'] = null;
4722
5147
  return table.mutate(req);
4723
5148
  } });
4724
5149
  },
@@ -4750,9 +5175,9 @@
4750
5175
  }
4751
5176
 
4752
5177
  var observabilityMiddleware = {
4753
- stack: "dbcore",
5178
+ stack: 'dbcore',
4754
5179
  level: 0,
4755
- name: "Observability",
5180
+ name: 'Observability',
4756
5181
  create: function (core) {
4757
5182
  var dbName = core.schema.name;
4758
5183
  var FULL_RANGE = new RangeSet(core.MIN_KEY, core.MAX_KEY);
@@ -4766,7 +5191,11 @@
4766
5191
  var schema = table.schema;
4767
5192
  var primaryKey = schema.primaryKey, indexes = schema.indexes;
4768
5193
  var extractKey = primaryKey.extractKey, outbound = primaryKey.outbound;
4769
- var indexesWithAutoIncPK = primaryKey.autoIncrement && indexes.filter(function (index) { return index.compound && index.keyPath.includes(primaryKey.keyPath); });
5194
+ var indexesWithAutoIncPK = primaryKey.autoIncrement &&
5195
+ indexes.filter(function (index) {
5196
+ return index.compound &&
5197
+ index.keyPath.includes(primaryKey.keyPath);
5198
+ });
4770
5199
  var tableClone = __assign(__assign({}, table), { mutate: function (req) {
4771
5200
  var _a, _b;
4772
5201
  var trans = req.trans;
@@ -4776,20 +5205,25 @@
4776
5205
  return (mutatedParts[part] ||
4777
5206
  (mutatedParts[part] = new RangeSet()));
4778
5207
  };
4779
- var pkRangeSet = getRangeSet("");
4780
- var delsRangeSet = getRangeSet(":dels");
5208
+ var pkRangeSet = getRangeSet('');
5209
+ var delsRangeSet = getRangeSet(':dels');
4781
5210
  var type = req.type;
4782
- var _c = req.type === "deleteRange"
5211
+ var _c = req.type === 'deleteRange'
4783
5212
  ? [req.range]
4784
- : req.type === "delete"
5213
+ : req.type === 'delete'
4785
5214
  ? [req.keys]
4786
5215
  : req.values.length < 50
4787
- ? [getEffectiveKeys(primaryKey, req).filter(function (id) { return id; }), req.values]
5216
+ ? [
5217
+ getEffectiveKeys(primaryKey, req).filter(function (id) { return id; }),
5218
+ req.values,
5219
+ ]
4788
5220
  : [], keys = _c[0], newObjs = _c[1];
4789
- var oldCache = req.trans["_cache"];
5221
+ var oldCache = req.trans['_cache'];
4790
5222
  if (isArray(keys)) {
4791
5223
  pkRangeSet.addKeys(keys);
4792
- var oldObjs = type === 'delete' || keys.length === newObjs.length ? getFromTransactionCache(keys, oldCache) : null;
5224
+ var oldObjs = type === 'delete' || keys.length === newObjs.length
5225
+ ? getFromTransactionCache(keys, oldCache)
5226
+ : null;
4793
5227
  if (!oldObjs) {
4794
5228
  delsRangeSet.addKeys(keys);
4795
5229
  }
@@ -4800,7 +5234,7 @@
4800
5234
  else if (keys) {
4801
5235
  var range = {
4802
5236
  from: (_a = keys.lower) !== null && _a !== void 0 ? _a : core.MIN_KEY,
4803
- to: (_b = keys.upper) !== null && _b !== void 0 ? _b : core.MAX_KEY
5237
+ to: (_b = keys.upper) !== null && _b !== void 0 ? _b : core.MAX_KEY,
4804
5238
  };
4805
5239
  delsRangeSet.add(range);
4806
5240
  pkRangeSet.add(range);
@@ -4808,7 +5242,9 @@
4808
5242
  else {
4809
5243
  pkRangeSet.add(FULL_RANGE);
4810
5244
  delsRangeSet.add(FULL_RANGE);
4811
- schema.indexes.forEach(function (idx) { return getRangeSet(idx.name).add(FULL_RANGE); });
5245
+ schema.indexes.forEach(function (idx) {
5246
+ return getRangeSet(idx.name).add(FULL_RANGE);
5247
+ });
4812
5248
  }
4813
5249
  return table.mutate(req).then(function (res) {
4814
5250
  if (keys && (req.type === 'add' || req.type === 'put')) {
@@ -4847,9 +5283,10 @@
4847
5283
  tableClone[method] = function (req) {
4848
5284
  var subscr = PSD.subscr;
4849
5285
  var isLiveQuery = !!subscr;
4850
- var cachable = isCachableContext(PSD, table) && isCachableRequest(method, req);
5286
+ var cachable = isCachableContext(PSD, table) &&
5287
+ isCachableRequest(method, req);
4851
5288
  var obsSet = cachable
4852
- ? req.obsSet = {}
5289
+ ? (req.obsSet = {})
4853
5290
  : subscr;
4854
5291
  if (isLiveQuery) {
4855
5292
  var getRangeSet = function (indexName) {
@@ -4857,26 +5294,28 @@
4857
5294
  return (obsSet[part] ||
4858
5295
  (obsSet[part] = new RangeSet()));
4859
5296
  };
4860
- var pkRangeSet_1 = getRangeSet("");
4861
- var delsRangeSet_1 = getRangeSet(":dels");
5297
+ var pkRangeSet_1 = getRangeSet('');
5298
+ var delsRangeSet_1 = getRangeSet(':dels');
4862
5299
  var _a = readSubscribers[method](req), queriedIndex = _a[0], queriedRanges = _a[1];
4863
- if (method === 'query' && queriedIndex.isPrimaryKey && !req.values) {
5300
+ if (method === 'query' &&
5301
+ queriedIndex.isPrimaryKey &&
5302
+ !req.values) {
4864
5303
  delsRangeSet_1.add(queriedRanges);
4865
5304
  }
4866
5305
  else {
4867
- getRangeSet(queriedIndex.name || "").add(queriedRanges);
5306
+ getRangeSet(queriedIndex.name || '').add(queriedRanges);
4868
5307
  }
4869
5308
  if (!queriedIndex.isPrimaryKey) {
4870
- if (method === "count") {
5309
+ if (method === 'count') {
4871
5310
  delsRangeSet_1.add(FULL_RANGE);
4872
5311
  }
4873
5312
  else {
4874
- var keysPromise_1 = method === "query" &&
5313
+ var keysPromise_1 = method === 'query' &&
4875
5314
  outbound &&
4876
5315
  req.values &&
4877
5316
  table.query(__assign(__assign({}, req), { values: false }));
4878
5317
  return table[method].apply(this, arguments).then(function (res) {
4879
- if (method === "query") {
5318
+ if (method === 'query') {
4880
5319
  if (outbound && req.values) {
4881
5320
  return keysPromise_1.then(function (_a) {
4882
5321
  var resultingKeys = _a.result;
@@ -4894,9 +5333,10 @@
4894
5333
  delsRangeSet_1.addKeys(pKeys);
4895
5334
  }
4896
5335
  }
4897
- else if (method === "openCursor") {
5336
+ else if (method === 'openCursor') {
4898
5337
  var cursor_1 = res;
4899
- var wantValues_1 = req.values;
5338
+ var wantValues_1 = req
5339
+ .values;
4900
5340
  return (cursor_1 &&
4901
5341
  Object.create(cursor_1, {
4902
5342
  key: {
@@ -4914,7 +5354,8 @@
4914
5354
  },
4915
5355
  value: {
4916
5356
  get: function () {
4917
- wantValues_1 && pkRangeSet_1.addKey(cursor_1.primaryKey);
5357
+ wantValues_1 &&
5358
+ pkRangeSet_1.addKey(cursor_1.primaryKey);
4918
5359
  return cursor_1.value;
4919
5360
  },
4920
5361
  },
@@ -4934,13 +5375,17 @@
4934
5375
  };
4935
5376
  function trackAffectedIndexes(getRangeSet, schema, oldObjs, newObjs) {
4936
5377
  function addAffectedIndex(ix) {
4937
- var rangeSet = getRangeSet(ix.name || "");
5378
+ var rangeSet = getRangeSet(ix.name || '');
4938
5379
  function extractKey(obj) {
4939
5380
  return obj != null ? ix.extractKey(obj) : null;
4940
5381
  }
4941
- var addKeyOrKeys = function (key) { return ix.multiEntry && isArray(key)
4942
- ? key.forEach(function (key) { return rangeSet.addKey(key); })
4943
- : rangeSet.addKey(key); };
5382
+ var addKeyOrKeys = function (key) {
5383
+ return ix.multiEntry && isArray(key)
5384
+ ?
5385
+ key.forEach(function (key) { return rangeSet.addKey(key); })
5386
+ :
5387
+ rangeSet.addKey(key);
5388
+ };
4944
5389
  (oldObjs || newObjs).forEach(function (_, i) {
4945
5390
  var oldKey = oldObjs && extractKey(oldObjs[i]);
4946
5391
  var newKey = newObjs && extractKey(newObjs[i]);
@@ -5154,7 +5599,8 @@
5154
5599
  var _a;
5155
5600
  return entry.req.limit === req.limit &&
5156
5601
  entry.req.values === req.values &&
5157
- ((_a = entry.req.direction) !== null && _a !== void 0 ? _a : 'next') === reqDirection_1 &&
5602
+ ((_a = entry.req.direction) !== null && _a !== void 0 ? _a : 'next') ===
5603
+ reqDirection_1 &&
5158
5604
  areRangesEqual(entry.req.query.range, req.query.range);
5159
5605
  });
5160
5606
  if (equalEntry)
@@ -5168,7 +5614,8 @@
5168
5614
  var _a;
5169
5615
  var limit = 'limit' in entry.req ? entry.req.limit : Infinity;
5170
5616
  return (limit >= req.limit &&
5171
- ((_a = entry.req.direction) !== null && _a !== void 0 ? _a : 'next') === reqDirection_1 &&
5617
+ ((_a = entry.req.direction) !== null && _a !== void 0 ? _a : 'next') ===
5618
+ reqDirection_1 &&
5172
5619
  (req.values ? entry.req.values : true) &&
5173
5620
  isSuperRange(entry.req.query.range, req.query.range));
5174
5621
  });
@@ -5183,7 +5630,7 @@
5183
5630
 
5184
5631
  function subscribeToCacheEntry(cacheEntry, container, requery, signal) {
5185
5632
  cacheEntry.subscribers.add(requery);
5186
- signal.addEventListener("abort", function () {
5633
+ signal.addEventListener('abort', function () {
5187
5634
  cacheEntry.subscribers.delete(requery);
5188
5635
  if (cacheEntry.subscribers.size === 0) {
5189
5636
  enqueForDeletion(cacheEntry, container);
@@ -5219,14 +5666,18 @@
5219
5666
  if (tblCache) {
5220
5667
  var table = core.table(storeName);
5221
5668
  var ops = tblCache.optimisticOps.filter(function (op) { return op.trans === idbtrans; });
5222
- if (idbtrans._explicit && wasCommitted && idbtrans.mutatedParts) {
5669
+ if (idbtrans._explicit &&
5670
+ wasCommitted &&
5671
+ idbtrans.mutatedParts) {
5223
5672
  for (var _a = 0, _b = Object.values(tblCache.queries.query); _a < _b.length; _a++) {
5224
5673
  var entries = _b[_a];
5225
5674
  for (var _c = 0, _d = entries.slice(); _c < _d.length; _c++) {
5226
5675
  var entry = _d[_c];
5227
5676
  if (obsSetsOverlap(entry.obsSet, idbtrans.mutatedParts)) {
5228
5677
  delArrayItem(entries, entry);
5229
- entry.subscribers.forEach(function (requery) { return affectedSubscribers_1.add(requery); });
5678
+ entry.subscribers.forEach(function (requery) {
5679
+ return affectedSubscribers_1.add(requery);
5680
+ });
5230
5681
  }
5231
5682
  }
5232
5683
  }
@@ -5245,18 +5696,24 @@
5245
5696
  var modRes = applyOptimisticOps(entry.res, entry.req, ops, table, entry, freezeResults);
5246
5697
  if (entry.dirty) {
5247
5698
  delArrayItem(entries, entry);
5248
- entry.subscribers.forEach(function (requery) { return affectedSubscribers_1.add(requery); });
5699
+ entry.subscribers.forEach(function (requery) {
5700
+ return affectedSubscribers_1.add(requery);
5701
+ });
5249
5702
  }
5250
5703
  else if (modRes !== entry.res) {
5251
5704
  entry.res = modRes;
5252
- entry.promise = DexiePromise.resolve({ result: modRes });
5705
+ entry.promise = DexiePromise.resolve({
5706
+ result: modRes,
5707
+ });
5253
5708
  }
5254
5709
  }
5255
5710
  else {
5256
5711
  if (entry.dirty) {
5257
5712
  delArrayItem(entries, entry);
5258
5713
  }
5259
- entry.subscribers.forEach(function (requery) { return affectedSubscribers_1.add(requery); });
5714
+ entry.subscribers.forEach(function (requery) {
5715
+ return affectedSubscribers_1.add(requery);
5716
+ });
5260
5717
  }
5261
5718
  }
5262
5719
  }
@@ -5294,7 +5751,9 @@
5294
5751
  if (!tblCache)
5295
5752
  return downTable.mutate(req);
5296
5753
  var promise = downTable.mutate(req);
5297
- if ((req.type === 'add' || req.type === 'put') && (req.values.length >= 50 || getEffectiveKeys(primKey, req).some(function (key) { return key == null; }))) {
5754
+ if ((req.type === 'add' || req.type === 'put') &&
5755
+ (req.values.length >= 50 ||
5756
+ getEffectiveKeys(primKey, req).some(function (key) { return key == null; }))) {
5298
5757
  promise.then(function (res) {
5299
5758
  var reqWithResolvedKeys = __assign(__assign({}, req), { values: req.values.map(function (value, i) {
5300
5759
  var _a;
@@ -5308,7 +5767,10 @@
5308
5767
  }) });
5309
5768
  var adjustedReq = adjustOptimisticFromFailures(tblCache, reqWithResolvedKeys, res);
5310
5769
  tblCache.optimisticOps.push(adjustedReq);
5311
- queueMicrotask(function () { return req.mutatedParts && signalSubscribersLazily(req.mutatedParts); });
5770
+ queueMicrotask(function () {
5771
+ return req.mutatedParts &&
5772
+ signalSubscribersLazily(req.mutatedParts);
5773
+ });
5312
5774
  });
5313
5775
  }
5314
5776
  else {
@@ -5332,16 +5794,20 @@
5332
5794
  return promise;
5333
5795
  }, query: function (req) {
5334
5796
  var _a;
5335
- if (!isCachableContext(PSD, downTable) || !isCachableRequest("query", req))
5797
+ if (!isCachableContext(PSD, downTable) ||
5798
+ !isCachableRequest('query', req))
5336
5799
  return downTable.query(req);
5337
- var freezeResults = ((_a = PSD.trans) === null || _a === void 0 ? void 0 : _a.db._options.cache) === 'immutable';
5800
+ var freezeResults = ((_a = PSD.trans) === null || _a === void 0 ? void 0 : _a.db._options.cache) ===
5801
+ 'immutable';
5338
5802
  var _b = PSD, requery = _b.requery, signal = _b.signal;
5339
5803
  var _c = findCompatibleQuery(dbName, tableName, 'query', req), cacheEntry = _c[0], exactMatch = _c[1], tblCache = _c[2], container = _c[3];
5340
5804
  if (cacheEntry && exactMatch) {
5341
5805
  cacheEntry.obsSet = req.obsSet;
5342
5806
  }
5343
5807
  else {
5344
- var promise = downTable.query(req).then(function (res) {
5808
+ var promise = downTable
5809
+ .query(req)
5810
+ .then(function (res) {
5345
5811
  var result = res.result;
5346
5812
  if (cacheEntry)
5347
5813
  cacheEntry.res = result;
@@ -5355,7 +5821,8 @@
5355
5821
  res.result = deepClone(result);
5356
5822
  }
5357
5823
  return res;
5358
- }).catch(function (error) {
5824
+ })
5825
+ .catch(function (error) {
5359
5826
  if (container && cacheEntry)
5360
5827
  delArrayItem(container, cacheEntry);
5361
5828
  return Promise.reject(error);
@@ -5381,7 +5848,7 @@
5381
5848
  },
5382
5849
  objs: new Map(),
5383
5850
  optimisticOps: [],
5384
- unsignaledParts: {}
5851
+ unsignaledParts: {},
5385
5852
  };
5386
5853
  }
5387
5854
  tblCache.queries.query[req.query.index.name || ''] = container;
@@ -5406,7 +5873,7 @@
5406
5873
  if (prop === 'db')
5407
5874
  return vipDb;
5408
5875
  return Reflect.get(target, prop, receiver);
5409
- }
5876
+ },
5410
5877
  });
5411
5878
  }
5412
5879
 
@@ -5421,7 +5888,7 @@
5421
5888
  indexedDB: deps.indexedDB, IDBKeyRange: deps.IDBKeyRange, cache: 'cloned', maxConnections: DEFAULT_MAX_CONNECTIONS }, options);
5422
5889
  this._deps = {
5423
5890
  indexedDB: options.indexedDB,
5424
- IDBKeyRange: options.IDBKeyRange
5891
+ IDBKeyRange: options.IDBKeyRange,
5425
5892
  };
5426
5893
  var addons = options.addons;
5427
5894
  this._dbSchema = {};
@@ -5451,7 +5918,9 @@
5451
5918
  });
5452
5919
  this._state = state;
5453
5920
  this.name = name;
5454
- this.on = Events(this, "populate", "blocked", "versionchange", "close", { ready: [promisableChain, nop] });
5921
+ this.on = Events(this, 'populate', 'blocked', 'versionchange', 'close', {
5922
+ ready: [promisableChain, nop],
5923
+ });
5455
5924
  this.once = function (event, callback) {
5456
5925
  var fn = function () {
5457
5926
  var args = [];
@@ -5495,26 +5964,29 @@
5495
5964
  this.Transaction = createTransactionConstructor(this);
5496
5965
  this.Version = createVersionConstructor(this);
5497
5966
  this.WhereClause = createWhereClauseConstructor(this);
5498
- this.on("versionchange", function (ev) {
5967
+ this.on('versionchange', function (ev) {
5499
5968
  if (ev.newVersion > 0)
5500
5969
  console.warn("Another connection wants to upgrade database '".concat(_this.name, "'. Closing db now to resume the upgrade."));
5501
5970
  else
5502
5971
  console.warn("Another connection wants to delete database '".concat(_this.name, "'. Closing db now to resume the delete request."));
5503
5972
  _this.close({ disableAutoOpen: false });
5504
5973
  });
5505
- this.on("blocked", function (ev) {
5974
+ this.on('blocked', function (ev) {
5506
5975
  if (!ev.newVersion || ev.newVersion < ev.oldVersion)
5507
5976
  console.warn("Dexie.delete('".concat(_this.name, "') was blocked"));
5508
5977
  else
5509
5978
  console.warn("Upgrade '".concat(_this.name, "' blocked by other connection holding version ").concat(ev.oldVersion / 10));
5510
5979
  });
5511
5980
  this._maxKey = getMaxKey(options.IDBKeyRange);
5512
- this._createTransaction = function (mode, storeNames, dbschema, parentTransaction) { return new _this.Transaction(mode, storeNames, dbschema, _this._options.chromeTransactionDurability, parentTransaction); };
5981
+ this._createTransaction = function (mode, storeNames, dbschema, parentTransaction) {
5982
+ return new _this.Transaction(mode, storeNames, dbschema, _this._options.chromeTransactionDurability, parentTransaction);
5983
+ };
5513
5984
  this._fireOnBlocked = function (ev) {
5514
- _this.on("blocked").fire(ev);
5515
- connections.toArray()
5985
+ _this.on('blocked').fire(ev);
5986
+ connections
5987
+ .toArray()
5516
5988
  .filter(function (c) { return c.name === _this.name && c !== _this && !c._state.vcFired; })
5517
- .map(function (c) { return c.on("versionchange").fire(ev); });
5989
+ .map(function (c) { return c.on('versionchange').fire(ev); });
5518
5990
  };
5519
5991
  this.use(cacheExistingValuesMiddleware);
5520
5992
  this.use(cacheMiddleware);
@@ -5538,7 +6010,7 @@
5538
6010
  return vipify(tx, vipDB);
5539
6011
  };
5540
6012
  return rv;
5541
- }
6013
+ },
5542
6014
  });
5543
6015
  this.vip = vipDB;
5544
6016
  addons.forEach(function (addon) { return addon(_this); });
@@ -5548,7 +6020,7 @@
5548
6020
  throw new exceptions.Type("Given version is not a positive number");
5549
6021
  versionNumber = Math.round(versionNumber * 10) / 10;
5550
6022
  if (this.idbdb || this._state.isBeingOpened)
5551
- throw new exceptions.Schema("Cannot add version when database is open");
6023
+ throw new exceptions.Schema('Cannot add version when database is open');
5552
6024
  this.verno = Math.max(this.verno, versionNumber);
5553
6025
  var versions = this._versions;
5554
6026
  var versionInstance = versions.filter(function (v) { return v._cfg.version === versionNumber; })[0];
@@ -5563,26 +6035,34 @@
5563
6035
  };
5564
6036
  Dexie.prototype._whenReady = function (fn) {
5565
6037
  var _this = this;
5566
- return (this.idbdb && (this._state.openComplete || PSD.letThrough || this._vip)) ? fn() : new DexiePromise(function (resolve, reject) {
5567
- if (_this._state.openComplete) {
5568
- return reject(new exceptions.DatabaseClosed(_this._state.dbOpenError));
5569
- }
5570
- if (!_this._state.isBeingOpened) {
5571
- if (!_this._state.autoOpen) {
5572
- reject(new exceptions.DatabaseClosed());
5573
- return;
6038
+ return this.idbdb &&
6039
+ (this._state.openComplete || PSD.letThrough || this._vip)
6040
+ ? fn()
6041
+ : new DexiePromise(function (resolve, reject) {
6042
+ if (_this._state.openComplete) {
6043
+ return reject(new exceptions.DatabaseClosed(_this._state.dbOpenError));
5574
6044
  }
5575
- _this.open().catch(nop);
5576
- }
5577
- _this._state.dbReadyPromise.then(resolve, reject);
5578
- }).then(fn);
6045
+ if (!_this._state.isBeingOpened) {
6046
+ if (!_this._state.autoOpen) {
6047
+ reject(new exceptions.DatabaseClosed());
6048
+ return;
6049
+ }
6050
+ _this.open().catch(nop);
6051
+ }
6052
+ _this._state.dbReadyPromise.then(resolve, reject);
6053
+ }).then(fn);
5579
6054
  };
5580
6055
  Dexie.prototype.use = function (_a) {
5581
6056
  var stack = _a.stack, create = _a.create, level = _a.level, name = _a.name;
5582
6057
  if (name)
5583
6058
  this.unuse({ stack: stack, name: name });
5584
6059
  var middlewares = this._middlewares[stack] || (this._middlewares[stack] = []);
5585
- middlewares.push({ stack: stack, create: create, level: level == null ? 10 : level, name: name });
6060
+ middlewares.push({
6061
+ stack: stack,
6062
+ create: create,
6063
+ level: level == null ? 10 : level,
6064
+ name: name,
6065
+ });
5586
6066
  middlewares.sort(function (a, b) { return a.level - b.level; });
5587
6067
  return this;
5588
6068
  };
@@ -5590,9 +6070,11 @@
5590
6070
  var stack = _a.stack, name = _a.name, create = _a.create;
5591
6071
  if (stack && this._middlewares[stack]) {
5592
6072
  this._middlewares[stack] = this._middlewares[stack].filter(function (mw) {
5593
- return create ? mw.create !== create :
5594
- name ? mw.name !== name :
5595
- false;
6073
+ return create
6074
+ ? mw.create !== create
6075
+ : name
6076
+ ? mw.name !== name
6077
+ : false;
5596
6078
  });
5597
6079
  }
5598
6080
  return this;
@@ -5635,8 +6117,7 @@
5635
6117
  }
5636
6118
  else {
5637
6119
  this._close();
5638
- state.autoOpen = this._options.autoOpen ||
5639
- state.isBeingOpened;
6120
+ state.autoOpen = this._options.autoOpen || state.isBeingOpened;
5640
6121
  state.openComplete = false;
5641
6122
  state.dbOpenError = null;
5642
6123
  }
@@ -5658,7 +6139,7 @@
5658
6139
  req.onblocked = _this._fireOnBlocked;
5659
6140
  };
5660
6141
  if (hasInvalidArguments)
5661
- throw new exceptions.InvalidArgument("Invalid closeOptions argument to db.delete()");
6142
+ throw new exceptions.InvalidArgument('Invalid closeOptions argument to db.delete()');
5662
6143
  if (state.isBeingOpened) {
5663
6144
  state.dbReadyPromise.then(doDelete);
5664
6145
  }
@@ -5675,7 +6156,7 @@
5675
6156
  };
5676
6157
  Dexie.prototype.hasBeenClosed = function () {
5677
6158
  var dbOpenError = this._state.dbOpenError;
5678
- return dbOpenError && (dbOpenError.name === 'DatabaseClosed');
6159
+ return dbOpenError && dbOpenError.name === 'DatabaseClosed';
5679
6160
  };
5680
6161
  Dexie.prototype.hasFailed = function () {
5681
6162
  return this._state.dbOpenError !== null;
@@ -5698,7 +6179,9 @@
5698
6179
  Dexie.prototype._transaction = function (mode, tables, scopeFunc) {
5699
6180
  var _this = this;
5700
6181
  var parentTransaction = PSD.trans;
5701
- if (!parentTransaction || parentTransaction.db !== this || mode.indexOf('!') !== -1)
6182
+ if (!parentTransaction ||
6183
+ parentTransaction.db !== this ||
6184
+ mode.indexOf('!') !== -1)
5702
6185
  parentTransaction = null;
5703
6186
  var onlyIfCompatible = mode.indexOf('?') !== -1;
5704
6187
  mode = mode.replace('!', '').replace('?', '');
@@ -5707,51 +6190,56 @@
5707
6190
  storeNames = tables.map(function (table) {
5708
6191
  var storeName = table instanceof _this.Table ? table.name : table;
5709
6192
  if (typeof storeName !== 'string')
5710
- throw new TypeError("Invalid table argument to Dexie.transaction(). Only Table or String are allowed");
6193
+ throw new TypeError('Invalid table argument to Dexie.transaction(). Only Table or String are allowed');
5711
6194
  return storeName;
5712
6195
  });
5713
- if (mode == "r" || mode === READONLY)
6196
+ if (mode == 'r' || mode === READONLY)
5714
6197
  idbMode = READONLY;
5715
- else if (mode == "rw" || mode == READWRITE)
6198
+ else if (mode == 'rw' || mode == READWRITE)
5716
6199
  idbMode = READWRITE;
5717
6200
  else
5718
- throw new exceptions.InvalidArgument("Invalid transaction mode: " + mode);
6201
+ throw new exceptions.InvalidArgument('Invalid transaction mode: ' + mode);
5719
6202
  if (parentTransaction) {
5720
6203
  if (parentTransaction.mode === READONLY && idbMode === READWRITE) {
5721
6204
  if (onlyIfCompatible) {
5722
6205
  parentTransaction = null;
5723
6206
  }
5724
6207
  else
5725
- throw new exceptions.SubTransaction("Cannot enter a sub-transaction with READWRITE mode when parent transaction is READONLY");
6208
+ throw new exceptions.SubTransaction('Cannot enter a sub-transaction with READWRITE mode when parent transaction is READONLY');
5726
6209
  }
5727
6210
  if (parentTransaction) {
5728
6211
  storeNames.forEach(function (storeName) {
5729
- if (parentTransaction && parentTransaction.storeNames.indexOf(storeName) === -1) {
6212
+ if (parentTransaction &&
6213
+ parentTransaction.storeNames.indexOf(storeName) === -1) {
5730
6214
  if (onlyIfCompatible) {
5731
6215
  parentTransaction = null;
5732
6216
  }
5733
6217
  else
5734
- throw new exceptions.SubTransaction("Table " + storeName +
5735
- " not included in parent transaction.");
6218
+ throw new exceptions.SubTransaction('Table ' + storeName + ' not included in parent transaction.');
5736
6219
  }
5737
6220
  });
5738
6221
  }
5739
- if (onlyIfCompatible && parentTransaction && !parentTransaction.active) {
6222
+ if (onlyIfCompatible &&
6223
+ parentTransaction &&
6224
+ !parentTransaction.active) {
5740
6225
  parentTransaction = null;
5741
6226
  }
5742
6227
  }
5743
6228
  }
5744
6229
  catch (e) {
5745
- return parentTransaction ?
5746
- parentTransaction._promise(null, function (_, reject) { reject(e); }) :
5747
- rejection(e);
6230
+ return parentTransaction
6231
+ ? parentTransaction._promise(null, function (_, reject) {
6232
+ reject(e);
6233
+ })
6234
+ : rejection(e);
5748
6235
  }
5749
6236
  var enterTransaction = enterTransactionScope.bind(null, this, idbMode, storeNames, parentTransaction, scopeFunc);
5750
- return (parentTransaction ?
5751
- parentTransaction._promise(idbMode, enterTransaction, "lock") :
5752
- PSD.trans ?
5753
- usePSD(PSD.transless, function () { return _this._whenReady(enterTransaction); }) :
5754
- this._whenReady(enterTransaction));
6237
+ return parentTransaction
6238
+ ? parentTransaction._promise(idbMode, enterTransaction, 'lock')
6239
+ : PSD.trans
6240
+ ?
6241
+ usePSD(PSD.transless, function () { return _this._whenReady(enterTransaction); })
6242
+ : this._whenReady(enterTransaction);
5755
6243
  };
5756
6244
  Dexie.prototype.table = function (tableName) {
5757
6245
  if (!hasOwn(this._allTables, tableName)) {
@@ -5762,15 +6250,15 @@
5762
6250
  return Dexie;
5763
6251
  }());
5764
6252
 
5765
- var symbolObservable = typeof Symbol !== "undefined" && "observable" in Symbol
6253
+ var symbolObservable = typeof Symbol !== 'undefined' && 'observable' in Symbol
5766
6254
  ? Symbol.observable
5767
- : "@@observable";
6255
+ : '@@observable';
5768
6256
  var Observable = (function () {
5769
6257
  function Observable(subscribe) {
5770
6258
  this._subscribe = subscribe;
5771
6259
  }
5772
6260
  Observable.prototype.subscribe = function (x, error, complete) {
5773
- return this._subscribe(!x || typeof x === "function" ? { next: x, error: error, complete: complete } : x);
6261
+ return this._subscribe(!x || typeof x === 'function' ? { next: x, error: error, complete: complete } : x);
5774
6262
  };
5775
6263
  Observable.prototype[symbolObservable] = function () {
5776
6264
  return this;
@@ -5781,8 +6269,11 @@
5781
6269
  var domDeps;
5782
6270
  try {
5783
6271
  domDeps = {
5784
- indexedDB: _global.indexedDB || _global.mozIndexedDB || _global.webkitIndexedDB || _global.msIndexedDB,
5785
- IDBKeyRange: _global.IDBKeyRange || _global.webkitIDBKeyRange
6272
+ indexedDB: _global.indexedDB ||
6273
+ _global.mozIndexedDB ||
6274
+ _global.webkitIndexedDB ||
6275
+ _global.msIndexedDB,
6276
+ IDBKeyRange: _global.IDBKeyRange || _global.webkitIDBKeyRange,
5786
6277
  };
5787
6278
  }
5788
6279
  catch (e) {
@@ -5909,10 +6400,13 @@
5909
6400
  return db.delete();
5910
6401
  },
5911
6402
  exists: function (name) {
5912
- return new Dexie(name, { addons: [] }).open().then(function (db) {
6403
+ return new Dexie(name, { addons: [] })
6404
+ .open()
6405
+ .then(function (db) {
5913
6406
  db.close();
5914
6407
  return true;
5915
- }).catch('NoSuchDatabaseError', function () { return false; });
6408
+ })
6409
+ .catch('NoSuchDatabaseError', function () { return false; });
5916
6410
  },
5917
6411
  getDatabaseNames: function (cb) {
5918
6412
  try {
@@ -5928,9 +6422,9 @@
5928
6422
  }
5929
6423
  return Class;
5930
6424
  }, ignoreTransaction: function (scopeFunc) {
5931
- return PSD.trans ?
5932
- usePSD(PSD.transless, scopeFunc) :
5933
- scopeFunc();
6425
+ return PSD.trans
6426
+ ? usePSD(PSD.transless || globalPSD, scopeFunc)
6427
+ : scopeFunc();
5934
6428
  }, vip: vip, async: function (generatorFn) {
5935
6429
  return function () {
5936
6430
  try {
@@ -5955,22 +6449,19 @@
5955
6449
  }
5956
6450
  },
5957
6451
  currentTransaction: {
5958
- get: function () { return PSD.trans || null; }
6452
+ get: function () { return PSD.trans || null; },
5959
6453
  }, waitFor: function (promiseOrFunction, optionalTimeout) {
5960
- var promise = DexiePromise.resolve(typeof promiseOrFunction === 'function' ?
5961
- Dexie.ignoreTransaction(promiseOrFunction) :
5962
- promiseOrFunction)
5963
- .timeout(optionalTimeout || 60000);
5964
- return PSD.trans ?
5965
- PSD.trans.waitFor(promise) :
5966
- promise;
6454
+ var promise = DexiePromise.resolve(typeof promiseOrFunction === 'function'
6455
+ ? Dexie.ignoreTransaction(promiseOrFunction)
6456
+ : promiseOrFunction).timeout(optionalTimeout || 60000);
6457
+ return PSD.trans ? PSD.trans.waitFor(promise) : promise;
5967
6458
  },
5968
6459
  Promise: DexiePromise,
5969
6460
  debug: {
5970
6461
  get: function () { return debug; },
5971
6462
  set: function (value) {
5972
6463
  setDebug(value);
5973
- }
6464
+ },
5974
6465
  },
5975
6466
  derive: derive, extend: extend, props: props, override: override,
5976
6467
  Events: Events, on: globalEvents, liveQuery: liveQuery, extendObservabilitySet: extendObservabilitySet,
@@ -5978,21 +6469,22 @@
5978
6469
  minKey: minKey,
5979
6470
  addons: [],
5980
6471
  connections: {
5981
- get: connections.toArray
6472
+ get: connections.toArray,
5982
6473
  },
5983
6474
  errnames: errnames,
5984
6475
  dependencies: domDeps, cache: cache,
5985
6476
  semVer: DEXIE_VERSION, version: DEXIE_VERSION.split('.')
5986
6477
  .map(function (n) { return parseInt(n); })
5987
- .reduce(function (p, c, i) { return p + (c / Math.pow(10, i * 2)); }) }));
6478
+ .reduce(function (p, c, i) { return p + c / Math.pow(10, i * 2); }) }));
5988
6479
  Dexie.maxKey = getMaxKey(Dexie.dependencies.IDBKeyRange);
5989
6480
 
5990
- if (typeof dispatchEvent !== 'undefined' && typeof addEventListener !== 'undefined') {
6481
+ if (typeof dispatchEvent !== 'undefined' &&
6482
+ typeof addEventListener !== 'undefined') {
5991
6483
  globalEvents(DEXIE_STORAGE_MUTATED_EVENT_NAME, function (updatedParts) {
5992
6484
  if (!propagatingLocally) {
5993
6485
  var event_1;
5994
6486
  event_1 = new CustomEvent(STORAGE_MUTATED_DOM_EVENT_NAME, {
5995
- detail: updatedParts
6487
+ detail: updatedParts,
5996
6488
  });
5997
6489
  propagatingLocally = true;
5998
6490
  dispatchEvent(event_1);