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 🙏

© 2025 – Pkg Stats / Ryan Hefner

prisma-models

v0.0.2

Published

Prisma Models as a Mapped type → Models['User'] and Enums['UserStatus']

Downloads

232

Readme

Prisma Models

Prisma Models returns a Mapped type that includes all the generated types from your Prisma Client. This approach enables you to access Prisma models and enums from a single source. Instead of importing each type individually from the Prisma Client, you can use mapped types such as Models["User"] for models and Enums["UserStatus"] for enums.

Usage

  1. Install library (as a dev dep)
npm i -D prisma-models

# bun i -d prisma-models
# pnpm i -D prisma-models
# yarn add -D prisma-models
  1. Generate Models and Enums
// [ src/types/models.ts ]
import {Prisma} from '@prisma/client';
import {PrismaModels} from 'prisma-models';

export type Models = PrismaModels<Prisma.ModelName, Prisma.TypeMap>;
// [ src/types/enums.ts ]
import {$Enums} from '@prisma/client';
import {PrismaEnums} from 'prisma-models';

export type Enums = PrismaEnums<typeof $Enums>;
  1. Use Models and Enums in your code
// [ src/routes/app.tsx ]
import type {Models} from '~/src/types/models';

export const loader = async () => {
  const {data, error} = await some_api.user.get();
  if (error) {
    /* ... */
  }
  const userData = data.user as Models['User'];
};
// [ src/components/user-status.tsx ]
import type {Enums} from '~/src/types/enums';

type Props = {status: Enums['UserStatus']};
export const UserStatusBadge: React.FC<Props> = ({status}) => {
  const statusStr = status_to_str[status]; // ACTIVE -> Active, REJECTED -> Rejected
  const statusColor = status_to_color[status]; // ACTIVE -> green, REJECTED -> red

  return <Badge color={statusColor}>{statusStr}</Badge>;
};

Motivation

The motivation behind creating this small yet useful library was to solve the challenge of using Prisma types from the backend in the frontend project within a monorepo setup. I had previously hardcoded all the types for the frontend and other projects, but this approach was not ideal, especially with over 50 tables. It was difficult to maintain and prone to errors.

In my search for a solution, I came across this discussion, and thanks to those who shared their solutions. However, the approach discussed there generated models without relations, whereas my requirements included models with relations, along with support for Enums.

That's where prisma-models came in as a drop-in solution. It not only generates models with relations but also Enums as a single Mapped type.

This approach has been tested with the latest Prisma version (v5.18.0) and should work with any Prisma version that exposes Prisma.ModelName, Prisma.TypeMap and $Enums from @prisma/client. If you encounter any issues, please don't hesitate to report them!