dexie-cloud-addon 4.0.1-beta.58 → 4.0.1-rc.2

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.1-beta.58, Tue Feb 20 2024
11
+ * Version 4.0.1-rc.2, Wed Mar 20 2024
12
12
  *
13
13
  * https://dexie.org
14
14
  *
@@ -16,7 +16,7 @@
16
16
  *
17
17
  */
18
18
 
19
- import Dexie, { cmp, liveQuery } from 'dexie';
19
+ import Dexie, { PropModification, cmp, liveQuery } from 'dexie';
20
20
  import { firstValueFrom, from as from$1, filter as filter$1, Observable as Observable$1, BehaviorSubject, Subject, fromEvent, of, merge, Subscription as Subscription$1, throwError, combineLatest, map as map$1, share, timer as timer$1 } from 'rxjs';
21
21
 
22
22
  /******************************************************************************
@@ -50,6 +50,18 @@ function __extends(d, b) {
50
50
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
51
51
  }
52
52
 
53
+ function __rest(s, e) {
54
+ var t = {};
55
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
56
+ t[p] = s[p];
57
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
58
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
59
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
60
+ t[p[i]] = s[p[i]];
61
+ }
62
+ return t;
63
+ }
64
+
53
65
  function __awaiter(thisArg, _arguments, P, generator) {
54
66
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
55
67
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -2602,16 +2614,11 @@ function login(db, hints) {
2602
2614
  const origUserId = currentUser.userId;
2603
2615
  if (currentUser.isLoggedIn && (!hints || (!hints.email && !hints.userId))) {
2604
2616
  const licenseStatus = ((_a = currentUser.license) === null || _a === void 0 ? void 0 : _a.status) || 'ok';
2605
- if (licenseStatus === 'ok' &&
2606
- currentUser.accessToken &&
2607
- (!currentUser.accessTokenExpiration ||
2608
- currentUser.accessTokenExpiration.getTime() > Date.now())) {
2617
+ if (licenseStatus === 'ok' && currentUser.accessToken && (!currentUser.accessTokenExpiration || currentUser.accessTokenExpiration.getTime() > Date.now())) {
2609
2618
  // Already authenticated according to given hints. And license is valid.
2610
2619
  return false;
2611
2620
  }
2612
- if (currentUser.refreshToken &&
2613
- (!currentUser.refreshTokenExpiration ||
2614
- currentUser.refreshTokenExpiration.getTime() > Date.now())) {
2621
+ if (currentUser.refreshToken && (!currentUser.refreshTokenExpiration || currentUser.refreshTokenExpiration.getTime() > Date.now())) {
2615
2622
  // Refresh the token
2616
2623
  yield loadAccessToken(db);
2617
2624
  return false;
@@ -2623,8 +2630,7 @@ function login(db, hints) {
2623
2630
  lastLogin: new Date(0),
2624
2631
  });
2625
2632
  yield authenticate(db.cloud.options.databaseUrl, context, db.cloud.options.fetchTokens || otpFetchTokenCallback(db), db.cloud.userInteraction, hints);
2626
- if (origUserId !== UNAUTHORIZED_USER.userId &&
2627
- context.userId !== origUserId) {
2633
+ if (origUserId !== UNAUTHORIZED_USER.userId && context.userId !== origUserId) {
2628
2634
  // User was logged in before, but now logged in as another user.
2629
2635
  yield logout(db);
2630
2636
  }
@@ -2643,7 +2649,7 @@ function login(db, hints) {
2643
2649
  yield setCurrentUser(db, context);
2644
2650
  // Make sure to resync as the new login will be authorized
2645
2651
  // for new realms.
2646
- triggerSync(db, 'pull');
2652
+ triggerSync(db, "pull");
2647
2653
  return context.userId !== origUserId;
2648
2654
  });
2649
2655
  }
@@ -3467,7 +3473,7 @@ class FakeBigInt {
3467
3473
  this.v = value;
3468
3474
  }
3469
3475
  }
3470
- const defs = Object.assign(Object.assign({}, undefinedDef), (hasBigIntSupport
3476
+ const defs = Object.assign(Object.assign(Object.assign({}, undefinedDef), (hasBigIntSupport
3471
3477
  ? {}
3472
3478
  : {
3473
3479
  bigint: {
@@ -3477,7 +3483,16 @@ const defs = Object.assign(Object.assign({}, undefinedDef), (hasBigIntSupport
3477
3483
  },
3478
3484
  revive: ({ v, }) => new FakeBigInt(v)
3479
3485
  }
3480
- }));
3486
+ })), { PropModification: {
3487
+ test: (val) => val instanceof PropModification,
3488
+ replace: (propModification) => {
3489
+ return Object.assign({ $t: 'PropModification' }, propModification);
3490
+ },
3491
+ revive: (_a) => {
3492
+ var propModification = __rest(_a, ["$t"]);
3493
+ return new PropModification(propModification);
3494
+ }
3495
+ } });
3481
3496
  const TSON = TypesonSimplified(builtin, defs);
3482
3497
  const BISON = Bison(defs);
3483
3498
 
@@ -5415,10 +5430,11 @@ function connectWebSocket(db) {
5415
5430
  }
5416
5431
  return new BehaviorSubject([userLogin, syncState]);
5417
5432
  }), switchMap(([userLogin, syncState]) => __awaiter(this, void 0, void 0, function* () { return [userLogin, yield computeRealmSetHash(syncState)]; })), distinctUntilChanged(([prevUser, prevHash], [currUser, currHash]) => prevUser === currUser && prevHash === currHash), switchMap(([userLogin, realmSetHash]) => {
5433
+ var _a;
5418
5434
  // Let server end query changes from last entry of same client-ID and forward.
5419
5435
  // If no new entries, server won't bother the client. If new entries, server sends only those
5420
5436
  // and the baseRev of the last from same client-ID.
5421
- if (userLogin) {
5437
+ if (userLogin && ((_a = db.cloud.persistedSyncState) === null || _a === void 0 ? void 0 : _a.value)) {
5422
5438
  return new WSObservable(db.cloud.options.databaseUrl, db.cloud.persistedSyncState.value.serverRevision, realmSetHash, db.cloud.persistedSyncState.value.clientIdentity, messageProducer, db.cloud.webSocketStatus, userLogin.accessToken, userLogin.accessTokenExpiration);
5423
5439
  }
5424
5440
  else {
@@ -6270,7 +6286,7 @@ function dexieCloud(dexie) {
6270
6286
  const syncComplete = new Subject();
6271
6287
  dexie.cloud = {
6272
6288
  // @ts-ignore
6273
- version: "4.0.1-beta.58",
6289
+ version: "4.0.1-rc.2",
6274
6290
  options: Object.assign({}, DEFAULT_OPTIONS),
6275
6291
  schema: null,
6276
6292
  get currentUserId() {
@@ -6501,10 +6517,7 @@ function dexieCloud(dexie) {
6501
6517
  // HERE: If requireAuth, do athentication now.
6502
6518
  let changedUser = false;
6503
6519
  if ((_c = db.cloud.options) === null || _c === void 0 ? void 0 : _c.requireAuth) {
6504
- const user = yield db.getCurrentUser();
6505
- if (!user.isLoggedIn) {
6506
- changedUser = yield login(db);
6507
- }
6520
+ changedUser = yield login(db);
6508
6521
  }
6509
6522
  if (localSyncWorker)
6510
6523
  localSyncWorker.stop();
@@ -6550,7 +6563,7 @@ function dexieCloud(dexie) {
6550
6563
  }
6551
6564
  }
6552
6565
  // @ts-ignore
6553
- dexieCloud.version = "4.0.1-beta.58";
6566
+ dexieCloud.version = "4.0.1-rc.2";
6554
6567
  Dexie.Cloud = dexieCloud;
6555
6568
 
6556
6569
  export { dexieCloud as default, dexieCloud, getTiedObjectId, getTiedRealmId, resolveText };