import * as Effect from "../Effect.ts"; import type { FileSystem } from "../FileSystem.ts"; import type { Cookie } from "../http/Cookies.ts"; import type * as Etag from "../http/Etag.ts"; import type { HttpPlatform } from "../http/HttpPlatform.ts"; import * as HttpRouter from "../http/HttpRouter.ts"; import * as Request from "../http/HttpServerRequest.ts"; import { HttpServerRequest } from "../http/HttpServerRequest.ts"; import type { HttpServerResponse } from "../http/HttpServerResponse.ts"; import * as Layer from "../Layer.ts"; import type { Path } from "../Path.ts"; import { type Pipeable } from "../Pipeable.ts"; import * as Redacted from "../Redacted.ts"; import * as Scope from "../Scope.ts"; import type { NoInfer } 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 HttpApiSecurity from "./HttpApiSecurity.ts"; /** * Registers an `HttpApi` with a `HttpRouter`. * * @stability unstable * @category layers * @since 4.0.0 */ export declare const layer: (api: HttpApi.HttpApi, options?: { readonly openapiPath?: `/${string}` | undefined; }) => Layer.Layer>; /** * Create a `Layer` that implements all endpoints in an `HttpApi` group. * * **Details** * * The `build` function receives an unimplemented `Handlers` instance that can * be used to add handlers to the group. Implement endpoints with * `handlers.handle`. * * @stability unstable * @category handlers * @since 4.0.0 */ export declare const group: , Return>(api: HttpApi.HttpApi, groupIdentifier: Identifier, build: (handlers: Handlers.FromGroup>) => Handlers.ValidateReturn) => Layer.Layer, Handlers.Error, Exclude, Scope.Scope>>; /** * Creates a reusable handler for a single endpoint in an API group. * * **Details** * * Returns the supplied callback unchanged, with its request, success, and error * types inferred from the endpoint, preserving the callback's service * requirements. Pass the result to `handlers.handle` when implementing the group. * * @stability unstable * @category handlers * @since 4.0.0 */ export declare const handler: , const EndpointIdentifier extends HttpApiGroup.EndpointsWithIdentifier["identifier"], R>(_api: HttpApi.HttpApi, _groupIdentifier: GroupIdentifier, _endpointIdentifier: EndpointIdentifier, f: HttpApiEndpoint.HandlerWithIdentifier, EndpointIdentifier, HttpApiEndpoint.MiddlewareError, EndpointIdentifier>>, R>) => HttpApiEndpoint.HandlerWithIdentifier, EndpointIdentifier, HttpApiEndpoint.MiddlewareError, EndpointIdentifier>>, R>; declare const HandlersTypeId = "~effect/http-api/HttpApiBuilder/Handlers"; type HandlerRequirements>> = HttpApiEndpoint.Middleware | HttpApiEndpoint.MiddlewareServices | ([R] extends [never] ? never : HttpRouter.Request.From<"Requires", R>); interface HandlerOptions { readonly uninterruptible?: boolean | undefined; } type HandleAllEntry = HttpApiEndpoint.Handler, unknown> | { readonly handler: HttpApiEndpoint.Handler, unknown>; readonly options?: HandlerOptions | undefined; }; type HandleAllHandlers> = { readonly [Identifier in keyof EndpointsByIdentifier]?: HandleAllEntry; }; type HandleAllExtraKeys, HandlersByIdentifier> = { readonly [Identifier in Exclude]: never; }; type NotHandledIdentifier = Identifier extends HandledIdentifiers ? never : unknown; type HandleAllEntryHandler = Entry extends { readonly handler: infer Handler; } ? Handler : Entry; type HandleAllRequirements, HandlersByIdentifier extends HandleAllHandlers> = { readonly [Identifier in keyof HandlersByIdentifier & keyof EndpointsByIdentifier]: HandleAllEntryHandler extends HttpApiEndpoint.Handler, infer R1> ? HandlerRequirements : never; }[keyof HandlersByIdentifier & keyof EndpointsByIdentifier]; type HandlersResult = A extends Effect.Effect ? H : A; type MissingHandlerNames> = Exclude; type ValidateHandlersReturn, Missing = H extends Handlers ? MissingHandlerNames : never> = H extends Handlers ? [Missing] extends [never] ? A : `Endpoint not handled: ${Missing & string}` : `Must return the implemented handlers`; /** * Mutable handler collection for one `HttpApi` group. * * **Details** * * Each call to `handle` or `handleRaw` registers an endpoint implementation and * adds that endpoint identifier to the type-level set of implemented endpoints. * Endpoint identifiers that were already handled are rejected at the type level. * * @stability unstable * @category handlers * @since 4.0.0 */ export interface Handlers = {}, HandledIdentifiers extends keyof EndpointsByIdentifier = never> extends Pipeable { readonly [HandlersTypeId]: typeof HandlersTypeId; readonly "~EndpointsByIdentifier": EndpointsByIdentifier; readonly "~HandledIdentifiers": HandledIdentifiers; /** * Add the implementation for an unhandled `HttpApiEndpoint` to a `Handlers` group. */ handle(identifier: Identifier & NotHandledIdentifier, handler: HttpApiEndpoint.Handler, R1>, options?: { readonly uninterruptible?: boolean | undefined; } | undefined): Handlers, EndpointsByIdentifier, HandledIdentifiers | Identifier>; /** * Add implementations for unhandled `HttpApiEndpoint`s in a `Handlers` group. */ handleAll>>(handlers: HandlersByIdentifier & HandleAllExtraKeys, HandlersByIdentifier>): Handlers, EndpointsByIdentifier, HandledIdentifiers | (keyof HandlersByIdentifier & keyof EndpointsByIdentifier)>; /** * Add the implementation for an unhandled `HttpApiEndpoint` to a `Handlers` group. * This version opts out of automatic payload decoding and provides the raw request. */ handleRaw(identifier: Identifier & NotHandledIdentifier, handler: HttpApiEndpoint.HandlerRaw, R1>, options?: { readonly uninterruptible?: boolean | undefined; } | undefined): Handlers, EndpointsByIdentifier, HandledIdentifiers | Identifier>; } /** * Namespace containing helper types for `HttpApiBuilder` handler collections. * * @stability unstable * @since 4.0.0 */ export declare namespace Handlers { /** * Creates a handler collection for a group where every endpoint in the group is * still awaiting an implementation. * * @stability unstable * @category handlers * @since 4.0.0 */ type FromGroup = Handlers; /** * Validates the return value of a group handler builder, preserving successful * handler collections and producing a descriptive type error when endpoints remain * unhandled. * * @stability unstable * @category handlers * @since 4.0.0 */ type ValidateReturn = ValidateHandlersReturn; /** * Extracts the error channel from an effect that produces a `Handlers` * collection, returning `never` for non-effectful handler collections. * * @stability unstable * @category handlers * @since 4.0.0 */ type Error = A extends Effect.Effect, infer _EX, infer _RX> ? _EX : never; /** * Extracts the services required by a handler collection, including both handler * requirements and the environment required to construct the handlers. * * @stability unstable * @category handlers * @since 4.0.0 */ type Context = A extends Handlers ? _R : A extends Effect.Effect, infer _EX, infer _RX> ? _R | _RX : never; } type EndpointReturn, EndpointIdentifier extends HttpApiGroup.Endpoints>["identifier"], R, Endpoint extends HttpApiEndpoint.Constraint = HttpApiEndpoint.WithIdentifier>, EndpointIdentifier>> = Effect.Effect>>, never, HttpApiEndpoint.ServerServices | HttpApiEndpoint.Middleware | HttpApiEndpoint.MiddlewareServices | Etag.Generator | FileSystem | HttpPlatform | Path>; /** * Builds the server-side HTTP effect for a single endpoint in an API group using * the endpoint metadata, middleware, codecs, and supplied handler. * * @stability unstable * @category handlers * @since 4.0.0 */ export declare const endpoint: , const EndpointIdentifier extends HttpApiGroup.Endpoints>["identifier"], R>(api: HttpApi.HttpApi, groupIdentifier: GroupIdentifier, endpointIdentifier: EndpointIdentifier, handler: NoInfer>, EndpointIdentifier, never, R>>) => EndpointReturn; /** * Decodes credentials for an HTTP API security scheme from the current request, * supporting bearer, API key, and basic authentication inputs. * * @stability unstable * @category security * @since 4.0.0 */ export declare const securityDecode: (self: Security) => Effect.Effect, never, HttpServerRequest | Request.ParsedSearchParams>; /** * Registers a pre-response handler that sets an API-key cookie on the outgoing * response, defaulting the cookie to `secure` and `httpOnly` unless overridden. * * @stability unstable * @category security * @since 4.0.0 */ export declare const securitySetCookie: (self: HttpApiSecurity.ApiKey, value: string | Redacted.Redacted, options?: Cookie["options"]) => Effect.Effect; export {}; //# sourceMappingURL=HttpApiBuilder.d.ts.map