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

@hatkom/prisma-generator-default-values

v1.0.0

Published

Expose default values from your Prisma schema as typed constants

Downloads

39

Readme

@hatkom/prisma-generator-default-values

npm

A Prisma generator that exposes the @default(...) values from your schema as typed, importable constants.

Why?

Prisma schemas define default values, but there's no way to access them at runtime. If you want to apply defaults in your application layer (e.g. for optimistic UI, form pre-filling, or validation), you end up duplicating them manually.

This generator reads your schema and produces a TypeScript file with all default values exported as as const objects.

Installation

npm i @hatkom/prisma-generator-default-values

Setup

Add the generator to your schema.prisma:

generator default_values {
  provider = "prisma-generator-default-values"
  output   = "./generated/defaults.ts"
}

Then run:

npx prisma generate

Example

Given this schema:

enum Role {
  USER
  ADMIN
}

model User {
  id        String   @id @default(cuid())
  email     String   @unique
  name      String?
  role      Role     @default(USER)
  active    Boolean  @default(true)
  createdAt DateTime @default(now())
}

model Post {
  id        String   @id @default(uuid())
  title     String
  published Boolean  @default(false)
  views     Int      @default(0)
  authorId  String
  author    User     @relation(fields: [authorId], references: [id])
}

The generator produces:

// Generated by prisma-generator-default-values — do not edit manually

export const UserDefaults = {
  id: { _fn: 'cuid' },
  role: "USER",
  active: true,
  createdAt: { _fn: 'now' },
} as const

export const PostDefaults = {
  id: { _fn: 'uuid' },
  published: false,
  views: 0,
} as const

What gets generated

For each model that has fields with @default(...), a {Model}Defaults const object is exported. The as const assertion gives you full literal types out of the box.

Default value representation

| Schema default | Generated value | |---|---| | @default("VALUE") | "VALUE" | | @default(true) | true | | @default(0) | 0 | | @default(ENUM_VALUE) | "ENUM_VALUE" | | @default(now()) | { _fn: 'now' } | | @default(uuid()) | { _fn: 'uuid' } | | @default(cuid()) | { _fn: 'cuid' } | | @default(autoincrement()) | { _fn: 'autoincrement' } | | @default(dbgenerated("...")) | { _fn: 'dbgenerated', _args: [...] } |

Scalar and enum defaults become their literal value. Function-based defaults (like now(), uuid()) become { _fn: 'name' } objects, with an _args array when the function has arguments.

Usage examples

import { UserDefaults, PostDefaults } from './generated/defaults'

// Pre-fill a form
const newUser = {
  role: UserDefaults.role,       // "USER"
  active: UserDefaults.active,   // true
}

// Check if a field has a server-generated default
if (typeof UserDefaults.id === 'object' && '_fn' in UserDefaults.id) {
  // id is generated server-side (cuid), don't include in form
}

License

MIT