@mailwoman/registry 10.8.0 → 11.0.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 +93 -98
- package/data/manifests/artifacts.json +32 -0
- package/data/manifests/coverage.json +56 -0
- package/data/manifests/sources.lock.json +48 -0
- package/data/normalized/iata-airports.json +126749 -0
- package/data/normalized/iso3166-1.json +2035 -0
- package/definitions/namespaces.json +63 -0
- package/definitions/sections.json +73 -0
- package/docs/data-policy.md +81 -0
- package/docs/performance.md +146 -0
- package/docs/rgy1.md +144 -0
- package/lib/artifacts/country-airport-collision.ts +26 -0
- package/lib/artifacts/iata-airport/membership.ts +26 -0
- package/lib/artifacts/iata-airport/records.ts +26 -0
- package/lib/artifacts/iso3166-1/alpha2-membership.ts +26 -0
- package/lib/artifacts/iso3166-1/alpha3-membership.ts +26 -0
- package/lib/artifacts/iso3166-1/records.ts +26 -0
- package/lib/errors.ts +44 -0
- package/lib/iata/airports/records.ts +174 -0
- package/lib/iata/airports/validate.ts +49 -0
- package/lib/index.ts +25 -15
- package/lib/inspect.ts +56 -0
- package/lib/iso3166/alpha2.ts +48 -0
- package/lib/iso3166/alpha3.ts +51 -0
- package/lib/iso3166/records.ts +149 -0
- package/lib/iso3166/relations.ts +30 -0
- package/lib/key.ts +146 -0
- package/lib/normalize.ts +31 -0
- package/lib/overlap/country-airport.ts +108 -0
- package/lib/rgy1/base64.ts +24 -0
- package/lib/rgy1/reader.ts +316 -0
- package/lib/rgy1/sections.generated.ts +79 -0
- package/lib/rgy1/views.ts +267 -0
- package/lib/types.ts +88 -74
- package/lib/wasm.ts +285 -0
- package/out/artifacts/country-airport-collision.d.ts +15 -0
- package/out/artifacts/country-airport-collision.d.ts.map +1 -0
- package/out/artifacts/country-airport-collision.js +21 -0
- package/out/artifacts/country-airport-collision.js.map +1 -0
- package/out/artifacts/iata-airport/membership.d.ts +15 -0
- package/out/artifacts/iata-airport/membership.d.ts.map +1 -0
- package/out/artifacts/iata-airport/membership.js +21 -0
- package/out/artifacts/iata-airport/membership.js.map +1 -0
- package/out/artifacts/iata-airport/records.d.ts +15 -0
- package/out/artifacts/iata-airport/records.d.ts.map +1 -0
- package/out/artifacts/iata-airport/records.js +21 -0
- package/out/artifacts/iata-airport/records.js.map +1 -0
- package/out/artifacts/iso3166-1/alpha2-membership.d.ts +15 -0
- package/out/artifacts/iso3166-1/alpha2-membership.d.ts.map +1 -0
- package/out/artifacts/iso3166-1/alpha2-membership.js +21 -0
- package/out/artifacts/iso3166-1/alpha2-membership.js.map +1 -0
- package/out/artifacts/iso3166-1/alpha3-membership.d.ts +15 -0
- package/out/artifacts/iso3166-1/alpha3-membership.d.ts.map +1 -0
- package/out/artifacts/iso3166-1/alpha3-membership.js +21 -0
- package/out/artifacts/iso3166-1/alpha3-membership.js.map +1 -0
- package/out/artifacts/iso3166-1/records.d.ts +15 -0
- package/out/artifacts/iso3166-1/records.d.ts.map +1 -0
- package/out/artifacts/iso3166-1/records.js +21 -0
- package/out/artifacts/iso3166-1/records.js.map +1 -0
- package/out/errors.d.ts +38 -0
- package/out/errors.d.ts.map +1 -0
- package/out/errors.js +35 -0
- package/out/errors.js.map +1 -0
- package/out/iata/airports/records.d.ts +44 -0
- package/out/iata/airports/records.d.ts.map +1 -0
- package/out/iata/airports/records.js +137 -0
- package/out/iata/airports/records.js.map +1 -0
- package/out/iata/airports/validate.d.ts +27 -0
- package/out/iata/airports/validate.d.ts.map +1 -0
- package/out/iata/airports/validate.js +42 -0
- package/out/iata/airports/validate.js.map +1 -0
- package/out/index.d.ts +19 -15
- package/out/index.d.ts.map +1 -1
- package/out/index.js +14 -15
- package/out/index.js.map +1 -1
- package/out/inspect.d.ts +38 -0
- package/out/inspect.d.ts.map +1 -0
- package/out/inspect.js +33 -0
- package/out/inspect.js.map +1 -0
- package/out/iso3166/alpha2.d.ts +24 -0
- package/out/iso3166/alpha2.d.ts.map +1 -0
- package/out/iso3166/alpha2.js +41 -0
- package/out/iso3166/alpha2.js.map +1 -0
- package/out/iso3166/alpha3.d.ts +29 -0
- package/out/iso3166/alpha3.d.ts.map +1 -0
- package/out/iso3166/alpha3.js +44 -0
- package/out/iso3166/alpha3.js.map +1 -0
- package/out/iso3166/records.d.ts +38 -0
- package/out/iso3166/records.d.ts.map +1 -0
- package/out/iso3166/records.js +105 -0
- package/out/iso3166/records.js.map +1 -0
- package/out/iso3166/relations.d.ts +20 -0
- package/out/iso3166/relations.d.ts.map +1 -0
- package/out/iso3166/relations.js +27 -0
- package/out/iso3166/relations.js.map +1 -0
- package/out/key.d.ts +68 -0
- package/out/key.d.ts.map +1 -0
- package/out/key.js +122 -0
- package/out/key.js.map +1 -0
- package/out/normalize.d.ts +25 -0
- package/out/normalize.d.ts.map +1 -0
- package/out/normalize.js +21 -0
- package/out/normalize.js.map +1 -0
- package/out/overlap/country-airport.d.ts +57 -0
- package/out/overlap/country-airport.d.ts.map +1 -0
- package/out/overlap/country-airport.js +71 -0
- package/out/overlap/country-airport.js.map +1 -0
- package/out/rgy1/base64.d.ts +15 -0
- package/out/rgy1/base64.d.ts.map +1 -0
- package/out/rgy1/base64.js +22 -0
- package/out/rgy1/base64.js.map +1 -0
- package/out/rgy1/reader.d.ts +103 -0
- package/out/rgy1/reader.d.ts.map +1 -0
- package/out/rgy1/reader.js +230 -0
- package/out/rgy1/reader.js.map +1 -0
- package/out/rgy1/sections.generated.d.ts +54 -0
- package/out/rgy1/sections.generated.d.ts.map +1 -0
- package/out/rgy1/sections.generated.js +69 -0
- package/out/rgy1/sections.generated.js.map +1 -0
- package/out/rgy1/views.d.ts +96 -0
- package/out/rgy1/views.d.ts.map +1 -0
- package/out/rgy1/views.js +218 -0
- package/out/rgy1/views.js.map +1 -0
- package/out/sdk/fetch.d.ts +53 -0
- package/out/sdk/fetch.d.ts.map +1 -0
- package/out/sdk/fetch.js +107 -0
- package/out/sdk/fetch.js.map +1 -0
- package/out/sdk/fetch.run.d.ts +14 -0
- package/out/sdk/fetch.run.d.ts.map +1 -0
- package/out/sdk/fetch.run.js +20 -0
- package/out/sdk/fetch.run.js.map +1 -0
- package/out/sdk/sources.d.ts +111 -0
- package/out/sdk/sources.d.ts.map +1 -0
- package/out/sdk/sources.js +98 -0
- package/out/sdk/sources.js.map +1 -0
- package/out/tools/artifact-path.d.ts +10 -0
- package/out/tools/artifact-path.d.ts.map +1 -0
- package/out/tools/artifact-path.js +12 -0
- package/out/tools/artifact-path.js.map +1 -0
- package/out/tools/bench.run.d.ts +19 -0
- package/out/tools/bench.run.d.ts.map +1 -0
- package/out/tools/bench.run.js +204 -0
- package/out/tools/bench.run.js.map +1 -0
- package/out/tools/build-wasm.run.d.ts +18 -0
- package/out/tools/build-wasm.run.d.ts.map +1 -0
- package/out/tools/build-wasm.run.js +71 -0
- package/out/tools/build-wasm.run.js.map +1 -0
- package/out/tools/generate-sections.run.d.ts +13 -0
- package/out/tools/generate-sections.run.d.ts.map +1 -0
- package/out/tools/generate-sections.run.js +136 -0
- package/out/tools/generate-sections.run.js.map +1 -0
- package/out/tools/generate.run.d.ts +18 -0
- package/out/tools/generate.run.d.ts.map +1 -0
- package/out/tools/generate.run.js +118 -0
- package/out/tools/generate.run.js.map +1 -0
- package/out/tools/normalize.d.ts +155 -0
- package/out/tools/normalize.d.ts.map +1 -0
- package/out/tools/normalize.js +303 -0
- package/out/tools/normalize.js.map +1 -0
- package/out/tools/normalize.run.d.ts +14 -0
- package/out/tools/normalize.run.d.ts.map +1 -0
- package/out/tools/normalize.run.js +29 -0
- package/out/tools/normalize.run.js.map +1 -0
- package/out/types.d.ts +90 -76
- package/out/types.d.ts.map +1 -1
- package/out/types.js +20 -4
- package/out/types.js.map +1 -1
- package/out/wasm.d.ts +98 -0
- package/out/wasm.d.ts.map +1 -0
- package/out/wasm.js +137 -0
- package/out/wasm.js.map +1 -0
- package/package.json +48 -27
- package/sdk/fetch.run.ts +24 -0
- package/sdk/fetch.ts +146 -0
- package/sdk/sources.ts +162 -0
- package/tools/artifact-path.ts +12 -0
- package/tools/bench.run.ts +265 -0
- package/tools/build-wasm.run.ts +82 -0
- package/tools/generate-sections.run.ts +152 -0
- package/tools/generate.run.ts +146 -0
- package/tools/normalize.run.ts +36 -0
- package/tools/normalize.ts +474 -0
- package/wasm/registry-simd.wasm +0 -0
- package/wasm/registry.wasm +0 -0
- package/lib/address-key.ts +0 -46
- package/lib/geocode-handler.ts +0 -37
- package/lib/geojson.ts +0 -72
- package/lib/ingest.ts +0 -349
- package/lib/learned-scorer.ts +0 -134
- package/lib/map-html.ts +0 -287
- package/lib/models/crosssource-gbt-en-us.ts +0 -43
- package/lib/models/dedup-gbt-en-us.ts +0 -47
- package/lib/models/org-crosssource-gbt-en-us.ts +0 -43
- package/lib/reconcile.ts +0 -239
- package/lib/resolve.ts +0 -569
- package/out/address-key.d.ts +0 -34
- package/out/address-key.d.ts.map +0 -1
- package/out/address-key.js +0 -41
- package/out/address-key.js.map +0 -1
- package/out/geocode-handler.d.ts +0 -20
- package/out/geocode-handler.d.ts.map +0 -1
- package/out/geocode-handler.js +0 -29
- package/out/geocode-handler.js.map +0 -1
- package/out/geojson.d.ts +0 -28
- package/out/geojson.d.ts.map +0 -1
- package/out/geojson.js +0 -62
- package/out/geojson.js.map +0 -1
- package/out/ingest.d.ts +0 -173
- package/out/ingest.d.ts.map +0 -1
- package/out/ingest.js +0 -185
- package/out/ingest.js.map +0 -1
- package/out/learned-scorer.d.ts +0 -61
- package/out/learned-scorer.d.ts.map +0 -1
- package/out/learned-scorer.js +0 -91
- package/out/learned-scorer.js.map +0 -1
- package/out/map-html.d.ts +0 -39
- package/out/map-html.d.ts.map +0 -1
- package/out/map-html.js +0 -220
- package/out/map-html.js.map +0 -1
- package/out/models/crosssource-gbt-en-us.d.ts +0 -45
- package/out/models/crosssource-gbt-en-us.d.ts.map +0 -1
- package/out/models/crosssource-gbt-en-us.js +0 -40
- package/out/models/crosssource-gbt-en-us.js.map +0 -1
- package/out/models/dedup-gbt-en-us.d.ts +0 -44
- package/out/models/dedup-gbt-en-us.d.ts.map +0 -1
- package/out/models/dedup-gbt-en-us.js +0 -44
- package/out/models/dedup-gbt-en-us.js.map +0 -1
- package/out/models/org-crosssource-gbt-en-us.d.ts +0 -45
- package/out/models/org-crosssource-gbt-en-us.d.ts.map +0 -1
- package/out/models/org-crosssource-gbt-en-us.js +0 -40
- package/out/models/org-crosssource-gbt-en-us.js.map +0 -1
- package/out/reconcile.d.ts +0 -96
- package/out/reconcile.d.ts.map +0 -1
- package/out/reconcile.js +0 -127
- package/out/reconcile.js.map +0 -1
- package/out/resolve.d.ts +0 -264
- package/out/resolve.d.ts.map +0 -1
- package/out/resolve.js +0 -282
- package/out/resolve.js.map +0 -1
- package/out/tools/coverage-reconciliation.d.ts +0 -67
- package/out/tools/coverage-reconciliation.d.ts.map +0 -1
- package/out/tools/coverage-reconciliation.js +0 -113
- package/out/tools/coverage-reconciliation.js.map +0 -1
- package/out/tools/cross/dataset-correlation.d.ts +0 -61
- package/out/tools/cross/dataset-correlation.d.ts.map +0 -1
- package/out/tools/cross/dataset-correlation.js +0 -244
- package/out/tools/cross/dataset-correlation.js.map +0 -1
- package/out/tools/cross/source-threshold-sweep.d.ts +0 -60
- package/out/tools/cross/source-threshold-sweep.d.ts.map +0 -1
- package/out/tools/cross/source-threshold-sweep.js +0 -264
- package/out/tools/cross/source-threshold-sweep.js.map +0 -1
- package/out/tools/dedup-ceiling.d.ts +0 -62
- package/out/tools/dedup-ceiling.d.ts.map +0 -1
- package/out/tools/dedup-ceiling.js +0 -171
- package/out/tools/dedup-ceiling.js.map +0 -1
- package/out/tools/eval-geocoder.d.ts +0 -68
- package/out/tools/eval-geocoder.d.ts.map +0 -1
- package/out/tools/eval-geocoder.js +0 -13
- package/out/tools/eval-geocoder.js.map +0 -1
- package/out/tools/geocoder/namesake-probe.d.ts +0 -33
- package/out/tools/geocoder/namesake-probe.d.ts.map +0 -1
- package/out/tools/geocoder/namesake-probe.js +0 -60
- package/out/tools/geocoder/namesake-probe.js.map +0 -1
- package/out/tools/geocoder/vs-provided-coords.d.ts +0 -53
- package/out/tools/geocoder/vs-provided-coords.d.ts.map +0 -1
- package/out/tools/geocoder/vs-provided-coords.js +0 -161
- package/out/tools/geocoder/vs-provided-coords.js.map +0 -1
- package/out/tools/gold-set-sample.d.ts +0 -67
- package/out/tools/gold-set-sample.d.ts.map +0 -1
- package/out/tools/gold-set-sample.js +0 -81
- package/out/tools/gold-set-sample.js.map +0 -1
- package/out/tools/learned/scorer/clustering-eval.d.ts +0 -77
- package/out/tools/learned/scorer/clustering-eval.d.ts.map +0 -1
- package/out/tools/learned/scorer/clustering-eval.js +0 -207
- package/out/tools/learned/scorer/clustering-eval.js.map +0 -1
- package/out/tools/learned/scorer/crossstate-eval.d.ts +0 -65
- package/out/tools/learned/scorer/crossstate-eval.d.ts.map +0 -1
- package/out/tools/learned/scorer/crossstate-eval.js +0 -168
- package/out/tools/learned/scorer/crossstate-eval.js.map +0 -1
- package/out/tools/learned/scorer/eval.d.ts +0 -64
- package/out/tools/learned/scorer/eval.d.ts.map +0 -1
- package/out/tools/learned/scorer/eval.js +0 -275
- package/out/tools/learned/scorer/eval.js.map +0 -1
- package/out/tools/matcher-scale.d.ts +0 -40
- package/out/tools/matcher-scale.d.ts.map +0 -1
- package/out/tools/matcher-scale.js +0 -111
- package/out/tools/matcher-scale.js.map +0 -1
- package/out/tools/nppes/dedup-benchmark.d.ts +0 -82
- package/out/tools/nppes/dedup-benchmark.d.ts.map +0 -1
- package/out/tools/nppes/dedup-benchmark.js +0 -226
- package/out/tools/nppes/dedup-benchmark.js.map +0 -1
- package/out/tools/nppes/org-name.d.ts +0 -15
- package/out/tools/nppes/org-name.d.ts.map +0 -1
- package/out/tools/nppes/org-name.js +0 -6
- package/out/tools/nppes/org-name.js.map +0 -1
- package/out/tools/nppes/overmerge-packet.d.ts +0 -43
- package/out/tools/nppes/overmerge-packet.d.ts.map +0 -1
- package/out/tools/nppes/overmerge-packet.js +0 -54
- package/out/tools/nppes/overmerge-packet.js.map +0 -1
- package/out/tools/nppes/report.d.ts +0 -97
- package/out/tools/nppes/report.d.ts.map +0 -1
- package/out/tools/nppes/report.js +0 -178
- package/out/tools/nppes/report.js.map +0 -1
- package/out/tools/nppes/sample.d.ts +0 -101
- package/out/tools/nppes/sample.d.ts.map +0 -1
- package/out/tools/nppes/sample.js +0 -127
- package/out/tools/nppes/sample.js.map +0 -1
- package/out/tools/nppes/scoring.d.ts +0 -37
- package/out/tools/nppes/scoring.d.ts.map +0 -1
- package/out/tools/nppes/scoring.js +0 -81
- package/out/tools/nppes/scoring.js.map +0 -1
- package/out/tools/nppes/settings.d.ts +0 -41
- package/out/tools/nppes/settings.d.ts.map +0 -1
- package/out/tools/nppes/settings.js +0 -79
- package/out/tools/nppes/settings.js.map +0 -1
- package/out/tools/nppes/truth-grains.d.ts +0 -63
- package/out/tools/nppes/truth-grains.d.ts.map +0 -1
- package/out/tools/nppes/truth-grains.js +0 -142
- package/out/tools/nppes/truth-grains.js.map +0 -1
- package/out/tools/shared.d.ts +0 -325
- package/out/tools/shared.d.ts.map +0 -1
- package/out/tools/shared.js +0 -453
- package/out/tools/shared.js.map +0 -1
- package/out/tools/train/cross-gbt.d.ts +0 -89
- package/out/tools/train/cross-gbt.d.ts.map +0 -1
- package/out/tools/train/cross-gbt.js +0 -132
- package/out/tools/train/cross-gbt.js.map +0 -1
- package/out/tools/train/gbt.d.ts +0 -85
- package/out/tools/train/gbt.d.ts.map +0 -1
- package/out/tools/train/gbt.js +0 -155
- package/out/tools/train/gbt.js.map +0 -1
- package/out/tools/train/org-cross-gbt.d.ts +0 -85
- package/out/tools/train/org-cross-gbt.d.ts.map +0 -1
- package/out/tools/train/org-cross-gbt.js +0 -122
- package/out/tools/train/org-cross-gbt.js.map +0 -1
- package/out/tools/txhhsc-to-oarow.d.ts +0 -42
- package/out/tools/txhhsc-to-oarow.d.ts.map +0 -1
- package/out/tools/txhhsc-to-oarow.js +0 -78
- package/out/tools/txhhsc-to-oarow.js.map +0 -1
- package/out/tools/viz/browser.d.ts +0 -31
- package/out/tools/viz/browser.d.ts.map +0 -1
- package/out/tools/viz/browser.js +0 -26
- package/out/tools/viz/browser.js.map +0 -1
- package/out/tools/viz/cross-dataset-map.d.ts +0 -39
- package/out/tools/viz/cross-dataset-map.d.ts.map +0 -1
- package/out/tools/viz/cross-dataset-map.js +0 -84
- package/out/tools/viz/cross-dataset-map.js.map +0 -1
- package/out/tools/viz/geocode-first-surface.d.ts +0 -36
- package/out/tools/viz/geocode-first-surface.d.ts.map +0 -1
- package/out/tools/viz/geocode-first-surface.js +0 -234
- package/out/tools/viz/geocode-first-surface.js.map +0 -1
- package/out/tools/viz/render/map.d.ts +0 -42
- package/out/tools/viz/render/map.d.ts.map +0 -1
- package/out/tools/viz/render/map.js +0 -40
- package/out/tools/viz/render/map.js.map +0 -1
- package/out/tools/viz/render.d.ts +0 -46
- package/out/tools/viz/render.d.ts.map +0 -1
- package/out/tools/viz/render.js +0 -49
- package/out/tools/viz/render.js.map +0 -1
- package/out/tools/viz/source-provenance-map.d.ts +0 -57
- package/out/tools/viz/source-provenance-map.d.ts.map +0 -1
- package/out/tools/viz/source-provenance-map.js +0 -82
- package/out/tools/viz/source-provenance-map.js.map +0 -1
- package/out/tools/viz/yardstick-figure.d.ts +0 -22
- package/out/tools/viz/yardstick-figure.d.ts.map +0 -1
- package/out/tools/viz/yardstick-figure.js +0 -106
- package/out/tools/viz/yardstick-figure.js.map +0 -1
- package/tools/coverage-reconciliation.ts +0 -192
- package/tools/cross/dataset-correlation.ts +0 -380
- package/tools/cross/source-threshold-sweep.ts +0 -416
- package/tools/dedup-ceiling.ts +0 -225
- package/tools/eval-geocoder.ts +0 -77
- package/tools/geocoder/namesake-probe.ts +0 -91
- package/tools/geocoder/vs-provided-coords.ts +0 -232
- package/tools/gold-set-sample.ts +0 -147
- package/tools/learned/scorer/clustering-eval.ts +0 -349
- package/tools/learned/scorer/crossstate-eval.ts +0 -280
- package/tools/learned/scorer/eval.ts +0 -429
- package/tools/matcher-scale.ts +0 -185
- package/tools/nppes/dedup-benchmark.ts +0 -364
- package/tools/nppes/org-name.ts +0 -15
- package/tools/nppes/overmerge-packet.ts +0 -98
- package/tools/nppes/report.ts +0 -380
- package/tools/nppes/sample.ts +0 -250
- package/tools/nppes/scoring.ts +0 -115
- package/tools/nppes/settings.ts +0 -102
- package/tools/nppes/truth-grains.ts +0 -185
- package/tools/shared.ts +0 -743
- package/tools/train/cross-gbt.ts +0 -214
- package/tools/train/gbt.ts +0 -261
- package/tools/train/org-cross-gbt.ts +0 -189
- package/tools/txhhsc-to-oarow.ts +0 -118
- package/tools/viz/browser.ts +0 -41
- package/tools/viz/cross-dataset-map.ts +0 -133
- package/tools/viz/geocode-first-surface.ts +0 -305
- package/tools/viz/render/map.ts +0 -61
- package/tools/viz/render.ts +0 -103
- package/tools/viz/source-provenance-map.ts +0 -154
- package/tools/viz/yardstick-figure.ts +0 -197
package/sdk/fetch.run.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* Downloads the open profile's sources into `$MAILWOMAN_DATA_ROOT/corpus/sources/registry/` and checks them
|
|
7
|
+
* against `data/manifests/sources.lock.json`.
|
|
8
|
+
*
|
|
9
|
+
* Usage: `node packages/registry/sdk/fetch.run.ts [--repin]`
|
|
10
|
+
*
|
|
11
|
+
* `--repin` rewrites the lock from the downloaded bytes. Without it, a changed publication fails the run.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { parseArguments } from "@mailwoman/core/scripting/arguments"
|
|
15
|
+
|
|
16
|
+
import { retrieveRegistrySources } from "#sdk/fetch"
|
|
17
|
+
|
|
18
|
+
const { values } = parseArguments({ options: { repin: { type: "boolean", default: false } } })
|
|
19
|
+
|
|
20
|
+
const lock = await retrieveRegistrySources({ repin: values.repin })
|
|
21
|
+
|
|
22
|
+
for (const [id, entry] of Object.entries(lock.sources)) {
|
|
23
|
+
console.log(`${id}\t${entry.bytes} bytes\tsha256 ${entry.sha256}\tpublication ${entry.publication}`)
|
|
24
|
+
}
|
package/sdk/fetch.ts
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* Downloads the open profile's pinned sources into the data root and checks them against the lock.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { APIClient } from "@mailwoman/core/api"
|
|
10
|
+
import { readLocalJSONFile } from "@mailwoman/core/fs/readers"
|
|
11
|
+
import { pathExists } from "@mailwoman/core/fs/readers/stat"
|
|
12
|
+
import { writeLocalFile, writeLocalJSONFile } from "@mailwoman/core/fs/writers"
|
|
13
|
+
import { sha256File } from "@mailwoman/core/hash"
|
|
14
|
+
import { stringifyJSON } from "@mailwoman/core/json"
|
|
15
|
+
import { workspacePathBuilder } from "@mailwoman/core/paths"
|
|
16
|
+
import type { PathBuilder } from "path-ts"
|
|
17
|
+
|
|
18
|
+
import {
|
|
19
|
+
OPEN_PROFILE,
|
|
20
|
+
type SourceDefinition,
|
|
21
|
+
type SourceID,
|
|
22
|
+
type SourceLock,
|
|
23
|
+
type SourceLockEntry,
|
|
24
|
+
sourcePath,
|
|
25
|
+
SOURCES,
|
|
26
|
+
} from "#sdk/sources"
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The lock the build reads.
|
|
30
|
+
*/
|
|
31
|
+
export function sourceLockPath(): PathBuilder {
|
|
32
|
+
return workspacePathBuilder("registry", "data", "manifests", "sources.lock.json")
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* The UN Statistics Division's M49 crosswalk, considered and refused, with the terms that refused it.
|
|
37
|
+
*/
|
|
38
|
+
export const UN_M49_NOT_ELECTED = {
|
|
39
|
+
url: "https://unstats.un.org/unsd/methodology/m49/overview/",
|
|
40
|
+
terms:
|
|
41
|
+
"The United Nations grants permission to Users to visit the Site and to download and copy the information " +
|
|
42
|
+
"for the User's personal, non-commercial use, without any right to resell or redistribute them or to compile or " +
|
|
43
|
+
"create derivative works therefrom.",
|
|
44
|
+
readAt: "https://www.un.org/en/about-us/terms-of-use",
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Reads the lock, or `null` when none has been written.
|
|
49
|
+
*/
|
|
50
|
+
export async function readSourceLock(): Promise<SourceLock | null> {
|
|
51
|
+
const path = sourceLockPath()
|
|
52
|
+
|
|
53
|
+
return (await pathExists(path)) ? readLocalJSONFile<SourceLock>(path) : null
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const DOWNLOAD_TIMEOUT_MS = 120_000
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* The result of downloading one source.
|
|
60
|
+
*/
|
|
61
|
+
export interface DownloadedSource {
|
|
62
|
+
id: SourceID
|
|
63
|
+
path: PathBuilder
|
|
64
|
+
entry: SourceLockEntry
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Downloads one source to its data-root path and records what the server stated about it.
|
|
69
|
+
*/
|
|
70
|
+
export async function retrieveRegistrySource(source: SourceDefinition, client: APIClient): Promise<DownloadedSource> {
|
|
71
|
+
const response = await client.fetch<string>({ url: source.url })
|
|
72
|
+
const path = sourcePath(source)
|
|
73
|
+
const body = typeof response.data === "string" ? response.data : stringifyJSON(response.data)
|
|
74
|
+
|
|
75
|
+
await writeLocalFile(body, path)
|
|
76
|
+
|
|
77
|
+
const sha256 = await sha256File(path)
|
|
78
|
+
const headers = response.headers as Record<string, string | undefined>
|
|
79
|
+
const publication = headers["last-modified"] ?? headers["etag"] ?? "unstated"
|
|
80
|
+
const bytes = Buffer.byteLength(body)
|
|
81
|
+
|
|
82
|
+
return {
|
|
83
|
+
id: source.id,
|
|
84
|
+
path,
|
|
85
|
+
entry: { url: source.url, sha256, bytes, publication, terms: source.terms, feeds: source.feeds },
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Creates the client the downloads share: three attempts, a two-minute idle timeout, text bodies.
|
|
91
|
+
*/
|
|
92
|
+
export function createRegistrySourceClient(): APIClient {
|
|
93
|
+
return new APIClient({
|
|
94
|
+
displayName: "registry sources",
|
|
95
|
+
retry: { maxAttempts: 3 },
|
|
96
|
+
axios: {
|
|
97
|
+
headers: {
|
|
98
|
+
"User-Agent": "mailwoman-registry/0.1 (https://github.com/sister-software/mailwoman)",
|
|
99
|
+
Accept: "text/csv, application/sparql-results+json, application/json",
|
|
100
|
+
"Accept-Encoding": "gzip",
|
|
101
|
+
},
|
|
102
|
+
timeout: DOWNLOAD_TIMEOUT_MS,
|
|
103
|
+
responseType: "text",
|
|
104
|
+
transitional: { silentJSONParsing: false },
|
|
105
|
+
},
|
|
106
|
+
})
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Downloads every elected source.
|
|
111
|
+
*
|
|
112
|
+
* With `repin`, the lock is rewritten from what was downloaded.
|
|
113
|
+
* Without it, a downloaded digest that differs from the lock is an error naming the source,
|
|
114
|
+
* because the build would otherwise read bytes the lock does not describe.
|
|
115
|
+
*/
|
|
116
|
+
export async function retrieveRegistrySources(options: { repin: boolean }): Promise<SourceLock> {
|
|
117
|
+
const client = createRegistrySourceClient()
|
|
118
|
+
const existing = await readSourceLock()
|
|
119
|
+
const downloaded: DownloadedSource[] = []
|
|
120
|
+
|
|
121
|
+
for (const source of SOURCES.filter((candidate) => candidate.terms.elected)) {
|
|
122
|
+
const result = await retrieveRegistrySource(source, client)
|
|
123
|
+
const locked = existing?.sources[source.id]
|
|
124
|
+
|
|
125
|
+
if (!options.repin && locked && locked.sha256 !== result.entry.sha256) {
|
|
126
|
+
throw new Error(
|
|
127
|
+
`${source.id}: downloaded ${result.entry.sha256} (${result.entry.bytes} bytes), lock holds ${locked.sha256} ` +
|
|
128
|
+
`(${locked.bytes} bytes). Pass --repin to accept the new publication.`
|
|
129
|
+
)
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
downloaded.push(result)
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const lock: SourceLock = {
|
|
136
|
+
profile: OPEN_PROFILE,
|
|
137
|
+
sources: Object.fromEntries(downloaded.map((item) => [item.id, item.entry])) as SourceLock["sources"],
|
|
138
|
+
$notElected: { "unsd-m49": UN_M49_NOT_ELECTED },
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (options.repin || !existing) {
|
|
142
|
+
await writeLocalJSONFile(lock, sourceLockPath())
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return lock
|
|
146
|
+
}
|
package/sdk/sources.ts
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* The pinned sources of the open profile, and the lock that records the bytes a build read.
|
|
7
|
+
*
|
|
8
|
+
* A source is a published file at one URL. The lock records its SHA-256 and byte count, the publication marker the
|
|
9
|
+
* server stated (`Last-Modified` or `ETag`), and the publisher's statement of terms. A build reads the locked bytes
|
|
10
|
+
* from the data root and refuses bytes whose digest differs, so a moving `latest` never enters an artifact unnoticed.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { dataRootPath } from "@mailwoman/core/data-root"
|
|
14
|
+
import type { PathBuilder } from "path-ts"
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The profile the open sources compile into.
|
|
18
|
+
*
|
|
19
|
+
* `open-2026-11` is the identifier of the source set below.
|
|
20
|
+
* A different source set is a different profile, so an artifact built from an official IATA
|
|
21
|
+
* or ISO feed would hold another identifier rather than this one.
|
|
22
|
+
*/
|
|
23
|
+
export const OPEN_PROFILE = "open-2026-11"
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* One pinned source.
|
|
27
|
+
*/
|
|
28
|
+
export interface SourceDefinition {
|
|
29
|
+
id: SourceID
|
|
30
|
+
url: string
|
|
31
|
+
/**
|
|
32
|
+
* The file name under the data root.
|
|
33
|
+
*/
|
|
34
|
+
file: string
|
|
35
|
+
/**
|
|
36
|
+
* The publisher's own statement of the terms, quoted, and where it was read.
|
|
37
|
+
*/
|
|
38
|
+
terms: {
|
|
39
|
+
statement: string
|
|
40
|
+
readAt: string
|
|
41
|
+
/**
|
|
42
|
+
* Whether the repository elects the source for redistribution in a built artifact.
|
|
43
|
+
*/
|
|
44
|
+
elected: boolean
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Which namespaces the source feeds.
|
|
48
|
+
*/
|
|
49
|
+
feeds: readonly string[]
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* The identifiers of the open profile's sources, as the lock keys them.
|
|
54
|
+
*/
|
|
55
|
+
export const SOURCE_IDS = ["ourairports-airports", "ourairports-countries", "wikidata-iso3166-1"] as const
|
|
56
|
+
|
|
57
|
+
export type SourceID = (typeof SOURCE_IDS)[number]
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* The SPARQL query that reads every item holding an ISO 3166-1 alpha-2, alpha-3 and numeric code.
|
|
61
|
+
*
|
|
62
|
+
* `wdt:` reads the best-rank claim.
|
|
63
|
+
* A state that has ended, such as the German Democratic Republic (`DD`) or the Netherlands Antilles
|
|
64
|
+
* (`AN`), keeps its codes as best-rank claims, so the query also reads the dissolution date (P576)
|
|
65
|
+
* and the normalizer records such an entry as `formerly-used` rather than `officially-assigned`.
|
|
66
|
+
*
|
|
67
|
+
* An item holding all three codes is the ISO entry.
|
|
68
|
+
* An item with only one of them is a region or a historical entry and is left out on purpose.
|
|
69
|
+
*/
|
|
70
|
+
export const ISO3166_1_QUERY = `SELECT ?item ?itemLabel ?alpha2 ?alpha3 ?numeric ?dissolved WHERE {
|
|
71
|
+
?item wdt:P297 ?alpha2; wdt:P298 ?alpha3; wdt:P299 ?numeric.
|
|
72
|
+
OPTIONAL { ?item wdt:P576 ?dissolved. }
|
|
73
|
+
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
|
|
74
|
+
}
|
|
75
|
+
ORDER BY ?alpha2 ?item`
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* The Wikidata Query Service endpoint the ISO 3166-1 query is sent to.
|
|
79
|
+
*/
|
|
80
|
+
export const WIKIDATA_SPARQL_ENDPOINT = "https://query.wikidata.org/sparql"
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* The open profile's sources.
|
|
84
|
+
*
|
|
85
|
+
* The UN Statistics Division's M49 crosswalk is not among them.
|
|
86
|
+
* The UN terms of use (https://www.un.org/en/about-us/terms-of-use, read 2026-11-06)
|
|
87
|
+
* grant "personal, non-commercial use, without any right to resell or redistribute"
|
|
88
|
+
* and exclude the right "to compile or create derivative works therefrom".
|
|
89
|
+
*
|
|
90
|
+
* A compiled artifact in a redistributed package is both, so the source is
|
|
91
|
+
* recorded as not elected rather than pinned.
|
|
92
|
+
*/
|
|
93
|
+
export const SOURCES: readonly SourceDefinition[] = [
|
|
94
|
+
{
|
|
95
|
+
id: "ourairports-airports",
|
|
96
|
+
url: "https://davidmegginson.github.io/ourairports-data/airports.csv",
|
|
97
|
+
file: "ourairports-airports.csv",
|
|
98
|
+
terms: {
|
|
99
|
+
statement:
|
|
100
|
+
"All data is released to the Public Domain, and comes with no guarantee of accuracy or fitness for use.",
|
|
101
|
+
readAt: "https://ourairports.com/data/",
|
|
102
|
+
elected: true,
|
|
103
|
+
},
|
|
104
|
+
feeds: ["iata-location", "icao-location"],
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
id: "ourairports-countries",
|
|
108
|
+
url: "https://davidmegginson.github.io/ourairports-data/countries.csv",
|
|
109
|
+
file: "ourairports-countries.csv",
|
|
110
|
+
terms: {
|
|
111
|
+
statement:
|
|
112
|
+
"All data is released to the Public Domain, and comes with no guarantee of accuracy or fitness for use.",
|
|
113
|
+
readAt: "https://ourairports.com/data/",
|
|
114
|
+
elected: true,
|
|
115
|
+
},
|
|
116
|
+
feeds: ["iso3166-1-alpha2"],
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
id: "wikidata-iso3166-1",
|
|
120
|
+
url: `${WIKIDATA_SPARQL_ENDPOINT}?format=json&query=${encodeURIComponent(ISO3166_1_QUERY)}`,
|
|
121
|
+
file: "wikidata-iso3166-1.json",
|
|
122
|
+
terms: {
|
|
123
|
+
statement:
|
|
124
|
+
"Wikidata publishes its structured data under the Creative Commons CC0 1.0 Universal public domain dedication.",
|
|
125
|
+
readAt: "https://www.wikidata.org/wiki/Wikidata:Licensing",
|
|
126
|
+
elected: true,
|
|
127
|
+
},
|
|
128
|
+
feeds: ["iso3166-1-alpha2", "iso3166-1-alpha3", "iso3166-1-numeric"],
|
|
129
|
+
},
|
|
130
|
+
]
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* One source's record in `data/manifests/sources.lock.json`.
|
|
134
|
+
*/
|
|
135
|
+
export interface SourceLockEntry {
|
|
136
|
+
url: string
|
|
137
|
+
sha256: string
|
|
138
|
+
bytes: number
|
|
139
|
+
/**
|
|
140
|
+
* The publication marker the server stated when the bytes were read:
|
|
141
|
+
* `Last-Modified`, else `ETag`, else `unstated`.
|
|
142
|
+
*/
|
|
143
|
+
publication: string
|
|
144
|
+
terms: SourceDefinition["terms"]
|
|
145
|
+
feeds: readonly string[]
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export interface SourceLock {
|
|
149
|
+
profile: string
|
|
150
|
+
sources: Record<SourceID, SourceLockEntry>
|
|
151
|
+
/**
|
|
152
|
+
* Sources considered and refused, with the terms that refused them.
|
|
153
|
+
*/
|
|
154
|
+
$notElected: Record<string, { url: string; terms: string; readAt: string }>
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Where the pinned bytes of a source live.
|
|
159
|
+
*/
|
|
160
|
+
export function sourcePath(source: SourceDefinition): PathBuilder {
|
|
161
|
+
return dataRootPath("corpus", "sources", "registry", source.file)
|
|
162
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Returns the module an artifact's bytes live in under `lib/artifacts/`, grouped by the dataset it reads.
|
|
9
|
+
*/
|
|
10
|
+
export function artifactModulePath(name: string): string {
|
|
11
|
+
return name.replace(/^(iso3166-1|iata-airport)-/u, "$1/")
|
|
12
|
+
}
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* Measures the readers on this host and prints a Markdown report for `docs/performance.md`.
|
|
7
|
+
*
|
|
8
|
+
* Arms: a JavaScript `Set` of strings as the baseline, the TypeScript bitset reader, and the WebAssembly batch
|
|
9
|
+
* kernels, scalar and simd. Inputs: strings end to end, and packed bytes where an arm takes them. Batch sizes 1, 16,
|
|
10
|
+
* 256, 4,096 and the whole 17,576-key domain. Distributions: hits, misses, and a shuffled sweep of the domain. Startup:
|
|
11
|
+
* module import, artifact decode and validation, wasm compile and instantiate, first query. Every result is consumed
|
|
12
|
+
* so the work is kept.
|
|
13
|
+
*
|
|
14
|
+
* Usage: `node packages/registry/tools/bench.run.ts [--json]`
|
|
15
|
+
*
|
|
16
|
+
* The numbers describe one host and one run. The report records the host, Node and the artifact digests beside them.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { readLocalBuffer, readLocalJSONFile } from "@mailwoman/core/fs/readers"
|
|
20
|
+
import { prettyJSON } from "@mailwoman/core/json"
|
|
21
|
+
import { workspacePath } from "@mailwoman/core/paths"
|
|
22
|
+
import { mulberry32, shuffleWith } from "@mailwoman/core/random"
|
|
23
|
+
import { parseArguments } from "@mailwoman/core/scripting/arguments"
|
|
24
|
+
import { cpuCount, cpuModel, totalMemoryBytes } from "@mailwoman/core/utils/system"
|
|
25
|
+
|
|
26
|
+
import { decode3, KEY_SPACE_3 } from "#key"
|
|
27
|
+
|
|
28
|
+
const { values } = parseArguments({ options: { json: { type: "boolean", default: false } } })
|
|
29
|
+
|
|
30
|
+
const encoder = new TextEncoder()
|
|
31
|
+
|
|
32
|
+
function nanoseconds(start: bigint): number {
|
|
33
|
+
return Number(process.hrtime.bigint() - start)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Runs `run` over `rounds` repetitions and reports the median nanoseconds per code.
|
|
38
|
+
*/
|
|
39
|
+
function measure(
|
|
40
|
+
label: string,
|
|
41
|
+
codesPerRound: number,
|
|
42
|
+
rounds: number,
|
|
43
|
+
run: () => number
|
|
44
|
+
): { label: string; nsPerCode: number; sink: number } {
|
|
45
|
+
const samples: number[] = []
|
|
46
|
+
let sink = 0
|
|
47
|
+
|
|
48
|
+
for (let round = 0; round < rounds; round++) {
|
|
49
|
+
const start = process.hrtime.bigint()
|
|
50
|
+
|
|
51
|
+
sink += run()
|
|
52
|
+
samples.push(nanoseconds(start) / codesPerRound)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
samples.sort((a, b) => a - b)
|
|
56
|
+
|
|
57
|
+
return { label, nsPerCode: samples[Math.floor(samples.length / 2)]!, sink }
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Startup: module import.
|
|
61
|
+
const importStart = process.hrtime.bigint()
|
|
62
|
+
|
|
63
|
+
const [{ collisionMembership, isCountryAirportCollision }, { alpha3Membership }, { airportMembership }, wasm] =
|
|
64
|
+
await Promise.all([
|
|
65
|
+
import("#overlap/country-airport"),
|
|
66
|
+
import("#iso3166/alpha3"),
|
|
67
|
+
import("#iata/airports/validate"),
|
|
68
|
+
import("#wasm"),
|
|
69
|
+
])
|
|
70
|
+
|
|
71
|
+
const importNs = nanoseconds(importStart)
|
|
72
|
+
|
|
73
|
+
// Startup: decode and validate the three bitsets on first use.
|
|
74
|
+
const decodeStart = process.hrtime.bigint()
|
|
75
|
+
collisionMembership()
|
|
76
|
+
alpha3Membership()
|
|
77
|
+
airportMembership()
|
|
78
|
+
const decodeNs = nanoseconds(decodeStart)
|
|
79
|
+
|
|
80
|
+
const firstQueryStart = process.hrtime.bigint()
|
|
81
|
+
isCountryAirportCollision("AUS")
|
|
82
|
+
const firstQueryNs = nanoseconds(firstQueryStart)
|
|
83
|
+
|
|
84
|
+
// The baseline: a Set of strings built from the normalized JSON.
|
|
85
|
+
const countries = await readLocalJSONFile<{ records: Array<{ alpha3: string; status: string }> }>(
|
|
86
|
+
workspacePath("registry", "data", "normalized", "iso3166-1.json")
|
|
87
|
+
)
|
|
88
|
+
const airports = await readLocalJSONFile<{ records: Array<{ iata: string }> }>(
|
|
89
|
+
workspacePath("registry", "data", "normalized", "iata-airports.json")
|
|
90
|
+
)
|
|
91
|
+
const setStart = process.hrtime.bigint()
|
|
92
|
+
const countrySet = new Set(
|
|
93
|
+
countries.records.filter((record) => record.status === "officially-assigned").map((record) => record.alpha3)
|
|
94
|
+
)
|
|
95
|
+
const airportSet = new Set(airports.records.map((record) => record.iata))
|
|
96
|
+
const collisionSet = new Set([...countrySet].filter((code) => airportSet.has(code)))
|
|
97
|
+
const setBuildNs = nanoseconds(setStart)
|
|
98
|
+
|
|
99
|
+
// Inputs.
|
|
100
|
+
const allCodes = Array.from({ length: KEY_SPACE_3 }, (_, key) => decode3(key))
|
|
101
|
+
const hits = [...collisionSet]
|
|
102
|
+
const misses = allCodes.filter((code) => !countrySet.has(code) && !airportSet.has(code)).slice(0, 4096)
|
|
103
|
+
const shuffled = [...allCodes]
|
|
104
|
+
|
|
105
|
+
// A fixed-seed shuffle so two runs read the same order.
|
|
106
|
+
shuffleWith(shuffled, mulberry32(0x9e_37_79_b9))
|
|
107
|
+
|
|
108
|
+
function packed(codes: readonly string[]): Uint8Array {
|
|
109
|
+
const bytes = new Uint8Array(codes.length * 3)
|
|
110
|
+
|
|
111
|
+
codes.forEach((code, index) => bytes.set(encoder.encode(code), index * 3))
|
|
112
|
+
|
|
113
|
+
return bytes
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const results: Array<{ arm: string; input: string; distribution: string; batch: number; nsPerCode: number }> = []
|
|
117
|
+
const batches = [1, 16, 256, 4096, KEY_SPACE_3]
|
|
118
|
+
|
|
119
|
+
for (const [distribution, codes] of [
|
|
120
|
+
["hits", hits],
|
|
121
|
+
["misses", misses],
|
|
122
|
+
["shuffled sweep", shuffled],
|
|
123
|
+
] as const) {
|
|
124
|
+
for (const batch of batches) {
|
|
125
|
+
if (batch > codes.length && batch !== KEY_SPACE_3) continue
|
|
126
|
+
|
|
127
|
+
const sample = codes.slice(0, Math.min(batch, codes.length))
|
|
128
|
+
const rounds = Math.max(5, Math.min(2000, Math.floor(200_000 / sample.length)))
|
|
129
|
+
|
|
130
|
+
results.push({
|
|
131
|
+
arm: "JS Set (baseline)",
|
|
132
|
+
input: "strings",
|
|
133
|
+
distribution,
|
|
134
|
+
batch,
|
|
135
|
+
...measure("set", sample.length, rounds, () => {
|
|
136
|
+
let count = 0
|
|
137
|
+
|
|
138
|
+
for (const code of sample) {
|
|
139
|
+
count += collisionSet.has(code) ? 1 : 0
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return count
|
|
143
|
+
}),
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
results.push({
|
|
147
|
+
arm: "TypeScript bitset",
|
|
148
|
+
input: "strings",
|
|
149
|
+
distribution,
|
|
150
|
+
batch,
|
|
151
|
+
...measure("ts", sample.length, rounds, () => {
|
|
152
|
+
let count = 0
|
|
153
|
+
|
|
154
|
+
for (const code of sample) {
|
|
155
|
+
count += isCountryAirportCollision(code) ? 1 : 0
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
return count
|
|
159
|
+
}),
|
|
160
|
+
})
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const variants = wasm.preferredWasmVariant() === "simd" ? (["scalar", "simd"] as const) : (["scalar"] as const)
|
|
165
|
+
const startup: Record<string, number> = {
|
|
166
|
+
"module import": importNs,
|
|
167
|
+
"artifact decode + validate (3 bitsets)": decodeNs,
|
|
168
|
+
"first query": firstQueryNs,
|
|
169
|
+
"JS Set build from JSON (baseline)": setBuildNs,
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
for (const variant of variants) {
|
|
173
|
+
const bytes = await readLocalBuffer(wasm.registryWasmURL(variant))
|
|
174
|
+
const compileStart = process.hrtime.bigint()
|
|
175
|
+
const registry = await wasm.createRegistry({ wasm: bytes })
|
|
176
|
+
|
|
177
|
+
startup[`wasm ${variant}: compile + instantiate + load 3 artifacts`] = nanoseconds(compileStart)
|
|
178
|
+
|
|
179
|
+
for (const [distribution, codes] of [
|
|
180
|
+
["hits", hits],
|
|
181
|
+
["misses", misses],
|
|
182
|
+
["shuffled sweep", shuffled],
|
|
183
|
+
] as const) {
|
|
184
|
+
for (const batch of batches) {
|
|
185
|
+
if (batch > codes.length && batch !== KEY_SPACE_3) continue
|
|
186
|
+
|
|
187
|
+
const sample = codes.slice(0, Math.min(batch, codes.length))
|
|
188
|
+
const input = packed(sample)
|
|
189
|
+
const out = new Uint8Array(sample.length)
|
|
190
|
+
const rounds = Math.max(5, Math.min(2000, Math.floor(200_000 / sample.length)))
|
|
191
|
+
|
|
192
|
+
results.push({
|
|
193
|
+
arm: `wasm ${variant} batch`,
|
|
194
|
+
input: "packed bytes",
|
|
195
|
+
distribution,
|
|
196
|
+
batch,
|
|
197
|
+
...measure("wasm", sample.length, rounds, () => {
|
|
198
|
+
registry.countryAirport.classifyManyInto(input, out)
|
|
199
|
+
|
|
200
|
+
let count = 0
|
|
201
|
+
|
|
202
|
+
for (const mask of out) {
|
|
203
|
+
count += mask & 4 ? 1 : 0
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
return count
|
|
207
|
+
}),
|
|
208
|
+
})
|
|
209
|
+
|
|
210
|
+
results.push({
|
|
211
|
+
arm: `wasm ${variant} batch`,
|
|
212
|
+
input: "strings (encode + copy included)",
|
|
213
|
+
distribution,
|
|
214
|
+
batch,
|
|
215
|
+
...measure("wasm-strings", sample.length, rounds, () => {
|
|
216
|
+
const masks = registry.countryAirport.classify(sample)
|
|
217
|
+
let count = 0
|
|
218
|
+
|
|
219
|
+
for (const mask of masks) {
|
|
220
|
+
count += mask & 4 ? 1 : 0
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
return count
|
|
224
|
+
}),
|
|
225
|
+
})
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
registry.dispose()
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
const manifest = await readLocalJSONFile<Record<string, { sha256: string; bytes: number }>>(
|
|
233
|
+
workspacePath("registry", "data", "manifests", "artifacts.json")
|
|
234
|
+
)
|
|
235
|
+
|
|
236
|
+
const host = {
|
|
237
|
+
node: process.version,
|
|
238
|
+
cpu: cpuModel(),
|
|
239
|
+
cores: cpuCount(),
|
|
240
|
+
memoryGB: Math.round(totalMemoryBytes() / 1e9),
|
|
241
|
+
platform: `${process.platform} ${process.arch}`,
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
if (values.json) {
|
|
245
|
+
console.log(prettyJSON({ host, startup, results, manifest }))
|
|
246
|
+
} else {
|
|
247
|
+
console.log(`Host: ${host.cpu}, ${host.cores} cores, ${host.memoryGB} GB, ${host.platform}, Node ${host.node}\n`)
|
|
248
|
+
console.log("| Startup | µs |\n| --- | --- |")
|
|
249
|
+
|
|
250
|
+
for (const [label, ns] of Object.entries(startup)) {
|
|
251
|
+
console.log(`| ${label} | ${(ns / 1000).toFixed(0)} |`)
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
console.log("\n| Arm | Input | Distribution | Batch | ns per code (median) |\n| --- | --- | --- | --- | --- |")
|
|
255
|
+
|
|
256
|
+
for (const row of results) {
|
|
257
|
+
console.log(`| ${row.arm} | ${row.input} | ${row.distribution} | ${row.batch} | ${row.nsPerCode.toFixed(1)} |`)
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
console.log("\n| Artifact | Bytes | SHA-256 |\n| --- | --- | --- |")
|
|
261
|
+
|
|
262
|
+
for (const [name, entry] of Object.entries(manifest)) {
|
|
263
|
+
console.log(`| ${name} | ${entry.bytes} | ${entry.sha256.slice(0, 16)}… |`)
|
|
264
|
+
}
|
|
265
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* Builds `crates/registry-wasm` for `wasm32-unknown-unknown` twice, once with `simd128` and once without, and
|
|
7
|
+
* writes `wasm/registry-simd.wasm` and `wasm/registry.wasm`.
|
|
8
|
+
*
|
|
9
|
+
* The two builds use separate target directories, because a `RUSTFLAGS` change would otherwise invalidate every
|
|
10
|
+
* crate in the shared target directory.
|
|
11
|
+
*
|
|
12
|
+
* With `--check`, the tool builds without writing and exits non-zero when a build's SHA-256 differs from the
|
|
13
|
+
* committed binary's.
|
|
14
|
+
*
|
|
15
|
+
* Usage: `node packages/registry/tools/build-wasm.run.ts [--check]`
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { statPath } from "@mailwoman/core/fs/readers/stat"
|
|
19
|
+
import { replaceFileAtomically } from "@mailwoman/core/fs/writers"
|
|
20
|
+
import { sha256File } from "@mailwoman/core/hash"
|
|
21
|
+
import { repoRootPath, workspacePath } from "@mailwoman/core/paths"
|
|
22
|
+
import { runFile } from "@mailwoman/core/process"
|
|
23
|
+
import { parseArguments } from "@mailwoman/core/scripting/arguments"
|
|
24
|
+
|
|
25
|
+
const { values } = parseArguments({ options: { check: { type: "boolean", default: false } } })
|
|
26
|
+
|
|
27
|
+
const workspace = workspacePath("registry")
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The two builds.
|
|
31
|
+
*
|
|
32
|
+
* The simd build passes its target feature through cargo's `--config`,
|
|
33
|
+
* so the environment stays as the caller set it.
|
|
34
|
+
*/
|
|
35
|
+
const VARIANTS = [
|
|
36
|
+
{ file: "registry.wasm", targetDir: repoRootPath("target", "registry-wasm"), config: [] },
|
|
37
|
+
{
|
|
38
|
+
file: "registry-simd.wasm",
|
|
39
|
+
targetDir: repoRootPath("target", "registry-wasm-simd"),
|
|
40
|
+
config: ["--config", 'build.rustflags=["-C","target-feature=+simd128"]'],
|
|
41
|
+
},
|
|
42
|
+
] as const
|
|
43
|
+
|
|
44
|
+
for (const variant of VARIANTS) {
|
|
45
|
+
await runFile(
|
|
46
|
+
"cargo",
|
|
47
|
+
[
|
|
48
|
+
"build",
|
|
49
|
+
"--release",
|
|
50
|
+
"--locked",
|
|
51
|
+
"--target",
|
|
52
|
+
"wasm32-unknown-unknown",
|
|
53
|
+
"-p",
|
|
54
|
+
"registry-wasm",
|
|
55
|
+
"--target-dir",
|
|
56
|
+
variant.targetDir,
|
|
57
|
+
...variant.config,
|
|
58
|
+
],
|
|
59
|
+
{ cwd: workspace }
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
const built = `${variant.targetDir}/wasm32-unknown-unknown/release/registry_wasm.wasm`
|
|
63
|
+
const committed = workspacePath("registry", "wasm", variant.file)
|
|
64
|
+
const builtDigest = await sha256File(built)
|
|
65
|
+
const { size } = await statPath(built)
|
|
66
|
+
|
|
67
|
+
if (values.check) {
|
|
68
|
+
const committedDigest = await sha256File(committed)
|
|
69
|
+
|
|
70
|
+
if (committedDigest === builtDigest) {
|
|
71
|
+
console.log(`wasm/${variant.file} matches the build: ${builtDigest} (${size} bytes)`)
|
|
72
|
+
} else {
|
|
73
|
+
console.error(`wasm/${variant.file} is stale: committed ${committedDigest}, built ${builtDigest} (${size} bytes)`)
|
|
74
|
+
|
|
75
|
+
process.exitCode = 1
|
|
76
|
+
}
|
|
77
|
+
} else {
|
|
78
|
+
await replaceFileAtomically(built, committed)
|
|
79
|
+
|
|
80
|
+
console.log(`wrote wasm/${variant.file}: ${builtDigest} (${size} bytes)`)
|
|
81
|
+
}
|
|
82
|
+
}
|