@procedures/geo 0.28.0 → 0.29.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/CHANGELOG.md +29 -0
- package/README.md +15 -0
- package/dist/.tsbuildinfo +1 -1
- package/dist/geo.d.ts.map +1 -1
- package/dist/geo.js +4 -0
- package/dist/geo.js.map +1 -1
- package/dist/module.d.ts +11 -0
- package/dist/module.d.ts.map +1 -1
- package/dist/module.js +15 -1
- package/dist/module.js.map +1 -1
- package/dist/procedures.d.ts +19 -0
- package/dist/procedures.d.ts.map +1 -1
- package/dist/procedures.js +46 -26
- package/dist/procedures.js.map +1 -1
- package/package.json +2 -2
- package/src/geo.ts +4 -0
- package/src/module.ts +15 -1
- package/src/procedures.ts +61 -30
package/dist/geo.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"geo.d.ts","sourceRoot":"","sources":["../src/geo.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"geo.d.ts","sourceRoot":"","sources":["../src/geo.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,sCAAsC;AACtC,MAAM,WAAW,KAAK;IACpB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,aAAc,SAAQ,KAAK;IAC1C,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;CAC9B;AAED,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;AAED,6HAA6H;AAC7H,eAAO,MAAM,aAAa,wCAAwC,CAAC;AAEnE,0GAA0G;AAC1G,eAAO,MAAM,QAAQ,oCAAoC,CAAC;AAE1D;;;GAGG;AACH,MAAM,MAAM,SAAS,GAAG,CACtB,GAAG,EAAE,MAAM,EACX,I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S,CAAA;CAAE,GAC5H,OAAO,CAAC,WAAW,CAAC,CActB"}
|
package/dist/geo.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* Places on a map: the coordinates of an address (OpenStreetMap Nominatim) and the time and
|
|
3
3
|
* distance of a drive between two points (OSRM).
|
|
4
4
|
*/
|
|
5
|
+
import { InvocationError } from "@procedures/client/browser";
|
|
5
6
|
/** The public Nominatim server. Its policy: at most one request each second, and a User-Agent that names the application. */
|
|
6
7
|
export const NOMINATIM_URL = "https://nominatim.openstreetmap.org";
|
|
7
8
|
/** The public OSRM demonstration server. It has a fair-use limit. A self-hosted OSRM has the same API. */
|
|
@@ -15,6 +16,9 @@ export async function getJson(url, options, service) {
|
|
|
15
16
|
response = await fetchJson(url, { signal: AbortSignal.any(signals), headers: { accept: "application/json", ...options.headers } });
|
|
16
17
|
}
|
|
17
18
|
catch (error) {
|
|
19
|
+
// A refusal (the host policy of a `fetch` of `createHostFetch()`) keeps its code and its reason
|
|
20
|
+
if (error instanceof InvocationError && error.code === "FORBIDDEN")
|
|
21
|
+
throw error;
|
|
18
22
|
const reason = error.name === "TimeoutError" ? `no answer in ${options.timeoutMs} ms` : "the request failed";
|
|
19
23
|
throw new Error(`${service} did not answer: ${reason}`, { cause: error });
|
|
20
24
|
}
|
package/dist/geo.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"geo.js","sourceRoot":"","sources":["../src/geo.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"geo.js","sourceRoot":"","sources":["../src/geo.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAiB7D,6HAA6H;AAC7H,MAAM,CAAC,MAAM,aAAa,GAAG,qCAAqC,CAAC;AAEnE,0GAA0G;AAC1G,MAAM,CAAC,MAAM,QAAQ,GAAG,iCAAiC,CAAC;AAW1D,wFAAwF;AACxF,MAA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OAAO,CACzB,GAAG,OAAO,CAAC,OAAO,IAAI,QAAQ,qBAAqB,IAAI,CAAC,GAAG,IAAI,IAAI,CAAC,GAAG,IAAI,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,GAAG,iBAAiB,EAC5G,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,EAC9E,MAAM,CACP,CAAgF,CAAC;IAClF,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC;IAC/B,IAAI,IAAI,CAAC,IAAI,KAAK,IAAI,IAAI,KAAK,EAAE,QAAQ,KAAK,SAAS,IAAI,KAAK,CAAC,QAAQ,KAAK,SAAS,EAAE,CAAC;QACxF,MAAM,IAAI,KAAK,CAAC,wBAAwB,IAAI,CAAC,IAAI,IAAI,SAAS,GAAG,CAAC,CAAC;IACrE,CAAC;IACD,OAAO;QACL,EAAE,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE;QACjD,OAAO,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,GAAG,EAAE,CAAC,CAAC;KACtD,CAAC;AACJ,CAAC"}
|
package/dist/module.d.ts
CHANGED
|
@@ -2,8 +2,19 @@
|
|
|
2
2
|
* The procedures of @procedures/geo as data. Importing this file registers nothing.
|
|
3
3
|
*/
|
|
4
4
|
import { type ProcedureModule, type ProcedureRegistry } from "@procedures/client/browser";
|
|
5
|
+
import { type GeoProceduresOptions } from "./procedures.js";
|
|
5
6
|
export declare const geoModule: ProcedureModule;
|
|
6
7
|
export default geoModule;
|
|
8
|
+
/**
|
|
9
|
+
* This function gives the module with the settings of the host: the `fetch` of `geo.geocode` and
|
|
10
|
+
* `geo.route`. Without options, it gives `geoModule`. A Node host that takes calls from others
|
|
11
|
+
* gives `createHostFetch()` of `@procedures/http`, so the host policy examines each `baseUrl`.
|
|
12
|
+
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* createRegistry(createGeoModule({ fetch: createHostFetch() }));
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare function createGeoModule(options?: GeoProceduresOptions): ProcedureModule;
|
|
7
18
|
/**
|
|
8
19
|
* This function registers the procedures of @procedures/geo in a registry. The default is the
|
|
9
20
|
* global registry.
|
package/dist/module.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAqD,KAAK,eAAe,EAAE,KAAK,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAqD,KAAK,eAAe,EAAE,KAAK,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC7I,OAAO,EAAsC,KAAK,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAEhG,eAAO,MAAM,SAAS,EAAE,eAAgE,CAAC;eAE1E,SAAS;AAExB;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,OAAO,GAAE,oBAAyB,GAAG,eAAe,CAGnF;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,QAAQ,GAAE,iBAAsC,GAAG,IAAI,CAE5F"}
|
package/dist/module.js
CHANGED
|
@@ -2,9 +2,23 @@
|
|
|
2
2
|
* The procedures of @procedures/geo as data. Importing this file registers nothing.
|
|
3
3
|
*/
|
|
4
4
|
import { defineModule, registerModules, PROCEDURE_REGISTRY } from "@procedures/client/browser";
|
|
5
|
-
import { geoProcedures } from "./procedures.js";
|
|
5
|
+
import { createGeoProcedures, geoProcedures } from "./procedures.js";
|
|
6
6
|
export const geoModule = defineModule("@procedures/geo", geoProcedures);
|
|
7
7
|
export default geoModule;
|
|
8
|
+
/**
|
|
9
|
+
* This function gives the module with the settings of the host: the `fetch` of `geo.geocode` and
|
|
10
|
+
* `geo.route`. Without options, it gives `geoModule`. A Node host that takes calls from others
|
|
11
|
+
* gives `createHostFetch()` of `@procedures/http`, so the host policy examines each `baseUrl`.
|
|
12
|
+
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* createRegistry(createGeoModule({ fetch: createHostFetch() }));
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export function createGeoModule(options = {}) {
|
|
18
|
+
if (options.fetch === undefined)
|
|
19
|
+
return geoModule;
|
|
20
|
+
return defineModule("@procedures/geo", createGeoProcedures(options));
|
|
21
|
+
}
|
|
8
22
|
/**
|
|
9
23
|
* This function registers the procedures of @procedures/geo in a registry. The default is the
|
|
10
24
|
* global registry.
|
package/dist/module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module.js","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,kBAAkB,EAAgD,MAAM,4BAA4B,CAAC;AAC7I,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"module.js","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,kBAAkB,EAAgD,MAAM,4BAA4B,CAAC;AAC7I,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAA6B,MAAM,iBAAiB,CAAC;AAEhG,MAAM,CAAC,MAAM,SAAS,GAAoB,YAAY,CAAC,iBAAiB,EAAE,aAAa,CAAC,CAAC;AAEzF,eAAe,SAAS,CAAC;AAEzB;;;;;;;;GAQG;AACH,MAAM,UAAU,eAAe,CAAC,OAAO,GAAyB,EAAE;IAChE,IAAI,OAAO,CAAC,KAAK,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IAClD,OAAO,YAAY,CAAC,iBAAiB,EAAE,mBAAmB,CAAC,OAAO,CAAC,CAAC,CAAC;AACvE,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,qBAAqB,CAAC,QAAQ,GAAsB,kBAAkB;IACpF,eAAe,CAAC,QAAQ,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC;AACzC,CAAC"}
|
package/dist/procedures.d.ts
CHANGED
|
@@ -1,10 +1,29 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The procedures of `@procedures/geo`: `geo.geocode`, `geo.route`, `geo.distance` and `geo.geohash`.
|
|
3
|
+
*
|
|
4
|
+
* `geo.geocode` and `geo.route` send their requests with the `fetch` of the module. The default is
|
|
5
|
+
* the global `fetch`, so the root stays safe for a browser. A Node host that takes calls from
|
|
6
|
+
* others gives `createHostFetch()` of `@procedures/http` to `createGeoModule()`. Then the host
|
|
7
|
+
* policy refuses a `baseUrl` on a loopback, private or link-local address (audit pass 2, O55).
|
|
3
8
|
*/
|
|
4
9
|
import { type AnyProcedure } from "@procedures/client/browser";
|
|
10
|
+
import { type FetchJson } from "./geo.js";
|
|
11
|
+
/** The settings of the host for the procedures of this package. The procedure input cannot change them. */
|
|
12
|
+
export interface GeoProceduresOptions {
|
|
13
|
+
/**
|
|
14
|
+
* The function that sends the requests of `geo.geocode` and `geo.route`. The default is the
|
|
15
|
+
* global `fetch`. A Node host gives `createHostFetch()` of `@procedures/http`.
|
|
16
|
+
*/
|
|
17
|
+
readonly fetch?: FetchJson | undefined;
|
|
18
|
+
}
|
|
5
19
|
export declare const geoGeocodeProcedure: AnyProcedure;
|
|
6
20
|
export declare const geoRouteProcedure: AnyProcedure;
|
|
7
21
|
export declare const geoDistanceProcedure: AnyProcedure;
|
|
8
22
|
export declare const geoGeohashProcedure: AnyProcedure;
|
|
9
23
|
export declare const geoProcedures: AnyProcedure[];
|
|
24
|
+
/**
|
|
25
|
+
* This function gives the procedures of this package with the settings of the host. Without a
|
|
26
|
+
* `fetch`, it gives `geoProcedures`.
|
|
27
|
+
*/
|
|
28
|
+
export declare function createGeoProcedures(options?: GeoProceduresOptions): AnyProcedure[];
|
|
10
29
|
//# sourceMappingURL=procedures.d.ts.map
|
package/dist/procedures.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"procedures.d.ts","sourceRoot":"","sources":["../src/procedures.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"procedures.d.ts","sourceRoot":"","sources":["../src/procedures.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAA+B,KAAK,YAAY,EAAyB,MAAM,4BAA4B,CAAC;AAEnH,OAAO,EAAyB,KAAK,SAAS,EAAwC,MAAM,UAAU,CAAC;AAmBvG,2GAA2G;AAC3G,MAAM,WAAW,oBAAoB;IACnC;;;OAGG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,SAAS,GAAG,SAAS,CAAC;CACxC;AA2ED,eAAO,MAAM,mBAAmB,EAAE,YAA0C,CAAC;AAE7E,eAAO,MAAM,iBAAiB,EAAE,YAAwC,CAAC;AAMzE,eAAO,MAAM,oBAAoB,EAAE,YAUT,CAAC;AAM3B,eAAO,MAAM,mBAAmB,EAAE,YAUR,CAAC;AAE3B,eAAO,MAAM,aAAa,EAAE,YAAY,EAAwF,CAAC;AAEjI;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,GAAE,oBAAyB,GAAG,YAAY,EAAE,CAGtF"}
|
package/dist/procedures.js
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The procedures of `@procedures/geo`: `geo.geocode`, `geo.route`, `geo.distance` and `geo.geohash`.
|
|
3
|
+
*
|
|
4
|
+
* `geo.geocode` and `geo.route` send their requests with the `fetch` of the module. The default is
|
|
5
|
+
* the global `fetch`, so the root stays safe for a browser. A Node host that takes calls from
|
|
6
|
+
* others gives `createHostFetch()` of `@procedures/http` to `createGeoModule()`. Then the host
|
|
7
|
+
* policy refuses a `baseUrl` on a loopback, private or link-local address (audit pass 2, O55).
|
|
3
8
|
*/
|
|
4
9
|
import { createProcedure, zodAdapter } from "@procedures/client/browser";
|
|
5
10
|
import { z } from "zod";
|
|
@@ -28,21 +33,23 @@ const GeocodeOutputSchema = z.object({
|
|
|
28
33
|
found: z.boolean(),
|
|
29
34
|
result: z.object({ lat: z.number(), lon: z.number(), displayName: z.string() }).optional(),
|
|
30
35
|
});
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
|
|
36
|
+
function geocodeProcedure(fetch) {
|
|
37
|
+
return createProcedure()
|
|
38
|
+
.path(["geo", "geocode"])
|
|
39
|
+
.input(zodAdapter(GeocodeInputSchema))
|
|
40
|
+
.output(zodAdapter(GeocodeOutputSchema))
|
|
41
|
+
.meta({
|
|
42
|
+
description: "Find the coordinates of an address or a place name (OpenStreetMap Nominatim)",
|
|
43
|
+
args: ["query"],
|
|
44
|
+
output: "json",
|
|
45
|
+
effects: NETWORK_READ,
|
|
46
|
+
})
|
|
47
|
+
.handler(async (input, ctx) => {
|
|
48
|
+
const result = await geocode(input.query, { ...input, signal: ctx?.signal, fetch });
|
|
49
|
+
return result === undefined ? { found: false } : { found: true, result };
|
|
50
|
+
})
|
|
51
|
+
.build();
|
|
52
|
+
}
|
|
46
53
|
// =============================================================================
|
|
47
54
|
// geo.route
|
|
48
55
|
// =============================================================================
|
|
@@ -53,17 +60,21 @@ const RouteInputSchema = z.object({
|
|
|
53
60
|
timeoutMs,
|
|
54
61
|
});
|
|
55
62
|
const RouteOutputSchema = z.object({ km: z.number(), minutes: z.number() });
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
63
|
+
function routeProcedure(fetch) {
|
|
64
|
+
return createProcedure()
|
|
65
|
+
.path(["geo", "route"])
|
|
66
|
+
.input(zodAdapter(RouteInputSchema))
|
|
67
|
+
.output(zodAdapter(RouteOutputSchema))
|
|
68
|
+
.meta({
|
|
69
|
+
description: "Give the time and the distance of a drive between two points (OSRM)",
|
|
70
|
+
output: "json",
|
|
71
|
+
effects: NETWORK_READ,
|
|
72
|
+
})
|
|
73
|
+
.handler(async (input, ctx) => drivingRoute(input.from, input.to, { baseUrl: input.baseUrl, timeoutMs: input.timeoutMs, signal: ctx?.signal, fetch }))
|
|
74
|
+
.build();
|
|
75
|
+
}
|
|
76
|
+
export const geoGeocodeProcedure = geocodeProcedure(undefined);
|
|
77
|
+
export const geoRouteProcedure = routeProcedure(undefined);
|
|
67
78
|
// =============================================================================
|
|
68
79
|
// geo.distance
|
|
69
80
|
// =============================================================================
|
|
@@ -93,4 +104,13 @@ export const geoGeohashProcedure = createProcedure()
|
|
|
93
104
|
.handler(async (input) => geoGeohash(input))
|
|
94
105
|
.build();
|
|
95
106
|
export const geoProcedures = [geoGeocodeProcedure, geoRouteProcedure, geoDistanceProcedure, geoGeohashProcedure];
|
|
107
|
+
/**
|
|
108
|
+
* This function gives the procedures of this package with the settings of the host. Without a
|
|
109
|
+
* `fetch`, it gives `geoProcedures`.
|
|
110
|
+
*/
|
|
111
|
+
export function createGeoProcedures(options = {}) {
|
|
112
|
+
if (options.fetch === undefined)
|
|
113
|
+
return geoProcedures;
|
|
114
|
+
return [geocodeProcedure(options.fetch), routeProcedure(options.fetch), geoDistanceProcedure, geoGeohashProcedure];
|
|
115
|
+
}
|
|
96
116
|
//# sourceMappingURL=procedures.js.map
|
package/dist/procedures.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"procedures.js","sourceRoot":"","sources":["../src/procedures.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"procedures.js","sourceRoot":"","sources":["../src/procedures.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,eAAe,EAAE,UAAU,EAA4C,MAAM,4BAA4B,CAAC;AACnH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,YAAY,EAAE,OAAO,EAAwD,MAAM,UAAU,CAAC;AACvG,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AACzD,OAAO,EACL,sBAAsB,EACtB,uBAAuB,EACvB,qBAAqB,EACrB,sBAAsB,GAKvB,MAAM,YAAY,CAAC;AAEpB,MAAM,YAAY,GAAG,EAAE,KAAK,EAAE,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;AACxD,MAAM,IAAI,GAAG,EAAE,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;AACvC,MAAM,KAAK,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;AACjG,MAAM,SAAS,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,kDAAkD,CAAC,CAAC;AAWxI,gFAAgF;AAChF,cAAc;AACd,gFAAgF;AAEhF,MAAM,kBAAkB,GAAG,CAA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AC,KAAK,CAAC,CAAC;KACvF,KAAK,EAAkB,CAAC;AAE3B,MAAM,CAAC,MAAM,aAAa,GAAmB,CAAC,mBAAmB,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,mBAAmB,CAAC,CAAC;AAEjI;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAAC,OAAO,GAAyB,EAAE;IACpE,IAAI,OAAO,CAAC,KAAK,KAAK,SAAS;QAAE,OAAO,aAAa,CAAC;IACtD,OAAO,CAAC,gBAAgB,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,cAAc,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,oBAAoB,EAAE,mBAAmB,CAAC,CAAC;AACrH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package",
|
|
3
3
|
"name": "@procedures/geo",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.29.0",
|
|
5
5
|
"description": "Map procedures: the coordinates of an address (OpenStreetMap Nominatim), the time and distance of a drive (OSRM), the great-circle distance and the geohash.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"geocode",
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"provenance": true
|
|
65
65
|
},
|
|
66
66
|
"dependencies": {
|
|
67
|
-
"@procedures/client": "0.
|
|
67
|
+
"@procedures/client": "0.29.0",
|
|
68
68
|
"zod": "^4.6.5"
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
package/src/geo.ts
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
* distance of a drive between two points (OSRM).
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
import { InvocationError } from "@procedures/client/browser";
|
|
7
|
+
|
|
6
8
|
/** A point on the map, in degrees. */
|
|
7
9
|
export interface Point {
|
|
8
10
|
readonly lat: number;
|
|
@@ -50,6 +52,8 @@ export async function getJson(
|
|
|
50
52
|
try {
|
|
51
53
|
response = await fetchJson(url, { signal: AbortSignal.any(signals), headers: { accept: "application/json", ...options.headers } });
|
|
52
54
|
} catch (error) {
|
|
55
|
+
// A refusal (the host policy of a `fetch` of `createHostFetch()`) keeps its code and its reason
|
|
56
|
+
if (error instanceof InvocationError && error.code === "FORBIDDEN") throw error;
|
|
53
57
|
const reason = (error as { name?: string }).name === "TimeoutError" ? `no answer in ${options.timeoutMs} ms` : "the request failed";
|
|
54
58
|
throw new Error(`${service} did not answer: ${reason}`, { cause: error });
|
|
55
59
|
}
|
package/src/module.ts
CHANGED
|
@@ -3,12 +3,26 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import { defineModule, registerModules, PROCEDURE_REGISTRY, type ProcedureModule, type ProcedureRegistry } from "@procedures/client/browser";
|
|
6
|
-
import { geoProcedures } from "./procedures.js";
|
|
6
|
+
import { createGeoProcedures, geoProcedures, type GeoProceduresOptions } from "./procedures.js";
|
|
7
7
|
|
|
8
8
|
export const geoModule: ProcedureModule = defineModule("@procedures/geo", geoProcedures);
|
|
9
9
|
|
|
10
10
|
export default geoModule;
|
|
11
11
|
|
|
12
|
+
/**
|
|
13
|
+
* This function gives the module with the settings of the host: the `fetch` of `geo.geocode` and
|
|
14
|
+
* `geo.route`. Without options, it gives `geoModule`. A Node host that takes calls from others
|
|
15
|
+
* gives `createHostFetch()` of `@procedures/http`, so the host policy examines each `baseUrl`.
|
|
16
|
+
*
|
|
17
|
+
* ```ts
|
|
18
|
+
* createRegistry(createGeoModule({ fetch: createHostFetch() }));
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export function createGeoModule(options: GeoProceduresOptions = {}): ProcedureModule {
|
|
22
|
+
if (options.fetch === undefined) return geoModule;
|
|
23
|
+
return defineModule("@procedures/geo", createGeoProcedures(options));
|
|
24
|
+
}
|
|
25
|
+
|
|
12
26
|
/**
|
|
13
27
|
* This function registers the procedures of @procedures/geo in a registry. The default is the
|
|
14
28
|
* global registry.
|
package/src/procedures.ts
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The procedures of `@procedures/geo`: `geo.geocode`, `geo.route`, `geo.distance` and `geo.geohash`.
|
|
3
|
+
*
|
|
4
|
+
* `geo.geocode` and `geo.route` send their requests with the `fetch` of the module. The default is
|
|
5
|
+
* the global `fetch`, so the root stays safe for a browser. A Node host that takes calls from
|
|
6
|
+
* others gives `createHostFetch()` of `@procedures/http` to `createGeoModule()`. Then the host
|
|
7
|
+
* policy refuses a `baseUrl` on a loopback, private or link-local address (audit pass 2, O55).
|
|
3
8
|
*/
|
|
4
9
|
|
|
5
10
|
import { createProcedure, zodAdapter, type AnyProcedure, type ProcedureContext } from "@procedures/client/browser";
|
|
6
11
|
import { z } from "zod";
|
|
7
|
-
import { drivingRoute, geocode, type GeocodeResult, type RouteResult } from "./geo.js";
|
|
12
|
+
import { drivingRoute, geocode, type FetchJson, type GeocodeResult, type RouteResult } from "./geo.js";
|
|
8
13
|
import { geoDistance } from "./procedures/geo/distance.js";
|
|
9
14
|
import { geoGeohash } from "./procedures/geo/geohash.js";
|
|
10
15
|
import {
|
|
@@ -23,6 +28,15 @@ const PURE = { reads: [], writes: [] };
|
|
|
23
28
|
const point = z.object({ lat: z.number().min(-90).max(90), lon: z.number().min(-180).max(180) });
|
|
24
29
|
const timeoutMs = z.number().int().positive().max(120_000).default(20_000).describe("The time limit, in milliseconds (default: 20000)");
|
|
25
30
|
|
|
31
|
+
/** The settings of the host for the procedures of this package. The procedure input cannot change them. */
|
|
32
|
+
export interface GeoProceduresOptions {
|
|
33
|
+
/**
|
|
34
|
+
* The function that sends the requests of `geo.geocode` and `geo.route`. The default is the
|
|
35
|
+
* global `fetch`. A Node host gives `createHostFetch()` of `@procedures/http`.
|
|
36
|
+
*/
|
|
37
|
+
readonly fetch?: FetchJson | undefined;
|
|
38
|
+
}
|
|
39
|
+
|
|
26
40
|
// =============================================================================
|
|
27
41
|
// geo.geocode
|
|
28
42
|
// =============================================================================
|
|
@@ -48,21 +62,23 @@ const GeocodeOutputSchema = z.object({
|
|
|
48
62
|
result: z.object({ lat: z.number(), lon: z.number(), displayName: z.string() }).optional(),
|
|
49
63
|
});
|
|
50
64
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
65
|
+
function geocodeProcedure(fetch: FetchJson | undefined): AnyProcedure {
|
|
66
|
+
return createProcedure()
|
|
67
|
+
.path(["geo", "geocode"])
|
|
68
|
+
.input(zodAdapter<GeocodeInput>(GeocodeInputSchema))
|
|
69
|
+
.output(zodAdapter<GeocodeOutput>(GeocodeOutputSchema))
|
|
70
|
+
.meta({
|
|
71
|
+
description: "Find the coordinates of an address or a place name (OpenStreetMap Nominatim)",
|
|
72
|
+
args: ["query"],
|
|
73
|
+
output: "json",
|
|
74
|
+
effects: NETWORK_READ,
|
|
75
|
+
})
|
|
76
|
+
.handler(async (input: GeocodeInput, ctx?: ProcedureContext): Promise<GeocodeOutput> => {
|
|
77
|
+
const result = await geocode(input.query, { ...input, signal: ctx?.signal, fetch });
|
|
78
|
+
return result === undefined ? { found: false } : { found: true, result };
|
|
79
|
+
})
|
|
80
|
+
.build() as AnyProcedure;
|
|
81
|
+
}
|
|
66
82
|
|
|
67
83
|
// =============================================================================
|
|
68
84
|
// geo.route
|
|
@@ -77,20 +93,26 @@ const RouteInputSchema = z.object({
|
|
|
77
93
|
type RouteInput = z.infer<typeof RouteInputSchema>;
|
|
78
94
|
const RouteOutputSchema = z.object({ km: z.number(), minutes: z.number() });
|
|
79
95
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
96
|
+
function routeProcedure(fetch: FetchJson | undefined): AnyProcedure {
|
|
97
|
+
return createProcedure()
|
|
98
|
+
.path(["geo", "route"])
|
|
99
|
+
.input(zodAdapter<RouteInput>(RouteInputSchema))
|
|
100
|
+
.output(zodAdapter<RouteResult>(RouteOutputSchema))
|
|
101
|
+
.meta({
|
|
102
|
+
description: "Give the time and the distance of a drive between two points (OSRM)",
|
|
103
|
+
output: "json",
|
|
104
|
+
effects: NETWORK_READ,
|
|
105
|
+
})
|
|
106
|
+
.handler(
|
|
107
|
+
async (input: RouteInput, ctx?: ProcedureContext): Promise<RouteResult> =>
|
|
108
|
+
drivingRoute(input.from, input.to, { baseUrl: input.baseUrl, timeoutMs: input.timeoutMs, signal: ctx?.signal, fetch })
|
|
109
|
+
)
|
|
110
|
+
.build() as AnyProcedure;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export const geoGeocodeProcedure: AnyProcedure = geocodeProcedure(undefined);
|
|
114
|
+
|
|
115
|
+
export const geoRouteProcedure: AnyProcedure = routeProcedure(undefined);
|
|
94
116
|
|
|
95
117
|
// =============================================================================
|
|
96
118
|
// geo.distance
|
|
@@ -125,3 +147,12 @@ export const geoGeohashProcedure: AnyProcedure = createProcedure()
|
|
|
125
147
|
.build() as AnyProcedure;
|
|
126
148
|
|
|
127
149
|
export const geoProcedures: AnyProcedure[] = [geoGeocodeProcedure, geoRouteProcedure, geoDistanceProcedure, geoGeohashProcedure];
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* This function gives the procedures of this package with the settings of the host. Without a
|
|
153
|
+
* `fetch`, it gives `geoProcedures`.
|
|
154
|
+
*/
|
|
155
|
+
export function createGeoProcedures(options: GeoProceduresOptions = {}): AnyProcedure[] {
|
|
156
|
+
if (options.fetch === undefined) return geoProcedures;
|
|
157
|
+
return [geocodeProcedure(options.fetch), routeProcedure(options.fetch), geoDistanceProcedure, geoGeohashProcedure];
|
|
158
|
+
}
|