(
evaluate: LazyArg<
Http.Server<typeof Http.IncomingMessage, typeof Http.ServerResponse>
>,
options: Net.ListenOptions & {
readonly disablePreemptiveShutdown?: boolean | undefined
readonly gracefulShutdownTimeout?: Duration.Input | undefined
}
): Layer.Layer<HttpServer.HttpServer, ServeError>Provides an HttpServer by creating and managing a scoped Node
http.Server with the supplied listen and shutdown options.
export const const layerServer: (
evaluate: LazyArg<
Http.Server<
typeof Http.IncomingMessage,
typeof Http.ServerResponse
>
>,
options: Net.ListenOptions & {
readonly disablePreemptiveShutdown?:
| boolean
| undefined
readonly gracefulShutdownTimeout?:
| Duration.Input
| undefined
}
) => Layer.Layer<
HttpServer.HttpServer,
ServeError
>
Provides an HttpServer by creating and managing a scoped Node
http.Server with the supplied listen and shutdown options.
layerServer: (
evaluate: LazyArg<
Http.Server<
typeof Http.IncomingMessage,
typeof Http.ServerResponse
>
>
evaluate: type LazyArg<A> = () => AA zero-argument function that produces a value when invoked.
When to use
Use to type a lazy value provider that should not run until called.
Example (Creating a lazy argument)
import { Function } from "effect"
const constNull: Function.LazyArg<null> = Function.constant(null)
LazyArg<import HttpHttp.type Http.Server = /*unresolved*/ anyServer<typeof import HttpHttp.IncomingMessage, typeof import HttpHttp.ServerResponse>>,
options: Net.ListenOptions & {
readonly disablePreemptiveShutdown?:
| boolean
| undefined
readonly gracefulShutdownTimeout?:
| Duration.Input
| undefined
}
options: import NetNet.type Net.ListenOptions = /*unresolved*/ anyListenOptions & {
readonly disablePreemptiveShutdown?: boolean | undefineddisablePreemptiveShutdown?: boolean | undefined
readonly gracefulShutdownTimeout?: Duration.Input | undefinedgracefulShutdownTimeout?: import DurationDuration.type Input =
| number
| bigint
| Duration.Duration
| readonly [seconds: number, nanos: number]
| `${number} nano`
| `${number} nanos`
| `${number} micro`
| `${number} micros`
| `${number} milli`
| `${number} millis`
| `${number} second`
| `${number} seconds`
| `${number} minute`
| `${number} minutes`
| `${number} hour`
| `${number} hours`
| `${number} day`
| `${number} days`
| `${number} week`
| `${number} weeks`
| "Infinity"
| "-Infinity"
| Duration.DurationObject
Valid input types that can be converted to a Duration.
When to use
Use when an API should accept any value that Effect can convert into a
Duration, including existing durations, millisecond numbers, nanosecond
bigints, high-resolution tuples, duration strings, infinity strings, or
duration objects.
Details
String inputs accept values like "10 seconds", "500 millis",
"Infinity", and "-Infinity". Finite fractional values that are
normalized to nanoseconds are rounded to the nearest nanosecond, with ties
away from zero.
Input | undefined
}
) => import LayerLayer.interface Layer<in ROut, out E = never, out RIn = never>A Layer describes how to build one or more services for dependency injection.
When to use
Use to model construction of application services for dependency injection,
especially when services have dependencies, can fail during construction, or
need scoped setup and release.
Details
A Layer<ROut, E, RIn> represents ROut as the services this layer
provides, E as the possible errors during layer construction, and RIn as
the services this layer requires as dependencies.
Layer<import HttpServerHttpServer.class HttpServerclass HttpServer {
key: Identifier;
Service: {
serve: { <E, R>(effect: Effect.Effect<HttpServerResponse, E, R>): Effect.Effect<void, never, Exclude<R, HttpServerRequest> | Scope.Scope>; <E, R, App extends Effect.Effect<HttpServerResponse, any, any>>(effect: Effect.Effect<HttpServerResponse, E…;
address: Address;
};
}
Service tag for an HTTP server runtime.
Details
The service can serve an HTTP response effect and exposes the address where the
server is listening.
HttpServer, class ServeErrorclass ServeError {
name: string;
message: string;
stack: string;
cause: unknown;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
_tag: Tag;
}
Error wrapping a low-level failure from the HTTP server implementation.
ServeError> = flow<[evaluate: LazyArg<Http.Server>, options: any], Effect.Effect<{
readonly serve: {
<E, R>(effect: Effect.Effect<HttpServerResponse, E, R>): Effect.Effect<void, never, Exclude<R, HttpServerRequest> | Scope.Scope>;
<E, R, App extends Effect.Effect<HttpServerResponse, any, any>>(effect: Effect.Effect<HttpServerResponse, E, R>, middleware: Middleware.HttpMiddleware.Applied<App, E, R>): Effect.Effect<void, never, Exclude<R, HttpServerRequest> | Scope.Scope>;
};
readonly address: HttpServer.Address;
}, ServeError, Scope.Scope>, Layer.Layer<...>>(ab: (evaluate: LazyArg<...>, options: any) => Effect.Effect<...>, bc: (b: Effect.Effect<...>) => Layer.Layer<...>): (evaluate: LazyArg<...>, options: any) => Layer.Layer<...> (+8 overloads)
Performs left-to-right function composition.
When to use
Use to build a reusable function from a left-to-right sequence of
transformations.
Details
The first function may have any arity. Every following function must be
unary.
Example (Composing functions left to right)
import { flow } from "effect"
import * as assert from "node:assert"
const len = (s: string): number => s.length
const double = (n: number): number => n * 2
const f = flow(len, double)
assert.strictEqual(f("aaa"), 6)
flow(const make: (
evaluate: LazyArg<Http.Server>,
options: any
) => Effect.Effect<
{
readonly serve: {
<E, R>(
effect: Effect.Effect<
HttpServerResponse,
E,
R
>
): Effect.Effect<
void,
never,
| Exclude<R, HttpServerRequest>
| Scope.Scope
>
<
E,
R,
App extends Effect.Effect<
HttpServerResponse,
any,
any
>
>(
effect: Effect.Effect<
HttpServerResponse,
E,
R
>,
middleware: Middleware.HttpMiddleware.Applied<
App,
E,
R
>
): Effect.Effect<
void,
never,
| Exclude<R, HttpServerRequest>
| Scope.Scope
>
}
readonly address: HttpServer.Address
},
ServeError,
Scope.Scope
>
Creates a scoped HttpServer from a Node http.Server, starts listening
with the supplied options, registers request and upgrade handling, and closes
the server during scope finalization with optional graceful-shutdown control.
make, import LayerLayer.const effect: {
<I, S>(service: Context.Key<I, S>): <E, R>(
effect: Effect<S, E, R>
) => Layer<I, E, Exclude<R, Scope.Scope>>
<I, S, E, R>(
service: Context.Key<I, S>,
effect: Effect<Types.NoInfer<S>, E, R>
): Layer<I, E, Exclude<R, Scope.Scope>>
}
Constructs a layer from an effect that produces a single service.
When to use
Use when you need to construct a Layer-provided service with an Effect,
dependencies, or scoped resource acquisition.
Details
This allows you to create a Layer from an Effect that produces a service.
The Effect is executed in the scope of the layer, allowing for proper
resource management.
Example (Creating a layer from an effect)
import { Context, Effect, Layer } from "effect"
class Database extends Context.Service<Database, {
readonly query: (sql: string) => Effect.Effect<string>
}>()("Database") {}
const layer = Layer.effect(Database,
Effect.sync(() => ({
query: (sql: string) => Effect.succeed(`Query: ${sql}`)
}))
)
effect(import HttpServerHttpServer.class HttpServerclass HttpServer {
key: Identifier;
Service: {
serve: { <E, R>(effect: Effect.Effect<HttpServerResponse, E, R>): Effect.Effect<void, never, Exclude<R, HttpServerRequest> | Scope.Scope>; <E, R, App extends Effect.Effect<HttpServerResponse, any, any>>(effect: Effect.Effect<HttpServerResponse, E…;
address: Address;
};
of: (this: void, self: { readonly serve: { <E, R>(effect: Effect.Effect<HttpServerResponse, E, R>): Effect.Effect<void, never, Exclude<R, HttpServerRequest> | Scope.Scope>; <E, R, App extends Effect.Effect<HttpServerResponse, any, any>>(effect…;
context: (self: { readonly serve: { <E, R>(effect: Effect.Effect<HttpServerResponse, E, R>): Effect.Effect<void, never, Exclude<R, HttpServerRequest> | Scope.Scope>; <E, R, App extends Effect.Effect<HttpServerResponse, any, any>>(effect: Effect.Eff…;
use: (f: (service: { readonly serve: { <E, R>(effect: Effect.Effect<HttpServerResponse, E, R>): Effect.Effect<void, never, Exclude<R, HttpServerRequest> | Scope.Scope>; <E, R, App extends Effect.Effect<HttpServerResponse, any, any>>(effect: Eff…;
useSync: (f: (service: { readonly serve: { <E, R>(effect: Effect.Effect<HttpServerResponse, E, R>): Effect.Effect<void, never, Exclude<R, HttpServerRequest> | Scope.Scope>; <E, R, App extends Effect.Effect<HttpServerResponse, any, any>>(effect: Eff…;
Identifier: Identifier;
stack: string | undefined;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
Service tag for an HTTP server runtime.
Details
The service can serve an HTTP response effect and exposes the address where the
server is listening.
HttpServer))