vanta-api 1.2.7 → 1.2.8
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/package.json +1 -1
- package/src/api-features.js +34 -9
package/package.json
CHANGED
package/src/api-features.js
CHANGED
|
@@ -62,21 +62,46 @@ export class ApiFeatures {
|
|
|
62
62
|
return this;
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
65
|
+
limitFields(input = "") {
|
|
66
|
+
const rawFields = [input, this.query.fields].filter(Boolean).join(",");
|
|
67
|
+
if (!rawFields) return this;
|
|
68
|
+
|
|
69
|
+
const validFields = Object.keys(this.model.schema.paths).filter(
|
|
70
|
+
(f) => !securityConfig.forbiddenFields.includes(f)
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
const fieldsArray = rawFields
|
|
74
|
+
.split(",")
|
|
75
|
+
.map((f) => f.trim())
|
|
76
|
+
.filter(Boolean);
|
|
77
|
+
|
|
78
|
+
const includeFields = new Set();
|
|
79
|
+
const excludeFields = new Set();
|
|
80
|
+
|
|
81
|
+
fieldsArray.forEach((f) => {
|
|
82
|
+
if (f.startsWith("-")) excludeFields.add(f.slice(1));
|
|
83
|
+
else includeFields.add(f);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
const project = {};
|
|
71
87
|
|
|
72
|
-
|
|
88
|
+
if (includeFields.size > 0) {
|
|
89
|
+
includeFields.forEach((f) => {
|
|
73
90
|
if (validFields.includes(f)) project[f] = 1;
|
|
74
91
|
});
|
|
92
|
+
} else if (excludeFields.size > 0) {
|
|
93
|
+
validFields.forEach((f) => {
|
|
94
|
+
if (!excludeFields.has(f)) project[f] = 1;
|
|
95
|
+
});
|
|
96
|
+
}
|
|
75
97
|
|
|
76
|
-
|
|
77
|
-
|
|
98
|
+
if (Object.keys(project).length) {
|
|
99
|
+
this.pipeline.push({ $project: project });
|
|
78
100
|
}
|
|
79
101
|
|
|
102
|
+
return this;
|
|
103
|
+
}
|
|
104
|
+
|
|
80
105
|
paginate() {
|
|
81
106
|
const { maxLimit } = securityConfig.accessLevels[this.userRole] || {
|
|
82
107
|
maxLimit: 100,
|