UNPKG

@signaldb/core

Version:

SignalDB is a client-side database that provides a simple MongoDB-like interface to the data with first-class typescript support to achieve an optimistic UI. Data persistence can be achieved by using storage providers that store the data through a JSON in

46 lines (45 loc) 1.15 kB
//#region src/utils/isFieldExpression.ts var expressionKeys = new Set([ "$eq", "$gt", "$gte", "$lt", "$lte", "$in", "$nin", "$ne", "$exists", "$not", "$expr", "$jsonSchema", "$mod", "$regex", "$options", "$text", "$where", "$all", "$elemMatch", "$size", "$bitsAllClear", "$bitsAllSet", "$bitsAnyClear", "$bitsAnySet" ]); /** * Determines whether a given object is a valid field expression. * A field expression is an object containing query operators supported by MongoDB-style queries. * @template T - The type of the field expression. * @param expression - The object to test. * @returns A boolean indicating whether the object is a valid field expression. * - `true` if the object contains only recognized query operators. * - `false` otherwise. */ function isFieldExpression(expression) { if (typeof expression !== "object" || expression == null) return false; const keys = Object.keys(expression); if (keys.length === 0) return false; if (keys.some((key) => !expressionKeys.has(key))) return false; return keys.every((key) => expressionKeys.has(key)); } //#endregion export { isFieldExpression as default };