Collections and datasets

Document Collections (collection.yaml)

Put collection.yaml in a folder to make it a document Collection. fields is a YAML mapping keyed by field name, not a list. select and multi-select options are plain strings:

version: 1
name: Kyoto Activities
fields:
  Day:
    type: number
  Status:
    type: select
    options:
      - Idea
      - Booked
      - Done
  Cost:
    type: number

Supported field types: text, number, checkbox, date, select, multi-select, person, relation, url, button.

Create records with dohc_create_record (pass collectionPath, name, optional fields). Update fields with dohc_set_record_fields (recordPath, fields). Query records with dohc_query_collection.

Transactional Collections (dataset.json)

Every transactional Collection is defined by dataset.json, a SQLite schema (schema.sql), and operations source (operations.js or backend.ts).

Choosing between create, prepare + approve, and app stage

Exact dataset.json rules

Every violation fails validation (for full slug-based formatVersion: 2 details, see docs/reference/app-kit.md):

Custom operations (backend.ts / operations.js)

Operations run synchronously inside an isolated QuickJS sandbox with no import, require, network, or filesystem access. Assign functions to globalThis.operations:

globalThis.operations = {
  bookSeat(ctx, input) {
    const seats = Number(input?.seats ?? 1);
    if (!Number.isInteger(seats) || seats < 1) {
      ctx.refuse("invalid_seats", "Choose at least 1 seat.");
    }
    const taken = Number(ctx.db.query("SELECT COALESCE(SUM(seats), 0) AS n FROM bookings")[0]?.n ?? 0);
    if (taken + seats > 8) {
      ctx.refuse("workshop_full", "All 8 seats are taken.");
    }
    ctx.db.execute(
      "INSERT INTO bookings(id, name, seats) VALUES(?, ?, ?)",
      [ctx.requestId, String(input?.name ?? ""), seats],
    );
    return { id: ctx.requestId, seats };
  },
};

dohc_dataset action cheat sheet

Pass { request: { action, ... } } to dohc_dataset. Through MCP, leave out workspaceId and dohc fills in the workspace the server serves. expectedDatasetId (the datasetId from describe) refuses a request when the path now names another Collection.

ActionRequired fieldsNotes
listworkspaceIdReturns approved Collections with datasetPath, revision, revisionSha256.
describeworkspaceId, datasetPathReturns tables, fields, operations, revision, revisionSha256.
permissionsworkspaceId, datasetPathReturns place ({ kind: "here" } on this computer or { kind: "server", host } on the workspace's server), workspace defaults, rules, collaborator grants, app bindings, boundApps with scope ("local", "link", "workspace", or "owner") and drift status ("compatible", "needs-refresh", "incompatible") and reasons, and boundAppsIncomplete: true if discovery failed or results are paginated (do not treat omitted boundApps as a complete check when boundAppsIncomplete is set).
createworkspaceId, definitionWrites generated files and approves revision 1.
prepareworkspaceId, descriptorPathCaptures edited dataset.json, schemaPath, operationsPath. Returns preparationId and revision.revisionSha256.
approveworkspaceId, preparationId, revisionSha256Approves a preparation. Do not pass datasetPath or sourceDigest.
invokeworkspaceId, datasetPath, operationId, revision, revisionSha256, input, idempotencyKeyRuns an approved operation and returns revision, replayed, and place ({ kind: "here" } or { kind: "server", host }). Check the operation's readOnly flag in describe to distinguish reads from writes: when place.kind === "server", writes (readOnly: false) run directly on place.host and fail offline rather than queuing, so a successful write proves revision committed on that server. When copy (offline, savedAtMs, host) is present, the read ran on a local replica or saved copy; online member reads and direct relay reads omit copy. Use a fresh idempotencyKey per intended write; reuse the same key and input to retry an uncertain write.
prepareSchemaChangeworkspaceId, datasetPath, revision, revisionSha256, changechange.kind: addField, renameField, changeField, renameTable, renameCollection, addButton. Required addField needs default. Returns boundApps and, if checks were incomplete or paginated, boundAppsIncomplete: true.
prepareMigrationworkspaceId, datasetPath, migrationPathPrepares edited source + SQL migration file for custom Collections. Pass migrationPath: null when only operations or metadata changed without schema SQL edits. Returns boundApps and, if checks were incomplete or paginated, boundAppsIncomplete: true.
prepareRelationChoicesworkspaceId, datasetPath, revision, revisionSha256, tableId, fieldId, labelFieldIdAdds a public read operation returning only key + labelFieldId for a relation field. Returns boundApps and, if checks were incomplete or paginated, boundAppsIncomplete: true.
approveMigrationworkspaceId, preparationId, revisionSha256, approvalDigestApplies a prepared schema change, migration, or relation choices. Do not pass datasetPath.
createFormworkspaceId, datasetPath, revision, revisionSha256, tableId, createOperationId, appRoot, fieldIdsOptional title, relationChoices: [{ fieldId, operationId, labelFieldId }]. Generated app.publish.json omits revision and revisionSha256 so re-preparing picks up later approved revisions automatically.
typesworkspaceId, datasetPathWrites a .d.ts file under .dohc/types/ with TypeScript types for the approved tables and operations, and returns its workspace-relative path. An app imports that file with import type, using a path relative to the importing source file.
sqlworkspaceId, datasetPath, sqlOwner only. Runs one read-only SQL query under the SQLite authorizer, or EXPLAIN QUERY PLAN with explain: true.
traceworkspaceId, datasetPathLists recent in-memory operation timings and SQL metrics.
history, historyRevisionworkspaceId, datasetPath; revisionSha256 for historyRevisionhistory queries the Collection's authority directly and returns headRevision, place, record edits, and schema and rule revisions. Pass limit: 1 when place.kind === "server" to confirm the server's latest revision. historyRevision reads one revision's saved source.
prepareHistoryRestoreworkspaceId, datasetPath, revision, revisionSha256, targetRevisionSha256, changedRevisionSha256Prepares a reviewed forward change back to a past revision against current records, keeping current access. Apply it with approveMigration. Restoring source files alone never activates rules.
approval, confirmApprovalworkspaceId, datasetPath; revisionSha256 for confirmApprovalapproval says who approved the rules the Collection runs. When needsOwnerConfirmation is true, the Admin who approved them no longer is one: confirmApproval with that revisionSha256 records the Owner as their approver without changing the rules.
exportworkspaceId, datasetPath, savePathStreams a private recovery archive, with private records, files, history, and retry credentials. savePath is absolute, outside the workspace, and ends in .dohc-recovery.
prepareRecoveryworkspaceId, sourcePathReads an archive at sourcePath (relative to the MCP server folder, or absolute) and returns recovery.
claimRecoveryworkspaceId, transferId, manifestSha256, sourceCursor, oldHostStoppedCopy recovery.sourceCursor.workspaceId, recovery.transferId, recovery.manifestSha256, and recovery.sourceCursor from prepareRecovery. Stop the old host first, then pass oldHostStopped: true.
discardRecoveryworkspaceId, transferIdCancels a prepared recovery before it installs. Copy recovery.transferId from prepareRecovery.