<Self, S extends Spec>(
tag: HyperlinkTag<Self, S>,
target:
| number
| `:${number}`
| `http://${string}`
| `https://${string}`,
options?: {
readonly serialization?: Layer.Layer<RpcSerialization.RpcSerialization>
}
): Layer.Layer<Self>
<Self, S extends Spec>(
tag: HyperlinkTag<Self, S>,
target: number | string,
options?: {
readonly serialization?: Layer.Layer<RpcSerialization.RpcSerialization>
}
): Layer.Layer<Self, InvalidHttpTarget>The single-resource client mirror of httpServer. Wire a served resource tag to a remote
over http and get a ready client Layer in one call — client(tag) plus the
batteries-included transport (Fetch + ndjson serialization), bundled.
The target is a port (3009 or ":3009" → http://localhost:3009/rpc) for a runtime on the
same machine, or a full url for one across the network. A bad target fails the Layer with
InvalidHttpTarget (not a sync throw):
Effect.provide(program, Hyperlink.clientHttp(Emails, 3001)); // same machine
Effect.provide(program, Hyperlink.clientHttp(Emails, "https://mail.internal/rpc")); // anywhereexport function function clientHttp<Self, S extends Spec>(tag: HyperlinkTag<Self, S>, target: number | `:${number}` | `http://${string}` | `https://${string}`, options?: {
readonly serialization?: Layer.Layer<RpcSerialization.RpcSerialization>;
}): Layer.Layer<Self> (+1 overload)
The single-resource client mirror of
httpServer
. Wire a served resource tag to a remote
over http and get a ready client Layer in one call —
client
(tag) plus the
batteries-included transport (Fetch + ndjson serialization), bundled.
The target is a port (3009 or ":3009" → http://localhost:3009/rpc) for a runtime on the
same machine, or a full url for one across the network. A bad target fails the Layer with
InvalidHttpTarget
(not a sync throw):
Effect.provide(program, Hyperlink.clientHttp(Emails, 3001)); // same machine
Effect.provide(program, Hyperlink.clientHttp(Emails, "https://mail.internal/rpc")); // anywhere
clientHttp<function (type parameter) Self in clientHttp<Self, S extends Spec>(tag: HyperlinkTag<Self, S>, target: number | `:${number}` | `http://${string}` | `https://${string}`, options?: {
readonly serialization?: Layer.Layer<RpcSerialization.RpcSerialization>;
}): Layer.Layer<Self>
Self, function (type parameter) S in clientHttp<Self, S extends Spec>(tag: HyperlinkTag<Self, S>, target: number | `:${number}` | `http://${string}` | `https://${string}`, options?: {
readonly serialization?: Layer.Layer<RpcSerialization.RpcSerialization>;
}): Layer.Layer<Self>
S extends Spec>(
tag: HyperlinkTag<Self, S>(parameter) tag: {
groupId: string;
description: string | undefined;
key: Identifier;
of: (this: void, self: Simplify<{ readonly [K in keyof S]: S[K] extends FromLocalMethod<infer M> ? InjectLocal<M, Self> : S[K] extends LocalMethod<infer T> ? LocalEffect<T, never, Self> : S[K] extends { readonly _tag: 'constant'; } ? SuccessOf…;
context: (self: Simplify<{ readonly [K in keyof S]: S[K] extends FromLocalMethod<infer M> ? InjectLocal<M, Self> : S[K] extends LocalMethod<infer T> ? LocalEffect<T, never, Self> : S[K] extends { readonly _tag: 'constant'; } ? SuccessOf<AsMethod<S[…;
use: (f: (service: Simplify<{ readonly [K in keyof S]: S[K] extends FromLocalMethod<infer M> ? InjectLocal<M, Self> : S[K] extends LocalMethod<infer T> ? LocalEffect<T, never, Self> : S[K] extends { readonly _tag: 'constant'; } ? SuccessOf<AsMe…;
useSync: (f: (service: Simplify<{ readonly [K in keyof S]: S[K] extends FromLocalMethod<infer M> ? InjectLocal<M, Self> : S[K] extends LocalMethod<infer T> ? LocalEffect<T, never, Self> : S[K] extends { readonly _tag: 'constant'; } ? SuccessOf<AsMe…;
Identifier: Identifier;
Service: Shape;
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;
}
tag: interface HyperlinkTag<Self, S extends Spec, Svc = Simplify<{ readonly [K in keyof S]: S[K] extends FromLocalMethod<infer M> ? InjectLocal<M, Self> : S[K] extends LocalMethod<infer T> ? LocalEffect<...> : S[K] extends { ...; } ? SuccessOf<...> : S[K] extends { ...; } ? Subscribable<...> : S[K] extends { ...; } ? ClientMethod<...> : S[K] extends Spec ? Simplify<...> : never; }>>The type of a resource tag carrying spec S — what
Hyperlink.Tag
/ a
Hyperlink.tagFor
factory produce (and what you extend). Lets a consumer write
<S extends Spec>(tag: HyperlinkTag<Self, S>) and read the spec through named types
(
specOf
/
groupOf
) instead of a Parameters<typeof specOf> workaround.
HyperlinkTag<function (type parameter) Self in clientHttp<Self, S extends Spec>(tag: HyperlinkTag<Self, S>, target: number | `:${number}` | `http://${string}` | `https://${string}`, options?: {
readonly serialization?: Layer.Layer<RpcSerialization.RpcSerialization>;
}): Layer.Layer<Self>
Self, function (type parameter) S in clientHttp<Self, S extends Spec>(tag: HyperlinkTag<Self, S>, target: number | `:${number}` | `http://${string}` | `https://${string}`, options?: {
readonly serialization?: Layer.Layer<RpcSerialization.RpcSerialization>;
}): Layer.Layer<Self>
S>,
target: | number
| `:${number}`
| `http://${string}`
| `https://${string}`
target: number | `:${number}` | `http://${string}` | `https://${string}`,
options: | {
readonly serialization?: Layer.Layer<RpcSerialization.RpcSerialization>
}
| undefined
options?: {
readonly serialization?: | Layer.Layer<
RpcSerialization.RpcSerialization,
never,
never
>
| undefined
serialization?: 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 RpcSerializationRpcSerialization.class RpcSerializationclass RpcSerialization {
key: Identifier;
Service: {
makeUnsafe: () => RpcSerialization.Parser;
contentType: string;
includesFraming: boolean;
};
}
Service that describes how RPC protocol messages are encoded and decoded,
including the content type and whether the serialization format provides
message framing.
When to use
Use to provide the serialization boundary shared by RPC clients and servers
for a chosen wire format.
RpcSerialization>;
},
): 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<function (type parameter) Self in clientHttp<Self, S extends Spec>(tag: HyperlinkTag<Self, S>, target: number | `:${number}` | `http://${string}` | `https://${string}`, options?: {
readonly serialization?: Layer.Layer<RpcSerialization.RpcSerialization>;
}): Layer.Layer<Self>
Self>;
export function function clientHttp<Self, S extends Spec>(tag: HyperlinkTag<Self, S>, target: number | string, options?: {
readonly serialization?: Layer.Layer<RpcSerialization.RpcSerialization>;
}): Layer.Layer<Self, InvalidHttpTarget> (+1 overload)
The single-resource client mirror of
httpServer
. Wire a served resource tag to a remote
over http and get a ready client Layer in one call —
client
(tag) plus the
batteries-included transport (Fetch + ndjson serialization), bundled.
The target is a port (3009 or ":3009" → http://localhost:3009/rpc) for a runtime on the
same machine, or a full url for one across the network. A bad target fails the Layer with
InvalidHttpTarget
(not a sync throw):
Effect.provide(program, Hyperlink.clientHttp(Emails, 3001)); // same machine
Effect.provide(program, Hyperlink.clientHttp(Emails, "https://mail.internal/rpc")); // anywhere
clientHttp<function (type parameter) Self in clientHttp<Self, S extends Spec>(tag: HyperlinkTag<Self, S>, target: number | string, options?: {
readonly serialization?: Layer.Layer<RpcSerialization.RpcSerialization>;
}): Layer.Layer<Self, InvalidHttpTarget>
Self, function (type parameter) S in clientHttp<Self, S extends Spec>(tag: HyperlinkTag<Self, S>, target: number | string, options?: {
readonly serialization?: Layer.Layer<RpcSerialization.RpcSerialization>;
}): Layer.Layer<Self, InvalidHttpTarget>
S extends Spec>(
tag: HyperlinkTag<Self, S>(parameter) tag: {
groupId: string;
description: string | undefined;
key: Identifier;
of: (this: void, self: Simplify<{ readonly [K in keyof S]: S[K] extends FromLocalMethod<infer M> ? InjectLocal<M, Self> : S[K] extends LocalMethod<infer T> ? LocalEffect<T, never, Self> : S[K] extends { readonly _tag: 'constant'; } ? SuccessOf…;
context: (self: Simplify<{ readonly [K in keyof S]: S[K] extends FromLocalMethod<infer M> ? InjectLocal<M, Self> : S[K] extends LocalMethod<infer T> ? LocalEffect<T, never, Self> : S[K] extends { readonly _tag: 'constant'; } ? SuccessOf<AsMethod<S[…;
use: (f: (service: Simplify<{ readonly [K in keyof S]: S[K] extends FromLocalMethod<infer M> ? InjectLocal<M, Self> : S[K] extends LocalMethod<infer T> ? LocalEffect<T, never, Self> : S[K] extends { readonly _tag: 'constant'; } ? SuccessOf<AsMe…;
useSync: (f: (service: Simplify<{ readonly [K in keyof S]: S[K] extends FromLocalMethod<infer M> ? InjectLocal<M, Self> : S[K] extends LocalMethod<infer T> ? LocalEffect<T, never, Self> : S[K] extends { readonly _tag: 'constant'; } ? SuccessOf<AsMe…;
Identifier: Identifier;
Service: Shape;
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;
}
tag: interface HyperlinkTag<Self, S extends Spec, Svc = Simplify<{ readonly [K in keyof S]: S[K] extends FromLocalMethod<infer M> ? InjectLocal<M, Self> : S[K] extends LocalMethod<infer T> ? LocalEffect<...> : S[K] extends { ...; } ? SuccessOf<...> : S[K] extends { ...; } ? Subscribable<...> : S[K] extends { ...; } ? ClientMethod<...> : S[K] extends Spec ? Simplify<...> : never; }>>The type of a resource tag carrying spec S — what
Hyperlink.Tag
/ a
Hyperlink.tagFor
factory produce (and what you extend). Lets a consumer write
<S extends Spec>(tag: HyperlinkTag<Self, S>) and read the spec through named types
(
specOf
/
groupOf
) instead of a Parameters<typeof specOf> workaround.
HyperlinkTag<function (type parameter) Self in clientHttp<Self, S extends Spec>(tag: HyperlinkTag<Self, S>, target: number | string, options?: {
readonly serialization?: Layer.Layer<RpcSerialization.RpcSerialization>;
}): Layer.Layer<Self, InvalidHttpTarget>
Self, function (type parameter) S in clientHttp<Self, S extends Spec>(tag: HyperlinkTag<Self, S>, target: number | string, options?: {
readonly serialization?: Layer.Layer<RpcSerialization.RpcSerialization>;
}): Layer.Layer<Self, InvalidHttpTarget>
S>,
target: string | numbertarget: number | string,
options: | {
readonly serialization?: Layer.Layer<RpcSerialization.RpcSerialization>
}
| undefined
options?: {
readonly serialization?: | Layer.Layer<
RpcSerialization.RpcSerialization,
never,
never
>
| undefined
serialization?: 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 RpcSerializationRpcSerialization.class RpcSerializationclass RpcSerialization {
key: Identifier;
Service: {
makeUnsafe: () => RpcSerialization.Parser;
contentType: string;
includesFraming: boolean;
};
}
Service that describes how RPC protocol messages are encoded and decoded,
including the content type and whether the serialization format provides
message framing.
When to use
Use to provide the serialization boundary shared by RPC clients and servers
for a chosen wire format.
RpcSerialization>;
},
): 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<function (type parameter) Self in clientHttp<Self, S extends Spec>(tag: HyperlinkTag<Self, S>, target: number | string, options?: {
readonly serialization?: Layer.Layer<RpcSerialization.RpcSerialization>;
}): Layer.Layer<Self, InvalidHttpTarget>
Self, import InvalidHttpTargetInvalidHttpTarget>;
export function function clientHttp<Self, S extends Spec>(tag: HyperlinkTag<Self, S>, target: number | `:${number}` | `http://${string}` | `https://${string}`, options?: {
readonly serialization?: Layer.Layer<RpcSerialization.RpcSerialization>;
}): Layer.Layer<Self> (+1 overload)
The single-resource client mirror of
httpServer
. Wire a served resource tag to a remote
over http and get a ready client Layer in one call —
client
(tag) plus the
batteries-included transport (Fetch + ndjson serialization), bundled.
The target is a port (3009 or ":3009" → http://localhost:3009/rpc) for a runtime on the
same machine, or a full url for one across the network. A bad target fails the Layer with
InvalidHttpTarget
(not a sync throw):
Effect.provide(program, Hyperlink.clientHttp(Emails, 3001)); // same machine
Effect.provide(program, Hyperlink.clientHttp(Emails, "https://mail.internal/rpc")); // anywhere
clientHttp<function (type parameter) Self in clientHttp<Self, S extends Spec>(tag: HyperlinkTag<Self, S>, target: number | string, options?: {
readonly serialization?: Layer.Layer<RpcSerialization.RpcSerialization>;
}): Layer.Layer<Self, InvalidHttpTarget | ClientVerifyError>
Self, function (type parameter) S in clientHttp<Self, S extends Spec>(tag: HyperlinkTag<Self, S>, target: number | string, options?: {
readonly serialization?: Layer.Layer<RpcSerialization.RpcSerialization>;
}): Layer.Layer<Self, InvalidHttpTarget | ClientVerifyError>
S extends Spec>(
tag: HyperlinkTag<Self, S>(parameter) tag: {
groupId: string;
description: string | undefined;
key: Identifier;
of: (this: void, self: Simplify<{ readonly [K in keyof S]: S[K] extends FromLocalMethod<infer M> ? InjectLocal<M, Self> : S[K] extends LocalMethod<infer T> ? LocalEffect<T, never, Self> : S[K] extends { readonly _tag: 'constant'; } ? SuccessOf…;
context: (self: Simplify<{ readonly [K in keyof S]: S[K] extends FromLocalMethod<infer M> ? InjectLocal<M, Self> : S[K] extends LocalMethod<infer T> ? LocalEffect<T, never, Self> : S[K] extends { readonly _tag: 'constant'; } ? SuccessOf<AsMethod<S[…;
use: (f: (service: Simplify<{ readonly [K in keyof S]: S[K] extends FromLocalMethod<infer M> ? InjectLocal<M, Self> : S[K] extends LocalMethod<infer T> ? LocalEffect<T, never, Self> : S[K] extends { readonly _tag: 'constant'; } ? SuccessOf<AsMe…;
useSync: (f: (service: Simplify<{ readonly [K in keyof S]: S[K] extends FromLocalMethod<infer M> ? InjectLocal<M, Self> : S[K] extends LocalMethod<infer T> ? LocalEffect<T, never, Self> : S[K] extends { readonly _tag: 'constant'; } ? SuccessOf<AsMe…;
Identifier: Identifier;
Service: Shape;
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;
}
tag: interface HyperlinkTag<Self, S extends Spec, Svc = Simplify<{ readonly [K in keyof S]: S[K] extends FromLocalMethod<infer M> ? InjectLocal<M, Self> : S[K] extends LocalMethod<infer T> ? LocalEffect<...> : S[K] extends { ...; } ? SuccessOf<...> : S[K] extends { ...; } ? Subscribable<...> : S[K] extends { ...; } ? ClientMethod<...> : S[K] extends Spec ? Simplify<...> : never; }>>The type of a resource tag carrying spec S — what
Hyperlink.Tag
/ a
Hyperlink.tagFor
factory produce (and what you extend). Lets a consumer write
<S extends Spec>(tag: HyperlinkTag<Self, S>) and read the spec through named types
(
specOf
/
groupOf
) instead of a Parameters<typeof specOf> workaround.
HyperlinkTag<function (type parameter) Self in clientHttp<Self, S extends Spec>(tag: HyperlinkTag<Self, S>, target: number | string, options?: {
readonly serialization?: Layer.Layer<RpcSerialization.RpcSerialization>;
}): Layer.Layer<Self, InvalidHttpTarget | ClientVerifyError>
Self, function (type parameter) S in clientHttp<Self, S extends Spec>(tag: HyperlinkTag<Self, S>, target: number | string, options?: {
readonly serialization?: Layer.Layer<RpcSerialization.RpcSerialization>;
}): Layer.Layer<Self, InvalidHttpTarget | ClientVerifyError>
S>,
target: string | numbertarget: number | string,
options: | {
readonly serialization?: Layer.Layer<RpcSerialization.RpcSerialization>
}
| undefined
options?: {
readonly serialization?: | Layer.Layer<
RpcSerialization.RpcSerialization,
never,
never
>
| undefined
serialization?: 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 RpcSerializationRpcSerialization.class RpcSerializationclass RpcSerialization {
key: Identifier;
Service: {
makeUnsafe: () => RpcSerialization.Parser;
contentType: string;
includesFraming: boolean;
};
}
Service that describes how RPC protocol messages are encoded and decoded,
including the content type and whether the serialization format provides
message framing.
When to use
Use to provide the serialization boundary shared by RPC clients and servers
for a chosen wire format.
RpcSerialization>;
},
): 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<function (type parameter) Self in clientHttp<Self, S extends Spec>(tag: HyperlinkTag<Self, S>, target: number | string, options?: {
readonly serialization?: Layer.Layer<RpcSerialization.RpcSerialization>;
}): Layer.Layer<Self, InvalidHttpTarget | ClientVerifyError>
Self, import InvalidHttpTargetInvalidHttpTarget | type ClientVerifyError = anyErrors default-on / deep client verify may surface on addressed client Layers.
ClientVerifyError> {
const const resolved: anyresolved = import resolveHttpTargetresolveHttpTarget(target: string | numbertarget);
if (import ResultResult.const isFailure: <unknown, unknown>(
self: Result.Result<unknown, unknown>
) => self is Result.Failure<unknown, unknown>
Checks whether a Result is a Failure.
When to use
Use to narrow a known Result to the Failure variant.
Details
- Acts as a TypeScript type guard, narrowing to
Failure<A, E>
- After narrowing, you can access
.failure to read the error value
Example (Narrowing to failure)
import { Result } from "effect"
const result = Result.fail("oops")
if (Result.isFailure(result)) {
console.log(result.failure)
// Output: "oops"
}
isFailure(const resolved: anyresolved)) {
return import invalidHttpTargetLayerinvalidHttpTargetLayer(const resolved: Result.Failure<
unknown,
unknown
>
const resolved: {
_tag: "Failure";
_op: "Failure";
failure: E;
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;
}
resolved.Failure<unknown, unknown>.failure: unknownfailure);
}
const const url: anyurl = const resolved: anyresolved.success;
const const wired: Layer.Layer<Self, any, never>const wired: {
build: (memoMap: Layer.MemoMap, scope: Scope.Scope) => Effect.Effect<Context.Context<Self>, any, 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; <…;
}
wired = function clientLayer<Self, S, unknown>(tag: NodeBoundTag<Self, S, unknown, Simplify<{ readonly [K in keyof S]: S[K] extends FromLocalMethod<infer M> ? InjectLocal<M, Self> : S[K] extends LocalMethod<infer T> ? LocalEffect<T, never, Self> : S[K] extends {
readonly _tag: "constant";
} ? SuccessOf<AsMethod<S[K]>> : S[K] extends {
readonly _tag: "ref";
} ? Subscribable<SuccessOf<AsMethod<S[K]>>> : S[K] extends {
...;
} ? ClientMethod<...> : S[K] extends Spec ? Simplify<...> : never; }>> & {
...;
}): Layer.Layer<...> (+4 overloads)
The client layer for a resource: drive it over RPC as if it were local — the exact
same yield* Tag code as the local layer, only the provided layer differs, so it doesn't
matter where the resource actually runs.
Paths, by whether — and where — the tag names a
Node
:
- **node-bearing +
AddressedNode
** —
client(Hosted) when the tag's { node } is
dialable: auto-wires connect (R = never). Bare bound nodes still require the node service.
- **nodeless tag +
AddressedNode
** —
client(tag, Worker) same auto-connect gate.
- bare node —
client(tag, Bare) / bare-bound client(Hosted) still require the node;
provide
Node.connect
(Bare, protocol) (or lookup / discoverClient) yourself.
- nodeless tag, ambient transport — ambient
RpcClient.Protocol.
clientLayer(tag: HyperlinkTag<Self, S>(parameter) tag: {
groupId: string;
description: string | undefined;
key: Identifier;
of: (this: void, self: Simplify<{ readonly [K in keyof S]: S[K] extends FromLocalMethod<infer M> ? InjectLocal<M, Self> : S[K] extends LocalMethod<infer T> ? LocalEffect<T, never, Self> : S[K] extends { readonly _tag: 'constant'; } ? SuccessOf…;
context: (self: Simplify<{ readonly [K in keyof S]: S[K] extends FromLocalMethod<infer M> ? InjectLocal<M, Self> : S[K] extends LocalMethod<infer T> ? LocalEffect<T, never, Self> : S[K] extends { readonly _tag: 'constant'; } ? SuccessOf<AsMethod<S[…;
use: (f: (service: Simplify<{ readonly [K in keyof S]: S[K] extends FromLocalMethod<infer M> ? InjectLocal<M, Self> : S[K] extends LocalMethod<infer T> ? LocalEffect<T, never, Self> : S[K] extends { readonly _tag: 'constant'; } ? SuccessOf<AsMe…;
useSync: (f: (service: Simplify<{ readonly [K in keyof S]: S[K] extends FromLocalMethod<infer M> ? InjectLocal<M, Self> : S[K] extends LocalMethod<infer T> ? LocalEffect<T, never, Self> : S[K] extends { readonly _tag: 'constant'; } ? SuccessOf<AsMe…;
Identifier: Identifier;
Service: Shape;
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;
}
tag).Pipeable.pipe<Layer.Layer<Self, any, never>, Layer.Layer<Self, any, never>>(this: Layer.Layer<Self, any, never>, ab: (_: Layer.Layer<Self, any, never>) => Layer.Layer<Self, any, never>): Layer.Layer<Self, any, never> (+21 overloads)pipe(
import LayerLayer.const provide: <never, never, RpcClient.Protocol>(that: Layer.Layer<RpcClient.Protocol, never, never>) => <RIn2, E2, ROut2>(self: Layer.Layer<ROut2, E2, RIn2>) => Layer.Layer<ROut2, E2, Exclude<RIn2, RpcClient.Protocol>> (+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(const protocolHttp: (
target?: number | string,
serialization?: Layer.Layer<RpcSerialization.RpcSerialization>
) => Layer.Layer<RpcClient.Protocol>
Build an http client Protocol (Fetch + ndjson serialization) for an endpoint — the value you
hand
layerProtocol
or
connect
. target is a port (3009 → http://${clientHost}:3009/rpc,
Config host default "localhost"), a full url, or a same-origin path (default "/rpc"). The
server/CLI transport; a browser should prefer
protocolWebsocket
(HTTP/1.1's ~6-connection cap
starves streams — protocolHttp dies loudly in a browser).
protocolHttp(const url: anyurl, options: | {
readonly serialization?: Layer.Layer<RpcSerialization.RpcSerialization>
}
| undefined
options?.serialization?: | Layer.Layer<
RpcSerialization.RpcSerialization,
never,
never
>
| undefined
serialization)),
);
// Nodeless clientHttp — deep F3/F4 probe on the resolved URL (default-on verify).
return import LayerLayer.const unwrap: <
Self,
any,
never,
any,
never
>(
self: Effect.Effect<
Layer.Layer<Self, any, never>,
any,
never
>
) => Layer.Layer<Self, any, never>
Unwraps a Layer from an Effect, flattening the nested structure.
When to use
Use when you have an Effect that produces a Layer and you want to
use that layer directly.
Details
The resulting Layer will have the combined error and dependency types from
both the outer Effect and the inner Layer.
Example (Unwrapping an effectful layer)
import { Context, Effect, Layer } from "effect"
class Database extends Context.Service<Database, {
readonly query: (sql: string) => Effect.Effect<string>
}>()("Database") {}
const layerEffect = Effect.succeed(
Layer.succeed(Database, { query: Effect.fn("Database.query")((sql: string) => Effect.succeed("result")) })
)
const unwrappedLayer = Layer.unwrap(layerEffect)
unwrap(
import EffectEffect.const gen: <Effect.Effect<void, any, never>, Layer.Layer<Self, any, never>>(f: () => Generator<Effect.Effect<void, any, never>, Layer.Layer<Self, any, never>, never>) => Effect.Effect<Layer.Layer<Self, any, never>, any, never> (+1 overload)Provides a way to write effectful code using generator functions, simplifying
control flow and error handling.
When to use
Use when you want to write effectful code that looks and behaves like
synchronous code, while still handling asynchronous tasks, errors, and complex
control flow such as loops and conditions.
Generator functions work similarly to async/await but keep errors,
requirements, and interruption in the Effect type. You can yield* values
from effects and return the final result at the end.
Example (Sequencing effects with generators)
import { Data, Effect } from "effect"
class DiscountRateError extends Data.TaggedError("DiscountRateError")<{}> {}
const addServiceCharge = (amount: number) => amount + 1
const applyDiscount = (
total: number,
discountRate: number
): Effect.Effect<number, DiscountRateError> =>
discountRate === 0
? Effect.fail(new DiscountRateError())
: Effect.succeed(total - (total * discountRate) / 100)
const fetchTransactionAmount = Effect.promise(() => Promise.resolve(100))
const fetchDiscountRate = Effect.promise(() => Promise.resolve(5))
export const program = Effect.gen(function*() {
const transactionAmount = yield* fetchTransactionAmount
const discountRate = yield* fetchDiscountRate
const discountedAmount = yield* applyDiscount(
transactionAmount,
discountRate
)
const finalAmount = addServiceCharge(discountedAmount)
return `Final amount to charge: ${finalAmount}`
})
gen(function* () {
yield* const applyClientVerify: (
node: AnyNode,
options?: ClientVerifyProbeOptions
) => Effect.Effect<void, ClientVerifyError>
Default-on client verify (§8.6) — "reject" unless
ClientVerify
overrides.
When resource + contractHash are set (tag-aware clients), escalates to deep F3/F4.
applyClientVerify(
{ key: stringkey: tag: HyperlinkTag<Self, S>(parameter) tag: {
groupId: string;
description: string | undefined;
key: Identifier;
of: (this: void, self: Simplify<{ readonly [K in keyof S]: S[K] extends FromLocalMethod<infer M> ? InjectLocal<M, Self> : S[K] extends LocalMethod<infer T> ? LocalEffect<T, never, Self> : S[K] extends { readonly _tag: 'constant'; } ? SuccessOf…;
context: (self: Simplify<{ readonly [K in keyof S]: S[K] extends FromLocalMethod<infer M> ? InjectLocal<M, Self> : S[K] extends LocalMethod<infer T> ? LocalEffect<T, never, Self> : S[K] extends { readonly _tag: 'constant'; } ? SuccessOf<AsMethod<S[…;
use: (f: (service: Simplify<{ readonly [K in keyof S]: S[K] extends FromLocalMethod<infer M> ? InjectLocal<M, Self> : S[K] extends LocalMethod<infer T> ? LocalEffect<T, never, Self> : S[K] extends { readonly _tag: 'constant'; } ? SuccessOf<AsMe…;
useSync: (f: (service: Simplify<{ readonly [K in keyof S]: S[K] extends FromLocalMethod<infer M> ? InjectLocal<M, Self> : S[K] extends LocalMethod<infer T> ? LocalEffect<T, never, Self> : S[K] extends { readonly _tag: 'constant'; } ? SuccessOf<AsMe…;
Identifier: Identifier;
Service: Shape;
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;
}
tag.ServiceClass<Self, string, Simplify<{ readonly [K in keyof S]: S[K] extends FromLocalMethod<infer M> ? InjectLocal<M, Self> : S[K] extends LocalMethod<...> ? LocalEffect<...> : S[K] extends { ...; } ? SuccessOf<...> : S[K] extends { ...; } ? Subscribable<...> : S[K] extends { ...; } ? ClientMethod<...> : S[K] extends Spec ? Simplify<...> : never; }>>.key: stringkey } as import AnyNodeAnyNode,
{
url?: string | undefinedurl,
resource?: string | undefinedresource: tag: HyperlinkTag<Self, S>(parameter) tag: {
groupId: string;
description: string | undefined;
key: Identifier;
of: (this: void, self: Simplify<{ readonly [K in keyof S]: S[K] extends FromLocalMethod<infer M> ? InjectLocal<M, Self> : S[K] extends LocalMethod<infer T> ? LocalEffect<T, never, Self> : S[K] extends { readonly _tag: 'constant'; } ? SuccessOf…;
context: (self: Simplify<{ readonly [K in keyof S]: S[K] extends FromLocalMethod<infer M> ? InjectLocal<M, Self> : S[K] extends LocalMethod<infer T> ? LocalEffect<T, never, Self> : S[K] extends { readonly _tag: 'constant'; } ? SuccessOf<AsMethod<S[…;
use: (f: (service: Simplify<{ readonly [K in keyof S]: S[K] extends FromLocalMethod<infer M> ? InjectLocal<M, Self> : S[K] extends LocalMethod<infer T> ? LocalEffect<T, never, Self> : S[K] extends { readonly _tag: 'constant'; } ? SuccessOf<AsMe…;
useSync: (f: (service: Simplify<{ readonly [K in keyof S]: S[K] extends FromLocalMethod<infer M> ? InjectLocal<M, Self> : S[K] extends LocalMethod<infer T> ? LocalEffect<T, never, Self> : S[K] extends { readonly _tag: 'constant'; } ? SuccessOf<AsMe…;
Identifier: Identifier;
Service: Shape;
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;
}
tag.HyperlinkTag<Self, S, Simplify<{ readonly [K in keyof S]: S[K] extends FromLocalMethod<infer M> ? InjectLocal<M, Self> : S[K] extends LocalMethod<...> ? LocalEffect<...> : S[K] extends { ...; } ? SuccessOf<...> : S[K] extends { ...; } ? Subscribable<...> : S[K] extends { ...; } ? ClientMethod<...> : S[K] extends Spec ? Simplify<...> : never; }>>.groupId: stringWire prefix — namespaces this resource's procedures on a shared RpcServer.
groupId,
contractHash?: string | undefinedcontractHash: const contractHash: <
Self,
S extends Spec
>(
tag: HyperlinkTag<Self, S>
) => string
F4 wire-contract fingerprint for a resource tag — same value the server stamps on
NodeStatus.resources[].contractHash at serve. Compare via
verifyConnection
({ deep: true, resource, contractHash }).
contractHash(tag: HyperlinkTag<Self, S>(parameter) tag: {
groupId: string;
description: string | undefined;
key: Identifier;
of: (this: void, self: Simplify<{ readonly [K in keyof S]: S[K] extends FromLocalMethod<infer M> ? InjectLocal<M, Self> : S[K] extends LocalMethod<infer T> ? LocalEffect<T, never, Self> : S[K] extends { readonly _tag: 'constant'; } ? SuccessOf…;
context: (self: Simplify<{ readonly [K in keyof S]: S[K] extends FromLocalMethod<infer M> ? InjectLocal<M, Self> : S[K] extends LocalMethod<infer T> ? LocalEffect<T, never, Self> : S[K] extends { readonly _tag: 'constant'; } ? SuccessOf<AsMethod<S[…;
use: (f: (service: Simplify<{ readonly [K in keyof S]: S[K] extends FromLocalMethod<infer M> ? InjectLocal<M, Self> : S[K] extends LocalMethod<infer T> ? LocalEffect<T, never, Self> : S[K] extends { readonly _tag: 'constant'; } ? SuccessOf<AsMe…;
useSync: (f: (service: Simplify<{ readonly [K in keyof S]: S[K] extends FromLocalMethod<infer M> ? InjectLocal<M, Self> : S[K] extends LocalMethod<infer T> ? LocalEffect<T, never, Self> : S[K] extends { readonly _tag: 'constant'; } ? SuccessOf<AsMe…;
Identifier: Identifier;
Service: Shape;
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;
}
tag),
},
);
return const wired: Layer.Layer<Self, any, never>const wired: {
build: (memoMap: Layer.MemoMap, scope: Scope.Scope) => Effect.Effect<Context.Context<Self>, any, 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; <…;
}
wired;
}),
) 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<function (type parameter) Self in clientHttp<Self, S extends Spec>(tag: HyperlinkTag<Self, S>, target: number | string, options?: {
readonly serialization?: Layer.Layer<RpcSerialization.RpcSerialization>;
}): Layer.Layer<Self, InvalidHttpTarget | ClientVerifyError>
Self, import InvalidHttpTargetInvalidHttpTarget | type ClientVerifyError = anyErrors default-on / deep client verify may surface on addressed client Layers.
ClientVerifyError>;
}