/** * Result Pattern Helpers * * Type-safe error handling without try-catch in happy path * Eliminates exceptions in normal flow and provides explicit success/failure states * * Usage: * ```typescript * const result = await storageService.uploadFile(params); * if (result.success) { * console.log(result.data.metadata); * } else { * console.error(result.error); * } * ``` */ import type { StorageResult as Result } from '@plyaz/types/storage'; /** * Create a successful result * * @param data - Success data * @returns Result object with success: true */ export declare function success(data: T): Result; /** * Create a failure result * * @param error - Error object * @returns Result object with success: false */ export declare function failure(error: E): Result; /** * Check if result is successful * Type guard for narrowing Result type * * @param result - Result to check * @returns true if result is successful */ export declare function isSuccess(result: Result): result is { success: true; data: T; }; /** * Check if result is a failure * Type guard for narrowing Result type * * @param result - Result to check * @returns true if result is a failure */ export declare function isFailure(result: Result): result is { success: false; error: E; }; /** * Unwrap result data or throw error * Use when you want to convert Result back to throwing style * * @param result - Result to unwrap * @returns Data if successful * @throws Error if failed */ export declare function unwrap(result: Result): T; /** * Unwrap result data or return default value * * @param result - Result to unwrap * @param defaultValue - Default value if failed * @returns Data if successful, defaultValue if failed */ export declare function unwrapOr(result: Result, defaultValue: T): T; /** * Map result data to a new value * Only applies function if result is successful * * @param result - Result to map * @param fn - Mapping function * @returns New result with mapped data */ export declare function map(result: Result, fn: (data: T) => U): Result; /** * Map result error to a new error * Only applies function if result is a failure * * @param result - Result to map * @param fn - Error mapping function * @returns New result with mapped error */ export declare function mapError(result: Result, fn: (error: E) => F): Result; /** * Chain async operations that return Results * FlatMap for Result (avoids Result>) * * @param result - Result to chain * @param fn - Function that returns a new Result * @returns Flattened result */ export declare function chain(result: Result, fn: (data: T) => Promise>): Promise>; /** * Combine multiple Results into a single Result with an array * All must succeed for overall success * * @param results - Array of results * @returns Result with array of data if all succeeded, first error otherwise */ export declare function combine(results: Result[]): Result; /** * Convert a Promise to a Result (catching exceptions) * Useful for wrapping third-party APIs that throw * * @param promise - Promise to convert * @returns Result (never throws) */ export declare function fromPromise(promise: Promise): Promise>; /** * Convert a throwing function to a Result-returning function * * @param fn - Function that might throw * @returns Result (never throws) */ export declare function fromThrowable(fn: () => T): Result;