dexie 4.3.0 → 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.d.ts CHANGED
@@ -4,7 +4,7 @@
4
4
  *
5
5
  * By David Fahlander, david.fahlander@gmail.com
6
6
  *
7
- * Version 4.3.0, Sat Dec 20 2025
7
+ * Version 4.4.0, Wed Mar 18 2026
8
8
  *
9
9
  * https://dexie.org
10
10
  *
@@ -643,6 +643,7 @@ export interface DBCoreQueryRequest {
643
643
  values?: boolean;
644
644
  limit?: number;
645
645
  query: DBCoreQuery;
646
+ direction?: "next" | "nextunique" | "prev" | "prevunique";
646
647
  obsSet?: ObservabilitySet;
647
648
  }
648
649
  export interface DBCoreQueryResponse {
@@ -1119,6 +1120,7 @@ export interface DexieOptions {
1119
1120
  };
1120
1121
  chromeTransactionDurability?: ChromeTransactionDurability;
1121
1122
  cache?: "immutable" | "cloned" | "disabled";
1123
+ maxConnections?: number;
1122
1124
  }
1123
1125
  export interface DexieConstructor extends DexieExceptionClasses {
1124
1126
  new (databaseName: string, options?: DexieOptions): Dexie;
@@ -1199,7 +1201,7 @@ export interface _Collection<T, TKey> extends Collection<T, TKey> {
1199
1201
  }
1200
1202
  // Besides being the only exported value, let Dexie also be
1201
1203
  // a namespace for types...
1202
- export declare module Dexie {
1204
+ export declare namespace Dexie {
1203
1205
  // The "Dexie.Promise" type.
1204
1206
  type Promise<T = any> = PromiseExtended<T>; // Because many samples have been Dexie.Promise.
1205
1207
  // The "Dexie.Table" interface. Same as named exported interface Table.
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.3.0, Sat Dec 20 2025
7
+ * Version 4.4.0, Wed Mar 18 2026
8
8
  *
9
9
  * https://dexie.org
10
10
  *
@@ -1144,12 +1144,12 @@
1144
1144
  }
1145
1145
  }
1146
1146
 
1147
- var DEXIE_VERSION = '4.3.0';
1147
+ var DEXIE_VERSION = '4.4.0';
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
- var connections = [];
1152
+ var DEFAULT_MAX_CONNECTIONS = 1000;
1153
1153
  var DBNAMES_DB = '__dbnames';
1154
1154
  var READONLY = 'readonly';
1155
1155
  var READWRITE = 'readwrite';
@@ -1981,13 +1981,14 @@
1981
1981
  var _this = this;
1982
1982
  return this._read(function (trans) {
1983
1983
  var ctx = _this._ctx;
1984
- if (ctx.dir === 'next' && isPlainKeyRange(ctx, true) && ctx.limit > 0) {
1984
+ if (isPlainKeyRange(ctx, true) && ctx.limit > 0) {
1985
1985
  var valueMapper_1 = ctx.valueMapper;
1986
1986
  var index = getIndexOrStore(ctx, ctx.table.core.schema);
1987
1987
  return ctx.table.core.query({
1988
1988
  trans: trans,
1989
1989
  limit: ctx.limit,
1990
1990
  values: true,
1991
+ direction: ctx.dir === 'prev' ? 'prev' : undefined,
1991
1992
  query: {
1992
1993
  index: index,
1993
1994
  range: ctx.range
@@ -2112,13 +2113,14 @@
2112
2113
  };
2113
2114
  Collection.prototype.primaryKeys = function (cb) {
2114
2115
  var ctx = this._ctx;
2115
- if (ctx.dir === 'next' && isPlainKeyRange(ctx, true) && ctx.limit > 0) {
2116
+ if (isPlainKeyRange(ctx, true) && ctx.limit > 0) {
2116
2117
  return this._read(function (trans) {
2117
2118
  var index = getIndexOrStore(ctx, ctx.table.core.schema);
2118
2119
  return ctx.table.core.query({
2119
2120
  trans: trans,
2120
2121
  values: false,
2121
2122
  limit: ctx.limit,
2123
+ direction: ctx.dir === 'prev' ? 'prev' : undefined,
2122
2124
  query: {
2123
2125
  index: index,
2124
2126
  range: ctx.range
@@ -3008,6 +3010,9 @@
3008
3010
  function createDBCore(db, IdbKeyRange, tmpTrans) {
3009
3011
  function extractSchema(db, trans) {
3010
3012
  var tables = arrayify(db.objectStoreNames);
3013
+ var tempStore = tables.length > 0
3014
+ ? trans.objectStore(tables[0])
3015
+ : {};
3011
3016
  return {
3012
3017
  schema: {
3013
3018
  name: db.name,
@@ -3052,10 +3057,11 @@
3052
3057
  return result;
3053
3058
  })
3054
3059
  },
3055
- hasGetAll: tables.length > 0 && ('getAll' in trans.objectStore(tables[0])) &&
3060
+ hasGetAll: tables.length > 0 && ('getAll' in tempStore) &&
3056
3061
  !(typeof navigator !== 'undefined' && /Safari/.test(navigator.userAgent) &&
3057
3062
  !/(Chrome\/|Edge\/)/.test(navigator.userAgent) &&
3058
- [].concat(navigator.userAgent.match(/Safari\/(\d*)/))[1] < 604)
3063
+ [].concat(navigator.userAgent.match(/Safari\/(\d*)/))[1] < 604),
3064
+ hasIdb3Features: 'getAllRecords' in tempStore
3059
3065
  };
3060
3066
  }
3061
3067
  function makeIDBKeyRange(range) {
@@ -3226,11 +3232,13 @@
3226
3232
  }, reject);
3227
3233
  });
3228
3234
  }
3229
- function query(hasGetAll) {
3235
+ function query(hasGetAll, hasIdb3Features) {
3230
3236
  return function (request) {
3231
3237
  return new Promise(function (resolve, reject) {
3238
+ var _a;
3232
3239
  resolve = wrap(resolve);
3233
3240
  var trans = request.trans, values = request.values, limit = request.limit, query = request.query;
3241
+ var direction = (_a = request.direction) !== null && _a !== void 0 ? _a : 'next';
3234
3242
  var nonInfinitLimit = limit === Infinity ? undefined : limit;
3235
3243
  var index = query.index, range = query.range;
3236
3244
  var store = trans.objectStore(tableName);
@@ -3238,7 +3246,19 @@
3238
3246
  var idbKeyRange = makeIDBKeyRange(range);
3239
3247
  if (limit === 0)
3240
3248
  return resolve({ result: [] });
3241
- if (hasGetAll) {
3249
+ if (hasIdb3Features) {
3250
+ var options = {
3251
+ query: idbKeyRange,
3252
+ count: nonInfinitLimit,
3253
+ direction: direction
3254
+ };
3255
+ var req = values ?
3256
+ source.getAll(options) :
3257
+ source.getAllKeys(options);
3258
+ req.onsuccess = function (event) { return resolve({ result: event.target.result }); };
3259
+ req.onerror = eventRejectHandler(reject);
3260
+ }
3261
+ else if (hasGetAll && direction === 'next') {
3242
3262
  var req = values ?
3243
3263
  source.getAll(idbKeyRange, nonInfinitLimit) :
3244
3264
  source.getAllKeys(idbKeyRange, nonInfinitLimit);
@@ -3248,10 +3268,10 @@
3248
3268
  else {
3249
3269
  var count_1 = 0;
3250
3270
  var req_1 = values || !('openKeyCursor' in source) ?
3251
- source.openCursor(idbKeyRange) :
3252
- source.openKeyCursor(idbKeyRange);
3271
+ source.openCursor(idbKeyRange, direction) :
3272
+ source.openKeyCursor(idbKeyRange, direction);
3253
3273
  var result_1 = [];
3254
- req_1.onsuccess = function (event) {
3274
+ req_1.onsuccess = function () {
3255
3275
  var cursor = req_1.result;
3256
3276
  if (!cursor)
3257
3277
  return resolve({ result: result_1 });
@@ -3311,7 +3331,7 @@
3311
3331
  req.onerror = eventRejectHandler(reject);
3312
3332
  });
3313
3333
  },
3314
- query: query(hasGetAll),
3334
+ query: query(hasGetAll, hasIdb3Features),
3315
3335
  openCursor: openCursor,
3316
3336
  count: function (_a) {
3317
3337
  var query = _a.query, trans = _a.trans;
@@ -3327,7 +3347,7 @@
3327
3347
  }
3328
3348
  };
3329
3349
  }
3330
- var _a = extractSchema(db, tmpTrans), schema = _a.schema, hasGetAll = _a.hasGetAll;
3350
+ var _a = extractSchema(db, tmpTrans), schema = _a.schema, hasGetAll = _a.hasGetAll, hasIdb3Features = _a.hasIdb3Features;
3331
3351
  var tables = schema.tables.map(function (tableSchema) { return createDbCoreTable(tableSchema); });
3332
3352
  var tableMap = {};
3333
3353
  tables.forEach(function (table) { return tableMap[table.name] = table; });
@@ -3779,6 +3799,63 @@
3779
3799
  });
3780
3800
  }
3781
3801
 
3802
+ var connections = createConnectionsManager();
3803
+ function createConnectionsManager() {
3804
+ if (typeof FinalizationRegistry !== 'undefined' && typeof WeakRef !== 'undefined') {
3805
+ var _refs_1 = new Set();
3806
+ var _registry_1 = new FinalizationRegistry(function (ref) {
3807
+ _refs_1.delete(ref);
3808
+ });
3809
+ var toArray = function () {
3810
+ return Array.from(_refs_1)
3811
+ .map(function (ref) { return ref.deref(); })
3812
+ .filter(function (db) { return db !== undefined; });
3813
+ };
3814
+ var add = function (db) {
3815
+ var ref = new WeakRef(db._novip);
3816
+ _refs_1.add(ref);
3817
+ _registry_1.register(db._novip, ref, ref);
3818
+ if (_refs_1.size > db._options.maxConnections) {
3819
+ var oldestRef = _refs_1.values().next().value;
3820
+ _refs_1.delete(oldestRef);
3821
+ _registry_1.unregister(oldestRef);
3822
+ }
3823
+ };
3824
+ var remove = function (db) {
3825
+ if (!db)
3826
+ return;
3827
+ var iterator = _refs_1.values();
3828
+ var result = iterator.next();
3829
+ while (!result.done) {
3830
+ var ref = result.value;
3831
+ if (ref.deref() === db._novip) {
3832
+ _refs_1.delete(ref);
3833
+ _registry_1.unregister(ref);
3834
+ return;
3835
+ }
3836
+ result = iterator.next();
3837
+ }
3838
+ };
3839
+ return { toArray: toArray, add: add, remove: remove };
3840
+ }
3841
+ else {
3842
+ var connections_1 = [];
3843
+ var toArray = function () { return connections_1; };
3844
+ var add = function (db) {
3845
+ connections_1.push(db._novip);
3846
+ };
3847
+ var remove = function (db) {
3848
+ if (!db)
3849
+ return;
3850
+ var index = connections_1.indexOf(db._novip);
3851
+ if (index !== -1) {
3852
+ connections_1.splice(index, 1);
3853
+ }
3854
+ };
3855
+ return { toArray: toArray, add: add, remove: remove };
3856
+ }
3857
+ }
3858
+
3782
3859
  function getDbNamesTable(indexedDB, IDBKeyRange) {
3783
3860
  var dbNamesDB = indexedDB["_dbNamesDB"];
3784
3861
  if (!dbNamesDB) {
@@ -4157,7 +4234,7 @@
4157
4234
  }
4158
4235
  catch (e) {
4159
4236
  }
4160
- connections.push(db);
4237
+ connections.add(db);
4161
4238
  idbdb.onversionchange = wrap(function (ev) {
4162
4239
  state.vcFired = true;
4163
4240
  db.on("versionchange").fire(ev);
@@ -5002,10 +5079,13 @@
5002
5079
  }, result);
5003
5080
  if (finalResult === result)
5004
5081
  return result;
5005
- finalResult.sort(function (a, b) {
5082
+ var sorter = function (a, b) {
5006
5083
  return cmp(extractLowLevelIndex(a), extractLowLevelIndex(b)) ||
5007
5084
  cmp(extractPrimKey(a), extractPrimKey(b));
5008
- });
5085
+ };
5086
+ finalResult.sort(req.direction === 'prev' || req.direction === 'prevunique'
5087
+ ? function (a, b) { return sorter(b, a); }
5088
+ : sorter);
5009
5089
  if (req.limit && req.limit < Infinity) {
5010
5090
  if (finalResult.length > req.limit) {
5011
5091
  finalResult.length = req.limit;
@@ -5062,6 +5142,7 @@
5062
5142
  }
5063
5143
 
5064
5144
  function findCompatibleQuery(dbName, tableName, type, req) {
5145
+ var _a;
5065
5146
  var tblCache = cache["idb://".concat(dbName, "/").concat(tableName)];
5066
5147
  if (!tblCache)
5067
5148
  return [];
@@ -5074,9 +5155,12 @@
5074
5155
  return [null, false, tblCache, null];
5075
5156
  switch (type) {
5076
5157
  case 'query':
5158
+ var reqDirection_1 = (_a = req.direction) !== null && _a !== void 0 ? _a : 'next';
5077
5159
  var equalEntry = entries.find(function (entry) {
5160
+ var _a;
5078
5161
  return entry.req.limit === req.limit &&
5079
5162
  entry.req.values === req.values &&
5163
+ ((_a = entry.req.direction) !== null && _a !== void 0 ? _a : 'next') === reqDirection_1 &&
5080
5164
  areRangesEqual(entry.req.query.range, req.query.range);
5081
5165
  });
5082
5166
  if (equalEntry)
@@ -5087,8 +5171,10 @@
5087
5171
  entries,
5088
5172
  ];
5089
5173
  var superEntry = entries.find(function (entry) {
5174
+ var _a;
5090
5175
  var limit = 'limit' in entry.req ? entry.req.limit : Infinity;
5091
5176
  return (limit >= req.limit &&
5177
+ ((_a = entry.req.direction) !== null && _a !== void 0 ? _a : 'next') === reqDirection_1 &&
5092
5178
  (req.values ? entry.req.values : true) &&
5093
5179
  isSuperRange(entry.req.query.range, req.query.range));
5094
5180
  });
@@ -5338,7 +5424,7 @@
5338
5424
  var deps = Dexie.dependencies;
5339
5425
  this._options = options = __assign({
5340
5426
  addons: Dexie.addons, autoOpen: true,
5341
- indexedDB: deps.indexedDB, IDBKeyRange: deps.IDBKeyRange, cache: 'cloned' }, options);
5427
+ indexedDB: deps.indexedDB, IDBKeyRange: deps.IDBKeyRange, cache: 'cloned', maxConnections: DEFAULT_MAX_CONNECTIONS }, options);
5342
5428
  this._deps = {
5343
5429
  indexedDB: options.indexedDB,
5344
5430
  IDBKeyRange: options.IDBKeyRange
@@ -5432,7 +5518,7 @@
5432
5518
  this._createTransaction = function (mode, storeNames, dbschema, parentTransaction) { return new _this.Transaction(mode, storeNames, dbschema, _this._options.chromeTransactionDurability, parentTransaction); };
5433
5519
  this._fireOnBlocked = function (ev) {
5434
5520
  _this.on("blocked").fire(ev);
5435
- connections
5521
+ connections.toArray()
5436
5522
  .filter(function (c) { return c.name === _this.name && c !== _this && !c._state.vcFired; })
5437
5523
  .map(function (c) { return c.on("versionchange").fire(ev); });
5438
5524
  };
@@ -5525,9 +5611,7 @@
5525
5611
  Dexie.prototype._close = function () {
5526
5612
  this.on.close.fire(new CustomEvent('close'));
5527
5613
  var state = this._state;
5528
- var idx = connections.indexOf(this);
5529
- if (idx >= 0)
5530
- connections.splice(idx, 1);
5614
+ connections.remove(this);
5531
5615
  if (this.idbdb) {
5532
5616
  try {
5533
5617
  this.idbdb.close();
@@ -5889,7 +5973,9 @@
5889
5973
  getByKeyPath: getByKeyPath, setByKeyPath: setByKeyPath, delByKeyPath: delByKeyPath, shallowClone: shallowClone, deepClone: deepClone, getObjectDiff: getObjectDiff, cmp: cmp, asap: asap$1,
5890
5974
  minKey: minKey,
5891
5975
  addons: [],
5892
- connections: connections,
5976
+ connections: {
5977
+ get: connections.toArray
5978
+ },
5893
5979
  errnames: errnames,
5894
5980
  dependencies: domDeps, cache: cache,
5895
5981
  semVer: DEXIE_VERSION, version: DEXIE_VERSION.split('.')
@@ -5953,8 +6039,8 @@
5953
6039
  if (debug)
5954
6040
  console.debug('Dexie: handling persisted pagehide');
5955
6041
  bc === null || bc === void 0 ? void 0 : bc.close();
5956
- for (var _i = 0, connections_1 = connections; _i < connections_1.length; _i++) {
5957
- var db = connections_1[_i];
6042
+ for (var _i = 0, _a = connections.toArray(); _i < _a.length; _i++) {
6043
+ var db = _a[_i];
5958
6044
  db.close({ disableAutoOpen: false });
5959
6045
  }
5960
6046
  }
@@ -5986,6 +6072,7 @@
5986
6072
 
5987
6073
  var namedExports = /*#__PURE__*/Object.freeze({
5988
6074
  __proto__: null,
6075
+ DEFAULT_MAX_CONNECTIONS: DEFAULT_MAX_CONNECTIONS,
5989
6076
  Dexie: Dexie$1,
5990
6077
  Entity: Entity,
5991
6078
  PropModification: PropModification,