feat: `requires` field for dependencies in HttpApiMiddleware
Type
- [ ] Refactor
- [x] Feature
- [ ] Bug Fix
- [ ] Optimization
- [ ] Documentation Update
Description
Adds requires support to HttpApiMiddleware.Tag to allow middlewares to depend on other middleware outputs.
Details:
- New option:
requires?: Context.Tag | ReadonlyArray<Context.Tag>when defining a middleware tag.
Example:
export class AdminUser extends HttpApiMiddleware.Tag<AdminUser>()("Http/Admin", {
failure: HttpApiError.Forbidden,
requires: CurrentUser // or: [CurrentUser, Session]
}) {}
// Inside the middleware implementation you can now safely use the required services
yield* CurrentUser
Related
- Related Issue: N/A
- Closes: N/A
- Discord conversation: https://discord.com/channels/795981131316985866/1411695023128317973
🦋 Changeset detected
Latest commit: 14347e8a5aca2787ada0465b3d469b639724d67b
The changes in this PR will be included in the next version bump.
This PR includes changesets to release 30 packages
| Name | Type |
|---|---|
| @effect/platform | Minor |
| @effect/cli | Major |
| @effect/cluster | Major |
| @effect/experimental | Major |
| @effect/opentelemetry | Major |
| @effect/platform-browser | Major |
| @effect/platform-bun | Major |
| @effect/platform-node-shared | Major |
| @effect/platform-node | Major |
| @effect/rpc | Major |
| @effect/sql-clickhouse | Major |
| @effect/sql-d1 | Major |
| @effect/sql-drizzle | Major |
| @effect/sql-libsql | Major |
| @effect/sql-mssql | Major |
| @effect/sql-mysql2 | Major |
| @effect/sql-pg | Major |
| @effect/sql-sqlite-bun | Major |
| @effect/sql-sqlite-node | Major |
| @effect/sql | Major |
| @effect/workflow | Major |
| @effect/ai | Major |
| @effect/ai-amazon-bedrock | Major |
| @effect/ai-anthropic | Major |
| @effect/ai-google | Major |
| @effect/ai-openai | Major |
| @effect/sql-sqlite-do | Major |
| @effect/sql-sqlite-react-native | Major |
| @effect/sql-sqlite-wasm | Major |
| @effect/sql-kysely | Major |
Not sure what this means? Click here to learn what changesets are.
Click here if you're a maintainer who wants to add another changeset to this PR
HttpApiMiddleware will have a type-level requires option: https://github.com/Effect-TS/effect-smol/blob/main/packages/effect/src/unstable/httpapi/HttpApiMiddleware.ts#L173
It could be back-ported at some stage.
It could be back-ported at some stage.
better soon than later. guess we can expand https://github.com/Effect-TS/effect/pull/5331 to http api
I'm eagerly awaiting this feature, exactly for the example use-case where the AuthenticatedUser from one middleware is built upon by another Middleware. @patroza are you integrating it into https://github.com/Effect-TS/effect/pull/5331?