| 1 | import "./validation.ts"; |
| 2 | import { defineContract } from "alchemy/Prisma/ORM"; |
| 3 | |
| 4 | export const contract = defineContract( |
| 5 | { extensions: {} }, |
| 6 | ({ field, model, rel }) => ({ |
| 7 | models: { |
| 8 | User: model("User", { |
| 9 | fields: { |
| 10 | id: field.id.uuidv7Native(), |
| 11 | email: field.text().unique(), |
| 12 | name: field.text(), |
| 13 | createdAt: field.temporal.createdAtString(), |
| 14 | }, |
| 15 | relations: { |
| 16 | posts: rel.hasMany("Post", { by: "authorId" }), |
| 17 | }, |
| 18 | }), |
| 19 | |
| 20 | Post: model("Post", { |
| 21 | fields: { |
| 22 | id: field.id.uuidv7Native(), |
| 23 | title: field.text(), |
| 24 | authorId: field.uuidNative(), |
| 25 | }, |
| 26 | relations: { |
| 27 | author: rel.belongsTo("User", { from: "authorId", to: "id" }), |
| 28 | }, |
| 29 | }), |
| 30 | }, |
| 31 | }), |
| 32 | ); |