@mailwoman/photon 9.0.0 → 9.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 +1 -1
- package/app.ts +4 -3
- package/cli.ts +43 -5
- package/locality-postcode.ts +69 -0
- package/out/app.d.ts.map +1 -1
- package/out/app.js +3 -3
- package/out/app.js.map +1 -1
- package/out/cli.js +33 -5
- package/out/cli.js.map +1 -1
- package/out/locality-postcode.d.ts +17 -0
- package/out/locality-postcode.d.ts.map +1 -0
- package/out/locality-postcode.js +55 -0
- package/out/locality-postcode.js.map +1 -0
- package/out/routes.d.ts.map +1 -1
- package/out/routes.js +3 -7
- package/out/routes.js.map +1 -1
- package/package.json +21 -13
- package/routes.ts +5 -10
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @mailwoman/photon
|
|
2
2
|
|
|
3
|
-
A **Photon-compatible autocomplete geocoding API** over the [Mailwoman](https://mailwoman.
|
|
3
|
+
A **Photon-compatible autocomplete geocoding API** over the [Mailwoman](https://mailwoman.ai) engine — search-as-you-type, returning GeoJSON `FeatureCollection`s. Where [`@mailwoman/nominatim`](../nominatim) is structured lookup, this is the type-ahead front door. No Elasticsearch.
|
|
4
4
|
|
|
5
5
|
```bash
|
|
6
6
|
# One-time data fetch (worldwide candidate gazetteer, population-first ranking, ~1.65 GB):
|
package/app.ts
CHANGED
|
@@ -9,9 +9,10 @@
|
|
|
9
9
|
|
|
10
10
|
import { OpenAPIHono } from "@hono/zod-openapi"
|
|
11
11
|
import { attachOpenAPIDocs, type OpenAPIDocInfo } from "@mailwoman/api-kit"
|
|
12
|
-
import packageJson from "@mailwoman/photon/package.json" with { type: "json" }
|
|
13
12
|
import { cors } from "hono/cors"
|
|
14
13
|
|
|
14
|
+
import packageJson from "#package.json" with { type: "json" }
|
|
15
|
+
|
|
15
16
|
import type { PhotonEngine } from "./engine.ts"
|
|
16
17
|
import { registerPhotonRoutes } from "./routes.ts"
|
|
17
18
|
|
|
@@ -38,10 +39,10 @@ export const PHOTON_DOC_INFO: OpenAPIDocInfo = {
|
|
|
38
39
|
version: packageJson.version,
|
|
39
40
|
description: packageJson.description,
|
|
40
41
|
license: { name: "AGPL-3.0-only OR LicenseRef-Commercial", identifier: "AGPL-3.0-only" },
|
|
41
|
-
contact: { name: "Sister Software", url: "https://mailwoman.
|
|
42
|
+
contact: { name: "Sister Software", url: "https://mailwoman.ai" },
|
|
42
43
|
externalDocs: {
|
|
43
44
|
description: "What Mailwoman is",
|
|
44
|
-
url: "https://mailwoman.
|
|
45
|
+
url: "https://mailwoman.ai/docs/developers/get-started/what-mailwoman-is",
|
|
45
46
|
},
|
|
46
47
|
servers: [
|
|
47
48
|
{
|
package/cli.ts
CHANGED
|
@@ -18,6 +18,7 @@ import { parseArgs } from "node:util"
|
|
|
18
18
|
|
|
19
19
|
import { printOpenAPIDocument, serveNode } from "@mailwoman/api-kit"
|
|
20
20
|
import { matchCountry } from "@mailwoman/codex/country"
|
|
21
|
+
import { pyTitle } from "@mailwoman/core"
|
|
21
22
|
import { createWOFResolver } from "@mailwoman/resolver"
|
|
22
23
|
import {
|
|
23
24
|
corsBannerLine,
|
|
@@ -41,6 +42,7 @@ import {
|
|
|
41
42
|
type PhotonEngine,
|
|
42
43
|
type PhotonProperties,
|
|
43
44
|
} from "./index.ts"
|
|
45
|
+
import { createLocalityPostcodeLookup } from "./locality-postcode.ts"
|
|
44
46
|
|
|
45
47
|
/**
|
|
46
48
|
* WOF placetype → Photon property key.
|
|
@@ -80,12 +82,13 @@ async function serve(): Promise<void> {
|
|
|
80
82
|
|
|
81
83
|
const resolverMod = await import("@mailwoman/resolver-wof-sqlite")
|
|
82
84
|
const gazetteer = resolveGazetteerOrExit(values["candidate-db"])
|
|
83
|
-
const { adminDBPath,
|
|
85
|
+
const { adminDBPath, candidateDB, wofPaths } = gazetteer
|
|
84
86
|
const classifier = await loadClassifierOrExit()
|
|
85
87
|
|
|
86
|
-
const backend = createResolverBackend(resolverMod, { wofPaths,
|
|
88
|
+
const backend = createResolverBackend(resolverMod, { wofPaths, candidateDB })
|
|
87
89
|
const resolver = createWOFResolver(backend)
|
|
88
90
|
const shards = new ShardProvider(resolverMod, mailwomanDataRoot())
|
|
91
|
+
const postcodeOfLocality = createLocalityPostcodeLookup()
|
|
89
92
|
// National open-register rooftop tier (#1012): BAN-FR ahead of the OSM tier for a non-US parse. A no-op
|
|
90
93
|
// when the shard isn't on disk (existsSync-gated inside the provider), so the endpoint degrades cleanly.
|
|
91
94
|
const { BANShardProvider } = await import("@mailwoman/ban/sdk")
|
|
@@ -121,20 +124,55 @@ async function serve(): Promise<void> {
|
|
|
121
124
|
// Photon clients don't TypeError. The candidate backend fills only the locality (no ancestors() table),
|
|
122
125
|
// so state/county come through only on an ancestry-capable backend — country still lands from the code.
|
|
123
126
|
const country = matchCountry(result.countryCode)
|
|
127
|
+
|
|
124
128
|
// #1041: a rooftop (`address_point`) or house-number-estimate (`interpolated`) tier is HOUSE-GRADE — carry the
|
|
125
129
|
// parsed housenumber + street so photonForwardProperties decorates it `type: house` (matching upstream Photon)
|
|
126
130
|
// instead of inheriting the admin locality's `type: city`. The admin tier (a locality centroid) never does.
|
|
127
|
-
const houseGrade =
|
|
131
|
+
const houseGrade =
|
|
132
|
+
result.resolution_tier === "address_point" ||
|
|
133
|
+
result.resolution_tier === "interpolated" ||
|
|
134
|
+
result.resolution_tier === "plus_code"
|
|
135
|
+
|
|
128
136
|
// #1050: the street-centroid tier is STREET-GRADE — full assembled street name in `name`,
|
|
129
137
|
// highway/street osm tags (the parallel of the #1041 house treatment).
|
|
130
138
|
const streetGrade = result.resolution_tier === "street"
|
|
131
139
|
|
|
140
|
+
// The register row's own scope tags (result.rooftop) decorate a house-grade answer whose
|
|
141
|
+
// hierarchy carries no locality/postcode — the register ATTESTS the rooftop's commune and
|
|
142
|
+
// postcode even when the query never named them, and #1014's decorate-from-the-resolved-place
|
|
143
|
+
// doctrine covers register attestations exactly as it covers gazetteer rows. The key form is
|
|
144
|
+
// normalized; title-case it for display (the shards store no display-cased locality).
|
|
145
|
+
const places = result.hierarchy.map((h) => ({ tag: h.tag, name: h.name }))
|
|
146
|
+
|
|
147
|
+
if (result.rooftop?.localityNorm && !places.some((p) => p.tag === "locality")) {
|
|
148
|
+
// The key form is normalized lowercase (the shards store no display-cased locality);
|
|
149
|
+
// pyTitle display-cases it particle-and-apostrophe-aware.
|
|
150
|
+
places.push({ tag: "locality", name: pyTitle(result.rooftop.localityNorm) })
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// Locality→postcode enrichment: an admin answer for a place whose CONTAINING postcode is
|
|
154
|
+
// unambiguous (exactly one) carries that postcode — the register/WOF attests it, the query
|
|
155
|
+
// simply never said it. Multi-postcode cities (Paris) get NOTHING: the exactly-one rule is
|
|
156
|
+
// the abstention, per the registry doctrine. Keyed by the resolved place's WOF id, so no
|
|
157
|
+
// name matching is involved.
|
|
158
|
+
let enrichedPostcode: string | undefined
|
|
159
|
+
|
|
160
|
+
if (!result.postcode && !result.rooftop?.postcode) {
|
|
161
|
+
const localityID = result.hierarchy.find(
|
|
162
|
+
(h) => (h.tag === "locality" || h.tag === "localadmin") && h.placeID?.startsWith("wof:")
|
|
163
|
+
)?.placeID
|
|
164
|
+
|
|
165
|
+
if (localityID) {
|
|
166
|
+
enrichedPostcode = postcodeOfLocality(Number(localityID.slice(4)), result.countryCode)
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
132
170
|
const primary: PhotonForwardInput = {
|
|
133
171
|
lat: result.lat,
|
|
134
172
|
lon: result.lon,
|
|
135
|
-
postcode: result.postcode,
|
|
173
|
+
postcode: result.postcode ?? result.rooftop?.postcode ?? enrichedPostcode,
|
|
136
174
|
country: country ? { name: country.canonical, code: country.iso2 } : undefined,
|
|
137
|
-
places
|
|
175
|
+
places,
|
|
138
176
|
...(houseGrade ? { house: { number: result.house_number, street: result.street } } : {}),
|
|
139
177
|
...(streetGrade ? { street: { name: result.street } } : {}),
|
|
140
178
|
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* Reverse lookup over the `postcode-locality-*.db` artifacts: the CONTAINING postcode of a
|
|
7
|
+
* resolved locality, keyed by its WOF id — no name matching. Serves the drop-ins' answer
|
|
8
|
+
* enrichment: a village answer carries the postcode the gazetteer attests for it.
|
|
9
|
+
*
|
|
10
|
+
* The exactly-one rule is the abstention: a locality contained by several postcodes (any real
|
|
11
|
+
* city) gets NOTHING — emitting one of many would state a precision the evidence doesn't hold.
|
|
12
|
+
* Tolerate-and-degrade like every optional artifact: a machine without the DBs answers undefined
|
|
13
|
+
* everywhere and the consumer simply doesn't decorate.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { existsSync } from "node:fs"
|
|
17
|
+
import { DatabaseSync } from "node:sqlite"
|
|
18
|
+
|
|
19
|
+
import { dataRootPath } from "@mailwoman/core/utils"
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The per-country artifacts, probed in caller-country order with `intl` as the shared fallback.
|
|
23
|
+
*/
|
|
24
|
+
const POSTCODE_LOCALITY_SUFFIXES = ["fr", "de", "jp", "intl"] as const
|
|
25
|
+
|
|
26
|
+
export type LocalityPostcodeLookup = (wofID: number, countryCode: string | null) => string | undefined
|
|
27
|
+
|
|
28
|
+
export function createLocalityPostcodeLookup(): LocalityPostcodeLookup {
|
|
29
|
+
const statements = new Map<string, ReturnType<DatabaseSync["prepare"]>>()
|
|
30
|
+
|
|
31
|
+
for (const suffix of POSTCODE_LOCALITY_SUFFIXES) {
|
|
32
|
+
const path = String(dataRootPath("wof", `postcode-locality-${suffix}.db`))
|
|
33
|
+
|
|
34
|
+
if (!existsSync(path)) continue
|
|
35
|
+
|
|
36
|
+
try {
|
|
37
|
+
const db = new DatabaseSync(path, { readOnly: true })
|
|
38
|
+
|
|
39
|
+
// No `is_containing` filter: villages routinely carry 0 (the builder's containment test is
|
|
40
|
+
// distance-classified, and a village near its postcode centroid still has exactly one code).
|
|
41
|
+
// The exactly-one DISTINCT rule below is the entire ambiguity guard.
|
|
42
|
+
statements.set(
|
|
43
|
+
suffix,
|
|
44
|
+
db.prepare(`SELECT DISTINCT postcode FROM postcode_locality WHERE locality_id = ? LIMIT 2`)
|
|
45
|
+
)
|
|
46
|
+
} catch {
|
|
47
|
+
// A torn or foreign file degrades to no enrichment, never a crash at serve start.
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return (wofID, countryCode) => {
|
|
52
|
+
const cc = countryCode?.toLowerCase()
|
|
53
|
+
const order = cc && statements.has(cc) ? [cc, "intl"] : ["intl"]
|
|
54
|
+
|
|
55
|
+
for (const suffix of order) {
|
|
56
|
+
const stmt = statements.get(suffix)
|
|
57
|
+
|
|
58
|
+
if (!stmt) continue
|
|
59
|
+
|
|
60
|
+
const rows = stmt.all(wofID) as Array<{ postcode: string }>
|
|
61
|
+
|
|
62
|
+
if (rows.length === 1) return rows[0]!.postcode
|
|
63
|
+
|
|
64
|
+
if (rows.length > 1) return undefined // ambiguous — abstain, never guess
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return undefined
|
|
68
|
+
}
|
|
69
|
+
}
|
package/out/app.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../app.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,EAAqB,KAAK,cAAc,EAAE,MAAM,oBAAoB,CAAA;
|
|
1
|
+
{"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../app.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,EAAqB,KAAK,cAAc,EAAE,MAAM,oBAAoB,CAAA;AAK3E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAG/C;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAChC;;;;;OAKG;IACH,IAAI,CAAC,EAAE,OAAO,CAAA;CACd;AAED;;;;GAIG;AACH,eAAO,MAAM,eAAe,EAAE,cAqB7B,CAAA;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,YAAY,EAAE,OAAO,GAAE,gBAAqB,GAAG,WAAW,CAiBjG"}
|
package/out/app.js
CHANGED
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import { OpenAPIHono } from "@hono/zod-openapi";
|
|
10
10
|
import { attachOpenAPIDocs } from "@mailwoman/api-kit";
|
|
11
|
-
import packageJson from "@mailwoman/photon/package.json" with { type: "json" };
|
|
12
11
|
import { cors } from "hono/cors";
|
|
12
|
+
import packageJson from "#package.json" with { type: "json" };
|
|
13
13
|
import { registerPhotonRoutes } from "./routes.js";
|
|
14
14
|
/**
|
|
15
15
|
* The document info stamped into the emitted OpenAPI document. Exported (not inlined) so the CLI's `openapi` subcommand
|
|
@@ -21,10 +21,10 @@ export const PHOTON_DOC_INFO = {
|
|
|
21
21
|
version: packageJson.version,
|
|
22
22
|
description: packageJson.description,
|
|
23
23
|
license: { name: "AGPL-3.0-only OR LicenseRef-Commercial", identifier: "AGPL-3.0-only" },
|
|
24
|
-
contact: { name: "Sister Software", url: "https://mailwoman.
|
|
24
|
+
contact: { name: "Sister Software", url: "https://mailwoman.ai" },
|
|
25
25
|
externalDocs: {
|
|
26
26
|
description: "What Mailwoman is",
|
|
27
|
-
url: "https://mailwoman.
|
|
27
|
+
url: "https://mailwoman.ai/docs/developers/get-started/what-mailwoman-is",
|
|
28
28
|
},
|
|
29
29
|
servers: [
|
|
30
30
|
{
|
package/out/app.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app.js","sourceRoot":"","sources":["../app.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,EAAE,iBAAiB,EAAuB,MAAM,oBAAoB,CAAA;AAC3E,OAAO,
|
|
1
|
+
{"version":3,"file":"app.js","sourceRoot":"","sources":["../app.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,EAAE,iBAAiB,EAAuB,MAAM,oBAAoB,CAAA;AAC3E,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAEhC,OAAO,WAAW,MAAM,eAAe,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAA;AAG7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAelD;;;;GAIG;AACH,MAAM,CAAC,MAAM,eAAe,GAAmB;IAC9C,KAAK,EAAE,WAAW,CAAC,IAAI;IACvB,OAAO,EAAE,WAAW,CAAC,OAAO;IAC5B,WAAW,EAAE,WAAW,CAAC,WAAW;IACpC,OAAO,EAAE,EAAE,IAAI,EAAE,wCAAwC,EAAE,UAAU,EAAE,eAAe,EAAE;IACxF,OAAO,EAAE,EAAE,IAAI,EAAE,iBAAiB,EAAE,GAAG,EAAE,sBAAsB,EAAE;IACjE,YAAY,EAAE;QACb,WAAW,EAAE,mBAAmB;QAChC,GAAG,EAAE,oEAAoE;KACzE;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,EAAE,EAAE;SACxE;KACD;IACD,QAAQ,EAAE,EAAE;IACZ,IAAI,EAAE;QACL,EAAE,IAAI,EAAE,WAAW,EAAE,WAAW,EAAE,6CAA6C,EAAE;QACjF,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,oCAAoC,EAAE;KACnE;CACD,CAAA;AAED;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,MAAoB,EAAE,UAA4B,EAAE;IACnF,MAAM,GAAG,GAAG,IAAI,WAAW,EAAE,CAAA;IAE7B,gHAAgH;IAChH,6GAA6G;IAC7G,IAAI,OAAO,CAAC,IAAI,KAAK,KAAK,EAAE,CAAC;QAC5B,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,YAAY,EAAE,CAAC,KAAK,EAAE,SAAS,CAAC,EAAE,YAAY,EAAE,CAAC,GAAG,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC,CAAA;IACtG,CAAC;IAED,6GAA6G;IAC7G,qEAAqE;IACrE,GAAG,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,mBAAmB,EAAE,QAAQ,EAAE,EAAE,EAAE,OAAO,EAAE,gBAAgB,EAAE,EAAE,GAAG,CAAC,CAAC,CAAA;IAE/G,oBAAoB,CAAC,GAAG,EAAE,MAAM,CAAC,CAAA;IACjC,iBAAiB,CAAC,GAAG,EAAE,eAAe,CAAC,CAAA;IAEvC,OAAO,GAAG,CAAA;AACX,CAAC"}
|
package/out/cli.js
CHANGED
|
@@ -16,11 +16,13 @@
|
|
|
16
16
|
import { parseArgs } from "node:util";
|
|
17
17
|
import { printOpenAPIDocument, serveNode } from "@mailwoman/api-kit";
|
|
18
18
|
import { matchCountry } from "@mailwoman/codex/country";
|
|
19
|
+
import { pyTitle } from "@mailwoman/core";
|
|
19
20
|
import { createWOFResolver } from "@mailwoman/resolver";
|
|
20
21
|
import { corsBannerLine, gazetteerBannerLines, loadClassifierOrExit, parseOpenAPIFlags, resolveGazetteerOrExit, runDropInCLI, } from "mailwoman/cli-kit/dropin";
|
|
21
22
|
import { geocodeAddress, ShardProvider } from "mailwoman/geocode-core";
|
|
22
23
|
import { createResolverBackend, mailwomanDataRoot } from "mailwoman/resolver-backend";
|
|
23
24
|
import { createPhotonApp, PHOTON_DOC_INFO, photonCollection, photonFeature, photonForwardCollection, photonOSMTags, } from "./index.js";
|
|
25
|
+
import { createLocalityPostcodeLookup } from "./locality-postcode.js";
|
|
24
26
|
/**
|
|
25
27
|
* WOF placetype → Photon property key.
|
|
26
28
|
*/
|
|
@@ -54,11 +56,12 @@ async function serve() {
|
|
|
54
56
|
const host = values.host ?? "0.0.0.0";
|
|
55
57
|
const resolverMod = await import("@mailwoman/resolver-wof-sqlite");
|
|
56
58
|
const gazetteer = resolveGazetteerOrExit(values["candidate-db"]);
|
|
57
|
-
const { adminDBPath,
|
|
59
|
+
const { adminDBPath, candidateDB, wofPaths } = gazetteer;
|
|
58
60
|
const classifier = await loadClassifierOrExit();
|
|
59
|
-
const backend = createResolverBackend(resolverMod, { wofPaths,
|
|
61
|
+
const backend = createResolverBackend(resolverMod, { wofPaths, candidateDB });
|
|
60
62
|
const resolver = createWOFResolver(backend);
|
|
61
63
|
const shards = new ShardProvider(resolverMod, mailwomanDataRoot());
|
|
64
|
+
const postcodeOfLocality = createLocalityPostcodeLookup();
|
|
62
65
|
// National open-register rooftop tier (#1012): BAN-FR ahead of the OSM tier for a non-US parse. A no-op
|
|
63
66
|
// when the shard isn't on disk (existsSync-gated inside the provider), so the endpoint degrades cleanly.
|
|
64
67
|
const { BANShardProvider } = await import("@mailwoman/ban/sdk");
|
|
@@ -95,16 +98,41 @@ async function serve() {
|
|
|
95
98
|
// #1041: a rooftop (`address_point`) or house-number-estimate (`interpolated`) tier is HOUSE-GRADE — carry the
|
|
96
99
|
// parsed housenumber + street so photonForwardProperties decorates it `type: house` (matching upstream Photon)
|
|
97
100
|
// instead of inheriting the admin locality's `type: city`. The admin tier (a locality centroid) never does.
|
|
98
|
-
const houseGrade = result.resolution_tier === "address_point" ||
|
|
101
|
+
const houseGrade = result.resolution_tier === "address_point" ||
|
|
102
|
+
result.resolution_tier === "interpolated" ||
|
|
103
|
+
result.resolution_tier === "plus_code";
|
|
99
104
|
// #1050: the street-centroid tier is STREET-GRADE — full assembled street name in `name`,
|
|
100
105
|
// highway/street osm tags (the parallel of the #1041 house treatment).
|
|
101
106
|
const streetGrade = result.resolution_tier === "street";
|
|
107
|
+
// The register row's own scope tags (result.rooftop) decorate a house-grade answer whose
|
|
108
|
+
// hierarchy carries no locality/postcode — the register ATTESTS the rooftop's commune and
|
|
109
|
+
// postcode even when the query never named them, and #1014's decorate-from-the-resolved-place
|
|
110
|
+
// doctrine covers register attestations exactly as it covers gazetteer rows. The key form is
|
|
111
|
+
// normalized; title-case it for display (the shards store no display-cased locality).
|
|
112
|
+
const places = result.hierarchy.map((h) => ({ tag: h.tag, name: h.name }));
|
|
113
|
+
if (result.rooftop?.localityNorm && !places.some((p) => p.tag === "locality")) {
|
|
114
|
+
// The key form is normalized lowercase (the shards store no display-cased locality);
|
|
115
|
+
// pyTitle display-cases it particle-and-apostrophe-aware.
|
|
116
|
+
places.push({ tag: "locality", name: pyTitle(result.rooftop.localityNorm) });
|
|
117
|
+
}
|
|
118
|
+
// Locality→postcode enrichment: an admin answer for a place whose CONTAINING postcode is
|
|
119
|
+
// unambiguous (exactly one) carries that postcode — the register/WOF attests it, the query
|
|
120
|
+
// simply never said it. Multi-postcode cities (Paris) get NOTHING: the exactly-one rule is
|
|
121
|
+
// the abstention, per the registry doctrine. Keyed by the resolved place's WOF id, so no
|
|
122
|
+
// name matching is involved.
|
|
123
|
+
let enrichedPostcode;
|
|
124
|
+
if (!result.postcode && !result.rooftop?.postcode) {
|
|
125
|
+
const localityID = result.hierarchy.find((h) => (h.tag === "locality" || h.tag === "localadmin") && h.placeID?.startsWith("wof:"))?.placeID;
|
|
126
|
+
if (localityID) {
|
|
127
|
+
enrichedPostcode = postcodeOfLocality(Number(localityID.slice(4)), result.countryCode);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
102
130
|
const primary = {
|
|
103
131
|
lat: result.lat,
|
|
104
132
|
lon: result.lon,
|
|
105
|
-
postcode: result.postcode,
|
|
133
|
+
postcode: result.postcode ?? result.rooftop?.postcode ?? enrichedPostcode,
|
|
106
134
|
country: country ? { name: country.canonical, code: country.iso2 } : undefined,
|
|
107
|
-
places
|
|
135
|
+
places,
|
|
108
136
|
...(houseGrade ? { house: { number: result.house_number, street: result.street } } : {}),
|
|
109
137
|
...(streetGrade ? { street: { name: result.street } } : {}),
|
|
110
138
|
};
|
package/out/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../cli.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAErC,OAAO,EAAE,oBAAoB,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AACpE,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AACvD,OAAO,EACN,cAAc,EACd,oBAAoB,EACpB,oBAAoB,EACpB,iBAAiB,EACjB,sBAAsB,EACtB,YAAY,GACZ,MAAM,0BAA0B,CAAA;AACjC,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAA;AACtE,OAAO,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAA;AAErF,OAAO,EACN,eAAe,EACf,eAAe,EACf,gBAAgB,EAChB,aAAa,EACb,uBAAuB,EAEvB,aAAa,GAGb,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../cli.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAErC,OAAO,EAAE,o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ACT,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;;;;;;GAMG;AACH,SAAS,OAAO;IACf,MAAM,GAAG,GAAG,eAAe,CAAC,EAAE,CAAC,CAAA;IAE/B,oBAAoB,CAAC,GAAG,EAAE,eAAe,EAAE,iBAAiB,CAAC,WAAW,CAAC,CAAC,CAAA;AAC3E,CAAC;AAED,MAAM,YAAY,CAAC;IAClB,UAAU,EAAE,WAAW;IACvB,OAAO;IACP,KAAK;IACL,KAAK,EAAE;QACN,4EAA4E;QAC5E,6CAA6C;KAC7C;CACD,CAAC,CAAA"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* Reverse lookup over the `postcode-locality-*.db` artifacts: the CONTAINING postcode of a
|
|
7
|
+
* resolved locality, keyed by its WOF id — no name matching. Serves the drop-ins' answer
|
|
8
|
+
* enrichment: a village answer carries the postcode the gazetteer attests for it.
|
|
9
|
+
*
|
|
10
|
+
* The exactly-one rule is the abstention: a locality contained by several postcodes (any real
|
|
11
|
+
* city) gets NOTHING — emitting one of many would state a precision the evidence doesn't hold.
|
|
12
|
+
* Tolerate-and-degrade like every optional artifact: a machine without the DBs answers undefined
|
|
13
|
+
* everywhere and the consumer simply doesn't decorate.
|
|
14
|
+
*/
|
|
15
|
+
export type LocalityPostcodeLookup = (wofID: number, countryCode: string | null) => string | undefined;
|
|
16
|
+
export declare function createLocalityPostcodeLookup(): LocalityPostcodeLookup;
|
|
17
|
+
//# sourceMappingURL=locality-postcode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"locality-postcode.d.ts","sourceRoot":"","sources":["../locality-postcode.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAYH,MAAM,MAAM,sBAAsB,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,IAAI,KAAK,MAAM,GAAG,SAAS,CAAA;AAEtG,wBAAgB,4BAA4B,IAAI,sBAAsB,CAyCrE"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* Reverse lookup over the `postcode-locality-*.db` artifacts: the CONTAINING postcode of a
|
|
7
|
+
* resolved locality, keyed by its WOF id — no name matching. Serves the drop-ins' answer
|
|
8
|
+
* enrichment: a village answer carries the postcode the gazetteer attests for it.
|
|
9
|
+
*
|
|
10
|
+
* The exactly-one rule is the abstention: a locality contained by several postcodes (any real
|
|
11
|
+
* city) gets NOTHING — emitting one of many would state a precision the evidence doesn't hold.
|
|
12
|
+
* Tolerate-and-degrade like every optional artifact: a machine without the DBs answers undefined
|
|
13
|
+
* everywhere and the consumer simply doesn't decorate.
|
|
14
|
+
*/
|
|
15
|
+
import { existsSync } from "node:fs";
|
|
16
|
+
import { DatabaseSync } from "node:sqlite";
|
|
17
|
+
import { dataRootPath } from "@mailwoman/core/utils";
|
|
18
|
+
/**
|
|
19
|
+
* The per-country artifacts, probed in caller-country order with `intl` as the shared fallback.
|
|
20
|
+
*/
|
|
21
|
+
const POSTCODE_LOCALITY_SUFFIXES = ["fr", "de", "jp", "intl"];
|
|
22
|
+
export function createLocalityPostcodeLookup() {
|
|
23
|
+
const statements = new Map();
|
|
24
|
+
for (const suffix of POSTCODE_LOCALITY_SUFFIXES) {
|
|
25
|
+
const path = String(dataRootPath("wof", `postcode-locality-${suffix}.db`));
|
|
26
|
+
if (!existsSync(path))
|
|
27
|
+
continue;
|
|
28
|
+
try {
|
|
29
|
+
const db = new DatabaseSync(path, { readOnly: true });
|
|
30
|
+
// No `is_containing` filter: villages routinely carry 0 (the builder's containment test is
|
|
31
|
+
// distance-classified, and a village near its postcode centroid still has exactly one code).
|
|
32
|
+
// The exactly-one DISTINCT rule below is the entire ambiguity guard.
|
|
33
|
+
statements.set(suffix, db.prepare(`SELECT DISTINCT postcode FROM postcode_locality WHERE locality_id = ? LIMIT 2`));
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
// A torn or foreign file degrades to no enrichment, never a crash at serve start.
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return (wofID, countryCode) => {
|
|
40
|
+
const cc = countryCode?.toLowerCase();
|
|
41
|
+
const order = cc && statements.has(cc) ? [cc, "intl"] : ["intl"];
|
|
42
|
+
for (const suffix of order) {
|
|
43
|
+
const stmt = statements.get(suffix);
|
|
44
|
+
if (!stmt)
|
|
45
|
+
continue;
|
|
46
|
+
const rows = stmt.all(wofID);
|
|
47
|
+
if (rows.length === 1)
|
|
48
|
+
return rows[0].postcode;
|
|
49
|
+
if (rows.length > 1)
|
|
50
|
+
return undefined; // ambiguous — abstain, never guess
|
|
51
|
+
}
|
|
52
|
+
return undefined;
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=locality-postcode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"locality-postcode.js","sourceRoot":"","sources":["../locality-postcode.ts"],"names":[],"mappings":"AAAA;;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,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,SAAS,CAAA,CAAC,mCAAmC;QAC1E,CAAC;QAED,OAAO,SAAS,CAAA;IACjB,CAAC,CAAA;AACF,CAAC"}
|
package/out/routes.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../routes.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAe,KAAK,WAAW,EAAK,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../routes.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAe,KAAK,WAAW,EAAK,MAAM,mBAAmB,CAAA;AAGpE,OAAO,KAAK,EAAE,YAAY,EAAoE,MAAM,aAAa,CAAA;AAyHjH;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,WAAW,EAAE,MAAM,EAAE,YAAY,GAAG,IAAI,CA6DjF"}
|
package/out/routes.js
CHANGED
|
@@ -71,7 +71,7 @@ footer { margin-top: 2rem; font-size: .9rem; opacity: .8 }
|
|
|
71
71
|
<li><a class="q" href="/api?q=1600+pennsylvania+ave&limit=1">/api?q=1600+pennsylvania+ave&limit=1</a></li>
|
|
72
72
|
<li><a class="q" href="/reverse?lat=52.52&lon=13.405">/reverse?lat=52.52&lon=13.405</a></li>
|
|
73
73
|
</ul>
|
|
74
|
-
<footer><a href="https://mailwoman.
|
|
74
|
+
<footer><a href="https://mailwoman.ai/docs/developers/get-started/what-mailwoman-is">What Mailwoman is</a> · <a href="https://mailwoman.ai/demo">Live demo</a></footer>
|
|
75
75
|
</body>
|
|
76
76
|
</html>
|
|
77
77
|
`;
|
|
@@ -136,10 +136,7 @@ export function registerPhotonRoutes(app, engine) {
|
|
|
136
136
|
layer: asStringArray(q["layer"]),
|
|
137
137
|
};
|
|
138
138
|
const collection = await engine.search(params);
|
|
139
|
-
// #1052: `format=jsonld` re-serializes the SAME FeatureCollection as schema.org `Place[]` JSON-LD.
|
|
140
|
-
// declared 200 schema documents only the FeatureCollection shape (matching the legacy yaml); the
|
|
141
|
-
// jsonld branch's differing runtime shape is a local cast at the boundary,
|
|
142
|
-
// never a wire-behavior change (api-kit's `openapi.ts` sets the precedent for this idiom).
|
|
139
|
+
// #1052: `format=jsonld` re-serializes the SAME FeatureCollection as schema.org `Place[]` JSON-LD.
|
|
143
140
|
if (asString(q["format"]) === "jsonld") {
|
|
144
141
|
return c.json(photonToSchemaOrg(collection), 200);
|
|
145
142
|
}
|
|
@@ -165,8 +162,7 @@ export function registerPhotonRoutes(app, engine) {
|
|
|
165
162
|
radius: q["radius"] != null ? Number(q["radius"]) : undefined,
|
|
166
163
|
};
|
|
167
164
|
const collection = await engine.reverse(params);
|
|
168
|
-
// #1052: `format=jsonld` re-serializes the reverse FeatureCollection as schema.org `Place[]` JSON-LD.
|
|
169
|
-
// the search handler's comment above for why this is a local cast, not a wire-behavior change.
|
|
165
|
+
// #1052: `format=jsonld` re-serializes the reverse FeatureCollection as schema.org `Place[]` JSON-LD.
|
|
170
166
|
if (asString(q["format"]) === "jsonld") {
|
|
171
167
|
return c.json(photonToSchemaOrg(collection), 200);
|
|
172
168
|
}
|
package/out/routes.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routes.js","sourceRoot":"","sources":["../routes.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,WAAW,EAAoB,CAAC,EAAE,MAAM,mBAAmB,CAAA;AACpE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GAAG,CAAC,CAAA;QACtE,CAAC;QAED,IAAI,GAAG,GAAG,YAAY,IAAI,GAAG,GAAG,YAAY,IAAI,GAAG,GAAG,aAAa,IAAI,GAAG,GAAG,aAAa,EAAE,CAAC;YAC5F,OAAO,CAAC,CAAC,IAAI,CAAC,EAAE,GAAG,KAAK,EAAE,OAAO,EAAE,iDAAiD,EAAE,EAAE,GAAG,CAAC,CAAA;QAC7F,CAAC;QAED,MAAM,MAAM,GAAwB;YACnC,GAAG;YACH,GAAG;YACH,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,aAAa,CAAC,IAAI,aAAa;YAC3D,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;YACzB,MAAM,EAAE,CAAC,CAAC,QAAQ,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS;SAC7D,CAAA;QAED,MAAM,UAAU,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;QAE/C,sGAAsG;QACtG,IAAI,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,KAAK,QAAQ,EAAE,CAAC;YACxC,OAAO,CAAC,CAAC,IAAI,CAAC,iBAAiB,CAAC,UAAU,CAAC,EAAE,GAAG,CAAC,CAAA;QAClD,CAAC;QAED,OAAO,CAAC,CAAC,IAAI,CAAC,UAAU,EAAE,GAAG,CAAC,CAAA;IAC/B,CAAC,CAAC,CAAA;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mailwoman/photon",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.2.0",
|
|
4
4
|
"description": "Photon drop-in — a Photon-compatible autocomplete/type-ahead geocoding API (GeoJSON FeatureCollection over /api + /reverse) on the Mailwoman engine. Run it with `npx @mailwoman/photon serve`.",
|
|
5
5
|
"license": "AGPL-3.0-only OR LicenseRef-Commercial",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "https://github.com/sister-software/mailwoman.git",
|
|
9
|
-
"directory": "photon"
|
|
9
|
+
"directory": "packages/photon"
|
|
10
10
|
},
|
|
11
11
|
"bin": "./out/cli.js",
|
|
12
12
|
"files": [
|
|
@@ -22,9 +22,13 @@
|
|
|
22
22
|
"!*.test.ts",
|
|
23
23
|
"!*.test.tsx",
|
|
24
24
|
"!**/*.test.ts",
|
|
25
|
-
"!**/*.test.tsx"
|
|
25
|
+
"!**/*.test.tsx",
|
|
26
|
+
"!test/**"
|
|
26
27
|
],
|
|
27
28
|
"type": "module",
|
|
29
|
+
"imports": {
|
|
30
|
+
"#package.json": "./package.json"
|
|
31
|
+
},
|
|
28
32
|
"exports": {
|
|
29
33
|
"./package.json": "./package.json",
|
|
30
34
|
".": {
|
|
@@ -40,20 +44,24 @@
|
|
|
40
44
|
"types": "./out/index.d.ts",
|
|
41
45
|
"default": "./out/index.js"
|
|
42
46
|
}
|
|
47
|
+
},
|
|
48
|
+
"imports": {
|
|
49
|
+
"#package.json": "./package.json"
|
|
43
50
|
}
|
|
44
51
|
},
|
|
45
52
|
"dependencies": {
|
|
46
53
|
"@hono/zod-openapi": "^1.5.1",
|
|
47
|
-
"@mailwoman/annotations": "9.
|
|
48
|
-
"@mailwoman/api-kit": "9.
|
|
49
|
-
"@mailwoman/ban": "9.
|
|
50
|
-
"@mailwoman/codex": "9.
|
|
51
|
-
"@mailwoman/
|
|
52
|
-
"@mailwoman/neural
|
|
53
|
-
"@mailwoman/
|
|
54
|
-
"@mailwoman/resolver
|
|
55
|
-
"
|
|
56
|
-
"
|
|
54
|
+
"@mailwoman/annotations": "9.2.0",
|
|
55
|
+
"@mailwoman/api-kit": "9.2.0",
|
|
56
|
+
"@mailwoman/ban": "9.2.0",
|
|
57
|
+
"@mailwoman/codex": "9.2.0",
|
|
58
|
+
"@mailwoman/core": "9.2.0",
|
|
59
|
+
"@mailwoman/neural": "9.2.0",
|
|
60
|
+
"@mailwoman/neural-weights-en-us": "9.2.0",
|
|
61
|
+
"@mailwoman/resolver": "9.2.0",
|
|
62
|
+
"@mailwoman/resolver-wof-sqlite": "9.2.0",
|
|
63
|
+
"hono": "^4.13.0",
|
|
64
|
+
"mailwoman": "9.2.0",
|
|
57
65
|
"zod": "^4.4.3"
|
|
58
66
|
}
|
|
59
67
|
}
|
package/routes.ts
CHANGED
|
@@ -10,7 +10,6 @@
|
|
|
10
10
|
|
|
11
11
|
import { createRoute, type OpenAPIHono, z } from "@hono/zod-openapi"
|
|
12
12
|
import { legacyQuery } from "@mailwoman/api-kit"
|
|
13
|
-
import type { Context } from "hono"
|
|
14
13
|
|
|
15
14
|
import type { PhotonEngine, PhotonFeatureCollection, PhotonReverseParams, PhotonSearchParams } from "./engine.ts"
|
|
16
15
|
import { photonToSchemaOrg } from "./projection.ts"
|
|
@@ -84,7 +83,7 @@ footer { margin-top: 2rem; font-size: .9rem; opacity: .8 }
|
|
|
84
83
|
<li><a class="q" href="/api?q=1600+pennsylvania+ave&limit=1">/api?q=1600+pennsylvania+ave&limit=1</a></li>
|
|
85
84
|
<li><a class="q" href="/reverse?lat=52.52&lon=13.405">/reverse?lat=52.52&lon=13.405</a></li>
|
|
86
85
|
</ul>
|
|
87
|
-
<footer><a href="https://mailwoman.
|
|
86
|
+
<footer><a href="https://mailwoman.ai/docs/developers/get-started/what-mailwoman-is">What Mailwoman is</a> · <a href="https://mailwoman.ai/demo">Live demo</a></footer>
|
|
88
87
|
</body>
|
|
89
88
|
</html>
|
|
90
89
|
`
|
|
@@ -158,12 +157,9 @@ export function registerPhotonRoutes(app: OpenAPIHono, engine: PhotonEngine): vo
|
|
|
158
157
|
|
|
159
158
|
const collection = await engine.search(params)
|
|
160
159
|
|
|
161
|
-
// #1052: `format=jsonld` re-serializes the SAME FeatureCollection as schema.org `Place[]` JSON-LD.
|
|
162
|
-
// declared 200 schema documents only the FeatureCollection shape (matching the legacy yaml); the
|
|
163
|
-
// jsonld branch's differing runtime shape is a local cast at the boundary,
|
|
164
|
-
// never a wire-behavior change (api-kit's `openapi.ts` sets the precedent for this idiom).
|
|
160
|
+
// #1052: `format=jsonld` re-serializes the SAME FeatureCollection as schema.org `Place[]` JSON-LD.
|
|
165
161
|
if (asString(q["format"]) === "jsonld") {
|
|
166
|
-
return c.json(photonToSchemaOrg(collection)
|
|
162
|
+
return c.json(photonToSchemaOrg(collection), 200)
|
|
167
163
|
}
|
|
168
164
|
|
|
169
165
|
return c.json(collection, 200)
|
|
@@ -193,10 +189,9 @@ export function registerPhotonRoutes(app: OpenAPIHono, engine: PhotonEngine): vo
|
|
|
193
189
|
|
|
194
190
|
const collection = await engine.reverse(params)
|
|
195
191
|
|
|
196
|
-
// #1052: `format=jsonld` re-serializes the reverse FeatureCollection as schema.org `Place[]` JSON-LD.
|
|
197
|
-
// the search handler's comment above for why this is a local cast, not a wire-behavior change.
|
|
192
|
+
// #1052: `format=jsonld` re-serializes the reverse FeatureCollection as schema.org `Place[]` JSON-LD.
|
|
198
193
|
if (asString(q["format"]) === "jsonld") {
|
|
199
|
-
return c.json(photonToSchemaOrg(collection)
|
|
194
|
+
return c.json(photonToSchemaOrg(collection), 200)
|
|
200
195
|
}
|
|
201
196
|
|
|
202
197
|
return c.json(collection, 200)
|