Layer.Layer<
HttpPlatform.HttpPlatform | Etag.Generator | NodeServices.NodeServices,
never,
never
>Provides the Node HTTP support services used by NodeHttpServer, including
the HTTP platform, ETag generator, and core Node platform services.
export const const layerHttpServices: Layer.Layer<
| NodeServices.NodeServices
| HttpPlatform.HttpPlatform
| Etag.Generator
>
const layerHttpServices: {
build: (memoMap: MemoMap, scope: Scope.Scope) => Effect<Context.Context<Generator | HttpPlatform | NodeServices>, never, never>;
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; <…;
}
Provides the Node HTTP support services used by NodeHttpServer, including
the HTTP platform, ETag generator, and core Node platform services.
layerHttpServices: 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 NodeServicesNodeServices.type NodeServices =
| FileSystem.FileSystem
| Path.Path
| ChildProcessSpawner
| Crypto
| Stdio
| Terminal
The union of core services provided by the Node platform layer, including
child process spawning, filesystem, path, stdio, and terminal services.
NodeServices | import HttpPlatformHttpPlatform.class HttpPlatformclass HttpPlatform {
key: Identifier;
Service: {
fileResponse: (path: string, options?: Response.Options.WithContent & { readonly bytesToRead?: FileSystem.SizeInput | undefined; readonly chunkSize?: FileSystem.SizeInput | undefined; readonly offset?: FileSystem.SizeInput | undefined }) => Effect.Effec…;
fileWebResponse: (file: Body.HttpBody.FileLike, options?: Response.Options.WithContent & { readonly bytesToRead?: FileSystem.SizeInput | undefined; readonly chunkSize?: FileSystem.SizeInput | undefined; readonly offset?: FileSystem.SizeInput | undefined })…;
};
}
Service for platform-specific HTTP response helpers, including file-backed server responses.
HttpPlatform | import EtagEtag.class Generatorclass Generator {
key: Identifier;
Service: {
fromFileInfo: (info: FileSystem.File.Info) => Effect.Effect<Etag>;
fromFileWeb: (file: Body.HttpBody.FileLike) => Effect.Effect<Etag>;
};
}
Service for generating ETags from filesystem file information or Web File-like metadata.
Generator
> = import LayerLayer.const mergeAll: <
Layers extends [
Layer<never, any, any>,
...Array<Layer<never, any, any>>
]
>(
...layers: Layers
) => Layer<
Success<Layers[number]>,
Error<Layers[number]>,
Services<Layers[number]>
>
Combines all the provided layers concurrently, creating a new layer with
merged input, error, and output types.
When to use
Use when you need to combine multiple independent layers.
Details
All layers are built concurrently, and their outputs are merged into a single layer.
If multiple merged layers depend on the same layer value, that dependency is
shared by default. Reuse a named layer value when you want services to share
the same resource, such as one database pool.
Example (Merging independent layers)
import { Context, Effect, Layer } from "effect"
class Database extends Context.Service<Database, {
readonly query: (sql: string) => Effect.Effect<string>
}>()("Database") {}
class Logger extends Context.Service<Logger, {
readonly log: (msg: string) => Effect.Effect<void>
}>()("Logger") {}
const dbLayer = Layer.succeed(Database, {
query: Effect.fn("Database.query")((sql: string) => Effect.succeed("result"))
})
const loggerLayer = Layer.succeed(Logger, {
log: Effect.fn("Logger.log")((msg: string) => Effect.sync(() => console.log(msg)))
})
const mergedLayer = Layer.mergeAll(dbLayer, loggerLayer)
mergeAll(
import NodeHttpPlatformNodeHttpPlatform.layer,
import EtagEtag.const layerWeak: Layer.Layer<Generator>const layerWeak: {
build: (memoMap: MemoMap, scope: Scope.Scope) => Effect<Context.Context<Generator>, never, never>;
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; <…;
}
Layer that provides a Generator which produces weak ETags from file size and modification time metadata.
layerWeak,
import NodeServicesNodeServices.const layer: Layer.Layer<NodeServices>const layer: {
build: (memoMap: MemoMap, scope: Scope.Scope) => Effect<Context.Context<NodeServices>, never, never>;
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; <…;
}
Provides the default Node implementations for child process spawning,
filesystem, path, stdio, and terminal services.
layer
)