dexie 4.4.0 → 4.4.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.0, Wed Mar 18 2026
7
+ * Version 4.4.2, Tue Mar 31 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,24 +227,25 @@
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
  }
231
- function objectIsEmpty(o) {
232
- for (var k in o)
233
- if (hasOwn(o, k))
234
- return false;
235
- return true;
236
- }
237
249
  var circularRefs = null;
238
250
  function deepClone(any) {
239
251
  circularRefs = new WeakMap();
@@ -273,13 +285,15 @@
273
285
  function toStringTag(o) {
274
286
  return toString.call(o).slice(8, -1);
275
287
  }
276
- var iteratorSymbol = typeof Symbol !== 'undefined' ?
277
- Symbol.iterator :
278
- '@@iterator';
279
- var getIteratorOf = typeof iteratorSymbol === "symbol" ? function (x) {
280
- var i;
281
- return x != null && (i = x[iteratorSymbol]) && i.apply(x);
282
- } : 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
+ };
283
297
  function delArrayItem(a, x) {
284
298
  var i = a.indexOf(x);
285
299
  if (i >= 0)
@@ -296,7 +310,7 @@
296
310
  return [arrayLike];
297
311
  if ((it = getIteratorOf(arrayLike))) {
298
312
  a = [];
299
- while ((x = it.next()), !x.done)
313
+ while (((x = it.next()), !x.done))
300
314
  a.push(x.value);
301
315
  return a;
302
316
  }
@@ -337,7 +351,7 @@
337
351
  'Internal',
338
352
  'DatabaseClosed',
339
353
  'PrematureCommit',
340
- 'ForeignAwait'
354
+ 'ForeignAwait',
341
355
  ];
342
356
  var idbDomErrorNames = [
343
357
  'Unknown',
@@ -353,28 +367,34 @@
353
367
  'Timeout',
354
368
  'QuotaExceeded',
355
369
  'Syntax',
356
- 'DataClone'
370
+ 'DataClone',
357
371
  ];
358
372
  var errorList = dexieErrorNames.concat(idbDomErrorNames);
359
373
  var defaultTexts = {
360
- VersionChanged: "Database version changed by other database connection",
361
- DatabaseClosed: "Database has been closed",
362
- Abort: "Transaction aborted",
363
- TransactionInactive: "Transaction has already completed or failed",
364
- 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',
365
379
  };
366
380
  function DexieError(name, msg) {
367
381
  this.name = name;
368
382
  this.message = msg;
369
383
  }
370
- derive(DexieError).from(Error).extend({
371
- 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
+ },
372
390
  });
373
391
  function getMultiErrorMessage(msg, failures) {
374
- return msg + ". Errors: " + Object.keys(failures)
375
- .map(function (key) { return failures[key].toString(); })
376
- .filter(function (v, i, s) { return s.indexOf(v) === i; })
377
- .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'));
378
398
  }
379
399
  function ModifyError(msg, failures, successCount, failedKeys) {
380
400
  this.failures = failures;
@@ -384,16 +404,16 @@
384
404
  }
385
405
  derive(ModifyError).from(DexieError);
386
406
  function BulkError(msg, failures) {
387
- this.name = "BulkError";
407
+ this.name = 'BulkError';
388
408
  this.failures = Object.keys(failures).map(function (pos) { return failures[pos]; });
389
409
  this.failuresByPos = failures;
390
410
  this.message = getMultiErrorMessage(msg, this.failures);
391
411
  }
392
412
  derive(BulkError).from(DexieError);
393
- 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); }, {});
394
414
  var BaseException = DexieError;
395
415
  var exceptions = errorList.reduce(function (obj, name) {
396
- var fullName = name + "Error";
416
+ var fullName = name + 'Error';
397
417
  function DexieError(msgOrInner, inner) {
398
418
  this.name = fullName;
399
419
  if (!msgOrInner) {
@@ -417,23 +437,30 @@
417
437
  exceptions.Type = TypeError;
418
438
  exceptions.Range = RangeError;
419
439
  var exceptionMap = idbDomErrorNames.reduce(function (obj, name) {
420
- obj[name + "Error"] = exceptions[name];
440
+ obj[name + 'Error'] = exceptions[name];
421
441
  return obj;
422
442
  }, {});
423
443
  function mapError(domError, message) {
424
- 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])
425
450
  return domError;
426
451
  var rv = new exceptionMap[domError.name](message || domError.message, domError);
427
- if ("stack" in domError) {
428
- setProp(rv, "stack", { get: function () {
452
+ if ('stack' in domError) {
453
+ setProp(rv, 'stack', {
454
+ get: function () {
429
455
  return this.inner.stack;
430
- } });
456
+ },
457
+ });
431
458
  }
432
459
  return rv;
433
460
  }
434
461
  var fullNameExceptions = errorList.reduce(function (obj, name) {
435
- if (["Syntax", "Type", "Range"].indexOf(name) === -1)
436
- obj[name + "Error"] = exceptions[name];
462
+ if (['Syntax', 'Type', 'Range'].indexOf(name) === -1)
463
+ obj[name + 'Error'] = exceptions[name];
437
464
  return obj;
438
465
  }, {});
439
466
  fullNameExceptions.ModifyError = ModifyError;
@@ -441,7 +468,9 @@
441
468
  fullNameExceptions.BulkError = BulkError;
442
469
 
443
470
  function nop() { }
444
- function mirror(val) { return val; }
471
+ function mirror(val) {
472
+ return val;
473
+ }
445
474
  function pureFunctionChain(f1, f2) {
446
475
  if (f1 == null || f1 === mirror)
447
476
  return f2;
@@ -468,7 +497,9 @@
468
497
  this.onerror = null;
469
498
  var res2 = f2.apply(this, arguments);
470
499
  if (onsuccess)
471
- this.onsuccess = this.onsuccess ? callBoth(onsuccess, this.onsuccess) : onsuccess;
500
+ this.onsuccess = this.onsuccess
501
+ ? callBoth(onsuccess, this.onsuccess)
502
+ : onsuccess;
472
503
  if (onerror)
473
504
  this.onerror = this.onerror ? callBoth(onerror, this.onerror) : onerror;
474
505
  return res2 !== undefined ? res2 : res;
@@ -484,7 +515,9 @@
484
515
  this.onsuccess = this.onerror = null;
485
516
  f2.apply(this, arguments);
486
517
  if (onsuccess)
487
- this.onsuccess = this.onsuccess ? callBoth(onsuccess, this.onsuccess) : onsuccess;
518
+ this.onsuccess = this.onsuccess
519
+ ? callBoth(onsuccess, this.onsuccess)
520
+ : onsuccess;
488
521
  if (onerror)
489
522
  this.onerror = this.onerror ? callBoth(onerror, this.onerror) : onerror;
490
523
  };
@@ -501,12 +534,16 @@
501
534
  this.onerror = null;
502
535
  var res2 = f2.apply(this, arguments);
503
536
  if (onsuccess)
504
- this.onsuccess = this.onsuccess ? callBoth(onsuccess, this.onsuccess) : onsuccess;
537
+ this.onsuccess = this.onsuccess
538
+ ? callBoth(onsuccess, this.onsuccess)
539
+ : onsuccess;
505
540
  if (onerror)
506
541
  this.onerror = this.onerror ? callBoth(onerror, this.onerror) : onerror;
507
- return res === undefined ?
508
- (res2 === undefined ? undefined : res2) :
509
- (extend(res, res2));
542
+ return res === undefined
543
+ ? res2 === undefined
544
+ ? undefined
545
+ : res2
546
+ : extend(res, res2);
510
547
  };
511
548
  }
512
549
  function reverseStoppableEventChain(f1, f2) {
@@ -542,18 +579,14 @@
542
579
  }
543
580
 
544
581
  var INTERNAL = {};
545
- var ZONE_ECHO_LIMIT = 100, _a$1 = typeof Promise === 'undefined' ?
546
- [] :
547
- (function () {
582
+ var ZONE_ECHO_LIMIT = 100, _a$1 = typeof Promise === 'undefined'
583
+ ? []
584
+ : (function () {
548
585
  var globalP = Promise.resolve();
549
586
  if (typeof crypto === 'undefined' || !crypto.subtle)
550
587
  return [globalP, getProto(globalP), globalP];
551
- var nativeP = crypto.subtle.digest("SHA-512", new Uint8Array([0]));
552
- return [
553
- nativeP,
554
- getProto(nativeP),
555
- globalP
556
- ];
588
+ var nativeP = crypto.subtle.digest('SHA-512', new Uint8Array([0]));
589
+ return [nativeP, getProto(nativeP), globalP];
557
590
  })(), resolvedNativePromise = _a$1[0], nativePromiseProto = _a$1[1], resolvedGlobalPromise = _a$1[2], nativePromiseThen = nativePromiseProto && nativePromiseProto.then;
558
591
  var NativePromise = resolvedNativePromise && resolvedNativePromise.constructor;
559
592
  var patchGlobalPromise = !!resolvedGlobalPromise;
@@ -580,7 +613,7 @@
580
613
  onunhandled: nop,
581
614
  pgp: false,
582
615
  env: {},
583
- finalize: nop
616
+ finalize: nop,
584
617
  };
585
618
  var PSD = globalPSD;
586
619
  var microtickQueue = [];
@@ -624,15 +657,15 @@
624
657
  return then;
625
658
  },
626
659
  set: function (value) {
627
- setProp(this, 'then', value && value.prototype === INTERNAL ?
628
- thenProp :
629
- {
660
+ setProp(this, 'then', value && value.prototype === INTERNAL
661
+ ? thenProp
662
+ : {
630
663
  get: function () {
631
664
  return value;
632
665
  },
633
- set: thenProp.set
666
+ set: thenProp.set,
634
667
  });
635
- }
668
+ },
636
669
  };
637
670
  props(DexiePromise.prototype, {
638
671
  then: thenProp,
@@ -643,9 +676,10 @@
643
676
  if (arguments.length === 1)
644
677
  return this.then(null, onRejected);
645
678
  var type = arguments[0], handler = arguments[1];
646
- return typeof type === 'function' ? this.then(null, function (err) {
647
- return err instanceof type ? handler(err) : PromiseReject(err);
648
- })
679
+ return typeof type === 'function'
680
+ ? this.then(null, function (err) {
681
+ return err instanceof type ? handler(err) : PromiseReject(err);
682
+ })
649
683
  : this.then(null, function (err) {
650
684
  return err && err.name === type ? handler(err) : PromiseReject(err);
651
685
  });
@@ -659,12 +693,13 @@
659
693
  },
660
694
  timeout: function (ms, msg) {
661
695
  var _this = this;
662
- return ms < Infinity ?
663
- new DexiePromise(function (resolve, reject) {
696
+ return ms < Infinity
697
+ ? new DexiePromise(function (resolve, reject) {
664
698
  var handle = setTimeout(function () { return reject(new exceptions.Timeout(msg)); }, ms);
665
699
  _this.then(resolve, reject).finally(clearTimeout.bind(null, handle));
666
- }) : this;
667
- }
700
+ })
701
+ : this;
702
+ },
668
703
  });
669
704
  if (typeof Symbol !== 'undefined' && Symbol.toStringTag)
670
705
  setProp(DexiePromise.prototype, Symbol.toStringTag, 'Dexie.Promise');
@@ -678,17 +713,20 @@
678
713
  }
679
714
  props(DexiePromise, {
680
715
  all: function () {
681
- var values = getArrayOf.apply(null, arguments)
716
+ var values = getArrayOf
717
+ .apply(null, arguments)
682
718
  .map(onPossibleParallellAsync);
683
719
  return new DexiePromise(function (resolve, reject) {
684
720
  if (values.length === 0)
685
721
  resolve([]);
686
722
  var remaining = values.length;
687
- values.forEach(function (a, i) { return DexiePromise.resolve(a).then(function (x) {
688
- values[i] = x;
689
- if (!--remaining)
690
- resolve(values);
691
- }, 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
+ });
692
730
  });
693
731
  },
694
732
  resolve: function (value) {
@@ -703,25 +741,31 @@
703
741
  },
704
742
  reject: PromiseReject,
705
743
  race: function () {
706
- var values = getArrayOf.apply(null, arguments).map(onPossibleParallellAsync);
744
+ var values = getArrayOf
745
+ .apply(null, arguments)
746
+ .map(onPossibleParallellAsync);
707
747
  return new DexiePromise(function (resolve, reject) {
708
748
  values.map(function (value) { return DexiePromise.resolve(value).then(resolve, reject); });
709
749
  });
710
750
  },
711
751
  PSD: {
712
752
  get: function () { return PSD; },
713
- set: function (value) { return PSD = value; }
753
+ set: function (value) { return (PSD = value); },
714
754
  },
715
755
  totalEchoes: { get: function () { return totalEchoes; } },
716
756
  newPSD: newScope,
717
757
  usePSD: usePSD,
718
758
  scheduler: {
719
759
  get: function () { return asap; },
720
- set: function (value) { asap = value; }
760
+ set: function (value) {
761
+ asap = value;
762
+ },
721
763
  },
722
764
  rejectionMapper: {
723
765
  get: function () { return rejectionMapper; },
724
- set: function (value) { rejectionMapper = value; }
766
+ set: function (value) {
767
+ rejectionMapper = value;
768
+ },
725
769
  },
726
770
  follow: function (fn, zoneProps) {
727
771
  return new DexiePromise(function (resolve, reject) {
@@ -732,40 +776,51 @@
732
776
  psd.finalize = callBoth(function () {
733
777
  var _this = this;
734
778
  run_at_end_of_this_or_next_physical_tick(function () {
735
- _this.unhandleds.length === 0 ? resolve() : reject(_this.unhandleds[0]);
779
+ _this.unhandleds.length === 0
780
+ ? resolve()
781
+ : reject(_this.unhandleds[0]);
736
782
  });
737
783
  }, psd.finalize);
738
784
  fn();
739
785
  }, zoneProps, resolve, reject);
740
786
  });
741
- }
787
+ },
742
788
  });
743
789
  if (NativePromise) {
744
790
  if (NativePromise.allSettled)
745
- setProp(DexiePromise, "allSettled", function () {
746
- var possiblePromises = getArrayOf.apply(null, arguments).map(onPossibleParallellAsync);
791
+ setProp(DexiePromise, 'allSettled', function () {
792
+ var possiblePromises = getArrayOf
793
+ .apply(null, arguments)
794
+ .map(onPossibleParallellAsync);
747
795
  return new DexiePromise(function (resolve) {
748
796
  if (possiblePromises.length === 0)
749
797
  resolve([]);
750
798
  var remaining = possiblePromises.length;
751
799
  var results = new Array(remaining);
752
- 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 }; })
753
- .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
+ });
754
805
  });
755
806
  });
756
807
  if (NativePromise.any && typeof AggregateError !== 'undefined')
757
- setProp(DexiePromise, "any", function () {
758
- var possiblePromises = getArrayOf.apply(null, arguments).map(onPossibleParallellAsync);
808
+ setProp(DexiePromise, 'any', function () {
809
+ var possiblePromises = getArrayOf
810
+ .apply(null, arguments)
811
+ .map(onPossibleParallellAsync);
759
812
  return new DexiePromise(function (resolve, reject) {
760
813
  if (possiblePromises.length === 0)
761
814
  reject(new AggregateError([]));
762
815
  var remaining = possiblePromises.length;
763
816
  var failures = new Array(remaining);
764
- possiblePromises.forEach(function (p, i) { return DexiePromise.resolve(p).then(function (value) { return resolve(value); }, function (failure) {
765
- failures[i] = failure;
766
- if (!--remaining)
767
- reject(new AggregateError(failures));
768
- }); });
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
+ });
769
824
  });
770
825
  });
771
826
  if (NativePromise.withResolvers)
@@ -781,9 +836,9 @@
781
836
  var shouldExecuteTick = promise._lib && beginMicroTickScope();
782
837
  if (value && typeof value.then === 'function') {
783
838
  executePromiseTask(promise, function (resolve, reject) {
784
- value instanceof DexiePromise ?
785
- value._then(resolve, reject) :
786
- value.then(resolve, reject);
839
+ value instanceof DexiePromise
840
+ ? value._then(resolve, reject)
841
+ : value.then(resolve, reject);
787
842
  });
788
843
  }
789
844
  else {
@@ -846,7 +901,10 @@
846
901
  var ret, value = promise._value;
847
902
  if (!promise._state && rejectingErrors.length)
848
903
  rejectingErrors = [];
849
- 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);
850
908
  if (!promise._state && rejectingErrors.indexOf(value) === -1) {
851
909
  markErrorAsHandled(promise);
852
910
  }
@@ -957,16 +1015,22 @@
957
1015
  psd.global = false;
958
1016
  psd.id = ++zone_id_counter;
959
1017
  globalPSD.env;
960
- psd.env = patchGlobalPromise ? {
961
- Promise: DexiePromise,
962
- PromiseProp: { value: DexiePromise, configurable: true, writable: true },
963
- all: DexiePromise.all,
964
- race: DexiePromise.race,
965
- allSettled: DexiePromise.allSettled,
966
- any: DexiePromise.any,
967
- resolve: DexiePromise.resolve,
968
- reject: DexiePromise.reject,
969
- } : {};
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
+ : {};
970
1034
  if (props)
971
1035
  extend(psd, props);
972
1036
  ++parent.ref;
@@ -997,7 +1061,9 @@
997
1061
  incrementExpectedAwaits = decrementExpectedAwaits = nop;
998
1062
  }
999
1063
  function onPossibleParallellAsync(possiblePromise) {
1000
- if (task.echoes && possiblePromise && possiblePromise.constructor === NativePromise) {
1064
+ if (task.echoes &&
1065
+ possiblePromise &&
1066
+ possiblePromise.constructor === NativePromise) {
1001
1067
  incrementExpectedAwaits();
1002
1068
  return possiblePromise.then(function (x) {
1003
1069
  decrementExpectedAwaits();
@@ -1024,7 +1090,9 @@
1024
1090
  }
1025
1091
  function switchToZone(targetZone, bEnteringZone) {
1026
1092
  var currentZone = PSD;
1027
- 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)) {
1028
1096
  queueMicrotask(bEnteringZone ? zoneEnterEcho.bind(null, targetZone) : zoneLeaveEcho);
1029
1097
  }
1030
1098
  if (targetZone === PSD)
@@ -1050,16 +1118,18 @@
1050
1118
  }
1051
1119
  function snapShot() {
1052
1120
  var GlobalPromise = _global.Promise;
1053
- return patchGlobalPromise ? {
1054
- Promise: GlobalPromise,
1055
- PromiseProp: Object.getOwnPropertyDescriptor(_global, "Promise"),
1056
- all: GlobalPromise.all,
1057
- race: GlobalPromise.race,
1058
- allSettled: GlobalPromise.allSettled,
1059
- any: GlobalPromise.any,
1060
- resolve: GlobalPromise.resolve,
1061
- reject: GlobalPromise.reject,
1062
- } : {};
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
+ : {};
1063
1133
  }
1064
1134
  function usePSD(psd, fn, a1, a2, a3) {
1065
1135
  var outerScope = PSD;
@@ -1072,20 +1142,22 @@
1072
1142
  }
1073
1143
  }
1074
1144
  function nativeAwaitCompatibleWrap(fn, zone, possibleAwait, cleanup) {
1075
- return typeof fn !== 'function' ? fn : function () {
1076
- var outerZone = PSD;
1077
- if (possibleAwait)
1078
- incrementExpectedAwaits();
1079
- switchToZone(zone, true);
1080
- try {
1081
- return fn.apply(this, arguments);
1082
- }
1083
- finally {
1084
- switchToZone(outerZone, false);
1085
- if (cleanup)
1086
- queueMicrotask(decrementExpectedAwaits);
1087
- }
1088
- };
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
+ };
1089
1161
  }
1090
1162
  function execInGlobalContext(cb) {
1091
1163
  if (Promise === NativePromise && task.echoes === 0) {
@@ -1103,7 +1175,7 @@
1103
1175
  var rejection = DexiePromise.reject;
1104
1176
 
1105
1177
  function tempTransaction(db, mode, storeNames, fn) {
1106
- if (!db.idbdb || (!db._state.openComplete && (!PSD.letThrough && !db._vip))) {
1178
+ if (!db.idbdb || (!db._state.openComplete && !PSD.letThrough && !db._vip)) {
1107
1179
  if (db._state.openComplete) {
1108
1180
  return rejection(new exceptions.DatabaseClosed(db._state.dbOpenError));
1109
1181
  }
@@ -1112,7 +1184,9 @@
1112
1184
  return rejection(new exceptions.DatabaseClosed());
1113
1185
  db.open().catch(nop);
1114
1186
  }
1115
- return db._state.dbReadyPromise.then(function () { return tempTransaction(db, mode, storeNames, fn); });
1187
+ return db._state.dbReadyPromise.then(function () {
1188
+ return tempTransaction(db, mode, storeNames, fn);
1189
+ });
1116
1190
  }
1117
1191
  else {
1118
1192
  var trans = db._createTransaction(mode, storeNames, db._dbSchema);
@@ -1121,45 +1195,53 @@
1121
1195
  db._state.PR1398_maxLoop = 3;
1122
1196
  }
1123
1197
  catch (ex) {
1124
- if (ex.name === errnames.InvalidState && db.isOpen() && --db._state.PR1398_maxLoop > 0) {
1198
+ if (ex.name === errnames.InvalidState &&
1199
+ db.isOpen() &&
1200
+ --db._state.PR1398_maxLoop > 0) {
1125
1201
  console.warn('Dexie: Need to reopen db');
1126
1202
  db.close({ disableAutoOpen: false });
1127
1203
  return db.open().then(function () { return tempTransaction(db, mode, storeNames, fn); });
1128
1204
  }
1129
1205
  return rejection(ex);
1130
1206
  }
1131
- return trans._promise(mode, function (resolve, reject) {
1207
+ return trans
1208
+ ._promise(mode, function (resolve, reject) {
1132
1209
  return newScope(function () {
1133
1210
  PSD.trans = trans;
1134
1211
  return fn(resolve, reject, trans);
1135
1212
  });
1136
- }).then(function (result) {
1213
+ })
1214
+ .then(function (result) {
1137
1215
  if (mode === 'readwrite')
1138
1216
  try {
1139
1217
  trans.idbtrans.commit();
1140
1218
  }
1141
1219
  catch (_a) { }
1142
- return mode === 'readonly' ? result : trans._completion.then(function () { return result; });
1220
+ return mode === 'readonly'
1221
+ ? result
1222
+ : trans._completion.then(function () { return result; });
1143
1223
  });
1144
1224
  }
1145
1225
  }
1146
1226
 
1147
- var DEXIE_VERSION = '4.4.0';
1227
+ var DEXIE_VERSION = '4.4.2';
1148
1228
  var maxString = String.fromCharCode(65535);
1149
1229
  var minKey = -Infinity;
1150
- var INVALID_KEY_ARGUMENT = "Invalid key provided. Keys must be of type string, number, Date or Array<string | number | Date>.";
1151
- var STRING_EXPECTED = "String expected.";
1230
+ var INVALID_KEY_ARGUMENT = 'Invalid key provided. Keys must be of type string, number, Date or Array<string | number | Date>.';
1231
+ var STRING_EXPECTED = 'String expected.';
1152
1232
  var DEFAULT_MAX_CONNECTIONS = 1000;
1153
1233
  var DBNAMES_DB = '__dbnames';
1154
1234
  var READONLY = 'readonly';
1155
1235
  var READWRITE = 'readwrite';
1156
1236
 
1157
1237
  function combine(filter1, filter2) {
1158
- return filter1 ?
1159
- filter2 ?
1160
- function () { return filter1.apply(this, arguments) && filter2.apply(this, arguments); } :
1161
- filter1 :
1162
- filter2;
1238
+ return filter1
1239
+ ? filter2
1240
+ ? function () {
1241
+ return (filter1.apply(this, arguments) && filter2.apply(this, arguments));
1242
+ }
1243
+ : filter1
1244
+ : filter2;
1163
1245
  }
1164
1246
 
1165
1247
  var AnyRange = {
@@ -1167,13 +1249,13 @@
1167
1249
  lower: -Infinity,
1168
1250
  lowerOpen: false,
1169
1251
  upper: [[]],
1170
- upperOpen: false
1252
+ upperOpen: false,
1171
1253
  };
1172
1254
 
1173
1255
  function workaroundForUndefinedPrimKey(keyPath) {
1174
- return typeof keyPath === "string" && !/\./.test(keyPath)
1256
+ return typeof keyPath === 'string' && !/\./.test(keyPath)
1175
1257
  ? function (obj) {
1176
- if (obj[keyPath] === undefined && (keyPath in obj)) {
1258
+ if (obj[keyPath] === undefined && keyPath in obj) {
1177
1259
  obj = deepClone(obj);
1178
1260
  delete obj[keyPath];
1179
1261
  }
@@ -1278,11 +1360,11 @@
1278
1360
 
1279
1361
  var PropModification = (function () {
1280
1362
  function PropModification(spec) {
1281
- this["@@propmod"] = spec;
1363
+ this['@@propmod'] = spec;
1282
1364
  }
1283
1365
  PropModification.prototype.execute = function (value) {
1284
1366
  var _a;
1285
- var spec = this["@@propmod"];
1367
+ var spec = this['@@propmod'];
1286
1368
  if (spec.add !== undefined) {
1287
1369
  var term = spec.add;
1288
1370
  if (isArray(term)) {
@@ -1303,7 +1385,9 @@
1303
1385
  if (spec.remove !== undefined) {
1304
1386
  var subtrahend_1 = spec.remove;
1305
1387
  if (isArray(subtrahend_1)) {
1306
- return isArray(value) ? value.filter(function (item) { return !subtrahend_1.includes(item); }).sort() : [];
1388
+ return isArray(value)
1389
+ ? value.filter(function (item) { return !subtrahend_1.includes(item); }).sort()
1390
+ : [];
1307
1391
  }
1308
1392
  if (typeof subtrahend_1 === 'number')
1309
1393
  return Number(value) - subtrahend_1;
@@ -1318,7 +1402,9 @@
1318
1402
  throw new TypeError("Invalid subtrahend ".concat(subtrahend_1));
1319
1403
  }
1320
1404
  var prefixToReplace = (_a = spec.replacePrefix) === null || _a === void 0 ? void 0 : _a[0];
1321
- if (prefixToReplace && typeof value === 'string' && value.startsWith(prefixToReplace)) {
1405
+ if (prefixToReplace &&
1406
+ typeof value === 'string' &&
1407
+ value.startsWith(prefixToReplace)) {
1322
1408
  return spec.replacePrefix[1] + value.substring(prefixToReplace.length);
1323
1409
  }
1324
1410
  return value;
@@ -1352,19 +1438,24 @@
1352
1438
  Table.prototype._trans = function (mode, fn, writeLocked) {
1353
1439
  var trans = this._tx || PSD.trans;
1354
1440
  var tableName = this.name;
1355
- var task = debug && typeof console !== 'undefined' && console.createTask && console.createTask("Dexie: ".concat(mode === 'readonly' ? 'read' : 'write', " ").concat(this.name));
1441
+ var task = debug &&
1442
+ typeof console !== 'undefined' &&
1443
+ console.createTask &&
1444
+ console.createTask("Dexie: ".concat(mode === 'readonly' ? 'read' : 'write', " ").concat(this.name));
1356
1445
  function checkTableInTransaction(resolve, reject, trans) {
1357
1446
  if (!trans.schema[tableName])
1358
- throw new exceptions.NotFound("Table " + tableName + " not part of transaction");
1447
+ throw new exceptions.NotFound('Table ' + tableName + ' not part of transaction');
1359
1448
  return fn(trans.idbtrans, trans);
1360
1449
  }
1361
1450
  var wasRootExec = beginMicroTickScope();
1362
1451
  try {
1363
- var p = trans && trans.db._novip === this.db._novip ?
1364
- trans === PSD.trans ?
1365
- trans._promise(mode, checkTableInTransaction, writeLocked) :
1366
- newScope(function () { return trans._promise(mode, checkTableInTransaction, writeLocked); }, { trans: trans, transless: PSD.transless || PSD }) :
1367
- tempTransaction(this.db, mode, [this.name], checkTableInTransaction);
1452
+ var p = trans && trans.db._novip === this.db._novip
1453
+ ? trans === PSD.trans
1454
+ ? trans._promise(mode, checkTableInTransaction, writeLocked)
1455
+ : newScope(function () {
1456
+ return trans._promise(mode, checkTableInTransaction, writeLocked);
1457
+ }, { trans: trans, transless: PSD.transless || PSD })
1458
+ : tempTransaction(this.db, mode, [this.name], checkTableInTransaction);
1368
1459
  if (task) {
1369
1460
  p._consoleTask = task;
1370
1461
  p = p.catch(function (err) {
@@ -1386,7 +1477,8 @@
1386
1477
  if (keyOrCrit == null)
1387
1478
  return rejection(new exceptions.Type("Invalid argument to Table.get()"));
1388
1479
  return this._trans('readonly', function (trans) {
1389
- return _this.core.get({ trans: trans, key: keyOrCrit })
1480
+ return _this.core
1481
+ .get({ trans: trans, key: keyOrCrit })
1390
1482
  .then(function (res) { return _this.hook.reading.fire(res); });
1391
1483
  }).then(cb);
1392
1484
  };
@@ -1397,10 +1489,10 @@
1397
1489
  return new this.db.WhereClause(this, "[".concat(indexOrCrit.join('+'), "]"));
1398
1490
  var keyPaths = keys(indexOrCrit);
1399
1491
  if (keyPaths.length === 1)
1400
- return this
1401
- .where(keyPaths[0])
1402
- .equals(indexOrCrit[keyPaths[0]]);
1403
- var compoundIndex = this.schema.indexes.concat(this.schema.primKey).filter(function (ix) {
1492
+ return this.where(keyPaths[0]).equals(indexOrCrit[keyPaths[0]]);
1493
+ var compoundIndex = this.schema.indexes
1494
+ .concat(this.schema.primKey)
1495
+ .filter(function (ix) {
1404
1496
  if (ix.compound &&
1405
1497
  keyPaths.every(function (keyPath) { return ix.keyPath.indexOf(keyPath) >= 0; })) {
1406
1498
  for (var i = 0; i < keyPaths.length; ++i) {
@@ -1410,12 +1502,11 @@
1410
1502
  return true;
1411
1503
  }
1412
1504
  return false;
1413
- }).sort(function (a, b) { return a.keyPath.length - b.keyPath.length; })[0];
1505
+ })
1506
+ .sort(function (a, b) { return a.keyPath.length - b.keyPath.length; })[0];
1414
1507
  if (compoundIndex && this.db._maxKey !== maxString) {
1415
1508
  var keyPathsInValidOrder = compoundIndex.keyPath.slice(0, keyPaths.length);
1416
- return this
1417
- .where(keyPathsInValidOrder)
1418
- .equals(keyPathsInValidOrder.map(function (kp) { return indexOrCrit[kp]; }));
1509
+ return this.where(keyPathsInValidOrder).equals(keyPathsInValidOrder.map(function (kp) { return indexOrCrit[kp]; }));
1419
1510
  }
1420
1511
  if (!compoundIndex && debug)
1421
1512
  console.warn("The query ".concat(JSON.stringify(indexOrCrit), " on ").concat(this.name, " would benefit from a ") +
@@ -1430,21 +1521,24 @@
1430
1521
  var value = indexOrCrit[keyPath];
1431
1522
  return [
1432
1523
  prevIndex || index,
1433
- prevIndex || !index ?
1434
- combine(prevFilterFn, index && index.multi ?
1435
- function (x) {
1524
+ prevIndex || !index
1525
+ ? combine(prevFilterFn, index && index.multi
1526
+ ? function (x) {
1436
1527
  var prop = getByKeyPath(x, keyPath);
1437
- return isArray(prop) && prop.some(function (item) { return equals(value, item); });
1438
- } : function (x) { return equals(value, getByKeyPath(x, keyPath)); })
1439
- : prevFilterFn
1528
+ return (isArray(prop) &&
1529
+ prop.some(function (item) { return equals(value, item); }));
1530
+ }
1531
+ : function (x) { return equals(value, getByKeyPath(x, keyPath)); })
1532
+ : prevFilterFn,
1440
1533
  ];
1441
1534
  }, [null, null]), idx = _a[0], filterFunction = _a[1];
1442
- return idx ?
1443
- this.where(idx.name).equals(indexOrCrit[idx.keyPath])
1444
- .filter(filterFunction) :
1445
- compoundIndex ?
1446
- this.filter(filterFunction) :
1447
- this.where(keyPaths).equals('');
1535
+ return idx
1536
+ ? this.where(idx.name)
1537
+ .equals(indexOrCrit[idx.keyPath])
1538
+ .filter(filterFunction)
1539
+ : compoundIndex
1540
+ ? this.filter(filterFunction)
1541
+ : this.where(keyPaths).equals('');
1448
1542
  };
1449
1543
  Table.prototype.filter = function (filterFunction) {
1450
1544
  return this.toCollection().and(filterFunction);
@@ -1468,9 +1562,7 @@
1468
1562
  return new this.db.Collection(new this.db.WhereClause(this));
1469
1563
  };
1470
1564
  Table.prototype.orderBy = function (index) {
1471
- return new this.db.Collection(new this.db.WhereClause(this, isArray(index) ?
1472
- "[".concat(index.join('+'), "]") :
1473
- index));
1565
+ return new this.db.Collection(new this.db.WhereClause(this, isArray(index) ? "[".concat(index.join('+'), "]") : index));
1474
1566
  };
1475
1567
  Table.prototype.reverse = function () {
1476
1568
  return this.toCollection().reverse();
@@ -1485,17 +1577,23 @@
1485
1577
  return _super !== null && _super.apply(this, arguments) || this;
1486
1578
  }
1487
1579
  Object.defineProperty(class_1.prototype, "db", {
1488
- get: function () { return db; },
1580
+ get: function () {
1581
+ return db;
1582
+ },
1489
1583
  enumerable: false,
1490
1584
  configurable: true
1491
1585
  });
1492
- class_1.prototype.table = function () { return tableName; };
1586
+ class_1.prototype.table = function () {
1587
+ return tableName;
1588
+ };
1493
1589
  return class_1;
1494
1590
  }(constructor));
1495
1591
  }
1496
1592
  var inheritedProps = new Set();
1497
1593
  for (var proto = constructor.prototype; proto; proto = getProto(proto)) {
1498
- Object.getOwnPropertyNames(proto).forEach(function (propName) { return inheritedProps.add(propName); });
1594
+ Object.getOwnPropertyNames(proto).forEach(function (propName) {
1595
+ return inheritedProps.add(propName);
1596
+ });
1499
1597
  }
1500
1598
  var readHook = function (obj) {
1501
1599
  if (!obj)
@@ -1513,7 +1611,7 @@
1513
1611
  this.hook.reading.unsubscribe(this.schema.readHook);
1514
1612
  }
1515
1613
  this.schema.readHook = readHook;
1516
- this.hook("reading", readHook);
1614
+ this.hook('reading', readHook);
1517
1615
  return constructor;
1518
1616
  };
1519
1617
  Table.prototype.defineClass = function () {
@@ -1530,8 +1628,16 @@
1530
1628
  objToAdd = workaroundForUndefinedPrimKey(keyPath)(obj);
1531
1629
  }
1532
1630
  return this._trans('readwrite', function (trans) {
1533
- return _this.core.mutate({ trans: trans, type: 'add', keys: key != null ? [key] : null, values: [objToAdd] });
1534
- }).then(function (res) { return res.numFailures ? DexiePromise.reject(res.failures[0]) : res.lastResult; })
1631
+ return _this.core.mutate({
1632
+ trans: trans,
1633
+ type: 'add',
1634
+ keys: key != null ? [key] : null,
1635
+ values: [objToAdd],
1636
+ });
1637
+ })
1638
+ .then(function (res) {
1639
+ return res.numFailures ? DexiePromise.reject(res.failures[0]) : res.lastResult;
1640
+ })
1535
1641
  .then(function (lastResult) {
1536
1642
  if (keyPath) {
1537
1643
  try {
@@ -1551,14 +1657,18 @@
1551
1657
  applyUpdateSpec(obj, modifications);
1552
1658
  if (keyPath)
1553
1659
  setByKeyPath(obj, keyPath, key);
1554
- return _this.core.mutate({
1660
+ return _this.core
1661
+ .mutate({
1555
1662
  trans: trans,
1556
1663
  type: 'put',
1557
1664
  values: [obj],
1558
1665
  keys: [key],
1559
1666
  upsert: true,
1560
- updates: { keys: [key], changeSpecs: [modifications] }
1561
- }).then(function (res) { return res.numFailures ? DexiePromise.reject(res.failures[0]) : !!existing; });
1667
+ updates: { keys: [key], changeSpecs: [modifications] },
1668
+ })
1669
+ .then(function (res) {
1670
+ return res.numFailures ? DexiePromise.reject(res.failures[0]) : !!existing;
1671
+ });
1562
1672
  });
1563
1673
  });
1564
1674
  };
@@ -1566,11 +1676,11 @@
1566
1676
  if (typeof keyOrObject === 'object' && !isArray(keyOrObject)) {
1567
1677
  var key = getByKeyPath(keyOrObject, this.schema.primKey.keyPath);
1568
1678
  if (key === undefined)
1569
- return rejection(new exceptions.InvalidArgument("Given object does not contain its primary key"));
1570
- return this.where(":id").equals(key).modify(modifications);
1679
+ return rejection(new exceptions.InvalidArgument('Given object does not contain its primary key'));
1680
+ return this.where(':id').equals(key).modify(modifications);
1571
1681
  }
1572
1682
  else {
1573
- return this.where(":id").equals(keyOrObject).modify(modifications);
1683
+ return this.where(':id').equals(keyOrObject).modify(modifications);
1574
1684
  }
1575
1685
  };
1576
1686
  Table.prototype.put = function (obj, key) {
@@ -1580,8 +1690,17 @@
1580
1690
  if (keyPath && auto) {
1581
1691
  objToAdd = workaroundForUndefinedPrimKey(keyPath)(obj);
1582
1692
  }
1583
- return this._trans('readwrite', function (trans) { return _this.core.mutate({ trans: trans, type: 'put', values: [objToAdd], keys: key != null ? [key] : null }); })
1584
- .then(function (res) { return res.numFailures ? DexiePromise.reject(res.failures[0]) : res.lastResult; })
1693
+ return this._trans('readwrite', function (trans) {
1694
+ return _this.core.mutate({
1695
+ trans: trans,
1696
+ type: 'put',
1697
+ values: [objToAdd],
1698
+ keys: key != null ? [key] : null,
1699
+ });
1700
+ })
1701
+ .then(function (res) {
1702
+ return res.numFailures ? DexiePromise.reject(res.failures[0]) : res.lastResult;
1703
+ })
1585
1704
  .then(function (lastResult) {
1586
1705
  if (keyPath) {
1587
1706
  try {
@@ -1594,41 +1713,60 @@
1594
1713
  };
1595
1714
  Table.prototype.delete = function (key) {
1596
1715
  var _this = this;
1597
- return this._trans('readwrite', function (trans) { return _this.core.mutate({ trans: trans, type: 'delete', keys: [key] })
1598
- .then(function (res) { return builtInDeletionTrigger(_this, [key], res); })
1599
- .then(function (res) { return res.numFailures ? DexiePromise.reject(res.failures[0]) : undefined; }); });
1716
+ return this._trans('readwrite', function (trans) {
1717
+ return _this.core
1718
+ .mutate({ trans: trans, type: 'delete', keys: [key] })
1719
+ .then(function (res) { return builtInDeletionTrigger(_this, [key], res); })
1720
+ .then(function (res) {
1721
+ return res.numFailures ? DexiePromise.reject(res.failures[0]) : undefined;
1722
+ });
1723
+ });
1600
1724
  };
1601
1725
  Table.prototype.clear = function () {
1602
1726
  var _this = this;
1603
- return this._trans('readwrite', function (trans) { return _this.core.mutate({ trans: trans, type: 'deleteRange', range: AnyRange })
1604
- .then(function (res) { return builtInDeletionTrigger(_this, null, res); }); })
1605
- .then(function (res) { return res.numFailures ? DexiePromise.reject(res.failures[0]) : undefined; });
1727
+ return this._trans('readwrite', function (trans) {
1728
+ return _this.core
1729
+ .mutate({ trans: trans, type: 'deleteRange', range: AnyRange })
1730
+ .then(function (res) { return builtInDeletionTrigger(_this, null, res); });
1731
+ }).then(function (res) {
1732
+ return res.numFailures ? DexiePromise.reject(res.failures[0]) : undefined;
1733
+ });
1606
1734
  };
1607
1735
  Table.prototype.bulkGet = function (keys) {
1608
1736
  var _this = this;
1609
1737
  return this._trans('readonly', function (trans) {
1610
- return _this.core.getMany({
1738
+ return _this.core
1739
+ .getMany({
1611
1740
  keys: keys,
1612
- trans: trans
1613
- }).then(function (result) { return result.map(function (res) { return _this.hook.reading.fire(res); }); });
1741
+ trans: trans,
1742
+ })
1743
+ .then(function (result) { return result.map(function (res) { return _this.hook.reading.fire(res); }); });
1614
1744
  });
1615
1745
  };
1616
1746
  Table.prototype.bulkAdd = function (objects, keysOrOptions, options) {
1617
1747
  var _this = this;
1618
1748
  var keys = Array.isArray(keysOrOptions) ? keysOrOptions : undefined;
1619
- options = options || (keys ? undefined : keysOrOptions);
1749
+ options =
1750
+ options || (keys ? undefined : keysOrOptions);
1620
1751
  var wantResults = options ? options.allKeys : undefined;
1621
1752
  return this._trans('readwrite', function (trans) {
1622
1753
  var _a = _this.schema.primKey, auto = _a.auto, keyPath = _a.keyPath;
1623
1754
  if (keyPath && keys)
1624
- throw new exceptions.InvalidArgument("bulkAdd(): keys argument invalid on tables with inbound keys");
1755
+ throw new exceptions.InvalidArgument('bulkAdd(): keys argument invalid on tables with inbound keys');
1625
1756
  if (keys && keys.length !== objects.length)
1626
- throw new exceptions.InvalidArgument("Arguments objects and keys must have the same length");
1757
+ throw new exceptions.InvalidArgument('Arguments objects and keys must have the same length');
1627
1758
  var numObjects = objects.length;
1628
- var objectsToAdd = keyPath && auto ?
1629
- objects.map(workaroundForUndefinedPrimKey(keyPath)) :
1630
- objects;
1631
- return _this.core.mutate({ trans: trans, type: 'add', keys: keys, values: objectsToAdd, wantResults: wantResults })
1759
+ var objectsToAdd = keyPath && auto
1760
+ ? objects.map(workaroundForUndefinedPrimKey(keyPath))
1761
+ : objects;
1762
+ return _this.core
1763
+ .mutate({
1764
+ trans: trans,
1765
+ type: 'add',
1766
+ keys: keys,
1767
+ values: objectsToAdd,
1768
+ wantResults: wantResults,
1769
+ })
1632
1770
  .then(function (_a) {
1633
1771
  var numFailures = _a.numFailures, results = _a.results, lastResult = _a.lastResult, failures = _a.failures;
1634
1772
  var result = wantResults ? results : lastResult;
@@ -1641,19 +1779,27 @@
1641
1779
  Table.prototype.bulkPut = function (objects, keysOrOptions, options) {
1642
1780
  var _this = this;
1643
1781
  var keys = Array.isArray(keysOrOptions) ? keysOrOptions : undefined;
1644
- options = options || (keys ? undefined : keysOrOptions);
1782
+ options =
1783
+ options || (keys ? undefined : keysOrOptions);
1645
1784
  var wantResults = options ? options.allKeys : undefined;
1646
1785
  return this._trans('readwrite', function (trans) {
1647
1786
  var _a = _this.schema.primKey, auto = _a.auto, keyPath = _a.keyPath;
1648
1787
  if (keyPath && keys)
1649
- throw new exceptions.InvalidArgument("bulkPut(): keys argument invalid on tables with inbound keys");
1788
+ throw new exceptions.InvalidArgument('bulkPut(): keys argument invalid on tables with inbound keys');
1650
1789
  if (keys && keys.length !== objects.length)
1651
- throw new exceptions.InvalidArgument("Arguments objects and keys must have the same length");
1790
+ throw new exceptions.InvalidArgument('Arguments objects and keys must have the same length');
1652
1791
  var numObjects = objects.length;
1653
- var objectsToPut = keyPath && auto ?
1654
- objects.map(workaroundForUndefinedPrimKey(keyPath)) :
1655
- objects;
1656
- return _this.core.mutate({ trans: trans, type: 'put', keys: keys, values: objectsToPut, wantResults: wantResults })
1792
+ var objectsToPut = keyPath && auto
1793
+ ? objects.map(workaroundForUndefinedPrimKey(keyPath))
1794
+ : objects;
1795
+ return _this.core
1796
+ .mutate({
1797
+ trans: trans,
1798
+ type: 'put',
1799
+ keys: keys,
1800
+ values: objectsToPut,
1801
+ wantResults: wantResults,
1802
+ })
1657
1803
  .then(function (_a) {
1658
1804
  var numFailures = _a.numFailures, results = _a.results, lastResult = _a.lastResult, failures = _a.failures;
1659
1805
  var result = wantResults ? results : lastResult;
@@ -1703,8 +1849,8 @@
1703
1849
  values: resultObjs,
1704
1850
  updates: {
1705
1851
  keys: keys,
1706
- changeSpecs: changeSpecs
1707
- }
1852
+ changeSpecs: changeSpecs,
1853
+ },
1708
1854
  })
1709
1855
  .then(function (_a) {
1710
1856
  var numFailures = _a.numFailures, failures = _a.failures;
@@ -1728,7 +1874,8 @@
1728
1874
  var _this = this;
1729
1875
  var numKeys = keys.length;
1730
1876
  return this._trans('readwrite', function (trans) {
1731
- return _this.core.mutate({ trans: trans, type: 'delete', keys: keys })
1877
+ return _this.core
1878
+ .mutate({ trans: trans, type: 'delete', keys: keys })
1732
1879
  .then(function (res) { return builtInDeletionTrigger(_this, keys, res); });
1733
1880
  }).then(function (_a) {
1734
1881
  var numFailures = _a.numFailures, lastResult = _a.lastResult, failures = _a.failures;
@@ -1750,7 +1897,7 @@
1750
1897
  evs[eventName].subscribe.apply(null, args);
1751
1898
  return ctx;
1752
1899
  }
1753
- else if (typeof (eventName) === 'string') {
1900
+ else if (typeof eventName === 'string') {
1754
1901
  return evs[eventName];
1755
1902
  }
1756
1903
  };
@@ -1776,9 +1923,11 @@
1776
1923
  }
1777
1924
  },
1778
1925
  unsubscribe: function (cb) {
1779
- context.subscribers = context.subscribers.filter(function (fn) { return fn !== cb; });
1926
+ context.subscribers = context.subscribers.filter(function (fn) {
1927
+ return fn !== cb;
1928
+ });
1780
1929
  context.fire = context.subscribers.reduce(chainFunction, defaultFunction);
1781
- }
1930
+ },
1782
1931
  };
1783
1932
  evs[eventName] = rv[eventName] = context;
1784
1933
  return context;
@@ -1802,7 +1951,7 @@
1802
1951
  });
1803
1952
  }
1804
1953
  else
1805
- throw new exceptions.InvalidArgument("Invalid event config");
1954
+ throw new exceptions.InvalidArgument('Invalid event config');
1806
1955
  });
1807
1956
  }
1808
1957
  }
@@ -1818,18 +1967,20 @@
1818
1967
  this._tx = trans;
1819
1968
  this.name = name;
1820
1969
  this.schema = tableSchema;
1821
- this.hook = db._allTables[name] ? db._allTables[name].hook : Events(null, {
1822
- "creating": [hookCreatingChain, nop],
1823
- "reading": [pureFunctionChain, mirror],
1824
- "updating": [hookUpdatingChain, nop],
1825
- "deleting": [hookDeletingChain, nop]
1826
- });
1970
+ this.hook = db._allTables[name]
1971
+ ? db._allTables[name].hook
1972
+ : Events(null, {
1973
+ creating: [hookCreatingChain, nop],
1974
+ reading: [pureFunctionChain, mirror],
1975
+ updating: [hookUpdatingChain, nop],
1976
+ deleting: [hookDeletingChain, nop],
1977
+ });
1827
1978
  });
1828
1979
  }
1829
1980
 
1830
1981
  function isPlainKeyRange(ctx, ignoreLimitFilter) {
1831
- return !(ctx.filter || ctx.algorithm || ctx.or) &&
1832
- (ignoreLimitFilter ? ctx.justLimit : !ctx.replayFilter);
1982
+ return (!(ctx.filter || ctx.algorithm || ctx.or) &&
1983
+ (ignoreLimitFilter ? ctx.justLimit : !ctx.replayFilter));
1833
1984
  }
1834
1985
  function addFilter(ctx, fn) {
1835
1986
  ctx.filter = combine(ctx.filter, fn);
@@ -1847,7 +1998,11 @@
1847
1998
  return coreSchema.primaryKey;
1848
1999
  var index = coreSchema.getIndexByKeyPath(ctx.index);
1849
2000
  if (!index)
1850
- throw new exceptions.Schema("KeyPath " + ctx.index + " on object store " + coreSchema.name + " is not indexed");
2001
+ throw new exceptions.Schema('KeyPath ' +
2002
+ ctx.index +
2003
+ ' on object store ' +
2004
+ coreSchema.name +
2005
+ ' is not indexed');
1851
2006
  return index;
1852
2007
  }
1853
2008
  function openCursor(ctx, coreTable, trans) {
@@ -1859,19 +2014,22 @@
1859
2014
  unique: !!ctx.unique,
1860
2015
  query: {
1861
2016
  index: index,
1862
- range: ctx.range
1863
- }
2017
+ range: ctx.range,
2018
+ },
1864
2019
  });
1865
2020
  }
1866
2021
  function iter(ctx, fn, coreTrans, coreTable) {
1867
- var filter = ctx.replayFilter ? combine(ctx.filter, ctx.replayFilter()) : ctx.filter;
2022
+ var filter = ctx.replayFilter
2023
+ ? combine(ctx.filter, ctx.replayFilter())
2024
+ : ctx.filter;
1868
2025
  if (!ctx.or) {
1869
2026
  return iterate(openCursor(ctx, coreTable, coreTrans), combine(ctx.algorithm, filter), fn, !ctx.keysOnly && ctx.valueMapper);
1870
2027
  }
1871
2028
  else {
1872
2029
  var set_1 = {};
1873
2030
  var union = function (item, cursor, advance) {
1874
- if (!filter || filter(cursor, advance, function (result) { return cursor.stop(result); }, function (err) { return cursor.fail(err); })) {
2031
+ if (!filter ||
2032
+ filter(cursor, advance, function (result) { return cursor.stop(result); }, function (err) { return cursor.fail(err); })) {
1875
2033
  var primaryKey = cursor.primaryKey;
1876
2034
  var key = '' + primaryKey;
1877
2035
  if (key === '[object ArrayBuffer]')
@@ -1884,7 +2042,7 @@
1884
2042
  };
1885
2043
  return Promise.all([
1886
2044
  ctx.or._iterate(union, coreTrans),
1887
- iterate(openCursor(ctx, coreTable, coreTrans), ctx.algorithm, union, !ctx.keysOnly && ctx.valueMapper)
2045
+ iterate(openCursor(ctx, coreTable, coreTrans), ctx.algorithm, union, !ctx.keysOnly && ctx.valueMapper),
1888
2046
  ]);
1889
2047
  }
1890
2048
  }
@@ -1895,8 +2053,15 @@
1895
2053
  if (cursor) {
1896
2054
  return cursor.start(function () {
1897
2055
  var c = function () { return cursor.continue(); };
1898
- if (!filter || filter(cursor, function (advancer) { return c = advancer; }, function (val) { cursor.stop(val); c = nop; }, function (e) { cursor.fail(e); c = nop; }))
1899
- wrappedFn(cursor.value, cursor, function (advancer) { return c = advancer; });
2056
+ if (!filter ||
2057
+ filter(cursor, function (advancer) { return (c = advancer); }, function (val) {
2058
+ cursor.stop(val);
2059
+ c = nop;
2060
+ }, function (e) {
2061
+ cursor.fail(e);
2062
+ c = nop;
2063
+ }))
2064
+ wrappedFn(cursor.value, cursor, function (advancer) { return (c = advancer); });
1900
2065
  c();
1901
2066
  });
1902
2067
  }
@@ -1908,15 +2073,15 @@
1908
2073
  }
1909
2074
  Collection.prototype._read = function (fn, cb) {
1910
2075
  var ctx = this._ctx;
1911
- return ctx.error ?
1912
- ctx.table._trans(null, rejection.bind(null, ctx.error)) :
1913
- ctx.table._trans('readonly', fn).then(cb);
2076
+ return ctx.error
2077
+ ? ctx.table._trans(null, rejection.bind(null, ctx.error))
2078
+ : ctx.table._trans('readonly', fn).then(cb);
1914
2079
  };
1915
2080
  Collection.prototype._write = function (fn) {
1916
2081
  var ctx = this._ctx;
1917
- return ctx.error ?
1918
- ctx.table._trans(null, rejection.bind(null, ctx.error)) :
1919
- ctx.table._trans('readwrite', fn, "locked");
2082
+ return ctx.error
2083
+ ? ctx.table._trans(null, rejection.bind(null, ctx.error))
2084
+ : ctx.table._trans('readwrite', fn, 'locked');
1920
2085
  };
1921
2086
  Collection.prototype._addAlgorithm = function (fn) {
1922
2087
  var ctx = this._ctx;
@@ -1946,18 +2111,22 @@
1946
2111
  var ctx = _this._ctx;
1947
2112
  var coreTable = ctx.table.core;
1948
2113
  if (isPlainKeyRange(ctx, true)) {
1949
- return coreTable.count({
2114
+ return coreTable
2115
+ .count({
1950
2116
  trans: trans,
1951
2117
  query: {
1952
2118
  index: getIndexOrStore(ctx, coreTable.schema),
1953
- range: ctx.range
1954
- }
1955
- }).then(function (count) { return Math.min(count, ctx.limit); });
2119
+ range: ctx.range,
2120
+ },
2121
+ })
2122
+ .then(function (count) { return Math.min(count, ctx.limit); });
1956
2123
  }
1957
2124
  else {
1958
2125
  var count = 0;
1959
- return iter(ctx, function () { ++count; return false; }, trans, coreTable)
1960
- .then(function () { return count; });
2126
+ return iter(ctx, function () {
2127
+ ++count;
2128
+ return false;
2129
+ }, trans, coreTable).then(function () { return count; });
1961
2130
  }
1962
2131
  }).then(cb);
1963
2132
  };
@@ -1968,7 +2137,7 @@
1968
2137
  return getval(obj[parts[i]], i - 1);
1969
2138
  return obj[lastPart];
1970
2139
  }
1971
- var order = this._ctx.dir === "next" ? 1 : -1;
2140
+ var order = this._ctx.dir === 'next' ? 1 : -1;
1972
2141
  function sorter(a, b) {
1973
2142
  var aVal = getval(a, lastIndex), bVal = getval(b, lastIndex);
1974
2143
  return cmp(aVal, bVal) * order;
@@ -1984,16 +2153,18 @@
1984
2153
  if (isPlainKeyRange(ctx, true) && ctx.limit > 0) {
1985
2154
  var valueMapper_1 = ctx.valueMapper;
1986
2155
  var index = getIndexOrStore(ctx, ctx.table.core.schema);
1987
- return ctx.table.core.query({
2156
+ return ctx.table.core
2157
+ .query({
1988
2158
  trans: trans,
1989
2159
  limit: ctx.limit,
1990
2160
  values: true,
1991
2161
  direction: ctx.dir === 'prev' ? 'prev' : undefined,
1992
2162
  query: {
1993
2163
  index: index,
1994
- range: ctx.range
1995
- }
1996
- }).then(function (_a) {
2164
+ range: ctx.range,
2165
+ },
2166
+ })
2167
+ .then(function (_a) {
1997
2168
  var result = _a.result;
1998
2169
  return valueMapper_1 ? result.map(valueMapper_1) : result;
1999
2170
  });
@@ -2030,7 +2201,7 @@
2030
2201
  else {
2031
2202
  addReplayFilter(ctx, function () {
2032
2203
  var offsetLeft = offset;
2033
- return function () { return (--offsetLeft < 0); };
2204
+ return function () { return --offsetLeft < 0; };
2034
2205
  });
2035
2206
  }
2036
2207
  return this;
@@ -2060,7 +2231,11 @@
2060
2231
  return this;
2061
2232
  };
2062
2233
  Collection.prototype.first = function (cb) {
2063
- return this.limit(1).toArray(function (a) { return a[0]; }).then(cb);
2234
+ return this.limit(1)
2235
+ .toArray(function (a) {
2236
+ return a[0];
2237
+ })
2238
+ .then(cb);
2064
2239
  };
2065
2240
  Collection.prototype.last = function (cb) {
2066
2241
  return this.reverse().first(cb);
@@ -2079,7 +2254,7 @@
2079
2254
  return new this.db.WhereClause(this._ctx.table, indexName, this);
2080
2255
  };
2081
2256
  Collection.prototype.reverse = function () {
2082
- this._ctx.dir = (this._ctx.dir === "prev" ? "next" : "prev");
2257
+ this._ctx.dir = this._ctx.dir === 'prev' ? 'next' : 'prev';
2083
2258
  if (this._ondirectionchange)
2084
2259
  this._ondirectionchange(this._ctx.dir);
2085
2260
  return this;
@@ -2090,16 +2265,20 @@
2090
2265
  Collection.prototype.eachKey = function (cb) {
2091
2266
  var ctx = this._ctx;
2092
2267
  ctx.keysOnly = !ctx.isMatch;
2093
- return this.each(function (val, cursor) { cb(cursor.key, cursor); });
2268
+ return this.each(function (val, cursor) {
2269
+ cb(cursor.key, cursor);
2270
+ });
2094
2271
  };
2095
2272
  Collection.prototype.eachUniqueKey = function (cb) {
2096
- this._ctx.unique = "unique";
2273
+ this._ctx.unique = 'unique';
2097
2274
  return this.eachKey(cb);
2098
2275
  };
2099
2276
  Collection.prototype.eachPrimaryKey = function (cb) {
2100
2277
  var ctx = this._ctx;
2101
2278
  ctx.keysOnly = !ctx.isMatch;
2102
- return this.each(function (val, cursor) { cb(cursor.primaryKey, cursor); });
2279
+ return this.each(function (val, cursor) {
2280
+ cb(cursor.primaryKey, cursor);
2281
+ });
2103
2282
  };
2104
2283
  Collection.prototype.keys = function (cb) {
2105
2284
  var ctx = this._ctx;
@@ -2107,9 +2286,11 @@
2107
2286
  var a = [];
2108
2287
  return this.each(function (item, cursor) {
2109
2288
  a.push(cursor.key);
2110
- }).then(function () {
2289
+ })
2290
+ .then(function () {
2111
2291
  return a;
2112
- }).then(cb);
2292
+ })
2293
+ .then(cb);
2113
2294
  };
2114
2295
  Collection.prototype.primaryKeys = function (cb) {
2115
2296
  var ctx = this._ctx;
@@ -2123,28 +2304,36 @@
2123
2304
  direction: ctx.dir === 'prev' ? 'prev' : undefined,
2124
2305
  query: {
2125
2306
  index: index,
2126
- range: ctx.range
2127
- }
2307
+ range: ctx.range,
2308
+ },
2128
2309
  });
2129
- }).then(function (_a) {
2310
+ })
2311
+ .then(function (_a) {
2130
2312
  var result = _a.result;
2131
2313
  return result;
2132
- }).then(cb);
2314
+ })
2315
+ .then(cb);
2133
2316
  }
2134
2317
  ctx.keysOnly = !ctx.isMatch;
2135
2318
  var a = [];
2136
2319
  return this.each(function (item, cursor) {
2137
2320
  a.push(cursor.primaryKey);
2138
- }).then(function () {
2321
+ })
2322
+ .then(function () {
2139
2323
  return a;
2140
- }).then(cb);
2324
+ })
2325
+ .then(cb);
2141
2326
  };
2142
2327
  Collection.prototype.uniqueKeys = function (cb) {
2143
- this._ctx.unique = "unique";
2328
+ this._ctx.unique = 'unique';
2144
2329
  return this.keys(cb);
2145
2330
  };
2146
2331
  Collection.prototype.firstKey = function (cb) {
2147
- return this.limit(1).keys(function (a) { return a[0]; }).then(cb);
2332
+ return this.limit(1)
2333
+ .keys(function (a) {
2334
+ return a[0];
2335
+ })
2336
+ .then(cb);
2148
2337
  };
2149
2338
  Collection.prototype.lastKey = function (cb) {
2150
2339
  return this.reverse().firstKey(cb);
@@ -2179,7 +2368,8 @@
2179
2368
  var modifyChunkSize = _this.db._options.modifyChunkSize;
2180
2369
  if (modifyChunkSize) {
2181
2370
  if (typeof modifyChunkSize == 'object') {
2182
- limit = modifyChunkSize[coreTable.name] || modifyChunkSize['*'] || 200;
2371
+ limit =
2372
+ modifyChunkSize[coreTable.name] || modifyChunkSize['*'] || 200;
2183
2373
  }
2184
2374
  else {
2185
2375
  limit = modifyChunkSize;
@@ -2197,21 +2387,25 @@
2197
2387
  }
2198
2388
  };
2199
2389
  var isUnconditionalDelete = changes === deleteCallback;
2200
- return _this.clone().primaryKeys().then(function (keys) {
2390
+ return _this.clone()
2391
+ .primaryKeys()
2392
+ .then(function (keys) {
2201
2393
  var criteria = isPlainKeyRange(ctx) &&
2202
2394
  ctx.limit === Infinity &&
2203
2395
  (typeof changes !== 'function' || isUnconditionalDelete) && {
2204
2396
  index: ctx.index,
2205
- range: ctx.range
2397
+ range: ctx.range,
2206
2398
  };
2207
2399
  var nextChunk = function (offset) {
2208
2400
  var count = Math.min(limit, keys.length - offset);
2209
2401
  var keysInChunk = keys.slice(offset, offset + count);
2210
- return (isUnconditionalDelete ? Promise.resolve([]) : coreTable.getMany({
2211
- trans: trans,
2212
- keys: keysInChunk,
2213
- cache: "immutable"
2214
- })).then(function (values) {
2402
+ return (isUnconditionalDelete
2403
+ ? Promise.resolve([])
2404
+ : coreTable.getMany({
2405
+ trans: trans,
2406
+ keys: keysInChunk,
2407
+ cache: 'immutable',
2408
+ })).then(function (values) {
2215
2409
  var addValues = [];
2216
2410
  var putValues = [];
2217
2411
  var putKeys = outbound ? [] : null;
@@ -2221,13 +2415,14 @@
2221
2415
  var origValue = values[i];
2222
2416
  var ctx_1 = {
2223
2417
  value: deepClone(origValue),
2224
- primKey: keys[offset + i]
2418
+ primKey: keys[offset + i],
2225
2419
  };
2226
2420
  if (modifyer.call(ctx_1, ctx_1.value, ctx_1) !== false) {
2227
2421
  if (ctx_1.value == null) {
2228
2422
  deleteKeys.push(keys[offset + i]);
2229
2423
  }
2230
- else if (!outbound && cmp(extractKey(origValue), extractKey(ctx_1.value)) !== 0) {
2424
+ else if (!outbound &&
2425
+ cmp(extractKey(origValue), extractKey(ctx_1.value)) !== 0) {
2231
2426
  deleteKeys.push(keys[offset + i]);
2232
2427
  addValues.push(ctx_1.value);
2233
2428
  }
@@ -2239,38 +2434,53 @@
2239
2434
  }
2240
2435
  }
2241
2436
  return Promise.resolve(addValues.length > 0 &&
2242
- coreTable.mutate({ trans: trans, type: 'add', values: addValues })
2437
+ coreTable
2438
+ .mutate({ trans: trans, type: 'add', values: addValues })
2243
2439
  .then(function (res) {
2244
2440
  for (var pos in res.failures) {
2245
2441
  deleteKeys.splice(parseInt(pos), 1);
2246
2442
  }
2247
2443
  applyMutateResult(addValues.length, res);
2248
- })).then(function () { return (putValues.length > 0 || (criteria && typeof changes === 'object')) &&
2249
- coreTable.mutate({
2250
- trans: trans,
2251
- type: 'put',
2252
- keys: putKeys,
2253
- values: putValues,
2254
- criteria: criteria,
2255
- changeSpec: typeof changes !== 'function'
2256
- && changes,
2257
- isAdditionalChunk: offset > 0
2258
- }).then(function (res) { return applyMutateResult(putValues.length, res); }); }).then(function () { return (deleteKeys.length > 0 || (criteria && isUnconditionalDelete)) &&
2259
- coreTable.mutate({
2260
- trans: trans,
2261
- type: 'delete',
2262
- keys: deleteKeys,
2263
- criteria: criteria,
2264
- isAdditionalChunk: offset > 0
2265
- }).then(function (res) { return builtInDeletionTrigger(ctx.table, deleteKeys, res); })
2266
- .then(function (res) { return applyMutateResult(deleteKeys.length, res); }); }).then(function () {
2267
- return keys.length > offset + count && nextChunk(offset + limit);
2444
+ }))
2445
+ .then(function () {
2446
+ return (putValues.length > 0 ||
2447
+ (criteria && typeof changes === 'object')) &&
2448
+ coreTable
2449
+ .mutate({
2450
+ trans: trans,
2451
+ type: 'put',
2452
+ keys: putKeys,
2453
+ values: putValues,
2454
+ criteria: criteria,
2455
+ changeSpec: typeof changes !== 'function' && changes,
2456
+ isAdditionalChunk: offset > 0,
2457
+ })
2458
+ .then(function (res) { return applyMutateResult(putValues.length, res); });
2459
+ })
2460
+ .then(function () {
2461
+ return (deleteKeys.length > 0 ||
2462
+ (criteria && isUnconditionalDelete)) &&
2463
+ coreTable
2464
+ .mutate({
2465
+ trans: trans,
2466
+ type: 'delete',
2467
+ keys: deleteKeys,
2468
+ criteria: criteria,
2469
+ isAdditionalChunk: offset > 0,
2470
+ })
2471
+ .then(function (res) {
2472
+ return builtInDeletionTrigger(ctx.table, deleteKeys, res);
2473
+ })
2474
+ .then(function (res) { return applyMutateResult(deleteKeys.length, res); });
2475
+ })
2476
+ .then(function () {
2477
+ return (keys.length > offset + count && nextChunk(offset + limit));
2268
2478
  });
2269
2479
  });
2270
2480
  };
2271
2481
  return nextChunk(0).then(function () {
2272
2482
  if (totalFailures.length > 0)
2273
- throw new ModifyError("Error modifying one or more objects", totalFailures, successCount, failedKeys);
2483
+ throw new ModifyError('Error modifying one or more objects', totalFailures, successCount, failedKeys);
2274
2484
  return keys.length;
2275
2485
  });
2276
2486
  });
@@ -2285,12 +2495,15 @@
2285
2495
  return this._write(function (trans) {
2286
2496
  var primaryKey = ctx.table.core.schema.primaryKey;
2287
2497
  var coreRange = range;
2288
- return ctx.table.core.count({ trans: trans, query: { index: primaryKey, range: coreRange } }).then(function (count) {
2289
- return ctx.table.core.mutate({ trans: trans, type: 'deleteRange', range: coreRange })
2498
+ return ctx.table.core
2499
+ .count({ trans: trans, query: { index: primaryKey, range: coreRange } })
2500
+ .then(function (count) {
2501
+ return ctx.table.core
2502
+ .mutate({ trans: trans, type: 'deleteRange', range: coreRange })
2290
2503
  .then(function (_a) {
2291
2504
  var failures = _a.failures, numFailures = _a.numFailures;
2292
2505
  if (numFailures)
2293
- throw new ModifyError("Could not delete some values", Object.keys(failures).map(function (pos) { return failures[pos]; }), count - numFailures);
2506
+ throw new ModifyError('Could not delete some values', Object.keys(failures).map(function (pos) { return failures[pos]; }), count - numFailures);
2294
2507
  return count - numFailures;
2295
2508
  });
2296
2509
  });
@@ -2300,7 +2513,7 @@
2300
2513
  };
2301
2514
  return Collection;
2302
2515
  }());
2303
- var deleteCallback = function (value, ctx) { return ctx.value = null; };
2516
+ var deleteCallback = function (value, ctx) { return (ctx.value = null); };
2304
2517
 
2305
2518
  function createCollectionConstructor(db) {
2306
2519
  return makeClassConstructor(Collection.prototype, function Collection(whereClause, keyRangeGenerator) {
@@ -2319,11 +2532,13 @@
2319
2532
  this._ctx = {
2320
2533
  table: table,
2321
2534
  index: whereCtx.index,
2322
- isPrimKey: (!whereCtx.index || (table.schema.primKey.keyPath && whereCtx.index === table.schema.primKey.name)),
2535
+ isPrimKey: !whereCtx.index ||
2536
+ (table.schema.primKey.keyPath &&
2537
+ whereCtx.index === table.schema.primKey.name),
2323
2538
  range: keyRange,
2324
2539
  keysOnly: false,
2325
- dir: "next",
2326
- unique: "",
2540
+ dir: 'next',
2541
+ unique: '',
2327
2542
  algorithm: null,
2328
2543
  filter: null,
2329
2544
  replayFilter: null,
@@ -2333,7 +2548,7 @@
2333
2548
  limit: Infinity,
2334
2549
  error: error,
2335
2550
  or: whereCtx.or,
2336
- valueMapper: readingHook !== mirror ? readingHook : null
2551
+ valueMapper: readingHook !== mirror ? readingHook : null,
2337
2552
  };
2338
2553
  });
2339
2554
  }
@@ -2346,24 +2561,24 @@
2346
2561
  }
2347
2562
 
2348
2563
  function fail(collectionOrWhereClause, err, T) {
2349
- var collection = collectionOrWhereClause instanceof WhereClause ?
2350
- new collectionOrWhereClause.Collection(collectionOrWhereClause) :
2351
- collectionOrWhereClause;
2564
+ var collection = collectionOrWhereClause instanceof WhereClause
2565
+ ? new collectionOrWhereClause.Collection(collectionOrWhereClause)
2566
+ : collectionOrWhereClause;
2352
2567
  collection._ctx.error = T ? new T(err) : new TypeError(err);
2353
2568
  return collection;
2354
2569
  }
2355
2570
  function emptyCollection(whereClause) {
2356
- return new whereClause.Collection(whereClause, function () { return rangeEqual(""); }).limit(0);
2571
+ return new whereClause.Collection(whereClause, function () { return rangeEqual(''); }).limit(0);
2357
2572
  }
2358
2573
  function upperFactory(dir) {
2359
- return dir === "next" ?
2360
- function (s) { return s.toUpperCase(); } :
2361
- function (s) { return s.toLowerCase(); };
2574
+ return dir === 'next'
2575
+ ? function (s) { return s.toUpperCase(); }
2576
+ : function (s) { return s.toLowerCase(); };
2362
2577
  }
2363
2578
  function lowerFactory(dir) {
2364
- return dir === "next" ?
2365
- function (s) { return s.toLowerCase(); } :
2366
- function (s) { return s.toUpperCase(); };
2579
+ return dir === 'next'
2580
+ ? function (s) { return s.toLowerCase(); }
2581
+ : function (s) { return s.toUpperCase(); };
2367
2582
  }
2368
2583
  function nextCasing(key, lowerKey, upperNeedle, lowerNeedle, cmp, dir) {
2369
2584
  var length = Math.min(key.length, lowerNeedle.length);
@@ -2382,11 +2597,13 @@
2382
2597
  if (cmp(key[i], lwrKeyChar) < 0)
2383
2598
  llp = i;
2384
2599
  }
2385
- if (length < lowerNeedle.length && dir === "next")
2600
+ if (length < lowerNeedle.length && dir === 'next')
2386
2601
  return key + upperNeedle.substr(key.length);
2387
- if (length < key.length && dir === "prev")
2602
+ if (length < key.length && dir === 'prev')
2388
2603
  return key.substr(0, upperNeedle.length);
2389
- return (llp < 0 ? null : key.substr(0, llp) + lowerNeedle[llp] + upperNeedle.substr(llp + 1));
2604
+ return llp < 0
2605
+ ? null
2606
+ : key.substr(0, llp) + lowerNeedle[llp] + upperNeedle.substr(llp + 1);
2390
2607
  }
2391
2608
  function addIgnoreCaseAlgorithm(whereClause, match, needles, suffix) {
2392
2609
  var upper, lower, compare, upperNeedles, lowerNeedles, direction, nextKeySuffix, needlesLen = needles.length;
@@ -2396,19 +2613,27 @@
2396
2613
  function initDirection(dir) {
2397
2614
  upper = upperFactory(dir);
2398
2615
  lower = lowerFactory(dir);
2399
- compare = (dir === "next" ? simpleCompare : simpleCompareReverse);
2400
- var needleBounds = needles.map(function (needle) {
2616
+ compare = dir === 'next' ? simpleCompare : simpleCompareReverse;
2617
+ var needleBounds = needles
2618
+ .map(function (needle) {
2401
2619
  return { lower: lower(needle), upper: upper(needle) };
2402
- }).sort(function (a, b) {
2620
+ })
2621
+ .sort(function (a, b) {
2403
2622
  return compare(a.lower, b.lower);
2404
2623
  });
2405
- upperNeedles = needleBounds.map(function (nb) { return nb.upper; });
2406
- lowerNeedles = needleBounds.map(function (nb) { return nb.lower; });
2624
+ upperNeedles = needleBounds.map(function (nb) {
2625
+ return nb.upper;
2626
+ });
2627
+ lowerNeedles = needleBounds.map(function (nb) {
2628
+ return nb.lower;
2629
+ });
2407
2630
  direction = dir;
2408
- nextKeySuffix = (dir === "next" ? "" : suffix);
2631
+ nextKeySuffix = dir === 'next' ? '' : suffix;
2409
2632
  }
2410
- initDirection("next");
2411
- var c = new whereClause.Collection(whereClause, function () { return createRange(upperNeedles[0], lowerNeedles[needlesLen - 1] + suffix); });
2633
+ initDirection('next');
2634
+ var c = new whereClause.Collection(whereClause, function () {
2635
+ return createRange(upperNeedles[0], lowerNeedles[needlesLen - 1] + suffix);
2636
+ });
2412
2637
  c._ondirectionchange = function (direction) {
2413
2638
  initDirection(direction);
2414
2639
  };
@@ -2427,12 +2652,15 @@
2427
2652
  var casing = nextCasing(key, lowerKey, upperNeedles[i], lowerNeedles[i], compare, direction);
2428
2653
  if (casing === null && lowestPossibleCasing === null)
2429
2654
  firstPossibleNeedle = i + 1;
2430
- else if (lowestPossibleCasing === null || compare(lowestPossibleCasing, casing) > 0) {
2655
+ else if (lowestPossibleCasing === null ||
2656
+ compare(lowestPossibleCasing, casing) > 0) {
2431
2657
  lowestPossibleCasing = casing;
2432
2658
  }
2433
2659
  }
2434
2660
  if (lowestPossibleCasing !== null) {
2435
- advance(function () { cursor.continue(lowestPossibleCasing + nextKeySuffix); });
2661
+ advance(function () {
2662
+ cursor.continue(lowestPossibleCasing + nextKeySuffix);
2663
+ });
2436
2664
  }
2437
2665
  else {
2438
2666
  advance(resolve);
@@ -2448,14 +2676,14 @@
2448
2676
  lower: lower,
2449
2677
  upper: upper,
2450
2678
  lowerOpen: lowerOpen,
2451
- upperOpen: upperOpen
2679
+ upperOpen: upperOpen,
2452
2680
  };
2453
2681
  }
2454
2682
  function rangeEqual(value) {
2455
2683
  return {
2456
2684
  type: 1 ,
2457
2685
  lower: value,
2458
- upper: value
2686
+ upper: value,
2459
2687
  };
2460
2688
  }
2461
2689
 
@@ -2473,10 +2701,14 @@
2473
2701
  includeLower = includeLower !== false;
2474
2702
  includeUpper = includeUpper === true;
2475
2703
  try {
2476
- if ((this._cmp(lower, upper) > 0) ||
2477
- (this._cmp(lower, upper) === 0 && (includeLower || includeUpper) && !(includeLower && includeUpper)))
2704
+ if (this._cmp(lower, upper) > 0 ||
2705
+ (this._cmp(lower, upper) === 0 &&
2706
+ (includeLower || includeUpper) &&
2707
+ !(includeLower && includeUpper)))
2478
2708
  return emptyCollection(this);
2479
- return new this.Collection(this, function () { return createRange(lower, upper, !includeLower, !includeUpper); });
2709
+ return new this.Collection(this, function () {
2710
+ return createRange(lower, upper, !includeLower, !includeUpper);
2711
+ });
2480
2712
  }
2481
2713
  catch (e) {
2482
2714
  return fail(this, INVALID_KEY_ARGUMENT);
@@ -2495,12 +2727,16 @@
2495
2727
  WhereClause.prototype.aboveOrEqual = function (value) {
2496
2728
  if (value == null)
2497
2729
  return fail(this, INVALID_KEY_ARGUMENT);
2498
- return new this.Collection(this, function () { return createRange(value, undefined, false); });
2730
+ return new this.Collection(this, function () {
2731
+ return createRange(value, undefined, false);
2732
+ });
2499
2733
  };
2500
2734
  WhereClause.prototype.below = function (value) {
2501
2735
  if (value == null)
2502
2736
  return fail(this, INVALID_KEY_ARGUMENT);
2503
- return new this.Collection(this, function () { return createRange(undefined, value, false, true); });
2737
+ return new this.Collection(this, function () {
2738
+ return createRange(undefined, value, false, true);
2739
+ });
2504
2740
  };
2505
2741
  WhereClause.prototype.belowOrEqual = function (value) {
2506
2742
  if (value == null)
@@ -2513,18 +2749,18 @@
2513
2749
  return this.between(str, str + maxString, true, true);
2514
2750
  };
2515
2751
  WhereClause.prototype.startsWithIgnoreCase = function (str) {
2516
- if (str === "")
2752
+ if (str === '')
2517
2753
  return this.startsWith(str);
2518
2754
  return addIgnoreCaseAlgorithm(this, function (x, a) { return x.indexOf(a[0]) === 0; }, [str], maxString);
2519
2755
  };
2520
2756
  WhereClause.prototype.equalsIgnoreCase = function (str) {
2521
- return addIgnoreCaseAlgorithm(this, function (x, a) { return x === a[0]; }, [str], "");
2757
+ return addIgnoreCaseAlgorithm(this, function (x, a) { return x === a[0]; }, [str], '');
2522
2758
  };
2523
2759
  WhereClause.prototype.anyOfIgnoreCase = function () {
2524
2760
  var set = getArrayOf.apply(NO_CHAR_ARRAY, arguments);
2525
2761
  if (set.length === 0)
2526
2762
  return emptyCollection(this);
2527
- return addIgnoreCaseAlgorithm(this, function (x, a) { return a.indexOf(x) !== -1; }, set, "");
2763
+ return addIgnoreCaseAlgorithm(this, function (x, a) { return a.indexOf(x) !== -1; }, set, '');
2528
2764
  };
2529
2765
  WhereClause.prototype.startsWithAnyOfIgnoreCase = function () {
2530
2766
  var set = getArrayOf.apply(NO_CHAR_ARRAY, arguments);
@@ -2544,11 +2780,11 @@
2544
2780
  }
2545
2781
  if (set.length === 0)
2546
2782
  return emptyCollection(this);
2547
- var c = new this.Collection(this, function () { return createRange(set[0], set[set.length - 1]); });
2783
+ var c = new this.Collection(this, function () {
2784
+ return createRange(set[0], set[set.length - 1]);
2785
+ });
2548
2786
  c._ondirectionchange = function (direction) {
2549
- compare = (direction === "next" ?
2550
- _this._ascending :
2551
- _this._descending);
2787
+ compare = direction === 'next' ? _this._ascending : _this._descending;
2552
2788
  set.sort(compare);
2553
2789
  };
2554
2790
  var i = 0;
@@ -2565,14 +2801,19 @@
2565
2801
  return true;
2566
2802
  }
2567
2803
  else {
2568
- advance(function () { cursor.continue(set[i]); });
2804
+ advance(function () {
2805
+ cursor.continue(set[i]);
2806
+ });
2569
2807
  return false;
2570
2808
  }
2571
2809
  });
2572
2810
  return c;
2573
2811
  };
2574
2812
  WhereClause.prototype.notEqual = function (value) {
2575
- return this.inAnyRange([[minKey, value], [value, this.db._maxKey]], { includeLowers: false, includeUppers: false });
2813
+ return this.inAnyRange([
2814
+ [minKey, value],
2815
+ [value, this.db._maxKey],
2816
+ ], { includeLowers: false, includeUppers: false });
2576
2817
  };
2577
2818
  WhereClause.prototype.noneOf = function () {
2578
2819
  var set = getArrayOf.apply(NO_CHAR_ARRAY, arguments);
@@ -2584,11 +2825,14 @@
2584
2825
  catch (e) {
2585
2826
  return fail(this, INVALID_KEY_ARGUMENT);
2586
2827
  }
2587
- var ranges = set.reduce(function (res, val) { return res ?
2588
- res.concat([[res[res.length - 1][1], val]]) :
2589
- [[minKey, val]]; }, null);
2828
+ var ranges = set.reduce(function (res, val) {
2829
+ return res ? res.concat([[res[res.length - 1][1], val]]) : [[minKey, val]];
2830
+ }, null);
2590
2831
  ranges.push([set[set.length - 1], this.db._maxKey]);
2591
- return this.inAnyRange(ranges, { includeLowers: false, includeUppers: false });
2832
+ return this.inAnyRange(ranges, {
2833
+ includeLowers: false,
2834
+ includeUppers: false,
2835
+ });
2592
2836
  };
2593
2837
  WhereClause.prototype.inAnyRange = function (ranges, options) {
2594
2838
  var _this = this;
@@ -2600,7 +2844,7 @@
2600
2844
  range[1] !== undefined &&
2601
2845
  ascending(range[0], range[1]) <= 0;
2602
2846
  })) {
2603
- 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);
2847
+ 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);
2604
2848
  }
2605
2849
  var includeLowers = !options || options.includeLowers !== false;
2606
2850
  var includeUppers = options && options.includeUppers === true;
@@ -2619,7 +2863,9 @@
2619
2863
  return ranges;
2620
2864
  }
2621
2865
  var sortDirection = ascending;
2622
- function rangeSorter(a, b) { return sortDirection(a[0], b[0]); }
2866
+ function rangeSorter(a, b) {
2867
+ return sortDirection(a[0], b[0]);
2868
+ }
2623
2869
  var set;
2624
2870
  try {
2625
2871
  set = ranges.reduce(addRange, []);
@@ -2629,19 +2875,21 @@
2629
2875
  return fail(this, INVALID_KEY_ARGUMENT);
2630
2876
  }
2631
2877
  var rangePos = 0;
2632
- var keyIsBeyondCurrentEntry = includeUppers ?
2633
- function (key) { return ascending(key, set[rangePos][1]) > 0; } :
2634
- function (key) { return ascending(key, set[rangePos][1]) >= 0; };
2635
- var keyIsBeforeCurrentEntry = includeLowers ?
2636
- function (key) { return descending(key, set[rangePos][0]) > 0; } :
2637
- function (key) { return descending(key, set[rangePos][0]) >= 0; };
2878
+ var keyIsBeyondCurrentEntry = includeUppers
2879
+ ? function (key) { return ascending(key, set[rangePos][1]) > 0; }
2880
+ : function (key) { return ascending(key, set[rangePos][1]) >= 0; };
2881
+ var keyIsBeforeCurrentEntry = includeLowers
2882
+ ? function (key) { return descending(key, set[rangePos][0]) > 0; }
2883
+ : function (key) { return descending(key, set[rangePos][0]) >= 0; };
2638
2884
  function keyWithinCurrentRange(key) {
2639
2885
  return !keyIsBeyondCurrentEntry(key) && !keyIsBeforeCurrentEntry(key);
2640
2886
  }
2641
2887
  var checkKey = keyIsBeyondCurrentEntry;
2642
- var c = new this.Collection(this, function () { return createRange(set[0][0], set[set.length - 1][1], !includeLowers, !includeUppers); });
2888
+ var c = new this.Collection(this, function () {
2889
+ return createRange(set[0][0], set[set.length - 1][1], !includeLowers, !includeUppers);
2890
+ });
2643
2891
  c._ondirectionchange = function (direction) {
2644
- if (direction === "next") {
2892
+ if (direction === 'next') {
2645
2893
  checkKey = keyIsBeyondCurrentEntry;
2646
2894
  sortDirection = ascending;
2647
2895
  }
@@ -2663,7 +2911,8 @@
2663
2911
  if (keyWithinCurrentRange(key)) {
2664
2912
  return true;
2665
2913
  }
2666
- else if (_this._cmp(key, set[rangePos][1]) === 0 || _this._cmp(key, set[rangePos][0]) === 0) {
2914
+ else if (_this._cmp(key, set[rangePos][1]) === 0 ||
2915
+ _this._cmp(key, set[rangePos][0]) === 0) {
2667
2916
  return false;
2668
2917
  }
2669
2918
  else {
@@ -2681,7 +2930,7 @@
2681
2930
  WhereClause.prototype.startsWithAnyOf = function () {
2682
2931
  var set = getArrayOf.apply(NO_CHAR_ARRAY, arguments);
2683
2932
  if (!set.every(function (s) { return typeof s === 'string'; })) {
2684
- return fail(this, "startsWithAnyOf() only works with strings");
2933
+ return fail(this, 'startsWithAnyOf() only works with strings');
2685
2934
  }
2686
2935
  if (set.length === 0)
2687
2936
  return emptyCollection(this);
@@ -2695,13 +2944,13 @@
2695
2944
  this.db = db;
2696
2945
  this._ctx = {
2697
2946
  table: table,
2698
- index: index === ":id" ? null : index,
2699
- or: orCollection
2947
+ index: index === ':id' ? null : index,
2948
+ or: orCollection,
2700
2949
  };
2701
2950
  this._cmp = this._ascending = cmp;
2702
2951
  this._descending = function (a, b) { return cmp(b, a); };
2703
- this._max = function (a, b) { return cmp(a, b) > 0 ? a : b; };
2704
- this._min = function (a, b) { return cmp(a, b) < 0 ? a : b; };
2952
+ this._max = function (a, b) { return (cmp(a, b) > 0 ? a : b); };
2953
+ this._min = function (a, b) { return (cmp(a, b) < 0 ? a : b); };
2705
2954
  this._IDBKeyRange = db._deps.IDBKeyRange;
2706
2955
  if (!this._IDBKeyRange)
2707
2956
  throw new exceptions.MissingAPI();
@@ -2763,9 +3012,9 @@
2763
3012
  assert(!this.idbtrans);
2764
3013
  if (!idbtrans && !idbdb) {
2765
3014
  switch (dbOpenError && dbOpenError.name) {
2766
- case "DatabaseClosedError":
3015
+ case 'DatabaseClosedError':
2767
3016
  throw new exceptions.DatabaseClosed(dbOpenError);
2768
- case "MissingAPIError":
3017
+ case 'MissingAPIError':
2769
3018
  throw new exceptions.MissingAPI(dbOpenError.message, dbOpenError);
2770
3019
  default:
2771
3020
  throw new exceptions.OpenFailed(dbOpenError);
@@ -2774,10 +3023,13 @@
2774
3023
  if (!this.active)
2775
3024
  throw new exceptions.TransactionInactive();
2776
3025
  assert(this._completion._state === null);
2777
- idbtrans = this.idbtrans = idbtrans ||
2778
- (this.db.core
2779
- ? this.db.core.transaction(this.storeNames, this.mode, { durability: this.chromeTransactionDurability })
2780
- : idbdb.transaction(this.storeNames, this.mode, { durability: this.chromeTransactionDurability }));
3026
+ idbtrans = this.idbtrans =
3027
+ idbtrans ||
3028
+ (this.db.core
3029
+ ? this.db.core.transaction(this.storeNames, this.mode, { durability: this.chromeTransactionDurability })
3030
+ : idbdb.transaction(this.storeNames, this.mode, {
3031
+ durability: this.chromeTransactionDurability,
3032
+ }));
2781
3033
  idbtrans.onerror = wrap(function (ev) {
2782
3034
  preventDefault(ev);
2783
3035
  _this._reject(idbtrans.error);
@@ -2786,13 +3038,13 @@
2786
3038
  preventDefault(ev);
2787
3039
  _this.active && _this._reject(new exceptions.Abort(idbtrans.error));
2788
3040
  _this.active = false;
2789
- _this.on("abort").fire(ev);
3041
+ _this.on('abort').fire(ev);
2790
3042
  });
2791
3043
  idbtrans.oncomplete = wrap(function () {
2792
3044
  _this.active = false;
2793
3045
  _this._resolve();
2794
3046
  if ('mutatedParts' in idbtrans) {
2795
- globalEvents.storagemutated.fire(idbtrans["mutatedParts"]);
3047
+ globalEvents.storagemutated.fire(idbtrans['mutatedParts']);
2796
3048
  }
2797
3049
  });
2798
3050
  return this;
@@ -2800,14 +3052,17 @@
2800
3052
  Transaction.prototype._promise = function (mode, fn, bWriteLock) {
2801
3053
  var _this = this;
2802
3054
  if (mode === 'readwrite' && this.mode !== 'readwrite')
2803
- return rejection(new exceptions.ReadOnly("Transaction is readonly"));
3055
+ return rejection(new exceptions.ReadOnly('Transaction is readonly'));
2804
3056
  if (!this.active)
2805
3057
  return rejection(new exceptions.TransactionInactive());
2806
3058
  if (this._locked()) {
2807
3059
  return new DexiePromise(function (resolve, reject) {
2808
- _this._blockedFuncs.push([function () {
3060
+ _this._blockedFuncs.push([
3061
+ function () {
2809
3062
  _this._promise(mode, fn, bWriteLock).then(resolve, reject);
2810
- }, PSD]);
3063
+ },
3064
+ PSD,
3065
+ ]);
2811
3066
  });
2812
3067
  }
2813
3068
  else if (bWriteLock) {
@@ -2849,14 +3104,16 @@
2849
3104
  (function spin() {
2850
3105
  ++root._spinCount;
2851
3106
  while (root._waitingQueue.length)
2852
- (root._waitingQueue.shift())();
3107
+ root._waitingQueue.shift()();
2853
3108
  if (root._waitingFor)
2854
3109
  store.get(-Infinity).onsuccess = spin;
2855
- }());
3110
+ })();
2856
3111
  }
2857
3112
  var currentWaitPromise = root._waitingFor;
2858
3113
  return new DexiePromise(function (resolve, reject) {
2859
- 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 () {
3114
+ promise
3115
+ .then(function (res) { return root._waitingQueue.push(wrap(resolve.bind(null, res))); }, function (err) { return root._waitingQueue.push(wrap(reject.bind(null, err))); })
3116
+ .finally(function () {
2860
3117
  if (root._waitingFor === currentWaitPromise) {
2861
3118
  root._waitingFor = null;
2862
3119
  }
@@ -2872,12 +3129,12 @@
2872
3129
  }
2873
3130
  };
2874
3131
  Transaction.prototype.table = function (tableName) {
2875
- var memoizedTables = (this._memoizedTables || (this._memoizedTables = {}));
3132
+ var memoizedTables = this._memoizedTables || (this._memoizedTables = {});
2876
3133
  if (hasOwn(memoizedTables, tableName))
2877
3134
  return memoizedTables[tableName];
2878
3135
  var tableSchema = this.schema[tableName];
2879
3136
  if (!tableSchema) {
2880
- throw new exceptions.NotFound("Table " + tableName + " not part of transaction");
3137
+ throw new exceptions.NotFound('Table ' + tableName + ' not part of transaction');
2881
3138
  }
2882
3139
  var transactionBoundTable = new this.db.Table(tableName, tableSchema, this);
2883
3140
  transactionBoundTable.core = this.db.core.table(tableName);
@@ -2903,7 +3160,7 @@
2903
3160
  this.schema = dbschema;
2904
3161
  this.chromeTransactionDurability = chromeTransactionDurability;
2905
3162
  this.idbtrans = null;
2906
- this.on = Events(this, "complete", "error", "abort");
3163
+ this.on = Events(this, 'complete', 'error', 'abort');
2907
3164
  this.parent = parent || null;
2908
3165
  this.active = true;
2909
3166
  this._reculock = 0;
@@ -2924,9 +3181,9 @@
2924
3181
  var wasActive = _this.active;
2925
3182
  _this.active = false;
2926
3183
  _this.on.error.fire(e);
2927
- _this.parent ?
2928
- _this.parent._reject(e) :
2929
- wasActive && _this.idbtrans && _this.idbtrans.abort();
3184
+ _this.parent
3185
+ ? _this.parent._reject(e)
3186
+ : wasActive && _this.idbtrans && _this.idbtrans.abort();
2930
3187
  return rejection(e);
2931
3188
  });
2932
3189
  });
@@ -2940,14 +3197,19 @@
2940
3197
  multi: multi,
2941
3198
  auto: auto,
2942
3199
  compound: compound,
2943
- src: (unique && !isPrimKey ? '&' : '') + (multi ? '*' : '') + (auto ? "++" : "") + nameFromKeyPath(keyPath),
2944
- type: type
3200
+ src: (unique && !isPrimKey ? '&' : '') +
3201
+ (multi ? '*' : '') +
3202
+ (auto ? '++' : '') +
3203
+ nameFromKeyPath(keyPath),
3204
+ type: type,
2945
3205
  };
2946
3206
  }
2947
3207
  function nameFromKeyPath(keyPath) {
2948
- return typeof keyPath === 'string' ?
2949
- keyPath :
2950
- keyPath ? ('[' + [].join.call(keyPath, '+') + ']') : "";
3208
+ return typeof keyPath === 'string'
3209
+ ? keyPath
3210
+ : keyPath
3211
+ ? '[' + [].join.call(keyPath, '+') + ']'
3212
+ : '';
2951
3213
  }
2952
3214
 
2953
3215
  function createTableSchema(name, primKey, indexes) {
@@ -3001,22 +3263,22 @@
3001
3263
  }
3002
3264
  var _id_counter = 0;
3003
3265
  function getKeyPathAlias(keyPath) {
3004
- return keyPath == null ?
3005
- ":id" :
3006
- typeof keyPath === 'string' ?
3007
- keyPath :
3008
- "[".concat(keyPath.join('+'), "]");
3266
+ return keyPath == null
3267
+ ? ':id'
3268
+ : typeof keyPath === 'string'
3269
+ ? keyPath
3270
+ : "[".concat(keyPath.join('+'), "]");
3009
3271
  }
3010
3272
  function createDBCore(db, IdbKeyRange, tmpTrans) {
3011
3273
  function extractSchema(db, trans) {
3012
3274
  var tables = arrayify(db.objectStoreNames);
3013
- var tempStore = tables.length > 0
3014
- ? trans.objectStore(tables[0])
3015
- : {};
3275
+ var tempStore = tables.length > 0 ? trans.objectStore(tables[0]) : {};
3016
3276
  return {
3017
3277
  schema: {
3018
3278
  name: db.name,
3019
- tables: tables.map(function (table) { return trans.objectStore(table); }).map(function (store) {
3279
+ tables: tables
3280
+ .map(function (table) { return trans.objectStore(table); })
3281
+ .map(function (store) {
3020
3282
  var keyPath = store.keyPath, autoIncrement = store.autoIncrement;
3021
3283
  var compound = isArray(keyPath);
3022
3284
  var outbound = keyPath == null;
@@ -3031,9 +3293,10 @@
3031
3293
  keyPath: keyPath,
3032
3294
  autoIncrement: autoIncrement,
3033
3295
  unique: true,
3034
- extractKey: getKeyExtractor(keyPath)
3296
+ extractKey: getKeyExtractor(keyPath),
3035
3297
  },
3036
- indexes: arrayify(store.indexNames).map(function (indexName) { return store.index(indexName); })
3298
+ indexes: arrayify(store.indexNames)
3299
+ .map(function (indexName) { return store.index(indexName); })
3037
3300
  .map(function (index) {
3038
3301
  var name = index.name, unique = index.unique, multiEntry = index.multiEntry, keyPath = index.keyPath;
3039
3302
  var compound = isArray(keyPath);
@@ -3043,40 +3306,44 @@
3043
3306
  keyPath: keyPath,
3044
3307
  unique: unique,
3045
3308
  multiEntry: multiEntry,
3046
- extractKey: getKeyExtractor(keyPath)
3309
+ extractKey: getKeyExtractor(keyPath),
3047
3310
  };
3048
3311
  indexByKeyPath[getKeyPathAlias(keyPath)] = result;
3049
3312
  return result;
3050
3313
  }),
3051
- getIndexByKeyPath: function (keyPath) { return indexByKeyPath[getKeyPathAlias(keyPath)]; }
3314
+ getIndexByKeyPath: function (keyPath) {
3315
+ return indexByKeyPath[getKeyPathAlias(keyPath)];
3316
+ },
3052
3317
  };
3053
- indexByKeyPath[":id"] = result.primaryKey;
3318
+ indexByKeyPath[':id'] = result.primaryKey;
3054
3319
  if (keyPath != null) {
3055
3320
  indexByKeyPath[getKeyPathAlias(keyPath)] = result.primaryKey;
3056
3321
  }
3057
3322
  return result;
3058
- })
3323
+ }),
3059
3324
  },
3060
- hasGetAll: tables.length > 0 && ('getAll' in tempStore) &&
3061
- !(typeof navigator !== 'undefined' && /Safari/.test(navigator.userAgent) &&
3325
+ hasGetAll: tables.length > 0 &&
3326
+ 'getAll' in tempStore &&
3327
+ !(typeof navigator !== 'undefined' &&
3328
+ /Safari/.test(navigator.userAgent) &&
3062
3329
  !/(Chrome\/|Edge\/)/.test(navigator.userAgent) &&
3063
3330
  [].concat(navigator.userAgent.match(/Safari\/(\d*)/))[1] < 604),
3064
- hasIdb3Features: 'getAllRecords' in tempStore
3331
+ hasIdb3Features: 'getAllRecords' in tempStore,
3065
3332
  };
3066
3333
  }
3067
3334
  function makeIDBKeyRange(range) {
3068
3335
  if (range.type === 3 )
3069
3336
  return null;
3070
3337
  if (range.type === 4 )
3071
- throw new Error("Cannot convert never type to IDBKeyRange");
3338
+ throw new Error('Cannot convert never type to IDBKeyRange');
3072
3339
  var lower = range.lower, upper = range.upper, lowerOpen = range.lowerOpen, upperOpen = range.upperOpen;
3073
- var idbRange = lower === undefined ?
3074
- upper === undefined ?
3075
- null :
3076
- IdbKeyRange.upperBound(upper, !!upperOpen) :
3077
- upper === undefined ?
3078
- IdbKeyRange.lowerBound(lower, !!lowerOpen) :
3079
- IdbKeyRange.bound(lower, upper, !!lowerOpen, !!upperOpen);
3340
+ var idbRange = lower === undefined
3341
+ ? upper === undefined
3342
+ ? null
3343
+ : IdbKeyRange.upperBound(upper, !!upperOpen)
3344
+ : upper === undefined
3345
+ ? IdbKeyRange.lowerBound(lower, !!lowerOpen)
3346
+ : IdbKeyRange.bound(lower, upper, !!lowerOpen, !!upperOpen);
3080
3347
  return idbRange;
3081
3348
  }
3082
3349
  function createDbCoreTable(tableSchema) {
@@ -3087,15 +3354,20 @@
3087
3354
  resolve = wrap(resolve);
3088
3355
  var store = trans.objectStore(tableName);
3089
3356
  var outbound = store.keyPath == null;
3090
- var isAddOrPut = type === "put" || type === "add";
3357
+ var isAddOrPut = type === 'put' || type === 'add';
3091
3358
  if (!isAddOrPut && type !== 'delete' && type !== 'deleteRange')
3092
- throw new Error("Invalid operation type: " + type);
3359
+ throw new Error('Invalid operation type: ' + type);
3093
3360
  var length = (keys || values || { length: 1 }).length;
3094
3361
  if (keys && values && keys.length !== values.length) {
3095
- throw new Error("Given keys array must have same length as given values array.");
3362
+ throw new Error('Given keys array must have same length as given values array.');
3096
3363
  }
3097
3364
  if (length === 0)
3098
- return resolve({ numFailures: 0, failures: {}, results: [], lastResult: undefined });
3365
+ return resolve({
3366
+ numFailures: 0,
3367
+ failures: {},
3368
+ results: [],
3369
+ lastResult: undefined,
3370
+ });
3099
3371
  var req;
3100
3372
  var reqs = [];
3101
3373
  var failures = [];
@@ -3106,29 +3378,34 @@
3106
3378
  };
3107
3379
  if (type === 'deleteRange') {
3108
3380
  if (range.type === 4 )
3109
- return resolve({ numFailures: numFailures, failures: failures, results: [], lastResult: undefined });
3381
+ return resolve({
3382
+ numFailures: numFailures,
3383
+ failures: failures,
3384
+ results: [],
3385
+ lastResult: undefined,
3386
+ });
3110
3387
  if (range.type === 3 )
3111
- reqs.push(req = store.clear());
3388
+ reqs.push((req = store.clear()));
3112
3389
  else
3113
- reqs.push(req = store.delete(makeIDBKeyRange(range)));
3390
+ reqs.push((req = store.delete(makeIDBKeyRange(range))));
3114
3391
  }
3115
3392
  else {
3116
- var _a = isAddOrPut ?
3117
- outbound ?
3118
- [values, keys] :
3119
- [values, null] :
3120
- [keys, null], args1 = _a[0], args2 = _a[1];
3393
+ var _a = isAddOrPut
3394
+ ? outbound
3395
+ ? [values, keys]
3396
+ : [values, null]
3397
+ : [keys, null], args1 = _a[0], args2 = _a[1];
3121
3398
  if (isAddOrPut) {
3122
3399
  for (var i = 0; i < length; ++i) {
3123
- reqs.push(req = (args2 && args2[i] !== undefined ?
3124
- store[type](args1[i], args2[i]) :
3125
- store[type](args1[i])));
3400
+ reqs.push((req = (args2 && args2[i] !== undefined
3401
+ ? store[type](args1[i], args2[i])
3402
+ : store[type](args1[i]))));
3126
3403
  req.onerror = errorHandler;
3127
3404
  }
3128
3405
  }
3129
3406
  else {
3130
3407
  for (var i = 0; i < length; ++i) {
3131
- reqs.push(req = store[type](args1[i]));
3408
+ reqs.push((req = store[type](args1[i])));
3132
3409
  req.onerror = errorHandler;
3133
3410
  }
3134
3411
  }
@@ -3139,8 +3416,8 @@
3139
3416
  resolve({
3140
3417
  numFailures: numFailures,
3141
3418
  failures: failures,
3142
- results: type === "delete" ? keys : reqs.map(function (req) { return req.result; }),
3143
- lastResult: lastResult
3419
+ results: type === 'delete' ? keys : reqs.map(function (req) { return req.result; }),
3420
+ lastResult: lastResult,
3144
3421
  });
3145
3422
  };
3146
3423
  req.onerror = function (event) {
@@ -3156,19 +3433,17 @@
3156
3433
  resolve = wrap(resolve);
3157
3434
  var index = query.index, range = query.range;
3158
3435
  var store = trans.objectStore(tableName);
3159
- var source = index.isPrimaryKey ?
3160
- store :
3161
- store.index(index.name);
3162
- var direction = reverse ?
3163
- unique ?
3164
- "prevunique" :
3165
- "prev" :
3166
- unique ?
3167
- "nextunique" :
3168
- "next";
3169
- var req = values || !('openKeyCursor' in source) ?
3170
- source.openCursor(makeIDBKeyRange(range), direction) :
3171
- source.openKeyCursor(makeIDBKeyRange(range), direction);
3436
+ var source = index.isPrimaryKey ? store : store.index(index.name);
3437
+ var direction = reverse
3438
+ ? unique
3439
+ ? 'prevunique'
3440
+ : 'prev'
3441
+ : unique
3442
+ ? 'nextunique'
3443
+ : 'next';
3444
+ var req = values || !('openKeyCursor' in source)
3445
+ ? source.openCursor(makeIDBKeyRange(range), direction)
3446
+ : source.openKeyCursor(makeIDBKeyRange(range), direction);
3172
3447
  req.onerror = eventRejectHandler(reject);
3173
3448
  req.onsuccess = wrap(function (ev) {
3174
3449
  var cursor = req.result;
@@ -3183,15 +3458,25 @@
3183
3458
  if (_cursorContinuePrimaryKey)
3184
3459
  _cursorContinuePrimaryKey = _cursorContinuePrimaryKey.bind(cursor);
3185
3460
  var _cursorAdvance = cursor.advance.bind(cursor);
3186
- var doThrowCursorIsNotStarted = function () { throw new Error("Cursor not started"); };
3187
- var doThrowCursorIsStopped = function () { throw new Error("Cursor not stopped"); };
3461
+ var doThrowCursorIsNotStarted = function () {
3462
+ throw new Error('Cursor not started');
3463
+ };
3464
+ var doThrowCursorIsStopped = function () {
3465
+ throw new Error('Cursor not stopped');
3466
+ };
3188
3467
  cursor.trans = trans;
3189
- cursor.stop = cursor.continue = cursor.continuePrimaryKey = cursor.advance = doThrowCursorIsNotStarted;
3468
+ cursor.stop =
3469
+ cursor.continue =
3470
+ cursor.continuePrimaryKey =
3471
+ cursor.advance =
3472
+ doThrowCursorIsNotStarted;
3190
3473
  cursor.fail = wrap(reject);
3191
3474
  cursor.next = function () {
3192
3475
  var _this = this;
3193
3476
  var gotOne = 1;
3194
- return this.start(function () { return gotOne-- ? _this.continue() : _this.stop(); }).then(function () { return _this; });
3477
+ return this.start(function () {
3478
+ return gotOne-- ? _this.continue() : _this.stop();
3479
+ }).then(function () { return _this; });
3195
3480
  };
3196
3481
  cursor.start = function (callback) {
3197
3482
  var iterationPromise = new Promise(function (resolveIteration, rejectIteration) {
@@ -3199,7 +3484,11 @@
3199
3484
  req.onerror = eventRejectHandler(rejectIteration);
3200
3485
  cursor.fail = rejectIteration;
3201
3486
  cursor.stop = function (value) {
3202
- cursor.stop = cursor.continue = cursor.continuePrimaryKey = cursor.advance = doThrowCursorIsStopped;
3487
+ cursor.stop =
3488
+ cursor.continue =
3489
+ cursor.continuePrimaryKey =
3490
+ cursor.advance =
3491
+ doThrowCursorIsStopped;
3203
3492
  resolveIteration(value);
3204
3493
  };
3205
3494
  });
@@ -3214,7 +3503,9 @@
3214
3503
  }
3215
3504
  else {
3216
3505
  cursor.done = true;
3217
- cursor.start = function () { throw new Error("Cursor behind last entry"); };
3506
+ cursor.start = function () {
3507
+ throw new Error('Cursor behind last entry');
3508
+ };
3218
3509
  cursor.stop();
3219
3510
  }
3220
3511
  };
@@ -3250,26 +3541,28 @@
3250
3541
  var options = {
3251
3542
  query: idbKeyRange,
3252
3543
  count: nonInfinitLimit,
3253
- direction: direction
3544
+ direction: direction,
3254
3545
  };
3255
- var req = values ?
3256
- source.getAll(options) :
3257
- source.getAllKeys(options);
3546
+ var req = values
3547
+ ? source.getAll(options)
3548
+ : source.getAllKeys(options);
3258
3549
  req.onsuccess = function (event) { return resolve({ result: event.target.result }); };
3259
3550
  req.onerror = eventRejectHandler(reject);
3260
3551
  }
3261
3552
  else if (hasGetAll && direction === 'next') {
3262
- var req = values ?
3263
- source.getAll(idbKeyRange, nonInfinitLimit) :
3264
- source.getAllKeys(idbKeyRange, nonInfinitLimit);
3265
- req.onsuccess = function (event) { return resolve({ result: event.target.result }); };
3553
+ var req = values
3554
+ ? source.getAll(idbKeyRange, nonInfinitLimit)
3555
+ : source.getAllKeys(idbKeyRange, nonInfinitLimit);
3556
+ req.onsuccess = function (event) {
3557
+ return resolve({ result: event.target.result });
3558
+ };
3266
3559
  req.onerror = eventRejectHandler(reject);
3267
3560
  }
3268
3561
  else {
3269
3562
  var count_1 = 0;
3270
- var req_1 = values || !('openKeyCursor' in source) ?
3271
- source.openCursor(idbKeyRange, direction) :
3272
- source.openKeyCursor(idbKeyRange, direction);
3563
+ var req_1 = values || !('openKeyCursor' in source)
3564
+ ? source.openCursor(idbKeyRange, direction)
3565
+ : source.openKeyCursor(idbKeyRange, direction);
3273
3566
  var result_1 = [];
3274
3567
  req_1.onsuccess = function () {
3275
3568
  var cursor = req_1.result;
@@ -3341,18 +3634,22 @@
3341
3634
  var source = index.isPrimaryKey ? store : store.index(index.name);
3342
3635
  var idbKeyRange = makeIDBKeyRange(range);
3343
3636
  var req = idbKeyRange ? source.count(idbKeyRange) : source.count();
3344
- req.onsuccess = wrap(function (ev) { return resolve(ev.target.result); });
3637
+ req.onsuccess = wrap(function (ev) {
3638
+ return resolve(ev.target.result);
3639
+ });
3345
3640
  req.onerror = eventRejectHandler(reject);
3346
3641
  });
3347
- }
3642
+ },
3348
3643
  };
3349
3644
  }
3350
3645
  var _a = extractSchema(db, tmpTrans), schema = _a.schema, hasGetAll = _a.hasGetAll, hasIdb3Features = _a.hasIdb3Features;
3351
- var tables = schema.tables.map(function (tableSchema) { return createDbCoreTable(tableSchema); });
3646
+ var tables = schema.tables.map(function (tableSchema) {
3647
+ return createDbCoreTable(tableSchema);
3648
+ });
3352
3649
  var tableMap = {};
3353
- tables.forEach(function (table) { return tableMap[table.name] = table; });
3650
+ tables.forEach(function (table) { return (tableMap[table.name] = table); });
3354
3651
  return {
3355
- stack: "dbcore",
3652
+ stack: 'dbcore',
3356
3653
  transaction: db.transaction.bind(db),
3357
3654
  table: function (name) {
3358
3655
  var result = tableMap[name];
@@ -3362,7 +3659,7 @@
3362
3659
  },
3363
3660
  MIN_KEY: -Infinity,
3364
3661
  MAX_KEY: getMaxKey(IdbKeyRange),
3365
- schema: schema
3662
+ schema: schema,
3366
3663
  };
3367
3664
  }
3368
3665
 
@@ -3376,7 +3673,7 @@
3376
3673
  var IDBKeyRange = _a.IDBKeyRange; _a.indexedDB;
3377
3674
  var dbcore = createMiddlewareStack(createDBCore(idbdb, IDBKeyRange, tmpTrans), middlewares.dbcore);
3378
3675
  return {
3379
- dbcore: dbcore
3676
+ dbcore: dbcore,
3380
3677
  };
3381
3678
  }
3382
3679
  function generateMiddlewareStacks(db, tmpTrans) {
@@ -3399,13 +3696,20 @@
3399
3696
  var schema = dbschema[tableName];
3400
3697
  objs.forEach(function (obj) {
3401
3698
  var propDesc = getPropertyDescriptor(obj, tableName);
3402
- if (!propDesc || ("value" in propDesc && propDesc.value === undefined)) {
3699
+ if (!propDesc || ('value' in propDesc && propDesc.value === undefined)) {
3403
3700
  if (obj === db.Transaction.prototype || obj instanceof db.Transaction) {
3404
3701
  setProp(obj, tableName, {
3405
- get: function () { return this.table(tableName); },
3702
+ get: function () {
3703
+ return this.table(tableName);
3704
+ },
3406
3705
  set: function (value) {
3407
- defineProperty(this, tableName, { value: value, writable: true, configurable: true, enumerable: true });
3408
- }
3706
+ defineProperty(this, tableName, {
3707
+ value: value,
3708
+ writable: true,
3709
+ configurable: true,
3710
+ enumerable: true,
3711
+ });
3712
+ },
3409
3713
  });
3410
3714
  }
3411
3715
  else {
@@ -3428,8 +3732,9 @@
3428
3732
  }
3429
3733
  function runUpgraders(db, oldVersion, idbUpgradeTrans, reject) {
3430
3734
  var globalSchema = db._dbSchema;
3431
- if (idbUpgradeTrans.objectStoreNames.contains('$meta') && !globalSchema.$meta) {
3432
- globalSchema.$meta = createTableSchema("$meta", parseIndexSyntax("")[0], []);
3735
+ if (idbUpgradeTrans.objectStoreNames.contains('$meta') &&
3736
+ !globalSchema.$meta) {
3737
+ globalSchema.$meta = createTableSchema('$meta', parseIndexSyntax('')[0], []);
3433
3738
  db._storeNames.push('$meta');
3434
3739
  }
3435
3740
  var trans = db._createTransaction('readwrite', db._storeNames, globalSchema);
@@ -3450,15 +3755,20 @@
3450
3755
  else {
3451
3756
  generateMiddlewareStacks(db, idbUpgradeTrans);
3452
3757
  return getExistingVersion(db, trans, oldVersion)
3453
- .then(function (oldVersion) { return updateTablesAndIndexes(db, oldVersion, trans, idbUpgradeTrans); })
3758
+ .then(function (oldVersion) {
3759
+ return updateTablesAndIndexes(db, oldVersion, trans, idbUpgradeTrans);
3760
+ })
3454
3761
  .catch(rejectTransaction);
3455
3762
  }
3456
3763
  });
3457
3764
  }
3458
3765
  function patchCurrentVersion(db, idbUpgradeTrans) {
3459
3766
  createMissingTables(db._dbSchema, idbUpgradeTrans);
3460
- if (idbUpgradeTrans.db.version % 10 === 0 && !idbUpgradeTrans.objectStoreNames.contains('$meta')) {
3461
- idbUpgradeTrans.db.createObjectStore('$meta').add(Math.ceil((idbUpgradeTrans.db.version / 10) - 1), 'version');
3767
+ if (idbUpgradeTrans.db.version % 10 === 0 &&
3768
+ !idbUpgradeTrans.objectStoreNames.contains('$meta')) {
3769
+ idbUpgradeTrans.db
3770
+ .createObjectStore('$meta')
3771
+ .add(Math.ceil(idbUpgradeTrans.db.version / 10 - 1), 'version');
3462
3772
  }
3463
3773
  var globalSchema = buildGlobalSchema(db, db.idbdb, idbUpgradeTrans);
3464
3774
  adjustToExistingIndexNames(db, db._dbSchema, idbUpgradeTrans);
@@ -3484,7 +3794,10 @@
3484
3794
  }
3485
3795
  function getExistingVersion(db, trans, oldVersion) {
3486
3796
  if (trans.storeNames.includes('$meta')) {
3487
- return trans.table('$meta').get('version').then(function (metaVersion) {
3797
+ return trans
3798
+ .table('$meta')
3799
+ .get('version')
3800
+ .then(function (metaVersion) {
3488
3801
  return metaVersion != null ? metaVersion : oldVersion;
3489
3802
  });
3490
3803
  }
@@ -3495,7 +3808,7 @@
3495
3808
  function updateTablesAndIndexes(db, oldVersion, trans, idbUpgradeTrans) {
3496
3809
  var queue = [];
3497
3810
  var versions = db._versions;
3498
- var globalSchema = db._dbSchema = buildGlobalSchema(db, db.idbdb, idbUpgradeTrans);
3811
+ var globalSchema = (db._dbSchema = buildGlobalSchema(db, db.idbdb, idbUpgradeTrans));
3499
3812
  var versToRun = versions.filter(function (v) { return v._cfg.version >= oldVersion; });
3500
3813
  if (versToRun.length === 0) {
3501
3814
  return DexiePromise.resolve();
@@ -3513,7 +3826,7 @@
3513
3826
  });
3514
3827
  diff.change.forEach(function (change) {
3515
3828
  if (change.recreate) {
3516
- throw new exceptions.Upgrade("Not yet support for changing primary key");
3829
+ throw new exceptions.Upgrade('Not yet support for changing primary key');
3517
3830
  }
3518
3831
  else {
3519
3832
  var store_1 = idbUpgradeTrans.objectStore(change.name);
@@ -3550,8 +3863,9 @@
3550
3863
  }
3551
3864
  }
3552
3865
  });
3553
- return (returnValue_1 && typeof returnValue_1.then === 'function' ?
3554
- DexiePromise.resolve(returnValue_1) : promiseFollowed.then(function () { return returnValue_1; }));
3866
+ return returnValue_1 && typeof returnValue_1.then === 'function'
3867
+ ? DexiePromise.resolve(returnValue_1)
3868
+ : promiseFollowed.then(function () { return returnValue_1; });
3555
3869
  }
3556
3870
  });
3557
3871
  queue.push(function (idbtrans) {
@@ -3575,8 +3889,9 @@
3575
3889
  });
3576
3890
  });
3577
3891
  function runQueue() {
3578
- return queue.length ? DexiePromise.resolve(queue.shift()(trans.idbtrans)).then(runQueue) :
3579
- DexiePromise.resolve();
3892
+ return queue.length
3893
+ ? DexiePromise.resolve(queue.shift()(trans.idbtrans)).then(runQueue)
3894
+ : DexiePromise.resolve();
3580
3895
  }
3581
3896
  return runQueue().then(function () {
3582
3897
  createMissingTables(globalSchema, idbUpgradeTrans);
@@ -3586,7 +3901,7 @@
3586
3901
  var diff = {
3587
3902
  del: [],
3588
3903
  add: [],
3589
- change: []
3904
+ change: [],
3590
3905
  };
3591
3906
  var table;
3592
3907
  for (table in oldSchema) {
@@ -3605,11 +3920,12 @@
3605
3920
  recreate: false,
3606
3921
  del: [],
3607
3922
  add: [],
3608
- change: []
3923
+ change: [],
3609
3924
  };
3610
- if ((
3611
- '' + (oldDef.primKey.keyPath || '')) !== ('' + (newDef.primKey.keyPath || '')) ||
3612
- (oldDef.primKey.auto !== newDef.primKey.auto)) {
3925
+ if (
3926
+ '' + (oldDef.primKey.keyPath || '') !==
3927
+ '' + (newDef.primKey.keyPath || '') ||
3928
+ oldDef.primKey.auto !== newDef.primKey.auto) {
3613
3929
  change.recreate = true;
3614
3930
  diff.change.push(change);
3615
3931
  }
@@ -3628,7 +3944,9 @@
3628
3944
  else if (oldIdx.src !== newIdx.src)
3629
3945
  change.change.push(newIdx);
3630
3946
  }
3631
- if (change.del.length > 0 || change.add.length > 0 || change.change.length > 0) {
3947
+ if (change.del.length > 0 ||
3948
+ change.add.length > 0 ||
3949
+ change.change.length > 0) {
3632
3950
  diff.change.push(change);
3633
3951
  }
3634
3952
  }
@@ -3637,9 +3955,9 @@
3637
3955
  return diff;
3638
3956
  }
3639
3957
  function createTable(idbtrans, tableName, primKey, indexes) {
3640
- var store = idbtrans.db.createObjectStore(tableName, primKey.keyPath ?
3641
- { keyPath: primKey.keyPath, autoIncrement: primKey.auto } :
3642
- { autoIncrement: primKey.auto });
3958
+ var store = idbtrans.db.createObjectStore(tableName, primKey.keyPath
3959
+ ? { keyPath: primKey.keyPath, autoIncrement: primKey.auto }
3960
+ : { autoIncrement: primKey.auto });
3643
3961
  indexes.forEach(function (idx) { return addIndex(store, idx); });
3644
3962
  return store;
3645
3963
  }
@@ -3653,12 +3971,17 @@
3653
3971
  });
3654
3972
  }
3655
3973
  function deleteRemovedTables(newSchema, idbtrans) {
3656
- [].slice.call(idbtrans.db.objectStoreNames).forEach(function (storeName) {
3974
+ [].slice
3975
+ .call(idbtrans.db.objectStoreNames)
3976
+ .forEach(function (storeName) {
3657
3977
  return newSchema[storeName] == null && idbtrans.db.deleteObjectStore(storeName);
3658
3978
  });
3659
3979
  }
3660
3980
  function addIndex(store, idx) {
3661
- store.createIndex(idx.name, idx.keyPath, { unique: idx.unique, multiEntry: idx.multi });
3981
+ store.createIndex(idx.name, idx.keyPath, {
3982
+ unique: idx.unique,
3983
+ multiEntry: idx.multi,
3984
+ });
3662
3985
  }
3663
3986
  function buildGlobalSchema(db, idbdb, tmpTrans) {
3664
3987
  var globalSchema = {};
@@ -3666,12 +3989,12 @@
3666
3989
  dbStoreNames.forEach(function (storeName) {
3667
3990
  var store = tmpTrans.objectStore(storeName);
3668
3991
  var keyPath = store.keyPath;
3669
- var primKey = createIndexSpec(nameFromKeyPath(keyPath), keyPath || "", true, false, !!store.autoIncrement, keyPath && typeof keyPath !== "string", true);
3992
+ var primKey = createIndexSpec(nameFromKeyPath(keyPath), keyPath || '', true, false, !!store.autoIncrement, keyPath && typeof keyPath !== 'string', true);
3670
3993
  var indexes = [];
3671
3994
  for (var j = 0; j < store.indexNames.length; ++j) {
3672
3995
  var idbindex = store.index(store.indexNames[j]);
3673
3996
  keyPath = idbindex.keyPath;
3674
- var index = createIndexSpec(idbindex.name, keyPath, !!idbindex.unique, !!idbindex.multiEntry, false, keyPath && typeof keyPath !== "string", false);
3997
+ var index = createIndexSpec(idbindex.name, keyPath, !!idbindex.unique, !!idbindex.multiEntry, false, keyPath && typeof keyPath !== 'string', false);
3675
3998
  indexes.push(index);
3676
3999
  }
3677
4000
  globalSchema[storeName] = createTableSchema(storeName, primKey, indexes);
@@ -3680,14 +4003,15 @@
3680
4003
  }
3681
4004
  function readGlobalSchema(db, idbdb, tmpTrans) {
3682
4005
  db.verno = idbdb.version / 10;
3683
- var globalSchema = db._dbSchema = buildGlobalSchema(db, idbdb, tmpTrans);
4006
+ var globalSchema = (db._dbSchema = buildGlobalSchema(db, idbdb, tmpTrans));
3684
4007
  db._storeNames = slice(idbdb.objectStoreNames, 0);
3685
4008
  setApiOnPlace(db, [db._allTables], keys(globalSchema), globalSchema);
3686
4009
  }
3687
4010
  function verifyInstalledSchema(db, tmpTrans) {
3688
4011
  var installedSchema = buildGlobalSchema(db, db.idbdb, tmpTrans);
3689
4012
  var diff = getSchemaDiff(installedSchema, db._dbSchema);
3690
- return !(diff.add.length || diff.change.some(function (ch) { return ch.add.length || ch.change.length; }));
4013
+ return !(diff.add.length ||
4014
+ diff.change.some(function (ch) { return ch.add.length || ch.change.length; }));
3691
4015
  }
3692
4016
  function adjustToExistingIndexNames(db, schema, idbtrans) {
3693
4017
  var storeNames = idbtrans.db.objectStoreNames;
@@ -3698,7 +4022,9 @@
3698
4022
  for (var j = 0; j < store.indexNames.length; ++j) {
3699
4023
  var indexName = store.indexNames[j];
3700
4024
  var keyPath = store.index(indexName).keyPath;
3701
- var dexieName = typeof keyPath === 'string' ? keyPath : "[" + slice(keyPath).join('+') + "]";
4025
+ var dexieName = typeof keyPath === 'string'
4026
+ ? keyPath
4027
+ : '[' + slice(keyPath).join('+') + ']';
3702
4028
  if (schema[storeName]) {
3703
4029
  var indexSpec = schema[storeName].idxByName[dexieName];
3704
4030
  if (indexSpec) {
@@ -3709,9 +4035,11 @@
3709
4035
  }
3710
4036
  }
3711
4037
  }
3712
- if (typeof navigator !== 'undefined' && /Safari/.test(navigator.userAgent) &&
4038
+ if (typeof navigator !== 'undefined' &&
4039
+ /Safari/.test(navigator.userAgent) &&
3713
4040
  !/(Chrome\/|Edge\/)/.test(navigator.userAgent) &&
3714
- _global.WorkerGlobalScope && _global instanceof _global.WorkerGlobalScope &&
4041
+ _global.WorkerGlobalScope &&
4042
+ _global instanceof _global.WorkerGlobalScope &&
3715
4043
  [].concat(navigator.userAgent.match(/Safari\/(\d*)/))[1] < 604) {
3716
4044
  db._hasGetAll = false;
3717
4045
  }
@@ -3722,8 +4050,10 @@
3722
4050
  var typeSplit = index.split(':');
3723
4051
  var type = (_a = typeSplit[1]) === null || _a === void 0 ? void 0 : _a.trim();
3724
4052
  index = typeSplit[0].trim();
3725
- var name = index.replace(/([&*]|\+\+)/g, "");
3726
- var keyPath = /^\[/.test(name) ? name.match(/^\[(.*)\]$/)[1].split('+') : name;
4053
+ var name = index.replace(/([&*]|\+\+)/g, '');
4054
+ var keyPath = /^\[/.test(name)
4055
+ ? name.match(/^\[(.*)\]$/)[1].split('+')
4056
+ : name;
3727
4057
  return createIndexSpec(name, keyPath || null, /\&/.test(index), /\*/.test(index), /\+\+/.test(index), isArray(keyPath), indexNum === 0, type);
3728
4058
  });
3729
4059
  }
@@ -3794,14 +4124,15 @@
3794
4124
  storesSource: null,
3795
4125
  dbschema: {},
3796
4126
  tables: {},
3797
- contentUpgrade: null
4127
+ contentUpgrade: null,
3798
4128
  };
3799
4129
  });
3800
4130
  }
3801
4131
 
3802
4132
  var connections = createConnectionsManager();
3803
4133
  function createConnectionsManager() {
3804
- if (typeof FinalizationRegistry !== 'undefined' && typeof WeakRef !== 'undefined') {
4134
+ if (typeof FinalizationRegistry !== 'undefined' &&
4135
+ typeof WeakRef !== 'undefined') {
3805
4136
  var _refs_1 = new Set();
3806
4137
  var _registry_1 = new FinalizationRegistry(function (ref) {
3807
4138
  _refs_1.delete(ref);
@@ -3857,19 +4188,19 @@
3857
4188
  }
3858
4189
 
3859
4190
  function getDbNamesTable(indexedDB, IDBKeyRange) {
3860
- var dbNamesDB = indexedDB["_dbNamesDB"];
4191
+ var dbNamesDB = indexedDB['_dbNamesDB'];
3861
4192
  if (!dbNamesDB) {
3862
- dbNamesDB = indexedDB["_dbNamesDB"] = new Dexie$1(DBNAMES_DB, {
4193
+ dbNamesDB = indexedDB['_dbNamesDB'] = new Dexie$1(DBNAMES_DB, {
3863
4194
  addons: [],
3864
4195
  indexedDB: indexedDB,
3865
4196
  IDBKeyRange: IDBKeyRange,
3866
4197
  });
3867
- dbNamesDB.version(1).stores({ dbnames: "name" });
4198
+ dbNamesDB.version(1).stores({ dbnames: 'name' });
3868
4199
  }
3869
- return dbNamesDB.table("dbnames");
4200
+ return dbNamesDB.table('dbnames');
3870
4201
  }
3871
4202
  function hasDatabasesNative(indexedDB) {
3872
- return indexedDB && typeof indexedDB.databases === "function";
4203
+ return indexedDB && typeof indexedDB.databases === 'function';
3873
4204
  }
3874
4205
  function getDatabaseNames(_a) {
3875
4206
  var indexedDB = _a.indexedDB, IDBKeyRange = _a.IDBKeyRange;
@@ -3917,15 +4248,17 @@
3917
4248
 
3918
4249
  var _a;
3919
4250
  function isEmptyRange(node) {
3920
- return !("from" in node);
4251
+ return !('from' in node);
3921
4252
  }
3922
4253
  var RangeSet = function (fromOrTree, to) {
3923
4254
  if (this) {
3924
- extend(this, arguments.length ? { d: 1, from: fromOrTree, to: arguments.length > 1 ? to : fromOrTree } : { d: 0 });
4255
+ extend(this, arguments.length
4256
+ ? { d: 1, from: fromOrTree, to: arguments.length > 1 ? to : fromOrTree }
4257
+ : { d: 0 });
3925
4258
  }
3926
4259
  else {
3927
4260
  var rv = new RangeSet();
3928
- if (fromOrTree && ("d" in fromOrTree)) {
4261
+ if (fromOrTree && 'd' in fromOrTree) {
3929
4262
  extend(rv, fromOrTree);
3930
4263
  }
3931
4264
  return rv;
@@ -4025,7 +4358,9 @@
4025
4358
  return false;
4026
4359
  }
4027
4360
  function getRangeSetIterator(node) {
4028
- var state = isEmptyRange(node) ? null : { s: 0, n: node };
4361
+ var state = isEmptyRange(node)
4362
+ ? null
4363
+ : { s: 0, n: node };
4029
4364
  return {
4030
4365
  next: function (key) {
4031
4366
  var keyProvided = arguments.length > 0;
@@ -4062,9 +4397,9 @@
4062
4397
  function rebalance(target) {
4063
4398
  var _a, _b;
4064
4399
  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);
4065
- var r = diff > 1 ? "r" : diff < -1 ? "l" : "";
4400
+ var r = diff > 1 ? 'r' : diff < -1 ? 'l' : '';
4066
4401
  if (r) {
4067
- var l = r === "r" ? "l" : "r";
4402
+ var l = r === 'r' ? 'l' : 'r';
4068
4403
  var rootClone = __assign({}, target);
4069
4404
  var oldRootRight = target[r];
4070
4405
  target.from = oldRootRight.from;
@@ -4092,7 +4427,9 @@
4092
4427
  }
4093
4428
 
4094
4429
  function obsSetsOverlap(os1, os2) {
4095
- return os1.all || os2.all || Object.keys(os1).some(function (key) { return os2[key] && rangesOverlap(os2[key], os1[key]); });
4430
+ return (os1.all ||
4431
+ os2.all ||
4432
+ Object.keys(os1).some(function (key) { return os2[key] && rangesOverlap(os2[key], os1[key]); }));
4096
4433
  }
4097
4434
 
4098
4435
  var cache = {};
@@ -4162,9 +4499,9 @@
4162
4499
  var state = db._state;
4163
4500
  var indexedDB = db._deps.indexedDB;
4164
4501
  if (state.isBeingOpened || db.idbdb)
4165
- return state.dbReadyPromise.then(function () { return state.dbOpenError ?
4166
- rejection(state.dbOpenError) :
4167
- db; });
4502
+ return state.dbReadyPromise.then(function () {
4503
+ return state.dbOpenError ? rejection(state.dbOpenError) : db;
4504
+ });
4168
4505
  state.isBeingOpened = true;
4169
4506
  state.dbOpenError = null;
4170
4507
  state.openComplete = false;
@@ -4177,97 +4514,102 @@
4177
4514
  }
4178
4515
  var resolveDbReady = state.dbReadyResolve,
4179
4516
  upgradeTransaction = null, wasCreated = false;
4180
- var tryOpenDB = function () { return new DexiePromise(function (resolve, reject) {
4181
- throwIfCancelled();
4182
- if (!indexedDB)
4183
- throw new exceptions.MissingAPI();
4184
- var dbName = db.name;
4185
- var req = state.autoSchema || !nativeVerToOpen ?
4186
- indexedDB.open(dbName) :
4187
- indexedDB.open(dbName, nativeVerToOpen);
4188
- if (!req)
4189
- throw new exceptions.MissingAPI();
4190
- req.onerror = eventRejectHandler(reject);
4191
- req.onblocked = wrap(db._fireOnBlocked);
4192
- req.onupgradeneeded = wrap(function (e) {
4193
- upgradeTransaction = req.transaction;
4194
- if (state.autoSchema && !db._options.allowEmptyDB) {
4195
- req.onerror = preventDefault;
4196
- upgradeTransaction.abort();
4197
- req.result.close();
4198
- var delreq = indexedDB.deleteDatabase(dbName);
4199
- delreq.onsuccess = delreq.onerror = wrap(function () {
4200
- reject(new exceptions.NoSuchDatabase("Database ".concat(dbName, " doesnt exist")));
4201
- });
4202
- }
4203
- else {
4204
- upgradeTransaction.onerror = eventRejectHandler(reject);
4205
- var oldVer = e.oldVersion > Math.pow(2, 62) ? 0 : e.oldVersion;
4206
- wasCreated = oldVer < 1;
4207
- db.idbdb = req.result;
4208
- if (schemaPatchMode) {
4209
- patchCurrentVersion(db, upgradeTransaction);
4517
+ var tryOpenDB = function () {
4518
+ return new DexiePromise(function (resolve, reject) {
4519
+ throwIfCancelled();
4520
+ if (!indexedDB)
4521
+ throw new exceptions.MissingAPI();
4522
+ var dbName = db.name;
4523
+ var req = state.autoSchema || !nativeVerToOpen
4524
+ ? indexedDB.open(dbName)
4525
+ : indexedDB.open(dbName, nativeVerToOpen);
4526
+ if (!req)
4527
+ throw new exceptions.MissingAPI();
4528
+ req.onerror = eventRejectHandler(reject);
4529
+ req.onblocked = wrap(db._fireOnBlocked);
4530
+ req.onupgradeneeded = wrap(function (e) {
4531
+ upgradeTransaction = req.transaction;
4532
+ if (state.autoSchema && !db._options.allowEmptyDB) {
4533
+ req.onerror = preventDefault;
4534
+ upgradeTransaction.abort();
4535
+ req.result.close();
4536
+ var delreq = indexedDB.deleteDatabase(dbName);
4537
+ delreq.onsuccess = delreq.onerror = wrap(function () {
4538
+ reject(new exceptions.NoSuchDatabase("Database ".concat(dbName, " doesnt exist")));
4539
+ });
4210
4540
  }
4211
- runUpgraders(db, oldVer / 10, upgradeTransaction, reject);
4212
- }
4213
- }, reject);
4214
- req.onsuccess = wrap(function () {
4215
- upgradeTransaction = null;
4216
- var idbdb = db.idbdb = req.result;
4217
- var objectStoreNames = slice(idbdb.objectStoreNames);
4218
- if (objectStoreNames.length > 0)
4219
- try {
4220
- var tmpTrans = idbdb.transaction(safariMultiStoreFix(objectStoreNames), 'readonly');
4221
- if (state.autoSchema)
4222
- readGlobalSchema(db, idbdb, tmpTrans);
4223
- else {
4224
- adjustToExistingIndexNames(db, db._dbSchema, tmpTrans);
4225
- if (!verifyInstalledSchema(db, tmpTrans) && !schemaPatchMode) {
4226
- 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.");
4227
- idbdb.close();
4228
- nativeVerToOpen = idbdb.version + 1;
4229
- schemaPatchMode = true;
4230
- return resolve(tryOpenDB());
4231
- }
4541
+ else {
4542
+ upgradeTransaction.onerror = eventRejectHandler(reject);
4543
+ var oldVer = e.oldVersion > Math.pow(2, 62) ? 0 : e.oldVersion;
4544
+ wasCreated = oldVer < 1;
4545
+ db.idbdb = req.result;
4546
+ if (schemaPatchMode) {
4547
+ patchCurrentVersion(db, upgradeTransaction);
4232
4548
  }
4233
- generateMiddlewareStacks(db, tmpTrans);
4234
- }
4235
- catch (e) {
4549
+ runUpgraders(db, oldVer / 10, upgradeTransaction, reject);
4236
4550
  }
4237
- connections.add(db);
4238
- idbdb.onversionchange = wrap(function (ev) {
4239
- state.vcFired = true;
4240
- db.on("versionchange").fire(ev);
4241
- });
4242
- idbdb.onclose = wrap(function () {
4243
- db.close({ disableAutoOpen: false });
4244
- });
4245
- if (wasCreated)
4246
- _onDatabaseCreated(db._deps, dbName);
4247
- resolve();
4248
- }, reject);
4249
- }).catch(function (err) {
4250
- switch (err === null || err === void 0 ? void 0 : err.name) {
4251
- case "UnknownError":
4252
- if (state.PR1398_maxLoop > 0) {
4253
- state.PR1398_maxLoop--;
4254
- console.warn('Dexie: Workaround for Chrome UnknownError on open()');
4255
- return tryOpenDB();
4256
- }
4257
- break;
4258
- case "VersionError":
4259
- if (nativeVerToOpen > 0) {
4260
- nativeVerToOpen = 0;
4261
- return tryOpenDB();
4262
- }
4263
- break;
4264
- }
4265
- return DexiePromise.reject(err);
4266
- }); };
4551
+ }, reject);
4552
+ req.onsuccess = wrap(function () {
4553
+ upgradeTransaction = null;
4554
+ var idbdb = (db.idbdb = req.result);
4555
+ var objectStoreNames = slice(idbdb.objectStoreNames);
4556
+ if (objectStoreNames.length > 0)
4557
+ try {
4558
+ var tmpTrans = idbdb.transaction(safariMultiStoreFix(objectStoreNames), 'readonly');
4559
+ if (state.autoSchema)
4560
+ readGlobalSchema(db, idbdb, tmpTrans);
4561
+ else {
4562
+ adjustToExistingIndexNames(db, db._dbSchema, tmpTrans);
4563
+ if (!verifyInstalledSchema(db, tmpTrans) && !schemaPatchMode) {
4564
+ 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.");
4565
+ idbdb.close();
4566
+ nativeVerToOpen = idbdb.version + 1;
4567
+ schemaPatchMode = true;
4568
+ return resolve(tryOpenDB());
4569
+ }
4570
+ }
4571
+ generateMiddlewareStacks(db, tmpTrans);
4572
+ }
4573
+ catch (e) {
4574
+ }
4575
+ connections.add(db);
4576
+ idbdb.onversionchange = wrap(function (ev) {
4577
+ state.vcFired = true;
4578
+ db.on('versionchange').fire(ev);
4579
+ });
4580
+ idbdb.onclose = wrap(function () {
4581
+ db.close({ disableAutoOpen: false });
4582
+ });
4583
+ if (wasCreated)
4584
+ _onDatabaseCreated(db._deps, dbName);
4585
+ resolve();
4586
+ }, reject);
4587
+ }).catch(function (err) {
4588
+ switch (err === null || err === void 0 ? void 0 : err.name) {
4589
+ case 'UnknownError':
4590
+ if (state.PR1398_maxLoop > 0) {
4591
+ state.PR1398_maxLoop--;
4592
+ console.warn('Dexie: Workaround for Chrome UnknownError on open()');
4593
+ return tryOpenDB();
4594
+ }
4595
+ break;
4596
+ case 'VersionError':
4597
+ if (nativeVerToOpen > 0) {
4598
+ nativeVerToOpen = 0;
4599
+ return tryOpenDB();
4600
+ }
4601
+ break;
4602
+ }
4603
+ return DexiePromise.reject(err);
4604
+ });
4605
+ };
4267
4606
  return DexiePromise.race([
4268
4607
  openCanceller,
4269
- (typeof navigator === 'undefined' ? DexiePromise.resolve() : idbReady()).then(tryOpenDB)
4270
- ]).then(function () {
4608
+ (typeof navigator === 'undefined'
4609
+ ? DexiePromise.resolve()
4610
+ : idbReady()).then(tryOpenDB),
4611
+ ])
4612
+ .then(function () {
4271
4613
  throwIfCancelled();
4272
4614
  state.onReadyBeingFired = [];
4273
4615
  return DexiePromise.resolve(vip(function () { return db.on.ready.fire(db.vip); })).then(function fireRemainders() {
@@ -4277,12 +4619,14 @@
4277
4619
  return DexiePromise.resolve(vip(function () { return remainders_1(db.vip); })).then(fireRemainders);
4278
4620
  }
4279
4621
  });
4280
- }).finally(function () {
4622
+ })
4623
+ .finally(function () {
4281
4624
  if (state.openCanceller === openCanceller) {
4282
4625
  state.onReadyBeingFired = null;
4283
4626
  state.isBeingOpened = false;
4284
4627
  }
4285
- }).catch(function (err) {
4628
+ })
4629
+ .catch(function (err) {
4286
4630
  state.dbOpenError = err;
4287
4631
  try {
4288
4632
  upgradeTransaction && upgradeTransaction.abort();
@@ -4292,16 +4636,19 @@
4292
4636
  db._close();
4293
4637
  }
4294
4638
  return rejection(err);
4295
- }).finally(function () {
4639
+ })
4640
+ .finally(function () {
4296
4641
  state.openComplete = true;
4297
4642
  resolveDbReady();
4298
- }).then(function () {
4643
+ })
4644
+ .then(function () {
4299
4645
  if (wasCreated) {
4300
4646
  var everything_1 = {};
4301
4647
  db.tables.forEach(function (table) {
4302
4648
  table.schema.indexes.forEach(function (idx) {
4303
4649
  if (idx.name)
4304
- everything_1["idb://".concat(db.name, "/").concat(table.name, "/").concat(idx.name)] = new RangeSet(-Infinity, [[[]]]);
4650
+ everything_1["idb://".concat(db.name, "/").concat(table.name, "/").concat(idx.name)] =
4651
+ new RangeSet(-Infinity, [[[]]]);
4305
4652
  });
4306
4653
  everything_1["idb://".concat(db.name, "/").concat(table.name, "/")] = everything_1["idb://".concat(db.name, "/").concat(table.name, "/:dels")] = new RangeSet(-Infinity, [[[]]]);
4307
4654
  });
@@ -4317,10 +4664,13 @@
4317
4664
  function step(getNext) {
4318
4665
  return function (val) {
4319
4666
  var next = getNext(val), value = next.value;
4320
- return next.done ? value :
4321
- (!value || typeof value.then !== 'function' ?
4322
- isArray(value) ? Promise.all(value).then(onSuccess, onError) : onSuccess(value) :
4323
- value.then(onSuccess, onError));
4667
+ return next.done
4668
+ ? value
4669
+ : !value || typeof value.then !== 'function'
4670
+ ? isArray(value)
4671
+ ? Promise.all(value).then(onSuccess, onError)
4672
+ : onSuccess(value)
4673
+ : value.then(onSuccess, onError);
4324
4674
  };
4325
4675
  }
4326
4676
  return step(callNext)();
@@ -4329,7 +4679,7 @@
4329
4679
  function extractTransactionArgs(mode, _tableArgs_, scopeFunc) {
4330
4680
  var i = arguments.length;
4331
4681
  if (i < 2)
4332
- throw new exceptions.InvalidArgument("Too few arguments");
4682
+ throw new exceptions.InvalidArgument('Too few arguments');
4333
4683
  var args = new Array(i - 1);
4334
4684
  while (--i)
4335
4685
  args[i - 1] = arguments[i];
@@ -4344,7 +4694,7 @@
4344
4694
  trans.explicit = true;
4345
4695
  var zoneProps = {
4346
4696
  trans: trans,
4347
- transless: transless
4697
+ transless: transless,
4348
4698
  };
4349
4699
  if (parentTransaction) {
4350
4700
  trans.idbtrans = parentTransaction.idbtrans;
@@ -4356,10 +4706,16 @@
4356
4706
  db._state.PR1398_maxLoop = 3;
4357
4707
  }
4358
4708
  catch (ex) {
4359
- if (ex.name === errnames.InvalidState && db.isOpen() && --db._state.PR1398_maxLoop > 0) {
4709
+ if (ex.name === errnames.InvalidState &&
4710
+ db.isOpen() &&
4711
+ --db._state.PR1398_maxLoop > 0) {
4360
4712
  console.warn('Dexie: Need to reopen db');
4361
4713
  db.close({ disableAutoOpen: false });
4362
- return db.open().then(function () { return enterTransactionScope(db, mode, storeNames, null, scopeFunc); });
4714
+ return db
4715
+ .open()
4716
+ .then(function () {
4717
+ return enterTransactionScope(db, mode, storeNames, null, scopeFunc);
4718
+ });
4363
4719
  }
4364
4720
  return rejection(ex);
4365
4721
  }
@@ -4376,20 +4732,27 @@
4376
4732
  var decrementor = decrementExpectedAwaits.bind(null, null);
4377
4733
  returnValue.then(decrementor, decrementor);
4378
4734
  }
4379
- else if (typeof returnValue.next === 'function' && typeof returnValue.throw === 'function') {
4735
+ else if (typeof returnValue.next === 'function' &&
4736
+ typeof returnValue.throw === 'function') {
4380
4737
  returnValue = awaitIterator(returnValue);
4381
4738
  }
4382
4739
  }
4383
4740
  }, zoneProps);
4384
- return (returnValue && typeof returnValue.then === 'function' ?
4385
- DexiePromise.resolve(returnValue).then(function (x) { return trans.active ?
4386
- x
4387
- : rejection(new exceptions.PrematureCommit("Transaction committed too early. See http://bit.ly/2kdckMn")); })
4388
- : promiseFollowed.then(function () { return returnValue; })).then(function (x) {
4741
+ return (returnValue && typeof returnValue.then === 'function'
4742
+ ?
4743
+ DexiePromise.resolve(returnValue).then(function (x) {
4744
+ return trans.active
4745
+ ? x
4746
+ : rejection(new exceptions.PrematureCommit('Transaction committed too early. See http://bit.ly/2kdckMn'));
4747
+ })
4748
+ :
4749
+ promiseFollowed.then(function () { return returnValue; }))
4750
+ .then(function (x) {
4389
4751
  if (parentTransaction)
4390
4752
  trans._resolve();
4391
4753
  return trans._completion.then(function () { return x; });
4392
- }).catch(function (e) {
4754
+ })
4755
+ .catch(function (e) {
4393
4756
  trans._reject(e);
4394
4757
  return rejection(e);
4395
4758
  });
@@ -4410,8 +4773,13 @@
4410
4773
  var allVirtualIndexes = [];
4411
4774
  function addVirtualIndexes(keyPath, keyTail, lowLevelIndex) {
4412
4775
  var keyPathAlias = getKeyPathAlias(keyPath);
4413
- var indexList = (indexLookup[keyPathAlias] = indexLookup[keyPathAlias] || []);
4414
- var keyLength = keyPath == null ? 0 : typeof keyPath === 'string' ? 1 : keyPath.length;
4776
+ var indexList = (indexLookup[keyPathAlias] =
4777
+ indexLookup[keyPathAlias] || []);
4778
+ var keyLength = keyPath == null
4779
+ ? 0
4780
+ : typeof keyPath === 'string'
4781
+ ? 1
4782
+ : keyPath.length;
4415
4783
  var isVirtual = keyTail > 0;
4416
4784
  var virtualIndex = __assign(__assign({}, lowLevelIndex), { name: isVirtual
4417
4785
  ? "".concat(keyPathAlias, "(virtual-from:").concat(lowLevelIndex.name, ")")
@@ -4421,16 +4789,16 @@
4421
4789
  allVirtualIndexes.push(virtualIndex);
4422
4790
  }
4423
4791
  if (keyLength > 1) {
4424
- var virtualKeyPath = keyLength === 2 ?
4425
- keyPath[0] :
4426
- keyPath.slice(0, keyLength - 1);
4792
+ var virtualKeyPath = keyLength === 2
4793
+ ? keyPath[0]
4794
+ : keyPath.slice(0, keyLength - 1);
4427
4795
  addVirtualIndexes(virtualKeyPath, keyTail + 1, lowLevelIndex);
4428
4796
  }
4429
4797
  indexList.sort(function (a, b) { return a.keyTail - b.keyTail; });
4430
4798
  return virtualIndex;
4431
4799
  }
4432
4800
  var primaryKey = addVirtualIndexes(schema.primaryKey.keyPath, 0, schema.primaryKey);
4433
- indexLookup[":id"] = [primaryKey];
4801
+ indexLookup[':id'] = [primaryKey];
4434
4802
  for (var _i = 0, _a = schema.indexes; _i < _a.length; _i++) {
4435
4803
  var index = _a[_i];
4436
4804
  addVirtualIndexes(index.keyPath, 0, index);
@@ -4441,80 +4809,82 @@
4441
4809
  }
4442
4810
  function translateRange(range, keyTail) {
4443
4811
  return {
4444
- type: range.type === 1 ?
4445
- 2 :
4446
- range.type,
4812
+ type: range.type === 1
4813
+ ? 2
4814
+ : range.type,
4447
4815
  lower: pad(range.lower, range.lowerOpen ? down.MAX_KEY : down.MIN_KEY, keyTail),
4448
4816
  lowerOpen: true,
4449
4817
  upper: pad(range.upper, range.upperOpen ? down.MIN_KEY : down.MAX_KEY, keyTail),
4450
- upperOpen: true
4818
+ upperOpen: true,
4451
4819
  };
4452
4820
  }
4453
4821
  function translateRequest(req) {
4454
4822
  var index = req.query.index;
4455
- return index.isVirtual ? __assign(__assign({}, req), { query: {
4456
- index: index.lowLevelIndex,
4457
- range: translateRange(req.query.range, index.keyTail)
4458
- } }) : req;
4823
+ return index.isVirtual
4824
+ ? __assign(__assign({}, req), { query: {
4825
+ index: index.lowLevelIndex,
4826
+ range: translateRange(req.query.range, index.keyTail),
4827
+ } }) : req;
4459
4828
  }
4460
4829
  var result = __assign(__assign({}, table), { schema: __assign(__assign({}, schema), { primaryKey: primaryKey, indexes: allVirtualIndexes, getIndexByKeyPath: findBestIndex }), count: function (req) {
4461
4830
  return table.count(translateRequest(req));
4462
4831
  }, query: function (req) {
4463
4832
  return table.query(translateRequest(req));
4464
4833
  }, openCursor: function (req) {
4465
- var _a = req.query.index, keyTail = _a.keyTail, isVirtual = _a.isVirtual, keyLength = _a.keyLength;
4834
+ var _a = req.query
4835
+ .index, keyTail = _a.keyTail, isVirtual = _a.isVirtual, keyLength = _a.keyLength;
4466
4836
  if (!isVirtual)
4467
4837
  return table.openCursor(req);
4468
4838
  function createVirtualCursor(cursor) {
4469
4839
  function _continue(key) {
4470
- key != null ?
4471
- cursor.continue(pad(key, req.reverse ? down.MAX_KEY : down.MIN_KEY, keyTail)) :
4472
- req.unique ?
4473
- cursor.continue(cursor.key.slice(0, keyLength)
4474
- .concat(req.reverse
4475
- ? down.MIN_KEY
4476
- : down.MAX_KEY, keyTail)) :
4477
- cursor.continue();
4840
+ key != null
4841
+ ? cursor.continue(pad(key, req.reverse ? down.MAX_KEY : down.MIN_KEY, keyTail))
4842
+ : req.unique
4843
+ ? cursor.continue(cursor.key
4844
+ .slice(0, keyLength)
4845
+ .concat(req.reverse ? down.MIN_KEY : down.MAX_KEY, keyTail))
4846
+ : cursor.continue();
4478
4847
  }
4479
4848
  var virtualCursor = Object.create(cursor, {
4480
4849
  continue: { value: _continue },
4481
4850
  continuePrimaryKey: {
4482
4851
  value: function (key, primaryKey) {
4483
4852
  cursor.continuePrimaryKey(pad(key, down.MAX_KEY, keyTail), primaryKey);
4484
- }
4853
+ },
4485
4854
  },
4486
4855
  primaryKey: {
4487
4856
  get: function () {
4488
4857
  return cursor.primaryKey;
4489
- }
4858
+ },
4490
4859
  },
4491
4860
  key: {
4492
4861
  get: function () {
4493
4862
  var key = cursor.key;
4494
- return keyLength === 1 ?
4495
- key[0] :
4496
- key.slice(0, keyLength);
4497
- }
4863
+ return keyLength === 1
4864
+ ? key[0]
4865
+ : key.slice(0, keyLength);
4866
+ },
4498
4867
  },
4499
4868
  value: {
4500
4869
  get: function () {
4501
4870
  return cursor.value;
4502
- }
4503
- }
4871
+ },
4872
+ },
4504
4873
  });
4505
4874
  return virtualCursor;
4506
4875
  }
4507
- return table.openCursor(translateRequest(req))
4876
+ return table
4877
+ .openCursor(translateRequest(req))
4508
4878
  .then(function (cursor) { return cursor && createVirtualCursor(cursor); });
4509
4879
  } });
4510
4880
  return result;
4511
4881
  } });
4512
4882
  }
4513
4883
  var virtualIndexMiddleware = {
4514
- stack: "dbcore",
4515
- name: "VirtualIndexMiddleware",
4884
+ stack: 'dbcore',
4885
+ name: 'VirtualIndexMiddleware',
4516
4886
  level: 1,
4517
- create: createVirtualIndexMiddleware
4887
+ create: createVirtualIndexMiddleware,
4518
4888
  };
4519
4889
 
4520
4890
  function getObjectDiff(a, b, rv, prfx) {
@@ -4558,127 +4928,155 @@
4558
4928
  }
4559
4929
 
4560
4930
  var hooksMiddleware = {
4561
- stack: "dbcore",
4562
- name: "HooksMiddleware",
4931
+ stack: 'dbcore',
4932
+ name: 'HooksMiddleware',
4563
4933
  level: 2,
4564
- create: function (downCore) { return (__assign(__assign({}, downCore), { table: function (tableName) {
4565
- var downTable = downCore.table(tableName);
4566
- var primaryKey = downTable.schema.primaryKey;
4567
- var tableMiddleware = __assign(__assign({}, downTable), { mutate: function (req) {
4568
- var dxTrans = PSD.trans;
4569
- var _a = dxTrans.table(tableName).hook, deleting = _a.deleting, creating = _a.creating, updating = _a.updating;
4570
- switch (req.type) {
4571
- case 'add':
4572
- if (creating.fire === nop)
4573
- break;
4574
- return dxTrans._promise('readwrite', function () { return addPutOrDelete(req); }, true);
4575
- case 'put':
4576
- if (creating.fire === nop && updating.fire === nop)
4577
- break;
4578
- return dxTrans._promise('readwrite', function () { return addPutOrDelete(req); }, true);
4579
- case 'delete':
4580
- if (deleting.fire === nop)
4581
- break;
4582
- return dxTrans._promise('readwrite', function () { return addPutOrDelete(req); }, true);
4583
- case 'deleteRange':
4584
- if (deleting.fire === nop)
4585
- break;
4586
- return dxTrans._promise('readwrite', function () { return deleteRange(req); }, true);
4587
- }
4588
- return downTable.mutate(req);
4589
- function addPutOrDelete(req) {
4934
+ create: function (downCore) {
4935
+ return (__assign(__assign({}, downCore), { table: function (tableName) {
4936
+ var downTable = downCore.table(tableName);
4937
+ var primaryKey = downTable.schema.primaryKey;
4938
+ var tableMiddleware = __assign(__assign({}, downTable), { mutate: function (req) {
4590
4939
  var dxTrans = PSD.trans;
4591
- var keys = req.keys || getEffectiveKeys(primaryKey, req);
4592
- if (!keys)
4593
- throw new Error("Keys missing");
4594
- req = req.type === 'add' || req.type === 'put' ? __assign(__assign({}, req), { keys: keys }) : __assign({}, req);
4595
- if (req.type !== 'delete')
4596
- req.values = __spreadArray([], req.values, true);
4597
- if (req.keys)
4598
- req.keys = __spreadArray([], req.keys, true);
4599
- return getExistingValues(downTable, req, keys).then(function (existingValues) {
4600
- var contexts = keys.map(function (key, i) {
4601
- var existingValue = existingValues[i];
4602
- var ctx = { onerror: null, onsuccess: null };
4603
- if (req.type === 'delete') {
4604
- deleting.fire.call(ctx, key, existingValue, dxTrans);
4605
- }
4606
- else if (req.type === 'add' || existingValue === undefined) {
4607
- var generatedPrimaryKey = creating.fire.call(ctx, key, req.values[i], dxTrans);
4608
- if (key == null && generatedPrimaryKey != null) {
4609
- key = generatedPrimaryKey;
4610
- req.keys[i] = key;
4611
- if (!primaryKey.outbound) {
4612
- setByKeyPath(req.values[i], primaryKey.keyPath, key);
4613
- }
4940
+ var _a = dxTrans.table(tableName).hook, deleting = _a.deleting, creating = _a.creating, updating = _a.updating;
4941
+ switch (req.type) {
4942
+ case 'add':
4943
+ if (creating.fire === nop)
4944
+ break;
4945
+ return dxTrans._promise('readwrite', function () { return addPutOrDelete(req); }, true);
4946
+ case 'put':
4947
+ if (creating.fire === nop && updating.fire === nop)
4948
+ break;
4949
+ return dxTrans._promise('readwrite', function () { return addPutOrDelete(req); }, true);
4950
+ case 'delete':
4951
+ if (deleting.fire === nop)
4952
+ break;
4953
+ return dxTrans._promise('readwrite', function () { return addPutOrDelete(req); }, true);
4954
+ case 'deleteRange':
4955
+ if (deleting.fire === nop)
4956
+ break;
4957
+ return dxTrans._promise('readwrite', function () { return deleteRange(req); }, true);
4958
+ }
4959
+ return downTable.mutate(req);
4960
+ function addPutOrDelete(req) {
4961
+ var dxTrans = PSD.trans;
4962
+ var keys = req.keys || getEffectiveKeys(primaryKey, req);
4963
+ if (!keys)
4964
+ throw new Error('Keys missing');
4965
+ req =
4966
+ req.type === 'add' || req.type === 'put'
4967
+ ? __assign(__assign({}, req), { keys: keys }) : __assign({}, req);
4968
+ if (req.type !== 'delete')
4969
+ req.values = __spreadArray([], req.values, true);
4970
+ if (req.keys)
4971
+ req.keys = __spreadArray([], req.keys, true);
4972
+ return getExistingValues(downTable, req, keys).then(function (existingValues) {
4973
+ var contexts = keys.map(function (key, i) {
4974
+ var existingValue = existingValues[i];
4975
+ var ctx = { onerror: null, onsuccess: null };
4976
+ if (req.type === 'delete') {
4977
+ deleting.fire.call(ctx, key, existingValue, dxTrans);
4614
4978
  }
4615
- }
4616
- else {
4617
- var objectDiff = getObjectDiff(existingValue, req.values[i]);
4618
- var additionalChanges_1 = updating.fire.call(ctx, objectDiff, key, existingValue, dxTrans);
4619
- if (additionalChanges_1) {
4620
- var requestedValue_1 = req.values[i];
4621
- Object.keys(additionalChanges_1).forEach(function (keyPath) {
4622
- if (hasOwn(requestedValue_1, keyPath)) {
4623
- requestedValue_1[keyPath] = additionalChanges_1[keyPath];
4624
- }
4625
- else {
4626
- setByKeyPath(requestedValue_1, keyPath, additionalChanges_1[keyPath]);
4979
+ else if (req.type === 'add' ||
4980
+ existingValue === undefined) {
4981
+ var generatedPrimaryKey = creating.fire.call(ctx, key, req.values[i], dxTrans);
4982
+ if (key == null && generatedPrimaryKey != null) {
4983
+ key = generatedPrimaryKey;
4984
+ req.keys[i] = key;
4985
+ if (!primaryKey.outbound) {
4986
+ setByKeyPath(req.values[i], primaryKey.keyPath, key);
4627
4987
  }
4628
- });
4988
+ }
4629
4989
  }
4630
- }
4631
- return ctx;
4990
+ else {
4991
+ var objectDiff = getObjectDiff(existingValue, req.values[i]);
4992
+ var additionalChanges_1 = updating.fire.call(ctx, objectDiff, key, existingValue, dxTrans);
4993
+ if (additionalChanges_1) {
4994
+ var requestedValue_1 = req.values[i];
4995
+ Object.keys(additionalChanges_1).forEach(function (keyPath) {
4996
+ if (hasOwn(requestedValue_1, keyPath)) {
4997
+ requestedValue_1[keyPath] =
4998
+ additionalChanges_1[keyPath];
4999
+ }
5000
+ else {
5001
+ setByKeyPath(requestedValue_1, keyPath, additionalChanges_1[keyPath]);
5002
+ }
5003
+ });
5004
+ }
5005
+ }
5006
+ return ctx;
5007
+ });
5008
+ return downTable
5009
+ .mutate(req)
5010
+ .then(function (_a) {
5011
+ var failures = _a.failures, results = _a.results, numFailures = _a.numFailures, lastResult = _a.lastResult;
5012
+ for (var i = 0; i < keys.length; ++i) {
5013
+ var primKey = results ? results[i] : keys[i];
5014
+ var ctx = contexts[i];
5015
+ if (primKey == null) {
5016
+ ctx.onerror && ctx.onerror(failures[i]);
5017
+ }
5018
+ else {
5019
+ ctx.onsuccess &&
5020
+ ctx.onsuccess(req.type === 'put' && existingValues[i]
5021
+ ? req.values[i]
5022
+ : primKey
5023
+ );
5024
+ }
5025
+ }
5026
+ return { failures: failures, results: results, numFailures: numFailures, lastResult: lastResult };
5027
+ })
5028
+ .catch(function (error) {
5029
+ contexts.forEach(function (ctx) { return ctx.onerror && ctx.onerror(error); });
5030
+ return Promise.reject(error);
5031
+ });
4632
5032
  });
4633
- return downTable.mutate(req).then(function (_a) {
4634
- var failures = _a.failures, results = _a.results, numFailures = _a.numFailures, lastResult = _a.lastResult;
4635
- for (var i = 0; i < keys.length; ++i) {
4636
- var primKey = results ? results[i] : keys[i];
4637
- var ctx = contexts[i];
4638
- if (primKey == null) {
4639
- ctx.onerror && ctx.onerror(failures[i]);
5033
+ }
5034
+ function deleteRange(req) {
5035
+ return deleteNextChunk(req.trans, req.range, 10000);
5036
+ }
5037
+ function deleteNextChunk(trans, range, limit) {
5038
+ return downTable
5039
+ .query({
5040
+ trans: trans,
5041
+ values: false,
5042
+ query: { index: primaryKey, range: range },
5043
+ limit: limit,
5044
+ })
5045
+ .then(function (_a) {
5046
+ var result = _a.result;
5047
+ return addPutOrDelete({
5048
+ type: 'delete',
5049
+ keys: result,
5050
+ trans: trans,
5051
+ }).then(function (res) {
5052
+ if (res.numFailures > 0)
5053
+ return Promise.reject(res.failures[0]);
5054
+ if (result.length < limit) {
5055
+ return {
5056
+ failures: [],
5057
+ numFailures: 0,
5058
+ lastResult: undefined,
5059
+ };
4640
5060
  }
4641
5061
  else {
4642
- ctx.onsuccess && ctx.onsuccess(req.type === 'put' && existingValues[i] ?
4643
- req.values[i] :
4644
- primKey
4645
- );
5062
+ return deleteNextChunk(trans, __assign(__assign({}, range), { lower: result[result.length - 1], lowerOpen: true }), limit);
4646
5063
  }
4647
- }
4648
- return { failures: failures, results: results, numFailures: numFailures, lastResult: lastResult };
4649
- }).catch(function (error) {
4650
- contexts.forEach(function (ctx) { return ctx.onerror && ctx.onerror(error); });
4651
- return Promise.reject(error);
5064
+ });
4652
5065
  });
4653
- });
4654
- }
4655
- function deleteRange(req) {
4656
- return deleteNextChunk(req.trans, req.range, 10000);
4657
- }
4658
- function deleteNextChunk(trans, range, limit) {
4659
- return downTable.query({ trans: trans, values: false, query: { index: primaryKey, range: range }, limit: limit })
4660
- .then(function (_a) {
4661
- var result = _a.result;
4662
- return addPutOrDelete({ type: 'delete', keys: result, trans: trans }).then(function (res) {
4663
- if (res.numFailures > 0)
4664
- return Promise.reject(res.failures[0]);
4665
- if (result.length < limit) {
4666
- return { failures: [], numFailures: 0, lastResult: undefined };
4667
- }
4668
- else {
4669
- return deleteNextChunk(trans, __assign(__assign({}, range), { lower: result[result.length - 1], lowerOpen: true }), limit);
4670
- }
4671
- });
4672
- });
4673
- }
4674
- } });
4675
- return tableMiddleware;
4676
- } })); }
5066
+ }
5067
+ } });
5068
+ return tableMiddleware;
5069
+ } }));
5070
+ },
4677
5071
  };
4678
5072
  function getExistingValues(table, req, effectiveKeys) {
4679
- return req.type === "add"
5073
+ return req.type === 'add'
4680
5074
  ? Promise.resolve([])
4681
- : table.getMany({ trans: req.trans, keys: effectiveKeys, cache: "immutable" });
5075
+ : table.getMany({
5076
+ trans: req.trans,
5077
+ keys: effectiveKeys,
5078
+ cache: 'immutable',
5079
+ });
4682
5080
  }
4683
5081
 
4684
5082
  function getFromTransactionCache(keys, cache, clone) {
@@ -4701,7 +5099,7 @@
4701
5099
  }
4702
5100
  }
4703
5101
  var cacheExistingValuesMiddleware = {
4704
- stack: "dbcore",
5102
+ stack: 'dbcore',
4705
5103
  level: -1,
4706
5104
  create: function (core) {
4707
5105
  return {
@@ -4711,20 +5109,20 @@
4711
5109
  if (!req.cache) {
4712
5110
  return table.getMany(req);
4713
5111
  }
4714
- var cachedResult = getFromTransactionCache(req.keys, req.trans["_cache"], req.cache === "clone");
5112
+ var cachedResult = getFromTransactionCache(req.keys, req.trans['_cache'], req.cache === 'clone');
4715
5113
  if (cachedResult) {
4716
5114
  return DexiePromise.resolve(cachedResult);
4717
5115
  }
4718
5116
  return table.getMany(req).then(function (res) {
4719
- req.trans["_cache"] = {
5117
+ req.trans['_cache'] = {
4720
5118
  keys: req.keys,
4721
- values: req.cache === "clone" ? deepClone(res) : res,
5119
+ values: req.cache === 'clone' ? deepClone(res) : res,
4722
5120
  };
4723
5121
  return res;
4724
5122
  });
4725
5123
  }, mutate: function (req) {
4726
- if (req.type !== "add")
4727
- req.trans["_cache"] = null;
5124
+ if (req.type !== 'add')
5125
+ req.trans['_cache'] = null;
4728
5126
  return table.mutate(req);
4729
5127
  } });
4730
5128
  },
@@ -4756,9 +5154,9 @@
4756
5154
  }
4757
5155
 
4758
5156
  var observabilityMiddleware = {
4759
- stack: "dbcore",
5157
+ stack: 'dbcore',
4760
5158
  level: 0,
4761
- name: "Observability",
5159
+ name: 'Observability',
4762
5160
  create: function (core) {
4763
5161
  var dbName = core.schema.name;
4764
5162
  var FULL_RANGE = new RangeSet(core.MIN_KEY, core.MAX_KEY);
@@ -4772,7 +5170,11 @@
4772
5170
  var schema = table.schema;
4773
5171
  var primaryKey = schema.primaryKey, indexes = schema.indexes;
4774
5172
  var extractKey = primaryKey.extractKey, outbound = primaryKey.outbound;
4775
- var indexesWithAutoIncPK = primaryKey.autoIncrement && indexes.filter(function (index) { return index.compound && index.keyPath.includes(primaryKey.keyPath); });
5173
+ var indexesWithAutoIncPK = primaryKey.autoIncrement &&
5174
+ indexes.filter(function (index) {
5175
+ return index.compound &&
5176
+ index.keyPath.includes(primaryKey.keyPath);
5177
+ });
4776
5178
  var tableClone = __assign(__assign({}, table), { mutate: function (req) {
4777
5179
  var _a, _b;
4778
5180
  var trans = req.trans;
@@ -4782,20 +5184,25 @@
4782
5184
  return (mutatedParts[part] ||
4783
5185
  (mutatedParts[part] = new RangeSet()));
4784
5186
  };
4785
- var pkRangeSet = getRangeSet("");
4786
- var delsRangeSet = getRangeSet(":dels");
5187
+ var pkRangeSet = getRangeSet('');
5188
+ var delsRangeSet = getRangeSet(':dels');
4787
5189
  var type = req.type;
4788
- var _c = req.type === "deleteRange"
5190
+ var _c = req.type === 'deleteRange'
4789
5191
  ? [req.range]
4790
- : req.type === "delete"
5192
+ : req.type === 'delete'
4791
5193
  ? [req.keys]
4792
5194
  : req.values.length < 50
4793
- ? [getEffectiveKeys(primaryKey, req).filter(function (id) { return id; }), req.values]
5195
+ ? [
5196
+ getEffectiveKeys(primaryKey, req).filter(function (id) { return id; }),
5197
+ req.values,
5198
+ ]
4794
5199
  : [], keys = _c[0], newObjs = _c[1];
4795
- var oldCache = req.trans["_cache"];
5200
+ var oldCache = req.trans['_cache'];
4796
5201
  if (isArray(keys)) {
4797
5202
  pkRangeSet.addKeys(keys);
4798
- var oldObjs = type === 'delete' || keys.length === newObjs.length ? getFromTransactionCache(keys, oldCache) : null;
5203
+ var oldObjs = type === 'delete' || keys.length === newObjs.length
5204
+ ? getFromTransactionCache(keys, oldCache)
5205
+ : null;
4799
5206
  if (!oldObjs) {
4800
5207
  delsRangeSet.addKeys(keys);
4801
5208
  }
@@ -4806,7 +5213,7 @@
4806
5213
  else if (keys) {
4807
5214
  var range = {
4808
5215
  from: (_a = keys.lower) !== null && _a !== void 0 ? _a : core.MIN_KEY,
4809
- to: (_b = keys.upper) !== null && _b !== void 0 ? _b : core.MAX_KEY
5216
+ to: (_b = keys.upper) !== null && _b !== void 0 ? _b : core.MAX_KEY,
4810
5217
  };
4811
5218
  delsRangeSet.add(range);
4812
5219
  pkRangeSet.add(range);
@@ -4814,7 +5221,9 @@
4814
5221
  else {
4815
5222
  pkRangeSet.add(FULL_RANGE);
4816
5223
  delsRangeSet.add(FULL_RANGE);
4817
- schema.indexes.forEach(function (idx) { return getRangeSet(idx.name).add(FULL_RANGE); });
5224
+ schema.indexes.forEach(function (idx) {
5225
+ return getRangeSet(idx.name).add(FULL_RANGE);
5226
+ });
4818
5227
  }
4819
5228
  return table.mutate(req).then(function (res) {
4820
5229
  if (keys && (req.type === 'add' || req.type === 'put')) {
@@ -4853,9 +5262,10 @@
4853
5262
  tableClone[method] = function (req) {
4854
5263
  var subscr = PSD.subscr;
4855
5264
  var isLiveQuery = !!subscr;
4856
- var cachable = isCachableContext(PSD, table) && isCachableRequest(method, req);
5265
+ var cachable = isCachableContext(PSD, table) &&
5266
+ isCachableRequest(method, req);
4857
5267
  var obsSet = cachable
4858
- ? req.obsSet = {}
5268
+ ? (req.obsSet = {})
4859
5269
  : subscr;
4860
5270
  if (isLiveQuery) {
4861
5271
  var getRangeSet = function (indexName) {
@@ -4863,26 +5273,28 @@
4863
5273
  return (obsSet[part] ||
4864
5274
  (obsSet[part] = new RangeSet()));
4865
5275
  };
4866
- var pkRangeSet_1 = getRangeSet("");
4867
- var delsRangeSet_1 = getRangeSet(":dels");
5276
+ var pkRangeSet_1 = getRangeSet('');
5277
+ var delsRangeSet_1 = getRangeSet(':dels');
4868
5278
  var _a = readSubscribers[method](req), queriedIndex = _a[0], queriedRanges = _a[1];
4869
- if (method === 'query' && queriedIndex.isPrimaryKey && !req.values) {
5279
+ if (method === 'query' &&
5280
+ queriedIndex.isPrimaryKey &&
5281
+ !req.values) {
4870
5282
  delsRangeSet_1.add(queriedRanges);
4871
5283
  }
4872
5284
  else {
4873
- getRangeSet(queriedIndex.name || "").add(queriedRanges);
5285
+ getRangeSet(queriedIndex.name || '').add(queriedRanges);
4874
5286
  }
4875
5287
  if (!queriedIndex.isPrimaryKey) {
4876
- if (method === "count") {
5288
+ if (method === 'count') {
4877
5289
  delsRangeSet_1.add(FULL_RANGE);
4878
5290
  }
4879
5291
  else {
4880
- var keysPromise_1 = method === "query" &&
5292
+ var keysPromise_1 = method === 'query' &&
4881
5293
  outbound &&
4882
5294
  req.values &&
4883
5295
  table.query(__assign(__assign({}, req), { values: false }));
4884
5296
  return table[method].apply(this, arguments).then(function (res) {
4885
- if (method === "query") {
5297
+ if (method === 'query') {
4886
5298
  if (outbound && req.values) {
4887
5299
  return keysPromise_1.then(function (_a) {
4888
5300
  var resultingKeys = _a.result;
@@ -4900,9 +5312,10 @@
4900
5312
  delsRangeSet_1.addKeys(pKeys);
4901
5313
  }
4902
5314
  }
4903
- else if (method === "openCursor") {
5315
+ else if (method === 'openCursor') {
4904
5316
  var cursor_1 = res;
4905
- var wantValues_1 = req.values;
5317
+ var wantValues_1 = req
5318
+ .values;
4906
5319
  return (cursor_1 &&
4907
5320
  Object.create(cursor_1, {
4908
5321
  key: {
@@ -4920,7 +5333,8 @@
4920
5333
  },
4921
5334
  value: {
4922
5335
  get: function () {
4923
- wantValues_1 && pkRangeSet_1.addKey(cursor_1.primaryKey);
5336
+ wantValues_1 &&
5337
+ pkRangeSet_1.addKey(cursor_1.primaryKey);
4924
5338
  return cursor_1.value;
4925
5339
  },
4926
5340
  },
@@ -4940,13 +5354,17 @@
4940
5354
  };
4941
5355
  function trackAffectedIndexes(getRangeSet, schema, oldObjs, newObjs) {
4942
5356
  function addAffectedIndex(ix) {
4943
- var rangeSet = getRangeSet(ix.name || "");
5357
+ var rangeSet = getRangeSet(ix.name || '');
4944
5358
  function extractKey(obj) {
4945
5359
  return obj != null ? ix.extractKey(obj) : null;
4946
5360
  }
4947
- var addKeyOrKeys = function (key) { return ix.multiEntry && isArray(key)
4948
- ? key.forEach(function (key) { return rangeSet.addKey(key); })
4949
- : rangeSet.addKey(key); };
5361
+ var addKeyOrKeys = function (key) {
5362
+ return ix.multiEntry && isArray(key)
5363
+ ?
5364
+ key.forEach(function (key) { return rangeSet.addKey(key); })
5365
+ :
5366
+ rangeSet.addKey(key);
5367
+ };
4950
5368
  (oldObjs || newObjs).forEach(function (_, i) {
4951
5369
  var oldKey = oldObjs && extractKey(oldObjs[i]);
4952
5370
  var newKey = newObjs && extractKey(newObjs[i]);
@@ -5160,7 +5578,8 @@
5160
5578
  var _a;
5161
5579
  return entry.req.limit === req.limit &&
5162
5580
  entry.req.values === req.values &&
5163
- ((_a = entry.req.direction) !== null && _a !== void 0 ? _a : 'next') === reqDirection_1 &&
5581
+ ((_a = entry.req.direction) !== null && _a !== void 0 ? _a : 'next') ===
5582
+ reqDirection_1 &&
5164
5583
  areRangesEqual(entry.req.query.range, req.query.range);
5165
5584
  });
5166
5585
  if (equalEntry)
@@ -5174,7 +5593,8 @@
5174
5593
  var _a;
5175
5594
  var limit = 'limit' in entry.req ? entry.req.limit : Infinity;
5176
5595
  return (limit >= req.limit &&
5177
- ((_a = entry.req.direction) !== null && _a !== void 0 ? _a : 'next') === reqDirection_1 &&
5596
+ ((_a = entry.req.direction) !== null && _a !== void 0 ? _a : 'next') ===
5597
+ reqDirection_1 &&
5178
5598
  (req.values ? entry.req.values : true) &&
5179
5599
  isSuperRange(entry.req.query.range, req.query.range));
5180
5600
  });
@@ -5189,7 +5609,7 @@
5189
5609
 
5190
5610
  function subscribeToCacheEntry(cacheEntry, container, requery, signal) {
5191
5611
  cacheEntry.subscribers.add(requery);
5192
- signal.addEventListener("abort", function () {
5612
+ signal.addEventListener('abort', function () {
5193
5613
  cacheEntry.subscribers.delete(requery);
5194
5614
  if (cacheEntry.subscribers.size === 0) {
5195
5615
  enqueForDeletion(cacheEntry, container);
@@ -5225,14 +5645,18 @@
5225
5645
  if (tblCache) {
5226
5646
  var table = core.table(storeName);
5227
5647
  var ops = tblCache.optimisticOps.filter(function (op) { return op.trans === idbtrans; });
5228
- if (idbtrans._explicit && wasCommitted && idbtrans.mutatedParts) {
5648
+ if (idbtrans._explicit &&
5649
+ wasCommitted &&
5650
+ idbtrans.mutatedParts) {
5229
5651
  for (var _a = 0, _b = Object.values(tblCache.queries.query); _a < _b.length; _a++) {
5230
5652
  var entries = _b[_a];
5231
5653
  for (var _c = 0, _d = entries.slice(); _c < _d.length; _c++) {
5232
5654
  var entry = _d[_c];
5233
5655
  if (obsSetsOverlap(entry.obsSet, idbtrans.mutatedParts)) {
5234
5656
  delArrayItem(entries, entry);
5235
- entry.subscribers.forEach(function (requery) { return affectedSubscribers_1.add(requery); });
5657
+ entry.subscribers.forEach(function (requery) {
5658
+ return affectedSubscribers_1.add(requery);
5659
+ });
5236
5660
  }
5237
5661
  }
5238
5662
  }
@@ -5251,18 +5675,24 @@
5251
5675
  var modRes = applyOptimisticOps(entry.res, entry.req, ops, table, entry, freezeResults);
5252
5676
  if (entry.dirty) {
5253
5677
  delArrayItem(entries, entry);
5254
- entry.subscribers.forEach(function (requery) { return affectedSubscribers_1.add(requery); });
5678
+ entry.subscribers.forEach(function (requery) {
5679
+ return affectedSubscribers_1.add(requery);
5680
+ });
5255
5681
  }
5256
5682
  else if (modRes !== entry.res) {
5257
5683
  entry.res = modRes;
5258
- entry.promise = DexiePromise.resolve({ result: modRes });
5684
+ entry.promise = DexiePromise.resolve({
5685
+ result: modRes,
5686
+ });
5259
5687
  }
5260
5688
  }
5261
5689
  else {
5262
5690
  if (entry.dirty) {
5263
5691
  delArrayItem(entries, entry);
5264
5692
  }
5265
- entry.subscribers.forEach(function (requery) { return affectedSubscribers_1.add(requery); });
5693
+ entry.subscribers.forEach(function (requery) {
5694
+ return affectedSubscribers_1.add(requery);
5695
+ });
5266
5696
  }
5267
5697
  }
5268
5698
  }
@@ -5300,7 +5730,9 @@
5300
5730
  if (!tblCache)
5301
5731
  return downTable.mutate(req);
5302
5732
  var promise = downTable.mutate(req);
5303
- if ((req.type === 'add' || req.type === 'put') && (req.values.length >= 50 || getEffectiveKeys(primKey, req).some(function (key) { return key == null; }))) {
5733
+ if ((req.type === 'add' || req.type === 'put') &&
5734
+ (req.values.length >= 50 ||
5735
+ getEffectiveKeys(primKey, req).some(function (key) { return key == null; }))) {
5304
5736
  promise.then(function (res) {
5305
5737
  var reqWithResolvedKeys = __assign(__assign({}, req), { values: req.values.map(function (value, i) {
5306
5738
  var _a;
@@ -5314,7 +5746,10 @@
5314
5746
  }) });
5315
5747
  var adjustedReq = adjustOptimisticFromFailures(tblCache, reqWithResolvedKeys, res);
5316
5748
  tblCache.optimisticOps.push(adjustedReq);
5317
- queueMicrotask(function () { return req.mutatedParts && signalSubscribersLazily(req.mutatedParts); });
5749
+ queueMicrotask(function () {
5750
+ return req.mutatedParts &&
5751
+ signalSubscribersLazily(req.mutatedParts);
5752
+ });
5318
5753
  });
5319
5754
  }
5320
5755
  else {
@@ -5338,16 +5773,20 @@
5338
5773
  return promise;
5339
5774
  }, query: function (req) {
5340
5775
  var _a;
5341
- if (!isCachableContext(PSD, downTable) || !isCachableRequest("query", req))
5776
+ if (!isCachableContext(PSD, downTable) ||
5777
+ !isCachableRequest('query', req))
5342
5778
  return downTable.query(req);
5343
- var freezeResults = ((_a = PSD.trans) === null || _a === void 0 ? void 0 : _a.db._options.cache) === 'immutable';
5779
+ var freezeResults = ((_a = PSD.trans) === null || _a === void 0 ? void 0 : _a.db._options.cache) ===
5780
+ 'immutable';
5344
5781
  var _b = PSD, requery = _b.requery, signal = _b.signal;
5345
5782
  var _c = findCompatibleQuery(dbName, tableName, 'query', req), cacheEntry = _c[0], exactMatch = _c[1], tblCache = _c[2], container = _c[3];
5346
5783
  if (cacheEntry && exactMatch) {
5347
5784
  cacheEntry.obsSet = req.obsSet;
5348
5785
  }
5349
5786
  else {
5350
- var promise = downTable.query(req).then(function (res) {
5787
+ var promise = downTable
5788
+ .query(req)
5789
+ .then(function (res) {
5351
5790
  var result = res.result;
5352
5791
  if (cacheEntry)
5353
5792
  cacheEntry.res = result;
@@ -5361,7 +5800,8 @@
5361
5800
  res.result = deepClone(result);
5362
5801
  }
5363
5802
  return res;
5364
- }).catch(function (error) {
5803
+ })
5804
+ .catch(function (error) {
5365
5805
  if (container && cacheEntry)
5366
5806
  delArrayItem(container, cacheEntry);
5367
5807
  return Promise.reject(error);
@@ -5387,7 +5827,7 @@
5387
5827
  },
5388
5828
  objs: new Map(),
5389
5829
  optimisticOps: [],
5390
- unsignaledParts: {}
5830
+ unsignaledParts: {},
5391
5831
  };
5392
5832
  }
5393
5833
  tblCache.queries.query[req.query.index.name || ''] = container;
@@ -5412,7 +5852,7 @@
5412
5852
  if (prop === 'db')
5413
5853
  return vipDb;
5414
5854
  return Reflect.get(target, prop, receiver);
5415
- }
5855
+ },
5416
5856
  });
5417
5857
  }
5418
5858
 
@@ -5427,7 +5867,7 @@
5427
5867
  indexedDB: deps.indexedDB, IDBKeyRange: deps.IDBKeyRange, cache: 'cloned', maxConnections: DEFAULT_MAX_CONNECTIONS }, options);
5428
5868
  this._deps = {
5429
5869
  indexedDB: options.indexedDB,
5430
- IDBKeyRange: options.IDBKeyRange
5870
+ IDBKeyRange: options.IDBKeyRange,
5431
5871
  };
5432
5872
  var addons = options.addons;
5433
5873
  this._dbSchema = {};
@@ -5457,7 +5897,9 @@
5457
5897
  });
5458
5898
  this._state = state;
5459
5899
  this.name = name;
5460
- this.on = Events(this, "populate", "blocked", "versionchange", "close", { ready: [promisableChain, nop] });
5900
+ this.on = Events(this, 'populate', 'blocked', 'versionchange', 'close', {
5901
+ ready: [promisableChain, nop],
5902
+ });
5461
5903
  this.once = function (event, callback) {
5462
5904
  var fn = function () {
5463
5905
  var args = [];
@@ -5501,26 +5943,29 @@
5501
5943
  this.Transaction = createTransactionConstructor(this);
5502
5944
  this.Version = createVersionConstructor(this);
5503
5945
  this.WhereClause = createWhereClauseConstructor(this);
5504
- this.on("versionchange", function (ev) {
5946
+ this.on('versionchange', function (ev) {
5505
5947
  if (ev.newVersion > 0)
5506
5948
  console.warn("Another connection wants to upgrade database '".concat(_this.name, "'. Closing db now to resume the upgrade."));
5507
5949
  else
5508
5950
  console.warn("Another connection wants to delete database '".concat(_this.name, "'. Closing db now to resume the delete request."));
5509
5951
  _this.close({ disableAutoOpen: false });
5510
5952
  });
5511
- this.on("blocked", function (ev) {
5953
+ this.on('blocked', function (ev) {
5512
5954
  if (!ev.newVersion || ev.newVersion < ev.oldVersion)
5513
5955
  console.warn("Dexie.delete('".concat(_this.name, "') was blocked"));
5514
5956
  else
5515
5957
  console.warn("Upgrade '".concat(_this.name, "' blocked by other connection holding version ").concat(ev.oldVersion / 10));
5516
5958
  });
5517
5959
  this._maxKey = getMaxKey(options.IDBKeyRange);
5518
- this._createTransaction = function (mode, storeNames, dbschema, parentTransaction) { return new _this.Transaction(mode, storeNames, dbschema, _this._options.chromeTransactionDurability, parentTransaction); };
5960
+ this._createTransaction = function (mode, storeNames, dbschema, parentTransaction) {
5961
+ return new _this.Transaction(mode, storeNames, dbschema, _this._options.chromeTransactionDurability, parentTransaction);
5962
+ };
5519
5963
  this._fireOnBlocked = function (ev) {
5520
- _this.on("blocked").fire(ev);
5521
- connections.toArray()
5964
+ _this.on('blocked').fire(ev);
5965
+ connections
5966
+ .toArray()
5522
5967
  .filter(function (c) { return c.name === _this.name && c !== _this && !c._state.vcFired; })
5523
- .map(function (c) { return c.on("versionchange").fire(ev); });
5968
+ .map(function (c) { return c.on('versionchange').fire(ev); });
5524
5969
  };
5525
5970
  this.use(cacheExistingValuesMiddleware);
5526
5971
  this.use(cacheMiddleware);
@@ -5544,7 +5989,7 @@
5544
5989
  return vipify(tx, vipDB);
5545
5990
  };
5546
5991
  return rv;
5547
- }
5992
+ },
5548
5993
  });
5549
5994
  this.vip = vipDB;
5550
5995
  addons.forEach(function (addon) { return addon(_this); });
@@ -5554,7 +5999,7 @@
5554
5999
  throw new exceptions.Type("Given version is not a positive number");
5555
6000
  versionNumber = Math.round(versionNumber * 10) / 10;
5556
6001
  if (this.idbdb || this._state.isBeingOpened)
5557
- throw new exceptions.Schema("Cannot add version when database is open");
6002
+ throw new exceptions.Schema('Cannot add version when database is open');
5558
6003
  this.verno = Math.max(this.verno, versionNumber);
5559
6004
  var versions = this._versions;
5560
6005
  var versionInstance = versions.filter(function (v) { return v._cfg.version === versionNumber; })[0];
@@ -5569,26 +6014,34 @@
5569
6014
  };
5570
6015
  Dexie.prototype._whenReady = function (fn) {
5571
6016
  var _this = this;
5572
- return (this.idbdb && (this._state.openComplete || PSD.letThrough || this._vip)) ? fn() : new DexiePromise(function (resolve, reject) {
5573
- if (_this._state.openComplete) {
5574
- return reject(new exceptions.DatabaseClosed(_this._state.dbOpenError));
5575
- }
5576
- if (!_this._state.isBeingOpened) {
5577
- if (!_this._state.autoOpen) {
5578
- reject(new exceptions.DatabaseClosed());
5579
- return;
6017
+ return this.idbdb &&
6018
+ (this._state.openComplete || PSD.letThrough || this._vip)
6019
+ ? fn()
6020
+ : new DexiePromise(function (resolve, reject) {
6021
+ if (_this._state.openComplete) {
6022
+ return reject(new exceptions.DatabaseClosed(_this._state.dbOpenError));
5580
6023
  }
5581
- _this.open().catch(nop);
5582
- }
5583
- _this._state.dbReadyPromise.then(resolve, reject);
5584
- }).then(fn);
6024
+ if (!_this._state.isBeingOpened) {
6025
+ if (!_this._state.autoOpen) {
6026
+ reject(new exceptions.DatabaseClosed());
6027
+ return;
6028
+ }
6029
+ _this.open().catch(nop);
6030
+ }
6031
+ _this._state.dbReadyPromise.then(resolve, reject);
6032
+ }).then(fn);
5585
6033
  };
5586
6034
  Dexie.prototype.use = function (_a) {
5587
6035
  var stack = _a.stack, create = _a.create, level = _a.level, name = _a.name;
5588
6036
  if (name)
5589
6037
  this.unuse({ stack: stack, name: name });
5590
6038
  var middlewares = this._middlewares[stack] || (this._middlewares[stack] = []);
5591
- middlewares.push({ stack: stack, create: create, level: level == null ? 10 : level, name: name });
6039
+ middlewares.push({
6040
+ stack: stack,
6041
+ create: create,
6042
+ level: level == null ? 10 : level,
6043
+ name: name,
6044
+ });
5592
6045
  middlewares.sort(function (a, b) { return a.level - b.level; });
5593
6046
  return this;
5594
6047
  };
@@ -5596,9 +6049,11 @@
5596
6049
  var stack = _a.stack, name = _a.name, create = _a.create;
5597
6050
  if (stack && this._middlewares[stack]) {
5598
6051
  this._middlewares[stack] = this._middlewares[stack].filter(function (mw) {
5599
- return create ? mw.create !== create :
5600
- name ? mw.name !== name :
5601
- false;
6052
+ return create
6053
+ ? mw.create !== create
6054
+ : name
6055
+ ? mw.name !== name
6056
+ : false;
5602
6057
  });
5603
6058
  }
5604
6059
  return this;
@@ -5641,8 +6096,7 @@
5641
6096
  }
5642
6097
  else {
5643
6098
  this._close();
5644
- state.autoOpen = this._options.autoOpen ||
5645
- state.isBeingOpened;
6099
+ state.autoOpen = this._options.autoOpen || state.isBeingOpened;
5646
6100
  state.openComplete = false;
5647
6101
  state.dbOpenError = null;
5648
6102
  }
@@ -5664,7 +6118,7 @@
5664
6118
  req.onblocked = _this._fireOnBlocked;
5665
6119
  };
5666
6120
  if (hasInvalidArguments)
5667
- throw new exceptions.InvalidArgument("Invalid closeOptions argument to db.delete()");
6121
+ throw new exceptions.InvalidArgument('Invalid closeOptions argument to db.delete()');
5668
6122
  if (state.isBeingOpened) {
5669
6123
  state.dbReadyPromise.then(doDelete);
5670
6124
  }
@@ -5681,7 +6135,7 @@
5681
6135
  };
5682
6136
  Dexie.prototype.hasBeenClosed = function () {
5683
6137
  var dbOpenError = this._state.dbOpenError;
5684
- return dbOpenError && (dbOpenError.name === 'DatabaseClosed');
6138
+ return dbOpenError && dbOpenError.name === 'DatabaseClosed';
5685
6139
  };
5686
6140
  Dexie.prototype.hasFailed = function () {
5687
6141
  return this._state.dbOpenError !== null;
@@ -5704,7 +6158,9 @@
5704
6158
  Dexie.prototype._transaction = function (mode, tables, scopeFunc) {
5705
6159
  var _this = this;
5706
6160
  var parentTransaction = PSD.trans;
5707
- if (!parentTransaction || parentTransaction.db !== this || mode.indexOf('!') !== -1)
6161
+ if (!parentTransaction ||
6162
+ parentTransaction.db !== this ||
6163
+ mode.indexOf('!') !== -1)
5708
6164
  parentTransaction = null;
5709
6165
  var onlyIfCompatible = mode.indexOf('?') !== -1;
5710
6166
  mode = mode.replace('!', '').replace('?', '');
@@ -5713,51 +6169,56 @@
5713
6169
  storeNames = tables.map(function (table) {
5714
6170
  var storeName = table instanceof _this.Table ? table.name : table;
5715
6171
  if (typeof storeName !== 'string')
5716
- throw new TypeError("Invalid table argument to Dexie.transaction(). Only Table or String are allowed");
6172
+ throw new TypeError('Invalid table argument to Dexie.transaction(). Only Table or String are allowed');
5717
6173
  return storeName;
5718
6174
  });
5719
- if (mode == "r" || mode === READONLY)
6175
+ if (mode == 'r' || mode === READONLY)
5720
6176
  idbMode = READONLY;
5721
- else if (mode == "rw" || mode == READWRITE)
6177
+ else if (mode == 'rw' || mode == READWRITE)
5722
6178
  idbMode = READWRITE;
5723
6179
  else
5724
- throw new exceptions.InvalidArgument("Invalid transaction mode: " + mode);
6180
+ throw new exceptions.InvalidArgument('Invalid transaction mode: ' + mode);
5725
6181
  if (parentTransaction) {
5726
6182
  if (parentTransaction.mode === READONLY && idbMode === READWRITE) {
5727
6183
  if (onlyIfCompatible) {
5728
6184
  parentTransaction = null;
5729
6185
  }
5730
6186
  else
5731
- throw new exceptions.SubTransaction("Cannot enter a sub-transaction with READWRITE mode when parent transaction is READONLY");
6187
+ throw new exceptions.SubTransaction('Cannot enter a sub-transaction with READWRITE mode when parent transaction is READONLY');
5732
6188
  }
5733
6189
  if (parentTransaction) {
5734
6190
  storeNames.forEach(function (storeName) {
5735
- if (parentTransaction && parentTransaction.storeNames.indexOf(storeName) === -1) {
6191
+ if (parentTransaction &&
6192
+ parentTransaction.storeNames.indexOf(storeName) === -1) {
5736
6193
  if (onlyIfCompatible) {
5737
6194
  parentTransaction = null;
5738
6195
  }
5739
6196
  else
5740
- throw new exceptions.SubTransaction("Table " + storeName +
5741
- " not included in parent transaction.");
6197
+ throw new exceptions.SubTransaction('Table ' + storeName + ' not included in parent transaction.');
5742
6198
  }
5743
6199
  });
5744
6200
  }
5745
- if (onlyIfCompatible && parentTransaction && !parentTransaction.active) {
6201
+ if (onlyIfCompatible &&
6202
+ parentTransaction &&
6203
+ !parentTransaction.active) {
5746
6204
  parentTransaction = null;
5747
6205
  }
5748
6206
  }
5749
6207
  }
5750
6208
  catch (e) {
5751
- return parentTransaction ?
5752
- parentTransaction._promise(null, function (_, reject) { reject(e); }) :
5753
- rejection(e);
6209
+ return parentTransaction
6210
+ ? parentTransaction._promise(null, function (_, reject) {
6211
+ reject(e);
6212
+ })
6213
+ : rejection(e);
5754
6214
  }
5755
6215
  var enterTransaction = enterTransactionScope.bind(null, this, idbMode, storeNames, parentTransaction, scopeFunc);
5756
- return (parentTransaction ?
5757
- parentTransaction._promise(idbMode, enterTransaction, "lock") :
5758
- PSD.trans ?
5759
- usePSD(PSD.transless, function () { return _this._whenReady(enterTransaction); }) :
5760
- this._whenReady(enterTransaction));
6216
+ return parentTransaction
6217
+ ? parentTransaction._promise(idbMode, enterTransaction, 'lock')
6218
+ : PSD.trans
6219
+ ?
6220
+ usePSD(PSD.transless, function () { return _this._whenReady(enterTransaction); })
6221
+ : this._whenReady(enterTransaction);
5761
6222
  };
5762
6223
  Dexie.prototype.table = function (tableName) {
5763
6224
  if (!hasOwn(this._allTables, tableName)) {
@@ -5768,15 +6229,15 @@
5768
6229
  return Dexie;
5769
6230
  }());
5770
6231
 
5771
- var symbolObservable = typeof Symbol !== "undefined" && "observable" in Symbol
6232
+ var symbolObservable = typeof Symbol !== 'undefined' && 'observable' in Symbol
5772
6233
  ? Symbol.observable
5773
- : "@@observable";
6234
+ : '@@observable';
5774
6235
  var Observable = (function () {
5775
6236
  function Observable(subscribe) {
5776
6237
  this._subscribe = subscribe;
5777
6238
  }
5778
6239
  Observable.prototype.subscribe = function (x, error, complete) {
5779
- return this._subscribe(!x || typeof x === "function" ? { next: x, error: error, complete: complete } : x);
6240
+ return this._subscribe(!x || typeof x === 'function' ? { next: x, error: error, complete: complete } : x);
5780
6241
  };
5781
6242
  Observable.prototype[symbolObservable] = function () {
5782
6243
  return this;
@@ -5787,8 +6248,11 @@
5787
6248
  var domDeps;
5788
6249
  try {
5789
6250
  domDeps = {
5790
- indexedDB: _global.indexedDB || _global.mozIndexedDB || _global.webkitIndexedDB || _global.msIndexedDB,
5791
- IDBKeyRange: _global.IDBKeyRange || _global.webkitIDBKeyRange
6251
+ indexedDB: _global.indexedDB ||
6252
+ _global.mozIndexedDB ||
6253
+ _global.webkitIndexedDB ||
6254
+ _global.msIndexedDB,
6255
+ IDBKeyRange: _global.IDBKeyRange || _global.webkitIDBKeyRange,
5792
6256
  };
5793
6257
  }
5794
6258
  catch (e) {
@@ -5862,22 +6326,32 @@
5862
6326
  signal: abortController.signal,
5863
6327
  requery: doQuery,
5864
6328
  querier: querier,
5865
- trans: null
6329
+ trans: null,
5866
6330
  };
5867
6331
  var ret = execute(ctx);
6332
+ if (!startedListening) {
6333
+ globalEvents(DEXIE_STORAGE_MUTATED_EVENT_NAME, mutationListener);
6334
+ startedListening = true;
6335
+ }
5868
6336
  Promise.resolve(ret).then(function (result) {
5869
6337
  hasValue = true;
5870
6338
  currentValue = result;
5871
6339
  if (closed || ctx.signal.aborted) {
5872
6340
  return;
5873
6341
  }
5874
- accumMuts = {};
5875
- currentObs = subscr;
5876
- if (!objectIsEmpty(currentObs) && !startedListening) {
5877
- globalEvents(DEXIE_STORAGE_MUTATED_EVENT_NAME, mutationListener);
5878
- startedListening = true;
6342
+ if (shouldNotify()) {
6343
+ doQuery();
6344
+ }
6345
+ else {
6346
+ currentObs = subscr;
6347
+ if (shouldNotify()) {
6348
+ doQuery();
6349
+ }
6350
+ else {
6351
+ accumMuts = {};
6352
+ execInGlobalContext(function () { return !closed && observer.next && observer.next(result); });
6353
+ }
5879
6354
  }
5880
- execInGlobalContext(function () { return !closed && observer.next && observer.next(result); });
5881
6355
  }, function (err) {
5882
6356
  hasValue = false;
5883
6357
  if (!['DatabaseClosedError', 'AbortError'].includes(err === null || err === void 0 ? void 0 : err.name)) {
@@ -5905,10 +6379,13 @@
5905
6379
  return db.delete();
5906
6380
  },
5907
6381
  exists: function (name) {
5908
- return new Dexie(name, { addons: [] }).open().then(function (db) {
6382
+ return new Dexie(name, { addons: [] })
6383
+ .open()
6384
+ .then(function (db) {
5909
6385
  db.close();
5910
6386
  return true;
5911
- }).catch('NoSuchDatabaseError', function () { return false; });
6387
+ })
6388
+ .catch('NoSuchDatabaseError', function () { return false; });
5912
6389
  },
5913
6390
  getDatabaseNames: function (cb) {
5914
6391
  try {
@@ -5924,9 +6401,9 @@
5924
6401
  }
5925
6402
  return Class;
5926
6403
  }, ignoreTransaction: function (scopeFunc) {
5927
- return PSD.trans ?
5928
- usePSD(PSD.transless, scopeFunc) :
5929
- scopeFunc();
6404
+ return PSD.trans
6405
+ ? usePSD(PSD.transless || globalPSD, scopeFunc)
6406
+ : scopeFunc();
5930
6407
  }, vip: vip, async: function (generatorFn) {
5931
6408
  return function () {
5932
6409
  try {
@@ -5951,22 +6428,19 @@
5951
6428
  }
5952
6429
  },
5953
6430
  currentTransaction: {
5954
- get: function () { return PSD.trans || null; }
6431
+ get: function () { return PSD.trans || null; },
5955
6432
  }, waitFor: function (promiseOrFunction, optionalTimeout) {
5956
- var promise = DexiePromise.resolve(typeof promiseOrFunction === 'function' ?
5957
- Dexie.ignoreTransaction(promiseOrFunction) :
5958
- promiseOrFunction)
5959
- .timeout(optionalTimeout || 60000);
5960
- return PSD.trans ?
5961
- PSD.trans.waitFor(promise) :
5962
- promise;
6433
+ var promise = DexiePromise.resolve(typeof promiseOrFunction === 'function'
6434
+ ? Dexie.ignoreTransaction(promiseOrFunction)
6435
+ : promiseOrFunction).timeout(optionalTimeout || 60000);
6436
+ return PSD.trans ? PSD.trans.waitFor(promise) : promise;
5963
6437
  },
5964
6438
  Promise: DexiePromise,
5965
6439
  debug: {
5966
6440
  get: function () { return debug; },
5967
6441
  set: function (value) {
5968
6442
  setDebug(value);
5969
- }
6443
+ },
5970
6444
  },
5971
6445
  derive: derive, extend: extend, props: props, override: override,
5972
6446
  Events: Events, on: globalEvents, liveQuery: liveQuery, extendObservabilitySet: extendObservabilitySet,
@@ -5974,21 +6448,22 @@
5974
6448
  minKey: minKey,
5975
6449
  addons: [],
5976
6450
  connections: {
5977
- get: connections.toArray
6451
+ get: connections.toArray,
5978
6452
  },
5979
6453
  errnames: errnames,
5980
6454
  dependencies: domDeps, cache: cache,
5981
6455
  semVer: DEXIE_VERSION, version: DEXIE_VERSION.split('.')
5982
6456
  .map(function (n) { return parseInt(n); })
5983
- .reduce(function (p, c, i) { return p + (c / Math.pow(10, i * 2)); }) }));
6457
+ .reduce(function (p, c, i) { return p + c / Math.pow(10, i * 2); }) }));
5984
6458
  Dexie.maxKey = getMaxKey(Dexie.dependencies.IDBKeyRange);
5985
6459
 
5986
- if (typeof dispatchEvent !== 'undefined' && typeof addEventListener !== 'undefined') {
6460
+ if (typeof dispatchEvent !== 'undefined' &&
6461
+ typeof addEventListener !== 'undefined') {
5987
6462
  globalEvents(DEXIE_STORAGE_MUTATED_EVENT_NAME, function (updatedParts) {
5988
6463
  if (!propagatingLocally) {
5989
6464
  var event_1;
5990
6465
  event_1 = new CustomEvent(STORAGE_MUTATED_DOM_EVENT_NAME, {
5991
- detail: updatedParts
6466
+ detail: updatedParts,
5992
6467
  });
5993
6468
  propagatingLocally = true;
5994
6469
  dispatchEvent(event_1);