/** * @since 1.0.0 */ import type { Brand } from "effect/Brand"; import * as Context from "effect/Context"; import type { Effect } from "effect/Effect"; import * as Option from "effect/Option"; import { type Pipeable } from "effect/Pipeable"; import * as Schema from "effect/Schema"; import type * as Stream from "effect/Stream"; import type * as Types from "effect/Types"; import type * as HttpApiMiddleware from "./HttpApiMiddleware.js"; import * as HttpApiSchema from "./HttpApiSchema.js"; import type { HttpMethod } from "./HttpMethod.js"; import * as HttpRouter from "./HttpRouter.js"; import type { HttpServerRequest } from "./HttpServerRequest.js"; import type { HttpServerResponse } from "./HttpServerResponse.js"; import type * as Multipart from "./Multipart.js"; /** * @since 1.0.0 * @category type ids */ export declare const TypeId: unique symbol; /** * @since 1.0.0 * @category type ids */ export type TypeId = typeof TypeId; /** * @since 1.0.0 * @category guards */ export declare const isHttpApiEndpoint: (u: unknown) => u is HttpApiEndpoint; /** * Represents a path segment. A path segment is a string that represents a * segment of a URL path. * * @since 1.0.0 * @category models */ export type PathSegment = `/${string}`; /** * Represents an API endpoint. An API endpoint is mapped to a single route on * the underlying `HttpRouter`. * * @since 1.0.0 * @category models */ export interface HttpApiEndpoint extends Pipeable { readonly [TypeId]: TypeId; readonly name: Name; readonly path: PathSegment; readonly method: Method; readonly pathSchema: Option.Option>; readonly urlParamsSchema: Option.Option>; readonly payloadSchema: Option.Option>; readonly headersSchema: Option.Option>; readonly successSchema: Schema.Schema; readonly errorSchema: Schema.Schema; readonly annotations: Context.Context; readonly middlewares: ReadonlySet; /** * Add a schema for the success response of the endpoint. The status code * will be inferred from the schema, otherwise it will default to 200. */ addSuccess(schema: S, annotations?: { readonly status?: number | undefined; }): HttpApiEndpoint | Schema.Schema.Type, Error, R | Schema.Schema.Context, RE>; /** * Add an error response schema to the endpoint. The status code * will be inferred from the schema, otherwise it will default to 500. */ addError(schema: E, annotations?: { readonly status?: number | undefined; }): HttpApiEndpoint, R, RE | Schema.Schema.Context>; /** * Set the schema for the request body of the endpoint. The schema will be * used to validate the request body before the handler is called. * * For endpoints with no request body, the payload will use the url search * parameters. * * You can set a multipart schema to handle file uploads by using the * `HttpApiSchema.Multipart` combinator. */ setPayload

(schema: P & HttpApiEndpoint.ValidatePayload): HttpApiEndpoint, Headers, Success, Error, R | Schema.Schema.Context

, RE>; /** * Set the schema for the path parameters of the endpoint. The schema will be * used to validate the path parameters before the handler is called. */ setPath(schema: Path & HttpApiEndpoint.ValidatePath): HttpApiEndpoint, UrlParams, Payload, Headers, Success, Error, R | Schema.Schema.Context, RE>; /** * Set the schema for the url search parameters of the endpoint. */ setUrlParams(schema: UrlParams & HttpApiEndpoint.ValidateUrlParams): HttpApiEndpoint, Payload, Headers, Success, Error, R | Schema.Schema.Context, RE>; /** * Set the schema for the headers of the endpoint. The schema will be * used to validate the headers before the handler is called. */ setHeaders(schema: H & HttpApiEndpoint.ValidateHeaders): HttpApiEndpoint, Success, Error, R | Schema.Schema.Context, RE>; /** * Add a prefix to the path of the endpoint. */ prefix(prefix: PathSegment): HttpApiEndpoint; /** * Add an `HttpApiMiddleware` to the endpoint. */ middleware(middleware: Context.Tag): HttpApiEndpoint, R | I, RE | HttpApiMiddleware.HttpApiMiddleware.ErrorContext>; /** * Add an annotation on the endpoint. */ annotate(tag: Context.Tag, value: S): HttpApiEndpoint; /** * Merge the annotations of the endpoint with the provided context. */ annotateContext(context: Context.Context): HttpApiEndpoint; } /** * @since 1.0.0 * @category models */ export declare namespace HttpApiEndpoint { /** * @since 1.0.0 * @category models */ interface Any extends Pipeable { readonly [TypeId]: TypeId; readonly name: string; } /** * @since 1.0.0 * @category models */ interface AnyWithProps extends HttpApiEndpoint { } /** * @since 1.0.0 * @category models */ type Name = Endpoint extends HttpApiEndpoint ? _Name : never; /** * @since 1.0.0 * @category models */ type Success = Endpoint extends HttpApiEndpoint ? _Success : never; /** * @since 1.0.0 * @category models */ type Error = Endpoint extends HttpApiEndpoint ? _Error : never; /** * @since 1.0.0 * @category models */ type PathParsed = Endpoint extends HttpApiEndpoint ? _Path : never; /** * @since 1.0.0 * @category models */ type UrlParams = Endpoint extends HttpApiEndpoint ? _UrlParams : never; /** * @since 1.0.0 * @category models */ type Payload = Endpoint extends HttpApiEndpoint ? _Payload : never; /** * @since 1.0.0 * @category models */ type Headers = Endpoint extends HttpApiEndpoint ? _Headers : never; /** * @since 1.0.0 * @category models */ type Request = Endpoint extends HttpApiEndpoint ? ([_Path] extends [never] ? {} : { readonly path: _Path; }) & ([_UrlParams] extends [never] ? {} : { readonly urlParams: _UrlParams; }) & ([_Payload] extends [never] ? {} : _Payload extends Brand ? { readonly payload: Stream.Stream; } : { readonly payload: _Payload; }) & ([_Headers] extends [never] ? {} : { readonly headers: _Headers; }) & { readonly request: HttpServerRequest; } : {}; /** * @since 1.0.0 * @category models */ type RequestRaw = Endpoint extends HttpApiEndpoint ? ([_Path] extends [never] ? {} : { readonly path: _Path; }) & ([_UrlParams] extends [never] ? {} : { readonly urlParams: _UrlParams; }) & ([_Headers] extends [never] ? {} : { readonly headers: _Headers; }) & { readonly request: HttpServerRequest; } : {}; /** * @since 1.0.0 * @category models */ type ClientRequest = (([Path] extends [void] ? {} : { readonly path: Path; }) & ([UrlParams] extends [never] ? {} : { readonly urlParams: UrlParams; }) & ([Headers] extends [never] ? {} : { readonly headers: Headers; }) & ([Payload] extends [never] ? {} : Payload extends infer P ? P extends Brand | Brand ? { readonly payload: FormData; } : { readonly payload: P; } : { readonly payload: Payload; })) extends infer Req ? keyof Req extends never ? (void | { readonly withResponse?: WithResponse; }) : Req & { readonly withResponse?: WithResponse; } : void; /** * @since 1.0.0 * @category models */ type Context = Endpoint extends HttpApiEndpoint ? _R : never; /** * @since 1.0.0 * @category models */ type ErrorContext = Endpoint extends HttpApiEndpoint ? _RE : never; /** * @since 1.0.0 * @category models */ type Handler = (request: Types.Simplify>) => Effect | HttpServerResponse, Error | E, R>; /** * @since 1.0.0 * @category models */ type HandlerRaw = (request: Types.Simplify>) => Effect | HttpServerResponse, Error | E, R>; /** * @since 1.0.0 * @category models */ type WithName = Extract; /** * @since 1.0.0 * @category models */ type ExcludeName = Exclude; /** * @since 1.0.0 * @category models */ type HandlerWithName = Handler, E, R>; /** * @since 1.0.0 * @category models */ type HandlerRawWithName = HandlerRaw, E, R>; /** * @since 1.0.0 * @category models */ type SuccessWithName = Success>; /** * @since 1.0.0 * @category models */ type ErrorWithName = Error>; /** * @since 1.0.0 * @category models */ type ContextWithName = Context>; /** * @since 1.0.0 * @category models */ type ErrorContextWithName = ErrorContext>; /** * @since 1.0.0 * @category models */ type ExcludeProvided = Exclude>>; /** * @since 1.0.0 * @category models */ type ValidatePath = S extends Schema.Schema ? [_I] extends [Readonly>] ? {} : `Path schema must be encodeable to strings` : {}; /** * @since 1.0.0 * @category models */ type ValidateUrlParams = S extends Schema.Schema ? [_I] extends [Readonly | undefined>>] ? {} : `UrlParams schema must be encodeable to strings` : {}; /** * @since 1.0.0 * @category models */ type ValidateHeaders = S extends Schema.Schema ? [_I] extends [Readonly>] ? {} : `Headers schema must be encodeable to strings` : {}; /** * @since 1.0.0 * @category models */ type ValidatePayload = Method extends HttpMethod.NoBody ? P extends Schema.Schema ? [_I] extends [Readonly | undefined>>] ? {} : `'${Method}' payload must be encodeable to strings` : {} : {}; /** * @since 1.0.0 * @category models */ type ValidateParams, Prev extends (Schema.Schema.Any | Schema.PropertySignature.Any) = never> = Schemas extends [ infer Head extends (Schema.Schema.Any | Schema.PropertySignature.Any), ...infer Tail extends ReadonlyArray ] ? [ Head extends HttpApiSchema.Param ? HttpApiSchema.Param<_Name, any> extends Prev ? `Duplicate param: ${_Name}` : [Schema.Schema.Encoded & {}] extends [string] ? Head : `Must be encodeable to string: ${_Name}` : Head, ...ValidateParams ] : Schemas; /** * @since 1.0.0 * @category models */ type AddError = Endpoint extends HttpApiEndpoint ? HttpApiEndpoint<_Name, _Method, _Path, _UrlParams, _Payload, _Headers, _Success, _Error | E, _R, _RE | R> : never; /** * @since 1.0.0 * @category models */ type AddContext = Endpoint extends HttpApiEndpoint ? HttpApiEndpoint<_Name, _Method, _Path, _UrlParams, _Payload, _Headers, _Success, _Error | HttpApiMiddleware.HttpApiMiddleware.Error, _R | R, _RE | HttpApiMiddleware.HttpApiMiddleware.ErrorContext> : never; /** * @since 1.0.0 * @category models */ type PathEntries> = Extract extends infer K ? K extends keyof Schemas ? Schemas[K] extends HttpApiSchema.Param ? [_Name, _S] : Schemas[K] extends (Schema.Schema.Any | Schema.PropertySignature.Any) ? [K, Schemas[K]] : never : never : never; type OptionalTypePropertySignature = Schema.PropertySignature<"?:", any, PropertyKey, Schema.PropertySignature.Token, any, boolean, unknown> | Schema.PropertySignature<"?:", any, PropertyKey, Schema.PropertySignature.Token, never, boolean, unknown> | Schema.PropertySignature<"?:", never, PropertyKey, Schema.PropertySignature.Token, any, boolean, unknown> | Schema.PropertySignature<"?:", never, PropertyKey, Schema.PropertySignature.Token, never, boolean, unknown>; /** * @since 1.0.0 * @category models */ type ExtractPath> = Schema.Simplify<{ readonly [Entry in Extract, [any, OptionalTypePropertySignature]> as Entry[0]]?: Schema.Schema.Type; } & { readonly [Entry in Exclude, [any, OptionalTypePropertySignature]> as Entry[0]]: Schema.Schema.Type; }>; /** * @since 1.0.0 * @category models */ type Constructor = >(segments: TemplateStringsArray, ...schemas: ValidateParams) => HttpApiEndpoint>, never, never, never, void, never, Schema.Schema.Context>; } /** * @since 1.0.0 * @category constructors */ export declare const make: (method: Method) => { (name: Name): HttpApiEndpoint.Constructor; (name: Name, path: PathSegment): HttpApiEndpoint; }; /** * @since 1.0.0 * @category constructors */ export declare const get: { /** * @since 1.0.0 * @category constructors */ (name: Name): HttpApiEndpoint.Constructor; /** * @since 1.0.0 * @category constructors */ (name: Name, path: PathSegment): HttpApiEndpoint; }; /** * @since 1.0.0 * @category constructors */ export declare const post: { /** * @since 1.0.0 * @category constructors */ (name: Name): HttpApiEndpoint.Constructor; /** * @since 1.0.0 * @category constructors */ (name: Name, path: PathSegment): HttpApiEndpoint; }; /** * @since 1.0.0 * @category constructors */ export declare const put: { /** * @since 1.0.0 * @category constructors */ (name: Name): HttpApiEndpoint.Constructor; /** * @since 1.0.0 * @category constructors */ (name: Name, path: PathSegment): HttpApiEndpoint; }; /** * @since 1.0.0 * @category constructors */ export declare const patch: { /** * @since 1.0.0 * @category constructors */ (name: Name): HttpApiEndpoint.Constructor; /** * @since 1.0.0 * @category constructors */ (name: Name, path: PathSegment): HttpApiEndpoint; }; /** * @since 1.0.0 * @category constructors */ export declare const del: { /** * @since 1.0.0 * @category constructors */ (name: Name): HttpApiEndpoint.Constructor; /** * @since 1.0.0 * @category constructors */ (name: Name, path: PathSegment): HttpApiEndpoint; }; /** * @since 1.0.0 * @category constructors */ export declare const head: { /** * @since 1.0.0 * @category constructors */ (name: Name): HttpApiEndpoint.Constructor; /** * @since 1.0.0 * @category constructors */ (name: Name, path: PathSegment): HttpApiEndpoint; }; /** * @since 1.0.0 * @category constructors */ export declare const options: { /** * @since 1.0.0 * @category constructors */ (name: Name): HttpApiEndpoint.Constructor; /** * @since 1.0.0 * @category constructors */ (name: Name, path: PathSegment): HttpApiEndpoint; }; //# sourceMappingURL=HttpApiEndpoint.d.ts.map