/** * The raw layer's result adapter. * * The generated `client/sdk.gen.ts` functions return hey-api's `{ data, error, request, * response }` envelope and are driven by two orthogonal switches (`throwOnError` and * `responseStyle`). {@link wrapRaw} collapses that onto the ergonomic client's contract: a * `{ data, error }` result by default (with {@link NeonErrorUnion} on the error * channel), or the bare resource when you pass `throwOnError: true`. `responseStyle` is * removed from the public raw surface — `throwOnError` is the only switch and the return * type always tracks it. * * The one difference from the ergonomic `NeonResult` is that the raw result also exposes the * underlying `response`/`request`, so power users (and the neonctl CLI) can read HTTP status * and headers without dropping to the low-level client. */ import { type NeonErrorUnion } from "./errors.js"; /** * Structural shape of any generated raw function: generic over `throwOnError`, resolving to * hey-api's envelope. The `any`s live only inside this adapter type so the generated * functions (each with their own precise option/response types) remain assignable; the * public {@link wrapRaw} overloads recover full type safety per function. */ export type AnyRawFn = (options: any) => Promise; /** Extract the success arm of a discriminated fields envelope. */ type SuccessArm = R extends { error: undefined | null; } ? R : never; /** * The success payload of a generated raw function — derived from its default (non-throw, * fields) return type, so it stays correct as the client is regenerated. */ export type RawData = SuccessArm>> extends { data: infer D; } ? D : never; /** The call options for a wrapped raw function, minus the removed hey-api switches. */ export type RawOptions = Omit[0]>, "throwOnError" | "responseStyle">; /** * The non-throwing result of a wrapped raw call: the ergonomic `{ data, error }` union * ({@link NeonErrorUnion} on the error channel), plus the underlying `response`/`request` * for HTTP status and headers. */ export type RawResult = { data: T; error: undefined; response?: Response; request?: Request; } | { data: undefined; error: NeonErrorUnion; response?: Response; request?: Request; }; /** * Wrap a generated raw function so it speaks the ergonomic result contract. * * @example * ```ts * import { getProject } from "@neon/sdk/raw"; * * const { data, error } = await getProject({ client, path: { project_id } }); * // or, throwing: * const { project } = await getProject({ client, path: { project_id }, throwOnError: true }); * ``` */ export declare function wrapRaw(fn: F & AnyRawFn): { (options: RawOptions & { throwOnError: true; }): Promise>; (options: RawOptions & { throwOnError?: false; }): Promise>>; }; export {}; //# sourceMappingURL=raw-wrap.d.ts.map