@mailwoman/resolver-wof-sqlite 11.0.0 → 11.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 (557) hide show
  1. package/README.md +6 -6
  2. package/lib/address/duplicate.ts +133 -0
  3. package/lib/address/keys/attribution.ts +119 -0
  4. package/lib/address/keys/build.ts +768 -0
  5. package/lib/address/keys/layout.ts +166 -0
  6. package/lib/address/keys/local-runner.ts +18 -0
  7. package/lib/address/keys/lookup.ts +205 -0
  8. package/lib/address/keys/open.ts +33 -0
  9. package/lib/address/keys/point-lookup.ts +130 -0
  10. package/lib/address/keys/postcode.ts +27 -0
  11. package/lib/address/keys/schema.ts +264 -0
  12. package/lib/address/number-forms.ts +61 -0
  13. package/lib/address/point/interpolation.ts +28 -23
  14. package/lib/address/point/schema.ts +2 -5
  15. package/lib/address/point/spine-schema.ts +4 -4
  16. package/lib/address/point.ts +12 -79
  17. package/lib/address/record.ts +155 -0
  18. package/lib/address/stack.ts +20 -0
  19. package/lib/address/subdivision-bounds.ts +81 -0
  20. package/lib/address.ts +2 -5
  21. package/lib/ancestry/backfill.ts +18 -47
  22. package/lib/ancestry.ts +10 -10
  23. package/lib/build/candidate.ts +44 -48
  24. package/lib/build/population-corrections.ts +4 -4
  25. package/lib/build/slim.ts +3 -6
  26. package/lib/candidate/alias-bags.ts +58 -18
  27. package/lib/candidate/ancestors/schema.ts +63 -43
  28. package/lib/candidate/ancestors/sidecar.ts +3 -3
  29. package/lib/candidate/bare-admin-names.ts +3 -3
  30. package/lib/candidate/country-display-names.ts +2 -5
  31. package/lib/candidate/extract-fold.ts +2 -5
  32. package/lib/candidate/fts.ts +5 -5
  33. package/lib/candidate/importance.ts +30 -24
  34. package/lib/candidate/key-fold.ts +132 -0
  35. package/lib/candidate/lookup.ts +25 -18
  36. package/lib/candidate/name-roles.ts +4 -4
  37. package/lib/candidate/nickname-namesakes.ts +140 -0
  38. package/lib/candidate/own-name.ts +12 -10
  39. package/lib/candidate/place-attrs.ts +4 -4
  40. package/lib/candidate/schema.ts +2 -5
  41. package/lib/candidate/scoring.ts +3 -6
  42. package/lib/capital-schema.ts +11 -10
  43. package/lib/capitals.ts +15 -12
  44. package/lib/convention/schema.ts +7 -7
  45. package/lib/convention.ts +3 -3
  46. package/lib/coverage-manifest-schema.ts +4 -4
  47. package/lib/env.ts +7 -6
  48. package/lib/exact-match.ts +6 -7
  49. package/lib/extracts.ts +11 -9
  50. package/lib/fst/autocomplete.ts +19 -15
  51. package/lib/fst/binary-matcher.ts +36 -50
  52. package/lib/fst/builder.ts +32 -11
  53. package/lib/fst/deserialize-web.ts +9 -8
  54. package/lib/fst/format.ts +153 -14
  55. package/lib/fst/freshness.ts +3 -4
  56. package/lib/fst/matcher.ts +6 -6
  57. package/lib/fst/serialize.ts +94 -69
  58. package/lib/fst/types.ts +4 -4
  59. package/lib/fst.ts +2 -5
  60. package/lib/fts/query.ts +3 -4
  61. package/lib/fts.ts +2 -5
  62. package/lib/geonames/aliases.ts +189 -46
  63. package/lib/geonames/postal.ts +17 -15
  64. package/lib/geonames.ts +2 -5
  65. package/lib/importance-source.ts +210 -0
  66. package/lib/index.ts +4 -5
  67. package/lib/interpolation.ts +7 -6
  68. package/lib/landmark/rows.ts +5 -5
  69. package/lib/landmark.ts +6 -6
  70. package/lib/lookup.ts +8 -8
  71. package/lib/name-score.ts +7 -6
  72. package/lib/nsul/lookup.ts +19 -15
  73. package/lib/nsul/schema.ts +4 -5
  74. package/lib/nsul.ts +2 -5
  75. package/lib/paths.ts +7 -7
  76. package/lib/place-importance-schema.ts +5 -8
  77. package/lib/poi/lookup.ts +11 -10
  78. package/lib/poi/schema.ts +16 -10
  79. package/lib/poi.ts +2 -5
  80. package/lib/polygon-schema.ts +10 -9
  81. package/lib/postal/city/alias/lookup.ts +14 -13
  82. package/lib/postal/city/alias/schema.ts +12 -12
  83. package/lib/postal/city/candidate-schema.ts +15 -12
  84. package/lib/postal.ts +2 -5
  85. package/lib/postcode-point-lookup.ts +2 -5
  86. package/lib/primary-preference.ts +42 -7
  87. package/lib/proximity-rerank.ts +23 -19
  88. package/lib/ranking-weights.ts +8 -7
  89. package/lib/region-keys.ts +15 -14
  90. package/lib/reverse.ts +16 -17
  91. package/lib/schema.ts +20 -6
  92. package/lib/search-fetch.ts +15 -11
  93. package/lib/sqlite/convention-source.ts +2 -5
  94. package/lib/sqlite/utils.ts +4 -4
  95. package/lib/street/centroid/schema.ts +6 -6
  96. package/lib/street/centroid.ts +3 -3
  97. package/lib/street/locale.ts +64 -0
  98. package/lib/street/morphology/fst/builder.ts +21 -19
  99. package/lib/street/morphology/fst/loader.ts +15 -13
  100. package/lib/street/name-lookup.ts +15 -14
  101. package/lib/street/normalize.ts +62 -17
  102. package/lib/street/segment-schema.ts +16 -14
  103. package/lib/street/table.ts +276 -0
  104. package/lib/street.ts +3 -5
  105. package/lib/types.ts +3 -6
  106. package/lib/unified-schema.ts +31 -9
  107. package/lib/uprn/existence.ts +10 -10
  108. package/lib/uprn/lookup.ts +7 -8
  109. package/lib/uprn/schema.ts +5 -5
  110. package/lib/uprn.ts +2 -5
  111. package/lib/weights-overlay-linker.ts +5 -8
  112. package/out/address/duplicate.d.ts +74 -0
  113. package/out/address/duplicate.d.ts.map +1 -0
  114. package/out/address/duplicate.js +79 -0
  115. package/out/address/duplicate.js.map +1 -0
  116. package/out/address/keys/attribution.d.ts +56 -0
  117. package/out/address/keys/attribution.d.ts.map +1 -0
  118. package/out/address/keys/attribution.js +64 -0
  119. package/out/address/keys/attribution.js.map +1 -0
  120. package/out/address/keys/build.d.ts +154 -0
  121. package/out/address/keys/build.d.ts.map +1 -0
  122. package/out/address/keys/build.js +423 -0
  123. package/out/address/keys/build.js.map +1 -0
  124. package/out/address/keys/layout.d.ts +92 -0
  125. package/out/address/keys/layout.d.ts.map +1 -0
  126. package/out/address/keys/layout.js +87 -0
  127. package/out/address/keys/layout.js.map +1 -0
  128. package/out/address/keys/local-runner.d.ts +9 -0
  129. package/out/address/keys/local-runner.d.ts.map +1 -0
  130. package/out/address/keys/local-runner.js +13 -0
  131. package/out/address/keys/local-runner.js.map +1 -0
  132. package/out/address/keys/lookup.d.ts +80 -0
  133. package/out/address/keys/lookup.d.ts.map +1 -0
  134. package/out/address/keys/lookup.js +104 -0
  135. package/out/address/keys/lookup.js.map +1 -0
  136. package/out/address/keys/open.d.ts +10 -0
  137. package/out/address/keys/open.d.ts.map +1 -0
  138. package/out/address/keys/open.js +28 -0
  139. package/out/address/keys/open.js.map +1 -0
  140. package/out/address/keys/point-lookup.d.ts +25 -0
  141. package/out/address/keys/point-lookup.d.ts.map +1 -0
  142. package/out/address/keys/point-lookup.js +100 -0
  143. package/out/address/keys/point-lookup.js.map +1 -0
  144. package/out/address/keys/postcode.d.ts +9 -0
  145. package/out/address/keys/postcode.d.ts.map +1 -0
  146. package/out/address/keys/postcode.js +25 -0
  147. package/out/address/keys/postcode.js.map +1 -0
  148. package/out/address/keys/schema.d.ts +156 -0
  149. package/out/address/keys/schema.d.ts.map +1 -0
  150. package/out/address/keys/schema.js +119 -0
  151. package/out/address/keys/schema.js.map +1 -0
  152. package/out/address/number-forms.d.ts +19 -0
  153. package/out/address/number-forms.d.ts.map +1 -0
  154. package/out/address/number-forms.js +50 -0
  155. package/out/address/number-forms.js.map +1 -0
  156. package/out/address/point/interpolation.d.ts +24 -22
  157. package/out/address/point/interpolation.d.ts.map +1 -1
  158. package/out/address/point/interpolation.js +3 -31
  159. package/out/address/point/interpolation.js.map +1 -1
  160. package/out/address/point/schema.d.ts +0 -5
  161. package/out/address/point/schema.d.ts.map +1 -1
  162. package/out/address/point/schema.js +2 -5
  163. package/out/address/point/schema.js.map +1 -1
  164. package/out/address/point/spine-schema.d.ts +1 -4
  165. package/out/address/point/spine-schema.d.ts.map +1 -1
  166. package/out/address/point/spine-schema.js +3 -4
  167. package/out/address/point/spine-schema.js.map +1 -1
  168. package/out/address/point.d.ts +0 -3
  169. package/out/address/point.d.ts.map +1 -1
  170. package/out/address/point.js +12 -71
  171. package/out/address/point.js.map +1 -1
  172. package/out/address/record.d.ts +125 -0
  173. package/out/address/record.d.ts.map +1 -0
  174. package/out/address/record.js +49 -0
  175. package/out/address/record.js.map +1 -0
  176. package/out/address/stack.d.ts +14 -0
  177. package/out/address/stack.d.ts.map +1 -0
  178. package/out/address/stack.js +19 -0
  179. package/out/address/stack.js.map +1 -0
  180. package/out/address/subdivision-bounds.d.ts +32 -0
  181. package/out/address/subdivision-bounds.d.ts.map +1 -0
  182. package/out/address/subdivision-bounds.js +48 -0
  183. package/out/address/subdivision-bounds.js.map +1 -0
  184. package/out/address.d.ts +0 -5
  185. package/out/address.d.ts.map +1 -1
  186. package/out/address.js +2 -5
  187. package/out/address.js.map +1 -1
  188. package/out/ancestry/backfill.d.ts +11 -13
  189. package/out/ancestry/backfill.d.ts.map +1 -1
  190. package/out/ancestry/backfill.js +6 -44
  191. package/out/ancestry/backfill.js.map +1 -1
  192. package/out/ancestry.d.ts +0 -14
  193. package/out/ancestry.d.ts.map +1 -1
  194. package/out/ancestry.js +9 -10
  195. package/out/ancestry.js.map +1 -1
  196. package/out/build/candidate.d.ts +20 -22
  197. package/out/build/candidate.d.ts.map +1 -1
  198. package/out/build/candidate.js +16 -28
  199. package/out/build/candidate.js.map +1 -1
  200. package/out/build/population-corrections.d.ts +1 -4
  201. package/out/build/population-corrections.d.ts.map +1 -1
  202. package/out/build/population-corrections.js +2 -19
  203. package/out/build/population-corrections.js.map +1 -1
  204. package/out/build/slim.d.ts +0 -5
  205. package/out/build/slim.d.ts.map +1 -1
  206. package/out/build/slim.js +3 -6
  207. package/out/build/slim.js.map +1 -1
  208. package/out/candidate/alias-bags.d.ts +9 -4
  209. package/out/candidate/alias-bags.d.ts.map +1 -1
  210. package/out/candidate/alias-bags.js +46 -19
  211. package/out/candidate/alias-bags.js.map +1 -1
  212. package/out/candidate/ancestors/schema.d.ts +60 -43
  213. package/out/candidate/ancestors/schema.d.ts.map +1 -1
  214. package/out/candidate/ancestors/schema.js +62 -43
  215. package/out/candidate/ancestors/schema.js.map +1 -1
  216. package/out/candidate/ancestors/sidecar.d.ts +0 -3
  217. package/out/candidate/ancestors/sidecar.d.ts.map +1 -1
  218. package/out/candidate/ancestors/sidecar.js +2 -6
  219. package/out/candidate/ancestors/sidecar.js.map +1 -1
  220. package/out/candidate/bare-admin-names.d.ts +0 -6
  221. package/out/candidate/bare-admin-names.d.ts.map +1 -1
  222. package/out/candidate/bare-admin-names.js +2 -3
  223. package/out/candidate/bare-admin-names.js.map +1 -1
  224. package/out/candidate/country-display-names.d.ts +0 -5
  225. package/out/candidate/country-display-names.d.ts.map +1 -1
  226. package/out/candidate/country-display-names.js +2 -5
  227. package/out/candidate/country-display-names.js.map +1 -1
  228. package/out/candidate/extract-fold.d.ts +0 -5
  229. package/out/candidate/extract-fold.d.ts.map +1 -1
  230. package/out/candidate/extract-fold.js +2 -5
  231. package/out/candidate/extract-fold.js.map +1 -1
  232. package/out/candidate/fts.d.ts +2 -5
  233. package/out/candidate/fts.d.ts.map +1 -1
  234. package/out/candidate/fts.js +2 -7
  235. package/out/candidate/fts.js.map +1 -1
  236. package/out/candidate/importance.d.ts +3 -33
  237. package/out/candidate/importance.d.ts.map +1 -1
  238. package/out/candidate/importance.js +29 -24
  239. package/out/candidate/importance.js.map +1 -1
  240. package/out/candidate/key-fold.d.ts +55 -0
  241. package/out/candidate/key-fold.d.ts.map +1 -0
  242. package/out/candidate/key-fold.js +80 -0
  243. package/out/candidate/key-fold.js.map +1 -0
  244. package/out/candidate/lookup.d.ts +0 -5
  245. package/out/candidate/lookup.d.ts.map +1 -1
  246. package/out/candidate/lookup.js +24 -17
  247. package/out/candidate/lookup.js.map +1 -1
  248. package/out/candidate/name-roles.d.ts +0 -6
  249. package/out/candidate/name-roles.d.ts.map +1 -1
  250. package/out/candidate/name-roles.js +3 -4
  251. package/out/candidate/name-roles.js.map +1 -1
  252. package/out/candidate/nickname-namesakes.d.ts +32 -0
  253. package/out/candidate/nickname-namesakes.d.ts.map +1 -0
  254. package/out/candidate/nickname-namesakes.js +98 -0
  255. package/out/candidate/nickname-namesakes.js.map +1 -0
  256. package/out/candidate/own-name.d.ts +0 -18
  257. package/out/candidate/own-name.d.ts.map +1 -1
  258. package/out/candidate/own-name.js +11 -10
  259. package/out/candidate/own-name.js.map +1 -1
  260. package/out/candidate/place-attrs.d.ts +1 -4
  261. package/out/candidate/place-attrs.d.ts.map +1 -1
  262. package/out/candidate/place-attrs.js +2 -12
  263. package/out/candidate/place-attrs.js.map +1 -1
  264. package/out/candidate/schema.d.ts +0 -5
  265. package/out/candidate/schema.d.ts.map +1 -1
  266. package/out/candidate/schema.js +2 -5
  267. package/out/candidate/schema.js.map +1 -1
  268. package/out/candidate/scoring.d.ts +0 -5
  269. package/out/candidate/scoring.d.ts.map +1 -1
  270. package/out/candidate/scoring.js +3 -6
  271. package/out/candidate/scoring.js.map +1 -1
  272. package/out/capital-schema.d.ts +0 -14
  273. package/out/capital-schema.d.ts.map +1 -1
  274. package/out/capital-schema.js +10 -10
  275. package/out/capital-schema.js.map +1 -1
  276. package/out/capitals.d.ts +0 -16
  277. package/out/capitals.d.ts.map +1 -1
  278. package/out/capitals.js +14 -12
  279. package/out/capitals.js.map +1 -1
  280. package/out/convention/schema.d.ts +4 -7
  281. package/out/convention/schema.d.ts.map +1 -1
  282. package/out/convention/schema.js +2 -10
  283. package/out/convention/schema.js.map +1 -1
  284. package/out/convention.d.ts +0 -3
  285. package/out/convention.d.ts.map +1 -1
  286. package/out/convention.js +2 -8
  287. package/out/convention.js.map +1 -1
  288. package/out/coverage-manifest-schema.d.ts +1 -4
  289. package/out/coverage-manifest-schema.d.ts.map +1 -1
  290. package/out/coverage-manifest-schema.js +2 -3
  291. package/out/coverage-manifest-schema.js.map +1 -1
  292. package/out/env.d.ts +0 -8
  293. package/out/env.d.ts.map +1 -1
  294. package/out/env.js +6 -6
  295. package/out/env.js.map +1 -1
  296. package/out/exact-match.d.ts +2 -6
  297. package/out/exact-match.d.ts.map +1 -1
  298. package/out/exact-match.js +3 -9
  299. package/out/exact-match.js.map +1 -1
  300. package/out/extracts.d.ts +8 -9
  301. package/out/extracts.d.ts.map +1 -1
  302. package/out/extracts.js +9 -8
  303. package/out/extracts.js.map +1 -1
  304. package/out/fst/autocomplete.d.ts +1 -19
  305. package/out/fst/autocomplete.d.ts.map +1 -1
  306. package/out/fst/autocomplete.js +2 -18
  307. package/out/fst/autocomplete.js.map +1 -1
  308. package/out/fst/binary-matcher.d.ts +6 -8
  309. package/out/fst/binary-matcher.d.ts.map +1 -1
  310. package/out/fst/binary-matcher.js +12 -43
  311. package/out/fst/binary-matcher.js.map +1 -1
  312. package/out/fst/builder.d.ts +0 -12
  313. package/out/fst/builder.d.ts.map +1 -1
  314. package/out/fst/builder.js +23 -11
  315. package/out/fst/builder.js.map +1 -1
  316. package/out/fst/deserialize-web.d.ts +1 -12
  317. package/out/fst/deserialize-web.d.ts.map +1 -1
  318. package/out/fst/deserialize-web.js +8 -8
  319. package/out/fst/deserialize-web.js.map +1 -1
  320. package/out/fst/format.d.ts +66 -16
  321. package/out/fst/format.d.ts.map +1 -1
  322. package/out/fst/format.js +100 -16
  323. package/out/fst/format.js.map +1 -1
  324. package/out/fst/freshness.d.ts +0 -7
  325. package/out/fst/freshness.d.ts.map +1 -1
  326. package/out/fst/freshness.js +2 -4
  327. package/out/fst/freshness.js.map +1 -1
  328. package/out/fst/matcher.d.ts +3 -6
  329. package/out/fst/matcher.d.ts.map +1 -1
  330. package/out/fst/matcher.js +2 -9
  331. package/out/fst/matcher.js.map +1 -1
  332. package/out/fst/serialize.d.ts +0 -23
  333. package/out/fst/serialize.d.ts.map +1 -1
  334. package/out/fst/serialize.js +68 -60
  335. package/out/fst/serialize.js.map +1 -1
  336. package/out/fst/types.d.ts +1 -4
  337. package/out/fst/types.d.ts.map +1 -1
  338. package/out/fst/types.js +2 -6
  339. package/out/fst/types.js.map +1 -1
  340. package/out/fst.d.ts +0 -5
  341. package/out/fst.d.ts.map +1 -1
  342. package/out/fst.js +2 -5
  343. package/out/fst.js.map +1 -1
  344. package/out/fts/query.d.ts +0 -4
  345. package/out/fts/query.d.ts.map +1 -1
  346. package/out/fts/query.js +2 -7
  347. package/out/fts/query.js.map +1 -1
  348. package/out/fts.d.ts +0 -5
  349. package/out/fts.d.ts.map +1 -1
  350. package/out/fts.js +2 -5
  351. package/out/fts.js.map +1 -1
  352. package/out/geonames/aliases.d.ts +43 -5
  353. package/out/geonames/aliases.d.ts.map +1 -1
  354. package/out/geonames/aliases.js +108 -44
  355. package/out/geonames/aliases.js.map +1 -1
  356. package/out/geonames/postal.d.ts +1 -25
  357. package/out/geonames/postal.d.ts.map +1 -1
  358. package/out/geonames/postal.js +15 -14
  359. package/out/geonames/postal.js.map +1 -1
  360. package/out/geonames.d.ts +0 -5
  361. package/out/geonames.d.ts.map +1 -1
  362. package/out/geonames.js +2 -5
  363. package/out/geonames.js.map +1 -1
  364. package/out/importance-source.d.ts +90 -0
  365. package/out/importance-source.d.ts.map +1 -0
  366. package/out/importance-source.js +133 -0
  367. package/out/importance-source.js.map +1 -0
  368. package/out/index.d.ts +2 -5
  369. package/out/index.d.ts.map +1 -1
  370. package/out/index.js +4 -5
  371. package/out/index.js.map +1 -1
  372. package/out/interpolation.d.ts +0 -7
  373. package/out/interpolation.d.ts.map +1 -1
  374. package/out/interpolation.js +6 -6
  375. package/out/interpolation.js.map +1 -1
  376. package/out/landmark/rows.d.ts +2 -5
  377. package/out/landmark/rows.d.ts.map +1 -1
  378. package/out/landmark/rows.js +2 -8
  379. package/out/landmark/rows.js.map +1 -1
  380. package/out/landmark.d.ts +3 -6
  381. package/out/landmark.d.ts.map +1 -1
  382. package/out/landmark.js +2 -8
  383. package/out/landmark.js.map +1 -1
  384. package/out/lookup.d.ts +0 -7
  385. package/out/lookup.d.ts.map +1 -1
  386. package/out/lookup.js +7 -8
  387. package/out/lookup.js.map +1 -1
  388. package/out/name-score.d.ts +4 -6
  389. package/out/name-score.d.ts.map +1 -1
  390. package/out/name-score.js +6 -6
  391. package/out/name-score.js.map +1 -1
  392. package/out/nsul/lookup.d.ts +16 -15
  393. package/out/nsul/lookup.d.ts.map +1 -1
  394. package/out/nsul/lookup.js +2 -25
  395. package/out/nsul/lookup.js.map +1 -1
  396. package/out/nsul/schema.d.ts +1 -5
  397. package/out/nsul/schema.d.ts.map +1 -1
  398. package/out/nsul/schema.js +3 -8
  399. package/out/nsul/schema.js.map +1 -1
  400. package/out/nsul.d.ts +0 -5
  401. package/out/nsul.d.ts.map +1 -1
  402. package/out/nsul.js +2 -5
  403. package/out/nsul.js.map +1 -1
  404. package/out/paths.d.ts +1 -13
  405. package/out/paths.d.ts.map +1 -1
  406. package/out/paths.js +6 -7
  407. package/out/paths.js.map +1 -1
  408. package/out/place-importance-schema.d.ts +3 -8
  409. package/out/place-importance-schema.d.ts.map +1 -1
  410. package/out/place-importance-schema.js +3 -6
  411. package/out/place-importance-schema.js.map +1 -1
  412. package/out/poi/lookup.d.ts +0 -13
  413. package/out/poi/lookup.d.ts.map +1 -1
  414. package/out/poi/lookup.js +10 -10
  415. package/out/poi/lookup.js.map +1 -1
  416. package/out/poi/schema.d.ts +13 -10
  417. package/out/poi/schema.d.ts.map +1 -1
  418. package/out/poi/schema.js +2 -13
  419. package/out/poi/schema.js.map +1 -1
  420. package/out/poi.d.ts +0 -5
  421. package/out/poi.d.ts.map +1 -1
  422. package/out/poi.js +2 -5
  423. package/out/poi.js.map +1 -1
  424. package/out/polygon-schema.d.ts +7 -9
  425. package/out/polygon-schema.d.ts.map +1 -1
  426. package/out/polygon-schema.js +2 -12
  427. package/out/polygon-schema.js.map +1 -1
  428. package/out/postal/city/alias/lookup.d.ts +11 -13
  429. package/out/postal/city/alias/lookup.d.ts.map +1 -1
  430. package/out/postal/city/alias/lookup.js +13 -13
  431. package/out/postal/city/alias/lookup.js.map +1 -1
  432. package/out/postal/city/alias/schema.d.ts +9 -12
  433. package/out/postal/city/alias/schema.d.ts.map +1 -1
  434. package/out/postal/city/alias/schema.js +2 -17
  435. package/out/postal/city/alias/schema.js.map +1 -1
  436. package/out/postal/city/candidate-schema.d.ts +12 -12
  437. package/out/postal/city/candidate-schema.d.ts.map +1 -1
  438. package/out/postal/city/candidate-schema.js +14 -12
  439. package/out/postal/city/candidate-schema.js.map +1 -1
  440. package/out/postal.d.ts +0 -5
  441. package/out/postal.d.ts.map +1 -1
  442. package/out/postal.js +2 -5
  443. package/out/postal.js.map +1 -1
  444. package/out/postcode-point-lookup.d.ts +0 -5
  445. package/out/postcode-point-lookup.d.ts.map +1 -1
  446. package/out/postcode-point-lookup.js +2 -5
  447. package/out/postcode-point-lookup.js.map +1 -1
  448. package/out/primary-preference.d.ts +20 -6
  449. package/out/primary-preference.d.ts.map +1 -1
  450. package/out/primary-preference.js +33 -6
  451. package/out/primary-preference.js.map +1 -1
  452. package/out/proximity-rerank.d.ts +2 -26
  453. package/out/proximity-rerank.d.ts.map +1 -1
  454. package/out/proximity-rerank.js +22 -19
  455. package/out/proximity-rerank.js.map +1 -1
  456. package/out/ranking-weights.d.ts +5 -7
  457. package/out/ranking-weights.d.ts.map +1 -1
  458. package/out/ranking-weights.js +2 -9
  459. package/out/ranking-weights.js.map +1 -1
  460. package/out/region-keys.d.ts +0 -15
  461. package/out/region-keys.d.ts.map +1 -1
  462. package/out/region-keys.js +14 -14
  463. package/out/region-keys.js.map +1 -1
  464. package/out/reverse.d.ts +1 -24
  465. package/out/reverse.d.ts.map +1 -1
  466. package/out/reverse.js +14 -16
  467. package/out/reverse.js.map +1 -1
  468. package/out/schema.d.ts +17 -6
  469. package/out/schema.d.ts.map +1 -1
  470. package/out/schema.js +2 -15
  471. package/out/schema.js.map +1 -1
  472. package/out/search-fetch.d.ts +0 -13
  473. package/out/search-fetch.d.ts.map +1 -1
  474. package/out/search-fetch.js +14 -11
  475. package/out/search-fetch.js.map +1 -1
  476. package/out/sqlite/convention-source.d.ts +0 -5
  477. package/out/sqlite/convention-source.d.ts.map +1 -1
  478. package/out/sqlite/convention-source.js +2 -5
  479. package/out/sqlite/convention-source.js.map +1 -1
  480. package/out/sqlite/utils.d.ts +1 -7
  481. package/out/sqlite/utils.d.ts.map +1 -1
  482. package/out/sqlite/utils.js +3 -4
  483. package/out/sqlite/utils.js.map +1 -1
  484. package/out/street/centroid/schema.d.ts +3 -6
  485. package/out/street/centroid/schema.d.ts.map +1 -1
  486. package/out/street/centroid/schema.js +2 -7
  487. package/out/street/centroid/schema.js.map +1 -1
  488. package/out/street/centroid.d.ts +0 -3
  489. package/out/street/centroid.d.ts.map +1 -1
  490. package/out/street/centroid.js +2 -6
  491. package/out/street/centroid.js.map +1 -1
  492. package/out/street/locale.d.ts +12 -0
  493. package/out/street/locale.d.ts.map +1 -0
  494. package/out/street/locale.js +54 -0
  495. package/out/street/locale.js.map +1 -0
  496. package/out/street/morphology/fst/builder.d.ts +1 -26
  497. package/out/street/morphology/fst/builder.d.ts.map +1 -1
  498. package/out/street/morphology/fst/builder.js +19 -18
  499. package/out/street/morphology/fst/builder.js.map +1 -1
  500. package/out/street/morphology/fst/loader.d.ts +0 -20
  501. package/out/street/morphology/fst/loader.d.ts.map +1 -1
  502. package/out/street/morphology/fst/loader.js +14 -13
  503. package/out/street/morphology/fst/loader.js.map +1 -1
  504. package/out/street/name-lookup.d.ts +11 -13
  505. package/out/street/name-lookup.d.ts.map +1 -1
  506. package/out/street/name-lookup.js +14 -14
  507. package/out/street/name-lookup.js.map +1 -1
  508. package/out/street/normalize.d.ts +29 -12
  509. package/out/street/normalize.d.ts.map +1 -1
  510. package/out/street/normalize.js +53 -13
  511. package/out/street/normalize.js.map +1 -1
  512. package/out/street/segment-schema.d.ts +11 -12
  513. package/out/street/segment-schema.d.ts.map +1 -1
  514. package/out/street/segment-schema.js +13 -12
  515. package/out/street/segment-schema.js.map +1 -1
  516. package/out/street/table.d.ts +154 -0
  517. package/out/street/table.d.ts.map +1 -0
  518. package/out/street/table.js +122 -0
  519. package/out/street/table.js.map +1 -0
  520. package/out/street.d.ts +1 -5
  521. package/out/street.d.ts.map +1 -1
  522. package/out/street.js +3 -5
  523. package/out/street.js.map +1 -1
  524. package/out/types.d.ts +1 -6
  525. package/out/types.d.ts.map +1 -1
  526. package/out/types.js +2 -5
  527. package/out/types.js.map +1 -1
  528. package/out/unified-schema.d.ts +18 -7
  529. package/out/unified-schema.d.ts.map +1 -1
  530. package/out/unified-schema.js +14 -10
  531. package/out/unified-schema.js.map +1 -1
  532. package/out/uprn/existence.d.ts +7 -10
  533. package/out/uprn/existence.d.ts.map +1 -1
  534. package/out/uprn/existence.js +9 -10
  535. package/out/uprn/existence.js.map +1 -1
  536. package/out/uprn/lookup.d.ts +1 -8
  537. package/out/uprn/lookup.d.ts.map +1 -1
  538. package/out/uprn/lookup.js +6 -8
  539. package/out/uprn/lookup.js.map +1 -1
  540. package/out/uprn/schema.d.ts +2 -5
  541. package/out/uprn/schema.d.ts.map +1 -1
  542. package/out/uprn/schema.js +2 -7
  543. package/out/uprn/schema.js.map +1 -1
  544. package/out/uprn.d.ts +0 -5
  545. package/out/uprn.d.ts.map +1 -1
  546. package/out/uprn.js +2 -5
  547. package/out/uprn.js.map +1 -1
  548. package/out/weights-overlay-linker.d.ts +3 -8
  549. package/out/weights-overlay-linker.d.ts.map +1 -1
  550. package/out/weights-overlay-linker.js +5 -8
  551. package/out/weights-overlay-linker.js.map +1 -1
  552. package/package.json +12 -12
  553. package/lib/currency-backfill.ts +0 -289
  554. package/out/currency-backfill.d.ts +0 -68
  555. package/out/currency-backfill.d.ts.map +0 -1
  556. package/out/currency-backfill.js +0 -169
  557. package/out/currency-backfill.js.map +0 -1
@@ -1,14 +1,11 @@
1
- /**
2
- * @copyright Sister Software
3
- * @license AGPL-3.0
4
- * @author Teffen Ellis, et al.
5
- */
1
+ // SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
2
+ // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
6
3
 
7
4
  import { isOfficialLanguage } from "@mailwoman/codex/country"
8
5
  import { readUnquotedTSV } from "@mailwoman/core/fs/delimited"
9
6
  import { pathExists } from "@mailwoman/core/fs/readers/stat"
10
- import { GEONAMES_ID_BASE, GEONAMES_POSTAL_ID_BASE } from "@mailwoman/core/resolver/synthetic-id-ranges"
11
- import type { DatabaseClient } from "@mailwoman/sqlite/client"
7
+ import { GEONAMES_ID_BASE, GEONAMES_POSTAL_ID_BASE, geonamesFoldID } from "@mailwoman/core/resolver/synthetic-id-ranges"
8
+ import type { DatabaseClient, StatementSync } from "@mailwoman/sqlite/client"
12
9
  import { type PathBuilderLike, resolvePathBuilder } from "path-ts"
13
10
 
14
11
  import type { WOFDatabase } from "#schema"
@@ -64,6 +61,12 @@ export interface GeonamesIngestProgress {
64
61
  * It distinguishes a sparse source from aliases that the fold discarded.
65
62
  */
66
63
  aliasesRefused: number | null
64
+
65
+ /**
66
+ * The number of populated places that matched an existing record and added their
67
+ * names to it, or null when the fold had no matcher.
68
+ */
69
+ matched?: number | null
67
70
  }
68
71
 
69
72
  /**
@@ -74,7 +77,9 @@ export function formatGeonamesIngestProgress(event: GeonamesIngestProgress, miss
74
77
  return `${event.country}: ${missingFile ? `${missingFile} missing` : "dump missing"} — download from download.geonames.org/export/dump/${event.country}.zip; skipped`
75
78
  }
76
79
 
77
- return `${event.country}: ${event.places.toLocaleString()} places, ${(event.aliasesRefused ?? 0).toLocaleString()} alt-names refused`
80
+ const matched = event.matched == null ? "" : `, ${event.matched.toLocaleString()} matched an existing record`
81
+
82
+ return `${event.country}: ${event.places.toLocaleString()} places${matched}, ${(event.aliasesRefused ?? 0).toLocaleString()} alt-names refused`
78
83
  }
79
84
 
80
85
  interface V2Alias {
@@ -139,6 +144,111 @@ async function parseAlternateNamesV2(
139
144
  return v2
140
145
  }
141
146
 
147
+ /**
148
+ * A GeoNames place the fold is about to write.
149
+ */
150
+ export interface GeonamesFoldPlace {
151
+ geonamesID: number
152
+ name: string
153
+ placetype: "country" | "region" | "locality"
154
+ country: string
155
+ latitude: number
156
+ longitude: number
157
+ }
158
+
159
+ /**
160
+ * The record a GeoNames place matched in the database being folded into.
161
+ */
162
+ export interface GeonamesFoldMatch {
163
+ id: number
164
+ placetype: string
165
+ }
166
+
167
+ /**
168
+ * Matches GeoNames places against the records already in the database being folded into.
169
+ */
170
+ export interface GeonamesFoldMatcher {
171
+ match(place: GeonamesFoldPlace): GeonamesFoldMatch | null
172
+ /**
173
+ * Answers whether the matched record lacks a name, recording it so the name is written once.
174
+ */
175
+ claimName(match: GeonamesFoldMatch, country: string, name: string): boolean
176
+ onGap(place: GeonamesFoldPlace & { id: number }): void
177
+ }
178
+
179
+ /**
180
+ * Folds one country's GeoNames `A`-class rows, its country and its ADM1 regions,
181
+ * and links each region the fold wrote to the country.
182
+ *
183
+ * A row that matches an existing record writes no row and adds its name to that record,
184
+ * and its id is the existing record's.
185
+ * Only regions the fold wrote are re-parented, so an existing region keeps its own parent.
186
+ */
187
+ function foldAdminRows(
188
+ statements: { db: DatabaseClient<WOFDatabase>; spr: StatementSync; names: StatementSync; ancestors: StatementSync },
189
+ input: {
190
+ rows: readonly string[][]
191
+ country: string
192
+ clean: (s: string) => string | null
193
+ existing: GeonamesFoldMatcher | undefined
194
+ claim: (match: GeonamesFoldMatch, name: string) => void
195
+ }
196
+ ): { countryID: number; adminMap: Map<string, number> } {
197
+ const { rows, country: cc, clean, existing, claim } = input
198
+ let countryID = -1
199
+ const adminMap = new Map<string, number>()
200
+ // The regions this fold wrote, as opposed to existing records a region matched.
201
+ const writtenRegions = new Set<number>()
202
+
203
+ for (const f of rows) {
204
+ const aname = clean(f[2] ?? "") ?? clean(f[1] ?? "")
205
+
206
+ if (!aname) continue
207
+ const lat = Number(f[4]) || 0
208
+ const lon = Number(f[5]) || 0
209
+ const placetype: GeonamesFoldPlace["placetype"] = f[7]?.startsWith("PCL") ? "country" : "region"
210
+
211
+ if (placetype === "country" && countryID >= 0) continue
212
+
213
+ if (placetype === "region" && !(f[7] === "ADM1" && f[10])) continue
214
+
215
+ const place = { geonamesID: Number(f[0]), name: aname, placetype, country: cc, latitude: lat, longitude: lon }
216
+ const matched = existing?.match(place) ?? null
217
+
218
+ if (matched) {
219
+ claim(matched, aname)
220
+ }
221
+
222
+ const rid = matched?.id ?? geonamesFoldID(place.geonamesID)
223
+
224
+ if (!matched) {
225
+ statements.spr.run(rid, -1, aname, placetype, cc, lat, lon, lat, lon, lat, lon, 1, 0, 0, 0, 0, 0)
226
+ statements.names.run(rid, aname, placetype, cc, "", "", 0, 0)
227
+ statements.ancestors.run(rid, rid, placetype)
228
+ existing?.onGap({ ...place, id: rid })
229
+ }
230
+
231
+ if (placetype === "country") {
232
+ countryID = rid
233
+ } else {
234
+ adminMap.set(f[10]!, rid)
235
+
236
+ if (!matched) {
237
+ writtenRegions.add(rid)
238
+ }
239
+ }
240
+ }
241
+
242
+ if (countryID >= 0) {
243
+ for (const rid of writtenRegions) {
244
+ statements.db.prepare("UPDATE spr SET parent_id = ? WHERE id = ?").run(countryID, rid)
245
+ statements.ancestors.run(rid, countryID, "country")
246
+ }
247
+ }
248
+
249
+ return { countryID, adminMap }
250
+ }
251
+
142
252
  /**
143
253
  * Purges the fold's id range, then adds GeoNames `P`-class places and their
144
254
  * alternate names for `countries` to `db`.
@@ -156,6 +266,13 @@ export async function ingestGeonamesAliases(
156
266
  adminForCountries?: ReadonlySet<string>
157
267
 
158
268
  alternateDir?: PathBuilderLike
269
+ /**
270
+ * The records already in `db` to match against.
271
+ *
272
+ * A GeoNames place that matches one adds its names to that record and writes no row.
273
+ * A place that matches none is written and reported to `onGap`.
274
+ */
275
+ existing?: GeonamesFoldMatcher
159
276
  }
160
277
  ): Promise<number> {
161
278
  const LATIN_NAME = /^[\p{Script=Latin}\p{M}\s\-'.]{2,60}$/u
@@ -184,7 +301,7 @@ export async function ingestGeonamesAliases(
184
301
  )
185
302
 
186
303
  const namesInsert = db.prepare(
187
- `INSERT INTO names (id, name, placetype, country, language, privateuse, official, lastmodified) VALUES (?, ?, ?, ?, ?, ?, ?, ?)`
304
+ `INSERT INTO names (id, name, placetype, country, language, privateuse, official, lastmodified, source) VALUES (?, ?, ?, ?, ?, ?, ?, ?, 'geonames')`
188
305
  )
189
306
 
190
307
  const populationInsert = db.prepare(`INSERT OR REPLACE INTO place_population (id, population) VALUES (?, ?)`)
@@ -201,7 +318,6 @@ export async function ingestGeonamesAliases(
201
318
  }
202
319
  }
203
320
 
204
- let id = GEONAMES_ID_BASE
205
321
  let total = 0
206
322
  db.exec("BEGIN")
207
323
 
@@ -218,6 +334,7 @@ export async function ingestGeonamesAliases(
218
334
 
219
335
  let nc = 0
220
336
  let refused = 0
337
+ let matchedPlaces = 0
221
338
 
222
339
  const addAdmin = opts?.adminForCountries?.has(cc) ?? false
223
340
  const v2File = opts?.alternateDir ? resolvePathBuilder(opts.alternateDir, `${cc}.txt`) : null
@@ -244,40 +361,22 @@ export async function ingestGeonamesAliases(
244
361
 
245
362
  const v2 = readV2 ? await parseAlternateNamesV2(v2File!, cc, wanted) : null
246
363
 
247
- let countryID = -1
248
- const adminMap = new Map<string, number>()
249
-
250
- if (addAdmin) {
251
- for (const f of adminRows) {
252
- const aname = clean(f[2] ?? "") ?? clean(f[1] ?? "")
253
-
254
- if (!aname) continue
255
- const lat = Number(f[4]) || 0
256
- const lon = Number(f[5]) || 0
257
-
258
- if (f[7]?.startsWith("PCL")) {
259
- if (countryID >= 0) continue
260
- countryID = id++
261
- sprInsert.run(countryID, -1, aname, "country", cc, lat, lon, lat, lon, lat, lon, 1, 0, 0, 0, 0, 0)
262
- namesInsert.run(countryID, aname, "country", cc, "", "", 0, 0)
263
- ancestorInsert.run(countryID, countryID, "country")
264
- } else if (f[7] === "ADM1" && f[10]) {
265
- const rid = id++
266
- sprInsert.run(rid, -1, aname, "region", cc, lat, lon, lat, lon, lat, lon, 1, 0, 0, 0, 0, 0)
267
- namesInsert.run(rid, aname, "region", cc, "", "", 0, 0)
268
- ancestorInsert.run(rid, rid, "region")
269
- adminMap.set(f[10], rid)
270
- }
271
- }
272
-
273
- if (countryID >= 0) {
274
- for (const rid of adminMap.values()) {
275
- db.prepare("UPDATE spr SET parent_id = ? WHERE id = ?").run(countryID, rid)
276
- ancestorInsert.run(rid, countryID, "country")
277
- }
364
+ /**
365
+ * Writes a place's name onto the existing record it matched, once.
366
+ */
367
+ const claim = (match: GeonamesFoldMatch, name: string, language = "", privateuse = "", official = 0) => {
368
+ if (opts?.existing?.claimName(match, cc, name)) {
369
+ namesInsert.run(match.id, name, match.placetype, cc, language, privateuse, official, 0)
278
370
  }
279
371
  }
280
372
 
373
+ const { countryID, adminMap } = addAdmin
374
+ ? foldAdminRows(
375
+ { db, spr: sprInsert, names: namesInsert, ancestors: ancestorInsert },
376
+ { rows: adminRows, country: cc, clean, existing: opts?.existing, claim }
377
+ )
378
+ : { countryID: -1, adminMap: new Map<string, number>() }
379
+
281
380
  for await (const f of readUnquotedTSV(file)) {
282
381
  if (f[6] !== "P") continue
283
382
  const lat = Number(f[4])
@@ -287,7 +386,46 @@ export async function ingestGeonamesAliases(
287
386
  const name = clean(f[1] ?? "")
288
387
 
289
388
  if (!name) continue
290
- const nid = id++
389
+
390
+ const tags = v2?.get(Number(f[0]))
391
+ const alternates = [f[2] ?? "", ...(f[3] ? f[3].split(",") : [])]
392
+
393
+ const place = {
394
+ geonamesID: Number(f[0]),
395
+ name,
396
+ placetype: "locality" as const,
397
+ country: cc,
398
+ latitude: lat,
399
+ longitude: lon,
400
+ }
401
+
402
+ const matched = opts?.existing?.match(place) ?? null
403
+
404
+ if (matched) {
405
+ claim(matched, name)
406
+
407
+ for (const raw of alternates) {
408
+ const alt = cleanAlias(raw)
409
+
410
+ if (!alt && raw.trim()) {
411
+ refused++
412
+ }
413
+
414
+ if (alt) {
415
+ const tag = tags?.get(alt)
416
+
417
+ claim(matched, alt, tag?.language ?? "", tag?.privateuse ?? "", tag?.official ?? 0)
418
+ }
419
+ }
420
+
421
+ matchedPlaces++
422
+
423
+ continue
424
+ }
425
+
426
+ const nid = geonamesFoldID(place.geonamesID)
427
+
428
+ opts?.existing?.onGap({ ...place, id: nid })
291
429
 
292
430
  const regionID = addAdmin ? (adminMap.get(f[10] ?? "") ?? -1) : -1
293
431
  const parentID = regionID >= 0 ? regionID : addAdmin && countryID >= 0 ? countryID : -1
@@ -309,9 +447,7 @@ export async function ingestGeonamesAliases(
309
447
 
310
448
  const seen = new Set([name])
311
449
 
312
- const tags = v2?.get(Number(f[0]))
313
-
314
- for (const raw of [f[2] ?? "", ...(f[3] ? f[3].split(",") : [])]) {
450
+ for (const raw of alternates) {
315
451
  const alt = cleanAlias(raw)
316
452
 
317
453
  if (!alt && raw.trim()) {
@@ -335,7 +471,14 @@ export async function ingestGeonamesAliases(
335
471
  nc++
336
472
  }
337
473
 
338
- report({ country: cc, places: nc, skipped: false, aliasesRefused: refused })
474
+ report({
475
+ country: cc,
476
+ places: nc,
477
+ skipped: false,
478
+ aliasesRefused: refused,
479
+ matched: opts?.existing ? matchedPlaces : null,
480
+ })
481
+
339
482
  total += nc
340
483
  }
341
484
 
@@ -1,20 +1,22 @@
1
+ // SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
2
+ // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
3
+
1
4
  /**
2
- * @copyright Sister Software
3
- * @license AGPL-3.0
4
- * @author Teffen Ellis, et al.
5
- *
6
- * Fold GeoNames postcode rows into a WOF or unified postcode extract as first-class `postalcode`
7
- * places for countries whose WOF postalcode repos do not exist.
5
+ * Fold GeoNames postcode rows into a WOF or unified postcode extract as first-class
6
+ * `postalcode` places for countries whose WOF postalcode repos do not exist.
8
7
  *
9
8
  * Two laws are enforced here in code rather than in a runbook.
10
9
  *
11
- * 1. The name law. A postcode row's `name` is stored in the sanitized-query token shape with
12
- * every non-letter and non-number stripped. `sanitizeFTSQuery` reduces the parsed token to
13
- * that shape at lookup time. A stored `"110 00"` or `"11-041"` can never match the
14
- * query `"11000"` or `"11041"`. The display form is preserved as an alt row in `names`.
15
- * 2. The medoid law. A postcode whose rows contain scattered points has no single true center.
16
- * Their average puts the code somewhere no address is. The medoid is the member point
17
- * nearest the group's mean.
10
+ * 1. The name law.
11
+ * A postcode row's `name` is stored in the sanitized-query token shape with
12
+ * every non-letter and non-number stripped.
13
+ * `sanitizeFTSQuery` reduces the parsed token to that shape at lookup time.
14
+ * A stored `"110 00"` or `"11-041"` can never match the query `"11000"` or `"11041"`.
15
+ * The display form is preserved as an alt row in `names`.
16
+ * 2. The medoid law.
17
+ * A postcode whose rows contain scattered points has no single true center.
18
+ * Their average puts the code somewhere no address is.
19
+ * The medoid is the member point nearest the group's mean.
18
20
  *
19
21
  * `build-unified-wof --geonames-postal-countries`, standalone folds and the `mailwoman
20
22
  * gazetteer` commands share one implementation. The GeoNames postal dump is
@@ -77,7 +79,7 @@ export interface MedoidSupport {
77
79
  * Distinct coordinates among them.
78
80
  *
79
81
  * One means every row refers to the same point.
80
- * In a dump whose coordinates are computed, that is one value inherited N times
82
+ * In a dump whose coordinates are computed, that's one value inherited N times
81
83
  * rather than N sources agreeing.
82
84
  */
83
85
  distinctPoints: number
@@ -223,7 +225,7 @@ export async function ingestGeonamesPostal(
223
225
  )
224
226
 
225
227
  const namesInsert = db.prepare(
226
- `INSERT INTO names (id, name, placetype, country, language, lastmodified) VALUES (?, ?, 'postalcode', ?, '', 0)`
228
+ `INSERT INTO names (id, name, placetype, country, language, lastmodified, source) VALUES (?, ?, 'postalcode', ?, '', 0, 'geonames')`
227
229
  )
228
230
 
229
231
  let nextID = GEONAMES_POSTAL_ID_BASE
package/lib/geonames.ts CHANGED
@@ -1,8 +1,5 @@
1
- /**
2
- * @copyright Sister Software
3
- * @license AGPL-3.0
4
- * @author Teffen Ellis, et al.
5
- */
1
+ // SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
2
+ // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
6
3
 
7
4
  export * from "#geonames/aliases"
8
5
  export * from "#geonames/postal"
@@ -0,0 +1,210 @@
1
+ // SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
2
+ // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
3
+
4
+ /**
5
+ * Which admin database an importance build was made from.
6
+ *
7
+ * `mailwoman gazetteer importance` copies an admin database and adds `place_importance` to the copy.
8
+ * It stamps the admin file's md5 and size into the copy's `importance_source` table, the same
9
+ * identity an FST stamps as `sourceDBMD5` and `sourceDBBytes` ({@linkcode readWOFSourceIdentity}).
10
+ *
11
+ * The copy is written beside the admin database at {@linkcode importanceDatabasePath},
12
+ * a name derived from the admin md5, so the candidate build finds the importance build for
13
+ * its admin database by hashing that database, and checks the stamp before reading a score.
14
+ */
15
+
16
+ import { pathExists } from "@mailwoman/core/fs/readers/stat"
17
+ import { DatabaseClient } from "@mailwoman/sqlite/client"
18
+ import { tableExists } from "@mailwoman/sqlite/introspection"
19
+ import type { Kysely } from "kysely"
20
+ import { basename, dirname, resolvePathBuilder, type PathBuilderLike } from "path-ts"
21
+
22
+ import { type FSTSourceIdentity, readWOFSourceIdentity } from "#fst/freshness"
23
+
24
+ /**
25
+ * The one row of `importance_source`: the admin database the importance build copied.
26
+ */
27
+ export interface ImportanceSourceTable {
28
+ /**
29
+ * The admin path as the importance build was given it.
30
+ */
31
+ admin_path: string
32
+ /**
33
+ * The admin file's md5 as lowercase hex.
34
+ */
35
+ admin_md5: string
36
+ /**
37
+ * The admin file's size in bytes.
38
+ */
39
+ admin_bytes: number
40
+ }
41
+
42
+ export interface ImportanceSourceDatabase {
43
+ importance_source: ImportanceSourceTable
44
+ }
45
+
46
+ /**
47
+ * The admin database an importance build records, read back from its stamp.
48
+ */
49
+ export interface ImportanceAdminSource extends FSTSourceIdentity {
50
+ path: string
51
+ }
52
+
53
+ /**
54
+ * The count of md5 hex characters in the importance file name.
55
+ * The stamp inside the file holds the whole digest.
56
+ */
57
+ const NAME_DIGEST_LENGTH = 12
58
+
59
+ /**
60
+ * Where the importance build for an admin database lives: beside it,
61
+ * under a name built from the admin's md5.
62
+ *
63
+ * `admin-global-priority.db` with md5 `6a0c2736…` gives `admin-global-priority-importance-6a0c2736xxxx.db`.
64
+ */
65
+ export function importanceDatabasePath(adminDB: PathBuilderLike, adminMD5: string): string {
66
+ const name = basename(adminDB.toString(), ".db")
67
+
68
+ return resolvePathBuilder(dirname(adminDB.toString()))(
69
+ `${name}-importance-${adminMD5.slice(0, NAME_DIGEST_LENGTH)}.db`
70
+ ).toString()
71
+ }
72
+
73
+ /**
74
+ * Create `importance_source` and write the admin identity into it, replacing any earlier row.
75
+ */
76
+ export async function writeImportanceSource(
77
+ db: Kysely<ImportanceSourceDatabase>,
78
+ source: ImportanceAdminSource
79
+ ): Promise<void> {
80
+ await db.schema.dropTable("importance_source").ifExists().execute()
81
+
82
+ await db.schema
83
+ .createTable("importance_source")
84
+ .addColumn("admin_path", "text", (c) => c.notNull())
85
+ .addColumn("admin_md5", "text", (c) => c.notNull())
86
+ .addColumn("admin_bytes", "integer", (c) => c.notNull())
87
+ .execute()
88
+
89
+ await db
90
+ .insertInto("importance_source")
91
+ .values({ admin_path: source.path, admin_md5: source.md5, admin_bytes: source.bytes })
92
+ .execute()
93
+ }
94
+
95
+ /**
96
+ * Read the admin identity an importance build stamped.
97
+ *
98
+ * Returns `null` only when the file has no `importance_source` table.
99
+ * Such a file is an importance build that predates the stamp.
100
+ *
101
+ * @throws When the file is missing, or when the table holds other than one row.
102
+ */
103
+ export async function readImportanceSource(importanceDB: PathBuilderLike): Promise<ImportanceAdminSource | null> {
104
+ if (!(await pathExists(importanceDB))) {
105
+ throw new Error(`importance source: ${importanceDB} not found`)
106
+ }
107
+
108
+ using db = new DatabaseClient<ImportanceSourceDatabase>(importanceDB, { readOnly: true })
109
+
110
+ if (!tableExists(db, "importance_source")) return null
111
+
112
+ const rows = await db.selectFrom("importance_source").selectAll().execute()
113
+
114
+ if (rows.length !== 1) {
115
+ throw new Error(`importance source: ${importanceDB} holds ${rows.length} importance_source rows, expected 1`)
116
+ }
117
+
118
+ const [row] = rows
119
+
120
+ return { path: row!.admin_path, md5: row!.admin_md5, bytes: Number(row!.admin_bytes) }
121
+ }
122
+
123
+ /**
124
+ * The importance build a reader uses, with its own md5 for a manifest or a report.
125
+ */
126
+ export interface ResolvedImportance {
127
+ path: string
128
+ md5: string
129
+ }
130
+
131
+ /**
132
+ * A refusal from {@linkcode resolveImportanceForAdmin}.
133
+ * Its message gives the admin path and the importance path.
134
+ */
135
+ export class ImportanceSourceError extends Error {
136
+ constructor(message: string) {
137
+ super(message)
138
+
139
+ this.name = "ImportanceSourceError"
140
+ }
141
+ }
142
+
143
+ /**
144
+ * Find the importance build that belongs with `adminDB` and check its stamp.
145
+ *
146
+ * Every reader of importance scores finds its file here, from the admin database it reads.
147
+ * Without `importanceDB` the file is the one {@linkcode importanceDatabasePath} gives for the admin md5.
148
+ * A given `importanceDB` is checked the same way.
149
+ *
150
+ * @throws {ImportanceSourceError} When no importance build exists for the admin database,
151
+ * when the file has no `importance_source` stamp, or when its stamp records another admin database.
152
+ */
153
+ export async function resolveImportanceForAdmin(
154
+ adminDB: PathBuilderLike,
155
+ importanceDB?: PathBuilderLike
156
+ ): Promise<ResolvedImportance> {
157
+ if (!(await pathExists(adminDB))) {
158
+ throw new ImportanceSourceError(`admin ${adminDB} does not exist, so no importance build can be matched to it.`)
159
+ }
160
+
161
+ const admin = await readWOFSourceIdentity(adminDB)
162
+ const path = (importanceDB ?? importanceDatabasePath(adminDB, admin.md5)).toString()
163
+ const rebuild = `mailwoman gazetteer importance --admin ${adminDB}`
164
+
165
+ if (!(await pathExists(path))) {
166
+ throw new ImportanceSourceError(
167
+ `no importance build for admin ${adminDB} (md5 ${admin.md5}): ${path} does not exist. ` +
168
+ `Build it with \`${rebuild}\`.`
169
+ )
170
+ }
171
+
172
+ const stamped = await readImportanceSource(path)
173
+
174
+ if (!stamped) {
175
+ throw new ImportanceSourceError(
176
+ `importance ${path} records no admin database (no importance_source table), so it cannot be ` +
177
+ `matched to admin ${adminDB} (md5 ${admin.md5}). Rebuild it with \`${rebuild}\`.`
178
+ )
179
+ }
180
+
181
+ if (stamped.md5 !== admin.md5 || stamped.bytes !== admin.bytes) {
182
+ throw new ImportanceSourceError(
183
+ `importance ${path} was built from admin ${stamped.path} (md5 ${stamped.md5}, ` +
184
+ `${stamped.bytes} bytes), not admin ${adminDB} (md5 ${admin.md5}, ${admin.bytes} bytes). ` +
185
+ `Rebuild it with \`${rebuild}\`.`
186
+ )
187
+ }
188
+
189
+ return { path, md5: (await readWOFSourceIdentity(path)).md5 }
190
+ }
191
+
192
+ /**
193
+ * {@linkcode resolveImportanceForAdmin} for a report that goes on without scores.
194
+ *
195
+ * A refusal comes back as its message, and the message gives both paths.
196
+ * The report states that message as the reason it read no scores.
197
+ *
198
+ * @throws Any error other than an {@linkcode ImportanceSourceError}.
199
+ */
200
+ export async function resolveImportanceOrRefusal(
201
+ adminDB: PathBuilderLike
202
+ ): Promise<(ResolvedImportance & { refusal: null }) | { path: null; md5: null; refusal: string }> {
203
+ try {
204
+ return { ...(await resolveImportanceForAdmin(adminDB)), refusal: null }
205
+ } catch (error) {
206
+ if (error instanceof ImportanceSourceError) return { path: null, md5: null, refusal: error.message }
207
+
208
+ throw error
209
+ }
210
+ }
package/lib/index.ts CHANGED
@@ -1,8 +1,5 @@
1
- /**
2
- * @copyright Sister Software
3
- * @license AGPL-3.0
4
- * @author Teffen Ellis, et al.
5
- */
1
+ // SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
2
+ // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
6
3
 
7
4
  export type { FindPlaceQuery, PlaceCandidate, PlaceLookup, WOFPlacetype } from "#types"
8
5
 
@@ -122,6 +119,8 @@ export {
122
119
 
123
120
  export { AddressPointInterpolator } from "#address/point/interpolation"
124
121
  export { AddressPointSqliteLookup } from "#address/point"
122
+ export { openAddressLayerLookup } from "#address/keys/open"
123
+ export { readLatestAddressLayerManifest } from "#address/keys/layout"
125
124
 
126
125
  export {
127
126
  STREET_CENTROID_COLUMNS,
@@ -1,9 +1,10 @@
1
+ // SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
2
+ // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
3
+
1
4
  /**
2
- * @copyright Sister Software
3
- * @license AGPL-3.0
4
- * @author Teffen Ellis, et al.
5
- *
6
- * House-number interpolation: when the exact address-point tier misses, estimate the coordinate from tiger street-segment ranges by parity-aware range match and linear interpolation along the segment polyline.
5
+ * House-number interpolation: when the exact address-point tier misses,
6
+ * estimate the coordinate from tiger street-segment ranges by parity-aware range match
7
+ * and linear interpolation along the segment polyline.
7
8
  */
8
9
 
9
10
  import { parseJSONStrict } from "@mailwoman/core/json"
@@ -134,7 +135,7 @@ export class StreetInterpolator<
134
135
  /**
135
136
  * Resources this instance opened.
136
137
  *
137
- * A caller-supplied connection is not in here, so disposal cannot reach it.
138
+ * A caller-supplied connection isn't in here, so disposal cannot reach it.
138
139
  */
139
140
  readonly #resources: DisposableStack
140
141
  readonly #byPostcode:
@@ -1,10 +1,10 @@
1
+ // SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
2
+ // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
3
+
1
4
  /**
2
- * @copyright Sister Software
3
- * @license AGPL-3.0
4
- * @author Teffen Ellis, et al.
5
+ * The landmark table's read, shared by the native lookup and the range-read lookup a Worker uses.
5
6
  *
6
- * The landmark table's read, shared by the native lookup and the range-read lookup a Worker uses. It holds no database
7
- * client, so a Worker bundle can import it.
7
+ * It holds no database client, so a Worker bundle can import it.
8
8
  */
9
9
 
10
10
  import type { LandmarkHit, LandmarkKind } from "@mailwoman/core/resolver"
package/lib/landmark.ts CHANGED
@@ -1,10 +1,10 @@
1
+ // SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
2
+ // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
3
+
1
4
  /**
2
- * @copyright Sister Software
3
- * @license AGPL-3.0
4
- * @author Teffen Ellis, et al.
5
- *
6
- * The landmark layer: Wikidata places keyed by every name and alias they are written with, ranked by the number of
7
- * Wikipedia language editions that describe them. The source is CC0, so the database may ship.
5
+ * The landmark layer: Wikidata places keyed by every name and alias they're written with,
6
+ * ranked by the number of Wikipedia language editions that describe them.
7
+ * The source is CC0, so the database may ship.
8
8
  */
9
9
 
10
10
  import type { LandmarkHit, LandmarkLookup } from "@mailwoman/core/resolver"