@@ -4,15 +4,36 @@ const _path = require("path");
4
4
const process = require("process");
5
5
const JSONbig = require("json-bigint")({ storeAsString: false });
6
6
7
- const KeysFunction = ["path", "$id", "execute", "name", "enabled", "logging", "runtime", "scopes", "events", "schedule", "timeout", "entrypoint", "commands"];
8
- const KeysDatabase = ["$id", "name", "enabled"];
9
- const KeysCollection = ["$id", "$permissions", "databaseId", "name", "enabled", "documentSecurity", "attributes", "indexes"];
10
- const KeysStorage = ["$id", "$permissions", "fileSecurity", "name", "enabled", "maximumFileSize", "allowedFileExtensions", "compression", "encryption", "antivirus"];
11
- const KeyTopics = ["$id", "name", "subscribe"];
12
- const KeyAttributes = ["key", "type", "required", "array", "size", "default"];
13
- const KeyIndexes = ["key", "type", "status", "attributes", "orders"];
14
-
15
- function whitelistKeys(value, keys, nestedKeys = []) {
7
+ const KeysFunction = new Set(["path", "$id", "execute", "name", "enabled", "logging", "runtime", "scopes", "events", "schedule", "timeout", "entrypoint", "commands"]);
8
+ const KeysDatabase = new Set(["$id", "name", "enabled"]);
9
+ const KeysCollection = new Set(["$id", "$permissions", "databaseId", "name", "enabled", "documentSecurity", "attributes", "indexes"]);
10
+ const KeysStorage = new Set(["$id", "$permissions", "fileSecurity", "name", "enabled", "maximumFileSize", "allowedFileExtensions", "compression", "encryption", "antivirus"]);
11
+ const KeyTopics = new Set(["$id", "name", "subscribe"]);
12
+ const KeyAttributes = new Set([
13
+ "key",
14
+ "type",
15
+ "required",
16
+ "array",
17
+ "size",
18
+ "default",
19
+ // integer and float
20
+ "min",
21
+ "max",
22
+ // email, enum, URL, IP, and datetime
23
+ "format",
24
+ // enum
25
+ "elements",
26
+ // relationship
27
+ "relatedCollection",
28
+ "relationType",
29
+ "twoWay",
30
+ "twoWayKey",
31
+ "onDelete",
32
+ "side"
33
+ ]);
34
+ const KeyIndexes = new Set(["key", "type", "status", "attributes", "orders"]);
35
+
36
+ function whitelistKeys(value, keys, nestedKeys = {}) {
16
37
if(Array.isArray(value)) {
17
38
const newValue = [];
18
39
@@ -25,7 +46,7 @@ function whitelistKeys(value, keys, nestedKeys = []) {
25
46
26
47
const newValue = {};
27
48
Object.keys(value).forEach((key) => {
28
- if(keys.includes (key)) {
49
+ if(keys.has (key)) {
29
50
if(nestedKeys[key]) {
30
51
newValue[key] = whitelistKeys(value[key], nestedKeys[key]);
31
52
} else {
0 commit comments