dexie-cloud-addon 4.1.0-beta.43 → 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.43, Fri Feb 07 2025
11
+ * Version 4.1.0-beta.44, Fri Feb 14 2025
12
12
  *
13
13
  * https://dexie.org
14
14
  *
@@ -3680,8 +3680,6 @@
3680
3680
  */
3681
3681
  function setCurrentUser(db, user) {
3682
3682
  return __awaiter(this, void 0, void 0, function* () {
3683
- if (user.userId === db.cloud.currentUserId)
3684
- return; // Already this user.
3685
3683
  const $logins = db.table('$logins');
3686
3684
  yield db.transaction('rw', $logins, (tx) => __awaiter(this, void 0, void 0, function* () {
3687
3685
  const existingLogins = yield $logins.toArray();
@@ -6161,8 +6159,14 @@
6161
6159
  }
6162
6160
  return Object.assign(Object.assign({}, table), { mutate: (req) => {
6163
6161
  var _a, _b;
6164
- // @ts-ignore
6165
- if (req.trans.disableChangeTracking) {
6162
+ const idbtrans = req.trans;
6163
+ if (idbtrans.mode === 'versionchange') {
6164
+ // Tell all the other middlewares to skip bothering. We're in versionchange mode.
6165
+ // dexie-cloud is not initialized yet.
6166
+ idbtrans.disableChangeTracking = true;
6167
+ idbtrans.disableAccessControl = true;
6168
+ }
6169
+ if (idbtrans.disableChangeTracking) {
6166
6170
  // Disable ID policy checks and ID generation
6167
6171
  return table.mutate(req);
6168
6172
  }
@@ -6219,17 +6223,13 @@
6219
6223
  return Object.assign(Object.assign({}, core), { table: (tableName) => {
6220
6224
  const table = core.table(tableName);
6221
6225
  return Object.assign(Object.assign({}, table), { mutate: (req) => {
6222
- var _a, _b, _c, _d;
6223
- // @ts-ignore
6224
- if (req.trans.disableChangeTracking) {
6226
+ var _a, _b, _c, _d, _e, _f;
6227
+ const trans = req.trans;
6228
+ if (trans.disableChangeTracking) {
6225
6229
  return table.mutate(req);
6226
6230
  }
6227
- const trans = req.trans;
6228
- if ((_b = (_a = db.cloud.schema) === null || _a === void 0 ? void 0 : _a[tableName]) === null || _b === void 0 ? void 0 : _b.markedForSync) {
6229
- if (trans.mode === 'versionchange') {
6230
- // Don't mutate tables marked for sync in versionchange transactions.
6231
- return Promise.reject(new Dexie.UpgradeError(`Dexie Cloud Addon: Cannot upgrade or populate synced table "${tableName}". See https://dexie.org/cloud/docs/best-practices`));
6232
- }
6231
+ const currentUserId = (_b = (_a = trans.currentUser) === null || _a === void 0 ? void 0 : _a.userId) !== null && _b !== void 0 ? _b : UNAUTHORIZED_USER.userId;
6232
+ if ((_d = (_c = db.cloud.schema) === null || _c === void 0 ? void 0 : _c[tableName]) === null || _d === void 0 ? void 0 : _d.markedForSync) {
6233
6233
  if (req.type === 'add' || req.type === 'put') {
6234
6234
  if (tableName === 'members') {
6235
6235
  for (const member of req.values) {
@@ -6253,12 +6253,12 @@
6253
6253
  // and expect them to be returned. That scenario must work also when db.cloud.currentUserId === 'unauthorized'.
6254
6254
  for (const obj of req.values) {
6255
6255
  if (!obj.owner) {
6256
- obj.owner = trans.currentUser.userId;
6256
+ obj.owner = currentUserId;
6257
6257
  }
6258
6258
  if (!obj.realmId) {
6259
- obj.realmId = trans.currentUser.userId;
6259
+ obj.realmId = currentUserId;
6260
6260
  }
6261
- const key = (_d = (_c = table.schema.primaryKey).extractKey) === null || _d === void 0 ? void 0 : _d.call(_c, obj);
6261
+ const key = (_f = (_e = table.schema.primaryKey).extractKey) === null || _f === void 0 ? void 0 : _f.call(_e, obj);
6262
6262
  if (typeof key === 'string' && key[0] === '#') {
6263
6263
  // Add $ts prop for put operations and
6264
6264
  // disable update operations as well as consistent
@@ -6354,16 +6354,14 @@
6354
6354
  name: 'MutationTrackingMiddleware',
6355
6355
  level: 1,
6356
6356
  create: (core) => {
6357
+ const allTableNames = new Set(core.schema.tables.map((t) => t.name));
6357
6358
  const ordinaryTables = core.schema.tables.filter((t) => !/^\$/.test(t.name));
6358
- let mutTableMap;
6359
- try {
6360
- mutTableMap = new Map(ordinaryTables.map((tbl) => [
6361
- tbl.name,
6362
- core.table(`$${tbl.name}_mutations`),
6363
- ]));
6364
- }
6365
- catch (_a) {
6366
- throwVersionIncrementNeeded();
6359
+ const mutTableMap = new Map();
6360
+ for (const tbl of ordinaryTables) {
6361
+ const mutationTableName = `$${tbl.name}_mutations`;
6362
+ if (allTableNames.has(mutationTableName)) {
6363
+ mutTableMap.set(tbl.name, core.table(mutationTableName));
6364
+ }
6367
6365
  }
6368
6366
  return Object.assign(Object.assign({}, core), { transaction: (tables, mode) => {
6369
6367
  let tx;
@@ -6441,6 +6439,11 @@
6441
6439
  }
6442
6440
  const { schema } = table;
6443
6441
  const mutsTable = mutTableMap.get(tableName);
6442
+ if (!mutsTable) {
6443
+ // We cannot track mutations on this table because there is no mutations table for it.
6444
+ // This might happen in upgraders that executes before cloud schema is applied.
6445
+ return table;
6446
+ }
6444
6447
  return guardedTable(Object.assign(Object.assign({}, table), { mutate: (req) => {
6445
6448
  var _a, _b, _c;
6446
6449
  const trans = req.trans;
@@ -8354,7 +8357,7 @@
8354
8357
  const syncComplete = new rxjs.Subject();
8355
8358
  dexie.cloud = {
8356
8359
  // @ts-ignore
8357
- version: "4.1.0-beta.43",
8360
+ version: "4.1.0-beta.44",
8358
8361
  options: Object.assign({}, DEFAULT_OPTIONS),
8359
8362
  schema: null,
8360
8363
  get currentUserId() {
@@ -8672,7 +8675,7 @@
8672
8675
  }
8673
8676
  }
8674
8677
  // @ts-ignore
8675
- dexieCloud.version = "4.1.0-beta.43";
8678
+ dexieCloud.version = "4.1.0-beta.44";
8676
8679
  Dexie.Cloud = dexieCloud;
8677
8680
 
8678
8681
  exports.default = dexieCloud;