minotor 11.5.0 → 11.5.2

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.
@@ -110,9 +110,9 @@ export declare class RangeResult {
110
110
  * the shortest travel duration (arrival time − origin departure time) across
111
111
  * all Pareto-optimal runs.
112
112
  *
113
- * Unlike {@link bestRoute}, which returns the route that departs as late as
114
- * possible while still arriving early, this method minimizes total time
115
- * spent traveling.
113
+ * When durations tie, the earliest departure is preferred.
114
+ * Unlike {@link bestRoute}, which minimizes arrival time, this method
115
+ * minimizes total time spent traveling.
116
116
  *
117
117
  * Defaults to this result's own destination stop(s) when `to` is omitted.
118
118
  * Always pass an explicit `to` stop when operating in full-network mode
@@ -1,5 +1,6 @@
1
1
  import { BinaryReader, BinaryWriter } from "@bufbuild/protobuf/wire";
2
2
  export declare const protobufPackage = "minotor.stops.v1";
3
+ export declare const protobufFileName = "src/stops/proto/v1/stops.proto";
3
4
  export declare enum LocationType {
4
5
  LOCATION_TYPE_UNSPECIFIED = 0,
5
6
  LOCATION_TYPE_SIMPLE_STOP_OR_PLATFORM = 1,
@@ -1,5 +1,6 @@
1
1
  import { BinaryReader, BinaryWriter } from "@bufbuild/protobuf/wire";
2
2
  export declare const protobufPackage = "minotor.timetable.v1";
3
+ export declare const protobufFileName = "src/timetable/proto/v1/timetable.proto";
3
4
  export declare enum TransferType {
4
5
  TRANSFER_TYPE_UNSPECIFIED = 0,
5
6
  TRANSFER_TYPE_RECOMMENDED_TRANSFER_POINT = 1,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "minotor",
3
- "version": "11.5.0",
3
+ "version": "11.5.2",
4
4
  "description": "A lightweight client-side transit routing library.",
5
5
  "keywords": [
6
6
  "minotor",
@@ -42,11 +42,11 @@
42
42
  }
43
43
  },
44
44
  "engines": {
45
- "node": ">=24.11.0",
45
+ "node": ">=24.15.0",
46
46
  "npm": ">=11.5.2"
47
47
  },
48
48
  "volta": {
49
- "node": "24.12.0",
49
+ "node": "24.22.0",
50
50
  "npm": "11.5.2"
51
51
  },
52
52
  "publishConfig": {
@@ -74,44 +74,44 @@
74
74
  "semantic-release": "semantic-release"
75
75
  },
76
76
  "devDependencies": {
77
- "@eslint/js": "^9.39.2",
78
- "@rollup/plugin-commonjs": "^29.0.2",
77
+ "@eslint/js": "^10.0.1",
78
+ "@rollup/plugin-commonjs": "^29.0.3",
79
79
  "@rollup/plugin-node-resolve": "^16.0.3",
80
80
  "@rollup/plugin-terser": "^1.0.0",
81
81
  "@rollup/plugin-typescript": "^12.3.0",
82
82
  "@ryansonshine/commitizen": "^4.2.8",
83
- "@ryansonshine/cz-conventional-changelog": "^3.3.1",
84
- "@semantic-release/changelog": "^6.0.3",
83
+ "@ryansonshine/cz-conventional-changelog": "^3.3.4",
84
+ "@semantic-release/changelog": "^7.0.0",
85
85
  "@semantic-release/commit-analyzer": "^13.0.1",
86
- "@semantic-release/github": "^12.0.2",
87
- "@semantic-release/npm": "^13.1.3",
88
- "@semantic-release/release-notes-generator": "^14.1.0",
86
+ "@semantic-release/github": "^12.0.10",
87
+ "@semantic-release/npm": "^13.2.0",
88
+ "@semantic-release/release-notes-generator": "^14.1.1",
89
89
  "@types/geokdbush": "^1.1.5",
90
- "@types/luxon": "^3.7.1",
91
- "@types/node": "^25.0.3",
92
- "c8": "^11.0.0",
93
- "cspell": "^9.4.0",
94
- "eslint": "^10.1.0",
90
+ "@types/luxon": "^3.7.6",
91
+ "@types/node": "^26.6.5",
92
+ "c8": "^12.0.0",
93
+ "cspell": "^10.4.0",
94
+ "eslint": "^10.13.0",
95
95
  "eslint-config-prettier": "^10.1.8",
96
- "eslint-plugin-simple-import-sort": "^12.1.1",
97
- "prettier": "^3.7.4",
98
- "rimraf": "^6.1.2",
99
- "rollup": "^4.55.1",
100
- "semantic-release": "^25.0.2",
101
- "ts-proto": "^2.10.1",
102
- "tsx": "^4.21.0",
103
- "typescript": "^5.9.3",
104
- "typescript-eslint": "^8.52.0"
96
+ "eslint-plugin-simple-import-sort": "^14.0.0",
97
+ "prettier": "^3.9.10",
98
+ "rimraf": "^6.1.3",
99
+ "rollup": "^4.64.10",
100
+ "semantic-release": "^25.0.9",
101
+ "ts-proto": "^2.18.0",
102
+ "tsx": "^4.23.15",
103
+ "typescript": "~6.0.3",
104
+ "typescript-eslint": "^8.72.0"
105
105
  },
106
106
  "dependencies": {
107
- "@bufbuild/protobuf": "^2.10.2",
108
- "commander": "^14.0.2",
109
- "csv-parse": "^6.1.0",
110
- "geokdbush": "^2.0.1",
111
- "kdbush": "^4.0.2",
107
+ "@bufbuild/protobuf": "^2.16.0",
108
+ "commander": "^15.0.0",
109
+ "csv-parse": "^7.0.3",
110
+ "geokdbush": "^2.1.0",
111
+ "kdbush": "^4.1.0",
112
112
  "loglevel": "^1.9.2",
113
113
  "luxon": "^3.7.2",
114
- "node-stream-zip": "^1.15.0",
115
- "slimsearch": "^2.3.0"
114
+ "node-stream-zip": "^1.16.0",
115
+ "slimsearch": "^3.0.0"
116
116
  }
117
117
  }
@@ -236,6 +236,25 @@ describe('RangeRouter', () => {
236
236
  assert.strictEqual(best.departureTime(), timeFromHM(8, 0));
237
237
  });
238
238
 
239
+ it('fastestRoute prefers the earliest departure when durations tie', () => {
240
+ const query = new RangeQuery.Builder()
241
+ .from(0)
242
+ .to(1)
243
+ .departureTime(timeFromHM(8, 0))
244
+ .lastDepartureTime(timeFromHM(8, 30))
245
+ .build();
246
+
247
+ const result = router.rangeRoute(query);
248
+ assert.strictEqual(result.size, 2);
249
+ for (const target of [undefined, 1, new Set([1])]) {
250
+ const fastest = result.fastestRoute(target);
251
+ assert(fastest);
252
+ assert.strictEqual(fastest.totalDuration(), 30);
253
+ assert.strictEqual(fastest.departureTime(), timeFromHM(8, 0));
254
+ assert.strictEqual(fastest.arrivalTime(), timeFromHM(8, 30));
255
+ }
256
+ });
257
+
239
258
  it('excludes a departure dominated by a later trip', () => {
240
259
  // Rebuild with a timetable where:
241
260
  // trip 0: departs 08:00 → arrives 09:00 (slower)
@@ -161,9 +161,9 @@ export class RangeResult {
161
161
  * the shortest travel duration (arrival time − origin departure time) across
162
162
  * all Pareto-optimal runs.
163
163
  *
164
- * Unlike {@link bestRoute}, which returns the route that departs as late as
165
- * possible while still arriving early, this method minimizes total time
166
- * spent traveling.
164
+ * When durations tie, the earliest departure is preferred.
165
+ * Unlike {@link bestRoute}, which minimizes arrival time, this method
166
+ * minimizes total time spent traveling.
167
167
  *
168
168
  * Defaults to this result's own destination stop(s) when `to` is omitted.
169
169
  * Always pass an explicit `to` stop when operating in full-network mode
@@ -184,7 +184,12 @@ export class RangeResult {
184
184
  const arrival = run.result.arrivalAt(stopId);
185
185
  if (arrival === undefined) continue;
186
186
  const duration = arrival.arrival - run.departureTime;
187
- if (duration < shortestDuration) {
187
+ if (
188
+ duration < shortestDuration ||
189
+ (duration === shortestDuration &&
190
+ fastestRun !== undefined &&
191
+ run.departureTime < fastestRun.departureTime)
192
+ ) {
188
193
  shortestDuration = duration;
189
194
  fastestRun = run;
190
195
  }
@@ -9,7 +9,7 @@ import {
9
9
  import { Duration, DURATION_ZERO, Time } from '../timetable/time.js';
10
10
  import { Timetable, TransferTypes, TripStop } from '../timetable/timetable.js';
11
11
  import { QueryOptions } from './query.js';
12
- import { RoutingEdge, TransferEdge, VehicleEdge } from './state.js';
12
+ import { RoutingEdge, VehicleEdge } from './state.js';
13
13
 
14
14
  /**
15
15
  * Common interface for all variants of RAPTOR routing.
@@ -411,7 +411,7 @@ export class Raptor {
411
411
  to: transfer.destination, // TODO needed?
412
412
  minTransferTime: transferTime || undefined,
413
413
  type: transfer.type,
414
- } as TransferEdge;
414
+ };
415
415
  state.updateArrival(
416
416
  transfer.destination,
417
417
  arrivalAfterTransfer,
@@ -5,7 +5,6 @@ import {
5
5
  DURATION_ZERO,
6
6
  durationToString,
7
7
  Time,
8
- TIME_ORIGIN,
9
8
  timeToString,
10
9
  } from '../timetable/time.js';
11
10
  import type {
@@ -81,7 +80,6 @@ export class Route {
81
80
  * @throws If no vehicle leg is found in the route.
82
81
  */
83
82
  arrivalTime(): Time {
84
- let lastVehicleArrivalTime: Time = TIME_ORIGIN;
85
83
  let totalTransferTime: Duration = DURATION_ZERO;
86
84
 
87
85
  // Find the last vehicle leg and sum transfer times that come after it
@@ -90,8 +88,7 @@ export class Route {
90
88
  const leg = this.legs[i]!;
91
89
 
92
90
  if ('arrivalTime' in leg) {
93
- lastVehicleArrivalTime = leg.arrivalTime;
94
- return lastVehicleArrivalTime + totalTransferTime;
91
+ return leg.arrivalTime + totalTransferTime;
95
92
  } else if ('minTransferTime' in leg && leg.minTransferTime) {
96
93
  totalTransferTime += leg.minTransferTime;
97
94
  }
@@ -1,6 +1,6 @@
1
1
  // Code generated by protoc-gen-ts_proto. DO NOT EDIT.
2
2
  // versions:
3
- // protoc-gen-ts_proto v2.10.1
3
+ // protoc-gen-ts_proto v2.18.0
4
4
  // protoc v4.23.4
5
5
  // source: src/stops/proto/v1/stops.proto
6
6
 
@@ -9,6 +9,8 @@ import { BinaryReader, BinaryWriter } from "@bufbuild/protobuf/wire";
9
9
 
10
10
  export const protobufPackage = "minotor.stops.v1";
11
11
 
12
+ export const protobufFileName = "src/stops/proto/v1/stops.proto";
13
+
12
14
  export enum LocationType {
13
15
  LOCATION_TYPE_UNSPECIFIED = 0,
14
16
  LOCATION_TYPE_SIMPLE_STOP_OR_PLATFORM = 1,
@@ -108,11 +110,13 @@ export const Stop: MessageFns<Stop> = {
108
110
  if (message.lon !== undefined) {
109
111
  writer.uint32(37).float(message.lon);
110
112
  }
111
- writer.uint32(42).fork();
112
- for (const v of message.children) {
113
- writer.uint32(v);
113
+ if (message.children.length !== 0) {
114
+ writer.uint32(42).fork();
115
+ for (const v of message.children) {
116
+ writer.uint32(v);
117
+ }
118
+ writer.join();
114
119
  }
115
- writer.join();
116
120
  if (message.parent !== undefined) {
117
121
  writer.uint32(48).uint32(message.parent);
118
122
  }
@@ -127,103 +131,120 @@ export const Stop: MessageFns<Stop> = {
127
131
 
128
132
  decode(input: BinaryReader | Uint8Array, length?: number): Stop {
129
133
  const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
130
- const end = length === undefined ? reader.len : reader.pos + length;
131
- const message = createBaseStop();
132
- while (reader.pos < end) {
133
- const tag = reader.uint32();
134
- switch (tag >>> 3) {
135
- case 1: {
136
- if (tag !== 10) {
137
- break;
138
- }
134
+ const previousRecursionDepth = (reader as any).__tsProtoDecodeDepth ?? 0;
135
+ if (previousRecursionDepth >= 100) {
136
+ throw new globalThis.Error("protobuf decode recursion limit exceeded");
137
+ }
138
+ (reader as any).__tsProtoDecodeDepth = previousRecursionDepth + 1;
139
+ try {
140
+ const end = length === undefined ? reader.len : reader.pos + length;
141
+ const message = createBaseStop();
142
+ while (reader.pos < end) {
143
+ const tag = reader.uint32();
144
+ switch (tag >>> 3) {
145
+ case 1: {
146
+ if (tag !== 10) {
147
+ break;
148
+ }
139
149
 
140
- message.name = reader.string();
141
- continue;
142
- }
143
- case 2: {
144
- if (tag !== 18) {
145
- break;
150
+ message.name = reader.string();
151
+ continue;
146
152
  }
153
+ case 2: {
154
+ if (tag !== 18) {
155
+ break;
156
+ }
147
157
 
148
- message.sourceStopId = reader.string();
149
- continue;
150
- }
151
- case 3: {
152
- if (tag !== 29) {
153
- break;
158
+ message.sourceStopId = reader.string();
159
+ continue;
154
160
  }
161
+ case 3: {
162
+ if (tag !== 29) {
163
+ break;
164
+ }
155
165
 
156
- message.lat = reader.float();
157
- continue;
158
- }
159
- case 4: {
160
- if (tag !== 37) {
161
- break;
166
+ message.lat = reader.float();
167
+ continue;
162
168
  }
169
+ case 4: {
170
+ if (tag !== 37) {
171
+ break;
172
+ }
163
173
 
164
- message.lon = reader.float();
165
- continue;
166
- }
167
- case 5: {
168
- if (tag === 40) {
169
- message.children.push(reader.uint32());
170
-
174
+ message.lon = reader.float();
171
175
  continue;
172
176
  }
173
-
174
- if (tag === 42) {
175
- const end2 = reader.uint32() + reader.pos;
176
- while (reader.pos < end2) {
177
+ case 5: {
178
+ if (tag === 40) {
177
179
  message.children.push(reader.uint32());
180
+
181
+ continue;
178
182
  }
179
183
 
180
- continue;
181
- }
184
+ if (tag === 42) {
185
+ const end2 = reader.uint32() + reader.pos;
186
+ while (reader.pos < end2) {
187
+ message.children.push(reader.uint32());
188
+ }
189
+
190
+ continue;
191
+ }
182
192
 
183
- break;
184
- }
185
- case 6: {
186
- if (tag !== 48) {
187
193
  break;
188
194
  }
195
+ case 6: {
196
+ if (tag !== 48) {
197
+ break;
198
+ }
189
199
 
190
- message.parent = reader.uint32();
191
- continue;
192
- }
193
- case 7: {
194
- if (tag !== 56) {
195
- break;
200
+ message.parent = reader.uint32();
201
+ continue;
196
202
  }
203
+ case 7: {
204
+ if (tag !== 56) {
205
+ break;
206
+ }
197
207
 
198
- message.locationType = reader.int32() as any;
199
- continue;
200
- }
201
- case 8: {
202
- if (tag !== 66) {
203
- break;
208
+ message.locationType = reader.int32() as any;
209
+ continue;
204
210
  }
211
+ case 8: {
212
+ if (tag !== 66) {
213
+ break;
214
+ }
205
215
 
206
- message.platform = reader.string();
207
- continue;
216
+ message.platform = reader.string();
217
+ continue;
218
+ }
208
219
  }
220
+ if ((tag & 7) === 4 || tag === 0) {
221
+ break;
222
+ }
223
+ reader.skip(tag & 7);
209
224
  }
210
- if ((tag & 7) === 4 || tag === 0) {
211
- break;
212
- }
213
- reader.skip(tag & 7);
225
+ return message;
226
+ } finally {
227
+ (reader as any).__tsProtoDecodeDepth = previousRecursionDepth;
214
228
  }
215
- return message;
216
229
  },
217
230
 
218
231
  fromJSON(object: any): Stop {
219
232
  return {
220
233
  name: isSet(object.name) ? globalThis.String(object.name) : "",
221
- sourceStopId: isSet(object.sourceStopId) ? globalThis.String(object.sourceStopId) : undefined,
234
+ sourceStopId: isSet(object.sourceStopId)
235
+ ? globalThis.String(object.sourceStopId)
236
+ : isSet(object.source_stop_id)
237
+ ? globalThis.String(object.source_stop_id)
238
+ : undefined,
222
239
  lat: isSet(object.lat) ? globalThis.Number(object.lat) : undefined,
223
240
  lon: isSet(object.lon) ? globalThis.Number(object.lon) : undefined,
224
241
  children: globalThis.Array.isArray(object?.children) ? object.children.map((e: any) => globalThis.Number(e)) : [],
225
242
  parent: isSet(object.parent) ? globalThis.Number(object.parent) : undefined,
226
- locationType: isSet(object.locationType) ? locationTypeFromJSON(object.locationType) : 0,
243
+ locationType: isSet(object.locationType)
244
+ ? locationTypeFromJSON(object.locationType)
245
+ : isSet(object.location_type)
246
+ ? locationTypeFromJSON(object.location_type)
247
+ : 0,
227
248
  platform: isSet(object.platform) ? globalThis.String(object.platform) : undefined,
228
249
  };
229
250
  },
@@ -237,10 +258,10 @@ export const Stop: MessageFns<Stop> = {
237
258
  obj.sourceStopId = message.sourceStopId;
238
259
  }
239
260
  if (message.lat !== undefined) {
240
- obj.lat = message.lat;
261
+ obj.lat = floatToJson(message.lat);
241
262
  }
242
263
  if (message.lon !== undefined) {
243
- obj.lon = message.lon;
264
+ obj.lon = floatToJson(message.lon);
244
265
  }
245
266
  if (message.children?.length) {
246
267
  obj.children = message.children.map((e) => Math.round(e));
@@ -288,26 +309,35 @@ export const StopsMap: MessageFns<StopsMap> = {
288
309
 
289
310
  decode(input: BinaryReader | Uint8Array, length?: number): StopsMap {
290
311
  const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
291
- const end = length === undefined ? reader.len : reader.pos + length;
292
- const message = createBaseStopsMap();
293
- while (reader.pos < end) {
294
- const tag = reader.uint32();
295
- switch (tag >>> 3) {
296
- case 2: {
297
- if (tag !== 18) {
298
- break;
299
- }
312
+ const previousRecursionDepth = (reader as any).__tsProtoDecodeDepth ?? 0;
313
+ if (previousRecursionDepth >= 100) {
314
+ throw new globalThis.Error("protobuf decode recursion limit exceeded");
315
+ }
316
+ (reader as any).__tsProtoDecodeDepth = previousRecursionDepth + 1;
317
+ try {
318
+ const end = length === undefined ? reader.len : reader.pos + length;
319
+ const message = createBaseStopsMap();
320
+ while (reader.pos < end) {
321
+ const tag = reader.uint32();
322
+ switch (tag >>> 3) {
323
+ case 2: {
324
+ if (tag !== 18) {
325
+ break;
326
+ }
300
327
 
301
- message.stops.push(Stop.decode(reader, reader.uint32()));
302
- continue;
328
+ message.stops.push(Stop.decode(reader, reader.uint32()));
329
+ continue;
330
+ }
303
331
  }
332
+ if ((tag & 7) === 4 || tag === 0) {
333
+ break;
334
+ }
335
+ reader.skip(tag & 7);
304
336
  }
305
- if ((tag & 7) === 4 || tag === 0) {
306
- break;
307
- }
308
- reader.skip(tag & 7);
337
+ return message;
338
+ } finally {
339
+ (reader as any).__tsProtoDecodeDepth = previousRecursionDepth;
309
340
  }
310
- return message;
311
341
  },
312
342
 
313
343
  fromJSON(object: any): StopsMap {
@@ -332,6 +362,10 @@ export const StopsMap: MessageFns<StopsMap> = {
332
362
  },
333
363
  };
334
364
 
365
+ function floatToJson(value: number | null | undefined): number | string | null | undefined {
366
+ return typeof value === "number" && !globalThis.Number.isFinite(value) ? globalThis.String(value) : value;
367
+ }
368
+
335
369
  type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
336
370
 
337
371
  export type DeepPartial<T> = T extends Builtin ? T
@@ -140,7 +140,7 @@ export class StopsIndex {
140
140
  maxResults,
141
141
  radius,
142
142
  ).map((id) => {
143
- const stopPoint = this.stopPoints[id as number] as StopPoint;
143
+ const stopPoint = this.stopPoints[id] as StopPoint;
144
144
  return this.stops[stopPoint.id] as Stop;
145
145
  });
146
146
  return nearestStops;