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

@cratebase/schema-codegen

v0.2.0

Published

CLI that turns a Cratebase schema-as-code JSON file (or a live GET /api/collections response) into a single .d.ts with one TypeScript type per non-system collection.

Readme

@cratebase/schema-codegen

Superseded by the built-in cratebase typegen. Cratebase's own server binary now ships this generator natively (Rust, no Node/Bun toolchain required), with a richer mapping — select fields become string literal unions, relation fields get a typed expand? field, and <Name>Create/<Name>Update input types are generated alongside each <Name>Record — plus a zero-setup GET /api/typegen endpoint and a --dev watch that regenerates the file on every schema change. Run cratebase typegen -o src/cratebase-types.d.ts (see the CLI reference or cratebase typegen --help) instead of this package for any new project. This package still works and is not going away, for projects already depending on it or that need it as a pure-JS build step with no Cratebase binary on hand.

Build-time CLI that turns a Cratebase schema-as-code JSON document into a single .d.ts file with one TypeScript interface per non-system collection. It has no dependency on the server or admin dashboard — run it from a project's own build pipeline, wherever a PostsRecord-shaped type is more useful than hand-written ones.

npx @cratebase/schema-codegen ./schema.json -o src/cratebase-types.d.ts

The input is exactly what GET /api/collections returns (an { items: [...] } page), what PUT /api/collections/import and POST /api/schema/apply accept ({ collections: [...] }), a bare array of collection objects, or a live server URL to fetch that page from directly:

npx @cratebase/schema-codegen https://api.example.com --token <superuser-jwt> -o types.d.ts

Field types follow FieldKind's variants in crates/core/src/field.rs one-for-one, so a change to that enum is the only place the mapping needs to catch up. select, file and relation fields become an array (string[]) when their maxSelect is greater than 1, and a bare string otherwise; every other field kind maps straight to its TypeScript scalar (text → string, number → number, bool → boolean, json → unknown, geoPoint → { lon: number; lat: number }, ...).

Alongside the per-collection interfaces, the generated file also exports a Schema interface mapping every non-system collection's name to its <Name>Record type, plus type Collections = keyof Schema. Pass Schema to @cratebase/client's createClient<Schema>() for a typed client.collection("posts") — an unknown collection name is then a compile error:

import { createClient } from "@cratebase/client";
import type { Schema } from "./cratebase-types.js";

const client = createClient<Schema>("http://localhost:8090");
const posts = await client.collection("posts").list(); // typed PostsRecord[]

Options

cratebase-codegen <schema.json | server-url> [-o out.d.ts] [--token <jwt>]
  • <schema.json | server-url> — a local file path, or an http(s):// server origin (or its /api/collections URL directly).
  • -o, --out — output path (default cratebase-types.d.ts); may also be given positionally.
  • --token — a superuser JWT, sent as Authorization: Bearer <token> when fetching from a live server.

Development

bun install
bun run typecheck
bun run build   # emits dist/codegen.js, the package's published bin entry point