From 17251b1973da7301134e13d7739190dea29c51c2 Mon Sep 17 00:00:00 2001 From: Everly Precia Suresh Date: Tue, 25 Oct 2022 17:37:07 +0000 Subject: [PATCH 01/46] initial implementation --- app/config/collections.php | 22 +++++++++++++++++++ app/controllers/api/databases.php | 2 ++ app/workers/databases.php | 1 + .../Database/Validator/Queries/Databases.php | 3 ++- .../Utopia/Response/Model/Attribute.php | 6 +++++ src/Appwrite/Utopia/Response/Model/Index.php | 6 +++++ 6 files changed, 39 insertions(+), 1 deletion(-) diff --git a/app/config/collections.php b/app/config/collections.php index d8f65da788..00d3be12cd 100644 --- a/app/config/collections.php +++ b/app/config/collections.php @@ -263,6 +263,17 @@ $collections = [ 'array' => false, 'filters' => [], ], + [ + '$id' => ID::custom('error'), + 'type' => Database::VAR_STRING, + 'format' => '', + 'size' => 255, + 'signed' => true, + 'required' => true, + 'default' => '', + 'array' => false, + 'filters' => [], + ], [ '$id' => ID::custom('size'), 'type' => Database::VAR_INTEGER, @@ -440,6 +451,17 @@ $collections = [ 'array' => false, 'filters' => [], ], + [ + '$id' => ID::custom('error'), + 'type' => Database::VAR_STRING, + 'format' => '', + 'size' => 16, + 'signed' => true, + 'required' => true, + 'default' => '', + 'array' => false, + 'filters' => [], + ], [ '$id' => ID::custom('attributes'), 'type' => Database::VAR_STRING, diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index 19264454e0..bbe078be29 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -107,6 +107,7 @@ function createAttribute(string $databaseId, string $collectionId, Document $att 'collectionId' => $collectionId, 'type' => $type, 'status' => 'processing', // processing, available, failed, deleting, stuck + 'error' => '', 'size' => $size, 'required' => $required, 'signed' => $signed, @@ -1649,6 +1650,7 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/indexes') 'collectionInternalId' => $collection->getInternalId(), 'collectionId' => $collectionId, 'type' => $type, + 'error' => '', 'attributes' => $attributes, 'lengths' => $lengths, 'orders' => $orders, diff --git a/app/workers/databases.php b/app/workers/databases.php index 71e78b3777..79c79a69cb 100644 --- a/app/workers/databases.php +++ b/app/workers/databases.php @@ -96,6 +96,7 @@ class DatabaseV1 extends Worker throw new Exception('Failed to create Attribute'); } $dbForProject->updateDocument('attributes', $attribute->getId(), $attribute->setAttribute('status', 'available')); + // $dbForProject->updateDocument('attributes', $attribute->getId(), $attribute->setAttribute('error', 'available')); } catch (\Throwable $th) { Console::error($th->getMessage()); $dbForProject->updateDocument('attributes', $attribute->getId(), $attribute->setAttribute('status', 'failed')); diff --git a/src/Appwrite/Utopia/Database/Validator/Queries/Databases.php b/src/Appwrite/Utopia/Database/Validator/Queries/Databases.php index 22f7ad9b82..2a33a2c7ab 100644 --- a/src/Appwrite/Utopia/Database/Validator/Queries/Databases.php +++ b/src/Appwrite/Utopia/Database/Validator/Queries/Databases.php @@ -5,7 +5,8 @@ namespace Appwrite\Utopia\Database\Validator\Queries; class Databases extends Base { public const ALLOWED_ATTRIBUTES = [ - 'name' + 'name', + 'error' ]; /** diff --git a/src/Appwrite/Utopia/Response/Model/Attribute.php b/src/Appwrite/Utopia/Response/Model/Attribute.php index a05a40766e..bb9f05d1ee 100644 --- a/src/Appwrite/Utopia/Response/Model/Attribute.php +++ b/src/Appwrite/Utopia/Response/Model/Attribute.php @@ -28,6 +28,12 @@ class Attribute extends Model 'default' => '', 'example' => 'available', ]) + ->addRule('error', [ + 'type' => self::TYPE_STRING, + 'description' => 'Error message', + 'default' => '', + 'example' => 'string', + ]) ->addRule('required', [ 'type' => self::TYPE_BOOLEAN, 'description' => 'Is attribute required?', diff --git a/src/Appwrite/Utopia/Response/Model/Index.php b/src/Appwrite/Utopia/Response/Model/Index.php index b7ac626be9..7145e17e6d 100644 --- a/src/Appwrite/Utopia/Response/Model/Index.php +++ b/src/Appwrite/Utopia/Response/Model/Index.php @@ -28,6 +28,12 @@ class Index extends Model 'default' => '', 'example' => 'available', ]) + ->addRule('error', [ + 'type' => self::TYPE_STRING, + 'description' => 'Error message', + 'default' => '', + 'example' => 'string', + ]) ->addRule('attributes', [ 'type' => self::TYPE_STRING, 'description' => 'Index attributes.', From de7fee6790dc0a52945bb27f85268a7905d46284 Mon Sep 17 00:00:00 2001 From: Everly Precia Suresh Date: Tue, 25 Oct 2022 17:46:28 +0000 Subject: [PATCH 02/46] implement error msg --- app/workers/databases.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/workers/databases.php b/app/workers/databases.php index 79c79a69cb..d3a8e17b1a 100644 --- a/app/workers/databases.php +++ b/app/workers/databases.php @@ -96,10 +96,10 @@ class DatabaseV1 extends Worker throw new Exception('Failed to create Attribute'); } $dbForProject->updateDocument('attributes', $attribute->getId(), $attribute->setAttribute('status', 'available')); - // $dbForProject->updateDocument('attributes', $attribute->getId(), $attribute->setAttribute('error', 'available')); } catch (\Throwable $th) { Console::error($th->getMessage()); $dbForProject->updateDocument('attributes', $attribute->getId(), $attribute->setAttribute('status', 'failed')); + $dbForProject->updateDocument('attributes', $attribute->getId(), $attribute->setAttribute('error', $th->getMessage())); } finally { $target = Realtime::fromPayload( // Pass first, most verbose event pattern From f055e15031bdec0841371468c5288584d3667d64 Mon Sep 17 00:00:00 2001 From: Everly Precia Suresh Date: Tue, 25 Oct 2022 18:47:24 +0000 Subject: [PATCH 03/46] push changes --- app/workers/databases.php | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/app/workers/databases.php b/app/workers/databases.php index d3a8e17b1a..ef6371a5ca 100644 --- a/app/workers/databases.php +++ b/app/workers/databases.php @@ -98,8 +98,10 @@ class DatabaseV1 extends Worker $dbForProject->updateDocument('attributes', $attribute->getId(), $attribute->setAttribute('status', 'available')); } catch (\Throwable $th) { Console::error($th->getMessage()); - $dbForProject->updateDocument('attributes', $attribute->getId(), $attribute->setAttribute('status', 'failed')); - $dbForProject->updateDocument('attributes', $attribute->getId(), $attribute->setAttribute('error', $th->getMessage())); + $dbForProject->updateDocument('attributes', $attribute->getId(), + $attribute + ->setAttribute('status', 'failed') + ->setAttribute('error', $th->getMessage())); } finally { $target = Realtime::fromPayload( // Pass first, most verbose event pattern @@ -159,7 +161,11 @@ class DatabaseV1 extends Worker $dbForProject->deleteDocument('attributes', $attribute->getId()); } catch (\Throwable $th) { Console::error($th->getMessage()); - $dbForProject->updateDocument('attributes', $attribute->getId(), $attribute->setAttribute('status', 'stuck')); + $dbForProject->updateDocument('attributes', $attribute->getId(), + $attribute + ->setAttribute('status', 'stuck') + ->setAttribute('error', $th->getMessage()) + ); } finally { $target = Realtime::fromPayload( // Pass first, most verbose event pattern @@ -269,7 +275,11 @@ class DatabaseV1 extends Worker $dbForProject->updateDocument('indexes', $index->getId(), $index->setAttribute('status', 'available')); } catch (\Throwable $th) { Console::error($th->getMessage()); - $dbForProject->updateDocument('indexes', $index->getId(), $index->setAttribute('status', 'failed')); + $dbForProject->updateDocument('indexes', $index->getId(), + $index + ->setAttribute('status', 'failed') + ->setAttribute('error', $th->getMessage()) + ); } finally { $target = Realtime::fromPayload( // Pass first, most verbose event pattern @@ -322,7 +332,12 @@ class DatabaseV1 extends Worker $dbForProject->deleteDocument('indexes', $index->getId()); } catch (\Throwable $th) { Console::error($th->getMessage()); - $dbForProject->updateDocument('indexes', $index->getId(), $index->setAttribute('status', 'stuck')); + $dbForProject->updateDocument('indexes', $index->getId(), + $index + ->setAttribute('status', 'stuck') + ->setAttribute('error',$th->getMessage()) + ); + } finally { $target = Realtime::fromPayload( // Pass first, most verbose event pattern From cd0a5b73f87b6e17d003315437038220f82c99e7 Mon Sep 17 00:00:00 2001 From: Everly Precia Suresh Date: Tue, 25 Oct 2022 19:26:15 +0000 Subject: [PATCH 04/46] style:run linter --- app/workers/databases.php | 48 +++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/app/workers/databases.php b/app/workers/databases.php index ef6371a5ca..98d9c37e9e 100644 --- a/app/workers/databases.php +++ b/app/workers/databases.php @@ -98,10 +98,13 @@ class DatabaseV1 extends Worker $dbForProject->updateDocument('attributes', $attribute->getId(), $attribute->setAttribute('status', 'available')); } catch (\Throwable $th) { Console::error($th->getMessage()); - $dbForProject->updateDocument('attributes', $attribute->getId(), - $attribute - ->setAttribute('status', 'failed') - ->setAttribute('error', $th->getMessage())); + $dbForProject->updateDocument( + 'attributes', + $attribute->getId(), + $attribute + ->setAttribute('status', 'failed') + ->setAttribute('error', $th->getMessage()) + ); } finally { $target = Realtime::fromPayload( // Pass first, most verbose event pattern @@ -161,11 +164,13 @@ class DatabaseV1 extends Worker $dbForProject->deleteDocument('attributes', $attribute->getId()); } catch (\Throwable $th) { Console::error($th->getMessage()); - $dbForProject->updateDocument('attributes', $attribute->getId(), - $attribute - ->setAttribute('status', 'stuck') - ->setAttribute('error', $th->getMessage()) - ); + $dbForProject->updateDocument( + 'attributes', + $attribute->getId(), + $attribute + ->setAttribute('status', 'stuck') + ->setAttribute('error', $th->getMessage()) + ); } finally { $target = Realtime::fromPayload( // Pass first, most verbose event pattern @@ -275,11 +280,13 @@ class DatabaseV1 extends Worker $dbForProject->updateDocument('indexes', $index->getId(), $index->setAttribute('status', 'available')); } catch (\Throwable $th) { Console::error($th->getMessage()); - $dbForProject->updateDocument('indexes', $index->getId(), - $index - ->setAttribute('status', 'failed') - ->setAttribute('error', $th->getMessage()) - ); + $dbForProject->updateDocument( + 'indexes', + $index->getId(), + $index + ->setAttribute('status', 'failed') + ->setAttribute('error', $th->getMessage()) + ); } finally { $target = Realtime::fromPayload( // Pass first, most verbose event pattern @@ -332,12 +339,13 @@ class DatabaseV1 extends Worker $dbForProject->deleteDocument('indexes', $index->getId()); } catch (\Throwable $th) { Console::error($th->getMessage()); - $dbForProject->updateDocument('indexes', $index->getId(), - $index - ->setAttribute('status', 'stuck') - ->setAttribute('error',$th->getMessage()) - ); - + $dbForProject->updateDocument( + 'indexes', + $index->getId(), + $index + ->setAttribute('status', 'stuck') + ->setAttribute('error', $th->getMessage()) + ); } finally { $target = Realtime::fromPayload( // Pass first, most verbose event pattern From afc1f50a877c6bff655358acea248875d96423d6 Mon Sep 17 00:00:00 2001 From: Everly Precia Suresh Date: Tue, 25 Oct 2022 19:27:33 +0000 Subject: [PATCH 05/46] clean up code --- src/Appwrite/Utopia/Database/Validator/Queries/Databases.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Appwrite/Utopia/Database/Validator/Queries/Databases.php b/src/Appwrite/Utopia/Database/Validator/Queries/Databases.php index 2a33a2c7ab..22f7ad9b82 100644 --- a/src/Appwrite/Utopia/Database/Validator/Queries/Databases.php +++ b/src/Appwrite/Utopia/Database/Validator/Queries/Databases.php @@ -5,8 +5,7 @@ namespace Appwrite\Utopia\Database\Validator\Queries; class Databases extends Base { public const ALLOWED_ATTRIBUTES = [ - 'name', - 'error' + 'name' ]; /** From 3c8b74628db1d49ab772c095d17be5cc6819e33b Mon Sep 17 00:00:00 2001 From: Everly Precia Suresh Date: Tue, 25 Oct 2022 19:42:19 +0000 Subject: [PATCH 06/46] revert unnecessary commit --- app/config/collections.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/config/collections.php b/app/config/collections.php index 00d3be12cd..151f480cb3 100644 --- a/app/config/collections.php +++ b/app/config/collections.php @@ -455,7 +455,7 @@ $collections = [ '$id' => ID::custom('error'), 'type' => Database::VAR_STRING, 'format' => '', - 'size' => 16, + 'size' => 255, 'signed' => true, 'required' => true, 'default' => '', From 605ec8f10c851ed74882d7d88e5a058a47d3995d Mon Sep 17 00:00:00 2001 From: Everly Precia Suresh Date: Tue, 25 Oct 2022 19:48:50 +0000 Subject: [PATCH 07/46] add PR to changelog --- CHANGES.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 340aec16d4..764276390c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -3,6 +3,9 @@ ## Bugs - Fix license detection for Flutter and Dart SDKs [#4435](https://github.com/appwrite/appwrite/pull/4435) +## Features +- Add error attribute to Collection Indexes and Attributes [#4575](https://github.com/appwrite/appwrite/pull/4575) + # Version 1.0.3 ## Bugs - Fix document audit deletion [#4429](https://github.com/appwrite/appwrite/pull/4429) From ddd747a084a4bdeb0339412787749fc89709d6bf Mon Sep 17 00:00:00 2001 From: Everly Precia Suresh Date: Tue, 25 Oct 2022 19:51:08 +0000 Subject: [PATCH 08/46] add PR to changelog --- CHANGES.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 764276390c..2542fe3d14 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,11 +1,11 @@ -# Version 1.1.0 - -## Bugs -- Fix license detection for Flutter and Dart SDKs [#4435](https://github.com/appwrite/appwrite/pull/4435) - +# Unreleased Version ## Features - Add error attribute to Collection Indexes and Attributes [#4575](https://github.com/appwrite/appwrite/pull/4575) +# Version 1.1.0 +## Bugs +- Fix license detection for Flutter and Dart SDKs [#4435](https://github.com/appwrite/appwrite/pull/4435) + # Version 1.0.3 ## Bugs - Fix document audit deletion [#4429](https://github.com/appwrite/appwrite/pull/4429) From 943a334277235bfd89299603a2750d9e69359a23 Mon Sep 17 00:00:00 2001 From: Everly Precia Suresh Date: Wed, 26 Oct 2022 17:01:16 +0000 Subject: [PATCH 09/46] review comments --- app/config/collections.php | 4 ++-- src/Appwrite/Utopia/Response/Model/Attribute.php | 2 +- src/Appwrite/Utopia/Response/Model/Index.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/config/collections.php b/app/config/collections.php index 151f480cb3..fe6738c32c 100644 --- a/app/config/collections.php +++ b/app/config/collections.php @@ -267,7 +267,7 @@ $collections = [ '$id' => ID::custom('error'), 'type' => Database::VAR_STRING, 'format' => '', - 'size' => 255, + 'size' => 2048, 'signed' => true, 'required' => true, 'default' => '', @@ -455,7 +455,7 @@ $collections = [ '$id' => ID::custom('error'), 'type' => Database::VAR_STRING, 'format' => '', - 'size' => 255, + 'size' => 2048, 'signed' => true, 'required' => true, 'default' => '', diff --git a/src/Appwrite/Utopia/Response/Model/Attribute.php b/src/Appwrite/Utopia/Response/Model/Attribute.php index bb9f05d1ee..0693e697be 100644 --- a/src/Appwrite/Utopia/Response/Model/Attribute.php +++ b/src/Appwrite/Utopia/Response/Model/Attribute.php @@ -30,7 +30,7 @@ class Attribute extends Model ]) ->addRule('error', [ 'type' => self::TYPE_STRING, - 'description' => 'Error message', + 'description' => 'Error message. Displays error generated when failure of creating or deleting an attribute.', 'default' => '', 'example' => 'string', ]) diff --git a/src/Appwrite/Utopia/Response/Model/Index.php b/src/Appwrite/Utopia/Response/Model/Index.php index 7145e17e6d..55f6a3c7c2 100644 --- a/src/Appwrite/Utopia/Response/Model/Index.php +++ b/src/Appwrite/Utopia/Response/Model/Index.php @@ -30,7 +30,7 @@ class Index extends Model ]) ->addRule('error', [ 'type' => self::TYPE_STRING, - 'description' => 'Error message', + 'description' => 'Error message. Displays error generated when failure of creating or deleting an index.', 'default' => '', 'example' => 'string', ]) From 9e8dddd70d5867b03839398d34c770525f5ed16d Mon Sep 17 00:00:00 2001 From: Everly Precia Suresh Date: Thu, 3 Nov 2022 14:56:20 +0000 Subject: [PATCH 10/46] Push changes --- app/workers/databases.php | 64 +++++-- composer.json | 10 +- composer.lock | 382 +++++--------------------------------- 3 files changed, 105 insertions(+), 351 deletions(-) diff --git a/app/workers/databases.php b/app/workers/databases.php index 98d9c37e9e..5f0ebb08e6 100644 --- a/app/workers/databases.php +++ b/app/workers/databases.php @@ -5,6 +5,7 @@ use Appwrite\Messaging\Adapter\Realtime; use Appwrite\Resque\Worker; use Utopia\CLI\Console; use Utopia\Database\Document; +use Utopia\Database\Exception; require_once __DIR__ . '/../init.php'; @@ -96,15 +97,25 @@ class DatabaseV1 extends Worker throw new Exception('Failed to create Attribute'); } $dbForProject->updateDocument('attributes', $attribute->getId(), $attribute->setAttribute('status', 'available')); - } catch (\Throwable $th) { - Console::error($th->getMessage()); + } catch (Exception $e) { + Console::error($e->getMessage()); $dbForProject->updateDocument( 'attributes', $attribute->getId(), $attribute ->setAttribute('status', 'failed') - ->setAttribute('error', $th->getMessage()) + ->setAttribute('error', $e->getMessage()) ); + } + catch(\Throwable $th){ + Console::error('Internal Error'); + $dbForProject->updateDocument( + 'attributes', + $attribute->getId(), + $attribute + ->setAttribute('status', 'failed') + ->setAttribute('error', 'Internal Error') + ); } finally { $target = Realtime::fromPayload( // Pass first, most verbose event pattern @@ -162,14 +173,23 @@ class DatabaseV1 extends Worker throw new Exception('Failed to delete Attribute'); } $dbForProject->deleteDocument('attributes', $attribute->getId()); - } catch (\Throwable $th) { - Console::error($th->getMessage()); + } catch (Exception $e) { + Console::error($e->getMessage()); $dbForProject->updateDocument( 'attributes', $attribute->getId(), $attribute ->setAttribute('status', 'stuck') - ->setAttribute('error', $th->getMessage()) + ->setAttribute('error', $e->getMessage()) + ); + } catch (\Throwable $th) { + Console::error('Internal Error'); + $dbForProject->updateDocument( + 'attributes', + $attribute->getId(), + $attribute + ->setAttribute('status', 'stuck') + ->setAttribute('error', 'Internal Error') ); } finally { $target = Realtime::fromPayload( @@ -278,16 +298,25 @@ class DatabaseV1 extends Worker throw new Exception('Failed to create Index'); } $dbForProject->updateDocument('indexes', $index->getId(), $index->setAttribute('status', 'available')); - } catch (\Throwable $th) { - Console::error($th->getMessage()); + } catch (Exception $e) { + Console::error($e->getMessage()); $dbForProject->updateDocument( 'indexes', $index->getId(), $index ->setAttribute('status', 'failed') - ->setAttribute('error', $th->getMessage()) + ->setAttribute('error', $e->getMessage()) ); - } finally { + } catch (\Throwable $th) { + Console::Error('Internal Error'); + $dbForProject->updateDocument( + 'indexes', + $index->getId(), + $index + ->setAttribute('status', 'failed') + ->setAttribute('error', 'Internal Error') + ); + } finally { $target = Realtime::fromPayload( // Pass first, most verbose event pattern event: $events[0], @@ -337,14 +366,23 @@ class DatabaseV1 extends Worker throw new Exception('Failed to delete index'); } $dbForProject->deleteDocument('indexes', $index->getId()); - } catch (\Throwable $th) { - Console::error($th->getMessage()); + } catch (Exception $e) { + Console::error($e->getMessage()); $dbForProject->updateDocument( 'indexes', $index->getId(), $index ->setAttribute('status', 'stuck') - ->setAttribute('error', $th->getMessage()) + ->setAttribute('error', $e->getMessage()) + ); + } catch (\Throwable $th) { + Console::error('Internal Error'); + $dbForProject->updateDocument( + 'indexes', + $index->getId(), + $index + ->setAttribute('status', 'stuck') + ->setAttribute('error', 'Internal Error') ); } finally { $target = Realtime::fromPayload( diff --git a/composer.json b/composer.json index 47317ed5e2..07006e2acc 100644 --- a/composer.json +++ b/composer.json @@ -48,13 +48,13 @@ "utopia-php/abuse": "0.14.*", "utopia-php/analytics": "0.2.*", "utopia-php/audit": "0.15.*", - "utopia-php/cache": "0.6.*", + "utopia-php/cache": "0.8.*", "utopia-php/cli": "0.13.*", "utopia-php/config": "0.2.*", - "utopia-php/database": "0.26.*", "utopia-php/locale": "0.4.*", "utopia-php/registry": "0.5.*", "utopia-php/preloader": "0.2.*", + "utopia-php/database": "dev-add-exception-class as 0.26.0", "utopia-php/domains": "1.1.*", "utopia-php/swoole": "0.3.*", "utopia-php/storage": "0.11.*", @@ -74,7 +74,12 @@ { "url": "https://github.com/appwrite/runtimes.git", "type": "git" + }, + { + "url": "https://github.com/everly-gif/database.git", + "type": "git" } + ], "require-dev": { "appwrite/sdk-generator": "0.28.*", @@ -83,6 +88,7 @@ "squizlabs/php_codesniffer": "^3.6", "swoole/ide-helper": "4.8.9", "textalk/websocket": "1.5.7" + }, "provide": { "ext-phpiredis": "*" diff --git a/composer.lock b/composer.lock index f6f29452ad..921f8fe952 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "08fdd139ad1285b02c4b4e555679e7de", + "content-hash": "6d24385bbb3207fa44866f955a805871", "packages": [ { "name": "adhocore/jwt", @@ -345,79 +345,6 @@ }, "time": "2022-06-20T22:56:59+00:00" }, - { - "name": "composer/package-versions-deprecated", - "version": "1.11.99.5", - "source": { - "type": "git", - "url": "https://github.com/composer/package-versions-deprecated.git", - "reference": "b4f54f74ef3453349c24a845d22392cd31e65f1d" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/composer/package-versions-deprecated/zipball/b4f54f74ef3453349c24a845d22392cd31e65f1d", - "reference": "b4f54f74ef3453349c24a845d22392cd31e65f1d", - "shasum": "" - }, - "require": { - "composer-plugin-api": "^1.1.0 || ^2.0", - "php": "^7 || ^8" - }, - "replace": { - "ocramius/package-versions": "1.11.99" - }, - "require-dev": { - "composer/composer": "^1.9.3 || ^2.0@dev", - "ext-zip": "^1.13", - "phpunit/phpunit": "^6.5 || ^7" - }, - "type": "composer-plugin", - "extra": { - "class": "PackageVersions\\Installer", - "branch-alias": { - "dev-master": "1.x-dev" - } - }, - "autoload": { - "psr-4": { - "PackageVersions\\": "src/PackageVersions" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Marco Pivetta", - "email": "ocramius@gmail.com" - }, - { - "name": "Jordi Boggiano", - "email": "j.boggiano@seld.be" - } - ], - "description": "Composer plugin that provides efficient querying for installed package versions (no runtime IO)", - "support": { - "issues": "https://github.com/composer/package-versions-deprecated/issues", - "source": "https://github.com/composer/package-versions-deprecated/tree/1.11.99.5" - }, - "funding": [ - { - "url": "https://packagist.com", - "type": "custom" - }, - { - "url": "https://github.com/composer", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/composer/composer", - "type": "tidelift" - } - ], - "time": "2022-01-17T14:14:24+00:00" - }, { "name": "dragonmantank/cron-expression", "version": "v3.3.1", @@ -693,16 +620,16 @@ }, { "name": "guzzlehttp/psr7", - "version": "2.4.1", + "version": "2.4.3", "source": { "type": "git", "url": "https://github.com/guzzle/psr7.git", - "reference": "69568e4293f4fa993f3b0e51c9723e1e17c41379" + "reference": "67c26b443f348a51926030c83481b85718457d3d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/psr7/zipball/69568e4293f4fa993f3b0e51c9723e1e17c41379", - "reference": "69568e4293f4fa993f3b0e51c9723e1e17c41379", + "url": "https://api.github.com/repos/guzzle/psr7/zipball/67c26b443f348a51926030c83481b85718457d3d", + "reference": "67c26b443f348a51926030c83481b85718457d3d", "shasum": "" }, "require": { @@ -792,7 +719,7 @@ ], "support": { "issues": "https://github.com/guzzle/psr7/issues", - "source": "https://github.com/guzzle/psr7/tree/2.4.1" + "source": "https://github.com/guzzle/psr7/tree/2.4.3" }, "funding": [ { @@ -808,7 +735,7 @@ "type": "tidelift" } ], - "time": "2022-08-28T14:45:39+00:00" + "time": "2022-10-26T14:07:24+00:00" }, { "name": "influxdb/influxdb-php", @@ -876,61 +803,6 @@ }, "time": "2020-12-26T17:45:17+00:00" }, - { - "name": "jean85/pretty-package-versions", - "version": "1.6.0", - "source": { - "type": "git", - "url": "https://github.com/Jean85/pretty-package-versions.git", - "reference": "1e0104b46f045868f11942aea058cd7186d6c303" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/Jean85/pretty-package-versions/zipball/1e0104b46f045868f11942aea058cd7186d6c303", - "reference": "1e0104b46f045868f11942aea058cd7186d6c303", - "shasum": "" - }, - "require": { - "composer/package-versions-deprecated": "^1.8.0", - "php": "^7.0|^8.0" - }, - "require-dev": { - "phpunit/phpunit": "^6.0|^8.5|^9.2" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.x-dev" - } - }, - "autoload": { - "psr-4": { - "Jean85\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Alessandro Lai", - "email": "alessandro.lai85@gmail.com" - } - ], - "description": "A wrapper for ocramius/package-versions to get pretty versions strings", - "keywords": [ - "composer", - "package", - "release", - "versions" - ], - "support": { - "issues": "https://github.com/Jean85/pretty-package-versions/issues", - "source": "https://github.com/Jean85/pretty-package-versions/tree/1.6.0" - }, - "time": "2021-02-04T16:20:16+00:00" - }, { "name": "matomo/device-detector", "version": "6.0.0", @@ -1000,74 +872,6 @@ }, "time": "2022-04-11T09:58:17+00:00" }, - { - "name": "mongodb/mongodb", - "version": "1.8.0", - "source": { - "type": "git", - "url": "https://github.com/mongodb/mongo-php-library.git", - "reference": "953dbc19443aa9314c44b7217a16873347e6840d" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/mongodb/mongo-php-library/zipball/953dbc19443aa9314c44b7217a16873347e6840d", - "reference": "953dbc19443aa9314c44b7217a16873347e6840d", - "shasum": "" - }, - "require": { - "ext-hash": "*", - "ext-json": "*", - "ext-mongodb": "^1.8.1", - "jean85/pretty-package-versions": "^1.2", - "php": "^7.0 || ^8.0", - "symfony/polyfill-php80": "^1.19" - }, - "require-dev": { - "squizlabs/php_codesniffer": "^3.5, <3.5.5", - "symfony/phpunit-bridge": "5.x-dev" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.8.x-dev" - } - }, - "autoload": { - "files": [ - "src/functions.php" - ], - "psr-4": { - "MongoDB\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "Apache-2.0" - ], - "authors": [ - { - "name": "Andreas Braun", - "email": "andreas.braun@mongodb.com" - }, - { - "name": "Jeremy Mikola", - "email": "jmikola@gmail.com" - } - ], - "description": "MongoDB driver library", - "homepage": "https://jira.mongodb.org/browse/PHPLIB", - "keywords": [ - "database", - "driver", - "mongodb", - "persistence" - ], - "support": { - "issues": "https://github.com/mongodb/mongo-php-library/issues", - "source": "https://github.com/mongodb/mongo-php-library/tree/1.8.0" - }, - "time": "2020-11-25T12:26:02+00:00" - }, { "name": "mustangostang/spyc", "version": "0.6.3", @@ -1656,89 +1460,6 @@ ], "time": "2022-02-25T11:15:52+00:00" }, - { - "name": "symfony/polyfill-php80", - "version": "v1.26.0", - "source": { - "type": "git", - "url": "https://github.com/symfony/polyfill-php80.git", - "reference": "cfa0ae98841b9e461207c13ab093d76b0fa7bace" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/cfa0ae98841b9e461207c13ab093d76b0fa7bace", - "reference": "cfa0ae98841b9e461207c13ab093d76b0fa7bace", - "shasum": "" - }, - "require": { - "php": ">=7.1" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "1.26-dev" - }, - "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" - } - }, - "autoload": { - "files": [ - "bootstrap.php" - ], - "psr-4": { - "Symfony\\Polyfill\\Php80\\": "" - }, - "classmap": [ - "Resources/stubs" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Ion Bazan", - "email": "ion.bazan@gmail.com" - }, - { - "name": "Nicolas Grekas", - "email": "p@tchwork.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions", - "homepage": "https://symfony.com", - "keywords": [ - "compatibility", - "polyfill", - "portable", - "shim" - ], - "support": { - "source": "https://github.com/symfony/polyfill-php80/tree/v1.26.0" - }, - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2022-05-10T07:21:04+00:00" - }, { "name": "utopia-php/abuse", "version": "0.14.0", @@ -1897,24 +1618,26 @@ }, { "name": "utopia-php/cache", - "version": "0.6.1", + "version": "0.8.0", "source": { "type": "git", "url": "https://github.com/utopia-php/cache.git", - "reference": "9889235a6d3da6cbb1f435201529da4d27c30e79" + "reference": "212e66100a1f32e674fca5d9bc317cc998303089" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/cache/zipball/9889235a6d3da6cbb1f435201529da4d27c30e79", - "reference": "9889235a6d3da6cbb1f435201529da4d27c30e79", + "url": "https://api.github.com/repos/utopia-php/cache/zipball/212e66100a1f32e674fca5d9bc317cc998303089", + "reference": "212e66100a1f32e674fca5d9bc317cc998303089", "shasum": "" }, "require": { "ext-json": "*", + "ext-memcached": "*", "ext-redis": "*", "php": ">=8.0" }, "require-dev": { + "laravel/pint": "1.2.*", "phpunit/phpunit": "^9.3", "vimeo/psalm": "4.13.1" }, @@ -1928,12 +1651,6 @@ "license": [ "MIT" ], - "authors": [ - { - "name": "Eldad Fux", - "email": "eldad@appwrite.io" - } - ], "description": "A simple cache library to manage application cache storing, loading and purging", "keywords": [ "cache", @@ -1944,9 +1661,9 @@ ], "support": { "issues": "https://github.com/utopia-php/cache/issues", - "source": "https://github.com/utopia-php/cache/tree/0.6.1" + "source": "https://github.com/utopia-php/cache/tree/0.8.0" }, - "time": "2022-08-10T08:12:46+00:00" + "time": "2022-10-16T16:48:09+00:00" }, { "name": "utopia-php/cli", @@ -2054,29 +1771,23 @@ }, { "name": "utopia-php/database", - "version": "0.26.0", + "version": "dev-add-exception-class", "source": { "type": "git", - "url": "https://github.com/utopia-php/database.git", - "reference": "d172af2541137c83a86d066f82f48914b5a3a610" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/d172af2541137c83a86d066f82f48914b5a3a610", - "reference": "d172af2541137c83a86d066f82f48914b5a3a610", - "shasum": "" + "url": "https://github.com/everly-gif/database.git", + "reference": "e0b91278e8ce9644ec0504f466a90f59a75d2653" }, "require": { - "ext-mongodb": "*", - "ext-pdo": "*", - "ext-redis": "*", - "mongodb/mongodb": "1.8.0", "php": ">=8.0", - "utopia-php/cache": "0.6.*", + "utopia-php/cache": "0.8.*", "utopia-php/framework": "0.*.*" }, "require-dev": { + "ext-mongodb": "*", + "ext-pdo": "*", + "ext-redis": "*", "fakerphp/faker": "^1.14", + "mongodb/mongodb": "1.8.0", "phpunit/phpunit": "^9.4", "swoole/ide-helper": "4.8.0", "utopia-php/cli": "^0.11.0", @@ -2088,20 +1799,14 @@ "Utopia\\Database\\": "src/Database" } }, - "notification-url": "https://packagist.org/downloads/", + "autoload-dev": { + "psr-4": { + "Utopia\\Tests\\": "tests/Database" + } + }, "license": [ "MIT" ], - "authors": [ - { - "name": "Eldad Fux", - "email": "eldad@appwrite.io" - }, - { - "name": "Brandon Leckemby", - "email": "brandon@appwrite.io" - } - ], "description": "A simple library to manage application persistency using multiple database adapters", "keywords": [ "database", @@ -2110,11 +1815,7 @@ "upf", "utopia" ], - "support": { - "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/0.26.0" - }, - "time": "2022-10-03T17:12:01+00:00" + "time": "2022-11-01T19:45:41+00:00" }, { "name": "utopia-php/domains", @@ -3535,16 +3236,16 @@ }, { "name": "phpunit/php-code-coverage", - "version": "9.2.17", + "version": "9.2.18", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "aa94dc41e8661fe90c7316849907cba3007b10d8" + "reference": "12fddc491826940cf9b7e88ad9664cf51f0f6d0a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/aa94dc41e8661fe90c7316849907cba3007b10d8", - "reference": "aa94dc41e8661fe90c7316849907cba3007b10d8", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/12fddc491826940cf9b7e88ad9664cf51f0f6d0a", + "reference": "12fddc491826940cf9b7e88ad9664cf51f0f6d0a", "shasum": "" }, "require": { @@ -3600,7 +3301,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", - "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.17" + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.18" }, "funding": [ { @@ -3608,7 +3309,7 @@ "type": "github" } ], - "time": "2022-08-30T12:24:04+00:00" + "time": "2022-10-27T13:35:33+00:00" }, { "name": "phpunit/php-file-iterator", @@ -5357,9 +5058,18 @@ "time": "2022-09-28T08:42:51+00:00" } ], - "aliases": [], + "aliases": [ + { + "package": "utopia-php/database", + "version": "dev-add-exception-class", + "alias": "0.26.0", + "alias_normalized": "0.26.0.0" + } + ], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": { + "utopia-php/database": 20 + }, "prefer-stable": false, "prefer-lowest": false, "platform": { From eece18c9f694efa0d8d35cce922c704afe626b01 Mon Sep 17 00:00:00 2001 From: Everly Precia Suresh Date: Thu, 3 Nov 2022 16:10:39 +0000 Subject: [PATCH 11/46] style:run linter --- app/workers/databases.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/workers/databases.php b/app/workers/databases.php index 5f0ebb08e6..e017855c57 100644 --- a/app/workers/databases.php +++ b/app/workers/databases.php @@ -106,8 +106,7 @@ class DatabaseV1 extends Worker ->setAttribute('status', 'failed') ->setAttribute('error', $e->getMessage()) ); - } - catch(\Throwable $th){ + } catch (\Throwable $th) { Console::error('Internal Error'); $dbForProject->updateDocument( 'attributes', @@ -316,7 +315,7 @@ class DatabaseV1 extends Worker ->setAttribute('status', 'failed') ->setAttribute('error', 'Internal Error') ); - } finally { + } finally { $target = Realtime::fromPayload( // Pass first, most verbose event pattern event: $events[0], From b011f931c5f1a23773723bc2d550e150f50ae1c0 Mon Sep 17 00:00:00 2001 From: Everly Precia Suresh Date: Mon, 7 Nov 2022 19:38:06 +0000 Subject: [PATCH 12/46] change grammar --- src/Appwrite/Utopia/Response/Model/Attribute.php | 2 +- src/Appwrite/Utopia/Response/Model/Index.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Appwrite/Utopia/Response/Model/Attribute.php b/src/Appwrite/Utopia/Response/Model/Attribute.php index 0693e697be..9f9ceca317 100644 --- a/src/Appwrite/Utopia/Response/Model/Attribute.php +++ b/src/Appwrite/Utopia/Response/Model/Attribute.php @@ -30,7 +30,7 @@ class Attribute extends Model ]) ->addRule('error', [ 'type' => self::TYPE_STRING, - 'description' => 'Error message. Displays error generated when failure of creating or deleting an attribute.', + 'description' => 'Error message. Displays error generated on failure of creating or deleting an attribute.', 'default' => '', 'example' => 'string', ]) diff --git a/src/Appwrite/Utopia/Response/Model/Index.php b/src/Appwrite/Utopia/Response/Model/Index.php index 55f6a3c7c2..3d3d1a3b52 100644 --- a/src/Appwrite/Utopia/Response/Model/Index.php +++ b/src/Appwrite/Utopia/Response/Model/Index.php @@ -30,7 +30,7 @@ class Index extends Model ]) ->addRule('error', [ 'type' => self::TYPE_STRING, - 'description' => 'Error message. Displays error generated when failure of creating or deleting an index.', + 'description' => 'Error message. Displays error generated on failure of creating or deleting an index.', 'default' => '', 'example' => 'string', ]) From 13ea6a5e6928f2802d2c1887fcf08f80ce54d7cf Mon Sep 17 00:00:00 2001 From: Everly Precia Suresh Date: Tue, 8 Nov 2022 17:06:50 +0000 Subject: [PATCH 13/46] update error attribute --- app/workers/databases.php | 43 ++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/app/workers/databases.php b/app/workers/databases.php index e017855c57..00b938d20a 100644 --- a/app/workers/databases.php +++ b/app/workers/databases.php @@ -5,7 +5,8 @@ use Appwrite\Messaging\Adapter\Realtime; use Appwrite\Resque\Worker; use Utopia\CLI\Console; use Utopia\Database\Document; -use Utopia\Database\Exception; +use Exception; +use Utopia\Database\Exception as DatabaseException; require_once __DIR__ . '/../init.php'; @@ -27,11 +28,11 @@ class DatabaseV1 extends Worker $database = new Document($this->args['database'] ?? []); if ($collection->isEmpty()) { - throw new Exception('Missing collection'); + throw new DatabaseException('Missing collection'); } if ($document->isEmpty()) { - throw new Exception('Missing document'); + throw new DatabaseException('Missing document'); } switch (strval($type)) { @@ -94,10 +95,10 @@ class DatabaseV1 extends Worker try { if (!$dbForProject->createAttribute('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), $key, $type, $size, $required, $default, $signed, $array, $format, $formatOptions, $filters)) { - throw new Exception('Failed to create Attribute'); + throw new DatabaseException('Failed to create Attribute'); } $dbForProject->updateDocument('attributes', $attribute->getId(), $attribute->setAttribute('status', 'available')); - } catch (Exception $e) { + } catch (DatabaseException $e) { Console::error($e->getMessage()); $dbForProject->updateDocument( 'attributes', @@ -106,14 +107,13 @@ class DatabaseV1 extends Worker ->setAttribute('status', 'failed') ->setAttribute('error', $e->getMessage()) ); - } catch (\Throwable $th) { - Console::error('Internal Error'); + } catch (Exception $e) { $dbForProject->updateDocument( 'attributes', $attribute->getId(), $attribute ->setAttribute('status', 'failed') - ->setAttribute('error', 'Internal Error') + ->setAttribute('error', '') ); } finally { $target = Realtime::fromPayload( @@ -169,10 +169,10 @@ class DatabaseV1 extends Worker // - stuck: attribute was available but cannot be removed try { if ($status !== 'failed' && !$dbForProject->deleteAttribute('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), $key)) { - throw new Exception('Failed to delete Attribute'); + throw new DatabaseException('Failed to delete Attribute'); } $dbForProject->deleteDocument('attributes', $attribute->getId()); - } catch (Exception $e) { + } catch (DatabaseException $e) { Console::error($e->getMessage()); $dbForProject->updateDocument( 'attributes', @@ -181,14 +181,13 @@ class DatabaseV1 extends Worker ->setAttribute('status', 'stuck') ->setAttribute('error', $e->getMessage()) ); - } catch (\Throwable $th) { - Console::error('Internal Error'); + } catch (Exception $e) { $dbForProject->updateDocument( 'attributes', $attribute->getId(), $attribute ->setAttribute('status', 'stuck') - ->setAttribute('error', 'Internal Error') + ->setAttribute('error', '') ); } finally { $target = Realtime::fromPayload( @@ -294,10 +293,10 @@ class DatabaseV1 extends Worker try { if (!$dbForProject->createIndex('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), $key, $type, $attributes, $lengths, $orders)) { - throw new Exception('Failed to create Index'); + throw new DatabaseException('Failed to create Index'); } $dbForProject->updateDocument('indexes', $index->getId(), $index->setAttribute('status', 'available')); - } catch (Exception $e) { + } catch (DatabaseException $e) { Console::error($e->getMessage()); $dbForProject->updateDocument( 'indexes', @@ -306,14 +305,13 @@ class DatabaseV1 extends Worker ->setAttribute('status', 'failed') ->setAttribute('error', $e->getMessage()) ); - } catch (\Throwable $th) { - Console::Error('Internal Error'); + } catch (Exception $e) { $dbForProject->updateDocument( 'indexes', $index->getId(), $index ->setAttribute('status', 'failed') - ->setAttribute('error', 'Internal Error') + ->setAttribute('error', '') ); } finally { $target = Realtime::fromPayload( @@ -362,10 +360,10 @@ class DatabaseV1 extends Worker try { if ($status !== 'failed' && !$dbForProject->deleteIndex('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), $key)) { - throw new Exception('Failed to delete index'); + throw new DatabaseException('Failed to delete index'); } $dbForProject->deleteDocument('indexes', $index->getId()); - } catch (Exception $e) { + } catch (DatabaseException $e) { Console::error($e->getMessage()); $dbForProject->updateDocument( 'indexes', @@ -374,14 +372,13 @@ class DatabaseV1 extends Worker ->setAttribute('status', 'stuck') ->setAttribute('error', $e->getMessage()) ); - } catch (\Throwable $th) { - Console::error('Internal Error'); + } catch (Exception $e) { $dbForProject->updateDocument( 'indexes', $index->getId(), $index ->setAttribute('status', 'stuck') - ->setAttribute('error', 'Internal Error') + ->setAttribute('error', '') ); } finally { $target = Realtime::fromPayload( From 9dcf4c098476764dbda2c56f5959f7c824101918 Mon Sep 17 00:00:00 2001 From: fogelito Date: Tue, 25 Apr 2023 14:35:49 +0300 Subject: [PATCH 14/46] validations changes --- app/controllers/api/account.php | 6 +- app/controllers/api/databases.php | 6 +- app/controllers/api/teams.php | 6 +- app/controllers/api/users.php | 6 +- composer.json | 2 +- composer.lock | 112 ++++---- .../Database/Validator/IndexedQueries.php | 111 -------- .../Utopia/Database/Validator/Queries.php | 135 ---------- .../Database/Validator/Queries/Base.php | 14 +- .../Database/Validator/Queries/Document.php | 4 +- .../Database/Validator/Queries/Documents.php | 14 +- .../Utopia/Database/Validator/Query/Base.php | 62 ----- .../Database/Validator/Query/Cursor.php | 44 ---- .../Database/Validator/Query/Filter.php | 141 ---------- .../Utopia/Database/Validator/Query/Limit.php | 61 ----- .../Database/Validator/Query/Offset.php | 60 ----- .../Utopia/Database/Validator/Query/Order.php | 68 ----- .../Database/Validator/Query/Select.php | 60 ----- .../Database/Validator/IndexedQueriesTest.php | 240 +++++++++--------- .../Utopia/Database/Validator/QueriesTest.php | 150 +++++------ .../Database/Validator/Query/CursorTest.php | 80 +++--- .../Database/Validator/Query/FilterTest.php | 126 ++++----- .../Database/Validator/Query/LimitTest.php | 72 +++--- .../Database/Validator/Query/OffsetTest.php | 80 +++--- .../Database/Validator/Query/OrderTest.php | 108 ++++---- .../Database/Validator/Query/SelectTest.php | 88 +++---- 26 files changed, 560 insertions(+), 1296 deletions(-) delete mode 100644 src/Appwrite/Utopia/Database/Validator/IndexedQueries.php delete mode 100644 src/Appwrite/Utopia/Database/Validator/Queries.php delete mode 100644 src/Appwrite/Utopia/Database/Validator/Query/Base.php delete mode 100644 src/Appwrite/Utopia/Database/Validator/Query/Cursor.php delete mode 100644 src/Appwrite/Utopia/Database/Validator/Query/Filter.php delete mode 100644 src/Appwrite/Utopia/Database/Validator/Query/Limit.php delete mode 100644 src/Appwrite/Utopia/Database/Validator/Query/Offset.php delete mode 100644 src/Appwrite/Utopia/Database/Validator/Query/Order.php delete mode 100644 src/Appwrite/Utopia/Database/Validator/Query/Select.php diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index dd5ac4a2da..2eb02c4b2e 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -16,9 +16,9 @@ use Appwrite\OpenSSL\OpenSSL; use Appwrite\Template\Template; use Appwrite\URL\URL as URLParser; use Appwrite\Utopia\Database\Validator\CustomId; -use Appwrite\Utopia\Database\Validator\Queries; -use Appwrite\Utopia\Database\Validator\Query\Limit; -use Appwrite\Utopia\Database\Validator\Query\Offset; +use Utopia\Database\Validator\Queries; +use Utopia\Database\Validator\Query\Limit; +use Utopia\Database\Validator\Query\Offset; use Appwrite\Utopia\Request; use Appwrite\Utopia\Response; use MaxMind\Db\Reader; diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index b309b74894..28caa9c3b2 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -37,13 +37,13 @@ use Appwrite\Network\Validator\Email; use Utopia\Validator\IP; use Utopia\Validator\URL; use Appwrite\Utopia\Database\Validator\CustomId; -use Appwrite\Utopia\Database\Validator\Query\Limit; -use Appwrite\Utopia\Database\Validator\Query\Offset; +use Utopia\Database\Validator\Query\Limit; +use Utopia\Database\Validator\Query\Offset; use Appwrite\Utopia\Response; use Appwrite\Detector\Detector; use Appwrite\Event\Database as EventDatabase; use Appwrite\Event\Event; -use Appwrite\Utopia\Database\Validator\Queries; +use Utopia\Database\Validator\Queries; use Appwrite\Utopia\Database\Validator\Queries\Collections; use Appwrite\Utopia\Database\Validator\Queries\Databases; use Appwrite\Utopia\Database\Validator\Queries\Document as DocumentValidator; diff --git a/app/controllers/api/teams.php b/app/controllers/api/teams.php index 338af70406..4f64a65752 100644 --- a/app/controllers/api/teams.php +++ b/app/controllers/api/teams.php @@ -12,11 +12,11 @@ use Appwrite\Network\Validator\Email; use Utopia\Validator\Host; use Appwrite\Template\Template; use Appwrite\Utopia\Database\Validator\CustomId; -use Appwrite\Utopia\Database\Validator\Queries; +use Utopia\Database\Validator\Queries; use Appwrite\Utopia\Database\Validator\Queries\Memberships; use Appwrite\Utopia\Database\Validator\Queries\Teams; -use Appwrite\Utopia\Database\Validator\Query\Limit; -use Appwrite\Utopia\Database\Validator\Query\Offset; +use Utopia\Database\Validator\Query\Limit; +use Utopia\Database\Validator\Query\Offset; use Appwrite\Utopia\Request; use Appwrite\Utopia\Response; use MaxMind\Db\Reader; diff --git a/app/controllers/api/users.php b/app/controllers/api/users.php index ceed901a32..72a351d97c 100644 --- a/app/controllers/api/users.php +++ b/app/controllers/api/users.php @@ -8,10 +8,10 @@ use Appwrite\Event\Delete; use Appwrite\Event\Event; use Appwrite\Network\Validator\Email; use Appwrite\Utopia\Database\Validator\CustomId; -use Appwrite\Utopia\Database\Validator\Queries; +use Utopia\Database\Validator\Queries; use Appwrite\Utopia\Database\Validator\Queries\Users; -use Appwrite\Utopia\Database\Validator\Query\Limit; -use Appwrite\Utopia\Database\Validator\Query\Offset; +use Utopia\Database\Validator\Query\Limit; +use Utopia\Database\Validator\Query\Offset; use Appwrite\Utopia\Response; use Utopia\App; use Utopia\Audit\Audit; diff --git a/composer.json b/composer.json index fdd5df4535..3d08bdd4a2 100644 --- a/composer.json +++ b/composer.json @@ -49,7 +49,7 @@ "utopia-php/cache": "0.8.*", "utopia-php/cli": "0.13.*", "utopia-php/config": "0.2.*", - "utopia-php/database": "0.35.*", + "utopia-php/database": "dev-appwrite-validators as 0.35.0", "utopia-php/domains": "1.1.*", "utopia-php/framework": "0.28.*", "utopia-php/image": "0.5.*", diff --git a/composer.lock b/composer.lock index 2d402ddb31..e71d901cfb 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "87de4ea3130e576470a63b21628e30fb", + "content-hash": "d17652f4b2ab219da983b0ff3f5456d9", "packages": [ { "name": "adhocore/jwt", @@ -300,16 +300,16 @@ }, { "name": "colinmollenhour/credis", - "version": "v1.14.0", + "version": "v1.15.0", "source": { "type": "git", "url": "https://github.com/colinmollenhour/credis.git", - "reference": "dccc8a46586475075fbb012d8bd523b8a938c2dc" + "reference": "28810439de1d9597b7ba11794ed9479fb6f3de7c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/colinmollenhour/credis/zipball/dccc8a46586475075fbb012d8bd523b8a938c2dc", - "reference": "dccc8a46586475075fbb012d8bd523b8a938c2dc", + "url": "https://api.github.com/repos/colinmollenhour/credis/zipball/28810439de1d9597b7ba11794ed9479fb6f3de7c", + "reference": "28810439de1d9597b7ba11794ed9479fb6f3de7c", "shasum": "" }, "require": { @@ -341,9 +341,9 @@ "homepage": "https://github.com/colinmollenhour/credis", "support": { "issues": "https://github.com/colinmollenhour/credis/issues", - "source": "https://github.com/colinmollenhour/credis/tree/v1.14.0" + "source": "https://github.com/colinmollenhour/credis/tree/v1.15.0" }, - "time": "2022-11-09T01:18:39+00:00" + "time": "2023-04-18T15:34:23+00:00" }, { "name": "composer/package-versions-deprecated", @@ -481,22 +481,22 @@ }, { "name": "guzzlehttp/guzzle", - "version": "7.5.0", + "version": "7.5.1", "source": { "type": "git", "url": "https://github.com/guzzle/guzzle.git", - "reference": "b50a2a1251152e43f6a37f0fa053e730a67d25ba" + "reference": "b964ca597e86b752cd994f27293e9fa6b6a95ed9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/guzzle/zipball/b50a2a1251152e43f6a37f0fa053e730a67d25ba", - "reference": "b50a2a1251152e43f6a37f0fa053e730a67d25ba", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/b964ca597e86b752cd994f27293e9fa6b6a95ed9", + "reference": "b964ca597e86b752cd994f27293e9fa6b6a95ed9", "shasum": "" }, "require": { "ext-json": "*", "guzzlehttp/promises": "^1.5", - "guzzlehttp/psr7": "^1.9 || ^2.4", + "guzzlehttp/psr7": "^1.9.1 || ^2.4.5", "php": "^7.2.5 || ^8.0", "psr/http-client": "^1.0", "symfony/deprecation-contracts": "^2.2 || ^3.0" @@ -589,7 +589,7 @@ ], "support": { "issues": "https://github.com/guzzle/guzzle/issues", - "source": "https://github.com/guzzle/guzzle/tree/7.5.0" + "source": "https://github.com/guzzle/guzzle/tree/7.5.1" }, "funding": [ { @@ -605,7 +605,7 @@ "type": "tidelift" } ], - "time": "2022-08-28T15:39:27+00:00" + "time": "2023-04-17T16:30:08+00:00" }, { "name": "guzzlehttp/promises", @@ -693,22 +693,22 @@ }, { "name": "guzzlehttp/psr7", - "version": "2.4.4", + "version": "2.5.0", "source": { "type": "git", "url": "https://github.com/guzzle/psr7.git", - "reference": "3cf1b6d4f0c820a2cf8bcaec39fc698f3443b5cf" + "reference": "b635f279edd83fc275f822a1188157ffea568ff6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/psr7/zipball/3cf1b6d4f0c820a2cf8bcaec39fc698f3443b5cf", - "reference": "3cf1b6d4f0c820a2cf8bcaec39fc698f3443b5cf", + "url": "https://api.github.com/repos/guzzle/psr7/zipball/b635f279edd83fc275f822a1188157ffea568ff6", + "reference": "b635f279edd83fc275f822a1188157ffea568ff6", "shasum": "" }, "require": { "php": "^7.2.5 || ^8.0", "psr/http-factory": "^1.0", - "psr/http-message": "^1.0", + "psr/http-message": "^1.1 || ^2.0", "ralouphie/getallheaders": "^3.0" }, "provide": { @@ -728,9 +728,6 @@ "bamarni-bin": { "bin-links": true, "forward-command": false - }, - "branch-alias": { - "dev-master": "2.4-dev" } }, "autoload": { @@ -792,7 +789,7 @@ ], "support": { "issues": "https://github.com/guzzle/psr7/issues", - "source": "https://github.com/guzzle/psr7/tree/2.4.4" + "source": "https://github.com/guzzle/psr7/tree/2.5.0" }, "funding": [ { @@ -808,7 +805,7 @@ "type": "tidelift" } ], - "time": "2023-03-09T13:19:02+00:00" + "time": "2023-04-17T16:11:26+00:00" }, { "name": "influxdb/influxdb-php", @@ -1372,16 +1369,16 @@ }, { "name": "psr/http-message", - "version": "1.1", + "version": "2.0", "source": { "type": "git", "url": "https://github.com/php-fig/http-message.git", - "reference": "cb6ce4845ce34a8ad9e68117c10ee90a29919eba" + "reference": "402d35bcb92c70c026d1a6a9883f06b2ead23d71" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-fig/http-message/zipball/cb6ce4845ce34a8ad9e68117c10ee90a29919eba", - "reference": "cb6ce4845ce34a8ad9e68117c10ee90a29919eba", + "url": "https://api.github.com/repos/php-fig/http-message/zipball/402d35bcb92c70c026d1a6a9883f06b2ead23d71", + "reference": "402d35bcb92c70c026d1a6a9883f06b2ead23d71", "shasum": "" }, "require": { @@ -1390,7 +1387,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.1.x-dev" + "dev-master": "2.0.x-dev" } }, "autoload": { @@ -1405,7 +1402,7 @@ "authors": [ { "name": "PHP-FIG", - "homepage": "http://www.php-fig.org/" + "homepage": "https://www.php-fig.org/" } ], "description": "Common interface for HTTP messages", @@ -1419,9 +1416,9 @@ "response" ], "support": { - "source": "https://github.com/php-fig/http-message/tree/1.1" + "source": "https://github.com/php-fig/http-message/tree/2.0" }, - "time": "2023-04-04T09:50:52+00:00" + "time": "2023-04-04T09:54:51+00:00" }, { "name": "psr/log", @@ -2112,16 +2109,16 @@ }, { "name": "utopia-php/database", - "version": "0.35.0", + "version": "dev-appwrite-validators", "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "f162c142fd61753c4b413b15c3c4041f3cd00bb2" + "reference": "00f473bff5f70a86be11519bdb0eca61af740f2a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/f162c142fd61753c4b413b15c3c4041f3cd00bb2", - "reference": "f162c142fd61753c4b413b15c3c4041f3cd00bb2", + "url": "https://api.github.com/repos/utopia-php/database/zipball/00f473bff5f70a86be11519bdb0eca61af740f2a", + "reference": "00f473bff5f70a86be11519bdb0eca61af740f2a", "shasum": "" }, "require": { @@ -2164,9 +2161,9 @@ ], "support": { "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/0.35.0" + "source": "https://github.com/utopia-php/database/tree/appwrite-validators" }, - "time": "2023-04-11T04:02:22+00:00" + "time": "2023-04-25T09:59:20+00:00" }, { "name": "utopia-php/domains", @@ -3037,16 +3034,16 @@ "packages-dev": [ { "name": "appwrite/sdk-generator", - "version": "0.32.1", + "version": "0.32.2", "source": { "type": "git", "url": "https://github.com/appwrite/sdk-generator.git", - "reference": "ba1d7afd57e3baef06c04ce6abc26f79310146df" + "reference": "cdec289bcf38c99d0074414d2438e9967d0c9699" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/ba1d7afd57e3baef06c04ce6abc26f79310146df", - "reference": "ba1d7afd57e3baef06c04ce6abc26f79310146df", + "url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/cdec289bcf38c99d0074414d2438e9967d0c9699", + "reference": "cdec289bcf38c99d0074414d2438e9967d0c9699", "shasum": "" }, "require": { @@ -3082,9 +3079,9 @@ "description": "Appwrite PHP library for generating API SDKs for multiple programming languages and platforms", "support": { "issues": "https://github.com/appwrite/sdk-generator/issues", - "source": "https://github.com/appwrite/sdk-generator/tree/0.32.1" + "source": "https://github.com/appwrite/sdk-generator/tree/0.32.2" }, - "time": "2023-04-12T04:43:07+00:00" + "time": "2023-04-12T21:06:57+00:00" }, { "name": "doctrine/deprecations", @@ -3787,16 +3784,16 @@ }, { "name": "phpstan/phpdoc-parser", - "version": "1.18.1", + "version": "1.20.3", "source": { "type": "git", "url": "https://github.com/phpstan/phpdoc-parser.git", - "reference": "22dcdfd725ddf99583bfe398fc624ad6c5004a0f" + "reference": "6c04009f6cae6eda2f040745b6b846080ef069c2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/22dcdfd725ddf99583bfe398fc624ad6c5004a0f", - "reference": "22dcdfd725ddf99583bfe398fc624ad6c5004a0f", + "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/6c04009f6cae6eda2f040745b6b846080ef069c2", + "reference": "6c04009f6cae6eda2f040745b6b846080ef069c2", "shasum": "" }, "require": { @@ -3826,9 +3823,9 @@ "description": "PHPDoc parser with support for nullable, intersection and generic types", "support": { "issues": "https://github.com/phpstan/phpdoc-parser/issues", - "source": "https://github.com/phpstan/phpdoc-parser/tree/1.18.1" + "source": "https://github.com/phpstan/phpdoc-parser/tree/1.20.3" }, - "time": "2023-04-07T11:51:11+00:00" + "time": "2023-04-25T09:01:03+00:00" }, { "name": "phpunit/php-code-coverage", @@ -5655,9 +5652,18 @@ "time": "2023-02-08T07:49:20+00:00" } ], - "aliases": [], + "aliases": [ + { + "package": "utopia-php/database", + "version": "dev-appwrite-validators", + "alias": "0.35.0", + "alias_normalized": "0.35.0.0" + } + ], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": { + "utopia-php/database": 20 + }, "prefer-stable": false, "prefer-lowest": false, "platform": { @@ -5681,5 +5687,5 @@ "platform-overrides": { "php": "8.0" }, - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.2.0" } diff --git a/src/Appwrite/Utopia/Database/Validator/IndexedQueries.php b/src/Appwrite/Utopia/Database/Validator/IndexedQueries.php deleted file mode 100644 index f247bb7e4f..0000000000 --- a/src/Appwrite/Utopia/Database/Validator/IndexedQueries.php +++ /dev/null @@ -1,111 +0,0 @@ - - */ - protected array $attributes = []; - - /** - * @var array - */ - protected array $indexes = []; - - /** - * Expression constructor - * - * This Queries Validator filters indexes for only available indexes - * - * @param array $attributes - * @param array $indexes - * @param Base ...$validators - * @throws \Exception - */ - public function __construct(array $attributes = [], array $indexes = [], Base ...$validators) - { - $this->attributes = $attributes; - - $this->indexes[] = new Document([ - 'type' => Database::INDEX_UNIQUE, - 'attributes' => ['$id'] - ]); - - $this->indexes[] = new Document([ - 'type' => Database::INDEX_KEY, - 'attributes' => ['$createdAt'] - ]); - - $this->indexes[] = new Document([ - 'type' => Database::INDEX_KEY, - 'attributes' => ['$updatedAt'] - ]); - - foreach ($indexes ?? [] as $index) { - $this->indexes[] = $index; - } - - parent::__construct(...$validators); - } - - /** - * Is valid. - * - * Returns false if: - * 1. any query in $value is invalid based on $validator - * 2. there is no index with an exact match of the filters - * 3. there is no index with an exact match of the order attributes - * - * Otherwise, returns true. - * - * @param mixed $value - * @return bool - */ - public function isValid($value): bool - { - if (!parent::isValid($value)) { - return false; - } - - $queries = []; - foreach ($value as $query) { - if (!$query instanceof Query) { - $query = Query::parse($query); - } - - $queries[] = $query; - } - - $grouped = Query::groupByType($queries); - $filters = $grouped['filters']; - - foreach ($filters as $filter) { - if ($filter->getMethod() === Query::TYPE_SEARCH) { - $matched = false; - - foreach ($this->indexes as $index) { - if ( - $index->getAttribute('type') === Database::INDEX_FULLTEXT - && $index->getAttribute('attributes') === [$filter->getAttribute()] - ) { - $matched = true; - } - } - - if (!$matched) { - $this->message = "Searching by attribute \"{$filter->getAttribute()}\" requires a fulltext index."; - return false; - } - } - } - - return true; - } -} diff --git a/src/Appwrite/Utopia/Database/Validator/Queries.php b/src/Appwrite/Utopia/Database/Validator/Queries.php deleted file mode 100644 index 825b24e2bc..0000000000 --- a/src/Appwrite/Utopia/Database/Validator/Queries.php +++ /dev/null @@ -1,135 +0,0 @@ - - */ - protected array $validators; - - /** - * Queries constructor - * - * @param Base ...$validators a list of validators - */ - public function __construct(Base ...$validators) - { - $this->validators = $validators; - } - - /** - * Get Description. - * - * Returns validator description - * - * @return string - */ - public function getDescription(): string - { - return $this->message; - } - - /** - * Is valid. - * - * Returns false if: - * 1. any query in $value is invalid based on $validator - * - * Otherwise, returns true. - * - * @param mixed $value - * @return bool - */ - public function isValid($value): bool - { - foreach ($value as $query) { - if (!$query instanceof Query) { - try { - $query = Query::parse($query); - } catch (\Throwable) { - $this->message = "Invalid query: {$query}"; - return false; - } - } - - $method = $query->getMethod(); - $methodType = match ($method) { - Query::TYPE_SELECT => Base::METHOD_TYPE_SELECT, - Query::TYPE_LIMIT => Base::METHOD_TYPE_LIMIT, - Query::TYPE_OFFSET => Base::METHOD_TYPE_OFFSET, - Query::TYPE_CURSORAFTER, - Query::TYPE_CURSORBEFORE => Base::METHOD_TYPE_CURSOR, - Query::TYPE_ORDERASC, - Query::TYPE_ORDERDESC => Base::METHOD_TYPE_ORDER, - Query::TYPE_EQUAL, - Query::TYPE_NOTEQUAL, - Query::TYPE_LESSER, - Query::TYPE_LESSEREQUAL, - Query::TYPE_GREATER, - Query::TYPE_GREATEREQUAL, - Query::TYPE_SEARCH, - Query::TYPE_IS_NULL, - Query::TYPE_IS_NOT_NULL, - Query::TYPE_BETWEEN, - Query::TYPE_STARTS_WITH, - Query::TYPE_ENDS_WITH => Base::METHOD_TYPE_FILTER, - default => '', - }; - - $methodIsValid = false; - foreach ($this->validators as $validator) { - if ($validator->getMethodType() !== $methodType) { - continue; - } - if (!$validator->isValid($query)) { - $this->message = 'Query not valid: ' . $validator->getDescription(); - return false; - } - - $methodIsValid = true; - } - - if (!$methodIsValid) { - $this->message = 'Query method not valid: ' . $method; - 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; - } -} diff --git a/src/Appwrite/Utopia/Database/Validator/Queries/Base.php b/src/Appwrite/Utopia/Database/Validator/Queries/Base.php index 2f7fd5d60d..3ea3121e25 100644 --- a/src/Appwrite/Utopia/Database/Validator/Queries/Base.php +++ b/src/Appwrite/Utopia/Database/Validator/Queries/Base.php @@ -2,13 +2,13 @@ namespace Appwrite\Utopia\Database\Validator\Queries; -use Appwrite\Utopia\Database\Validator\Queries; -use Appwrite\Utopia\Database\Validator\Query\Limit; -use Appwrite\Utopia\Database\Validator\Query\Offset; -use Appwrite\Utopia\Database\Validator\Query\Cursor; -use Appwrite\Utopia\Database\Validator\Query\Filter; -use Appwrite\Utopia\Database\Validator\Query\Order; -use Appwrite\Utopia\Database\Validator\Query\Select; +use Utopia\Database\Validator\Queries; +use Utopia\Database\Validator\Query\Limit; +use Utopia\Database\Validator\Query\Offset; +use Utopia\Database\Validator\Query\Cursor; +use Utopia\Database\Validator\Query\Filter; +use Utopia\Database\Validator\Query\Order; +use Utopia\Database\Validator\Query\Select; use Utopia\Config\Config; use Utopia\Database\Database; use Utopia\Database\Document; diff --git a/src/Appwrite/Utopia/Database/Validator/Queries/Document.php b/src/Appwrite/Utopia/Database/Validator/Queries/Document.php index 3c630dfca9..f8e0e2f065 100644 --- a/src/Appwrite/Utopia/Database/Validator/Queries/Document.php +++ b/src/Appwrite/Utopia/Database/Validator/Queries/Document.php @@ -2,8 +2,8 @@ namespace Appwrite\Utopia\Database\Validator\Queries; -use Appwrite\Utopia\Database\Validator\Queries; -use Appwrite\Utopia\Database\Validator\Query\Select; +use Utopia\Database\Validator\Queries; +use Utopia\Database\Validator\Query\Select; use Utopia\Database\Database; class Document extends Queries diff --git a/src/Appwrite/Utopia/Database/Validator/Queries/Documents.php b/src/Appwrite/Utopia/Database/Validator/Queries/Documents.php index 7955ad35cc..d7caf7cdea 100644 --- a/src/Appwrite/Utopia/Database/Validator/Queries/Documents.php +++ b/src/Appwrite/Utopia/Database/Validator/Queries/Documents.php @@ -2,13 +2,13 @@ namespace Appwrite\Utopia\Database\Validator\Queries; -use Appwrite\Utopia\Database\Validator\IndexedQueries; -use Appwrite\Utopia\Database\Validator\Query\Cursor; -use Appwrite\Utopia\Database\Validator\Query\Filter; -use Appwrite\Utopia\Database\Validator\Query\Limit; -use Appwrite\Utopia\Database\Validator\Query\Offset; -use Appwrite\Utopia\Database\Validator\Query\Order; -use Appwrite\Utopia\Database\Validator\Query\Select; +use Utopia\Database\Validator\IndexedQueries; +use Utopia\Database\Validator\Query\Cursor; +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\Database; use Utopia\Database\Document; diff --git a/src/Appwrite/Utopia/Database/Validator/Query/Base.php b/src/Appwrite/Utopia/Database/Validator/Query/Base.php deleted file mode 100644 index d6f6df33f3..0000000000 --- a/src/Appwrite/Utopia/Database/Validator/Query/Base.php +++ /dev/null @@ -1,62 +0,0 @@ -message; - } - - /** - * Is array - * - * Function will return true if object is array. - * - * @return bool - */ - public function isArray(): bool - { - return false; - } - - /** - * Get Type - * - * Returns validator type. - * - * @return string - */ - public function getType(): string - { - return self::TYPE_OBJECT; - } - - /** - * Returns what type of query this Validator is for - */ - abstract public function getMethodType(): string; -} diff --git a/src/Appwrite/Utopia/Database/Validator/Query/Cursor.php b/src/Appwrite/Utopia/Database/Validator/Query/Cursor.php deleted file mode 100644 index 42bff08a1d..0000000000 --- a/src/Appwrite/Utopia/Database/Validator/Query/Cursor.php +++ /dev/null @@ -1,44 +0,0 @@ -getMethod(); - - if ($method === Query::TYPE_CURSORAFTER || $method === Query::TYPE_CURSORBEFORE) { - $cursor = $query->getValue(); - $validator = new UID(); - if ($validator->isValid($cursor)) { - return true; - } - $this->message = 'Invalid cursor: ' . $validator->getDescription(); - return false; - } - - return false; - } - - public function getMethodType(): string - { - return self::METHOD_TYPE_CURSOR; - } -} diff --git a/src/Appwrite/Utopia/Database/Validator/Query/Filter.php b/src/Appwrite/Utopia/Database/Validator/Query/Filter.php deleted file mode 100644 index 08847133de..0000000000 --- a/src/Appwrite/Utopia/Database/Validator/Query/Filter.php +++ /dev/null @@ -1,141 +0,0 @@ -schema[$attribute->getAttribute('key')] = $attribute->getArrayCopy(); - } - - $this->maxValuesCount = $maxValuesCount; - } - - protected function isValidAttribute($attribute): bool - { - if (\str_contains($attribute, '.')) { - // For relationships, just validate the top level. - // Utopia will validate each nested level during the recursive calls. - $attribute = \explode('.', $attribute)[0]; - - // TODO: Remove this when nested queries are supported - if (isset($this->schema[$attribute])) { - $this->message = 'Cannot query nested attribute on: ' . $attribute; - return false; - } - } - - // Search for attribute in schema - if (!isset($this->schema[$attribute])) { - $this->message = 'Attribute not found in schema: ' . $attribute; - return false; - } - - return true; - } - - protected function isValidAttributeAndValues(string $attribute, array $values): bool - { - if (!$this->isValidAttribute($attribute)) { - return false; - } - - if (\str_contains($attribute, '.')) { - // For relationships, just validate the top level. - // Utopia will validate each nested level during the recursive calls. - $attribute = \explode('.', $attribute)[0]; - } - - $attributeSchema = $this->schema[$attribute]; - - if (count($values) > $this->maxValuesCount) { - $this->message = 'Query on attribute has greater than ' . $this->maxValuesCount . ' values: ' . $attribute; - return false; - } - - // Extract the type of desired attribute from collection $schema - $attributeType = $attributeSchema['type']; - - foreach ($values as $value) { - $condition = match ($attributeType) { - Database::VAR_RELATIONSHIP => true, - Database::VAR_DATETIME => gettype($value) === Database::VAR_STRING, - Database::VAR_FLOAT => (gettype($value) === Database::VAR_FLOAT || gettype($value) === Database::VAR_INTEGER), - default => gettype($value) === $attributeType - }; - - if (!$condition) { - $this->message = 'Query type does not match expected: ' . $attributeType; - return false; - } - } - - return true; - } - - /** - * Is valid. - * - * Returns true if method is a filter method, attribute exists, and value matches attribute type - * - * Otherwise, returns false - * - * @param Query $value - * - * @return bool - */ - public function isValid($query): bool - { - // Validate method - $method = $query->getMethod(); - $attribute = $query->getAttribute(); - - switch ($method) { - case Query::TYPE_EQUAL: - case Query::TYPE_NOTEQUAL: - case Query::TYPE_LESSER: - case Query::TYPE_LESSEREQUAL: - case Query::TYPE_GREATER: - case Query::TYPE_GREATEREQUAL: - case Query::TYPE_SEARCH: - case Query::TYPE_STARTS_WITH: - case Query::TYPE_ENDS_WITH: - case Query::TYPE_BETWEEN: - case Query::TYPE_IS_NULL: - case Query::TYPE_IS_NOT_NULL: - $values = $query->getValues(); - return $this->isValidAttributeAndValues($attribute, $values); - - default: - return false; - } - } - - public function getMethodType(): string - { - return self::METHOD_TYPE_FILTER; - } -} diff --git a/src/Appwrite/Utopia/Database/Validator/Query/Limit.php b/src/Appwrite/Utopia/Database/Validator/Query/Limit.php deleted file mode 100644 index 7a99825bcd..0000000000 --- a/src/Appwrite/Utopia/Database/Validator/Query/Limit.php +++ /dev/null @@ -1,61 +0,0 @@ -maxLimit = $maxLimit; - } - - protected function isValidLimit($limit): bool - { - $validator = new Range(0, $this->maxLimit); - if ($validator->isValid($limit)) { - return true; - } - - $this->message = 'Invalid limit: ' . $validator->getDescription(); - return false; - } - - /** - * Is valid. - * - * Returns true if method is limit values are within range. - * - * @param Query $value - * - * @return bool - */ - public function isValid($query): bool - { - // Validate method - $method = $query->getMethod(); - - if ($method !== Query::TYPE_LIMIT) { - $this->message = 'Query method invalid: ' . $method; - return false; - } - - $limit = $query->getValue(); - return $this->isValidLimit($limit); - } - - public function getMethodType(): string - { - return self::METHOD_TYPE_LIMIT; - } -} diff --git a/src/Appwrite/Utopia/Database/Validator/Query/Offset.php b/src/Appwrite/Utopia/Database/Validator/Query/Offset.php deleted file mode 100644 index 0bcbb909fa..0000000000 --- a/src/Appwrite/Utopia/Database/Validator/Query/Offset.php +++ /dev/null @@ -1,60 +0,0 @@ -maxOffset = $maxOffset; - } - - protected function isValidOffset($offset): bool - { - $validator = new Range(0, $this->maxOffset); - if ($validator->isValid($offset)) { - return true; - } - - $this->message = 'Invalid offset: ' . $validator->getDescription(); - return false; - } - - /** - * Is valid. - * - * Returns true if method is offset and values are within range. - * - * @param Query $value - * - * @return bool - */ - public function isValid($query): bool - { - // Validate method - $method = $query->getMethod(); - - if ($method !== Query::TYPE_OFFSET) { - $this->message = 'Query method invalid: ' . $method; - return false; - } - - $offset = $query->getValue(); - return $this->isValidOffset($offset); - } - - public function getMethodType(): string - { - return self::METHOD_TYPE_OFFSET; - } -} diff --git a/src/Appwrite/Utopia/Database/Validator/Query/Order.php b/src/Appwrite/Utopia/Database/Validator/Query/Order.php deleted file mode 100644 index 0c12d7ac44..0000000000 --- a/src/Appwrite/Utopia/Database/Validator/Query/Order.php +++ /dev/null @@ -1,68 +0,0 @@ -schema[$attribute->getAttribute('key')] = $attribute->getArrayCopy(); - } - } - - protected function isValidAttribute($attribute): bool - { - // Search for attribute in schema - if (!isset($this->schema[$attribute])) { - $this->message = 'Attribute not found in schema: ' . $attribute; - return false; - } - - return true; - } - - /** - * Is valid. - * - * Returns true if method is ORDER_ASC or ORDER_DESC and attributes are valid - * - * Otherwise, returns false - * - * @param Query $value - * - * @return bool - */ - public function isValid($query): bool - { - $method = $query->getMethod(); - $attribute = $query->getAttribute(); - - if ($method === Query::TYPE_ORDERASC || $method === Query::TYPE_ORDERDESC) { - if ($attribute === '') { - return true; - } - return $this->isValidAttribute($attribute); - } - - return false; - } - - public function getMethodType(): string - { - return self::METHOD_TYPE_ORDER; - } -} diff --git a/src/Appwrite/Utopia/Database/Validator/Query/Select.php b/src/Appwrite/Utopia/Database/Validator/Query/Select.php deleted file mode 100644 index f1907f2e86..0000000000 --- a/src/Appwrite/Utopia/Database/Validator/Query/Select.php +++ /dev/null @@ -1,60 +0,0 @@ -schema[$attribute->getAttribute('key')] = $attribute->getArrayCopy(); - } - } - - /** - * Is valid. - * - * Returns true if method is TYPE_SELECT selections are valid - * - * Otherwise, returns false - * - * @param $query - * @return bool - */ - public function isValid($query): bool - { - /* @var $query Query */ - - if ($query->getMethod() !== Query::TYPE_SELECT) { - return false; - } - - foreach ($query->getValues() as $attribute) { - if (\str_contains($attribute, '.')) { - // For relationships, just validate the top level. - // Utopia will validate each nested level during the recursive calls. - $attribute = \explode('.', $attribute)[0]; - } - if (!isset($this->schema[$attribute]) && $attribute !== '*') { - $this->message = 'Attribute not found in schema: ' . $attribute; - return false; - } - } - return true; - } - - public function getMethodType(): string - { - return self::METHOD_TYPE_SELECT; - } -} diff --git a/tests/unit/Utopia/Database/Validator/IndexedQueriesTest.php b/tests/unit/Utopia/Database/Validator/IndexedQueriesTest.php index 52375004ca..3092029222 100644 --- a/tests/unit/Utopia/Database/Validator/IndexedQueriesTest.php +++ b/tests/unit/Utopia/Database/Validator/IndexedQueriesTest.php @@ -1,121 +1,121 @@ assertEquals(true, $validator->isValid([])); - } - - public function testInvalidQuery(): void - { - $validator = new IndexedQueries(); - - $this->assertEquals(false, $validator->isValid(["this.is.invalid"])); - } - - public function testInvalidMethod(): void - { - $validator = new IndexedQueries(); - $this->assertEquals(false, $validator->isValid(['equal("attr", "value")'])); - - $validator = new IndexedQueries([], [], new Limit()); - $this->assertEquals(false, $validator->isValid(['equal("attr", "value")'])); - } - - public function testInvalidValue(): void - { - $validator = new IndexedQueries([], [], new Limit()); - $this->assertEquals(false, $validator->isValid(['limit(-1)'])); - } - - public function testValid(): void - { - $attributes = [ - new Document([ - 'key' => 'name', - 'type' => Database::VAR_STRING, - 'array' => false, - ]), - ]; - $indexes = [ - new Document([ - 'status' => 'available', - 'type' => Database::INDEX_KEY, - 'attributes' => ['name'], - ]), - new Document([ - 'status' => 'available', - 'type' => Database::INDEX_FULLTEXT, - 'attributes' => ['name'], - ]), - ]; - $validator = new IndexedQueries( - $attributes, - $indexes, - new Cursor(), - new Filter($attributes), - new Limit(), - new Offset(), - new Order($attributes), - ); - $this->assertEquals(true, $validator->isValid(['cursorAfter("asdf")']), $validator->getDescription()); - $this->assertEquals(true, $validator->isValid(['equal("name", "value")']), $validator->getDescription()); - $this->assertEquals(true, $validator->isValid(['limit(10)']), $validator->getDescription()); - $this->assertEquals(true, $validator->isValid(['offset(10)']), $validator->getDescription()); - $this->assertEquals(true, $validator->isValid(['orderAsc("name")']), $validator->getDescription()); - $this->assertEquals(true, $validator->isValid(['search("name", "value")']), $validator->getDescription()); - } - - public function testMissingIndex(): void - { - $attributes = [ - new Document([ - 'key' => 'name', - 'type' => Database::VAR_STRING, - 'array' => false, - ]), - ]; - $indexes = [ - new Document([ - 'status' => 'available', - 'type' => Database::INDEX_KEY, - 'attributes' => ['name'], - ]), - ]; - $validator = new IndexedQueries( - $attributes, - $indexes, - new Cursor(), - new Filter($attributes), - new Limit(), - new Offset(), - new Order($attributes), - ); - $this->assertEquals(false, $validator->isValid(['equal("dne", "value")']), $validator->getDescription()); - $this->assertEquals(false, $validator->isValid(['orderAsc("dne")']), $validator->getDescription()); - $this->assertEquals(false, $validator->isValid(['search("name", "value")']), $validator->getDescription()); - } -} +// +//namespace Tests\Unit\Utopia\Database\Validator; +// +//use Appwrite\Utopia\Database\Validator\IndexedQueries; +//use Appwrite\Utopia\Database\Validator\Query\Cursor; +//use Appwrite\Utopia\Database\Validator\Query\Filter; +//use Appwrite\Utopia\Database\Validator\Query\Limit; +//use Appwrite\Utopia\Database\Validator\Query\Offset; +//use Appwrite\Utopia\Database\Validator\Query\Order; +//use PHPUnit\Framework\TestCase; +//use Utopia\Database\Database; +//use Utopia\Database\Document; +// +//class IndexedQueriesTest extends TestCase +//{ +// public function setUp(): void +// { +// } +// +// public function tearDown(): void +// { +// } +// +// public function testEmptyQueries(): void +// { +// $validator = new IndexedQueries(); +// +// $this->assertEquals(true, $validator->isValid([])); +// } +// +// public function testInvalidQuery(): void +// { +// $validator = new IndexedQueries(); +// +// $this->assertEquals(false, $validator->isValid(["this.is.invalid"])); +// } +// +// public function testInvalidMethod(): void +// { +// $validator = new IndexedQueries(); +// $this->assertEquals(false, $validator->isValid(['equal("attr", "value")'])); +// +// $validator = new IndexedQueries([], [], new Limit()); +// $this->assertEquals(false, $validator->isValid(['equal("attr", "value")'])); +// } +// +// public function testInvalidValue(): void +// { +// $validator = new IndexedQueries([], [], new Limit()); +// $this->assertEquals(false, $validator->isValid(['limit(-1)'])); +// } +// +// public function testValid(): void +// { +// $attributes = [ +// new Document([ +// 'key' => 'name', +// 'type' => Database::VAR_STRING, +// 'array' => false, +// ]), +// ]; +// $indexes = [ +// new Document([ +// 'status' => 'available', +// 'type' => Database::INDEX_KEY, +// 'attributes' => ['name'], +// ]), +// new Document([ +// 'status' => 'available', +// 'type' => Database::INDEX_FULLTEXT, +// 'attributes' => ['name'], +// ]), +// ]; +// $validator = new IndexedQueries( +// $attributes, +// $indexes, +// new Cursor(), +// new Filter($attributes), +// new Limit(), +// new Offset(), +// new Order($attributes), +// ); +// $this->assertEquals(true, $validator->isValid(['cursorAfter("asdf")']), $validator->getDescription()); +// $this->assertEquals(true, $validator->isValid(['equal("name", "value")']), $validator->getDescription()); +// $this->assertEquals(true, $validator->isValid(['limit(10)']), $validator->getDescription()); +// $this->assertEquals(true, $validator->isValid(['offset(10)']), $validator->getDescription()); +// $this->assertEquals(true, $validator->isValid(['orderAsc("name")']), $validator->getDescription()); +// $this->assertEquals(true, $validator->isValid(['search("name", "value")']), $validator->getDescription()); +// } +// +// public function testMissingIndex(): void +// { +// $attributes = [ +// new Document([ +// 'key' => 'name', +// 'type' => Database::VAR_STRING, +// 'array' => false, +// ]), +// ]; +// $indexes = [ +// new Document([ +// 'status' => 'available', +// 'type' => Database::INDEX_KEY, +// 'attributes' => ['name'], +// ]), +// ]; +// $validator = new IndexedQueries( +// $attributes, +// $indexes, +// new Cursor(), +// new Filter($attributes), +// new Limit(), +// new Offset(), +// new Order($attributes), +// ); +// $this->assertEquals(false, $validator->isValid(['equal("dne", "value")']), $validator->getDescription()); +// $this->assertEquals(false, $validator->isValid(['orderAsc("dne")']), $validator->getDescription()); +// $this->assertEquals(false, $validator->isValid(['search("name", "value")']), $validator->getDescription()); +// } +//} diff --git a/tests/unit/Utopia/Database/Validator/QueriesTest.php b/tests/unit/Utopia/Database/Validator/QueriesTest.php index 55e04c2b84..d78cfe316b 100644 --- a/tests/unit/Utopia/Database/Validator/QueriesTest.php +++ b/tests/unit/Utopia/Database/Validator/QueriesTest.php @@ -1,76 +1,76 @@ assertEquals(true, $validator->isValid([])); - } - - public function testInvalidQuery(): void - { - $validator = new Queries(); - - $this->assertEquals(false, $validator->isValid(["this.is.invalid"])); - } - - public function testInvalidMethod(): void - { - $validator = new Queries(); - $this->assertEquals(false, $validator->isValid(['equal("attr", "value")'])); - - $validator = new Queries(new Limit()); - $this->assertEquals(false, $validator->isValid(['equal("attr", "value")'])); - } - - public function testInvalidValue(): void - { - $validator = new Queries(new Limit()); - $this->assertEquals(false, $validator->isValid(['limit(-1)'])); - } - - public function testValid(): void - { - $attributes = [ - new Document([ - 'key' => 'name', - 'type' => Database::VAR_STRING, - 'array' => false, - ]) - ]; - $validator = new Queries( - new Cursor(), - new Filter($attributes), - new Limit(), - new Offset(), - new Order($attributes), - ); - $this->assertEquals(true, $validator->isValid(['cursorAfter("asdf")']), $validator->getDescription()); - $this->assertEquals(true, $validator->isValid(['equal("name", "value")']), $validator->getDescription()); - $this->assertEquals(true, $validator->isValid(['limit(10)']), $validator->getDescription()); - $this->assertEquals(true, $validator->isValid(['offset(10)']), $validator->getDescription()); - $this->assertEquals(true, $validator->isValid(['orderAsc("name")']), $validator->getDescription()); - } -} +// +//namespace Tests\Unit\Utopia\Database\Validator; +// +//use Utopia\Database\Validator\Queries; +//use Utopia\Database\Validator\Query\Cursor; +//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 PHPUnit\Framework\TestCase; +//use Utopia\Database\Database; +//use Utopia\Database\Document; +// +//class QueriesTest extends TestCase +//{ +// public function setUp(): void +// { +// } +// +// public function tearDown(): void +// { +// } +// +// public function testEmptyQueries(): void +// { +// $validator = new Queries(); +// +// $this->assertEquals(true, $validator->isValid([])); +// } +// +// public function testInvalidQuery(): void +// { +// $validator = new Queries(); +// +// $this->assertEquals(false, $validator->isValid(["this.is.invalid"])); +// } +// +// public function testInvalidMethod(): void +// { +// $validator = new Queries(); +// $this->assertEquals(false, $validator->isValid(['equal("attr", "value")'])); +// +// $validator = new Queries(new Limit()); +// $this->assertEquals(false, $validator->isValid(['equal("attr", "value")'])); +// } +// +// public function testInvalidValue(): void +// { +// $validator = new Queries(new Limit()); +// $this->assertEquals(false, $validator->isValid(['limit(-1)'])); +// } +// +// public function testValid(): void +// { +// $attributes = [ +// new Document([ +// 'key' => 'name', +// 'type' => Database::VAR_STRING, +// 'array' => false, +// ]) +// ]; +// $validator = new Queries( +// new Cursor(), +// new Filter($attributes), +// new Limit(), +// new Offset(), +// new Order($attributes), +// ); +// $this->assertEquals(true, $validator->isValid(['cursorAfter("asdf")']), $validator->getDescription()); +// $this->assertEquals(true, $validator->isValid(['equal("name", "value")']), $validator->getDescription()); +// $this->assertEquals(true, $validator->isValid(['limit(10)']), $validator->getDescription()); +// $this->assertEquals(true, $validator->isValid(['offset(10)']), $validator->getDescription()); +// $this->assertEquals(true, $validator->isValid(['orderAsc("name")']), $validator->getDescription()); +// } +//} diff --git a/tests/unit/Utopia/Database/Validator/Query/CursorTest.php b/tests/unit/Utopia/Database/Validator/Query/CursorTest.php index 0afc8baddd..5959ff3884 100644 --- a/tests/unit/Utopia/Database/Validator/Query/CursorTest.php +++ b/tests/unit/Utopia/Database/Validator/Query/CursorTest.php @@ -1,41 +1,41 @@ validator = new Cursor(); - } - - public function tearDown(): void - { - } - - public function testValue(): void - { - // Test for Success - $this->assertEquals($this->validator->isValid(new Query(Query::TYPE_CURSORAFTER, values: ['asdf'])), true, $this->validator->getDescription()); - $this->assertEquals($this->validator->isValid(new Query(Query::TYPE_CURSORBEFORE, values: ['asdf'])), true, $this->validator->getDescription()); - - // Test for Failure - $this->assertEquals($this->validator->isValid(Query::limit(-1)), false, $this->validator->getDescription()); - $this->assertEquals($this->validator->isValid(Query::limit(101)), false, $this->validator->getDescription()); - $this->assertEquals($this->validator->isValid(Query::offset(-1)), false, $this->validator->getDescription()); - $this->assertEquals($this->validator->isValid(Query::offset(5001)), false, $this->validator->getDescription()); - $this->assertEquals($this->validator->isValid(Query::equal('attr', ['v'])), false, $this->validator->getDescription()); - $this->assertEquals($this->validator->isValid(Query::orderAsc('attr')), false, $this->validator->getDescription()); - $this->assertEquals($this->validator->isValid(Query::orderDesc('attr')), false, $this->validator->getDescription()); - } -} +// +//namespace Tests\Unit\Utopia\Database\Validator\Query; +// +//use Appwrite\Utopia\Database\Validator\Query\Base; +//use Appwrite\Utopia\Database\Validator\Query\Cursor; +//use Utopia\Database\Query; +//use PHPUnit\Framework\TestCase; +// +//class CursorTest extends TestCase +//{ +// /** +// * @var Base +// */ +// protected $validator = null; +// +// public function setUp(): void +// { +// $this->validator = new Cursor(); +// } +// +// public function tearDown(): void +// { +// } +// +// public function testValue(): void +// { +// // Test for Success +// $this->assertEquals($this->validator->isValid(new Query(Query::TYPE_CURSORAFTER, values: ['asdf'])), true, $this->validator->getDescription()); +// $this->assertEquals($this->validator->isValid(new Query(Query::TYPE_CURSORBEFORE, values: ['asdf'])), true, $this->validator->getDescription()); +// +// // Test for Failure +// $this->assertEquals($this->validator->isValid(Query::limit(-1)), false, $this->validator->getDescription()); +// $this->assertEquals($this->validator->isValid(Query::limit(101)), false, $this->validator->getDescription()); +// $this->assertEquals($this->validator->isValid(Query::offset(-1)), false, $this->validator->getDescription()); +// $this->assertEquals($this->validator->isValid(Query::offset(5001)), false, $this->validator->getDescription()); +// $this->assertEquals($this->validator->isValid(Query::equal('attr', ['v'])), false, $this->validator->getDescription()); +// $this->assertEquals($this->validator->isValid(Query::orderAsc('attr')), false, $this->validator->getDescription()); +// $this->assertEquals($this->validator->isValid(Query::orderDesc('attr')), false, $this->validator->getDescription()); +// } +//} diff --git a/tests/unit/Utopia/Database/Validator/Query/FilterTest.php b/tests/unit/Utopia/Database/Validator/Query/FilterTest.php index 6e35435e32..df2d7148b7 100644 --- a/tests/unit/Utopia/Database/Validator/Query/FilterTest.php +++ b/tests/unit/Utopia/Database/Validator/Query/FilterTest.php @@ -1,64 +1,64 @@ validator = new Filter( - attributes: [ - new Document([ - 'key' => 'attr', - 'type' => Database::VAR_STRING, - 'array' => false, - ]), - ], - ); - } - - public function tearDown(): void - { - } - - public function testValue(): void - { - // Test for Success - $this->assertEquals($this->validator->isValid(Query::between('attr', '1975-12-06', '2050-12-06')), true, $this->validator->getDescription()); - $this->assertEquals($this->validator->isValid(Query::isNotNull('attr')), true, $this->validator->getDescription()); - $this->assertEquals($this->validator->isValid(Query::isNull('attr')), true, $this->validator->getDescription()); - $this->assertEquals($this->validator->isValid(Query::startsWith('attr', 'super')), true, $this->validator->getDescription()); - $this->assertEquals($this->validator->isValid(Query::endsWith('attr', 'man')), true, $this->validator->getDescription()); - - // Test for Failure - $this->assertEquals($this->validator->isValid(Query::select(['attr'])), false, $this->validator->getDescription()); - $this->assertEquals($this->validator->isValid(Query::limit(1)), false, $this->validator->getDescription()); - $this->assertEquals($this->validator->isValid(Query::limit(0)), false, $this->validator->getDescription()); - $this->assertEquals($this->validator->isValid(Query::limit(100)), false, $this->validator->getDescription()); - $this->assertEquals($this->validator->isValid(Query::limit(-1)), false, $this->validator->getDescription()); - $this->assertEquals($this->validator->isValid(Query::limit(101)), false, $this->validator->getDescription()); - $this->assertEquals($this->validator->isValid(Query::offset(1)), false, $this->validator->getDescription()); - $this->assertEquals($this->validator->isValid(Query::offset(0)), false, $this->validator->getDescription()); - $this->assertEquals($this->validator->isValid(Query::offset(5000)), false, $this->validator->getDescription()); - $this->assertEquals($this->validator->isValid(Query::offset(-1)), false, $this->validator->getDescription()); - $this->assertEquals($this->validator->isValid(Query::offset(5001)), false, $this->validator->getDescription()); - $this->assertEquals($this->validator->isValid(Query::equal('dne', ['v'])), false, $this->validator->getDescription()); - $this->assertEquals($this->validator->isValid(Query::equal('', ['v'])), false, $this->validator->getDescription()); - $this->assertEquals($this->validator->isValid(Query::orderAsc('attr')), false, $this->validator->getDescription()); - $this->assertEquals($this->validator->isValid(Query::orderDesc('attr')), false, $this->validator->getDescription()); - $this->assertEquals($this->validator->isValid(new Query(Query::TYPE_CURSORAFTER, values: ['asdf'])), false, $this->validator->getDescription()); - $this->assertEquals($this->validator->isValid(new Query(Query::TYPE_CURSORBEFORE, values: ['asdf'])), false, $this->validator->getDescription()); - } -} +// +//namespace Tests\Unit\Utopia\Database\Validator\Query; +// +//use Appwrite\Utopia\Database\Validator\Query\Base; +//use Appwrite\Utopia\Database\Validator\Query\Filter; +//use Utopia\Database\Database; +//use Utopia\Database\Document; +//use Utopia\Database\Query; +//use PHPUnit\Framework\TestCase; +// +//class FilterTest extends TestCase +//{ +// /** +// * @var Base +// */ +// protected $validator = null; +// +// public function setUp(): void +// { +// $this->validator = new Filter( +// attributes: [ +// new Document([ +// 'key' => 'attr', +// 'type' => Database::VAR_STRING, +// 'array' => false, +// ]), +// ], +// ); +// } +// +// public function tearDown(): void +// { +// } +// +// public function testValue(): void +// { +// // Test for Success +// $this->assertEquals($this->validator->isValid(Query::between('attr', '1975-12-06', '2050-12-06')), true, $this->validator->getDescription()); +// $this->assertEquals($this->validator->isValid(Query::isNotNull('attr')), true, $this->validator->getDescription()); +// $this->assertEquals($this->validator->isValid(Query::isNull('attr')), true, $this->validator->getDescription()); +// $this->assertEquals($this->validator->isValid(Query::startsWith('attr', 'super')), true, $this->validator->getDescription()); +// $this->assertEquals($this->validator->isValid(Query::endsWith('attr', 'man')), true, $this->validator->getDescription()); +// +// // Test for Failure +// $this->assertEquals($this->validator->isValid(Query::select(['attr'])), false, $this->validator->getDescription()); +// $this->assertEquals($this->validator->isValid(Query::limit(1)), false, $this->validator->getDescription()); +// $this->assertEquals($this->validator->isValid(Query::limit(0)), false, $this->validator->getDescription()); +// $this->assertEquals($this->validator->isValid(Query::limit(100)), false, $this->validator->getDescription()); +// $this->assertEquals($this->validator->isValid(Query::limit(-1)), false, $this->validator->getDescription()); +// $this->assertEquals($this->validator->isValid(Query::limit(101)), false, $this->validator->getDescription()); +// $this->assertEquals($this->validator->isValid(Query::offset(1)), false, $this->validator->getDescription()); +// $this->assertEquals($this->validator->isValid(Query::offset(0)), false, $this->validator->getDescription()); +// $this->assertEquals($this->validator->isValid(Query::offset(5000)), false, $this->validator->getDescription()); +// $this->assertEquals($this->validator->isValid(Query::offset(-1)), false, $this->validator->getDescription()); +// $this->assertEquals($this->validator->isValid(Query::offset(5001)), false, $this->validator->getDescription()); +// $this->assertEquals($this->validator->isValid(Query::equal('dne', ['v'])), false, $this->validator->getDescription()); +// $this->assertEquals($this->validator->isValid(Query::equal('', ['v'])), false, $this->validator->getDescription()); +// $this->assertEquals($this->validator->isValid(Query::orderAsc('attr')), false, $this->validator->getDescription()); +// $this->assertEquals($this->validator->isValid(Query::orderDesc('attr')), false, $this->validator->getDescription()); +// $this->assertEquals($this->validator->isValid(new Query(Query::TYPE_CURSORAFTER, values: ['asdf'])), false, $this->validator->getDescription()); +// $this->assertEquals($this->validator->isValid(new Query(Query::TYPE_CURSORBEFORE, values: ['asdf'])), false, $this->validator->getDescription()); +// } +//} diff --git a/tests/unit/Utopia/Database/Validator/Query/LimitTest.php b/tests/unit/Utopia/Database/Validator/Query/LimitTest.php index 1594d0db1f..cd37180f3a 100644 --- a/tests/unit/Utopia/Database/Validator/Query/LimitTest.php +++ b/tests/unit/Utopia/Database/Validator/Query/LimitTest.php @@ -1,37 +1,37 @@ validator = new Limit(100); - } - - public function tearDown(): void - { - } - - public function testValue(): void - { - // Test for Success - $this->assertEquals($this->validator->isValid(Query::limit(1)), true, $this->validator->getDescription()); - $this->assertEquals($this->validator->isValid(Query::limit(0)), true, $this->validator->getDescription()); - $this->assertEquals($this->validator->isValid(Query::limit(100)), true, $this->validator->getDescription()); - - // Test for Failure - $this->assertEquals($this->validator->isValid(Query::limit(-1)), false, $this->validator->getDescription()); - $this->assertEquals($this->validator->isValid(Query::limit(101)), false, $this->validator->getDescription()); - } -} +// +//namespace Tests\Unit\Utopia\Database\Validator\Query; +// +//use Appwrite\Utopia\Database\Validator\Query\Base; +//use Appwrite\Utopia\Database\Validator\Query\Limit; +//use Utopia\Database\Query; +//use PHPUnit\Framework\TestCase; +// +//class LimitTest extends TestCase +//{ +// /** +// * @var Base +// */ +// protected $validator = null; +// +// public function setUp(): void +// { +// $this->validator = new Limit(100); +// } +// +// public function tearDown(): void +// { +// } +// +// public function testValue(): void +// { +// // Test for Success +// $this->assertEquals($this->validator->isValid(Query::limit(1)), true, $this->validator->getDescription()); +// $this->assertEquals($this->validator->isValid(Query::limit(0)), true, $this->validator->getDescription()); +// $this->assertEquals($this->validator->isValid(Query::limit(100)), true, $this->validator->getDescription()); +// +// // Test for Failure +// $this->assertEquals($this->validator->isValid(Query::limit(-1)), false, $this->validator->getDescription()); +// $this->assertEquals($this->validator->isValid(Query::limit(101)), false, $this->validator->getDescription()); +// } +//} diff --git a/tests/unit/Utopia/Database/Validator/Query/OffsetTest.php b/tests/unit/Utopia/Database/Validator/Query/OffsetTest.php index 4a29117e83..fb28b09116 100644 --- a/tests/unit/Utopia/Database/Validator/Query/OffsetTest.php +++ b/tests/unit/Utopia/Database/Validator/Query/OffsetTest.php @@ -1,41 +1,41 @@ validator = new Offset(5000); - } - - public function tearDown(): void - { - } - - public function testValue(): void - { - // Test for Success - $this->assertEquals($this->validator->isValid(Query::offset(1)), true, $this->validator->getDescription()); - $this->assertEquals($this->validator->isValid(Query::offset(0)), true, $this->validator->getDescription()); - $this->assertEquals($this->validator->isValid(Query::offset(5000)), true, $this->validator->getDescription()); - - // Test for Failure - $this->assertEquals($this->validator->isValid(Query::offset(-1)), false, $this->validator->getDescription()); - $this->assertEquals($this->validator->isValid(Query::offset(5001)), false, $this->validator->getDescription()); - $this->assertEquals($this->validator->isValid(Query::equal('attr', ['v'])), false, $this->validator->getDescription()); - $this->assertEquals($this->validator->isValid(Query::orderAsc('attr')), false, $this->validator->getDescription()); - $this->assertEquals($this->validator->isValid(Query::orderDesc('attr')), false, $this->validator->getDescription()); - $this->assertEquals($this->validator->isValid(Query::limit(100)), false, $this->validator->getDescription()); - } -} +// +//namespace Tests\Unit\Utopia\Database\Validator\Query; +// +//use Appwrite\Utopia\Database\Validator\Query\Base; +//use Appwrite\Utopia\Database\Validator\Query\Offset; +//use Utopia\Database\Query; +//use PHPUnit\Framework\TestCase; +// +//class OffsetTest extends TestCase +//{ +// /** +// * @var Base +// */ +// protected $validator = null; +// +// public function setUp(): void +// { +// $this->validator = new Offset(5000); +// } +// +// public function tearDown(): void +// { +// } +// +// public function testValue(): void +// { +// // Test for Success +// $this->assertEquals($this->validator->isValid(Query::offset(1)), true, $this->validator->getDescription()); +// $this->assertEquals($this->validator->isValid(Query::offset(0)), true, $this->validator->getDescription()); +// $this->assertEquals($this->validator->isValid(Query::offset(5000)), true, $this->validator->getDescription()); +// +// // Test for Failure +// $this->assertEquals($this->validator->isValid(Query::offset(-1)), false, $this->validator->getDescription()); +// $this->assertEquals($this->validator->isValid(Query::offset(5001)), false, $this->validator->getDescription()); +// $this->assertEquals($this->validator->isValid(Query::equal('attr', ['v'])), false, $this->validator->getDescription()); +// $this->assertEquals($this->validator->isValid(Query::orderAsc('attr')), false, $this->validator->getDescription()); +// $this->assertEquals($this->validator->isValid(Query::orderDesc('attr')), false, $this->validator->getDescription()); +// $this->assertEquals($this->validator->isValid(Query::limit(100)), false, $this->validator->getDescription()); +// } +//} diff --git a/tests/unit/Utopia/Database/Validator/Query/OrderTest.php b/tests/unit/Utopia/Database/Validator/Query/OrderTest.php index fe1b42d5c1..f1587e3ef1 100644 --- a/tests/unit/Utopia/Database/Validator/Query/OrderTest.php +++ b/tests/unit/Utopia/Database/Validator/Query/OrderTest.php @@ -1,55 +1,55 @@ validator = new Order( - attributes: [ - new Document([ - 'key' => 'attr', - 'type' => Database::VAR_STRING, - 'array' => false, - ]), - ], - ); - } - - public function tearDown(): void - { - } - - public function testValue(): void - { - // Test for Success - $this->assertEquals($this->validator->isValid(Query::orderAsc('attr')), true, $this->validator->getDescription()); - $this->assertEquals($this->validator->isValid(Query::orderAsc('')), true, $this->validator->getDescription()); - $this->assertEquals($this->validator->isValid(Query::orderDesc('attr')), true, $this->validator->getDescription()); - $this->assertEquals($this->validator->isValid(Query::orderDesc('')), true, $this->validator->getDescription()); - - // Test for Failure - $this->assertEquals($this->validator->isValid(Query::limit(-1)), false, $this->validator->getDescription()); - $this->assertEquals($this->validator->isValid(Query::limit(101)), false, $this->validator->getDescription()); - $this->assertEquals($this->validator->isValid(Query::offset(-1)), false, $this->validator->getDescription()); - $this->assertEquals($this->validator->isValid(Query::offset(5001)), false, $this->validator->getDescription()); - $this->assertEquals($this->validator->isValid(Query::equal('attr', ['v'])), false, $this->validator->getDescription()); - $this->assertEquals($this->validator->isValid(Query::equal('dne', ['v'])), false, $this->validator->getDescription()); - $this->assertEquals($this->validator->isValid(Query::equal('', ['v'])), false, $this->validator->getDescription()); - $this->assertEquals($this->validator->isValid(Query::orderDesc('dne')), false, $this->validator->getDescription()); - $this->assertEquals($this->validator->isValid(Query::orderAsc('dne')), false, $this->validator->getDescription()); - } -} +// +//namespace Tests\Unit\Utopia\Database\Validator\Query; +// +//use Appwrite\Utopia\Database\Validator\Query\Base; +//use Appwrite\Utopia\Database\Validator\Query\Order; +//use Utopia\Database\Database; +//use Utopia\Database\Document; +//use Utopia\Database\Query; +//use PHPUnit\Framework\TestCase; +// +//class OrderTest extends TestCase +//{ +// /** +// * @var Base +// */ +// protected $validator = null; +// +// public function setUp(): void +// { +// $this->validator = new Order( +// attributes: [ +// new Document([ +// 'key' => 'attr', +// 'type' => Database::VAR_STRING, +// 'array' => false, +// ]), +// ], +// ); +// } +// +// public function tearDown(): void +// { +// } +// +// public function testValue(): void +// { +// // Test for Success +// $this->assertEquals($this->validator->isValid(Query::orderAsc('attr')), true, $this->validator->getDescription()); +// $this->assertEquals($this->validator->isValid(Query::orderAsc('')), true, $this->validator->getDescription()); +// $this->assertEquals($this->validator->isValid(Query::orderDesc('attr')), true, $this->validator->getDescription()); +// $this->assertEquals($this->validator->isValid(Query::orderDesc('')), true, $this->validator->getDescription()); +// +// // Test for Failure +// $this->assertEquals($this->validator->isValid(Query::limit(-1)), false, $this->validator->getDescription()); +// $this->assertEquals($this->validator->isValid(Query::limit(101)), false, $this->validator->getDescription()); +// $this->assertEquals($this->validator->isValid(Query::offset(-1)), false, $this->validator->getDescription()); +// $this->assertEquals($this->validator->isValid(Query::offset(5001)), false, $this->validator->getDescription()); +// $this->assertEquals($this->validator->isValid(Query::equal('attr', ['v'])), false, $this->validator->getDescription()); +// $this->assertEquals($this->validator->isValid(Query::equal('dne', ['v'])), false, $this->validator->getDescription()); +// $this->assertEquals($this->validator->isValid(Query::equal('', ['v'])), false, $this->validator->getDescription()); +// $this->assertEquals($this->validator->isValid(Query::orderDesc('dne')), false, $this->validator->getDescription()); +// $this->assertEquals($this->validator->isValid(Query::orderAsc('dne')), false, $this->validator->getDescription()); +// } +//} diff --git a/tests/unit/Utopia/Database/Validator/Query/SelectTest.php b/tests/unit/Utopia/Database/Validator/Query/SelectTest.php index ff2db35eb4..2b2bf39070 100644 --- a/tests/unit/Utopia/Database/Validator/Query/SelectTest.php +++ b/tests/unit/Utopia/Database/Validator/Query/SelectTest.php @@ -1,45 +1,45 @@ validator = new Select( - attributes: [ - new Document([ - 'key' => 'attr', - 'type' => Database::VAR_STRING, - 'array' => false, - ]), - ], - ); - } - - public function tearDown(): void - { - } - - public function testValue(): void - { - // Test for Success - $this->assertEquals($this->validator->isValid(Query::select(['*', 'attr'])), true, $this->validator->getDescription()); - - // Test for Failure - $this->assertEquals($this->validator->isValid(Query::limit(1)), false, $this->validator->getDescription()); - } -} +// +//namespace Tests\Unit\Utopia\Database\Validator\Query; +// +//use Appwrite\Utopia\Database\Validator\Query\Base; +//use Appwrite\Utopia\Database\Validator\Query\Order; +//use Appwrite\Utopia\Database\Validator\Query\Select; +//use Utopia\Database\Database; +//use Utopia\Database\Document; +//use Utopia\Database\Query; +//use PHPUnit\Framework\TestCase; +// +//class SelectTest extends TestCase +//{ +// /** +// * @var Base +// */ +// protected $validator = null; +// +// public function setUp(): void +// { +// $this->validator = new Select( +// attributes: [ +// new Document([ +// 'key' => 'attr', +// 'type' => Database::VAR_STRING, +// 'array' => false, +// ]), +// ], +// ); +// } +// +// public function tearDown(): void +// { +// } +// +// public function testValue(): void +// { +// // Test for Success +// $this->assertEquals($this->validator->isValid(Query::select(['*', 'attr'])), true, $this->validator->getDescription()); +// +// // Test for Failure +// $this->assertEquals($this->validator->isValid(Query::limit(1)), false, $this->validator->getDescription()); +// } +//} From e631453e3b92edd15e0dfa60a617be4134ea5487 Mon Sep 17 00:00:00 2001 From: fogelito Date: Thu, 27 Apr 2023 09:59:55 +0300 Subject: [PATCH 15/46] documents name changes --- app/controllers/api/databases.php | 6 ++++-- composer.lock | 8 ++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index 28caa9c3b2..a0048773e4 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -46,8 +46,10 @@ use Appwrite\Event\Event; use Utopia\Database\Validator\Queries; use Appwrite\Utopia\Database\Validator\Queries\Collections; use Appwrite\Utopia\Database\Validator\Queries\Databases; -use Appwrite\Utopia\Database\Validator\Queries\Document as DocumentValidator; -use Appwrite\Utopia\Database\Validator\Queries\Documents; +//use Appwrite\Utopia\Database\Validator\Queries\Document as DocumentValidator; +//use Appwrite\Utopia\Database\Validator\Queries\Documents; +use Utopia\Database\Validator\Documents; +use Utopia\Database\Validator\DocumentValidator; use Utopia\Config\Config; use MaxMind\Db\Reader; use Utopia\Validator\Nullable; diff --git a/composer.lock b/composer.lock index e71d901cfb..eabb545ebc 100644 --- a/composer.lock +++ b/composer.lock @@ -2113,12 +2113,12 @@ "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "00f473bff5f70a86be11519bdb0eca61af740f2a" + "reference": "94bca644f3ff418e6742e89fcf571c2c342adcd6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/00f473bff5f70a86be11519bdb0eca61af740f2a", - "reference": "00f473bff5f70a86be11519bdb0eca61af740f2a", + "url": "https://api.github.com/repos/utopia-php/database/zipball/94bca644f3ff418e6742e89fcf571c2c342adcd6", + "reference": "94bca644f3ff418e6742e89fcf571c2c342adcd6", "shasum": "" }, "require": { @@ -2163,7 +2163,7 @@ "issues": "https://github.com/utopia-php/database/issues", "source": "https://github.com/utopia-php/database/tree/appwrite-validators" }, - "time": "2023-04-25T09:59:20+00:00" + "time": "2023-04-27T06:57:58+00:00" }, { "name": "utopia-php/domains", From 0460b59cdc0d3e19298a9619e6924bb4c2636fe4 Mon Sep 17 00:00:00 2001 From: fogelito Date: Thu, 27 Apr 2023 14:59:05 +0300 Subject: [PATCH 16/46] Namespace Changes --- app/controllers/api/databases.php | 8 ++- composer.lock | 8 +-- src/Appwrite/GraphQL/Types/Mapper.php | 4 +- .../Specification/Format/OpenAPI3.php | 4 +- .../Specification/Format/Swagger2.php | 4 +- .../Database/Validator/Queries/Document.php | 41 --------------- .../Database/Validator/Queries/Documents.php | 52 ------------------- 7 files changed, 13 insertions(+), 108 deletions(-) delete mode 100644 src/Appwrite/Utopia/Database/Validator/Queries/Document.php delete mode 100644 src/Appwrite/Utopia/Database/Validator/Queries/Documents.php diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index a0048773e4..c997ae6315 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -46,10 +46,8 @@ use Appwrite\Event\Event; use Utopia\Database\Validator\Queries; use Appwrite\Utopia\Database\Validator\Queries\Collections; use Appwrite\Utopia\Database\Validator\Queries\Databases; -//use Appwrite\Utopia\Database\Validator\Queries\Document as DocumentValidator; -//use Appwrite\Utopia\Database\Validator\Queries\Documents; -use Utopia\Database\Validator\Documents; -use Utopia\Database\Validator\DocumentValidator; +use Utopia\Database\Validator\Queries\Documents as DocumentsValidator; +use Utopia\Database\Validator\Queries\Document as DocumentValidator; use Utopia\Config\Config; use MaxMind\Db\Reader; use Utopia\Validator\Nullable; @@ -2875,7 +2873,7 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/documents') } // Validate queries - $queriesValidator = new Documents($collection->getAttribute('attributes'), $collection->getAttribute('indexes')); + $queriesValidator = new DocumentsValidator($collection->getAttribute('attributes'), $collection->getAttribute('indexes')); $validQueries = $queriesValidator->isValid($queries); if (!$validQueries) { throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, $queriesValidator->getDescription()); diff --git a/composer.lock b/composer.lock index eabb545ebc..d795f012dd 100644 --- a/composer.lock +++ b/composer.lock @@ -2113,12 +2113,12 @@ "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "94bca644f3ff418e6742e89fcf571c2c342adcd6" + "reference": "e56f580f304c70a55f3d75c6d3ab554c7e687789" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/94bca644f3ff418e6742e89fcf571c2c342adcd6", - "reference": "94bca644f3ff418e6742e89fcf571c2c342adcd6", + "url": "https://api.github.com/repos/utopia-php/database/zipball/e56f580f304c70a55f3d75c6d3ab554c7e687789", + "reference": "e56f580f304c70a55f3d75c6d3ab554c7e687789", "shasum": "" }, "require": { @@ -2163,7 +2163,7 @@ "issues": "https://github.com/utopia-php/database/issues", "source": "https://github.com/utopia-php/database/tree/appwrite-validators" }, - "time": "2023-04-27T06:57:58+00:00" + "time": "2023-04-27T08:18:20+00:00" }, { "name": "utopia-php/domains", diff --git a/src/Appwrite/GraphQL/Types/Mapper.php b/src/Appwrite/GraphQL/Types/Mapper.php index 9a6eb123c5..9d2705baa7 100644 --- a/src/Appwrite/GraphQL/Types/Mapper.php +++ b/src/Appwrite/GraphQL/Types/Mapper.php @@ -254,14 +254,14 @@ class Mapper case 'Appwrite\Utopia\Database\Validator\Queries\Collections': case 'Appwrite\Utopia\Database\Validator\Queries\Databases': case 'Appwrite\Utopia\Database\Validator\Queries\Deployments': - case 'Appwrite\Utopia\Database\Validator\Queries\Documents': + case 'Utopia\Database\Validator\Queries\Documents': case 'Appwrite\Utopia\Database\Validator\Queries\Executions': case 'Appwrite\Utopia\Database\Validator\Queries\Files': case 'Appwrite\Utopia\Database\Validator\Queries\Functions': case 'Appwrite\Utopia\Database\Validator\Queries\Memberships': case 'Utopia\Database\Validator\Permissions': case 'Appwrite\Utopia\Database\Validator\Queries\Projects': - case 'Appwrite\Utopia\Database\Validator\Queries': + case 'Utopia\Database\Validator\Queries': case 'Utopia\Database\Validator\Roles': case 'Appwrite\Utopia\Database\Validator\Queries\Teams': case 'Appwrite\Utopia\Database\Validator\Queries\Users': diff --git a/src/Appwrite/Specification/Format/OpenAPI3.php b/src/Appwrite/Specification/Format/OpenAPI3.php index 46db262d3b..bf0293d5af 100644 --- a/src/Appwrite/Specification/Format/OpenAPI3.php +++ b/src/Appwrite/Specification/Format/OpenAPI3.php @@ -345,7 +345,7 @@ class OpenAPI3 extends Format case 'Appwrite\Utopia\Database\Validator\Queries\Collections': case 'Appwrite\Utopia\Database\Validator\Queries\Databases': case 'Appwrite\Utopia\Database\Validator\Queries\Deployments': - case 'Appwrite\Utopia\Database\Validator\Queries\Documents': + case 'Utopia\Database\Validator\Queries\Documents': case 'Appwrite\Utopia\Database\Validator\Queries\Executions': case 'Appwrite\Utopia\Database\Validator\Queries\Files': case 'Appwrite\Utopia\Database\Validator\Queries\Functions': @@ -354,7 +354,7 @@ class OpenAPI3 extends Format case 'Appwrite\Utopia\Database\Validator\Queries\Teams': case 'Appwrite\Utopia\Database\Validator\Queries\Users': case 'Appwrite\Utopia\Database\Validator\Queries\Variables': - case 'Appwrite\Utopia\Database\Validator\Queries': + case 'Utopia\Database\Validator\Queries': $node['schema']['type'] = 'array'; $node['schema']['items'] = [ 'type' => 'string', diff --git a/src/Appwrite/Specification/Format/Swagger2.php b/src/Appwrite/Specification/Format/Swagger2.php index 422f164fa6..60974bef85 100644 --- a/src/Appwrite/Specification/Format/Swagger2.php +++ b/src/Appwrite/Specification/Format/Swagger2.php @@ -344,7 +344,7 @@ class Swagger2 extends Format case 'Appwrite\Utopia\Database\Validator\Queries\Collections': case 'Appwrite\Utopia\Database\Validator\Queries\Databases': case 'Appwrite\Utopia\Database\Validator\Queries\Deployments': - case 'Appwrite\Utopia\Database\Validator\Queries\Documents': + case 'Utopia\Database\Validator\Queries\Documents': case 'Appwrite\Utopia\Database\Validator\Queries\Executions': case 'Appwrite\Utopia\Database\Validator\Queries\Files': case 'Appwrite\Utopia\Database\Validator\Queries\Functions': @@ -353,7 +353,7 @@ class Swagger2 extends Format case 'Appwrite\Utopia\Database\Validator\Queries\Teams': case 'Appwrite\Utopia\Database\Validator\Queries\Users': case 'Appwrite\Utopia\Database\Validator\Queries\Variables': - case 'Appwrite\Utopia\Database\Validator\Queries': + case 'Utopia\Database\Validator\Queries': $node['type'] = 'array'; $node['collectionFormat'] = 'multi'; $node['items'] = [ diff --git a/src/Appwrite/Utopia/Database/Validator/Queries/Document.php b/src/Appwrite/Utopia/Database/Validator/Queries/Document.php deleted file mode 100644 index f8e0e2f065..0000000000 --- a/src/Appwrite/Utopia/Database/Validator/Queries/Document.php +++ /dev/null @@ -1,41 +0,0 @@ - '$id', - 'type' => Database::VAR_STRING, - 'array' => false, - ]); - $attributes[] = new \Utopia\Database\Document([ - 'key' => '$createdAt', - 'type' => Database::VAR_DATETIME, - 'array' => false, - ]); - $attributes[] = new \Utopia\Database\Document([ - 'key' => '$updatedAt', - 'type' => Database::VAR_DATETIME, - 'array' => false, - ]); - - $validators = [ - new Select($attributes), - ]; - - parent::__construct(...$validators); - } -} diff --git a/src/Appwrite/Utopia/Database/Validator/Queries/Documents.php b/src/Appwrite/Utopia/Database/Validator/Queries/Documents.php deleted file mode 100644 index d7caf7cdea..0000000000 --- a/src/Appwrite/Utopia/Database/Validator/Queries/Documents.php +++ /dev/null @@ -1,52 +0,0 @@ - '$id', - 'type' => Database::VAR_STRING, - 'array' => false, - ]); - $attributes[] = new Document([ - 'key' => '$createdAt', - 'type' => Database::VAR_DATETIME, - 'array' => false, - ]); - $attributes[] = new Document([ - 'key' => '$updatedAt', - 'type' => Database::VAR_DATETIME, - 'array' => false, - ]); - - $validators = [ - new Limit(), - new Offset(), - new Cursor(), - new Filter($attributes), - new Order($attributes), - new Select($attributes), - ]; - - parent::__construct($attributes, $indexes, ...$validators); - } -} From 9e5af4c0464429af650776d37ef557f647ca9e07 Mon Sep 17 00:00:00 2001 From: fogelito Date: Thu, 27 Apr 2023 15:01:40 +0300 Subject: [PATCH 17/46] Alias change --- app/controllers/api/databases.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index c997ae6315..a2887c17cf 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -46,8 +46,8 @@ use Appwrite\Event\Event; use Utopia\Database\Validator\Queries; use Appwrite\Utopia\Database\Validator\Queries\Collections; use Appwrite\Utopia\Database\Validator\Queries\Databases; -use Utopia\Database\Validator\Queries\Documents as DocumentsValidator; -use Utopia\Database\Validator\Queries\Document as DocumentValidator; +use Utopia\Database\Validator\Queries\Documents as QueriesDocumentsValidator; +use Utopia\Database\Validator\Queries\Document as QueriesDocumentValidator; use Utopia\Config\Config; use MaxMind\Db\Reader; use Utopia\Validator\Nullable; @@ -2873,7 +2873,7 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/documents') } // Validate queries - $queriesValidator = new DocumentsValidator($collection->getAttribute('attributes'), $collection->getAttribute('indexes')); + $queriesValidator = new QueriesDocumentsValidator($collection->getAttribute('attributes'), $collection->getAttribute('indexes')); $validQueries = $queriesValidator->isValid($queries); if (!$validQueries) { throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, $queriesValidator->getDescription()); @@ -3027,7 +3027,7 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/documents/:documen } // Validate queries - $queriesValidator = new DocumentValidator($collection->getAttribute('attributes')); + $queriesValidator = new QueriesDocumentValidator($collection->getAttribute('attributes')); $validQueries = $queriesValidator->isValid($queries); if (!$validQueries) { throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, $queriesValidator->getDescription()); From 36dee1f345f33eb45e7f1b403650286be412dd38 Mon Sep 17 00:00:00 2001 From: fogelito Date: Thu, 27 Apr 2023 15:10:07 +0300 Subject: [PATCH 18/46] Alias change --- app/controllers/api/databases.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index a2887c17cf..21858555a6 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -46,8 +46,8 @@ use Appwrite\Event\Event; use Utopia\Database\Validator\Queries; use Appwrite\Utopia\Database\Validator\Queries\Collections; use Appwrite\Utopia\Database\Validator\Queries\Databases; -use Utopia\Database\Validator\Queries\Documents as QueriesDocumentsValidator; -use Utopia\Database\Validator\Queries\Document as QueriesDocumentValidator; +use Utopia\Database\Validator\Queries\Documents as DocumentsQueriesValidator; +use Utopia\Database\Validator\Queries\Document as DocumentQueriesValidator; use Utopia\Config\Config; use MaxMind\Db\Reader; use Utopia\Validator\Nullable; @@ -2873,7 +2873,7 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/documents') } // Validate queries - $queriesValidator = new QueriesDocumentsValidator($collection->getAttribute('attributes'), $collection->getAttribute('indexes')); + $queriesValidator = new DocumentsQueriesValidator($collection->getAttribute('attributes'), $collection->getAttribute('indexes')); $validQueries = $queriesValidator->isValid($queries); if (!$validQueries) { throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, $queriesValidator->getDescription()); @@ -3027,7 +3027,7 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/documents/:documen } // Validate queries - $queriesValidator = new QueriesDocumentValidator($collection->getAttribute('attributes')); + $queriesValidator = new DocumentQueriesValidator($collection->getAttribute('attributes')); $validQueries = $queriesValidator->isValid($queries); if (!$validQueries) { throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, $queriesValidator->getDescription()); From fd9b6aba55271cdcc8bea63d28553a9c36e7878e Mon Sep 17 00:00:00 2001 From: fogelito Date: Thu, 27 Apr 2023 17:21:51 +0300 Subject: [PATCH 19/46] format --- tests/unit/Utopia/Database/Validator/IndexedQueriesTest.php | 1 + tests/unit/Utopia/Database/Validator/QueriesTest.php | 1 + tests/unit/Utopia/Database/Validator/Query/CursorTest.php | 1 + tests/unit/Utopia/Database/Validator/Query/FilterTest.php | 1 + tests/unit/Utopia/Database/Validator/Query/LimitTest.php | 1 + tests/unit/Utopia/Database/Validator/Query/OffsetTest.php | 1 + tests/unit/Utopia/Database/Validator/Query/OrderTest.php | 1 + tests/unit/Utopia/Database/Validator/Query/SelectTest.php | 1 + 8 files changed, 8 insertions(+) diff --git a/tests/unit/Utopia/Database/Validator/IndexedQueriesTest.php b/tests/unit/Utopia/Database/Validator/IndexedQueriesTest.php index 3092029222..ad27200e74 100644 --- a/tests/unit/Utopia/Database/Validator/IndexedQueriesTest.php +++ b/tests/unit/Utopia/Database/Validator/IndexedQueriesTest.php @@ -1,4 +1,5 @@ Date: Sun, 30 Apr 2023 09:41:00 +0300 Subject: [PATCH 20/46] Remove OrderAttributes Class --- composer.lock | 8 +++--- .../Database/Validator/OrderAttributes.php | 26 ------------------- 2 files changed, 4 insertions(+), 30 deletions(-) delete mode 100644 src/Appwrite/Utopia/Database/Validator/OrderAttributes.php diff --git a/composer.lock b/composer.lock index d795f012dd..9247175eb6 100644 --- a/composer.lock +++ b/composer.lock @@ -2113,12 +2113,12 @@ "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "e56f580f304c70a55f3d75c6d3ab554c7e687789" + "reference": "52f351230fab5922c6b63bd19b0bf4891d940d8f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/e56f580f304c70a55f3d75c6d3ab554c7e687789", - "reference": "e56f580f304c70a55f3d75c6d3ab554c7e687789", + "url": "https://api.github.com/repos/utopia-php/database/zipball/52f351230fab5922c6b63bd19b0bf4891d940d8f", + "reference": "52f351230fab5922c6b63bd19b0bf4891d940d8f", "shasum": "" }, "require": { @@ -2163,7 +2163,7 @@ "issues": "https://github.com/utopia-php/database/issues", "source": "https://github.com/utopia-php/database/tree/appwrite-validators" }, - "time": "2023-04-27T08:18:20+00:00" + "time": "2023-04-27T15:49:03+00:00" }, { "name": "utopia-php/domains", diff --git a/src/Appwrite/Utopia/Database/Validator/OrderAttributes.php b/src/Appwrite/Utopia/Database/Validator/OrderAttributes.php deleted file mode 100644 index dcf38c90f1..0000000000 --- a/src/Appwrite/Utopia/Database/Validator/OrderAttributes.php +++ /dev/null @@ -1,26 +0,0 @@ -getAttribute('status') === 'available'; - }); - - parent::__construct($attributes, $indexes, $strict); - } -} From ce40d3c2c5b805ba26c215f35487e5f29c269aee Mon Sep 17 00:00:00 2001 From: fogelito Date: Sun, 30 Apr 2023 13:00:39 +0300 Subject: [PATCH 21/46] Remove test moved to Utopia --- .../Database/Validator/IndexedQueriesTest.php | 122 ------------------ .../Utopia/Database/Validator/QueriesTest.php | 77 ----------- .../Database/Validator/Query/CursorTest.php | 42 ------ .../Database/Validator/Query/FilterTest.php | 65 ---------- .../Database/Validator/Query/LimitTest.php | 38 ------ .../Database/Validator/Query/OffsetTest.php | 42 ------ .../Database/Validator/Query/OrderTest.php | 56 -------- .../Database/Validator/Query/SelectTest.php | 46 ------- 8 files changed, 488 deletions(-) delete mode 100644 tests/unit/Utopia/Database/Validator/IndexedQueriesTest.php delete mode 100644 tests/unit/Utopia/Database/Validator/QueriesTest.php delete mode 100644 tests/unit/Utopia/Database/Validator/Query/CursorTest.php delete mode 100644 tests/unit/Utopia/Database/Validator/Query/FilterTest.php delete mode 100644 tests/unit/Utopia/Database/Validator/Query/LimitTest.php delete mode 100644 tests/unit/Utopia/Database/Validator/Query/OffsetTest.php delete mode 100644 tests/unit/Utopia/Database/Validator/Query/OrderTest.php delete mode 100644 tests/unit/Utopia/Database/Validator/Query/SelectTest.php diff --git a/tests/unit/Utopia/Database/Validator/IndexedQueriesTest.php b/tests/unit/Utopia/Database/Validator/IndexedQueriesTest.php deleted file mode 100644 index ad27200e74..0000000000 --- a/tests/unit/Utopia/Database/Validator/IndexedQueriesTest.php +++ /dev/null @@ -1,122 +0,0 @@ -assertEquals(true, $validator->isValid([])); -// } -// -// public function testInvalidQuery(): void -// { -// $validator = new IndexedQueries(); -// -// $this->assertEquals(false, $validator->isValid(["this.is.invalid"])); -// } -// -// public function testInvalidMethod(): void -// { -// $validator = new IndexedQueries(); -// $this->assertEquals(false, $validator->isValid(['equal("attr", "value")'])); -// -// $validator = new IndexedQueries([], [], new Limit()); -// $this->assertEquals(false, $validator->isValid(['equal("attr", "value")'])); -// } -// -// public function testInvalidValue(): void -// { -// $validator = new IndexedQueries([], [], new Limit()); -// $this->assertEquals(false, $validator->isValid(['limit(-1)'])); -// } -// -// public function testValid(): void -// { -// $attributes = [ -// new Document([ -// 'key' => 'name', -// 'type' => Database::VAR_STRING, -// 'array' => false, -// ]), -// ]; -// $indexes = [ -// new Document([ -// 'status' => 'available', -// 'type' => Database::INDEX_KEY, -// 'attributes' => ['name'], -// ]), -// new Document([ -// 'status' => 'available', -// 'type' => Database::INDEX_FULLTEXT, -// 'attributes' => ['name'], -// ]), -// ]; -// $validator = new IndexedQueries( -// $attributes, -// $indexes, -// new Cursor(), -// new Filter($attributes), -// new Limit(), -// new Offset(), -// new Order($attributes), -// ); -// $this->assertEquals(true, $validator->isValid(['cursorAfter("asdf")']), $validator->getDescription()); -// $this->assertEquals(true, $validator->isValid(['equal("name", "value")']), $validator->getDescription()); -// $this->assertEquals(true, $validator->isValid(['limit(10)']), $validator->getDescription()); -// $this->assertEquals(true, $validator->isValid(['offset(10)']), $validator->getDescription()); -// $this->assertEquals(true, $validator->isValid(['orderAsc("name")']), $validator->getDescription()); -// $this->assertEquals(true, $validator->isValid(['search("name", "value")']), $validator->getDescription()); -// } -// -// public function testMissingIndex(): void -// { -// $attributes = [ -// new Document([ -// 'key' => 'name', -// 'type' => Database::VAR_STRING, -// 'array' => false, -// ]), -// ]; -// $indexes = [ -// new Document([ -// 'status' => 'available', -// 'type' => Database::INDEX_KEY, -// 'attributes' => ['name'], -// ]), -// ]; -// $validator = new IndexedQueries( -// $attributes, -// $indexes, -// new Cursor(), -// new Filter($attributes), -// new Limit(), -// new Offset(), -// new Order($attributes), -// ); -// $this->assertEquals(false, $validator->isValid(['equal("dne", "value")']), $validator->getDescription()); -// $this->assertEquals(false, $validator->isValid(['orderAsc("dne")']), $validator->getDescription()); -// $this->assertEquals(false, $validator->isValid(['search("name", "value")']), $validator->getDescription()); -// } -//} diff --git a/tests/unit/Utopia/Database/Validator/QueriesTest.php b/tests/unit/Utopia/Database/Validator/QueriesTest.php deleted file mode 100644 index fbcd6d685a..0000000000 --- a/tests/unit/Utopia/Database/Validator/QueriesTest.php +++ /dev/null @@ -1,77 +0,0 @@ -assertEquals(true, $validator->isValid([])); -// } -// -// public function testInvalidQuery(): void -// { -// $validator = new Queries(); -// -// $this->assertEquals(false, $validator->isValid(["this.is.invalid"])); -// } -// -// public function testInvalidMethod(): void -// { -// $validator = new Queries(); -// $this->assertEquals(false, $validator->isValid(['equal("attr", "value")'])); -// -// $validator = new Queries(new Limit()); -// $this->assertEquals(false, $validator->isValid(['equal("attr", "value")'])); -// } -// -// public function testInvalidValue(): void -// { -// $validator = new Queries(new Limit()); -// $this->assertEquals(false, $validator->isValid(['limit(-1)'])); -// } -// -// public function testValid(): void -// { -// $attributes = [ -// new Document([ -// 'key' => 'name', -// 'type' => Database::VAR_STRING, -// 'array' => false, -// ]) -// ]; -// $validator = new Queries( -// new Cursor(), -// new Filter($attributes), -// new Limit(), -// new Offset(), -// new Order($attributes), -// ); -// $this->assertEquals(true, $validator->isValid(['cursorAfter("asdf")']), $validator->getDescription()); -// $this->assertEquals(true, $validator->isValid(['equal("name", "value")']), $validator->getDescription()); -// $this->assertEquals(true, $validator->isValid(['limit(10)']), $validator->getDescription()); -// $this->assertEquals(true, $validator->isValid(['offset(10)']), $validator->getDescription()); -// $this->assertEquals(true, $validator->isValid(['orderAsc("name")']), $validator->getDescription()); -// } -//} diff --git a/tests/unit/Utopia/Database/Validator/Query/CursorTest.php b/tests/unit/Utopia/Database/Validator/Query/CursorTest.php deleted file mode 100644 index 92cebcfad7..0000000000 --- a/tests/unit/Utopia/Database/Validator/Query/CursorTest.php +++ /dev/null @@ -1,42 +0,0 @@ -validator = new Cursor(); -// } -// -// public function tearDown(): void -// { -// } -// -// public function testValue(): void -// { -// // Test for Success -// $this->assertEquals($this->validator->isValid(new Query(Query::TYPE_CURSORAFTER, values: ['asdf'])), true, $this->validator->getDescription()); -// $this->assertEquals($this->validator->isValid(new Query(Query::TYPE_CURSORBEFORE, values: ['asdf'])), true, $this->validator->getDescription()); -// -// // Test for Failure -// $this->assertEquals($this->validator->isValid(Query::limit(-1)), false, $this->validator->getDescription()); -// $this->assertEquals($this->validator->isValid(Query::limit(101)), false, $this->validator->getDescription()); -// $this->assertEquals($this->validator->isValid(Query::offset(-1)), false, $this->validator->getDescription()); -// $this->assertEquals($this->validator->isValid(Query::offset(5001)), false, $this->validator->getDescription()); -// $this->assertEquals($this->validator->isValid(Query::equal('attr', ['v'])), false, $this->validator->getDescription()); -// $this->assertEquals($this->validator->isValid(Query::orderAsc('attr')), false, $this->validator->getDescription()); -// $this->assertEquals($this->validator->isValid(Query::orderDesc('attr')), false, $this->validator->getDescription()); -// } -//} diff --git a/tests/unit/Utopia/Database/Validator/Query/FilterTest.php b/tests/unit/Utopia/Database/Validator/Query/FilterTest.php deleted file mode 100644 index 26bac48268..0000000000 --- a/tests/unit/Utopia/Database/Validator/Query/FilterTest.php +++ /dev/null @@ -1,65 +0,0 @@ -validator = new Filter( -// attributes: [ -// new Document([ -// 'key' => 'attr', -// 'type' => Database::VAR_STRING, -// 'array' => false, -// ]), -// ], -// ); -// } -// -// public function tearDown(): void -// { -// } -// -// public function testValue(): void -// { -// // Test for Success -// $this->assertEquals($this->validator->isValid(Query::between('attr', '1975-12-06', '2050-12-06')), true, $this->validator->getDescription()); -// $this->assertEquals($this->validator->isValid(Query::isNotNull('attr')), true, $this->validator->getDescription()); -// $this->assertEquals($this->validator->isValid(Query::isNull('attr')), true, $this->validator->getDescription()); -// $this->assertEquals($this->validator->isValid(Query::startsWith('attr', 'super')), true, $this->validator->getDescription()); -// $this->assertEquals($this->validator->isValid(Query::endsWith('attr', 'man')), true, $this->validator->getDescription()); -// -// // Test for Failure -// $this->assertEquals($this->validator->isValid(Query::select(['attr'])), false, $this->validator->getDescription()); -// $this->assertEquals($this->validator->isValid(Query::limit(1)), false, $this->validator->getDescription()); -// $this->assertEquals($this->validator->isValid(Query::limit(0)), false, $this->validator->getDescription()); -// $this->assertEquals($this->validator->isValid(Query::limit(100)), false, $this->validator->getDescription()); -// $this->assertEquals($this->validator->isValid(Query::limit(-1)), false, $this->validator->getDescription()); -// $this->assertEquals($this->validator->isValid(Query::limit(101)), false, $this->validator->getDescription()); -// $this->assertEquals($this->validator->isValid(Query::offset(1)), false, $this->validator->getDescription()); -// $this->assertEquals($this->validator->isValid(Query::offset(0)), false, $this->validator->getDescription()); -// $this->assertEquals($this->validator->isValid(Query::offset(5000)), false, $this->validator->getDescription()); -// $this->assertEquals($this->validator->isValid(Query::offset(-1)), false, $this->validator->getDescription()); -// $this->assertEquals($this->validator->isValid(Query::offset(5001)), false, $this->validator->getDescription()); -// $this->assertEquals($this->validator->isValid(Query::equal('dne', ['v'])), false, $this->validator->getDescription()); -// $this->assertEquals($this->validator->isValid(Query::equal('', ['v'])), false, $this->validator->getDescription()); -// $this->assertEquals($this->validator->isValid(Query::orderAsc('attr')), false, $this->validator->getDescription()); -// $this->assertEquals($this->validator->isValid(Query::orderDesc('attr')), false, $this->validator->getDescription()); -// $this->assertEquals($this->validator->isValid(new Query(Query::TYPE_CURSORAFTER, values: ['asdf'])), false, $this->validator->getDescription()); -// $this->assertEquals($this->validator->isValid(new Query(Query::TYPE_CURSORBEFORE, values: ['asdf'])), false, $this->validator->getDescription()); -// } -//} diff --git a/tests/unit/Utopia/Database/Validator/Query/LimitTest.php b/tests/unit/Utopia/Database/Validator/Query/LimitTest.php deleted file mode 100644 index 32ad7e1d6a..0000000000 --- a/tests/unit/Utopia/Database/Validator/Query/LimitTest.php +++ /dev/null @@ -1,38 +0,0 @@ -validator = new Limit(100); -// } -// -// public function tearDown(): void -// { -// } -// -// public function testValue(): void -// { -// // Test for Success -// $this->assertEquals($this->validator->isValid(Query::limit(1)), true, $this->validator->getDescription()); -// $this->assertEquals($this->validator->isValid(Query::limit(0)), true, $this->validator->getDescription()); -// $this->assertEquals($this->validator->isValid(Query::limit(100)), true, $this->validator->getDescription()); -// -// // Test for Failure -// $this->assertEquals($this->validator->isValid(Query::limit(-1)), false, $this->validator->getDescription()); -// $this->assertEquals($this->validator->isValid(Query::limit(101)), false, $this->validator->getDescription()); -// } -//} diff --git a/tests/unit/Utopia/Database/Validator/Query/OffsetTest.php b/tests/unit/Utopia/Database/Validator/Query/OffsetTest.php deleted file mode 100644 index be25cd0953..0000000000 --- a/tests/unit/Utopia/Database/Validator/Query/OffsetTest.php +++ /dev/null @@ -1,42 +0,0 @@ -validator = new Offset(5000); -// } -// -// public function tearDown(): void -// { -// } -// -// public function testValue(): void -// { -// // Test for Success -// $this->assertEquals($this->validator->isValid(Query::offset(1)), true, $this->validator->getDescription()); -// $this->assertEquals($this->validator->isValid(Query::offset(0)), true, $this->validator->getDescription()); -// $this->assertEquals($this->validator->isValid(Query::offset(5000)), true, $this->validator->getDescription()); -// -// // Test for Failure -// $this->assertEquals($this->validator->isValid(Query::offset(-1)), false, $this->validator->getDescription()); -// $this->assertEquals($this->validator->isValid(Query::offset(5001)), false, $this->validator->getDescription()); -// $this->assertEquals($this->validator->isValid(Query::equal('attr', ['v'])), false, $this->validator->getDescription()); -// $this->assertEquals($this->validator->isValid(Query::orderAsc('attr')), false, $this->validator->getDescription()); -// $this->assertEquals($this->validator->isValid(Query::orderDesc('attr')), false, $this->validator->getDescription()); -// $this->assertEquals($this->validator->isValid(Query::limit(100)), false, $this->validator->getDescription()); -// } -//} diff --git a/tests/unit/Utopia/Database/Validator/Query/OrderTest.php b/tests/unit/Utopia/Database/Validator/Query/OrderTest.php deleted file mode 100644 index 240fab9363..0000000000 --- a/tests/unit/Utopia/Database/Validator/Query/OrderTest.php +++ /dev/null @@ -1,56 +0,0 @@ -validator = new Order( -// attributes: [ -// new Document([ -// 'key' => 'attr', -// 'type' => Database::VAR_STRING, -// 'array' => false, -// ]), -// ], -// ); -// } -// -// public function tearDown(): void -// { -// } -// -// public function testValue(): void -// { -// // Test for Success -// $this->assertEquals($this->validator->isValid(Query::orderAsc('attr')), true, $this->validator->getDescription()); -// $this->assertEquals($this->validator->isValid(Query::orderAsc('')), true, $this->validator->getDescription()); -// $this->assertEquals($this->validator->isValid(Query::orderDesc('attr')), true, $this->validator->getDescription()); -// $this->assertEquals($this->validator->isValid(Query::orderDesc('')), true, $this->validator->getDescription()); -// -// // Test for Failure -// $this->assertEquals($this->validator->isValid(Query::limit(-1)), false, $this->validator->getDescription()); -// $this->assertEquals($this->validator->isValid(Query::limit(101)), false, $this->validator->getDescription()); -// $this->assertEquals($this->validator->isValid(Query::offset(-1)), false, $this->validator->getDescription()); -// $this->assertEquals($this->validator->isValid(Query::offset(5001)), false, $this->validator->getDescription()); -// $this->assertEquals($this->validator->isValid(Query::equal('attr', ['v'])), false, $this->validator->getDescription()); -// $this->assertEquals($this->validator->isValid(Query::equal('dne', ['v'])), false, $this->validator->getDescription()); -// $this->assertEquals($this->validator->isValid(Query::equal('', ['v'])), false, $this->validator->getDescription()); -// $this->assertEquals($this->validator->isValid(Query::orderDesc('dne')), false, $this->validator->getDescription()); -// $this->assertEquals($this->validator->isValid(Query::orderAsc('dne')), false, $this->validator->getDescription()); -// } -//} diff --git a/tests/unit/Utopia/Database/Validator/Query/SelectTest.php b/tests/unit/Utopia/Database/Validator/Query/SelectTest.php deleted file mode 100644 index 8e0ccf46c8..0000000000 --- a/tests/unit/Utopia/Database/Validator/Query/SelectTest.php +++ /dev/null @@ -1,46 +0,0 @@ -validator = new Select( -// attributes: [ -// new Document([ -// 'key' => 'attr', -// 'type' => Database::VAR_STRING, -// 'array' => false, -// ]), -// ], -// ); -// } -// -// public function tearDown(): void -// { -// } -// -// public function testValue(): void -// { -// // Test for Success -// $this->assertEquals($this->validator->isValid(Query::select(['*', 'attr'])), true, $this->validator->getDescription()); -// -// // Test for Failure -// $this->assertEquals($this->validator->isValid(Query::limit(1)), false, $this->validator->getDescription()); -// } -//} From 5e4ff01568c8bc6c0930cd052070947bffc1dd2c Mon Sep 17 00:00:00 2001 From: fogelito Date: Mon, 1 May 2023 12:18:50 +0300 Subject: [PATCH 22/46] getByType --- app/controllers/api/databases.php | 6 +++--- app/controllers/api/functions.php | 6 +++--- app/controllers/api/projects.php | 2 +- app/controllers/api/storage.php | 4 ++-- app/controllers/api/teams.php | 4 ++-- app/controllers/api/users.php | 2 +- app/init.php | 2 +- composer.lock | 20 ++++++++++---------- 8 files changed, 23 insertions(+), 23 deletions(-) diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index 21858555a6..4e3d5bde5f 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -468,7 +468,7 @@ App::get('/v1/databases') } // Get cursor document if there was a cursor query - $cursor = Query::getByType($queries, Query::TYPE_CURSORAFTER, Query::TYPE_CURSORBEFORE); + $cursor = Query::getByType($queries, [Query::TYPE_CURSORAFTER, Query::TYPE_CURSORBEFORE]); $cursor = reset($cursor); if ($cursor) { /** @var Query $cursor */ @@ -794,7 +794,7 @@ App::get('/v1/databases/:databaseId/collections') } // Get cursor document if there was a cursor query - $cursor = Query::getByType($queries, Query::TYPE_CURSORAFTER, Query::TYPE_CURSORBEFORE); + $cursor = Query::getByType($queries, [Query::TYPE_CURSORAFTER, Query::TYPE_CURSORBEFORE]); $cursor = reset($cursor); if ($cursor) { /** @var Query $cursor */ @@ -2882,7 +2882,7 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/documents') $queries = Query::parseQueries($queries); // Get cursor document if there was a cursor query - $cursor = Query::getByType($queries, Query::TYPE_CURSORAFTER, Query::TYPE_CURSORBEFORE); + $cursor = Query::getByType($queries, [Query::TYPE_CURSORAFTER, Query::TYPE_CURSORBEFORE]); $cursor = reset($cursor); if ($cursor) { $documentId = $cursor->getValue(); diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index 5c10a3df9b..89132bead3 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -136,7 +136,7 @@ App::get('/v1/functions') } // Get cursor document if there was a cursor query - $cursor = Query::getByType($queries, Query::TYPE_CURSORAFTER, Query::TYPE_CURSORBEFORE); + $cursor = Query::getByType($queries, [Query::TYPE_CURSORAFTER, Query::TYPE_CURSORBEFORE]); $cursor = reset($cursor); if ($cursor) { /** @var Query $cursor */ @@ -812,7 +812,7 @@ App::get('/v1/functions/:functionId/deployments') $queries[] = Query::equal('resourceType', ['functions']); // Get cursor document if there was a cursor query - $cursor = Query::getByType($queries, Query::TYPE_CURSORAFTER, Query::TYPE_CURSORBEFORE); + $cursor = Query::getByType($queries, [Query::TYPE_CURSORAFTER, Query::TYPE_CURSORBEFORE]); $cursor = reset($cursor); if ($cursor) { /** @var Query $cursor */ @@ -1246,7 +1246,7 @@ App::get('/v1/functions/:functionId/executions') $queries[] = Query::equal('functionId', [$function->getId()]); // Get cursor document if there was a cursor query - $cursor = Query::getByType($queries, Query::TYPE_CURSORAFTER, Query::TYPE_CURSORBEFORE); + $cursor = Query::getByType($queries, [Query::TYPE_CURSORAFTER, Query::TYPE_CURSORBEFORE]); $cursor = reset($cursor); if ($cursor) { /** @var Query $cursor */ diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index 44329724b1..b1374097e5 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -197,7 +197,7 @@ App::get('/v1/projects') } // Get cursor document if there was a cursor query - $cursor = Query::getByType($queries, Query::TYPE_CURSORAFTER, Query::TYPE_CURSORBEFORE); + $cursor = Query::getByType($queries, [Query::TYPE_CURSORAFTER, Query::TYPE_CURSORBEFORE]); $cursor = reset($cursor); if ($cursor) { /** @var Query $cursor */ diff --git a/app/controllers/api/storage.php b/app/controllers/api/storage.php index b936fc6b2f..c65b44184f 100644 --- a/app/controllers/api/storage.php +++ b/app/controllers/api/storage.php @@ -167,7 +167,7 @@ App::get('/v1/storage/buckets') } // Get cursor document if there was a cursor query - $cursor = Query::getByType($queries, Query::TYPE_CURSORAFTER, Query::TYPE_CURSORBEFORE); + $cursor = Query::getByType($queries, [Query::TYPE_CURSORAFTER, Query::TYPE_CURSORBEFORE]); $cursor = reset($cursor); if ($cursor) { /** @var Query $cursor */ @@ -707,7 +707,7 @@ App::get('/v1/storage/buckets/:bucketId/files') } // Get cursor document if there was a cursor query - $cursor = Query::getByType($queries, Query::TYPE_CURSORAFTER, Query::TYPE_CURSORBEFORE); + $cursor = Query::getByType($queries, [Query::TYPE_CURSORAFTER, Query::TYPE_CURSORBEFORE]); $cursor = reset($cursor); if ($cursor) { /** @var Query $cursor */ diff --git a/app/controllers/api/teams.php b/app/controllers/api/teams.php index 4f64a65752..daa44d02b9 100644 --- a/app/controllers/api/teams.php +++ b/app/controllers/api/teams.php @@ -148,7 +148,7 @@ App::get('/v1/teams') } // Get cursor document if there was a cursor query - $cursor = Query::getByType($queries, Query::TYPE_CURSORAFTER, Query::TYPE_CURSORBEFORE); + $cursor = Query::getByType($queries, [Query::TYPE_CURSORAFTER, Query::TYPE_CURSORBEFORE]); $cursor = reset($cursor); if ($cursor) { /** @var Query $cursor */ @@ -629,7 +629,7 @@ App::get('/v1/teams/:teamId/memberships') $queries[] = Query::equal('teamId', [$teamId]); // Get cursor document if there was a cursor query - $cursor = Query::getByType($queries, Query::TYPE_CURSORAFTER, Query::TYPE_CURSORBEFORE); + $cursor = Query::getByType($queries, [Query::TYPE_CURSORAFTER, Query::TYPE_CURSORBEFORE]); $cursor = reset($cursor); if ($cursor) { /** @var Query $cursor */ diff --git a/app/controllers/api/users.php b/app/controllers/api/users.php index 72a351d97c..cb2645785c 100644 --- a/app/controllers/api/users.php +++ b/app/controllers/api/users.php @@ -386,7 +386,7 @@ App::get('/v1/users') } // Get cursor document if there was a cursor query - $cursor = Query::getByType($queries, Query::TYPE_CURSORAFTER, Query::TYPE_CURSORBEFORE); + $cursor = Query::getByType($queries, [Query::TYPE_CURSORAFTER, Query::TYPE_CURSORBEFORE]); $cursor = reset($cursor); if ($cursor) { /** @var Query $cursor */ diff --git a/app/init.php b/app/init.php index 02fd9246f7..b6dfc79fe1 100644 --- a/app/init.php +++ b/app/init.php @@ -1085,7 +1085,7 @@ App::setResource('schema', function ($utopia, $dbForProject) { $complexity = function (int $complexity, array $args) { $queries = Query::parseQueries($args['queries'] ?? []); - $query = Query::getByType($queries, Query::TYPE_LIMIT)[0] ?? null; + $query = Query::getByType($queries, [Query::TYPE_LIMIT])[0] ?? null; $limit = $query ? $query->getValue() : APP_LIMIT_LIST_DEFAULT; return $complexity * $limit; diff --git a/composer.lock b/composer.lock index 9247175eb6..4b8eb12ab9 100644 --- a/composer.lock +++ b/composer.lock @@ -2113,12 +2113,12 @@ "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "52f351230fab5922c6b63bd19b0bf4891d940d8f" + "reference": "0b7a496dbaec817909a41380728d43c9dc3ecfd4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/52f351230fab5922c6b63bd19b0bf4891d940d8f", - "reference": "52f351230fab5922c6b63bd19b0bf4891d940d8f", + "url": "https://api.github.com/repos/utopia-php/database/zipball/0b7a496dbaec817909a41380728d43c9dc3ecfd4", + "reference": "0b7a496dbaec817909a41380728d43c9dc3ecfd4", "shasum": "" }, "require": { @@ -2163,7 +2163,7 @@ "issues": "https://github.com/utopia-php/database/issues", "source": "https://github.com/utopia-php/database/tree/appwrite-validators" }, - "time": "2023-04-27T15:49:03+00:00" + "time": "2023-05-01T08:52:04+00:00" }, { "name": "utopia-php/domains", @@ -3034,16 +3034,16 @@ "packages-dev": [ { "name": "appwrite/sdk-generator", - "version": "0.32.2", + "version": "0.32.3", "source": { "type": "git", "url": "https://github.com/appwrite/sdk-generator.git", - "reference": "cdec289bcf38c99d0074414d2438e9967d0c9699" + "reference": "4057e14a61335070034b1cbdce9e39bef94d997d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/cdec289bcf38c99d0074414d2438e9967d0c9699", - "reference": "cdec289bcf38c99d0074414d2438e9967d0c9699", + "url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/4057e14a61335070034b1cbdce9e39bef94d997d", + "reference": "4057e14a61335070034b1cbdce9e39bef94d997d", "shasum": "" }, "require": { @@ -3079,9 +3079,9 @@ "description": "Appwrite PHP library for generating API SDKs for multiple programming languages and platforms", "support": { "issues": "https://github.com/appwrite/sdk-generator/issues", - "source": "https://github.com/appwrite/sdk-generator/tree/0.32.2" + "source": "https://github.com/appwrite/sdk-generator/tree/0.32.3" }, - "time": "2023-04-12T21:06:57+00:00" + "time": "2023-04-27T19:22:05+00:00" }, { "name": "doctrine/deprecations", From bfd757e0fbbd513726924014f4b39f6756e7a679 Mon Sep 17 00:00:00 2001 From: fogelito Date: Mon, 1 May 2023 18:34:38 +0300 Subject: [PATCH 23/46] audit chnage --- composer.json | 6 +++--- composer.lock | 60 +++++++++++++++++++++++++++++++-------------------- phpunit.xml | 2 +- 3 files changed, 41 insertions(+), 27 deletions(-) diff --git a/composer.json b/composer.json index 3d08bdd4a2..f843150382 100644 --- a/composer.json +++ b/composer.json @@ -43,13 +43,13 @@ "ext-sockets": "*", "appwrite/php-clamav": "1.1.*", "appwrite/php-runtimes": "0.11.*", - "utopia-php/abuse": "0.24.*", + "utopia-php/abuse": "dev-add-key-attribute as 0.25.0", "utopia-php/analytics": "0.2.*", - "utopia-php/audit": "0.25.*", + "utopia-php/audit": "dev-add-attribute-key as 0.26.0", "utopia-php/cache": "0.8.*", "utopia-php/cli": "0.13.*", "utopia-php/config": "0.2.*", - "utopia-php/database": "dev-appwrite-validators as 0.35.0", + "utopia-php/database": "dev-appwrite-validators as 0.36.0", "utopia-php/domains": "1.1.*", "utopia-php/framework": "0.28.*", "utopia-php/image": "0.5.*", diff --git a/composer.lock b/composer.lock index 4b8eb12ab9..90972796e0 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "d17652f4b2ab219da983b0ff3f5456d9", + "content-hash": "337bf088f3cec320e1c8d059ef1efb7f", "packages": [ { "name": "adhocore/jwt", @@ -1805,26 +1805,26 @@ }, { "name": "utopia-php/abuse", - "version": "0.24.0", + "version": "dev-add-key-attribute", "source": { "type": "git", "url": "https://github.com/utopia-php/abuse.git", - "reference": "403641f16a53b81ac40b91111a86e5672da49e8c" + "reference": "59a9cbd71f8e5261301a9bd4e277b4f48601f487" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/abuse/zipball/403641f16a53b81ac40b91111a86e5672da49e8c", - "reference": "403641f16a53b81ac40b91111a86e5672da49e8c", + "url": "https://api.github.com/repos/utopia-php/abuse/zipball/59a9cbd71f8e5261301a9bd4e277b4f48601f487", + "reference": "59a9cbd71f8e5261301a9bd4e277b4f48601f487", "shasum": "" }, "require": { "ext-curl": "*", "ext-pdo": "*", "php": ">=8.0", - "utopia-php/database": "0.35.*" + "utopia-php/database": "0.36.*" }, "require-dev": { - "laravel/pint": "1.2.*", + "laravel/pint": "1.5.*", "phpstan/phpstan": "^1.9", "phpunit/phpunit": "^9.4" }, @@ -1848,9 +1848,9 @@ ], "support": { "issues": "https://github.com/utopia-php/abuse/issues", - "source": "https://github.com/utopia-php/abuse/tree/0.24.0" + "source": "https://github.com/utopia-php/abuse/tree/add-key-attribute" }, - "time": "2023-04-11T05:31:55+00:00" + "time": "2023-05-01T13:53:36+00:00" }, { "name": "utopia-php/analytics", @@ -1909,24 +1909,24 @@ }, { "name": "utopia-php/audit", - "version": "0.25.0", + "version": "dev-add-attribute-key", "source": { "type": "git", "url": "https://github.com/utopia-php/audit.git", - "reference": "adc209f2e16878e5468f0b9cfd9f7f7ab497db31" + "reference": "a5a158257ab4e90e9b25e1564840765998a092a5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/audit/zipball/adc209f2e16878e5468f0b9cfd9f7f7ab497db31", - "reference": "adc209f2e16878e5468f0b9cfd9f7f7ab497db31", + "url": "https://api.github.com/repos/utopia-php/audit/zipball/a5a158257ab4e90e9b25e1564840765998a092a5", + "reference": "a5a158257ab4e90e9b25e1564840765998a092a5", "shasum": "" }, "require": { "php": ">=8.0", - "utopia-php/database": "0.35.*" + "utopia-php/database": "0.36.*" }, "require-dev": { - "laravel/pint": "1.2.*", + "laravel/pint": "1.5.*", "phpstan/phpstan": "^1.8", "phpunit/phpunit": "^9.3" }, @@ -1950,9 +1950,9 @@ ], "support": { "issues": "https://github.com/utopia-php/audit/issues", - "source": "https://github.com/utopia-php/audit/tree/0.25.0" + "source": "https://github.com/utopia-php/audit/tree/add-attribute-key" }, - "time": "2023-04-11T05:31:15+00:00" + "time": "2023-05-01T15:15:44+00:00" }, { "name": "utopia-php/cache", @@ -2113,12 +2113,12 @@ "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "0b7a496dbaec817909a41380728d43c9dc3ecfd4" + "reference": "9b693eb2b28ec789cce815994b133ca42b21cd0b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/0b7a496dbaec817909a41380728d43c9dc3ecfd4", - "reference": "0b7a496dbaec817909a41380728d43c9dc3ecfd4", + "url": "https://api.github.com/repos/utopia-php/database/zipball/9b693eb2b28ec789cce815994b133ca42b21cd0b", + "reference": "9b693eb2b28ec789cce815994b133ca42b21cd0b", "shasum": "" }, "require": { @@ -2163,7 +2163,7 @@ "issues": "https://github.com/utopia-php/database/issues", "source": "https://github.com/utopia-php/database/tree/appwrite-validators" }, - "time": "2023-05-01T08:52:04+00:00" + "time": "2023-05-01T14:10:12+00:00" }, { "name": "utopia-php/domains", @@ -5653,15 +5653,29 @@ } ], "aliases": [ + { + "package": "utopia-php/abuse", + "version": "dev-add-key-attribute", + "alias": "0.25.0", + "alias_normalized": "0.25.0.0" + }, + { + "package": "utopia-php/audit", + "version": "dev-add-attribute-key", + "alias": "0.26.0", + "alias_normalized": "0.26.0.0" + }, { "package": "utopia-php/database", "version": "dev-appwrite-validators", - "alias": "0.35.0", - "alias_normalized": "0.35.0.0" + "alias": "0.36.0", + "alias_normalized": "0.36.0.0" } ], "minimum-stability": "stable", "stability-flags": { + "utopia-php/abuse": 20, + "utopia-php/audit": 20, "utopia-php/database": 20 }, "prefer-stable": false, diff --git a/phpunit.xml b/phpunit.xml index f83f9f0fae..3d15bbd21a 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -6,7 +6,7 @@ convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" - stopOnFailure="false" + stopOnFailure="true" > From cf7e6831c742fd656b18d9a51593678e398af9d1 Mon Sep 17 00:00:00 2001 From: fogelito Date: Tue, 2 May 2023 19:25:19 +0300 Subject: [PATCH 24/46] revert audit tags --- composer.json | 6 ++--- composer.lock | 72 +++++++++++++++++++++------------------------------ 2 files changed, 32 insertions(+), 46 deletions(-) diff --git a/composer.json b/composer.json index f843150382..3d08bdd4a2 100644 --- a/composer.json +++ b/composer.json @@ -43,13 +43,13 @@ "ext-sockets": "*", "appwrite/php-clamav": "1.1.*", "appwrite/php-runtimes": "0.11.*", - "utopia-php/abuse": "dev-add-key-attribute as 0.25.0", + "utopia-php/abuse": "0.24.*", "utopia-php/analytics": "0.2.*", - "utopia-php/audit": "dev-add-attribute-key as 0.26.0", + "utopia-php/audit": "0.25.*", "utopia-php/cache": "0.8.*", "utopia-php/cli": "0.13.*", "utopia-php/config": "0.2.*", - "utopia-php/database": "dev-appwrite-validators as 0.36.0", + "utopia-php/database": "dev-appwrite-validators as 0.35.0", "utopia-php/domains": "1.1.*", "utopia-php/framework": "0.28.*", "utopia-php/image": "0.5.*", diff --git a/composer.lock b/composer.lock index 90972796e0..c7ad052755 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "337bf088f3cec320e1c8d059ef1efb7f", + "content-hash": "d17652f4b2ab219da983b0ff3f5456d9", "packages": [ { "name": "adhocore/jwt", @@ -1805,26 +1805,26 @@ }, { "name": "utopia-php/abuse", - "version": "dev-add-key-attribute", + "version": "0.24.0", "source": { "type": "git", "url": "https://github.com/utopia-php/abuse.git", - "reference": "59a9cbd71f8e5261301a9bd4e277b4f48601f487" + "reference": "403641f16a53b81ac40b91111a86e5672da49e8c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/abuse/zipball/59a9cbd71f8e5261301a9bd4e277b4f48601f487", - "reference": "59a9cbd71f8e5261301a9bd4e277b4f48601f487", + "url": "https://api.github.com/repos/utopia-php/abuse/zipball/403641f16a53b81ac40b91111a86e5672da49e8c", + "reference": "403641f16a53b81ac40b91111a86e5672da49e8c", "shasum": "" }, "require": { "ext-curl": "*", "ext-pdo": "*", "php": ">=8.0", - "utopia-php/database": "0.36.*" + "utopia-php/database": "0.35.*" }, "require-dev": { - "laravel/pint": "1.5.*", + "laravel/pint": "1.2.*", "phpstan/phpstan": "^1.9", "phpunit/phpunit": "^9.4" }, @@ -1848,9 +1848,9 @@ ], "support": { "issues": "https://github.com/utopia-php/abuse/issues", - "source": "https://github.com/utopia-php/abuse/tree/add-key-attribute" + "source": "https://github.com/utopia-php/abuse/tree/0.24.0" }, - "time": "2023-05-01T13:53:36+00:00" + "time": "2023-04-11T05:31:55+00:00" }, { "name": "utopia-php/analytics", @@ -1909,24 +1909,24 @@ }, { "name": "utopia-php/audit", - "version": "dev-add-attribute-key", + "version": "0.25.0", "source": { "type": "git", "url": "https://github.com/utopia-php/audit.git", - "reference": "a5a158257ab4e90e9b25e1564840765998a092a5" + "reference": "adc209f2e16878e5468f0b9cfd9f7f7ab497db31" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/audit/zipball/a5a158257ab4e90e9b25e1564840765998a092a5", - "reference": "a5a158257ab4e90e9b25e1564840765998a092a5", + "url": "https://api.github.com/repos/utopia-php/audit/zipball/adc209f2e16878e5468f0b9cfd9f7f7ab497db31", + "reference": "adc209f2e16878e5468f0b9cfd9f7f7ab497db31", "shasum": "" }, "require": { "php": ">=8.0", - "utopia-php/database": "0.36.*" + "utopia-php/database": "0.35.*" }, "require-dev": { - "laravel/pint": "1.5.*", + "laravel/pint": "1.2.*", "phpstan/phpstan": "^1.8", "phpunit/phpunit": "^9.3" }, @@ -1950,9 +1950,9 @@ ], "support": { "issues": "https://github.com/utopia-php/audit/issues", - "source": "https://github.com/utopia-php/audit/tree/add-attribute-key" + "source": "https://github.com/utopia-php/audit/tree/0.25.0" }, - "time": "2023-05-01T15:15:44+00:00" + "time": "2023-04-11T05:31:15+00:00" }, { "name": "utopia-php/cache", @@ -2113,12 +2113,12 @@ "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "9b693eb2b28ec789cce815994b133ca42b21cd0b" + "reference": "d131ad4f68084c72dd1afaf25f584e1d561b3b6d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/9b693eb2b28ec789cce815994b133ca42b21cd0b", - "reference": "9b693eb2b28ec789cce815994b133ca42b21cd0b", + "url": "https://api.github.com/repos/utopia-php/database/zipball/d131ad4f68084c72dd1afaf25f584e1d561b3b6d", + "reference": "d131ad4f68084c72dd1afaf25f584e1d561b3b6d", "shasum": "" }, "require": { @@ -2163,7 +2163,7 @@ "issues": "https://github.com/utopia-php/database/issues", "source": "https://github.com/utopia-php/database/tree/appwrite-validators" }, - "time": "2023-05-01T14:10:12+00:00" + "time": "2023-05-02T15:44:22+00:00" }, { "name": "utopia-php/domains", @@ -3784,16 +3784,16 @@ }, { "name": "phpstan/phpdoc-parser", - "version": "1.20.3", + "version": "1.20.4", "source": { "type": "git", "url": "https://github.com/phpstan/phpdoc-parser.git", - "reference": "6c04009f6cae6eda2f040745b6b846080ef069c2" + "reference": "7d568c87a9df9c5f7e8b5f075fc469aa8cb0a4cd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/6c04009f6cae6eda2f040745b6b846080ef069c2", - "reference": "6c04009f6cae6eda2f040745b6b846080ef069c2", + "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/7d568c87a9df9c5f7e8b5f075fc469aa8cb0a4cd", + "reference": "7d568c87a9df9c5f7e8b5f075fc469aa8cb0a4cd", "shasum": "" }, "require": { @@ -3823,9 +3823,9 @@ "description": "PHPDoc parser with support for nullable, intersection and generic types", "support": { "issues": "https://github.com/phpstan/phpdoc-parser/issues", - "source": "https://github.com/phpstan/phpdoc-parser/tree/1.20.3" + "source": "https://github.com/phpstan/phpdoc-parser/tree/1.20.4" }, - "time": "2023-04-25T09:01:03+00:00" + "time": "2023-05-02T09:19:37+00:00" }, { "name": "phpunit/php-code-coverage", @@ -5653,29 +5653,15 @@ } ], "aliases": [ - { - "package": "utopia-php/abuse", - "version": "dev-add-key-attribute", - "alias": "0.25.0", - "alias_normalized": "0.25.0.0" - }, - { - "package": "utopia-php/audit", - "version": "dev-add-attribute-key", - "alias": "0.26.0", - "alias_normalized": "0.26.0.0" - }, { "package": "utopia-php/database", "version": "dev-appwrite-validators", - "alias": "0.36.0", - "alias_normalized": "0.36.0.0" + "alias": "0.35.0", + "alias_normalized": "0.35.0.0" } ], "minimum-stability": "stable", "stability-flags": { - "utopia-php/abuse": 20, - "utopia-php/audit": 20, "utopia-php/database": 20 }, "prefer-stable": false, From 6f0fde242a50414ba1e536b7442c370fbe20446e Mon Sep 17 00:00:00 2001 From: fogelito Date: Tue, 2 May 2023 20:20:04 +0300 Subject: [PATCH 25/46] composer.lock --- composer.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.lock b/composer.lock index c7ad052755..d53a85ff5a 100644 --- a/composer.lock +++ b/composer.lock @@ -2113,12 +2113,12 @@ "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "d131ad4f68084c72dd1afaf25f584e1d561b3b6d" + "reference": "959bce0d87dc47e41c970964c68bb756dacc33fc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/d131ad4f68084c72dd1afaf25f584e1d561b3b6d", - "reference": "d131ad4f68084c72dd1afaf25f584e1d561b3b6d", + "url": "https://api.github.com/repos/utopia-php/database/zipball/959bce0d87dc47e41c970964c68bb756dacc33fc", + "reference": "959bce0d87dc47e41c970964c68bb756dacc33fc", "shasum": "" }, "require": { @@ -2163,7 +2163,7 @@ "issues": "https://github.com/utopia-php/database/issues", "source": "https://github.com/utopia-php/database/tree/appwrite-validators" }, - "time": "2023-05-02T15:44:22+00:00" + "time": "2023-05-02T16:55:47+00:00" }, { "name": "utopia-php/domains", From 5be5a7dd0e869b5ecafe86117c7d99bf8fa50ef9 Mon Sep 17 00:00:00 2001 From: fogelito Date: Wed, 3 May 2023 14:53:40 +0300 Subject: [PATCH 26/46] Empty queries fixes --- app/controllers/api/projects.php | 26 +++++++++---------- composer.lock | 8 +++--- .../Functions/FunctionsCustomServerTest.php | 8 +++--- tests/e2e/Services/Storage/StorageBase.php | 4 +-- tests/e2e/Services/Teams/TeamsBaseClient.php | 4 +-- 5 files changed, 25 insertions(+), 25 deletions(-) diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index b1374097e5..34df09c7f5 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -820,7 +820,7 @@ App::get('/v1/projects/:projectId/webhooks/:webhookId') } $webhook = $dbForConsole->findOne('webhooks', [ - Query::equal('_uid', [$webhookId]), + Query::equal('$id', [$webhookId]), Query::equal('projectInternalId', [$project->getInternalId()]), ]); @@ -862,7 +862,7 @@ App::put('/v1/projects/:projectId/webhooks/:webhookId') $security = ($security === '1' || $security === 'true' || $security === 1 || $security === true); $webhook = $dbForConsole->findOne('webhooks', [ - Query::equal('_uid', [$webhookId]), + Query::equal('$id', [$webhookId]), Query::equal('projectInternalId', [$project->getInternalId()]), ]); @@ -908,7 +908,7 @@ App::patch('/v1/projects/:projectId/webhooks/:webhookId/signature') } $webhook = $dbForConsole->findOne('webhooks', [ - Query::equal('_uid', [$webhookId]), + Query::equal('$id', [$webhookId]), Query::equal('projectInternalId', [$project->getInternalId()]), ]); @@ -946,7 +946,7 @@ App::delete('/v1/projects/:projectId/webhooks/:webhookId') } $webhook = $dbForConsole->findOne('webhooks', [ - Query::equal('_uid', [$webhookId]), + Query::equal('$id', [$webhookId]), Query::equal('projectInternalId', [$project->getInternalId()]), ]); @@ -1068,7 +1068,7 @@ App::get('/v1/projects/:projectId/keys/:keyId') } $key = $dbForConsole->findOne('keys', [ - Query::equal('_uid', [$keyId]), + Query::equal('$id', [$keyId]), Query::equal('projectInternalId', [$project->getInternalId()]), ]); @@ -1105,7 +1105,7 @@ App::put('/v1/projects/:projectId/keys/:keyId') } $key = $dbForConsole->findOne('keys', [ - Query::equal('_uid', [$keyId]), + Query::equal('$id', [$keyId]), Query::equal('projectInternalId', [$project->getInternalId()]), ]); @@ -1148,7 +1148,7 @@ App::delete('/v1/projects/:projectId/keys/:keyId') } $key = $dbForConsole->findOne('keys', [ - Query::equal('_uid', [$keyId]), + Query::equal('$id', [$keyId]), Query::equal('projectInternalId', [$project->getInternalId()]), ]); @@ -1270,7 +1270,7 @@ App::get('/v1/projects/:projectId/platforms/:platformId') } $platform = $dbForConsole->findOne('platforms', [ - Query::equal('_uid', [$platformId]), + Query::equal('$id', [$platformId]), Query::equal('projectInternalId', [$project->getInternalId()]), ]); @@ -1307,7 +1307,7 @@ App::put('/v1/projects/:projectId/platforms/:platformId') } $platform = $dbForConsole->findOne('platforms', [ - Query::equal('_uid', [$platformId]), + Query::equal('$id', [$platformId]), Query::equal('projectInternalId', [$project->getInternalId()]), ]); @@ -1351,7 +1351,7 @@ App::delete('/v1/projects/:projectId/platforms/:platformId') } $platform = $dbForConsole->findOne('platforms', [ - Query::equal('_uid', [$platformId]), + Query::equal('$id', [$platformId]), Query::equal('projectInternalId', [$project->getInternalId()]), ]); @@ -1488,7 +1488,7 @@ App::get('/v1/projects/:projectId/domains/:domainId') } $domain = $dbForConsole->findOne('domains', [ - Query::equal('_uid', [$domainId]), + Query::equal('$id', [$domainId]), Query::equal('projectInternalId', [$project->getInternalId()]), ]); @@ -1522,7 +1522,7 @@ App::patch('/v1/projects/:projectId/domains/:domainId/verification') } $domain = $dbForConsole->findOne('domains', [ - Query::equal('_uid', [$domainId]), + Query::equal('$id', [$domainId]), Query::equal('projectInternalId', [$project->getInternalId()]), ]); @@ -1582,7 +1582,7 @@ App::delete('/v1/projects/:projectId/domains/:domainId') } $domain = $dbForConsole->findOne('domains', [ - Query::equal('_uid', [$domainId]), + Query::equal('$id', [$domainId]), Query::equal('projectInternalId', [$project->getInternalId()]), ]); diff --git a/composer.lock b/composer.lock index d53a85ff5a..199ee7f42b 100644 --- a/composer.lock +++ b/composer.lock @@ -2113,12 +2113,12 @@ "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "959bce0d87dc47e41c970964c68bb756dacc33fc" + "reference": "46de56c58555c5740ad79bef0467c7451a7a5bc7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/959bce0d87dc47e41c970964c68bb756dacc33fc", - "reference": "959bce0d87dc47e41c970964c68bb756dacc33fc", + "url": "https://api.github.com/repos/utopia-php/database/zipball/46de56c58555c5740ad79bef0467c7451a7a5bc7", + "reference": "46de56c58555c5740ad79bef0467c7451a7a5bc7", "shasum": "" }, "require": { @@ -2163,7 +2163,7 @@ "issues": "https://github.com/utopia-php/database/issues", "source": "https://github.com/utopia-php/database/tree/appwrite-validators" }, - "time": "2023-05-02T16:55:47+00:00" + "time": "2023-05-03T09:50:09+00:00" }, { "name": "utopia-php/domains", diff --git a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php index 2b66277952..03722f2fd6 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php @@ -119,11 +119,11 @@ class FunctionsCustomServerTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => [ 'limit(0)' ] + 'queries' => [ 'limit(1)' ] ]); $this->assertEquals($response['headers']['status-code'], 200); - $this->assertCount(0, $response['body']['functions']); + $this->assertCount(1, $response['body']['functions']); $response = $this->client->call(Client::METHOD_GET, '/functions', array_merge([ 'content-type' => 'application/json', @@ -675,11 +675,11 @@ class FunctionsCustomServerTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => [ 'limit(0)' ] + 'queries' => [ 'limit(1)' ] ]); $this->assertEquals(200, $response['headers']['status-code']); - $this->assertCount(0, $response['body']['executions']); + $this->assertCount(1, $response['body']['executions']); $response = $this->client->call(Client::METHOD_GET, '/functions/' . $data['functionId'] . '/executions', array_merge([ 'content-type' => 'application/json', diff --git a/tests/e2e/Services/Storage/StorageBase.php b/tests/e2e/Services/Storage/StorageBase.php index baef838979..3a9b181921 100644 --- a/tests/e2e/Services/Storage/StorageBase.php +++ b/tests/e2e/Services/Storage/StorageBase.php @@ -314,10 +314,10 @@ trait StorageBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => [ 'limit(0)' ] + 'queries' => [ 'limit(1)' ] ]); $this->assertEquals(200, $files['headers']['status-code']); - $this->assertEquals(0, count($files['body']['files'])); + $this->assertEquals(1, count($files['body']['files'])); $files = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $data['bucketId'] . '/files', array_merge([ 'content-type' => 'application/json', diff --git a/tests/e2e/Services/Teams/TeamsBaseClient.php b/tests/e2e/Services/Teams/TeamsBaseClient.php index 271e80a03f..0de99cc357 100644 --- a/tests/e2e/Services/Teams/TeamsBaseClient.php +++ b/tests/e2e/Services/Teams/TeamsBaseClient.php @@ -39,11 +39,11 @@ trait TeamsBaseClient 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => [ 'limit(0)' ] + 'queries' => [ 'limit(1)' ] ]); $this->assertEquals(200, $response['headers']['status-code']); - $this->assertCount(0, $response['body']['memberships']); + $this->assertCount(1, $response['body']['memberships']); $response = $this->client->call(Client::METHOD_GET, '/teams/' . $teamUid . '/memberships', array_merge([ 'content-type' => 'application/json', From 969655366538b40ab4418727c8853227e3c4892f Mon Sep 17 00:00:00 2001 From: fogelito Date: Thu, 4 May 2023 18:14:46 +0300 Subject: [PATCH 27/46] composer.lock --- composer.lock | 60 +++++++++++++++++++++++++++------------------------ 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/composer.lock b/composer.lock index 978d14f490..ec8475651b 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "169ab6e7dd540e45309d3c5093506fad", + "content-hash": "c521b6e92f892781775039f1e51af5a3", "packages": [ { "name": "adhocore/jwt", @@ -2109,16 +2109,16 @@ }, { "name": "utopia-php/database", - "version": "0.36.1", + "version": "dev-appwrite-validators", "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "f6ab65e59a199da5155c114564077b1ab8c4daef" + "reference": "d7795caccab8811ebe0e30d6f425d277ed522ad5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/f6ab65e59a199da5155c114564077b1ab8c4daef", - "reference": "f6ab65e59a199da5155c114564077b1ab8c4daef", + "url": "https://api.github.com/repos/utopia-php/database/zipball/d7795caccab8811ebe0e30d6f425d277ed522ad5", + "reference": "d7795caccab8811ebe0e30d6f425d277ed522ad5", "shasum": "" }, "require": { @@ -2161,9 +2161,9 @@ ], "support": { "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/0.36.1" + "source": "https://github.com/utopia-php/database/tree/appwrite-validators" }, - "time": "2023-04-27T08:39:55+00:00" + "time": "2023-05-04T13:23:51+00:00" }, { "name": "utopia-php/domains", @@ -3784,16 +3784,16 @@ }, { "name": "phpstan/phpdoc-parser", - "version": "1.20.3", + "version": "1.20.4", "source": { "type": "git", "url": "https://github.com/phpstan/phpdoc-parser.git", - "reference": "6c04009f6cae6eda2f040745b6b846080ef069c2" + "reference": "7d568c87a9df9c5f7e8b5f075fc469aa8cb0a4cd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/6c04009f6cae6eda2f040745b6b846080ef069c2", - "reference": "6c04009f6cae6eda2f040745b6b846080ef069c2", + "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/7d568c87a9df9c5f7e8b5f075fc469aa8cb0a4cd", + "reference": "7d568c87a9df9c5f7e8b5f075fc469aa8cb0a4cd", "shasum": "" }, "require": { @@ -3823,9 +3823,9 @@ "description": "PHPDoc parser with support for nullable, intersection and generic types", "support": { "issues": "https://github.com/phpstan/phpdoc-parser/issues", - "source": "https://github.com/phpstan/phpdoc-parser/tree/1.20.3" + "source": "https://github.com/phpstan/phpdoc-parser/tree/1.20.4" }, - "time": "2023-04-25T09:01:03+00:00" + "time": "2023-05-02T09:19:37+00:00" }, { "name": "phpunit/php-code-coverage", @@ -5577,16 +5577,16 @@ }, { "name": "twig/twig", - "version": "v3.5.1", + "version": "v3.6.0", "source": { "type": "git", "url": "https://github.com/twigphp/Twig.git", - "reference": "a6e0510cc793912b451fd40ab983a1d28f611c15" + "reference": "106c170d08e8415d78be2d16c3d057d0d108262b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/twigphp/Twig/zipball/a6e0510cc793912b451fd40ab983a1d28f611c15", - "reference": "a6e0510cc793912b451fd40ab983a1d28f611c15", + "url": "https://api.github.com/repos/twigphp/Twig/zipball/106c170d08e8415d78be2d16c3d057d0d108262b", + "reference": "106c170d08e8415d78be2d16c3d057d0d108262b", "shasum": "" }, "require": { @@ -5595,15 +5595,10 @@ "symfony/polyfill-mbstring": "^1.3" }, "require-dev": { - "psr/container": "^1.0", + "psr/container": "^1.0|^2.0", "symfony/phpunit-bridge": "^4.4.9|^5.0.9|^6.0" }, "type": "library", - "extra": { - "branch-alias": { - "dev-master": "3.5-dev" - } - }, "autoload": { "psr-4": { "Twig\\": "src/" @@ -5637,7 +5632,7 @@ ], "support": { "issues": "https://github.com/twigphp/Twig/issues", - "source": "https://github.com/twigphp/Twig/tree/v3.5.1" + "source": "https://github.com/twigphp/Twig/tree/v3.6.0" }, "funding": [ { @@ -5649,12 +5644,21 @@ "type": "tidelift" } ], - "time": "2023-02-08T07:49:20+00:00" + "time": "2023-05-03T19:06:57+00:00" + } + ], + "aliases": [ + { + "package": "utopia-php/database", + "version": "dev-appwrite-validators", + "alias": "0.36.0", + "alias_normalized": "0.36.0.0" } ], - "aliases": [], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": { + "utopia-php/database": 20 + }, "prefer-stable": false, "prefer-lowest": false, "platform": { @@ -5678,5 +5682,5 @@ "platform-overrides": { "php": "8.0" }, - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.2.0" } From 60377fd8b7ec7142e56a29f6104286df92c61f87 Mon Sep 17 00:00:00 2001 From: fogelito Date: Sun, 7 May 2023 12:21:54 +0300 Subject: [PATCH 28/46] console --- tests/e2e/General/UsageTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/e2e/General/UsageTest.php b/tests/e2e/General/UsageTest.php index fec6d75db3..eca2ccfe7d 100644 --- a/tests/e2e/General/UsageTest.php +++ b/tests/e2e/General/UsageTest.php @@ -256,6 +256,7 @@ class UsageTest extends Scope $filesCreate = $data['filesCreate']; $filesDelete = $data['filesDelete']; + sleep(20); // console request From 0fd89b2ca6d2c464253c38e57238ce64f08093b1 Mon Sep 17 00:00:00 2001 From: fogelito Date: Sun, 7 May 2023 12:22:28 +0300 Subject: [PATCH 29/46] remove extra line --- tests/e2e/General/UsageTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/e2e/General/UsageTest.php b/tests/e2e/General/UsageTest.php index eca2ccfe7d..fec6d75db3 100644 --- a/tests/e2e/General/UsageTest.php +++ b/tests/e2e/General/UsageTest.php @@ -256,7 +256,6 @@ class UsageTest extends Scope $filesCreate = $data['filesCreate']; $filesDelete = $data['filesDelete']; - sleep(20); // console request From f6153b76262eeadfa630872180fb2f21b2f8309b Mon Sep 17 00:00:00 2001 From: fogelito Date: Tue, 16 May 2023 15:56:20 +0300 Subject: [PATCH 30/46] Use array instead of variadic --- app/controllers/api/account.php | 2 +- app/controllers/api/databases.php | 10 +++--- app/controllers/api/teams.php | 2 +- app/controllers/api/users.php | 2 +- composer.lock | 35 +++++++++---------- docs/tutorials/add-route.md | 2 +- .../Database/Validator/Queries/Base.php | 2 +- 7 files changed, 26 insertions(+), 29 deletions(-) diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index 2eb02c4b2e..2daf9429f4 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -1411,7 +1411,7 @@ App::get('/v1/account/logs') ->label('sdk.response.code', Response::STATUS_CODE_OK) ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) ->label('sdk.response.model', Response::MODEL_LOG_LIST) - ->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 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) ->inject('response') ->inject('user') ->inject('locale') diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index ea731fd8a2..bbcedc6207 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -46,7 +46,7 @@ use Appwrite\Event\Event; use Utopia\Database\Validator\Queries; use Appwrite\Utopia\Database\Validator\Queries\Collections; use Appwrite\Utopia\Database\Validator\Queries\Databases; -use Utopia\Database\Validator\Queries\Documents as DocumentsQueriesValidator; +use Utopia\Database\Validator\Queries\Documents; use Utopia\Database\Validator\Queries\Document as DocumentQueriesValidator; use Utopia\Config\Config; use MaxMind\Db\Reader; @@ -528,7 +528,7 @@ App::get('/v1/databases/:databaseId/logs') ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) ->label('sdk.response.model', Response::MODEL_LOG_LIST) ->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 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) ->inject('response') ->inject('dbForProject') ->inject('locale') @@ -867,7 +867,7 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/logs') ->label('sdk.response.model', Response::MODEL_LOG_LIST) ->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 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) ->inject('response') ->inject('dbForProject') ->inject('locale') @@ -2900,7 +2900,7 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/documents') } // Validate queries - $queriesValidator = new DocumentsQueriesValidator($collection->getAttribute('attributes'), $collection->getAttribute('indexes')); + $queriesValidator = new Documents($collection->getAttribute('attributes'), $collection->getAttribute('indexes')); $validQueries = $queriesValidator->isValid($queries); if (!$validQueries) { throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, $queriesValidator->getDescription()); @@ -3101,7 +3101,7 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/documents/:documen ->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 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) ->inject('response') ->inject('dbForProject') ->inject('locale') diff --git a/app/controllers/api/teams.php b/app/controllers/api/teams.php index daa44d02b9..155567a90e 100644 --- a/app/controllers/api/teams.php +++ b/app/controllers/api/teams.php @@ -1002,7 +1002,7 @@ App::get('/v1/teams/:teamId/logs') ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) ->label('sdk.response.model', Response::MODEL_LOG_LIST) ->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 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) ->inject('response') ->inject('dbForProject') ->inject('locale') diff --git a/app/controllers/api/users.php b/app/controllers/api/users.php index adca12ceea..2eae494758 100644 --- a/app/controllers/api/users.php +++ b/app/controllers/api/users.php @@ -557,7 +557,7 @@ App::get('/v1/users/:userId/logs') ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) ->label('sdk.response.model', Response::MODEL_LOG_LIST) ->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 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) ->inject('response') ->inject('dbForProject') ->inject('locale') diff --git a/composer.lock b/composer.lock index ec8475651b..676f837fa0 100644 --- a/composer.lock +++ b/composer.lock @@ -481,16 +481,16 @@ }, { "name": "guzzlehttp/guzzle", - "version": "7.5.1", + "version": "7.6.0", "source": { "type": "git", "url": "https://github.com/guzzle/guzzle.git", - "reference": "b964ca597e86b752cd994f27293e9fa6b6a95ed9" + "reference": "733dd89533dd371a0987172727df15f500dab0ef" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/guzzle/zipball/b964ca597e86b752cd994f27293e9fa6b6a95ed9", - "reference": "b964ca597e86b752cd994f27293e9fa6b6a95ed9", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/733dd89533dd371a0987172727df15f500dab0ef", + "reference": "733dd89533dd371a0987172727df15f500dab0ef", "shasum": "" }, "require": { @@ -521,9 +521,6 @@ "bamarni-bin": { "bin-links": true, "forward-command": false - }, - "branch-alias": { - "dev-master": "7.5-dev" } }, "autoload": { @@ -589,7 +586,7 @@ ], "support": { "issues": "https://github.com/guzzle/guzzle/issues", - "source": "https://github.com/guzzle/guzzle/tree/7.5.1" + "source": "https://github.com/guzzle/guzzle/tree/7.6.0" }, "funding": [ { @@ -605,7 +602,7 @@ "type": "tidelift" } ], - "time": "2023-04-17T16:30:08+00:00" + "time": "2023-05-14T11:23:39+00:00" }, { "name": "guzzlehttp/promises", @@ -2113,12 +2110,12 @@ "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "d7795caccab8811ebe0e30d6f425d277ed522ad5" + "reference": "51ff5b031397ef27e789bd14855f13c233282c74" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/d7795caccab8811ebe0e30d6f425d277ed522ad5", - "reference": "d7795caccab8811ebe0e30d6f425d277ed522ad5", + "url": "https://api.github.com/repos/utopia-php/database/zipball/51ff5b031397ef27e789bd14855f13c233282c74", + "reference": "51ff5b031397ef27e789bd14855f13c233282c74", "shasum": "" }, "require": { @@ -2163,7 +2160,7 @@ "issues": "https://github.com/utopia-php/database/issues", "source": "https://github.com/utopia-php/database/tree/appwrite-validators" }, - "time": "2023-05-04T13:23:51+00:00" + "time": "2023-05-15T13:12:11+00:00" }, { "name": "utopia-php/domains", @@ -4548,16 +4545,16 @@ }, { "name": "sebastian/diff", - "version": "4.0.4", + "version": "4.0.5", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/diff.git", - "reference": "3461e3fccc7cfdfc2720be910d3bd73c69be590d" + "reference": "74be17022044ebaaecfdf0c5cd504fc9cd5a7131" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/3461e3fccc7cfdfc2720be910d3bd73c69be590d", - "reference": "3461e3fccc7cfdfc2720be910d3bd73c69be590d", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/74be17022044ebaaecfdf0c5cd504fc9cd5a7131", + "reference": "74be17022044ebaaecfdf0c5cd504fc9cd5a7131", "shasum": "" }, "require": { @@ -4602,7 +4599,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/diff/issues", - "source": "https://github.com/sebastianbergmann/diff/tree/4.0.4" + "source": "https://github.com/sebastianbergmann/diff/tree/4.0.5" }, "funding": [ { @@ -4610,7 +4607,7 @@ "type": "github" } ], - "time": "2020-10-26T13:10:38+00:00" + "time": "2023-05-07T05:35:17+00:00" }, { "name": "sebastian/environment", diff --git a/docs/tutorials/add-route.md b/docs/tutorials/add-route.md index 574e7454c6..43b55921c7 100644 --- a/docs/tutorials/add-route.md +++ b/docs/tutorials/add-route.md @@ -157,7 +157,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 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) ``` ### 6. inject diff --git a/src/Appwrite/Utopia/Database/Validator/Queries/Base.php b/src/Appwrite/Utopia/Database/Validator/Queries/Base.php index 3ea3121e25..587862fa65 100644 --- a/src/Appwrite/Utopia/Database/Validator/Queries/Base.php +++ b/src/Appwrite/Utopia/Database/Validator/Queries/Base.php @@ -70,6 +70,6 @@ class Base extends Queries new Select($attributes), ]; - parent::__construct(...$validators); + parent::__construct($validators); } } From aae6b932d38edeb5cf360d7162cceec98cef58e9 Mon Sep 17 00:00:00 2001 From: fogelito Date: Tue, 16 May 2023 17:49:12 +0300 Subject: [PATCH 31/46] remove unnecessary hint --- app/controllers/api/databases.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index bbcedc6207..16948913ce 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -471,7 +471,6 @@ App::get('/v1/databases') $cursor = Query::getByType($queries, [Query::TYPE_CURSORAFTER, Query::TYPE_CURSORBEFORE]); $cursor = reset($cursor); if ($cursor) { - /** @var Query $cursor */ $databaseId = $cursor->getValue(); $cursorDocument = $dbForProject->getDocument('databases', $databaseId); From 454480b0771b0e86100e741c03dd10261bc07d96 Mon Sep 17 00:00:00 2001 From: fogelito Date: Thu, 18 May 2023 10:21:34 +0300 Subject: [PATCH 32/46] composer.lock --- composer.lock | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/composer.lock b/composer.lock index 676f837fa0..965088d225 100644 --- a/composer.lock +++ b/composer.lock @@ -481,16 +481,16 @@ }, { "name": "guzzlehttp/guzzle", - "version": "7.6.0", + "version": "7.6.1", "source": { "type": "git", "url": "https://github.com/guzzle/guzzle.git", - "reference": "733dd89533dd371a0987172727df15f500dab0ef" + "reference": "8444a2bacf1960bc6a2b62ed86b8e72e11eebe51" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/guzzle/zipball/733dd89533dd371a0987172727df15f500dab0ef", - "reference": "733dd89533dd371a0987172727df15f500dab0ef", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/8444a2bacf1960bc6a2b62ed86b8e72e11eebe51", + "reference": "8444a2bacf1960bc6a2b62ed86b8e72e11eebe51", "shasum": "" }, "require": { @@ -586,7 +586,7 @@ ], "support": { "issues": "https://github.com/guzzle/guzzle/issues", - "source": "https://github.com/guzzle/guzzle/tree/7.6.0" + "source": "https://github.com/guzzle/guzzle/tree/7.6.1" }, "funding": [ { @@ -602,7 +602,7 @@ "type": "tidelift" } ], - "time": "2023-05-14T11:23:39+00:00" + "time": "2023-05-15T20:43:01+00:00" }, { "name": "guzzlehttp/promises", @@ -2110,12 +2110,12 @@ "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "51ff5b031397ef27e789bd14855f13c233282c74" + "reference": "aa72d655183b7a6d902d1b3c668d5decbc4ecdd9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/51ff5b031397ef27e789bd14855f13c233282c74", - "reference": "51ff5b031397ef27e789bd14855f13c233282c74", + "url": "https://api.github.com/repos/utopia-php/database/zipball/aa72d655183b7a6d902d1b3c668d5decbc4ecdd9", + "reference": "aa72d655183b7a6d902d1b3c668d5decbc4ecdd9", "shasum": "" }, "require": { @@ -2160,7 +2160,7 @@ "issues": "https://github.com/utopia-php/database/issues", "source": "https://github.com/utopia-php/database/tree/appwrite-validators" }, - "time": "2023-05-15T13:12:11+00:00" + "time": "2023-05-16T15:28:17+00:00" }, { "name": "utopia-php/domains", From c4fc5c90f007d6d603d2adccc4ef0f2c4daa7fec Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Thu, 15 Jun 2023 12:59:19 +1200 Subject: [PATCH 33/46] Update dependencies --- composer.json | 6 ++--- composer.lock | 68 +++++++++++++++++++++++++-------------------------- 2 files changed, 36 insertions(+), 38 deletions(-) diff --git a/composer.json b/composer.json index 8710cce8a9..792e757ff8 100644 --- a/composer.json +++ b/composer.json @@ -43,13 +43,13 @@ "ext-sockets": "*", "appwrite/php-clamav": "1.1.*", "appwrite/php-runtimes": "0.11.*", - "utopia-php/abuse": "0.25.*", + "utopia-php/abuse": "0.26.*", "utopia-php/analytics": "0.2.*", - "utopia-php/audit": "0.26.*", + "utopia-php/audit": "0.28.*", "utopia-php/cache": "0.8.*", "utopia-php/cli": "0.13.*", "utopia-php/config": "0.2.*", - "utopia-php/database": "dev-appwrite-validators as 0.36.0", + "utopia-php/database": "0.37.*", "utopia-php/domains": "1.1.*", "utopia-php/framework": "0.28.*", "utopia-php/image": "0.5.*", diff --git a/composer.lock b/composer.lock index c9a9933773..3202cbdafd 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "3eadbfe5543aafdf8682ea0465159e3c", + "content-hash": "0f20fb41e9b250b6763af1b734bb8d2d", "packages": [ { "name": "adhocore/jwt", @@ -1802,23 +1802,23 @@ }, { "name": "utopia-php/abuse", - "version": "0.25.0", + "version": "0.26.0", "source": { "type": "git", "url": "https://github.com/utopia-php/abuse.git", - "reference": "49a180cab5316cddec9676d900d5112d03e97ffc" + "reference": "fb73180f0588bc8826b85d433393b983bdc37cfa" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/abuse/zipball/49a180cab5316cddec9676d900d5112d03e97ffc", - "reference": "49a180cab5316cddec9676d900d5112d03e97ffc", + "url": "https://api.github.com/repos/utopia-php/abuse/zipball/fb73180f0588bc8826b85d433393b983bdc37cfa", + "reference": "fb73180f0588bc8826b85d433393b983bdc37cfa", "shasum": "" }, "require": { "ext-curl": "*", "ext-pdo": "*", "php": ">=8.0", - "utopia-php/database": "0.36.*" + "utopia-php/database": "0.37.*" }, "require-dev": { "laravel/pint": "1.5.*", @@ -1845,9 +1845,9 @@ ], "support": { "issues": "https://github.com/utopia-php/abuse/issues", - "source": "https://github.com/utopia-php/abuse/tree/0.25.0" + "source": "https://github.com/utopia-php/abuse/tree/0.26.0" }, - "time": "2023-04-27T15:43:47+00:00" + "time": "2023-06-15T00:53:36+00:00" }, { "name": "utopia-php/analytics", @@ -1906,21 +1906,21 @@ }, { "name": "utopia-php/audit", - "version": "0.26.0", + "version": "0.28.0", "source": { "type": "git", "url": "https://github.com/utopia-php/audit.git", - "reference": "e7228080f14df28737fbb050c180c26d86ac0403" + "reference": "abf4124bec20b6ab3555869b64afe5b274e37165" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/audit/zipball/e7228080f14df28737fbb050c180c26d86ac0403", - "reference": "e7228080f14df28737fbb050c180c26d86ac0403", + "url": "https://api.github.com/repos/utopia-php/audit/zipball/abf4124bec20b6ab3555869b64afe5b274e37165", + "reference": "abf4124bec20b6ab3555869b64afe5b274e37165", "shasum": "" }, "require": { "php": ">=8.0", - "utopia-php/database": "0.36.*" + "utopia-php/database": "0.37.*" }, "require-dev": { "laravel/pint": "1.5.*", @@ -1947,9 +1947,9 @@ ], "support": { "issues": "https://github.com/utopia-php/audit/issues", - "source": "https://github.com/utopia-php/audit/tree/0.26.0" + "source": "https://github.com/utopia-php/audit/tree/0.28.0" }, - "time": "2023-04-27T15:43:50+00:00" + "time": "2023-06-15T00:52:49+00:00" }, { "name": "utopia-php/cache", @@ -2106,16 +2106,16 @@ }, { "name": "utopia-php/database", - "version": "0.36.1", + "version": "0.37.0", "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "f6ab65e59a199da5155c114564077b1ab8c4daef" + "reference": "698c5a44598bc263c58506d4fd526589ea392114" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/f6ab65e59a199da5155c114564077b1ab8c4daef", - "reference": "f6ab65e59a199da5155c114564077b1ab8c4daef", + "url": "https://api.github.com/repos/utopia-php/database/zipball/698c5a44598bc263c58506d4fd526589ea392114", + "reference": "698c5a44598bc263c58506d4fd526589ea392114", "shasum": "" }, "require": { @@ -2126,8 +2126,6 @@ "utopia-php/mongo": "0.2.*" }, "require-dev": { - "ext-mongodb": "*", - "ext-redis": "*", "fakerphp/faker": "^1.14", "laravel/pint": "1.4.*", "mongodb/mongodb": "1.8.0", @@ -2158,9 +2156,9 @@ ], "support": { "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/0.36.1" + "source": "https://github.com/utopia-php/database/tree/0.37.0" }, - "time": "2023-04-27T08:39:55+00:00" + "time": "2023-06-09T07:39:11+00:00" }, { "name": "utopia-php/domains", @@ -3200,16 +3198,16 @@ }, { "name": "matthiasmullie/minify", - "version": "1.3.70", + "version": "1.3.71", "source": { "type": "git", "url": "https://github.com/matthiasmullie/minify.git", - "reference": "2807d9f9bece6877577ad44acb5c801bb3ae536b" + "reference": "ae42a47d7fecc1fbb7277b2f2d84c37a33edc3b1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/matthiasmullie/minify/zipball/2807d9f9bece6877577ad44acb5c801bb3ae536b", - "reference": "2807d9f9bece6877577ad44acb5c801bb3ae536b", + "url": "https://api.github.com/repos/matthiasmullie/minify/zipball/ae42a47d7fecc1fbb7277b2f2d84c37a33edc3b1", + "reference": "ae42a47d7fecc1fbb7277b2f2d84c37a33edc3b1", "shasum": "" }, "require": { @@ -3259,7 +3257,7 @@ ], "support": { "issues": "https://github.com/matthiasmullie/minify/issues", - "source": "https://github.com/matthiasmullie/minify/tree/1.3.70" + "source": "https://github.com/matthiasmullie/minify/tree/1.3.71" }, "funding": [ { @@ -3267,7 +3265,7 @@ "type": "github" } ], - "time": "2022-12-09T12:56:44+00:00" + "time": "2023-04-25T20:33:03+00:00" }, { "name": "matthiasmullie/path-converter", @@ -5581,16 +5579,16 @@ }, { "name": "twig/twig", - "version": "v3.6.0", + "version": "v3.6.1", "source": { "type": "git", "url": "https://github.com/twigphp/Twig.git", - "reference": "106c170d08e8415d78be2d16c3d057d0d108262b" + "reference": "7e7d5839d4bec168dfeef0ac66d5c5a2edbabffd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/twigphp/Twig/zipball/106c170d08e8415d78be2d16c3d057d0d108262b", - "reference": "106c170d08e8415d78be2d16c3d057d0d108262b", + "url": "https://api.github.com/repos/twigphp/Twig/zipball/7e7d5839d4bec168dfeef0ac66d5c5a2edbabffd", + "reference": "7e7d5839d4bec168dfeef0ac66d5c5a2edbabffd", "shasum": "" }, "require": { @@ -5636,7 +5634,7 @@ ], "support": { "issues": "https://github.com/twigphp/Twig/issues", - "source": "https://github.com/twigphp/Twig/tree/v3.6.0" + "source": "https://github.com/twigphp/Twig/tree/v3.6.1" }, "funding": [ { @@ -5648,7 +5646,7 @@ "type": "tidelift" } ], - "time": "2023-05-03T19:06:57+00:00" + "time": "2023-06-08T12:52:13+00:00" } ], "aliases": [], From 742736a479e8b81306fa7e30659631c2fa3c8d61 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Thu, 15 Jun 2023 13:00:24 +1200 Subject: [PATCH 34/46] Update dependencies --- composer.json | 6 ++-- composer.lock | 78 +++++++++++++++++++++++---------------------------- 2 files changed, 38 insertions(+), 46 deletions(-) diff --git a/composer.json b/composer.json index 0ba26540bd..792e757ff8 100644 --- a/composer.json +++ b/composer.json @@ -43,13 +43,13 @@ "ext-sockets": "*", "appwrite/php-clamav": "1.1.*", "appwrite/php-runtimes": "0.11.*", - "utopia-php/abuse": "0.25.*", + "utopia-php/abuse": "0.26.*", "utopia-php/analytics": "0.2.*", - "utopia-php/audit": "0.26.*", + "utopia-php/audit": "0.28.*", "utopia-php/cache": "0.8.*", "utopia-php/cli": "0.13.*", "utopia-php/config": "0.2.*", - "utopia-php/database": "0.36.*", + "utopia-php/database": "0.37.*", "utopia-php/domains": "1.1.*", "utopia-php/framework": "0.28.*", "utopia-php/image": "0.5.*", diff --git a/composer.lock b/composer.lock index a9168dbbf4..3202cbdafd 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "3eadbfe5543aafdf8682ea0465159e3c", + "content-hash": "0f20fb41e9b250b6763af1b734bb8d2d", "packages": [ { "name": "adhocore/jwt", @@ -1802,23 +1802,23 @@ }, { "name": "utopia-php/abuse", - "version": "0.25.0", + "version": "0.26.0", "source": { "type": "git", "url": "https://github.com/utopia-php/abuse.git", - "reference": "49a180cab5316cddec9676d900d5112d03e97ffc" + "reference": "fb73180f0588bc8826b85d433393b983bdc37cfa" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/abuse/zipball/49a180cab5316cddec9676d900d5112d03e97ffc", - "reference": "49a180cab5316cddec9676d900d5112d03e97ffc", + "url": "https://api.github.com/repos/utopia-php/abuse/zipball/fb73180f0588bc8826b85d433393b983bdc37cfa", + "reference": "fb73180f0588bc8826b85d433393b983bdc37cfa", "shasum": "" }, "require": { "ext-curl": "*", "ext-pdo": "*", "php": ">=8.0", - "utopia-php/database": "0.36.*" + "utopia-php/database": "0.37.*" }, "require-dev": { "laravel/pint": "1.5.*", @@ -1845,9 +1845,9 @@ ], "support": { "issues": "https://github.com/utopia-php/abuse/issues", - "source": "https://github.com/utopia-php/abuse/tree/0.25.0" + "source": "https://github.com/utopia-php/abuse/tree/0.26.0" }, - "time": "2023-04-27T15:43:47+00:00" + "time": "2023-06-15T00:53:36+00:00" }, { "name": "utopia-php/analytics", @@ -1906,21 +1906,21 @@ }, { "name": "utopia-php/audit", - "version": "0.26.0", + "version": "0.28.0", "source": { "type": "git", "url": "https://github.com/utopia-php/audit.git", - "reference": "e7228080f14df28737fbb050c180c26d86ac0403" + "reference": "abf4124bec20b6ab3555869b64afe5b274e37165" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/audit/zipball/e7228080f14df28737fbb050c180c26d86ac0403", - "reference": "e7228080f14df28737fbb050c180c26d86ac0403", + "url": "https://api.github.com/repos/utopia-php/audit/zipball/abf4124bec20b6ab3555869b64afe5b274e37165", + "reference": "abf4124bec20b6ab3555869b64afe5b274e37165", "shasum": "" }, "require": { "php": ">=8.0", - "utopia-php/database": "0.36.*" + "utopia-php/database": "0.37.*" }, "require-dev": { "laravel/pint": "1.5.*", @@ -1947,9 +1947,9 @@ ], "support": { "issues": "https://github.com/utopia-php/audit/issues", - "source": "https://github.com/utopia-php/audit/tree/0.26.0" + "source": "https://github.com/utopia-php/audit/tree/0.28.0" }, - "time": "2023-04-27T15:43:50+00:00" + "time": "2023-06-15T00:52:49+00:00" }, { "name": "utopia-php/cache", @@ -2106,16 +2106,16 @@ }, { "name": "utopia-php/database", - "version": "0.36.1", + "version": "0.37.0", "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "f6ab65e59a199da5155c114564077b1ab8c4daef" + "reference": "698c5a44598bc263c58506d4fd526589ea392114" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/f6ab65e59a199da5155c114564077b1ab8c4daef", - "reference": "f6ab65e59a199da5155c114564077b1ab8c4daef", + "url": "https://api.github.com/repos/utopia-php/database/zipball/698c5a44598bc263c58506d4fd526589ea392114", + "reference": "698c5a44598bc263c58506d4fd526589ea392114", "shasum": "" }, "require": { @@ -2126,8 +2126,6 @@ "utopia-php/mongo": "0.2.*" }, "require-dev": { - "ext-mongodb": "*", - "ext-redis": "*", "fakerphp/faker": "^1.14", "laravel/pint": "1.4.*", "mongodb/mongodb": "1.8.0", @@ -2144,11 +2142,7 @@ "Utopia\\Database\\": "src/Database" } }, - "autoload-dev": { - "psr-4": { - "Utopia\\Tests\\": "tests/Database" - } - }, + "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], @@ -2162,9 +2156,9 @@ ], "support": { "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/0.36.1" + "source": "https://github.com/utopia-php/database/tree/0.37.0" }, - "time": "2023-04-27T08:39:55+00:00" + "time": "2023-06-09T07:39:11+00:00" }, { "name": "utopia-php/domains", @@ -3204,16 +3198,16 @@ }, { "name": "matthiasmullie/minify", - "version": "1.3.70", + "version": "1.3.71", "source": { "type": "git", "url": "https://github.com/matthiasmullie/minify.git", - "reference": "2807d9f9bece6877577ad44acb5c801bb3ae536b" + "reference": "ae42a47d7fecc1fbb7277b2f2d84c37a33edc3b1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/matthiasmullie/minify/zipball/2807d9f9bece6877577ad44acb5c801bb3ae536b", - "reference": "2807d9f9bece6877577ad44acb5c801bb3ae536b", + "url": "https://api.github.com/repos/matthiasmullie/minify/zipball/ae42a47d7fecc1fbb7277b2f2d84c37a33edc3b1", + "reference": "ae42a47d7fecc1fbb7277b2f2d84c37a33edc3b1", "shasum": "" }, "require": { @@ -3263,7 +3257,7 @@ ], "support": { "issues": "https://github.com/matthiasmullie/minify/issues", - "source": "https://github.com/matthiasmullie/minify/tree/1.3.70" + "source": "https://github.com/matthiasmullie/minify/tree/1.3.71" }, "funding": [ { @@ -3271,7 +3265,7 @@ "type": "github" } ], - "time": "2022-12-09T12:56:44+00:00" + "time": "2023-04-25T20:33:03+00:00" }, { "name": "matthiasmullie/path-converter", @@ -5585,16 +5579,16 @@ }, { "name": "twig/twig", - "version": "v3.6.0", + "version": "v3.6.1", "source": { "type": "git", "url": "https://github.com/twigphp/Twig.git", - "reference": "106c170d08e8415d78be2d16c3d057d0d108262b" + "reference": "7e7d5839d4bec168dfeef0ac66d5c5a2edbabffd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/twigphp/Twig/zipball/106c170d08e8415d78be2d16c3d057d0d108262b", - "reference": "106c170d08e8415d78be2d16c3d057d0d108262b", + "url": "https://api.github.com/repos/twigphp/Twig/zipball/7e7d5839d4bec168dfeef0ac66d5c5a2edbabffd", + "reference": "7e7d5839d4bec168dfeef0ac66d5c5a2edbabffd", "shasum": "" }, "require": { @@ -5640,7 +5634,7 @@ ], "support": { "issues": "https://github.com/twigphp/Twig/issues", - "source": "https://github.com/twigphp/Twig/tree/v3.6.0" + "source": "https://github.com/twigphp/Twig/tree/v3.6.1" }, "funding": [ { @@ -5652,14 +5646,12 @@ "type": "tidelift" } ], - "time": "2023-05-03T19:06:57+00:00" + "time": "2023-06-08T12:52:13+00:00" } ], "aliases": [], "minimum-stability": "stable", - "stability-flags": { - "utopia-php/database": 20 - }, + "stability-flags": [], "prefer-stable": false, "prefer-lowest": false, "platform": { From 10f06226d3e77807831500f37822dc26f3cc9a3d Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Thu, 15 Jun 2023 13:05:37 +1200 Subject: [PATCH 35/46] Make error optional --- app/config/collections.php | 8 ++++---- app/controllers/api/databases.php | 2 -- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/app/config/collections.php b/app/config/collections.php index dbc212e63c..b5c9daccc8 100644 --- a/app/config/collections.php +++ b/app/config/collections.php @@ -280,8 +280,8 @@ $collections = [ 'format' => '', 'size' => 2048, 'signed' => true, - 'required' => true, - 'default' => '', + 'required' => false, + 'default' => null, 'array' => false, 'filters' => [], ], @@ -478,8 +478,8 @@ $collections = [ 'format' => '', 'size' => 2048, 'signed' => true, - 'required' => true, - 'default' => '', + 'required' => false, + 'default' => null, 'array' => false, 'filters' => [], ], diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index e94c9adb7f..c4ff448ce4 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -118,7 +118,6 @@ function createAttribute(string $databaseId, string $collectionId, Document $att 'collectionId' => $collectionId, 'type' => $type, 'status' => 'processing', // processing, available, failed, deleting, stuck - 'error' => '', 'size' => $size, 'required' => $required, 'signed' => $signed, @@ -2437,7 +2436,6 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/indexes') 'collectionInternalId' => $collection->getInternalId(), 'collectionId' => $collectionId, 'type' => $type, - 'error' => '', 'attributes' => $attributes, 'lengths' => $lengths, 'orders' => $orders, From 44e7a822b18421e7ac3b4022754b00f47dc2361b Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Thu, 15 Jun 2023 13:25:25 +1200 Subject: [PATCH 36/46] Single catch with type check --- app/workers/databases.php | 126 ++++++++++++++------------------------ 1 file changed, 45 insertions(+), 81 deletions(-) diff --git a/app/workers/databases.php b/app/workers/databases.php index 2b16fb8f0b..6600fc2c01 100644 --- a/app/workers/databases.php +++ b/app/workers/databases.php @@ -102,7 +102,7 @@ class DatabaseV1 extends Worker case Database::VAR_RELATIONSHIP: $relatedCollection = $dbForProject->getDocument('database_' . $database->getInternalId(), $options['relatedCollection']); if ($relatedCollection->isEmpty()) { - throw new Exception('Collection not found'); + throw new DatabaseException('Collection not found'); } if ( @@ -116,7 +116,7 @@ class DatabaseV1 extends Worker onDelete: $options['onDelete'], ) ) { - throw new Exception('Failed to create Attribute'); + throw new DatabaseException('Failed to create Attribute'); } if ($options['twoWay']) { @@ -131,42 +131,27 @@ class DatabaseV1 extends Worker } $dbForProject->updateDocument('attributes', $attribute->getId(), $attribute->setAttribute('status', 'available')); - } catch (DatabaseException $e) { - Console::error($e->getMessage()); - $dbForProject->updateDocument( - 'attributes', - $attribute->getId(), - $attribute - ->setAttribute('status', 'failed') - ->setAttribute('error', $e->getMessage()) - ); - - if ($type === Database::VAR_RELATIONSHIP && $options['twoWay']) { - $relatedAttribute = $dbForProject->getDocument('attributes', $database->getInternalId() . '_' . $relatedCollection->getInternalId() . '_' . $options['twoWayKey']); - $dbForProject->updateDocument( - 'attributes', - $relatedAttribute->getId(), - $relatedAttribute - ->setAttribute('status', 'failed') - ->setAttribute('error', $e->getMessage()); - } } catch (Exception $e) { + Console::error($e->getMessage()); + + if ($e instanceof DatabaseException) { + $attribute->setAttribute('error', $e->getMessage()); + if (isset($relatedAttribute)) { + $relatedAttribute->setAttribute('error', $e->getMessage()); + } + } + $dbForProject->updateDocument( 'attributes', $attribute->getId(), - $attribute - ->setAttribute('status', 'failed') - ->setAttribute('error', '') + $attribute->setAttribute('status', 'failed') ); - if ($type === Database::VAR_RELATIONSHIP && $options['twoWay']) { - $relatedAttribute = $dbForProject->getDocument('attributes', $database->getInternalId() . '_' . $relatedCollection->getInternalId() . '_' . $options['twoWayKey']); + if (isset($relatedAttribute)) { $dbForProject->updateDocument( 'attributes', $relatedAttribute->getId(), - $relatedAttribute - ->setAttribute('status', 'failed') - ->setAttribute('error', '') + $relatedAttribute->setAttribute('status', 'failed') ); } } finally { @@ -236,7 +221,7 @@ class DatabaseV1 extends Worker if ($options['twoWay']) { $relatedCollection = $dbForProject->getDocument('database_' . $database->getInternalId(), $options['relatedCollection']); if ($relatedCollection->isEmpty()) { - throw new Exception(Exception::COLLECTION_NOT_FOUND); + throw new DatabaseException('Collection not found'); } $relatedAttribute = $dbForProject->getDocument('attributes', $database->getInternalId() . '_' . $relatedCollection->getInternalId() . '_' . $options['twoWayKey']); } @@ -246,7 +231,7 @@ class DatabaseV1 extends Worker throw new DatabaseException('Failed to delete Relationship'); } } elseif (!$dbForProject->deleteAttribute('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), $key)) { - throw new Exception('Failed to delete Attribute'); + throw new DatabaseException('Failed to delete Attribute'); } } @@ -255,37 +240,27 @@ class DatabaseV1 extends Worker if (!$relatedAttribute->isEmpty()) { $dbForProject->deleteDocument('attributes', $relatedAttribute->getId()); } - } catch (DatabaseException $e) { - Console::error($e->getMessage()); - $dbForProject->updateDocument( - 'attributes', - $attribute->getId(), - $attribute - ->setAttribute('status', 'stuck') - ->setAttribute('error', $e->getMessage()) - ); - $dbForProject->updateDocument( - 'attributes', - $relatedAttribute->getId(), - $relatedAttribute - ->setAttribute('status', 'stuck') - ->setAttribute('error', $e->getMessage()) - ); } catch (Exception $e) { + Console::error($e->getMessage()); + + if ($e instanceof DatabaseException) { + $attribute->setAttribute('error', $e->getMessage()); + if (!$relatedAttribute->isEmpty()) { + $relatedAttribute->setAttribute('error', $e->getMessage()); + } + } $dbForProject->updateDocument( 'attributes', $attribute->getId(), - $attribute - ->setAttribute('status', 'stuck') - ->setAttribute('error', '') - ); - $dbForProject->updateDocument( - 'attributes', - $relatedAttribute->getId(), - $relatedAttribute - ->setAttribute('status', 'stuck') - ->setAttribute('error', '') + $attribute->setAttribute('status', 'stuck') ); + if (!$relatedAttribute->isEmpty()) { + $dbForProject->updateDocument( + 'attributes', + $relatedAttribute->getId(), + $relatedAttribute->setAttribute('status', 'stuck') + ); + } } finally { $target = Realtime::fromPayload( // Pass first, most verbose event pattern @@ -398,22 +373,16 @@ class DatabaseV1 extends Worker throw new DatabaseException('Failed to create Index'); } $dbForProject->updateDocument('indexes', $index->getId(), $index->setAttribute('status', 'available')); - } catch (DatabaseException $e) { - Console::error($e->getMessage()); - $dbForProject->updateDocument( - 'indexes', - $index->getId(), - $index - ->setAttribute('status', 'failed') - ->setAttribute('error', $e->getMessage()) - ); } catch (Exception $e) { + Console::error($e->getMessage()); + + if ($e instanceof DatabaseException) { + $index->setAttribute('error', $e->getMessage()); + } $dbForProject->updateDocument( 'indexes', $index->getId(), - $index - ->setAttribute('status', 'failed') - ->setAttribute('error', '') + $index->setAttribute('status', 'failed') ); } finally { $target = Realtime::fromPayload( @@ -445,6 +414,7 @@ class DatabaseV1 extends Worker * @param Document $collection * @param Document $index * @param string $projectId + * @throws Exception */ protected function deleteIndex(Document $database, Document $collection, Document $index, string $projectId): void { @@ -465,22 +435,16 @@ class DatabaseV1 extends Worker throw new DatabaseException('Failed to delete index'); } $dbForProject->deleteDocument('indexes', $index->getId()); - } catch (DatabaseException $e) { - Console::error($e->getMessage()); - $dbForProject->updateDocument( - 'indexes', - $index->getId(), - $index - ->setAttribute('status', 'stuck') - ->setAttribute('error', $e->getMessage()) - ); } catch (Exception $e) { + Console::error($e->getMessage()); + + if ($e instanceof DatabaseException) { + $index->setAttribute('error', $e->getMessage()); + } $dbForProject->updateDocument( 'indexes', $index->getId(), - $index - ->setAttribute('status', 'stuck') - ->setAttribute('error', '') + $index->setAttribute('status', 'stuck') ); } finally { $target = Realtime::fromPayload( From 4daa023663362e50b8bd7179b38e494389417e41 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Thu, 15 Jun 2023 13:32:49 +1200 Subject: [PATCH 37/46] Fix filter --- src/Appwrite/Utopia/Request/Filters/V15.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Appwrite/Utopia/Request/Filters/V15.php b/src/Appwrite/Utopia/Request/Filters/V15.php index 50e5ec0db7..318096fe0d 100644 --- a/src/Appwrite/Utopia/Request/Filters/V15.php +++ b/src/Appwrite/Utopia/Request/Filters/V15.php @@ -200,11 +200,11 @@ class V15 extends Filter $operations = [ 'equal' => Query::TYPE_EQUAL, - 'notEqual' => Query::TYPE_NOTEQUAL, + 'notEqual' => Query::TYPE_NOT_EQUAL, 'lesser' => Query::TYPE_LESSER, - 'lesserEqual' => Query::TYPE_LESSEREQUAL, + 'lesserEqual' => Query::TYPE_LESSER_EQUAL, 'greater' => Query::TYPE_GREATER, - 'greaterEqual' => Query::TYPE_GREATEREQUAL, + 'greaterEqual' => Query::TYPE_GREATER_EQUAL, 'search' => Query::TYPE_SEARCH, ]; foreach ($content['queries'] as $i => $query) { From ab2cd297f9940d21c73e3db426a75d108f144208 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Thu, 15 Jun 2023 13:45:10 +1200 Subject: [PATCH 38/46] Fix imports --- app/workers/databases.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/app/workers/databases.php b/app/workers/databases.php index 6600fc2c01..f3e678d389 100644 --- a/app/workers/databases.php +++ b/app/workers/databases.php @@ -7,8 +7,6 @@ use Appwrite\Resque\Worker; use Utopia\CLI\Console; use Utopia\Database\Database; use Utopia\Database\Document; -use Utopia\Database\Helpers\ID; -use Exception; use Utopia\Database\Exception as DatabaseException; require_once __DIR__ . '/../init.php'; @@ -217,7 +215,7 @@ class DatabaseV1 extends Worker try { if ($status !== 'failed') { - if ($type === Database::VAR_RELATIONSHIP) { + if ($type === Database::VAR_RELATIONSHIP) { if ($options['twoWay']) { $relatedCollection = $dbForProject->getDocument('database_' . $database->getInternalId(), $options['relatedCollection']); if ($relatedCollection->isEmpty()) { @@ -310,8 +308,7 @@ class DatabaseV1 extends Worker $index ->setAttribute('attributes', $attributes, Document::SET_TYPE_ASSIGN) ->setAttribute('lengths', $lengths, Document::SET_TYPE_ASSIGN) - ->setAttribute('orders', $orders, Document::SET_TYPE_ASSIGN) - ; + ->setAttribute('orders', $orders, Document::SET_TYPE_ASSIGN); // Check if an index exists with the same attributes and orders $exists = false; From 0363993f13752f78717bd596b5e00574ae5e8748 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Thu, 15 Jun 2023 17:28:35 +1200 Subject: [PATCH 39/46] Fix errors --- app/config/errors.php | 5 + app/workers/databases.php | 10 +- src/Appwrite/Extend/Exception.php | 1 + .../e2e/Services/Databases/DatabasesBase.php | 94 ++++++++++++++++--- 4 files changed, 94 insertions(+), 16 deletions(-) diff --git a/app/config/errors.php b/app/config/errors.php index 9fadde6e93..1ff8d2e8e7 100644 --- a/app/config/errors.php +++ b/app/config/errors.php @@ -487,6 +487,11 @@ return [ 'description' => 'Index with the requested ID already exists.', 'code' => 409, ], + Exception::INDEX_INVALID => [ + 'name' => Exception::INDEX_INVALID, + 'description' => 'Index invalid.', + 'code' => 400, + ], /** Project Errors */ Exception::PROJECT_NOT_FOUND => [ diff --git a/app/workers/databases.php b/app/workers/databases.php index f3e678d389..ecdb667f0d 100644 --- a/app/workers/databases.php +++ b/app/workers/databases.php @@ -129,7 +129,7 @@ class DatabaseV1 extends Worker } $dbForProject->updateDocument('attributes', $attribute->getId(), $attribute->setAttribute('status', 'available')); - } catch (Exception $e) { + } catch (\Exception $e) { Console::error($e->getMessage()); if ($e instanceof DatabaseException) { @@ -238,7 +238,7 @@ class DatabaseV1 extends Worker if (!$relatedAttribute->isEmpty()) { $dbForProject->deleteDocument('attributes', $relatedAttribute->getId()); } - } catch (Exception $e) { + } catch (\Exception $e) { Console::error($e->getMessage()); if ($e instanceof DatabaseException) { @@ -346,6 +346,7 @@ class DatabaseV1 extends Worker * @param Document $collection * @param Document $index * @param string $projectId + * @throws \Exception */ protected function createIndex(Document $database, Document $collection, Document $index, string $projectId): void { @@ -370,7 +371,7 @@ class DatabaseV1 extends Worker throw new DatabaseException('Failed to create Index'); } $dbForProject->updateDocument('indexes', $index->getId(), $index->setAttribute('status', 'available')); - } catch (Exception $e) { + } catch (\Exception $e) { Console::error($e->getMessage()); if ($e instanceof DatabaseException) { @@ -411,7 +412,6 @@ class DatabaseV1 extends Worker * @param Document $collection * @param Document $index * @param string $projectId - * @throws Exception */ protected function deleteIndex(Document $database, Document $collection, Document $index, string $projectId): void { @@ -432,7 +432,7 @@ class DatabaseV1 extends Worker throw new DatabaseException('Failed to delete index'); } $dbForProject->deleteDocument('indexes', $index->getId()); - } catch (Exception $e) { + } catch (\Exception $e) { Console::error($e->getMessage()); if ($e instanceof DatabaseException) { diff --git a/src/Appwrite/Extend/Exception.php b/src/Appwrite/Extend/Exception.php index ebd12851e2..f27d22d0f5 100644 --- a/src/Appwrite/Extend/Exception.php +++ b/src/Appwrite/Extend/Exception.php @@ -154,6 +154,7 @@ class Exception extends \Exception public const INDEX_NOT_FOUND = 'index_not_found'; public const INDEX_LIMIT_EXCEEDED = 'index_limit_exceeded'; public const INDEX_ALREADY_EXISTS = 'index_already_exists'; + public const INDEX_INVALID = 'index_invalid'; /** Projects */ public const PROJECT_NOT_FOUND = 'project_not_found'; diff --git a/tests/e2e/Services/Databases/DatabasesBase.php b/tests/e2e/Services/Databases/DatabasesBase.php index 144adfb989..bd9443adec 100644 --- a/tests/e2e/Services/Databases/DatabasesBase.php +++ b/tests/e2e/Services/Databases/DatabasesBase.php @@ -174,7 +174,18 @@ trait DatabasesBase 'x-appwrite-key' => $this->getProject()['apiKey'] ]), [ 'key' => 'description', - 'size' => 256, + 'size' => 512, + 'required' => false, + 'default' => '', + ]); + + $tagline = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $data['moviesId'] . '/attributes/string', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'tagline', + 'size' => 512, 'required' => false, 'default' => '', ]); @@ -241,10 +252,17 @@ trait DatabasesBase $this->assertEquals(202, $description['headers']['status-code']); $this->assertEquals($description['body']['key'], 'description'); $this->assertEquals($description['body']['type'], 'string'); - $this->assertEquals($description['body']['size'], 256); + $this->assertEquals($description['body']['size'], 512); $this->assertEquals($description['body']['required'], false); $this->assertEquals($description['body']['default'], ''); + $this->assertEquals(202, $tagline['headers']['status-code']); + $this->assertEquals($tagline['body']['key'], 'tagline'); + $this->assertEquals($tagline['body']['type'], 'string'); + $this->assertEquals($tagline['body']['size'], 512); + $this->assertEquals($tagline['body']['required'], false); + $this->assertEquals($tagline['body']['default'], ''); + $this->assertEquals(202, $releaseYear['headers']['status-code']); $this->assertEquals($releaseYear['body']['key'], 'releaseYear'); $this->assertEquals($releaseYear['body']['type'], 'integer'); @@ -282,17 +300,18 @@ trait DatabasesBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'] - ]), []); + ])); $this->assertIsArray($movies['body']['attributes']); - $this->assertCount(7, $movies['body']['attributes']); + $this->assertCount(8, $movies['body']['attributes']); $this->assertEquals($movies['body']['attributes'][0]['key'], $title['body']['key']); $this->assertEquals($movies['body']['attributes'][1]['key'], $description['body']['key']); - $this->assertEquals($movies['body']['attributes'][2]['key'], $releaseYear['body']['key']); - $this->assertEquals($movies['body']['attributes'][3]['key'], $duration['body']['key']); - $this->assertEquals($movies['body']['attributes'][4]['key'], $actors['body']['key']); - $this->assertEquals($movies['body']['attributes'][5]['key'], $datetime['body']['key']); - $this->assertEquals($movies['body']['attributes'][6]['key'], $relationship['body']['key']); + $this->assertEquals($movies['body']['attributes'][2]['key'], $tagline['body']['key']); + $this->assertEquals($movies['body']['attributes'][3]['key'], $releaseYear['body']['key']); + $this->assertEquals($movies['body']['attributes'][4]['key'], $duration['body']['key']); + $this->assertEquals($movies['body']['attributes'][5]['key'], $actors['body']['key']); + $this->assertEquals($movies['body']['attributes'][6]['key'], $datetime['body']['key']); + $this->assertEquals($movies['body']['attributes'][7]['key'], $relationship['body']['key']); return $data; } @@ -888,6 +907,7 @@ trait DatabasesBase public function testCreateIndexes(array $data): array { $databaseId = $data['databaseId']; + $titleIndex = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $data['moviesId'] . '/indexes', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], @@ -956,7 +976,6 @@ trait DatabasesBase $this->assertEquals('available', $movies['body']['indexes'][1]['status']); $this->assertEquals('available', $movies['body']['indexes'][2]['status']); - $releaseWithDate = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $data['moviesId'] . '/indexes', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], @@ -973,6 +992,59 @@ trait DatabasesBase $this->assertCount(1, $releaseWithDate['body']['attributes']); $this->assertEquals('birthDay', $releaseWithDate['body']['attributes'][0]); + // Test for failure + $fulltextReleaseYear = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $data['moviesId'] . '/indexes', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'releaseYearDated', + 'type' => 'fulltext', + 'attributes' => ['releaseYear'], + ]); + + $this->assertEquals(400, $fulltextReleaseYear['headers']['status-code']); + $this->assertEquals($fulltextReleaseYear['body']['message'], 'Attribute "releaseYear" cannot be part of a FULLTEXT index, must be of type string'); + + $noAttributes = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $data['moviesId'] . '/indexes', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'none', + 'type' => 'key', + 'attributes' => [], + ]); + + $this->assertEquals(400, $noAttributes['headers']['status-code']); + $this->assertEquals($noAttributes['body']['message'], 'No attributes provided for index'); + + $duplicates = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $data['moviesId'] . '/indexes', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'duplicate', + 'type' => 'fulltext', + 'attributes' => ['releaseYear', 'releaseYear'], + ]); + + $this->assertEquals(400, $duplicates['headers']['status-code']); + $this->assertEquals($duplicates['body']['message'], 'Duplicate attributes provided'); + + $tooLong = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $data['moviesId'] . '/indexes', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ]), [ + 'key' => 'tooLong', + 'type' => 'key', + 'attributes' => ['description', 'tagline'], + ]); + + $this->assertEquals(400, $tooLong['headers']['status-code']); + $this->assertStringContainsString('Index length is longer than the maximum', $tooLong['body']['message']); + return $data; } @@ -3419,7 +3491,7 @@ trait DatabasesBase ]); $this->assertEquals(400, $documents['headers']['status-code']); - $this->assertEquals('Query not valid: Cannot query nested attribute on: library', $documents['body']['message']); + $this->assertEquals('Invalid query: Cannot query nested attribute on: library', $documents['body']['message']); $response = $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId . '/collections/' . $person['body']['$id'] . '/attributes/library', array_merge([ 'content-type' => 'application/json', From 95b06c660a5ace1b2f2c14eb28ea528f9d8fd0a0 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Thu, 15 Jun 2023 17:29:03 +1200 Subject: [PATCH 40/46] Add index validator --- app/controllers/api/databases.php | 119 ++++++++++++++++-------------- 1 file changed, 64 insertions(+), 55 deletions(-) diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index e1e941bfaa..f64b4d07c0 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -1,56 +1,57 @@ createCollection('database_' . $database->getInternalId(), $attributes, $indexes); - } catch (DuplicateException $th) { + } catch (DuplicateException) { throw new Exception(Exception::DATABASE_ALREADY_EXISTS); } @@ -637,7 +638,7 @@ App::put('/v1/databases/:databaseId') ->setAttribute('name', $name) ->setAttribute('enabled', $enabled) ->setAttribute('search', implode(' ', [$databaseId, $name]))); - } catch (AuthorizationException $exception) { + } catch (AuthorizationException) { throw new Exception(Exception::USER_UNAUTHORIZED); } catch (StructureException $exception) { throw new Exception(Exception::DOCUMENT_INVALID_STRUCTURE, 'Bad structure. ' . $exception->getMessage()); @@ -2345,6 +2346,7 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/indexes') if ($db->isEmpty()) { throw new Exception(Exception::DATABASE_NOT_FOUND); } + $collection = $dbForProject->getDocument('database_' . $db->getInternalId(), $collectionId); if ($collection->isEmpty()) { @@ -2425,21 +2427,28 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/indexes') $lengths[$i] = ($attributeType === Database::VAR_STRING) ? $attributeSize : null; } + $index = new Document([ + '$id' => ID::custom($db->getInternalId() . '_' . $collection->getInternalId() . '_' . $key), + 'key' => $key, + 'status' => 'processing', // processing, available, failed, deleting, stuck + 'databaseInternalId' => $db->getInternalId(), + 'databaseId' => $databaseId, + 'collectionInternalId' => $collection->getInternalId(), + 'collectionId' => $collectionId, + 'type' => $type, + 'attributes' => $attributes, + 'lengths' => $lengths, + 'orders' => $orders, + ]); + + $validator = new IndexValidator($dbForProject->getAdapter()->getMaxIndexLength()); + if (!$validator->isValid($collection->setAttribute('indexes', $index, Document::SET_TYPE_APPEND))) { + throw new Exception(Exception::INDEX_INVALID, $validator->getDescription()); + } + try { - $index = $dbForProject->createDocument('indexes', new Document([ - '$id' => ID::custom($db->getInternalId() . '_' . $collection->getInternalId() . '_' . $key), - 'key' => $key, - 'status' => 'processing', // processing, available, failed, deleting, stuck - 'databaseInternalId' => $db->getInternalId(), - 'databaseId' => $databaseId, - 'collectionInternalId' => $collection->getInternalId(), - 'collectionId' => $collectionId, - 'type' => $type, - 'attributes' => $attributes, - 'lengths' => $lengths, - 'orders' => $orders, - ])); - } catch (DuplicateException $th) { + $index = $dbForProject->createDocument('indexes', $index); + } catch (DuplicateException) { throw new Exception(Exception::INDEX_ALREADY_EXISTS); } From 9903897373fab3c2a55e458585cc239a4f4ca92e Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Thu, 15 Jun 2023 17:29:23 +1200 Subject: [PATCH 41/46] Fix audits --- app/workers/audits.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/workers/audits.php b/app/workers/audits.php index b25430ec41..b86649543b 100644 --- a/app/workers/audits.php +++ b/app/workers/audits.php @@ -40,7 +40,6 @@ class AuditsV1 extends Worker $dbForProject = $this->getProjectDB($project->getId()); $audit = new Audit($dbForProject); $audit->log( - userInternalId: $user->getInternalId(), userId: $user->getId(), // Pass first, most verbose event pattern event: $event, From 813e0d6c6c37ad991a696d53ff618ce71ab29117 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Thu, 15 Jun 2023 17:40:36 +1200 Subject: [PATCH 42/46] Increase sleep --- tests/e2e/Services/Realtime/RealtimeCustomClientTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/e2e/Services/Realtime/RealtimeCustomClientTest.php b/tests/e2e/Services/Realtime/RealtimeCustomClientTest.php index 858fec7d29..4f880338a4 100644 --- a/tests/e2e/Services/Realtime/RealtimeCustomClientTest.php +++ b/tests/e2e/Services/Realtime/RealtimeCustomClientTest.php @@ -1294,7 +1294,7 @@ class RealtimeCustomClientTest extends Scope $this->assertNotEmpty($deployment['body']['$id']); // Wait for deployment to be built. - sleep(5); + sleep(10); $response = $this->client->call(Client::METHOD_PATCH, '/functions/' . $functionId . '/deployments/' . $deploymentId, array_merge([ 'content-type' => 'application/json', From d84223091d57fa1f0426e5b09013a6c83c0bb85f Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Thu, 15 Jun 2023 18:41:20 +1200 Subject: [PATCH 43/46] Update database --- composer.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/composer.lock b/composer.lock index 3202cbdafd..38f6a67fa8 100644 --- a/composer.lock +++ b/composer.lock @@ -2106,16 +2106,16 @@ }, { "name": "utopia-php/database", - "version": "0.37.0", + "version": "0.37.1", "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "698c5a44598bc263c58506d4fd526589ea392114" + "reference": "4035d3f7e3393385eabc7816055047659c6fb4d3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/698c5a44598bc263c58506d4fd526589ea392114", - "reference": "698c5a44598bc263c58506d4fd526589ea392114", + "url": "https://api.github.com/repos/utopia-php/database/zipball/4035d3f7e3393385eabc7816055047659c6fb4d3", + "reference": "4035d3f7e3393385eabc7816055047659c6fb4d3", "shasum": "" }, "require": { @@ -2156,9 +2156,9 @@ ], "support": { "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/0.37.0" + "source": "https://github.com/utopia-php/database/tree/0.37.1" }, - "time": "2023-06-09T07:39:11+00:00" + "time": "2023-06-15T06:36:27+00:00" }, { "name": "utopia-php/domains", From d3e7830620d52c63f691219d8355e90e7f7d2d90 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Fri, 16 Jun 2023 14:16:19 +1200 Subject: [PATCH 44/46] Update changes --- CHANGES.md | 16 +++++++++++++++- app/controllers/api/account.php | 2 +- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index f64b2ec4e1..d4cf425908 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,7 +2,21 @@ ## Features -- Add error attribute to Collection Indexes and Attributes [#4575](https://github.com/appwrite/appwrite/pull/4575) +- Add error attribute to indexes and attributes [#4575](https://github.com/appwrite/appwrite/pull/4575) +- Add new index validation rules [#5710](https://github.com/appwrite/appwrite/pull/5710) + +## Fixes + +- Fix cascading deletes across multiple levels [DB #269](https://github.com/utopia-php/database/pull/269) +- Fix identical two-way keys not throwing duplicate exceptions [DB #273](https://github.com/utopia-php/database/pull/273) +- Fix search wildcards [DB #279](https://github.com/utopia-php/database/pull/279) +- Fix permissions returning as an object instead of list [DB #281](https://github.com/utopia-php/database/pull/281) +- Fix missing collection not found error [DB #282](https://github.com/utopia-php/database/pull/282) + +## Changes + +- Improve permission indexes [DB #248](https://github.com/utopia-php/database/pull/248) +- Validators back-ported to Utopia [#5439](https://github.com/appwrite/appwrite/pull/5439) # Version 1.3.7 diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index b1e16e2f70..49c5ef3376 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -1656,7 +1656,7 @@ App::patch('/v1/account/email') try { $user = $dbForProject->withRequestTimestamp($requestTimestamp, fn () => $dbForProject->updateDocument('users', $user->getId(), $user)); - } catch (Duplicate $th) { + } catch (Duplicate) { throw new Exception(Exception::USER_EMAIL_ALREADY_EXISTS); } From 840a1548d2b528c3342536c29d75afcf6da2ae3d Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Fri, 16 Jun 2023 14:17:17 +1200 Subject: [PATCH 45/46] Remove error --- CHANGES.md | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index d4cf425908..527b37f13d 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -136,7 +136,6 @@ - Added support for the new Appwrite Console [#4655](https://github.com/appwrite/appwrite/pull/4655) - Added new property to projects configuration: `authDuration` which allows you to alter the duration of signed in sessions for your project. [#4618](https://github.com/appwrite/appwrite/pull/4618) -# Version 1.1.0 ## Bugs - Fix license detection for Flutter and Dart SDKs [#4435](https://github.com/appwrite/appwrite/pull/4435) - Fix missing realtime event for create function deployment [#4574](https://github.com/appwrite/appwrite/pull/4574) From 354c8c66936a9738f704d72873a5938d3beb7399 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Fri, 16 Jun 2023 14:20:56 +1200 Subject: [PATCH 46/46] Revert stopOnFailure --- phpunit.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpunit.xml b/phpunit.xml index 3d15bbd21a..f83f9f0fae 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -6,7 +6,7 @@ convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" - stopOnFailure="true" + stopOnFailure="false" >