@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
package/lib/schema.ts
ADDED
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Zod schemas, media types and conformance class URIs for the OGC API surface.
|
|
6
|
+
*
|
|
7
|
+
* The shapes follow the `landingPage`, `confClasses` and `link` schemas of OGC
|
|
8
|
+
* API Common Part 1 (OGC 19-072), and the `collections` and `collectionDesc`
|
|
9
|
+
* schemas of OGC API Common Part 2 (OGC 20-024).
|
|
10
|
+
* The `/search` response follows PDOK's Location API, for which OGC publishes no schema.
|
|
11
|
+
*
|
|
12
|
+
* Each schema is registered as a component, so the API definition references it by name.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { z } from "@hono/zod-openapi"
|
|
16
|
+
import { featureCollectionSchema, featureSchema } from "@mailwoman/api-kit"
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The media types this surface serves, keyed by their role.
|
|
20
|
+
*/
|
|
21
|
+
export const OGCMediaType = {
|
|
22
|
+
JSON: "application/json",
|
|
23
|
+
GeoJSON: "application/geo+json",
|
|
24
|
+
HTML: "text/html",
|
|
25
|
+
OpenAPI30: "application/vnd.oai.openapi+json;version=3.0",
|
|
26
|
+
} as const
|
|
27
|
+
|
|
28
|
+
export type OGCMediaType = (typeof OGCMediaType)[keyof typeof OGCMediaType]
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The values the `f` query parameter accepts on every resource.
|
|
32
|
+
*/
|
|
33
|
+
export const OGCFormat = {
|
|
34
|
+
JSON: "json",
|
|
35
|
+
HTML: "html",
|
|
36
|
+
} as const
|
|
37
|
+
|
|
38
|
+
export type OGCFormat = (typeof OGCFormat)[keyof typeof OGCFormat]
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The link relations the landing page emits.
|
|
42
|
+
*
|
|
43
|
+
* OGC API Common identifies the conformance relation by URI.
|
|
44
|
+
* PDOK's Location API emits both the URI and the short name, and the landing page does the same.
|
|
45
|
+
*/
|
|
46
|
+
export const OGCLinkRelation = {
|
|
47
|
+
Self: "self",
|
|
48
|
+
Alternate: "alternate",
|
|
49
|
+
ServiceDesc: "service-desc",
|
|
50
|
+
ServiceDoc: "service-doc",
|
|
51
|
+
Conformance: "conformance",
|
|
52
|
+
OGCConformance: "http://www.opengis.net/def/rel/ogc/1.0/conformance",
|
|
53
|
+
Data: "data",
|
|
54
|
+
OGCData: "http://www.opengis.net/def/rel/ogc/1.0/data",
|
|
55
|
+
Search: "search",
|
|
56
|
+
} as const
|
|
57
|
+
|
|
58
|
+
export type OGCLinkRelation = (typeof OGCLinkRelation)[keyof typeof OGCLinkRelation]
|
|
59
|
+
|
|
60
|
+
const COMMON_PART_1 = "http://www.opengis.net/spec/ogcapi-common-1/1.0/conf"
|
|
61
|
+
|
|
62
|
+
const COMMON_PART_2 = "http://www.opengis.net/spec/ogcapi-common-2/1.0/conf"
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* The OGC API conformance classes this surface implements.
|
|
66
|
+
*
|
|
67
|
+
* Each one is declared only because a route serves what its requirements ask for:
|
|
68
|
+
*
|
|
69
|
+
* - `core`: HTTP 1.1, and a 400 for an unknown query parameter or an invalid `f` value.
|
|
70
|
+
* - `landing-page`: `GET /` with API definition and conformance links, `GET /conformance`, `GET /api`.
|
|
71
|
+
* - `json`: the landing page, conformance declaration and collections as `application/json`.
|
|
72
|
+
* - `html`: the same resources as HTML5 carrying every link as an `<a>`.
|
|
73
|
+
* - `oas30`: an OpenAPI 3.0 document as `service-desc` and its HTML form as `service-doc`.
|
|
74
|
+
* - `collections` (Common Part 2): `GET /collections` linked from the landing page as `data`,
|
|
75
|
+
* `GET /collections/{collectionId}` for every listed id, each with `self` and `alternate` links.
|
|
76
|
+
*/
|
|
77
|
+
export const OGCConformanceClass = {
|
|
78
|
+
Core: `${COMMON_PART_1}/core`,
|
|
79
|
+
LandingPage: `${COMMON_PART_1}/landing-page`,
|
|
80
|
+
JSON: `${COMMON_PART_1}/json`,
|
|
81
|
+
HTML: `${COMMON_PART_1}/html`,
|
|
82
|
+
OAS30: `${COMMON_PART_1}/oas30`,
|
|
83
|
+
Collections: `${COMMON_PART_2}/collections`,
|
|
84
|
+
} as const
|
|
85
|
+
|
|
86
|
+
export type OGCConformanceClass = (typeof OGCConformanceClass)[keyof typeof OGCConformanceClass]
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* A link object from OGC API Common's `link.yaml`.
|
|
90
|
+
*/
|
|
91
|
+
export const OGCLinkSchema = z
|
|
92
|
+
.object({
|
|
93
|
+
href: z.string(),
|
|
94
|
+
rel: z.string(),
|
|
95
|
+
type: z.string().optional(),
|
|
96
|
+
title: z.string().optional(),
|
|
97
|
+
})
|
|
98
|
+
.openapi("OGCLink")
|
|
99
|
+
|
|
100
|
+
export type OGCLink = z.infer<typeof OGCLinkSchema>
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* The landing page from OGC API Common's `landingPage.yaml`.
|
|
104
|
+
*/
|
|
105
|
+
export const OGCLandingPageSchema = z
|
|
106
|
+
.object({
|
|
107
|
+
title: z.string(),
|
|
108
|
+
description: z.string(),
|
|
109
|
+
links: z.array(OGCLinkSchema),
|
|
110
|
+
})
|
|
111
|
+
.openapi("OGCLandingPage")
|
|
112
|
+
|
|
113
|
+
export type OGCLandingPage = z.infer<typeof OGCLandingPageSchema>
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* The conformance declaration from OGC API Common's `confClasses.yaml`.
|
|
117
|
+
*/
|
|
118
|
+
export const OGCConformanceSchema = z
|
|
119
|
+
.object({
|
|
120
|
+
conformsTo: z.array(z.string()),
|
|
121
|
+
links: z.array(OGCLinkSchema).optional(),
|
|
122
|
+
})
|
|
123
|
+
.openapi("OGCConformance")
|
|
124
|
+
|
|
125
|
+
export type OGCConformance = z.infer<typeof OGCConformanceSchema>
|
|
126
|
+
|
|
127
|
+
const formatParameter = z.enum([OGCFormat.JSON, OGCFormat.HTML]).optional().openapi({
|
|
128
|
+
description: "The response encoding. Without it the `Accept` header decides, and JSON is the default.",
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* The query every resource accepts.
|
|
133
|
+
*
|
|
134
|
+
* The object is strict because OGC API Common's core class answers 400 to a query
|
|
135
|
+
* parameter the API definition doesn't name.
|
|
136
|
+
*/
|
|
137
|
+
export const OGCFormatQuerySchema = z.object({ f: formatParameter }).strict()
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* One collection description, from OGC API Common Part 2's `collectionDesc.yaml`.
|
|
141
|
+
*
|
|
142
|
+
* `id` and `links` are the two members the schema requires.
|
|
143
|
+
* `itemType` is left out because it describes a `/collections/{collectionId}/items`
|
|
144
|
+
* route this surface doesn't serve.
|
|
145
|
+
*/
|
|
146
|
+
export const OGCCollectionSchema = z
|
|
147
|
+
.object({
|
|
148
|
+
id: z.string(),
|
|
149
|
+
title: z.string(),
|
|
150
|
+
description: z.string(),
|
|
151
|
+
links: z.array(OGCLinkSchema),
|
|
152
|
+
geometryDimension: z.literal(0).openapi({ description: "Every feature in the collection is a point." }),
|
|
153
|
+
version: z.number().int().openapi({
|
|
154
|
+
description: "The collection version, the value `/search` takes in `<collectionId>[version]`, as on PDOK.",
|
|
155
|
+
}),
|
|
156
|
+
})
|
|
157
|
+
.openapi("OGCCollection")
|
|
158
|
+
|
|
159
|
+
export type OGCCollection = z.infer<typeof OGCCollectionSchema>
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* The collections list, from OGC API Common Part 2's `collections.yaml`.
|
|
163
|
+
*/
|
|
164
|
+
export const OGCCollectionsSchema = z
|
|
165
|
+
.object({
|
|
166
|
+
links: z.array(OGCLinkSchema),
|
|
167
|
+
collections: z.array(OGCCollectionSchema),
|
|
168
|
+
})
|
|
169
|
+
.openapi("OGCCollections")
|
|
170
|
+
|
|
171
|
+
export type OGCCollections = z.infer<typeof OGCCollectionsSchema>
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* The path parameter of `/collections/{collectionId}`.
|
|
175
|
+
*/
|
|
176
|
+
export const OGCCollectionPathSchema = z.object({
|
|
177
|
+
collectionId: z.string().openapi({ param: { name: "collectionId", in: "path" }, example: "addresses" }),
|
|
178
|
+
})
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* The properties of one `/search` feature.
|
|
182
|
+
*/
|
|
183
|
+
export const OGCSearchPropertiesSchema = z
|
|
184
|
+
.object({
|
|
185
|
+
display_name: z.string().openapi({ description: "A one-line label for the matched place or address." }),
|
|
186
|
+
score: z.number().nullable().openapi({
|
|
187
|
+
description:
|
|
188
|
+
"The engine's ranking score for the match, larger ranking higher. Scores compare candidates for one part of the input and have no unit across collections. Null when the engine measured none.",
|
|
189
|
+
}),
|
|
190
|
+
score_unmeasured: z.string().optional().openapi({
|
|
191
|
+
description: "Why `score` is null. Absent when `score` holds a value.",
|
|
192
|
+
}),
|
|
193
|
+
collection_id: z.string().openapi({ description: "The collection the feature belongs to." }),
|
|
194
|
+
place_id: z.string().optional().openapi({
|
|
195
|
+
description:
|
|
196
|
+
"The gazetteer place ID of a place or postcode, such as `wof:85975673`. Absent for an address, a street, a plus code, or a place the gazetteer gave no ID.",
|
|
197
|
+
}),
|
|
198
|
+
placetype: z.string().optional().openapi({
|
|
199
|
+
description:
|
|
200
|
+
"The gazetteer placetype of a place or postcode, such as `locality`, `localadmin` or `postalcode`. Absent for an address, a street or a plus code.",
|
|
201
|
+
}),
|
|
202
|
+
})
|
|
203
|
+
.openapi("OGCSearchProperties")
|
|
204
|
+
|
|
205
|
+
export type OGCSearchProperties = z.infer<typeof OGCSearchPropertiesSchema>
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* One `/search` feature, a GeoJSON point.
|
|
209
|
+
*/
|
|
210
|
+
export const OGCSearchFeatureSchema = featureSchema(OGCSearchPropertiesSchema).openapi("OGCSearchFeature")
|
|
211
|
+
|
|
212
|
+
export type OGCSearchFeature = z.infer<typeof OGCSearchFeatureSchema>
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* The `/search` response: a GeoJSON FeatureCollection with the members PDOK's Location API adds.
|
|
216
|
+
*/
|
|
217
|
+
export const OGCSearchResponseSchema = featureCollectionSchema(OGCSearchFeatureSchema)
|
|
218
|
+
.extend({
|
|
219
|
+
timeStamp: z.string().openapi({ description: "When the response was generated, as an RFC 3339 UTC timestamp." }),
|
|
220
|
+
links: z.array(OGCLinkSchema),
|
|
221
|
+
numberReturned: z.number().int(),
|
|
222
|
+
})
|
|
223
|
+
.openapi("OGCSearchResponse")
|
|
224
|
+
|
|
225
|
+
export type OGCSearchResponse = z.infer<typeof OGCSearchResponseSchema>
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* The query name that selects a collection for `/search`, in PDOK's form, such as `addresses[version]`.
|
|
229
|
+
*/
|
|
230
|
+
export function collectionVersionParameter(collectionID: string): string {
|
|
231
|
+
return `${collectionID}[version]`
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* The query name that weights a collection for `/search`, in PDOK's form, such as `addresses[relevance]`.
|
|
236
|
+
*/
|
|
237
|
+
export function collectionRelevanceParameter(collectionID: string): string {
|
|
238
|
+
return `${collectionID}[relevance]`
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* The number of `/search` features returned when the request omits `limit`.
|
|
243
|
+
*/
|
|
244
|
+
export const OGC_SEARCH_DEFAULT_LIMIT = 10
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* The largest `limit` `/search` accepts.
|
|
248
|
+
*/
|
|
249
|
+
export const OGC_SEARCH_MAX_LIMIT = 50
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* The version every collection reports, and the only value `<collectionId>[version]` accepts.
|
|
253
|
+
*/
|
|
254
|
+
export const OGC_COLLECTION_VERSION = 1
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* The `/search` query for a service whose collections are `collectionIDs`.
|
|
258
|
+
*
|
|
259
|
+
* The object is strict, as on every resource, and declares each collection's two parameters.
|
|
260
|
+
* A parameter for a collection the service doesn't hold is therefore unknown and answers 400.
|
|
261
|
+
*/
|
|
262
|
+
export function searchQuerySchema(collectionIDs: readonly string[]) {
|
|
263
|
+
const perCollection: Record<string, z.ZodOptional<z.ZodString>> = {}
|
|
264
|
+
|
|
265
|
+
for (const id of collectionIDs) {
|
|
266
|
+
perCollection[collectionVersionParameter(id)] = z
|
|
267
|
+
.string()
|
|
268
|
+
.optional()
|
|
269
|
+
.openapi({
|
|
270
|
+
description: `Restrict the search to the \`${id}\` collection, with any other collection named the same way. The value is the collection version, \`${OGC_COLLECTION_VERSION}\`.`,
|
|
271
|
+
})
|
|
272
|
+
|
|
273
|
+
perCollection[collectionRelevanceParameter(id)] = z.string().optional().openapi({
|
|
274
|
+
description: `A number from 0 to 1, accepted for PDOK clients. It doesn't change the ranking, because the engine's scores don't compare across collections.`,
|
|
275
|
+
})
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
return z
|
|
279
|
+
.object({
|
|
280
|
+
q: z.string().optional().openapi({ description: "The address or place to search for. Required." }),
|
|
281
|
+
limit: z
|
|
282
|
+
.string()
|
|
283
|
+
.optional()
|
|
284
|
+
.openapi({
|
|
285
|
+
type: "integer",
|
|
286
|
+
description: `The most features to return, from 1 to ${OGC_SEARCH_MAX_LIMIT}. The default is ${OGC_SEARCH_DEFAULT_LIMIT}.`,
|
|
287
|
+
}),
|
|
288
|
+
bbox: z.string().optional().openapi({
|
|
289
|
+
description:
|
|
290
|
+
"Keep only features inside the box `minLon,minLat,maxLon,maxLat`, in WGS 84 longitude and latitude.",
|
|
291
|
+
}),
|
|
292
|
+
f: formatParameter,
|
|
293
|
+
...perCollection,
|
|
294
|
+
})
|
|
295
|
+
.strict()
|
|
296
|
+
}
|
package/out/app.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { OpenAPIHono } from "@hono/zod-openapi";
|
|
2
|
+
import { type CompatibilityAppOptions, type OpenAPIDocInfo } from "@mailwoman/api-kit";
|
|
3
|
+
import type { OGCEngine } from "#engine";
|
|
4
|
+
/**
|
|
5
|
+
* The port `mailwoman-ogc serve` listens on unless told otherwise.
|
|
6
|
+
*/
|
|
7
|
+
export declare const OGC_DEFAULT_PORT = 8090;
|
|
8
|
+
/**
|
|
9
|
+
* The document info for the OGC API surface.
|
|
10
|
+
*
|
|
11
|
+
* The landing page reads its title and description from it, and both API definitions include it.
|
|
12
|
+
*/
|
|
13
|
+
export declare const OGC_DOC_INFO: OpenAPIDocInfo;
|
|
14
|
+
/**
|
|
15
|
+
* Options for {@link createOGCApp}.
|
|
16
|
+
*/
|
|
17
|
+
export interface OGCAppOptions extends CompatibilityAppOptions {
|
|
18
|
+
/**
|
|
19
|
+
* The service's public base URL.
|
|
20
|
+
* Link hrefs and the API definition's `servers` entry use it.
|
|
21
|
+
*
|
|
22
|
+
* @defaultValue The request's own origin.
|
|
23
|
+
*/
|
|
24
|
+
baseURL?: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Builds the OGC API app around the given {@link OGCEngine}: the landing page at `/`,
|
|
28
|
+
* the conformance declaration at `/conformance`, the OpenAPI 3.0 definition at `/api`,
|
|
29
|
+
* the collections at `/collections`, forward geocoding at `/search`, and the OpenAPI
|
|
30
|
+
* 3.1 document at `/openapi.json` that every Mailwoman surface serves.
|
|
31
|
+
*/
|
|
32
|
+
export declare function createOGCApp(engine: OGCEngine, options?: OGCAppOptions): OpenAPIHono;
|
|
33
|
+
//# sourceMappingURL=app.d.ts.map
|
package/out/app.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../lib/app.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,EAEN,KAAK,uBAAuB,EAG5B,KAAK,cAAc,EAEnB,MAAM,oBAAoB,CAAA;AAG3B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAGxC;;GAEG;AACH,eAAO,MAAM,gBAAgB,OAAO,CAAA;AAEpC;;;;GAIG;AACH,eAAO,MAAM,YAAY,EAAE,cAmB1B,CAAA;AAED;;GAEG;AACH,MAAM,WAAW,aAAc,SAAQ,uBAAuB;IAC7D;;;;;OAKG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;CAChB;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,GAAE,aAAkB,GAAG,WAAW,CA+BxF"}
|
package/out/app.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
|
|
3
|
+
import { OpenAPIHono } from "@hono/zod-openapi";
|
|
4
|
+
import { attachOpenAPIDocs, engineHeaders, errorResponse, readServedDocumentInfo, } from "@mailwoman/api-kit";
|
|
5
|
+
import { cors } from "hono/cors";
|
|
6
|
+
import { registerOGCRoutes } from "#routes";
|
|
7
|
+
/**
|
|
8
|
+
* The port `mailwoman-ogc serve` listens on unless told otherwise.
|
|
9
|
+
*/
|
|
10
|
+
export const OGC_DEFAULT_PORT = 8090;
|
|
11
|
+
/**
|
|
12
|
+
* The document info for the OGC API surface.
|
|
13
|
+
*
|
|
14
|
+
* The landing page reads its title and description from it, and both API definitions include it.
|
|
15
|
+
*/
|
|
16
|
+
export const OGC_DOC_INFO = {
|
|
17
|
+
...(await readServedDocumentInfo(import.meta.url, "@mailwoman/ogc")),
|
|
18
|
+
license: { name: "AGPL-3.0-only OR LicenseRef-Commercial", identifier: "AGPL-3.0-only" },
|
|
19
|
+
contact: { name: "Sister Software", url: "https://mailwoman.post" },
|
|
20
|
+
externalDocs: {
|
|
21
|
+
description: "What Mailwoman is",
|
|
22
|
+
url: "https://mailwoman.post/product",
|
|
23
|
+
},
|
|
24
|
+
servers: [
|
|
25
|
+
{
|
|
26
|
+
url: "http://{host}:{port}",
|
|
27
|
+
variables: { host: { default: "127.0.0.1" }, port: { default: String(OGC_DEFAULT_PORT) } },
|
|
28
|
+
},
|
|
29
|
+
],
|
|
30
|
+
security: [],
|
|
31
|
+
tags: [
|
|
32
|
+
{ name: "capabilities", description: "The OGC API Common landing page, conformance and API definition." },
|
|
33
|
+
{ name: "data", description: "The collections and the forward geocoding search." },
|
|
34
|
+
],
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Builds the OGC API app around the given {@link OGCEngine}: the landing page at `/`,
|
|
38
|
+
* the conformance declaration at `/conformance`, the OpenAPI 3.0 definition at `/api`,
|
|
39
|
+
* the collections at `/collections`, forward geocoding at `/search`, and the OpenAPI
|
|
40
|
+
* 3.1 document at `/openapi.json` that every Mailwoman surface serves.
|
|
41
|
+
*/
|
|
42
|
+
export function createOGCApp(engine, options = {}) {
|
|
43
|
+
const app = new OpenAPIHono({
|
|
44
|
+
defaultHook: (result, c) => {
|
|
45
|
+
if (result.success)
|
|
46
|
+
return;
|
|
47
|
+
const detail = result.error.issues
|
|
48
|
+
.map((issue) => (issue.path.length ? `${issue.path.join(".")}: ${issue.message}` : issue.message))
|
|
49
|
+
.join("; ");
|
|
50
|
+
return errorResponse(c, 400, "invalid query parameter", detail);
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
if (options.cors !== false) {
|
|
54
|
+
app.use(cors({ origin: "*", allowMethods: ["GET", "OPTIONS"], allowHeaders: ["*"], maxAge: 86_400 }));
|
|
55
|
+
}
|
|
56
|
+
if (options.engine) {
|
|
57
|
+
app.use(engineHeaders(options.engine));
|
|
58
|
+
}
|
|
59
|
+
app.onError((_error, c) => errorResponse(c, 500, "internal error"));
|
|
60
|
+
const docInfo = options.baseURL
|
|
61
|
+
? { ...OGC_DOC_INFO, servers: [{ url: options.baseURL }] }
|
|
62
|
+
: OGC_DOC_INFO;
|
|
63
|
+
registerOGCRoutes(app, engine, { baseURL: options.baseURL, docInfo });
|
|
64
|
+
attachOpenAPIDocs(app, docInfo);
|
|
65
|
+
return app;
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=app.js.map
|
package/out/app.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app.js","sourceRoot":"","sources":["../lib/app.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,kEAAkE;AAElE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,EACN,iBAAiB,EAEjB,aAAa,EACb,aAAa,EAEb,sBAAsB,GACtB,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAGhC,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAE3C;;GAEG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,CAAA;AAEpC;;;;GAIG;AACH,MAAM,CAAC,MAAM,YAAY,GAAmB;IAC3C,GAAG,CAAC,MAAM,sBAAsB,CAAC,OAAO,IAAI,CAAC,GAAG,EAAE,gBAAgB,CAAC,CAAC;IACpE,OAAO,EAAE,EAAE,IAAI,EAAE,wCAAwC,EAAE,UAAU,EAAE,eAAe,EAAE;IACxF,OAAO,EAAE,EAAE,IAAI,EAAE,iBAAiB,EAAE,GAAG,EAAE,wBAAwB,EAAE;IACnE,YAAY,EAAE;QACb,WAAW,EAAE,mBAAmB;QAChC,GAAG,EAAE,gCAAgC;KACrC;IACD,OAAO,EAAE;QACR;YACC,GAAG,EAAE,sBAAsB;YAC3B,SAAS,EAAE,EAAE,IAAI,EAAE,EAAE,OAAO,EAAE,WAAW,EAAE,EAAE,IAAI,EAAE,EAAE,OAAO,EAAE,MAAM,CAAC,gBAAgB,CAAC,EAAE,EAAE;SAC1F;KACD;IACD,QAAQ,EA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AAG,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC,aAAa,CAAC,CAAC,EAAE,GAAG,EAAE,gBAAgB,CAAC,CAAC,CAAA;IAEnE,MAAM,OAAO,GAAmB,OAAO,CAAC,OAAO;QAC9C,CAAC,CAAC,EAAE,GAAG,YAAY,EAAE,OAAO,EAAE,CAAC,EAAE,GAAG,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC,EAAE;QAC1D,CAAC,CAAC,YAAY,CAAA;IAEf,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,CAAC,CAAA;IACrE,iBAAiB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;IAE/B,OAAO,GAAG,CAAA;AACX,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../cli/main.ts"],"names":[],"mappings":""}
|
package/out/cli/main.js
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
|
|
3
|
+
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
|
|
4
|
+
/**
|
|
5
|
+
* `mailwoman-ogc` boots the OGC API surface through the `serve` command
|
|
6
|
+
* and prints its API definition through the `openapi` command.
|
|
7
|
+
*
|
|
8
|
+
* `serve` wires `/search` over `geocodeAddress` (parse, then resolve) with the same
|
|
9
|
+
* gazetteer, classifier and rooftop providers the Photon and Nominatim servers attach,
|
|
10
|
+
* and lists as collections the layers those providers opened.
|
|
11
|
+
*/
|
|
12
|
+
import { serveNode } from "@mailwoman/api-kit";
|
|
13
|
+
import { worldCountries } from "@mailwoman/codex/country/sets";
|
|
14
|
+
import { US_STATE_BY_ABBREVIATION } from "@mailwoman/codex/us";
|
|
15
|
+
import { dataRootPath } from "@mailwoman/core/data-root";
|
|
16
|
+
import { parseArguments } from "@mailwoman/core/scripting/arguments";
|
|
17
|
+
import { createWOFResolver } from "@mailwoman/resolver";
|
|
18
|
+
import { corsBannerLine, gazetteerBannerLines, loadClassifierOrExit, openAPICommand, resolveGazetteerOrExit, runDropInCLI, } from "mailwoman/cli/kit/dropin";
|
|
19
|
+
import { geocodeAddress, USStateDatabaseProvider } from "mailwoman/geocode";
|
|
20
|
+
import { openServingRooftopProviders } from "mailwoman/geocode/serving-layers";
|
|
21
|
+
import { createResolverBackend } from "mailwoman/resolver-backend";
|
|
22
|
+
import { createOGCApp, geocodeSearchHits, OGC_COLLECTION_CATALOG, OGC_DEFAULT_PORT, OGC_DOC_INFO, servedCollections, } from "#index";
|
|
23
|
+
const BINARY_NAME = "mailwoman-ogc";
|
|
24
|
+
/**
|
|
25
|
+
* The engine the `openapi` command documents.
|
|
26
|
+
*
|
|
27
|
+
* It lists every collection the surface can serve, so the printed definition
|
|
28
|
+
* declares each collection's `/search` parameters.
|
|
29
|
+
*/
|
|
30
|
+
const DOCUMENTED_ENGINE = {
|
|
31
|
+
collections: Object.keys(OGC_COLLECTION_CATALOG).map((id) => ({ id: id, regions: null })),
|
|
32
|
+
search: async () => [],
|
|
33
|
+
};
|
|
34
|
+
async function serve(engineStamp) {
|
|
35
|
+
const { values } = parseArguments({
|
|
36
|
+
options: {
|
|
37
|
+
port: { type: "string", default: String(OGC_DEFAULT_PORT) },
|
|
38
|
+
host: { type: "string", default: "0.0.0.0" },
|
|
39
|
+
// The public base URL that link hrefs resolve against, for a deployment behind a reverse proxy.
|
|
40
|
+
"base-url": { type: "string" },
|
|
41
|
+
"candidate-db": { type: "string" },
|
|
42
|
+
// Permissive CORS is on by default because OGC API clients run in browsers too.
|
|
43
|
+
// `--no-cors` turns it off where a reverse proxy already sets the headers.
|
|
44
|
+
cors: { type: "boolean", default: true },
|
|
45
|
+
},
|
|
46
|
+
allowNegative: true,
|
|
47
|
+
allowPositionals: true,
|
|
48
|
+
});
|
|
49
|
+
const port = Number(values.port) || OGC_DEFAULT_PORT;
|
|
50
|
+
const host = values.host ?? "0.0.0.0";
|
|
51
|
+
const baseURL = values["base-url"];
|
|
52
|
+
const resolverMod = await import("@mailwoman/resolver-wof-sqlite");
|
|
53
|
+
const gazetteer = await resolveGazetteerOrExit(values["candidate-db"] ?? null);
|
|
54
|
+
const { candidateDB, wofPaths } = gazetteer;
|
|
55
|
+
const classifier = await loadClassifierOrExit();
|
|
56
|
+
const backend = await createResolverBackend(resolverMod, { wofPaths, candidateDB });
|
|
57
|
+
const resolver = createWOFResolver(backend);
|
|
58
|
+
// The gazetteer's own ancestry reader labels each place match with its region and county.
|
|
59
|
+
const ancestorsOf = backend.ancestors?.bind(backend);
|
|
60
|
+
const extracts = await USStateDatabaseProvider.create(resolverMod, dataRootPath());
|
|
61
|
+
// The national open register ahead of the OpenStreetMap tier, read from one generation
|
|
62
|
+
// of the active selection, as the Photon and Nominatim servers read them.
|
|
63
|
+
const rooftops = await openServingRooftopProviders(dataRootPath());
|
|
64
|
+
const countries = worldCountries();
|
|
65
|
+
const probes = [
|
|
66
|
+
{
|
|
67
|
+
provider: extracts,
|
|
68
|
+
keys: Object.keys(US_STATE_BY_ABBREVIATION).map((abbreviation) => abbreviation.toLowerCase()),
|
|
69
|
+
regionOf: (slug) => `US-${slug.toUpperCase()}`,
|
|
70
|
+
},
|
|
71
|
+
{ provider: rooftops.national, keys: countries, regionOf: (code) => code.toUpperCase() },
|
|
72
|
+
...(rooftops.osm
|
|
73
|
+
? [{ provider: rooftops.osm, keys: countries, regionOf: (code) => code.toUpperCase() }]
|
|
74
|
+
: []),
|
|
75
|
+
];
|
|
76
|
+
const engine = {
|
|
77
|
+
collections: servedCollections(probes),
|
|
78
|
+
async search(q) {
|
|
79
|
+
// The call sets no country constraint, so the placer routes the query to its own country.
|
|
80
|
+
const result = await geocodeAddress(q, {
|
|
81
|
+
classifier,
|
|
82
|
+
resolver,
|
|
83
|
+
databases: extracts.for,
|
|
84
|
+
nationalDatabases: rooftops.national.for,
|
|
85
|
+
...(rooftops.osm ? { osmDatabases: rooftops.osm.for } : {}),
|
|
86
|
+
});
|
|
87
|
+
return geocodeSearchHits(result, ancestorsOf);
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
const app = createOGCApp(engine, { cors: values.cors, engine: engineStamp.stamp, baseURL });
|
|
91
|
+
await serveNode({
|
|
92
|
+
fetch: app.fetch,
|
|
93
|
+
port,
|
|
94
|
+
hostname: host,
|
|
95
|
+
onListen: () => {
|
|
96
|
+
console.error(`[@mailwoman/ogc] listening on http://${host}:${port}`);
|
|
97
|
+
console.error(` base URL: ${baseURL ?? "(the request's own origin)"}`);
|
|
98
|
+
for (const line of gazetteerBannerLines(gazetteer)) {
|
|
99
|
+
console.error(line);
|
|
100
|
+
}
|
|
101
|
+
for (const { id, regions } of engine.collections) {
|
|
102
|
+
console.error(` collection ${id}: ${regions ? regions.join(" ") : "worldwide"}`);
|
|
103
|
+
}
|
|
104
|
+
console.error(corsBannerLine(values.cors));
|
|
105
|
+
console.error(` endpoints: GET / GET /conformance GET /api GET /collections GET /search GET /openapi.json`);
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
await runDropInCLI({
|
|
110
|
+
binaryName: BINARY_NAME,
|
|
111
|
+
openapi: openAPICommand(BINARY_NAME, createOGCApp, OGC_DOC_INFO, DOCUMENTED_ENGINE),
|
|
112
|
+
serve,
|
|
113
|
+
usage: [
|
|
114
|
+
" serve [--port 8090] [--host 0.0.0.0] [--base-url <url>] [--candidate-db <path>] [--no-cors]",
|
|
115
|
+
" openapi [--flavor 3.1|3.0] [--out <path>]",
|
|
116
|
+
],
|
|
117
|
+
});
|
|
118
|
+
//# sourceMappingURL=main.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.js","sourceRoot":"","sources":["../../cli/main.ts"],"names":[],"mappings":";AACA,kEAAkE;AAClE,kEAAkE;AAElE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C/F,6CAA6C;KAC7C;CACD,CAAC,CAAA"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The collections the OGC surface can describe, and the engine output each one holds.
|
|
3
|
+
*
|
|
4
|
+
* A collection groups the answers one kind of serving layer produces.
|
|
5
|
+
* The geocoder reports which tier placed a coordinate, so the tier decides the collection.
|
|
6
|
+
*
|
|
7
|
+
* The running engine lists only the collections whose layers it opened,
|
|
8
|
+
* and `/collections` serves that list.
|
|
9
|
+
*/
|
|
10
|
+
import type { GeocodeResult } from "@mailwoman/core/geocode";
|
|
11
|
+
import type { RegionDatabaseProvider } from "@mailwoman/core/resolver";
|
|
12
|
+
import type { OGCServedCollection } from "#engine";
|
|
13
|
+
type ResolutionTier = GeocodeResult["resolution_tier"];
|
|
14
|
+
/**
|
|
15
|
+
* The table maps each collection's name to its id.
|
|
16
|
+
*/
|
|
17
|
+
export declare const OGCCollectionID: {
|
|
18
|
+
readonly Addresses: "addresses";
|
|
19
|
+
readonly Streets: "streets";
|
|
20
|
+
readonly Postcodes: "postcodes";
|
|
21
|
+
readonly Places: "places";
|
|
22
|
+
readonly PlusCodes: "plus-codes";
|
|
23
|
+
};
|
|
24
|
+
export type OGCCollectionID = (typeof OGCCollectionID)[keyof typeof OGCCollectionID];
|
|
25
|
+
/**
|
|
26
|
+
* The fixed title and description of one collection.
|
|
27
|
+
*/
|
|
28
|
+
export interface OGCCollectionEntry {
|
|
29
|
+
title: string;
|
|
30
|
+
description: string;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The title and description of every collection.
|
|
34
|
+
*/
|
|
35
|
+
export declare const OGC_COLLECTION_CATALOG: Readonly<Record<OGCCollectionID, OGCCollectionEntry>>;
|
|
36
|
+
/**
|
|
37
|
+
* The collection that holds an answer the geocoder placed at `tier`.
|
|
38
|
+
*
|
|
39
|
+
* @returns Null for a tier no collection holds, such as `venue`, whose layer the OGC engine doesn't open.
|
|
40
|
+
*/
|
|
41
|
+
export declare function collectionOfTier(tier: ResolutionTier): OGCCollectionID | null;
|
|
42
|
+
/**
|
|
43
|
+
* The collection that holds a gazetteer place of `placetype`.
|
|
44
|
+
*/
|
|
45
|
+
export declare function collectionOfPlacetype(placetype: string): OGCCollectionID;
|
|
46
|
+
/**
|
|
47
|
+
* One region-keyed provider of street-tier layers, and the keys to ask it for.
|
|
48
|
+
*/
|
|
49
|
+
export interface RegionLayerProbe {
|
|
50
|
+
provider: Pick<RegionDatabaseProvider, "for">;
|
|
51
|
+
keys: Iterable<string>;
|
|
52
|
+
/**
|
|
53
|
+
* The region code a key names in a collection description, such as `US-TX` for the key `tx`.
|
|
54
|
+
*/
|
|
55
|
+
regionOf: (key: string) => string;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* The collections an engine serves, from the layers its providers opened.
|
|
59
|
+
*
|
|
60
|
+
* The gazetteer is always open, because the engine refuses to start without one,
|
|
61
|
+
* so places, postcodes and plus codes are always served.
|
|
62
|
+
* Addresses and streets are served when some region has an address-point, interpolation
|
|
63
|
+
* or street-centroid layer, and their descriptions name those regions.
|
|
64
|
+
*
|
|
65
|
+
* A collection no region has a layer for is left out of the list.
|
|
66
|
+
*
|
|
67
|
+
* A provider opens a region's layers when asked for the region.
|
|
68
|
+
* A query for that region would open them as well.
|
|
69
|
+
*/
|
|
70
|
+
export declare function servedCollections(probes: readonly RegionLayerProbe[]): OGCServedCollection[];
|
|
71
|
+
export {};
|
|
72
|
+
//# sourceMappingURL=collections.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collections.d.ts","sourceRoot":"","sources":["../lib/collections.ts"],"names":[],"mappings":"AAGA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAA;AAC5D,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAA;AAEtE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAA;AAEl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