diff --git a/docs/entity-types-server.md b/docs/entity-types-server.md index c7eaa4394..8383b64d8 100644 --- a/docs/entity-types-server.md +++ b/docs/entity-types-server.md @@ -4,7 +4,7 @@ Module `@zenstackhq/runtime/types` contains type definitions of entities, filter Suppose a `User` model is defined in ZModel: -```prisma +```zmodel model User { id String @id @default(cuid()) email String @unique @email diff --git a/docs/entity-types.md b/docs/entity-types.md index c7eaa4394..8383b64d8 100644 --- a/docs/entity-types.md +++ b/docs/entity-types.md @@ -4,7 +4,7 @@ Module `@zenstackhq/runtime/types` contains type definitions of entities, filter Suppose a `User` model is defined in ZModel: -```prisma +```zmodel model User { id String @id @default(cuid()) email String @unique @email diff --git a/docs/get-started/learning-the-zmodel-language.md b/docs/get-started/learning-the-zmodel-language.md index 1850d3216..27b01032e 100644 --- a/docs/get-started/learning-the-zmodel-language.md +++ b/docs/get-started/learning-the-zmodel-language.md @@ -9,7 +9,7 @@ Every model needs to include exactly one `datasource` declaration, providing inf The recommended way is to load the connection string from an environment variable, like: -```prisma +```zmodel datasource db { provider = "postgresql" url = env("DATABASE_URL") @@ -24,7 +24,7 @@ Data models define the shapes of entities in your application domain. They inclu Here's an example of a blog post model: -```prisma +```zmodel model Post { // the mandatory primary key of this model with a default UUID value id String @id @default(uuid()) @@ -59,7 +59,7 @@ Attributes attached to fields are prefixed with '@', and those to models are pre Here're some examples of commonly used attributes: -```prisma +```zmodel model Post { // @id is a field attribute, marking the field as a primary key // @default is another field attribute for specifying a default value for the field if it's not given at creation time @@ -97,7 +97,7 @@ ZenStack inherits most attributes and functions from Prisma, and added a number You can override the default setting with the `saltLength` or `salt` named parameters, like: -```prisma +```zmodel model User { password String @password(saltLength: 16) } @@ -115,7 +115,7 @@ If both `saltLength` and `salt` parameters are provided, `salt` is used. E.g.: -```prisma +```zmodel model User { password String @password @omit } @@ -129,7 +129,7 @@ The special `@relation` attribute expresses relations between data models. Here' - One-to-one -```prisma +```zmodel model User { id String @id profile Profile? @@ -144,7 +144,7 @@ model Profile { - One-to-many -```prisma +```zmodel model User { id String @id posts Post[] @@ -159,7 +159,7 @@ model Post { - Many-to-many -```prisma +```zmodel model Space { id String @id members Membership[] @@ -194,7 +194,7 @@ This document serves as a quick overview for starting with the ZModel language. Access policies express authorization logic in a declarative way. They use `@@allow` and `@@deny` rules to specify the eligibility of an operation over a model entity. The signatures of the attributes are: -```prisma +```zmodel @@allow(operation, condition) @@deny(operation, condition) ``` @@ -216,26 +216,26 @@ You can use `auth()` to: - Check if a user is logged in -```prisma +```zmodel @@deny('all', auth() == null) ``` - Access user's fields -```prisma +```zmodel @@allow('update', auth().role == 'ADMIN') ``` - Compare user identity -```prisma +```zmodel // owner is a relation field to User model @@allow('update', auth() == owner) ``` ### A simple example with Post model -```prisma +```zmodel model Post { // reject all operations if user's not logged in @@deny('all', auth() == null) @@ -250,7 +250,7 @@ model Post { ### A more complex example with multi-user spaces -```prisma +```zmodel model Space { id String @id members Membership[] @@ -322,7 +322,7 @@ model User { As you've seen in the examples above, you can access fields from relations in policy expressions. For example, to express "a user can be read by any user sharing a space" in the `User` model, you can directly read into its `membership` field. -```prisma +```zmodel @@allow('read', membership?[space.members?[user == auth()]]) ``` @@ -358,7 +358,7 @@ Collection predicate expressions are boolean expressions used to express conditi The `condition` expression has direct access to fields defined in the model of `collection`. E.g.: -```prisma +```zmodel @@allow('read', members?[user == auth()]) ``` @@ -366,7 +366,7 @@ The `condition` expression has direct access to fields defined in the model of ` Also, collection predicates can be nested to express complex conditions involving multi-level relation lookup. E.g.: -```prisma +```zmodel @@allow('read', membership?[space.members?[user == auth()]]) ``` @@ -434,7 +434,7 @@ The following attributes can be used to attach field constraints: ### Sample usage -```prisma +```zmodel model User { id String @id handle String @regex("^[0-9a-zA-Z]{4,16}$") diff --git a/docs/get-started/next-js.md b/docs/get-started/next-js.md index a67201fb8..1387e9f5d 100644 --- a/docs/get-started/next-js.md +++ b/docs/get-started/next-js.md @@ -59,7 +59,7 @@ npm i @zenstackhq/runtime Here's an example of using a Postgres database with connection string specified in `DATABASE_URL` environment variable: -```prisma +```zmodel datasource db { provider = 'postgresql' url = env('DATABASE_URL') diff --git a/docs/index.html b/docs/index.html index 0b81d0098..c470e1a76 100644 --- a/docs/index.html +++ b/docs/index.html @@ -76,6 +76,7 @@ +