@mailwoman/nominatim 7.2.0 → 7.2.1
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/app.ts +74 -0
- package/cli.ts +385 -0
- package/dev-tools/capture-search-golden.run.ts +81 -0
- package/engine.ts +114 -0
- package/format.ts +150 -0
- package/index.ts +29 -0
- package/package.json +33 -19
- package/routes.ts +281 -0
- package/schema.ts +222 -0
package/schema.ts
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* Zod wire schemas for the Nominatim-compatible surface. Key names and envelopes are the vendor
|
|
7
|
+
* contract — immutable. Query schemas are validator-proof (string|string[] unions, all optional)
|
|
8
|
+
* with doc-exact `.openapi()` overrides; every wire decision lives in the handlers (see
|
|
9
|
+
* routes.ts's legacyQuery adapter, the photon-established pattern).
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { z } from "@hono/zod-openapi"
|
|
13
|
+
|
|
14
|
+
/** The `addressdetails=1` breakdown — OSM-derived keys; tolerant of extras. */
|
|
15
|
+
export const NominatimAddressDetailsSchema = z
|
|
16
|
+
.object({
|
|
17
|
+
house_number: z.string().optional(),
|
|
18
|
+
road: z.string().optional(),
|
|
19
|
+
neighbourhood: z.string().optional(),
|
|
20
|
+
suburb: z.string().optional(),
|
|
21
|
+
city: z.string().optional(),
|
|
22
|
+
town: z.string().optional(),
|
|
23
|
+
village: z.string().optional(),
|
|
24
|
+
county: z.string().optional(),
|
|
25
|
+
state: z.string().optional(),
|
|
26
|
+
postcode: z.string().optional(),
|
|
27
|
+
country: z.string().optional(),
|
|
28
|
+
country_code: z.string().optional(),
|
|
29
|
+
})
|
|
30
|
+
.loose()
|
|
31
|
+
.openapi("NominatimAddressDetails")
|
|
32
|
+
|
|
33
|
+
/** A single Nominatim result (the shape geopy and friends parse). */
|
|
34
|
+
export const NominatimResultSchema = z
|
|
35
|
+
.object({
|
|
36
|
+
place_id: z.union([z.number(), z.string()]),
|
|
37
|
+
licence: z.string(),
|
|
38
|
+
osm_type: z.string().optional(),
|
|
39
|
+
osm_id: z.union([z.number(), z.string()]).optional(),
|
|
40
|
+
lat: z.string(),
|
|
41
|
+
lon: z.string(),
|
|
42
|
+
display_name: z.string(),
|
|
43
|
+
boundingbox: z.tuple([z.string(), z.string(), z.string(), z.string()]).optional(),
|
|
44
|
+
class: z.string().optional(),
|
|
45
|
+
type: z.string().optional(),
|
|
46
|
+
importance: z.number().optional(),
|
|
47
|
+
place_rank: z.number().optional(),
|
|
48
|
+
address: NominatimAddressDetailsSchema.optional(),
|
|
49
|
+
geojson: z.unknown().optional(),
|
|
50
|
+
annotations: z.looseObject({}).optional(),
|
|
51
|
+
})
|
|
52
|
+
.loose()
|
|
53
|
+
.openapi("NominatimResult")
|
|
54
|
+
|
|
55
|
+
export const NominatimResultsSchema = z.array(NominatimResultSchema)
|
|
56
|
+
|
|
57
|
+
/** The `format=geojson` envelope — nominatim's own shape (polygon-capable geometry, result fields as properties). */
|
|
58
|
+
export const NominatimFeatureCollectionSchema = z
|
|
59
|
+
.object({
|
|
60
|
+
type: z.literal("FeatureCollection"),
|
|
61
|
+
features: z.array(
|
|
62
|
+
z.object({
|
|
63
|
+
type: z.literal("Feature"),
|
|
64
|
+
properties: z.looseObject({}),
|
|
65
|
+
geometry: z.unknown(),
|
|
66
|
+
bbox: z.tuple([z.number(), z.number(), z.number(), z.number()]).optional(),
|
|
67
|
+
})
|
|
68
|
+
),
|
|
69
|
+
})
|
|
70
|
+
.openapi("NominatimFeatureCollection")
|
|
71
|
+
|
|
72
|
+
/** The `/status` payload. */
|
|
73
|
+
export const NominatimStatusSchema = z
|
|
74
|
+
.object({
|
|
75
|
+
status: z.number(),
|
|
76
|
+
message: z.string(),
|
|
77
|
+
data_updated: z.string().optional(),
|
|
78
|
+
})
|
|
79
|
+
.openapi("NominatimStatus")
|
|
80
|
+
|
|
81
|
+
/** The JSON error envelope (this surface uses `{error}`, unlike photon's FeatureCollection+message). */
|
|
82
|
+
export const ErrorSchema = z
|
|
83
|
+
.object({
|
|
84
|
+
error: z.string(),
|
|
85
|
+
})
|
|
86
|
+
.openapi("Error")
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* The schema.org [`GeoCoordinates`](https://schema.org/GeoCoordinates) node — mirrors `@mailwoman/annotations`'s
|
|
90
|
+
* `SchemaOrgGeoCoordinates` interface. Hand-modeled locally (no import from `@mailwoman/annotations`), matching this
|
|
91
|
+
* file's existing wire-schema convention: each surface owns its own doc-accuracy schemas rather than sharing a schema
|
|
92
|
+
* across the package boundary.
|
|
93
|
+
*/
|
|
94
|
+
export const SchemaOrgGeoCoordinatesSchema = z
|
|
95
|
+
.object({
|
|
96
|
+
"@type": z.literal("GeoCoordinates"),
|
|
97
|
+
latitude: z.number(),
|
|
98
|
+
longitude: z.number(),
|
|
99
|
+
})
|
|
100
|
+
.openapi("SchemaOrgGeoCoordinates")
|
|
101
|
+
|
|
102
|
+
/** The schema.org [`PostalAddress`](https://schema.org/PostalAddress) node — mirrors `SchemaOrgPostalAddress`. */
|
|
103
|
+
export const SchemaOrgPostalAddressSchema = z
|
|
104
|
+
.object({
|
|
105
|
+
"@type": z.literal("PostalAddress"),
|
|
106
|
+
streetAddress: z.string().optional(),
|
|
107
|
+
postOfficeBoxNumber: z.string().optional(),
|
|
108
|
+
addressLocality: z.string().optional(),
|
|
109
|
+
addressRegion: z.string().optional(),
|
|
110
|
+
postalCode: z.string().optional(),
|
|
111
|
+
addressCountry: z.string().optional(),
|
|
112
|
+
})
|
|
113
|
+
.openapi("SchemaOrgPostalAddress")
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* The `format=jsonld` re-serialization (#1052) — mirrors `@mailwoman/annotations`'s `SchemaOrgPlace` interface, the
|
|
117
|
+
* shape `nominatimResultToSchemaOrg` actually produces.
|
|
118
|
+
*/
|
|
119
|
+
export const SchemaOrgPlaceSchema = z
|
|
120
|
+
.object({
|
|
121
|
+
"@context": z.literal("https://schema.org"),
|
|
122
|
+
"@type": z.literal("Place"),
|
|
123
|
+
name: z.string().optional(),
|
|
124
|
+
geo: SchemaOrgGeoCoordinatesSchema.optional(),
|
|
125
|
+
address: SchemaOrgPostalAddressSchema.optional(),
|
|
126
|
+
})
|
|
127
|
+
.openapi("SchemaOrgPlace")
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* The real `/search` 200 response union (#1052 doc accuracy): a jsonv2/json result array by default, a `format=geojson`
|
|
131
|
+
* FeatureCollection, or a `format=jsonld` array of schema.org `Place` objects — see `routes.ts`'s search handler.
|
|
132
|
+
* Doc-only; the wire behavior is unchanged.
|
|
133
|
+
*/
|
|
134
|
+
export const NominatimSearchResponseSchema = z
|
|
135
|
+
.union([NominatimResultsSchema, NominatimFeatureCollectionSchema, z.array(SchemaOrgPlaceSchema)])
|
|
136
|
+
.openapi("NominatimSearchResponse")
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* The real `/reverse` 200 response union (#1052 doc accuracy): a single jsonv2/json result, `null` when unresolved, a
|
|
140
|
+
* `format=geojson` FeatureCollection, or a `format=jsonld` schema.org `Place` — see `routes.ts`'s reverse handler.
|
|
141
|
+
* Doc-only; the wire behavior is unchanged.
|
|
142
|
+
*/
|
|
143
|
+
export const NominatimReverseResponseSchema = z
|
|
144
|
+
.union([NominatimResultSchema, z.null(), NominatimFeatureCollectionSchema, SchemaOrgPlaceSchema])
|
|
145
|
+
.openapi("NominatimReverseResponse")
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* The real `/lookup` 200 response union (#1052 doc accuracy): a jsonv2/json result array by default, or a
|
|
149
|
+
* `format=geojson` FeatureCollection. NO `jsonld` branch — a legacy quirk preserved verbatim by `routes.ts`'s lookup
|
|
150
|
+
* handler (`format=jsonld` falls through to the raw jsonv2 array there), so this union stays two-wide, unlike
|
|
151
|
+
* `/search`'s three-wide union.
|
|
152
|
+
*/
|
|
153
|
+
export const NominatimLookupResponseSchema = z
|
|
154
|
+
.union([NominatimResultsSchema, NominatimFeatureCollectionSchema])
|
|
155
|
+
.openapi("NominatimLookupResponse")
|
|
156
|
+
|
|
157
|
+
/** A validator-proof query param: accepts one value or repeats; the doc override keeps the emitted schema exact. */
|
|
158
|
+
const tolerantParam = z.union([z.string(), z.array(z.string())]).optional()
|
|
159
|
+
|
|
160
|
+
/** `GET /search` query. */
|
|
161
|
+
export const searchQueryParams = z.object({
|
|
162
|
+
q: tolerantParam.openapi({
|
|
163
|
+
type: "string",
|
|
164
|
+
description: "Free-text query. Mutually exclusive with the structured fields.",
|
|
165
|
+
}),
|
|
166
|
+
street: tolerantParam.openapi({ type: "string", description: "Structured: house number and street name." }),
|
|
167
|
+
city: tolerantParam.openapi({ type: "string", description: "Structured: city." }),
|
|
168
|
+
county: tolerantParam.openapi({ type: "string", description: "Structured: county." }),
|
|
169
|
+
state: tolerantParam.openapi({ type: "string", description: "Structured: state." }),
|
|
170
|
+
country: tolerantParam.openapi({ type: "string", description: "Structured: country." }),
|
|
171
|
+
postalcode: tolerantParam.openapi({ type: "string", description: "Structured: postal code." }),
|
|
172
|
+
countrycodes: tolerantParam.openapi({
|
|
173
|
+
type: "string",
|
|
174
|
+
description: "Comma-separated ISO 3166-1 alpha-2 codes restricting results.",
|
|
175
|
+
}),
|
|
176
|
+
bounded: tolerantParam.openapi({ type: "string", enum: ["0", "1"], description: "Restrict to the viewbox." }),
|
|
177
|
+
limit: tolerantParam.openapi({ type: "integer", description: "Maximum results (default 10)." }),
|
|
178
|
+
addressdetails: tolerantParam.openapi({
|
|
179
|
+
type: "string",
|
|
180
|
+
enum: ["0", "1"],
|
|
181
|
+
description: "Include the address breakdown.",
|
|
182
|
+
}),
|
|
183
|
+
format: tolerantParam.openapi({
|
|
184
|
+
type: "string",
|
|
185
|
+
enum: ["jsonv2", "json", "geojson", "jsonld"],
|
|
186
|
+
description: "Output format (default jsonv2).",
|
|
187
|
+
}),
|
|
188
|
+
"accept-language": tolerantParam.openapi({ type: "string", description: "Preferred result language." }),
|
|
189
|
+
})
|
|
190
|
+
|
|
191
|
+
/** `GET /reverse` query. */
|
|
192
|
+
export const reverseQueryParams = z.object({
|
|
193
|
+
lat: tolerantParam.openapi({ type: "number", description: "Latitude." }),
|
|
194
|
+
lon: tolerantParam.openapi({ type: "number", description: "Longitude." }),
|
|
195
|
+
zoom: tolerantParam.openapi({ type: "integer", description: "Detail level." }),
|
|
196
|
+
addressdetails: tolerantParam.openapi({
|
|
197
|
+
type: "string",
|
|
198
|
+
enum: ["0", "1"],
|
|
199
|
+
description: "Include the address breakdown.",
|
|
200
|
+
}),
|
|
201
|
+
format: tolerantParam.openapi({
|
|
202
|
+
type: "string",
|
|
203
|
+
enum: ["jsonv2", "json", "geojson", "jsonld"],
|
|
204
|
+
description: "Output format (default jsonv2).",
|
|
205
|
+
}),
|
|
206
|
+
"accept-language": tolerantParam.openapi({ type: "string", description: "Preferred result language." }),
|
|
207
|
+
})
|
|
208
|
+
|
|
209
|
+
/** `GET /lookup` query. */
|
|
210
|
+
export const lookupQueryParams = z.object({
|
|
211
|
+
osm_ids: tolerantParam.openapi({ type: "string", description: "Comma-separated OSM ids (N|W|R-prefixed)." }),
|
|
212
|
+
addressdetails: tolerantParam.openapi({
|
|
213
|
+
type: "string",
|
|
214
|
+
enum: ["0", "1"],
|
|
215
|
+
description: "Include the address breakdown.",
|
|
216
|
+
}),
|
|
217
|
+
format: tolerantParam.openapi({
|
|
218
|
+
type: "string",
|
|
219
|
+
enum: ["jsonv2", "json", "geojson", "jsonld"],
|
|
220
|
+
description: "Output format (default jsonv2).",
|
|
221
|
+
}),
|
|
222
|
+
})
|