ZenStack

raw JSON →
2.22.1 verified Sat Apr 25 auth: no javascript

ZenStack is a fullstack enhancement layer for Prisma ORM that provides seamless integration from database to UI. It extends Prisma with access policies, automatic API generation (REST and RPC), client-side hooks for React/TanStack Query, Zod schema generation, and more. Current stable version is 3.6.2, with active releases roughly every month. Key differentiators: declarative permission policies similar to Firebase Security Rules, custom types with relations, OpenAPI spec generation, and deep integration with Prisma without replacing it. Requires Prisma 5.0+ and Zod 3.25+ as peer dependencies.

error Cannot find module '@zenstackhq/runtime' or its corresponding type declarations.
cause Missing installation of the runtime package.
fix
Run 'npm install @zenstackhq/runtime'.
error TypeError: prismadb.enhance is not a function
cause Using enhance incorrectly or missing import.
fix
Use 'import { enhance } from "@zenstackhq/runtime"'; then call 'enhance(prisma, { getCurrentUser })'.
breaking Since v3, React hooks moved from @zenstackhq/react to @zenstackhq/tanstack-query
fix Update imports: use @zenstackhq/tanstack-query instead of @zenstackhq/react.
breaking Zod schema generation now requires explicit import from @zenstackhq/zod
fix Change 'import { generateZodSchemas } from "zenstack"' to 'import { generateZodSchemas } from "@zenstackhq/zod"'.
deprecated The old 'zenstack' global package is deprecated; use scoped packages like @zenstackhq/runtime, @zenstackhq/tanstack-query
fix Replace imports with specific @zenstackhq/* packages.
gotcha Policy rules must be defined correctly; incorrect rules may silently return empty results
fix Use @@allow and @@deny with auth() conditions; test policies thoroughly.
npm install zenstack
yarn add zenstack
pnpm add zenstack

Shows how to set up a ZenStack-enhanced Prisma client with a permissive policy for reading users.

// Install: npm install @zenstackhq/runtime @zenstackhq/tanstack-query prisma @prisma/client zod
// Define schema.prisma with ZenStack extensions
// model User {
//   id        String   @id @default(uuid())
//   email     String   @unique
//   role      String   @default('user')
//   posts     Post[]
//   @@allow('read', true)
//   @@allow('create,update', auth().role == 'admin')
// }
// Run: npx zenstack generate
import { PrismaClient } from '@prisma/client';
import { enhance } from '@zenstackhq/runtime';

const prisma = new PrismaClient();
const enhanced = enhance(prisma, { getCurrentUser: () => ({ id: '1', role: 'admin' }) });

async function main() {
  const users = await enhanced.user.findMany();
  console.log(users);
}
main()