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.
@@ -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.5, Sat May 25 2024
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 loopWarning = 0;
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
- 10000) {
4184
+ TIME_WINDOW) {
4183
4185
  // Ten loops within 10 seconds. Slow down!
4184
- if (Date.now() - loopWarning < 5000) {
4185
- // Last time we did this, we ended up here too. Wait for a minute.
4186
- console.warn(`Slowing down websocket loop for one minute`);
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);
@@ -5028,6 +5021,9 @@
5028
5021
  txid,
5029
5022
  userId,
5030
5023
  };
5024
+ if ('isAdditionalChunk' in req && req.isAdditionalChunk) {
5025
+ mut.isAdditionalChunk = true;
5026
+ }
5031
5027
  return keys.length > 0 || ('criteria' in req && req.criteria)
5032
5028
  ? mutsTable
5033
5029
  .mutate({ type: 'add', trans, values: [mut] }) // Log entry
@@ -6317,7 +6313,7 @@
6317
6313
  const syncComplete = new rxjs.Subject();
6318
6314
  dexie.cloud = {
6319
6315
  // @ts-ignore
6320
- version: "4.0.5",
6316
+ version: "4.0.8",
6321
6317
  options: Object.assign({}, DEFAULT_OPTIONS),
6322
6318
  schema: null,
6323
6319
  get currentUserId() {
@@ -6544,8 +6540,19 @@
6544
6540
  // HERE: If requireAuth, do athentication now.
6545
6541
  let changedUser = false;
6546
6542
  const user = yield db.getCurrentUser();
6547
- if ((_c = db.cloud.options) === null || _c === void 0 ? void 0 : _c.requireAuth) {
6548
- if (!user.isLoggedIn) {
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
6549
6556
  changedUser = yield login(db);
6550
6557
  }
6551
6558
  }
@@ -6601,7 +6608,7 @@
6601
6608
  }
6602
6609
  }
6603
6610
  // @ts-ignore
6604
- dexieCloud.version = "4.0.5";
6611
+ dexieCloud.version = "4.0.8";
6605
6612
  Dexie.Cloud = dexieCloud;
6606
6613
 
6607
6614
  exports.default = dexieCloud;