dexie-cloud-addon 4.0.7 → 4.0.8
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/DexieCloudOptions.d.ts +3 -2
- package/dist/modern/dexie-cloud-addon.js +24 -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 +24 -20
- 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/DexieCloudOptions.d.ts +3 -2
- package/dist/umd/dexie-cloud-addon.js +24 -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 +24 -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
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { TokenFinalResponse } from 'dexie-cloud-common';
|
|
1
|
+
import type { TokenFinalResponse } from 'dexie-cloud-common';
|
|
2
|
+
import type { LoginHints } from './DexieCloudAPI';
|
|
2
3
|
export interface PeriodicSyncOptions {
|
|
3
4
|
minInterval?: number;
|
|
4
5
|
}
|
|
5
6
|
export interface DexieCloudOptions {
|
|
6
7
|
databaseUrl: string;
|
|
7
|
-
requireAuth?: boolean;
|
|
8
|
+
requireAuth?: boolean | LoginHints;
|
|
8
9
|
tryUseServiceWorker?: boolean;
|
|
9
10
|
periodicSync?: PeriodicSyncOptions;
|
|
10
11
|
customLoginGui?: boolean;
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*
|
|
9
9
|
* ==========================================================================
|
|
10
10
|
*
|
|
11
|
-
* Version 4.0.
|
|
11
|
+
* Version 4.0.8, Tue Jun 04 2024
|
|
12
12
|
*
|
|
13
13
|
* https://dexie.org
|
|
14
14
|
*
|
|
@@ -4156,13 +4156,15 @@ function filterServerChangesThroughAddedClientChanges(serverChanges, addedClient
|
|
|
4156
4156
|
return toDBOperationSet(changes);
|
|
4157
4157
|
}
|
|
4158
4158
|
|
|
4159
|
+
const LIMIT_NUM_MESSAGES_PER_TIME = 10; // Allow a maximum of 10 messages per...
|
|
4160
|
+
const TIME_WINDOW = 10000; // ...10 seconds.
|
|
4161
|
+
const PAUSE_PERIOD = 1000; // Pause for 1 second if reached
|
|
4159
4162
|
function MessagesFromServerConsumer(db) {
|
|
4160
4163
|
const queue = [];
|
|
4161
4164
|
const readyToServe = new BehaviorSubject(true);
|
|
4162
4165
|
const event = new BehaviorSubject(null);
|
|
4163
4166
|
let isWorking = false;
|
|
4164
|
-
let
|
|
4165
|
-
let loopDetection = [0, 0, 0, 0, 0, 0, 0, 0, 0, Date.now()];
|
|
4167
|
+
let loopDetection = new Array(LIMIT_NUM_MESSAGES_PER_TIME).fill(0);
|
|
4166
4168
|
event.subscribe(() => __awaiter(this, void 0, void 0, function* () {
|
|
4167
4169
|
if (isWorking)
|
|
4168
4170
|
return;
|
|
@@ -4176,20 +4178,11 @@ function MessagesFromServerConsumer(db) {
|
|
|
4176
4178
|
}
|
|
4177
4179
|
finally {
|
|
4178
4180
|
if (loopDetection[loopDetection.length - 1] - loopDetection[0] <
|
|
4179
|
-
|
|
4181
|
+
TIME_WINDOW) {
|
|
4180
4182
|
// Ten loops within 10 seconds. Slow down!
|
|
4181
|
-
|
|
4182
|
-
|
|
4183
|
-
|
|
4184
|
-
loopWarning = Date.now() + 60000;
|
|
4185
|
-
yield new Promise((resolve) => setTimeout(resolve, 60000));
|
|
4186
|
-
}
|
|
4187
|
-
else {
|
|
4188
|
-
// This is a one-time event. Just pause 10 seconds.
|
|
4189
|
-
console.warn(`Slowing down websocket loop for 10 seconds`);
|
|
4190
|
-
loopWarning = Date.now() + 10000;
|
|
4191
|
-
yield new Promise((resolve) => setTimeout(resolve, 10000));
|
|
4192
|
-
}
|
|
4183
|
+
// This is a one-time event. Just pause 10 seconds.
|
|
4184
|
+
console.warn(`Slowing down websocket loop for ${PAUSE_PERIOD} milliseconds`);
|
|
4185
|
+
yield new Promise((resolve) => setTimeout(resolve, PAUSE_PERIOD));
|
|
4193
4186
|
}
|
|
4194
4187
|
isWorking = false;
|
|
4195
4188
|
readyToServe.next(true);
|
|
@@ -6317,7 +6310,7 @@ function dexieCloud(dexie) {
|
|
|
6317
6310
|
const syncComplete = new Subject();
|
|
6318
6311
|
dexie.cloud = {
|
|
6319
6312
|
// @ts-ignore
|
|
6320
|
-
version: "4.0.
|
|
6313
|
+
version: "4.0.8",
|
|
6321
6314
|
options: Object.assign({}, DEFAULT_OPTIONS),
|
|
6322
6315
|
schema: null,
|
|
6323
6316
|
get currentUserId() {
|
|
@@ -6544,8 +6537,19 @@ function dexieCloud(dexie) {
|
|
|
6544
6537
|
// HERE: If requireAuth, do athentication now.
|
|
6545
6538
|
let changedUser = false;
|
|
6546
6539
|
const user = yield db.getCurrentUser();
|
|
6547
|
-
|
|
6548
|
-
|
|
6540
|
+
const requireAuth = (_c = db.cloud.options) === null || _c === void 0 ? void 0 : _c.requireAuth;
|
|
6541
|
+
if (requireAuth) {
|
|
6542
|
+
if (typeof requireAuth === 'object') {
|
|
6543
|
+
// requireAuth contains login hints. Check if we already fulfil it:
|
|
6544
|
+
if (!user.isLoggedIn ||
|
|
6545
|
+
(requireAuth.userId && user.userId !== requireAuth.userId) ||
|
|
6546
|
+
(requireAuth.email && user.email !== requireAuth.email)) {
|
|
6547
|
+
// If not, login the configured user:
|
|
6548
|
+
changedUser = yield login(db, requireAuth);
|
|
6549
|
+
}
|
|
6550
|
+
}
|
|
6551
|
+
else if (!user.isLoggedIn) {
|
|
6552
|
+
// requireAuth is true and user is not logged in
|
|
6549
6553
|
changedUser = yield login(db);
|
|
6550
6554
|
}
|
|
6551
6555
|
}
|
|
@@ -6601,7 +6605,7 @@ function dexieCloud(dexie) {
|
|
|
6601
6605
|
}
|
|
6602
6606
|
}
|
|
6603
6607
|
// @ts-ignore
|
|
6604
|
-
dexieCloud.version = "4.0.
|
|
6608
|
+
dexieCloud.version = "4.0.8";
|
|
6605
6609
|
Dexie.Cloud = dexieCloud;
|
|
6606
6610
|
|
|
6607
6611
|
export { dexieCloud as default, dexieCloud, getTiedObjectId, getTiedRealmId, resolveText };
|