/** * PolicyEngine — First-Match-Wins Policy Resolution * * Single responsibility: resolve a tool name to its applicable policy. * Delegates glob matching to GlobMatcher and validation to PolicyValidator. * * Stateless after construction. Resolution results are cached in a Map * for O(1) repeat lookups — the glob iteration only happens once per * unique tool name. * * Cache is bounded to {@link MAX_CACHE_SIZE} entries to prevent unbounded * memory growth from dynamic tool names. * * @example * ```typescript * const engine = new PolicyEngine( * [{ match: 'sprints.*', cacheControl: 'no-store' }], * { cacheControl: 'no-store' }, * ); * * engine.resolve('sprints.get'); // { cacheControl: 'no-store' } * engine.resolve('sprints.get'); // O(1) — cached * engine.resolve('unknown.tool'); // { cacheControl: 'no-store' } — default * ``` * * @module */ import type { SyncPolicy, ResolvedPolicy, CacheDirective } from './types.js'; export declare class PolicyEngine { private readonly _policies; private readonly _defaultCacheControl; /** * Resolution cache: avoids repeated glob iteration for the same tool name. * Key = tool name, Value = resolved policy or null (no match, no default). */ private readonly _cache; /** * Pre-computed resolved policies, one per policy entry. * Built once at construction time so multiple tool names matching * the same policy share the same frozen object reference. */ private readonly _resolvedByIndex; /** * Pre-frozen default-only resolution. Created once at construction * if defaults are configured, reused for every unmatched tool name. */ private readonly _defaultResolved; /** * Construct a PolicyEngine with eager validation. * * @param policies - Policy rules, evaluated in declaration order * @param defaults - Fallback applied when no policy matches * @throws {Error} If any policy or default is invalid */ constructor(policies: readonly SyncPolicy[], defaults?: { readonly cacheControl?: CacheDirective; }); /** * Resolve the applicable policy for a tool name. * * First matching policy wins. Falls back to defaults if no match. * Returns `null` if no policy matches and no defaults are configured. * * Results are cached — repeated calls for the same tool name are O(1). */ resolve(toolName: string): ResolvedPolicy | null; private _resolveUncached; /** * Build a frozen ResolvedPolicy from a SyncPolicy. * Merges policy cacheControl with the default as fallback. * Called once per policy at construction time. */ private _buildResolved; } //# sourceMappingURL=PolicyEngine.d.ts.map