@mailwoman/photon 9.4.0 → 10.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 +2 -2
- package/{lib/cli.ts → cli/main.ts} +40 -54
- package/lib/app.ts +13 -18
- package/lib/engine.ts +13 -5
- package/lib/index.ts +6 -11
- package/lib/locality-postcode.ts +9 -13
- package/lib/projection.ts +60 -55
- package/lib/routes.ts +9 -21
- package/lib/schema.ts +31 -24
- package/out/app.d.ts +13 -14
- package/out/app.d.ts.map +1 -1
- package/out/app.js +4 -11
- package/out/app.js.map +1 -1
- package/out/cli/main.d.ts +12 -0
- package/out/cli/main.d.ts.map +1 -0
- package/out/{cli.js → cli/main.js} +40 -54
- package/out/cli/main.js.map +1 -0
- package/out/engine.d.ts +13 -5
- package/out/engine.d.ts.map +1 -1
- package/out/engine.js +2 -2
- package/out/engine.js.map +1 -1
- package/out/index.d.ts +6 -11
- package/out/index.d.ts.map +1 -1
- package/out/index.js +6 -11
- package/out/index.js.map +1 -1
- package/out/locality-postcode.d.ts +4 -7
- package/out/locality-postcode.d.ts.map +1 -1
- package/out/locality-postcode.js +8 -12
- package/out/locality-postcode.js.map +1 -1
- package/out/projection.d.ts +48 -38
- package/out/projection.d.ts.map +1 -1
- package/out/projection.js +37 -35
- package/out/projection.js.map +1 -1
- package/out/routes.d.ts +2 -2
- package/out/routes.d.ts.map +1 -1
- package/out/routes.js +9 -21
- package/out/routes.js.map +1 -1
- package/out/schema.d.ts +29 -22
- package/out/schema.d.ts.map +1 -1
- package/out/schema.js +31 -24
- package/out/schema.js.map +1 -1
- package/package.json +47 -31
- package/out/cli.d.ts +0 -17
- package/out/cli.d.ts.map +0 -1
- package/out/cli.js.map +0 -1
package/out/index.d.ts
CHANGED
|
@@ -3,20 +3,15 @@
|
|
|
3
3
|
* @license AGPL-3.0
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
5
|
*
|
|
6
|
-
* `@mailwoman/photon`
|
|
6
|
+
* `@mailwoman/photon` is a Photon-compatible autocomplete / type-ahead geocoding API over the
|
|
7
7
|
* Mailwoman engine. Where `@mailwoman/nominatim` is structured lookup, Photon is
|
|
8
8
|
* search-as-you-type: a GeoJSON `FeatureCollection` per query, biased by location, ranked for
|
|
9
|
-
* prefixes. It maps onto Mailwoman's shipped FST autocomplete tier
|
|
10
|
-
*
|
|
9
|
+
* prefixes. It maps onto Mailwoman's shipped FST autocomplete tier and the parse then resolve
|
|
10
|
+
* path.
|
|
11
11
|
*
|
|
12
|
-
* Like its siblings, the package is engine-agnostic
|
|
13
|
-
* {@link PhotonEngine}
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* The Hono app (CORS + error envelope + the emitted OpenAPI document) lives in `app.ts`; route
|
|
17
|
-
* definitions + handlers in `routes.ts`; wire types + the engine contract in `engine.ts`; the
|
|
18
|
-
* resolved-place → Photon-schema projection in `projection.ts`; the zod wire schemas in
|
|
19
|
-
* `schema.ts`.
|
|
12
|
+
* Like its siblings, the package is engine-agnostic. {@link createPhotonApp} takes a
|
|
13
|
+
* {@link PhotonEngine}, and the CLI wires the real engine. Routes whose engine method is absent
|
|
14
|
+
* answer `501`.
|
|
20
15
|
*/
|
|
21
16
|
export * from "#app";
|
|
22
17
|
export * from "#engine";
|
package/out/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,cAAc,MAAM,CAAA;AACpB,cAAc,SAAS,CAAA;AACvB,cAAc,aAAa,CAAA;AAC3B,cAAc,SAAS,CAAA"}
|
package/out/index.js
CHANGED
|
@@ -3,20 +3,15 @@
|
|
|
3
3
|
* @license AGPL-3.0
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
5
|
*
|
|
6
|
-
* `@mailwoman/photon`
|
|
6
|
+
* `@mailwoman/photon` is a Photon-compatible autocomplete / type-ahead geocoding API over the
|
|
7
7
|
* Mailwoman engine. Where `@mailwoman/nominatim` is structured lookup, Photon is
|
|
8
8
|
* search-as-you-type: a GeoJSON `FeatureCollection` per query, biased by location, ranked for
|
|
9
|
-
* prefixes. It maps onto Mailwoman's shipped FST autocomplete tier
|
|
10
|
-
*
|
|
9
|
+
* prefixes. It maps onto Mailwoman's shipped FST autocomplete tier and the parse then resolve
|
|
10
|
+
* path.
|
|
11
11
|
*
|
|
12
|
-
* Like its siblings, the package is engine-agnostic
|
|
13
|
-
* {@link PhotonEngine}
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* The Hono app (CORS + error envelope + the emitted OpenAPI document) lives in `app.ts`; route
|
|
17
|
-
* definitions + handlers in `routes.ts`; wire types + the engine contract in `engine.ts`; the
|
|
18
|
-
* resolved-place → Photon-schema projection in `projection.ts`; the zod wire schemas in
|
|
19
|
-
* `schema.ts`.
|
|
12
|
+
* Like its siblings, the package is engine-agnostic. {@link createPhotonApp} takes a
|
|
13
|
+
* {@link PhotonEngine}, and the CLI wires the real engine. Routes whose engine method is absent
|
|
14
|
+
* answer `501`.
|
|
20
15
|
*/
|
|
21
16
|
export * from "#app";
|
|
22
17
|
export * from "#engine";
|
package/out/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,cAAc,MAAM,CAAA;AACpB,cAAc,SAAS,CAAA;AACvB,cAAc,aAAa,CAAA;AAC3B,cAAc,SAAS,CAAA"}
|
|
@@ -3,14 +3,11 @@
|
|
|
3
3
|
* @license AGPL-3.0
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
5
|
*
|
|
6
|
-
* Reverse lookup over the `postcode-locality-*.db` artifacts: the
|
|
7
|
-
* resolved locality, keyed by its WOF id
|
|
8
|
-
* enrichment: a village answer carries the postcode the gazetteer attests for it.
|
|
6
|
+
* Reverse lookup over the `postcode-locality-*.db` artifacts: the containing postcode of a
|
|
7
|
+
* resolved locality, keyed by its WOF id.
|
|
9
8
|
*
|
|
10
|
-
* The exactly-one rule is the abstention: a locality contained by several postcodes (any real
|
|
11
|
-
*
|
|
12
|
-
* Tolerate-and-degrade like every optional artifact: a machine without the DBs answers undefined
|
|
13
|
-
* everywhere and the consumer simply doesn't decorate.
|
|
9
|
+
* The exactly-one rule is the abstention: a locality contained by several postcodes (any real city) gets
|
|
10
|
+
* no postcode. A machine without the DBs degrades to no enrichment.
|
|
14
11
|
*/
|
|
15
12
|
export type LocalityPostcodeLookup = (wofID: number, countryCode: string | null) => string | undefined;
|
|
16
13
|
export declare function createLocalityPostcodeLookup(): Promise<LocalityPostcodeLookup>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"locality-postcode.d.ts","sourceRoot":"","sources":["../lib/locality-postcode.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"locality-postcode.d.ts","sourceRoot":"","sources":["../lib/locality-postcode.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAYH,MAAM,MAAM,sBAAsB,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,IAAI,KAAK,MAAM,GAAG,SAAS,CAAA;AAEtG,wBAAsB,4BAA4B,IAAI,OAAO,CAAC,sBAAsB,CAAC,CAwCpF"}
|
package/out/locality-postcode.js
CHANGED
|
@@ -3,17 +3,14 @@
|
|
|
3
3
|
* @license AGPL-3.0
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
5
|
*
|
|
6
|
-
* Reverse lookup over the `postcode-locality-*.db` artifacts: the
|
|
7
|
-
* resolved locality, keyed by its WOF id
|
|
8
|
-
* enrichment: a village answer carries the postcode the gazetteer attests for it.
|
|
6
|
+
* Reverse lookup over the `postcode-locality-*.db` artifacts: the containing postcode of a
|
|
7
|
+
* resolved locality, keyed by its WOF id.
|
|
9
8
|
*
|
|
10
|
-
* The exactly-one rule is the abstention: a locality contained by several postcodes (any real
|
|
11
|
-
*
|
|
12
|
-
* Tolerate-and-degrade like every optional artifact: a machine without the DBs answers undefined
|
|
13
|
-
* everywhere and the consumer simply doesn't decorate.
|
|
9
|
+
* The exactly-one rule is the abstention: a locality contained by several postcodes (any real city) gets
|
|
10
|
+
* no postcode. A machine without the DBs degrades to no enrichment.
|
|
14
11
|
*/
|
|
15
|
-
import { dataRootPath } from "@mailwoman/core/data-root";
|
|
16
12
|
import { pathExists } from "@mailwoman/core/fs/readers";
|
|
13
|
+
import { wofDatabasePath } from "@mailwoman/resolver-wof-sqlite/paths";
|
|
17
14
|
import { DatabaseClient } from "@mailwoman/sqlite/client";
|
|
18
15
|
/**
|
|
19
16
|
* The per-country artifacts, probed in caller-country order with `intl` as the shared fallback.
|
|
@@ -22,14 +19,13 @@ const POSTCODE_LOCALITY_SUFFIXES = ["fr", "de", "jp", "intl"];
|
|
|
22
19
|
export async function createLocalityPostcodeLookup() {
|
|
23
20
|
const statements = new Map();
|
|
24
21
|
for (const suffix of POSTCODE_LOCALITY_SUFFIXES) {
|
|
25
|
-
const path =
|
|
22
|
+
const path = wofDatabasePath(`postcode-locality-${suffix}.db`);
|
|
26
23
|
if (!(await pathExists(path)))
|
|
27
24
|
continue;
|
|
28
25
|
try {
|
|
29
26
|
const db = new DatabaseClient(path, { readOnly: true });
|
|
30
|
-
// No `is_containing` filter: villages routinely
|
|
31
|
-
//
|
|
32
|
-
// The exactly-one DISTINCT rule below is the entire ambiguity guard.
|
|
27
|
+
// No `is_containing` filter: villages routinely have 0, so the exactly-one
|
|
28
|
+
// distinct rule below is the entire ambiguity guard.
|
|
33
29
|
statements.set(suffix, db.prepare(`SELECT DISTINCT postcode FROM postcode_locality WHERE locality_id = ? LIMIT 2`));
|
|
34
30
|
}
|
|
35
31
|
catch {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"locality-postcode.js","sourceRoot":"","sources":["../lib/locality-postcode.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"locality-postcode.js","sourceRoot":"","sources":["../lib/locality-postcode.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAA;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAA;AACtE,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAA;AAGzD;;GAEG;AACH,MAAM,0BAA0B,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,CAAU,CAAA;AAItE,MAAM,CAAC,KAAK,UAAU,4BAA4B;IACjD,MAAM,UAAU,GAAG,IAAI,GAAG,EAAiD,CAAA;IAE3E,KAAK,MAAM,MAAM,IAAI,0BAA0B,EAAE,CAAC;QACjD,MAAM,IAAI,GAAG,eAAe,CAAC,qBAAqB,MAAM,KAAK,CAAC,CAAA;QAE9D,IAAI,CAAC,CAAC,MAAM,UAAU,CAAC,IAAI,CAAC,CAAC;YAAE,SAAQ;QAEvC,IAAI,CAAC;YACJ,MAAM,EAAE,GAAG,IAAI,cAAc,CAA2B,IAAI,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAA;YAEjF,2EAA2E;YAC3E,qDAAqD;YACrD,UAAU,CAAC,GAAG,CACb,MAAM,EACN,EAAE,CAAC,OAAO,CAAC,+EAA+E,CAAC,CAC3F,CAAA;QACF,CAAC;QAAC,MAAM,CAAC;YACR,kFAAkF;QACnF,CAAC;IACF,CAAC;IAED,OAAO,CAAC,KAAK,EAAE,WAAW,EAAE,EAAE;QAC7B,MAAM,EAAE,GAAG,WAAW,EAAE,WAAW,EAAE,CAAA;QACrC,MAAM,KAAK,GAAG,EAAE,IAAI,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAA;QAEhE,KAAK,MAAM,MAAM,IAAI,KAAK,EAAE,CAAC;YAC5B,MAAM,IAAI,GAAG,UAAU,CAAC,GAAG,CAAC,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/projection.d.ts
CHANGED
|
@@ -3,17 +3,18 @@
|
|
|
3
3
|
* @license AGPL-3.0
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
5
|
*
|
|
6
|
-
* The
|
|
7
|
-
* cased names
|
|
8
|
-
* plus the `format=jsonld` schema.org re-serialization.
|
|
9
|
-
* construction live in `engine.ts`.
|
|
6
|
+
* The resolved-place → Photon-schema projection: decorating a resolved gazetteer place (proper-
|
|
7
|
+
* cased names, ancestry, country, house and street grade overrides) into {@link PhotonProperties},
|
|
8
|
+
* plus the `format=jsonld` schema.org re-serialization.
|
|
10
9
|
*/
|
|
11
10
|
import { type SchemaOrgPlace } from "@mailwoman/annotations";
|
|
12
11
|
import { type PhotonFeature, type PhotonFeatureCollection, type PhotonProperties } from "#engine";
|
|
13
12
|
/**
|
|
14
|
-
* The resolved-place info a forward `/api` result
|
|
15
|
-
* the coordinate, the resolved country
|
|
16
|
-
*
|
|
13
|
+
* The resolved-place info in a forward `/api` result: the admin ladder (most-specific first)
|
|
14
|
+
* with gazetteer names, the coordinate, the resolved country and the postcode.
|
|
15
|
+
* {@link photonForwardProperties} projects it onto Photon's schema.
|
|
16
|
+
*
|
|
17
|
+
* Decorate from the resolved place rather than the parsed input span.
|
|
17
18
|
*/
|
|
18
19
|
export interface PhotonForwardInput {
|
|
19
20
|
lat: number;
|
|
@@ -27,42 +28,43 @@ export interface PhotonForwardInput {
|
|
|
27
28
|
code?: string;
|
|
28
29
|
} | null;
|
|
29
30
|
/**
|
|
30
|
-
* Resolved admin ancestry, most-specific first, each carrying the gazetteer's
|
|
31
|
+
* Resolved admin ancestry, most-specific first, each carrying the gazetteer's
|
|
32
|
+
* canonical name rather than the parsed span.
|
|
31
33
|
*/
|
|
32
34
|
places: ReadonlyArray<{
|
|
33
35
|
tag: string;
|
|
34
36
|
name: string;
|
|
35
37
|
}>;
|
|
36
38
|
/**
|
|
37
|
-
* A
|
|
38
|
-
* `address_point` (rooftop) or `interpolated` tier
|
|
39
|
-
* re-tags the schema `osm_key: place` /
|
|
40
|
-
* `
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
39
|
+
* A house-grade result: set only when the resolver produced a specific building coordinate,
|
|
40
|
+
* the `address_point` (rooftop) or `interpolated` tier rather than an admin centroid.
|
|
41
|
+
* {@link photonForwardProperties} then re-tags the schema `osm_key: place` /
|
|
42
|
+
* `osm_value: house` / `type: house` and surfaces the parsed `housenumber` + `street`,
|
|
43
|
+
* matching upstream komoot/photon's bare-address-point shape.
|
|
44
|
+
*
|
|
45
|
+
* Absent means the result keeps its admin-ancestry schema.
|
|
44
46
|
*/
|
|
45
47
|
house?: {
|
|
46
48
|
number?: string | null;
|
|
47
49
|
street?: string | null;
|
|
48
50
|
} | null;
|
|
49
51
|
/**
|
|
50
|
-
* A
|
|
51
|
-
* below rooftop/interp
|
|
52
|
-
* residential` / `type: street` with the
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
* never street-tiers).
|
|
52
|
+
* A street-grade result: set when the street-centroid tier fired, a street-level
|
|
53
|
+
* coordinate below rooftop/interp and above admin. {@link photonForwardProperties}
|
|
54
|
+
* re-tags it `osm_key: highway` / `osm_value: residential` / `type: street` with the
|
|
55
|
+
* full assembled street name in `name`, matching upstream komoot's street results.
|
|
56
|
+
*
|
|
57
|
+
* `house` wins when both are set, since a numbered query never street-tiers.
|
|
57
58
|
*/
|
|
58
59
|
street?: {
|
|
59
60
|
name?: string | null;
|
|
60
61
|
} | null;
|
|
61
62
|
}
|
|
62
63
|
/**
|
|
63
|
-
* The Photon `osm_key`/`osm_value`/`type` for a resolved tag or WOF placetype
|
|
64
|
-
* falling back to a safe default so the fields are always present.
|
|
65
|
-
*
|
|
64
|
+
* The Photon `osm_key`/`osm_value`/`type` for a resolved tag or WOF placetype
|
|
65
|
+
* (`locality`, `region`, `country`, …), falling back to a safe default so the fields are always present.
|
|
66
|
+
*
|
|
67
|
+
* Shared by the forward projection and `/reverse` so the two endpoints report a place the same way.
|
|
66
68
|
*/
|
|
67
69
|
export declare function photonOSMTags(tagOrPlacetype: string): {
|
|
68
70
|
osm_key: string;
|
|
@@ -70,17 +72,19 @@ export declare function photonOSMTags(tagOrPlacetype: string): {
|
|
|
70
72
|
type: string;
|
|
71
73
|
};
|
|
72
74
|
/**
|
|
73
|
-
* Project a resolved forward result into Photon properties
|
|
74
|
-
* names
|
|
75
|
-
*
|
|
75
|
+
* Project a resolved forward result into Photon properties, decorating from the resolved
|
|
76
|
+
* gazetteer place (proper-cased names, ancestry, country) rather than the parsed input span.
|
|
77
|
+
*
|
|
78
|
+
* Always emit `osm_key`/`osm_value`/`type` so Photon client libraries
|
|
79
|
+
* (leaflet-control-geocoder, @openrunner/photon-geocoder) never dereference undefined.
|
|
76
80
|
*/
|
|
77
81
|
export declare function photonForwardProperties(input: PhotonForwardInput): PhotonProperties;
|
|
78
82
|
/**
|
|
79
|
-
* {@link photonForwardProperties}, wrapped as a Photon Point `Feature` at the resolved coordinate.
|
|
83
|
+
* {@link photonForwardProperties}, wrapped as a Photon Point `Feature` at the resolved coordinate.
|
|
80
84
|
*/
|
|
81
85
|
export declare function photonForwardFeature(input: PhotonForwardInput): PhotonFeature;
|
|
82
86
|
/**
|
|
83
|
-
* The winning place plus its ranked alternatives
|
|
87
|
+
* The winning place plus its ranked alternatives, the input to {@link photonForwardCollection}.
|
|
84
88
|
*/
|
|
85
89
|
export interface PhotonForwardResult {
|
|
86
90
|
/**
|
|
@@ -88,24 +92,30 @@ export interface PhotonForwardResult {
|
|
|
88
92
|
*/
|
|
89
93
|
primary: PhotonForwardInput;
|
|
90
94
|
/**
|
|
91
|
-
* Ranked alternative places (Springfield MA / IL / …), each a single-place input
|
|
95
|
+
* Ranked alternative places (Springfield MA / IL / …), each a single-place input.
|
|
96
|
+
* Excludes the primary.
|
|
92
97
|
*/
|
|
93
98
|
alternatives: PhotonForwardInput[];
|
|
94
99
|
}
|
|
95
100
|
/**
|
|
96
|
-
* Assemble a Photon `FeatureCollection` honoring `limit
|
|
97
|
-
* capped at `limit`.
|
|
101
|
+
* Assemble a Photon `FeatureCollection` honoring `limit`: the primary feature first,
|
|
102
|
+
* then ranked alternatives, capped at `limit`.
|
|
103
|
+
*
|
|
104
|
+
* `limit` floors to 1, since Photon always returns at least the best match.
|
|
98
105
|
*/
|
|
99
106
|
export declare function photonForwardCollection(result: PhotonForwardResult, limit: number): PhotonFeatureCollection;
|
|
100
107
|
/**
|
|
101
|
-
* Project a Photon `Feature` into a schema.org `Place` JSON-LD object (`format=jsonld
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
108
|
+
* Project a Photon `Feature` into a schema.org `Place` JSON-LD object (`format=jsonld`),
|
|
109
|
+
* the output-format projection.
|
|
110
|
+
*
|
|
111
|
+
* Reads the feature's already-decorated {@link PhotonProperties}
|
|
112
|
+
* (housenumber/street/city/state/postcode/countrycode and the coordinate), so it stays a
|
|
113
|
+
* pure re-serialization of the same resolved place included in the FeatureCollection.
|
|
114
|
+
* `streetAddress` is the plain house-number-first join, since the light router has no locale formatter.
|
|
105
115
|
*/
|
|
106
116
|
export declare function photonFeatureToSchemaOrg(feature: PhotonFeature): SchemaOrgPlace;
|
|
107
117
|
/**
|
|
108
|
-
* Project a whole Photon `FeatureCollection` into an array of schema.org `Place` objects (`format=jsonld`).
|
|
118
|
+
* Project a whole Photon `FeatureCollection` into an array of schema.org `Place` objects (`format=jsonld`).
|
|
109
119
|
*/
|
|
110
120
|
export declare function photonToSchemaOrg(collection: PhotonFeatureCollection): SchemaOrgPlace[];
|
|
111
121
|
//# sourceMappingURL=projection.d.ts.map
|
package/out/projection.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"projection.d.ts","sourceRoot":"","sources":["../lib/projection.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"projection.d.ts","sourceRoot":"","sources":["../lib/projection.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAwB,KAAK,cAAc,EAAe,MAAM,wBAAwB,CAAA;AAE/F,OAAO,EACN,KAAK,aAAa,EAClB,KAAK,uBAAuB,EAG5B,KAAK,gBAAgB,EACrB,MAAM,SAAS,CAAA;AAEhB;;;;;;GAMG;AACH,MAAM,WAAW,kBAAkB;IAClC,GAAG,EAAE,MAAM,CAAA;IACX,GAAG,EAAE,MAAM,CAAA;IACX,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACxB;;OAEG;IACH,OAAO,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAA;IACjD;;;OAGG;IACH,MAAM,EAAE,aAAa,CAAC;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;IACpD;;;;;;;;OAQG;IACH,KAAK,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,GAAG,IAAI,CAAA;IACjE;;;;;;;OAOG;IACH,MAAM,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,GAAG,IAAI,CAAA;CACxC;AA0CD;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,cAAc,EAAE,MAAM,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAI1G;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,kBAAkB,GAAG,gBAAgB,CAqDnF;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,kBAAkB,GAAG,aAAa,CAE7E;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IACnC;;OAEG;IACH,OAAO,EAAE,kBAAkB,CAAA;IAC3B;;;OAGG;IACH,YAAY,EAAE,kBAAkB,EAAE,CAAA;CAClC;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,mBAAmB,EAAE,KAAK,EAAE,MAAM,GAAG,uBAAuB,CAU3G;AAED;;;;;;;;GAQG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,aAAa,GAAG,cAAc,CAe/E;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,uBAAuB,GAAG,cAAc,EAAE,CAEvF"}
|
package/out/projection.js
CHANGED
|
@@ -3,34 +3,34 @@
|
|
|
3
3
|
* @license AGPL-3.0
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
5
|
*
|
|
6
|
-
* The
|
|
7
|
-
* cased names
|
|
8
|
-
* plus the `format=jsonld` schema.org re-serialization.
|
|
9
|
-
* construction live in `engine.ts`.
|
|
6
|
+
* The resolved-place → Photon-schema projection: decorating a resolved gazetteer place (proper-
|
|
7
|
+
* cased names, ancestry, country, house and street grade overrides) into {@link PhotonProperties},
|
|
8
|
+
* plus the `format=jsonld` schema.org re-serialization.
|
|
10
9
|
*/
|
|
11
10
|
import { composeStreetAddress, toSchemaOrg } from "@mailwoman/annotations";
|
|
12
11
|
import { photonCollection, photonFeature, } from "#engine";
|
|
13
12
|
/**
|
|
14
|
-
* How a resolved tag projects onto Photon's schema: the property key that holds its name,
|
|
15
|
-
* `type` a Photon client reads.
|
|
13
|
+
* How a resolved tag projects onto Photon's schema: the property key that holds its name,
|
|
14
|
+
* plus the OSM `key`/`value`/ `type` a Photon client reads.
|
|
15
|
+
*
|
|
16
|
+
* Kept close to komoot Photon's own values so client label-builders behave.
|
|
16
17
|
*/
|
|
17
18
|
const FORWARD_TAG_PROJECTION = {
|
|
18
19
|
venue: { key: "name", osmKey: "amenity", osmValue: "yes", type: "house" },
|
|
19
20
|
house: { key: "name", osmKey: "building", osmValue: "yes", type: "house" },
|
|
20
21
|
street: { key: "street", osmKey: "highway", osmValue: "residential", type: "street" },
|
|
21
22
|
neighbourhood: { key: "district", osmKey: "place", osmValue: "suburb", type: "district" },
|
|
22
|
-
// The finest tier the /reverse descent ladder (resolver-wof-sqlite `DESCENT_TIERS`) can return
|
|
23
|
-
// here a microhood-deepest reverse result fell through to the `place/yes/other` default. #1041 close-out.
|
|
23
|
+
// The finest tier the /reverse descent ladder (resolver-wof-sqlite `DESCENT_TIERS`) can return.
|
|
24
24
|
microhood: { key: "district", osmKey: "place", osmValue: "neighbourhood", type: "district" },
|
|
25
25
|
dependent_locality: { key: "district", osmKey: "place", osmValue: "suburb", type: "district" },
|
|
26
26
|
borough: { key: "district", osmKey: "place", osmValue: "borough", type: "district" },
|
|
27
27
|
locality: { key: "city", osmKey: "place", osmValue: "city", type: "city" },
|
|
28
|
-
// The JP tiers the character-path model emits
|
|
29
|
-
// district (大字 / 町名) its district
|
|
28
|
+
// The JP tiers the character-path model emits: a municipality is Photon's city, a prefecture
|
|
29
|
+
// its state, a district (大字 / 町名) its district, the same keys Nominatim assigns those ranks.
|
|
30
30
|
municipality: { key: "city", osmKey: "place", osmValue: "city", type: "city" },
|
|
31
31
|
prefecture: { key: "state", osmKey: "place", osmValue: "state", type: "state" },
|
|
32
32
|
district: { key: "district", osmKey: "place", osmValue: "suburb", type: "district" },
|
|
33
|
-
// WOF placetypes the /reverse hierarchy uses (so both endpoints derive osm tags from
|
|
33
|
+
// WOF placetypes the /reverse hierarchy uses (so both endpoints derive osm tags from one table).
|
|
34
34
|
localadmin: { key: "city", osmKey: "place", osmValue: "city", type: "city" },
|
|
35
35
|
subregion: { key: "county", osmKey: "place", osmValue: "county", type: "county" },
|
|
36
36
|
county: { key: "county", osmKey: "place", osmValue: "county", type: "county" },
|
|
@@ -39,25 +39,29 @@ const FORWARD_TAG_PROJECTION = {
|
|
|
39
39
|
country: { key: "country", osmKey: "place", osmValue: "country", type: "country" },
|
|
40
40
|
};
|
|
41
41
|
/**
|
|
42
|
-
* Fallback OSM tags
|
|
42
|
+
* Fallback OSM tags.
|
|
43
|
+
*
|
|
44
|
+
* A Photon client reads `osm_key`/`osm_value`/`type` unconditionally, so they must never be absent.
|
|
43
45
|
*/
|
|
44
46
|
const DEFAULT_OSM_TAGS = { osm_key: "place", osm_value: "yes", type: "other" };
|
|
45
47
|
/**
|
|
46
|
-
* The Photon `osm_key`/`osm_value`/`type` for a resolved tag or WOF placetype
|
|
47
|
-
* falling back to a safe default so the fields are always present.
|
|
48
|
-
*
|
|
48
|
+
* The Photon `osm_key`/`osm_value`/`type` for a resolved tag or WOF placetype
|
|
49
|
+
* (`locality`, `region`, `country`, …), falling back to a safe default so the fields are always present.
|
|
50
|
+
*
|
|
51
|
+
* Shared by the forward projection and `/reverse` so the two endpoints report a place the same way.
|
|
49
52
|
*/
|
|
50
53
|
export function photonOSMTags(tagOrPlacetype) {
|
|
51
54
|
const proj = FORWARD_TAG_PROJECTION[tagOrPlacetype];
|
|
52
55
|
return proj ? { osm_key: proj.osmKey, osm_value: proj.osmValue, type: proj.type } : { ...DEFAULT_OSM_TAGS };
|
|
53
56
|
}
|
|
54
57
|
/**
|
|
55
|
-
* Project a resolved forward result into Photon properties
|
|
56
|
-
* names
|
|
57
|
-
*
|
|
58
|
+
* Project a resolved forward result into Photon properties, decorating from the resolved
|
|
59
|
+
* gazetteer place (proper-cased names, ancestry, country) rather than the parsed input span.
|
|
60
|
+
*
|
|
61
|
+
* Always emit `osm_key`/`osm_value`/`type` so Photon client libraries
|
|
62
|
+
* (leaflet-control-geocoder, @openrunner/photon-geocoder) never dereference undefined.
|
|
58
63
|
*/
|
|
59
64
|
export function photonForwardProperties(input) {
|
|
60
|
-
// Safe defaults: a Photon client reads osm_key/osm_value/type unconditionally, so they must never be undefined.
|
|
61
65
|
const props = { ...DEFAULT_OSM_TAGS };
|
|
62
66
|
const [primary] = input.places;
|
|
63
67
|
if (primary) {
|
|
@@ -79,18 +83,11 @@ export function photonForwardProperties(input) {
|
|
|
79
83
|
if (input.country?.code) {
|
|
80
84
|
props.countrycode = input.country.code.toLowerCase();
|
|
81
85
|
}
|
|
82
|
-
// #1041: house-grade override. A rooftop / interpolated coordinate is a BUILDING, not the admin locality the
|
|
83
|
-
// ancestry above would label it — re-tag the schema so a Photon client renders (and zooms to) a house, and surface
|
|
84
|
-
// the parsed housenumber + street. Matches upstream komoot/photon's bare address point (osm_key:place, osm_value:
|
|
85
|
-
// house, type:house, with housenumber + street and NO name). Drop the admin-derived `name` — else the QGIS FLF label
|
|
86
|
-
// (name + housenumber + street + city + postcode) doubles the city ("Paris 8 Boulevard du Palais Paris 75001"). The
|
|
87
|
-
// city/state/postcode/country the ancestry filled stay put (upstream carries them on a house result too).
|
|
88
|
-
// #1050: street-grade — the street-centroid tier fired. Re-tag per upstream's street shape (full
|
|
89
|
-
// name in `name`, highway/street osm tags); the admin ancestry (city/state/…) stays as context.
|
|
90
86
|
if (input.street?.name && !input.house) {
|
|
91
87
|
props.name = input.street.name;
|
|
92
88
|
Object.assign(props, { osm_key: "highway", osm_value: "residential", type: "street" });
|
|
93
89
|
}
|
|
90
|
+
// Drop the admin-derived `name`, or a QGIS FLF label doubles the city.
|
|
94
91
|
if (input.house) {
|
|
95
92
|
props.osm_key = "place";
|
|
96
93
|
props.osm_value = "house";
|
|
@@ -108,14 +105,16 @@ export function photonForwardProperties(input) {
|
|
|
108
105
|
return props;
|
|
109
106
|
}
|
|
110
107
|
/**
|
|
111
|
-
* {@link photonForwardProperties}, wrapped as a Photon Point `Feature` at the resolved coordinate.
|
|
108
|
+
* {@link photonForwardProperties}, wrapped as a Photon Point `Feature` at the resolved coordinate.
|
|
112
109
|
*/
|
|
113
110
|
export function photonForwardFeature(input) {
|
|
114
111
|
return photonFeature(input.lon, input.lat, photonForwardProperties(input));
|
|
115
112
|
}
|
|
116
113
|
/**
|
|
117
|
-
* Assemble a Photon `FeatureCollection` honoring `limit
|
|
118
|
-
* capped at `limit`.
|
|
114
|
+
* Assemble a Photon `FeatureCollection` honoring `limit`: the primary feature first,
|
|
115
|
+
* then ranked alternatives, capped at `limit`.
|
|
116
|
+
*
|
|
117
|
+
* `limit` floors to 1, since Photon always returns at least the best match.
|
|
119
118
|
*/
|
|
120
119
|
export function photonForwardCollection(result, limit) {
|
|
121
120
|
const cap = Math.max(1, Math.floor(limit) || 1);
|
|
@@ -128,10 +127,13 @@ export function photonForwardCollection(result, limit) {
|
|
|
128
127
|
return photonCollection(features);
|
|
129
128
|
}
|
|
130
129
|
/**
|
|
131
|
-
* Project a Photon `Feature` into a schema.org `Place` JSON-LD object (`format=jsonld
|
|
132
|
-
*
|
|
133
|
-
*
|
|
134
|
-
*
|
|
130
|
+
* Project a Photon `Feature` into a schema.org `Place` JSON-LD object (`format=jsonld`),
|
|
131
|
+
* the output-format projection.
|
|
132
|
+
*
|
|
133
|
+
* Reads the feature's already-decorated {@link PhotonProperties}
|
|
134
|
+
* (housenumber/street/city/state/postcode/countrycode and the coordinate), so it stays a
|
|
135
|
+
* pure re-serialization of the same resolved place included in the FeatureCollection.
|
|
136
|
+
* `streetAddress` is the plain house-number-first join, since the light router has no locale formatter.
|
|
135
137
|
*/
|
|
136
138
|
export function photonFeatureToSchemaOrg(feature) {
|
|
137
139
|
const p = feature.properties;
|
|
@@ -149,7 +151,7 @@ export function photonFeatureToSchemaOrg(feature) {
|
|
|
149
151
|
});
|
|
150
152
|
}
|
|
151
153
|
/**
|
|
152
|
-
* Project a whole Photon `FeatureCollection` into an array of schema.org `Place` objects (`format=jsonld`).
|
|
154
|
+
* Project a whole Photon `FeatureCollection` into an array of schema.org `Place` objects (`format=jsonld`).
|
|
153
155
|
*/
|
|
154
156
|
export function photonToSchemaOrg(collection) {
|
|
155
157
|
return collection.features.map(photonFeatureToSchemaOrg);
|
package/out/projection.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"projection.js","sourceRoot":"","sources":["../lib/projection.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"projection.js","sourceRoot":"","sources":["../lib/projection.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,oBAAoB,EAAuB,WAAW,EAAE,MAAM,wBAAwB,CAAA;AAE/F,OAAO,EAGN,gBAAgB,EAChB,aAAa,GAEb,MAAM,SAAS,CAAA;AA2ChB;;;;;GAKG;AACH,MAAM,sBAAsB,GAGxB;IACH,KAAK,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE;IACzE,KAAK,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE;IAC1E,MAAM,EAAE,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS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CAAC;IAED,OAAO,gBAAgB,CAAC,QAAQ,CAAC,CAAA;AAClC,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,wBAAwB,CAAC,OAAsB;IAC9D,MAAM,CAAC,GAAG,OAAO,CAAC,UAAU,CAAA;IAC5B,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAA;IAC/C,MAAM,aAAa,GAAG,oBAAoB,CAAC,EAAE,WAAW,EAAE,CAAC,CAAC,WAAW,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,CAAA;IAE5F,OAAO,WAAW,CAAC;QAClB,GAAG;QACH,GAAG;QACH,IAAI,EAAE,CAAC,CAAC,IAAI;QACZ,aAAa,EAAE,aAAa,IAAI,SAAS;QACzC,QAAQ,EAAE,CAAC,CAAC,IAAI;QAChB,MAAM,EAAE,CAAC,CAAC,KAAK;QACf,UAAU,EAAE,CAAC,CAAC,QAAQ;QACtB,WAAW,EAAE,CAAC,CAAC,WAAW;KAC1B,CAAC,CAAA;AACH,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAC,UAAmC;IACpE,OAAO,UAAU,CAAC,QAAQ,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAA;AACzD,CAAC"}
|
package/out/routes.d.ts
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
5
|
*
|
|
6
6
|
* Route definitions + handlers for the Photon-compatible surface. The OpenAPI document is
|
|
7
|
-
* emitted from these definitions
|
|
8
|
-
* `legacyQuery` express-shaped view
|
|
7
|
+
* emitted from these definitions, so no handwritten spec exists. Handlers parse params from
|
|
8
|
+
* the `legacyQuery` express-shaped view. The zod query schemas drive only the emitted document.
|
|
9
9
|
*/
|
|
10
10
|
import { type OpenAPIHono } from "@hono/zod-openapi";
|
|
11
11
|
import type { EngineStamp } from "@mailwoman/core/license";
|
package/out/routes.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../lib/routes.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAe,KAAK,WAAW,EAAK,MAAM,mBAAmB,CAAA;AAEpE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAE1D,OAAO,KAAK,EAAE,YAAY,EAAoE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../lib/routes.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAe,KAAK,WAAW,EAAK,MAAM,mBAAmB,CAAA;AAEpE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAE1D,OAAO,KAAK,EAAE,YAAY,EAAoE,MAAM,SAAS,CAAA;AAyG7G;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,WAAW,EAAE,MAAM,EAAE,YAAY,EAAE,KAAK,CAAC,EAAE,WAAW,GAAG,IAAI,CA6DtG"}
|
package/out/routes.js
CHANGED
|
@@ -4,28 +4,16 @@
|
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
5
|
*
|
|
6
6
|
* Route definitions + handlers for the Photon-compatible surface. The OpenAPI document is
|
|
7
|
-
* emitted from these definitions
|
|
8
|
-
* `legacyQuery` express-shaped view
|
|
7
|
+
* emitted from these definitions, so no handwritten spec exists. Handlers parse params from
|
|
8
|
+
* the `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
11
|
import { asString, legacyQuery, withEngineStamp } from "@mailwoman/api-kit";
|
|
12
12
|
import { photonToSchemaOrg } from "#projection";
|
|
13
13
|
import { PhotonMessageCollectionSchema, PhotonResponseSchema, reverseQueryParams, searchQueryParams } from "#schema";
|
|
14
|
-
/**
|
|
15
|
-
* Southern limit of latitude in WGS-84 degrees.
|
|
16
|
-
*/
|
|
17
14
|
const MIN_LATITUDE = -90;
|
|
18
|
-
/**
|
|
19
|
-
* Northern limit of latitude in WGS-84 degrees.
|
|
20
|
-
*/
|
|
21
15
|
const MAX_LATITUDE = 90;
|
|
22
|
-
/**
|
|
23
|
-
* Western limit of longitude in WGS-84 degrees.
|
|
24
|
-
*/
|
|
25
16
|
const MIN_LONGITUDE = -180;
|
|
26
|
-
/**
|
|
27
|
-
* Eastern limit of longitude in WGS-84 degrees.
|
|
28
|
-
*/
|
|
29
17
|
const MAX_LONGITUDE = 180;
|
|
30
18
|
const DEFAULT_LIMIT = 15;
|
|
31
19
|
const EMPTY = { type: "FeatureCollection", features: [] };
|
|
@@ -36,10 +24,10 @@ function asStringArray(raw) {
|
|
|
36
24
|
return s ? [s] : undefined;
|
|
37
25
|
}
|
|
38
26
|
/**
|
|
39
|
-
* A friendly
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
27
|
+
* A friendly html landing page for `GET /`.
|
|
28
|
+
*
|
|
29
|
+
* Upstream komoot/photon serves no root page, so there is no wire interface to match.
|
|
30
|
+
* Relative example URLs resolve against whatever host and port serve this.
|
|
43
31
|
*/
|
|
44
32
|
const ROOT_HTML = `<!doctype html>
|
|
45
33
|
<html lang="en">
|
|
@@ -61,7 +49,7 @@ footer { margin-top: 2rem; font-size: .9rem; opacity: .8 }
|
|
|
61
49
|
</head>
|
|
62
50
|
<body>
|
|
63
51
|
<h1>@mailwoman/photon</h1>
|
|
64
|
-
<p>A Photon-compatible autocomplete geocoding API — the same <code>/api</code> and <code>/reverse</code>
|
|
52
|
+
<p>A Photon-compatible autocomplete geocoding API — the same <code>/api</code> and <code>/reverse</code> interface, served from a SQLite gazetteer instead of an Elasticsearch cluster.</p>
|
|
65
53
|
<p>Try a query:</p>
|
|
66
54
|
<ul>
|
|
67
55
|
<li><a class="q" href="/api?q=berlin&limit=3">/api?q=berlin&limit=3</a></li>
|
|
@@ -133,7 +121,7 @@ export function registerPhotonRoutes(app, engine, stamp) {
|
|
|
133
121
|
layer: asStringArray(q["layer"]),
|
|
134
122
|
};
|
|
135
123
|
const collection = await engine.search(params);
|
|
136
|
-
//
|
|
124
|
+
// `format=jsonld` re-serializes the FeatureCollection as schema.org `Place[]` JSON-LD.
|
|
137
125
|
if (asString(q["format"]) === "jsonld") {
|
|
138
126
|
return c.json(photonToSchemaOrg(collection), 200);
|
|
139
127
|
}
|
|
@@ -159,7 +147,7 @@ export function registerPhotonRoutes(app, engine, stamp) {
|
|
|
159
147
|
radius: q["radius"] != null ? Number(q["radius"]) : undefined,
|
|
160
148
|
};
|
|
161
149
|
const collection = await engine.reverse(params);
|
|
162
|
-
//
|
|
150
|
+
// `format=jsonld` re-serializes the reverse FeatureCollection as schema.org `Place[]` JSON-LD.
|
|
163
151
|
if (asString(q["format"]) === "jsonld") {
|
|
164
152
|
return c.json(photonToSchemaOrg(collection), 200);
|
|
165
153
|
}
|
package/out/routes.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routes.js","sourceRoot":"","sources":["../lib/routes.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,WAAW,EAAoB,CAAC,EAAE,MAAM,mBAAmB,CAAA;AACpE,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AAI3E,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAC/C,OAAO,EAAE,6BAA6B,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAEpH
|
|
1
|
+
{"version":3,"file":"routes.js","sourceRoot":"","sources":["../lib/routes.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,WAAW,EAAoB,CAAC,EAAE,MAAM,mBAAmB,CAAA;AACpE,OAAO,EAAE,Q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