import * as Effect from "../Effect.ts"; import * as Sse from "../encoding/Sse.ts"; import type * as Headers from "../http/Headers.ts"; import * as HttpClient from "../http/HttpClient.ts"; import * as HttpClientError from "../http/HttpClientError.ts"; import type * as HttpClientResponse from "../http/HttpClientResponse.ts"; import * as Schema from "../Schema.ts"; import type * as Socket from "../socket/Socket.ts"; import * as Stream from "../Stream.ts"; import type { Simplify } from "../Types.ts"; import * as HttpApi from "./HttpApi.ts"; import * as HttpApiEndpoint from "./HttpApiEndpoint.ts"; import type * as HttpApiGroup from "./HttpApiGroup.ts"; import type * as HttpApiMiddleware from "./HttpApiMiddleware.ts"; import * as HttpApiSchema from "./HttpApiSchema.ts"; /** * The type-safe client shape generated from HTTP API groups, with non-top-level * groups exposed as nested objects and top-level endpoints exposed as methods. * * @stability unstable * @category models * @since 4.0.0 */ export type Client = Simplify<{ readonly [Group in Extract as HttpApiGroup.Identifier]: Client.Group; } & Client.TopLevelMethods>; /** * Derives the typed client interface for an `HttpApi`, preserving any additional * client error and service requirements supplied by the caller. * * @stability unstable * @category utility types * @since 4.0.0 */ export type ForApi = Api extends HttpApi.HttpApi ? Client : never; /** * Computes the decoded success value a client receives for an endpoint * success schema, including headers, streaming Server-Sent Events, and * streaming byte responses. * * @stability unstable * @category utility types * @since 4.0.0 */ export type SuccessType = S extends HttpApiSchema.WithHeaders ? HttpApiSchema.withHeaders, _Headers["Type"]> : S extends HttpApiSchema.StreamSse ? Stream.Stream<_Value, _Error["Type"] | HttpClientError.HttpClientError | Schema.SchemaError | Sse.Retry | Sse.SseError, never> : S extends HttpApiSchema.StreamUint8Array ? Stream.Stream : S extends HttpApiSchema.StreamNdjson ? Stream.Stream<_S["Type"], HttpClientError.HttpClientError | Schema.SchemaError, never> : S extends HttpApiSchema.Upgrade ? Upgraded : S extends Schema.Constraint ? S["Type"] : never; /** * The value a client method returns for an endpoint declared with * `HttpApiSchema.Upgrade`: the headers of the `101 Switching Protocols` * response and the upgraded connection. * * **Details** * * See `HttpClientResponse.upgrade` for how the connection behaves and when it * closes. * * @stability unstable * @category models * @since 4.0.6 */ export interface Upgraded { readonly headers: Headers.Headers; readonly socket: Socket.Socket; } type SuccessDecodingServices = S extends HttpApiSchema.StreamSse ? _Events["DecodingServices"] | _Error["DecodingServices"] : S extends HttpApiSchema.StreamUint8Array ? never : S extends HttpApiSchema.StreamNdjson ? _S["DecodingServices"] : S extends Schema.Constraint ? S["DecodingServices"] : never; /** * Helper types used to describe generated HTTP API clients, including endpoint * methods, response modes, and grouped client shapes. * * @stability unstable * @since 4.0.0 */ export declare namespace Client { /** * The response mode accepted by generated client methods, controlling whether a * call returns the decoded success value, the raw response, or both. * * @stability unstable * @category models * @since 4.0.0 */ type ResponseMode = HttpApiEndpoint.ClientResponseMode; /** * Computes the value returned by a client method for a success type and response * mode. * * @stability unstable * @category models * @since 4.0.0 */ type Response = Mode extends "decoded-and-response" ? [Success, HttpClientResponse.HttpClientResponse] : Mode extends "response-only" ? HttpClientResponse.HttpClientResponse : Success; type GroupByEndpoint = Group["endpoints"] extends infer Endpoints extends Readonly> ? { readonly [Identifier in keyof Endpoints]: Method; } : {}; /** * The client object for one API group, mapping each endpoint identifier in that * group to its typed client method. * * @stability unstable * @category models * @since 4.0.0 */ type Group = GroupByEndpoint; type MethodReturn = Effect.Effect, Mode>, HttpApiMiddleware.Error | HttpApiMiddleware.ClientError | E | HttpClientError.HttpClientError | ([Mode] extends ["response-only"] ? never : Endpoint["~Error"]["Type"] | Schema.SchemaError), R | PayloadR | Endpoint["~Params"]["EncodingServices"] | Endpoint["~Query"]["EncodingServices"] | Endpoint["~Payload"]["EncodingServices"] | Endpoint["~Headers"]["EncodingServices"] | ([Mode] extends ["response-only"] ? never : SuccessDecodingServices | Endpoint["~Error"]["DecodingServices"])>; /** * The typed function generated for an endpoint, accepting the endpoint request * shape, including optional per-call SSE decoding options. The returned effect's success, * error, and service channels reflect the endpoint schemas, middleware, and * selected response mode. * * **Details** * * The services of a streaming `payload` are inferred and added to the * returned effect. * * @stability unstable * @category models * @since 4.0.0 */ type Method = (request: Simplify>) => MethodReturn; /** * Extracts client methods for endpoints in top-level groups so they can be exposed * directly on the generated client object. * * @stability unstable * @category models * @since 4.0.0 */ type TopLevelMethods = { readonly [Endpoint in Extract>, HttpApiEndpoint.ConstraintRequest> as Endpoint["identifier"]]: Method; }; } type UrlBuilderRequestPart = [Value] extends [never] ? {} : { readonly [K in Key]: Value; }; type UrlBuilderRequest["Type"], Query = HttpApiEndpoint.Query["Type"]> = (UrlBuilderRequestPart<"params", Params> & UrlBuilderRequestPart<"query", Query>) extends infer Request ? keyof Request extends never ? void | undefined : Request : never; type UrlBuilderArgs = [Request] extends [void | undefined] ? [request?: Request] : [request: Request]; /** * The type-safe URL builder shape for an HTTP API, mirroring the generated client * layout while returning URL strings instead of executing requests. * * @stability unstable * @category models * @since 4.0.0 */ export type UrlBuilder = Api extends HttpApi.HttpApi ? [ Extract ] extends [never] ? UrlBuilderGroups : [Extract] extends [never] ? UrlBuilderTopLevelMethods : Simplify & UrlBuilderTopLevelMethods> : never; type UrlBuilderGroups = { readonly [Group in Extract as HttpApiGroup.Identifier]: UrlBuilderGroup>; }; type UrlBuilderGroup = { readonly [Endpoint in Endpoints as HttpApiEndpoint.Identifier]: UrlBuilderMethod; }; type UrlBuilderMethod = (...args: UrlBuilderArgs>) => string; type UrlBuilderTopLevelMethods = { readonly [Endpoint in HttpApiGroup.Endpoints> as HttpApiEndpoint.Identifier]: UrlBuilderMethod; }; /** * Constructs a type-safe client for an HTTP API using the `HttpClient` service, * endpoint schemas, middleware, and optional client or response transformations. * * @stability unstable * @category constructors * @since 4.0.0 */ export declare const make: (api: HttpApi.HttpApi, options?: { readonly transformClient?: ((client: HttpClient.HttpClient) => HttpClient.HttpClient) | undefined; readonly transformResponse?: ((effect: Effect.Effect) => Effect.Effect) | undefined; readonly baseUrl?: URL | string | undefined; }) => Effect.Effect, never, HttpClient.HttpClient | HttpApiGroup.MiddlewareClient>; /** * Constructs a type-safe client for an HTTP API from the supplied `HttpClient`, * using the API metadata to encode requests, execute middleware, and decode * responses. * * @stability unstable * @category constructors * @since 4.0.0 */ export declare const makeWith: (api: HttpApi.HttpApi, options: { readonly httpClient: HttpClient.HttpClient.With; readonly transformResponse?: ((effect: Effect.Effect) => Effect.Effect) | undefined; readonly baseUrl?: URL | string | undefined; }) => Effect.Effect, R>, never, HttpApiGroup.MiddlewareClient>; /** * Builds a typed client object for a single API group from the supplied * `HttpClient`, filtering the API to that group. * * @stability unstable * @category constructors * @since 4.0.0 */ export declare const group: , E, R>(api: HttpApi.HttpApi, options: { readonly group: GroupIdentifier; readonly httpClient: HttpClient.HttpClient.With; readonly transformResponse?: ((effect: Effect.Effect) => Effect.Effect) | undefined; readonly baseUrl?: URL | string | undefined; }) => Effect.Effect, E, R>, never, HttpApiGroup.MiddlewareClient>>; type EndpointReturn, EndpointIdentifier extends HttpApiGroup.EndpointsWithIdentifier["identifier"], E, R, Endpoint extends HttpApiEndpoint.ConstraintRequest = Extract, EndpointIdentifier>, HttpApiEndpoint.ConstraintRequest>> = Effect.Effect, never, HttpApiEndpoint.MiddlewareClient>; /** * Builds the typed client method for one endpoint in one API group, using the * supplied `HttpClient` and endpoint metadata. * * @stability unstable * @category constructors * @since 4.0.0 */ export declare const endpoint: , const EndpointIdentifier extends HttpApiGroup.EndpointsWithIdentifier["identifier"], E, R>(api: HttpApi.HttpApi, options: { readonly group: GroupIdentifier; readonly endpoint: EndpointIdentifier; readonly httpClient: HttpClient.HttpClient.With; readonly transformClient?: ((client: HttpClient.HttpClient.With) => HttpClient.HttpClient.With) | undefined; readonly transformResponse?: ((effect: Effect.Effect) => Effect.Effect) | undefined; readonly baseUrl?: URL | string | undefined; }) => EndpointReturn; /** * Creates a type-safe URL builder that mirrors `HttpApiClient.make`. * * **Example** (Building typed URLs) * * ```ts import.meta.vitest * import { Schema } from "effect" * import { HttpApi, HttpApiClient, HttpApiEndpoint, HttpApiGroup } from "effect/http-api" * * const Api = HttpApi.make("Api").add( * HttpApiGroup.make("users").add( * HttpApiEndpoint.get("getUser", "/users/:id", { * params: { id: Schema.String } * }) * ) * ) * * const buildUrl = HttpApiClient.urlBuilder(Api, { * baseUrl: "https://api.example.com" * }) * * buildUrl.users.getUser({ * params: { id: "123" } * }) // => "https://api.example.com/users/123" * ``` * * @stability unstable * @category constructors * @since 4.0.0 */ export declare const urlBuilder: (api: Api, options?: { readonly baseUrl?: URL | string | undefined; }) => UrlBuilder; export {}; //# sourceMappingURL=HttpApiClient.d.ts.map