<Serve extends Layer.Layer<never, any, any>>(
serve: Serve,
options: IpcServerOptions
): Layer.Layer<
Layer.Success<Serve>,
Layer.Error<Serve>,
Layer.Services<Serve>
>
<Serves extends ServerServeList>(
serves: Serves,
options: IpcServerOptions
): Layer.Layer<
Layer.Success<Serves[number]>,
Layer.Error<Serves[number]>,
Layer.Services<Serves[number]>
>A Unix-domain RPC server — same-machine sibling of httpServer / wsServer.
Speaks Effect's raw socket RPC protocol (RpcServer.layerProtocolSocketServer) over a
filesystem path — no HTTP, no WebSocket upgrade. Clients connect with connectIpc
or a node whose ProtocolKind is "IpcSocket" (Tag()("x", { path })).
class Worker extends Tag<Worker>()("worker", { path: "/tmp/worker.sock" }) {}
const live = Hyperlink.ipcServer(
[Hyperlink.serve(Jobs, jobsImpl)],
{ path: "/tmp/worker.sock" },
)
// or Node.unix(Worker, [Hyperlink.serve(Jobs, jobsImpl)])Auto-mounts NodeStatus like the http/ws servers. There is no /health HTTP route
(no HTTP listener) — probe readiness via NodeStatus over RPC.
export function function ipcServer<Serve extends Layer.Layer<never, any, any>>(serve: Serve, options: IpcServerOptions): Layer.Layer<Layer.Success<Serve>, Layer.Error<Serve>, Layer.Services<Serve>> (+1 overload)A Unix-domain RPC server — same-machine sibling of
httpServer
/
wsServer
.
Speaks Effect's raw socket RPC protocol (RpcServer.layerProtocolSocketServer) over a
filesystem path — no HTTP, no WebSocket upgrade. Clients connect with
connectIpc
or a node whose
ProtocolKind
is "IpcSocket" (Tag()("x", { path })).
class Worker extends Tag<Worker>()("worker", { path: "/tmp/worker.sock" }) {}
const live = Hyperlink.ipcServer(
[Hyperlink.serve(Jobs, jobsImpl)],
{ path: "/tmp/worker.sock" },
)
// or Node.unix(Worker, [Hyperlink.serve(Jobs, jobsImpl)])
Auto-mounts
NodeStatus
like the http/ws servers. There is no /health HTTP route
(no HTTP listener) — probe readiness via NodeStatus over RPC.
ipcServer<function (type parameter) Serve in ipcServer<Serve extends Layer.Layer<never, any, any>>(serve: Serve, options: IpcServerOptions): Layer.Layer<Layer.Success<Serve>, Layer.Error<Serve>, Layer.Services<Serve>>Serve extends 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<never, any, any>>(
serve: Serve extends Layer.Layer<never, any, any>serve: function (type parameter) Serve in ipcServer<Serve extends Layer.Layer<never, any, any>>(serve: Serve, options: IpcServerOptions): Layer.Layer<Layer.Success<Serve>, Layer.Error<Serve>, Layer.Services<Serve>>Serve,
options: IpcServerOptions(parameter) options: {
path: string;
serialization: Layer.Layer<RpcSerialization.RpcSerialization>;
node: string | { readonly key: string };
unlink: boolean;
advertiseNode: AnyNode & { readonly key: string };
onConflict: OnConflict;
}
options: IpcServerOptions,
): 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 LayerLayer.type Success<T extends Layer.Any> =
T extends Layer.Layer<
infer _ROut,
infer _E,
infer _RIn
>
? _ROut
: never
Extracts the service output type (ROut) from a Layer type.
When to use
Use to derive the services provided by an existing or generic Layer without
restating its ROut type parameter.
Success<function (type parameter) Serve in ipcServer<Serve extends Layer.Layer<never, any, any>>(serve: Serve, options: IpcServerOptions): Layer.Layer<Layer.Success<Serve>, Layer.Error<Serve>, Layer.Services<Serve>>Serve>,
import LayerLayer.type Error<T extends Layer.Any> =
T extends Layer.Layer<
infer _ROut,
infer _E,
infer _RIn
>
? _E
: never
Extracts the error type (E) from a Layer type.
When to use
Use to derive a layer construction error type for helper types, wrappers, or
APIs that preserve a layer failure channel.
Error<function (type parameter) Serve in ipcServer<Serve extends Layer.Layer<never, any, any>>(serve: Serve, options: IpcServerOptions): Layer.Layer<Layer.Success<Serve>, Layer.Error<Serve>, Layer.Services<Serve>>Serve>,
import LayerLayer.type Services<T extends Layer.Any> =
T extends infer L
? L extends Layer.Layer<
infer _ROut,
infer _E,
infer _RIn
>
? _RIn
: never
: never
Extracts the service requirements (RIn) from a Layer type.
When to use
Use to derive the dependency requirements of a generic or inferred Layer
without restating its RIn type parameter.
Services<function (type parameter) Serve in ipcServer<Serve extends Layer.Layer<never, any, any>>(serve: Serve, options: IpcServerOptions): Layer.Layer<Layer.Success<Serve>, Layer.Error<Serve>, Layer.Services<Serve>>Serve>
>;
export function function ipcServer<Serves extends ServerServeList>(serves: Serves, options: IpcServerOptions): Layer.Layer<Layer.Success<Serves[number]>, Layer.Error<Serves[number]>, Layer.Services<Serves[number]>> (+1 overload)A Unix-domain RPC server — same-machine sibling of
httpServer
/
wsServer
.
Speaks Effect's raw socket RPC protocol (RpcServer.layerProtocolSocketServer) over a
filesystem path — no HTTP, no WebSocket upgrade. Clients connect with
connectIpc
or a node whose
ProtocolKind
is "IpcSocket" (Tag()("x", { path })).
class Worker extends Tag<Worker>()("worker", { path: "/tmp/worker.sock" }) {}
const live = Hyperlink.ipcServer(
[Hyperlink.serve(Jobs, jobsImpl)],
{ path: "/tmp/worker.sock" },
)
// or Node.unix(Worker, [Hyperlink.serve(Jobs, jobsImpl)])
Auto-mounts
NodeStatus
like the http/ws servers. There is no /health HTTP route
(no HTTP listener) — probe readiness via NodeStatus over RPC.
ipcServer<function (type parameter) Serves in ipcServer<Serves extends ServerServeList>(serves: Serves, options: IpcServerOptions): Layer.Layer<Layer.Success<Serves[number]>, Layer.Error<Serves[number]>, Layer.Services<Serves[number]>>Serves extends import ServerServeListServerServeList>(
serves: Serves extends ServerServeListserves: function (type parameter) Serves in ipcServer<Serves extends ServerServeList>(serves: Serves, options: IpcServerOptions): Layer.Layer<Layer.Success<Serves[number]>, Layer.Error<Serves[number]>, Layer.Services<Serves[number]>>Serves,
options: IpcServerOptions(parameter) options: {
path: string;
serialization: Layer.Layer<RpcSerialization.RpcSerialization>;
node: string | { readonly key: string };
unlink: boolean;
advertiseNode: AnyNode & { readonly key: string };
onConflict: OnConflict;
}
options: IpcServerOptions,
): 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 LayerLayer.type Success<T extends Layer.Any> =
T extends Layer.Layer<
infer _ROut,
infer _E,
infer _RIn
>
? _ROut
: never
Extracts the service output type (ROut) from a Layer type.
When to use
Use to derive the services provided by an existing or generic Layer without
restating its ROut type parameter.
Success<function (type parameter) Serves in ipcServer<Serves extends ServerServeList>(serves: Serves, options: IpcServerOptions): Layer.Layer<Layer.Success<Serves[number]>, Layer.Error<Serves[number]>, Layer.Services<Serves[number]>>Serves[number]>,
import LayerLayer.type Error<T extends Layer.Any> =
T extends Layer.Layer<
infer _ROut,
infer _E,
infer _RIn
>
? _E
: never
Extracts the error type (E) from a Layer type.
When to use
Use to derive a layer construction error type for helper types, wrappers, or
APIs that preserve a layer failure channel.
Error<function (type parameter) Serves in ipcServer<Serves extends ServerServeList>(serves: Serves, options: IpcServerOptions): Layer.Layer<Layer.Success<Serves[number]>, Layer.Error<Serves[number]>, Layer.Services<Serves[number]>>Serves[number]>,
import LayerLayer.type Services<T extends Layer.Any> =
T extends infer L
? L extends Layer.Layer<
infer _ROut,
infer _E,
infer _RIn
>
? _RIn
: never
: never
Extracts the service requirements (RIn) from a Layer type.
When to use
Use to derive the dependency requirements of a generic or inferred Layer
without restating its RIn type parameter.
Services<function (type parameter) Serves in ipcServer<Serves extends ServerServeList>(serves: Serves, options: IpcServerOptions): Layer.Layer<Layer.Success<Serves[number]>, Layer.Error<Serves[number]>, Layer.Services<Serves[number]>>Serves[number]>
>;
export function function ipcServer<Serve extends Layer.Layer<never, any, any>>(serve: Serve, options: IpcServerOptions): Layer.Layer<Layer.Success<Serve>, Layer.Error<Serve>, Layer.Services<Serve>> (+1 overload)A Unix-domain RPC server — same-machine sibling of
httpServer
/
wsServer
.
Speaks Effect's raw socket RPC protocol (RpcServer.layerProtocolSocketServer) over a
filesystem path — no HTTP, no WebSocket upgrade. Clients connect with
connectIpc
or a node whose
ProtocolKind
is "IpcSocket" (Tag()("x", { path })).
class Worker extends Tag<Worker>()("worker", { path: "/tmp/worker.sock" }) {}
const live = Hyperlink.ipcServer(
[Hyperlink.serve(Jobs, jobsImpl)],
{ path: "/tmp/worker.sock" },
)
// or Node.unix(Worker, [Hyperlink.serve(Jobs, jobsImpl)])
Auto-mounts
NodeStatus
like the http/ws servers. There is no /health HTTP route
(no HTTP listener) — probe readiness via NodeStatus over RPC.
ipcServer(
serves: anyserves: 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<never, any, any> | import ServerServeListServerServeList | interface ReadonlyArray<T>ReadonlyArray<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<never, any, any>>,
options: IpcServerOptions(parameter) options: {
path: string;
serialization: Layer.Layer<RpcSerialization.RpcSerialization>;
node: string | { readonly key: string };
unlink: boolean;
advertiseNode: AnyNode & { readonly key: string };
onConflict: OnConflict;
}
options: IpcServerOptions,
): 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<never, any, any> {
const const list: ServerServeListlist = (
var Array: ArrayConstructorArray.ArrayConstructor.isArray(arg: any): arg is any[]isArray(serves: anyserves) ? serves: any[]serves : [serves: anyserves]
) as unknown as import ServerServeListServerServeList;
return const ipcServerBase: (
options: IpcServerOptions
) => Layer.Layer<
never,
never,
Hyperlink.ServedHyperlinks
>
Registry → one RpcServer over a Unix-domain
SocketServer
.
ipcServerBase(options: IpcServerOptions(parameter) options: {
path: string;
serialization: Layer.Layer<RpcSerialization.RpcSerialization>;
node: string | { readonly key: string };
unlink: boolean;
advertiseNode: AnyNode & { readonly key: string };
onConflict: OnConflict;
}
options).Pipeable.pipe<Layer.Layer<never, never, Hyperlink.ServedHyperlinks>, Layer.Layer<any, any, any>, Layer.Layer<any, unknown, any>>(this: Layer.Layer<never, never, Hyperlink.ServedHyperlinks>, ab: (_: Layer.Layer<never, never, Hyperlink.ServedHyperlinks>) => Layer.Layer<any, any, any>, bc: (_: Layer.Layer<any, any, any>) => Layer.Layer<any, unknown, any>): Layer.Layer<any, unknown, any> (+21 overloads)pipe(
import LayerLayer.const provideMerge: <any>(that: any) => <A, E, R>(self: Layer.Layer<A, E, R>) => Layer.Layer<any, any, any> (+3 overloads)Feeds the output services of the dependency layer into the requirements of
this layer, returning a layer that provides both sets of services.
When to use
Use when you need to compose Layers while keeping both the constructed
service and the dependency used to build it available.
Details
Prefer
provide
when the dependency should stay private.
Example (Providing dependencies while retaining services)
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") {}
class UserService extends Context.Service<UserService, {
readonly getUser: (id: string) => Effect.Effect<{
id: string
name: string
}>
}>()("UserService") {}
// Create dependency layers
const databaseLayer = Layer.succeed(Database, {
query: Effect.fn("Database.query")((sql: string) => Effect.succeed(`DB: ${sql}`))
})
const loggerLayer = Layer.succeed(Logger, {
log: Effect.fn("Logger.log")((msg: string) => Effect.sync(() => console.log(`[LOG] ${msg}`)))
})
// UserService depends on Database and Logger
const userServiceLayer = Layer.effect(UserService, Effect.gen(function*() {
const database = yield* Database
const logger = yield* Logger
return {
getUser: Effect.fn("UserService.getUser")(function*(id: string) {
yield* logger.log(`Looking up user ${id}`)
const result = yield* database.query(
`SELECT * FROM users WHERE id = ${id}`
)
return { id, name: result }
})
}
}))
// Provide dependencies and merge all services together
const allServicesLayer = userServiceLayer.pipe(
Layer.provideMerge(Layer.mergeAll(databaseLayer, loggerLayer))
)
// Now the resulting layer provides UserService, Database, AND Logger
const program = Effect.gen(function*() {
const userService = yield* UserService
const logger = yield* Logger // Still available!
const database = yield* Database // Still available!
const user = yield* userService.getUser("123")
yield* logger.log(`Found user: ${user.name}`)
return user
}).pipe(
Effect.provide(allServicesLayer)
)
provideMerge(import mergeServeListmergeServeList(const list: ServerServeListlist)),
// Fresh registry per server — Lookup + Worker in one process must not share.
import LayerLayer.const provide: <any, unknown, unknown>(that: Layer.Layer<unknown, unknown, any>) => <RIn2, E2, ROut2>(self: Layer.Layer<ROut2, E2, RIn2>) => Layer.Layer<ROut2, unknown, any> (+3 overloads)Feeds the output services of the dependency layer into the requirements of
this layer, returning a layer that only provides the services from this layer.
When to use
Use when you need to hide an implementation dependency layer from callers.
Details
In serviceLayer.pipe(Layer.provide(dependencyLayer)), the dependency layer is
built first and is used to satisfy the requirements of serviceLayer.
Example (Providing layer dependencies)
import { Context, Effect, Layer } from "effect"
class Database extends Context.Service<Database, {
readonly query: (sql: string) => Effect.Effect<string>
}>()("Database") {}
class UserService extends Context.Service<UserService, {
readonly getUser: (id: string) => Effect.Effect<{
id: string
name: string
}>
}>()("UserService") {}
class Logger extends Context.Service<Logger, {
readonly log: (msg: string) => Effect.Effect<void>
}>()("Logger") {}
// Create dependency layers
const databaseLayer = Layer.succeed(Database, {
query: Effect.fn("Database.query")((sql: string) => Effect.succeed(`DB: ${sql}`))
})
const loggerLayer = Layer.succeed(Logger, {
log: Effect.fn("Logger.log")((msg: string) => Effect.sync(() => console.log(`[LOG] ${msg}`)))
})
// UserService depends on Database and Logger
const userServiceLayer = Layer.effect(UserService, Effect.gen(function*() {
const database = yield* Database
const logger = yield* Logger
return {
getUser: Effect.fn("UserService.getUser")(function*(id: string) {
yield* logger.log(`Looking up user ${id}`)
const result = yield* database.query(
`SELECT * FROM users WHERE id = ${id}`
)
return { id, name: result }
})
}
}))
// Provide dependencies to UserService layer
const userServiceWithDependencies = userServiceLayer.pipe(
Layer.provide(Layer.mergeAll(databaseLayer, loggerLayer))
)
// Now UserService layer has no dependencies
const program = Effect.gen(function*() {
const userService = yield* UserService
return yield* userService.getUser("123")
}).pipe(
Effect.provide(userServiceWithDependencies)
)
provide(import LayerLayer.const fresh: <unknown, unknown, any>(
self: Layer.Layer<unknown, unknown, any>
) => Layer.Layer<unknown, unknown, any>
Creates a fresh version of this layer that will not be shared.
When to use
Use when you need two parts of an application to receive separate instances
of a resource, such as two independent client sessions.
Gotchas
Do not use it just to work around confusing composition. By default, sharing
the same layer value is usually the desired behavior.
Example (Creating non-shared layer instances)
import { Context, Effect, Layer, Ref } from "effect"
class Counter extends Context.Service<Counter, {
readonly id: number
}>()("Counter") {}
class Left extends Context.Service<Left, {
readonly counterId: number
}>()("Left") {}
class Right extends Context.Service<Right, {
readonly counterId: number
}>()("Right") {}
const leftLayer = Layer.effect(Left, Effect.gen(function*() {
const counter = yield* Counter
return { counterId: counter.id }
}))
const rightLayer = Layer.effect(Right, Effect.gen(function*() {
const counter = yield* Counter
return { counterId: counter.id }
}))
const showIds = Effect.gen(function*() {
const left = yield* Left
const right = yield* Right
console.log(`same Counter: ${left.counterId === right.counterId}`)
})
const program = Effect.gen(function*() {
const nextId = yield* Ref.make(0)
const counterLayer = Layer.effect(Counter, Effect.gen(function*() {
const id = yield* Ref.updateAndGet(nextId, (n) => n + 1)
console.log("constructed Counter")
return { id }
}))
const shared = Layer.merge(
Layer.provide(leftLayer, counterLayer),
Layer.provide(rightLayer, counterLayer)
)
yield* Effect.provide(showIds, shared)
const freshCounterLayer = Layer.fresh(counterLayer)
const fresh = Layer.merge(
Layer.provide(leftLayer, freshCounterLayer),
Layer.provide(rightLayer, freshCounterLayer)
)
yield* Effect.provide(showIds, fresh)
})
Effect.runPromise(program)
// constructed Counter
// same Counter: true
// constructed Counter
// constructed Counter
// same Counter: false
fresh(import HyperlinkHyperlink.servedHyperlinksLayer)),
) as 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<never, any, any>;
}