corequery-gtfs 0.1.0 → 0.1.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.
Files changed (185) hide show
  1. package/README.md +1 -1
  2. package/dist/config/gtfs-config.d.ts +10 -0
  3. package/dist/config/gtfs-config.js +2 -0
  4. package/dist/config/gtfs-config.js.map +1 -0
  5. package/dist/config/ids.d.ts +13 -0
  6. package/dist/config/ids.js +2 -0
  7. package/dist/config/ids.js.map +1 -0
  8. package/dist/config/index.d.ts +4 -0
  9. package/dist/config/index.js +5 -0
  10. package/dist/config/index.js.map +1 -0
  11. package/dist/config/routes.d.ts +16 -0
  12. package/dist/config/routes.js +2 -0
  13. package/dist/config/routes.js.map +1 -0
  14. package/dist/config/timezone-data.d.ts +5 -0
  15. package/dist/config/timezone-data.js +2 -0
  16. package/dist/config/timezone-data.js.map +1 -0
  17. package/dist/corequery-types.d.ts +2 -0
  18. package/dist/corequery-types.js +3 -0
  19. package/dist/corequery-types.js.map +1 -0
  20. package/dist/data/bounded-instant-range.d.ts +10 -0
  21. package/dist/data/bounded-instant-range.js +30 -0
  22. package/dist/data/bounded-instant-range.js.map +1 -0
  23. package/dist/data/gtfs-calendar.d.ts +38 -0
  24. package/dist/data/gtfs-calendar.js +116 -0
  25. package/dist/data/gtfs-calendar.js.map +1 -0
  26. package/dist/data/gtfs-feed.d.ts +16 -0
  27. package/dist/data/gtfs-feed.js +33 -0
  28. package/dist/data/gtfs-feed.js.map +1 -0
  29. package/dist/data/gtfs-realtime-data.d.ts +9 -0
  30. package/dist/data/gtfs-realtime-data.js +20 -0
  31. package/dist/data/gtfs-realtime-data.js.map +1 -0
  32. package/dist/data/gtfs-schedule-data.d.ts +13 -0
  33. package/dist/data/gtfs-schedule-data.js +40 -0
  34. package/dist/data/gtfs-schedule-data.js.map +1 -0
  35. package/dist/data/gtfs-scheduled-trip-movements.d.ts +118 -0
  36. package/dist/data/gtfs-scheduled-trip-movements.js +233 -0
  37. package/dist/data/gtfs-scheduled-trip-movements.js.map +1 -0
  38. package/dist/data/gtfs-scheduled-trip.d.ts +41 -0
  39. package/dist/data/gtfs-scheduled-trip.js +100 -0
  40. package/dist/data/gtfs-scheduled-trip.js.map +1 -0
  41. package/dist/data/gtfs-stop-time.d.ts +38 -0
  42. package/dist/data/gtfs-stop-time.js +105 -0
  43. package/dist/data/gtfs-stop-time.js.map +1 -0
  44. package/dist/data/gtfs-updated-trip-movements.d.ts +124 -0
  45. package/dist/data/gtfs-updated-trip-movements.js +150 -0
  46. package/dist/data/gtfs-updated-trip-movements.js.map +1 -0
  47. package/dist/data/gtfs-updated-trip.d.ts +21 -0
  48. package/dist/data/gtfs-updated-trip.js +55 -0
  49. package/dist/data/gtfs-updated-trip.js.map +1 -0
  50. package/dist/data/ids/index.d.ts +2 -0
  51. package/dist/data/ids/index.js +3 -0
  52. package/dist/data/ids/index.js.map +1 -0
  53. package/dist/data/ids/line-gtfs-id-collection.d.ts +16 -0
  54. package/dist/data/ids/line-gtfs-id-collection.js +47 -0
  55. package/dist/data/ids/line-gtfs-id-collection.js.map +1 -0
  56. package/dist/data/ids/line-gtfs-id-mapping.d.ts +17 -0
  57. package/dist/data/ids/line-gtfs-id-mapping.js +50 -0
  58. package/dist/data/ids/line-gtfs-id-mapping.js.map +1 -0
  59. package/dist/data/ids/line-gtfs-id-metadata.d.ts +17 -0
  60. package/dist/data/ids/line-gtfs-id-metadata.js +2 -0
  61. package/dist/data/ids/line-gtfs-id-metadata.js.map +1 -0
  62. package/dist/data/ids/stop-gtfs-id-collection.d.ts +14 -0
  63. package/dist/data/ids/stop-gtfs-id-collection.js +55 -0
  64. package/dist/data/ids/stop-gtfs-id-collection.js.map +1 -0
  65. package/dist/data/ids/stop-gtfs-id-mapping.d.ts +17 -0
  66. package/dist/data/ids/stop-gtfs-id-mapping.js +50 -0
  67. package/dist/data/ids/stop-gtfs-id-mapping.js.map +1 -0
  68. package/dist/data/ids/stop-gtfs-id-metadata.d.ts +23 -0
  69. package/dist/data/ids/stop-gtfs-id-metadata.js +2 -0
  70. package/dist/data/ids/stop-gtfs-id-metadata.js.map +1 -0
  71. package/dist/data/index.d.ts +3 -0
  72. package/dist/data/index.js +4 -0
  73. package/dist/data/index.js.map +1 -0
  74. package/dist/data/plain-date-range.d.ts +11 -0
  75. package/dist/data/plain-date-range.js +36 -0
  76. package/dist/data/plain-date-range.js.map +1 -0
  77. package/dist/data/raw/realtime-data-json.d.ts +26 -0
  78. package/dist/data/raw/realtime-data-json.js +2 -0
  79. package/dist/data/raw/realtime-data-json.js.map +1 -0
  80. package/dist/data/raw/schedule-csvs.d.ts +69 -0
  81. package/dist/data/raw/schedule-csvs.js +2 -0
  82. package/dist/data/raw/schedule-csvs.js.map +1 -0
  83. package/dist/data/route/bonus-lines-mapping.d.ts +17 -0
  84. package/dist/data/route/bonus-lines-mapping.js +29 -0
  85. package/dist/data/route/bonus-lines-mapping.js.map +1 -0
  86. package/dist/data/route/index.d.ts +1 -0
  87. package/dist/data/route/index.js +2 -0
  88. package/dist/data/route/index.js.map +1 -0
  89. package/dist/data/route/line-routes-mapping.d.ts +8 -0
  90. package/dist/data/route/line-routes-mapping.js +20 -0
  91. package/dist/data/route/line-routes-mapping.js.map +1 -0
  92. package/dist/data/route/route-stop.d.ts +12 -0
  93. package/dist/data/route/route-stop.js +18 -0
  94. package/dist/data/route/route-stop.js.map +1 -0
  95. package/dist/data/route/route.d.ts +19 -0
  96. package/dist/data/route/route.js +43 -0
  97. package/dist/data/route/route.js.map +1 -0
  98. package/dist/data/utils.d.ts +3 -0
  99. package/dist/data/utils.js +2 -0
  100. package/dist/data/utils.js.map +1 -0
  101. package/dist/departures/departures-block-iterator.d.ts +18 -0
  102. package/dist/departures/departures-block-iterator.js +70 -0
  103. package/dist/departures/departures-block-iterator.js.map +1 -0
  104. package/dist/departures/departures-block.d.ts +19 -0
  105. package/dist/departures/departures-block.js +13 -0
  106. package/dist/departures/departures-block.js.map +1 -0
  107. package/dist/departures/departures-iterator.d.ts +16 -0
  108. package/dist/departures/departures-iterator.js +15 -0
  109. package/dist/departures/departures-iterator.js.map +1 -0
  110. package/dist/departures/gtfs-scheduled-movements-index.d.ts +18 -0
  111. package/dist/departures/gtfs-scheduled-movements-index.js +66 -0
  112. package/dist/departures/gtfs-scheduled-movements-index.js.map +1 -0
  113. package/dist/departures/index.d.ts +1 -0
  114. package/dist/departures/index.js +2 -0
  115. package/dist/departures/index.js.map +1 -0
  116. package/dist/departures/multifeed-departures-iterator.d.ts +20 -0
  117. package/dist/departures/multifeed-departures-iterator.js +52 -0
  118. package/dist/departures/multifeed-departures-iterator.js.map +1 -0
  119. package/dist/departures/realtime-departures-block-iterator.d.ts +12 -0
  120. package/dist/departures/realtime-departures-block-iterator.js +38 -0
  121. package/dist/departures/realtime-departures-block-iterator.js.map +1 -0
  122. package/dist/departures/realtime-departures-block.d.ts +16 -0
  123. package/dist/departures/realtime-departures-block.js +43 -0
  124. package/dist/departures/realtime-departures-block.js.map +1 -0
  125. package/dist/departures/scheduled-departures-block-iterator.d.ts +12 -0
  126. package/dist/departures/scheduled-departures-block-iterator.js +55 -0
  127. package/dist/departures/scheduled-departures-block-iterator.js.map +1 -0
  128. package/dist/departures/scheduled-departures-block.d.ts +18 -0
  129. package/dist/departures/scheduled-departures-block.js +54 -0
  130. package/dist/departures/scheduled-departures-block.js.map +1 -0
  131. package/dist/departures/scheduled-departures-blocks-builder.d.ts +20 -0
  132. package/dist/departures/scheduled-departures-blocks-builder.js +222 -0
  133. package/dist/departures/scheduled-departures-blocks-builder.js.map +1 -0
  134. package/dist/departures/scheduled-departures-iterator.d.ts +30 -0
  135. package/dist/departures/scheduled-departures-iterator.js +204 -0
  136. package/dist/departures/scheduled-departures-iterator.js.map +1 -0
  137. package/dist/departures/zipper-departures-iterator.d.ts +18 -0
  138. package/dist/departures/zipper-departures-iterator.js +68 -0
  139. package/dist/departures/zipper-departures-iterator.js.map +1 -0
  140. package/dist/gtfs-system.d.ts +31 -0
  141. package/dist/gtfs-system.js +86 -0
  142. package/dist/gtfs-system.js.map +1 -0
  143. package/dist/index.d.ts +6 -0
  144. package/dist/index.js +7 -0
  145. package/dist/index.js.map +1 -0
  146. package/dist/parser/gtfs-feed-parser.d.ts +18 -0
  147. package/dist/parser/gtfs-feed-parser.js +23 -0
  148. package/dist/parser/gtfs-feed-parser.js.map +1 -0
  149. package/dist/parser/index.d.ts +2 -0
  150. package/dist/parser/index.js +3 -0
  151. package/dist/parser/index.js.map +1 -0
  152. package/dist/parser/realtime/gtfs-realtime-data-parser.d.ts +11 -0
  153. package/dist/parser/realtime/gtfs-realtime-data-parser.js +19 -0
  154. package/dist/parser/realtime/gtfs-realtime-data-parser.js.map +1 -0
  155. package/dist/parser/realtime/gtfs-trip-update-parser.d.ts +99 -0
  156. package/dist/parser/realtime/gtfs-trip-update-parser.js +335 -0
  157. package/dist/parser/realtime/gtfs-trip-update-parser.js.map +1 -0
  158. package/dist/parser/realtime/gtfs-trip-update-trip-identifier.d.ts +35 -0
  159. package/dist/parser/realtime/gtfs-trip-update-trip-identifier.js +95 -0
  160. package/dist/parser/realtime/gtfs-trip-update-trip-identifier.js.map +1 -0
  161. package/dist/parser/realtime/index.d.ts +3 -0
  162. package/dist/parser/realtime/index.js +2 -0
  163. package/dist/parser/realtime/index.js.map +1 -0
  164. package/dist/parser/schedule/gtfs-calendar-parser.d.ts +28 -0
  165. package/dist/parser/schedule/gtfs-calendar-parser.js +113 -0
  166. package/dist/parser/schedule/gtfs-calendar-parser.js.map +1 -0
  167. package/dist/parser/schedule/gtfs-route-matcher.d.ts +48 -0
  168. package/dist/parser/schedule/gtfs-route-matcher.js +199 -0
  169. package/dist/parser/schedule/gtfs-route-matcher.js.map +1 -0
  170. package/dist/parser/schedule/gtfs-schedule-parser.d.ts +15 -0
  171. package/dist/parser/schedule/gtfs-schedule-parser.js +19 -0
  172. package/dist/parser/schedule/gtfs-schedule-parser.js.map +1 -0
  173. package/dist/parser/schedule/gtfs-stop-time-normaliser.d.ts +47 -0
  174. package/dist/parser/schedule/gtfs-stop-time-normaliser.js +119 -0
  175. package/dist/parser/schedule/gtfs-stop-time-normaliser.js.map +1 -0
  176. package/dist/parser/schedule/gtfs-transfer-connector.d.ts +52 -0
  177. package/dist/parser/schedule/gtfs-transfer-connector.js +168 -0
  178. package/dist/parser/schedule/gtfs-transfer-connector.js.map +1 -0
  179. package/dist/parser/schedule/gtfs-trip-parser.d.ts +45 -0
  180. package/dist/parser/schedule/gtfs-trip-parser.js +169 -0
  181. package/dist/parser/schedule/gtfs-trip-parser.js.map +1 -0
  182. package/dist/parser/schedule/index.d.ts +6 -0
  183. package/dist/parser/schedule/index.js +2 -0
  184. package/dist/parser/schedule/index.js.map +1 -0
  185. package/package.json +3 -3
@@ -0,0 +1,99 @@
1
+ import type { GtfsScheduleData } from "../../data/gtfs-schedule-data.js";
2
+ import type { GtfsScheduledTrip } from "../../data/gtfs-scheduled-trip.js";
3
+ import { GtfsUpdatedTrip } from "../../data/gtfs-updated-trip.js";
4
+ import type { StopTimeUpdateJson, TripUpdateJson, UpdatedTimeJson } from "../../data/raw/realtime-data-json.js";
5
+ import { type GtfsTripUpdateTripIdentificationError } from "./gtfs-trip-update-trip-identifier.js";
6
+ import type { StopGtfsIdMapping } from "../../data/ids/stop-gtfs-id-mapping.js";
7
+ export declare class GtfsTripUpdateParser {
8
+ private readonly _timezone;
9
+ private readonly _onError;
10
+ private readonly _tripIdentifier;
11
+ constructor(_timezone: string, _onError: (error: GtfsTripUpdateParsingError) => void);
12
+ parse(tripUpdate: TripUpdateJson, scheduleData: GtfsScheduleData, stopGtfsIdMapping: StopGtfsIdMapping): GtfsUpdatedTrip | null;
13
+ private _parseForScheduledTrip;
14
+ private _parseForCancelledTrip;
15
+ private _parseUpdatedTime;
16
+ }
17
+ export type GtfsTripUpdateParsingError = UnsupportedTripUpdateScheduleRelationshipError | GtfsTripUpdateTripIdentificationError | NoStopTimeUpdateFieldGivenError | UnsupportedStopTimeUpdateEntryScheduleRelationshipError | NecessaryFieldNotInStopTimeUpdateEntryError | StopTimeUpdateEntryReferencesNonExistentStopSequenceError | MultipleStopTimeUpdateEntriesForSameMovementIndexError | StopTimeUpdateEntryReferencesUnmappedStopIdError | StopTimeUpdateEntryChangesStopError | StopTimeUpdateEntryChangesPlatformError | NeitherTimeNorDelayGivenError | TimeAndDelayDisagreeWithEachOtherError | NeitherArrivalNorDepartureGivenError;
18
+ export declare class UnsupportedTripUpdateScheduleRelationshipError extends Error {
19
+ readonly tripUpdate: TripUpdateJson;
20
+ readonly type = "unsupported-trip-update-schedule-relationship";
21
+ constructor(tripUpdate: TripUpdateJson);
22
+ }
23
+ export declare class NoStopTimeUpdateFieldGivenError extends Error {
24
+ readonly tripUpdate: TripUpdateJson;
25
+ readonly type = "no-stop-time-update-field-given";
26
+ constructor(tripUpdate: TripUpdateJson);
27
+ }
28
+ export declare class UnsupportedStopTimeUpdateEntryScheduleRelationshipError extends Error {
29
+ readonly tripUpdate: TripUpdateJson;
30
+ readonly stopTimeUpdateEntry: StopTimeUpdateJson;
31
+ readonly type = "unsupported-stop-time-update-entry-schedule-relationship";
32
+ constructor(tripUpdate: TripUpdateJson, stopTimeUpdateEntry: StopTimeUpdateJson);
33
+ }
34
+ export declare class NecessaryFieldNotInStopTimeUpdateEntryError extends Error {
35
+ readonly tripUpdate: TripUpdateJson;
36
+ readonly stopTimeUpdateEntry: StopTimeUpdateJson;
37
+ readonly field: "stopSequence" | "stopId";
38
+ readonly type = "necessary-field-not-in-stop-time-update-entry";
39
+ constructor(tripUpdate: TripUpdateJson, stopTimeUpdateEntry: StopTimeUpdateJson, field: "stopSequence" | "stopId");
40
+ }
41
+ export declare class StopTimeUpdateEntryReferencesNonExistentStopSequenceError extends Error {
42
+ readonly tripUpdate: TripUpdateJson;
43
+ readonly stopTimeUpdateEntry: StopTimeUpdateJson;
44
+ readonly matchedTrip: GtfsScheduledTrip;
45
+ readonly type = "stop-time-update-entry-references-non-existent-stop-sequence";
46
+ constructor(tripUpdate: TripUpdateJson, stopTimeUpdateEntry: StopTimeUpdateJson, matchedTrip: GtfsScheduledTrip);
47
+ }
48
+ export declare class MultipleStopTimeUpdateEntriesForSameMovementIndexError extends Error {
49
+ readonly tripUpdate: TripUpdateJson;
50
+ readonly stopTimeUpdateEntry: StopTimeUpdateJson;
51
+ readonly matchedTrip: GtfsScheduledTrip;
52
+ readonly matchedMovementIndex: number;
53
+ readonly type = "multiple-stop-time-update-entries-for-same-movement-index";
54
+ constructor(tripUpdate: TripUpdateJson, stopTimeUpdateEntry: StopTimeUpdateJson, matchedTrip: GtfsScheduledTrip, matchedMovementIndex: number);
55
+ }
56
+ export declare class StopTimeUpdateEntryReferencesUnmappedStopIdError extends Error {
57
+ readonly tripUpdate: TripUpdateJson;
58
+ readonly stopTimeUpdateEntry: StopTimeUpdateJson;
59
+ readonly type = "stop-time-update-entry-references-unmapped-stop-id";
60
+ constructor(tripUpdate: TripUpdateJson, stopTimeUpdateEntry: StopTimeUpdateJson);
61
+ }
62
+ export declare class StopTimeUpdateEntryChangesStopError extends Error {
63
+ readonly tripUpdate: TripUpdateJson;
64
+ readonly stopTimeUpdateEntry: StopTimeUpdateJson;
65
+ readonly matchedTrip: GtfsScheduledTrip;
66
+ readonly matchedMovementIndex: number;
67
+ readonly type = "stop-time-update-entry-changes-stop";
68
+ constructor(tripUpdate: TripUpdateJson, stopTimeUpdateEntry: StopTimeUpdateJson, matchedTrip: GtfsScheduledTrip, matchedMovementIndex: number);
69
+ }
70
+ export declare class StopTimeUpdateEntryChangesPlatformError extends Error {
71
+ readonly tripUpdate: TripUpdateJson;
72
+ readonly stopTimeUpdateEntry: StopTimeUpdateJson;
73
+ readonly matchedTrip: GtfsScheduledTrip;
74
+ readonly matchedMovementIndex: number;
75
+ readonly type = "stop-time-update-entry-changes-platform";
76
+ constructor(tripUpdate: TripUpdateJson, stopTimeUpdateEntry: StopTimeUpdateJson, matchedTrip: GtfsScheduledTrip, matchedMovementIndex: number);
77
+ }
78
+ export declare class NeitherTimeNorDelayGivenError extends Error {
79
+ readonly tripUpdate: TripUpdateJson;
80
+ readonly stopTimeUpdateEntry: StopTimeUpdateJson;
81
+ readonly updatedTime: UpdatedTimeJson;
82
+ readonly type = "neither-time-nor-delay-given";
83
+ constructor(tripUpdate: TripUpdateJson, stopTimeUpdateEntry: StopTimeUpdateJson, updatedTime: UpdatedTimeJson);
84
+ }
85
+ export declare class TimeAndDelayDisagreeWithEachOtherError extends Error {
86
+ readonly tripUpdate: TripUpdateJson;
87
+ readonly stopTimeUpdateEntry: StopTimeUpdateJson;
88
+ readonly updatedTime: UpdatedTimeJson;
89
+ readonly parsedFromTime: Temporal.Instant;
90
+ readonly parsedFromDelay: Temporal.Instant;
91
+ readonly type = "time-and-delay-disagree-with-each-other";
92
+ constructor(tripUpdate: TripUpdateJson, stopTimeUpdateEntry: StopTimeUpdateJson, updatedTime: UpdatedTimeJson, parsedFromTime: Temporal.Instant, parsedFromDelay: Temporal.Instant);
93
+ }
94
+ export declare class NeitherArrivalNorDepartureGivenError extends Error {
95
+ readonly tripUpdate: TripUpdateJson;
96
+ readonly stopTimeUpdateEntry: StopTimeUpdateJson;
97
+ readonly type = "neither-arrival-nor-departure-given";
98
+ constructor(tripUpdate: TripUpdateJson, stopTimeUpdateEntry: StopTimeUpdateJson);
99
+ }
@@ -0,0 +1,335 @@
1
+ import { GtfsUpdatedTrip } from "../../data/gtfs-updated-trip.js";
2
+ import { GtfsTripUpdateTripIdentifier, } from "./gtfs-trip-update-trip-identifier.js";
3
+ import { itsOk } from "@dan-schel/js-utils";
4
+ const TRIP_UPDATE_SCHEDULE_RELATIONSHIP_SCHEDULED = "SCHEDULED";
5
+ const TRIP_UPDATE_SCHEDULE_RELATIONSHIP_CANCELLED = "CANCELED";
6
+ const STOP_TIME_UPDATE_ENTRY_SCHEDULE_RELATIONSHIP_SCHEDULED = "SCHEDULED";
7
+ export class GtfsTripUpdateParser {
8
+ _timezone;
9
+ _onError;
10
+ _tripIdentifier;
11
+ constructor(
12
+ // We could maybe store this in the GtfsSchedule obj itself if we wanted,
13
+ // since you can parse it from agency.txt.
14
+ _timezone, _onError) {
15
+ this._timezone = _timezone;
16
+ this._onError = _onError;
17
+ this._tripIdentifier = new GtfsTripUpdateTripIdentifier(_onError);
18
+ }
19
+ parse(tripUpdate, scheduleData, stopGtfsIdMapping) {
20
+ const sr = tripUpdate.trip.scheduleRelationship;
21
+ if (sr === TRIP_UPDATE_SCHEDULE_RELATIONSHIP_SCHEDULED) {
22
+ return this._parseForScheduledTrip(tripUpdate, scheduleData, stopGtfsIdMapping);
23
+ }
24
+ else if (sr === TRIP_UPDATE_SCHEDULE_RELATIONSHIP_CANCELLED) {
25
+ return this._parseForCancelledTrip(tripUpdate, scheduleData);
26
+ }
27
+ else {
28
+ this._onError(new UnsupportedTripUpdateScheduleRelationshipError(tripUpdate));
29
+ return null;
30
+ }
31
+ }
32
+ _parseForScheduledTrip(tripUpdate, scheduleData, stopGtfsIdMapping) {
33
+ const result = this._tripIdentifier.identify(tripUpdate.trip, scheduleData);
34
+ if (result == null)
35
+ return null;
36
+ const { trip, serviceDay } = result;
37
+ if (tripUpdate.stopTimeUpdate == null) {
38
+ this._onError(new NoStopTimeUpdateFieldGivenError(tripUpdate));
39
+ return null;
40
+ }
41
+ const updatedMovementsByIndex = new Map();
42
+ for (const entry of tripUpdate.stopTimeUpdate) {
43
+ // This `scheduleRelationship` field is probably how altered routes work.
44
+ const sr = entry.scheduleRelationship;
45
+ if (sr !== STOP_TIME_UPDATE_ENTRY_SCHEDULE_RELATIONSHIP_SCHEDULED) {
46
+ const Err = UnsupportedStopTimeUpdateEntryScheduleRelationshipError;
47
+ this._onError(new Err(tripUpdate, entry));
48
+ return null;
49
+ }
50
+ // Check the fields we're gonna rely on (that PTV seems to reliably give
51
+ // but are technically optional in the GTFS-RT spec) are actually present.
52
+ if (entry.stopSequence == null) {
53
+ const Err = NecessaryFieldNotInStopTimeUpdateEntryError;
54
+ this._onError(new Err(tripUpdate, entry, "stopSequence"));
55
+ return null;
56
+ }
57
+ if (entry.stopId == null) {
58
+ const Err = NecessaryFieldNotInStopTimeUpdateEntryError;
59
+ this._onError(new Err(tripUpdate, entry, "stopId"));
60
+ return null;
61
+ }
62
+ if (entry.arrival == null && entry.departure == null) {
63
+ const Err = NeitherArrivalNorDepartureGivenError;
64
+ this._onError(new Err(tripUpdate, entry));
65
+ return null;
66
+ }
67
+ // Find the stop in the scheduled trip that this update is supposed to be
68
+ // for.
69
+ const movementIndex = trip.movements.findIndex((m) => m.isServicing && m.gtfsStopSequence === entry.stopSequence);
70
+ if (movementIndex === -1) {
71
+ const Err = StopTimeUpdateEntryReferencesNonExistentStopSequenceError;
72
+ this._onError(new Err(tripUpdate, entry, trip));
73
+ return null;
74
+ }
75
+ // Enforced by findIndex above.
76
+ const scheduledMovement = itsOk(trip.movements[movementIndex]);
77
+ if (!scheduledMovement.isServicing)
78
+ throw new Error();
79
+ // Check that we haven't already matched a stop time update entry to this
80
+ // movement index. (Would happen if `stopSequence` was the same value
81
+ // twice, I guess.)
82
+ if (updatedMovementsByIndex.has(movementIndex)) {
83
+ const Err = MultipleStopTimeUpdateEntriesForSameMovementIndexError;
84
+ this._onError(new Err(tripUpdate, entry, trip, movementIndex));
85
+ return null;
86
+ }
87
+ // Look up the stop GTFS ID given in the stop time update entry, and check
88
+ // whether it still maps to the same (CoreQuery) stop. In this way, we
89
+ // allow the platform/position ID to change, not the overall stop/station.
90
+ const gtfsIdMetadata = stopGtfsIdMapping.tryResolve(entry.stopId);
91
+ if (gtfsIdMetadata == null) {
92
+ const Err = StopTimeUpdateEntryReferencesUnmappedStopIdError;
93
+ this._onError(new Err(tripUpdate, entry));
94
+ return null;
95
+ }
96
+ if (gtfsIdMetadata.stopId !== scheduledMovement.gtfsIdMetadata.stopId) {
97
+ const Err = StopTimeUpdateEntryChangesStopError;
98
+ this._onError(new Err(tripUpdate, entry, trip, movementIndex));
99
+ return null;
100
+ }
101
+ // This is not really an error (note that I don't return null!), it's just
102
+ // logging to see if it ever happens. We support platform changes done in
103
+ // this way, but I built that support on assumptions, and I have no idea
104
+ // if this is typically how PTV would represent a platform change.
105
+ if (gtfsIdMetadata.id !== scheduledMovement.gtfsIdMetadata.id) {
106
+ const Err = StopTimeUpdateEntryChangesPlatformError;
107
+ this._onError(new Err(tripUpdate, entry, trip, movementIndex));
108
+ }
109
+ const updatedPositionId = gtfsIdMetadata.type === "platform" ? gtfsIdMetadata.positionId : null;
110
+ // Parse the updated times from the `arrivalTime` and `departureTime`
111
+ // fields.
112
+ const realtimeArrivalTime = "arrivalTime" in scheduledMovement
113
+ ? this._parseUpdatedTime(entry.arrival ?? null, scheduledMovement.arrivalTime, serviceDay, tripUpdate, entry)
114
+ : null;
115
+ const realtimeDepartureTime = "departureTime" in scheduledMovement
116
+ ? this._parseUpdatedTime(entry.departure ?? null, scheduledMovement.departureTime, serviceDay, tripUpdate, entry)
117
+ : null;
118
+ updatedMovementsByIndex.set(movementIndex, scheduledMovement.asUpdatedTripMovement({
119
+ arrivalTime: realtimeArrivalTime,
120
+ departureTime: realtimeDepartureTime,
121
+ updatedPositionId,
122
+ updatedGtfsIdMetadata: gtfsIdMetadata,
123
+ serviceDay,
124
+ timezone: this._timezone,
125
+ }));
126
+ }
127
+ let movements = trip.movements.map((m) => m.asHollowUpdatedTripMovement(serviceDay, this._timezone));
128
+ movements = movements.map((movement, i) => {
129
+ return updatedMovementsByIndex.get(i) ?? movement;
130
+ });
131
+ return new GtfsUpdatedTrip({
132
+ scheduledTrip: trip,
133
+ serviceDay,
134
+ movements,
135
+ isCancelled: false,
136
+ });
137
+ }
138
+ _parseForCancelledTrip(tripUpdate, scheduleData) {
139
+ const result = this._tripIdentifier.identify(tripUpdate.trip, scheduleData);
140
+ if (result == null)
141
+ return null;
142
+ const { trip, serviceDay } = result;
143
+ return GtfsUpdatedTrip.unmodified(trip, serviceDay, this._timezone).with({
144
+ isCancelled: true,
145
+ });
146
+ }
147
+ _parseUpdatedTime(updatedTime, scheduledTime, serviceDay, tripUpdate, stopTimeUpdateEntry) {
148
+ if (updatedTime == null) {
149
+ return null;
150
+ }
151
+ const { time, delay } = updatedTime;
152
+ const fromTime = time != null ? Temporal.Instant.fromEpochMilliseconds(time * 1000) : null;
153
+ const fromDelay = delay != null
154
+ ? scheduledTime
155
+ .toInstant(serviceDay, this._timezone)
156
+ .add({ seconds: delay })
157
+ : null;
158
+ // Most/all trips in PTV's realtime feed have both time and delay. If using
159
+ // both of those methods gives us different results, then I've probably
160
+ // messed something up (e.g. maybe my service day assumption in the trip
161
+ // identifier is wrong)... or PTV has.
162
+ //
163
+ // We'll press on (this check is only meant for reporting/my interest), but
164
+ // the something's probably gonna be very broken for this trip!
165
+ if (fromTime != null && fromDelay != null && !fromTime.equals(fromDelay)) {
166
+ this._onError(new TimeAndDelayDisagreeWithEachOtherError(tripUpdate, stopTimeUpdateEntry, updatedTime, fromTime, fromDelay));
167
+ }
168
+ // I don't think it really matters which of `delay` or `time` we preference,
169
+ // since they're either identical, or we've (probably) messed up the service
170
+ // day, in which case we're either applying the right time to the wrong
171
+ // service (`time`), or the we've calculated the time assuming the wrong
172
+ // service day (`delay`).
173
+ //
174
+ // It'll probably be clearer to me trying to debug this if we apply this
175
+ // realtime update to yesterday/tomorrow's service and it makes it look like
176
+ // there's two departures of the same service happening at/near to the same
177
+ // time, so I'll pick `time`.
178
+ if (fromTime != null) {
179
+ return fromTime;
180
+ }
181
+ else if (fromDelay != null) {
182
+ return fromDelay;
183
+ }
184
+ else {
185
+ const Err = NeitherTimeNorDelayGivenError;
186
+ this._onError(new Err(tripUpdate, stopTimeUpdateEntry, updatedTime));
187
+ return null;
188
+ }
189
+ }
190
+ }
191
+ export class UnsupportedTripUpdateScheduleRelationshipError extends Error {
192
+ tripUpdate;
193
+ type = "unsupported-trip-update-schedule-relationship";
194
+ constructor(tripUpdate) {
195
+ super();
196
+ this.tripUpdate = tripUpdate;
197
+ }
198
+ }
199
+ export class NoStopTimeUpdateFieldGivenError extends Error {
200
+ tripUpdate;
201
+ type = "no-stop-time-update-field-given";
202
+ constructor(tripUpdate) {
203
+ super();
204
+ this.tripUpdate = tripUpdate;
205
+ }
206
+ }
207
+ export class UnsupportedStopTimeUpdateEntryScheduleRelationshipError extends Error {
208
+ tripUpdate;
209
+ stopTimeUpdateEntry;
210
+ type = "unsupported-stop-time-update-entry-schedule-relationship";
211
+ constructor(tripUpdate, stopTimeUpdateEntry) {
212
+ super();
213
+ this.tripUpdate = tripUpdate;
214
+ this.stopTimeUpdateEntry = stopTimeUpdateEntry;
215
+ }
216
+ }
217
+ export class NecessaryFieldNotInStopTimeUpdateEntryError extends Error {
218
+ tripUpdate;
219
+ stopTimeUpdateEntry;
220
+ field;
221
+ type = "necessary-field-not-in-stop-time-update-entry";
222
+ constructor(tripUpdate, stopTimeUpdateEntry, field) {
223
+ super();
224
+ this.tripUpdate = tripUpdate;
225
+ this.stopTimeUpdateEntry = stopTimeUpdateEntry;
226
+ this.field = field;
227
+ }
228
+ }
229
+ export class StopTimeUpdateEntryReferencesNonExistentStopSequenceError extends Error {
230
+ tripUpdate;
231
+ stopTimeUpdateEntry;
232
+ matchedTrip;
233
+ type = "stop-time-update-entry-references-non-existent-stop-sequence";
234
+ constructor(tripUpdate, stopTimeUpdateEntry, matchedTrip) {
235
+ super();
236
+ this.tripUpdate = tripUpdate;
237
+ this.stopTimeUpdateEntry = stopTimeUpdateEntry;
238
+ this.matchedTrip = matchedTrip;
239
+ }
240
+ }
241
+ export class MultipleStopTimeUpdateEntriesForSameMovementIndexError extends Error {
242
+ tripUpdate;
243
+ stopTimeUpdateEntry;
244
+ matchedTrip;
245
+ matchedMovementIndex;
246
+ type = "multiple-stop-time-update-entries-for-same-movement-index";
247
+ constructor(tripUpdate, stopTimeUpdateEntry, matchedTrip, matchedMovementIndex) {
248
+ super();
249
+ this.tripUpdate = tripUpdate;
250
+ this.stopTimeUpdateEntry = stopTimeUpdateEntry;
251
+ this.matchedTrip = matchedTrip;
252
+ this.matchedMovementIndex = matchedMovementIndex;
253
+ }
254
+ }
255
+ export class StopTimeUpdateEntryReferencesUnmappedStopIdError extends Error {
256
+ tripUpdate;
257
+ stopTimeUpdateEntry;
258
+ type = "stop-time-update-entry-references-unmapped-stop-id";
259
+ constructor(tripUpdate, stopTimeUpdateEntry) {
260
+ super();
261
+ this.tripUpdate = tripUpdate;
262
+ this.stopTimeUpdateEntry = stopTimeUpdateEntry;
263
+ }
264
+ }
265
+ // i.e. It doesn't just change the platform (which we're fine with), but the
266
+ // entire stop.
267
+ export class StopTimeUpdateEntryChangesStopError extends Error {
268
+ tripUpdate;
269
+ stopTimeUpdateEntry;
270
+ matchedTrip;
271
+ matchedMovementIndex;
272
+ type = "stop-time-update-entry-changes-stop";
273
+ constructor(tripUpdate, stopTimeUpdateEntry, matchedTrip, matchedMovementIndex) {
274
+ super();
275
+ this.tripUpdate = tripUpdate;
276
+ this.stopTimeUpdateEntry = stopTimeUpdateEntry;
277
+ this.matchedTrip = matchedTrip;
278
+ this.matchedMovementIndex = matchedMovementIndex;
279
+ }
280
+ }
281
+ // Just logging this to see if it ever happens. It's not really an error, and we
282
+ // handle it well.
283
+ export class StopTimeUpdateEntryChangesPlatformError extends Error {
284
+ tripUpdate;
285
+ stopTimeUpdateEntry;
286
+ matchedTrip;
287
+ matchedMovementIndex;
288
+ type = "stop-time-update-entry-changes-platform";
289
+ constructor(tripUpdate, stopTimeUpdateEntry, matchedTrip, matchedMovementIndex) {
290
+ super();
291
+ this.tripUpdate = tripUpdate;
292
+ this.stopTimeUpdateEntry = stopTimeUpdateEntry;
293
+ this.matchedTrip = matchedTrip;
294
+ this.matchedMovementIndex = matchedMovementIndex;
295
+ }
296
+ }
297
+ export class NeitherTimeNorDelayGivenError extends Error {
298
+ tripUpdate;
299
+ stopTimeUpdateEntry;
300
+ updatedTime;
301
+ type = "neither-time-nor-delay-given";
302
+ constructor(tripUpdate, stopTimeUpdateEntry, updatedTime) {
303
+ super();
304
+ this.tripUpdate = tripUpdate;
305
+ this.stopTimeUpdateEntry = stopTimeUpdateEntry;
306
+ this.updatedTime = updatedTime;
307
+ }
308
+ }
309
+ export class TimeAndDelayDisagreeWithEachOtherError extends Error {
310
+ tripUpdate;
311
+ stopTimeUpdateEntry;
312
+ updatedTime;
313
+ parsedFromTime;
314
+ parsedFromDelay;
315
+ type = "time-and-delay-disagree-with-each-other";
316
+ constructor(tripUpdate, stopTimeUpdateEntry, updatedTime, parsedFromTime, parsedFromDelay) {
317
+ super();
318
+ this.tripUpdate = tripUpdate;
319
+ this.stopTimeUpdateEntry = stopTimeUpdateEntry;
320
+ this.updatedTime = updatedTime;
321
+ this.parsedFromTime = parsedFromTime;
322
+ this.parsedFromDelay = parsedFromDelay;
323
+ }
324
+ }
325
+ export class NeitherArrivalNorDepartureGivenError extends Error {
326
+ tripUpdate;
327
+ stopTimeUpdateEntry;
328
+ type = "neither-arrival-nor-departure-given";
329
+ constructor(tripUpdate, stopTimeUpdateEntry) {
330
+ super();
331
+ this.tripUpdate = tripUpdate;
332
+ this.stopTimeUpdateEntry = stopTimeUpdateEntry;
333
+ }
334
+ }
335
+ //# sourceMappingURL=gtfs-trip-update-parser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gtfs-trip-update-parser.js","sourceRoot":"","sources":["../../../src/parser/realtime/gtfs-trip-update-parser.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAMlE,OAAO,EACL,4BAA4B,GAE7B,MAAM,uCAAuC,CAAC;AAG/C,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAG5C,MAAM,2CAA2C,GAAG,WAAW,CAAC;AAChE,MAAM,2CAA2C,GAAG,UAAU,CAAC;AAC/D,MAAM,sDAAsD,GAAG,WAAW,CAAC;AAE3E,MAAM,OAAO,oBAAoB;IAMZ;IAEA;IAPF,eAAe,CAA+B;IAE/D;IACE,yEAAyE;IACzE,0CAA0C;IACzB,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nB,mBAAmB,CAAoB;QACvC,gBAAW,GAAX,WAAW,CAAiB;IAGvC,CAAC;CACF;AAED,MAAM,OAAO,sCAAuC,SAAQ,KAAK;IAGpD;IACA;IACA;IACA;IACA;IANF,IAAI,GAAG,yCAAyC,CAAC;IAC1D,YACW,UAA0B,EAC1B,mBAAuC,EACvC,WAA4B,EAC5B,cAAgC,EAChC,eAAiC;QAE1C,KAAK,EAAE,CAAC;QANC,eAAU,GAAV,UAAU,CAAgB;QAC1B,wBAAmB,GAAnB,mBAAmB,CAAoB;QACvC,gBAAW,GAAX,WAAW,CAAiB;QAC5B,mBAAc,GAAd,cAAc,CAAkB;QAChC,oBAAe,GAAf,eAAe,CAAkB;IAG5C,CAAC;CACF;AAED,MAAM,OAAO,oCAAqC,SAAQ,KAAK;IAGlD;IACA;IAHF,IAAI,GAAG,qCAAqC,CAAC;IACtD,YACW,UAA0B,EAC1B,mBAAuC;QAEhD,KAAK,EAAE,CAAC;QAHC,eAAU,GAAV,UAAU,CAAgB;QAC1B,wBAAmB,GAAnB,mBAAmB,CAAoB;IAGlD,CAAC;CACF"}
@@ -0,0 +1,35 @@
1
+ import type { GtfsScheduleData } from "../../data/gtfs-schedule-data.js";
2
+ import type { GtfsScheduledTrip } from "../../data/gtfs-scheduled-trip.js";
3
+ import type { TripDescriptorJson } from "../../data/raw/realtime-data-json.js";
4
+ export declare class GtfsTripUpdateTripIdentifier {
5
+ private readonly _onError;
6
+ constructor(_onError: (error: GtfsTripUpdateTripIdentificationError) => void);
7
+ identify(tripDescriptor: TripDescriptorJson, scheduleData: GtfsScheduleData): {
8
+ trip: GtfsScheduledTrip;
9
+ serviceDay: Temporal.PlainDate;
10
+ } | null;
11
+ }
12
+ export type GtfsTripUpdateTripIdentificationError = NecessaryFieldNotInTripDescriptorError | TripDescriptorReferencesNonExistentTripIdError | TripDoesNotOccurOnStartDateError | TripDescriptorStartTimeDoesNotMatchTripOriginStopTimeError;
13
+ export declare class NecessaryFieldNotInTripDescriptorError extends Error {
14
+ readonly tripDescriptor: TripDescriptorJson;
15
+ readonly field: "tripId" | "startDate";
16
+ readonly type = "necessary-field-not-in-trip-descriptor";
17
+ constructor(tripDescriptor: TripDescriptorJson, field: "tripId" | "startDate");
18
+ }
19
+ export declare class TripDescriptorReferencesNonExistentTripIdError extends Error {
20
+ readonly tripDescriptor: TripDescriptorJson;
21
+ readonly type = "trip-descriptor-references-non-existent-trip-id";
22
+ constructor(tripDescriptor: TripDescriptorJson);
23
+ }
24
+ export declare class TripDoesNotOccurOnStartDateError extends Error {
25
+ readonly tripDescriptor: TripDescriptorJson;
26
+ readonly trip: GtfsScheduledTrip;
27
+ readonly type = "trip-does-not-occur-on-start-date";
28
+ constructor(tripDescriptor: TripDescriptorJson, trip: GtfsScheduledTrip);
29
+ }
30
+ export declare class TripDescriptorStartTimeDoesNotMatchTripOriginStopTimeError extends Error {
31
+ readonly tripDescriptor: TripDescriptorJson;
32
+ readonly trip: GtfsScheduledTrip;
33
+ readonly type = "trip-descriptor-start-time-does-not-match-trip-origin-stop-time";
34
+ constructor(tripDescriptor: TripDescriptorJson, trip: GtfsScheduledTrip);
35
+ }
@@ -0,0 +1,95 @@
1
+ export class GtfsTripUpdateTripIdentifier {
2
+ _onError;
3
+ constructor(_onError) {
4
+ this._onError = _onError;
5
+ }
6
+ identify(tripDescriptor, scheduleData) {
7
+ // Currently it seems like PTV always gives `tripId` and `startDate` in the
8
+ // trip descriptor, even though the GTFS-RT spec allows other methods of
9
+ // identifying the trip. We'll rely on them being present unless it later
10
+ // turns out we can't.
11
+ if (tripDescriptor.tripId == null) {
12
+ const Err = NecessaryFieldNotInTripDescriptorError;
13
+ this._onError(new Err(tripDescriptor, "tripId"));
14
+ return null;
15
+ }
16
+ if (tripDescriptor.startDate == null) {
17
+ const Err = NecessaryFieldNotInTripDescriptorError;
18
+ this._onError(new Err(tripDescriptor, "startDate"));
19
+ return null;
20
+ }
21
+ const trip = scheduleData.getTrip(tripDescriptor.tripId);
22
+ // TODO: We filter out trips from replacement bus services, so if we ever
23
+ // got a trip update for a replacement bus it would trigger this error, but
24
+ // we should probably ignore that case.
25
+ if (trip == null) {
26
+ const Err = TripDescriptorReferencesNonExistentTripIdError;
27
+ this._onError(new Err(tripDescriptor));
28
+ return null;
29
+ }
30
+ // It's unclear to me whether the startDate in GTFS-RT is meant to be the
31
+ // "service day" of the trip, or just the calendar date of the first stop.
32
+ // I'm assuming it's the service date for now, since startTime can exceed
33
+ // 24:00:00, so they probably work together as a pair to be consistent with
34
+ // the GTFS schedule representation.
35
+ //
36
+ // If this error ever fires, it indicates that that assumption is incorrect!
37
+ // (Or that PTV made a mistake I guess.)
38
+ if (!trip.calendar.occursOn(tripDescriptor.startDate)) {
39
+ this._onError(new TripDoesNotOccurOnStartDateError(tripDescriptor, trip));
40
+ return null;
41
+ }
42
+ // If a startTime is given, check that it matches the trip we've identified.
43
+ // If it doesn't, it might indicate a bug with our matching logic. For now,
44
+ // I've decided only to report it rather than return null, but idk, this
45
+ // might be a strong enough case to say we've matched incorrectly.
46
+ if (tripDescriptor.startTime != null &&
47
+ !tripDescriptor.startTime.equals(trip.origination.departureTime)) {
48
+ const Err = TripDescriptorStartTimeDoesNotMatchTripOriginStopTimeError;
49
+ this._onError(new Err(tripDescriptor, trip));
50
+ }
51
+ return { trip, serviceDay: tripDescriptor.startDate };
52
+ }
53
+ }
54
+ // Naming "necessary" rather that "required" since "required" implies that it
55
+ // breaks the GTFS-RT spec, but in reality it's just that we don't support other
56
+ // methods of identifying the trip yet.
57
+ export class NecessaryFieldNotInTripDescriptorError extends Error {
58
+ tripDescriptor;
59
+ field;
60
+ type = "necessary-field-not-in-trip-descriptor";
61
+ constructor(tripDescriptor, field) {
62
+ super();
63
+ this.tripDescriptor = tripDescriptor;
64
+ this.field = field;
65
+ }
66
+ }
67
+ export class TripDescriptorReferencesNonExistentTripIdError extends Error {
68
+ tripDescriptor;
69
+ type = "trip-descriptor-references-non-existent-trip-id";
70
+ constructor(tripDescriptor) {
71
+ super();
72
+ this.tripDescriptor = tripDescriptor;
73
+ }
74
+ }
75
+ export class TripDoesNotOccurOnStartDateError extends Error {
76
+ tripDescriptor;
77
+ trip;
78
+ type = "trip-does-not-occur-on-start-date";
79
+ constructor(tripDescriptor, trip) {
80
+ super();
81
+ this.tripDescriptor = tripDescriptor;
82
+ this.trip = trip;
83
+ }
84
+ }
85
+ export class TripDescriptorStartTimeDoesNotMatchTripOriginStopTimeError extends Error {
86
+ tripDescriptor;
87
+ trip;
88
+ type = "trip-descriptor-start-time-does-not-match-trip-origin-stop-time";
89
+ constructor(tripDescriptor, trip) {
90
+ super();
91
+ this.tripDescriptor = tripDescriptor;
92
+ this.trip = trip;
93
+ }
94
+ }
95
+ //# sourceMappingURL=gtfs-trip-update-trip-identifier.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gtfs-trip-update-trip-identifier.js","sourceRoot":"","sources":["../../../src/parser/realtime/gtfs-trip-update-trip-identifier.ts"],"names":[],"mappings":"AAIA,MAAM,OAAO,4BAA4B;IAEpB;IADnB,YACmB,QAER;QAFQ,aAAQ,GAAR,QAAQ,CAEhB;IACR,CAAC;IAEJ,QAAQ,CAAC,cAAkC,EAAE,YAA8B;QACzE,2EAA2E;QAC3E,wEAAwE;QACxE,yEAAyE;QACzE,sBAAsB;QACtB,IAAI,cAAc,CAAC,MAAM,IAAI,IAAI,EAAE,CAAC;YAClC,MAAM,GAAG,GAAG,sCAAsC,CAAC;YACnD,IAAI,CAAC,QAAQ,CAAC,IAAI,GAAG,CAAC,cAAc,EAAE,QAAQ,CAAC,CAAC,CAAC;YACjD,OAAO,IAAI,CAAC;QACd,CAAC;QACD,IAAI,cAAc,CAAC,SAAS,IAAI,IAAI,EAAE,CAAC;YACrC,MAAM,GAAG,GAAG,sCAAsC,CAAC;YACnD,IAAI,CAAC,QAAQ,CAAC,IAAI,GAAG,CAAC,cAAc,EAAE,WAAW,CAAC,CAAC,CAAC;YACpD,OAAO,IAAI,CAAC;QACd,CAAC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KAAK,EAAE,CAAC;QAHC,mBAAc,GAAd,cAAc,CAAoB;QAClC,UAAK,GAAL,KAAK,CAAwB;IAGxC,CAAC;CACF;AAED,MAAM,OAAO,8CAA+C,SAAQ,KAAK;IAElD;IADZ,IAAI,GAAG,iDAAiD,CAAC;IAClE,YAAqB,cAAkC;QACrD,KAAK,EAAE,CAAC;QADW,mBAAc,GAAd,cAAc,CAAoB;IAEvD,CAAC;CACF;AAED,MAAM,OAAO,gCAAiC,SAAQ,KAAK;IAG9C;IACA;IAHF,IAAI,GAAG,mCAAmC,CAAC;IACpD,YACW,cAAkC,EAClC,IAAuB;QAEhC,KAAK,EAAE,CAAC;QAHC,mBAAc,GAAd,cAAc,CAAoB;QAClC,SAAI,GAAJ,IAAI,CAAmB;IAGlC,CAAC;CACF;AAED,MAAM,OAAO,0DAA2D,SAAQ,KAAK;IAIxE;IACA;IAJF,IAAI,GACX,iEAAiE,CAAC;IACpE,YACW,cAAkC,EAClC,IAAuB;QAEhC,KAAK,EAAE,CAAC;QAHC,mBAAc,GAAd,cAAc,CAAoB;QAClC,SAAI,GAAJ,IAAI,CAAmB;IAGlC,CAAC;CACF"}
@@ -0,0 +1,3 @@
1
+ export type { GtfsRealtimeDataParsingError } from "./gtfs-realtime-data-parser.js";
2
+ export type { GtfsTripUpdateParsingError, UnsupportedTripUpdateScheduleRelationshipError, NoStopTimeUpdateFieldGivenError, UnsupportedStopTimeUpdateEntryScheduleRelationshipError, NecessaryFieldNotInStopTimeUpdateEntryError, StopTimeUpdateEntryReferencesNonExistentStopSequenceError, MultipleStopTimeUpdateEntriesForSameMovementIndexError, StopTimeUpdateEntryReferencesUnmappedStopIdError, StopTimeUpdateEntryChangesStopError, StopTimeUpdateEntryChangesPlatformError, NeitherTimeNorDelayGivenError, TimeAndDelayDisagreeWithEachOtherError, NeitherArrivalNorDepartureGivenError, } from "./gtfs-trip-update-parser.js";
3
+ export type { GtfsTripUpdateTripIdentificationError, NecessaryFieldNotInTripDescriptorError, TripDescriptorReferencesNonExistentTripIdError, TripDoesNotOccurOnStartDateError, TripDescriptorStartTimeDoesNotMatchTripOriginStopTimeError, } from "./gtfs-trip-update-trip-identifier.js";
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/parser/realtime/index.ts"],"names":[],"mappings":""}
@@ -0,0 +1,28 @@
1
+ import type { CalendarCsv, CalendarCsvRow, CalendarDatesCsv, CalendarDatesCsvRow } from "../../data/raw/schedule-csvs.js";
2
+ import { GtfsCalendar } from "../../data/gtfs-calendar.js";
3
+ export declare class GtfsCalendarParser {
4
+ private readonly _onError;
5
+ constructor(_onError: (error: GtfsCalendarParsingError) => void);
6
+ parse(calendarCsv: CalendarCsv, calendarDatesCsv: CalendarDatesCsv): readonly GtfsCalendar[];
7
+ }
8
+ export type GtfsCalendarParsingError = DuplicateCalendarIdError | UnexpectedCalendarDateExceptionTypeError | InvalidCalendarDateRangeError | MultipleExceptionsForSameDateError;
9
+ export declare class DuplicateCalendarIdError extends Error {
10
+ readonly subsequentRowWithDuplicateId: CalendarCsvRow;
11
+ readonly type = "duplicate-calendar";
12
+ constructor(subsequentRowWithDuplicateId: CalendarCsvRow);
13
+ }
14
+ export declare class InvalidCalendarDateRangeError extends Error {
15
+ readonly row: CalendarCsvRow;
16
+ readonly type = "invalid-calendar-date-range";
17
+ constructor(row: CalendarCsvRow);
18
+ }
19
+ export declare class UnexpectedCalendarDateExceptionTypeError extends Error {
20
+ readonly row: CalendarDatesCsvRow;
21
+ readonly type = "unexpected-calendar-date-exception-type";
22
+ constructor(row: CalendarDatesCsvRow);
23
+ }
24
+ export declare class MultipleExceptionsForSameDateError extends Error {
25
+ readonly subsequentRowForSameDate: CalendarDatesCsvRow;
26
+ readonly type = "multiple-exceptions-for-same-date";
27
+ constructor(subsequentRowForSameDate: CalendarDatesCsvRow);
28
+ }