@tmlmobilidade/gtfs-validator
v20260114.2306.46
Published
A GTFS Validator
Readme
GTFS Validator TypeScript Wrapper
A TypeScript wrapper for the GTFS Validator binary, providing a clean and type-safe API for validating GTFS feeds.
Features
- ✅ Type-safe API - Full TypeScript support with comprehensive type definitions
- ✅ Cross-platform - Supports Windows, macOS (Intel & Apple Silicon), and Linux (x64 & ARM64)
- ✅ Robust error handling - Detailed error messages with error codes
- ✅ Input validation - Validates inputs before execution
- ✅ Configurable timeouts - Customizable timeout for large feeds
- ✅ Comprehensive documentation - Full JSDoc documentation
Installation
npm install @tmlmobilidade/gtfs-validatorUsage
Basic Usage
import { GTFSValidator } from '@tmlmobilidade/gtfs-validator';
const result = await GTFSValidator('./gtfs-feed.zip', {
lang: 'en',
timeout: 300000, // 5 minutes
});
console.log(`Validation completed in ${result.executionTime}ms`);
console.log(`Found ${result.summary.errorCount} errors`);Advanced Usage
import { GTFSValidator, GTFSValidatorError, getValidatorInfo } from '@tmlmobilidade/gtfs-validator';
try {
// Check if binary is available
const info = await getValidatorInfo();
if (!info.isAvailable) {
console.error(`Binary not found for platform: ${info.platform}`);
return;
}
// Run validation with custom options
const result = await GTFSValidator('./gtfs-feed.zip', {
lang: 'pt',
timeout: 600000, // 10 minutes
out_file: './validation-report.json',
rules_path: './custom-rules.json',
cwd: './working-directory',
env: {
CUSTOM_VAR: 'value',
},
});
// Access results
console.log('Validation Summary:', result.summary);
console.log('Execution Time:', result.executionTime, 'ms');
console.log('Arguments:', result.args);
} catch (err) {
if (err instanceof GTFSValidatorError) {
console.error(`Validation failed: ${err.message}`);
console.error(`Error code: ${err.code}`);
if (err.stderr) {
console.error('Stderr:', err.stderr);
}
} else {
console.error('Unexpected error:', err);
}
}API Reference
GTFSValidator(input, options?)
Runs the GTFS validator on the specified input.
Parameters:
input(string): Path to the GTFS feed (file or directory)options(GTFSValidatorOptions, optional): Validation options
Returns: Promise
Throws: GTFSValidatorError
getValidatorInfo()
Gets information about the available validator binary for the current platform.
Returns: Promise<{ binaryName: string, binaryPath: string, isAvailable: boolean, platform: SupportedPlatform }>
GTFSValidatorError
Error class thrown when validation fails.
Properties:
message(string): Error messagecode(string): Error code (e.g., 'VALIDATION_FAILED', 'TIMEOUT', 'BINARY_NOT_FOUND')originalError(Error?, optional): Original error if availablestdout(string?, optional): Standard output from the validatorstderr(string?, optional): Standard error from the validator
Options
GTFSValidatorOptions
cwd?(string): Working directory for the validation processenv?(Record<string, string>): Additional environment variableslang?('en' | 'pt'): Language for validation messagesout_file?(string): Output file path for detailed validation resultsrules_path?(string): Path to custom validation rules filetimeout?(number): Timeout in milliseconds (default: 30 minutes)
Error Codes
UNSUPPORTED_PLATFORM: Current platform is not supportedBINARY_NOT_FOUND: Validator binary not found or not executableINVALID_INPUT: Input path is invalidINPUT_NOT_ACCESSIBLE: Input path does not exist or is not readableINVALID_OPTIONS: Invalid options providedVALIDATION_FAILED: General validation failureVALIDATOR_ERROR: Validator exited with non-zero codeVALIDATION_TIMEOUT: Validation timed outPARSE_ERROR: Failed to parse validation resultsOUTPUT_TOO_LARGE: Validation output exceeded maximum sizeERROR_OUTPUT_TOO_LARGE: Validation error output exceeded maximum sizeUNEXPECTED_ERROR: Unexpected error occurred
Supported Platforms
darwin-arm64- macOS (Apple Silicon)darwin-x64- macOS (Intel)linux-arm64- Linux (ARM64)linux-x64- Linux (x64)win32-x64- Windows (x64)
License
ISC
