/** * `archive --doc
[--successor
]`: move an obsolete document out of the
* read path, leave a tombstone at the original path, and set the lifecycle to
* `archived`. Live claims left on the document are reported, never moved.
*/
import { mkdir, readFile, writeFile } from "node:fs/promises";
import { dirname, join } from "node:path";
import type { Document } from "../core/model.ts";
import { exists } from "../fs.ts";
import type { ClaimStore } from "../store/store.ts";
import { documentIdForPath, newDocument } from "./record.ts";
import { isLiveClaimOn } from "./supersede.ts";
function tombstone(docPath: string, successorPath?: string): string {
const redirect = successorPath
? `\nSuperseded by [\`${successorPath}\`](${successorPath}).\n`
: "\n";
return [
"# Archived",
"",
`This document (\`${docPath}\`) has been archived and moved out of the read path.`,
redirect,
].join("\n");
}
export interface ArchiveResult {
document: Document;
archivedTo: string | null;
successor?: string;
strandedClaims: string[];
dryRun: boolean;
}
export async function archiveDocument(
store: ClaimStore,
docPath: string,
successorPath?: string,
opts: { dryRun?: boolean } = {},
): Promise