import type { FreshnessConfig, FreshnessLevel, FreshnessMessageFn, FreshnessMessages, FreshnessResult } from './types.js'; /** * The caller's config and clock, each read exactly once and validated. Every * later step uses these values, never the caller's objects, so a getter, proxy * or Date subclass that answers differently on a second read cannot make the * result disagree with what was validated. */ export interface FreshnessContext { readonly warnAfterDays: number; readonly staleAfterDays: number; /** The clock as epoch milliseconds. */ readonly current: number; } /** The two thresholds of a validated config, each read once. */ export interface FreshnessThresholds { readonly warnAfterDays: number; readonly staleAfterDays: number; } /** Internal: validate `config`'s thresholds and snapshot them. Throws RangeError. */ export declare function readThresholds(config: FreshnessConfig): FreshnessThresholds; /** Internal: validate `config` and `now` (also used for an empty dataset) and snapshot them. */ export declare function readFreshnessContext(config: FreshnessConfig, now: Date): FreshnessContext; /** Internal: the clock as epoch milliseconds, brand-checked. Throws RangeError. */ export declare function readNow(now: Date): number; /** Internal: strict parse of a bare date or explicit-zone ISO timestamp. Throws RangeError. */ export declare function parseReviewedOn(reviewedOn: string): { instant: number; dateOnly: boolean; }; /** * Whole days between `reviewedOn` and `now`, computed in UTC, floored, never * negative. * * Throws RangeError for malformed, impossible or future review dates, or * an invalid clock. Bare dates mean UTC midnight; timestamps require an * explicit timezone. No invalid input is converted to age zero. * * Future dates: a timestamp is an exact instant and is rejected if it is * even one millisecond after `now`. A bare date has no zone, so it is * rejected only when it is later than today in every time zone (that is, * when its UTC midnight is more than 14 hours after `now`); a bare date that * is already today in UTC+14 is accepted and reads as age 0. This keeps a * reviewer who types their local date from being rejected for part of the day. */ export declare function ageInDays(reviewedOn: string, now?: Date): number; /** Internal: true when a parsed date is later than the clock allows (the future-date rule on ageInDays). */ export declare function isAheadOfClock(parsed: { instant: number; dateOnly: boolean; }, current: number): boolean; /** Internal: whole UTC days from `instant` to `current`, floored, never negative. */ export declare function wholeDaysBetween(instant: number, current: number): number; /** "1 day" or "N days", for the default messages. */ export declare function dayCount(ageDays: number): string; /** The caller's message overrides after validation: only real functions, read once. */ export type FreshnessMessageFns = Readonly>>; /** A plain object or a null-prototype object: not an array, Map, Set, Date, RegExp or class instance. */ export declare function isPlainObject(value: unknown): value is Record; /** `typeof`, except that null is named as null. Cannot throw, so it is safe inside an error message. */ export declare function typeName(value: unknown): string; /** * Internal: validate and snapshot the caller's `messages`. `undefined` means * "use the defaults"; anything else must be a plain object whose own * `fresh`/`aging`/`stale` entries are each `undefined` or a function. A Map, a * class instance or `null` would otherwise be read as "no overrides" and * silently replaced by the defaults. */ export declare function readMessages(messages: FreshnessMessages | undefined): FreshnessMessageFns; /** * Internal: the level and whole-day age of one review date, against an * already-read context, plus the review instant (epoch ms) for tie-breaking. * No callbacks run. */ export declare function classify(reviewedOn: string, context: FreshnessContext): { level: FreshnessLevel; ageDays: number; instant: number; }; /** Internal: the level of a whole-day age against two thresholds (inclusive boundaries). */ export declare function levelForAge(ageDays: number, thresholds: FreshnessThresholds): FreshnessLevel; /** Internal: the reader-facing message for a classified date. The callback must return a string. */ export declare function renderMessage(level: FreshnessLevel, ageDays: number, reviewedOn: string, fns: FreshnessMessageFns): string; /** * Compute a FreshnessResult for a single reviewed-on date against a pair of * declared thresholds, generating reader-facing copy through * caller-overridable message functions (generic defaults are used for any * level not overridden). * * Level boundaries: 'fresh' through and including warnAfterDays, 'aging' * from warnAfterDays + 1 through and including staleAfterDays, 'stale' from * staleAfterDays + 1 on. Age is floored to whole days, so "stale after N days" * means more than N whole days have passed: at N days and 23 hours the result * is still 'aging'. * * `config`, `messages` and `now` are each read once. `messages` must be * `undefined` or a plain object whose `fresh`/`aging`/`stale` entries are * `undefined` or functions, and the function for the reached level must return * a string. * * @throws {RangeError} for invalid thresholds, date input or clock, or a * `messages` value that is not a plain object. Callers must surface an * unavailable warning or fail their gate, not substitute fresh. * @throws {TypeError} when a `messages` entry is not a function, or a message * function returns something other than a string. These are caller-code * bugs, not bad input data. */ export declare function assessFreshness(reviewedOn: string, config: FreshnessConfig, messages?: FreshnessMessages, now?: Date): FreshnessResult;