import { Service } from '../service'; import { AppwriteException, Client } from '../client'; import type { Models } from '../models'; import type { UploadProgress, Payload } from '../client'; export class Functions extends Service { constructor(client: Client) { super(client); } /** * Retry Build * * * @param {string} functionId * @param {string} deploymentId * @param {string} buildId * @throws {AppwriteException} * @returns {Promise} */ async retryBuild(functionId: string, deploymentId: string, buildId: string): Promise<{}> { if (typeof functionId === 'undefined') { throw new AppwriteException('Missing required parameter: "functionId"'); } if (typeof deploymentId === 'undefined') { throw new AppwriteException('Missing required parameter: "deploymentId"'); } if (typeof buildId === 'undefined') { throw new AppwriteException('Missing required parameter: "buildId"'); } let path = '/functions/{functionId}/deployments/{deploymentId}/builds/{buildId}'.replace('{functionId}', functionId).replace('{deploymentId}', deploymentId).replace('{buildId}', buildId); let payload: Payload = {}; const uri = new URL(this.client.config.endpoint + path); return await this.client.call('post', uri, { 'content-type': 'application/json', }, payload); } /** * List Executions * * Get a list of all the current user function execution logs. You can use the * query params to filter your results. On admin mode, this endpoint will * return a list of all of the project's executions. [Learn more about * different API modes](/docs/admin). * * @param {string} functionId * @param {string[]} queries * @param {string} search * @throws {AppwriteException} * @returns {Promise} */ async listExecutions(functionId: string, queries?: string[], search?: string): Promise { if (typeof functionId === 'undefined') { throw new AppwriteException('Missing required parameter: "functionId"'); } let path = '/functions/{functionId}/executions'.replace('{functionId}', functionId); let payload: Payload = {}; if (typeof queries !== 'undefined') { payload['queries'] = queries; } if (typeof search !== 'undefined') { payload['search'] = search; } const uri = new URL(this.client.config.endpoint + path); return await this.client.call('get', uri, { 'content-type': 'application/json', }, payload); } /** * Create Execution * * Trigger a function execution. The returned object will return you the * current execution status. You can ping the `Get Execution` endpoint to get * updates on the current execution status. Once this endpoint is called, your * function execution process will start asynchronously. * * @param {string} functionId * @param {string} data * @param {boolean} async * @throws {AppwriteException} * @returns {Promise} */ async createExecution(functionId: string, data?: string, async?: boolean): Promise { if (typeof functionId === 'undefined') { throw new AppwriteException('Missing required parameter: "functionId"'); } let path = '/functions/{functionId}/executions'.replace('{functionId}', functionId); let payload: Payload = {}; if (typeof data !== 'undefined') { payload['data'] = data; } if (typeof async !== 'undefined') { payload['async'] = async; } const uri = new URL(this.client.config.endpoint + path); return await this.client.call('post', uri, { 'content-type': 'application/json', }, payload); } /** * Get Execution * * Get a function execution log by its unique ID. * * @param {string} functionId * @param {string} executionId * @throws {AppwriteException} * @returns {Promise} */ async getExecution(functionId: string, executionId: string): Promise { if (typeof functionId === 'undefined') { throw new AppwriteException('Missing required parameter: "functionId"'); } if (typeof executionId === 'undefined') { throw new AppwriteException('Missing required parameter: "executionId"'); } let path = '/functions/{functionId}/executions/{executionId}'.replace('{functionId}', functionId).replace('{executionId}', executionId); let payload: Payload = {}; const uri = new URL(this.client.config.endpoint + path); return await this.client.call('get', uri, { 'content-type': 'application/json', }, payload); } };