semantic-ds-toolkit
Version:
Performance-first semantic layer for modern data stacks - Stable Column Anchors & intelligent inference
74 lines • 2.21 kB
TypeScript
export declare enum OfflineMode {
STRICT_OFFLINE = "STRICT_OFFLINE",
CACHE_FIRST = "CACHE_FIRST",
NETWORK_FIRST = "NETWORK_FIRST",
FORCE_NETWORK = "FORCE_NETWORK"
}
export type ExchangeRateSource = 'cache' | 'ecb' | 'fed' | 'fallback';
export interface ExchangeRateResult {
rate: number;
timestamp: Date;
source: ExchangeRateSource;
fromCurrency: string;
toCurrency: string;
confidence: number;
ageMs: number;
stale: boolean;
}
export interface RedisLikeClient {
get(key: string): Promise<string | null>;
set?(key: string, value: string): Promise<any>;
setEx?(key: string, ttl: number, value: string): Promise<any>;
expire?(key: string, ttl: number): Promise<any>;
}
export interface FXCacheConfig {
ttlMs: number;
enableRedis?: boolean;
redisClient?: RedisLikeClient;
fallbackRates?: Record<string, number>;
dataSources?: Array<'ecb' | 'fed'>;
defaultMode?: OfflineMode;
timeoutMs?: number;
ecbEndpoint?: string;
fedEndpoint?: string;
}
export declare class FXCache {
private memoryCache;
private config;
private lastFetchTime;
private redisClient?;
private defaultMode;
private timeoutMs;
constructor(ttlMs?: number, config?: Partial<FXCacheConfig>);
private getCacheKey;
private isExpired;
private getCachedEntry;
private storeCacheEntries;
private toExchangeRateResult;
private fetchAndStore;
private fetchFromECB;
private fetchFromFed;
private getFallbackRate;
private fetchExchangeRate;
private fetchWithTimeout;
getExchangeRate(fromCurrency: string, toCurrency: string, options?: {
mode?: OfflineMode;
timeoutMs?: number;
}): Promise<ExchangeRateResult>;
preloadRates(currencyPairs: Array<{
from: string;
to: string;
}>, options?: {
mode?: OfflineMode;
}): Promise<void>;
getCacheStats(): {
size: number;
hitRate: number;
oldestEntry: Date | null;
newestEntry: Date | null;
};
clearCache(): void;
getSupportedCurrencies(): string[];
warmupCache(baseCurrency?: string): Promise<void>;
}
//# sourceMappingURL=fx-cache.d.ts.map