/** * SchemaCache — Schema caching layer (G40 content-hash keying added in v1.5.0) * ───────────────────────────────────────────────────────────────────────────── * Caches compiled SchemaModel instances to avoid re-parsing XSD on every * validation call. Supports both synchronous (string) and async (file path) * loading. * * Features * ──────── * • LRU eviction when max size is reached * • TTL-based expiry (optional) * • Manual invalidation * • Content-hash keying (G40): schema is re-parsed when source content changes * • Dependency-graph tracking (G40): parent entry invalidated when any import changes */ import { SchemaLoader } from '../xsd/XsdParser'; import { ValidationOptions } from '../validator/ValidationEngine'; import { SchemaModel } from '../schema/SchemaModel'; import { ValidationResult } from '../validator/ValidationResult'; export interface SchemaCacheOptions { /** * Maximum number of schemas to keep in cache. * When exceeded the least-recently-used entry is evicted. * Default: 100 */ maxSize?: number; /** * Time-to-live in milliseconds. Entries older than this are re-loaded. * Default: Infinity (never expire) */ ttlMs?: number; /** * When true, content-hash keying is used: if the XSD source changes, * the cache entry is invalidated automatically (G40). * Default: true */ trackContentHash?: boolean; /** * P0 fix: Maximum number of versioned entries to keep per logical key. * With content-hash keying, each source change creates a new `key@hash` * entry. In long-running processes (watch mode, servers) this causes * silent unbounded growth. When the limit is exceeded, older hash-versioned * entries for the same logical key are evicted first. * Default: 2 (keep at most 2 hash-versions per logical key) */ maxVersionsPerKey?: number; /** * item 15: When true, use fs.stat (mtime + size) as a fast freshness check * before reading the full file and computing a content hash. * On a cache hit with matching stat, the file read is skipped entirely. * Default: false (safer; set to true in long-running server scenarios). */ statFast?: boolean; } export declare class SchemaCache { private cache; private maxSize; private ttlMs; private trackContentHash; private maxVersionsPerKey; private statFast; constructor(options?: SchemaCacheOptions); /** * Return the cached SchemaModel for `key`, or parse `xsdSource` and cache * it under `key`. * * When `trackContentHash` is enabled (default), the cache is keyed on * `key + "@" + sha256(xsdSource)` so that source changes automatically * produce a new cache entry (G40). * * @param key Cache key — typically the resolved file path. * @param xsdSource The raw XSD source string. * @param loader Optional SchemaLoader for xs:import / xs:include. */ getOrParse(key: string, xsdSource: string, loader?: SchemaLoader): SchemaModel; /** * Return the cached SchemaModel for `filePath`, reading and parsing the file * if it is not cached (or the source has changed). * * A file-system SchemaLoader is automatically created relative to the XSD file. * When `trackContentHash` is enabled (default), content changes are detected * automatically without needing manual invalidation (G40). */ getOrLoad(filePath: string, loader?: SchemaLoader): Promise; /** * Validate an XML file against an XSD file, using the cache for the schema. */ validateFile(xmlPath: string, xsdPath: string, options?: ValidationOptions): Promise; /** * Validate multiple XML files against a single XSD. * The schema is loaded once and reused for all files. */ validateFiles(xmlPaths: string[], xsdPath: string, options?: ValidationOptions): Promise>; /** * Synchronous variant — loads the XSD from disk synchronously. * Prefer the async version in production code. */ getOrLoadSync(filePath: string, loader?: SchemaLoader): SchemaModel; /** * Retrieve a cached schema by key (returns undefined if not found or expired). */ get(key: string): SchemaModel | undefined; /** * Returns true if the cache contains an entry for key. */ has(key: string): boolean; /** * Manually insert a pre-parsed schema under a key. */ set(key: string, schema: SchemaModel): void; /** * Remove a schema from the cache by key. * With content-hash keying enabled, all hash-versioned entries for this key * are removed (i.e. `invalidate('myKey')` removes `myKey@abc123...`). */ invalidate(key: string): boolean; /** * Invalidate all entries whose content hash no longer matches the provided * source string. Useful for watch-mode integrations (G40). * * @param filePath The file path (or cache key) to check. * @param newSource The new source content to hash. * @returns true if any entry was removed. */ invalidateByContent(filePath: string, newSource: string): boolean; /** * Return the content hash currently stored for a cache key, or null if not * present. Useful for verifying freshness without triggering a reload (G40). */ getContentHash(key: string): string | null; /** * Return the dependency map for a cache key (G40). * Keys are import/include paths; values are their content hashes at load time. */ getDependencies(key: string): Map | null; /** * Remove all entries from the cache. */ clear(): void; /** * Returns the number of schemas currently cached. */ get size(): number; /** * Returns all logical keys currently in the cache. * When content-hash keying is enabled, the `@hash` suffix is stripped so * callers always see the original key they passed to `getOrParse`. */ keys(): string[]; private _get; private _setWithMeta; private _makeFsLoader; } /** A shared global SchemaCache instance with default settings (content-hash keying enabled). */ export declare const globalSchemaCache: SchemaCache; //# sourceMappingURL=SchemaCache.d.ts.map