/** * policy.ts * * `RetentionPolicy`, tracks registered checkpoints and decides which ones * must be pruned to satisfy the configured retention limits. * * Each retention class (`short`, `standard`, `forensic`) has independent * age, count, and size ceilings. Pruning candidates are determined in the * following order: * * 1. Age limit , any record older than `maxAgeMs` is a candidate. * 2. Count limit, oldest records beyond `maxCount` are candidates. * 3. Size limit , oldest records are candidates until total size fits. * * The actual file deletion is delegated to `SnapshotPruner`. */ import type { CheckpointRecord, Pruner, PruneOptions, PruneResult, RetentionConfig, RetentionStats } from './types.js'; /** * Default limits applied when no override is provided. * * - `short` : 1 h / 5 checkpoints / 50 MB * - `standard` : 24 h / 20 checkpoints / 200 MB * - `forensic` : 7 d / 100 checkpoints / 1 GB */ export declare const DEFAULT_RETENTION_CONFIG: RetentionConfig; /** * Manages the lifecycle of checkpoint records by enforcing per-class * retention limits (age, count, size). * * @example * ```ts * const policy = new RetentionPolicy(); * policy.register({ * id: 'cpt_01', * createdAt: Date.now(), * sizeBytes: 1024, * retentionClass: 'standard', * path: '/tmp/checkpoints/cpt_01.json', * }); * const result = await policy.prune(); * ``` */ export declare class RetentionPolicy { private readonly _config; private readonly _records; private readonly _pruner; private readonly _clock; /** * @param config - Optional partial override for any retention class limits. * Unspecified classes fall back to `DEFAULT_RETENTION_CONFIG`. * @param clock - Optional clock function returning the current time in ms. * Defaults to `Date.now`. Inject a fixed value in tests for * deterministic time-based assertions. * @param pruner - Optional pruner implementation. Defaults to `new SnapshotPruner()`. * Tests can inject an in-memory implementation for deterministic assertions. */ constructor(config?: Partial, clock?: () => number, pruner?: Pruner); /** * Register a new checkpoint for retention tracking. * * If a record with the same `id` already exists it is replaced in-place, * allowing callers to update metadata (e.g. size after write). The updated * metadata is reflected in subsequent stats and prune decisions. * * @param record - The checkpoint record to track. */ register(record: CheckpointRecord): void; /** * Unregister a checkpoint record (e.g. after it has been pruned externally). * * @param id - The checkpoint ID to remove from tracking. * @returns `true` if the record was found and removed, `false` otherwise. */ unregister(id: string): boolean; /** * Prune checkpoints that exceed retention limits. * * Evaluates each retention class independently and delegates file removal * to `SnapshotPruner`. Successfully deleted records are removed from the * internal tracking map. * * @param options - Optional prune options (e.g. `dryRun: true` to preview * what would be deleted without touching the file system). * @returns Aggregated `PruneResult` across all classes. */ prune(options?: PruneOptions): Promise; /** * Cheap in-memory check: does at least one registered record currently * violate its class's age/count/size limits and thus need pruning? * * Runs the same candidate-collection pass as `prune()` but touches no I/O * and mutates nothing, safe to call on a hot path (e.g. after every * checkpoint create) to decide whether an actual `prune()` is worth running. */ needsPrune(): boolean; /** * Return current retention statistics per class. * * Useful for surfacing storage pressure in diagnostics panels. */ getRetainedCount(): RetentionStats; /** * Return the current `RetentionConfig` in effect (defaults merged with overrides). * * Returns a deep clone so callers cannot mutate the internal configuration * through nested object references. */ getConfig(): RetentionConfig; /** * Collect records that violate any limit for their class. * * Evaluation order: age → count → size. * Records violating multiple limits are included once. */ private _collectCandidates; /** * Return all records for a given retention class, sorted oldest-first. */ private _getClassRecords; /** * Apply age, count, and size limits to a sorted list of class records. * * @param sorted - Records sorted oldest-first. * @param config - Limits for this class. * @returns Records that should be pruned. */ private _evaluateClass; } //# sourceMappingURL=policy.d.ts.map