From ad702ef0d8e1a3e5cf994d493cc5431b16e5722a Mon Sep 17 00:00:00 2001 From: ymc9 <104139426+ymc9@users.noreply.github.com> Date: Tue, 20 May 2025 19:49:38 -0700 Subject: [PATCH 1/2] docs: for release 2.15.0 --- docs/faq.md | 4 ++ docs/reference/server-adapters/elysia.mdx | 67 +++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 docs/reference/server-adapters/elysia.mdx diff --git a/docs/faq.md b/docs/faq.md index 39d88c76..504fb69d 100644 --- a/docs/faq.md +++ b/docs/faq.md @@ -61,3 +61,7 @@ The short answer is it works in most cases. Please refer to [this guide](./guide ### Does the order in which access policies are defined matter? No. See [here](./the-complete-guide/part1/4-access-policy/4.1-model-level.md#evaluation-of-model-level-policies) for how access polices are evaluated. + +### Is Prisma's new "prisma-client" generator supported? + +No. The feature was add in [Prisma 6.6](https://github.com/prisma/prisma/releases/tag/6.6.0) but it's still in early access. We plan to work on it when Prisma pushes it to GA. diff --git a/docs/reference/server-adapters/elysia.mdx b/docs/reference/server-adapters/elysia.mdx new file mode 100644 index 00000000..7e9953ae --- /dev/null +++ b/docs/reference/server-adapters/elysia.mdx @@ -0,0 +1,67 @@ +--- +title: Elysia +description: Adapter for integrating with Elysia +sidebar_position: 7 +--- + +import ErrorHandling from './_error-handling.md'; +import AdapterOptions from './_options.mdx'; +import UsingAPI from './_using-api.mdx' + +# Elysia Adapter + +The `@zenstackhq/server/elysia` module provides a quick way to install a CRUD middleware onto an [Elysia](https://elysiajs.com/) app. Combined with ZenStack's power of enhancing Prisma with access policies, you can achieve a secure data backend without manually coding it. + +### Installation + +```bash +bun install @zenstackhq/server +``` + +### Mounting the API + +You can use the `createElysiaHandler` API to create an Elysia request handler that handles CRUD requests automatically: + +```ts +import { PrismaClient } from '@prisma/client'; +import { Elysia, Context } from 'elysia'; +import { enhance } from '@zenstackhq/runtime'; +import { createElysiaHandler } from '@zenstackhq/server/elysia'; + +const prisma = new PrismaClient(); + +const app = new Elysia({ prefix: '/api' }); + +// install the CRUD middleware under route "/api/crud" +app.group('/crud', (app) => + app.use( + createElysiaHandler({ + getPrisma: () => enhance(prisma, { user:getCurrentUser() }), + basePath: '/api/crud', + }) + ) +); + +function getCurrentUser(context: Context) { + // the implementation depends on your authentication mechanism + ... +} + +app.listen(3000); +``` + +The middleware factory takes the following options to initialize: + + + +- basePath (optional) + +
string
+ + Optional base path to strip from the request path before passing to the API handler. E.g., if your CRUD handler is mounted at `/api/crud`, set this field to `'/api/crud'`. + +### Using the API + + + + From 016310f458278be13f0497cd38fc4ea776cc247a Mon Sep 17 00:00:00 2001 From: ymc9 <104139426+ymc9@users.noreply.github.com> Date: Tue, 20 May 2025 22:39:43 -0700 Subject: [PATCH 2/2] update --- docs/reference/server-adapters/elysia.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/reference/server-adapters/elysia.mdx b/docs/reference/server-adapters/elysia.mdx index 7e9953ae..d353454a 100644 --- a/docs/reference/server-adapters/elysia.mdx +++ b/docs/reference/server-adapters/elysia.mdx @@ -1,7 +1,7 @@ --- title: Elysia description: Adapter for integrating with Elysia -sidebar_position: 7 +sidebar_position: 8 --- import ErrorHandling from './_error-handling.md'; @@ -36,7 +36,7 @@ const app = new Elysia({ prefix: '/api' }); app.group('/crud', (app) => app.use( createElysiaHandler({ - getPrisma: () => enhance(prisma, { user:getCurrentUser() }), + getPrisma: (context) => enhance(prisma, { user: getCurrentUser(context) }), basePath: '/api/crud', }) )