UNPKG

@point-hub/papi

Version:

Point API Framework

101 lines 4.52 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; /** * Parses a boolean value from a string or boolean input. * * - Accepts `true` / `false` booleans directly * - Converts string values `"true"` and `"false"` to booleans * - Returns `undefined` for any other value * * @param value - A boolean or a string representation of a boolean. * @returns `true`, `false`, or `undefined` if the value cannot be parsed. */ export declare const parseBoolean: (value?: string | boolean) => boolean | undefined; /** * Adds a boolean exact-match filter to the filters array. * * The filter is only added if the value can be successfully parsed * into a boolean (`true` or `false`). * * @param filters - An array of MongoDB filter objects to be modified. * @param field - The field name to match. * @param value - A boolean or string (`"true"` / `"false"`) to match. */ export declare const addBooleanFilter: (filters: Record<string, unknown>[], field: string, value?: string | boolean) => void; /** * Adds a MongoDB date range filter (`$gte` / `$lte`) to the filters array. * * The filter is only added if at least one of `value_from` or `value_to` * is provided and non-empty. * * @param filters - An array of MongoDB filter objects to be modified. * @param field - The date field name to apply the range filter on. * @param value_from - The start date (inclusive) as a string. * @param value_to - The end date (inclusive) as a string. */ export declare const addDateRangeFilter: (filters: Record<string, unknown>[], field: string, value_from?: string, value_to?: 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; }; addBooleanFilter: (filters: Record<string, unknown>[], field: string, value?: string | boolean) => void; addNumberFilter: (filters: Record<string, unknown>[], field: string, value?: string) => void; addRegexFilter: (filters: Record<string, unknown>[], field: string, value?: string) => void; addDateRangeFilter: (filters: Record<string, unknown>[], field: string, value_from?: string, value_to?: string) => void; addExactFilter: (filters: Record<string, unknown>[], field: string, value?: string) => void; }; export default _default; //# sourceMappingURL=mongodb-query-filters.d.ts.map