File size: 6,239 Bytes
31e8457 051bada 31e8457 051bada 31e8457 051bada 31e8457 051bada 31e8457 051bada 31e8457 051bada 31e8457 051bada 31e8457 051bada 31e8457 051bada 31e8457 051bada 31e8457 051bada 31e8457 051bada 31e8457 051bada 31e8457 051bada 31e8457 051bada 31e8457 051bada 31e8457 051bada 31e8457 051bada 31e8457 051bada 31e8457 051bada 31e8457 051bada 31e8457 051bada 31e8457 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | import * as Context from "../../Context.ts";
import * as Effect from "../../Effect.ts";
import * as Layer from "../../Layer.ts";
import * as Scope from "../../Scope.ts";
import { type HttpMiddleware } from "./HttpMiddleware.ts";
import { HttpServerError } from "./HttpServerError.ts";
import { HttpServerRequest } from "./HttpServerRequest.ts";
import type { HttpServerResponse } from "./HttpServerResponse.ts";
import { appendPreResponseHandlerUnsafe } from "./internal/preResponseHandler.ts";
/**
* Runs an HTTP server effect, sends the produced response with the supplied handler, and converts failures into HTTP responses.
*
* @category combinators
* @since 4.0.0
*/
export declare const toHandled: <E, R, EH, RH>(self: Effect.Effect<HttpServerResponse, E, R>, handleResponse: (request: HttpServerRequest, response: HttpServerResponse) => Effect.Effect<unknown, EH, RH>, middleware?: HttpMiddleware | undefined) => Effect.Effect<void, never, Exclude<R | RH | HttpServerRequest, Scope.Scope>>;
/**
* Disables automatic closing for an HTTP request scope.
*
* **Gotchas**
*
* Use only when another owner will close the scope; otherwise resources attached
* to the request scope can leak.
*
* @category resource management
* @since 4.0.0
*/
export declare const scopeDisableClose: (scope: Scope.Scope) => void;
/**
* Returns a streaming server response that closes the request scope when the body stream exits.
*
* @category resource management
* @since 4.0.0
*/
export declare const scopeTransferToStream: (response: HttpServerResponse) => HttpServerResponse;
/**
* Function run with the current request and response just before the response is sent, allowing the response to be replaced or failing with `HttpServerError`.
*
* @category Pre-response handlers
* @since 4.0.0
*/
export type PreResponseHandler = (request: HttpServerRequest, response: HttpServerResponse) => Effect.Effect<HttpServerResponse, HttpServerError>;
/**
* Registers an additional pre-response handler for the current HTTP server request.
*
* @category fiber refs
* @since 4.0.0
*/
export declare const appendPreResponseHandler: (handler: PreResponseHandler) => Effect.Effect<void, never, HttpServerRequest>;
export {
/**
* Registers a pre-response handler for the supplied HTTP server request.
*
* @category fiber refs
* @since 4.0.0
*/
appendPreResponseHandlerUnsafe };
/**
* Runs an effect after registering a pre-response handler for the current HTTP server request.
*
* @category fiber refs
* @since 4.0.0
*/
export declare const withPreResponseHandler: {
/**
* Runs an effect after registering a pre-response handler for the current HTTP server request.
*
* @category fiber refs
* @since 4.0.0
*/
(handler: PreResponseHandler): <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R | HttpServerRequest>;
/**
* Runs an effect after registering a pre-response handler for the current HTTP server request.
*
* @category fiber refs
* @since 4.0.0
*/
<A, E, R>(self: Effect.Effect<A, E, R>, handler: PreResponseHandler): Effect.Effect<A, E, R | HttpServerRequest>;
};
/**
* Converts an HTTP server effect into a Web `Request` handler using the supplied base context and optional middleware.
*
* @category converting
* @since 4.0.0
*/
export declare const toWebHandlerWith: <Provided, R = never, ReqR = Exclude<R, Provided | Scope.Scope | HttpServerRequest>>(context: Context.Context<Provided>) => <E>(self: Effect.Effect<HttpServerResponse, E, R>, middleware?: HttpMiddleware | undefined) => [ReqR] extends [never] ? (request: Request, context?: Context.Context<never> | undefined) => Promise<globalThis.Response> : (request: Request, context: Context.Context<ReqR>) => Promise<globalThis.Response>;
/**
* Converts an HTTP server effect into a Web `Request` handler using an empty base context.
*
* @category converting
* @since 4.0.0
*/
export declare const toWebHandler: <E>(self: Effect.Effect<HttpServerResponse, E, HttpServerRequest | Scope.Scope>, middleware?: HttpMiddleware | undefined) => (request: Request, context?: Context.Context<never> | undefined) => Promise<globalThis.Response>;
/**
* Builds a Web `Request` handler from a layer and handler factory, returning the handler with a `dispose` function for the layer scope.
*
* @category converting
* @since 4.0.0
*/
export declare const toWebHandlerLayerWith: <E, Provided, LE, R, ReqR = Exclude<R, Provided | Scope.Scope | HttpServerRequest>>(layer: Layer.Layer<Provided, LE>, options: {
readonly toHandler: (context: Context.Context<Provided>) => Effect.Effect<Effect.Effect<HttpServerResponse, E, R>, LE>;
readonly middleware?: HttpMiddleware | undefined;
readonly memoMap?: Layer.MemoMap | undefined;
}) => {
readonly dispose: () => Promise<void>;
readonly handler: [ReqR] extends [never] ? (request: Request, context?: Context.Context<never> | undefined) => Promise<globalThis.Response> : (request: Request, context: Context.Context<ReqR>) => Promise<globalThis.Response>;
};
/**
* Builds a Web `Request` handler for an HTTP server effect using a layer to provide its services, returning the handler with a `dispose` function.
*
* @category converting
* @since 4.0.0
*/
export declare const toWebHandlerLayer: <E, R, Provided, LE, ReqR = Exclude<R, Provided | Scope.Scope | HttpServerRequest>>(self: Effect.Effect<HttpServerResponse, E, R>, layer: Layer.Layer<Provided, LE>, options?: {
readonly middleware?: HttpMiddleware | undefined;
readonly memoMap?: Layer.MemoMap | undefined;
} | undefined) => {
readonly dispose: () => Promise<void>;
readonly handler: [ReqR] extends [never] ? (request: Request, context?: Context.Context<never> | undefined) => Promise<globalThis.Response> : (request: Request, context: Context.Context<ReqR>) => Promise<globalThis.Response>;
};
/**
* Adapts a Web `Request` handler into an HTTP server effect for the current `HttpServerRequest`.
*
* @category converting
* @since 4.0.0
*/
export declare const fromWebHandler: (handler: (request: Request) => Promise<Response>) => Effect.Effect<HttpServerResponse, HttpServerError, HttpServerRequest>;
//# sourceMappingURL=HttpEffect.d.ts.map |