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
@@ -2,7 +2,7 @@
2
2
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('dexie'), require('rxjs')) :
3
3
  typeof define === 'function' && define.amd ? define(['dexie', 'rxjs'], factory) :
4
4
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Dexie, global.rxjs));
5
- }(this, (function (Dexie, rxjs) { 'use strict';
5
+ })(this, (function (Dexie, rxjs) { 'use strict';
6
6
 
7
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
8
 
@@ -447,10 +447,12 @@
447
447
  for (var _i = 0; _i < arguments.length; _i++) {
448
448
  args[_i] = arguments[_i];
449
449
  }
450
- return (setTimeout).apply(void 0, __spreadArray([], __read(args)));
450
+ var delegate = timeoutProvider.delegate;
451
+ return ((delegate === null || delegate === void 0 ? void 0 : delegate.setTimeout) || setTimeout).apply(void 0, __spreadArray([], __read(args)));
451
452
  },
452
453
  clearTimeout: function (handle) {
453
- return (clearTimeout)(handle);
454
+ var delegate = timeoutProvider.delegate;
455
+ return ((delegate === null || delegate === void 0 ? void 0 : delegate.clearTimeout) || clearTimeout)(handle);
454
456
  },
455
457
  delegate: undefined,
456
458
  };
@@ -465,11 +467,33 @@
465
467
 
466
468
  function noop() { }
467
469
 
470
+ var COMPLETE_NOTIFICATION = (function () { return createNotification('C', undefined, undefined); })();
471
+ function errorNotification(error) {
472
+ return createNotification('E', undefined, error);
473
+ }
474
+ function nextNotification(value) {
475
+ return createNotification('N', value, undefined);
476
+ }
477
+ function createNotification(kind, value, error) {
478
+ return {
479
+ kind: kind,
480
+ value: value,
481
+ error: error,
482
+ };
483
+ }
484
+
485
+ var context = null;
468
486
  function errorContext(cb) {
469
487
  {
470
488
  cb();
471
489
  }
472
490
  }
491
+ function captureError(err) {
492
+ if (config.useDeprecatedSynchronousErrorHandling && context) {
493
+ context.errorThrown = true;
494
+ context.error = err;
495
+ }
496
+ }
473
497
 
474
498
  var Subscriber = (function (_super) {
475
499
  __extends(Subscriber, _super);
@@ -491,20 +515,26 @@
491
515
  return new SafeSubscriber(next, error, complete);
492
516
  };
493
517
  Subscriber.prototype.next = function (value) {
494
- if (this.isStopped) ;
518
+ if (this.isStopped) {
519
+ handleStoppedNotification(nextNotification(value), this);
520
+ }
495
521
  else {
496
522
  this._next(value);
497
523
  }
498
524
  };
499
525
  Subscriber.prototype.error = function (err) {
500
- if (this.isStopped) ;
526
+ if (this.isStopped) {
527
+ handleStoppedNotification(errorNotification(err), this);
528
+ }
501
529
  else {
502
530
  this.isStopped = true;
503
531
  this._error(err);
504
532
  }
505
533
  };
506
534
  Subscriber.prototype.complete = function () {
507
- if (this.isStopped) ;
535
+ if (this.isStopped) {
536
+ handleStoppedNotification(COMPLETE_NOTIFICATION, this);
537
+ }
508
538
  else {
509
539
  this.isStopped = true;
510
540
  this._complete();
@@ -579,7 +609,10 @@
579
609
  handler.apply(void 0, __spreadArray([], __read(args)));
580
610
  }
581
611
  catch (err) {
582
- {
612
+ if (config.useDeprecatedSynchronousErrorHandling) {
613
+ captureError(err);
614
+ }
615
+ else {
583
616
  reportUnhandledError(err);
584
617
  }
585
618
  }
@@ -588,6 +621,10 @@
588
621
  function defaultErrorHandler(err) {
589
622
  throw err;
590
623
  }
624
+ function handleStoppedNotification(notification, subscriber) {
625
+ var onStoppedNotification = config.onStoppedNotification;
626
+ onStoppedNotification && timeoutProvider.setTimeout(function () { return onStoppedNotification(notification, subscriber); });
627
+ }
591
628
  var EMPTY_OBSERVER = {
592
629
  closed: true,
593
630
  next: noop,
@@ -963,10 +1000,12 @@
963
1000
  for (var _i = 0; _i < arguments.length; _i++) {
964
1001
  args[_i] = arguments[_i];
965
1002
  }
966
- return (setInterval).apply(void 0, __spreadArray([], __read(args)));
1003
+ var delegate = intervalProvider.delegate;
1004
+ return ((delegate === null || delegate === void 0 ? void 0 : delegate.setInterval) || setInterval).apply(void 0, __spreadArray([], __read(args)));
967
1005
  },
968
1006
  clearInterval: function (handle) {
969
- return (clearInterval)(handle);
1007
+ var delegate = intervalProvider.delegate;
1008
+ return ((delegate === null || delegate === void 0 ? void 0 : delegate.clearInterval) || clearInterval)(handle);
970
1009
  },
971
1010
  delegate: undefined,
972
1011
  };
@@ -1055,7 +1094,7 @@
1055
1094
 
1056
1095
  var dateTimestampProvider = {
1057
1096
  now: function () {
1058
- return (Date).now();
1097
+ return (dateTimestampProvider.delegate || Date).now();
1059
1098
  },
1060
1099
  delegate: undefined,
1061
1100
  };
@@ -2174,16 +2213,19 @@
2174
2213
  }
2175
2214
 
2176
2215
  function interactWithUser(userInteraction, req) {
2216
+ let done = false;
2177
2217
  return new Promise((resolve, reject) => {
2178
2218
  const interactionProps = {
2179
2219
  ...req,
2180
2220
  onSubmit: (res) => {
2181
2221
  userInteraction.next(undefined);
2222
+ done = true;
2182
2223
  resolve(res);
2183
2224
  },
2184
2225
  onCancel: () => {
2185
2226
  userInteraction.next(undefined);
2186
- reject(new Dexie__default['default'].AbortError("User cancelled"));
2227
+ done = true;
2228
+ reject(new Dexie__default["default"].AbortError("User cancelled"));
2187
2229
  },
2188
2230
  };
2189
2231
  userInteraction.next(interactionProps);
@@ -2963,7 +3005,7 @@
2963
3005
  const rewrittenKey = JSON.stringify(key);
2964
3006
  mutClone.keys[keyIndex] = rewrittenKey;
2965
3007
  if (rewriteValues) {
2966
- Dexie__default['default'].setByKeyPath(mutClone.values[keyIndex], primaryKey.keyPath, rewrittenKey);
3008
+ Dexie__default["default"].setByKeyPath(mutClone.values[keyIndex], primaryKey.keyPath, rewrittenKey);
2967
3009
  }
2968
3010
  }
2969
3011
  else if (key[0] === '#') {
@@ -2976,7 +3018,7 @@
2976
3018
  const rewrittenKey = `${key}:${currentUser.userId}`;
2977
3019
  mutClone.keys[keyIndex] = rewrittenKey;
2978
3020
  if (rewriteValues) {
2979
- Dexie__default['default'].setByKeyPath(mutClone.values[keyIndex], primaryKey.keyPath, rewrittenKey);
3021
+ Dexie__default["default"].setByKeyPath(mutClone.values[keyIndex], primaryKey.keyPath, rewrittenKey);
2980
3022
  }
2981
3023
  }
2982
3024
  });
@@ -3091,7 +3133,7 @@
3091
3133
 
3092
3134
  function throwIfCancelled(cancelToken) {
3093
3135
  if (cancelToken?.cancelled)
3094
- throw new Dexie__default['default'].AbortError(`Operation was cancelled`);
3136
+ throw new Dexie__default["default"].AbortError(`Operation was cancelled`);
3095
3137
  }
3096
3138
 
3097
3139
  /* Need this because navigator.onLine seems to say "false" when it is actually online.
@@ -3137,7 +3179,7 @@
3137
3179
  }
3138
3180
  }
3139
3181
  else {
3140
- Dexie__default['default'].setByKeyPath(obj, keyPath, value);
3182
+ Dexie__default["default"].setByKeyPath(obj, keyPath, value);
3141
3183
  }
3142
3184
  }
3143
3185
  resultKeys.push(key);
@@ -3150,7 +3192,7 @@
3150
3192
  }
3151
3193
 
3152
3194
  async function applyServerChanges(changes, db) {
3153
- console.debug('Applying server changes', changes, Dexie__default['default'].currentTransaction);
3195
+ console.debug('Applying server changes', changes, Dexie__default["default"].currentTransaction);
3154
3196
  for (const { table: tableName, muts } of changes) {
3155
3197
  const table = db.table(tableName);
3156
3198
  if (!table)
@@ -3187,7 +3229,7 @@
3187
3229
  else {
3188
3230
  keys.forEach((key, i) => {
3189
3231
  // Make sure inbound keys are consistent
3190
- Dexie__default['default'].setByKeyPath(mut.values[i], primaryKey.keyPath, key);
3232
+ Dexie__default["default"].setByKeyPath(mut.values[i], primaryKey.keyPath, key);
3191
3233
  });
3192
3234
  await table.bulkAdd(mut.values);
3193
3235
  }
@@ -3199,7 +3241,7 @@
3199
3241
  else {
3200
3242
  keys.forEach((key, i) => {
3201
3243
  // Make sure inbound keys are consistent
3202
- Dexie__default['default'].setByKeyPath(mut.values[i], primaryKey.keyPath, key);
3244
+ Dexie__default["default"].setByKeyPath(mut.values[i], primaryKey.keyPath, key);
3203
3245
  });
3204
3246
  await table.bulkPut(mut.values);
3205
3247
  }
@@ -3648,7 +3690,7 @@
3648
3690
  return; // Ignore message
3649
3691
  }
3650
3692
  // Verify also that the message is based on the exact same set of realms
3651
- const ourRealmSetHash = await Dexie__default['default'].waitFor(
3693
+ const ourRealmSetHash = await Dexie__default["default"].waitFor(
3652
3694
  // Keep TX in non-IDB work
3653
3695
  computeRealmSetHash(syncState));
3654
3696
  console.debug('ourRealmSetHash', ourRealmSetHash);
@@ -4038,7 +4080,7 @@
4038
4080
  const IS_SERVICE_WORKER = typeof self !== "undefined" && "clients" in self && !self.document;
4039
4081
 
4040
4082
  function throwVersionIncrementNeeded() {
4041
- throw new Dexie__default['default'].SchemaError(`Version increment needed to allow dexie-cloud change tracking`);
4083
+ throw new Dexie__default["default"].SchemaError(`Version increment needed to allow dexie-cloud change tracking`);
4042
4084
  }
4043
4085
 
4044
4086
  const { toString } = {};
@@ -4155,14 +4197,14 @@
4155
4197
  if (!table.schema.primaryKey.outbound) {
4156
4198
  if (!valueClones)
4157
4199
  valueClones = req.values.slice();
4158
- valueClones[idx] = Dexie__default['default'].deepClone(valueClones[idx]);
4159
- Dexie__default['default'].setByKeyPath(valueClones[idx], table.schema.primaryKey.keyPath, keys[idx]);
4200
+ valueClones[idx] = Dexie__default["default"].deepClone(valueClones[idx]);
4201
+ Dexie__default["default"].setByKeyPath(valueClones[idx], table.schema.primaryKey.keyPath, keys[idx]);
4160
4202
  }
4161
4203
  }
4162
4204
  else if (typeof key !== 'string' ||
4163
4205
  (!key.startsWith(idPrefix) && !key.startsWith('#' + idPrefix))) {
4164
4206
  // Key was specified by caller. Verify it complies with id prefix.
4165
- throw new Dexie__default['default'].ConstraintError(`The ID "${key}" is not valid for table "${tableName}". ` +
4207
+ throw new Dexie__default["default"].ConstraintError(`The ID "${key}" is not valid for table "${tableName}". ` +
4166
4208
  `Primary '@' keys requires the key to be prefixed with "${idPrefix}" (or "#${idPrefix}).\n` +
4167
4209
  `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.`);
4168
4210
  }
@@ -4192,7 +4234,7 @@
4192
4234
  const type = Array.isArray(key)
4193
4235
  ? key.map(toStringTag).join(',')
4194
4236
  : toStringTag(key);
4195
- 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)`);
4237
+ 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)`);
4196
4238
  }
4197
4239
  });
4198
4240
  }
@@ -4710,7 +4752,7 @@
4710
4752
  console.debug("Done initial sync");
4711
4753
  }
4712
4754
 
4713
- const USER_INACTIVITY_TIMEOUT = 300000; // 300_000;
4755
+ const USER_INACTIVITY_TIMEOUT = 180000; // 3 minutes
4714
4756
  const INACTIVE_WAIT_TIME = 20000;
4715
4757
  // This observable will be emitted to later down....
4716
4758
  const userIsActive = new rxjs.BehaviorSubject(true);
@@ -4724,9 +4766,13 @@
4724
4766
  // for just a short time.
4725
4767
  const userIsReallyActive = new rxjs.BehaviorSubject(true);
4726
4768
  userIsActive
4727
- .pipe(switchMap((isActive) => isActive
4728
- ? rxjs.of(true)
4729
- : rxjs.of(false).pipe(delay(INACTIVE_WAIT_TIME))), distinctUntilChanged())
4769
+ .pipe(switchMap((isActive) => {
4770
+ //console.debug('SyncStatus: DUBB: isActive changed to', isActive);
4771
+ return isActive
4772
+ ? rxjs.of(true)
4773
+ : rxjs.of(false).pipe(delay(INACTIVE_WAIT_TIME))
4774
+ ;
4775
+ }), distinctUntilChanged())
4730
4776
  .subscribe(userIsReallyActive);
4731
4777
  //
4732
4778
  // First create some corner-stone observables to build the flow on
@@ -4741,7 +4787,7 @@
4741
4787
  const documentBecomesVisible = visibilityStateIsChanged.pipe(filter(() => document.visibilityState === 'visible'));
4742
4788
  // Any of various user-activity-related events happen:
4743
4789
  const userDoesSomething = typeof window !== 'undefined'
4744
- ? rxjs.merge(documentBecomesVisible, rxjs.fromEvent(window, 'mousemove'), rxjs.fromEvent(window, 'keydown'), rxjs.fromEvent(window, 'wheel'), rxjs.fromEvent(window, 'touchmove'))
4790
+ ? rxjs.merge(documentBecomesVisible, rxjs.fromEvent(window, 'mousedown'), rxjs.fromEvent(window, 'mousemove'), rxjs.fromEvent(window, 'keydown'), rxjs.fromEvent(window, 'wheel'), rxjs.fromEvent(window, 'touchmove'))
4745
4791
  : rxjs.of({});
4746
4792
  if (typeof document !== 'undefined') {
4747
4793
  //
@@ -4792,6 +4838,7 @@
4792
4838
  constructor(databaseUrl, rev, realmSetHash, clientIdentity, token, tokenExpiration, subscriber, messageProducer, webSocketStatus) {
4793
4839
  super(() => this.teardown());
4794
4840
  this.id = ++counter;
4841
+ this.reconnecting = false;
4795
4842
  console.debug('New WebSocket Connection', this.id, token ? 'authorized' : 'unauthorized');
4796
4843
  this.databaseUrl = databaseUrl;
4797
4844
  this.rev = rev;
@@ -4811,7 +4858,7 @@
4811
4858
  this.disconnect();
4812
4859
  }
4813
4860
  disconnect() {
4814
- this.webSocketStatus.next("disconnected");
4861
+ this.webSocketStatus.next('disconnected');
4815
4862
  if (this.pinger) {
4816
4863
  clearInterval(this.pinger);
4817
4864
  this.pinger = null;
@@ -4829,11 +4876,18 @@
4829
4876
  }
4830
4877
  }
4831
4878
  reconnect() {
4832
- this.disconnect();
4833
- this.connect();
4879
+ if (this.reconnecting)
4880
+ return;
4881
+ this.reconnecting = true;
4882
+ try {
4883
+ this.disconnect();
4884
+ }
4885
+ catch { }
4886
+ this.connect()
4887
+ .catch(() => { })
4888
+ .then(() => (this.reconnecting = false)); // finally()
4834
4889
  }
4835
4890
  async connect() {
4836
- this.webSocketStatus.next("connecting");
4837
4891
  this.lastServerActivity = new Date();
4838
4892
  if (this.pauseUntil && this.pauseUntil > new Date()) {
4839
4893
  console.debug('WS not reconnecting just yet', {
@@ -4848,12 +4902,14 @@
4848
4902
  if (!this.databaseUrl)
4849
4903
  throw new Error(`Cannot connect without a database URL`);
4850
4904
  if (this.closed) {
4905
+ //console.debug('SyncStatus: DUBB: Ooops it was closed!');
4851
4906
  return;
4852
4907
  }
4853
4908
  if (this.tokenExpiration && this.tokenExpiration < new Date()) {
4854
4909
  this.subscriber.error(new TokenExpiredError()); // Will be handled in connectWebSocket.ts.
4855
4910
  return;
4856
4911
  }
4912
+ this.webSocketStatus.next('connecting');
4857
4913
  this.pinger = setInterval(async () => {
4858
4914
  if (this.closed) {
4859
4915
  console.debug('pinger check', this.id, 'CLOSED.');
@@ -4900,7 +4956,7 @@
4900
4956
  const searchParams = new URLSearchParams();
4901
4957
  if (this.subscriber.closed)
4902
4958
  return;
4903
- searchParams.set('v', "2");
4959
+ searchParams.set('v', '2');
4904
4960
  searchParams.set('rev', this.rev);
4905
4961
  searchParams.set('realmsHash', this.realmSetHash);
4906
4962
  searchParams.set('clientId', this.clientIdentity);
@@ -4939,23 +4995,30 @@
4939
4995
  }
4940
4996
  };
4941
4997
  try {
4998
+ let everConnected = false;
4942
4999
  await new Promise((resolve, reject) => {
4943
5000
  ws.onopen = (event) => {
4944
5001
  console.debug('dexie-cloud WebSocket onopen');
5002
+ everConnected = true;
4945
5003
  resolve(null);
4946
5004
  };
4947
5005
  ws.onerror = (event) => {
4948
- const error = event.error || new Error('WebSocket Error');
4949
- this.disconnect();
4950
- this.subscriber.error(error);
4951
- this.webSocketStatus.next("error");
4952
- reject(error);
5006
+ if (!everConnected) {
5007
+ const error = event.error || new Error('WebSocket Error');
5008
+ this.subscriber.error(error);
5009
+ this.webSocketStatus.next('error');
5010
+ reject(error);
5011
+ }
5012
+ else {
5013
+ this.reconnect();
5014
+ }
4953
5015
  };
4954
5016
  });
4955
- this.messageProducerSubscription = this.messageProducer.subscribe(msg => {
5017
+ this.messageProducerSubscription = this.messageProducer.subscribe((msg) => {
4956
5018
  if (!this.closed) {
4957
- if (msg.type === 'ready' && this.webSocketStatus.value !== 'connected') {
4958
- this.webSocketStatus.next("connected");
5019
+ if (msg.type === 'ready' &&
5020
+ this.webSocketStatus.value !== 'connected') {
5021
+ this.webSocketStatus.next('connected');
4959
5022
  }
4960
5023
  this.ws?.send(TSON.stringify(msg));
4961
5024
  }
@@ -4992,9 +5055,9 @@
4992
5055
  rev: syncState.serverRevision,
4993
5056
  })));
4994
5057
  function createObservable() {
4995
- return db.cloud.persistedSyncState.pipe(filter(syncState => syncState?.serverRevision), // Don't connect before there's no initial sync performed.
5058
+ return db.cloud.persistedSyncState.pipe(filter((syncState) => syncState?.serverRevision), // Don't connect before there's no initial sync performed.
4996
5059
  take(1), // Don't continue waking up whenever syncState change
4997
- 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]) =>
5060
+ 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]) =>
4998
5061
  // Let server end query changes from last entry of same client-ID and forward.
4999
5062
  // If no new entries, server won't bother the client. If new entries, server sends only those
5000
5063
  // and the baseRev of the last from same client-ID.
@@ -5017,7 +5080,10 @@
5017
5080
  else {
5018
5081
  return rxjs.throwError(error);
5019
5082
  }
5020
- }), catchError((error) => rxjs.from(waitAndReconnectWhenUserDoesSomething(error)).pipe(switchMap(() => createObservable()))));
5083
+ }), catchError((error) => {
5084
+ db.cloud.webSocketStatus.next("error");
5085
+ return rxjs.from(waitAndReconnectWhenUserDoesSomething(error)).pipe(switchMap(() => createObservable()));
5086
+ }));
5021
5087
  }
5022
5088
  return createObservable().subscribe((msg) => {
5023
5089
  if (msg) {
@@ -5181,18 +5247,18 @@
5181
5247
  for (const table of db.tables) {
5182
5248
  if (db.cloud.schema?.[table.name]?.markedForSync) {
5183
5249
  if (table.schema.primKey.auto) {
5184
- throw new Dexie__default['default'].SchemaError(`Table ${table.name} is both autoIncremented and synced. ` +
5250
+ throw new Dexie__default["default"].SchemaError(`Table ${table.name} is both autoIncremented and synced. ` +
5185
5251
  `Use db.cloud.configure({unsyncedTables: [${JSON.stringify(table.name)}]}) to blacklist it from sync`);
5186
5252
  }
5187
5253
  if (!table.schema.primKey.keyPath) {
5188
- throw new Dexie__default['default'].SchemaError(`Table ${table.name} cannot be both synced and outbound. ` +
5254
+ throw new Dexie__default["default"].SchemaError(`Table ${table.name} cannot be both synced and outbound. ` +
5189
5255
  `Use db.cloud.configure({unsyncedTables: [${JSON.stringify(table.name)}]}) to blacklist it from sync`);
5190
5256
  }
5191
5257
  }
5192
5258
  }
5193
5259
  }
5194
5260
 
5195
- 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;
5261
+ 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;
5196
5262
 
5197
5263
  const Styles = {
5198
5264
  Error: {
@@ -5441,6 +5507,21 @@
5441
5507
  return rv;
5442
5508
  }
5443
5509
 
5510
+ const getGlobalRolesObservable = associate((db) => {
5511
+ return createSharedValueObservable(Dexie.liveQuery(() => db.roles
5512
+ .where({ realmId: 'rlm-public' })
5513
+ .toArray()
5514
+ .then((roles) => {
5515
+ const rv = {};
5516
+ for (const role of roles
5517
+ .slice()
5518
+ .sort((a, b) => (a.sortOrder || 0) - (b.sortOrder || 0))) {
5519
+ rv[role.name] = role;
5520
+ }
5521
+ return rv;
5522
+ })), {});
5523
+ });
5524
+
5444
5525
  const getCurrentUserEmitter = associate((db) => new rxjs.BehaviorSubject(UNAUTHORIZED_USER));
5445
5526
 
5446
5527
  const getInternalAccessControlObservable = associate((db) => {
@@ -5542,18 +5623,38 @@
5542
5623
  }
5543
5624
 
5544
5625
  const getPermissionsLookupObservable = associate((db) => {
5545
- const o = getInternalAccessControlObservable(db._novip);
5546
- return mapValueObservable(o, ({ selfMembers, realms, userId }) => {
5626
+ const o = createSharedValueObservable(rxjs.combineLatest([
5627
+ getInternalAccessControlObservable(db._novip),
5628
+ getGlobalRolesObservable(db._novip),
5629
+ ]).pipe(map(([{ selfMembers, realms, userId }, globalRoles]) => ({
5630
+ selfMembers,
5631
+ realms,
5632
+ userId,
5633
+ globalRoles,
5634
+ }))), {
5635
+ selfMembers: [],
5636
+ realms: [],
5637
+ userId: UNAUTHORIZED_USER.userId,
5638
+ globalRoles: {},
5639
+ });
5640
+ return mapValueObservable(o, ({ selfMembers, realms, userId, globalRoles }) => {
5547
5641
  const rv = realms
5548
- .map((realm) => ({
5549
- ...realm,
5550
- permissions: realm.owner === userId
5551
- ? { manage: '*' }
5552
- : mergePermissions(...selfMembers
5553
- .filter((m) => m.realmId === realm.realmId)
5554
- .map((m) => m.permissions)
5555
- .filter((p) => p)),
5556
- }))
5642
+ .map((realm) => {
5643
+ const selfRealmMembers = selfMembers.filter((m) => m.realmId === realm.realmId);
5644
+ const directPermissionSets = selfRealmMembers
5645
+ .map((m) => m.permissions)
5646
+ .filter((p) => p);
5647
+ const rolePermissionSets = flatten(selfRealmMembers.map((m) => m.roles).filter((roleName) => roleName))
5648
+ .map((role) => globalRoles[role])
5649
+ .filter((role) => role)
5650
+ .map((role) => role.permissions);
5651
+ return {
5652
+ ...realm,
5653
+ permissions: realm.owner === userId
5654
+ ? { manage: '*' }
5655
+ : mergePermissions(...directPermissionSets, ...rolePermissionSets),
5656
+ };
5657
+ })
5557
5658
  .reduce((p, c) => ({ ...p, [c.realmId]: c }), {
5558
5659
  [userId]: {
5559
5660
  realmId: userId,
@@ -5637,7 +5738,7 @@
5637
5738
  const realm = permissionsLookup[realmId || dexie.cloud.currentUserId];
5638
5739
  if (!realm)
5639
5740
  return new PermissionChecker({}, tableName, !owner || owner === dexie.cloud.currentUserId);
5640
- return new PermissionChecker(realm.permissions, tableName, !owner || owner === dexie.cloud.currentUserId);
5741
+ return new PermissionChecker(realm.permissions, tableName, realmId === dexie.cloud.currentUserId || owner === dexie.cloud.currentUserId);
5641
5742
  };
5642
5743
  const o = source.pipe(map(mapper));
5643
5744
  o.getValue = () => mapper(source.getValue());
@@ -5666,6 +5767,7 @@
5666
5767
  //
5667
5768
  const currentUserEmitter = getCurrentUserEmitter(dexie);
5668
5769
  const subscriptions = [];
5770
+ let configuredProgramatically = false;
5669
5771
  // local sync worker - used when there's no service worker.
5670
5772
  let localSyncWorker = null;
5671
5773
  dexie.on('ready', async (dexie) => {
@@ -5682,7 +5784,7 @@
5682
5784
  let closed = false;
5683
5785
  function throwIfClosed() {
5684
5786
  if (closed)
5685
- throw new Dexie__default['default'].DatabaseClosedError();
5787
+ throw new Dexie__default["default"].DatabaseClosedError();
5686
5788
  }
5687
5789
  dbOnClosed(dexie, () => {
5688
5790
  subscriptions.forEach((subscription) => subscription.unsubscribe());
@@ -5692,7 +5794,7 @@
5692
5794
  currentUserEmitter.next(UNAUTHORIZED_USER);
5693
5795
  });
5694
5796
  dexie.cloud = {
5695
- version: '4.0.0-beta.13',
5797
+ version: '4.0.0-beta.16',
5696
5798
  options: { ...DEFAULT_OPTIONS },
5697
5799
  schema: null,
5698
5800
  serverState: null,
@@ -5713,8 +5815,10 @@
5713
5815
  await login(db, hint);
5714
5816
  },
5715
5817
  invites: getInvitesObservable(dexie),
5818
+ roles: getGlobalRolesObservable(dexie),
5716
5819
  configure(options) {
5717
5820
  options = dexie.cloud.options = { ...dexie.cloud.options, ...options };
5821
+ configuredProgramatically = true;
5718
5822
  if (options.databaseUrl && options.nameSuffix) {
5719
5823
  // @ts-ignore
5720
5824
  dexie.name = `${origIdbName}-${getDbNameFromDbUrl(options.databaseUrl)}`;
@@ -5762,7 +5866,7 @@
5762
5866
  return permissions(dexie._novip, obj, tableName);
5763
5867
  },
5764
5868
  };
5765
- dexie.Version.prototype['_parseStoresSpec'] = Dexie__default['default'].override(dexie.Version.prototype['_parseStoresSpec'], (origFunc) => overrideParseStoresSpec(origFunc, dexie));
5869
+ dexie.Version.prototype['_parseStoresSpec'] = Dexie__default["default"].override(dexie.Version.prototype['_parseStoresSpec'], (origFunc) => overrideParseStoresSpec(origFunc, dexie));
5766
5870
  dexie.Table.prototype.newId = function ({ colocateWith } = {}) {
5767
5871
  const shardKey = colocateWith && colocateWith.substr(colocateWith.length - 3);
5768
5872
  return generateKey(dexie.cloud.schema[this.name].idPrefix || '', shardKey);
@@ -5801,7 +5905,7 @@
5801
5905
  db.getSchema(),
5802
5906
  db.getPersistedSyncState(),
5803
5907
  ]);
5804
- if (!options) {
5908
+ if (!configuredProgramatically) {
5805
5909
  // Options not specified programatically (use case for SW!)
5806
5910
  // Take persisted options:
5807
5911
  db.cloud.options = persistedOptions || null;
@@ -5809,6 +5913,8 @@
5809
5913
  else if (!persistedOptions ||
5810
5914
  JSON.stringify(persistedOptions) !== JSON.stringify(options)) {
5811
5915
  // Update persisted options:
5916
+ if (!options)
5917
+ throw new Error(`Internal error`); // options cannot be null if configuredProgramatically is set.
5812
5918
  await db.$syncState.put(options, 'options');
5813
5919
  }
5814
5920
  if (db.cloud.options?.tryUseServiceWorker &&
@@ -5930,8 +6036,8 @@
5930
6036
  }
5931
6037
  }
5932
6038
  }
5933
- dexieCloud.version = '4.0.0-beta.13';
5934
- Dexie__default['default'].Cloud = dexieCloud;
6039
+ dexieCloud.version = '4.0.0-beta.16';
6040
+ Dexie__default["default"].Cloud = dexieCloud;
5935
6041
 
5936
6042
  // In case the SW lives for a while, let it reuse already opened connections:
5937
6043
  const managedDBs = new Map();
@@ -5963,7 +6069,7 @@
5963
6069
  let db = managedDBs.get(dbName);
5964
6070
  if (!db) {
5965
6071
  console.debug('Dexie Cloud SW: Creating new Dexie instance for', dbName);
5966
- const dexie = new Dexie__default['default'](dbName, { addons: [dexieCloud] });
6072
+ const dexie = new Dexie__default["default"](dbName, { addons: [dexieCloud] });
5967
6073
  db = DexieCloudDB(dexie);
5968
6074
  dexie.on('versionchange', stopManagingDB);
5969
6075
  await db.dx.open(); // Makes sure db.cloud.options and db.cloud.schema are read from db,
@@ -6003,7 +6109,7 @@
6003
6109
  // Error occured. Stop managing this DB until we wake up again by a sync event,
6004
6110
  // which will open a new Dexie and start trying to sync it.
6005
6111
  stopManagingDB();
6006
- if (e.name !== Dexie__default['default'].errnames.NoSuchDatabase) {
6112
+ if (e.name !== Dexie__default["default"].errnames.NoSuchDatabase) {
6007
6113
  // Unless the error was that DB doesn't exist, rethrow to trigger sync retry.
6008
6114
  throw e; // Throw e to make syncEvent.waitUntil() receive a rejected promis, so it will retry.
6009
6115
  }
@@ -6053,5 +6159,5 @@
6053
6159
  return new Promise((resolve) => setTimeout(resolve, ms));
6054
6160
  }
6055
6161
 
6056
- })));
6162
+ }));
6057
6163
  //# sourceMappingURL=service-worker.js.map