voyage-and-consumption-mcp-server
Version:
Voyage and consumption management server handling vessel voyages, fuel consumption, performance monitoring, and operational data with ERP access for data extraction
99 lines (98 loc) • 3.89 kB
TypeScript
/**
* IMO Validation Utility
*
* Centralizes IMO number validation and parsing logic that was duplicated
* across 13 different tool methods in the codebase.
*
* This utility extracts the common patterns:
* - IMO parameter validation (null/undefined/empty string checks)
* - IMO number parsing with regex validation
* - Standardized error handling for invalid IMO formats
*/
export declare class MissingParameterError extends Error {
param: string;
tool_name: string;
constructor(param: string, tool_name: string);
}
export declare class InvalidImoError extends Error {
imo: string;
constructor(imo: string);
}
/**
* Validates that an IMO parameter is present and not empty
* @param imo - The IMO parameter to validate
* @param toolName - The name of the tool calling this validation
* @throws MissingParameterError if IMO is missing or empty
*/
export declare function validateImoParameter(imo: any, toolName: string): void;
/**
* Validates that an IMO parameter is present (basic check)
* @param imo - The IMO parameter to validate
* @param toolName - The name of the tool calling this validation
* @throws MissingParameterError if IMO is missing
*/
export declare function validateImoParameterBasic(imo: any, toolName: string): void;
/**
* Parses IMO for API methods - returns number if valid numeric string, otherwise original value
* @param imo - The IMO value to parse
* @returns Parsed IMO number or original value
*/
export declare function parseImoForApi(imo: any): number | any;
/**
* Parses IMO for database methods - always returns a number
* @param imo - The IMO value to parse
* @returns Parsed IMO number
*/
export declare function parseImoForDatabase(imo: any): number;
/**
* Validates and parses IMO for API methods
* @param imo - The IMO parameter to validate and parse
* @param toolName - The name of the tool calling this function
* @returns Parsed IMO number or original value
* @throws MissingParameterError if IMO is missing or empty
*/
export declare function validateAndParseImoForApi(imo: any, toolName: string): number | any;
/**
* Validates and parses IMO for database methods
* @param imo - The IMO parameter to validate and parse
* @param toolName - The name of the tool calling this function
* @returns Parsed IMO number
* @throws MissingParameterError if IMO is missing or empty
*/
export declare function validateAndParseImoForDatabase(imo: any, toolName: string): number;
/**
* Validates and parses IMO for position methods (basic validation)
* @param imo - The IMO parameter to validate
* @param toolName - The name of the tool calling this function
* @returns Original IMO value
* @throws MissingParameterError if IMO is missing
*/
export declare function validateAndParseImoForPosition(imo: any, toolName: string): any;
/**
* Validates IMO format using regex (digits only)
* @param imo - The IMO string to validate
* @returns true if IMO contains only digits
*/
export declare function isValidImoFormat(imo: string): boolean;
/**
* Validates IMO checksum according to IMO standard (DISABLED for demo data compatibility)
* @param _imo - The IMO string to validate (unused)
* @returns true (checksum validation disabled)
*/
export declare function validateImoChecksum(_imo: string): boolean;
/**
* Comprehensive IMO validation with checksum
* @param imo - The IMO value to validate
* @param requireChecksum - Whether to validate IMO checksum (default: false)
* @returns true if IMO is valid
*/
export declare function validateImoFormat(imo: any, requireChecksum?: boolean): boolean;
/**
* Validates an IMO number and returns validation result with error message
* @param imo - The IMO number to validate
* @returns Object with isValid boolean and error message if invalid
*/
export declare function validateIMO(imo: any): {
isValid: boolean;
error?: string;
};