Hyperlinkv0.8.0-beta.28

Hyperlink

Hyperlink.clientHttpfunctionsrc/Hyperlink.ts:4659
<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")); // anywhere
clientshttpServerclientInvalidHttpTarget
Source src/Hyperlink.ts:465944 lines
export 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>;
export function clientHttp<Self, S extends Spec>(
  tag: HyperlinkTag<Self, S>,
  target: number | string,
  options?: {
    readonly serialization?: Layer.Layer<RpcSerialization.RpcSerialization>;
  },
): Layer.Layer<Self, InvalidHttpTarget>;
export function clientHttp<Self, S extends Spec>(
  tag: HyperlinkTag<Self, S>,
  target: number | string,
  options?: {
    readonly serialization?: Layer.Layer<RpcSerialization.RpcSerialization>;
  },
): Layer.Layer<Self, InvalidHttpTarget | ClientVerifyError> {
  const resolved = resolveHttpTarget(target);
  if (Result.isFailure(resolved)) {
    return invalidHttpTargetLayer(resolved.failure);
  }
  const url = resolved.success;
  const wired = clientLayer(tag).pipe(
    Layer.provide(protocolHttp(url, options?.serialization)),
  );
  // Nodeless clientHttp — deep F3/F4 probe on the resolved URL (default-on verify).
  return Layer.unwrap(
    Effect.gen(function* () {
      yield* applyClientVerify(
        { key: tag.key } as AnyNode,
        {
          url,
          resource: tag.groupId,
          contractHash: contractHash(tag),
        },
      );
      return wired;
    }),
  ) as Layer.Layer<Self, InvalidHttpTarget | ClientVerifyError>;
}