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

pglite-typegen

v0.0.2

Published

Generate TypeScript types from a PGlite database via pg_catalog. Optional Kysely output.

Readme

pglite-typegen

Generates TypeScript types by introspecting a PGlite database through pg_catalog. Plain interfaces by default; Kysely Generated<> output is an opt-in flag, not the default.

Why this approach

PGlite is Postgres compiled to WASM, so its pg_catalog is standard Postgres. There is no SQL parsing and nothing is executed — the tool opens an existing PGlite data dir and asks the catalog what the schema actually is. This captures, with zero guessing: enums (as string-literal unions), domains (resolved to their base type via a recursive CTE), standalone composite types, array columns, and nullability. However the schema got into the dir — any migration tool, raw SQL, DO blocks — is irrelevant, because the catalog reflects the final state regardless.

Usage

# Plain TypeScript interfaces (default)
pglite-typegen ./.pglite --out ./src/db.ts

# Kysely DB interface with Generated<> wrappers
pglite-typegen ./.pglite --out ./src/db.ts --kysely

# Multiple schemas, numeric/bigint as number
pglite-typegen ./.pglite --schemas public,app \
  --out ./src/db.ts --numeric-as-number

With --kysely, columns with a default / identity / generated value are wrapped in Generated<> (so they're optional on insert) and the file imports Generated from kysely. Without it, every column is T or T | null and there is no kysely dependency at all.

The dir must already contain the schema (run your migrations into it beforehand, by whatever means — that's not this tool's job).

Programmatic

import { generate } from "pglite-typegen";
await generate({ dataDir: "./.pglite", outFile: "./src/db.ts" });

generate() also accepts { pglite } (any object with .query), which overrides dataDir and is how the test suite runs without a real PGlite.

Type mapping notes

  • int8 / numericstring by default (avoids 2^53 precision loss). --numeric-as-number overrides.
  • json / jsonbunknown (annotate yourself if you have a shape).
  • Unknown base types emit string /* unmapped pg type: <name> */ so they surface in review rather than silently becoming any.
  • Non-public schemas: interface name is Schema_TableTable, DB key is "schema.table".

Tests

bun test — validates the model builder and emitter against synthetic pg_catalog rows shaped exactly as the introspection queries return them (enum, domain, composite, array, identity, generated, nullable), covering both the plain default output and the --kysely opt-in. Bun resolves the .ts sources directly, so no build step or loader is needed to run it.