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.
@@ -3189,7 +3189,10 @@
3189
3189
  function cloneChange(change, rewriteValues) {
3190
3190
  // clone on demand:
3191
3191
  return Object.assign(Object.assign({}, change), { muts: rewriteValues
3192
- ? change.muts.map((m) => (Object.assign(Object.assign({}, m), { keys: m.keys.slice(), values: m.values.slice() })))
3192
+ ? change.muts.map((m) => {
3193
+ return (m.type === 'insert' || m.type === 'upsert') && m.values
3194
+ ? Object.assign(Object.assign({}, m), { keys: m.keys.slice(), values: m.values.slice() }) : Object.assign(Object.assign({}, m), { keys: m.keys.slice() });
3195
+ })
3193
3196
  : change.muts.map((m) => (Object.assign(Object.assign({}, m), { keys: m.keys.slice() }))) });
3194
3197
  }
3195
3198
 
@@ -4798,6 +4801,38 @@
4798
4801
  function overrideParseStoresSpec(origFunc, dexie) {
4799
4802
  return function (stores, dbSchema) {
4800
4803
  const storesClone = Object.assign(Object.assign({}, DEXIE_CLOUD_SCHEMA), stores);
4804
+ // Merge indexes of DEXIE_CLOUD_SCHEMA with stores
4805
+ Object.keys(DEXIE_CLOUD_SCHEMA).forEach((tableName) => {
4806
+ const schemaSrc = storesClone[tableName];
4807
+ // Verify that they don't try to delete a table that is needed for access control of Dexie Cloud
4808
+ if (schemaSrc == null) {
4809
+ // They try to delete one of the built-in schema tables.
4810
+ throw new Error(`Cannot delete table ${tableName} as it is needed for access control of Dexie Cloud`);
4811
+ }
4812
+ // If not trying to override a built-in table, then we can skip this and continue to next table.
4813
+ if (!stores[tableName]) {
4814
+ // They haven't tried to declare this table. No need to merge indexes.
4815
+ return; // Continue
4816
+ }
4817
+ // They have declared this table. Merge indexes in case they didn't declare all indexes we need.
4818
+ const requestedIndexes = schemaSrc.split(',').map(spec => spec.trim());
4819
+ const builtInIndexes = DEXIE_CLOUD_SCHEMA[tableName].split(',').map(spec => spec.trim());
4820
+ const requestedIndexSet = new Set(requestedIndexes.map(index => index.replace(/([&*]|\+\+)/g, "")));
4821
+ // Verify that primary key is unchanged
4822
+ if (requestedIndexes[0] !== builtInIndexes[0]) {
4823
+ // Primary key must match exactly
4824
+ throw new Error(`Cannot override primary key of table ${tableName}. Please declare it as {${tableName}: ${JSON.stringify(DEXIE_CLOUD_SCHEMA[tableName])}`);
4825
+ }
4826
+ // Merge indexes
4827
+ for (let i = 1; i < builtInIndexes.length; ++i) {
4828
+ const builtInIndex = builtInIndexes[i];
4829
+ if (!requestedIndexSet.has(builtInIndex.replace(/([&*]|\+\+)/g, ""))) {
4830
+ // Add built-in index if not already requested
4831
+ storesClone[tableName] += `,${builtInIndex}`;
4832
+ }
4833
+ }
4834
+ });
4835
+ // Populate dexie.cloud.schema
4801
4836
  const cloudSchema = dexie.cloud.schema || (dexie.cloud.schema = {});
4802
4837
  const allPrefixes = new Set();
4803
4838
  Object.keys(storesClone).forEach(tableName => {
@@ -6020,7 +6055,7 @@
6020
6055
  });
6021
6056
  const syncComplete = new rxjs.Subject();
6022
6057
  dexie.cloud = {
6023
- version: '4.0.1-beta.36',
6058
+ version: '4.0.1-beta.38',
6024
6059
  options: Object.assign({}, DEFAULT_OPTIONS),
6025
6060
  schema: null,
6026
6061
  get currentUserId() {
@@ -6281,7 +6316,7 @@
6281
6316
  });
6282
6317
  }
6283
6318
  }
6284
- dexieCloud.version = '4.0.1-beta.36';
6319
+ dexieCloud.version = '4.0.1-beta.38';
6285
6320
  Dexie__default["default"].Cloud = dexieCloud;
6286
6321
 
6287
6322
  // In case the SW lives for a while, let it reuse already opened connections: