/** * Result type utilities for adapter operations * * Enforces "never throws" invariant - all adapter functions return Result. */ import type { AdapterError, AdapterErrorCode } from './types.js'; /** * Result type for adapter operations * * All adapter parsing/validation functions should return this type * instead of throwing exceptions. This makes error handling explicit * and predictable. * * @example * function parseEvent(input: unknown): Result { * if (!input) { * return adapterErr('input is required', 'missing_required_field'); * } * return ok({ ... }); * } */ export type Result = { ok: true; value: T; } | { ok: false; error: E; }; /** * Create a success result */ export declare function ok(value: T): Result; /** * Create a generic error result */ export declare function err(error: E): Result; /** * Create an adapter error result (convenience helper) * * @param message - Human-readable error message * @param code - Machine-readable error code * @param field - Optional field name that caused the error */ export declare function adapterErr(message: string, code: AdapterErrorCode, field?: string): Result; /** * Check if result is ok (type guard) */ export declare function isOk(result: Result): result is { ok: true; value: T; }; /** * Check if result is error (type guard) */ export declare function isErr(result: Result): result is { ok: false; error: E; }; /** * Map over a successful result * * @example * const result = ok(5); * const doubled = map(result, x => x * 2); // ok(10) */ export declare function map(result: Result, fn: (value: T) => U): Result; /** * Map over an error result * * @example * const result = err({ message: 'oops' }); * const mapped = mapErr(result, e => ({ ...e, prefix: 'Error: ' })); */ export declare function mapErr(result: Result, fn: (error: E) => F): Result; /** * Chain results (flatMap/bind) * * @example * const parseNumber = (s: string): Result => { * const n = parseInt(s); * return isNaN(n) ? err('not a number') : ok(n); * }; * * const result = chain(ok('42'), parseNumber); // ok(42) */ export declare function chain(result: Result, fn: (value: T) => Result): Result; /** * Unwrap a result, throwing if it's an error * * Use sparingly - prefer explicit error handling. * * @throws The error value if result is an error */ export declare function unwrap(result: Result): T; /** * Unwrap a result with a default value for errors */ export declare function unwrapOr(result: Result, defaultValue: T): T; //# sourceMappingURL=result.d.ts.map