Extensions
Adding one
Section titled “Adding one”npx @tapedb/cli add @tapedb/cmsnpx @tapedb/cli migrate dev --name cmsnpx @tapedb/cli devadd installs the package, lists it in package.json and runs its set-up:
"tapedb": { "extensions": ["@tapedb/cms"] }The CMS’s set-up writes a content file, adds itself to the schema and the Worker, and adds an R2 bucket, the Images binding and a cron trigger to wrangler.jsonc, which tapedb deploy provisions:
export default schema({ /* your models */ }, { extensions: [content] });
// worker.tsconst tapedb = defineTapeDB({ schema, migrations, extensions: [cms({ content })] });A second add changes nothing. Code the CLI cannot edit with certainty, such as options built in another file, it leaves alone and says what to add by hand. tapedb init --cms does the same in a new project before its first migration.
From then on tapedb dev and tapedb deploy run the extension’s build first (the CMS bundles the app’s tapedb.cms.tsx, as they do tapedb.auth.tsx), tapedb dev runs it again when a file it names changes, and its commands run as tapedb <extension> <command>.
The CMS has its own section: CMS.
The three halves
Section titled “The three halves”| Where | What it adds | Declared with |
|---|---|---|
| Schema | models beside the app’s, and file rules under one path prefix | schema(models, { extensions }) |
| Worker | routes, cron work, and a handler for change events | defineTapeDB({ extensions }) |
| CLI | set-up, a build step, commands | <package>/tapedb, default-exporting defineExtension({...}) |
An extension’s models join the schema, so the client, migrations and access rules see one schema, and its type includes them. A model name it shares with the app is refused. Its file rules cover only the paths under its prefix: a file takes the rule of the longest prefix that defines the action, then the app’s own files rule, then the default.
Change events without a webhook
Section titled “Change events without a webhook”An extension’s changes handler receives the same events a webhook does, through the same outbox: captured inside the write’s transaction, handed over after the commit in sequence order, and retried with backoff while later events wait. The difference is the last step. Instead of a signed POST, the event is a function call inside the workspace’s Durable Object, so there is no URL, secret or public address to configure, and nothing outside the Worker can send one. GET /engine/workspaces/:id/webhooks lists it as the endpoint tapedb-extension:<name>, with the same counts and dead letters.
const search: TapeDBExtension = { name: "search", changes: { models: ["post"], async handle(event, env) { await env.SEARCH.upsert(event.row); // a throw retries it }, }, async fetch(request, env, ctx, tapedb) { if (new URL(request.url).pathname !== "/search") return null; // not ours return Response.json(await env.SEARCH.query(new URL(request.url).searchParams.get("q"))); },};fetch sees every request TapeDB does not answer itself, extensions in order; null passes it on. scheduled runs on the Worker’s cron triggers. Each gets tapedb: fetch into the deployment in process, signClaim to act through the engine routes under their rules, and verifyClaim to check a caller’s claim.
Reference
Section titled “Reference”The full contract, with every member and the CLI’s project helpers, is in API.md; the types are on @tapedb/tapedb/extension and @tapedb/tapedb/worker.