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.
@@ -108,7 +108,7 @@
108
108
  *
109
109
  * ==========================================================================
110
110
  *
111
- * Version 4.0.1-beta.37, Mon Apr 17 2023
111
+ * Version 4.0.1-beta.38, Mon Apr 17 2023
112
112
  *
113
113
  * https://dexie.org
114
114
  *
@@ -5451,6 +5451,38 @@
5451
5451
  function overrideParseStoresSpec(origFunc, dexie) {
5452
5452
  return function (stores, dbSchema) {
5453
5453
  var storesClone = Object.assign(Object.assign({}, DEXIE_CLOUD_SCHEMA), stores);
5454
+ // Merge indexes of DEXIE_CLOUD_SCHEMA with stores
5455
+ Object.keys(DEXIE_CLOUD_SCHEMA).forEach(function (tableName) {
5456
+ var schemaSrc = storesClone[tableName];
5457
+ // Verify that they don't try to delete a table that is needed for access control of Dexie Cloud
5458
+ if (schemaSrc == null) {
5459
+ // They try to delete one of the built-in schema tables.
5460
+ throw new Error("Cannot delete table ".concat(tableName, " as it is needed for access control of Dexie Cloud"));
5461
+ }
5462
+ // If not trying to override a built-in table, then we can skip this and continue to next table.
5463
+ if (!stores[tableName]) {
5464
+ // They haven't tried to declare this table. No need to merge indexes.
5465
+ return; // Continue
5466
+ }
5467
+ // They have declared this table. Merge indexes in case they didn't declare all indexes we need.
5468
+ var requestedIndexes = schemaSrc.split(',').map(function (spec) { return spec.trim(); });
5469
+ var builtInIndexes = DEXIE_CLOUD_SCHEMA[tableName].split(',').map(function (spec) { return spec.trim(); });
5470
+ var requestedIndexSet = new Set(requestedIndexes.map(function (index) { return index.replace(/([&*]|\+\+)/g, ""); }));
5471
+ // Verify that primary key is unchanged
5472
+ if (requestedIndexes[0] !== builtInIndexes[0]) {
5473
+ // Primary key must match exactly
5474
+ throw new Error("Cannot override primary key of table ".concat(tableName, ". Please declare it as {").concat(tableName, ": ").concat(JSON.stringify(DEXIE_CLOUD_SCHEMA[tableName])));
5475
+ }
5476
+ // Merge indexes
5477
+ for (var i_6 = 1; i_6 < builtInIndexes.length; ++i_6) {
5478
+ var builtInIndex = builtInIndexes[i_6];
5479
+ if (!requestedIndexSet.has(builtInIndex.replace(/([&*]|\+\+)/g, ""))) {
5480
+ // Add built-in index if not already requested
5481
+ storesClone[tableName] += ",".concat(builtInIndex);
5482
+ }
5483
+ }
5484
+ });
5485
+ // Populate dexie.cloud.schema
5454
5486
  var cloudSchema = dexie.cloud.schema || (dexie.cloud.schema = {});
5455
5487
  var allPrefixes = new Set();
5456
5488
  Object.keys(storesClone).forEach(function (tableName) {
@@ -7049,7 +7081,7 @@
7049
7081
  });
7050
7082
  var syncComplete = new rxjs.Subject();
7051
7083
  dexie.cloud = {
7052
- version: '4.0.1-beta.37',
7084
+ version: '4.0.1-beta.38',
7053
7085
  options: Object.assign({}, DEFAULT_OPTIONS),
7054
7086
  schema: null,
7055
7087
  get currentUserId() {
@@ -7388,7 +7420,7 @@
7388
7420
  });
7389
7421
  }
7390
7422
  }
7391
- dexieCloud.version = '4.0.1-beta.37';
7423
+ dexieCloud.version = '4.0.1-beta.38';
7392
7424
  Dexie__default["default"].Cloud = dexieCloud;
7393
7425
 
7394
7426
  exports["default"] = dexieCloud;