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

kiri-factory

v0.1.1

Published

Schema-driven Drizzle factories for explicit test rows and relation wiring

Readme

npm version CI License Types Node

kiri-factory

Schema-first test factories for Drizzle ORM.

[!IMPORTANT] kiri-factory is still early. It is published, but small API changes are still possible across 0.x releases. For production apps, prefer pinning an exact version and checking the changelog before upgrades.

kiri-factory gives you test-friendly factories directly from your Drizzle schema.

It supports both:

  • stable Drizzle relations(...)
  • Drizzle's current beta Relational Queries v2 shape through defineRelations(...) and the kiri-factory/rqb-v2 entrypoint

You can start with zero per-table factory definitions. Required columns are inferred from the schema using the same generator selection logic that powers drizzle-seed, missing single-column parents can be auto-created during create(), and create() still gives you the inserted row back.

When you do want shared defaults, defineFactory(..., { columns }) uses the same public drizzle-seed generator surface as the official seeding API. That means the same columns(f) definition can power both small test setup and bulk seeding.

In short:

  • start from your schema
  • use create() / createMany() for test rows
  • add defineFactory(...) only where shared defaults help
  • reuse the same columns(f) in drizzle-seed

Quick Example

import * as schema from "./db/schema";
import { createFactories } from "kiri-factory";

const factories = createFactories({
  db,
  schema,
  seed: 42,
});

const session = await factories.sessions.create();
// a required single-column parent can be auto-created when its table is in the runtime

If one table needs shared values, add a factory definition:

const customerFactory = defineFactory(customers, {
  columns: (f) => ({
    status: "active",
    companyName: f.companyName(),
    contactName: f.fullName(),
    contactEmail: f.email(),
  }),
});

const factories = createFactories({
  db,
  schema,
  seed: 42,
  definitions: {
    customers: customerFactory,
  },
});

And the same definition plugs straight into drizzle-seed:

await seed(db, schema).refine((f) => ({
  customers: {
    count: 1000,
    columns: customerFactory.columns(f),
  },
}));

seed is optional. The default is 0, which preserves the built-in stable per-column determinism. kiri-factory does not log the seed automatically, but you can read it back from the runtime with factories.getSeed().

What seed is good for:

  • reproducible test data across runs
  • easier debugging when a generated row causes a failure
  • intentionally varying generated data in CI when you want broader coverage

This follows the same general idea as Drizzle's own deterministic seed docs:

If you want opt-in variation between runs, a common pattern is:

const factories = createFactories({
  db,
  schema,
  seed: Number(process.env.TEST_SEED ?? 0),
});

The generated values still depend on factory call order and sequence state, so the most reliable reproduction recipe is: same schema, same seed, same sequence reset, same call order.

Install

pnpm add drizzle-orm kiri-factory

Requirements:

  • ESM only
  • Node ^20.19.0 || >=22.12.0
  • peer install range: drizzle-orm >=0.36.4 <1 || >=1.0.0-beta.1 <2
  • kiri-factory is tested with drizzle-orm 0.45.x
  • kiri-factory/rqb-v2 is tested with Drizzle's current beta Relational Queries v2 path on drizzle-orm 1.0.0-beta.21

The peer range is intentionally broader than the repository test matrix so Drizzle users do not get blocked on install while the beta line keeps moving. The versions above are the ones currently exercised in this repository.

kiri-factory/rqb-v1 is kept as a compatibility alias for the stable path.

Entrypoints

| Import | Use when | | --------------------- | --------------------------------------------------------------------- | | kiri-factory | your project uses stable relations(...) | | kiri-factory/rqb-v2 | your project uses beta defineRelations(...) / Relational Queries v2 |

What It Does

  • build() / buildMany() for in-memory rows
  • create() / createMany() for persisted rows
  • for("relation", row) for explicit parent wiring
  • defineFactory(..., { columns }) for reusable per-table definitions

kiri-factory is intentionally narrow. It does not try to replace drizzle-seed, prove every database constraint ahead of time, or hide multi-row scenarios behind a second DSL.

RQB v2 defineRelations(...)

import { PGlite } from "@electric-sql/pglite";
import { drizzle } from "drizzle-orm/pglite";
import { createFactories } from "kiri-factory/rqb-v2";
import { defineRelations } from "drizzle-orm";
import * as schema from "./db/schema";

const client = new PGlite();
const db = drizzle({ client });

const relations = defineRelations(schema, (r) => ({
  posts: {
    author: r.one.users({
      from: r.posts.authorId,
      to: r.users.id,
    }),
  },
  users: {
    posts: r.many.posts(),
  },
}));

const factories = createFactories({
  db,
  relations,
});

const author = await factories.users.create();
const post = await factories.posts.for("author", author).create();

If you want the official seeding API itself, go straight to:

Docs

The docs are split into small Markdown files so humans and agents can jump directly to one topic.

Development

This repository uses pnpm workspaces, catalogs, and Vite+.

pnpm setup:hooks
pnpm check
pnpm test
pnpm build

pnpm setup:hooks installs the repo-local Vite+ hooks.
The pre-commit hook runs vp staged, which applies vp check --fix to staged files.