Hyperlinkv0.8.0-beta.28

HttpApiHyperlink

HttpApiHyperlink.instrumentEndpointsconstsrc/HttpApiHyperlink.ts:204
<ApiId extends string, Groups extends HttpApiGroup.Constraint>(
  api: HttpApiType.HttpApi<ApiId, Groups>,
  client: HttpApiClient.Client<Groups>,
  clientId: string
): void

Wrap every endpoint on a built HttpApi client with usage metrics and registry hooks.

combinators
export const instrumentEndpoints = <
  ApiId extends string,
  Groups extends HttpApiGroup.Constraint,
>(
  api: HttpApiType.HttpApi<ApiId, Groups>,
  client: HttpApiClient.Client<Groups>,
  clientId: string,
): void => {
  const metrics = makeEndpointMetrics(clientId);
  HttpApi.reflect(api, {
    onGroup: () => {},
    onEndpoint({ group, endpoint }) {
      const bucket: Record<string, unknown> | undefined = group.topLevel
        ? (client as Record<string, unknown>)
        : (client as Record<string, Record<string, unknown>>)[group.identifier];
      if (bucket === undefined) {
        return;
      }
      const original = bucket[endpoint.identifier];
      if (typeof original !== "function") {
        return;
      }
      bucket[endpoint.identifier] = wrapEndpointCall(
        original as (...args: Array<never>) => Effect.Effect<unknown, unknown, unknown>,
        { client: clientId, group: group.identifier, endpoint: endpoint.identifier },
        metrics,
      );
    },
  });
};