Skip to content

Instantly share code, notes, and snippets.

@furrycatherder
Created August 3, 2023 15:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save furrycatherder/2a8310f2b66b4ed51fd898dba2a26788 to your computer and use it in GitHub Desktop.
Save furrycatherder/2a8310f2b66b4ed51fd898dba2a26788 to your computer and use it in GitHub Desktop.
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