@coolon/angular-ui-powerups 14.46.0 → 14.47.1

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.
@@ -60,7 +60,6 @@ import * as i1$6 from '@angular/material/dialog';
60
60
  import { MatDialogModule, MAT_DIALOG_DEFAULT_OPTIONS } from '@angular/material/dialog';
61
61
  import * as i1$4 from '@angular/router';
62
62
  import { ActivatedRouteSnapshot, UrlSegment, NavigationStart, NavigationEnd, NavigationError, NavigationCancel, RouterModule } from '@angular/router';
63
- import { ArrayMultimap } from '@teppeis/multimaps';
64
63
  import 'reflect-metadata';
65
64
  import { Memoize as Memoize$1 } from 'typescript-memoize';
66
65
  import * as i1$5 from '@angular/cdk/overlay';
@@ -6411,15 +6410,6 @@ class PlaceComponent extends DisposableComponent {
6411
6410
  const { chain, valueOf, before, when, after, observe, switchOn } = Dsl.disposeWith(this);
6412
6411
  when(this._active).becomesTruthy(() => this._notifyPlaceReady());
6413
6412
  this.childPlaces$ = ListModel.constant(this.placeDefinition.children.map(d => d.component));
6414
- this.authorisedChildPlaces$ = chain(this.childPlaces$)
6415
- .select(placeType => {
6416
- const definition = PlaceComponent.getDefinition(placeType);
6417
- const guard = this.placeRouter.authService.accessGuard$.value;
6418
- return guard.isAuthorised(definition) || this.placeRouter.activeVisit$.value?.isPlaceActive(definition);
6419
- }, {
6420
- postponeWhile: this.placeRouter.navigationInProgress$,
6421
- dependsOn: [this.placeRouter.authService.accessGuard$, this.placeRouter.activeVisit$]
6422
- });
6423
6413
  }
6424
6414
  initialiseVisit(visit, notifyVisitChanged) {
6425
6415
  assert.isNil(this.visitModel.value);
@@ -6443,11 +6433,8 @@ class PlaceComponent extends DisposableComponent {
6443
6433
  // notifyVisitChanged(this.visitModel.value, visit)
6444
6434
  // }
6445
6435
  }
6446
- /**
6447
- * @deprecated use authorisedChildPlaces$ instead
6448
- */
6449
6436
  get childPlaces() {
6450
- return this.authorisedChildPlaces$.value;
6437
+ return this.childPlaces$.value;
6451
6438
  }
6452
6439
  updateVisit(visit) {
6453
6440
  assert.isTruthy(this.isInitialised());
@@ -6763,76 +6750,114 @@ __decorate([
6763
6750
  // .withAncestorParameters(ParentB, {id: "c"}) // barf if not a ancestor or missing parameters are required or parameter isn't valid
6764
6751
  //
6765
6752
 
6766
- class PlaceAuthorisationChecker extends ReducingValueModel {
6753
+ function toPromise(disposedWith, condition$) {
6754
+ // TODO: move this functionality to pectin with a waitUnit(model$).isTruthy() DSL.
6755
+ const { when } = Dsl.disposeWith(disposedWith);
6756
+ return new Promise((resolve) => {
6757
+ when(condition$).becomesTruthy(() => resolve(), { once: true, initialValue: "evaluate" });
6758
+ });
6759
+ }
6760
+ function withPostponeUntil(disposable, options, callback) {
6761
+ // TODO: move this functionality to powerups
6762
+ const { chain } = Dsl.disposeWith(disposable);
6763
+ if (options.postponeUntil) {
6764
+ return callback(options.postponeUntil);
6765
+ }
6766
+ else if (options.postponeWhile) {
6767
+ return callback(chain(options.postponeWhile).isFalsey());
6768
+ }
6769
+ return undefined;
6770
+ }
6771
+ class PlaceAuthGuard extends GarbageCollector {
6772
+ constructor(placeDefinition, enabled$, options) {
6773
+ super();
6774
+ this.placeDefinition = placeDefinition;
6775
+ this.enabled$ = enabled$;
6776
+ const { chain } = Dsl.disposeWith(this);
6777
+ this.readyPromise = withPostponeUntil(this, options, condition$ => {
6778
+ return toPromise(this, condition$);
6779
+ }) ?? Promise.resolve();
6780
+ }
6781
+ async waitUntilReady() {
6782
+ await this.readyPromise;
6783
+ }
6784
+ }
6785
+ class EnabledPlaceChecker extends ReducingValueModel {
6767
6786
  constructor() {
6768
6787
  super([]);
6769
- this.predicatesByPlace = new ArrayMultimap;
6770
- this.defaultAuthCheck = () => true;
6771
- }
6772
- setDefaultAuthCheck(options) {
6773
- this.defaultAuthCheck = (placeDef) => {
6774
- return options.isAuthorised(placeDef);
6775
- };
6776
- if (options.dependsOn$) {
6777
- this.trackSource(options.dependsOn$);
6778
- }
6788
+ this.placeGuards$ = new MutableListModel();
6789
+ const { chain } = Dsl.disposeWith(this);
6790
+ this.placeGuardsByPlaceDef$ = chain(this.placeGuards$).indexManyBy("placeDefinition");
6779
6791
  }
6780
- authoriseWhen(placeDefinition, condition$) {
6792
+ enableWhen(placeDefinition, condition$, options) {
6781
6793
  const { chain } = Dsl.disposeWith(this);
6782
- this.predicatesByPlace.put(placeDefinition, condition$);
6794
+ this.placeGuards$.push(new PlaceAuthGuard(placeDefinition, condition$, options));
6783
6795
  this.trackSource(condition$);
6784
6796
  }
6785
6797
  isAuthorised(placeDef) {
6786
6798
  return this.value(placeDef);
6787
6799
  }
6788
6800
  compute(values) {
6789
- return (def) => {
6790
- return this.defaultAuthCheck(def) && this.checkPredicatesByPlace(def);
6791
- };
6801
+ return (def) => this.checkPredicatesByPlace(def);
6792
6802
  }
6793
6803
  checkPredicatesByPlace(def) {
6794
- const placePredicates = this.predicatesByPlace.get(def);
6804
+ const placePredicates = this.placeGuardsByPlaceDef$.get(def);
6795
6805
  if (!placePredicates || placePredicates.length < 1) {
6796
6806
  return true;
6797
6807
  }
6798
6808
  else {
6799
6809
  return placePredicates.reduce((sum, model) => {
6800
- return sum && model.value;
6810
+ return sum && model.enabled$.value;
6801
6811
  }, true);
6802
6812
  }
6803
6813
  }
6814
+ async waitUntilReady(placeDef) {
6815
+ const placeAuthGuards = this.placeGuardsByPlaceDef$.get(placeDef);
6816
+ if (placeAuthGuards?.length > 0) {
6817
+ await Promise.all(placeAuthGuards.map(it => it.waitUntilReady()));
6818
+ }
6819
+ }
6804
6820
  }
6805
6821
  class PlaceAuthService extends GarbageCollector {
6806
6822
  constructor() {
6807
6823
  super();
6808
- this.placeGuards$ = new MutableListModel();
6809
- this._ready$ = new AndValueModel().setDefault(true);
6824
+ this._authNReady$ = new AndValueModel().setDefault(true);
6825
+ this._authZReady$ = new AndValueModel().setDefault(true);
6810
6826
  this.authenticated$ = this.registerDisposable(new DelegatingValueModel).withDefault(true);
6811
- this.authorisationChecker$ = this.registerDisposable(new PlaceAuthorisationChecker());
6827
+ this.authChecker$ = this.registerDisposable(new DelegatingValueModel).withDefault(() => true);
6828
+ this.enabledPlaceChecker = this.registerDisposable(new EnabledPlaceChecker());
6812
6829
  const { chain } = Dsl.disposeWith(this);
6813
- this.accessGuard$ = chain.reduce(this.authenticated$, this.authorisationChecker$, (authenticated, authCheck) => {
6814
- return new PlaceAuthService.AccessGuard(authenticated, authCheck);
6830
+ this.accessGuard$ = chain.reduce(this.authenticated$, this.authChecker$, this.enabledPlaceChecker, (authenticated, authCheck, enabledPlaceCheck) => {
6831
+ return new PlaceAuthService.AccessGuard(authenticated, def => authCheck(def) && enabledPlaceCheck(def));
6815
6832
  });
6816
6833
  }
6817
6834
  configureAuthentication(options) {
6818
6835
  this.authNOptions = options;
6819
6836
  this.authenticated$.setDelegate(options.isAuthenticated$);
6820
- this.capturePostoneDependency(options);
6837
+ withPostponeUntil(this, options, condition$ => this._authNReady$.addSource(condition$));
6821
6838
  }
6822
6839
  configureAuthorisation(options) {
6823
6840
  const { chain } = Dsl.disposeWith(this);
6824
6841
  this.authZOptions = options;
6825
- this.authorisationChecker$.setDefaultAuthCheck(options);
6826
- this.capturePostoneDependency(options);
6842
+ let authChecker$ = ValueModel.constant(def => options.isAuthorised(def));
6843
+ if (options.dependsOn$) {
6844
+ // have to return a new funtion or the value model won't fire a change event
6845
+ authChecker$ = chain(authChecker$).map(it => def => it(def), { dependsOn: options.dependsOn$ });
6846
+ }
6847
+ this.authChecker$.setDelegate(authChecker$);
6848
+ withPostponeUntil(this, options, condition$ => this._authZReady$.addSource(condition$));
6827
6849
  }
6828
6850
  enablePlace(placeDefinition, options) {
6829
6851
  const { chain } = Dsl.disposeWith(this);
6830
6852
  const when$ = options.when$ ? options.when$ : chain(options.unless$).isFalsey();
6831
- this.authorisationChecker$.authoriseWhen(PlaceComponent.getDefinition(placeDefinition), when$);
6832
- this.capturePostoneDependency(options);
6853
+ this.enabledPlaceChecker.enableWhen(PlaceComponent.getDefinition(placeDefinition), when$, options);
6854
+ }
6855
+ async waitUntilAuthenticationReady() {
6856
+ await toPromise(this, this._authNReady$);
6833
6857
  }
6834
- waitUntilReady() {
6835
- return this.toPromise(this._ready$);
6858
+ async waitUntilAuthorisationReadyFor(placeDef) {
6859
+ await toPromise(this, this._authZReady$);
6860
+ await this.enabledPlaceChecker.waitUntilReady(placeDef);
6836
6861
  }
6837
6862
  getAuthenticationFailureRedirect(activatedRoute, state) {
6838
6863
  const redirect = this.authNOptions.redirectTo(activatedRoute, state);
@@ -6841,22 +6866,6 @@ class PlaceAuthService extends GarbageCollector {
6841
6866
  getAuthorisationFailureRedirectOptions(component) {
6842
6867
  return this.authZOptions.redirectTo(component).map(it => it instanceof Visit ? it : Visit.goto(it));
6843
6868
  }
6844
- toPromise(condition$) {
6845
- // TODO: move this functionality to pectin with a waitUnit(model$).isTruthy() DSL.
6846
- const { when } = Dsl.disposeWith(this);
6847
- return new Promise((resolve) => {
6848
- when(condition$).becomesTruthy(() => resolve(), { once: true, initialValue: "evaluate" });
6849
- });
6850
- }
6851
- capturePostoneDependency(options) {
6852
- const { chain } = Dsl.disposeWith(this);
6853
- if (options.postponeUntil) {
6854
- this._ready$.addSource(options.postponeUntil);
6855
- }
6856
- else if (options.postponeWhile) {
6857
- this._ready$.addSource(chain(options.postponeWhile).isFalsey());
6858
- }
6859
- }
6860
6869
  isAuthenticated() {
6861
6870
  return this.accessGuard$.value.isAuthenticated();
6862
6871
  }
@@ -6866,15 +6875,15 @@ class PlaceAuthService extends GarbageCollector {
6866
6875
  }
6867
6876
  (function (PlaceAuthService) {
6868
6877
  class AccessGuard {
6869
- constructor(authenticated, authCheck) {
6878
+ constructor(authenticated, checkAuth) {
6870
6879
  this.authenticated = authenticated;
6871
- this.authCheck = authCheck;
6880
+ this.checkAuth = checkAuth;
6872
6881
  }
6873
6882
  isAuthenticated() {
6874
6883
  return this.authenticated;
6875
6884
  }
6876
6885
  isAuthorised(placeDefinition) {
6877
- return this.authCheck(placeDefinition);
6886
+ return this.checkAuth(placeDefinition);
6878
6887
  }
6879
6888
  }
6880
6889
  PlaceAuthService.AccessGuard = AccessGuard;
@@ -10290,7 +10299,16 @@ class AbstractPlaceNavigationComponent extends DisposableComponent {
10290
10299
  this.placeFaces = new Map();
10291
10300
  this.trackByPlaceDef = (index, data) => data.place;
10292
10301
  const { chain, valueOf, before, when, after, observe, switchOn } = Dsl.disposeWith(this);
10293
- this.placeDefinitions = chain(this.places$).map(c => PlaceComponent.getDefinition(c));
10302
+ this.authorisedPlaces$ = chain(this.places$)
10303
+ .select(placeType => {
10304
+ const definition = PlaceComponent.getDefinition(placeType);
10305
+ const guard = this.placeRouter.authService.accessGuard$.value;
10306
+ return guard.isAuthorised(definition) || this.placeRouter.activeVisit$.value?.isPlaceActive(definition);
10307
+ }, {
10308
+ postponeWhile: this.placeRouter.navigationInProgress$,
10309
+ dependsOn: [this.placeRouter.authService.accessGuard$, this.placeRouter.activeVisit$]
10310
+ });
10311
+ this.placeDefinitions = chain(this.authorisedPlaces$).map(c => PlaceComponent.getDefinition(c));
10294
10312
  this.commandFactory = Command.createFactory((placeDefinition) => {
10295
10313
  this.placeRouter.navigate(placeDefinition.component);
10296
10314
  });
@@ -10870,7 +10888,7 @@ class PlaceGuard {
10870
10888
  if (PlaceComponent.isPlaceComponentConstructor(activatedRoute.component)) {
10871
10889
  const placeDefinition = PlaceComponent.getDefinition(activatedRoute.component);
10872
10890
  if (placeDefinition.authenticate) {
10873
- await this.placeRouter.authService.waitUntilReady();
10891
+ await this.placeRouter.authService.waitUntilAuthenticationReady();
10874
10892
  const authenticated = this.authService.isAuthenticated();
10875
10893
  if (!authenticated) {
10876
10894
  const redirect = this.authService.getAuthenticationFailureRedirect(activatedRoute, state);
@@ -10880,6 +10898,7 @@ class PlaceGuard {
10880
10898
  }
10881
10899
  return this.createUrlTree(redirect);
10882
10900
  }
10901
+ await this.authService.waitUntilAuthorisationReadyFor(placeDefinition);
10883
10902
  if (!this.authService.isAuthorised(placeDefinition)) {
10884
10903
  const nextRedirect = this.findBestAuthenticatedAlternative(placeDefinition, activatedRoute);
10885
10904
  return this.createUrlTree(nextRedirect);