diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index b740cbe87d..8ceb11f88d 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -31,6 +31,7 @@ use Appwrite\URL\URL as URLParser; use Appwrite\Utopia\Database\Documents\User; use Appwrite\Utopia\Database\Validator\CustomId; use Appwrite\Utopia\Database\Validator\Queries\Identities; +use Appwrite\Utopia\Database\Validator\Queries\Types; use Appwrite\Utopia\Request; use Appwrite\Utopia\Response; use libphonenumber\PhoneNumberUtil; @@ -3033,7 +3034,9 @@ App::get('/v1/account/logs') ], contentType: ContentType::JSON, )) - ->param('queries', [], new Queries([new Limit(), new Offset()]), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Only supported methods are limit and offset', true) + //->param('queries', [], new ArrayList(new Text(APP_LIMIT_ARRAY_ELEMENT_SIZE), APP_LIMIT_ARRAY_PARAMS_SIZE), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' queries are allowed, each ' . APP_LIMIT_ARRAY_ELEMENT_SIZE . ' characters long.', true) + //->param('queries', [], new Queries([new Limit(), new Offset()]), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Only supported methods are limit and offset', true) + ->param('queries', [], new Types([Query::TYPE_LIMIT, Query::TYPE_OFFSET]), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Only supported methods are limit and offset', true) ->param('total', true, new Boolean(true), 'When set to false, the total count returned will be 0 and will not be calculated.', true) ->inject('response') ->inject('user') @@ -3048,6 +3051,11 @@ App::get('/v1/account/logs') throw new Exception(Exception::GENERAL_QUERY_INVALID, $e->getMessage()); } +// $validator = new Types([Query::TYPE_LIMIT, Query::TYPE_OFFSET]); +// if (!$validator->isValid($queries)) { +// throw new Exception(Exception::GENERAL_QUERY_INVALID, $validator->getDescription()); +// } + $audit = new EventAudit($dbForProject); $logs = $audit->getLogsByUser($user->getSequence(), $queries); diff --git a/app/controllers/api/messaging.php b/app/controllers/api/messaging.php index 0eb9866173..8880fa677f 100644 --- a/app/controllers/api/messaging.php +++ b/app/controllers/api/messaging.php @@ -23,6 +23,7 @@ use Appwrite\Utopia\Database\Validator\Queries\Providers; use Appwrite\Utopia\Database\Validator\Queries\Subscribers; use Appwrite\Utopia\Database\Validator\Queries\Targets; use Appwrite\Utopia\Database\Validator\Queries\Topics; +use Appwrite\Utopia\Database\Validator\Queries\Types; use Appwrite\Utopia\Response; use MaxMind\Db\Reader; use Utopia\App; @@ -1141,7 +1142,7 @@ App::get('/v1/messaging/providers/:providerId/logs') ] )) ->param('providerId', '', new UID(), 'Provider ID.') - ->param('queries', [], new Queries([new Limit(), new Offset()]), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Only supported methods are limit and offset', true) + ->param('queries', [], new Types([Query::TYPE_LIMIT, Query::TYPE_OFFSET]), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Only supported methods are limit and offset', true) ->param('total', true, new Boolean(true), 'When set to false, the total count returned will be 0 and will not be calculated.', true) ->inject('response') ->inject('dbForProject') @@ -2546,7 +2547,7 @@ App::get('/v1/messaging/topics/:topicId/logs') ] )) ->param('topicId', '', new UID(), 'Topic ID.') - ->param('queries', [], new Queries([new Limit(), new Offset()]), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Only supported methods are limit and offset', true) + ->param('queries', [], new Types([Query::TYPE_LIMIT, Query::TYPE_OFFSET]), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Only supported methods are limit and offset', true) ->param('total', true, new Boolean(true), 'When set to false, the total count returned will be 0 and will not be calculated.', true) ->inject('response') ->inject('dbForProject') @@ -2962,7 +2963,7 @@ App::get('/v1/messaging/subscribers/:subscriberId/logs') ] )) ->param('subscriberId', '', new UID(), 'Subscriber ID.') - ->param('queries', [], new Queries([new Limit(), new Offset()]), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Only supported methods are limit and offset', true) + ->param('queries', [], new Types([Query::TYPE_LIMIT, Query::TYPE_OFFSET]), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Only supported methods are limit and offset', true) ->param('total', true, new Boolean(true), 'When set to false, the total count returned will be 0 and will not be calculated.', true) ->inject('response') ->inject('dbForProject') @@ -3761,7 +3762,7 @@ App::get('/v1/messaging/messages/:messageId/logs') ], )) ->param('messageId', '', new UID(), 'Message ID.') - ->param('queries', [], new Queries([new Limit(), new Offset()]), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Only supported methods are limit and offset', true) + ->param('queries', [], new Types([Query::TYPE_LIMIT, Query::TYPE_OFFSET]), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Only supported methods are limit and offset', true) ->param('total', true, new Boolean(true), 'When set to false, the total count returned will be 0 and will not be calculated.', true) ->inject('response') ->inject('dbForProject') diff --git a/app/controllers/api/teams.php b/app/controllers/api/teams.php index c948c9c990..eae3dfa70e 100644 --- a/app/controllers/api/teams.php +++ b/app/controllers/api/teams.php @@ -21,6 +21,7 @@ use Appwrite\Utopia\Database\Documents\User; use Appwrite\Utopia\Database\Validator\CustomId; use Appwrite\Utopia\Database\Validator\Queries\Memberships; use Appwrite\Utopia\Database\Validator\Queries\Teams; +use Appwrite\Utopia\Database\Validator\Queries\Types; use Appwrite\Utopia\Request; use Appwrite\Utopia\Response; use libphonenumber\PhoneNumberUtil; @@ -1465,7 +1466,7 @@ App::get('/v1/teams/:teamId/logs') ] )) ->param('teamId', '', new UID(), 'Team ID.') - ->param('queries', [], new Queries([new Limit(), new Offset()]), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Only supported methods are limit and offset', true) + ->param('queries', [], new Types([Query::TYPE_LIMIT, Query::TYPE_OFFSET]), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Only supported methods are limit and offset', true) ->param('total', true, new Boolean(true), 'When set to false, the total count returned will be 0 and will not be calculated.', true) ->inject('response') ->inject('dbForProject') diff --git a/app/controllers/api/users.php b/app/controllers/api/users.php index 747f77f564..ee99f848f5 100644 --- a/app/controllers/api/users.php +++ b/app/controllers/api/users.php @@ -25,6 +25,7 @@ use Appwrite\Utopia\Database\Validator\CustomId; use Appwrite\Utopia\Database\Validator\Queries\Identities; use Appwrite\Utopia\Database\Validator\Queries\Memberships; use Appwrite\Utopia\Database\Validator\Queries\Targets; +use Appwrite\Utopia\Database\Validator\Queries\Types; use Appwrite\Utopia\Database\Validator\Queries\Users; use Appwrite\Utopia\Request; use Appwrite\Utopia\Response; @@ -939,7 +940,7 @@ App::get('/v1/users/:userId/logs') ] )) ->param('userId', '', new UID(), 'User ID.') - ->param('queries', [], new Queries([new Limit(), new Offset()]), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Only supported methods are limit and offset', true) + ->param('queries', [], new Types([Query::TYPE_LIMIT, Query::TYPE_OFFSET]), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Only supported methods are limit and offset', true) ->param('total', true, new Boolean(true), 'When set to false, the total count returned will be 0 and will not be calculated.', true) ->inject('response') ->inject('dbForProject') diff --git a/app/controllers/api/vcs.php b/app/controllers/api/vcs.php index 2270f4fd89..ea74cc0e43 100644 --- a/app/controllers/api/vcs.php +++ b/app/controllers/api/vcs.php @@ -10,6 +10,7 @@ use Appwrite\SDK\Method; use Appwrite\SDK\MethodType; use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Database\Validator\Queries\Installations; +use Appwrite\Utopia\Database\Validator\Queries\Types; use Appwrite\Utopia\Request; use Appwrite\Utopia\Response; use Appwrite\Vcs\Comment; @@ -1035,7 +1036,7 @@ App::get('/v1/vcs/github/installations/:installationId/providerRepositories') ->param('installationId', '', new Text(256), 'Installation Id') ->param('type', '', new WhiteList(['runtime', 'framework']), 'Detector type. Must be one of the following: runtime, framework') ->param('search', '', new Text(256), 'Search term to filter your list results. Max length: 256 chars.', true) - ->param('queries', [], new Queries([new Limit(), new Offset()]), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Only supported methods are limit and offset', true) + ->param('queries', [], new Types([Query::TYPE_LIMIT, Query::TYPE_OFFSET]), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Only supported methods are limit and offset', true) ->inject('gitHub') ->inject('response') ->inject('dbForPlatform') diff --git a/docs/tutorials/add-route.md b/docs/tutorials/add-route.md index 53926f7002..0024d6c6e3 100644 --- a/docs/tutorials/add-route.md +++ b/docs/tutorials/add-route.md @@ -152,7 +152,7 @@ As the name implies, `param()` is used to define a request parameter. ```php App::get('/v1/account/logs') - ->param('queries', [], new Queries([new Limit(), new Offset()]), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Only supported methods are limit and offset', true) + ->param('queries', [], new Types([Query::TYPE_LIMIT, Query::TYPE_OFFSET]), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Only supported methods are limit and offset', true) ``` ### 6. inject diff --git a/phpunit.xml b/phpunit.xml index a8578995c1..215ee2d59d 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -6,7 +6,7 @@ convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" - stopOnFailure="false" + stopOnFailure="true" > diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Logs/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Logs/XList.php index c7b775c7f5..4a30c67465 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Logs/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Logs/XList.php @@ -10,6 +10,7 @@ use Appwrite\SDK\ContentType; use Appwrite\SDK\Deprecated; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; +use Appwrite\Utopia\Database\Validator\Queries\Types; use Appwrite\Utopia\Response as UtopiaResponse; use MaxMind\Db\Reader; use Utopia\Audit\Audit; @@ -67,7 +68,7 @@ class XList extends Action ->param('databaseId', '', new UID(), 'Database ID.') ->param('collectionId', '', new UID(), 'Collection ID.') ->param('documentId', '', new UID(), 'Document ID.') - ->param('queries', [], new Queries([new Limit(), new Offset()]), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Only supported methods are limit and offset', true) + ->param('queries', [], new Types([Query::TYPE_LIMIT, Query::TYPE_OFFSET]), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Only supported methods are limit and offset', true) ->inject('response') ->inject('dbForProject') ->inject('locale') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Logs/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Logs/XList.php index efdb937aa8..d0db8b9895 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Logs/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Logs/XList.php @@ -9,6 +9,7 @@ use Appwrite\SDK\ContentType; use Appwrite\SDK\Deprecated; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; +use Appwrite\Utopia\Database\Validator\Queries\Types; use Appwrite\Utopia\Response as UtopiaResponse; use DeviceDetector\DeviceDetector as Detector; use MaxMind\Db\Reader; @@ -66,7 +67,7 @@ class XList extends Action )) ->param('databaseId', '', new UID(), 'Database ID.') ->param('collectionId', '', new UID(), 'Collection ID.') - ->param('queries', [], new Queries([new Limit(), new Offset()]), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Only supported methods are limit and offset', true) + ->param('queries', [], new Types([Query::TYPE_LIMIT, Query::TYPE_OFFSET]), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Only supported methods are limit and offset', true) ->inject('response') ->inject('dbForProject') ->inject('locale') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Logs/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Logs/XList.php index a794ec325e..65cbd59e22 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Logs/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Logs/XList.php @@ -8,6 +8,7 @@ use Appwrite\SDK\ContentType; use Appwrite\SDK\Deprecated; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; +use Appwrite\Utopia\Database\Validator\Queries\Types; use Appwrite\Utopia\Response as UtopiaResponse; use DeviceDetector\DeviceDetector as Detector; use MaxMind\Db\Reader; @@ -62,7 +63,7 @@ class XList extends Action ), ]) ->param('databaseId', '', new UID(), 'Database ID.') - ->param('queries', [], new Queries([new Limit(), new Offset()]), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Only supported methods are limit and offset', true) + ->param('queries', [], new Types([Query::TYPE_LIMIT, Query::TYPE_OFFSET]), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Only supported methods are limit and offset', true) ->inject('response') ->inject('dbForProject') ->inject('locale') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Logs/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Logs/XList.php index 53476dbae1..ce3ec1387e 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Logs/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Logs/XList.php @@ -7,6 +7,7 @@ use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; +use Appwrite\Utopia\Database\Validator\Queries\Types; use Appwrite\Utopia\Response as UtopiaResponse; use DeviceDetector\DeviceDetector as Detector; use MaxMind\Db\Reader; @@ -57,7 +58,7 @@ class XList extends Action ), ]) ->param('databaseId', '', new UID(), 'Database ID.') - ->param('queries', [], new Queries([new Limit(), new Offset()]), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Only supported methods are limit and offset', true) + ->param('queries', [], new Types([Query::TYPE_LIMIT, Query::TYPE_OFFSET]), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Only supported methods are limit and offset', true) ->inject('response') ->inject('dbForProject') ->inject('locale') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Logs/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Logs/XList.php index f9111287c3..0e660bd527 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Logs/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Logs/XList.php @@ -7,6 +7,8 @@ use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; +use Appwrite\Utopia\Database\Validator\Queries\Types; +use Utopia\Database\Query; use Utopia\Database\Validator\Queries; use Utopia\Database\Validator\Query\Limit; use Utopia\Database\Validator\Query\Offset; @@ -45,7 +47,7 @@ class XList extends CollectionLogXList )) ->param('databaseId', '', new UID(), 'Database ID.') ->param('tableId', '', new UID(), 'Table ID.') - ->param('queries', [], new Queries([new Limit(), new Offset()]), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Only supported methods are limit and offset', true) + ->param('queries', [], new Types([Query::TYPE_LIMIT, Query::TYPE_OFFSET]), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Only supported methods are limit and offset', true) ->inject('response') ->inject('dbForProject') ->inject('locale') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Rows/Logs/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Rows/Logs/XList.php index 5117e77ea9..14fb0d7536 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Rows/Logs/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Rows/Logs/XList.php @@ -7,6 +7,8 @@ use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; +use Appwrite\Utopia\Database\Validator\Queries\Types; +use Utopia\Database\Query; use Utopia\Database\Validator\Queries; use Utopia\Database\Validator\Query\Limit; use Utopia\Database\Validator\Query\Offset; @@ -46,7 +48,7 @@ class XList extends DocumentLogXList ->param('databaseId', '', new UID(), 'Database ID.') ->param('tableId', '', new UID(), 'Table ID.') ->param('rowId', '', new UID(), 'Row ID.') - ->param('queries', [], new Queries([new Limit(), new Offset()]), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Only supported methods are limit and offset', true) + ->param('queries', [], new Types([Query::TYPE_LIMIT, Query::TYPE_OFFSET]), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Only supported methods are limit and offset', true) ->inject('response') ->inject('dbForProject') ->inject('locale') diff --git a/src/Appwrite/Utopia/Database/Validator/Queries/Base.php b/src/Appwrite/Utopia/Database/Validator/Queries/Base.php index 9d9bbde00b..6a956b0a67 100644 --- a/src/Appwrite/Utopia/Database/Validator/Queries/Base.php +++ b/src/Appwrite/Utopia/Database/Validator/Queries/Base.php @@ -5,15 +5,16 @@ namespace Appwrite\Utopia\Database\Validator\Queries; use Utopia\Config\Config; use Utopia\Database\Database; use Utopia\Database\Document; +use Utopia\Database\Query; use Utopia\Database\Validator\Queries; use Utopia\Database\Validator\Query\Cursor; -use Utopia\Database\Validator\Query\Filter; +//use Utopia\Database\Validator\Query\Filter; use Utopia\Database\Validator\Query\Limit; use Utopia\Database\Validator\Query\Offset; -use Utopia\Database\Validator\Query\Order; -use Utopia\Database\Validator\Query\Select; +//use Utopia\Database\Validator\Query\Order; +//use Utopia\Database\Validator\Query\Select; -class Base extends Queries +class Base extends Types { /** * Expression constructor @@ -24,6 +25,51 @@ class Base extends Queries */ public function __construct(string $collection, array $allowedAttributes) { + $types = [ + Query::TYPE_LIMIT, + Query::TYPE_OFFSET, + Query::TYPE_CURSOR_AFTER, + Query::TYPE_CURSOR_BEFORE, + Query::TYPE_ORDER_ASC, + Query::TYPE_ORDER_DESC, + Query::TYPE_ORDER_RANDOM, + Query::TYPE_EQUAL, + Query::TYPE_NOT_EQUAL, + Query::TYPE_LESSER, + Query::TYPE_LESSER_EQUAL, + Query::TYPE_GREATER, + Query::TYPE_GREATER_EQUAL, + Query::TYPE_SEARCH, + Query::TYPE_NOT_SEARCH, + Query::TYPE_IS_NULL, + Query::TYPE_IS_NOT_NULL, + Query::TYPE_BETWEEN, + Query::TYPE_NOT_BETWEEN, + Query::TYPE_STARTS_WITH, + Query::TYPE_NOT_STARTS_WITH, + Query::TYPE_ENDS_WITH, + Query::TYPE_NOT_ENDS_WITH, + Query::TYPE_CONTAINS, + Query::TYPE_NOT_CONTAINS, + Query::TYPE_AND, + Query::TYPE_OR, + Query::TYPE_CROSSES, + Query::TYPE_NOT_CROSSES, + Query::TYPE_DISTANCE_EQUAL, + Query::TYPE_DISTANCE_NOT_EQUAL, + Query::TYPE_DISTANCE_GREATER_THAN, + Query::TYPE_DISTANCE_LESS_THAN, + Query::TYPE_INTERSECTS, + Query::TYPE_NOT_INTERSECTS, + Query::TYPE_OVERLAPS, + Query::TYPE_NOT_OVERLAPS, + Query::TYPE_TOUCHES, + Query::TYPE_NOT_TOUCHES, + Query::TYPE_VECTOR_DOT, + Query::TYPE_VECTOR_COSINE, + Query::TYPE_VECTOR_EUCLIDEAN + ]; + $config = Config::getParam('collections', []); $collections = \array_merge( @@ -87,19 +133,11 @@ class Base extends Queries $allAttributes[] = $attribute; } - $validators = [ - new Limit(), - new Offset(), - new Cursor(), - new Filter($attributes, APP_DATABASE_QUERY_MAX_VALUES), - new Order($attributes), - ]; - if ($this->isSelectQueryAllowed()) { - $validators[] = new Select($allAttributes); + $types[] = Query::TYPE_SELECT; } - parent::__construct($validators); + parent::__construct($types); } public function isSelectQueryAllowed(): bool diff --git a/src/Appwrite/Utopia/Database/Validator/Queries/Types.php b/src/Appwrite/Utopia/Database/Validator/Queries/Types.php new file mode 100644 index 0000000000..72e742d328 --- /dev/null +++ b/src/Appwrite/Utopia/Database/Validator/Queries/Types.php @@ -0,0 +1,117 @@ + + */ + protected array $types; + + /** + * @var array + */ + protected array $queries; + + /** + * @param array $types + */ + public function __construct(array $types = []) + { + $this->types = $types; + } + + /** + * Get Description. + * + * Returns validator description + * + * @return string + */ + public function getDescription(): string + { + return $this->message; + } + + /** + * @param array $value + * @return bool + */ + public function isValid($value): bool + { + try { + if (!is_array($value)) { + throw new \Exception('Queries must be an array'); + } + + var_dump($value); + + foreach ($value as $query) { + if (!$query instanceof Query) { + $query = Query::parse($query); + } + + if ($query->isNested()) { + if (!self::isValid($query->getValues())) { + throw new \Exception('Invalid queries'); + } + } + + if (!in_array($query->getMethod(), $this->types)) { + throw new \Exception("Query method {$query->getMethod()} not allowed"); + } + } + + $context = new QueryContext(); + + $validator = new DocumentsValidator($context, Database::VAR_INTEGER); + + if (!$validator->isValid($value)) { + throw new \Exception($validator->getDescription()); + } + + } catch (\Throwable $e) { + var_dump($e->getMessage()); + var_dump($e->getFile()); + var_dump($e->getLine()); + + $this->message = 'Invalid query: ' . $e->getMessage(); + return false; + } + + return true; + } + + /** + * Is array + * + * Function will return true if object is array. + * + * @return bool + */ + public function isArray(): bool + { + return true; + } + + /** + * Get Type + * + * Returns validator type. + * + * @return string + */ + public function getType(): string + { + return self::TYPE_OBJECT; + } +}