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
@@ -8,7 +8,7 @@
8
8
  *
9
9
  * ==========================================================================
10
10
  *
11
- * Version 4.0.0-beta.13, Sun Dec 19 2021
11
+ * Version 4.0.0-beta.16, Fri Apr 01 2022
12
12
  *
13
13
  * https://dexie.org
14
14
  *
@@ -653,10 +653,12 @@ var timeoutProvider = {
653
653
  for (var _i = 0; _i < arguments.length; _i++) {
654
654
  args[_i] = arguments[_i];
655
655
  }
656
- return (setTimeout).apply(void 0, __spreadArray([], __read(args)));
656
+ var delegate = timeoutProvider.delegate;
657
+ return ((delegate === null || delegate === void 0 ? void 0 : delegate.setTimeout) || setTimeout).apply(void 0, __spreadArray([], __read(args)));
657
658
  },
658
659
  clearTimeout: function (handle) {
659
- return (clearTimeout)(handle);
660
+ var delegate = timeoutProvider.delegate;
661
+ return ((delegate === null || delegate === void 0 ? void 0 : delegate.clearTimeout) || clearTimeout)(handle);
660
662
  },
661
663
  delegate: undefined,
662
664
  };
@@ -671,11 +673,33 @@ function reportUnhandledError(err) {
671
673
 
672
674
  function noop() { }
673
675
 
676
+ var COMPLETE_NOTIFICATION = (function () { return createNotification('C', undefined, undefined); })();
677
+ function errorNotification(error) {
678
+ return createNotification('E', undefined, error);
679
+ }
680
+ function nextNotification(value) {
681
+ return createNotification('N', value, undefined);
682
+ }
683
+ function createNotification(kind, value, error) {
684
+ return {
685
+ kind: kind,
686
+ value: value,
687
+ error: error,
688
+ };
689
+ }
690
+
691
+ var context = null;
674
692
  function errorContext(cb) {
675
693
  {
676
694
  cb();
677
695
  }
678
696
  }
697
+ function captureError(err) {
698
+ if (config.useDeprecatedSynchronousErrorHandling && context) {
699
+ context.errorThrown = true;
700
+ context.error = err;
701
+ }
702
+ }
679
703
 
680
704
  var Subscriber = (function (_super) {
681
705
  __extends(Subscriber, _super);
@@ -697,20 +721,26 @@ var Subscriber = (function (_super) {
697
721
  return new SafeSubscriber(next, error, complete);
698
722
  };
699
723
  Subscriber.prototype.next = function (value) {
700
- if (this.isStopped) ;
724
+ if (this.isStopped) {
725
+ handleStoppedNotification(nextNotification(value), this);
726
+ }
701
727
  else {
702
728
  this._next(value);
703
729
  }
704
730
  };
705
731
  Subscriber.prototype.error = function (err) {
706
- if (this.isStopped) ;
732
+ if (this.isStopped) {
733
+ handleStoppedNotification(errorNotification(err), this);
734
+ }
707
735
  else {
708
736
  this.isStopped = true;
709
737
  this._error(err);
710
738
  }
711
739
  };
712
740
  Subscriber.prototype.complete = function () {
713
- if (this.isStopped) ;
741
+ if (this.isStopped) {
742
+ handleStoppedNotification(COMPLETE_NOTIFICATION, this);
743
+ }
714
744
  else {
715
745
  this.isStopped = true;
716
746
  this._complete();
@@ -785,7 +815,10 @@ function wrapForErrorHandling(handler, instance) {
785
815
  handler.apply(void 0, __spreadArray([], __read(args)));
786
816
  }
787
817
  catch (err) {
788
- {
818
+ if (config.useDeprecatedSynchronousErrorHandling) {
819
+ captureError(err);
820
+ }
821
+ else {
789
822
  reportUnhandledError(err);
790
823
  }
791
824
  }
@@ -794,6 +827,10 @@ function wrapForErrorHandling(handler, instance) {
794
827
  function defaultErrorHandler(err) {
795
828
  throw err;
796
829
  }
830
+ function handleStoppedNotification(notification, subscriber) {
831
+ var onStoppedNotification = config.onStoppedNotification;
832
+ onStoppedNotification && timeoutProvider.setTimeout(function () { return onStoppedNotification(notification, subscriber); });
833
+ }
797
834
  var EMPTY_OBSERVER = {
798
835
  closed: true,
799
836
  next: noop,
@@ -1169,10 +1206,12 @@ var intervalProvider = {
1169
1206
  for (var _i = 0; _i < arguments.length; _i++) {
1170
1207
  args[_i] = arguments[_i];
1171
1208
  }
1172
- return (setInterval).apply(void 0, __spreadArray([], __read(args)));
1209
+ var delegate = intervalProvider.delegate;
1210
+ return ((delegate === null || delegate === void 0 ? void 0 : delegate.setInterval) || setInterval).apply(void 0, __spreadArray([], __read(args)));
1173
1211
  },
1174
1212
  clearInterval: function (handle) {
1175
- return (clearInterval)(handle);
1213
+ var delegate = intervalProvider.delegate;
1214
+ return ((delegate === null || delegate === void 0 ? void 0 : delegate.clearInterval) || clearInterval)(handle);
1176
1215
  },
1177
1216
  delegate: undefined,
1178
1217
  };
@@ -1261,7 +1300,7 @@ var AsyncAction = (function (_super) {
1261
1300
 
1262
1301
  var dateTimestampProvider = {
1263
1302
  now: function () {
1264
- return (Date).now();
1303
+ return (dateTimestampProvider.delegate || Date).now();
1265
1304
  },
1266
1305
  delegate: undefined,
1267
1306
  };
@@ -1941,15 +1980,18 @@ const b64encode = typeof Buffer !== "undefined"
1941
1980
  : (b) => btoa(String.fromCharCode.apply(null, b));
1942
1981
 
1943
1982
  function interactWithUser(userInteraction, req) {
1983
+ let done = false;
1944
1984
  return new Promise((resolve, reject) => {
1945
1985
  const interactionProps = {
1946
1986
  ...req,
1947
1987
  onSubmit: (res) => {
1948
1988
  userInteraction.next(undefined);
1989
+ done = true;
1949
1990
  resolve(res);
1950
1991
  },
1951
1992
  onCancel: () => {
1952
1993
  userInteraction.next(undefined);
1994
+ done = true;
1953
1995
  reject(new Dexie.AbortError("User cancelled"));
1954
1996
  },
1955
1997
  };
@@ -4721,7 +4763,7 @@ async function performInitialSync(db, cloudOptions, cloudSchema) {
4721
4763
  console.debug("Done initial sync");
4722
4764
  }
4723
4765
 
4724
- const USER_INACTIVITY_TIMEOUT = 300000; // 300_000;
4766
+ const USER_INACTIVITY_TIMEOUT = 180000; // 3 minutes
4725
4767
  const INACTIVE_WAIT_TIME = 20000;
4726
4768
  // This observable will be emitted to later down....
4727
4769
  const userIsActive = new BehaviorSubject(true);
@@ -4735,9 +4777,13 @@ const userIsActive = new BehaviorSubject(true);
4735
4777
  // for just a short time.
4736
4778
  const userIsReallyActive = new BehaviorSubject(true);
4737
4779
  userIsActive
4738
- .pipe(switchMap((isActive) => isActive
4739
- ? of(true)
4740
- : of(false).pipe(delay(INACTIVE_WAIT_TIME))), distinctUntilChanged())
4780
+ .pipe(switchMap((isActive) => {
4781
+ //console.debug('SyncStatus: DUBB: isActive changed to', isActive);
4782
+ return isActive
4783
+ ? of(true)
4784
+ : of(false).pipe(delay(INACTIVE_WAIT_TIME))
4785
+ ;
4786
+ }), distinctUntilChanged())
4741
4787
  .subscribe(userIsReallyActive);
4742
4788
  //
4743
4789
  // First create some corner-stone observables to build the flow on
@@ -4752,7 +4798,7 @@ const documentBecomesHidden = visibilityStateIsChanged.pipe(filter(() => documen
4752
4798
  const documentBecomesVisible = visibilityStateIsChanged.pipe(filter(() => document.visibilityState === 'visible'));
4753
4799
  // Any of various user-activity-related events happen:
4754
4800
  const userDoesSomething = typeof window !== 'undefined'
4755
- ? merge(documentBecomesVisible, fromEvent(window, 'mousemove'), fromEvent(window, 'keydown'), fromEvent(window, 'wheel'), fromEvent(window, 'touchmove'))
4801
+ ? merge(documentBecomesVisible, fromEvent(window, 'mousedown'), fromEvent(window, 'mousemove'), fromEvent(window, 'keydown'), fromEvent(window, 'wheel'), fromEvent(window, 'touchmove'))
4756
4802
  : of({});
4757
4803
  if (typeof document !== 'undefined') {
4758
4804
  //
@@ -4803,6 +4849,7 @@ class WSConnection extends Subscription$1 {
4803
4849
  constructor(databaseUrl, rev, realmSetHash, clientIdentity, token, tokenExpiration, subscriber, messageProducer, webSocketStatus) {
4804
4850
  super(() => this.teardown());
4805
4851
  this.id = ++counter;
4852
+ this.reconnecting = false;
4806
4853
  console.debug('New WebSocket Connection', this.id, token ? 'authorized' : 'unauthorized');
4807
4854
  this.databaseUrl = databaseUrl;
4808
4855
  this.rev = rev;
@@ -4822,7 +4869,7 @@ class WSConnection extends Subscription$1 {
4822
4869
  this.disconnect();
4823
4870
  }
4824
4871
  disconnect() {
4825
- this.webSocketStatus.next("disconnected");
4872
+ this.webSocketStatus.next('disconnected');
4826
4873
  if (this.pinger) {
4827
4874
  clearInterval(this.pinger);
4828
4875
  this.pinger = null;
@@ -4840,11 +4887,18 @@ class WSConnection extends Subscription$1 {
4840
4887
  }
4841
4888
  }
4842
4889
  reconnect() {
4843
- this.disconnect();
4844
- this.connect();
4890
+ if (this.reconnecting)
4891
+ return;
4892
+ this.reconnecting = true;
4893
+ try {
4894
+ this.disconnect();
4895
+ }
4896
+ catch { }
4897
+ this.connect()
4898
+ .catch(() => { })
4899
+ .then(() => (this.reconnecting = false)); // finally()
4845
4900
  }
4846
4901
  async connect() {
4847
- this.webSocketStatus.next("connecting");
4848
4902
  this.lastServerActivity = new Date();
4849
4903
  if (this.pauseUntil && this.pauseUntil > new Date()) {
4850
4904
  console.debug('WS not reconnecting just yet', {
@@ -4859,12 +4913,14 @@ class WSConnection extends Subscription$1 {
4859
4913
  if (!this.databaseUrl)
4860
4914
  throw new Error(`Cannot connect without a database URL`);
4861
4915
  if (this.closed) {
4916
+ //console.debug('SyncStatus: DUBB: Ooops it was closed!');
4862
4917
  return;
4863
4918
  }
4864
4919
  if (this.tokenExpiration && this.tokenExpiration < new Date()) {
4865
4920
  this.subscriber.error(new TokenExpiredError()); // Will be handled in connectWebSocket.ts.
4866
4921
  return;
4867
4922
  }
4923
+ this.webSocketStatus.next('connecting');
4868
4924
  this.pinger = setInterval(async () => {
4869
4925
  if (this.closed) {
4870
4926
  console.debug('pinger check', this.id, 'CLOSED.');
@@ -4911,7 +4967,7 @@ class WSConnection extends Subscription$1 {
4911
4967
  const searchParams = new URLSearchParams();
4912
4968
  if (this.subscriber.closed)
4913
4969
  return;
4914
- searchParams.set('v', "2");
4970
+ searchParams.set('v', '2');
4915
4971
  searchParams.set('rev', this.rev);
4916
4972
  searchParams.set('realmsHash', this.realmSetHash);
4917
4973
  searchParams.set('clientId', this.clientIdentity);
@@ -4950,23 +5006,30 @@ class WSConnection extends Subscription$1 {
4950
5006
  }
4951
5007
  };
4952
5008
  try {
5009
+ let everConnected = false;
4953
5010
  await new Promise((resolve, reject) => {
4954
5011
  ws.onopen = (event) => {
4955
5012
  console.debug('dexie-cloud WebSocket onopen');
5013
+ everConnected = true;
4956
5014
  resolve(null);
4957
5015
  };
4958
5016
  ws.onerror = (event) => {
4959
- const error = event.error || new Error('WebSocket Error');
4960
- this.disconnect();
4961
- this.subscriber.error(error);
4962
- this.webSocketStatus.next("error");
4963
- reject(error);
5017
+ if (!everConnected) {
5018
+ const error = event.error || new Error('WebSocket Error');
5019
+ this.subscriber.error(error);
5020
+ this.webSocketStatus.next('error');
5021
+ reject(error);
5022
+ }
5023
+ else {
5024
+ this.reconnect();
5025
+ }
4964
5026
  };
4965
5027
  });
4966
- this.messageProducerSubscription = this.messageProducer.subscribe(msg => {
5028
+ this.messageProducerSubscription = this.messageProducer.subscribe((msg) => {
4967
5029
  if (!this.closed) {
4968
- if (msg.type === 'ready' && this.webSocketStatus.value !== 'connected') {
4969
- this.webSocketStatus.next("connected");
5030
+ if (msg.type === 'ready' &&
5031
+ this.webSocketStatus.value !== 'connected') {
5032
+ this.webSocketStatus.next('connected');
4970
5033
  }
4971
5034
  this.ws?.send(TSON.stringify(msg));
4972
5035
  }
@@ -5003,9 +5066,9 @@ function connectWebSocket(db) {
5003
5066
  rev: syncState.serverRevision,
5004
5067
  })));
5005
5068
  function createObservable() {
5006
- return db.cloud.persistedSyncState.pipe(filter(syncState => syncState?.serverRevision), // Don't connect before there's no initial sync performed.
5069
+ return db.cloud.persistedSyncState.pipe(filter((syncState) => syncState?.serverRevision), // Don't connect before there's no initial sync performed.
5007
5070
  take(1), // Don't continue waking up whenever syncState change
5008
- 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]) =>
5071
+ 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]) =>
5009
5072
  // Let server end query changes from last entry of same client-ID and forward.
5010
5073
  // If no new entries, server won't bother the client. If new entries, server sends only those
5011
5074
  // and the baseRev of the last from same client-ID.
@@ -5028,7 +5091,10 @@ function connectWebSocket(db) {
5028
5091
  else {
5029
5092
  return throwError(error);
5030
5093
  }
5031
- }), catchError((error) => from$1(waitAndReconnectWhenUserDoesSomething(error)).pipe(switchMap(() => createObservable()))));
5094
+ }), catchError((error) => {
5095
+ db.cloud.webSocketStatus.next("error");
5096
+ return from$1(waitAndReconnectWhenUserDoesSomething(error)).pipe(switchMap(() => createObservable()));
5097
+ }));
5032
5098
  }
5033
5099
  return createObservable().subscribe((msg) => {
5034
5100
  if (msg) {
@@ -5203,7 +5269,7 @@ function verifySchema(db) {
5203
5269
  }
5204
5270
  }
5205
5271
 
5206
- 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;
5272
+ 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;
5207
5273
 
5208
5274
  const Styles = {
5209
5275
  Error: {
@@ -5452,6 +5518,21 @@ function createSharedValueObservable(o, defaultValue) {
5452
5518
  return rv;
5453
5519
  }
5454
5520
 
5521
+ const getGlobalRolesObservable = associate((db) => {
5522
+ return createSharedValueObservable(liveQuery(() => db.roles
5523
+ .where({ realmId: 'rlm-public' })
5524
+ .toArray()
5525
+ .then((roles) => {
5526
+ const rv = {};
5527
+ for (const role of roles
5528
+ .slice()
5529
+ .sort((a, b) => (a.sortOrder || 0) - (b.sortOrder || 0))) {
5530
+ rv[role.name] = role;
5531
+ }
5532
+ return rv;
5533
+ })), {});
5534
+ });
5535
+
5455
5536
  const getCurrentUserEmitter = associate((db) => new BehaviorSubject(UNAUTHORIZED_USER));
5456
5537
 
5457
5538
  const getInternalAccessControlObservable = associate((db) => {
@@ -5553,18 +5634,38 @@ function mergePermissions(...permissions) {
5553
5634
  }
5554
5635
 
5555
5636
  const getPermissionsLookupObservable = associate((db) => {
5556
- const o = getInternalAccessControlObservable(db._novip);
5557
- return mapValueObservable(o, ({ selfMembers, realms, userId }) => {
5637
+ const o = createSharedValueObservable(combineLatest([
5638
+ getInternalAccessControlObservable(db._novip),
5639
+ getGlobalRolesObservable(db._novip),
5640
+ ]).pipe(map(([{ selfMembers, realms, userId }, globalRoles]) => ({
5641
+ selfMembers,
5642
+ realms,
5643
+ userId,
5644
+ globalRoles,
5645
+ }))), {
5646
+ selfMembers: [],
5647
+ realms: [],
5648
+ userId: UNAUTHORIZED_USER.userId,
5649
+ globalRoles: {},
5650
+ });
5651
+ return mapValueObservable(o, ({ selfMembers, realms, userId, globalRoles }) => {
5558
5652
  const rv = realms
5559
- .map((realm) => ({
5560
- ...realm,
5561
- permissions: realm.owner === userId
5562
- ? { manage: '*' }
5563
- : mergePermissions(...selfMembers
5564
- .filter((m) => m.realmId === realm.realmId)
5565
- .map((m) => m.permissions)
5566
- .filter((p) => p)),
5567
- }))
5653
+ .map((realm) => {
5654
+ const selfRealmMembers = selfMembers.filter((m) => m.realmId === realm.realmId);
5655
+ const directPermissionSets = selfRealmMembers
5656
+ .map((m) => m.permissions)
5657
+ .filter((p) => p);
5658
+ const rolePermissionSets = flatten(selfRealmMembers.map((m) => m.roles).filter((roleName) => roleName))
5659
+ .map((role) => globalRoles[role])
5660
+ .filter((role) => role)
5661
+ .map((role) => role.permissions);
5662
+ return {
5663
+ ...realm,
5664
+ permissions: realm.owner === userId
5665
+ ? { manage: '*' }
5666
+ : mergePermissions(...directPermissionSets, ...rolePermissionSets),
5667
+ };
5668
+ })
5568
5669
  .reduce((p, c) => ({ ...p, [c.realmId]: c }), {
5569
5670
  [userId]: {
5570
5671
  realmId: userId,
@@ -5648,7 +5749,7 @@ function permissions(dexie, obj, tableName) {
5648
5749
  const realm = permissionsLookup[realmId || dexie.cloud.currentUserId];
5649
5750
  if (!realm)
5650
5751
  return new PermissionChecker({}, tableName, !owner || owner === dexie.cloud.currentUserId);
5651
- return new PermissionChecker(realm.permissions, tableName, !owner || owner === dexie.cloud.currentUserId);
5752
+ return new PermissionChecker(realm.permissions, tableName, realmId === dexie.cloud.currentUserId || owner === dexie.cloud.currentUserId);
5652
5753
  };
5653
5754
  const o = source.pipe(map(mapper));
5654
5755
  o.getValue = () => mapper(source.getValue());
@@ -5684,6 +5785,7 @@ function dexieCloud(dexie) {
5684
5785
  //
5685
5786
  const currentUserEmitter = getCurrentUserEmitter(dexie);
5686
5787
  const subscriptions = [];
5788
+ let configuredProgramatically = false;
5687
5789
  // local sync worker - used when there's no service worker.
5688
5790
  let localSyncWorker = null;
5689
5791
  dexie.on('ready', async (dexie) => {
@@ -5710,7 +5812,7 @@ function dexieCloud(dexie) {
5710
5812
  currentUserEmitter.next(UNAUTHORIZED_USER);
5711
5813
  });
5712
5814
  dexie.cloud = {
5713
- version: '4.0.0-beta.13',
5815
+ version: '4.0.0-beta.16',
5714
5816
  options: { ...DEFAULT_OPTIONS },
5715
5817
  schema: null,
5716
5818
  serverState: null,
@@ -5731,8 +5833,10 @@ function dexieCloud(dexie) {
5731
5833
  await login(db, hint);
5732
5834
  },
5733
5835
  invites: getInvitesObservable(dexie),
5836
+ roles: getGlobalRolesObservable(dexie),
5734
5837
  configure(options) {
5735
5838
  options = dexie.cloud.options = { ...dexie.cloud.options, ...options };
5839
+ configuredProgramatically = true;
5736
5840
  if (options.databaseUrl && options.nameSuffix) {
5737
5841
  // @ts-ignore
5738
5842
  dexie.name = `${origIdbName}-${getDbNameFromDbUrl(options.databaseUrl)}`;
@@ -5819,7 +5923,7 @@ function dexieCloud(dexie) {
5819
5923
  db.getSchema(),
5820
5924
  db.getPersistedSyncState(),
5821
5925
  ]);
5822
- if (!options) {
5926
+ if (!configuredProgramatically) {
5823
5927
  // Options not specified programatically (use case for SW!)
5824
5928
  // Take persisted options:
5825
5929
  db.cloud.options = persistedOptions || null;
@@ -5827,6 +5931,8 @@ function dexieCloud(dexie) {
5827
5931
  else if (!persistedOptions ||
5828
5932
  JSON.stringify(persistedOptions) !== JSON.stringify(options)) {
5829
5933
  // Update persisted options:
5934
+ if (!options)
5935
+ throw new Error(`Internal error`); // options cannot be null if configuredProgramatically is set.
5830
5936
  await db.$syncState.put(options, 'options');
5831
5937
  }
5832
5938
  if (db.cloud.options?.tryUseServiceWorker &&
@@ -5948,9 +6054,8 @@ function dexieCloud(dexie) {
5948
6054
  }
5949
6055
  }
5950
6056
  }
5951
- dexieCloud.version = '4.0.0-beta.13';
6057
+ dexieCloud.version = '4.0.0-beta.16';
5952
6058
  Dexie.Cloud = dexieCloud;
5953
6059
 
5954
- export default dexieCloud;
5955
- export { dexieCloud, getTiedObjectId, getTiedRealmId };
6060
+ export { dexieCloud as default, dexieCloud, getTiedObjectId, getTiedRealmId };
5956
6061
  //# sourceMappingURL=dexie-cloud-addon.js.map