import { ConstructiveError } from './error'; import { registry } from './registry'; import type { ErrorClass, ErrorContext, ErrorDefinition } from './types'; /** * The callable produced for a registry entry. Codes with no context params can * be called with no arguments; codes with params require a matching context. * The `[keyof C]` tuple wrapper prevents `never` from distributing. */ export type ErrorFactory = [keyof C] extends [never] ? (context?: Record, overrideMessage?: string) => ConstructiveError : (context: C, overrideMessage?: string) => ConstructiveError; export type ErrorsApi = { [K in keyof R]: R[K] extends { __context: (context: infer C) => void; } ? C extends ErrorContext ? ErrorFactory : never : never; }; /** Build a throwable factory for a single definition. */ export declare function makeErrorFromDefinition(def: ErrorDefinition): ErrorFactory; /** Build the `errors.*` factory object from a registry. */ export declare function buildErrors void; }>>(reg: R): ErrorsApi; /** * Low-level factory helper for defining an error inline (the pattern the former * pgpm `error-factory` exposed). Prefer registering codes in the registry, but * this remains available for ad-hoc / dynamically-coded errors. */ export declare function makeError(code: string, messageFn: (context: C) => string, httpCode?: number, errorClass?: ErrorClass): (context: C, overrideMessage?: string) => ConstructiveError; /** * The canonical `errors.*` factory. * * Curated codes are strongly typed (`errors.MODULE_NOT_FOUND({ name })`); every * other constructive-db code is available via a generic factory through the * index signature (`errors.ACCOUNT_EXISTS()`), backed by the generated * registry. Curated entries override generated ones on conflict. */ export declare const errors: ErrorsApi & Record>;