dexie 4.0.1-beta.6 → 4.0.1-beta.7

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.0.1-beta.6, Mon Dec 18 2023
7
+ * Version 4.0.1-beta.7, Wed Jan 31 2024
8
8
  *
9
9
  * https://dexie.org
10
10
  *
@@ -1120,7 +1120,7 @@ export type InsertType<T, OptionalProps extends keyof T> = Omit<T, OptionalProps
1120
1120
  export type IDType<T, TKeyPropNameOrKeyType> = IsStrictlyAny<T> extends true ? TKeyPropNameOrKeyType : TKeyPropNameOrKeyType extends string ? TKeyPropNameOrKeyType extends keyof T ? T[TKeyPropNameOrKeyType] : TKeyPropNameOrKeyType : TKeyPropNameOrKeyType;
1121
1121
  export type EntityTable<T, TKeyPropName extends keyof T = never, TInsertType = InsertType<T, TKeyPropName>> = Table<T, IDType<T, TKeyPropName>, TInsertType>;
1122
1122
  export declare var Dexie: DexieConstructor;
1123
- export interface _Table<T, TKey> extends Table<T, TKey> {
1123
+ export interface _Table<T, TKey, TInsertType> extends Table<T, TKey, TInsertType> {
1124
1124
  }
1125
1125
  export interface _Collection<T, TKey> extends Collection<T, TKey> {
1126
1126
  }
@@ -1128,7 +1128,7 @@ export declare module Dexie {
1128
1128
  // The "Dexie.Promise" type.
1129
1129
  type Promise<T = any> = PromiseExtended<T>; // Because many samples have been Dexie.Promise.
1130
1130
  // The "Dexie.Table" interface. Same as named exported interface Table.
1131
- interface Table<T = any, Key = any> extends _Table<T, Key> {
1131
+ interface Table<T = any, Key = any, TInsertType = T> extends _Table<T, Key, TInsertType> {
1132
1132
  } // Because all samples have been Dexie.Table<...>
1133
1133
  // The "Dexie.Collection" interface. Same as named exported interface Collection.
1134
1134
  interface Collection<T = any, Key = any> extends _Collection<T, Key> {
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.0.1-beta.6, Mon Dec 18 2023
7
+ * Version 4.0.1-beta.7, Wed Jan 31 2024
8
8
  *
9
9
  * https://dexie.org
10
10
  *
@@ -1271,7 +1271,7 @@
1271
1271
  }
1272
1272
  }
1273
1273
 
1274
- var DEXIE_VERSION = '4.0.1-beta.6';
1274
+ var DEXIE_VERSION = '4.0.1-beta.7';
1275
1275
  var maxString = String.fromCharCode(65535);
1276
1276
  var minKey = -Infinity;
1277
1277
  var INVALID_KEY_ARGUMENT = "Invalid key provided. Keys must be of type string, number, Date or Array<string | number | Date>.";
@@ -1454,7 +1454,7 @@
1454
1454
  .equals(keyPathsInValidOrder.map(function (kp) { return indexOrCrit[kp]; }));
1455
1455
  }
1456
1456
  if (!compoundIndex && debug)
1457
- console.warn("The query ".concat(JSON.stringify(indexOrCrit), " on ").concat(this.name, " would benefit of a ") +
1457
+ console.warn("The query ".concat(JSON.stringify(indexOrCrit), " on ").concat(this.name, " would benefit from a ") +
1458
1458
  "compound index [".concat(keyPaths.join('+'), "]"));
1459
1459
  var idxByName = this.schema.idxByName;
1460
1460
  var idb = this.db._deps.indexedDB;
@@ -3591,7 +3591,7 @@
3591
3591
  dbStoreNames.forEach(function (storeName) {
3592
3592
  var store = tmpTrans.objectStore(storeName);
3593
3593
  var keyPath = store.keyPath;
3594
- var primKey = createIndexSpec(nameFromKeyPath(keyPath), keyPath || "", false, false, !!store.autoIncrement, keyPath && typeof keyPath !== "string", true);
3594
+ var primKey = createIndexSpec(nameFromKeyPath(keyPath), keyPath || "", true, false, !!store.autoIncrement, keyPath && typeof keyPath !== "string", true);
3595
3595
  var indexes = [];
3596
3596
  for (var j = 0; j < store.indexNames.length; ++j) {
3597
3597
  var idbindex = store.index(store.indexNames[j]);
@@ -3658,6 +3658,7 @@
3658
3658
  if (stores[tableName] !== null) {
3659
3659
  var indexes = parseIndexSyntax(stores[tableName]);
3660
3660
  var primKey = indexes.shift();
3661
+ primKey.unique = true;
3661
3662
  if (primKey.multi)
3662
3663
  throw new exceptions.Schema("Primary key cannot be multi-valued");
3663
3664
  indexes.forEach(function (idx) {
@@ -3941,7 +3942,7 @@
3941
3942
  }
3942
3943
 
3943
3944
  function obsSetsOverlap(os1, os2) {
3944
- return Object.keys(os1).some(function (key) { return os2[key] && rangesOverlap(os2[key], os1[key]); });
3945
+ return os1.all || os2.all || Object.keys(os1).some(function (key) { return os2[key] && rangesOverlap(os2[key], os1[key]); });
3945
3946
  }
3946
3947
 
3947
3948
  var cache = {};
@@ -3963,13 +3964,21 @@
3963
3964
  function signalSubscribersNow(updatedParts, deleteAffectedCacheEntries) {
3964
3965
  if (deleteAffectedCacheEntries === void 0) { deleteAffectedCacheEntries = false; }
3965
3966
  var queriesToSignal = new Set();
3966
- for (var key in updatedParts) {
3967
- var parts = /^idb\:\/\/(.*)\/(.*)\//.exec(key);
3968
- if (parts) {
3969
- var dbName = parts[1], tableName = parts[2];
3970
- var tblCache = cache["idb://".concat(dbName, "/").concat(tableName)];
3971
- if (tblCache)
3972
- signalTableSubscribersNow(tblCache, updatedParts, queriesToSignal, deleteAffectedCacheEntries);
3967
+ if (updatedParts.all) {
3968
+ for (var _i = 0, _a = Object.values(cache); _i < _a.length; _i++) {
3969
+ var tblCache = _a[_i];
3970
+ signalTableSubscribersNow(tblCache, updatedParts, queriesToSignal, deleteAffectedCacheEntries);
3971
+ }
3972
+ }
3973
+ else {
3974
+ for (var key in updatedParts) {
3975
+ var parts = /^idb\:\/\/(.*)\/(.*)\//.exec(key);
3976
+ if (parts) {
3977
+ var dbName = parts[1], tableName = parts[2];
3978
+ var tblCache = cache["idb://".concat(dbName, "/").concat(tableName)];
3979
+ if (tblCache)
3980
+ signalTableSubscribersNow(tblCache, updatedParts, queriesToSignal, deleteAffectedCacheEntries);
3981
+ }
3973
3982
  }
3974
3983
  }
3975
3984
  queriesToSignal.forEach(function (requery) { return requery(); });
@@ -4811,6 +4820,8 @@
4811
4820
  if (!ops || ops.length === 0)
4812
4821
  return result;
4813
4822
  var index = req.query.index;
4823
+ var multiEntry = index.multiEntry;
4824
+ var queryRange = req.query.range;
4814
4825
  var primaryKey = table.schema.primaryKey;
4815
4826
  var extractPrimKey = primaryKey.extractKey;
4816
4827
  var extractIndex = index.extractKey;
@@ -4819,7 +4830,10 @@
4819
4830
  var modifedResult = result;
4820
4831
  var includedValues = op.type === 'add' || op.type === 'put'
4821
4832
  ? op.values.filter(function (v) {
4822
- return isWithinRange(extractIndex(v), req.query.range);
4833
+ var key = extractIndex(v);
4834
+ return multiEntry && isArray(key)
4835
+ ? key.some(function (k) { return isWithinRange(k, queryRange); })
4836
+ : isWithinRange(key, queryRange);
4823
4837
  }).map(function (v) {
4824
4838
  v = deepClone(v);
4825
4839
  if (immutable)
@@ -5749,62 +5763,40 @@
5749
5763
  }
5750
5764
  var propagatingLocally = false;
5751
5765
 
5766
+ var bc;
5767
+ var createBC = function () { };
5752
5768
  if (typeof BroadcastChannel !== 'undefined') {
5753
- var bc_1 = new BroadcastChannel(STORAGE_MUTATED_DOM_EVENT_NAME);
5754
- if (typeof bc_1.unref === 'function') {
5755
- bc_1.unref();
5769
+ createBC = function () {
5770
+ bc = new BroadcastChannel(STORAGE_MUTATED_DOM_EVENT_NAME);
5771
+ bc.onmessage = function (ev) { return ev.data && propagateLocally(ev.data); };
5772
+ };
5773
+ createBC();
5774
+ if (typeof bc.unref === 'function') {
5775
+ bc.unref();
5756
5776
  }
5757
5777
  globalEvents(DEXIE_STORAGE_MUTATED_EVENT_NAME, function (changedParts) {
5758
5778
  if (!propagatingLocally) {
5759
- bc_1.postMessage(changedParts);
5779
+ bc.postMessage(changedParts);
5760
5780
  }
5761
5781
  });
5762
- bc_1.onmessage = function (ev) {
5763
- if (ev.data)
5764
- propagateLocally(ev.data);
5765
- };
5766
5782
  }
5767
- else if (typeof self !== 'undefined' && typeof navigator !== 'undefined') {
5768
- globalEvents(DEXIE_STORAGE_MUTATED_EVENT_NAME, function (changedParts) {
5769
- try {
5770
- if (!propagatingLocally) {
5771
- if (typeof localStorage !== 'undefined') {
5772
- localStorage.setItem(STORAGE_MUTATED_DOM_EVENT_NAME, JSON.stringify({
5773
- trig: Math.random(),
5774
- changedParts: changedParts,
5775
- }));
5776
- }
5777
- if (typeof self['clients'] === 'object') {
5778
- __spreadArray([], self['clients'].matchAll({ includeUncontrolled: true }), true).forEach(function (client) {
5779
- return client.postMessage({
5780
- type: STORAGE_MUTATED_DOM_EVENT_NAME,
5781
- changedParts: changedParts,
5782
- });
5783
- });
5784
- }
5785
- }
5783
+
5784
+ if (typeof addEventListener !== 'undefined') {
5785
+ addEventListener('pagehide', function (event) {
5786
+ if (event.persisted) {
5787
+ bc === null || bc === void 0 ? void 0 : bc.close();
5788
+ }
5789
+ for (var _i = 0, connections_1 = connections; _i < connections_1.length; _i++) {
5790
+ var db = connections_1[_i];
5791
+ db.close({ disableAutoOpen: false });
5792
+ }
5793
+ });
5794
+ addEventListener('pageshow', function (event) {
5795
+ if (event.persisted) {
5796
+ createBC();
5797
+ propagateLocally({ all: new RangeSet(-Infinity, [[]]) });
5786
5798
  }
5787
- catch (_a) { }
5788
5799
  });
5789
- if (typeof addEventListener !== 'undefined') {
5790
- addEventListener('storage', function (ev) {
5791
- if (ev.key === STORAGE_MUTATED_DOM_EVENT_NAME) {
5792
- var data = JSON.parse(ev.newValue);
5793
- if (data)
5794
- propagateLocally(data.changedParts);
5795
- }
5796
- });
5797
- }
5798
- var swContainer = self.document && navigator.serviceWorker;
5799
- if (swContainer) {
5800
- swContainer.addEventListener('message', propagateMessageLocally);
5801
- }
5802
- }
5803
- function propagateMessageLocally(_a) {
5804
- var data = _a.data;
5805
- if (data && data.type === STORAGE_MUTATED_DOM_EVENT_NAME) {
5806
- propagateLocally(data.changedParts);
5807
- }
5808
5800
  }
5809
5801
 
5810
5802
  DexiePromise.rejectionMapper = mapError;