(
api: HttpApi.HttpApi<ApiId, Groups, ApiError, ApiR>,
options: {
readonly httpClient: HttpClient.HttpClient.With<E, R>
readonly predicate?: Predicate.Predicate<{
readonly endpoint: HttpApiEndpoint.AnyWithProps
readonly group: HttpApiGroup.AnyWithProps
}>
readonly onGroup?: (options: {
readonly group: HttpApiGroup.AnyWithProps
readonly mergedAnnotations: Context.Context<never>
}) => void
readonly onEndpoint: (options: {
readonly group: HttpApiGroup.AnyWithProps
readonly endpoint: HttpApiEndpoint<string, HttpMethod.HttpMethod>
readonly mergedAnnotations: Context.Context<never>
readonly middleware: ReadonlySet<HttpApiMiddleware.TagClassAny>
readonly successes: ReadonlyMap<number, {
readonly ast: Option.Option<AST.AST>
readonly description: Option.Option<string>
}>
readonly errors: ReadonlyMap<number, {
readonly ast: Option.Option<AST.AST>
readonly description: Option.Option<string>
}>
readonly endpointFn: Function
}) => void
readonly transformResponse?:
| ((effect: Effect.Effect<unknown, unknown>) => Effect.Effect<unknown, unknown>)
| undefined
readonly baseUrl?: URL | string | undefined
}
)
| 105 | * @internal |
| 106 | */ |
| 107 | const makeClient = <ApiId extends string, Groups extends HttpApiGroup.Any, ApiError, ApiR, E, R>( |
| 108 | api: HttpApi.HttpApi<ApiId, Groups, ApiError, ApiR>, |
| 109 | options: { |
| 110 | readonly httpClient: HttpClient.HttpClient.With<E, R> |
| 111 | readonly predicate?: Predicate.Predicate<{ |
| 112 | readonly endpoint: HttpApiEndpoint.AnyWithProps |
| 113 | readonly group: HttpApiGroup.AnyWithProps |
| 114 | }> |
| 115 | readonly onGroup?: (options: { |
| 116 | readonly group: HttpApiGroup.AnyWithProps |
| 117 | readonly mergedAnnotations: Context.Context<never> |
| 118 | }) => void |
| 119 | readonly onEndpoint: (options: { |
| 120 | readonly group: HttpApiGroup.AnyWithProps |
| 121 | readonly endpoint: HttpApiEndpoint<string, HttpMethod.HttpMethod> |
| 122 | readonly mergedAnnotations: Context.Context<never> |
| 123 | readonly middleware: ReadonlySet<HttpApiMiddleware.TagClassAny> |
| 124 | readonly successes: ReadonlyMap<number, { |
| 125 | readonly ast: Option.Option<AST.AST> |
| 126 | readonly description: Option.Option<string> |
| 127 | }> |
| 128 | readonly errors: ReadonlyMap<number, { |
| 129 | readonly ast: Option.Option<AST.AST> |
| 130 | readonly description: Option.Option<string> |
| 131 | }> |
| 132 | readonly endpointFn: Function |
| 133 | }) => void |
| 134 | readonly transformResponse?: |
| 135 | | ((effect: Effect.Effect<unknown, unknown>) => Effect.Effect<unknown, unknown>) |
| 136 | | undefined |
| 137 | readonly baseUrl?: URL | string | undefined |
| 138 | } |
| 139 | ): Effect.Effect< |
| 140 | void, |
| 141 | never, |
| 142 | HttpApiMiddleware.HttpApiMiddleware.Without<ApiR | HttpApiGroup.ClientContext<Groups>> |
| 143 | > => |
| 144 | Effect.gen(function*() { |
| 145 | const context = yield* Effect.context<any>() |
| 146 | const httpClient = options.httpClient.pipe( |
| 147 | options?.baseUrl === undefined |
| 148 | ? identity |
| 149 | : HttpClient.mapRequest( |
| 150 | HttpClientRequest.prependUrl(options.baseUrl.toString()) |
| 151 | ) |
| 152 | ) |
| 153 | HttpApi.reflect(api as any, { |
| 154 | predicate: options?.predicate, |
| 155 | onGroup(onGroupOptions) { |
| 156 | options.onGroup?.(onGroupOptions) |
| 157 | }, |
| 158 | onEndpoint(onEndpointOptions) { |
| 159 | const { endpoint, errors, successes } = onEndpointOptions |
| 160 | const makeUrl = compilePath(endpoint.path) |
| 161 | const decodeMap: Record< |
| 162 | number | "orElse", |
| 163 | (response: HttpClientResponse.HttpClientResponse) => Effect.Effect<any, any> |
| 164 | > = { orElse: statusOrElse } |
no test coverage detected
searching dependent graphs…