@mailwoman/ogc 11.2.0 → 11.3.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 (73) hide show
  1. package/README.md +167 -28
  2. package/cli/geocoder.ts +50 -0
  3. package/cli/main.ts +303 -49
  4. package/lib/app.ts +9 -1
  5. package/lib/bbox.ts +69 -0
  6. package/lib/collections.ts +63 -9
  7. package/lib/engine.ts +72 -0
  8. package/lib/html.ts +64 -2
  9. package/lib/index.ts +4 -0
  10. package/lib/items.ts +169 -0
  11. package/lib/projection.ts +28 -8
  12. package/lib/provenance.ts +86 -0
  13. package/lib/refusal.ts +34 -0
  14. package/lib/routes.ts +326 -61
  15. package/lib/schema.ts +164 -3
  16. package/out/app.d.ts +8 -0
  17. package/out/app.d.ts.map +1 -1
  18. package/out/app.js +1 -1
  19. package/out/app.js.map +1 -1
  20. package/out/bbox.d.ts +23 -0
  21. package/out/bbox.d.ts.map +1 -0
  22. package/out/bbox.js +54 -0
  23. package/out/bbox.js.map +1 -0
  24. package/out/cli/geocoder.d.ts +24 -0
  25. package/out/cli/geocoder.d.ts.map +1 -0
  26. package/out/cli/geocoder.js +28 -0
  27. package/out/cli/geocoder.js.map +1 -0
  28. package/out/cli/main.js +225 -46
  29. package/out/cli/main.js.map +1 -1
  30. package/out/collections.d.ts +31 -4
  31. package/out/collections.d.ts.map +1 -1
  32. package/out/collections.js +32 -3
  33. package/out/collections.js.map +1 -1
  34. package/out/engine.d.ts +68 -0
  35. package/out/engine.d.ts.map +1 -1
  36. package/out/html.d.ts +11 -1
  37. package/out/html.d.ts.map +1 -1
  38. package/out/html.js +49 -2
  39. package/out/html.js.map +1 -1
  40. package/out/index.d.ts +4 -0
  41. package/out/index.d.ts.map +1 -1
  42. package/out/index.js +4 -0
  43. package/out/index.js.map +1 -1
  44. package/out/items.d.ts +38 -0
  45. package/out/items.d.ts.map +1 -0
  46. package/out/items.js +136 -0
  47. package/out/items.js.map +1 -0
  48. package/out/projection.d.ts +15 -1
  49. package/out/projection.d.ts.map +1 -1
  50. package/out/projection.js +21 -8
  51. package/out/projection.js.map +1 -1
  52. package/out/provenance.d.ts +41 -0
  53. package/out/provenance.d.ts.map +1 -0
  54. package/out/provenance.js +60 -0
  55. package/out/provenance.js.map +1 -0
  56. package/out/refusal.d.ts +18 -0
  57. package/out/refusal.d.ts.map +1 -0
  58. package/out/refusal.js +30 -0
  59. package/out/refusal.js.map +1 -0
  60. package/out/routes.d.ts +24 -22
  61. package/out/routes.d.ts.map +1 -1
  62. package/out/routes.js +246 -51
  63. package/out/routes.js.map +1 -1
  64. package/out/schema.d.ts +157 -2
  65. package/out/schema.d.ts.map +1 -1
  66. package/out/schema.js +140 -3
  67. package/out/schema.js.map +1 -1
  68. package/out/tools/ets.run.d.ts +2 -0
  69. package/out/tools/ets.run.d.ts.map +1 -0
  70. package/out/tools/ets.run.js +187 -0
  71. package/out/tools/ets.run.js.map +1 -0
  72. package/package.json +32 -10
  73. package/tools/ets.run.ts +258 -0
package/README.md CHANGED
@@ -4,13 +4,20 @@ An [OGC API](https://ogcapi.ogc.org) adapter for the [Mailwoman](https://mailwom
4
4
  such as QGIS, GDAL/OGR and OWSLib start from a service's landing page and its conformance declaration. This
5
5
  package serves both, the API definition they link to, as described in
6
6
  [OGC API Common Part 1](https://docs.ogc.org/is/19-072/19-072.html), and the collections of
7
- [OGC API Common Part 2](https://www.opengis.net/doc/is/ogcapi-common-2/1.0). Forward geocoding is served at `/search`, in the
8
- form of the [PDOK Location API](https://api.pdok.nl/kadaster/location-api/v1/).
7
+ [OGC API Common Part 2](https://www.opengis.net/doc/is/ogcapi-common-2/1.0). With `--serve-items`, the `places`
8
+ collection serves the gazetteer's places as items, as described in
9
+ [OGC API Features Part 1](https://docs.ogc.org/is/17-069r4/17-069r4.html), so QGIS, GDAL/OGR and other Features
10
+ clients can browse them. Forward geocoding is served at `/search`, in the form of the
11
+ [PDOK Location API](https://api.pdok.nl/kadaster/location-api/v1/).
9
12
 
10
13
  ```sh
11
14
  npx @mailwoman/ogc serve --port 8090
12
15
  curl "http://localhost:8090/collections"
13
16
  curl "http://localhost:8090/search?q=Dam%201%2C%201012JS%20Amsterdam&limit=2"
17
+
18
+ # Bulk browsing is opt-in.
19
+ npx @mailwoman/ogc serve --port 8090 --serve-items
20
+ curl "http://localhost:8090/collections/places/items?bbox=4.7,52.2,5.1,52.5&limit=5"
14
21
  ```
15
22
 
16
23
  `serve` loads the same engine as `@mailwoman/photon` and `@mailwoman/nominatim`: the en-US classifier, the
@@ -20,15 +27,17 @@ a candidate gazetteer.
20
27
 
21
28
  ## Endpoints
22
29
 
23
- | Endpoint | What it returns |
24
- | ----------------------------- | ---------------------------------------------------------------------------------- |
25
- | `/` | The landing page: a title, a description and links to every resource below |
26
- | `/conformance` | `{ "conformsTo": [...] }`, the conformance classes the routes implement |
27
- | `/api` | The API definition as OpenAPI 3.0 (`application/vnd.oai.openapi+json;version=3.0`) |
28
- | `/collections` | `{ "links": [...], "collections": [...] }`, the collections the engine serves |
29
- | `/collections/{collectionId}` | One collection, as `/collections` lists it, or a 404 for an unknown id |
30
- | `/search` | Forward geocoding, as a GeoJSON FeatureCollection (`application/geo+json`) |
31
- | `/openapi.json` | The same routes as OpenAPI 3.1, the document every Mailwoman HTTP surface serves |
30
+ | Endpoint | What it returns |
31
+ | ----------------------------------------------- | ---------------------------------------------------------------------------------- |
32
+ | `/` | The landing page: a title, a description and links to every resource below |
33
+ | `/conformance` | `{ "conformsTo": [...] }`, the conformance classes the routes implement |
34
+ | `/api` | The API definition as OpenAPI 3.0 (`application/vnd.oai.openapi+json;version=3.0`) |
35
+ | `/collections` | `{ "links": [...], "collections": [...] }`, the collections the engine serves |
36
+ | `/collections/{collectionId}` | One collection, as `/collections` lists it, or a 404 for an unknown id |
37
+ | `/collections/{collectionId}/items` | One page of a collection's places, as a GeoJSON FeatureCollection |
38
+ | `/collections/{collectionId}/items/{featureId}` | One place, as a GeoJSON Feature |
39
+ | `/search` | Forward geocoding, as a GeoJSON FeatureCollection (`application/geo+json`) |
40
+ | `/openapi.json` | The same routes as OpenAPI 3.1, the document every Mailwoman HTTP surface serves |
32
41
 
33
42
  Every resource accepts `f=json` or `f=html`. Without `f`, the `Accept` header decides, and JSON answers a
34
43
  request that names neither. Any other `f` value, a query parameter the API definition doesn't name, or an
@@ -43,7 +52,7 @@ coordinate, and the tier decides the collection:
43
52
  | ------------ | ------------------------------------------------------------ | ------------------------------------------------------------- |
44
53
  | `addresses` | `address_point`, `interpolated` | a region has an address-point or interpolation layer |
45
54
  | `streets` | `street` | a region has a street-centroid layer |
46
- | `postcodes` | `postcode`, and postcode places | always, because postcode places come from the gazetteer |
55
+ | `postcodes` | `postcode`, and postcode places | the gazetteer holds postcode places |
47
56
  | `places` | `admin`, and the other gazetteer places the resolver weighed | always |
48
57
  | `plus-codes` | `plus_code` | always, because the engine decodes plus codes without a layer |
49
58
 
@@ -52,21 +61,121 @@ only when some region has a layer. Their descriptions name those regions, such a
52
61
  startup banner prints them. A region absent from the list has no layer the engine opened. Its addresses may
53
62
  still exist, and the list makes no claim about them.
54
63
 
55
- Each collection reports `version: 1` and `geometryDimension: 0`, since every feature is a point. `itemType`
56
- and the `items` link are absent because the server doesn't serve `/collections/{collectionId}/items`.
64
+ Each collection reports `version: 1` and `geometryDimension: 0`, since every feature is a point. A collection
65
+ that serves items adds `itemType: "feature"`, an `items` link for GeoJSON, an `items` link for HTML and an `extent`.
66
+ The other collections omit all three item fields, and their items routes answer 404.
67
+
68
+ Every collection also links where its data comes from, read from the `layer_manifest` of each database behind it:
69
+
70
+ - A `license` link ([RFC 4946](https://www.rfc-editor.org/rfc/rfc4946)) for each identifier in the recorded
71
+ license expression whose text has a known URL: SPDX's page for an SPDX identifier, and Who's On First's own
72
+ license text for `LicenseRef-WhosOnFirst-Mixed`, because that text requires the link back.
73
+ - A `via` link ([RFC 4287](https://www.rfc-editor.org/rfc/rfc4287), "the source of the information") identifies each
74
+ source the manifest records, to the page where a user obtains it. Each source's location belongs to the package
75
+ that builds its layers: `GAZETTEER_SOURCE_LOCATIONS` in `@mailwoman/resolver-wof-sqlite/build/sources` for the
76
+ gazetteer, `BAN_SOURCE_LOCATIONS` in `@mailwoman/ban/source`, and `OSM_SOURCE_LOCATIONS` in
77
+ `@mailwoman/osm/source`. Each build writes its source names from the same table. The Who's On First entry points to
78
+ the [`mailwoman` organization](https://github.com/mailwoman). Its `whosonfirst-data-admin-<cc>` repositories are
79
+ the forks the build clones from `whosonfirst-data`. The OpenStreetMap entry points to the `@mailwoman/osm` build
80
+ documentation, because the project publishes the builder and a user builds the database.
81
+ - When a recorded license requires credit, the collection includes the `attribution` link that OGC API Common Part 2 defines.
82
+
83
+ A source that matches another opened layer, as the candidate gazetteer's manifest records the admin gazetteer,
84
+ uses that layer's license links, sources and credit. The address and street collections read the manifest
85
+ of every region file their providers report, and list each license and source once. If a manifest records no
86
+ license or source, a source has no known location, or a license identifier has no published text, the description
87
+ states that condition instead of linking to it. A region file without a readable `layer_manifest` adds no link,
88
+ and the description counts those regions. `plus-codes` has no layer.
89
+
90
+ ## Where the data comes from
91
+
92
+ The adapter serves only the operator's own data root, `$MAILWOMAN_DATA_ROOT`. `/search` answers one
93
+ query at a time. Bulk browsing through `items` is opt-in: `serve` serves no items unless it's started with
94
+ `--serve-items`.
95
+
96
+ A user who wants the data obtains it from its sources:
97
+
98
+ - The gazetteer: `mailwoman data pull candidate` installs the candidate gazetteer, as the
99
+ [data and locales reference](https://mailwoman.post/docs/reference/data-and-locales) describes. To build the admin
100
+ gazetteer from Who's On First yourself, clone the `whosonfirst-data-admin-<cc>` repositories from the
101
+ [`mailwoman` organization](https://github.com/mailwoman) or from `whosonfirst-data`, then run
102
+ `mailwoman gazetteer build admin`, as the
103
+ [reverse geocoding guide](https://mailwoman.post/docs/guides/reverse-geocode) shows.
104
+ - Address points, interpolation and street layers: `mailwoman data pull` installs the published bundles. The
105
+ data and locales reference lists them.
106
+ - Each source's own terms: the [data and licensing page](https://mailwoman.post/product/data-and-licensing) links
107
+ the publishers' pages. Each collection's `license` and `via` links identify what the opened databases record.
108
+ - Your own data root: `mailwoman data inventory` lists every database under it with its license, the
109
+ obligations imposed by that license, its sources and where to obtain each one, and the databases whose
110
+ `layer_manifest` it couldn't read. The collections' links come from the same function, `resolveLayerTerms` in
111
+ `@mailwoman/core/layers/provenance`, so the two agree.
112
+
113
+ ## Items
114
+
115
+ Items are served only when `serve` is started with `--serve-items`, or `createOGCApp` is built with
116
+ `serveItems: true`. While items are off, the collection descriptions link none, both items routes answer 404
117
+ with `{ "error": "collection serves no items" }`, `/search` features omit `href`, and `/conformance` lists
118
+ only the OGC API Common classes. The startup banner states whether items are served and gives the reason when they're not.
119
+
120
+ Two collections serve items:
121
+
122
+ - `places` reads the admin gazetteer's current places, the `admin-global-priority.db` the server resolves under
123
+ `$MAILWOMAN_DATA_ROOT/db/wof`, through its primary key and its `place_bbox` R*Tree.
124
+ - `postcodes` reads the candidate gazetteer's postcode places through its `candidate_postcode_place` index. The index
125
+ holds each postcode's id, point and name in id order. A candidate gazetteer built without that index serves no
126
+ postcode items, and the banner reports that absence. A server that resolves against WOF databases rather than a candidate
127
+ gazetteer serves no postcode items either. The candidate gazetteer's recorded license decides an obligation
128
+ refusal, as the admin gazetteer's does for `places`.
129
+
130
+ The other collections serve no items:
131
+
132
+ - `plus-codes`: the engine decodes plus codes and stores none.
133
+ - `addresses` and `streets`: out of scope for now.
134
+
135
+ | Parameter | Meaning |
136
+ | ---------- | ----------------------------------------------------------------------------------------------------------- |
137
+ | `limit` | The most features to return. The default is 10. A value above 1000 returns 1000 rather than an error. |
138
+ | `bbox` | `minLon,minLat,maxLon,maxLat`, or six numbers with a minimum and maximum height after each latitude. |
139
+ | `datetime` | An RFC 3339 date-time, or an interval of two separated by `/` with `..` or an empty string for an open end. |
140
+ | `after` | The cursor encoded by a `next` link. A client follows the link rather than building it. |
141
+ | `f` | `json` (GeoJSON) or `html`. |
142
+
143
+ A page lists places in ascending WOF id order. Its `next` link continues after the page's last id, so a deep page
144
+ costs what the first page costs, and following the links visits every place in the box once. A `postcodes` box
145
+ page walks the index in id order and keeps the postcodes whose point lies inside the box. A box with few postcodes
146
+ therefore reads more of the index before its page fills. On the 2026-11-21 candidate gazetteer, a box with no
147
+ postcodes read the whole index of 4,098,848 rows in 246 ms. The last page has no
148
+ `next` link. A response includes `timeStamp`, `numberReturned`, `self`, `alternate` and `collection` links, and
149
+ omits the optional `numberMatched`, because counting a large box's places costs a scan.
150
+
151
+ `bbox` keeps the places whose point lies inside the box, and a box whose minimum longitude exceeds its maximum
152
+ crosses the antimeridian. The places have no height, so a six-number box selects by its longitudes and latitudes.
153
+ The places have no temporal geometry, so every valid `datetime` selects every place, as Requirement 26 C of the
154
+ standard requires for features without a temporal geometry. A malformed value of either returns 400.
155
+
156
+ A feature's `id` is the gazetteer place ID `/search` reports as `place_id`, such as `wof:101751893`, and
157
+ `/collections/places/items/wof:101751893` returns that place. Its properties are `name`, `placetype`,
158
+ `country_code` and `display_name`, the label `/search` gives the same place. An id the collection doesn't hold
159
+ returns 404.
160
+
161
+ The items routes serve the gazetteer in bulk, so with `--serve-items` the server reads the database's recorded
162
+ license at startup and prints it. When `MAILWOMAN_REFUSE_OBLIGATIONS` refuses a class listed by that license, `places`
163
+ serves no items and the banner states the refusal. The database records `LicenseRef-WhosOnFirst-Mixed`
164
+ (attribution) beside `ODbL-1.0` (attribution and share-alike) and `CC-BY-4.0`. An operator who sets
165
+ `MAILWOMAN_REFUSE_OBLIGATIONS=share-alike` therefore serves no items, and one who sets `unresolved` serves them.
57
166
 
58
167
  ## Search
59
168
 
60
- | Parameter | Meaning |
61
- | --------------------------- | -------------------------------------------------------------------------------------- |
62
- | `q` | The address or place to search for. Required. |
63
- | `<collectionId>[version]=1` | Restrict the search to the named collections. Repeat it for each collection. |
64
- | `<collectionId>[relevance]` | A number from 0 to 1. It also selects the collection, and doesn't change the ranking. |
65
- | `limit` | The most features to return, from 1 to 50. The default is 10. |
66
- | `bbox` | `minLon,minLat,maxLon,maxLat`. Only features whose point lies inside the box are kept. |
67
- | `f` | `json` (GeoJSON) or `html`. |
169
+ | Parameter | Meaning |
170
+ | --------------------------- | -------------------------------------------------------------------------------------------------- |
171
+ | `q` | The address or place to search for. Required. |
172
+ | `<collectionId>[version]=1` | Restrict the search to the collections identified by the parameter. Repeat it for each collection. |
173
+ | `<collectionId>[relevance]` | A number from 0 to 1. It also selects the collection, and doesn't change the ranking. |
174
+ | `limit` | The most features to return, from 1 to 50. The default is 10. |
175
+ | `bbox` | `minLon,minLat,maxLon,maxLat`. Only features whose point lies inside the box are kept. |
176
+ | `f` | `json` (GeoJSON) or `html`. |
68
177
 
69
- The response carries `timeStamp`, `links` (`self` and `alternate`) and `numberReturned` beside `features`.
178
+ The response includes `timeStamp`, `links` (`self` and `alternate`) and `numberReturned` beside `features`.
70
179
  Each feature's properties are:
71
180
 
72
181
  - `display_name`: a one-line label, in the country's address order for an address or a street.
@@ -79,6 +188,8 @@ Each feature's properties are:
79
188
  or `localadmin`, of a place or postcode. Two places that share a label, such as a locality and the
80
189
  local-government area of the same name, differ here. Both are absent for an address, a street and a plus code,
81
190
  and `place_id` is absent for a place the gazetteer gave no ID.
191
+ - `href`: the place's URL under `/collections/places/items`, as on PDOK. It's present only when the collection
192
+ serves items and holds the place, so the link never answers 404.
82
193
 
83
194
  A place's `display_name` is its name, then the ancestors the gazetteer records between it and its country, most
84
195
  specific first, then the country, such as `Camden, Ouachita, Arkansas, United States`. An ancestor that repeats
@@ -87,7 +198,7 @@ country.
87
198
 
88
199
  The first feature is the engine's answer. The places the resolver weighed for the same part of the input
89
200
  follow. A box whose minimum longitude exceeds its maximum crosses the antimeridian. `f=html` without `q`
90
- serves a search form, which the landing page links as `search`.
201
+ serves a search form. The landing page links that form as `search`.
91
202
 
92
203
  ### Differences from PDOK
93
204
 
@@ -95,7 +206,6 @@ serves a search form, which the landing page links as `search`.
95
206
  its index needs the collection. The engine has no such need.
96
207
  - `<collectionId>[relevance]` is accepted so a PDOK client works unchanged, but it doesn't reweight the
97
208
  ranking, because the engine's scores don't compare across collections.
98
- - Features carry no `href` to an item yet. The link arrives with `/collections/{collectionId}/items` in #3142.
99
209
  - PDOK defines no reverse operation, so reverse geocoding stays on `@mailwoman/photon` and `@mailwoman/nominatim`.
100
210
 
101
211
  ## Conformance
@@ -110,10 +220,36 @@ The declaration lists five OGC API Common Part 1 classes, each under
110
220
  - `html`: the same resources as HTML5, each link an `<a>` element.
111
221
  - `oas30`: an OpenAPI 3.0 definition as `service-desc` and its HTML form as `service-doc`.
112
222
  - `http://www.opengis.net/spec/ogcapi-common-2/1.0/conf/collections`: the landing page links `/collections`
113
- as `data`, and `/collections` and each `/collections/{collectionId}` carry `self` and `alternate` links with
223
+ as `data`, and `/collections` and each `/collections/{collectionId}` include `self` and `alternate` links with
114
224
  a `type`.
115
225
 
116
- `/search` is PDOK's convention. OGC publishes no conformance class for it, so the declaration names none.
226
+ When a collection serves items, it adds four OGC API Features Part 1 classes, each under
227
+ `http://www.opengis.net/spec/ogcapi-features-1/1.0/conf/`:
228
+
229
+ - `core`: the two items routes with `limit`, `bbox` and `datetime`, `next` links, and the error codes above.
230
+ - `geojson`: both items routes as `application/geo+json`.
231
+ - `html`: both items routes as HTML5, each link an `<a>` element.
232
+ - `oas30`: the OpenAPI 3.0 definition declares both items routes and their parameters in the form the standard gives.
233
+
234
+ A server whose collections serve no items declares none of the four and registers no items routes.
235
+ `/search` is PDOK's convention. OGC publishes no conformance class for it, so the declaration lists none.
236
+
237
+ ## The OGC test suite
238
+
239
+ `packages/ogc/tools/ets.run.ts` runs OGC's executable test suite for Features Part 1,
240
+ [`ets-ogcapi-features10`](https://github.com/opengeospatial/ets-ogcapi-features10) revision 1.9, against a server on
241
+ this machine. It needs Podman and the data root's gazetteer. From the repository root:
242
+
243
+ ```sh
244
+ node packages/ogc/tools/ets.run.ts --out "$MAILWOMAN_DATA_ROOT/audits/ogc-ets/latest"
245
+ ```
246
+
247
+ The tool starts `mailwoman-ogc serve --serve-items` on 127.0.0.1 (port 8195 unless `--port` specifies another port),
248
+ because the suite needs a feature collection to test. It runs the suite
249
+ from OGC's published image `docker.io/ogccite/ets-ogcapi-features10:1.9-teamengine-6.0.0-RC2` with the host's
250
+ network, and stops the server it started. The container opens no port. The TestNG and EARL reports land under
251
+ `--out`, `summary.json` beside them lists every failed and skipped test, and the tool exits 1 when a test failed.
252
+ `--iut <url>` tests a running server instead, and the tool starts no server of its own.
117
253
 
118
254
  ## Link hrefs behind a proxy
119
255
 
@@ -127,7 +263,10 @@ npx @mailwoman/ogc serve --base-url https://example.org/ogc/
127
263
  ## Library use
128
264
 
129
265
  `createOGCApp` takes an `OGCEngine`: the collections it serves and a `search(q)` that returns its matches.
130
- `geocodeSearchHits` projects a `geocodeAddress` result to those matches.
266
+ `geocodeSearchHits` projects a `geocodeAddress` result to those matches. A collection serves items when it defines
267
+ an `items` source, such as `placeItemSource(new WOFPlaceBrowser({ databasePath }), ancestorsOf)`, with
268
+ `WOFPlaceBrowser` from `@mailwoman/resolver-wof-sqlite/lookup/browse`, and the app is built with `serveItems: true`.
269
+ A collection's `layers` lists the manifest terms its license and `via` links come from.
131
270
 
132
271
  ```ts
133
272
  import { serveNode } from "@mailwoman/api-kit"
@@ -0,0 +1,50 @@
1
+ // SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
2
+ // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
3
+
4
+ /**
5
+ * The forward geocoder behind `mailwoman-ogc serve`: the data layers the server composes,
6
+ * and the geocode of one query through its session.
7
+ *
8
+ * The module is separate from `main.ts` because that file runs the command line when it loads.
9
+ */
10
+
11
+ import type { GeocodeResult } from "@mailwoman/core/geocode"
12
+ import { type DropInGeocoder, openDropInGeocoder } from "mailwoman/cli/kit/dropin"
13
+ import type { LayerContribution } from "mailwoman/geocode/layers/contributions"
14
+ import { banLayer, forkEntityProbe, observationRoutes, osmLayer, regionDatabases } from "mailwoman/services/entry/node"
15
+
16
+ /**
17
+ * The data layers the OGC server composes.
18
+ *
19
+ * The server consults the national open register (BAN) and then the OpenStreetMap tier,
20
+ * as the Photon and Nominatim servers do.
21
+ * It leaves national Overture out, so `/search` reads every collection it lists.
22
+ */
23
+ const OGC_LAYERS: readonly LayerContribution[] = [
24
+ banLayer,
25
+ osmLayer,
26
+ regionDatabases,
27
+ forkEntityProbe,
28
+ observationRoutes,
29
+ ]
30
+
31
+ /**
32
+ * What `mailwoman-ogc serve` opens to answer `/search` and to list its collections.
33
+ */
34
+ export interface OGCGeocoder extends DropInGeocoder {
35
+ /**
36
+ * Geocodes one query.
37
+ */
38
+ geocode(query: string): Promise<GeocodeResult>
39
+ }
40
+
41
+ /**
42
+ * Opens the gazetteer and the server's session, and ends the process when either is unavailable.
43
+ *
44
+ * @param candidateDBFlag The `--candidate-db` value, or `null` to read the conventional path.
45
+ */
46
+ export async function openOGCGeocoder(candidateDBFlag: string | null): Promise<OGCGeocoder> {
47
+ const opened = await openDropInGeocoder(candidateDBFlag, OGC_LAYERS)
48
+
49
+ return { ...opened, geocode: async (query) => (await opened.session.geocode(query)).result }
50
+ }