dexie 3.2.1-beta.2 → 4.0.0-alpha.2

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-beta.2, Wed Jan 05 2022
7
+ * Version 4.0.0-alpha.2, Sun Apr 10 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++) {
@@ -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-beta.2';
1297
+ var DEXIE_VERSION = '4.0.0-alpha.2';
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,
@@ -3306,20 +3343,19 @@ function generateMiddlewareStacks(_a, tmpTrans) {
3306
3343
  if (db.core.schema.tables.some(function (tbl) { return tbl.name === tableName; })) {
3307
3344
  table.core = db.core.table(tableName);
3308
3345
  if (db[tableName] instanceof db.Table) {
3309
- db[tableName].core = table.core;
3346
+ db[tableName].core = db.vip[tableName].core = table.core;
3310
3347
  }
3311
3348
  }
3312
3349
  });
3313
3350
  }
3314
3351
 
3315
- function setApiOnPlace(_a, objs, tableNames, dbschema) {
3316
- var db = _a._novip;
3352
+ function setApiOnPlace(objs, tableNames, dbschema) {
3317
3353
  tableNames.forEach(function (tableName) {
3318
3354
  var schema = dbschema[tableName];
3319
3355
  objs.forEach(function (obj) {
3320
3356
  var propDesc = getPropertyDescriptor(obj, tableName);
3321
- if (!propDesc || ("value" in propDesc && propDesc.value === undefined)) {
3322
- if (obj === db.Transaction.prototype || obj instanceof db.Transaction) {
3357
+ if (!propDesc || ("value" in propDesc && (propDesc.value === undefined || propDesc.value instanceof Table))) {
3358
+ if (obj instanceof Transaction) {
3323
3359
  setProp(obj, tableName, {
3324
3360
  get: function () { return this.table(tableName); },
3325
3361
  set: function (value) {
@@ -3327,20 +3363,22 @@ function setApiOnPlace(_a, objs, tableNames, dbschema) {
3327
3363
  }
3328
3364
  });
3329
3365
  }
3330
- else {
3331
- obj[tableName] = new db.Table(tableName, schema);
3366
+ else if (obj instanceof Dexie$1) {
3367
+ obj._allTables[tableName] = obj[tableName] = new obj.Table(tableName, schema);
3332
3368
  }
3333
3369
  }
3334
3370
  });
3335
3371
  });
3336
3372
  }
3337
- function removeTablesApi(_a, objs) {
3338
- var db = _a._novip;
3373
+ function removeTablesApi(objs) {
3339
3374
  objs.forEach(function (obj) {
3340
- for (var key in obj) {
3341
- if (obj[key] instanceof db.Table)
3342
- delete obj[key];
3343
- }
3375
+ (obj instanceof Dexie$1 ? [obj, obj._allTables] : [obj]).forEach(function (obj) {
3376
+ for (var key in obj) {
3377
+ if (obj[key] instanceof Table) {
3378
+ delete obj[key];
3379
+ }
3380
+ }
3381
+ });
3344
3382
  });
3345
3383
  }
3346
3384
  function lowerVersionFirst(a, b) {
@@ -3408,8 +3446,8 @@ function updateTablesAndIndexes(_a, oldVersion, trans, idbUpgradeTrans) {
3408
3446
  diff.del.forEach(function (table) {
3409
3447
  upgradeSchema_1[table] = oldSchema[table];
3410
3448
  });
3411
- removeTablesApi(db, [db.Transaction.prototype]);
3412
- setApiOnPlace(db, [db.Transaction.prototype], keys(upgradeSchema_1), upgradeSchema_1);
3449
+ removeTablesApi([db.Transaction.prototype]);
3450
+ setApiOnPlace([db.Transaction.prototype], keys(upgradeSchema_1), upgradeSchema_1);
3413
3451
  trans.schema = upgradeSchema_1;
3414
3452
  var contentUpgradeIsAsync_1 = isAsyncFunction(contentUpgrade);
3415
3453
  if (contentUpgradeIsAsync_1) {
@@ -3434,8 +3472,8 @@ function updateTablesAndIndexes(_a, oldVersion, trans, idbUpgradeTrans) {
3434
3472
  var newSchema = version._cfg.dbschema;
3435
3473
  deleteRemovedTables(newSchema, idbtrans);
3436
3474
  }
3437
- removeTablesApi(db, [db.Transaction.prototype]);
3438
- setApiOnPlace(db, [db.Transaction.prototype], db._storeNames, db._dbSchema);
3475
+ removeTablesApi([db.Transaction.prototype]);
3476
+ setApiOnPlace([db.Transaction.prototype], db._storeNames, db._dbSchema);
3439
3477
  trans.schema = db._dbSchema;
3440
3478
  });
3441
3479
  });
@@ -3547,7 +3585,7 @@ function readGlobalSchema(_a, idbdb, tmpTrans) {
3547
3585
  db.verno = idbdb.version / 10;
3548
3586
  var globalSchema = db._dbSchema = buildGlobalSchema(db, idbdb, tmpTrans);
3549
3587
  db._storeNames = slice(idbdb.objectStoreNames, 0);
3550
- setApiOnPlace(db, [db._allTables], keys(globalSchema), globalSchema);
3588
+ setApiOnPlace([db, db.vip], keys(globalSchema), globalSchema);
3551
3589
  }
3552
3590
  function verifyInstalledSchema(db, tmpTrans) {
3553
3591
  var installedSchema = buildGlobalSchema(db, db.idbdb, tmpTrans);
@@ -3612,7 +3650,7 @@ var Version = (function () {
3612
3650
  });
3613
3651
  };
3614
3652
  Version.prototype.stores = function (stores) {
3615
- var db = this.db;
3653
+ var db = this.db._novip;
3616
3654
  this._cfg.storesSource = this._cfg.storesSource ?
3617
3655
  extend(this._cfg.storesSource, stores) :
3618
3656
  stores;
@@ -3625,8 +3663,8 @@ var Version = (function () {
3625
3663
  version._parseStoresSpec(storesSpec, dbschema);
3626
3664
  });
3627
3665
  db._dbSchema = dbschema;
3628
- removeTablesApi(db, [db._allTables, db, db.Transaction.prototype]);
3629
- setApiOnPlace(db, [db._allTables, db, db.Transaction.prototype, this._cfg.tables], keys(dbschema), dbschema);
3666
+ removeTablesApi([db, db.vip, db.Transaction.prototype]);
3667
+ setApiOnPlace([db, db.vip, db.Transaction.prototype], keys(dbschema), dbschema);
3630
3668
  db._storeNames = keys(dbschema);
3631
3669
  return this;
3632
3670
  };
@@ -3644,7 +3682,6 @@ function createVersionConstructor(db) {
3644
3682
  version: versionNumber,
3645
3683
  storesSource: null,
3646
3684
  dbschema: {},
3647
- tables: {},
3648
3685
  contentUpgrade: null
3649
3686
  };
3650
3687
  });
@@ -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); };
@@ -4669,7 +4706,11 @@ var Dexie$1 = (function () {
4669
4706
  this.use(hooksMiddleware);
4670
4707
  this.use(observabilityMiddleware);
4671
4708
  this.use(cacheExistingValuesMiddleware);
4672
- this.vip = Object.create(this, { _vip: { value: true } });
4709
+ var vipDexie = Object.create(this);
4710
+ vipDexie._vip = true;
4711
+ vipDexie.Table = createTableConstructor(vipDexie);
4712
+ vipDexie._allTables = {};
4713
+ this.vip = vipDexie;
4673
4714
  addons.forEach(function (addon) { return addon(_this); });
4674
4715
  }
4675
4716
  Dexie.prototype.version = function (versionNumber) {
@@ -4869,7 +4910,7 @@ var Dexie$1 = (function () {
4869
4910
  };
4870
4911
  Dexie.prototype.table = function (tableName) {
4871
4912
  if (!hasOwn(this._allTables, tableName)) {
4872
- throw new exceptions.InvalidTable("Table " + tableName + " does not exist");
4913
+ throw new exceptions.InvalidTable("Table ".concat(tableName, " does not exist"));
4873
4914
  }
4874
4915
  return this._allTables[tableName];
4875
4916
  };
@@ -4943,8 +4984,9 @@ function liveQuery(querier) {
4943
4984
  }
4944
4985
  };
4945
4986
  var doQuery = function () {
4946
- if (querying || closed)
4987
+ if (querying || closed) {
4947
4988
  return;
4989
+ }
4948
4990
  accumMuts = {};
4949
4991
  var subscr = {};
4950
4992
  var ret = execute(subscr);
@@ -4955,8 +4997,9 @@ function liveQuery(querier) {
4955
4997
  querying = true;
4956
4998
  Promise.resolve(ret).then(function (result) {
4957
4999
  querying = false;
4958
- if (closed)
5000
+ if (closed) {
4959
5001
  return;
5002
+ }
4960
5003
  if (shouldNotify()) {
4961
5004
  doQuery();
4962
5005
  }
@@ -4966,9 +5009,11 @@ function liveQuery(querier) {
4966
5009
  observer.next && observer.next(result);
4967
5010
  }
4968
5011
  }, function (err) {
4969
- querying = false;
4970
- observer.error && observer.error(err);
4971
- subscription.unsubscribe();
5012
+ if (!['DatabaseClosedError', 'AbortError'].includes(err === null || err === void 0 ? void 0 : err.name)) {
5013
+ querying = false;
5014
+ observer.error && observer.error(err);
5015
+ subscription.unsubscribe();
5016
+ }
4972
5017
  });
4973
5018
  };
4974
5019
  doQuery();
@@ -5163,5 +5208,5 @@ function propagateMessageLocally(_a) {
5163
5208
  DexiePromise.rejectionMapper = mapError;
5164
5209
  setDebug(debug, dexieStackFrameFilter);
5165
5210
 
5166
- export { Dexie$1 as Dexie, RangeSet, Dexie$1 as default, liveQuery, mergeRanges, rangesOverlap };
5211
+ export { Dexie$1 as Dexie, Entity, RangeSet, cmp, Dexie$1 as default, liveQuery, mergeRanges, rangesOverlap };
5167
5212
  //# sourceMappingURL=dexie.mjs.map