UNPKG

@point-hub/papi

Version:

Point API Framework

65 lines 2.74 kB
/** * Adds a case-insensitive regex filter to the filters array if a value is provided. * * @param filters - An array of MongoDB filter objects to be modified. * @param field - The field name to apply the regex on. * @param value - The string value to search for (optional). If empty or only whitespace, no filter is added. */ export declare const addRegexFilter: (filters: Record<string, unknown>[], field: string, value?: string) => void; /** * Adds an exact-match filter to the filters array if a value is provided. * * @param filters - An array of MongoDB filter objects to be modified. * @param field - The field name to match exactly. * @param value - The exact value to match (optional). If empty or only whitespace, no filter is added. */ export declare const addExactFilter: (filters: Record<string, unknown>[], field: string, value?: string) => void; /** * Adds a numeric filter to the filters array based on comparison operators or a single value. * * Accepts expressions like `">10<20"`, `"<=15"`, `"=5"` or `"50"` (interpreted as equality). * * @param filters - An array of MongoDB filter objects to be modified. * @param field - The field name to apply the numeric comparison on. * @param value - A string representing the numeric comparison(s). */ export declare const addNumberFilter: (filters: Record<string, unknown>[], field: string, value?: string) => void; /** * Parses a string expression into MongoDB-style numeric comparison operators. * * Supported formats: * - `"50"` → `{ eq: 50 }` * - `">10"` → `{ gt: 10 }` * - `"<=15"` → `{ lte: 15 }` * - `">=5<20"` → `{ gte: 5, lt: 20 }` * * Constraints: * - Only one lower-bound (`>` or `>=`) and one upper-bound (`<` or `<=`) operator are allowed. * - Throws an API error for malformed or ambiguous expressions. * * @param expr - A string representing numeric comparisons. * @returns An object with numeric comparison constraints. * * @throws Will throw an API error if the input format is invalid or has duplicate bounds. */ export declare const parseComparisons: (expr: string) => { gt?: number; gte?: number; lt?: number; lte?: number; eq?: number; }; declare const _default: { parseComparisons: (expr: string) => { gt?: number; gte?: number; lt?: number; lte?: number; eq?: number; }; addNumberFilter: (filters: Record<string, unknown>[], field: string, value?: string) => void; addRegexFilter: (filters: Record<string, unknown>[], field: string, value?: string) => void; addExactFilter: (filters: Record<string, unknown>[], field: string, value?: string) => void; }; export default _default; //# sourceMappingURL=mongodb-query-filters.d.ts.map