Skip to content
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

fix #99 #100

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 7 additions & 7 deletions examples/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"compilerOptions": {
"sourceMap": true,
"outDir": "dist",
"strict": true,
"lib": ["esnext"],
"esModuleInterop": true
}
"compilerOptions": {
"sourceMap": true,
"outDir": "dist",
"strict": true,
"lib": ["esnext"],
"esModuleInterop": true
}
}
22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "zod-prisma",
"version": "0.5.4",
"version": "0.5.5",
"description": "A Prisma generator that creates Zod schemas for all of your models",
"license": "MIT",
"author": "Carter Grimmeisen",
Expand Down Expand Up @@ -52,24 +52,24 @@
"testEnvironment": "node"
},
"dependencies": {
"@prisma/generator-helper": "~3.8.1",
"@prisma/generator-helper": "~3.10.0",
"parenthesis": "^3.1.8",
"ts-morph": "^13.0.2"
"ts-morph": "^13.0.3"
},
"devDependencies": {
"@prisma/client": "~3.8.1",
"@prisma/sdk": "~3.7.0",
"@prisma/client": "~3.10.0",
"@prisma/sdk": "~3.10.0",
"@tsconfig/recommended": "^1.0.1",
"@types/fs-extra": "^9.0.13",
"dts-cli": "^1.1.5",
"execa": "^5.1.0",
"fast-glob": "^3.2.5",
"fs-extra": "^10.0.0",
"dts-cli": "^1.4.0",
"execa": "^5.1.1",
"fast-glob": "^3.2.11",
"fs-extra": "^10.0.1",
"husky": "^7.0.4",
"jest-mock-extended": "^2.0.4",
"prisma": "^3.4.2",
"prisma": "^3.10.0",
"tslib": "^2.3.1",
"typescript": "^4.5.4",
"typescript": "^4.5.5",
"zod": "^3.11.6"
},
"peerDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion src/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const writeImportsForModel = (
kind: StructureKind.ImportDeclaration,
isTypeOnly: enumFields.length === 0,
moduleSpecifier: dotSlash(relativePath),
namedImports: enumFields.map((f) => f.type),
defaultImport: 'prisma',
})
}

Expand Down
16 changes: 14 additions & 2 deletions src/test/functional/driver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,22 @@ describe('Functional Tests', () => {
test.concurrent('Optional fields', ftForDir('optional'))
test.concurrent('Config Import', ftForDir('config-import'))

test.concurrent('Type Check Everything', async () => {
test('Type Check Everything', async () => {
const typeCheckResults = await execa(
path.resolve(__dirname, '../../../node_modules/.bin/tsc'),
['--strict', '--noEmit', ...(await glob(`${__dirname}/*/expected/*.ts`))]
[
'--strict',
'--noEmit',
'--esModuleInterop',
'--allowSyntheticDefaultImports',
'--target',
'esnext',
'--module',
'esnext',
'--moduleResolution',
'node',
...(await glob(`${__dirname}/*/expected/*.ts`)),
]
)

expect(typeCheckResults.exitCode).toBe(0)
Expand Down
4 changes: 2 additions & 2 deletions src/test/functional/imports/expected/document.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import * as z from "zod"
import { Status } from "../prisma/.client"
import prisma from "../prisma/.client"

export const DocumentModel = z.object({
id: z.string(),
filename: z.string(),
author: z.string(),
contents: z.string(),
status: z.nativeEnum(Status),
status: z.nativeEnum(prisma.Status),
created: z.date(),
updated: z.date(),
})
5 changes: 5 additions & 0 deletions src/test/functional/imports/prisma/.client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,8 @@ export const Status = {
}

export type Status = typeof Status[keyof typeof Status]

// TODO figure out why TSC fails and we ahd to add this explicitly
export default {
Status,
}
2 changes: 1 addition & 1 deletion src/test/regressions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('Regression Tests', () => {
writeImportsForModel(model, testFile, config, prismaOptions)

expect(testFile.print()).toBe(
'import * as z from "zod";\nimport { UserType } from "@prisma/client";\n'
'import * as z from "zod";\nimport prisma from "@prisma/client";\n'
)
})
})
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const getZodConstructor = (
break
}
} else if (field.kind === 'enum') {
zodType = `z.nativeEnum(${field.type})`
zodType = `z.nativeEnum(prisma.${field.type})`
} else if (field.kind === 'object') {
zodType = getRelatedModelName(field.type)
}
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"noEmit": true,
"downlevelIteration": true,
"resolveJsonModule": true,
"allowSyntheticDefaultImports": true,
"noErrorTruncation": true
}
}