Using zod-prisma-types ❤️
This commit is contained in:
parent
c895bcef19
commit
d3e8a43b34
7 changed files with 4536 additions and 16 deletions
|
@ -1,13 +1,8 @@
|
|||
import { GameState } from "@prisma/client"
|
||||
import { GameSchema } from "../prisma/generated/zod"
|
||||
import { z } from "zod"
|
||||
|
||||
export const createSchema = z.object({
|
||||
game: z.object({
|
||||
id: z.string(),
|
||||
createdAt: z.date(),
|
||||
updatedAt: z.date(),
|
||||
state: z.nativeEnum(GameState),
|
||||
}),
|
||||
export const CreateSchema = z.object({
|
||||
game: GameSchema.strict(),
|
||||
pin: z.string().optional(),
|
||||
player: z.object({
|
||||
id: z.string(),
|
||||
|
|
|
@ -37,7 +37,8 @@
|
|||
"socket.io-client": "^4.6.1",
|
||||
"typescript": "4.9.4",
|
||||
"unique-names-generator": "^4.7.1",
|
||||
"zod": "^3.21.4"
|
||||
"zod": "^3.21.1",
|
||||
"zod-prisma-types": "^2.5.6"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@total-typescript/ts-reset": "^0.3.7",
|
||||
|
|
|
@ -3,12 +3,12 @@ import { getAnyRunningGame } from "./running"
|
|||
import sendResponse from "@backend/sendResponse"
|
||||
import { rejectionErrors } from "@lib/backend/errors"
|
||||
import prisma from "@lib/prisma"
|
||||
import { createSchema } from "@lib/zodSchemas"
|
||||
import { CreateSchema } from "@lib/zodSchemas"
|
||||
import type { NextApiRequest, NextApiResponse } from "next"
|
||||
import { getServerSession } from "next-auth"
|
||||
import { z } from "zod"
|
||||
|
||||
type Data = z.infer<typeof createSchema>
|
||||
type Data = z.infer<typeof CreateSchema>
|
||||
|
||||
export default async function create(
|
||||
req: NextApiRequest,
|
||||
|
|
|
@ -5,7 +5,7 @@ import { faEye, faLeftLong } from "@fortawesome/pro-regular-svg-icons"
|
|||
import { faPlus, faUserPlus } from "@fortawesome/pro-solid-svg-icons"
|
||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"
|
||||
import useGameState from "@lib/hooks/useGameState"
|
||||
import { createSchema } from "@lib/zodSchemas"
|
||||
import { CreateSchema } from "@lib/zodSchemas"
|
||||
import status from "http-status"
|
||||
import { GetServerSideProps } from "next"
|
||||
import { useRouter } from "next/router"
|
||||
|
@ -61,7 +61,7 @@ export default function Home({ q }: Props) {
|
|||
body: JSON.stringify({ pin }),
|
||||
})
|
||||
.then(isAuthenticated)
|
||||
.then((game) => createSchema.parse(game))
|
||||
.then((game) => CreateSchema.parse(game))
|
||||
|
||||
const res = await toast.promise(gamePromise, {
|
||||
pending: {
|
||||
|
|
65
leaky-ships/pnpm-lock.yaml
generated
65
leaky-ships/pnpm-lock.yaml
generated
|
@ -86,8 +86,11 @@ dependencies:
|
|||
specifier: ^4.7.1
|
||||
version: 4.7.1
|
||||
zod:
|
||||
specifier: ^3.21.4
|
||||
version: 3.21.4
|
||||
specifier: ^3.21.1
|
||||
version: 3.21.1
|
||||
zod-prisma-types:
|
||||
specifier: ^2.5.6
|
||||
version: 2.5.6
|
||||
|
||||
devDependencies:
|
||||
'@total-typescript/ts-reset':
|
||||
|
@ -548,6 +551,16 @@ packages:
|
|||
prisma: 4.12.0
|
||||
dev: false
|
||||
|
||||
/@prisma/debug@4.13.0:
|
||||
resolution: {integrity: sha512-JrltTewF/paRb5mcM5OvcEi9DtdX0sINOAswruxKQrwOLA7Phqb52OfY38MIzGrsrJ8iUGVqQ5bpYZYpxOGCsQ==}
|
||||
dependencies:
|
||||
'@types/debug': 4.1.7
|
||||
debug: 4.3.4
|
||||
strip-ansi: 6.0.1
|
||||
transitivePeerDependencies:
|
||||
- supports-color
|
||||
dev: false
|
||||
|
||||
/@prisma/engines-version@4.12.0-67.659ef412370fa3b41cd7bf6e94587c1dfb7f67e7:
|
||||
resolution: {integrity: sha512-JIHNj5jlXb9mcaJwakM0vpgRYJIAurxTUqM0iX0tfEQA5XLZ9ONkIckkhuAKdAzocZ+80GYg7QSsfpjg7OxbOA==}
|
||||
dev: false
|
||||
|
@ -557,6 +570,17 @@ packages:
|
|||
requiresBuild: true
|
||||
dev: false
|
||||
|
||||
/@prisma/generator-helper@4.13.0:
|
||||
resolution: {integrity: sha512-Zx9rtbsEIU/9DKnGRvmjLdyeyhzeeXNFp1alkRh1w//rQ5jTcobiay/jU4Qo+EQOs2bnWEfUeiBoOjfaysdLNg==}
|
||||
dependencies:
|
||||
'@prisma/debug': 4.13.0
|
||||
'@types/cross-spawn': 6.0.2
|
||||
chalk: 4.1.2
|
||||
cross-spawn: 7.0.3
|
||||
transitivePeerDependencies:
|
||||
- supports-color
|
||||
dev: false
|
||||
|
||||
/@rushstack/eslint-patch@1.2.0:
|
||||
resolution: {integrity: sha512-sXo/qW2/pAcmT43VoRKOJbDOfV3cYpq3szSVfIThQXNt+E4DfKj361vaAt3c88U5tPUxzEswam7GW48PJqtKAg==}
|
||||
dev: false
|
||||
|
@ -605,10 +629,26 @@ packages:
|
|||
'@types/node': 18.15.11
|
||||
dev: false
|
||||
|
||||
/@types/cross-spawn@6.0.2:
|
||||
resolution: {integrity: sha512-KuwNhp3eza+Rhu8IFI5HUXRP0LIhqH5cAjubUvGXXthh4YYBuP2ntwEX+Cz8GJoZUHlKo247wPWOfA9LYEq4cw==}
|
||||
dependencies:
|
||||
'@types/node': 18.15.11
|
||||
dev: false
|
||||
|
||||
/@types/debug@4.1.7:
|
||||
resolution: {integrity: sha512-9AonUzyTjXXhEOa0DnqpzZi6VHlqKMswga9EXjpXnnqxwLtdvPPtlO8evrI5D9S6asFRCQ6v+wpiUKbw+vKqyg==}
|
||||
dependencies:
|
||||
'@types/ms': 0.7.31
|
||||
dev: false
|
||||
|
||||
/@types/json5@0.0.29:
|
||||
resolution: {integrity: sha512-dRLjCWHYg4oaA77cxO64oO+7JwCwnIzkZPdrrC71jQmQtlhM556pwKo5bUzqvZndkVbeFLIIi+9TC40JNF5hNQ==}
|
||||
dev: false
|
||||
|
||||
/@types/ms@0.7.31:
|
||||
resolution: {integrity: sha512-iiUgKzV9AuaEkZqkOLDIvlQiL6ltuZd9tGcW3gwpnX8JbuiuhFlEGmmFXEXkN50Cvq7Os88IY2v0dkDqXYWVgA==}
|
||||
dev: false
|
||||
|
||||
/@types/node@18.15.11:
|
||||
resolution: {integrity: sha512-E5Kwq2n4SbMzQOn6wnmBjuK9ouqlURrcZDVfbo9ftDDTFt3nk7ZKK4GMOzoYgnpQJKcxwQw+lGaBvvlMo0qN/Q==}
|
||||
|
||||
|
@ -955,6 +995,10 @@ packages:
|
|||
engines: {node: '>=6'}
|
||||
dev: false
|
||||
|
||||
/code-block-writer@11.0.3:
|
||||
resolution: {integrity: sha512-NiujjUFB4SwScJq2bwbYUtXbZhBSlY6vYzm++3Q6oC+U+injTqfPYFK8wS9COOmb2lueqp0ZRB4nK1VYeHgNyw==}
|
||||
dev: false
|
||||
|
||||
/color-convert@1.9.3:
|
||||
resolution: {integrity: sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==}
|
||||
dependencies:
|
||||
|
@ -2105,7 +2149,6 @@ packages:
|
|||
|
||||
/lodash@4.17.21:
|
||||
resolution: {integrity: sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==}
|
||||
dev: true
|
||||
|
||||
/loose-envify@1.4.0:
|
||||
resolution: {integrity: sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==}
|
||||
|
@ -3227,6 +3270,22 @@ packages:
|
|||
resolution: {integrity: sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==}
|
||||
engines: {node: '>=10'}
|
||||
|
||||
/zod-prisma-types@2.5.6:
|
||||
resolution: {integrity: sha512-Cck7hzz15t4+ADmoZWa475fPiDxxd1/hve+vfS85BsEVr3u8y3zphKi/5/yhkT/mKuJhiMkIfc4VJLrJt/cTpw==}
|
||||
hasBin: true
|
||||
dependencies:
|
||||
'@prisma/generator-helper': 4.13.0
|
||||
code-block-writer: 11.0.3
|
||||
lodash: 4.17.21
|
||||
zod: 3.21.4
|
||||
transitivePeerDependencies:
|
||||
- supports-color
|
||||
dev: false
|
||||
|
||||
/zod@3.21.1:
|
||||
resolution: {integrity: sha512-+dTu2m6gmCbO9Ahm4ZBDapx2O6ZY9QSPXst2WXjcznPMwf2YNpn3RevLx4KkZp1OPW/ouFcoBtBzFz/LeY69oA==}
|
||||
dev: false
|
||||
|
||||
/zod@3.21.4:
|
||||
resolution: {integrity: sha512-m46AKbrzKVzOzs/DZgVnG5H55N1sv1M8qZU3A8RIKbs3mrACDNeIOeilDymVb2HdmP8uwshOCF4uJ8uM9rCqJw==}
|
||||
dev: false
|
||||
|
|
4461
leaky-ships/prisma/generated/zod/index.ts
Normal file
4461
leaky-ships/prisma/generated/zod/index.ts
Normal file
File diff suppressed because it is too large
Load diff
|
@ -1,3 +1,7 @@
|
|||
generator zod {
|
||||
provider = "zod-prisma-types"
|
||||
}
|
||||
|
||||
generator client {
|
||||
provider = "prisma-client-js"
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue