@lyxa.ai/core 1.2.41 → 1.2.42
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
|
@@ -9,8 +9,13 @@ const models_1 = require("../libraries/mongo/models");
|
|
|
9
9
|
function normalizeObjectIds(query, objectIdFields) {
|
|
10
10
|
for (const field of objectIdFields) {
|
|
11
11
|
if (query?.[field]) {
|
|
12
|
-
if (query?.[field]['$in']) {
|
|
13
|
-
|
|
12
|
+
if (query?.[field]['$in'] || query?.[field]['$nin']) {
|
|
13
|
+
if (query?.[field]['$in']) {
|
|
14
|
+
query[field]['$in'] = query?.[field]['$in'].map((id) => new typegoose_1.mongoose.Types.ObjectId(id));
|
|
15
|
+
}
|
|
16
|
+
if (query?.[field]['$nin']) {
|
|
17
|
+
query[field]['$nin'] = query?.[field]['$nin'].map((id) => new typegoose_1.mongoose.Types.ObjectId(id));
|
|
18
|
+
}
|
|
14
19
|
}
|
|
15
20
|
else {
|
|
16
21
|
query[field] = new typegoose_1.mongoose.Types.ObjectId(query[field]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"normalize.js","sourceRoot":"/","sources":["utilities/normalize.ts"],"names":[],"mappings":";;;AAOA,
|
|
1
|
+
{"version":3,"file":"normalize.js","sourceRoot":"/","sources":["utilities/normalize.ts"],"names":[],"mappings":";;;AAOA,gDAeC;AAOD,sDAeC;AA5CD,oDAAgD;AAChD,6CAA6D;AAC7D,sDAA6D;AAK7D,SAAgB,kBAAkB,CAAC,KAA0B,EAAE,cAAwB;IACtF,KAAK,MAAM,KAAK,IAAI,cAAc,EAAE,CAAC;QACpC,IAAI,KAAK,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC;YACpB,IAAI,KAAK,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,IAAI,KAAK,EAAE,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,EAAE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gBAAgB,CAAC,MAAM,EAAE,2BAAc,CAAC,IAAI,CAAC,CAAC;QACtF,gBAAgB,CAAC,QAAQ,GAAG;YAC3B,IAAI,EAAE,UAAU;YAChB,MAAM,EAAE,8BAA8B;YACtC,KAAK,EAAE,IAAA,yBAAgB,GAAE;SACzB,CAAC;IACH,CAAC;AACF,CAAC;AAaM,MAAM,aAAa,GAAG,CAAC,IAAY,EAAE,EAAE,CAC7C,IAAI;KACF,IAAI,EAAE;KACN,SAAS,CAAC,KAAK,CAAC;KAChB,OAAO,CAAC,kBAAkB,EAAE,EAAE,CAAC;KAC/B,OAAO,CAAC,iBAAiB,EAAE,EAAE,CAAC;KAC9B,WAAW,EAAE,CAAC;AANJ,QAAA,aAAa,iBAMT","sourcesContent":["import { mongoose } from '@typegoose/typegoose';\nimport { excludeFields, ProjectionType } from './projection';\nimport { getCoreUserModel } from '../libraries/mongo/models';\n\n/**\n * Converts specific fields in query to ObjectIds safely.\n */\nexport function normalizeObjectIds(query: Record<string, any>, objectIdFields: string[]): void {\n\tfor (const field of objectIdFields) {\n\t\tif (query?.[field]) {\n\t\t\tif (query?.[field]['$in'] || query?.[field]['$nin']) {\n\t\t\t\tif (query?.[field]['$in']) {\n\t\t\t\t\tquery[field]['$in'] = query?.[field]['$in'].map((id: string) => new mongoose.Types.ObjectId(id));\n\t\t\t\t}\n\t\t\t\tif (query?.[field]['$nin']) {\n\t\t\t\t\tquery[field]['$nin'] = query?.[field]['$nin'].map((id: string) => new mongoose.Types.ObjectId(id));\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tquery[field] = new mongoose.Types.ObjectId(query[field]);\n\t\t\t}\n\t\t}\n\t}\n}\n\n/**\n * Adjusts user population rules:\n * - Excludes sensitive user fields\n * - Populates nested `coreUser`\n */\nexport function normalizeUserPopulate(populate?: any[] | any): void {\n\tif (!Array.isArray(populate)) {\n\t\tpopulate = populate ? [populate] : [];\n\t}\n\n\tconst findUserPopulate = populate.find((populate: any) => populate.path === 'user');\n\n\tif (findUserPopulate) {\n\t\tfindUserPopulate.select = excludeFields(findUserPopulate.select, ProjectionType.USER);\n\t\tfindUserPopulate.populate = {\n\t\t\tpath: 'coreUser',\n\t\t\tselect: '-_id name email profilePhoto',\n\t\t\tmodel: getCoreUserModel(),\n\t\t};\n\t}\n}\n\n/**\n * Normalizes a string by removing diacritics (accents) and punctuation/special chars and converting it to lowercase.\n *\n * @param text - The input string to normalize.\n * @returns The normalized string without accents and punctuation/special chars and in lowercase.\n *\n * @example\n * normalizeName(\"Crème Brûlée\"); // \"creme brulee\"\n * normalizeName(\"São Paulo\"); // \"sao paulo\"\n * normalizeName(\"Ka'ak\"); // \"kaak\"\n */\nexport const normalizeName = (text: string) =>\n\ttext\n\t\t.trim()\n\t\t.normalize('NFD')\n\t\t.replace(/[\\u0300-\\u036f]/g, '') // remove accents\n\t\t.replace(/[^a-zA-Z0-9\\s]/g, '') // remove punctuation/special chars\n\t\t.toLowerCase();\n"]}
|