dexie 4.0.1-alpha.21 → 4.0.1-alpha.23
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/README.md +1 -1
- package/dist/dexie.d.ts +4 -2
- package/dist/dexie.js +266 -249
- package/dist/dexie.js.map +1 -1
- package/dist/dexie.min.js +1 -1
- package/dist/dexie.min.js.map +1 -1
- package/dist/dexie.mjs +266 -249
- package/dist/dexie.mjs.map +1 -1
- package/dist/modern/dexie.min.mjs +1 -1
- package/dist/modern/dexie.min.mjs.map +1 -1
- package/dist/modern/dexie.mjs +256 -240
- package/dist/modern/dexie.mjs.map +1 -1
- package/package.json +6 -2
- package/dist/README.md +0 -46
package/dist/modern/dexie.mjs
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*
|
|
5
5
|
* By David Fahlander, david.fahlander@gmail.com
|
|
6
6
|
*
|
|
7
|
-
* Version 4.0.1-alpha.
|
|
7
|
+
* Version 4.0.1-alpha.23, Tue Jul 04 2023
|
|
8
8
|
*
|
|
9
9
|
* https://dexie.org
|
|
10
10
|
*
|
|
@@ -1226,7 +1226,7 @@ function tempTransaction(db, mode, storeNames, fn) {
|
|
|
1226
1226
|
}
|
|
1227
1227
|
}
|
|
1228
1228
|
|
|
1229
|
-
const DEXIE_VERSION = '4.0.1-alpha.
|
|
1229
|
+
const DEXIE_VERSION = '4.0.1-alpha.23';
|
|
1230
1230
|
const maxString = String.fromCharCode(65535);
|
|
1231
1231
|
const minKey = -Infinity;
|
|
1232
1232
|
const INVALID_KEY_ARGUMENT = "Invalid key provided. Keys must be of type string, number, Date or Array<string | number | Date>.";
|
|
@@ -3642,6 +3642,228 @@ function idbReady() {
|
|
|
3642
3642
|
}).finally(function () { return clearInterval(intervalId); });
|
|
3643
3643
|
}
|
|
3644
3644
|
|
|
3645
|
+
function isEmptyRange(node) {
|
|
3646
|
+
return !("from" in node);
|
|
3647
|
+
}
|
|
3648
|
+
const RangeSet = function (fromOrTree, to) {
|
|
3649
|
+
if (this) {
|
|
3650
|
+
extend(this, arguments.length ? { d: 1, from: fromOrTree, to: arguments.length > 1 ? to : fromOrTree } : { d: 0 });
|
|
3651
|
+
}
|
|
3652
|
+
else {
|
|
3653
|
+
const rv = new RangeSet();
|
|
3654
|
+
if (fromOrTree && ("d" in fromOrTree)) {
|
|
3655
|
+
extend(rv, fromOrTree);
|
|
3656
|
+
}
|
|
3657
|
+
return rv;
|
|
3658
|
+
}
|
|
3659
|
+
};
|
|
3660
|
+
props(RangeSet.prototype, {
|
|
3661
|
+
add(rangeSet) {
|
|
3662
|
+
mergeRanges(this, rangeSet);
|
|
3663
|
+
return this;
|
|
3664
|
+
},
|
|
3665
|
+
addKey(key) {
|
|
3666
|
+
addRange(this, key, key);
|
|
3667
|
+
return this;
|
|
3668
|
+
},
|
|
3669
|
+
addKeys(keys) {
|
|
3670
|
+
keys.forEach(key => addRange(this, key, key));
|
|
3671
|
+
return this;
|
|
3672
|
+
},
|
|
3673
|
+
[iteratorSymbol]() {
|
|
3674
|
+
return getRangeSetIterator(this);
|
|
3675
|
+
}
|
|
3676
|
+
});
|
|
3677
|
+
function addRange(target, from, to) {
|
|
3678
|
+
const diff = cmp(from, to);
|
|
3679
|
+
if (isNaN(diff))
|
|
3680
|
+
return;
|
|
3681
|
+
if (diff > 0)
|
|
3682
|
+
throw RangeError();
|
|
3683
|
+
if (isEmptyRange(target))
|
|
3684
|
+
return extend(target, { from, to, d: 1 });
|
|
3685
|
+
const left = target.l;
|
|
3686
|
+
const right = target.r;
|
|
3687
|
+
if (cmp(to, target.from) < 0) {
|
|
3688
|
+
left
|
|
3689
|
+
? addRange(left, from, to)
|
|
3690
|
+
: (target.l = { from, to, d: 1, l: null, r: null });
|
|
3691
|
+
return rebalance(target);
|
|
3692
|
+
}
|
|
3693
|
+
if (cmp(from, target.to) > 0) {
|
|
3694
|
+
right
|
|
3695
|
+
? addRange(right, from, to)
|
|
3696
|
+
: (target.r = { from, to, d: 1, l: null, r: null });
|
|
3697
|
+
return rebalance(target);
|
|
3698
|
+
}
|
|
3699
|
+
if (cmp(from, target.from) < 0) {
|
|
3700
|
+
target.from = from;
|
|
3701
|
+
target.l = null;
|
|
3702
|
+
target.d = right ? right.d + 1 : 1;
|
|
3703
|
+
}
|
|
3704
|
+
if (cmp(to, target.to) > 0) {
|
|
3705
|
+
target.to = to;
|
|
3706
|
+
target.r = null;
|
|
3707
|
+
target.d = target.l ? target.l.d + 1 : 1;
|
|
3708
|
+
}
|
|
3709
|
+
const rightWasCutOff = !target.r;
|
|
3710
|
+
if (left && !target.l) {
|
|
3711
|
+
mergeRanges(target, left);
|
|
3712
|
+
}
|
|
3713
|
+
if (right && rightWasCutOff) {
|
|
3714
|
+
mergeRanges(target, right);
|
|
3715
|
+
}
|
|
3716
|
+
}
|
|
3717
|
+
function mergeRanges(target, newSet) {
|
|
3718
|
+
function _addRangeSet(target, { from, to, l, r }) {
|
|
3719
|
+
addRange(target, from, to);
|
|
3720
|
+
if (l)
|
|
3721
|
+
_addRangeSet(target, l);
|
|
3722
|
+
if (r)
|
|
3723
|
+
_addRangeSet(target, r);
|
|
3724
|
+
}
|
|
3725
|
+
if (!isEmptyRange(newSet))
|
|
3726
|
+
_addRangeSet(target, newSet);
|
|
3727
|
+
}
|
|
3728
|
+
function rangesOverlap(rangeSet1, rangeSet2) {
|
|
3729
|
+
const i1 = getRangeSetIterator(rangeSet2);
|
|
3730
|
+
let nextResult1 = i1.next();
|
|
3731
|
+
if (nextResult1.done)
|
|
3732
|
+
return false;
|
|
3733
|
+
let a = nextResult1.value;
|
|
3734
|
+
const i2 = getRangeSetIterator(rangeSet1);
|
|
3735
|
+
let nextResult2 = i2.next(a.from);
|
|
3736
|
+
let b = nextResult2.value;
|
|
3737
|
+
while (!nextResult1.done && !nextResult2.done) {
|
|
3738
|
+
if (cmp(b.from, a.to) <= 0 && cmp(b.to, a.from) >= 0)
|
|
3739
|
+
return true;
|
|
3740
|
+
cmp(a.from, b.from) < 0
|
|
3741
|
+
? (a = (nextResult1 = i1.next(b.from)).value)
|
|
3742
|
+
: (b = (nextResult2 = i2.next(a.from)).value);
|
|
3743
|
+
}
|
|
3744
|
+
return false;
|
|
3745
|
+
}
|
|
3746
|
+
function getRangeSetIterator(node) {
|
|
3747
|
+
let state = isEmptyRange(node) ? null : { s: 0, n: node };
|
|
3748
|
+
return {
|
|
3749
|
+
next(key) {
|
|
3750
|
+
const keyProvided = arguments.length > 0;
|
|
3751
|
+
while (state) {
|
|
3752
|
+
switch (state.s) {
|
|
3753
|
+
case 0:
|
|
3754
|
+
state.s = 1;
|
|
3755
|
+
if (keyProvided) {
|
|
3756
|
+
while (state.n.l && cmp(key, state.n.from) < 0)
|
|
3757
|
+
state = { up: state, n: state.n.l, s: 1 };
|
|
3758
|
+
}
|
|
3759
|
+
else {
|
|
3760
|
+
while (state.n.l)
|
|
3761
|
+
state = { up: state, n: state.n.l, s: 1 };
|
|
3762
|
+
}
|
|
3763
|
+
case 1:
|
|
3764
|
+
state.s = 2;
|
|
3765
|
+
if (!keyProvided || cmp(key, state.n.to) <= 0)
|
|
3766
|
+
return { value: state.n, done: false };
|
|
3767
|
+
case 2:
|
|
3768
|
+
if (state.n.r) {
|
|
3769
|
+
state.s = 3;
|
|
3770
|
+
state = { up: state, n: state.n.r, s: 0 };
|
|
3771
|
+
continue;
|
|
3772
|
+
}
|
|
3773
|
+
case 3:
|
|
3774
|
+
state = state.up;
|
|
3775
|
+
}
|
|
3776
|
+
}
|
|
3777
|
+
return { done: true };
|
|
3778
|
+
},
|
|
3779
|
+
};
|
|
3780
|
+
}
|
|
3781
|
+
function rebalance(target) {
|
|
3782
|
+
var _a, _b;
|
|
3783
|
+
const diff = (((_a = target.r) === null || _a === void 0 ? void 0 : _a.d) || 0) - (((_b = target.l) === null || _b === void 0 ? void 0 : _b.d) || 0);
|
|
3784
|
+
const r = diff > 1 ? "r" : diff < -1 ? "l" : "";
|
|
3785
|
+
if (r) {
|
|
3786
|
+
const l = r === "r" ? "l" : "r";
|
|
3787
|
+
const rootClone = { ...target };
|
|
3788
|
+
const oldRootRight = target[r];
|
|
3789
|
+
target.from = oldRootRight.from;
|
|
3790
|
+
target.to = oldRootRight.to;
|
|
3791
|
+
target[r] = oldRootRight[r];
|
|
3792
|
+
rootClone[r] = oldRootRight[l];
|
|
3793
|
+
target[l] = rootClone;
|
|
3794
|
+
rootClone.d = computeDepth(rootClone);
|
|
3795
|
+
}
|
|
3796
|
+
target.d = computeDepth(target);
|
|
3797
|
+
}
|
|
3798
|
+
function computeDepth({ r, l }) {
|
|
3799
|
+
return (r ? (l ? Math.max(r.d, l.d) : r.d) : l ? l.d : 0) + 1;
|
|
3800
|
+
}
|
|
3801
|
+
|
|
3802
|
+
function extendObservabilitySet(target, newSet) {
|
|
3803
|
+
keys(newSet).forEach(part => {
|
|
3804
|
+
if (target[part])
|
|
3805
|
+
mergeRanges(target[part], newSet[part]);
|
|
3806
|
+
else
|
|
3807
|
+
target[part] = cloneSimpleObjectTree(newSet[part]);
|
|
3808
|
+
});
|
|
3809
|
+
return target;
|
|
3810
|
+
}
|
|
3811
|
+
|
|
3812
|
+
function obsSetsOverlap(os1, os2) {
|
|
3813
|
+
return Object.keys(os1).some((key) => os2[key] && rangesOverlap(os2[key], os1[key]));
|
|
3814
|
+
}
|
|
3815
|
+
|
|
3816
|
+
const cache = {};
|
|
3817
|
+
|
|
3818
|
+
let unsignaledParts = {};
|
|
3819
|
+
let isTaskEnqueued = false;
|
|
3820
|
+
function signalSubscribersLazily(part) {
|
|
3821
|
+
extendObservabilitySet(unsignaledParts, part);
|
|
3822
|
+
if (!isTaskEnqueued) {
|
|
3823
|
+
isTaskEnqueued = true;
|
|
3824
|
+
queueMicrotask(() => {
|
|
3825
|
+
isTaskEnqueued = false;
|
|
3826
|
+
const parts = unsignaledParts;
|
|
3827
|
+
unsignaledParts = {};
|
|
3828
|
+
signalSubscribersNow(parts);
|
|
3829
|
+
});
|
|
3830
|
+
}
|
|
3831
|
+
}
|
|
3832
|
+
function signalSubscribersNow(updatedParts, deleteAffectedCacheEntries = false) {
|
|
3833
|
+
const queriesToSignal = new Set();
|
|
3834
|
+
for (const key in updatedParts) {
|
|
3835
|
+
const parts = /^idb\:\/\/(.*)\/(.*)\//.exec(key);
|
|
3836
|
+
if (parts) {
|
|
3837
|
+
const [, dbName, tableName] = parts;
|
|
3838
|
+
const tblCache = cache[`idb://${dbName}/${tableName}`];
|
|
3839
|
+
if (tblCache)
|
|
3840
|
+
signalTableSubscribersNow(tblCache, updatedParts, queriesToSignal, deleteAffectedCacheEntries);
|
|
3841
|
+
}
|
|
3842
|
+
}
|
|
3843
|
+
queriesToSignal.forEach((requery) => requery());
|
|
3844
|
+
}
|
|
3845
|
+
function signalTableSubscribersNow(tblCache, updatedParts, outQueriesToSignal, deleteAffectedCacheEntries) {
|
|
3846
|
+
const updatedEntryLists = deleteAffectedCacheEntries && [];
|
|
3847
|
+
for (const [indexName, entries] of Object.entries(tblCache.queries.query)) {
|
|
3848
|
+
const filteredEntries = deleteAffectedCacheEntries && [];
|
|
3849
|
+
for (const entry of entries) {
|
|
3850
|
+
if (entry.obsSet && obsSetsOverlap(updatedParts, entry.obsSet)) {
|
|
3851
|
+
entry.subscribers.forEach((requery) => outQueriesToSignal.add(requery));
|
|
3852
|
+
}
|
|
3853
|
+
else if (deleteAffectedCacheEntries) {
|
|
3854
|
+
filteredEntries.push(entry);
|
|
3855
|
+
}
|
|
3856
|
+
}
|
|
3857
|
+
if (deleteAffectedCacheEntries)
|
|
3858
|
+
updatedEntryLists.push([indexName, filteredEntries]);
|
|
3859
|
+
}
|
|
3860
|
+
if (deleteAffectedCacheEntries) {
|
|
3861
|
+
for (const [indexName, filteredEntries] of updatedEntryLists) {
|
|
3862
|
+
tblCache.queries.query[indexName] = filteredEntries;
|
|
3863
|
+
}
|
|
3864
|
+
}
|
|
3865
|
+
}
|
|
3866
|
+
|
|
3645
3867
|
function dexieOpen(db) {
|
|
3646
3868
|
const state = db._state;
|
|
3647
3869
|
const { indexedDB } = db._deps;
|
|
@@ -3733,10 +3955,10 @@ function dexieOpen(db) {
|
|
|
3733
3955
|
}
|
|
3734
3956
|
});
|
|
3735
3957
|
}).finally(() => {
|
|
3736
|
-
state.
|
|
3737
|
-
|
|
3738
|
-
|
|
3739
|
-
|
|
3958
|
+
if (state.openCanceller === openCanceller) {
|
|
3959
|
+
state.onReadyBeingFired = null;
|
|
3960
|
+
state.isBeingOpened = false;
|
|
3961
|
+
}
|
|
3740
3962
|
}).catch(err => {
|
|
3741
3963
|
state.dbOpenError = err;
|
|
3742
3964
|
try {
|
|
@@ -3750,6 +3972,20 @@ function dexieOpen(db) {
|
|
|
3750
3972
|
}).finally(() => {
|
|
3751
3973
|
state.openComplete = true;
|
|
3752
3974
|
resolveDbReady();
|
|
3975
|
+
}).then(() => {
|
|
3976
|
+
if (wasCreated) {
|
|
3977
|
+
const everything = {};
|
|
3978
|
+
db.tables.forEach(table => {
|
|
3979
|
+
table.schema.indexes.forEach(idx => {
|
|
3980
|
+
if (idx.name)
|
|
3981
|
+
everything[`idb://${db.name}/${table.name}/${idx.name}`] = new RangeSet(-Infinity, [[[]]]);
|
|
3982
|
+
});
|
|
3983
|
+
everything[`idb://${db.name}/${table.name}/`] = everything[`idb://${db.name}/${table.name}/:dels`] = new RangeSet(-Infinity, [[[]]]);
|
|
3984
|
+
});
|
|
3985
|
+
globalEvents(DEXIE_STORAGE_MUTATED_EVENT_NAME).fire(everything);
|
|
3986
|
+
signalSubscribersNow(everything, true);
|
|
3987
|
+
}
|
|
3988
|
+
return db;
|
|
3753
3989
|
});
|
|
3754
3990
|
}
|
|
3755
3991
|
|
|
@@ -4207,163 +4443,6 @@ const cacheExistingValuesMiddleware = {
|
|
|
4207
4443
|
},
|
|
4208
4444
|
};
|
|
4209
4445
|
|
|
4210
|
-
function isEmptyRange(node) {
|
|
4211
|
-
return !("from" in node);
|
|
4212
|
-
}
|
|
4213
|
-
const RangeSet = function (fromOrTree, to) {
|
|
4214
|
-
if (this) {
|
|
4215
|
-
extend(this, arguments.length ? { d: 1, from: fromOrTree, to: arguments.length > 1 ? to : fromOrTree } : { d: 0 });
|
|
4216
|
-
}
|
|
4217
|
-
else {
|
|
4218
|
-
const rv = new RangeSet();
|
|
4219
|
-
if (fromOrTree && ("d" in fromOrTree)) {
|
|
4220
|
-
extend(rv, fromOrTree);
|
|
4221
|
-
}
|
|
4222
|
-
return rv;
|
|
4223
|
-
}
|
|
4224
|
-
};
|
|
4225
|
-
props(RangeSet.prototype, {
|
|
4226
|
-
add(rangeSet) {
|
|
4227
|
-
mergeRanges(this, rangeSet);
|
|
4228
|
-
return this;
|
|
4229
|
-
},
|
|
4230
|
-
addKey(key) {
|
|
4231
|
-
addRange(this, key, key);
|
|
4232
|
-
return this;
|
|
4233
|
-
},
|
|
4234
|
-
addKeys(keys) {
|
|
4235
|
-
keys.forEach(key => addRange(this, key, key));
|
|
4236
|
-
return this;
|
|
4237
|
-
},
|
|
4238
|
-
[iteratorSymbol]() {
|
|
4239
|
-
return getRangeSetIterator(this);
|
|
4240
|
-
}
|
|
4241
|
-
});
|
|
4242
|
-
function addRange(target, from, to) {
|
|
4243
|
-
const diff = cmp(from, to);
|
|
4244
|
-
if (isNaN(diff))
|
|
4245
|
-
return;
|
|
4246
|
-
if (diff > 0)
|
|
4247
|
-
throw RangeError();
|
|
4248
|
-
if (isEmptyRange(target))
|
|
4249
|
-
return extend(target, { from, to, d: 1 });
|
|
4250
|
-
const left = target.l;
|
|
4251
|
-
const right = target.r;
|
|
4252
|
-
if (cmp(to, target.from) < 0) {
|
|
4253
|
-
left
|
|
4254
|
-
? addRange(left, from, to)
|
|
4255
|
-
: (target.l = { from, to, d: 1, l: null, r: null });
|
|
4256
|
-
return rebalance(target);
|
|
4257
|
-
}
|
|
4258
|
-
if (cmp(from, target.to) > 0) {
|
|
4259
|
-
right
|
|
4260
|
-
? addRange(right, from, to)
|
|
4261
|
-
: (target.r = { from, to, d: 1, l: null, r: null });
|
|
4262
|
-
return rebalance(target);
|
|
4263
|
-
}
|
|
4264
|
-
if (cmp(from, target.from) < 0) {
|
|
4265
|
-
target.from = from;
|
|
4266
|
-
target.l = null;
|
|
4267
|
-
target.d = right ? right.d + 1 : 1;
|
|
4268
|
-
}
|
|
4269
|
-
if (cmp(to, target.to) > 0) {
|
|
4270
|
-
target.to = to;
|
|
4271
|
-
target.r = null;
|
|
4272
|
-
target.d = target.l ? target.l.d + 1 : 1;
|
|
4273
|
-
}
|
|
4274
|
-
const rightWasCutOff = !target.r;
|
|
4275
|
-
if (left && !target.l) {
|
|
4276
|
-
mergeRanges(target, left);
|
|
4277
|
-
}
|
|
4278
|
-
if (right && rightWasCutOff) {
|
|
4279
|
-
mergeRanges(target, right);
|
|
4280
|
-
}
|
|
4281
|
-
}
|
|
4282
|
-
function mergeRanges(target, newSet) {
|
|
4283
|
-
function _addRangeSet(target, { from, to, l, r }) {
|
|
4284
|
-
addRange(target, from, to);
|
|
4285
|
-
if (l)
|
|
4286
|
-
_addRangeSet(target, l);
|
|
4287
|
-
if (r)
|
|
4288
|
-
_addRangeSet(target, r);
|
|
4289
|
-
}
|
|
4290
|
-
if (!isEmptyRange(newSet))
|
|
4291
|
-
_addRangeSet(target, newSet);
|
|
4292
|
-
}
|
|
4293
|
-
function rangesOverlap(rangeSet1, rangeSet2) {
|
|
4294
|
-
const i1 = getRangeSetIterator(rangeSet2);
|
|
4295
|
-
let nextResult1 = i1.next();
|
|
4296
|
-
if (nextResult1.done)
|
|
4297
|
-
return false;
|
|
4298
|
-
let a = nextResult1.value;
|
|
4299
|
-
const i2 = getRangeSetIterator(rangeSet1);
|
|
4300
|
-
let nextResult2 = i2.next(a.from);
|
|
4301
|
-
let b = nextResult2.value;
|
|
4302
|
-
while (!nextResult1.done && !nextResult2.done) {
|
|
4303
|
-
if (cmp(b.from, a.to) <= 0 && cmp(b.to, a.from) >= 0)
|
|
4304
|
-
return true;
|
|
4305
|
-
cmp(a.from, b.from) < 0
|
|
4306
|
-
? (a = (nextResult1 = i1.next(b.from)).value)
|
|
4307
|
-
: (b = (nextResult2 = i2.next(a.from)).value);
|
|
4308
|
-
}
|
|
4309
|
-
return false;
|
|
4310
|
-
}
|
|
4311
|
-
function getRangeSetIterator(node) {
|
|
4312
|
-
let state = isEmptyRange(node) ? null : { s: 0, n: node };
|
|
4313
|
-
return {
|
|
4314
|
-
next(key) {
|
|
4315
|
-
const keyProvided = arguments.length > 0;
|
|
4316
|
-
while (state) {
|
|
4317
|
-
switch (state.s) {
|
|
4318
|
-
case 0:
|
|
4319
|
-
state.s = 1;
|
|
4320
|
-
if (keyProvided) {
|
|
4321
|
-
while (state.n.l && cmp(key, state.n.from) < 0)
|
|
4322
|
-
state = { up: state, n: state.n.l, s: 1 };
|
|
4323
|
-
}
|
|
4324
|
-
else {
|
|
4325
|
-
while (state.n.l)
|
|
4326
|
-
state = { up: state, n: state.n.l, s: 1 };
|
|
4327
|
-
}
|
|
4328
|
-
case 1:
|
|
4329
|
-
state.s = 2;
|
|
4330
|
-
if (!keyProvided || cmp(key, state.n.to) <= 0)
|
|
4331
|
-
return { value: state.n, done: false };
|
|
4332
|
-
case 2:
|
|
4333
|
-
if (state.n.r) {
|
|
4334
|
-
state.s = 3;
|
|
4335
|
-
state = { up: state, n: state.n.r, s: 0 };
|
|
4336
|
-
continue;
|
|
4337
|
-
}
|
|
4338
|
-
case 3:
|
|
4339
|
-
state = state.up;
|
|
4340
|
-
}
|
|
4341
|
-
}
|
|
4342
|
-
return { done: true };
|
|
4343
|
-
},
|
|
4344
|
-
};
|
|
4345
|
-
}
|
|
4346
|
-
function rebalance(target) {
|
|
4347
|
-
var _a, _b;
|
|
4348
|
-
const diff = (((_a = target.r) === null || _a === void 0 ? void 0 : _a.d) || 0) - (((_b = target.l) === null || _b === void 0 ? void 0 : _b.d) || 0);
|
|
4349
|
-
const r = diff > 1 ? "r" : diff < -1 ? "l" : "";
|
|
4350
|
-
if (r) {
|
|
4351
|
-
const l = r === "r" ? "l" : "r";
|
|
4352
|
-
const rootClone = { ...target };
|
|
4353
|
-
const oldRootRight = target[r];
|
|
4354
|
-
target.from = oldRootRight.from;
|
|
4355
|
-
target.to = oldRootRight.to;
|
|
4356
|
-
target[r] = oldRootRight[r];
|
|
4357
|
-
rootClone[r] = oldRootRight[l];
|
|
4358
|
-
target[l] = rootClone;
|
|
4359
|
-
rootClone.d = computeDepth(rootClone);
|
|
4360
|
-
}
|
|
4361
|
-
target.d = computeDepth(target);
|
|
4362
|
-
}
|
|
4363
|
-
function computeDepth({ r, l }) {
|
|
4364
|
-
return (r ? (l ? Math.max(r.d, l.d) : r.d) : l ? l.d : 0) + 1;
|
|
4365
|
-
}
|
|
4366
|
-
|
|
4367
4446
|
function isCachableContext(ctx, table) {
|
|
4368
4447
|
return (ctx.trans.mode === 'readonly' &&
|
|
4369
4448
|
!!ctx.subscr &&
|
|
@@ -4387,19 +4466,9 @@ function isCachableRequest(type, req) {
|
|
|
4387
4466
|
}
|
|
4388
4467
|
}
|
|
4389
4468
|
|
|
4390
|
-
function extendObservabilitySet(target, newSet) {
|
|
4391
|
-
keys(newSet).forEach(part => {
|
|
4392
|
-
if (target[part])
|
|
4393
|
-
mergeRanges(target[part], newSet[part]);
|
|
4394
|
-
else
|
|
4395
|
-
target[part] = cloneSimpleObjectTree(newSet[part]);
|
|
4396
|
-
});
|
|
4397
|
-
return target;
|
|
4398
|
-
}
|
|
4399
|
-
|
|
4400
4469
|
const observabilityMiddleware = {
|
|
4401
4470
|
stack: "dbcore",
|
|
4402
|
-
level:
|
|
4471
|
+
level: 0,
|
|
4403
4472
|
name: "Observability",
|
|
4404
4473
|
create: (core) => {
|
|
4405
4474
|
const dbName = core.schema.name;
|
|
@@ -4407,10 +4476,9 @@ const observabilityMiddleware = {
|
|
|
4407
4476
|
return {
|
|
4408
4477
|
...core,
|
|
4409
4478
|
transaction: (stores, mode, options) => {
|
|
4410
|
-
if (
|
|
4411
|
-
|
|
4412
|
-
|
|
4413
|
-
throw new exceptions.ReadOnly('write transaction not allowed within liveQueries');
|
|
4479
|
+
if (PSD.subscr && mode !== 'readonly') {
|
|
4480
|
+
throw new exceptions.ReadOnly(`Readwrite transaction in liveQuery context. Querier source: ${PSD.querier}`);
|
|
4481
|
+
}
|
|
4414
4482
|
return core.transaction(stores, mode, options);
|
|
4415
4483
|
},
|
|
4416
4484
|
table: (tableName) => {
|
|
@@ -4674,8 +4742,6 @@ function applyOptimisticOps(result, req, ops, table, cacheEntry, immutable) {
|
|
|
4674
4742
|
return immutable ? Object.freeze(finalResult) : finalResult;
|
|
4675
4743
|
}
|
|
4676
4744
|
|
|
4677
|
-
const cache = {};
|
|
4678
|
-
|
|
4679
4745
|
function areRangesEqual(r1, r2) {
|
|
4680
4746
|
return (cmp(r1.lower, r2.lower) === 0 &&
|
|
4681
4747
|
cmp(r1.upper, r2.upper) === 0 &&
|
|
@@ -4756,59 +4822,6 @@ function findCompatibleQuery(dbName, tableName, type, req) {
|
|
|
4756
4822
|
}
|
|
4757
4823
|
}
|
|
4758
4824
|
|
|
4759
|
-
function obsSetsOverlap(os1, os2) {
|
|
4760
|
-
return Object.keys(os1).some((key) => os2[key] && rangesOverlap(os2[key], os1[key]));
|
|
4761
|
-
}
|
|
4762
|
-
|
|
4763
|
-
let unsignaledParts = {};
|
|
4764
|
-
let isTaskEnqueued = false;
|
|
4765
|
-
function signalSubscribersLazily(part) {
|
|
4766
|
-
extendObservabilitySet(unsignaledParts, part);
|
|
4767
|
-
if (!isTaskEnqueued) {
|
|
4768
|
-
isTaskEnqueued = true;
|
|
4769
|
-
queueMicrotask(() => {
|
|
4770
|
-
isTaskEnqueued = false;
|
|
4771
|
-
const parts = unsignaledParts;
|
|
4772
|
-
unsignaledParts = {};
|
|
4773
|
-
signalSubscribersNow(parts);
|
|
4774
|
-
});
|
|
4775
|
-
}
|
|
4776
|
-
}
|
|
4777
|
-
function signalSubscribersNow(updatedParts, deleteAffectedCacheEntries = false) {
|
|
4778
|
-
const queriesToSignal = new Set();
|
|
4779
|
-
for (const key in updatedParts) {
|
|
4780
|
-
const parts = /^idb\:\/\/(.*)\/(.*)\//.exec(key);
|
|
4781
|
-
if (parts) {
|
|
4782
|
-
const [, dbName, tableName] = parts;
|
|
4783
|
-
const tblCache = cache[`idb://${dbName}/${tableName}`];
|
|
4784
|
-
if (tblCache)
|
|
4785
|
-
signalTableSubscribersNow(tblCache, updatedParts, queriesToSignal, deleteAffectedCacheEntries);
|
|
4786
|
-
}
|
|
4787
|
-
}
|
|
4788
|
-
queriesToSignal.forEach((requery) => requery());
|
|
4789
|
-
}
|
|
4790
|
-
function signalTableSubscribersNow(tblCache, updatedParts, outQueriesToSignal, deleteAffectedCacheEntries) {
|
|
4791
|
-
const updatedEntryLists = deleteAffectedCacheEntries && [];
|
|
4792
|
-
for (const [indexName, entries] of Object.entries(tblCache.queries.query)) {
|
|
4793
|
-
const filteredEntries = deleteAffectedCacheEntries && [];
|
|
4794
|
-
for (const entry of entries) {
|
|
4795
|
-
if (entry.obsSet && obsSetsOverlap(updatedParts, entry.obsSet)) {
|
|
4796
|
-
entry.subscribers.forEach((requery) => outQueriesToSignal.add(requery));
|
|
4797
|
-
}
|
|
4798
|
-
else if (deleteAffectedCacheEntries) {
|
|
4799
|
-
filteredEntries.push(entry);
|
|
4800
|
-
}
|
|
4801
|
-
}
|
|
4802
|
-
if (deleteAffectedCacheEntries)
|
|
4803
|
-
updatedEntryLists.push([indexName, filteredEntries]);
|
|
4804
|
-
}
|
|
4805
|
-
if (deleteAffectedCacheEntries) {
|
|
4806
|
-
for (const [indexName, filteredEntries] of updatedEntryLists) {
|
|
4807
|
-
tblCache.queries.query[indexName] = filteredEntries;
|
|
4808
|
-
}
|
|
4809
|
-
}
|
|
4810
|
-
}
|
|
4811
|
-
|
|
4812
4825
|
function subscribeToCacheEntry(cacheEntry, container, requery, signal) {
|
|
4813
4826
|
cacheEntry.subscribers.add(requery);
|
|
4814
4827
|
signal.addEventListener("abort", () => {
|
|
@@ -4828,7 +4841,7 @@ function enqueForDeletion(cacheEntry, container) {
|
|
|
4828
4841
|
|
|
4829
4842
|
const cacheMiddleware = {
|
|
4830
4843
|
stack: 'dbcore',
|
|
4831
|
-
level:
|
|
4844
|
+
level: 0,
|
|
4832
4845
|
name: 'Cache',
|
|
4833
4846
|
create: (core) => {
|
|
4834
4847
|
const dbName = core.schema.name;
|
|
@@ -5089,7 +5102,8 @@ class Dexie$1 {
|
|
|
5089
5102
|
console.warn(`Another connection wants to upgrade database '${this.name}'. Closing db now to resume the upgrade.`);
|
|
5090
5103
|
else
|
|
5091
5104
|
console.warn(`Another connection wants to delete database '${this.name}'. Closing db now to resume the delete request.`);
|
|
5092
|
-
this.close();
|
|
5105
|
+
this.close({ disableAutoOpen: false });
|
|
5106
|
+
this._state.openComplete = false;
|
|
5093
5107
|
});
|
|
5094
5108
|
this.on("blocked", ev => {
|
|
5095
5109
|
if (!ev.newVersion || ev.newVersion < ev.oldVersion)
|
|
@@ -5106,10 +5120,10 @@ class Dexie$1 {
|
|
|
5106
5120
|
.map(c => c.on("versionchange").fire(ev));
|
|
5107
5121
|
};
|
|
5108
5122
|
this.use(cacheExistingValuesMiddleware);
|
|
5109
|
-
this.use(virtualIndexMiddleware);
|
|
5110
|
-
this.use(hooksMiddleware);
|
|
5111
5123
|
this.use(cacheMiddleware);
|
|
5112
5124
|
this.use(observabilityMiddleware);
|
|
5125
|
+
this.use(virtualIndexMiddleware);
|
|
5126
|
+
this.use(hooksMiddleware);
|
|
5113
5127
|
this.vip = Object.create(this, { _vip: { value: true } });
|
|
5114
5128
|
addons.forEach(addon => addon(this));
|
|
5115
5129
|
}
|
|
@@ -5185,10 +5199,11 @@ class Dexie$1 {
|
|
|
5185
5199
|
state.cancelOpen = reject;
|
|
5186
5200
|
});
|
|
5187
5201
|
}
|
|
5188
|
-
close() {
|
|
5202
|
+
close({ disableAutoOpen } = { disableAutoOpen: true }) {
|
|
5189
5203
|
this._close();
|
|
5190
5204
|
const state = this._state;
|
|
5191
|
-
|
|
5205
|
+
if (disableAutoOpen)
|
|
5206
|
+
this._options.autoOpen = false;
|
|
5192
5207
|
state.dbOpenError = new exceptions.DatabaseClosed();
|
|
5193
5208
|
if (state.isBeingOpened)
|
|
5194
5209
|
state.cancelOpen(state.dbOpenError);
|
|
@@ -5198,7 +5213,7 @@ class Dexie$1 {
|
|
|
5198
5213
|
const state = this._state;
|
|
5199
5214
|
return new DexiePromise((resolve, reject) => {
|
|
5200
5215
|
const doDelete = () => {
|
|
5201
|
-
this.close();
|
|
5216
|
+
this.close({ disableAutoOpen: false });
|
|
5202
5217
|
var req = this._deps.indexedDB.deleteDatabase(this.name);
|
|
5203
5218
|
req.onsuccess = wrap(() => {
|
|
5204
5219
|
_onDatabaseDeleted(this._deps, this.name);
|
|
@@ -5390,6 +5405,7 @@ function liveQuery(querier) {
|
|
|
5390
5405
|
subscr,
|
|
5391
5406
|
signal: abortController.signal,
|
|
5392
5407
|
requery: doQuery,
|
|
5408
|
+
querier,
|
|
5393
5409
|
trans: null
|
|
5394
5410
|
};
|
|
5395
5411
|
const ret = execute(ctx);
|