dexie-cloud-addon 4.0.0-beta.13 → 4.0.0-beta.16

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.
Files changed (45) hide show
  1. package/dist/modern/dexie-cloud-addon.js +154 -49
  2. package/dist/modern/dexie-cloud-addon.js.map +1 -1
  3. package/dist/modern/dexie-cloud-addon.min.js +1 -1
  4. package/dist/modern/dexie-cloud-addon.min.js.map +1 -1
  5. package/dist/modern/service-worker.js +152 -46
  6. package/dist/modern/service-worker.js.map +1 -1
  7. package/dist/modern/service-worker.min.js +1 -1
  8. package/dist/modern/service-worker.min.js.map +1 -1
  9. package/dist/module-es5/dexie-cloud-addon.js +109 -45
  10. package/dist/module-es5/dexie-cloud-addon.js.map +1 -1
  11. package/dist/module-es5/dexie-cloud-addon.min.js +1 -1
  12. package/dist/module-es5/dexie-cloud-addon.min.js.map +1 -1
  13. package/dist/types/DexieCloudAPI.d.ts +4 -1
  14. package/dist/types/DexieCloudEntity.d.ts +8 -0
  15. package/dist/types/Invite.d.ts +1 -1
  16. package/dist/types/WSObservable.d.ts +1 -0
  17. package/dist/types/WebSocketStatus.d.ts +1 -0
  18. package/dist/types/createMyMembersObservable.d.ts +14 -0
  19. package/dist/types/currentUserObservable.d.ts +3 -0
  20. package/dist/types/dexie-cloud-client.d.ts +1 -0
  21. package/dist/types/getGlobalRolesObservable.d.ts +5 -0
  22. package/dist/types/getInvitesObservable.d.ts +1 -1
  23. package/dist/types/helpers/BroadcastedLocalEvent.d.ts +8 -0
  24. package/dist/types/helpers/visibleState.d.ts +1 -0
  25. package/dist/types/permissionsLookup.d.ts +9 -0
  26. package/dist/types/permissionsLookupObservable.d.ts +14 -0
  27. package/dist/types/sync/globalizePrivateIds.d.ts +4 -0
  28. package/dist/types/sync/syncServerToClientOnly.d.ts +3 -0
  29. package/dist/types/types/CloudConnectionStatus.d.ts +0 -0
  30. package/dist/types/types/ConnectionStatus.d.ts +0 -0
  31. package/dist/types/types/LoginState.d.ts +41 -0
  32. package/dist/types/types/SyncConnectionStatus.d.ts +1 -0
  33. package/dist/types/types/SyncFlowStatus.d.ts +6 -0
  34. package/dist/types/types/SyncStatus.d.ts +6 -0
  35. package/dist/umd/dexie-cloud-addon.js +129 -64
  36. package/dist/umd/dexie-cloud-addon.js.map +1 -1
  37. package/dist/umd/dexie-cloud-addon.min.js +1 -1
  38. package/dist/umd/dexie-cloud-addon.min.js.map +1 -1
  39. package/dist/umd/service-worker.js +175 -69
  40. package/dist/umd/service-worker.js.map +1 -1
  41. package/dist/umd/service-worker.min.js +1 -1
  42. package/dist/umd/service-worker.min.js.map +1 -1
  43. package/dist/umd-modern/dexie-cloud-addon.js +172 -66
  44. package/dist/umd-modern/dexie-cloud-addon.js.map +1 -1
  45. package/package.json +5 -3
@@ -20,7 +20,7 @@
20
20
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('dexie'), require('rxjs')) :
21
21
  typeof define === 'function' && define.amd ? define(['exports', 'dexie', 'rxjs'], factory) :
22
22
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.DexieCloud = {}, global.Dexie, global.rxjs));
23
- }(this, (function (exports, Dexie, rxjs) { 'use strict';
23
+ })(this, (function (exports, Dexie, rxjs) { 'use strict';
24
24
 
25
25
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
26
26
 
@@ -660,10 +660,12 @@
660
660
  for (var _i = 0; _i < arguments.length; _i++) {
661
661
  args[_i] = arguments[_i];
662
662
  }
663
- return (setTimeout).apply(void 0, __spreadArray([], __read(args)));
663
+ var delegate = timeoutProvider.delegate;
664
+ return ((delegate === null || delegate === void 0 ? void 0 : delegate.setTimeout) || setTimeout).apply(void 0, __spreadArray([], __read(args)));
664
665
  },
665
666
  clearTimeout: function (handle) {
666
- return (clearTimeout)(handle);
667
+ var delegate = timeoutProvider.delegate;
668
+ return ((delegate === null || delegate === void 0 ? void 0 : delegate.clearTimeout) || clearTimeout)(handle);
667
669
  },
668
670
  delegate: undefined,
669
671
  };
@@ -678,11 +680,33 @@
678
680
 
679
681
  function noop() { }
680
682
 
683
+ var COMPLETE_NOTIFICATION = (function () { return createNotification('C', undefined, undefined); })();
684
+ function errorNotification(error) {
685
+ return createNotification('E', undefined, error);
686
+ }
687
+ function nextNotification(value) {
688
+ return createNotification('N', value, undefined);
689
+ }
690
+ function createNotification(kind, value, error) {
691
+ return {
692
+ kind: kind,
693
+ value: value,
694
+ error: error,
695
+ };
696
+ }
697
+
698
+ var context = null;
681
699
  function errorContext(cb) {
682
700
  {
683
701
  cb();
684
702
  }
685
703
  }
704
+ function captureError(err) {
705
+ if (config.useDeprecatedSynchronousErrorHandling && context) {
706
+ context.errorThrown = true;
707
+ context.error = err;
708
+ }
709
+ }
686
710
 
687
711
  var Subscriber = (function (_super) {
688
712
  __extends(Subscriber, _super);
@@ -704,20 +728,26 @@
704
728
  return new SafeSubscriber(next, error, complete);
705
729
  };
706
730
  Subscriber.prototype.next = function (value) {
707
- if (this.isStopped) ;
731
+ if (this.isStopped) {
732
+ handleStoppedNotification(nextNotification(value), this);
733
+ }
708
734
  else {
709
735
  this._next(value);
710
736
  }
711
737
  };
712
738
  Subscriber.prototype.error = function (err) {
713
- if (this.isStopped) ;
739
+ if (this.isStopped) {
740
+ handleStoppedNotification(errorNotification(err), this);
741
+ }
714
742
  else {
715
743
  this.isStopped = true;
716
744
  this._error(err);
717
745
  }
718
746
  };
719
747
  Subscriber.prototype.complete = function () {
720
- if (this.isStopped) ;
748
+ if (this.isStopped) {
749
+ handleStoppedNotification(COMPLETE_NOTIFICATION, this);
750
+ }
721
751
  else {
722
752
  this.isStopped = true;
723
753
  this._complete();
@@ -792,7 +822,10 @@
792
822
  handler.apply(void 0, __spreadArray([], __read(args)));
793
823
  }
794
824
  catch (err) {
795
- {
825
+ if (config.useDeprecatedSynchronousErrorHandling) {
826
+ captureError(err);
827
+ }
828
+ else {
796
829
  reportUnhandledError(err);
797
830
  }
798
831
  }
@@ -801,6 +834,10 @@
801
834
  function defaultErrorHandler(err) {
802
835
  throw err;
803
836
  }
837
+ function handleStoppedNotification(notification, subscriber) {
838
+ var onStoppedNotification = config.onStoppedNotification;
839
+ onStoppedNotification && timeoutProvider.setTimeout(function () { return onStoppedNotification(notification, subscriber); });
840
+ }
804
841
  var EMPTY_OBSERVER = {
805
842
  closed: true,
806
843
  next: noop,
@@ -1176,10 +1213,12 @@
1176
1213
  for (var _i = 0; _i < arguments.length; _i++) {
1177
1214
  args[_i] = arguments[_i];
1178
1215
  }
1179
- return (setInterval).apply(void 0, __spreadArray([], __read(args)));
1216
+ var delegate = intervalProvider.delegate;
1217
+ return ((delegate === null || delegate === void 0 ? void 0 : delegate.setInterval) || setInterval).apply(void 0, __spreadArray([], __read(args)));
1180
1218
  },
1181
1219
  clearInterval: function (handle) {
1182
- return (clearInterval)(handle);
1220
+ var delegate = intervalProvider.delegate;
1221
+ return ((delegate === null || delegate === void 0 ? void 0 : delegate.clearInterval) || clearInterval)(handle);
1183
1222
  },
1184
1223
  delegate: undefined,
1185
1224
  };
@@ -1268,7 +1307,7 @@
1268
1307
 
1269
1308
  var dateTimestampProvider = {
1270
1309
  now: function () {
1271
- return (Date).now();
1310
+ return (dateTimestampProvider.delegate || Date).now();
1272
1311
  },
1273
1312
  delegate: undefined,
1274
1313
  };
@@ -1948,16 +1987,19 @@
1948
1987
  : (b) => btoa(String.fromCharCode.apply(null, b));
1949
1988
 
1950
1989
  function interactWithUser(userInteraction, req) {
1990
+ let done = false;
1951
1991
  return new Promise((resolve, reject) => {
1952
1992
  const interactionProps = {
1953
1993
  ...req,
1954
1994
  onSubmit: (res) => {
1955
1995
  userInteraction.next(undefined);
1996
+ done = true;
1956
1997
  resolve(res);
1957
1998
  },
1958
1999
  onCancel: () => {
1959
2000
  userInteraction.next(undefined);
1960
- reject(new Dexie__default['default'].AbortError("User cancelled"));
2001
+ done = true;
2002
+ reject(new Dexie__default["default"].AbortError("User cancelled"));
1961
2003
  },
1962
2004
  };
1963
2005
  userInteraction.next(interactionProps);
@@ -3187,7 +3229,7 @@
3187
3229
  const rewrittenKey = JSON.stringify(key);
3188
3230
  mutClone.keys[keyIndex] = rewrittenKey;
3189
3231
  if (rewriteValues) {
3190
- Dexie__default['default'].setByKeyPath(mutClone.values[keyIndex], primaryKey.keyPath, rewrittenKey);
3232
+ Dexie__default["default"].setByKeyPath(mutClone.values[keyIndex], primaryKey.keyPath, rewrittenKey);
3191
3233
  }
3192
3234
  }
3193
3235
  else if (key[0] === '#') {
@@ -3200,7 +3242,7 @@
3200
3242
  const rewrittenKey = `${key}:${currentUser.userId}`;
3201
3243
  mutClone.keys[keyIndex] = rewrittenKey;
3202
3244
  if (rewriteValues) {
3203
- Dexie__default['default'].setByKeyPath(mutClone.values[keyIndex], primaryKey.keyPath, rewrittenKey);
3245
+ Dexie__default["default"].setByKeyPath(mutClone.values[keyIndex], primaryKey.keyPath, rewrittenKey);
3204
3246
  }
3205
3247
  }
3206
3248
  });
@@ -3315,7 +3357,7 @@
3315
3357
 
3316
3358
  function throwIfCancelled(cancelToken) {
3317
3359
  if (cancelToken?.cancelled)
3318
- throw new Dexie__default['default'].AbortError(`Operation was cancelled`);
3360
+ throw new Dexie__default["default"].AbortError(`Operation was cancelled`);
3319
3361
  }
3320
3362
 
3321
3363
  /* Need this because navigator.onLine seems to say "false" when it is actually online.
@@ -3361,7 +3403,7 @@
3361
3403
  }
3362
3404
  }
3363
3405
  else {
3364
- Dexie__default['default'].setByKeyPath(obj, keyPath, value);
3406
+ Dexie__default["default"].setByKeyPath(obj, keyPath, value);
3365
3407
  }
3366
3408
  }
3367
3409
  resultKeys.push(key);
@@ -3374,7 +3416,7 @@
3374
3416
  }
3375
3417
 
3376
3418
  async function applyServerChanges(changes, db) {
3377
- console.debug('Applying server changes', changes, Dexie__default['default'].currentTransaction);
3419
+ console.debug('Applying server changes', changes, Dexie__default["default"].currentTransaction);
3378
3420
  for (const { table: tableName, muts } of changes) {
3379
3421
  const table = db.table(tableName);
3380
3422
  if (!table)
@@ -3411,7 +3453,7 @@
3411
3453
  else {
3412
3454
  keys.forEach((key, i) => {
3413
3455
  // Make sure inbound keys are consistent
3414
- Dexie__default['default'].setByKeyPath(mut.values[i], primaryKey.keyPath, key);
3456
+ Dexie__default["default"].setByKeyPath(mut.values[i], primaryKey.keyPath, key);
3415
3457
  });
3416
3458
  await table.bulkAdd(mut.values);
3417
3459
  }
@@ -3423,7 +3465,7 @@
3423
3465
  else {
3424
3466
  keys.forEach((key, i) => {
3425
3467
  // Make sure inbound keys are consistent
3426
- Dexie__default['default'].setByKeyPath(mut.values[i], primaryKey.keyPath, key);
3468
+ Dexie__default["default"].setByKeyPath(mut.values[i], primaryKey.keyPath, key);
3427
3469
  });
3428
3470
  await table.bulkPut(mut.values);
3429
3471
  }
@@ -3872,7 +3914,7 @@
3872
3914
  return; // Ignore message
3873
3915
  }
3874
3916
  // Verify also that the message is based on the exact same set of realms
3875
- const ourRealmSetHash = await Dexie__default['default'].waitFor(
3917
+ const ourRealmSetHash = await Dexie__default["default"].waitFor(
3876
3918
  // Keep TX in non-IDB work
3877
3919
  computeRealmSetHash(syncState));
3878
3920
  console.debug('ourRealmSetHash', ourRealmSetHash);
@@ -4056,7 +4098,7 @@
4056
4098
  const IS_SERVICE_WORKER = typeof self !== "undefined" && "clients" in self && !self.document;
4057
4099
 
4058
4100
  function throwVersionIncrementNeeded() {
4059
- throw new Dexie__default['default'].SchemaError(`Version increment needed to allow dexie-cloud change tracking`);
4101
+ throw new Dexie__default["default"].SchemaError(`Version increment needed to allow dexie-cloud change tracking`);
4060
4102
  }
4061
4103
 
4062
4104
  const { toString } = {};
@@ -4173,14 +4215,14 @@
4173
4215
  if (!table.schema.primaryKey.outbound) {
4174
4216
  if (!valueClones)
4175
4217
  valueClones = req.values.slice();
4176
- valueClones[idx] = Dexie__default['default'].deepClone(valueClones[idx]);
4177
- Dexie__default['default'].setByKeyPath(valueClones[idx], table.schema.primaryKey.keyPath, keys[idx]);
4218
+ valueClones[idx] = Dexie__default["default"].deepClone(valueClones[idx]);
4219
+ Dexie__default["default"].setByKeyPath(valueClones[idx], table.schema.primaryKey.keyPath, keys[idx]);
4178
4220
  }
4179
4221
  }
4180
4222
  else if (typeof key !== 'string' ||
4181
4223
  (!key.startsWith(idPrefix) && !key.startsWith('#' + idPrefix))) {
4182
4224
  // Key was specified by caller. Verify it complies with id prefix.
4183
- throw new Dexie__default['default'].ConstraintError(`The ID "${key}" is not valid for table "${tableName}". ` +
4225
+ throw new Dexie__default["default"].ConstraintError(`The ID "${key}" is not valid for table "${tableName}". ` +
4184
4226
  `Primary '@' keys requires the key to be prefixed with "${idPrefix}" (or "#${idPrefix}).\n` +
4185
4227
  `If you want to generate IDs programmatically, remove '@' from the schema to get rid of this constraint. Dexie Cloud supports custom IDs as long as they are random and globally unique.`);
4186
4228
  }
@@ -4210,7 +4252,7 @@
4210
4252
  const type = Array.isArray(key)
4211
4253
  ? key.map(toStringTag).join(',')
4212
4254
  : toStringTag(key);
4213
- throw new Dexie__default['default'].ConstraintError(`Invalid primary key type ${type} for table ${tableName}. Tables marked for sync has primary keys of type string or Array of string (and optional numbers)`);
4255
+ throw new Dexie__default["default"].ConstraintError(`Invalid primary key type ${type} for table ${tableName}. Tables marked for sync has primary keys of type string or Array of string (and optional numbers)`);
4214
4256
  }
4215
4257
  });
4216
4258
  }
@@ -4728,7 +4770,7 @@
4728
4770
  console.debug("Done initial sync");
4729
4771
  }
4730
4772
 
4731
- const USER_INACTIVITY_TIMEOUT = 300000; // 300_000;
4773
+ const USER_INACTIVITY_TIMEOUT = 180000; // 3 minutes
4732
4774
  const INACTIVE_WAIT_TIME = 20000;
4733
4775
  // This observable will be emitted to later down....
4734
4776
  const userIsActive = new rxjs.BehaviorSubject(true);
@@ -4742,9 +4784,13 @@
4742
4784
  // for just a short time.
4743
4785
  const userIsReallyActive = new rxjs.BehaviorSubject(true);
4744
4786
  userIsActive
4745
- .pipe(switchMap((isActive) => isActive
4746
- ? rxjs.of(true)
4747
- : rxjs.of(false).pipe(delay(INACTIVE_WAIT_TIME))), distinctUntilChanged())
4787
+ .pipe(switchMap((isActive) => {
4788
+ //console.debug('SyncStatus: DUBB: isActive changed to', isActive);
4789
+ return isActive
4790
+ ? rxjs.of(true)
4791
+ : rxjs.of(false).pipe(delay(INACTIVE_WAIT_TIME))
4792
+ ;
4793
+ }), distinctUntilChanged())
4748
4794
  .subscribe(userIsReallyActive);
4749
4795
  //
4750
4796
  // First create some corner-stone observables to build the flow on
@@ -4759,7 +4805,7 @@
4759
4805
  const documentBecomesVisible = visibilityStateIsChanged.pipe(filter(() => document.visibilityState === 'visible'));
4760
4806
  // Any of various user-activity-related events happen:
4761
4807
  const userDoesSomething = typeof window !== 'undefined'
4762
- ? rxjs.merge(documentBecomesVisible, rxjs.fromEvent(window, 'mousemove'), rxjs.fromEvent(window, 'keydown'), rxjs.fromEvent(window, 'wheel'), rxjs.fromEvent(window, 'touchmove'))
4808
+ ? rxjs.merge(documentBecomesVisible, rxjs.fromEvent(window, 'mousedown'), rxjs.fromEvent(window, 'mousemove'), rxjs.fromEvent(window, 'keydown'), rxjs.fromEvent(window, 'wheel'), rxjs.fromEvent(window, 'touchmove'))
4763
4809
  : rxjs.of({});
4764
4810
  if (typeof document !== 'undefined') {
4765
4811
  //
@@ -4810,6 +4856,7 @@
4810
4856
  constructor(databaseUrl, rev, realmSetHash, clientIdentity, token, tokenExpiration, subscriber, messageProducer, webSocketStatus) {
4811
4857
  super(() => this.teardown());
4812
4858
  this.id = ++counter;
4859
+ this.reconnecting = false;
4813
4860
  console.debug('New WebSocket Connection', this.id, token ? 'authorized' : 'unauthorized');
4814
4861
  this.databaseUrl = databaseUrl;
4815
4862
  this.rev = rev;
@@ -4829,7 +4876,7 @@
4829
4876
  this.disconnect();
4830
4877
  }
4831
4878
  disconnect() {
4832
- this.webSocketStatus.next("disconnected");
4879
+ this.webSocketStatus.next('disconnected');
4833
4880
  if (this.pinger) {
4834
4881
  clearInterval(this.pinger);
4835
4882
  this.pinger = null;
@@ -4847,11 +4894,18 @@
4847
4894
  }
4848
4895
  }
4849
4896
  reconnect() {
4850
- this.disconnect();
4851
- this.connect();
4897
+ if (this.reconnecting)
4898
+ return;
4899
+ this.reconnecting = true;
4900
+ try {
4901
+ this.disconnect();
4902
+ }
4903
+ catch { }
4904
+ this.connect()
4905
+ .catch(() => { })
4906
+ .then(() => (this.reconnecting = false)); // finally()
4852
4907
  }
4853
4908
  async connect() {
4854
- this.webSocketStatus.next("connecting");
4855
4909
  this.lastServerActivity = new Date();
4856
4910
  if (this.pauseUntil && this.pauseUntil > new Date()) {
4857
4911
  console.debug('WS not reconnecting just yet', {
@@ -4866,12 +4920,14 @@
4866
4920
  if (!this.databaseUrl)
4867
4921
  throw new Error(`Cannot connect without a database URL`);
4868
4922
  if (this.closed) {
4923
+ //console.debug('SyncStatus: DUBB: Ooops it was closed!');
4869
4924
  return;
4870
4925
  }
4871
4926
  if (this.tokenExpiration && this.tokenExpiration < new Date()) {
4872
4927
  this.subscriber.error(new TokenExpiredError()); // Will be handled in connectWebSocket.ts.
4873
4928
  return;
4874
4929
  }
4930
+ this.webSocketStatus.next('connecting');
4875
4931
  this.pinger = setInterval(async () => {
4876
4932
  if (this.closed) {
4877
4933
  console.debug('pinger check', this.id, 'CLOSED.');
@@ -4918,7 +4974,7 @@
4918
4974
  const searchParams = new URLSearchParams();
4919
4975
  if (this.subscriber.closed)
4920
4976
  return;
4921
- searchParams.set('v', "2");
4977
+ searchParams.set('v', '2');
4922
4978
  searchParams.set('rev', this.rev);
4923
4979
  searchParams.set('realmsHash', this.realmSetHash);
4924
4980
  searchParams.set('clientId', this.clientIdentity);
@@ -4957,23 +5013,30 @@
4957
5013
  }
4958
5014
  };
4959
5015
  try {
5016
+ let everConnected = false;
4960
5017
  await new Promise((resolve, reject) => {
4961
5018
  ws.onopen = (event) => {
4962
5019
  console.debug('dexie-cloud WebSocket onopen');
5020
+ everConnected = true;
4963
5021
  resolve(null);
4964
5022
  };
4965
5023
  ws.onerror = (event) => {
4966
- const error = event.error || new Error('WebSocket Error');
4967
- this.disconnect();
4968
- this.subscriber.error(error);
4969
- this.webSocketStatus.next("error");
4970
- reject(error);
5024
+ if (!everConnected) {
5025
+ const error = event.error || new Error('WebSocket Error');
5026
+ this.subscriber.error(error);
5027
+ this.webSocketStatus.next('error');
5028
+ reject(error);
5029
+ }
5030
+ else {
5031
+ this.reconnect();
5032
+ }
4971
5033
  };
4972
5034
  });
4973
- this.messageProducerSubscription = this.messageProducer.subscribe(msg => {
5035
+ this.messageProducerSubscription = this.messageProducer.subscribe((msg) => {
4974
5036
  if (!this.closed) {
4975
- if (msg.type === 'ready' && this.webSocketStatus.value !== 'connected') {
4976
- this.webSocketStatus.next("connected");
5037
+ if (msg.type === 'ready' &&
5038
+ this.webSocketStatus.value !== 'connected') {
5039
+ this.webSocketStatus.next('connected');
4977
5040
  }
4978
5041
  this.ws?.send(TSON.stringify(msg));
4979
5042
  }
@@ -5010,9 +5073,9 @@
5010
5073
  rev: syncState.serverRevision,
5011
5074
  })));
5012
5075
  function createObservable() {
5013
- return db.cloud.persistedSyncState.pipe(filter(syncState => syncState?.serverRevision), // Don't connect before there's no initial sync performed.
5076
+ return db.cloud.persistedSyncState.pipe(filter((syncState) => syncState?.serverRevision), // Don't connect before there's no initial sync performed.
5014
5077
  take(1), // Don't continue waking up whenever syncState change
5015
- switchMap((syncState) => db.cloud.currentUser.pipe(map(userLogin => [userLogin, syncState]))), switchMap(([userLogin, syncState]) => userIsReallyActive.pipe(map((isActive) => [isActive ? userLogin : null, syncState]))), switchMap(async ([userLogin, syncState]) => [userLogin, await computeRealmSetHash(syncState)]), switchMap(([userLogin, realmSetHash]) =>
5078
+ switchMap((syncState) => db.cloud.currentUser.pipe(map((userLogin) => [userLogin, syncState]))), switchMap(([userLogin, syncState]) => userIsReallyActive.pipe(map((isActive) => [isActive ? userLogin : null, syncState]))), switchMap(async ([userLogin, syncState]) => [userLogin, await computeRealmSetHash(syncState)]), switchMap(([userLogin, realmSetHash]) =>
5016
5079
  // Let server end query changes from last entry of same client-ID and forward.
5017
5080
  // If no new entries, server won't bother the client. If new entries, server sends only those
5018
5081
  // and the baseRev of the last from same client-ID.
@@ -5035,7 +5098,10 @@
5035
5098
  else {
5036
5099
  return rxjs.throwError(error);
5037
5100
  }
5038
- }), catchError((error) => rxjs.from(waitAndReconnectWhenUserDoesSomething(error)).pipe(switchMap(() => createObservable()))));
5101
+ }), catchError((error) => {
5102
+ db.cloud.webSocketStatus.next("error");
5103
+ return rxjs.from(waitAndReconnectWhenUserDoesSomething(error)).pipe(switchMap(() => createObservable()));
5104
+ }));
5039
5105
  }
5040
5106
  return createObservable().subscribe((msg) => {
5041
5107
  if (msg) {
@@ -5199,18 +5265,18 @@
5199
5265
  for (const table of db.tables) {
5200
5266
  if (db.cloud.schema?.[table.name]?.markedForSync) {
5201
5267
  if (table.schema.primKey.auto) {
5202
- throw new Dexie__default['default'].SchemaError(`Table ${table.name} is both autoIncremented and synced. ` +
5268
+ throw new Dexie__default["default"].SchemaError(`Table ${table.name} is both autoIncremented and synced. ` +
5203
5269
  `Use db.cloud.configure({unsyncedTables: [${JSON.stringify(table.name)}]}) to blacklist it from sync`);
5204
5270
  }
5205
5271
  if (!table.schema.primKey.keyPath) {
5206
- throw new Dexie__default['default'].SchemaError(`Table ${table.name} cannot be both synced and outbound. ` +
5272
+ throw new Dexie__default["default"].SchemaError(`Table ${table.name} cannot be both synced and outbound. ` +
5207
5273
  `Use db.cloud.configure({unsyncedTables: [${JSON.stringify(table.name)}]}) to blacklist it from sync`);
5208
5274
  }
5209
5275
  }
5210
5276
  }
5211
5277
  }
5212
5278
 
5213
- var n,u$1,i$1,t$1,r$1={},f$1=[],e$1=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i;function c$1(n,l){for(var u in l)n[u]=l[u];return n}function s$1(n){var l=n.parentNode;l&&l.removeChild(n);}function a$1(n,l,u){var i,t,o,r=arguments,f={};for(o in l)"key"==o?i=l[o]:"ref"==o?t=l[o]:f[o]=l[o];if(arguments.length>3)for(u=[u],o=3;o<arguments.length;o++)u.push(r[o]);if(null!=u&&(f.children=u),"function"==typeof n&&null!=n.defaultProps)for(o in n.defaultProps)void 0===f[o]&&(f[o]=n.defaultProps[o]);return v$1(n,f,i,t,null)}function v$1(l,u,i,t,o){var r={type:l,props:u,key:i,ref:t,__k:null,__:null,__b:0,__e:null,__d:void 0,__c:null,__h:null,constructor:void 0,__v:null==o?++n.__v:o};return null!=n.vnode&&n.vnode(r),r}function y(n){return n.children}function p$1(n,l){this.props=n,this.context=l;}function d$1(n,l){if(null==l)return n.__?d$1(n.__,n.__.__k.indexOf(n)+1):null;for(var u;l<n.__k.length;l++)if(null!=(u=n.__k[l])&&null!=u.__e)return u.__e;return "function"==typeof n.type?d$1(n):null}function _(n){var l,u;if(null!=(n=n.__)&&null!=n.__c){for(n.__e=n.__c.base=null,l=0;l<n.__k.length;l++)if(null!=(u=n.__k[l])&&null!=u.__e){n.__e=n.__c.base=u.__e;break}return _(n)}}function k$1(l){(!l.__d&&(l.__d=!0)&&u$1.push(l)&&!b$1.__r++||t$1!==n.debounceRendering)&&((t$1=n.debounceRendering)||i$1)(b$1);}function b$1(){for(var n;b$1.__r=u$1.length;)n=u$1.sort(function(n,l){return n.__v.__b-l.__v.__b}),u$1=[],n.some(function(n){var l,u,i,t,o,r;n.__d&&(o=(t=(l=n).__v).__e,(r=l.__P)&&(u=[],(i=c$1({},t)).__v=t.__v+1,I(r,t,i,l.__n,void 0!==r.ownerSVGElement,null!=t.__h?[o]:null,u,null==o?d$1(t):o,t.__h),T(u,t),t.__e!=o&&_(t)));});}function m$1(n,l,u,i,t,o,e,c,s,a){var h,p,_,k,b,m,w,A=i&&i.__k||f$1,P=A.length;for(u.__k=[],h=0;h<l.length;h++)if(null!=(k=u.__k[h]=null==(k=l[h])||"boolean"==typeof k?null:"string"==typeof k||"number"==typeof k||"bigint"==typeof k?v$1(null,k,null,null,k):Array.isArray(k)?v$1(y,{children:k},null,null,null):k.__b>0?v$1(k.type,k.props,k.key,null,k.__v):k)){if(k.__=u,k.__b=u.__b+1,null===(_=A[h])||_&&k.key==_.key&&k.type===_.type)A[h]=void 0;else for(p=0;p<P;p++){if((_=A[p])&&k.key==_.key&&k.type===_.type){A[p]=void 0;break}_=null;}I(n,k,_=_||r$1,t,o,e,c,s,a),b=k.__e,(p=k.ref)&&_.ref!=p&&(w||(w=[]),_.ref&&w.push(_.ref,null,k),w.push(p,k.__c||b,k)),null!=b?(null==m&&(m=b),"function"==typeof k.type&&null!=k.__k&&k.__k===_.__k?k.__d=s=g$1(k,s,n):s=x$1(n,k,_,A,b,s),a||"option"!==u.type?"function"==typeof u.type&&(u.__d=s):n.value=""):s&&_.__e==s&&s.parentNode!=n&&(s=d$1(_));}for(u.__e=m,h=P;h--;)null!=A[h]&&("function"==typeof u.type&&null!=A[h].__e&&A[h].__e==u.__d&&(u.__d=d$1(i,h+1)),L(A[h],A[h]));if(w)for(h=0;h<w.length;h++)z(w[h],w[++h],w[++h]);}function g$1(n,l,u){var i,t;for(i=0;i<n.__k.length;i++)(t=n.__k[i])&&(t.__=n,l="function"==typeof t.type?g$1(t,l,u):x$1(u,t,t,n.__k,t.__e,l));return l}function x$1(n,l,u,i,t,o){var r,f,e;if(void 0!==l.__d)r=l.__d,l.__d=void 0;else if(null==u||t!=o||null==t.parentNode)n:if(null==o||o.parentNode!==n)n.appendChild(t),r=null;else {for(f=o,e=0;(f=f.nextSibling)&&e<i.length;e+=2)if(f==t)break n;n.insertBefore(t,o),r=o;}return void 0!==r?r:t.nextSibling}function A(n,l,u,i,t){var o;for(o in u)"children"===o||"key"===o||o in l||C(n,o,null,u[o],i);for(o in l)t&&"function"!=typeof l[o]||"children"===o||"key"===o||"value"===o||"checked"===o||u[o]===l[o]||C(n,o,l[o],u[o],i);}function P(n,l,u){"-"===l[0]?n.setProperty(l,u):n[l]=null==u?"":"number"!=typeof u||e$1.test(l)?u:u+"px";}function C(n,l,u,i,t){var o;n:if("style"===l)if("string"==typeof u)n.style.cssText=u;else {if("string"==typeof i&&(n.style.cssText=i=""),i)for(l in i)u&&l in u||P(n.style,l,"");if(u)for(l in u)i&&u[l]===i[l]||P(n.style,l,u[l]);}else if("o"===l[0]&&"n"===l[1])o=l!==(l=l.replace(/Capture$/,"")),l=l.toLowerCase()in n?l.toLowerCase().slice(2):l.slice(2),n.l||(n.l={}),n.l[l+o]=u,u?i||n.addEventListener(l,o?H:$,o):n.removeEventListener(l,o?H:$,o);else if("dangerouslySetInnerHTML"!==l){if(t)l=l.replace(/xlink[H:h]/,"h").replace(/sName$/,"s");else if("href"!==l&&"list"!==l&&"form"!==l&&"tabIndex"!==l&&"download"!==l&&l in n)try{n[l]=null==u?"":u;break n}catch(n){}"function"==typeof u||(null!=u&&(!1!==u||"a"===l[0]&&"r"===l[1])?n.setAttribute(l,u):n.removeAttribute(l));}}function $(l){this.l[l.type+!1](n.event?n.event(l):l);}function H(l){this.l[l.type+!0](n.event?n.event(l):l);}function I(l,u,i,t,o,r,f,e,s){var a,v,h,d,_,k,b,g,w,x,A,P=u.type;if(void 0!==u.constructor)return null;null!=i.__h&&(s=i.__h,e=u.__e=i.__e,u.__h=null,r=[e]),(a=n.__b)&&a(u);try{n:if("function"==typeof P){if(g=u.props,w=(a=P.contextType)&&t[a.__c],x=a?w?w.props.value:a.__:t,i.__c?b=(v=u.__c=i.__c).__=v.__E:("prototype"in P&&P.prototype.render?u.__c=v=new P(g,x):(u.__c=v=new p$1(g,x),v.constructor=P,v.render=M),w&&w.sub(v),v.props=g,v.state||(v.state={}),v.context=x,v.__n=t,h=v.__d=!0,v.__h=[]),null==v.__s&&(v.__s=v.state),null!=P.getDerivedStateFromProps&&(v.__s==v.state&&(v.__s=c$1({},v.__s)),c$1(v.__s,P.getDerivedStateFromProps(g,v.__s))),d=v.props,_=v.state,h)null==P.getDerivedStateFromProps&&null!=v.componentWillMount&&v.componentWillMount(),null!=v.componentDidMount&&v.__h.push(v.componentDidMount);else {if(null==P.getDerivedStateFromProps&&g!==d&&null!=v.componentWillReceiveProps&&v.componentWillReceiveProps(g,x),!v.__e&&null!=v.shouldComponentUpdate&&!1===v.shouldComponentUpdate(g,v.__s,x)||u.__v===i.__v){v.props=g,v.state=v.__s,u.__v!==i.__v&&(v.__d=!1),v.__v=u,u.__e=i.__e,u.__k=i.__k,u.__k.forEach(function(n){n&&(n.__=u);}),v.__h.length&&f.push(v);break n}null!=v.componentWillUpdate&&v.componentWillUpdate(g,v.__s,x),null!=v.componentDidUpdate&&v.__h.push(function(){v.componentDidUpdate(d,_,k);});}v.context=x,v.props=g,v.state=v.__s,(a=n.__r)&&a(u),v.__d=!1,v.__v=u,v.__P=l,a=v.render(v.props,v.state,v.context),v.state=v.__s,null!=v.getChildContext&&(t=c$1(c$1({},t),v.getChildContext())),h||null==v.getSnapshotBeforeUpdate||(k=v.getSnapshotBeforeUpdate(d,_)),A=null!=a&&a.type===y&&null==a.key?a.props.children:a,m$1(l,Array.isArray(A)?A:[A],u,i,t,o,r,f,e,s),v.base=u.__e,u.__h=null,v.__h.length&&f.push(v),b&&(v.__E=v.__=null),v.__e=!1;}else null==r&&u.__v===i.__v?(u.__k=i.__k,u.__e=i.__e):u.__e=j$1(i.__e,u,i,t,o,r,f,s);(a=n.diffed)&&a(u);}catch(l){u.__v=null,(s||null!=r)&&(u.__e=e,u.__h=!!s,r[r.indexOf(e)]=null),n.__e(l,u,i);}}function T(l,u){n.__c&&n.__c(u,l),l.some(function(u){try{l=u.__h,u.__h=[],l.some(function(n){n.call(u);});}catch(l){n.__e(l,u.__v);}});}function j$1(n,l,u,i,t,o,e,c){var a,v,h,y,p=u.props,d=l.props,_=l.type,k=0;if("svg"===_&&(t=!0),null!=o)for(;k<o.length;k++)if((a=o[k])&&(a===n||(_?a.localName==_:3==a.nodeType))){n=a,o[k]=null;break}if(null==n){if(null===_)return document.createTextNode(d);n=t?document.createElementNS("http://www.w3.org/2000/svg",_):document.createElement(_,d.is&&d),o=null,c=!1;}if(null===_)p===d||c&&n.data===d||(n.data=d);else {if(o=o&&f$1.slice.call(n.childNodes),v=(p=u.props||r$1).dangerouslySetInnerHTML,h=d.dangerouslySetInnerHTML,!c){if(null!=o)for(p={},y=0;y<n.attributes.length;y++)p[n.attributes[y].name]=n.attributes[y].value;(h||v)&&(h&&(v&&h.__html==v.__html||h.__html===n.innerHTML)||(n.innerHTML=h&&h.__html||""));}if(A(n,d,p,t,c),h)l.__k=[];else if(k=l.props.children,m$1(n,Array.isArray(k)?k:[k],l,u,i,t&&"foreignObject"!==_,o,e,n.firstChild,c),null!=o)for(k=o.length;k--;)null!=o[k]&&s$1(o[k]);c||("value"in d&&void 0!==(k=d.value)&&(k!==n.value||"progress"===_&&!k)&&C(n,"value",k,p.value,!1),"checked"in d&&void 0!==(k=d.checked)&&k!==n.checked&&C(n,"checked",k,p.checked,!1));}return n}function z(l,u,i){try{"function"==typeof l?l(u):l.current=u;}catch(l){n.__e(l,i);}}function L(l,u,i){var t,o,r;if(n.unmount&&n.unmount(l),(t=l.ref)&&(t.current&&t.current!==l.__e||z(t,null,u)),i||"function"==typeof l.type||(i=null!=(o=l.__e)),l.__e=l.__d=void 0,null!=(t=l.__c)){if(t.componentWillUnmount)try{t.componentWillUnmount();}catch(l){n.__e(l,u);}t.base=t.__P=null;}if(t=l.__k)for(r=0;r<t.length;r++)t[r]&&L(t[r],u,i);null!=o&&s$1(o);}function M(n,l,u){return this.constructor(n,u)}function N(l,u,i){var t,o,e;n.__&&n.__(l,u),o=(t="function"==typeof i)?null:i&&i.__k||u.__k,e=[],I(u,l=(!t&&i||u).__k=a$1(y,null,[l]),o||r$1,r$1,void 0!==u.ownerSVGElement,!t&&i?[i]:o?null:u.firstChild?f$1.slice.call(u.childNodes):null,e,!t&&i?i:o?o.__e:u.firstChild,t),T(e,l);}n={__e:function(n,l){for(var u,i,t;l=l.__;)if((u=l.__c)&&!u.__)try{if((i=u.constructor)&&null!=i.getDerivedStateFromError&&(u.setState(i.getDerivedStateFromError(n)),t=u.__d),null!=u.componentDidCatch&&(u.componentDidCatch(n),t=u.__d),t)return u.__E=u}catch(l){n=l;}throw n},__v:0},p$1.prototype.setState=function(n,l){var u;u=null!=this.__s&&this.__s!==this.state?this.__s:this.__s=c$1({},this.state),"function"==typeof n&&(n=n(c$1({},u),this.props)),n&&c$1(u,n),null!=n&&this.__v&&(l&&this.__h.push(l),k$1(this));},p$1.prototype.forceUpdate=function(n){this.__v&&(this.__e=!0,n&&this.__h.push(n),k$1(this));},p$1.prototype.render=y,u$1=[],i$1="function"==typeof Promise?Promise.prototype.then.bind(Promise.resolve()):setTimeout,b$1.__r=0,0;
5279
+ var n,u$1,i$1,t$1,r$1={},f$1=[],e$1=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i;function c$1(n,l){for(var u in l)n[u]=l[u];return n}function s$1(n){var l=n.parentNode;l&&l.removeChild(n);}function a$1(n,l,u){var i,t,o,r=arguments,f={};for(o in l)"key"==o?i=l[o]:"ref"==o?t=l[o]:f[o]=l[o];if(arguments.length>3)for(u=[u],o=3;o<arguments.length;o++)u.push(r[o]);if(null!=u&&(f.children=u),"function"==typeof n&&null!=n.defaultProps)for(o in n.defaultProps)void 0===f[o]&&(f[o]=n.defaultProps[o]);return v$1(n,f,i,t,null)}function v$1(l,u,i,t,o){var r={type:l,props:u,key:i,ref:t,__k:null,__:null,__b:0,__e:null,__d:void 0,__c:null,__h:null,constructor:void 0,__v:null==o?++n.__v:o};return null!=n.vnode&&n.vnode(r),r}function y(n){return n.children}function p$1(n,l){this.props=n,this.context=l;}function d$1(n,l){if(null==l)return n.__?d$1(n.__,n.__.__k.indexOf(n)+1):null;for(var u;l<n.__k.length;l++)if(null!=(u=n.__k[l])&&null!=u.__e)return u.__e;return "function"==typeof n.type?d$1(n):null}function _(n){var l,u;if(null!=(n=n.__)&&null!=n.__c){for(n.__e=n.__c.base=null,l=0;l<n.__k.length;l++)if(null!=(u=n.__k[l])&&null!=u.__e){n.__e=n.__c.base=u.__e;break}return _(n)}}function k$1(l){(!l.__d&&(l.__d=!0)&&u$1.push(l)&&!b$1.__r++||t$1!==n.debounceRendering)&&((t$1=n.debounceRendering)||i$1)(b$1);}function b$1(){for(var n;b$1.__r=u$1.length;)n=u$1.sort(function(n,l){return n.__v.__b-l.__v.__b}),u$1=[],n.some(function(n){var l,u,i,t,o,r;n.__d&&(o=(t=(l=n).__v).__e,(r=l.__P)&&(u=[],(i=c$1({},t)).__v=t.__v+1,I(r,t,i,l.__n,void 0!==r.ownerSVGElement,null!=t.__h?[o]:null,u,null==o?d$1(t):o,t.__h),T(u,t),t.__e!=o&&_(t)));});}function m$1(n,l,u,i,t,o,e,c,s,a){var h,p,_,k,b,m,w,A=i&&i.__k||f$1,P=A.length;for(u.__k=[],h=0;h<l.length;h++)if(null!=(k=u.__k[h]=null==(k=l[h])||"boolean"==typeof k?null:"string"==typeof k||"number"==typeof k||"bigint"==typeof k?v$1(null,k,null,null,k):Array.isArray(k)?v$1(y,{children:k},null,null,null):k.__b>0?v$1(k.type,k.props,k.key,null,k.__v):k)){if(k.__=u,k.__b=u.__b+1,null===(_=A[h])||_&&k.key==_.key&&k.type===_.type)A[h]=void 0;else for(p=0;p<P;p++){if((_=A[p])&&k.key==_.key&&k.type===_.type){A[p]=void 0;break}_=null;}I(n,k,_=_||r$1,t,o,e,c,s,a),b=k.__e,(p=k.ref)&&_.ref!=p&&(w||(w=[]),_.ref&&w.push(_.ref,null,k),w.push(p,k.__c||b,k)),null!=b?(null==m&&(m=b),"function"==typeof k.type&&null!=k.__k&&k.__k===_.__k?k.__d=s=g$1(k,s,n):s=x$1(n,k,_,A,b,s),a||"option"!==u.type?"function"==typeof u.type&&(u.__d=s):n.value=""):s&&_.__e==s&&s.parentNode!=n&&(s=d$1(_));}for(u.__e=m,h=P;h--;)null!=A[h]&&("function"==typeof u.type&&null!=A[h].__e&&A[h].__e==u.__d&&(u.__d=d$1(i,h+1)),L(A[h],A[h]));if(w)for(h=0;h<w.length;h++)z(w[h],w[++h],w[++h]);}function g$1(n,l,u){var i,t;for(i=0;i<n.__k.length;i++)(t=n.__k[i])&&(t.__=n,l="function"==typeof t.type?g$1(t,l,u):x$1(u,t,t,n.__k,t.__e,l));return l}function x$1(n,l,u,i,t,o){var r,f,e;if(void 0!==l.__d)r=l.__d,l.__d=void 0;else if(null==u||t!=o||null==t.parentNode)n:if(null==o||o.parentNode!==n)n.appendChild(t),r=null;else {for(f=o,e=0;(f=f.nextSibling)&&e<i.length;e+=2)if(f==t)break n;n.insertBefore(t,o),r=o;}return void 0!==r?r:t.nextSibling}function A(n,l,u,i,t){var o;for(o in u)"children"===o||"key"===o||o in l||C(n,o,null,u[o],i);for(o in l)t&&"function"!=typeof l[o]||"children"===o||"key"===o||"value"===o||"checked"===o||u[o]===l[o]||C(n,o,l[o],u[o],i);}function P(n,l,u){"-"===l[0]?n.setProperty(l,u):n[l]=null==u?"":"number"!=typeof u||e$1.test(l)?u:u+"px";}function C(n,l,u,i,t){var o;n:if("style"===l)if("string"==typeof u)n.style.cssText=u;else {if("string"==typeof i&&(n.style.cssText=i=""),i)for(l in i)u&&l in u||P(n.style,l,"");if(u)for(l in u)i&&u[l]===i[l]||P(n.style,l,u[l]);}else if("o"===l[0]&&"n"===l[1])o=l!==(l=l.replace(/Capture$/,"")),l=l.toLowerCase()in n?l.toLowerCase().slice(2):l.slice(2),n.l||(n.l={}),n.l[l+o]=u,u?i||n.addEventListener(l,o?H:$,o):n.removeEventListener(l,o?H:$,o);else if("dangerouslySetInnerHTML"!==l){if(t)l=l.replace(/xlink[H:h]/,"h").replace(/sName$/,"s");else if("href"!==l&&"list"!==l&&"form"!==l&&"tabIndex"!==l&&"download"!==l&&l in n)try{n[l]=null==u?"":u;break n}catch(n){}"function"==typeof u||(null!=u&&(!1!==u||"a"===l[0]&&"r"===l[1])?n.setAttribute(l,u):n.removeAttribute(l));}}function $(l){this.l[l.type+!1](n.event?n.event(l):l);}function H(l){this.l[l.type+!0](n.event?n.event(l):l);}function I(l,u,i,t,o,r,f,e,s){var a,v,h,d,_,k,b,g,w,x,A,P=u.type;if(void 0!==u.constructor)return null;null!=i.__h&&(s=i.__h,e=u.__e=i.__e,u.__h=null,r=[e]),(a=n.__b)&&a(u);try{n:if("function"==typeof P){if(g=u.props,w=(a=P.contextType)&&t[a.__c],x=a?w?w.props.value:a.__:t,i.__c?b=(v=u.__c=i.__c).__=v.__E:("prototype"in P&&P.prototype.render?u.__c=v=new P(g,x):(u.__c=v=new p$1(g,x),v.constructor=P,v.render=M),w&&w.sub(v),v.props=g,v.state||(v.state={}),v.context=x,v.__n=t,h=v.__d=!0,v.__h=[]),null==v.__s&&(v.__s=v.state),null!=P.getDerivedStateFromProps&&(v.__s==v.state&&(v.__s=c$1({},v.__s)),c$1(v.__s,P.getDerivedStateFromProps(g,v.__s))),d=v.props,_=v.state,h)null==P.getDerivedStateFromProps&&null!=v.componentWillMount&&v.componentWillMount(),null!=v.componentDidMount&&v.__h.push(v.componentDidMount);else {if(null==P.getDerivedStateFromProps&&g!==d&&null!=v.componentWillReceiveProps&&v.componentWillReceiveProps(g,x),!v.__e&&null!=v.shouldComponentUpdate&&!1===v.shouldComponentUpdate(g,v.__s,x)||u.__v===i.__v){v.props=g,v.state=v.__s,u.__v!==i.__v&&(v.__d=!1),v.__v=u,u.__e=i.__e,u.__k=i.__k,u.__k.forEach(function(n){n&&(n.__=u);}),v.__h.length&&f.push(v);break n}null!=v.componentWillUpdate&&v.componentWillUpdate(g,v.__s,x),null!=v.componentDidUpdate&&v.__h.push(function(){v.componentDidUpdate(d,_,k);});}v.context=x,v.props=g,v.state=v.__s,(a=n.__r)&&a(u),v.__d=!1,v.__v=u,v.__P=l,a=v.render(v.props,v.state,v.context),v.state=v.__s,null!=v.getChildContext&&(t=c$1(c$1({},t),v.getChildContext())),h||null==v.getSnapshotBeforeUpdate||(k=v.getSnapshotBeforeUpdate(d,_)),A=null!=a&&a.type===y&&null==a.key?a.props.children:a,m$1(l,Array.isArray(A)?A:[A],u,i,t,o,r,f,e,s),v.base=u.__e,u.__h=null,v.__h.length&&f.push(v),b&&(v.__E=v.__=null),v.__e=!1;}else null==r&&u.__v===i.__v?(u.__k=i.__k,u.__e=i.__e):u.__e=j$1(i.__e,u,i,t,o,r,f,s);(a=n.diffed)&&a(u);}catch(l){u.__v=null,(s||null!=r)&&(u.__e=e,u.__h=!!s,r[r.indexOf(e)]=null),n.__e(l,u,i);}}function T(l,u){n.__c&&n.__c(u,l),l.some(function(u){try{l=u.__h,u.__h=[],l.some(function(n){n.call(u);});}catch(l){n.__e(l,u.__v);}});}function j$1(n,l,u,i,t,o,e,c){var a,v,h,y,p=u.props,d=l.props,_=l.type,k=0;if("svg"===_&&(t=!0),null!=o)for(;k<o.length;k++)if((a=o[k])&&(a===n||(_?a.localName==_:3==a.nodeType))){n=a,o[k]=null;break}if(null==n){if(null===_)return document.createTextNode(d);n=t?document.createElementNS("http://www.w3.org/2000/svg",_):document.createElement(_,d.is&&d),o=null,c=!1;}if(null===_)p===d||c&&n.data===d||(n.data=d);else {if(o=o&&f$1.slice.call(n.childNodes),v=(p=u.props||r$1).dangerouslySetInnerHTML,h=d.dangerouslySetInnerHTML,!c){if(null!=o)for(p={},y=0;y<n.attributes.length;y++)p[n.attributes[y].name]=n.attributes[y].value;(h||v)&&(h&&(v&&h.__html==v.__html||h.__html===n.innerHTML)||(n.innerHTML=h&&h.__html||""));}if(A(n,d,p,t,c),h)l.__k=[];else if(k=l.props.children,m$1(n,Array.isArray(k)?k:[k],l,u,i,t&&"foreignObject"!==_,o,e,n.firstChild,c),null!=o)for(k=o.length;k--;)null!=o[k]&&s$1(o[k]);c||("value"in d&&void 0!==(k=d.value)&&(k!==n.value||"progress"===_&&!k)&&C(n,"value",k,p.value,!1),"checked"in d&&void 0!==(k=d.checked)&&k!==n.checked&&C(n,"checked",k,p.checked,!1));}return n}function z(l,u,i){try{"function"==typeof l?l(u):l.current=u;}catch(l){n.__e(l,i);}}function L(l,u,i){var t,o,r;if(n.unmount&&n.unmount(l),(t=l.ref)&&(t.current&&t.current!==l.__e||z(t,null,u)),i||"function"==typeof l.type||(i=null!=(o=l.__e)),l.__e=l.__d=void 0,null!=(t=l.__c)){if(t.componentWillUnmount)try{t.componentWillUnmount();}catch(l){n.__e(l,u);}t.base=t.__P=null;}if(t=l.__k)for(r=0;r<t.length;r++)t[r]&&L(t[r],u,i);null!=o&&s$1(o);}function M(n,l,u){return this.constructor(n,u)}function N(l,u,i){var t,o,e;n.__&&n.__(l,u),o=(t="function"==typeof i)?null:i&&i.__k||u.__k,e=[],I(u,l=(!t&&i||u).__k=a$1(y,null,[l]),o||r$1,r$1,void 0!==u.ownerSVGElement,!t&&i?[i]:o?null:u.firstChild?f$1.slice.call(u.childNodes):null,e,!t&&i?i:o?o.__e:u.firstChild,t),T(e,l);}n={__e:function(n,l){for(var u,i,t;l=l.__;)if((u=l.__c)&&!u.__)try{if((i=u.constructor)&&null!=i.getDerivedStateFromError&&(u.setState(i.getDerivedStateFromError(n)),t=u.__d),null!=u.componentDidCatch&&(u.componentDidCatch(n),t=u.__d),t)return u.__E=u}catch(l){n=l;}throw n},__v:0},p$1.prototype.setState=function(n,l){var u;u=null!=this.__s&&this.__s!==this.state?this.__s:this.__s=c$1({},this.state),"function"==typeof n&&(n=n(c$1({},u),this.props)),n&&c$1(u,n),null!=n&&this.__v&&(l&&this.__h.push(l),k$1(this));},p$1.prototype.forceUpdate=function(n){this.__v&&(this.__e=!0,n&&this.__h.push(n),k$1(this));},p$1.prototype.render=y,u$1=[],i$1="function"==typeof Promise?Promise.prototype.then.bind(Promise.resolve()):setTimeout,b$1.__r=0;
5214
5280
 
5215
5281
  const Styles = {
5216
5282
  Error: {
@@ -5459,6 +5525,21 @@
5459
5525
  return rv;
5460
5526
  }
5461
5527
 
5528
+ const getGlobalRolesObservable = associate((db) => {
5529
+ return createSharedValueObservable(Dexie.liveQuery(() => db.roles
5530
+ .where({ realmId: 'rlm-public' })
5531
+ .toArray()
5532
+ .then((roles) => {
5533
+ const rv = {};
5534
+ for (const role of roles
5535
+ .slice()
5536
+ .sort((a, b) => (a.sortOrder || 0) - (b.sortOrder || 0))) {
5537
+ rv[role.name] = role;
5538
+ }
5539
+ return rv;
5540
+ })), {});
5541
+ });
5542
+
5462
5543
  const getCurrentUserEmitter = associate((db) => new rxjs.BehaviorSubject(UNAUTHORIZED_USER));
5463
5544
 
5464
5545
  const getInternalAccessControlObservable = associate((db) => {
@@ -5560,18 +5641,38 @@
5560
5641
  }
5561
5642
 
5562
5643
  const getPermissionsLookupObservable = associate((db) => {
5563
- const o = getInternalAccessControlObservable(db._novip);
5564
- return mapValueObservable(o, ({ selfMembers, realms, userId }) => {
5644
+ const o = createSharedValueObservable(rxjs.combineLatest([
5645
+ getInternalAccessControlObservable(db._novip),
5646
+ getGlobalRolesObservable(db._novip),
5647
+ ]).pipe(map(([{ selfMembers, realms, userId }, globalRoles]) => ({
5648
+ selfMembers,
5649
+ realms,
5650
+ userId,
5651
+ globalRoles,
5652
+ }))), {
5653
+ selfMembers: [],
5654
+ realms: [],
5655
+ userId: UNAUTHORIZED_USER.userId,
5656
+ globalRoles: {},
5657
+ });
5658
+ return mapValueObservable(o, ({ selfMembers, realms, userId, globalRoles }) => {
5565
5659
  const rv = realms
5566
- .map((realm) => ({
5567
- ...realm,
5568
- permissions: realm.owner === userId
5569
- ? { manage: '*' }
5570
- : mergePermissions(...selfMembers
5571
- .filter((m) => m.realmId === realm.realmId)
5572
- .map((m) => m.permissions)
5573
- .filter((p) => p)),
5574
- }))
5660
+ .map((realm) => {
5661
+ const selfRealmMembers = selfMembers.filter((m) => m.realmId === realm.realmId);
5662
+ const directPermissionSets = selfRealmMembers
5663
+ .map((m) => m.permissions)
5664
+ .filter((p) => p);
5665
+ const rolePermissionSets = flatten(selfRealmMembers.map((m) => m.roles).filter((roleName) => roleName))
5666
+ .map((role) => globalRoles[role])
5667
+ .filter((role) => role)
5668
+ .map((role) => role.permissions);
5669
+ return {
5670
+ ...realm,
5671
+ permissions: realm.owner === userId
5672
+ ? { manage: '*' }
5673
+ : mergePermissions(...directPermissionSets, ...rolePermissionSets),
5674
+ };
5675
+ })
5575
5676
  .reduce((p, c) => ({ ...p, [c.realmId]: c }), {
5576
5677
  [userId]: {
5577
5678
  realmId: userId,
@@ -5655,7 +5756,7 @@
5655
5756
  const realm = permissionsLookup[realmId || dexie.cloud.currentUserId];
5656
5757
  if (!realm)
5657
5758
  return new PermissionChecker({}, tableName, !owner || owner === dexie.cloud.currentUserId);
5658
- return new PermissionChecker(realm.permissions, tableName, !owner || owner === dexie.cloud.currentUserId);
5759
+ return new PermissionChecker(realm.permissions, tableName, realmId === dexie.cloud.currentUserId || owner === dexie.cloud.currentUserId);
5659
5760
  };
5660
5761
  const o = source.pipe(map(mapper));
5661
5762
  o.getValue = () => mapper(source.getValue());
@@ -5691,6 +5792,7 @@
5691
5792
  //
5692
5793
  const currentUserEmitter = getCurrentUserEmitter(dexie);
5693
5794
  const subscriptions = [];
5795
+ let configuredProgramatically = false;
5694
5796
  // local sync worker - used when there's no service worker.
5695
5797
  let localSyncWorker = null;
5696
5798
  dexie.on('ready', async (dexie) => {
@@ -5707,7 +5809,7 @@
5707
5809
  let closed = false;
5708
5810
  function throwIfClosed() {
5709
5811
  if (closed)
5710
- throw new Dexie__default['default'].DatabaseClosedError();
5812
+ throw new Dexie__default["default"].DatabaseClosedError();
5711
5813
  }
5712
5814
  dbOnClosed(dexie, () => {
5713
5815
  subscriptions.forEach((subscription) => subscription.unsubscribe());
@@ -5738,8 +5840,10 @@
5738
5840
  await login(db, hint);
5739
5841
  },
5740
5842
  invites: getInvitesObservable(dexie),
5843
+ roles: getGlobalRolesObservable(dexie),
5741
5844
  configure(options) {
5742
5845
  options = dexie.cloud.options = { ...dexie.cloud.options, ...options };
5846
+ configuredProgramatically = true;
5743
5847
  if (options.databaseUrl && options.nameSuffix) {
5744
5848
  // @ts-ignore
5745
5849
  dexie.name = `${origIdbName}-${getDbNameFromDbUrl(options.databaseUrl)}`;
@@ -5787,7 +5891,7 @@
5787
5891
  return permissions(dexie._novip, obj, tableName);
5788
5892
  },
5789
5893
  };
5790
- dexie.Version.prototype['_parseStoresSpec'] = Dexie__default['default'].override(dexie.Version.prototype['_parseStoresSpec'], (origFunc) => overrideParseStoresSpec(origFunc, dexie));
5894
+ dexie.Version.prototype['_parseStoresSpec'] = Dexie__default["default"].override(dexie.Version.prototype['_parseStoresSpec'], (origFunc) => overrideParseStoresSpec(origFunc, dexie));
5791
5895
  dexie.Table.prototype.newId = function ({ colocateWith } = {}) {
5792
5896
  const shardKey = colocateWith && colocateWith.substr(colocateWith.length - 3);
5793
5897
  return generateKey(dexie.cloud.schema[this.name].idPrefix || '', shardKey);
@@ -5826,7 +5930,7 @@
5826
5930
  db.getSchema(),
5827
5931
  db.getPersistedSyncState(),
5828
5932
  ]);
5829
- if (!options) {
5933
+ if (!configuredProgramatically) {
5830
5934
  // Options not specified programatically (use case for SW!)
5831
5935
  // Take persisted options:
5832
5936
  db.cloud.options = persistedOptions || null;
@@ -5834,6 +5938,8 @@
5834
5938
  else if (!persistedOptions ||
5835
5939
  JSON.stringify(persistedOptions) !== JSON.stringify(options)) {
5836
5940
  // Update persisted options:
5941
+ if (!options)
5942
+ throw new Error(`Internal error`); // options cannot be null if configuredProgramatically is set.
5837
5943
  await db.$syncState.put(options, 'options');
5838
5944
  }
5839
5945
  if (db.cloud.options?.tryUseServiceWorker &&
@@ -5956,14 +6062,14 @@
5956
6062
  }
5957
6063
  }
5958
6064
  dexieCloud.version = '{version}';
5959
- Dexie__default['default'].Cloud = dexieCloud;
6065
+ Dexie__default["default"].Cloud = dexieCloud;
5960
6066
 
5961
- exports.default = dexieCloud;
6067
+ exports["default"] = dexieCloud;
5962
6068
  exports.dexieCloud = dexieCloud;
5963
6069
  exports.getTiedObjectId = getTiedObjectId;
5964
6070
  exports.getTiedRealmId = getTiedRealmId;
5965
6071
 
5966
6072
  Object.defineProperty(exports, '__esModule', { value: true });
5967
6073
 
5968
- })));
6074
+ }));
5969
6075
  //# sourceMappingURL=dexie-cloud-addon.js.map