import { mapResponse } from '@ngrx/operators'; import { EventInstance } from '@ngrx/signals/events'; import { Observable } from 'rxjs'; import { describeError } from '../notifications'; type Creator = (message: string) => EventInstance; /** Runs a command and turns its outcome into a succeeded/failed event. */ export function runCommand( command$: Observable, successMessage: string, succeeded: Creator, failed: Creator, ) { return command$.pipe( mapResponse({ next: () => succeeded(successMessage), error: (error) => failed(describeError(error)), }), ); }