import { TbxAppStateModel, TbxAppStateService } from '@lacera/ngx-toolbox/app'; import { NgxsOnInit, StateContext, NgxsModuleOptions, NgxsModule } from '@ngxs/store'; import * as i0 from '@angular/core'; import { ModuleWithProviders } from '@angular/core'; import { Observable } from 'rxjs'; import { TbxError } from '@lacera/ngx-toolbox/http'; import { Params, RouterStateSnapshot } from '@angular/router'; import { RouterStateSerializer, RouterStateModel, NgxsRouterPluginModule } from '@ngxs/router-plugin'; import { NgxsDevtoolsOptions, NgxsReduxDevtoolsPluginModule } from '@ngxs/devtools-plugin'; declare namespace TbxAppActions { /** Sets the application details received from the server to the vendor. */ class TbxInitApplication { payload: TbxAppStateModel; static readonly type = "[TBX Application] Init Application"; constructor(payload: TbxAppStateModel); } /** Sets fatal startup information when user is authorized to run the app. */ class TbxUserUnauthorized { payload: string; static readonly type = "[TBX Application] User Unauthorized"; constructor(payload: string); } } declare class TbxAppState implements NgxsOnInit { private readonly stateService; constructor(stateService: TbxAppStateService); /** * Initializes the state with application details received from the server. * * @param ctx The state context. * @param action The action payload. */ setApp(ctx: StateContext, action: TbxAppActions.TbxInitApplication): void; /** * Sets the state to unauthorized when current user cannot run the application. * * @param ctx The state context. * @param action The action payload. */ setAppFail(ctx: StateContext, action: TbxAppActions.TbxUserUnauthorized): void; /** * Invoked after all states have been initialized and pushed into the state stream. * * @param ctx The store context. */ ngxsOnInit(ctx: StateContext): void; static ɵfac: i0.ɵɵFactoryDeclaration; static ɵprov: i0.ɵɵInjectableDeclaration; } /** Defines the state slice for the LoadMore list helper. */ interface TbxLoadMoreStateModel { /** The ending index to which a list should be sliced. */ endIndex: number; /** The number of items to display at a time. */ pageSize: number; } /** The initial state of the LoadMore state. */ declare const initialState: TbxLoadMoreStateModel; declare namespace TbxLoadMoreActions { /** An action to set the LoadMore state. */ class SetLoadMore { endIndex: number; pageSize: number; static readonly type = "[ToolBox LoadMore Page] Set Load More"; constructor(endIndex: number, pageSize: number); } /** An action to set the end index for the LoadMore state. */ class SetEndIndex { endIndex: number; static readonly type = "[ToolBox LoadMore Page] Set End Index"; constructor(endIndex: number); } /** An action to set the page size for the LoadMore state. */ class SetPageSize { pageSize: number; static readonly type = "[ToolBox LoadMore Page] Set Page Size"; constructor(pageSize: number); } } declare class TbxLoadMoreState { static loadMore(state: TbxLoadMoreStateModel): TbxLoadMoreStateModel; static endIndex(state: TbxLoadMoreStateModel): number; static pageSize(state: TbxLoadMoreStateModel): number; setLoadMore(ctx: StateContext, { endIndex, pageSize }: TbxLoadMoreActions.SetLoadMore): void; setIndex(ctx: StateContext, { endIndex }: TbxLoadMoreActions.SetEndIndex): void; create(ctx: StateContext, { pageSize }: TbxLoadMoreActions.SetPageSize): void; static ɵfac: i0.ɵɵFactoryDeclaration; static ɵprov: i0.ɵɵInjectableDeclaration; } /** The enumeration of types that can be assigned to an error vendor. */ type TbxLoadingState = "init" | "loading" | "loaded"; /** The custom error type that may be caught during an API call. */ type TbxStateError = any | string | null; /** The error state to append to other states. */ interface TbxErrorState { /** The API call state error. */ error: TbxStateError; } /** The custom type that can be assigned to the call state. */ type TbxCallState = TbxLoadingState | TbxErrorState; /** The base state model from which other states should derive. */ interface TbxBaseStateModel { /** The state for the API call. */ callState: TbxCallState; } /** * Helper function to get the error from the given state, if any. * @param callState The state to check. * @returns The error found in the state, or null. */ declare const getStateError: (callState: TbxCallState) => TbxStateError | null; declare namespace TbxCallActions { /** * An action to update the base state to indicate an API call in in progress. */ class CallLoading { static readonly type = "[ToolBox API] Call Loading"; } /** * An action to update the base state to indicate the call was successful. */ class CallSuccess { static readonly type = "[ToolBox API] Call Success"; } /** * An action to update the base state to indicate the API call failed. */ class CallFailure { error: TbxErrorState; static readonly type = "[ToolBox API] Call Failure"; constructor(error: TbxErrorState); } } /** * Base class from which other base classes should derive to make use of the * call state that this manages. * * @dynamic */ declare class TbxBaseState { /** * Gets a value indicating whether the API call state is currently in progress. * @returns True if the state is loading or not. */ static loadingFn(): (state: TbxBaseStateModel) => boolean; /** * Gets a value indicating whether the API call state was successful and loaded. * @returns True if the state is loaded or not. */ static loadedFn(): (state: TbxBaseStateModel) => boolean; /** * Gets the {@link TbxError} that occurred during the API call, if any. * @returns A {@link TbxError} object, string or null in the error state. */ static errorFn(): (state: TbxBaseStateModel) => TbxError | string | null; /** * Gets the error message as a string from the state. * @returns The error message as a string. */ static errorMessageFn(): (state: TbxBaseStateModel) => string | null; /** * Updates the state to indicate the API call is loading. * @param ctx The current state. * @returns The updated state. */ callLoading(ctx: StateContext): TbxBaseStateModel; /** * Updates the state to indicate the API call was successful. * @param ctx The current state. * @returns The updated state. */ callSuccess(ctx: StateContext): TbxBaseStateModel; /** * Updates the state to indicate the call failed. * @param ctx The current state. * @param error The error to store in the state. * @returns The updated state. */ callFailure(ctx: StateContext, { error }: TbxCallActions.CallFailure): TbxBaseStateModel; /** * Executes a request and updates the state accordingly. * @param ctx The current state. * @param request The request to pipe. * @param success The function to call after the request completes. * @returns The observable result. */ request(ctx: StateContext, request: () => Observable, success?: (response: TResult) => void): Observable; } interface TbxRouterStateModel { /** The current URL. */ url: string; /** Any parameters found in the URL. */ params: Params; /** Any query parameters found in the URL. */ queryParams: Params; /** Any custom data in the route. */ data: any; } /** * The route vendor serializer will on route changes serialize the activated route * into an object which reflect our vendor model. */ declare class TbxRouterStateSerializer implements RouterStateSerializer { serialize(routerState: RouterStateSnapshot): TbxRouterStateModel; } /** Defines all the selectors for the router state. */ declare class TbxRouterSelectors { /** * Retrieves the URL from the router state. * @param param0 The router state. * @returns The route URL if found or undefined. */ static url({ state }: RouterStateModel): string | undefined; /** * Retrieves the array of {@link Params} from the router state. * @param param0 The router state. * @returns The route parameters if found or undefined. */ static params({ state }: RouterStateModel): Params | undefined; /** * Retrieves the array of query {@link Params} from the router state. * @param param0 The router state. * @returns The route query parameters if found or undefined. */ static queryParams({ state }: RouterStateModel): Params | undefined; /** * Retrieves the router data object from the router state. * @param param0 The router state. * @returns The route data object if found or undefined. */ static data({ state }: RouterStateModel): any; /** * Retrieves the page title from the router data object state. * @param data The router data object state. * @returns The page title if found or undefined. */ static pageTitle(data: any): string; /** * Retrieves the action from the router data object state. * @param data The router data object state. * @returns The action if found or undefined. */ static action(data: any): string; /** * Retrieves whether in edit mode from the router data object state. * @param data The router data object state. * @returns The edit mode flag. */ static editMode(data: any): boolean; /** * Retrieves whether in delete mode from the router data object state. * @param data The router data object state. * @returns The delete mode flag. */ static deleteMode(data: any): boolean; /** * Retrieves the parameter 'id' from the route parameters. * @param params An array of {@link params} retrieved from the route. * @returns The value of 'id' as a {@link number} or zero. */ static id(params?: Params): number; } declare type StateClass = new (...args: any[]) => T; declare class TbxNgxsModule { constructor(parentModule: TbxNgxsModule); static forRoot(states?: StateClass[], options?: NgxsModuleOptions): ModuleWithProviders; static forRouterRoot(): ModuleWithProviders; static forDevToolsRoot(options?: NgxsDevtoolsOptions): ModuleWithProviders; static ɵfac: i0.ɵɵFactoryDeclaration; static ɵmod: i0.ɵɵNgModuleDeclaration; static ɵinj: i0.ɵɵInjectorDeclaration; } export { TbxAppActions, TbxAppState, TbxBaseState, TbxCallActions, TbxLoadMoreActions, TbxLoadMoreState, TbxNgxsModule, TbxRouterSelectors, TbxRouterStateSerializer, getStateError, initialState }; export type { StateClass, TbxBaseStateModel, TbxCallState, TbxErrorState, TbxLoadMoreStateModel, TbxLoadingState, TbxRouterStateModel, TbxStateError };