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
|
*
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
19
|
import Dexie, { PropModification, cmp, liveQuery } from 'dexie';
|
|
20
|
-
import { Observable as Observable$1, BehaviorSubject,
|
|
20
|
+
import { Observable as Observable$1, BehaviorSubject, firstValueFrom, Subject, from as from$1, filter as filter$1, fromEvent, of, merge, Subscription as Subscription$1, throwError, combineLatest, map as map$1, share, timer as timer$1 } from 'rxjs';
|
|
21
21
|
|
|
22
22
|
/******************************************************************************
|
|
23
23
|
Copyright (c) Microsoft Corporation.
|
|
@@ -3903,9 +3903,7 @@ function MessagesFromServerConsumer(db) {
|
|
|
3903
3903
|
// If the sync worker or service worker is syncing, wait 'til thei're done.
|
|
3904
3904
|
// It's no need to have two channels at the same time - even though it wouldnt
|
|
3905
3905
|
// be a problem - this is an optimization.
|
|
3906
|
-
yield db.cloud.syncState
|
|
3907
|
-
.pipe(filter(({ phase }) => phase === 'in-sync' || phase === 'error'), take(1))
|
|
3908
|
-
.toPromise();
|
|
3906
|
+
yield firstValueFrom(db.cloud.syncState.pipe(filter(({ phase }) => phase === 'in-sync' || phase === 'error')));
|
|
3909
3907
|
console.debug('processing msg', msg);
|
|
3910
3908
|
const persistedSyncState = db.cloud.persistedSyncState.value;
|
|
3911
3909
|
//syncState.
|
|
@@ -4710,6 +4708,10 @@ function createImplicitPropSetterMiddleware(db) {
|
|
|
4710
4708
|
}
|
|
4711
4709
|
const trans = req.trans;
|
|
4712
4710
|
if ((_b = (_a = db.cloud.schema) === null || _a === void 0 ? void 0 : _a[tableName]) === null || _b === void 0 ? void 0 : _b.markedForSync) {
|
|
4711
|
+
if (trans.mode === 'versionchange') {
|
|
4712
|
+
// Don't mutate tables marked for sync in versionchange transactions.
|
|
4713
|
+
return Promise.reject(new Dexie.UpgradeError(`Dexie Cloud Addon: Cannot upgrade or populate synced table "${tableName}". See https://dexie.org/cloud/docs/best-practices`));
|
|
4714
|
+
}
|
|
4713
4715
|
if (req.type === 'add' || req.type === 'put') {
|
|
4714
4716
|
if (tableName === 'members') {
|
|
4715
4717
|
for (const member of req.values) {
|
|
@@ -5414,7 +5416,7 @@ function waitAndReconnectWhenUserDoesSomething(error) {
|
|
|
5414
5416
|
yield sleep$1(3000);
|
|
5415
5417
|
// Wait til user does something (move mouse, tap, scroll, click etc)
|
|
5416
5418
|
console.debug('waiting for someone to do something');
|
|
5417
|
-
yield userDoesSomething
|
|
5419
|
+
yield firstValueFrom(userDoesSomething);
|
|
5418
5420
|
console.debug('someone did something!');
|
|
5419
5421
|
});
|
|
5420
5422
|
}
|
|
@@ -6305,7 +6307,7 @@ function dexieCloud(dexie) {
|
|
|
6305
6307
|
const syncComplete = new Subject();
|
|
6306
6308
|
dexie.cloud = {
|
|
6307
6309
|
// @ts-ignore
|
|
6308
|
-
version: "4.0.
|
|
6310
|
+
version: "4.0.5",
|
|
6309
6311
|
options: Object.assign({}, DEFAULT_OPTIONS),
|
|
6310
6312
|
schema: null,
|
|
6311
6313
|
get currentUserId() {
|
|
@@ -6363,10 +6365,8 @@ function dexieCloud(dexie) {
|
|
|
6363
6365
|
const syncState = db.cloud.persistedSyncState.value;
|
|
6364
6366
|
triggerSync(db, purpose);
|
|
6365
6367
|
if (wait) {
|
|
6366
|
-
const newSyncState = yield db.cloud.persistedSyncState
|
|
6367
|
-
|
|
6368
|
-
(!syncState || newSyncState.timestamp > syncState.timestamp)), take(1))
|
|
6369
|
-
.toPromise();
|
|
6368
|
+
const newSyncState = yield firstValueFrom(db.cloud.persistedSyncState.pipe(filter((newSyncState) => (newSyncState === null || newSyncState === void 0 ? void 0 : newSyncState.timestamp) != null &&
|
|
6369
|
+
(!syncState || newSyncState.timestamp > syncState.timestamp))));
|
|
6370
6370
|
if (newSyncState === null || newSyncState === void 0 ? void 0 : newSyncState.error) {
|
|
6371
6371
|
throw new Error(`Sync error: ` + newSyncState.error);
|
|
6372
6372
|
}
|
|
@@ -6377,16 +6377,14 @@ function dexieCloud(dexie) {
|
|
|
6377
6377
|
triggerSync(db, purpose);
|
|
6378
6378
|
if (wait) {
|
|
6379
6379
|
console.debug('db.cloud.login() is waiting for sync completion...');
|
|
6380
|
-
yield from$1(liveQuery(() => __awaiter(this, void 0, void 0, function* () {
|
|
6380
|
+
yield firstValueFrom(from$1(liveQuery(() => __awaiter(this, void 0, void 0, function* () {
|
|
6381
6381
|
const syncNeeded = yield isSyncNeeded(db);
|
|
6382
6382
|
const newSyncState = yield db.getPersistedSyncState();
|
|
6383
6383
|
if ((newSyncState === null || newSyncState === void 0 ? void 0 : newSyncState.timestamp) !== (syncState === null || syncState === void 0 ? void 0 : syncState.timestamp) &&
|
|
6384
6384
|
(newSyncState === null || newSyncState === void 0 ? void 0 : newSyncState.error))
|
|
6385
6385
|
throw new Error(`Sync error: ` + newSyncState.error);
|
|
6386
6386
|
return syncNeeded;
|
|
6387
|
-
})))
|
|
6388
|
-
.pipe(filter((isNeeded) => !isNeeded), take(1))
|
|
6389
|
-
.toPromise();
|
|
6387
|
+
}))).pipe(filter((isNeeded) => !isNeeded)));
|
|
6390
6388
|
console.debug('Done waiting for sync completion because we have nothing to push anymore');
|
|
6391
6389
|
}
|
|
6392
6390
|
}
|
|
@@ -6435,7 +6433,7 @@ function dexieCloud(dexie) {
|
|
|
6435
6433
|
const swRegistrations = 'serviceWorker' in navigator
|
|
6436
6434
|
? yield navigator.serviceWorker.getRegistrations()
|
|
6437
6435
|
: [];
|
|
6438
|
-
const initiallySynced = yield db.transaction('rw', db.$syncState, () => __awaiter(this, void 0, void 0, function* () {
|
|
6436
|
+
const [initiallySynced, lastSyncedRealms] = yield db.transaction('rw', db.$syncState, () => __awaiter(this, void 0, void 0, function* () {
|
|
6439
6437
|
var _h, _j;
|
|
6440
6438
|
const { options, schema } = db.cloud;
|
|
6441
6439
|
const [persistedOptions, persistedSchema, persistedSyncState] = yield Promise.all([
|
|
@@ -6508,7 +6506,7 @@ function dexieCloud(dexie) {
|
|
|
6508
6506
|
// Let's assign all props as the newPersistedSchems should be what we should be working with.
|
|
6509
6507
|
Object.assign(schema, newPersistedSchema);
|
|
6510
6508
|
}
|
|
6511
|
-
return persistedSyncState === null || persistedSyncState === void 0 ? void 0 : persistedSyncState.initiallySynced;
|
|
6509
|
+
return [persistedSyncState === null || persistedSyncState === void 0 ? void 0 : persistedSyncState.initiallySynced, persistedSyncState === null || persistedSyncState === void 0 ? void 0 : persistedSyncState.realms];
|
|
6512
6510
|
}));
|
|
6513
6511
|
if (initiallySynced) {
|
|
6514
6512
|
db.setInitiallySynced(true);
|
|
@@ -6528,19 +6526,27 @@ function dexieCloud(dexie) {
|
|
|
6528
6526
|
// with things from the database and not just the default values.
|
|
6529
6527
|
// This is so that when db.open() completes, user should be safe
|
|
6530
6528
|
// to subscribe to these observables and get actual data.
|
|
6531
|
-
yield combineLatest([
|
|
6529
|
+
yield firstValueFrom(combineLatest([
|
|
6532
6530
|
currentUserEmitter.pipe(skip(1), take(1)),
|
|
6533
6531
|
db.cloud.persistedSyncState.pipe(skip(1), take(1)),
|
|
6534
|
-
])
|
|
6532
|
+
]));
|
|
6535
6533
|
}
|
|
6536
6534
|
// HERE: If requireAuth, do athentication now.
|
|
6537
6535
|
let changedUser = false;
|
|
6536
|
+
const user = yield db.getCurrentUser();
|
|
6538
6537
|
if ((_c = db.cloud.options) === null || _c === void 0 ? void 0 : _c.requireAuth) {
|
|
6539
|
-
const user = yield db.getCurrentUser();
|
|
6540
6538
|
if (!user.isLoggedIn) {
|
|
6541
6539
|
changedUser = yield login(db);
|
|
6542
6540
|
}
|
|
6543
6541
|
}
|
|
6542
|
+
if (user.isLoggedIn && (!lastSyncedRealms || !lastSyncedRealms.includes(user.userId))) {
|
|
6543
|
+
// User has been logged in but this is not reflected in the sync state.
|
|
6544
|
+
// This can happen if page is reloaded after login but before the sync call following
|
|
6545
|
+
// the login was complete.
|
|
6546
|
+
// The user is to be viewed as changed becuase current syncState does not reflect the presence
|
|
6547
|
+
// of the logged-in user.
|
|
6548
|
+
changedUser = true; // Set changedUser to true to trigger a pull-sync later down.
|
|
6549
|
+
}
|
|
6544
6550
|
if (localSyncWorker)
|
|
6545
6551
|
localSyncWorker.stop();
|
|
6546
6552
|
localSyncWorker = null;
|
|
@@ -6585,7 +6591,7 @@ function dexieCloud(dexie) {
|
|
|
6585
6591
|
}
|
|
6586
6592
|
}
|
|
6587
6593
|
// @ts-ignore
|
|
6588
|
-
dexieCloud.version = "4.0.
|
|
6594
|
+
dexieCloud.version = "4.0.5";
|
|
6589
6595
|
Dexie.Cloud = dexieCloud;
|
|
6590
6596
|
|
|
6591
6597
|
// In case the SW lives for a while, let it reuse already opened connections:
|