/** * Hooks that fix two gaps in the generated request pipeline without editing * generated files: * * 1. Timeouts and signals compose (#1123). The generated `_createRequest` * skips `timeoutMs` whenever the caller passes `signal`. This hook restores * the timeout on the hook context so `_do` combines it with the signal and * the request aborts on whichever fires first. The timeout covers the whole * attempt, including reading a streamed response body, the same as for * calls made without a signal. * * 2. Aborts survive garbage collection in Node (#1315). The generated * `HTTPClient` calls `fetch(request)` with only a `Request`. In undici, a * `Request`'s signal follows its source signal through a weak reference, so * after a GC an abort can stop reaching the network * (https://github.com/nodejs/undici/issues/4068). Passing the caller's * signal again in the `fetch` init avoids this. The hook links each * outgoing `Request` to a signal built directly from the caller's signal * and the per-attempt timeout, and a wrapped fetcher passes it as `init`. * This part only runs on Node: other runtimes don't have the bug, and Bun * mishandles a `Request` combined with an `init` argument. */ import type { SDKOptions } from "../lib/config.js"; import type { RequestInput } from "../lib/http.js"; import type { BeforeCreateRequestContext, BeforeCreateRequestHook, BeforeRequestContext, BeforeRequestHook, SDKInitHook } from "./types.js"; /** True on Node.js, false on Bun, Deno, browsers and other runtimes. */ export declare function isNodeRuntime(): boolean; export type SignalTimeoutHookOptions = { /** * Whether to apply the abort-after-GC fix (#1315). Defaults to true on * Node.js only. */ fixAbortAfterGC?: boolean; }; export declare class SignalTimeoutHook implements SDKInitHook, BeforeCreateRequestHook, BeforeRequestHook { #private; constructor(options?: SignalTimeoutHookOptions); sdkInit(opts: SDKOptions): SDKOptions; beforeCreateRequest(hookCtx: BeforeCreateRequestContext, input: RequestInput): RequestInput; beforeRequest(hookCtx: BeforeRequestContext, request: Request): Request; } //# sourceMappingURL=signal-hooks.d.ts.map