Hyperlinkv0.9.0-beta.0

Gate

Gate.HttpApiClientconstsrc/internal/httpApiClient.ts:797
<Self>(): <
  ApiId extends string,
  Groups extends HttpApiGroup.Constraint,
  const Name extends string,
  const MK extends string = "metrics"
>(
  key: Name,
  api: HttpApiType.HttpApi<ApiId, Groups>,
  config?: HttpApiClientTagConfig & { readonly metricsKey?: MK }
) => StampedHttpApiClientTag<Self, Groups, MK>

Class factory: Hyperlink Tag for an HttpApi client — no baked .layer. Pair with httpApiClientLayer.

constructorshttpApiClientLayer
export const HttpApiClient = <Self>() =>
  <
    ApiId extends string,
    Groups extends HttpApiGroup.Constraint,
    const Name extends string,
    const MK extends string = "metrics",
  >(
    key: Name,
    api: HttpApiType.HttpApi<ApiId, Groups>,
    config: HttpApiClientTagConfig & { readonly metricsKey?: MK } = {},
  ): StampedHttpApiClientTag<Self, Groups, MK> => {
    const adaptive = normalizeAdaptive(config.adaptive);
    if (adaptive.enabled && config.rateLimit === undefined) {
      throw new AdaptiveRequiresRateLimit({ tagKey: key });
    }
    const metricsKey = (config.metricsKey ?? "metrics") as MK;
    assertNoMetricsKeyCollision(api, metricsKey);
    const spec = buildHttpApiClientSpec(api, metricsKey);
    // Licensed boundary: reflect-built Spec matches Client locals + nest — see
    // test/gate-http-api-client.test-d.ts.
    const tag = Hyperlink.Tag<Self, HttpApiClientShape<Groups, MK>>()(
      key,
      spec as never,
      { kind: httpApiClientKind, description: config.description },
    );
    const stamped = stampGateMetricsMetadata(tag, {
      metricsKey,
      rateLimitKey:
        config.rateLimit === undefined
          ? undefined
          : (config.rateLimit.key ?? key),
    });
    return Object.assign(stamped, {
      [tagConfigSym]: {
        api,
        concurrency: config.concurrency,
        rateLimit: config.rateLimit,
        adaptive,
        metricsKey,
        windowMs: config.windowMs,
      },
    }) as unknown as StampedHttpApiClientTag<Self, Groups, MK>;
  };