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.
@@ -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
  *
@@ -1242,7 +1242,7 @@ function tempTransaction(db, mode, storeNames, fn) {
1242
1242
  }
1243
1243
  }
1244
1244
 
1245
- const DEXIE_VERSION = '3.2.1-beta.2';
1245
+ const DEXIE_VERSION = '4.0.0-alpha.2';
1246
1246
  const maxString = String.fromCharCode(65535);
1247
1247
  const minKey = -Infinity;
1248
1248
  const INVALID_KEY_ARGUMENT = "Invalid key provided. Keys must be of type string, number, Date or Array<string | number | Date>.";
@@ -1284,6 +1284,10 @@ function workaroundForUndefinedPrimKey(keyPath) {
1284
1284
  : (obj) => obj;
1285
1285
  }
1286
1286
 
1287
+ function Entity() {
1288
+ throw exceptions.Type();
1289
+ }
1290
+
1287
1291
  class Table {
1288
1292
  _trans(mode, fn, writeLocked) {
1289
1293
  const trans = this._tx || PSD.trans;
@@ -1395,13 +1399,24 @@ class Table {
1395
1399
  return this.toCollection().reverse();
1396
1400
  }
1397
1401
  mapToClass(constructor) {
1402
+ const { db, name: tableName } = this;
1398
1403
  this.schema.mappedClass = constructor;
1399
- const readHook = obj => {
1404
+ if (constructor.prototype instanceof Entity) {
1405
+ constructor = class extends constructor {
1406
+ get db() { return db; }
1407
+ table() { return tableName; }
1408
+ };
1409
+ }
1410
+ const inheritedProps = new Set();
1411
+ for (let proto = constructor.prototype; proto; proto = getProto(proto)) {
1412
+ Object.getOwnPropertyNames(proto).forEach(propName => inheritedProps.add(propName));
1413
+ }
1414
+ const readHook = (obj) => {
1400
1415
  if (!obj)
1401
1416
  return obj;
1402
1417
  const res = Object.create(constructor.prototype);
1403
- for (var m in obj)
1404
- if (hasOwn(obj, m))
1418
+ for (let m in obj)
1419
+ if (!inheritedProps.has(m))
1405
1420
  try {
1406
1421
  res[m] = obj[m];
1407
1422
  }
@@ -3207,19 +3222,19 @@ function generateMiddlewareStacks({ _novip: db }, tmpTrans) {
3207
3222
  if (db.core.schema.tables.some(tbl => tbl.name === tableName)) {
3208
3223
  table.core = db.core.table(tableName);
3209
3224
  if (db[tableName] instanceof db.Table) {
3210
- db[tableName].core = table.core;
3225
+ db[tableName].core = db.vip[tableName].core = table.core;
3211
3226
  }
3212
3227
  }
3213
3228
  });
3214
3229
  }
3215
3230
 
3216
- function setApiOnPlace({ _novip: db }, objs, tableNames, dbschema) {
3231
+ function setApiOnPlace(objs, tableNames, dbschema) {
3217
3232
  tableNames.forEach(tableName => {
3218
3233
  const schema = dbschema[tableName];
3219
3234
  objs.forEach(obj => {
3220
3235
  const propDesc = getPropertyDescriptor(obj, tableName);
3221
- if (!propDesc || ("value" in propDesc && propDesc.value === undefined)) {
3222
- if (obj === db.Transaction.prototype || obj instanceof db.Transaction) {
3236
+ if (!propDesc || ("value" in propDesc && (propDesc.value === undefined || propDesc.value instanceof Table))) {
3237
+ if (obj instanceof Transaction) {
3223
3238
  setProp(obj, tableName, {
3224
3239
  get() { return this.table(tableName); },
3225
3240
  set(value) {
@@ -3227,19 +3242,22 @@ function setApiOnPlace({ _novip: db }, objs, tableNames, dbschema) {
3227
3242
  }
3228
3243
  });
3229
3244
  }
3230
- else {
3231
- obj[tableName] = new db.Table(tableName, schema);
3245
+ else if (obj instanceof Dexie$1) {
3246
+ obj._allTables[tableName] = obj[tableName] = new obj.Table(tableName, schema);
3232
3247
  }
3233
3248
  }
3234
3249
  });
3235
3250
  });
3236
3251
  }
3237
- function removeTablesApi({ _novip: db }, objs) {
3252
+ function removeTablesApi(objs) {
3238
3253
  objs.forEach(obj => {
3239
- for (let key in obj) {
3240
- if (obj[key] instanceof db.Table)
3241
- delete obj[key];
3242
- }
3254
+ (obj instanceof Dexie$1 ? [obj, obj._allTables] : [obj]).forEach((obj) => {
3255
+ for (let key in obj) {
3256
+ if (obj[key] instanceof Table) {
3257
+ delete obj[key];
3258
+ }
3259
+ }
3260
+ });
3243
3261
  });
3244
3262
  }
3245
3263
  function lowerVersionFirst(a, b) {
@@ -3306,8 +3324,8 @@ function updateTablesAndIndexes({ _novip: db }, oldVersion, trans, idbUpgradeTra
3306
3324
  diff.del.forEach(table => {
3307
3325
  upgradeSchema[table] = oldSchema[table];
3308
3326
  });
3309
- removeTablesApi(db, [db.Transaction.prototype]);
3310
- setApiOnPlace(db, [db.Transaction.prototype], keys(upgradeSchema), upgradeSchema);
3327
+ removeTablesApi([db.Transaction.prototype]);
3328
+ setApiOnPlace([db.Transaction.prototype], keys(upgradeSchema), upgradeSchema);
3311
3329
  trans.schema = upgradeSchema;
3312
3330
  const contentUpgradeIsAsync = isAsyncFunction(contentUpgrade);
3313
3331
  if (contentUpgradeIsAsync) {
@@ -3332,8 +3350,8 @@ function updateTablesAndIndexes({ _novip: db }, oldVersion, trans, idbUpgradeTra
3332
3350
  const newSchema = version._cfg.dbschema;
3333
3351
  deleteRemovedTables(newSchema, idbtrans);
3334
3352
  }
3335
- removeTablesApi(db, [db.Transaction.prototype]);
3336
- setApiOnPlace(db, [db.Transaction.prototype], db._storeNames, db._dbSchema);
3353
+ removeTablesApi([db.Transaction.prototype]);
3354
+ setApiOnPlace([db.Transaction.prototype], db._storeNames, db._dbSchema);
3337
3355
  trans.schema = db._dbSchema;
3338
3356
  });
3339
3357
  });
@@ -3442,7 +3460,7 @@ function readGlobalSchema({ _novip: db }, idbdb, tmpTrans) {
3442
3460
  db.verno = idbdb.version / 10;
3443
3461
  const globalSchema = db._dbSchema = buildGlobalSchema(db, idbdb, tmpTrans);
3444
3462
  db._storeNames = slice(idbdb.objectStoreNames, 0);
3445
- setApiOnPlace(db, [db._allTables], keys(globalSchema), globalSchema);
3463
+ setApiOnPlace([db, db.vip], keys(globalSchema), globalSchema);
3446
3464
  }
3447
3465
  function verifyInstalledSchema(db, tmpTrans) {
3448
3466
  const installedSchema = buildGlobalSchema(db, db.idbdb, tmpTrans);
@@ -3504,7 +3522,7 @@ class Version {
3504
3522
  });
3505
3523
  }
3506
3524
  stores(stores) {
3507
- const db = this.db;
3525
+ const db = this.db._novip;
3508
3526
  this._cfg.storesSource = this._cfg.storesSource ?
3509
3527
  extend(this._cfg.storesSource, stores) :
3510
3528
  stores;
@@ -3517,8 +3535,8 @@ class Version {
3517
3535
  version._parseStoresSpec(storesSpec, dbschema);
3518
3536
  });
3519
3537
  db._dbSchema = dbschema;
3520
- removeTablesApi(db, [db._allTables, db, db.Transaction.prototype]);
3521
- setApiOnPlace(db, [db._allTables, db, db.Transaction.prototype, this._cfg.tables], keys(dbschema), dbschema);
3538
+ removeTablesApi([db, db.vip, db.Transaction.prototype]);
3539
+ setApiOnPlace([db, db.vip, db.Transaction.prototype], keys(dbschema), dbschema);
3522
3540
  db._storeNames = keys(dbschema);
3523
3541
  return this;
3524
3542
  }
@@ -3535,7 +3553,6 @@ function createVersionConstructor(db) {
3535
3553
  version: versionNumber,
3536
3554
  storesSource: null,
3537
3555
  dbschema: {},
3538
- tables: {},
3539
3556
  contentUpgrade: null
3540
3557
  };
3541
3558
  });
@@ -4593,7 +4610,11 @@ class Dexie$1 {
4593
4610
  this.use(hooksMiddleware);
4594
4611
  this.use(observabilityMiddleware);
4595
4612
  this.use(cacheExistingValuesMiddleware);
4596
- this.vip = Object.create(this, { _vip: { value: true } });
4613
+ const vipDexie = Object.create(this);
4614
+ vipDexie._vip = true;
4615
+ vipDexie.Table = createTableConstructor(vipDexie);
4616
+ vipDexie._allTables = {};
4617
+ this.vip = vipDexie;
4597
4618
  addons.forEach(addon => addon(this));
4598
4619
  }
4599
4620
  version(versionNumber) {
@@ -4851,8 +4872,9 @@ function liveQuery(querier) {
4851
4872
  }
4852
4873
  };
4853
4874
  const doQuery = () => {
4854
- if (querying || closed)
4875
+ if (querying || closed) {
4855
4876
  return;
4877
+ }
4856
4878
  accumMuts = {};
4857
4879
  const subscr = {};
4858
4880
  const ret = execute(subscr);
@@ -4863,8 +4885,9 @@ function liveQuery(querier) {
4863
4885
  querying = true;
4864
4886
  Promise.resolve(ret).then((result) => {
4865
4887
  querying = false;
4866
- if (closed)
4888
+ if (closed) {
4867
4889
  return;
4890
+ }
4868
4891
  if (shouldNotify()) {
4869
4892
  doQuery();
4870
4893
  }
@@ -4874,9 +4897,11 @@ function liveQuery(querier) {
4874
4897
  observer.next && observer.next(result);
4875
4898
  }
4876
4899
  }, (err) => {
4877
- querying = false;
4878
- observer.error && observer.error(err);
4879
- subscription.unsubscribe();
4900
+ if (!['DatabaseClosedError', 'AbortError'].includes(err === null || err === void 0 ? void 0 : err.name)) {
4901
+ querying = false;
4902
+ observer.error && observer.error(err);
4903
+ subscription.unsubscribe();
4904
+ }
4880
4905
  });
4881
4906
  };
4882
4907
  doQuery();
@@ -5088,5 +5113,5 @@ function propagateMessageLocally({ data }) {
5088
5113
  DexiePromise.rejectionMapper = mapError;
5089
5114
  setDebug(debug, dexieStackFrameFilter);
5090
5115
 
5091
- export { Dexie$1 as Dexie, RangeSet, Dexie$1 as default, liveQuery, mergeRanges, rangesOverlap };
5116
+ export { Dexie$1 as Dexie, Entity, RangeSet, cmp, Dexie$1 as default, liveQuery, mergeRanges, rangesOverlap };
5092
5117
  //# sourceMappingURL=dexie.mjs.map