dexie-cloud-addon 4.0.6 → 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 +27 -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 -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 +27 -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 +27 -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);
|
|
@@ -5025,6 +5018,9 @@ function createMutationTrackingMiddleware({ currentUserObservable, db, }) {
|
|
|
5025
5018
|
txid,
|
|
5026
5019
|
userId,
|
|
5027
5020
|
};
|
|
5021
|
+
if ('isAdditionalChunk' in req && req.isAdditionalChunk) {
|
|
5022
|
+
mut.isAdditionalChunk = true;
|
|
5023
|
+
}
|
|
5028
5024
|
return keys.length > 0 || ('criteria' in req && req.criteria)
|
|
5029
5025
|
? mutsTable
|
|
5030
5026
|
.mutate({ type: 'add', trans, values: [mut] }) // Log entry
|
|
@@ -6314,7 +6310,7 @@ function dexieCloud(dexie) {
|
|
|
6314
6310
|
const syncComplete = new Subject();
|
|
6315
6311
|
dexie.cloud = {
|
|
6316
6312
|
// @ts-ignore
|
|
6317
|
-
version: "4.0.
|
|
6313
|
+
version: "4.0.8",
|
|
6318
6314
|
options: Object.assign({}, DEFAULT_OPTIONS),
|
|
6319
6315
|
schema: null,
|
|
6320
6316
|
get currentUserId() {
|
|
@@ -6541,8 +6537,19 @@ function dexieCloud(dexie) {
|
|
|
6541
6537
|
// HERE: If requireAuth, do athentication now.
|
|
6542
6538
|
let changedUser = false;
|
|
6543
6539
|
const user = yield db.getCurrentUser();
|
|
6544
|
-
|
|
6545
|
-
|
|
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
|
|
6546
6553
|
changedUser = yield login(db);
|
|
6547
6554
|
}
|
|
6548
6555
|
}
|
|
@@ -6598,7 +6605,7 @@ function dexieCloud(dexie) {
|
|
|
6598
6605
|
}
|
|
6599
6606
|
}
|
|
6600
6607
|
// @ts-ignore
|
|
6601
|
-
dexieCloud.version = "4.0.
|
|
6608
|
+
dexieCloud.version = "4.0.8";
|
|
6602
6609
|
Dexie.Cloud = dexieCloud;
|
|
6603
6610
|
|
|
6604
6611
|
export { dexieCloud as default, dexieCloud, getTiedObjectId, getTiedRealmId, resolveText };
|