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

@damatjs/codegen

v2.1.0

Published

Damatjs codegen — agnostic type + zod + CRUD scaffold generation

Readme

@damatjs/codegen

Generate TypeScript types and Zod schemas from Damat ORM model schemas.

@damatjs/codegen turns a serialized ModuleSchema (from @damatjs/orm-type) into ready-to-write TypeScript source: row interfaces, New*/Update* mutation types, enum unions, relation fields, and matching Zod validation schemas (new/update/query/id). It is a pure string-generation library — it produces file contents, never writing to disk itself — and is consumed by the ORM CLI and the framework's module system to keep generated DB types in sync with your models.

Part of the Damat monorepo · Full guide · Internals

Install

bun add @damatjs/codegen

Inside this monorepo it is referenced as a workspace dependency with "@damatjs/codegen": "*".

When to use

Use this package to:

  • Generate one combined .ts type file for a module (generateTypes) or all Zod schemas in one file (generateZodTypes).
  • Generate a file-per-table layout — <table>.ts, <table>.zod.ts, enums.ts, index.ts — as an in-memory map ready to write (generateFilesMap).
  • Map a single column to its TypeScript type (columnToTsType) or Zod schema (columnToZodSchema).

Do not use it to:

  • Define or build models — that is @damatjs/orm-model.
  • Read the database or run migrations — codegen never touches a connection; it only consumes a ModuleSchema.
  • Write files to disk — it returns strings/maps; the caller persists them.

Quick start

import { generateTypes, generateFilesMap } from "@damatjs/codegen";
import type { ModuleSchema } from "@damatjs/orm-type";

const schema: ModuleSchema = {
  moduleName: "store",
  tables: [
    {
      name: "product",
      columns: [
        { name: "id", type: "uuid", nullable: false, primaryKey: true },
        { name: "name", type: "text", nullable: false },
        { name: "price", type: "numeric", nullable: true },
      ],
    },
  ],
  enums: [{ name: "status", values: ["pending", "shipped", "delivered"] }],
  relationships: [],
};

// One combined types file (string)
const types = generateTypes(schema);
// → "export type StatusEnum = 'pending' | 'shipped' | 'delivered';"
//   "export interface Product { id: string; name: string; price: number | null; }"
//   "export type NewProduct = { name: string; price?: number | null; };"
//   "export type UpdateProduct = Partial<Omit<Product, 'id'>>;"

// File-per-table map: write each [filename, contents] pair yourself
const files = generateFilesMap(schema); // Map: "product.ts", "product.zod.ts", "enums.ts", "index.ts"
for (const [name, contents] of files) {
  // fs.writeFileSync(path.join(outDir, name), contents)
}

API

| Export | Kind | Summary | | --- | --- | --- | | columnToTsType(col) | function | ColumnSchema → TS type string (handles enum alias, array, nullable). | | columnToZodSchema(col) | function | ColumnSchema → Zod schema string (no .optional()/.nullable()). | | DEFAULT_AUTO_FIELDS | const Set<string> | Columns omitted from New* types: id, createdAt, created_at, updatedAt, updated_at. | | generateTypes(schema, opts?) | function | One combined .ts string: enums + per-table interface/New/Update. | | generateZodTypes(schema, opts?) | function | One combined .ts string of all Zod schemas. | | generateTableFile(table, schema, autoFields, banner) | function | Single table's .ts (with enum/relation imports). | | generateZodFile(table, schema, banner) | function | Single table's Zod .ts. | | generateFilesMap(schema, opts?, logger?) | function | Map<filename, contents> for the file-per-table layout. | | buildRelationMap(relationships) | function | Group RelationSchema[] by source table. | | relationFields(relations) | function | Optional loaded-relation interface fields. | | GenerateTypesOptions, GeneratedFilesMap | types | Options (autoFields, banner) and the files-map result type. |

Subpath exports: @damatjs/codegen/types is declared in package.json (maps to dist/types/index.js). It is a build-output subpath; the public, source-backed surface is the root . export above.

How it fits

Depends on:

  • @damatjs/orm-typeColumnSchema, ColumnType, ModuleSchema, EnumSchema, RelationSchema.
  • @damatjs/orm-model — workspace dependency.
  • @damatjs/logger (peer) — getLogger/ILogger for progress logging; the file-per-table generator accepts an injected logger.

It performs no I/O and opens no database connection.

Depended on by (in-repo): @damatjs/orm-cli, @damatjs/module.

Documentation

License

MIT