dexie 4.2.1 → 4.4.0

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,57 +4,49 @@
4
4
  *
5
5
  * By David Fahlander, david.fahlander@gmail.com
6
6
  *
7
- * Version 4.2.1, Sat Oct 04 2025
7
+ * Version 4.4.0, Wed Mar 18 2026
8
8
  *
9
9
  * https://dexie.org
10
10
  *
11
11
  * Apache License Version 2.0, January 2004, http://www.apache.org/licenses/
12
12
  */
13
13
 
14
- /*! *****************************************************************************
15
- Copyright (c) Microsoft Corporation.
16
- Permission to use, copy, modify, and/or distribute this software for any
17
- purpose with or without fee is hereby granted.
18
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
19
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
20
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
21
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
22
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
23
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
24
- PERFORMANCE OF THIS SOFTWARE.
25
- ***************************************************************************** */
26
14
  var extendStatics = function(d, b) {
27
- extendStatics = Object.setPrototypeOf ||
28
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
29
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
30
- return extendStatics(d, b);
15
+ extendStatics = Object.setPrototypeOf ||
16
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
17
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
18
+ return extendStatics(d, b);
31
19
  };
32
20
  function __extends(d, b) {
33
- if (typeof b !== "function" && b !== null)
34
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
35
- extendStatics(d, b);
36
- function __() { this.constructor = d; }
37
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
21
+ if (typeof b !== "function" && b !== null)
22
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
23
+ extendStatics(d, b);
24
+ function __() { this.constructor = d; }
25
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
38
26
  }
39
27
  var __assign = function() {
40
- __assign = Object.assign || function __assign(t) {
41
- for (var s, i = 1, n = arguments.length; i < n; i++) {
42
- s = arguments[i];
43
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
44
- }
45
- return t;
46
- };
47
- return __assign.apply(this, arguments);
28
+ __assign = Object.assign || function __assign(t) {
29
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
30
+ s = arguments[i];
31
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
32
+ }
33
+ return t;
34
+ };
35
+ return __assign.apply(this, arguments);
48
36
  };
49
37
  function __spreadArray(to, from, pack) {
50
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
51
- if (ar || !(i in from)) {
52
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
53
- ar[i] = from[i];
54
- }
55
- }
56
- return to.concat(ar || Array.prototype.slice.call(from));
57
- }
38
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
39
+ if (ar || !(i in from)) {
40
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
41
+ ar[i] = from[i];
42
+ }
43
+ }
44
+ return to.concat(ar || Array.prototype.slice.call(from));
45
+ }
46
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
47
+ var e = new Error(message);
48
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
49
+ };
58
50
 
59
51
  var _global = typeof globalThis !== 'undefined' ? globalThis :
60
52
  typeof self !== 'undefined' ? self :
@@ -1146,12 +1138,12 @@ function tempTransaction(db, mode, storeNames, fn) {
1146
1138
  }
1147
1139
  }
1148
1140
 
1149
- var DEXIE_VERSION = '4.2.1';
1141
+ var DEXIE_VERSION = '4.4.0';
1150
1142
  var maxString = String.fromCharCode(65535);
1151
1143
  var minKey = -Infinity;
1152
1144
  var INVALID_KEY_ARGUMENT = "Invalid key provided. Keys must be of type string, number, Date or Array<string | number | Date>.";
1153
1145
  var STRING_EXPECTED = "String expected.";
1154
- var connections = [];
1146
+ var DEFAULT_MAX_CONNECTIONS = 1000;
1155
1147
  var DBNAMES_DB = '__dbnames';
1156
1148
  var READONLY = 'readonly';
1157
1149
  var READWRITE = 'readwrite';
@@ -1983,13 +1975,14 @@ var Collection = (function () {
1983
1975
  var _this = this;
1984
1976
  return this._read(function (trans) {
1985
1977
  var ctx = _this._ctx;
1986
- if (ctx.dir === 'next' && isPlainKeyRange(ctx, true) && ctx.limit > 0) {
1978
+ if (isPlainKeyRange(ctx, true) && ctx.limit > 0) {
1987
1979
  var valueMapper_1 = ctx.valueMapper;
1988
1980
  var index = getIndexOrStore(ctx, ctx.table.core.schema);
1989
1981
  return ctx.table.core.query({
1990
1982
  trans: trans,
1991
1983
  limit: ctx.limit,
1992
1984
  values: true,
1985
+ direction: ctx.dir === 'prev' ? 'prev' : undefined,
1993
1986
  query: {
1994
1987
  index: index,
1995
1988
  range: ctx.range
@@ -2114,13 +2107,14 @@ var Collection = (function () {
2114
2107
  };
2115
2108
  Collection.prototype.primaryKeys = function (cb) {
2116
2109
  var ctx = this._ctx;
2117
- if (ctx.dir === 'next' && isPlainKeyRange(ctx, true) && ctx.limit > 0) {
2110
+ if (isPlainKeyRange(ctx, true) && ctx.limit > 0) {
2118
2111
  return this._read(function (trans) {
2119
2112
  var index = getIndexOrStore(ctx, ctx.table.core.schema);
2120
2113
  return ctx.table.core.query({
2121
2114
  trans: trans,
2122
2115
  values: false,
2123
2116
  limit: ctx.limit,
2117
+ direction: ctx.dir === 'prev' ? 'prev' : undefined,
2124
2118
  query: {
2125
2119
  index: index,
2126
2120
  range: ctx.range
@@ -3010,6 +3004,9 @@ function getKeyPathAlias(keyPath) {
3010
3004
  function createDBCore(db, IdbKeyRange, tmpTrans) {
3011
3005
  function extractSchema(db, trans) {
3012
3006
  var tables = arrayify(db.objectStoreNames);
3007
+ var tempStore = tables.length > 0
3008
+ ? trans.objectStore(tables[0])
3009
+ : {};
3013
3010
  return {
3014
3011
  schema: {
3015
3012
  name: db.name,
@@ -3054,10 +3051,11 @@ function createDBCore(db, IdbKeyRange, tmpTrans) {
3054
3051
  return result;
3055
3052
  })
3056
3053
  },
3057
- hasGetAll: tables.length > 0 && ('getAll' in trans.objectStore(tables[0])) &&
3054
+ hasGetAll: tables.length > 0 && ('getAll' in tempStore) &&
3058
3055
  !(typeof navigator !== 'undefined' && /Safari/.test(navigator.userAgent) &&
3059
3056
  !/(Chrome\/|Edge\/)/.test(navigator.userAgent) &&
3060
- [].concat(navigator.userAgent.match(/Safari\/(\d*)/))[1] < 604)
3057
+ [].concat(navigator.userAgent.match(/Safari\/(\d*)/))[1] < 604),
3058
+ hasIdb3Features: 'getAllRecords' in tempStore
3061
3059
  };
3062
3060
  }
3063
3061
  function makeIDBKeyRange(range) {
@@ -3228,11 +3226,13 @@ function createDBCore(db, IdbKeyRange, tmpTrans) {
3228
3226
  }, reject);
3229
3227
  });
3230
3228
  }
3231
- function query(hasGetAll) {
3229
+ function query(hasGetAll, hasIdb3Features) {
3232
3230
  return function (request) {
3233
3231
  return new Promise(function (resolve, reject) {
3232
+ var _a;
3234
3233
  resolve = wrap(resolve);
3235
3234
  var trans = request.trans, values = request.values, limit = request.limit, query = request.query;
3235
+ var direction = (_a = request.direction) !== null && _a !== void 0 ? _a : 'next';
3236
3236
  var nonInfinitLimit = limit === Infinity ? undefined : limit;
3237
3237
  var index = query.index, range = query.range;
3238
3238
  var store = trans.objectStore(tableName);
@@ -3240,7 +3240,19 @@ function createDBCore(db, IdbKeyRange, tmpTrans) {
3240
3240
  var idbKeyRange = makeIDBKeyRange(range);
3241
3241
  if (limit === 0)
3242
3242
  return resolve({ result: [] });
3243
- if (hasGetAll) {
3243
+ if (hasIdb3Features) {
3244
+ var options = {
3245
+ query: idbKeyRange,
3246
+ count: nonInfinitLimit,
3247
+ direction: direction
3248
+ };
3249
+ var req = values ?
3250
+ source.getAll(options) :
3251
+ source.getAllKeys(options);
3252
+ req.onsuccess = function (event) { return resolve({ result: event.target.result }); };
3253
+ req.onerror = eventRejectHandler(reject);
3254
+ }
3255
+ else if (hasGetAll && direction === 'next') {
3244
3256
  var req = values ?
3245
3257
  source.getAll(idbKeyRange, nonInfinitLimit) :
3246
3258
  source.getAllKeys(idbKeyRange, nonInfinitLimit);
@@ -3250,10 +3262,10 @@ function createDBCore(db, IdbKeyRange, tmpTrans) {
3250
3262
  else {
3251
3263
  var count_1 = 0;
3252
3264
  var req_1 = values || !('openKeyCursor' in source) ?
3253
- source.openCursor(idbKeyRange) :
3254
- source.openKeyCursor(idbKeyRange);
3265
+ source.openCursor(idbKeyRange, direction) :
3266
+ source.openKeyCursor(idbKeyRange, direction);
3255
3267
  var result_1 = [];
3256
- req_1.onsuccess = function (event) {
3268
+ req_1.onsuccess = function () {
3257
3269
  var cursor = req_1.result;
3258
3270
  if (!cursor)
3259
3271
  return resolve({ result: result_1 });
@@ -3313,7 +3325,7 @@ function createDBCore(db, IdbKeyRange, tmpTrans) {
3313
3325
  req.onerror = eventRejectHandler(reject);
3314
3326
  });
3315
3327
  },
3316
- query: query(hasGetAll),
3328
+ query: query(hasGetAll, hasIdb3Features),
3317
3329
  openCursor: openCursor,
3318
3330
  count: function (_a) {
3319
3331
  var query = _a.query, trans = _a.trans;
@@ -3329,7 +3341,7 @@ function createDBCore(db, IdbKeyRange, tmpTrans) {
3329
3341
  }
3330
3342
  };
3331
3343
  }
3332
- var _a = extractSchema(db, tmpTrans), schema = _a.schema, hasGetAll = _a.hasGetAll;
3344
+ var _a = extractSchema(db, tmpTrans), schema = _a.schema, hasGetAll = _a.hasGetAll, hasIdb3Features = _a.hasIdb3Features;
3333
3345
  var tables = schema.tables.map(function (tableSchema) { return createDbCoreTable(tableSchema); });
3334
3346
  var tableMap = {};
3335
3347
  tables.forEach(function (table) { return tableMap[table.name] = table; });
@@ -3781,6 +3793,63 @@ function createVersionConstructor(db) {
3781
3793
  });
3782
3794
  }
3783
3795
 
3796
+ var connections = createConnectionsManager();
3797
+ function createConnectionsManager() {
3798
+ if (typeof FinalizationRegistry !== 'undefined' && typeof WeakRef !== 'undefined') {
3799
+ var _refs_1 = new Set();
3800
+ var _registry_1 = new FinalizationRegistry(function (ref) {
3801
+ _refs_1.delete(ref);
3802
+ });
3803
+ var toArray = function () {
3804
+ return Array.from(_refs_1)
3805
+ .map(function (ref) { return ref.deref(); })
3806
+ .filter(function (db) { return db !== undefined; });
3807
+ };
3808
+ var add = function (db) {
3809
+ var ref = new WeakRef(db._novip);
3810
+ _refs_1.add(ref);
3811
+ _registry_1.register(db._novip, ref, ref);
3812
+ if (_refs_1.size > db._options.maxConnections) {
3813
+ var oldestRef = _refs_1.values().next().value;
3814
+ _refs_1.delete(oldestRef);
3815
+ _registry_1.unregister(oldestRef);
3816
+ }
3817
+ };
3818
+ var remove = function (db) {
3819
+ if (!db)
3820
+ return;
3821
+ var iterator = _refs_1.values();
3822
+ var result = iterator.next();
3823
+ while (!result.done) {
3824
+ var ref = result.value;
3825
+ if (ref.deref() === db._novip) {
3826
+ _refs_1.delete(ref);
3827
+ _registry_1.unregister(ref);
3828
+ return;
3829
+ }
3830
+ result = iterator.next();
3831
+ }
3832
+ };
3833
+ return { toArray: toArray, add: add, remove: remove };
3834
+ }
3835
+ else {
3836
+ var connections_1 = [];
3837
+ var toArray = function () { return connections_1; };
3838
+ var add = function (db) {
3839
+ connections_1.push(db._novip);
3840
+ };
3841
+ var remove = function (db) {
3842
+ if (!db)
3843
+ return;
3844
+ var index = connections_1.indexOf(db._novip);
3845
+ if (index !== -1) {
3846
+ connections_1.splice(index, 1);
3847
+ }
3848
+ };
3849
+ return { toArray: toArray, add: add, remove: remove };
3850
+ }
3851
+ }
3852
+
3784
3853
  function getDbNamesTable(indexedDB, IDBKeyRange) {
3785
3854
  var dbNamesDB = indexedDB["_dbNamesDB"];
3786
3855
  if (!dbNamesDB) {
@@ -4159,7 +4228,7 @@ function dexieOpen(db) {
4159
4228
  }
4160
4229
  catch (e) {
4161
4230
  }
4162
- connections.push(db);
4231
+ connections.add(db);
4163
4232
  idbdb.onversionchange = wrap(function (ev) {
4164
4233
  state.vcFired = true;
4165
4234
  db.on("versionchange").fire(ev);
@@ -5004,10 +5073,13 @@ function applyOptimisticOps(result, req, ops, table, cacheEntry, immutable) {
5004
5073
  }, result);
5005
5074
  if (finalResult === result)
5006
5075
  return result;
5007
- finalResult.sort(function (a, b) {
5076
+ var sorter = function (a, b) {
5008
5077
  return cmp(extractLowLevelIndex(a), extractLowLevelIndex(b)) ||
5009
5078
  cmp(extractPrimKey(a), extractPrimKey(b));
5010
- });
5079
+ };
5080
+ finalResult.sort(req.direction === 'prev' || req.direction === 'prevunique'
5081
+ ? function (a, b) { return sorter(b, a); }
5082
+ : sorter);
5011
5083
  if (req.limit && req.limit < Infinity) {
5012
5084
  if (finalResult.length > req.limit) {
5013
5085
  finalResult.length = req.limit;
@@ -5064,6 +5136,7 @@ function isSuperRange(r1, r2) {
5064
5136
  }
5065
5137
 
5066
5138
  function findCompatibleQuery(dbName, tableName, type, req) {
5139
+ var _a;
5067
5140
  var tblCache = cache["idb://".concat(dbName, "/").concat(tableName)];
5068
5141
  if (!tblCache)
5069
5142
  return [];
@@ -5076,9 +5149,12 @@ function findCompatibleQuery(dbName, tableName, type, req) {
5076
5149
  return [null, false, tblCache, null];
5077
5150
  switch (type) {
5078
5151
  case 'query':
5152
+ var reqDirection_1 = (_a = req.direction) !== null && _a !== void 0 ? _a : 'next';
5079
5153
  var equalEntry = entries.find(function (entry) {
5154
+ var _a;
5080
5155
  return entry.req.limit === req.limit &&
5081
5156
  entry.req.values === req.values &&
5157
+ ((_a = entry.req.direction) !== null && _a !== void 0 ? _a : 'next') === reqDirection_1 &&
5082
5158
  areRangesEqual(entry.req.query.range, req.query.range);
5083
5159
  });
5084
5160
  if (equalEntry)
@@ -5089,8 +5165,10 @@ function findCompatibleQuery(dbName, tableName, type, req) {
5089
5165
  entries,
5090
5166
  ];
5091
5167
  var superEntry = entries.find(function (entry) {
5168
+ var _a;
5092
5169
  var limit = 'limit' in entry.req ? entry.req.limit : Infinity;
5093
5170
  return (limit >= req.limit &&
5171
+ ((_a = entry.req.direction) !== null && _a !== void 0 ? _a : 'next') === reqDirection_1 &&
5094
5172
  (req.values ? entry.req.values : true) &&
5095
5173
  isSuperRange(entry.req.query.range, req.query.range));
5096
5174
  });
@@ -5340,7 +5418,7 @@ var Dexie$1 = (function () {
5340
5418
  var deps = Dexie.dependencies;
5341
5419
  this._options = options = __assign({
5342
5420
  addons: Dexie.addons, autoOpen: true,
5343
- indexedDB: deps.indexedDB, IDBKeyRange: deps.IDBKeyRange, cache: 'cloned' }, options);
5421
+ indexedDB: deps.indexedDB, IDBKeyRange: deps.IDBKeyRange, cache: 'cloned', maxConnections: DEFAULT_MAX_CONNECTIONS }, options);
5344
5422
  this._deps = {
5345
5423
  indexedDB: options.indexedDB,
5346
5424
  IDBKeyRange: options.IDBKeyRange
@@ -5434,7 +5512,7 @@ var Dexie$1 = (function () {
5434
5512
  this._createTransaction = function (mode, storeNames, dbschema, parentTransaction) { return new _this.Transaction(mode, storeNames, dbschema, _this._options.chromeTransactionDurability, parentTransaction); };
5435
5513
  this._fireOnBlocked = function (ev) {
5436
5514
  _this.on("blocked").fire(ev);
5437
- connections
5515
+ connections.toArray()
5438
5516
  .filter(function (c) { return c.name === _this.name && c !== _this && !c._state.vcFired; })
5439
5517
  .map(function (c) { return c.on("versionchange").fire(ev); });
5440
5518
  };
@@ -5527,9 +5605,7 @@ var Dexie$1 = (function () {
5527
5605
  Dexie.prototype._close = function () {
5528
5606
  this.on.close.fire(new CustomEvent('close'));
5529
5607
  var state = this._state;
5530
- var idx = connections.indexOf(this);
5531
- if (idx >= 0)
5532
- connections.splice(idx, 1);
5608
+ connections.remove(this);
5533
5609
  if (this.idbdb) {
5534
5610
  try {
5535
5611
  this.idbdb.close();
@@ -5891,7 +5967,9 @@ props(Dexie, __assign(__assign({}, fullNameExceptions), {
5891
5967
  getByKeyPath: getByKeyPath, setByKeyPath: setByKeyPath, delByKeyPath: delByKeyPath, shallowClone: shallowClone, deepClone: deepClone, getObjectDiff: getObjectDiff, cmp: cmp, asap: asap$1,
5892
5968
  minKey: minKey,
5893
5969
  addons: [],
5894
- connections: connections,
5970
+ connections: {
5971
+ get: connections.toArray
5972
+ },
5895
5973
  errnames: errnames,
5896
5974
  dependencies: domDeps, cache: cache,
5897
5975
  semVer: DEXIE_VERSION, version: DEXIE_VERSION.split('.')
@@ -5955,8 +6033,8 @@ if (typeof addEventListener !== 'undefined') {
5955
6033
  if (debug)
5956
6034
  console.debug('Dexie: handling persisted pagehide');
5957
6035
  bc === null || bc === void 0 ? void 0 : bc.close();
5958
- for (var _i = 0, connections_1 = connections; _i < connections_1.length; _i++) {
5959
- var db = connections_1[_i];
6036
+ for (var _i = 0, _a = connections.toArray(); _i < _a.length; _i++) {
6037
+ var db = _a[_i];
5960
6038
  db.close({ disableAutoOpen: false });
5961
6039
  }
5962
6040
  }
@@ -5986,5 +6064,5 @@ function replacePrefix(a, b) {
5986
6064
  DexiePromise.rejectionMapper = mapError;
5987
6065
  setDebug(debug);
5988
6066
 
5989
- export { Dexie$1 as Dexie, Entity, PropModification, RangeSet, add, cmp, Dexie$1 as default, liveQuery, mergeRanges, rangesOverlap, remove, replacePrefix };
6067
+ export { DEFAULT_MAX_CONNECTIONS, Dexie$1 as Dexie, Entity, PropModification, RangeSet, add, cmp, Dexie$1 as default, liveQuery, mergeRanges, rangesOverlap, remove, replacePrefix };
5990
6068
  //# sourceMappingURL=dexie.mjs.map