@mailwoman/resolver 10.0.0 → 10.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 +9 -7
- package/lib/admin/coherence-passes.ts +19 -160
- package/lib/admin/containment.ts +12 -30
- package/lib/admin/jp-municipality.ts +20 -13
- package/lib/admin/winner.ts +30 -62
- package/lib/backend-capabilities.ts +25 -24
- package/lib/bare-toponym-race.ts +69 -37
- package/lib/decorate-node.ts +17 -41
- package/lib/fold-name.ts +5 -18
- package/lib/index.ts +5 -9
- package/lib/plausibility.ts +35 -62
- package/lib/postcode/country-coherence.ts +64 -284
- package/lib/postcode/prefix.ts +20 -84
- package/lib/postcode/shape-coherence.ts +23 -113
- package/lib/remote-resolver.ts +32 -29
- package/lib/rerank.ts +34 -50
- package/lib/resolve/passes.ts +144 -147
- package/lib/resolve.ts +726 -0
- package/lib/span-rescore.ts +215 -172
- package/lib/street/evidence.ts +65 -73
- package/lib/street/tier.ts +33 -175
- package/lib/toponym-prior.ts +53 -179
- package/out/admin/coherence-passes.d.ts +17 -68
- package/out/admin/coherence-passes.d.ts.map +1 -1
- package/out/admin/coherence-passes.js +18 -160
- package/out/admin/coherence-passes.js.map +1 -1
- package/out/admin/containment.d.ts +11 -29
- package/out/admin/containment.d.ts.map +1 -1
- package/out/admin/containment.js +12 -30
- package/out/admin/containment.js.map +1 -1
- package/out/admin/jp-municipality.d.ts +20 -13
- package/out/admin/jp-municipality.d.ts.map +1 -1
- package/out/admin/jp-municipality.js +18 -12
- package/out/admin/jp-municipality.js.map +1 -1
- package/out/admin/winner.d.ts +30 -62
- package/out/admin/winner.d.ts.map +1 -1
- package/out/admin/winner.js +18 -51
- package/out/admin/winner.js.map +1 -1
- package/out/{admin/index.d.ts → admin.d.ts} +1 -1
- package/out/admin.d.ts.map +1 -0
- package/out/{admin/index.js → admin.js} +1 -1
- package/out/admin.js.map +1 -0
- package/out/backend-capabilities.d.ts +18 -19
- package/out/backend-capabilities.d.ts.map +1 -1
- package/out/backend-capabilities.js +25 -24
- package/out/backend-capabilities.js.map +1 -1
- package/out/bare-toponym-race.d.ts +54 -27
- package/out/bare-toponym-race.d.ts.map +1 -1
- package/out/bare-toponym-race.js +69 -37
- package/out/bare-toponym-race.js.map +1 -1
- package/out/decorate-node.d.ts +6 -8
- package/out/decorate-node.d.ts.map +1 -1
- package/out/decorate-node.js +17 -41
- package/out/decorate-node.js.map +1 -1
- package/out/fold-name.d.ts +5 -18
- package/out/fold-name.d.ts.map +1 -1
- package/out/fold-name.js +5 -18
- package/out/fold-name.js.map +1 -1
- package/out/index.d.ts +5 -6
- package/out/index.d.ts.map +1 -1
- package/out/index.js +5 -8
- package/out/index.js.map +1 -1
- package/out/plausibility.d.ts +27 -57
- package/out/plausibility.d.ts.map +1 -1
- package/out/plausibility.js +16 -49
- package/out/plausibility.js.map +1 -1
- package/out/postcode/country-coherence.d.ts +48 -162
- package/out/postcode/country-coherence.d.ts.map +1 -1
- package/out/postcode/country-coherence.js +19 -252
- package/out/postcode/country-coherence.js.map +1 -1
- package/out/postcode/prefix.d.ts +17 -68
- package/out/postcode/prefix.d.ts.map +1 -1
- package/out/postcode/prefix.js +8 -77
- package/out/postcode/prefix.js.map +1 -1
- package/out/postcode/shape-coherence.d.ts +17 -84
- package/out/postcode/shape-coherence.d.ts.map +1 -1
- package/out/postcode/shape-coherence.js +9 -105
- package/out/postcode/shape-coherence.js.map +1 -1
- package/out/{postcode/index.d.ts → postcode.d.ts} +1 -1
- package/out/postcode.d.ts.map +1 -0
- package/out/{postcode/index.js → postcode.js} +1 -1
- package/out/postcode.js.map +1 -0
- package/out/remote-resolver.d.ts +27 -28
- package/out/remote-resolver.d.ts.map +1 -1
- package/out/remote-resolver.js +9 -19
- package/out/remote-resolver.js.map +1 -1
- package/out/rerank.d.ts +28 -45
- package/out/rerank.d.ts.map +1 -1
- package/out/rerank.js +13 -38
- package/out/rerank.js.map +1 -1
- package/out/resolve/passes.d.ts +95 -85
- package/out/resolve/passes.d.ts.map +1 -1
- package/out/resolve/passes.js +40 -105
- package/out/resolve/passes.js.map +1 -1
- package/out/resolve.d.ts +15 -0
- package/out/resolve.d.ts.map +1 -0
- package/out/resolve.js +543 -0
- package/out/resolve.js.map +1 -0
- package/out/span-rescore.d.ts +51 -64
- package/out/span-rescore.d.ts.map +1 -1
- package/out/span-rescore.js +132 -130
- package/out/span-rescore.js.map +1 -1
- package/out/street/evidence.d.ts +56 -61
- package/out/street/evidence.d.ts.map +1 -1
- package/out/street/evidence.js +22 -46
- package/out/street/evidence.js.map +1 -1
- package/out/street/tier.d.ts +17 -29
- package/out/street/tier.d.ts.map +1 -1
- package/out/street/tier.js +27 -175
- package/out/street/tier.js.map +1 -1
- package/out/{street/index.d.ts → street.d.ts} +1 -1
- package/out/street.d.ts.map +1 -0
- package/out/{street/index.js → street.js} +1 -1
- package/out/street.js.map +1 -0
- package/out/toponym-prior.d.ts +21 -109
- package/out/toponym-prior.d.ts.map +1 -1
- package/out/toponym-prior.js +41 -170
- package/out/toponym-prior.js.map +1 -1
- package/package.json +44 -147
- package/lib/resolve/index.ts +0 -989
- package/out/admin/index.d.ts.map +0 -1
- package/out/admin/index.js.map +0 -1
- package/out/postcode/index.d.ts.map +0 -1
- package/out/postcode/index.js.map +0 -1
- package/out/resolve/index.d.ts +0 -20
- package/out/resolve/index.d.ts.map +0 -1
- package/out/resolve/index.js +0 -808
- package/out/resolve/index.js.map +0 -1
- package/out/street/index.d.ts.map +0 -1
- package/out/street/index.js.map +0 -1
- package/vitest.config.ts +0 -38
- /package/lib/{admin/index.ts → admin.ts} +0 -0
- /package/lib/{postcode/index.ts → postcode.ts} +0 -0
- /package/lib/{street/index.ts → street.ts} +0 -0
package/out/postcode/prefix.js
CHANGED
|
@@ -2,84 +2,22 @@
|
|
|
2
2
|
* @copyright Sister Software
|
|
3
3
|
* @license AGPL-3.0
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
|
-
*
|
|
6
|
-
* Postcode-prefix prior (#31, Mechanism 3) — the partial-code prior for postcodes the full-code
|
|
7
|
-
* gazetteer does not carry. #1480's abstention is the defect: a BT unit with no permissive source
|
|
8
|
-
* behind it (the NI half of Code-Point Open) misses the gazetteer, and the tree contributes
|
|
9
|
-
* NOTHING for it — no country scope, no district, no coordinate. This module derives the code's
|
|
10
|
-
* PREFIX and probes the PFX1 index (`postcode-prefix-<cc>.bin`), so the resolve "abstains on the
|
|
11
|
-
* UNIT and still contributes its DISTRICT": the node resolves from the prefix's centroid and/or
|
|
12
|
-
* ancestry, whichever the artifact carries.
|
|
13
|
-
*
|
|
14
|
-
* The index is a structural type (`PostcodePrefixIndexLike`, declared in `core/resolver/types.ts`),
|
|
15
|
-
* injected by the pipeline and never imported from `@mailwoman/neural` — B3-5: the probe touches
|
|
16
|
-
* zero model inputs. The loader lives in `@mailwoman/neural/postcode-prefix-index.ts` (PFX1 format:
|
|
17
|
-
* magic, header, dictionary, quantized i16 coordinates, `radiusP95Km`, ancestry); the resolver
|
|
18
|
-
* side only defines the derivation law and the probe.
|
|
19
|
-
*
|
|
20
|
-
* ## The derivation law (per artifact country)
|
|
21
|
-
*
|
|
22
|
-
* - **GB** — the OUTWARD code: the compact (whitespace-stripped) form minus its trailing 3 unit
|
|
23
|
-
* characters ("SW1A 2AA" → "SW1A", "BT9 5GS" → "BT9"). Never a greedy regex — the unit is
|
|
24
|
-
* exactly 3 chars in the compact form, and `outwardOf` in `mailwoman/gazetteer-pipeline/
|
|
25
|
-
* postcode-prefix.ts` is the build-side twin of this law.
|
|
26
|
-
* - **US** — the 3-digit section ("94043" → "940"). M-3 measured 3 digits as the first length
|
|
27
|
-
* where the ZIP prefix stops being free (145 km p95 median); a 5-digit artifact would be the
|
|
28
|
-
* full code the gazetteer already carries. No US artifact ships yet (B3-4 needs a ZCTA
|
|
29
|
-
* acquisition) — the branch exists so the law is tested before the data.
|
|
30
|
-
* - **Anything else** — abstain (null).
|
|
31
|
-
*
|
|
32
|
-
* ## The probe's country restriction
|
|
33
|
-
*
|
|
34
|
-
* The index is country-specific EVIDENCE: it is only probed when its `country` matches the
|
|
35
|
-
* query's country scope (or the scope is absent). A GB index must not speak under a US scope —
|
|
36
|
-
* the pipeline passes the locale's index, and the walk's country filter is the caller's declared
|
|
37
|
-
* universe.
|
|
38
|
-
*
|
|
39
|
-
* ## Metadata contract (what the node carries afterward)
|
|
40
|
-
*
|
|
41
|
-
* - `postcode_prefix` — the prefix string that resolved it.
|
|
42
|
-
* - `postcode_prefix_ancestors` — the ancestry the prefix asserts (coarsest-first; GB outward
|
|
43
|
-
* nodes carry country → constituent-country → district).
|
|
44
|
-
* - `postcode_prefix_radius_p95_km` — the artifact's measured p95 radius, when the node carries a
|
|
45
|
-
* coordinate (M-3's receipt: a 1-digit US band and a GB outward code differ by 200×; never read
|
|
46
|
-
* a coordinate without its radius).
|
|
47
|
-
* - `coordinate_source: "postcode_prefix"` — ONLY when the node actually carries a coordinate.
|
|
48
|
-
* The ancestry-only tier (NI's 80 BT districts) stays coordinate-free — the meaning-of-zero
|
|
49
|
-
* rule, and the half that decides B3-3: inventing a BT centroid would reproduce the `BT3 9QQ` →
|
|
50
|
-
* Sheffield defect #1480 just fixed.
|
|
51
|
-
*
|
|
52
|
-
* **D-rule: opt-in behind `ResolveOpts.postcodePrefixPrior`, default-OFF** (the PCN1 posture:
|
|
53
|
-
* data + loader + offline probe, no decode wiring; the header ships without `delta` until a
|
|
54
|
-
* calibration measures one). Bars: B3-2 (≥60% of held-out units within 10 km, zero worse than the
|
|
55
|
-
* abstention arm), B3-3 (NI ≥95% country scope GB + NIR ancestry + correct district named, 0%
|
|
56
|
-
* coordinate), B3-5 (structural — no model inputs touched).
|
|
57
|
-
*/
|
|
58
|
-
/**
|
|
59
|
-
* The MINIMUM compact code length for a GB outward derivation — a shorter code has no 3-character unit to strip ("B3"
|
|
60
|
-
* is a GB area, not a unit-bearing code).
|
|
61
5
|
*/
|
|
62
6
|
const MIN_GB_OUTWARD_CODE_LENGTH = 5;
|
|
63
|
-
/**
|
|
64
|
-
* The MINIMUM code length for a US section derivation.
|
|
65
|
-
*/
|
|
66
7
|
const MIN_US_SECTION_CODE_LENGTH = 3;
|
|
67
8
|
/**
|
|
68
|
-
*
|
|
69
|
-
*
|
|
9
|
+
* Derives the key a postcode prefix index uses for `code`: the GB outward code
|
|
10
|
+
* or the US three-digit prefix.
|
|
11
|
+
*
|
|
12
|
+
* @returns `null` for a country with no rule or a code too short to contain a prefix.
|
|
70
13
|
*/
|
|
71
14
|
export function derivePostcodePrefix(code, country) {
|
|
72
15
|
if (!code || !country)
|
|
73
16
|
return null;
|
|
74
17
|
const compact = code.replaceAll(/\s+/g, "");
|
|
75
18
|
switch (country.toUpperCase()) {
|
|
76
|
-
// The outward-code law: compact minus the trailing 3 unit characters ("SW1A2AA" → "SW1A",
|
|
77
|
-
// "BT93GS" → "BT9"). Exactly 3 — never a greedy regex, the build-side twin is `outwardOf`.
|
|
78
19
|
case "GB":
|
|
79
20
|
return compact.length >= MIN_GB_OUTWARD_CODE_LENGTH ? compact.slice(0, -3) : null;
|
|
80
|
-
// The 3-digit sectional centre ("94043" → "940"). Deliberately looser than the build side, which
|
|
81
|
-
// requires a real ZIP shape: a probe for something that is not a code simply misses, and a reader
|
|
82
|
-
// that re-derived the writer's validation would be a second copy of it.
|
|
83
21
|
case "US":
|
|
84
22
|
return compact.length >= MIN_US_SECTION_CODE_LENGTH ? compact.slice(0, 3) : null;
|
|
85
23
|
default:
|
|
@@ -87,14 +25,11 @@ export function derivePostcodePrefix(code, country) {
|
|
|
87
25
|
}
|
|
88
26
|
}
|
|
89
27
|
/**
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
* abstain — never throws, never guesses.
|
|
28
|
+
* Looks up `code`'s prefix in the index, returning `null` when the query's country
|
|
29
|
+
* differs from the index's or no indexed prefix can be derived.
|
|
93
30
|
*/
|
|
94
31
|
export function probePostcodePrefix(code, index, queryCountry) {
|
|
95
32
|
const indexCountry = index.country?.toUpperCase();
|
|
96
|
-
// Country check: the index is evidence FOR its own country only. A GB index under a US scope stays
|
|
97
|
-
// silent — the walk's country filter is the caller's declared universe.
|
|
98
33
|
if (queryCountry && indexCountry && queryCountry.toUpperCase() !== indexCountry)
|
|
99
34
|
return null;
|
|
100
35
|
const prefix = derivePostcodePrefix(code, indexCountry);
|
|
@@ -104,18 +39,14 @@ export function probePostcodePrefix(code, index, queryCountry) {
|
|
|
104
39
|
return node ? { prefix, node } : null;
|
|
105
40
|
}
|
|
106
41
|
/**
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
* present ONLY when the node carries one, so an ancestry-only hit stays coordinate-free by construction (B3-3's 0%
|
|
110
|
-
* half).
|
|
42
|
+
* Builds the synthetic `postalcode` place for a prefix hit, with `id: 0` because it is not a gazetteer row.
|
|
43
|
+
* It includes a coordinate only when the prefix node has one.
|
|
111
44
|
*/
|
|
112
45
|
export function postcodePrefixResolvedPlace(prefix, node, index) {
|
|
113
46
|
return {
|
|
114
47
|
id: 0,
|
|
115
48
|
name: prefix,
|
|
116
49
|
placetype: "postalcode",
|
|
117
|
-
// `""` = country unknown — the same empty-string convention the candidate backend uses for a row
|
|
118
|
-
// whose country_id resolves to nothing.
|
|
119
50
|
country: index.country?.toUpperCase() ?? "",
|
|
120
51
|
...(node.lat !== undefined && node.lon !== undefined ? { lat: node.lat, lon: node.lon } : {}),
|
|
121
52
|
score: 0,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prefix.js","sourceRoot":"","sources":["../../lib/postcode/prefix.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"prefix.js","sourceRoot":"","sources":["../../lib/postcode/prefix.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAaH,MAAM,0BAA0B,GAAG,CAAC,CAAA;AAEpC,MAAM,0BAA0B,GAAG,CAAC,CAAA;AAEpC;;;;;GAKG;AACH,MAAM,UAAU,oBAAoB,CAAC,IAAY,EAAE,OAAg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,EAAE,MAAM;QACZ,SAAS,EAAE,YAAY;QAEvB,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE;QAC3C,GAAG,CAAC,IAAI,CAAC,GAAG,KAAK,SAAS,IAAI,IAAI,CAAC,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC7F,KAAK,EAAE,CAAC;QACR,UAAU,EAAE,KAAK;KACjB,CAAA;AACF,CAAC"}
|
|
@@ -2,112 +2,45 @@
|
|
|
2
2
|
* @copyright Sister Software
|
|
3
3
|
* @license AGPL-3.0
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
|
-
*
|
|
6
|
-
* Postcode-shape coherence (#31, Mechanism 1) — shape as CONFIDENCE and EXCLUSION, downstream of the
|
|
7
|
-
* siblings. The fifth member of the joint-consistency coherence family (after `applyAdminCoherence`
|
|
8
|
-
* #263, `applyExplicitCountryCoherence` #822, `applyRegionCountryCoherence`, and
|
|
9
|
-
* `findPostcodeCountryScope` #42/#1477), and the only one that is pure-sync and backend-free:
|
|
10
|
-
* everything it needs is `candidateSystemsForPostcode` plus the tree.
|
|
11
|
-
*
|
|
12
|
-
* The defect (M-1, `docs/superpowers/plans/2026-08-05-postcode-structure-arc.md`): the decoder
|
|
13
|
-
* sometimes tags a HOUSE NUMBER as `postcode` when its digits form a foreign postcode shape —
|
|
14
|
-
* "1200" in "Twin Peaks Golf Course, 1200 Cornell Dr, Longmont, CO 80503" is accepted only by the
|
|
15
|
-
* AU/NZ 4-digit shape, while every sibling placetype says US. The shape alone cannot say a code is
|
|
16
|
-
* foreign (49/100 Gauntlet codes are accepted by more than one system, 10 by none), so this pass
|
|
17
|
-
* never reads the shape as country evidence by itself — it INTERSECTS each span's candidate systems
|
|
18
|
-
* with the systems the SIBLINGS already assert, and only a confident sibling set can demote.
|
|
19
|
-
*
|
|
20
|
-
* ## The rule (three outcomes, per span)
|
|
21
|
-
*
|
|
22
|
-
* 1. **Intersection non-empty → CONFIRMED.** Stamp `postcode_shape_systems` (the narrowed
|
|
23
|
-
* intersection, upper-case). Additive metadata only — resolution is byte-identical (B1-1). The
|
|
24
|
-
* same intersection narrows `findPostcodeCountryScope`'s candidate list when the caller threads
|
|
25
|
-
* it (a pure subset of codex's shape candidates — safe by construction).
|
|
26
|
-
* 2. **Intersection empty + confident siblings → EXCLUDED.** A digit-only span is demoted to
|
|
27
|
-
* `house_number` (the correct sibling tag — B1-2's "correct sibling tag surviving"); a
|
|
28
|
-
* letter-bearing span keeps its tag and gets `postcode_shape_excluded: true` instead (the
|
|
29
|
-
* compound-split corner — "15 07691" — is #942 postal-compound-recovery territory, out of
|
|
30
|
-
* scope). Either way the span's contribution to the resolve is stripped: `firstPostcodeValue`,
|
|
31
|
-
* the walk's postcode lookup, and the post-walk postcode passes all skip excluded spans.
|
|
32
|
-
* 3. **No confident siblings → ABSTAIN** (the `postcode-country-coherence.ts:269` posture
|
|
33
|
-
* verbatim). A shape no codex system recognizes (the 10/110 slice-less codes) also abstains —
|
|
34
|
-
* an empty candidate set is no evidence either way.
|
|
35
|
-
*
|
|
36
|
-
* ## What counts as a sibling signal
|
|
37
|
-
*
|
|
38
|
-
* - The **country node**, via `matchCountry`, territory-mapped: PR/VI/GU/MP/AS are USPS
|
|
39
|
-
* abbreviations (`codex/us/state.ts`), so a "Puerto Rico" token speaks for `us` — the mapping
|
|
40
|
-
* that protects the true postcode in "Ponce, 00716, Puerto Rico".
|
|
41
|
-
* - The **region node**, via `matchSubdivision` (US states + CA provinces; the US-first tiebreak
|
|
42
|
-
* that makes "CA" mean California is `matchSubdivision`'s own), plus the region's
|
|
43
|
-
* `country_hint` metadata stamp (`mailwoman/region-recognition.ts` writes it on 2-letter US
|
|
44
|
-
* state abbreviations).
|
|
45
|
-
* - Signals are filtered to the codex SystemCode universe BEFORE the intersection test. A country
|
|
46
|
-
* with no codex slice (ES, MX, IE, …) can never appear in any candidate set, so an unfiltered
|
|
47
|
-
* signal would make every intersection empty and every span "foreign" — the slice-less filter
|
|
48
|
-
* is the whole reason the JP-shaped "15 07691" span in the ES Portopetro row ABSTAINS rather
|
|
49
|
-
* than false-excludes.
|
|
50
|
-
*
|
|
51
|
-
* Deliberately NOT a signal: a second postcode span. The census's "cross-span" idea fails on the
|
|
52
|
-
* symmetric case — "2000 Sydney NSW, SW1A 2AA London" would exclude BOTH true codes (their systems
|
|
53
|
-
* are disjoint), a regression worse than the defect. Cross-country multi-postcode strings are
|
|
54
|
-
* pathological, and every M-1 span carries a country/region/`country_hint` signal instead.
|
|
55
|
-
*
|
|
56
|
-
* `defaultCountry` is never a signal: it is a LOCALE DEFAULT, not knowledge. B1-3's confound —
|
|
57
|
-
* "Sydney NSW 2000, Australia" reached with a US default must not have its 2000 excluded, and "10
|
|
58
|
-
* Downing Street, London SW1A 2AA" under a US default must not either. Those rows are exactly what
|
|
59
|
-
* `findPostcodeCountryScope` exists to rescue, and an exclusion pass that trusted the default
|
|
60
|
-
* would delete the evidence the country pass needs.
|
|
61
|
-
*
|
|
62
|
-
* ## Evidence posture
|
|
63
|
-
*
|
|
64
|
-
* M-1's six Gauntlet exclusion spans grade 4 exclusions (US "1600"/"3080"/"1200" via their region,
|
|
65
|
-
* PR "3499" via the territory-mapped country) + 2 documented abstentions (MX "2000" — no country
|
|
66
|
-
* token, "Tabasco" is not a `matchSubdivision` key; ES "15 07691" — no ES slice). Within-country,
|
|
67
|
-
* the exclusion problem is close to empty on the curated board, and a 5-digit house number in a
|
|
68
|
-
* DE/FR address is shape-native — the shape cannot exclude it (M-1 finding #1), so the mechanism
|
|
69
|
-
* CONFIRMS it instead.
|
|
70
|
-
*
|
|
71
|
-
* **D-rule: opt-in behind `ResolveOpts.postcodeShapeCoherence`, default-OFF.** Demotion is the
|
|
72
|
-
* failure mode with teeth, so a default-on promotion needs the full pre-registered eval (B1-1
|
|
73
|
-
* byte-stability, B1-2 exclusion ≥90% with the correct sibling tag surviving, B1-3 confound ≤2%
|
|
74
|
-
* false exclusions; kill on any B1-3 δ).
|
|
75
5
|
*/
|
|
76
6
|
import { type AddressNode } from "@mailwoman/core/decoder";
|
|
77
7
|
/**
|
|
78
|
-
*
|
|
79
|
-
*
|
|
8
|
+
* Records which postcode spans {@link applyPostcodeShapeCoherence} confirmed, excluded, or abstained on.
|
|
9
|
+
*
|
|
10
|
+
* It also records the postcode systems of the first confirmed span.
|
|
80
11
|
*/
|
|
81
12
|
export interface PostcodeShapeVerdict {
|
|
82
13
|
/**
|
|
83
|
-
* The
|
|
84
|
-
*
|
|
85
|
-
* confirmed.
|
|
14
|
+
* The upper-case postcode systems of the first confirmed span, passed to
|
|
15
|
+
* `findPostcodeCountryScope` as its candidate systems; `undefined` when no span was confirmed.
|
|
86
16
|
*/
|
|
87
17
|
narrowing?: string[];
|
|
88
18
|
/**
|
|
89
|
-
*
|
|
19
|
+
* Postcode values whose shape fits a system used by a sibling country or region span.
|
|
90
20
|
*/
|
|
91
21
|
confirmed: string[];
|
|
92
22
|
/**
|
|
93
|
-
*
|
|
23
|
+
* Postcode values whose shape fits none of the systems the siblings name.
|
|
94
24
|
*/
|
|
95
25
|
excluded: string[];
|
|
96
26
|
/**
|
|
97
|
-
*
|
|
27
|
+
* Postcode values left undecided because they match no known postcode shape
|
|
28
|
+
* or the tree names no country or region.
|
|
98
29
|
*/
|
|
99
30
|
abstained: string[];
|
|
100
31
|
}
|
|
101
32
|
/**
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
33
|
+
* Checks each postcode span's shape against the postcode systems of the countries
|
|
34
|
+
* and regions listed in the same tree, without querying a backend.
|
|
35
|
+
*
|
|
36
|
+
* A span that fits none of those systems is excluded: an all-digit span is retagged
|
|
37
|
+
* `house_number`, and any other span is stamped `postcode_shape_excluded`.
|
|
105
38
|
*/
|
|
106
39
|
export declare function applyPostcodeShapeCoherence(roots: readonly AddressNode[]): PostcodeShapeVerdict;
|
|
107
40
|
/**
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
*
|
|
41
|
+
* Returns true for a postcode span excluded by shape coherence when it could not be retagged.
|
|
42
|
+
*
|
|
43
|
+
* Every postcode consumer in the resolver must skip that span.
|
|
111
44
|
*/
|
|
112
45
|
export declare function isShapeExcludedPostcode(node: AddressNode): boolean;
|
|
113
46
|
//# sourceMappingURL=shape-coherence.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shape-coherence.d.ts","sourceRoot":"","sources":["../../lib/postcode/shape-coherence.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"shape-coherence.d.ts","sourceRoot":"","sources":["../../lib/postcode/shape-coherence.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAKH,OAAO,EAA2B,KAAK,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAInF;;;;GAIG;AACH,MAAM,WAAW,oBAAoB;IACpC;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,EAAE,CAAA;IAEpB;;OAEG;IACH,SAAS,EAAE,MAAM,EAAE,CAAA;IAEnB;;OAEG;IACH,QAAQ,EAAE,MAAM,EAAE,CAAA;IAElB;;;OAGG;IACH,SAAS,EAAE,MAAM,EAAE,CAAA;CACnB;AAsCD;;;;;;GAMG;AACH,wBAAgB,2BAA2B,CAAC,KAAK,EAAE,SAAS,WAAW,EAAE,GAAG,oBAAoB,CAiD/F;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,CAElE"}
|
|
@@ -2,94 +2,12 @@
|
|
|
2
2
|
* @copyright Sister Software
|
|
3
3
|
* @license AGPL-3.0
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
|
-
*
|
|
6
|
-
* Postcode-shape coherence (#31, Mechanism 1) — shape as CONFIDENCE and EXCLUSION, downstream of the
|
|
7
|
-
* siblings. The fifth member of the joint-consistency coherence family (after `applyAdminCoherence`
|
|
8
|
-
* #263, `applyExplicitCountryCoherence` #822, `applyRegionCountryCoherence`, and
|
|
9
|
-
* `findPostcodeCountryScope` #42/#1477), and the only one that is pure-sync and backend-free:
|
|
10
|
-
* everything it needs is `candidateSystemsForPostcode` plus the tree.
|
|
11
|
-
*
|
|
12
|
-
* The defect (M-1, `docs/superpowers/plans/2026-08-05-postcode-structure-arc.md`): the decoder
|
|
13
|
-
* sometimes tags a HOUSE NUMBER as `postcode` when its digits form a foreign postcode shape —
|
|
14
|
-
* "1200" in "Twin Peaks Golf Course, 1200 Cornell Dr, Longmont, CO 80503" is accepted only by the
|
|
15
|
-
* AU/NZ 4-digit shape, while every sibling placetype says US. The shape alone cannot say a code is
|
|
16
|
-
* foreign (49/100 Gauntlet codes are accepted by more than one system, 10 by none), so this pass
|
|
17
|
-
* never reads the shape as country evidence by itself — it INTERSECTS each span's candidate systems
|
|
18
|
-
* with the systems the SIBLINGS already assert, and only a confident sibling set can demote.
|
|
19
|
-
*
|
|
20
|
-
* ## The rule (three outcomes, per span)
|
|
21
|
-
*
|
|
22
|
-
* 1. **Intersection non-empty → CONFIRMED.** Stamp `postcode_shape_systems` (the narrowed
|
|
23
|
-
* intersection, upper-case). Additive metadata only — resolution is byte-identical (B1-1). The
|
|
24
|
-
* same intersection narrows `findPostcodeCountryScope`'s candidate list when the caller threads
|
|
25
|
-
* it (a pure subset of codex's shape candidates — safe by construction).
|
|
26
|
-
* 2. **Intersection empty + confident siblings → EXCLUDED.** A digit-only span is demoted to
|
|
27
|
-
* `house_number` (the correct sibling tag — B1-2's "correct sibling tag surviving"); a
|
|
28
|
-
* letter-bearing span keeps its tag and gets `postcode_shape_excluded: true` instead (the
|
|
29
|
-
* compound-split corner — "15 07691" — is #942 postal-compound-recovery territory, out of
|
|
30
|
-
* scope). Either way the span's contribution to the resolve is stripped: `firstPostcodeValue`,
|
|
31
|
-
* the walk's postcode lookup, and the post-walk postcode passes all skip excluded spans.
|
|
32
|
-
* 3. **No confident siblings → ABSTAIN** (the `postcode-country-coherence.ts:269` posture
|
|
33
|
-
* verbatim). A shape no codex system recognizes (the 10/110 slice-less codes) also abstains —
|
|
34
|
-
* an empty candidate set is no evidence either way.
|
|
35
|
-
*
|
|
36
|
-
* ## What counts as a sibling signal
|
|
37
|
-
*
|
|
38
|
-
* - The **country node**, via `matchCountry`, territory-mapped: PR/VI/GU/MP/AS are USPS
|
|
39
|
-
* abbreviations (`codex/us/state.ts`), so a "Puerto Rico" token speaks for `us` — the mapping
|
|
40
|
-
* that protects the true postcode in "Ponce, 00716, Puerto Rico".
|
|
41
|
-
* - The **region node**, via `matchSubdivision` (US states + CA provinces; the US-first tiebreak
|
|
42
|
-
* that makes "CA" mean California is `matchSubdivision`'s own), plus the region's
|
|
43
|
-
* `country_hint` metadata stamp (`mailwoman/region-recognition.ts` writes it on 2-letter US
|
|
44
|
-
* state abbreviations).
|
|
45
|
-
* - Signals are filtered to the codex SystemCode universe BEFORE the intersection test. A country
|
|
46
|
-
* with no codex slice (ES, MX, IE, …) can never appear in any candidate set, so an unfiltered
|
|
47
|
-
* signal would make every intersection empty and every span "foreign" — the slice-less filter
|
|
48
|
-
* is the whole reason the JP-shaped "15 07691" span in the ES Portopetro row ABSTAINS rather
|
|
49
|
-
* than false-excludes.
|
|
50
|
-
*
|
|
51
|
-
* Deliberately NOT a signal: a second postcode span. The census's "cross-span" idea fails on the
|
|
52
|
-
* symmetric case — "2000 Sydney NSW, SW1A 2AA London" would exclude BOTH true codes (their systems
|
|
53
|
-
* are disjoint), a regression worse than the defect. Cross-country multi-postcode strings are
|
|
54
|
-
* pathological, and every M-1 span carries a country/region/`country_hint` signal instead.
|
|
55
|
-
*
|
|
56
|
-
* `defaultCountry` is never a signal: it is a LOCALE DEFAULT, not knowledge. B1-3's confound —
|
|
57
|
-
* "Sydney NSW 2000, Australia" reached with a US default must not have its 2000 excluded, and "10
|
|
58
|
-
* Downing Street, London SW1A 2AA" under a US default must not either. Those rows are exactly what
|
|
59
|
-
* `findPostcodeCountryScope` exists to rescue, and an exclusion pass that trusted the default
|
|
60
|
-
* would delete the evidence the country pass needs.
|
|
61
|
-
*
|
|
62
|
-
* ## Evidence posture
|
|
63
|
-
*
|
|
64
|
-
* M-1's six Gauntlet exclusion spans grade 4 exclusions (US "1600"/"3080"/"1200" via their region,
|
|
65
|
-
* PR "3499" via the territory-mapped country) + 2 documented abstentions (MX "2000" — no country
|
|
66
|
-
* token, "Tabasco" is not a `matchSubdivision` key; ES "15 07691" — no ES slice). Within-country,
|
|
67
|
-
* the exclusion problem is close to empty on the curated board, and a 5-digit house number in a
|
|
68
|
-
* DE/FR address is shape-native — the shape cannot exclude it (M-1 finding #1), so the mechanism
|
|
69
|
-
* CONFIRMS it instead.
|
|
70
|
-
*
|
|
71
|
-
* **D-rule: opt-in behind `ResolveOpts.postcodeShapeCoherence`, default-OFF.** Demotion is the
|
|
72
|
-
* failure mode with teeth, so a default-on promotion needs the full pre-registered eval (B1-1
|
|
73
|
-
* byte-stability, B1-2 exclusion ≥90% with the correct sibling tag surviving, B1-3 confound ≤2%
|
|
74
|
-
* false exclusions; kill on any B1-3 δ).
|
|
75
5
|
*/
|
|
76
6
|
import { candidateSystemsForPostcode, SYSTEM_CODES } from "@mailwoman/codex";
|
|
77
7
|
import { matchCountry, matchSubdivision } from "@mailwoman/codex/country";
|
|
78
8
|
import { isUSStateAbbreviation } from "@mailwoman/codex/us";
|
|
79
9
|
import { collectNodes, walkNodes } from "@mailwoman/core/decoder";
|
|
80
|
-
/**
|
|
81
|
-
* The codex address systems a sibling signal can speak for — the universe `candidateSystemsForPostcode` can return, in
|
|
82
|
-
* the upper-case ISO form this module's signals are emitted in (`SystemCode` itself is lower-case). Signals from
|
|
83
|
-
* countries with no codex slice are filtered out BEFORE the intersection test, so a slice-less country can never
|
|
84
|
-
* manufacture an empty intersection (the false-exclusion trap; see the header). Derived from codex's own list so a
|
|
85
|
-
* system added there is admitted here in the same change.
|
|
86
|
-
*/
|
|
87
10
|
const SYSTEM_UNIVERSE = new Set(SYSTEM_CODES.map((system) => system.toUpperCase()));
|
|
88
|
-
/**
|
|
89
|
-
* Collect the sibling country signals: the country node (territory-mapped), the region node (`matchSubdivision` +
|
|
90
|
-
* `country_hint`), each filtered to the codex SystemCode universe. The tree is walked once for ALL postcode spans —
|
|
91
|
-
* sibling evidence is tree-level, not per-span.
|
|
92
|
-
*/
|
|
93
11
|
function collectSiblingSystems(roots) {
|
|
94
12
|
const out = new Set();
|
|
95
13
|
for (const n of walkNodes(roots)) {
|
|
@@ -97,8 +15,6 @@ function collectSiblingSystems(roots) {
|
|
|
97
15
|
const matched = matchCountry(n.value);
|
|
98
16
|
if (!matched)
|
|
99
17
|
continue;
|
|
100
|
-
// Territory map: PR/VI/GU/MP/AS are USPS state-or-territory abbreviations (codex/us/state.ts),
|
|
101
|
-
// so a US-territory country token ("Puerto Rico", "Guam") is a US-system signal.
|
|
102
18
|
const system = isUSStateAbbreviation(matched.iso2) ? "US" : matched.iso2.toUpperCase();
|
|
103
19
|
if (SYSTEM_UNIVERSE.has(system)) {
|
|
104
20
|
out.add(system);
|
|
@@ -106,9 +22,6 @@ function collectSiblingSystems(roots) {
|
|
|
106
22
|
continue;
|
|
107
23
|
}
|
|
108
24
|
if (n.tag === "region") {
|
|
109
|
-
// (a) The region's value as a subdivision ("CA" → US, "ON" → CA — the US-wins tiebreak for
|
|
110
|
-
// "CA" is matchSubdivision's own). (b) The `country_hint` stamp annotateUSRegions writes on
|
|
111
|
-
// 2-letter US state abbreviations — the same evidence via the pipeline's other path.
|
|
112
25
|
const sub = matchSubdivision(n.value);
|
|
113
26
|
if (sub && SYSTEM_UNIVERSE.has(sub.country.toUpperCase())) {
|
|
114
27
|
out.add(sub.country.toUpperCase());
|
|
@@ -122,23 +35,21 @@ function collectSiblingSystems(roots) {
|
|
|
122
35
|
return out;
|
|
123
36
|
}
|
|
124
37
|
/**
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
*
|
|
38
|
+
* Checks each postcode span's shape against the postcode systems of the countries
|
|
39
|
+
* and regions listed in the same tree, without querying a backend.
|
|
40
|
+
*
|
|
41
|
+
* A span that fits none of those systems is excluded: an all-digit span is retagged
|
|
42
|
+
* `house_number`, and any other span is stamped `postcode_shape_excluded`.
|
|
128
43
|
*/
|
|
129
44
|
export function applyPostcodeShapeCoherence(roots) {
|
|
130
45
|
const verdict = { confirmed: [], excluded: [], abstained: [] };
|
|
131
|
-
|
|
132
|
-
// "first confirmed" is the node `state.postcode` will read.
|
|
133
|
-
const postcodes = collectNodes(roots, (n) => n.tag === "postcode" && n.value.trim().length > 0);
|
|
46
|
+
const postcodes = collectNodes(roots, (n) => n.tag === "postcode" && n.value.trim());
|
|
134
47
|
if (!postcodes.length)
|
|
135
48
|
return verdict;
|
|
136
49
|
const siblingSystems = collectSiblingSystems(roots);
|
|
137
50
|
for (const node of postcodes) {
|
|
138
51
|
const code = node.value.trim();
|
|
139
52
|
const systems = candidateSystemsForPostcode(code);
|
|
140
|
-
// A shape no codex system recognizes is no evidence either way — abstain (the 10/110
|
|
141
|
-
// slice-less Gauntlet codes: IE Eircode, SI, IM, …).
|
|
142
53
|
if (!systems.length) {
|
|
143
54
|
verdict.abstained.push(code);
|
|
144
55
|
continue;
|
|
@@ -146,8 +57,6 @@ export function applyPostcodeShapeCoherence(roots) {
|
|
|
146
57
|
const intersection = systems.map((system) => system.toUpperCase()).filter((system) => siblingSystems.has(system));
|
|
147
58
|
if (intersection.length) {
|
|
148
59
|
verdict.confirmed.push(code);
|
|
149
|
-
// Additive only — resolution stays byte-identical (B1-1). The narrowed intersection is the
|
|
150
|
-
// candidate set the country-scope pass should bound itself to.
|
|
151
60
|
node.metadata = { ...node.metadata, postcode_shape_systems: intersection };
|
|
152
61
|
if (verdict.narrowing === undefined) {
|
|
153
62
|
verdict.narrowing = intersection;
|
|
@@ -155,9 +64,6 @@ export function applyPostcodeShapeCoherence(roots) {
|
|
|
155
64
|
continue;
|
|
156
65
|
}
|
|
157
66
|
if (siblingSystems.size) {
|
|
158
|
-
// Confident siblings, empty intersection → EXCLUDED. A digit-only span is demoted to its
|
|
159
|
-
// correct sibling tag (B1-2); a letter-bearing span (the "15 07691" compound corner) keeps
|
|
160
|
-
// its tag and is stamped instead — either way every resolve consumer skips it.
|
|
161
67
|
verdict.excluded.push(code);
|
|
162
68
|
if (/^\d+$/.test(code)) {
|
|
163
69
|
node.tag = "house_number";
|
|
@@ -167,16 +73,14 @@ export function applyPostcodeShapeCoherence(roots) {
|
|
|
167
73
|
}
|
|
168
74
|
continue;
|
|
169
75
|
}
|
|
170
|
-
// No confident siblings — the same abstention posture postcode-country-coherence.ts:269 takes
|
|
171
|
-
// on zero-or-two coherent countries. Never guess with the shape alone.
|
|
172
76
|
verdict.abstained.push(code);
|
|
173
77
|
}
|
|
174
78
|
return verdict;
|
|
175
79
|
}
|
|
176
80
|
/**
|
|
177
|
-
*
|
|
178
|
-
*
|
|
179
|
-
*
|
|
81
|
+
* Returns true for a postcode span excluded by shape coherence when it could not be retagged.
|
|
82
|
+
*
|
|
83
|
+
* Every postcode consumer in the resolver must skip that span.
|
|
180
84
|
*/
|
|
181
85
|
export function isShapeExcludedPostcode(node) {
|
|
182
86
|
return node.tag === "postcode" && node.metadata?.["postcode_shape_excluded"] === true;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shape-coherence.js","sourceRoot":"","sources":["../../lib/postcode/shape-coherence.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"shape-coherence.js","sourceRoot":"","sources":["../../lib/postcode/shape-coherence.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,2BAA2B,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAC5E,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAA;AACzE,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAA;AA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C,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;YAE5B,IAAI,CAAC,QAAQ,GAAG,EAAE,GAAG,IAAI,CAAC,QAAQ,EAAE,sBAAsB,EAAE,YAAY,EAAE,CAAA;YAE1E,IAAI,OAAO,CAAC,SAAS,KAAK,SAAS,EAAE,CAAC;gBACrC,OAAO,CAAC,SAAS,GAAG,YAAY,CAAA;YACjC,CAAC;YAED,SAAQ;QACT,CAAC;QAED,IAAI,cAAc,CAAC,IAAI,EAAE,CAAC;YACzB,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;YAE3B,IAAI,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;gBACxB,IAAI,CAAC,GAAG,GAAG,cAAc,CAAA;YAC1B,CAAC;iBAAM,CAAC;gBACP,IAAI,CAAC,QAAQ,GAAG,EAAE,GAAG,IAAI,CAAC,QAAQ,EAAE,uBAAuB,EAAE,IAAI,EAAE,CAAA;YACpE,CAAC;YAED,SAAQ;QACT,CAAC;QAED,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAC7B,CAAC;IAED,OAAO,OAAO,CAAA;AACf,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,uBAAuB,CAAC,IAAiB;IACxD,OAAO,IAAI,CAAC,GAAG,KAAK,UAAU,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC,yBAAyB,CAAC,KAAK,IAAI,CAAA;AACtF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postcode.d.ts","sourceRoot":"","sources":["../lib/postcode.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,6BAA6B,CAAA;AAC3C,cAAc,kBAAkB,CAAA;AAChC,cAAc,2BAA2B,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postcode.js","sourceRoot":"","sources":["../lib/postcode.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,6BAA6B,CAAA;AAC3C,cAAc,kBAAkB,CAAA;AAChC,cAAc,2BAA2B,CAAA"}
|
package/out/remote-resolver.d.ts
CHANGED
|
@@ -2,34 +2,24 @@
|
|
|
2
2
|
* @copyright Sister Software
|
|
3
3
|
* @license AGPL-3.0
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
|
-
*
|
|
6
|
-
* `RemoteResolver` — the `Resolver` interface (`resolveTree`) over HTTP. The adapter the interface
|
|
7
|
-
* docstring anticipated (Phase 4.4): a client POSTs a parsed `AddressTree` + the serializable
|
|
8
|
-
* `ResolveOpts` to a resolver service, which owns the gazetteer + situs/interpolation extracts,
|
|
9
|
-
* runs the cascade, and returns the resolved tree. Two payoffs:
|
|
10
|
-
*
|
|
11
|
-
* 1. **Multi-instance** — stateless parser nodes (the ~30 MB ONNX model) talk to ONE resolver service
|
|
12
|
-
* (the multi-GB gazetteer + extracts). `parse` locally, `new RemoteResolver(...).resolveTree`
|
|
13
|
-
* remotely — same interface the in-process `WOFResolver` satisfies, so it's a drop-in.
|
|
14
|
-
* 2. **Canary** — point it at a second resolver build (or an adapter fronting Pelias/Nominatim/BAN)
|
|
15
|
-
* and diff the resolved trees through the identical contract.
|
|
16
|
-
*
|
|
17
|
-
* Pure transport: `fetch` only, no node-specific deps (runs in the browser too). The
|
|
18
|
-
* `addressPoints` / `interpolation` opts are LIVE SQLite handles — not serializable — so they're
|
|
19
|
-
* stripped before the POST; the resolver service supplies its own from the tree's region (the
|
|
20
|
-
* data lives server-side, which is the whole point). All other opts (defaultCountry, calibration,
|
|
21
|
-
* hierarchyCompletion, …) ride along.
|
|
22
5
|
*/
|
|
23
6
|
import type { AddressTree } from "@mailwoman/core/decoder";
|
|
24
7
|
import type { ResolveOpts, Resolver } from "@mailwoman/core/resolver";
|
|
25
8
|
/**
|
|
26
|
-
* `ResolveOpts`
|
|
9
|
+
* Describes the `ResolveOpts` sent over the wire.
|
|
10
|
+
*
|
|
11
|
+
* The options omit live `addressPoints` and `interpolation` lookup handles
|
|
12
|
+
* because they cannot be serialized.
|
|
27
13
|
*/
|
|
28
14
|
export type SerializableResolveOpts = Omit<ResolveOpts, "addressPoints" | "interpolation">;
|
|
29
15
|
/**
|
|
30
|
-
* Strip the live lookup handles from `ResolveOpts` so the rest can be JSON-serialized over
|
|
16
|
+
* Strip the live lookup handles from `ResolveOpts` so the rest can be JSON-serialized over http.
|
|
31
17
|
*/
|
|
32
18
|
export declare function serializableResolveOpts(opts?: ResolveOpts): SerializableResolveOpts | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* Describes the subset of `fetch` that {@link RemoteResolver} calls,
|
|
21
|
+
* so callers can inject a custom or test implementation.
|
|
22
|
+
*/
|
|
33
23
|
export type RemoteResolverFetch = (url: string, init: {
|
|
34
24
|
method: string;
|
|
35
25
|
headers: Record<string, string>;
|
|
@@ -41,30 +31,33 @@ export type RemoteResolverFetch = (url: string, init: {
|
|
|
41
31
|
statusText: string;
|
|
42
32
|
json(): Promise<unknown>;
|
|
43
33
|
}>;
|
|
34
|
+
/**
|
|
35
|
+
* Configures a {@link RemoteResolver}: the endpoint to POST to, an optional `fetch`,
|
|
36
|
+
* a timeout (10 seconds by default), and extra request headers.
|
|
37
|
+
*/
|
|
44
38
|
export interface RemoteResolverOpts {
|
|
45
39
|
/**
|
|
46
|
-
*
|
|
40
|
+
* Gives the full URL of the resolver service's resolve-tree endpoint,
|
|
41
|
+
* such as `http://resolver:7081/v1/resolve`.
|
|
47
42
|
*/
|
|
48
43
|
endpoint: string;
|
|
49
44
|
/**
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
* Typed by what this module reads — `ok`, `status`, `statusText`, `json()` — rather than the full `fetch`, whose
|
|
53
|
-
* `Response` carries a body stream and headers no code here touches. The global `fetch` satisfies this shape, and a
|
|
54
|
-
* test double can be an object instead of an assertion.
|
|
45
|
+
* Supplies a fetch implementation for tests or custom agents, defaulting to the global `fetch`.
|
|
55
46
|
*/
|
|
56
47
|
fetch?: RemoteResolverFetch;
|
|
57
48
|
/**
|
|
58
|
-
*
|
|
49
|
+
* Sets the per-request timeout in milliseconds, defaulting to 10,000.
|
|
59
50
|
*/
|
|
60
51
|
timeoutMs?: number;
|
|
61
52
|
/**
|
|
62
|
-
*
|
|
53
|
+
* Adds request headers such as auth or tracing.
|
|
54
|
+
*
|
|
55
|
+
* The resolver merges them over the default `Content-Type: application/json`.
|
|
63
56
|
*/
|
|
64
57
|
headers?: Record<string, string>;
|
|
65
58
|
}
|
|
66
59
|
/**
|
|
67
|
-
* The wire request body `
|
|
60
|
+
* The wire request body `post <endpoint>` expects (and the matching server handler parses).
|
|
68
61
|
*/
|
|
69
62
|
export interface ResolveTreeRequest {
|
|
70
63
|
tree: AddressTree;
|
|
@@ -76,6 +69,12 @@ export interface ResolveTreeRequest {
|
|
|
76
69
|
export interface ResolveTreeResponse {
|
|
77
70
|
tree: AddressTree;
|
|
78
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* Resolves address trees by POSTing them to a remote resolver endpoint, so a client
|
|
74
|
+
* can resolve without loading gazetteer databases itself.
|
|
75
|
+
*
|
|
76
|
+
* Live lookup handles in `ResolveOpts` are dropped before sending, so the server resolves with its own.
|
|
77
|
+
*/
|
|
79
78
|
export declare class RemoteResolver implements Resolver {
|
|
80
79
|
#private;
|
|
81
80
|
constructor(opts: RemoteResolverOpts);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remote-resolver.d.ts","sourceRoot":"","sources":["../lib/remote-resolver.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"remote-resolver.d.ts","sourceRoot":"","sources":["../lib/remote-resolver.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAE1D,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAA;AAErE;;;;;GAKG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