Attribute current page lines to revisions, merge page and metadata history, then roll back and forward without losing history. A git-blame-style view of a page body, one combined timeline, and proof that rollback is another revision.
View source
Blame
Attribute current page lines to revisions, merge page and metadata history, then roll back and forward without losing history. A git-blame-style view of a page body, one combined timeline, and proof that rollback is another revision.
Read the codeBefore you run it
Run Write back first, preferably more than once, to give the memo history.
Set COCO_PAGE when you want to inspect a page other than demo/deals/acme.
Use a credential that can read versions and create restore revisions.
What it does
Read every version of the target page from oldest to newest.
Carry line attribution forward with a small line diff.
Print the current body with revision, author, actor type, date, and note.
Interleave page revisions with metadata history.
Promote an old version to latest, then promote the previous latest again.
Core SDK calls
These are intentionally smaller than the source files. They show the backend shape to copy first.
Read versions for attribution
const PAGE = process.env.COCO_PAGE ?? "demo/deals/acme";
const history = await coco.pages.versions(PAGE);
const versions = [...history.items].sort(
(left, right) => left.version - right.version,
);
const bodies = await Promise.all(
versions.map(async (revision) => {
const page = await coco.pages.get(PAGE, { version: revision.version });
return [revision.version, page.content.split("\n")] as const;
}),
);Timeline and rollback
const metadata = await coco.pages.metadataHistory(PAGE, { limit: 50 });
const first = versions[0].version;
const before = history.currentVersion;
await coco.pages.makeLatest(PAGE, first);
await coco.pages.makeLatest(PAGE, before);CLI companion
Use the CLI to inspect or exercise the same backend surface from a terminal while your app code uses the SDK.
COCO_PAGE=demo/deals/acme pnpm example:blame
coco page versions demo/deals/acme
coco meta history demo/deals/acme
coco page restore demo/deals/acme 1