/** * Result — the canonical error channel for API loaders. * * The public loaders in this package historically collapsed a failed fetch * to an empty value (`[]`, `{ performers: [], showPerformers: false }`, or * `null`), which is indistinguishable from a genuinely empty result. A buyer * hitting a live event during a transient endpoint blip then sees a dead * "No tickets available" button with no retry; a failed calendar month * renders dark, so the venue looks like it has nothing on. * * `Result` gives loaders a typed error channel so callers can tell * "the request failed" apart from "there is genuinely nothing here", and * offer a retry instead of silently degrading. Loaders expose a `*Result` * variant returning this; the array/object-returning public functions stay * as thin fail-open adapters over that variant (single source of truth for * the fetch + validation logic). * * Not to be confused with `ApiResponse` (types.ts) — that is the write-path * HTTP envelope returned by `apiPost`/`apiGet`/etc. (`{ success, data?, error?, * statusCode? }`, discriminated on `.success`). `Result` is the read-path * loader channel, discriminated on `.ok`. They are deliberately separate: * `ApiResponse` carries transport metadata, `Result` carries only "loaded vs * failed". Check `.ok` on a Result, `.success` on an ApiResponse — never mix. */ export type Result = { ok: true; data: T; } | { ok: false; error: string; notFound?: boolean; }; /** Wrap a successful value. */ export declare function ok(data: T): Result; /** * Wrap a failure with a short, stable error code (used for i18n/render). * * This is a TRANSIENT failure by default (`notFound` is unset) — the request * couldn't complete (network, timeout, 5xx). Loaders that gate an SSR 404 on a * Result must treat a plain `err(...)` as retryable (503), not "gone" (404), so * a backend blip never renders a permanent-looking 404 to a buyer or crawler. */ export declare function err(error: string): Result; /** * Wrap a genuine "this resource does not exist" failure (upstream 404). * * Distinct from `err(...)`: only this warrants an SSR 404. A transient upstream * failure must NOT collapse to `errNotFound` — that is exactly the bug this * channel exists to prevent (a fetch blip becoming a permanent 404). */ export declare function errNotFound(error: string): Result; /** Narrowing guard — true when the result carries data. */ export declare function isOk(result: Result): result is { ok: true; data: T; }; /** * Narrowing guard — true when the result is a failure (transient OR not-found). * * This package typechecks with `strictNullChecks` off, where the ELSE flow of a * discriminated union does NOT narrow (`if (r.ok) {…}` narrows the positive * branch, but the fall-through keeps the full union). Consumers that need the * failure branch's `error`/`notFound` must narrow POSITIVELY through this guard * rather than relying on `!r.ok` control flow. */ export declare function isErr(result: Result): result is { ok: false; error: string; notFound?: boolean; }; /** * Collapse a Result to its data, substituting `fallback` on failure. * * This is the fail-open bridge the legacy array/object-returning loaders use * so existing callers keep their current "degrade to empty" behaviour until * they adopt the Result variant and render an error/retry state. */ export declare function unwrapOr(result: Result, fallback: T): T;