@mailwoman/core 9.1.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 (371) 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 +1 -1
  5. package/coarse-placer/tools/build-outlier-exposure.ts +1 -1
  6. package/coarse-placer/tools/build-outlier-latin.ts +13 -7
  7. package/coarse-placer/tools/build-outlier-oa.ts +11 -5
  8. package/coarse-placer/tools/eval-latin-offmap.ts +3 -2
  9. package/coarse-placer/tools/eval-openset.ts +3 -2
  10. package/coarse-placer/tools/eval-quant-compare.ts +3 -2
  11. package/coarse-placer/tools/eval.ts +3 -2
  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 -2
  15. package/coarse-placer/tools/quantize.ts +2 -2
  16. package/coarse-placer/tools/train.ts +2 -1
  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/containment.ts +5 -1
  22. package/decoder/index.ts +1 -0
  23. package/decoder/parse-diff.ts +347 -0
  24. package/decoder/proposals-to-tree.ts +1 -1
  25. package/decoder/serialize-json.ts +51 -7
  26. package/decoder/serialize-tuples.ts +7 -1
  27. package/decoder/serialize-xml.ts +1 -1
  28. package/decoder/tree-shape.ts +144 -0
  29. package/decoder/types.ts +8 -0
  30. package/decoder/validate-tree.ts +15 -3
  31. package/env/index.ts +3 -1
  32. package/env/paths.ts +21 -33
  33. package/env/schema.ts +26 -3
  34. package/fs/utils/formatters.ts +107 -0
  35. package/fs/utils/index.ts +7 -0
  36. package/fs/zip.ts +1 -1
  37. package/layers/manifest.ts +56 -15
  38. package/layers/schema.ts +54 -2
  39. package/locale/locale.ts +1 -1
  40. package/locale/registry.ts +1 -1
  41. package/objects.ts +20 -8
  42. package/out/api/responses.d.ts +9 -0
  43. package/out/api/responses.d.ts.map +1 -1
  44. package/out/api/responses.js +11 -0
  45. package/out/api/responses.js.map +1 -1
  46. package/out/coarse-placer/featurize.d.ts +0 -1
  47. package/out/coarse-placer/featurize.d.ts.map +1 -1
  48. package/out/coarse-placer/featurize.js.map +1 -1
  49. package/out/coarse-placer/tools/build-dataset.js +1 -1
  50. package/out/coarse-placer/tools/build-dataset.js.map +1 -1
  51. package/out/coarse-placer/tools/build-outlier-exposure.js +1 -1
  52. package/out/coarse-placer/tools/build-outlier-exposure.js.map +1 -1
  53. package/out/coarse-placer/tools/build-outlier-latin.d.ts.map +1 -1
  54. package/out/coarse-placer/tools/build-outlier-latin.js +12 -7
  55. package/out/coarse-placer/tools/build-outlier-latin.js.map +1 -1
  56. package/out/coarse-placer/tools/build-outlier-oa.d.ts.map +1 -1
  57. package/out/coarse-placer/tools/build-outlier-oa.js +10 -5
  58. package/out/coarse-placer/tools/build-outlier-oa.js.map +1 -1
  59. package/out/coarse-placer/tools/eval-latin-offmap.d.ts.map +1 -1
  60. package/out/coarse-placer/tools/eval-latin-offmap.js +2 -2
  61. package/out/coarse-placer/tools/eval-latin-offmap.js.map +1 -1
  62. package/out/coarse-placer/tools/eval-openset.d.ts.map +1 -1
  63. package/out/coarse-placer/tools/eval-openset.js +2 -2
  64. package/out/coarse-placer/tools/eval-openset.js.map +1 -1
  65. package/out/coarse-placer/tools/eval-quant-compare.d.ts.map +1 -1
  66. package/out/coarse-placer/tools/eval-quant-compare.js +2 -2
  67. package/out/coarse-placer/tools/eval-quant-compare.js.map +1 -1
  68. package/out/coarse-placer/tools/eval.d.ts.map +1 -1
  69. package/out/coarse-placer/tools/eval.js +2 -2
  70. package/out/coarse-placer/tools/eval.js.map +1 -1
  71. package/out/coarse-placer/tools/fnv-hash.d.ts +1 -6
  72. package/out/coarse-placer/tools/fnv-hash.d.ts.map +1 -1
  73. package/out/coarse-placer/tools/fnv-hash.js +1 -6
  74. package/out/coarse-placer/tools/fnv-hash.js.map +1 -1
  75. package/out/coarse-placer/tools/index.d.ts +1 -1
  76. package/out/coarse-placer/tools/index.js +1 -1
  77. package/out/coarse-placer/tools/probe-frontier.d.ts.map +1 -1
  78. package/out/coarse-placer/tools/probe-frontier.js +2 -2
  79. package/out/coarse-placer/tools/probe-frontier.js.map +1 -1
  80. package/out/coarse-placer/tools/quantize.js +2 -2
  81. package/out/coarse-placer/tools/quantize.js.map +1 -1
  82. package/out/coarse-placer/tools/train.d.ts.map +1 -1
  83. package/out/coarse-placer/tools/train.js +1 -1
  84. package/out/coarse-placer/tools/train.js.map +1 -1
  85. package/out/crypto/node.d.ts.map +1 -1
  86. package/out/crypto/node.js +2 -1
  87. package/out/crypto/node.js.map +1 -1
  88. package/out/db/schema.d.ts +12 -3
  89. package/out/db/schema.d.ts.map +1 -1
  90. package/out/db/schema.js +6 -0
  91. package/out/db/schema.js.map +1 -1
  92. package/out/decoder/containment.d.ts.map +1 -1
  93. package/out/decoder/containment.js +5 -1
  94. package/out/decoder/containment.js.map +1 -1
  95. package/out/decoder/index.d.ts +1 -0
  96. package/out/decoder/index.d.ts.map +1 -1
  97. package/out/decoder/index.js +1 -0
  98. package/out/decoder/index.js.map +1 -1
  99. package/out/decoder/parse-diff.d.ts +125 -0
  100. package/out/decoder/parse-diff.d.ts.map +1 -0
  101. package/out/decoder/parse-diff.js +219 -0
  102. package/out/decoder/parse-diff.js.map +1 -0
  103. package/out/decoder/proposals-to-tree.js.map +1 -1
  104. package/out/decoder/serialize-json.d.ts +29 -0
  105. package/out/decoder/serialize-json.d.ts.map +1 -1
  106. package/out/decoder/serialize-json.js +20 -4
  107. package/out/decoder/serialize-json.js.map +1 -1
  108. package/out/decoder/serialize-tuples.d.ts +8 -1
  109. package/out/decoder/serialize-tuples.d.ts.map +1 -1
  110. package/out/decoder/serialize-tuples.js +7 -1
  111. package/out/decoder/serialize-tuples.js.map +1 -1
  112. package/out/decoder/serialize-xml.js +1 -1
  113. package/out/decoder/serialize-xml.js.map +1 -1
  114. package/out/decoder/tree-shape.d.ts +84 -0
  115. package/out/decoder/tree-shape.d.ts.map +1 -0
  116. package/out/decoder/tree-shape.js +98 -0
  117. package/out/decoder/tree-shape.js.map +1 -0
  118. package/out/decoder/types.d.ts +11 -0
  119. package/out/decoder/types.d.ts.map +1 -1
  120. package/out/decoder/validate-tree.d.ts +8 -0
  121. package/out/decoder/validate-tree.d.ts.map +1 -1
  122. package/out/decoder/validate-tree.js +4 -3
  123. package/out/decoder/validate-tree.js.map +1 -1
  124. package/out/env/index.d.ts +10 -1
  125. package/out/env/index.d.ts.map +1 -1
  126. package/out/env/index.js +2 -1
  127. package/out/env/index.js.map +1 -1
  128. package/out/env/paths.d.ts +15 -8
  129. package/out/env/paths.d.ts.map +1 -1
  130. package/out/env/paths.js +19 -29
  131. package/out/env/paths.js.map +1 -1
  132. package/out/env/schema.d.ts +9 -1
  133. package/out/env/schema.d.ts.map +1 -1
  134. package/out/env/schema.js +25 -3
  135. package/out/env/schema.js.map +1 -1
  136. package/out/fs/utils/formatters.d.ts +57 -0
  137. package/out/fs/utils/formatters.d.ts.map +1 -0
  138. package/out/fs/utils/formatters.js +79 -0
  139. package/out/fs/utils/formatters.js.map +1 -0
  140. package/out/fs/utils/index.d.ts +7 -0
  141. package/out/fs/utils/index.d.ts.map +1 -0
  142. package/out/fs/utils/index.js +7 -0
  143. package/out/fs/utils/index.js.map +1 -0
  144. package/out/fs/zip.js +1 -1
  145. package/out/fs/zip.js.map +1 -1
  146. package/out/layers/manifest.d.ts +32 -7
  147. package/out/layers/manifest.d.ts.map +1 -1
  148. package/out/layers/manifest.js +31 -6
  149. package/out/layers/manifest.js.map +1 -1
  150. package/out/layers/schema.d.ts +48 -2
  151. package/out/layers/schema.d.ts.map +1 -1
  152. package/out/layers/schema.js +32 -0
  153. package/out/layers/schema.js.map +1 -1
  154. package/out/locale/locale.d.ts +1 -1
  155. package/out/locale/locale.d.ts.map +1 -1
  156. package/out/locale/registry.js +1 -1
  157. package/out/locale/registry.js.map +1 -1
  158. package/out/objects.d.ts +12 -6
  159. package/out/objects.d.ts.map +1 -1
  160. package/out/objects.js +4 -1
  161. package/out/objects.js.map +1 -1
  162. package/out/pipeline/index.d.ts +2 -6
  163. package/out/pipeline/index.d.ts.map +1 -1
  164. package/out/pipeline/index.js +1 -3
  165. package/out/pipeline/index.js.map +1 -1
  166. package/out/pipeline/runtime-pipeline.d.ts +51 -9
  167. package/out/pipeline/runtime-pipeline.d.ts.map +1 -1
  168. package/out/pipeline/runtime-pipeline.js +29 -132
  169. package/out/pipeline/runtime-pipeline.js.map +1 -1
  170. package/out/pipeline/span-proposer.js +1 -1
  171. package/out/pipeline/span-proposer.js.map +1 -1
  172. package/out/pipeline/types.d.ts +22 -14
  173. package/out/pipeline/types.d.ts.map +1 -1
  174. package/out/pipeline/types.js.map +1 -1
  175. package/out/policy/defaults.d.ts +1 -1
  176. package/out/policy/defaults.d.ts.map +1 -1
  177. package/out/policy/defaults.js +1 -1
  178. package/out/policy/defaults.js.map +1 -1
  179. package/out/policy/policy.d.ts +1 -1
  180. package/out/policy/policy.d.ts.map +1 -1
  181. package/out/policy/registry.d.ts +1 -1
  182. package/out/policy/registry.d.ts.map +1 -1
  183. package/out/resolver/coverage-facts.d.ts +89 -0
  184. package/out/resolver/coverage-facts.d.ts.map +1 -0
  185. package/out/resolver/coverage-facts.js +22 -0
  186. package/out/resolver/coverage-facts.js.map +1 -0
  187. package/out/resolver/index.d.ts +2 -1
  188. package/out/resolver/index.d.ts.map +1 -1
  189. package/out/resolver/index.js +1 -0
  190. package/out/resolver/index.js.map +1 -1
  191. package/out/resolver/lookup-types.d.ts +178 -0
  192. package/out/resolver/lookup-types.d.ts.map +1 -0
  193. package/out/resolver/lookup-types.js +11 -0
  194. package/out/resolver/lookup-types.js.map +1 -0
  195. package/out/resolver/placetype-map.d.ts +71 -0
  196. package/out/resolver/placetype-map.d.ts.map +1 -0
  197. package/out/resolver/placetype-map.js +98 -0
  198. package/out/resolver/placetype-map.js.map +1 -0
  199. package/out/resolver/postcode-format.d.ts +38 -0
  200. package/out/resolver/postcode-format.d.ts.map +1 -0
  201. package/out/resolver/postcode-format.js +83 -0
  202. package/out/resolver/postcode-format.js.map +1 -0
  203. package/out/resolver/types.d.ts +271 -297
  204. package/out/resolver/types.d.ts.map +1 -1
  205. package/out/resolver/types.js +4 -97
  206. package/out/resolver/types.js.map +1 -1
  207. package/out/resources/git.d.ts +8 -1
  208. package/out/resources/git.d.ts.map +1 -1
  209. package/out/resources/git.js +4 -3
  210. package/out/resources/git.js.map +1 -1
  211. package/out/resources/languages/types.gen.d.ts +1 -1
  212. package/out/resources/languages/types.gen.d.ts.map +1 -1
  213. package/out/resources/languages/types.gen.js +40 -0
  214. package/out/resources/languages/types.gen.js.map +1 -1
  215. package/out/resources/libpostal.d.ts +2 -2
  216. package/out/resources/libpostal.d.ts.map +1 -1
  217. package/out/resources/libpostal.js +2 -2
  218. package/out/resources/libpostal.js.map +1 -1
  219. package/out/resources/whosonfirst/DataSourceCache.d.ts.map +1 -1
  220. package/out/resources/whosonfirst/DataSourceCache.js.map +1 -1
  221. package/out/resources/whosonfirst/PlacetypeDataSource.d.ts +2 -2
  222. package/out/resources/whosonfirst/PlacetypeDataSource.d.ts.map +1 -1
  223. package/out/resources/whosonfirst/PlacetypeDataSource.js +28 -3
  224. package/out/resources/whosonfirst/PlacetypeDataSource.js.map +1 -1
  225. package/out/resources/whosonfirst/loader.d.ts +2 -2
  226. package/out/resources/whosonfirst/loader.d.ts.map +1 -1
  227. package/out/resources/whosonfirst/loader.js.map +1 -1
  228. package/out/resources/whosonfirst/placetypes/Placetype.d.ts.map +1 -1
  229. package/out/resources/whosonfirst/placetypes/Placetype.js +2 -2
  230. package/out/resources/whosonfirst/placetypes/Placetype.js.map +1 -1
  231. package/out/resources/whosonfirst/placetypes/admin.d.ts +9 -1
  232. package/out/resources/whosonfirst/placetypes/admin.d.ts.map +1 -1
  233. package/out/resources/whosonfirst/placetypes/admin.js +1 -1
  234. package/out/resources/whosonfirst/placetypes/admin.js.map +1 -1
  235. package/out/resources/whosonfirst/placetypes/definition.d.ts.map +1 -1
  236. package/out/resources/whosonfirst/placetypes/definition.js +1 -1
  237. package/out/resources/whosonfirst/placetypes/definition.js.map +1 -1
  238. package/out/resources/whosonfirst/placetypes/index.d.ts +1 -0
  239. package/out/resources/whosonfirst/placetypes/index.d.ts.map +1 -1
  240. package/out/resources/whosonfirst/placetypes/index.js +1 -0
  241. package/out/resources/whosonfirst/placetypes/index.js.map +1 -1
  242. package/out/resources/whosonfirst/placetypes/specificity.d.ts +65 -0
  243. package/out/resources/whosonfirst/placetypes/specificity.d.ts.map +1 -0
  244. package/out/resources/whosonfirst/placetypes/specificity.js +101 -0
  245. package/out/resources/whosonfirst/placetypes/specificity.js.map +1 -0
  246. package/out/resources/whosonfirst/sharded-repo.d.ts +28 -0
  247. package/out/resources/whosonfirst/sharded-repo.d.ts.map +1 -1
  248. package/out/resources/whosonfirst/sharded-repo.js +46 -2
  249. package/out/resources/whosonfirst/sharded-repo.js.map +1 -1
  250. package/out/scripting/arguments.d.ts +27 -0
  251. package/out/scripting/arguments.d.ts.map +1 -0
  252. package/out/scripting/arguments.js +32 -0
  253. package/out/scripting/arguments.js.map +1 -0
  254. package/out/scripting/command.d.ts +28 -0
  255. package/out/scripting/command.d.ts.map +1 -0
  256. package/out/scripting/command.js +47 -0
  257. package/out/scripting/command.js.map +1 -0
  258. package/out/scripting/index.js +3 -3
  259. package/out/scripting/index.js.map +1 -1
  260. package/out/scripting/utils/index.d.ts +1 -12
  261. package/out/scripting/utils/index.d.ts.map +1 -1
  262. package/out/scripting/utils/index.js +4 -21
  263. package/out/scripting/utils/index.js.map +1 -1
  264. package/out/tools/download-libpostal-resources.d.ts.map +1 -1
  265. package/out/tools/download-libpostal-resources.js +4 -7
  266. package/out/tools/download-libpostal-resources.js.map +1 -1
  267. package/out/tools/download-ssl-address.d.ts +3 -3
  268. package/out/tools/download-ssl-address.d.ts.map +1 -1
  269. package/out/tools/download-ssl-address.js +26 -13
  270. package/out/tools/download-ssl-address.js.map +1 -1
  271. package/out/tools/generate-language-types.d.ts +16 -1
  272. package/out/tools/generate-language-types.d.ts.map +1 -1
  273. package/out/tools/generate-language-types.js +38 -5
  274. package/out/tools/generate-language-types.js.map +1 -1
  275. package/out/tools/index.d.ts +1 -2
  276. package/out/tools/index.d.ts.map +1 -1
  277. package/out/tools/index.js +1 -2
  278. package/out/tools/index.js.map +1 -1
  279. package/out/utils/data-root.d.ts +27 -7
  280. package/out/utils/data-root.d.ts.map +1 -1
  281. package/out/utils/data-root.js +36 -13
  282. package/out/utils/data-root.js.map +1 -1
  283. package/out/utils/hash.d.ts +2 -3
  284. package/out/utils/hash.d.ts.map +1 -1
  285. package/out/utils/hash.js +3 -3
  286. package/out/utils/hash.js.map +1 -1
  287. package/out/utils/index.d.ts +1 -0
  288. package/out/utils/index.d.ts.map +1 -1
  289. package/out/utils/index.js +1 -0
  290. package/out/utils/index.js.map +1 -1
  291. package/out/utils/jsonl.js +1 -1
  292. package/out/utils/jsonl.js.map +1 -1
  293. package/out/utils/repo.d.ts +8 -0
  294. package/out/utils/repo.d.ts.map +1 -1
  295. package/out/utils/repo.js +10 -1
  296. package/out/utils/repo.js.map +1 -1
  297. package/out/utils/sealed-db.d.ts +11 -0
  298. package/out/utils/sealed-db.d.ts.map +1 -1
  299. package/out/utils/sealed-db.js +28 -1
  300. package/out/utils/sealed-db.js.map +1 -1
  301. package/out/utils/sqlite-rows.d.ts +34 -0
  302. package/out/utils/sqlite-rows.d.ts.map +1 -0
  303. package/out/utils/sqlite-rows.js +37 -0
  304. package/out/utils/sqlite-rows.js.map +1 -0
  305. package/out/utils/stats.d.ts +1 -6
  306. package/out/utils/stats.d.ts.map +1 -1
  307. package/out/utils/stats.js +1 -6
  308. package/out/utils/stats.js.map +1 -1
  309. package/package.json +476 -7
  310. package/pipeline/index.ts +12 -14
  311. package/pipeline/runtime-pipeline.ts +29 -183
  312. package/pipeline/span-proposer.ts +1 -1
  313. package/pipeline/types.ts +26 -15
  314. package/policy/defaults.ts +1 -1
  315. package/policy/policy.ts +1 -1
  316. package/policy/registry.ts +1 -1
  317. package/resolver/coverage-facts.ts +102 -0
  318. package/resolver/index.ts +5 -0
  319. package/resolver/lookup-types.ts +174 -0
  320. package/resolver/placetype-map.ts +122 -0
  321. package/resolver/postcode-format.ts +89 -0
  322. package/resolver/types.ts +293 -351
  323. package/resources/git.ts +18 -4
  324. package/resources/languages/types.gen.ts +60 -0
  325. package/resources/libpostal.ts +4 -3
  326. package/resources/whosonfirst/DataSourceCache.ts +2 -1
  327. package/resources/whosonfirst/PlacetypeDataSource.ts +36 -11
  328. package/resources/whosonfirst/loader.ts +3 -2
  329. package/resources/whosonfirst/placetypes/Placetype.ts +3 -2
  330. package/resources/whosonfirst/placetypes/admin.ts +11 -2
  331. package/resources/whosonfirst/placetypes/definition.ts +4 -3
  332. package/resources/whosonfirst/placetypes/index.ts +1 -0
  333. package/resources/whosonfirst/placetypes/specificity.ts +114 -0
  334. package/resources/whosonfirst/sharded-repo.ts +55 -2
  335. package/scripting/arguments.ts +38 -0
  336. package/scripting/command.ts +55 -0
  337. package/scripting/index.ts +3 -3
  338. package/scripting/utils/index.ts +6 -23
  339. package/tools/download-libpostal-resources.ts +4 -7
  340. package/tools/download-ssl-address.ts +28 -12
  341. package/tools/generate-language-types.ts +39 -5
  342. package/tools/index.ts +1 -2
  343. package/utils/data-root.ts +40 -14
  344. package/utils/hash.ts +5 -4
  345. package/utils/index.ts +1 -0
  346. package/utils/jsonl.ts +1 -1
  347. package/utils/repo.ts +12 -1
  348. package/utils/sealed-db.ts +30 -1
  349. package/utils/sqlite-rows.ts +40 -0
  350. package/utils/stats.ts +1 -6
  351. package/data/libpostal/dictionaries/all/chains.txt +0 -504
  352. package/kysley/adapter.ts +0 -29
  353. package/out/kysley/adapter.d.ts +0 -13
  354. package/out/kysley/adapter.d.ts.map +0 -1
  355. package/out/kysley/adapter.js +0 -25
  356. package/out/kysley/adapter.js.map +0 -1
  357. package/out/pipeline/reconcile-lookups.d.ts +0 -39
  358. package/out/pipeline/reconcile-lookups.d.ts.map +0 -1
  359. package/out/pipeline/reconcile-lookups.js +0 -88
  360. package/out/pipeline/reconcile-lookups.js.map +0 -1
  361. package/out/pipeline/reconcile.d.ts +0 -153
  362. package/out/pipeline/reconcile.d.ts.map +0 -1
  363. package/out/pipeline/reconcile.js +0 -388
  364. package/out/pipeline/reconcile.js.map +0 -1
  365. package/out/pipeline/span-logit-aggregation.d.ts +0 -58
  366. package/out/pipeline/span-logit-aggregation.d.ts.map +0 -1
  367. package/out/pipeline/span-logit-aggregation.js +0 -117
  368. package/out/pipeline/span-logit-aggregation.js.map +0 -1
  369. package/pipeline/reconcile-lookups.ts +0 -111
  370. package/pipeline/reconcile.ts +0 -583
  371. package/pipeline/span-logit-aggregation.ts +0 -156
@@ -11,13 +11,66 @@
11
11
  * parsed record has.
12
12
  */
13
13
 
14
- import { existsSync, readFileSync } from "node:fs"
14
+ import { existsSync, readFileSync, statSync } from "node:fs"
15
15
 
16
- import { tryParsingJSON } from "@mailwoman/core/objects"
17
16
  import { resolvePath } from "path-ts"
18
17
 
18
+ import { tryParsingJSON } from "#objects"
19
+
19
20
  import type { WOFFeature } from "./placetypes/admin.ts"
20
21
 
22
+ /**
23
+ * The GitHub organization holding the country data repositories.
24
+ */
25
+ export const WOF_DATA_OWNER = "whosonfirst-data"
26
+
27
+ /**
28
+ * The repository name for a country's data of one theme — `whosonfirst-data-admin-tr`.
29
+ *
30
+ * Four call sites used to build this string themselves, each with its own `toLowerCase()`, which is how a country code
31
+ * arriving uppercase became a directory that silently does not exist.
32
+ */
33
+ export function wofRepoName(theme: "admin" | "postalcode" | "venue", country: string): string {
34
+ return `${WOF_DATA_OWNER}-${theme}-${country.toLowerCase()}`
35
+ }
36
+
37
+ /**
38
+ * Find a cloned repository under a repositories root, in either layout.
39
+ *
40
+ * Two are in use and both are legitimate. `gazetteer inspect sync` writes `<root>/<owner>/<name>`, which is what the
41
+ * admin ingest's depth-agnostic GeoJSON glob reads. The shipped postcode shards were built from repositories cloned by
42
+ * hand as `<root>/<name>`. A reader that knows one layout reports a repository that is present as MISSING, and every
43
+ * reader here treats missing as "no evidence" and continues — so the wrong layout is silent, not loud.
44
+ *
45
+ * Synchronous to match {@link readWOFFeature}: these readers run inside sync loops over database rows.
46
+ */
47
+ export function resolveWOFRepo(reposRoot: string, name: string, owner = WOF_DATA_OWNER): string | null {
48
+ for (const candidate of [resolvePath(reposRoot, owner, name), resolvePath(reposRoot, name)]) {
49
+ try {
50
+ if (statSync(candidate).isDirectory()) return candidate.toString()
51
+ } catch {
52
+ // Absent, or unreadable — try the other layout, then answer null.
53
+ }
54
+ }
55
+
56
+ return null
57
+ }
58
+
59
+ /**
60
+ * The `data` directory of a country's repository, or `null` when the repository is not cloned.
61
+ *
62
+ * The pairing every reader needs: {@link readWOFFeature} takes roots that already point INTO `data`.
63
+ */
64
+ export function resolveWOFDataDir(
65
+ reposRoot: string,
66
+ theme: "admin" | "postalcode" | "venue",
67
+ country: string
68
+ ): string | null {
69
+ const repo = resolveWOFRepo(reposRoot, wofRepoName(theme, country))
70
+
71
+ return repo && resolvePath(repo, "data").toString()
72
+ }
73
+
21
74
  /**
22
75
  * Characters per directory level. A trailing group shorter than this is its own directory — `85977539` ends in `39`,
23
76
  * not `390`.
@@ -0,0 +1,38 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ *
6
+ * Dependency-free process argument accessors. Kept separate from script cleanup/logging so latency-sensitive CLI
7
+ * dispatchers can read argv without loading the ResourceError, ConsoleLogger, and async-init graphs.
8
+ */
9
+
10
+ export type UnsafeCLIArgument = string & { __unsafeCLIArgumentBrand: never }
11
+
12
+ export type UnsafeCLIArguments = ReadonlyArray<UnsafeCLIArgument>
13
+
14
+ /**
15
+ * The one blessed accessor for user CLI arguments.
16
+ */
17
+ export function cliArguments(): UnsafeCLIArguments {
18
+ // oxlint-disable-next-line sister-software/no-process-globals -- this function is the blessed argv accessor
19
+ return process.argv.slice(2) as unknown as UnsafeCLIArguments
20
+ }
21
+
22
+ /**
23
+ * Forward the CLI arguments to a child process.
24
+ *
25
+ * Do not use this function unless its arguments are being passed to a child process.
26
+ */
27
+ export function passThroughCLIArguments(): readonly unknown[] {
28
+ // oxlint-disable-next-line sister-software/no-process-globals -- Forwarding arguments to a child process.
29
+ return process.argv.slice(2)
30
+ }
31
+
32
+ /**
33
+ * The path of the executing script (`argv[1]`).
34
+ */
35
+ export function scriptEntryPath(): string {
36
+ // oxlint-disable-next-line sister-software/no-process-globals -- this function is the blessed argv entry-path accessor
37
+ return process.argv[1]!
38
+ }
@@ -0,0 +1,55 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ *
6
+ * Dependency-light lifecycle and error primitives for user-facing CLI commands. This is intentionally separate from
7
+ * `scripting/utils`, whose service disposal and structured logging are appropriate for long-running scripts.
8
+ */
9
+
10
+ /**
11
+ * An expected command failure whose message is safe to show directly. The original failure belongs in `cause`.
12
+ */
13
+ export class CommandError extends Error {
14
+ readonly exitCode = 1
15
+
16
+ constructor(message: string, options?: ErrorOptions) {
17
+ super(message, options)
18
+ this.name = "CommandError"
19
+ }
20
+ }
21
+
22
+ /**
23
+ * Format an expected command failure as guidance and preserve stacks for unexpected failures.
24
+ */
25
+ export function formatCommandError(error: unknown): string {
26
+ if (error instanceof CommandError) return error.message
27
+
28
+ return error instanceof Error ? (error.stack ?? error.message) : String(error)
29
+ }
30
+
31
+ /**
32
+ * Log a command failure and the cause attached to expected guidance errors.
33
+ */
34
+ export function reportError(error: unknown): void {
35
+ console.error(formatCommandError(error))
36
+
37
+ if (error instanceof CommandError && error.cause !== undefined) {
38
+ console.error(`Caused by: ${formatCommandError(error.cause)}`)
39
+ }
40
+ }
41
+
42
+ /**
43
+ * Run a CLI command with one consistent stderr and exit-code boundary.
44
+ */
45
+ export function runCLICommand(
46
+ command: () => number | undefined | Promise<number | undefined>
47
+ ): Promise<number | undefined> {
48
+ return Promise.resolve()
49
+ .then(command)
50
+ .catch((error: unknown) => {
51
+ reportError(error)
52
+
53
+ return 1
54
+ })
55
+ }
@@ -24,9 +24,9 @@ export async function runIfScript(meta: ImportMeta, scriptCallback: ScriptCallba
24
24
  if (!meta.main) return
25
25
 
26
26
  const [{ $public }, { ConsoleLogger, stringifyLoggedObject }, { runScript }] = await Promise.all([
27
- import("@mailwoman/core/env"),
28
- import("@mailwoman/core/logging"),
29
- import("@mailwoman/core/scripting/utils"),
27
+ import("#env"),
28
+ import("#logging"),
29
+ import("#scripting/utils"),
30
30
  ])
31
31
 
32
32
  ConsoleLogger.info(
@@ -1,7 +1,10 @@
1
- import { ResourceError } from "@mailwoman/core/errors"
2
- import { ConsoleLogger } from "@mailwoman/core/logging"
3
1
  import { defaultRegistry } from "async-init"
4
2
 
3
+ import { ResourceError } from "#errors"
4
+ import { ConsoleLogger } from "#logging"
5
+
6
+ export { cliArguments, passThroughCLIArguments, scriptEntryPath } from "../arguments.ts"
7
+
5
8
  /**
6
9
  * Logs an error that occurred while running a script.
7
10
  */
@@ -73,32 +76,12 @@ export function runScript(scriptCallback: ScriptCallback): Promise<void> {
73
76
  .catch(() => postScriptCleanup("SIGTERM", 1))
74
77
  }
75
78
 
76
- /**
77
- * The ONE blessed accessor for CLI arguments. Everything outside `core/env` + this module is forbidden from touching
78
- * `process.argv` directly (enforced by the `sister-software/no-process-globals` oxlint rule) — prefer `node:util`
79
- * `parseArgs` (which reads this same slice by default) and reach for this only where `parseArgs` cannot express the
80
- * grammar (e.g. verbatim passthrough of undeclared flags to a child process — see
81
- * `corpus-python/scripts/train_with_resume.ts`).
82
- */
83
- export function cliArguments(): string[] {
84
- // oxlint-disable-next-line sister-software/no-process-globals
85
- return process.argv.slice(2)
86
- }
87
-
88
79
  /**
89
80
  * The ONE blessed way to build a child-process environment: the current environment with explicit overrides. Everything
90
81
  * outside `core/env` + this module is forbidden from touching `process.env` directly (enforced by
91
82
  * `scripts/lint-raw-env-argv.ts`) — read config through `$public`/`$private`.
92
83
  */
93
84
  export function childEnv(overrides: Record<string, string | undefined> = {}): NodeJS.ProcessEnv {
94
- // oxlint-disable-next-line sister-software/no-process-globals
85
+ // oxlint-disable-next-line sister-software/no-process-globals -- this function is the blessed child-process environment boundary
95
86
  return { ...process.env, ...overrides }
96
87
  }
97
-
98
- /**
99
- * The path of the executing script (`argv[1]`) — for commands that re-spawn or reference their own CLI entry.
100
- */
101
- export function scriptEntryPath(): string {
102
- // oxlint-disable-next-line sister-software/no-process-globals
103
- return process.argv[1]!
104
- }
@@ -28,8 +28,9 @@ import { cp, mkdtemp, readdir, readFile, rm, writeFile } from "node:fs/promises"
28
28
  import { tmpdir } from "node:os"
29
29
  import { join } from "node:path"
30
30
 
31
- import { isDirectory } from "@mailwoman/core/fs"
32
- import { resourceDictionaryPath } from "@mailwoman/core/utils"
31
+ import { isDirectory } from "#fs"
32
+ import { CommandError } from "#scripting/command"
33
+ import { resourceDictionaryPath } from "#utils"
33
34
 
34
35
  const REPO_URL = "https://github.com/openvenues/libpostal.git"
35
36
  const DICTIONARIES_DIR = resourceDictionaryPath("libpostal")
@@ -68,11 +69,7 @@ export async function downloadLibpostalResources(
68
69
  report?.("Warning: The dictionaries directory already exists. Deleting it due to --force flag.")
69
70
  await rm(DICTIONARIES_DIR, { recursive: true, force: true })
70
71
  } else {
71
- // Guidance-grade refusal: suppress the stack so the CLI renders just the message
72
- // (core can't import mailwoman/cli-kit's commandError — wrong dependency direction).
73
- const error = new Error("The dictionaries directory already exists. Remove it first or pass --force.")
74
- error.stack = error.message
75
- throw error
72
+ throw new CommandError("The dictionaries directory already exists. Remove it first or pass --force.")
76
73
  }
77
74
  }
78
75
 
@@ -9,9 +9,9 @@
9
9
  *
10
10
  * See: https://github.com/google/libaddressinput/wiki/AddressValidationMetadata
11
11
  *
12
- * Replaces the bash `ssl-address-download.sh` (curl + jq) with native `fetch` + `JSON.parse`. The
13
- * country list lives at `…/ssl-address/data` as a `~`-delimited `.countries` string; each country's
14
- * record is then fetched from `…/ssl-address/data/<CC>` and written to `<out-dir>/<CC>.json`.
12
+ * Replaces the bash `ssl-address-download.sh` (curl + jq). The country list lives at
13
+ * `…/ssl-address/data` as a `~`-delimited `.countries` string; each country's record is then
14
+ * fetched from `…/ssl-address/data/<CC>` and written to `<out-dir>/<CC>.json`.
15
15
  *
16
16
  * ## Usage
17
17
  *
@@ -28,10 +28,26 @@
28
28
  import { mkdir, writeFile } from "node:fs/promises"
29
29
  import { join } from "node:path"
30
30
 
31
- import { corePackagePath } from "@mailwoman/core/utils"
31
+ import { corePackagePath } from "#utils"
32
+
33
+ import { APIClient, pluckResponseData } from "../api/index.ts"
32
34
 
33
35
  const BASE_URL = "https://chromium-i18n.appspot.com/ssl-address/data"
34
36
 
37
+ /**
38
+ * One host, ~250 small records, fetched `concurrency`-wide.
39
+ *
40
+ * Retry is the point: a throttle or a dropped connection on ONE country previously counted as a permanent failure for
41
+ * that country, and the run reported `written: 249, failed: 1` — indistinguishable from a country the source does not
42
+ * carry. No `minRequestIntervalMs`: the concurrency-wide burst is what this tool has always done and the host has not
43
+ * objected, and inventing a rate limit no measurement supports would only make a working tool slower.
44
+ */
45
+ const sslAddressClient = new APIClient({
46
+ displayName: "ssl-address",
47
+ retry: true,
48
+ axios: { timeout: 60_000 },
49
+ })
50
+
35
51
  /**
36
52
  * Flag-shaped options for {@linkcode downloadSSLAddress}.
37
53
  */
@@ -50,22 +66,22 @@ export interface DownloadSSLAddressOptions {
50
66
  * Fetch the `~`-delimited country list and return it as an array of ISO codes.
51
67
  */
52
68
  async function fetchCountryCodes(): Promise<string[]> {
53
- const res = await fetch(BASE_URL, { signal: AbortSignal.timeout(60_000) })
54
-
55
- if (!res.ok) throw new Error(`HTTP ${res.status} ${res.statusText} fetching country list`)
56
- const data = (await res.json()) as { countries?: string }
69
+ const data = await sslAddressClient.fetch<{ countries?: string }>({ url: BASE_URL }).then(pluckResponseData)
57
70
 
58
- return (data.countries ?? "").split("~").filter(Boolean)
71
+ return (data.countries ?? "").split("~").filter((code) => code.length > 0)
59
72
  }
60
73
 
61
74
  /**
62
75
  * Fetch a single country's metadata record and write its raw JSON body to `<outDir>/<cc>.json`.
63
76
  */
64
77
  async function fetchCountry(cc: string, outDir: string): Promise<void> {
65
- const res = await fetch(`${BASE_URL}/${cc}`, { signal: AbortSignal.timeout(60_000) })
78
+ // `responseType: "text"` keeps the RAW body: these records are written to disk verbatim, and letting
79
+ // axios parse then re-serialize would rewrite key order and spacing in a checked-in artifact.
80
+ const body = await sslAddressClient
81
+ .fetch<string>({ url: `${BASE_URL}/${cc}`, responseType: "text" })
82
+ .then(pluckResponseData)
66
83
 
67
- if (!res.ok) throw new Error(`HTTP ${res.status} ${res.statusText} on ${cc}`)
68
- await writeFile(join(outDir, `${cc}.json`), await res.text())
84
+ await writeFile(join(outDir, `${cc}.json`), body)
69
85
  }
70
86
 
71
87
  /**
@@ -3,9 +3,24 @@
3
3
  * @license AGPL-3.0
4
4
  * @author Teffen Ellis, et al.
5
5
  *
6
- * Regenerate `core/resources/languages/types.gen.ts` — the ISO 639-1/639-2b language-code types +
6
+ * Regenerate `core/resources/languages/types.gen.ts` — the ISO 639-1 / 639-2 language-code types +
7
7
  * label maps — from the committed `internal/languages.csv` resource dictionary.
8
8
  *
9
+ * BOTH 639-2 standards are emitted, and the reason is data, not completeness. ISO 639-2 has two
10
+ * three-letter forms: /B (bibliographic) and /T (terminological, identical to 639-3). They differ
11
+ * for exactly 20 languages, and **Who's On First keys its name properties in /T** — so a /B-only
12
+ * union excluded `deu`, `fra` and `nld`, three tier-1 locales, while admitting spellings the data
13
+ * never uses. Measured over the built gazetteer's `names` table: 3,591,751 rows on the /T side of
14
+ * those 20 pairs against 247 on the /B side, a ratio of 14,542:1.
15
+ *
16
+ * /B is NOT dropped: `packages/codex/country/official-languages.ts` lists both forms deliberately
17
+ * (`DE: ["de","deu","ger"]`) and 247 real rows carry one, so the union accepts either and both map
18
+ * to the same label and the same alpha-2.
19
+ *
20
+ * NAME DEBT, deliberately not paid here: `Alpha3bLanguageCode`, `Alpha3bLabelMap`, `Alpha3bToAlpha2`
21
+ * and the CSV's `alpha3-b` header all still say "b" while holding both standards. Renaming them is a
22
+ * published-API break and belongs in a major.
23
+ *
9
24
  * Usage: mailwoman dev generate language-types
10
25
  */
11
26
 
@@ -14,7 +29,7 @@ import * as fs from "node:fs/promises"
14
29
  import { pascalCase } from "change-case"
15
30
  import { CSVSpliterator } from "spliterator"
16
31
 
17
- import { repoRootPath, resourceDictionaryPath } from "../utils/index.ts"
32
+ import { resourceDictionaryPath, workspacePath } from "../utils/index.ts"
18
33
 
19
34
  /**
20
35
  * Options for {@linkcode generateLanguageTypes}.
@@ -41,12 +56,14 @@ export async function generateLanguageTypes(
41
56
  options: GenerateLanguageTypesOptions = {},
42
57
  report?: (line: string) => void
43
58
  ): Promise<GenerateLanguageTypesSummary> {
44
- const outfile = options.out ?? repoRootPath("core", "resources", "languages", "types.gen.ts")
59
+ const outfile = options.out ?? workspacePath("core", "resources", "languages", "types.gen.ts")
45
60
  const dataSourcePath = resourceDictionaryPath("internal", "languages.csv")
46
61
 
47
62
  const alpha2Entries = new Map<string, string[]>()
48
63
  const alpha3bEntries = new Map<string, string[]>()
49
64
  const entryLines: [alpha2: string, alpha3b: string][] = []
65
+ // The 20 divergent /T spellings, kept apart so they widen the accepting direction only.
66
+ const alpha3tPairs: [alpha2: string, alpha3t: string][] = []
50
67
 
51
68
  report?.(`Reading ${dataSourcePath}`)
52
69
 
@@ -57,6 +74,8 @@ export async function generateLanguageTypes(
57
74
  const alpha3b = columns[0] as string
58
75
  const alpha2 = columns[1] as string
59
76
  const labelsConcatenated = columns[2] as string
77
+ // Empty for the 163 languages whose two 639-2 forms agree; a distinct code for the 20 that diverge.
78
+ const alpha3t = (columns[3] as string | undefined) ?? ""
60
79
 
61
80
  const labels = labelsConcatenated.split("; ")
62
81
 
@@ -64,6 +83,19 @@ export async function generateLanguageTypes(
64
83
  alpha3bEntries.set(alpha3b, labels)
65
84
 
66
85
  entryLines.push([alpha2, alpha3b])
86
+
87
+ // The /T spelling is a first-class member of the same union and maps to the same label and the
88
+ // same alpha-2. It is the form WOF actually writes, so a lookup keyed on it must hit.
89
+ //
90
+ // It goes to `alpha3tPairs`, NOT to `entryLines`. Both lists build BOTH direction maps from a
91
+ // `new Map([...])`, where the LAST entry for a key wins — so appending the /T form to
92
+ // `entryLines` would silently flip `Alpha2ToAlpha3b.get("de")` from `ger` to `deu`. That map is
93
+ // named for the /B standard and documented as returning it; changing what it answers is a
94
+ // separate decision from widening what the union ACCEPTS, and it is not this one.
95
+ if (alpha3t) {
96
+ alpha3bEntries.set(alpha3t, labels)
97
+ alpha3tPairs.push([alpha2, alpha3t])
98
+ }
67
99
  }
68
100
 
69
101
  const handle = await fs.open(outfile, "w")
@@ -177,8 +209,10 @@ export const Alpha2ToAlpha3b: ReadonlyMap<Alpha2LanguageCode, Alpha3bLanguageCod
177
209
  export const Alpha3bToAlpha2: ReadonlyMap<Alpha3bLanguageCode, Alpha2LanguageCode> = new Map([
178
210
  `)
179
211
 
180
- for (const [alpha2, alpha3b] of entryLines) {
181
- await writeLine(`["${alpha3b}", "${alpha2}"],`)
212
+ // This direction ACCEPTS a code, so it takes both spellings — the keys are distinct, nothing is
213
+ // overwritten, and `deu` answers `de` exactly as `ger` does.
214
+ for (const [alpha2, alpha3] of [...entryLines, ...alpha3tPairs]) {
215
+ await writeLine(`["${alpha3}", "${alpha2}"],`)
182
216
  }
183
217
 
184
218
  await writeLine(`])`)
package/tools/index.ts CHANGED
@@ -4,8 +4,7 @@
4
4
  * @author Teffen Ellis, et al.
5
5
  *
6
6
  * Core operator tools — the `run()`-style modules behind `mailwoman dev generate …` commands. No
7
- * argv, no `process.exit`: commands own parsing, rendering, and exit codes (see the 2026-07-09
8
- * scripts→Pastel spec).
7
+ * argv, no `process.exit`: commands own parsing, rendering, and exit codes.
9
8
  */
10
9
 
11
10
  export * from "./download-libpostal-resources.ts"
@@ -3,12 +3,7 @@
3
3
  * @license AGPL-3.0
4
4
  * @author Teffen Ellis, et al.
5
5
  *
6
- * The Mailwoman data root — the single, env-configurable home for every shard, model, anchor, and
7
- * manifest the runtime + build tooling read. Centralized here (mirroring isp-nexus's
8
- * `dataSourcePathBuilder`) so the lab `/mnt/playpen/...` default lives in EXACTLY ONE place instead
9
- * of as a literal scattered across the codebase, and so consumers compose paths through
10
- * {@link dataRootPath} rather than re-deriving the string. Going public, this is the only file that
11
- * names the operator's filesystem layout; everything else reads `$MAILWOMAN_DATA_ROOT`.
6
+ * Path builders for Mailwoman's platform-native application directories.
12
7
  */
13
8
 
14
9
  import { resolvePath } from "path-ts"
@@ -16,16 +11,10 @@ import { resolvePath } from "path-ts"
16
11
  import { $public } from "../env/index.ts"
17
12
 
18
13
  /**
19
- * The lab default data root — the ONE place this literal appears. Everything else builds on {@link dataRootPath} /
20
- * {@link mailwomanDataRoot}; override per-deployment with `$MAILWOMAN_DATA_ROOT`.
21
- */
22
- const DEFAULT_MAILWOMAN_DATA_ROOT = "/mnt/playpen/mailwoman-data"
23
-
24
- /**
25
- * The Mailwoman data root: `$MAILWOMAN_DATA_ROOT` when set, else the lab default.
14
+ * The Mailwoman data root from the typed public environment.
26
15
  */
27
16
  export function mailwomanDataRoot(): string {
28
- return $public.MAILWOMAN_DATA_ROOT ?? DEFAULT_MAILWOMAN_DATA_ROOT
17
+ return $public.MAILWOMAN_DATA_ROOT
29
18
  }
30
19
 
31
20
  /**
@@ -36,6 +25,43 @@ export function dataRootPath(...segments: string[]): string {
36
25
  return resolvePath(mailwomanDataRoot(), ...segments)
37
26
  }
38
27
 
28
+ /**
29
+ * The dev-weights overlay for a locale: `$MAILWOMAN_DATA_ROOT/weights/<locale>/`.
30
+ *
31
+ * ONE definition of the convention, because it is written by ten `link-dev-weights.ts` scripts and read by
32
+ * `@mailwoman/neural`'s `resolveWeights`, and a reader that disagreed with the writers about the directory would report
33
+ * the artifacts absent rather than misplaced — every sibling degrades `existsSync → undefined`.
34
+ *
35
+ * It lives OUTSIDE git deliberately. The binaries are not committed, so materializing them into the tracked package
36
+ * directory is what made a fresh worktree unable to geocode, made `yarn test` mutate tracked directories as a side
37
+ * effect, and put a symlink in a publish tarball (`YN0035`). The data root is shared across every checkout on the
38
+ * machine and is not packed by anything.
39
+ */
40
+ export function weightsOverlayPath(locale: string, ...segments: string[]): string {
41
+ return dataRootPath("weights", locale.toLowerCase(), ...segments)
42
+ }
43
+
44
+ /**
45
+ * The Mailwoman temporary-file root from the typed public environment.
46
+ */
47
+ export function mailwomanTempRoot(): string {
48
+ return $public.MAILWOMAN_TEMP_ROOT
49
+ }
50
+
51
+ /**
52
+ * Build an absolute path under Mailwoman's temporary-file root.
53
+ */
54
+ export function tempRootPath(...segments: string[]): string {
55
+ return resolvePath(mailwomanTempRoot(), ...segments)
56
+ }
57
+
58
+ /**
59
+ * Build an absolute path under Mailwoman's application cache directory.
60
+ */
61
+ export function cacheRootPath(...segments: string[]): string {
62
+ return resolvePath($public.MAILWOMAN_CACHE_ROOT, ...segments)
63
+ }
64
+
39
65
  /**
40
66
  * The default WOF shard list the FTS backend probes when no single `--wof-db` is given: the global admin-priority shard
41
67
  * plus the postcode shards, with country-aware routing in `pickShardForPlacetype` sending each postcode query to the
package/utils/hash.ts CHANGED
@@ -3,8 +3,7 @@
3
3
  * @license AGPL-3.0
4
4
  * @author Teffen Ellis, et al.
5
5
  *
6
- * File/content hashing — the canonical home for the ~12 `sha256OfFile` clones the 2026-07-09
7
- * dedupe survey found across the corpus fetch scripts.
6
+ * File and content hashing utilities.
8
7
  */
9
8
 
10
9
  import { createHash } from "node:crypto"
@@ -26,8 +25,10 @@ export async function sha256File(path: string): Promise<string> {
26
25
  /**
27
26
  * SHA-256 of in-memory content, hex-encoded.
28
27
  */
29
- export function sha256Hex(data: string | NodeJS.ArrayBufferView): string {
30
- return createHash("sha256").update(data).digest("hex")
28
+ export function sha256Hex(data: string | NodeJS.ArrayBufferView | string[]): string {
29
+ const formattedData = Array.isArray(data) ? data.join("\n") : data
30
+
31
+ return createHash("sha256").update(formattedData).digest("hex")
31
32
  }
32
33
 
33
34
  /**
package/utils/index.ts CHANGED
@@ -12,4 +12,5 @@ export * from "./python-numeric.ts"
12
12
  export * from "./python-random.ts"
13
13
  export * from "./repo.ts"
14
14
  export * from "./sealed-db.ts"
15
+ export * from "./sqlite-rows.ts"
15
16
  export * from "./stats.ts"
package/utils/jsonl.ts CHANGED
@@ -29,7 +29,7 @@ export function readJSONL<T>(path: string): T[] {
29
29
  return (
30
30
  [...TextSpliterator.from(readFileSync(path, "utf8"))]
31
31
  .filter((line) => line.trim().length > 0)
32
- // oxlint-disable-next-line no-restricted-properties
32
+ // oxlint-disable-next-line no-restricted-properties -- deprecated helper's throw-on-corrupt contract is preserved
33
33
  .map((line) => JSON.parse(line) as T)
34
34
  )
35
35
  }
package/utils/repo.ts CHANGED
@@ -26,7 +26,7 @@ const RepoRootAlias = "mailwoman" as const
26
26
 
27
27
  type RepoRootAlias = typeof RepoRootAlias
28
28
 
29
- const PathReflection = ["core", "out", "utils"] as const
29
+ const PathReflection = ["packages", "core", "out", "utils"] as const
30
30
 
31
31
  type PathReflection = typeof PathReflection
32
32
 
@@ -68,6 +68,7 @@ const __dirname = dirname(fileURLToPath(import.meta.url)) as Join<[RepoRootAlias
68
68
  const __isCompiledTree = basename(resolve(__dirname, "..")) === OutDirectoryName
69
69
  const __upCount = __isCompiledTree ? PathReflection.length : PathReflection.length - 1
70
70
  const RepoRootAbsolutePath = resolve(__dirname, ...Array.from({ length: __upCount }, () => ".."))
71
+ const PackagesAbsolutePath = resolve(RepoRootAbsolutePath, "packages")
71
72
 
72
73
  type RepoRootAbsolutePath = RepoRootAlias
73
74
 
@@ -82,6 +83,16 @@ export const repoRootPathBuilder = createPathBuilderResolver<RepoRootAlias>(Repo
82
83
  */
83
84
  export const repoRootPath = createPathResolver<RepoRootAlias>(RepoRootAbsolutePath)
84
85
 
86
+ /**
87
+ * Path builder relative to the directory containing the public workspaces.
88
+ */
89
+ export const workspacePathBuilder = createPathBuilderResolver<RepoRootAlias>(PackagesAbsolutePath)
90
+
91
+ /**
92
+ * Absolute-path-string resolver relative to the directory containing the public workspaces.
93
+ */
94
+ export const workspacePath = createPathResolver<RepoRootAlias>(PackagesAbsolutePath)
95
+
85
96
  /**
86
97
  * Path builder relative to the `@mailwoman/core` workspace root (the directory containing `package.json` for this
87
98
  * package).
@@ -84,6 +84,25 @@ export function sealDatabase(path: string): void {
84
84
  chmodSync(path, 0o444)
85
85
  }
86
86
 
87
+ /**
88
+ * Verify a freshly-built database is not corrupt, immediately before it is sealed and published.
89
+ *
90
+ * Belongs beside {@link sealDatabase} for the same reason `swapDatabaseIntoPlace` does: the check is part of the
91
+ * built-artifact lifecycle, and every builder was running it from its own copy. `integrity_check` answers with the
92
+ * single row `{ integrity_check: "ok" }` on a healthy file and one row per problem otherwise, so only the first matters
93
+ * — a builder that reads the column and compares it to `"ok"` has done the whole check.
94
+ *
95
+ * @throws When the database reports anything other than `ok`, naming the artifact and what SQLite said.
96
+ */
97
+ export function assertDatabaseIntegrity(db: DatabaseSync, artifact: string): void {
98
+ const row = db.prepare("PRAGMA integrity_check").get() as { integrity_check: string } | undefined
99
+ const verdict = row?.integrity_check
100
+
101
+ if (verdict !== "ok") {
102
+ throw new Error(`integrity_check failed on ${basename(artifact)}: ${verdict ?? "no result"}`)
103
+ }
104
+ }
105
+
87
106
  /**
88
107
  * Open a data artifact. Read-only by default. `write: true` is for builders working on UNsealed staging — against a
89
108
  * sealed artifact it throws {@link SealedArtifactError}.
@@ -120,7 +139,17 @@ export function swapDatabaseIntoPlace(tmpPath: string, finalPath: string): void
120
139
  rmSync(finalPath + sfx, { force: true })
121
140
  }
122
141
 
123
- renameSync(tmpPath, finalPath)
142
+ try {
143
+ renameSync(tmpPath, finalPath)
144
+ } catch (error) {
145
+ // The prior version is already aside at this point — a failed forward rename must not leave
146
+ // the slot empty while a restorable artifact sits one rename away.
147
+ if (existsSync(aside) && !existsSync(finalPath)) {
148
+ renameSync(aside, finalPath)
149
+ }
150
+
151
+ throw error
152
+ }
124
153
 
125
154
  for (const sfx of ["-wal", "-shm"]) {
126
155
  rmSync(tmpPath + sfx, { force: true })
@@ -0,0 +1,40 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ *
6
+ * The `node:sqlite` → typed-row seam, in ONE place.
7
+ *
8
+ * `node:sqlite` types every result as `Record<string, SQLOutputValue>` because it cannot infer a row shape from SQL
9
+ * text, so every raw read needs an assertion somewhere. That assertion belongs at this boundary rather than repeated
10
+ * at each query site: a cast written inline is invisible to review and indistinguishable from a cast that is
11
+ * defeating a real check, which is how a branded key column came to be written with an unfolded value (#1757).
12
+ *
13
+ * It lives in `core` rather than beside the resolver's readers because `@mailwoman/resolver-wof-sqlite` is an
14
+ * OPTIONAL peer of `mailwoman` — a static import of it from there would break the contract that lets a consumer
15
+ * install the CLI without the gazetteer backend. `core` is the one package every reader already depends on, and
16
+ * `core/kysley/driver.ts` already makes the identical assertion for the Kysely path.
17
+ *
18
+ * The type-only import keeps `node:sqlite` out of the emitted graph, so this module stays safe to reach from the
19
+ * browser tier and the docs bundler (see `sealed-db.ts` for the value-side counterpart).
20
+ */
21
+
22
+ import type { SQLInputValue, StatementSync } from "node:sqlite"
23
+
24
+ /**
25
+ * Execute a prepared statement whose selected columns are described by `Row`.
26
+ *
27
+ * Callers own the correspondence: `Row` must match the statement's PROJECTION, not the table. A column added to the
28
+ * table without being selected does not belong in `Row`, and a `Row` field the `SELECT` omits reads back `undefined` at
29
+ * runtime while the type promises otherwise.
30
+ */
31
+ export function allRows<Row>(statement: StatementSync, ...parameters: SQLInputValue[]): Row[] {
32
+ return statement.all(...parameters) as Row[]
33
+ }
34
+
35
+ /**
36
+ * Single-row counterpart to {@link allRows}. `undefined` when the statement matched nothing.
37
+ */
38
+ export function getRow<Row>(statement: StatementSync, ...parameters: SQLInputValue[]): Row | undefined {
39
+ return statement.get(...parameters) as Row | undefined
40
+ }