Skip to content

Repository files navigation

@itboom/prisma-types 🚀

@itboom/prisma-types is a helper TypeScript types library for working with Prisma Client operations. It allows you to easily extract operation arguments and results for Prisma models (tables), and even customize payload types when needed.

❗️NOTICE (v1.1.0+)
All exported types now start with a Prisma prefix for clarity and future-proofing.
Example: TableArgsPrismaTableArgs, OpResultPrismaOpResult, etc.


Table of Contents

  1. Features ✨
  2. Installation 📦
  3. Usage 🔧
  4. API Reference 📚
  5. Documentation 📝
  6. License 📄
  7. Contributing 🤝
  8. Contact 📬

Features ✨

  • 🔍 Extract Operation Arguments & Results: Easily obtain type definitions for operations such as findFirst, update, upsert, etc.
  • 🧩 Customizable Payloads: "Fix" a table (model) name first and later provide a custom payload type via generics.
  • 🔌 Seamless Integration: Works directly with your generated Prisma Client types.
    Note: Ensure you have run prisma generate to have all required types available.

Installation 📦

Using npm

npm install @itboom/prisma-types

Using Bun

bun add @itboom/prisma-types

Note: Make sure you have @prisma/client installed and that you've run prisma generate.


Usage 🔧

Basic Example

import{PrismaTableArgs,PrismaTableKey,PrismaTableResults,}from"@itboom/prisma-types";consttableKey: PrismaTableKey="user";// Get all operation argument types for the "user" tabletypeUserArgs=PrismaTableArgs<typeoftableKey>;// Get all operation result types for the "user" tabletypeUserResults=PrismaTableResults<typeoftableKey>;// Example: Types for the "findFirst" operationtypeUserFindFirstArgs=UserArgs["findFirst"];typeUserFindFirstResult=UserResults["findFirst"];// Usage in code:constpayload: UserFindFirstArgs={where: {id: 1},include: {posts: true},};constresult: UserFindFirstResult=awaitprisma.user.findFirst(payload);

Custom Payload Example

import{PrismaTableKey,PrismaTableResults}from"@itboom/prisma-types";consttableKey: PrismaTableKey="user";// Define a custom payload interfaceinterfaceMyPayload{customField: string;}// Override the default payload for operation resultstypeCustomUserResults=PrismaTableResults<typeoftableKey,MyPayload>;// Now, for example, the "update" operation will use your custom payloadconstcustomResult: CustomUserResults["update"]=awaitprisma.user.update({where: {id: 1},data: {name: "New Name"},});

API Reference 📚

Types

TypeDescription
PrismaTableKeyAvailable Prisma model names, from Prisma.TypeMap.
PrismaTableArgs<T>Argument types for all operations on table T.
PrismaTableResults<T, P>Result types for all operations on table T, with optional payload override.
PrismaOpArgs<T, O>Arguments for operation O on table T.
PrismaOpResult<T, O, P>Result for operation O on table T using payload P.

Documentation 📝

To generate detailed documentation using TypeDoc, run:

npx typedoc --out docs src

This will create an HTML documentation site in the docs/ folder.


License 📄

This project is licensed under the MIT License. See the LICENSE file for details.


Contributing 🤝

Contributions are welcome!
Please open an issue or submit a PR to improve type inference, extend features, or fix bugs.


Contact 📬

For questions or further information, please contact:

📨 itboom.dev@gmail.com


Enjoy using @itboom/prisma-types and happy coding! 🎉

About

No description, website, or topics provided.

Resources

Stars

3 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages