Skip to content
Auto
English

Importing

tapedb cms import brings content in from any system that can write JSON: an export from another CMS, a spreadsheet converted to records, a script over an old database.

Terminal window
npx @tapedb/cli cms import records.ndjson --workspace <id> --dev importer --publish

One record per line (NDJSON), or a JSON array of the same:

{ "type": "author", "id": "ada", "fields": { "name": "Ada Lovelace" } }
{ "type": "post", "id": "hello", "fields": {
"title": "Hello",
"slug": "hello",
"body": { "markdown": "Some **bold** text.\n\n## A heading" },
"author": { "ref": "ada" },
"cover": { "url": "https://<your-old-site>/cover.jpg", "alt": "The cover" } } }
  • type is a content type; fields are its fields by name.
  • id is the record’s id in the source system. The document keeps it when it is a valid TapeDB id, and otherwise gets a stable id derived from it, so importing the same file again updates the documents instead of duplicating them.
  • References are { "ref": "<source id>" }, or just the source id, to a record of the referenced type in the same file or imported before. Documents are written in reference order, so authors exist before the posts that name them.
  • Rich text is ProseMirror JSON, { "markdown": "…" }, or plain text, where blank lines separate paragraphs.
  • Images are { "path": "public/…" } for a file already in the workspace, or { "url": … } / { "file": … } with optional alt, x and y, to upload into the media library under public/media/.
  • Other fields take their stored form: strings, numbers, booleans, a select option, "2026-11-28" for a date.

Every record is checked against your content types first: unknown types and fields, values of the wrong kind, references to records that do not exist, required fields missing when publishing. Every problem is listed at once, with the record’s line, type and id. If there is any problem, nothing is written.

--dry-run stops after the check, to try a file without touching the workspace.

Option
--workspace <id> the workspace to import into
--url <origin> the Worker; defaults to tapedb dev at http://localhost:8787
--token <claim> an editor’s claim, for a deployed Worker
--dev <name> a development claim with that name, for tapedb dev and other non-production Workers
--publish publish each document after writing it; without it, documents arrive as drafts for review
--dry-run check everything and write nothing
--content <file> the file exporting content; defaults to cms.content.ts, then tapedb.schema.ts

The import runs through the same rules as the studio, in the claim holder’s name: drafts and revisions carry it, publishing needs an editor, and each document is one transaction. At the end it reports how many documents were created, updated and published and how many images were uploaded.

@tapedb/cms/import does the same from your own script, with a TapeDB client:

import { importContent, parseRecords } from "@tapedb/cms/import";
import { content } from "./cms.content";
const records = parseRecords(await readFile("records.ndjson", "utf8"));
const report = await importContent(db, content, records, {
sub: "importer",
publish: true,
readFile: async (path) => new Blob([await readFile(path)]),
onProgress: (done, total) => console.log(`${done}/${total}`),
});
report.problems; // [] when everything was written
report.created; report.updated; report.published; report.images;

fromMarkdown(text) converts Markdown to the CMS’s rich text on its own, for content you transform before importing.