MCPcopy Index your code
hub / github.com/Passionfroot/prisma-generator-zero

github.com/Passionfroot/prisma-generator-zero @0.4.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release 0.4.0 ↗ · + Follow
28 symbols 81 edges 9 files 4 documented · 14%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

prisma-generator-zero

prisma-generator-zero is a generator for prisma that generates a Zero schema from your Prisma schema. This includes schemas of models, enums, and relationships.

Installation

npm install @passionfroot/prisma-generator-zero

Usage

Add a new generator to your prisma.schema:

generator zero {
  provider       = "prisma-generator-zero"
}

Then run the following command to generate the schema.ts file in the ./generated/zero output folder:

npx prisma generate

Now import the generated schema into your schema file and define your own permissions.

import { definePermissions } from "@rocicorp/zero";

import { schema as generatedSchema, Schema } from "./prisma/generated/zero/schema";

// The contents of your decoded JWT.
type AuthData = {
  sub: string | null;
};

export const schema = generatedSchema;
export const permissions = definePermissions<ClerkAuthData, Schema>(generatedSchema, () => ({
  // Add your logic here
}));

For more information on definePermissions see the official docs

You can directly use the generated schema as explained here and/or reference specific exports anywhere else in your code.

Postgres Array Support

Since Zero doesn't natively support Postgres arrays, this generator automatically maps array fields to JSON storage while preserving TypeScript type safety:

model User {
  id          String   @id @default(cuid())
  email       String   @unique
  tags        String[] // Maps to json<string[]>()
  scores      Int[]    // Maps to json<number[]>()
  categories  Category[] // Maps to json<Category[]>() for enum arrays
}

enum Category {
  TECH
  BUSINESS
  LIFESTYLE
}

The generated Zero schema will include:

export const userTable = table("User")
  .columns({
    id: string(),
    email: string(),
    tags: json<string[]>(),
    scores: json<number[]>(),
    categories: json<Category[]>(),
  })
  .primaryKey("id");

Supported Array Types

  • Scalar arrays: String[], Int[], Float[], Boolean[], DateTime[], BigInt[], Decimal[]
  • Enum arrays: MyEnum[]
  • Optional arrays: String[]?json<string[]>().optional()

Configuration

If you want to customize the behavior of the generator you can use the following options:

generator zero {
  // Specify output dir
  output   = "generated/one"
  // When true, the output will be formatted using prettier
  prettier = true
  // When true, the generator will remap table names to camel case using Zero's `.from()` method.
  // You can read more about it here https://zero.rocicorp.dev/docs/zero-schema#name-mapping
  remapTablesToCamelCase = true
  // Optional list of Prisma Model names you want to exclude from the generated schema.
  // Helpful if you want to exclude Views (not supported by Zero) or other tables
  // you don't want Zero client to have access to
  excludeTables = ["Posts", "Comments", ...]
  // Produce union type for Enums instead of TypeScript Enums
  enumAsUnion = true
}

Core symbols most depended-on inside this repo

transformSchema
called by 15
src/mappers/schemaMapper.ts
mapPrismaTypeToZero
called by 13
src/mappers/typeMapper.ts
onGenerate
called by 9
src/generator.ts
getZeroTableName
called by 8
src/mappers/schemaMapper.ts
ensureStringArray
called by 7
src/mappers/schemaMapper.ts
getImplicitManyToManyTableName
called by 2
src/mappers/schemaMapper.ts
toCamelCase
called by 2
src/mappers/schemaMapper.ts
getTableName
called by 2
src/mappers/schemaMapper.ts

Shape

Function 28

Languages

TypeScript100%

Modules by API surface

src/mappers/schemaMapper.ts10 symbols
src/generators/codeGenerator.ts9 symbols
src/__tests__/utils.ts4 symbols
src/generator.ts3 symbols
src/mappers/typeMapper.ts1 symbols
src/__tests__/generator.test.ts1 symbols

For agents

$ claude mcp add prisma-generator-zero \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact