/** In-memory interpretation of the public bounded collection filter contract. */ export function matchesRecordWhere(data: Record, where: unknown): boolean { if (!where || typeof where !== "object") return true; return Object.entries(where).every(([key, condition]) => { const value = data[key]; if (condition === null || typeof condition !== "object") return value === condition; return Object.entries(condition).every(([operator, expected]) => { if (operator === "eq") return value === expected; if (operator === "contains") return ( typeof value === "string" && typeof expected === "string" && value.toLowerCase().includes(expected.toLowerCase()) ); if ( typeof value !== typeof expected || (typeof value !== "string" && typeof value !== "number") ) return false; const comparison = typeof value === "number" ? value - Number(expected) : value.localeCompare(String(expected)); if (operator === "gt") return comparison > 0; if (operator === "gte") return comparison >= 0; if (operator === "lt") return comparison < 0; if (operator === "lte") return comparison <= 0; return false; }); }); }