/** * Process-wide registration + dispatch for the relation-cache error handler * (`onRelationsCacheError`, ADR-009). Holds the host-supplied default handler and * reports every runtime cache-infra/serialization failure to the effective * handler (per-model → process-wide default → no-op), guarded and never awaited * so a reporter can neither throw into nor delay a load/write. * * Defaults to a **no-op** so the package stays dependency-neutral — it never * imports a logger; the host wires `onRelationsCacheError` to its own logger / * Sentry / metrics (or nothing). * * @module @nhtio/lucid-resourceful/private/utils/cache_error_handler */ import type { LucidModel } from '@adonisjs/lucid/types/model'; import type { E_RELATION_CACHE_OPERATION_FAILED } from "../../errors"; /** * Host-supplied observer invoked when a runtime relation-cache operation fails * (ADR-009). Observe-only: its return value is ignored — it cannot change the * fallback control flow — and a throw from it is swallowed. * * @public */ export type RelationsCacheErrorHandler = (error: E_RELATION_CACHE_OPERATION_FAILED) => void; /** * Registers (or clears) the process-wide default relation-cache error handler. * * The host application calls this once at boot. Passing `null` clears the * default (used by tests). Models without their own `onRelationsCacheError` fall * back to this handler, and absent a default the built-in best-effort log is * used — so registering nothing is a valid (logged) configuration. * * @param handler - The default handler, or `null` to clear it. * @public */ export declare const setDefaultOnRelationsCacheError: (handler: RelationsCacheErrorHandler | null) => void; /** * Reads the currently-registered default handler. Exposed for completeness; * prefer {@link reportRelationCacheError}. * * @returns The default handler, or `null` when none is registered. * @internal */ export declare const getDefaultOnRelationsCacheError: () => RelationsCacheErrorHandler | null; /** * Clears the module-scoped default handler. Test-only hook: hosts must not call * this at runtime. Mirrors `resetRelationCacheTargets`. * * @public */ export declare const resetDefaultOnRelationsCacheError: () => void; /** * Reports a runtime relation-cache failure to the effective handler (ADR-009). * * Resolves the handler by precedence — the model's own * `$resourcefulOnRelationsCacheError` → the process-wide default → no-op — then * invokes it SYNCHRONOUSLY inside a guard (a throwing handler is swallowed) and * does NOT await it (a returned promise is fire-and-forget), so a slow or failing * reporter can neither delay nor break the load. When no handler resolves the * failure is dropped (the package never logs on its own). The CALLER performs the * actual fallback (DB load / skip caching / continue the write); this function * only observes. * * @param model - The model whose handler should be consulted. * @param error - The typed relation-cache operational failure to report. */ export declare const reportRelationCacheError: (model: LucidModel, error: E_RELATION_CACHE_OPERATION_FAILED) => void;