( endpoint_: HttpApiEndpoint.HttpApiEndpoint.Any, middleware: MiddlewareMap, handler: HttpApiEndpoint.HttpApiEndpoint.Handler<any, any, any>, isFullRequest: boolean, uninterruptible: boolean )
| 642 | } |
| 643 | |
| 644 | const handlerToRoute = ( |
| 645 | endpoint_: HttpApiEndpoint.HttpApiEndpoint.Any, |
| 646 | middleware: MiddlewareMap, |
| 647 | handler: HttpApiEndpoint.HttpApiEndpoint.Handler<any, any, any>, |
| 648 | isFullRequest: boolean, |
| 649 | uninterruptible: boolean |
| 650 | ): HttpRouter.Route<any, any> => { |
| 651 | const endpoint = endpoint_ as HttpApiEndpoint.HttpApiEndpoint.AnyWithProps |
| 652 | const isMultipartStream = endpoint.payloadSchema.pipe( |
| 653 | Option.map(({ ast }) => HttpApiSchema.getMultipartStream(ast) !== undefined), |
| 654 | Option.getOrElse(constFalse) |
| 655 | ) |
| 656 | const multipartLimits = endpoint.payloadSchema.pipe( |
| 657 | Option.flatMapNullable(({ ast }) => HttpApiSchema.getMultipart(ast) || HttpApiSchema.getMultipartStream(ast)) |
| 658 | ) |
| 659 | const decodePath = Option.map(endpoint.pathSchema, Schema.decodeUnknown) |
| 660 | const decodePayload = isFullRequest || isMultipartStream |
| 661 | ? Option.none() |
| 662 | : Option.map(endpoint.payloadSchema, Schema.decodeUnknown) |
| 663 | const decodeHeaders = Option.map(endpoint.headersSchema, Schema.decodeUnknown) |
| 664 | const encodeSuccess = Schema.encode(makeSuccessSchema(endpoint.successSchema)) |
| 665 | return HttpRouter.makeRoute( |
| 666 | endpoint.method, |
| 667 | endpoint.path, |
| 668 | applyMiddleware( |
| 669 | middleware, |
| 670 | Effect.gen(function*() { |
| 671 | const fiber = Option.getOrThrow(Fiber.getCurrentFiber()) |
| 672 | const context = fiber.currentContext |
| 673 | const httpRequest = Context.unsafeGet(context, HttpServerRequest.HttpServerRequest) |
| 674 | const routeContext = Context.unsafeGet(context, HttpRouter.RouteContext) |
| 675 | const urlParams = Context.unsafeGet(context, HttpServerRequest.ParsedSearchParams) |
| 676 | const request: any = { request: httpRequest } |
| 677 | if (decodePath._tag === "Some") { |
| 678 | request.path = yield* decodePath.value(routeContext.params) |
| 679 | } |
| 680 | if (decodePayload._tag === "Some") { |
| 681 | request.payload = yield* Effect.flatMap( |
| 682 | requestPayload(httpRequest, urlParams, multipartLimits), |
| 683 | decodePayload.value |
| 684 | ) |
| 685 | } else if (isMultipartStream) { |
| 686 | request.payload = Option.match(multipartLimits, { |
| 687 | onNone: () => httpRequest.multipartStream, |
| 688 | onSome: (limits) => Multipart.withLimitsStream(httpRequest.multipartStream, limits) |
| 689 | }) |
| 690 | } |
| 691 | if (decodeHeaders._tag === "Some") { |
| 692 | request.headers = yield* decodeHeaders.value(httpRequest.headers) |
| 693 | } |
| 694 | if (endpoint.urlParamsSchema._tag === "Some") { |
| 695 | const schema = endpoint.urlParamsSchema.value |
| 696 | request.urlParams = yield* Schema.decodeUnknown(schema)(normalizeUrlParams(urlParams, schema.ast)) |
| 697 | } |
| 698 | const response = yield* handler(request) |
| 699 | return HttpServerResponse.isServerResponse(response) ? response : yield* encodeSuccess(response) |
| 700 | }).pipe( |
| 701 | Effect.catchIf(ParseResult.isParseError, HttpApiDecodeError.refailParseError) |
no test coverage detected