import type { TABLE_NAMES, PruneOptions, PruneResult, TableRetentionPolicy } from '@mastra/core/storage'; import type { PgDB } from './db/index.js'; /** One table to prune, resolved from a policy + the domain's descriptor. */ export interface PruneTarget { /** Physical table name. */ table: TABLE_NAMES; /** Anchor column for the age comparison. */ column: string; /** * How the anchor column stores time, which decides how the cutoff is bound: * - `timestamp` (default): a `Date` compared against a `timestamptz` column. * - `epoch-ms`: a raw millisecond number compared against a `bigint` column * (e.g. `schedules.triggers.actual_fire_at`). */ anchorType: 'timestamp' | 'epoch-ms'; /** Retention policy (maxAge + optional batchSize). */ policy: TableRetentionPolicy; } /** * Convert a policy's `maxAge` into a cutoff bound matching the anchor's storage * type: a `Date` for `timestamptz` columns (pg compares timezone-aware), or a * raw millisecond number for `bigint` epoch-ms columns. */ export declare function cutoffFor(policy: TableRetentionPolicy, anchorType: 'timestamp' | 'epoch-ms', now?: number): number | Date; /** * Run the bounded/cancellable batched-delete loop for a single logical target, * delegating the actual delete of up to `limit` rows to `deleteBatch`. Returns * `{ deleted, done }`; `done: false` means the loop stopped on a bound or the * abort signal and eligible rows may remain. */ export declare function runBatchedDelete({ deleteBatch, batchSize, options, }: { deleteBatch: (limit: number) => Promise; batchSize: number; options?: PruneOptions; }): Promise<{ deleted: number; done: boolean; }>; /** * Runs the bounded, batched, cancellable delete loop for a set of tables in the * given order (callers pass children before parents for cascade-safe pruning), * and returns one {@link PruneResult} per table. * * The loop: * - deletes in chunks of `batchSize` (default 1000), each its own statement; * - stops a table's loop when a batch deletes fewer rows than requested (drained), * or when `maxBatches`/`maxRows` is hit, or the `signal` aborts — the latter * three leave `done: false` so the caller can resume; * - pauses `pauseMs` between batches when set, to avoid starving live traffic. * * `prune()` only deletes rows; it never reclaims disk. PostgreSQL reuses freed * space (dead tuples) via autovacuum on subsequent writes, so tables stop * growing. Returning disk to the OS (e.g. `VACUUM FULL`) is left to the operator. */ export declare function runPrune({ db, domain, targets, options, }: { db: PgDB; domain: string; targets: PruneTarget[]; options?: PruneOptions; }): Promise; /** * Resolve a domain's `{ tableKey: policy }` map plus its descriptor into an * ordered list of {@link PruneTarget}s. `order` lists table keys children-first * so cascade-dependent rows are removed before their parents. Table keys not in * `policies` are skipped (unset = keep forever). */ export declare function resolveTargets({ policies, descriptor, order, }: { policies: Record; descriptor: Record; order: string[]; }): PruneTarget[]; //# sourceMappingURL=retention.d.ts.map