import { HttpErrorResponse } from '@angular/common/http'; import * as _ngrx_effects from '@ngrx/effects'; import { Actions, CreateEffectMetadata } from '@ngrx/effects'; import * as _ngrx_store from '@ngrx/store'; import { ActionCreator, Creator, Action, ActionReducer, on, MemoizedSelector } from '@ngrx/store'; import * as rxjs from 'rxjs'; import { OperatorFunction, Observable } from 'rxjs'; import * as _angular_core from '@angular/core'; import { ProviderToken } from '@angular/core'; import { GenericEditDialogService, GridComponent } from '@sowatech/shared/swt-generic'; import { RefreshResult, RefreshParams } from '@sowatech/shared/ds-datasource'; /** * Effect, der als Reaktion auf eine Failure Action den ErrorHandler mit angegebenem ActionText auslöst. * ```ts * loadListError$ = createErrorHandlerEffect(apiActions.loadListFailure, 'Laden der Liste'); * ``` */ declare function createErrorHandlerEffect(action: ActionCreator>, actionText: string, actions$?: Actions): rxjs.Observable<{ error: ErrorParams; actionText: string; handling: "messageBox" | "dialog"; } & Action<"[App] Error">> & _ngrx_effects.CreateEffectMetadata; /** * Effect, der als Reaktion auf eine Failure Action den Fehler im Edit Dialog anzeigt. * ```ts * createError$ = createDialogErrorEffect(apiActions.createFailure); * ``` */ declare function createDialogErrorEffect(action: ActionCreator>, actions$?: Actions): rxjs.Observable<{ error: ErrorParams; actionText: string; handling: "messageBox" | "dialog"; } & Action<"[App] Error">> & _ngrx_effects.CreateEffectMetadata; type HttpStatusCode = number; type ErrorParams = { name: string; message: string; status: HttpStatusCode; error: any; trace?: string; }; type FailureParam = HttpErrorResponse; type FailurePayload = { error: ErrorParams; }; type FailureAction = ActionCreator>; /** * Kann gesetzt werden, um eine Trace ID aus dem Error zu lesen * ```ts * errorPropsGetTraceId.set(error => { * if (error instanceof HttpErrorResponse) * return error.headers.get('X-Trace-Id') ?? undefined; * return undefined; * }); * ``` */ declare const errorPropsGetTraceId: _angular_core.WritableSignal<(error: unknown) => string | undefined>; /** * props für Failure Actions. * ```ts * createActionGroup({ * name: 'My API', * events: { * 'Update Success': emptyProps(), * 'Update Failure': errorProps(), * }, * }); * * catchError(err => of(apiActions.updateFailure(err))) * ``` */ declare const errorProps: () => (error: FailureParam) => FailurePayload; /** * Abkürzung fürs Mappen zu einer Failure Action. * * ohne mapFailure: `catchError(err => of(apiActions.updateFailure(err)))` * * mit mapFailure: `mapFailure(apiActions.updateFailure)` */ declare const mapFailure: (failureAction: FailureAction) => OperatorFunction; type ErrorOptions = { handling: 'messageBox'; actionText: string; } | { handling: 'dialog'; actionText: undefined; }; /** * globale Error Action, über die sämtliches ErrorHandling abgehandelt wird */ declare const errorAction: _ngrx_store.FunctionWithParametersType<[error: ErrorParams, errorOptions: ErrorOptions], { error: ErrorParams; actionText: string; handling: "messageBox" | "dialog"; } & Action<"[App] Error">> & Action<"[App] Error">; /** * Globaler Effect, der von `createDialogErrorEffect` gemappte Fehler im Dialog anzeigt. * Der Effect muss im AppModule registriert werden: * ```ts * EffectsModule.forRoot({ globalDialogErrorHandlingEffect }) * ``` */ declare const globalDialogErrorHandlingEffect: _ngrx_effects.FunctionalEffect<(actions$?: Actions, dialog?: GenericEditDialogService) => rxjs.Observable>; type ErrorHandlerService = ProviderToken<{ handleError: (error: any, actionText: string) => any; }>; /** * Globaler Effect, der von `createErrorHandlerEffect` gemappte Fehler über den ErrorHandler anzeigt * Ist eine Factory, weil der ErrorHandler nicht im shared liegt. * Der Effect muss im AppModule registriert werden: * ```ts * EffectsModule.forRoot({ globalErrorHandlingEffect: globalErrorHandlingEffectFactory(ErrorHandlerService) }) * ``` */ declare function globalErrorHandlingEffectFactory(errorHandlerType: ErrorHandlerService): _ngrx_effects.FunctionalEffect<(actions$?: Actions, errorHandler?: { handleError: (error: any, actionText: string) => any; }) => rxjs.Observable>; type EffectReturnType = Observable & CreateEffectMetadata; /** * Abkürzung von `createEffect` für den Standardfall, wenn man auf Actions reagiert * ```ts * loadList$ = createActionEffect( * [listActions.init, apiActions.createSuccess], * switchMap(() => this.webApi.getList()), * ); * create$ = createActionEffect( * listActions.create, * showDialog(new CreateDialog()), * switchMap(({ dto }) => this.webApi.create(dto)), * ); * ``` */ declare function createActionEffect(actions: ActionCreator | ActionCreator[], op1: OperatorFunction, Action>): EffectReturnType; declare function createActionEffect(actions: ActionCreator | ActionCreator[], op1: OperatorFunction, A>, op2: OperatorFunction): EffectReturnType; declare function createActionEffect(actions: ActionCreator | ActionCreator[], op1: OperatorFunction, A>, op2: OperatorFunction, op3: OperatorFunction): EffectReturnType; declare function createActionEffect(actions: ActionCreator | ActionCreator[], op1: OperatorFunction, A>, op2: OperatorFunction, op3: OperatorFunction, op4: OperatorFunction): EffectReturnType; declare function createActionEffect(actions: ActionCreator | ActionCreator[], op1: OperatorFunction, A>, op2: OperatorFunction, op3: OperatorFunction, op4: OperatorFunction, op5: OperatorFunction): EffectReturnType; declare function createActionEffect(actions: ActionCreator | ActionCreator[], op1: OperatorFunction, A>, op2: OperatorFunction, op3: OperatorFunction, op4: OperatorFunction, op5: OperatorFunction, op6: OperatorFunction): EffectReturnType; declare function createActionEffect(actions: ActionCreator | ActionCreator[], op1: OperatorFunction, A>, op2: OperatorFunction, op3: OperatorFunction, op4: OperatorFunction, op5: OperatorFunction, op6: OperatorFunction, op7: OperatorFunction): EffectReturnType; declare function createActionEffect(actions: ActionCreator | ActionCreator[], op1: OperatorFunction, A>, op2: OperatorFunction, op3: OperatorFunction, op4: OperatorFunction, op5: OperatorFunction, op6: OperatorFunction, op7: OperatorFunction, op8: OperatorFunction): EffectReturnType; declare function createActionEffect(actions: ActionCreator | ActionCreator[], op1: OperatorFunction, A>, op2: OperatorFunction, op3: OperatorFunction, op4: OperatorFunction, op5: OperatorFunction, op6: OperatorFunction, op7: OperatorFunction, op8: OperatorFunction, op9: OperatorFunction): EffectReturnType; declare function createActionEffect(actions: ActionCreator | ActionCreator[], op1: OperatorFunction, A>, op2: OperatorFunction, op3: OperatorFunction, op4: OperatorFunction, op5: OperatorFunction, op6: OperatorFunction, op7: OperatorFunction, op8: OperatorFunction, op9: OperatorFunction, op10: OperatorFunction): EffectReturnType; /** * @deprecated * Benutze `createActionEffect` statt `this.on`, * `createErrorHandlerEffect` statt `this.onError` * und `createDialogErrorEffect` statt `this.onDialogError` */ declare abstract class EffectBase { protected readonly actions$: Actions; protected on(actions: ActionCreator | ActionCreator[], fn: (obs$: Observable>) => Observable): EffectReturnType; protected onError(action: ActionCreator>, actionText: string): Observable<{ error: ErrorParams; actionText: string; handling: "messageBox" | "dialog"; } & Action<"[App] Error">> & CreateEffectMetadata; protected onDialogError(action: ActionCreator>): Observable<{ error: ErrorParams; actionText: string; handling: "messageBox" | "dialog"; } & Action<"[App] Error">> & CreateEffectMetadata; } /** * Meta Reducer fürs Loggen der Actions. Wird konfiguriert im AppModule: * ```ts * StoreModule.forRoot({}, { metaReducers: [loggingMetaReducer] }), * ``` */ declare function loggingMetaReducer(reducer: ActionReducer): ActionReducer; interface ExternalRefreshState { refreshResult: RefreshResult | null; loading: boolean; } type Last = T extends readonly [...infer _, infer L] ? L : never; type OnFunction = typeof on; type OnReducer = Last>>; type Id = any; declare class ExternalRefreshAdapter { /** * Initial State für external Refresh. * ```ts * type State = ExternalRefreshState & { loading: boolean }; * const initialState: State = adapter.getInitialState({ loading: false }); * ``` * @param extraState zusätzlicher State, der neben dem `refreshResult` abgelegt wird */ getInitialState(extraState?: ExtraState): ExternalRefreshState & ExtraState; /** * Zum Updaten des Refresh Results. * ```ts * on(apiActions.loadSuccess, (state, { refreshResult }) => adapter.update(refreshResult, state)), * ``` */ update>(result: RefreshResult, state: State): State; /** * Zum Updaten des Refresh Results über `externalRefreshProps` * ```ts * // Action * 'Load Success': externalRefreshProps(), * // Reducer * on(apiActions.loadSuccess, adapter.updateFromAction()), * ``` */ updateFromAction>(): OnReducer[]>; /** * Löscht das Refresh Result */ clear>(state: State): State; setLoading>(loading: boolean, state: State): State & { loading: boolean; }; /** * Zum Setzen von `loading` * ```ts * on(apiActions.loadSuccess, apiAction.loadFailure, adapter.setLoadingStatic(false)), * ``` */ setLoadingStatic>(loading: boolean): (state: State) => State & { loading: boolean; }; /** * Setzt Loading auf `true`, wenn nicht nur für die Aggregate Params neu geladen wird. * ```ts * on(apiActions.load, (state, { refreshParams }) => adapter.startLoading(refreshParams, state)), * ``` */ startLoading>(refreshParams: RefreshParams, state: State): State; /** * Gibt ein paar nützliche Selectors zurück: */ getSelectors(): { selectList: (state: ExternalRefreshState) => T[]; selectItem: (state: ExternalRefreshState, id: Id) => T; selectIds: (state: ExternalRefreshState) => Id[]; }; /** * Da der Store immutable ist, muss der Selector für die Datasource überschrieben werden. * (SHANG-465) */ createRefreshResultSelector(selector: MemoizedSelector, RefreshResult | null>): MemoizedSelector, any, (s1: RefreshResult) => any>; } /** * Erstellt einen Adapter für den Umgang mit serverseitig geladenen Collections. * ```ts * const adapter = createExternalRefreshAdapter(); * * type State = ExternalRefreshState; * * const initialState: State = adapter.getInitialState(); * * const myFeature = createFeature({ * name: 'myFeature', * reducer: createReducer( * initialState, * on(apiActions.loadSuccess, adapter.updateFromAction()), * on(actions.load, (state, { refreshParams }) => adapter.startLoading(refreshParams, state)), * on(apiActions.loadSuccess, apiActions.loadFailure, adapter.setLoadingStatic(false)), * ), * extraSelectors(baseSelectors) { * const selectRefreshResult = adapter.createRefreshResultSelector(baseSelectors.selectRefreshResult); * return { * selectRefreshResult, * }; * }, * }); * * // Load Action * 'Load': externalRefreshParamsProps(), * // API Action * 'Load Success': externalRefreshResultProps(), * ``` */ declare function createExternalRefreshAdapter(): ExternalRefreshAdapter; type ExternalRefreshResultProps = { refreshResult: RefreshResult; }; type ExternalRefreshResultAction = ActionCreator], ExternalRefreshResultProps & { type: string; }>>; declare function externalRefreshResultProps(): (refreshResult: RefreshResult) => ExternalRefreshResultProps; type ExternalRefreshParamsProps = { refreshParams: RefreshParams; }; type ExternalRefreshParamsAction = ActionCreator>; declare function externalRefreshParamsProps(): (refreshParams: RefreshParams) => ExternalRefreshParamsProps; interface DatasourceCsvExportEffectOptions { action: ExternalRefreshResultAction; grid: () => GridComponent | null | undefined; } /** * Ermöglicht CSV-Downloads mit External Refresh über NGRX. * ```ts * constructor() { * // ... * handleCsvExportAction({ action: myActions.loadSuccess, grid: () => this.grid() }); * } * ``` */ declare function handleCsvExportAction(options: DatasourceCsvExportEffectOptions): void; declare class ExternalRefreshActionDirective { private readonly datasource; private readonly store; readonly externalRefreshAction: _angular_core.InputSignal; constructor(); static ɵfac: _angular_core.ɵɵFactoryDeclaration; static ɵdir: _angular_core.ɵɵDirectiveDeclaration; } export { EffectBase, ExternalRefreshActionDirective, ExternalRefreshAdapter, createActionEffect, createDialogErrorEffect, createErrorHandlerEffect, createExternalRefreshAdapter, errorAction, errorProps, errorPropsGetTraceId, externalRefreshParamsProps, externalRefreshResultProps, globalDialogErrorHandlingEffect, globalErrorHandlingEffectFactory, handleCsvExportAction, loggingMetaReducer, mapFailure }; export type { DatasourceCsvExportEffectOptions, ErrorParams, ExternalRefreshParamsAction, ExternalRefreshParamsProps, ExternalRefreshResultAction, ExternalRefreshResultProps, ExternalRefreshState };