Hyperlinkv0.8.0-beta.28

Hyperlink

Hyperlink.identityconstsrc/Hyperlink.ts:4916
<T extends PipeableTag>(tag: T): T & { readonly [identitySym]: true }

Mark a Tag as identity-claiming (S1): layer / serve claim the resource key at Lookup first — winner runs the local impl; loser becomes a client of the winner's endpoint. Requires LookupIdentity in the layer graph (fail-closed if Lookup is down).

Pipe onto any Hyperlink / Process / Queue tag (same shape as withReadiness):

class Mail extends Hyperlink.Tag<Mail>()("app/Mail", spec).pipe(Hyperlink.identity) {}

// bind a Node on the Tag (or listen with ListenNode) — Lookup decides winner/loser:
class Mail extends Hyperlink.Tag<Mail>()("app/Mail", spec, { node: ThisNode }).pipe(
  Hyperlink.identity,
) {}
Hyperlink.serve(Mail, impl).pipe(Layer.provide(Lookup.client(lookupNode)))
Source src/Hyperlink.ts:491615 lines
export const identity = <T extends PipeableTag>(
  tag: T,
): T & { readonly [identitySym]: true } => {
  // S1: refuse identity on a Tag that already carries a multi-node fleet.
  if (
    (typeof tag === "object" || typeof tag === "function") &&
    tag !== null &&
    "key" in tag
  ) {
    const fleet =
      (tag as { readonly [nodesSym]?: ReadonlyArray<AnyNode> })[nodesSym] ?? [];
    assertIdentityNodeCount(tag as { readonly key: string }, fleet);
  }
  return Object.assign(tag, { [identitySym]: true as const });
};