Skip to content

Commit

Permalink
chore: update SDKs to new RC version
Browse files Browse the repository at this point in the history
  • Loading branch information
christyjacob4 committed Aug 20, 2024
1 parent 851e598 commit 64cf18a
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 12 deletions.
1 change: 0 additions & 1 deletion docs/examples/functions/create-execution.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 2 additions & 1 deletion docs/examples/functions/create.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ const result = await functions.create(
'<TEMPLATE_REPOSITORY>', // templateRepository (optional)
'<TEMPLATE_OWNER>', // templateOwner (optional)
'<TEMPLATE_ROOT_DIRECTORY>', // templateRootDirectory (optional)
'<TEMPLATE_VERSION>' // templateVersion (optional)
'<TEMPLATE_VERSION>', // templateVersion (optional)
'' // specification (optional)
);
10 changes: 10 additions & 0 deletions docs/examples/functions/list-specifications.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const sdk = require('node-appwrite');

const client = new sdk.Client()
.setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint
.setProject('&lt;YOUR_PROJECT_ID&gt;') // Your project ID
.setKey('&lt;YOUR_API_KEY&gt;'); // Your secret API key

const functions = new sdk.Functions(client);

const result = await functions.listSpecifications();
3 changes: 2 additions & 1 deletion docs/examples/functions/update.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ const result = await functions.update(
'<PROVIDER_REPOSITORY_ID>', // providerRepositoryId (optional)
'<PROVIDER_BRANCH>', // providerBranch (optional)
false, // providerSilentMode (optional)
'<PROVIDER_ROOT_DIRECTORY>' // providerRootDirectory (optional)
'<PROVIDER_ROOT_DIRECTORY>', // providerRootDirectory (optional)
'' // specification (optional)
);
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = [];
Expand Down Expand Up @@ -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',
};
Expand Down
38 changes: 38 additions & 0 deletions src/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
*/
Expand Down
44 changes: 38 additions & 6 deletions src/services/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,11 @@ export class Functions {
* @param {string} templateOwner
* @param {string} templateRootDirectory
* @param {string} templateVersion
* @param {string} specification
* @throws {AppwriteException}
* @returns {Promise<Models.Function>}
*/
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<Models.Function> {
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<Models.Function> {
if (typeof functionId === 'undefined') {
throw new AppwriteException('Missing required parameter: "functionId"');
}
Expand Down Expand Up @@ -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 } = {
Expand Down Expand Up @@ -183,6 +187,31 @@ export class Functions {
payload,
);
}
/**
* List available function runtime specifications
*
* List allowed function specifications for this instance.
*
* @throws {AppwriteException}
* @returns {Promise<Models.SpecificationList>}
*/
async listSpecifications(): Promise<Models.SpecificationList> {
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
*
Expand Down Expand Up @@ -301,10 +330,11 @@ export class Functions {
* @param {string} providerBranch
* @param {boolean} providerSilentMode
* @param {string} providerRootDirectory
* @param {string} specification
* @throws {AppwriteException}
* @returns {Promise<Models.Function>}
*/
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<Models.Function> {
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<Models.Function> {
if (typeof functionId === 'undefined') {
throw new AppwriteException('Missing required parameter: "functionId"');
}
Expand Down Expand Up @@ -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 } = {
Expand Down Expand Up @@ -739,7 +772,7 @@ Use the &quot;command&quot; param to set the entrypoint used to execute your cod
* @throws {AppwriteException}
* @returns {Promise<Models.Execution>}
*/
async createExecution(functionId: string, body?: string, async?: boolean, xpath?: string, method?: ExecutionMethod, headers?: object, scheduledAt?: string, onProgress = (progress: UploadProgress) => {}): Promise<Models.Execution> {
async createExecution(functionId: string, body?: string, async?: boolean, xpath?: string, method?: ExecutionMethod, headers?: object, scheduledAt?: string): Promise<Models.Execution> {
if (typeof functionId === 'undefined') {
throw new AppwriteException('Missing required parameter: "functionId"');
}
Expand All @@ -766,15 +799,14 @@ Use the &quot;command&quot; 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
);
}
/**
Expand Down

0 comments on commit 64cf18a

Please sign in to comment.