0.3.3 • Published 7 months ago

@passionfroot/prisma-generator-zero v0.3.3

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

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

Note that unsupported column types (eg. string[]) will be automatically excluded from the generated schema.

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.

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
}
0.3.3

7 months ago

0.3.2

8 months ago

0.3.1

9 months ago

0.3.0

9 months ago

0.2.1

9 months ago

0.2.0

10 months ago

0.1.0

10 months ago

0.0.5

11 months ago

0.0.4

11 months ago

0.0.3

11 months ago

0.0.2

11 months ago

0.0.1

11 months ago