{"id":13767643,"url":"https://github.com/omar-dulaimi/prisma-trpc-generator","last_synced_at":"2025-05-15T19:07:46.662Z","repository":{"id":39092285,"uuid":"490414296","full_name":"omar-dulaimi/prisma-trpc-generator","owner":"omar-dulaimi","description":"Prisma 2+ generator to emit fully implemented tRPC routers","archived":false,"fork":false,"pushed_at":"2024-04-11T17:51:52.000Z","size":2211,"stargazers_count":690,"open_issues_count":13,"forks_count":32,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-05-09T22:37:17.358Z","etag":null,"topics":["prisma","prisma-generator","trpc","zod"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/omar-dulaimi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"omar-dulaimi","custom":["https://www.buymeacoffee.com/omardulaimi"]}},"created_at":"2022-05-09T19:15:42.000Z","updated_at":"2025-05-02T20:42:39.000Z","dependencies_parsed_at":"2024-01-25T23:08:53.195Z","dependency_job_id":"bc5a0345-e620-4d0d-be66-37077db27312","html_url":"https://github.com/omar-dulaimi/prisma-trpc-generator","commit_stats":{"total_commits":150,"total_committers":10,"mean_commits":15.0,"dds":0.1466666666666666,"last_synced_commit":"2d0813e5ecd9fbd4a05d9373125733e8af033da4"},"previous_names":[],"tags_count":29,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/omar-dulaimi%2Fprisma-trpc-generator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/omar-dulaimi%2Fprisma-trpc-generator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/omar-dulaimi%2Fprisma-trpc-generator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/omar-dulaimi%2Fprisma-trpc-generator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/omar-dulaimi","download_url":"https://codeload.github.com/omar-dulaimi/prisma-trpc-generator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254404356,"owners_count":22065641,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["prisma","prisma-generator","trpc","zod"],"created_at":"2024-08-03T16:01:10.546Z","updated_at":"2025-05-15T19:07:46.639Z","avatar_url":"https://github.com/omar-dulaimi.png","language":"TypeScript","funding_links":["https://github.com/sponsors/omar-dulaimi","https://www.buymeacoffee.com/omardulaimi"],"categories":["others","Projects Using Zod"],"sub_categories":[],"readme":"[![npm version](https://badge.fury.io/js/prisma-trpc-generator.svg)](https://badge.fury.io/js/prisma-trpc-generator)\n[![npm](https://img.shields.io/npm/dt/prisma-trpc-generator.svg)](https://www.npmjs.com/package/prisma-trpc-generator)\n[![HitCount](https://hits.dwyl.com/omar-dulaimi/prisma-trpc-generator.svg?style=flat)](http://hits.dwyl.com/omar-dulaimi/prisma-trpc-generator)\n[![npm](https://img.shields.io/npm/l/prisma-trpc-generator.svg)](LICENSE)\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://github.com/omar-dulaimi/prisma-trpc-generator\"\u003e\n    \u003cimg src=\"https://raw.githubusercontent.com/omar-dulaimi/prisma-trpc-generator/master/logo.png\" alt=\"Logo\" width=\"200\" height=\"200\"/\u003e\n  \u003c/a\u003e\n  \u003ch3 align=\"center\"\u003ePrisma tRPC Generator\u003c/h3\u003e\n  \u003cp align=\"center\"\u003e\n    A Prisma generator that automates creating your tRPC routers from your Prisma schema.\n    \u003cbr /\u003e\n    \u003ca href=\"https://github.com/omar-dulaimi/prisma-trpc-generator#additional-options\"\u003e\u003cstrong\u003eExplore the options »\u003c/strong\u003e\u003c/a\u003e\n    \u003cbr /\u003e\n    \u003cbr /\u003e\n    \u003ca href=\"https://github.com/omar-dulaimi/prisma-trpc-generator/issues/new?template=bug_report.yml\"\u003eReport Bug\u003c/a\u003e\n    ·\n    \u003ca href=\"https://github.com/omar-dulaimi/prisma-trpc-generator/issues/new?template=feature_request.md\"\u003eRequest Feature\u003c/a\u003e\n  \u003c/p\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://www.buymeacoffee.com/omardulaimi\"\u003e\n    \u003cimg src=\"https://cdn.buymeacoffee.com/buttons/default-black.png\" alt=\"Buy Me A Coffee\" height=\"41\" width=\"174\"/\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n## Table of Contents\n\n- [About The Project](#about-the-project)\n- [Supported Prisma Versions](#supported-prisma-versions)\n  - [Prisma 4](#prisma-4)\n  - [Prisma 2/3](#prisma-23)\n- [Supported tRPC Versions](#supported-trpc-versions)\n  - [tRPC 10](#trpc-10)\n  - [tRPC 9](#trpc-9)\n- [Installation](#installation)\n- [Usage](#usage)\n- [Customizations](#customizations)\n  - [Skipping entire models](#skipping-entire-models)\n- [Additional Options](#additional-options)\n\n# About The Project\n\nAutomatically generate fully implemented tRPC routers from your [Prisma](https://github.com/prisma/prisma) Schema. This includes routers, app router and of course all input schemas using [Zod](https://github.com/colinhacks/zod). Updates every time `npx prisma generate` runs.\n\n# Supported Prisma Versions\n\n### Prisma 4\n\n- 0.2.0 and higher\n\n### Prisma 2/3\n\n- 0.1.12 and lower\n\n# Supported tRPC Versions\n\n### tRPC 10\n\n- 0.8.0 and higher\n\n### tRPC 9\n\n- 0.7.2 and lower\n\n# Installation\n\nUsing npm:\n\n```bash\n npm install prisma-trpc-generator\n```\n\nUsing yarn:\n\n```bash\n yarn add prisma-trpc-generator\n```\n\n# Usage\n\n1- Star this repo 😉\n\n2- Add the generator to your Prisma schema\n\n```prisma\ngenerator trpc {\n  provider          = \"prisma-trpc-generator\"\n  withZod           = true\n  withMiddleware    = false\n  withShield        = false\n  contextPath       = \"../src/context\"\n  trpcOptionsPath   = \"../src/trpcOptions\"\n}\n```\n\n3- Enable strict mode in `tsconfig` as it is required by Zod, and considered a Typescript best practice\n\n```ts\n{\n  \"compilerOptions\": {\n    \"strict\": true\n  }\n}\n\n```\n\n4- Running `npx prisma generate` for the following schema.prisma\n\n```prisma\nmodel User {\n  id    Int     @id @default(autoincrement())\n  email String  @unique\n  name  String?\n  posts Post[]\n}\n\nmodel Post {\n  id        Int      @id @default(autoincrement())\n  createdAt DateTime @default(now())\n  updatedAt DateTime @updatedAt\n  title     String\n  content   String?\n  published Boolean  @default(false)\n  viewCount Int      @default(0)\n  author    User?    @relation(fields: [authorId], references: [id])\n  authorId  Int?\n}\n```\n\nwill generate\n\n![tRPC Routers](https://raw.githubusercontent.com/omar-dulaimi/prisma-trpc-generator/master/trpcRouters.png)\n\n5- Make sure you have a valid `Context` file, as specified in `contextPath` option. The official [Context](https://trpc.io/docs/context) for reference.\n\n6- Optionally, you can specify a `trpcOptionsPath` to set various tRPC options (like transformer, error formatter, etc). Find about all possible options [here](https://trpc.io/docs/router#advanced-usage).\n\n```ts\nimport { ZodError } from 'zod';\n\nexport default {\n  errorFormatter({ shape, error }) {\n    return {\n      ...shape,\n      data: {\n        ...shape.data,\n        zodError:\n          error.code === 'BAD_REQUEST' \u0026\u0026 error.cause instanceof ZodError\n            ? error.cause.flatten()\n            : null,\n      },\n    };\n  },\n};\n```\n\n# Customizations\n\n## Skipping entire models\n\n```prisma\n/// @@Gen.model(hide: true)\nmodel User {\n  id    Int     @id @default(autoincrement())\n  email String  @unique\n  name  String?\n}\n```\n\n# Additional Options\n\n| Option                     | Description                                                                            | Type      | Default                                                                                                                                                                      |\n| -------------------------- | -------------------------------------------------------------------------------------- | --------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| `output`                   | Output directory for the generated routers and zod schemas                             | `string`  | `./generated`                                                                                                                                                                |\n| `withMiddleware`           | Attaches a global middleware that runs before all procedures                           | `boolean or string`| `true`                                                                                                                                                              |\n| `output`                   | Output directory for the generated routers and zod schemas                             | `string`  | `./generated`                                                                                                                                                                |\n| `withZod`                  |  Use Zod for input validation                                                          | `boolean` | `true`                                                                                                                                                                       |\n| `withShield`               | Generates a tRPC Shield to use as a permissions layer                                  | `boolean or string` | `true`                                                                                                                                                                       |\n| `contextPath`              | Sets the context path used in your routers                                             | `string`  | `../../../../src/context`                                                                                                                                                    |\n| `trpcOptionsPath`          | Sets the tRPC instance options                                                         | `string`  | `../../../../src/trpcOptions`                                                                                                                                                |\n| `isGenerateSelect`         | Enables the generation of Select related schemas and the select property               | `boolean` | `false`                                                                                                                                                                      |\n| `isGenerateInclude`        | Enables the generation of Include related schemas and the include property             | `boolean` | `false`                                                                                                                                                                      |\n| `showModelNameInProcedure` | When disabled, the generated procedure no longer includes the name of the Prisma model | `boolean` | `true`                                                                                                                                                                       |\n| `generateModelActions`     | Enables the generation of specific model actions                                       | `string`  | `aggregate,aggregateRaw,count,create,createMany,delete,deleteMany,findFirst,findFirstOrThrow,findMany,findRaw,findUnique,findUniqueOrThrow,groupBy,update,updateMany,upsert` |\n\nUse additional options in the `schema.prisma`\n\n```prisma\ngenerator trpc {\n  provider           = \"prisma-trpc-generator\"\n  output             = \"./trpc\"\n  withMiddleware     = \"../middleware\"\n  withZod            = false\n  withShield         = false\n  contextPath        = \"../context\"\n  trpcOptionsPath    = \"../trpcOptions\"\n  isGenerateSelect   = true\n  isGenerateInclude  = true\n  showModelNameInProcedure  = false\n  generateModelActions = \"aggregate,aggregateRaw,count,create,createMany,delete,deleteMany,findFirst,findFirstOrThrow,findMany,findRaw,findUnique,findUniqueOrThrow,groupBy,update,updateMany,upsert\"\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fomar-dulaimi%2Fprisma-trpc-generator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fomar-dulaimi%2Fprisma-trpc-generator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fomar-dulaimi%2Fprisma-trpc-generator/lists"}