Skip to content

Commit 1e7e199

Browse files
authored
Merge pull request #2922 from appwrite/chore-sdk-bump
feat: build + runtime specification controls for sites and functions
2 parents a90a0ea + 1499bcb commit 1e7e199

19 files changed

Lines changed: 174 additions & 76 deletions

File tree

bun.lock

Lines changed: 5 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
},
2121
"dependencies": {
2222
"@ai-sdk/svelte": "^1.1.24",
23-
"@appwrite.io/console": "https://pkg.vc/-/@appwrite/@appwrite.io/console@41152f5",
23+
"@appwrite.io/console": "https://pkg.vc/-/@appwrite/@appwrite.io/console@9163640",
2424
"@appwrite.io/pink-icons": "0.25.0",
2525
"@appwrite.io/pink-icons-svelte": "https://pkg.vc/-/@appwrite/@appwrite.io/pink-icons-svelte@bfe7ce3",
2626
"@appwrite.io/pink-legacy": "^1.0.3",
@@ -38,6 +38,7 @@
3838
"dayjs": "^1.11.13",
3939
"deep-equal": "^2.2.3",
4040
"echarts": "^5.6.0",
41+
"flatted": "^3.4.2",
4142
"ignore": "^6.0.2",
4243
"nanoid": "^5.1.5",
4344
"nanotar": "^0.1.1",
@@ -91,6 +92,6 @@
9192
"vite": "npm:rolldown-vite@latest",
9293
"minimatch": "10.2.3",
9394
"immutable": "^5.1.5",
94-
"flatted": "^3.4.0"
95+
"flatted": "^3.4.2"
9596
}
9697
}

src/lib/actions/analytics.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ export enum Submit {
314314
FunctionUpdateSchedule = 'submit_function_update_schedule',
315315
FunctionUpdateConfiguration = 'submit_function_update_configuration',
316316
FunctionUpdateLogging = 'submit_function_update_logging',
317+
FunctionUpdateResourceLimits = 'submit_function_update_resource_limits',
317318
FunctionUpdateTimeout = 'submit_function_update_timeout',
318319
FunctionUpdateEvents = 'submit_function_update_events',
319320
FunctionUpdateScopes = 'submit_function_key_update_scopes',
@@ -438,6 +439,7 @@ export enum Submit {
438439
SiteUpdateEvents = 'submit_site_update_events',
439440
SiteUpdateScopes = 'submit_site_key_update_scopes',
440441
SiteUpdateBuildSettings = 'submit_site_update_build_settings',
442+
SiteUpdateResourceLimits = 'submit_site_update_resource_limits',
441443
SiteUpdateSinglePageApplication = 'submit_site_update_single_page_application',
442444
SiteConnectRepo = 'submit_site_connect_repo',
443445
SiteRedeploy = 'submit_site_redeploy',

src/lib/stores/sdk.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
Tokens,
2424
TablesDB,
2525
Domains,
26+
Webhooks,
2627
/*DocumentsDB,*/
2728
Realtime,
2829
Organizations
@@ -137,7 +138,8 @@ const sdkForProject = {
137138
sites: new Sites(clientProject),
138139
tablesDB: new TablesDB(clientProject),
139140
/*documentsDB: new DocumentsDB(clientProject),*/
140-
console: new Console(clientProject) // for suggestions API
141+
console: new Console(clientProject), // for suggestions API
142+
webhooks: new Webhooks(clientProject)
141143
};
142144

143145
export const realtime = {

src/routes/(console)/project-[region]-[project]/functions/function-[function]/settings/+page.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,15 @@ export const load = async ({ params, depends, parent }) => {
55
depends(Dependencies.VARIABLES);
66
depends(Dependencies.FUNCTION);
77

8-
const { runtimesList, specificationsList } = await parent();
8+
const { runtimesList, specificationsList, function: fn } = await parent();
9+
10+
const enabledSpecs = specificationsList?.specifications?.filter((s) => s.enabled) ?? [];
11+
if (!enabledSpecs.some((s) => s.slug === fn.buildSpecification)) {
12+
fn.buildSpecification = enabledSpecs[0]?.slug;
13+
}
14+
if (!enabledSpecs.some((s) => s.slug === fn.runtimeSpecification)) {
15+
fn.runtimeSpecification = enabledSpecs[0]?.slug;
16+
}
917

1018
const [globalVariables, variables] = await Promise.all([
1119
sdk.forProject(params.region, params.project).projectApi.listVariables(),
@@ -36,6 +44,7 @@ export const load = async ({ params, depends, parent }) => {
3644
variables,
3745
globalVariables,
3846
runtimesList,
39-
specificationsList
47+
specificationsList,
48+
function: fn
4049
};
4150
};

src/routes/(console)/project-[region]-[project]/functions/function-[function]/settings/updateResourceLimits.svelte

Lines changed: 52 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
import { isValueOfStringEnum } from '$lib/helpers/types';
1010
import { Runtime, type Models, type Scopes } from '@appwrite.io/console';
1111
import Link from '$lib/elements/link.svelte';
12-
import { Alert } from '@appwrite.io/pink-svelte';
12+
import { Alert, Icon, Tooltip } from '@appwrite.io/pink-svelte';
13+
import { IconInfo } from '@appwrite.io/pink-icons-svelte';
1314
import { isStarterPlan, getChangePlanUrl } from '$lib/stores/billing';
1415
import { isCloud } from '$lib/system';
1516
import { organization } from '$lib/stores/organization';
@@ -18,11 +19,23 @@
1819
export let func: Models.Function;
1920
export let specs: Models.SpecificationList;
2021
21-
let specification = func.buildSpecification;
22-
let originalSpecification = func.buildSpecification;
23-
$: originalSpecification = func.buildSpecification;
22+
let buildSpecification = func.buildSpecification;
23+
let runtimeSpecification = func.runtimeSpecification;
24+
let originalBuild = func.buildSpecification;
25+
let originalRuntime = func.runtimeSpecification;
2426
25-
async function updateLogging() {
27+
let functionId: string | undefined = undefined;
28+
$: if (func.$id !== functionId) {
29+
functionId = func.$id;
30+
buildSpecification = func.buildSpecification;
31+
runtimeSpecification = func.runtimeSpecification;
32+
}
33+
$: {
34+
originalBuild = func.buildSpecification;
35+
originalRuntime = func.runtimeSpecification;
36+
}
37+
38+
async function updateResourceLimits() {
2639
try {
2740
if (!isValueOfStringEnum(Runtime, func.runtime)) {
2841
throw new Error(`Invalid runtime: ${func.runtime}`);
@@ -45,24 +58,23 @@
4558
providerBranch: func.providerBranch || undefined,
4659
providerSilentMode: func.providerSilentMode || undefined,
4760
providerRootDirectory: func.providerRootDirectory || undefined,
48-
buildSpecification: specification || undefined
61+
buildSpecification: buildSpecification || undefined,
62+
runtimeSpecification: runtimeSpecification || undefined
4963
});
5064
5165
await invalidate(Dependencies.FUNCTION);
5266
53-
originalSpecification = specification;
54-
5567
addNotification({
5668
type: 'success',
5769
message: 'Resource limits have been updated'
5870
});
59-
trackEvent(Submit.FunctionUpdateLogging);
71+
trackEvent(Submit.FunctionUpdateResourceLimits);
6072
} catch (error) {
6173
addNotification({
6274
type: 'error',
6375
message: error.message
6476
});
65-
trackError(error, Submit.FunctionUpdateLogging);
77+
trackError(error, Submit.FunctionUpdateResourceLimits);
6678
}
6779
}
6880
@@ -73,7 +85,7 @@
7385
}));
7486
</script>
7587

76-
<Form onSubmit={updateLogging}>
88+
<Form onSubmit={updateResourceLimits}>
7789
<CardGrid>
7890
<svelte:fragment slot="title">Resource limits</svelte:fragment>
7991
Define your function's compute specifications, including CPU and memory, to optimize performance
@@ -84,12 +96,33 @@
8496
</Link>.
8597
<svelte:fragment slot="aside">
8698
<InputSelect
87-
label="CPU and memory"
88-
id="resources"
99+
label="Build specification"
100+
id="build-specification"
101+
required
102+
disabled={options.length < 1}
103+
bind:value={buildSpecification}
104+
{options}>
105+
<Tooltip slot="info">
106+
<Icon icon={IconInfo} size="s" />
107+
<span slot="tooltip">
108+
CPU and memory used when building and packaging your function deployment.
109+
</span>
110+
</Tooltip>
111+
</InputSelect>
112+
<InputSelect
113+
label="Runtime specification"
114+
id="runtime-specification"
89115
required
90116
disabled={options.length < 1}
91-
bind:value={specification}
92-
{options} />
117+
bind:value={runtimeSpecification}
118+
{options}>
119+
<Tooltip slot="info">
120+
<Icon icon={IconInfo} size="s" />
121+
<span slot="tooltip">
122+
CPU and memory available to each function execution at runtime.
123+
</span>
124+
</Tooltip>
125+
</InputSelect>
93126

94127
<!-- always show upgrade on starters -->
95128
{@const isStarter = isStarterPlan($organization.billingPlanId)}
@@ -104,7 +137,10 @@
104137
</svelte:fragment>
105138

106139
<svelte:fragment slot="actions">
107-
<Button disabled={originalSpecification === specification} submit>Update</Button>
140+
<Button
141+
disabled={originalBuild === buildSpecification &&
142+
originalRuntime === runtimeSpecification}
143+
submit>Update</Button>
108144
</svelte:fragment>
109145
</CardGrid>
110146
</Form>

src/routes/(console)/project-[region]-[project]/settings/webhooks/+page.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ export const load: PageLoad = async ({ params, url, depends }) => {
1010

1111
return {
1212
page,
13-
webhooks: await sdk.forConsole.projects.listWebhooks({ projectId: params.project })
13+
webhooks: await sdk.forProject(params.region, params.project).webhooks.list()
1414
};
1515
};

src/routes/(console)/project-[region]-[project]/settings/webhooks/[webhook]/+layout.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ export const load: LayoutLoad = async ({ params, depends }) => {
1010
return {
1111
header: Header,
1212
breadcrumbs: Breadcrumbs,
13-
webhook: await sdk.forConsole.projects.getWebhook({
14-
projectId: params.project,
13+
webhook: await sdk.forProject(params.region, params.project).webhooks.get({
1514
webhookId: params.webhook
1615
})
1716
};

src/routes/(console)/project-[region]-[project]/settings/webhooks/[webhook]/delete.svelte

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<script lang="ts">
22
import { goto, invalidate } from '$app/navigation';
3+
import { page } from '$app/state';
34
import { base } from '$app/paths';
45
import { Submit, trackEvent, trackError } from '$lib/actions/analytics';
56
import Confirm from '$lib/components/confirm.svelte';
@@ -14,8 +15,7 @@
1415
let error: string;
1516
async function handleDelete() {
1617
try {
17-
await sdk.forConsole.projects.deleteWebhook({
18-
projectId: $project.$id,
18+
await sdk.forProject(page.params.region, $project.$id).webhooks.delete({
1919
webhookId: $webhook.$id
2020
});
2121
await invalidate(Dependencies.WEBHOOKS);
@@ -25,7 +25,7 @@
2525
message: `${$webhook.name} has been deleted`
2626
});
2727
trackEvent(Submit.WebhookDelete);
28-
await goto(`${base}/project-${$project.region}-${$project.$id}/settings/webhooks`);
28+
await goto(`${base}/project-${page.params.region}-${$project.$id}/settings/webhooks`);
2929
} catch (e) {
3030
error = e.message;
3131
trackError(e, Submit.WebhookDelete);

src/routes/(console)/project-[region]-[project]/settings/webhooks/[webhook]/details.svelte

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525
2626
async function setEnabled() {
2727
try {
28-
await sdk.forConsole.projects.updateWebhook({
29-
projectId,
28+
await sdk.forProject(page.params.region, projectId).webhooks.update({
3029
webhookId: $webhook.$id,
3130
name: $webhook.name,
3231
events: $webhook.events,

0 commit comments

Comments
 (0)