| 45 | |
| 46 | /** @internal */ |
| 47 | export const schemaJson = < |
| 48 | R, |
| 49 | I extends Partial<{ |
| 50 | readonly method: Method.HttpMethod |
| 51 | readonly url: string |
| 52 | readonly cookies: Readonly<Record<string, string | undefined>> |
| 53 | readonly headers: Readonly<Record<string, string | undefined>> |
| 54 | readonly pathParams: Readonly<Record<string, string | undefined>> |
| 55 | readonly searchParams: Readonly<Record<string, string | ReadonlyArray<string> | undefined>> |
| 56 | readonly body: any |
| 57 | }>, |
| 58 | A |
| 59 | >( |
| 60 | schema: Schema.Schema<A, I, R>, |
| 61 | options?: ParseOptions | undefined |
| 62 | ) => { |
| 63 | const parse = Schema.decodeUnknown(schema, options) |
| 64 | return Effect.flatMap( |
| 65 | Effect.context<ServerRequest.HttpServerRequest | ServerRequest.ParsedSearchParams | Router.RouteContext>(), |
| 66 | (context) => { |
| 67 | const request = Context.get(context, ServerRequest.HttpServerRequest) |
| 68 | const searchParams = Context.get(context, ServerRequest.ParsedSearchParams) |
| 69 | const routeContext = Context.get(context, RouteContext) |
| 70 | return Effect.flatMap(request.json, (body) => |
| 71 | parse({ |
| 72 | method: request.method, |
| 73 | url: request.url, |
| 74 | headers: request.headers, |
| 75 | cookies: request.cookies, |
| 76 | pathParams: routeContext.params, |
| 77 | searchParams, |
| 78 | body |
| 79 | })) |
| 80 | } |
| 81 | ) |
| 82 | } |
| 83 | |
| 84 | /** @internal */ |
| 85 | export const schemaNoBody = < |