@mailwoman/resolver 10.0.0 → 10.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (134) hide show
  1. package/README.md +9 -7
  2. package/lib/admin/coherence-passes.ts +31 -172
  3. package/lib/admin/containment.ts +15 -33
  4. package/lib/admin/jp-municipality.ts +21 -14
  5. package/lib/admin/winner.ts +37 -69
  6. package/lib/backend-capabilities.ts +28 -27
  7. package/lib/bare-toponym-race.ts +69 -37
  8. package/lib/decorate-node.ts +25 -49
  9. package/lib/fold-name.ts +5 -18
  10. package/lib/index.ts +5 -9
  11. package/lib/plausibility.ts +41 -68
  12. package/lib/postcode/country-coherence.ts +92 -296
  13. package/lib/postcode/prefix.ts +24 -86
  14. package/lib/postcode/shape-coherence.ts +26 -116
  15. package/lib/remote-resolver.ts +38 -33
  16. package/lib/rerank.ts +41 -54
  17. package/lib/resolve/passes.ts +188 -177
  18. package/lib/resolve.ts +744 -0
  19. package/lib/span-rescore.ts +219 -175
  20. package/lib/street/evidence.ts +65 -73
  21. package/lib/street/tier.ts +51 -194
  22. package/lib/toponym-prior.ts +54 -180
  23. package/out/admin/coherence-passes.d.ts +18 -69
  24. package/out/admin/coherence-passes.d.ts.map +1 -1
  25. package/out/admin/coherence-passes.js +24 -166
  26. package/out/admin/coherence-passes.js.map +1 -1
  27. package/out/admin/containment.d.ts +13 -31
  28. package/out/admin/containment.d.ts.map +1 -1
  29. package/out/admin/containment.js +13 -31
  30. package/out/admin/containment.js.map +1 -1
  31. package/out/admin/jp-municipality.d.ts +21 -14
  32. package/out/admin/jp-municipality.d.ts.map +1 -1
  33. package/out/admin/jp-municipality.js +18 -12
  34. package/out/admin/jp-municipality.js.map +1 -1
  35. package/out/admin/winner.d.ts +32 -64
  36. package/out/admin/winner.d.ts.map +1 -1
  37. package/out/admin/winner.js +23 -56
  38. package/out/admin/winner.js.map +1 -1
  39. package/out/{admin/index.d.ts → admin.d.ts} +1 -1
  40. package/out/admin.d.ts.map +1 -0
  41. package/out/{admin/index.js → admin.js} +1 -1
  42. package/out/admin.js.map +1 -0
  43. package/out/backend-capabilities.d.ts +19 -20
  44. package/out/backend-capabilities.d.ts.map +1 -1
  45. package/out/backend-capabilities.js +28 -26
  46. package/out/backend-capabilities.js.map +1 -1
  47. package/out/bare-toponym-race.d.ts +54 -27
  48. package/out/bare-toponym-race.d.ts.map +1 -1
  49. package/out/bare-toponym-race.js +69 -37
  50. package/out/bare-toponym-race.js.map +1 -1
  51. package/out/decorate-node.d.ts +6 -8
  52. package/out/decorate-node.d.ts.map +1 -1
  53. package/out/decorate-node.js +25 -49
  54. package/out/decorate-node.js.map +1 -1
  55. package/out/fold-name.d.ts +5 -18
  56. package/out/fold-name.d.ts.map +1 -1
  57. package/out/fold-name.js +5 -18
  58. package/out/fold-name.js.map +1 -1
  59. package/out/index.d.ts +5 -6
  60. package/out/index.d.ts.map +1 -1
  61. package/out/index.js +5 -8
  62. package/out/index.js.map +1 -1
  63. package/out/plausibility.d.ts +30 -60
  64. package/out/plausibility.d.ts.map +1 -1
  65. package/out/plausibility.js +19 -52
  66. package/out/plausibility.js.map +1 -1
  67. package/out/postcode/country-coherence.d.ts +53 -167
  68. package/out/postcode/country-coherence.d.ts.map +1 -1
  69. package/out/postcode/country-coherence.js +42 -259
  70. package/out/postcode/country-coherence.js.map +1 -1
  71. package/out/postcode/prefix.d.ts +18 -69
  72. package/out/postcode/prefix.d.ts.map +1 -1
  73. package/out/postcode/prefix.js +11 -78
  74. package/out/postcode/prefix.js.map +1 -1
  75. package/out/postcode/shape-coherence.d.ts +18 -85
  76. package/out/postcode/shape-coherence.d.ts.map +1 -1
  77. package/out/postcode/shape-coherence.js +11 -107
  78. package/out/postcode/shape-coherence.js.map +1 -1
  79. package/out/{postcode/index.d.ts → postcode.d.ts} +1 -1
  80. package/out/postcode.d.ts.map +1 -0
  81. package/out/{postcode/index.js → postcode.js} +1 -1
  82. package/out/postcode.js.map +1 -0
  83. package/out/remote-resolver.d.ts +32 -31
  84. package/out/remote-resolver.d.ts.map +1 -1
  85. package/out/remote-resolver.js +12 -20
  86. package/out/remote-resolver.js.map +1 -1
  87. package/out/rerank.d.ts +32 -46
  88. package/out/rerank.d.ts.map +1 -1
  89. package/out/rerank.js +16 -41
  90. package/out/rerank.js.map +1 -1
  91. package/out/resolve/passes.d.ts +108 -95
  92. package/out/resolve/passes.d.ts.map +1 -1
  93. package/out/resolve/passes.js +67 -126
  94. package/out/resolve/passes.js.map +1 -1
  95. package/out/resolve.d.ts +15 -0
  96. package/out/resolve.d.ts.map +1 -0
  97. package/out/resolve.js +557 -0
  98. package/out/resolve.js.map +1 -0
  99. package/out/span-rescore.d.ts +56 -65
  100. package/out/span-rescore.d.ts.map +1 -1
  101. package/out/span-rescore.js +134 -132
  102. package/out/span-rescore.js.map +1 -1
  103. package/out/street/evidence.d.ts +56 -61
  104. package/out/street/evidence.d.ts.map +1 -1
  105. package/out/street/evidence.js +22 -46
  106. package/out/street/evidence.js.map +1 -1
  107. package/out/street/tier.d.ts +18 -30
  108. package/out/street/tier.d.ts.map +1 -1
  109. package/out/street/tier.js +43 -191
  110. package/out/street/tier.js.map +1 -1
  111. package/out/{street/index.d.ts → street.d.ts} +1 -1
  112. package/out/street.d.ts.map +1 -0
  113. package/out/{street/index.js → street.js} +1 -1
  114. package/out/street.js.map +1 -0
  115. package/out/toponym-prior.d.ts +22 -110
  116. package/out/toponym-prior.d.ts.map +1 -1
  117. package/out/toponym-prior.js +41 -170
  118. package/out/toponym-prior.js.map +1 -1
  119. package/package.json +44 -147
  120. package/lib/resolve/index.ts +0 -989
  121. package/out/admin/index.d.ts.map +0 -1
  122. package/out/admin/index.js.map +0 -1
  123. package/out/postcode/index.d.ts.map +0 -1
  124. package/out/postcode/index.js.map +0 -1
  125. package/out/resolve/index.d.ts +0 -20
  126. package/out/resolve/index.d.ts.map +0 -1
  127. package/out/resolve/index.js +0 -808
  128. package/out/resolve/index.js.map +0 -1
  129. package/out/street/index.d.ts.map +0 -1
  130. package/out/street/index.js.map +0 -1
  131. package/vitest.config.ts +0 -38
  132. /package/lib/{admin/index.ts → admin.ts} +0 -0
  133. /package/lib/{postcode/index.ts → postcode.ts} +0 -0
  134. /package/lib/{street/index.ts → street.ts} +0 -0
@@ -2,32 +2,33 @@
2
2
  * @copyright Sister Software
3
3
  * @license AGPL-3.0
4
4
  * @author Teffen Ellis, et al.
5
- * @file The resolver walk's per-node machinery: the trace recorder and its diagnostic bands, the walk's
6
- * `ResolutionState`, and the span-rescore / postcode-recovery / postcode-consistency passes the walk applies.
7
- * Split from `resolve.ts`, which owns `WOFResolver` — the walk itself over what this module provides.
8
5
  */
9
6
  import type { PlacetypeMap } from "@mailwoman/codex/placetype-map";
10
7
  import { type AddressNode } from "@mailwoman/core/decoder";
11
- import { type CoincidentLocality, type ResolveNodeTrace, type PostcodePrefixIndexLike, type ResolvedPlace, type ResolveOpts, type ResolverBackend } from "@mailwoman/core/resolver";
8
+ import { type CoincidentLocality, type DefaultCountry, type ResolveNodeTrace, type PostcodePrefixIndexLike, type ResolvedPlace, type ResolveOpts, type ResolverBackend, type ResolveSwitches } from "@mailwoman/core/resolver";
12
9
  import type { CoordinateOptionalPlace } from "#postcode/prefix";
13
10
  /**
14
- * The admin bands `ResolveOpts.diagnoseUnreachable` re-probes, coarse to fine.
11
+ * {@link ResolveOpts} with every {@link ResolveSwitches} key resolved against its default.
12
+ */
13
+ export type ResolvedOpts = ResolveOpts & ResolveSwitches;
14
+ /**
15
+ * The admin placetypes from country to microhood that `ResolveOpts.diagnoseUnreachable`
16
+ * re-probes, coarse to fine.
15
17
  *
16
- * Derived from `PLACETYPE_SPECIFICITY` rather than typed out, so a placetype added there is probed here without anyone
17
- * remembering to.
18
+ * The list derives from `PLACETYPE_SPECIFICITY`, so a new placetype in that range is probed automatically.
18
19
  */
19
20
  export declare const DIAGNOSTIC_BANDS: readonly string[];
20
21
  /**
21
- * Per-lookup trace bookkeeping (#1721). `#lookupAndPick` talks to ONE of these unconditionally — a real recorder when
22
- * `ResolveOpts.traceSink` is set, the frozen {@link NOOP_TRACE_RECORDER} otherwise — so the hot path carries no
23
- * per-event branches and the no-sink walk costs a handful of empty calls per node.
22
+ * Collects the trace for one placetype lookup and emits it as a `ResolveNodeTrace`;
23
+ * the walk always calls one and uses {@link NOOP_TRACE_RECORDER} when no trace
24
+ * sink is set, so the hot path has no per-event branches.
24
25
  */
25
26
  export interface NodeTraceRecorder {
26
27
  bind(node: AddressNode, placetype: string, query: {
27
28
  country?: string;
28
29
  parentID?: string | number;
29
- postcode?: string;
30
- regionQualifier?: string;
30
+ postcode?: string | null;
31
+ regionQualifier?: string | null;
31
32
  limit?: number;
32
33
  }, defaultLimit: number): void;
33
34
  check(name: string): void;
@@ -36,62 +37,78 @@ export interface NodeTraceRecorder {
36
37
  emit(picked: NonNullable<ResolveNodeTrace["picked"]> | null): void;
37
38
  }
38
39
  /**
39
- * A recorder that records nothing — the walk's default when no trace was requested.
40
+ * A {@link NodeTraceRecorder} that records no events, for walks without a trace sink.
40
41
  */
41
42
  export declare const NOOP_TRACE_RECORDER: NodeTraceRecorder;
43
+ /**
44
+ * Creates a {@link NodeTraceRecorder} that sends one `ResolveNodeTrace` to `sink` on `emit`,
45
+ * listing at most ten candidates from the last stage with each candidate's rank in every stage.
46
+ */
42
47
  export declare function createNodeTraceRecorder(sink: (record: ResolveNodeTrace) => void): NodeTraceRecorder;
48
+ /**
49
+ * The options and mutable state that one `resolveTree` call passes through its tree walk.
50
+ */
43
51
  export interface ResolutionState {
44
52
  lookupsRemaining: number;
45
53
  placetypeMap: PlacetypeMap;
46
54
  minWinningScore: number;
55
+ /**
56
+ * The count of lookups rejected by {@link ResolutionState.minWinningScore}.
57
+ *
58
+ * A nonzero count skips the span-rescore pass.
59
+ * That pass would otherwise treat the refused node as unresolved and repeat the rejected lookup.
60
+ */
61
+ minScoreRefusals: number;
47
62
  candidatesPerLookup: number;
48
- defaultCountry?: string;
49
63
  /**
50
- * Whether {@link defaultCountry} came from the locale rather than the caller. Consulted only by `country`-placetype
51
- * lookups, which skip an inferred scope — see `ResolveOpts.defaultCountryIsInferred`.
64
+ * The default country scope, or null for none.
65
+ *
66
+ * `country` lookups ignore an inferred default.
52
67
  */
53
- defaultCountryIsInferred: boolean;
68
+ defaultCountry: DefaultCountry | null;
54
69
  /**
55
- * The tree's single value-bearing node when it is locality-tagged (the bare-toponym shape), else null. Checks the
56
- * country-placetype sibling race in `#lookupAndPick` — a bare name can be a country the parser tagged `locality`
57
- * ("Japan", "China"), and the locality placetype filter makes the country row unreachable no matter how it ranks.
70
+ * The tree's only value-bearing node when it maps to `locality`, or null otherwise.
71
+ *
72
+ * Its lookup also probes countries and regions of the same name, because the locality
73
+ * placetype filter cannot reach a country that the parser tagged as a locality.
58
74
  */
59
75
  bareLocalityNode: AddressNode | null;
60
76
  parentFallback: boolean;
61
77
  /**
62
- * The address's postcode string, extracted once up front, passed to locality lookups so a coordinate-first backend
63
- * can inject postcode-proximal locality candidates.
78
+ * The tree's first postcode value.
79
+ *
80
+ * Locality lookups send it to the backend.
81
+ * The backend can then favor nearby candidates.
64
82
  */
65
- postcode?: string;
83
+ postcode?: string | null;
66
84
  /**
67
- * Postcode-containment coherence (#31, Mechanism 2) — forwarded to locality lookups so a coordinate-first backend can
68
- * re-rank name candidates by proximity to the postcode's own centroid. Opt-in; OFF by default.
85
+ * Whether locality lookups ask the backend to re-rank candidates by distance to the postcode centroid.
69
86
  */
70
87
  postcodeContainmentCoherence: boolean;
71
88
  /**
72
- * Postcode-prefix prior (#31, Mechanism 3) — on a `postalcode` miss, derive the code's prefix and probe
73
- * `postcodePrefixIndex`. Opt-in; OFF by default.
89
+ * Whether a `postalcode` lookup that misses falls back to {@link ResolutionState.postcodePrefixIndex}.
74
90
  */
75
91
  postcodePrefixPrior: boolean;
76
92
  /**
77
- * #1589 — the countries the parsed postcode's FORMAT implies (the #928 singles plus the shared `NNN NN` family). When
78
- * set AND no country constraint survives, the `postalcode` lookup probes exactly these countries and abstains if all
79
- * miss — never falling through to an unconstrained probe, whose space-stripped fold collides across systems (`100 00`
80
- * folded to `10000` answers Troyes FR while Prague sits in the artifact under both keyings).
93
+ * The countries implied by the postcode's format.
94
+ *
95
+ * A `postalcode` lookup without a country scope probes only these countries
96
+ * and abstains if all of them miss.
97
+ * An unscoped probe of a space-stripped code can match another country's postcode system.
81
98
  */
82
99
  postcodeFormatCountries?: readonly string[];
83
100
  /**
84
- * #1585 — the locale hint's country, forwarded to the backend as `fuzzyCountry` on every primary lookup. Scopes the
85
- * typo-fuzzy tier only; exact matches stay worldwide. See `ResolveOpts.fuzzyCountryScope`.
101
+ * The locale hint's country, sent as `fuzzyCountry` on every lookup.
102
+ * It scopes only the typo-fuzzy tier.
86
103
  */
87
104
  fuzzyCountryScope?: string;
88
105
  /**
89
- * The injected PFX1 index (structural — `PostcodePrefixIndexLike`, core/resolver/types.ts). Absent = the prior cannot
90
- * fire.
106
+ * The postcode prefix index that {@link ResolutionState.postcodePrefixPrior} requires.
91
107
  */
92
108
  postcodePrefixIndex?: PostcodePrefixIndexLike;
93
109
  /**
94
- * Proximity-bias points (viewport, user location) — forwarded to every primary lookup.
110
+ * Proximity-bias points, such as a viewport or user location, that every
111
+ * lookup uses to reorder candidates.
95
112
  */
96
113
  bias?: Array<{
97
114
  lat: number;
@@ -99,121 +116,117 @@ export interface ResolutionState {
99
116
  weight?: number;
100
117
  }>;
101
118
  /**
102
- * Postcode-anchor country posterior (#369). Undefined = no re-rank (byte-stable default).
119
+ * The postcode anchor's posterior over countries, used to re-rank region and locality candidates.
120
+ *
121
+ * When set, it also replaces the importance re-rank and capital promotion.
103
122
  */
104
123
  anchorPosterior?: Record<string, number>;
105
124
  /**
106
- * Weight on the posterior in the locality re-rank. Only used when `anchorPosterior` is set.
125
+ * The weight on {@link ResolutionState.anchorPosterior} in the re-rank key.
107
126
  */
108
127
  anchorWeight: number;
109
128
  /**
110
- * #1721 resolver-interior trace sink. Undefined (the default) = zero bookkeeping, byte-identical walk.
129
+ * The callback that receives one trace record per lookup.
130
+ * The walk records no events when it is absent.
111
131
  */
112
132
  traceSink?: (record: ResolveNodeTrace) => void;
113
133
  /**
114
- * Re-probe a resolved-nothing lookup across the other admin bands and record which hold it. Diagnostic only — never
115
- * reaches the pick. See `ResolveOpts.diagnoseUnreachable`.
134
+ * Whether an empty lookup re-probes the other admin bands and traces which ones hold the value.
135
+ *
136
+ * It is set only when a trace sink exists.
137
+ * It never affects the pick.
116
138
  */
117
139
  diagnoseUnreachable?: boolean;
118
140
  /**
119
- * #27 locale-country SOFT prior for the bare-toponym admin walk. Undefined = no prior (the shipped default) →
120
- * byte-stable. See `ResolveOpts.localeCountryPrior` for the calibration and why it ships opt-in.
141
+ * The locale country used as a soft prior on region and locality candidates
142
+ * when no default country or anchor posterior applies.
121
143
  */
122
144
  localeCountryPrior?: string;
123
145
  /**
124
- * Weight of that prior in log10-population units. Only consulted when `localeCountryPrior` is set.
146
+ * The weight of {@link ResolutionState.localeCountryPrior}, in log10-population units.
125
147
  */
126
148
  localeCountryPriorWeight: number;
127
149
  /**
128
- * #1880 capital status per candidate, from `ResolveOpts.capitalLevel`. Undefined → no promotion, byte-stable.
150
+ * Returns a candidate's capital level for bounded capital promotion.
151
+ * Capital promotion is off when it is absent.
129
152
  */
130
153
  capitalLevel?: (place: {
131
154
  name: string;
132
- country?: string;
155
+ country: string | null;
133
156
  lat: number;
134
157
  lon: number;
135
158
  }) => number;
136
159
  /**
137
- * #743/#194 confident-placer country as a HARD filter (empty→unresolved, no global retry). Off = undefined.
160
+ * The country scope applied to a lookup when no parent, default country, or node hint supplies one.
138
161
  */
139
162
  hardCountry?: string;
140
163
  /**
141
- * Dual-role hierarchy completion (#405). Off by default → byte-stable.
164
+ * Whether a resolved region gains its coincident locality of the same name as an
165
+ * interpretation when the tree has no locality node.
142
166
  */
143
167
  hierarchyCompletion: boolean;
144
168
  /**
145
- * Attach ancestor lineage to each resolved node (#404). Off by default → byte-stable.
169
+ * Whether each resolved node gets its ancestor lineage in metadata, when the backend supports it.
146
170
  */
147
171
  includeAncestors: boolean;
148
172
  /**
149
- * Admin-containment re-rank (#1717 stage 2). Off by default → byte-stable. See `ResolveOpts.adminContainmentRerank`.
173
+ * Whether locality candidates contained by {@link ResolutionState.regionQualifier}
174
+ * are ordered ahead of the rest.
150
175
  */
151
176
  adminContainmentRerank: boolean;
152
177
  /**
153
- * The tree's first parsed region-tagged span, extracted once up front (the `postcode` pattern above — region and
154
- * locality are siblings, so the top-down walk wouldn't otherwise let the locality lookup see it). Only consulted when
155
- * {@link adminContainmentRerank} is on.
178
+ * The tree's first region value.
179
+ *
180
+ * The region and locality nodes are siblings, so the walk would not otherwise
181
+ * pass the region to the locality lookup.
182
+ * It applies only with {@link ResolutionState.adminContainmentRerank}
183
+ * and no caller-supplied default country.
156
184
  */
157
- regionQualifier?: string;
185
+ regionQualifier?: string | null;
158
186
  /**
159
- * Set while resolving when ANY tree node maps to the `locality` placetype (resolved or not) — the completion only
160
- * fires when the parser emitted no locality at all, never to override one.
187
+ * Whether any node maps to the `locality` placetype.
188
+ * Hierarchy completion runs only when this is false.
161
189
  */
162
190
  localityNodePresent: boolean;
163
191
  /**
164
- * The first region that resolved (its place — for the coincident-roles lookup).
192
+ * The first resolved region place, used to look up its coincident locality.
165
193
  */
166
194
  resolvedRegion: CoordinateOptionalPlace | null;
167
195
  /**
168
- * The decorated region NODE that produced {@link resolvedRegion} — completion pushes the locality interpretation onto
169
- * it in place (no synthesized sibling).
196
+ * The decorated node for {@link ResolutionState.resolvedRegion}.
197
+ *
198
+ * Hierarchy completion adds the locality interpretation to it in place.
170
199
  */
171
200
  resolvedRegionNode: AddressNode | null;
172
201
  }
173
202
  /**
174
- * Pick the completion locality when an admin maps to several coincident same-name candidates (#405). REFERENTIAL
175
- * likelihood is the PRIMARY signal — the principal city is the populous one, and it can sit FARTHER from the admin
176
- * centroid than a tiny same-name hamlet (the Niigata case from #403). Nearest centroid breaks a referential tie; a
177
- * genuine tie (same population AND distance) ABSTAINS rather than guess.
203
+ * Picks the completion locality among coincident candidates of the same name.
178
204
  *
179
- * ROAD_TO_V9 §2: `compareReferential` is referential DESC with raw population as its own tiebreak, which is the SAME
180
- * ORDER as the plain `b.population - a.population` it replaced — referential is strictly increasing in population below
181
- * saturation and constant above it. The abstention check below still reads raw population, deliberately: two megacities
182
- * that saturate to the same referential score are not tied, and abstaining there would be a new behavior.
205
+ * It prefers the most populous candidate, then the nearest candidate.
206
+ * It returns `null` on an exact tie.
183
207
  */
184
208
  export declare function pickCompletion(candidates: readonly CoincidentLocality[]): CoincidentLocality | null;
185
209
  /**
186
- * Find the first postcode value anywhere in the tree (a one-shot pre-scan; postcode and locality are siblings, so the
187
- * top-down walk wouldn't otherwise let the locality lookup see it).
210
+ * Returns the first postcode value anywhere in the tree, skipping shape-excluded postcodes.
211
+ * a locality lookup uses it because the postcode node is usually a sibling.
188
212
  */
189
- export declare function firstPostcodeValue(roots: readonly AddressNode[]): string | undefined;
213
+ export declare function firstPostcodeValue(roots: readonly AddressNode[]): string | null;
190
214
  /**
191
- * Span-rescore tier (#370): opt-in last-resort locality recovery. Runs ONLY when the tree resolved NOTHING (the #685
192
- * brake — never disturb a working coordinate). Enumerates raw-token spans, exact- matches the same-country gazetteer
193
- * (longest-wins + postcode-consistency check; see `span-rescore.ts`), and on a hit INJECTS a resolved `locality` node
194
- * decorated exactly like a normally-resolved one. Default-ON (#370, promoted 2026-06-25); byte-stable opt-out via
195
- * `opts.spanRescore: false`. Async (it queries the backend), so it's awaited.
215
+ * Recovers a locality from raw-text spans when the tree resolved no place,
216
+ * appending a resolved `locality` node on a hit.
217
+ *
218
+ * When no span matches, it tries the postcode node's code part.
196
219
  */
197
- export declare function applySpanRescore(roots: AddressNode[], raw: string, backend: ResolverBackend, opts: ResolveOpts): Promise<void>;
220
+ export declare function applySpanRescore(roots: AddressNode[], raw: string, backend: ResolverBackend, opts: ResolvedOpts): Promise<void>;
198
221
  /**
199
- * Postcode-disambiguated locality selection (#370 "Change A"). The single biggest miss on the EU/AU panel is a
200
- * same-named town resolved to the WRONG instance — "06260 Saint-Pierre" lands 617 km off — while the postcode that
201
- * would disambiguate it (06260 → Alpes-Maritimes) sits resolved in the same tree, discarded because the
202
- * coordinate-picker prefers the (wrong) locality node and never cross- checks it. This post-walk pass closes that loop,
203
- * backend-agnostically and with no extra query:
204
- *
205
- * 1. Find the resolved postcode's coordinate (the trustworthy anchor — a postcode is unambiguous within a country in a way
206
- * a town name is not).
207
- * 2. For each resolved locality node farther than `thresholdKm` from it: re-pick the same-named candidate from the node's
208
- * already-captured `alternatives` that is NEAREST the postcode and within the radius. This keeps locality
209
- * granularity at the CORRECT instance.
210
- * 3. If no alternative reconciles, the locality instance is unreliable — fall its coordinate back to the postcode point
211
- * (right area, the safe answer) and flag `postcode_city_mismatch`.
212
- *
213
- * Only fires where the postcode resolved to a point, so it composes with postcode coverage (#193) — add a country's
214
- * postcodes and this immediately disambiguates its same-named towns. **Default-ON** since the #370 operator promotion
215
- * (2026-07-04, commit `0010bb8c`) — `opts.postcodeConsistency: false` opts out, and the pass is byte-stable on every
216
- * tree with no resolved postcode point (the `!anchor` early return below).
222
+ * The farthest distance, in kilometers, that {@link applyPostcodeConsistency}
223
+ * moves a locality onto its postcode's point.
224
+ */
225
+ export declare const DEFAULT_POSTCODE_MAX_MOVE_KM = 300;
226
+ /**
227
+ * Reconciles each resolved locality that lies farther than `thresholdKm` from the tree's
228
+ * resolved postcode point, re-picking the nearest alternative within the threshold and otherwise
229
+ * moving the coordinate there, but skipping the move when the distance exceeds `maxMoveKm`.
217
230
  */
218
- export declare function applyPostcodeConsistency(roots: readonly AddressNode[], thresholdKm: number): void;
231
+ export declare function applyPostcodeConsistency(roots: readonly AddressNode[], thresholdKm: number, maxMoveKm?: number): void;
219
232
  //# sourceMappingURL=passes.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"passes.d.ts","sourceRoot":"","sources":["../../lib/resolve/passes.ts"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