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..d353454a --- /dev/null +++ b/docs/reference/server-adapters/elysia.mdx @@ -0,0 +1,67 @@ +--- +title: Elysia +description: Adapter for integrating with Elysia +sidebar_position: 8 +--- + +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: (context) => enhance(prisma, { user: getCurrentUser(context) }), + 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 + + + +