/** * Window-scaling utilities for converting between observation windows and * receiver reset windows. * * The rate receiver resets its per-pattern counters every * RECEIVER_DEFAULT_RESET_MS (4 minutes by default). Cap CSV rows are * denominated in bytes-per-reset-window. Any code path that converts a * Prometheus query window (e.g. "24h") or a monthly projection to a per-cap * value must go through these helpers so the denominator is explicit and * testable. * * Pure functions; no side effects; no env reads. */ /** Default rate-receiver reset interval in milliseconds (4 minutes). */ export declare const RECEIVER_DEFAULT_RESET_MS = 240000; /** * Parse a free-form window string into milliseconds. * * Accepted formats: `\d+[mhd]` * - `5m` → 300_000 * - `1h` → 3_600_000 * - `24h` → 86_400_000 * - `7d` → 604_800_000 * * Throws TypeError for any other input (e.g. '5sec', '1', 'tomorrow'). */ export declare function parseWindowMs(window: string): number; /** * Scale a byte count from one time window to another by linear proportion. * * Returns `bytesInWindow * (toWindowMs / fromWindowMs)`. * Returns 0 if bytesInWindow is 0 (avoids NaN propagation). * Does not round — caller rounds before writing to CSV. * * Throws RangeError if either window is non-positive. */ export declare function scaleBytes(bytesInWindow: number, fromWindowMs: number, toWindowMs: number): number; /** * Convert an observed byte count and a reduction percentage to the * post-reduction target byte count. * * `percentReduction` is clamped to [0, 100]. * Returns `observedBytes * (1 - percentReduction / 100)`. * Returns 0 when percentReduction is 100; returns observedBytes when 0. */ export declare function percentToTargetBytes(observedBytes: number, percentReduction: number): number; /** * Canonical helper: convert a byte count observed over `observedWindow` * (e.g. from a Prometheus `increase()` query) into bytes-per-receiver-reset- * window. * * This is the function configure_engine should call when computing a cap CSV * row from Prometheus data. * * @param observedBytes Byte count from the observation window. * @param observedWindow Window string matching the Prometheus query range, * e.g. "24h", "7d". * @param receiverResetMs Reset interval of the rate receiver in ms. Defaults * to RECEIVER_DEFAULT_RESET_MS (4 minutes). */ export declare function scaleObservedToReceiverWindow(observedBytes: number, observedWindow: string, receiverResetMs?: number): number; /** * Convert a millisecond duration back to a human-readable window string. * Used for log lines and error messages. * * 240_000 → '4m' * 3_600_000 → '1h' * 86_400_000 → '1d' * * Prefer the largest exact unit. Falls back to minutes (floored) for * durations that don't align to a round number of hours or days. */ export declare function readableWindow(ms: number): string;