(url: string): <Self>(node: NodeKey<Self>) => Layer.Layer<Self>
<Self>(
node: NodeKey<Self> & {
readonly url?: string
readonly endpoints?: Endpoints
}
): Layer.Layer<Self>Wire a node over a WebSocket — Effect's layerProtocolSocket transport (WS in the
browser), connect pinned to kind: "WebSocket". Dual: MyNode.pipe(Hyperlink.connectSocket)
uses the node's own url (or "/rpc"); MyNode.pipe(Hyperlink.connectSocket(url)) overrides it.
export const const connectSocket: {
(url: string): <Self>(
node: NodeKey<Self>
) => Layer.Layer<Self>
<Self>(
node: NodeKey<Self> & {
readonly url?: string
readonly endpoints?: Endpoints
}
): Layer.Layer<Self>
}
Wire a node over a WebSocket — Effect's layerProtocolSocket transport (WS in the
browser),
connect
pinned to kind: "WebSocket". Dual: MyNode.pipe(Hyperlink.connectSocket)
uses the node's own url (or "/rpc"); MyNode.pipe(Hyperlink.connectSocket(url)) overrides it.
connectSocket: {
// data-last first, node form last — see connectHttp.
(url: stringurl: string): <function (type parameter) Self in <Self>(node: NodeKey<Self>): Layer.Layer<Self>Self>(node: NodeKey<Self>(parameter) node: {
key: string;
Service: {
protocol: Context.Service.Shape<typeof RpcClient.Protocol>;
ping: Effect.Effect<number, NodeUnreachable>;
status: { readonly get: Effect.Effect<NodeStatusSnapshot, NodeUnreachable>; readonly changes: Stream.Stream<NodeStatusSnapshot, NodeUnreachable> };
logs: { readonly stream: Stream.Stream<LogEntry, NodeUnreachable>; readonly query: (options: { readonly limit: number }) => Effect.Effect<ReadonlyArray<LogEntry>, NodeUnreachable> };
};
Identifier: Identifier;
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;
}
node: type NodeKey<HSelf> = Context.Key<HSelf, NodeProtocol>The Context key of a
Node
(HSelf = its identity): a service whose value is the
transport
NodeProtocol
. Stored on a node-bearing tag under
nodeSym
; read by
Hyperlink.client
to resolve where to connect (its requirement channel).
NodeKey<function (type parameter) Self in <Self>(node: NodeKey<Self>): Layer.Layer<Self>Self>) => 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>): Layer.Layer<Self>Self>;
<function (type parameter) Self in <Self>(node: NodeKey<Self> & {
readonly url?: string;
readonly endpoints?: Endpoints;
}): Layer.Layer<Self>
Self>(
node: NodeKey<Self> & {
readonly url?: string
readonly endpoints?: Endpoints
}
node: type NodeKey<HSelf> = Context.Key<HSelf, NodeProtocol>The Context key of a
Node
(HSelf = its identity): a service whose value is the
transport
NodeProtocol
. Stored on a node-bearing tag under
nodeSym
; read by
Hyperlink.client
to resolve where to connect (its requirement channel).
NodeKey<function (type parameter) Self in <Self>(node: NodeKey<Self> & {
readonly url?: string;
readonly endpoints?: Endpoints;
}): Layer.Layer<Self>
Self> & { readonly url?: string | undefinedurl?: string; readonly endpoints?: Endpoints | undefinedendpoints?: Endpoints },
): 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;
}): Layer.Layer<Self>
Self>;
} = import FnFn.const dual: <(...args: Array<any>) => any, (node: NodeKey<unknown> & {
readonly url?: string;
readonly endpoints?: Endpoints;
}, url?: string) => Layer.Layer<unknown>>(isDataFirst: (args: IArguments) => boolean, body: (node: NodeKey<unknown> & {
readonly url?: string;
readonly endpoints?: Endpoints;
}, url?: string) => Layer.Layer<unknown>) => ((...args: Array<any>) => any) & ((node: NodeKey<unknown> & {
readonly url?: string;
readonly endpoints?: Endpoints;
}, url?: string) => Layer.Layer<unknown>) (+1 overload)
Creates a function that can be called in data-first style or data-last
(pipe-friendly) style.
When to use
Use to expose one implementation through both direct and pipe-friendly
call styles.
Details
Pass either the arity of the uncurried function or a predicate that decides
whether the current call is data-first. Arity is the common case. Use a
predicate when optional arguments make arity ambiguous.
Example (Selecting data-first or data-last style by arity)
import { Function, pipe } from "effect"
const sum = Function.dual<
(that: number) => (self: number) => number,
(self: number, that: number) => number
>(2, (self, that) => self + that)
console.log(sum(2, 3)) // 5
console.log(pipe(2, sum(3))) // 5
Example (Defining overloads with call signatures)
import { Function, pipe } from "effect"
const sum: {
(that: number): (self: number) => number
(self: number, that: number): number
} = Function.dual(2, (self: number, that: number): number => self + that)
console.log(sum(2, 3)) // 5
console.log(pipe(2, sum(3))) // 5
Example (Selecting data-first or data-last style with a predicate)
import { Function, pipe } from "effect"
const sum = Function.dual<
(that: number) => (self: number) => number,
(self: number, that: number) => number
>(
(args) => args.length === 2,
(self, that) => self + that
)
console.log(sum(2, 3)) // 5
console.log(pipe(2, sum(3))) // 5
dual(
(args: IArgumentsargs: IArguments) => typeof args: IArgumentsargs[0] !== "string",
(
node: NodeKey<unknown> & {
readonly url?: string
readonly endpoints?: Endpoints
}
node: type NodeKey<HSelf> = Context.Key<HSelf, NodeProtocol>The Context key of a
Node
(HSelf = its identity): a service whose value is the
transport
NodeProtocol
. Stored on a node-bearing tag under
nodeSym
; read by
Hyperlink.client
to resolve where to connect (its requirement channel).
NodeKey<unknown> & { readonly url?: string | undefinedurl?: string; readonly endpoints?: Endpoints | undefinedendpoints?: Endpoints },
url: string | undefinedurl?: string,
// Prefer the node's OWN WebSocket endpoint over the primary `url`: on a multi-protocol `{ http, ws }`
// node the primary is the Http url, so `node.url` would dial ws against the http endpoint (footgun).
// Fall back to `node.url` (scheme-swapped) for a single-transport / co-mounted node.
): 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<unknown> =>
connectLayer<Self, E, RIn>(node: NodeKey<Self>, protocol: Layer.Layer<RpcClient.Protocol, E, RIn>): Layer.Layer<Self, E, RIn>Provide a node handle for node over protocol — its { protocol } plus lazy status accessors.
connectLayer(
node: NodeKey<unknown> & {
readonly url?: string
readonly endpoints?: Endpoints
}
node,
import HyperlinkHyperlink.const protocolWebsocket: (
target?: number | string,
serialization?: Layer.Layer<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(url: string | undefinedurl ?? node: NodeKey<unknown> & {
readonly url?: string
readonly endpoints?: Endpoints
}
node.endpoints?: Endpoints | undefinedendpoints?.Endpoints.WebSocket?: {
readonly url: string;
} | undefined
WebSocket?.url: string | undefinedurl ?? node: NodeKey<unknown> & {
readonly url?: string
readonly endpoints?: Endpoints
}
node.url?: string | undefinedurl ?? "/rpc"),
),
);