@mailwoman/photon 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.
- package/README.md +2 -2
- package/{lib/cli.ts → cli/main.ts} +42 -56
- package/lib/app.ts +12 -34
- package/lib/engine.ts +21 -13
- package/lib/index.ts +6 -11
- package/lib/locality-postcode.ts +13 -17
- package/lib/projection.ts +61 -56
- package/lib/routes.ts +14 -26
- package/lib/schema.ts +31 -24
- package/out/app.d.ts +6 -28
- package/out/app.d.ts.map +1 -1
- package/out/app.js +5 -12
- package/out/app.js.map +1 -1
- package/out/cli/main.d.ts +12 -0
- package/out/cli/main.d.ts.map +1 -0
- package/out/{cli.js → cli/main.js} +42 -56
- package/out/cli/main.js.map +1 -0
- package/out/engine.d.ts +21 -13
- package/out/engine.d.ts.map +1 -1
- package/out/engine.js +2 -2
- package/out/engine.js.map +1 -1
- package/out/index.d.ts +6 -11
- package/out/index.d.ts.map +1 -1
- package/out/index.js +6 -11
- package/out/index.js.map +1 -1
- package/out/locality-postcode.d.ts +5 -8
- package/out/locality-postcode.d.ts.map +1 -1
- package/out/locality-postcode.js +11 -15
- package/out/locality-postcode.js.map +1 -1
- package/out/projection.d.ts +48 -38
- package/out/projection.d.ts.map +1 -1
- package/out/projection.js +38 -36
- package/out/projection.js.map +1 -1
- package/out/routes.d.ts +2 -2
- package/out/routes.d.ts.map +1 -1
- package/out/routes.js +13 -25
- package/out/routes.js.map +1 -1
- package/out/schema.d.ts +31 -24
- package/out/schema.d.ts.map +1 -1
- package/out/schema.js +31 -24
- package/out/schema.js.map +1 -1
- package/package.json +49 -33
- package/out/cli.d.ts +0 -17
- package/out/cli.d.ts.map +0 -1
- package/out/cli.js.map +0 -1
|
@@ -4,24 +4,19 @@
|
|
|
4
4
|
* @license AGPL-3.0
|
|
5
5
|
* @author Teffen Ellis, et al.
|
|
6
6
|
*
|
|
7
|
-
* `mailwoman-photon` — boot a Photon-compatible autocomplete endpoint via the `serve` command
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* - Examples live in the package README.
|
|
11
|
-
*
|
|
12
|
-
* Wires the real engine: `/api` over `geocodeAddress` (parse → resolve), `/reverse` over
|
|
13
|
-
* `WOFReverseGeocoder`, projecting results into Photon's GeoJSON FeatureCollection. The FST
|
|
14
|
-
* autocomplete tier is the eventual front for `/api`; geocode resolution is the MVP path.
|
|
7
|
+
* `mailwoman-photon` — boot a Photon-compatible autocomplete endpoint via the `serve` command, wiring
|
|
8
|
+
* `/api` over `geocodeAddress` (parse → resolve) and `/reverse` over `WOFReverseGeocoder` into Photon's
|
|
9
|
+
* GeoJSON FeatureCollection.
|
|
15
10
|
*/
|
|
16
11
|
import { serveNode } from "@mailwoman/api-kit";
|
|
17
12
|
import { matchCountry } from "@mailwoman/codex/country";
|
|
18
|
-
import {
|
|
13
|
+
import { dataRootPath } from "@mailwoman/core/data-root";
|
|
19
14
|
import { parseArguments } from "@mailwoman/core/scripting/arguments";
|
|
20
|
-
import { mailwomanDataRoot } from "@mailwoman/core/utils";
|
|
21
15
|
import { createWOFResolver } from "@mailwoman/resolver";
|
|
22
|
-
import { corsBannerLine, gazetteerBannerLines, loadClassifierOrExit, openAPICommand, resolveGazetteerOrExit, runDropInCLI, } from "mailwoman/cli
|
|
23
|
-
import { geocodeAddress,
|
|
16
|
+
import { corsBannerLine, gazetteerBannerLines, loadClassifierOrExit, openAPICommand, resolveGazetteerOrExit, runDropInCLI, } from "mailwoman/cli/kit/dropin";
|
|
17
|
+
import { geocodeAddress, USStateDatabaseProvider } from "mailwoman/geocode";
|
|
24
18
|
import { createResolverBackend } from "mailwoman/resolver-backend";
|
|
19
|
+
import { titleCase } from "spliterator";
|
|
25
20
|
import { createPhotonApp, PHOTON_DOC_INFO, photonCollection, photonFeature, photonForwardCollection, photonOSMTags, } from "#index";
|
|
26
21
|
import { createLocalityPostcodeLookup } from "#locality-postcode";
|
|
27
22
|
/**
|
|
@@ -36,7 +31,9 @@ const PLACETYPE_TO_KEY = {
|
|
|
36
31
|
country: "country",
|
|
37
32
|
};
|
|
38
33
|
/**
|
|
39
|
-
* A real address fits comfortably
|
|
34
|
+
* A real address fits comfortably.
|
|
35
|
+
*
|
|
36
|
+
* Longer input is malformed and would exceed the model's window.
|
|
40
37
|
*/
|
|
41
38
|
const MAX_QUERY_LEN = 512;
|
|
42
39
|
const BINARY_NAME = "mailwoman-photon";
|
|
@@ -46,8 +43,8 @@ async function serve(engineStamp) {
|
|
|
46
43
|
port: { type: "string", default: "2322" },
|
|
47
44
|
host: { type: "string", default: "0.0.0.0" },
|
|
48
45
|
"candidate-db": { type: "string" },
|
|
49
|
-
// Permissive CORS is on by default
|
|
50
|
-
//
|
|
46
|
+
// Permissive CORS is on by default for upstream Photon parity; `--no-cors` turns it off
|
|
47
|
+
// where a reverse proxy already sets the headers.
|
|
51
48
|
cors: { type: "boolean", default: true },
|
|
52
49
|
},
|
|
53
50
|
allowNegative: true,
|
|
@@ -56,72 +53,62 @@ async function serve(engineStamp) {
|
|
|
56
53
|
const port = Number(values.port) || 2322;
|
|
57
54
|
const host = values.host ?? "0.0.0.0";
|
|
58
55
|
const resolverMod = await import("@mailwoman/resolver-wof-sqlite");
|
|
59
|
-
const gazetteer = await resolveGazetteerOrExit(values["candidate-db"]);
|
|
56
|
+
const gazetteer = await resolveGazetteerOrExit(values["candidate-db"] ?? null);
|
|
60
57
|
const { adminDBPath, candidateDB, wofPaths } = gazetteer;
|
|
61
58
|
const classifier = await loadClassifierOrExit();
|
|
62
59
|
const backend = await createResolverBackend(resolverMod, { wofPaths, candidateDB });
|
|
63
60
|
const resolver = createWOFResolver(backend);
|
|
64
|
-
const extracts = await
|
|
61
|
+
const extracts = await USStateDatabaseProvider.create(resolverMod, dataRootPath());
|
|
65
62
|
const postcodeOfLocality = await createLocalityPostcodeLookup();
|
|
66
|
-
// National open-register rooftop tier
|
|
67
|
-
// when the extract
|
|
68
|
-
const { BANRegionDatabaseProvider } = await import("@mailwoman/ban/
|
|
69
|
-
const banExtracts = await BANRegionDatabaseProvider.create(
|
|
63
|
+
// National open-register rooftop tier: BAN-FR ahead of the OSM tier for a non-US parse,
|
|
64
|
+
// a no-op when the extract is absent.
|
|
65
|
+
const { BANRegionDatabaseProvider } = await import("@mailwoman/ban/region-database-provider");
|
|
66
|
+
const banExtracts = await BANRegionDatabaseProvider.create(dataRootPath());
|
|
70
67
|
const reverseGeo = adminDBPath ? new resolverMod.WOFReverseGeocoder({ adminDBPath }) : undefined;
|
|
71
68
|
const engine = {
|
|
72
69
|
async search(params) {
|
|
73
|
-
// Empty/whitespace → no query; absurdly long → not an address (and would blow the model's input).
|
|
74
70
|
const query = params.q?.trim();
|
|
75
71
|
if (!query || query.length > MAX_QUERY_LEN)
|
|
76
72
|
return photonCollection([]);
|
|
77
|
-
//
|
|
78
|
-
// folds into candidate scoring
|
|
73
|
+
// Forward the client's viewport as a proximity bias, a soft re-rank the resolver
|
|
74
|
+
// folds into candidate scoring, only when both coords are present.
|
|
79
75
|
const bias = params.lat != null && params.lon != null ? [{ lat: params.lat, lon: params.lon }] : undefined;
|
|
80
|
-
// No country constraint
|
|
81
|
-
//
|
|
82
|
-
// non-US query to its US namesake — wrong for a global autocomplete front.
|
|
76
|
+
// No country constraint lets the placer route the query's own country.
|
|
77
|
+
// A hard-coded `US` value here would resolve every non-US query to its US namesake.
|
|
83
78
|
const result = await geocodeAddress(query, {
|
|
84
79
|
classifier,
|
|
85
80
|
resolver,
|
|
86
81
|
databases: extracts.for,
|
|
87
82
|
nationalDatabases: banExtracts.for,
|
|
88
83
|
bias,
|
|
89
|
-
//
|
|
84
|
+
// Photon is an autocomplete front where a human types fragments.
|
|
90
85
|
inputMode: "fragmented",
|
|
91
86
|
});
|
|
92
87
|
if (result.lat == null || result.lon == null)
|
|
93
88
|
return photonCollection([]);
|
|
94
|
-
//
|
|
95
|
-
//
|
|
96
|
-
//
|
|
97
|
-
// so state/county come through only on an ancestry-capable backend — country still lands from the code.
|
|
89
|
+
// Decorate from the resolved place using proper-cased ancestry names,
|
|
90
|
+
// the resolved country and osm_key/value/type.
|
|
91
|
+
// Include state/county only on an ancestry-capable backend.
|
|
98
92
|
const country = matchCountry(result.countryCode);
|
|
99
|
-
//
|
|
100
|
-
//
|
|
101
|
-
//
|
|
93
|
+
// A rooftop or interpolated tier is house-grade: include the parsed housenumber
|
|
94
|
+
// and street so photonForwardProperties decorates it `type: house`
|
|
95
|
+
// rather than the admin locality's `type: city`.
|
|
102
96
|
const houseGrade = result.resolution_tier === "address_point" ||
|
|
103
97
|
result.resolution_tier === "interpolated" ||
|
|
104
98
|
result.resolution_tier === "plus_code";
|
|
105
|
-
//
|
|
106
|
-
// highway/street osm tags
|
|
99
|
+
// The street-centroid tier is street-grade: the full assembled street name
|
|
100
|
+
// in `name` plus highway/street osm tags.
|
|
107
101
|
const streetGrade = result.resolution_tier === "street";
|
|
108
|
-
// The register row's own
|
|
109
|
-
//
|
|
110
|
-
// postcode even when the query never named them, and #1014's decorate-from-the-resolved-place
|
|
111
|
-
// doctrine covers register attestations exactly as it covers gazetteer rows. The key form is
|
|
112
|
-
// normalized; title-case it for display (the extracts store no display-cased locality).
|
|
102
|
+
// The register row's own locality decorates a house-grade answer whose hierarchy
|
|
103
|
+
// has no locality, title-cased because extracts store no display-cased locality.
|
|
113
104
|
const places = result.hierarchy.map((h) => ({ tag: h.tag, name: h.name }));
|
|
114
105
|
if (result.rooftop?.localityNorm && !places.some((p) => p.tag === "locality")) {
|
|
115
|
-
|
|
116
|
-
// pyTitle display-cases it particle-and-apostrophe-aware.
|
|
117
|
-
places.push({ tag: "locality", name: pyTitle(result.rooftop.localityNorm) });
|
|
106
|
+
places.push({ tag: "locality", name: titleCase(result.rooftop.localityNorm) });
|
|
118
107
|
}
|
|
119
|
-
// Locality→postcode enrichment: an admin answer
|
|
120
|
-
// unambiguous (exactly one
|
|
121
|
-
//
|
|
122
|
-
|
|
123
|
-
// name matching is involved.
|
|
124
|
-
let enrichedPostcode;
|
|
108
|
+
// Locality→postcode enrichment: an admin answer whose containing postcode is
|
|
109
|
+
// unambiguous (exactly one, keyed by the resolved place's WOF ID) includes it.
|
|
110
|
+
// A multi-postcode city gets no postcode.
|
|
111
|
+
let enrichedPostcode = null;
|
|
125
112
|
if (!result.postcode && !result.rooftop?.postcode) {
|
|
126
113
|
const localityID = result.hierarchy.find((h) => (h.tag === "locality" || h.tag === "localadmin") && h.placeID?.startsWith("wof:"))?.placeID;
|
|
127
114
|
if (localityID) {
|
|
@@ -137,8 +124,8 @@ async function serve(engineStamp) {
|
|
|
137
124
|
...(houseGrade ? { house: { number: result.house_number, street: result.street } } : {}),
|
|
138
125
|
...(streetGrade ? { street: { name: result.street } } : {}),
|
|
139
126
|
};
|
|
140
|
-
//
|
|
141
|
-
// extra features
|
|
127
|
+
// candidates[0] is the primary.
|
|
128
|
+
// Its ranked alternatives become extra features up to the requested `limit`.
|
|
142
129
|
const alternatives = result.candidates.slice(1).map((c) => {
|
|
143
130
|
const cc = matchCountry(c.countryCode);
|
|
144
131
|
return {
|
|
@@ -157,8 +144,7 @@ async function serve(engineStamp) {
|
|
|
157
144
|
if (!hierarchy.length)
|
|
158
145
|
return photonCollection([]);
|
|
159
146
|
const deepest = hierarchy[0];
|
|
160
|
-
//
|
|
161
|
-
// no Photon client should dereference an undefined osm_key on a reverse result either.
|
|
147
|
+
// Include osm_key/osm_value/type from the deepest placetype so `/reverse` matches `/api`'s schema.
|
|
162
148
|
const properties = {
|
|
163
149
|
name: deepest.name,
|
|
164
150
|
countrycode: deepest.country?.toLowerCase(),
|
|
@@ -197,4 +183,4 @@ await runDropInCLI({
|
|
|
197
183
|
" openapi [--flavor 3.1|3.0] [--out <path>]",
|
|
198
184
|
],
|
|
199
185
|
});
|
|
200
|
-
//# sourceMappingURL=
|
|
186
|
+
//# sourceMappingURL=main.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.js","sourceRoot":"","sources":["../../cli/main.ts"],"names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AE,MAAM,EAAE,WAAW,CAAC,KAAK,EAAE,CAAC,CAAA;IAErF,MAAM,SAAS,CAAC;QACf,KAAK,EAAE,GAAG,CAAC,KAAK;QAChB,IAAI;QACJ,QAAQ,EAAE,IAAI;QACd,QAAQ,EAAE,GAAG,EAAE;YACd,OAAO,CAAC,KAAK,CAAC,2CAA2C,IAAI,IAAI,IAAI,EAAE,CAAC,CAAA;YAExE,KAAK,MAAM,IAAI,IAAI,oBAAoB,CAAC,SAAS,CAAC,EAAE,CAAC;gBACpD,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;YACpB,CAAC;YAED,OAAO,CAAC,KAAK,CAAC,cAAc,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAA;YAC1C,OAAO,CAAC,KAAK,CAAC,+DAA+D,CAAC,CAAA;QAC/E,CAAC;KACD,CAAC,CAAA;AACH,CAAC;AAED,MAAM,YAAY,CAAC;IAClB,UAAU,EAAE,WAAW;IACvB,OAAO,EAAE,cAAc,CAAC,WAAW,EAAE,eAAe,EAAE,eAAe,EAAE,EAAE,CAAC;IAC1E,KAAK;IACL,KAAK,EAAE;QACN,4EAA4E;QAC5E,6CAA6C;KAC7C;CACD,CAAC,CAAA"}
|
package/out/engine.d.ts
CHANGED
|
@@ -3,13 +3,16 @@
|
|
|
3
3
|
* @license AGPL-3.0
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
5
|
*
|
|
6
|
-
* The Photon engine
|
|
6
|
+
* The Photon engine interface + wire types the router delegates to. Feature/collection
|
|
7
7
|
* construction lives here too (`photonFeature`, `photonCollection`) since every projection
|
|
8
|
-
* builds on them
|
|
8
|
+
* builds on them. the resolved-place → {@link PhotonProperties} projection itself lives in
|
|
9
9
|
* `projection.ts`.
|
|
10
10
|
*/
|
|
11
11
|
/**
|
|
12
|
-
* Photon feature properties
|
|
12
|
+
* Photon feature properties.
|
|
13
|
+
*
|
|
14
|
+
* OSM-derived tag names, populated from Mailwoman's `ComponentTag` / resolved place.
|
|
15
|
+
*
|
|
13
16
|
* `extent` is `[minLon, maxLat, maxLon, minLat]` per Photon's convention.
|
|
14
17
|
*/
|
|
15
18
|
export interface PhotonProperties {
|
|
@@ -55,15 +58,15 @@ export interface PhotonFeatureCollection {
|
|
|
55
58
|
export interface PhotonSearchParams {
|
|
56
59
|
q: string;
|
|
57
60
|
limit: number;
|
|
58
|
-
lang?: string;
|
|
61
|
+
lang?: string | null;
|
|
59
62
|
/**
|
|
60
63
|
* Location bias.
|
|
61
64
|
*/
|
|
62
|
-
lat?: number;
|
|
63
|
-
lon?: number;
|
|
64
|
-
bbox?: [number, number, number, number];
|
|
65
|
-
osmTag?: string[];
|
|
66
|
-
layer?: string[];
|
|
65
|
+
lat?: number | null;
|
|
66
|
+
lon?: number | null;
|
|
67
|
+
bbox?: [number, number, number, number] | null;
|
|
68
|
+
osmTag?: string[] | null;
|
|
69
|
+
layer?: string[] | null;
|
|
67
70
|
}
|
|
68
71
|
/**
|
|
69
72
|
* Parsed `/reverse` parameters.
|
|
@@ -72,12 +75,17 @@ export interface PhotonReverseParams {
|
|
|
72
75
|
lat: number;
|
|
73
76
|
lon: number;
|
|
74
77
|
limit: number;
|
|
75
|
-
lang?: string;
|
|
76
|
-
radius?: number;
|
|
78
|
+
lang?: string | null;
|
|
79
|
+
radius?: number | null;
|
|
77
80
|
}
|
|
78
81
|
/**
|
|
79
|
-
* The engine the router delegates to.
|
|
80
|
-
*
|
|
82
|
+
* The engine the router delegates to.
|
|
83
|
+
*
|
|
84
|
+
* Each method is optional.
|
|
85
|
+
* A missing one answers `501`.
|
|
86
|
+
*
|
|
87
|
+
* The real implementation backs `/api` with the FST autocomplete tier + parse→resolve.
|
|
88
|
+
* and `/reverse` with the `WOFReverseGeocoder`.
|
|
81
89
|
*/
|
|
82
90
|
export interface PhotonEngine {
|
|
83
91
|
search?(params: PhotonSearchParams): Promise<PhotonFeatureCollection>;
|
package/out/engine.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../lib/engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH
|
|
1
|
+
{"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../lib/engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH;;;;;;GAMG;AACH,MAAM,WAAW,gBAAgB;IAChC,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAA;IACzC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC7B,IAAI,EAAE,SAAS,CAAA;IACf,QAAQ,EAAE;QACT,IAAI,EAAE,OAAO,CAAA;QACb,WAAW,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;KAC7B,CAAA;IACD,UAAU,EAAE,gBAAgB,CAAA;CAC5B;AAED;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACvC,IAAI,EAAE,mBAAmB,CAAA;IACzB,QAAQ,EAA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Teffen Ellis, et al.
|
|
5
5
|
*
|
|
6
|
-
* The Photon engine
|
|
6
|
+
* The Photon engine interface + wire types the router delegates to. Feature/collection
|
|
7
7
|
* construction lives here too (`photonFeature`, `photonCollection`) since every projection
|
|
8
|
-
* builds on them
|
|
8
|
+
* builds on them. the resolved-place → {@link PhotonProperties} projection itself lives in
|
|
9
9
|
* `projection.ts`.
|
|
10
10
|
*/
|
|
11
11
|
/**
|
package/out/engine.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"engine.js","sourceRoot":"","sources":["../lib/engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;
|
|
1
|
+
{"version":3,"file":"engine.js","sourceRoot":"","sources":["../lib/engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AA2FH;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,GAAW,EAAE,GAAW,EAAE,UAA4B;IACnF,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,EAAE,UAAU,EAAE,CAAA;AAC7F,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,QAAyB;IACzD,OAAO,EAAE,IAAI,EAAE,mBAAmB,EAAE,QAAQ,EAAE,CAAA;AAC/C,CAAC"}
|
package/out/index.d.ts
CHANGED
|
@@ -3,20 +3,15 @@
|
|
|
3
3
|
* @license AGPL-3.0
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
5
|
*
|
|
6
|
-
* `@mailwoman/photon`
|
|
6
|
+
* `@mailwoman/photon` is a Photon-compatible autocomplete / type-ahead geocoding API over the
|
|
7
7
|
* Mailwoman engine. Where `@mailwoman/nominatim` is structured lookup, Photon is
|
|
8
8
|
* search-as-you-type: a GeoJSON `FeatureCollection` per query, biased by location, ranked for
|
|
9
|
-
* prefixes. It maps onto Mailwoman's shipped FST autocomplete tier
|
|
10
|
-
*
|
|
9
|
+
* prefixes. It maps onto Mailwoman's shipped FST autocomplete tier and the parse then resolve
|
|
10
|
+
* path.
|
|
11
11
|
*
|
|
12
|
-
* Like its siblings, the package is engine-agnostic
|
|
13
|
-
* {@link PhotonEngine}
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* The Hono app (CORS + error envelope + the emitted OpenAPI document) lives in `app.ts`; route
|
|
17
|
-
* definitions + handlers in `routes.ts`; wire types + the engine contract in `engine.ts`; the
|
|
18
|
-
* resolved-place → Photon-schema projection in `projection.ts`; the zod wire schemas in
|
|
19
|
-
* `schema.ts`.
|
|
12
|
+
* Like its siblings, the package is engine-agnostic. {@link createPhotonApp} takes a
|
|
13
|
+
* {@link PhotonEngine}, and the CLI wires the real engine. Routes whose engine method is absent
|
|
14
|
+
* answer `501`.
|
|
20
15
|
*/
|
|
21
16
|
export * from "#app";
|
|
22
17
|
export * from "#engine";
|
package/out/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,cAAc,MAAM,CAAA;AACpB,cAAc,SAAS,CAAA;AACvB,cAAc,aAAa,CAAA;AAC3B,cAAc,SAAS,CAAA"}
|
package/out/index.js
CHANGED
|
@@ -3,20 +3,15 @@
|
|
|
3
3
|
* @license AGPL-3.0
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
5
|
*
|
|
6
|
-
* `@mailwoman/photon`
|
|
6
|
+
* `@mailwoman/photon` is a Photon-compatible autocomplete / type-ahead geocoding API over the
|
|
7
7
|
* Mailwoman engine. Where `@mailwoman/nominatim` is structured lookup, Photon is
|
|
8
8
|
* search-as-you-type: a GeoJSON `FeatureCollection` per query, biased by location, ranked for
|
|
9
|
-
* prefixes. It maps onto Mailwoman's shipped FST autocomplete tier
|
|
10
|
-
*
|
|
9
|
+
* prefixes. It maps onto Mailwoman's shipped FST autocomplete tier and the parse then resolve
|
|
10
|
+
* path.
|
|
11
11
|
*
|
|
12
|
-
* Like its siblings, the package is engine-agnostic
|
|
13
|
-
* {@link PhotonEngine}
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* The Hono app (CORS + error envelope + the emitted OpenAPI document) lives in `app.ts`; route
|
|
17
|
-
* definitions + handlers in `routes.ts`; wire types + the engine contract in `engine.ts`; the
|
|
18
|
-
* resolved-place → Photon-schema projection in `projection.ts`; the zod wire schemas in
|
|
19
|
-
* `schema.ts`.
|
|
12
|
+
* Like its siblings, the package is engine-agnostic. {@link createPhotonApp} takes a
|
|
13
|
+
* {@link PhotonEngine}, and the CLI wires the real engine. Routes whose engine method is absent
|
|
14
|
+
* answer `501`.
|
|
20
15
|
*/
|
|
21
16
|
export * from "#app";
|
|
22
17
|
export * from "#engine";
|
package/out/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,cAAc,MAAM,CAAA;AACpB,cAAc,SAAS,CAAA;AACvB,cAAc,aAAa,CAAA;AAC3B,cAAc,SAAS,CAAA"}
|
|
@@ -3,15 +3,12 @@
|
|
|
3
3
|
* @license AGPL-3.0
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
5
|
*
|
|
6
|
-
* Reverse lookup over the `postcode-locality-*.db` artifacts: the
|
|
7
|
-
* resolved locality, keyed by its WOF id
|
|
8
|
-
* enrichment: a village answer carries the postcode the gazetteer attests for it.
|
|
6
|
+
* Reverse lookup over the `postcode-locality-*.db` artifacts: the containing postcode of a
|
|
7
|
+
* resolved locality, keyed by its WOF id.
|
|
9
8
|
*
|
|
10
|
-
* The exactly-one rule is the abstention: a locality contained by several postcodes (any real
|
|
11
|
-
*
|
|
12
|
-
* Tolerate-and-degrade like every optional artifact: a machine without the DBs answers undefined
|
|
13
|
-
* everywhere and the consumer simply doesn't decorate.
|
|
9
|
+
* The exactly-one rule is the abstention: a locality contained by several postcodes (any real city) gets
|
|
10
|
+
* no postcode. A machine without the DBs degrades to no enrichment.
|
|
14
11
|
*/
|
|
15
|
-
export type LocalityPostcodeLookup = (wofID: number, countryCode: string | null) => string |
|
|
12
|
+
export type LocalityPostcodeLookup = (wofID: number, countryCode: string | null) => string | null;
|
|
16
13
|
export declare function createLocalityPostcodeLookup(): Promise<LocalityPostcodeLookup>;
|
|
17
14
|
//# sourceMappingURL=locality-postcode.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"locality-postcode.d.ts","sourceRoot":"","sources":["../lib/locality-postcode.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"locality-postcode.d.ts","sourceRoot":"","sources":["../lib/locality-postcode.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAYH,MAAM,MAAM,sBAAsB,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,IAAI,KAAK,MAAM,GAAG,IAAI,CAAA;AAEjG,wBAAsB,4BAA4B,IAAI,OAAO,CAAC,sBAAsB,CAAC,CAwCpF"}
|
package/out/locality-postcode.js
CHANGED
|
@@ -3,17 +3,14 @@
|
|
|
3
3
|
* @license AGPL-3.0
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
5
|
*
|
|
6
|
-
* Reverse lookup over the `postcode-locality-*.db` artifacts: the
|
|
7
|
-
* resolved locality, keyed by its WOF id
|
|
8
|
-
* enrichment: a village answer carries the postcode the gazetteer attests for it.
|
|
6
|
+
* Reverse lookup over the `postcode-locality-*.db` artifacts: the containing postcode of a
|
|
7
|
+
* resolved locality, keyed by its WOF id.
|
|
9
8
|
*
|
|
10
|
-
* The exactly-one rule is the abstention: a locality contained by several postcodes (any real
|
|
11
|
-
*
|
|
12
|
-
* Tolerate-and-degrade like every optional artifact: a machine without the DBs answers undefined
|
|
13
|
-
* everywhere and the consumer simply doesn't decorate.
|
|
9
|
+
* The exactly-one rule is the abstention: a locality contained by several postcodes (any real city) gets
|
|
10
|
+
* no postcode. A machine without the DBs degrades to no enrichment.
|
|
14
11
|
*/
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
12
|
+
import { pathExists } from "@mailwoman/core/fs/readers/stat";
|
|
13
|
+
import { wofDatabasePath } from "@mailwoman/resolver-wof-sqlite/paths";
|
|
17
14
|
import { DatabaseClient } from "@mailwoman/sqlite/client";
|
|
18
15
|
/**
|
|
19
16
|
* The per-country artifacts, probed in caller-country order with `intl` as the shared fallback.
|
|
@@ -22,14 +19,13 @@ const POSTCODE_LOCALITY_SUFFIXES = ["fr", "de", "jp", "intl"];
|
|
|
22
19
|
export async function createLocalityPostcodeLookup() {
|
|
23
20
|
const statements = new Map();
|
|
24
21
|
for (const suffix of POSTCODE_LOCALITY_SUFFIXES) {
|
|
25
|
-
const path =
|
|
22
|
+
const path = wofDatabasePath(`postcode-locality-${suffix}.db`);
|
|
26
23
|
if (!(await pathExists(path)))
|
|
27
24
|
continue;
|
|
28
25
|
try {
|
|
29
26
|
const db = new DatabaseClient(path, { readOnly: true });
|
|
30
|
-
// No `is_containing` filter: villages routinely
|
|
31
|
-
//
|
|
32
|
-
// The exactly-one DISTINCT rule below is the entire ambiguity guard.
|
|
27
|
+
// No `is_containing` filter: villages routinely have 0, so the exactly-one
|
|
28
|
+
// distinct rule below is the entire ambiguity guard.
|
|
33
29
|
statements.set(suffix, db.prepare(`SELECT DISTINCT postcode FROM postcode_locality WHERE locality_id = ? LIMIT 2`));
|
|
34
30
|
}
|
|
35
31
|
catch {
|
|
@@ -47,9 +43,9 @@ export async function createLocalityPostcodeLookup() {
|
|
|
47
43
|
if (rows.length === 1)
|
|
48
44
|
return rows[0].postcode;
|
|
49
45
|
if (rows.length > 1)
|
|
50
|
-
return
|
|
46
|
+
return null; // ambiguous — abstain, never guess
|
|
51
47
|
}
|
|
52
|
-
return
|
|
48
|
+
return null;
|
|
53
49
|
};
|
|
54
50
|
}
|
|
55
51
|
//# sourceMappingURL=locality-postcode.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"locality-postcode.js","sourceRoot":"","sources":["../lib/locality-postcode.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"locality-postcode.js","sourceRoot":"","sources":["../lib/locality-postcode.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAA;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAA;AACtE,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAA;AAGzD;;GAEG;AACH,MAAM,0BAA0B,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,CAAU,CAAA;AAItE,MAAM,CAAC,KAAK,UAAU,4BAA4B;IACjD,MAAM,UAAU,GAAG,IAAI,GAAG,EAAiD,CAAA;IAE3E,KAAK,MAAM,MAAM,IAAI,0BAA0B,EAAE,CAAC;QACjD,MAAM,IAAI,GAAG,eAAe,CAAC,qBAAqB,MAAM,KAAK,CAAC,CAAA;QAE9D,IAAI,CAAC,CAAC,MAAM,UAAU,CAAC,IAAI,CAAC,CAAC;YAAE,SAAQ;QAEvC,IAAI,CAAC;YACJ,MAAM,EAAE,GAAG,IAAI,cAAc,CAA2B,IAAI,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAA;YAEjF,2EAA2E;YAC3E,qDAAqD;YACrD,UAAU,CAAC,GAAG,CACb,MAAM,EACN,EAAE,CAAC,OAAO,CAAC,+EAA+E,CAAC,CAC3F,CAAA;QACF,CAAC;QAAC,MAAM,CAAC;YACR,kFAAkF;QACnF,CAAC;IACF,CAAC;IAED,OAAO,CAAC,KAAK,EAAE,WAAW,EAAE,EAAE;QAC7B,MAAM,EAAE,GAAG,WAAW,EAAE,WAAW,EAAE,CAAA;QACrC,MAAM,KAAK,GAAG,EAAE,IAAI,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAA;QAEhE,KAAK,MAAM,MAAM,IAAI,KAAK,EAAE,CAAC;YAC5B,MAAM,IAAI,GAAG,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;YAEnC,IAAI,CAAC,IAAI;gBAAE,SAAQ;YAEnB,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAgC,CAAA;YAE3D,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;gBAAE,OAAO,IAAI,CAAC,CAAC,CAAE,CAAC,QAAQ,CAAA;YAE/C,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC;gBAAE,OAAO,IAAI,CAAA,CAAC,mCAAmC;QACrE,CAAC;QAED,OAAO,IAAI,CAAA;IACZ,CAAC,CAAA;AACF,CAAC"}
|
package/out/projection.d.ts
CHANGED
|
@@ -3,17 +3,18 @@
|
|
|
3
3
|
* @license AGPL-3.0
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
5
|
*
|
|
6
|
-
* The
|
|
7
|
-
* cased names
|
|
8
|
-
* plus the `format=jsonld` schema.org re-serialization.
|
|
9
|
-
* construction live in `engine.ts`.
|
|
6
|
+
* The resolved-place → Photon-schema projection: decorating a resolved gazetteer place (proper-
|
|
7
|
+
* cased names, ancestry, country, house and street grade overrides) into {@link PhotonProperties},
|
|
8
|
+
* plus the `format=jsonld` schema.org re-serialization.
|
|
10
9
|
*/
|
|
11
10
|
import { type SchemaOrgPlace } from "@mailwoman/annotations";
|
|
12
11
|
import { type PhotonFeature, type PhotonFeatureCollection, type PhotonProperties } from "#engine";
|
|
13
12
|
/**
|
|
14
|
-
* The resolved-place info a forward `/api` result
|
|
15
|
-
* the coordinate, the resolved country
|
|
16
|
-
*
|
|
13
|
+
* The resolved-place info in a forward `/api` result: the admin ladder (most-specific first)
|
|
14
|
+
* with gazetteer names, the coordinate, the resolved country and the postcode.
|
|
15
|
+
* {@link photonForwardProperties} projects it onto Photon's schema.
|
|
16
|
+
*
|
|
17
|
+
* Decorate from the resolved place rather than the parsed input span.
|
|
17
18
|
*/
|
|
18
19
|
export interface PhotonForwardInput {
|
|
19
20
|
lat: number;
|
|
@@ -27,42 +28,43 @@ export interface PhotonForwardInput {
|
|
|
27
28
|
code?: string;
|
|
28
29
|
} | null;
|
|
29
30
|
/**
|
|
30
|
-
* Resolved admin ancestry, most-specific first, each carrying the gazetteer's
|
|
31
|
+
* Resolved admin ancestry, most-specific first, each carrying the gazetteer's
|
|
32
|
+
* canonical name rather than the parsed span.
|
|
31
33
|
*/
|
|
32
34
|
places: ReadonlyArray<{
|
|
33
35
|
tag: string;
|
|
34
36
|
name: string;
|
|
35
37
|
}>;
|
|
36
38
|
/**
|
|
37
|
-
* A
|
|
38
|
-
* `address_point` (rooftop) or `interpolated` tier
|
|
39
|
-
* re-tags the schema `osm_key: place` /
|
|
40
|
-
* `
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
39
|
+
* A house-grade result: set only when the resolver produced a specific building coordinate,
|
|
40
|
+
* the `address_point` (rooftop) or `interpolated` tier rather than an admin centroid.
|
|
41
|
+
* {@link photonForwardProperties} then re-tags the schema `osm_key: place` /
|
|
42
|
+
* `osm_value: house` / `type: house` and surfaces the parsed `housenumber` + `street`,
|
|
43
|
+
* matching upstream komoot/photon's bare-address-point shape.
|
|
44
|
+
*
|
|
45
|
+
* Absent means the result keeps its admin-ancestry schema.
|
|
44
46
|
*/
|
|
45
47
|
house?: {
|
|
46
48
|
number?: string | null;
|
|
47
49
|
street?: string | null;
|
|
48
50
|
} | null;
|
|
49
51
|
/**
|
|
50
|
-
* A
|
|
51
|
-
* below rooftop/interp
|
|
52
|
-
* residential` / `type: street` with the
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
* never street-tiers).
|
|
52
|
+
* A street-grade result: set when the street-centroid tier fired, a street-level
|
|
53
|
+
* coordinate below rooftop/interp and above admin. {@link photonForwardProperties}
|
|
54
|
+
* re-tags it `osm_key: highway` / `osm_value: residential` / `type: street` with the
|
|
55
|
+
* full assembled street name in `name`, matching upstream komoot's street results.
|
|
56
|
+
*
|
|
57
|
+
* `house` wins when both are set, since a numbered query never street-tiers.
|
|
57
58
|
*/
|
|
58
59
|
street?: {
|
|
59
60
|
name?: string | null;
|
|
60
61
|
} | null;
|
|
61
62
|
}
|
|
62
63
|
/**
|
|
63
|
-
* The Photon `osm_key`/`osm_value`/`type` for a resolved tag or WOF placetype
|
|
64
|
-
* falling back to a safe default so the fields are always present.
|
|
65
|
-
*
|
|
64
|
+
* The Photon `osm_key`/`osm_value`/`type` for a resolved tag or WOF placetype
|
|
65
|
+
* (`locality`, `region`, `country`, …), falling back to a safe default so the fields are always present.
|
|
66
|
+
*
|
|
67
|
+
* Shared by the forward projection and `/reverse` so the two endpoints report a place the same way.
|
|
66
68
|
*/
|
|
67
69
|
export declare function photonOSMTags(tagOrPlacetype: string): {
|
|
68
70
|
osm_key: string;
|
|
@@ -70,17 +72,19 @@ export declare function photonOSMTags(tagOrPlacetype: string): {
|
|
|
70
72
|
type: string;
|
|
71
73
|
};
|
|
72
74
|
/**
|
|
73
|
-
* Project a resolved forward result into Photon properties
|
|
74
|
-
* names
|
|
75
|
-
*
|
|
75
|
+
* Project a resolved forward result into Photon properties, decorating from the resolved
|
|
76
|
+
* gazetteer place (proper-cased names, ancestry, country) rather than the parsed input span.
|
|
77
|
+
*
|
|
78
|
+
* Always emit `osm_key`/`osm_value`/`type` so Photon client libraries
|
|
79
|
+
* (leaflet-control-geocoder, @openrunner/photon-geocoder) never dereference undefined.
|
|
76
80
|
*/
|
|
77
81
|
export declare function photonForwardProperties(input: PhotonForwardInput): PhotonProperties;
|
|
78
82
|
/**
|
|
79
|
-
* {@link photonForwardProperties}, wrapped as a Photon Point `Feature` at the resolved coordinate.
|
|
83
|
+
* {@link photonForwardProperties}, wrapped as a Photon Point `Feature` at the resolved coordinate.
|
|
80
84
|
*/
|
|
81
85
|
export declare function photonForwardFeature(input: PhotonForwardInput): PhotonFeature;
|
|
82
86
|
/**
|
|
83
|
-
* The winning place plus its ranked alternatives
|
|
87
|
+
* The winning place plus its ranked alternatives, the input to {@link photonForwardCollection}.
|
|
84
88
|
*/
|
|
85
89
|
export interface PhotonForwardResult {
|
|
86
90
|
/**
|
|
@@ -88,24 +92,30 @@ export interface PhotonForwardResult {
|
|
|
88
92
|
*/
|
|
89
93
|
primary: PhotonForwardInput;
|
|
90
94
|
/**
|
|
91
|
-
* Ranked alternative places (Springfield MA / IL / …), each a single-place input
|
|
95
|
+
* Ranked alternative places (Springfield MA / IL / …), each a single-place input.
|
|
96
|
+
* Excludes the primary.
|
|
92
97
|
*/
|
|
93
98
|
alternatives: PhotonForwardInput[];
|
|
94
99
|
}
|
|
95
100
|
/**
|
|
96
|
-
* Assemble a Photon `FeatureCollection` honoring `limit
|
|
97
|
-
* capped at `limit`.
|
|
101
|
+
* Assemble a Photon `FeatureCollection` honoring `limit`: the primary feature first,
|
|
102
|
+
* then ranked alternatives, capped at `limit`.
|
|
103
|
+
*
|
|
104
|
+
* `limit` floors to 1, since Photon always returns at least the best match.
|
|
98
105
|
*/
|
|
99
106
|
export declare function photonForwardCollection(result: PhotonForwardResult, limit: number): PhotonFeatureCollection;
|
|
100
107
|
/**
|
|
101
|
-
* Project a Photon `Feature` into a schema.org `Place` JSON-LD object (`format=jsonld
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
108
|
+
* Project a Photon `Feature` into a schema.org `Place` JSON-LD object (`format=jsonld`),
|
|
109
|
+
* the output-format projection.
|
|
110
|
+
*
|
|
111
|
+
* Reads the feature's already-decorated {@link PhotonProperties}
|
|
112
|
+
* (housenumber/street/city/state/postcode/countrycode and the coordinate), so it stays a
|
|
113
|
+
* pure re-serialization of the same resolved place included in the FeatureCollection.
|
|
114
|
+
* `streetAddress` is the plain house-number-first join, since the light router has no locale formatter.
|
|
105
115
|
*/
|
|
106
116
|
export declare function photonFeatureToSchemaOrg(feature: PhotonFeature): SchemaOrgPlace;
|
|
107
117
|
/**
|
|
108
|
-
* Project a whole Photon `FeatureCollection` into an array of schema.org `Place` objects (`format=jsonld`).
|
|
118
|
+
* Project a whole Photon `FeatureCollection` into an array of schema.org `Place` objects (`format=jsonld`).
|
|
109
119
|
*/
|
|
110
120
|
export declare function photonToSchemaOrg(collection: PhotonFeatureCollection): SchemaOrgPlace[];
|
|
111
121
|
//# sourceMappingURL=projection.d.ts.map
|