@arian8ultra/prismagen
v0.1.5
Published
Generate API routes + Prisma function wrappers from prisma/schema.prisma
Maintainers
Readme
PrismaGen
Generate API route handlers and Prisma function wrappers from prisma/schema.prisma.
- Generates Next.js-style route handlers under
app/api/<model>/route.ts - Generates thin Prisma wrappers under
prisma/functions/<Model>/<Model>Fun.ts - Optional interactive TUI (
--interactive) to select models, includes, and protected methods
Requirements
- Node.js
>=18 - A project with
prisma/schema.prisma prismaandreactinstalled in the target project (can be independenciesordevDependencies; the CLI checks this)
Run via npx / bunx
After you publish this package:
npx @arian8ultra/prismagen --interactive
# or
bunx @arian8ultra/prismagen --interactiveNon-interactive (uses prisma/api-gen.config.json or defaults):
npx @arian8ultra/prismagenLocal development (this repo)
npm install
npm run build
node dist/cli.js --interactiveConfiguration
PrismaGen reads (and in --interactive mode writes) configuration at:
prisma/api-gen.config.json
Key options:
apiRoot: output folder for API routes (default:app/api)functionsRoot: output folder for Prisma wrappers (default:prisma/functions)prismaClientImport: import path used in generated files (example:@/prisma/prisma)prismaImportStyle:"named"or"default"authImport: import path for your auth helpers (example:@/auth/AuthFunctions)authGuardFn: function called to enforce auth (example:IsAuthenticatedAdmin)protectMethods: list of HTTP methods requiring auth (example:["POST","PUT","DELETE"])fieldDenylist: fields excluded from create/update payload pickinggenerateApisForModels: if present, only generate API routes for these modelsgenerateFunctionsForModels: if present, only generate wrappers for these modelsincludes: per-model list of relations included for<Model>_GetById
Notes
- Run the CLI from your project root (the folder that contains
prisma/schema.prisma). - The generator uses
@prisma/internalsto read Prisma DMMF from your schema.
License
MIT (see LICENSE).
