Reviewing TypeScript Function for Effect Code Style

can somebody look at my function and say if its good effect code style or if im overcomplicating things?

import { Config, Effect, Schema } from "effect"
import { FetchHttpClient, HttpClient } from "@effect/platform"

const placeFoundResponse = Schema.Struct({
  data: Schema.Array(
    Schema.Struct({
      business_id: Schema.String,
    }),
  ),
})

const placeNotFoundResponse = Schema.Struct({
  data: Schema.Array(
    Schema.Struct({
      business_id: Schema.Literal(null),
    }),
  ),
})

const expectedResponse = Schema.Union(placeFoundResponse, placeNotFoundResponse)

export const getPlaceInfo = Effect.fn("getPlaceInfo")(function* (
  place_id: string,
) {
  return yield* Effect.gen(function* () {
    const client = yield* HttpClient.HttpClient

    const response = yield* client.get(
      "https://maps-data.p.rapidapi.com/place.php",
      {
        urlParams: {
          place_id,
          business_id: "required_but_not_used",
        },
        headers: {
          "x-rapidapi-host": "maps-data.p.rapidapi.com",
          "x-rapidapi-key": yield* Config.string("RAPIDAPI_KEY"),
        },
      },
    )
    const json = yield* response.json

    const result = yield* Schema.decodeUnknown(expectedResponse)(json)

    if (!result.data[0].business_id) return null

    return result.data[0]
  }).pipe(Effect.provide(FetchHttpClient.layer))
})
Was this page helpful?