import type { Check } from './spec.js'; import type { CheckResult, CheckStatus } from './types.js'; export type { CheckResult, CheckRule, ChecksReport, CheckStatus } from './types.js'; export interface CheckRunnerOptions { checks: Check[]; /** Where checks with a path go, e.g. http://localhost:3000. */ baseUrl: string; fetch?: typeof fetch; /** Wall clock, for `atMs`. */ now?: () => number; /** A clock that never jumps (NTP, sleep), for durations. Default performance.now. */ elapsed?: () => number; /** Results kept per check. Default 50. */ history?: number; /** The first run of every check waits this long (the app may still be starting). Default 3 s. */ firstDelayMs?: number; /** * While the app has not answered yet, a refused connection to it within this time of start() is not a result: * `next dev` is still starting. After it, "nobody is listening" is exactly what a check is for. Default 60 s. */ startupGraceMs?: number; /** A run that met the starting app is tried again this soon, whatever the check's interval. Default 5 s. */ startupRetryMs?: number; onResult?: (check: Check, result: CheckResult, failures: number) => void; } /** Marks the request as the observer's own (the value is the check's name, URL-encoded: header values are ASCII). */ export declare const CHECK_HEADER = "x-observe-check"; /** As much of a body as is read: enough for `bodyIncludes`, and a large download is not buffered every minute. */ export declare const MAX_BODY_BYTES = 1000000; export declare class CheckRunner { private readonly options; readonly baseUrl: string; private readonly checks; private readonly fetch; private readonly now; private readonly elapsed; private readonly keep; private readonly firstDelayMs; private readonly startupGraceMs; private readonly startupRetryMs; private readonly results; /** Failed runs in a row per check — counted, not derived from the kept history, which is cut at `keep`. */ private readonly streak; private readonly traces; private running; private inFlight; private timers; /** Changes on every start()/stop(): a run from an earlier one must not report into this one. */ private generation; /** On the `elapsed` clock: a wall clock stepping back would keep the grace time open for ever. */ private startedAt; /** The app itself (a check with a path) has answered since start(). */ private appAnswered; constructor(options: CheckRunnerOptions); /** Was this trace started by one of our own requests? Their spans are not real traffic. */ isCheckTrace(traceId: string): boolean; urlOf(check: Check): string; /** * One request, judged. Never throws: a failed request is a result. Resolves with `undefined` when there is nothing * to report — the runner was stopped meanwhile, or the app has not started listening yet (see startupGraceMs). */ run(check: Check): Promise; private attempt; /** Starts the timers. A check whose previous run is still waiting for its answer is skipped, not stacked. */ start(): void; /** Stops the timers and drops the requests on their way: nothing is recorded or reported after this. */ stop(): void; list(): CheckStatus[]; }