@mailwoman/resolver-wof-sqlite 4.16.2 → 5.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/out/address-point-interpolation.d.ts.map +1 -1
- package/out/address-point-interpolation.js +6 -6
- package/out/address-point-interpolation.js.map +1 -1
- package/out/address-point-schema.d.ts +5 -6
- package/out/address-point-schema.d.ts.map +1 -1
- package/out/address-point-schema.js +7 -2
- package/out/address-point-schema.js.map +1 -1
- package/out/address-point.d.ts +22 -8
- package/out/address-point.d.ts.map +1 -1
- package/out/address-point.js +29 -13
- package/out/address-point.js.map +1 -1
- package/out/ancestry-backfill.d.ts +53 -0
- package/out/ancestry-backfill.d.ts.map +1 -0
- package/out/ancestry-backfill.js +150 -0
- package/out/ancestry-backfill.js.map +1 -0
- package/out/ancestry.d.ts +6 -6
- package/out/ancestry.d.ts.map +1 -1
- package/out/ancestry.js +6 -6
- package/out/ancestry.js.map +1 -1
- package/out/build-candidate-cli.d.ts.map +1 -1
- package/out/build-candidate-cli.js.map +1 -1
- package/out/build-candidate.d.ts +4 -5
- package/out/build-candidate.d.ts.map +1 -1
- package/out/build-candidate.js +15 -14
- package/out/build-candidate.js.map +1 -1
- package/out/build-coincident-roles-cli.d.ts.map +1 -1
- package/out/build-coincident-roles-cli.js.map +1 -1
- package/out/build-fts-cli.d.ts +1 -1
- package/out/build-fts-cli.d.ts.map +1 -1
- package/out/build-fts-cli.js +6 -6
- package/out/build-fts-cli.js.map +1 -1
- package/out/build-slim-cli.d.ts +1 -1
- package/out/build-slim-cli.d.ts.map +1 -1
- package/out/build-slim-cli.js +3 -3
- package/out/build-slim-cli.js.map +1 -1
- package/out/build-slim.d.ts +7 -8
- package/out/build-slim.d.ts.map +1 -1
- package/out/build-slim.js +9 -9
- package/out/build-slim.js.map +1 -1
- package/out/candidate-fts.d.ts +5 -7
- package/out/candidate-fts.d.ts.map +1 -1
- package/out/candidate-fts.js +5 -7
- package/out/candidate-fts.js.map +1 -1
- package/out/candidate-lookup.d.ts +7 -7
- package/out/candidate-lookup.d.ts.map +1 -1
- package/out/candidate-lookup.js +31 -35
- package/out/candidate-lookup.js.map +1 -1
- package/out/candidate-schema.d.ts +13 -14
- package/out/candidate-schema.d.ts.map +1 -1
- package/out/candidate-schema.js +9 -9
- package/out/candidate-schema.js.map +1 -1
- package/out/coincident-roles.d.ts +9 -11
- package/out/coincident-roles.d.ts.map +1 -1
- package/out/coincident-roles.js +7 -7
- package/out/coincident-roles.js.map +1 -1
- package/out/convention.d.ts +30 -35
- package/out/convention.d.ts.map +1 -1
- package/out/convention.js +19 -21
- package/out/convention.js.map +1 -1
- package/out/fst-autocomplete.d.ts +5 -5
- package/out/fst-autocomplete.d.ts.map +1 -1
- package/out/fst-autocomplete.js +12 -13
- package/out/fst-autocomplete.js.map +1 -1
- package/out/fst-builder.d.ts +7 -7
- package/out/fst-builder.d.ts.map +1 -1
- package/out/fst-builder.js +9 -9
- package/out/fst-builder.js.map +1 -1
- package/out/fst-deserialize-web.d.ts +4 -4
- package/out/fst-deserialize-web.d.ts.map +1 -1
- package/out/fst-deserialize-web.js +4 -4
- package/out/fst-deserialize-web.js.map +1 -1
- package/out/fst-matcher.d.ts +12 -12
- package/out/fst-matcher.d.ts.map +1 -1
- package/out/fst-matcher.js +25 -25
- package/out/fst-matcher.js.map +1 -1
- package/out/fst-serialize.d.ts +5 -5
- package/out/fst-serialize.d.ts.map +1 -1
- package/out/fst-serialize.js +7 -6
- package/out/fst-serialize.js.map +1 -1
- package/out/fst-types.d.ts +13 -13
- package/out/fts.d.ts +74 -80
- package/out/fts.d.ts.map +1 -1
- package/out/fts.js +65 -71
- package/out/fts.js.map +1 -1
- package/out/geo.d.ts +14 -15
- package/out/geo.d.ts.map +1 -1
- package/out/geo.js +8 -8
- package/out/geo.js.map +1 -1
- package/out/geonames-aliases.d.ts +18 -9
- package/out/geonames-aliases.d.ts.map +1 -1
- package/out/geonames-aliases.js +70 -12
- package/out/geonames-aliases.js.map +1 -1
- package/out/index.d.ts +9 -9
- package/out/index.js +7 -7
- package/out/interpolation.d.ts +8 -10
- package/out/interpolation.d.ts.map +1 -1
- package/out/interpolation.js +6 -6
- package/out/interpolation.js.map +1 -1
- package/out/lookup.d.ts +74 -81
- package/out/lookup.d.ts.map +1 -1
- package/out/lookup.js +114 -128
- package/out/lookup.js.map +1 -1
- package/out/postal-city-alias-lookup.d.ts +9 -10
- package/out/postal-city-alias-lookup.d.ts.map +1 -1
- package/out/postal-city-alias-lookup.js +13 -14
- package/out/postal-city-alias-lookup.js.map +1 -1
- package/out/postal-city-alias-schema.d.ts +5 -6
- package/out/postal-city-alias-schema.d.ts.map +1 -1
- package/out/postal-city-alias-schema.js +3 -4
- package/out/postal-city-alias-schema.js.map +1 -1
- package/out/postal-city-candidate-schema.d.ts +7 -10
- package/out/postal-city-candidate-schema.d.ts.map +1 -1
- package/out/postal-city-candidate-schema.js +4 -6
- package/out/postal-city-candidate-schema.js.map +1 -1
- package/out/postcode-point-lookup.d.ts +3 -4
- package/out/postcode-point-lookup.d.ts.map +1 -1
- package/out/postcode-point-lookup.js +2 -2
- package/out/postcode-point-lookup.js.map +1 -1
- package/out/reverse.d.ts +26 -29
- package/out/reverse.d.ts.map +1 -1
- package/out/reverse.js +36 -38
- package/out/reverse.js.map +1 -1
- package/out/schema.d.ts +32 -33
- package/out/schema.d.ts.map +1 -1
- package/out/sharding.d.ts +26 -28
- package/out/sharding.d.ts.map +1 -1
- package/out/sharding.js +16 -16
- package/out/sharding.js.map +1 -1
- package/out/sqlite-convention-source.d.ts +3 -3
- package/out/sqlite-convention-source.d.ts.map +1 -1
- package/out/sqlite-convention-source.js +6 -6
- package/out/sqlite-convention-source.js.map +1 -1
- package/out/sqlite-utils.d.ts +4 -5
- package/out/sqlite-utils.d.ts.map +1 -1
- package/out/sqlite-utils.js +4 -5
- package/out/sqlite-utils.js.map +1 -1
- package/out/street-morphology-fst-builder.d.ts +15 -18
- package/out/street-morphology-fst-builder.d.ts.map +1 -1
- package/out/street-morphology-fst-builder.js +17 -17
- package/out/street-morphology-fst-builder.js.map +1 -1
- package/out/street-normalize.d.ts +43 -28
- package/out/street-normalize.d.ts.map +1 -1
- package/out/street-normalize.js +96 -34
- package/out/street-normalize.js.map +1 -1
- package/out/street-segment-schema.d.ts +5 -5
- package/out/street-segment-schema.js +2 -2
- package/out/types.d.ts +42 -47
- package/out/types.d.ts.map +1 -1
- package/out/types.js +1 -1
- package/out/unified-schema.d.ts +6 -6
- package/out/unified-schema.d.ts.map +1 -1
- package/out/unified-schema.js +10 -10
- package/out/unified-schema.js.map +1 -1
- package/package.json +26 -22
package/out/candidate-lookup.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
5
|
*
|
|
6
6
|
* Node-side {@link PlaceLookup} over the byte-range CANDIDATE table (`build-candidate.ts`) — the
|
|
7
|
-
* SAME gazetteer the browser demo resolves against ({@link
|
|
7
|
+
* SAME gazetteer the browser demo resolves against ({@link WOFCandidateTableLookup} in
|
|
8
8
|
* `docs/src/shared/httpvfs-resolver.ts`), but reading a LOCAL `candidate.db` via `node:sqlite`
|
|
9
9
|
* instead of sql.js-httpvfs. This is what makes the server/CLI resolver match the demo: one
|
|
10
10
|
* lookup surface, one artifact, one ranking.
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* {@link normalizeLocalityForKey} (build- and query-consistent), each row is denormalized (display
|
|
15
15
|
* `name`, centroid, bbox), and population rank is precomputed into `neg_rank` — so the result is
|
|
16
16
|
* POPULATION-FIRST and COUNTRY-AGNOSTIC (when no `country` filter is given), exactly like the
|
|
17
|
-
* demo. That's the deliberate divergence from {@link
|
|
17
|
+
* demo. That's the deliberate divergence from {@link WOFSqlitePlaceLookup}'s FTS/bm25 ranking: a
|
|
18
18
|
* bare "Moscow" resolves to the 10.4 M-pop Russian city, not whichever same-name US township bm25
|
|
19
19
|
* floats to the top.
|
|
20
20
|
*
|
|
@@ -22,24 +22,23 @@
|
|
|
22
22
|
* stored bbox and the locality query is point-in-bbox-filtered on the candidate centroid (the
|
|
23
23
|
* `bbox` field on {@link FindPlaceQuery}).
|
|
24
24
|
*/
|
|
25
|
-
import { expandPlacetypeFilter } from "@mailwoman/resolver";
|
|
26
25
|
import { DatabaseSync } from "node:sqlite";
|
|
26
|
+
import { expandPlacetypeFilter } from "@mailwoman/resolver";
|
|
27
27
|
import { CANDIDATE_FTS_TABLE } from "./candidate-fts.js";
|
|
28
28
|
import { trigramJaccard } from "./lookup.js";
|
|
29
29
|
import { POSTAL_CITY_CANDIDATE_TABLE } from "./postal-city-candidate-schema.js";
|
|
30
30
|
import { hasTable } from "./sqlite-utils.js";
|
|
31
31
|
import { normalizeLocalityForKey, stripLocalityQualifier } from "./street-normalize.js";
|
|
32
32
|
/**
|
|
33
|
-
* FTS5-trigram over-fetch before the trigram-Jaccard re-rank, and the minimum similarity to count
|
|
34
|
-
*
|
|
35
|
-
* Tunable.
|
|
33
|
+
* FTS5-trigram over-fetch before the trigram-Jaccard re-rank, and the minimum similarity to count as a fuzzy hit (below
|
|
34
|
+
* it the trigram overlap is noise, e.g. unrelated same-trigram names). Tunable.
|
|
36
35
|
*/
|
|
37
36
|
const FUZZY_FETCH = 40;
|
|
38
37
|
const FUZZY_MIN = 0.34;
|
|
39
38
|
/**
|
|
40
|
-
* Unpadded character-trigrams of `s`, OR'd into an FTS5 trigram MATCH query (each quoted so FTS
|
|
41
|
-
*
|
|
42
|
-
*
|
|
39
|
+
* Unpadded character-trigrams of `s`, OR'd into an FTS5 trigram MATCH query (each quoted so FTS treats it as a literal
|
|
40
|
+
* term). Returns "" when `s` is shorter than a trigram or yields no clean grams — the caller then skips the fuzzy
|
|
41
|
+
* probe.
|
|
43
42
|
*/
|
|
44
43
|
function ftsTrigramQuery(s) {
|
|
45
44
|
const grams = new Set();
|
|
@@ -51,60 +50,57 @@ function ftsTrigramQuery(s) {
|
|
|
51
50
|
return [...grams].map((g) => `"${g}"`).join(" OR ");
|
|
52
51
|
}
|
|
53
52
|
/**
|
|
54
|
-
* Node {@link PlaceLookup} over `candidate.db`. Drop-in for {@link
|
|
55
|
-
*
|
|
53
|
+
* Node {@link PlaceLookup} over `candidate.db`. Drop-in for {@link WOFSqlitePlaceLookup} in `createWOFResolver(backend)`
|
|
54
|
+
* — same `findPlace` contract, population-first ranking.
|
|
56
55
|
*/
|
|
57
|
-
export class
|
|
56
|
+
export class WOFCandidateTableLookup {
|
|
58
57
|
#db;
|
|
59
|
-
#
|
|
60
|
-
#
|
|
58
|
+
#ownsDB;
|
|
59
|
+
#countryToID = new Map();
|
|
61
60
|
#idToCountry = new Map();
|
|
62
|
-
#
|
|
61
|
+
#placetypeToID = new Map();
|
|
63
62
|
#idToPlacetype = new Map();
|
|
64
63
|
/**
|
|
65
|
-
* Prepared `(name_key, postcode)` probe for the #741 postal-city side-index — `undefined` when
|
|
66
|
-
*
|
|
67
|
-
* byte-stable.
|
|
64
|
+
* Prepared `(name_key, postcode)` probe for the #741 postal-city side-index — `undefined` when the
|
|
65
|
+
* `postal_city_candidate` table isn't present, so a candidate.db built without it is byte-stable.
|
|
68
66
|
*/
|
|
69
67
|
#postalCityProbe;
|
|
70
68
|
/**
|
|
71
|
-
* Prepared FTS5-trigram MATCH probe for the typo-tolerant fallback — `undefined` when the
|
|
72
|
-
*
|
|
73
|
-
* fuzzy path is skipped, exactly like today).
|
|
69
|
+
* Prepared FTS5-trigram MATCH probe for the typo-tolerant fallback — `undefined` when the `candidate_fts` index isn't
|
|
70
|
+
* present, so a candidate.db built without it is byte-stable (the fuzzy path is skipped, exactly like today).
|
|
74
71
|
*/
|
|
75
72
|
#ftsProbe;
|
|
76
73
|
/**
|
|
77
|
-
* Prepared UNFILTERED existence probe (`name_key` present anywhere, ignoring
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
* cascade's country-agnostic retry. Prepared only alongside `#ftsProbe`.
|
|
74
|
+
* Prepared UNFILTERED existence probe (`name_key` present anywhere, ignoring country/placetype/bbox). Gates the fuzzy
|
|
75
|
+
* fallback: fuzzy is a TYPO corrector, so it engages only when the name doesn't exist in the gazetteer at all. A name
|
|
76
|
+
* that DOES exist but missed under the active filter is a filter miss (e.g. a placer misroute "Vienna, Austria"→IT),
|
|
77
|
+
* not a spelling miss — fuzzing it would scrape an unrelated same-country place and defeat the cascade's
|
|
78
|
+
* country-agnostic retry. Prepared only alongside `#ftsProbe`.
|
|
83
79
|
*/
|
|
84
80
|
#nameKeyExistsProbe;
|
|
85
81
|
constructor(opts) {
|
|
86
82
|
if (opts.database) {
|
|
87
83
|
this.#db = opts.database;
|
|
88
|
-
this.#
|
|
84
|
+
this.#ownsDB = false;
|
|
89
85
|
}
|
|
90
86
|
else if (opts.databasePath) {
|
|
91
87
|
this.#db = new DatabaseSync(opts.databasePath, { readOnly: true });
|
|
92
|
-
this.#
|
|
88
|
+
this.#ownsDB = true;
|
|
93
89
|
}
|
|
94
90
|
else {
|
|
95
|
-
throw new Error("
|
|
91
|
+
throw new Error("WOFCandidateTableLookup needs `databasePath` or `database`");
|
|
96
92
|
}
|
|
97
93
|
// The code tables are tiny (country/placetype dictionaries) — load them once at construction so
|
|
98
94
|
// `findPlace` is a single B-tree probe with no dictionary round-trip.
|
|
99
95
|
for (const r of this.#db.prepare("SELECT id, code FROM country_codes").all()) {
|
|
100
96
|
const code = String(r.code).toUpperCase();
|
|
101
|
-
this.#
|
|
97
|
+
this.#countryToID.set(code, Number(r.id));
|
|
102
98
|
this.#idToCountry.set(Number(r.id), code);
|
|
103
99
|
}
|
|
104
100
|
for (const r of this.#db
|
|
105
101
|
.prepare("SELECT id, placetype FROM placetype_codes")
|
|
106
102
|
.all()) {
|
|
107
|
-
this.#
|
|
103
|
+
this.#placetypeToID.set(String(r.placetype), Number(r.id));
|
|
108
104
|
this.#idToPlacetype.set(Number(r.id), String(r.placetype));
|
|
109
105
|
}
|
|
110
106
|
// #741 postal-city side-index: prepare the exact probe only if the table is present. Absent →
|
|
@@ -161,7 +157,7 @@ export class WofCandidateTableLookup {
|
|
|
161
157
|
const filters = [];
|
|
162
158
|
const filterParams = [];
|
|
163
159
|
if (query.country) {
|
|
164
|
-
const cid = this.#
|
|
160
|
+
const cid = this.#countryToID.get(query.country.toUpperCase());
|
|
165
161
|
if (cid === undefined)
|
|
166
162
|
return []; // a country the candidate table doesn't carry
|
|
167
163
|
filters.push("country_id = ?");
|
|
@@ -172,7 +168,7 @@ export class WofCandidateTableLookup {
|
|
|
172
168
|
// localadmin). `postalcode` maps to no admin placetype here → empty → no rows.
|
|
173
169
|
const want = Array.isArray(query.placetype) ? query.placetype : [query.placetype];
|
|
174
170
|
const ids = expandPlacetypeFilter(want)
|
|
175
|
-
.map((t) => this.#
|
|
171
|
+
.map((t) => this.#placetypeToID.get(t))
|
|
176
172
|
.filter((v) => v !== undefined);
|
|
177
173
|
if (ids.length === 0)
|
|
178
174
|
return [];
|
|
@@ -259,7 +255,7 @@ export class WofCandidateTableLookup {
|
|
|
259
255
|
});
|
|
260
256
|
}
|
|
261
257
|
close() {
|
|
262
|
-
if (this.#
|
|
258
|
+
if (this.#ownsDB)
|
|
263
259
|
this.#db.close();
|
|
264
260
|
}
|
|
265
261
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"candidate-lookup.js","sourceRoot":"","sources":["../candidate-lookup.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"candidate-lookup.js","sourceRoot":"","sources":["../candidate-lookup.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE1C,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAA;AAE3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AAExD,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,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,IAAI,EAAE,CAAiB;gBACpF,6FAA6F;gBAC7F,gGAAgG;gBAChG,OAAO,EAAE,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,IAAI,EAAE;gBAC5D,GAAG,EAAE,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;gBACzB,GAAG,EAAE,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC;gBAC1B,KAAK,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;gBAC5B,0FAA0F;gBAC1F,0FAA0F;gBAC1F,UAAU,EAAE,IAAI;gBAChB,GAAG,CAAC,OAAO;oBACV,CAAC,CAAC;wBACA,IAAI,EAAE;4BACL,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC;4BAC3B,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC;4BAC3B,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC;4BAC3B,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC;yBAC3B;qBACD;oBACF,CAAC,CAAC,EAAE,CAAC;aACN,CAAA;QACF,CAAC,CAAC,CAAA;IACH,CAAC;IAED,KAAK;QACJ,IAAI,IAAI,CAAC,OAAO;YAAE,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,CAAA;IACnC,CAAC;CACD"}
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*
|
|
6
6
|
* Typed schema for the byte-range CANDIDATE gazetteer (`candidate.db`) — the single source of truth
|
|
7
7
|
* for the columns shared by the BUILDER ({@link buildCandidateTable}) and the READERS (the Node
|
|
8
|
-
* {@link
|
|
8
|
+
* {@link WOFCandidateTableLookup} + the browser `httpvfs-resolver.ts`). Before this module each
|
|
9
9
|
* side hand-wrote the column list; a rename in one place broke the other at runtime. Now the
|
|
10
10
|
* contract is a Kysely `Database` interface (`new DatabaseClient<CandidateDatabase>(...)` for
|
|
11
11
|
* typed inserts) plus the table DDL as strings — so a column change is a compile error on every
|
|
@@ -16,9 +16,9 @@
|
|
|
16
16
|
*/
|
|
17
17
|
import { type Kysely } from "kysely";
|
|
18
18
|
/**
|
|
19
|
-
* One candidate row. `name_key` + the four small int keys + `neg_rank` + `spr_id` form the
|
|
20
|
-
*
|
|
21
|
-
*
|
|
19
|
+
* One candidate row. `name_key` + the four small int keys + `neg_rank` + `spr_id` form the clustered primary key; the
|
|
20
|
+
* rest is denormalized so a resolve is one probe (no join to `spr`). Coordinates + bbox + name are nullable at the SQL
|
|
21
|
+
* level (a postcode shard row may lack a bbox).
|
|
22
22
|
*/
|
|
23
23
|
export interface CandidateTable {
|
|
24
24
|
/** The shared {@link normalizeLocalityForKey} of the name/alias — the probe key. */
|
|
@@ -30,8 +30,7 @@ export interface CandidateTable {
|
|
|
30
30
|
/** Small int from {@link PlacetypeCodeTable}. */
|
|
31
31
|
placetype_id: number;
|
|
32
32
|
/**
|
|
33
|
-
* `-log10(population + 1)` — ASC order = highest-population first. 0 for postcodes (no
|
|
34
|
-
* population).
|
|
33
|
+
* `-log10(population + 1)` — ASC order = highest-population first. 0 for postcodes (no population).
|
|
35
34
|
*/
|
|
36
35
|
neg_rank: number;
|
|
37
36
|
/** WOF id of the place this row resolves to. */
|
|
@@ -67,20 +66,20 @@ export interface CandidateDatabase {
|
|
|
67
66
|
placetype_codes: PlacetypeCodeTable;
|
|
68
67
|
}
|
|
69
68
|
/**
|
|
70
|
-
* The `candidate`/`cand_stage` columns in clustered-key order. The materialization `INSERT INTO
|
|
71
|
-
*
|
|
72
|
-
*
|
|
69
|
+
* The `candidate`/`cand_stage` columns in clustered-key order. The materialization `INSERT INTO candidate SELECT … FROM
|
|
70
|
+
* cand_stage` derives its column list from this, so the two tables can't drift. Keep in sync with
|
|
71
|
+
* {@link CandidateTable}.
|
|
73
72
|
*/
|
|
74
73
|
export declare const CANDIDATE_COLUMNS: readonly ["name_key", "country_id", "region_id", "placetype_id", "neg_rank", "spr_id", "name", "latitude", "longitude", "min_lat", "min_lon", "max_lat", "max_lon", "population", "is_primary"];
|
|
75
74
|
/**
|
|
76
|
-
* Create the code dictionaries + the transient staging table — called before the build's load
|
|
77
|
-
*
|
|
78
|
-
*
|
|
75
|
+
* Create the code dictionaries + the transient staging table — called before the build's load passes. `cand_stage`
|
|
76
|
+
* mirrors {@link CandidateTable} but every column is nullable (the loader fills them positionally). Pass a
|
|
77
|
+
* {@link DatabaseClient} (or any `Kysely`) over the candidate DB.
|
|
79
78
|
*/
|
|
80
79
|
export declare function createCandidateStagingTables(db: Kysely<CandidateDatabase>): Promise<void>;
|
|
81
80
|
/**
|
|
82
|
-
* Create the clustered `WITHOUT ROWID` lookup table — called after staging, before the VACUUM. The
|
|
83
|
-
*
|
|
81
|
+
* Create the clustered `WITHOUT ROWID` lookup table — called after staging, before the VACUUM. The first six columns
|
|
82
|
+
* form the clustered primary key (population-ranked via `neg_rank`).
|
|
84
83
|
*/
|
|
85
84
|
export declare function createCandidateTable(db: Kysely<CandidateDatabase>): Promise<void>;
|
|
86
85
|
//# sourceMappingURL=candidate-schema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"candidate-schema.d.ts","sourceRoot":"","sources":["../candidate-schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAO,KAAK,MAAM,EAAE,MAAM,QAAQ,CAAA;AAEzC;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC9B,oFAAoF;IACpF,QAAQ,EAAE,MAAM,CAAA;IAChB,2EAA2E;IAC3E,UAAU,EAAE,MAAM,CAAA;IAClB,wFAAwF;IACxF,SAAS,EAAE,MAAM,CAAA;IACjB,iDAAiD;IACjD,YAAY,EAAE,MAAM,CAAA;IACpB
|
|
1
|
+
{"version":3,"file":"candidate-schema.d.ts","sourceRoot":"","sources":["../candidate-schema.ts"],"names":[],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eAAO,MAAM,iBAAiB,iMAgBpB,CAAA;AAEV;;;;GAIG;AACH,wBAAsB,4BAA4B,CAAC,EAAE,EAAE,MAAM,CAAC,iBAAiB,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CA6B/F;AAED;;;GAGG;AACH,wBAAsB,oBAAoB,CAAC,EAAE,EAAE,MAAM,CAAC,iBAAiB,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CA6BvF"}
|
package/out/candidate-schema.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*
|
|
6
6
|
* Typed schema for the byte-range CANDIDATE gazetteer (`candidate.db`) — the single source of truth
|
|
7
7
|
* for the columns shared by the BUILDER ({@link buildCandidateTable}) and the READERS (the Node
|
|
8
|
-
* {@link
|
|
8
|
+
* {@link WOFCandidateTableLookup} + the browser `httpvfs-resolver.ts`). Before this module each
|
|
9
9
|
* side hand-wrote the column list; a rename in one place broke the other at runtime. Now the
|
|
10
10
|
* contract is a Kysely `Database` interface (`new DatabaseClient<CandidateDatabase>(...)` for
|
|
11
11
|
* typed inserts) plus the table DDL as strings — so a column change is a compile error on every
|
|
@@ -16,9 +16,9 @@
|
|
|
16
16
|
*/
|
|
17
17
|
import { sql } from "kysely";
|
|
18
18
|
/**
|
|
19
|
-
* The `candidate`/`cand_stage` columns in clustered-key order. The materialization `INSERT INTO
|
|
20
|
-
*
|
|
21
|
-
*
|
|
19
|
+
* The `candidate`/`cand_stage` columns in clustered-key order. The materialization `INSERT INTO candidate SELECT … FROM
|
|
20
|
+
* cand_stage` derives its column list from this, so the two tables can't drift. Keep in sync with
|
|
21
|
+
* {@link CandidateTable}.
|
|
22
22
|
*/
|
|
23
23
|
export const CANDIDATE_COLUMNS = [
|
|
24
24
|
"name_key",
|
|
@@ -38,9 +38,9 @@ export const CANDIDATE_COLUMNS = [
|
|
|
38
38
|
"is_primary",
|
|
39
39
|
];
|
|
40
40
|
/**
|
|
41
|
-
* Create the code dictionaries + the transient staging table — called before the build's load
|
|
42
|
-
*
|
|
43
|
-
*
|
|
41
|
+
* Create the code dictionaries + the transient staging table — called before the build's load passes. `cand_stage`
|
|
42
|
+
* mirrors {@link CandidateTable} but every column is nullable (the loader fills them positionally). Pass a
|
|
43
|
+
* {@link DatabaseClient} (or any `Kysely`) over the candidate DB.
|
|
44
44
|
*/
|
|
45
45
|
export async function createCandidateStagingTables(db) {
|
|
46
46
|
await db.schema
|
|
@@ -73,8 +73,8 @@ export async function createCandidateStagingTables(db) {
|
|
|
73
73
|
.execute();
|
|
74
74
|
}
|
|
75
75
|
/**
|
|
76
|
-
* Create the clustered `WITHOUT ROWID` lookup table — called after staging, before the VACUUM. The
|
|
77
|
-
*
|
|
76
|
+
* Create the clustered `WITHOUT ROWID` lookup table — called after staging, before the VACUUM. The first six columns
|
|
77
|
+
* form the clustered primary key (population-ranked via `neg_rank`).
|
|
78
78
|
*/
|
|
79
79
|
export async function createCandidateTable(db) {
|
|
80
80
|
await db.schema
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"candidate-schema.js","sourceRoot":"","sources":["../candidate-schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,GAAG,EAAe,MAAM,QAAQ,CAAA;
|
|
1
|
+
{"version":3,"file":"candidate-schema.js","sourceRoot":"","sources":["../candidate-schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,GAAG,EAAe,MAAM,QAAQ,CAAA;AAwDzC;;;;GAIG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAChC,UAAU;IACV,YAAY;IACZ,WAAW;IACX,cAAc;IACd,UAAU;IACV,QAAQ;IACR,MAAM;IACN,UAAU;IACV,WAAW;IACX,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,YAAY;IACZ,YAAY;CACH,CAAA;AAEV;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,4BAA4B,CAAC,EAA6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,cAAc,EAAE;QACxC,UAAU;QACV,YAAY;QACZ,WAAW;QACX,cAAc;QACd,UAAU;QACV,QAAQ;KACR,CAAC;QACF,0FAA0F;SACzF,SAAS,CAAC,GAAG,CAAA,eAAe,CAAC;SAC7B,OAAO,EAAE,CAAA;AACZ,CAAC"}
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
* `relationship_type` is recorded for debuggability / deferred per-type behavior; v1 completion is
|
|
34
34
|
* uniform (see #405). It's a coarse classification, not critical.
|
|
35
35
|
*
|
|
36
|
-
* Mirrors the derived-table builder pattern in `fts.ts` (`
|
|
36
|
+
* Mirrors the derived-table builder pattern in `fts.ts` (`buildPlaceSearchFTS`). Run incrementally
|
|
37
37
|
* against an existing `admin-global-priority.db` via `build-coincident-roles-cli.ts`; should also
|
|
38
38
|
* be wired as a post-step of the main `scripts/build-unified-wof.ts`.
|
|
39
39
|
*/
|
|
@@ -41,7 +41,7 @@ import type { DatabaseSync } from "node:sqlite";
|
|
|
41
41
|
export declare const COINCIDENT_ROLES_TABLE = "coincident_roles";
|
|
42
42
|
/** A place that plays multiple admin roles — one row of the relation, keyed by `admin_id`. */
|
|
43
43
|
export interface CoincidentRole {
|
|
44
|
-
|
|
44
|
+
localityID: number;
|
|
45
45
|
relationshipType: "city-state" | "capital-seat" | "consolidated-county";
|
|
46
46
|
adminPlacetype: string;
|
|
47
47
|
distanceKm: number;
|
|
@@ -51,15 +51,13 @@ export interface BuildCoincidentRolesOpts {
|
|
|
51
51
|
/** Drop + rebuild the table if it already exists. Default true (the build is cheap + idempotent). */
|
|
52
52
|
drop?: boolean;
|
|
53
53
|
/**
|
|
54
|
-
* Relative tolerance: a pair is kept when centroid distance ≤ `toleranceFraction ×
|
|
55
|
-
* bbox-diagonal`. Default 0.15.
|
|
54
|
+
* Relative tolerance: a pair is kept when centroid distance ≤ `toleranceFraction × bbox-diagonal`. Default 0.15.
|
|
56
55
|
*/
|
|
57
56
|
toleranceFraction?: number;
|
|
58
57
|
/** Floor (km) under the relative tolerance, so small-bbox city-states still qualify. Default 12. */
|
|
59
58
|
minToleranceKm?: number;
|
|
60
59
|
/**
|
|
61
|
-
* Centroid distance (km) below which a region-tier pair is classed `city-state` (metadata only).
|
|
62
|
-
* Default 2.
|
|
60
|
+
* Centroid distance (km) below which a region-tier pair is classed `city-state` (metadata only). Default 2.
|
|
63
61
|
*/
|
|
64
62
|
cityStateMaxKm?: number;
|
|
65
63
|
onProgress?: (phase: string, detail?: string) => void;
|
|
@@ -71,16 +69,16 @@ export interface BuildCoincidentRolesResult {
|
|
|
71
69
|
durationMs: number;
|
|
72
70
|
}
|
|
73
71
|
/**
|
|
74
|
-
* Derive the coincident-roles relation into `db`. Additive — only creates/replaces the
|
|
75
|
-
*
|
|
72
|
+
* Derive the coincident-roles relation into `db`. Additive — only creates/replaces the `coincident_roles` table; never
|
|
73
|
+
* touches `spr`/`names`/`ancestors`. Idempotent.
|
|
76
74
|
*/
|
|
77
75
|
export declare function buildCoincidentRoles(db: DatabaseSync, opts?: BuildCoincidentRolesOpts): BuildCoincidentRolesResult;
|
|
78
76
|
/** True iff the relation table exists. Used by the resolver to decide whether completion can run. */
|
|
79
77
|
export declare function coincidentRolesExists(db: DatabaseSync): boolean;
|
|
80
78
|
/**
|
|
81
|
-
* Load the relation into an in-memory map keyed by `admin_id` for O(1) runtime lookup (#405). Each
|
|
82
|
-
*
|
|
83
|
-
*
|
|
79
|
+
* Load the relation into an in-memory map keyed by `admin_id` for O(1) runtime lookup (#405). Each admin may map to
|
|
80
|
+
* MULTIPLE same-name descendants; the consumer disambiguates (min distance → population → abstain). Returns an empty
|
|
81
|
+
* map when the table is absent.
|
|
84
82
|
*/
|
|
85
83
|
export declare function loadCoincidentRoles(db: DatabaseSync): Map<number, CoincidentRole[]>;
|
|
86
84
|
//# sourceMappingURL=coincident-roles.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coincident-roles.d.ts","sourceRoot":"","sources":["../coincident-roles.ts"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E/D;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,EAAE,EAAE,YAAY,GAAG,GAAG,CAAC,MAAM,EAAE,cAAc,EAAE,CAAC,CAiCnF"}
|
package/out/coincident-roles.js
CHANGED
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
* `relationship_type` is recorded for debuggability / deferred per-type behavior; v1 completion is
|
|
34
34
|
* uniform (see #405). It's a coarse classification, not critical.
|
|
35
35
|
*
|
|
36
|
-
* Mirrors the derived-table builder pattern in `fts.ts` (`
|
|
36
|
+
* Mirrors the derived-table builder pattern in `fts.ts` (`buildPlaceSearchFTS`). Run incrementally
|
|
37
37
|
* against an existing `admin-global-priority.db` via `build-coincident-roles-cli.ts`; should also
|
|
38
38
|
* be wired as a post-step of the main `scripts/build-unified-wof.ts`.
|
|
39
39
|
*/
|
|
@@ -43,8 +43,8 @@ function tableExists(db, name) {
|
|
|
43
43
|
return !!db.prepare("SELECT 1 FROM sqlite_master WHERE type='table' AND name = ?").get(name);
|
|
44
44
|
}
|
|
45
45
|
/**
|
|
46
|
-
* Derive the coincident-roles relation into `db`. Additive — only creates/replaces the
|
|
47
|
-
*
|
|
46
|
+
* Derive the coincident-roles relation into `db`. Additive — only creates/replaces the `coincident_roles` table; never
|
|
47
|
+
* touches `spr`/`names`/`ancestors`. Idempotent.
|
|
48
48
|
*/
|
|
49
49
|
export function buildCoincidentRoles(db, opts = {}) {
|
|
50
50
|
const start = Date.now();
|
|
@@ -129,9 +129,9 @@ export function coincidentRolesExists(db) {
|
|
|
129
129
|
return tableExists(db, COINCIDENT_ROLES_TABLE);
|
|
130
130
|
}
|
|
131
131
|
/**
|
|
132
|
-
* Load the relation into an in-memory map keyed by `admin_id` for O(1) runtime lookup (#405). Each
|
|
133
|
-
*
|
|
134
|
-
*
|
|
132
|
+
* Load the relation into an in-memory map keyed by `admin_id` for O(1) runtime lookup (#405). Each admin may map to
|
|
133
|
+
* MULTIPLE same-name descendants; the consumer disambiguates (min distance → population → abstain). Returns an empty
|
|
134
|
+
* map when the table is absent.
|
|
135
135
|
*/
|
|
136
136
|
export function loadCoincidentRoles(db) {
|
|
137
137
|
const map = new Map();
|
|
@@ -143,7 +143,7 @@ export function loadCoincidentRoles(db) {
|
|
|
143
143
|
.all();
|
|
144
144
|
for (const r of rows) {
|
|
145
145
|
const entry = {
|
|
146
|
-
|
|
146
|
+
localityID: r.locality_id,
|
|
147
147
|
relationshipType: r.relationship_type,
|
|
148
148
|
adminPlacetype: r.admin_placetype,
|
|
149
149
|
distanceKm: r.distance_km,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coincident-roles.js","sourceRoot":"","sources":["../coincident-roles.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;
|
|
1
|
+
{"version":3,"file":"coincident-roles.js","sourceRoot":"","sources":["../coincident-roles.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AAIH,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAEhD,MAAM,CAAC,MAAM,sBAAsB,GAAG,kBAAkB,CAAA;AAkDxD,SAAS,WAAW,CAAC,EAAgB,EAAE,IAAY;IAClD,OAAO,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,6DAA6D,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;AAC7F,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CACnC,EAAgB,EAChB,OAAiC,EAAE;IAEnC,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;IACxB,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,IAAI,IAAI,CAAA;IAC9B,MAAM,iBAAiB,GAAG,IAAI,CAAC,iBAAiB,IAAI,IAAI,CAAA;IACxD,MAAM,cAAc,GAAG,IAAI,CAAC,cAAc,IAAI,EAAE,CAAA;IAChD,MAAM,cAAc,GAA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;IACrD,OAAO,WAAW,CAAC,EAAE,EAAE,sBAAsB,CAAC,CAAA;AAC/C,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAAC,EAAgB;IACnD,MAAM,GAAG,GAAG,IAAI,GAAG,EAA4B,CAAA;IAE/C,IAAI,CAAC,qBAAqB,CAAC,EAAE,CAAC;QAAE,OAAO,GAAG,CAAA;IAC1C,MAAM,IAAI,GAAG,EAAE;SACb,OAAO,CACP;UACO,sBAAsB,EAAE,CAC/B;SACA,GAAG,EAOH,CAAA;IAEF,KAAK,MAAM,CAAC,IAAI,IAAI,EAAE,CAAC;QACtB,MAAM,KAAK,GAAmB;YAC7B,UAAU,EAAE,CAAC,CAAC,WAAW;YACzB,gBAAgB,EAAE,CAAC,CAAC,iBAAiB;YACrC,cAAc,EAAE,CAAC,CAAC,eAAe;YACjC,UAAU,EAAE,CAAC,CAAC,WAAW;YACzB,UAAU,EAAE,CAAC,CAAC,mBAAmB;SACjC,CAAA;QACD,MAAM,IAAI,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAA;QAEhC,IAAI,IAAI;YAAE,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;;YACrB,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,CAAC,CAAA;IAClC,CAAC;IAED,OAAO,GAAG,CAAA;AACX,CAAC"}
|
package/out/convention.d.ts
CHANGED
|
@@ -22,8 +22,7 @@
|
|
|
22
22
|
*/
|
|
23
23
|
import type { FindPlaceQuery, PlaceCandidate } from "./types.js";
|
|
24
24
|
/**
|
|
25
|
-
* Soft-scoring weights for the `postcode_area_resolution` strategy: `pc·S_pc + name·S_name +
|
|
26
|
-
* pop·S_pop`.
|
|
25
|
+
* Soft-scoring weights for the `postcode_area_resolution` strategy: `pc·S_pc + name·S_name + pop·S_pop`.
|
|
27
26
|
*/
|
|
28
27
|
export interface ScoringWeights {
|
|
29
28
|
pc: number;
|
|
@@ -31,79 +30,75 @@ export interface ScoringWeights {
|
|
|
31
30
|
pop: number;
|
|
32
31
|
}
|
|
33
32
|
/**
|
|
34
|
-
* A geographically-scoped resolution profile. Namespaced sections grow per phase; #289 ships the
|
|
35
|
-
*
|
|
36
|
-
* `
|
|
33
|
+
* A geographically-scoped resolution profile. Namespaced sections grow per phase; #289 ships the dispatch + scoring
|
|
34
|
+
* slice (`candidateStrategies` + `scoringWeights`). Later phases add `fieldMapping` (locale semantics for `locator[]`),
|
|
35
|
+
* `tokenNormalization`, etc.
|
|
37
36
|
*/
|
|
38
37
|
export interface Convention {
|
|
39
38
|
/** Ordered strategy names the dispatcher runs; the first to return a non-null result wins. */
|
|
40
39
|
candidateStrategies?: string[];
|
|
41
40
|
/**
|
|
42
|
-
* Weights for `postcode_area_resolution`'s soft-score. Partial — a layer may nudge one weight and
|
|
43
|
-
*
|
|
44
|
-
* WORLD_DEFAULT).
|
|
41
|
+
* Weights for `postcode_area_resolution`'s soft-score. Partial — a layer may nudge one weight and inherit the rest
|
|
42
|
+
* from the layers below it (`resolveConvention` fills any gaps from WORLD_DEFAULT).
|
|
45
43
|
*/
|
|
46
44
|
scoringWeights?: Partial<ScoringWeights>;
|
|
47
45
|
}
|
|
48
46
|
/**
|
|
49
|
-
* A fully-resolved convention: every field present, weights complete. What `resolveConvention`
|
|
50
|
-
*
|
|
47
|
+
* A fully-resolved convention: every field present, weights complete. What `resolveConvention` returns and what
|
|
48
|
+
* strategies consume.
|
|
51
49
|
*/
|
|
52
50
|
export interface ResolvedConvention {
|
|
53
51
|
candidateStrategies: string[];
|
|
54
52
|
scoringWeights: ScoringWeights;
|
|
55
53
|
}
|
|
56
54
|
/**
|
|
57
|
-
* The base layer every ancestor chain starts from. Reproduces the pre-engine coordinate-first
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
* run.
|
|
55
|
+
* The base layer every ancestor chain starts from. Reproduces the pre-engine coordinate-first behavior exactly: try
|
|
56
|
+
* `postcode_area_resolution`, else fall back to fuzzy name match; soft-score weights 0.6 / 0.3 / 0.1. Changing these
|
|
57
|
+
* changes EU behavior — don't, without a byte-stability run.
|
|
61
58
|
*/
|
|
62
59
|
export declare const WORLD_DEFAULT: ResolvedConvention;
|
|
63
60
|
/**
|
|
64
|
-
* The strategy names the backend registers. The single source of truth shared by the dispatch
|
|
65
|
-
*
|
|
66
|
-
*
|
|
61
|
+
* The strategy names the backend registers. The single source of truth shared by the dispatch registry and the
|
|
62
|
+
* build-time validator, so an authored convention that names a non-existent strategy is caught at build (loud) rather
|
|
63
|
+
* than silently skipped at runtime.
|
|
67
64
|
*/
|
|
68
65
|
export declare const BUILTIN_STRATEGY_NAMES: readonly ["postcode_area_resolution", "fallback_fuzzy_name_match"];
|
|
69
66
|
/**
|
|
70
|
-
* Table name for the convention asset (#290). Carried here so the build script, the runtime source,
|
|
71
|
-
*
|
|
67
|
+
* Table name for the convention asset (#290). Carried here so the build script, the runtime source, and the shard
|
|
68
|
+
* auto-detect all agree.
|
|
72
69
|
*/
|
|
73
70
|
export declare const ADDRESS_CONVENTION_TABLE = "address_convention";
|
|
74
71
|
/**
|
|
75
|
-
* A named resolution primitive. Returns `null` to abstain (gate unmet / no data) → the dispatcher
|
|
76
|
-
*
|
|
72
|
+
* A named resolution primitive. Returns `null` to abstain (gate unmet / no data) → the dispatcher tries the next
|
|
73
|
+
* strategy; returns an array (possibly empty) to claim the result.
|
|
77
74
|
*/
|
|
78
75
|
export type Strategy = (query: FindPlaceQuery, convention: ResolvedConvention) => Promise<PlaceCandidate[] | null>;
|
|
79
76
|
/**
|
|
80
|
-
* Look up a convention record by WOF polygon id. Returns `undefined` when the polygon has no
|
|
81
|
-
* override.
|
|
77
|
+
* Look up a convention record by WOF polygon id. Returns `undefined` when the polygon has no override.
|
|
82
78
|
*/
|
|
83
79
|
export interface ConventionSource {
|
|
84
|
-
get(
|
|
80
|
+
get(wofID: number): Convention | undefined;
|
|
85
81
|
}
|
|
86
82
|
/**
|
|
87
|
-
* In-memory convention source seeded from a `{
|
|
88
|
-
*
|
|
89
|
-
*
|
|
83
|
+
* In-memory convention source seeded from a `{ wofID: Convention }` map. Empty for the EU locales (they ride
|
|
84
|
+
* `WORLD_DEFAULT`); JP / KR / TW add rows. #290 replaces this with a sqlite-backed source built from source, same
|
|
85
|
+
* distributable-asset discipline as `postcode-locality-intl.db`.
|
|
90
86
|
*/
|
|
91
87
|
export declare class SeedConventionSource implements ConventionSource {
|
|
92
88
|
#private;
|
|
93
89
|
constructor(rows?: Record<number, Convention>);
|
|
94
|
-
get(
|
|
90
|
+
get(wofID: number): Convention | undefined;
|
|
95
91
|
}
|
|
96
92
|
/**
|
|
97
|
-
* Deep-merge convention layers, later (more-specific) layers winning per field.
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
* restating the others.
|
|
93
|
+
* Deep-merge convention layers, later (more-specific) layers winning per field. `candidateStrategies` is replaced
|
|
94
|
+
* wholesale — a convention names its full ordered list, it does not append. `scoringWeights` is merged key-by-key so a
|
|
95
|
+
* locality can nudge one weight without restating the others.
|
|
101
96
|
*/
|
|
102
97
|
export declare function mergeConventions(base: Convention, ...overrides: Array<Convention | undefined>): Convention;
|
|
103
98
|
/**
|
|
104
|
-
* Resolve the effective convention for a place given its ancestor chain, ordered MOST-GENERAL →
|
|
105
|
-
*
|
|
106
|
-
*
|
|
99
|
+
* Resolve the effective convention for a place given its ancestor chain, ordered MOST-GENERAL → MOST-SPECIFIC (country,
|
|
100
|
+
* region, …, locality). Starts from `WORLD_DEFAULT` so every field is defined regardless of which (if any) ancestors
|
|
101
|
+
* carry an override.
|
|
107
102
|
*/
|
|
108
103
|
export declare function resolveConvention(source: ConventionSource, ancestorIds: readonly number[]): ResolvedConvention;
|
|
109
104
|
//# sourceMappingURL=convention.d.ts.map
|
package/out/convention.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convention.d.ts","sourceRoot":"","sources":["../convention.ts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