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.
@@ -4794,6 +4794,38 @@ function createMutationTrackingMiddleware({ currentUserObservable, db }) {
4794
4794
  function overrideParseStoresSpec(origFunc, dexie) {
4795
4795
  return function (stores, dbSchema) {
4796
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
4797
4829
  const cloudSchema = dexie.cloud.schema || (dexie.cloud.schema = {});
4798
4830
  const allPrefixes = new Set();
4799
4831
  Object.keys(storesClone).forEach(tableName => {
@@ -6016,7 +6048,7 @@ function dexieCloud(dexie) {
6016
6048
  });
6017
6049
  const syncComplete = new Subject();
6018
6050
  dexie.cloud = {
6019
- version: '4.0.1-beta.37',
6051
+ version: '4.0.1-beta.38',
6020
6052
  options: Object.assign({}, DEFAULT_OPTIONS),
6021
6053
  schema: null,
6022
6054
  get currentUserId() {
@@ -6277,7 +6309,7 @@ function dexieCloud(dexie) {
6277
6309
  });
6278
6310
  }
6279
6311
  }
6280
- dexieCloud.version = '4.0.1-beta.37';
6312
+ dexieCloud.version = '4.0.1-beta.38';
6281
6313
  Dexie.Cloud = dexieCloud;
6282
6314
 
6283
6315
  // In case the SW lives for a while, let it reuse already opened connections: