@tmlmobilidade/types
Version:
This package provides shared Zod validation schemas and their corresponding TypeScript types for use across projects. All types are automatically inferred from the schemas to ensure full type safety and reduce maintenance overhead.
116 lines (115 loc) • 4.81 kB
TypeScript
import { type GTFS_Binary, type GTFS_PickupDropoffType } from './common.js';
/**
* Represents the type of vehicle or service provided by a GTFS Route.
* This type is used to categorize the route based on the mode of transportation it represents.
* Each route type corresponds to a specific mode of transit, such as bus, subway, ferry, etc.
* The values are defined according to the GTFS specification.
*/
export type GTFS_RouteType = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 11 | 12;
/**
* Validates and transforms a value into a GTFS Route Type.
* It accepts numeric or string representations of route types.
* @param value The value to validate and transform.
* @returns A GTFS Route Type value (0-12).
* @throws Error if the value is not a valid GTFS Route type representation.
*/
export declare function validateGtfsRouteType(value: number | string): GTFS_RouteType;
/**
* Represents a route in the GTFS (General Transit Feed Specification) format.
* A route is a group of trips that operate on a specific path or service,
* typically identified by a unique route ID. Each route can have various attributes
* such as agency ID, route color, long name, short name, and type of service.
*/
export interface GTFS_Route {
agency_id: string;
continuous_drop_off?: GTFS_PickupDropoffType;
continuous_pickup?: GTFS_PickupDropoffType;
route_color: string;
route_desc?: string;
route_id: string;
route_long_name: string;
route_short_name: string;
route_sort_order?: number;
route_text_color: string;
route_type: GTFS_RouteType;
route_url?: string;
}
/**
* Represents a raw route in the GTFS format.
* This interface is used to parse raw data from GTFS files, where fields may be optional
* or represented as strings. It is typically used for data ingestion before validation
* and transformation into the `GTFS_Route` format.
*/
export interface GTFS_Route_Raw {
agency_id?: string;
continuous_drop_off?: string;
continuous_pickup?: string;
route_color?: string;
route_desc?: string;
route_id?: string;
route_long_name?: string;
route_short_name?: string;
route_sort_order?: string;
route_text_color?: string;
route_type?: string;
route_url?: string;
}
/**
* Validates and transforms raw GTFS trip data into a structured GTFS_Route object.
* This function checks the types of fields, converts boolean strings to boolean values,
* and ensures that required fields are present.
* @param rawData The raw trip data to validate and transform.
* @returns A validated GTFS_Route object.
*/
export declare function validateGtfsRoute(rawData: GTFS_Route_Raw): GTFS_Route;
/**
* Represents the type of path for a GTFS route.
* This type is used to indicate whether the path is a base path, a partial path,
* or a variant path. It is used in the GTFS-TML (Transporte Metropolitano de Lisboa) standard
* to differentiate between different types of paths for a route.
*/
export type GTFS_PathType = 1 | 2 | 3;
/**
* Validates and transforms a value into a GTFS Path Type.
* It accepts numeric or string representations of path types.
* @param value The value to validate and transform.
* @returns A GTFS Path Type value (1, 2, or 3).
* @throws Error if the value is not a valid GTFS Path Type representation.
*/
export declare function validateGTFSPathType(value?: number | string): GTFS_PathType;
/**
* Extended version of the GTFS_Route interface that
* should be used for working with the GTFS-TML standard.
*/
export interface GTFS_Route_Extended extends GTFS_Route {
circular?: GTFS_Binary;
line_id: number;
line_long_name: string;
line_short_name: string;
path_type?: GTFS_PathType;
route_remarks?: string;
school?: GTFS_Binary;
}
/**
* Represents a raw trip in the GTFS-TML format.
* This interface is used to parse raw data from GTFS-TML files, where fields may be optional
* or represented as strings. It is typically used for data ingestion before validation
* and transformation into the `GTFS_Route_Extended` format.
*/
export interface GTFS_Route_Extended_Raw extends GTFS_Route_Raw {
circular?: string;
line_id?: string;
line_long_name?: string;
line_short_name?: string;
path_type?: string;
route_remarks?: string;
school?: string;
}
/**
* Validates and transforms raw GTFS-TML route data into a structured GTFS_Route_Extended object.
* This function checks the types of fields, converts boolean strings to boolean values,
* and ensures that required fields are present, including the pattern_id.
* @param rawData he raw route data to validate and transform.
* @returns A validated GTFS_Route_Extended object.
*/
export declare function validateGtfsRouteExtended(rawData: GTFS_Route_Extended_Raw): GTFS_Route_Extended;