@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';
@@ -6600,16 +6599,6 @@ class PlaceComponent extends DisposableComponent {
6600
6599
  const { chain, valueOf, before, when, after, observe, switchOn } = Dsl.disposeWith(this);
6601
6600
  when(this._active).becomesTruthy(() => this._notifyPlaceReady());
6602
6601
  this.childPlaces$ = ListModel.constant(this.placeDefinition.children.map(d => d.component));
6603
- this.authorisedChildPlaces$ = chain(this.childPlaces$)
6604
- .select(placeType => {
6605
- var _a;
6606
- const definition = PlaceComponent.getDefinition(placeType);
6607
- const guard = this.placeRouter.authService.accessGuard$.value;
6608
- return guard.isAuthorised(definition) || ((_a = this.placeRouter.activeVisit$.value) === null || _a === void 0 ? void 0 : _a.isPlaceActive(definition));
6609
- }, {
6610
- postponeWhile: this.placeRouter.navigationInProgress$,
6611
- dependsOn: [this.placeRouter.authService.accessGuard$, this.placeRouter.activeVisit$]
6612
- });
6613
6602
  }
6614
6603
  initialiseVisit(visit, notifyVisitChanged) {
6615
6604
  assert.isNil(this.visitModel.value);
@@ -6633,11 +6622,8 @@ class PlaceComponent extends DisposableComponent {
6633
6622
  // notifyVisitChanged(this.visitModel.value, visit)
6634
6623
  // }
6635
6624
  }
6636
- /**
6637
- * @deprecated use authorisedChildPlaces$ instead
6638
- */
6639
6625
  get childPlaces() {
6640
- return this.authorisedChildPlaces$.value;
6626
+ return this.childPlaces$.value;
6641
6627
  }
6642
6628
  updateVisit(visit) {
6643
6629
  assert.isTruthy(this.isInitialised());
@@ -6957,76 +6943,123 @@ __decorate([
6957
6943
  // .withAncestorParameters(ParentB, {id: "c"}) // barf if not a ancestor or missing parameters are required or parameter isn't valid
6958
6944
  //
6959
6945
 
6960
- class PlaceAuthorisationChecker extends ReducingValueModel {
6946
+ function toPromise(disposedWith, condition$) {
6947
+ // TODO: move this functionality to pectin with a waitUnit(model$).isTruthy() DSL.
6948
+ const { when } = Dsl.disposeWith(disposedWith);
6949
+ return new Promise((resolve) => {
6950
+ when(condition$).becomesTruthy(() => resolve(), { once: true, initialValue: "evaluate" });
6951
+ });
6952
+ }
6953
+ function withPostponeUntil(disposable, options, callback) {
6954
+ // TODO: move this functionality to powerups
6955
+ const { chain } = Dsl.disposeWith(disposable);
6956
+ if (options.postponeUntil) {
6957
+ return callback(options.postponeUntil);
6958
+ }
6959
+ else if (options.postponeWhile) {
6960
+ return callback(chain(options.postponeWhile).isFalsey());
6961
+ }
6962
+ return undefined;
6963
+ }
6964
+ class PlaceAuthGuard extends GarbageCollector {
6965
+ constructor(placeDefinition, enabled$, options) {
6966
+ var _a;
6967
+ super();
6968
+ this.placeDefinition = placeDefinition;
6969
+ this.enabled$ = enabled$;
6970
+ const { chain } = Dsl.disposeWith(this);
6971
+ this.readyPromise = (_a = withPostponeUntil(this, options, condition$ => {
6972
+ return toPromise(this, condition$);
6973
+ })) !== null && _a !== void 0 ? _a : Promise.resolve();
6974
+ }
6975
+ waitUntilReady() {
6976
+ return __awaiter(this, void 0, void 0, function* () {
6977
+ yield this.readyPromise;
6978
+ });
6979
+ }
6980
+ }
6981
+ class EnabledPlaceChecker extends ReducingValueModel {
6961
6982
  constructor() {
6962
6983
  super([]);
6963
- this.predicatesByPlace = new ArrayMultimap;
6964
- this.defaultAuthCheck = () => true;
6965
- }
6966
- setDefaultAuthCheck(options) {
6967
- this.defaultAuthCheck = (placeDef) => {
6968
- return options.isAuthorised(placeDef);
6969
- };
6970
- if (options.dependsOn$) {
6971
- this.trackSource(options.dependsOn$);
6972
- }
6984
+ this.placeGuards$ = new MutableListModel();
6985
+ const { chain } = Dsl.disposeWith(this);
6986
+ this.placeGuardsByPlaceDef$ = chain(this.placeGuards$).indexManyBy("placeDefinition");
6973
6987
  }
6974
- authoriseWhen(placeDefinition, condition$) {
6988
+ enableWhen(placeDefinition, condition$, options) {
6975
6989
  const { chain } = Dsl.disposeWith(this);
6976
- this.predicatesByPlace.put(placeDefinition, condition$);
6990
+ this.placeGuards$.push(new PlaceAuthGuard(placeDefinition, condition$, options));
6977
6991
  this.trackSource(condition$);
6978
6992
  }
6979
6993
  isAuthorised(placeDef) {
6980
6994
  return this.value(placeDef);
6981
6995
  }
6982
6996
  compute(values) {
6983
- return (def) => {
6984
- return this.defaultAuthCheck(def) && this.checkPredicatesByPlace(def);
6985
- };
6997
+ return (def) => this.checkPredicatesByPlace(def);
6986
6998
  }
6987
6999
  checkPredicatesByPlace(def) {
6988
- const placePredicates = this.predicatesByPlace.get(def);
7000
+ const placePredicates = this.placeGuardsByPlaceDef$.get(def);
6989
7001
  if (!placePredicates || placePredicates.length < 1) {
6990
7002
  return true;
6991
7003
  }
6992
7004
  else {
6993
7005
  return placePredicates.reduce((sum, model) => {
6994
- return sum && model.value;
7006
+ return sum && model.enabled$.value;
6995
7007
  }, true);
6996
7008
  }
6997
7009
  }
7010
+ waitUntilReady(placeDef) {
7011
+ return __awaiter(this, void 0, void 0, function* () {
7012
+ const placeAuthGuards = this.placeGuardsByPlaceDef$.get(placeDef);
7013
+ if ((placeAuthGuards === null || placeAuthGuards === void 0 ? void 0 : placeAuthGuards.length) > 0) {
7014
+ yield Promise.all(placeAuthGuards.map(it => it.waitUntilReady()));
7015
+ }
7016
+ });
7017
+ }
6998
7018
  }
6999
7019
  class PlaceAuthService extends GarbageCollector {
7000
7020
  constructor() {
7001
7021
  super();
7002
- this.placeGuards$ = new MutableListModel();
7003
- this._ready$ = new AndValueModel().setDefault(true);
7022
+ this._authNReady$ = new AndValueModel().setDefault(true);
7023
+ this._authZReady$ = new AndValueModel().setDefault(true);
7004
7024
  this.authenticated$ = this.registerDisposable(new DelegatingValueModel).withDefault(true);
7005
- this.authorisationChecker$ = this.registerDisposable(new PlaceAuthorisationChecker());
7025
+ this.authChecker$ = this.registerDisposable(new DelegatingValueModel).withDefault(() => true);
7026
+ this.enabledPlaceChecker = this.registerDisposable(new EnabledPlaceChecker());
7006
7027
  const { chain } = Dsl.disposeWith(this);
7007
- this.accessGuard$ = chain.reduce(this.authenticated$, this.authorisationChecker$, (authenticated, authCheck) => {
7008
- return new PlaceAuthService.AccessGuard(authenticated, authCheck);
7028
+ this.accessGuard$ = chain.reduce(this.authenticated$, this.authChecker$, this.enabledPlaceChecker, (authenticated, authCheck, enabledPlaceCheck) => {
7029
+ return new PlaceAuthService.AccessGuard(authenticated, def => authCheck(def) && enabledPlaceCheck(def));
7009
7030
  });
7010
7031
  }
7011
7032
  configureAuthentication(options) {
7012
7033
  this.authNOptions = options;
7013
7034
  this.authenticated$.setDelegate(options.isAuthenticated$);
7014
- this.capturePostoneDependency(options);
7035
+ withPostponeUntil(this, options, condition$ => this._authNReady$.addSource(condition$));
7015
7036
  }
7016
7037
  configureAuthorisation(options) {
7017
7038
  const { chain } = Dsl.disposeWith(this);
7018
7039
  this.authZOptions = options;
7019
- this.authorisationChecker$.setDefaultAuthCheck(options);
7020
- this.capturePostoneDependency(options);
7040
+ let authChecker$ = ValueModel.constant(def => options.isAuthorised(def));
7041
+ if (options.dependsOn$) {
7042
+ // have to return a new funtion or the value model won't fire a change event
7043
+ authChecker$ = chain(authChecker$).map(it => def => it(def), { dependsOn: options.dependsOn$ });
7044
+ }
7045
+ this.authChecker$.setDelegate(authChecker$);
7046
+ withPostponeUntil(this, options, condition$ => this._authZReady$.addSource(condition$));
7021
7047
  }
7022
7048
  enablePlace(placeDefinition, options) {
7023
7049
  const { chain } = Dsl.disposeWith(this);
7024
7050
  const when$ = options.when$ ? options.when$ : chain(options.unless$).isFalsey();
7025
- this.authorisationChecker$.authoriseWhen(PlaceComponent.getDefinition(placeDefinition), when$);
7026
- this.capturePostoneDependency(options);
7051
+ this.enabledPlaceChecker.enableWhen(PlaceComponent.getDefinition(placeDefinition), when$, options);
7027
7052
  }
7028
- waitUntilReady() {
7029
- return this.toPromise(this._ready$);
7053
+ waitUntilAuthenticationReady() {
7054
+ return __awaiter(this, void 0, void 0, function* () {
7055
+ yield toPromise(this, this._authNReady$);
7056
+ });
7057
+ }
7058
+ waitUntilAuthorisationReadyFor(placeDef) {
7059
+ return __awaiter(this, void 0, void 0, function* () {
7060
+ yield toPromise(this, this._authZReady$);
7061
+ yield this.enabledPlaceChecker.waitUntilReady(placeDef);
7062
+ });
7030
7063
  }
7031
7064
  getAuthenticationFailureRedirect(activatedRoute, state) {
7032
7065
  const redirect = this.authNOptions.redirectTo(activatedRoute, state);
@@ -7035,22 +7068,6 @@ class PlaceAuthService extends GarbageCollector {
7035
7068
  getAuthorisationFailureRedirectOptions(component) {
7036
7069
  return this.authZOptions.redirectTo(component).map(it => it instanceof Visit ? it : Visit.goto(it));
7037
7070
  }
7038
- toPromise(condition$) {
7039
- // TODO: move this functionality to pectin with a waitUnit(model$).isTruthy() DSL.
7040
- const { when } = Dsl.disposeWith(this);
7041
- return new Promise((resolve) => {
7042
- when(condition$).becomesTruthy(() => resolve(), { once: true, initialValue: "evaluate" });
7043
- });
7044
- }
7045
- capturePostoneDependency(options) {
7046
- const { chain } = Dsl.disposeWith(this);
7047
- if (options.postponeUntil) {
7048
- this._ready$.addSource(options.postponeUntil);
7049
- }
7050
- else if (options.postponeWhile) {
7051
- this._ready$.addSource(chain(options.postponeWhile).isFalsey());
7052
- }
7053
- }
7054
7071
  isAuthenticated() {
7055
7072
  return this.accessGuard$.value.isAuthenticated();
7056
7073
  }
@@ -7060,15 +7077,15 @@ class PlaceAuthService extends GarbageCollector {
7060
7077
  }
7061
7078
  (function (PlaceAuthService) {
7062
7079
  class AccessGuard {
7063
- constructor(authenticated, authCheck) {
7080
+ constructor(authenticated, checkAuth) {
7064
7081
  this.authenticated = authenticated;
7065
- this.authCheck = authCheck;
7082
+ this.checkAuth = checkAuth;
7066
7083
  }
7067
7084
  isAuthenticated() {
7068
7085
  return this.authenticated;
7069
7086
  }
7070
7087
  isAuthorised(placeDefinition) {
7071
- return this.authCheck(placeDefinition);
7088
+ return this.checkAuth(placeDefinition);
7072
7089
  }
7073
7090
  }
7074
7091
  PlaceAuthService.AccessGuard = AccessGuard;
@@ -10410,7 +10427,17 @@ class AbstractPlaceNavigationComponent extends DisposableComponent {
10410
10427
  this.placeFaces = new Map();
10411
10428
  this.trackByPlaceDef = (index, data) => data.place;
10412
10429
  const { chain, valueOf, before, when, after, observe, switchOn } = Dsl.disposeWith(this);
10413
- this.placeDefinitions = chain(this.places$).map(c => PlaceComponent.getDefinition(c));
10430
+ this.authorisedPlaces$ = chain(this.places$)
10431
+ .select(placeType => {
10432
+ var _a;
10433
+ const definition = PlaceComponent.getDefinition(placeType);
10434
+ const guard = this.placeRouter.authService.accessGuard$.value;
10435
+ return guard.isAuthorised(definition) || ((_a = this.placeRouter.activeVisit$.value) === null || _a === void 0 ? void 0 : _a.isPlaceActive(definition));
10436
+ }, {
10437
+ postponeWhile: this.placeRouter.navigationInProgress$,
10438
+ dependsOn: [this.placeRouter.authService.accessGuard$, this.placeRouter.activeVisit$]
10439
+ });
10440
+ this.placeDefinitions = chain(this.authorisedPlaces$).map(c => PlaceComponent.getDefinition(c));
10414
10441
  this.commandFactory = Command.createFactory((placeDefinition) => {
10415
10442
  this.placeRouter.navigate(placeDefinition.component);
10416
10443
  });
@@ -10989,7 +11016,7 @@ class PlaceGuard {
10989
11016
  if (PlaceComponent.isPlaceComponentConstructor(activatedRoute.component)) {
10990
11017
  const placeDefinition = PlaceComponent.getDefinition(activatedRoute.component);
10991
11018
  if (placeDefinition.authenticate) {
10992
- yield this.placeRouter.authService.waitUntilReady();
11019
+ yield this.placeRouter.authService.waitUntilAuthenticationReady();
10993
11020
  const authenticated = this.authService.isAuthenticated();
10994
11021
  if (!authenticated) {
10995
11022
  const redirect = this.authService.getAuthenticationFailureRedirect(activatedRoute, state);
@@ -10999,6 +11026,7 @@ class PlaceGuard {
10999
11026
  }
11000
11027
  return this.createUrlTree(redirect);
11001
11028
  }
11029
+ yield this.authService.waitUntilAuthorisationReadyFor(placeDefinition);
11002
11030
  if (!this.authService.isAuthorised(placeDefinition)) {
11003
11031
  const nextRedirect = this.findBestAuthenticatedAlternative(placeDefinition, activatedRoute);
11004
11032
  return this.createUrlTree(nextRedirect);