dexie-cloud-addon 4.0.1-beta.37 → 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.
@@ -4801,6 +4801,38 @@
4801
4801
  function overrideParseStoresSpec(origFunc, dexie) {
4802
4802
  return function (stores, dbSchema) {
4803
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
4804
4836
  const cloudSchema = dexie.cloud.schema || (dexie.cloud.schema = {});
4805
4837
  const allPrefixes = new Set();
4806
4838
  Object.keys(storesClone).forEach(tableName => {
@@ -6023,7 +6055,7 @@
6023
6055
  });
6024
6056
  const syncComplete = new rxjs.Subject();
6025
6057
  dexie.cloud = {
6026
- version: '4.0.1-beta.37',
6058
+ version: '4.0.1-beta.38',
6027
6059
  options: Object.assign({}, DEFAULT_OPTIONS),
6028
6060
  schema: null,
6029
6061
  get currentUserId() {
@@ -6284,7 +6316,7 @@
6284
6316
  });
6285
6317
  }
6286
6318
  }
6287
- dexieCloud.version = '4.0.1-beta.37';
6319
+ dexieCloud.version = '4.0.1-beta.38';
6288
6320
  Dexie__default["default"].Cloud = dexieCloud;
6289
6321
 
6290
6322
  // In case the SW lives for a while, let it reuse already opened connections: