@o3r/routing
Version:
This module helps you to configure an Otter application's routing (POST parameter management, preloading strategy, guard recommendation).
266 lines (256 loc) • 13.8 kB
TypeScript
import * as _ngrx_effects from '@ngrx/effects';
import { Actions } from '@ngrx/effects';
import * as rxjs from 'rxjs';
import { Observable } from 'rxjs';
import * as _ngrx_store from '@ngrx/store';
import { ActionReducer, Action, ReducerTypes, ActionCreator } from '@ngrx/store';
import * as i0 from '@angular/core';
import { InjectionToken, ModuleWithProviders, Provider } from '@angular/core';
import * as _ngrx_entity from '@ngrx/entity';
import { EntityState, EntityAdapter } from '@ngrx/entity';
import * as _o3r_routing from '@o3r/routing';
import { BuildTimeProperties } from '@o3r/core';
import { PreloadingStrategy, Route } from '@angular/router';
/**
* Effect to react on Ngrx router store actions
*/
declare class NgrxStoreRouterEffect {
protected actions$: Actions<any>;
/**
* Clear Router registrations when the active history entry changes (ex : click on back/next button Action)
*/
resetRouterRegistrationOnRequest$: rxjs.Observable<_ngrx_store.Action<"[RoutingGuard] clear entities">> & _ngrx_effects.CreateEffectMetadata;
/**
* Clear Router registrations when navigation happened
*/
resetRouterRegistrationOnNavigated$: rxjs.Observable<_ngrx_store.Action<"[RoutingGuard] clear entities">> & _ngrx_effects.CreateEffectMetadata;
static ɵfac: i0.ɵɵFactoryDeclaration<NgrxStoreRouterEffect, never>;
static ɵprov: i0.ɵɵInjectableDeclaration<NgrxStoreRouterEffect>;
}
/** Identifies the status of a registered block */
declare enum RegisteredItemStatus {
/** block is ready (async call has not been triggered) */
READY = "READY",
/** block is waiting for async call to resolve */
PENDING = "PENDING",
/** block received the async call result and it's a failure */
FAILURE = "FAILURE",
/** block received the async call result and it's a success */
SUCCESS = "SUCCESS"
}
/** Identifies the failure reason for the registered block */
declare enum RegisteredItemFailureReason {
/** Routing Failed because the async call result is failure */
ASYNC_CALL_FAILURE = "ASYNC_CALL_FAILURE",
/** Routing failed because the changes to the form has not been saved */
FORM_UNSAVED = "FORM_UNSAVED"
}
/**
* RoutingGuard model
*/
interface RoutingGuardModel {
/** Id of the block instance */
id: string;
/** Routing status of the block */
status: RegisteredItemStatus;
/** Routing Guard blocking reason */
blockingReason?: RegisteredItemFailureReason;
}
/**
* RoutingGuard store state
*/
interface RoutingGuardState extends EntityState<RoutingGuardModel> {
}
/**
* Name of the RoutingGuard Store
*/
declare const ROUTING_GUARD_STORE_NAME = "routingGuard";
/**
* RoutingGuard Store Interface
*/
interface RoutingGuardStore {
/** RoutingGuard state */
[ROUTING_GUARD_STORE_NAME]: RoutingGuardState;
}
interface RoutingGuardActionPayload {
/** Id of the block instance */
id: string;
}
interface RoutingGuardFailureReasonPayload {
/** Id of the block instance */
id: string;
/** Reason for failure */
reason: RegisteredItemFailureReason;
}
/**
* Register a new entity in routing guard store
*/
declare const registerRoutingGuardEntity: _ngrx_store.ActionCreator<"[RoutingGuard] register an entity", (props: RoutingGuardActionPayload) => RoutingGuardActionPayload & _ngrx_store.Action<"[RoutingGuard] register an entity">>;
/**
* Set an entity in FAILURE status
*/
declare const setRoutingGuardEntityAsFailure: _ngrx_store.ActionCreator<"[RoutingGuard] set an entity state as FAILURE", (props: RoutingGuardActionPayload) => RoutingGuardActionPayload & _ngrx_store.Action<"[RoutingGuard] set an entity state as FAILURE">>;
/**
* Set an entity in SUCCESS status and clear the reason
*/
declare const setRoutingGuardEntityAsSuccessAndClearReason: _ngrx_store.ActionCreator<"[RoutingGuard] set an entity state as SUCCESS and clear reason", (props: RoutingGuardActionPayload) => RoutingGuardActionPayload & _ngrx_store.Action<"[RoutingGuard] set an entity state as SUCCESS and clear reason">>;
/**
* Set an entity in PENDING status
*/
declare const setRoutingGuardEntityAsPending: _ngrx_store.ActionCreator<"[RoutingGuard] set an entity state as PENDING", (props: RoutingGuardActionPayload) => RoutingGuardActionPayload & _ngrx_store.Action<"[RoutingGuard] set an entity state as PENDING">>;
/**
* Clear only the entities, keeps the other attributes in the state
*/
declare const clearRoutingGuardEntities: _ngrx_store.ActionCreator<"[RoutingGuard] clear entities", () => _ngrx_store.Action<"[RoutingGuard] clear entities">>;
/**
* Clear only the entities, keeps the other attributes in the state
*/
declare const clearRoutingGuardEntitiesFailureReason: _ngrx_store.ActionCreator<"[RoutingGuard] clear failure reason for an entity", (props: RoutingGuardActionPayload) => RoutingGuardActionPayload & _ngrx_store.Action<"[RoutingGuard] clear failure reason for an entity">>;
/**
* Set entity in FAILURE status with a reason
*/
declare const setRoutingGuardEntityFailureWithReason: _ngrx_store.ActionCreator<"[RoutingGuard] set an entity state as FAILURE with a reason", (props: RoutingGuardFailureReasonPayload) => RoutingGuardFailureReasonPayload & _ngrx_store.Action<"[RoutingGuard] set an entity state as FAILURE with a reason">>;
/** Token of the RoutingGuard reducer */
declare const ROUTING_GUARD_REDUCER_TOKEN: InjectionToken<ActionReducer<RoutingGuardState, Action<string>>>;
/** Provide default reducer for RoutingGuard store */
declare function getDefaultRoutingGuardReducer(): ActionReducer<RoutingGuardState, Action<string>>;
declare class RoutingGuardStoreModule {
static forRoot<T extends RoutingGuardState>(reducerFactory: () => ActionReducer<T, Action>): ModuleWithProviders<RoutingGuardStoreModule>;
static ɵfac: i0.ɵɵFactoryDeclaration<RoutingGuardStoreModule, never>;
static ɵmod: i0.ɵɵNgModuleDeclaration<RoutingGuardStoreModule, never, [typeof _ngrx_store.StoreFeatureModule], never>;
static ɵinj: i0.ɵɵInjectorDeclaration<RoutingGuardStoreModule>;
}
/**
* RoutingGuard Store adapter
*/
declare const routingGuardAdapter: EntityAdapter<RoutingGuardModel>;
/**
* RoutingGuard Store initial value
*/
declare const routingGuardInitialState: RoutingGuardState;
/**
* List of basic actions for RoutingGuard Store
*/
declare const routingGuardReducerFeatures: ReducerTypes<RoutingGuardState, ActionCreator[]>[];
/**
* RoutingGuard Store reducer
*/
declare const routingGuardReducer: _ngrx_store.ActionReducer<RoutingGuardState, _ngrx_store.Action<string>>;
/** Select RoutingGuard State */
declare const selectRoutingGuardState: _ngrx_store.MemoizedSelector<object, RoutingGuardState, _ngrx_store.DefaultProjectorFn<RoutingGuardState>>;
/** Select the array of RoutingGuard ids */
declare const selectRoutingGuardIds: _ngrx_store.MemoizedSelector<object, string[] | number[], (s1: RoutingGuardState) => string[] | number[]>;
/** Select the array of RoutingGuard */
declare const selectAllRoutingGuard: _ngrx_store.MemoizedSelector<object, _o3r_routing.RoutingGuardModel[], (s1: RoutingGuardState) => _o3r_routing.RoutingGuardModel[]>;
/** Select the dictionary of RoutingGuard entities */
declare const selectRoutingGuardEntities: _ngrx_store.MemoizedSelector<object, _ngrx_entity.Dictionary<_o3r_routing.RoutingGuardModel>, (s1: RoutingGuardState) => _ngrx_entity.Dictionary<_o3r_routing.RoutingGuardModel>>;
/** Select the total RoutingGuard count */
declare const selectRoutingGuardTotal: _ngrx_store.MemoizedSelector<object, number, (s1: RoutingGuardState) => number>;
/**
* Selector used to retrieve the list of entities' status
*/
declare const selectRoutingGuardEntitiesStatusList: _ngrx_store.MemoizedSelector<object, RegisteredItemStatus[], (s1: RoutingGuardState) => RegisteredItemStatus[]>;
/**
* Selector used to retrieve the list of entities' blocking reasons for FAILURE status.
*/
declare const selectRoutingGuardEntitiesBlockingReasons: _ngrx_store.MemoizedSelector<object, RegisteredItemFailureReason[], (s1: RoutingGuardState) => RegisteredItemFailureReason[]>;
/**
* Selector used to check that no item is in PENDING state.
* For example, we will rely on this selector to trigger the canDeactivate logic in the RoutingGuard
*/
declare const hasNoEntitiesInPendingState: _ngrx_store.MemoizedSelector<object, boolean, (s1: RegisteredItemStatus[]) => boolean>;
/**
* Selector used to check that no item is in FAILURE state.
* For example, we will rely on this selector to authorize or not the navigation in the RoutingGuard
*/
declare const hasNoEntitiesInFailureState: _ngrx_store.MemoizedSelector<object, boolean, (s1: RegisteredItemStatus[]) => boolean>;
/**
* Selector used to check that no item is in READY or FAILURE state.
* For example, we will rely on this selector to trigger the router navigation and display a loader
*/
declare const hasNoEntityInReadyOrFailureState: _ngrx_store.MemoizedSelector<object, boolean, (s1: RegisteredItemStatus[]) => boolean>;
/**
* Selector used to check that no item is in FAILURE state with a blocking reason provided.
* Takes `blockingReason: RegisteredItemFailureReason` as aproperty parameter.
*/
declare const hasNoEntityFailureStateWithReasons: _ngrx_store.MemoizedSelectorWithProps<object, {
blockingReason: RegisteredItemFailureReason;
}, boolean, (s1: RegisteredItemFailureReason[], props: {
blockingReason: RegisteredItemFailureReason;
}) => boolean>;
/**
* AppBaseHref factory function
* The APP_BASE_HREF will assume one of the following values (ordered by priority):
* 1- undefined (or disabled) if it's not a PROD environment
* 2- the content of the data tag data-appbasehref in the body if it exists
* 3- the content of config.APP_BASE_HREF if defined
* 4- otherwise, undefined
* @param config The application environment configuration
*/
declare function appBaseHrefFactory(config: BuildTimeProperties): string | undefined;
declare const ENVIRONMENT_CONFIG_TOKEN: InjectionToken<BuildTimeProperties>;
/**
* @deprecated Will be removed in v14.
*/
declare class AppServerRoutingModule {
/**
* Injects the APP_BASE_HREF with a custom factory
* @param config The application environment configuration
* @deprecated Please use {@link provideEnvironment} instead. Will be removed in v14.
*/
static forRoot(config: Partial<BuildTimeProperties>): ModuleWithProviders<AppServerRoutingModule>;
static ɵfac: i0.ɵɵFactoryDeclaration<AppServerRoutingModule, never>;
static ɵmod: i0.ɵɵNgModuleDeclaration<AppServerRoutingModule, never, never, never>;
static ɵinj: i0.ɵɵInjectorDeclaration<AppServerRoutingModule>;
}
type EnvironmentFeatureKind = 'base-href';
interface EnvironmentFeature<FeatureKind extends EnvironmentFeatureKind> {
ɵkind: FeatureKind;
ɵproviders: Provider[];
}
type BaseHrefFeature = EnvironmentFeature<'base-href'>;
type EnvironmentFeatures = BaseHrefFeature;
/**
* Specify a custom base href
* @param baseHref
*/
declare function withBaseHref<T extends string | undefined>(baseHref: T | ((environmentConfig: BuildTimeProperties) => T)): EnvironmentFeatures;
/**
* Provide environment configuration
* @note it will also provide APP_BASE_HREF based on the environment configuration
* @param config
* @param features
*/
declare function provideEnvironment(config: Partial<BuildTimeProperties>, ...features: EnvironmentFeatures[]): i0.EnvironmentProviders;
/**
* Data to inject to the route parameter to specify preloading strategy
*/
interface O3rOnDemandPreloadingData {
/** List of page reached that trigger preloading */
preloadOn: string[] | '*' | RegExp;
}
/**
* Check if the route has preload instructions
* @param data Route data
*/
declare function hasPreloadingOnDemand(data: any): data is O3rOnDemandPreloadingData;
/**
* Otter Preloading strategy base on previous route
* @inheritDoc
*/
declare class O3rOnNavigationPreloadingStrategy implements PreloadingStrategy {
private readonly router;
/**
* Check if the module should be preloaded based on the data preload array of routes or regex value
* @param data Route data
* @param url URL of current page
*/
private isUrlMatchingPreloadConfig;
/** @inheritDoc */
preload(route: Route, preload: () => Observable<any>): Observable<any>;
static ɵfac: i0.ɵɵFactoryDeclaration<O3rOnNavigationPreloadingStrategy, never>;
static ɵprov: i0.ɵɵInjectableDeclaration<O3rOnNavigationPreloadingStrategy>;
}
export { AppServerRoutingModule, ENVIRONMENT_CONFIG_TOKEN, NgrxStoreRouterEffect, O3rOnNavigationPreloadingStrategy, ROUTING_GUARD_REDUCER_TOKEN, ROUTING_GUARD_STORE_NAME, RegisteredItemFailureReason, RegisteredItemStatus, RoutingGuardStoreModule, appBaseHrefFactory, clearRoutingGuardEntities, clearRoutingGuardEntitiesFailureReason, getDefaultRoutingGuardReducer, hasNoEntitiesInFailureState, hasNoEntitiesInPendingState, hasNoEntityFailureStateWithReasons, hasNoEntityInReadyOrFailureState, hasPreloadingOnDemand, provideEnvironment, registerRoutingGuardEntity, routingGuardAdapter, routingGuardInitialState, routingGuardReducer, routingGuardReducerFeatures, selectAllRoutingGuard, selectRoutingGuardEntities, selectRoutingGuardEntitiesBlockingReasons, selectRoutingGuardEntitiesStatusList, selectRoutingGuardIds, selectRoutingGuardState, selectRoutingGuardTotal, setRoutingGuardEntityAsFailure, setRoutingGuardEntityAsPending, setRoutingGuardEntityAsSuccessAndClearReason, setRoutingGuardEntityFailureWithReason, withBaseHref };
export type { O3rOnDemandPreloadingData, RoutingGuardActionPayload, RoutingGuardFailureReasonPayload, RoutingGuardModel, RoutingGuardState, RoutingGuardStore };
//# sourceMappingURL=index.d.ts.map