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.
@@ -101,7 +101,7 @@ function __spreadArray$1(to, from, pack) {
101
101
  *
102
102
  * ==========================================================================
103
103
  *
104
- * Version 4.0.1-beta.37, Mon Apr 17 2023
104
+ * Version 4.0.1-beta.38, Mon Apr 17 2023
105
105
  *
106
106
  * https://dexie.org
107
107
  *
@@ -5444,6 +5444,38 @@ function createMutationTrackingMiddleware(_k) {
5444
5444
  function overrideParseStoresSpec(origFunc, dexie) {
5445
5445
  return function (stores, dbSchema) {
5446
5446
  var storesClone = Object.assign(Object.assign({}, DEXIE_CLOUD_SCHEMA), stores);
5447
+ // Merge indexes of DEXIE_CLOUD_SCHEMA with stores
5448
+ Object.keys(DEXIE_CLOUD_SCHEMA).forEach(function (tableName) {
5449
+ var schemaSrc = storesClone[tableName];
5450
+ // Verify that they don't try to delete a table that is needed for access control of Dexie Cloud
5451
+ if (schemaSrc == null) {
5452
+ // They try to delete one of the built-in schema tables.
5453
+ throw new Error("Cannot delete table ".concat(tableName, " as it is needed for access control of Dexie Cloud"));
5454
+ }
5455
+ // If not trying to override a built-in table, then we can skip this and continue to next table.
5456
+ if (!stores[tableName]) {
5457
+ // They haven't tried to declare this table. No need to merge indexes.
5458
+ return; // Continue
5459
+ }
5460
+ // They have declared this table. Merge indexes in case they didn't declare all indexes we need.
5461
+ var requestedIndexes = schemaSrc.split(',').map(function (spec) { return spec.trim(); });
5462
+ var builtInIndexes = DEXIE_CLOUD_SCHEMA[tableName].split(',').map(function (spec) { return spec.trim(); });
5463
+ var requestedIndexSet = new Set(requestedIndexes.map(function (index) { return index.replace(/([&*]|\+\+)/g, ""); }));
5464
+ // Verify that primary key is unchanged
5465
+ if (requestedIndexes[0] !== builtInIndexes[0]) {
5466
+ // Primary key must match exactly
5467
+ throw new Error("Cannot override primary key of table ".concat(tableName, ". Please declare it as {").concat(tableName, ": ").concat(JSON.stringify(DEXIE_CLOUD_SCHEMA[tableName])));
5468
+ }
5469
+ // Merge indexes
5470
+ for (var i_6 = 1; i_6 < builtInIndexes.length; ++i_6) {
5471
+ var builtInIndex = builtInIndexes[i_6];
5472
+ if (!requestedIndexSet.has(builtInIndex.replace(/([&*]|\+\+)/g, ""))) {
5473
+ // Add built-in index if not already requested
5474
+ storesClone[tableName] += ",".concat(builtInIndex);
5475
+ }
5476
+ }
5477
+ });
5478
+ // Populate dexie.cloud.schema
5447
5479
  var cloudSchema = dexie.cloud.schema || (dexie.cloud.schema = {});
5448
5480
  var allPrefixes = new Set();
5449
5481
  Object.keys(storesClone).forEach(function (tableName) {
@@ -7042,7 +7074,7 @@ function dexieCloud(dexie) {
7042
7074
  });
7043
7075
  var syncComplete = new Subject();
7044
7076
  dexie.cloud = {
7045
- version: '4.0.1-beta.37',
7077
+ version: '4.0.1-beta.38',
7046
7078
  options: Object.assign({}, DEFAULT_OPTIONS),
7047
7079
  schema: null,
7048
7080
  get currentUserId() {
@@ -7381,7 +7413,7 @@ function dexieCloud(dexie) {
7381
7413
  });
7382
7414
  }
7383
7415
  }
7384
- dexieCloud.version = '4.0.1-beta.37';
7416
+ dexieCloud.version = '4.0.1-beta.38';
7385
7417
  Dexie.Cloud = dexieCloud;
7386
7418
 
7387
7419
  export { dexieCloud as default, dexieCloud, getTiedObjectId, getTiedRealmId };