(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 http — Effect's layerProtocolHttp transport, connect pinned to
kind: "Http". Dual: MyNode.pipe(Hyperlink.connectHttp) uses the node's own url (or "/rpc");
MyNode.pipe(Hyperlink.connectHttp(url)) overrides it.
export const const connectHttp: {
(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 http — Effect's layerProtocolHttp transport,
connect
pinned to
kind: "Http". Dual: MyNode.pipe(Hyperlink.connectHttp) uses the node's own url (or "/rpc");
MyNode.pipe(Hyperlink.connectHttp(url)) overrides it.
connectHttp: {
// data-last first, node form last — so the bare pipe (`node.pipe(connectHttp)`) resolves to the node
// overload (TS picks the last for a bare value); `connectHttp(url)` still matches the string overload.
(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 Http endpoint over the primary `url` — a multi-protocol `{ http, ws }` node
// has a WebSocket primary-or-http primary but its Http endpoint is the right target for `connectHttp`.
): 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 protocolHttp: (
target?: number | string,
serialization?: Layer.Layer<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(url: string | undefinedurl ?? node: NodeKey<unknown> & {
readonly url?: string
readonly endpoints?: Endpoints
}
node.endpoints?: Endpoints | undefinedendpoints?.Endpoints.Http?: {
readonly url: string;
} | undefined
Http?.url: string | undefinedurl ?? node: NodeKey<unknown> & {
readonly url?: string
readonly endpoints?: Endpoints
}
node.url?: string | undefinedurl ?? "/rpc")),
);