You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+43-13Lines changed: 43 additions & 13 deletions
Original file line number
Diff line number
Diff line change
@@ -21,13 +21,17 @@
21
21
22
22
## What it is
23
23
24
-
ZenStack is a toolkit that simplifies the development of a web app's backend. It supercharges [Prisma ORM](https://prisma.io) with a powerful access control layer and unleashes its full potential for web development.
24
+
ZenStack is a Node.js/TypeScript toolkit that simplifies the development of a web app's backend. It supercharges [Prisma ORM](https://prisma.io) with a powerful access control layer and unleashes its full potential for full-stack development.
25
25
26
26
Our goal is to let you save time writing boilerplate code and focus on building real features!
27
27
28
28
## How it works
29
29
30
-
ZenStack extended Prisma schema language for supporting custom attributes and functions and, based on that, implemented a flexible access control layer around Prisma.
30
+
ZenStack incrementally extends Prisma's power with the following four layers:
31
+
32
+
### 1. ZModel - an extended Prisma schema language
33
+
34
+
ZenStack introduces a data modeling language called "ZModel" - a superset of Prisma schema language. It extended Prisma schema with custom attributes and functions and, based on that, implemented a flexible access control layer around Prisma.
31
35
32
36
```prisma
33
37
// schema.zmodel
@@ -47,34 +51,58 @@ model Post {
47
51
}
48
52
```
49
53
50
-
At runtime, transparent proxies are created around Prisma clients for intercepting queries and mutations to enforce access policies. Moreover, framework integration packages help you wrap an access-control-enabled Prisma client into backend APIs that can be safely called from the frontend.
54
+
The `zenstack` CLI transpiles the ZModel into a standard Prisma schema, which you can use with the regular Prisma workflows.
55
+
56
+
### 2. Runtime enhancements to Prisma client
57
+
58
+
At runtime, transparent proxies are created around Prisma clients for intercepting queries and mutations to enforce access policies.
51
59
52
60
```ts
53
-
// Next.js example: pages/api/model/[...path].ts
61
+
import { withPolicy } from'@zenstackhq/runtime';
62
+
63
+
// a regular Prisma client
64
+
const prisma =newPrismaClient();
65
+
66
+
asyncfunction getPosts(userId:string) {
67
+
// create an enhanced Prisma client that has access control enabled
// only posts that're visible to the user will be returned
71
+
returnenhanced.post.findMany();
72
+
}
73
+
```
74
+
75
+
### 3. Automatic RESTful APIs through server adapters
76
+
77
+
Server adapter packages help you wrap an access-control-enabled Prisma client into backend CRUD APIs that can be safely called from the frontend. Here's an example for Next.js:
78
+
79
+
```ts
80
+
// pages/api/model/[...path].ts
54
81
55
82
import { requestHandler } from'@zenstackhq/next';
56
83
import { withPolicy } from'@zenstackhq/runtime';
57
84
import { getSessionUser } from'@lib/auth';
58
85
import { prisma } from'@lib/db';
59
86
87
+
// Mount Prisma-style APIs: "/api/model/post/findMany", "/api/model/post/create", etc.
88
+
// Can be configured to provide standard RESTful APIs (using JSON:API) instead.
0 commit comments