/** * Fetch from batch.openaddresses.io: a country collection, or individual sources' latest job outputs. */ import { APIClient } from "@mailwoman/core/api"; import { type PathBuilderLike } from "path-ts"; import type { BaseFetchOptions, FetchSummary } from "#tools/fetch/download"; export interface FetchOpenAddressesOptions extends BaseFetchOptions { country?: string; /** * OpenAddresses source members, such as `us/mi/statewide`, each with the job a plan pins it to. * * When set, the fetch caches each source's batch job output in `cache` instead of a country collection. */ sources?: readonly OpenAddressesFetchTarget[] | null; /** * Where source job outputs are cached, the US address layer's OpenAddresses cache. * * @defaultValue `$MAILWOMAN_CACHE_ROOT/sources/openaddresses` */ cache?: PathBuilderLike; } /** * One entry of `GET /api/data`: a source layer's latest successful job. */ export interface OaDataEntry { /** * The source's member path, such as `us/tx/nueces`. */ source?: string; job?: number; layer?: string; /** * The name the source definition gives the layer. * * Most US names state the publisher's level, such as `city`, `county` or `state`. */ name?: string; /** * When the job last updated, as the ISO timestamp the API returns, such as `2026-10-30T15:01:55.655Z`. */ updated?: string; /** * The job output's size in bytes. */ size?: number; } /** * The entry with the most recent `updated` timestamp among those that name a job, * or undefined when none does. */ export declare function latestOpenAddressesJob(entries: readonly OaDataEntry[]): OaDataEntry | undefined; /** * The latest job of one member among the entries the batch API returned for it. * * The API's `source` parameter matches by prefix, so a query for `us/fl/statewide` * also returns the jobs of `us/fl/statewide2`. * Only entries whose `source` is the member itself are read. */ export declare function latestMemberJob(entries: readonly OaDataEntry[], member: string): OaDataEntry | undefined; /** * A batch API client authenticated with `OA_BATCH_TOKEN`. * * @throws When `OA_BATCH_TOKEN` isn't set. */ export declare function createOpenAddressesClient(): APIClient; /** * The fields of one job's record, `GET /api/job/:id`, the plan reads. */ export interface OpenAddressesJobRecord { id: number; /** * The license object the source's definition states, such as `{ "url": "…", "website": "…" }`. */ license?: unknown; /** * The source definition's URL at the commit the job ran from. */ source?: string; count?: number; status?: string; } /** * One job's record as the batch API returns it. */ export declare function readOpenAddressesJob(client: APIClient, id: number): Promise; /** * Every `GET /api/data` entry the batch API lists for one layer, across all sources. */ export declare function listOpenAddressesLayerJobs(client: APIClient, layer: string): Promise; /** * One source the batch API holds an addresses job for, with the license its latest job states. */ export interface OpenAddressesPlanSource { member: string; license: unknown; /** * The latest batch job, or null for a source an earlier plan listed that the * batch API holds no addresses job for. * * The cache can still hold that source's run from the anonymous results endpoint. */ job: number | null; updated: string | null; /** * The latest job's layer name, such as `county`, or null when the API states none. */ level: string | null; /** * The latest job's feature count, or null when its record states none. */ features: number | null; /** * The latest job output's size in bytes, or null when the API states none. */ bytes: number | null; } /** * Lists every addresses source under a member prefix, such as `us/`, with its latest job's license. * * A source with several addresses entries, one per layer `name` such as `county`, * keeps the most recently updated. * Each source's job record is read once, for the license and feature count the plan records. */ export declare function buildOpenAddressesPlan(client: APIClient, prefix: string, report?: (done: number, total: number) => void): Promise; /** * What a cached source job output's `.RECORD.json` sidecar states. */ export interface OpenAddressesSourceRecord { member: string; job: number; /** * When OpenAddresses last updated the job, as an ISO date. */ updated: string | null; features: number; bytes: number; sha256: string; fetchedAt: string; } /** * One source member to cache, with the job a plan pins it to. */ export interface OpenAddressesFetchTarget { member: string; /** * The job to cache. * * When absent, the fetch asks the batch API for the member's latest job. */ job?: number | null; /** * When the pinned job last updated, as the plan records it. */ updated?: string | null; } /** * Caches each source's batch job output, `source.geojson.gz`, in `cache` under * {@linkcode openAddressesSourceCacheName}, with a `.RECORD.json` sidecar. * * A target that pins a job is cached at that job. * Any other target is cached at the member's latest job. * * The file is stored compressed, as the batch API serves it, because the * address-layer reader decompresses while it streams. * A source whose sidecar records the job, and whose file still has the recorded size, is skipped. * * A download whose feature count differs from the job's recorded count is refused and removed. */ export declare function fetchOpenAddressesSources(options: { sources: readonly OpenAddressesFetchTarget[]; cache: PathBuilderLike; }, report?: (line: string) => void): Promise; export declare function fetchOpenAddresses(options: FetchOpenAddressesOptions, report?: (line: string) => void): Promise; //# sourceMappingURL=openaddresses.d.ts.map