import type { CrudRequestOptions } from '@nestjs-crud/core'; import type { CacheStrategy } from '@nestjs-crud/core/cache'; import type { FetchHelper, FetchHelperFindOneOpts } from '@nestjs-crud/core/query'; import type { ParsedRequestParams } from '@nestjs-crud/request'; /** * @internal — subject to change without semver-major. * Executes prepared Prisma arg-object queries: count, findOne, executeMany. * * ### getDelegate thunk contract * * The ctor takes `getDelegate: () => any` — a thunk, NOT a captured delegate * instance. This matches MikroORM's `getEm` pattern and protects against stale * delegate references across `$transaction` scopes. * * **Cache-wrap closures MUST call getDelegate() INSIDE the closure body** — * capturing the delegate outside the closure re-introduces the cross-scope bug. */ export interface PrismaFetchHelperConfig { /** thunk — matches MikroORM's getEm pattern; protects against stale references across $transaction scopes */ getDelegate: () => any; onNotFound: (alias: string) => void; /** Optional cache backend; resolved at request time (ctor field > CrudConfigService global). */ cacheStrategy?: CacheStrategy; /** Entity name used as cache-key prefix (required when cacheStrategy is set). */ entityName?: string; /** Optional logger threaded into withCacheErrorPolicy (FIX 2). */ logger?: { warn?: (msg: string) => void; error?: (msg: string, trace?: string) => void; [k: string]: any; }; } export declare class PrismaFetchHelper implements FetchHelper { private readonly config; private readonly logger; constructor(config: PrismaFetchHelperConfig); count(qb: any): Promise; findOneOrFail(qb: any, opts: FetchHelperFindOneOpts, parsed?: ParsedRequestParams, options?: CrudRequestOptions): Promise; executeMany(qb: any, parsed: ParsedRequestParams, options: CrudRequestOptions): Promise; /** * Lazily resolve the effective cache strategy. * Priority: ctor-injected config field > CrudConfigService global > undefined. * Called at request time so `CrudConfigService.load(...)` after app bootstrap works. */ private getResolvedStrategy; /** * Internal cache wrapper used by `findOneOrFail`. Both `executeMany` and * `findOneOrFail` derive the cache key from the SAME `buildCacheKey(entityName, parsed)` * util (D-06 — full request fingerprint). TTL sourced from `options.query.cache` * via `getEffectiveTtl` (D-10 — no hard-coded TTL fallback). * * If `parsed` or `options` is undefined (e.g. legacy callers without request * context), the wrap is skipped — fetchFn runs directly. NO 1000ms default. */ private wrapRead; /** * FIX 2 — apply `cacheErrorPolicy` from CrudConfigService.config.query.cacheErrorPolicy. * Mirrors the TypeORM/MikroORM/Drizzle helpers exactly. */ private withCacheErrorPolicy; /** * Extract the per-request TTL from `options.query.cache` (sole production source per D-10). * Returns `undefined` when the option is unset, false, or non-positive. Units = MILLISECONDS (FIX 1). */ private getEffectiveTtl; /** * Cache predicate. Requires resolved strategy + entityName + positive TTL + bypass NOT explicitly false. */ private shouldCache; /** * D-11 fail-fast: throw `CrudCacheNotConfiguredError` UNCONDITIONALLY when: * - `@Crud cache` is set (positive TTL), AND * - consumer did NOT bypass (`?cache=0` or `parsed.options.cache === false`), AND * - `cacheStrategy` is undefined. * * Matches TypeORM/MikroORM/Drizzle behavior. NO "[200, 500] adjust based on". */ private assertStrategyOrPassThrough; }