dexie-cloud-addon 4.0.7 → 4.0.11

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.
@@ -8,7 +8,7 @@
8
8
  *
9
9
  * ==========================================================================
10
10
  *
11
- * Version 4.0.7, Sun May 26 2024
11
+ * Version 4.0.11, Wed Jan 15 2025
12
12
  *
13
13
  * https://dexie.org
14
14
  *
@@ -2824,7 +2824,7 @@ var numberDef = {
2824
2824
  },
2825
2825
  };
2826
2826
 
2827
- const bigIntDef = {
2827
+ const bigIntDef$1 = {
2828
2828
  bigint: {
2829
2829
  replace: (realVal) => {
2830
2830
  return { $t: "bigint", v: "" + realVal };
@@ -3067,7 +3067,7 @@ var BlobDef = {
3067
3067
 
3068
3068
  const builtin = {
3069
3069
  ...numberDef,
3070
- ...bigIntDef,
3070
+ ...bigIntDef$1,
3071
3071
  ...DateDef,
3072
3072
  ...SetDef,
3073
3073
  ...MapDef,
@@ -3177,7 +3177,7 @@ class FakeBigInt {
3177
3177
  this.v = value;
3178
3178
  }
3179
3179
  }
3180
- const defs = Object.assign(Object.assign(Object.assign({}, undefinedDef), (hasBigIntSupport
3180
+ const bigIntDef = hasBigIntSupport
3181
3181
  ? {}
3182
3182
  : {
3183
3183
  bigint: {
@@ -3185,17 +3185,19 @@ const defs = Object.assign(Object.assign(Object.assign({}, undefinedDef), (hasBi
3185
3185
  replace: (fakeBigInt) => {
3186
3186
  return Object.assign({ $t: 'bigint' }, fakeBigInt);
3187
3187
  },
3188
- revive: ({ v, }) => new FakeBigInt(v)
3189
- }
3190
- })), { PropModification: {
3188
+ revive: ({ v }) => new FakeBigInt(v),
3189
+ },
3190
+ };
3191
+ const defs = Object.assign(Object.assign(Object.assign({}, undefinedDef), bigIntDef), { PropModification: {
3191
3192
  test: (val) => val instanceof PropModification,
3192
3193
  replace: (propModification) => {
3193
- return Object.assign({ $t: 'PropModification' }, propModification);
3194
+ return Object.assign({ $t: 'PropModification' }, propModification['@@propmod']);
3194
3195
  },
3195
3196
  revive: (_a) => {
3196
- var propModification = __rest(_a, ["$t"]);
3197
- return new PropModification(propModification);
3198
- }
3197
+ var propModSpec = __rest(_a, ["$t"]) // keep the rest
3198
+ ;
3199
+ return new PropModification(propModSpec);
3200
+ },
3199
3201
  } });
3200
3202
  const TSON = TypesonSimplified(builtin, defs);
3201
3203
  const BISON = Bison(defs);
@@ -3850,13 +3852,15 @@ function filterServerChangesThroughAddedClientChanges(serverChanges, addedClient
3850
3852
  return toDBOperationSet(changes);
3851
3853
  }
3852
3854
 
3855
+ const LIMIT_NUM_MESSAGES_PER_TIME = 10; // Allow a maximum of 10 messages per...
3856
+ const TIME_WINDOW = 10000; // ...10 seconds.
3857
+ const PAUSE_PERIOD = 1000; // Pause for 1 second if reached
3853
3858
  function MessagesFromServerConsumer(db) {
3854
3859
  const queue = [];
3855
3860
  const readyToServe = new BehaviorSubject(true);
3856
3861
  const event = new BehaviorSubject(null);
3857
3862
  let isWorking = false;
3858
- let loopWarning = 0;
3859
- let loopDetection = [0, 0, 0, 0, 0, 0, 0, 0, 0, Date.now()];
3863
+ let loopDetection = new Array(LIMIT_NUM_MESSAGES_PER_TIME).fill(0);
3860
3864
  event.subscribe(() => __awaiter(this, void 0, void 0, function* () {
3861
3865
  if (isWorking)
3862
3866
  return;
@@ -3870,20 +3874,11 @@ function MessagesFromServerConsumer(db) {
3870
3874
  }
3871
3875
  finally {
3872
3876
  if (loopDetection[loopDetection.length - 1] - loopDetection[0] <
3873
- 10000) {
3877
+ TIME_WINDOW) {
3874
3878
  // Ten loops within 10 seconds. Slow down!
3875
- if (Date.now() - loopWarning < 5000) {
3876
- // Last time we did this, we ended up here too. Wait for a minute.
3877
- console.warn(`Slowing down websocket loop for one minute`);
3878
- loopWarning = Date.now() + 60000;
3879
- yield new Promise((resolve) => setTimeout(resolve, 60000));
3880
- }
3881
- else {
3882
- // This is a one-time event. Just pause 10 seconds.
3883
- console.warn(`Slowing down websocket loop for 10 seconds`);
3884
- loopWarning = Date.now() + 10000;
3885
- yield new Promise((resolve) => setTimeout(resolve, 10000));
3886
- }
3879
+ // This is a one-time event. Just pause 10 seconds.
3880
+ console.warn(`Slowing down websocket loop for ${PAUSE_PERIOD} milliseconds`);
3881
+ yield new Promise((resolve) => setTimeout(resolve, PAUSE_PERIOD));
3887
3882
  }
3888
3883
  isWorking = false;
3889
3884
  readyToServe.next(true);
@@ -6310,7 +6305,7 @@ function dexieCloud(dexie) {
6310
6305
  const syncComplete = new Subject();
6311
6306
  dexie.cloud = {
6312
6307
  // @ts-ignore
6313
- version: "4.0.7",
6308
+ version: "4.0.11",
6314
6309
  options: Object.assign({}, DEFAULT_OPTIONS),
6315
6310
  schema: null,
6316
6311
  get currentUserId() {
@@ -6537,8 +6532,19 @@ function dexieCloud(dexie) {
6537
6532
  // HERE: If requireAuth, do athentication now.
6538
6533
  let changedUser = false;
6539
6534
  const user = yield db.getCurrentUser();
6540
- if ((_c = db.cloud.options) === null || _c === void 0 ? void 0 : _c.requireAuth) {
6541
- if (!user.isLoggedIn) {
6535
+ const requireAuth = (_c = db.cloud.options) === null || _c === void 0 ? void 0 : _c.requireAuth;
6536
+ if (requireAuth) {
6537
+ if (typeof requireAuth === 'object') {
6538
+ // requireAuth contains login hints. Check if we already fulfil it:
6539
+ if (!user.isLoggedIn ||
6540
+ (requireAuth.userId && user.userId !== requireAuth.userId) ||
6541
+ (requireAuth.email && user.email !== requireAuth.email)) {
6542
+ // If not, login the configured user:
6543
+ changedUser = yield login(db, requireAuth);
6544
+ }
6545
+ }
6546
+ else if (!user.isLoggedIn) {
6547
+ // requireAuth is true and user is not logged in
6542
6548
  changedUser = yield login(db);
6543
6549
  }
6544
6550
  }
@@ -6594,7 +6600,7 @@ function dexieCloud(dexie) {
6594
6600
  }
6595
6601
  }
6596
6602
  // @ts-ignore
6597
- dexieCloud.version = "4.0.7";
6603
+ dexieCloud.version = "4.0.11";
6598
6604
  Dexie.Cloud = dexieCloud;
6599
6605
 
6600
6606
  // In case the SW lives for a while, let it reuse already opened connections: