dexie 3.2.1 → 4.0.0-alpha.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.mjs CHANGED
@@ -4,7 +4,7 @@
4
4
  *
5
5
  * By David Fahlander, david.fahlander@gmail.com
6
6
  *
7
- * Version 3.2.1, Wed Feb 16 2022
7
+ * Version 4.0.0-alpha.3, Wed Apr 27 2022
8
8
  *
9
9
  * https://dexie.org
10
10
  *
@@ -23,6 +23,19 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
23
23
  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
24
24
  PERFORMANCE OF THIS SOFTWARE.
25
25
  ***************************************************************************** */
26
+ 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);
31
+ };
32
+ 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 __());
38
+ }
26
39
  var __assign = function() {
27
40
  __assign = Object.assign || function __assign(t) {
28
41
  for (var s, i = 1, n = arguments.length; i < n; i++) {
@@ -176,7 +189,7 @@ function setByKeyPath(obj, keyPath, value) {
176
189
  obj[currentKeyPath] = value;
177
190
  else {
178
191
  var innerObj = obj[currentKeyPath];
179
- if (!innerObj)
192
+ if (!innerObj || !hasOwn(obj, currentKeyPath))
180
193
  innerObj = (obj[currentKeyPath] = {});
181
194
  setByKeyPath(innerObj, remainingKeyPath, value);
182
195
  }
@@ -421,11 +434,11 @@ var exceptions = errorList.reduce(function (obj, name) {
421
434
  this.inner = null;
422
435
  }
423
436
  else if (typeof msgOrInner === 'string') {
424
- this.message = "" + msgOrInner + (!inner ? '' : '\n ' + inner);
437
+ this.message = "".concat(msgOrInner).concat(!inner ? '' : '\n ' + inner);
425
438
  this.inner = inner || null;
426
439
  }
427
440
  else if (typeof msgOrInner === 'object') {
428
- this.message = msgOrInner.name + " " + msgOrInner.message;
441
+ this.message = "".concat(msgOrInner.name, " ").concat(msgOrInner.message);
429
442
  this.inner = msgOrInner;
430
443
  }
431
444
  }
@@ -1237,7 +1250,7 @@ function globalError(err, promise) {
1237
1250
  catch (_) { }
1238
1251
  }
1239
1252
  if (debug && event && !event.defaultPrevented) {
1240
- console.warn("Unhandled rejection: " + (err.stack || err));
1253
+ console.warn("Unhandled rejection: ".concat(err.stack || err));
1241
1254
  }
1242
1255
  }
1243
1256
  catch (e) { }
@@ -1281,7 +1294,7 @@ function tempTransaction(db, mode, storeNames, fn) {
1281
1294
  }
1282
1295
  }
1283
1296
 
1284
- var DEXIE_VERSION = '3.2.1';
1297
+ var DEXIE_VERSION = '4.0.0-alpha.3';
1285
1298
  var maxString = String.fromCharCode(65535);
1286
1299
  var minKey = -Infinity;
1287
1300
  var INVALID_KEY_ARGUMENT = "Invalid key provided. Keys must be of type string, number, Date or Array<string | number | Date>.";
@@ -1323,6 +1336,10 @@ function workaroundForUndefinedPrimKey(keyPath) {
1323
1336
  : function (obj) { return obj; };
1324
1337
  }
1325
1338
 
1339
+ function Entity() {
1340
+ throw exceptions.Type();
1341
+ }
1342
+
1326
1343
  var Table = (function () {
1327
1344
  function Table() {
1328
1345
  }
@@ -1360,7 +1377,7 @@ var Table = (function () {
1360
1377
  if (typeof indexOrCrit === 'string')
1361
1378
  return new this.db.WhereClause(this, indexOrCrit);
1362
1379
  if (isArray(indexOrCrit))
1363
- return new this.db.WhereClause(this, "[" + indexOrCrit.join('+') + "]");
1380
+ return new this.db.WhereClause(this, "[".concat(indexOrCrit.join('+'), "]"));
1364
1381
  var keyPaths = keys(indexOrCrit);
1365
1382
  if (keyPaths.length === 1)
1366
1383
  return this
@@ -1376,8 +1393,8 @@ var Table = (function () {
1376
1393
  .where(compoundIndex.name)
1377
1394
  .equals(compoundIndex.keyPath.map(function (kp) { return indexOrCrit[kp]; }));
1378
1395
  if (!compoundIndex && debug)
1379
- console.warn("The query " + JSON.stringify(indexOrCrit) + " on " + this.name + " would benefit of a " +
1380
- ("compound index [" + keyPaths.join('+') + "]"));
1396
+ console.warn("The query ".concat(JSON.stringify(indexOrCrit), " on ").concat(this.name, " would benefit of a ") +
1397
+ "compound index [".concat(keyPaths.join('+'), "]"));
1381
1398
  var idxByName = this.schema.idxByName;
1382
1399
  var idb = this.db._deps.indexedDB;
1383
1400
  function equals(a, b) {
@@ -1433,20 +1450,40 @@ var Table = (function () {
1433
1450
  };
1434
1451
  Table.prototype.orderBy = function (index) {
1435
1452
  return new this.db.Collection(new this.db.WhereClause(this, isArray(index) ?
1436
- "[" + index.join('+') + "]" :
1453
+ "[".concat(index.join('+'), "]") :
1437
1454
  index));
1438
1455
  };
1439
1456
  Table.prototype.reverse = function () {
1440
1457
  return this.toCollection().reverse();
1441
1458
  };
1442
1459
  Table.prototype.mapToClass = function (constructor) {
1460
+ var _a = this, db = _a.db, tableName = _a.name;
1443
1461
  this.schema.mappedClass = constructor;
1462
+ if (constructor.prototype instanceof Entity) {
1463
+ constructor = (function (_super) {
1464
+ __extends(class_1, _super);
1465
+ function class_1() {
1466
+ return _super !== null && _super.apply(this, arguments) || this;
1467
+ }
1468
+ Object.defineProperty(class_1.prototype, "db", {
1469
+ get: function () { return db; },
1470
+ enumerable: false,
1471
+ configurable: true
1472
+ });
1473
+ class_1.prototype.table = function () { return tableName; };
1474
+ return class_1;
1475
+ }(constructor));
1476
+ }
1477
+ var inheritedProps = new Set();
1478
+ for (var proto = constructor.prototype; proto; proto = getProto(proto)) {
1479
+ Object.getOwnPropertyNames(proto).forEach(function (propName) { return inheritedProps.add(propName); });
1480
+ }
1444
1481
  var readHook = function (obj) {
1445
1482
  if (!obj)
1446
1483
  return obj;
1447
1484
  var res = Object.create(constructor.prototype);
1448
1485
  for (var m in obj)
1449
- if (hasOwn(obj, m))
1486
+ if (!inheritedProps.has(m))
1450
1487
  try {
1451
1488
  res[m] = obj[m];
1452
1489
  }
@@ -1568,7 +1605,7 @@ var Table = (function () {
1568
1605
  var result = wantResults ? results : lastResult;
1569
1606
  if (numFailures === 0)
1570
1607
  return result;
1571
- throw new BulkError(_this.name + ".bulkAdd(): " + numFailures + " of " + numObjects + " operations failed", failures);
1608
+ throw new BulkError("".concat(_this.name, ".bulkAdd(): ").concat(numFailures, " of ").concat(numObjects, " operations failed"), failures);
1572
1609
  });
1573
1610
  });
1574
1611
  };
@@ -1593,7 +1630,7 @@ var Table = (function () {
1593
1630
  var result = wantResults ? results : lastResult;
1594
1631
  if (numFailures === 0)
1595
1632
  return result;
1596
- throw new BulkError(_this.name + ".bulkPut(): " + numFailures + " of " + numObjects + " operations failed", failures);
1633
+ throw new BulkError("".concat(_this.name, ".bulkPut(): ").concat(numFailures, " of ").concat(numObjects, " operations failed"), failures);
1597
1634
  });
1598
1635
  });
1599
1636
  };
@@ -1606,7 +1643,7 @@ var Table = (function () {
1606
1643
  var numFailures = _a.numFailures, lastResult = _a.lastResult, failures = _a.failures;
1607
1644
  if (numFailures === 0)
1608
1645
  return lastResult;
1609
- throw new BulkError(_this.name + ".bulkDelete(): " + numFailures + " of " + numKeys + " operations failed", failures);
1646
+ throw new BulkError("".concat(_this.name, ".bulkDelete(): ").concat(numFailures, " of ").concat(numKeys, " operations failed"), failures);
1610
1647
  });
1611
1648
  };
1612
1649
  return Table;
@@ -2940,7 +2977,7 @@ function getKeyPathAlias(keyPath) {
2940
2977
  ":id" :
2941
2978
  typeof keyPath === 'string' ?
2942
2979
  keyPath :
2943
- "[" + keyPath.join('+') + "]";
2980
+ "[".concat(keyPath.join('+'), "]");
2944
2981
  }
2945
2982
  function createDBCore(db, IdbKeyRange, tmpTrans) {
2946
2983
  function extractSchema(db, trans) {
@@ -3274,7 +3311,7 @@ function createDBCore(db, IdbKeyRange, tmpTrans) {
3274
3311
  table: function (name) {
3275
3312
  var result = tableMap[name];
3276
3313
  if (!result)
3277
- throw new Error("Table '" + name + "' not found");
3314
+ throw new Error("Table '".concat(name, "' not found"));
3278
3315
  return tableMap[name];
3279
3316
  },
3280
3317
  MIN_KEY: -Infinity,
@@ -3747,7 +3784,7 @@ function dexieOpen(db) {
3747
3784
  req.result.close();
3748
3785
  var delreq = indexedDB.deleteDatabase(dbName);
3749
3786
  delreq.onsuccess = delreq.onerror = wrap(function () {
3750
- reject(new exceptions.NoSuchDatabase("Database " + dbName + " doesnt exist"));
3787
+ reject(new exceptions.NoSuchDatabase("Database ".concat(dbName, " doesnt exist")));
3751
3788
  });
3752
3789
  }
3753
3790
  else {
@@ -4413,7 +4450,7 @@ var observabilityMiddleware = {
4413
4450
  var trans = req.trans;
4414
4451
  var mutatedParts = trans.mutatedParts || (trans.mutatedParts = {});
4415
4452
  var getRangeSet = function (indexName) {
4416
- var part = "idb://" + dbName + "/" + tableName + "/" + indexName;
4453
+ var part = "idb://".concat(dbName, "/").concat(tableName, "/").concat(indexName);
4417
4454
  return (mutatedParts[part] ||
4418
4455
  (mutatedParts[part] = new RangeSet()));
4419
4456
  };
@@ -4474,7 +4511,7 @@ var observabilityMiddleware = {
4474
4511
  var subscr = PSD.subscr;
4475
4512
  if (subscr) {
4476
4513
  var getRangeSet = function (indexName) {
4477
- var part = "idb://" + dbName + "/" + tableName + "/" + indexName;
4514
+ var part = "idb://".concat(dbName, "/").concat(tableName, "/").concat(indexName);
4478
4515
  return (subscr[part] ||
4479
4516
  (subscr[part] = new RangeSet()));
4480
4517
  };
@@ -4646,16 +4683,16 @@ var Dexie$1 = (function () {
4646
4683
  this.WhereClause = createWhereClauseConstructor(this);
4647
4684
  this.on("versionchange", function (ev) {
4648
4685
  if (ev.newVersion > 0)
4649
- console.warn("Another connection wants to upgrade database '" + _this.name + "'. Closing db now to resume the upgrade.");
4686
+ console.warn("Another connection wants to upgrade database '".concat(_this.name, "'. Closing db now to resume the upgrade."));
4650
4687
  else
4651
- console.warn("Another connection wants to delete database '" + _this.name + "'. Closing db now to resume the delete request.");
4688
+ console.warn("Another connection wants to delete database '".concat(_this.name, "'. Closing db now to resume the delete request."));
4652
4689
  _this.close();
4653
4690
  });
4654
4691
  this.on("blocked", function (ev) {
4655
4692
  if (!ev.newVersion || ev.newVersion < ev.oldVersion)
4656
- console.warn("Dexie.delete('" + _this.name + "') was blocked");
4693
+ console.warn("Dexie.delete('".concat(_this.name, "') was blocked"));
4657
4694
  else
4658
- console.warn("Upgrade '" + _this.name + "' blocked by other connection holding version " + ev.oldVersion / 10);
4695
+ console.warn("Upgrade '".concat(_this.name, "' blocked by other connection holding version ").concat(ev.oldVersion / 10));
4659
4696
  });
4660
4697
  this._maxKey = getMaxKey(options.IDBKeyRange);
4661
4698
  this._createTransaction = function (mode, storeNames, dbschema, parentTransaction) { return new _this.Transaction(mode, storeNames, dbschema, _this._options.chromeTransactionDurability, parentTransaction); };
@@ -4869,7 +4906,7 @@ var Dexie$1 = (function () {
4869
4906
  };
4870
4907
  Dexie.prototype.table = function (tableName) {
4871
4908
  if (!hasOwn(this._allTables, tableName)) {
4872
- throw new exceptions.InvalidTable("Table " + tableName + " does not exist");
4909
+ throw new exceptions.InvalidTable("Table ".concat(tableName, " does not exist"));
4873
4910
  }
4874
4911
  return this._allTables[tableName];
4875
4912
  };
@@ -4943,8 +4980,9 @@ function liveQuery(querier) {
4943
4980
  }
4944
4981
  };
4945
4982
  var doQuery = function () {
4946
- if (querying || closed)
4983
+ if (querying || closed) {
4947
4984
  return;
4985
+ }
4948
4986
  accumMuts = {};
4949
4987
  var subscr = {};
4950
4988
  var ret = execute(subscr);
@@ -4955,8 +4993,9 @@ function liveQuery(querier) {
4955
4993
  querying = true;
4956
4994
  Promise.resolve(ret).then(function (result) {
4957
4995
  querying = false;
4958
- if (closed)
4996
+ if (closed) {
4959
4997
  return;
4998
+ }
4960
4999
  if (shouldNotify()) {
4961
5000
  doQuery();
4962
5001
  }
@@ -4966,9 +5005,11 @@ function liveQuery(querier) {
4966
5005
  observer.next && observer.next(result);
4967
5006
  }
4968
5007
  }, function (err) {
4969
- querying = false;
4970
- observer.error && observer.error(err);
4971
- subscription.unsubscribe();
5008
+ if (!['DatabaseClosedError', 'AbortError'].includes(err === null || err === void 0 ? void 0 : err.name)) {
5009
+ querying = false;
5010
+ observer.error && observer.error(err);
5011
+ subscription.unsubscribe();
5012
+ }
4972
5013
  });
4973
5014
  };
4974
5015
  doQuery();
@@ -5141,13 +5182,15 @@ else if (typeof self !== 'undefined' && typeof navigator !== 'undefined') {
5141
5182
  }
5142
5183
  catch (_a) { }
5143
5184
  });
5144
- addEventListener('storage', function (ev) {
5145
- if (ev.key === STORAGE_MUTATED_DOM_EVENT_NAME) {
5146
- var data = JSON.parse(ev.newValue);
5147
- if (data)
5148
- propagateLocally(data.changedParts);
5149
- }
5150
- });
5185
+ if (typeof addEventListener !== 'undefined') {
5186
+ addEventListener('storage', function (ev) {
5187
+ if (ev.key === STORAGE_MUTATED_DOM_EVENT_NAME) {
5188
+ var data = JSON.parse(ev.newValue);
5189
+ if (data)
5190
+ propagateLocally(data.changedParts);
5191
+ }
5192
+ });
5193
+ }
5151
5194
  var swContainer = self.document && navigator.serviceWorker;
5152
5195
  if (swContainer) {
5153
5196
  swContainer.addEventListener('message', propagateMessageLocally);
@@ -5163,5 +5206,5 @@ function propagateMessageLocally(_a) {
5163
5206
  DexiePromise.rejectionMapper = mapError;
5164
5207
  setDebug(debug, dexieStackFrameFilter);
5165
5208
 
5166
- export { Dexie$1 as Dexie, RangeSet, Dexie$1 as default, liveQuery, mergeRanges, rangesOverlap };
5209
+ export { Dexie$1 as Dexie, Entity, RangeSet, cmp, Dexie$1 as default, liveQuery, mergeRanges, rangesOverlap };
5167
5210
  //# sourceMappingURL=dexie.mjs.map