UNPKG

bc-webclient-mcp

Version:

Model Context Protocol (MCP) server for Microsoft Dynamics 365 Business Central via WebUI protocol. Enables AI assistants to interact with BC through the web client protocol, supporting Card, List, and Document pages with full line item support and server

139 lines 5.22 kB
/** * Filter Metadata Service * * Provides caching for filter-related metadata to optimize repeated filter operations. * * Architecture (validated by GPT-5.1 high reasoning review): * - Wraps existing CacheManager for consistency * - Uses namespaced keys for different cache types * - Integrates with ConnectionManager for session lifecycle management * * Phase 1: Filter State Cache (HIGHEST VALUE) * - Tracks currently applied filters per session+page * - Prevents redundant Filter + SaveValue WebSocket calls * - Biggest performance win: avoids round-trip latency * * Phase 2: Repeater Path Cache (MEDIUM VALUE) * - Caches repeater control paths to avoid tree walks * - Reduces CPU cost of LogicalForm traversal * * Phase 3: Field Metadata Cache (LOWER VALUE) * - Caches filterable field metadata for pre-validation * - Enables helpful error messages for invalid filter requests */ import type { FieldMetadata } from '../types/bc-types.js'; /** * Filter specification with operator and value. */ export interface FilterSpec { operator: string; value: unknown; } /** * Service for caching filter metadata and state. * Singleton pattern for global cache coordination. */ export declare class FilterMetadataService { private static instance; private cache; private constructor(); /** * Gets the singleton instance. */ static getInstance(): FilterMetadataService; /** * Gets cached filter state for a session+page combination. * * @param sessionId - BC session ID * @param pageId - BC page ID (e.g., "21", "22") * @returns Map of currently applied filters, or empty Map if none cached */ getFilterState(sessionId: string, pageId: string): Map<string, FilterSpec>; /** * Sets filter state for a session+page combination. * * @param sessionId - BC session ID * @param pageId - BC page ID * @param state - Map of applied filters */ setFilterState(sessionId: string, pageId: string, state: Map<string, FilterSpec>): void; /** * Clears all filter state for a given session. * Called when session is closed to prevent stale cache entries. * * @param sessionId - BC session ID */ clearFilterStateForSession(sessionId: string): void; /** * Clears filter state for a specific session+page combination. * Useful when page is refreshed or filters are explicitly reset. * * @param sessionId - BC session ID * @param pageId - BC page ID */ clearFilterStateForPage(sessionId: string, pageId: string): void; /** * Builds cache key for filter state. * Format: filterstate:{sessionId}:{pageId} */ private buildFilterStateKey; /** * Gets or computes the repeater control path for a page. * Caches the result to avoid re-walking the LogicalForm tree on every filter operation. * * Uses CacheManager.getOrCompute() for stampede protection (concurrent requests * for the same pageId will coalesce to a single computation). * * @param pageId - BC page ID * @param logicalForm - LogicalForm structure to walk if not cached * @param findRepeaterFn - Function to find repeater path in LogicalForm * @returns Repeater control path (e.g., "server:c[1]") or null if not found */ getOrComputeRepeaterPath(pageId: string, logicalForm: unknown, findRepeaterFn: (form: unknown) => string | null): Promise<string | null>; /** * Invalidates cached repeater path for a page. * Call when page structure changes (rare - usually only after BC schema updates). * * @param pageId - BC page ID */ clearRepeaterPath(pageId: string): void; /** * Builds cache key for repeater path. * Format: repeater:{pageId} */ private buildRepeaterPathKey; /** * Gets or computes field metadata for a page. * Caches the result to enable pre-validation of filter requests. * * Uses CacheManager.getOrCompute() for stampede protection (concurrent requests * for the same pageId will coalesce to a single computation). * * @param pageId - BC page ID * @param logicalForm - LogicalForm structure to extract fields from if not cached * @param extractFieldsFn - Function to extract field metadata from LogicalForm * @returns Map of field name to FieldMetadata */ getOrComputeFieldMetadata(pageId: string, logicalForm: unknown, extractFieldsFn: (form: unknown) => Map<string, FieldMetadata>): Promise<Map<string, FieldMetadata>>; /** * Invalidates cached field metadata for a page. * Call when page structure changes (rare - usually only after BC schema updates). * * @param pageId - BC page ID */ clearFieldMetadata(pageId: string): void; /** * Builds cache key for field metadata. * Format: fieldmeta:{pageId} */ private buildFieldMetadataKey; /** * Gets cache statistics for monitoring. */ getStats(): import("./cache-manager.js").CacheStats; /** * Clears all cached data (for testing/debugging). */ clearAll(): void; } //# sourceMappingURL=filter-metadata-service.d.ts.map