Merge remote-tracking branch 'origin/restore-storage-folder-api' into restore-storage-folder-api

This commit is contained in:
Torsten Dittmann committed 2026-07-27 15:35:29 +04:00
commit d8c2dc0bef
22 files changed
+580 -43

No files matched your search

+42
View File
@@ -197,6 +197,48 @@ return [
'icon' => '',
'platforms' => ['client', 'server', 'console'],
],
'webhooks' => [
'key' => 'webhooks',
'name' => 'Webhooks',
'subtitle' => 'The Webhooks service allows you to manage your project webhooks.',
'description' => '',
'controller' => '', // Uses modules
'sdk' => true,
'docs' => true,
'docsUrl' => '',
'tests' => false,
'optional' => false,
'icon' => '',
'platforms' => ['server', 'console'],
],
'tokens' => [
'key' => 'tokens',
'name' => 'Tokens',
'subtitle' => 'The Tokens service allows you to create and manage resource tokens for secure file access.',
'description' => '',
'controller' => '', // Uses modules
'sdk' => true,
'docs' => true,
'docsUrl' => '',
'tests' => false,
'optional' => false,
'icon' => '',
'platforms' => ['server', 'console'],
],
'presences' => [
'key' => 'presences',
'name' => 'Presences',
'subtitle' => 'The Presences service allows you to track and manage real-time user presence in your project.',
'description' => '',
'controller' => '', // Uses modules
'sdk' => true,
'docs' => true,
'docsUrl' => '',
'tests' => false,
'optional' => false,
'icon' => '',
'platforms' => ['client', 'server', 'console'],
],
'sites' => [
'key' => 'sites',
'name' => 'Sites',
+3
View File
@@ -225,6 +225,7 @@ use Appwrite\Utopia\Response\Model\UsageVectorsDBs;
use Appwrite\Utopia\Response\Model\User;
use Appwrite\Utopia\Response\Model\Variable;
use Appwrite\Utopia\Response\Model\VcsContent;
use Appwrite\Utopia\Response\Model\VcsNamespace;
use Appwrite\Utopia\Response\Model\VectorsDBCollection;
use Appwrite\Utopia\Response\Model\Webhook;
@@ -261,6 +262,8 @@ Response::setModel(new BaseList('Function Templates List', Response::MODEL_TEMPL
Response::setModel(new BaseList('Installations List', Response::MODEL_INSTALLATION_LIST, 'installations', Response::MODEL_INSTALLATION));
Response::setModel(new ProviderRepositoryFrameworkList());
Response::setModel(new ProviderRepositoryRuntimeList());
Response::setModel(new VcsNamespace());
Response::setModel(new BaseList('VCS Namespaces List', Response::MODEL_VCS_NAMESPACE_LIST, 'namespaces', Response::MODEL_VCS_NAMESPACE));
Response::setModel(new BaseList('Branches List', Response::MODEL_BRANCH_LIST, 'branches', Response::MODEL_BRANCH));
Response::setModel(new BaseList('Frameworks List', Response::MODEL_FRAMEWORK_LIST, 'frameworks', Response::MODEL_FRAMEWORK));
Response::setModel(new BaseList('Runtimes List', Response::MODEL_RUNTIME_LIST, 'runtimes', Response::MODEL_RUNTIME));
+6 -2
View File
@@ -41,6 +41,10 @@
{
"type": "vcs",
"url": "https://github.com/utopia-php/auth"
},
{
"type": "vcs",
"url": "https://github.com/utopia-php/vcs"
}
],
"require": {
@@ -91,12 +95,12 @@
"utopia-php/queue": "^0.22",
"utopia-php/servers": "0.4.*",
"utopia-php/registry": "0.5.*",
"utopia-php/storage": "3.*",
"utopia-php/storage": "^3.1",
"utopia-php/system": "0.10.*",
"utopia-php/telemetry": "^0.4",
"utopia-php/user-agent": "0.1.*",
"mustangostang/spyc": "0.6.*",
"utopia-php/vcs": "^4.4.2",
"utopia-php/vcs": "4.*.*",
"utopia-php/websocket": "1.0.*",
"dragonmantank/cron-expression": "3.4.*",
"phpmailer/phpmailer": "6.9.*",
Generated
+39 -21
View File
@@ -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": "7a2821539fc6e6063587e38e3eca19c4",
"content-hash": "a811ab43bece6d9d01be1caab8a08a75",
"packages": [
{
"name": "adhocore/jwt",
@@ -3212,16 +3212,16 @@
},
{
"name": "utopia-php/auth",
"version": "0.10.0",
"version": "0.10.1",
"source": {
"type": "git",
"url": "https://github.com/utopia-php/auth.git",
"reference": "fc6e7861a0428415a7454ba808a511cc01bf8db4"
"reference": "0f1a342bceebc2659736e52a4496daf24ca4954c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/utopia-php/auth/zipball/fc6e7861a0428415a7454ba808a511cc01bf8db4",
"reference": "fc6e7861a0428415a7454ba808a511cc01bf8db4",
"url": "https://api.github.com/repos/utopia-php/auth/zipball/0f1a342bceebc2659736e52a4496daf24ca4954c",
"reference": "0f1a342bceebc2659736e52a4496daf24ca4954c",
"shasum": ""
},
"require": {
@@ -3264,10 +3264,10 @@
"security"
],
"support": {
"source": "https://github.com/utopia-php/auth/tree/0.10.0",
"source": "https://github.com/utopia-php/auth/tree/0.10.1",
"issues": "https://github.com/utopia-php/auth/issues"
},
"time": "2026-07-15T15:52:58+00:00"
"time": "2026-07-23T07:34:27+00:00"
},
{
"name": "utopia-php/cache",
@@ -4931,16 +4931,16 @@
},
{
"name": "utopia-php/storage",
"version": "3.0.0",
"version": "3.1.0",
"source": {
"type": "git",
"url": "https://github.com/utopia-php/storage.git",
"reference": "171746978543323c2536edacd8ad8e8d3fde401c"
"reference": "38bfc0c14a16a7de2a86b3331865dad1230ed739"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/utopia-php/storage/zipball/171746978543323c2536edacd8ad8e8d3fde401c",
"reference": "171746978543323c2536edacd8ad8e8d3fde401c",
"url": "https://api.github.com/repos/utopia-php/storage/zipball/38bfc0c14a16a7de2a86b3331865dad1230ed739",
"reference": "38bfc0c14a16a7de2a86b3331865dad1230ed739",
"shasum": ""
},
"require": {
@@ -4975,9 +4975,9 @@
],
"support": {
"issues": "https://github.com/utopia-php/storage/issues",
"source": "https://github.com/utopia-php/storage/tree/3.0.0"
"source": "https://github.com/utopia-php/storage/tree/3.1.0"
},
"time": "2026-07-20T13:15:54+00:00"
"time": "2026-07-22T15:57:57+00:00"
},
{
"name": "utopia-php/system",
@@ -5165,16 +5165,16 @@
},
{
"name": "utopia-php/vcs",
"version": "4.4.4",
"version": "4.4.5",
"source": {
"type": "git",
"url": "https://github.com/utopia-php/vcs.git",
"reference": "37580b1a459c6b51f567b1720c118a8a0213f314"
"reference": "4abcc51d113697fb45ad7fab83851bc4162c6bd4"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/utopia-php/vcs/zipball/37580b1a459c6b51f567b1720c118a8a0213f314",
"reference": "37580b1a459c6b51f567b1720c118a8a0213f314",
"url": "https://api.github.com/repos/utopia-php/vcs/zipball/4abcc51d113697fb45ad7fab83851bc4162c6bd4",
"reference": "4abcc51d113697fb45ad7fab83851bc4162c6bd4",
"shasum": ""
},
"require": {
@@ -5195,7 +5195,25 @@
"Utopia\\VCS\\": "src/VCS"
}
},
"notification-url": "https://packagist.org/downloads/",
"autoload-dev": {
"psr-4": {
"Utopia\\Tests\\": "tests/VCS"
}
},
"scripts": {
"lint": [
"./vendor/bin/pint --test --config pint.json"
],
"format": [
"./vendor/bin/pint --config pint.json"
],
"check": [
"./vendor/bin/phpstan analyse --level 8 --memory-limit 512M -c phpstan.neon src tests"
],
"test": [
"./vendor/bin/phpunit --configuration phpunit.xml --debug"
]
},
"license": [
"MIT"
],
@@ -5207,10 +5225,10 @@
"vcs"
],
"support": {
"issues": "https://github.com/utopia-php/vcs/issues",
"source": "https://github.com/utopia-php/vcs/tree/4.4.4"
"source": "https://github.com/utopia-php/vcs/tree/4.4.5",
"issues": "https://github.com/utopia-php/vcs/issues"
},
"time": "2026-07-22T10:18:04+00:00"
"time": "2026-07-23T13:01:07+00:00"
},
{
"name": "utopia-php/websocket",
+2 -2
View File
@@ -1239,7 +1239,7 @@ services:
options:
max-file: "5"
max-size: 10m
image: ghcr.io/open-runtimes/orchestrator/jobs-service:0.8.0
image: ghcr.io/open-runtimes/orchestrator/jobs-service:0.13.0
restart: unless-stopped
user: root
networks:
@@ -1250,7 +1250,7 @@ services:
- ORCHESTRATOR_BACKEND=docker
- ORCHESTRATOR_NETWORK=appwrite
- ARTIFACT_ENDPOINT=http://orchestrator-jobs:8080
- JOB_SIDECAR_IMAGE=ghcr.io/open-runtimes/orchestrator/job-sidecar:0.8.0
- JOB_SIDECAR_IMAGE=ghcr.io/open-runtimes/orchestrator/job-sidecar:0.13.0
mariadb:
image: mariadb:10.11
@@ -0,0 +1 @@
Get a list of all the user's documents in a given collection using a POST request. This behaves identically to the list documents endpoint but accepts the queries in the request body, allowing much larger `queries` arrays than can fit in a URL query string.
+1 -1
View File
@@ -137,7 +137,7 @@ class Gitea extends OAuth2
return $this->user;
}
public function createRepository(string $accessToken, string $repositoryName, bool $private): array
public function createRepository(string $accessToken, string $repositoryName, bool $private, string $namespaceId = ''): array
{
$repository = $this->request('POST', $this->endpoint . '/api/v1/user/repos', ['Authorization: token ' . $accessToken, 'Content-Type: application/json'], \json_encode([
'name' => $repositoryName,
+1 -1
View File
@@ -235,7 +235,7 @@ class Github extends OAuth2
return $this->user;
}
public function createRepository(string $accessToken, string $repositoryName, bool $private): array
public function createRepository(string $accessToken, string $repositoryName, bool $private, string $namespaceId = ''): array
{
$repository = $this->request('POST', 'https://api.github.com/user/repos', ['Authorization: token ' . \urlencode($accessToken)], \json_encode([
'name' => $repositoryName,
+9 -3
View File
@@ -183,12 +183,18 @@ class Gitlab extends OAuth2
*
* @return array
*/
public function createRepository(string $accessToken, string $repositoryName, bool $private): array
public function createRepository(string $accessToken, string $repositoryName, bool $private, string $namespaceId = ''): array
{
$repository = $this->request('POST', $this->getEndpoint() . '/api/v4/projects', ['Authorization: Bearer ' . $accessToken, 'Content-Type: application/json'], \json_encode([
$payload = [
'name' => $repositoryName,
'visibility' => $private ? 'private' : 'public',
]));
];
if (!empty($namespaceId)) {
$payload['namespace_id'] = (int) $namespaceId;
}
$repository = $this->request('POST', $this->getEndpoint() . '/api/v4/projects', ['Authorization: Bearer ' . $accessToken, 'Content-Type: application/json'], \json_encode($payload));
$repository = \json_decode($repository, true) ?? [];
@@ -0,0 +1,63 @@
<?php
namespace Appwrite\Platform\Modules\Databases\Http\VectorsDB\Collections\Documents\Queries;
use Appwrite\Platform\Modules\Databases\Http\VectorsDB\Collections\Documents\XList;
use Appwrite\SDK\AuthType;
use Appwrite\SDK\ContentType;
use Appwrite\SDK\Method;
use Appwrite\SDK\Response as SDKResponse;
use Utopia\Database\Validator\UID;
use Utopia\Http\Adapter\Swoole\Response as SwooleResponse;
use Utopia\Validator\ArrayList;
use Utopia\Validator\Boolean;
use Utopia\Validator\Range;
use Utopia\Validator\Text;
class Create extends XList
{
public static function getName(): string
{
return 'createVectorsDBDocumentsQuery';
}
public function __construct()
{
$this
->setHttpMethod(self::HTTP_REQUEST_METHOD_POST)
->setHttpPath('/v1/vectorsdb/:databaseId/collections/:collectionId/documents/query')
->desc('Create query')
->groups(['api', 'database'])
->label('scope', 'documents.read')
->label('usage.resource', 'database/{request.databaseId}/collection/{request.collectionId}')
->label('resourceType', RESOURCE_TYPE_DATABASES)
->label('sdk', new Method(
namespace: 'vectorsDB',
group: $this->getSdkGroup(),
name: 'createQuery',
description: '/docs/references/vectorsdb/create-query.md',
auth: [AuthType::ADMIN, AuthType::SESSION, AuthType::KEY, AuthType::JWT],
responses: [
new SDKResponse(
code: SwooleResponse::STATUS_CODE_OK,
model: $this->getResponseModel(),
)
],
contentType: ContentType::JSON
))
->param('databaseId', '', new UID(), 'Database ID.')
->param('collectionId', '', new UID(), 'Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).')
->param('queries', [], new ArrayList(new Text(APP_LIMIT_ARRAY_ELEMENT_SIZE), APP_LIMIT_ARRAY_PARAMS_SIZE), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' queries are allowed, each ' . APP_LIMIT_ARRAY_ELEMENT_SIZE . ' characters long.', true)
->param('transactionId', null, new UID(), 'Transaction ID to read uncommitted changes within the transaction.', true)
->param('total', true, new Boolean(true), 'When set to false, the total count returned will be 0 and will not be calculated.', true)
->param('ttl', 0, new Range(min: 0, max: 86400), 'TTL (seconds) for cached responses when caching is enabled for select queries. Must be between 0 and 86400 (24 hours).', true)
->inject('response')
->inject('dbForProject')
->inject('user')
->inject('getDatabasesDB')
->inject('usage')
->inject('transactionState')
->inject('authorization')
->callback($this->action(...));
}
}
@@ -10,6 +10,7 @@ use Appwrite\Platform\Modules\Databases\Http\VectorsDB\Collections\Documents\Bul
use Appwrite\Platform\Modules\Databases\Http\VectorsDB\Collections\Documents\Create as CreateDocument;
use Appwrite\Platform\Modules\Databases\Http\VectorsDB\Collections\Documents\Delete as DeleteDocument;
use Appwrite\Platform\Modules\Databases\Http\VectorsDB\Collections\Documents\Get as GetDocument;
use Appwrite\Platform\Modules\Databases\Http\VectorsDB\Collections\Documents\Queries\Create as CreateDocumentsQuery;
use Appwrite\Platform\Modules\Databases\Http\VectorsDB\Collections\Documents\Update as UpdateDocument;
use Appwrite\Platform\Modules\Databases\Http\VectorsDB\Collections\Documents\Upsert as UpsertDocument;
use Appwrite\Platform\Modules\Databases\Http\VectorsDB\Collections\Documents\XList as ListDocuments;
@@ -79,6 +80,7 @@ class VectorsDB extends Base
$service->addAction(UpsertDocument::getName(), new UpsertDocument());
$service->addAction(GetDocument::getName(), new GetDocument());
$service->addAction(ListDocuments::getName(), new ListDocuments());
$service->addAction(CreateDocumentsQuery::getName(), new CreateDocumentsQuery());
$service->addAction(DeleteDocument::getName(), new DeleteDocument());
$service->addAction(UpdateDocuments::getName(), new UpdateDocuments());
$service->addAction(UpsertDocuments::getName(), new UpsertDocuments());
@@ -93,7 +93,7 @@ class Databases extends Action
match (\strval($type)) {
DATABASE_TYPE_DELETE_DATABASE => $this->deleteDatabase($database, $dbForProject, $dbForDatabases),
DATABASE_TYPE_DELETE_COLLECTION => $this->deleteCollection($database, $collection, $dbForProject, $dbForDatabases),
DATABASE_TYPE_CREATE_ATTRIBUTE => $this->createAttribute($database, $collection, $document, $project, $dbForPlatform, $dbForProject, $queueForRealtime),
DATABASE_TYPE_CREATE_ATTRIBUTE => $this->createAttribute($database, $collection, $document, $project, $dbForPlatform, $dbForProject, $dbForDatabases, $queueForRealtime),
DATABASE_TYPE_DELETE_ATTRIBUTE => $this->deleteAttribute($database, $collection, $document, $project, $dbForPlatform, $dbForProject, $dbForDatabases, $queueForRealtime),
DATABASE_TYPE_CREATE_INDEX => $this->createIndex($database, $collection, $document, $project, $dbForPlatform, $dbForProject, $dbForDatabases, $queueForRealtime),
DATABASE_TYPE_DELETE_INDEX => $this->deleteIndex($database, $collection, $document, $project, $dbForPlatform, $dbForProject, $dbForDatabases, $queueForRealtime),
@@ -108,6 +108,7 @@ class Databases extends Action
* @param Document $project
* @param Database $dbForPlatform
* @param Database $dbForProject
* @param Database $dbForDatabases
* @param Realtime $queueForRealtime
* @return void
* @throws Authorization
@@ -122,6 +123,7 @@ class Databases extends Action
Document $project,
Database $dbForPlatform,
Database $dbForProject,
Database $dbForDatabases,
Realtime $queueForRealtime
): void {
if ($collection->isEmpty()) {
@@ -183,7 +185,7 @@ class Databases extends Action
}
if (
!$dbForProject->createRelationship(
!$dbForDatabases->createRelationship(
collection: 'database_' . $database->getSequence() . '_collection_' . $collection->getSequence(),
relatedCollection: 'database_' . $database->getSequence() . '_collection_' . $relatedCollection->getSequence(),
type: $options['relationType'],
@@ -202,7 +204,7 @@ class Databases extends Action
}
break;
default:
if (!$dbForProject->createAttribute('database_' . $database->getSequence() . '_collection_' . $collection->getSequence(), $key, $type, $size, $required, $default, $signed, $array, $format, $formatOptions, $filters)) {
if (!$dbForDatabases->createAttribute('database_' . $database->getSequence() . '_collection_' . $collection->getSequence(), $key, $type, $size, $required, $default, $signed, $array, $format, $formatOptions, $filters)) {
throw new Exception('Failed to create attribute/column');
}
}
@@ -0,0 +1,130 @@
<?php
namespace Appwrite\Platform\Modules\VCS\Http\Installations\Namespaces;
use Appwrite\Extend\Exception;
use Appwrite\Platform\Action;
use Appwrite\SDK\AuthType;
use Appwrite\SDK\Method;
use Appwrite\SDK\Response as SDKResponse;
use Appwrite\Utopia\Response;
use Appwrite\Vcs\Factory as VcsFactory;
use Appwrite\Vcs\InstallationTokens;
use Utopia\Database\Database;
use Utopia\Database\Document;
use Utopia\Database\Query;
use Utopia\Database\Validator\Queries;
use Utopia\Database\Validator\Query\Limit;
use Utopia\Database\Validator\Query\Offset;
use Utopia\Platform\Scope\HTTP;
use Utopia\Validator\Text;
class XList extends Action
{
use HTTP;
public static function getName()
{
return 'listNamespaces';
}
public function __construct()
{
$this
->setHttpMethod(Action::HTTP_REQUEST_METHOD_GET)
->setHttpPath('/v1/vcs/installations/:installationId/namespaces')
->desc('List namespaces')
->groups(['api', 'vcs'])
->label('scope', 'vcs.read')
->label('resourceType', RESOURCE_TYPE_VCS)
->label('sdk', new Method(
namespace: 'vcs',
group: 'namespaces',
name: 'listNamespaces',
description: 'List provider namespaces available to a VCS installation. This can include the user personal namespace and any groups or organizations the installation can browse.',
auth: [AuthType::ADMIN],
responses: [
new SDKResponse(
code: Response::STATUS_CODE_OK,
model: Response::MODEL_VCS_NAMESPACE_LIST,
)
]
))
->param('installationId', '', new Text(256), 'Installation Id')
->param('search', '', new Text(256), 'Search term to filter your list results. Max length: 256 chars.', true)
->param('queries', [], new Queries([new Limit(), new Offset()]), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Only supported methods are limit and offset', true)
->inject('vcsFactory')
->inject('installationTokens')
->inject('response')
->inject('project')
->inject('dbForPlatform')
->callback($this->action(...));
}
public function action(
string $installationId,
string $search,
array $queries,
VcsFactory $vcsFactory,
InstallationTokens $installationTokens,
Response $response,
Document $project,
Database $dbForPlatform
) {
$installation = $dbForPlatform->getDocument('installations', $installationId);
if ($installation->isEmpty()) {
throw new Exception(Exception::INSTALLATION_NOT_FOUND);
}
if ($installation->getAttribute('projectInternalId') !== $project->getSequence()) {
throw new Exception(Exception::INSTALLATION_NOT_FOUND);
}
$installation = $installationTokens->refreshForInstallation($installation, $dbForPlatform, $vcsFactory);
$vcs = $vcsFactory->fromInstallation($installation);
$queries = Query::parseQueries($queries);
$limitQuery = current(array_filter($queries, fn ($query) => $query->getMethod() === Query::TYPE_LIMIT));
$offsetQuery = current(array_filter($queries, fn ($query) => $query->getMethod() === Query::TYPE_OFFSET));
$limit = !empty($limitQuery) ? $limitQuery->getValue() : 20;
$offset = !empty($offsetQuery) ? $offsetQuery->getValue() : 0;
if ($offset % $limit !== 0) {
throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, 'offset must be a multiple of the limit');
}
$page = ($offset / $limit) + 1;
if (\method_exists($vcs, 'listNamespaces')) {
['items' => $namespaces, 'total' => $total] = $vcs->listNamespaces($page, $limit, $search);
$namespaces = \array_map(fn ($namespace) => [
'$id' => $namespace['id'] ?? '',
'name' => $namespace['name'] ?? '',
'path' => $namespace['path'] ?? '',
'type' => ($namespace['kind'] ?? '') === 'user' ? 'user' : 'organization',
'avatarUrl' => $namespace['avatarUrl'] ?? '',
], $namespaces);
} else {
$providerInstallationId = $installation->getAttribute('providerInstallationId', '');
$owner = $vcs->getOwnerName($providerInstallationId);
$matches = empty($search) || \stripos($owner, $search) !== false;
$namespaces = $matches ? [[
'$id' => $providerInstallationId,
'name' => $owner,
'path' => $owner,
'type' => $installation->getAttribute('personal', false) ? 'user' : 'organization',
'avatarUrl' => '',
]] : [];
$total = \count($namespaces);
}
$namespaces = \array_map(fn ($namespace) => new Document($namespace), $namespaces);
$response->dynamic(new Document([
'namespaces' => $namespaces,
'total' => $total,
]), Response::MODEL_VCS_NAMESPACE_LIST);
}
}
@@ -51,6 +51,7 @@ class Create extends Action
->param('installationId', '', new Text(256), 'Installation Id')
->param('name', '', new Text(256), 'Repository name (slug)')
->param('private', '', new Boolean(false), 'Mark repository public or private')
->param('providerNamespace', '', new Text(256), 'Namespace of the git repository. Defaults to the installation\'s own namespace.', true)
->inject('vcsFactory')
->inject('installationTokens')
->inject('user')
@@ -63,6 +64,7 @@ class Create extends Action
string $installationId,
string $name,
bool $private,
string $providerNamespace,
VcsFactory $vcsFactory,
InstallationTokens $installationTokens,
Document $user,
@@ -99,14 +101,18 @@ class Create extends Action
$accessToken = $installation->getAttribute('personalAccessToken');
try {
$repository = $oauth2->createRepository($accessToken, $name, $private);
if (!empty($providerNamespace)) {
$repository = $oauth2->createRepository($accessToken, $name, $private, $providerNamespace);
} else {
$repository = $oauth2->createRepository($accessToken, $name, $private);
}
} catch (\Throwable $exception) {
throw new Exception(Exception::GENERAL_PROVIDER_FAILURE, "VCS provider failed to process the request: " . $exception->getMessage());
}
} else {
$providerInstallationId = $installation->getAttribute('providerInstallationId');
$vcs = $vcsFactory->fromInstallation($installation);
$owner = $vcs->getOwnerName($providerInstallationId);
$owner = !empty($providerNamespace) ? $providerNamespace : $vcs->getOwnerName($providerInstallationId);
try {
$repository = $vcs->createRepository($owner, $name, $private);
@@ -7,6 +7,7 @@ use Appwrite\Platform\Action;
use Appwrite\SDK\AuthType;
use Appwrite\SDK\Method;
use Appwrite\SDK\Response as SDKResponse;
use Appwrite\Utopia\Database\Validator\Queries\VcsRepositories;
use Appwrite\Utopia\Response;
use Appwrite\Vcs\Factory as VcsFactory;
use Appwrite\Vcs\InstallationTokens;
@@ -17,9 +18,6 @@ use Utopia\Config\Exceptions\Parse;
use Utopia\Database\Database;
use Utopia\Database\Document;
use Utopia\Database\Query;
use Utopia\Database\Validator\Queries;
use Utopia\Database\Validator\Query\Limit;
use Utopia\Database\Validator\Query\Offset;
use Utopia\Detector\Detection\Framework\Analog;
use Utopia\Detector\Detection\Framework\Angular;
use Utopia\Detector\Detection\Framework\Astro;
@@ -97,7 +95,7 @@ class XList extends Action
->param('installationId', '', new Text(256), 'Installation Id')
->param('type', '', new WhiteList(['runtime', 'framework']), 'Detector type. Must be one of the following: runtime, framework', enum: new Enum(name: 'VCSDetectionType'))
->param('search', '', new Text(256), 'Search term to filter your list results. Max length: 256 chars.', true)
->param('queries', [], new Queries([new Limit(), new Offset()]), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Only supported methods are limit and offset', true)
->param('queries', [], new VcsRepositories(), '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, offset, and equal on namespace.', true)
->inject('vcsFactory')
->inject('installationTokens')
->inject('response')
@@ -132,17 +130,20 @@ class XList extends Action
$queries = Query::parseQueries($queries);
$limitQuery = current(array_filter($queries, fn ($query) => $query->getMethod() === Query::TYPE_LIMIT));
$offsetQuery = current(array_filter($queries, fn ($query) => $query->getMethod() === Query::TYPE_OFFSET));
$namespaceQueries = array_filter($queries, fn ($query) => $query->getMethod() === Query::TYPE_EQUAL && $query->getAttribute() === 'namespace');
$limit = !empty($limitQuery) ? $limitQuery->getValue() : 4;
$offset = !empty($offsetQuery) ? $offsetQuery->getValue() : 0;
$namespaceQuery = current($namespaceQueries);
$providerNamespace = !empty($namespaceQuery) ? $namespaceQuery->getValue('') : '';
if ($offset % $limit !== 0) {
throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, 'offset must be a multiple of the limit');
}
$page = ($offset / $limit) + 1;
$owner = $vcs->getOwnerName($providerInstallationId);
['items' => $repos, 'total' => $total] = $vcs->searchRepositories($owner, $page, $limit, $search);
$namespace = !empty($providerNamespace) ? $providerNamespace : $vcs->getOwnerName($providerInstallationId);
['items' => $repos, 'total' => $total] = $vcs->searchRepositories($namespace, $page, $limit, $search);
$repos = \array_map(function ($repo) use ($installation) {
$repo['id'] = \strval($repo['id'] ?? '');
@@ -14,6 +14,7 @@ use Appwrite\Platform\Modules\VCS\Http\Gitlab\Callback\Get as GetGitlabCallback;
use Appwrite\Platform\Modules\VCS\Http\Gitlab\Events\Create as CreateGitlabEvent;
use Appwrite\Platform\Modules\VCS\Http\Installations\Delete as DeleteInstallation;
use Appwrite\Platform\Modules\VCS\Http\Installations\Get as GetInstallation;
use Appwrite\Platform\Modules\VCS\Http\Installations\Namespaces\XList as ListNamespaces;
use Appwrite\Platform\Modules\VCS\Http\Installations\Repositories\Branches\XList as ListRepositoryBranches;
use Appwrite\Platform\Modules\VCS\Http\Installations\Repositories\Contents\Get as GetRepositoryContents;
use Appwrite\Platform\Modules\VCS\Http\Installations\Repositories\Create as CreateRepository;
@@ -46,6 +47,7 @@ class Http extends Service
$this->addAction(GetInstallation::getName(), new GetInstallation());
$this->addAction(ListInstallations::getName(), new ListInstallations());
$this->addAction(DeleteInstallation::getName(), new DeleteInstallation());
$this->addAction(ListNamespaces::getName(), new ListNamespaces());
// Repositories
$this->addAction(CreateRepository::getName(), new CreateRepository());
+37 -2
View File
@@ -615,6 +615,7 @@ class Specs extends Action
$routes = [];
$models = [];
$services = [];
$routeNamespaces = [];
foreach ($appRoutes as $key => $method) {
foreach ($method as $route) {
@@ -660,11 +661,27 @@ class Specs extends Action
}
$routes[] = $route;
$routeNamespaces[$sdk->getNamespace()] = true;
}
}
}
/**
* Tag names must match Method namespaces (path tags), e.g. tablesDB.
* Service config keys stay lowercase (tablesdb); descriptions resolve
* case-insensitively from services.php.
*/
$serviceDescriptions = [];
$configuredServices = [];
foreach (Config::getParam('services', []) as $service) {
$serviceKey = $service['key'] ?? '';
if ($serviceKey === '') {
continue;
}
$serviceDescriptions[\strtolower($serviceKey)] = $service['subtitle'] ?? '';
if (
!isset($service['docs']) // Skip service if not part of the public API
|| !isset($service['sdk'])
@@ -679,9 +696,27 @@ class Specs extends Action
continue;
}
$configuredServices[$serviceKey] = $service['subtitle'] ?? '';
}
$seenServices = [];
foreach (\array_keys($routeNamespaces) as $namespace) {
$services[] = [
'name' => $service['key'] ?? '',
'description' => $service['subtitle'] ?? '',
'name' => $namespace,
'description' => $serviceDescriptions[\strtolower($namespace)] ?? '',
];
$seenServices[\strtolower($namespace)] = true;
}
foreach ($configuredServices as $serviceKey => $description) {
if (isset($seenServices[\strtolower($serviceKey)])) {
continue;
}
$services[] = [
'name' => $serviceKey,
'description' => $description,
];
}
@@ -0,0 +1,20 @@
<?php
namespace Appwrite\Utopia\Database\Validator\Queries;
use Appwrite\Utopia\Database\Validator\Query\VcsNamespace;
use Utopia\Database\Validator\Queries;
use Utopia\Database\Validator\Query\Limit;
use Utopia\Database\Validator\Query\Offset;
class VcsRepositories extends Queries
{
public function __construct()
{
parent::__construct([
new Limit(),
new Offset(),
new VcsNamespace(),
]);
}
}
@@ -0,0 +1,45 @@
<?php
namespace Appwrite\Utopia\Database\Validator\Query;
use Utopia\Database\Query;
use Utopia\Database\Validator\Query\Base;
use Utopia\Validator\Text;
class VcsNamespace extends Base
{
public function getMethodType(): string
{
return self::METHOD_TYPE_FILTER;
}
public function isValid($value): bool
{
if (!$value instanceof Query) {
$this->message = 'Query must be an instance of Query';
return false;
}
if ($value->getMethod() !== Query::TYPE_EQUAL) {
$this->message = 'Only equal queries are supported for namespace';
return false;
}
if ($value->getAttribute() !== 'namespace') {
$this->message = 'Only namespace can be queried';
return false;
}
if (\count($value->getValues()) !== 1) {
$this->message = 'Namespace query must have exactly one value';
return false;
}
if (!(new Text(256))->isValid($value->getValue())) {
$this->message = 'Namespace query value must be a string with a maximum length of 256 characters';
return false;
}
return true;
}
}
+2
View File
@@ -197,6 +197,8 @@ class Response extends SwooleResponse
public const MODEL_PROVIDER_REPOSITORY_FRAMEWORK_LIST = 'providerRepositoryFrameworkList';
public const MODEL_PROVIDER_REPOSITORY_RUNTIME = 'providerRepositoryRuntime';
public const MODEL_PROVIDER_REPOSITORY_RUNTIME_LIST = 'providerRepositoryRuntimeList';
public const MODEL_VCS_NAMESPACE = 'vcsNamespace';
public const MODEL_VCS_NAMESPACE_LIST = 'vcsNamespaceList';
public const MODEL_BRANCH = 'branch';
public const MODEL_BRANCH_LIST = 'branchList';
public const MODEL_DETECTION_FRAMEWORK = 'detectionFramework';
@@ -0,0 +1,64 @@
<?php
namespace Appwrite\Utopia\Response\Model;
use Appwrite\Utopia\Response;
use Appwrite\Utopia\Response\Model;
class VcsNamespace extends Model
{
public function __construct()
{
$this
->addRule('$id', [
'type' => self::TYPE_STRING,
'description' => 'VCS (Version Control System) namespace ID.',
'default' => '',
'example' => '5e5ea5c16897e',
])
->addRule('name', [
'type' => self::TYPE_STRING,
'description' => 'VCS (Version Control System) namespace display name.',
'default' => '',
'example' => 'Appwrite',
])
->addRule('path', [
'type' => self::TYPE_STRING,
'description' => 'VCS (Version Control System) namespace path, used to filter repositories by namespace.',
'default' => '',
'example' => 'appwrite',
])
->addRule('type', [
'type' => self::TYPE_STRING,
'description' => 'Namespace type. Either the user\'s personal namespace or a group/organization.',
'default' => '',
'example' => 'user',
])
->addRule('avatarUrl', [
'type' => self::TYPE_STRING,
'description' => 'Namespace avatar URL.',
'default' => '',
'example' => 'https://example.com/avatar.png',
]);
}
/**
* Get Name
*
* @return string
*/
public function getName(): string
{
return 'VcsNamespace';
}
/**
* Get Type
*
* @return string
*/
public function getType(): string
{
return Response::MODEL_VCS_NAMESPACE;
}
}
@@ -0,0 +1,91 @@
<?php
declare(strict_types=1);
namespace Tests\Unit\Platform\Workers;
use Appwrite\Event\Realtime;
use Appwrite\Platform\Modules\Databases\Workers\Databases;
use PHPUnit\Framework\TestCase;
use Utopia\Database\Database;
use Utopia\Database\Document;
use Utopia\Logger\Log;
use Utopia\Queue\Message;
require_once __DIR__ . '/../../../../app/init.php';
final class DatabasesTest extends TestCase
{
/**
* A dedicated database (tablesdb/documentsdb/vectorsdb) hosts its collections
* on the backing resolved by getDatabasesDB, not the shared project database.
* createAttribute must run its DDL on that resolved database — as its siblings
* createIndex/deleteAttribute already do — or, for a dedicated backing, it
* queries the shared pool, cannot find the collection and fails
* "Collection not found" (DAT-1967).
*/
public function testCreateAttributeTargetsResolvedDatabaseNotProjectDb(): void
{
$attribute = new Document([
'$id' => 'attr1',
'key' => 'note',
'type' => Database::VAR_STRING,
'size' => 64,
'required' => false,
'default' => null,
]);
// The shared project DB owns the `attributes` metadata but must never
// receive the collection DDL for a dedicated backing.
$dbForProject = $this->createMock(Database::class);
$dbForProject->method('getDocument')->willReturnCallback(
fn (string $collection, string $id) => $collection === 'attributes' ? $attribute : new Document()
);
$dbForProject->method('updateDocument')->willReturnArgument(2);
$dbForProject->expects($this->never())->method('createAttribute');
$dbForPlatform = $this->createMock(Database::class);
$dbForPlatform->method('getDocument')->willReturn(new Document(['$id' => 'proj1']));
// The resolved (dedicated) backing must receive the physical DDL.
$dbForDatabases = $this->createMock(Database::class);
$dbForDatabases->expects($this->once())
->method('createAttribute')
->willReturn(true);
$worker = new class () extends Databases {
protected function trigger(
Document $database,
Document $collection,
Document $project,
string $event,
Realtime $queueForRealtime,
Document|null $attribute = null,
Document|null $index = null,
): void {
}
};
$message = new Message([
'pid' => 'pid',
'queue' => 'v1-databases',
'timestamp' => \time(),
'payload' => [
'type' => DATABASE_TYPE_CREATE_ATTRIBUTE,
'database' => ['$id' => 'db1', '$sequence' => '30360'],
'collection' => ['$id' => 'proof', '$sequence' => '1'],
'document' => ['$id' => 'attr1'],
],
]);
$worker->action(
$message,
new Document(['$id' => 'proj1']),
$dbForPlatform,
$dbForProject,
static fn () => $dbForDatabases,
$this->createStub(Realtime::class),
$this->createStub(Log::class),
);
}
}