Skip to content

Commit cf16483

Browse files
committed
add table-to-schema map and primary key map
1 parent dbc892d commit cf16483

File tree

1 file changed

+117
-0
lines changed

1 file changed

+117
-0
lines changed

src/static.def.ts

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,3 +445,120 @@ export interface BookingRule {
445445
info_url?: string;
446446
booking_url?: string;
447447
}
448+
449+
/** map between the file name and schema for each table */
450+
export interface GtfsFiles {
451+
"agency.txt": Agency;
452+
"calendar.txt": Calendar;
453+
"calendar_dates.txt": CalendarDates;
454+
"fare_rules.txt": FareRules;
455+
"fare_attributes.txt": FareAttributes;
456+
"feed_info.txt": FeedInfo;
457+
"frequencies.txt": Frequencies;
458+
"pathways.txt": Pathways;
459+
"routes.txt": Route;
460+
"shapes.txt": Shapes;
461+
"stops.txt": Stop;
462+
"stop_times.txt": StopTime;
463+
"transfers.txt": Transfers;
464+
"trips.txt": Trip;
465+
"timeframes.txt": Timeframe;
466+
"rider_categories.txt": RiderCategory;
467+
"fare_media.txt": FareMedia;
468+
"fare_products.txt": FareProduct;
469+
"fare_leg_rules.txt": FareLegRule;
470+
"fare_leg_join_rules.txt": FareLegJoinRule;
471+
"fare_transfer_rules.txt": FareTransferRule;
472+
"areas.txt": Area;
473+
"stop_areas.txt": StopArea;
474+
"networks.txt": Network;
475+
"route_networks.txt": RouteNetwork;
476+
"levels.txt": Levels;
477+
"location_groups.txt": LocationGroup;
478+
"location_group_stops.txt": LocationGroupStop;
479+
"booking_rules.txt": BookingRule;
480+
"translations.txt": Translations;
481+
"attributions.txt": Attributions;
482+
}
483+
484+
/** same as {@link Table}, except with a `.txt` suffix */
485+
export type GtfsFile = keyof GtfsFiles;
486+
487+
/** same as {@link GtfsFile}, except without the `.txt` suffix */
488+
export type Table = keyof GtfsFiles extends `${infer T}.txt` ? T : never;
489+
490+
/**
491+
* - if it's a `string`, then the table has 1 primary key
492+
* - if it's a `string[]`, then the primary key spans multiple columns
493+
* - if it's `undefined`, then the table has no primary keys
494+
*/
495+
export const PRIMARY_KEYS = {
496+
"agency.txt": "agency_id",
497+
"calendar.txt": "service_id",
498+
"calendar_dates.txt": ["service_id", "date"],
499+
"fare_attributes.txt": "fare_id",
500+
"fare_rules.txt": undefined,
501+
"feed_info.txt": undefined,
502+
"frequencies.txt": ["trip_id", "start_time"],
503+
"routes.txt": "route_id",
504+
"shapes.txt": ["shape_id", "shape_pt_sequence"],
505+
"stops.txt": "stop_id",
506+
"stop_times.txt": ["trip_id", "stop_sequence"],
507+
"transfers.txt": [
508+
"from_stop_id",
509+
"to_stop_id",
510+
"from_trip_id",
511+
"to_trip_id",
512+
"from_route_id",
513+
"to_route_id",
514+
],
515+
"trips.txt": "trip_id",
516+
"pathways.txt": "pathway_id",
517+
"timeframes.txt": undefined,
518+
"rider_categories.txt": "rider_category_id",
519+
"fare_media.txt": "fare_media_id",
520+
"fare_products.txt": "fare_product_id",
521+
"fare_leg_rules.txt": [
522+
"network_id",
523+
"from_area_id",
524+
"to_area_id",
525+
"from_timeframe_group_id",
526+
"to_timeframe_group_id",
527+
"fare_product_id",
528+
],
529+
"fare_leg_join_rules.txt": [
530+
"from_network_id",
531+
"to_network_id",
532+
"from_stop_id",
533+
"to_stop_id",
534+
],
535+
"fare_transfer_rules.txt": [
536+
"from_leg_group_id",
537+
"to_leg_group_id",
538+
"fare_product_id",
539+
"transfer_count",
540+
"duration_limit",
541+
],
542+
"areas.txt": "area_id",
543+
"stop_areas.txt": ["area_id", "stop_id"],
544+
"networks.txt": "network_id",
545+
"route_networks.txt": "route_id",
546+
"levels.txt": "level_id",
547+
"location_groups.txt": "location_group_id",
548+
"location_group_stops.txt": ["location_group_id", "stop_id"],
549+
"booking_rules.txt": "booking_rule_id",
550+
"translations.txt": [
551+
"table_name",
552+
"field_name",
553+
"language",
554+
"record_id",
555+
"record_sub_id",
556+
"field_value",
557+
],
558+
"attributions.txt": "attribution_id",
559+
} satisfies {
560+
[T in keyof GtfsFiles]:
561+
| keyof GtfsFiles[T]
562+
| (keyof GtfsFiles[T])[]
563+
| undefined;
564+
};

0 commit comments

Comments
 (0)