Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: sdk context #1551

Draft
wants to merge 6 commits into
base: feat-support-multi-region
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 2 additions & 2 deletions src/lib/commandCenter/panels/createAttribute.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
import { initCreateAttribute } from '$routes/(console)/project-[project]/databases/database-[database]/collection-[collection]/+layout.svelte';
import { attributeOptions } from '$routes/(console)/project-[project]/databases/database-[database]/collection-[collection]/attributes/store';
import { initCreateAttribute } from '$routes/(console)/project-[region]-[project]/databases/database-[database]/collection-[collection]/+layout.svelte';
import { attributeOptions } from '$routes/(console)/project-[region]-[project]/databases/database-[database]/collection-[collection]/attributes/store';
import Template from './template.svelte';

let search = '';
Expand Down
8 changes: 4 additions & 4 deletions src/lib/commandCenter/panels/createMessage.svelte
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<script lang="ts">
import { providers } from '$routes/(console)/project-[project]/messaging/providers/store';
import { providers } from '$routes/(console)/project-[region]-[project]/messaging/providers/store';
import {
messageParams,
providerType,
targetsById
} from '$routes/(console)/project-[project]/messaging/wizard/store';
} from '$routes/(console)/project-[region]-[project]/messaging/wizard/store';
import { MessagingProviderType } from '@appwrite.io/console';
import Template from './template.svelte';
import { wizard } from '$lib/stores/wizard';
import Create from '$routes/(console)/project-[project]/messaging/create.svelte';
import { topicsById } from '$routes/(console)/project-[project]/messaging/store';
import Create from '$routes/(console)/project-[region]-[project]/messaging/create.svelte';
import { topicsById } from '$routes/(console)/project-[region]-[project]/messaging/store';

let search = '';

Expand Down
2 changes: 1 addition & 1 deletion src/lib/commandCenter/panels/platforms.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import {
Platform,
addPlatform
} from '$routes/(console)/project-[project]/overview/platforms/+page.svelte';
} from '$routes/(console)/project-[region]-[project]/overview/platforms/+page.svelte';
import Template from './template.svelte';

let search = '';
Expand Down
20 changes: 13 additions & 7 deletions src/lib/commandCenter/searchers/buckets.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { goto } from '$app/navigation';
import { sdk } from '$lib/stores/sdk';
import { project } from '$routes/(console)/project-[project]/store';
import { project } from '$routes/(console)/project-[region]-[project]/store';
import { Query, type Models } from '@appwrite.io/console';
import { get } from 'svelte/store';
import type { Command, Searcher } from '../commands';
import { addSubPanel } from '../subPanels';
import { FilesPanel } from '../panels';
import { base } from '$app/paths';
import { page } from '$app/stores';

const getBucketCommand = (bucket: Models.Bucket, projectId: string) => {
return {
Expand All @@ -20,9 +21,12 @@ const getBucketCommand = (bucket: Models.Bucket, projectId: string) => {
};

export const bucketSearcher = (async (query: string) => {
const { buckets } = await sdk.forProject.storage.listBuckets([Query.orderDesc('$createdAt')]);

const $page = get(page);
const $project = get(project);
const { buckets } = await sdk
.forProject($page.params.region, $page.params.project)
.storage.listBuckets([Query.orderDesc('$createdAt')]);

const filtered = buckets.filter((bucket) => bucket.name.includes(query));

if (filtered.length === 1) {
Expand All @@ -32,7 +36,9 @@ export const bucketSearcher = (async (query: string) => {
{
label: 'Find files',
async callback() {
await goto(`${base}/project-${$project.$id}/storage/bucket-${bucket.$id}`);
await goto(
`${base}/project-${$project.region}-${$project.$id}/storage/bucket-${bucket.$id}`
);
addSubPanel(FilesPanel);
},
group: 'buckets',
Expand All @@ -44,7 +50,7 @@ export const bucketSearcher = (async (query: string) => {
label: 'Permissions',
async callback() {
await goto(
`${base}/project-${$project.$id}/storage/bucket-${bucket.$id}/settings#permissions`
`${base}/project-${$project.region}-${$project.$id}/storage/bucket-${bucket.$id}/settings#permissions`
);
scrollBy({ top: -100 });
},
Expand All @@ -56,7 +62,7 @@ export const bucketSearcher = (async (query: string) => {
label: 'Extensions',
async callback() {
await goto(
`${base}/project-${$project.$id}/storage/bucket-${bucket.$id}/settings#extensions`
`${base}/project-${$project.region}-${$project.$id}/storage/bucket-${bucket.$id}/settings#extensions`
);
},
group: 'buckets',
Expand All @@ -67,7 +73,7 @@ export const bucketSearcher = (async (query: string) => {
label: 'File Security',
async callback() {
await goto(
`${base}/project-${$project.$id}/storage/bucket-${bucket.$id}/settings#file-security`
`${base}/project-${$project.region}-${$project.$id}/storage/bucket-${bucket.$id}/settings#file-security`
);
scrollBy({ top: -100 });
},
Expand Down
10 changes: 7 additions & 3 deletions src/lib/commandCenter/searchers/collections.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import { goto } from '$app/navigation';
import { database } from '$routes/(console)/project-[project]/databases/database-[database]/store';
import { project } from '$routes/(console)/project-[project]/store';
import { database } from '$routes/(console)/project-[region]-[project]/databases/database-[database]/store';
import { project } from '$routes/(console)/project-[region]-[project]/store';
import { get } from 'svelte/store';
import type { Searcher } from '../commands';
import { sdk } from '$lib/stores/sdk';
import { base } from '$app/paths';
import { page } from '$app/stores';

export const collectionsSearcher = (async (query: string) => {
const databaseId = get(database).$id;
const { collections } = await sdk.forProject.databases.listCollections(databaseId);
const $page = get(page);
const { collections } = await sdk
.forProject($page.params.region, $page.params.project)
.databases.listCollections(databaseId);

const projectId = get(project).$id;
return collections
Expand Down
8 changes: 6 additions & 2 deletions src/lib/commandCenter/searchers/databases.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { goto } from '$app/navigation';
import { project } from '$routes/(console)/project-[project]/store';
import { project } from '$routes/(console)/project-[region]-[project]/store';
import { get } from 'svelte/store';
import type { Searcher } from '../commands';
import { sdk } from '$lib/stores/sdk';
import { base } from '$app/paths';
import { page } from '$app/stores';

export const dbSearcher = (async (query: string) => {
const { databases } = await sdk.forProject.databases.list();
const $page = get(page);
const { databases } = await sdk
.forProject($page.params.region, $page.params.project)
.databases.list();

return databases
.filter((db) => db.name.toLowerCase().includes(query.toLowerCase()))
Expand Down
18 changes: 10 additions & 8 deletions src/lib/commandCenter/searchers/files.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
import { sdk } from '$lib/stores/sdk';
import { get } from 'svelte/store';
import type { Searcher } from '../commands';
import { bucket } from '$routes/(console)/project-[project]/storage/bucket-[bucket]/store';
import { bucket } from '$routes/(console)/project-[region]-[project]/storage/bucket-[bucket]/store';
import { Query } from '@appwrite.io/console';
import { goto } from '$app/navigation';
import { project } from '$routes/(console)/project-[project]/store';
import { project } from '$routes/(console)/project-[region]-[project]/store';
import { base } from '$app/paths';
import { page } from '$app/stores';

export const fileSearcher = (async (query: string) => {
const $bucket = get(bucket);
const $project = get(project);
const $page = get(page);

const { files } = await sdk.forProject.storage.listFiles(
$bucket.$id,
[Query.orderDesc('')],
query || undefined
);
const { files } = await sdk
.forProject($page.params.region, $page.params.project)
.storage.listFiles($bucket.$id, [Query.orderDesc('')], query || undefined);

return files.map((file) => ({
label: file.name,
callback: () => {
goto(`${base}/project-${$project.$id}/storage/bucket-${$bucket.$id}/file-${file.$id}`);
goto(
`${base}/project-${$project.region}-${$project.$id}/storage/bucket-${$bucket.$id}/file-${file.$id}`
);
},
icon: 'document',
group: 'files'
Expand Down
10 changes: 6 additions & 4 deletions src/lib/commandCenter/searchers/functions.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { goto } from '$app/navigation';
import { sdk } from '$lib/stores/sdk';
import { project } from '$routes/(console)/project-[project]/store';
import { project } from '$routes/(console)/project-[region]-[project]/store';
import { get } from 'svelte/store';
import type { Searcher } from '../commands';
import type { Models } from '@appwrite.io/console';
import { page } from '$app/stores';
import { showCreateDeployment } from '$routes/(console)/project-[project]/functions/function-[function]/store';
import { showCreateDeployment } from '$routes/(console)/project-[region]-[project]/functions/function-[function]/store';
import { base } from '$app/paths';

const getFunctionCommand = (fn: Models.Function, projectId: string) => {
Expand All @@ -20,9 +20,11 @@ const getFunctionCommand = (fn: Models.Function, projectId: string) => {
};

export const functionsSearcher = (async (query: string) => {
const { functions } = await sdk.forProject.functions.list();

const $page = get(page);
const projectId = get(project).$id;
const { functions } = await sdk
.forProject($page.params.region, $page.params.project)
.functions.list();

const filtered = functions.filter((fn) => fn.name.toLowerCase().includes(query.toLowerCase()));

Expand Down
9 changes: 6 additions & 3 deletions src/lib/commandCenter/searchers/messages.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { goto } from '$app/navigation';
import { project } from '$routes/(console)/project-[project]/store';
import { project } from '$routes/(console)/project-[region]-[project]/store';
import { get } from 'svelte/store';
import { type Searcher } from '../commands';
import { sdk } from '$lib/stores/sdk';
import { MessagingProviderType } from '@appwrite.io/console';
import { base } from '$app/paths';
import { page } from '$app/stores';

const getLabel = (message) => {
switch (message.providerType) {
Expand Down Expand Up @@ -33,9 +34,11 @@ const getIcon = (message) => {
};

export const messagesSearcher = (async (query: string) => {
const { messages } = await sdk.forProject.messaging.listMessages([], query || undefined);

const $page = get(page);
const projectId = get(project).$id;
const { messages } = await sdk
.forProject($page.params.region, $page.params.project)
.messaging.listMessages([], query || undefined);

return messages
.filter((message) => getLabel(message).toLowerCase().includes(query.toLowerCase()))
Expand Down
2 changes: 1 addition & 1 deletion src/lib/commandCenter/searchers/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const projectsSearcher = (async (query: string) => {
return {
label: project.name,
callback: () => {
goto(`${base}/project-${project.$id}`);
goto(`${base}/project-${project.region}-${project.$id}`);
},
group: 'projects'
} as const;
Expand Down
11 changes: 7 additions & 4 deletions src/lib/commandCenter/searchers/providers.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
import { goto } from '$app/navigation';
import { project } from '$routes/(console)/project-[project]/store';
import { project } from '$routes/(console)/project-[region]-[project]/store';
import { get } from 'svelte/store';
import type { Searcher } from '../commands';
import { sdk } from '$lib/stores/sdk';
import { getProviderDisplayNameAndIcon } from '$routes/(console)/project-[project]/messaging/provider.svelte';
import { getProviderDisplayNameAndIcon } from '$routes/(console)/project-[region]-[project]/messaging/provider.svelte';
import { base } from '$app/paths';
import { page } from '$app/stores';

const getIcon = (provider: string) => {
const { icon } = getProviderDisplayNameAndIcon(provider);
return icon;
};

export const providersSearcher = (async (query: string) => {
const { providers } = await sdk.forProject.messaging.listProviders([], query || undefined);

const $page = get(page);
const projectId = get(project).$id;
const { providers } = await sdk
.forProject($page.params.region, $page.params.project)
.messaging.listProviders([], query || undefined);

return providers
.filter((provider) => provider.name.toLowerCase().includes(query.toLowerCase()))
Expand Down
8 changes: 6 additions & 2 deletions src/lib/commandCenter/searchers/teams.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { goto } from '$app/navigation';
import { sdk } from '$lib/stores/sdk';
import { project } from '$routes/(console)/project-[project]/store';
import { project } from '$routes/(console)/project-[region]-[project]/store';
import { get } from 'svelte/store';
import type { Command, Searcher } from '../commands';
import type { Models } from '@appwrite.io/console';
import { base } from '$app/paths';
import { page } from '$app/stores';

const getTeamCommand = (team: Models.Team<Models.Preferences>, projectId: string) =>
({
Expand All @@ -17,8 +18,11 @@ const getTeamCommand = (team: Models.Team<Models.Preferences>, projectId: string
}) satisfies Command;

export const teamSearcher = (async (query: string) => {
const { teams } = await sdk.forProject.teams.list([], query);
const $page = get(page);
const projectId = get(project).$id;
const { teams } = await sdk
.forProject($page.params.region, $page.params.project)
.teams.list([], query);

if (teams.length === 1) {
return [
Expand Down
9 changes: 6 additions & 3 deletions src/lib/commandCenter/searchers/topics.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { goto } from '$app/navigation';
import { project } from '$routes/(console)/project-[project]/store';
import { project } from '$routes/(console)/project-[region]-[project]/store';
import { get } from 'svelte/store';
import type { Searcher } from '../commands';
import { sdk } from '$lib/stores/sdk';
import { base } from '$app/paths';
import { page } from '$app/stores';

export const topicsSearcher = (async (query: string) => {
const { topics } = await sdk.forProject.messaging.listTopics([], query || undefined);

const $page = get(page);
const projectId = get(project).$id;
const { topics } = await sdk
.forProject($page.params.region, $page.params.project)
.messaging.listTopics([], query || undefined);

return topics
.filter((topic) => topic.name.toLowerCase().includes(query.toLowerCase()))
Expand Down
10 changes: 7 additions & 3 deletions src/lib/commandCenter/searchers/users.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { goto } from '$app/navigation';
import { sdk } from '$lib/stores/sdk';
import { project } from '$routes/(console)/project-[project]/store';
import { project } from '$routes/(console)/project-[region]-[project]/store';
import { get } from 'svelte/store';
import type { Command, Searcher } from '../commands';
import type { Models } from '@appwrite.io/console';
import { promptDeleteUser } from '$routes/(console)/project-[project]/auth/user-[user]/dangerZone.svelte';
import { promptDeleteUser } from '$routes/(console)/project-[region]-[project]/auth/user-[user]/dangerZone.svelte';
import { base } from '$app/paths';
import { page } from '$app/stores';

const getUserCommand = (user: Models.User<Models.Preferences>, projectId: string) =>
({
Expand All @@ -18,8 +19,11 @@ const getUserCommand = (user: Models.User<Models.Preferences>, projectId: string
}) satisfies Command;

export const userSearcher = (async (query: string) => {
const { users } = await sdk.forProject.users.list([], query || undefined);
const $page = get(page);
const projectId = get(project).$id;
const { users } = await sdk
.forProject($page.params.region, $page.params.project)
.users.list([], query || undefined);

if (users.length === 1) {
return [
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/avatarInitials.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
export let background: string | undefined = undefined;
export let color = 'black';

$: src = sdk.forConsole.avatars.getInitials(name, size * 2, size * 2, background).toString();
$: src = sdk.forConsole.avatars.getInitials(name, size * 2, size * 2, background);
</script>

<Avatar {name} {size} {src} {color} />
5 changes: 4 additions & 1 deletion src/lib/components/backupRestoreBox.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

function showRestoreNotification(newDatabaseId: string, newDatabaseName: string) {
if (newDatabaseId && newDatabaseName && lastDatabaseRestorationId !== newDatabaseId) {
const region = $page.params.region;
const project = $page.params.project;
lastDatabaseRestorationId = newDatabaseId;

Expand All @@ -44,7 +45,9 @@
{
name: 'View restored data',
method: () => {
goto(`${base}/project-${project}/databases/database-${newDatabaseId}`);
goto(
`${base}/project-${region}-${project}/databases/database-${newDatabaseId}`
);
}
}
]
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/bottomModalAlert.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import { BillingPlan } from '$lib/constants';
import { upgradeURL } from '$lib/stores/billing';
import { addBottomModalAlerts } from '$routes/(console)/bottomAlerts';
import { project } from '$routes/(console)/project-[project]/store';
import { project } from '$routes/(console)/project-[region]-[project]/store';
import { page } from '$app/stores';
import { trackEvent } from '$lib/actions/analytics';

Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/cardContainer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

$: planLimit = getServiceLimit(serviceId) || Infinity;

$: limit = preferences.get($page.route)?.limit ?? CARD_LIMIT;
$: limit = preferences.get($page.params.project, $page.route)?.limit ?? CARD_LIMIT;
</script>

<ul
Expand Down
Loading
Loading