@jsm-mit/map-routes-package 0.0.0-stage → 0.2.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 +64 -2
- package/declarations/map-routes-coordinator/map-routes-coordinator.did +485 -0
- package/declarations/map-routes-coordinator/map-routes-coordinator.did.d.ts +764 -0
- package/declarations/map-routes-coordinator/map-routes-coordinator.did.js +303 -0
- package/declarations/map-routes-core/map-routes-core.did +107 -0
- package/declarations/map-routes-core/map-routes-core.did.d.ts +171 -0
- package/declarations/map-routes-core/map-routes-core.did.js +108 -0
- package/declarations/map-routes-worker/map-routes-worker.did +172 -0
- package/declarations/map-routes-worker/map-routes-worker.did.d.ts +296 -0
- package/declarations/map-routes-worker/map-routes-worker.did.js +128 -0
- package/dist/canister-actor.d.ts +59 -0
- package/dist/canister-actor.d.ts.map +1 -0
- package/dist/canister-actor.js +150 -0
- package/dist/client.d.ts +109 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +174 -0
- package/dist/index.d.ts +50 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +49 -0
- package/dist/passes.d.ts +37 -0
- package/dist/passes.d.ts.map +1 -0
- package/dist/passes.js +28 -0
- package/dist/types.d.ts +5 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +1 -0
- package/package.json +51 -5
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
type BeginUploadArgs = record {
|
|
2
|
+
// sha256 (hex) of the graph file.
|
|
3
|
+
sha256 : text;
|
|
4
|
+
// Bytes of the graph file (`map-routes-build build` output, format TMC3).
|
|
5
|
+
size : nat64;
|
|
6
|
+
osmDate : text;
|
|
7
|
+
};
|
|
8
|
+
type BufferInfo = record {
|
|
9
|
+
sha256 : text;
|
|
10
|
+
size : nat64;
|
|
11
|
+
startedAtNs : nat64;
|
|
12
|
+
state : BufferState;
|
|
13
|
+
buffer : nat8;
|
|
14
|
+
osmDate : text;
|
|
15
|
+
};
|
|
16
|
+
type BufferState = variant { Uploading; Active; Ready };
|
|
17
|
+
type CopyFromArgs = record {
|
|
18
|
+
// A worker that lists this canister in its peers.
|
|
19
|
+
source : principal;
|
|
20
|
+
};
|
|
21
|
+
type CopyStatus = record {
|
|
22
|
+
sha256 : text;
|
|
23
|
+
source : principal;
|
|
24
|
+
size : nat64;
|
|
25
|
+
// Bytes written so far.
|
|
26
|
+
copied : nat64;
|
|
27
|
+
};
|
|
28
|
+
// The fastest route by car between two points.
|
|
29
|
+
type Distance = record {
|
|
30
|
+
meters : nat64;
|
|
31
|
+
snapToMeters : nat32;
|
|
32
|
+
seconds : nat64;
|
|
33
|
+
// Instructions this query took (measurement of the PoC).
|
|
34
|
+
instructions : nat64;
|
|
35
|
+
// sha256 (hex) of the graph, as printed by `map-routes-build build`.
|
|
36
|
+
graphSha256 : text;
|
|
37
|
+
// Date of the OpenStreetMap extract the graph was built from.
|
|
38
|
+
osmDate : text;
|
|
39
|
+
// How far each point lies from the junction the route starts or ends at.
|
|
40
|
+
snapFromMeters : nat32;
|
|
41
|
+
};
|
|
42
|
+
type DistanceArgs = record {
|
|
43
|
+
to : Point;
|
|
44
|
+
from : Point;
|
|
45
|
+
// The pass from the coordinator (`map-routes-pass`); required once `passRequired`.
|
|
46
|
+
pass : opt blob;
|
|
47
|
+
};
|
|
48
|
+
type Error = variant {
|
|
49
|
+
// No road within `MAX_SNAP_M` of the point named ("from" / "to" / "points[i]").
|
|
50
|
+
OutsideArea : text;
|
|
51
|
+
// A point lies outside the bbox of the pass ("from" / "to" / "points[i]").
|
|
52
|
+
OutsideBbox : text;
|
|
53
|
+
// No graph is active yet, or the active one is of an older format.
|
|
54
|
+
NotReady;
|
|
55
|
+
NotFound;
|
|
56
|
+
NotAuthorized : text;
|
|
57
|
+
// The pass is past its time: ask the coordinator for a new one.
|
|
58
|
+
PassExpired;
|
|
59
|
+
NoRoute;
|
|
60
|
+
InvalidData : text;
|
|
61
|
+
// `passRequired` and the query carries no pass.
|
|
62
|
+
PassMissing;
|
|
63
|
+
// The pass does not hold: format, key, signature, copy, caller or area (named).
|
|
64
|
+
PassInvalid : text;
|
|
65
|
+
};
|
|
66
|
+
// The fastest route from one point of a `route` query to the next.
|
|
67
|
+
type Leg = record {
|
|
68
|
+
meters : nat64;
|
|
69
|
+
// Encoded polyline of precision 5 (as ORS sends it), from the junction the leg starts
|
|
70
|
+
// at to the one it ends at; "" when the line was not asked for.
|
|
71
|
+
line : text;
|
|
72
|
+
seconds : nat64;
|
|
73
|
+
};
|
|
74
|
+
// One pass key of this copy, from the coordinator.
|
|
75
|
+
type PassKeyArgs = record {
|
|
76
|
+
id : nat32;
|
|
77
|
+
// 32 bytes.
|
|
78
|
+
key : blob;
|
|
79
|
+
// An old key after a rotation stays valid until then; `null` = no end.
|
|
80
|
+
validUntilNs : opt nat64;
|
|
81
|
+
};
|
|
82
|
+
// The pass check as `getStatus` shows it: never the keys.
|
|
83
|
+
type PassStatus = record {
|
|
84
|
+
keyIds : vec nat32;
|
|
85
|
+
area : opt text;
|
|
86
|
+
required : bool;
|
|
87
|
+
};
|
|
88
|
+
type Point = record { lat : float64; lon : float64 };
|
|
89
|
+
type ReadChunkArgs = record {
|
|
90
|
+
// The graph to read: the buffer holding a committed graph with this sha256.
|
|
91
|
+
sha256 : text;
|
|
92
|
+
offset : nat64;
|
|
93
|
+
// 1..=`MAX_CHUNK_BYTES`.
|
|
94
|
+
length : nat32;
|
|
95
|
+
};
|
|
96
|
+
type Result = variant { Ok : BufferInfo; Err : Error };
|
|
97
|
+
type Result_1 = variant { Ok : Distance; Err : Error };
|
|
98
|
+
type Result_2 = variant { Ok : Status; Err : Error };
|
|
99
|
+
type Result_3 = variant { Ok : blob; Err : Error };
|
|
100
|
+
type Result_4 = variant { Ok : RouteAnswer; Err : Error };
|
|
101
|
+
type Result_5 = variant { Ok : PassStatus; Err : Error };
|
|
102
|
+
type Result_6 = variant { Ok; Err : Error };
|
|
103
|
+
type RouteAnswer = record {
|
|
104
|
+
// How far each point lies from the junction its legs start or end at.
|
|
105
|
+
snapMeters : vec nat32;
|
|
106
|
+
// One leg for each pair of consecutive points.
|
|
107
|
+
legs : vec Leg;
|
|
108
|
+
instructions : nat64;
|
|
109
|
+
graphSha256 : text;
|
|
110
|
+
osmDate : text;
|
|
111
|
+
};
|
|
112
|
+
type RouteArgs = record {
|
|
113
|
+
// Whether each leg carries its line.
|
|
114
|
+
line : bool;
|
|
115
|
+
// The pass from the coordinator (`map-routes-pass`); required once `passRequired`.
|
|
116
|
+
pass : opt blob;
|
|
117
|
+
// 2..=`MAX_ROUTE_POINTS` points, driven in this order.
|
|
118
|
+
points : vec Point;
|
|
119
|
+
};
|
|
120
|
+
type SetPassConfigArgs = record {
|
|
121
|
+
// The area of this worker; a pass for another area is refused.
|
|
122
|
+
area : text;
|
|
123
|
+
// 0..=`MAX_PASS_KEYS` keys; replaces the ones held.
|
|
124
|
+
keys : vec PassKeyArgs;
|
|
125
|
+
// Without a pass `distance` and `route` answer `PassMissing`.
|
|
126
|
+
required : bool;
|
|
127
|
+
};
|
|
128
|
+
type Status = record {
|
|
129
|
+
stableBytes : nat64;
|
|
130
|
+
heapBytes : nat64;
|
|
131
|
+
// A copy from another worker that has not ended (`copyFrom`).
|
|
132
|
+
copy : opt CopyStatus;
|
|
133
|
+
// The pass check; `opt` so that a newer package reads an older canister.
|
|
134
|
+
pass : opt PassStatus;
|
|
135
|
+
// Who may upload and commit a graph besides the controllers (`setUploaders`).
|
|
136
|
+
uploaders : opt vec principal;
|
|
137
|
+
// Nodes of the graph that answers `distance`; 0 when none is active.
|
|
138
|
+
nodes : nat64;
|
|
139
|
+
buffers : vec BufferInfo;
|
|
140
|
+
// Workers that may read this graph (`setPeers`).
|
|
141
|
+
peers : opt vec principal;
|
|
142
|
+
};
|
|
143
|
+
type UploadChunkArgs = record { offset : nat64; bytes : blob };
|
|
144
|
+
service : () -> {
|
|
145
|
+
// Switches `distance` to the inactive buffer — a new graph, or back to the previous one.
|
|
146
|
+
activate : () -> (Result);
|
|
147
|
+
// Starts an upload into the inactive buffer; whatever was there is dropped.
|
|
148
|
+
beginUpload : (BeginUploadArgs) -> (Result);
|
|
149
|
+
// Checks the hash and the header of the uploaded graph; the buffer becomes Ready.
|
|
150
|
+
commitUpload : () -> (Result);
|
|
151
|
+
// Pulls the active graph of `source` into the inactive buffer, chunk by chunk, and commits
|
|
152
|
+
// it (hash and header checked). It does not activate it. Called again after a stop, it goes
|
|
153
|
+
// on where it stopped; the source must list this canister in its peers.
|
|
154
|
+
copyFrom : (CopyFromArgs) -> (Result);
|
|
155
|
+
// The fastest route by car from one point to another. Public.
|
|
156
|
+
distance : (DistanceArgs) -> (Result_1) query;
|
|
157
|
+
getStatus : () -> (Result_2) query;
|
|
158
|
+
// The active graph, for a copy: sha256, size, date. Controllers and peers.
|
|
159
|
+
graphInfo : () -> (Result) query;
|
|
160
|
+
// Bytes of a committed graph (by its sha256), for a copy. Controllers and peers.
|
|
161
|
+
readChunk : (ReadChunkArgs) -> (Result_3) query;
|
|
162
|
+
// The fastest route by car through 2..=5 points, leg by leg, with each leg's line when
|
|
163
|
+
// asked. Public.
|
|
164
|
+
route : (RouteArgs) -> (Result_4) query;
|
|
165
|
+
// Sets the pass check: required or not, the area, the keys (from the coordinator).
|
|
166
|
+
setPassConfig : (SetPassConfigArgs) -> (Result_5);
|
|
167
|
+
// Sets the workers that may read the graph to copy it (the coordinator lists the copies).
|
|
168
|
+
setPeers : (vec principal) -> (Result_6);
|
|
169
|
+
// Sets who may upload and commit a graph besides the controllers (not activate it).
|
|
170
|
+
setUploaders : (vec principal) -> (Result_6);
|
|
171
|
+
uploadChunk : (UploadChunkArgs) -> (Result_6);
|
|
172
|
+
}
|
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
import type { Principal } from '@icp-sdk/core/principal';
|
|
2
|
+
import type { ActorMethod } from '@icp-sdk/core/agent';
|
|
3
|
+
import type { IDL } from '@icp-sdk/core/candid';
|
|
4
|
+
|
|
5
|
+
export interface BeginUploadArgs {
|
|
6
|
+
/**
|
|
7
|
+
* sha256 (hex) of the graph file.
|
|
8
|
+
*/
|
|
9
|
+
'sha256' : string,
|
|
10
|
+
/**
|
|
11
|
+
* Bytes of the graph file (`map-routes-build build` output, format TMC3).
|
|
12
|
+
*/
|
|
13
|
+
'size' : bigint,
|
|
14
|
+
'osmDate' : string,
|
|
15
|
+
}
|
|
16
|
+
export interface BufferInfo {
|
|
17
|
+
'sha256' : string,
|
|
18
|
+
'size' : bigint,
|
|
19
|
+
'startedAtNs' : bigint,
|
|
20
|
+
'state' : BufferState,
|
|
21
|
+
'buffer' : number,
|
|
22
|
+
'osmDate' : string,
|
|
23
|
+
}
|
|
24
|
+
export type BufferState = { 'Uploading' : null } |
|
|
25
|
+
{ 'Active' : null } |
|
|
26
|
+
{ 'Ready' : null };
|
|
27
|
+
export interface CopyFromArgs {
|
|
28
|
+
/**
|
|
29
|
+
* A worker that lists this canister in its peers.
|
|
30
|
+
*/
|
|
31
|
+
'source' : Principal,
|
|
32
|
+
}
|
|
33
|
+
export interface CopyStatus {
|
|
34
|
+
'sha256' : string,
|
|
35
|
+
'source' : Principal,
|
|
36
|
+
'size' : bigint,
|
|
37
|
+
/**
|
|
38
|
+
* Bytes written so far.
|
|
39
|
+
*/
|
|
40
|
+
'copied' : bigint,
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* The fastest route by car between two points.
|
|
44
|
+
*/
|
|
45
|
+
export interface Distance {
|
|
46
|
+
'meters' : bigint,
|
|
47
|
+
'snapToMeters' : number,
|
|
48
|
+
'seconds' : bigint,
|
|
49
|
+
/**
|
|
50
|
+
* Instructions this query took (measurement of the PoC).
|
|
51
|
+
*/
|
|
52
|
+
'instructions' : bigint,
|
|
53
|
+
/**
|
|
54
|
+
* sha256 (hex) of the graph, as printed by `map-routes-build build`.
|
|
55
|
+
*/
|
|
56
|
+
'graphSha256' : string,
|
|
57
|
+
/**
|
|
58
|
+
* Date of the OpenStreetMap extract the graph was built from.
|
|
59
|
+
*/
|
|
60
|
+
'osmDate' : string,
|
|
61
|
+
/**
|
|
62
|
+
* How far each point lies from the junction the route starts or ends at.
|
|
63
|
+
*/
|
|
64
|
+
'snapFromMeters' : number,
|
|
65
|
+
}
|
|
66
|
+
export interface DistanceArgs {
|
|
67
|
+
'to' : Point,
|
|
68
|
+
'from' : Point,
|
|
69
|
+
/**
|
|
70
|
+
* The pass from the coordinator (`map-routes-pass`); required once `passRequired`.
|
|
71
|
+
*/
|
|
72
|
+
'pass' : [] | [Uint8Array | number[]],
|
|
73
|
+
}
|
|
74
|
+
export type Error = {
|
|
75
|
+
/**
|
|
76
|
+
* No road within `MAX_SNAP_M` of the point named ("from" / "to" / "points[i]").
|
|
77
|
+
*/
|
|
78
|
+
'OutsideArea' : string
|
|
79
|
+
} |
|
|
80
|
+
{
|
|
81
|
+
/**
|
|
82
|
+
* A point lies outside the bbox of the pass ("from" / "to" / "points[i]").
|
|
83
|
+
*/
|
|
84
|
+
'OutsideBbox' : string
|
|
85
|
+
} |
|
|
86
|
+
{
|
|
87
|
+
/**
|
|
88
|
+
* No graph is active yet, or the active one is of an older format.
|
|
89
|
+
*/
|
|
90
|
+
'NotReady' : null
|
|
91
|
+
} |
|
|
92
|
+
{ 'NotFound' : null } |
|
|
93
|
+
{ 'NotAuthorized' : string } |
|
|
94
|
+
{
|
|
95
|
+
/**
|
|
96
|
+
* The pass is past its time: ask the coordinator for a new one.
|
|
97
|
+
*/
|
|
98
|
+
'PassExpired' : null
|
|
99
|
+
} |
|
|
100
|
+
{ 'NoRoute' : null } |
|
|
101
|
+
{ 'InvalidData' : string } |
|
|
102
|
+
{
|
|
103
|
+
/**
|
|
104
|
+
* `passRequired` and the query carries no pass.
|
|
105
|
+
*/
|
|
106
|
+
'PassMissing' : null
|
|
107
|
+
} |
|
|
108
|
+
{
|
|
109
|
+
/**
|
|
110
|
+
* The pass does not hold: format, key, signature, copy, caller or area (named).
|
|
111
|
+
*/
|
|
112
|
+
'PassInvalid' : string
|
|
113
|
+
};
|
|
114
|
+
/**
|
|
115
|
+
* The fastest route from one point of a `route` query to the next.
|
|
116
|
+
*/
|
|
117
|
+
export interface Leg {
|
|
118
|
+
'meters' : bigint,
|
|
119
|
+
/**
|
|
120
|
+
* Encoded polyline of precision 5 (as ORS sends it), from the junction the leg starts
|
|
121
|
+
* at to the one it ends at; "" when the line was not asked for.
|
|
122
|
+
*/
|
|
123
|
+
'line' : string,
|
|
124
|
+
'seconds' : bigint,
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* One pass key of this copy, from the coordinator.
|
|
128
|
+
*/
|
|
129
|
+
export interface PassKeyArgs {
|
|
130
|
+
'id' : number,
|
|
131
|
+
/**
|
|
132
|
+
* 32 bytes.
|
|
133
|
+
*/
|
|
134
|
+
'key' : Uint8Array | number[],
|
|
135
|
+
/**
|
|
136
|
+
* An old key after a rotation stays valid until then; `null` = no end.
|
|
137
|
+
*/
|
|
138
|
+
'validUntilNs' : [] | [bigint],
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* The pass check as `getStatus` shows it: never the keys.
|
|
142
|
+
*/
|
|
143
|
+
export interface PassStatus {
|
|
144
|
+
'keyIds' : Uint32Array | number[],
|
|
145
|
+
'area' : [] | [string],
|
|
146
|
+
'required' : boolean,
|
|
147
|
+
}
|
|
148
|
+
export interface Point { 'lat' : number, 'lon' : number }
|
|
149
|
+
export interface ReadChunkArgs {
|
|
150
|
+
/**
|
|
151
|
+
* The graph to read: the buffer holding a committed graph with this sha256.
|
|
152
|
+
*/
|
|
153
|
+
'sha256' : string,
|
|
154
|
+
'offset' : bigint,
|
|
155
|
+
/**
|
|
156
|
+
* 1..=`MAX_CHUNK_BYTES`.
|
|
157
|
+
*/
|
|
158
|
+
'length' : number,
|
|
159
|
+
}
|
|
160
|
+
export type Result = { 'Ok' : BufferInfo } |
|
|
161
|
+
{ 'Err' : Error };
|
|
162
|
+
export type Result_1 = { 'Ok' : Distance } |
|
|
163
|
+
{ 'Err' : Error };
|
|
164
|
+
export type Result_2 = { 'Ok' : Status } |
|
|
165
|
+
{ 'Err' : Error };
|
|
166
|
+
export type Result_3 = { 'Ok' : Uint8Array | number[] } |
|
|
167
|
+
{ 'Err' : Error };
|
|
168
|
+
export type Result_4 = { 'Ok' : RouteAnswer } |
|
|
169
|
+
{ 'Err' : Error };
|
|
170
|
+
export type Result_5 = { 'Ok' : PassStatus } |
|
|
171
|
+
{ 'Err' : Error };
|
|
172
|
+
export type Result_6 = { 'Ok' : null } |
|
|
173
|
+
{ 'Err' : Error };
|
|
174
|
+
export interface RouteAnswer {
|
|
175
|
+
/**
|
|
176
|
+
* How far each point lies from the junction its legs start or end at.
|
|
177
|
+
*/
|
|
178
|
+
'snapMeters' : Uint32Array | number[],
|
|
179
|
+
/**
|
|
180
|
+
* One leg for each pair of consecutive points.
|
|
181
|
+
*/
|
|
182
|
+
'legs' : Array<Leg>,
|
|
183
|
+
'instructions' : bigint,
|
|
184
|
+
'graphSha256' : string,
|
|
185
|
+
'osmDate' : string,
|
|
186
|
+
}
|
|
187
|
+
export interface RouteArgs {
|
|
188
|
+
/**
|
|
189
|
+
* Whether each leg carries its line.
|
|
190
|
+
*/
|
|
191
|
+
'line' : boolean,
|
|
192
|
+
/**
|
|
193
|
+
* The pass from the coordinator (`map-routes-pass`); required once `passRequired`.
|
|
194
|
+
*/
|
|
195
|
+
'pass' : [] | [Uint8Array | number[]],
|
|
196
|
+
/**
|
|
197
|
+
* 2..=`MAX_ROUTE_POINTS` points, driven in this order.
|
|
198
|
+
*/
|
|
199
|
+
'points' : Array<Point>,
|
|
200
|
+
}
|
|
201
|
+
export interface SetPassConfigArgs {
|
|
202
|
+
/**
|
|
203
|
+
* The area of this worker; a pass for another area is refused.
|
|
204
|
+
*/
|
|
205
|
+
'area' : string,
|
|
206
|
+
/**
|
|
207
|
+
* 0..=`MAX_PASS_KEYS` keys; replaces the ones held.
|
|
208
|
+
*/
|
|
209
|
+
'keys' : Array<PassKeyArgs>,
|
|
210
|
+
/**
|
|
211
|
+
* Without a pass `distance` and `route` answer `PassMissing`.
|
|
212
|
+
*/
|
|
213
|
+
'required' : boolean,
|
|
214
|
+
}
|
|
215
|
+
export interface Status {
|
|
216
|
+
'stableBytes' : bigint,
|
|
217
|
+
'heapBytes' : bigint,
|
|
218
|
+
/**
|
|
219
|
+
* A copy from another worker that has not ended (`copyFrom`).
|
|
220
|
+
*/
|
|
221
|
+
'copy' : [] | [CopyStatus],
|
|
222
|
+
/**
|
|
223
|
+
* The pass check; `opt` so that a newer package reads an older canister.
|
|
224
|
+
*/
|
|
225
|
+
'pass' : [] | [PassStatus],
|
|
226
|
+
/**
|
|
227
|
+
* Who may upload and commit a graph besides the controllers (`setUploaders`).
|
|
228
|
+
*/
|
|
229
|
+
'uploaders' : [] | [Array<Principal>],
|
|
230
|
+
/**
|
|
231
|
+
* Nodes of the graph that answers `distance`; 0 when none is active.
|
|
232
|
+
*/
|
|
233
|
+
'nodes' : bigint,
|
|
234
|
+
'buffers' : Array<BufferInfo>,
|
|
235
|
+
/**
|
|
236
|
+
* Workers that may read this graph (`setPeers`).
|
|
237
|
+
*/
|
|
238
|
+
'peers' : [] | [Array<Principal>],
|
|
239
|
+
}
|
|
240
|
+
export interface UploadChunkArgs {
|
|
241
|
+
'offset' : bigint,
|
|
242
|
+
'bytes' : Uint8Array | number[],
|
|
243
|
+
}
|
|
244
|
+
export interface _SERVICE {
|
|
245
|
+
/**
|
|
246
|
+
* Switches `distance` to the inactive buffer — a new graph, or back to the previous one.
|
|
247
|
+
*/
|
|
248
|
+
'activate' : ActorMethod<[], Result>,
|
|
249
|
+
/**
|
|
250
|
+
* Starts an upload into the inactive buffer; whatever was there is dropped.
|
|
251
|
+
*/
|
|
252
|
+
'beginUpload' : ActorMethod<[BeginUploadArgs], Result>,
|
|
253
|
+
/**
|
|
254
|
+
* Checks the hash and the header of the uploaded graph; the buffer becomes Ready.
|
|
255
|
+
*/
|
|
256
|
+
'commitUpload' : ActorMethod<[], Result>,
|
|
257
|
+
/**
|
|
258
|
+
* Pulls the active graph of `source` into the inactive buffer, chunk by chunk, and commits
|
|
259
|
+
* it (hash and header checked). It does not activate it. Called again after a stop, it goes
|
|
260
|
+
* on where it stopped; the source must list this canister in its peers.
|
|
261
|
+
*/
|
|
262
|
+
'copyFrom' : ActorMethod<[CopyFromArgs], Result>,
|
|
263
|
+
/**
|
|
264
|
+
* The fastest route by car from one point to another. Public.
|
|
265
|
+
*/
|
|
266
|
+
'distance' : ActorMethod<[DistanceArgs], Result_1>,
|
|
267
|
+
'getStatus' : ActorMethod<[], Result_2>,
|
|
268
|
+
/**
|
|
269
|
+
* The active graph, for a copy: sha256, size, date. Controllers and peers.
|
|
270
|
+
*/
|
|
271
|
+
'graphInfo' : ActorMethod<[], Result>,
|
|
272
|
+
/**
|
|
273
|
+
* Bytes of a committed graph (by its sha256), for a copy. Controllers and peers.
|
|
274
|
+
*/
|
|
275
|
+
'readChunk' : ActorMethod<[ReadChunkArgs], Result_3>,
|
|
276
|
+
/**
|
|
277
|
+
* The fastest route by car through 2..=5 points, leg by leg, with each leg's line when
|
|
278
|
+
* asked. Public.
|
|
279
|
+
*/
|
|
280
|
+
'route' : ActorMethod<[RouteArgs], Result_4>,
|
|
281
|
+
/**
|
|
282
|
+
* Sets the pass check: required or not, the area, the keys (from the coordinator).
|
|
283
|
+
*/
|
|
284
|
+
'setPassConfig' : ActorMethod<[SetPassConfigArgs], Result_5>,
|
|
285
|
+
/**
|
|
286
|
+
* Sets the workers that may read the graph to copy it (the coordinator lists the copies).
|
|
287
|
+
*/
|
|
288
|
+
'setPeers' : ActorMethod<[Array<Principal>], Result_6>,
|
|
289
|
+
/**
|
|
290
|
+
* Sets who may upload and commit a graph besides the controllers (not activate it).
|
|
291
|
+
*/
|
|
292
|
+
'setUploaders' : ActorMethod<[Array<Principal>], Result_6>,
|
|
293
|
+
'uploadChunk' : ActorMethod<[UploadChunkArgs], Result_6>,
|
|
294
|
+
}
|
|
295
|
+
export declare const idlFactory: IDL.InterfaceFactory;
|
|
296
|
+
export declare const init: (args: { IDL: typeof IDL }) => IDL.Type[];
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
export const idlFactory = ({ IDL }) => {
|
|
2
|
+
const BufferState = IDL.Variant({
|
|
3
|
+
'Uploading' : IDL.Null,
|
|
4
|
+
'Active' : IDL.Null,
|
|
5
|
+
'Ready' : IDL.Null,
|
|
6
|
+
});
|
|
7
|
+
const BufferInfo = IDL.Record({
|
|
8
|
+
'sha256' : IDL.Text,
|
|
9
|
+
'size' : IDL.Nat64,
|
|
10
|
+
'startedAtNs' : IDL.Nat64,
|
|
11
|
+
'state' : BufferState,
|
|
12
|
+
'buffer' : IDL.Nat8,
|
|
13
|
+
'osmDate' : IDL.Text,
|
|
14
|
+
});
|
|
15
|
+
const Error = IDL.Variant({
|
|
16
|
+
'OutsideArea' : IDL.Text,
|
|
17
|
+
'OutsideBbox' : IDL.Text,
|
|
18
|
+
'NotReady' : IDL.Null,
|
|
19
|
+
'NotFound' : IDL.Null,
|
|
20
|
+
'NotAuthorized' : IDL.Text,
|
|
21
|
+
'PassExpired' : IDL.Null,
|
|
22
|
+
'NoRoute' : IDL.Null,
|
|
23
|
+
'InvalidData' : IDL.Text,
|
|
24
|
+
'PassMissing' : IDL.Null,
|
|
25
|
+
'PassInvalid' : IDL.Text,
|
|
26
|
+
});
|
|
27
|
+
const Result = IDL.Variant({ 'Ok' : BufferInfo, 'Err' : Error });
|
|
28
|
+
const BeginUploadArgs = IDL.Record({
|
|
29
|
+
'sha256' : IDL.Text,
|
|
30
|
+
'size' : IDL.Nat64,
|
|
31
|
+
'osmDate' : IDL.Text,
|
|
32
|
+
});
|
|
33
|
+
const CopyFromArgs = IDL.Record({ 'source' : IDL.Principal });
|
|
34
|
+
const Point = IDL.Record({ 'lat' : IDL.Float64, 'lon' : IDL.Float64 });
|
|
35
|
+
const DistanceArgs = IDL.Record({
|
|
36
|
+
'to' : Point,
|
|
37
|
+
'from' : Point,
|
|
38
|
+
'pass' : IDL.Opt(IDL.Vec(IDL.Nat8)),
|
|
39
|
+
});
|
|
40
|
+
const Distance = IDL.Record({
|
|
41
|
+
'meters' : IDL.Nat64,
|
|
42
|
+
'snapToMeters' : IDL.Nat32,
|
|
43
|
+
'seconds' : IDL.Nat64,
|
|
44
|
+
'instructions' : IDL.Nat64,
|
|
45
|
+
'graphSha256' : IDL.Text,
|
|
46
|
+
'osmDate' : IDL.Text,
|
|
47
|
+
'snapFromMeters' : IDL.Nat32,
|
|
48
|
+
});
|
|
49
|
+
const Result_1 = IDL.Variant({ 'Ok' : Distance, 'Err' : Error });
|
|
50
|
+
const CopyStatus = IDL.Record({
|
|
51
|
+
'sha256' : IDL.Text,
|
|
52
|
+
'source' : IDL.Principal,
|
|
53
|
+
'size' : IDL.Nat64,
|
|
54
|
+
'copied' : IDL.Nat64,
|
|
55
|
+
});
|
|
56
|
+
const PassStatus = IDL.Record({
|
|
57
|
+
'keyIds' : IDL.Vec(IDL.Nat32),
|
|
58
|
+
'area' : IDL.Opt(IDL.Text),
|
|
59
|
+
'required' : IDL.Bool,
|
|
60
|
+
});
|
|
61
|
+
const Status = IDL.Record({
|
|
62
|
+
'stableBytes' : IDL.Nat64,
|
|
63
|
+
'heapBytes' : IDL.Nat64,
|
|
64
|
+
'copy' : IDL.Opt(CopyStatus),
|
|
65
|
+
'pass' : IDL.Opt(PassStatus),
|
|
66
|
+
'uploaders' : IDL.Opt(IDL.Vec(IDL.Principal)),
|
|
67
|
+
'nodes' : IDL.Nat64,
|
|
68
|
+
'buffers' : IDL.Vec(BufferInfo),
|
|
69
|
+
'peers' : IDL.Opt(IDL.Vec(IDL.Principal)),
|
|
70
|
+
});
|
|
71
|
+
const Result_2 = IDL.Variant({ 'Ok' : Status, 'Err' : Error });
|
|
72
|
+
const ReadChunkArgs = IDL.Record({
|
|
73
|
+
'sha256' : IDL.Text,
|
|
74
|
+
'offset' : IDL.Nat64,
|
|
75
|
+
'length' : IDL.Nat32,
|
|
76
|
+
});
|
|
77
|
+
const Result_3 = IDL.Variant({ 'Ok' : IDL.Vec(IDL.Nat8), 'Err' : Error });
|
|
78
|
+
const RouteArgs = IDL.Record({
|
|
79
|
+
'line' : IDL.Bool,
|
|
80
|
+
'pass' : IDL.Opt(IDL.Vec(IDL.Nat8)),
|
|
81
|
+
'points' : IDL.Vec(Point),
|
|
82
|
+
});
|
|
83
|
+
const Leg = IDL.Record({
|
|
84
|
+
'meters' : IDL.Nat64,
|
|
85
|
+
'line' : IDL.Text,
|
|
86
|
+
'seconds' : IDL.Nat64,
|
|
87
|
+
});
|
|
88
|
+
const RouteAnswer = IDL.Record({
|
|
89
|
+
'snapMeters' : IDL.Vec(IDL.Nat32),
|
|
90
|
+
'legs' : IDL.Vec(Leg),
|
|
91
|
+
'instructions' : IDL.Nat64,
|
|
92
|
+
'graphSha256' : IDL.Text,
|
|
93
|
+
'osmDate' : IDL.Text,
|
|
94
|
+
});
|
|
95
|
+
const Result_4 = IDL.Variant({ 'Ok' : RouteAnswer, 'Err' : Error });
|
|
96
|
+
const PassKeyArgs = IDL.Record({
|
|
97
|
+
'id' : IDL.Nat32,
|
|
98
|
+
'key' : IDL.Vec(IDL.Nat8),
|
|
99
|
+
'validUntilNs' : IDL.Opt(IDL.Nat64),
|
|
100
|
+
});
|
|
101
|
+
const SetPassConfigArgs = IDL.Record({
|
|
102
|
+
'area' : IDL.Text,
|
|
103
|
+
'keys' : IDL.Vec(PassKeyArgs),
|
|
104
|
+
'required' : IDL.Bool,
|
|
105
|
+
});
|
|
106
|
+
const Result_5 = IDL.Variant({ 'Ok' : PassStatus, 'Err' : Error });
|
|
107
|
+
const Result_6 = IDL.Variant({ 'Ok' : IDL.Null, 'Err' : Error });
|
|
108
|
+
const UploadChunkArgs = IDL.Record({
|
|
109
|
+
'offset' : IDL.Nat64,
|
|
110
|
+
'bytes' : IDL.Vec(IDL.Nat8),
|
|
111
|
+
});
|
|
112
|
+
return IDL.Service({
|
|
113
|
+
'activate' : IDL.Func([], [Result], []),
|
|
114
|
+
'beginUpload' : IDL.Func([BeginUploadArgs], [Result], []),
|
|
115
|
+
'commitUpload' : IDL.Func([], [Result], []),
|
|
116
|
+
'copyFrom' : IDL.Func([CopyFromArgs], [Result], []),
|
|
117
|
+
'distance' : IDL.Func([DistanceArgs], [Result_1], ['query']),
|
|
118
|
+
'getStatus' : IDL.Func([], [Result_2], ['query']),
|
|
119
|
+
'graphInfo' : IDL.Func([], [Result], ['query']),
|
|
120
|
+
'readChunk' : IDL.Func([ReadChunkArgs], [Result_3], ['query']),
|
|
121
|
+
'route' : IDL.Func([RouteArgs], [Result_4], ['query']),
|
|
122
|
+
'setPassConfig' : IDL.Func([SetPassConfigArgs], [Result_5], []),
|
|
123
|
+
'setPeers' : IDL.Func([IDL.Vec(IDL.Principal)], [Result_6], []),
|
|
124
|
+
'setUploaders' : IDL.Func([IDL.Vec(IDL.Principal)], [Result_6], []),
|
|
125
|
+
'uploadChunk' : IDL.Func([UploadChunkArgs], [Result_6], []),
|
|
126
|
+
});
|
|
127
|
+
};
|
|
128
|
+
export const init = ({ IDL }) => { return []; };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { type ActorSubclass, type Identity } from "@icp-sdk/core/agent";
|
|
2
|
+
import type { IDL } from "@icp-sdk/core/candid";
|
|
3
|
+
export interface MapRoutesOptions {
|
|
4
|
+
/**
|
|
5
|
+
* The gateway or replica to talk to. Default: mainnet (`https://icp0.io`). Pass a local
|
|
6
|
+
* replica (`http://127.0.0.1:4943`) for runs that must not touch mainnet. For a local
|
|
7
|
+
* host — and only then — the agent fetches the replica's root key.
|
|
8
|
+
*/
|
|
9
|
+
host?: string;
|
|
10
|
+
}
|
|
11
|
+
export declare const MAINNET_HOST = "https://icp0.io";
|
|
12
|
+
/** True for a replica on this machine: localhost, *.localhost, 127.0.0.1 or [::1]. */
|
|
13
|
+
export declare function isLocalHost(host: string): boolean;
|
|
14
|
+
export declare function rawActorAsync<S>(idlFactory: IDL.InterfaceFactory, canisterId: string, options: MapRoutesOptions): Promise<ActorSubclass<S>>;
|
|
15
|
+
export declare function signedActorAsync<S>(idlFactory: IDL.InterfaceFactory, canisterId: string, host: string, identity: Identity | undefined): Promise<ActorSubclass<S>>;
|
|
16
|
+
/**
|
|
17
|
+
* A canister that is stopped or stopping — an upgrade of it runs — refuses every call with
|
|
18
|
+
* IC0508 / IC0509. The call did NOT run, so it is tried again: doubling pauses from
|
|
19
|
+
* `STOPPED_RETRY_FIRST_DELAY_MS`, at most `STOPPED_RETRY_MAX_FACTOR` times it, each 0.5–1.5
|
|
20
|
+
* of its length at random, `STOPPED_RETRY_ATTEMPTS` tries in all: about a minute — unless
|
|
21
|
+
* the time limit of the call ends first.
|
|
22
|
+
*/
|
|
23
|
+
export declare const STOPPED_RETRY_FIRST_DELAY_MS = 1000;
|
|
24
|
+
export declare const STOPPED_RETRY_MAX_FACTOR = 8;
|
|
25
|
+
export declare const STOPPED_RETRY_ATTEMPTS = 10;
|
|
26
|
+
/** True for the refusal of a stopped or stopping canister. */
|
|
27
|
+
export declare function isCanisterStoppedError(error: unknown): boolean;
|
|
28
|
+
/** The wait before try `attempt + 1`: doubling, capped, 0.5–1.5 of it at random. */
|
|
29
|
+
export declare function stoppedRetryDelayMs(attempt: number, firstDelayMs?: number): number;
|
|
30
|
+
/** Tests shorten the waits. */
|
|
31
|
+
export declare const retrySettings: {
|
|
32
|
+
stoppedFirstDelayMs: number;
|
|
33
|
+
stoppedAttempts: number;
|
|
34
|
+
};
|
|
35
|
+
export declare function waitOutStoppedAsync<T>(fnAsync: () => Promise<T>): Promise<T>;
|
|
36
|
+
/** The error of a call that did not answer within its time limit. */
|
|
37
|
+
export declare function timeoutError(timeoutMs: number): Error;
|
|
38
|
+
export declare function isTimeoutError(error: unknown): boolean;
|
|
39
|
+
/**
|
|
40
|
+
* The call, or `Timeout` after `timeoutMs` (none when undefined). The call itself goes on
|
|
41
|
+
* (a query cannot be called back); its late answer is dropped.
|
|
42
|
+
*/
|
|
43
|
+
export declare function withTimeoutAsync<T>(fnAsync: () => Promise<T>, timeoutMs: number | undefined): Promise<T>;
|
|
44
|
+
export type RustResult<T> = {
|
|
45
|
+
Ok: T;
|
|
46
|
+
} | {
|
|
47
|
+
Err: Record<string, unknown>;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* `{ Ok: T }` resolves with `T`; `{ Err }` is thrown as `Error("CanisterError", { cause:
|
|
51
|
+
* { errorKey, errorMessage } })` with the variant's name as the errorKey (`OutsideArea`,
|
|
52
|
+
* `NoRoute`, `NotReady`, `InvalidData`); any transport failure as
|
|
53
|
+
* `Error("CriticalCanisterError", { cause: { rawError } })`. A stopped canister is waited
|
|
54
|
+
* out first.
|
|
55
|
+
*/
|
|
56
|
+
export declare function executeRustAsyncUnsafe<T>(fnAsync: () => Promise<RustResult<T>>): Promise<T>;
|
|
57
|
+
/** The errorKey of a `CanisterError`, or undefined for any other error. */
|
|
58
|
+
export declare function errorKeyOf(error: unknown): string | undefined;
|
|
59
|
+
//# sourceMappingURL=canister-actor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"canister-actor.d.ts","sourceRoot":"","sources":["../src/canister-actor.ts"],"names":[],"mappings":"AAIA,OAAO,EAAS,KAAK,aAAa,EAAa,KAAK,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC1F,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,sBAAsB,CAAC;AAEhD,MAAM,WAAW,gBAAgB;IAC7B;;;;OAIG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,eAAO,MAAM,YAAY,oBAAoB,CAAC;AAE9C,sFAAsF;AACtF,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAUjD;AAiBD,wBAAsB,aAAa,CAAC,CAAC,EAAE,UAAU,EAAE,GAAG,CAAC,gBAAgB,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAKjJ;AAKD,wBAAsB,gBAAgB,CAAC,CAAC,EAAE,UAAU,EAAE,GAAG,CAAC,gBAAgB,EAAE,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,SAAS,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAgBvK;AAID;;;;;;GAMG;AACH,eAAO,MAAM,4BAA4B,OAAO,CAAC;AACjD,eAAO,MAAM,wBAAwB,IAAI,CAAC;AAC1C,eAAO,MAAM,sBAAsB,KAAK,CAAC;AAKzC,8DAA8D;AAC9D,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAW9D;AAED,oFAAoF;AACpF,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,EAAE,YAAY,GAAE,MAAqC,GAAG,MAAM,CAGhH;AAED,+BAA+B;AAC/B,eAAO,MAAM,aAAa;;;CAGzB,CAAC;AAEF,wBAAsB,mBAAmB,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAUlF;AAID,qEAAqE;AACrE,wBAAgB,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,KAAK,CAErD;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAEtD;AAED;;;GAGG;AACH,wBAAsB,gBAAgB,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,CAAC,CAAC,CAa9G;AAID,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI;IAAE,EAAE,EAAE,CAAC,CAAA;CAAE,GAAG;IAAE,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAAE,CAAC;AAEzE;;;;;;GAMG;AACH,wBAAsB,sBAAsB,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAYjG;AAED,2EAA2E;AAC3E,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAG7D"}
|