@mailwoman/core 9.1.0 → 9.2.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 (371) hide show
  1. package/README.md +1 -1
  2. package/api/responses.ts +12 -0
  3. package/coarse-placer/featurize.ts +0 -2
  4. package/coarse-placer/tools/build-dataset.ts +1 -1
  5. package/coarse-placer/tools/build-outlier-exposure.ts +1 -1
  6. package/coarse-placer/tools/build-outlier-latin.ts +13 -7
  7. package/coarse-placer/tools/build-outlier-oa.ts +11 -5
  8. package/coarse-placer/tools/eval-latin-offmap.ts +3 -2
  9. package/coarse-placer/tools/eval-openset.ts +3 -2
  10. package/coarse-placer/tools/eval-quant-compare.ts +3 -2
  11. package/coarse-placer/tools/eval.ts +3 -2
  12. package/coarse-placer/tools/fnv-hash.ts +1 -6
  13. package/coarse-placer/tools/index.ts +1 -1
  14. package/coarse-placer/tools/probe-frontier.ts +3 -2
  15. package/coarse-placer/tools/quantize.ts +2 -2
  16. package/coarse-placer/tools/train.ts +2 -1
  17. package/crypto/node.ts +3 -1
  18. package/data/internal/dictionaries/languages.csv +184 -184
  19. package/data/libpostal/README.md +8 -2
  20. package/db/schema.ts +12 -3
  21. package/decoder/containment.ts +5 -1
  22. package/decoder/index.ts +1 -0
  23. package/decoder/parse-diff.ts +347 -0
  24. package/decoder/proposals-to-tree.ts +1 -1
  25. package/decoder/serialize-json.ts +51 -7
  26. package/decoder/serialize-tuples.ts +7 -1
  27. package/decoder/serialize-xml.ts +1 -1
  28. package/decoder/tree-shape.ts +144 -0
  29. package/decoder/types.ts +8 -0
  30. package/decoder/validate-tree.ts +15 -3
  31. package/env/index.ts +3 -1
  32. package/env/paths.ts +21 -33
  33. package/env/schema.ts +26 -3
  34. package/fs/utils/formatters.ts +107 -0
  35. package/fs/utils/index.ts +7 -0
  36. package/fs/zip.ts +1 -1
  37. package/layers/manifest.ts +56 -15
  38. package/layers/schema.ts +54 -2
  39. package/locale/locale.ts +1 -1
  40. package/locale/registry.ts +1 -1
  41. package/objects.ts +20 -8
  42. package/out/api/responses.d.ts +9 -0
  43. package/out/api/responses.d.ts.map +1 -1
  44. package/out/api/responses.js +11 -0
  45. package/out/api/responses.js.map +1 -1
  46. package/out/coarse-placer/featurize.d.ts +0 -1
  47. package/out/coarse-placer/featurize.d.ts.map +1 -1
  48. package/out/coarse-placer/featurize.js.map +1 -1
  49. package/out/coarse-placer/tools/build-dataset.js +1 -1
  50. package/out/coarse-placer/tools/build-dataset.js.map +1 -1
  51. package/out/coarse-placer/tools/build-outlier-exposure.js +1 -1
  52. package/out/coarse-placer/tools/build-outlier-exposure.js.map +1 -1
  53. package/out/coarse-placer/tools/build-outlier-latin.d.ts.map +1 -1
  54. package/out/coarse-placer/tools/build-outlier-latin.js +12 -7
  55. package/out/coarse-placer/tools/build-outlier-latin.js.map +1 -1
  56. package/out/coarse-placer/tools/build-outlier-oa.d.ts.map +1 -1
  57. package/out/coarse-placer/tools/build-outlier-oa.js +10 -5
  58. package/out/coarse-placer/tools/build-outlier-oa.js.map +1 -1
  59. package/out/coarse-placer/tools/eval-latin-offmap.d.ts.map +1 -1
  60. package/out/coarse-placer/tools/eval-latin-offmap.js +2 -2
  61. package/out/coarse-placer/tools/eval-latin-offmap.js.map +1 -1
  62. package/out/coarse-placer/tools/eval-openset.d.ts.map +1 -1
  63. package/out/coarse-placer/tools/eval-openset.js +2 -2
  64. package/out/coarse-placer/tools/eval-openset.js.map +1 -1
  65. package/out/coarse-placer/tools/eval-quant-compare.d.ts.map +1 -1
  66. package/out/coarse-placer/tools/eval-quant-compare.js +2 -2
  67. package/out/coarse-placer/tools/eval-quant-compare.js.map +1 -1
  68. package/out/coarse-placer/tools/eval.d.ts.map +1 -1
  69. package/out/coarse-placer/tools/eval.js +2 -2
  70. package/out/coarse-placer/tools/eval.js.map +1 -1
  71. package/out/coarse-placer/tools/fnv-hash.d.ts +1 -6
  72. package/out/coarse-placer/tools/fnv-hash.d.ts.map +1 -1
  73. package/out/coarse-placer/tools/fnv-hash.js +1 -6
  74. package/out/coarse-placer/tools/fnv-hash.js.map +1 -1
  75. package/out/coarse-placer/tools/index.d.ts +1 -1
  76. package/out/coarse-placer/tools/index.js +1 -1
  77. package/out/coarse-placer/tools/probe-frontier.d.ts.map +1 -1
  78. package/out/coarse-placer/tools/probe-frontier.js +2 -2
  79. package/out/coarse-placer/tools/probe-frontier.js.map +1 -1
  80. package/out/coarse-placer/tools/quantize.js +2 -2
  81. package/out/coarse-placer/tools/quantize.js.map +1 -1
  82. package/out/coarse-placer/tools/train.d.ts.map +1 -1
  83. package/out/coarse-placer/tools/train.js +1 -1
  84. package/out/coarse-placer/tools/train.js.map +1 -1
  85. package/out/crypto/node.d.ts.map +1 -1
  86. package/out/crypto/node.js +2 -1
  87. package/out/crypto/node.js.map +1 -1
  88. package/out/db/schema.d.ts +12 -3
  89. package/out/db/schema.d.ts.map +1 -1
  90. package/out/db/schema.js +6 -0
  91. package/out/db/schema.js.map +1 -1
  92. package/out/decoder/containment.d.ts.map +1 -1
  93. package/out/decoder/containment.js +5 -1
  94. package/out/decoder/containment.js.map +1 -1
  95. package/out/decoder/index.d.ts +1 -0
  96. package/out/decoder/index.d.ts.map +1 -1
  97. package/out/decoder/index.js +1 -0
  98. package/out/decoder/index.js.map +1 -1
  99. package/out/decoder/parse-diff.d.ts +125 -0
  100. package/out/decoder/parse-diff.d.ts.map +1 -0
  101. package/out/decoder/parse-diff.js +219 -0
  102. package/out/decoder/parse-diff.js.map +1 -0
  103. package/out/decoder/proposals-to-tree.js.map +1 -1
  104. package/out/decoder/serialize-json.d.ts +29 -0
  105. package/out/decoder/serialize-json.d.ts.map +1 -1
  106. package/out/decoder/serialize-json.js +20 -4
  107. package/out/decoder/serialize-json.js.map +1 -1
  108. package/out/decoder/serialize-tuples.d.ts +8 -1
  109. package/out/decoder/serialize-tuples.d.ts.map +1 -1
  110. package/out/decoder/serialize-tuples.js +7 -1
  111. package/out/decoder/serialize-tuples.js.map +1 -1
  112. package/out/decoder/serialize-xml.js +1 -1
  113. package/out/decoder/serialize-xml.js.map +1 -1
  114. package/out/decoder/tree-shape.d.ts +84 -0
  115. package/out/decoder/tree-shape.d.ts.map +1 -0
  116. package/out/decoder/tree-shape.js +98 -0
  117. package/out/decoder/tree-shape.js.map +1 -0
  118. package/out/decoder/types.d.ts +11 -0
  119. package/out/decoder/types.d.ts.map +1 -1
  120. package/out/decoder/validate-tree.d.ts +8 -0
  121. package/out/decoder/validate-tree.d.ts.map +1 -1
  122. package/out/decoder/validate-tree.js +4 -3
  123. package/out/decoder/validate-tree.js.map +1 -1
  124. package/out/env/index.d.ts +10 -1
  125. package/out/env/index.d.ts.map +1 -1
  126. package/out/env/index.js +2 -1
  127. package/out/env/index.js.map +1 -1
  128. package/out/env/paths.d.ts +15 -8
  129. package/out/env/paths.d.ts.map +1 -1
  130. package/out/env/paths.js +19 -29
  131. package/out/env/paths.js.map +1 -1
  132. package/out/env/schema.d.ts +9 -1
  133. package/out/env/schema.d.ts.map +1 -1
  134. package/out/env/schema.js +25 -3
  135. package/out/env/schema.js.map +1 -1
  136. package/out/fs/utils/formatters.d.ts +57 -0
  137. package/out/fs/utils/formatters.d.ts.map +1 -0
  138. package/out/fs/utils/formatters.js +79 -0
  139. package/out/fs/utils/formatters.js.map +1 -0
  140. package/out/fs/utils/index.d.ts +7 -0
  141. package/out/fs/utils/index.d.ts.map +1 -0
  142. package/out/fs/utils/index.js +7 -0
  143. package/out/fs/utils/index.js.map +1 -0
  144. package/out/fs/zip.js +1 -1
  145. package/out/fs/zip.js.map +1 -1
  146. package/out/layers/manifest.d.ts +32 -7
  147. package/out/layers/manifest.d.ts.map +1 -1
  148. package/out/layers/manifest.js +31 -6
  149. package/out/layers/manifest.js.map +1 -1
  150. package/out/layers/schema.d.ts +48 -2
  151. package/out/layers/schema.d.ts.map +1 -1
  152. package/out/layers/schema.js +32 -0
  153. package/out/layers/schema.js.map +1 -1
  154. package/out/locale/locale.d.ts +1 -1
  155. package/out/locale/locale.d.ts.map +1 -1
  156. package/out/locale/registry.js +1 -1
  157. package/out/locale/registry.js.map +1 -1
  158. package/out/objects.d.ts +12 -6
  159. package/out/objects.d.ts.map +1 -1
  160. package/out/objects.js +4 -1
  161. package/out/objects.js.map +1 -1
  162. package/out/pipeline/index.d.ts +2 -6
  163. package/out/pipeline/index.d.ts.map +1 -1
  164. package/out/pipeline/index.js +1 -3
  165. package/out/pipeline/index.js.map +1 -1
  166. package/out/pipeline/runtime-pipeline.d.ts +51 -9
  167. package/out/pipeline/runtime-pipeline.d.ts.map +1 -1
  168. package/out/pipeline/runtime-pipeline.js +29 -132
  169. package/out/pipeline/runtime-pipeline.js.map +1 -1
  170. package/out/pipeline/span-proposer.js +1 -1
  171. package/out/pipeline/span-proposer.js.map +1 -1
  172. package/out/pipeline/types.d.ts +22 -14
  173. package/out/pipeline/types.d.ts.map +1 -1
  174. package/out/pipeline/types.js.map +1 -1
  175. package/out/policy/defaults.d.ts +1 -1
  176. package/out/policy/defaults.d.ts.map +1 -1
  177. package/out/policy/defaults.js +1 -1
  178. package/out/policy/defaults.js.map +1 -1
  179. package/out/policy/policy.d.ts +1 -1
  180. package/out/policy/policy.d.ts.map +1 -1
  181. package/out/policy/registry.d.ts +1 -1
  182. package/out/policy/registry.d.ts.map +1 -1
  183. package/out/resolver/coverage-facts.d.ts +89 -0
  184. package/out/resolver/coverage-facts.d.ts.map +1 -0
  185. package/out/resolver/coverage-facts.js +22 -0
  186. package/out/resolver/coverage-facts.js.map +1 -0
  187. package/out/resolver/index.d.ts +2 -1
  188. package/out/resolver/index.d.ts.map +1 -1
  189. package/out/resolver/index.js +1 -0
  190. package/out/resolver/index.js.map +1 -1
  191. package/out/resolver/lookup-types.d.ts +178 -0
  192. package/out/resolver/lookup-types.d.ts.map +1 -0
  193. package/out/resolver/lookup-types.js +11 -0
  194. package/out/resolver/lookup-types.js.map +1 -0
  195. package/out/resolver/placetype-map.d.ts +71 -0
  196. package/out/resolver/placetype-map.d.ts.map +1 -0
  197. package/out/resolver/placetype-map.js +98 -0
  198. package/out/resolver/placetype-map.js.map +1 -0
  199. package/out/resolver/postcode-format.d.ts +38 -0
  200. package/out/resolver/postcode-format.d.ts.map +1 -0
  201. package/out/resolver/postcode-format.js +83 -0
  202. package/out/resolver/postcode-format.js.map +1 -0
  203. package/out/resolver/types.d.ts +271 -297
  204. package/out/resolver/types.d.ts.map +1 -1
  205. package/out/resolver/types.js +4 -97
  206. package/out/resolver/types.js.map +1 -1
  207. package/out/resources/git.d.ts +8 -1
  208. package/out/resources/git.d.ts.map +1 -1
  209. package/out/resources/git.js +4 -3
  210. package/out/resources/git.js.map +1 -1
  211. package/out/resources/languages/types.gen.d.ts +1 -1
  212. package/out/resources/languages/types.gen.d.ts.map +1 -1
  213. package/out/resources/languages/types.gen.js +40 -0
  214. package/out/resources/languages/types.gen.js.map +1 -1
  215. package/out/resources/libpostal.d.ts +2 -2
  216. package/out/resources/libpostal.d.ts.map +1 -1
  217. package/out/resources/libpostal.js +2 -2
  218. package/out/resources/libpostal.js.map +1 -1
  219. package/out/resources/whosonfirst/DataSourceCache.d.ts.map +1 -1
  220. package/out/resources/whosonfirst/DataSourceCache.js.map +1 -1
  221. package/out/resources/whosonfirst/PlacetypeDataSource.d.ts +2 -2
  222. package/out/resources/whosonfirst/PlacetypeDataSource.d.ts.map +1 -1
  223. package/out/resources/whosonfirst/PlacetypeDataSource.js +28 -3
  224. package/out/resources/whosonfirst/PlacetypeDataSource.js.map +1 -1
  225. package/out/resources/whosonfirst/loader.d.ts +2 -2
  226. package/out/resources/whosonfirst/loader.d.ts.map +1 -1
  227. package/out/resources/whosonfirst/loader.js.map +1 -1
  228. package/out/resources/whosonfirst/placetypes/Placetype.d.ts.map +1 -1
  229. package/out/resources/whosonfirst/placetypes/Placetype.js +2 -2
  230. package/out/resources/whosonfirst/placetypes/Placetype.js.map +1 -1
  231. package/out/resources/whosonfirst/placetypes/admin.d.ts +9 -1
  232. package/out/resources/whosonfirst/placetypes/admin.d.ts.map +1 -1
  233. package/out/resources/whosonfirst/placetypes/admin.js +1 -1
  234. package/out/resources/whosonfirst/placetypes/admin.js.map +1 -1
  235. package/out/resources/whosonfirst/placetypes/definition.d.ts.map +1 -1
  236. package/out/resources/whosonfirst/placetypes/definition.js +1 -1
  237. package/out/resources/whosonfirst/placetypes/definition.js.map +1 -1
  238. package/out/resources/whosonfirst/placetypes/index.d.ts +1 -0
  239. package/out/resources/whosonfirst/placetypes/index.d.ts.map +1 -1
  240. package/out/resources/whosonfirst/placetypes/index.js +1 -0
  241. package/out/resources/whosonfirst/placetypes/index.js.map +1 -1
  242. package/out/resources/whosonfirst/placetypes/specificity.d.ts +65 -0
  243. package/out/resources/whosonfirst/placetypes/specificity.d.ts.map +1 -0
  244. package/out/resources/whosonfirst/placetypes/specificity.js +101 -0
  245. package/out/resources/whosonfirst/placetypes/specificity.js.map +1 -0
  246. package/out/resources/whosonfirst/sharded-repo.d.ts +28 -0
  247. package/out/resources/whosonfirst/sharded-repo.d.ts.map +1 -1
  248. package/out/resources/whosonfirst/sharded-repo.js +46 -2
  249. package/out/resources/whosonfirst/sharded-repo.js.map +1 -1
  250. package/out/scripting/arguments.d.ts +27 -0
  251. package/out/scripting/arguments.d.ts.map +1 -0
  252. package/out/scripting/arguments.js +32 -0
  253. package/out/scripting/arguments.js.map +1 -0
  254. package/out/scripting/command.d.ts +28 -0
  255. package/out/scripting/command.d.ts.map +1 -0
  256. package/out/scripting/command.js +47 -0
  257. package/out/scripting/command.js.map +1 -0
  258. package/out/scripting/index.js +3 -3
  259. package/out/scripting/index.js.map +1 -1
  260. package/out/scripting/utils/index.d.ts +1 -12
  261. package/out/scripting/utils/index.d.ts.map +1 -1
  262. package/out/scripting/utils/index.js +4 -21
  263. package/out/scripting/utils/index.js.map +1 -1
  264. package/out/tools/download-libpostal-resources.d.ts.map +1 -1
  265. package/out/tools/download-libpostal-resources.js +4 -7
  266. package/out/tools/download-libpostal-resources.js.map +1 -1
  267. package/out/tools/download-ssl-address.d.ts +3 -3
  268. package/out/tools/download-ssl-address.d.ts.map +1 -1
  269. package/out/tools/download-ssl-address.js +26 -13
  270. package/out/tools/download-ssl-address.js.map +1 -1
  271. package/out/tools/generate-language-types.d.ts +16 -1
  272. package/out/tools/generate-language-types.d.ts.map +1 -1
  273. package/out/tools/generate-language-types.js +38 -5
  274. package/out/tools/generate-language-types.js.map +1 -1
  275. package/out/tools/index.d.ts +1 -2
  276. package/out/tools/index.d.ts.map +1 -1
  277. package/out/tools/index.js +1 -2
  278. package/out/tools/index.js.map +1 -1
  279. package/out/utils/data-root.d.ts +27 -7
  280. package/out/utils/data-root.d.ts.map +1 -1
  281. package/out/utils/data-root.js +36 -13
  282. package/out/utils/data-root.js.map +1 -1
  283. package/out/utils/hash.d.ts +2 -3
  284. package/out/utils/hash.d.ts.map +1 -1
  285. package/out/utils/hash.js +3 -3
  286. package/out/utils/hash.js.map +1 -1
  287. package/out/utils/index.d.ts +1 -0
  288. package/out/utils/index.d.ts.map +1 -1
  289. package/out/utils/index.js +1 -0
  290. package/out/utils/index.js.map +1 -1
  291. package/out/utils/jsonl.js +1 -1
  292. package/out/utils/jsonl.js.map +1 -1
  293. package/out/utils/repo.d.ts +8 -0
  294. package/out/utils/repo.d.ts.map +1 -1
  295. package/out/utils/repo.js +10 -1
  296. package/out/utils/repo.js.map +1 -1
  297. package/out/utils/sealed-db.d.ts +11 -0
  298. package/out/utils/sealed-db.d.ts.map +1 -1
  299. package/out/utils/sealed-db.js +28 -1
  300. package/out/utils/sealed-db.js.map +1 -1
  301. package/out/utils/sqlite-rows.d.ts +34 -0
  302. package/out/utils/sqlite-rows.d.ts.map +1 -0
  303. package/out/utils/sqlite-rows.js +37 -0
  304. package/out/utils/sqlite-rows.js.map +1 -0
  305. package/out/utils/stats.d.ts +1 -6
  306. package/out/utils/stats.d.ts.map +1 -1
  307. package/out/utils/stats.js +1 -6
  308. package/out/utils/stats.js.map +1 -1
  309. package/package.json +476 -7
  310. package/pipeline/index.ts +12 -14
  311. package/pipeline/runtime-pipeline.ts +29 -183
  312. package/pipeline/span-proposer.ts +1 -1
  313. package/pipeline/types.ts +26 -15
  314. package/policy/defaults.ts +1 -1
  315. package/policy/policy.ts +1 -1
  316. package/policy/registry.ts +1 -1
  317. package/resolver/coverage-facts.ts +102 -0
  318. package/resolver/index.ts +5 -0
  319. package/resolver/lookup-types.ts +174 -0
  320. package/resolver/placetype-map.ts +122 -0
  321. package/resolver/postcode-format.ts +89 -0
  322. package/resolver/types.ts +293 -351
  323. package/resources/git.ts +18 -4
  324. package/resources/languages/types.gen.ts +60 -0
  325. package/resources/libpostal.ts +4 -3
  326. package/resources/whosonfirst/DataSourceCache.ts +2 -1
  327. package/resources/whosonfirst/PlacetypeDataSource.ts +36 -11
  328. package/resources/whosonfirst/loader.ts +3 -2
  329. package/resources/whosonfirst/placetypes/Placetype.ts +3 -2
  330. package/resources/whosonfirst/placetypes/admin.ts +11 -2
  331. package/resources/whosonfirst/placetypes/definition.ts +4 -3
  332. package/resources/whosonfirst/placetypes/index.ts +1 -0
  333. package/resources/whosonfirst/placetypes/specificity.ts +114 -0
  334. package/resources/whosonfirst/sharded-repo.ts +55 -2
  335. package/scripting/arguments.ts +38 -0
  336. package/scripting/command.ts +55 -0
  337. package/scripting/index.ts +3 -3
  338. package/scripting/utils/index.ts +6 -23
  339. package/tools/download-libpostal-resources.ts +4 -7
  340. package/tools/download-ssl-address.ts +28 -12
  341. package/tools/generate-language-types.ts +39 -5
  342. package/tools/index.ts +1 -2
  343. package/utils/data-root.ts +40 -14
  344. package/utils/hash.ts +5 -4
  345. package/utils/index.ts +1 -0
  346. package/utils/jsonl.ts +1 -1
  347. package/utils/repo.ts +12 -1
  348. package/utils/sealed-db.ts +30 -1
  349. package/utils/sqlite-rows.ts +40 -0
  350. package/utils/stats.ts +1 -6
  351. package/data/libpostal/dictionaries/all/chains.txt +0 -504
  352. package/kysley/adapter.ts +0 -29
  353. package/out/kysley/adapter.d.ts +0 -13
  354. package/out/kysley/adapter.d.ts.map +0 -1
  355. package/out/kysley/adapter.js +0 -25
  356. package/out/kysley/adapter.js.map +0 -1
  357. package/out/pipeline/reconcile-lookups.d.ts +0 -39
  358. package/out/pipeline/reconcile-lookups.d.ts.map +0 -1
  359. package/out/pipeline/reconcile-lookups.js +0 -88
  360. package/out/pipeline/reconcile-lookups.js.map +0 -1
  361. package/out/pipeline/reconcile.d.ts +0 -153
  362. package/out/pipeline/reconcile.d.ts.map +0 -1
  363. package/out/pipeline/reconcile.js +0 -388
  364. package/out/pipeline/reconcile.js.map +0 -1
  365. package/out/pipeline/span-logit-aggregation.d.ts +0 -58
  366. package/out/pipeline/span-logit-aggregation.d.ts.map +0 -1
  367. package/out/pipeline/span-logit-aggregation.js +0 -117
  368. package/out/pipeline/span-logit-aggregation.js.map +0 -1
  369. package/pipeline/reconcile-lookups.ts +0 -111
  370. package/pipeline/reconcile.ts +0 -583
  371. package/pipeline/span-logit-aggregation.ts +0 -156
package/resolver/types.ts CHANGED
@@ -11,9 +11,43 @@
11
11
  * `RemoteResolver` adapter (Phase 4.4 — Pelias / BAN / Nominatim) without a public-API break.
12
12
  *
13
13
  * See `docs/plan/phases/PHASE_4_3_resolver_integration.md` for the design intent.
14
+ *
15
+ * This module is a published subpath (`@mailwoman/core/resolver/types`) with a wide consumer set, so the
16
+ * groups that moved to siblings are re-exported here rather than requiring every importer to move with them.
14
17
  */
15
18
 
16
- import type { AddressTree, ComponentTag } from "../decoder/types.ts"
19
+ import type { AddressTree } from "../decoder/types.ts"
20
+ import type { GazetteerArtifactCoverage } from "./coverage-facts.ts"
21
+ import type {
22
+ AddressPointLookup,
23
+ InterpolationLookup,
24
+ PostcodePrefixIndexLike,
25
+ StreetCentroidLookup,
26
+ } from "./lookup-types.ts"
27
+ import type { PlacetypeMap } from "./placetype-map.ts"
28
+
29
+ export type { CountryBBoxFact, CountryCoverageFact, GazetteerArtifactCoverage } from "./coverage-facts.ts"
30
+ export { hardCountrySafelistFromCoverage } from "./coverage-facts.ts"
31
+
32
+ export type {
33
+ AddressPointHit,
34
+ AddressPointLookup,
35
+ InterpolatedPointHit,
36
+ InterpolationLookup,
37
+ PostcodePrefixAncestor,
38
+ PostcodePrefixIndexLike,
39
+ PostcodePrefixNode,
40
+ StreetCentroidHit,
41
+ StreetCentroidLookup,
42
+ } from "./lookup-types.ts"
43
+
44
+ export {
45
+ DEFAULT_PLACETYPE_MAP,
46
+ expandPlacetypeFilter,
47
+ isPlacetypeFallback,
48
+ PLACETYPE_FILTER_GROUPS,
49
+ type PlacetypeMap,
50
+ } from "./placetype-map.ts"
17
51
 
18
52
  /**
19
53
  * One candidate place returned by a resolver. Mirrors the shape used by `@mailwoman/core/resolver-wof-sqlite`'s
@@ -65,6 +99,12 @@ export interface ResolvedPlace {
65
99
  * to score-based ordering.
66
100
  */
67
101
  prominence?: number
102
+ /**
103
+ * Raw population from the backend's record, when carried (`PlaceCandidate.population` mirrors it). Absent means
104
+ * UNKNOWN, never zero — the meaning-of-zero rule. The bare-toponym race's region-dominance rule reads this because
105
+ * {@link ResolvedPlace.prominence} saturates at the backend's population cap and erases the margins it needs.
106
+ */
107
+ population?: number
68
108
  /**
69
109
  * REFERENTIAL likelihood in [0, 1] — population-anchored, the named form of the key namesake ranking has always used
70
110
  * (ROAD_TO_V9 §2, ratified 2026-08-06: "the importance of a knowledge-base article is not the probability that this
@@ -123,6 +163,23 @@ export interface ResolvedPlace {
123
163
  * Absent when the exact placetype matched (the normal case).
124
164
  */
125
165
  resolutionQuality?: "fallback"
166
+ /**
167
+ * The admin-containment verdict for this candidate (#1717 stage 2) — TRI-STATE, and the absence is load-bearing
168
+ * (meaning-of-zero): `true` = the backend's ancestors sidecar vouches that this candidate sits UNDER the query's
169
+ * parsed region qualifier; `false` = the backend evaluated containment and could not vouch for it; `undefined` = the
170
+ * question was never asked — the lever is off, the query carried no qualifier, or the backend/artifact cannot answer
171
+ * (no sidecar). Set only by backends implementing `FindPlaceQuery.regionQualifier`; consumed by the resolver walk's
172
+ * `adminContainmentRerank` partition, which must never read `undefined` as "not contained".
173
+ */
174
+ containedByQualifier?: boolean
175
+ /**
176
+ * #1731: `true` when a `parentID` region scope was applied, MISSED across the whole probe cascade, and the backend's
177
+ * unscoped fallback produced this row — the re-admission path where a wrong-instance namesake enters (the Astoria
178
+ * class: no locality-group row exists under the parent, so the fallback answers population-first from anywhere).
179
+ * Absent when the question never arose (no parent scope, or the scoped probe answered). Backend-optional; the
180
+ * resolver-interior trace (#1721) surfaces it as a gate.
181
+ */
182
+ regionScopeMiss?: boolean
126
183
  }
127
184
 
128
185
  /**
@@ -132,104 +189,18 @@ export interface ResolvedPlace {
132
189
  * Structurally compatible with `PlaceLookup` from `@mailwoman/core/resolver-wof-sqlite` so the latter satisfies this
133
190
  * interface without an adapter shim.
134
191
  */
135
- /**
136
- * One country's measured hard-filter coverage fact, as recorded at a promote gate. Facts about the gazetteer artifact
137
- * live IN the artifact (the `country_coverage` table the gazetteer build emits) — code constants are only the fallback
138
- * for artifacts that predate the manifest.
139
- *
140
- * Meaning-of-zero discipline: a country ABSENT from the coverage map was never measured — never "measured and failed".
141
- * A measured-and-failed country is PRESENT with `hardFilterSafe: false` (e.g. FI at 69.5% hard-resolve), so the
142
- * negative result is a first-class record, distinguishable from ignorance.
143
- */
144
- export interface CountryCoverageFact {
145
- /**
146
- * ISO 3166-1 alpha-2, uppercase.
147
- */
148
- country: string
149
- /**
150
- * The promote-gate VERDICT: hard-filtering this country is a pure win (a hard-filter miss is almost always a genuine
151
- * non-match, not a coverage gap). Stored as a verdict — not re-derived from `hardResolveRate` at read time — because
152
- * the gate is a judgment over a panel, not a pure rate function (CA cleared at the #928 promote on the
153
- * postcode-format-prior rationale despite a sub-95% panel resolve rate).
154
- */
155
- hardFilterSafe: boolean
156
- /**
157
- * Measured hard-resolve rate (0..1) on the panel named in `source`, when the receipt recorded one.
158
- */
159
- hardResolveRate?: number
160
- /**
161
- * Panel size behind `hardResolveRate`, when recorded.
162
- */
163
- sampleSize?: number
164
- /**
165
- * ISO-8601 date of the measurement / promote gate.
166
- */
167
- measuredAt: string
168
- /**
169
- * The receipt: which panel/gate produced this row (issue + date, human-readable).
170
- */
171
- source: string
172
- }
173
-
174
- /**
175
- * One country's coarse guard-B bounding box, as carried by the gazetteer artifact's `country_bbox` table.
176
- */
177
- export interface CountryBBoxFact {
178
- /**
179
- * ISO 3166-1 alpha-2, uppercase.
180
- */
181
- country: string
182
- latMin: number
183
- latMax: number
184
- lonMin: number
185
- lonMax: number
186
- /**
187
- * Provenance of the box (harness + date).
188
- */
189
- source: string
190
- }
191
-
192
- /**
193
- * Facts a loaded gazetteer artifact declares about itself — read from the artifact's own manifest tables at open time,
194
- * carried on the {@link ResolverBackend}/{@link Resolver} handle so consumers read the facts from the artifact they are
195
- * actually resolving against. `undefined` on the handle = the artifact predates the manifest → consumers fall back to
196
- * the code constants (byte-identical legacy behavior).
197
- */
198
- export interface GazetteerArtifactCoverage {
199
- /**
200
- * Country → measured coverage fact. ABSENCE = never measured (meaning-of-zero), never "failed".
201
- */
202
- countryCoverage: ReadonlyMap<string, CountryCoverageFact>
203
- /**
204
- * Country → guard-B bbox. ABSENCE = no box → the plausibility guard fails open for that country.
205
- */
206
- countryBBoxes: ReadonlyMap<string, CountryBBoxFact>
207
- /**
208
- * Derived at load: the countries whose fact says `hardFilterSafe` — the artifact's hard-country safelist.
209
- */
210
- hardCountrySafelist: ReadonlySet<string>
211
- }
212
-
213
- /**
214
- * Derive the hard-country safelist from coverage facts — the ONE derivation both the reader and the build share.
215
- */
216
- export function hardCountrySafelistFromCoverage(facts: Iterable<CountryCoverageFact>): ReadonlySet<string> {
217
- const out = new Set<string>()
218
-
219
- for (const fact of facts) {
220
- if (fact.hardFilterSafe) {
221
- out.add(fact.country.toUpperCase())
222
- }
223
- }
224
-
225
- return out
226
- }
227
192
 
228
193
  export interface ResolverBackend {
229
194
  findPlace(query: {
230
195
  text: string
231
196
  placetype?: string | string[]
232
197
  country?: string
198
+ /**
199
+ * ISO-3166 alpha-2 scoping the TYPO-FUZZY tier only (#1585): exact and qualifier-strip probes stay worldwide, the
200
+ * corrected-key probes honor it, and a scoped-empty fuzzy ABSTAINS instead of falling through to a world-fuzzy
201
+ * candidate. Backends without a fuzzy tier ignore it. Ignored when `country` is set (already narrower).
202
+ */
203
+ fuzzyCountry?: string
233
204
  parentID?: number | string
234
205
  /**
235
206
  * Sibling postcode string, when the address carries one. A coordinate-first backend uses it to inject
@@ -248,6 +219,32 @@ export interface ResolverBackend {
248
219
  * Proximity-bias points — a SOFT prominence re-rank; backends without support ignore it.
249
220
  */
250
221
  bias?: Array<{ lat: number; lon: number; weight?: number }>
222
+ /**
223
+ * Restrict name matching to PRIMARY-keyed rows — set by probes whose query surface is a RE-READING (a token cut out
224
+ * of a longer classified span) rather than a naming. The #1626 rationale, generalized: `Savile Row`'s token `Row`
225
+ * never named Rhu's historical alias, so the alias tier must not answer it; a whole-input bare toponym DID name
226
+ * whatever it matches (Москва's exonym rows included) and keeps the alias tier. Backends without a primary flag
227
+ * ignore it.
228
+ */
229
+ primaryOnly?: boolean
230
+ /**
231
+ * Alias-row NAME ROLES the probe refuses to answer through (#1730) — set by the bare-toponym side races with
232
+ * `abbr`/`gloss`. A lone bare token matching only an abbreviation row ("Tó" folded onto Toledo's "TO") or a
233
+ * translation-gloss row is a weak re-reading, not a naming; role-NULL alias rows (the exonym tier, the country
234
+ * display names) stay fully open, which is what `primaryOnly` could never express. Backends without a role column
235
+ * ignore it — an older artifact degrades to today's behavior.
236
+ */
237
+ excludeNameRoles?: readonly string[]
238
+ /**
239
+ * The tree's parsed REGION qualifier, verbatim (#1717 stage 2) — set by the resolver on locality lookups when
240
+ * `ResolveOpts.adminContainmentRerank` is on. A capable backend resolves the qualifier to its own region-class rows
241
+ * and (a) stamps every returned candidate's `containedByQualifier`, (b) ranks contained candidates ahead of
242
+ * uncontained ones, and (c) may ADD contained same-name candidates its other filters (a locale-inferred country
243
+ * scope) would have hidden — additive only, never a filter, so a qualifier that matches nothing changes nothing.
244
+ * Backends without a containment source ignore it (candidates then carry no stamp, which the walk reports as
245
+ * `unavailable`).
246
+ */
247
+ regionQualifier?: string
251
248
  limit?: number
252
249
  }): Promise<ResolvedPlace[]>
253
250
  /**
@@ -271,6 +268,36 @@ export interface ResolverBackend {
271
268
  artifactCoverage?: GazetteerArtifactCoverage
272
269
  }
273
270
 
271
+ /**
272
+ * An optional {@link ResolverBackend} method the loaded backend does not implement, and what that costs.
273
+ *
274
+ * Optional methods let a backend be valid while omitting a capability — but the options they serve can still default to
275
+ * ON, in which case the feature reports success and does nothing. This type carries the absence as data so a caller can
276
+ * read it instead of inferring it from a result that looks complete.
277
+ */
278
+ export interface BackendCapabilityGap {
279
+ /**
280
+ * The absent method, named as it appears on {@link ResolverBackend}.
281
+ */
282
+ capability: "ancestors" | "coincidentLocalitiesFor"
283
+ /**
284
+ * The {@link ResolveOpts} field whose behavior the absence removes.
285
+ */
286
+ gates: keyof ResolveOpts
287
+ /**
288
+ * Whether `gates` is on unless a caller turns it off — the difference between a silent loss and a chosen one.
289
+ */
290
+ defaultOn: boolean
291
+ /**
292
+ * What stops working, in terms of the answer rather than the call.
293
+ */
294
+ degrades: string
295
+ /**
296
+ * The backend's class name, so a log line identifies which artifact is loaded.
297
+ */
298
+ backend: string
299
+ }
300
+
274
301
  /**
275
302
  * One link in a resolved place's containment lineage ({@link ResolverBackend.ancestors}, #404).
276
303
  */
@@ -302,155 +329,6 @@ export interface CoincidentLocality extends ResolvedPlace {
302
329
  /**
303
330
  * Options for `resolveTree`. All optional with sensible defaults.
304
331
  */
305
- /**
306
- * One exact address-point hit (#476): a real situs coordinate for `(street, number)` within a postcode/locality scope —
307
- * the street-level tier in front of admin-centroid resolution.
308
- */
309
- export interface AddressPointHit {
310
- lat: number
311
- lon: number
312
- /**
313
- * Provenance, e.g. `"overture:NAD"`.
314
- */
315
- source: string
316
- /**
317
- * Pinned data release the point came from, e.g. `"2026-05-20.0"`.
318
- */
319
- release: string
320
- }
321
-
322
- /**
323
- * Street-level exact-point lookup (#476). Implementations own their normalization — both the shard build and this
324
- * lookup must apply the SAME normalizer (see `resolver-wof-sqlite/street-normalize.ts`). Core depends only on this
325
- * contract.
326
- */
327
- export interface AddressPointLookup {
328
- find(query: {
329
- street: string
330
- number: string
331
- postcode?: string
332
- locality?: string
333
- /**
334
- * Optional bbox scope (`minLat`/`maxLat`/`minLon`/`maxLon`), tried AFTER postcode/locality. For shards whose points
335
- * carry no postcode/locality of their own (OSM addr nodes often don't) but DO carry a coordinate — the resolved
336
- * locality's bounding box scopes the `(street, number)` probe instead. US situs never passes it (byte-stable).
337
- */
338
- bbox?: { minLat: number; maxLat: number; minLon: number; maxLon: number }
339
- }): AddressPointHit | null
340
- }
341
-
342
- /**
343
- * One interpolated coordinate estimate (#483) — NEVER an exact situs point (`uncertaintyM` prices the estimate
344
- * honestly). Structural mirror of `InterpolatedHit` in `resolver-wof-sqlite/interpolation.ts`; keep this a SUBSET of
345
- * that shape so the concrete `StreetInterpolator`/`AddressPointInterpolator` satisfy {@link InterpolationLookup} with no
346
- * adapter (the {@link AddressPointHit} precedent).
347
- */
348
- export interface InterpolatedPointHit {
349
- lat: number
350
- lon: number
351
- interpolated: true
352
- /**
353
- * `address_point` = bracketed between real neighbor points; `tiger_range` = linear within a segment range.
354
- */
355
- method: "address_point" | "tiger_range"
356
- /**
357
- * False when only the opposite side's range contained the number (right block, wrong side).
358
- */
359
- parityMatched?: boolean
360
- /**
361
- * `both` = neighbors bracketed it; `single` = one-sided extrapolation (larger uncertainty).
362
- */
363
- bracket?: "both" | "single"
364
- /**
365
- * Honest uncertainty radius in METERS (half the matched segment length).
366
- */
367
- uncertaintyM: number
368
- source: string
369
- release: string
370
- }
371
-
372
- /**
373
- * House-number interpolation lookup (#483). Like {@link AddressPointLookup}, implementations own their normalization
374
- * (the shared `resolver-wof-sqlite/street-normalize.ts`); core depends only on this contract. Postcode-scoped (no
375
- * locality field) — the tier abstains statewide without a postcode.
376
- */
377
- export interface InterpolationLookup {
378
- find(query: { street: string; number: string; postcode?: string }): InterpolatedPointHit | null
379
- /**
380
- * The ARTIFACT's own conformal radius multiplier for `uncertaintyM` (#374), read from the shard's
381
- * `interp_calibration` metadata table at open time (the pair-index δ/transitionBeta header precedent): the multiplier
382
- * is a property of the calibration set the artifact was built against, so it ships in the artifact, not in caller
383
- * code. The resolver applies it as the DEFAULT whenever `ResolveOpts.interpolationRadiusCalibration` is absent.
384
- * `undefined` (or an implementation without the property) = the artifact carries none — shards built before the
385
- * metadata table existed; behavior is then exactly the pre-artifact ladder (caller-supplied factor or raw).
386
- * Implementations must read this at OPEN time (constructor/factory), never per-lookup — `find()` is synchronous by
387
- * design.
388
- */
389
- readonly radiusCalibration?: number
390
- }
391
-
392
- /**
393
- * One street-CENTROID hit (#1042) — the street-level tier BELOW the exact address-point tier and ABOVE admin-centroid
394
- * resolution. A street's centroid + an honest extent-derived radius, for a street-only query (no house number) that an
395
- * address-point tier cannot serve by definition. Derived from a national register's rooftop points
396
- * (`street-centroids-<cc>.db`, a `GROUP BY street` roll-up). `uncertaintyM` prices the coarseness (half the street's
397
- * bbox diagonal) so a consumer never mistakes it for a rooftop.
398
- */
399
- export interface StreetCentroidHit {
400
- lat: number
401
- lon: number
402
- /**
403
- * Honest coarse radius in METERS — half the street's bounding-box diagonal.
404
- */
405
- uncertaintyM: number
406
- source: string
407
- release: string
408
- }
409
-
410
- /**
411
- * Street-centroid lookup (#1042). Like {@link AddressPointLookup}, implementations own their normalization (the shared
412
- * `resolver-wof-sqlite/street-normalize.ts`); core depends only on this contract. Scoped by `postcode` (preferred) or
413
- * `locality` (the base commune) — NO house number: this is the street-only tier.
414
- */
415
- export interface StreetCentroidLookup {
416
- find(query: { street: string; postcode?: string; locality?: string }): StreetCentroidHit | null
417
- }
418
-
419
- /**
420
- * One admin-ancestry entry a PFX1 node asserts (coarsest-first: country → constituent country → district).
421
- */
422
- export interface PostcodePrefixAncestor {
423
- placetype: string
424
- wofID: number
425
- name: string
426
- }
427
-
428
- /**
429
- * A PFX1 postcode-prefix node — the partial-code prior's payload ({@link ResolveOpts.postcodePrefixPrior}, #31
430
- * Mechanism 3). The coordinate is OPTIONAL and its absence is meaningful: an ancestry-only tier (NI's 80 BT districts)
431
- * carries `ancestors` and no `lat`/`lon` — representable as absence, never as `0,0` (the meaning-of-zero rule).
432
- * `radiusP95Km` is mandatory whenever a coordinate is present (M-3's receipt: a 1-digit US band and a GB outward code
433
- * are both "a prefix with a centroid" and differ by 200×).
434
- */
435
- export interface PostcodePrefixNode {
436
- prefix: string
437
- ancestors: readonly PostcodePrefixAncestor[]
438
- lat?: number
439
- lon?: number
440
- radiusP95Km?: number
441
- unitCount: number
442
- }
443
-
444
- /**
445
- * The PFX1 index the resolver probes — minimal, structural (`probe` + optional `country`), so `@mailwoman/resolver`
446
- * consumes an index built in `@mailwoman/neural` without depending on it (B3-5: the partial-code prior touches zero
447
- * model inputs). `country` is the ISO-3166 alpha-2 the index was built for (upper-case); the resolver only probes an
448
- * index whose country matches the query's country scope.
449
- */
450
- export interface PostcodePrefixIndexLike {
451
- probe(prefix: string): PostcodePrefixNode | null
452
- readonly country?: string
453
- }
454
332
 
455
333
  export interface ResolveOpts {
456
334
  /**
@@ -476,6 +354,23 @@ export interface ResolveOpts {
476
354
  * overrides it deeper in the tree.
477
355
  */
478
356
  defaultCountry?: string
357
+ /**
358
+ * True when {@link defaultCountry} was INFERRED from the locale rather than user-declared. A `country`-placetype
359
+ * lookup under an inferred scope is a self-contradiction — the query names a country outright, and the filter can
360
+ * only admit the scope country itself (bare `Germany` under the default en-US locale filtered out the DE row and fell
361
+ * through to a US locality whose historical alias is "Germany, Ohio"). The resolver therefore withholds an inferred
362
+ * {@link defaultCountry} from `country`-placetype lookups only; an EXPLICIT scope stays supreme (the #912 posture), as
363
+ * do parent evidence and the confident placer.
364
+ */
365
+ defaultCountryIsInferred?: boolean
366
+ /**
367
+ * #1585 — the locale hint's country, scoping the backend's TYPO-FUZZY tier only. Unlike {@link defaultCountry} this
368
+ * is threaded even where the bare-toponym guard withholds the hard scope: an exact foreign match still resolves
369
+ * (`Paris` under en-US), but a typo CORRECTION stays inside the hinted country, and a scoped-empty correction
370
+ * abstains rather than falling through to a world-fuzzy candidate (`Stanmore Bay` under en-NZ must not answer Banmore
371
+ * IN). Never a country filter on exact matches — the fuzzy tier is the only consumer.
372
+ */
373
+ fuzzyCountryScope?: string
479
374
  /**
480
375
  * Ordered proximity-bias points (viewport center first, then user location, …), each optionally weighted (default
481
376
  * 1.0). SOFT ranking signal only — candidates near a bias point win prominence ties (the ambiguous-postcode case:
@@ -551,6 +446,13 @@ export interface ResolveOpts {
551
446
  * consulted when `localeCountryPrior` is set.
552
447
  */
553
448
  localeCountryPriorWeight?: number
449
+ /**
450
+ * #1880 — capital status of a candidate (2 national capital, 1 admin-1 seat, 0 neither), answered by the caller's
451
+ * reference against the candidate's own name + country + coordinates. Consumed by the resolver's bounded capital
452
+ * promotion (`resolver/toponym-prior.ts` — the bare-toponym class only, after the fame key). Structural rather than a
453
+ * named import because this package must not depend on the reference's home. Undefined → no promotion, byte-stable.
454
+ */
455
+ capitalLevel?: (place: { name: string; country?: string; lat: number; lon: number }) => number
554
456
  /**
555
457
  * #743/#194 — a CONFIDENT coarse-placer country applied as a HARD candidate filter (`query.country`), not the soft
556
458
  * {@link anchorPosterior} boost. This collapses the off-continent tail for LOW-population places the soft prior can't
@@ -785,6 +687,14 @@ export interface ResolveOpts {
785
687
  * structural type (`PostcodePrefixIndexLike`), injected, never imported from `@mailwoman/neural`.
786
688
  */
787
689
  postcodePrefixPrior?: boolean
690
+ /**
691
+ * #1589 — countries the parsed postcode's FORMAT implies (the #928 unforgeable singles plus the shared `NNN NN`
692
+ * CZ/SK/SE/GR family). Applied by the `postalcode` lookup ONLY when no country constraint survives (an explicit
693
+ * `defaultCountry` outranks format evidence, which outranks a locale hint): the lookup probes exactly the implied
694
+ * countries, keeps the most populous hit, and abstains when all miss rather than falling through to a fold-colliding
695
+ * unconstrained probe.
696
+ */
697
+ postcodeFormatCountries?: readonly string[]
788
698
  /**
789
699
  * The PFX1 postcode-prefix index to probe when {@link postcodePrefixPrior} is on — injected by the pipeline (loaded
790
700
  * from `$MAILWOMAN_DATA_ROOT/postcode-prefix/postcode-prefix-<cc>.bin`), never constructed here. Structural
@@ -805,11 +715,28 @@ export interface ResolveOpts {
805
715
  * or the backend lacks `ancestors`. Pass `false` to opt out.
806
716
  */
807
717
  adminCoherence?: boolean
808
- hierarchyCompletion?: boolean
809
718
  /**
810
- * @deprecated Renamed to {@link hierarchyCompletion} (#405 generalized #387). Still honored.
719
+ * Dual-role completion (#387, generalized by #405). Some places are two things at once — Singapore is a country AND a
720
+ * city, Washington DC a region AND a locality — but the address writes one span, so the tree resolves a region and
721
+ * carries no locality node even though the place genuinely is one.
722
+ *
723
+ * When a region resolved and no locality span is present, this asks the gazetteer's `coincident_roles` relation
724
+ * (#403, via {@link ResolverBackend.coincidentLocalitiesFor}) whether that region also functions as a locality, and
725
+ * ATTACHES a second reading to the same node. The region answer is untouched; the locality reading rides alongside it
726
+ * in `interpretations`, stamped `resolver_completed` so a consumer can tell it was inferred rather than parsed.
727
+ *
728
+ * **Default-ON, and on the shipped default backend it currently does nothing.** `WOFCandidateTableLookup` implements
729
+ * neither `coincidentLocalitiesFor` nor `ancestors` — `candidate.db` carries no such table — so the guard returns and
730
+ * no interpretation is attached. `Resolver.capabilityGaps` reports that at construction rather than leaving it
731
+ * silent.
732
+ *
733
+ * Measured 2026-08-15 on the FTS backend, which DOES implement both: toggling this flag changed **0 of 837** board
734
+ * inputs. The capability is real and its measured value on everything we currently test is zero, which is why
735
+ * `candidate.db` was not grown to support it (#1667, closed not-planned). Reopen on a consumer that needs it.
736
+ *
737
+ * `false` opts out; byte-stable either way on any backend lacking the relation.
811
738
  */
812
- cityStateFallback?: boolean
739
+ hierarchyCompletion?: boolean
813
740
  /**
814
741
  * Attach each resolved node's ancestor lineage (#404) — the containment chain (county → region → country) the
815
742
  * backend's {@link ResolverBackend.ancestors} returns — onto `metadata.ancestors`. The Pelias/Nominatim
@@ -818,121 +745,123 @@ export interface ResolveOpts {
818
745
  * resolver actually resolved.
819
746
  */
820
747
  includeAncestors?: boolean
748
+ /**
749
+ * Admin-containment re-rank (#1717 stage 2) — make a parsed REGION qualifier participate in locality-candidate
750
+ * selection. `Weimar, Thüringen` under the en-US locale resolves to Weimar, Texas: the locale-inferred
751
+ * `defaultCountry` becomes a hard `country` filter on the locality lookup, so the candidate pool is all-US before any
752
+ * comparator runs — the qualifier the parse got RIGHT never reaches the deciding site (the #1729 lesson, measured
753
+ * again here: the DE row is simply not in the list). The coherence passes cannot reach this class either:
754
+ * `applyAdminCoherence` needs the locality to have FAILED, `applyRegionCountryCoherence` expands only the codex US+CA
755
+ * subdivision table, and there is no postcode for #42 to re-scope by.
756
+ *
757
+ * When on, the walk threads the tree's first region-tagged span onto every locality lookup
758
+ * (`FindPlaceQuery.regionQualifier`); a capable backend answers containment from its ancestors sidecar — stamping
759
+ * `ResolvedPlace.containedByQualifier` and ADDING contained same-name candidates a locale-inferred country scope hid
760
+ * — and the walk finishes with a TIER-SAFE stable partition: contained candidates ahead of uncontained ones, within
761
+ * the exact-match tier, preserving each group's relative order. The partition runs AFTER the fame/anchor re-ranks
762
+ * because the qualifier is the address's OWN text — evidence, which outranks a prior (the same precedence
763
+ * `anchorPosterior` holds over `rankByImportance`).
764
+ *
765
+ * Soft by construction: candidates are only ever added or reordered, never dropped, so a qualifier that matches
766
+ * nothing (or contains no same-name candidate) leaves the answer byte-identical. Stands down under an EXPLICIT caller
767
+ * `defaultCountry` (the #912 posture: only a locale-INFERRED scope is bypassable by the address's own evidence). Each
768
+ * locality pick records `metadata.admin_containment`: `"contained"` (the sidecar vouched for at least one candidate),
769
+ * `"no_contained_candidate"` (evaluated, none contained), or `"unavailable"` (the backend or artifact cannot answer —
770
+ * a pre-sidecar candidate.db, the FTS/browser backends) — so an inert lever is visible in the trace rather than
771
+ * silently dead (#1719's rule; the parse-side census cannot see resolver levers, so the stamp is the census surface
772
+ * here).
773
+ *
774
+ * **Default OFF** (D-rule): opt in and measure; the promotion battery is the full board + gauntlet + parity ON/OFF
775
+ * with one declared variable.
776
+ */
777
+ adminContainmentRerank?: boolean
778
+ /**
779
+ * Resolver-interior trace sink (#1721): when set, the walk emits one {@link ResolveNodeTrace} per candidate lookup —
780
+ * the query as sent, the candidate table with per-stage ranks, every gate that fired, and the pick's provenance — so
781
+ * "the right row was present at rank 3 and lost to the fame term" is a recorded fact instead of a spelunking result.
782
+ * Absent (the default) the walk does ZERO trace bookkeeping and stays byte-identical; the sink is a hot-path opt-in
783
+ * for debug surfaces, never a production default.
784
+ */
785
+ traceSink?: (record: ResolveNodeTrace) => void
786
+ /**
787
+ * When a lookup resolves NOTHING, re-probe the same value across the other admin bands and record which ones hold it
788
+ * ({@link ResolveNodeTrace.reachableIn}) — a DIAGNOSTIC that never changes the answer.
789
+ *
790
+ * The distinction it buys is the one a `null` cannot carry: a key we hold under a different placetype is a
791
+ * REACHABILITY failure — the model's tag chose the band, and a wrong tag makes a row we own unreachable — while a key
792
+ * that exists nowhere is a coverage fact. Those call for opposite work and today reach a caller identically.
793
+ *
794
+ * Costs one extra backend call per band per miss, so it is off by default and belongs to debug surfaces. Requires
795
+ * `traceSink`: with no sink there is nowhere to record the answer, and the probes would be pure cost.
796
+ */
797
+ diagnoseUnreachable?: boolean
821
798
  }
822
799
 
823
800
  /**
824
- * Mapping from mailwoman's address-component tags to the resolver's placetype taxonomy. Components not present in the
825
- * map are NOT queried — the resolver pass leaves their classifier attribution untouched.
826
- *
827
- * Phase 4.3 default ships the obvious admin-level mappings; other tags (postcode, street, venue, dependent_locality,
828
- * prefecture, etc.) are explicitly omitted because:
829
- *
830
- * - `postcode` lives in a separate WOF shard (Phase 4.3.x follow-up via the postalcode loader).
831
- * - `street` / `house_number` aren't in WOF admin — would need OSM / OpenAddresses gazetteers and license diligence
832
- * (Phase 4.4 candidate).
833
- * - Non-US JP-specific tags wait on a different shard entirely.
834
- */
835
- export type PlacetypeMap = Partial<Record<ComponentTag, string>>
836
-
837
- /**
838
- * Placetype equivalences applied when a backend does not supply its own. A `locality` query must also reach `borough`
839
- * and `localadmin` rows — Brooklyn is a borough, and a strict filter made it unreachable.
840
- */
841
- export const DEFAULT_PLACETYPE_MAP: PlacetypeMap = {
842
- country: "country",
843
- region: "region",
844
- locality: "locality",
845
- dependent_locality: "locality",
846
- subregion: "county",
847
- // `postcode` (mailwoman tag) maps to WOF's `postalcode` placetype. Resolves only when the
848
- // backend has the postcode shard available — `WOFSqlitePlaceLookup` auto-routes `postalcode`
849
- // queries to a `postalcode_us` (or similarly-named) shard, falling back to main if absent.
850
- postcode: "postalcode",
851
- }
852
-
853
- /**
854
- * Placetype-equivalence groups for lookup FILTERING. WOF splits a single addressing tier across several placetypes, but
855
- * an address's span can name ANY of them. A backend that filters to the one "obvious" placetype makes the equivalents
856
- * unreachable, so a fuzzy same-name place in the wrong tier wins instead.
857
- *
858
- * Three tiers are affected (the value of each entry is the set the SQL filter should accept; the FIRST entry is the
859
- * canonical/requested type, which shard routing keys off):
860
- *
861
- * - **`locality`** — `locality` (most cities), `borough` (Brooklyn, the Paris arrondissements, the London boroughs), and
862
- * `localadmin` (FR communes, US towns/townships in New England). Without the group, Brooklyn-the-borough (pop 2.5M)
863
- * was unreachable and the fuzzy "Brooklyn Park, MN" won.
864
- * - **`region`** — `region` + `macroregion` (#718). WOF does NOT model every country's top-level civil division as
865
- * `region`: Italian regions (Lombardia, Veneto, Toscana…) are `macroregion` (their PROVINCES are `region`), and the
866
- * post-2016 French régions (Île-de-France) are `macroregion` too. An address's `region` span names exactly those, so
867
- * a `region`-only filter resolved them to NOTHING (confirmed against the IT/FR eval rows). US states / DE
868
- * Bundesländer / ES provincias are genuine `region`, so the EXACT-type match is preferred in ranking (see the
869
- * resolve.ts fallback-quality annotation) — the macro is the recall safety net, not a demotion.
870
- * - **`county`** — `county` + `macrocounty` (#718). The `subregion` ComponentTag maps to `county` via
871
- * {@link DEFAULT_PLACETYPE_MAP}; WOF carries `macrocounty` for FR départements-grouping / DE / GB tiers above the
872
- * county. Proactive (no eval row exercises `subregion` today) but symmetric with `region` — biasing to inclusion,
873
- * since a missed resolution costs more than a too-broad candidate (which is QA-visible). Same exact-type preference
874
- * applies.
875
- *
876
- * This table is the single source of truth for that expansion, shared by every lookup backend
877
- * (`@mailwoman/core/resolver-wof-sqlite`, `@mailwoman/core/resolver-wof-wasm`, and the demo's httpvfs lookup) so the
878
- * Node and browser resolvers can't drift. Keyed by the REQUESTED placetype. Placetypes without an entry pass through
879
- * unchanged — an explicit `placetype: "borough"` query stays narrow.
801
+ * One candidate as the resolver's deciding site saw it — the fields the ranking stages actually read, plus a per-stage
802
+ * rank vector. `ranks` carries one entry per stage that RAN, in execution order (`initial` = the backend's own order;
803
+ * then whichever of `anchor`, `locale_prior`, `importance`, `containment`, `exact_type` were active); a stage a
804
+ * candidate set never went through is absent, never defaulted. The vector is what makes loss attributable: the stage
805
+ * whose entry moved a row down is the term it lost to.
880
806
  */
881
- export const PLACETYPE_FILTER_GROUPS: Readonly<Record<string, readonly string[]>> = {
882
- locality: ["locality", "borough", "localadmin"],
883
- region: ["region", "macroregion"],
884
- county: ["county", "macrocounty"],
807
+ export interface ResolveCandidateTrace {
808
+ id: string | number
809
+ name: string
810
+ country: string
811
+ placetype: string
812
+ score: number
813
+ prominence?: number
814
+ importance?: number
815
+ population?: number
816
+ exactMatch?: boolean
817
+ containedByQualifier?: boolean
818
+ ranks: Record<string, number>
885
819
  }
886
820
 
887
821
  /**
888
- * Expand a placetype filter through {@link PLACETYPE_FILTER_GROUPS}, deduplicated and order-preserving (the first entry
889
- * stays first — shard routing keys off it). `null`/`undefined` (no filter) passes through untouched.
822
+ * One `ResolveNodeTrace` per backend lookup the walk performed (#1721) — and one per POST-WALK recovery that answers
823
+ * off the walk (`span_rescore`, `postal_compound_recovery`), so no resolved coordinate is off the record. `gates`
824
+ * records mechanism events in execution order, in the resolver's own vocabulary (`parent_fallback_retry`,
825
+ * `region_scope_miss`, `backend_error`, `postcode_format_probe`, `postcode_prefix_prior`, `bare_race`,
826
+ * `empty_admin_pick`, `min_score_reject`, `bare_country_repick`, `bare_region_repick`, `placetype_fallback`). `picked:
827
+ * null` states the lookup resolved nothing — a claim, not an omission. The candidate table is capped
828
+ * ({@link ResolveNodeTrace.candidatesTruncated} counts the tail) so a trace stays a record, not a dump.
890
829
  */
891
- export function expandPlacetypeFilter(placetypes: null): null
892
- export function expandPlacetypeFilter(placetypes: readonly string[]): string[]
893
- export function expandPlacetypeFilter(placetypes: readonly string[] | null): string[] | null
894
-
895
- export function expandPlacetypeFilter(placetypes: readonly string[] | null): string[] | null {
896
- if (!placetypes) return null
897
- const out: string[] = []
898
-
899
- for (const placetype of placetypes) {
900
- for (const expanded of PLACETYPE_FILTER_GROUPS[placetype] ?? [placetype]) {
901
- if (!out.includes(expanded)) {
902
- out.push(expanded)
903
- }
904
- }
830
+ export interface ResolveNodeTrace {
831
+ tag: string
832
+ value: string
833
+ placetype: string
834
+ query: {
835
+ country?: string
836
+ parentID?: string | number
837
+ postcode?: string
838
+ regionQualifier?: string
839
+ limit: number
905
840
  }
906
-
907
- return out
908
- }
909
-
910
- /**
911
- * Macro/broader-tier members of {@link PLACETYPE_FILTER_GROUPS} — the recall safety net a query may fall through to
912
- * when no candidate of the EXACT requested placetype exists (#718). DELIBERATELY scoped to the `macro*` tiers only: the
913
- * `locality` group's `borough`/`localadmin` are genuine peers (Brooklyn-the-borough is a first-class locality answer,
914
- * #404-class), NOT fallbacks — so they must NOT be deprioritized or annotated. Only `macroregion`/`macrocounty` are a
915
- * broader admin tier standing in for a true `region`/`county`.
916
- */
917
- const MACRO_FALLBACK_PLACETYPES: ReadonlySet<string> = new Set(["macroregion", "macrocounty"])
918
-
919
- /**
920
- * Did `candidatePlacetype` resolve `requestedPlacetype` only via a BROADER admin tier (a macro-type fallback within the
921
- * {@link PLACETYPE_FILTER_GROUPS} expansion), rather than the exact type (#718)?
922
- *
923
- * `region` → `region` is exact (false); `region` → `macroregion` is a fallback (true). Scoped to the `macro*` tiers
924
- * (see {@link MACRO_FALLBACK_PLACETYPES}) so the `locality` group's borough/localadmin peers stay exact. The resolver
925
- * uses this to (a) prefer an exact-type candidate in ranking and (b) annotate `resolutionQuality: "fallback"` when only
926
- * a macro-type matched. A placetype outside the requested group, or any non-macro member, is treated as exact (false).
927
- */
928
- export function isPlacetypeFallback(requestedPlacetype: string, candidatePlacetype: string): boolean {
929
- const group = PLACETYPE_FILTER_GROUPS[requestedPlacetype]
930
-
931
- if (!group) return false
932
-
933
- if (candidatePlacetype === requestedPlacetype) return false
934
-
935
- return MACRO_FALLBACK_PLACETYPES.has(candidatePlacetype) && group.includes(candidatePlacetype)
841
+ gates: string[]
842
+ /**
843
+ * Which OTHER admin bands hold this value, probed only when the lookup resolved nothing and
844
+ * {@link ResolveOpts.diagnoseUnreachable} is on.
845
+ *
846
+ * `[]` is a measured absence — every band was asked and none held it, so the miss is coverage. `undefined` means
847
+ * nobody asked, which is a different fact and must not be read as an empty answer.
848
+ */
849
+ reachableIn?: Array<{ placetype: string; n: number }>
850
+ candidates: ResolveCandidateTrace[]
851
+ candidatesTruncated: number
852
+ picked: {
853
+ id: string | number
854
+ name: string
855
+ source:
856
+ | "ranked"
857
+ | "bare_country"
858
+ | "bare_region"
859
+ | "postcode_prefix"
860
+ | "postcode_format_probe"
861
+ | "empty_admin"
862
+ | "span_rescore"
863
+ | "postal_compound_recovery"
864
+ } | null
936
865
  }
937
866
 
938
867
  /**
@@ -944,10 +873,23 @@ export function isPlacetypeFallback(requestedPlacetype: string, candidatePlacety
944
873
  */
945
874
  export interface Resolver {
946
875
  resolveTree(tree: AddressTree, opts?: ResolveOpts): Promise<AddressTree>
876
+ /**
877
+ * Direct gazetteer probe, passed through from the {@link ResolverBackend} — for pipeline-level consumers that need one
878
+ * lookup outside a tree walk (the #1738 dominant-bearer guard on the coarse placer's hard-country promotion is the
879
+ * first). Optional like the members below: a resolver without it degrades its consumers to their without-the-probe
880
+ * behavior, never to a crash.
881
+ */
882
+ findPlace?: ResolverBackend["findPlace"]
947
883
  /**
948
884
  * Facts the loaded gazetteer artifact declares about itself, passed through from the {@link ResolverBackend} so
949
885
  * pipeline-level consumers (the hard-country coverage gate, guard-B plausibility) read them from the handle they
950
886
  * already hold. Absent = artifact predates the manifest → code-constant fallback.
951
887
  */
952
888
  artifactCoverage?: GazetteerArtifactCoverage
889
+ /**
890
+ * Optional backend methods this resolver's backend does not implement, each naming the default-ON option it silently
891
+ * disables. Empty means every default-ON option has the support it needs; absent means the resolver predates the
892
+ * check. See {@link BackendCapabilityGap}.
893
+ */
894
+ capabilityGaps?: readonly BackendCapabilityGap[]
953
895
  }