@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
package/env/index.ts
CHANGED
|
@@ -4,6 +4,8 @@ import { loadEnvFile } from "./load.ts"
|
|
|
4
4
|
import { cwdPathBuilder } from "./paths.ts"
|
|
5
5
|
import { PrivateEnvSchema, PublicEnvSchema } from "./schema.ts"
|
|
6
6
|
|
|
7
|
+
export { defaultMailwomanPaths } from "./paths.ts"
|
|
8
|
+
|
|
7
9
|
// The optional `.env` is read once (it can't change mid-process); the real environment is layered on top
|
|
8
10
|
// LIVE. `process.env` can change during a process — a test stubbing a var, a late setter — and `$public` /
|
|
9
11
|
// `$private` must reflect it, exactly like `process.env` itself. So each key is a getter that re-parses the
|
|
@@ -17,7 +19,7 @@ function liveEnv<Shape extends z.ZodRawShape>(schema: z.ZodObject<Shape>): z.inf
|
|
|
17
19
|
for (const key of Object.keys(schema.shape)) {
|
|
18
20
|
Object.defineProperty(view, key, {
|
|
19
21
|
enumerable: true,
|
|
20
|
-
// oxlint-disable-next-line sister-software/no-process-globals
|
|
22
|
+
// oxlint-disable-next-line sister-software/no-process-globals -- this module is the typed process.env boundary
|
|
21
23
|
get: () => schema.parse({ ...dotEnv, ...process.env })[key as keyof z.infer<z.ZodObject<Shape>>],
|
|
22
24
|
})
|
|
23
25
|
}
|
package/env/paths.ts
CHANGED
|
@@ -1,40 +1,28 @@
|
|
|
1
|
-
import { existsSync } from "node:fs"
|
|
2
|
-
import { homedir } from "node:os"
|
|
3
|
-
import { dirname, resolve } from "node:path"
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Resolve a path relative to the directory Claude Code is running in (cwd).
|
|
7
|
-
*
|
|
8
|
-
* @param paths Path segments to join onto cwd.
|
|
9
|
-
*/
|
|
10
|
-
export function cwdPathBuilder(...paths: string[]): string {
|
|
11
|
-
return resolve(process.cwd(), ...paths)
|
|
12
|
-
}
|
|
13
|
-
|
|
14
1
|
/**
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* @
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
18
5
|
*/
|
|
19
|
-
export function cwdEnvPaths(): string[] {
|
|
20
|
-
const found: string[] = []
|
|
21
|
-
let dir = process.cwd()
|
|
22
|
-
const home = homedir()
|
|
23
6
|
|
|
24
|
-
|
|
25
|
-
|
|
7
|
+
import envPaths from "env-paths"
|
|
8
|
+
import { resolvePath } from "path-ts"
|
|
26
9
|
|
|
27
|
-
|
|
28
|
-
found.push(candidate)
|
|
29
|
-
}
|
|
10
|
+
const platformPaths = envPaths("mailwoman", { suffix: "" })
|
|
30
11
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
12
|
+
/**
|
|
13
|
+
* Platform-native filesystem defaults used by the typed environment schema.
|
|
14
|
+
*/
|
|
15
|
+
export const defaultMailwomanPaths = {
|
|
16
|
+
data: resolvePath(platformPaths.data),
|
|
17
|
+
config: resolvePath(platformPaths.config),
|
|
18
|
+
cache: resolvePath(platformPaths.cache),
|
|
19
|
+
log: resolvePath(platformPaths.log),
|
|
20
|
+
temp: resolvePath(platformPaths.temp),
|
|
21
|
+
} as const
|
|
37
22
|
|
|
38
|
-
|
|
39
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Resolve a path relative to the current working directory.
|
|
25
|
+
*/
|
|
26
|
+
export function cwdPathBuilder(...paths: string[]): string {
|
|
27
|
+
return resolvePath(process.cwd(), ...paths)
|
|
40
28
|
}
|
package/env/schema.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { z } from "zod"
|
|
2
2
|
|
|
3
|
+
import { defaultMailwomanPaths } from "./paths.ts"
|
|
4
|
+
|
|
3
5
|
/**
|
|
4
6
|
* Wrap a coerced schema so a BLANK value means the same as an absent one.
|
|
5
7
|
*
|
|
@@ -23,6 +25,10 @@ export const PublicEnvSchema = z.object({
|
|
|
23
25
|
// `.catch` (not `.default`) so an unknown value never throws — vitest sets NODE_ENV=test, CI may set others.
|
|
24
26
|
NODE_ENV: z.enum(["development", "production", "test"]).catch("development"),
|
|
25
27
|
CI: z.coerce.boolean().default(false),
|
|
28
|
+
/**
|
|
29
|
+
* Operator locale override used when a request supplies no locale. Safe to expose in diagnostics.
|
|
30
|
+
*/
|
|
31
|
+
MW_LOCALE: z.string().min(1).optional(),
|
|
26
32
|
|
|
27
33
|
// Gazetteer / resolver database paths. CLI flags (`--resolve-db`, …) override these at the call site.
|
|
28
34
|
MAILWOMAN_WOF_DB: z.string().optional(),
|
|
@@ -33,6 +39,8 @@ export const PublicEnvSchema = z.object({
|
|
|
33
39
|
MAILWOMAN_FST_BIN: z.string().optional(),
|
|
34
40
|
MAILWOMAN_MODEL_CARD: z.string().optional(),
|
|
35
41
|
MAILWOMAN_COARSE_PLACER_DIR: z.string().optional(),
|
|
42
|
+
// PMTiles archive for the geocode --debug map pane; --tiles outranks it at the call site.
|
|
43
|
+
MAILWOMAN_TILES: z.string().optional(),
|
|
36
44
|
|
|
37
45
|
// ONNX intra-op thread cap. Deployment-shaped rather than code-shaped: the right value depends on how many
|
|
38
46
|
// mailwoman processes share the host, which the library cannot know. See DEFAULT_INTRA_OP_THREADS.
|
|
@@ -50,8 +58,12 @@ export const PublicEnvSchema = z.object({
|
|
|
50
58
|
// Receipts: `docs/engineering/reference/performance.mdx`.
|
|
51
59
|
MAILWOMAN_BATCH_MAX: blankAsAbsent(z.coerce.number().int().positive().default(1000)),
|
|
52
60
|
|
|
53
|
-
//
|
|
54
|
-
MAILWOMAN_DATA_ROOT: z.string().
|
|
61
|
+
// Platform-native application directories. Environment values override these defaults.
|
|
62
|
+
MAILWOMAN_DATA_ROOT: z.string().default(defaultMailwomanPaths.data),
|
|
63
|
+
MAILWOMAN_CONFIG_ROOT: z.string().default(defaultMailwomanPaths.config),
|
|
64
|
+
MAILWOMAN_CACHE_ROOT: z.string().default(defaultMailwomanPaths.cache),
|
|
65
|
+
MAILWOMAN_LOG_ROOT: z.string().default(defaultMailwomanPaths.log),
|
|
66
|
+
MAILWOMAN_TEMP_ROOT: z.string().default(defaultMailwomanPaths.temp),
|
|
55
67
|
|
|
56
68
|
// Corpus source-fetch tools (`corpus/src/tools/fetch/*` — env knobs are now command flags; these remain for compat). Callers do their own numeric/boolean parsing on these,
|
|
57
69
|
// so they stay raw strings — the schema only gates which keys surface, not how they're coerced.
|
|
@@ -84,13 +96,22 @@ export const PublicEnvSchema = z.object({
|
|
|
84
96
|
|
|
85
97
|
// Release-it publish flow (`scripts/publish-workspace.ts`). The OTP is a secret — see `$private`.
|
|
86
98
|
MAILWOMAN_SKIP_WEIGHTS: z.string().optional(),
|
|
99
|
+
/**
|
|
100
|
+
* Set to `0` to publish WITHOUT a sigstore provenance attestation. Provenance is otherwise on by default under GitHub
|
|
101
|
+
* Actions — this exists so a release blocked by a sigstore or registry outage can still ship.
|
|
102
|
+
*/
|
|
87
103
|
MAILWOMAN_NPM_PROVENANCE: z.string().optional(),
|
|
104
|
+
/**
|
|
105
|
+
* Set by GitHub Actions itself. npm can only mint a provenance attestation from a CI provider it supports, so this is
|
|
106
|
+
* the predicate for `--provenance` rather than the generic {@link CI} flag.
|
|
107
|
+
*/
|
|
108
|
+
GITHUB_ACTIONS: z.coerce.boolean().default(false),
|
|
88
109
|
RELEASE_IT_WORKSPACES_PATH_TO_WORKSPACE: z.string().optional(),
|
|
89
110
|
RELEASE_IT_WORKSPACES_TAG: z.string().optional(),
|
|
90
111
|
RELEASE_IT_WORKSPACES_ACCESS: z.string().optional(),
|
|
91
112
|
RELEASE_IT_WORKSPACES_DRY_RUN: z.string().optional(),
|
|
92
113
|
|
|
93
|
-
// Demo
|
|
114
|
+
// Demo artifact staging (`docs/plugins/demo-assets/artifacts.ts`) + docs driver.
|
|
94
115
|
PLAYPEN_WOF_ADMIN_DB: z.string().optional(),
|
|
95
116
|
PLAYPEN_WOF_POSTCODE_DB: z.string().optional(),
|
|
96
117
|
SLIM_COUNTRIES: z.string().optional(),
|
|
@@ -141,6 +162,8 @@ export const PublicEnvSchema = z.object({
|
|
|
141
162
|
MW_DUMP_REGRESSIONS: z.string().optional(),
|
|
142
163
|
PROBE_N: z.string().optional(),
|
|
143
164
|
DEBUG: z.string().optional(),
|
|
165
|
+
// The informal-standard color kill switch (no-color.org). chalk/Ink honor it on their own; declared here because the debug view's map pane emits raw SGR and must consult it itself — the schema strips unlisted vars.
|
|
166
|
+
NO_COLOR: z.string().optional(),
|
|
144
167
|
})
|
|
145
168
|
|
|
146
169
|
/**
|
|
@@ -181,6 +204,15 @@ export const PrivateEnvSchema = z.object({
|
|
|
181
204
|
|
|
182
205
|
// SEC EDGAR fair-access User-Agent (`filer/sdk/sec-client.ts`) — "Company Name AdminContact@domain.com".
|
|
183
206
|
SEC_EDGAR_USER_AGENT: z.string().optional(),
|
|
207
|
+
/**
|
|
208
|
+
* Descriptive User-Agent for the FCC CORES lookup (`filer/sdk/cores-client.ts`). Optional in a way
|
|
209
|
+
* `SEC_EDGAR_USER_AGENT` is not: SEC 403s a request that fails to identify itself, FCC does not. Falls back to
|
|
210
|
+
* `SEC_EDGAR_USER_AGENT` — the same contact address — when unset.
|
|
211
|
+
*/
|
|
212
|
+
FCC_CORES_USER_AGENT: z.string().optional(),
|
|
213
|
+
|
|
214
|
+
USAC_API_KEY_ID: z.string().optional(),
|
|
215
|
+
USAC_API_SECRET_KEY: z.string().optional(),
|
|
184
216
|
|
|
185
217
|
// Google Maps Platform key for the reference-geocoder ORACLE (`geocode-oracle/sdk/google-client.ts`).
|
|
186
218
|
// Verification tooling only — nothing on the parse path reads this, and `@mailwoman/geocode-oracle` is
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software.
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A kibibyte. Named so a `< 1024` guard reads as a threshold rather than a magic number — several fetchers use it to
|
|
9
|
+
* reject a response too small to be the archive they asked for.
|
|
10
|
+
*/
|
|
11
|
+
export const BYTES_PER_KIB = 1024
|
|
12
|
+
|
|
13
|
+
export interface ByteFormatterOptions {
|
|
14
|
+
/**
|
|
15
|
+
* Prefix an explicit `+` on a positive value. For a DELTA, where the sign is the information. A negative always
|
|
16
|
+
* carries its own sign.
|
|
17
|
+
*/
|
|
18
|
+
signed?: boolean
|
|
19
|
+
/**
|
|
20
|
+
* Override the formatter's locale for this call.
|
|
21
|
+
*/
|
|
22
|
+
locales?: Intl.LocalesArgument
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Byte counts as a human reads them, in whichever of the two bases the number was actually measured in.
|
|
27
|
+
*
|
|
28
|
+
* Both bases, spelled correctly. A formatter that divides by 1024 and prints `KB` is off by 2.4% at KB and 10% by TB,
|
|
29
|
+
* and the label is the only thing telling a reader which it did — so the choice is named at the call site:
|
|
30
|
+
*
|
|
31
|
+
* - {@linkcode ByteFormatter.formatIEC} for anything a MACHINE measured — heap, file size on disk, buffer length.
|
|
32
|
+
* - {@linkcode ByteFormatter.formatSI} for a size a VENDOR reports. Disk capacity, download sizes and GitHub's own API
|
|
33
|
+
* are quoted in powers of ten; rendering GitHub's `41.3 GB` as `38.5 GiB` is correct arithmetic and the wrong
|
|
34
|
+
* answer.
|
|
35
|
+
*
|
|
36
|
+
* Rendering goes through `Intl.NumberFormat`, so the unit and the decimal separator follow the locale. Pass an explicit
|
|
37
|
+
* locale when a caller needs a stable string — a test asserting an exact rendering, not a line printed for a human.
|
|
38
|
+
*/
|
|
39
|
+
export class ByteFormatter {
|
|
40
|
+
public static SI_UNITS = ["byte", "kilobyte", "megabyte", "gigabyte", "terabyte"] as const
|
|
41
|
+
public static IEC_UNITS = ["B", "KiB", "MiB", "GiB", "TiB"] as const
|
|
42
|
+
|
|
43
|
+
public static shared = new ByteFormatter()
|
|
44
|
+
|
|
45
|
+
public static formatSI(bytes: number, options?: ByteFormatterOptions): string {
|
|
46
|
+
return ByteFormatter.shared.formatSI(bytes, options)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
public static formatIEC(bytes: number, options?: ByteFormatterOptions): string {
|
|
50
|
+
return ByteFormatter.shared.formatIEC(bytes, options)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
protected locales?: Intl.LocalesArgument
|
|
54
|
+
|
|
55
|
+
constructor(locales?: Intl.LocalesArgument) {
|
|
56
|
+
this.locales = locales
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Formats a file size in bytes into a human-readable string with appropriate SI units (B, kB, MB, GB, TB).
|
|
61
|
+
*
|
|
62
|
+
* @param bytes The file size in bytes.
|
|
63
|
+
*/
|
|
64
|
+
public formatSI(bytes: number, options?: ByteFormatterOptions): string {
|
|
65
|
+
const units = ByteFormatter.SI_UNITS
|
|
66
|
+
|
|
67
|
+
let value = bytes
|
|
68
|
+
let unit = 0
|
|
69
|
+
|
|
70
|
+
while (Math.abs(value) >= 1000 && unit < units.length - 1) {
|
|
71
|
+
value /= 1000
|
|
72
|
+
|
|
73
|
+
unit++
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return new Intl.NumberFormat(options?.locales ?? this.locales, {
|
|
77
|
+
style: "unit",
|
|
78
|
+
unit: units[unit],
|
|
79
|
+
maximumFractionDigits: 1,
|
|
80
|
+
signDisplay: options?.signed ? "exceptZero" : "auto",
|
|
81
|
+
}).format(value)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Formats a file size in bytes into a human-readable string with appropriate IEC units (B, KiB, MiB, GiB, TiB).
|
|
86
|
+
*
|
|
87
|
+
* @param bytes The file size in bytes.
|
|
88
|
+
*/
|
|
89
|
+
public formatIEC(bytes: number, options?: ByteFormatterOptions): string {
|
|
90
|
+
let value = bytes
|
|
91
|
+
let unit = 0
|
|
92
|
+
|
|
93
|
+
// oxlint-disable-next-line sister-software/no-unnamed-threshold -- Well known.
|
|
94
|
+
while (Math.abs(value) >= 1024 && unit < ByteFormatter.IEC_UNITS.length - 1) {
|
|
95
|
+
value /= 1024
|
|
96
|
+
|
|
97
|
+
unit++
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const formatted = new Intl.NumberFormat(options?.locales ?? this.locales, {
|
|
101
|
+
maximumFractionDigits: 1,
|
|
102
|
+
signDisplay: options?.signed ? "exceptZero" : "auto",
|
|
103
|
+
}).format(value)
|
|
104
|
+
|
|
105
|
+
return `${formatted} ${ByteFormatter.IEC_UNITS[unit]}`
|
|
106
|
+
}
|
|
107
|
+
}
|
package/fs/zip.ts
ADDED
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software.
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
* @file Zip readers, in two flavours — buffer-in for archives already in memory, path-in for archives on disk.
|
|
6
|
+
*
|
|
7
|
+
* {@link extractZip} and {@link extractSingleFileZip} take the whole archive as a `Buffer`, which is the right shape
|
|
8
|
+
* when a client has just downloaded one (`bdc/sdk/download.ts`) and the wrong shape for anything sizable: adm-zip
|
|
9
|
+
* holds the archive AND the decompressed member resident at once. The national address dumps under
|
|
10
|
+
* `$MAILWOMAN_DATA_ROOT` are 0.5–2.9 GB compressed and up to 9 GB unpacked, so the path-in readers below stream —
|
|
11
|
+
* yauzl seeks the central directory over a file handle and inflates one member on demand, at constant memory
|
|
12
|
+
* regardless of archive size.
|
|
13
|
+
*
|
|
14
|
+
* The path-in readers also handle ZIP64, which the dumps need: a member above 4 GB parks `0xFFFFFFFF` in the 32-bit
|
|
15
|
+
* size and offset slots and carries the real values in the entry's extra field.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { createWriteStream } from "node:fs"
|
|
19
|
+
import { mkdir } from "node:fs/promises"
|
|
20
|
+
import { basename, dirname, join } from "node:path"
|
|
21
|
+
import { pipeline } from "node:stream/promises"
|
|
22
|
+
import { crc32 } from "node:zlib"
|
|
23
|
+
|
|
24
|
+
import ADMZip from "adm-zip"
|
|
25
|
+
import type { PathBuilderLike } from "path-ts"
|
|
26
|
+
import { open as openArchive } from "yauzl-promise"
|
|
27
|
+
|
|
28
|
+
export type ZipEntryContentPair = [entry: ADMZip.IZipEntry, content: Buffer]
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Extract the contents of a zip file.
|
|
32
|
+
*
|
|
33
|
+
* @category Files
|
|
34
|
+
* @internal
|
|
35
|
+
*/
|
|
36
|
+
export function extractZip(data: ArrayBuffer | Buffer): Map<ADMZip.IZipEntry, Buffer> {
|
|
37
|
+
const normalizedData = data instanceof ArrayBuffer ? Buffer.from(data) : data
|
|
38
|
+
const zip = new ADMZip(normalizedData)
|
|
39
|
+
|
|
40
|
+
const pairs = zip
|
|
41
|
+
.getEntries()
|
|
42
|
+
.map((entry) => [entry, zip.readFile(entry)])
|
|
43
|
+
.filter((pair): pair is ZipEntryContentPair => pair[1] !== null)
|
|
44
|
+
|
|
45
|
+
if (!pairs.length) {
|
|
46
|
+
throw new Error("No entry pairs found in zip file.")
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return new Map<ADMZip.IZipEntry, Buffer>(pairs)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Extract the contents of a zip file and return the first entry.
|
|
54
|
+
*/
|
|
55
|
+
export function extractSingleFileZip(data: ArrayBuffer | Buffer): Promise<Buffer> {
|
|
56
|
+
const normalizedData = data instanceof ArrayBuffer ? Buffer.from(data) : data
|
|
57
|
+
const zip = new ADMZip(normalizedData)
|
|
58
|
+
|
|
59
|
+
const [entry] = zip.getEntries()
|
|
60
|
+
|
|
61
|
+
// We use the async version of getData to avoid blocking the event loop.
|
|
62
|
+
return new Promise<Buffer>((resolve, reject) =>
|
|
63
|
+
// oxlint-disable-next-line no-promise-executor-return -- return the callback registration from this expression-bodied executor
|
|
64
|
+
entry!.getDataAsync((extractedData, error) => {
|
|
65
|
+
if (error) {
|
|
66
|
+
reject(error)
|
|
67
|
+
} else {
|
|
68
|
+
resolve(extractedData)
|
|
69
|
+
}
|
|
70
|
+
})
|
|
71
|
+
)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Names a member of an archive, either exactly or by pattern.
|
|
76
|
+
*
|
|
77
|
+
* A pattern matches the FIRST entry whose full archive-internal path tests true, in central-directory order.
|
|
78
|
+
*/
|
|
79
|
+
export type ZipEntrySelector = string | RegExp
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* One archive member, as reported by the central directory.
|
|
83
|
+
*
|
|
84
|
+
* @category Files
|
|
85
|
+
*/
|
|
86
|
+
export interface ZipEntryInfo {
|
|
87
|
+
/**
|
|
88
|
+
* The archive-internal path, e.g. `it/countrywide.csv`. Directory entries keep their trailing slash.
|
|
89
|
+
*/
|
|
90
|
+
name: string
|
|
91
|
+
compressedSize: number
|
|
92
|
+
uncompressedSize: number
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function selectorMatches(selector: ZipEntrySelector, name: string): boolean {
|
|
96
|
+
return typeof selector === "string" ? name === selector : selector.test(name)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* List an archive's members without decompressing any of them.
|
|
101
|
+
*
|
|
102
|
+
* @category Files
|
|
103
|
+
*/
|
|
104
|
+
export async function listZipEntries(archivePath: PathBuilderLike): Promise<ZipEntryInfo[]> {
|
|
105
|
+
const archive = await openArchive(String(archivePath))
|
|
106
|
+
const entries: ZipEntryInfo[] = []
|
|
107
|
+
|
|
108
|
+
try {
|
|
109
|
+
for await (const entry of archive) {
|
|
110
|
+
entries.push({
|
|
111
|
+
name: entry.filename,
|
|
112
|
+
compressedSize: entry.compressedSize,
|
|
113
|
+
uncompressedSize: entry.uncompressedSize,
|
|
114
|
+
})
|
|
115
|
+
}
|
|
116
|
+
} finally {
|
|
117
|
+
await archive.close()
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return entries
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Stream one member's decompressed bytes out of an archive on disk.
|
|
125
|
+
*
|
|
126
|
+
* Nothing beyond the central directory and the inflate window is held in memory, so this is bounded by the consumer
|
|
127
|
+
* rather than by the member's size. A consumer that stops early — a `take`, a `break` — destroys the member stream and
|
|
128
|
+
* closes the archive on the way out.
|
|
129
|
+
*
|
|
130
|
+
* @category Files
|
|
131
|
+
* @throws If no member matches `selector`.
|
|
132
|
+
*/
|
|
133
|
+
export async function* readZipEntry(
|
|
134
|
+
archivePath: PathBuilderLike,
|
|
135
|
+
selector: ZipEntrySelector
|
|
136
|
+
): AsyncGenerator<Uint8Array> {
|
|
137
|
+
const archive = await openArchive(String(archivePath))
|
|
138
|
+
|
|
139
|
+
try {
|
|
140
|
+
for await (const entry of archive) {
|
|
141
|
+
if (!selectorMatches(selector, entry.filename)) continue
|
|
142
|
+
|
|
143
|
+
const contents = await entry.openReadStream()
|
|
144
|
+
|
|
145
|
+
try {
|
|
146
|
+
yield* contents
|
|
147
|
+
} finally {
|
|
148
|
+
contents.destroy()
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
throw new Error(`No entry matching ${selector} in ${archivePath}`)
|
|
155
|
+
} finally {
|
|
156
|
+
await archive.close()
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Write one member's decompressed bytes to `destinationPath`.
|
|
162
|
+
*
|
|
163
|
+
* @category Files
|
|
164
|
+
*
|
|
165
|
+
* @returns The number of bytes written, as the central directory reports them.
|
|
166
|
+
* @throws If no member matches `selector`.
|
|
167
|
+
*/
|
|
168
|
+
export async function extractZipEntry(
|
|
169
|
+
archivePath: PathBuilderLike,
|
|
170
|
+
selector: ZipEntrySelector,
|
|
171
|
+
destinationPath: PathBuilderLike
|
|
172
|
+
): Promise<number> {
|
|
173
|
+
const archive = await openArchive(String(archivePath))
|
|
174
|
+
|
|
175
|
+
try {
|
|
176
|
+
for await (const entry of archive) {
|
|
177
|
+
if (!selectorMatches(selector, entry.filename)) continue
|
|
178
|
+
|
|
179
|
+
await pipeline(await entry.openReadStream(), createWriteStream(String(destinationPath)))
|
|
180
|
+
|
|
181
|
+
return entry.uncompressedSize
|
|
182
|
+
}
|
|
183
|
+
} finally {
|
|
184
|
+
await archive.close()
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
throw new Error(`No entry matching ${selector} in ${archivePath}`)
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export interface ExtractZipEntriesOptions {
|
|
191
|
+
/**
|
|
192
|
+
* Which members to write. Omit for every member.
|
|
193
|
+
*/
|
|
194
|
+
selector?: ZipEntrySelector
|
|
195
|
+
/**
|
|
196
|
+
* Write each member under its basename rather than its archive-internal path, flattening the tree — `unzip -j`.
|
|
197
|
+
*
|
|
198
|
+
* The shapefile archives this exists for carry their siblings in one directory, and the readers downstream expect
|
|
199
|
+
* them flat.
|
|
200
|
+
*/
|
|
201
|
+
flatten?: boolean
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Extract members of an archive into `destinationDirectory`.
|
|
206
|
+
*
|
|
207
|
+
* Directory entries are skipped; a nested path is created as needed unless `flatten` is set. Members stream one at a
|
|
208
|
+
* time, so this is bounded by the largest member rather than by the archive.
|
|
209
|
+
*
|
|
210
|
+
* @category Files
|
|
211
|
+
*
|
|
212
|
+
* @returns The archive-internal names of everything written, in central-directory order.
|
|
213
|
+
*/
|
|
214
|
+
export async function extractZipEntries(
|
|
215
|
+
archivePath: PathBuilderLike,
|
|
216
|
+
destinationDirectory: PathBuilderLike,
|
|
217
|
+
{ selector, flatten = false }: ExtractZipEntriesOptions = {}
|
|
218
|
+
): Promise<string[]> {
|
|
219
|
+
const archive = await openArchive(String(archivePath))
|
|
220
|
+
const written: string[] = []
|
|
221
|
+
|
|
222
|
+
try {
|
|
223
|
+
for await (const entry of archive) {
|
|
224
|
+
if (entry.filename.endsWith("/")) continue
|
|
225
|
+
|
|
226
|
+
if (selector && !selectorMatches(selector, entry.filename)) continue
|
|
227
|
+
|
|
228
|
+
const relative = flatten ? basename(entry.filename) : entry.filename
|
|
229
|
+
const destination = join(String(destinationDirectory), relative)
|
|
230
|
+
|
|
231
|
+
if (!flatten) {
|
|
232
|
+
await mkdir(dirname(destination), { recursive: true })
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
await pipeline(await entry.openReadStream(), createWriteStream(destination))
|
|
236
|
+
|
|
237
|
+
written.push(entry.filename)
|
|
238
|
+
}
|
|
239
|
+
} finally {
|
|
240
|
+
await archive.close()
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
return written
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Verify every member's CRC-32 against the value its central-directory header claims — what `unzip -t` is for.
|
|
248
|
+
*
|
|
249
|
+
* This is a corruption check on a download, so it decompresses everything and keeps nothing; the archive is read one
|
|
250
|
+
* member at a time and the checksum is folded chunk by chunk, so memory is bounded by the inflate window.
|
|
251
|
+
*
|
|
252
|
+
* The CRC is computed here rather than delegated to yauzl's `validateCrc32`, which asserts `Cannot validate CRC32 for
|
|
253
|
+
* uncompressed data` on a STORED member — and a corrupt stored member is precisely what this is meant to catch. Folding
|
|
254
|
+
* it locally covers both storage methods with one path.
|
|
255
|
+
*
|
|
256
|
+
* @category Files
|
|
257
|
+
*
|
|
258
|
+
* @returns The number of members checked. @throws If the archive is unreadable, or any member's checksum or length
|
|
259
|
+
* disagrees with its header.
|
|
260
|
+
*/
|
|
261
|
+
export async function verifyZipIntegrity(archivePath: PathBuilderLike): Promise<number> {
|
|
262
|
+
const archive = await openArchive(String(archivePath))
|
|
263
|
+
let checked = 0
|
|
264
|
+
|
|
265
|
+
try {
|
|
266
|
+
for await (const entry of archive) {
|
|
267
|
+
if (entry.filename.endsWith("/")) continue
|
|
268
|
+
|
|
269
|
+
const contents = await entry.openReadStream({ validateCrc32: false })
|
|
270
|
+
let checksum = 0
|
|
271
|
+
let length = 0
|
|
272
|
+
|
|
273
|
+
for await (const chunk of contents) {
|
|
274
|
+
checksum = crc32(chunk as Uint8Array, checksum)
|
|
275
|
+
length += (chunk as Uint8Array).length
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
if (checksum !== entry.crc32) {
|
|
279
|
+
throw new Error(
|
|
280
|
+
`CRC mismatch in ${archivePath}: ${entry.filename} is 0x${checksum.toString(16)}, header claims 0x${entry.crc32.toString(16)}`
|
|
281
|
+
)
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
if (length !== entry.uncompressedSize) {
|
|
285
|
+
throw new Error(
|
|
286
|
+
`Length mismatch in ${archivePath}: ${entry.filename} is ${length} bytes, header claims ${entry.uncompressedSize}`
|
|
287
|
+
)
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
checked++
|
|
291
|
+
}
|
|
292
|
+
} finally {
|
|
293
|
+
await archive.close()
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
return checked
|
|
297
|
+
}
|