@sailboat-computer/data-storage
Version:
Shared data storage library for sailboat computer v3
149 lines (148 loc) • 4.19 kB
TypeScript
/**
* Storage Configuration Manager
*
* This implementation uses the @sailboat-computer/config-client package to interact
* with the Configuration Service, with fallback to local files when the service is unavailable.
*/
import { EventBus } from '../event-bus';
import { StorageConfig, UnifiedStorageManagerOptions } from '../types';
import { IStorageConfigManager } from './IStorageConfigManager';
/**
* Default storage configuration
*/
export declare const DEFAULT_STORAGE_CONFIG: StorageConfig;
/**
* Default unified storage manager options
*/
export declare const DEFAULT_UNIFIED_STORAGE_MANAGER_OPTIONS: UnifiedStorageManagerOptions;
/**
* Storage configuration manager options
*/
export interface StorageConfigManagerOptions {
/**
* Configuration service URL
* If not provided, will use CONFIG_SERVICE_URL environment variable or default to http://localhost:3000
*/
serviceUrl?: string;
/**
* Local configuration directory
* If not provided, will use './config'
*/
localDir?: string;
/**
* Environment to use
* If not provided, will use 'production'
*/
environment?: string;
/**
* Service name
* If not provided, will use 'data-manager'
*/
serviceName?: string;
/**
* Configuration ID
* If not provided, will use 'config'
*/
configId?: string;
/**
* Custom logger
*/
logger?: {
info: (message: string, meta?: any) => void;
warn: (message: string, meta?: any) => void;
error: (message: string, meta?: any) => void;
debug: (message: string, meta?: any) => void;
};
}
/**
* Storage configuration manager
*/
export declare class StorageConfigManager implements IStorageConfigManager {
private storageConfig;
private unifiedStorageManagerOptions;
private configClient;
private eventBus?;
private stopWatching?;
private localDir;
private serviceName;
private configId;
private environment;
/**
* Create a new storage configuration manager
* @param options Configuration options
*/
constructor(options?: StorageConfigManagerOptions);
/**
* Initialize the configuration manager
*/
initialize(): Promise<void>;
/**
* Extract storage config and unified storage manager options from full config
* @param config Full configuration
*/
private extractConfig;
/**
* Create full configuration from storage config and unified storage manager options
* @returns Full configuration
*/
private createFullConfig;
/**
* Cache configuration locally
* @param config Configuration to cache
*/
private cacheConfigLocally;
/**
* Start watching for configuration changes
*/
private startWatching;
/**
* Handle configuration change event
* @param event Configuration change event
*/
private handleConfigChange;
/**
* Set the event bus
* @param eventBus Event bus
*/
setEventBus(eventBus: EventBus): void;
/**
* Reload configuration
*/
reload(): Promise<void>;
/**
* Reset configuration to default
*/
resetToDefault(): Promise<void>;
/**
* Apply configuration changes
*/
applyChanges(): Promise<void>;
/**
* Publish configuration change event
*/
publishConfigChanged(): Promise<void>;
/**
* Get the storage configuration
*/
getStorageConfig(): StorageConfig;
/**
* Get the unified storage manager options
*/
getUnifiedStorageManagerOptions(): UnifiedStorageManagerOptions;
/**
* Save configuration
* @param config Configuration to save
* @param description Optional description
*/
saveConfig(config: StorageConfig, description?: string): Promise<void>;
/**
* Shutdown the configuration manager
*/
shutdown(): void;
}
/**
* Create a new storage configuration manager
* @param options Configuration options
* @returns Storage configuration manager
*/
export declare function createStorageConfigManager(options?: StorageConfigManagerOptions): StorageConfigManager;