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
  *
@@ -2990,8 +2990,8 @@
2990
2990
  });
2991
2991
  }
2992
2992
  function registerPeriodicSyncEvent(db) {
2993
- var _a;
2994
2993
  return __awaiter(this, void 0, void 0, function* () {
2994
+ var _a;
2995
2995
  try {
2996
2996
  // Register periodicSync event to SW:
2997
2997
  // @ts-ignore
@@ -3202,8 +3202,8 @@
3202
3202
  }
3203
3203
 
3204
3204
  function loadAccessToken(db) {
3205
- var _a, _b, _c;
3206
3205
  return __awaiter(this, void 0, void 0, function* () {
3206
+ var _a, _b, _c;
3207
3207
  const currentUser = yield db.getCurrentUser();
3208
3208
  const { accessToken, accessTokenExpiration, refreshToken, refreshTokenExpiration, claims, } = currentUser;
3209
3209
  if (!accessToken)
@@ -3475,8 +3475,8 @@
3475
3475
  }
3476
3476
  });
3477
3477
  }
3478
- function _logout(db, { deleteUnsyncedData = false } = {}) {
3479
- return __awaiter(this, void 0, void 0, function* () {
3478
+ function _logout(db_1) {
3479
+ return __awaiter(this, arguments, void 0, function* (db, { deleteUnsyncedData = false } = {}) {
3480
3480
  // Clear the database without emptying configuration options.
3481
3481
  const [numUnsynced, loggedOut] = yield db.dx.transaction('rw', db.dx.tables, (tx) => __awaiter(this, void 0, void 0, function* () {
3482
3482
  // @ts-ignore
@@ -3524,11 +3524,11 @@
3524
3524
 
3525
3525
  function otpFetchTokenCallback(db) {
3526
3526
  const { userInteraction } = db.cloud;
3527
- return function otpAuthenticate({ public_key, hints }) {
3528
- var _a;
3529
- return __awaiter(this, void 0, void 0, function* () {
3527
+ return function otpAuthenticate(_a) {
3528
+ return __awaiter(this, arguments, void 0, function* ({ public_key, hints }) {
3529
+ var _b;
3530
3530
  let tokenRequest;
3531
- const url = (_a = db.cloud.options) === null || _a === void 0 ? void 0 : _a.databaseUrl;
3531
+ const url = (_b = db.cloud.options) === null || _b === void 0 ? void 0 : _b.databaseUrl;
3532
3532
  if (!url)
3533
3533
  throw new Error(`No database URL given.`);
3534
3534
  if ((hints === null || hints === void 0 ? void 0 : hints.grant_type) === 'demo') {
@@ -3694,8 +3694,8 @@
3694
3694
  }
3695
3695
 
3696
3696
  function login(db, hints) {
3697
- var _a;
3698
3697
  return __awaiter(this, void 0, void 0, function* () {
3698
+ var _a;
3699
3699
  const currentUser = yield db.getCurrentUser();
3700
3700
  const origUserId = currentUser.userId;
3701
3701
  if (currentUser.isLoggedIn && (!hints || (!hints.email && !hints.userId))) {
@@ -3883,8 +3883,8 @@
3883
3883
  }
3884
3884
  }
3885
3885
 
3886
- function computeRealmSetHash({ realms, inviteRealms, }) {
3887
- return __awaiter(this, void 0, void 0, function* () {
3886
+ function computeRealmSetHash(_a) {
3887
+ return __awaiter(this, arguments, void 0, function* ({ realms, inviteRealms, }) {
3888
3888
  const data = JSON.stringify([
3889
3889
  ...realms.map((realmId) => ({ realmId, accepted: true })),
3890
3890
  ...inviteRealms.map((realmId) => ({ realmId, accepted: false })),
@@ -3920,8 +3920,8 @@
3920
3920
  return concat.apply([], a);
3921
3921
  }
3922
3922
 
3923
- function listClientChanges(mutationTables, db, { since = {}, limit = Infinity } = {}) {
3924
- return __awaiter(this, void 0, void 0, function* () {
3923
+ function listClientChanges(mutationTables_1, db_1) {
3924
+ return __awaiter(this, arguments, void 0, function* (mutationTables, db, { since = {}, limit = Infinity } = {}) {
3925
3925
  const allMutsOnTables = yield Promise.all(mutationTables.map((mutationTable) => __awaiter(this, void 0, void 0, function* () {
3926
3926
  const tableName = getTableFromMutationTable(mutationTable.name);
3927
3927
  const lastRevision = since[tableName];
@@ -4656,8 +4656,8 @@
4656
4656
  // seconds (given that there is a Ratelimit-Reset header).
4657
4657
  let syncRatelimitDelays = new WeakMap();
4658
4658
  function checkSyncRateLimitDelay(db) {
4659
- var _a, _b;
4660
4659
  return __awaiter(this, void 0, void 0, function* () {
4660
+ var _a, _b;
4661
4661
  const delatMilliseconds = ((_b = (_a = syncRatelimitDelays.get(db)) === null || _a === void 0 ? void 0 : _a.getTime()) !== null && _b !== void 0 ? _b : 0) - Date.now();
4662
4662
  if (delatMilliseconds > 0) {
4663
4663
  console.debug(`Stalling sync request ${delatMilliseconds} ms to spare ratelimits`);
@@ -5061,8 +5061,8 @@
5061
5061
  }
5062
5062
 
5063
5063
  function applyYServerMessages(yMessages, db) {
5064
- var _a;
5065
5064
  return __awaiter(this, void 0, void 0, function* () {
5065
+ var _a;
5066
5066
  const result = {};
5067
5067
  for (const m of yMessages) {
5068
5068
  switch (m.type) {
@@ -5127,8 +5127,8 @@
5127
5127
  }
5128
5128
 
5129
5129
  function updateYSyncStates(lastUpdateIdsBeforeSync, receivedUntilsAfterSync, db, serverRevision) {
5130
- var _a, _b, _c, _d, _e;
5131
5130
  return __awaiter(this, void 0, void 0, function* () {
5131
+ var _a, _b, _c, _d, _e;
5132
5132
  // We want to update unsentFrom for each yTable to the value specified in first argument
5133
5133
  // because we got those values before we synced with server and here we are back from server
5134
5134
  // that has successfully received all those messages - no matter if the last update was a client or server update,
@@ -5193,8 +5193,8 @@
5193
5193
  const BINSTREAM_TYPE_REALMID = 1;
5194
5194
  const BINSTREAM_TYPE_TABLE_AND_PROP = 2;
5195
5195
  const BINSTREAM_TYPE_DOCUMENT = 3;
5196
- function downloadYDocsFromServer(db, databaseUrl, { yDownloadedRealms, realms }) {
5197
- return __awaiter(this, void 0, void 0, function* () {
5196
+ function downloadYDocsFromServer(db_1, databaseUrl_1, _a) {
5197
+ return __awaiter(this, arguments, void 0, function* (db, databaseUrl, { yDownloadedRealms, realms }) {
5198
5198
  if (yDownloadedRealms &&
5199
5199
  realms &&
5200
5200
  realms.every((realmId) => yDownloadedRealms[realmId] === '*')) {
@@ -5352,11 +5352,11 @@
5352
5352
  return Promise.reject(error);
5353
5353
  }));
5354
5354
  }
5355
- function _sync(db, options, schema, { isInitialSync, cancelToken, justCheckIfNeeded, purpose } = {
5356
- isInitialSync: false,
5357
- }) {
5358
- var _a;
5359
- return __awaiter(this, void 0, void 0, function* () {
5355
+ function _sync(db_1, options_1, schema_1) {
5356
+ return __awaiter(this, arguments, void 0, function* (db, options, schema, { isInitialSync, cancelToken, justCheckIfNeeded, purpose } = {
5357
+ isInitialSync: false,
5358
+ }) {
5359
+ var _a;
5360
5360
  if (!justCheckIfNeeded) {
5361
5361
  console.debug('SYNC STARTED', { isInitialSync, purpose });
5362
5362
  }
@@ -5398,7 +5398,7 @@
5398
5398
  const [clientChangeSet, syncState, baseRevs, { yMessages, lastUpdateIds }] = yield db.transaction('r', db.tables, () => __awaiter(this, void 0, void 0, function* () {
5399
5399
  const syncState = yield db.getPersistedSyncState();
5400
5400
  const baseRevs = yield db.$baseRevs.toArray();
5401
- let clientChanges = yield listClientChanges(mutationTables);
5401
+ let clientChanges = yield listClientChanges(mutationTables, db);
5402
5402
  const yResults = yield listYClientMessagesAndStateVector(db, tablesToSync);
5403
5403
  throwIfCancelled(cancelToken);
5404
5404
  if (doSyncify) {
@@ -5667,8 +5667,8 @@
5667
5667
  event.next(null);
5668
5668
  }
5669
5669
  function consumeQueue() {
5670
- var _a, _b, _c, _d, _e, _f;
5671
5670
  return __awaiter(this, void 0, void 0, function* () {
5671
+ var _a, _b, _c, _d, _e, _f;
5672
5672
  while (queue.length > 0) {
5673
5673
  const msg = queue.shift();
5674
5674
  try {
@@ -7100,7 +7100,7 @@
7100
7100
  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]));
7101
7101
  }
7102
7102
  return new rxjs.BehaviorSubject([userLogin, syncState]);
7103
- }), 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]) => {
7103
+ }), 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]) => {
7104
7104
  var _a;
7105
7105
  if (!((_a = db.cloud.persistedSyncState) === null || _a === void 0 ? void 0 : _a.value)) {
7106
7106
  // Restart the flow if persistedSyncState is not yet available.
@@ -7161,8 +7161,8 @@
7161
7161
  }
7162
7162
 
7163
7163
  function isSyncNeeded(db) {
7164
- var _a;
7165
7164
  return __awaiter(this, void 0, void 0, function* () {
7165
+ var _a;
7166
7166
  return ((_a = db.cloud.options) === null || _a === void 0 ? void 0 : _a.databaseUrl) && db.cloud.schema
7167
7167
  ? yield sync(db, db.cloud.options, db.cloud.schema, { justCheckIfNeeded: true })
7168
7168
  : false;
@@ -7846,6 +7846,7 @@
7846
7846
  // If user can update any prop in any table in this realm, return true unless
7847
7847
  // it regards to ownership change:
7848
7848
  if (this.permissions.update === '*') {
7849
+ // @ts-ignore
7849
7850
  return props.every((prop) => prop !== 'owner');
7850
7851
  }
7851
7852
  const tablePermissions = (_b = this.permissions.update) === null || _b === void 0 ? void 0 : _b[this.tableName];
@@ -7929,8 +7930,8 @@
7929
7930
  get() {
7930
7931
  if (awareness)
7931
7932
  return awareness;
7932
- awarenessWeakMap.set(doc, awareness);
7933
7933
  awareness = createAwareness(db, doc, provider);
7934
+ awarenessWeakMap.set(doc, awareness);
7934
7935
  return awareness;
7935
7936
  }
7936
7937
  });
@@ -8099,7 +8100,7 @@
8099
8100
  const syncComplete = new rxjs.Subject();
8100
8101
  dexie.cloud = {
8101
8102
  // @ts-ignore
8102
- version: "4.1.0-alpha.19",
8103
+ version: "4.1.0-alpha.20",
8103
8104
  options: Object.assign({}, DEFAULT_OPTIONS),
8104
8105
  schema: null,
8105
8106
  get currentUserId() {
@@ -8135,16 +8136,16 @@
8135
8136
  }
8136
8137
  updateSchemaFromOptions(dexie.cloud.schema, dexie.cloud.options);
8137
8138
  },
8138
- logout({ force } = {}) {
8139
- return __awaiter(this, void 0, void 0, function* () {
8139
+ logout() {
8140
+ return __awaiter(this, arguments, void 0, function* ({ force } = {}) {
8140
8141
  force
8141
8142
  ? yield _logout(DexieCloudDB(dexie), { deleteUnsyncedData: true })
8142
8143
  : yield logout(DexieCloudDB(dexie));
8143
8144
  });
8144
8145
  },
8145
- sync({ wait, purpose } = { wait: true, purpose: 'push' }) {
8146
- var _a;
8147
- return __awaiter(this, void 0, void 0, function* () {
8146
+ sync() {
8147
+ return __awaiter(this, arguments, void 0, function* ({ wait, purpose } = { wait: true, purpose: 'push' }) {
8148
+ var _a;
8148
8149
  if (wait === undefined)
8149
8150
  wait = true;
8150
8151
  const db = DexieCloudDB(dexie);
@@ -8202,8 +8203,8 @@
8202
8203
  dexie.use(createImplicitPropSetterMiddleware(DexieCloudDB(dexie)));
8203
8204
  dexie.use(createIdGenerationMiddleware(DexieCloudDB(dexie)));
8204
8205
  function onDbReady(dexie) {
8205
- var _a, _b, _c, _d, _e, _f, _g;
8206
8206
  return __awaiter(this, void 0, void 0, function* () {
8207
+ var _a, _b, _c, _d, _e, _f, _g;
8207
8208
  closed = false; // As Dexie calls us, we are not closed anymore. Maybe reopened? Remember db.ready event is registered with sticky flag!
8208
8209
  const db = DexieCloudDB(dexie);
8209
8210
  // Setup default GUI:
@@ -8226,7 +8227,7 @@
8226
8227
  ? yield navigator.serviceWorker.getRegistrations()
8227
8228
  : [];
8228
8229
  const [initiallySynced, lastSyncedRealms] = yield db.transaction('rw', db.$syncState, () => __awaiter(this, void 0, void 0, function* () {
8229
- var _h, _j;
8230
+ var _a, _b;
8230
8231
  const { options, schema } = db.cloud;
8231
8232
  const [persistedOptions, persistedSchema, persistedSyncState] = yield Promise.all([
8232
8233
  db.getOptions(),
@@ -8248,7 +8249,7 @@
8248
8249
  delete newPersistedOptions.awarenessProtocol;
8249
8250
  yield db.$syncState.put(newPersistedOptions, 'options');
8250
8251
  }
8251
- if (((_h = db.cloud.options) === null || _h === void 0 ? void 0 : _h.tryUseServiceWorker) &&
8252
+ if (((_a = db.cloud.options) === null || _a === void 0 ? void 0 : _a.tryUseServiceWorker) &&
8252
8253
  'serviceWorker' in navigator &&
8253
8254
  swRegistrations.length > 0 &&
8254
8255
  !DISABLE_SERVICEWORKER_STRATEGY) {
@@ -8262,7 +8263,7 @@
8262
8263
  // Not configured for using service worker or no service worker
8263
8264
  // registration exists. Don't rely on service worker to do any job.
8264
8265
  // Use LocalSyncWorker instead.
8265
- if (((_j = db.cloud.options) === null || _j === void 0 ? void 0 : _j.tryUseServiceWorker) &&
8266
+ if (((_b = db.cloud.options) === null || _b === void 0 ? void 0 : _b.tryUseServiceWorker) &&
8266
8267
  !db.cloud.isServiceWorkerDB) {
8267
8268
  console.debug('dexie-cloud-addon: Not using service worker.', swRegistrations.length === 0
8268
8269
  ? 'No SW registrations found.'
@@ -8401,7 +8402,7 @@
8401
8402
  }
8402
8403
  }
8403
8404
  // @ts-ignore
8404
- dexieCloud.version = "4.1.0-alpha.19";
8405
+ dexieCloud.version = "4.1.0-alpha.20";
8405
8406
  Dexie.Cloud = dexieCloud;
8406
8407
 
8407
8408
  const ydocTriggers = {};