(options?: Https.AgentOptions | undefined): Layer.Layer<HttpAgent>Provides the HttpAgent service using scoped Node http and https
agents configured with the supplied options.
export const const layerAgentOptions: (
options?: Https.AgentOptions | undefined
) => Layer.Layer<HttpAgent>
Provides the HttpAgent service using scoped Node http and https
agents configured with the supplied options.
layerAgentOptions: (options: anyoptions?: import HttpsHttps.type Https.AgentOptions = /*unresolved*/ anyAgentOptions | 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<
class HttpAgentclass HttpAgent {
key: Identifier;
Service: {
http: Http.Agent;
https: Https.Agent;
};
}
Service tag for the paired Node http and https agents used by the
node:http-backed HTTP client.
HttpAgent
> = flow<[options?: any], Effect.Effect<{
readonly http: Http.Agent;
readonly https: Https.Agent;
}, never, Scope.Scope>, Layer.Layer<HttpAgent, never, never>>(ab: (options?: any) => Effect.Effect<{
readonly http: Http.Agent;
readonly https: Https.Agent;
}, never, Scope.Scope>, bc: (b: Effect.Effect<{
readonly http: Http.Agent;
readonly https: Https.Agent;
}, never, Scope.Scope>) => Layer.Layer<HttpAgent, never, never>): (options?: any) => Layer.Layer<HttpAgent, never, never> (+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 makeAgent: (
options?: Https.AgentOptions
) => Effect.Effect<
HttpAgent["Service"],
never,
Scope.Scope
>
Acquires Node http and https agents with the supplied options and
destroys both agents when the enclosing scope is finalized.
makeAgent, 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(class HttpAgentclass HttpAgent {
key: Identifier;
Service: {
http: Http.Agent;
https: Https.Agent;
};
of: (this: void, self: { readonly http: Http.Agent; readonly https: Https.Agent }) => { readonly http: Http.Agent; readonly https: Https.Agent };
context: (self: { readonly http: Http.Agent; readonly https: Https.Agent }) => Context.Context<HttpAgent>;
use: (f: (service: { readonly http: Http.Agent; readonly https: Https.Agent }) => Effect.Effect<A, E, R>) => Effect.Effect<A, E, HttpAgent | R>;
useSync: (f: (service: { readonly http: Http.Agent; readonly https: Https.Agent }) => A) => Effect.Effect<A, never, HttpAgent>;
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 the paired Node http and https agents used by the
node:http-backed HTTP client.
HttpAgent))