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.
@@ -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
  *
@@ -144,7 +144,7 @@ function setByKeyPath(obj, keyPath, value) {
144
144
  obj[currentKeyPath] = value;
145
145
  else {
146
146
  var innerObj = obj[currentKeyPath];
147
- if (!innerObj)
147
+ if (!innerObj || !hasOwn(obj, currentKeyPath))
148
148
  innerObj = (obj[currentKeyPath] = {});
149
149
  setByKeyPath(innerObj, remainingKeyPath, value);
150
150
  }
@@ -1242,7 +1242,7 @@ function tempTransaction(db, mode, storeNames, fn) {
1242
1242
  }
1243
1243
  }
1244
1244
 
1245
- const DEXIE_VERSION = '3.2.1';
1245
+ const DEXIE_VERSION = '4.0.0-alpha.3';
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
  }
@@ -4851,8 +4866,9 @@ function liveQuery(querier) {
4851
4866
  }
4852
4867
  };
4853
4868
  const doQuery = () => {
4854
- if (querying || closed)
4869
+ if (querying || closed) {
4855
4870
  return;
4871
+ }
4856
4872
  accumMuts = {};
4857
4873
  const subscr = {};
4858
4874
  const ret = execute(subscr);
@@ -4863,8 +4879,9 @@ function liveQuery(querier) {
4863
4879
  querying = true;
4864
4880
  Promise.resolve(ret).then((result) => {
4865
4881
  querying = false;
4866
- if (closed)
4882
+ if (closed) {
4867
4883
  return;
4884
+ }
4868
4885
  if (shouldNotify()) {
4869
4886
  doQuery();
4870
4887
  }
@@ -4874,9 +4891,11 @@ function liveQuery(querier) {
4874
4891
  observer.next && observer.next(result);
4875
4892
  }
4876
4893
  }, (err) => {
4877
- querying = false;
4878
- observer.error && observer.error(err);
4879
- subscription.unsubscribe();
4894
+ if (!['DatabaseClosedError', 'AbortError'].includes(err === null || err === void 0 ? void 0 : err.name)) {
4895
+ querying = false;
4896
+ observer.error && observer.error(err);
4897
+ subscription.unsubscribe();
4898
+ }
4880
4899
  });
4881
4900
  };
4882
4901
  doQuery();
@@ -5067,13 +5086,15 @@ else if (typeof self !== 'undefined' && typeof navigator !== 'undefined') {
5067
5086
  }
5068
5087
  catch (_a) { }
5069
5088
  });
5070
- addEventListener('storage', (ev) => {
5071
- if (ev.key === STORAGE_MUTATED_DOM_EVENT_NAME) {
5072
- const data = JSON.parse(ev.newValue);
5073
- if (data)
5074
- propagateLocally(data.changedParts);
5075
- }
5076
- });
5089
+ if (typeof addEventListener !== 'undefined') {
5090
+ addEventListener('storage', (ev) => {
5091
+ if (ev.key === STORAGE_MUTATED_DOM_EVENT_NAME) {
5092
+ const data = JSON.parse(ev.newValue);
5093
+ if (data)
5094
+ propagateLocally(data.changedParts);
5095
+ }
5096
+ });
5097
+ }
5077
5098
  const swContainer = self.document && navigator.serviceWorker;
5078
5099
  if (swContainer) {
5079
5100
  swContainer.addEventListener('message', propagateMessageLocally);
@@ -5088,5 +5109,5 @@ function propagateMessageLocally({ data }) {
5088
5109
  DexiePromise.rejectionMapper = mapError;
5089
5110
  setDebug(debug, dexieStackFrameFilter);
5090
5111
 
5091
- export { Dexie$1 as Dexie, RangeSet, Dexie$1 as default, liveQuery, mergeRanges, rangesOverlap };
5112
+ export { Dexie$1 as Dexie, Entity, RangeSet, cmp, Dexie$1 as default, liveQuery, mergeRanges, rangesOverlap };
5092
5113
  //# sourceMappingURL=dexie.mjs.map