Skip to content

Commit

Permalink
Merge pull request #733 from benmccann/sveltekit2
Browse files Browse the repository at this point in the history
upgrade to SvelteKit 2
  • Loading branch information
TorstenDittmann authored Jan 30, 2024
2 parents 5da7952 + e0c0975 commit e11d985
Show file tree
Hide file tree
Showing 31 changed files with 1,261 additions and 943 deletions.
2,095 changes: 1,215 additions & 880 deletions package-lock.json

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@
"@melt-ui/pp": "^0.1.4",
"@melt-ui/svelte": "^0.61.2",
"@playwright/test": "^1.37.1",
"@sveltejs/adapter-static": "^2.0.3",
"@sveltejs/kit": "^1.24.0",
"@sveltejs/vite-plugin-svelte": "^2.4.5",
"@sveltejs/adapter-static": "^3.0.1",
"@sveltejs/kit": "^2.3.4",
"@sveltejs/vite-plugin-svelte": "^3.0.1",
"@testing-library/dom": "^9.0.1",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/svelte": "^4.0.3",
Expand All @@ -55,7 +55,7 @@
"@types/prismjs": "^1.26.0",
"@typescript-eslint/eslint-plugin": "^6.5.0",
"@typescript-eslint/parser": "^6.5.0",
"@vitest/ui": "^0.29.7",
"@vitest/ui": "^1.2.1",
"eslint": "^8.48.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-svelte": "^2.33.0",
Expand All @@ -64,15 +64,15 @@
"prettier": "^3.2.2",
"prettier-plugin-svelte": "^3.1.2",
"sass": "^1.66.1",
"svelte": "^4.2.0",
"svelte": "^4.2.9",
"svelte-check": "^3.5.1",
"svelte-jester": "^2.3.2",
"svelte-preprocess": "^5.0.4",
"svelte-sequential-preprocessor": "^2.0.1",
"tslib": "^2.6.2",
"typescript": "^5.2.2",
"vite": "^4.4.9",
"vitest": "^0.29.7"
"vite": "^5.0.11",
"vitest": "^1.2.1"
},
"type": "module"
}
4 changes: 2 additions & 2 deletions src/routes/+layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const load: LayoutLoad = async ({ depends, url }) => {

return {
account,
organizations: sdk.forConsole.teams.list()
organizations: await sdk.forConsole.teams.list()
};
} catch (error) {
const acceptedRoutes = [
Expand All @@ -41,7 +41,7 @@ export const load: LayoutLoad = async ({ depends, url }) => {
const redirectUrl =
url.pathname && url.pathname !== '/' ? `redirect=${url.pathname}` : '';
const path = url.search ? `${url.search}&${redirectUrl}` : `?${redirectUrl}`;
throw redirect(303, `/login${path}`);
redirect(303, `/login${path}`);
}
}
};
6 changes: 2 additions & 4 deletions src/routes/+page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import type { PageLoad } from './$types';
import { user } from '$lib/stores/user';

export const load: PageLoad = async () => {
if (user) {
return;
} else {
throw redirect(302, `${base}/login`);
if (!user) {
redirect(302, `${base}/login`);
}
};
3 changes: 1 addition & 2 deletions src/routes/auth/magic-url/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<script lang="ts">
import { goto } from '$app/navigation';
import { page } from '$app/stores';
import { Heading } from '$lib/components';
import { Account, Client } from '@appwrite.io/console';
Expand All @@ -18,7 +17,7 @@
const secret = $page.url.searchParams.get('secret');
await account.updateMagicURLSession(userId, secret);
await goto(`appwrite-callback-${projectId}://${$page.url.search}`);
window.location.href = `appwrite-callback-${projectId}://${$page.url.search}`;
});
</script>

Expand Down
9 changes: 2 additions & 7 deletions src/routes/auth/oauth2/failure/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
<script lang="ts">
import { goto } from '$app/navigation';
import { page } from '$app/stores';
import { Heading } from '$lib/components';
const project = $page.url.searchParams.get('project');
const link = `appwrite-callback-${project}://${$page.url.search}`;
const redirect = new Promise((resolve, reject) => {
const redirect = new Promise((_resolve, reject) => {
if (!project) {
reject('no-project');
}
// this timeout is needed because goto does not
// throw an exception if the redirect does not work
setTimeout(() => reject('timeout'), 500);
// goto will resolve on successful redirect
goto(link).then(resolve);
window.location.href = link;
});
</script>

Expand Down
9 changes: 2 additions & 7 deletions src/routes/auth/oauth2/success/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
<script lang="ts">
import { goto } from '$app/navigation';
import { page } from '$app/stores';
import { Heading } from '$lib/components';
const project = $page.url.searchParams.get('project');
const link = `appwrite-callback-${project}://${$page.url.search}`;
const redirect = new Promise((resolve, reject) => {
const redirect = new Promise((_resolve, reject) => {
if (!project) {
reject('no-project');
}
// this timeout is needed because goto does not
// throw an exception if the redirect does not work
setTimeout(() => reject('timeout'), 500);
// goto will resolve on successful redirect
goto(link).then(resolve);
window.location.href = link;
});
</script>

Expand Down
6 changes: 3 additions & 3 deletions src/routes/card/+page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { isCloud } from '$lib/system';
import { redirect } from '@sveltejs/kit';

export async function load({ parent }) {
if (!isCloud) throw redirect(303, '/');
if (!isCloud) redirect(303, '/');
const { account } = await parent();
if (!account) throw redirect(303, '/login');
if (!account) redirect(303, '/login');

throw redirect(303, `/card/${account.$id}`);
redirect(303, `/card/${account.$id}`);
}
4 changes: 2 additions & 2 deletions src/routes/card/[uid]/+page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export async function load({ params, url, parent }) {
const res = await fetch(frontImg);

if (!res.ok) {
throw redirect(303, '/');
redirect(303, '/');
}

return {
Expand All @@ -53,6 +53,6 @@ export async function load({ params, url, parent }) {
};
} catch (e) {
console.error(e);
throw redirect(303, '/');
redirect(303, '/');
}
}
6 changes: 3 additions & 3 deletions src/routes/console/+page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ export const load: PageLoad = async ({ parent, url }) => {
if (organizations.total) {
const teamId = account.prefs.organization ?? organizations.teams[0].$id;
if (!teamId) {
throw redirect(303, `${base}/console/account/organizations${url.search ?? ''}`);
} else throw redirect(303, `${base}/console/organization-${teamId}${url.search ?? ''}`);
redirect(303, `${base}/console/account/organizations${url.search ?? ''}`);
} else redirect(303, `${base}/console/organization-${teamId}${url.search ?? ''}`);
} else {
throw redirect(303, `${base}/console/onboarding${url.search ?? ''}`);
redirect(303, `${base}/console/onboarding${url.search ?? ''}`);
}
};
2 changes: 1 addition & 1 deletion src/routes/console/organization-[organization]/+layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ export const load: LayoutLoad = async ({ params, depends }) => {
const newPrefs = { ...prefs, organization: null };
sdk.forConsole.account.updatePrefs(newPrefs);
localStorage.removeItem('organization');
throw error(e.code, e.message);
error(e.code, e.message);
}
};
2 changes: 1 addition & 1 deletion src/routes/console/project-[project]/+layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ export const load: LayoutLoad = async ({ params, depends }) => {
organization: await sdk.forConsole.teams.get(project.teamId)
};
} catch (e) {
throw error(e.code, e.message);
error(e.code, e.message);
}
};
2 changes: 1 addition & 1 deletion src/routes/console/project-[project]/+page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import { base } from '$app/paths';
import type { PageLoad } from './$types';

export const load: PageLoad = async ({ params }) => {
throw redirect(302, `${base}/console/project-${params.project}/overview`);
redirect(302, `${base}/console/project-${params.project}/overview`);
};
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ export const load: LayoutLoad = async ({ params, depends }) => {
team: await sdk.forProject.teams.get(params.team)
};
} catch (e) {
throw error(e.code, e.message);
error(e.code, e.message);
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ export const load: PageLoad = async ({ params }) => {
users: response.users as Metric[]
};
} catch (e) {
throw error(e.code, e.message);
error(e.code, e.message);
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ export const load: LayoutLoad = async ({ params, depends }) => {
user: await sdk.forProject.users.get(params.user)
};
} catch (e) {
throw error(e.code, e.message);
error(e.code, e.message);
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ export const load: LayoutLoad = async ({ params, depends }) => {
database: await sdk.forProject.databases.get(params.database)
};
} catch (e) {
throw error(e.code, e.message);
error(e.code, e.message);
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ export const load: LayoutLoad = async ({ params, depends }) => {
])
};
} catch (e) {
throw error(e.code, e.message);
error(e.code, e.message);
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ export const load: LayoutLoad = async ({ params, parent, depends }) => {
document
};
} catch (e) {
throw error(e.code, e.message);
error(e.code, e.message);
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ export const load: PageLoad = async ({ params }) => {
databases: response.databases as Metric[]
};
} catch (e) {
throw error(e.code, e.message);
error(e.code, e.message);
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ export const load: LayoutLoad = async ({ params, depends }) => {
])
};
} catch (e) {
throw error(e.code, e.message);
error(e.code, e.message);
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ export const load: PageLoad = async ({ params }) => {
executions: response.executions as Metric[]
};
} catch (e) {
throw error(e.code, e.message);
error(e.code, e.message);
}
};
4 changes: 2 additions & 2 deletions src/routes/console/project-[project]/overview/+page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { selectedTab } from './store';

export const load: PageLoad = async ({ params }) => {
if (get(selectedTab) === 'keys') {
throw redirect(302, `${base}/console/project-${params.project}/overview/keys`);
redirect(302, `${base}/console/project-${params.project}/overview/keys`);
} else {
throw redirect(302, `${base}/console/project-${params.project}/overview/platforms`);
redirect(302, `${base}/console/project-${params.project}/overview/platforms`);
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ export const load: LayoutLoad = async ({ params, depends }) => {
webhook: await sdk.forConsole.projects.getWebhook(params.project, params.webhook)
};
} catch (e) {
throw error(e.code, e.message);
error(e.code, e.message);
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ export const load: LayoutLoad = async ({ params, depends }) => {
bucket: await sdk.forProject.storage.getBucket(params.bucket)
};
} catch (e) {
throw error(e.code, e.message);
error(e.code, e.message);
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ export const load: LayoutLoad = async ({ params, depends }) => {
file: await sdk.forProject.storage.getFile(params.bucket, params.file)
};
} catch (e) {
throw error(e.code, e.message);
error(e.code, e.message);
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ export const load: PageLoad = async ({ params }) => {
buckets: response.buckets as Metric[]
};
} catch (e) {
throw error(e.code, e.message);
error(e.code, e.message);
}
};
4 changes: 2 additions & 2 deletions src/routes/hackathon/+page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { isCloud } from '$lib/system';
import { redirect } from '@sveltejs/kit';

export async function load({ parent }) {
if (!isCloud) throw redirect(303, '/');
if (!isCloud) redirect(303, '/');
const { account } = await parent();
if (!account) throw redirect(303, '/login');
if (!account) redirect(303, '/login');
}
2 changes: 1 addition & 1 deletion src/routes/register/invite/+layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ import type { LayoutLoad } from './$types';

export const load: LayoutLoad = async () => {
if (isSelfHosted) {
throw error(501, 'Not available in self hosted.');
error(501, 'Not available in self hosted.');
}
};
1 change: 0 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"module": "ESNext",
"target": "ESNext",
"moduleResolution": "Node",
"importsNotUsedAsValues": "error",
"noUncheckedIndexedAccess": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
Expand Down
5 changes: 1 addition & 4 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ const config = defineConfig({
define: {
'import.meta.env.VERCEL_ANALYTICS_ID': JSON.stringify(process.env.VERCEL_ANALYTICS_ID)
},
legacy: {
buildSsrCjsExternalHeuristics: true
},
server: {
port: 3000
}
Expand All @@ -36,7 +33,7 @@ const testConfig = defineConfig({
include: ['tests/unit/**/*.test.ts'],
environment: 'jsdom',
globals: true,
threads: true,
pool: 'threads',
setupFiles: ['./tests/unit/setup.ts'],
deps: {
inline: ['@analytics/type-utils']
Expand Down

0 comments on commit e11d985

Please sign in to comment.