Create a schema-backed record type, seed records, patch metadata, update a page body, and inspect the audit trail. A space with a deal-memo template, conforming deal records, a safe body update, and metadata history you can inspect.

All guides
View source

Write back

Create a schema-backed record type, seed records, patch metadata, update a page body, and inspect the audit trail. A space with a deal-memo template, conforming deal records, a safe body update, and metadata history you can inspect.

Read the code

Before you run it

Use a Coconut deployment that accepts writes.
Set COCO_SPACE and COCO_TEMPLATE, or use the demo defaults.
Run this first when the target space is empty.

What it does

Upsert a deal-memo template with a metadata schema.
Create records from the template so each page is stamped with its type.
Patch metadata with set and appendUnique without rewriting the page body.
Update the memo body with optimistic concurrency.
Read the per-key metadata history to see who changed what.

Core SDK calls

These are intentionally smaller than the source files. They show the backend shape to copy first.

Create a record type and record

await coco.pages.upsert("demo/templates/deal-memo", {
  title: "Deal memo",
  frontmatter: {
    defaultPathPrefix: "deals",
    metadataSchema: {
      fields: [
        { key: "stage", type: "select", options: ["sourcing", "diligence", "closed"] },
        { key: "conviction-score", type: "number", min: 0, max: 1 },
      ],
    },
  },
  content: "# {Company}\n\n## Thesis\n_Why this could matter._",
});

await coco.records.create("demo", "deal-memo", {
  path: "deals/acme",
  title: "Acme Corp",
  metadata: { stage: "diligence", "conviction-score": 0.82 },
});

Patch metadata and update content

await coco.pages.patchMetadata("demo/deals/acme", {
  set: { stage: "diligence", "last-reviewed": "2026-09-04" },
  appendUnique: { sources: ["https://news.example/acme-series-b"] },
});

const memo = await coco.pages.get("demo/deals/acme");
await coco.pages.update(memo.path, {
  content: `${memo.content}\n\n- Management call folded in.`,
  expectedVersion: memo.version,
  note: "Diligence log entry",
});

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 put demo/deals/acme --title 'Acme' --template deal-memo --metadata stage=sourcing < memo.md
coco meta patch demo/deals/acme --set stage=diligence --append-unique sources=https://news.example/acme
coco meta history demo/deals/acme