diff --git a/package-lock.json b/package-lock.json index 650428e1e..709bf44cc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6,7 +6,7 @@ "": { "name": "@appwrite/console", "dependencies": { - "@appwrite.io/console": "^0.6.2", + "@appwrite.io/console": "^0.6.3", "@appwrite.io/pink": "0.25.0", "@appwrite.io/pink-icons": "0.25.0", "@popperjs/core": "^2.11.8", @@ -149,9 +149,10 @@ "integrity": "sha512-TD+xbmsBLyYy/IxFimW/YL/9L2IEnM7/EoV9Aeh56U64Ify8o27HJcKjo38XY9Tcn0uOq1AX3thkKgvtWvwFQg==" }, "node_modules/@appwrite.io/console": { - "version": "0.6.2", - "resolved": "https://registry.npmjs.org/@appwrite.io/console/-/console-0.6.2.tgz", - "integrity": "sha512-3qYknuFwhvTN2GnPB8G1w5DgxfVorGtfj4uuEaXbTmMUmjA8fHaW5VkJriuUxCi6/TpxDxqV/hhEkdoXL+5H4w==" + "version": "0.6.3", + "resolved": "https://registry.npmjs.org/@appwrite.io/console/-/console-0.6.3.tgz", + "integrity": "sha512-V821WlzzOngF/Ax7A0KihTkcz2qOiOwHp+seLszcFgUuoUpAk9HU4V8WV7zFSqFxTaluL0tE55p4SDoc9CifpA==", + "license": "BSD-3-Clause" }, "node_modules/@appwrite.io/pink": { "version": "0.25.0", diff --git a/package.json b/package.json index e566dcf14..7e47e62a2 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "e2e:ui": "playwright test tests/e2e --ui" }, "dependencies": { - "@appwrite.io/console": "^0.6.2", + "@appwrite.io/console": "^0.6.3", "@appwrite.io/pink": "0.25.0", "@appwrite.io/pink-icons": "0.25.0", "@popperjs/core": "^2.11.8", diff --git a/src/lib/sdk/functionsSpec.ts b/src/lib/sdk/functionsSpec.ts deleted file mode 100644 index 7afb2b1f6..000000000 --- a/src/lib/sdk/functionsSpec.ts +++ /dev/null @@ -1,438 +0,0 @@ -import { AppwriteException, Runtime, type Client, type Payload } from '@appwrite.io/console'; - -export type Specs = { - cpus: number[]; - memory: number[]; -}; - -/** - * Variable - */ -type Variable = { - /** - * Variable ID. - */ - $id: string; - /** - * Variable creation date in ISO 8601 format. - */ - $createdAt: string; - /** - * Variable creation date in ISO 8601 format. - */ - $updatedAt: string; - /** - * Variable key. - */ - key: string; - /** - * Variable value. - */ - value: string; - /** - * Service to which the variable belongs. Possible values are "project", "function" - */ - resourceType: string; - /** - * ID of resource to which the variable belongs. If resourceType is "project", it is empty. If resourceType is "function", it is ID of the function. - */ - resourceId: string; -}; - -export type Func = { - /** - * Function ID. - */ - $id: string; - /** - * Function creation date in ISO 8601 format. - */ - $createdAt: string; - /** - * Function update date in ISO 8601 format. - */ - $updatedAt: string; - /** - * Execution permissions. - */ - execute: string[]; - /** - * Function name. - */ - name: string; - /** - * Function enabled. - */ - enabled: boolean; - /** - * Is the function deployed with the latest configuration? This is set to false if you've changed an environment variables, entrypoint, commands, or other settings that needs redeploy to be applied. When the value is false, redeploy the function to update it with the latest configuration. - */ - live: boolean; - /** - * Whether executions will be logged. When set to false, executions will not be logged, but will reduce resource used by your Appwrite project. - */ - logging: boolean; - /** - * Function execution runtime. - */ - runtime: string; - /** - * Function's active deployment ID. - */ - deployment: string; - /** - * Function variables. - */ - vars: Variable[]; - /** - * Function trigger events. - */ - events: string[]; - /** - * Function execution schedult in CRON format. - */ - schedule: string; - /** - * Function execution timeout in seconds. - */ - timeout: number; - /** - * The entrypoint file used to execute the deployment. - */ - entrypoint: string; - /** - * The build command used to build the deployment. - */ - commands: string; - /** - * Version of Open Runtimes used for the function. - */ - version: string; - /** - * Function VCS (Version Control System) installation id. - */ - installationId: string; - /** - * VCS (Version Control System) Repository ID - */ - providerRepositoryId: string; - /** - * VCS (Version Control System) branch name - */ - providerBranch: string; - /** - * Path to function in VCS (Version Control System) repository - */ - providerRootDirectory: string; - /** - * 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; - /** - * Runtime Size - */ - specification: string; -}; - -export type Specification = { - slug: string; - plan: string; - cpus: number; - memory: number; - enabled: boolean; -}; - -export type Specifications = { - specification: Specification[]; -}; - -export enum FunctionUsageRange { - TwentyFourHours = '24h', - ThirtyDays = '30d', - NinetyDays = '90d' -} - -/** - * Metric - */ -export type Metric = { - /** - * The value of this metric at the timestamp. - */ - value: number; - /** - * The date at which this metric was aggregated in ISO 8601 format. - */ - date: string; -}; -/** - * Metric Breakdown - */ -export type MetricBreakdown = { - /** - * Resource ID. - */ - resourceId: string; - /** - * Resource name. - */ - name: string; - /** - * The value of this metric at the timestamp. - */ - value: number; -}; - -/** - * UsageFunction - */ -export type UsageFunction = { - /** - * The time range of the usage stats. - */ - range: string; - /** - * Total aggregated number of function deployments. - */ - deploymentsTotal: number; - /** - * Total aggregated sum of function deployments storage. - */ - deploymentsStorageTotal: number; - /** - * Total aggregated number of function builds. - */ - buildsTotal: number; - /** - * total aggregated sum of function builds storage. - */ - buildsStorageTotal: number; - /** - * Total aggregated sum of function builds compute time. - */ - buildsTimeTotal: number; - /** - * Total aggregated number of function executions. - */ - executionsTotal: number; - /** - * Total aggregated sum of function executions compute time. - */ - executionsTimeTotal: number; - /** - * Total amount fo executions mbSeconds - */ - executionsMbSecondsTotal: number; - /** - * Aggregated number of function deployments per period. - */ - deployments: Metric[]; - /** - * Aggregated number of function deployments storage per period. - */ - deploymentsStorage: Metric[]; - /** - * Aggregated number of function builds per period. - */ - builds: Metric[]; - /** - * Aggregated sum of function builds storage per period. - */ - buildsStorage: Metric[]; - /** - * Aggregated sum of function builds compute time per period. - */ - buildsTime: Metric[]; - /** - * Aggregated number of function executions per period. - */ - executions: Metric[]; - /** - * Aggregated number of function executions compute time per period. - */ - executionsTime: Metric[]; - /** - * Aggregated number of function executions compute time per period. - */ - executionsMbSeconds: Metric[]; -}; - -export class SizesFunctions { - client: Client; - - constructor(client: Client) { - this.client = client; - } - - async getSpecifications(): Promise { - const path = '/functions/specifications'; - - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call('GET', uri, { - 'content-type': 'application/json' - }); - } - - /** - * Update function - * - * Update function by its unique ID. - * - * @param {string} functionId - * @param {string} name - * @param {Runtime} runtime - * @param {string[]} execute - * @param {string[]} events - * @param {string} schedule - * @param {number} timeout - * @param {boolean} enabled - * @param {boolean} logging - * @param {string} entrypoint - * @param {string} commands - * @param {string} installationId - * @param {string} providerRepositoryId - * @param {string} providerBranch - * @param {boolean} providerSilentMode - * @param {string} providerRootDirectory - * @param {number} cpus - * @param {number} memory - * @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, - installationId?: string, - providerRepositoryId?: string, - providerBranch?: string, - providerSilentMode?: boolean, - providerRootDirectory?: string, - specification?: string - ): Promise { - if (typeof functionId === 'undefined') { - throw new AppwriteException('Missing required parameter: "functionId"'); - } - - if (typeof name === 'undefined') { - throw new AppwriteException('Missing required parameter: "name"'); - } - - const apiPath = '/functions/{functionId}'.replace('{functionId}', functionId); - const payload: Payload = {}; - - if (typeof name !== 'undefined') { - payload['name'] = name; - } - - if (typeof runtime !== 'undefined') { - payload['runtime'] = runtime; - } - - if (typeof execute !== 'undefined') { - payload['execute'] = execute; - } - - if (typeof events !== 'undefined') { - payload['events'] = events; - } - - if (typeof schedule !== 'undefined') { - payload['schedule'] = schedule; - } - - if (typeof timeout !== 'undefined') { - payload['timeout'] = timeout; - } - - if (typeof enabled !== 'undefined') { - payload['enabled'] = enabled; - } - - if (typeof logging !== 'undefined') { - payload['logging'] = logging; - } - - if (typeof entrypoint !== 'undefined') { - payload['entrypoint'] = entrypoint; - } - - if (typeof commands !== 'undefined') { - payload['commands'] = commands; - } - - if (typeof installationId !== 'undefined') { - payload['installationId'] = installationId; - } - - if (typeof providerRepositoryId !== 'undefined') { - payload['providerRepositoryId'] = providerRepositoryId; - } - - if (typeof providerBranch !== 'undefined') { - payload['providerBranch'] = providerBranch; - } - - if (typeof providerSilentMode !== 'undefined') { - payload['providerSilentMode'] = providerSilentMode; - } - - if (typeof providerRootDirectory !== 'undefined') { - payload['providerRootDirectory'] = providerRootDirectory; - } - - if (typeof specification !== 'undefined') { - payload['specification'] = specification; - } - - const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call( - 'put', - uri, - { - 'content-type': 'application/json' - }, - payload - ); - } - - /** - * Get function usage - * - * - * @param {string} functionId - * @param {FunctionUsageRange} range - * @throws {AppwriteException} - * @returns {Promise} - */ - async getFunctionUsage(functionId: string, range?: FunctionUsageRange): Promise { - if (typeof functionId === 'undefined') { - throw new AppwriteException('Missing required parameter: "functionId"'); - } - - const apiPath = '/functions/{functionId}/usage'.replace('{functionId}', functionId); - const payload: Payload = {}; - - if (typeof range !== 'undefined') { - payload['range'] = range; - } - - const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call( - 'get', - uri, - { - 'content-type': 'application/json' - }, - payload - ); - } -} diff --git a/src/lib/stores/sdk.ts b/src/lib/stores/sdk.ts index f040a732e..8dacdc079 100644 --- a/src/lib/stores/sdk.ts +++ b/src/lib/stores/sdk.ts @@ -23,7 +23,6 @@ import { } from '@appwrite.io/console'; import { Billing } from '../sdk/billing'; import { Sources } from '$lib/sdk/sources'; -import { SizesFunctions } from '$lib/sdk/functionsSpec'; const endpoint = VARS.APPWRITE_ENDPOINT ?? `${globalThis?.location?.origin}/v1`; @@ -39,7 +38,6 @@ const sdkForProject = { avatars: new Avatars(clientProject), databases: new Databases(clientProject), functions: new Functions(clientProject), - sizesFunctions: new SizesFunctions(clientProject), health: new Health(clientProject), locale: new Locale(clientProject), messaging: new Messaging(clientProject), diff --git a/src/routes/console/project-[project]/functions/+layout.ts b/src/routes/console/project-[project]/functions/+layout.ts index 94801c23a..f30945205 100644 --- a/src/routes/console/project-[project]/functions/+layout.ts +++ b/src/routes/console/project-[project]/functions/+layout.ts @@ -11,7 +11,7 @@ export const load: LayoutLoad = async ({ depends }) => { const [runtimesList, installations, specifications] = await Promise.all([ sdk.forProject.functions.listRuntimes(), sdk.forProject.vcs.listInstallations([Query.limit(100)]), - sdk.forProject.sizesFunctions.getSpecifications() + sdk.forProject.functions.getSpecifications() ]); return { diff --git a/src/routes/console/project-[project]/functions/function-[function]/settings/updateRuntime.svelte b/src/routes/console/project-[project]/functions/function-[function]/settings/updateRuntime.svelte index 4500b968d..21b6ded4f 100644 --- a/src/routes/console/project-[project]/functions/function-[function]/settings/updateRuntime.svelte +++ b/src/routes/console/project-[project]/functions/function-[function]/settings/updateRuntime.svelte @@ -35,7 +35,7 @@ specificationOptions = allowedSpecifications.map((size) => ({ label: `${size.cpus} CPU, ${size.memory} MB RAM` + - (size.plan && !size.enabled ? ` (${size.plan} and higher)` : ''), + (!size.enabled ? ` (Upgrade to use this)` : ''), value: size.slug, disabled: !size.enabled })); @@ -46,7 +46,7 @@ if (!isValueOfStringEnum(Runtime, runtime)) { throw new Error(`Invalid runtime: ${runtime}`); } - await sdk.forProject.sizesFunctions.update( + await sdk.forProject.functions.update( functionId, $func.name, runtime, diff --git a/src/routes/console/project-[project]/functions/function-[function]/store.ts b/src/routes/console/project-[project]/functions/function-[function]/store.ts index ffe78b451..0bc01a1d4 100644 --- a/src/routes/console/project-[project]/functions/function-[function]/store.ts +++ b/src/routes/console/project-[project]/functions/function-[function]/store.ts @@ -1,9 +1,8 @@ import { page } from '$app/stores'; import { derived, writable, type Writable } from 'svelte/store'; import type { Models } from '@appwrite.io/console'; -import type { Func } from '$lib/sdk/functionsSpec'; -export const func = derived(page, ($page) => $page.data.function as Func); +export const func = derived(page, ($page) => $page.data.function as Models.Function); export const deploymentList = derived( page, ($page) => $page.data.deploymentList as Models.DeploymentList diff --git a/src/routes/console/project-[project]/functions/function-[function]/usage/[[period]]/+page.ts b/src/routes/console/project-[project]/functions/function-[function]/usage/[[period]]/+page.ts index 548b7ae41..1766c60a0 100644 --- a/src/routes/console/project-[project]/functions/function-[function]/usage/[[period]]/+page.ts +++ b/src/routes/console/project-[project]/functions/function-[function]/usage/[[period]]/+page.ts @@ -9,7 +9,7 @@ export const load: PageLoad = async ({ params }) => { const period = isValueOfStringEnum(FunctionUsageRange, params.period) ? params.period : FunctionUsageRange.ThirtyDays; - return sdk.forProject.sizesFunctions.getFunctionUsage(params.function, period); + return sdk.forProject.functions.getFunctionUsage(params.function, period); } catch (e) { error(e.code, e.message); } diff --git a/src/routes/console/project-[project]/functions/store.ts b/src/routes/console/project-[project]/functions/store.ts index b7074518f..e56f264ea 100644 --- a/src/routes/console/project-[project]/functions/store.ts +++ b/src/routes/console/project-[project]/functions/store.ts @@ -1,7 +1,6 @@ import { page } from '$app/stores'; import { derived } from 'svelte/store'; import type { Models } from '@appwrite.io/console'; -import type { Specification } from '$lib/sdk/functionsSpec'; export const runtimesList = derived( page, @@ -10,7 +9,7 @@ export const runtimesList = derived( export const specifications = derived( page, - async ($page) => (await $page.data.specifications.specifications) as Specification[] + async ($page) => (await $page.data.specifications.specifications) as Models.Specification[] ); export const baseRuntimesList = derived(runtimesList, async ($runtimesList) => {