From 71b764c94012d102bd33e9b3fc014e471f574880 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 20 Aug 2024 11:03:11 +0000 Subject: [PATCH] chore: update SDKs to new RC version --- docs/examples/functions/create.md | 3 +- .../examples/functions/list-specifications.md | 13 +++++ docs/examples/functions/update.md | 3 +- docs/functions.md | 11 ++++ src/Appwrite/Client.php | 4 +- src/Appwrite/Services/Functions.php | 54 +++++++++++++++++-- tests/Appwrite/Services/FunctionsTest.php | 29 ++++++++-- 7 files changed, 105 insertions(+), 12 deletions(-) create mode 100644 docs/examples/functions/list-specifications.md diff --git a/docs/examples/functions/create.md b/docs/examples/functions/create.md index 44ff159..8c59076 100644 --- a/docs/examples/functions/create.md +++ b/docs/examples/functions/create.md @@ -32,5 +32,6 @@ $result = $functions->create( templateRepository: '', // optional templateOwner: '', // optional templateRootDirectory: '', // optional - templateVersion: '' // optional + templateVersion: '', // optional + specification: '' // optional ); \ No newline at end of file diff --git a/docs/examples/functions/list-specifications.md b/docs/examples/functions/list-specifications.md new file mode 100644 index 0000000..678c2fa --- /dev/null +++ b/docs/examples/functions/list-specifications.md @@ -0,0 +1,13 @@ +setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + ->setProject('<YOUR_PROJECT_ID>') // Your project ID + ->setKey('<YOUR_API_KEY>'); // Your secret API key + +$functions = new Functions($client); + +$result = $functions->listSpecifications(); diff --git a/docs/examples/functions/update.md b/docs/examples/functions/update.md index db0d50a..bd028cb 100644 --- a/docs/examples/functions/update.md +++ b/docs/examples/functions/update.md @@ -27,5 +27,6 @@ $result = $functions->update( providerRepositoryId: '', // optional providerBranch: '', // optional providerSilentMode: false, // optional - providerRootDirectory: '' // optional + providerRootDirectory: '', // optional + specification: '' // optional ); \ No newline at end of file diff --git a/docs/functions.md b/docs/functions.md index 06fccc8..08a932c 100644 --- a/docs/functions.md +++ b/docs/functions.md @@ -48,6 +48,7 @@ POST https://cloud.appwrite.io/v1/functions | templateOwner | string | The name of the owner of the template. | | | templateRootDirectory | string | Path to function code in the template repo. | | | templateVersion | string | Version (tag) for the repo linked to the function template. | | +| specification | string | Runtime specification for the function and builds. | s-0.5vcpu-512mb | ## List runtimes @@ -57,6 +58,15 @@ GET https://cloud.appwrite.io/v1/functions/runtimes ** Get a list of all runtimes that are currently active on your instance. ** +## List available function runtime specifications + +```http request +GET https://cloud.appwrite.io/v1/functions/specifications +``` + +** List allowed function specifications for this instance. + ** + ## List function templates ```http request @@ -131,6 +141,7 @@ PUT https://cloud.appwrite.io/v1/functions/{functionId} | providerBranch | string | Production branch for the repo linked to the function | | | providerSilentMode | boolean | Is the VCS (Version Control System) connection in silent mode for the repo linked to the function? In silent mode, comments will not be made on commits and pull requests. | | | providerRootDirectory | string | Path to function code in the linked repo. | | +| specification | string | Runtime specification for the function and builds. | s-0.5vcpu-512mb | ## Delete function diff --git a/src/Appwrite/Client.php b/src/Appwrite/Client.php index 2f7e61a..8314ca8 100644 --- a/src/Appwrite/Client.php +++ b/src/Appwrite/Client.php @@ -37,11 +37,11 @@ class Client */ protected array $headers = [ 'content-type' => '', - 'user-agent' => 'AppwritePHPSDK/12.0.0-rc.1 ()', + 'user-agent' => 'AppwritePHPSDK/12.0.0-rc.2 ()', 'x-sdk-name'=> 'PHP', 'x-sdk-platform'=> 'server', 'x-sdk-language'=> 'php', - 'x-sdk-version'=> '12.0.0-rc.1', + 'x-sdk-version'=> '12.0.0-rc.2', ]; /** diff --git a/src/Appwrite/Services/Functions.php b/src/Appwrite/Services/Functions.php index 56521f1..57e4830 100644 --- a/src/Appwrite/Services/Functions.php +++ b/src/Appwrite/Services/Functions.php @@ -85,10 +85,11 @@ public function list(?array $queries = null, ?string $search = null): array * @param ?string $templateOwner * @param ?string $templateRootDirectory * @param ?string $templateVersion + * @param ?string $specification * @throws AppwriteException * @return array */ - public function create(string $functionId, string $name, Runtime $runtime, ?array $execute = null, ?array $events = null, ?string $schedule = null, ?int $timeout = null, ?bool $enabled = null, ?bool $logging = null, ?string $entrypoint = null, ?string $commands = null, ?array $scopes = null, ?string $installationId = null, ?string $providerRepositoryId = null, ?string $providerBranch = null, ?bool $providerSilentMode = null, ?string $providerRootDirectory = null, ?string $templateRepository = null, ?string $templateOwner = null, ?string $templateRootDirectory = null, ?string $templateVersion = null): array + public function create(string $functionId, string $name, Runtime $runtime, ?array $execute = null, ?array $events = null, ?string $schedule = null, ?int $timeout = null, ?bool $enabled = null, ?bool $logging = null, ?string $entrypoint = null, ?string $commands = null, ?array $scopes = null, ?string $installationId = null, ?string $providerRepositoryId = null, ?string $providerBranch = null, ?bool $providerSilentMode = null, ?string $providerRootDirectory = null, ?string $templateRepository = null, ?string $templateOwner = null, ?string $templateRootDirectory = null, ?string $templateVersion = null, ?string $specification = null): array { $apiPath = str_replace( [], @@ -173,6 +174,10 @@ public function create(string $functionId, string $name, Runtime $runtime, ?arra $apiParams['templateVersion'] = $templateVersion; } + if (!is_null($specification)) { + $apiParams['specification'] = $specification; + } + $apiHeaders = []; $apiHeaders['content-type'] = 'application/json'; @@ -213,6 +218,36 @@ public function listRuntimes(): array ); } + /** + * List available function runtime specifications + * + * List allowed function specifications for this instance. + * + * + * @throws AppwriteException + * @return array + */ + public function listSpecifications(): array + { + $apiPath = str_replace( + [], + [], + '/functions/specifications' + ); + + $apiParams = []; + + $apiHeaders = []; + $apiHeaders['content-type'] = 'application/json'; + + return $this->client->call( + Client::METHOD_GET, + $apiPath, + $apiHeaders, + $apiParams + ); + } + /** * List function templates * @@ -350,10 +385,11 @@ public function get(string $functionId): array * @param ?string $providerBranch * @param ?bool $providerSilentMode * @param ?string $providerRootDirectory + * @param ?string $specification * @throws AppwriteException * @return array */ - public function update(string $functionId, string $name, ?Runtime $runtime = null, ?array $execute = null, ?array $events = null, ?string $schedule = null, ?int $timeout = null, ?bool $enabled = null, ?bool $logging = null, ?string $entrypoint = null, ?string $commands = null, ?array $scopes = null, ?string $installationId = null, ?string $providerRepositoryId = null, ?string $providerBranch = null, ?bool $providerSilentMode = null, ?string $providerRootDirectory = null): array + public function update(string $functionId, string $name, ?Runtime $runtime = null, ?array $execute = null, ?array $events = null, ?string $schedule = null, ?int $timeout = null, ?bool $enabled = null, ?bool $logging = null, ?string $entrypoint = null, ?string $commands = null, ?array $scopes = null, ?string $installationId = null, ?string $providerRepositoryId = null, ?string $providerBranch = null, ?bool $providerSilentMode = null, ?string $providerRootDirectory = null, ?string $specification = null): array { $apiPath = str_replace( ['{functionId}'], @@ -422,6 +458,10 @@ public function update(string $functionId, string $name, ?Runtime $runtime = nul $apiParams['providerRootDirectory'] = $providerRootDirectory; } + if (!is_null($specification)) { + $apiParams['specification'] = $specification; + } + $apiHeaders = []; $apiHeaders['content-type'] = 'application/json'; @@ -887,7 +927,7 @@ public function listExecutions(string $functionId, ?array $queries = null, ?stri * @throws AppwriteException * @return array */ - public function createExecution(string $functionId, ?string $body = null, ?bool $async = null, ?string $xpath = null, ?ExecutionMethod $method = null, ?array $headers = null, ?string $scheduledAt = null, callable $onProgress = null): array + public function createExecution(string $functionId, ?string $body = null, ?bool $async = null, ?string $xpath = null, ?ExecutionMethod $method = null, ?array $headers = null, ?string $scheduledAt = null): array { $apiPath = str_replace( ['{functionId}'], @@ -923,8 +963,14 @@ public function createExecution(string $functionId, ?string $body = null, ?bool } $apiHeaders = []; - $apiHeaders['content-type'] = 'multipart/form-data'; + $apiHeaders['content-type'] = 'application/json'; + return $this->client->call( + Client::METHOD_POST, + $apiPath, + $apiHeaders, + $apiParams + ); } /** diff --git a/tests/Appwrite/Services/FunctionsTest.php b/tests/Appwrite/Services/FunctionsTest.php index ea44a6e..27904c8 100644 --- a/tests/Appwrite/Services/FunctionsTest.php +++ b/tests/Appwrite/Services/FunctionsTest.php @@ -58,7 +58,8 @@ public function testMethodCreate(): void { "providerRepositoryId" => "appwrite", "providerBranch" => "main", "providerRootDirectory" => "functions/helloWorld", - "providerSilentMode" => true,); + "providerSilentMode" => true, + "specification" => "s-0.5vcpu-512mb",); $this->client @@ -91,6 +92,23 @@ public function testMethodListRuntimes(): void { $this->assertSame($data, $response); } + public function testMethodListSpecifications(): void { + + $data = array( + "total" => 5, + "specifications" => array(),); + + + $this->client + ->allows()->call(Mockery::any(), Mockery::any(), Mockery::any(), Mockery::any()) + ->andReturn($data); + + $response = $this->functions->listSpecifications( + ); + + $this->assertSame($data, $response); + } + public function testMethodListTemplates(): void { $data = array( @@ -166,7 +184,8 @@ public function testMethodGet(): void { "providerRepositoryId" => "appwrite", "providerBranch" => "main", "providerRootDirectory" => "functions/helloWorld", - "providerSilentMode" => true,); + "providerSilentMode" => true, + "specification" => "s-0.5vcpu-512mb",); $this->client @@ -205,7 +224,8 @@ public function testMethodUpdate(): void { "providerRepositoryId" => "appwrite", "providerBranch" => "main", "providerRootDirectory" => "functions/helloWorld", - "providerSilentMode" => true,); + "providerSilentMode" => true, + "specification" => "s-0.5vcpu-512mb",); $this->client @@ -360,7 +380,8 @@ public function testMethodUpdateDeployment(): void { "providerRepositoryId" => "appwrite", "providerBranch" => "main", "providerRootDirectory" => "functions/helloWorld", - "providerSilentMode" => true,); + "providerSilentMode" => true, + "specification" => "s-0.5vcpu-512mb",); $this->client