Type generation CLI

Generating database metadata improves DX and runtime validation.

  1. Create a script in your app:
json
{
  "scripts": {
    "notion:generate": "source .env && npx @mikemajara/notion-cms generate -t $NOTION_API_KEY -d $NOTION_CMS_DATABASE_ID -o ./lib/notion"
  }
}
  1. Run the generator with required env vars (database IDs, output path). Each project typically maintains a notion-types-*.ts file checked into source control.
  2. Import the generated file early in your app (e.g., _app.tsx, entry server file) so registerDatabase runs before queries. Alternatively, import the NotionCMS from your types directory (./lib/notion in the example above), this will ensure the database is registered when you use it.

Last updated: