import { IGearboxError } from "./errors/base.js"; import "./errors/index.js"; //#region src/model/result.d.ts /** * The success half of every refusable answer: the data the method was asked * for, behind the `ok` discriminant a caller must narrow first. **/ export interface SDKResult { ok: true; data: T; } /** * The failure half: one of the errors that method's own signature names — * see {@link IGearboxError} for what every error carries. **/ export interface SDKError { ok: false; error: E; } /** * What a method that can be refused answers with. `ok` is the discriminant, * and narrowing it settles which of the two fields is there — a caller * cannot read `data` without having ruled the failure out first. * * ```ts * const res = await sdk.opportunities.prepare.depositStrategy(position, params); * if (!res.ok) { * return showRefusal(res.error); // res.error: exactly this method's union * } * res.data; // res.data: StrategyResult * ``` * * @typeParam T - What the method answers when it can. * @typeParam E - The errors that method can refuse with. Naming them * per method is the point: the union is the list of everything a caller has * to handle, checked by the compiler. **/ export type SDKReturn = SDKResult | SDKError; /** * Best-effort result: `value` is always present (zero / empty when nothing * worked), `error` is set when it was degraded. * * Opposite of {@link SDKReturn}, which is exclusive (ok XOR error: a refusal). * Later safe-priced figures reuse this type. **/ export interface SafeValue { value: T; error?: E; } /** * Builds a {@link SafeValue}. Omits `error` when the value was not degraded. **/ export declare function safeValue(value: T, error?: E): SafeValue; /** The success half, built. */ export declare function sdkOk(data: T): SDKResult; /** The failure half, built. */ export declare function sdkErr(error: E): SDKError; //#endregion