From 64cf18a0d7d6c26e75bbf7ea50795ee84d62eef2 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 20 Aug 2024 11:02:48 +0000 Subject: [PATCH] chore: update SDKs to new RC version --- docs/examples/functions/create-execution.md | 1 - docs/examples/functions/create.md | 3 +- .../examples/functions/list-specifications.md | 10 +++++ docs/examples/functions/update.md | 3 +- package.json | 2 +- src/client.ts | 4 +- src/models.ts | 38 ++++++++++++++++ src/services/functions.ts | 44 ++++++++++++++++--- 8 files changed, 93 insertions(+), 12 deletions(-) create mode 100644 docs/examples/functions/list-specifications.md diff --git a/docs/examples/functions/create-execution.md b/docs/examples/functions/create-execution.md index cf531c7..1b5e09b 100644 --- a/docs/examples/functions/create-execution.md +++ b/docs/examples/functions/create-execution.md @@ -1,5 +1,4 @@ const sdk = require('node-appwrite'); -const fs = require('fs'); const client = new sdk.Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint diff --git a/docs/examples/functions/create.md b/docs/examples/functions/create.md index c4deaf6..56b3c82 100644 --- a/docs/examples/functions/create.md +++ b/docs/examples/functions/create.md @@ -28,5 +28,6 @@ const result = await functions.create( '', // templateRepository (optional) '', // templateOwner (optional) '', // templateRootDirectory (optional) - '' // templateVersion (optional) + '', // templateVersion (optional) + '' // specification (optional) ); diff --git a/docs/examples/functions/list-specifications.md b/docs/examples/functions/list-specifications.md new file mode 100644 index 0000000..d2e6825 --- /dev/null +++ b/docs/examples/functions/list-specifications.md @@ -0,0 +1,10 @@ +const sdk = require('node-appwrite'); + +const client = new sdk.Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('<YOUR_PROJECT_ID>') // Your project ID + .setKey('<YOUR_API_KEY>'); // Your secret API key + +const functions = new sdk.Functions(client); + +const result = await functions.listSpecifications(); diff --git a/docs/examples/functions/update.md b/docs/examples/functions/update.md index c437704..e6157a3 100644 --- a/docs/examples/functions/update.md +++ b/docs/examples/functions/update.md @@ -24,5 +24,6 @@ const result = await functions.update( '', // providerRepositoryId (optional) '', // providerBranch (optional) false, // providerSilentMode (optional) - '' // providerRootDirectory (optional) + '', // providerRootDirectory (optional) + '' // specification (optional) ); diff --git a/package.json b/package.json index 3b57707..97df522 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "node-appwrite", "homepage": "https://appwrite.io/support", "description": "Appwrite is an open-source self-hosted backend server that abstract and simplify complex and repetitive development tasks behind a very simple REST API", - "version": "14.0.0-rc.2", + "version": "14.0.0-rc.3", "license": "BSD-3-Clause", "main": "dist/index.js", "type": "commonjs", diff --git a/src/client.ts b/src/client.ts index bb89292..7913597 100644 --- a/src/client.ts +++ b/src/client.ts @@ -33,7 +33,7 @@ class AppwriteException extends Error { } function getUserAgent() { - let ua = 'AppwriteNodeJSSDK/14.0.0-rc.2'; + let ua = 'AppwriteNodeJSSDK/14.0.0-rc.3'; // `process` is a global in Node.js, but not fully available in all runtimes. const platform: string[] = []; @@ -82,7 +82,7 @@ class Client { 'x-sdk-name': 'Node.js', 'x-sdk-platform': 'server', 'x-sdk-language': 'nodejs', - 'x-sdk-version': '14.0.0-rc.2', + 'x-sdk-version': '14.0.0-rc.3', 'user-agent' : getUserAgent(), 'X-Appwrite-Response-Format': '1.6.0', }; diff --git a/src/models.ts b/src/models.ts index 98f6c79..0c08065 100644 --- a/src/models.ts +++ b/src/models.ts @@ -379,6 +379,19 @@ export namespace Models { */ targets: Target[]; } + /** + * Specifications List + */ + export type SpecificationList = { + /** + * Total number of specifications documents that matched your query. + */ + total: number; + /** + * List of specifications. + */ + specifications: Specification[]; + } /** * Database */ @@ -1728,6 +1741,10 @@ export namespace Models { * Is VCS (Version Control System) connection is in silent mode? When in silence mode, no comments will be posted on the repository pull or merge requests */ providerSilentMode: boolean; + /** + * Machine specification for builds and executions. + */ + specification: string; } /** * Template Function @@ -2324,6 +2341,27 @@ export namespace Models { */ value: string; } + /** + * Specification + */ + export type Specification = { + /** + * Memory size in MB. + */ + memory: number; + /** + * Number of CPUs. + */ + cpus: number; + /** + * Is size enabled. + */ + enabled: boolean; + /** + * Size slug. + */ + slug: string; + } /** * MFA Challenge */ diff --git a/src/services/functions.ts b/src/services/functions.ts index 0ecbfec..f8e7e80 100644 --- a/src/services/functions.ts +++ b/src/services/functions.ts @@ -68,10 +68,11 @@ export class Functions { * @param {string} templateOwner * @param {string} templateRootDirectory * @param {string} templateVersion + * @param {string} specification * @throws {AppwriteException} * @returns {Promise} */ - async create(functionId: string, name: string, runtime: Runtime, execute?: string[], events?: string[], schedule?: string, timeout?: number, enabled?: boolean, logging?: boolean, entrypoint?: string, commands?: string, scopes?: string[], installationId?: string, providerRepositoryId?: string, providerBranch?: string, providerSilentMode?: boolean, providerRootDirectory?: string, templateRepository?: string, templateOwner?: string, templateRootDirectory?: string, templateVersion?: string): Promise { + async create(functionId: string, name: string, runtime: Runtime, execute?: string[], events?: string[], schedule?: string, timeout?: number, enabled?: boolean, logging?: boolean, entrypoint?: string, commands?: string, scopes?: string[], installationId?: string, providerRepositoryId?: string, providerBranch?: string, providerSilentMode?: boolean, providerRootDirectory?: string, templateRepository?: string, templateOwner?: string, templateRootDirectory?: string, templateVersion?: string, specification?: string): Promise { if (typeof functionId === 'undefined') { throw new AppwriteException('Missing required parameter: "functionId"'); } @@ -146,6 +147,9 @@ export class Functions { if (typeof templateVersion !== 'undefined') { payload['templateVersion'] = templateVersion; } + if (typeof specification !== 'undefined') { + payload['specification'] = specification; + } const uri = new URL(this.client.config.endpoint + apiPath); const apiHeaders: { [header: string]: string } = { @@ -183,6 +187,31 @@ export class Functions { payload, ); } + /** + * List available function runtime specifications + * + * List allowed function specifications for this instance. + + * + * @throws {AppwriteException} + * @returns {Promise} + */ + async listSpecifications(): Promise { + const apiPath = '/functions/specifications'; + const payload: Payload = {}; + const uri = new URL(this.client.config.endpoint + apiPath); + + const apiHeaders: { [header: string]: string } = { + 'content-type': 'application/json', + } + + return await this.client.call( + 'get', + uri, + apiHeaders, + payload, + ); + } /** * List function templates * @@ -301,10 +330,11 @@ export class Functions { * @param {string} providerBranch * @param {boolean} providerSilentMode * @param {string} providerRootDirectory + * @param {string} specification * @throws {AppwriteException} * @returns {Promise} */ - async update(functionId: string, name: string, runtime?: Runtime, execute?: string[], events?: string[], schedule?: string, timeout?: number, enabled?: boolean, logging?: boolean, entrypoint?: string, commands?: string, scopes?: string[], installationId?: string, providerRepositoryId?: string, providerBranch?: string, providerSilentMode?: boolean, providerRootDirectory?: string): Promise { + async update(functionId: string, name: string, runtime?: Runtime, execute?: string[], events?: string[], schedule?: string, timeout?: number, enabled?: boolean, logging?: boolean, entrypoint?: string, commands?: string, scopes?: string[], installationId?: string, providerRepositoryId?: string, providerBranch?: string, providerSilentMode?: boolean, providerRootDirectory?: string, specification?: string): Promise { if (typeof functionId === 'undefined') { throw new AppwriteException('Missing required parameter: "functionId"'); } @@ -361,6 +391,9 @@ export class Functions { if (typeof providerRootDirectory !== 'undefined') { payload['providerRootDirectory'] = providerRootDirectory; } + if (typeof specification !== 'undefined') { + payload['specification'] = specification; + } const uri = new URL(this.client.config.endpoint + apiPath); const apiHeaders: { [header: string]: string } = { @@ -739,7 +772,7 @@ Use the "command" param to set the entrypoint used to execute your cod * @throws {AppwriteException} * @returns {Promise} */ - async createExecution(functionId: string, body?: string, async?: boolean, xpath?: string, method?: ExecutionMethod, headers?: object, scheduledAt?: string, onProgress = (progress: UploadProgress) => {}): Promise { + async createExecution(functionId: string, body?: string, async?: boolean, xpath?: string, method?: ExecutionMethod, headers?: object, scheduledAt?: string): Promise { if (typeof functionId === 'undefined') { throw new AppwriteException('Missing required parameter: "functionId"'); } @@ -766,15 +799,14 @@ Use the "command" param to set the entrypoint used to execute your cod const uri = new URL(this.client.config.endpoint + apiPath); const apiHeaders: { [header: string]: string } = { - 'content-type': 'multipart/form-data', + 'content-type': 'application/json', } - return await this.client.chunkedUpload( + return await this.client.call( 'post', uri, apiHeaders, payload, - onProgress ); } /**