@mailwoman/resolver-wof-sqlite 11.0.0 → 11.1.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/lib/address/duplicate.ts +133 -0
- package/lib/address/keys/attribution.ts +119 -0
- package/lib/address/keys/build.ts +768 -0
- package/lib/address/keys/layout.ts +166 -0
- package/lib/address/keys/local-runner.ts +18 -0
- package/lib/address/keys/lookup.ts +205 -0
- package/lib/address/keys/open.ts +33 -0
- package/lib/address/keys/point-lookup.ts +130 -0
- package/lib/address/keys/postcode.ts +27 -0
- package/lib/address/keys/schema.ts +264 -0
- package/lib/address/number-forms.ts +61 -0
- package/lib/address/point/interpolation.ts +28 -23
- package/lib/address/point/schema.ts +2 -5
- package/lib/address/point/spine-schema.ts +4 -4
- package/lib/address/point.ts +12 -79
- package/lib/address/record.ts +155 -0
- package/lib/address/stack.ts +20 -0
- package/lib/address/subdivision-bounds.ts +81 -0
- package/lib/address.ts +2 -5
- package/lib/ancestry/backfill.ts +5 -4
- package/lib/ancestry.ts +10 -10
- package/lib/build/candidate.ts +2 -46
- package/lib/build/population-corrections.ts +4 -4
- package/lib/build/slim.ts +3 -6
- package/lib/candidate/alias-bags.ts +4 -4
- package/lib/candidate/ancestors/schema.ts +63 -43
- package/lib/candidate/ancestors/sidecar.ts +3 -3
- package/lib/candidate/bare-admin-names.ts +3 -3
- package/lib/candidate/country-display-names.ts +2 -5
- package/lib/candidate/extract-fold.ts +2 -5
- package/lib/candidate/fts.ts +5 -5
- package/lib/candidate/importance.ts +29 -24
- package/lib/candidate/lookup.ts +2 -5
- package/lib/candidate/name-roles.ts +4 -4
- package/lib/candidate/own-name.ts +12 -10
- package/lib/candidate/place-attrs.ts +4 -4
- package/lib/candidate/schema.ts +2 -5
- package/lib/candidate/scoring.ts +3 -6
- package/lib/capital-schema.ts +11 -10
- package/lib/capitals.ts +15 -12
- package/lib/convention/schema.ts +7 -7
- package/lib/convention.ts +3 -3
- package/lib/coverage-manifest-schema.ts +4 -4
- package/lib/env.ts +7 -6
- package/lib/exact-match.ts +6 -7
- package/lib/extracts.ts +11 -9
- package/lib/fst/autocomplete.ts +19 -15
- package/lib/fst/binary-matcher.ts +10 -9
- package/lib/fst/builder.ts +32 -11
- package/lib/fst/deserialize-web.ts +9 -8
- package/lib/fst/format.ts +9 -7
- package/lib/fst/freshness.ts +3 -4
- package/lib/fst/matcher.ts +6 -6
- package/lib/fst/serialize.ts +5 -9
- package/lib/fst/types.ts +4 -4
- package/lib/fst.ts +2 -5
- package/lib/fts/query.ts +3 -4
- package/lib/fts.ts +2 -5
- package/lib/geonames/aliases.ts +193 -43
- package/lib/geonames/postal.ts +17 -15
- package/lib/geonames.ts +2 -5
- package/lib/index.ts +4 -5
- package/lib/interpolation.ts +7 -6
- package/lib/landmark/rows.ts +5 -5
- package/lib/landmark.ts +6 -6
- package/lib/lookup.ts +8 -8
- package/lib/name-score.ts +7 -6
- package/lib/nsul/lookup.ts +19 -15
- package/lib/nsul/schema.ts +4 -5
- package/lib/nsul.ts +2 -5
- package/lib/paths.ts +7 -7
- package/lib/place-importance-schema.ts +5 -8
- package/lib/poi/lookup.ts +11 -10
- package/lib/poi/schema.ts +16 -10
- package/lib/poi.ts +2 -5
- package/lib/polygon-schema.ts +10 -9
- package/lib/postal/city/alias/lookup.ts +14 -13
- package/lib/postal/city/alias/schema.ts +12 -12
- package/lib/postal/city/candidate-schema.ts +15 -12
- package/lib/postal.ts +2 -5
- package/lib/postcode-point-lookup.ts +2 -5
- package/lib/primary-preference.ts +2 -5
- package/lib/proximity-rerank.ts +23 -19
- package/lib/ranking-weights.ts +8 -7
- package/lib/region-keys.ts +15 -14
- package/lib/reverse.ts +16 -17
- package/lib/schema.ts +20 -6
- package/lib/search-fetch.ts +15 -11
- package/lib/sqlite/convention-source.ts +2 -5
- package/lib/sqlite/utils.ts +4 -4
- package/lib/street/centroid/schema.ts +6 -6
- package/lib/street/centroid.ts +3 -3
- package/lib/street/locale.ts +64 -0
- package/lib/street/morphology/fst/builder.ts +21 -19
- package/lib/street/morphology/fst/loader.ts +15 -13
- package/lib/street/name-lookup.ts +15 -14
- package/lib/street/normalize.ts +20 -17
- package/lib/street/segment-schema.ts +16 -14
- package/lib/street/table.ts +276 -0
- package/lib/street.ts +3 -5
- package/lib/types.ts +3 -6
- package/lib/unified-schema.ts +31 -9
- package/lib/uprn/existence.ts +10 -10
- package/lib/uprn/lookup.ts +7 -8
- package/lib/uprn/schema.ts +5 -5
- package/lib/uprn.ts +2 -5
- package/lib/weights-overlay-linker.ts +5 -8
- package/out/address/duplicate.d.ts +74 -0
- package/out/address/duplicate.d.ts.map +1 -0
- package/out/address/duplicate.js +79 -0
- package/out/address/duplicate.js.map +1 -0
- package/out/address/keys/attribution.d.ts +56 -0
- package/out/address/keys/attribution.d.ts.map +1 -0
- package/out/address/keys/attribution.js +64 -0
- package/out/address/keys/attribution.js.map +1 -0
- package/out/address/keys/build.d.ts +154 -0
- package/out/address/keys/build.d.ts.map +1 -0
- package/out/address/keys/build.js +423 -0
- package/out/address/keys/build.js.map +1 -0
- package/out/address/keys/layout.d.ts +92 -0
- package/out/address/keys/layout.d.ts.map +1 -0
- package/out/address/keys/layout.js +87 -0
- package/out/address/keys/layout.js.map +1 -0
- package/out/address/keys/local-runner.d.ts +9 -0
- package/out/address/keys/local-runner.d.ts.map +1 -0
- package/out/address/keys/local-runner.js +13 -0
- package/out/address/keys/local-runner.js.map +1 -0
- package/out/address/keys/lookup.d.ts +80 -0
- package/out/address/keys/lookup.d.ts.map +1 -0
- package/out/address/keys/lookup.js +104 -0
- package/out/address/keys/lookup.js.map +1 -0
- package/out/address/keys/open.d.ts +10 -0
- package/out/address/keys/open.d.ts.map +1 -0
- package/out/address/keys/open.js +28 -0
- package/out/address/keys/open.js.map +1 -0
- package/out/address/keys/point-lookup.d.ts +25 -0
- package/out/address/keys/point-lookup.d.ts.map +1 -0
- package/out/address/keys/point-lookup.js +100 -0
- package/out/address/keys/point-lookup.js.map +1 -0
- package/out/address/keys/postcode.d.ts +9 -0
- package/out/address/keys/postcode.d.ts.map +1 -0
- package/out/address/keys/postcode.js +25 -0
- package/out/address/keys/postcode.js.map +1 -0
- package/out/address/keys/schema.d.ts +156 -0
- package/out/address/keys/schema.d.ts.map +1 -0
- package/out/address/keys/schema.js +119 -0
- package/out/address/keys/schema.js.map +1 -0
- package/out/address/number-forms.d.ts +19 -0
- package/out/address/number-forms.d.ts.map +1 -0
- package/out/address/number-forms.js +50 -0
- package/out/address/number-forms.js.map +1 -0
- package/out/address/point/interpolation.d.ts +24 -22
- package/out/address/point/interpolation.d.ts.map +1 -1
- package/out/address/point/interpolation.js +3 -31
- package/out/address/point/interpolation.js.map +1 -1
- package/out/address/point/schema.d.ts +0 -5
- package/out/address/point/schema.d.ts.map +1 -1
- package/out/address/point/schema.js +2 -5
- package/out/address/point/schema.js.map +1 -1
- package/out/address/point/spine-schema.d.ts +1 -4
- package/out/address/point/spine-schema.d.ts.map +1 -1
- package/out/address/point/spine-schema.js +3 -4
- package/out/address/point/spine-schema.js.map +1 -1
- package/out/address/point.d.ts +0 -3
- package/out/address/point.d.ts.map +1 -1
- package/out/address/point.js +12 -71
- package/out/address/point.js.map +1 -1
- package/out/address/record.d.ts +125 -0
- package/out/address/record.d.ts.map +1 -0
- package/out/address/record.js +49 -0
- package/out/address/record.js.map +1 -0
- package/out/address/stack.d.ts +14 -0
- package/out/address/stack.d.ts.map +1 -0
- package/out/address/stack.js +19 -0
- package/out/address/stack.js.map +1 -0
- package/out/address/subdivision-bounds.d.ts +32 -0
- package/out/address/subdivision-bounds.d.ts.map +1 -0
- package/out/address/subdivision-bounds.js +48 -0
- package/out/address/subdivision-bounds.js.map +1 -0
- package/out/address.d.ts +0 -5
- package/out/address.d.ts.map +1 -1
- package/out/address.js +2 -5
- package/out/address.js.map +1 -1
- package/out/ancestry/backfill.d.ts +0 -7
- package/out/ancestry/backfill.d.ts.map +1 -1
- package/out/ancestry/backfill.js +4 -4
- package/out/ancestry/backfill.js.map +1 -1
- package/out/ancestry.d.ts +0 -14
- package/out/ancestry.d.ts.map +1 -1
- package/out/ancestry.js +9 -10
- package/out/ancestry.js.map +1 -1
- package/out/build/candidate.d.ts +0 -22
- package/out/build/candidate.d.ts.map +1 -1
- package/out/build/candidate.js +2 -26
- package/out/build/candidate.js.map +1 -1
- package/out/build/population-corrections.d.ts +1 -4
- package/out/build/population-corrections.d.ts.map +1 -1
- package/out/build/population-corrections.js +2 -19
- package/out/build/population-corrections.js.map +1 -1
- package/out/build/slim.d.ts +0 -5
- package/out/build/slim.d.ts.map +1 -1
- package/out/build/slim.js +3 -6
- package/out/build/slim.js.map +1 -1
- package/out/candidate/alias-bags.d.ts +1 -4
- package/out/candidate/alias-bags.d.ts.map +1 -1
- package/out/candidate/alias-bags.js +3 -7
- package/out/candidate/alias-bags.js.map +1 -1
- package/out/candidate/ancestors/schema.d.ts +60 -43
- package/out/candidate/ancestors/schema.d.ts.map +1 -1
- package/out/candidate/ancestors/schema.js +62 -43
- package/out/candidate/ancestors/schema.js.map +1 -1
- package/out/candidate/ancestors/sidecar.d.ts +0 -3
- package/out/candidate/ancestors/sidecar.d.ts.map +1 -1
- package/out/candidate/ancestors/sidecar.js +2 -6
- package/out/candidate/ancestors/sidecar.js.map +1 -1
- package/out/candidate/bare-admin-names.d.ts +0 -6
- package/out/candidate/bare-admin-names.d.ts.map +1 -1
- package/out/candidate/bare-admin-names.js +2 -3
- package/out/candidate/bare-admin-names.js.map +1 -1
- package/out/candidate/country-display-names.d.ts +0 -5
- package/out/candidate/country-display-names.d.ts.map +1 -1
- package/out/candidate/country-display-names.js +2 -5
- package/out/candidate/country-display-names.js.map +1 -1
- package/out/candidate/extract-fold.d.ts +0 -5
- package/out/candidate/extract-fold.d.ts.map +1 -1
- package/out/candidate/extract-fold.js +2 -5
- package/out/candidate/extract-fold.js.map +1 -1
- package/out/candidate/fts.d.ts +2 -5
- package/out/candidate/fts.d.ts.map +1 -1
- package/out/candidate/fts.js +2 -7
- package/out/candidate/fts.js.map +1 -1
- package/out/candidate/importance.d.ts +3 -33
- package/out/candidate/importance.d.ts.map +1 -1
- package/out/candidate/importance.js +28 -24
- package/out/candidate/importance.js.map +1 -1
- package/out/candidate/lookup.d.ts +0 -5
- package/out/candidate/lookup.d.ts.map +1 -1
- package/out/candidate/lookup.js +2 -5
- package/out/candidate/lookup.js.map +1 -1
- package/out/candidate/name-roles.d.ts +0 -6
- package/out/candidate/name-roles.d.ts.map +1 -1
- package/out/candidate/name-roles.js +3 -4
- package/out/candidate/name-roles.js.map +1 -1
- package/out/candidate/own-name.d.ts +0 -18
- package/out/candidate/own-name.d.ts.map +1 -1
- package/out/candidate/own-name.js +11 -10
- package/out/candidate/own-name.js.map +1 -1
- package/out/candidate/place-attrs.d.ts +1 -4
- package/out/candidate/place-attrs.d.ts.map +1 -1
- package/out/candidate/place-attrs.js +2 -12
- package/out/candidate/place-attrs.js.map +1 -1
- package/out/candidate/schema.d.ts +0 -5
- package/out/candidate/schema.d.ts.map +1 -1
- package/out/candidate/schema.js +2 -5
- package/out/candidate/schema.js.map +1 -1
- package/out/candidate/scoring.d.ts +0 -5
- package/out/candidate/scoring.d.ts.map +1 -1
- package/out/candidate/scoring.js +3 -6
- package/out/candidate/scoring.js.map +1 -1
- package/out/capital-schema.d.ts +0 -14
- package/out/capital-schema.d.ts.map +1 -1
- package/out/capital-schema.js +10 -10
- package/out/capital-schema.js.map +1 -1
- package/out/capitals.d.ts +0 -16
- package/out/capitals.d.ts.map +1 -1
- package/out/capitals.js +14 -12
- package/out/capitals.js.map +1 -1
- package/out/convention/schema.d.ts +4 -7
- package/out/convention/schema.d.ts.map +1 -1
- package/out/convention/schema.js +2 -10
- package/out/convention/schema.js.map +1 -1
- package/out/convention.d.ts +0 -3
- package/out/convention.d.ts.map +1 -1
- package/out/convention.js +2 -8
- package/out/convention.js.map +1 -1
- package/out/coverage-manifest-schema.d.ts +1 -4
- package/out/coverage-manifest-schema.d.ts.map +1 -1
- package/out/coverage-manifest-schema.js +2 -3
- package/out/coverage-manifest-schema.js.map +1 -1
- package/out/env.d.ts +0 -8
- package/out/env.d.ts.map +1 -1
- package/out/env.js +6 -6
- package/out/env.js.map +1 -1
- package/out/exact-match.d.ts +2 -6
- package/out/exact-match.d.ts.map +1 -1
- package/out/exact-match.js +3 -9
- package/out/exact-match.js.map +1 -1
- package/out/extracts.d.ts +8 -9
- package/out/extracts.d.ts.map +1 -1
- package/out/extracts.js +9 -8
- package/out/extracts.js.map +1 -1
- package/out/fst/autocomplete.d.ts +1 -19
- package/out/fst/autocomplete.d.ts.map +1 -1
- package/out/fst/autocomplete.js +2 -18
- package/out/fst/autocomplete.js.map +1 -1
- package/out/fst/binary-matcher.d.ts +6 -8
- package/out/fst/binary-matcher.d.ts.map +1 -1
- package/out/fst/binary-matcher.js +3 -13
- package/out/fst/binary-matcher.js.map +1 -1
- package/out/fst/builder.d.ts +0 -12
- package/out/fst/builder.d.ts.map +1 -1
- package/out/fst/builder.js +23 -11
- package/out/fst/builder.js.map +1 -1
- package/out/fst/deserialize-web.d.ts +1 -12
- package/out/fst/deserialize-web.d.ts.map +1 -1
- package/out/fst/deserialize-web.js +8 -8
- package/out/fst/deserialize-web.js.map +1 -1
- package/out/fst/format.d.ts +6 -7
- package/out/fst/format.d.ts.map +1 -1
- package/out/fst/format.js +3 -10
- package/out/fst/format.js.map +1 -1
- package/out/fst/freshness.d.ts +0 -7
- package/out/fst/freshness.d.ts.map +1 -1
- package/out/fst/freshness.js +2 -4
- package/out/fst/freshness.js.map +1 -1
- package/out/fst/matcher.d.ts +3 -6
- package/out/fst/matcher.d.ts.map +1 -1
- package/out/fst/matcher.js +2 -9
- package/out/fst/matcher.js.map +1 -1
- package/out/fst/serialize.d.ts +0 -23
- package/out/fst/serialize.d.ts.map +1 -1
- package/out/fst/serialize.js +4 -8
- package/out/fst/serialize.js.map +1 -1
- package/out/fst/types.d.ts +1 -4
- package/out/fst/types.d.ts.map +1 -1
- package/out/fst/types.js +2 -6
- package/out/fst/types.js.map +1 -1
- package/out/fst.d.ts +0 -5
- package/out/fst.d.ts.map +1 -1
- package/out/fst.js +2 -5
- package/out/fst.js.map +1 -1
- package/out/fts/query.d.ts +0 -4
- package/out/fts/query.d.ts.map +1 -1
- package/out/fts/query.js +2 -7
- package/out/fts/query.js.map +1 -1
- package/out/fts.d.ts +0 -5
- package/out/fts.d.ts.map +1 -1
- package/out/fts.js +2 -5
- package/out/fts.js.map +1 -1
- package/out/geonames/aliases.d.ts +43 -5
- package/out/geonames/aliases.d.ts.map +1 -1
- package/out/geonames/aliases.js +109 -41
- package/out/geonames/aliases.js.map +1 -1
- package/out/geonames/postal.d.ts +1 -25
- package/out/geonames/postal.d.ts.map +1 -1
- package/out/geonames/postal.js +15 -14
- package/out/geonames/postal.js.map +1 -1
- package/out/geonames.d.ts +0 -5
- package/out/geonames.d.ts.map +1 -1
- package/out/geonames.js +2 -5
- package/out/geonames.js.map +1 -1
- package/out/index.d.ts +2 -5
- package/out/index.d.ts.map +1 -1
- package/out/index.js +4 -5
- package/out/index.js.map +1 -1
- package/out/interpolation.d.ts +0 -7
- package/out/interpolation.d.ts.map +1 -1
- package/out/interpolation.js +6 -6
- package/out/interpolation.js.map +1 -1
- package/out/landmark/rows.d.ts +2 -5
- package/out/landmark/rows.d.ts.map +1 -1
- package/out/landmark/rows.js +2 -8
- package/out/landmark/rows.js.map +1 -1
- package/out/landmark.d.ts +3 -6
- package/out/landmark.d.ts.map +1 -1
- package/out/landmark.js +2 -8
- package/out/landmark.js.map +1 -1
- package/out/lookup.d.ts +0 -7
- package/out/lookup.d.ts.map +1 -1
- package/out/lookup.js +7 -8
- package/out/lookup.js.map +1 -1
- package/out/name-score.d.ts +4 -6
- package/out/name-score.d.ts.map +1 -1
- package/out/name-score.js +6 -6
- package/out/name-score.js.map +1 -1
- package/out/nsul/lookup.d.ts +16 -15
- package/out/nsul/lookup.d.ts.map +1 -1
- package/out/nsul/lookup.js +2 -25
- package/out/nsul/lookup.js.map +1 -1
- package/out/nsul/schema.d.ts +1 -5
- package/out/nsul/schema.d.ts.map +1 -1
- package/out/nsul/schema.js +3 -8
- package/out/nsul/schema.js.map +1 -1
- package/out/nsul.d.ts +0 -5
- package/out/nsul.d.ts.map +1 -1
- package/out/nsul.js +2 -5
- package/out/nsul.js.map +1 -1
- package/out/paths.d.ts +1 -13
- package/out/paths.d.ts.map +1 -1
- package/out/paths.js +6 -7
- package/out/paths.js.map +1 -1
- package/out/place-importance-schema.d.ts +3 -8
- package/out/place-importance-schema.d.ts.map +1 -1
- package/out/place-importance-schema.js +3 -6
- package/out/place-importance-schema.js.map +1 -1
- package/out/poi/lookup.d.ts +0 -13
- package/out/poi/lookup.d.ts.map +1 -1
- package/out/poi/lookup.js +10 -10
- package/out/poi/lookup.js.map +1 -1
- package/out/poi/schema.d.ts +13 -10
- package/out/poi/schema.d.ts.map +1 -1
- package/out/poi/schema.js +2 -13
- package/out/poi/schema.js.map +1 -1
- package/out/poi.d.ts +0 -5
- package/out/poi.d.ts.map +1 -1
- package/out/poi.js +2 -5
- package/out/poi.js.map +1 -1
- package/out/polygon-schema.d.ts +7 -9
- package/out/polygon-schema.d.ts.map +1 -1
- package/out/polygon-schema.js +2 -12
- package/out/polygon-schema.js.map +1 -1
- package/out/postal/city/alias/lookup.d.ts +11 -13
- package/out/postal/city/alias/lookup.d.ts.map +1 -1
- package/out/postal/city/alias/lookup.js +13 -13
- package/out/postal/city/alias/lookup.js.map +1 -1
- package/out/postal/city/alias/schema.d.ts +9 -12
- package/out/postal/city/alias/schema.d.ts.map +1 -1
- package/out/postal/city/alias/schema.js +2 -17
- package/out/postal/city/alias/schema.js.map +1 -1
- package/out/postal/city/candidate-schema.d.ts +12 -12
- package/out/postal/city/candidate-schema.d.ts.map +1 -1
- package/out/postal/city/candidate-schema.js +14 -12
- package/out/postal/city/candidate-schema.js.map +1 -1
- package/out/postal.d.ts +0 -5
- package/out/postal.d.ts.map +1 -1
- package/out/postal.js +2 -5
- package/out/postal.js.map +1 -1
- package/out/postcode-point-lookup.d.ts +0 -5
- package/out/postcode-point-lookup.d.ts.map +1 -1
- package/out/postcode-point-lookup.js +2 -5
- package/out/postcode-point-lookup.js.map +1 -1
- package/out/primary-preference.d.ts +0 -5
- package/out/primary-preference.d.ts.map +1 -1
- package/out/primary-preference.js +2 -5
- package/out/primary-preference.js.map +1 -1
- package/out/proximity-rerank.d.ts +2 -26
- package/out/proximity-rerank.d.ts.map +1 -1
- package/out/proximity-rerank.js +22 -19
- package/out/proximity-rerank.js.map +1 -1
- package/out/ranking-weights.d.ts +5 -7
- package/out/ranking-weights.d.ts.map +1 -1
- package/out/ranking-weights.js +2 -9
- package/out/ranking-weights.js.map +1 -1
- package/out/region-keys.d.ts +0 -15
- package/out/region-keys.d.ts.map +1 -1
- package/out/region-keys.js +14 -14
- package/out/region-keys.js.map +1 -1
- package/out/reverse.d.ts +1 -24
- package/out/reverse.d.ts.map +1 -1
- package/out/reverse.js +14 -16
- package/out/reverse.js.map +1 -1
- package/out/schema.d.ts +17 -6
- package/out/schema.d.ts.map +1 -1
- package/out/schema.js +2 -15
- package/out/schema.js.map +1 -1
- package/out/search-fetch.d.ts +0 -13
- package/out/search-fetch.d.ts.map +1 -1
- package/out/search-fetch.js +14 -11
- package/out/search-fetch.js.map +1 -1
- package/out/sqlite/convention-source.d.ts +0 -5
- package/out/sqlite/convention-source.d.ts.map +1 -1
- package/out/sqlite/convention-source.js +2 -5
- package/out/sqlite/convention-source.js.map +1 -1
- package/out/sqlite/utils.d.ts +1 -7
- package/out/sqlite/utils.d.ts.map +1 -1
- package/out/sqlite/utils.js +3 -4
- package/out/sqlite/utils.js.map +1 -1
- package/out/street/centroid/schema.d.ts +3 -6
- package/out/street/centroid/schema.d.ts.map +1 -1
- package/out/street/centroid/schema.js +2 -7
- package/out/street/centroid/schema.js.map +1 -1
- package/out/street/centroid.d.ts +0 -3
- package/out/street/centroid.d.ts.map +1 -1
- package/out/street/centroid.js +2 -6
- package/out/street/centroid.js.map +1 -1
- package/out/street/locale.d.ts +12 -0
- package/out/street/locale.d.ts.map +1 -0
- package/out/street/locale.js +54 -0
- package/out/street/locale.js.map +1 -0
- package/out/street/morphology/fst/builder.d.ts +1 -26
- package/out/street/morphology/fst/builder.d.ts.map +1 -1
- package/out/street/morphology/fst/builder.js +19 -18
- package/out/street/morphology/fst/builder.js.map +1 -1
- package/out/street/morphology/fst/loader.d.ts +0 -20
- package/out/street/morphology/fst/loader.d.ts.map +1 -1
- package/out/street/morphology/fst/loader.js +14 -13
- package/out/street/morphology/fst/loader.js.map +1 -1
- package/out/street/name-lookup.d.ts +11 -13
- package/out/street/name-lookup.d.ts.map +1 -1
- package/out/street/name-lookup.js +14 -14
- package/out/street/name-lookup.js.map +1 -1
- package/out/street/normalize.d.ts +10 -12
- package/out/street/normalize.d.ts.map +1 -1
- package/out/street/normalize.js +15 -13
- package/out/street/normalize.js.map +1 -1
- package/out/street/segment-schema.d.ts +11 -12
- package/out/street/segment-schema.d.ts.map +1 -1
- package/out/street/segment-schema.js +13 -12
- package/out/street/segment-schema.js.map +1 -1
- package/out/street/table.d.ts +154 -0
- package/out/street/table.d.ts.map +1 -0
- package/out/street/table.js +122 -0
- package/out/street/table.js.map +1 -0
- package/out/street.d.ts +1 -5
- package/out/street.d.ts.map +1 -1
- package/out/street.js +3 -5
- package/out/street.js.map +1 -1
- package/out/types.d.ts +1 -6
- package/out/types.d.ts.map +1 -1
- package/out/types.js +2 -5
- package/out/types.js.map +1 -1
- package/out/unified-schema.d.ts +18 -7
- package/out/unified-schema.d.ts.map +1 -1
- package/out/unified-schema.js +14 -10
- package/out/unified-schema.js.map +1 -1
- package/out/uprn/existence.d.ts +7 -10
- package/out/uprn/existence.d.ts.map +1 -1
- package/out/uprn/existence.js +9 -10
- package/out/uprn/existence.js.map +1 -1
- package/out/uprn/lookup.d.ts +1 -8
- package/out/uprn/lookup.d.ts.map +1 -1
- package/out/uprn/lookup.js +6 -8
- package/out/uprn/lookup.js.map +1 -1
- package/out/uprn/schema.d.ts +2 -5
- package/out/uprn/schema.d.ts.map +1 -1
- package/out/uprn/schema.js +2 -7
- package/out/uprn/schema.js.map +1 -1
- package/out/uprn.d.ts +0 -5
- package/out/uprn.d.ts.map +1 -1
- package/out/uprn.js +2 -5
- package/out/uprn.js.map +1 -1
- package/out/weights-overlay-linker.d.ts +3 -8
- package/out/weights-overlay-linker.d.ts.map +1 -1
- package/out/weights-overlay-linker.js +5 -8
- package/out/weights-overlay-linker.js.map +1 -1
- package/package.json +12 -12
- package/lib/currency-backfill.ts +0 -289
- package/out/currency-backfill.d.ts +0 -68
- package/out/currency-backfill.d.ts.map +0 -1
- package/out/currency-backfill.js +0 -169
- package/out/currency-backfill.js.map +0 -1
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Where a country's address-layer files live, how a country is split into them,
|
|
6
|
+
* and the manifest that lists them.
|
|
7
|
+
*
|
|
8
|
+
* Each file sits under a dated prefix, `addresses/<region>/<version>/`, and is never overwritten.
|
|
9
|
+
* A reader learns a country's files from its manifest, `addresses/<cc>/<version>/manifest.json`,
|
|
10
|
+
* so code holds no list of countries or subdivisions.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { readLocalJSONFile, sortedGlob } from "@mailwoman/core/fs/readers"
|
|
14
|
+
import { pathExists, statPath } from "@mailwoman/core/fs/readers/stat"
|
|
15
|
+
import { writeLocalJSONFile } from "@mailwoman/core/fs/writers"
|
|
16
|
+
import { type RecordedFile, sha256File } from "@mailwoman/core/hash"
|
|
17
|
+
import { relative, resolvePathBuilder, type PathBuilder, type PathBuilderLike } from "path-ts"
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The row count above which a country is written one file per first-level subdivision.
|
|
21
|
+
*
|
|
22
|
+
* At 10 M, France (26.0 M rows) and Germany (20.3 M) split and Taiwan (9.7 M) doesn't.
|
|
23
|
+
*/
|
|
24
|
+
export const ADDRESS_LAYER_SPLIT_ROWS = 10_000_000
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* One file set of a country's address layer: the whole country, or one of its subdivisions.
|
|
28
|
+
*/
|
|
29
|
+
export interface AddressLayerRegion {
|
|
30
|
+
/**
|
|
31
|
+
* The region's path segment: the lower-case ISO 3166-1 code (`tw`), or the
|
|
32
|
+
* lower-case ISO 3166-2 code of a subdivision (`us-wi`).
|
|
33
|
+
*/
|
|
34
|
+
region: string
|
|
35
|
+
/**
|
|
36
|
+
* The ISO 3166-2 code the region's records hold, or `null` for a whole-country file.
|
|
37
|
+
*/
|
|
38
|
+
subdivision: string | null
|
|
39
|
+
records: number
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* The files a country's address layer is written as, from its record count per subdivision.
|
|
44
|
+
*
|
|
45
|
+
* A country above `threshold` rows is written one file per subdivision.
|
|
46
|
+
* Records without a subdivision then go to a file of the country's own.
|
|
47
|
+
* A country at or below the threshold is one file.
|
|
48
|
+
*
|
|
49
|
+
* @param bySubdivision Records per ISO 3166-2 code, with `null` for records that state none.
|
|
50
|
+
*/
|
|
51
|
+
export function planAddressLayerRegions(
|
|
52
|
+
country: string,
|
|
53
|
+
bySubdivision: ReadonlyMap<string | null, number>,
|
|
54
|
+
threshold = ADDRESS_LAYER_SPLIT_ROWS
|
|
55
|
+
): AddressLayerRegion[] {
|
|
56
|
+
const cc = country.toLowerCase()
|
|
57
|
+
let total = 0
|
|
58
|
+
|
|
59
|
+
for (const count of bySubdivision.values()) {
|
|
60
|
+
total += count
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (total <= threshold) return [{ region: cc, subdivision: null, records: total }]
|
|
64
|
+
|
|
65
|
+
return [...bySubdivision]
|
|
66
|
+
.map(([subdivision, records]) => ({
|
|
67
|
+
region: subdivision ? subdivision.toLowerCase() : cc,
|
|
68
|
+
subdivision,
|
|
69
|
+
records,
|
|
70
|
+
}))
|
|
71
|
+
.toSorted((left, right) => left.region.localeCompare(right.region))
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* The two files of one region at one version, under `root`.
|
|
76
|
+
*/
|
|
77
|
+
export function addressLayerFiles(
|
|
78
|
+
root: PathBuilderLike,
|
|
79
|
+
region: string,
|
|
80
|
+
version: string
|
|
81
|
+
): { lookup: PathBuilder; detail: PathBuilder } {
|
|
82
|
+
const directory = resolvePathBuilder(root, "addresses", region, version)
|
|
83
|
+
|
|
84
|
+
return { lookup: directory("lookup.db"), detail: directory("detail.db") }
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Where a country's manifest for one version lives, under `root`.
|
|
89
|
+
*/
|
|
90
|
+
export function addressLayerManifestPath(root: PathBuilderLike, country: string, version: string): PathBuilder {
|
|
91
|
+
return resolvePathBuilder(root, "addresses", country.toLowerCase(), version, "manifest.json")
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* A country's address-layer manifest for one version.
|
|
96
|
+
*
|
|
97
|
+
* Each file is listed by its path relative to the layer root.
|
|
98
|
+
*/
|
|
99
|
+
export interface AddressLayerCountryManifest {
|
|
100
|
+
country: string
|
|
101
|
+
version: string
|
|
102
|
+
/**
|
|
103
|
+
* The split threshold the build applied, so a reader sees why a country is one file or several.
|
|
104
|
+
*/
|
|
105
|
+
splitRows: number
|
|
106
|
+
/**
|
|
107
|
+
* The most distinct addresses one source could place at one point before the build refused them.
|
|
108
|
+
*/
|
|
109
|
+
stackLimit?: number
|
|
110
|
+
/**
|
|
111
|
+
* The duplicate rule the build dropped repeated records by: the source ranking it applied,
|
|
112
|
+
* highest first, and the distance and stacked-point limits of `isDuplicateAddress`.
|
|
113
|
+
*/
|
|
114
|
+
duplicateRule?: { ranking: readonly string[]; distanceKm: number; stackLimit: number }
|
|
115
|
+
regions: Array<
|
|
116
|
+
AddressLayerRegion & {
|
|
117
|
+
lookup: RecordedFile
|
|
118
|
+
detail: RecordedFile
|
|
119
|
+
/**
|
|
120
|
+
* Records the build left out of the region, per source id and reason.
|
|
121
|
+
*/
|
|
122
|
+
refused?: Record<string, Record<string, number>>
|
|
123
|
+
}
|
|
124
|
+
>
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* One built file's path relative to `root`, its size and its SHA-256, for the manifest.
|
|
129
|
+
*/
|
|
130
|
+
export async function describeAddressLayerFile(root: PathBuilderLike, path: PathBuilderLike): Promise<RecordedFile> {
|
|
131
|
+
const [stats, sha256] = await Promise.all([statPath(path), sha256File(path)])
|
|
132
|
+
|
|
133
|
+
return { path: relative(root, path).toString(), bytes: stats.size, sha256 }
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* The newest manifest a country's address layer holds under `root`, by its dated
|
|
138
|
+
* version directory, or `null` when the country has no layer there.
|
|
139
|
+
*/
|
|
140
|
+
export async function readLatestAddressLayerManifest(
|
|
141
|
+
root: PathBuilderLike,
|
|
142
|
+
country: string
|
|
143
|
+
): Promise<AddressLayerCountryManifest | null> {
|
|
144
|
+
const countryDir = resolvePathBuilder(root, "addresses", country.toLowerCase())
|
|
145
|
+
|
|
146
|
+
if (!(await pathExists(countryDir))) return null
|
|
147
|
+
|
|
148
|
+
// Versions are ISO dates, so code-point order is date order and the last manifest is the newest.
|
|
149
|
+
const newest = (await sortedGlob(countryDir, "*/manifest.json")).at(-1)
|
|
150
|
+
|
|
151
|
+
return newest ? readLocalJSONFile<AddressLayerCountryManifest>(newest) : null
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Writes a country's manifest beside its files, after every region it lists is built.
|
|
156
|
+
*/
|
|
157
|
+
export async function writeAddressLayerManifest(
|
|
158
|
+
root: PathBuilderLike,
|
|
159
|
+
manifest: AddressLayerCountryManifest
|
|
160
|
+
): Promise<PathBuilder> {
|
|
161
|
+
const path = addressLayerManifestPath(root, manifest.country, manifest.version)
|
|
162
|
+
|
|
163
|
+
await writeLocalJSONFile<AddressLayerCountryManifest>(manifest, path)
|
|
164
|
+
|
|
165
|
+
return path
|
|
166
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
|
|
3
|
+
|
|
4
|
+
import type { DatabaseClient } from "@mailwoman/sqlite/client"
|
|
5
|
+
|
|
6
|
+
import type { AddressStatementRunner } from "#address/keys/lookup"
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* An {@link AddressStatementRunner} over a local `lookup.db`, for the CLI and the Node API.
|
|
10
|
+
*
|
|
11
|
+
* It lives apart from the reader, so the browser loads the reader without `node:sqlite`.
|
|
12
|
+
*/
|
|
13
|
+
export function localAddressStatementRunner(db: DatabaseClient<unknown>): AddressStatementRunner {
|
|
14
|
+
return {
|
|
15
|
+
query: async <Row>(sql: string, parameters: readonly (string | number)[]) =>
|
|
16
|
+
db.prepare(sql).all(...parameters) as Row[],
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Reads an address layer's `lookup.db` by the levels a parse resolved,
|
|
6
|
+
* for the CLI, the Workers and the browser.
|
|
7
|
+
*
|
|
8
|
+
* The reader runs its statements through an {@link AddressStatementRunner}.
|
|
9
|
+
* A local `DatabaseClient` and the browser's range-request database both satisfy it,
|
|
10
|
+
* so the three runtimes share one read order.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { addressPostcodeKey } from "#address/keys/postcode"
|
|
14
|
+
import { houseNumberForms } from "#address/number-forms"
|
|
15
|
+
import { streetLocaleForCountry } from "#street/locale"
|
|
16
|
+
import {
|
|
17
|
+
normalizeHouseNumberForKey,
|
|
18
|
+
normalizeLocalityForKey,
|
|
19
|
+
type StreetLocale,
|
|
20
|
+
streetKeyVariants,
|
|
21
|
+
streetLocaleForSurface,
|
|
22
|
+
} from "#street/normalize"
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The one capability the reader needs from a database: run a parameterized `SELECT` and return its rows.
|
|
26
|
+
*/
|
|
27
|
+
export interface AddressStatementRunner {
|
|
28
|
+
query<Row>(sql: string, parameters: readonly (string | number)[]): Promise<Row[]>
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The key level a lookup answered at.
|
|
33
|
+
*/
|
|
34
|
+
export const AddressKeyLevel = {
|
|
35
|
+
Postcode: "postcode",
|
|
36
|
+
Locality: "locality",
|
|
37
|
+
Subregion: "subregion",
|
|
38
|
+
Region: "region",
|
|
39
|
+
} as const
|
|
40
|
+
|
|
41
|
+
export type AddressKeyLevel = (typeof AddressKeyLevel)[keyof typeof AddressKeyLevel]
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* One point a key answered with.
|
|
45
|
+
*/
|
|
46
|
+
export interface AddressKeyHit {
|
|
47
|
+
lat: number
|
|
48
|
+
lon: number
|
|
49
|
+
addressID: number
|
|
50
|
+
sourceID: number
|
|
51
|
+
level: AddressKeyLevel
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* What a parse resolved, in the encoder's terms.
|
|
56
|
+
*/
|
|
57
|
+
export interface AddressKeyQuery {
|
|
58
|
+
street: string
|
|
59
|
+
number: string
|
|
60
|
+
postcode?: string | null
|
|
61
|
+
/**
|
|
62
|
+
* Every locality and dependent-locality name the parse states, in the order the reader tries them.
|
|
63
|
+
*/
|
|
64
|
+
localities?: readonly string[]
|
|
65
|
+
subregion?: string | null
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* The rows the first answering level returned, at most {@link AddressKeyLookupOptions.rowCap}, with the level.
|
|
70
|
+
*
|
|
71
|
+
* Several rows mean namesake points under one key: two sources for one address,
|
|
72
|
+
* or one street and number repeated within the scope.
|
|
73
|
+
* The caller ranks them.
|
|
74
|
+
*/
|
|
75
|
+
export interface AddressKeyAnswer {
|
|
76
|
+
level: AddressKeyLevel
|
|
77
|
+
hits: AddressKeyHit[]
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export interface AddressKeyLookupOptions {
|
|
81
|
+
/**
|
|
82
|
+
* The ISO 3166-1 alpha-2 code of the country the file covers.
|
|
83
|
+
* It selects the street locale and the postcode key.
|
|
84
|
+
*/
|
|
85
|
+
country: string
|
|
86
|
+
/**
|
|
87
|
+
* The most rows one level returns.
|
|
88
|
+
*
|
|
89
|
+
* @defaultValue 8
|
|
90
|
+
*/
|
|
91
|
+
rowCap?: number
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
interface KeyRow {
|
|
95
|
+
lat: number
|
|
96
|
+
lon: number
|
|
97
|
+
address_id: number
|
|
98
|
+
source_id: number
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const SELECT_SCOPED = (table: string, cap: number) =>
|
|
102
|
+
`SELECT lat, lon, address_id, source_id FROM ${table} WHERE scope = ? AND street = ? AND number = ? LIMIT ${cap}`
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Finds address points by the most precise level a parse states: postcode,
|
|
106
|
+
* then each locality name, then the subregion, then the file's whole region.
|
|
107
|
+
*
|
|
108
|
+
* The first level with a row answers.
|
|
109
|
+
* A level the parse leaves empty is skipped, so a parse that states a street
|
|
110
|
+
* and number and no place reads only the region key.
|
|
111
|
+
*/
|
|
112
|
+
export class AddressKeyLookup {
|
|
113
|
+
readonly #runner: AddressStatementRunner
|
|
114
|
+
readonly #country: string
|
|
115
|
+
readonly #locale: StreetLocale
|
|
116
|
+
readonly #cap: number
|
|
117
|
+
|
|
118
|
+
constructor(runner: AddressStatementRunner, options: AddressKeyLookupOptions) {
|
|
119
|
+
this.#runner = runner
|
|
120
|
+
this.#country = options.country.toUpperCase()
|
|
121
|
+
this.#locale = streetLocaleForCountry(options.country)
|
|
122
|
+
this.#cap = options.rowCap ?? 8
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* The first level's rows, or `null` when no level holds the street and number.
|
|
127
|
+
*/
|
|
128
|
+
async find(query: AddressKeyQuery): Promise<AddressKeyAnswer | null> {
|
|
129
|
+
const number = query.number.trim() ? normalizeHouseNumberForKey(query.number, this.#locale) : ""
|
|
130
|
+
|
|
131
|
+
if (!number) return null
|
|
132
|
+
|
|
133
|
+
// Every street variant runs every number form, and every form runs the level ladder,
|
|
134
|
+
// so the literal street and written number answer first.
|
|
135
|
+
for (const street of streetKeyVariants(query.street, streetLocaleForSurface(query.street, this.#locale))) {
|
|
136
|
+
if (!street) continue
|
|
137
|
+
|
|
138
|
+
for (const form of houseNumberForms(number, this.#locale)) {
|
|
139
|
+
const answer = await this.#ladder(query, street, form)
|
|
140
|
+
|
|
141
|
+
if (answer) return answer
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return null
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
async #ladder(query: AddressKeyQuery, street: string, number: string): Promise<AddressKeyAnswer | null> {
|
|
149
|
+
const postcode = addressPostcodeKey(this.#country, query.postcode)
|
|
150
|
+
|
|
151
|
+
if (postcode) {
|
|
152
|
+
const hits = await this.#scoped("key_postcode", AddressKeyLevel.Postcode, postcode, street, number)
|
|
153
|
+
|
|
154
|
+
if (hits.length) return { level: AddressKeyLevel.Postcode, hits }
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
for (const locality of query.localities ?? []) {
|
|
158
|
+
const key = normalizeLocalityForKey(locality)
|
|
159
|
+
|
|
160
|
+
if (!key) continue
|
|
161
|
+
const hits = await this.#scoped("key_locality", AddressKeyLevel.Locality, key, street, number)
|
|
162
|
+
|
|
163
|
+
if (hits.length) return { level: AddressKeyLevel.Locality, hits }
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const subregion = query.subregion?.trim() ? normalizeLocalityForKey(query.subregion) : ""
|
|
167
|
+
|
|
168
|
+
if (subregion) {
|
|
169
|
+
const hits = await this.#scoped("key_subregion", AddressKeyLevel.Subregion, subregion, street, number)
|
|
170
|
+
|
|
171
|
+
if (hits.length) return { level: AddressKeyLevel.Subregion, hits }
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const rows = await this.#runner.query<KeyRow>(
|
|
175
|
+
`SELECT lat, lon, address_id, source_id FROM key_region WHERE street = ? AND number = ? LIMIT ${this.#cap}`,
|
|
176
|
+
[street, number]
|
|
177
|
+
)
|
|
178
|
+
|
|
179
|
+
return rows.length
|
|
180
|
+
? { level: AddressKeyLevel.Region, hits: rows.map((row) => toHit(row, AddressKeyLevel.Region)) }
|
|
181
|
+
: null
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
async #scoped(
|
|
185
|
+
table: "key_postcode" | "key_locality" | "key_subregion",
|
|
186
|
+
level: AddressKeyLevel,
|
|
187
|
+
scope: string,
|
|
188
|
+
street: string,
|
|
189
|
+
number: string
|
|
190
|
+
): Promise<AddressKeyHit[]> {
|
|
191
|
+
const rows = await this.#runner.query<KeyRow>(SELECT_SCOPED(table, this.#cap), [scope, street, number])
|
|
192
|
+
|
|
193
|
+
return rows.map((row) => toHit(row, level))
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function toHit(row: KeyRow, level: AddressKeyLevel): AddressKeyHit {
|
|
198
|
+
return {
|
|
199
|
+
lat: Number(row.lat),
|
|
200
|
+
lon: Number(row.lon),
|
|
201
|
+
addressID: Number(row.address_id),
|
|
202
|
+
sourceID: Number(row.source_id),
|
|
203
|
+
level,
|
|
204
|
+
}
|
|
205
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
|
|
3
|
+
|
|
4
|
+
import type { AddressPointLookup } from "@mailwoman/core/resolver"
|
|
5
|
+
import { DatabaseClient } from "@mailwoman/sqlite/client"
|
|
6
|
+
import { dirname, resolvePath, type PathBuilderLike } from "path-ts"
|
|
7
|
+
|
|
8
|
+
import { localAddressStatementRunner } from "#address/keys/local-runner"
|
|
9
|
+
import { AddressKeyPointLookup } from "#address/keys/point-lookup"
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Opens one region's local `lookup.db`, and the `detail.db` beside it, as the
|
|
13
|
+
* resolver's address-point tier, closing both files on dispose.
|
|
14
|
+
*
|
|
15
|
+
* @param country The ISO 3166-1 alpha-2 code of the country the file covers.
|
|
16
|
+
*/
|
|
17
|
+
export function openAddressLayerLookup(lookupPath: PathBuilderLike, country: string): AddressPointLookup & Disposable {
|
|
18
|
+
const db = new DatabaseClient<unknown>(lookupPath, { readOnly: true })
|
|
19
|
+
const detail = new DatabaseClient<unknown>(resolvePath(dirname(lookupPath), "detail.db"), { readOnly: true })
|
|
20
|
+
|
|
21
|
+
const lookup = new AddressKeyPointLookup(localAddressStatementRunner(db), {
|
|
22
|
+
country,
|
|
23
|
+
detail: localAddressStatementRunner(detail),
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
find: (query) => lookup.find(query),
|
|
28
|
+
[Symbol.dispose]: () => {
|
|
29
|
+
db[Symbol.dispose]()
|
|
30
|
+
detail[Symbol.dispose]()
|
|
31
|
+
},
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The resolver's address-point tier, answered from an address layer's
|
|
6
|
+
* `lookup.db` through `AddressKeyLookup`.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { parseJSONStrict } from "@mailwoman/core/json"
|
|
10
|
+
import { memoizeResettable } from "@mailwoman/core/memoize"
|
|
11
|
+
import type { AddressPointHit, AddressPointLookup } from "@mailwoman/core/resolver"
|
|
12
|
+
import { type LatLonBounds, latLonBoundsContain } from "@mailwoman/spatial/bbox"
|
|
13
|
+
|
|
14
|
+
import {
|
|
15
|
+
type AddressKeyHit,
|
|
16
|
+
AddressKeyLevel,
|
|
17
|
+
AddressKeyLookup,
|
|
18
|
+
type AddressStatementRunner,
|
|
19
|
+
} from "#address/keys/lookup"
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* An {@link AddressPointLookup} over one region's `lookup.db`.
|
|
23
|
+
*
|
|
24
|
+
* A postcode, locality or subregion key answers with its first row.
|
|
25
|
+
* A region key matches a street and number anywhere in the file.
|
|
26
|
+
*
|
|
27
|
+
* It answers only with a row inside the box the resolver passes around the resolved locality,
|
|
28
|
+
* and only with a row whose record states no postcode and no locality, read from `detail.db`.
|
|
29
|
+
* A row that states either would have matched its own scope, so its place isn't the one the parse states.
|
|
30
|
+
*
|
|
31
|
+
* This is the rule the `address_point` reader applies to its bounding-box scope.
|
|
32
|
+
*
|
|
33
|
+
* With no box, or with no `detail.db` to read, a region key doesn't answer.
|
|
34
|
+
*/
|
|
35
|
+
export class AddressKeyPointLookup implements AddressPointLookup {
|
|
36
|
+
readonly #runner: AddressStatementRunner
|
|
37
|
+
readonly #detail: AddressStatementRunner | null
|
|
38
|
+
readonly #lookup: AddressKeyLookup
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The `source` table, read once.
|
|
42
|
+
* A failed read is retried by the next lookup.
|
|
43
|
+
*/
|
|
44
|
+
readonly #sourceNames = memoizeResettable(() =>
|
|
45
|
+
this.#runner
|
|
46
|
+
.query<{ source_id: number; name: string }>("SELECT source_id, name FROM source", [])
|
|
47
|
+
.then((rows) => new Map(rows.map((row) => [Number(row.source_id), String(row.name)])))
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* The layer release version, read once.
|
|
52
|
+
* A failed read is retried by the next lookup.
|
|
53
|
+
*/
|
|
54
|
+
readonly #releaseVersion = memoizeResettable(() =>
|
|
55
|
+
this.#runner.query<{ version: string }>("SELECT version FROM layer_manifest LIMIT 1", []).then((rows) => {
|
|
56
|
+
const version = rows[0]?.version
|
|
57
|
+
|
|
58
|
+
if (!version) throw new Error("lookup.db holds no layer_manifest version")
|
|
59
|
+
|
|
60
|
+
return String(version)
|
|
61
|
+
})
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
constructor(runner: AddressStatementRunner, options: { country: string; detail?: AddressStatementRunner | null }) {
|
|
65
|
+
this.#runner = runner
|
|
66
|
+
this.#detail = options.detail ?? null
|
|
67
|
+
this.#lookup = new AddressKeyLookup(runner, { country: options.country })
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* The first region-key row inside `bounds` whose record states no postcode and no locality.
|
|
72
|
+
*/
|
|
73
|
+
async #unscopedInside(hits: readonly AddressKeyHit[], bounds: LatLonBounds): Promise<AddressKeyHit | undefined> {
|
|
74
|
+
if (!this.#detail) return undefined
|
|
75
|
+
|
|
76
|
+
for (const candidate of hits) {
|
|
77
|
+
if (!latLonBoundsContain(bounds, candidate.lat, candidate.lon)) continue
|
|
78
|
+
|
|
79
|
+
const [row] = await this.#detail.query<{ postcode: string | null; names: string }>(
|
|
80
|
+
"SELECT postcode, names FROM address WHERE address_id = ?",
|
|
81
|
+
[candidate.addressID]
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
if (!row) throw new Error(`detail.db holds no address ${candidate.addressID} for a lookup.db key row`)
|
|
85
|
+
|
|
86
|
+
const statesLocality = parseJSONStrict<Array<{ level: string }>>(row.names).some(
|
|
87
|
+
(name) => name.level === "locality" || name.level === "dependent_locality"
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
if (!row.postcode && !statesLocality) return candidate
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return undefined
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
async find(query: Parameters<AddressPointLookup["find"]>[0]): Promise<AddressPointHit | null> {
|
|
97
|
+
const answer = await this.#lookup.find({
|
|
98
|
+
street: query.street,
|
|
99
|
+
number: query.number,
|
|
100
|
+
postcode: query.postcode ?? null,
|
|
101
|
+
localities: query.locality ? [query.locality] : [],
|
|
102
|
+
subregion: query.subregion ?? null,
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
if (!answer) return null
|
|
106
|
+
|
|
107
|
+
const hit =
|
|
108
|
+
answer.level === AddressKeyLevel.Region
|
|
109
|
+
? query.bbox
|
|
110
|
+
? await this.#unscopedInside(answer.hits, query.bbox)
|
|
111
|
+
: undefined
|
|
112
|
+
: answer.hits[0]
|
|
113
|
+
|
|
114
|
+
if (!hit) return null
|
|
115
|
+
|
|
116
|
+
const [sources, release] = await Promise.all([this.#sourceNames(), this.#releaseVersion()])
|
|
117
|
+
const source = sources.get(hit.sourceID)
|
|
118
|
+
|
|
119
|
+
if (!source) throw new Error(`lookup.db holds a key row of source ${hit.sourceID}, which its source table lacks`)
|
|
120
|
+
|
|
121
|
+
return {
|
|
122
|
+
lat: hit.lat,
|
|
123
|
+
lon: hit.lon,
|
|
124
|
+
source,
|
|
125
|
+
release,
|
|
126
|
+
localityNorm: null,
|
|
127
|
+
postcode: answer.level === AddressKeyLevel.Postcode ? (query.postcode?.trim() ?? null) : null,
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Per-country patterns whose first group is the part of a postcode the key tables store.
|
|
6
|
+
*
|
|
7
|
+
* A US ZIP+4 (`53221-3633`) keys as its five-digit ZIP Code, because a query that states
|
|
8
|
+
* a ZIP Code matches it whether or not the query adds the four-digit extension.
|
|
9
|
+
*/
|
|
10
|
+
const POSTCODE_KEY_PATTERNS: Readonly<Record<string, RegExp>> = {
|
|
11
|
+
US: /^(\d{5})(?:-?\d{4})?$/u,
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The key a postcode is stored and probed under: the country's reduced form where the
|
|
16
|
+
* country has a pattern, else the postcode upper-cased with its spaces removed.
|
|
17
|
+
* Returns `null` for an empty postcode.
|
|
18
|
+
*
|
|
19
|
+
* The address layer's build and its reader both call this, so one written postcode keys one way.
|
|
20
|
+
*/
|
|
21
|
+
export function addressPostcodeKey(country: string, postcode: string | null | undefined): string | null {
|
|
22
|
+
const compact = postcode?.trim().toUpperCase().replaceAll(/\s+/gu, "")
|
|
23
|
+
|
|
24
|
+
if (!compact) return null
|
|
25
|
+
|
|
26
|
+
return POSTCODE_KEY_PATTERNS[country.toUpperCase()]?.exec(compact)?.[1] ?? compact
|
|
27
|
+
}
|