@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.
- package/README.md +1 -1
- package/api/responses.ts +12 -0
- package/coarse-placer/featurize.ts +0 -2
- package/coarse-placer/tools/build-dataset.ts +2 -2
- package/coarse-placer/tools/build-outlier-exposure.ts +2 -2
- package/coarse-placer/tools/build-outlier-latin.ts +14 -8
- package/coarse-placer/tools/build-outlier-oa.ts +12 -6
- package/coarse-placer/tools/eval-latin-offmap.ts +3 -4
- package/coarse-placer/tools/eval-openset.ts +3 -3
- package/coarse-placer/tools/eval-quant-compare.ts +3 -3
- package/coarse-placer/tools/eval.ts +3 -3
- package/coarse-placer/tools/fnv-hash.ts +1 -6
- package/coarse-placer/tools/index.ts +1 -1
- package/coarse-placer/tools/probe-frontier.ts +3 -4
- package/coarse-placer/tools/quantize.ts +3 -2
- package/coarse-placer/tools/train.ts +2 -2
- package/crypto/node.ts +3 -1
- package/data/internal/dictionaries/languages.csv +184 -184
- package/data/libpostal/README.md +8 -2
- package/db/schema.ts +12 -3
- package/decoder/build-tree.ts +19 -0
- package/decoder/containment.ts +5 -1
- package/decoder/index.ts +1 -0
- package/decoder/parse-diff.ts +347 -0
- package/decoder/proposals-to-tree.ts +1 -1
- package/decoder/serialize-json.ts +51 -7
- package/decoder/serialize-tuples.ts +7 -1
- package/decoder/serialize-xml.ts +1 -1
- package/decoder/tree-shape.ts +144 -0
- package/decoder/types.ts +8 -0
- package/decoder/validate-tree.ts +15 -3
- package/env/index.ts +3 -1
- package/env/paths.ts +21 -33
- package/env/schema.ts +35 -3
- package/fs/utils/formatters.ts +107 -0
- package/fs/utils/index.ts +7 -0
- package/fs/zip.ts +297 -0
- package/layers/manifest.ts +56 -15
- package/layers/schema.ts +54 -2
- package/locale/locale.ts +1 -1
- package/locale/registry.ts +1 -1
- package/objects.ts +20 -8
- package/out/api/responses.d.ts +9 -0
- package/out/api/responses.d.ts.map +1 -1
- package/out/api/responses.js +11 -0
- package/out/api/responses.js.map +1 -1
- package/out/coarse-placer/featurize.d.ts +0 -1
- package/out/coarse-placer/featurize.d.ts.map +1 -1
- package/out/coarse-placer/featurize.js.map +1 -1
- package/out/coarse-placer/tools/build-dataset.js +1 -2
- package/out/coarse-placer/tools/build-dataset.js.map +1 -1
- package/out/coarse-placer/tools/build-outlier-exposure.js +1 -2
- package/out/coarse-placer/tools/build-outlier-exposure.js.map +1 -1
- package/out/coarse-placer/tools/build-outlier-latin.d.ts.map +1 -1
- package/out/coarse-placer/tools/build-outlier-latin.js +12 -8
- package/out/coarse-placer/tools/build-outlier-latin.js.map +1 -1
- package/out/coarse-placer/tools/build-outlier-oa.d.ts.map +1 -1
- package/out/coarse-placer/tools/build-outlier-oa.js +10 -6
- package/out/coarse-placer/tools/build-outlier-oa.js.map +1 -1
- package/out/coarse-placer/tools/eval-latin-offmap.d.ts.map +1 -1
- package/out/coarse-placer/tools/eval-latin-offmap.js +2 -4
- package/out/coarse-placer/tools/eval-latin-offmap.js.map +1 -1
- package/out/coarse-placer/tools/eval-openset.js +2 -3
- package/out/coarse-placer/tools/eval-openset.js.map +1 -1
- package/out/coarse-placer/tools/eval-quant-compare.js +2 -3
- package/out/coarse-placer/tools/eval-quant-compare.js.map +1 -1
- package/out/coarse-placer/tools/eval.js +2 -3
- package/out/coarse-placer/tools/eval.js.map +1 -1
- package/out/coarse-placer/tools/fnv-hash.d.ts +1 -6
- package/out/coarse-placer/tools/fnv-hash.d.ts.map +1 -1
- package/out/coarse-placer/tools/fnv-hash.js +1 -6
- package/out/coarse-placer/tools/fnv-hash.js.map +1 -1
- package/out/coarse-placer/tools/index.d.ts +1 -1
- package/out/coarse-placer/tools/index.js +1 -1
- package/out/coarse-placer/tools/probe-frontier.d.ts.map +1 -1
- package/out/coarse-placer/tools/probe-frontier.js +2 -4
- package/out/coarse-placer/tools/probe-frontier.js.map +1 -1
- package/out/coarse-placer/tools/quantize.d.ts.map +1 -1
- package/out/coarse-placer/tools/quantize.js +2 -2
- package/out/coarse-placer/tools/quantize.js.map +1 -1
- package/out/coarse-placer/tools/train.js +1 -2
- package/out/coarse-placer/tools/train.js.map +1 -1
- package/out/crypto/node.d.ts.map +1 -1
- package/out/crypto/node.js +2 -1
- package/out/crypto/node.js.map +1 -1
- package/out/db/schema.d.ts +12 -3
- package/out/db/schema.d.ts.map +1 -1
- package/out/db/schema.js +6 -0
- package/out/db/schema.js.map +1 -1
- package/out/decoder/build-tree.d.ts.map +1 -1
- package/out/decoder/build-tree.js +17 -0
- package/out/decoder/build-tree.js.map +1 -1
- package/out/decoder/containment.d.ts.map +1 -1
- package/out/decoder/containment.js +5 -1
- package/out/decoder/containment.js.map +1 -1
- package/out/decoder/index.d.ts +1 -0
- package/out/decoder/index.d.ts.map +1 -1
- package/out/decoder/index.js +1 -0
- package/out/decoder/index.js.map +1 -1
- package/out/decoder/parse-diff.d.ts +125 -0
- package/out/decoder/parse-diff.d.ts.map +1 -0
- package/out/decoder/parse-diff.js +219 -0
- package/out/decoder/parse-diff.js.map +1 -0
- package/out/decoder/proposals-to-tree.js.map +1 -1
- package/out/decoder/serialize-json.d.ts +29 -0
- package/out/decoder/serialize-json.d.ts.map +1 -1
- package/out/decoder/serialize-json.js +20 -4
- package/out/decoder/serialize-json.js.map +1 -1
- package/out/decoder/serialize-tuples.d.ts +8 -1
- package/out/decoder/serialize-tuples.d.ts.map +1 -1
- package/out/decoder/serialize-tuples.js +7 -1
- package/out/decoder/serialize-tuples.js.map +1 -1
- package/out/decoder/serialize-xml.js +1 -1
- package/out/decoder/serialize-xml.js.map +1 -1
- package/out/decoder/tree-shape.d.ts +84 -0
- package/out/decoder/tree-shape.d.ts.map +1 -0
- package/out/decoder/tree-shape.js +98 -0
- package/out/decoder/tree-shape.js.map +1 -0
- package/out/decoder/types.d.ts +11 -0
- package/out/decoder/types.d.ts.map +1 -1
- package/out/decoder/validate-tree.d.ts +8 -0
- package/out/decoder/validate-tree.d.ts.map +1 -1
- package/out/decoder/validate-tree.js +4 -3
- package/out/decoder/validate-tree.js.map +1 -1
- package/out/env/index.d.ts +13 -1
- package/out/env/index.d.ts.map +1 -1
- package/out/env/index.js +2 -1
- package/out/env/index.js.map +1 -1
- package/out/env/paths.d.ts +15 -8
- package/out/env/paths.d.ts.map +1 -1
- package/out/env/paths.js +19 -29
- package/out/env/paths.js.map +1 -1
- package/out/env/schema.d.ts +12 -1
- package/out/env/schema.d.ts.map +1 -1
- package/out/env/schema.js +33 -3
- package/out/env/schema.js.map +1 -1
- package/out/fs/utils/formatters.d.ts +57 -0
- package/out/fs/utils/formatters.d.ts.map +1 -0
- package/out/fs/utils/formatters.js +79 -0
- package/out/fs/utils/formatters.js.map +1 -0
- package/out/fs/utils/index.d.ts +7 -0
- package/out/fs/utils/index.d.ts.map +1 -0
- package/out/fs/utils/index.js +7 -0
- package/out/fs/utils/index.js.map +1 -0
- package/out/fs/zip.d.ts +116 -0
- package/out/fs/zip.d.ts.map +1 -0
- package/out/fs/zip.js +216 -0
- package/out/fs/zip.js.map +1 -0
- package/out/layers/manifest.d.ts +32 -7
- package/out/layers/manifest.d.ts.map +1 -1
- package/out/layers/manifest.js +31 -6
- package/out/layers/manifest.js.map +1 -1
- package/out/layers/schema.d.ts +48 -2
- package/out/layers/schema.d.ts.map +1 -1
- package/out/layers/schema.js +32 -0
- package/out/layers/schema.js.map +1 -1
- package/out/locale/locale.d.ts +1 -1
- package/out/locale/locale.d.ts.map +1 -1
- package/out/locale/registry.js +1 -1
- package/out/locale/registry.js.map +1 -1
- package/out/objects.d.ts +12 -6
- package/out/objects.d.ts.map +1 -1
- package/out/objects.js +4 -1
- package/out/objects.js.map +1 -1
- package/out/pipeline/index.d.ts +3 -7
- package/out/pipeline/index.d.ts.map +1 -1
- package/out/pipeline/index.js +2 -4
- package/out/pipeline/index.js.map +1 -1
- package/out/pipeline/runtime-pipeline.d.ts +51 -9
- package/out/pipeline/runtime-pipeline.d.ts.map +1 -1
- package/out/pipeline/runtime-pipeline.js +46 -133
- package/out/pipeline/runtime-pipeline.js.map +1 -1
- package/out/pipeline/span-proposer.js +1 -1
- package/out/pipeline/span-proposer.js.map +1 -1
- package/out/pipeline/types.d.ts +137 -16
- package/out/pipeline/types.d.ts.map +1 -1
- package/out/pipeline/types.js +30 -0
- package/out/pipeline/types.js.map +1 -1
- package/out/policy/defaults.d.ts +1 -1
- package/out/policy/defaults.d.ts.map +1 -1
- package/out/policy/defaults.js +1 -1
- package/out/policy/defaults.js.map +1 -1
- package/out/policy/policy.d.ts +1 -1
- package/out/policy/policy.d.ts.map +1 -1
- package/out/policy/registry.d.ts +1 -1
- package/out/policy/registry.d.ts.map +1 -1
- package/out/resolver/coverage-facts.d.ts +89 -0
- package/out/resolver/coverage-facts.d.ts.map +1 -0
- package/out/resolver/coverage-facts.js +22 -0
- package/out/resolver/coverage-facts.js.map +1 -0
- package/out/resolver/index.d.ts +4 -1
- package/out/resolver/index.d.ts.map +1 -1
- package/out/resolver/index.js +2 -0
- package/out/resolver/index.js.map +1 -1
- package/out/resolver/lookup-types.d.ts +178 -0
- package/out/resolver/lookup-types.d.ts.map +1 -0
- package/out/resolver/lookup-types.js +11 -0
- package/out/resolver/lookup-types.js.map +1 -0
- package/out/resolver/placetype-map.d.ts +71 -0
- package/out/resolver/placetype-map.d.ts.map +1 -0
- package/out/resolver/placetype-map.js +98 -0
- package/out/resolver/placetype-map.js.map +1 -0
- package/out/resolver/postcode-format.d.ts +38 -0
- package/out/resolver/postcode-format.d.ts.map +1 -0
- package/out/resolver/postcode-format.js +83 -0
- package/out/resolver/postcode-format.js.map +1 -0
- package/out/resolver/referential.d.ts +73 -0
- package/out/resolver/referential.d.ts.map +1 -0
- package/out/resolver/referential.js +71 -0
- package/out/resolver/referential.js.map +1 -0
- package/out/resolver/types.d.ts +401 -264
- package/out/resolver/types.d.ts.map +1 -1
- package/out/resolver/types.js +4 -97
- package/out/resolver/types.js.map +1 -1
- package/out/resources/git.d.ts +8 -1
- package/out/resources/git.d.ts.map +1 -1
- package/out/resources/git.js +4 -3
- package/out/resources/git.js.map +1 -1
- package/out/resources/languages/types.gen.d.ts +1 -1
- package/out/resources/languages/types.gen.d.ts.map +1 -1
- package/out/resources/languages/types.gen.js +40 -0
- package/out/resources/languages/types.gen.js.map +1 -1
- package/out/resources/libpostal.d.ts +2 -2
- package/out/resources/libpostal.d.ts.map +1 -1
- package/out/resources/libpostal.js +2 -2
- package/out/resources/libpostal.js.map +1 -1
- package/out/resources/whosonfirst/DataSourceCache.d.ts.map +1 -1
- package/out/resources/whosonfirst/DataSourceCache.js.map +1 -1
- package/out/resources/whosonfirst/PlacetypeDataSource.d.ts +2 -2
- package/out/resources/whosonfirst/PlacetypeDataSource.d.ts.map +1 -1
- package/out/resources/whosonfirst/PlacetypeDataSource.js +28 -3
- package/out/resources/whosonfirst/PlacetypeDataSource.js.map +1 -1
- package/out/resources/whosonfirst/loader.d.ts +2 -2
- package/out/resources/whosonfirst/loader.d.ts.map +1 -1
- package/out/resources/whosonfirst/loader.js.map +1 -1
- package/out/resources/whosonfirst/placetypes/Placetype.d.ts.map +1 -1
- package/out/resources/whosonfirst/placetypes/Placetype.js +1 -1
- package/out/resources/whosonfirst/placetypes/Placetype.js.map +1 -1
- package/out/resources/whosonfirst/placetypes/admin.d.ts +9 -1
- package/out/resources/whosonfirst/placetypes/admin.d.ts.map +1 -1
- package/out/resources/whosonfirst/placetypes/admin.js +1 -1
- package/out/resources/whosonfirst/placetypes/admin.js.map +1 -1
- package/out/resources/whosonfirst/placetypes/definition.d.ts.map +1 -1
- package/out/resources/whosonfirst/placetypes/definition.js +1 -1
- package/out/resources/whosonfirst/placetypes/definition.js.map +1 -1
- package/out/resources/whosonfirst/placetypes/index.d.ts +1 -0
- package/out/resources/whosonfirst/placetypes/index.d.ts.map +1 -1
- package/out/resources/whosonfirst/placetypes/index.js +1 -0
- package/out/resources/whosonfirst/placetypes/index.js.map +1 -1
- package/out/resources/whosonfirst/placetypes/specificity.d.ts +65 -0
- package/out/resources/whosonfirst/placetypes/specificity.d.ts.map +1 -0
- package/out/resources/whosonfirst/placetypes/specificity.js +101 -0
- package/out/resources/whosonfirst/placetypes/specificity.js.map +1 -0
- package/out/resources/whosonfirst/sharded-repo.d.ts +28 -0
- package/out/resources/whosonfirst/sharded-repo.d.ts.map +1 -1
- package/out/resources/whosonfirst/sharded-repo.js +46 -2
- package/out/resources/whosonfirst/sharded-repo.js.map +1 -1
- package/out/scripting/arguments.d.ts +27 -0
- package/out/scripting/arguments.d.ts.map +1 -0
- package/out/scripting/arguments.js +32 -0
- package/out/scripting/arguments.js.map +1 -0
- package/out/scripting/command.d.ts +28 -0
- package/out/scripting/command.d.ts.map +1 -0
- package/out/scripting/command.js +47 -0
- package/out/scripting/command.js.map +1 -0
- package/out/scripting/index.js +3 -3
- package/out/scripting/index.js.map +1 -1
- package/out/scripting/utils/index.d.ts +1 -12
- package/out/scripting/utils/index.d.ts.map +1 -1
- package/out/scripting/utils/index.js +4 -21
- package/out/scripting/utils/index.js.map +1 -1
- package/out/tools/download-libpostal-resources.d.ts.map +1 -1
- package/out/tools/download-libpostal-resources.js +4 -7
- package/out/tools/download-libpostal-resources.js.map +1 -1
- package/out/tools/download-ssl-address.d.ts +3 -3
- package/out/tools/download-ssl-address.d.ts.map +1 -1
- package/out/tools/download-ssl-address.js +26 -13
- package/out/tools/download-ssl-address.js.map +1 -1
- package/out/tools/generate-language-types.d.ts +16 -1
- package/out/tools/generate-language-types.d.ts.map +1 -1
- package/out/tools/generate-language-types.js +38 -5
- package/out/tools/generate-language-types.js.map +1 -1
- package/out/tools/index.d.ts +1 -2
- package/out/tools/index.d.ts.map +1 -1
- package/out/tools/index.js +1 -2
- package/out/tools/index.js.map +1 -1
- package/out/utils/data-root.d.ts +27 -7
- package/out/utils/data-root.d.ts.map +1 -1
- package/out/utils/data-root.js +36 -13
- package/out/utils/data-root.js.map +1 -1
- package/out/utils/hash.d.ts +2 -3
- package/out/utils/hash.d.ts.map +1 -1
- package/out/utils/hash.js +3 -3
- package/out/utils/hash.js.map +1 -1
- package/out/utils/index.d.ts +1 -0
- package/out/utils/index.d.ts.map +1 -1
- package/out/utils/index.js +1 -0
- package/out/utils/index.js.map +1 -1
- package/out/utils/jsonl.js +1 -1
- package/out/utils/jsonl.js.map +1 -1
- package/out/utils/repo.d.ts +8 -0
- package/out/utils/repo.d.ts.map +1 -1
- package/out/utils/repo.js +10 -1
- package/out/utils/repo.js.map +1 -1
- package/out/utils/sealed-db.d.ts +11 -0
- package/out/utils/sealed-db.d.ts.map +1 -1
- package/out/utils/sealed-db.js +28 -1
- package/out/utils/sealed-db.js.map +1 -1
- package/out/utils/sqlite-rows.d.ts +34 -0
- package/out/utils/sqlite-rows.d.ts.map +1 -0
- package/out/utils/sqlite-rows.js +37 -0
- package/out/utils/sqlite-rows.js.map +1 -0
- package/out/utils/stats.d.ts +1 -6
- package/out/utils/stats.d.ts.map +1 -1
- package/out/utils/stats.js +1 -6
- package/out/utils/stats.js.map +1 -1
- package/package.json +488 -8
- package/pipeline/index.ts +14 -15
- package/pipeline/runtime-pipeline.ts +48 -184
- package/pipeline/span-proposer.ts +1 -1
- package/pipeline/types.ts +143 -16
- package/policy/defaults.ts +1 -1
- package/policy/policy.ts +1 -1
- package/policy/registry.ts +1 -1
- package/resolver/coverage-facts.ts +102 -0
- package/resolver/index.ts +18 -0
- package/resolver/lookup-types.ts +174 -0
- package/resolver/placetype-map.ts +122 -0
- package/resolver/postcode-format.ts +89 -0
- package/resolver/referential.ts +84 -0
- package/resolver/types.ts +423 -315
- package/resources/git.ts +18 -4
- package/resources/languages/types.gen.ts +60 -0
- package/resources/libpostal.ts +4 -3
- package/resources/whosonfirst/DataSourceCache.ts +2 -1
- package/resources/whosonfirst/PlacetypeDataSource.ts +36 -11
- package/resources/whosonfirst/loader.ts +3 -2
- package/resources/whosonfirst/placetypes/Placetype.ts +2 -1
- package/resources/whosonfirst/placetypes/admin.ts +11 -2
- package/resources/whosonfirst/placetypes/definition.ts +4 -3
- package/resources/whosonfirst/placetypes/index.ts +1 -0
- package/resources/whosonfirst/placetypes/specificity.ts +114 -0
- package/resources/whosonfirst/sharded-repo.ts +55 -2
- package/scripting/arguments.ts +38 -0
- package/scripting/command.ts +55 -0
- package/scripting/index.ts +3 -3
- package/scripting/utils/index.ts +5 -23
- package/tools/download-libpostal-resources.ts +4 -7
- package/tools/download-ssl-address.ts +28 -12
- package/tools/generate-language-types.ts +39 -5
- package/tools/index.ts +1 -2
- package/utils/data-root.ts +40 -14
- package/utils/hash.ts +5 -4
- package/utils/index.ts +1 -0
- package/utils/jsonl.ts +1 -1
- package/utils/repo.ts +12 -1
- package/utils/sealed-db.ts +30 -1
- package/utils/sqlite-rows.ts +40 -0
- package/utils/stats.ts +1 -6
- package/data/libpostal/dictionaries/all/chains.txt +0 -504
- package/kysley/adapter.ts +0 -29
- package/out/kysley/adapter.d.ts +0 -13
- package/out/kysley/adapter.d.ts.map +0 -1
- package/out/kysley/adapter.js +0 -25
- package/out/kysley/adapter.js.map +0 -1
- package/out/pipeline/reconcile-lookups.d.ts +0 -39
- package/out/pipeline/reconcile-lookups.d.ts.map +0 -1
- package/out/pipeline/reconcile-lookups.js +0 -88
- package/out/pipeline/reconcile-lookups.js.map +0 -1
- package/out/pipeline/reconcile.d.ts +0 -153
- package/out/pipeline/reconcile.d.ts.map +0 -1
- package/out/pipeline/reconcile.js +0 -388
- package/out/pipeline/reconcile.js.map +0 -1
- package/out/pipeline/span-logit-aggregation.d.ts +0 -58
- package/out/pipeline/span-logit-aggregation.d.ts.map +0 -1
- package/out/pipeline/span-logit-aggregation.js +0 -117
- package/out/pipeline/span-logit-aggregation.js.map +0 -1
- package/pipeline/reconcile-lookups.ts +0 -111
- package/pipeline/reconcile.ts +0 -583
- 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
16
|
import { resolvePath } from "path-ts"
|
|
17
17
|
|
|
18
|
-
import { tryParsingJSON } from "
|
|
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
|
+
}
|
package/scripting/index.ts
CHANGED
|
@@ -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("
|
|
28
|
-
import("
|
|
29
|
-
import("
|
|
27
|
+
import("#env"),
|
|
28
|
+
import("#logging"),
|
|
29
|
+
import("#scripting/utils"),
|
|
30
30
|
])
|
|
31
31
|
|
|
32
32
|
ConsoleLogger.info(
|
package/scripting/utils/index.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { defaultRegistry } from "async-init"
|
|
2
2
|
|
|
3
|
-
import { ResourceError } from "
|
|
4
|
-
import { ConsoleLogger } from "
|
|
3
|
+
import { ResourceError } from "#errors"
|
|
4
|
+
import { ConsoleLogger } from "#logging"
|
|
5
|
+
|
|
6
|
+
export { cliArguments, passThroughCLIArguments, scriptEntryPath } from "../arguments.ts"
|
|
5
7
|
|
|
6
8
|
/**
|
|
7
9
|
* Logs an error that occurred while running a script.
|
|
@@ -74,32 +76,12 @@ export function runScript(scriptCallback: ScriptCallback): Promise<void> {
|
|
|
74
76
|
.catch(() => postScriptCleanup("SIGTERM", 1))
|
|
75
77
|
}
|
|
76
78
|
|
|
77
|
-
/**
|
|
78
|
-
* The ONE blessed accessor for CLI arguments. Everything outside `core/env` + this module is forbidden from touching
|
|
79
|
-
* `process.argv` directly (enforced by the `sister-software/no-process-globals` oxlint rule) — prefer `node:util`
|
|
80
|
-
* `parseArgs` (which reads this same slice by default) and reach for this only where `parseArgs` cannot express the
|
|
81
|
-
* grammar (e.g. verbatim passthrough of undeclared flags to a child process — see
|
|
82
|
-
* `corpus-python/scripts/train_with_resume.ts`).
|
|
83
|
-
*/
|
|
84
|
-
export function cliArguments(): string[] {
|
|
85
|
-
// oxlint-disable-next-line sister-software/no-process-globals
|
|
86
|
-
return process.argv.slice(2)
|
|
87
|
-
}
|
|
88
|
-
|
|
89
79
|
/**
|
|
90
80
|
* The ONE blessed way to build a child-process environment: the current environment with explicit overrides. Everything
|
|
91
81
|
* outside `core/env` + this module is forbidden from touching `process.env` directly (enforced by
|
|
92
82
|
* `scripts/lint-raw-env-argv.ts`) — read config through `$public`/`$private`.
|
|
93
83
|
*/
|
|
94
84
|
export function childEnv(overrides: Record<string, string | undefined> = {}): NodeJS.ProcessEnv {
|
|
95
|
-
// 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
|
|
96
86
|
return { ...process.env, ...overrides }
|
|
97
87
|
}
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* The path of the executing script (`argv[1]`) — for commands that re-spawn or reference their own CLI entry.
|
|
101
|
-
*/
|
|
102
|
-
export function scriptEntryPath(): string {
|
|
103
|
-
// oxlint-disable-next-line sister-software/no-process-globals
|
|
104
|
-
return process.argv[1]!
|
|
105
|
-
}
|
|
@@ -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 "
|
|
32
|
-
import {
|
|
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
|
-
|
|
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)
|
|
13
|
-
*
|
|
14
|
-
*
|
|
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 "
|
|
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
|
|
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(
|
|
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
|
-
|
|
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
|
-
|
|
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-
|
|
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 {
|
|
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 ??
|
|
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
|
-
|
|
181
|
-
|
|
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
|
|
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"
|
package/utils/data-root.ts
CHANGED
|
@@ -3,12 +3,7 @@
|
|
|
3
3
|
* @license AGPL-3.0
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
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
|
|
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
|
|
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
|
|
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
|
-
|
|
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
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).
|
package/utils/sealed-db.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
+
}
|