P
Prisma5mo ago
kgtrey1

how to import prisma client on a client without compromising credentials

Hello, I would like to build an app using a monorepo. Since my backend will be using nestjs and my application react native. I would love to use prisma as an ORM to define my entities and reuse the types in both my nestjs and rn applications. While it’s not a concern importing prisma client on my backend, I’m afraid that doing so on react native may lead to credentials leaks Is there a way to get the types and the types only on my rn app?
7 Replies
Olyno
Olyno5mo ago
Hi :vmathi: You an import Prisma types safely, those are only Typescript types. You just won't import the prisma client at any cost in your client or it will be compromised
kgtrey1
kgtrey1OP5mo ago
I'm sorry but I didn't get what you said I'm aware that I could import as "type" and that the imports would be remove after transpilation, but I'm not sure it will be the case if I use enum in my prisma schema because enums (if my memory is good, I could be wrong) are considered as object and I plan on using enum anyway. I'm looking for a way to only expose my entities types to the RN app without having a lot of things to do once I change something in the schema
Olyno
Olyno5mo ago
When you generate the Prisma client, you also generate types. Simply import those types:
import type { YourType } from '@prisma/client';
import type { YourType } from '@prisma/client';
I forgot how types are generated from the client 😅
kgtrey1
kgtrey1OP5mo ago
I agree with that, but if it's an enum, it's a value and not a type and in this case, it won't work But I might miss a point
Olyno
Olyno5mo ago
My guess would be to recreate this enum based on the type Or import it from prisma
kgtrey1
kgtrey1OP5mo ago
import type { Status } from '@prisma/client'

export const changeStatus = (status: Status) => {
// send something to the api
}
import type { Status } from '@prisma/client'

export const changeStatus = (status: Status) => {
// send something to the api
}
import type { Status } from '@prisma/client'
import { changeStatus } from 'adapters'

const onConnect = () => {
changeStatus(Status.AVAILABLE) // this will throw
}
import type { Status } from '@prisma/client'
import { changeStatus } from 'adapters'

const onConnect = () => {
changeStatus(Status.AVAILABLE) // this will throw
}
In this case, I don't think I can use the enum, but I might be able to hardcode it like and still benefit type safety
import { changeStatus } from 'adapters'

const onConnect = () => {
changeStatus("AVAILABLE")
}
import { changeStatus } from 'adapters'

const onConnect = () => {
changeStatus("AVAILABLE")
}
If my enum looks something like:
enum Status {
AVAILABLE = "AVAILABLE",
DISCONNECTED = "DISCONNECTED"
}
enum Status {
AVAILABLE = "AVAILABLE",
DISCONNECTED = "DISCONNECTED"
}
I need to check but I think it might be ok, thanks for the idea If anybody comes around here and have another take on this subject, then I would be glad to hear about it
Olyno
Olyno5mo ago
Don't you have the Status enum available in exports from the client?
Want results from more Discord servers?
Add your server