/** * Caps the combined serialized size of `web.fetch` metadata (headers, TLS, * timing, redirect chain, cookies) at {@link METADATA_BUDGET_BYTES} (64 KiB), * trimming in order: trailing cookies, then longest header values (down to * 1024 chars, keys always kept), then trailing redirect hops. Pure function; * bounded iteration count so a pathological input can't loop indefinitely. */ import { type CookieInfo, type HeaderMap, type RedirectChain, type TimingInfo, type TlsInfo, METADATA_BUDGET_BYTES } from "./types.js"; /** * Inputs accepted by {@link enforce}. * * Each field corresponds to one slice of {@link WebFetchMetadata}. * Fields that the caller chose not to include (for example because the * user passed `includeHeaders=false`) may be omitted or set to * `undefined`; they are passed through to the result unchanged. */ export interface BudgetInput { headers?: HeaderMap | undefined; tls?: TlsInfo | undefined; timing?: TimingInfo | undefined; redirectChain?: RedirectChain | undefined; cookies?: CookieInfo[] | undefined; } /** * Result returned by {@link enforce}. Optional fields are present iff * the corresponding input field was present (an empty array is still * "present"). `metadataBytes` is the UTF-8 byte length of * `JSON.stringify({headers, tls, timing, redirectChain, cookies})` after * the truncation loop has finished. `cap` mirrors the constant from * `types.ts` so consumers can render `metadataBytes / cap` without * importing it themselves. */ export interface BudgetResult { headers?: HeaderMap; tls?: TlsInfo; timing?: TimingInfo; redirectChain?: RedirectChain; cookies?: CookieInfo[]; metadataBytes: number; cap: typeof METADATA_BUDGET_BYTES; } /** * Enforce the 64 KiB metadata budget on the supplied fields. * * Returns a fresh {@link BudgetResult} containing (possibly shortened) * copies of `headers`, `redirectChain`, and `cookies`, alongside `tls` * and `timing` passed through unchanged, plus the final * `metadataBytes` count. * * The returned arrays/maps are independent of the caller's inputs — the * function does not mutate `input`. */ export declare function enforce(input: BudgetInput): BudgetResult;