dexie-cloud-addon 4.1.0-alpha.19 → 4.1.0-alpha.20

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.
@@ -6,7 +6,7 @@ export declare class FakeBigInt {
6
6
  constructor(value: string);
7
7
  }
8
8
  export declare const TSON: {
9
- stringify(value: any, alternateChannel?: any, space?: number | undefined): string;
9
+ stringify(value: any, alternateChannel?: any, space?: number): string;
10
10
  parse(tson: string, alternateChannel?: any): any;
11
11
  };
12
12
  export declare const BISON: {
@@ -8,7 +8,7 @@
8
8
  *
9
9
  * ==========================================================================
10
10
  *
11
- * Version 4.1.0-alpha.19, Fri Oct 18 2024
11
+ * Version 4.1.0-alpha.20, Wed Oct 23 2024
12
12
  *
13
13
  * https://dexie.org
14
14
  *
@@ -2987,8 +2987,8 @@ function registerSyncEvent(db, purpose) {
2987
2987
  });
2988
2988
  }
2989
2989
  function registerPeriodicSyncEvent(db) {
2990
- var _a;
2991
2990
  return __awaiter(this, void 0, void 0, function* () {
2991
+ var _a;
2992
2992
  try {
2993
2993
  // Register periodicSync event to SW:
2994
2994
  // @ts-ignore
@@ -3199,8 +3199,8 @@ function confirmLogout(userInteraction, currentUserId, numUnsyncedChanges) {
3199
3199
  }
3200
3200
 
3201
3201
  function loadAccessToken(db) {
3202
- var _a, _b, _c;
3203
3202
  return __awaiter(this, void 0, void 0, function* () {
3203
+ var _a, _b, _c;
3204
3204
  const currentUser = yield db.getCurrentUser();
3205
3205
  const { accessToken, accessTokenExpiration, refreshToken, refreshTokenExpiration, claims, } = currentUser;
3206
3206
  if (!accessToken)
@@ -3472,8 +3472,8 @@ function logout(db) {
3472
3472
  }
3473
3473
  });
3474
3474
  }
3475
- function _logout(db, { deleteUnsyncedData = false } = {}) {
3476
- return __awaiter(this, void 0, void 0, function* () {
3475
+ function _logout(db_1) {
3476
+ return __awaiter(this, arguments, void 0, function* (db, { deleteUnsyncedData = false } = {}) {
3477
3477
  // Clear the database without emptying configuration options.
3478
3478
  const [numUnsynced, loggedOut] = yield db.dx.transaction('rw', db.dx.tables, (tx) => __awaiter(this, void 0, void 0, function* () {
3479
3479
  // @ts-ignore
@@ -3521,11 +3521,11 @@ class HttpError extends Error {
3521
3521
 
3522
3522
  function otpFetchTokenCallback(db) {
3523
3523
  const { userInteraction } = db.cloud;
3524
- return function otpAuthenticate({ public_key, hints }) {
3525
- var _a;
3526
- return __awaiter(this, void 0, void 0, function* () {
3524
+ return function otpAuthenticate(_a) {
3525
+ return __awaiter(this, arguments, void 0, function* ({ public_key, hints }) {
3526
+ var _b;
3527
3527
  let tokenRequest;
3528
- const url = (_a = db.cloud.options) === null || _a === void 0 ? void 0 : _a.databaseUrl;
3528
+ const url = (_b = db.cloud.options) === null || _b === void 0 ? void 0 : _b.databaseUrl;
3529
3529
  if (!url)
3530
3530
  throw new Error(`No database URL given.`);
3531
3531
  if ((hints === null || hints === void 0 ? void 0 : hints.grant_type) === 'demo') {
@@ -3691,8 +3691,8 @@ function setCurrentUser(db, user) {
3691
3691
  }
3692
3692
 
3693
3693
  function login(db, hints) {
3694
- var _a;
3695
3694
  return __awaiter(this, void 0, void 0, function* () {
3695
+ var _a;
3696
3696
  const currentUser = yield db.getCurrentUser();
3697
3697
  const origUserId = currentUser.userId;
3698
3698
  if (currentUser.isLoggedIn && (!hints || (!hints.email && !hints.userId))) {
@@ -3880,8 +3880,8 @@ class BroadcastedAndLocalEvent extends Observable$1 {
3880
3880
  }
3881
3881
  }
3882
3882
 
3883
- function computeRealmSetHash({ realms, inviteRealms, }) {
3884
- return __awaiter(this, void 0, void 0, function* () {
3883
+ function computeRealmSetHash(_a) {
3884
+ return __awaiter(this, arguments, void 0, function* ({ realms, inviteRealms, }) {
3885
3885
  const data = JSON.stringify([
3886
3886
  ...realms.map((realmId) => ({ realmId, accepted: true })),
3887
3887
  ...inviteRealms.map((realmId) => ({ realmId, accepted: false })),
@@ -3917,8 +3917,8 @@ function flatten(a) {
3917
3917
  return concat.apply([], a);
3918
3918
  }
3919
3919
 
3920
- function listClientChanges(mutationTables, db, { since = {}, limit = Infinity } = {}) {
3921
- return __awaiter(this, void 0, void 0, function* () {
3920
+ function listClientChanges(mutationTables_1, db_1) {
3921
+ return __awaiter(this, arguments, void 0, function* (mutationTables, db, { since = {}, limit = Infinity } = {}) {
3922
3922
  const allMutsOnTables = yield Promise.all(mutationTables.map((mutationTable) => __awaiter(this, void 0, void 0, function* () {
3923
3923
  const tableName = getTableFromMutationTable(mutationTable.name);
3924
3924
  const lastRevision = since[tableName];
@@ -4653,8 +4653,8 @@ function cloneChange(change, rewriteValues) {
4653
4653
  // seconds (given that there is a Ratelimit-Reset header).
4654
4654
  let syncRatelimitDelays = new WeakMap();
4655
4655
  function checkSyncRateLimitDelay(db) {
4656
- var _a, _b;
4657
4656
  return __awaiter(this, void 0, void 0, function* () {
4657
+ var _a, _b;
4658
4658
  const delatMilliseconds = ((_b = (_a = syncRatelimitDelays.get(db)) === null || _a === void 0 ? void 0 : _a.getTime()) !== null && _b !== void 0 ? _b : 0) - Date.now();
4659
4659
  if (delatMilliseconds > 0) {
4660
4660
  console.debug(`Stalling sync request ${delatMilliseconds} ms to spare ratelimits`);
@@ -5058,8 +5058,8 @@ function getUpdatesTable(db, table, ydocProp) {
5058
5058
  }
5059
5059
 
5060
5060
  function applyYServerMessages(yMessages, db) {
5061
- var _a;
5062
5061
  return __awaiter(this, void 0, void 0, function* () {
5062
+ var _a;
5063
5063
  const result = {};
5064
5064
  for (const m of yMessages) {
5065
5065
  switch (m.type) {
@@ -5124,8 +5124,8 @@ function applyYServerMessages(yMessages, db) {
5124
5124
  }
5125
5125
 
5126
5126
  function updateYSyncStates(lastUpdateIdsBeforeSync, receivedUntilsAfterSync, db, serverRevision) {
5127
- var _a, _b, _c, _d, _e;
5128
5127
  return __awaiter(this, void 0, void 0, function* () {
5128
+ var _a, _b, _c, _d, _e;
5129
5129
  // We want to update unsentFrom for each yTable to the value specified in first argument
5130
5130
  // because we got those values before we synced with server and here we are back from server
5131
5131
  // that has successfully received all those messages - no matter if the last update was a client or server update,
@@ -5190,8 +5190,8 @@ function updateYSyncStates(lastUpdateIdsBeforeSync, receivedUntilsAfterSync, db,
5190
5190
  const BINSTREAM_TYPE_REALMID = 1;
5191
5191
  const BINSTREAM_TYPE_TABLE_AND_PROP = 2;
5192
5192
  const BINSTREAM_TYPE_DOCUMENT = 3;
5193
- function downloadYDocsFromServer(db, databaseUrl, { yDownloadedRealms, realms }) {
5194
- return __awaiter(this, void 0, void 0, function* () {
5193
+ function downloadYDocsFromServer(db_1, databaseUrl_1, _a) {
5194
+ return __awaiter(this, arguments, void 0, function* (db, databaseUrl, { yDownloadedRealms, realms }) {
5195
5195
  if (yDownloadedRealms &&
5196
5196
  realms &&
5197
5197
  realms.every((realmId) => yDownloadedRealms[realmId] === '*')) {
@@ -5349,11 +5349,11 @@ function sync(db, options, schema, syncOptions) {
5349
5349
  return Promise.reject(error);
5350
5350
  }));
5351
5351
  }
5352
- function _sync(db, options, schema, { isInitialSync, cancelToken, justCheckIfNeeded, purpose } = {
5353
- isInitialSync: false,
5354
- }) {
5355
- var _a;
5356
- return __awaiter(this, void 0, void 0, function* () {
5352
+ function _sync(db_1, options_1, schema_1) {
5353
+ return __awaiter(this, arguments, void 0, function* (db, options, schema, { isInitialSync, cancelToken, justCheckIfNeeded, purpose } = {
5354
+ isInitialSync: false,
5355
+ }) {
5356
+ var _a;
5357
5357
  if (!justCheckIfNeeded) {
5358
5358
  console.debug('SYNC STARTED', { isInitialSync, purpose });
5359
5359
  }
@@ -5395,7 +5395,7 @@ function _sync(db, options, schema, { isInitialSync, cancelToken, justCheckIfNee
5395
5395
  const [clientChangeSet, syncState, baseRevs, { yMessages, lastUpdateIds }] = yield db.transaction('r', db.tables, () => __awaiter(this, void 0, void 0, function* () {
5396
5396
  const syncState = yield db.getPersistedSyncState();
5397
5397
  const baseRevs = yield db.$baseRevs.toArray();
5398
- let clientChanges = yield listClientChanges(mutationTables);
5398
+ let clientChanges = yield listClientChanges(mutationTables, db);
5399
5399
  const yResults = yield listYClientMessagesAndStateVector(db, tablesToSync);
5400
5400
  throwIfCancelled(cancelToken);
5401
5401
  if (doSyncify) {
@@ -5664,8 +5664,8 @@ function MessagesFromServerConsumer(db) {
5664
5664
  event.next(null);
5665
5665
  }
5666
5666
  function consumeQueue() {
5667
- var _a, _b, _c, _d, _e, _f;
5668
5667
  return __awaiter(this, void 0, void 0, function* () {
5668
+ var _a, _b, _c, _d, _e, _f;
5669
5669
  while (queue.length > 0) {
5670
5670
  const msg = queue.shift();
5671
5671
  try {
@@ -7097,7 +7097,7 @@ function connectWebSocket(db) {
7097
7097
  return db.cloud.persistedSyncState.pipe(filter((syncState) => (syncState === null || syncState === void 0 ? void 0 : syncState.realms.includes(userLogin.userId)) || false), take(1), map((syncState) => [userLogin, syncState]));
7098
7098
  }
7099
7099
  return new BehaviorSubject([userLogin, syncState]);
7100
- }), 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]) => {
7100
+ }), switchMap((_a) => __awaiter(this, [_a], void 0, function* ([userLogin, syncState]) { return [userLogin, yield computeRealmSetHash(syncState)]; })), distinctUntilChanged(([prevUser, prevHash], [currUser, currHash]) => prevUser === currUser && prevHash === currHash), switchMap(([userLogin, realmSetHash]) => {
7101
7101
  var _a;
7102
7102
  if (!((_a = db.cloud.persistedSyncState) === null || _a === void 0 ? void 0 : _a.value)) {
7103
7103
  // Restart the flow if persistedSyncState is not yet available.
@@ -7158,8 +7158,8 @@ function connectWebSocket(db) {
7158
7158
  }
7159
7159
 
7160
7160
  function isSyncNeeded(db) {
7161
- var _a;
7162
7161
  return __awaiter(this, void 0, void 0, function* () {
7162
+ var _a;
7163
7163
  return ((_a = db.cloud.options) === null || _a === void 0 ? void 0 : _a.databaseUrl) && db.cloud.schema
7164
7164
  ? yield sync(db, db.cloud.options, db.cloud.schema, { justCheckIfNeeded: true })
7165
7165
  : false;
@@ -7843,6 +7843,7 @@ class PermissionChecker {
7843
7843
  // If user can update any prop in any table in this realm, return true unless
7844
7844
  // it regards to ownership change:
7845
7845
  if (this.permissions.update === '*') {
7846
+ // @ts-ignore
7846
7847
  return props.every((prop) => prop !== 'owner');
7847
7848
  }
7848
7849
  const tablePermissions = (_b = this.permissions.update) === null || _b === void 0 ? void 0 : _b[this.tableName];
@@ -7926,8 +7927,8 @@ function createYHandler(db) {
7926
7927
  get() {
7927
7928
  if (awareness)
7928
7929
  return awareness;
7929
- awarenessWeakMap.set(doc, awareness);
7930
7930
  awareness = createAwareness(db, doc, provider);
7931
+ awarenessWeakMap.set(doc, awareness);
7931
7932
  return awareness;
7932
7933
  }
7933
7934
  });
@@ -8096,7 +8097,7 @@ function dexieCloud(dexie) {
8096
8097
  const syncComplete = new Subject();
8097
8098
  dexie.cloud = {
8098
8099
  // @ts-ignore
8099
- version: "4.1.0-alpha.19",
8100
+ version: "4.1.0-alpha.20",
8100
8101
  options: Object.assign({}, DEFAULT_OPTIONS),
8101
8102
  schema: null,
8102
8103
  get currentUserId() {
@@ -8132,16 +8133,16 @@ function dexieCloud(dexie) {
8132
8133
  }
8133
8134
  updateSchemaFromOptions(dexie.cloud.schema, dexie.cloud.options);
8134
8135
  },
8135
- logout({ force } = {}) {
8136
- return __awaiter(this, void 0, void 0, function* () {
8136
+ logout() {
8137
+ return __awaiter(this, arguments, void 0, function* ({ force } = {}) {
8137
8138
  force
8138
8139
  ? yield _logout(DexieCloudDB(dexie), { deleteUnsyncedData: true })
8139
8140
  : yield logout(DexieCloudDB(dexie));
8140
8141
  });
8141
8142
  },
8142
- sync({ wait, purpose } = { wait: true, purpose: 'push' }) {
8143
- var _a;
8144
- return __awaiter(this, void 0, void 0, function* () {
8143
+ sync() {
8144
+ return __awaiter(this, arguments, void 0, function* ({ wait, purpose } = { wait: true, purpose: 'push' }) {
8145
+ var _a;
8145
8146
  if (wait === undefined)
8146
8147
  wait = true;
8147
8148
  const db = DexieCloudDB(dexie);
@@ -8199,8 +8200,8 @@ function dexieCloud(dexie) {
8199
8200
  dexie.use(createImplicitPropSetterMiddleware(DexieCloudDB(dexie)));
8200
8201
  dexie.use(createIdGenerationMiddleware(DexieCloudDB(dexie)));
8201
8202
  function onDbReady(dexie) {
8202
- var _a, _b, _c, _d, _e, _f, _g;
8203
8203
  return __awaiter(this, void 0, void 0, function* () {
8204
+ var _a, _b, _c, _d, _e, _f, _g;
8204
8205
  closed = false; // As Dexie calls us, we are not closed anymore. Maybe reopened? Remember db.ready event is registered with sticky flag!
8205
8206
  const db = DexieCloudDB(dexie);
8206
8207
  // Setup default GUI:
@@ -8223,7 +8224,7 @@ function dexieCloud(dexie) {
8223
8224
  ? yield navigator.serviceWorker.getRegistrations()
8224
8225
  : [];
8225
8226
  const [initiallySynced, lastSyncedRealms] = yield db.transaction('rw', db.$syncState, () => __awaiter(this, void 0, void 0, function* () {
8226
- var _h, _j;
8227
+ var _a, _b;
8227
8228
  const { options, schema } = db.cloud;
8228
8229
  const [persistedOptions, persistedSchema, persistedSyncState] = yield Promise.all([
8229
8230
  db.getOptions(),
@@ -8245,7 +8246,7 @@ function dexieCloud(dexie) {
8245
8246
  delete newPersistedOptions.awarenessProtocol;
8246
8247
  yield db.$syncState.put(newPersistedOptions, 'options');
8247
8248
  }
8248
- if (((_h = db.cloud.options) === null || _h === void 0 ? void 0 : _h.tryUseServiceWorker) &&
8249
+ if (((_a = db.cloud.options) === null || _a === void 0 ? void 0 : _a.tryUseServiceWorker) &&
8249
8250
  'serviceWorker' in navigator &&
8250
8251
  swRegistrations.length > 0 &&
8251
8252
  !DISABLE_SERVICEWORKER_STRATEGY) {
@@ -8259,7 +8260,7 @@ function dexieCloud(dexie) {
8259
8260
  // Not configured for using service worker or no service worker
8260
8261
  // registration exists. Don't rely on service worker to do any job.
8261
8262
  // Use LocalSyncWorker instead.
8262
- if (((_j = db.cloud.options) === null || _j === void 0 ? void 0 : _j.tryUseServiceWorker) &&
8263
+ if (((_b = db.cloud.options) === null || _b === void 0 ? void 0 : _b.tryUseServiceWorker) &&
8263
8264
  !db.cloud.isServiceWorkerDB) {
8264
8265
  console.debug('dexie-cloud-addon: Not using service worker.', swRegistrations.length === 0
8265
8266
  ? 'No SW registrations found.'
@@ -8398,7 +8399,7 @@ function dexieCloud(dexie) {
8398
8399
  }
8399
8400
  }
8400
8401
  // @ts-ignore
8401
- dexieCloud.version = "4.1.0-alpha.19";
8402
+ dexieCloud.version = "4.1.0-alpha.20";
8402
8403
  Dexie.Cloud = dexieCloud;
8403
8404
 
8404
8405
  const ydocTriggers = {};