/** * `FaultCode` is the stable, machine-readable discriminant that the server's * operation pipeline attaches to every fault. Transport adapters serialize it * onto the wire so clients can branch on the failure programmatically rather * than string-matching a human message: * * - REST operation routes: HTTP status plus `{ error: string }` for declared * faults, with `EngineFailure` masked to `"Internal server error"`. * - JSON-RPC: `error.data.weftCode` plus `error.data.httpStatus` (see * `fault-to-json-rpc.ts`). * * The type lives in `core` — not `server` — because both the server (which * produces faults) and the client (which consumes them off the wire) need it, * and the client must not import from `server`. The server re-exports it from * `operation-fault.ts` so its existing call sites are unaffected. * * `FAULT_CODE_TO_FAILURE_CATEGORY` is the single source of truth for mapping a * wire fault code onto the coarser {@link FailureCategory} execution taxonomy. * The category is a derived convenience: it is **not** carried on the wire, so * a client computes it from `faultCode` rather than reading it from the body. */ import type { FailureCategory } from './types/identity.ts'; /** * Stable fault code names. The full vocabulary is closed for v1; new codes can * be added additively, and the `satisfies` map below forces every new code to * declare its failure category at compile time. * * See `documentation/reference/api-errors.md#faultcode` for the REST HTTP * status and JSON-RPC error-data mappings for every public fault code. * * @example * ```ts * import { HttpClientError, type FaultCode } from '@lostgradient/weft'; * * function describe(error: HttpClientError): string { * const code: FaultCode | undefined = error.faultCode; * return code === 'NotFound' ? 'missing resource' : (code ?? 'unknown'); * } * void describe; * ``` */ export type FaultCode = 'Unauthorized' | 'Forbidden' | 'NotFound' | 'Conflict' | 'Unprocessable' | 'Timeout' | 'PayloadTooLarge' | 'NotImplemented' | 'UnsupportedTransport' | 'SubscriptionOverflow' | 'InvalidParams' | 'MethodNotFound' | 'EngineFailure'; /** * Maps each wire {@link FaultCode} onto a {@link FailureCategory}. * * There is deliberately no `cancellation` entry: cancellation never crosses * the REST fault wire (HTTP has no fault code for an aborted request), so no * fault code can derive that category. * * Declared with `satisfies` so adding a future `FaultCode` is a compile error * until it is mapped here. * * @example * ```ts * import { FAULT_CODE_TO_FAILURE_CATEGORY } from '@lostgradient/weft'; * * FAULT_CODE_TO_FAILURE_CATEGORY.Timeout; // 'timeout' * ``` */ export declare const FAULT_CODE_TO_FAILURE_CATEGORY: Readonly<{ readonly Unauthorized: "application"; readonly Forbidden: "application"; readonly NotFound: "application"; readonly Conflict: "application"; readonly Unprocessable: "application"; readonly InvalidParams: "application"; readonly MethodNotFound: "application"; readonly Timeout: "timeout"; readonly PayloadTooLarge: "resource"; readonly SubscriptionOverflow: "resource"; readonly NotImplemented: "system"; readonly UnsupportedTransport: "system"; readonly EngineFailure: "system"; }>; /** * Type guard: narrows an unknown wire value to a known {@link FaultCode}. * * @example * ```ts * import { isFaultCode } from '@lostgradient/weft'; * * isFaultCode('NotFound'); // true * isFaultCode('teapot'); // false * ``` */ export declare function isFaultCode(value: unknown): value is FaultCode; /** * Returns the {@link FailureCategory} a given {@link FaultCode} belongs to. * * @example * ```ts * import { failureCategoryForFaultCode } from '@lostgradient/weft'; * * failureCategoryForFaultCode('Timeout'); // 'timeout' * failureCategoryForFaultCode('EngineFailure'); // 'system' * ``` */ export declare function failureCategoryForFaultCode(code: FaultCode): FailureCategory;