<Self>(
node: NodeKey<Self> & {
readonly url?: string
readonly endpoints?: Endpoints
},
options?: {
readonly url?: string
readonly serialization?: Layer.Layer<RpcSerialization.RpcSerialization>
}
): Layer.Layer<Self, NodeUnreachable | UnaddressedNode>Wire a Node's transport over a WebSocket — the browser counterpart to
http. Every stream (each resource's status + metrics + logs) rides one
multiplexed connection, so a dashboard never trips the browser's ~6-connection-per-origin
HTTP/1.1 limit that starves streams over http (in a browser http now
fails hard — see its note). The server must be a wsServer.
The url may be a same-origin path ("/rpc" — resolved against the page location, so the
browser follows its own host + scheme, http→ws / https→wss), an http(s):// url (scheme
swapped), or an absolute ws(s):// url. Resolution is lazy, so this is safe to call at module
scope in a file a Node server also imports. Uses the browser's global WebSocket.
const EdgeLive = Hyperlink.ws(EdgeNode, { url: "/rpc" }); // same origin as the pageconst const ws: <Self>(
node: NodeKey<Self> & {
readonly url?: string
readonly endpoints?: Endpoints
},
options?: {
readonly url?: string
readonly serialization?: Layer.Layer<RpcSerialization.RpcSerialization>
}
) => Layer.Layer<
Self,
NodeUnreachable | UnaddressedNode
>
Wire a
Node
's transport over a WebSocket — the browser counterpart to
http
. Every stream (each resource's status + metrics + logs) rides one
multiplexed connection, so a dashboard never trips the browser's ~6-connection-per-origin
HTTP/1.1 limit that starves streams over
http
(in a browser
http
now
fails hard — see its note). The server must be a
wsServer
.
The url may be a same-origin path ("/rpc" — resolved against the page location, so the
browser follows its own host + scheme, http→ws / https→wss), an http(s):// url (scheme
swapped), or an absolute ws(s):// url. Resolution is lazy, so this is safe to call at module
scope in a file a Node server also imports. Uses the browser's global WebSocket.
const EdgeLive = Hyperlink.ws(EdgeNode, { url: "/rpc" }); // same origin as the page
ws = <function (type parameter) Self in <Self>(node: NodeKey<Self> & {
readonly url?: string;
readonly endpoints?: Endpoints;
}, options?: {
readonly url?: string;
readonly serialization?: Layer.Layer<RpcSerialization.RpcSerialization>;
}): Layer.Layer<Self, NodeUnreachable | UnaddressedNode>
Self>(
node: anynode: import NodeKeyNodeKey<function (type parameter) Self in <Self>(node: NodeKey<Self> & {
readonly url?: string;
readonly endpoints?: Endpoints;
}, options?: {
readonly url?: string;
readonly serialization?: Layer.Layer<RpcSerialization.RpcSerialization>;
}): Layer.Layer<Self, NodeUnreachable | UnaddressedNode>
Self> & { readonly url?: string | undefinedurl?: string; readonly endpoints?: anyendpoints?: import EndpointsEndpoints },
options: | {
readonly url?: string
readonly serialization?: Layer.Layer<RpcSerialization.RpcSerialization>
}
| undefined
options?: {
readonly url?: string | undefinedurl?: string;
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 <Self>(node: NodeKey<Self> & {
readonly url?: string;
readonly endpoints?: Endpoints;
}, options?: {
readonly url?: string;
readonly serialization?: Layer.Layer<RpcSerialization.RpcSerialization>;
}): Layer.Layer<Self, NodeUnreachable | UnaddressedNode>
Self, import NodeUnreachableNodeUnreachable | import UnaddressedNodeUnaddressedNode> => {
// The client sibling of {@link Node.ws} = `connect` + {@link protocolWebsocket}. Prefers the node's
// own WebSocket endpoint (multi-protocol — its primary `url` is the Http one on an `{ http, ws }`
// node), then the primary `url`, then `"/rpc"`; `options.url` overrides.
const const url: anyurl =
options: | {
readonly url?: string
readonly serialization?: Layer.Layer<RpcSerialization.RpcSerialization>
}
| undefined
options?.url?: string | undefinedurl ?? node: anynode.endpoints?.WebSocket?.url ?? node: anynode.url ?? "/rpc";
const const wired: anywired = import connectLayerconnectLayer(
node: anynode,
const protocolWebsocket: (
target?: number | string,
serialization?: Layer.Layer<RpcSerialization.RpcSerialization>
) => Layer.Layer<RpcClient.Protocol>
Build a WebSocket client Protocol (one multiplexed connection + ndjson) for one endpoint
url (default "/rpc"). The url may be a same-origin path ("/rpc" — resolved against the
page location, http→ws / https→wss), an http(s):// url (scheme swapped), or an absolute
ws(s):// url; resolution is lazy, so this is safe at module scope in a file a Node server also
imports. The browser transport — every stream rides one connection, past the ~6-connection cap that
starves streams over
protocolHttp
.
protocolWebsocket(const url: anyurl, options: | {
readonly url?: string
readonly serialization?: Layer.Layer<RpcSerialization.RpcSerialization>
}
| undefined
options?.serialization?: | Layer.Layer<
RpcSerialization.RpcSerialization,
never,
never
>
| undefined
serialization),
);
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>, any>(f: () => Generator<Effect.Effect<void, any, never>, any, never>) => Effect.Effect<any, 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(node: anynode as import AnyNodeAnyNode, { url?: string | undefinedurl });
return const wired: anywired;
}),
) 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 <Self>(node: NodeKey<Self> & {
readonly url?: string;
readonly endpoints?: Endpoints;
}, options?: {
readonly url?: string;
readonly serialization?: Layer.Layer<RpcSerialization.RpcSerialization>;
}): Layer.Layer<Self, NodeUnreachable | UnaddressedNode>
Self, import NodeUnreachableNodeUnreachable | import UnaddressedNodeUnaddressedNode>;
};