@jsm-mit/map-places-replicated-shards-package
v0.2.0
Published
The package of map-places: address search (autocomplete) and reverse geocoding from a replicated-shards group of IC canisters (a coordinator, a ticket core and worker copies) that hold OpenStreetMap indexes.
Readme
@jsm-mit/map-places-replicated-shards-package
The package of map-places: address search (autocomplete) and reverse geocoding from a group of
Internet Computer canisters (replicated shards): a coordinator, a ticket core and copies of
workers, each holding an OpenStreetMap index of one area (© OpenStreetMap contributors, ODbL).
Queries cost the caller nothing. It replaces the deprecated @jsm-mit/tigi-geo-package.
The group (0.2): MapPlacesClient
import { coordinatorTicketProvider, errorKeyOf, isTimeoutError, MapPlacesClient } from "@jsm-mit/map-places-replicated-shards-package";
const geo = new MapPlacesClient({
coordinatorId, // the coordinator of the group
identity: user, // the caller of the queries (a ticket names it)
ticketProvider, // where tickets come from (below)
});
const search = await geo.searchAsyncUnsafe("Family Mall", {
near: position, // { lat, lng }: nearest first; picks the area
limit: 5, // default 5, at most 10
lang: "en", // "en" / "pl" names where OSM has them
timeoutMs: 3_000,
});
// search.places[i]: { label, area, location: { lat, lng }, kind } like the front's Place
// search.nearInArea === false → the rider is outside every area: ask Photon instead
const pin = await geo.reverseAsyncUnsafe(point); // { label, area, location, kind, meters } | null- The client reads the areas and their live copies from the coordinator and keeps them
ttlSeconds.reverseasks the area that holds the point;searchthe area that holdsnear(withoutnear:options.area, else the first area). A point outside every area makes no call:reversegivesnull,searchno places withnearInArea: false. - A ticket (
replicated-shards.md) names the user, the area, a bbox, a time and one copy. The client keeps it per area, asks for the next one in the background in the last quarter of its life, and at once (with one retry of the call) when the worker refuses it (TicketExpired,TicketInvalid,TicketMissing,OutsideBbox). - Ticket providers:
- a system registered at the coordinator signs
issueTicketitself at the ticket core of the user (the coordinator names it,issuerFor):coordinatorTicketProvider({ coordinatorId, system: identity, user }); - a front asks its own backend canister (a registered system), which asks the ticket core
for the front's user:
ticketProvider: (request) => backend.placesTicket(request).
- a system registered at the coordinator signs
- Without a provider the client draws a live copy and sends no ticket — only while the copies do not require tickets.
- A copy that does not answer: the list is read again and the call is tried once more.
Errors: CanisterError with errorKeyOf(error) = NotReady (no live copy, no index),
InvalidData (a point that is not on Earth), the ticket refusals above (after the renewal),
and the refusals of the provider: Blocked (the user — a clear reason; show it),
RateLimited, Waiting, NotAuthorized. Timeout (isTimeoutError; renewals and retries
count) and CriticalCanisterError (transport; also a system the coordinator does not know).
The front falls back to Photon / Nominatim when the group throws, when nearInArea is false,
when places is empty, or when reverseAsyncUnsafe gives null.
From 0.1
0.2 is breaking: MapPlacesActor and MAP_PLACES_CANISTER_ID (the single canister backend8)
are gone from the public API; searchPlacesAsyncUnsafe is searchAsyncUnsafe of
MapPlacesClient. The place shapes (Place, PlaceSearch, ReversePlace) are the same.
Local replica: host: "http://127.0.0.1:4943".
Scripts
npm run test-unit— no canister (the client on a fake transport).npm run test-smoke— one copy (map-places-worker) on the LOCAL replica with the Iraq index (data/iraq-261104.tgi, orINDEX=…).npm run test-group— the group on the LOCAL replica: the coordinator, two copies of Iraq, tickets required (../scripts/check/local-coordinator-check.sh iraq, local test identitymrc-systemas the system).npm run sync-declarations—declarations/from../worker/map-places-worker.did,../coordinator/map-places-coordinator.didand../core/map-places-core.did.npm run publish-public— human-run; see the script for its refusals.
Before 0.2 the package was @jsm-mit/map-places-package (0.1, one canister: MapPlacesActor).
