A GTFS Validator
npm install @tmlmobilidade/gtfs-validatorA TypeScript wrapper for the GTFS Validator binary, providing a clean and type-safe API for validating GTFS feeds.
- ✅ 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
``bash`
npm install @tmlmobilidade/gtfs-validator
`typescript
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);Found ${result.summary.errorCount} errors
console.log();`
`typescript
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});Error code: ${err.code}
console.error();`
if (err.stderr) {
console.error('Stderr:', err.stderr);
}
} else {
console.error('Unexpected error:', err);
}
}
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
Gets information about the available validator binary for the current platform.
Returns: Promise<{ binaryName: string, binaryPath: string, isAvailable: boolean, platform: SupportedPlatform }>
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
- cwd? (string): Working directory for the validation processenv?
- (Recordlang?
- ('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)
- 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
- darwin-arm64 - macOS (Apple Silicon)darwin-x64
- - macOS (Intel)linux-arm64
- - Linux (ARM64)linux-x64
- - Linux (x64)win32-x64` - Windows (x64)
-
ISC