import { type FeedResult, type RaceFeed } from "./circuits.feed.ts"; /** Why a feed could not be read. */ export type FeedProblemKind = "address" | "blocked" | "refused" | "busy" | "http" | "big" | "json" | "format"; /** A feed that could not be read: what kind of problem, the answer's status if there was one, and a sentence. */ export declare class RaceFeedError extends Error { readonly kind: FeedProblemKind; readonly status?: number; constructor(kind: FeedProblemKind, message: string, status?: number); } /** The most text a feed may be: 30 MB. */ export declare const FEED_MAX_BYTES = 30000000; type Fetch = (url: string, init?: RequestInit) => Promise; /** * Read a feed from text (pasted, or a file's): kyogijo's open race timeline, or the lap rows of an OpenF1-style API. The answer is a feed, or a sentence that says why not. * @example * ```ts * import { feedFromText } from "@johnmorrisdotca/kyogijo-stadiums/circuits"; * console.log(feedFromText('{"kind":"kyogijo-race","version":1,"cars":[{"id":"a"}],"crossings":[{"car":"a","lap":1,"t":99}]}').ok, feedFromText("not json").ok); * // true false * ``` */ export declare function feedFromText(text: string): FeedResult; /** An address the user typed, if it is one a page may read: http or https, nothing else. */ export declare function feedAddress(text: string, base?: string): URL | undefined; /** For an OpenF1-style lap address (`…/laps?session_key=…`), the same source's pit and driver addresses for that session. */ export declare function openF1Siblings(url: URL): { pit: string; drivers: string; } | undefined; /** * Read a race feed from an address the user gave, with the user's browser: kyogijo's open race timeline, or an OpenF1-style lap list (whose pit stops and drivers are then asked for from the same source and session, * if it has them). It throws a `RaceFeedError` whose message says what went wrong in words: a source that does not let pages read it (CORS), a refusal (403), too many requests (429), not JSON, not a feed. * @example * ```ts no-run * import { loadRaceFeed, raceFromFeed } from "@johnmorrisdotca/kyogijo-stadiums/circuits"; * const feed = await loadRaceFeed("https://example.org/my-race.json"); * const race = raceFromFeed(feed, "las-vegas"); * ``` */ export declare function loadRaceFeed(address: string, options?: { fetch?: Fetch; signal?: AbortSignal; base?: string; }): Promise; /** What `followRaceFeed` gives back. */ export interface FeedFollower { /** Stop asking. */ stop(): void; /** Whether it is still following. */ readonly following: boolean; } /** How often a feed is asked again while it is followed: no faster than every 10 seconds, every 15 by default. */ export declare const FOLLOW_EVERY: Readonly<{ least: 10000; normal: 15000; most: 120000; }>; /** * Follow a race that is going on: ask the user's address again every 15 seconds (never faster than 10), only while the page is visible, and hand each new feed to `onFeed`. It stops by itself when the feed is no longer * live (the race is over), when the source refuses (403) or says it is busy (429), and when `stop` is called; after any other failure it waits twice as long each time, up to two minutes. A hidden page asks nothing. */ export declare function followRaceFeed(address: string, onFeed: (feed: RaceFeed) => void, options?: { every?: number; fetch?: Fetch; doc?: Document; onError?: (error: RaceFeedError) => void; onStop?: (why: "over" | "refused" | "stopped") => void; }): FeedFollower; export {};