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.
@@ -3436,7 +3436,10 @@
3436
3436
  function cloneChange(change, rewriteValues) {
3437
3437
  // clone on demand:
3438
3438
  return Object.assign(Object.assign({}, change), { muts: rewriteValues
3439
- ? change.muts.map((m) => (Object.assign(Object.assign({}, m), { keys: m.keys.slice(), values: m.values.slice() })))
3439
+ ? change.muts.map((m) => {
3440
+ return (m.type === 'insert' || m.type === 'upsert') && m.values
3441
+ ? Object.assign(Object.assign({}, m), { keys: m.keys.slice(), values: m.values.slice() }) : Object.assign(Object.assign({}, m), { keys: m.keys.slice() });
3442
+ })
3440
3443
  : change.muts.map((m) => (Object.assign(Object.assign({}, m), { keys: m.keys.slice() }))) });
3441
3444
  }
3442
3445
 
@@ -4816,6 +4819,38 @@
4816
4819
  function overrideParseStoresSpec(origFunc, dexie) {
4817
4820
  return function (stores, dbSchema) {
4818
4821
  const storesClone = Object.assign(Object.assign({}, DEXIE_CLOUD_SCHEMA), stores);
4822
+ // Merge indexes of DEXIE_CLOUD_SCHEMA with stores
4823
+ Object.keys(DEXIE_CLOUD_SCHEMA).forEach((tableName) => {
4824
+ const schemaSrc = storesClone[tableName];
4825
+ // Verify that they don't try to delete a table that is needed for access control of Dexie Cloud
4826
+ if (schemaSrc == null) {
4827
+ // They try to delete one of the built-in schema tables.
4828
+ throw new Error(`Cannot delete table ${tableName} as it is needed for access control of Dexie Cloud`);
4829
+ }
4830
+ // If not trying to override a built-in table, then we can skip this and continue to next table.
4831
+ if (!stores[tableName]) {
4832
+ // They haven't tried to declare this table. No need to merge indexes.
4833
+ return; // Continue
4834
+ }
4835
+ // They have declared this table. Merge indexes in case they didn't declare all indexes we need.
4836
+ const requestedIndexes = schemaSrc.split(',').map(spec => spec.trim());
4837
+ const builtInIndexes = DEXIE_CLOUD_SCHEMA[tableName].split(',').map(spec => spec.trim());
4838
+ const requestedIndexSet = new Set(requestedIndexes.map(index => index.replace(/([&*]|\+\+)/g, "")));
4839
+ // Verify that primary key is unchanged
4840
+ if (requestedIndexes[0] !== builtInIndexes[0]) {
4841
+ // Primary key must match exactly
4842
+ throw new Error(`Cannot override primary key of table ${tableName}. Please declare it as {${tableName}: ${JSON.stringify(DEXIE_CLOUD_SCHEMA[tableName])}`);
4843
+ }
4844
+ // Merge indexes
4845
+ for (let i = 1; i < builtInIndexes.length; ++i) {
4846
+ const builtInIndex = builtInIndexes[i];
4847
+ if (!requestedIndexSet.has(builtInIndex.replace(/([&*]|\+\+)/g, ""))) {
4848
+ // Add built-in index if not already requested
4849
+ storesClone[tableName] += `,${builtInIndex}`;
4850
+ }
4851
+ }
4852
+ });
4853
+ // Populate dexie.cloud.schema
4819
4854
  const cloudSchema = dexie.cloud.schema || (dexie.cloud.schema = {});
4820
4855
  const allPrefixes = new Set();
4821
4856
  Object.keys(storesClone).forEach(tableName => {