@mailwoman/resolver-wof-sqlite 9.2.0 → 9.3.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 (488) hide show
  1. package/README.md +16 -19
  2. package/lib/address/index.ts +9 -0
  3. package/{address-point-interpolation.ts → lib/address/point-interpolation.ts} +24 -22
  4. package/{address-point-schema.ts → lib/address/point-schema.ts} +18 -4
  5. package/{address-point.ts → lib/address/point.ts} +89 -27
  6. package/{ancestry-backfill.ts → lib/ancestry/backfill.ts} +14 -19
  7. package/{ancestry.ts → lib/ancestry/index.ts} +5 -3
  8. package/{build-candidate.ts → lib/build-candidate.ts} +84 -77
  9. package/{build-slim.ts → lib/build-slim.ts} +150 -165
  10. package/{candidate → lib/candidate}/alias-bags.ts +8 -6
  11. package/{candidate → lib/candidate}/ancestors-sidecar.ts +13 -15
  12. package/{candidate → lib/candidate}/country-display-names.ts +2 -2
  13. package/{candidate/shard-fold.ts → lib/candidate/extract-fold.ts} +26 -25
  14. package/{candidate → lib/candidate}/name-roles.ts +17 -16
  15. package/{candidate → lib/candidate}/own-name.ts +1 -1
  16. package/{candidate → lib/candidate}/place-attrs.ts +3 -3
  17. package/{candidate-ancestors-schema.ts → lib/candidate-ancestors-schema.ts} +4 -4
  18. package/{candidate-fts.ts → lib/candidate-fts.ts} +3 -3
  19. package/{candidate-importance.ts → lib/candidate-importance.ts} +53 -57
  20. package/{candidate-lookup.ts → lib/candidate-lookup.ts} +76 -73
  21. package/{candidate-schema.ts → lib/candidate-schema.ts} +5 -5
  22. package/{candidate-scoring.ts → lib/candidate-scoring.ts} +15 -22
  23. package/{capital-schema.ts → lib/capital-schema.ts} +5 -6
  24. package/{capitals.ts → lib/capitals.ts} +2 -2
  25. package/{coincident-roles.ts → lib/coincident-roles.ts} +8 -11
  26. package/{convention.ts → lib/convention/index.ts} +3 -3
  27. package/{convention-schema.ts → lib/convention/schema.ts} +2 -2
  28. package/{coverage-manifest-schema.ts → lib/coverage-manifest-schema.ts} +9 -10
  29. package/{currency-backfill.ts → lib/currency-backfill.ts} +126 -41
  30. package/lib/env.ts +50 -0
  31. package/{exact-match.ts → lib/exact-match.ts} +23 -14
  32. package/{sharding.ts → lib/extracts.ts} +61 -58
  33. package/{fst-autocomplete.ts → lib/fst/autocomplete.ts} +4 -4
  34. package/{fst-builder.ts → lib/fst/builder.ts} +17 -16
  35. package/{fst-deserialize-web.ts → lib/fst/deserialize-web.ts} +27 -87
  36. package/lib/fst/format.ts +106 -0
  37. package/{fst-freshness.ts → lib/fst/freshness.ts} +41 -74
  38. package/lib/fst/index.ts +14 -0
  39. package/{fst-matcher.ts → lib/fst/matcher.ts} +1 -1
  40. package/{fst-serialize.ts → lib/fst/serialize.ts} +37 -115
  41. package/{fst-types.ts → lib/fst/types.ts} +4 -2
  42. package/{fts.ts → lib/fts/index.ts} +24 -19
  43. package/{fts-query.ts → lib/fts/query.ts} +1 -1
  44. package/{geonames-aliases.ts → lib/geonames/aliases.ts} +13 -13
  45. package/lib/geonames/index.ts +8 -0
  46. package/{geonames-postal.ts → lib/geonames/postal.ts} +14 -13
  47. package/{index.ts → lib/index.ts} +37 -37
  48. package/{interpolation.ts → lib/interpolation.ts} +27 -25
  49. package/{lookup.ts → lib/lookup.ts} +129 -141
  50. package/lib/nsul/index.ts +8 -0
  51. package/lib/nsul/lookup.ts +144 -0
  52. package/lib/nsul/schema.ts +130 -0
  53. package/{place-importance-schema.ts → lib/place-importance-schema.ts} +7 -8
  54. package/lib/poi/index.ts +8 -0
  55. package/{poi-lookup.ts → lib/poi/lookup.ts} +22 -28
  56. package/{poi-schema.ts → lib/poi/schema.ts} +3 -4
  57. package/{postal-city-alias-lookup.ts → lib/postal/city-alias-lookup.ts} +14 -20
  58. package/{postal-city-candidate-schema.ts → lib/postal/city-candidate-schema.ts} +2 -2
  59. package/lib/postal/index.ts +9 -0
  60. package/{postcode-point-lookup.ts → lib/postcode-point-lookup.ts} +17 -15
  61. package/{primary-preference.ts → lib/primary-preference.ts} +29 -10
  62. package/{proximity-rerank.ts → lib/proximity-rerank.ts} +2 -2
  63. package/{ranking-weights.ts → lib/ranking-weights.ts} +30 -4
  64. package/{region-keys.ts → lib/region-keys.ts} +9 -9
  65. package/{reverse.ts → lib/reverse.ts} +34 -46
  66. package/{schema.ts → lib/schema.ts} +10 -0
  67. package/{search-fetch.ts → lib/search-fetch.ts} +29 -28
  68. package/{sqlite-convention-source.ts → lib/sqlite-convention-source.ts} +9 -10
  69. package/{sqlite-utils.ts → lib/sqlite-utils.ts} +14 -18
  70. package/{street-centroid-schema.ts → lib/street/centroid-schema.ts} +5 -5
  71. package/{street-centroid.ts → lib/street/centroid.ts} +14 -21
  72. package/lib/street/index.ts +13 -0
  73. package/{street-morphology-fst-builder.ts → lib/street/morphology-fst-builder.ts} +24 -14
  74. package/{street-morphology-fst-loader.ts → lib/street/morphology-fst-loader.ts} +14 -12
  75. package/{street-name-lookup.ts → lib/street/name-lookup.ts} +14 -30
  76. package/{street-normalize.ts → lib/street/normalize.ts} +44 -19
  77. package/{street-segment-schema.ts → lib/street/segment-schema.ts} +7 -7
  78. package/{types.ts → lib/types.ts} +18 -12
  79. package/{unified-schema.ts → lib/unified-schema.ts} +20 -24
  80. package/lib/uprn/existence.ts +84 -0
  81. package/lib/uprn/index.ts +9 -0
  82. package/{uprn-lookup.ts → lib/uprn/lookup.ts} +14 -18
  83. package/{uprn-schema.ts → lib/uprn/schema.ts} +3 -3
  84. package/lib/weights-overlay-linker.ts +878 -0
  85. package/out/address/index.d.ts +9 -0
  86. package/out/address/index.d.ts.map +1 -0
  87. package/out/address/index.js +9 -0
  88. package/out/address/index.js.map +1 -0
  89. package/out/{address-point-interpolation.d.ts → address/point-interpolation.d.ts} +11 -10
  90. package/out/address/point-interpolation.d.ts.map +1 -0
  91. package/out/{address-point-interpolation.js → address/point-interpolation.js} +18 -18
  92. package/out/address/point-interpolation.js.map +1 -0
  93. package/out/{address-point-schema.d.ts → address/point-schema.d.ts} +16 -6
  94. package/out/address/point-schema.d.ts.map +1 -0
  95. package/out/{address-point-schema.js → address/point-schema.js} +7 -3
  96. package/out/address/point-schema.js.map +1 -0
  97. package/out/{address-point.d.ts → address/point.d.ts} +16 -8
  98. package/out/address/point.d.ts.map +1 -0
  99. package/out/{address-point.js → address/point.js} +71 -20
  100. package/out/address/point.js.map +1 -0
  101. package/out/{ancestry-backfill.d.ts → ancestry/backfill.d.ts} +7 -5
  102. package/out/ancestry/backfill.d.ts.map +1 -0
  103. package/out/{ancestry-backfill.js → ancestry/backfill.js} +12 -16
  104. package/out/ancestry/backfill.js.map +1 -0
  105. package/out/{ancestry.d.ts → ancestry/index.d.ts} +4 -3
  106. package/out/ancestry/index.d.ts.map +1 -0
  107. package/out/{ancestry.js → ancestry/index.js} +3 -2
  108. package/out/ancestry/index.js.map +1 -0
  109. package/out/build-candidate.d.ts +30 -24
  110. package/out/build-candidate.d.ts.map +1 -1
  111. package/out/build-candidate.js +50 -52
  112. package/out/build-candidate.js.map +1 -1
  113. package/out/build-slim.d.ts +4 -4
  114. package/out/build-slim.d.ts.map +1 -1
  115. package/out/build-slim.js +124 -139
  116. package/out/build-slim.js.map +1 -1
  117. package/out/candidate/alias-bags.d.ts +5 -3
  118. package/out/candidate/alias-bags.d.ts.map +1 -1
  119. package/out/candidate/alias-bags.js +2 -2
  120. package/out/candidate/alias-bags.js.map +1 -1
  121. package/out/candidate/ancestors-sidecar.d.ts +9 -10
  122. package/out/candidate/ancestors-sidecar.d.ts.map +1 -1
  123. package/out/candidate/ancestors-sidecar.js +7 -7
  124. package/out/candidate/ancestors-sidecar.js.map +1 -1
  125. package/out/candidate/country-display-names.d.ts +1 -1
  126. package/out/candidate/country-display-names.d.ts.map +1 -1
  127. package/out/candidate/country-display-names.js +1 -1
  128. package/out/candidate/country-display-names.js.map +1 -1
  129. package/out/candidate/extract-fold.d.ts +32 -0
  130. package/out/candidate/extract-fold.d.ts.map +1 -0
  131. package/out/candidate/{shard-fold.js → extract-fold.js} +20 -20
  132. package/out/candidate/extract-fold.js.map +1 -0
  133. package/out/candidate/name-roles.d.ts +13 -11
  134. package/out/candidate/name-roles.d.ts.map +1 -1
  135. package/out/candidate/name-roles.js +11 -10
  136. package/out/candidate/name-roles.js.map +1 -1
  137. package/out/candidate/own-name.d.ts +1 -1
  138. package/out/candidate/own-name.d.ts.map +1 -1
  139. package/out/candidate/own-name.js +1 -1
  140. package/out/candidate/own-name.js.map +1 -1
  141. package/out/candidate/place-attrs.d.ts +3 -3
  142. package/out/candidate/place-attrs.d.ts.map +1 -1
  143. package/out/candidate/place-attrs.js +1 -1
  144. package/out/candidate/place-attrs.js.map +1 -1
  145. package/out/candidate-ancestors-schema.d.ts +4 -4
  146. package/out/candidate-ancestors-schema.d.ts.map +1 -1
  147. package/out/candidate-ancestors-schema.js +2 -2
  148. package/out/candidate-ancestors-schema.js.map +1 -1
  149. package/out/candidate-fts.d.ts +3 -3
  150. package/out/candidate-fts.d.ts.map +1 -1
  151. package/out/candidate-fts.js +1 -1
  152. package/out/candidate-fts.js.map +1 -1
  153. package/out/candidate-importance.d.ts +16 -16
  154. package/out/candidate-importance.d.ts.map +1 -1
  155. package/out/candidate-importance.js +46 -51
  156. package/out/candidate-importance.js.map +1 -1
  157. package/out/candidate-lookup.d.ts +11 -9
  158. package/out/candidate-lookup.d.ts.map +1 -1
  159. package/out/candidate-lookup.js +61 -58
  160. package/out/candidate-lookup.js.map +1 -1
  161. package/out/candidate-schema.d.ts +5 -5
  162. package/out/candidate-schema.d.ts.map +1 -1
  163. package/out/candidate-schema.js.map +1 -1
  164. package/out/candidate-scoring.d.ts +7 -7
  165. package/out/candidate-scoring.d.ts.map +1 -1
  166. package/out/candidate-scoring.js +10 -14
  167. package/out/candidate-scoring.js.map +1 -1
  168. package/out/capital-schema.d.ts +3 -3
  169. package/out/capital-schema.d.ts.map +1 -1
  170. package/out/capital-schema.js +2 -2
  171. package/out/capital-schema.js.map +1 -1
  172. package/out/capitals.d.ts +1 -1
  173. package/out/capitals.d.ts.map +1 -1
  174. package/out/capitals.js +2 -2
  175. package/out/capitals.js.map +1 -1
  176. package/out/coincident-roles.d.ts +6 -5
  177. package/out/coincident-roles.d.ts.map +1 -1
  178. package/out/coincident-roles.js +2 -4
  179. package/out/coincident-roles.js.map +1 -1
  180. package/out/{convention.d.ts → convention/index.d.ts} +4 -4
  181. package/out/convention/index.d.ts.map +1 -0
  182. package/out/{convention.js → convention/index.js} +2 -2
  183. package/out/convention/index.js.map +1 -0
  184. package/out/{convention-schema.d.ts → convention/schema.d.ts} +2 -2
  185. package/out/convention/schema.d.ts.map +1 -0
  186. package/out/{convention-schema.js → convention/schema.js} +3 -3
  187. package/out/convention/schema.js.map +1 -0
  188. package/out/coverage-manifest-schema.d.ts +8 -8
  189. package/out/coverage-manifest-schema.d.ts.map +1 -1
  190. package/out/coverage-manifest-schema.js +4 -4
  191. package/out/coverage-manifest-schema.js.map +1 -1
  192. package/out/currency-backfill.d.ts +51 -7
  193. package/out/currency-backfill.d.ts.map +1 -1
  194. package/out/currency-backfill.js +65 -49
  195. package/out/currency-backfill.js.map +1 -1
  196. package/out/env.d.ts +43 -0
  197. package/out/env.d.ts.map +1 -0
  198. package/out/env.js +48 -0
  199. package/out/env.js.map +1 -0
  200. package/out/exact-match.d.ts +5 -5
  201. package/out/exact-match.d.ts.map +1 -1
  202. package/out/exact-match.js +10 -11
  203. package/out/exact-match.js.map +1 -1
  204. package/out/extracts.d.ts +114 -0
  205. package/out/extracts.d.ts.map +1 -0
  206. package/out/{sharding.js → extracts.js} +38 -38
  207. package/out/extracts.js.map +1 -0
  208. package/out/{fst-autocomplete.d.ts → fst/autocomplete.d.ts} +2 -2
  209. package/out/fst/autocomplete.d.ts.map +1 -0
  210. package/out/{fst-autocomplete.js → fst/autocomplete.js} +3 -3
  211. package/out/fst/autocomplete.js.map +1 -0
  212. package/out/{fst-builder.d.ts → fst/builder.d.ts} +5 -5
  213. package/out/fst/builder.d.ts.map +1 -0
  214. package/out/{fst-builder.js → fst/builder.js} +14 -13
  215. package/out/fst/builder.js.map +1 -0
  216. package/out/{fst-deserialize-web.d.ts → fst/deserialize-web.d.ts} +3 -3
  217. package/out/fst/deserialize-web.d.ts.map +1 -0
  218. package/out/{fst-deserialize-web.js → fst/deserialize-web.js} +10 -74
  219. package/out/fst/deserialize-web.js.map +1 -0
  220. package/out/fst/format.d.ts +80 -0
  221. package/out/fst/format.d.ts.map +1 -0
  222. package/out/fst/format.js +91 -0
  223. package/out/fst/format.js.map +1 -0
  224. package/out/{fst-freshness.d.ts → fst/freshness.d.ts} +10 -13
  225. package/out/fst/freshness.d.ts.map +1 -0
  226. package/out/{fst-freshness.js → fst/freshness.js} +41 -73
  227. package/out/fst/freshness.js.map +1 -0
  228. package/out/fst/index.d.ts +14 -0
  229. package/out/fst/index.d.ts.map +1 -0
  230. package/out/fst/index.js +14 -0
  231. package/out/fst/index.js.map +1 -0
  232. package/out/{fst-matcher.d.ts → fst/matcher.d.ts} +2 -2
  233. package/out/fst/matcher.d.ts.map +1 -0
  234. package/out/{fst-matcher.js → fst/matcher.js} +1 -1
  235. package/out/fst/matcher.js.map +1 -0
  236. package/out/{fst-serialize.d.ts → fst/serialize.d.ts} +5 -10
  237. package/out/fst/serialize.d.ts.map +1 -0
  238. package/out/{fst-serialize.js → fst/serialize.js} +18 -98
  239. package/out/fst/serialize.js.map +1 -0
  240. package/out/{fst-types.d.ts → fst/types.d.ts} +4 -3
  241. package/out/fst/types.d.ts.map +1 -0
  242. package/out/{fst-types.js → fst/types.js} +1 -1
  243. package/out/fst/types.js.map +1 -0
  244. package/out/{fts.d.ts → fts/index.d.ts} +16 -9
  245. package/out/fts/index.d.ts.map +1 -0
  246. package/out/{fts.js → fts/index.js} +16 -11
  247. package/out/fts/index.js.map +1 -0
  248. package/out/{fts-query.d.ts → fts/query.d.ts} +2 -2
  249. package/out/fts/query.d.ts.map +1 -0
  250. package/out/{fts-query.js → fts/query.js} +1 -1
  251. package/out/fts/query.js.map +1 -0
  252. package/out/{geonames-aliases.d.ts → geonames/aliases.d.ts} +8 -6
  253. package/out/geonames/aliases.d.ts.map +1 -0
  254. package/out/{geonames-aliases.js → geonames/aliases.js} +7 -7
  255. package/out/geonames/aliases.js.map +1 -0
  256. package/out/geonames/index.d.ts +8 -0
  257. package/out/geonames/index.d.ts.map +1 -0
  258. package/out/geonames/index.js +8 -0
  259. package/out/geonames/index.js.map +1 -0
  260. package/out/{geonames-postal.d.ts → geonames/postal.d.ts} +10 -8
  261. package/out/geonames/postal.d.ts.map +1 -0
  262. package/out/{geonames-postal.js → geonames/postal.js} +9 -9
  263. package/out/geonames/postal.js.map +1 -0
  264. package/out/index.d.ts +32 -32
  265. package/out/index.d.ts.map +1 -1
  266. package/out/index.js +24 -24
  267. package/out/index.js.map +1 -1
  268. package/out/interpolation.d.ts +10 -9
  269. package/out/interpolation.d.ts.map +1 -1
  270. package/out/interpolation.js +20 -20
  271. package/out/interpolation.js.map +1 -1
  272. package/out/lookup.d.ts +21 -20
  273. package/out/lookup.d.ts.map +1 -1
  274. package/out/lookup.js +102 -112
  275. package/out/lookup.js.map +1 -1
  276. package/out/name-score.d.ts.map +1 -1
  277. package/out/name-score.js.map +1 -1
  278. package/out/nsul/index.d.ts +8 -0
  279. package/out/nsul/index.d.ts.map +1 -0
  280. package/out/nsul/index.js +8 -0
  281. package/out/nsul/index.js.map +1 -0
  282. package/out/nsul/lookup.d.ts +83 -0
  283. package/out/nsul/lookup.d.ts.map +1 -0
  284. package/out/nsul/lookup.js +80 -0
  285. package/out/nsul/lookup.js.map +1 -0
  286. package/out/nsul/schema.d.ts +100 -0
  287. package/out/nsul/schema.d.ts.map +1 -0
  288. package/out/nsul/schema.js +78 -0
  289. package/out/nsul/schema.js.map +1 -0
  290. package/out/place-importance-schema.d.ts +5 -5
  291. package/out/place-importance-schema.d.ts.map +1 -1
  292. package/out/place-importance-schema.js +3 -3
  293. package/out/place-importance-schema.js.map +1 -1
  294. package/out/poi/index.d.ts +8 -0
  295. package/out/poi/index.d.ts.map +1 -0
  296. package/out/poi/index.js +8 -0
  297. package/out/poi/index.js.map +1 -0
  298. package/out/{poi-lookup.d.ts → poi/lookup.d.ts} +8 -10
  299. package/out/poi/lookup.d.ts.map +1 -0
  300. package/out/{poi-lookup.js → poi/lookup.js} +14 -18
  301. package/out/poi/lookup.js.map +1 -0
  302. package/out/{poi-schema.d.ts → poi/schema.d.ts} +4 -4
  303. package/out/poi/schema.d.ts.map +1 -0
  304. package/out/{poi-schema.js → poi/schema.js} +1 -1
  305. package/out/poi/schema.js.map +1 -0
  306. package/out/polygon-schema.d.ts.map +1 -1
  307. package/out/polygon-schema.js.map +1 -1
  308. package/out/{postal-city-alias-lookup.d.ts → postal/city-alias-lookup.d.ts} +6 -5
  309. package/out/postal/city-alias-lookup.d.ts.map +1 -0
  310. package/out/{postal-city-alias-lookup.js → postal/city-alias-lookup.js} +11 -15
  311. package/out/postal/city-alias-lookup.js.map +1 -0
  312. package/out/{postal-city-alias-schema.d.ts → postal/city-alias-schema.d.ts} +1 -1
  313. package/out/{postal-city-alias-schema.d.ts.map → postal/city-alias-schema.d.ts.map} +1 -1
  314. package/out/{postal-city-alias-schema.js → postal/city-alias-schema.js} +1 -1
  315. package/out/{postal-city-alias-schema.js.map → postal/city-alias-schema.js.map} +1 -1
  316. package/out/{postal-city-candidate-schema.d.ts → postal/city-candidate-schema.d.ts} +3 -3
  317. package/out/{postal-city-candidate-schema.d.ts.map → postal/city-candidate-schema.d.ts.map} +1 -1
  318. package/out/{postal-city-candidate-schema.js → postal/city-candidate-schema.js} +2 -2
  319. package/out/{postal-city-candidate-schema.js.map → postal/city-candidate-schema.js.map} +1 -1
  320. package/out/postal/index.d.ts +9 -0
  321. package/out/postal/index.d.ts.map +1 -0
  322. package/out/postal/index.js +9 -0
  323. package/out/postal/index.js.map +1 -0
  324. package/out/postcode-point-lookup.d.ts +10 -10
  325. package/out/postcode-point-lookup.d.ts.map +1 -1
  326. package/out/postcode-point-lookup.js +13 -13
  327. package/out/postcode-point-lookup.js.map +1 -1
  328. package/out/primary-preference.d.ts +13 -5
  329. package/out/primary-preference.d.ts.map +1 -1
  330. package/out/primary-preference.js +16 -8
  331. package/out/primary-preference.js.map +1 -1
  332. package/out/proximity-rerank.d.ts +2 -2
  333. package/out/proximity-rerank.d.ts.map +1 -1
  334. package/out/proximity-rerank.js +2 -2
  335. package/out/proximity-rerank.js.map +1 -1
  336. package/out/ranking-weights.d.ts +15 -3
  337. package/out/ranking-weights.d.ts.map +1 -1
  338. package/out/ranking-weights.js +21 -3
  339. package/out/ranking-weights.js.map +1 -1
  340. package/out/region-keys.d.ts +8 -8
  341. package/out/region-keys.d.ts.map +1 -1
  342. package/out/region-keys.js +9 -9
  343. package/out/region-keys.js.map +1 -1
  344. package/out/reverse.d.ts +6 -6
  345. package/out/reverse.d.ts.map +1 -1
  346. package/out/reverse.js +20 -29
  347. package/out/reverse.js.map +1 -1
  348. package/out/schema.d.ts +9 -0
  349. package/out/schema.d.ts.map +1 -1
  350. package/out/schema.js.map +1 -1
  351. package/out/search-fetch.d.ts +12 -10
  352. package/out/search-fetch.d.ts.map +1 -1
  353. package/out/search-fetch.js +21 -20
  354. package/out/search-fetch.js.map +1 -1
  355. package/out/sqlite-convention-source.d.ts +7 -7
  356. package/out/sqlite-convention-source.d.ts.map +1 -1
  357. package/out/sqlite-convention-source.js +5 -5
  358. package/out/sqlite-convention-source.js.map +1 -1
  359. package/out/sqlite-utils.d.ts +8 -8
  360. package/out/sqlite-utils.d.ts.map +1 -1
  361. package/out/sqlite-utils.js +7 -8
  362. package/out/sqlite-utils.js.map +1 -1
  363. package/out/{street-centroid-schema.d.ts → street/centroid-schema.d.ts} +6 -6
  364. package/out/{street-centroid-schema.d.ts.map → street/centroid-schema.d.ts.map} +1 -1
  365. package/out/{street-centroid-schema.js → street/centroid-schema.js} +5 -5
  366. package/out/{street-centroid-schema.js.map → street/centroid-schema.js.map} +1 -1
  367. package/out/{street-centroid.d.ts → street/centroid.d.ts} +6 -6
  368. package/out/street/centroid.d.ts.map +1 -0
  369. package/out/{street-centroid.js → street/centroid.js} +13 -19
  370. package/out/street/centroid.js.map +1 -0
  371. package/out/street/index.d.ts +13 -0
  372. package/out/street/index.d.ts.map +1 -0
  373. package/out/street/index.js +13 -0
  374. package/out/street/index.js.map +1 -0
  375. package/out/{street-morphology-fst-builder.d.ts → street/morphology-fst-builder.d.ts} +4 -4
  376. package/out/street/morphology-fst-builder.d.ts.map +1 -0
  377. package/out/{street-morphology-fst-builder.js → street/morphology-fst-builder.js} +18 -13
  378. package/out/street/morphology-fst-builder.js.map +1 -0
  379. package/out/{street-morphology-fst-loader.d.ts → street/morphology-fst-loader.d.ts} +5 -5
  380. package/out/street/morphology-fst-loader.d.ts.map +1 -0
  381. package/out/{street-morphology-fst-loader.js → street/morphology-fst-loader.js} +11 -10
  382. package/out/street/morphology-fst-loader.js.map +1 -0
  383. package/out/{street-name-lookup.d.ts → street/name-lookup.d.ts} +4 -7
  384. package/out/street/name-lookup.d.ts.map +1 -0
  385. package/out/{street-name-lookup.js → street/name-lookup.js} +9 -23
  386. package/out/street/name-lookup.js.map +1 -0
  387. package/out/{street-normalize.d.ts → street/normalize.d.ts} +25 -14
  388. package/out/street/normalize.d.ts.map +1 -0
  389. package/out/{street-normalize.js → street/normalize.js} +36 -17
  390. package/out/street/normalize.js.map +1 -0
  391. package/out/{street-segment-schema.d.ts → street/segment-schema.d.ts} +8 -8
  392. package/out/{street-segment-schema.d.ts.map → street/segment-schema.d.ts.map} +1 -1
  393. package/out/{street-segment-schema.js → street/segment-schema.js} +4 -4
  394. package/out/{street-segment-schema.js.map → street/segment-schema.js.map} +1 -1
  395. package/out/types.d.ts +18 -12
  396. package/out/types.d.ts.map +1 -1
  397. package/out/types.js.map +1 -1
  398. package/out/unified-schema.d.ts +5 -4
  399. package/out/unified-schema.d.ts.map +1 -1
  400. package/out/unified-schema.js +15 -18
  401. package/out/unified-schema.js.map +1 -1
  402. package/out/uprn/existence.d.ts +53 -0
  403. package/out/uprn/existence.d.ts.map +1 -0
  404. package/out/uprn/existence.js +61 -0
  405. package/out/uprn/existence.js.map +1 -0
  406. package/out/uprn/index.d.ts +9 -0
  407. package/out/uprn/index.d.ts.map +1 -0
  408. package/out/uprn/index.js +9 -0
  409. package/out/uprn/index.js.map +1 -0
  410. package/out/{uprn-lookup.d.ts → uprn/lookup.d.ts} +4 -4
  411. package/out/uprn/lookup.d.ts.map +1 -0
  412. package/out/{uprn-lookup.js → uprn/lookup.js} +11 -14
  413. package/out/uprn/lookup.js.map +1 -0
  414. package/out/{uprn-schema.d.ts → uprn/schema.d.ts} +4 -4
  415. package/out/uprn/schema.d.ts.map +1 -0
  416. package/out/{uprn-schema.js → uprn/schema.js} +4 -4
  417. package/out/uprn/schema.js.map +1 -0
  418. package/out/weights-overlay-linker.d.ts +184 -26
  419. package/out/weights-overlay-linker.d.ts.map +1 -1
  420. package/out/weights-overlay-linker.js +338 -86
  421. package/out/weights-overlay-linker.js.map +1 -1
  422. package/package.json +465 -269
  423. package/out/address-point-interpolation.d.ts.map +0 -1
  424. package/out/address-point-interpolation.js.map +0 -1
  425. package/out/address-point-schema.d.ts.map +0 -1
  426. package/out/address-point-schema.js.map +0 -1
  427. package/out/address-point.d.ts.map +0 -1
  428. package/out/address-point.js.map +0 -1
  429. package/out/ancestry-backfill.d.ts.map +0 -1
  430. package/out/ancestry-backfill.js.map +0 -1
  431. package/out/ancestry.d.ts.map +0 -1
  432. package/out/ancestry.js.map +0 -1
  433. package/out/candidate/shard-fold.d.ts +0 -31
  434. package/out/candidate/shard-fold.d.ts.map +0 -1
  435. package/out/candidate/shard-fold.js.map +0 -1
  436. package/out/convention-schema.d.ts.map +0 -1
  437. package/out/convention-schema.js.map +0 -1
  438. package/out/convention.d.ts.map +0 -1
  439. package/out/convention.js.map +0 -1
  440. package/out/fst-autocomplete.d.ts.map +0 -1
  441. package/out/fst-autocomplete.js.map +0 -1
  442. package/out/fst-builder.d.ts.map +0 -1
  443. package/out/fst-builder.js.map +0 -1
  444. package/out/fst-deserialize-web.d.ts.map +0 -1
  445. package/out/fst-deserialize-web.js.map +0 -1
  446. package/out/fst-freshness.d.ts.map +0 -1
  447. package/out/fst-freshness.js.map +0 -1
  448. package/out/fst-matcher.d.ts.map +0 -1
  449. package/out/fst-matcher.js.map +0 -1
  450. package/out/fst-serialize.d.ts.map +0 -1
  451. package/out/fst-serialize.js.map +0 -1
  452. package/out/fst-types.d.ts.map +0 -1
  453. package/out/fst-types.js.map +0 -1
  454. package/out/fts-query.d.ts.map +0 -1
  455. package/out/fts-query.js.map +0 -1
  456. package/out/fts.d.ts.map +0 -1
  457. package/out/fts.js.map +0 -1
  458. package/out/geonames-aliases.d.ts.map +0 -1
  459. package/out/geonames-aliases.js.map +0 -1
  460. package/out/geonames-postal.d.ts.map +0 -1
  461. package/out/geonames-postal.js.map +0 -1
  462. package/out/poi-lookup.d.ts.map +0 -1
  463. package/out/poi-lookup.js.map +0 -1
  464. package/out/poi-schema.d.ts.map +0 -1
  465. package/out/poi-schema.js.map +0 -1
  466. package/out/postal-city-alias-lookup.d.ts.map +0 -1
  467. package/out/postal-city-alias-lookup.js.map +0 -1
  468. package/out/sharding.d.ts +0 -114
  469. package/out/sharding.d.ts.map +0 -1
  470. package/out/sharding.js.map +0 -1
  471. package/out/street-centroid.d.ts.map +0 -1
  472. package/out/street-centroid.js.map +0 -1
  473. package/out/street-morphology-fst-builder.d.ts.map +0 -1
  474. package/out/street-morphology-fst-builder.js.map +0 -1
  475. package/out/street-morphology-fst-loader.d.ts.map +0 -1
  476. package/out/street-morphology-fst-loader.js.map +0 -1
  477. package/out/street-name-lookup.d.ts.map +0 -1
  478. package/out/street-name-lookup.js.map +0 -1
  479. package/out/street-normalize.d.ts.map +0 -1
  480. package/out/street-normalize.js.map +0 -1
  481. package/out/uprn-lookup.d.ts.map +0 -1
  482. package/out/uprn-lookup.js.map +0 -1
  483. package/out/uprn-schema.d.ts.map +0 -1
  484. package/out/uprn-schema.js.map +0 -1
  485. package/weights-overlay-linker.ts +0 -377
  486. /package/{name-score.ts → lib/name-score.ts} +0 -0
  487. /package/{polygon-schema.ts → lib/polygon-schema.ts} +0 -0
  488. /package/{postal-city-alias-schema.ts → lib/postal/city-alias-schema.ts} +0 -0
@@ -22,7 +22,7 @@
22
22
  *
23
23
  * The name_key normalizer is the SHARED {@link normalizeLocalityForKey} — the query side (the demo
24
24
  * resolver {@link WOFCandidateTableLookup}) MUST use the same function, the one-normalizer
25
- * discipline the address-point shard uses, so build/query stay consistent by construction.
25
+ * discipline the address-point extract uses, so build/query stay consistent by construction.
26
26
  *
27
27
  * Measured (2026-06-20, vs the 2.6 GB full-DB FTS): ~5 M rows; ~12 range fetches per 8-query
28
28
  * session (the full DB needs 243); US locality 96.8% (region bbox), EU coord parity 88.6%.
@@ -39,36 +39,36 @@
39
39
  * `candidate-ancestors-schema.ts` owns the encoding decision and the DAG/absence semantics.
40
40
  */
41
41
 
42
- import { existsSync, rmSync } from "node:fs"
43
- import { DatabaseSync } from "node:sqlite"
44
-
45
42
  import { COUNTRY_POPULATION } from "@mailwoman/codex/country"
46
- import { DatabaseClient } from "@mailwoman/core/kysley/client"
43
+ import { pathExists } from "@mailwoman/core/fs/readers"
44
+ import { removePath } from "@mailwoman/core/fs/writers"
45
+ import { DatabaseClient } from "@mailwoman/sqlite/client"
47
46
 
48
- import { createCandidateFTS } from "./candidate-fts.ts"
49
- import { IMPORTANCE_JOIN_GATE_KM, loadImportanceIndex } from "./candidate-importance.ts"
47
+ import { createCandidateFTS } from "#candidate-fts"
48
+ import { IMPORTANCE_JOIN_RADIUS_KM, loadImportanceIndex } from "#candidate-importance"
50
49
  import {
51
50
  CANDIDATE_COLUMNS,
52
51
  createCandidateStagingTables,
53
52
  createCandidateTable,
54
53
  type CandidateDatabase,
55
- } from "./candidate-schema.ts"
56
- import { explodeAliasBags } from "./candidate/alias-bags.ts"
57
- import { buildAncestorsSidecar } from "./candidate/ancestors-sidecar.ts"
58
- import { stageCountryDisplayNames } from "./candidate/country-display-names.ts"
59
- import { GLOSS_KEY_THRESHOLD, stampNameRoles } from "./candidate/name-roles.ts"
60
- import type { PlaceAttrs } from "./candidate/place-attrs.ts"
61
- import { foldShard } from "./candidate/shard-fold.ts"
62
- import { createCapitalTable } from "./capital-schema.ts"
63
- import type { CapitalPoint } from "./capitals.ts"
64
- import { resurrectCurrencyHoles } from "./currency-backfill.ts"
65
- import { normalizeLocalityForKey } from "./street-normalize.ts"
54
+ } from "#candidate-schema"
55
+ import { explodeAliasBags } from "#candidate/alias-bags"
56
+ import { buildAncestorsSidecar } from "#candidate/ancestors-sidecar"
57
+ import { stageCountryDisplayNames } from "#candidate/country-display-names"
58
+ import { foldExtract } from "#candidate/extract-fold"
59
+ import { GLOSS_KEY_THRESHOLD, stampNameRoles } from "#candidate/name-roles"
60
+ import type { PlaceAttrs } from "#candidate/place-attrs"
61
+ import { createCapitalTable } from "#capital-schema"
62
+ import type { CapitalPoint } from "#capitals"
63
+ import { resurrectCurrencyHoles } from "#currency-backfill"
64
+ import type { WOFDatabase } from "#schema"
65
+ import { normalizeLocalityForKey } from "#street/normalize"
66
66
 
67
67
  // The build's contract is this module path; the passes behind it live in `./candidate/`. Re-exported
68
68
  // here so a consumer never has to know which pass owns which name.
69
- export { stageCountryDisplayNames } from "./candidate/country-display-names.ts"
70
- export { GLOSS_EXCLUDED_PLACETYPES, GLOSS_KEY_THRESHOLD } from "./candidate/name-roles.ts"
71
- export type { PlaceAttrs } from "./candidate/place-attrs.ts"
69
+ export { stageCountryDisplayNames } from "#candidate/country-display-names"
70
+ export { GLOSS_EXCLUDED_PLACETYPES, GLOSS_KEY_THRESHOLD } from "#candidate/name-roles"
71
+ export type { PlaceAttrs } from "#candidate/place-attrs"
72
72
 
73
73
  export interface BuildCandidateOptions {
74
74
  /**
@@ -86,20 +86,20 @@ export interface BuildCandidateOptions {
86
86
  */
87
87
  capitals?: readonly CapitalPoint[]
88
88
  /**
89
- * Optional postcode shards (`spr` rows with `placetype='postalcode'` + real coords, e.g. postalcode-us.db) — folded
89
+ * Optional postcode extracts (`spr` rows with `placetype='postalcode'` + real coords, e.g. postalcode-us.db) — folded
90
90
  * in as `postalcode` candidate rows so `findPlace(postalcode)` resolves a ZIP directly (the demo's primary postcode
91
91
  * path; the postcode-*.bin anchor stays the fallback). Matches the slim wof-hot.db, which took one such postcode DB.
92
92
  *
93
- * Each shard's `names` table is folded in too (#1495) — that's where the GeoNames delivery-city names live
93
+ * Each extract's `names` table is folded in too (#1495) — that's where the GeoNames delivery-city names live
94
94
  * ("Brooklyn" for 11201), and they were previously reachable only through FTS.
95
95
  */
96
96
  postcodes?: string[]
97
97
  /**
98
- * Optional LOCALITY shards (`spr` rows with `placetype='locality'` + real coords, e.g. localities-nz-linz.db — the
99
- * #1564 NZ suburb tier) — folded through the same shard loop as the postcode shards, staged as `locality` candidate
100
- * rows with no region scope and UNMEASURED population (`neg_rank 0`: a shard row ranks behind any populated namesake
101
- * and wins only where its key is the answer). Each shard's `names` table folds as aliases, `is_primary = 0`, same as
102
- * the delivery-city pass.
98
+ * Optional LOCALITY extracts (`spr` rows with `placetype='locality'` + real coords, e.g. localities-nz-linz.db — the
99
+ * #1564 NZ suburb tier) — folded through the same extract loop as the postcode extracts, staged as `locality`
100
+ * candidate rows with no region scope and UNMEASURED population (`neg_rank 0`: a extract row ranks behind any
101
+ * populated namesake and wins only where its key is the answer). Each extract's `names` table folds as aliases,
102
+ * `is_primary = 0`, same as the delivery-city pass.
103
103
  */
104
104
  localities?: string[]
105
105
  /**
@@ -118,21 +118,30 @@ export interface BuildCandidateOptions {
118
118
  * Cross-source currency backfill (#1737). WOF carries deprecated-with-no-successor records for real, populated
119
119
  * settlements (Rochester Kent, Aldershot, Telford — 120 GB localities alone), and the currency filter correctly drops
120
120
  * them, leaving holes no ranking can fill. When this option is set, pass 1c resurrects a dead locality ONLY under
121
- * three gates, positive evidence throughout: no live same-name row of any placetype near the dead record (a distant
122
- * same-name row is a NAMESAKE and does not block — Rochester, Northumberland pop 318 must not veto Rochester, Kent);
123
- * an independent GeoNames P-class attestation of the same folded name within {@link CURRENCY_BACKFILL_RADIUS_KM}; and
124
- * the attestor at or above {@link CURRENCY_BACKFILL_POP_FLOOR}. The staged row keeps the real WOF id, name, centroid
125
- * and bbox — GeoNames only ATTESTS the place and supplies the population that lets it stand in prominence races.
126
- * `countries` are judged only where `<cc>.txt` exists under `geonamesDir`; absent dumps are skipped loudly.
121
+ * three conditions, positive evidence throughout: no live same-name row of any placetype near the dead record (a
122
+ * distant same-name row is a NAMESAKE and does not block — Rochester, Northumberland pop 318 must not veto Rochester,
123
+ * Kent); an independent GeoNames P-class attestation of the same folded name within
124
+ * {@link CURRENCY_BACKFILL_RADIUS_KM}; and the attestor at or above {@link CURRENCY_BACKFILL_POP_FLOOR}. The staged
125
+ * row keeps the real WOF id, name, centroid and bbox — GeoNames only ATTESTS the place and supplies the population
126
+ * that lets it stand in prominence races. `countries` are judged only where `<cc>.txt` exists under `geonamesDir`;
127
+ * absent dumps are skipped loudly.
127
128
  */
128
- currencyBackfill?: { geonamesDir: string; countries: readonly string[] }
129
+ currencyBackfill?: {
130
+ geonamesDir: string
131
+ countries: readonly string[]
132
+ /**
133
+ * The dead placetypes the resurrection judges; `resurrectCurrencyHoles`'s default (`locality`) when absent. The
134
+ * `localadmin` widening #1746 named is admitted here once its census is read.
135
+ */
136
+ deadPlacetypes?: readonly string[]
137
+ }
129
138
  /**
130
139
  * Optional progress callback for CLI / test introspection.
131
140
  */
132
141
  onProgress?: (phase: string, message: string) => void
133
142
  /**
134
143
  * Key-count threshold for the gloss anomaly detector — {@link GLOSS_KEY_THRESHOLD} unless a test passes a
135
- * fixture-scale value. The production number is the #1730 sweep's own cut (4,000 places at >= 50 keys).
144
+ * fixture-scale value. The production number is the #1730 sweep's own threshold (4,000 places at >= 50 keys).
136
145
  */
137
146
  glossKeyThreshold?: number
138
147
  }
@@ -145,8 +154,8 @@ export interface BuildCandidateResult {
145
154
  abbrevs: number
146
155
  postcodes: number
147
156
  /**
148
- * Delivery-city (and other `names`-table) aliases folded onto postcode rows — #1495. Zero here means the shards
149
- * carried no alias names, NOT that the pass was skipped: a shard with no `names` table reports that separately
157
+ * Delivery-city (and other `names`-table) aliases folded onto postcode rows — #1495. Zero here means the extracts
158
+ * carried no alias names, NOT that the pass was skipped: a extract with no `names` table reports that separately
150
159
  * through `onProgress`.
151
160
  */
152
161
  postcodeAliases: number
@@ -161,7 +170,7 @@ export interface BuildCandidateResult {
161
170
  ancestorPlaces: number
162
171
  /**
163
172
  * Places that received a pre/post interval label — the canonical-parent forest's node count. Places outside it (no
164
- * recorded ancestry, shard rows, cycle-skipped) have NO label: containment against them is unverifiable, never
173
+ * recorded ancestry, extract rows, cycle-skipped) have NO label: containment against them is unverifiable, never
165
174
  * false.
166
175
  */
167
176
  intervalPlaces: number
@@ -174,12 +183,12 @@ export interface BuildCandidateResult {
174
183
  importanceScored?: number
175
184
  /**
176
185
  * Places whose `(name_key, country, placetype)` matched a scored group but whose nearest scored centroid was outside
177
- * {@link IMPORTANCE_JOIN_GATE_KM} — a different town wearing the same name, refused rather than scored.
186
+ * {@link IMPORTANCE_JOIN_RADIUS_KM} — a different town wearing the same name, refused rather than scored.
178
187
  *
179
188
  * Worth watching across rebuilds: a jump here means the score source and the admin source have drifted apart, and the
180
189
  * join is being asked to guess.
181
190
  */
182
- importanceGated?: number
191
+ importanceFiltered?: number
183
192
  /**
184
193
  * Alias rows stamped `name_role = 'gloss'` — the anomaly detector's certain core (#1730).
185
194
  */
@@ -202,16 +211,16 @@ export interface BuildCandidateResult {
202
211
  export async function buildCandidateTable(opts: BuildCandidateOptions): Promise<BuildCandidateResult> {
203
212
  const progress = opts.onProgress ?? (() => {})
204
213
 
205
- if (existsSync(opts.output)) {
206
- rmSync(opts.output)
214
+ if (await pathExists(opts.output)) {
215
+ await removePath(opts.output)
207
216
  }
208
217
 
209
- const src = new DatabaseSync(opts.input, { readOnly: true })
210
- const out = new DatabaseSync(opts.output)
218
+ using src = new DatabaseClient<WOFDatabase>(opts.input, { readOnly: true })
219
+ await using kdb = new DatabaseClient<CandidateDatabase>(opts.output)
211
220
  // Build-tuning pragmas (raw — Kysely doesn't model PRAGMA). The code dictionaries + the transient
212
221
  // staging table come from the SHARED schema DDL, so they can't drift from {@link CandidateDatabase}.
213
- out.exec("PRAGMA page_size=8192; PRAGMA journal_mode=OFF; PRAGMA synchronous=OFF; PRAGMA cache_size=-2000000;")
214
- const kdb = new DatabaseClient<CandidateDatabase>({ database: out })
222
+ kdb.exec("PRAGMA page_size=8192; PRAGMA journal_mode=OFF; PRAGMA synchronous=OFF; PRAGMA cache_size=-2000000;")
223
+
215
224
  await createCandidateStagingTables(kdb)
216
225
 
217
226
  // --- compact code maps (country/placetype → small int, shrinks the clustered key). The ids are
@@ -296,13 +305,13 @@ export async function buildCandidateTable(opts: BuildCandidateOptions): Promise<
296
305
  // The hot path — millions of clustered rows. Kept a single positional prepared statement (the fastest
297
306
  // node:sqlite insert) rather than a per-row query builder. Placeholders come from CANDIDATE_COLUMNS so
298
307
  // the column COUNT can't drift; the positional run() args below MUST stay in CANDIDATE_COLUMNS order.
299
- const insStage = out.prepare(`INSERT INTO cand_stage VALUES (${CANDIDATE_COLUMNS.map(() => "?").join(", ")})`)
308
+ const insStage = kdb.prepare(`INSERT INTO cand_stage VALUES (${CANDIDATE_COLUMNS.map(() => "?").join(", ")})`)
300
309
 
301
310
  // --- pass 1: primaries (and the per-place attrs the alias/abbrev passes reuse) ---
302
311
  progress("primaries", "indexing place names")
303
312
  const attrs = new Map<number, PlaceAttrs>()
304
313
  let nPrim = 0
305
- out.exec("BEGIN")
314
+ kdb.exec("BEGIN")
306
315
 
307
316
  for (const r of src
308
317
  .prepare(
@@ -374,14 +383,14 @@ export async function buildCandidateTable(opts: BuildCandidateOptions): Promise<
374
383
  }
375
384
  }
376
385
 
377
- out.exec("COMMIT")
386
+ kdb.exec("COMMIT")
378
387
  progress("primaries", `${nPrim.toLocaleString()} primaries; ${attrs.size.toLocaleString()} places`)
379
388
 
380
389
  if (importance) {
381
390
  progress(
382
391
  "importance",
383
392
  `${importance.matched.toLocaleString()} places scored; ` +
384
- `${importance.gated.toLocaleString()} refused (nearest same-name place > ${IMPORTANCE_JOIN_GATE_KM} km away)`
393
+ `${importance.refused.toLocaleString()} refused (nearest same-name place > ${IMPORTANCE_JOIN_RADIUS_KM} km away)`
385
394
  )
386
395
  }
387
396
 
@@ -417,18 +426,19 @@ export async function buildCandidateTable(opts: BuildCandidateOptions): Promise<
417
426
  iso2ByID: new Map([...ccodes].map(([code, id]) => [id, code])),
418
427
  countryPtID: ptID("country"),
419
428
  stageRow,
420
- tx: out,
429
+ tx: kdb,
421
430
  }).toLocaleString()} country surfaces`
422
431
  )
423
432
 
424
- // --- pass 1c: cross-source currency backfill (#1737 — resurrectCurrencyHoles owns the gates). Runs BEFORE
433
+ // --- pass 1c: cross-source currency backfill (#1737 — resurrectCurrencyHoles owns the checks). Runs BEFORE
425
434
  // the alias pass so a resurrected place's alt names explode like any primary's. ---
426
435
  if (opts.currencyBackfill) {
427
436
  const nBackfill = await resurrectCurrencyHoles({
428
437
  src,
429
- tx: out,
438
+ tx: kdb,
430
439
  geonamesDir: opts.currencyBackfill.geonamesDir,
431
440
  countries: opts.currencyBackfill.countries,
441
+ ...(opts.currencyBackfill.deadPlacetypes ? { deadPlacetypes: opts.currencyBackfill.deadPlacetypes } : {}),
432
442
  attrs,
433
443
  ccID,
434
444
  ptID,
@@ -447,12 +457,12 @@ export async function buildCandidateTable(opts: BuildCandidateOptions): Promise<
447
457
 
448
458
  // --- pass 2: distinct normalized aliases from place_search.alt_names (explodeAliasBags owns the loop) ---
449
459
  progress("aliases", "exploding alias bags")
450
- const { nAlias, keyCounts } = explodeAliasBags(src, out, attrs, stageRow)
460
+ const { nAlias, keyCounts } = explodeAliasBags(src, kdb, attrs, stageRow)
451
461
  progress("aliases", `${nAlias.toLocaleString()} aliases`)
452
462
 
453
463
  // --- pass 3: region abbreviations (place_abbr) ---
454
464
  let nAbbr = 0
455
- out.exec("BEGIN")
465
+ kdb.exec("BEGIN")
456
466
 
457
467
  for (const r of src.prepare("SELECT id, abbr FROM place_abbr").iterate()) {
458
468
  const a = attrs.get(Number(r.id))
@@ -466,7 +476,7 @@ export async function buildCandidateTable(opts: BuildCandidateOptions): Promise<
466
476
  nAbbr++
467
477
  }
468
478
 
469
- out.exec("COMMIT")
479
+ kdb.exec("COMMIT")
470
480
  progress("abbrevs", `${nAbbr.toLocaleString()} abbrevs`)
471
481
 
472
482
  // --- pass 3b: name roles (#1730 prototype — stampNameRoles owns the detectors) ---
@@ -474,7 +484,7 @@ export async function buildCandidateTable(opts: BuildCandidateOptions): Promise<
474
484
  // interval tables, and neither reads the other's output. Ordered by label only.
475
485
  const roles = stampNameRoles({
476
486
  src,
477
- out,
487
+ out: kdb,
478
488
  attrs,
479
489
  keyCounts,
480
490
  glossThreshold: opts.glossKeyThreshold ?? GLOSS_KEY_THRESHOLD,
@@ -484,17 +494,17 @@ export async function buildCandidateTable(opts: BuildCandidateOptions): Promise<
484
494
  })
485
495
 
486
496
  // --- pass 3c: the ancestors sidecar (candidate-ancestors-schema.ts owns the encoding decision) ---
487
- const sidecar = await buildAncestorsSidecar({ src, out, kdb, attrs, ptID, progress })
497
+ const sidecar = await buildAncestorsSidecar({ src, out: kdb, attrs, ptID, progress })
488
498
 
489
- // --- pass 4 + 4b: postcode and locality shards (foldShard owns the per-shard loop) ---
499
+ // --- pass 4 + 4b: postcode and locality extracts (foldExtract owns the per-extract loop) ---
490
500
  let nPostcode = 0
491
501
  let nPostcodeAlias = 0
492
502
 
493
503
  for (const pcDB of opts.postcodes ?? []) {
494
- const folded = foldShard({
495
- out,
496
- shardPath: pcDB,
497
- shardPlacetype: "postalcode",
504
+ const folded = foldExtract({
505
+ out: kdb,
506
+ extractPath: pcDB,
507
+ extractPlacetype: "postalcode",
498
508
  ccID,
499
509
  ptID,
500
510
  stageRow,
@@ -512,10 +522,10 @@ export async function buildCandidateTable(opts: BuildCandidateOptions): Promise<
512
522
  let nLocality = 0
513
523
 
514
524
  for (const locDB of opts.localities ?? []) {
515
- const folded = foldShard({
516
- out,
517
- shardPath: locDB,
518
- shardPlacetype: "locality",
525
+ const folded = foldExtract({
526
+ out: kdb,
527
+ extractPath: locDB,
528
+ extractPlacetype: "locality",
519
529
  ccID,
520
530
  ptID,
521
531
  stageRow,
@@ -526,7 +536,7 @@ export async function buildCandidateTable(opts: BuildCandidateOptions): Promise<
526
536
  }
527
537
 
528
538
  if (nLocality > 0) {
529
- progress("localities", `${nLocality.toLocaleString()} shard localities folded`)
539
+ progress("localities", `${nLocality.toLocaleString()} extract localities folded`)
530
540
  }
531
541
 
532
542
  // --- code dictionaries: typed batch inserts via kdb (a few hundred rows — Kysely is clean here) ---
@@ -574,26 +584,23 @@ export async function buildCandidateTable(opts: BuildCandidateOptions): Promise<
574
584
  await createCandidateTable(kdb)
575
585
  // OR IGNORE: an abbrev/alias can normalize to a place's primary key (same place, same rank) → any one
576
586
  // row. The bulk sorted INSERT…SELECT (clustered materialization) stays raw — a single hot bulk statement.
577
- out.exec(`INSERT OR IGNORE INTO candidate (${cols}) SELECT ${cols} FROM cand_stage ORDER BY ${keyOrder};`)
587
+ kdb.exec(`INSERT OR IGNORE INTO candidate (${cols}) SELECT ${cols} FROM cand_stage ORDER BY ${keyOrder};`)
578
588
  await kdb.schema.dropTable("cand_stage").execute()
579
589
  // Typo-tolerant fallback index (the unified gazetteer's second mode): the exact name_key probe can't
580
590
  // recover misspellings, so FTS5-trigram over `name` lets the reader fuzzy-match on an exact+strip miss.
581
591
  progress("fts", "building FTS5-trigram fuzzy index")
582
- createCandidateFTS(out)
592
+ createCandidateFTS(kdb)
583
593
  // page_size MUST be set right before VACUUM: node:sqlite initializes the file at the 4096 default on
584
594
  // `new DatabaseSync`, so the creation-time pragma is a no-op — only a VACUUM rebuilds at the new size.
585
595
  // 8192 matches the sql.js-httpvfs 64 KiB request chunk cleanly (8 pages) and shallows the B-tree.
586
- out.exec("PRAGMA page_size=8192")
587
- out.exec("VACUUM")
596
+ kdb.exec("PRAGMA page_size=8192")
597
+ kdb.exec("VACUUM")
588
598
 
589
599
  const { n: rows } = await kdb
590
600
  .selectFrom("candidate")
591
601
  .select((eb) => eb.fn.countAll<number>().as("n"))
592
602
  .executeTakeFirstOrThrow()
593
603
 
594
- src.close()
595
- await kdb.destroy()
596
-
597
604
  // closes the underlying `out` connection
598
605
  return {
599
606
  rows,
@@ -607,6 +614,6 @@ export async function buildCandidateTable(opts: BuildCandidateOptions): Promise<
607
614
  ancestorPlaces: sidecar.ancestorPlaces,
608
615
  intervalPlaces: sidecar.intervalPlaces,
609
616
  ...roles,
610
- ...(importance ? { importanceScored: importance.matched, importanceGated: importance.gated } : {}),
617
+ ...(importance ? { importanceScored: importance.matched, importanceFiltered: importance.refused } : {}),
611
618
  }
612
619
  }