import { type EnclaveKey } from '../../kernel/enclave/index.js'; import type { NoydbStore } from '../../kernel/types.js'; import type { LedgerStore } from '../../with-commit/history/ledger/store.js'; import type { Collection } from '../../kernel/collection.js'; import type { PeriodsStrategy } from './strategy.js'; import { type PeriodRecord, type TargetPurgeCount, type ClosePeriodOptions, type OpenPeriodOptions } from './periods.js'; /** Everything the moving period methods touched on the vault's `this.*`. */ export interface VaultPeriodsDeps { /** Resolved periods strategy (NO_PERIODS when not configured). */ readonly strategy: PeriodsStrategy; /** The ciphertext store. */ readonly adapter: NoydbStore; /** Vault namespace name. */ readonly vault: string; /** Whether records are encrypted (vs debug-plaintext). */ readonly encrypted: boolean; /** The invoking keyring's user id (read fresh per call). */ userId(): string; /** Per-collection DEK resolver (bound `vault.getDEK`). */ getDEK(collection: string): Promise; /** The vault's ledger store, or null when history is off. */ getLedgerOrNull(): LedgerStore | null; /** Collection accessor (used by `openPeriod`'s carry-forward writes). */ collection(name: string): Collection; /** #604: physically purge delete markers with `_ts < before`. Bound to `vault._purgeDeleteMarkers`. */ purgeDeleteMarkers(before: string): Promise; /** #613: relocate a closed period's in-window records hot → cold. Bound to `vault._archiveClosedPeriod`. */ archiveRecords(before: string): Promise; /** #615: sweep delete markers off the vault's push-only sync targets. Bound to `vault._purgePeriodTargets`. */ purgeTargets(before: string): Promise; } export declare class VaultPeriods { private readonly deps; /** * Loaded period records, lazily populated on first close/open/list/get/guard * and kept in sync by the write paths. `null` until first touched — the * write-guard fast-path avoids a full adapter scan for vaults that never use * periods. */ private periodCache; constructor(deps: VaultPeriodsDeps); closePeriod(options: ClosePeriodOptions): Promise; openPeriod>>(options: OpenPeriodOptions): Promise; /** * Freeze a closed period: physically purges delete markers whose `_ts` * falls inside the period's window (#604) and records the fact in a * companion `_period_freezes/` record. NEVER mutates the * hash-chained `_periods/` record's stored bytes — `frozenAt` / * `frozenBy` / `purgedMarkerCount` are merged into `PeriodRecord`s on * read only. Idempotent: a second call is a no-op that returns the * same merged record without re-purging or re-appending a ledger entry. */ freezePeriod(name: string): Promise; /** * Archive a closed period (#613): physically relocates its in-window * records (those with `_ts < periodExclusiveUpperBound(endDate)`) from the * hot store to the configured cold tier via `archiveRecords`, and records * the fact in a companion `_period_archives/` record. NEVER mutates * the hash-chained `_periods/` record. Non-destructive (reads fall * through to cold) and idempotent: a second call is a no-op returning the * same merged record. */ archivePeriod(name: string): Promise; /** * Target-purge a closed period (#615): sweeps delete markers off the vault's * PUSH-ONLY sync targets (`backup`/`archive`) via `purgeTargets`, recording a * companion `_period_target_purges/` record. `sync-peer` targets are * skipped (resurrection risk). NEVER mutates the chained `_periods/` * record. Requires the period be frozen first (closed → frozen → target-purged). * Idempotent once run; with no push-only targets it writes no companion and * is re-runnable. */ purgePeriodTargets(name: string): Promise; /** Merge target-purge companion fields into a fresh `PeriodRecord` copy — never mutates `periodCache`. */ private mergeTargetPurge; /** Merge archive companion fields into a fresh `PeriodRecord` copy — never mutates `periodCache`. */ private mergeArchive; /** Merge freeze companion fields into a fresh `PeriodRecord` copy — never mutates `periodCache`. */ private mergeFreeze; /** Return every closed / opened period in `closedAt` order, merged with any freeze + archive companions. */ listPeriods(): Promise; /** Look up a single period by name, merged with its freeze + archive + target-purge companions if any. Returns `null` if not found. */ getPeriod(name: string): Promise; /** Called by the gate bus before put/delete. */ assertTsWritable(existing: { ts: string | null; record: Record | null; } | null, incoming: Record | null): Promise; private loadPeriodsCache; /** Generic reserved-collection writer — serves `_periods` and `_period_freezes` alike. */ private writeReserved; /** Generic reserved-collection reader — serves `_period_freezes` companion reads. */ private readReserved; private decryptPeriodRecord; }