dexie-cloud-addon 4.0.4 → 4.0.6
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/modern/dexie-cloud-addon.js +26 -20
- package/dist/modern/dexie-cloud-addon.js.map +1 -1
- package/dist/modern/dexie-cloud-addon.min.js +1 -1
- package/dist/modern/dexie-cloud-addon.min.js.map +1 -1
- package/dist/modern/service-worker.js +27 -21
- package/dist/modern/service-worker.js.map +1 -1
- package/dist/modern/service-worker.min.js +1 -1
- package/dist/modern/service-worker.min.js.map +1 -1
- package/dist/umd/dexie-cloud-addon.js +26 -20
- package/dist/umd/dexie-cloud-addon.js.map +1 -1
- package/dist/umd/dexie-cloud-addon.min.js +1 -1
- package/dist/umd/dexie-cloud-addon.min.js.map +1 -1
- package/dist/umd/service-worker.js +26 -20
- package/dist/umd/service-worker.js.map +1 -1
- package/dist/umd/service-worker.min.js +1 -1
- package/dist/umd/service-worker.min.js.map +1 -1
- package/package.json +1 -1
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*
|
|
9
9
|
* ==========================================================================
|
|
10
10
|
*
|
|
11
|
-
* Version 4.0.
|
|
11
|
+
* Version 4.0.5, Sat May 25 2024
|
|
12
12
|
*
|
|
13
13
|
* https://dexie.org
|
|
14
14
|
*
|
|
@@ -3906,9 +3906,7 @@
|
|
|
3906
3906
|
// If the sync worker or service worker is syncing, wait 'til thei're done.
|
|
3907
3907
|
// It's no need to have two channels at the same time - even though it wouldnt
|
|
3908
3908
|
// be a problem - this is an optimization.
|
|
3909
|
-
yield db.cloud.syncState
|
|
3910
|
-
.pipe(filter(({ phase }) => phase === 'in-sync' || phase === 'error'), take(1))
|
|
3911
|
-
.toPromise();
|
|
3909
|
+
yield rxjs.firstValueFrom(db.cloud.syncState.pipe(filter(({ phase }) => phase === 'in-sync' || phase === 'error')));
|
|
3912
3910
|
console.debug('processing msg', msg);
|
|
3913
3911
|
const persistedSyncState = db.cloud.persistedSyncState.value;
|
|
3914
3912
|
//syncState.
|
|
@@ -4713,6 +4711,10 @@
|
|
|
4713
4711
|
}
|
|
4714
4712
|
const trans = req.trans;
|
|
4715
4713
|
if ((_b = (_a = db.cloud.schema) === null || _a === void 0 ? void 0 : _a[tableName]) === null || _b === void 0 ? void 0 : _b.markedForSync) {
|
|
4714
|
+
if (trans.mode === 'versionchange') {
|
|
4715
|
+
// Don't mutate tables marked for sync in versionchange transactions.
|
|
4716
|
+
return Promise.reject(new Dexie.UpgradeError(`Dexie Cloud Addon: Cannot upgrade or populate synced table "${tableName}". See https://dexie.org/cloud/docs/best-practices`));
|
|
4717
|
+
}
|
|
4716
4718
|
if (req.type === 'add' || req.type === 'put') {
|
|
4717
4719
|
if (tableName === 'members') {
|
|
4718
4720
|
for (const member of req.values) {
|
|
@@ -5417,7 +5419,7 @@
|
|
|
5417
5419
|
yield sleep$1(3000);
|
|
5418
5420
|
// Wait til user does something (move mouse, tap, scroll, click etc)
|
|
5419
5421
|
console.debug('waiting for someone to do something');
|
|
5420
|
-
yield
|
|
5422
|
+
yield rxjs.firstValueFrom(userDoesSomething);
|
|
5421
5423
|
console.debug('someone did something!');
|
|
5422
5424
|
});
|
|
5423
5425
|
}
|
|
@@ -6308,7 +6310,7 @@
|
|
|
6308
6310
|
const syncComplete = new rxjs.Subject();
|
|
6309
6311
|
dexie.cloud = {
|
|
6310
6312
|
// @ts-ignore
|
|
6311
|
-
version: "4.0.
|
|
6313
|
+
version: "4.0.5",
|
|
6312
6314
|
options: Object.assign({}, DEFAULT_OPTIONS),
|
|
6313
6315
|
schema: null,
|
|
6314
6316
|
get currentUserId() {
|
|
@@ -6366,10 +6368,8 @@
|
|
|
6366
6368
|
const syncState = db.cloud.persistedSyncState.value;
|
|
6367
6369
|
triggerSync(db, purpose);
|
|
6368
6370
|
if (wait) {
|
|
6369
|
-
const newSyncState = yield db.cloud.persistedSyncState
|
|
6370
|
-
|
|
6371
|
-
(!syncState || newSyncState.timestamp > syncState.timestamp)), take(1))
|
|
6372
|
-
.toPromise();
|
|
6371
|
+
const newSyncState = yield rxjs.firstValueFrom(db.cloud.persistedSyncState.pipe(filter((newSyncState) => (newSyncState === null || newSyncState === void 0 ? void 0 : newSyncState.timestamp) != null &&
|
|
6372
|
+
(!syncState || newSyncState.timestamp > syncState.timestamp))));
|
|
6373
6373
|
if (newSyncState === null || newSyncState === void 0 ? void 0 : newSyncState.error) {
|
|
6374
6374
|
throw new Error(`Sync error: ` + newSyncState.error);
|
|
6375
6375
|
}
|
|
@@ -6380,16 +6380,14 @@
|
|
|
6380
6380
|
triggerSync(db, purpose);
|
|
6381
6381
|
if (wait) {
|
|
6382
6382
|
console.debug('db.cloud.login() is waiting for sync completion...');
|
|
6383
|
-
yield rxjs.from(Dexie.liveQuery(() => __awaiter(this, void 0, void 0, function* () {
|
|
6383
|
+
yield rxjs.firstValueFrom(rxjs.from(Dexie.liveQuery(() => __awaiter(this, void 0, void 0, function* () {
|
|
6384
6384
|
const syncNeeded = yield isSyncNeeded(db);
|
|
6385
6385
|
const newSyncState = yield db.getPersistedSyncState();
|
|
6386
6386
|
if ((newSyncState === null || newSyncState === void 0 ? void 0 : newSyncState.timestamp) !== (syncState === null || syncState === void 0 ? void 0 : syncState.timestamp) &&
|
|
6387
6387
|
(newSyncState === null || newSyncState === void 0 ? void 0 : newSyncState.error))
|
|
6388
6388
|
throw new Error(`Sync error: ` + newSyncState.error);
|
|
6389
6389
|
return syncNeeded;
|
|
6390
|
-
})))
|
|
6391
|
-
.pipe(filter((isNeeded) => !isNeeded), take(1))
|
|
6392
|
-
.toPromise();
|
|
6390
|
+
}))).pipe(filter((isNeeded) => !isNeeded)));
|
|
6393
6391
|
console.debug('Done waiting for sync completion because we have nothing to push anymore');
|
|
6394
6392
|
}
|
|
6395
6393
|
}
|
|
@@ -6438,7 +6436,7 @@
|
|
|
6438
6436
|
const swRegistrations = 'serviceWorker' in navigator
|
|
6439
6437
|
? yield navigator.serviceWorker.getRegistrations()
|
|
6440
6438
|
: [];
|
|
6441
|
-
const initiallySynced = yield db.transaction('rw', db.$syncState, () => __awaiter(this, void 0, void 0, function* () {
|
|
6439
|
+
const [initiallySynced, lastSyncedRealms] = yield db.transaction('rw', db.$syncState, () => __awaiter(this, void 0, void 0, function* () {
|
|
6442
6440
|
var _h, _j;
|
|
6443
6441
|
const { options, schema } = db.cloud;
|
|
6444
6442
|
const [persistedOptions, persistedSchema, persistedSyncState] = yield Promise.all([
|
|
@@ -6511,7 +6509,7 @@
|
|
|
6511
6509
|
// Let's assign all props as the newPersistedSchems should be what we should be working with.
|
|
6512
6510
|
Object.assign(schema, newPersistedSchema);
|
|
6513
6511
|
}
|
|
6514
|
-
return persistedSyncState === null || persistedSyncState === void 0 ? void 0 : persistedSyncState.initiallySynced;
|
|
6512
|
+
return [persistedSyncState === null || persistedSyncState === void 0 ? void 0 : persistedSyncState.initiallySynced, persistedSyncState === null || persistedSyncState === void 0 ? void 0 : persistedSyncState.realms];
|
|
6515
6513
|
}));
|
|
6516
6514
|
if (initiallySynced) {
|
|
6517
6515
|
db.setInitiallySynced(true);
|
|
@@ -6531,19 +6529,27 @@
|
|
|
6531
6529
|
// with things from the database and not just the default values.
|
|
6532
6530
|
// This is so that when db.open() completes, user should be safe
|
|
6533
6531
|
// to subscribe to these observables and get actual data.
|
|
6534
|
-
yield rxjs.combineLatest([
|
|
6532
|
+
yield rxjs.firstValueFrom(rxjs.combineLatest([
|
|
6535
6533
|
currentUserEmitter.pipe(skip(1), take(1)),
|
|
6536
6534
|
db.cloud.persistedSyncState.pipe(skip(1), take(1)),
|
|
6537
|
-
])
|
|
6535
|
+
]));
|
|
6538
6536
|
}
|
|
6539
6537
|
// HERE: If requireAuth, do athentication now.
|
|
6540
6538
|
let changedUser = false;
|
|
6539
|
+
const user = yield db.getCurrentUser();
|
|
6541
6540
|
if ((_c = db.cloud.options) === null || _c === void 0 ? void 0 : _c.requireAuth) {
|
|
6542
|
-
const user = yield db.getCurrentUser();
|
|
6543
6541
|
if (!user.isLoggedIn) {
|
|
6544
6542
|
changedUser = yield login(db);
|
|
6545
6543
|
}
|
|
6546
6544
|
}
|
|
6545
|
+
if (user.isLoggedIn && (!lastSyncedRealms || !lastSyncedRealms.includes(user.userId))) {
|
|
6546
|
+
// User has been logged in but this is not reflected in the sync state.
|
|
6547
|
+
// This can happen if page is reloaded after login but before the sync call following
|
|
6548
|
+
// the login was complete.
|
|
6549
|
+
// The user is to be viewed as changed becuase current syncState does not reflect the presence
|
|
6550
|
+
// of the logged-in user.
|
|
6551
|
+
changedUser = true; // Set changedUser to true to trigger a pull-sync later down.
|
|
6552
|
+
}
|
|
6547
6553
|
if (localSyncWorker)
|
|
6548
6554
|
localSyncWorker.stop();
|
|
6549
6555
|
localSyncWorker = null;
|
|
@@ -6588,7 +6594,7 @@
|
|
|
6588
6594
|
}
|
|
6589
6595
|
}
|
|
6590
6596
|
// @ts-ignore
|
|
6591
|
-
dexieCloud.version = "4.0.
|
|
6597
|
+
dexieCloud.version = "4.0.5";
|
|
6592
6598
|
Dexie.Cloud = dexieCloud;
|
|
6593
6599
|
|
|
6594
6600
|
// In case the SW lives for a while, let it reuse already opened connections:
|