@jsm-mit/tigi-sharded-package 0.5.1 → 0.7.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/declarations/worker/worker.did +2 -0
- package/declarations/worker/worker.did.d.ts +2 -0
- package/declarations/worker/worker.did.js +2 -0
- package/dist/actors/rides-actor.d.ts +11 -0
- package/dist/actors/rides-actor.d.ts.map +1 -1
- package/dist/actors/rides-actor.js +19 -7
- package/dist/mappers.d.ts +29 -1
- package/dist/mappers.d.ts.map +1 -1
- package/dist/mappers.js +43 -0
- package/package.json +3 -3
|
@@ -171,6 +171,7 @@ type Result =
|
|
|
171
171
|
};
|
|
172
172
|
type RequestView =
|
|
173
173
|
record {
|
|
174
|
+
asOfNs: opt nat64;
|
|
174
175
|
asked: nat32;
|
|
175
176
|
createdNs: nat64;
|
|
176
177
|
expiresNs: nat64;
|
|
@@ -203,6 +204,7 @@ type RequestRideArgs =
|
|
|
203
204
|
destination: Geo;
|
|
204
205
|
pickup: Geo;
|
|
205
206
|
radiusMeters: nat32;
|
|
207
|
+
realDriversOnly: opt bool;
|
|
206
208
|
requestId: RequestId;
|
|
207
209
|
riderName: text;
|
|
208
210
|
};
|
|
@@ -193,6 +193,7 @@ export interface RequestRef { 'requestId' : RequestId }
|
|
|
193
193
|
export interface RequestRideArgs {
|
|
194
194
|
'destination' : Geo,
|
|
195
195
|
'requestId' : RequestId,
|
|
196
|
+
'realDriversOnly' : [] | [boolean],
|
|
196
197
|
'pickup' : Geo,
|
|
197
198
|
'radiusMeters' : number,
|
|
198
199
|
'riderName' : string,
|
|
@@ -217,6 +218,7 @@ export interface RequestView {
|
|
|
217
218
|
'requestId' : RequestId,
|
|
218
219
|
'expiresNs' : bigint,
|
|
219
220
|
'asked' : number,
|
|
221
|
+
'asOfNs' : [] | [bigint],
|
|
220
222
|
'createdNs' : bigint,
|
|
221
223
|
'offers' : Array<OfferView>,
|
|
222
224
|
'state' : RequestStateView,
|
|
@@ -214,6 +214,7 @@ export const idlFactory = ({ IDL }) => {
|
|
|
214
214
|
'requestId' : RequestId,
|
|
215
215
|
'expiresNs' : IDL.Nat64,
|
|
216
216
|
'asked' : IDL.Nat32,
|
|
217
|
+
'asOfNs' : IDL.Opt(IDL.Nat64),
|
|
217
218
|
'createdNs' : IDL.Nat64,
|
|
218
219
|
'offers' : IDL.Vec(OfferView),
|
|
219
220
|
'state' : RequestStateView,
|
|
@@ -272,6 +273,7 @@ export const idlFactory = ({ IDL }) => {
|
|
|
272
273
|
const RequestRideArgs = IDL.Record({
|
|
273
274
|
'destination' : Geo,
|
|
274
275
|
'requestId' : RequestId,
|
|
276
|
+
'realDriversOnly' : IDL.Opt(IDL.Bool),
|
|
275
277
|
'pickup' : Geo,
|
|
276
278
|
'radiusMeters' : IDL.Nat32,
|
|
277
279
|
'riderName' : IDL.Text,
|
|
@@ -30,6 +30,8 @@ interface RequestState {
|
|
|
30
30
|
widened: boolean;
|
|
31
31
|
othersClosed: boolean;
|
|
32
32
|
sawOffer: boolean;
|
|
33
|
+
/** ZO-23: kept for the widening and "Szukaj ponownie". */
|
|
34
|
+
realDriversOnly?: boolean;
|
|
33
35
|
accepted?: {
|
|
34
36
|
worker: string;
|
|
35
37
|
canister: string;
|
|
@@ -43,6 +45,11 @@ export interface RequestRideArgs {
|
|
|
43
45
|
riderName?: string;
|
|
44
46
|
/** Only for tests and resumed flows: the id of the request (1–64 characters). */
|
|
45
47
|
requestId?: string;
|
|
48
|
+
/**
|
|
49
|
+
* ZO-23 (test builds): true = the simulator's drivers are not asked, only real driver
|
|
50
|
+
* canisters (the Test Manager's switch). Left out = everyone, as before.
|
|
51
|
+
*/
|
|
52
|
+
realDriversOnly?: boolean;
|
|
46
53
|
}
|
|
47
54
|
/**
|
|
48
55
|
* The refusal key of a worker's answer (WO-N9): `ALREADY_OPEN`, `NOT_MY_AREA`, `FULL`,
|
|
@@ -103,6 +110,10 @@ export declare class RideRequest {
|
|
|
103
110
|
private choosing;
|
|
104
111
|
private lastSnapshot;
|
|
105
112
|
private slots;
|
|
113
|
+
/** ZO-24: each worker's last answer, with the time of its state. */
|
|
114
|
+
private readonly heldViews;
|
|
115
|
+
/** ZO-24: the last ride shown (status and position never go back). */
|
|
116
|
+
private lastRide;
|
|
106
117
|
private readonly rejected;
|
|
107
118
|
private readonly notFree;
|
|
108
119
|
private readonly refreshingUntilMs;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rides-actor.d.ts","sourceRoot":"","sources":["../../src/actors/rides-actor.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAKpD,OAAO,EAAgJ,KAAK,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC7M,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAE9C,OAAO,EAA2B,KAAK,GAAG,EAAE,MAAM,WAAW,CAAC;AAC9D,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,WAAW,EAAa,eAAe,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAInI,sFAAsF;AACtF,eAAO,MAAM,oBAAoB,OAAQ,CAAC;AAC1C,eAAO,MAAM,kBAAkB,OAAQ,CAAC;AACxC,yEAAyE;AACzE,eAAO,MAAM,cAAc,QAAS,CAAC;AACrC,qFAAqF;AACrF,eAAO,MAAM,eAAe,OAAQ,CAAC;AACrC;;;GAGG;AACH,eAAO,MAAM,eAAe,QAAS,CAAC;AACtC,+GAA+G;AAC/G,eAAO,MAAM,YAAY,OAAQ,CAAC;AAClC,eAAO,MAAM,iBAAiB,OAAQ,CAAC;AAEvC,wFAAwF;AACxF,UAAU,YAAY;IAClB,CAAC,EAAE,CAAC,CAAC;IACL,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,GAAG,CAAC;IACZ,WAAW,EAAE,GAAG,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,E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/E,UAAU;YASV,kBAAkB;YAalB,mBAAmB;YAOnB,WAAW;CAG5B"}
|
|
@@ -11,7 +11,7 @@ import { TigiGroup } from "../group/group.js";
|
|
|
11
11
|
import { geohashesByWorker } from "../group/prefixes.js";
|
|
12
12
|
import { cellsWithin, isValidGeo } from "../geo.js";
|
|
13
13
|
import { driverChatPlaceAsyncUnsafe } from "../chat.js";
|
|
14
|
-
import { cardOf, closeReasonOf, decodeToken, driverOfOfferId, encodeToken, mergedPhase, mergeOffers, moneyOf, msOf, offerIdOf, offerOf, phaseOf, placeOffers, rideOfRideRef, rideStatusOf, routeLineOf } from "../mappers.js";
|
|
14
|
+
import { cardOf, closeReasonOf, decodeToken, driverOfOfferId, encodeToken, fresherRide, freshViews, mergedPhase, mergeOffers, moneyOf, msOf, offerIdOf, offerOf, phaseOf, placeOffers, rideOfRideRef, rideStatusOf, routeLineOf } from "../mappers.js";
|
|
15
15
|
/** U-29: the rider's radius, and the radius after `WIDEN_AFTER_MS` without offers. */
|
|
16
16
|
export const SEARCH_RADIUS_METERS = 3_000;
|
|
17
17
|
export const WIDE_RADIUS_METERS = 6_000;
|
|
@@ -89,6 +89,7 @@ export class RidesActor {
|
|
|
89
89
|
widened: false,
|
|
90
90
|
othersClosed: false,
|
|
91
91
|
sawOffer: false,
|
|
92
|
+
...(args.realDriversOnly ? { realDriversOnly: true } : {}),
|
|
92
93
|
};
|
|
93
94
|
const request = new RideRequest(this.group, this.identity, this.options, state, () => this.simulatorIdAsync());
|
|
94
95
|
await request.placeAsyncUnsafe(SEARCH_RADIUS_METERS);
|
|
@@ -154,6 +155,10 @@ export class RideRequest {
|
|
|
154
155
|
choosing = false;
|
|
155
156
|
lastSnapshot;
|
|
156
157
|
slots = [];
|
|
158
|
+
/** ZO-24: each worker's last answer, with the time of its state. */
|
|
159
|
+
heldViews = new Map();
|
|
160
|
+
/** ZO-24: the last ride shown (status and position never go back). */
|
|
161
|
+
lastRide;
|
|
157
162
|
rejected = new Set();
|
|
158
163
|
notFree = new Set();
|
|
159
164
|
refreshingUntilMs = new Map();
|
|
@@ -193,7 +198,7 @@ export class RideRequest {
|
|
|
193
198
|
const workers = (await workersForAsync(this.group, this.state.pickup, radiusMeters, fresh)).filter((worker) => !tried.has(worker));
|
|
194
199
|
const results = await Promise.allSettled(workers.map(async (worker) => {
|
|
195
200
|
tried.add(worker);
|
|
196
|
-
await this.group.onWorkerAsyncUnsafe(worker, (actor) => actor.requestRide({ requestId: this.state.requestId, pickup: this.state.pickup, destination: this.state.destination, riderName: this.state.riderName, radiusMeters }));
|
|
201
|
+
await this.group.onWorkerAsyncUnsafe(worker, (actor) => actor.requestRide({ requestId: this.state.requestId, pickup: this.state.pickup, destination: this.state.destination, riderName: this.state.riderName, radiusMeters, realDriversOnly: this.state.realDriversOnly ? [true] : [] }));
|
|
197
202
|
return worker;
|
|
198
203
|
}));
|
|
199
204
|
let staleMap = false;
|
|
@@ -387,6 +392,7 @@ export class RideRequest {
|
|
|
387
392
|
widened: false,
|
|
388
393
|
othersClosed: false,
|
|
389
394
|
sawOffer: false,
|
|
395
|
+
...(this.state.realDriversOnly ? { realDriversOnly: true } : {}),
|
|
390
396
|
};
|
|
391
397
|
const request = new RideRequest(this.group, this.identity, this.options, state, this.simulatorIdAsync);
|
|
392
398
|
await request.placeAsyncUnsafe(SEARCH_RADIUS_METERS);
|
|
@@ -410,7 +416,9 @@ export class RideRequest {
|
|
|
410
416
|
*/
|
|
411
417
|
async getRideAsyncUnsafe() {
|
|
412
418
|
const accepted = await this.acceptedAsyncUnsafe();
|
|
413
|
-
|
|
419
|
+
// ZO-24: an answer from an older state never moves the ride back.
|
|
420
|
+
this.lastRide = fresherRide(this.lastRide, await getRideOfAsyncUnsafe(this.identity, this.options, accepted, this.state.requestId));
|
|
421
|
+
return this.lastRide;
|
|
414
422
|
}
|
|
415
423
|
/**
|
|
416
424
|
* K-4, U-13: the rider cancels in the driver canister only, before `inProgress`, once.
|
|
@@ -469,22 +477,26 @@ export class RideRequest {
|
|
|
469
477
|
async readAllAsyncUnsafe(workers) {
|
|
470
478
|
const results = await Promise.allSettled(workers.map(async (worker) => ({ worker, view: await this.group.onWorkerAsyncUnsafe(worker, (actor) => actor.getRequest({ requestId: this.state.requestId })) })));
|
|
471
479
|
const answers = [];
|
|
480
|
+
const failed = [];
|
|
472
481
|
let failure;
|
|
473
482
|
let notFound = 0;
|
|
474
|
-
|
|
483
|
+
results.forEach((result, index) => {
|
|
475
484
|
if (result.status === "fulfilled")
|
|
476
485
|
answers.push(result.value);
|
|
477
486
|
else if (errorKeyOf(result.reason) === "NotFound")
|
|
478
487
|
notFound += 1;
|
|
479
|
-
else
|
|
488
|
+
else {
|
|
480
489
|
failure ??= result.reason;
|
|
481
|
-
|
|
490
|
+
failed.push(workers[index]);
|
|
491
|
+
}
|
|
492
|
+
});
|
|
482
493
|
// One silent worker does not hide the rest; nobody answering is an error.
|
|
483
494
|
if (answers.length === 0 && failure !== undefined)
|
|
484
495
|
throw failure;
|
|
485
496
|
if (answers.length === 0 && notFound > 0)
|
|
486
497
|
throw canisterError("NotFound", "no worker holds this request");
|
|
487
|
-
|
|
498
|
+
// ZO-24: an older state than the held one, or a silent worker, keeps the held answer.
|
|
499
|
+
return freshViews(this.heldViews, answers, failed, Date.now());
|
|
488
500
|
}
|
|
489
501
|
async mergeAsync(answers) {
|
|
490
502
|
const simulator = await this.simulatorIdAsync();
|
package/dist/mappers.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { CarrierKind as CandidCarrierKind, DriverCard, Money as CandidMoney, RideStatus, RouteLine } from "../declarations/tigi-driver/tigi-driver.did.js";
|
|
2
2
|
import type { OfferView as CandidOfferView, RequestView as CandidRequestView } from "../declarations/worker/worker.did.js";
|
|
3
3
|
import type { RateRideOutcome as CandidRateRideOutcome, RideView as CandidHistoryRide } from "../declarations/core/core.did.js";
|
|
4
|
-
import type { CarrierKind, CloseReason, DriverCardView, Money, OfferView, RateRideOutcome, RequestPhase, RideHistoryEntry, RideStatusView, RouteLineView } from "./interfaces.js";
|
|
4
|
+
import type { CarrierKind, CloseReason, DriverCardView, Money, OfferView, RateRideOutcome, RequestPhase, RideHistoryEntry, RideStatusView, RideView, RouteLineView } from "./interfaces.js";
|
|
5
5
|
export declare const NS_PER_MS = 1000000n;
|
|
6
6
|
export declare function msOf(ns: bigint): number;
|
|
7
7
|
export declare function moneyOf(money: CandidMoney): Money;
|
|
@@ -85,4 +85,32 @@ export declare function phaseOf(view: CandidRequestView): RequestPhase;
|
|
|
85
85
|
* then an order waiting anywhere, then a search anywhere; closed only when closed in all.
|
|
86
86
|
*/
|
|
87
87
|
export declare function mergedPhase(phases: RequestPhase[]): RequestPhase;
|
|
88
|
+
/** ZO-24: a worker's answer that failed is stood in for by its last one this long. */
|
|
89
|
+
export declare const STAND_IN_MS = 10000;
|
|
90
|
+
/** ZO-24: the last answer of one worker, with the time of its state. */
|
|
91
|
+
export interface HeldView<V> {
|
|
92
|
+
asOfNs: bigint;
|
|
93
|
+
view: V;
|
|
94
|
+
atMs: number;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* ZO-24: a query goes to any replica of the subnet, and one a round behind answers from an
|
|
98
|
+
* older state (an offer flashing away and back). Per worker: an answer older than the held
|
|
99
|
+
* one is replaced by the held one; a worker that failed this time keeps its held answer for
|
|
100
|
+
* `STAND_IN_MS` (one silent worker does not blink its offers away). Updates `held`.
|
|
101
|
+
*/
|
|
102
|
+
export declare function freshViews<V extends {
|
|
103
|
+
asOfNs: [] | [bigint];
|
|
104
|
+
}>(held: Map<string, HeldView<V>>, answers: {
|
|
105
|
+
worker: string;
|
|
106
|
+
view: V;
|
|
107
|
+
}[], failed: string[], nowMs: number): {
|
|
108
|
+
worker: string;
|
|
109
|
+
view: V;
|
|
110
|
+
}[];
|
|
111
|
+
/**
|
|
112
|
+
* ZO-24: a ride never goes back — an answer from an older state keeps the newer status, and
|
|
113
|
+
* the position stays the newer one (by `positionAtMs`).
|
|
114
|
+
*/
|
|
115
|
+
export declare function fresherRide(before: RideView | undefined, next: RideView): RideView;
|
|
88
116
|
//# sourceMappingURL=mappers.d.ts.map
|
package/dist/mappers.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mappers.d.ts","sourceRoot":"","sources":["../src/mappers.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,IAAI,iBAAiB,EAAE,UAAU,EAAE,KAAK,IAAI,WAAW,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,gDAAgD,CAAC;AAChK,OAAO,KAAK,EAAE,SAAS,IAAI,eAAe,EAAE,WAAW,IAAI,iBAAiB,EAAE,MAAM,sCAAsC,CAAC;AAC3H,OAAO,KAAK,EAAE,eAAe,IAAI,qBAAqB,EAAE,QAAQ,IAAI,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAEhI,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,cAAc,EAAE,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,YAAY,EAAW,gBAAgB,
|
|
1
|
+
{"version":3,"file":"mappers.d.ts","sourceRoot":"","sources":["../src/mappers.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,IAAI,iBAAiB,EAAE,UAAU,EAAE,KAAK,IAAI,WAAW,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,gDAAgD,CAAC;AAChK,OAAO,KAAK,EAAE,SAAS,IAAI,eAAe,EAAE,WAAW,IAAI,iBAAiB,EAAE,MAAM,sCAAsC,CAAC;AAC3H,OAAO,KAAK,EAAE,eAAe,IAAI,qBAAqB,EAAE,QAAQ,IAAI,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAEhI,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,cAAc,EAAE,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,YAAY,EAAW,gBAAgB,EAAkB,cAAc,EAAE,QAAQ,EAAE,aAAa,EAAE,M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E,OAAO,CAAC;CACnB;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,SAAS,SAAS,EAAE,EAAE,IAAI,EAAE,SAAS,SAAS,EAAE,EAAE,KAAK,EAAE,UAAU,GAAG,SAAS,EAAE,CAiBtH;AAED,wBAAgB,OAAO,CAAC,IAAI,EAAE,iBAAiB,GAAG,YAAY,CAE7D;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,YAAY,EAAE,GAAG,YAAY,CAMhE;AAKD,sFAAsF;AACtF,eAAO,MAAM,WAAW,QAAS,CAAC;AAElC,wEAAwE;AACxE,MAAM,WAAW,QAAQ,CAAC,CAAC;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,CAAC,CAAC;IACR,IAAI,EAAE,MAAM,CAAC;CAChB;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,CAAC,SAAS;IAAE,MAAM,EAAE,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;CAAE,EAAE,IAAI,EAAE,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,CAAC,CAAA;CAAE,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,CAAC,CAAA;CAAE,EAAE,CActM;AAID;;;GAGG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,QAAQ,GAAG,SAAS,EAAE,IAAI,EAAE,QAAQ,GAAG,QAAQ,CAQlF"}
|
package/dist/mappers.js
CHANGED
|
@@ -227,3 +227,46 @@ export function mergedPhase(phases) {
|
|
|
227
227
|
}
|
|
228
228
|
return "closed";
|
|
229
229
|
}
|
|
230
|
+
// ---------------------------------------------------------------- ZO-24: fresh reads
|
|
231
|
+
/** ZO-24: a worker's answer that failed is stood in for by its last one this long. */
|
|
232
|
+
export const STAND_IN_MS = 10_000;
|
|
233
|
+
/**
|
|
234
|
+
* ZO-24: a query goes to any replica of the subnet, and one a round behind answers from an
|
|
235
|
+
* older state (an offer flashing away and back). Per worker: an answer older than the held
|
|
236
|
+
* one is replaced by the held one; a worker that failed this time keeps its held answer for
|
|
237
|
+
* `STAND_IN_MS` (one silent worker does not blink its offers away). Updates `held`.
|
|
238
|
+
*/
|
|
239
|
+
export function freshViews(held, answers, failed, nowMs) {
|
|
240
|
+
const fresh = answers.map(({ worker, view }) => {
|
|
241
|
+
const asOf = view.asOfNs[0];
|
|
242
|
+
const before = held.get(worker);
|
|
243
|
+
if (asOf === undefined)
|
|
244
|
+
return { worker, view };
|
|
245
|
+
if (before && before.asOfNs > asOf)
|
|
246
|
+
return { worker, view: before.view };
|
|
247
|
+
held.set(worker, { asOfNs: asOf, view, atMs: nowMs });
|
|
248
|
+
return { worker, view };
|
|
249
|
+
});
|
|
250
|
+
for (const worker of failed) {
|
|
251
|
+
const before = held.get(worker);
|
|
252
|
+
if (before && nowMs - before.atMs <= STAND_IN_MS)
|
|
253
|
+
fresh.push({ worker, view: before.view });
|
|
254
|
+
}
|
|
255
|
+
return fresh;
|
|
256
|
+
}
|
|
257
|
+
const RIDE_STEP = { accepted: 0, driverArrived: 1, inProgress: 2, completed: 3, cancelledByDriver: 3, cancelledByRider: 3 };
|
|
258
|
+
/**
|
|
259
|
+
* ZO-24: a ride never goes back — an answer from an older state keeps the newer status, and
|
|
260
|
+
* the position stays the newer one (by `positionAtMs`).
|
|
261
|
+
*/
|
|
262
|
+
export function fresherRide(before, next) {
|
|
263
|
+
if (!before || before.requestId !== next.requestId)
|
|
264
|
+
return next;
|
|
265
|
+
let ride = next;
|
|
266
|
+
if (RIDE_STEP[next.status.kind] < RIDE_STEP[before.status.kind])
|
|
267
|
+
ride = { ...ride, status: before.status };
|
|
268
|
+
if (before.positionAtMs !== undefined && (next.positionAtMs === undefined || next.positionAtMs < before.positionAtMs)) {
|
|
269
|
+
ride = { ...ride, driverPosition: before.driverPosition, positionAtMs: before.positionAtMs, etaToPickupSec: before.etaToPickupSec };
|
|
270
|
+
}
|
|
271
|
+
return ride;
|
|
272
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsm-mit/tigi-sharded-package",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "The one package of the Tigi network group: takes the coordinator's id and hides the coordinator, the core and the workers — for a consumer the group is one canister; plus the rider's few driver-canister endpoints (U-14).",
|
|
5
5
|
"homepage": "https://github.com/JSM-Tigi/tigi-sharded/tree/master/package#readme",
|
|
6
6
|
"repository": {
|
|
@@ -59,11 +59,11 @@
|
|
|
59
59
|
"tigiSharded": {
|
|
60
60
|
"repo": "tigi-sharded",
|
|
61
61
|
"repoUrl": "https://github.com/JSM-Tigi/tigi-sharded",
|
|
62
|
-
"commit": "
|
|
62
|
+
"commit": "ac6ef3488e4cda361833ac4819491f8a0231df5b"
|
|
63
63
|
},
|
|
64
64
|
"tigiDriverRust": {
|
|
65
65
|
"repo": "tigi-driver-rust",
|
|
66
66
|
"repoUrl": "https://github.com/JSM-Tigi/tigi-driver-rust",
|
|
67
|
-
"commit": "
|
|
67
|
+
"commit": "516d8b97918290f300ca954e6f6efde4e9e41654"
|
|
68
68
|
}
|
|
69
69
|
}
|