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
|
*
|
|
@@ -4212,9 +4212,7 @@
|
|
|
4212
4212
|
// If the sync worker or service worker is syncing, wait 'til thei're done.
|
|
4213
4213
|
// It's no need to have two channels at the same time - even though it wouldnt
|
|
4214
4214
|
// be a problem - this is an optimization.
|
|
4215
|
-
yield db.cloud.syncState
|
|
4216
|
-
.pipe(filter(({ phase }) => phase === 'in-sync' || phase === 'error'), take(1))
|
|
4217
|
-
.toPromise();
|
|
4215
|
+
yield rxjs.firstValueFrom(db.cloud.syncState.pipe(filter(({ phase }) => phase === 'in-sync' || phase === 'error')));
|
|
4218
4216
|
console.debug('processing msg', msg);
|
|
4219
4217
|
const persistedSyncState = db.cloud.persistedSyncState.value;
|
|
4220
4218
|
//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(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
|
}
|
|
@@ -6315,7 +6317,7 @@
|
|
|
6315
6317
|
const syncComplete = new rxjs.Subject();
|
|
6316
6318
|
dexie.cloud = {
|
|
6317
6319
|
// @ts-ignore
|
|
6318
|
-
version: "4.0.
|
|
6320
|
+
version: "4.0.5",
|
|
6319
6321
|
options: Object.assign({}, DEFAULT_OPTIONS),
|
|
6320
6322
|
schema: null,
|
|
6321
6323
|
get currentUserId() {
|
|
@@ -6373,10 +6375,8 @@
|
|
|
6373
6375
|
const syncState = db.cloud.persistedSyncState.value;
|
|
6374
6376
|
triggerSync(db, purpose);
|
|
6375
6377
|
if (wait) {
|
|
6376
|
-
const newSyncState = yield db.cloud.persistedSyncState
|
|
6377
|
-
|
|
6378
|
-
(!syncState || newSyncState.timestamp > syncState.timestamp)), take(1))
|
|
6379
|
-
.toPromise();
|
|
6378
|
+
const newSyncState = yield rxjs.firstValueFrom(db.cloud.persistedSyncState.pipe(filter((newSyncState) => (newSyncState === null || newSyncState === void 0 ? void 0 : newSyncState.timestamp) != null &&
|
|
6379
|
+
(!syncState || newSyncState.timestamp > syncState.timestamp))));
|
|
6380
6380
|
if (newSyncState === null || newSyncState === void 0 ? void 0 : newSyncState.error) {
|
|
6381
6381
|
throw new Error(`Sync error: ` + newSyncState.error);
|
|
6382
6382
|
}
|
|
@@ -6387,16 +6387,14 @@
|
|
|
6387
6387
|
triggerSync(db, purpose);
|
|
6388
6388
|
if (wait) {
|
|
6389
6389
|
console.debug('db.cloud.login() is waiting for sync completion...');
|
|
6390
|
-
yield rxjs.from(Dexie.liveQuery(() => __awaiter(this, void 0, void 0, function* () {
|
|
6390
|
+
yield rxjs.firstValueFrom(rxjs.from(Dexie.liveQuery(() => __awaiter(this, void 0, void 0, function* () {
|
|
6391
6391
|
const syncNeeded = yield isSyncNeeded(db);
|
|
6392
6392
|
const newSyncState = yield db.getPersistedSyncState();
|
|
6393
6393
|
if ((newSyncState === null || newSyncState === void 0 ? void 0 : newSyncState.timestamp) !== (syncState === null || syncState === void 0 ? void 0 : syncState.timestamp) &&
|
|
6394
6394
|
(newSyncState === null || newSyncState === void 0 ? void 0 : newSyncState.error))
|
|
6395
6395
|
throw new Error(`Sync error: ` + newSyncState.error);
|
|
6396
6396
|
return syncNeeded;
|
|
6397
|
-
})))
|
|
6398
|
-
.pipe(filter((isNeeded) => !isNeeded), take(1))
|
|
6399
|
-
.toPromise();
|
|
6397
|
+
}))).pipe(filter((isNeeded) => !isNeeded)));
|
|
6400
6398
|
console.debug('Done waiting for sync completion because we have nothing to push anymore');
|
|
6401
6399
|
}
|
|
6402
6400
|
}
|
|
@@ -6445,7 +6443,7 @@
|
|
|
6445
6443
|
const swRegistrations = 'serviceWorker' in navigator
|
|
6446
6444
|
? yield navigator.serviceWorker.getRegistrations()
|
|
6447
6445
|
: [];
|
|
6448
|
-
const initiallySynced = yield db.transaction('rw', db.$syncState, () => __awaiter(this, void 0, void 0, function* () {
|
|
6446
|
+
const [initiallySynced, lastSyncedRealms] = yield db.transaction('rw', db.$syncState, () => __awaiter(this, void 0, void 0, function* () {
|
|
6449
6447
|
var _h, _j;
|
|
6450
6448
|
const { options, schema } = db.cloud;
|
|
6451
6449
|
const [persistedOptions, persistedSchema, persistedSyncState] = yield Promise.all([
|
|
@@ -6518,7 +6516,7 @@
|
|
|
6518
6516
|
// Let's assign all props as the newPersistedSchems should be what we should be working with.
|
|
6519
6517
|
Object.assign(schema, newPersistedSchema);
|
|
6520
6518
|
}
|
|
6521
|
-
return persistedSyncState === null || persistedSyncState === void 0 ? void 0 : persistedSyncState.initiallySynced;
|
|
6519
|
+
return [persistedSyncState === null || persistedSyncState === void 0 ? void 0 : persistedSyncState.initiallySynced, persistedSyncState === null || persistedSyncState === void 0 ? void 0 : persistedSyncState.realms];
|
|
6522
6520
|
}));
|
|
6523
6521
|
if (initiallySynced) {
|
|
6524
6522
|
db.setInitiallySynced(true);
|
|
@@ -6538,19 +6536,27 @@
|
|
|
6538
6536
|
// with things from the database and not just the default values.
|
|
6539
6537
|
// This is so that when db.open() completes, user should be safe
|
|
6540
6538
|
// to subscribe to these observables and get actual data.
|
|
6541
|
-
yield rxjs.combineLatest([
|
|
6539
|
+
yield rxjs.firstValueFrom(rxjs.combineLatest([
|
|
6542
6540
|
currentUserEmitter.pipe(skip(1), take(1)),
|
|
6543
6541
|
db.cloud.persistedSyncState.pipe(skip(1), take(1)),
|
|
6544
|
-
])
|
|
6542
|
+
]));
|
|
6545
6543
|
}
|
|
6546
6544
|
// HERE: If requireAuth, do athentication now.
|
|
6547
6545
|
let changedUser = false;
|
|
6546
|
+
const user = yield db.getCurrentUser();
|
|
6548
6547
|
if ((_c = db.cloud.options) === null || _c === void 0 ? void 0 : _c.requireAuth) {
|
|
6549
|
-
const user = yield db.getCurrentUser();
|
|
6550
6548
|
if (!user.isLoggedIn) {
|
|
6551
6549
|
changedUser = yield login(db);
|
|
6552
6550
|
}
|
|
6553
6551
|
}
|
|
6552
|
+
if (user.isLoggedIn && (!lastSyncedRealms || !lastSyncedRealms.includes(user.userId))) {
|
|
6553
|
+
// User has been logged in but this is not reflected in the sync state.
|
|
6554
|
+
// This can happen if page is reloaded after login but before the sync call following
|
|
6555
|
+
// the login was complete.
|
|
6556
|
+
// The user is to be viewed as changed becuase current syncState does not reflect the presence
|
|
6557
|
+
// of the logged-in user.
|
|
6558
|
+
changedUser = true; // Set changedUser to true to trigger a pull-sync later down.
|
|
6559
|
+
}
|
|
6554
6560
|
if (localSyncWorker)
|
|
6555
6561
|
localSyncWorker.stop();
|
|
6556
6562
|
localSyncWorker = null;
|
|
@@ -6595,7 +6601,7 @@
|
|
|
6595
6601
|
}
|
|
6596
6602
|
}
|
|
6597
6603
|
// @ts-ignore
|
|
6598
|
-
dexieCloud.version = "4.0.
|
|
6604
|
+
dexieCloud.version = "4.0.5";
|
|
6599
6605
|
Dexie.Cloud = dexieCloud;
|
|
6600
6606
|
|
|
6601
6607
|
exports.default = dexieCloud;
|