@lyxa.ai/core 1.3.220 → 1.3.221
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/types/README.md
CHANGED
package/dist/types/package.json
CHANGED
package/dist/utilities/search.js
CHANGED
|
@@ -3,11 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.buildSearchQuery = buildSearchQuery;
|
|
4
4
|
const normalize_1 = require("./normalize");
|
|
5
5
|
function buildSearchQuery(searchKey, fields) {
|
|
6
|
-
if (!searchKey?.trim())
|
|
6
|
+
if (!searchKey?.trim() || !fields?.length)
|
|
7
|
+
return {};
|
|
8
|
+
const isEmail = searchKey.includes('@');
|
|
9
|
+
const normalizeSearchKey = isEmail ? searchKey : (0, normalize_1.normalizeName)(searchKey);
|
|
10
|
+
const searchTerms = normalizeSearchKey.split(/[ ,]+/).filter(term => term.trim() !== '');
|
|
11
|
+
if (!searchTerms.length)
|
|
7
12
|
return {};
|
|
8
|
-
const searchTerms = (0, normalize_1.normalizeName)(searchKey)
|
|
9
|
-
.split(/[ ,]+/)
|
|
10
|
-
.filter(term => term.trim() !== '');
|
|
11
13
|
return {
|
|
12
14
|
$and: searchTerms.map(term => ({
|
|
13
15
|
$or: fields.map(field => ({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"search.js","sourceRoot":"/","sources":["utilities/search.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"search.js","sourceRoot":"/","sources":["utilities/search.ts"],"names":[],"mappings":";;AAuCA,4CAkBC;AAzDD,2CAA4C;AAuC5C,SAAgB,gBAAgB,CAAC,SAAiB,EAAE,MAAgB;IACnE,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE,MAAM;QAAE,OAAO,EAAE,CAAC;IAErD,MAAM,OAAO,GAAG,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;IACxC,MAAM,kBAAkB,GAAG,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAA,yBAAa,EAAC,SAAS,CAAC,CAAC;IAG1E,MAAM,WAAW,GAAG,kBAAkB,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;IAEzF,IAAI,CAAC,WAAW,CAAC,MAAM;QAAE,OAAO,EAAE,CAAC;IAEnC,OAAO;QACN,IAAI,EAAE,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YAC9B,GAAG,EAAE,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;gBACzB,CAAC,KAAK,CAAC,EAAE,IAAI,MAAM,CAAC,IAAI,EAAE,GAAG,CAAC;aAC9B,CAAC,CAAC;SACH,CAAC,CAAC;KACH,CAAC;AACH,CAAC","sourcesContent":["import { normalizeName } from './normalize';\n\n/**\n * Builds a MongoDB/Mongoose search query that searches across multiple fields\n *\n * @param searchKey - The search string to parse (space or comma separated terms)\n * @param fields - Array of field names to search against (default: ['name', 'email', 'phoneNumber'])\n * @returns A MongoDB query object that requires ALL terms to match in ANY of the specified fields\n *\n * @example\n * // Basic usage\n * const query = buildSearchQuery('john doe');\n * // Returns: {\n * // $and: [\n * // { $or: [{ name: /john/i }, { email: /john/i }, { phoneNumber: /john/i }] },\n * // { $or: [{ name: /doe/i }, { email: /doe/i }, { phoneNumber: /doe/i }] }\n * // ]\n * // }\n *\n * @example\n * // Custom fields\n * const query = buildSearchQuery('example', ['name', 'email']);\n */\n// export function buildSearchQuery(searchKey: string, fields: string[]): Record<string, any> {\n// \tif (!searchKey?.trim()) return {};\n//\n// \tconst searchTerms = normalizeName(searchKey)\n// \t\t.split(/[ ,]+/)\n// \t\t.filter(term => term.trim() !== '');\n//\n// \treturn {\n// \t\t$and: searchTerms.map(term => ({\n// \t\t\t$or: fields.map(field => ({\n// \t\t\t\t[field]: new RegExp(term, 'i'),\n// \t\t\t})),\n// \t\t})),\n// \t};\n// }\n\nexport function buildSearchQuery(searchKey: string, fields: string[]): Record<string, any> {\n\tif (!searchKey?.trim() || !fields?.length) return {};\n\n\tconst isEmail = searchKey.includes('@');\n\tconst normalizeSearchKey = isEmail ? searchKey : normalizeName(searchKey);\n\n\t// Normal behavior for non-email search (names, userId, phoneNumber, etc ...)\n\tconst searchTerms = normalizeSearchKey.split(/[ ,]+/).filter(term => term.trim() !== '');\n\n\tif (!searchTerms.length) return {};\n\n\treturn {\n\t\t$and: searchTerms.map(term => ({\n\t\t\t$or: fields.map(field => ({\n\t\t\t\t[field]: new RegExp(term, 'i'),\n\t\t\t})),\n\t\t})),\n\t};\n}\n"]}
|