/** * Result wrapper type for API responses that provides a standardized way to handle both successful and failed operations. * This pattern ensures consistent error handling across the entire API framework and makes error states explicit. * * @template VO - The type of data contained in a successful result */ export type Result = SuccessResult | FailedResult; /** * Represents a successful API operation result containing the response data. * * @template D - The type of the successful response data */ export interface SuccessResult { /** Indicates this is a successful result */ success: true; /** The actual response data returned by the API */ data: D; } /** * Represents a failed API operation result containing error information. * Used when an API call encounters validation errors, server errors, or other failures. */ export interface FailedResult { /** Indicates this is a failed result */ success: false; /** Error code (HTTP status code or custom application error code) */ code: number; /** Optional human-readable error message */ msg?: string; } /** * Creates a successful result wrapper with the given data. * Used internally by the framework to wrap successful API responses. * * @template D - The type of the response data * @param data - The successful response data to wrap * @returns A SuccessResult containing the provided data * * @example * ```typescript * const userResult = ofSuccess({ id: "123", name: "John Doe" }) * // Returns: { success: true, data: { id: "123", name: "John Doe" } } * ``` */ export declare function ofSuccess(data: D): Result; /** * Converts various error types into a standardized failed result. * Handles APIError instances, standard Error objects, string messages, and unknown error types. * This function ensures all errors are properly normalized into the Result format. * * @template D - The type that would have been returned on success * @param error - The error to convert (can be APIError, Error, string, or unknown) * @returns A FailedResult with appropriate error code and message * * @example * ```typescript * // With APIError * const apiError = new APIError(404, 'User not found') * const result = ofError(apiError) * // Returns: { success: false, code: 404, msg: 'User not found' } * * // With standard Error * const error = new Error('Something went wrong') * const result = ofError(error) * // Returns: { success: false, code: 1, msg: 'Something went wrong' } * * // With string * const result = ofError('Invalid input') * // Returns: { success: false, code: 1, msg: 'Invalid input' } * ``` */ export declare function ofError(error: unknown): Result; //# sourceMappingURL=Result.d.ts.map