@mailwoman/core 8.1.0 → 8.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/api/APIClient.ts +3 -4
- package/api/responses.ts +6 -3
- package/coarse-placer/coarse-placer.ts +26 -11
- package/coarse-placer/featurize.ts +25 -16
- package/coarse-placer/tools/build-dataset.ts +42 -18
- package/coarse-placer/tools/build-outlier-exposure.ts +51 -18
- package/coarse-placer/tools/build-outlier-latin.ts +48 -22
- package/coarse-placer/tools/build-outlier-oa.ts +52 -20
- package/coarse-placer/tools/eval-latin-offmap.ts +37 -12
- package/coarse-placer/tools/eval-openset.ts +104 -37
- package/coarse-placer/tools/eval-quant-compare.ts +41 -11
- package/coarse-placer/tools/eval.ts +51 -13
- package/coarse-placer/tools/fnv-hash.ts +5 -3
- package/coarse-placer/tools/probe-frontier.ts +63 -32
- package/coarse-placer/tools/quantize.ts +30 -8
- package/coarse-placer/tools/train.ts +63 -17
- package/collections.ts +2 -2
- package/decoder/build-tree.ts +16 -3
- package/decoder/calibration.ts +23 -7
- package/decoder/containment.ts +3 -1
- package/decoder/proposals-to-tree.ts +2 -0
- package/decoder/resolve-proposal-overlaps.ts +5 -1
- package/decoder/serialize-json.ts +8 -2
- package/decoder/serialize-tuples.ts +7 -2
- package/decoder/serialize-xml.ts +29 -11
- package/decoder/types.ts +34 -12
- package/decoder/unknown-spans.ts +14 -5
- package/decoder/validate-tree.ts +6 -1
- package/env/index.ts +1 -1
- package/env/load.ts +1 -1
- package/env/paths.ts +1 -1
- package/env/schema.ts +12 -4
- package/errors/schema.ts +1 -1
- package/fs/node.ts +9 -10
- package/identifiers.ts +3 -3
- package/kysley/adapter.ts +1 -1
- package/layers/manifest.ts +22 -8
- package/layers/schema.ts +59 -19
- package/locale/locale.ts +6 -2
- package/locale/profiles/en-us.ts +3 -0
- package/locale/profiles/fr-fr.ts +3 -0
- package/locale/profiles/ja-jp.ts +3 -0
- package/locale/registry.ts +3 -1
- package/logging/shared.ts +1 -0
- package/logging/utils.ts +1 -1
- package/objects.ts +7 -2
- package/out/api/APIClient.d.ts +1 -1
- package/out/api/APIClient.d.ts.map +1 -1
- package/out/api/APIClient.js +3 -2
- package/out/api/APIClient.js.map +1 -1
- package/out/api/responses.d.ts.map +1 -1
- package/out/api/responses.js +3 -3
- package/out/api/responses.js.map +1 -1
- package/out/coarse-placer/coarse-placer.d.ts +19 -9
- package/out/coarse-placer/coarse-placer.d.ts.map +1 -1
- package/out/coarse-placer/coarse-placer.js +6 -4
- package/out/coarse-placer/coarse-placer.js.map +1 -1
- package/out/coarse-placer/featurize.d.ts.map +1 -1
- package/out/coarse-placer/featurize.js +20 -16
- package/out/coarse-placer/featurize.js.map +1 -1
- package/out/coarse-placer/tools/build-dataset.d.ts +15 -5
- package/out/coarse-placer/tools/build-dataset.d.ts.map +1 -1
- package/out/coarse-placer/tools/build-dataset.js +19 -14
- package/out/coarse-placer/tools/build-dataset.js.map +1 -1
- package/out/coarse-placer/tools/build-outlier-exposure.d.ts +21 -7
- package/out/coarse-placer/tools/build-outlier-exposure.d.ts.map +1 -1
- package/out/coarse-placer/tools/build-outlier-exposure.js +24 -12
- package/out/coarse-placer/tools/build-outlier-exposure.js.map +1 -1
- package/out/coarse-placer/tools/build-outlier-latin.d.ts +18 -6
- package/out/coarse-placer/tools/build-outlier-latin.d.ts.map +1 -1
- package/out/coarse-placer/tools/build-outlier-latin.js +27 -17
- package/out/coarse-placer/tools/build-outlier-latin.js.map +1 -1
- package/out/coarse-placer/tools/build-outlier-oa.d.ts +18 -6
- package/out/coarse-placer/tools/build-outlier-oa.d.ts.map +1 -1
- package/out/coarse-placer/tools/build-outlier-oa.js +29 -15
- package/out/coarse-placer/tools/build-outlier-oa.js.map +1 -1
- package/out/coarse-placer/tools/eval-latin-offmap.d.ts +18 -6
- package/out/coarse-placer/tools/eval-latin-offmap.d.ts.map +1 -1
- package/out/coarse-placer/tools/eval-latin-offmap.js +13 -7
- package/out/coarse-placer/tools/eval-latin-offmap.js.map +1 -1
- package/out/coarse-placer/tools/eval-openset.d.ts +24 -8
- package/out/coarse-placer/tools/eval-openset.d.ts.map +1 -1
- package/out/coarse-placer/tools/eval-openset.js +52 -31
- package/out/coarse-placer/tools/eval-openset.js.map +1 -1
- package/out/coarse-placer/tools/eval-quant-compare.d.ts +30 -10
- package/out/coarse-placer/tools/eval-quant-compare.d.ts.map +1 -1
- package/out/coarse-placer/tools/eval-quant-compare.js +4 -2
- package/out/coarse-placer/tools/eval-quant-compare.js.map +1 -1
- package/out/coarse-placer/tools/eval.d.ts +24 -8
- package/out/coarse-placer/tools/eval.d.ts.map +1 -1
- package/out/coarse-placer/tools/eval.js +16 -6
- package/out/coarse-placer/tools/eval.js.map +1 -1
- package/out/coarse-placer/tools/fnv-hash.d.ts +3 -1
- package/out/coarse-placer/tools/fnv-hash.d.ts.map +1 -1
- package/out/coarse-placer/tools/fnv-hash.js +5 -3
- package/out/coarse-placer/tools/fnv-hash.js.map +1 -1
- package/out/coarse-placer/tools/probe-frontier.d.ts +18 -6
- package/out/coarse-placer/tools/probe-frontier.d.ts.map +1 -1
- package/out/coarse-placer/tools/probe-frontier.js +39 -23
- package/out/coarse-placer/tools/probe-frontier.js.map +1 -1
- package/out/coarse-placer/tools/quantize.d.ts +15 -5
- package/out/coarse-placer/tools/quantize.d.ts.map +1 -1
- package/out/coarse-placer/tools/quantize.js +11 -4
- package/out/coarse-placer/tools/quantize.js.map +1 -1
- package/out/coarse-placer/tools/train.d.ts +24 -8
- package/out/coarse-placer/tools/train.d.ts.map +1 -1
- package/out/coarse-placer/tools/train.js +24 -10
- package/out/coarse-placer/tools/train.js.map +1 -1
- package/out/collections.js +2 -2
- package/out/collections.js.map +1 -1
- package/out/decoder/build-tree.d.ts.map +1 -1
- package/out/decoder/build-tree.js +9 -3
- package/out/decoder/build-tree.js.map +1 -1
- package/out/decoder/calibration.d.ts +17 -3
- package/out/decoder/calibration.d.ts.map +1 -1
- package/out/decoder/calibration.js +12 -4
- package/out/decoder/calibration.js.map +1 -1
- package/out/decoder/containment.d.ts +3 -1
- package/out/decoder/containment.d.ts.map +1 -1
- package/out/decoder/containment.js +3 -1
- package/out/decoder/containment.js.map +1 -1
- package/out/decoder/proposals-to-tree.d.ts.map +1 -1
- package/out/decoder/proposals-to-tree.js.map +1 -1
- package/out/decoder/resolve-proposal-overlaps.d.ts.map +1 -1
- package/out/decoder/resolve-proposal-overlaps.js +5 -1
- package/out/decoder/resolve-proposal-overlaps.js.map +1 -1
- package/out/decoder/serialize-json.d.ts +6 -2
- package/out/decoder/serialize-json.d.ts.map +1 -1
- package/out/decoder/serialize-json.js.map +1 -1
- package/out/decoder/serialize-tuples.d.ts +6 -2
- package/out/decoder/serialize-tuples.d.ts.map +1 -1
- package/out/decoder/serialize-tuples.js.map +1 -1
- package/out/decoder/serialize-xml.d.ts +21 -7
- package/out/decoder/serialize-xml.d.ts.map +1 -1
- package/out/decoder/serialize-xml.js +7 -5
- package/out/decoder/serialize-xml.js.map +1 -1
- package/out/decoder/types.d.ts +34 -12
- package/out/decoder/types.d.ts.map +1 -1
- package/out/decoder/types.js +1 -1
- package/out/decoder/types.js.map +1 -1
- package/out/decoder/unknown-spans.d.ts +9 -3
- package/out/decoder/unknown-spans.d.ts.map +1 -1
- package/out/decoder/unknown-spans.js +4 -2
- package/out/decoder/unknown-spans.js.map +1 -1
- package/out/decoder/validate-tree.d.ts +3 -1
- package/out/decoder/validate-tree.d.ts.map +1 -1
- package/out/decoder/validate-tree.js +3 -1
- package/out/decoder/validate-tree.js.map +1 -1
- package/out/env/index.js +0 -1
- package/out/env/index.js.map +1 -1
- package/out/env/load.js +1 -1
- package/out/env/load.js.map +1 -1
- package/out/env/paths.js +1 -1
- package/out/env/paths.js.map +1 -1
- package/out/env/schema.d.ts.map +1 -1
- package/out/env/schema.js +12 -4
- package/out/env/schema.js.map +1 -1
- package/out/errors/schema.js +1 -1
- package/out/errors/schema.js.map +1 -1
- package/out/fs/node.d.ts +1 -2
- package/out/fs/node.d.ts.map +1 -1
- package/out/fs/node.js +7 -8
- package/out/fs/node.js.map +1 -1
- package/out/identifiers.js +3 -3
- package/out/identifiers.js.map +1 -1
- package/out/kysley/adapter.d.ts +1 -1
- package/out/kysley/adapter.d.ts.map +1 -1
- package/out/kysley/adapter.js +1 -1
- package/out/kysley/adapter.js.map +1 -1
- package/out/layers/manifest.d.ts +18 -6
- package/out/layers/manifest.d.ts.map +1 -1
- package/out/layers/manifest.js +8 -4
- package/out/layers/manifest.js.map +1 -1
- package/out/layers/schema.d.ts +57 -19
- package/out/layers/schema.d.ts.map +1 -1
- package/out/layers/schema.js +24 -8
- package/out/layers/schema.js.map +1 -1
- package/out/locale/locale.d.ts +6 -2
- package/out/locale/locale.d.ts.map +1 -1
- package/out/locale/profiles/en-us.d.ts +3 -0
- package/out/locale/profiles/en-us.d.ts.map +1 -1
- package/out/locale/profiles/en-us.js +3 -0
- package/out/locale/profiles/en-us.js.map +1 -1
- package/out/locale/profiles/fr-fr.d.ts +3 -0
- package/out/locale/profiles/fr-fr.d.ts.map +1 -1
- package/out/locale/profiles/fr-fr.js +3 -0
- package/out/locale/profiles/fr-fr.js.map +1 -1
- package/out/locale/profiles/ja-jp.d.ts +3 -0
- package/out/locale/profiles/ja-jp.d.ts.map +1 -1
- package/out/locale/profiles/ja-jp.js +3 -0
- package/out/locale/profiles/ja-jp.js.map +1 -1
- package/out/locale/registry.d.ts +3 -1
- package/out/locale/registry.d.ts.map +1 -1
- package/out/locale/registry.js +3 -1
- package/out/locale/registry.js.map +1 -1
- package/out/logging/shared.d.ts.map +1 -1
- package/out/logging/shared.js +1 -0
- package/out/logging/shared.js.map +1 -1
- package/out/logging/utils.js +1 -1
- package/out/logging/utils.js.map +1 -1
- package/out/objects.d.ts.map +1 -1
- package/out/objects.js +2 -2
- package/out/objects.js.map +1 -1
- package/out/pipeline/index.d.ts +2 -2
- package/out/pipeline/index.d.ts.map +1 -1
- package/out/pipeline/index.js +1 -1
- package/out/pipeline/index.js.map +1 -1
- package/out/pipeline/reconcile-lookups.d.ts.map +1 -1
- package/out/pipeline/reconcile-lookups.js.map +1 -1
- package/out/pipeline/reconcile.d.ts +30 -10
- package/out/pipeline/reconcile.d.ts.map +1 -1
- package/out/pipeline/reconcile.js +12 -9
- package/out/pipeline/reconcile.js.map +1 -1
- package/out/pipeline/runtime-pipeline.d.ts +18 -0
- package/out/pipeline/runtime-pipeline.d.ts.map +1 -1
- package/out/pipeline/runtime-pipeline.js +73 -46
- package/out/pipeline/runtime-pipeline.js.map +1 -1
- package/out/pipeline/span-logit-aggregation.d.ts.map +1 -1
- package/out/pipeline/span-logit-aggregation.js +5 -2
- package/out/pipeline/span-logit-aggregation.js.map +1 -1
- package/out/pipeline/span-proposer.d.ts +19 -9
- package/out/pipeline/span-proposer.d.ts.map +1 -1
- package/out/pipeline/span-proposer.js +42 -22
- package/out/pipeline/span-proposer.js.map +1 -1
- package/out/pipeline/types.d.ts +77 -19
- package/out/pipeline/types.d.ts.map +1 -1
- package/out/pipeline/types.js +16 -0
- package/out/pipeline/types.js.map +1 -1
- package/out/policy/proposal-collection.d.ts +1 -1
- package/out/policy/proposal-collection.d.ts.map +1 -1
- package/out/policy/proposal-collection.js +2 -3
- package/out/policy/proposal-collection.js.map +1 -1
- package/out/policy/registry.d.ts +9 -3
- package/out/policy/registry.d.ts.map +1 -1
- package/out/policy/registry.js +9 -3
- package/out/policy/registry.js.map +1 -1
- package/out/resolver/index.d.ts.map +1 -1
- package/out/resolver/types.d.ts +94 -30
- package/out/resolver/types.d.ts.map +1 -1
- package/out/resolver/types.js +7 -1
- package/out/resolver/types.js.map +1 -1
- package/out/resources/LocaleIndex.d.ts +1 -1
- package/out/resources/LocaleIndex.d.ts.map +1 -1
- package/out/resources/LocaleIndex.js +1 -2
- package/out/resources/LocaleIndex.js.map +1 -1
- package/out/resources/ResourceMapCache.d.ts.map +1 -1
- package/out/resources/ResourceMapCache.js +1 -1
- package/out/resources/ResourceMapCache.js.map +1 -1
- package/out/resources/collections.d.ts.map +1 -1
- package/out/resources/collections.js +3 -1
- package/out/resources/collections.js.map +1 -1
- package/out/resources/languages/index.d.ts +1 -1
- package/out/resources/languages/index.d.ts.map +1 -1
- package/out/resources/languages/index.js +1 -1
- package/out/resources/languages/index.js.map +1 -1
- package/out/resources/libpostal.d.ts +1 -1
- package/out/resources/libpostal.d.ts.map +1 -1
- package/out/resources/libpostal.js +7 -5
- package/out/resources/libpostal.js.map +1 -1
- package/out/resources/set.js +6 -6
- package/out/resources/set.js.map +1 -1
- package/out/resources/whosonfirst/DataSourceCache.d.ts +1 -4
- package/out/resources/whosonfirst/DataSourceCache.d.ts.map +1 -1
- package/out/resources/whosonfirst/DataSourceCache.js +1 -20
- package/out/resources/whosonfirst/DataSourceCache.js.map +1 -1
- package/out/resources/whosonfirst/PlacetypeDataSource.d.ts +1 -1
- package/out/resources/whosonfirst/PlacetypeDataSource.d.ts.map +1 -1
- package/out/resources/whosonfirst/PlacetypeDataSource.js +2 -2
- package/out/resources/whosonfirst/PlacetypeDataSource.js.map +1 -1
- package/out/resources/whosonfirst/backoff.d.ts +19 -0
- package/out/resources/whosonfirst/backoff.d.ts.map +1 -0
- package/out/resources/whosonfirst/backoff.js +35 -0
- package/out/resources/whosonfirst/backoff.js.map +1 -0
- package/out/resources/whosonfirst/loader.d.ts +1 -1
- package/out/resources/whosonfirst/loader.d.ts.map +1 -1
- package/out/resources/whosonfirst/loader.js +0 -1
- package/out/resources/whosonfirst/loader.js.map +1 -1
- package/out/resources/whosonfirst/placetypes/Placetype.d.ts +4 -1
- package/out/resources/whosonfirst/placetypes/Placetype.d.ts.map +1 -1
- package/out/resources/whosonfirst/placetypes/Placetype.js +8 -6
- package/out/resources/whosonfirst/placetypes/Placetype.js.map +1 -1
- package/out/resources/whosonfirst/placetypes/admin.d.ts +6 -4
- package/out/resources/whosonfirst/placetypes/admin.d.ts.map +1 -1
- package/out/resources/whosonfirst/placetypes/admin.js +8 -4
- package/out/resources/whosonfirst/placetypes/admin.js.map +1 -1
- package/out/resources/whosonfirst/placetypes/definition.d.ts +5 -6
- package/out/resources/whosonfirst/placetypes/definition.d.ts.map +1 -1
- package/out/resources/whosonfirst/placetypes/definition.js +3 -0
- package/out/resources/whosonfirst/placetypes/definition.js.map +1 -1
- package/out/resources/whosonfirst/placetypes/graph.d.ts +4 -2
- package/out/resources/whosonfirst/placetypes/graph.d.ts.map +1 -1
- package/out/resources/whosonfirst/placetypes/graph.js +0 -0
- package/out/resources/whosonfirst/placetypes/graph.js.map +1 -1
- package/out/resources/whosonfirst/placetypes/mermaid.d.ts +4 -2
- package/out/resources/whosonfirst/placetypes/mermaid.d.ts.map +1 -1
- package/out/resources/whosonfirst/placetypes/mermaid.js +0 -1
- package/out/resources/whosonfirst/placetypes/mermaid.js.map +1 -1
- package/out/resources/whosonfirst/placetypes/tree.d.ts +1 -1
- package/out/resources/whosonfirst/placetypes/tree.d.ts.map +1 -1
- package/out/resources/whosonfirst/placetypes/tree.js +0 -1
- package/out/resources/whosonfirst/placetypes/tree.js.map +1 -1
- package/out/routing/index.d.ts.map +1 -1
- package/out/routing/index.js +1 -1
- package/out/routing/index.js.map +1 -1
- package/out/scripting/utils/index.d.ts +3 -1
- package/out/scripting/utils/index.d.ts.map +1 -1
- package/out/scripting/utils/index.js +3 -1
- package/out/scripting/utils/index.js.map +1 -1
- package/out/tokenization/Span.js.map +1 -1
- package/out/tokenization/normalizer.js +11 -11
- package/out/tokenization/normalizer.js.map +1 -1
- package/out/tools/download-libpostal-resources.d.ts.map +1 -1
- package/out/tools/download-libpostal-resources.js.map +1 -1
- package/out/tools/download-ssl-address.d.ts +9 -3
- package/out/tools/download-ssl-address.d.ts.map +1 -1
- package/out/tools/download-ssl-address.js +8 -4
- package/out/tools/download-ssl-address.js.map +1 -1
- package/out/tools/generate-language-types.d.ts +12 -4
- package/out/tools/generate-language-types.d.ts.map +1 -1
- package/out/tools/generate-language-types.js +3 -1
- package/out/tools/generate-language-types.js.map +1 -1
- package/out/types/Classification.d.ts.map +1 -1
- package/out/types/Classification.js.map +1 -1
- package/out/types/classifier.d.ts +27 -9
- package/out/types/classifier.d.ts.map +1 -1
- package/out/types/component.d.ts +6 -2
- package/out/types/component.d.ts.map +1 -1
- package/out/types/component.js.map +1 -1
- package/out/utils/data-root.d.ts +3 -1
- package/out/utils/data-root.d.ts.map +1 -1
- package/out/utils/data-root.js +3 -1
- package/out/utils/data-root.js.map +1 -1
- package/out/utils/hash.d.ts +6 -2
- package/out/utils/hash.d.ts.map +1 -1
- package/out/utils/hash.js +6 -2
- package/out/utils/hash.js.map +1 -1
- package/out/utils/jsonl.d.ts +9 -3
- package/out/utils/jsonl.d.ts.map +1 -1
- package/out/utils/jsonl.js +9 -3
- package/out/utils/jsonl.js.map +1 -1
- package/out/utils/python-json.d.ts +6 -2
- package/out/utils/python-json.d.ts.map +1 -1
- package/out/utils/python-json.js +9 -3
- package/out/utils/python-json.js.map +1 -1
- package/out/utils/python-random.d.ts +15 -5
- package/out/utils/python-random.d.ts.map +1 -1
- package/out/utils/python-random.js +17 -7
- package/out/utils/python-random.js.map +1 -1
- package/out/utils/repo.d.ts +4 -0
- package/out/utils/repo.d.ts.map +1 -1
- package/out/utils/repo.js +4 -0
- package/out/utils/repo.js.map +1 -1
- package/out/utils/sealed-db.d.ts +6 -2
- package/out/utils/sealed-db.d.ts.map +1 -1
- package/out/utils/sealed-db.js +6 -2
- package/out/utils/sealed-db.js.map +1 -1
- package/out/utils/stats.d.ts +9 -3
- package/out/utils/stats.d.ts.map +1 -1
- package/out/utils/stats.js +11 -5
- package/out/utils/stats.js.map +1 -1
- package/package.json +2 -2
- package/pipeline/index.ts +5 -1
- package/pipeline/reconcile-lookups.ts +3 -0
- package/pipeline/reconcile.ts +65 -24
- package/pipeline/runtime-pipeline.ts +95 -46
- package/pipeline/span-logit-aggregation.ts +7 -2
- package/pipeline/span-proposer.ts +95 -34
- package/pipeline/types.ts +88 -19
- package/policy/proposal-collection.ts +4 -3
- package/policy/registry.ts +13 -3
- package/resolver/index.ts +1 -0
- package/resolver/types.ts +95 -30
- package/resources/LocaleIndex.ts +2 -2
- package/resources/ResourceMapCache.ts +3 -2
- package/resources/collections.ts +4 -1
- package/resources/languages/index.ts +2 -1
- package/resources/libpostal.ts +6 -3
- package/resources/set.ts +6 -6
- package/resources/whosonfirst/DataSourceCache.ts +2 -24
- package/resources/whosonfirst/PlacetypeDataSource.ts +2 -2
- package/resources/whosonfirst/backoff.ts +39 -0
- package/resources/whosonfirst/loader.ts +2 -1
- package/resources/whosonfirst/placetypes/Placetype.ts +9 -6
- package/resources/whosonfirst/placetypes/admin.ts +12 -7
- package/resources/whosonfirst/placetypes/definition.ts +6 -6
- package/resources/whosonfirst/placetypes/graph.ts +0 -0
- package/resources/whosonfirst/placetypes/mermaid.ts +5 -2
- package/resources/whosonfirst/placetypes/tree.ts +1 -1
- package/routing/index.ts +5 -1
- package/scripting/utils/index.ts +3 -1
- package/tokenization/Span.ts +1 -1
- package/tokenization/normalizer.ts +11 -11
- package/tools/download-libpostal-resources.ts +1 -0
- package/tools/download-ssl-address.ts +19 -7
- package/tools/generate-language-types.ts +12 -4
- package/types/Classification.ts +5 -0
- package/types/classifier.ts +27 -9
- package/types/component.ts +6 -2
- package/utils/data-root.ts +3 -1
- package/utils/hash.ts +6 -2
- package/utils/jsonl.ts +11 -3
- package/utils/python-json.ts +13 -4
- package/utils/python-random.ts +17 -7
- package/utils/repo.ts +8 -0
- package/utils/sealed-db.ts +10 -2
- package/utils/stats.ts +11 -5
package/policy/registry.ts
CHANGED
|
@@ -42,17 +42,23 @@ export class InMemoryPolicyRegistry implements PolicyRegistry {
|
|
|
42
42
|
return registry
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
/**
|
|
45
|
+
/**
|
|
46
|
+
* Install a policy entry. Replaces any prior entry with the same key.
|
|
47
|
+
*/
|
|
46
48
|
set(policy: ClassifierPolicy): void {
|
|
47
49
|
this.#entries.set(policyKey(policy.component, policy.locale), policy)
|
|
48
50
|
}
|
|
49
51
|
|
|
50
|
-
/**
|
|
52
|
+
/**
|
|
53
|
+
* Remove a policy entry, if present.
|
|
54
|
+
*/
|
|
51
55
|
remove(component: ComponentTag, locale?: string): void {
|
|
52
56
|
this.#entries.delete(policyKey(component, locale))
|
|
53
57
|
}
|
|
54
58
|
|
|
55
|
-
/**
|
|
59
|
+
/**
|
|
60
|
+
* All current entries, in insertion order.
|
|
61
|
+
*/
|
|
56
62
|
entries(): ClassifierPolicy[] {
|
|
57
63
|
return Array.from(this.#entries.values())
|
|
58
64
|
}
|
|
@@ -63,6 +69,7 @@ export class InMemoryPolicyRegistry implements PolicyRegistry {
|
|
|
63
69
|
|
|
64
70
|
if (localized) return localized
|
|
65
71
|
}
|
|
72
|
+
|
|
66
73
|
const global = this.#entries.get(policyKey(component, undefined))
|
|
67
74
|
|
|
68
75
|
if (global) return global
|
|
@@ -127,18 +134,21 @@ function applyPreferenceFilters(
|
|
|
127
134
|
|
|
128
135
|
if (!policy) {
|
|
129
136
|
out.push(...list)
|
|
137
|
+
|
|
130
138
|
continue
|
|
131
139
|
}
|
|
132
140
|
|
|
133
141
|
if (policy.mode === "neural_preferred") {
|
|
134
142
|
const hasNeural = list.some((p) => p.source === "neural")
|
|
135
143
|
out.push(...(hasNeural ? list.filter((p) => p.source !== "rule") : list))
|
|
144
|
+
|
|
136
145
|
continue
|
|
137
146
|
}
|
|
138
147
|
|
|
139
148
|
if (policy.mode === "rule_preferred") {
|
|
140
149
|
const hasRule = list.some((p) => p.source === "rule")
|
|
141
150
|
out.push(...(hasRule ? list.filter((p) => p.source !== "neural") : list))
|
|
151
|
+
|
|
142
152
|
continue
|
|
143
153
|
}
|
|
144
154
|
|
package/resolver/index.ts
CHANGED
package/resolver/types.ts
CHANGED
|
@@ -21,19 +21,33 @@ import type { AddressTree, ComponentTag } from "../decoder/types.ts"
|
|
|
21
21
|
* `ResolvedPlace` is expected.
|
|
22
22
|
*/
|
|
23
23
|
export interface ResolvedPlace {
|
|
24
|
-
/**
|
|
24
|
+
/**
|
|
25
|
+
* Resolver-specific place identifier (e.g. WOF id).
|
|
26
|
+
*/
|
|
25
27
|
id: number | string
|
|
26
|
-
/**
|
|
28
|
+
/**
|
|
29
|
+
* Canonical name of the place as the resolver knows it.
|
|
30
|
+
*/
|
|
27
31
|
name: string
|
|
28
|
-
/**
|
|
32
|
+
/**
|
|
33
|
+
* Resolver's placetype taxonomy label (e.g. WOF's `country` / `region` / `locality`).
|
|
34
|
+
*/
|
|
29
35
|
placetype: string
|
|
30
|
-
/**
|
|
36
|
+
/**
|
|
37
|
+
* ISO 3166-1 alpha-2 country code, if known.
|
|
38
|
+
*/
|
|
31
39
|
country: string
|
|
32
|
-
/**
|
|
40
|
+
/**
|
|
41
|
+
* Centroid latitude in WGS-84 decimal degrees.
|
|
42
|
+
*/
|
|
33
43
|
lat: number
|
|
34
|
-
/**
|
|
44
|
+
/**
|
|
45
|
+
* Centroid longitude in WGS-84 decimal degrees.
|
|
46
|
+
*/
|
|
35
47
|
lon: number
|
|
36
|
-
/**
|
|
48
|
+
/**
|
|
49
|
+
* Parent place id within the resolver's hierarchy, if any.
|
|
50
|
+
*/
|
|
37
51
|
parent_id?: number | string
|
|
38
52
|
/**
|
|
39
53
|
* Resolver-defined ranking score. Higher = better fit for the query. Scale is implementation- defined; callers should
|
|
@@ -93,7 +107,9 @@ export interface ResolvedPlace {
|
|
|
93
107
|
* negative result is a first-class record, distinguishable from ignorance.
|
|
94
108
|
*/
|
|
95
109
|
export interface CountryCoverageFact {
|
|
96
|
-
/**
|
|
110
|
+
/**
|
|
111
|
+
* ISO 3166-1 alpha-2, uppercase.
|
|
112
|
+
*/
|
|
97
113
|
country: string
|
|
98
114
|
/**
|
|
99
115
|
* The promote-gate VERDICT: hard-filtering this country is a pure win (a hard-filter miss is almost always a genuine
|
|
@@ -102,25 +118,39 @@ export interface CountryCoverageFact {
|
|
|
102
118
|
* postcode-format-prior rationale despite a sub-95% panel resolve rate).
|
|
103
119
|
*/
|
|
104
120
|
hardFilterSafe: boolean
|
|
105
|
-
/**
|
|
121
|
+
/**
|
|
122
|
+
* Measured hard-resolve rate (0..1) on the panel named in `source`, when the receipt recorded one.
|
|
123
|
+
*/
|
|
106
124
|
hardResolveRate?: number
|
|
107
|
-
/**
|
|
125
|
+
/**
|
|
126
|
+
* Panel size behind `hardResolveRate`, when recorded.
|
|
127
|
+
*/
|
|
108
128
|
sampleSize?: number
|
|
109
|
-
/**
|
|
129
|
+
/**
|
|
130
|
+
* ISO-8601 date of the measurement / promote gate.
|
|
131
|
+
*/
|
|
110
132
|
measuredAt: string
|
|
111
|
-
/**
|
|
133
|
+
/**
|
|
134
|
+
* The receipt: which panel/gate produced this row (issue + date, human-readable).
|
|
135
|
+
*/
|
|
112
136
|
source: string
|
|
113
137
|
}
|
|
114
138
|
|
|
115
|
-
/**
|
|
139
|
+
/**
|
|
140
|
+
* One country's coarse guard-B bounding box, as carried by the gazetteer artifact's `country_bbox` table.
|
|
141
|
+
*/
|
|
116
142
|
export interface CountryBBoxFact {
|
|
117
|
-
/**
|
|
143
|
+
/**
|
|
144
|
+
* ISO 3166-1 alpha-2, uppercase.
|
|
145
|
+
*/
|
|
118
146
|
country: string
|
|
119
147
|
latMin: number
|
|
120
148
|
latMax: number
|
|
121
149
|
lonMin: number
|
|
122
150
|
lonMax: number
|
|
123
|
-
/**
|
|
151
|
+
/**
|
|
152
|
+
* Provenance of the box (harness + date).
|
|
153
|
+
*/
|
|
124
154
|
source: string
|
|
125
155
|
}
|
|
126
156
|
|
|
@@ -131,15 +161,23 @@ export interface CountryBBoxFact {
|
|
|
131
161
|
* the code constants (byte-identical legacy behavior).
|
|
132
162
|
*/
|
|
133
163
|
export interface GazetteerArtifactCoverage {
|
|
134
|
-
/**
|
|
164
|
+
/**
|
|
165
|
+
* Country → measured coverage fact. ABSENCE = never measured (meaning-of-zero), never "failed".
|
|
166
|
+
*/
|
|
135
167
|
countryCoverage: ReadonlyMap<string, CountryCoverageFact>
|
|
136
|
-
/**
|
|
168
|
+
/**
|
|
169
|
+
* Country → guard-B bbox. ABSENCE = no box → the plausibility guard fails open for that country.
|
|
170
|
+
*/
|
|
137
171
|
countryBBoxes: ReadonlyMap<string, CountryBBoxFact>
|
|
138
|
-
/**
|
|
172
|
+
/**
|
|
173
|
+
* Derived at load: the countries whose fact says `hardFilterSafe` — the artifact's hard-country safelist.
|
|
174
|
+
*/
|
|
139
175
|
hardCountrySafelist: ReadonlySet<string>
|
|
140
176
|
}
|
|
141
177
|
|
|
142
|
-
/**
|
|
178
|
+
/**
|
|
179
|
+
* Derive the hard-country safelist from coverage facts — the ONE derivation both the reader and the build share.
|
|
180
|
+
*/
|
|
143
181
|
export function hardCountrySafelistFromCoverage(facts: Iterable<CountryCoverageFact>): ReadonlySet<string> {
|
|
144
182
|
const out = new Set<string>()
|
|
145
183
|
|
|
@@ -164,7 +202,9 @@ export interface ResolverBackend {
|
|
|
164
202
|
* recovering localities the name-match alone misses. Backends without postcode support ignore it.
|
|
165
203
|
*/
|
|
166
204
|
postcode?: string
|
|
167
|
-
/**
|
|
205
|
+
/**
|
|
206
|
+
* Proximity-bias points — a SOFT prominence re-rank; backends without support ignore it.
|
|
207
|
+
*/
|
|
168
208
|
bias?: Array<{ lat: number; lon: number; weight?: number }>
|
|
169
209
|
limit?: number
|
|
170
210
|
}): Promise<ResolvedPlace[]>
|
|
@@ -189,7 +229,9 @@ export interface ResolverBackend {
|
|
|
189
229
|
artifactCoverage?: GazetteerArtifactCoverage
|
|
190
230
|
}
|
|
191
231
|
|
|
192
|
-
/**
|
|
232
|
+
/**
|
|
233
|
+
* One link in a resolved place's containment lineage ({@link ResolverBackend.ancestors}, #404).
|
|
234
|
+
*/
|
|
193
235
|
export interface Ancestor {
|
|
194
236
|
id: number | string
|
|
195
237
|
placetype: string
|
|
@@ -205,9 +247,13 @@ export interface CoincidentLocality extends ResolvedPlace {
|
|
|
205
247
|
* `city-state` / `capital-seat` / `consolidated-county` — surfaced as `metadata.relationship_type`.
|
|
206
248
|
*/
|
|
207
249
|
relationshipType: string
|
|
208
|
-
/**
|
|
250
|
+
/**
|
|
251
|
+
* Locality population (0 when unknown) — the PRIMARY disambiguator when an admin has several.
|
|
252
|
+
*/
|
|
209
253
|
population: number
|
|
210
|
-
/**
|
|
254
|
+
/**
|
|
255
|
+
* Centroid distance (km) admin↔locality from the relation — the population tiebreak.
|
|
256
|
+
*/
|
|
211
257
|
distanceKm: number
|
|
212
258
|
}
|
|
213
259
|
|
|
@@ -221,9 +267,13 @@ export interface CoincidentLocality extends ResolvedPlace {
|
|
|
221
267
|
export interface AddressPointHit {
|
|
222
268
|
lat: number
|
|
223
269
|
lon: number
|
|
224
|
-
/**
|
|
270
|
+
/**
|
|
271
|
+
* Provenance, e.g. `"overture:NAD"`.
|
|
272
|
+
*/
|
|
225
273
|
source: string
|
|
226
|
-
/**
|
|
274
|
+
/**
|
|
275
|
+
* Pinned data release the point came from, e.g. `"2026-05-20.0"`.
|
|
276
|
+
*/
|
|
227
277
|
release: string
|
|
228
278
|
}
|
|
229
279
|
|
|
@@ -261,11 +311,17 @@ export interface InterpolatedPointHit {
|
|
|
261
311
|
* `address_point` = bracketed between real neighbor points; `tiger_range` = linear within a segment range.
|
|
262
312
|
*/
|
|
263
313
|
method: "address_point" | "tiger_range"
|
|
264
|
-
/**
|
|
314
|
+
/**
|
|
315
|
+
* False when only the opposite side's range contained the number (right block, wrong side).
|
|
316
|
+
*/
|
|
265
317
|
parityMatched?: boolean
|
|
266
|
-
/**
|
|
318
|
+
/**
|
|
319
|
+
* `both` = neighbors bracketed it; `single` = one-sided extrapolation (larger uncertainty).
|
|
320
|
+
*/
|
|
267
321
|
bracket?: "both" | "single"
|
|
268
|
-
/**
|
|
322
|
+
/**
|
|
323
|
+
* Honest uncertainty radius in METERS (half the matched segment length).
|
|
324
|
+
*/
|
|
269
325
|
uncertaintyM: number
|
|
270
326
|
source: string
|
|
271
327
|
release: string
|
|
@@ -301,7 +357,9 @@ export interface InterpolationLookup {
|
|
|
301
357
|
export interface StreetCentroidHit {
|
|
302
358
|
lat: number
|
|
303
359
|
lon: number
|
|
304
|
-
/**
|
|
360
|
+
/**
|
|
361
|
+
* Honest coarse radius in METERS — half the street's bounding-box diagonal.
|
|
362
|
+
*/
|
|
305
363
|
uncertaintyM: number
|
|
306
364
|
source: string
|
|
307
365
|
release: string
|
|
@@ -541,7 +599,9 @@ export interface ResolveOpts {
|
|
|
541
599
|
*/
|
|
542
600
|
adminCoherence?: boolean
|
|
543
601
|
hierarchyCompletion?: boolean
|
|
544
|
-
/**
|
|
602
|
+
/**
|
|
603
|
+
* @deprecated Renamed to {@link hierarchyCompletion} (#405 generalized #387). Still honored.
|
|
604
|
+
*/
|
|
545
605
|
cityStateFallback?: boolean
|
|
546
606
|
/**
|
|
547
607
|
* Attach each resolved node's ancestor lineage (#404) — the containment chain (county → region → country) the
|
|
@@ -567,6 +627,10 @@ export interface ResolveOpts {
|
|
|
567
627
|
*/
|
|
568
628
|
export type PlacetypeMap = Partial<Record<ComponentTag, string>>
|
|
569
629
|
|
|
630
|
+
/**
|
|
631
|
+
* Placetype equivalences applied when a backend does not supply its own. A `locality` query must also reach `borough`
|
|
632
|
+
* and `localadmin` rows — Brooklyn is a borough, and a strict filter made it unreachable.
|
|
633
|
+
*/
|
|
570
634
|
export const DEFAULT_PLACETYPE_MAP: PlacetypeMap = {
|
|
571
635
|
country: "country",
|
|
572
636
|
region: "region",
|
|
@@ -620,6 +684,7 @@ export const PLACETYPE_FILTER_GROUPS: Readonly<Record<string, readonly string[]>
|
|
|
620
684
|
export function expandPlacetypeFilter(placetypes: null): null
|
|
621
685
|
export function expandPlacetypeFilter(placetypes: readonly string[]): string[]
|
|
622
686
|
export function expandPlacetypeFilter(placetypes: readonly string[] | null): string[] | null
|
|
687
|
+
|
|
623
688
|
export function expandPlacetypeFilter(placetypes: readonly string[] | null): string[] | null {
|
|
624
689
|
if (!placetypes) return null
|
|
625
690
|
const out: string[] = []
|
package/resources/LocaleIndex.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import { TextNormalizer } from "../tokenization/normalizer.ts"
|
|
7
|
+
import type { TextNormalizer } from "../tokenization/normalizer.ts"
|
|
8
8
|
import type { Displayable } from "./debugging.ts"
|
|
9
9
|
|
|
10
10
|
/**
|
|
@@ -49,7 +49,7 @@ export class LocaleIndex<LanguageCodes extends string> extends Map<string, Set<L
|
|
|
49
49
|
* @param languageCodes The language codes to associate with the placename.
|
|
50
50
|
*/
|
|
51
51
|
public add(placename: string, ...languageCodes: LanguageCodes[]): void {
|
|
52
|
-
if (languageCodes.length
|
|
52
|
+
if (!languageCodes.length) {
|
|
53
53
|
throw new Error(`At least one language code must be provided for "${placename}".`)
|
|
54
54
|
}
|
|
55
55
|
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
export type DisposableLike = Disposable | AsyncDisposable
|
|
11
11
|
|
|
12
12
|
export type ResourceConstructor<K extends PropertyKey, R extends DisposableLike> = new (key: K) => R
|
|
13
|
+
|
|
13
14
|
export type ResourceFactory<K extends PropertyKey, R extends DisposableLike> = (key: K) => R | Promise<R>
|
|
14
15
|
|
|
15
16
|
export type ResourceFactoryLike<K extends PropertyKey = PropertyKey, R extends DisposableLike = DisposableLike> =
|
|
@@ -58,7 +59,7 @@ export class ResourceMapCache<
|
|
|
58
59
|
/**
|
|
59
60
|
* The human-readable name of the resource.
|
|
60
61
|
*/
|
|
61
|
-
public displayName
|
|
62
|
+
public displayName = "ResourceMapCache"
|
|
62
63
|
|
|
63
64
|
protected readonly factoryLike: F
|
|
64
65
|
|
|
@@ -115,7 +116,7 @@ export class ResourceMapCache<
|
|
|
115
116
|
}
|
|
116
117
|
|
|
117
118
|
public async [Symbol.asyncDispose]() {
|
|
118
|
-
const resourceKeys = Array.from(super.keys()).
|
|
119
|
+
const resourceKeys = Array.from(super.keys()).toReversed()
|
|
119
120
|
|
|
120
121
|
for (const resourceKey of resourceKeys) {
|
|
121
122
|
this.close(resourceKey)
|
package/resources/collections.ts
CHANGED
|
@@ -27,6 +27,7 @@ export async function* takeInParallel<T, C extends (entry: T) => Promise<unknown
|
|
|
27
27
|
|
|
28
28
|
let iterationResult = await iterator.next()
|
|
29
29
|
|
|
30
|
+
// oxlint-disable-next-line eslint/no-unmodified-loop-condition -- `abortSignal.aborted` is flipped by the controller, not by this loop
|
|
30
31
|
while ((!iterationResult.done || results.size) && !abortSignal?.aborted) {
|
|
31
32
|
for (const [key, result] of results) {
|
|
32
33
|
yield result
|
|
@@ -36,6 +37,7 @@ export async function* takeInParallel<T, C extends (entry: T) => Promise<unknown
|
|
|
36
37
|
|
|
37
38
|
if (runningTasks.size >= batchSize) {
|
|
38
39
|
await Promise.race(runningTasks.values())
|
|
40
|
+
|
|
39
41
|
continue
|
|
40
42
|
}
|
|
41
43
|
|
|
@@ -47,6 +49,7 @@ export async function* takeInParallel<T, C extends (entry: T) => Promise<unknown
|
|
|
47
49
|
|
|
48
50
|
const entry = iterationResult.value
|
|
49
51
|
|
|
52
|
+
// oxlint-disable-next-line promise/always-return -- the handle tracks completion, not a value
|
|
50
53
|
const futureResult = callback(entry).then((result) => {
|
|
51
54
|
runningTasks.delete(entry)
|
|
52
55
|
|
|
@@ -87,7 +90,7 @@ export async function* takeAsync<T>(collection: AsyncIterable<T>, batchSize: num
|
|
|
87
90
|
}
|
|
88
91
|
}
|
|
89
92
|
|
|
90
|
-
if (buffer.length
|
|
93
|
+
if (buffer.length) {
|
|
91
94
|
yield buffer
|
|
92
95
|
}
|
|
93
96
|
}
|
|
@@ -4,9 +4,10 @@
|
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
export * from "./types.gen.ts"
|
|
8
7
|
import { Alpha2LabelMap, Alpha2LanguageCode, Alpha3bLabelMap, type Alpha3bLanguageCode } from "./types.gen.ts"
|
|
9
8
|
|
|
9
|
+
export * from "./types.gen.ts"
|
|
10
|
+
|
|
10
11
|
/**
|
|
11
12
|
* Prefixed languages are those which use a street prefix instead of a suffix.
|
|
12
13
|
*/
|
package/resources/libpostal.ts
CHANGED
|
@@ -8,9 +8,9 @@ import { readdir } from "node:fs/promises"
|
|
|
8
8
|
import { availableParallelism } from "node:os"
|
|
9
9
|
|
|
10
10
|
import { tryStat } from "@mailwoman/core/fs"
|
|
11
|
-
import { Alpha2LanguageCode } from "@mailwoman/core/resources/languages"
|
|
11
|
+
import type { Alpha2LanguageCode } from "@mailwoman/core/resources/languages"
|
|
12
12
|
import { TextNormalizer, type TextNormalizerInit } from "@mailwoman/core/tokenization"
|
|
13
|
-
import { PathBuilder } from "path-ts"
|
|
13
|
+
import type { PathBuilder } from "path-ts"
|
|
14
14
|
import pluralize from "pluralize"
|
|
15
15
|
import { TextSpliterator } from "spliterator"
|
|
16
16
|
|
|
@@ -94,6 +94,7 @@ export async function prepareLocaleIndex(
|
|
|
94
94
|
options?: LibPostalNormalizerInit
|
|
95
95
|
): Promise<LocaleIndex<LibPostalLanguageCode>> {
|
|
96
96
|
const normalizer = new TextNormalizer(options)
|
|
97
|
+
|
|
97
98
|
const index = new LocaleIndex<LibPostalLanguageCode>([], {
|
|
98
99
|
displayName: "libpostal",
|
|
99
100
|
normalizer,
|
|
@@ -107,6 +108,7 @@ export async function prepareLocaleIndex(
|
|
|
107
108
|
|
|
108
109
|
for await (const batch of fileEntries) {
|
|
109
110
|
await Promise.all(
|
|
111
|
+
// oxlint-disable-next-line no-loop-func -- the binding is per-iteration (for-of/for-await) and the batch is awaited before the next
|
|
110
112
|
batch.map(async ({ filePath, languageCode }) => {
|
|
111
113
|
const lines = TextSpliterator.fromAsync(filePath)
|
|
112
114
|
|
|
@@ -127,6 +129,7 @@ export async function prepareLocaleIndex(
|
|
|
127
129
|
|
|
128
130
|
for await (const batch of internalFileEntries) {
|
|
129
131
|
await Promise.all(
|
|
132
|
+
// oxlint-disable-next-line no-loop-func -- the binding is per-iteration (for-of/for-await) and the batch is awaited before the next
|
|
130
133
|
batch.map(async ({ filePath, languageCode }) => {
|
|
131
134
|
const lines = TextSpliterator.fromAsync(filePath)
|
|
132
135
|
|
|
@@ -155,7 +158,7 @@ export async function prepareLocaleIndex(
|
|
|
155
158
|
)
|
|
156
159
|
}
|
|
157
160
|
|
|
158
|
-
if (index.size
|
|
161
|
+
if (!index.size && !inserted) {
|
|
159
162
|
throw new Error(
|
|
160
163
|
`No index matches found for ${filename} in ${libPostalDataDirectory} for languages ${languageCodes}`
|
|
161
164
|
)
|
package/resources/set.ts
CHANGED
|
@@ -29,7 +29,7 @@ export class Sequence<T extends WeakKey> extends Set<T> {
|
|
|
29
29
|
super(nodes)
|
|
30
30
|
|
|
31
31
|
this.#first = nodes[0] ?? null
|
|
32
|
-
this.#last = nodes
|
|
32
|
+
this.#last = nodes.at(-1) ?? null
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
/**
|
|
@@ -49,7 +49,7 @@ export class Sequence<T extends WeakKey> extends Set<T> {
|
|
|
49
49
|
if (!nodes.length) return this
|
|
50
50
|
|
|
51
51
|
for (const node of nodes) {
|
|
52
|
-
if (
|
|
52
|
+
if (node === undefined || node === null) {
|
|
53
53
|
throw new Error("Attempted to add an undefined or null node to a sequence.")
|
|
54
54
|
}
|
|
55
55
|
|
|
@@ -60,7 +60,7 @@ export class Sequence<T extends WeakKey> extends Set<T> {
|
|
|
60
60
|
this.#first = nodes[0]!
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
this.#last = nodes
|
|
63
|
+
this.#last = nodes.at(-1)!
|
|
64
64
|
|
|
65
65
|
return this
|
|
66
66
|
}
|
|
@@ -69,7 +69,7 @@ export class Sequence<T extends WeakKey> extends Set<T> {
|
|
|
69
69
|
* Delete a node from the sequence.
|
|
70
70
|
*/
|
|
71
71
|
public override delete(node: T): boolean {
|
|
72
|
-
if (
|
|
72
|
+
if (node === undefined || node === null) {
|
|
73
73
|
throw new Error("Attempted to delete an undefined or null node from a sequence.")
|
|
74
74
|
}
|
|
75
75
|
|
|
@@ -77,7 +77,7 @@ export class Sequence<T extends WeakKey> extends Set<T> {
|
|
|
77
77
|
|
|
78
78
|
if (!deleted) return false
|
|
79
79
|
|
|
80
|
-
if (this.size
|
|
80
|
+
if (!this.size) {
|
|
81
81
|
this.#first = null
|
|
82
82
|
this.#last = null
|
|
83
83
|
} else if (this.#first === node) {
|
|
@@ -104,7 +104,7 @@ export class Sequence<T extends WeakKey> extends Set<T> {
|
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
this.#first = currentEntries[0] ?? null
|
|
107
|
-
this.#last = currentEntries
|
|
107
|
+
this.#last = currentEntries.at(-1) ?? null
|
|
108
108
|
|
|
109
109
|
return this
|
|
110
110
|
}
|
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import { mkdirSync } from "node:fs"
|
|
8
|
-
import { setTimeout } from "node:timers/promises"
|
|
9
8
|
|
|
10
9
|
import type { Alpha3bLanguageCode } from "@mailwoman/core/resources/languages"
|
|
11
10
|
import { dirname } from "path-ts"
|
|
@@ -13,6 +12,8 @@ import { dirname } from "path-ts"
|
|
|
13
12
|
import { PlacetypeDataSource, type PlacetypeDataSourceOptions } from "./PlacetypeDataSource.ts"
|
|
14
13
|
import type { WhosOnFirstPlacetype } from "./placetypes/definition.ts"
|
|
15
14
|
|
|
15
|
+
export { tryWithBackoff } from "./backoff.ts"
|
|
16
|
+
|
|
16
17
|
export class DataSourceCache extends DisposableStack {
|
|
17
18
|
#placetypeToLanguage = new Map<WhosOnFirstPlacetype, Map<Alpha3bLanguageCode, PlacetypeDataSource>>()
|
|
18
19
|
|
|
@@ -47,26 +48,3 @@ export class DataSourceCache extends DisposableStack {
|
|
|
47
48
|
return dataSource
|
|
48
49
|
}
|
|
49
50
|
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Given a callback, attempt to run it up to `attempts` times.
|
|
53
|
-
*/
|
|
54
|
-
export async function tryWithBackoff<T>(attempts: number, callback: () => T): Promise<T> {
|
|
55
|
-
let lastError: unknown
|
|
56
|
-
|
|
57
|
-
for (let i = 0; i < attempts; i++) {
|
|
58
|
-
try {
|
|
59
|
-
const result = await callback()
|
|
60
|
-
|
|
61
|
-
return result
|
|
62
|
-
} catch (error) {
|
|
63
|
-
lastError = error
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// We try to avoid contention by giving a pause between attempts.
|
|
67
|
-
const delay = Math.floor(Math.random() * 1000) + 1000 * attempts
|
|
68
|
-
await setTimeout(delay)
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
throw lastError
|
|
72
|
-
}
|
|
@@ -7,14 +7,14 @@
|
|
|
7
7
|
import { DatabaseSync, type DatabaseSyncOptions, type SQLInputValue } from "node:sqlite"
|
|
8
8
|
|
|
9
9
|
import {
|
|
10
|
-
Alpha2LanguageCode,
|
|
10
|
+
type Alpha2LanguageCode,
|
|
11
11
|
type Alpha3bLanguageCode,
|
|
12
12
|
Alpha3bToAlpha2,
|
|
13
13
|
isAlpha3bLanguageCode,
|
|
14
14
|
} from "@mailwoman/core/resources/languages"
|
|
15
15
|
import { PathBuilder, type PathBuilderLike } from "path-ts"
|
|
16
16
|
|
|
17
|
-
import { tryWithBackoff } from "./
|
|
17
|
+
import { tryWithBackoff } from "./backoff.ts"
|
|
18
18
|
import type { WhosOnFirstPlacetype } from "./placetypes/definition.ts"
|
|
19
19
|
|
|
20
20
|
export interface PlacetypeDataSourceOptions<
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
* @file Retry-with-backoff helper for the Who's On First data sources.
|
|
6
|
+
*
|
|
7
|
+
* This lives apart from `DataSourceCache` because both that module and `PlacetypeDataSource` need
|
|
8
|
+
* it, and each already imports the other — putting it in either one closes an import cycle.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { setTimeout } from "node:timers/promises"
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Given a callback, attempt to run it up to `attempts` times.
|
|
15
|
+
*
|
|
16
|
+
* @param attempts Maximum number of tries before the last error is rethrown.
|
|
17
|
+
* @param callback The operation to attempt.
|
|
18
|
+
*
|
|
19
|
+
* @returns The callback's result from the first successful attempt.
|
|
20
|
+
*/
|
|
21
|
+
export async function tryWithBackoff<T>(attempts: number, callback: () => T): Promise<T> {
|
|
22
|
+
let lastError: unknown
|
|
23
|
+
|
|
24
|
+
for (let i = 0; i < attempts; i++) {
|
|
25
|
+
try {
|
|
26
|
+
const result = await callback()
|
|
27
|
+
|
|
28
|
+
return result
|
|
29
|
+
} catch (error) {
|
|
30
|
+
lastError = error
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// We try to avoid contention by giving a pause between attempts.
|
|
34
|
+
const delay = Math.floor(Math.random() * 1000) + 1000 * attempts
|
|
35
|
+
await setTimeout(delay)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
throw lastError
|
|
39
|
+
}
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import type { Alpha3bLanguageCode } from "@mailwoman/core/resources/languages"
|
|
8
|
-
import { TextNormalizer } from "@mailwoman/core/tokenization"
|
|
8
|
+
import type { TextNormalizer } from "@mailwoman/core/tokenization"
|
|
9
9
|
import FastGlob, { type Entry } from "fast-glob"
|
|
10
10
|
import { PathBuilder, type PathBuilderLike } from "path-ts"
|
|
11
11
|
import { TextSpliterator } from "spliterator"
|
|
@@ -21,6 +21,7 @@ import { parsePlacetypeSource } from "./placetypes/admin.ts"
|
|
|
21
21
|
* If a value is present in this index, it means that the value is a valid value in at least one language.
|
|
22
22
|
*/
|
|
23
23
|
export type WhosOnFirstLocaleIndex = Map<string, Set<string>>
|
|
24
|
+
|
|
24
25
|
export type ReadonlyWhosOnFirstIndex = ReadonlyMap<string, ReadonlySet<string>>
|
|
25
26
|
|
|
26
27
|
export interface WOFCacheOptions {
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
import * as fs from "node:fs/promises"
|
|
8
8
|
|
|
9
9
|
import FastGlob from "fast-glob"
|
|
10
|
-
import { PathBuilder } from "path-ts"
|
|
10
|
+
import type { PathBuilder } from "path-ts"
|
|
11
11
|
|
|
12
12
|
import { takeInParallel } from "../../collections.ts"
|
|
13
13
|
import { prepareRepositoryDirectories, type RepositorySource } from "../../git.ts"
|
|
@@ -19,6 +19,9 @@ import {
|
|
|
19
19
|
PlacetypeRoleOrder,
|
|
20
20
|
} from "./definition.ts"
|
|
21
21
|
|
|
22
|
+
/**
|
|
23
|
+
* Upstream Who's On First placetypes repository the local definitions are generated from.
|
|
24
|
+
*/
|
|
22
25
|
export const PLACETYPES_REPO_SOURCE = {
|
|
23
26
|
url: "https://github.com/whosonfirst/whosonfirst-placetypes.git",
|
|
24
27
|
owner: "whosonfirst",
|
|
@@ -243,7 +246,7 @@ export class Placetype implements Disposable {
|
|
|
243
246
|
|
|
244
247
|
this.#collectAncestors(ancestorsContext, roleFilters)
|
|
245
248
|
|
|
246
|
-
return Array.from(ancestorsContext).
|
|
249
|
+
return Array.from(ancestorsContext).toSorted(Placetype.comparatorAsc)
|
|
247
250
|
}
|
|
248
251
|
|
|
249
252
|
#collectAncestors(ancestorsContext: Set<Placetype>, roleFilters?: Set<PlacetypeRole> | null): void {
|
|
@@ -271,7 +274,7 @@ export class Placetype implements Disposable {
|
|
|
271
274
|
validChildren.push(child)
|
|
272
275
|
}
|
|
273
276
|
|
|
274
|
-
return validChildren.
|
|
277
|
+
return validChildren.toSorted(Placetype.comparatorAsc)
|
|
275
278
|
}
|
|
276
279
|
|
|
277
280
|
/**
|
|
@@ -289,7 +292,7 @@ export class Placetype implements Disposable {
|
|
|
289
292
|
validParents.push(parent)
|
|
290
293
|
}
|
|
291
294
|
|
|
292
|
-
return validParents.
|
|
295
|
+
return validParents.toSorted(Placetype.comparatorDesc)
|
|
293
296
|
}
|
|
294
297
|
|
|
295
298
|
/**
|
|
@@ -304,7 +307,7 @@ export class Placetype implements Disposable {
|
|
|
304
307
|
return validSiblings.filter((sibling) => roleFilters.has(sibling.role))
|
|
305
308
|
}
|
|
306
309
|
|
|
307
|
-
return validSiblings.
|
|
310
|
+
return validSiblings.toSorted((a, b) => {
|
|
308
311
|
return PlacetypeRoleOrder[a.role] - PlacetypeRoleOrder[b.role]
|
|
309
312
|
})
|
|
310
313
|
}
|
|
@@ -320,7 +323,7 @@ export class Placetype implements Disposable {
|
|
|
320
323
|
|
|
321
324
|
this.#collectDescendants(descendantsContext, roleFilters)
|
|
322
325
|
|
|
323
|
-
return Array.from(descendantsContext).
|
|
326
|
+
return Array.from(descendantsContext).toSorted(Placetype.comparatorAsc)
|
|
324
327
|
}
|
|
325
328
|
|
|
326
329
|
#collectDescendants(descendantsContext: Set<Placetype>, roleFilters?: Set<PlacetypeRole> | null): void {
|