import { type Database } from "../../data/database.js"; export declare const SHORT_ID_MIGRATION_ID = "core-short-ids-v1"; export interface ShortIdMapping { members: Map; rooms: Map; } export interface RenameOp { from: string; to: string; } export declare function assignShortIds(memberIds: readonly string[], roomIds: readonly string[], generate?: { member?: () => string; room?: () => string; }): ShortIdMapping; /** * Pure: compute the renamed form of a single path segment, or null to leave it. * Only ids present in the mapping are touched, so legacy `rm_` records and * unrelated names never match. */ export declare function renameSegment(name: string, mapping: ShortIdMapping): string | null; /** * Plan every filesystem rename under the surface roots. Post-order: a directory's * own rename is recorded after its children's, so executing ops in order keeps * every recorded path valid until the moment it is applied. */ export declare function planFilesystemRenames(root: string, mapping: ShortIdMapping): RenameOp[]; /** Fold every segment of a relative path through the mapping (ancestor renames included). * Positionally aligned with the planner: the member segment directly under * `rooms//memory/members/` keeps its old form (archive semantics, design §3.3); * deeper segments fold as usual (`mem_.jsonl` file names included). */ export declare function foldRelPath(rel: string, mapping: ShortIdMapping): string; export interface RenameApplyResult { done: number; skipped: number; failures: string[]; } export declare function applyRenameOps(root: string, ops: readonly RenameOp[], options?: { fold?: (rel: string) => string; }): RenameApplyResult; export declare function shortIdJournalPath(root: string): string; export interface ShortIdJournal { version: 1; migration: typeof SHORT_ID_MIGRATION_ID; createdAt: number; ops: RenameOp[]; } /** Atomic write (temp + rename) so a crash never leaves a torn journal. */ export declare function writeShortIdJournal(root: string, ops: readonly RenameOp[]): string; export declare function readShortIdJournal(root: string): ShortIdJournal | null; export declare function clearShortIdJournal(root: string): void; /** * Startup replay: finish any renames a previously interrupted run left pending. * Runs before the other upgrade steps so every later step sees consistent names. * * `mappingProvider` resolves the id mapping when available; it is only needed for * nested ops whose parent was already renamed (both recorded paths point under * the old parent name) — the op is then recognized via its folded final location. */ export declare function replayShortIdJournal(root: string, mappingProvider?: () => ShortIdMapping | null): { status: "none"; } | { status: "replayed"; done: number; skipped: number; } | { status: "failed"; failures: string[]; }; /** * Earliest-possible replay, before any startup verifier inspects the filesystem: * the DB rewrite commits before the filesystem renames, so a crash between them * leaves new ids in SQL against old names on disk — `verifyActiveMemberAssets` * would reject the store before the ordinary post-upgrade steps could run. * Reads the mapping straight from the on-disk database (read-only). */ export declare function replayShortIdJournalFromDisk(root: string): { status: "none"; } | { status: "stale"; } | { status: "replayed"; done: number; skipped: number; } | { status: "failed"; failures: string[]; }; export declare function mapCompositeString(value: string, mapping: ShortIdMapping): string; interface JsonTransformResult { changed: boolean; text: string; parseFailure: boolean; leftovers: number; } /** * Structured replacement on known keys only — senderMemberId / mentionMemberIds / * targets' actorKey·memberId / scope strings / paths. Content fields are never * rewritten; strings that still carry old ids are counted, not touched. */ export declare function transformJsonText(text: string, mapping: ShortIdMapping): JsonTransformResult; export declare function loadShortIdMapping(db: Database): ShortIdMapping | null; /** Exclusion zones from the migration design: their disk names keep the old ids. */ export declare function isExcludedRelPath(rel: string): boolean; export interface ShortIdMigrationReport { status: "already-done" | "migrated"; members: number; rooms: number; filesRenamed: number; jsonParseFailures: number; } /** * The one-shot migration: plan + journal the filesystem renames, then the * single-transaction DB rewrite (mapping fill, root ids, column surface, ledgers, * trigger round-trip, FK + residue self-check), then apply the renames, then the * archive mirror and done flag. Journal-before-commit makes the crash windows * self-healing: a journal without a committed mapping is stale and gets cleared. * Any failure throws — startup must not continue on a half-migrated store. */ export declare function migrateShortIds(root: string, db: Database): ShortIdMigrationReport; export {}; //# sourceMappingURL=ids.d.ts.map