@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 aPrismaprefix for clarity and future-proofing.
Example:TableArgs→PrismaTableArgs,OpResult→PrismaOpResult, etc.
- 🔍 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 runprisma generateto have all required types available.
npm install @itboom/prisma-typesbun add @itboom/prisma-typesNote: Make sure you have
@prisma/clientinstalled and that you've runprisma generate.
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);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"},});| Type | Description |
|---|---|
PrismaTableKey | Available 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. |
To generate detailed documentation using TypeDoc, run:
npx typedoc --out docs srcThis will create an HTML documentation site in the docs/ folder.
This project is licensed under the MIT License. See the LICENSE file for details.
Contributions are welcome!
Please open an issue or submit a PR to improve type inference, extend features,
or fix bugs.
For questions or further information, please contact:
Enjoy using @itboom/prisma-types and happy coding! 🎉