@mailwoman/core 9.0.0 → 9.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (380) hide show
  1. package/README.md +1 -1
  2. package/api/responses.ts +12 -0
  3. package/coarse-placer/featurize.ts +0 -2
  4. package/coarse-placer/tools/build-dataset.ts +2 -2
  5. package/coarse-placer/tools/build-outlier-exposure.ts +2 -2
  6. package/coarse-placer/tools/build-outlier-latin.ts +14 -8
  7. package/coarse-placer/tools/build-outlier-oa.ts +12 -6
  8. package/coarse-placer/tools/eval-latin-offmap.ts +3 -4
  9. package/coarse-placer/tools/eval-openset.ts +3 -3
  10. package/coarse-placer/tools/eval-quant-compare.ts +3 -3
  11. package/coarse-placer/tools/eval.ts +3 -3
  12. package/coarse-placer/tools/fnv-hash.ts +1 -6
  13. package/coarse-placer/tools/index.ts +1 -1
  14. package/coarse-placer/tools/probe-frontier.ts +3 -4
  15. package/coarse-placer/tools/quantize.ts +3 -2
  16. package/coarse-placer/tools/train.ts +2 -2
  17. package/crypto/node.ts +3 -1
  18. package/data/internal/dictionaries/languages.csv +184 -184
  19. package/data/libpostal/README.md +8 -2
  20. package/db/schema.ts +12 -3
  21. package/decoder/build-tree.ts +19 -0
  22. package/decoder/containment.ts +5 -1
  23. package/decoder/index.ts +1 -0
  24. package/decoder/parse-diff.ts +347 -0
  25. package/decoder/proposals-to-tree.ts +1 -1
  26. package/decoder/serialize-json.ts +51 -7
  27. package/decoder/serialize-tuples.ts +7 -1
  28. package/decoder/serialize-xml.ts +1 -1
  29. package/decoder/tree-shape.ts +144 -0
  30. package/decoder/types.ts +8 -0
  31. package/decoder/validate-tree.ts +15 -3
  32. package/env/index.ts +3 -1
  33. package/env/paths.ts +21 -33
  34. package/env/schema.ts +35 -3
  35. package/fs/utils/formatters.ts +107 -0
  36. package/fs/utils/index.ts +7 -0
  37. package/fs/zip.ts +297 -0
  38. package/layers/manifest.ts +56 -15
  39. package/layers/schema.ts +54 -2
  40. package/locale/locale.ts +1 -1
  41. package/locale/registry.ts +1 -1
  42. package/objects.ts +20 -8
  43. package/out/api/responses.d.ts +9 -0
  44. package/out/api/responses.d.ts.map +1 -1
  45. package/out/api/responses.js +11 -0
  46. package/out/api/responses.js.map +1 -1
  47. package/out/coarse-placer/featurize.d.ts +0 -1
  48. package/out/coarse-placer/featurize.d.ts.map +1 -1
  49. package/out/coarse-placer/featurize.js.map +1 -1
  50. package/out/coarse-placer/tools/build-dataset.js +1 -2
  51. package/out/coarse-placer/tools/build-dataset.js.map +1 -1
  52. package/out/coarse-placer/tools/build-outlier-exposure.js +1 -2
  53. package/out/coarse-placer/tools/build-outlier-exposure.js.map +1 -1
  54. package/out/coarse-placer/tools/build-outlier-latin.d.ts.map +1 -1
  55. package/out/coarse-placer/tools/build-outlier-latin.js +12 -8
  56. package/out/coarse-placer/tools/build-outlier-latin.js.map +1 -1
  57. package/out/coarse-placer/tools/build-outlier-oa.d.ts.map +1 -1
  58. package/out/coarse-placer/tools/build-outlier-oa.js +10 -6
  59. package/out/coarse-placer/tools/build-outlier-oa.js.map +1 -1
  60. package/out/coarse-placer/tools/eval-latin-offmap.d.ts.map +1 -1
  61. package/out/coarse-placer/tools/eval-latin-offmap.js +2 -4
  62. package/out/coarse-placer/tools/eval-latin-offmap.js.map +1 -1
  63. package/out/coarse-placer/tools/eval-openset.js +2 -3
  64. package/out/coarse-placer/tools/eval-openset.js.map +1 -1
  65. package/out/coarse-placer/tools/eval-quant-compare.js +2 -3
  66. package/out/coarse-placer/tools/eval-quant-compare.js.map +1 -1
  67. package/out/coarse-placer/tools/eval.js +2 -3
  68. package/out/coarse-placer/tools/eval.js.map +1 -1
  69. package/out/coarse-placer/tools/fnv-hash.d.ts +1 -6
  70. package/out/coarse-placer/tools/fnv-hash.d.ts.map +1 -1
  71. package/out/coarse-placer/tools/fnv-hash.js +1 -6
  72. package/out/coarse-placer/tools/fnv-hash.js.map +1 -1
  73. package/out/coarse-placer/tools/index.d.ts +1 -1
  74. package/out/coarse-placer/tools/index.js +1 -1
  75. package/out/coarse-placer/tools/probe-frontier.d.ts.map +1 -1
  76. package/out/coarse-placer/tools/probe-frontier.js +2 -4
  77. package/out/coarse-placer/tools/probe-frontier.js.map +1 -1
  78. package/out/coarse-placer/tools/quantize.d.ts.map +1 -1
  79. package/out/coarse-placer/tools/quantize.js +2 -2
  80. package/out/coarse-placer/tools/quantize.js.map +1 -1
  81. package/out/coarse-placer/tools/train.js +1 -2
  82. package/out/coarse-placer/tools/train.js.map +1 -1
  83. package/out/crypto/node.d.ts.map +1 -1
  84. package/out/crypto/node.js +2 -1
  85. package/out/crypto/node.js.map +1 -1
  86. package/out/db/schema.d.ts +12 -3
  87. package/out/db/schema.d.ts.map +1 -1
  88. package/out/db/schema.js +6 -0
  89. package/out/db/schema.js.map +1 -1
  90. package/out/decoder/build-tree.d.ts.map +1 -1
  91. package/out/decoder/build-tree.js +17 -0
  92. package/out/decoder/build-tree.js.map +1 -1
  93. package/out/decoder/containment.d.ts.map +1 -1
  94. package/out/decoder/containment.js +5 -1
  95. package/out/decoder/containment.js.map +1 -1
  96. package/out/decoder/index.d.ts +1 -0
  97. package/out/decoder/index.d.ts.map +1 -1
  98. package/out/decoder/index.js +1 -0
  99. package/out/decoder/index.js.map +1 -1
  100. package/out/decoder/parse-diff.d.ts +125 -0
  101. package/out/decoder/parse-diff.d.ts.map +1 -0
  102. package/out/decoder/parse-diff.js +219 -0
  103. package/out/decoder/parse-diff.js.map +1 -0
  104. package/out/decoder/proposals-to-tree.js.map +1 -1
  105. package/out/decoder/serialize-json.d.ts +29 -0
  106. package/out/decoder/serialize-json.d.ts.map +1 -1
  107. package/out/decoder/serialize-json.js +20 -4
  108. package/out/decoder/serialize-json.js.map +1 -1
  109. package/out/decoder/serialize-tuples.d.ts +8 -1
  110. package/out/decoder/serialize-tuples.d.ts.map +1 -1
  111. package/out/decoder/serialize-tuples.js +7 -1
  112. package/out/decoder/serialize-tuples.js.map +1 -1
  113. package/out/decoder/serialize-xml.js +1 -1
  114. package/out/decoder/serialize-xml.js.map +1 -1
  115. package/out/decoder/tree-shape.d.ts +84 -0
  116. package/out/decoder/tree-shape.d.ts.map +1 -0
  117. package/out/decoder/tree-shape.js +98 -0
  118. package/out/decoder/tree-shape.js.map +1 -0
  119. package/out/decoder/types.d.ts +11 -0
  120. package/out/decoder/types.d.ts.map +1 -1
  121. package/out/decoder/validate-tree.d.ts +8 -0
  122. package/out/decoder/validate-tree.d.ts.map +1 -1
  123. package/out/decoder/validate-tree.js +4 -3
  124. package/out/decoder/validate-tree.js.map +1 -1
  125. package/out/env/index.d.ts +13 -1
  126. package/out/env/index.d.ts.map +1 -1
  127. package/out/env/index.js +2 -1
  128. package/out/env/index.js.map +1 -1
  129. package/out/env/paths.d.ts +15 -8
  130. package/out/env/paths.d.ts.map +1 -1
  131. package/out/env/paths.js +19 -29
  132. package/out/env/paths.js.map +1 -1
  133. package/out/env/schema.d.ts +12 -1
  134. package/out/env/schema.d.ts.map +1 -1
  135. package/out/env/schema.js +33 -3
  136. package/out/env/schema.js.map +1 -1
  137. package/out/fs/utils/formatters.d.ts +57 -0
  138. package/out/fs/utils/formatters.d.ts.map +1 -0
  139. package/out/fs/utils/formatters.js +79 -0
  140. package/out/fs/utils/formatters.js.map +1 -0
  141. package/out/fs/utils/index.d.ts +7 -0
  142. package/out/fs/utils/index.d.ts.map +1 -0
  143. package/out/fs/utils/index.js +7 -0
  144. package/out/fs/utils/index.js.map +1 -0
  145. package/out/fs/zip.d.ts +116 -0
  146. package/out/fs/zip.d.ts.map +1 -0
  147. package/out/fs/zip.js +216 -0
  148. package/out/fs/zip.js.map +1 -0
  149. package/out/layers/manifest.d.ts +32 -7
  150. package/out/layers/manifest.d.ts.map +1 -1
  151. package/out/layers/manifest.js +31 -6
  152. package/out/layers/manifest.js.map +1 -1
  153. package/out/layers/schema.d.ts +48 -2
  154. package/out/layers/schema.d.ts.map +1 -1
  155. package/out/layers/schema.js +32 -0
  156. package/out/layers/schema.js.map +1 -1
  157. package/out/locale/locale.d.ts +1 -1
  158. package/out/locale/locale.d.ts.map +1 -1
  159. package/out/locale/registry.js +1 -1
  160. package/out/locale/registry.js.map +1 -1
  161. package/out/objects.d.ts +12 -6
  162. package/out/objects.d.ts.map +1 -1
  163. package/out/objects.js +4 -1
  164. package/out/objects.js.map +1 -1
  165. package/out/pipeline/index.d.ts +3 -7
  166. package/out/pipeline/index.d.ts.map +1 -1
  167. package/out/pipeline/index.js +2 -4
  168. package/out/pipeline/index.js.map +1 -1
  169. package/out/pipeline/runtime-pipeline.d.ts +51 -9
  170. package/out/pipeline/runtime-pipeline.d.ts.map +1 -1
  171. package/out/pipeline/runtime-pipeline.js +46 -133
  172. package/out/pipeline/runtime-pipeline.js.map +1 -1
  173. package/out/pipeline/span-proposer.js +1 -1
  174. package/out/pipeline/span-proposer.js.map +1 -1
  175. package/out/pipeline/types.d.ts +137 -16
  176. package/out/pipeline/types.d.ts.map +1 -1
  177. package/out/pipeline/types.js +30 -0
  178. package/out/pipeline/types.js.map +1 -1
  179. package/out/policy/defaults.d.ts +1 -1
  180. package/out/policy/defaults.d.ts.map +1 -1
  181. package/out/policy/defaults.js +1 -1
  182. package/out/policy/defaults.js.map +1 -1
  183. package/out/policy/policy.d.ts +1 -1
  184. package/out/policy/policy.d.ts.map +1 -1
  185. package/out/policy/registry.d.ts +1 -1
  186. package/out/policy/registry.d.ts.map +1 -1
  187. package/out/resolver/coverage-facts.d.ts +89 -0
  188. package/out/resolver/coverage-facts.d.ts.map +1 -0
  189. package/out/resolver/coverage-facts.js +22 -0
  190. package/out/resolver/coverage-facts.js.map +1 -0
  191. package/out/resolver/index.d.ts +4 -1
  192. package/out/resolver/index.d.ts.map +1 -1
  193. package/out/resolver/index.js +2 -0
  194. package/out/resolver/index.js.map +1 -1
  195. package/out/resolver/lookup-types.d.ts +178 -0
  196. package/out/resolver/lookup-types.d.ts.map +1 -0
  197. package/out/resolver/lookup-types.js +11 -0
  198. package/out/resolver/lookup-types.js.map +1 -0
  199. package/out/resolver/placetype-map.d.ts +71 -0
  200. package/out/resolver/placetype-map.d.ts.map +1 -0
  201. package/out/resolver/placetype-map.js +98 -0
  202. package/out/resolver/placetype-map.js.map +1 -0
  203. package/out/resolver/postcode-format.d.ts +38 -0
  204. package/out/resolver/postcode-format.d.ts.map +1 -0
  205. package/out/resolver/postcode-format.js +83 -0
  206. package/out/resolver/postcode-format.js.map +1 -0
  207. package/out/resolver/referential.d.ts +73 -0
  208. package/out/resolver/referential.d.ts.map +1 -0
  209. package/out/resolver/referential.js +71 -0
  210. package/out/resolver/referential.js.map +1 -0
  211. package/out/resolver/types.d.ts +401 -264
  212. package/out/resolver/types.d.ts.map +1 -1
  213. package/out/resolver/types.js +4 -97
  214. package/out/resolver/types.js.map +1 -1
  215. package/out/resources/git.d.ts +8 -1
  216. package/out/resources/git.d.ts.map +1 -1
  217. package/out/resources/git.js +4 -3
  218. package/out/resources/git.js.map +1 -1
  219. package/out/resources/languages/types.gen.d.ts +1 -1
  220. package/out/resources/languages/types.gen.d.ts.map +1 -1
  221. package/out/resources/languages/types.gen.js +40 -0
  222. package/out/resources/languages/types.gen.js.map +1 -1
  223. package/out/resources/libpostal.d.ts +2 -2
  224. package/out/resources/libpostal.d.ts.map +1 -1
  225. package/out/resources/libpostal.js +2 -2
  226. package/out/resources/libpostal.js.map +1 -1
  227. package/out/resources/whosonfirst/DataSourceCache.d.ts.map +1 -1
  228. package/out/resources/whosonfirst/DataSourceCache.js.map +1 -1
  229. package/out/resources/whosonfirst/PlacetypeDataSource.d.ts +2 -2
  230. package/out/resources/whosonfirst/PlacetypeDataSource.d.ts.map +1 -1
  231. package/out/resources/whosonfirst/PlacetypeDataSource.js +28 -3
  232. package/out/resources/whosonfirst/PlacetypeDataSource.js.map +1 -1
  233. package/out/resources/whosonfirst/loader.d.ts +2 -2
  234. package/out/resources/whosonfirst/loader.d.ts.map +1 -1
  235. package/out/resources/whosonfirst/loader.js.map +1 -1
  236. package/out/resources/whosonfirst/placetypes/Placetype.d.ts.map +1 -1
  237. package/out/resources/whosonfirst/placetypes/Placetype.js +1 -1
  238. package/out/resources/whosonfirst/placetypes/Placetype.js.map +1 -1
  239. package/out/resources/whosonfirst/placetypes/admin.d.ts +9 -1
  240. package/out/resources/whosonfirst/placetypes/admin.d.ts.map +1 -1
  241. package/out/resources/whosonfirst/placetypes/admin.js +1 -1
  242. package/out/resources/whosonfirst/placetypes/admin.js.map +1 -1
  243. package/out/resources/whosonfirst/placetypes/definition.d.ts.map +1 -1
  244. package/out/resources/whosonfirst/placetypes/definition.js +1 -1
  245. package/out/resources/whosonfirst/placetypes/definition.js.map +1 -1
  246. package/out/resources/whosonfirst/placetypes/index.d.ts +1 -0
  247. package/out/resources/whosonfirst/placetypes/index.d.ts.map +1 -1
  248. package/out/resources/whosonfirst/placetypes/index.js +1 -0
  249. package/out/resources/whosonfirst/placetypes/index.js.map +1 -1
  250. package/out/resources/whosonfirst/placetypes/specificity.d.ts +65 -0
  251. package/out/resources/whosonfirst/placetypes/specificity.d.ts.map +1 -0
  252. package/out/resources/whosonfirst/placetypes/specificity.js +101 -0
  253. package/out/resources/whosonfirst/placetypes/specificity.js.map +1 -0
  254. package/out/resources/whosonfirst/sharded-repo.d.ts +28 -0
  255. package/out/resources/whosonfirst/sharded-repo.d.ts.map +1 -1
  256. package/out/resources/whosonfirst/sharded-repo.js +46 -2
  257. package/out/resources/whosonfirst/sharded-repo.js.map +1 -1
  258. package/out/scripting/arguments.d.ts +27 -0
  259. package/out/scripting/arguments.d.ts.map +1 -0
  260. package/out/scripting/arguments.js +32 -0
  261. package/out/scripting/arguments.js.map +1 -0
  262. package/out/scripting/command.d.ts +28 -0
  263. package/out/scripting/command.d.ts.map +1 -0
  264. package/out/scripting/command.js +47 -0
  265. package/out/scripting/command.js.map +1 -0
  266. package/out/scripting/index.js +3 -3
  267. package/out/scripting/index.js.map +1 -1
  268. package/out/scripting/utils/index.d.ts +1 -12
  269. package/out/scripting/utils/index.d.ts.map +1 -1
  270. package/out/scripting/utils/index.js +4 -21
  271. package/out/scripting/utils/index.js.map +1 -1
  272. package/out/tools/download-libpostal-resources.d.ts.map +1 -1
  273. package/out/tools/download-libpostal-resources.js +4 -7
  274. package/out/tools/download-libpostal-resources.js.map +1 -1
  275. package/out/tools/download-ssl-address.d.ts +3 -3
  276. package/out/tools/download-ssl-address.d.ts.map +1 -1
  277. package/out/tools/download-ssl-address.js +26 -13
  278. package/out/tools/download-ssl-address.js.map +1 -1
  279. package/out/tools/generate-language-types.d.ts +16 -1
  280. package/out/tools/generate-language-types.d.ts.map +1 -1
  281. package/out/tools/generate-language-types.js +38 -5
  282. package/out/tools/generate-language-types.js.map +1 -1
  283. package/out/tools/index.d.ts +1 -2
  284. package/out/tools/index.d.ts.map +1 -1
  285. package/out/tools/index.js +1 -2
  286. package/out/tools/index.js.map +1 -1
  287. package/out/utils/data-root.d.ts +27 -7
  288. package/out/utils/data-root.d.ts.map +1 -1
  289. package/out/utils/data-root.js +36 -13
  290. package/out/utils/data-root.js.map +1 -1
  291. package/out/utils/hash.d.ts +2 -3
  292. package/out/utils/hash.d.ts.map +1 -1
  293. package/out/utils/hash.js +3 -3
  294. package/out/utils/hash.js.map +1 -1
  295. package/out/utils/index.d.ts +1 -0
  296. package/out/utils/index.d.ts.map +1 -1
  297. package/out/utils/index.js +1 -0
  298. package/out/utils/index.js.map +1 -1
  299. package/out/utils/jsonl.js +1 -1
  300. package/out/utils/jsonl.js.map +1 -1
  301. package/out/utils/repo.d.ts +8 -0
  302. package/out/utils/repo.d.ts.map +1 -1
  303. package/out/utils/repo.js +10 -1
  304. package/out/utils/repo.js.map +1 -1
  305. package/out/utils/sealed-db.d.ts +11 -0
  306. package/out/utils/sealed-db.d.ts.map +1 -1
  307. package/out/utils/sealed-db.js +28 -1
  308. package/out/utils/sealed-db.js.map +1 -1
  309. package/out/utils/sqlite-rows.d.ts +34 -0
  310. package/out/utils/sqlite-rows.d.ts.map +1 -0
  311. package/out/utils/sqlite-rows.js +37 -0
  312. package/out/utils/sqlite-rows.js.map +1 -0
  313. package/out/utils/stats.d.ts +1 -6
  314. package/out/utils/stats.d.ts.map +1 -1
  315. package/out/utils/stats.js +1 -6
  316. package/out/utils/stats.js.map +1 -1
  317. package/package.json +488 -8
  318. package/pipeline/index.ts +14 -15
  319. package/pipeline/runtime-pipeline.ts +48 -184
  320. package/pipeline/span-proposer.ts +1 -1
  321. package/pipeline/types.ts +143 -16
  322. package/policy/defaults.ts +1 -1
  323. package/policy/policy.ts +1 -1
  324. package/policy/registry.ts +1 -1
  325. package/resolver/coverage-facts.ts +102 -0
  326. package/resolver/index.ts +18 -0
  327. package/resolver/lookup-types.ts +174 -0
  328. package/resolver/placetype-map.ts +122 -0
  329. package/resolver/postcode-format.ts +89 -0
  330. package/resolver/referential.ts +84 -0
  331. package/resolver/types.ts +423 -315
  332. package/resources/git.ts +18 -4
  333. package/resources/languages/types.gen.ts +60 -0
  334. package/resources/libpostal.ts +4 -3
  335. package/resources/whosonfirst/DataSourceCache.ts +2 -1
  336. package/resources/whosonfirst/PlacetypeDataSource.ts +36 -11
  337. package/resources/whosonfirst/loader.ts +3 -2
  338. package/resources/whosonfirst/placetypes/Placetype.ts +2 -1
  339. package/resources/whosonfirst/placetypes/admin.ts +11 -2
  340. package/resources/whosonfirst/placetypes/definition.ts +4 -3
  341. package/resources/whosonfirst/placetypes/index.ts +1 -0
  342. package/resources/whosonfirst/placetypes/specificity.ts +114 -0
  343. package/resources/whosonfirst/sharded-repo.ts +55 -2
  344. package/scripting/arguments.ts +38 -0
  345. package/scripting/command.ts +55 -0
  346. package/scripting/index.ts +3 -3
  347. package/scripting/utils/index.ts +5 -23
  348. package/tools/download-libpostal-resources.ts +4 -7
  349. package/tools/download-ssl-address.ts +28 -12
  350. package/tools/generate-language-types.ts +39 -5
  351. package/tools/index.ts +1 -2
  352. package/utils/data-root.ts +40 -14
  353. package/utils/hash.ts +5 -4
  354. package/utils/index.ts +1 -0
  355. package/utils/jsonl.ts +1 -1
  356. package/utils/repo.ts +12 -1
  357. package/utils/sealed-db.ts +30 -1
  358. package/utils/sqlite-rows.ts +40 -0
  359. package/utils/stats.ts +1 -6
  360. package/data/libpostal/dictionaries/all/chains.txt +0 -504
  361. package/kysley/adapter.ts +0 -29
  362. package/out/kysley/adapter.d.ts +0 -13
  363. package/out/kysley/adapter.d.ts.map +0 -1
  364. package/out/kysley/adapter.js +0 -25
  365. package/out/kysley/adapter.js.map +0 -1
  366. package/out/pipeline/reconcile-lookups.d.ts +0 -39
  367. package/out/pipeline/reconcile-lookups.d.ts.map +0 -1
  368. package/out/pipeline/reconcile-lookups.js +0 -88
  369. package/out/pipeline/reconcile-lookups.js.map +0 -1
  370. package/out/pipeline/reconcile.d.ts +0 -153
  371. package/out/pipeline/reconcile.d.ts.map +0 -1
  372. package/out/pipeline/reconcile.js +0 -388
  373. package/out/pipeline/reconcile.js.map +0 -1
  374. package/out/pipeline/span-logit-aggregation.d.ts +0 -58
  375. package/out/pipeline/span-logit-aggregation.d.ts.map +0 -1
  376. package/out/pipeline/span-logit-aggregation.js +0 -117
  377. package/out/pipeline/span-logit-aggregation.js.map +0 -1
  378. package/pipeline/reconcile-lookups.ts +0 -111
  379. package/pipeline/reconcile.ts +0 -583
  380. package/pipeline/span-logit-aggregation.ts +0 -156
package/resources/git.ts CHANGED
@@ -8,9 +8,10 @@ import { execFile } from "node:child_process"
8
8
  import * as fs from "node:fs/promises"
9
9
  import { promisify } from "node:util"
10
10
 
11
- import { tryStat } from "@mailwoman/core/fs"
12
11
  import { PathBuilder, type PathBuilderLike } from "path-ts"
13
12
 
13
+ import { tryStat } from "#fs"
14
+
14
15
  const execFileAsync = promisify(execFile)
15
16
 
16
17
  /**
@@ -36,19 +37,32 @@ export async function prepareRepositoryDirectories(
36
37
  return { ownerDirectory, repoDirectory, exists }
37
38
  }
38
39
 
40
+ /**
41
+ * What a synchronization did, so a caller can report it.
42
+ *
43
+ * A clone and a pull differ by orders of magnitude in both time and bytes — reporting them as one "synchronized" makes
44
+ * a first-time clone indistinguishable from a no-op refresh while it holds the progress display still.
45
+ */
46
+ export type SynchronizeAction = "cloned" | "pulled" | "skipped"
47
+
39
48
  /**
40
49
  * Synchronize a repository source, i.e. clone or pull the repository.
41
50
  */
42
- export async function synchronizeRepo(source: RepositorySource, localRepoDirectory: PathBuilderLike): Promise<void> {
43
- if (source.name.includes("deprecated")) return
51
+ export async function synchronizeRepo(
52
+ source: RepositorySource,
53
+ localRepoDirectory: PathBuilderLike
54
+ ): Promise<SynchronizeAction> {
55
+ if (source.name.includes("deprecated")) return "skipped"
44
56
 
45
57
  const { ownerDirectory, repoDirectory, exists } = await prepareRepositoryDirectories(source, localRepoDirectory)
46
58
 
47
59
  if (exists) {
48
60
  await execFileAsync("git", ["pull"], { cwd: repoDirectory.toString() })
49
61
 
50
- return
62
+ return "pulled"
51
63
  }
52
64
 
53
65
  await execFileAsync("git", ["clone", "--depth=1", source.url], { cwd: ownerDirectory.toString() })
66
+
67
+ return "cloned"
54
68
  }
@@ -427,10 +427,12 @@ export type Alpha3bLanguageCode =
427
427
  | "afr"
428
428
  | "aka"
429
429
  | "alb"
430
+ | "sqi"
430
431
  | "amh"
431
432
  | "ara"
432
433
  | "arg"
433
434
  | "arm"
435
+ | "hye"
434
436
  | "asm"
435
437
  | "ava"
436
438
  | "ave"
@@ -439,6 +441,7 @@ export type Alpha3bLanguageCode =
439
441
  | "bak"
440
442
  | "bam"
441
443
  | "baq"
444
+ | "eus"
442
445
  | "bel"
443
446
  | "ben"
444
447
  | "bis"
@@ -446,19 +449,23 @@ export type Alpha3bLanguageCode =
446
449
  | "bre"
447
450
  | "bul"
448
451
  | "bur"
452
+ | "mya"
449
453
  | "cat"
450
454
  | "cha"
451
455
  | "che"
452
456
  | "chi"
457
+ | "zho"
453
458
  | "chu"
454
459
  | "chv"
455
460
  | "cor"
456
461
  | "cos"
457
462
  | "cre"
458
463
  | "cze"
464
+ | "ces"
459
465
  | "dan"
460
466
  | "div"
461
467
  | "dut"
468
+ | "nld"
462
469
  | "dzo"
463
470
  | "eng"
464
471
  | "epo"
@@ -468,15 +475,19 @@ export type Alpha3bLanguageCode =
468
475
  | "fij"
469
476
  | "fin"
470
477
  | "fre"
478
+ | "fra"
471
479
  | "fry"
472
480
  | "ful"
473
481
  | "geo"
482
+ | "kat"
474
483
  | "ger"
484
+ | "deu"
475
485
  | "gla"
476
486
  | "gle"
477
487
  | "glg"
478
488
  | "glv"
479
489
  | "gre"
490
+ | "ell"
480
491
  | "grn"
481
492
  | "guj"
482
493
  | "hat"
@@ -489,6 +500,7 @@ export type Alpha3bLanguageCode =
489
500
  | "hun"
490
501
  | "ibo"
491
502
  | "ice"
503
+ | "isl"
492
504
  | "ido"
493
505
  | "iii"
494
506
  | "iku"
@@ -523,11 +535,14 @@ export type Alpha3bLanguageCode =
523
535
  | "lub"
524
536
  | "lug"
525
537
  | "mac"
538
+ | "mkd"
526
539
  | "mah"
527
540
  | "mal"
528
541
  | "mao"
542
+ | "mri"
529
543
  | "mar"
530
544
  | "may"
545
+ | "msa"
531
546
  | "mlg"
532
547
  | "mlt"
533
548
  | "mon"
@@ -548,6 +563,7 @@ export type Alpha3bLanguageCode =
548
563
  | "oss"
549
564
  | "pan"
550
565
  | "per"
566
+ | "fas"
551
567
  | "pli"
552
568
  | "pol"
553
569
  | "por"
@@ -555,12 +571,14 @@ export type Alpha3bLanguageCode =
555
571
  | "que"
556
572
  | "roh"
557
573
  | "rum"
574
+ | "ron"
558
575
  | "run"
559
576
  | "rus"
560
577
  | "sag"
561
578
  | "san"
562
579
  | "sin"
563
580
  | "slo"
581
+ | "slk"
564
582
  | "slv"
565
583
  | "sme"
566
584
  | "smo"
@@ -583,6 +601,7 @@ export type Alpha3bLanguageCode =
583
601
  | "tgl"
584
602
  | "tha"
585
603
  | "tib"
604
+ | "bod"
586
605
  | "tir"
587
606
  | "ton"
588
607
  | "tsn"
@@ -598,6 +617,7 @@ export type Alpha3bLanguageCode =
598
617
  | "vie"
599
618
  | "vol"
600
619
  | "wel"
620
+ | "cym"
601
621
  | "wln"
602
622
  | "wol"
603
623
  | "xho"
@@ -809,10 +829,12 @@ export const Alpha3bLabelMap: ReadonlyMap<Alpha3bLanguageCode, string[]> = new M
809
829
  ["afr", ["Afrikaans"]],
810
830
  ["aka", ["Akan"]],
811
831
  ["alb", ["Albanian"]],
832
+ ["sqi", ["Albanian"]],
812
833
  ["amh", ["Amharic"]],
813
834
  ["ara", ["Arabic"]],
814
835
  ["arg", ["Aragonese"]],
815
836
  ["arm", ["Armenian"]],
837
+ ["hye", ["Armenian"]],
816
838
  ["asm", ["Assamese"]],
817
839
  ["ava", ["Avaric"]],
818
840
  ["ave", ["Avestan"]],
@@ -821,6 +843,7 @@ export const Alpha3bLabelMap: ReadonlyMap<Alpha3bLanguageCode, string[]> = new M
821
843
  ["bak", ["Bashkir"]],
822
844
  ["bam", ["Bambara"]],
823
845
  ["baq", ["Basque"]],
846
+ ["eus", ["Basque"]],
824
847
  ["bel", ["Belarusian"]],
825
848
  ["ben", ["Bengali"]],
826
849
  ["bis", ["Bislama"]],
@@ -828,19 +851,23 @@ export const Alpha3bLabelMap: ReadonlyMap<Alpha3bLanguageCode, string[]> = new M
828
851
  ["bre", ["Breton"]],
829
852
  ["bul", ["Bulgarian"]],
830
853
  ["bur", ["Burmese"]],
854
+ ["mya", ["Burmese"]],
831
855
  ["cat", ["Catalan", "Valencian"]],
832
856
  ["cha", ["Chamorro"]],
833
857
  ["che", ["Chechen"]],
834
858
  ["chi", ["Chinese"]],
859
+ ["zho", ["Chinese"]],
835
860
  ["chu", ["Church Slavic", "Old Slavonic", "Church Slavonic", "Old Bulgarian", "Old Church Slavonic"]],
836
861
  ["chv", ["Chuvash"]],
837
862
  ["cor", ["Cornish"]],
838
863
  ["cos", ["Corsican"]],
839
864
  ["cre", ["Cree"]],
840
865
  ["cze", ["Czech"]],
866
+ ["ces", ["Czech"]],
841
867
  ["dan", ["Danish"]],
842
868
  ["div", ["Divehi", "Dhivehi", "Maldivian"]],
843
869
  ["dut", ["Dutch", "Flemish"]],
870
+ ["nld", ["Dutch", "Flemish"]],
844
871
  ["dzo", ["Dzongkha"]],
845
872
  ["eng", ["English"]],
846
873
  ["epo", ["Esperanto"]],
@@ -850,15 +877,19 @@ export const Alpha3bLabelMap: ReadonlyMap<Alpha3bLanguageCode, string[]> = new M
850
877
  ["fij", ["Fijian"]],
851
878
  ["fin", ["Finnish"]],
852
879
  ["fre", ["French"]],
880
+ ["fra", ["French"]],
853
881
  ["fry", ["Western Frisian"]],
854
882
  ["ful", ["Fulah"]],
855
883
  ["geo", ["Georgian"]],
884
+ ["kat", ["Georgian"]],
856
885
  ["ger", ["German"]],
886
+ ["deu", ["German"]],
857
887
  ["gla", ["Gaelic", "Scottish Gaelic"]],
858
888
  ["gle", ["Irish"]],
859
889
  ["glg", ["Galician"]],
860
890
  ["glv", ["Manx"]],
861
891
  ["gre", ["Greek, Modern (1453-)"]],
892
+ ["ell", ["Greek, Modern (1453-)"]],
862
893
  ["grn", ["Guarani"]],
863
894
  ["guj", ["Gujarati"]],
864
895
  ["hat", ["Haitian", "Haitian Creole"]],
@@ -871,6 +902,7 @@ export const Alpha3bLabelMap: ReadonlyMap<Alpha3bLanguageCode, string[]> = new M
871
902
  ["hun", ["Hungarian"]],
872
903
  ["ibo", ["Igbo"]],
873
904
  ["ice", ["Icelandic"]],
905
+ ["isl", ["Icelandic"]],
874
906
  ["ido", ["Ido"]],
875
907
  ["iii", ["Sichuan Yi", "Nuosu"]],
876
908
  ["iku", ["Inuktitut"]],
@@ -905,11 +937,14 @@ export const Alpha3bLabelMap: ReadonlyMap<Alpha3bLanguageCode, string[]> = new M
905
937
  ["lub", ["Luba-Katanga"]],
906
938
  ["lug", ["Ganda"]],
907
939
  ["mac", ["Macedonian"]],
940
+ ["mkd", ["Macedonian"]],
908
941
  ["mah", ["Marshallese"]],
909
942
  ["mal", ["Malayalam"]],
910
943
  ["mao", ["Maori"]],
944
+ ["mri", ["Maori"]],
911
945
  ["mar", ["Marathi"]],
912
946
  ["may", ["Malay"]],
947
+ ["msa", ["Malay"]],
913
948
  ["mlg", ["Malagasy"]],
914
949
  ["mlt", ["Maltese"]],
915
950
  ["mon", ["Mongolian"]],
@@ -930,6 +965,7 @@ export const Alpha3bLabelMap: ReadonlyMap<Alpha3bLanguageCode, string[]> = new M
930
965
  ["oss", ["Ossetian", "Ossetic"]],
931
966
  ["pan", ["Panjabi", "Punjabi"]],
932
967
  ["per", ["Persian"]],
968
+ ["fas", ["Persian"]],
933
969
  ["pli", ["Pali"]],
934
970
  ["pol", ["Polish"]],
935
971
  ["por", ["Portuguese"]],
@@ -937,12 +973,14 @@ export const Alpha3bLabelMap: ReadonlyMap<Alpha3bLanguageCode, string[]> = new M
937
973
  ["que", ["Quechua"]],
938
974
  ["roh", ["Romansh"]],
939
975
  ["rum", ["Romanian", "Moldavian", "Moldovan"]],
976
+ ["ron", ["Romanian", "Moldavian", "Moldovan"]],
940
977
  ["run", ["Rundi"]],
941
978
  ["rus", ["Russian"]],
942
979
  ["sag", ["Sango"]],
943
980
  ["san", ["Sanskrit"]],
944
981
  ["sin", ["Sinhala", "Sinhalese"]],
945
982
  ["slo", ["Slovak"]],
983
+ ["slk", ["Slovak"]],
946
984
  ["slv", ["Slovenian"]],
947
985
  ["sme", ["Northern Sami"]],
948
986
  ["smo", ["Samoan"]],
@@ -965,6 +1003,7 @@ export const Alpha3bLabelMap: ReadonlyMap<Alpha3bLanguageCode, string[]> = new M
965
1003
  ["tgl", ["Tagalog"]],
966
1004
  ["tha", ["Thai"]],
967
1005
  ["tib", ["Tibetan"]],
1006
+ ["bod", ["Tibetan"]],
968
1007
  ["tir", ["Tigrinya"]],
969
1008
  ["ton", ["Tonga (Tonga Islands)"]],
970
1009
  ["tsn", ["Tswana"]],
@@ -980,6 +1019,7 @@ export const Alpha3bLabelMap: ReadonlyMap<Alpha3bLanguageCode, string[]> = new M
980
1019
  ["vie", ["Vietnamese"]],
981
1020
  ["vol", ["Volapük"]],
982
1021
  ["wel", ["Welsh"]],
1022
+ ["cym", ["Welsh"]],
983
1023
  ["wln", ["Walloon"]],
984
1024
  ["wol", ["Wolof"]],
985
1025
  ["xho", ["Xhosa"]],
@@ -1365,4 +1405,24 @@ export const Alpha3bToAlpha2: ReadonlyMap<Alpha3bLanguageCode, Alpha2LanguageCod
1365
1405
  ["yor", "yo"],
1366
1406
  ["zha", "za"],
1367
1407
  ["zul", "zu"],
1408
+ ["sqi", "sq"],
1409
+ ["hye", "hy"],
1410
+ ["eus", "eu"],
1411
+ ["mya", "my"],
1412
+ ["zho", "zh"],
1413
+ ["ces", "cs"],
1414
+ ["nld", "nl"],
1415
+ ["fra", "fr"],
1416
+ ["kat", "ka"],
1417
+ ["deu", "de"],
1418
+ ["ell", "el"],
1419
+ ["isl", "is"],
1420
+ ["mkd", "mk"],
1421
+ ["mri", "mi"],
1422
+ ["msa", "ms"],
1423
+ ["fas", "fa"],
1424
+ ["ron", "ro"],
1425
+ ["slk", "sk"],
1426
+ ["bod", "bo"],
1427
+ ["cym", "cy"],
1368
1428
  ])
@@ -7,13 +7,14 @@
7
7
  import { readdir } from "node:fs/promises"
8
8
  import { availableParallelism } from "node:os"
9
9
 
10
- import { tryStat } from "@mailwoman/core/fs"
11
- import type { Alpha2LanguageCode } from "@mailwoman/core/resources/languages"
12
- import { TextNormalizer, type TextNormalizerInit } from "@mailwoman/core/tokenization"
13
10
  import type { PathBuilder } from "path-ts"
14
11
  import pluralize from "pluralize"
15
12
  import { AsyncSequence, TextSpliterator } from "spliterator"
16
13
 
14
+ import { tryStat } from "#fs"
15
+ import type { Alpha2LanguageCode } from "#resources/languages"
16
+ import { TextNormalizer, type TextNormalizerInit } from "#tokenization"
17
+
17
18
  import { resourceDictionaryPathBuilder } from "../utils/repo.ts"
18
19
  import { LocaleIndex } from "./LocaleIndex.ts"
19
20
 
@@ -6,9 +6,10 @@
6
6
 
7
7
  import { mkdirSync } from "node:fs"
8
8
 
9
- import type { Alpha3bLanguageCode } from "@mailwoman/core/resources/languages"
10
9
  import { dirname } from "path-ts"
11
10
 
11
+ import type { Alpha3bLanguageCode } from "#resources/languages"
12
+
12
13
  import { PlacetypeDataSource, type PlacetypeDataSourceOptions } from "./PlacetypeDataSource.ts"
13
14
  import type { WhosOnFirstPlacetype } from "./placetypes/definition.ts"
14
15
 
@@ -6,13 +6,14 @@
6
6
 
7
7
  import { DatabaseSync, type DatabaseSyncOptions, type SQLInputValue } from "node:sqlite"
8
8
 
9
+ import { PathBuilder, type PathBuilderLike } from "path-ts"
10
+
9
11
  import {
10
12
  type Alpha2LanguageCode,
11
13
  type Alpha3bLanguageCode,
12
14
  Alpha3bToAlpha2,
13
15
  isAlpha3bLanguageCode,
14
- } from "@mailwoman/core/resources/languages"
15
- import { PathBuilder, type PathBuilderLike } from "path-ts"
16
+ } from "#resources/languages"
16
17
 
17
18
  import { tryWithBackoff } from "./backoff.ts"
18
19
  import type { WhosOnFirstPlacetype } from "./placetypes/definition.ts"
@@ -65,6 +66,36 @@ export interface PlacetypeRecord {
65
66
  short: string | null
66
67
  }
67
68
 
69
+ function sqlParameters(input: Partial<PlacetypeRecord>): Record<string, SQLInputValue> {
70
+ const parameters: Record<string, SQLInputValue> = {}
71
+
72
+ for (const [key, value] of Object.entries(input)) {
73
+ if (value !== undefined) {
74
+ parameters[key] = value
75
+ }
76
+ }
77
+
78
+ return parameters
79
+ }
80
+
81
+ function nullableString(value: unknown): string | null {
82
+ return value == null ? null : String(value)
83
+ }
84
+
85
+ function placetypeRecordFromRow(row: Record<string, SQLInputValue>): PlacetypeRecord {
86
+ return {
87
+ id: Number(row["id"]),
88
+ src: String(row["src"]),
89
+ parent_id: Number(row["parent_id"]),
90
+ name: String(row["name"]),
91
+ preferred: nullableString(row["preferred"]),
92
+ variant: nullableString(row["variant"]),
93
+ colloquial: nullableString(row["colloquial"]),
94
+ abbr: nullableString(row["abbr"]),
95
+ short: nullableString(row["short"]),
96
+ }
97
+ }
98
+
68
99
  /**
69
100
  * A data source for WhosOnFirst placetype records.
70
101
  */
@@ -80,11 +111,7 @@ export class PlacetypeDataSource implements Disposable {
80
111
  ? Alpha3bToAlpha2.get(languageCode)
81
112
  : languageCode
82
113
 
83
- return PathBuilder.from(
84
- dataDirectory,
85
- placetype,
86
- `${normalizedLanguageCode}.db`
87
- ) as unknown as PathBuilder<`/${P}/${L}.db`>
114
+ return PathBuilder.from(dataDirectory, placetype, `${normalizedLanguageCode}.db`)
88
115
  }
89
116
 
90
117
  public prepareTables(): void {
@@ -155,9 +182,7 @@ export class PlacetypeDataSource implements Disposable {
155
182
 
156
183
  // node:sqlite's StatementSync.iterate() accepts named params via an object whose keys match
157
184
  // the `@name` / `:name` / `$name` placeholders in the SQL.
158
- return Iterator.from(
159
- statement.iterate(criteria as unknown as Record<string, SQLInputValue>)
160
- ) as unknown as IteratorObject<PlacetypeRecord>
185
+ return Iterator.from(statement.iterate(sqlParameters(criteria))).map(placetypeRecordFromRow)
161
186
  }
162
187
 
163
188
  /**
@@ -191,7 +216,7 @@ export class PlacetypeDataSource implements Disposable {
191
216
  parent_id = excluded.parent_id
192
217
  `)
193
218
 
194
- statement.run(record as unknown as Record<string, SQLInputValue>)
219
+ statement.run(sqlParameters(record))
195
220
  }
196
221
 
197
222
  await tryWithBackoff(5, perform)
@@ -4,12 +4,13 @@
4
4
  * @author Teffen Ellis, et al.
5
5
  */
6
6
 
7
- import type { Alpha3bLanguageCode } from "@mailwoman/core/resources/languages"
8
- import type { TextNormalizer } from "@mailwoman/core/tokenization"
9
7
  import FastGlob, { type Entry } from "fast-glob"
10
8
  import { PathBuilder, type PathBuilderLike } from "path-ts"
11
9
  import { TextSpliterator } from "spliterator"
12
10
 
11
+ import type { Alpha3bLanguageCode } from "#resources/languages"
12
+ import type { TextNormalizer } from "#tokenization"
13
+
13
14
  import type { Displayable } from "../debugging.ts"
14
15
  import { ResourceMapCache } from "../ResourceMapCache.ts"
15
16
  import { DisposableSet } from "../set.ts"
@@ -10,7 +10,8 @@ import FastGlob from "fast-glob"
10
10
  import type { PathBuilder } from "path-ts"
11
11
  import { parallelMap } from "spliterator"
12
12
 
13
- import { parseJSONStrict } from "../../../objects.ts"
13
+ import { parseJSONStrict } from "#objects"
14
+
14
15
  import { prepareRepositoryDirectories, type RepositorySource } from "../../git.ts"
15
16
  import {
16
17
  normalizePlacetypeDefinition,
@@ -4,14 +4,15 @@
4
4
  * @author Teffen Ellis, et al.
5
5
  */
6
6
 
7
+ import type { GeoFeature, GeometryLiteral } from "@mailwoman/spatial"
8
+
7
9
  import {
8
10
  type Alpha2LanguageCode,
9
11
  type Alpha3bLanguageCode,
10
12
  Alpha3bToAlpha2,
11
13
  isAlpha2LanguageCode,
12
14
  isAlpha3bLanguageCode,
13
- } from "@mailwoman/core/resources/languages"
14
- import type { GeoFeature, GeometryLiteral } from "@mailwoman/spatial"
15
+ } from "#resources/languages"
15
16
 
16
17
  import type { WhosOnFirstPlacetype } from "./definition.ts"
17
18
 
@@ -36,6 +37,14 @@ export interface WOFBaseProperties {
36
37
  "wof:lastmodified"?: number
37
38
  "geom:latitude"?: number
38
39
  "geom:longitude"?: number
40
+ /**
41
+ * The label centroid — where a human would drop the pin, distinct from the geometry's mathematical centroid. The
42
+ * difference is territorial: France's `geom:` centroid sits in Spain (42.19, -2.74) because the multipolygon spans
43
+ * the overseas territories, while `lbl:` is metropolitan France (46.71, 2.46). Prefer `lbl:` wherever a point stands
44
+ * in for the place.
45
+ */
46
+ "lbl:latitude"?: number
47
+ "lbl:longitude"?: number
39
48
  /**
40
49
  * `"minLon,minLat,maxLon,maxLat"` — WOF writes the bbox as a comma-joined string, not an array. Read by the gazetteer
41
50
  * ingest for the resolver's point-in-box proximity.
@@ -119,14 +119,15 @@ export type PlacetypeDefinitionInit = {
119
119
  export function normalizePlacetypeDefinition(
120
120
  initLike: PlacetypeDefinition | PlacetypeDefinitionInit
121
121
  ): PlacetypeDefinition {
122
- const spec: Record<string, unknown> = {}
122
+ const spec = {} as PlacetypeDefinition
123
123
 
124
124
  for (const [key, value] of Object.entries(initLike)) {
125
125
  const normalizedKey = key.startsWith(WOFPrefix) ? key.slice(WOFPrefix.length) : key
126
- spec[normalizedKey] = value
126
+
127
+ Reflect.set(spec, normalizedKey, value)
127
128
  }
128
129
 
129
- return spec as unknown as PlacetypeDefinition
130
+ return spec
130
131
  }
131
132
 
132
133
  /**
@@ -9,4 +9,5 @@ export * from "./definition.ts"
9
9
  export * from "./graph.ts"
10
10
  export * from "./mermaid.ts"
11
11
  export * from "./Placetype.ts"
12
+ export * from "./specificity.ts"
12
13
  export * from "./tree.ts"
@@ -0,0 +1,114 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ *
6
+ * How SPECIFIC a placetype is — the ordering `Placetype.ts` deliberately does not give you.
7
+ *
8
+ * WOF placetype ids are assignment order, and `Placetype.ts` says so in place ("these IDs are not in any specific
9
+ * order. Avoid using them for sorting."). Every consumer that needs "is this row finer or coarser than that one"
10
+ * therefore writes its own table, and two identical copies already existed — `eval-harness/oa-resolver-eval.ts` and
11
+ * `dev-tools/score-hard-slice-board.run.ts` — agreeing on seven placetypes and both missing everything below
12
+ * `localadmin`.
13
+ *
14
+ * THAT SHARED GAP IS WHY THIS FILE EXISTS. #1746: the currency backfill refused to
15
+ * resurrect a deprecated locality whenever ANY live same-name row sat within 10 km, "possibly under another
16
+ * placetype". For a place recorded twice that premise holds. For a placetype DEMOTION it does not — WOF retired
17
+ * `Gillingham` the locality (pop 101,187) and kept `Gillingham` the neighbourhood 3.2 km away, and the gate read the
18
+ * surviving CHILD as covering its own dead parent. Sixteen of seventeen GB refusals had exactly that shape. A rank
19
+ * comparison separates the two cases, and it needs the fine end of the scale that neither existing copy carried.
20
+ *
21
+ * IT IS NOT THE ONLY TABLE. `resolver-wof-sqlite/ancestry.ts` publishes `PLACETYPE_DEPTH` for hierarchical
22
+ * containment, and `eval-harness/gauntlet/ablation-expectation.ts` carries a deliberate copy of THAT one so an old
23
+ * artifact can be re-graded against the table it was built with. This scale ORDERS the eleven placetypes they share
24
+ * identically, and `specificity.test.ts` holds that agreement — the two differ only in offset and in what an
25
+ * unranked placetype means, never in which of two placetypes is finer.
26
+ *
27
+ * They did not always agree. This scale once put `borough` COARSER than `locality` and tied `county` with
28
+ * `macrocounty`, both wrong: a NYC borough sits inside its locality, and a macrocounty contains counties. The
29
+ * inversion mattered — it let a live borough read as covering its own dead parent locality, which is the same shape
30
+ * as the Gillingham defect above, one rung down.
31
+ */
32
+
33
+ import type { WhosOnFirstPlacetype } from "./definition.ts"
34
+
35
+ /**
36
+ * Higher is finer. Absent placetypes are UNRANKED and must be handled by the caller rather than defaulted — a missing
37
+ * entry silently scoring 0 would rank an unknown placetype as coarse as `country`, which is the wrong direction for
38
+ * every gate that reads this.
39
+ */
40
+ export const PLACETYPE_SPECIFICITY: Readonly<Partial<Record<WhosOnFirstPlacetype | (string & {}), number>>> = {
41
+ address: 11,
42
+ building: 10,
43
+ campus: 10,
44
+ venue: 10,
45
+ postalcode: 9,
46
+ microhood: 8,
47
+ neighbourhood: 7,
48
+ macrohood: 6,
49
+ borough: 5,
50
+ locality: 4,
51
+ localadmin: 3,
52
+ county: 2,
53
+ macrocounty: 1,
54
+ region: 0,
55
+ macroregion: -1,
56
+ country: -2,
57
+ dependency: -2,
58
+ continent: -3,
59
+ empire: -4,
60
+ planet: -5,
61
+ }
62
+
63
+ /**
64
+ * The rank of a placetype, or `undefined` when it carries none.
65
+ *
66
+ * Returning `undefined` rather than a number is the point: a caller that cannot rank a row has to decide what that
67
+ * means for its own gate, and the two reasonable answers (block conservatively, or ignore) differ per call site.
68
+ */
69
+ export function placetypeSpecificity(placetype: string | null | undefined): number | undefined {
70
+ if (!placetype) return undefined
71
+
72
+ return PLACETYPE_SPECIFICITY[placetype]
73
+ }
74
+
75
+ /**
76
+ * Is `candidate` at least as fine-grained as `reference`?
77
+ *
78
+ * `undefined` when either placetype is unranked — the caller decides. The comparison is `>=` so an equal rung counts as
79
+ * covering, which is what a "this place is already represented" check wants.
80
+ */
81
+ export function isAtLeastAsSpecific(
82
+ candidate: string | null | undefined,
83
+ reference: string | null | undefined
84
+ ): boolean | undefined {
85
+ const a = placetypeSpecificity(candidate)
86
+ const b = placetypeSpecificity(reference)
87
+
88
+ if (a === undefined || b === undefined) return undefined
89
+
90
+ return a >= b
91
+ }
92
+
93
+ /**
94
+ * Is `candidate` STRICTLY finer than `reference` — a child rung, not the same one?
95
+ *
96
+ * The distinction from {@link isAtLeastAsSpecific} is the whole bug it was written for. "Does this live row cover that
97
+ * dead one" wants the EQUAL case to count as covering: a live `locality` plainly covers a dead `locality` of the same
98
+ * name. Asking `isAtLeastAsSpecific(live, dead)` and negating it answers "is the live row strictly coarser", which
99
+ * quietly drops the equal case — measured on the real artifact, that turned 973 blocked rows into 18 and would have
100
+ * resurrected 955 places that are already alive.
101
+ *
102
+ * `undefined` when either placetype is unranked; a caller gating on this should treat that as "not strictly finer".
103
+ */
104
+ export function isStrictlyFiner(
105
+ candidate: string | null | undefined,
106
+ reference: string | null | undefined
107
+ ): boolean | undefined {
108
+ const a = placetypeSpecificity(candidate)
109
+ const b = placetypeSpecificity(reference)
110
+
111
+ if (a === undefined || b === undefined) return undefined
112
+
113
+ return a > b
114
+ }