Simplifying and Validating HTTP Request Body in TypeScript

is there a more succinct way of validating the incoming request body, in fact is this an idiomatic way of performing a post at all? ive scoured discord and the docs but there's still a little uncertainty (theres no entries in discord for HttpClientRequest.schemaBodyJson or HttpClient.schemaFunction)

import { HttpClient, HttpClientRequest, HttpClientResponse } from "@effect/platform";
import { Config, Effect, RequestResolver } from "effect";
import * as Models from "~/models";
import { LoginRequest } from "./login.request";

export const LoginResolver = RequestResolver.fromEffect((request: LoginRequest) =>
  Effect.gen(function* () {
    const baseURL = yield* Config.nonEmptyString("BASE_URL");
    const client = yield* HttpClient.HttpClient;

    const authClient = client.pipe(
      HttpClient.mapRequest(HttpClientRequest.prependUrl("/authentication")),
      HttpClient.mapRequest(HttpClientRequest.prependUrl(baseURL)),
      HttpClient.filterStatusOk,
    );

    return yield* HttpClientRequest.post("/login").pipe(
      HttpClientRequest.schemaBodyJson(LoginRequest)(request),
      Effect.andThen(authClient.execute),
      Effect.andThen(HttpClientResponse.schemaBodyJson(Models.Session)),
      Effect.scoped,
    );
  }),
).pipe(RequestResolver.contextFromServices(HttpClient.HttpClient));


in the return statement, would HttpClientRequest.bodyUnsafeJson(request), perhaps be more appropriate as the request is a Schema.TaggedRequest already, my intuition tells me im validating the request body redundantly a second time (the first being when the resolver is called within the service using the schema tagged request?
Was this page helpful?