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
|
*
|
|
@@ -4159,13 +4159,15 @@
|
|
|
4159
4159
|
return toDBOperationSet(changes);
|
|
4160
4160
|
}
|
|
4161
4161
|
|
|
4162
|
+
const LIMIT_NUM_MESSAGES_PER_TIME = 10; // Allow a maximum of 10 messages per...
|
|
4163
|
+
const TIME_WINDOW = 10000; // ...10 seconds.
|
|
4164
|
+
const PAUSE_PERIOD = 1000; // Pause for 1 second if reached
|
|
4162
4165
|
function MessagesFromServerConsumer(db) {
|
|
4163
4166
|
const queue = [];
|
|
4164
4167
|
const readyToServe = new rxjs.BehaviorSubject(true);
|
|
4165
4168
|
const event = new rxjs.BehaviorSubject(null);
|
|
4166
4169
|
let isWorking = false;
|
|
4167
|
-
let
|
|
4168
|
-
let loopDetection = [0, 0, 0, 0, 0, 0, 0, 0, 0, Date.now()];
|
|
4170
|
+
let loopDetection = new Array(LIMIT_NUM_MESSAGES_PER_TIME).fill(0);
|
|
4169
4171
|
event.subscribe(() => __awaiter(this, void 0, void 0, function* () {
|
|
4170
4172
|
if (isWorking)
|
|
4171
4173
|
return;
|
|
@@ -4179,20 +4181,11 @@
|
|
|
4179
4181
|
}
|
|
4180
4182
|
finally {
|
|
4181
4183
|
if (loopDetection[loopDetection.length - 1] - loopDetection[0] <
|
|
4182
|
-
|
|
4184
|
+
TIME_WINDOW) {
|
|
4183
4185
|
// Ten loops within 10 seconds. Slow down!
|
|
4184
|
-
|
|
4185
|
-
|
|
4186
|
-
|
|
4187
|
-
loopWarning = Date.now() + 60000;
|
|
4188
|
-
yield new Promise((resolve) => setTimeout(resolve, 60000));
|
|
4189
|
-
}
|
|
4190
|
-
else {
|
|
4191
|
-
// This is a one-time event. Just pause 10 seconds.
|
|
4192
|
-
console.warn(`Slowing down websocket loop for 10 seconds`);
|
|
4193
|
-
loopWarning = Date.now() + 10000;
|
|
4194
|
-
yield new Promise((resolve) => setTimeout(resolve, 10000));
|
|
4195
|
-
}
|
|
4186
|
+
// This is a one-time event. Just pause 10 seconds.
|
|
4187
|
+
console.warn(`Slowing down websocket loop for ${PAUSE_PERIOD} milliseconds`);
|
|
4188
|
+
yield new Promise((resolve) => setTimeout(resolve, PAUSE_PERIOD));
|
|
4196
4189
|
}
|
|
4197
4190
|
isWorking = false;
|
|
4198
4191
|
readyToServe.next(true);
|
|
@@ -6320,7 +6313,7 @@
|
|
|
6320
6313
|
const syncComplete = new rxjs.Subject();
|
|
6321
6314
|
dexie.cloud = {
|
|
6322
6315
|
// @ts-ignore
|
|
6323
|
-
version: "4.0.
|
|
6316
|
+
version: "4.0.8",
|
|
6324
6317
|
options: Object.assign({}, DEFAULT_OPTIONS),
|
|
6325
6318
|
schema: null,
|
|
6326
6319
|
get currentUserId() {
|
|
@@ -6547,8 +6540,19 @@
|
|
|
6547
6540
|
// HERE: If requireAuth, do athentication now.
|
|
6548
6541
|
let changedUser = false;
|
|
6549
6542
|
const user = yield db.getCurrentUser();
|
|
6550
|
-
|
|
6551
|
-
|
|
6543
|
+
const requireAuth = (_c = db.cloud.options) === null || _c === void 0 ? void 0 : _c.requireAuth;
|
|
6544
|
+
if (requireAuth) {
|
|
6545
|
+
if (typeof requireAuth === 'object') {
|
|
6546
|
+
// requireAuth contains login hints. Check if we already fulfil it:
|
|
6547
|
+
if (!user.isLoggedIn ||
|
|
6548
|
+
(requireAuth.userId && user.userId !== requireAuth.userId) ||
|
|
6549
|
+
(requireAuth.email && user.email !== requireAuth.email)) {
|
|
6550
|
+
// If not, login the configured user:
|
|
6551
|
+
changedUser = yield login(db, requireAuth);
|
|
6552
|
+
}
|
|
6553
|
+
}
|
|
6554
|
+
else if (!user.isLoggedIn) {
|
|
6555
|
+
// requireAuth is true and user is not logged in
|
|
6552
6556
|
changedUser = yield login(db);
|
|
6553
6557
|
}
|
|
6554
6558
|
}
|
|
@@ -6604,7 +6608,7 @@
|
|
|
6604
6608
|
}
|
|
6605
6609
|
}
|
|
6606
6610
|
// @ts-ignore
|
|
6607
|
-
dexieCloud.version = "4.0.
|
|
6611
|
+
dexieCloud.version = "4.0.8";
|
|
6608
6612
|
Dexie.Cloud = dexieCloud;
|
|
6609
6613
|
|
|
6610
6614
|
exports.default = dexieCloud;
|