Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/routes/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ documented.addGetRoute(
.transform((x) => x === undefined ? undefined : parseInt(x))
.pipe(z.optional(z.number())),
}),
resBody: z.any(),
resBody: z.object({ journeys: z.array(journeyService.ProcessedJourneySchema) }),
},
async (_, { originLat, originLon, destLat, destLon, walkingPenalty, range }) => {
try {
Expand Down
45 changes: 43 additions & 2 deletions src/services/bustimeCommon.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import z from "zod";

// ========== patterns & bus lines =========

const PatternPtSchema = z.object({
seq: z.int(),
typ: z.string(),
Expand All @@ -20,9 +22,8 @@ export const PatternSchema = z.object({
}).meta({ id: 'Pattern' });
export type Pattern = z.infer<typeof PatternSchema>

export const PatternsArraySchema = z.array(PatternSchema);

export const LatLonSchema = z.object({ lat: z.number(), lon: z.number() }).meta({ id: 'LatLon' });
export type LatLon = z.infer<typeof LatLonSchema>;

export const BusStopSchema = z.object({
id: z.string(),
Expand Down Expand Up @@ -142,3 +143,43 @@ function normalizeStopName(rawStopName: string): string {
.trim();
}

// ========= predictions ==========

// fields that were not present in practice are commented out
// might've missed a field given it happened with prdctdn (in response fields table but not the xml schema)...
export const PredictionSchema = z.object({
tmstmp: z.string(),
typ: z.string(),
stpid: z.string(),
stpnm: z.string(),
vid: z.string(), // number in schema
dstp: z.number(),
rt: z.string(),
rtdd: z.string(),
rtdir: z.string(),
des: z.string(),
prdtm: z.string(),
dly: z.optional(z.boolean()),
dyn: z.number(),
tablockid: z.string(),
tatripid: z.string(),
origtatripno: z.string(),
prdctdn: z.string(), // not in xml schema
zone: z.string(),
psgld: z.string(),
// gtfsseq: z.string(),
nbus: z.optional(z.string()),
stst: z.optional(z.number()),
stsd: z.optional(z.string()), // number? in schema
// flagStop: z.number(),
}).meta({ id: 'Prediction' });
export type Prediction = z.infer<typeof PredictionSchema>;

export const GetPredictionsResponseSchema = z.object({
'bustime-response': z.object({
'prd': z.optional(z.array(PredictionSchema)),
'error': z.optional(z.unknown()),
})
}).meta({ id: 'GetPredictionsResponse' });
export type GetPredictionsResponse = z.infer<typeof GetPredictionsResponseSchema>;

Loading