dexie-cloud-addon 4.0.1-beta.36 → 4.0.1-beta.38

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.36, Mon Apr 17 2023
11
+ * Version 4.0.1-beta.38, Mon Apr 17 2023
12
12
  *
13
13
  * https://dexie.org
14
14
  *
@@ -3429,7 +3429,10 @@ function encodeIdsForServer(schema, currentUser, changes) {
3429
3429
  function cloneChange(change, rewriteValues) {
3430
3430
  // clone on demand:
3431
3431
  return Object.assign(Object.assign({}, change), { muts: rewriteValues
3432
- ? change.muts.map((m) => (Object.assign(Object.assign({}, m), { keys: m.keys.slice(), values: m.values.slice() })))
3432
+ ? change.muts.map((m) => {
3433
+ return (m.type === 'insert' || m.type === 'upsert') && m.values
3434
+ ? Object.assign(Object.assign({}, m), { keys: m.keys.slice(), values: m.values.slice() }) : Object.assign(Object.assign({}, m), { keys: m.keys.slice() });
3435
+ })
3433
3436
  : change.muts.map((m) => (Object.assign(Object.assign({}, m), { keys: m.keys.slice() }))) });
3434
3437
  }
3435
3438
 
@@ -4809,6 +4812,38 @@ function createMutationTrackingMiddleware({ currentUserObservable, db }) {
4809
4812
  function overrideParseStoresSpec(origFunc, dexie) {
4810
4813
  return function (stores, dbSchema) {
4811
4814
  const storesClone = Object.assign(Object.assign({}, DEXIE_CLOUD_SCHEMA), stores);
4815
+ // Merge indexes of DEXIE_CLOUD_SCHEMA with stores
4816
+ Object.keys(DEXIE_CLOUD_SCHEMA).forEach((tableName) => {
4817
+ const schemaSrc = storesClone[tableName];
4818
+ // Verify that they don't try to delete a table that is needed for access control of Dexie Cloud
4819
+ if (schemaSrc == null) {
4820
+ // They try to delete one of the built-in schema tables.
4821
+ throw new Error(`Cannot delete table ${tableName} as it is needed for access control of Dexie Cloud`);
4822
+ }
4823
+ // If not trying to override a built-in table, then we can skip this and continue to next table.
4824
+ if (!stores[tableName]) {
4825
+ // They haven't tried to declare this table. No need to merge indexes.
4826
+ return; // Continue
4827
+ }
4828
+ // They have declared this table. Merge indexes in case they didn't declare all indexes we need.
4829
+ const requestedIndexes = schemaSrc.split(',').map(spec => spec.trim());
4830
+ const builtInIndexes = DEXIE_CLOUD_SCHEMA[tableName].split(',').map(spec => spec.trim());
4831
+ const requestedIndexSet = new Set(requestedIndexes.map(index => index.replace(/([&*]|\+\+)/g, "")));
4832
+ // Verify that primary key is unchanged
4833
+ if (requestedIndexes[0] !== builtInIndexes[0]) {
4834
+ // Primary key must match exactly
4835
+ throw new Error(`Cannot override primary key of table ${tableName}. Please declare it as {${tableName}: ${JSON.stringify(DEXIE_CLOUD_SCHEMA[tableName])}`);
4836
+ }
4837
+ // Merge indexes
4838
+ for (let i = 1; i < builtInIndexes.length; ++i) {
4839
+ const builtInIndex = builtInIndexes[i];
4840
+ if (!requestedIndexSet.has(builtInIndex.replace(/([&*]|\+\+)/g, ""))) {
4841
+ // Add built-in index if not already requested
4842
+ storesClone[tableName] += `,${builtInIndex}`;
4843
+ }
4844
+ }
4845
+ });
4846
+ // Populate dexie.cloud.schema
4812
4847
  const cloudSchema = dexie.cloud.schema || (dexie.cloud.schema = {});
4813
4848
  const allPrefixes = new Set();
4814
4849
  Object.keys(storesClone).forEach(tableName => {
@@ -6038,7 +6073,7 @@ function dexieCloud(dexie) {
6038
6073
  });
6039
6074
  const syncComplete = new Subject();
6040
6075
  dexie.cloud = {
6041
- version: '4.0.1-beta.36',
6076
+ version: '4.0.1-beta.38',
6042
6077
  options: Object.assign({}, DEFAULT_OPTIONS),
6043
6078
  schema: null,
6044
6079
  get currentUserId() {
@@ -6299,7 +6334,7 @@ function dexieCloud(dexie) {
6299
6334
  });
6300
6335
  }
6301
6336
  }
6302
- dexieCloud.version = '4.0.1-beta.36';
6337
+ dexieCloud.version = '4.0.1-beta.38';
6303
6338
  Dexie.Cloud = dexieCloud;
6304
6339
 
6305
6340
  export { dexieCloud as default, dexieCloud, getTiedObjectId, getTiedRealmId };