Created
August 3, 2023 15:53
-
-
Save sphaugh/2a8310f2b66b4ed51fd898dba2a26788 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as Context from "@effect/data/Context"; | |
import * as Effect from "@effect/io/Effect"; | |
import type { Span } from "@effect/io/Tracer"; | |
import type { RpcResponse } from "@effect/rpc/Resolver"; | |
import type { RpcHandlers, RpcRouter } from "@effect/rpc/Router"; | |
import * as Server from "@effect/rpc/Server"; | |
import * as aws from "aws-lambda"; | |
export const ApiGatewayRequest = Context.Tag<aws.APIGatewayProxyEventV2>(); | |
export interface RpcEventHandler<R extends RpcRouter.Base> { | |
(event: aws.APIGatewayProxyEventV2): Effect.Effect< | |
Exclude< | |
RpcHandlers.Services<R["handlers"]>, | |
aws.APIGatewayProxyEventV2 | Span | |
>, | |
never, | |
ReadonlyArray<RpcResponse> | |
>; | |
} | |
export function make<R extends RpcRouter.Base>(router: R): RpcEventHandler<R> { | |
const handler = Server.handler(router); | |
return (event) => | |
Effect.provideService(handler(event.body), ApiGatewayRequest, event); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment