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.
@@ -3182,7 +3182,10 @@ function encodeIdsForServer(schema, currentUser, changes) {
3182
3182
  function cloneChange(change, rewriteValues) {
3183
3183
  // clone on demand:
3184
3184
  return Object.assign(Object.assign({}, change), { muts: rewriteValues
3185
- ? change.muts.map((m) => (Object.assign(Object.assign({}, m), { keys: m.keys.slice(), values: m.values.slice() })))
3185
+ ? change.muts.map((m) => {
3186
+ return (m.type === 'insert' || m.type === 'upsert') && m.values
3187
+ ? Object.assign(Object.assign({}, m), { keys: m.keys.slice(), values: m.values.slice() }) : Object.assign(Object.assign({}, m), { keys: m.keys.slice() });
3188
+ })
3186
3189
  : change.muts.map((m) => (Object.assign(Object.assign({}, m), { keys: m.keys.slice() }))) });
3187
3190
  }
3188
3191
 
@@ -4791,6 +4794,38 @@ function createMutationTrackingMiddleware({ currentUserObservable, db }) {
4791
4794
  function overrideParseStoresSpec(origFunc, dexie) {
4792
4795
  return function (stores, dbSchema) {
4793
4796
  const storesClone = Object.assign(Object.assign({}, DEXIE_CLOUD_SCHEMA), stores);
4797
+ // Merge indexes of DEXIE_CLOUD_SCHEMA with stores
4798
+ Object.keys(DEXIE_CLOUD_SCHEMA).forEach((tableName) => {
4799
+ const schemaSrc = storesClone[tableName];
4800
+ // Verify that they don't try to delete a table that is needed for access control of Dexie Cloud
4801
+ if (schemaSrc == null) {
4802
+ // They try to delete one of the built-in schema tables.
4803
+ throw new Error(`Cannot delete table ${tableName} as it is needed for access control of Dexie Cloud`);
4804
+ }
4805
+ // If not trying to override a built-in table, then we can skip this and continue to next table.
4806
+ if (!stores[tableName]) {
4807
+ // They haven't tried to declare this table. No need to merge indexes.
4808
+ return; // Continue
4809
+ }
4810
+ // They have declared this table. Merge indexes in case they didn't declare all indexes we need.
4811
+ const requestedIndexes = schemaSrc.split(',').map(spec => spec.trim());
4812
+ const builtInIndexes = DEXIE_CLOUD_SCHEMA[tableName].split(',').map(spec => spec.trim());
4813
+ const requestedIndexSet = new Set(requestedIndexes.map(index => index.replace(/([&*]|\+\+)/g, "")));
4814
+ // Verify that primary key is unchanged
4815
+ if (requestedIndexes[0] !== builtInIndexes[0]) {
4816
+ // Primary key must match exactly
4817
+ throw new Error(`Cannot override primary key of table ${tableName}. Please declare it as {${tableName}: ${JSON.stringify(DEXIE_CLOUD_SCHEMA[tableName])}`);
4818
+ }
4819
+ // Merge indexes
4820
+ for (let i = 1; i < builtInIndexes.length; ++i) {
4821
+ const builtInIndex = builtInIndexes[i];
4822
+ if (!requestedIndexSet.has(builtInIndex.replace(/([&*]|\+\+)/g, ""))) {
4823
+ // Add built-in index if not already requested
4824
+ storesClone[tableName] += `,${builtInIndex}`;
4825
+ }
4826
+ }
4827
+ });
4828
+ // Populate dexie.cloud.schema
4794
4829
  const cloudSchema = dexie.cloud.schema || (dexie.cloud.schema = {});
4795
4830
  const allPrefixes = new Set();
4796
4831
  Object.keys(storesClone).forEach(tableName => {
@@ -6013,7 +6048,7 @@ function dexieCloud(dexie) {
6013
6048
  });
6014
6049
  const syncComplete = new Subject();
6015
6050
  dexie.cloud = {
6016
- version: '4.0.1-beta.36',
6051
+ version: '4.0.1-beta.38',
6017
6052
  options: Object.assign({}, DEFAULT_OPTIONS),
6018
6053
  schema: null,
6019
6054
  get currentUserId() {
@@ -6274,7 +6309,7 @@ function dexieCloud(dexie) {
6274
6309
  });
6275
6310
  }
6276
6311
  }
6277
- dexieCloud.version = '4.0.1-beta.36';
6312
+ dexieCloud.version = '4.0.1-beta.38';
6278
6313
  Dexie.Cloud = dexieCloud;
6279
6314
 
6280
6315
  // In case the SW lives for a while, let it reuse already opened connections: