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