dexie-cloud-addon 4.1.0-beta.42 → 4.1.0-beta.44

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.1.0-beta.42, Tue Feb 04 2025
11
+ * Version 4.1.0-beta.44, Fri Feb 14 2025
12
12
  *
13
13
  * https://dexie.org
14
14
  *
@@ -5915,8 +5915,6 @@ function prodLog(level, ...args) {
5915
5915
  */
5916
5916
  function setCurrentUser(db, user) {
5917
5917
  return __awaiter(this, void 0, void 0, function* () {
5918
- if (user.userId === db.cloud.currentUserId)
5919
- return; // Already this user.
5920
5918
  const $logins = db.table('$logins');
5921
5919
  yield db.transaction('rw', $logins, (tx) => __awaiter(this, void 0, void 0, function* () {
5922
5920
  const existingLogins = yield $logins.toArray();
@@ -6158,8 +6156,14 @@ function createIdGenerationMiddleware(db) {
6158
6156
  }
6159
6157
  return Object.assign(Object.assign({}, table), { mutate: (req) => {
6160
6158
  var _a, _b;
6161
- // @ts-ignore
6162
- if (req.trans.disableChangeTracking) {
6159
+ const idbtrans = req.trans;
6160
+ if (idbtrans.mode === 'versionchange') {
6161
+ // Tell all the other middlewares to skip bothering. We're in versionchange mode.
6162
+ // dexie-cloud is not initialized yet.
6163
+ idbtrans.disableChangeTracking = true;
6164
+ idbtrans.disableAccessControl = true;
6165
+ }
6166
+ if (idbtrans.disableChangeTracking) {
6163
6167
  // Disable ID policy checks and ID generation
6164
6168
  return table.mutate(req);
6165
6169
  }
@@ -6216,17 +6220,13 @@ function createImplicitPropSetterMiddleware(db) {
6216
6220
  return Object.assign(Object.assign({}, core), { table: (tableName) => {
6217
6221
  const table = core.table(tableName);
6218
6222
  return Object.assign(Object.assign({}, table), { mutate: (req) => {
6219
- var _a, _b, _c, _d;
6220
- // @ts-ignore
6221
- if (req.trans.disableChangeTracking) {
6223
+ var _a, _b, _c, _d, _e, _f;
6224
+ const trans = req.trans;
6225
+ if (trans.disableChangeTracking) {
6222
6226
  return table.mutate(req);
6223
6227
  }
6224
- const trans = req.trans;
6225
- if ((_b = (_a = db.cloud.schema) === null || _a === void 0 ? void 0 : _a[tableName]) === null || _b === void 0 ? void 0 : _b.markedForSync) {
6226
- if (trans.mode === 'versionchange') {
6227
- // Don't mutate tables marked for sync in versionchange transactions.
6228
- return Promise.reject(new Dexie.UpgradeError(`Dexie Cloud Addon: Cannot upgrade or populate synced table "${tableName}". See https://dexie.org/cloud/docs/best-practices`));
6229
- }
6228
+ const currentUserId = (_b = (_a = trans.currentUser) === null || _a === void 0 ? void 0 : _a.userId) !== null && _b !== void 0 ? _b : UNAUTHORIZED_USER.userId;
6229
+ if ((_d = (_c = db.cloud.schema) === null || _c === void 0 ? void 0 : _c[tableName]) === null || _d === void 0 ? void 0 : _d.markedForSync) {
6230
6230
  if (req.type === 'add' || req.type === 'put') {
6231
6231
  if (tableName === 'members') {
6232
6232
  for (const member of req.values) {
@@ -6250,12 +6250,12 @@ function createImplicitPropSetterMiddleware(db) {
6250
6250
  // and expect them to be returned. That scenario must work also when db.cloud.currentUserId === 'unauthorized'.
6251
6251
  for (const obj of req.values) {
6252
6252
  if (!obj.owner) {
6253
- obj.owner = trans.currentUser.userId;
6253
+ obj.owner = currentUserId;
6254
6254
  }
6255
6255
  if (!obj.realmId) {
6256
- obj.realmId = trans.currentUser.userId;
6256
+ obj.realmId = currentUserId;
6257
6257
  }
6258
- const key = (_d = (_c = table.schema.primaryKey).extractKey) === null || _d === void 0 ? void 0 : _d.call(_c, obj);
6258
+ const key = (_f = (_e = table.schema.primaryKey).extractKey) === null || _f === void 0 ? void 0 : _f.call(_e, obj);
6259
6259
  if (typeof key === 'string' && key[0] === '#') {
6260
6260
  // Add $ts prop for put operations and
6261
6261
  // disable update operations as well as consistent
@@ -6351,16 +6351,14 @@ function createMutationTrackingMiddleware({ currentUserObservable, db, }) {
6351
6351
  name: 'MutationTrackingMiddleware',
6352
6352
  level: 1,
6353
6353
  create: (core) => {
6354
+ const allTableNames = new Set(core.schema.tables.map((t) => t.name));
6354
6355
  const ordinaryTables = core.schema.tables.filter((t) => !/^\$/.test(t.name));
6355
- let mutTableMap;
6356
- try {
6357
- mutTableMap = new Map(ordinaryTables.map((tbl) => [
6358
- tbl.name,
6359
- core.table(`$${tbl.name}_mutations`),
6360
- ]));
6361
- }
6362
- catch (_a) {
6363
- throwVersionIncrementNeeded();
6356
+ const mutTableMap = new Map();
6357
+ for (const tbl of ordinaryTables) {
6358
+ const mutationTableName = `$${tbl.name}_mutations`;
6359
+ if (allTableNames.has(mutationTableName)) {
6360
+ mutTableMap.set(tbl.name, core.table(mutationTableName));
6361
+ }
6364
6362
  }
6365
6363
  return Object.assign(Object.assign({}, core), { transaction: (tables, mode) => {
6366
6364
  let tx;
@@ -6438,6 +6436,11 @@ function createMutationTrackingMiddleware({ currentUserObservable, db, }) {
6438
6436
  }
6439
6437
  const { schema } = table;
6440
6438
  const mutsTable = mutTableMap.get(tableName);
6439
+ if (!mutsTable) {
6440
+ // We cannot track mutations on this table because there is no mutations table for it.
6441
+ // This might happen in upgraders that executes before cloud schema is applied.
6442
+ return table;
6443
+ }
6441
6444
  return guardedTable(Object.assign(Object.assign({}, table), { mutate: (req) => {
6442
6445
  var _a, _b, _c;
6443
6446
  const trans = req.trans;
@@ -8188,7 +8191,7 @@ function dexieCloud(dexie) {
8188
8191
  const syncComplete = new Subject();
8189
8192
  dexie.cloud = {
8190
8193
  // @ts-ignore
8191
- version: "4.1.0-beta.42",
8194
+ version: "4.1.0-beta.44",
8192
8195
  options: Object.assign({}, DEFAULT_OPTIONS),
8193
8196
  schema: null,
8194
8197
  get currentUserId() {
@@ -8506,7 +8509,7 @@ function dexieCloud(dexie) {
8506
8509
  }
8507
8510
  }
8508
8511
  // @ts-ignore
8509
- dexieCloud.version = "4.1.0-beta.42";
8512
+ dexieCloud.version = "4.1.0-beta.44";
8510
8513
  Dexie.Cloud = dexieCloud;
8511
8514
 
8512
8515
  // In case the SW lives for a while, let it reuse already opened connections: