dexie 3.2.0-beta.1 → 3.2.0-rc.3

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 3.2.0-beta.1, Sun Jun 27 2021
7
+ * Version 3.2.0-rc.3, Thu Oct 28 2021
8
8
  *
9
9
  * http://dexie.org
10
10
  *
@@ -15,7 +15,7 @@
15
15
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
16
16
  typeof define === 'function' && define.amd ? define(factory) :
17
17
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Dexie = factory());
18
- }(this, (function () { 'use strict';
18
+ })(this, (function () { 'use strict';
19
19
 
20
20
  /*! *****************************************************************************
21
21
  Copyright (c) Microsoft Corporation.
@@ -39,10 +39,14 @@
39
39
  };
40
40
  return __assign.apply(this, arguments);
41
41
  };
42
- function __spreadArray(to, from) {
43
- for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
44
- to[j] = from[i];
45
- return to;
42
+ function __spreadArray(to, from, pack) {
43
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
44
+ if (ar || !(i in from)) {
45
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
46
+ ar[i] = from[i];
47
+ }
48
+ }
49
+ return to.concat(ar || Array.prototype.slice.call(from));
46
50
  }
47
51
 
48
52
  var _global = typeof globalThis !== 'undefined' ? globalThis :
@@ -1247,7 +1251,10 @@
1247
1251
  var rejection = DexiePromise.reject;
1248
1252
 
1249
1253
  function tempTransaction(db, mode, storeNames, fn) {
1250
- if (!db._state.openComplete && (!PSD.letThrough)) {
1254
+ if (!db.idbdb || (!db._state.openComplete && (!PSD.letThrough && !db._vip))) {
1255
+ if (db._state.openComplete) {
1256
+ return rejection(new exceptions.DatabaseClosed(db._state.dbOpenError));
1257
+ }
1251
1258
  if (!db._state.isBeingOpened) {
1252
1259
  if (!db._options.autoOpen)
1253
1260
  return rejection(new exceptions.DatabaseClosed());
@@ -1274,7 +1281,7 @@
1274
1281
  }
1275
1282
  }
1276
1283
 
1277
- var DEXIE_VERSION = '3.2.0-beta.1';
1284
+ var DEXIE_VERSION = '3.2.0-rc.3';
1278
1285
  var maxString = String.fromCharCode(65535);
1279
1286
  var minKey = -Infinity;
1280
1287
  var INVALID_KEY_ARGUMENT = "Invalid key provided. Keys must be of type string, number, Date or Array<string | number | Date>.";
@@ -1296,37 +1303,11 @@
1296
1303
  filter2;
1297
1304
  }
1298
1305
 
1299
- var domDeps;
1300
- try {
1301
- domDeps = {
1302
- indexedDB: _global.indexedDB || _global.mozIndexedDB || _global.webkitIndexedDB || _global.msIndexedDB,
1303
- IDBKeyRange: _global.IDBKeyRange || _global.webkitIDBKeyRange
1304
- };
1305
- }
1306
- catch (e) {
1307
- domDeps = { indexedDB: null, IDBKeyRange: null };
1308
- }
1309
-
1310
- function safariMultiStoreFix(storeNames) {
1311
- return storeNames.length === 1 ? storeNames[0] : storeNames;
1312
- }
1313
- var getMaxKey = function (IdbKeyRange) {
1314
- try {
1315
- IdbKeyRange.only([[]]);
1316
- getMaxKey = function () { return [[]]; };
1317
- return [[]];
1318
- }
1319
- catch (e) {
1320
- getMaxKey = function () { return maxString; };
1321
- return maxString;
1322
- }
1323
- };
1324
-
1325
1306
  var AnyRange = {
1326
1307
  type: 3 ,
1327
1308
  lower: -Infinity,
1328
1309
  lowerOpen: false,
1329
- get upper() { return getMaxKey(domDeps.IDBKeyRange); },
1310
+ upper: [[]],
1330
1311
  upperOpen: false
1331
1312
  };
1332
1313
 
@@ -1794,6 +1775,82 @@
1794
1775
  });
1795
1776
  }
1796
1777
 
1778
+ function cmp(a, b) {
1779
+ try {
1780
+ var ta = type(a);
1781
+ var tb = type(b);
1782
+ if (ta !== tb) {
1783
+ if (ta === 'Array')
1784
+ return 1;
1785
+ if (tb === 'Array')
1786
+ return -1;
1787
+ if (ta === 'binary')
1788
+ return 1;
1789
+ if (tb === 'binary')
1790
+ return -1;
1791
+ if (ta === 'string')
1792
+ return 1;
1793
+ if (tb === 'string')
1794
+ return -1;
1795
+ if (ta === 'Date')
1796
+ return 1;
1797
+ if (tb !== 'Date')
1798
+ return NaN;
1799
+ return -1;
1800
+ }
1801
+ switch (ta) {
1802
+ case 'number':
1803
+ case 'Date':
1804
+ case 'string':
1805
+ return a > b ? 1 : a < b ? -1 : 0;
1806
+ case 'binary': {
1807
+ return compareUint8Arrays(getUint8Array(a), getUint8Array(b));
1808
+ }
1809
+ case 'Array':
1810
+ return compareArrays(a, b);
1811
+ }
1812
+ }
1813
+ catch (_a) { }
1814
+ return NaN;
1815
+ }
1816
+ function compareArrays(a, b) {
1817
+ var al = a.length;
1818
+ var bl = b.length;
1819
+ var l = al < bl ? al : bl;
1820
+ for (var i = 0; i < l; ++i) {
1821
+ var res = cmp(a[i], b[i]);
1822
+ if (res !== 0)
1823
+ return res;
1824
+ }
1825
+ return al === bl ? 0 : al < bl ? -1 : 1;
1826
+ }
1827
+ function compareUint8Arrays(a, b) {
1828
+ var al = a.length;
1829
+ var bl = b.length;
1830
+ var l = al < bl ? al : bl;
1831
+ for (var i = 0; i < l; ++i) {
1832
+ if (a[i] !== b[i])
1833
+ return a[i] < b[i] ? -1 : 1;
1834
+ }
1835
+ return al === bl ? 0 : al < bl ? -1 : 1;
1836
+ }
1837
+ function type(x) {
1838
+ var t = typeof x;
1839
+ if (t !== 'object')
1840
+ return t;
1841
+ if (ArrayBuffer.isView(x))
1842
+ return 'binary';
1843
+ var tsTag = toStringTag(x);
1844
+ return tsTag === 'ArrayBuffer' ? 'binary' : tsTag;
1845
+ }
1846
+ function getUint8Array(a) {
1847
+ if (a instanceof Uint8Array)
1848
+ return a;
1849
+ if (ArrayBuffer.isView(a))
1850
+ return new Uint8Array(a.buffer, a.byteOffset, a.byteLength);
1851
+ return new Uint8Array(a);
1852
+ }
1853
+
1797
1854
  var Collection = (function () {
1798
1855
  function Collection() {
1799
1856
  }
@@ -2077,7 +2134,6 @@
2077
2134
  var coreTable = ctx.table.core;
2078
2135
  var _a = coreTable.schema.primaryKey, outbound = _a.outbound, extractKey = _a.extractKey;
2079
2136
  var limit = _this.db._options.modifyChunkSize || 200;
2080
- var cmp = _this.db.core.cmp;
2081
2137
  var totalFailures = [];
2082
2138
  var successCount = 0;
2083
2139
  var failedKeys = [];
@@ -2609,7 +2665,9 @@
2609
2665
  event.preventDefault();
2610
2666
  }
2611
2667
 
2612
- var globalEvents = Events(null, "txcommitted");
2668
+ var DEXIE_STORAGE_MUTATED_EVENT_NAME = 'storagemutated';
2669
+ var STORAGE_MUTATED_DOM_EVENT_NAME = 'x-storagemutated-1';
2670
+ var globalEvents = Events(null, DEXIE_STORAGE_MUTATED_EVENT_NAME);
2613
2671
 
2614
2672
  var Transaction = (function () {
2615
2673
  function Transaction() {
@@ -2661,8 +2719,8 @@
2661
2719
  assert(this._completion._state === null);
2662
2720
  idbtrans = this.idbtrans = idbtrans ||
2663
2721
  (this.db.core
2664
- ? this.db.core.transaction(this.storeNames, this.mode)
2665
- : idbdb.transaction(this.storeNames, this.mode));
2722
+ ? this.db.core.transaction(this.storeNames, this.mode, { durability: this.chromeTransactionDurability })
2723
+ : idbdb.transaction(this.storeNames, this.mode, { durability: this.chromeTransactionDurability }));
2666
2724
  idbtrans.onerror = wrap(function (ev) {
2667
2725
  preventDefault(ev);
2668
2726
  _this._reject(idbtrans.error);
@@ -2677,7 +2735,7 @@
2677
2735
  _this.active = false;
2678
2736
  _this._resolve();
2679
2737
  if ('mutatedParts' in idbtrans) {
2680
- globalEvents.txcommitted.fire(idbtrans["mutatedParts"]);
2738
+ globalEvents.storagemutated.fire(idbtrans["mutatedParts"]);
2681
2739
  }
2682
2740
  });
2683
2741
  return this;
@@ -2773,12 +2831,13 @@
2773
2831
  }());
2774
2832
 
2775
2833
  function createTransactionConstructor(db) {
2776
- return makeClassConstructor(Transaction.prototype, function Transaction(mode, storeNames, dbschema, parent) {
2834
+ return makeClassConstructor(Transaction.prototype, function Transaction(mode, storeNames, dbschema, chromeTransactionDurability, parent) {
2777
2835
  var _this = this;
2778
2836
  this.db = db;
2779
2837
  this.mode = mode;
2780
2838
  this.storeNames = storeNames;
2781
2839
  this.schema = dbschema;
2840
+ this.chromeTransactionDurability = chromeTransactionDurability;
2782
2841
  this.idbtrans = null;
2783
2842
  this.on = Events(this, "complete", "error", "abort");
2784
2843
  this.parent = parent || null;
@@ -2836,6 +2895,21 @@
2836
2895
  };
2837
2896
  }
2838
2897
 
2898
+ function safariMultiStoreFix(storeNames) {
2899
+ return storeNames.length === 1 ? storeNames[0] : storeNames;
2900
+ }
2901
+ var getMaxKey = function (IdbKeyRange) {
2902
+ try {
2903
+ IdbKeyRange.only([[]]);
2904
+ getMaxKey = function () { return [[]]; };
2905
+ return [[]];
2906
+ }
2907
+ catch (e) {
2908
+ getMaxKey = function () { return maxString; };
2909
+ return maxString;
2910
+ }
2911
+ };
2912
+
2839
2913
  function getKeyExtractor(keyPath) {
2840
2914
  if (keyPath == null) {
2841
2915
  return function () { return undefined; };
@@ -2868,8 +2942,7 @@
2868
2942
  keyPath :
2869
2943
  "[" + keyPath.join('+') + "]";
2870
2944
  }
2871
- function createDBCore(db, indexedDB, IdbKeyRange, tmpTrans) {
2872
- var cmp = indexedDB.cmp.bind(indexedDB);
2945
+ function createDBCore(db, IdbKeyRange, tmpTrans) {
2873
2946
  function extractSchema(db, trans) {
2874
2947
  var tables = arrayify(db.objectStoreNames);
2875
2948
  return {
@@ -3204,7 +3277,6 @@
3204
3277
  throw new Error("Table '" + name + "' not found");
3205
3278
  return tableMap[name];
3206
3279
  },
3207
- cmp: cmp,
3208
3280
  MIN_KEY: -Infinity,
3209
3281
  MAX_KEY: getMaxKey(IdbKeyRange),
3210
3282
  schema: schema
@@ -3218,13 +3290,14 @@
3218
3290
  }, stackImpl);
3219
3291
  }
3220
3292
  function createMiddlewareStacks(middlewares, idbdb, _a, tmpTrans) {
3221
- var IDBKeyRange = _a.IDBKeyRange, indexedDB = _a.indexedDB;
3222
- var dbcore = createMiddlewareStack(createDBCore(idbdb, indexedDB, IDBKeyRange, tmpTrans), middlewares.dbcore);
3293
+ var IDBKeyRange = _a.IDBKeyRange; _a.indexedDB;
3294
+ var dbcore = createMiddlewareStack(createDBCore(idbdb, IDBKeyRange, tmpTrans), middlewares.dbcore);
3223
3295
  return {
3224
3296
  dbcore: dbcore
3225
3297
  };
3226
3298
  }
3227
- function generateMiddlewareStacks(db, tmpTrans) {
3299
+ function generateMiddlewareStacks(_a, tmpTrans) {
3300
+ var db = _a._novip;
3228
3301
  var idbdb = tmpTrans.db;
3229
3302
  var stacks = createMiddlewareStacks(db._middlewares, idbdb, db._deps, tmpTrans);
3230
3303
  db.core = stacks.dbcore;
@@ -3239,7 +3312,8 @@
3239
3312
  });
3240
3313
  }
3241
3314
 
3242
- function setApiOnPlace(db, objs, tableNames, dbschema) {
3315
+ function setApiOnPlace(_a, objs, tableNames, dbschema) {
3316
+ var db = _a._novip;
3243
3317
  tableNames.forEach(function (tableName) {
3244
3318
  var schema = dbschema[tableName];
3245
3319
  objs.forEach(function (obj) {
@@ -3260,7 +3334,8 @@
3260
3334
  });
3261
3335
  });
3262
3336
  }
3263
- function removeTablesApi(db, objs) {
3337
+ function removeTablesApi(_a, objs) {
3338
+ var db = _a._novip;
3264
3339
  objs.forEach(function (obj) {
3265
3340
  for (var key in obj) {
3266
3341
  if (obj[key] instanceof db.Table)
@@ -3292,7 +3367,8 @@
3292
3367
  updateTablesAndIndexes(db, oldVersion, trans, idbUpgradeTrans).catch(rejectTransaction);
3293
3368
  });
3294
3369
  }
3295
- function updateTablesAndIndexes(db, oldVersion, trans, idbUpgradeTrans) {
3370
+ function updateTablesAndIndexes(_a, oldVersion, trans, idbUpgradeTrans) {
3371
+ var db = _a._novip;
3296
3372
  var queue = [];
3297
3373
  var versions = db._versions;
3298
3374
  var globalSchema = db._dbSchema = buildGlobalSchema(db, db.idbdb, idbUpgradeTrans);
@@ -3441,12 +3517,9 @@
3441
3517
  });
3442
3518
  }
3443
3519
  function deleteRemovedTables(newSchema, idbtrans) {
3444
- for (var i = 0; i < idbtrans.db.objectStoreNames.length; ++i) {
3445
- var storeName = idbtrans.db.objectStoreNames[i];
3446
- if (newSchema[storeName] == null) {
3447
- idbtrans.db.deleteObjectStore(storeName);
3448
- }
3449
- }
3520
+ [].slice.call(idbtrans.db.objectStoreNames).forEach(function (storeName) {
3521
+ return newSchema[storeName] == null && idbtrans.db.deleteObjectStore(storeName);
3522
+ });
3450
3523
  }
3451
3524
  function addIndex(store, idx) {
3452
3525
  store.createIndex(idx.name, idx.keyPath, { unique: idx.unique, multiEntry: idx.multi });
@@ -3469,7 +3542,8 @@
3469
3542
  });
3470
3543
  return globalSchema;
3471
3544
  }
3472
- function readGlobalSchema(db, idbdb, tmpTrans) {
3545
+ function readGlobalSchema(_a, idbdb, tmpTrans) {
3546
+ var db = _a._novip;
3473
3547
  db.verno = idbdb.version / 10;
3474
3548
  var globalSchema = db._dbSchema = buildGlobalSchema(db, idbdb, tmpTrans);
3475
3549
  db._storeNames = slice(idbdb.objectStoreNames, 0);
@@ -3480,7 +3554,8 @@
3480
3554
  var diff = getSchemaDiff(installedSchema, db._dbSchema);
3481
3555
  return !(diff.add.length || diff.change.some(function (ch) { return ch.add.length || ch.change.length; }));
3482
3556
  }
3483
- function adjustToExistingIndexNames(db, schema, idbtrans) {
3557
+ function adjustToExistingIndexNames(_a, schema, idbtrans) {
3558
+ var db = _a._novip;
3484
3559
  var storeNames = idbtrans.db.objectStoreNames;
3485
3560
  for (var i = 0; i < storeNames.length; ++i) {
3486
3561
  var storeName = storeNames[i];
@@ -3620,6 +3695,20 @@
3620
3695
  });
3621
3696
  }
3622
3697
 
3698
+ function idbReady() {
3699
+ var isSafari = !navigator.userAgentData &&
3700
+ /Safari\//.test(navigator.userAgent) &&
3701
+ !/Chrom(e|ium)\//.test(navigator.userAgent);
3702
+ if (!isSafari || !indexedDB.databases)
3703
+ return Promise.resolve();
3704
+ var intervalId;
3705
+ return new Promise(function (resolve) {
3706
+ var tryIdb = function () { return indexedDB.databases().finally(resolve); };
3707
+ intervalId = setInterval(tryIdb, 100);
3708
+ tryIdb();
3709
+ }).finally(function () { return clearInterval(intervalId); });
3710
+ }
3711
+
3623
3712
  function dexieOpen(db) {
3624
3713
  var state = db._state;
3625
3714
  var indexedDB = db._deps.indexedDB;
@@ -3631,9 +3720,15 @@
3631
3720
  state.isBeingOpened = true;
3632
3721
  state.dbOpenError = null;
3633
3722
  state.openComplete = false;
3723
+ var openCanceller = state.openCanceller;
3724
+ function throwIfCancelled() {
3725
+ if (state.openCanceller !== openCanceller)
3726
+ throw new exceptions.DatabaseClosed('db.open() was cancelled');
3727
+ }
3634
3728
  var resolveDbReady = state.dbReadyResolve,
3635
3729
  upgradeTransaction = null, wasCreated = false;
3636
- return DexiePromise.race([state.openCanceller, new DexiePromise(function (resolve, reject) {
3730
+ return DexiePromise.race([openCanceller, (typeof navigator === 'undefined' ? DexiePromise.resolve() : idbReady()).then(function () { return new DexiePromise(function (resolve, reject) {
3731
+ throwIfCancelled();
3637
3732
  if (!indexedDB)
3638
3733
  throw new exceptions.MissingAPI();
3639
3734
  var dbName = db.name;
@@ -3659,13 +3754,13 @@
3659
3754
  upgradeTransaction.onerror = eventRejectHandler(reject);
3660
3755
  var oldVer = e.oldVersion > Math.pow(2, 62) ? 0 : e.oldVersion;
3661
3756
  wasCreated = oldVer < 1;
3662
- db.idbdb = req.result;
3757
+ db._novip.idbdb = req.result;
3663
3758
  runUpgraders(db, oldVer / 10, upgradeTransaction, reject);
3664
3759
  }
3665
3760
  }, reject);
3666
3761
  req.onsuccess = wrap(function () {
3667
3762
  upgradeTransaction = null;
3668
- var idbdb = db.idbdb = req.result;
3763
+ var idbdb = db._novip.idbdb = req.result;
3669
3764
  var objectStoreNames = slice(idbdb.objectStoreNames);
3670
3765
  if (objectStoreNames.length > 0)
3671
3766
  try {
@@ -3694,32 +3789,31 @@
3694
3789
  _onDatabaseCreated(db._deps, dbName);
3695
3790
  resolve();
3696
3791
  }, reject);
3697
- })]).then(function () {
3792
+ }); })]).then(function () {
3793
+ throwIfCancelled();
3698
3794
  state.onReadyBeingFired = [];
3699
- var vipedDb = Object.create(db);
3700
- vipedDb._state = Object.create(db._state);
3701
- vipedDb._state.openComplete = true;
3702
- return DexiePromise.resolve(vip(function () { return db.on.ready.fire(vipedDb); })).then(function fireRemainders() {
3795
+ return DexiePromise.resolve(vip(function () { return db.on.ready.fire(db.vip); })).then(function fireRemainders() {
3703
3796
  if (state.onReadyBeingFired.length > 0) {
3704
- var remainders = state.onReadyBeingFired.reduce(promisableChain, nop);
3797
+ var remainders_1 = state.onReadyBeingFired.reduce(promisableChain, nop);
3705
3798
  state.onReadyBeingFired = [];
3706
- return DexiePromise.resolve(vip(remainders)).then(fireRemainders);
3799
+ return DexiePromise.resolve(vip(function () { return remainders_1(db.vip); })).then(fireRemainders);
3707
3800
  }
3708
3801
  });
3709
3802
  }).finally(function () {
3710
3803
  state.onReadyBeingFired = null;
3711
- }).then(function () {
3712
3804
  state.isBeingOpened = false;
3805
+ }).then(function () {
3713
3806
  return db;
3714
3807
  }).catch(function (err) {
3808
+ state.dbOpenError = err;
3715
3809
  try {
3716
3810
  upgradeTransaction && upgradeTransaction.abort();
3717
3811
  }
3718
- catch (e) { }
3719
- state.isBeingOpened = false;
3720
- db.close();
3721
- state.dbOpenError = err;
3722
- return rejection(state.dbOpenError);
3812
+ catch (_a) { }
3813
+ if (openCanceller === state.openCanceller) {
3814
+ db._close();
3815
+ }
3816
+ return rejection(err);
3723
3817
  }).finally(function () {
3724
3818
  state.openComplete = true;
3725
3819
  resolveDbReady();
@@ -3814,9 +3908,7 @@
3814
3908
  var indexList = (indexLookup[keyPathAlias] = indexLookup[keyPathAlias] || []);
3815
3909
  var keyLength = keyPath == null ? 0 : typeof keyPath === 'string' ? 1 : keyPath.length;
3816
3910
  var isVirtual = keyTail > 0;
3817
- var virtualIndex = __assign(__assign({}, lowLevelIndex), { isVirtual: isVirtual,
3818
- keyTail: keyTail,
3819
- keyLength: keyLength, extractKey: getKeyExtractor(keyPath), unique: !isVirtual && lowLevelIndex.unique });
3911
+ var virtualIndex = __assign(__assign({}, lowLevelIndex), { isVirtual: isVirtual, keyTail: keyTail, keyLength: keyLength, extractKey: getKeyExtractor(keyPath), unique: !isVirtual && lowLevelIndex.unique });
3820
3912
  indexList.push(virtualIndex);
3821
3913
  if (!virtualIndex.isPrimaryKey) {
3822
3914
  allVirtualIndexes.push(virtualIndex);
@@ -3860,11 +3952,9 @@
3860
3952
  }
3861
3953
  var result = __assign(__assign({}, table), { schema: __assign(__assign({}, schema), { primaryKey: primaryKey, indexes: allVirtualIndexes, getIndexByKeyPath: findBestIndex }), count: function (req) {
3862
3954
  return table.count(translateRequest(req));
3863
- },
3864
- query: function (req) {
3955
+ }, query: function (req) {
3865
3956
  return table.query(translateRequest(req));
3866
- },
3867
- openCursor: function (req) {
3957
+ }, openCursor: function (req) {
3868
3958
  var _a = req.query.index, keyTail = _a.keyTail, isVirtual = _a.isVirtual, keyLength = _a.keyLength;
3869
3959
  if (!isVirtual)
3870
3960
  return table.openCursor(req);
@@ -3873,7 +3963,10 @@
3873
3963
  key != null ?
3874
3964
  cursor.continue(pad(key, req.reverse ? down.MAX_KEY : down.MIN_KEY, keyTail)) :
3875
3965
  req.unique ?
3876
- cursor.continue(pad(cursor.key, req.reverse ? down.MIN_KEY : down.MAX_KEY, keyTail)) :
3966
+ cursor.continue(cursor.key.slice(0, keyLength)
3967
+ .concat(req.reverse
3968
+ ? down.MIN_KEY
3969
+ : down.MAX_KEY, keyTail)) :
3877
3970
  cursor.continue();
3878
3971
  }
3879
3972
  var virtualCursor = Object.create(cursor, {
@@ -3883,6 +3976,11 @@
3883
3976
  cursor.continuePrimaryKey(pad(key, down.MAX_KEY, keyTail), primaryKey);
3884
3977
  }
3885
3978
  },
3979
+ primaryKey: {
3980
+ get: function () {
3981
+ return cursor.primaryKey;
3982
+ }
3983
+ },
3886
3984
  key: {
3887
3985
  get: function () {
3888
3986
  var key = cursor.key;
@@ -3988,9 +4086,9 @@
3988
4086
  throw new Error("Keys missing");
3989
4087
  req = req.type === 'add' || req.type === 'put' ? __assign(__assign({}, req), { keys: keys }) : __assign({}, req);
3990
4088
  if (req.type !== 'delete')
3991
- req.values = __spreadArray([], req.values);
4089
+ req.values = __spreadArray([], req.values, true);
3992
4090
  if (req.keys)
3993
- req.keys = __spreadArray([], req.keys);
4091
+ req.keys = __spreadArray([], req.keys, true);
3994
4092
  return getExistingValues(downTable, req, keys).then(function (existingValues) {
3995
4093
  var contexts = keys.map(function (key, i) {
3996
4094
  var existingValue = existingValues[i];
@@ -4076,24 +4174,6 @@
4076
4174
  : table.getMany({ trans: req.trans, keys: effectiveKeys, cache: "immutable" });
4077
4175
  }
4078
4176
 
4079
- var _cmp;
4080
- function cmp(a, b) {
4081
- if (_cmp)
4082
- return _cmp(a, b);
4083
- var indexedDB = domDeps.indexedDB;
4084
- if (!indexedDB)
4085
- throw new exceptions.MissingAPI();
4086
- _cmp = function (a, b) {
4087
- try {
4088
- return a == null || b == null ? NaN : indexedDB.cmp(a, b);
4089
- }
4090
- catch (_a) {
4091
- return NaN;
4092
- }
4093
- };
4094
- return _cmp(a, b);
4095
- }
4096
-
4097
4177
  function getFromTransactionCache(keys, cache, clone) {
4098
4178
  try {
4099
4179
  if (!cache)
@@ -4499,6 +4579,7 @@
4499
4579
  this._storeNames = [];
4500
4580
  this._allTables = {};
4501
4581
  this.idbdb = null;
4582
+ this._novip = this;
4502
4583
  var state = {
4503
4584
  dbOpenError: null,
4504
4585
  isBeingOpened: false,
@@ -4565,7 +4646,7 @@
4565
4646
  console.warn("Upgrade '" + _this.name + "' blocked by other connection holding version " + ev.oldVersion / 10);
4566
4647
  });
4567
4648
  this._maxKey = getMaxKey(options.IDBKeyRange);
4568
- this._createTransaction = function (mode, storeNames, dbschema, parentTransaction) { return new _this.Transaction(mode, storeNames, dbschema, parentTransaction); };
4649
+ this._createTransaction = function (mode, storeNames, dbschema, parentTransaction) { return new _this.Transaction(mode, storeNames, dbschema, _this._options.chromeTransactionDurability, parentTransaction); };
4569
4650
  this._fireOnBlocked = function (ev) {
4570
4651
  _this.on("blocked").fire(ev);
4571
4652
  connections
@@ -4576,6 +4657,7 @@
4576
4657
  this.use(hooksMiddleware);
4577
4658
  this.use(observabilityMiddleware);
4578
4659
  this.use(cacheExistingValuesMiddleware);
4660
+ this.vip = Object.create(this, { _vip: { value: true } });
4579
4661
  addons.forEach(function (addon) { return addon(_this); });
4580
4662
  }
4581
4663
  Dexie.prototype.version = function (versionNumber) {
@@ -4598,7 +4680,10 @@
4598
4680
  };
4599
4681
  Dexie.prototype._whenReady = function (fn) {
4600
4682
  var _this = this;
4601
- return this._state.openComplete || PSD.letThrough ? fn() : new DexiePromise(function (resolve, reject) {
4683
+ return (this.idbdb && (this._state.openComplete || PSD.letThrough || this._vip)) ? fn() : new DexiePromise(function (resolve, reject) {
4684
+ if (_this._state.openComplete) {
4685
+ return reject(new exceptions.DatabaseClosed(_this._state.dbOpenError));
4686
+ }
4602
4687
  if (!_this._state.isBeingOpened) {
4603
4688
  if (!_this._options.autoOpen) {
4604
4689
  reject(new exceptions.DatabaseClosed());
@@ -4632,8 +4717,9 @@
4632
4717
  Dexie.prototype.open = function () {
4633
4718
  return dexieOpen(this);
4634
4719
  };
4635
- Dexie.prototype.close = function () {
4636
- var idx = connections.indexOf(this), state = this._state;
4720
+ Dexie.prototype._close = function () {
4721
+ var state = this._state;
4722
+ var idx = connections.indexOf(this);
4637
4723
  if (idx >= 0)
4638
4724
  connections.splice(idx, 1);
4639
4725
  if (this.idbdb) {
@@ -4641,12 +4727,8 @@
4641
4727
  this.idbdb.close();
4642
4728
  }
4643
4729
  catch (e) { }
4644
- this.idbdb = null;
4730
+ this._novip.idbdb = null;
4645
4731
  }
4646
- this._options.autoOpen = false;
4647
- state.dbOpenError = new exceptions.DatabaseClosed();
4648
- if (state.isBeingOpened)
4649
- state.cancelOpen(state.dbOpenError);
4650
4732
  state.dbReadyPromise = new DexiePromise(function (resolve) {
4651
4733
  state.dbReadyResolve = resolve;
4652
4734
  });
@@ -4654,6 +4736,14 @@
4654
4736
  state.cancelOpen = reject;
4655
4737
  });
4656
4738
  };
4739
+ Dexie.prototype.close = function () {
4740
+ this._close();
4741
+ var state = this._state;
4742
+ this._options.autoOpen = false;
4743
+ state.dbOpenError = new exceptions.DatabaseClosed();
4744
+ if (state.isBeingOpened)
4745
+ state.cancelOpen(state.dbOpenError);
4746
+ };
4657
4747
  Dexie.prototype.delete = function () {
4658
4748
  var _this = this;
4659
4749
  var hasArguments = arguments.length > 0;
@@ -4775,7 +4865,7 @@
4775
4865
  }());
4776
4866
 
4777
4867
  var symbolObservable = typeof Symbol !== "undefined" && "observable" in Symbol
4778
- ? Symbol["observable"]
4868
+ ? Symbol.observable
4779
4869
  : "@@observable";
4780
4870
  var Observable = (function () {
4781
4871
  function Observable(subscribe) {
@@ -4824,7 +4914,7 @@
4824
4914
  },
4825
4915
  unsubscribe: function () {
4826
4916
  closed = true;
4827
- globalEvents.txcommitted.unsubscribe(mutationListener);
4917
+ globalEvents.storagemutated.unsubscribe(mutationListener);
4828
4918
  },
4829
4919
  };
4830
4920
  observer.start && observer.start(subscription);
@@ -4847,7 +4937,7 @@
4847
4937
  var subscr = {};
4848
4938
  var ret = execute(subscr);
4849
4939
  if (!startedListening) {
4850
- globalEvents("txcommitted", mutationListener);
4940
+ globalEvents(DEXIE_STORAGE_MUTATED_EVENT_NAME, mutationListener);
4851
4941
  startedListening = true;
4852
4942
  }
4853
4943
  querying = true;
@@ -4874,6 +4964,17 @@
4874
4964
  });
4875
4965
  }
4876
4966
 
4967
+ var domDeps;
4968
+ try {
4969
+ domDeps = {
4970
+ indexedDB: _global.indexedDB || _global.mozIndexedDB || _global.webkitIndexedDB || _global.msIndexedDB,
4971
+ IDBKeyRange: _global.IDBKeyRange || _global.webkitIDBKeyRange
4972
+ };
4973
+ }
4974
+ catch (e) {
4975
+ domDeps = { indexedDB: null, IDBKeyRange: null };
4976
+ }
4977
+
4877
4978
  var Dexie = Dexie$1;
4878
4979
  props(Dexie, __assign(__assign({}, fullNameExceptions), {
4879
4980
  delete: function (databaseName) {
@@ -4899,13 +5000,11 @@
4899
5000
  extend(this, content);
4900
5001
  }
4901
5002
  return Class;
4902
- },
4903
- ignoreTransaction: function (scopeFunc) {
5003
+ }, ignoreTransaction: function (scopeFunc) {
4904
5004
  return PSD.trans ?
4905
5005
  usePSD(PSD.transless, scopeFunc) :
4906
5006
  scopeFunc();
4907
- },
4908
- vip: vip, async: function (generatorFn) {
5007
+ }, vip: vip, async: function (generatorFn) {
4909
5008
  return function () {
4910
5009
  try {
4911
5010
  var rv = awaitIterator(generatorFn.apply(this, arguments));
@@ -4947,9 +5046,8 @@
4947
5046
  }
4948
5047
  },
4949
5048
  derive: derive, extend: extend, props: props, override: override,
4950
- Events: Events, on: globalEvents, liveQuery: liveQuery,
4951
- extendObservabilitySet: extendObservabilitySet,
4952
- getByKeyPath: getByKeyPath, setByKeyPath: setByKeyPath, delByKeyPath: delByKeyPath, shallowClone: shallowClone, deepClone: deepClone, getObjectDiff: getObjectDiff, asap: asap$1,
5049
+ Events: Events, on: globalEvents, liveQuery: liveQuery, extendObservabilitySet: extendObservabilitySet,
5050
+ getByKeyPath: getByKeyPath, setByKeyPath: setByKeyPath, delByKeyPath: delByKeyPath, shallowClone: shallowClone, deepClone: deepClone, getObjectDiff: getObjectDiff, cmp: cmp, asap: asap$1,
4953
5051
  minKey: minKey,
4954
5052
  addons: [],
4955
5053
  connections: connections,
@@ -4960,38 +5058,46 @@
4960
5058
  .reduce(function (p, c, i) { return p + (c / Math.pow(10, i * 2)); }) }));
4961
5059
  Dexie.maxKey = getMaxKey(Dexie.dependencies.IDBKeyRange);
4962
5060
 
4963
- function fireLocally(updateParts) {
5061
+ if (typeof dispatchEvent !== 'undefined' && typeof addEventListener !== 'undefined') {
5062
+ globalEvents(DEXIE_STORAGE_MUTATED_EVENT_NAME, function (updatedParts) {
5063
+ if (!propagatingLocally) {
5064
+ var event_1;
5065
+ if (isIEOrEdge) {
5066
+ event_1 = document.createEvent('CustomEvent');
5067
+ event_1.initCustomEvent(STORAGE_MUTATED_DOM_EVENT_NAME, true, true, updatedParts);
5068
+ }
5069
+ else {
5070
+ event_1 = new CustomEvent(STORAGE_MUTATED_DOM_EVENT_NAME, {
5071
+ detail: updatedParts
5072
+ });
5073
+ }
5074
+ propagatingLocally = true;
5075
+ dispatchEvent(event_1);
5076
+ propagatingLocally = false;
5077
+ }
5078
+ });
5079
+ addEventListener(STORAGE_MUTATED_DOM_EVENT_NAME, function (_a) {
5080
+ var detail = _a.detail;
5081
+ if (!propagatingLocally) {
5082
+ propagateLocally(detail);
5083
+ }
5084
+ });
5085
+ }
5086
+ function propagateLocally(updateParts) {
4964
5087
  var wasMe = propagatingLocally;
4965
5088
  try {
4966
5089
  propagatingLocally = true;
4967
- globalEvents.txcommitted.fire(updateParts);
5090
+ globalEvents.storagemutated.fire(updateParts);
4968
5091
  }
4969
5092
  finally {
4970
5093
  propagatingLocally = wasMe;
4971
5094
  }
4972
5095
  }
4973
- var propagateLocally = fireLocally;
4974
5096
  var propagatingLocally = false;
4975
- var accumulatedParts = {};
4976
- if (typeof document !== 'undefined' && document.addEventListener) {
4977
- var fireIfVisible_1 = function () {
4978
- if (document.visibilityState === "visible") {
4979
- if (Object.keys(accumulatedParts).length > 0) {
4980
- fireLocally(accumulatedParts);
4981
- }
4982
- accumulatedParts = {};
4983
- }
4984
- };
4985
- document.addEventListener("visibilitychange", fireIfVisible_1);
4986
- propagateLocally = function (changedParts) {
4987
- extendObservabilitySet(accumulatedParts, changedParts);
4988
- fireIfVisible_1();
4989
- };
4990
- }
4991
5097
 
4992
- if (typeof BroadcastChannel !== "undefined") {
4993
- var bc_1 = new BroadcastChannel("dexie-txcommitted");
4994
- globalEvents("txcommitted", function (changedParts) {
5098
+ if (typeof BroadcastChannel !== 'undefined') {
5099
+ var bc_1 = new BroadcastChannel(STORAGE_MUTATED_DOM_EVENT_NAME);
5100
+ globalEvents(DEXIE_STORAGE_MUTATED_EVENT_NAME, function (changedParts) {
4995
5101
  if (!propagatingLocally) {
4996
5102
  bc_1.postMessage(changedParts);
4997
5103
  }
@@ -5001,20 +5107,20 @@
5001
5107
  propagateLocally(ev.data);
5002
5108
  };
5003
5109
  }
5004
- else if (typeof self !== "undefined" && typeof navigator !== "undefined") {
5005
- globalEvents("txcommitted", function (changedParts) {
5110
+ else if (typeof self !== 'undefined' && typeof navigator !== 'undefined') {
5111
+ globalEvents(DEXIE_STORAGE_MUTATED_EVENT_NAME, function (changedParts) {
5006
5112
  try {
5007
5113
  if (!propagatingLocally) {
5008
- if (typeof localStorage !== "undefined") {
5009
- localStorage.setItem("dexie-txcommitted", JSON.stringify({
5114
+ if (typeof localStorage !== 'undefined') {
5115
+ localStorage.setItem(STORAGE_MUTATED_DOM_EVENT_NAME, JSON.stringify({
5010
5116
  trig: Math.random(),
5011
5117
  changedParts: changedParts,
5012
5118
  }));
5013
5119
  }
5014
- if (typeof self["clients"] === "object") {
5015
- __spreadArray([], self["clients"].matchAll({ includeUncontrolled: true })).forEach(function (client) {
5120
+ if (typeof self['clients'] === 'object') {
5121
+ __spreadArray([], self['clients'].matchAll({ includeUncontrolled: true }), true).forEach(function (client) {
5016
5122
  return client.postMessage({
5017
- type: "dexie-txcommitted",
5123
+ type: STORAGE_MUTATED_DOM_EVENT_NAME,
5018
5124
  changedParts: changedParts,
5019
5125
  });
5020
5126
  });
@@ -5023,8 +5129,8 @@
5023
5129
  }
5024
5130
  catch (_a) { }
5025
5131
  });
5026
- addEventListener("storage", function (ev) {
5027
- if (ev.key === "dexie-txcommitted") {
5132
+ addEventListener('storage', function (ev) {
5133
+ if (ev.key === STORAGE_MUTATED_DOM_EVENT_NAME) {
5028
5134
  var data = JSON.parse(ev.newValue);
5029
5135
  if (data)
5030
5136
  propagateLocally(data.changedParts);
@@ -5037,7 +5143,7 @@
5037
5143
  }
5038
5144
  function propagateMessageLocally(_a) {
5039
5145
  var data = _a.data;
5040
- if (data && data.type === "dexie-txcommitted") {
5146
+ if (data && data.type === STORAGE_MUTATED_DOM_EVENT_NAME) {
5041
5147
  propagateLocally(data.changedParts);
5042
5148
  }
5043
5149
  }
@@ -5059,5 +5165,5 @@
5059
5165
 
5060
5166
  return Dexie$1;
5061
5167
 
5062
- })));
5168
+ }));
5063
5169
  //# sourceMappingURL=dexie.js.map