Skip to content

Commit 7f886ab

Browse files
authored
fix(cli): ensure all attribute keys are pulled into appwrite.json
1 parent b9cd545 commit 7f886ab

File tree

1 file changed

+31
-10
lines changed

1 file changed

+31
-10
lines changed

templates/cli/lib/config.js.twig

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,36 @@ const _path = require("path");
44
const process = require("process");
55
const JSONbig = require("json-bigint")({ storeAsString: false });
66

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 = {}) {
1637
if(Array.isArray(value)) {
1738
const newValue = [];
1839

@@ -25,7 +46,7 @@ function whitelistKeys(value, keys, nestedKeys = []) {
2546

2647
const newValue = {};
2748
Object.keys(value).forEach((key) => {
28-
if(keys.includes(key)) {
49+
if(keys.has(key)) {
2950
if(nestedKeys[key]) {
3051
newValue[key] = whitelistKeys(value[key], nestedKeys[key]);
3152
} else {

0 commit comments

Comments
 (0)