@mailwoman/core 8.0.0 → 8.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 (409) hide show
  1. package/api/APIClient.ts +3 -4
  2. package/api/responses.ts +6 -3
  3. package/coarse-placer/coarse-placer.ts +26 -11
  4. package/coarse-placer/featurize.ts +25 -16
  5. package/coarse-placer/tools/build-dataset.ts +42 -18
  6. package/coarse-placer/tools/build-outlier-exposure.ts +51 -18
  7. package/coarse-placer/tools/build-outlier-latin.ts +48 -22
  8. package/coarse-placer/tools/build-outlier-oa.ts +52 -20
  9. package/coarse-placer/tools/eval-latin-offmap.ts +37 -12
  10. package/coarse-placer/tools/eval-openset.ts +104 -37
  11. package/coarse-placer/tools/eval-quant-compare.ts +41 -11
  12. package/coarse-placer/tools/eval.ts +51 -13
  13. package/coarse-placer/tools/fnv-hash.ts +5 -3
  14. package/coarse-placer/tools/probe-frontier.ts +63 -32
  15. package/coarse-placer/tools/quantize.ts +30 -8
  16. package/coarse-placer/tools/train.ts +63 -17
  17. package/collections.ts +2 -2
  18. package/decoder/build-tree.ts +16 -3
  19. package/decoder/calibration.ts +23 -7
  20. package/decoder/containment.ts +3 -1
  21. package/decoder/proposals-to-tree.ts +2 -0
  22. package/decoder/resolve-proposal-overlaps.ts +5 -1
  23. package/decoder/serialize-json.ts +8 -2
  24. package/decoder/serialize-tuples.ts +7 -2
  25. package/decoder/serialize-xml.ts +29 -11
  26. package/decoder/types.ts +34 -12
  27. package/decoder/unknown-spans.ts +14 -5
  28. package/decoder/validate-tree.ts +6 -1
  29. package/env/index.ts +1 -1
  30. package/env/load.ts +1 -1
  31. package/env/paths.ts +1 -1
  32. package/env/schema.ts +12 -4
  33. package/errors/schema.ts +1 -1
  34. package/fs/node.ts +9 -10
  35. package/identifiers.ts +3 -3
  36. package/kysley/adapter.ts +1 -1
  37. package/layers/manifest.ts +22 -8
  38. package/layers/schema.ts +59 -19
  39. package/locale/locale.ts +6 -2
  40. package/locale/profiles/en-us.ts +3 -0
  41. package/locale/profiles/fr-fr.ts +3 -0
  42. package/locale/profiles/ja-jp.ts +3 -0
  43. package/locale/registry.ts +3 -1
  44. package/logging/shared.ts +1 -0
  45. package/logging/utils.ts +1 -1
  46. package/objects.ts +7 -2
  47. package/out/api/APIClient.d.ts +1 -1
  48. package/out/api/APIClient.d.ts.map +1 -1
  49. package/out/api/APIClient.js +3 -2
  50. package/out/api/APIClient.js.map +1 -1
  51. package/out/api/responses.d.ts.map +1 -1
  52. package/out/api/responses.js +3 -3
  53. package/out/api/responses.js.map +1 -1
  54. package/out/coarse-placer/coarse-placer.d.ts +19 -9
  55. package/out/coarse-placer/coarse-placer.d.ts.map +1 -1
  56. package/out/coarse-placer/coarse-placer.js +6 -4
  57. package/out/coarse-placer/coarse-placer.js.map +1 -1
  58. package/out/coarse-placer/featurize.d.ts.map +1 -1
  59. package/out/coarse-placer/featurize.js +20 -16
  60. package/out/coarse-placer/featurize.js.map +1 -1
  61. package/out/coarse-placer/tools/build-dataset.d.ts +15 -5
  62. package/out/coarse-placer/tools/build-dataset.d.ts.map +1 -1
  63. package/out/coarse-placer/tools/build-dataset.js +19 -14
  64. package/out/coarse-placer/tools/build-dataset.js.map +1 -1
  65. package/out/coarse-placer/tools/build-outlier-exposure.d.ts +21 -7
  66. package/out/coarse-placer/tools/build-outlier-exposure.d.ts.map +1 -1
  67. package/out/coarse-placer/tools/build-outlier-exposure.js +24 -12
  68. package/out/coarse-placer/tools/build-outlier-exposure.js.map +1 -1
  69. package/out/coarse-placer/tools/build-outlier-latin.d.ts +18 -6
  70. package/out/coarse-placer/tools/build-outlier-latin.d.ts.map +1 -1
  71. package/out/coarse-placer/tools/build-outlier-latin.js +27 -17
  72. package/out/coarse-placer/tools/build-outlier-latin.js.map +1 -1
  73. package/out/coarse-placer/tools/build-outlier-oa.d.ts +18 -6
  74. package/out/coarse-placer/tools/build-outlier-oa.d.ts.map +1 -1
  75. package/out/coarse-placer/tools/build-outlier-oa.js +29 -15
  76. package/out/coarse-placer/tools/build-outlier-oa.js.map +1 -1
  77. package/out/coarse-placer/tools/eval-latin-offmap.d.ts +18 -6
  78. package/out/coarse-placer/tools/eval-latin-offmap.d.ts.map +1 -1
  79. package/out/coarse-placer/tools/eval-latin-offmap.js +13 -7
  80. package/out/coarse-placer/tools/eval-latin-offmap.js.map +1 -1
  81. package/out/coarse-placer/tools/eval-openset.d.ts +24 -8
  82. package/out/coarse-placer/tools/eval-openset.d.ts.map +1 -1
  83. package/out/coarse-placer/tools/eval-openset.js +52 -31
  84. package/out/coarse-placer/tools/eval-openset.js.map +1 -1
  85. package/out/coarse-placer/tools/eval-quant-compare.d.ts +30 -10
  86. package/out/coarse-placer/tools/eval-quant-compare.d.ts.map +1 -1
  87. package/out/coarse-placer/tools/eval-quant-compare.js +4 -2
  88. package/out/coarse-placer/tools/eval-quant-compare.js.map +1 -1
  89. package/out/coarse-placer/tools/eval.d.ts +24 -8
  90. package/out/coarse-placer/tools/eval.d.ts.map +1 -1
  91. package/out/coarse-placer/tools/eval.js +16 -6
  92. package/out/coarse-placer/tools/eval.js.map +1 -1
  93. package/out/coarse-placer/tools/fnv-hash.d.ts +3 -1
  94. package/out/coarse-placer/tools/fnv-hash.d.ts.map +1 -1
  95. package/out/coarse-placer/tools/fnv-hash.js +5 -3
  96. package/out/coarse-placer/tools/fnv-hash.js.map +1 -1
  97. package/out/coarse-placer/tools/probe-frontier.d.ts +18 -6
  98. package/out/coarse-placer/tools/probe-frontier.d.ts.map +1 -1
  99. package/out/coarse-placer/tools/probe-frontier.js +39 -23
  100. package/out/coarse-placer/tools/probe-frontier.js.map +1 -1
  101. package/out/coarse-placer/tools/quantize.d.ts +15 -5
  102. package/out/coarse-placer/tools/quantize.d.ts.map +1 -1
  103. package/out/coarse-placer/tools/quantize.js +11 -4
  104. package/out/coarse-placer/tools/quantize.js.map +1 -1
  105. package/out/coarse-placer/tools/train.d.ts +24 -8
  106. package/out/coarse-placer/tools/train.d.ts.map +1 -1
  107. package/out/coarse-placer/tools/train.js +24 -10
  108. package/out/coarse-placer/tools/train.js.map +1 -1
  109. package/out/collections.js +2 -2
  110. package/out/collections.js.map +1 -1
  111. package/out/decoder/build-tree.d.ts.map +1 -1
  112. package/out/decoder/build-tree.js +9 -3
  113. package/out/decoder/build-tree.js.map +1 -1
  114. package/out/decoder/calibration.d.ts +17 -3
  115. package/out/decoder/calibration.d.ts.map +1 -1
  116. package/out/decoder/calibration.js +12 -4
  117. package/out/decoder/calibration.js.map +1 -1
  118. package/out/decoder/containment.d.ts +3 -1
  119. package/out/decoder/containment.d.ts.map +1 -1
  120. package/out/decoder/containment.js +3 -1
  121. package/out/decoder/containment.js.map +1 -1
  122. package/out/decoder/proposals-to-tree.d.ts.map +1 -1
  123. package/out/decoder/proposals-to-tree.js.map +1 -1
  124. package/out/decoder/resolve-proposal-overlaps.d.ts.map +1 -1
  125. package/out/decoder/resolve-proposal-overlaps.js +5 -1
  126. package/out/decoder/resolve-proposal-overlaps.js.map +1 -1
  127. package/out/decoder/serialize-json.d.ts +6 -2
  128. package/out/decoder/serialize-json.d.ts.map +1 -1
  129. package/out/decoder/serialize-json.js.map +1 -1
  130. package/out/decoder/serialize-tuples.d.ts +6 -2
  131. package/out/decoder/serialize-tuples.d.ts.map +1 -1
  132. package/out/decoder/serialize-tuples.js.map +1 -1
  133. package/out/decoder/serialize-xml.d.ts +21 -7
  134. package/out/decoder/serialize-xml.d.ts.map +1 -1
  135. package/out/decoder/serialize-xml.js +7 -5
  136. package/out/decoder/serialize-xml.js.map +1 -1
  137. package/out/decoder/types.d.ts +34 -12
  138. package/out/decoder/types.d.ts.map +1 -1
  139. package/out/decoder/types.js +1 -1
  140. package/out/decoder/types.js.map +1 -1
  141. package/out/decoder/unknown-spans.d.ts +9 -3
  142. package/out/decoder/unknown-spans.d.ts.map +1 -1
  143. package/out/decoder/unknown-spans.js +4 -2
  144. package/out/decoder/unknown-spans.js.map +1 -1
  145. package/out/decoder/validate-tree.d.ts +3 -1
  146. package/out/decoder/validate-tree.d.ts.map +1 -1
  147. package/out/decoder/validate-tree.js +3 -1
  148. package/out/decoder/validate-tree.js.map +1 -1
  149. package/out/env/index.js +0 -1
  150. package/out/env/index.js.map +1 -1
  151. package/out/env/load.js +1 -1
  152. package/out/env/load.js.map +1 -1
  153. package/out/env/paths.js +1 -1
  154. package/out/env/paths.js.map +1 -1
  155. package/out/env/schema.d.ts.map +1 -1
  156. package/out/env/schema.js +12 -4
  157. package/out/env/schema.js.map +1 -1
  158. package/out/errors/schema.js +1 -1
  159. package/out/errors/schema.js.map +1 -1
  160. package/out/fs/node.d.ts +1 -2
  161. package/out/fs/node.d.ts.map +1 -1
  162. package/out/fs/node.js +7 -8
  163. package/out/fs/node.js.map +1 -1
  164. package/out/identifiers.js +3 -3
  165. package/out/identifiers.js.map +1 -1
  166. package/out/kysley/adapter.d.ts +1 -1
  167. package/out/kysley/adapter.d.ts.map +1 -1
  168. package/out/kysley/adapter.js +1 -1
  169. package/out/kysley/adapter.js.map +1 -1
  170. package/out/layers/manifest.d.ts +18 -6
  171. package/out/layers/manifest.d.ts.map +1 -1
  172. package/out/layers/manifest.js +8 -4
  173. package/out/layers/manifest.js.map +1 -1
  174. package/out/layers/schema.d.ts +57 -19
  175. package/out/layers/schema.d.ts.map +1 -1
  176. package/out/layers/schema.js +24 -8
  177. package/out/layers/schema.js.map +1 -1
  178. package/out/locale/locale.d.ts +6 -2
  179. package/out/locale/locale.d.ts.map +1 -1
  180. package/out/locale/profiles/en-us.d.ts +3 -0
  181. package/out/locale/profiles/en-us.d.ts.map +1 -1
  182. package/out/locale/profiles/en-us.js +3 -0
  183. package/out/locale/profiles/en-us.js.map +1 -1
  184. package/out/locale/profiles/fr-fr.d.ts +3 -0
  185. package/out/locale/profiles/fr-fr.d.ts.map +1 -1
  186. package/out/locale/profiles/fr-fr.js +3 -0
  187. package/out/locale/profiles/fr-fr.js.map +1 -1
  188. package/out/locale/profiles/ja-jp.d.ts +3 -0
  189. package/out/locale/profiles/ja-jp.d.ts.map +1 -1
  190. package/out/locale/profiles/ja-jp.js +3 -0
  191. package/out/locale/profiles/ja-jp.js.map +1 -1
  192. package/out/locale/registry.d.ts +3 -1
  193. package/out/locale/registry.d.ts.map +1 -1
  194. package/out/locale/registry.js +3 -1
  195. package/out/locale/registry.js.map +1 -1
  196. package/out/logging/shared.d.ts.map +1 -1
  197. package/out/logging/shared.js +1 -0
  198. package/out/logging/shared.js.map +1 -1
  199. package/out/logging/utils.js +1 -1
  200. package/out/logging/utils.js.map +1 -1
  201. package/out/objects.d.ts.map +1 -1
  202. package/out/objects.js +2 -2
  203. package/out/objects.js.map +1 -1
  204. package/out/pipeline/index.d.ts +2 -2
  205. package/out/pipeline/index.d.ts.map +1 -1
  206. package/out/pipeline/index.js +1 -1
  207. package/out/pipeline/index.js.map +1 -1
  208. package/out/pipeline/reconcile-lookups.d.ts.map +1 -1
  209. package/out/pipeline/reconcile-lookups.js.map +1 -1
  210. package/out/pipeline/reconcile.d.ts +30 -10
  211. package/out/pipeline/reconcile.d.ts.map +1 -1
  212. package/out/pipeline/reconcile.js +12 -9
  213. package/out/pipeline/reconcile.js.map +1 -1
  214. package/out/pipeline/runtime-pipeline.d.ts +22 -0
  215. package/out/pipeline/runtime-pipeline.d.ts.map +1 -1
  216. package/out/pipeline/runtime-pipeline.js +94 -42
  217. package/out/pipeline/runtime-pipeline.js.map +1 -1
  218. package/out/pipeline/span-logit-aggregation.d.ts.map +1 -1
  219. package/out/pipeline/span-logit-aggregation.js +5 -2
  220. package/out/pipeline/span-logit-aggregation.js.map +1 -1
  221. package/out/pipeline/span-proposer.d.ts +19 -9
  222. package/out/pipeline/span-proposer.d.ts.map +1 -1
  223. package/out/pipeline/span-proposer.js +42 -22
  224. package/out/pipeline/span-proposer.js.map +1 -1
  225. package/out/pipeline/types.d.ts +82 -23
  226. package/out/pipeline/types.d.ts.map +1 -1
  227. package/out/pipeline/types.js +16 -0
  228. package/out/pipeline/types.js.map +1 -1
  229. package/out/policy/proposal-collection.d.ts +1 -1
  230. package/out/policy/proposal-collection.d.ts.map +1 -1
  231. package/out/policy/proposal-collection.js +2 -3
  232. package/out/policy/proposal-collection.js.map +1 -1
  233. package/out/policy/registry.d.ts +9 -3
  234. package/out/policy/registry.d.ts.map +1 -1
  235. package/out/policy/registry.js +9 -3
  236. package/out/policy/registry.js.map +1 -1
  237. package/out/resolver/index.d.ts +2 -2
  238. package/out/resolver/index.d.ts.map +1 -1
  239. package/out/resolver/index.js +1 -1
  240. package/out/resolver/index.js.map +1 -1
  241. package/out/resolver/types.d.ts +172 -25
  242. package/out/resolver/types.d.ts.map +1 -1
  243. package/out/resolver/types.js +16 -0
  244. package/out/resolver/types.js.map +1 -1
  245. package/out/resources/LocaleIndex.d.ts +1 -1
  246. package/out/resources/LocaleIndex.d.ts.map +1 -1
  247. package/out/resources/LocaleIndex.js +1 -2
  248. package/out/resources/LocaleIndex.js.map +1 -1
  249. package/out/resources/ResourceMapCache.d.ts.map +1 -1
  250. package/out/resources/ResourceMapCache.js +1 -1
  251. package/out/resources/ResourceMapCache.js.map +1 -1
  252. package/out/resources/collections.d.ts.map +1 -1
  253. package/out/resources/collections.js +3 -1
  254. package/out/resources/collections.js.map +1 -1
  255. package/out/resources/languages/index.d.ts +1 -1
  256. package/out/resources/languages/index.d.ts.map +1 -1
  257. package/out/resources/languages/index.js +1 -1
  258. package/out/resources/languages/index.js.map +1 -1
  259. package/out/resources/libpostal.d.ts +1 -1
  260. package/out/resources/libpostal.d.ts.map +1 -1
  261. package/out/resources/libpostal.js +7 -5
  262. package/out/resources/libpostal.js.map +1 -1
  263. package/out/resources/set.js +6 -6
  264. package/out/resources/set.js.map +1 -1
  265. package/out/resources/whosonfirst/DataSourceCache.d.ts +1 -4
  266. package/out/resources/whosonfirst/DataSourceCache.d.ts.map +1 -1
  267. package/out/resources/whosonfirst/DataSourceCache.js +1 -20
  268. package/out/resources/whosonfirst/DataSourceCache.js.map +1 -1
  269. package/out/resources/whosonfirst/PlacetypeDataSource.d.ts +1 -1
  270. package/out/resources/whosonfirst/PlacetypeDataSource.d.ts.map +1 -1
  271. package/out/resources/whosonfirst/PlacetypeDataSource.js +2 -2
  272. package/out/resources/whosonfirst/PlacetypeDataSource.js.map +1 -1
  273. package/out/resources/whosonfirst/backoff.d.ts +19 -0
  274. package/out/resources/whosonfirst/backoff.d.ts.map +1 -0
  275. package/out/resources/whosonfirst/backoff.js +35 -0
  276. package/out/resources/whosonfirst/backoff.js.map +1 -0
  277. package/out/resources/whosonfirst/loader.d.ts +1 -1
  278. package/out/resources/whosonfirst/loader.d.ts.map +1 -1
  279. package/out/resources/whosonfirst/loader.js +0 -1
  280. package/out/resources/whosonfirst/loader.js.map +1 -1
  281. package/out/resources/whosonfirst/placetypes/Placetype.d.ts +4 -1
  282. package/out/resources/whosonfirst/placetypes/Placetype.d.ts.map +1 -1
  283. package/out/resources/whosonfirst/placetypes/Placetype.js +8 -6
  284. package/out/resources/whosonfirst/placetypes/Placetype.js.map +1 -1
  285. package/out/resources/whosonfirst/placetypes/admin.d.ts +6 -4
  286. package/out/resources/whosonfirst/placetypes/admin.d.ts.map +1 -1
  287. package/out/resources/whosonfirst/placetypes/admin.js +8 -4
  288. package/out/resources/whosonfirst/placetypes/admin.js.map +1 -1
  289. package/out/resources/whosonfirst/placetypes/definition.d.ts +5 -6
  290. package/out/resources/whosonfirst/placetypes/definition.d.ts.map +1 -1
  291. package/out/resources/whosonfirst/placetypes/definition.js +3 -0
  292. package/out/resources/whosonfirst/placetypes/definition.js.map +1 -1
  293. package/out/resources/whosonfirst/placetypes/graph.d.ts +4 -2
  294. package/out/resources/whosonfirst/placetypes/graph.d.ts.map +1 -1
  295. package/out/resources/whosonfirst/placetypes/graph.js +0 -0
  296. package/out/resources/whosonfirst/placetypes/graph.js.map +1 -1
  297. package/out/resources/whosonfirst/placetypes/mermaid.d.ts +4 -2
  298. package/out/resources/whosonfirst/placetypes/mermaid.d.ts.map +1 -1
  299. package/out/resources/whosonfirst/placetypes/mermaid.js +0 -1
  300. package/out/resources/whosonfirst/placetypes/mermaid.js.map +1 -1
  301. package/out/resources/whosonfirst/placetypes/tree.d.ts +1 -1
  302. package/out/resources/whosonfirst/placetypes/tree.d.ts.map +1 -1
  303. package/out/resources/whosonfirst/placetypes/tree.js +0 -1
  304. package/out/resources/whosonfirst/placetypes/tree.js.map +1 -1
  305. package/out/routing/index.d.ts.map +1 -1
  306. package/out/routing/index.js +1 -1
  307. package/out/routing/index.js.map +1 -1
  308. package/out/scripting/utils/index.d.ts +3 -1
  309. package/out/scripting/utils/index.d.ts.map +1 -1
  310. package/out/scripting/utils/index.js +3 -1
  311. package/out/scripting/utils/index.js.map +1 -1
  312. package/out/tokenization/Span.js.map +1 -1
  313. package/out/tokenization/normalizer.js +11 -11
  314. package/out/tokenization/normalizer.js.map +1 -1
  315. package/out/tools/download-libpostal-resources.d.ts.map +1 -1
  316. package/out/tools/download-libpostal-resources.js.map +1 -1
  317. package/out/tools/download-ssl-address.d.ts +9 -3
  318. package/out/tools/download-ssl-address.d.ts.map +1 -1
  319. package/out/tools/download-ssl-address.js +8 -4
  320. package/out/tools/download-ssl-address.js.map +1 -1
  321. package/out/tools/generate-language-types.d.ts +12 -4
  322. package/out/tools/generate-language-types.d.ts.map +1 -1
  323. package/out/tools/generate-language-types.js +3 -1
  324. package/out/tools/generate-language-types.js.map +1 -1
  325. package/out/types/Classification.d.ts.map +1 -1
  326. package/out/types/Classification.js.map +1 -1
  327. package/out/types/classifier.d.ts +27 -9
  328. package/out/types/classifier.d.ts.map +1 -1
  329. package/out/types/component.d.ts +6 -2
  330. package/out/types/component.d.ts.map +1 -1
  331. package/out/types/component.js.map +1 -1
  332. package/out/utils/data-root.d.ts +3 -1
  333. package/out/utils/data-root.d.ts.map +1 -1
  334. package/out/utils/data-root.js +3 -1
  335. package/out/utils/data-root.js.map +1 -1
  336. package/out/utils/hash.d.ts +6 -2
  337. package/out/utils/hash.d.ts.map +1 -1
  338. package/out/utils/hash.js +6 -2
  339. package/out/utils/hash.js.map +1 -1
  340. package/out/utils/jsonl.d.ts +9 -3
  341. package/out/utils/jsonl.d.ts.map +1 -1
  342. package/out/utils/jsonl.js +9 -3
  343. package/out/utils/jsonl.js.map +1 -1
  344. package/out/utils/python-json.d.ts +6 -2
  345. package/out/utils/python-json.d.ts.map +1 -1
  346. package/out/utils/python-json.js +9 -3
  347. package/out/utils/python-json.js.map +1 -1
  348. package/out/utils/python-random.d.ts +15 -5
  349. package/out/utils/python-random.d.ts.map +1 -1
  350. package/out/utils/python-random.js +17 -7
  351. package/out/utils/python-random.js.map +1 -1
  352. package/out/utils/repo.d.ts +4 -0
  353. package/out/utils/repo.d.ts.map +1 -1
  354. package/out/utils/repo.js +4 -0
  355. package/out/utils/repo.js.map +1 -1
  356. package/out/utils/sealed-db.d.ts +6 -2
  357. package/out/utils/sealed-db.d.ts.map +1 -1
  358. package/out/utils/sealed-db.js +6 -2
  359. package/out/utils/sealed-db.js.map +1 -1
  360. package/out/utils/stats.d.ts +9 -3
  361. package/out/utils/stats.d.ts.map +1 -1
  362. package/out/utils/stats.js +11 -5
  363. package/out/utils/stats.js.map +1 -1
  364. package/package.json +2 -2
  365. package/pipeline/index.ts +5 -1
  366. package/pipeline/reconcile-lookups.ts +3 -0
  367. package/pipeline/reconcile.ts +65 -24
  368. package/pipeline/runtime-pipeline.ts +118 -42
  369. package/pipeline/span-logit-aggregation.ts +7 -2
  370. package/pipeline/span-proposer.ts +95 -34
  371. package/pipeline/types.ts +93 -23
  372. package/policy/proposal-collection.ts +4 -3
  373. package/policy/registry.ts +13 -3
  374. package/resolver/index.ts +11 -1
  375. package/resolver/types.ts +187 -25
  376. package/resources/LocaleIndex.ts +2 -2
  377. package/resources/ResourceMapCache.ts +3 -2
  378. package/resources/collections.ts +4 -1
  379. package/resources/languages/index.ts +2 -1
  380. package/resources/libpostal.ts +6 -3
  381. package/resources/set.ts +6 -6
  382. package/resources/whosonfirst/DataSourceCache.ts +2 -24
  383. package/resources/whosonfirst/PlacetypeDataSource.ts +2 -2
  384. package/resources/whosonfirst/backoff.ts +39 -0
  385. package/resources/whosonfirst/loader.ts +2 -1
  386. package/resources/whosonfirst/placetypes/Placetype.ts +9 -6
  387. package/resources/whosonfirst/placetypes/admin.ts +12 -7
  388. package/resources/whosonfirst/placetypes/definition.ts +6 -6
  389. package/resources/whosonfirst/placetypes/graph.ts +0 -0
  390. package/resources/whosonfirst/placetypes/mermaid.ts +5 -2
  391. package/resources/whosonfirst/placetypes/tree.ts +1 -1
  392. package/routing/index.ts +5 -1
  393. package/scripting/utils/index.ts +3 -1
  394. package/tokenization/Span.ts +1 -1
  395. package/tokenization/normalizer.ts +11 -11
  396. package/tools/download-libpostal-resources.ts +1 -0
  397. package/tools/download-ssl-address.ts +19 -7
  398. package/tools/generate-language-types.ts +12 -4
  399. package/types/Classification.ts +5 -0
  400. package/types/classifier.ts +27 -9
  401. package/types/component.ts +6 -2
  402. package/utils/data-root.ts +3 -1
  403. package/utils/hash.ts +6 -2
  404. package/utils/jsonl.ts +11 -3
  405. package/utils/python-json.ts +13 -4
  406. package/utils/python-random.ts +17 -7
  407. package/utils/repo.ts +8 -0
  408. package/utils/sealed-db.ts +10 -2
  409. package/utils/stats.ts +11 -5
package/resolver/index.ts CHANGED
@@ -11,12 +11,22 @@
11
11
  * `@mailwoman/codex`.
12
12
  */
13
13
 
14
- export { DEFAULT_PLACETYPE_MAP, PLACETYPE_FILTER_GROUPS, expandPlacetypeFilter, isPlacetypeFallback } from "./types.ts"
14
+ export {
15
+ DEFAULT_PLACETYPE_MAP,
16
+ PLACETYPE_FILTER_GROUPS,
17
+ expandPlacetypeFilter,
18
+ hardCountrySafelistFromCoverage,
19
+ isPlacetypeFallback,
20
+ } from "./types.ts"
21
+
15
22
  export type {
16
23
  AddressPointHit,
17
24
  AddressPointLookup,
18
25
  Ancestor,
19
26
  CoincidentLocality,
27
+ CountryBBoxFact,
28
+ CountryCoverageFact,
29
+ GazetteerArtifactCoverage,
20
30
  InterpolatedPointHit,
21
31
  InterpolationLookup,
22
32
  PlacetypeMap,
package/resolver/types.ts CHANGED
@@ -21,19 +21,33 @@ import type { AddressTree, ComponentTag } from "../decoder/types.ts"
21
21
  * `ResolvedPlace` is expected.
22
22
  */
23
23
  export interface ResolvedPlace {
24
- /** Resolver-specific place identifier (e.g. WOF id). */
24
+ /**
25
+ * Resolver-specific place identifier (e.g. WOF id).
26
+ */
25
27
  id: number | string
26
- /** Canonical name of the place as the resolver knows it. */
28
+ /**
29
+ * Canonical name of the place as the resolver knows it.
30
+ */
27
31
  name: string
28
- /** Resolver's placetype taxonomy label (e.g. WOF's `country` / `region` / `locality`). */
32
+ /**
33
+ * Resolver's placetype taxonomy label (e.g. WOF's `country` / `region` / `locality`).
34
+ */
29
35
  placetype: string
30
- /** ISO 3166-1 alpha-2 country code, if known. */
36
+ /**
37
+ * ISO 3166-1 alpha-2 country code, if known.
38
+ */
31
39
  country: string
32
- /** Centroid latitude in WGS-84 decimal degrees. */
40
+ /**
41
+ * Centroid latitude in WGS-84 decimal degrees.
42
+ */
33
43
  lat: number
34
- /** Centroid longitude in WGS-84 decimal degrees. */
44
+ /**
45
+ * Centroid longitude in WGS-84 decimal degrees.
46
+ */
35
47
  lon: number
36
- /** Parent place id within the resolver's hierarchy, if any. */
48
+ /**
49
+ * Parent place id within the resolver's hierarchy, if any.
50
+ */
37
51
  parent_id?: number | string
38
52
  /**
39
53
  * Resolver-defined ranking score. Higher = better fit for the query. Scale is implementation- defined; callers should
@@ -83,6 +97,99 @@ export interface ResolvedPlace {
83
97
  * Structurally compatible with `PlaceLookup` from `@mailwoman/core/resolver-wof-sqlite` so the latter satisfies this
84
98
  * interface without an adapter shim.
85
99
  */
100
+ /**
101
+ * One country's measured hard-filter coverage fact, as recorded at a promote gate. Facts about the gazetteer artifact
102
+ * live IN the artifact (the `country_coverage` table the gazetteer build emits) — code constants are only the fallback
103
+ * for artifacts that predate the manifest.
104
+ *
105
+ * Meaning-of-zero discipline: a country ABSENT from the coverage map was never measured — never "measured and failed".
106
+ * A measured-and-failed country is PRESENT with `hardFilterSafe: false` (e.g. FI at 69.5% hard-resolve), so the
107
+ * negative result is a first-class record, distinguishable from ignorance.
108
+ */
109
+ export interface CountryCoverageFact {
110
+ /**
111
+ * ISO 3166-1 alpha-2, uppercase.
112
+ */
113
+ country: string
114
+ /**
115
+ * The promote-gate VERDICT: hard-filtering this country is a pure win (a hard-filter miss is almost always a genuine
116
+ * non-match, not a coverage gap). Stored as a verdict — not re-derived from `hardResolveRate` at read time — because
117
+ * the gate is a judgment over a panel, not a pure rate function (CA cleared at the #928 promote on the
118
+ * postcode-format-prior rationale despite a sub-95% panel resolve rate).
119
+ */
120
+ hardFilterSafe: boolean
121
+ /**
122
+ * Measured hard-resolve rate (0..1) on the panel named in `source`, when the receipt recorded one.
123
+ */
124
+ hardResolveRate?: number
125
+ /**
126
+ * Panel size behind `hardResolveRate`, when recorded.
127
+ */
128
+ sampleSize?: number
129
+ /**
130
+ * ISO-8601 date of the measurement / promote gate.
131
+ */
132
+ measuredAt: string
133
+ /**
134
+ * The receipt: which panel/gate produced this row (issue + date, human-readable).
135
+ */
136
+ source: string
137
+ }
138
+
139
+ /**
140
+ * One country's coarse guard-B bounding box, as carried by the gazetteer artifact's `country_bbox` table.
141
+ */
142
+ export interface CountryBBoxFact {
143
+ /**
144
+ * ISO 3166-1 alpha-2, uppercase.
145
+ */
146
+ country: string
147
+ latMin: number
148
+ latMax: number
149
+ lonMin: number
150
+ lonMax: number
151
+ /**
152
+ * Provenance of the box (harness + date).
153
+ */
154
+ source: string
155
+ }
156
+
157
+ /**
158
+ * Facts a loaded gazetteer artifact declares about itself — read from the artifact's own manifest tables at open time,
159
+ * carried on the {@link ResolverBackend}/{@link Resolver} handle so consumers read the facts from the artifact they are
160
+ * actually resolving against. `undefined` on the handle = the artifact predates the manifest → consumers fall back to
161
+ * the code constants (byte-identical legacy behavior).
162
+ */
163
+ export interface GazetteerArtifactCoverage {
164
+ /**
165
+ * Country → measured coverage fact. ABSENCE = never measured (meaning-of-zero), never "failed".
166
+ */
167
+ countryCoverage: ReadonlyMap<string, CountryCoverageFact>
168
+ /**
169
+ * Country → guard-B bbox. ABSENCE = no box → the plausibility guard fails open for that country.
170
+ */
171
+ countryBBoxes: ReadonlyMap<string, CountryBBoxFact>
172
+ /**
173
+ * Derived at load: the countries whose fact says `hardFilterSafe` — the artifact's hard-country safelist.
174
+ */
175
+ hardCountrySafelist: ReadonlySet<string>
176
+ }
177
+
178
+ /**
179
+ * Derive the hard-country safelist from coverage facts — the ONE derivation both the reader and the build share.
180
+ */
181
+ export function hardCountrySafelistFromCoverage(facts: Iterable<CountryCoverageFact>): ReadonlySet<string> {
182
+ const out = new Set<string>()
183
+
184
+ for (const fact of facts) {
185
+ if (fact.hardFilterSafe) {
186
+ out.add(fact.country.toUpperCase())
187
+ }
188
+ }
189
+
190
+ return out
191
+ }
192
+
86
193
  export interface ResolverBackend {
87
194
  findPlace(query: {
88
195
  text: string
@@ -95,7 +202,9 @@ export interface ResolverBackend {
95
202
  * recovering localities the name-match alone misses. Backends without postcode support ignore it.
96
203
  */
97
204
  postcode?: string
98
- /** Proximity-bias points — a SOFT prominence re-rank; backends without support ignore it. */
205
+ /**
206
+ * Proximity-bias points — a SOFT prominence re-rank; backends without support ignore it.
207
+ */
99
208
  bias?: Array<{ lat: number; lon: number; weight?: number }>
100
209
  limit?: number
101
210
  }): Promise<ResolvedPlace[]>
@@ -113,9 +222,16 @@ export interface ResolverBackend {
113
222
  * `ancestors` table.
114
223
  */
115
224
  ancestors?(id: number | string): Ancestor[]
225
+ /**
226
+ * Facts the loaded gazetteer artifact declares about itself (its coverage-manifest tables, read at open). OPTIONAL —
227
+ * absent when the artifact predates the manifest, and consumers fall back to the code constants.
228
+ */
229
+ artifactCoverage?: GazetteerArtifactCoverage
116
230
  }
117
231
 
118
- /** One link in a resolved place's containment lineage ({@link ResolverBackend.ancestors}, #404). */
232
+ /**
233
+ * One link in a resolved place's containment lineage ({@link ResolverBackend.ancestors}, #404).
234
+ */
119
235
  export interface Ancestor {
120
236
  id: number | string
121
237
  placetype: string
@@ -131,9 +247,13 @@ export interface CoincidentLocality extends ResolvedPlace {
131
247
  * `city-state` / `capital-seat` / `consolidated-county` — surfaced as `metadata.relationship_type`.
132
248
  */
133
249
  relationshipType: string
134
- /** Locality population (0 when unknown) — the PRIMARY disambiguator when an admin has several. */
250
+ /**
251
+ * Locality population (0 when unknown) — the PRIMARY disambiguator when an admin has several.
252
+ */
135
253
  population: number
136
- /** Centroid distance (km) admin↔locality from the relation — the population tiebreak. */
254
+ /**
255
+ * Centroid distance (km) admin↔locality from the relation — the population tiebreak.
256
+ */
137
257
  distanceKm: number
138
258
  }
139
259
 
@@ -147,9 +267,13 @@ export interface CoincidentLocality extends ResolvedPlace {
147
267
  export interface AddressPointHit {
148
268
  lat: number
149
269
  lon: number
150
- /** Provenance, e.g. `"overture:NAD"`. */
270
+ /**
271
+ * Provenance, e.g. `"overture:NAD"`.
272
+ */
151
273
  source: string
152
- /** Pinned data release the point came from, e.g. `"2026-05-20.0"`. */
274
+ /**
275
+ * Pinned data release the point came from, e.g. `"2026-05-20.0"`.
276
+ */
153
277
  release: string
154
278
  }
155
279
 
@@ -187,11 +311,17 @@ export interface InterpolatedPointHit {
187
311
  * `address_point` = bracketed between real neighbor points; `tiger_range` = linear within a segment range.
188
312
  */
189
313
  method: "address_point" | "tiger_range"
190
- /** False when only the opposite side's range contained the number (right block, wrong side). */
314
+ /**
315
+ * False when only the opposite side's range contained the number (right block, wrong side).
316
+ */
191
317
  parityMatched?: boolean
192
- /** `both` = neighbors bracketed it; `single` = one-sided extrapolation (larger uncertainty). */
318
+ /**
319
+ * `both` = neighbors bracketed it; `single` = one-sided extrapolation (larger uncertainty).
320
+ */
193
321
  bracket?: "both" | "single"
194
- /** Honest uncertainty radius in METERS (half the matched segment length). */
322
+ /**
323
+ * Honest uncertainty radius in METERS (half the matched segment length).
324
+ */
195
325
  uncertaintyM: number
196
326
  source: string
197
327
  release: string
@@ -204,6 +334,17 @@ export interface InterpolatedPointHit {
204
334
  */
205
335
  export interface InterpolationLookup {
206
336
  find(query: { street: string; number: string; postcode?: string }): InterpolatedPointHit | null
337
+ /**
338
+ * The ARTIFACT's own conformal radius multiplier for `uncertaintyM` (#374), read from the shard's
339
+ * `interp_calibration` metadata table at open time (the pair-index δ/transitionBeta header precedent): the multiplier
340
+ * is a property of the calibration set the artifact was built against, so it ships in the artifact, not in caller
341
+ * code. The resolver applies it as the DEFAULT whenever `ResolveOpts.interpolationRadiusCalibration` is absent.
342
+ * `undefined` (or an implementation without the property) = the artifact carries none — shards built before the
343
+ * metadata table existed; behavior is then exactly the pre-artifact ladder (caller-supplied factor or raw).
344
+ * Implementations must read this at OPEN time (constructor/factory), never per-lookup — `find()` is synchronous by
345
+ * design.
346
+ */
347
+ readonly radiusCalibration?: number
207
348
  }
208
349
 
209
350
  /**
@@ -216,7 +357,9 @@ export interface InterpolationLookup {
216
357
  export interface StreetCentroidHit {
217
358
  lat: number
218
359
  lon: number
219
- /** Honest coarse radius in METERS — half the street's bounding-box diagonal. */
360
+ /**
361
+ * Honest coarse radius in METERS — half the street's bounding-box diagonal.
362
+ */
220
363
  uncertaintyM: number
221
364
  source: string
222
365
  release: string
@@ -350,14 +493,20 @@ export interface ResolveOpts {
350
493
  */
351
494
  interpolation?: InterpolationLookup
352
495
  /**
353
- * Conformal calibration multiplier for the interpolation tier's `uncertainty_m` (#374). The raw radius is half the
354
- * matched TIGER segment length — an honest-but-TIGHT prior: a split-conformal calibration on 1562 Travis-County
355
- * interp hits (2026-06-14) found it covers only ~72% of true errors, and that multiplying by **Q̂ ≈ 1.70** yields a
356
- * calibrated 90% bound (91.5% empirical). When set, `applyInterpolation` reports `uncertainty_m = round(raw × this)`
357
- * and preserves the raw value under `uncertainty_raw_m`. Absent = raw heuristic (byte-stable). The factor is the
358
- * CALLER's (it's a property of the calibration set, not the geometry); the geocode CLI passes the TX-derived 1.70.
359
- * Re-calibrate on a multi-region holdout before treating it as national-exact. Report:
496
+ * Conformal calibration multiplier OVERRIDE for the interpolation tier's `uncertainty_m` (#374). The raw radius is
497
+ * half the matched TIGER segment length — an honest-but-TIGHT prior: a split-conformal calibration on 1562
498
+ * Travis-County interp hits (2026-06-14) found it covers only ~72% of true errors, and that multiplying by **Q̂ ≈
499
+ * 1.70** yields a calibrated 90% bound (91.5% empirical). When a factor applies, `applyInterpolation` reports
500
+ * `uncertainty_m = round(raw × factor)` and preserves the raw value under `uncertainty_raw_m`.
501
+ *
502
+ * The factor is a property of the CALIBRATION SET the artifact was built against, so it ships IN the artifact:
503
+ * {@link InterpolationLookup.radiusCalibration} (the shard's `interp_calibration` metadata table, read at open time)
504
+ * is the default whenever this option is absent. Absent + artifact-silent = raw heuristic (byte-stable — shards
505
+ * predating the metadata table; production callers fall back to their in-code per-region table for those). Report:
360
506
  * docs/articles/evals/calibration/2026-06-14-interp-radius-calibration.md.
507
+ *
508
+ * @internal Instrument knob (D3) — measurement decomposition + legacy-shard fallback only; the artifact header IS
509
+ * the shipped calibration. Set it only to override the artifact's value.
361
510
  */
362
511
  interpolationRadiusCalibration?: number
363
512
  /**
@@ -450,7 +599,9 @@ export interface ResolveOpts {
450
599
  */
451
600
  adminCoherence?: boolean
452
601
  hierarchyCompletion?: boolean
453
- /** @deprecated Renamed to {@link hierarchyCompletion} (#405 generalized #387). Still honored. */
602
+ /**
603
+ * @deprecated Renamed to {@link hierarchyCompletion} (#405 generalized #387). Still honored.
604
+ */
454
605
  cityStateFallback?: boolean
455
606
  /**
456
607
  * Attach each resolved node's ancestor lineage (#404) — the containment chain (county → region → country) the
@@ -476,6 +627,10 @@ export interface ResolveOpts {
476
627
  */
477
628
  export type PlacetypeMap = Partial<Record<ComponentTag, string>>
478
629
 
630
+ /**
631
+ * Placetype equivalences applied when a backend does not supply its own. A `locality` query must also reach `borough`
632
+ * and `localadmin` rows — Brooklyn is a borough, and a strict filter made it unreachable.
633
+ */
479
634
  export const DEFAULT_PLACETYPE_MAP: PlacetypeMap = {
480
635
  country: "country",
481
636
  region: "region",
@@ -529,6 +684,7 @@ export const PLACETYPE_FILTER_GROUPS: Readonly<Record<string, readonly string[]>
529
684
  export function expandPlacetypeFilter(placetypes: null): null
530
685
  export function expandPlacetypeFilter(placetypes: readonly string[]): string[]
531
686
  export function expandPlacetypeFilter(placetypes: readonly string[] | null): string[] | null
687
+
532
688
  export function expandPlacetypeFilter(placetypes: readonly string[] | null): string[] | null {
533
689
  if (!placetypes) return null
534
690
  const out: string[] = []
@@ -581,4 +737,10 @@ export function isPlacetypeFallback(requestedPlacetype: string, candidatePlacety
581
737
  */
582
738
  export interface Resolver {
583
739
  resolveTree(tree: AddressTree, opts?: ResolveOpts): Promise<AddressTree>
740
+ /**
741
+ * Facts the loaded gazetteer artifact declares about itself, passed through from the {@link ResolverBackend} so
742
+ * pipeline-level consumers (the hard-country coverage gate, guard-B plausibility) read them from the handle they
743
+ * already hold. Absent = artifact predates the manifest → code-constant fallback.
744
+ */
745
+ artifactCoverage?: GazetteerArtifactCoverage
584
746
  }
@@ -4,7 +4,7 @@
4
4
  * @author Teffen Ellis, et al.
5
5
  */
6
6
 
7
- import { TextNormalizer } from "../tokenization/normalizer.ts"
7
+ import type { TextNormalizer } from "../tokenization/normalizer.ts"
8
8
  import type { Displayable } from "./debugging.ts"
9
9
 
10
10
  /**
@@ -49,7 +49,7 @@ export class LocaleIndex<LanguageCodes extends string> extends Map<string, Set<L
49
49
  * @param languageCodes The language codes to associate with the placename.
50
50
  */
51
51
  public add(placename: string, ...languageCodes: LanguageCodes[]): void {
52
- if (languageCodes.length === 0) {
52
+ if (!languageCodes.length) {
53
53
  throw new Error(`At least one language code must be provided for "${placename}".`)
54
54
  }
55
55
 
@@ -10,6 +10,7 @@
10
10
  export type DisposableLike = Disposable | AsyncDisposable
11
11
 
12
12
  export type ResourceConstructor<K extends PropertyKey, R extends DisposableLike> = new (key: K) => R
13
+
13
14
  export type ResourceFactory<K extends PropertyKey, R extends DisposableLike> = (key: K) => R | Promise<R>
14
15
 
15
16
  export type ResourceFactoryLike<K extends PropertyKey = PropertyKey, R extends DisposableLike = DisposableLike> =
@@ -58,7 +59,7 @@ export class ResourceMapCache<
58
59
  /**
59
60
  * The human-readable name of the resource.
60
61
  */
61
- public displayName: string = "ResourceMapCache"
62
+ public displayName = "ResourceMapCache"
62
63
 
63
64
  protected readonly factoryLike: F
64
65
 
@@ -115,7 +116,7 @@ export class ResourceMapCache<
115
116
  }
116
117
 
117
118
  public async [Symbol.asyncDispose]() {
118
- const resourceKeys = Array.from(super.keys()).reverse()
119
+ const resourceKeys = Array.from(super.keys()).toReversed()
119
120
 
120
121
  for (const resourceKey of resourceKeys) {
121
122
  this.close(resourceKey)
@@ -27,6 +27,7 @@ export async function* takeInParallel<T, C extends (entry: T) => Promise<unknown
27
27
 
28
28
  let iterationResult = await iterator.next()
29
29
 
30
+ // oxlint-disable-next-line eslint/no-unmodified-loop-condition -- `abortSignal.aborted` is flipped by the controller, not by this loop
30
31
  while ((!iterationResult.done || results.size) && !abortSignal?.aborted) {
31
32
  for (const [key, result] of results) {
32
33
  yield result
@@ -36,6 +37,7 @@ export async function* takeInParallel<T, C extends (entry: T) => Promise<unknown
36
37
 
37
38
  if (runningTasks.size >= batchSize) {
38
39
  await Promise.race(runningTasks.values())
40
+
39
41
  continue
40
42
  }
41
43
 
@@ -47,6 +49,7 @@ export async function* takeInParallel<T, C extends (entry: T) => Promise<unknown
47
49
 
48
50
  const entry = iterationResult.value
49
51
 
52
+ // oxlint-disable-next-line promise/always-return -- the handle tracks completion, not a value
50
53
  const futureResult = callback(entry).then((result) => {
51
54
  runningTasks.delete(entry)
52
55
 
@@ -87,7 +90,7 @@ export async function* takeAsync<T>(collection: AsyncIterable<T>, batchSize: num
87
90
  }
88
91
  }
89
92
 
90
- if (buffer.length !== 0) {
93
+ if (buffer.length) {
91
94
  yield buffer
92
95
  }
93
96
  }
@@ -4,9 +4,10 @@
4
4
  * @author Teffen Ellis, et al.
5
5
  */
6
6
 
7
- export * from "./types.gen.ts"
8
7
  import { Alpha2LabelMap, Alpha2LanguageCode, Alpha3bLabelMap, type Alpha3bLanguageCode } from "./types.gen.ts"
9
8
 
9
+ export * from "./types.gen.ts"
10
+
10
11
  /**
11
12
  * Prefixed languages are those which use a street prefix instead of a suffix.
12
13
  */
@@ -8,9 +8,9 @@ import { readdir } from "node:fs/promises"
8
8
  import { availableParallelism } from "node:os"
9
9
 
10
10
  import { tryStat } from "@mailwoman/core/fs"
11
- import { Alpha2LanguageCode } from "@mailwoman/core/resources/languages"
11
+ import type { Alpha2LanguageCode } from "@mailwoman/core/resources/languages"
12
12
  import { TextNormalizer, type TextNormalizerInit } from "@mailwoman/core/tokenization"
13
- import { PathBuilder } from "path-ts"
13
+ import type { PathBuilder } from "path-ts"
14
14
  import pluralize from "pluralize"
15
15
  import { TextSpliterator } from "spliterator"
16
16
 
@@ -94,6 +94,7 @@ export async function prepareLocaleIndex(
94
94
  options?: LibPostalNormalizerInit
95
95
  ): Promise<LocaleIndex<LibPostalLanguageCode>> {
96
96
  const normalizer = new TextNormalizer(options)
97
+
97
98
  const index = new LocaleIndex<LibPostalLanguageCode>([], {
98
99
  displayName: "libpostal",
99
100
  normalizer,
@@ -107,6 +108,7 @@ export async function prepareLocaleIndex(
107
108
 
108
109
  for await (const batch of fileEntries) {
109
110
  await Promise.all(
111
+ // oxlint-disable-next-line no-loop-func -- the binding is per-iteration (for-of/for-await) and the batch is awaited before the next
110
112
  batch.map(async ({ filePath, languageCode }) => {
111
113
  const lines = TextSpliterator.fromAsync(filePath)
112
114
 
@@ -127,6 +129,7 @@ export async function prepareLocaleIndex(
127
129
 
128
130
  for await (const batch of internalFileEntries) {
129
131
  await Promise.all(
132
+ // oxlint-disable-next-line no-loop-func -- the binding is per-iteration (for-of/for-await) and the batch is awaited before the next
130
133
  batch.map(async ({ filePath, languageCode }) => {
131
134
  const lines = TextSpliterator.fromAsync(filePath)
132
135
 
@@ -155,7 +158,7 @@ export async function prepareLocaleIndex(
155
158
  )
156
159
  }
157
160
 
158
- if (index.size === 0 && !inserted) {
161
+ if (!index.size && !inserted) {
159
162
  throw new Error(
160
163
  `No index matches found for ${filename} in ${libPostalDataDirectory} for languages ${languageCodes}`
161
164
  )
package/resources/set.ts CHANGED
@@ -29,7 +29,7 @@ export class Sequence<T extends WeakKey> extends Set<T> {
29
29
  super(nodes)
30
30
 
31
31
  this.#first = nodes[0] ?? null
32
- this.#last = nodes[nodes.length - 1] ?? null
32
+ this.#last = nodes.at(-1) ?? null
33
33
  }
34
34
 
35
35
  /**
@@ -49,7 +49,7 @@ export class Sequence<T extends WeakKey> extends Set<T> {
49
49
  if (!nodes.length) return this
50
50
 
51
51
  for (const node of nodes) {
52
- if (typeof node === "undefined" || node === null) {
52
+ if (node === undefined || node === null) {
53
53
  throw new Error("Attempted to add an undefined or null node to a sequence.")
54
54
  }
55
55
 
@@ -60,7 +60,7 @@ export class Sequence<T extends WeakKey> extends Set<T> {
60
60
  this.#first = nodes[0]!
61
61
  }
62
62
 
63
- this.#last = nodes[nodes.length - 1]!
63
+ this.#last = nodes.at(-1)!
64
64
 
65
65
  return this
66
66
  }
@@ -69,7 +69,7 @@ export class Sequence<T extends WeakKey> extends Set<T> {
69
69
  * Delete a node from the sequence.
70
70
  */
71
71
  public override delete(node: T): boolean {
72
- if (typeof node === "undefined" || node === null) {
72
+ if (node === undefined || node === null) {
73
73
  throw new Error("Attempted to delete an undefined or null node from a sequence.")
74
74
  }
75
75
 
@@ -77,7 +77,7 @@ export class Sequence<T extends WeakKey> extends Set<T> {
77
77
 
78
78
  if (!deleted) return false
79
79
 
80
- if (this.size === 0) {
80
+ if (!this.size) {
81
81
  this.#first = null
82
82
  this.#last = null
83
83
  } else if (this.#first === node) {
@@ -104,7 +104,7 @@ export class Sequence<T extends WeakKey> extends Set<T> {
104
104
  }
105
105
 
106
106
  this.#first = currentEntries[0] ?? null
107
- this.#last = currentEntries[currentEntries.length - 1] ?? null
107
+ this.#last = currentEntries.at(-1) ?? null
108
108
 
109
109
  return this
110
110
  }
@@ -5,7 +5,6 @@
5
5
  */
6
6
 
7
7
  import { mkdirSync } from "node:fs"
8
- import { setTimeout } from "node:timers/promises"
9
8
 
10
9
  import type { Alpha3bLanguageCode } from "@mailwoman/core/resources/languages"
11
10
  import { dirname } from "path-ts"
@@ -13,6 +12,8 @@ import { dirname } from "path-ts"
13
12
  import { PlacetypeDataSource, type PlacetypeDataSourceOptions } from "./PlacetypeDataSource.ts"
14
13
  import type { WhosOnFirstPlacetype } from "./placetypes/definition.ts"
15
14
 
15
+ export { tryWithBackoff } from "./backoff.ts"
16
+
16
17
  export class DataSourceCache extends DisposableStack {
17
18
  #placetypeToLanguage = new Map<WhosOnFirstPlacetype, Map<Alpha3bLanguageCode, PlacetypeDataSource>>()
18
19
 
@@ -47,26 +48,3 @@ export class DataSourceCache extends DisposableStack {
47
48
  return dataSource
48
49
  }
49
50
  }
50
-
51
- /**
52
- * Given a callback, attempt to run it up to `attempts` times.
53
- */
54
- export async function tryWithBackoff<T>(attempts: number, callback: () => T): Promise<T> {
55
- let lastError: unknown
56
-
57
- for (let i = 0; i < attempts; i++) {
58
- try {
59
- const result = await callback()
60
-
61
- return result
62
- } catch (error) {
63
- lastError = error
64
- }
65
-
66
- // We try to avoid contention by giving a pause between attempts.
67
- const delay = Math.floor(Math.random() * 1000) + 1000 * attempts
68
- await setTimeout(delay)
69
- }
70
-
71
- throw lastError
72
- }
@@ -7,14 +7,14 @@
7
7
  import { DatabaseSync, type DatabaseSyncOptions, type SQLInputValue } from "node:sqlite"
8
8
 
9
9
  import {
10
- Alpha2LanguageCode,
10
+ type Alpha2LanguageCode,
11
11
  type Alpha3bLanguageCode,
12
12
  Alpha3bToAlpha2,
13
13
  isAlpha3bLanguageCode,
14
14
  } from "@mailwoman/core/resources/languages"
15
15
  import { PathBuilder, type PathBuilderLike } from "path-ts"
16
16
 
17
- import { tryWithBackoff } from "./DataSourceCache.ts"
17
+ import { tryWithBackoff } from "./backoff.ts"
18
18
  import type { WhosOnFirstPlacetype } from "./placetypes/definition.ts"
19
19
 
20
20
  export interface PlacetypeDataSourceOptions<
@@ -0,0 +1,39 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ * @file Retry-with-backoff helper for the Who's On First data sources.
6
+ *
7
+ * This lives apart from `DataSourceCache` because both that module and `PlacetypeDataSource` need
8
+ * it, and each already imports the other — putting it in either one closes an import cycle.
9
+ */
10
+
11
+ import { setTimeout } from "node:timers/promises"
12
+
13
+ /**
14
+ * Given a callback, attempt to run it up to `attempts` times.
15
+ *
16
+ * @param attempts Maximum number of tries before the last error is rethrown.
17
+ * @param callback The operation to attempt.
18
+ *
19
+ * @returns The callback's result from the first successful attempt.
20
+ */
21
+ export async function tryWithBackoff<T>(attempts: number, callback: () => T): Promise<T> {
22
+ let lastError: unknown
23
+
24
+ for (let i = 0; i < attempts; i++) {
25
+ try {
26
+ const result = await callback()
27
+
28
+ return result
29
+ } catch (error) {
30
+ lastError = error
31
+ }
32
+
33
+ // We try to avoid contention by giving a pause between attempts.
34
+ const delay = Math.floor(Math.random() * 1000) + 1000 * attempts
35
+ await setTimeout(delay)
36
+ }
37
+
38
+ throw lastError
39
+ }
@@ -5,7 +5,7 @@
5
5
  */
6
6
 
7
7
  import type { Alpha3bLanguageCode } from "@mailwoman/core/resources/languages"
8
- import { TextNormalizer } from "@mailwoman/core/tokenization"
8
+ import type { TextNormalizer } from "@mailwoman/core/tokenization"
9
9
  import FastGlob, { type Entry } from "fast-glob"
10
10
  import { PathBuilder, type PathBuilderLike } from "path-ts"
11
11
  import { TextSpliterator } from "spliterator"
@@ -21,6 +21,7 @@ import { parsePlacetypeSource } from "./placetypes/admin.ts"
21
21
  * If a value is present in this index, it means that the value is a valid value in at least one language.
22
22
  */
23
23
  export type WhosOnFirstLocaleIndex = Map<string, Set<string>>
24
+
24
25
  export type ReadonlyWhosOnFirstIndex = ReadonlyMap<string, ReadonlySet<string>>
25
26
 
26
27
  export interface WOFCacheOptions {