/** * TokenizingCacheGateway - Single gateway for all code stored in distributed cache. * * This wrapper enforces tokenization/detokenization for ANY distributed cache * storing code, eliminating the "forgot to tokenize" bug class. * * All code stored in distributed cache (Redis/API) must go through this gateway. * The gateway automatically: * - Tokenizes code on write (replaces absolute paths with __VF_CACHE_DIR__) * - Detokenizes code on read (replaces tokens with local paths) * - Validates portable code before storage * * @module cache/tokenizing-gateway */ import type { CacheBackend } from "./types.js"; /** * Gateway interface for code storage in distributed cache. * Extends CacheBackend with code-specific methods that enforce tokenization. */ export interface CodeCacheGateway { /** Backend type identifier */ readonly type: CacheBackend["type"]; /** Gateway name for logging */ readonly name: string; /** * Get code from cache with automatic detokenization. * ALWAYS returns local paths (detokenized). */ getCode(key: string): Promise; /** * Get multiple codes from cache with automatic detokenization. * ALWAYS returns local paths (detokenized). */ getCodeBatch?(keys: string[]): Promise>; /** * Store code in cache with automatic tokenization. * ALWAYS tokenizes before storage. * @throws VeryfrontError (cache-invariant-violation) if code contains paths that can't be tokenized */ setCode(key: string, code: string, ttlSeconds?: number): Promise; /** * Store multiple codes in cache with automatic tokenization. * ALWAYS tokenizes before storage. */ setCodeBatch?(entries: Array<{ key: string; code: string; ttl?: number; }>): Promise; /** * Delete code from cache. */ delCode(key: string): Promise; /** * Delete codes matching pattern from cache. */ delCodeByPattern?(pattern: string): Promise; /** * Get raw data from cache (no tokenization). * Use for metadata, manifests, etc. */ get(key: string): Promise; /** * Store raw data in cache (no tokenization). * Use for metadata, manifests, etc. */ set(key: string, value: string, ttlSeconds?: number): Promise; /** * Delete raw data from cache. */ del(key: string): Promise; /** * Check if the underlying backend is distributed (Redis/API) vs memory. */ isDistributed(): boolean; } /** * TokenizingCacheGateway wraps a CacheBackend and enforces tokenization * for all code storage operations. * * This is the ONLY authorized way to store transformed code in distributed cache. */ export declare class TokenizingCacheGateway implements CodeCacheGateway { private backend; readonly type: CacheBackend["type"]; readonly name: string; constructor(backend: CacheBackend, name: string); /** * Check if the underlying backend is distributed (Redis/API) vs memory. */ isDistributed(): boolean; /** * Get code from cache with automatic detokenization. * For memory backend, no detokenization is needed. */ getCode(key: string): Promise; /** * Get multiple codes from cache with automatic detokenization. */ getCodeBatch(keys: string[]): Promise>; /** * Store code in cache with automatic tokenization. * Validates that code is portable before storage. * @throws VeryfrontError (cache-invariant-violation) if code contains paths that can't be properly tokenized */ setCode(key: string, code: string, ttlSeconds?: number): Promise; /** * Store multiple codes in cache with automatic tokenization. */ setCodeBatch(entries: Array<{ key: string; code: string; ttl?: number; }>): Promise; /** * Delete code from cache. */ delCode(key: string): Promise; /** * Delete codes matching pattern from cache. */ delCodeByPattern(pattern: string): Promise; /** * Get raw data from cache (no tokenization). */ get(key: string): Promise; /** * Store raw data in cache (no tokenization). */ set(key: string, value: string, ttlSeconds?: number): Promise; /** * Delete raw data from cache. */ del(key: string): Promise; } /** * Create a TokenizingCacheGateway wrapping a CacheBackend. * * @param backend - The underlying cache backend * @param name - Name for logging (e.g., "TRANSFORM-CACHE", "SSR-MODULE") * @returns A gateway that enforces tokenization for code storage */ export declare function createTokenizingGateway(backend: CacheBackend, name: string): TokenizingCacheGateway; //# sourceMappingURL=tokenizing-gateway.d.ts.map