npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@betttercms/codegen

v0.5.0

Published

Generate TypeScript types from your BetterCMS content schema — the single source of truth shared by the dashboard builder and the MCP tools.

Downloads

579

Readme

@betttercms/codegen

Generate TypeScript types from your BetterCMS content schema.

Your models are defined once — in the dashboard schema builder or by your AI through the MCP tools. Both write the same underlying field schema, so the types this generates can never drift from what your editors and agents actually create. This is the deterministic floor under the AI integration: even if an agent mis-wires something, you still have exact, committed types to fall back on.

Use it

# In your site repo (key from the dashboard → Settings → API Keys, content:manage scope)
BETTERCMS_API_KEY=bcms_xxx npx @betttercms/codegen --out src/bettercms.generated.ts
✓ Generated 2 model types → src/bettercms.generated.ts

Commit the generated file and re-run codegen after any schema change (a CI step or the BetterCMS GitHub Action does this for you on every build).

Options

| Flag | Env | Default | |------|-----|---------| | --out, -o | — | bettercms.generated.ts | | --bindings-out | — | (off) — also emit Live Preview bindings to this path | | --api-url | BETTERCMS_API_URL | https://api.bettercms.ai/api/v1 | | --key | BETTERCMS_API_KEY | — |

What it emits

For a blog model with title (text, required), body (richtext), hero (group):

export interface BlogFields {
  readonly title: string;
  readonly body?: RichText;
  readonly hero?: {
    readonly heading: string;
  };
}

export interface BetterCMSSchema {
  readonly "blog": BlogFields;
}
export type BetterCMSModelSlug = keyof BetterCMSSchema;

The BetterCMSSchema registry lets the Next.js adapter type getEntry("blog", …) by slug.

Field type → TypeScript

| Field | TS | |-------|-----| | text · date · datetime | string | | richtext | RichText | | image | BetterCMSImage | | boolean / number | boolean / number | | select | "a" \| "b" (or string) | | reference / multi-reference | string / string[] (entry ids) | | array | string[] / number[] | | group | { …nested } | | repeater | Array<{ …nested }> |

Live Preview bindings (--bindings-out)

Pass --bindings-out src/bettercms.bindings.generated.ts to also emit a tiny, schema-derived helper that powers the dashboard's Live Preview editor. Spread a binding onto the element that renders each field — the editor reads the resulting data-bcms-field attribute to make the real, running site editable in place:

import { bcms } from "./bettercms.bindings.generated";

<h1 {...bcms.blog.title}>{entry.fields.title}</h1>            // scalar
<li {...bcms.blog.tags.value(i)}>{tag}</li>                   // primitive-array item
<article {...bcms.blog.features.$(i)}>                        // array item root
  <h3 {...bcms.blog.features.label(i)}>{f.label}</h3>         // array item sub-field
</article>

The attributes are emitted only when the site is built with BCMS_ANNOTATE set (preview builds); a normal production build ships zero extra attributes (bcmsField returns {}). Same generated file for both — no separate mode. Bindings follow the editor's one-level path grammar (field, field[i], field[i].sub); non-repeatable zones and deeper nesting aren't index-addressable yet, so they're omitted rather than emitted as paths that can't bind.

Library API

import { generateTypes, generateBindings, fetchModels } from "@betttercms/codegen";

const models = await fetchModels({ apiUrl, apiKey });
const types = generateTypes(models);       // pure, deterministic
const bindings = generateBindings(models); // pure, deterministic (Live Preview)

generateTypes and generateBindings are pure and deterministic — same models in, byte-identical output out.