@mailwoman/photon 8.6.0 → 9.1.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 +4 -5
- package/app.ts +2 -2
- package/cli.ts +30 -97
- package/out/app.js +2 -2
- package/out/app.js.map +1 -1
- package/out/cli.js +20 -75
- package/out/cli.js.map +1 -1
- package/out/routes.d.ts.map +1 -1
- package/out/routes.js +4 -19
- package/out/routes.js.map +1 -1
- package/package.json +11 -11
- package/routes.ts +4 -22
package/README.md
CHANGED
|
@@ -3,14 +3,13 @@
|
|
|
3
3
|
A **Photon-compatible autocomplete geocoding API** over the [Mailwoman](https://mailwoman.sister.software) 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
|
-
# One-time data fetch (worldwide candidate gazetteer, ~1.
|
|
7
|
-
|
|
8
|
-
curl -fSL https://public.sister.software/mailwoman/gazetteer/2026-07-07a/candidate.db \
|
|
9
|
-
-o "${MAILWOMAN_DATA_ROOT:-/tmp/mailwoman-data}/wof/candidate.db"
|
|
6
|
+
# One-time data fetch (worldwide candidate gazetteer, population-first ranking, ~1.65 GB):
|
|
7
|
+
MAILWOMAN_DATA_ROOT="${MAILWOMAN_DATA_ROOT:-/tmp/mailwoman-data}" npx mailwoman data pull candidate
|
|
10
8
|
|
|
11
9
|
MAILWOMAN_DATA_ROOT="${MAILWOMAN_DATA_ROOT:-/tmp/mailwoman-data}" \
|
|
12
10
|
npx @mailwoman/photon serve --port 2322
|
|
13
|
-
#
|
|
11
|
+
# The pulled candidate.db is auto-detected at $MAILWOMAN_DATA_ROOT/wof/candidate.db — no export needed.
|
|
12
|
+
# Or point at your own data: --candidate-db <path> / $MAILWOMAN_CANDIDATE_DB
|
|
14
13
|
```
|
|
15
14
|
|
|
16
15
|
Prefer to try before self-hosting? A hosted trial endpoint runs at
|
package/app.ts
CHANGED
|
@@ -40,8 +40,8 @@ export const PHOTON_DOC_INFO: OpenAPIDocInfo = {
|
|
|
40
40
|
license: { name: "AGPL-3.0-only OR LicenseRef-Commercial", identifier: "AGPL-3.0-only" },
|
|
41
41
|
contact: { name: "Sister Software", url: "https://mailwoman.sister.software" },
|
|
42
42
|
externalDocs: {
|
|
43
|
-
description: "
|
|
44
|
-
url: "https://mailwoman.sister.software/docs/
|
|
43
|
+
description: "What Mailwoman is",
|
|
44
|
+
url: "https://mailwoman.sister.software/docs/developers/get-started/what-mailwoman-is",
|
|
45
45
|
},
|
|
46
46
|
servers: [
|
|
47
47
|
{
|
package/cli.ts
CHANGED
|
@@ -14,21 +14,21 @@
|
|
|
14
14
|
* autocomplete tier is the eventual front for `/api`; geocode resolution is the MVP path.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
import { existsSync } from "node:fs"
|
|
18
|
-
import { join } from "node:path"
|
|
19
17
|
import { parseArgs } from "node:util"
|
|
20
18
|
|
|
21
19
|
import { printOpenAPIDocument, serveNode } from "@mailwoman/api-kit"
|
|
22
20
|
import { matchCountry } from "@mailwoman/codex/country"
|
|
23
|
-
import { NeuralAddressClassifier } from "@mailwoman/neural"
|
|
24
21
|
import { createWOFResolver } from "@mailwoman/resolver"
|
|
25
|
-
import { geocodeAddress, ShardProvider } from "mailwoman/geocode-core"
|
|
26
22
|
import {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
23
|
+
corsBannerLine,
|
|
24
|
+
gazetteerBannerLines,
|
|
25
|
+
loadClassifierOrExit,
|
|
26
|
+
parseOpenAPIFlags,
|
|
27
|
+
resolveGazetteerOrExit,
|
|
28
|
+
runDropInCLI,
|
|
29
|
+
} from "mailwoman/cli-kit/dropin"
|
|
30
|
+
import { geocodeAddress, ShardProvider } from "mailwoman/geocode-core"
|
|
31
|
+
import { createResolverBackend, mailwomanDataRoot } from "mailwoman/resolver-backend"
|
|
32
32
|
|
|
33
33
|
import {
|
|
34
34
|
createPhotonApp,
|
|
@@ -59,6 +59,8 @@ const PLACETYPE_TO_KEY: Record<string, keyof PhotonProperties> = {
|
|
|
59
59
|
*/
|
|
60
60
|
const MAX_QUERY_LEN = 512
|
|
61
61
|
|
|
62
|
+
const BINARY_NAME = "mailwoman-photon"
|
|
63
|
+
|
|
62
64
|
async function serve(): Promise<void> {
|
|
63
65
|
const { values } = parseArgs({
|
|
64
66
|
options: {
|
|
@@ -77,52 +79,10 @@ async function serve(): Promise<void> {
|
|
|
77
79
|
const host = values.host ?? "0.0.0.0"
|
|
78
80
|
|
|
79
81
|
const resolverMod = await import("@mailwoman/resolver-wof-sqlite")
|
|
80
|
-
const
|
|
81
|
-
const adminDBPath =
|
|
82
|
-
|
|
83
|
-
// Candidate gazetteer = worldwide resolution (see @mailwoman/nominatim). --candidate-db /
|
|
84
|
-
// $MAILWOMAN_CANDIDATE_DB, else auto-use one fetched to `<data-root>/wof/candidate.db`; absent → admin-only.
|
|
85
|
-
const conventionCandidate = join(mailwomanDataRoot(), "wof", "candidate.db")
|
|
86
|
-
|
|
87
|
-
// #1009 kin: an EXPLICIT --candidate-db that doesn't exist must error loudly, not silently fall
|
|
88
|
-
// back to whatever ambient data-root file happens to be present (a typo'd path would serve the
|
|
89
|
-
// wrong gazetteer without a word).
|
|
90
|
-
if (values["candidate-db"] && !existsSync(values["candidate-db"])) {
|
|
91
|
-
console.error(`✗ --candidate-db not found: ${values["candidate-db"]}`)
|
|
92
|
-
|
|
93
|
-
process.exit(1)
|
|
94
|
-
}
|
|
82
|
+
const gazetteer = resolveGazetteerOrExit(values["candidate-db"])
|
|
83
|
+
const { adminDBPath, candidateDb, wofPaths } = gazetteer
|
|
84
|
+
const classifier = await loadClassifierOrExit()
|
|
95
85
|
|
|
96
|
-
const candidateDb =
|
|
97
|
-
resolveCandidateDBPath(values["candidate-db"]) ??
|
|
98
|
-
(existsSync(conventionCandidate) ? conventionCandidate : undefined)
|
|
99
|
-
|
|
100
|
-
// #1009: fail FRIENDLY before the resolver throws its internal "resolveShards: at least one shard
|
|
101
|
-
// is required" — a stranger's first `npx @mailwoman/photon serve` must say exactly what data is
|
|
102
|
-
// missing and the one command that fixes it. Kept in sync with the docs' hosted-artifact layout
|
|
103
|
-
// (mailwoman.sister.software/docs/switching/photon — the maintained pointer).
|
|
104
|
-
if (!candidateDb && !wofPaths.length) {
|
|
105
|
-
console.error(
|
|
106
|
-
[
|
|
107
|
-
"✗ no gazetteer data found — the endpoint needs a resolver database to answer queries.",
|
|
108
|
-
"",
|
|
109
|
-
" Fastest path (worldwide resolution, ~1.4 GB, byte-range friendly):",
|
|
110
|
-
` mkdir -p ${join(mailwomanDataRoot(), "wof")}`,
|
|
111
|
-
` curl -fSL https://public.sister.software/mailwoman/gazetteer/2026-07-07a/candidate.db \\`,
|
|
112
|
-
` -o ${conventionCandidate}`,
|
|
113
|
-
"",
|
|
114
|
-
" Then re-run `serve` (the file is auto-detected at that path), or point at your own:",
|
|
115
|
-
" --candidate-db <path> / $MAILWOMAN_CANDIDATE_DB (candidate gazetteer)",
|
|
116
|
-
" $MAILWOMAN_WOF_DB / <data-root>/wof/*.db (admin WOF distribution)",
|
|
117
|
-
"",
|
|
118
|
-
" Docs: https://mailwoman.sister.software/docs/switching/photon",
|
|
119
|
-
].join("\n")
|
|
120
|
-
)
|
|
121
|
-
|
|
122
|
-
process.exit(1)
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
const classifier = await NeuralAddressClassifier.loadFromWeights({ locale: "en-US" })
|
|
126
86
|
const backend = createResolverBackend(resolverMod, { wofPaths, candidateDb })
|
|
127
87
|
const resolver = createWOFResolver(backend)
|
|
128
88
|
const shards = new ShardProvider(resolverMod, mailwomanDataRoot())
|
|
@@ -230,13 +190,12 @@ async function serve(): Promise<void> {
|
|
|
230
190
|
hostname: host,
|
|
231
191
|
onListen: () => {
|
|
232
192
|
console.error(`[@mailwoman/photon] listening on http://${host}:${port}`)
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
)
|
|
239
|
-
console.error(` cors: ${values.cors ? "enabled (Access-Control-Allow-Origin: *)" : "disabled (--no-cors)"}`)
|
|
193
|
+
|
|
194
|
+
for (const line of gazetteerBannerLines(gazetteer)) {
|
|
195
|
+
console.error(line)
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
console.error(corsBannerLine(values.cors))
|
|
240
199
|
console.error(` endpoints: GET / GET /api GET /reverse GET /openapi.json`)
|
|
241
200
|
},
|
|
242
201
|
})
|
|
@@ -250,43 +209,17 @@ async function serve(): Promise<void> {
|
|
|
250
209
|
* the default 3.1.0.
|
|
251
210
|
*/
|
|
252
211
|
function openapi(): void {
|
|
253
|
-
const { values } = parseArgs({
|
|
254
|
-
options: {
|
|
255
|
-
flavor: { type: "string", default: "3.1" },
|
|
256
|
-
out: { type: "string" },
|
|
257
|
-
},
|
|
258
|
-
allowPositionals: true,
|
|
259
|
-
})
|
|
260
|
-
|
|
261
|
-
if (values.flavor !== "3.1" && values.flavor !== "3.0") {
|
|
262
|
-
console.error(`✗ --flavor must be "3.1" or "3.0" (got "${values.flavor}")`)
|
|
263
|
-
console.error("Usage: mailwoman-photon openapi [--flavor 3.1|3.0] [--out <path>]")
|
|
264
|
-
|
|
265
|
-
process.exit(1)
|
|
266
|
-
}
|
|
267
|
-
|
|
268
212
|
const app = createPhotonApp({})
|
|
269
213
|
|
|
270
|
-
printOpenAPIDocument(app, PHOTON_DOC_INFO,
|
|
214
|
+
printOpenAPIDocument(app, PHOTON_DOC_INFO, parseOpenAPIFlags(BINARY_NAME))
|
|
271
215
|
}
|
|
272
216
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
break
|
|
283
|
-
default:
|
|
284
|
-
console.error(
|
|
285
|
-
[
|
|
286
|
-
"Usage: mailwoman-photon <command>",
|
|
287
|
-
" serve [--port 2322] [--host 0.0.0.0] [--candidate-db <path>] [--no-cors]",
|
|
288
|
-
" openapi [--flavor 3.1|3.0] [--out <path>]",
|
|
289
|
-
].join("\n")
|
|
290
|
-
)
|
|
291
|
-
process.exit(command ? 1 : 0)
|
|
292
|
-
}
|
|
217
|
+
await runDropInCLI({
|
|
218
|
+
binaryName: BINARY_NAME,
|
|
219
|
+
openapi,
|
|
220
|
+
serve,
|
|
221
|
+
usage: [
|
|
222
|
+
" serve [--port 2322] [--host 0.0.0.0] [--candidate-db <path>] [--no-cors]",
|
|
223
|
+
" openapi [--flavor 3.1|3.0] [--out <path>]",
|
|
224
|
+
],
|
|
225
|
+
})
|
package/out/app.js
CHANGED
|
@@ -23,8 +23,8 @@ export const PHOTON_DOC_INFO = {
|
|
|
23
23
|
license: { name: "AGPL-3.0-only OR LicenseRef-Commercial", identifier: "AGPL-3.0-only" },
|
|
24
24
|
contact: { name: "Sister Software", url: "https://mailwoman.sister.software" },
|
|
25
25
|
externalDocs: {
|
|
26
|
-
description: "
|
|
27
|
-
url: "https://mailwoman.sister.software/docs/
|
|
26
|
+
description: "What Mailwoman is",
|
|
27
|
+
url: "https://mailwoman.sister.software/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,WAAW,MAAM,gCAAgC,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAA;AAC9E,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAGhC,OAAO,EAAE,oBAAoB,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AAE,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
|
@@ -13,15 +13,13 @@
|
|
|
13
13
|
* `WOFReverseGeocoder`, projecting results into Photon's GeoJSON FeatureCollection. The FST
|
|
14
14
|
* autocomplete tier is the eventual front for `/api`; geocode resolution is the MVP path.
|
|
15
15
|
*/
|
|
16
|
-
import { existsSync } from "node:fs";
|
|
17
|
-
import { join } from "node:path";
|
|
18
16
|
import { parseArgs } from "node:util";
|
|
19
17
|
import { printOpenAPIDocument, serveNode } from "@mailwoman/api-kit";
|
|
20
18
|
import { matchCountry } from "@mailwoman/codex/country";
|
|
21
|
-
import { NeuralAddressClassifier } from "@mailwoman/neural";
|
|
22
19
|
import { createWOFResolver } from "@mailwoman/resolver";
|
|
20
|
+
import { corsBannerLine, gazetteerBannerLines, loadClassifierOrExit, parseOpenAPIFlags, resolveGazetteerOrExit, runDropInCLI, } from "mailwoman/cli-kit/dropin";
|
|
23
21
|
import { geocodeAddress, ShardProvider } from "mailwoman/geocode-core";
|
|
24
|
-
import { createResolverBackend, mailwomanDataRoot
|
|
22
|
+
import { createResolverBackend, mailwomanDataRoot } from "mailwoman/resolver-backend";
|
|
25
23
|
import { createPhotonApp, PHOTON_DOC_INFO, photonCollection, photonFeature, photonForwardCollection, photonOSMTags, } from "./index.js";
|
|
26
24
|
/**
|
|
27
25
|
* WOF placetype → Photon property key.
|
|
@@ -38,6 +36,7 @@ const PLACETYPE_TO_KEY = {
|
|
|
38
36
|
* A real address fits comfortably; longer is malformed input (and would exceed the model's window).
|
|
39
37
|
*/
|
|
40
38
|
const MAX_QUERY_LEN = 512;
|
|
39
|
+
const BINARY_NAME = "mailwoman-photon";
|
|
41
40
|
async function serve() {
|
|
42
41
|
const { values } = parseArgs({
|
|
43
42
|
options: {
|
|
@@ -54,42 +53,9 @@ async function serve() {
|
|
|
54
53
|
const port = Number(values.port) || 2322;
|
|
55
54
|
const host = values.host ?? "0.0.0.0";
|
|
56
55
|
const resolverMod = await import("@mailwoman/resolver-wof-sqlite");
|
|
57
|
-
const
|
|
58
|
-
const adminDBPath =
|
|
59
|
-
|
|
60
|
-
// $MAILWOMAN_CANDIDATE_DB, else auto-use one fetched to `<data-root>/wof/candidate.db`; absent → admin-only.
|
|
61
|
-
const conventionCandidate = join(mailwomanDataRoot(), "wof", "candidate.db");
|
|
62
|
-
// #1009 kin: an EXPLICIT --candidate-db that doesn't exist must error loudly, not silently fall
|
|
63
|
-
// back to whatever ambient data-root file happens to be present (a typo'd path would serve the
|
|
64
|
-
// wrong gazetteer without a word).
|
|
65
|
-
if (values["candidate-db"] && !existsSync(values["candidate-db"])) {
|
|
66
|
-
console.error(`✗ --candidate-db not found: ${values["candidate-db"]}`);
|
|
67
|
-
process.exit(1);
|
|
68
|
-
}
|
|
69
|
-
const candidateDb = resolveCandidateDBPath(values["candidate-db"]) ??
|
|
70
|
-
(existsSync(conventionCandidate) ? conventionCandidate : undefined);
|
|
71
|
-
// #1009: fail FRIENDLY before the resolver throws its internal "resolveShards: at least one shard
|
|
72
|
-
// is required" — a stranger's first `npx @mailwoman/photon serve` must say exactly what data is
|
|
73
|
-
// missing and the one command that fixes it. Kept in sync with the docs' hosted-artifact layout
|
|
74
|
-
// (mailwoman.sister.software/docs/switching/photon — the maintained pointer).
|
|
75
|
-
if (!candidateDb && !wofPaths.length) {
|
|
76
|
-
console.error([
|
|
77
|
-
"✗ no gazetteer data found — the endpoint needs a resolver database to answer queries.",
|
|
78
|
-
"",
|
|
79
|
-
" Fastest path (worldwide resolution, ~1.4 GB, byte-range friendly):",
|
|
80
|
-
` mkdir -p ${join(mailwomanDataRoot(), "wof")}`,
|
|
81
|
-
` curl -fSL https://public.sister.software/mailwoman/gazetteer/2026-07-07a/candidate.db \\`,
|
|
82
|
-
` -o ${conventionCandidate}`,
|
|
83
|
-
"",
|
|
84
|
-
" Then re-run `serve` (the file is auto-detected at that path), or point at your own:",
|
|
85
|
-
" --candidate-db <path> / $MAILWOMAN_CANDIDATE_DB (candidate gazetteer)",
|
|
86
|
-
" $MAILWOMAN_WOF_DB / <data-root>/wof/*.db (admin WOF distribution)",
|
|
87
|
-
"",
|
|
88
|
-
" Docs: https://mailwoman.sister.software/docs/switching/photon",
|
|
89
|
-
].join("\n"));
|
|
90
|
-
process.exit(1);
|
|
91
|
-
}
|
|
92
|
-
const classifier = await NeuralAddressClassifier.loadFromWeights({ locale: "en-US" });
|
|
56
|
+
const gazetteer = resolveGazetteerOrExit(values["candidate-db"]);
|
|
57
|
+
const { adminDBPath, candidateDb, wofPaths } = gazetteer;
|
|
58
|
+
const classifier = await loadClassifierOrExit();
|
|
93
59
|
const backend = createResolverBackend(resolverMod, { wofPaths, candidateDb });
|
|
94
60
|
const resolver = createWOFResolver(backend);
|
|
95
61
|
const shards = new ShardProvider(resolverMod, mailwomanDataRoot());
|
|
@@ -185,11 +151,10 @@ async function serve() {
|
|
|
185
151
|
hostname: host,
|
|
186
152
|
onListen: () => {
|
|
187
153
|
console.error(`[@mailwoman/photon] listening on http://${host}:${port}`);
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
console.error(` cors: ${values.cors ? "enabled (Access-Control-Allow-Origin: *)" : "disabled (--no-cors)"}`);
|
|
154
|
+
for (const line of gazetteerBannerLines(gazetteer)) {
|
|
155
|
+
console.error(line);
|
|
156
|
+
}
|
|
157
|
+
console.error(corsBannerLine(values.cors));
|
|
193
158
|
console.error(` endpoints: GET / GET /api GET /reverse GET /openapi.json`);
|
|
194
159
|
},
|
|
195
160
|
});
|
|
@@ -202,36 +167,16 @@ async function serve() {
|
|
|
202
167
|
* the default 3.1.0.
|
|
203
168
|
*/
|
|
204
169
|
function openapi() {
|
|
205
|
-
const { values } = parseArgs({
|
|
206
|
-
options: {
|
|
207
|
-
flavor: { type: "string", default: "3.1" },
|
|
208
|
-
out: { type: "string" },
|
|
209
|
-
},
|
|
210
|
-
allowPositionals: true,
|
|
211
|
-
});
|
|
212
|
-
if (values.flavor !== "3.1" && values.flavor !== "3.0") {
|
|
213
|
-
console.error(`✗ --flavor must be "3.1" or "3.0" (got "${values.flavor}")`);
|
|
214
|
-
console.error("Usage: mailwoman-photon openapi [--flavor 3.1|3.0] [--out <path>]");
|
|
215
|
-
process.exit(1);
|
|
216
|
-
}
|
|
217
170
|
const app = createPhotonApp({});
|
|
218
|
-
printOpenAPIDocument(app, PHOTON_DOC_INFO,
|
|
219
|
-
}
|
|
220
|
-
// Subcommand dispatch via parseArgs (strict:false — the per-command parsers own their flags).
|
|
221
|
-
const command = parseArgs({ strict: false, allowPositionals: true }).positionals[0];
|
|
222
|
-
switch (command) {
|
|
223
|
-
case "serve":
|
|
224
|
-
await serve();
|
|
225
|
-
break;
|
|
226
|
-
case "openapi":
|
|
227
|
-
openapi();
|
|
228
|
-
break;
|
|
229
|
-
default:
|
|
230
|
-
console.error([
|
|
231
|
-
"Usage: mailwoman-photon <command>",
|
|
232
|
-
" serve [--port 2322] [--host 0.0.0.0] [--candidate-db <path>] [--no-cors]",
|
|
233
|
-
" openapi [--flavor 3.1|3.0] [--out <path>]",
|
|
234
|
-
].join("\n"));
|
|
235
|
-
process.exit(command ? 1 : 0);
|
|
171
|
+
printOpenAPIDocument(app, PHOTON_DOC_INFO, parseOpenAPIFlags(BINARY_NAME));
|
|
236
172
|
}
|
|
173
|
+
await runDropInCLI({
|
|
174
|
+
binaryName: BINARY_NAME,
|
|
175
|
+
openapi,
|
|
176
|
+
serve,
|
|
177
|
+
usage: [
|
|
178
|
+
" serve [--port 2322] [--host 0.0.0.0] [--candidate-db <path>] [--no-cors]",
|
|
179
|
+
" openapi [--flavor 3.1|3.0] [--out <path>]",
|
|
180
|
+
],
|
|
181
|
+
});
|
|
237
182
|
//# sourceMappingURL=cli.js.map
|
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,
|
|
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,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,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"}
|
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;AAIpE,OAAO,KAAK,EAAE,YAAY,EAAoE,MAAM,aAAa,CAAA;AAyHjH;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,WAAW,EAAE,MAAM,EAAE,YAAY,GAAG,IAAI,CAiEjF"}
|
package/out/routes.js
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
* `legacyQuery` express-shaped view; the zod query schemas drive only the emitted document.
|
|
9
9
|
*/
|
|
10
10
|
import { createRoute, z } from "@hono/zod-openapi";
|
|
11
|
+
import { legacyQuery } from "@mailwoman/api-kit";
|
|
11
12
|
import { photonToSchemaOrg } from "./projection.js";
|
|
12
13
|
import { PhotonMessageCollectionSchema, PhotonResponseSchema, reverseQueryParams, searchQueryParams } from "./schema.js";
|
|
13
14
|
/**
|
|
@@ -37,22 +38,6 @@ function asStringArray(raw) {
|
|
|
37
38
|
const s = asString(raw);
|
|
38
39
|
return s ? [s] : undefined;
|
|
39
40
|
}
|
|
40
|
-
/**
|
|
41
|
-
* Express's `req.query` shape: `string` for a single value, `string[]` for repeats. The legacy parsing helpers
|
|
42
|
-
* (`asString`, `asStringArray`, `Number(...)`) — and their observable degenerate behaviors (repeated `q` → 400,
|
|
43
|
-
* repeated `lat` → NaN → 400) — key off exactly this shape, so the handlers consume it unchanged. Do NOT dedup or
|
|
44
|
-
* canonicalize here: photon's repeatable params (`osm_tag`, `layer`) are contract, and its duplicate-param 400s are
|
|
45
|
-
* contract too (unlike libpostal, where duplicates were never-contract — see the phase-1 adjudications).
|
|
46
|
-
* Null-prototype, matching express-simple's req.query shape (a repeated `?__proto__=` param must create an own
|
|
47
|
-
* property, not reparent the object).
|
|
48
|
-
*/
|
|
49
|
-
function legacyQuery(c) {
|
|
50
|
-
const out = Object.create(null);
|
|
51
|
-
for (const [key, values] of Object.entries(c.req.queries())) {
|
|
52
|
-
out[key] = values.length === 1 ? values[0] : values;
|
|
53
|
-
}
|
|
54
|
-
return out;
|
|
55
|
-
}
|
|
56
41
|
/**
|
|
57
42
|
* A friendly HTML landing page for `GET /` (#1022). Upstream komoot/photon serves no root page, so there's no wire
|
|
58
43
|
* contract to match — this is pure courtesy: a browser visitor (or an evaluator kicking the tires) who pastes the bare
|
|
@@ -86,7 +71,7 @@ footer { margin-top: 2rem; font-size: .9rem; opacity: .8 }
|
|
|
86
71
|
<li><a class="q" href="/api?q=1600+pennsylvania+ave&limit=1">/api?q=1600+pennsylvania+ave&limit=1</a></li>
|
|
87
72
|
<li><a class="q" href="/reverse?lat=52.52&lon=13.405">/reverse?lat=52.52&lon=13.405</a></li>
|
|
88
73
|
</ul>
|
|
89
|
-
<footer><a href="https://mailwoman.sister.software/docs/
|
|
74
|
+
<footer><a href="https://mailwoman.sister.software/docs/developers/get-started/what-mailwoman-is">What Mailwoman is</a> · <a href="https://mailwoman.sister.software/demo">Live demo</a></footer>
|
|
90
75
|
</body>
|
|
91
76
|
</html>
|
|
92
77
|
`;
|
|
@@ -152,8 +137,8 @@ export function registerPhotonRoutes(app, engine) {
|
|
|
152
137
|
};
|
|
153
138
|
const collection = await engine.search(params);
|
|
154
139
|
// #1052: `format=jsonld` re-serializes the SAME FeatureCollection as schema.org `Place[]` JSON-LD. The
|
|
155
|
-
// declared 200 schema documents only the FeatureCollection shape (matching the legacy yaml
|
|
156
|
-
//
|
|
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,
|
|
157
142
|
// never a wire-behavior change (api-kit's `openapi.ts` sets the precedent for this idiom).
|
|
158
143
|
if (asString(q["format"]) === "jsonld") {
|
|
159
144
|
return c.json(photonToSchemaOrg(collection), 200);
|
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;
|
|
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,OAAO,EAAE,WAAW,EAAE,MAAM,oBAA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AAK,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,0GAA0G;QAC1G,+FAA+F;QAC/F,IAAI,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,KAAK,QAAQ,EAAE,CAAC;YACxC,OAAO,CAAC,CAAC,IAAI,CAAC,iBAAiB,CAAC,UAAU,CAAU,EAAE,GAAG,CAAC,CAAA;QAC3D,CAAC;QAED,OAAO,CAAC,CAAC,IAAI,CAAC,UAAU,EAAE,GAAG,CAAC,CAAA;IAC/B,CAAC,CAAC,CAAA;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mailwoman/photon",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "9.1.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": {
|
|
@@ -44,16 +44,16 @@
|
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"@hono/zod-openapi": "^1.5.1",
|
|
47
|
-
"@mailwoman/annotations": "
|
|
48
|
-
"@mailwoman/api-kit": "
|
|
49
|
-
"@mailwoman/ban": "
|
|
50
|
-
"@mailwoman/codex": "
|
|
51
|
-
"@mailwoman/neural": "
|
|
52
|
-
"@mailwoman/neural-weights-en-us": "
|
|
53
|
-
"@mailwoman/resolver": "
|
|
54
|
-
"@mailwoman/resolver-wof-sqlite": "
|
|
55
|
-
"hono": "^4.
|
|
56
|
-
"mailwoman": "
|
|
47
|
+
"@mailwoman/annotations": "9.1.0",
|
|
48
|
+
"@mailwoman/api-kit": "9.1.0",
|
|
49
|
+
"@mailwoman/ban": "9.1.0",
|
|
50
|
+
"@mailwoman/codex": "9.1.0",
|
|
51
|
+
"@mailwoman/neural": "9.1.0",
|
|
52
|
+
"@mailwoman/neural-weights-en-us": "9.1.0",
|
|
53
|
+
"@mailwoman/resolver": "9.1.0",
|
|
54
|
+
"@mailwoman/resolver-wof-sqlite": "9.1.0",
|
|
55
|
+
"hono": "^4.13.0",
|
|
56
|
+
"mailwoman": "9.1.0",
|
|
57
57
|
"zod": "^4.4.3"
|
|
58
58
|
}
|
|
59
59
|
}
|
package/routes.ts
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
import { createRoute, type OpenAPIHono, z } from "@hono/zod-openapi"
|
|
12
|
+
import { legacyQuery } from "@mailwoman/api-kit"
|
|
12
13
|
import type { Context } from "hono"
|
|
13
14
|
|
|
14
15
|
import type { PhotonEngine, PhotonFeatureCollection, PhotonReverseParams, PhotonSearchParams } from "./engine.ts"
|
|
@@ -50,25 +51,6 @@ function asStringArray(raw: unknown): string[] | undefined {
|
|
|
50
51
|
return s ? [s] : undefined
|
|
51
52
|
}
|
|
52
53
|
|
|
53
|
-
/**
|
|
54
|
-
* Express's `req.query` shape: `string` for a single value, `string[]` for repeats. The legacy parsing helpers
|
|
55
|
-
* (`asString`, `asStringArray`, `Number(...)`) — and their observable degenerate behaviors (repeated `q` → 400,
|
|
56
|
-
* repeated `lat` → NaN → 400) — key off exactly this shape, so the handlers consume it unchanged. Do NOT dedup or
|
|
57
|
-
* canonicalize here: photon's repeatable params (`osm_tag`, `layer`) are contract, and its duplicate-param 400s are
|
|
58
|
-
* contract too (unlike libpostal, where duplicates were never-contract — see the phase-1 adjudications).
|
|
59
|
-
* Null-prototype, matching express-simple's req.query shape (a repeated `?__proto__=` param must create an own
|
|
60
|
-
* property, not reparent the object).
|
|
61
|
-
*/
|
|
62
|
-
function legacyQuery(c: Context): Record<string, string | string[]> {
|
|
63
|
-
const out: Record<string, string | string[]> = Object.create(null)
|
|
64
|
-
|
|
65
|
-
for (const [key, values] of Object.entries(c.req.queries())) {
|
|
66
|
-
out[key] = values.length === 1 ? values[0]! : values
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return out
|
|
70
|
-
}
|
|
71
|
-
|
|
72
54
|
/**
|
|
73
55
|
* A friendly HTML landing page for `GET /` (#1022). Upstream komoot/photon serves no root page, so there's no wire
|
|
74
56
|
* contract to match — this is pure courtesy: a browser visitor (or an evaluator kicking the tires) who pastes the bare
|
|
@@ -102,7 +84,7 @@ footer { margin-top: 2rem; font-size: .9rem; opacity: .8 }
|
|
|
102
84
|
<li><a class="q" href="/api?q=1600+pennsylvania+ave&limit=1">/api?q=1600+pennsylvania+ave&limit=1</a></li>
|
|
103
85
|
<li><a class="q" href="/reverse?lat=52.52&lon=13.405">/reverse?lat=52.52&lon=13.405</a></li>
|
|
104
86
|
</ul>
|
|
105
|
-
<footer><a href="https://mailwoman.sister.software/docs/
|
|
87
|
+
<footer><a href="https://mailwoman.sister.software/docs/developers/get-started/what-mailwoman-is">What Mailwoman is</a> · <a href="https://mailwoman.sister.software/demo">Live demo</a></footer>
|
|
106
88
|
</body>
|
|
107
89
|
</html>
|
|
108
90
|
`
|
|
@@ -177,8 +159,8 @@ export function registerPhotonRoutes(app: OpenAPIHono, engine: PhotonEngine): vo
|
|
|
177
159
|
const collection = await engine.search(params)
|
|
178
160
|
|
|
179
161
|
// #1052: `format=jsonld` re-serializes the SAME FeatureCollection as schema.org `Place[]` JSON-LD. The
|
|
180
|
-
// declared 200 schema documents only the FeatureCollection shape (matching the legacy yaml
|
|
181
|
-
//
|
|
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,
|
|
182
164
|
// never a wire-behavior change (api-kit's `openapi.ts` sets the precedent for this idiom).
|
|
183
165
|
if (asString(q["format"]) === "jsonld") {
|
|
184
166
|
return c.json(photonToSchemaOrg(collection) as never, 200)
|