@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/out/env/schema.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
import { defaultMailwomanPaths } from "./paths.js";
|
|
2
3
|
/**
|
|
3
4
|
* Wrap a coerced schema so a BLANK value means the same as an absent one.
|
|
4
5
|
*
|
|
@@ -21,6 +22,10 @@ export const PublicEnvSchema = z.object({
|
|
|
21
22
|
// `.catch` (not `.default`) so an unknown value never throws — vitest sets NODE_ENV=test, CI may set others.
|
|
22
23
|
NODE_ENV: z.enum(["development", "production", "test"]).catch("development"),
|
|
23
24
|
CI: z.coerce.boolean().default(false),
|
|
25
|
+
/**
|
|
26
|
+
* Operator locale override used when a request supplies no locale. Safe to expose in diagnostics.
|
|
27
|
+
*/
|
|
28
|
+
MW_LOCALE: z.string().min(1).optional(),
|
|
24
29
|
// Gazetteer / resolver database paths. CLI flags (`--resolve-db`, …) override these at the call site.
|
|
25
30
|
MAILWOMAN_WOF_DB: z.string().optional(),
|
|
26
31
|
MAILWOMAN_WOF_ADMIN_DB: z.string().optional(),
|
|
@@ -30,6 +35,8 @@ export const PublicEnvSchema = z.object({
|
|
|
30
35
|
MAILWOMAN_FST_BIN: z.string().optional(),
|
|
31
36
|
MAILWOMAN_MODEL_CARD: z.string().optional(),
|
|
32
37
|
MAILWOMAN_COARSE_PLACER_DIR: z.string().optional(),
|
|
38
|
+
// PMTiles archive for the geocode --debug map pane; --tiles outranks it at the call site.
|
|
39
|
+
MAILWOMAN_TILES: z.string().optional(),
|
|
33
40
|
// ONNX intra-op thread cap. Deployment-shaped rather than code-shaped: the right value depends on how many
|
|
34
41
|
// mailwoman processes share the host, which the library cannot know. See DEFAULT_INTRA_OP_THREADS.
|
|
35
42
|
//
|
|
@@ -44,8 +51,12 @@ export const PublicEnvSchema = z.object({
|
|
|
44
51
|
// threads (see `mailwoman/geocode-stream.ts`) are the only lever that moves this in Node.
|
|
45
52
|
// Receipts: `docs/engineering/reference/performance.mdx`.
|
|
46
53
|
MAILWOMAN_BATCH_MAX: blankAsAbsent(z.coerce.number().int().positive().default(1000)),
|
|
47
|
-
//
|
|
48
|
-
MAILWOMAN_DATA_ROOT: z.string().
|
|
54
|
+
// Platform-native application directories. Environment values override these defaults.
|
|
55
|
+
MAILWOMAN_DATA_ROOT: z.string().default(defaultMailwomanPaths.data),
|
|
56
|
+
MAILWOMAN_CONFIG_ROOT: z.string().default(defaultMailwomanPaths.config),
|
|
57
|
+
MAILWOMAN_CACHE_ROOT: z.string().default(defaultMailwomanPaths.cache),
|
|
58
|
+
MAILWOMAN_LOG_ROOT: z.string().default(defaultMailwomanPaths.log),
|
|
59
|
+
MAILWOMAN_TEMP_ROOT: z.string().default(defaultMailwomanPaths.temp),
|
|
49
60
|
// 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,
|
|
50
61
|
// so they stay raw strings — the schema only gates which keys surface, not how they're coerced.
|
|
51
62
|
OUT_ROOT: z.string().optional(),
|
|
@@ -74,12 +85,21 @@ export const PublicEnvSchema = z.object({
|
|
|
74
85
|
MAILWOMAN_SKIP_WEIGHTS_COPY: z.string().optional(),
|
|
75
86
|
// Release-it publish flow (`scripts/publish-workspace.ts`). The OTP is a secret — see `$private`.
|
|
76
87
|
MAILWOMAN_SKIP_WEIGHTS: z.string().optional(),
|
|
88
|
+
/**
|
|
89
|
+
* Set to `0` to publish WITHOUT a sigstore provenance attestation. Provenance is otherwise on by default under GitHub
|
|
90
|
+
* Actions — this exists so a release blocked by a sigstore or registry outage can still ship.
|
|
91
|
+
*/
|
|
77
92
|
MAILWOMAN_NPM_PROVENANCE: z.string().optional(),
|
|
93
|
+
/**
|
|
94
|
+
* Set by GitHub Actions itself. npm can only mint a provenance attestation from a CI provider it supports, so this is
|
|
95
|
+
* the predicate for `--provenance` rather than the generic {@link CI} flag.
|
|
96
|
+
*/
|
|
97
|
+
GITHUB_ACTIONS: z.coerce.boolean().default(false),
|
|
78
98
|
RELEASE_IT_WORKSPACES_PATH_TO_WORKSPACE: z.string().optional(),
|
|
79
99
|
RELEASE_IT_WORKSPACES_TAG: z.string().optional(),
|
|
80
100
|
RELEASE_IT_WORKSPACES_ACCESS: z.string().optional(),
|
|
81
101
|
RELEASE_IT_WORKSPACES_DRY_RUN: z.string().optional(),
|
|
82
|
-
// Demo
|
|
102
|
+
// Demo artifact staging (`docs/plugins/demo-assets/artifacts.ts`) + docs driver.
|
|
83
103
|
PLAYPEN_WOF_ADMIN_DB: z.string().optional(),
|
|
84
104
|
PLAYPEN_WOF_POSTCODE_DB: z.string().optional(),
|
|
85
105
|
SLIM_COUNTRIES: z.string().optional(),
|
|
@@ -129,6 +149,8 @@ export const PublicEnvSchema = z.object({
|
|
|
129
149
|
MW_DUMP_REGRESSIONS: z.string().optional(),
|
|
130
150
|
PROBE_N: z.string().optional(),
|
|
131
151
|
DEBUG: z.string().optional(),
|
|
152
|
+
// 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.
|
|
153
|
+
NO_COLOR: z.string().optional(),
|
|
132
154
|
});
|
|
133
155
|
/**
|
|
134
156
|
* Secrets and credentials, exposed via `$private`. Never log these. Add a key here to make it available; anything not
|
|
@@ -160,6 +182,14 @@ export const PrivateEnvSchema = z.object({
|
|
|
160
182
|
FCC_MAP_API_KEY: z.string().optional(),
|
|
161
183
|
// SEC EDGAR fair-access User-Agent (`filer/sdk/sec-client.ts`) — "Company Name AdminContact@domain.com".
|
|
162
184
|
SEC_EDGAR_USER_AGENT: z.string().optional(),
|
|
185
|
+
/**
|
|
186
|
+
* Descriptive User-Agent for the FCC CORES lookup (`filer/sdk/cores-client.ts`). Optional in a way
|
|
187
|
+
* `SEC_EDGAR_USER_AGENT` is not: SEC 403s a request that fails to identify itself, FCC does not. Falls back to
|
|
188
|
+
* `SEC_EDGAR_USER_AGENT` — the same contact address — when unset.
|
|
189
|
+
*/
|
|
190
|
+
FCC_CORES_USER_AGENT: z.string().optional(),
|
|
191
|
+
USAC_API_KEY_ID: z.string().optional(),
|
|
192
|
+
USAC_API_SECRET_KEY: z.string().optional(),
|
|
163
193
|
// Google Maps Platform key for the reference-geocoder ORACLE (`geocode-oracle/sdk/google-client.ts`).
|
|
164
194
|
// Verification tooling only — nothing on the parse path reads this, and `@mailwoman/geocode-oracle` is
|
|
165
195
|
// a private workspace precisely so it cannot become a runtime dependency of a published package.
|
package/out/env/schema.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../env/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB;;;;;;;;;;GAUG;AACH,SAAS,aAAa,CAAsB,KAAQ;IACnD,OAAO,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAA;AAC9D,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC;IACvC,6GAA6G;IAC7G,QAAQ,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,aAAa,EAAE,YAAY,EAAE,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,aAAa,CAAC;IAC5E,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../env/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAA;AAElD;;;;;;;;;;GAUG;AACH,SAAS,aAAa,CAAsB,KAAQ;IACnD,OAAO,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,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E,kBAAkB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IACzC,uBAAuB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC9C,2BAA2B,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAElD,sFAAsF;IACtF,cAAc,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAErC,6EAA6E;IAC7E,yBAAyB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAEhD,4GAA4G;IAC5G,gBAAgB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IACvC,eAAe,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAEtC,yGAAyG;IACzG,oBAAoB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC3C;;;;OAIG;IACH,oBAAoB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAE3C,eAAe,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IACtC,mBAAmB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAE1C,sGAAsG;IACtG,uGAAuG;IACvG,iGAAiG;IACjG,uGAAuG;IACvG,mBAAmB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CAC1C,CAAC,CAAA"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software.
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* A kibibyte. Named so a `< 1024` guard reads as a threshold rather than a magic number — several fetchers use it to
|
|
8
|
+
* reject a response too small to be the archive they asked for.
|
|
9
|
+
*/
|
|
10
|
+
export declare const BYTES_PER_KIB = 1024;
|
|
11
|
+
export interface ByteFormatterOptions {
|
|
12
|
+
/**
|
|
13
|
+
* Prefix an explicit `+` on a positive value. For a DELTA, where the sign is the information. A negative always
|
|
14
|
+
* carries its own sign.
|
|
15
|
+
*/
|
|
16
|
+
signed?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Override the formatter's locale for this call.
|
|
19
|
+
*/
|
|
20
|
+
locales?: Intl.LocalesArgument;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Byte counts as a human reads them, in whichever of the two bases the number was actually measured in.
|
|
24
|
+
*
|
|
25
|
+
* Both bases, spelled correctly. A formatter that divides by 1024 and prints `KB` is off by 2.4% at KB and 10% by TB,
|
|
26
|
+
* and the label is the only thing telling a reader which it did — so the choice is named at the call site:
|
|
27
|
+
*
|
|
28
|
+
* - {@linkcode ByteFormatter.formatIEC} for anything a MACHINE measured — heap, file size on disk, buffer length.
|
|
29
|
+
* - {@linkcode ByteFormatter.formatSI} for a size a VENDOR reports. Disk capacity, download sizes and GitHub's own API
|
|
30
|
+
* are quoted in powers of ten; rendering GitHub's `41.3 GB` as `38.5 GiB` is correct arithmetic and the wrong
|
|
31
|
+
* answer.
|
|
32
|
+
*
|
|
33
|
+
* Rendering goes through `Intl.NumberFormat`, so the unit and the decimal separator follow the locale. Pass an explicit
|
|
34
|
+
* locale when a caller needs a stable string — a test asserting an exact rendering, not a line printed for a human.
|
|
35
|
+
*/
|
|
36
|
+
export declare class ByteFormatter {
|
|
37
|
+
static SI_UNITS: readonly ["byte", "kilobyte", "megabyte", "gigabyte", "terabyte"];
|
|
38
|
+
static IEC_UNITS: readonly ["B", "KiB", "MiB", "GiB", "TiB"];
|
|
39
|
+
static shared: ByteFormatter;
|
|
40
|
+
static formatSI(bytes: number, options?: ByteFormatterOptions): string;
|
|
41
|
+
static formatIEC(bytes: number, options?: ByteFormatterOptions): string;
|
|
42
|
+
protected locales?: Intl.LocalesArgument;
|
|
43
|
+
constructor(locales?: Intl.LocalesArgument);
|
|
44
|
+
/**
|
|
45
|
+
* Formats a file size in bytes into a human-readable string with appropriate SI units (B, kB, MB, GB, TB).
|
|
46
|
+
*
|
|
47
|
+
* @param bytes The file size in bytes.
|
|
48
|
+
*/
|
|
49
|
+
formatSI(bytes: number, options?: ByteFormatterOptions): string;
|
|
50
|
+
/**
|
|
51
|
+
* Formats a file size in bytes into a human-readable string with appropriate IEC units (B, KiB, MiB, GiB, TiB).
|
|
52
|
+
*
|
|
53
|
+
* @param bytes The file size in bytes.
|
|
54
|
+
*/
|
|
55
|
+
formatIEC(bytes: number, options?: ByteFormatterOptions): string;
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=formatters.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatters.d.ts","sourceRoot":"","sources":["../../../fs/utils/formatters.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;GAGG;AACH,eAAO,MAAM,aAAa,OAAO,CAAA;AAEjC,MAAM,WAAW,oBAAoB;IACpC;;;OAGG;IACH,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB;;OAEG;IACH,OAAO,CAAC,EAAE,IAAI,CAAC,eAAe,CAAA;CAC9B;AAED;;;;;;;;;;;;;GAaG;AACH,qBAAa,aAAa;IACzB,OAAc,QAAQ,oEAAoE;IAC1F,OAAc,SAAS,6CAA6C;IAEpE,OAAc,MAAM,gBAAsB;WAE5B,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,oBAAoB,GAAG,MAAM;WAI/D,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,oBAAoB,GAAG,MAAM;IAI9E,SAAS,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,eAAe,CAAA;gBAE5B,OAAO,CAAC,EAAE,IAAI,CAAC,eAAe;IAI1C;;;;OAIG;IACI,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,oBAAoB,GAAG,MAAM;IAoBtE;;;;OAIG;IACI,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,oBAAoB,GAAG,MAAM;CAkBvE"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software.
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* A kibibyte. Named so a `< 1024` guard reads as a threshold rather than a magic number — several fetchers use it to
|
|
8
|
+
* reject a response too small to be the archive they asked for.
|
|
9
|
+
*/
|
|
10
|
+
export const BYTES_PER_KIB = 1024;
|
|
11
|
+
/**
|
|
12
|
+
* Byte counts as a human reads them, in whichever of the two bases the number was actually measured in.
|
|
13
|
+
*
|
|
14
|
+
* Both bases, spelled correctly. A formatter that divides by 1024 and prints `KB` is off by 2.4% at KB and 10% by TB,
|
|
15
|
+
* and the label is the only thing telling a reader which it did — so the choice is named at the call site:
|
|
16
|
+
*
|
|
17
|
+
* - {@linkcode ByteFormatter.formatIEC} for anything a MACHINE measured — heap, file size on disk, buffer length.
|
|
18
|
+
* - {@linkcode ByteFormatter.formatSI} for a size a VENDOR reports. Disk capacity, download sizes and GitHub's own API
|
|
19
|
+
* are quoted in powers of ten; rendering GitHub's `41.3 GB` as `38.5 GiB` is correct arithmetic and the wrong
|
|
20
|
+
* answer.
|
|
21
|
+
*
|
|
22
|
+
* Rendering goes through `Intl.NumberFormat`, so the unit and the decimal separator follow the locale. Pass an explicit
|
|
23
|
+
* locale when a caller needs a stable string — a test asserting an exact rendering, not a line printed for a human.
|
|
24
|
+
*/
|
|
25
|
+
export class ByteFormatter {
|
|
26
|
+
static SI_UNITS = ["byte", "kilobyte", "megabyte", "gigabyte", "terabyte"];
|
|
27
|
+
static IEC_UNITS = ["B", "KiB", "MiB", "GiB", "TiB"];
|
|
28
|
+
static shared = new ByteFormatter();
|
|
29
|
+
static formatSI(bytes, options) {
|
|
30
|
+
return ByteFormatter.shared.formatSI(bytes, options);
|
|
31
|
+
}
|
|
32
|
+
static formatIEC(bytes, options) {
|
|
33
|
+
return ByteFormatter.shared.formatIEC(bytes, options);
|
|
34
|
+
}
|
|
35
|
+
locales;
|
|
36
|
+
constructor(locales) {
|
|
37
|
+
this.locales = locales;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Formats a file size in bytes into a human-readable string with appropriate SI units (B, kB, MB, GB, TB).
|
|
41
|
+
*
|
|
42
|
+
* @param bytes The file size in bytes.
|
|
43
|
+
*/
|
|
44
|
+
formatSI(bytes, options) {
|
|
45
|
+
const units = ByteFormatter.SI_UNITS;
|
|
46
|
+
let value = bytes;
|
|
47
|
+
let unit = 0;
|
|
48
|
+
while (Math.abs(value) >= 1000 && unit < units.length - 1) {
|
|
49
|
+
value /= 1000;
|
|
50
|
+
unit++;
|
|
51
|
+
}
|
|
52
|
+
return new Intl.NumberFormat(options?.locales ?? this.locales, {
|
|
53
|
+
style: "unit",
|
|
54
|
+
unit: units[unit],
|
|
55
|
+
maximumFractionDigits: 1,
|
|
56
|
+
signDisplay: options?.signed ? "exceptZero" : "auto",
|
|
57
|
+
}).format(value);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Formats a file size in bytes into a human-readable string with appropriate IEC units (B, KiB, MiB, GiB, TiB).
|
|
61
|
+
*
|
|
62
|
+
* @param bytes The file size in bytes.
|
|
63
|
+
*/
|
|
64
|
+
formatIEC(bytes, options) {
|
|
65
|
+
let value = bytes;
|
|
66
|
+
let unit = 0;
|
|
67
|
+
// oxlint-disable-next-line sister-software/no-unnamed-threshold -- Well known.
|
|
68
|
+
while (Math.abs(value) >= 1024 && unit < ByteFormatter.IEC_UNITS.length - 1) {
|
|
69
|
+
value /= 1024;
|
|
70
|
+
unit++;
|
|
71
|
+
}
|
|
72
|
+
const formatted = new Intl.NumberFormat(options?.locales ?? this.locales, {
|
|
73
|
+
maximumFractionDigits: 1,
|
|
74
|
+
signDisplay: options?.signed ? "exceptZero" : "auto",
|
|
75
|
+
}).format(value);
|
|
76
|
+
return `${formatted} ${ByteFormatter.IEC_UNITS[unit]}`;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=formatters.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatters.js","sourceRoot":"","sources":["../../../fs/utils/formatters.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;GAGG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,IAAI,CAAA;AAcjC;;;;;;;;;;;;;GAaG;AACH,MAAM,OAAO,aAAa;IAClB,MAAM,CAAC,QAAQ,GAAG,CAAC,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,CAAU,CAAA;IACnF,MAAM,CAAC,SAAS,GAAG,CAAC,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,CAAU,CAAA;IAE7D,MAAM,CAAC,MAAM,GAAG,IAAI,aAAa,EAAE,CAAA;IAEnC,MAAM,CAAC,QAAQ,CAAC,KAAa,EAAE,OAA8B;QACnE,OAAO,aAAa,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;IACrD,CAAC;IAEM,MAAM,CAAC,SAAS,CAAC,KAAa,EAAE,OAA8B;QACpE,OAAO,aAAa,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;IACtD,CAAC;IAES,OAAO,CAAuB;IAExC,YAAY,OAA8B;QACzC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;IACvB,CAAC;IAED;;;;OAIG;IACI,QAAQ,CAAC,KAAa,EAAE,OAA8B;QAC5D,MAAM,KAAK,GAAG,aAAa,CAAC,QAAQ,CAAA;QAEpC,IAAI,KAAK,GAAG,KAAK,CAAA;QACjB,IAAI,IAAI,GAAG,CAAC,CAAA;QAEZ,OAAO,IAAI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"file":"index.d.ts","sourceRoot":"","sources":["../../../fs/utils/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,iBAAiB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../fs/utils/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,iBAAiB,CAAA"}
|
package/out/fs/zip.d.ts
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
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
|
+
import ADMZip from "adm-zip";
|
|
18
|
+
import type { PathBuilderLike } from "path-ts";
|
|
19
|
+
export type ZipEntryContentPair = [entry: ADMZip.IZipEntry, content: Buffer];
|
|
20
|
+
/**
|
|
21
|
+
* Extract the contents of a zip file.
|
|
22
|
+
*
|
|
23
|
+
* @category Files
|
|
24
|
+
* @internal
|
|
25
|
+
*/
|
|
26
|
+
export declare function extractZip(data: ArrayBuffer | Buffer): Map<ADMZip.IZipEntry, Buffer>;
|
|
27
|
+
/**
|
|
28
|
+
* Extract the contents of a zip file and return the first entry.
|
|
29
|
+
*/
|
|
30
|
+
export declare function extractSingleFileZip(data: ArrayBuffer | Buffer): Promise<Buffer>;
|
|
31
|
+
/**
|
|
32
|
+
* Names a member of an archive, either exactly or by pattern.
|
|
33
|
+
*
|
|
34
|
+
* A pattern matches the FIRST entry whose full archive-internal path tests true, in central-directory order.
|
|
35
|
+
*/
|
|
36
|
+
export type ZipEntrySelector = string | RegExp;
|
|
37
|
+
/**
|
|
38
|
+
* One archive member, as reported by the central directory.
|
|
39
|
+
*
|
|
40
|
+
* @category Files
|
|
41
|
+
*/
|
|
42
|
+
export interface ZipEntryInfo {
|
|
43
|
+
/**
|
|
44
|
+
* The archive-internal path, e.g. `it/countrywide.csv`. Directory entries keep their trailing slash.
|
|
45
|
+
*/
|
|
46
|
+
name: string;
|
|
47
|
+
compressedSize: number;
|
|
48
|
+
uncompressedSize: number;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* List an archive's members without decompressing any of them.
|
|
52
|
+
*
|
|
53
|
+
* @category Files
|
|
54
|
+
*/
|
|
55
|
+
export declare function listZipEntries(archivePath: PathBuilderLike): Promise<ZipEntryInfo[]>;
|
|
56
|
+
/**
|
|
57
|
+
* Stream one member's decompressed bytes out of an archive on disk.
|
|
58
|
+
*
|
|
59
|
+
* Nothing beyond the central directory and the inflate window is held in memory, so this is bounded by the consumer
|
|
60
|
+
* rather than by the member's size. A consumer that stops early — a `take`, a `break` — destroys the member stream and
|
|
61
|
+
* closes the archive on the way out.
|
|
62
|
+
*
|
|
63
|
+
* @category Files
|
|
64
|
+
* @throws If no member matches `selector`.
|
|
65
|
+
*/
|
|
66
|
+
export declare function readZipEntry(archivePath: PathBuilderLike, selector: ZipEntrySelector): AsyncGenerator<Uint8Array>;
|
|
67
|
+
/**
|
|
68
|
+
* Write one member's decompressed bytes to `destinationPath`.
|
|
69
|
+
*
|
|
70
|
+
* @category Files
|
|
71
|
+
*
|
|
72
|
+
* @returns The number of bytes written, as the central directory reports them.
|
|
73
|
+
* @throws If no member matches `selector`.
|
|
74
|
+
*/
|
|
75
|
+
export declare function extractZipEntry(archivePath: PathBuilderLike, selector: ZipEntrySelector, destinationPath: PathBuilderLike): Promise<number>;
|
|
76
|
+
export interface ExtractZipEntriesOptions {
|
|
77
|
+
/**
|
|
78
|
+
* Which members to write. Omit for every member.
|
|
79
|
+
*/
|
|
80
|
+
selector?: ZipEntrySelector;
|
|
81
|
+
/**
|
|
82
|
+
* Write each member under its basename rather than its archive-internal path, flattening the tree — `unzip -j`.
|
|
83
|
+
*
|
|
84
|
+
* The shapefile archives this exists for carry their siblings in one directory, and the readers downstream expect
|
|
85
|
+
* them flat.
|
|
86
|
+
*/
|
|
87
|
+
flatten?: boolean;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Extract members of an archive into `destinationDirectory`.
|
|
91
|
+
*
|
|
92
|
+
* Directory entries are skipped; a nested path is created as needed unless `flatten` is set. Members stream one at a
|
|
93
|
+
* time, so this is bounded by the largest member rather than by the archive.
|
|
94
|
+
*
|
|
95
|
+
* @category Files
|
|
96
|
+
*
|
|
97
|
+
* @returns The archive-internal names of everything written, in central-directory order.
|
|
98
|
+
*/
|
|
99
|
+
export declare function extractZipEntries(archivePath: PathBuilderLike, destinationDirectory: PathBuilderLike, { selector, flatten }?: ExtractZipEntriesOptions): Promise<string[]>;
|
|
100
|
+
/**
|
|
101
|
+
* Verify every member's CRC-32 against the value its central-directory header claims — what `unzip -t` is for.
|
|
102
|
+
*
|
|
103
|
+
* This is a corruption check on a download, so it decompresses everything and keeps nothing; the archive is read one
|
|
104
|
+
* member at a time and the checksum is folded chunk by chunk, so memory is bounded by the inflate window.
|
|
105
|
+
*
|
|
106
|
+
* The CRC is computed here rather than delegated to yauzl's `validateCrc32`, which asserts `Cannot validate CRC32 for
|
|
107
|
+
* uncompressed data` on a STORED member — and a corrupt stored member is precisely what this is meant to catch. Folding
|
|
108
|
+
* it locally covers both storage methods with one path.
|
|
109
|
+
*
|
|
110
|
+
* @category Files
|
|
111
|
+
*
|
|
112
|
+
* @returns The number of members checked. @throws If the archive is unreadable, or any member's checksum or length
|
|
113
|
+
* disagrees with its header.
|
|
114
|
+
*/
|
|
115
|
+
export declare function verifyZipIntegrity(archivePath: PathBuilderLike): Promise<number>;
|
|
116
|
+
//# sourceMappingURL=zip.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zip.d.ts","sourceRoot":"","sources":["../../fs/zip.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAQH,OAAO,MAAM,MAAM,SAAS,CAAA;AAC5B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAG9C,MAAM,MAAM,mBAAmB,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,SAAS,EAAE,OAAO,EAAE,MAAM,CAAC,CAAA;AAE5E;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,WAAW,GAAG,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,CAcpF;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,WAAW,GAAG,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAiBhF;AAED;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG,MAAM,CAAA;AAE9C;;;;GAIG;AACH,MAAM,WAAW,YAAY;IAC5B;;OAEG;IACH,IAAI,EAAE,MAAM,CAAA;IACZ,cAAc,EAAE,MAAM,CAAA;IACtB,gBAAgB,EAAE,MAAM,CAAA;CACxB;AAMD;;;;GAIG;AACH,wBAAsB,cAAc,CAAC,WAAW,EAAE,eAAe,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,CAiB1F;AAED;;;;;;;;;GASG;AACH,wBAAuB,YAAY,CAClC,WAAW,EAAE,eAAe,EAC5B,QAAQ,EAAE,gBAAgB,GACxB,cAAc,CAAC,UAAU,CAAC,CAsB5B;AAED;;;;;;;GAOG;AACH,wBAAsB,eAAe,CACpC,WAAW,EAAE,eAAe,EAC5B,QAAQ,EAAE,gBAAgB,EAC1B,eAAe,EAAE,eAAe,GAC9B,OAAO,CAAC,MAAM,CAAC,CAgBjB;AAED,MAAM,WAAW,wBAAwB;IACxC;;OAEG;IACH,QAAQ,CAAC,EAAE,gBAAgB,CAAA;IAC3B;;;;;OAKG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;CACjB;AAED;;;;;;;;;GASG;AACH,wBAAsB,iBAAiB,CACtC,WAAW,EAAE,eAAe,EAC5B,oBAAoB,EAAE,eAAe,EACrC,EAAE,QAAQ,EAAE,OAAe,EAAE,GAAE,wBAA6B,GAC1D,OAAO,CAAC,MAAM,EAAE,CAAC,CA0BnB;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,kBAAkB,CAAC,WAAW,EAAE,eAAe,GAAG,OAAO,CAAC,MAAM,CAAC,CAoCtF"}
|
package/out/fs/zip.js
ADDED
|
@@ -0,0 +1,216 @@
|
|
|
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
|
+
import { createWriteStream } from "node:fs";
|
|
18
|
+
import { mkdir } from "node:fs/promises";
|
|
19
|
+
import { basename, dirname, join } from "node:path";
|
|
20
|
+
import { pipeline } from "node:stream/promises";
|
|
21
|
+
import { crc32 } from "node:zlib";
|
|
22
|
+
import ADMZip from "adm-zip";
|
|
23
|
+
import { open as openArchive } from "yauzl-promise";
|
|
24
|
+
/**
|
|
25
|
+
* Extract the contents of a zip file.
|
|
26
|
+
*
|
|
27
|
+
* @category Files
|
|
28
|
+
* @internal
|
|
29
|
+
*/
|
|
30
|
+
export function extractZip(data) {
|
|
31
|
+
const normalizedData = data instanceof ArrayBuffer ? Buffer.from(data) : data;
|
|
32
|
+
const zip = new ADMZip(normalizedData);
|
|
33
|
+
const pairs = zip
|
|
34
|
+
.getEntries()
|
|
35
|
+
.map((entry) => [entry, zip.readFile(entry)])
|
|
36
|
+
.filter((pair) => pair[1] !== null);
|
|
37
|
+
if (!pairs.length) {
|
|
38
|
+
throw new Error("No entry pairs found in zip file.");
|
|
39
|
+
}
|
|
40
|
+
return new Map(pairs);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Extract the contents of a zip file and return the first entry.
|
|
44
|
+
*/
|
|
45
|
+
export function extractSingleFileZip(data) {
|
|
46
|
+
const normalizedData = data instanceof ArrayBuffer ? Buffer.from(data) : data;
|
|
47
|
+
const zip = new ADMZip(normalizedData);
|
|
48
|
+
const [entry] = zip.getEntries();
|
|
49
|
+
// We use the async version of getData to avoid blocking the event loop.
|
|
50
|
+
return new Promise((resolve, reject) =>
|
|
51
|
+
// oxlint-disable-next-line no-promise-executor-return -- return the callback registration from this expression-bodied executor
|
|
52
|
+
entry.getDataAsync((extractedData, error) => {
|
|
53
|
+
if (error) {
|
|
54
|
+
reject(error);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
resolve(extractedData);
|
|
58
|
+
}
|
|
59
|
+
}));
|
|
60
|
+
}
|
|
61
|
+
function selectorMatches(selector, name) {
|
|
62
|
+
return typeof selector === "string" ? name === selector : selector.test(name);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* List an archive's members without decompressing any of them.
|
|
66
|
+
*
|
|
67
|
+
* @category Files
|
|
68
|
+
*/
|
|
69
|
+
export async function listZipEntries(archivePath) {
|
|
70
|
+
const archive = await openArchive(String(archivePath));
|
|
71
|
+
const entries = [];
|
|
72
|
+
try {
|
|
73
|
+
for await (const entry of archive) {
|
|
74
|
+
entries.push({
|
|
75
|
+
name: entry.filename,
|
|
76
|
+
compressedSize: entry.compressedSize,
|
|
77
|
+
uncompressedSize: entry.uncompressedSize,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
finally {
|
|
82
|
+
await archive.close();
|
|
83
|
+
}
|
|
84
|
+
return entries;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Stream one member's decompressed bytes out of an archive on disk.
|
|
88
|
+
*
|
|
89
|
+
* Nothing beyond the central directory and the inflate window is held in memory, so this is bounded by the consumer
|
|
90
|
+
* rather than by the member's size. A consumer that stops early — a `take`, a `break` — destroys the member stream and
|
|
91
|
+
* closes the archive on the way out.
|
|
92
|
+
*
|
|
93
|
+
* @category Files
|
|
94
|
+
* @throws If no member matches `selector`.
|
|
95
|
+
*/
|
|
96
|
+
export async function* readZipEntry(archivePath, selector) {
|
|
97
|
+
const archive = await openArchive(String(archivePath));
|
|
98
|
+
try {
|
|
99
|
+
for await (const entry of archive) {
|
|
100
|
+
if (!selectorMatches(selector, entry.filename))
|
|
101
|
+
continue;
|
|
102
|
+
const contents = await entry.openReadStream();
|
|
103
|
+
try {
|
|
104
|
+
yield* contents;
|
|
105
|
+
}
|
|
106
|
+
finally {
|
|
107
|
+
contents.destroy();
|
|
108
|
+
}
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
throw new Error(`No entry matching ${selector} in ${archivePath}`);
|
|
112
|
+
}
|
|
113
|
+
finally {
|
|
114
|
+
await archive.close();
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Write one member's decompressed bytes to `destinationPath`.
|
|
119
|
+
*
|
|
120
|
+
* @category Files
|
|
121
|
+
*
|
|
122
|
+
* @returns The number of bytes written, as the central directory reports them.
|
|
123
|
+
* @throws If no member matches `selector`.
|
|
124
|
+
*/
|
|
125
|
+
export async function extractZipEntry(archivePath, selector, destinationPath) {
|
|
126
|
+
const archive = await openArchive(String(archivePath));
|
|
127
|
+
try {
|
|
128
|
+
for await (const entry of archive) {
|
|
129
|
+
if (!selectorMatches(selector, entry.filename))
|
|
130
|
+
continue;
|
|
131
|
+
await pipeline(await entry.openReadStream(), createWriteStream(String(destinationPath)));
|
|
132
|
+
return entry.uncompressedSize;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
finally {
|
|
136
|
+
await archive.close();
|
|
137
|
+
}
|
|
138
|
+
throw new Error(`No entry matching ${selector} in ${archivePath}`);
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Extract members of an archive into `destinationDirectory`.
|
|
142
|
+
*
|
|
143
|
+
* Directory entries are skipped; a nested path is created as needed unless `flatten` is set. Members stream one at a
|
|
144
|
+
* time, so this is bounded by the largest member rather than by the archive.
|
|
145
|
+
*
|
|
146
|
+
* @category Files
|
|
147
|
+
*
|
|
148
|
+
* @returns The archive-internal names of everything written, in central-directory order.
|
|
149
|
+
*/
|
|
150
|
+
export async function extractZipEntries(archivePath, destinationDirectory, { selector, flatten = false } = {}) {
|
|
151
|
+
const archive = await openArchive(String(archivePath));
|
|
152
|
+
const written = [];
|
|
153
|
+
try {
|
|
154
|
+
for await (const entry of archive) {
|
|
155
|
+
if (entry.filename.endsWith("/"))
|
|
156
|
+
continue;
|
|
157
|
+
if (selector && !selectorMatches(selector, entry.filename))
|
|
158
|
+
continue;
|
|
159
|
+
const relative = flatten ? basename(entry.filename) : entry.filename;
|
|
160
|
+
const destination = join(String(destinationDirectory), relative);
|
|
161
|
+
if (!flatten) {
|
|
162
|
+
await mkdir(dirname(destination), { recursive: true });
|
|
163
|
+
}
|
|
164
|
+
await pipeline(await entry.openReadStream(), createWriteStream(destination));
|
|
165
|
+
written.push(entry.filename);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
finally {
|
|
169
|
+
await archive.close();
|
|
170
|
+
}
|
|
171
|
+
return written;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Verify every member's CRC-32 against the value its central-directory header claims — what `unzip -t` is for.
|
|
175
|
+
*
|
|
176
|
+
* This is a corruption check on a download, so it decompresses everything and keeps nothing; the archive is read one
|
|
177
|
+
* member at a time and the checksum is folded chunk by chunk, so memory is bounded by the inflate window.
|
|
178
|
+
*
|
|
179
|
+
* The CRC is computed here rather than delegated to yauzl's `validateCrc32`, which asserts `Cannot validate CRC32 for
|
|
180
|
+
* uncompressed data` on a STORED member — and a corrupt stored member is precisely what this is meant to catch. Folding
|
|
181
|
+
* it locally covers both storage methods with one path.
|
|
182
|
+
*
|
|
183
|
+
* @category Files
|
|
184
|
+
*
|
|
185
|
+
* @returns The number of members checked. @throws If the archive is unreadable, or any member's checksum or length
|
|
186
|
+
* disagrees with its header.
|
|
187
|
+
*/
|
|
188
|
+
export async function verifyZipIntegrity(archivePath) {
|
|
189
|
+
const archive = await openArchive(String(archivePath));
|
|
190
|
+
let checked = 0;
|
|
191
|
+
try {
|
|
192
|
+
for await (const entry of archive) {
|
|
193
|
+
if (entry.filename.endsWith("/"))
|
|
194
|
+
continue;
|
|
195
|
+
const contents = await entry.openReadStream({ validateCrc32: false });
|
|
196
|
+
let checksum = 0;
|
|
197
|
+
let length = 0;
|
|
198
|
+
for await (const chunk of contents) {
|
|
199
|
+
checksum = crc32(chunk, checksum);
|
|
200
|
+
length += chunk.length;
|
|
201
|
+
}
|
|
202
|
+
if (checksum !== entry.crc32) {
|
|
203
|
+
throw new Error(`CRC mismatch in ${archivePath}: ${entry.filename} is 0x${checksum.toString(16)}, header claims 0x${entry.crc32.toString(16)}`);
|
|
204
|
+
}
|
|
205
|
+
if (length !== entry.uncompressedSize) {
|
|
206
|
+
throw new Error(`Length mismatch in ${archivePath}: ${entry.filename} is ${length} bytes, header claims ${entry.uncompressedSize}`);
|
|
207
|
+
}
|
|
208
|
+
checked++;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
finally {
|
|
212
|
+
await archive.close();
|
|
213
|
+
}
|
|
214
|
+
return checked;
|
|
215
|
+
}
|
|
216
|
+
//# sourceMappingURL=zip.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zip.js","sourceRoot":"","sources":["../../fs/zip.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAC3C,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAA;AACxC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAC/C,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAA;AAEjC,OAAO,MAAM,MAAM,SAAS,CAAA;AAE5B,OAAO,EAAE,IAAI,IAAI,WAAW,EAAE,MAAM,eAAe,CAAA;AAInD;;;;;GAKG;AACH,MAAM,UAAU,UAAU,CAAC,IAA0B;IACpD,MAAM,cAAc,GAAG,IAAI,YAAY,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;IAC7E,MAAM,GAAG,GAAG,IAAI,MAAM,CAAC,cAAc,CAAC,CAA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