@five-vm/cli
Version:
High-performance CLI for Five VM development with WebAssembly integration
161 lines • 4.63 kB
TypeScript
/**
* Five File Format Manager
*
* Centralized management for Five file formats (.five, .bin, .v)
* This is the SINGLE SOURCE OF TRUTH for all Five file operations.
*
* Design Principles:
* - Single responsibility for file format detection and loading
* - Consistent error handling across all file operations
* - Extensible for future file formats
* - Rich metadata preservation and validation
* - Performance optimized with caching where appropriate
*/
export interface FiveCompiledFile {
bytecode: string;
abi: {
functions: Record<string, {
index: number;
parameters: any[];
accounts: any[];
}>;
fields: any[];
version: string;
};
version: string;
disassembly?: string[];
metadata?: {
sourceFile?: string;
compilationTime?: number;
optimizationLevel?: string;
compilerVersion?: string;
[key: string]: any;
};
debug?: any;
}
export interface LoadedFiveFile {
bytecode: Uint8Array;
abi?: any;
metadata?: any;
debug?: any;
format: 'five' | 'bin' | 'v';
sourceFile: string;
size: number;
}
export interface FiveFileValidationResult {
valid: boolean;
errors: string[];
warnings: string[];
format: string;
size: number;
}
export interface SaveOptions {
preserveMetadata?: boolean;
indent?: number;
compression?: boolean;
}
export interface LoadOptions {
validateFormat?: boolean;
requireABI?: boolean;
cacheable?: boolean;
}
/**
* Centralized Five File Manager
* All Five file operations MUST go through this class
*/
export declare class FiveFileManager {
private static instance;
private fileCache;
private readonly supportedExtensions;
/**
* Singleton pattern to ensure consistent behavior across the CLI
*/
static getInstance(): FiveFileManager;
/**
* Universal file loader - handles ALL Five file formats
* This is the PRIMARY method that all commands should use
*/
loadFile(filePath: string, options?: LoadOptions): Promise<LoadedFiveFile>;
/**
* Save compiled data to .five format
* This ensures consistent .five file structure across the CLI
*/
saveFiveFile(filePath: string, bytecode: Uint8Array, abi: any, metadata?: any, disassembly?: string[], options?: SaveOptions): Promise<void>;
/**
* Save raw bytecode to .bin format
*/
saveBinFile(filePath: string, bytecode: Uint8Array): Promise<void>;
/**
* Detect file format without loading content
*/
detectFormat(filePath: string): 'five' | 'bin' | 'v' | 'unknown';
/**
* Validate file format and content
*/
validateFileContent(file: LoadedFiveFile): FiveFileValidationResult;
/**
* Get file information without loading full content
*/
getFileInfo(filePath: string): Promise<{
exists: boolean;
size: number;
format: string;
lastModified: Date;
}>;
/**
* Convert between file formats
*/
convertFormat(inputPath: string, outputPath: string, options?: {
preserveMetadata?: boolean;
}): Promise<void>;
/**
* Clear file cache
*/
clearCache(): void;
/**
* Get cache statistics
*/
getCacheStats(): {
size: number;
keys: string[];
};
private loadFiveFile;
private loadBinFile;
private loadSourceFile;
private validateFilePath;
private getCompilerVersion;
private arraysEqual;
}
/**
* Custom error class for Five file operations
*/
export declare class FiveFileError extends Error {
readonly code: string;
readonly details: any;
constructor(message: string, code: string, details?: any);
}
/**
* Convenience functions for common operations
* These provide a simple API while still using the centralized manager
*/
/**
* Quick load function for simple use cases
*/
export declare function loadFiveFile(filePath: string): Promise<LoadedFiveFile>;
/**
* Quick save function for .five files
*/
export declare function saveFiveFile(filePath: string, bytecode: Uint8Array, abi: any, metadata?: any, disassembly?: string[]): Promise<void>;
/**
* Quick bytecode extraction function
*/
export declare function extractBytecode(filePath: string): Promise<Uint8Array>;
/**
* Quick ABI extraction function
*/
export declare function extractABI(filePath: string): Promise<any>;
/**
* Validate any Five file format
*/
export declare function validateFiveFile(filePath: string): Promise<FiveFileValidationResult>;
//# sourceMappingURL=FiveFileManager.d.ts.map