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.
@@ -101,7 +101,7 @@ function __spreadArray$1(to, from, pack) {
101
101
  *
102
102
  * ==========================================================================
103
103
  *
104
- * Version 4.0.1-beta.36, Mon Apr 17 2023
104
+ * Version 4.0.1-beta.38, Mon Apr 17 2023
105
105
  *
106
106
  * https://dexie.org
107
107
  *
@@ -3751,7 +3751,10 @@ function encodeIdsForServer(schema, currentUser, changes) {
3751
3751
  function cloneChange(change, rewriteValues) {
3752
3752
  // clone on demand:
3753
3753
  return Object.assign(Object.assign({}, change), { muts: rewriteValues
3754
- ? change.muts.map(function (m) { return (Object.assign(Object.assign({}, m), { keys: m.keys.slice(), values: m.values.slice() })); })
3754
+ ? change.muts.map(function (m) {
3755
+ return (m.type === 'insert' || m.type === 'upsert') && m.values
3756
+ ? Object.assign(Object.assign({}, m), { keys: m.keys.slice(), values: m.values.slice() }) : Object.assign(Object.assign({}, m), { keys: m.keys.slice() });
3757
+ })
3755
3758
  : change.muts.map(function (m) { return (Object.assign(Object.assign({}, m), { keys: m.keys.slice() })); }) });
3756
3759
  }
3757
3760
  //import {BisonWebStreamReader} from "dreambase-library/dist/typeson-simplified/BisonWebStreamReader";
@@ -5441,6 +5444,38 @@ function createMutationTrackingMiddleware(_k) {
5441
5444
  function overrideParseStoresSpec(origFunc, dexie) {
5442
5445
  return function (stores, dbSchema) {
5443
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
5444
5479
  var cloudSchema = dexie.cloud.schema || (dexie.cloud.schema = {});
5445
5480
  var allPrefixes = new Set();
5446
5481
  Object.keys(storesClone).forEach(function (tableName) {
@@ -7039,7 +7074,7 @@ function dexieCloud(dexie) {
7039
7074
  });
7040
7075
  var syncComplete = new Subject();
7041
7076
  dexie.cloud = {
7042
- version: '4.0.1-beta.36',
7077
+ version: '4.0.1-beta.38',
7043
7078
  options: Object.assign({}, DEFAULT_OPTIONS),
7044
7079
  schema: null,
7045
7080
  get currentUserId() {
@@ -7378,7 +7413,7 @@ function dexieCloud(dexie) {
7378
7413
  });
7379
7414
  }
7380
7415
  }
7381
- dexieCloud.version = '4.0.1-beta.36';
7416
+ dexieCloud.version = '4.0.1-beta.38';
7382
7417
  Dexie.Cloud = dexieCloud;
7383
7418
 
7384
7419
  export { dexieCloud as default, dexieCloud, getTiedObjectId, getTiedRealmId };