| 446 | * Used to create clients for resource modules. |
| 447 | */ |
| 448 | export class ApiClientFactory |
| 449 | extends Context.Opaque<ApiClientFactory, Effect.Success<typeof makeApiClientFactory>>()("ApiClientFactory") |
| 450 | { |
| 451 | static readonly layer = (config: ApiConfig) => |
| 452 | ApiClientFactory.toLayer(makeApiClientFactory).pipe(Layer.provide(RpcSerializationLayer(config))) |
| 453 | static readonly layerFromConfig = Layer.unwrap( |
| 454 | Effect.gen(function*() { |
| 455 | const config = yield* DefaultApiConfig |
| 456 | return ApiClientFactory.layer(config) |
| 457 | }) |
| 458 | ) |
| 459 | |
| 460 | static readonly makeFor = |
| 461 | (requestLevelLayers: Layer.Layer<never>, options?: ClientForOptions) => |
| 462 | <M extends RequestsAny>( |
| 463 | resource: M |
| 464 | ) => |
| 465 | ApiClientFactory.use((apiClientFactory) => { |
| 466 | const f = apiClientFactory(requestLevelLayers, options) |
| 467 | return f(resource) |
| 468 | }) |
| 469 | } |