/** * The shapes the HTTP API and the MCP server hand out. Both use these, so a * note looks the same to the site, the admin page and an agent. */ import type { HeldChange, Revision, StoredNote } from "./store.ts"; import type { Outcome } from "./service.ts"; export const noteView = (n: StoredNote, opts: { text?: boolean } = {}) => ({ path: n.path, type: n.type, name: n.name, slug: n.slug, title: n.title, publish: n.publish, data: n.data, body: n.body, rev: n.rev, acceptedAt: n.acceptedAt, author: n.author, ...(opts.text ? { text: n.text } : {}), }); export const summaryView = (n: StoredNote) => ({ path: n.path, type: n.type, title: n.title, slug: n.slug, publish: n.publish, acceptedAt: n.acceptedAt, }); export const revisionView = (r: Revision, opts: { text?: boolean } = {}) => ({ rev: r.rev, author: r.author, at: r.at, action: r.action, ...(opts.text ? { text: r.text } : {}), }); export const heldView = (h: HeldChange, opts: { text?: boolean } = {}) => ({ id: h.id, path: h.path, author: h.author, source: h.source, reasons: h.reasons, at: h.at, status: h.status, decidedAt: h.decidedAt, ...(opts.text ? { text: h.text } : {}), }); export const outcomeView = (o: Outcome) => { switch (o.status) { case "accepted": return { status: o.status, path: o.path, note: summaryView(o.note) }; case "held": return { status: o.status, path: o.path, held: heldView(o.held) }; default: return o; } };