/** * @copyright Sister Software * @license AGPL-3.0 * @author Teffen Ellis, et al. * * Browser-side postcode resolver for the anchor (#240). A pure-JS, zero-dependency * `PostcodeResolver` backed by a compact flat binary instead of SQLite, so the postcode anchor * runs in the WASM/browser parser behind the same `lookup()` seam as the server-side * `WOFPostcodeLookup`. * * This file owns BOTH ends of the format — `serializePostcodeBinary` (run in Node by * `scripts/build-postcode-binary.ts`) and `PostcodeBinaryResolver` (run in the browser) — so the * layout can never drift between writer and reader. * * Binary layout (little-endian): magic "PCB1" (4 bytes) u32 recordCount u8 countryCount, then * countryCount × 2 ASCII bytes (the country table) u8 keyWidth (max postcode length in bytes) * records recordCount × { key[keyWidth] ASCII right-padded with 0x00, u8 countryIdx, i16 latQ, * i16 lonQ }, sorted by key bytes ascending. A postcode present in two countries appears as two * adjacent records (same key, different countryIdx). * * Coordinates are quantized to i16: latQ = round(lat/90 × 32767), lonQ = round(lon/180 × 32767), * giving ~300 m resolution — ample for a "which city/region" anchor. A record with latQ = lonQ = * 0 means "known postcode, no centroid" (membership only), matching the SQLite resolver's * convention. */ import type { AnchorLookup } from "./anchor-inference.ts"; import type { PostcodePlace } from "./postcode-anchor.ts"; export interface PostcodeBinaryEntry { postcode: string; country: string; lat: number; lon: number; } /** * Serialize postcode entries into the flat binary. Entries are sorted by (postcode, country) so equal postcodes land in * adjacent records. Run in Node; consumed by {@link PostcodeBinaryResolver}. */ export declare function serializePostcodeBinary(entries: readonly PostcodeBinaryEntry[]): Uint8Array; /** * Pure-JS, browser-safe postcode resolver over the flat binary. Implements the same `lookup()` seam as the SQLite * `WOFPostcodeLookup`, so `extractPostcodeAnchors` is agnostic to which backs it. */ export declare class PostcodeBinaryResolver { #private; constructor(bytes: Uint8Array); lookup(postcode: string): PostcodePlace[]; /** * Decode the whole binary into an {@link AnchorLookup} (`Map`) for the neural anchor channel * (#239/#240): each postcode → a uniform posterior over its member countries * * - The mean of its non-zero centroids. This is the browser-side equivalent of the pilot postcode→anchor lookup the * model trained against, built live from the shipped binary instead of a precomputed JSON. Records are stored * sorted by (postcode, country), so equal keys are contiguous. */ toAnchorLookup(): AnchorLookup; } //# sourceMappingURL=postcode-binary-resolver.d.ts.map