Collaborate on prisma types and enums for various projects

I'm currently working on an API that utilizes Prisma to provide data. This API is used in various projects. Within the API, I create types using Prisma.ModelGetPayload to specify the return types for certain API responses.

import { Prisma } from "@prisma/client";

export const minimalSelect = Prisma.validator<Prisma.ModelXYSelect>()({
    id: true,
    name: true
});

export type MinimalModelXY = Prisma.ModelXYGetPayload<{
    select: typeof minimalSelect;
}>;

Alternatively, enums can be directly imported from the Prisma client.

import { EnumXY } from "@prisma/client";

These enums and type definitions are dependent on the generated Prisma client of the API.

While there are options to extract the entire Prisma client into an npm package (refer here), this approach may not align with my preferences.

Is there a way to extract these types into an npm package in order to share them across multiple projects without extracting the entire Prisma client?

Answer №1

To access all the generated types from Prisma, simply navigate to

node_modules/.prisma/client/index.d.ts

You have the option of exporting this file as an npm package for use in your frontend application.

Alternatively, consider packaging your schema.prisma file as an npm module. By generating a prisma client library from the schema.prisma in another project, you can eliminate the need to export PrismaClient separately.

Answer №2

If you ever face a similar scenario in the future, I encountered the same problem and decided to create a tool that can export your Prisma client's types to a specific directory and eliminate the compiled JS files.

  1. npm install -D prisma-types-export
  2. To implement this solution, simply include the following code snippet in your schema.prisma file:
    generator types {
        provider = "prisma-types-export"
        output   = "./prisma-types"
    }
    
  3. npx prisma generate

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Distribution running of VueJS doesn't show styles

Even though I am able to successfully run my Vuejs app using nom run serve, I am facing an issue when I build it and deploy it to nginx. None of my styles, especially bootstrap, are appearing. Despite my app logic appearing correct and all my js and css ...

What is the most effective method for declaring callbacks on objects in Typescript?

I am currently working on a sidebar menu component that is connected to a service holding items in the menu. This allows multiple sources to make alterations to the menu as needed. Each item in the menu currently follows the SidebarItem interface: export ...

Steps for duplicating Angular Material locallyInstructions for making a duplicate of Angular Material

I am currently developing a web application that utilizes Angular Material (Angular4), and it seems like they are making frequent updates to their components, such as transitioning from md-select to mat-select. However, the challenge I am facing is that my ...

The upcoming construction of 'pages/404' page will not permit the use of getInitialProps or getServerSideProps, however, these methods are not already implemented in my code

Despite my efforts to search for a solution, I have not found anyone facing the same issue as me. When I execute next build, an error occurs stating that I cannot use getInitalProps/getServerSideProps, even though these methods are not used in my 404.tsx f ...

Error: unable to locate module that was imported from

Every time I try to run the project using this command, an error pops up: > npm run build npm info using <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c7a9b7aa87fee9f1e9f0">[email protected]</a> npm info using ...

Using ngFor directive to iterate through nested objects in Angular

Receiving data from the server: { "12312412": { "id": "12312412", "something": { "54332": { "id": "54332", "nextNode": { "65474&q ...

What is the process of declaring a method within a subclass and then retrieving it from a method within the parent class using Typescript?

I am currently working with this TypeScript code snippet: abstract class Base { static actions:Record<string,unknown> static getActions () { return this.actions } } class Sub extends Base { static actions = { bar:(bar:string ...

Blazing Paths with an Isomorphic Application Using Inferno and TypeScript

I am currently working on building an isomorphic application using Express and Inferno. Strangely, I have not come across any similar projects online. In my attempt to create one myself by following a guide on Razzle, specifically related to Inferno, I enc ...

Utilizing Arrow Functions with Parameters in Angular

I am currently working on an Angular 4 app and I am attempting to create a queue of actions. Each action should only be executed after the previous one has finished, and each action should receive its own set of parameters. public activeRegistrationAndS ...

You should only call them after the method that returns a promise has completed

submitTCtoDB() { console.log("The selected file list contains: " + this.selectedFileList) this.readFile().then(() => { alert("ReadFile has finished, now submitting TC"); this.submitTC() }); } readFile() { return new Promise((resolve, r ...

Bringing in a JSON file into a ReactXP project

I'm encountering a strange issue, possibly a bug, with importing a JSON file as an object into my application. I have the following configurations: "compilerOptions": { "resolveJsonModule": true, "esModuleInterop": true, } While it appears t ...

Angular is hindered from updating due to its reliance on TypeScript dependencies

My Ionic info is as follows: Ionic CLI : 6.2.1 (C:\Users\Arashsoft\AppData\Roaming\npm\node_modules\@ionic\cli) Ionic Framework : @ionic/angular 5.0.5 @angular-devkit/build-angular ...

Choose an alternative following the start-up phase

I have been searching for solutions on various platforms, including Stack Overflow, but nothing seems to work for me. I am struggling with selecting the first option after initializing the box because currently it is choosing a blank option that is not eve ...

What to do when encountering NPM UNMET PEER DEPENDENCY issue: npm ERR! peer dep missing: bufferutil@^4.0.1, as requested by [email protected]

I am working on a project cloned from GitLab and using it locally on Ubuntu with Node.js version 9. However, I encountered an issue: (npm ERR! peer dep missing: bufferutil@^4.0.1, required by [email protected] ), even though when I ran the "npm list ...

[deactivated]: Modify a property's value using a different component

One of the requirements for my button is that it should be disabled whenever the callToActionBtn property is true. match-component.html <button [disabled]="callToActionBtn" (click)="sendTask()>Send</button> match-component.ts public callToA ...

"Successful npm ci execution on local machine, but encountered failure on a GitLab

Encountering an issue while running the npm ci command, although it works fine on my local machine (even after removing node_modules and reinstalling with npm ci, no errors) $ npm ci npm WARN ERESOLVE overriding peer dependency npm WARN While resolving: @u ...

Implementing Render Props pattern with TypeScript in functional components

I am in the process of transitioning my React app (created with create-react-app) to use Typescript, and I have encountered a problem with a component that utilizes render props. Below is a simplified version of the component that is still causing an erro ...

Having difficulty uploading an npm package to the GitLab registry

I am having trouble with a basic setup for publishing a node package to GitLab's package registry. I started a project using GitLab's Node Express template, but when I try to run npm publish, I encounter the following error: npm notice npm notic ...

How can I find the "types" specific to modules within the "firebase" library?

I have a question that applies to various scenarios, with Firebase serving as an example. When working on my react project, I find myself wanting to import firebase from "@firebase/app", which is logical. However, if I want the const locationRef ...

Step-by-step guide on installing a multitude of global packages using Yarn

yarn install -h indicates that the -g (global) option is now considered outdated. How can I specify that I want to globally install multiple packages from my existing package.json/yarn.lock files? Possible solutions: yarn global [command] offers command ...