From 680517d195f37c116f28f645d19e7b1dca29b178 Mon Sep 17 00:00:00 2001 From: Gabriel Date: Mon, 22 Jan 2024 12:06:04 -0300 Subject: [PATCH] chore: Make zod work with prisma --- package-lock.json | 80 ++++++++++++++++--- package.json | 3 +- prisma/generated/zod/index.ts | 2 + .../zod/inputTypeSchemas/NullsOrderSchema.ts | 5 ++ .../zod/inputTypeSchemas/QueryModeSchema.ts | 5 ++ .../SessionScalarFieldEnumSchema.ts | 12 +++ .../zod/inputTypeSchemas/SortOrderSchema.ts | 5 ++ .../TokensScalarFieldEnumSchema.ts | 13 +++ .../TransactionIsolationLevelSchema.ts | 10 +++ .../zod/inputTypeSchemas/TypeTokenSchema.ts | 7 ++ .../UserScalarFieldEnumSchema.ts | 12 +++ .../generated/zod/inputTypeSchemas/index.ts | 8 ++ .../zod/modelSchema/SessionSchema.ts | 18 +++++ .../generated/zod/modelSchema/TokensSchema.ts | 20 +++++ .../generated/zod/modelSchema/UserSchema.ts | 18 +++++ prisma/generated/zod/modelSchema/index.ts | 3 + prisma/schema.prisma | 6 ++ tsconfig.json | 1 + 18 files changed, 218 insertions(+), 10 deletions(-) create mode 100644 prisma/generated/zod/index.ts create mode 100644 prisma/generated/zod/inputTypeSchemas/NullsOrderSchema.ts create mode 100644 prisma/generated/zod/inputTypeSchemas/QueryModeSchema.ts create mode 100644 prisma/generated/zod/inputTypeSchemas/SessionScalarFieldEnumSchema.ts create mode 100644 prisma/generated/zod/inputTypeSchemas/SortOrderSchema.ts create mode 100644 prisma/generated/zod/inputTypeSchemas/TokensScalarFieldEnumSchema.ts create mode 100644 prisma/generated/zod/inputTypeSchemas/TransactionIsolationLevelSchema.ts create mode 100644 prisma/generated/zod/inputTypeSchemas/TypeTokenSchema.ts create mode 100644 prisma/generated/zod/inputTypeSchemas/UserScalarFieldEnumSchema.ts create mode 100644 prisma/generated/zod/inputTypeSchemas/index.ts create mode 100644 prisma/generated/zod/modelSchema/SessionSchema.ts create mode 100644 prisma/generated/zod/modelSchema/TokensSchema.ts create mode 100644 prisma/generated/zod/modelSchema/UserSchema.ts create mode 100644 prisma/generated/zod/modelSchema/index.ts diff --git a/package-lock.json b/package-lock.json index 021a899..f348bb4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -40,7 +40,8 @@ "tsconfig-paths": "^4.1.2", "tsoa": "^5.1.1", "winston": "^3.6.0", - "zod": "^3.22.4" + "zod": "^3.22.4", + "zod-prisma-types": "^3.1.6" }, "devDependencies": { "@faker-js/faker": "^8.0.2", @@ -1369,6 +1370,11 @@ } } }, + "node_modules/@prisma/debug": { + "version": "5.8.1", + "resolved": "https://registry.npmjs.org/@prisma/debug/-/debug-5.8.1.tgz", + "integrity": "sha512-tjuw7eA0Us3T42jx9AmAgL58rzwzpFGYc3R7Y4Ip75EBYrKMBA1YihuWMcBC92ILmjlQ/u3p8VxcIE0hr+fZfg==" + }, "node_modules/@prisma/engines": { "version": "5.5.2", "resolved": "https://registry.npmjs.org/@prisma/engines/-/engines-5.5.2.tgz", @@ -1380,6 +1386,14 @@ "resolved": "https://registry.npmjs.org/@prisma/engines-version/-/engines-version-5.5.1-1.aebc046ce8b88ebbcb45efe31cbe7d06fd6abc0a.tgz", "integrity": "sha512-O+qHFnZvAyOFk1tUco2/VdiqS0ym42a3+6CYLScllmnpbyiTplgyLt2rK/B9BTjYkSHjrgMhkG47S0oqzdIckA==" }, + "node_modules/@prisma/generator-helper": { + "version": "5.8.1", + "resolved": "https://registry.npmjs.org/@prisma/generator-helper/-/generator-helper-5.8.1.tgz", + "integrity": "sha512-2EDd0o+GHfbX1dtw5BnfOz3hQB7AtYrwe4YNiKfo2UDBvB/ne/ChZa3b/vBm/GKpjW2Xaymct8D9oIHev3juzQ==", + "dependencies": { + "@prisma/debug": "5.8.1" + } + }, "node_modules/@sinclair/typebox": { "version": "0.27.8", "resolved": "https://registry.npmjs.org/@sinclair/typebox/-/typebox-0.27.8.tgz", @@ -2802,6 +2816,11 @@ "node": ">= 0.12.0" } }, + "node_modules/code-block-writer": { + "version": "12.0.0", + "resolved": "https://registry.npmjs.org/code-block-writer/-/code-block-writer-12.0.0.tgz", + "integrity": "sha512-q4dMFMlXtKR3XNBHyMHt/3pwYNA69EDk00lloMOaaUMKPUXBw6lpXtbu3MMVG6/uOihGnRDOlkyqsONEUj60+w==" + }, "node_modules/collect-v8-coverage": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/collect-v8-coverage/-/collect-v8-coverage-1.0.2.tgz", @@ -4515,14 +4534,14 @@ } }, "node_modules/glob": { - "version": "7.1.7", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.7.tgz", - "integrity": "sha512-OvD9ENzPLbegENnYP5UUfJIirTg4+XwMWGaQfQTY0JenxNvvIKP3U3/tAQSPIu/lHxXYSZmpXlUHeqAIdKzBLQ==", + "version": "7.2.3", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", + "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==", "dependencies": { "fs.realpath": "^1.0.0", "inflight": "^1.0.4", "inherits": "2", - "minimatch": "^3.0.4", + "minimatch": "^3.1.1", "once": "^1.3.0", "path-is-absolute": "^1.0.0" }, @@ -8644,6 +8663,20 @@ "funding": { "url": "https://github.com/sponsors/colinhacks" } + }, + "node_modules/zod-prisma-types": { + "version": "3.1.6", + "resolved": "https://registry.npmjs.org/zod-prisma-types/-/zod-prisma-types-3.1.6.tgz", + "integrity": "sha512-ySaG91RraTm4J19zfvuX6S3OxhDMlK4dTfYWM4rS+4AlEGqDqGu5BbIn2trjTDt8OiCMBHoIjZmRXPKQCyNApA==", + "dependencies": { + "@prisma/generator-helper": "^5.5.2", + "code-block-writer": "^12.0.0", + "lodash": "^4.17.21", + "zod": "^3.22.4" + }, + "bin": { + "zod-prisma-types": "dist/bin.js" + } } }, "dependencies": { @@ -9587,6 +9620,11 @@ "@prisma/engines-version": "5.5.1-1.aebc046ce8b88ebbcb45efe31cbe7d06fd6abc0a" } }, + "@prisma/debug": { + "version": "5.8.1", + "resolved": "https://registry.npmjs.org/@prisma/debug/-/debug-5.8.1.tgz", + "integrity": "sha512-tjuw7eA0Us3T42jx9AmAgL58rzwzpFGYc3R7Y4Ip75EBYrKMBA1YihuWMcBC92ILmjlQ/u3p8VxcIE0hr+fZfg==" + }, "@prisma/engines": { "version": "5.5.2", "resolved": "https://registry.npmjs.org/@prisma/engines/-/engines-5.5.2.tgz", @@ -9597,6 +9635,14 @@ "resolved": "https://registry.npmjs.org/@prisma/engines-version/-/engines-version-5.5.1-1.aebc046ce8b88ebbcb45efe31cbe7d06fd6abc0a.tgz", "integrity": "sha512-O+qHFnZvAyOFk1tUco2/VdiqS0ym42a3+6CYLScllmnpbyiTplgyLt2rK/B9BTjYkSHjrgMhkG47S0oqzdIckA==" }, + "@prisma/generator-helper": { + "version": "5.8.1", + "resolved": "https://registry.npmjs.org/@prisma/generator-helper/-/generator-helper-5.8.1.tgz", + "integrity": "sha512-2EDd0o+GHfbX1dtw5BnfOz3hQB7AtYrwe4YNiKfo2UDBvB/ne/ChZa3b/vBm/GKpjW2Xaymct8D9oIHev3juzQ==", + "requires": { + "@prisma/debug": "5.8.1" + } + }, "@sinclair/typebox": { "version": "0.27.8", "resolved": "https://registry.npmjs.org/@sinclair/typebox/-/typebox-0.27.8.tgz", @@ -10670,6 +10716,11 @@ "resolved": "https://registry.npmjs.org/co/-/co-4.6.0.tgz", "integrity": "sha512-QVb0dM5HvG+uaxitm8wONl7jltx8dqhfU33DcqtOZcLSVIKSDDLDi7+0LbAKiyI8hD9u42m2YxXSkMGWThaecQ==" }, + "code-block-writer": { + "version": "12.0.0", + "resolved": "https://registry.npmjs.org/code-block-writer/-/code-block-writer-12.0.0.tgz", + "integrity": "sha512-q4dMFMlXtKR3XNBHyMHt/3pwYNA69EDk00lloMOaaUMKPUXBw6lpXtbu3MMVG6/uOihGnRDOlkyqsONEUj60+w==" + }, "collect-v8-coverage": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/collect-v8-coverage/-/collect-v8-coverage-1.0.2.tgz", @@ -11943,14 +11994,14 @@ } }, "glob": { - "version": "7.1.7", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.7.tgz", - "integrity": "sha512-OvD9ENzPLbegENnYP5UUfJIirTg4+XwMWGaQfQTY0JenxNvvIKP3U3/tAQSPIu/lHxXYSZmpXlUHeqAIdKzBLQ==", + "version": "7.2.3", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", + "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==", "requires": { "fs.realpath": "^1.0.0", "inflight": "^1.0.4", "inherits": "2", - "minimatch": "^3.0.4", + "minimatch": "^3.1.1", "once": "^1.3.0", "path-is-absolute": "^1.0.0" } @@ -14904,6 +14955,17 @@ "version": "3.22.4", "resolved": "https://registry.npmjs.org/zod/-/zod-3.22.4.tgz", "integrity": "sha512-iC+8Io04lddc+mVqQ9AZ7OQ2MrUKGN+oIQyq1vemgt46jwCwLfhq7/pwnBnNXXXZb8VTVLKwp9EDkx+ryxIWmg==" + }, + "zod-prisma-types": { + "version": "3.1.6", + "resolved": "https://registry.npmjs.org/zod-prisma-types/-/zod-prisma-types-3.1.6.tgz", + "integrity": "sha512-ySaG91RraTm4J19zfvuX6S3OxhDMlK4dTfYWM4rS+4AlEGqDqGu5BbIn2trjTDt8OiCMBHoIjZmRXPKQCyNApA==", + "requires": { + "@prisma/generator-helper": "^5.5.2", + "code-block-writer": "^12.0.0", + "lodash": "^4.17.21", + "zod": "^3.22.4" + } } } } diff --git a/package.json b/package.json index 0e6a67b..240ddeb 100644 --- a/package.json +++ b/package.json @@ -93,6 +93,7 @@ "tsconfig-paths": "^4.1.2", "tsoa": "^5.1.1", "winston": "^3.6.0", - "zod": "^3.22.4" + "zod": "^3.22.4", + "zod-prisma-types": "^3.1.6" } } diff --git a/prisma/generated/zod/index.ts b/prisma/generated/zod/index.ts new file mode 100644 index 0000000..17b9080 --- /dev/null +++ b/prisma/generated/zod/index.ts @@ -0,0 +1,2 @@ +export * from './modelSchema'; +export * from './inputTypeSchemas'; diff --git a/prisma/generated/zod/inputTypeSchemas/NullsOrderSchema.ts b/prisma/generated/zod/inputTypeSchemas/NullsOrderSchema.ts new file mode 100644 index 0000000..2c02d92 --- /dev/null +++ b/prisma/generated/zod/inputTypeSchemas/NullsOrderSchema.ts @@ -0,0 +1,5 @@ +import { z } from 'zod'; + +export const NullsOrderSchema = z.enum(['first', 'last']); + +export default NullsOrderSchema; diff --git a/prisma/generated/zod/inputTypeSchemas/QueryModeSchema.ts b/prisma/generated/zod/inputTypeSchemas/QueryModeSchema.ts new file mode 100644 index 0000000..5791196 --- /dev/null +++ b/prisma/generated/zod/inputTypeSchemas/QueryModeSchema.ts @@ -0,0 +1,5 @@ +import { z } from 'zod'; + +export const QueryModeSchema = z.enum(['default', 'insensitive']); + +export default QueryModeSchema; diff --git a/prisma/generated/zod/inputTypeSchemas/SessionScalarFieldEnumSchema.ts b/prisma/generated/zod/inputTypeSchemas/SessionScalarFieldEnumSchema.ts new file mode 100644 index 0000000..9c1d4dd --- /dev/null +++ b/prisma/generated/zod/inputTypeSchemas/SessionScalarFieldEnumSchema.ts @@ -0,0 +1,12 @@ +import { z } from 'zod'; + +export const SessionScalarFieldEnumSchema = z.enum([ + 'id', + 'createdAt', + 'updatedAt', + 'userId', + 'accessToken', + 'refreshToken', +]); + +export default SessionScalarFieldEnumSchema; diff --git a/prisma/generated/zod/inputTypeSchemas/SortOrderSchema.ts b/prisma/generated/zod/inputTypeSchemas/SortOrderSchema.ts new file mode 100644 index 0000000..cc63701 --- /dev/null +++ b/prisma/generated/zod/inputTypeSchemas/SortOrderSchema.ts @@ -0,0 +1,5 @@ +import { z } from 'zod'; + +export const SortOrderSchema = z.enum(['asc', 'desc']); + +export default SortOrderSchema; diff --git a/prisma/generated/zod/inputTypeSchemas/TokensScalarFieldEnumSchema.ts b/prisma/generated/zod/inputTypeSchemas/TokensScalarFieldEnumSchema.ts new file mode 100644 index 0000000..7c73df1 --- /dev/null +++ b/prisma/generated/zod/inputTypeSchemas/TokensScalarFieldEnumSchema.ts @@ -0,0 +1,13 @@ +import { z } from 'zod'; + +export const TokensScalarFieldEnumSchema = z.enum([ + 'id', + 'createdAt', + 'updatedAt', + 'token', + 'type', + 'expiresAt', + 'userId', +]); + +export default TokensScalarFieldEnumSchema; diff --git a/prisma/generated/zod/inputTypeSchemas/TransactionIsolationLevelSchema.ts b/prisma/generated/zod/inputTypeSchemas/TransactionIsolationLevelSchema.ts new file mode 100644 index 0000000..b2d382c --- /dev/null +++ b/prisma/generated/zod/inputTypeSchemas/TransactionIsolationLevelSchema.ts @@ -0,0 +1,10 @@ +import { z } from 'zod'; + +export const TransactionIsolationLevelSchema = z.enum([ + 'ReadUncommitted', + 'ReadCommitted', + 'RepeatableRead', + 'Serializable', +]); + +export default TransactionIsolationLevelSchema; diff --git a/prisma/generated/zod/inputTypeSchemas/TypeTokenSchema.ts b/prisma/generated/zod/inputTypeSchemas/TypeTokenSchema.ts new file mode 100644 index 0000000..2a1a598 --- /dev/null +++ b/prisma/generated/zod/inputTypeSchemas/TypeTokenSchema.ts @@ -0,0 +1,7 @@ +import { z } from 'zod'; + +export const TypeTokenSchema = z.enum(['RESET_PASSWORD']); + +export type TypeTokenType = `${z.infer}`; + +export default TypeTokenSchema; diff --git a/prisma/generated/zod/inputTypeSchemas/UserScalarFieldEnumSchema.ts b/prisma/generated/zod/inputTypeSchemas/UserScalarFieldEnumSchema.ts new file mode 100644 index 0000000..bfea896 --- /dev/null +++ b/prisma/generated/zod/inputTypeSchemas/UserScalarFieldEnumSchema.ts @@ -0,0 +1,12 @@ +import { z } from 'zod'; + +export const UserScalarFieldEnumSchema = z.enum([ + 'id', + 'createdAt', + 'updatedAt', + 'email', + 'password', + 'name', +]); + +export default UserScalarFieldEnumSchema; diff --git a/prisma/generated/zod/inputTypeSchemas/index.ts b/prisma/generated/zod/inputTypeSchemas/index.ts new file mode 100644 index 0000000..b8fbe20 --- /dev/null +++ b/prisma/generated/zod/inputTypeSchemas/index.ts @@ -0,0 +1,8 @@ +export { TransactionIsolationLevelSchema } from './TransactionIsolationLevelSchema'; +export { UserScalarFieldEnumSchema } from './UserScalarFieldEnumSchema'; +export { SessionScalarFieldEnumSchema } from './SessionScalarFieldEnumSchema'; +export { TokensScalarFieldEnumSchema } from './TokensScalarFieldEnumSchema'; +export { SortOrderSchema } from './SortOrderSchema'; +export { QueryModeSchema } from './QueryModeSchema'; +export { NullsOrderSchema } from './NullsOrderSchema'; +export { TypeTokenSchema } from './TypeTokenSchema'; diff --git a/prisma/generated/zod/modelSchema/SessionSchema.ts b/prisma/generated/zod/modelSchema/SessionSchema.ts new file mode 100644 index 0000000..dfe45f2 --- /dev/null +++ b/prisma/generated/zod/modelSchema/SessionSchema.ts @@ -0,0 +1,18 @@ +import { z } from 'zod'; + +///////////////////////////////////////// +// SESSION SCHEMA +///////////////////////////////////////// + +export const SessionSchema = z.object({ + id: z.string().uuid(), + createdAt: z.coerce.date(), + updatedAt: z.coerce.date(), + userId: z.string(), + accessToken: z.string(), + refreshToken: z.string(), +}); + +export type Session = z.infer; + +export default SessionSchema; diff --git a/prisma/generated/zod/modelSchema/TokensSchema.ts b/prisma/generated/zod/modelSchema/TokensSchema.ts new file mode 100644 index 0000000..ae8adc9 --- /dev/null +++ b/prisma/generated/zod/modelSchema/TokensSchema.ts @@ -0,0 +1,20 @@ +import { z } from 'zod'; +import { TypeTokenSchema } from '../inputTypeSchemas/TypeTokenSchema'; + +///////////////////////////////////////// +// TOKENS SCHEMA +///////////////////////////////////////// + +export const TokensSchema = z.object({ + type: TypeTokenSchema, + id: z.string().uuid(), + createdAt: z.coerce.date(), + updatedAt: z.coerce.date(), + token: z.string(), + expiresAt: z.coerce.date(), + userId: z.string().nullable(), +}); + +export type Tokens = z.infer; + +export default TokensSchema; diff --git a/prisma/generated/zod/modelSchema/UserSchema.ts b/prisma/generated/zod/modelSchema/UserSchema.ts new file mode 100644 index 0000000..289b6c1 --- /dev/null +++ b/prisma/generated/zod/modelSchema/UserSchema.ts @@ -0,0 +1,18 @@ +import { z } from 'zod'; + +///////////////////////////////////////// +// USER SCHEMA +///////////////////////////////////////// + +export const UserSchema = z.object({ + id: z.string().uuid(), + createdAt: z.coerce.date(), + updatedAt: z.coerce.date(), + email: z.string(), + password: z.string(), + name: z.string().nullable(), +}); + +export type User = z.infer; + +export default UserSchema; diff --git a/prisma/generated/zod/modelSchema/index.ts b/prisma/generated/zod/modelSchema/index.ts new file mode 100644 index 0000000..512eba1 --- /dev/null +++ b/prisma/generated/zod/modelSchema/index.ts @@ -0,0 +1,3 @@ +export * from './UserSchema'; +export * from './SessionSchema'; +export * from './TokensSchema'; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 1b1ab6f..4fd5e80 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -6,6 +6,12 @@ generator client { binaryTargets = ["native", "linux-musl", "linux-musl-openssl-3.0.x"] } +generator zod { + provider = "zod-prisma-types" + useMultipleFiles = true + createInputTypes = false +} + datasource db { provider = "postgresql" url = env("DATABASE_URL") diff --git a/tsconfig.json b/tsconfig.json index 8e5b07a..2a7c1e4 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,6 +7,7 @@ "esModuleInterop": true, "forceConsistentCasingInFileNames": true, "strict": true, + "strictNullChecks": true, "skipLibCheck": true, "experimentalDecorators": true, "emitDecoratorMetadata": true,