<S extends Spec, R>(
tag: {
readonly [wireKeySym]: string
readonly [specSym]: FlatSpec
readonly [specTypeSym]?: S
readonly [groupSym]: ServeRemoteTag[typeof groupSym]
},
driver: Driver<S, R>
): Layer.Layer<HandlerContextOf<S>, never, R>Served-only mount for a Driver — preserves the driver's requirement R on the Layer.
Separate from serveRemote so plain-impl ServeRequirements inference stays sharp and
open-S Driver overloads don't hit TS2589. Used by Gate / Daemon / WorkPool / serve.
Success channel is HandlerContextOf<S> when S is concrete on the tag; callers that
already name handler slots on their public return can treat this as the R-preserving mount.
export const const serveRemoteDriver: <
S extends Spec,
R
>(
tag: {
readonly [wireKeySym]: string
readonly [specSym]: FlatSpec
readonly [specTypeSym]?: S
readonly [groupSym]: ServeRemoteTag[typeof groupSym]
},
driver: Driver<S, R>
) => Layer.Layer<HandlerContextOf<S>, never, R>
Served-only mount for a
Driver
— preserves the driver's requirement R on the Layer.
Separate from
serveRemote
so plain-impl ServeRequirements inference stays sharp and
open-S Driver overloads don't hit TS2589. Used by Gate / Daemon / WorkPool /
serve
.
Success channel is
HandlerContextOf
<S> when S is concrete on the tag; callers that
already name handler slots on their public return can treat this as the R-preserving mount.
serveRemoteDriver = <function (type parameter) S in <S extends Spec, R>(tag: {
readonly [wireKeySym]: string;
readonly [specSym]: FlatSpec;
readonly [specTypeSym]?: S;
readonly [groupSym]: ServeRemoteTag[typeof groupSym];
}, driver: Driver<S, R>): Layer.Layer<HandlerContextOf<S>, never, R>
S extends Spec, function (type parameter) R in <S extends Spec, R>(tag: {
readonly [wireKeySym]: string;
readonly [specSym]: FlatSpec;
readonly [specTypeSym]?: S;
readonly [groupSym]: ServeRemoteTag[typeof groupSym];
}, driver: Driver<S, R>): Layer.Layer<HandlerContextOf<S>, never, R>
R>(
tag: {
readonly [wireKeySym]: string
readonly [specSym]: FlatSpec
readonly [specTypeSym]?: S
readonly [groupSym]: ServeRemoteTag[typeof groupSym]
}
tag: {
readonly [const wireKeySym: typeof wireKeySymWhere the wire key (RpcGroup prefix) is stowed on a Tag. Solo
Tag
s use the
same string as
Context.Key.key
; shared-Spec instances use the factory wire key.
Read with
wireKeyOf
.
wireKeySym]: string;
readonly [const specSym: typeof specSymWhere the contract spec is stowed on a Tag (hidden from the value surface). Exported so
the public
HyperlinkTag
type is nameable across modules.
specSym]: type FlatSpec = {
[x: string]:
| AnyMethod
| AnyLocalMethod
| AnyDefaultMethod
}
A flat spec — a path-keyed record of leaves (no nested groups). The wire machinery runs on this;
a (possibly nested)
Spec
flattens to it via
flattenSpec
.
FlatSpec;
readonly [const specTypeSym: typeof specTypeSymPhantom carrier of a tag's (possibly nested) spec type S, so functions can infer S from a tag —
specSym
holds the flat spec at runtime and can't carry the nested S. Type-only, never set at
runtime.
specTypeSym]?: function (type parameter) S in <S extends Spec, R>(tag: {
readonly [wireKeySym]: string;
readonly [specSym]: FlatSpec;
readonly [specTypeSym]?: S;
readonly [groupSym]: ServeRemoteTag[typeof groupSym];
}, driver: Driver<S, R>): Layer.Layer<HandlerContextOf<S>, never, R>
S;
readonly [const groupSym: typeof groupSymWhere the built RPC group is stowed on a Tag.
groupSym]: type ServeRemoteTag = {
readonly key?: string
readonly [wireKeySym]: string
readonly [specSym]: FlatSpec
readonly [groupSym]: {
readonly toLayer: (
handlers: never
) => Layer.Any
}
}
Shallow tag shape for serve-remote mounts — avoids open RpcGroupOf<S> walks (TS2589).
ServeRemoteTag[typeof const groupSym: typeof groupSymWhere the built RPC group is stowed on a Tag.
groupSym];
},
driver: Driver<S, R>(parameter) driver: {
impl: WithRequirement<ImplOf<S>, R>;
workerContext: Context.Context<R>;
}
driver: interface Driver<S extends Spec, R>A HyperService impl before worker-context discharge — the impl still carries requirement R on its
Effect methods, paired with the
Context.Context
captured at build time. Used by
WorkPool
,
Gate
, and
Daemon
(any toolkit HyperService that builds
its driver under ambient R).
layer
/
serve
grant locally via
grantLocal
;
serveRemote
defers discharge to each wire call via
invokeWireMethodWithContext
so
one materialization backs both paths.
Driver<function (type parameter) S in <S extends Spec, R>(tag: {
readonly [wireKeySym]: string;
readonly [specSym]: FlatSpec;
readonly [specTypeSym]?: S;
readonly [groupSym]: ServeRemoteTag[typeof groupSym];
}, driver: Driver<S, R>): Layer.Layer<HandlerContextOf<S>, never, R>
S, function (type parameter) R in <S extends Spec, R>(tag: {
readonly [wireKeySym]: string;
readonly [specSym]: FlatSpec;
readonly [specTypeSym]?: S;
readonly [groupSym]: ServeRemoteTag[typeof groupSym];
}, driver: Driver<S, R>): Layer.Layer<HandlerContextOf<S>, never, R>
R>,
): 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<type HandlerContextOf<S extends Spec> =
RpcUnionOf<S, ""> extends Rpc.Rpc<
infer _Tag extends string,
infer _Payload extends Schema.Top,
infer _Success extends Schema.Top,
infer _Error extends Schema.Top,
infer _Middleware extends AnyService,
infer _Requires
>
? Rpc.Handler<_Tag>
: never
The context a server layer for a
Spec
provides: the handler for every method.
Used to pin the server layers' output type so their requirement channel stays
never — RpcGroup's own ToHandlerFn defaults that channel to any, so without
this the inferred server layer would re-leak any into anything that consumes it.
HandlerContextOf<function (type parameter) S in <S extends Spec, R>(tag: {
readonly [wireKeySym]: string;
readonly [specSym]: FlatSpec;
readonly [specTypeSym]?: S;
readonly [groupSym]: ServeRemoteTag[typeof groupSym];
}, driver: Driver<S, R>): Layer.Layer<HandlerContextOf<S>, never, R>
S>, never, function (type parameter) R in <S extends Spec, R>(tag: {
readonly [wireKeySym]: string;
readonly [specSym]: FlatSpec;
readonly [specTypeSym]?: S;
readonly [groupSym]: ServeRemoteTag[typeof groupSym];
}, driver: Driver<S, R>): Layer.Layer<HandlerContextOf<S>, never, R>
R> =>
const retype: <Layer.Layer<Rpc.ToHandler<RpcUnionOf<S, "">>, never, R>>(value: never) => Layer.Layer<Rpc.ToHandler<RpcUnionOf<S, "">>, never, R>Retype through never (not any/unknown channels) at dynamic Effect/Rpc factories.
Same bridge as internal/nodeServerCommon.retype — kept local so this module does not
import server plumbing.
retype<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<type HandlerContextOf<S extends Spec> =
RpcUnionOf<S, ""> extends Rpc.Rpc<
infer _Tag extends string,
infer _Payload extends Schema.Top,
infer _Success extends Schema.Top,
infer _Error extends Schema.Top,
infer _Middleware extends AnyService,
infer _Requires
>
? Rpc.Handler<_Tag>
: never
The context a server layer for a
Spec
provides: the handler for every method.
Used to pin the server layers' output type so their requirement channel stays
never — RpcGroup's own ToHandlerFn defaults that channel to any, so without
this the inferred server layer would re-leak any into anything that consumes it.
HandlerContextOf<function (type parameter) S in <S extends Spec, R>(tag: {
readonly [wireKeySym]: string;
readonly [specSym]: FlatSpec;
readonly [specTypeSym]?: S;
readonly [groupSym]: ServeRemoteTag[typeof groupSym];
}, driver: Driver<S, R>): Layer.Layer<HandlerContextOf<S>, never, R>
S>, never, function (type parameter) R in <S extends Spec, R>(tag: {
readonly [wireKeySym]: string;
readonly [specSym]: FlatSpec;
readonly [specTypeSym]?: S;
readonly [groupSym]: ServeRemoteTag[typeof groupSym];
}, driver: Driver<S, R>): Layer.Layer<HandlerContextOf<S>, never, R>
R>>(
const serveRemoteHandlers: (
tag: ServeRemoteTag,
wireImpl: unknown,
workerContext:
| Context.Context<unknown>
| undefined
) => Layer.Any
Shared handler mount + registry registration for
serveRemote
/
serveRemoteDriver
.
Returns
Layer.Any
; public wrappers reify R /
HandlerContextOf
.
Shared-Spec tags (
Tag
(wireKey, spec) instances) merge under one RpcGroup: the first
serve mounts handlers; later serves of the same wire key only append instances.
serveRemoteHandlers(tag: {
readonly [wireKeySym]: string
readonly [specSym]: FlatSpec
readonly [specTypeSym]?: S
readonly [groupSym]: ServeRemoteTag[typeof groupSym]
}
tag, driver: Driver<S, R>(parameter) driver: {
impl: WithRequirement<ImplOf<S>, R>;
workerContext: Context.Context<R>;
}
driver.Driver<S, R>.impl: WithRequirement<ImplOf<S>, R>impl, driver: Driver<S, R>(parameter) driver: {
impl: WithRequirement<ImplOf<S>, R>;
workerContext: Context.Context<R>;
}
driver.Driver<S, R>.workerContext: Context.Context<R>(property) Driver<S, R>.workerContext: {
mapUnsafe: ReadonlyMap<string, any>;
mutable: boolean;
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;
}
workerContext as import ContextContext.interface Context<in Services>Immutable collection of service implementations used for dependency
injection in Effect programs.
Details
The type parameter tracks the service identifiers available in the context.
At runtime, services are stored by each key's string key.
Example (Creating a context with multiple services)
import { Context } from "effect"
// Create a context with multiple services
const Logger = Context.Service<{ log: (msg: string) => void }>("Logger")
const Database = Context.Service<{ query: (sql: string) => string }>(
"Database"
)
const context = Context.make(Logger, {
log: (msg: string) => console.log(msg)
})
.pipe(Context.add(Database, { query: (sql) => `Result: ${sql}` }))
Context<unknown>) as never,
);