dexie 4.0.1-beta.9 → 4.0.1

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.mjs CHANGED
@@ -4,7 +4,7 @@
4
4
  *
5
5
  * By David Fahlander, david.fahlander@gmail.com
6
6
  *
7
- * Version 4.0.1-beta.9, Thu Feb 08 2024
7
+ * Version 4.0.1, Tue Mar 26 2024
8
8
  *
9
9
  * https://dexie.org
10
10
  *
@@ -150,7 +150,7 @@ function getByKeyPath(obj, keyPath) {
150
150
  var period = keyPath.indexOf('.');
151
151
  if (period !== -1) {
152
152
  var innerObj = obj[keyPath.substr(0, period)];
153
- return innerObj === undefined ? undefined : getByKeyPath(innerObj, keyPath.substr(period + 1));
153
+ return innerObj == null ? undefined : getByKeyPath(innerObj, keyPath.substr(period + 1));
154
154
  }
155
155
  return undefined;
156
156
  }
@@ -1123,7 +1123,7 @@ function tempTransaction(db, mode, storeNames, fn) {
1123
1123
  catch (ex) {
1124
1124
  if (ex.name === errnames.InvalidState && db.isOpen() && --db._state.PR1398_maxLoop > 0) {
1125
1125
  console.warn('Dexie: Need to reopen db');
1126
- db._close();
1126
+ db.close({ disableAutoOpen: false });
1127
1127
  return db.open().then(function () { return tempTransaction(db, mode, storeNames, fn); });
1128
1128
  }
1129
1129
  return rejection(ex);
@@ -1144,15 +1144,12 @@ function tempTransaction(db, mode, storeNames, fn) {
1144
1144
  }
1145
1145
  }
1146
1146
 
1147
- var DEXIE_VERSION = '4.0.1-beta.9';
1147
+ var DEXIE_VERSION = '4.0.1';
1148
1148
  var maxString = String.fromCharCode(65535);
1149
1149
  var minKey = -Infinity;
1150
1150
  var INVALID_KEY_ARGUMENT = "Invalid key provided. Keys must be of type string, number, Date or Array<string | number | Date>.";
1151
1151
  var STRING_EXPECTED = "String expected.";
1152
1152
  var connections = [];
1153
- var isIEOrEdge = typeof navigator !== 'undefined' && /(MSIE|Trident|Edge)/.test(navigator.userAgent);
1154
- var hasIEDeleteObjectStoreBug = isIEOrEdge;
1155
- var hangsOnDeleteLargeKeyRange = isIEOrEdge;
1156
1153
  var DBNAMES_DB = '__dbnames';
1157
1154
  var READONLY = 'readonly';
1158
1155
  var READWRITE = 'readwrite';
@@ -1800,6 +1797,22 @@ function iterate(cursorPromise, filter, fn, valueMapper) {
1800
1797
  });
1801
1798
  }
1802
1799
 
1800
+ var PropModSymbol = Symbol();
1801
+ var PropModification = (function () {
1802
+ function PropModification(spec) {
1803
+ Object.assign(this, spec);
1804
+ }
1805
+ PropModification.prototype.execute = function (value) {
1806
+ var _a;
1807
+ var prefixToReplace = (_a = this.replacePrefix) === null || _a === void 0 ? void 0 : _a[0];
1808
+ if (prefixToReplace && typeof value === 'string' && value.startsWith(prefixToReplace)) {
1809
+ return this.replacePrefix[1] + value.substring(prefixToReplace.length);
1810
+ }
1811
+ return value;
1812
+ };
1813
+ return PropModification;
1814
+ }());
1815
+
1803
1816
  var Collection = (function () {
1804
1817
  function Collection() {
1805
1818
  }
@@ -2071,8 +2084,14 @@ var Collection = (function () {
2071
2084
  modifyer = function (item) {
2072
2085
  var anythingModified = false;
2073
2086
  for (var i = 0; i < numKeys; ++i) {
2074
- var keyPath = keyPaths[i], val = changes[keyPath];
2075
- if (getByKeyPath(item, keyPath) !== val) {
2087
+ var keyPath = keyPaths[i];
2088
+ var val = changes[keyPath];
2089
+ var origVal = getByKeyPath(item, keyPath);
2090
+ if (val instanceof PropModification) {
2091
+ setByKeyPath(item, keyPath, val.execute(origVal));
2092
+ anythingModified = true;
2093
+ }
2094
+ else if (origVal !== val) {
2076
2095
  setByKeyPath(item, keyPath, val);
2077
2096
  anythingModified = true;
2078
2097
  }
@@ -2171,7 +2190,7 @@ var Collection = (function () {
2171
2190
  Collection.prototype.delete = function () {
2172
2191
  var ctx = this._ctx, range = ctx.range;
2173
2192
  if (isPlainKeyRange(ctx) &&
2174
- ((ctx.isPrimKey && !hangsOnDeleteLargeKeyRange) || range.type === 3 ))
2193
+ (ctx.isPrimKey || range.type === 3 ))
2175
2194
  {
2176
2195
  return this._write(function (trans) {
2177
2196
  var primaryKey = ctx.table.core.schema.primaryKey;
@@ -3361,7 +3380,6 @@ function updateTablesAndIndexes(db, oldVersion, trans, idbUpgradeTrans) {
3361
3380
  var queue = [];
3362
3381
  var versions = db._versions;
3363
3382
  var globalSchema = db._dbSchema = buildGlobalSchema(db, db.idbdb, idbUpgradeTrans);
3364
- var anyContentUpgraderHasRun = false;
3365
3383
  var versToRun = versions.filter(function (v) { return v._cfg.version >= oldVersion; });
3366
3384
  if (versToRun.length === 0) {
3367
3385
  return DexiePromise.resolve();
@@ -3395,7 +3413,6 @@ function updateTablesAndIndexes(db, oldVersion, trans, idbUpgradeTrans) {
3395
3413
  if (contentUpgrade && version._cfg.version > oldVersion) {
3396
3414
  generateMiddlewareStacks(db, idbUpgradeTrans);
3397
3415
  trans._memoizedTables = {};
3398
- anyContentUpgraderHasRun = true;
3399
3416
  var upgradeSchema_1 = shallowClone(newSchema);
3400
3417
  diff.del.forEach(function (table) {
3401
3418
  upgradeSchema_1[table] = oldSchema[table];
@@ -3422,10 +3439,8 @@ function updateTablesAndIndexes(db, oldVersion, trans, idbUpgradeTrans) {
3422
3439
  }
3423
3440
  });
3424
3441
  queue.push(function (idbtrans) {
3425
- if (!anyContentUpgraderHasRun || !hasIEDeleteObjectStoreBug) {
3426
- var newSchema = version._cfg.dbschema;
3427
- deleteRemovedTables(newSchema, idbtrans);
3428
- }
3442
+ var newSchema = version._cfg.dbschema;
3443
+ deleteRemovedTables(newSchema, idbtrans);
3429
3444
  removeTablesApi(db, [db.Transaction.prototype]);
3430
3445
  setApiOnPlace(db, [db.Transaction.prototype], db._storeNames, db._dbSchema);
3431
3446
  trans.schema = db._dbSchema;
@@ -3478,8 +3493,7 @@ function getSchemaDiff(oldSchema, newSchema) {
3478
3493
  };
3479
3494
  if ((
3480
3495
  '' + (oldDef.primKey.keyPath || '')) !== ('' + (newDef.primKey.keyPath || '')) ||
3481
- (oldDef.primKey.auto !== newDef.primKey.auto && !isIEOrEdge))
3482
- {
3496
+ (oldDef.primKey.auto !== newDef.primKey.auto)) {
3483
3497
  change.recreate = true;
3484
3498
  diff.change.push(change);
3485
3499
  }
@@ -4153,7 +4167,7 @@ function enterTransactionScope(db, mode, storeNames, parentTransaction, scopeFun
4153
4167
  catch (ex) {
4154
4168
  if (ex.name === errnames.InvalidState && db.isOpen() && --db._state.PR1398_maxLoop > 0) {
4155
4169
  console.warn('Dexie: Need to reopen db');
4156
- db._close();
4170
+ db.close({ disableAutoOpen: false });
4157
4171
  return db.open().then(function () { return enterTransactionScope(db, mode, storeNames, null, scopeFunc); });
4158
4172
  }
4159
4173
  return rejection(ex);
@@ -5246,7 +5260,6 @@ var Dexie$1 = (function () {
5246
5260
  else
5247
5261
  console.warn("Another connection wants to delete database '".concat(_this.name, "'. Closing db now to resume the delete request."));
5248
5262
  _this.close({ disableAutoOpen: false });
5249
- _this._state.openComplete = false;
5250
5263
  });
5251
5264
  this.on("blocked", function (ev) {
5252
5265
  if (!ev.newVersion || ev.newVersion < ev.oldVersion)
@@ -5360,34 +5373,42 @@ var Dexie$1 = (function () {
5360
5373
  catch (e) { }
5361
5374
  this.idbdb = null;
5362
5375
  }
5363
- state.dbReadyPromise = new DexiePromise(function (resolve) {
5364
- state.dbReadyResolve = resolve;
5365
- });
5366
- state.openCanceller = new DexiePromise(function (_, reject) {
5367
- state.cancelOpen = reject;
5368
- });
5376
+ if (!state.isBeingOpened) {
5377
+ state.dbReadyPromise = new DexiePromise(function (resolve) {
5378
+ state.dbReadyResolve = resolve;
5379
+ });
5380
+ state.openCanceller = new DexiePromise(function (_, reject) {
5381
+ state.cancelOpen = reject;
5382
+ });
5383
+ }
5369
5384
  };
5370
5385
  Dexie.prototype.close = function (_a) {
5371
5386
  var _b = _a === void 0 ? { disableAutoOpen: true } : _a, disableAutoOpen = _b.disableAutoOpen;
5372
- var wasOpen = this.isOpen();
5373
- this._close();
5374
5387
  var state = this._state;
5375
- if (disableAutoOpen)
5376
- this._state.autoOpen = false;
5377
- else if (wasOpen && this._options.autoOpen) {
5378
- this._state.autoOpen = true;
5379
- }
5380
- state.dbOpenError = new exceptions.DatabaseClosed();
5381
- if (state.isBeingOpened)
5382
- state.cancelOpen(state.dbOpenError);
5388
+ if (disableAutoOpen) {
5389
+ if (state.isBeingOpened) {
5390
+ state.cancelOpen(new exceptions.DatabaseClosed());
5391
+ }
5392
+ this._close();
5393
+ state.autoOpen = false;
5394
+ state.dbOpenError = new exceptions.DatabaseClosed();
5395
+ }
5396
+ else {
5397
+ this._close();
5398
+ state.autoOpen = this._options.autoOpen ||
5399
+ state.isBeingOpened;
5400
+ state.openComplete = false;
5401
+ state.dbOpenError = null;
5402
+ }
5383
5403
  };
5384
- Dexie.prototype.delete = function () {
5404
+ Dexie.prototype.delete = function (closeOptions) {
5385
5405
  var _this = this;
5386
- var hasArguments = arguments.length > 0;
5406
+ if (closeOptions === void 0) { closeOptions = { disableAutoOpen: true }; }
5407
+ var hasInvalidArguments = arguments.length > 0 && typeof arguments[0] !== 'object';
5387
5408
  var state = this._state;
5388
5409
  return new DexiePromise(function (resolve, reject) {
5389
5410
  var doDelete = function () {
5390
- _this.close({ disableAutoOpen: false });
5411
+ _this.close(closeOptions);
5391
5412
  var req = _this._deps.indexedDB.deleteDatabase(_this.name);
5392
5413
  req.onsuccess = wrap(function () {
5393
5414
  _onDatabaseDeleted(_this._deps, _this.name);
@@ -5396,8 +5417,8 @@ var Dexie$1 = (function () {
5396
5417
  req.onerror = eventRejectHandler(reject);
5397
5418
  req.onblocked = _this._fireOnBlocked;
5398
5419
  };
5399
- if (hasArguments)
5400
- throw new exceptions.InvalidArgument("Arguments not allowed in db.delete()");
5420
+ if (hasInvalidArguments)
5421
+ throw new exceptions.InvalidArgument("Invalid closeOptions argument to db.delete()");
5401
5422
  if (state.isBeingOpened) {
5402
5423
  state.dbReadyPromise.then(doDelete);
5403
5424
  }
@@ -5718,15 +5739,9 @@ if (typeof dispatchEvent !== 'undefined' && typeof addEventListener !== 'undefin
5718
5739
  globalEvents(DEXIE_STORAGE_MUTATED_EVENT_NAME, function (updatedParts) {
5719
5740
  if (!propagatingLocally) {
5720
5741
  var event_1;
5721
- if (isIEOrEdge) {
5722
- event_1 = document.createEvent('CustomEvent');
5723
- event_1.initCustomEvent(STORAGE_MUTATED_DOM_EVENT_NAME, true, true, updatedParts);
5724
- }
5725
- else {
5726
- event_1 = new CustomEvent(STORAGE_MUTATED_DOM_EVENT_NAME, {
5727
- detail: updatedParts
5728
- });
5729
- }
5742
+ event_1 = new CustomEvent(STORAGE_MUTATED_DOM_EVENT_NAME, {
5743
+ detail: updatedParts
5744
+ });
5730
5745
  propagatingLocally = true;
5731
5746
  dispatchEvent(event_1);
5732
5747
  propagatingLocally = false;
@@ -5772,24 +5787,32 @@ if (typeof BroadcastChannel !== 'undefined') {
5772
5787
 
5773
5788
  if (typeof addEventListener !== 'undefined') {
5774
5789
  addEventListener('pagehide', function (event) {
5775
- if (event.persisted) {
5790
+ if (!Dexie$1.disableBfCache && event.persisted) {
5791
+ if (debug)
5792
+ console.debug('Dexie: handling persisted pagehide');
5776
5793
  bc === null || bc === void 0 ? void 0 : bc.close();
5777
- }
5778
- for (var _i = 0, connections_1 = connections; _i < connections_1.length; _i++) {
5779
- var db = connections_1[_i];
5780
- db.close({ disableAutoOpen: false });
5794
+ for (var _i = 0, connections_1 = connections; _i < connections_1.length; _i++) {
5795
+ var db = connections_1[_i];
5796
+ db.close({ disableAutoOpen: false });
5797
+ }
5781
5798
  }
5782
5799
  });
5783
5800
  addEventListener('pageshow', function (event) {
5784
- if (event.persisted) {
5801
+ if (!Dexie$1.disableBfCache && event.persisted) {
5802
+ if (debug)
5803
+ console.debug('Dexie: handling persisted pageshow');
5785
5804
  createBC();
5786
5805
  propagateLocally({ all: new RangeSet(-Infinity, [[]]) });
5787
5806
  }
5788
5807
  });
5789
5808
  }
5790
5809
 
5810
+ function replacePrefix(a, b) {
5811
+ return new PropModification({ replacePrefix: [a, b] });
5812
+ }
5813
+
5791
5814
  DexiePromise.rejectionMapper = mapError;
5792
5815
  setDebug(debug);
5793
5816
 
5794
- export { Dexie$1 as Dexie, Entity, RangeSet, cmp, Dexie$1 as default, liveQuery, mergeRanges, rangesOverlap };
5817
+ export { Dexie$1 as Dexie, Entity, PropModSymbol, PropModification, RangeSet, cmp, Dexie$1 as default, liveQuery, mergeRanges, rangesOverlap, replacePrefix };
5795
5818
  //# sourceMappingURL=dexie.mjs.map