import { ChildKey, NodeDefinition, NodeLike, StaticGraphNode, StaticNodeDefinition, StaticNodeType } from '../../types/graph'; import { ErrorFallbackGenerator } from './if-error'; import { KeyNodeDefinition } from './key'; /** * An instance of the [[catchError]] node. * See the [[catchError]] documentation to find out more. */ export interface CatchErrorNode extends StaticGraphNode<'catch-error', CatchErrorNodeProperties> { } /** * A definition of the [[catchError]] node. * See the [[catchError]] documentation to find out more. */ export interface CatchErrorNodeDefinition extends StaticNodeDefinition<'catch-error', CatchErrorNodeProperties> { } export interface CatchErrorNodeProperties { fallbackGenerator: ErrorFallbackGenerator; target: KeyNodeDefinition; } /** * The implementation of the [[catchError]]. * See the [[catchError]] documentation to learn more. */ export declare const CatchErrorNodeType: StaticNodeType<'catch-error', CatchErrorNodeProperties>; /** * Creates a new instance of a [[catchError]] node, which is a type of a [[NodeDefinition]] used inside a [[query]] * to indicate that a given part of the query can resolve to an error, and in that case it should be replaced with * a given fallback value. * * @example **Fallback value when branch errors** * ```javascript * import muster, { catchError, error, key, query, root, value } from '@dws/muster'; * * const app = muster({ * user: error('Some reason why user can`t be loaded'), * }); * * await app.resolve(query(root(), { * user: catchError(value('Could not load user'), { * firstName: key('firstName'), * lastName: key('lastName'), * }), * })); // === 'Could not load user' * ``` */ export declare function catchError(fallback: ErrorFallbackGenerator | NodeDefinition | NodeLike, target: KeyNodeDefinition | ChildKey): CatchErrorNodeDefinition; export declare function isCatchErrorNodeDefinition(value: NodeDefinition): value is CatchErrorNodeDefinition;