@mailwoman/core 10.3.0 → 10.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (190) hide show
  1. package/data/PROVENANCE.md +14 -14
  2. package/data/libpostal/README.md +15 -15
  3. package/data/libpostal/dictionaries/README.md +3 -3
  4. package/lib/api/APIClient.ts +3 -3
  5. package/lib/api/ckan.ts +1 -1
  6. package/lib/api/clock.ts +1 -1
  7. package/lib/api/disk-storage.ts +4 -4
  8. package/lib/api/ogc.ts +9 -9
  9. package/lib/api/pacer.ts +1 -1
  10. package/lib/api/responses.ts +6 -6
  11. package/lib/api/retry.ts +2 -2
  12. package/lib/api/test/clocks.ts +2 -2
  13. package/lib/api/test/transport.ts +1 -1
  14. package/lib/coarse-placer/coarse-placer.ts +1 -1
  15. package/lib/decoder/build-tree.ts +1 -1
  16. package/lib/decoder/parse-diff.ts +3 -3
  17. package/lib/decoder/serialize/json.ts +1 -1
  18. package/lib/decoder/serialize/xml.ts +1 -1
  19. package/lib/env/env-file.ts +71 -0
  20. package/lib/env.ts +15 -9
  21. package/lib/fs/delimited.ts +3 -3
  22. package/lib/fs/formatters.ts +1 -1
  23. package/lib/fs/readers/stat.ts +16 -1
  24. package/lib/fs/readers.ts +18 -2
  25. package/lib/fs/zip.ts +1 -1
  26. package/lib/geocode/result.ts +8 -4
  27. package/lib/html/document.ts +1 -1
  28. package/lib/html/elements.ts +3 -3
  29. package/lib/json.ts +1 -1
  30. package/lib/layers/coverage.ts +3 -3
  31. package/lib/layers/manifest.ts +2 -2
  32. package/lib/layers/publication.ts +1 -1
  33. package/lib/layers/schema.ts +1 -1
  34. package/lib/license/docs-site.ts +1 -1
  35. package/lib/license/record.ts +3 -4
  36. package/lib/module/compiled-freshness.ts +6 -2
  37. package/lib/numeric.ts +2 -2
  38. package/lib/pipeline/runtime-pipeline.ts +47 -9
  39. package/lib/pipeline/span-proposer.ts +2 -2
  40. package/lib/pipeline/types.ts +153 -6
  41. package/lib/pipeline.ts +6 -0
  42. package/lib/postcode-prefix-files.ts +87 -0
  43. package/lib/promises.ts +12 -0
  44. package/lib/release-config.ts +7 -0
  45. package/lib/resolver/coverage-facts.ts +3 -3
  46. package/lib/resolver/lookup-types.ts +7 -6
  47. package/lib/resolver/referential.ts +1 -1
  48. package/lib/resolver/types.ts +6 -0
  49. package/lib/resources/libpostal.ts +51 -3
  50. package/lib/resources/whosonfirst/placetypes/graph.ts +2 -2
  51. package/lib/resources/whosonfirst/placetypes/specificity.ts +2 -2
  52. package/lib/scripting/utils.ts +1 -1
  53. package/lib/tokenization/normalizer.ts +1 -1
  54. package/lib/trust-policies.ts +1 -1
  55. package/lib/types/classifier.ts +1 -1
  56. package/lib/utils/chunk-process.ts +1 -1
  57. package/lib/utils/system.ts +1 -1
  58. package/out/api/APIClient.d.ts +2 -2
  59. package/out/api/APIClient.js +1 -1
  60. package/out/api/APIClient.js.map +1 -1
  61. package/out/api/ckan.d.ts +1 -1
  62. package/out/api/clock.d.ts +1 -1
  63. package/out/api/clock.js +1 -1
  64. package/out/api/disk-storage.js +4 -4
  65. package/out/api/disk-storage.js.map +1 -1
  66. package/out/api/ogc.d.ts +8 -8
  67. package/out/api/ogc.js +8 -8
  68. package/out/api/ogc.js.map +1 -1
  69. package/out/api/pacer.d.ts +1 -1
  70. package/out/api/pacer.js +1 -1
  71. package/out/api/responses.d.ts +4 -4
  72. package/out/api/responses.js +6 -6
  73. package/out/api/responses.js.map +1 -1
  74. package/out/api/retry.d.ts +2 -2
  75. package/out/api/retry.js +1 -1
  76. package/out/api/test/clocks.js +2 -2
  77. package/out/api/test/transport.d.ts +1 -1
  78. package/out/coarse-placer/coarse-placer.d.ts +1 -1
  79. package/out/coarse-placer/coarse-placer.js +1 -1
  80. package/out/decoder/build-tree.js +1 -1
  81. package/out/decoder/build-tree.js.map +1 -1
  82. package/out/decoder/parse-diff.d.ts +3 -3
  83. package/out/decoder/parse-diff.js +2 -2
  84. package/out/decoder/serialize/json.js +1 -1
  85. package/out/decoder/serialize/xml.d.ts +1 -1
  86. package/out/decoder/serialize/xml.js +1 -1
  87. package/out/env/env-file.d.ts +26 -0
  88. package/out/env/env-file.d.ts.map +1 -0
  89. package/out/env/env-file.js +60 -0
  90. package/out/env/env-file.js.map +1 -0
  91. package/out/env.d.ts.map +1 -1
  92. package/out/env.js +15 -10
  93. package/out/env.js.map +1 -1
  94. package/out/fs/delimited.d.ts +3 -3
  95. package/out/fs/delimited.js +3 -3
  96. package/out/fs/formatters.d.ts +1 -1
  97. package/out/fs/formatters.js +1 -1
  98. package/out/fs/readers/stat.d.ts +9 -1
  99. package/out/fs/readers/stat.d.ts.map +1 -1
  100. package/out/fs/readers/stat.js +16 -0
  101. package/out/fs/readers/stat.js.map +1 -1
  102. package/out/fs/readers.d.ts +14 -2
  103. package/out/fs/readers.d.ts.map +1 -1
  104. package/out/fs/readers.js +17 -2
  105. package/out/fs/readers.js.map +1 -1
  106. package/out/fs/zip.d.ts +1 -1
  107. package/out/fs/zip.js +1 -1
  108. package/out/geocode/result.d.ts +17 -5
  109. package/out/geocode/result.d.ts.map +1 -1
  110. package/out/geocode/result.js +8 -4
  111. package/out/geocode/result.js.map +1 -1
  112. package/out/html/document.d.ts +1 -1
  113. package/out/html/document.js +1 -1
  114. package/out/html/elements.d.ts +2 -2
  115. package/out/html/elements.js +3 -3
  116. package/out/json.d.ts +1 -1
  117. package/out/json.js +1 -1
  118. package/out/layers/coverage.d.ts +3 -3
  119. package/out/layers/coverage.js +2 -2
  120. package/out/layers/manifest.d.ts +2 -2
  121. package/out/layers/publication.d.ts +1 -1
  122. package/out/layers/publication.js +1 -1
  123. package/out/layers/schema.d.ts +1 -1
  124. package/out/license/docs-site.d.ts +1 -1
  125. package/out/license/docs-site.js +1 -1
  126. package/out/license/record.d.ts.map +1 -1
  127. package/out/license/record.js +3 -4
  128. package/out/license/record.js.map +1 -1
  129. package/out/module/compiled-freshness.d.ts +1 -1
  130. package/out/module/compiled-freshness.d.ts.map +1 -1
  131. package/out/module/compiled-freshness.js +6 -2
  132. package/out/module/compiled-freshness.js.map +1 -1
  133. package/out/numeric.js +2 -2
  134. package/out/pipeline/runtime-pipeline.d.ts +15 -0
  135. package/out/pipeline/runtime-pipeline.d.ts.map +1 -1
  136. package/out/pipeline/runtime-pipeline.js +25 -5
  137. package/out/pipeline/runtime-pipeline.js.map +1 -1
  138. package/out/pipeline/span-proposer.d.ts +1 -1
  139. package/out/pipeline/span-proposer.js +1 -1
  140. package/out/pipeline/types.d.ts +150 -6
  141. package/out/pipeline/types.d.ts.map +1 -1
  142. package/out/pipeline/types.js +1 -1
  143. package/out/pipeline/types.js.map +1 -1
  144. package/out/pipeline.d.ts +2 -2
  145. package/out/pipeline.d.ts.map +1 -1
  146. package/out/pipeline.js +1 -1
  147. package/out/pipeline.js.map +1 -1
  148. package/out/postcode-prefix-files.d.ts +45 -0
  149. package/out/postcode-prefix-files.d.ts.map +1 -0
  150. package/out/postcode-prefix-files.js +64 -0
  151. package/out/postcode-prefix-files.js.map +1 -0
  152. package/out/promises.d.ts +7 -0
  153. package/out/promises.d.ts.map +1 -1
  154. package/out/promises.js +10 -0
  155. package/out/promises.js.map +1 -1
  156. package/out/release-config.d.ts +7 -0
  157. package/out/release-config.d.ts.map +1 -1
  158. package/out/release-config.js.map +1 -1
  159. package/out/resolver/coverage-facts.d.ts +3 -3
  160. package/out/resolver/lookup-types.d.ts +7 -6
  161. package/out/resolver/lookup-types.d.ts.map +1 -1
  162. package/out/resolver/referential.d.ts +1 -1
  163. package/out/resolver/referential.js +1 -1
  164. package/out/resolver/types.d.ts +11 -1
  165. package/out/resolver/types.d.ts.map +1 -1
  166. package/out/resolver/types.js.map +1 -1
  167. package/out/resources/libpostal.d.ts +22 -3
  168. package/out/resources/libpostal.d.ts.map +1 -1
  169. package/out/resources/libpostal.js +44 -4
  170. package/out/resources/libpostal.js.map +1 -1
  171. package/out/resources/whosonfirst/placetypes/graph.d.ts +2 -2
  172. package/out/resources/whosonfirst/placetypes/graph.js +1 -1
  173. package/out/resources/whosonfirst/placetypes/specificity.d.ts +2 -2
  174. package/out/resources/whosonfirst/placetypes/specificity.js +2 -2
  175. package/out/scripting/utils.d.ts +1 -1
  176. package/out/scripting/utils.js +1 -1
  177. package/out/tokenization/normalizer.js +1 -1
  178. package/out/tools/coarse-placer/outlier-rows.js +1 -1
  179. package/out/tools/coarse-placer/paths.d.ts +2 -2
  180. package/out/tools/coarse-placer/paths.js +2 -2
  181. package/out/trust-policies.d.ts +1 -1
  182. package/out/trust-policies.js +1 -1
  183. package/out/types/classifier.d.ts +1 -1
  184. package/out/utils/chunk-process.d.ts +1 -1
  185. package/out/utils/chunk-process.js +1 -1
  186. package/out/utils/system.d.ts +1 -1
  187. package/out/utils/system.js +1 -1
  188. package/package.json +28 -8
  189. package/tools/coarse-placer/outlier-rows.ts +1 -1
  190. package/tools/coarse-placer/paths.ts +2 -2
@@ -5,7 +5,7 @@
5
5
  */
6
6
 
7
7
  import { AssertionError } from "node:assert"
8
- import type { Dirent, Mode, Stats } from "node:fs"
8
+ import { type Dirent, type Mode, type Stats, statSync } from "node:fs"
9
9
  import {
10
10
  open as openNative,
11
11
  access,
@@ -201,6 +201,21 @@ export function isFile(path: PathBuilderLike | URL): Promise<boolean> {
201
201
  return tryStat(path).then((stats) => stats?.isFile() ?? false)
202
202
  }
203
203
 
204
+ /**
205
+ * Whether a path exists and is a file, read synchronously.
206
+ *
207
+ * The env module folds `.env` into `process.env` when it is imported,
208
+ * ahead of any `await`, so it cannot use {@linkcode isFile}.
209
+ * Every other caller can, and should.
210
+ */
211
+ export function isFileSync(path: PathBuilderLike): boolean {
212
+ try {
213
+ return statSync(resolvePath(path)).isFile()
214
+ } catch {
215
+ return false
216
+ }
217
+ }
218
+
204
219
  /**
205
220
  * Whether a path exists and is a symbolic link.
206
221
  */
package/lib/fs/readers.ts CHANGED
@@ -8,6 +8,7 @@
8
8
  * makes no blocking filesystem calls. The `debt` check in `lib/repo-health` counts any violations.
9
9
  */
10
10
 
11
+ import { readFileSync } from "node:fs"
11
12
  import { readFile } from "node:fs/promises"
12
13
 
13
14
  import { type PathBuilderLike, resolvePath } from "path-ts"
@@ -24,7 +25,7 @@ export type { FileHandle } from "node:fs/promises"
24
25
  * Read the first `byteSize` bytes of a file, or the whole file if it is smaller.
25
26
  *
26
27
  * @param path The file to read.
27
- * @param byteSize [65536] How many bytes to read.
28
+ * @param byteSize [65536] The number of bytes to read.
28
29
  * That size is enough to sniff a file's format.
29
30
  *
30
31
  * @returns The bytes read, as a UTF-8 string.
@@ -52,7 +53,8 @@ export async function readFileHead(path: PathBuilderLike, byteSize: number): Pro
52
53
  * Three reads at three positions, where reading the whole file would mean loading
53
54
  * a multi-gigabyte artifact to look at sixteen bytes.
54
55
  *
55
- * Returns the bytes it actually read.
56
+ * Returns the bytes it read.
57
+ * The count can be smaller than the requested size.
56
58
  * The result is shorter than `length` at end of file.
57
59
  *
58
60
  * @throws Enoent when the file does not exist.
@@ -89,6 +91,20 @@ function readTarget(pathSegments: Array<PathBuilderLike | URL>): URL | string {
89
91
  return resolvePath(...(pathSegments as PathBuilderLike[]))
90
92
  }
91
93
 
94
+ /**
95
+ * Read a local text file synchronously.
96
+ *
97
+ * The env module folds `.env` into `process.env` when it is imported, ahead of any `await`,
98
+ * so it cannot use {@linkcode readLocalTextFile}.
99
+ * Every other caller can, and should.
100
+ *
101
+ * @category Files
102
+ * @runtime node
103
+ */
104
+ export function readLocalTextFileSync(...pathSegments: PathBuilderLike[]): string {
105
+ return readFileSync(resolvePath(...pathSegments), "utf8")
106
+ }
107
+
92
108
  /**
93
109
  * Read a local text file.
94
110
  *
package/lib/fs/zip.ts CHANGED
@@ -5,7 +5,7 @@
5
5
  * @file Zip readers for archives already in memory or stored on disk.
6
6
  *
7
7
  * {@link extractZip} and {@link extractSingleFileZip} take the whole archive as a `Buffer`.
8
- * That suits a client that just downloaded one (`bdc/sdk/download.ts`).
8
+ * That suits a client that has downloaded one into memory (`bdc/sdk/download.ts`).
9
9
  * It does not suit large archives because adm-zip keeps both the archive and decompressed member in memory.
10
10
  * National address dumps under `$MAILWOMAN_DATA_ROOT` range from 0.5–2.9 GB compressed and reach 9 GB unpacked.
11
11
  * The path-based readers stream them. Yauzl seeks the central directory through a file handle and inflates one member on demand.
@@ -5,7 +5,7 @@
5
5
  *
6
6
  * The geocode result: the data shape one geocoded input projects to.
7
7
  *
8
- * The schemas here are the source of truth and each type is inferred from its schema.
8
+ * The schemas here define the shapes, and each type is inferred from its schema.
9
9
  * The `mailwoman` package computes the result and the HTTP surfaces serve it.
10
10
  */
11
11
 
@@ -139,13 +139,17 @@ export type AuthoritativeAssertion = z.infer<typeof AuthoritativeAssertionSchema
139
139
  /**
140
140
  * A parsed component that the answer's coordinate ignored.
141
141
  *
142
- * The only current `reason`, `postcode_move_refused`, means the postcode resolved
143
- * too far from the selected locality.
142
+ * - `postcode_move_refused`: the postcode resolved too far from the selected locality.
143
+ * - `rooftop_outside_locality`: the address-point row lies too far from the selected
144
+ * locality, and no alternative locality lies near it.
145
+ * The coordinate is the rooftop.
146
+ * The hierarchy still holds the selected locality.
147
+ * The rooftop contradicts that locality.
144
148
  */
145
149
  export const UnfollowedComponentSchema = z.object({
146
150
  tag: ComponentTagSchema,
147
151
  value: z.string(),
148
- reason: z.literal("postcode_move_refused"),
152
+ reason: z.enum(["postcode_move_refused", "rooftop_outside_locality"]),
149
153
  /**
150
154
  * The distance in kilometers that following this component would have moved the answer.
151
155
  */
@@ -3,7 +3,7 @@
3
3
  * @license AGPL-3.0
4
4
  * @author Teffen Ellis, et al.
5
5
  *
6
- * Narrows a document to the markup worth reading before downstream code parses it.
6
+ * Narrows a document to the markup that holds content before downstream code parses it.
7
7
  * An archive can wrap its payload in an envelope element. Its `<head>` title can contain a filename.
8
8
  * Its `<script>` and `<style>` blocks do not contain document content.
9
9
  * Downstream strategies should read the same narrowed window instead of deriving their own.
@@ -88,8 +88,8 @@ export interface StreamMarkupOptions {
88
88
  * The elements matching `name`, each complete, in document order.
89
89
  *
90
90
  * A nested element of the same name is not yielded separately: capture starts at the
91
- * outermost occurrence and ends when that one closes, so one `ad:Address` arrives
92
- * once however many `ad:Address` elements its own subtree contains.
91
+ * outermost occurrence and ends when that one closes, so one `ad:Address` arrives once
92
+ * whatever the number of `ad:Address` elements its own subtree contains.
93
93
  *
94
94
  * Several names read one document once.
95
95
  * An INSPIRE collection writes the features an address references before the addresses
@@ -226,7 +226,7 @@ export async function* streamMarkupElements(
226
226
  * A caller that buffers a whole document and yields it once would otherwise
227
227
  * ask for a string past V8's maximum length.
228
228
  * The decoder's state persists across the pieces, so a multi-byte character spanning
229
- * a slice boundary survives, as it does across chunks.
229
+ * a piece boundary survives, as it does across chunks.
230
230
  */
231
231
  const decodePieces = (chunk: Uint8Array): string[] => {
232
232
  if (chunk.length <= MAX_DECODED_CHUNK) return [decoder.decode(chunk, { stream: true })]
package/lib/json.ts CHANGED
@@ -116,7 +116,7 @@ export function parseJSONStrict<T = unknown>(input: string): T {
116
116
  * because a non-array there is a schema change at the source rather than something to coerce.
117
117
  * An empty array would read as "none", which is not what a differently-shaped value means.
118
118
  *
119
- * @param scope Names the reader in the error, e.g. `coastal client`.
119
+ * @param scope The reader the error message identifies, e.g. `coastal client`.
120
120
  */
121
121
  export function parseJSONArray<T>(raw: string | null | undefined, scope: string): T[] {
122
122
  if (!raw) return []
@@ -75,7 +75,7 @@ export function designatedCoverageCells(
75
75
  * writes a stronger basis without settling the footprint question, the build refuses
76
76
  * rather than letting an absent polygon be read as a designation.
77
77
  *
78
- * @param scope Names the caller in the refusal, e.g. `coastal build`.
78
+ * @param scope The caller the refusal identifies, e.g. `coastal build`.
79
79
  * @param limitSentence The product's own sentence saying why its coverage licenses no negative claim.
80
80
  */
81
81
  export function assertNoNegativeClaim(scope: string, cells: ReadonlyArray<CoverageCell>, limitSentence: string): void {
@@ -139,7 +139,7 @@ export interface ResolutionMeasurementOptions {
139
139
  resolutions: readonly number[]
140
140
  onProgress?: (message: string) => void
141
141
  /**
142
- * How often to report progress, in features.
142
+ * The progress interval, in features.
143
143
  */
144
144
  progressEvery?: number
145
145
  }
@@ -249,7 +249,7 @@ export function areaAgreementFrom(streamed: StreamedAreaTotals, sourceM2: number
249
249
  * The message includes the hole-blind total beside the nested one, because the gap between them
250
250
  * is the diagnosis: a hole read as an exterior ring answers "inside" for every point in it.
251
251
  *
252
- * @param scope Names the builder in the error, e.g. `coastal build`.
252
+ * @param scope The builder the error message identifies, e.g. `coastal build`.
253
253
  */
254
254
  export function assertAreaAgreement(scope: string, area: AreaAgreementReading, tolerance: number): void {
255
255
  if (area.witness === "absent") return
@@ -51,7 +51,7 @@ export interface LayerManifest {
51
51
  spineKeys: SpineKeys
52
52
  createdAt: string
53
53
  /**
54
- * How many records each input publisher supplied to this build, keyed by the publisher's own name.
54
+ * The number of records each input publisher supplied to this build, keyed by the publisher's own name.
55
55
  *
56
56
  * The count is of the input rather than the rows the artifact kept.
57
57
  * It is recorded here because it cannot be recovered afterwards.
@@ -71,7 +71,7 @@ export interface CoverageCell {
71
71
  h3Cell: number
72
72
  completeness: number
73
73
  /**
74
- * Evidence basis for completeness.
74
+ * The evidence basis of `completeness`.
75
75
  *
76
76
  * @defaultValue `SourcePresent`
77
77
  */
@@ -36,7 +36,7 @@ import { carriesShareAlike, LicenseResolution, readLicenseRecord } from "#licens
36
36
  * `private` makes no claim about the license.
37
37
  *
38
38
  * @param subject The tier and license expression about to be stamped.
39
- * @param context Names the build in the error message.
39
+ * @param context The build the error message identifies.
40
40
  * @param detail Appended to the message where the caller knows why the license reads as it does.
41
41
  * @throws When the tier and the license disagree.
42
42
  */
@@ -146,7 +146,7 @@ export interface LayerCoverageTable {
146
146
  */
147
147
  basis: CoverageBasis | null
148
148
  /**
149
- * Rows this layer actually holds in the cell.
149
+ * Rows this layer stores in the cell.
150
150
  */
151
151
  observed_rows: number
152
152
  }
@@ -4,7 +4,7 @@
4
4
  * @author Teffen Ellis, et al.
5
5
  *
6
6
  * Where the docs site lives, for every URL the license posture points at: the well-known key register and the
7
- * `/license` page. One derivation, so a configured `MAILWOMAN_DOCS_URL` moves both together.
7
+ * `/license` page. One derivation serves both, so a configured `MAILWOMAN_DOCS_URL` moves them together.
8
8
  */
9
9
 
10
10
  import { $public } from "#env"
@@ -129,7 +129,7 @@ const EXPRESSION_ALIASES: ReadonlyMap<string, string> = new Map([
129
129
  ])
130
130
 
131
131
  /**
132
- * License identifiers worth recognizing inside prose, with the spelling each one appears under.
132
+ * License identifiers this reader recognizes inside prose, with the spelling each one appears under.
133
133
  *
134
134
  * Ordered longest-first so `CC-BY-SA` is found before `CC-BY`.
135
135
  */
@@ -263,9 +263,8 @@ const LICENSE_FAMILY_WORDS =
263
263
  * The caller keeps the verbatim entry beside the result.
264
264
  */
265
265
  export function licenseNamedIn(entry: string): string | null {
266
- // An entry often opens with a parenthetical belonging to the dataset's own name,
267
- // such as "OpenAddresses PL — GUGiK / PRG (public, BDOT-derived)", so every
268
- // parenthetical is read rather than the first.
266
+ // An entry can open with a parenthetical belonging to the dataset's own name, such as "OpenAddresses
267
+ // PL — GUGiK / PRG (public, BDOT-derived)", so every parenthetical is read rather than the first.
269
268
  for (const match of entry.matchAll(/\(([^()]{1,120})\)/gu)) {
270
269
  const inner = match[1]!.trim()
271
270
 
@@ -115,7 +115,7 @@ export interface CompiledFreshness {
115
115
  * Compares the newest source file against the newest compiled `.js` file across the given workspaces.
116
116
  *
117
117
  * `workspaces` are repo-relative directories.
118
- * Each caller passes the workspaces it actually loads.
118
+ * Each caller passes the workspaces it loads.
119
119
  *
120
120
  * A set that omits a loaded workspace can report `fresh` while that workspace is stale.
121
121
  */
@@ -124,6 +124,7 @@ export async function checkCompiledFreshness(
124
124
  workspaces: readonly string[]
125
125
  ): Promise<CompiledFreshness> {
126
126
  let newestSource: TimestampedFile | null = null
127
+ let newestSourceWorkspace: string | null = null
127
128
  let newestCompiled: TimestampedFile | null = null
128
129
 
129
130
  const root = PathBuilder.from(repoRoot)
@@ -142,6 +143,7 @@ export async function checkCompiledFreshness(
142
143
 
143
144
  if (source && (!newestSource || source.mtimeMs > newestSource.mtimeMs)) {
144
145
  newestSource = source
146
+ newestSourceWorkspace = workspace
145
147
  }
146
148
 
147
149
  if (compiled && (!newestCompiled || compiled.mtimeMs > newestCompiled.mtimeMs)) {
@@ -167,7 +169,9 @@ export async function checkCompiledFreshness(
167
169
  newestCompiled,
168
170
  reason:
169
171
  `Compiled output is ${driftSeconds}s older than source: ${newestSource.path} was modified after ` +
170
- `${newestCompiled.path}. Run \`yarn compile\` and re-run.`,
172
+ `${newestCompiled.path}. Run \`yarn compile\` and re-run. When the source reverted to content ` +
173
+ `that is already compiled, \`tsc -b\` skips the emit and the output stays stale, so run ` +
174
+ `\`yarn tsc -b ${newestSourceWorkspace} --force\` instead.`,
171
175
  }
172
176
  }
173
177
 
package/lib/numeric.ts CHANGED
@@ -22,8 +22,8 @@ export function clamp(value: number, min: number, max: number): number {
22
22
  *
23
23
  * These exist because the gazetteer pipeline was ported from Python and its outputs have to match
24
24
  * the originals bit for bit. A postcode centroid that rounds differently is a different centroid.
25
- * The extract containing it then differs from the reference. Divergence here never throws. It surfaces as a
26
- * extract that quietly disagrees with the reference.
25
+ * The extract containing it then differs from the reference. Divergence here never throws. It surfaces as an
26
+ * extract that disagrees with the reference and raises no error.
27
27
  */
28
28
 
29
29
  /**
@@ -23,6 +23,7 @@ import {
23
23
  import type {
24
24
  AddressClassifier,
25
25
  CaseNormalization,
26
+ AnchorRegionLookupLike,
26
27
  FSTMatcherLike,
27
28
  InputMode,
28
29
  LocaleHint,
@@ -34,6 +35,7 @@ import type {
34
35
  QueryKindResult,
35
36
  QueryShapeLite,
36
37
  RuntimePipelineStages,
38
+ VenueHeadStage,
37
39
  } from "#pipeline/types"
38
40
  import type { ResolveOpts } from "#resolver/types"
39
41
 
@@ -43,7 +45,7 @@ import type { ResolveOpts } from "#resolver/types"
43
45
  const SHORT_CIRCUIT_MIN_CONFIDENCE = 0.95
44
46
 
45
47
  /**
46
- * A locality-only input longer than this many characters takes the full pipeline.
48
+ * A locality-only input longer than this number of characters takes the full pipeline.
47
49
  */
48
50
  const SHORT_CIRCUIT_MAX_LOCALITY_LENGTH = 30
49
51
 
@@ -399,6 +401,9 @@ export async function runPipeline(
399
401
  caseNormalization: opts?.caseNormalization ?? DEFAULT_CASE_NORMALIZATION,
400
402
  placetypePair: opts?.placetypePair ?? "inherit",
401
403
  streetMorphology: stages.streetMorphology ?? null,
404
+ streetMorphologyPrior: stages.streetMorphologyPrior ?? false,
405
+ anchorRegions: stages.anchorRegions ?? null,
406
+ venueHead: stages.venueHead?.(locale) ?? null,
402
407
  inputMode: deriveInputMode(opts?.inputMode ?? "auto", kind.kind),
403
408
  })
404
409
 
@@ -477,10 +482,22 @@ async function safeClassify(
477
482
  caseNormalization: CaseNormalization
478
483
  placetypePair: PlacetypePairSelection
479
484
  streetMorphology: FSTMatcherLike | null
485
+ streetMorphologyPrior: boolean
486
+ anchorRegions: AnchorRegionLookupLike | null
487
+ venueHead: VenueHeadStage | null
480
488
  inputMode: InputMode
481
489
  }
482
490
  ): Promise<AddressTree> {
483
- const { fst, caseNormalization, placetypePair, streetMorphology, inputMode } = knobs
491
+ const {
492
+ fst,
493
+ caseNormalization,
494
+ placetypePair,
495
+ streetMorphology,
496
+ streetMorphologyPrior,
497
+ anchorRegions,
498
+ venueHead,
499
+ inputMode,
500
+ } = knobs
484
501
 
485
502
  try {
486
503
  return await classifier.parse(text, {
@@ -491,7 +508,10 @@ async function safeClassify(
491
508
  caseNormalization,
492
509
  enforceWordConsistency: WORD_CONSISTENCY_SHIP_DEFAULT,
493
510
  placetypePair,
494
- ...streetContextRequirementFor({ fst, streetMorphology }),
511
+ ...streetContextRequirementFor({ fst, streetMorphology }, { streetMorphologyPrior }),
512
+ ...(fst && anchorRegions ? { anchorRegions } : {}),
513
+ ...(venueHead ? { venueHead: venueHead.venueHead } : {}),
514
+ ...(venueHead?.venueHeadOpts ? { venueHeadOpts: venueHead.venueHeadOpts } : {}),
495
515
  })
496
516
  } catch (error) {
497
517
  recordFault(faults, PipelineFaultStage.Classifier, error)
@@ -506,6 +526,16 @@ async function safeClassify(
506
526
  */
507
527
  export const ZEROED_MORPHOLOGY_OPTS = { biasScale: 0, dependentLocalityPenalty: 0 } as const
508
528
 
529
+ /**
530
+ * The street-morphology options that bias a street affix at the prior's own weights,
531
+ * on a segment that opens with a house number only.
532
+ */
533
+ export const NUMBERED_MORPHOLOGY_OPTS = {
534
+ biasScale: 1,
535
+ dependentLocalityPenalty: 2,
536
+ numberedSegmentOnly: true,
537
+ } as const
538
+
509
539
  /**
510
540
  * The scale for positive street-context emissions.
511
541
  * Zero disables the positive boost.
@@ -515,19 +545,27 @@ export const STREET_CONTEXT_POSITIVE_SCALE = 0
515
545
  /**
516
546
  * Returns the street-context classifier options, or an empty object unless both the FST
517
547
  * and the street-morphology matcher are available.
548
+ *
549
+ * With `streetMorphologyPrior` the matcher also biases a street affix on a numbered segment.
550
+ * Without it the matcher serves the street-context check at zero emission weight.
518
551
  */
519
- export function streetContextRequirementFor(stages: {
520
- fst?: FSTMatcherLike | null
521
- streetMorphology?: FSTMatcherLike | null
522
- }): {
552
+ export function streetContextRequirementFor(
553
+ stages: {
554
+ fst?: FSTMatcherLike | null
555
+ streetMorphology?: FSTMatcherLike | null
556
+ },
557
+ options: { streetMorphologyPrior?: boolean } = {}
558
+ ): {
523
559
  fstStreetMorphology?: FSTMatcherLike
524
- fstStreetMorphologyOpts?: { biasScale: number; dependentLocalityPenalty: number }
560
+ fstStreetMorphologyOpts?: { biasScale: number; dependentLocalityPenalty: number; numberedSegmentOnly?: boolean }
525
561
  fstStreetContextPositiveScale?: number
526
562
  } {
527
563
  return stages.fst && stages.streetMorphology
528
564
  ? {
529
565
  fstStreetMorphology: stages.streetMorphology,
530
- fstStreetMorphologyOpts: { ...ZEROED_MORPHOLOGY_OPTS },
566
+ fstStreetMorphologyOpts: options.streetMorphologyPrior
567
+ ? { ...NUMBERED_MORPHOLOGY_OPTS }
568
+ : { ...ZEROED_MORPHOLOGY_OPTS },
531
569
  fstStreetContextPositiveScale: STREET_CONTEXT_POSITIVE_SCALE,
532
570
  }
533
571
  : {}
@@ -8,7 +8,7 @@
8
8
  */
9
9
 
10
10
  /**
11
- * A bracketed tail with at most this many tokens gets the lower short-tail confidence.
11
+ * A bracketed tail with at most this number of tokens gets the lower short-tail confidence.
12
12
  */
13
13
  const SHORT_INPUT_MAX_TOKENS = 3
14
14
 
@@ -88,7 +88,7 @@ export interface SpanProposerLexicon {
88
88
  */
89
89
  levelDesignators: ReadonlySet<string>
90
90
  /**
91
- * Designators that usually introduce descriptive text.
91
+ * Designators that can introduce descriptive text.
92
92
  * Their unit phrases get lower confidence.
93
93
  */
94
94
  weakDesignators: ReadonlySet<string>
@@ -42,7 +42,8 @@ export type CaseNormalization = "title-case" | "preserve"
42
42
  /**
43
43
  * How a caller sources an optional stage.
44
44
  *
45
- * - `"auto"` loads the bundled default, usually on the first parse.
45
+ * - `"auto"` loads the bundled default when it is first needed.
46
+ * For a typical caller that is the first parse.
46
47
  * - `"none"` disables the stage.
47
48
  * - Any other value is the stage itself.
48
49
  */
@@ -186,7 +187,7 @@ export interface QueryShapeLite {
186
187
  segments: ReadonlyArray<{ body: string; index: number; span: { start: number; end: number } | null }> | null
187
188
  characterClass: string | null
188
189
  /**
189
- * ISO 15924 scripts ranked by share of script-bearing characters.
190
+ * ISO 15924 scripts ranked by share of characters that belong to a script.
190
191
  */
191
192
  scripts: ReadonlyArray<{ script: string; share: number }> | null
192
193
  /**
@@ -212,7 +213,7 @@ export interface LocaleHint {
212
213
  /**
213
214
  * ISO 15924 scripts in the input, ranked by character share.
214
215
  *
215
- * The array is empty when the input has no script-bearing text.
216
+ * The array is empty when no character of the input belongs to a script.
216
217
  * `locale` stays a BCP-47 language tag.
217
218
  */
218
219
  script: ReadonlyArray<{ script: string; confidence: number }>
@@ -263,7 +264,7 @@ export type QueryKind = z.infer<typeof QueryKindSchema>
263
264
  */
264
265
  export const QueryIntentCode = {
265
266
  /**
266
- * Resolution found no decisive candidate for a place with a recognized name.
267
+ * Resolution found no single candidate that outranks the rest for a place with a recognized name.
267
268
  */
268
269
  DeclaredAmbiguity: "declared_ambiguity",
269
270
  /**
@@ -531,7 +532,112 @@ export interface FSTMatcherLike {
531
532
  prev: { stateID: number; depth: number },
532
533
  token: string
533
534
  ): { stateID: number; accepted: boolean; depth: number } | null
534
- accepting(stateID: number): Array<{ wofID: number; placetype: string; referential: number }>
535
+ accepting(stateID: number): Array<{ wofID: number; placetype: string; referential: number; name?: string }>
536
+ }
537
+
538
+ /**
539
+ * One admin ancestor an anchored postcode asserts.
540
+ */
541
+ export interface AnchorRegionAncestor {
542
+ /**
543
+ * The WOF placetype, such as `"region"`.
544
+ */
545
+ placetype: string
546
+ wofID: number
547
+ /**
548
+ * The place's name in the gazetteer, which the prior compares with the written surface.
549
+ */
550
+ name: string
551
+ }
552
+
553
+ /**
554
+ * The admin ancestry a postcode's anchor asserts, read by the anchor-region prior.
555
+ */
556
+ export interface AnchorRegionLookupLike {
557
+ /**
558
+ * Returns the ancestors the index asserts for `postcode` in `country`, coarsest first.
559
+ *
560
+ * The array is empty when no index covers the country or the index holds no unanimous
561
+ * answer for the postcode, as for a prefix whose units sit in two regions.
562
+ */
563
+ ancestorsFor(postcode: string, country: string): readonly AnchorRegionAncestor[]
564
+ }
565
+
566
+ /**
567
+ * Venue-head lookups for one country.
568
+ * Each method returns a bias in natural-log units or `null`.
569
+ */
570
+ export interface VenueHeadLexiconLike {
571
+ /**
572
+ * The bias of `word` as the first word of a venue name.
573
+ */
574
+ first(word: string): number | null
575
+ /**
576
+ * The bias of `word` as the last word of a venue name.
577
+ */
578
+ last(word: string): number | null
579
+ /**
580
+ * The bias of the longest suffix of `word`, shorter than `word`, that marks a venue name.
581
+ */
582
+ suffix(word: string): number | null
583
+ }
584
+
585
+ /**
586
+ * Overrides for the venue-head prior.
587
+ */
588
+ export interface VenueHeadPriorOpts {
589
+ /**
590
+ * Multiplier on the lexicon's bias.
591
+ *
592
+ * The prior's own default applies when this is absent.
593
+ */
594
+ biasScale?: number
595
+ /**
596
+ * Maximum bias, in logits, on any one cell.
597
+ *
598
+ * The table's biases are log rate ratios and seldom exceed 6.
599
+ * The cap bounds a scaled bias.
600
+ *
601
+ * @defaultValue `6`
602
+ */
603
+ maxBias?: number
604
+ /**
605
+ * The most words the venue span extends from its head.
606
+ *
607
+ * @defaultValue `3`
608
+ */
609
+ extensionWords?: number
610
+ /**
611
+ * Factor applied to the bias once for each word between a word and its head.
612
+ *
613
+ * The shipped model's venue logits trail the winning label by a near-constant margin
614
+ * across a landmark name's pieces, so the default extends the head's bias undiminished.
615
+ *
616
+ * @defaultValue `1`
617
+ */
618
+ extensionDecay?: number
619
+ /**
620
+ * Whether a word is a street-type affix, in `normalizeFSTToken` form.
621
+ *
622
+ * A head followed by one is a street name (`Museum Street`) and gets no bias,
623
+ * and an extension stops at one.
624
+ */
625
+ isStreetAffix?: (word: string) => boolean
626
+ /**
627
+ * Whether a segment's words, joined by single spaces in `normalizeFSTToken` form,
628
+ * are a country name, as `united states of america` is.
629
+ *
630
+ * No word of such a segment heads a venue, so `of America` keeps its country reading.
631
+ */
632
+ isCountryName?: (segment: string) => boolean
633
+ }
634
+
635
+ /**
636
+ * The venue-head lexicon a pipeline stage selects for one parse, with the prior's overrides.
637
+ */
638
+ export interface VenueHeadStage {
639
+ venueHead: VenueHeadLexiconLike
640
+ venueHeadOpts?: VenueHeadPriorOpts
535
641
  }
536
642
 
537
643
  /**
@@ -554,7 +660,30 @@ export interface ClassifierOpts {
554
660
  /**
555
661
  * Emission-prior weights for the street-morphology matcher.
556
662
  */
557
- fstStreetMorphologyOpts?: { biasScale?: number; dependentLocalityPenalty?: number }
663
+ fstStreetMorphologyOpts?: { biasScale?: number; dependentLocalityPenalty?: number; numberedSegmentOnly?: boolean }
664
+ /**
665
+ * The scale for positive street-context emissions.
666
+ */
667
+ fstStreetContextPositiveScale?: number
668
+ /**
669
+ * The admin ancestry of an anchored postcode, for the anchor-region prior.
670
+ *
671
+ * The prior raises an FST region match to the full bias when the postcode the anchor
672
+ * channel fired on asserts that region and the written name is the region's own name.
673
+ * It runs only with `fst` and the classifier's postcode anchor lookup.
674
+ */
675
+ anchorRegions?: AnchorRegionLookupLike
676
+ /**
677
+ * Venue-head lookups for the input's country.
678
+ *
679
+ * Their prior biases a venue head word and the words of its phrase toward `venue`.
680
+ * Absent, the prior does not run.
681
+ */
682
+ venueHead?: VenueHeadLexiconLike
683
+ /**
684
+ * Overrides for the venue-head prior's bias magnitudes and extension.
685
+ */
686
+ venueHeadOpts?: VenueHeadPriorOpts
558
687
  /**
559
688
  * Applies deterministic postcode repair after decoding.
560
689
  */
@@ -646,6 +775,24 @@ export interface RuntimePipelineStages {
646
775
  * The street-context check runs only when `fst` is also set.
647
776
  */
648
777
  streetMorphology?: FSTMatcherLike
778
+ /**
779
+ * Whether the street-morphology matcher also biases a street affix on a segment that
780
+ * opens with a house number, as `Plaza` in `30 Rockefeller Plaza, New York, NY 10112`.
781
+ *
782
+ * Absent, the matcher serves the street-context check at zero emission weight.
783
+ */
784
+ streetMorphologyPrior?: boolean
785
+ /**
786
+ * The admin ancestry of an anchored postcode, for the anchor-region prior.
787
+ * The prior runs only when `fst` is also set.
788
+ */
789
+ anchorRegions?: AnchorRegionLookupLike
790
+ /**
791
+ * The venue-head lexicon for the detected locale with the prior's overrides, or `null` for none.
792
+ *
793
+ * The pipeline calls it once per parse with the locale hint and passes both to the classifier.
794
+ */
795
+ venueHead?: (locale: LocaleHint) => VenueHeadStage | null
649
796
  resolver?: Resolver
650
797
  /**
651
798
  * The backend for resolver candidate and parent-chain lookups during reconciliation.