-
-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature Request] Create a package with no dependencies to @prisma/client
#279
Comments
This isn't an issue with this package, but rather with how you are using it in your monorepo project, I will assume you're using You need Let's say you generate it with in your database {
"name": "@repo/database",
// etc other stuff, like version, scripts, etc.
"exports": {
".": "./src/index.ts"
},
"dependencies": {
"@prisma/client": "^5.22.0"
},
"devDependencies": {
"prisma": "^5.22.0",
"zod-prisma-types": "^3.1.8"
}
} and then in the export * from '@prisma/client' If this is what you currently have, then everything is alright so far. In your Like so: "name": "@repo/schemas",
// etc other stuff, like version, scripts, etc.
"exports": {
".": "./src/index.ts"
},
"dependencies": {
"@repo/database": "*",
"zod": "^3.23.8"
} Then you will be able to import the import { User } from "@repo/database" This is the same as doing Doing this way you can safely just have this inside the export * from './prisma' then in your apps you'd just need to use the |
Hello, if someone else comes by and needs a quick and dirty way around (I am not in the case above unfortunately). Update your generators: generator zod {
provider = "zod-prisma-types"
output = "<PATH>"
...
}
generator fixZod {
provider = "prisma/schema/fixGeneratedZod.js"
output = "not_important"
} Create a #!/usr/bin/env node
import pkg from '@prisma/generator-helper';
import { execSync } from 'node:child_process';
import fs from 'node:fs';
const { generatorHandler } = pkg;
const FILE_PATH = '<PATH>/index.ts';
generatorHandler({
onManifest: () => {
return {};
},
onGenerate: async (config) => {
const data = fs.readFileSync(FILE_PATH, 'utf8');
// Replace content using a regex
const updatedData = data
.replace("import { Prisma } from '@prisma/client';", '')
.replace(/\/\/ JSON([\S\s\/-]*)\/\/ ENUMS/m, '// Deleted by helper')
.replace(/JsonValueSchema.nullable\(\)/gm, 'z.any()')
.replace(
/(.*(NullableJsonNullValueInputSchema|JsonNullValueFilterSchema).*)/gm,
''
);
// Write the updated content back to the file
fs.writeFileSync(FILE_PATH, updatedData, 'utf8');
execSync(
'npx prettier --write src/abrico-lib-shared/generated/prisma-zod/index.ts'
);
},
}); |
Is your feature request related to a problem? Please describe.
Hi there, thanks for this amazing generator. We are trying to export the schema validation inside a monorepo. The reason is kind of reusing the schema as validation for forms in the frontend and the backend. When the schema types are generated in a different package inside the monorepo though the
@prisma/client
is not present. We are trying to use the package as follow:The generated output inside the
packages/zod
is not aware of the@prisma/client
required from the generated output since it's a different package reused by both a client and backend application.Describe the solution you'd like
Maybe provide our own types somehow through a config file like:
Or somehow skip nullish checking through configuration.
Describe alternatives you've considered
A quick and dirty patch is to trick typescript to import
@prisma/client
as my own types through aliasing.Once again thanks ton for your amazing work. Keep up.
The text was updated successfully, but these errors were encountered: