Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 19 additions & 13 deletions lib/commands/databases.js
Original file line number Diff line number Diff line change
Expand Up @@ -1185,7 +1185,7 @@ const databasesUpdateIpAttribute = async ({databaseId,collectionId,key,required,
* @property {string} collectionId Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).
* @property {string} key Attribute Key.
* @property {boolean} required Is attribute required?
* @property {string} xdefault Default value for attribute when not provided, as JSON string. Cannot be set when attribute is required.
* @property {any[]} xdefault Default value for attribute when not provided, two-dimensional array of coordinate pairs, [[longitude, latitude], [longitude, latitude], …], listing the vertices of the line in order. Cannot be set when attribute is required.
* @property {boolean} overrideForCli
* @property {boolean} parseOutput
* @property {libClient | undefined} sdk
Expand All @@ -1205,6 +1205,7 @@ const databasesCreateLineAttribute = async ({databaseId,collectionId,key,require
if (typeof required !== 'undefined') {
payload['required'] = required;
}
xdefault = xdefault === true ? [] : xdefault;
if (typeof xdefault !== 'undefined') {
payload['default'] = xdefault;
}
Comment on lines +1208 to 1211
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

xdefault passed as string; must JSON.parse before sending.

Commander delivers CLI args as strings. Without parsing, the API receives a string instead of an array and will fail validation for spatial defaults.

Apply parsing in all spatial attribute helpers:

 xdefault = xdefault === true ? [] : xdefault;
+if (typeof xdefault === 'string') {
+  xdefault = JSON.parse(xdefault);
+}
 if (typeof xdefault !== 'undefined') {
   payload['default'] = xdefault;
 }

Also applies to: 1250-1253, 1297-1300, 1339-1342, 1386-1389, 1429-1432

Expand All @@ -1228,7 +1229,7 @@ const databasesCreateLineAttribute = async ({databaseId,collectionId,key,require
* @property {string} collectionId Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#createCollection).
* @property {string} key Attribute Key.
* @property {boolean} required Is attribute required?
* @property {string} xdefault Default value for attribute when not provided, as JSON string. Cannot be set when attribute is required.
* @property {any[]} xdefault Default value for attribute when not provided, two-dimensional array of coordinate pairs, [[longitude, latitude], [longitude, latitude], …], listing the vertices of the line in order. Cannot be set when attribute is required.
* @property {string} newKey New attribute key.
* @property {boolean} overrideForCli
* @property {boolean} parseOutput
Expand All @@ -1246,6 +1247,7 @@ const databasesUpdateLineAttribute = async ({databaseId,collectionId,key,require
if (typeof required !== 'undefined') {
payload['required'] = required;
}
xdefault = xdefault === true ? [] : xdefault;
if (typeof xdefault !== 'undefined') {
payload['default'] = xdefault;
}
Expand All @@ -1272,7 +1274,7 @@ const databasesUpdateLineAttribute = async ({databaseId,collectionId,key,require
* @property {string} collectionId Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).
* @property {string} key Attribute Key.
* @property {boolean} required Is attribute required?
* @property {string} xdefault Default value for attribute when not provided, as JSON string. Cannot be set when attribute is required.
* @property {any[]} xdefault Default value for attribute when not provided, array of two numbers [longitude, latitude], representing a single coordinate. Cannot be set when attribute is required.
* @property {boolean} overrideForCli
* @property {boolean} parseOutput
* @property {libClient | undefined} sdk
Expand All @@ -1292,6 +1294,7 @@ const databasesCreatePointAttribute = async ({databaseId,collectionId,key,requir
if (typeof required !== 'undefined') {
payload['required'] = required;
}
xdefault = xdefault === true ? [] : xdefault;
if (typeof xdefault !== 'undefined') {
payload['default'] = xdefault;
}
Expand All @@ -1315,7 +1318,7 @@ const databasesCreatePointAttribute = async ({databaseId,collectionId,key,requir
* @property {string} collectionId Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#createCollection).
* @property {string} key Attribute Key.
* @property {boolean} required Is attribute required?
* @property {string} xdefault Default value for attribute when not provided, as JSON string. Cannot be set when attribute is required.
* @property {any[]} xdefault Default value for attribute when not provided, array of two numbers [longitude, latitude], representing a single coordinate. Cannot be set when attribute is required.
* @property {string} newKey New attribute key.
* @property {boolean} overrideForCli
* @property {boolean} parseOutput
Expand All @@ -1333,6 +1336,7 @@ const databasesUpdatePointAttribute = async ({databaseId,collectionId,key,requir
if (typeof required !== 'undefined') {
payload['required'] = required;
}
xdefault = xdefault === true ? [] : xdefault;
if (typeof xdefault !== 'undefined') {
payload['default'] = xdefault;
}
Expand All @@ -1359,7 +1363,7 @@ const databasesUpdatePointAttribute = async ({databaseId,collectionId,key,requir
* @property {string} collectionId Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).
* @property {string} key Attribute Key.
* @property {boolean} required Is attribute required?
* @property {string} xdefault Default value for attribute when not provided, as JSON string. Cannot be set when attribute is required.
* @property {any[]} xdefault Default value for attribute when not provided, three-dimensional array where the outer array holds one or more linear rings, [[[longitude, latitude], …], …], the first ring is the exterior boundary, any additional rings are interior holes, and each ring must start and end with the same coordinate pair. Cannot be set when attribute is required.
* @property {boolean} overrideForCli
* @property {boolean} parseOutput
* @property {libClient | undefined} sdk
Expand All @@ -1379,6 +1383,7 @@ const databasesCreatePolygonAttribute = async ({databaseId,collectionId,key,requ
if (typeof required !== 'undefined') {
payload['required'] = required;
}
xdefault = xdefault === true ? [] : xdefault;
if (typeof xdefault !== 'undefined') {
payload['default'] = xdefault;
}
Expand All @@ -1402,7 +1407,7 @@ const databasesCreatePolygonAttribute = async ({databaseId,collectionId,key,requ
* @property {string} collectionId Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#createCollection).
* @property {string} key Attribute Key.
* @property {boolean} required Is attribute required?
* @property {string} xdefault Default value for attribute when not provided, as JSON string. Cannot be set when attribute is required.
* @property {any[]} xdefault Default value for attribute when not provided, three-dimensional array where the outer array holds one or more linear rings, [[[longitude, latitude], …], …], the first ring is the exterior boundary, any additional rings are interior holes, and each ring must start and end with the same coordinate pair. Cannot be set when attribute is required.
* @property {string} newKey New attribute key.
* @property {boolean} overrideForCli
* @property {boolean} parseOutput
Expand All @@ -1420,6 +1425,7 @@ const databasesUpdatePolygonAttribute = async ({databaseId,collectionId,key,requ
if (typeof required !== 'undefined') {
payload['required'] = required;
}
xdefault = xdefault === true ? [] : xdefault;
if (typeof xdefault !== 'undefined') {
payload['default'] = xdefault;
}
Expand Down Expand Up @@ -2851,7 +2857,7 @@ databases
.requiredOption(`--collection-id <collection-id>`, `Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).`)
.requiredOption(`--key <key>`, `Attribute Key.`)
.requiredOption(`--required [value]`, `Is attribute required?`, (value) => value === undefined ? true : parseBool(value))
.option(`--xdefault <xdefault>`, `Default value for attribute when not provided, as JSON string. Cannot be set when attribute is required.`)
.option(`--xdefault <xdefault>`, `Default value for attribute when not provided, two-dimensional array of coordinate pairs, [[longitude, latitude], [longitude, latitude], …], listing the vertices of the line in order. Cannot be set when attribute is required.`)
.action(actionRunner(databasesCreateLineAttribute))

databases
Expand All @@ -2861,18 +2867,18 @@ databases
.requiredOption(`--collection-id <collection-id>`, `Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#createCollection).`)
.requiredOption(`--key <key>`, `Attribute Key.`)
.requiredOption(`--required [value]`, `Is attribute required?`, (value) => value === undefined ? true : parseBool(value))
.option(`--xdefault <xdefault>`, `Default value for attribute when not provided, as JSON string. Cannot be set when attribute is required.`)
.option(`--xdefault <xdefault>`, `Default value for attribute when not provided, two-dimensional array of coordinate pairs, [[longitude, latitude], [longitude, latitude], …], listing the vertices of the line in order. Cannot be set when attribute is required.`)
.option(`--new-key <new-key>`, `New attribute key.`)
.action(actionRunner(databasesUpdateLineAttribute))

databases
.command(`create-point-attribute`)
.description(`[**DEPRECATED** - This command is deprecated. Please use 'tables-db create-point-column' instead] Create a geometric 2d point attribute.`)
.description(`[**DEPRECATED** - This command is deprecated. Please use 'tables-db create-point-column' instead] Create a geometric point attribute.`)
.requiredOption(`--database-id <database-id>`, `Database ID.`)
.requiredOption(`--collection-id <collection-id>`, `Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).`)
.requiredOption(`--key <key>`, `Attribute Key.`)
.requiredOption(`--required [value]`, `Is attribute required?`, (value) => value === undefined ? true : parseBool(value))
.option(`--xdefault <xdefault>`, `Default value for attribute when not provided, as JSON string. Cannot be set when attribute is required.`)
.option(`--xdefault <xdefault>`, `Default value for attribute when not provided, array of two numbers [longitude, latitude], representing a single coordinate. Cannot be set when attribute is required.`)
.action(actionRunner(databasesCreatePointAttribute))

databases
Expand All @@ -2882,7 +2888,7 @@ databases
.requiredOption(`--collection-id <collection-id>`, `Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#createCollection).`)
.requiredOption(`--key <key>`, `Attribute Key.`)
.requiredOption(`--required [value]`, `Is attribute required?`, (value) => value === undefined ? true : parseBool(value))
.option(`--xdefault <xdefault>`, `Default value for attribute when not provided, as JSON string. Cannot be set when attribute is required.`)
.option(`--xdefault <xdefault>`, `Default value for attribute when not provided, array of two numbers [longitude, latitude], representing a single coordinate. Cannot be set when attribute is required.`)
.option(`--new-key <new-key>`, `New attribute key.`)
.action(actionRunner(databasesUpdatePointAttribute))

Expand All @@ -2893,7 +2899,7 @@ databases
.requiredOption(`--collection-id <collection-id>`, `Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).`)
.requiredOption(`--key <key>`, `Attribute Key.`)
.requiredOption(`--required [value]`, `Is attribute required?`, (value) => value === undefined ? true : parseBool(value))
.option(`--xdefault <xdefault>`, `Default value for attribute when not provided, as JSON string. Cannot be set when attribute is required.`)
.option(`--xdefault <xdefault>`, `Default value for attribute when not provided, three-dimensional array where the outer array holds one or more linear rings, [[[longitude, latitude], …], …], the first ring is the exterior boundary, any additional rings are interior holes, and each ring must start and end with the same coordinate pair. Cannot be set when attribute is required.`)
.action(actionRunner(databasesCreatePolygonAttribute))

databases
Expand All @@ -2903,7 +2909,7 @@ databases
.requiredOption(`--collection-id <collection-id>`, `Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#createCollection).`)
.requiredOption(`--key <key>`, `Attribute Key.`)
.requiredOption(`--required [value]`, `Is attribute required?`, (value) => value === undefined ? true : parseBool(value))
.option(`--xdefault <xdefault>`, `Default value for attribute when not provided, as JSON string. Cannot be set when attribute is required.`)
.option(`--xdefault <xdefault>`, `Default value for attribute when not provided, three-dimensional array where the outer array holds one or more linear rings, [[[longitude, latitude], …], …], the first ring is the exterior boundary, any additional rings are interior holes, and each ring must start and end with the same coordinate pair. Cannot be set when attribute is required.`)
.option(`--new-key <new-key>`, `New attribute key.`)
.action(actionRunner(databasesUpdatePolygonAttribute))

Expand Down
Loading