Hyperlinkv0.8.0-beta.28

Hyperlink

Hyperlink.Tagconstsrc/Hyperlink.ts:2937
<Self>(): {
  <const S extends Spec>(
    key: string,
    spec: S,
    options?: { readonly description?: string; readonly kind?: string }
  ): HyperlinkTag<Self, S>
  <const S extends Spec, HSelf>(
    key: string,
    spec: S,
    options: {
      readonly description?: string
      readonly kind?: string
      readonly node: AddressedNode<HSelf>
    }
  ): NodeBoundTag<Self, S, HSelf> & {
    readonly [nodeSym]: AddressedNode<HSelf>
  }
  <const S extends Spec, HSelf>(
    key: string,
    spec: S,
    options: {
      readonly description?: string
      readonly kind?: string
      readonly node: NodeKey<HSelf>
    }
  ): NodeBoundTag<Self, S, HSelf>
}

Create a resource service tag from a Spec. Extend the result, like Context.Tag, but the value type is inferred from the spec:

class Counter extends Hyperlink.Tag<Counter>()("Counter", {
  increment: Hyperlink.effectFn({ by: Schema.Number }),
  current: Hyperlink.effect(Schema.Number),
}) {}

const c = yield* Counter; // { increment: (p) => Effect<void>; current: Effect<number> }

Keys must be unique: a duplicate throws at declaration — Effect's Context is keyed by the key string and silently last-write-wins on collisions, so we guard it. For a single resource the key is also its group id (the wire prefix for its procedures), so a shared RpcServer can node it alongside other resource types.

constructorsSpec
Source src/Hyperlink.ts:293754 lines
const makeTag = <Self>() => {
  // `Context.Service`-shaped: `Tag<Self>()(key, spec, options?)`. The spec (2nd arg) is the
  // inferring call; `options.node` rides the inferring call so its identity `HSelf` infers from the
  // argument, and the node-bearing overload narrows `[nodeSym]` to a concrete `NodeKey` — which is
  // how `Hyperlink.client` discriminates the node-aware path. An {@link AddressedNode} narrows
  // further so `client(Tag)` can auto-wire connect.
  function build<const S extends Spec>(
    key: string,
    spec: S,
    options?: { readonly description?: string; readonly kind?: string },
  ): HyperlinkTag<Self, S>;
  function build<const S extends Spec, HSelf>(
    key: string,
    spec: S,
    options: {
      readonly description?: string;
      readonly kind?: string;
      readonly node: AddressedNode<HSelf>;
    },
  ): NodeBoundTag<Self, S, HSelf> & {
    readonly [nodeSym]: AddressedNode<HSelf>;
  };
  function build<const S extends Spec, HSelf>(
    key: string,
    spec: S,
    options: {
      readonly description?: string;
      readonly kind?: string;
      readonly node: NodeKey<HSelf>;
    },
  ): NodeBoundTag<Self, S, HSelf>;
  function build<const S extends Spec>(
    key: string,
    spec: S,
    options?: {
      readonly description?: string;
      readonly kind?: string;
      readonly node?: NodeKey<unknown>;
    },
  ): HyperlinkTag<Self, S> {
    // single resource: key doubles as the group id (its wire prefix)
    claimGroupId(key);
    return buildInstanceTag<Self, S>(
      key,
      key,
      spec,
      buildRpcGroup(key, flattenSpec(spec)),
      options?.description,
      options?.node,
      options?.kind,
    );
  }
  return build;
};
Referenced by 9 symbols