@mailwoman/ogc 0.0.0-stage → 11.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 +149 -2
- package/cli/main.ts +153 -0
- package/lib/app.ts +99 -0
- package/lib/collections.ts +159 -0
- package/lib/engine.ts +71 -0
- package/lib/format.ts +46 -0
- package/lib/html.ts +236 -0
- package/lib/index.ts +20 -0
- package/lib/projection.ts +206 -0
- package/lib/routes.ts +587 -0
- package/lib/schema.ts +296 -0
- package/out/app.d.ts +33 -0
- package/out/app.d.ts.map +1 -0
- package/out/app.js +67 -0
- package/out/app.js.map +1 -0
- package/out/cli/main.d.ts +3 -0
- package/out/cli/main.d.ts.map +1 -0
- package/out/cli/main.js +118 -0
- package/out/cli/main.js.map +1 -0
- package/out/collections.d.ts +72 -0
- package/out/collections.d.ts.map +1 -0
- package/out/collections.js +103 -0
- package/out/collections.js.map +1 -0
- package/out/engine.d.ts +65 -0
- package/out/engine.d.ts.map +1 -0
- package/out/engine.js +4 -0
- package/out/engine.js.map +1 -0
- package/out/format.d.ts +18 -0
- package/out/format.d.ts.map +1 -0
- package/out/format.js +31 -0
- package/out/format.js.map +1 -0
- package/out/html.d.ts +42 -0
- package/out/html.d.ts.map +1 -0
- package/out/html.js +153 -0
- package/out/html.js.map +1 -0
- package/out/index.d.ts +17 -0
- package/out/index.d.ts.map +1 -0
- package/out/index.js +19 -0
- package/out/index.js.map +1 -0
- package/out/projection.d.ts +26 -0
- package/out/projection.d.ts.map +1 -0
- package/out/projection.js +168 -0
- package/out/projection.js.map +1 -0
- package/out/routes.d.ts +93 -0
- package/out/routes.d.ts.map +1 -0
- package/out/routes.js +429 -0
- package/out/routes.js.map +1 -0
- package/out/schema.d.ts +267 -0
- package/out/schema.d.ts.map +1 -0
- package/out/schema.js +241 -0
- package/out/schema.js.map +1 -0
- package/package.json +98 -3
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
|
|
3
|
+
/**
|
|
4
|
+
* The projection from a geocode result to `/search` matches.
|
|
5
|
+
*
|
|
6
|
+
* The result's coordinate is the first match, in the collection its tier names.
|
|
7
|
+
* The places the resolver weighed for the same part of the input follow,
|
|
8
|
+
* each in the collection its placetype names.
|
|
9
|
+
*/
|
|
10
|
+
import { formatAddress } from "@mailwoman/codex/address/format";
|
|
11
|
+
import { matchCountry } from "@mailwoman/codex/country";
|
|
12
|
+
import { ScoreUnmeasuredReason, wofIDFromPlaceID } from "@mailwoman/core/resolver";
|
|
13
|
+
import { collectionOfPlacetype, collectionOfTier, OGCCollectionID } from "#collections";
|
|
14
|
+
function hierarchyName(result, tag) {
|
|
15
|
+
return result.hierarchy.find((entry) => entry.tag === tag)?.name ?? null;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The resolved names, most specific first, with a repeated name dropped
|
|
19
|
+
* and the country appended when the hierarchy doesn't name it.
|
|
20
|
+
*/
|
|
21
|
+
function hierarchyLabel(result) {
|
|
22
|
+
const names = [];
|
|
23
|
+
for (const { name } of result.hierarchy) {
|
|
24
|
+
if (name && !names.includes(name)) {
|
|
25
|
+
names.push(name);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
const country = matchCountry(result.countryCode)?.canonical;
|
|
29
|
+
if (names.length && country && !names.includes(country)) {
|
|
30
|
+
names.push(country);
|
|
31
|
+
}
|
|
32
|
+
return names.join(", ");
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The one-line address of a house-grade or street-grade answer, in the country's own order.
|
|
36
|
+
*/
|
|
37
|
+
function addressLabel(result, withHouseNumber) {
|
|
38
|
+
const country = matchCountry(result.countryCode);
|
|
39
|
+
const postcode = result.postcode ?? result.rooftop?.postcode ?? null;
|
|
40
|
+
const locality = hierarchyName(result, "locality") ?? result.locality;
|
|
41
|
+
const region = hierarchyName(result, "region") ?? result.region;
|
|
42
|
+
const components = {
|
|
43
|
+
...(withHouseNumber && result.house_number ? { house_number: result.house_number } : {}),
|
|
44
|
+
...(result.street ? { street: result.street } : {}),
|
|
45
|
+
...(result.unit && withHouseNumber ? { unit: result.unit } : {}),
|
|
46
|
+
...(postcode ? { postcode } : {}),
|
|
47
|
+
...(locality ? { locality } : {}),
|
|
48
|
+
...(region ? { region } : {}),
|
|
49
|
+
...(country?.canonical ? { country: country.canonical } : {}),
|
|
50
|
+
};
|
|
51
|
+
const formatted = country ? formatAddress(components, country.iso2, { singleLine: true, withRegion: true }) : "";
|
|
52
|
+
// A country with no recorded layout renders an empty string, so the parts join in the order they were read.
|
|
53
|
+
return formatted || Object.values(components).join(", ");
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* The candidate the answer's coordinate came from, when the coordinate is a gazetteer place's.
|
|
57
|
+
*/
|
|
58
|
+
function answeringCandidate(result) {
|
|
59
|
+
if (result.resolution_tier !== "admin" && result.resolution_tier !== "postcode")
|
|
60
|
+
return null;
|
|
61
|
+
return result.candidates.find((candidate) => candidate.lat === result.lat && candidate.lon === result.lon) ?? null;
|
|
62
|
+
}
|
|
63
|
+
function scoreOf(candidate) {
|
|
64
|
+
if (candidate && typeof candidate.score === "number")
|
|
65
|
+
return { score: candidate.score };
|
|
66
|
+
return { score: null, scoreUnmeasured: candidate?.scoreUnmeasured ?? ScoreUnmeasuredReason.Unrecorded };
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* A gazetteer place's label: its name, the ancestors the gazetteer records between it
|
|
70
|
+
* and its country, most specific first, and the country.
|
|
71
|
+
*
|
|
72
|
+
* A name repeated by an ancestor appears once.
|
|
73
|
+
* Without a WOF place ID or a recorded ancestry the label is the name and the country.
|
|
74
|
+
*/
|
|
75
|
+
function candidateLabel(candidate, ancestorsOf) {
|
|
76
|
+
const names = [candidate.name];
|
|
77
|
+
const wofID = wofIDFromPlaceID(candidate.placeID);
|
|
78
|
+
if (ancestorsOf && wofID != null) {
|
|
79
|
+
for (const ancestor of ancestorsOf(wofID)) {
|
|
80
|
+
if (ancestor.placetype !== "country" && ancestor.name && !names.includes(ancestor.name)) {
|
|
81
|
+
names.push(ancestor.name);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
const country = matchCountry(candidate.countryCode)?.canonical;
|
|
86
|
+
if (country && !names.includes(country)) {
|
|
87
|
+
names.push(country);
|
|
88
|
+
}
|
|
89
|
+
return names.join(", ");
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* The gazetteer identity of a place match, so two places that share a label stay apart.
|
|
93
|
+
*/
|
|
94
|
+
function placeIdentity(candidate) {
|
|
95
|
+
return { ...(candidate.placeID ? { placeID: candidate.placeID } : {}), placetype: candidate.placetype };
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* The `/search` matches for one geocode result, best first.
|
|
99
|
+
*
|
|
100
|
+
* The answer's own coordinate comes first.
|
|
101
|
+
* Its score is the resolver's score for the gazetteer place it came from.
|
|
102
|
+
*
|
|
103
|
+
* An answer placed by an address point, an interpolation or a street centroid
|
|
104
|
+
* has no measured score, so its score is null.
|
|
105
|
+
*
|
|
106
|
+
* The places the resolver weighed for the same span as its first candidate follow, each with its own score.
|
|
107
|
+
* The result lists at most 10 places for a span, so a call reads at most 10 ancestries.
|
|
108
|
+
*
|
|
109
|
+
* @param ancestorsOf The gazetteer's ancestry reader.
|
|
110
|
+
* The label of each place lists the region and county it returns.
|
|
111
|
+
* Absent, a place's label is its name and its country.
|
|
112
|
+
* @returns An empty array when the result has no coordinate.
|
|
113
|
+
*/
|
|
114
|
+
export function geocodeSearchHits(result, ancestorsOf) {
|
|
115
|
+
const hits = [];
|
|
116
|
+
const answering = answeringCandidate(result);
|
|
117
|
+
const collectionID = collectionOfTier(result.resolution_tier);
|
|
118
|
+
if (result.lat != null && result.lon != null && collectionID) {
|
|
119
|
+
const houseGrade = collectionID === OGCCollectionID.Addresses;
|
|
120
|
+
if (houseGrade || collectionID === OGCCollectionID.Streets) {
|
|
121
|
+
hits.push({
|
|
122
|
+
collectionID,
|
|
123
|
+
lon: result.lon,
|
|
124
|
+
lat: result.lat,
|
|
125
|
+
displayName: addressLabel(result, houseGrade),
|
|
126
|
+
...scoreOf(answering),
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
hits.push({
|
|
131
|
+
collectionID,
|
|
132
|
+
lon: result.lon,
|
|
133
|
+
lat: result.lat,
|
|
134
|
+
displayName: answering ? candidateLabel(answering, ancestorsOf) : hierarchyLabel(result) || result.input.trim(),
|
|
135
|
+
...scoreOf(answering),
|
|
136
|
+
...(answering ? placeIdentity(answering) : {}),
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
const [first] = result.candidates;
|
|
141
|
+
if (!first)
|
|
142
|
+
return hits;
|
|
143
|
+
// A place appears once, so the answer's own place and a place listed twice are skipped.
|
|
144
|
+
// Two places at one coordinate stay two matches, because the place ID tells them apart.
|
|
145
|
+
const seen = new Set();
|
|
146
|
+
const placeKey = (candidate) => candidate.placeID ?? `${candidate.lon},${candidate.lat}`;
|
|
147
|
+
if (answering) {
|
|
148
|
+
seen.add(placeKey(answering));
|
|
149
|
+
}
|
|
150
|
+
for (const candidate of result.candidates) {
|
|
151
|
+
if (candidate.tag !== first.tag || candidate.value !== first.value)
|
|
152
|
+
continue;
|
|
153
|
+
const key = placeKey(candidate);
|
|
154
|
+
if (seen.has(key))
|
|
155
|
+
continue;
|
|
156
|
+
seen.add(key);
|
|
157
|
+
hits.push({
|
|
158
|
+
collectionID: collectionOfPlacetype(candidate.placetype),
|
|
159
|
+
lon: candidate.lon,
|
|
160
|
+
lat: candidate.lat,
|
|
161
|
+
displayName: candidateLabel(candidate, ancestorsOf),
|
|
162
|
+
...scoreOf(candidate),
|
|
163
|
+
...placeIdentity(candidate),
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
return hits;
|
|
167
|
+
}
|
|
168
|
+
//# sourceMappingURL=projection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"projection.js","sourceRoot":"","sources":["../lib/projection.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,kEAAkE;AAElE;;;;;;GAMG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAA;AAE/D,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AAEvD,OAAO,EAAiB,qBAAqB,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAA;AAEjG,OAAO,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAGvF,SAAS,aAAa,CAAC,MAAqB,EAAE,GAAW;IACxD,OAAO,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,KAAK,GAAG,CAAC,EAAE,IAAI,IAAI,IAAI,CAAA;AACzE,CAAC;AAED;;;GAGG;AACH,SAAS,cAAc,CAAC,MAAqB;IAC5C,MAAM,KAAK,GAAa,EAAE,CAAA;IAE1B,KAAK,MAAM,EAAE,IAAI,EAAE,IAAI,MAAM,CAAC,SAAS,EAAE,CAAC;QACzC,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;YACnC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QACjB,CAAC;IACF,CAAC;IAED,MAAM,OAAO,GAAG,YAAY,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE,SAAS,CAAA;IAE3D,IAAI,KAAK,CAAC,MAAM,IAAI,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;QACzD,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IACpB,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CA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ED,KAAK,MAAM,SAAS,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC;QAC3C,IAAI,SAAS,CAAC,GAAG,KAAK,KAAK,CAAC,GAAG,IAAI,SAAS,CAAC,KAAK,KAAK,KAAK,CAAC,KAAK;YAAE,SAAQ;QAE5E,MAAM,GAAG,GAAG,QAAQ,CAAC,SAAS,CAAC,CAAA;QAE/B,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;YAAE,SAAQ;QAE3B,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QAEb,IAAI,CAAC,IAAI,CAAC;YACT,YAAY,EAAE,qBAAqB,CAAC,SAAS,CAAC,SAAS,CAAC;YACxD,GAAG,EAAE,SAAS,CAAC,GAAG;YAClB,GAAG,EAAE,SAAS,CAAC,GAAG;YAClB,WAAW,EAAE,cAAc,CAAC,SAAS,EAAE,WAAW,CAAC;YACnD,GAAG,OAAO,CAAC,SAAS,CAAC;YACrB,GAAG,aAAa,CAAC,SAAS,CAAC;SAC3B,CAAC,CAAA;IACH,CAAC;IAED,OAAO,IAAI,CAAA;AACZ,CAAC"}
|
package/out/routes.d.ts
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Route definitions and handlers for the OGC API resources.
|
|
3
|
+
*
|
|
4
|
+
* The API definition is emitted from these definitions, so no handwritten spec exists.
|
|
5
|
+
* Every resource validates its query against a strict schema, and the app's
|
|
6
|
+
* validation hook answers a failure with a 400.
|
|
7
|
+
*/
|
|
8
|
+
import { type OpenAPIHono } from "@hono/zod-openapi";
|
|
9
|
+
import { type OpenAPIDocInfo } from "@mailwoman/api-kit";
|
|
10
|
+
import type { OGCEngine, OGCSearchHit, OGCServedCollection } from "#engine";
|
|
11
|
+
import { type OGCCollection, type OGCCollections, type OGCConformance, OGCFormat, type OGCLandingPage, type OGCSearchFeature } from "#schema";
|
|
12
|
+
/**
|
|
13
|
+
* What the routes need to know about the deployment.
|
|
14
|
+
*/
|
|
15
|
+
export interface OGCRouteOptions {
|
|
16
|
+
/**
|
|
17
|
+
* The service's public base URL, such as `https://example.org/ogc/`.
|
|
18
|
+
*
|
|
19
|
+
* Link hrefs resolve against it.
|
|
20
|
+
* Without it they resolve against the request's own origin.
|
|
21
|
+
*
|
|
22
|
+
* A reverse proxy that rewrites the host or mounts the service under a path needs it set.
|
|
23
|
+
*/
|
|
24
|
+
baseURL?: string;
|
|
25
|
+
/**
|
|
26
|
+
* The landing page's title and description, and the API definition's `info` block.
|
|
27
|
+
*/
|
|
28
|
+
docInfo: OpenAPIDocInfo;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* The conformance classes the routes below implement.
|
|
32
|
+
*/
|
|
33
|
+
export declare const OGC_CONFORMANCE: OGCConformance;
|
|
34
|
+
/**
|
|
35
|
+
* The landing page for a request served in `format`.
|
|
36
|
+
*/
|
|
37
|
+
export declare function buildLandingPage(base: string, docInfo: OpenAPIDocInfo, format: OGCFormat): OGCLandingPage;
|
|
38
|
+
/**
|
|
39
|
+
* The description of one collection the engine serves, in the form `/collections`
|
|
40
|
+
* and `/collections/{collectionId}` both serve, so the two can't disagree.
|
|
41
|
+
*/
|
|
42
|
+
export declare function buildCollection(base: string, served: OGCServedCollection, format: OGCFormat): OGCCollection;
|
|
43
|
+
/**
|
|
44
|
+
* The collections list for a request served in `format`.
|
|
45
|
+
*/
|
|
46
|
+
export declare function buildCollections(base: string, collections: readonly OGCServedCollection[], format: OGCFormat): OGCCollections;
|
|
47
|
+
/**
|
|
48
|
+
* A `[minLon, minLat, maxLon, maxLat]` box in WGS 84 degrees.
|
|
49
|
+
*/
|
|
50
|
+
export type OGCBBox = readonly [number, number, number, number];
|
|
51
|
+
/**
|
|
52
|
+
* Parse a `bbox` value.
|
|
53
|
+
*
|
|
54
|
+
* @returns The box, or a message that states the problem with the value.
|
|
55
|
+
*/
|
|
56
|
+
export declare function parseBBox(raw: string): OGCBBox | string;
|
|
57
|
+
/**
|
|
58
|
+
* Whether a point lies inside the box, edges included.
|
|
59
|
+
*
|
|
60
|
+
* A box whose minimum longitude exceeds its maximum crosses the antimeridian, as OGC API boxes may.
|
|
61
|
+
*/
|
|
62
|
+
export declare function searchBoxContains([minLon, minLat, maxLon, maxLat]: OGCBBox, lon: number, lat: number): boolean;
|
|
63
|
+
/**
|
|
64
|
+
* A validated `/search` request.
|
|
65
|
+
*/
|
|
66
|
+
export interface OGCSearchRequest {
|
|
67
|
+
q: string;
|
|
68
|
+
limit: number;
|
|
69
|
+
bbox: OGCBBox | null;
|
|
70
|
+
/**
|
|
71
|
+
* The collections the request names, or null when it names none and every collection is searched.
|
|
72
|
+
*/
|
|
73
|
+
collections: ReadonlySet<string> | null;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Validate a `/search` query the schema admitted.
|
|
77
|
+
*
|
|
78
|
+
* @returns The request, or a message that identifies the invalid parameter.
|
|
79
|
+
*/
|
|
80
|
+
export declare function parseSearchQuery(query: Readonly<Record<string, string | undefined>>, collections: readonly OGCServedCollection[]): OGCSearchRequest | string;
|
|
81
|
+
/**
|
|
82
|
+
* Keep the hits the request's collections and box admit, up to its limit.
|
|
83
|
+
*/
|
|
84
|
+
export declare function selectHits(hits: readonly OGCSearchHit[], request: OGCSearchRequest): OGCSearchHit[];
|
|
85
|
+
/**
|
|
86
|
+
* One hit as a GeoJSON feature.
|
|
87
|
+
*/
|
|
88
|
+
export declare function searchFeature(hit: OGCSearchHit): OGCSearchFeature;
|
|
89
|
+
/**
|
|
90
|
+
* Register the OGC API routes against an engine.
|
|
91
|
+
*/
|
|
92
|
+
export declare function registerOGCRoutes(app: OpenAPIHono, engine: OGCEngine, { baseURL, docInfo }: OGCRouteOptions): void;
|
|
93
|
+
//# sourceMappingURL=routes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../lib/routes.ts"],"names":[],"mappings":"AAGA;;;;;;GAMG;AAEH,OAAO,E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