From 1e9d3b49ed8daedea39fcd755b31c00d167f8c69 Mon Sep 17 00:00:00 2001
From: ymc9 <104139426+ymc9@users.noreply.github.com>
Date: Sat, 26 Nov 2022 12:17:46 +0800
Subject: [PATCH 1/4] feat: add prism syntax file for zmodel
---
packages/schema/src/res/prism-zmodel.js | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
create mode 100644 packages/schema/src/res/prism-zmodel.js
diff --git a/packages/schema/src/res/prism-zmodel.js b/packages/schema/src/res/prism-zmodel.js
new file mode 100644
index 000000000..29645a853
--- /dev/null
+++ b/packages/schema/src/res/prism-zmodel.js
@@ -0,0 +1,23 @@
+(function (Prism) {
+ Prism.languages.prisma = Prism.languages.extend('clike', {
+ keyword: /\b(?:datasource|enum|generator|model)\b/,
+ 'type-class-name': /(\b()\s+)[\w.\\]+/,
+ });
+
+ Prism.languages.javascript['class-name'][0].pattern =
+ /(\b(?:model|datasource|enum|generator)\s+)[\w.\\]+/;
+
+ Prism.languages.insertBefore('prisma', 'function', {
+ annotation: {
+ pattern: /(^|[^.])@+\w+/,
+ lookbehind: true,
+ alias: 'punctuation',
+ },
+ });
+
+ Prism.languages.insertBefore('prisma', 'punctuation', {
+ 'type-args': /\b(?:references|fields|onDelete|onUpdate):/,
+ });
+
+ Prism.languages.json5 = Prism.languages.js;
+})(Prism);
From 1481a77d2f1ab369804f9c12a75d6d082f08acb6 Mon Sep 17 00:00:00 2001
From: ymc9 <104139426+ymc9@users.noreply.github.com>
Date: Sat, 26 Nov 2022 12:25:38 +0800
Subject: [PATCH 2/4] update
---
packages/schema/src/res/prism-zmodel.js | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/packages/schema/src/res/prism-zmodel.js b/packages/schema/src/res/prism-zmodel.js
index 29645a853..106798b9f 100644
--- a/packages/schema/src/res/prism-zmodel.js
+++ b/packages/schema/src/res/prism-zmodel.js
@@ -1,21 +1,21 @@
(function (Prism) {
- Prism.languages.prisma = Prism.languages.extend('clike', {
- keyword: /\b(?:datasource|enum|generator|model)\b/,
+ Prism.languages.zmodel = Prism.languages.extend('clike', {
+ keyword: /\b(?:datasource|enum|generator|model|attribute|function)\b/,
'type-class-name': /(\b()\s+)[\w.\\]+/,
});
Prism.languages.javascript['class-name'][0].pattern =
/(\b(?:model|datasource|enum|generator)\s+)[\w.\\]+/;
- Prism.languages.insertBefore('prisma', 'function', {
+ Prism.languages.insertBefore('zmodel', 'function', {
annotation: {
- pattern: /(^|[^.])@+\w+/,
+ pattern: /@+\w+/,
lookbehind: true,
alias: 'punctuation',
},
});
- Prism.languages.insertBefore('prisma', 'punctuation', {
+ Prism.languages.insertBefore('zmodel', 'punctuation', {
'type-args': /\b(?:references|fields|onDelete|onUpdate):/,
});
From 2ded06b0e340be52391292993c5ee36d8ae2dd4b Mon Sep 17 00:00:00 2001
From: ymc9 <104139426+ymc9@users.noreply.github.com>
Date: Sat, 26 Nov 2022 12:51:03 +0800
Subject: [PATCH 3/4] update docs
---
docs/entity-types-server.md | 2 +-
docs/entity-types.md | 2 +-
.../learning-the-zmodel-language.md | 36 ++++-----
docs/get-started/next-js.md | 2 +-
docs/index.html | 1 +
docs/integrating-authentication.md | 2 +-
docs/modeling-your-app.md | 12 +--
docs/zmodel-access-policy.md | 20 ++---
docs/zmodel-attribute.md | 78 +++++++++----------
docs/zmodel-data-model.md | 4 +-
docs/zmodel-data-source.md | 6 +-
docs/zmodel-enum.md | 2 +-
docs/zmodel-field-constraint.md | 2 +-
docs/zmodel-field.md | 4 +-
docs/zmodel-referential-action.md | 6 +-
docs/zmodel-relation.md | 6 +-
package.json | 2 +-
packages/runtime/package.json | 2 +-
packages/schema/package.json | 2 +-
packages/schema/src/res/prism-zmodel.js | 11 ++-
samples/todo/package.json | 2 +-
21 files changed, 102 insertions(+), 102 deletions(-)
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..a4a7cda8e 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -76,6 +76,7 @@
+