@mailwoman/core 8.1.0 → 8.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (407) 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 +6 -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 +6 -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 +18 -0
  215. package/out/pipeline/runtime-pipeline.d.ts.map +1 -1
  216. package/out/pipeline/runtime-pipeline.js +73 -46
  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 +77 -19
  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.map +1 -1
  238. package/out/resolver/types.d.ts +94 -30
  239. package/out/resolver/types.d.ts.map +1 -1
  240. package/out/resolver/types.js +7 -1
  241. package/out/resolver/types.js.map +1 -1
  242. package/out/resources/LocaleIndex.d.ts +1 -1
  243. package/out/resources/LocaleIndex.d.ts.map +1 -1
  244. package/out/resources/LocaleIndex.js +1 -2
  245. package/out/resources/LocaleIndex.js.map +1 -1
  246. package/out/resources/ResourceMapCache.d.ts.map +1 -1
  247. package/out/resources/ResourceMapCache.js +1 -1
  248. package/out/resources/ResourceMapCache.js.map +1 -1
  249. package/out/resources/collections.d.ts.map +1 -1
  250. package/out/resources/collections.js +3 -1
  251. package/out/resources/collections.js.map +1 -1
  252. package/out/resources/languages/index.d.ts +1 -1
  253. package/out/resources/languages/index.d.ts.map +1 -1
  254. package/out/resources/languages/index.js +1 -1
  255. package/out/resources/languages/index.js.map +1 -1
  256. package/out/resources/libpostal.d.ts +1 -1
  257. package/out/resources/libpostal.d.ts.map +1 -1
  258. package/out/resources/libpostal.js +7 -5
  259. package/out/resources/libpostal.js.map +1 -1
  260. package/out/resources/set.js +6 -6
  261. package/out/resources/set.js.map +1 -1
  262. package/out/resources/whosonfirst/DataSourceCache.d.ts +1 -4
  263. package/out/resources/whosonfirst/DataSourceCache.d.ts.map +1 -1
  264. package/out/resources/whosonfirst/DataSourceCache.js +1 -20
  265. package/out/resources/whosonfirst/DataSourceCache.js.map +1 -1
  266. package/out/resources/whosonfirst/PlacetypeDataSource.d.ts +1 -1
  267. package/out/resources/whosonfirst/PlacetypeDataSource.d.ts.map +1 -1
  268. package/out/resources/whosonfirst/PlacetypeDataSource.js +2 -2
  269. package/out/resources/whosonfirst/PlacetypeDataSource.js.map +1 -1
  270. package/out/resources/whosonfirst/backoff.d.ts +19 -0
  271. package/out/resources/whosonfirst/backoff.d.ts.map +1 -0
  272. package/out/resources/whosonfirst/backoff.js +35 -0
  273. package/out/resources/whosonfirst/backoff.js.map +1 -0
  274. package/out/resources/whosonfirst/loader.d.ts +1 -1
  275. package/out/resources/whosonfirst/loader.d.ts.map +1 -1
  276. package/out/resources/whosonfirst/loader.js +0 -1
  277. package/out/resources/whosonfirst/loader.js.map +1 -1
  278. package/out/resources/whosonfirst/placetypes/Placetype.d.ts +4 -1
  279. package/out/resources/whosonfirst/placetypes/Placetype.d.ts.map +1 -1
  280. package/out/resources/whosonfirst/placetypes/Placetype.js +8 -6
  281. package/out/resources/whosonfirst/placetypes/Placetype.js.map +1 -1
  282. package/out/resources/whosonfirst/placetypes/admin.d.ts +6 -4
  283. package/out/resources/whosonfirst/placetypes/admin.d.ts.map +1 -1
  284. package/out/resources/whosonfirst/placetypes/admin.js +8 -4
  285. package/out/resources/whosonfirst/placetypes/admin.js.map +1 -1
  286. package/out/resources/whosonfirst/placetypes/definition.d.ts +5 -6
  287. package/out/resources/whosonfirst/placetypes/definition.d.ts.map +1 -1
  288. package/out/resources/whosonfirst/placetypes/definition.js +3 -0
  289. package/out/resources/whosonfirst/placetypes/definition.js.map +1 -1
  290. package/out/resources/whosonfirst/placetypes/graph.d.ts +4 -2
  291. package/out/resources/whosonfirst/placetypes/graph.d.ts.map +1 -1
  292. package/out/resources/whosonfirst/placetypes/graph.js +0 -0
  293. package/out/resources/whosonfirst/placetypes/graph.js.map +1 -1
  294. package/out/resources/whosonfirst/placetypes/mermaid.d.ts +4 -2
  295. package/out/resources/whosonfirst/placetypes/mermaid.d.ts.map +1 -1
  296. package/out/resources/whosonfirst/placetypes/mermaid.js +0 -1
  297. package/out/resources/whosonfirst/placetypes/mermaid.js.map +1 -1
  298. package/out/resources/whosonfirst/placetypes/tree.d.ts +1 -1
  299. package/out/resources/whosonfirst/placetypes/tree.d.ts.map +1 -1
  300. package/out/resources/whosonfirst/placetypes/tree.js +0 -1
  301. package/out/resources/whosonfirst/placetypes/tree.js.map +1 -1
  302. package/out/routing/index.d.ts.map +1 -1
  303. package/out/routing/index.js +1 -1
  304. package/out/routing/index.js.map +1 -1
  305. package/out/scripting/utils/index.d.ts +3 -1
  306. package/out/scripting/utils/index.d.ts.map +1 -1
  307. package/out/scripting/utils/index.js +3 -1
  308. package/out/scripting/utils/index.js.map +1 -1
  309. package/out/tokenization/Span.js.map +1 -1
  310. package/out/tokenization/normalizer.js +11 -11
  311. package/out/tokenization/normalizer.js.map +1 -1
  312. package/out/tools/download-libpostal-resources.d.ts.map +1 -1
  313. package/out/tools/download-libpostal-resources.js.map +1 -1
  314. package/out/tools/download-ssl-address.d.ts +9 -3
  315. package/out/tools/download-ssl-address.d.ts.map +1 -1
  316. package/out/tools/download-ssl-address.js +8 -4
  317. package/out/tools/download-ssl-address.js.map +1 -1
  318. package/out/tools/generate-language-types.d.ts +12 -4
  319. package/out/tools/generate-language-types.d.ts.map +1 -1
  320. package/out/tools/generate-language-types.js +3 -1
  321. package/out/tools/generate-language-types.js.map +1 -1
  322. package/out/types/Classification.d.ts.map +1 -1
  323. package/out/types/Classification.js.map +1 -1
  324. package/out/types/classifier.d.ts +27 -9
  325. package/out/types/classifier.d.ts.map +1 -1
  326. package/out/types/component.d.ts +8 -4
  327. package/out/types/component.d.ts.map +1 -1
  328. package/out/types/component.js +3 -3
  329. package/out/types/component.js.map +1 -1
  330. package/out/utils/data-root.d.ts +3 -1
  331. package/out/utils/data-root.d.ts.map +1 -1
  332. package/out/utils/data-root.js +3 -1
  333. package/out/utils/data-root.js.map +1 -1
  334. package/out/utils/hash.d.ts +6 -2
  335. package/out/utils/hash.d.ts.map +1 -1
  336. package/out/utils/hash.js +6 -2
  337. package/out/utils/hash.js.map +1 -1
  338. package/out/utils/jsonl.d.ts +9 -3
  339. package/out/utils/jsonl.d.ts.map +1 -1
  340. package/out/utils/jsonl.js +9 -3
  341. package/out/utils/jsonl.js.map +1 -1
  342. package/out/utils/python-json.d.ts +6 -2
  343. package/out/utils/python-json.d.ts.map +1 -1
  344. package/out/utils/python-json.js +9 -3
  345. package/out/utils/python-json.js.map +1 -1
  346. package/out/utils/python-random.d.ts +15 -5
  347. package/out/utils/python-random.d.ts.map +1 -1
  348. package/out/utils/python-random.js +17 -7
  349. package/out/utils/python-random.js.map +1 -1
  350. package/out/utils/repo.d.ts +4 -0
  351. package/out/utils/repo.d.ts.map +1 -1
  352. package/out/utils/repo.js +4 -0
  353. package/out/utils/repo.js.map +1 -1
  354. package/out/utils/sealed-db.d.ts +6 -2
  355. package/out/utils/sealed-db.d.ts.map +1 -1
  356. package/out/utils/sealed-db.js +6 -2
  357. package/out/utils/sealed-db.js.map +1 -1
  358. package/out/utils/stats.d.ts +9 -3
  359. package/out/utils/stats.d.ts.map +1 -1
  360. package/out/utils/stats.js +11 -5
  361. package/out/utils/stats.js.map +1 -1
  362. package/package.json +2 -2
  363. package/pipeline/index.ts +5 -1
  364. package/pipeline/reconcile-lookups.ts +3 -0
  365. package/pipeline/reconcile.ts +65 -24
  366. package/pipeline/runtime-pipeline.ts +95 -46
  367. package/pipeline/span-logit-aggregation.ts +7 -2
  368. package/pipeline/span-proposer.ts +95 -34
  369. package/pipeline/types.ts +88 -19
  370. package/policy/proposal-collection.ts +4 -3
  371. package/policy/registry.ts +13 -3
  372. package/resolver/index.ts +1 -0
  373. package/resolver/types.ts +95 -30
  374. package/resources/LocaleIndex.ts +2 -2
  375. package/resources/ResourceMapCache.ts +3 -2
  376. package/resources/collections.ts +4 -1
  377. package/resources/languages/index.ts +2 -1
  378. package/resources/libpostal.ts +6 -3
  379. package/resources/set.ts +6 -6
  380. package/resources/whosonfirst/DataSourceCache.ts +2 -24
  381. package/resources/whosonfirst/PlacetypeDataSource.ts +2 -2
  382. package/resources/whosonfirst/backoff.ts +39 -0
  383. package/resources/whosonfirst/loader.ts +2 -1
  384. package/resources/whosonfirst/placetypes/Placetype.ts +9 -6
  385. package/resources/whosonfirst/placetypes/admin.ts +12 -7
  386. package/resources/whosonfirst/placetypes/definition.ts +6 -6
  387. package/resources/whosonfirst/placetypes/graph.ts +0 -0
  388. package/resources/whosonfirst/placetypes/mermaid.ts +5 -2
  389. package/resources/whosonfirst/placetypes/tree.ts +1 -1
  390. package/routing/index.ts +5 -1
  391. package/scripting/utils/index.ts +3 -1
  392. package/tokenization/Span.ts +1 -1
  393. package/tokenization/normalizer.ts +11 -11
  394. package/tools/download-libpostal-resources.ts +1 -0
  395. package/tools/download-ssl-address.ts +19 -7
  396. package/tools/generate-language-types.ts +12 -4
  397. package/types/Classification.ts +5 -0
  398. package/types/classifier.ts +27 -9
  399. package/types/component.ts +9 -5
  400. package/utils/data-root.ts +3 -1
  401. package/utils/hash.ts +6 -2
  402. package/utils/jsonl.ts +11 -3
  403. package/utils/python-json.ts +13 -4
  404. package/utils/python-random.ts +17 -7
  405. package/utils/repo.ts +8 -0
  406. package/utils/sealed-db.ts +10 -2
  407. package/utils/stats.ts +11 -5
@@ -42,17 +42,23 @@ export class InMemoryPolicyRegistry implements PolicyRegistry {
42
42
  return registry
43
43
  }
44
44
 
45
- /** Install a policy entry. Replaces any prior entry with the same key. */
45
+ /**
46
+ * Install a policy entry. Replaces any prior entry with the same key.
47
+ */
46
48
  set(policy: ClassifierPolicy): void {
47
49
  this.#entries.set(policyKey(policy.component, policy.locale), policy)
48
50
  }
49
51
 
50
- /** Remove a policy entry, if present. */
52
+ /**
53
+ * Remove a policy entry, if present.
54
+ */
51
55
  remove(component: ComponentTag, locale?: string): void {
52
56
  this.#entries.delete(policyKey(component, locale))
53
57
  }
54
58
 
55
- /** All current entries, in insertion order. */
59
+ /**
60
+ * All current entries, in insertion order.
61
+ */
56
62
  entries(): ClassifierPolicy[] {
57
63
  return Array.from(this.#entries.values())
58
64
  }
@@ -63,6 +69,7 @@ export class InMemoryPolicyRegistry implements PolicyRegistry {
63
69
 
64
70
  if (localized) return localized
65
71
  }
72
+
66
73
  const global = this.#entries.get(policyKey(component, undefined))
67
74
 
68
75
  if (global) return global
@@ -127,18 +134,21 @@ function applyPreferenceFilters(
127
134
 
128
135
  if (!policy) {
129
136
  out.push(...list)
137
+
130
138
  continue
131
139
  }
132
140
 
133
141
  if (policy.mode === "neural_preferred") {
134
142
  const hasNeural = list.some((p) => p.source === "neural")
135
143
  out.push(...(hasNeural ? list.filter((p) => p.source !== "rule") : list))
144
+
136
145
  continue
137
146
  }
138
147
 
139
148
  if (policy.mode === "rule_preferred") {
140
149
  const hasRule = list.some((p) => p.source === "rule")
141
150
  out.push(...(hasRule ? list.filter((p) => p.source !== "neural") : list))
151
+
142
152
  continue
143
153
  }
144
154
 
package/resolver/index.ts CHANGED
@@ -18,6 +18,7 @@ export {
18
18
  hardCountrySafelistFromCoverage,
19
19
  isPlacetypeFallback,
20
20
  } from "./types.ts"
21
+
21
22
  export type {
22
23
  AddressPointHit,
23
24
  AddressPointLookup,
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
@@ -93,7 +107,9 @@ export interface ResolvedPlace {
93
107
  * negative result is a first-class record, distinguishable from ignorance.
94
108
  */
95
109
  export interface CountryCoverageFact {
96
- /** ISO 3166-1 alpha-2, uppercase. */
110
+ /**
111
+ * ISO 3166-1 alpha-2, uppercase.
112
+ */
97
113
  country: string
98
114
  /**
99
115
  * The promote-gate VERDICT: hard-filtering this country is a pure win (a hard-filter miss is almost always a genuine
@@ -102,25 +118,39 @@ export interface CountryCoverageFact {
102
118
  * postcode-format-prior rationale despite a sub-95% panel resolve rate).
103
119
  */
104
120
  hardFilterSafe: boolean
105
- /** Measured hard-resolve rate (0..1) on the panel named in `source`, when the receipt recorded one. */
121
+ /**
122
+ * Measured hard-resolve rate (0..1) on the panel named in `source`, when the receipt recorded one.
123
+ */
106
124
  hardResolveRate?: number
107
- /** Panel size behind `hardResolveRate`, when recorded. */
125
+ /**
126
+ * Panel size behind `hardResolveRate`, when recorded.
127
+ */
108
128
  sampleSize?: number
109
- /** ISO-8601 date of the measurement / promote gate. */
129
+ /**
130
+ * ISO-8601 date of the measurement / promote gate.
131
+ */
110
132
  measuredAt: string
111
- /** The receipt: which panel/gate produced this row (issue + date, human-readable). */
133
+ /**
134
+ * The receipt: which panel/gate produced this row (issue + date, human-readable).
135
+ */
112
136
  source: string
113
137
  }
114
138
 
115
- /** One country's coarse guard-B bounding box, as carried by the gazetteer artifact's `country_bbox` table. */
139
+ /**
140
+ * One country's coarse guard-B bounding box, as carried by the gazetteer artifact's `country_bbox` table.
141
+ */
116
142
  export interface CountryBBoxFact {
117
- /** ISO 3166-1 alpha-2, uppercase. */
143
+ /**
144
+ * ISO 3166-1 alpha-2, uppercase.
145
+ */
118
146
  country: string
119
147
  latMin: number
120
148
  latMax: number
121
149
  lonMin: number
122
150
  lonMax: number
123
- /** Provenance of the box (harness + date). */
151
+ /**
152
+ * Provenance of the box (harness + date).
153
+ */
124
154
  source: string
125
155
  }
126
156
 
@@ -131,15 +161,23 @@ export interface CountryBBoxFact {
131
161
  * the code constants (byte-identical legacy behavior).
132
162
  */
133
163
  export interface GazetteerArtifactCoverage {
134
- /** Country → measured coverage fact. ABSENCE = never measured (meaning-of-zero), never "failed". */
164
+ /**
165
+ * Country → measured coverage fact. ABSENCE = never measured (meaning-of-zero), never "failed".
166
+ */
135
167
  countryCoverage: ReadonlyMap<string, CountryCoverageFact>
136
- /** Country → guard-B bbox. ABSENCE = no box → the plausibility guard fails open for that country. */
168
+ /**
169
+ * Country → guard-B bbox. ABSENCE = no box → the plausibility guard fails open for that country.
170
+ */
137
171
  countryBBoxes: ReadonlyMap<string, CountryBBoxFact>
138
- /** Derived at load: the countries whose fact says `hardFilterSafe` — the artifact's hard-country safelist. */
172
+ /**
173
+ * Derived at load: the countries whose fact says `hardFilterSafe` — the artifact's hard-country safelist.
174
+ */
139
175
  hardCountrySafelist: ReadonlySet<string>
140
176
  }
141
177
 
142
- /** Derive the hard-country safelist from coverage facts — the ONE derivation both the reader and the build share. */
178
+ /**
179
+ * Derive the hard-country safelist from coverage facts — the ONE derivation both the reader and the build share.
180
+ */
143
181
  export function hardCountrySafelistFromCoverage(facts: Iterable<CountryCoverageFact>): ReadonlySet<string> {
144
182
  const out = new Set<string>()
145
183
 
@@ -164,7 +202,9 @@ export interface ResolverBackend {
164
202
  * recovering localities the name-match alone misses. Backends without postcode support ignore it.
165
203
  */
166
204
  postcode?: string
167
- /** 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
+ */
168
208
  bias?: Array<{ lat: number; lon: number; weight?: number }>
169
209
  limit?: number
170
210
  }): Promise<ResolvedPlace[]>
@@ -189,7 +229,9 @@ export interface ResolverBackend {
189
229
  artifactCoverage?: GazetteerArtifactCoverage
190
230
  }
191
231
 
192
- /** 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
+ */
193
235
  export interface Ancestor {
194
236
  id: number | string
195
237
  placetype: string
@@ -205,9 +247,13 @@ export interface CoincidentLocality extends ResolvedPlace {
205
247
  * `city-state` / `capital-seat` / `consolidated-county` — surfaced as `metadata.relationship_type`.
206
248
  */
207
249
  relationshipType: string
208
- /** 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
+ */
209
253
  population: number
210
- /** 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
+ */
211
257
  distanceKm: number
212
258
  }
213
259
 
@@ -221,9 +267,13 @@ export interface CoincidentLocality extends ResolvedPlace {
221
267
  export interface AddressPointHit {
222
268
  lat: number
223
269
  lon: number
224
- /** Provenance, e.g. `"overture:NAD"`. */
270
+ /**
271
+ * Provenance, e.g. `"overture:NAD"`.
272
+ */
225
273
  source: string
226
- /** 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
+ */
227
277
  release: string
228
278
  }
229
279
 
@@ -261,11 +311,17 @@ export interface InterpolatedPointHit {
261
311
  * `address_point` = bracketed between real neighbor points; `tiger_range` = linear within a segment range.
262
312
  */
263
313
  method: "address_point" | "tiger_range"
264
- /** 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
+ */
265
317
  parityMatched?: boolean
266
- /** `both` = neighbors bracketed it; `single` = one-sided extrapolation (larger uncertainty). */
318
+ /**
319
+ * `both` = neighbors bracketed it; `single` = one-sided extrapolation (larger uncertainty).
320
+ */
267
321
  bracket?: "both" | "single"
268
- /** Honest uncertainty radius in METERS (half the matched segment length). */
322
+ /**
323
+ * Honest uncertainty radius in METERS (half the matched segment length).
324
+ */
269
325
  uncertaintyM: number
270
326
  source: string
271
327
  release: string
@@ -301,7 +357,9 @@ export interface InterpolationLookup {
301
357
  export interface StreetCentroidHit {
302
358
  lat: number
303
359
  lon: number
304
- /** 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
+ */
305
363
  uncertaintyM: number
306
364
  source: string
307
365
  release: string
@@ -541,7 +599,9 @@ export interface ResolveOpts {
541
599
  */
542
600
  adminCoherence?: boolean
543
601
  hierarchyCompletion?: boolean
544
- /** @deprecated Renamed to {@link hierarchyCompletion} (#405 generalized #387). Still honored. */
602
+ /**
603
+ * @deprecated Renamed to {@link hierarchyCompletion} (#405 generalized #387). Still honored.
604
+ */
545
605
  cityStateFallback?: boolean
546
606
  /**
547
607
  * Attach each resolved node's ancestor lineage (#404) — the containment chain (county → region → country) the
@@ -567,6 +627,10 @@ export interface ResolveOpts {
567
627
  */
568
628
  export type PlacetypeMap = Partial<Record<ComponentTag, string>>
569
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
+ */
570
634
  export const DEFAULT_PLACETYPE_MAP: PlacetypeMap = {
571
635
  country: "country",
572
636
  region: "region",
@@ -620,6 +684,7 @@ export const PLACETYPE_FILTER_GROUPS: Readonly<Record<string, readonly string[]>
620
684
  export function expandPlacetypeFilter(placetypes: null): null
621
685
  export function expandPlacetypeFilter(placetypes: readonly string[]): string[]
622
686
  export function expandPlacetypeFilter(placetypes: readonly string[] | null): string[] | null
687
+
623
688
  export function expandPlacetypeFilter(placetypes: readonly string[] | null): string[] | null {
624
689
  if (!placetypes) return null
625
690
  const out: string[] = []
@@ -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 {
@@ -7,7 +7,7 @@
7
7
  import * as fs from "node:fs/promises"
8
8
 
9
9
  import FastGlob from "fast-glob"
10
- import { PathBuilder } from "path-ts"
10
+ import type { PathBuilder } from "path-ts"
11
11
 
12
12
  import { takeInParallel } from "../../collections.ts"
13
13
  import { prepareRepositoryDirectories, type RepositorySource } from "../../git.ts"
@@ -19,6 +19,9 @@ import {
19
19
  PlacetypeRoleOrder,
20
20
  } from "./definition.ts"
21
21
 
22
+ /**
23
+ * Upstream Who's On First placetypes repository the local definitions are generated from.
24
+ */
22
25
  export const PLACETYPES_REPO_SOURCE = {
23
26
  url: "https://github.com/whosonfirst/whosonfirst-placetypes.git",
24
27
  owner: "whosonfirst",
@@ -243,7 +246,7 @@ export class Placetype implements Disposable {
243
246
 
244
247
  this.#collectAncestors(ancestorsContext, roleFilters)
245
248
 
246
- return Array.from(ancestorsContext).sort(Placetype.comparatorAsc)
249
+ return Array.from(ancestorsContext).toSorted(Placetype.comparatorAsc)
247
250
  }
248
251
 
249
252
  #collectAncestors(ancestorsContext: Set<Placetype>, roleFilters?: Set<PlacetypeRole> | null): void {
@@ -271,7 +274,7 @@ export class Placetype implements Disposable {
271
274
  validChildren.push(child)
272
275
  }
273
276
 
274
- return validChildren.sort(Placetype.comparatorAsc)
277
+ return validChildren.toSorted(Placetype.comparatorAsc)
275
278
  }
276
279
 
277
280
  /**
@@ -289,7 +292,7 @@ export class Placetype implements Disposable {
289
292
  validParents.push(parent)
290
293
  }
291
294
 
292
- return validParents.sort(Placetype.comparatorDesc)
295
+ return validParents.toSorted(Placetype.comparatorDesc)
293
296
  }
294
297
 
295
298
  /**
@@ -304,7 +307,7 @@ export class Placetype implements Disposable {
304
307
  return validSiblings.filter((sibling) => roleFilters.has(sibling.role))
305
308
  }
306
309
 
307
- return validSiblings.sort((a, b) => {
310
+ return validSiblings.toSorted((a, b) => {
308
311
  return PlacetypeRoleOrder[a.role] - PlacetypeRoleOrder[b.role]
309
312
  })
310
313
  }
@@ -320,7 +323,7 @@ export class Placetype implements Disposable {
320
323
 
321
324
  this.#collectDescendants(descendantsContext, roleFilters)
322
325
 
323
- return Array.from(descendantsContext).sort(Placetype.comparatorAsc)
326
+ return Array.from(descendantsContext).toSorted(Placetype.comparatorAsc)
324
327
  }
325
328
 
326
329
  #collectDescendants(descendantsContext: Set<Placetype>, roleFilters?: Set<PlacetypeRole> | null): void {