@lobb-js/core 0.21.0 → 0.22.0
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
CHANGED
|
@@ -9,6 +9,7 @@ import { ZodError } from "zod";
|
|
|
9
9
|
import { LobbError } from "../../LobbError.ts";
|
|
10
10
|
import { Lobb } from "../../Lobb.ts";
|
|
11
11
|
import { beginTransaction } from "./transactions.ts";
|
|
12
|
+
import { validateFilterFields } from "./utils.ts";
|
|
12
13
|
|
|
13
14
|
export interface ExposedServiceOutput {
|
|
14
15
|
data: any;
|
|
@@ -70,6 +71,10 @@ export class CollectionStore {
|
|
|
70
71
|
}
|
|
71
72
|
|
|
72
73
|
if (params?.filter) {
|
|
74
|
+
if (triggeredBy === "API") {
|
|
75
|
+
validateFilterFields(params.filter, collectionName);
|
|
76
|
+
}
|
|
77
|
+
|
|
73
78
|
params.filter = {
|
|
74
79
|
$and: [params.filter],
|
|
75
80
|
};
|
|
@@ -1,6 +1,29 @@
|
|
|
1
1
|
import { Lobb } from "../../Lobb.ts";
|
|
2
|
+
import { LobbError } from "../../LobbError.ts";
|
|
2
3
|
import { z } from "zod";
|
|
3
4
|
|
|
5
|
+
export function validateFilterFields(filter: any, collectionName: string) {
|
|
6
|
+
const collectionFields = Lobb.instance.configManager.getNormalCollection(collectionName)?.fields;
|
|
7
|
+
if (!collectionFields) return;
|
|
8
|
+
|
|
9
|
+
const checkObject = (obj: any) => {
|
|
10
|
+
for (const key of Object.keys(obj)) {
|
|
11
|
+
if (key === "$and" || key === "$or") {
|
|
12
|
+
for (const sub of obj[key]) checkObject(sub);
|
|
13
|
+
} else if (!key.startsWith("$")) {
|
|
14
|
+
if (!collectionFields[key]) {
|
|
15
|
+
throw new LobbError({
|
|
16
|
+
code: "BAD_REQUEST",
|
|
17
|
+
message: `Invalid filter: field "${key}" does not exist in collection "${collectionName}"`,
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
checkObject(filter);
|
|
25
|
+
}
|
|
26
|
+
|
|
4
27
|
export function getCollectionDocumentSchema(
|
|
5
28
|
collectionName?: string,
|
|
6
29
|
) {
|