@lyxa.ai/core 1.0.167 → 1.0.169
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
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare enum ProjectionType {
|
|
2
|
+
USER = "user",
|
|
3
|
+
SHOP = "shop",
|
|
4
|
+
PARENT = "parent",
|
|
5
|
+
RIDER = "rider",
|
|
6
|
+
ADMIN = "admin"
|
|
7
|
+
}
|
|
8
|
+
export declare function excludeFields(select: Record<string, any> | null | undefined, type: ProjectionType): Record<string, 0 | 1>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ProjectionType = void 0;
|
|
4
|
+
exports.excludeFields = excludeFields;
|
|
5
|
+
var ProjectionType;
|
|
6
|
+
(function (ProjectionType) {
|
|
7
|
+
ProjectionType["USER"] = "user";
|
|
8
|
+
ProjectionType["SHOP"] = "shop";
|
|
9
|
+
ProjectionType["PARENT"] = "parent";
|
|
10
|
+
ProjectionType["RIDER"] = "rider";
|
|
11
|
+
ProjectionType["ADMIN"] = "admin";
|
|
12
|
+
})(ProjectionType || (exports.ProjectionType = ProjectionType = {}));
|
|
13
|
+
const excludedFieldsMap = {
|
|
14
|
+
[ProjectionType.USER]: ['phoneOtpInfo fcmTokens'],
|
|
15
|
+
[ProjectionType.SHOP]: ['fcmTokens'],
|
|
16
|
+
[ProjectionType.PARENT]: [],
|
|
17
|
+
[ProjectionType.RIDER]: ['password', 'fcmToken', 'forgetToken', 'forgetExpired'],
|
|
18
|
+
[ProjectionType.ADMIN]: [],
|
|
19
|
+
};
|
|
20
|
+
function excludeFieldsFromProjection(select, fieldsToExclude) {
|
|
21
|
+
if (select && typeof select === 'object') {
|
|
22
|
+
const newSelect = { ...select };
|
|
23
|
+
for (const field of fieldsToExclude) {
|
|
24
|
+
delete newSelect[field];
|
|
25
|
+
}
|
|
26
|
+
return newSelect;
|
|
27
|
+
}
|
|
28
|
+
return fieldsToExclude.reduce((acc, field) => {
|
|
29
|
+
acc[field] = 0;
|
|
30
|
+
return acc;
|
|
31
|
+
}, {});
|
|
32
|
+
}
|
|
33
|
+
function excludeFields(select, type) {
|
|
34
|
+
const fieldsToExclude = excludedFieldsMap[type] || [];
|
|
35
|
+
return excludeFieldsFromProjection(select, fieldsToExclude);
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=projection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"projection.js","sourceRoot":"/","sources":["utilities/projection.ts"],"names":[],"mappings":";;;AAoDA,sCAMC;AA1DD,IAAY,cAMX;AAND,WAAY,cAAc;IACzB,+BAAa,CAAA;IACb,+BAAa,CAAA;IACb,mCAAiB,CAAA;IACjB,iCAAe,CAAA;IACf,iCAAe,CAAA;AAChB,CAAC,EANW,cAAc,8BAAd,cAAc,QAMzB;AAED,MAAM,iBAAiB,GAAqC;IAC3D,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE,CAAC,wBAAwB,CAAC;IACjD,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE,CAAC,WAAW,CAAC;IACpC,CAAC,cAAc,CAAC,MAAM,CAAC,EAAE,EAAE;IAC3B,CAAC,cAAc,CAAC,KAAK,CAAC,EAAE,CAAC,UAAU,EAAE,UAAU,EAAE,aAAa,EAAE,eAAe,CAAC;IAChF,CAAC,cAAc,CAAC,KAAK,CAAC,EAAE,EAAE;CAC1B,CAAC;AASF,SAAS,2BAA2B,CACnC,MAA8C,EAC9C,eAAyB;IAGzB,IAAI,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;QAC1C,MAAM,SAAS,GAA0B,EAAE,GAAG,MAAM,EAAE,CAAC;QAEvD,KAAK,MAAM,KAAK,IAAI,eAAe,EAAE,CAAC;YACrC,OAAO,SAAS,CAAC,KAAK,CAAC,CAAC;QACzB,CAAC;QAED,OAAO,SAAS,CAAC;IAClB,CAAC;IAGD,OAAO,eAAe,CAAC,MAAM,CAAoB,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE;QAC/D,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACf,OAAO,GAAG,CAAC;IACZ,CAAC,EAAE,EAAE,CAAC,CAAC;AACR,CAAC;AASD,SAAgB,aAAa,CAC5B,MAA8C,EAC9C,IAAoB;IAEpB,MAAM,eAAe,GAAG,iBAAiB,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;IACtD,OAAO,2BAA2B,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;AAC7D,CAAC","sourcesContent":["export enum ProjectionType {\n\tUSER = 'user',\n\tSHOP = 'shop',\n\tPARENT = 'parent',\n\tRIDER = 'rider',\n\tADMIN = 'admin',\n}\n\nconst excludedFieldsMap: Record<ProjectionType, string[]> = {\n\t[ProjectionType.USER]: ['phoneOtpInfo fcmTokens'],\n\t[ProjectionType.SHOP]: ['fcmTokens'],\n\t[ProjectionType.PARENT]: [],\n\t[ProjectionType.RIDER]: ['password', 'fcmToken', 'forgetToken', 'forgetExpired'],\n\t[ProjectionType.ADMIN]: [],\n};\n\n/**\n * Utility to exclude specific fields from a MongoDB projection/select object.\n *\n * @param select - Existing projection object or undefined.\n * @param fieldsToExclude - Array of field names to exclude.\n * @returns A new projection object with specified fields excluded.\n */\nfunction excludeFieldsFromProjection(\n\tselect: Record<string, any> | null | undefined,\n\tfieldsToExclude: string[]\n): Record<string, 0 | 1> {\n\t// Case 1: If select object exists, clone and delete excluded fields\n\tif (select && typeof select === 'object') {\n\t\tconst newSelect: Record<string, 0 | 1> = { ...select };\n\n\t\tfor (const field of fieldsToExclude) {\n\t\t\tdelete newSelect[field];\n\t\t}\n\n\t\treturn newSelect;\n\t}\n\n\t// Case 2: No select provided, create one with excluded fields only\n\treturn fieldsToExclude.reduce<Record<string, 0>>((acc, field) => {\n\t\tacc[field] = 0;\n\t\treturn acc;\n\t}, {});\n}\n\n/**\n * Dynamically excludes fields from a projection based on model type.\n *\n * @param select - The existing MongoDB projection object.\n * @param model - The model type (e.g., 'user', 'shop').\n * @returns A new projection object with model-specific fields excluded.\n */\nexport function excludeFields(\n\tselect: Record<string, any> | null | undefined,\n\ttype: ProjectionType\n): Record<string, 0 | 1> {\n\tconst fieldsToExclude = excludedFieldsMap[type] || [];\n\treturn excludeFieldsFromProjection(select, fieldsToExclude);\n}\n"]}
|