mapricot 0.11.0 → 0.12.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 +8 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +4 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -30,6 +30,7 @@ Methods are grouped by product, the same way as the API's paths. Each returns th
|
|
|
30
30
|
| Method | Endpoint |
|
|
31
31
|
| --- | --- |
|
|
32
32
|
| `client.geocoding.search(q, { focus, country, limit, lang })` | [`GET /geocoding/v1/search`](https://mapricot.com/docs/geocoding/#find-an-address) |
|
|
33
|
+
| `client.geocoding.searchBatch(queries)` | [`POST /geocoding/v1/search/batch`](https://mapricot.com/docs/geocoding/#search-a-list-of-addresses) |
|
|
33
34
|
| `client.geocoding.autocomplete(q, { focus, country, limit, lang })` | [`GET /geocoding/v1/autocomplete`](https://mapricot.com/docs/geocoding/#suggest-as-people-type) |
|
|
34
35
|
| `client.geocoding.reverse(lat, lon, { limit, lang })` | [`GET /geocoding/v1/reverse`](https://mapricot.com/docs/geocoding/#find-the-address-at-a-point) |
|
|
35
36
|
| `client.places.nearby(lat, lon, { category, radius, limit, lang })` | [`GET /places/v1/nearby`](https://mapricot.com/docs/places/#list-places-around-a-point) |
|
|
@@ -48,6 +49,13 @@ const { routes } = await client.routing.route([{ lat: 45.5189, lon: -122.6793 },
|
|
|
48
49
|
console.log(routes[0].durationSeconds);
|
|
49
50
|
```
|
|
50
51
|
|
|
52
|
+
`searchBatch` runs up to 100 searches in one request. Each query is an object of `search`'s parameters, and `responses` answers them in the same order, each with `results` and `attribution`, or an `error` with the `code` and `message` that search would get, without rejecting. Each completed search is billed as one request; errors aren't.
|
|
53
|
+
|
|
54
|
+
```js
|
|
55
|
+
const { responses } = await client.geocoding.searchBatch([{ q: "128 SW 3rd Ave, Portland", limit: 1 }, { q: "10 Downing Street, London", limit: 1 }]);
|
|
56
|
+
for (const response of responses) console.log(response.error?.message ?? response.results[0].label);
|
|
57
|
+
```
|
|
58
|
+
|
|
51
59
|
To cancel a request, such as an autocomplete request for text that has since changed, pass an `AbortSignal` as `signal` to any method. The request then rejects with an `AbortError`:
|
|
52
60
|
|
|
53
61
|
```js
|
package/dist/index.d.ts
CHANGED
|
@@ -35,6 +35,27 @@ export interface Places {
|
|
|
35
35
|
results: Place[];
|
|
36
36
|
attribution: Attribution[];
|
|
37
37
|
}
|
|
38
|
+
/** One search in a batch, with the same parameters as `geocoding.search`. */
|
|
39
|
+
export interface SearchQuery {
|
|
40
|
+
q: string;
|
|
41
|
+
focus?: Point;
|
|
42
|
+
country?: string | string[];
|
|
43
|
+
limit?: number;
|
|
44
|
+
lang?: string;
|
|
45
|
+
}
|
|
46
|
+
/** One search's answer in a batch: results and attribution, or the error the search would get on its own, unbilled. */
|
|
47
|
+
export interface SearchResponse {
|
|
48
|
+
results?: Place[];
|
|
49
|
+
attribution?: Attribution[];
|
|
50
|
+
error?: {
|
|
51
|
+
code: string;
|
|
52
|
+
message: string;
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
export interface SearchBatch {
|
|
56
|
+
/** One per query, in the queries' order. */
|
|
57
|
+
responses: SearchResponse[];
|
|
58
|
+
}
|
|
38
59
|
export interface PlaceResult {
|
|
39
60
|
result: Place;
|
|
40
61
|
attribution: Attribution[];
|
|
@@ -159,6 +180,8 @@ export declare class Mapricot {
|
|
|
159
180
|
readonly geocoding: {
|
|
160
181
|
/** Find addresses and places matching free text. */
|
|
161
182
|
search: (q: string, { signal, ...options }?: SearchOptions) => Promise<Places>;
|
|
183
|
+
/** Run up to 100 searches in one request. Each completed search is billed as one request. */
|
|
184
|
+
searchBatch: (queries: SearchQuery[], { signal }?: RequestOptions) => Promise<SearchBatch>;
|
|
162
185
|
/** Suggest addresses and places as someone types. */
|
|
163
186
|
autocomplete: (q: string, { signal, ...options }?: SearchOptions) => Promise<Places>;
|
|
164
187
|
/** Find the address nearest a coordinate, or the area around it. */
|
package/dist/index.js
CHANGED
|
@@ -30,6 +30,10 @@ export class Mapricot {
|
|
|
30
30
|
this.geocoding = {
|
|
31
31
|
/** Find addresses and places matching free text. */
|
|
32
32
|
search: (q, { signal, ...options } = {}) => __classPrivateFieldGet(this, _Mapricot_instances, "m", _Mapricot_request).call(this, "GET", "/geocoding/v1/search", { q, ...options }, signal),
|
|
33
|
+
/** Run up to 100 searches in one request. Each completed search is billed as one request. */
|
|
34
|
+
searchBatch: (queries, { signal } = {}) => __classPrivateFieldGet(this, _Mapricot_instances, "m", _Mapricot_request).call(this, "POST", "/geocoding/v1/search/batch", {}, signal, {
|
|
35
|
+
queries: queries.map((query) => Object.fromEntries(Object.entries(query).map(([name, value]) => [name, format(value)]))),
|
|
36
|
+
}),
|
|
33
37
|
/** Suggest addresses and places as someone types. */
|
|
34
38
|
autocomplete: (q, { signal, ...options } = {}) => __classPrivateFieldGet(this, _Mapricot_instances, "m", _Mapricot_request).call(this, "GET", "/geocoding/v1/autocomplete", { q, ...options }, signal),
|
|
35
39
|
/** Find the address nearest a coordinate, or the area around it. */
|