From 0099beb416a57fed60281aa155db8504e184bca2 Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Tue, 16 Jul 2024 20:13:11 +0900 Subject: [PATCH] Remove variable runtime specs from 1.6.x --- src/lib/sdk/functionsSpec.ts | 292 ------------------ src/lib/stores/sdk.ts | 2 - .../project-[project]/functions/+layout.ts | 8 +- .../settings/updateRuntime.svelte | 53 +--- .../functions/function-[function]/store.ts | 3 +- .../project-[project]/functions/store.ts | 3 - 6 files changed, 11 insertions(+), 350 deletions(-) delete mode 100644 src/lib/sdk/functionsSpec.ts diff --git a/src/lib/sdk/functionsSpec.ts b/src/lib/sdk/functionsSpec.ts deleted file mode 100644 index a50679099..000000000 --- a/src/lib/sdk/functionsSpec.ts +++ /dev/null @@ -1,292 +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; - /** - * CPU limit - */ - cpus: number; - /** - * Memory limit - */ - memory: number; -}; - -export class SpecsFunctions { - client: Client; - - constructor(client: Client) { - this.client = client; - } - - async getSpecs(): Promise { - const path = '/functions/specs'; - - 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, - cpus?: number, - memory?: number - ): 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 cpus !== 'undefined') { - payload['cpus'] = cpus; - } - - if (typeof memory !== 'undefined') { - payload['memory'] = memory; - } - - const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call( - 'put', - uri, - { - 'content-type': 'application/json' - }, - payload - ); - } -} diff --git a/src/lib/stores/sdk.ts b/src/lib/stores/sdk.ts index ec3ca5328..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 { SpecsFunctions } 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), - specsFunctions: new SpecsFunctions(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 5be87b9cf..68ecb719d 100644 --- a/src/routes/console/project-[project]/functions/+layout.ts +++ b/src/routes/console/project-[project]/functions/+layout.ts @@ -8,17 +8,15 @@ import type { LayoutLoad } from './$types'; export const load: LayoutLoad = async ({ depends }) => { depends(Dependencies.FUNCTION_INSTALLATIONS); - const [runtimesList, installations, specs] = await Promise.all([ + const [runtimesList, installations] = await Promise.all([ sdk.forProject.functions.listRuntimes(), - sdk.forProject.vcs.listInstallations([Query.limit(100)]), - sdk.forProject.specsFunctions.getSpecs() + sdk.forProject.vcs.listInstallations([Query.limit(100)]) ]); return { header: Header, breadcrumbs: Breadcrumbs, runtimesList, - installations, - specs + installations }; }; 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 b88055ddf..8733e9442 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 @@ -10,47 +10,26 @@ import { onMount } from 'svelte'; import { func } from '../store'; import InputSelect from '$lib/elements/forms/inputSelect.svelte'; - import { runtimesList, specs } from '../../store'; + import { runtimesList } from '../../store'; import { isValueOfStringEnum } from '$lib/helpers/types'; import { Runtime } from '@appwrite.io/console'; const functionId = $page.params.function; let runtime: string = null; - let memory: number = null; - let cpus: number = null; let options = []; - let cpuOptions = []; - let memoryOptions = []; onMount(async () => { runtime ??= $func.runtime; - memory ??= $func.memory; - cpus ??= $func.cpus; let runtimes = await $runtimesList; - let allowedSpecs = await $specs; + + console.log(runtimes); + options = runtimes.runtimes.map((runtime) => ({ label: `${runtime.name} - ${runtime.version}`, value: runtime.$id })); - - memoryOptions = allowedSpecs.memory.map((memory) => - memory > 1024 - ? { - label: `${memory / 1024} GB`, - value: memory - } - : { - label: `${memory} MB`, - value: memory - } - ); - - cpuOptions = allowedSpecs.cpus.map((cpu) => ({ - label: cpu === 1 ? `${cpu} CPU Cores` : `${cpu} CPU Core`, - value: cpu - })); }); async function updateRuntime() { @@ -58,7 +37,7 @@ if (!isValueOfStringEnum(Runtime, runtime)) { throw new Error(`Invalid runtime: ${runtime}`); } - await sdk.forProject.specsFunctions.update( + await sdk.forProject.functions.update( functionId, $func.name, runtime, @@ -75,9 +54,7 @@ $func.providerRepositoryId || undefined, $func.providerBranch || undefined, $func.providerSilentMode || undefined, - $func.providerRootDirectory || undefined, - cpus, - memory + $func.providerRootDirectory || undefined ); await invalidate(Dependencies.FUNCTION); addNotification({ @@ -95,7 +72,7 @@ } $: isUpdateButtonEnabled = - runtime !== $func?.runtime || memory !== $func?.memory || cpus !== $func?.cpus; + runtime !== $func?.runtime;
@@ -112,22 +89,6 @@ {options} required hideRequired /> - - 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 18f03dd31..e5b2bbe56 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/store.ts b/src/routes/console/project-[project]/functions/store.ts index 396c5d584..3acf62136 100644 --- a/src/routes/console/project-[project]/functions/store.ts +++ b/src/routes/console/project-[project]/functions/store.ts @@ -1,15 +1,12 @@ import { page } from '$app/stores'; import { derived } from 'svelte/store'; import type { Models } from '@appwrite.io/console'; -import type { Specs } from '$lib/sdk/functionsSpec'; export const runtimesList = derived( page, async ($page) => (await $page.data.runtimesList) as Models.RuntimeList ); -export const specs = derived(page, async ($page) => (await $page.data.specs) as Specs); - export const baseRuntimesList = derived(runtimesList, async ($runtimesList) => { const baseRuntimes = new Map(); for (const runtime of (await $runtimesList).runtimes) {