Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
67 changes: 67 additions & 0 deletions docs/reference/server-adapters/elysia.mdx
Original file line number Diff line number Diff line change
@@ -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:

<AdapterOptions getPrisma='(ctx: Context) => unknown | Promise<unknown>' />

- basePath (optional)

<blockquote>string</blockquote>

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

<UsingAPI />

<ErrorHandling />