Hyperlinkv0.8.0-beta.28

Lookup

Lookup.directoryAdvertiseLayerconstsrc/Lookup.ts:763
(
  node: AnyNode & { readonly key: string },
  serves: ReadonlyArray<string>,
  options?: { readonly onConflict?: OnConflict }
): Layer.Layer<never, IncumbentAlive>

Soft directory advertise for Node.unix / Node.http / Node.ws: when Directory is in the environment, register node with the given serves keys and unregister on scope close. No-op when Directory is absent (local-only listen).

serves is derived from the protocol-listen serve list (group ids) after registration. Duplicate nodeKey with a live incumbent fails the layer with IncumbentAlive.

options.onConflict is the call-site preference; combined with the node's stamp before the wire request (may still be "inherit" for the Lookup server to finish).

layers & servingNode.unixNode.httpNode.wsDirectoryunregisterIncumbentAlive
Source src/Lookup.ts:76348 lines
export const directoryAdvertiseLayer = (
  node: AnyNode & { readonly key: string },
  serves: ReadonlyArray<string>,
  options?: { readonly onConflict?: OnConflict },
): Layer.Layer<never, IncumbentAlive> =>
  Layer.effectDiscard(
    Effect.gen(function* () {
      const dirOpt = yield* Effect.serviceOption(Directory);
      if (Option.isNone(dirOpt)) {
        return;
      }
      const kind = node.kind;
      if (kind === undefined) {
        return;
      }
      // Advertiser side: call-site → node stamp; leave `"inherit"` so Lookup finishes.
      const callSite = options?.onConflict;
      const nodeStamp = onConflictOf(node);
      const wireOnConflict: OnConflict =
        callSite !== undefined && callSite !== "inherit"
          ? callSite
          : nodeStamp !== undefined && nodeStamp !== "inherit"
            ? nodeStamp
            : "inherit";
      yield* dirOpt.value.advertise(
        new AdvertiseRequest({
          nodeKey: node.key,
          kind,
          serves: [...serves],
          onConflict: wireOnConflict,
          ...(typeof node.path === "string" ? { path: node.path } : {}),
          ...(typeof node.url === "string" ? { url: node.url } : {}),
        }),
      );
      yield* Effect.addFinalizer(() =>
        dirOpt.value
          .unregister(
            new UnregisterRequest({
              nodeKey: node.key,
              kind,
              ...(typeof node.path === "string" ? { path: node.path } : {}),
              ...(typeof node.url === "string" ? { url: node.url } : {}),
            }),
          )
          .pipe(Effect.ignore),
      );
    }),
  );