Skip to content

Commit b31fde8

Browse files
abnegateclaude
andcommitted
Type scopes variables as Scopes[] instead of string[]
Move casts to the model boundary (where SDK models return string[]) and remove unnecessary casts at SDK call sites. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 5581e9c commit b31fde8

5 files changed

Lines changed: 15 additions & 14 deletions

File tree

src/routes/(console)/project-[region]-[project]/functions/create-function/deploy/+page.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
let specification = $state('');
4040
let runtime = $state<Runtime>();
4141
let installCommand = $state('');
42-
let selectedScopes = $state<string[]>([]);
42+
let selectedScopes = $state<Scopes[]>([]);
4343
let rootDir = $state(data.repository?.rootDirectory);
4444
let variables = $state<Array<{ key: string; value: string; secret: boolean }>>([]);
4545
@@ -103,7 +103,7 @@
103103
execute: execute ? ['any'] : undefined,
104104
entrypoint: entrypoint || undefined,
105105
commands: installCommand || undefined,
106-
scopes: selectedScopes?.length ? (selectedScopes as Scopes[]) : undefined,
106+
scopes: selectedScopes?.length ? selectedScopes : undefined,
107107
providerSilentMode: false,
108108
specification: specification || undefined
109109
});

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
import { Link } from '$lib/elements';
1717
1818
const functionId = page.params.function;
19-
let functionScopes: string[] = null;
19+
let functionScopes: ScopesType[] = null;
2020
2121
onMount(async () => {
22-
functionScopes ??= $func.scopes;
22+
functionScopes ??= $func.scopes as ScopesType[];
2323
});
2424
2525
async function updateScopes() {
@@ -39,7 +39,7 @@
3939
logging: $func.logging || undefined,
4040
entrypoint: $func.entrypoint || undefined,
4141
commands: $func.commands || undefined,
42-
scopes: (functionScopes as ScopesType[]) || undefined,
42+
scopes: functionScopes || undefined,
4343
installationId: $func.installationId || undefined,
4444
providerRepositoryId: $func.providerRepositoryId || undefined,
4545
providerBranch: $func.providerBranch || undefined,

src/routes/(console)/project-[region]-[project]/overview/(components)/create.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
let formComponent: Form;
2525
let isSubmitting = writable(false);
2626
27-
let scopes: string[] = [];
27+
let scopes: ScopesType[] = [];
2828
let name = '';
2929
let expire: string | null = null;
3030
@@ -33,7 +33,7 @@
3333
const { $id, secret } = await sdk.forConsole.projects.createKey({
3434
projectId,
3535
name,
36-
scopes: scopes as ScopesType[],
36+
scopes,
3737
expire: expire || undefined
3838
});
3939

src/routes/(console)/project-[region]-[project]/overview/(components)/keyDetails.svelte

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
export let keyType: 'api' | 'dev' = 'api';
2323
2424
let name: string = null;
25-
let scopes: string[] = null;
25+
let scopes: ScopesType[] = null;
2626
2727
let showDelete = false;
2828
const isApiKey = keyType === 'api';
@@ -33,7 +33,7 @@
3333
onMount(() => {
3434
name ??= key.name;
3535
if (isApiKey) {
36-
scopes ??= (key as Models.Key).scopes;
36+
scopes ??= (key as Models.Key).scopes as ScopesType[];
3737
}
3838
});
3939
@@ -48,7 +48,7 @@
4848
projectId: $project.$id,
4949
keyId: key.$id,
5050
name,
51-
scopes: scopes as ScopesType[],
51+
scopes,
5252
expire: key.expire
5353
});
5454
} else {
@@ -81,7 +81,7 @@
8181
projectId: $project.$id,
8282
keyId: key.$id,
8383
name: key.name,
84-
scopes: scopes as ScopesType[],
84+
scopes,
8585
expire: key.expire
8686
});
8787
await invalidate(Dependencies.KEY);

src/routes/(console)/project-[region]-[project]/overview/api-keys/scopes.svelte

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@
3232
import { symmetricDifference } from '$lib/helpers/array';
3333
import { scopes as allScopes, cloudOnlyBackupScopes } from '$lib/constants';
3434
import { Accordion, Divider, Layout, Selector } from '@appwrite.io/pink-svelte';
35+
import type { Scopes } from '@appwrite.io/console';
3536
36-
export let scopes: string[];
37+
export let scopes: Scopes[];
3738
3839
const baseFilteredScopes = allScopes.filter((scope) => {
3940
const val = scope.scope;
@@ -159,7 +160,7 @@
159160
});
160161
}
161162
162-
function generateSyncedScopes(activeScopesObj: Record<string, boolean>): string[] {
163+
function generateSyncedScopes(activeScopesObj: Record<string, boolean>): Scopes[] {
163164
const result = new Set<string>();
164165
165166
Object.entries(activeScopesObj).forEach(([scope, isActive]) => {
@@ -173,7 +174,7 @@
173174
}
174175
});
175176
176-
return Array.from(result);
177+
return Array.from(result) as Scopes[];
177178
}
178179
179180
$: {

0 commit comments

Comments
 (0)