UNPKG

@siva-sub/mcp-public-transport

Version:

A Model Context Protocol server for Singapore transport data with real-time information and routing

31 lines (30 loc) 1.25 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.LocationSchema = exports.CoordinateSchema = exports.BusStopCodeSchema = void 0; exports.validateInput = validateInput; const zod_1 = require("zod"); const errors_js_1 = require("./errors.js"); exports.BusStopCodeSchema = zod_1.z.string() .regex(/^\d{5}$/, 'Bus stop code must be 5 digits') .describe('5-digit bus stop code'); exports.CoordinateSchema = zod_1.z.object({ lat: zod_1.z.number().min(-90).max(90), lng: zod_1.z.number().min(-180).max(180), }); exports.LocationSchema = zod_1.z.object({ location: zod_1.z.string().optional(), lat: zod_1.z.number().optional(), lng: zod_1.z.number().optional(), }).refine((data) => data.location || (data.lat !== undefined && data.lng !== undefined), 'Either location name or coordinates (lat, lng) must be provided'); function validateInput(schema, data) { try { return schema.parse(data); } catch (error) { if (error instanceof zod_1.z.ZodError) { const issues = error.errors.map(e => `${e.path.join('.')}: ${e.message}`).join(', '); throw new errors_js_1.ValidationError(`Validation failed: ${issues}`); } throw error; } }