diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Create.php index 0dbe3eebbd..9b52b482bb 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Create.php @@ -4,9 +4,10 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases; use Appwrite\Event\Event; use Appwrite\Extend\Exception; -use Appwrite\Platform\Modules\Databases\SDKMethod; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; +use Appwrite\SDK\Deprecated; +use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Database\Validator\CustomId; use Appwrite\Utopia\Response as UtopiaResponse; @@ -42,20 +43,40 @@ class Create extends Action ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('audits.event', 'database.create') ->label('audits.resource', 'database/{response.$id}') - ->label('sdk', SDKMethod::withGridsAPI( - namespace: 'databases', - group: 'databases', - name: 'create', - description: '/docs/references/databases/create.md', - auth: [AuthType::KEY], - responses: [ - new SDKResponse( - code: SwooleResponse::STATUS_CODE_CREATED, - model: UtopiaResponse::MODEL_DATABASE, + ->label('sdk', [ + new Method( + namespace: 'databases', + group: 'databases', + name: 'create', + description: '/docs/references/databases/create.md', + auth: [AuthType::KEY], + responses: [ + new SDKResponse( + code: SwooleResponse::STATUS_CODE_CREATED, + model: UtopiaResponse::MODEL_DATABASE, + ) + ], + contentType: ContentType::JSON, + deprecated: new Deprecated( + since: '1.8.0', + replaceWith: 'grids.createDatabase', ) - ], - contentType: ContentType::JSON - )) + ), + new Method( + namespace: 'grids', + group: 'grids', + name: 'createDatabase', + description: '/docs/references/grids/create-database.md', + auth: [AuthType::KEY], + responses: [ + new SDKResponse( + code: SwooleResponse::STATUS_CODE_CREATED, + model: UtopiaResponse::MODEL_DATABASE, + ) + ], + contentType: ContentType::JSON + ) + ]) ->param('databaseId', '', new CustomId(), 'Unique Id. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.') ->param('name', '', new Text(128), 'Database name. Max length: 128 chars.') ->param('enabled', true, new Boolean(), 'Is the database enabled? When set to \'disabled\', users cannot access the database but Server SDKs with an API key can still read and write to the database. No data is lost when this is toggled.', true) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Delete.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Delete.php index fb5594abb8..388b5edf7e 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Delete.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Delete.php @@ -5,9 +5,10 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases; use Appwrite\Event\Database as EventDatabase; use Appwrite\Event\Event; use Appwrite\Extend\Exception; -use Appwrite\Platform\Modules\Databases\SDKMethod; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; +use Appwrite\SDK\Deprecated; +use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Database; @@ -34,20 +35,40 @@ class Delete extends Action ->label('event', 'databases.[databaseId].delete') ->label('audits.event', 'database.delete') ->label('audits.resource', 'database/{request.databaseId}') - ->label('sdk', SDKMethod::withGridsAPI( - namespace: 'databases', - group: 'databases', - name: 'delete', - description: '/docs/references/databases/delete.md', - auth: [AuthType::KEY], - responses: [ - new SDKResponse( - code: SwooleResponse::STATUS_CODE_NOCONTENT, - model: UtopiaResponse::MODEL_NONE, + ->label('sdk', [ + new Method( + namespace: 'databases', + group: 'databases', + name: 'delete', + description: '/docs/references/databases/delete.md', + auth: [AuthType::KEY], + responses: [ + new SDKResponse( + code: SwooleResponse::STATUS_CODE_NOCONTENT, + model: UtopiaResponse::MODEL_NONE, + ) + ], + contentType: ContentType::NONE, + deprecated: new Deprecated( + since: '1.8.0', + replaceWith: 'grids.deleteDatabase', ) - ], - contentType: ContentType::NONE - )) + ), + new Method( + namespace: 'grids', + group: 'grids', + name: 'deleteDatabase', + description: '/docs/references/grids/delete-database.md', + auth: [AuthType::KEY], + responses: [ + new SDKResponse( + code: SwooleResponse::STATUS_CODE_NOCONTENT, + model: UtopiaResponse::MODEL_NONE, + ) + ], + contentType: ContentType::NONE + ), + ]) ->param('databaseId', '', new UID(), 'Database ID.') ->inject('response') ->inject('dbForProject') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Get.php index ff4a9af0a4..a3ac4d0da0 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Get.php @@ -3,9 +3,10 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases; use Appwrite\Extend\Exception; -use Appwrite\Platform\Modules\Databases\SDKMethod; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; +use Appwrite\SDK\Deprecated; +use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Database; @@ -29,20 +30,40 @@ class Get extends Action ->groups(['api', 'database']) ->label('scope', 'databases.read') ->label('resourceType', RESOURCE_TYPE_DATABASES) - ->label('sdk', SDKMethod::withGridsAPI( - namespace: 'databases', - group: 'databases', - name: 'get', - description: '/docs/references/databases/get.md', - auth: [AuthType::KEY], - responses: [ - new SDKResponse( - code: SwooleResponse::STATUS_CODE_OK, - model: UtopiaResponse::MODEL_DATABASE, + ->label('sdk', [ + new Method( + namespace: 'databases', + group: 'databases', + name: 'get', + description: '/docs/references/databases/get.md', + auth: [AuthType::KEY], + responses: [ + new SDKResponse( + code: SwooleResponse::STATUS_CODE_OK, + model: UtopiaResponse::MODEL_DATABASE, + ) + ], + contentType: ContentType::JSON, + deprecated: new Deprecated( + since: '1.8.0', + replaceWith: 'grids.getDatabase', ) - ], - contentType: ContentType::JSON - )) + ), + new Method( + namespace: 'grids', + group: 'grids', + name: 'getDatabase', + description: '/docs/references/grids/get-database.md', + auth: [AuthType::KEY], + responses: [ + new SDKResponse( + code: SwooleResponse::STATUS_CODE_OK, + model: UtopiaResponse::MODEL_DATABASE, + ) + ], + contentType: ContentType::JSON + ), + ]) ->param('databaseId', '', new UID(), 'Database ID.') ->inject('response') ->inject('dbForProject') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Logs/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Logs/XList.php index 6d3e30f52a..5828b9f8b8 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Logs/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Logs/XList.php @@ -3,9 +3,10 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Logs; use Appwrite\Extend\Exception; -use Appwrite\Platform\Modules\Databases\SDKMethod; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; +use Appwrite\SDK\Deprecated; +use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; use DeviceDetector\DeviceDetector as Detector; @@ -41,20 +42,40 @@ class XList extends Action ->groups(['api', 'database']) ->label('scope', 'databases.read') ->label('resourceType', RESOURCE_TYPE_DATABASES) - ->label('sdk', SDKMethod::withGridsAPI( - namespace: 'databases', - group: 'logs', - name: 'listLogs', - description: '/docs/references/databases/get-logs.md', - auth: [AuthType::ADMIN], - responses: [ - new SDKResponse( - code: SwooleResponse::STATUS_CODE_OK, - model: UtopiaResponse::MODEL_LOG_LIST, + ->label('sdk', [ + new Method( + namespace: 'databases', + group: 'logs', + name: 'listLogs', + description: '/docs/references/databases/get-logs.md', + auth: [AuthType::ADMIN], + responses: [ + new SDKResponse( + code: SwooleResponse::STATUS_CODE_OK, + model: UtopiaResponse::MODEL_LOG_LIST, + ) + ], + contentType: ContentType::JSON, + deprecated: new Deprecated( + since: '1.8.0', + replaceWith: 'grids.listDatabaseLogs', ) - ], - contentType: ContentType::JSON - )) + ), + new Method( + namespace: 'grids', + group: 'logs', + name: 'listDatabaseLogs', + description: '/docs/references/grids/list-database-logs.md', + auth: [AuthType::ADMIN], + responses: [ + new SDKResponse( + code: SwooleResponse::STATUS_CODE_OK, + model: UtopiaResponse::MODEL_LOG_LIST, + ) + ], + contentType: ContentType::JSON + ), + ]) ->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) ->inject('response') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Update.php index d164325469..b2b268075c 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Update.php @@ -4,9 +4,10 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases; use Appwrite\Event\Event; use Appwrite\Extend\Exception; -use Appwrite\Platform\Modules\Databases\SDKMethod; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; +use Appwrite\SDK\Deprecated; +use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Database; @@ -35,20 +36,40 @@ class Update extends Action ->label('event', 'databases.[databaseId].update') ->label('audits.event', 'database.update') ->label('audits.resource', 'database/{response.$id}') - ->label('sdk', SDKMethod::withGridsAPI( - namespace: 'databases', - group: 'databases', - name: 'update', - description: '/docs/references/databases/update.md', - auth: [AuthType::KEY], - responses: [ - new SDKResponse( - code: SwooleResponse::STATUS_CODE_OK, - model: UtopiaResponse::MODEL_DATABASE, + ->label('sdk', [ + new Method( + namespace: 'databases', + group: 'databases', + name: 'update', + description: '/docs/references/databases/update.md', + auth: [AuthType::KEY], + responses: [ + new SDKResponse( + code: SwooleResponse::STATUS_CODE_OK, + model: UtopiaResponse::MODEL_DATABASE, + ) + ], + contentType: ContentType::JSON, + deprecated: new Deprecated( + since: '1.8.0', + replaceWith: 'grids.updateDatabase', ) - ], - contentType: ContentType::JSON - )) + ), + new Method( + namespace: 'grids', + group: 'grids', + name: 'updateDatabase', + description: '/docs/references/grids/update-database.md', + auth: [AuthType::KEY], + responses: [ + new SDKResponse( + code: SwooleResponse::STATUS_CODE_OK, + model: UtopiaResponse::MODEL_DATABASE, + ) + ], + contentType: ContentType::JSON + ), + ]) ->param('databaseId', '', new UID(), 'Database ID.') ->param('name', null, new Text(128), 'Database name. Max length: 128 chars.') ->param('enabled', true, new Boolean(), 'Is database enabled? When set to \'disabled\', users cannot access the database but Server SDKs with an API key can still read and write to the database. No data is lost when this is toggled.', true) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Usage/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Usage/Get.php index fcdb4c615d..8efb6ae0ee 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Usage/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Usage/Get.php @@ -3,9 +3,10 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Usage; use Appwrite\Extend\Exception; -use Appwrite\Platform\Modules\Databases\SDKMethod; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; +use Appwrite\SDK\Deprecated; +use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Config\Config; @@ -34,20 +35,41 @@ class Get extends Action ->groups(['api', 'database', 'usage']) ->label('scope', 'collections.read') ->label('resourceType', RESOURCE_TYPE_DATABASES) - ->label('sdk', SDKMethod::withGridsAPI( - namespace: 'databases', - group: null, - name: self::getName(), - description: '/docs/references/databases/get-database-usage.md', - auth: [AuthType::ADMIN], - responses: [ - new SDKResponse( - code: SwooleResponse::STATUS_CODE_OK, - model: UtopiaResponse::MODEL_USAGE_DATABASE, + ->label('sdk', [ + new Method( + namespace: 'databases', + group: null, + name: self::getName(), + description: '/docs/references/databases/get-database-usage.md', + auth: [AuthType::ADMIN], + responses: [ + new SDKResponse( + code: SwooleResponse::STATUS_CODE_OK, + model: UtopiaResponse::MODEL_USAGE_DATABASE, + ) + ], + contentType: ContentType::JSON, + deprecated: new Deprecated( + since: '1.8.0', + replaceWith: 'grids.' . self::getName(), ) - ], - contentType: ContentType::JSON, - )) + ), + new Method( + namespace: 'grids', + group: null, + name: self::getName(), + description: '/docs/references/grids/get-database-usage.md', + auth: [AuthType::ADMIN], + responses: [ + new SDKResponse( + code: SwooleResponse::STATUS_CODE_OK, + model: UtopiaResponse::MODEL_USAGE_DATABASE, + ) + ], + contentType: ContentType::JSON, + ), + + ]) ->param('databaseId', '', new UID(), 'Database ID.') ->param('range', '30d', new WhiteList(['24h', '30d', '90d'], true), 'Date range.', true) ->inject('response') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Usage/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Usage/XList.php index b3ff8a6fac..31d520611e 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Usage/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Usage/XList.php @@ -2,9 +2,10 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Usage; -use Appwrite\Platform\Modules\Databases\SDKMethod; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; +use Appwrite\SDK\Deprecated; +use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Config\Config; @@ -32,20 +33,40 @@ class XList extends Action ->groups(['api', 'database', 'usage']) ->label('scope', 'collections.read') ->label('resourceType', RESOURCE_TYPE_DATABASES) - ->label('sdk', SDKMethod::withGridsAPI( - namespace: 'databases', - group: null, - name: self::getName(), - description: '/docs/references/databases/list-usage.md', - auth: [AuthType::ADMIN], - responses: [ - new SDKResponse( - code: SwooleResponse::STATUS_CODE_OK, - model: UtopiaResponse::MODEL_USAGE_DATABASES, + ->label('sdk', [ + new Method( + namespace: 'databases', + group: null, + name: self::getName(), + description: '/docs/references/databases/list-usage.md', + auth: [AuthType::ADMIN], + responses: [ + new SDKResponse( + code: SwooleResponse::STATUS_CODE_OK, + model: UtopiaResponse::MODEL_USAGE_DATABASES, + ) + ], + contentType: ContentType::JSON, + deprecated: new Deprecated( + since: '1.8.0', + replaceWith: 'grids.listDatabaseUsage' ) - ], - contentType: ContentType::JSON - )) + ), + new Method( + namespace: 'grids', + group: null, + name: 'listDatabaseUsage', + description: '/docs/references/grids/list-database-usage.md', + auth: [AuthType::ADMIN], + responses: [ + new SDKResponse( + code: SwooleResponse::STATUS_CODE_OK, + model: UtopiaResponse::MODEL_USAGE_DATABASES, + ) + ], + contentType: ContentType::JSON + ), + ]) ->param('range', '30d', new WhiteList(['24h', '30d', '90d'], true), 'Date range.', true) ->inject('response') ->inject('dbForProject') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/XList.php index 1806cdc3fb..fdf3428101 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/XList.php @@ -3,9 +3,10 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases; use Appwrite\Extend\Exception; -use Appwrite\Platform\Modules\Databases\SDKMethod; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; +use Appwrite\SDK\Deprecated; +use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Database\Validator\Queries\Databases; use Appwrite\Utopia\Response as UtopiaResponse; @@ -35,20 +36,40 @@ class XList extends Action ->groups(['api', 'database']) ->label('scope', 'databases.read') ->label('resourceType', RESOURCE_TYPE_DATABASES) - ->label('sdk', SDKMethod::withGridsAPI( - namespace: 'databases', - group: 'databases', - name: 'list', - description: '/docs/references/databases/list.md', - auth: [AuthType::KEY], - responses: [ - new SDKResponse( - code: SwooleResponse::STATUS_CODE_OK, - model: UtopiaResponse::MODEL_DATABASE_LIST, + ->label('sdk', [ + new Method( + namespace: 'databases', + group: 'databases', + name: 'list', + description: '/docs/references/databases/list.md', + auth: [AuthType::KEY], + responses: [ + new SDKResponse( + code: SwooleResponse::STATUS_CODE_OK, + model: UtopiaResponse::MODEL_DATABASE_LIST, + ) + ], + contentType: ContentType::JSON, + deprecated: new Deprecated( + since: '1.8.0', + replaceWith: 'grids.listDatabases', ) - ], - contentType: ContentType::JSON - )) + ), + new Method( + namespace: 'grids', + group: 'grids', + name: 'listDatabases', + description: '/docs/references/grids/list-databases.md', + auth: [AuthType::KEY], + responses: [ + new SDKResponse( + code: SwooleResponse::STATUS_CODE_OK, + model: UtopiaResponse::MODEL_DATABASE_LIST, + ) + ], + contentType: ContentType::JSON + ), + ]) ->param('queries', [], new Databases(), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' queries are allowed, each ' . APP_LIMIT_ARRAY_ELEMENT_SIZE . ' characters long. You may filter on the following attributes: ' . implode(', ', Databases::ALLOWED_ATTRIBUTES), true) ->param('search', '', new Text(256), 'Search term to filter your list results. Max length: 256 chars.', true) ->inject('response') diff --git a/src/Appwrite/Platform/Modules/Databases/SDKMethod.php b/src/Appwrite/Platform/Modules/Databases/SDKMethod.php deleted file mode 100644 index e3f12776c2..0000000000 --- a/src/Appwrite/Platform/Modules/Databases/SDKMethod.php +++ /dev/null @@ -1,72 +0,0 @@ - ['name' => 'createDatabase', 'docs' => 'create-database'], - 'list' => ['name' => 'listDatabases', 'docs' => 'list-databases'], - 'get' => ['name' => 'getDatabase', 'docs' => 'get-database'], - 'update' => ['name' => 'updateDatabase', 'docs' => 'update-database'], - 'delete' => ['name' => 'deleteDatabase', 'docs' => 'delete-database'], - 'listLogs' => ['name' => 'listDatabaseLogs', 'docs' => 'list-database-logs'], - 'listUsage' => ['name' => 'listDatabaseUsage', 'docs' => 'list-database-usage'], - 'getDatabaseUsage' => ['name' => 'getDatabaseUsage', 'docs' => 'get-database-usage'], - ]; - - /** - * @return Method[] - */ - public static function withGridsAPI( - string $namespace, - ?string $group, - string $name, - string $description, - array $auth, - array $responses, - ContentType $contentType, - ): array { - return [ - new Method( - namespace: $namespace, - group: $group, - name: $name, - description: $description, - auth: $auth, - responses: $responses, - contentType: $contentType, - ), - new Method( - namespace: 'grids', - group: $group === null ? null : 'grids', - name: self::transformNameForGrids($name), - description: self::transformDocsPathForGrids($description), - auth: $auth, - responses: $responses, - contentType: $contentType, - ) - ]; - } - - private static function transformNameForGrids(string $original): string - { - return self::SDK_INFO_MAP[$original]['name'] ?? $original; - } - - private static function transformDocsPathForGrids(string $original): string - { - $path = str_replace('/databases/', '/grids/', $original); - - foreach (self::SDK_INFO_MAP as $from => $mapped) { - if (str_ends_with($path, "/$from.md")) { - return substr($path, 0, -strlen("$from.md")) . $mapped['docs'] . '.md'; - } - } - - return $path; - } -}