Skip to content

Commit

Permalink
Updated to Sveltekit-typesafe-api
Browse files Browse the repository at this point in the history
  • Loading branch information
Laurent Stéphenne committed Jan 18, 2024
1 parent 0f4ee07 commit 845b67e
Show file tree
Hide file tree
Showing 23 changed files with 43 additions and 43 deletions.
Binary file modified bun.lockb
Binary file not shown.
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
"studio": "drizzle-kit studio"
},
"devDependencies": {
"@skeletonlabs/skeleton": "^2.7.1",
"@skeletonlabs/tw-plugin": "^0.3.1",
"@types/node": "^20.11.4",
"@typescript-eslint/eslint-plugin": "^6.19.0",
"@typescript-eslint/parser": "^6.19.0",
Expand All @@ -28,8 +26,7 @@
"prettier": "^3.2.2",
"prettier-plugin-organize-imports": "^3.2.4",
"prettier-plugin-svelte": "^3.1.2",
"prettier-plugin-tailwindcss": "^0.5.11",
"vite-plugin-tailwind-purgecss": "^0.2.0"
"prettier-plugin-tailwindcss": "^0.5.11"
},
"dependencies": {
"@dicebear/collection": "^6.0.4",
Expand All @@ -38,6 +35,8 @@
"@google-cloud/storage": "^7.7.0",
"@lucia-auth/adapter-mysql": "^2.1.0",
"@planetscale/database": "^1.13.0",
"@skeletonlabs/skeleton": "^2.7.1",
"@skeletonlabs/tw-plugin": "^0.3.1",
"@sveltejs/adapter-vercel": "^4.0.5",
"@sveltejs/kit": "^2.3.3",
"@tailwindcss/forms": "^0.5.7",
Expand All @@ -51,10 +50,11 @@
"sharp": "^0.33.2",
"svelte": "^4.2.8",
"svelte-check": "^3.6.3",
"sveltekit-api-fetch": "^3.3.0",
"sveltekit-superforms": "^1.13.3",
"sveltekit-typesafe-api": "^0.1.2",
"tailwindcss": "^3.4.1",
"vite": "^5.0.11",
"vite-plugin-tailwind-purgecss": "^0.2.0",
"zod": "^3.22.4"
},
"trustedDependencies": [
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/BookDetails.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { invalidate } from "$app/navigation";
import type { Book } from "$lib/types";
import Carousel from "$lib/components/Carousel.svelte";
import { api } from "sveltekit-api-fetch";
import { api } from "sveltekit-typesafe-api";
export let book: Book;
export let isDeletable: boolean = false;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/modals/AddFriendModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import friends from "$lib/stores/friends";
import { getModalStore, getToastStore } from "@skeletonlabs/skeleton";
import type { User } from "lucia";
import { api } from "sveltekit-api-fetch";
import { api } from "sveltekit-typesafe-api";
import UsersList from "./components/UsersList.svelte";
const modalStore = getModalStore();
Expand Down
2 changes: 1 addition & 1 deletion src/lib/stores/colorScheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import { browser } from "$app/environment";
import { writable } from "svelte/store";
import { api } from "sveltekit-api-fetch";
import { api } from "sveltekit-typesafe-api";

export type ColorScheme = "light" | "dark";

Expand Down
2 changes: 1 addition & 1 deletion src/lib/stores/friends.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { User } from "lucia";
import { writable } from "svelte/store";
import { api } from "sveltekit-api-fetch";
import { api } from "sveltekit-typesafe-api";

function createFriendsStore() {
const { subscribe, set } = writable<User[]>();
Expand Down
2 changes: 1 addition & 1 deletion src/lib/stores/groups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { Group } from "$lib/types";
import { getModalStore } from "@skeletonlabs/skeleton";
import type { User } from "lucia";
import { writable } from "svelte/store";
import { api } from "sveltekit-api-fetch";
import { api } from "sveltekit-typesafe-api";

function createGroupsStore() {
const { subscribe, set } = writable<Group[]>();
Expand Down
2 changes: 1 addition & 1 deletion src/lib/stores/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import type { Notification, NotificationKind } from "$lib/types";
import { writable } from "svelte/store";
import { api } from "sveltekit-api-fetch";
import { api } from "sveltekit-typesafe-api";

function createNotificationsStore() {
const { subscribe, set } = writable<Notification[]>();
Expand Down
2 changes: 1 addition & 1 deletion src/lib/stores/schedule.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { scheduleFromJson, type JsonSchedule } from "$lib/sanitization";
import type { Period, Schedule } from "$lib/types";
import { writable } from "svelte/store";
import { api } from "sveltekit-api-fetch";
import { api } from "sveltekit-typesafe-api";

function createScheduleStore() {
const { subscribe, set: setStore } = writable<Schedule>();
Expand Down
2 changes: 1 addition & 1 deletion src/lib/stores/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { browser } from "$app/environment";
import { invalidate } from "$app/navigation";
import type { User } from "lucia";
import { writable } from "svelte/store";
import { api } from "sveltekit-api-fetch";
import { api } from "sveltekit-typesafe-api";

function createUserStore() {
const { subscribe, set: setStore, update } = writable<User>();
Expand Down
4 changes: 2 additions & 2 deletions src/routes/(app)/livres/(acheter)/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
import Loader from "$lib/components/Loader.svelte";
import { api } from "sveltekit-api-fetch";
import { api } from "sveltekit-typesafe-api";
export let data;
Expand All @@ -11,7 +11,7 @@
function showMore() {
page += 1;
loadingMore = true;
api.GET("/api/books", {
api.GET("/api/books", {
searchParams: {
query: data.query,
codes: data.selectedCodes.at(0) ?? "",
Expand Down
4 changes: 2 additions & 2 deletions src/routes/api/books/+server.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import * as db from "$lib/server/db";
import { json } from "@sveltejs/kit";
import { apiValidate } from "sveltekit-api-fetch/server";
import { validate } from "sveltekit-typesafe-api/server";
import { z } from "zod";
import type { RequestHandler } from "./$types";

export const GET = (async ({ locals, url }) => {
const { data } = await apiValidate(url, {
const { data } = await validate(url, {
searchParams: z.object({
query: z.string(),
codes: z.string(),
Expand Down
6 changes: 3 additions & 3 deletions src/routes/api/friends/+server.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import * as db from "$lib/server/db";
import { userIdSchema } from "$lib/zod_schemas";
import { json } from "@sveltejs/kit";
import { apiValidate } from "sveltekit-api-fetch/server";
import { validate } from "sveltekit-typesafe-api/server";
import type { RequestHandler } from "./$types";

export const POST = (async ({ request, locals }) => {
const { data } = await apiValidate(request, { friendId: userIdSchema });
const { data } = await validate(request, { friendId: userIdSchema });

return json({
success: await db.sendNotification(locals.user, data.friendId, "FriendRequest"),
});
}) satisfies RequestHandler;

export const DELETE = (async ({ request, locals }) => {
const { data } = await apiValidate(request, { friendId: userIdSchema });
const { data } = await validate(request, { friendId: userIdSchema });

return json({
success: await db.deleteFriend(locals.user, data.friendId),
Expand Down
6 changes: 3 additions & 3 deletions src/routes/api/groups/+server.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import * as db from "$lib/server/db";
import { groupIdSchema, userIdSchema } from "$lib/zod_schemas";
import { error, json } from "@sveltejs/kit";
import { apiValidate } from "sveltekit-api-fetch/server";
import { validate } from "sveltekit-typesafe-api/server";
import { z } from "zod";
import type { RequestHandler } from "./$types";

export const POST = (async ({ request, locals }) => {
const { data } = await apiValidate(request, {
const { data } = await validate(request, {
name: z.string().min(3).max(80),
usersId: z.array(userIdSchema).min(2),
});
Expand All @@ -22,7 +22,7 @@ export const POST = (async ({ request, locals }) => {
}) satisfies RequestHandler;

export const DELETE = (async ({ request, locals }) => {
const { data } = await apiValidate(request, { groupId: groupIdSchema });
const { data } = await validate(request, { groupId: groupIdSchema });

return json({ success: await db.quitGroup(locals.user, data.groupId) });
}) satisfies RequestHandler;
Expand Down
4 changes: 2 additions & 2 deletions src/routes/api/groups/invite/+server.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import * as db from "$lib/server/db";
import { groupIdSchema, userIdSchema } from "$lib/zod_schemas";
import { error, json } from "@sveltejs/kit";
import { apiValidate } from "sveltekit-api-fetch/server";
import { validate } from "sveltekit-typesafe-api/server";
import { z } from "zod";
import type { RequestHandler } from "./$types";

export const POST = (async ({ request, locals }) => {
const { data } = await apiValidate(request, {
const { data } = await validate(request, {
groupId: groupIdSchema,
usersId: z.array(userIdSchema).min(1),
});
Expand Down
4 changes: 2 additions & 2 deletions src/routes/api/groups/members/+server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import * as db from "$lib/server/db";
import { groupIdSchema } from "$lib/zod_schemas";
import { error, json } from "@sveltejs/kit";
import type { User } from "lucia";
import { apiValidate } from "sveltekit-api-fetch/server";
import { validate } from "sveltekit-typesafe-api/server";
import type { RequestHandler } from "./$types";

export const POST = (async ({ locals, request }) => {
const { data } = await apiValidate(request, { groupId: groupIdSchema });
const { data } = await validate(request, { groupId: groupIdSchema });

const group = await db.getGroup(data.groupId);
if (!group || group.usersId.every((id) => locals.user.userId !== id)) {
Expand Down
4 changes: 2 additions & 2 deletions src/routes/api/groups/name/+server.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import * as db from "$lib/server/db";
import { groupIdSchema } from "$lib/zod_schemas";
import { json } from "@sveltejs/kit";
import { apiValidate } from "sveltekit-api-fetch/server";
import { validate } from "sveltekit-typesafe-api/server";
import { z } from "zod";
import type { RequestHandler } from "./$types";

export const POST = (async ({ request, locals }) => {
const { data } = await apiValidate(request, {
const { data } = await validate(request, {
groupId: groupIdSchema,
name: z.string().min(3).max(30),
});
Expand Down
6 changes: 3 additions & 3 deletions src/routes/api/notifications/+server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import * as db from "$lib/server/db";
import type { NotificationKind } from "$lib/types";
import { serialIdSchema, userIdSchema } from "$lib/zod_schemas";
import { json } from "@sveltejs/kit";
import { apiValidate } from "sveltekit-api-fetch/server";
import { validate } from "sveltekit-typesafe-api/server";
import { z } from "zod";
import type { RequestHandler } from "./$types";

export const POST = (async ({ request, locals }) => {
const { data } = await apiValidate(request, {
const { data } = await validate(request, {
kind: z.string().transform((k) => k as NotificationKind),
receiverId: userIdSchema,
});
Expand All @@ -18,7 +18,7 @@ export const POST = (async ({ request, locals }) => {
}) satisfies RequestHandler;

export const DELETE = (async ({ request, locals }) => {
const { data } = await apiValidate(request, { notificationId: serialIdSchema });
const { data } = await validate(request, { notificationId: serialIdSchema });

return json({ success: await db.deleteNotification(locals.user, data.notificationId) });
}) satisfies RequestHandler;
Expand Down
6 changes: 3 additions & 3 deletions src/routes/api/schedule/+server.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import * as db from "$lib/server/db";
import { periodSchema, serialIdSchema } from "$lib/zod_schemas";
import { json } from "@sveltejs/kit";
import { apiValidate } from "sveltekit-api-fetch/server";
import { validate } from "sveltekit-typesafe-api/server";
import type { RequestHandler } from "./$types";

export const POST = (async ({ request, locals }) => {
const { data } = await apiValidate(request, { period: periodSchema });
const { data } = await validate(request, { period: periodSchema });

return json({ success: await db.addPeriodsToSchedule(locals.user, [data.period]) });
}) satisfies RequestHandler;

export const DELETE = (async ({ request, locals }) => {
const { data } = await apiValidate(request, { periodId: serialIdSchema });
const { data } = await validate(request, { periodId: serialIdSchema });

return json({ success: await db.deletePeriodFromSchedule(locals.user, data.periodId) });
}) satisfies RequestHandler;
Expand Down
4 changes: 2 additions & 2 deletions src/routes/api/settings/colorScheme/+server.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { json } from "@sveltejs/kit";
import { apiValidate } from "sveltekit-api-fetch/server";
import { validate } from "sveltekit-typesafe-api/server";
import { z } from "zod";
import type { RequestHandler } from "./$types";

export const PUT = (async ({ request, cookies }) => {
const { data } = await apiValidate(request, { colorScheme: z.string().regex(/light|dark/) });
const { data } = await validate(request, { colorScheme: z.string().regex(/light|dark/) });

cookies.set("colorScheme", data.colorScheme, { path: "/" });
return json({ success: true });
Expand Down
4 changes: 2 additions & 2 deletions src/routes/api/user/avatar/+server.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import * as db from "$lib/server/db";
import { json } from "@sveltejs/kit";
import { apiValidate } from "sveltekit-api-fetch/server";
import { validate } from "sveltekit-typesafe-api/server";
import { z } from "zod";
import type { RequestHandler } from "./$types";

export const POST = (async ({ locals, request }) => {
const { data } = await apiValidate(request, { avatar: z.string().min(6) });
const { data } = await validate(request, { avatar: z.string().min(6) });

return json({ success: await db.updateUser(locals.user, { avatar: data.avatar }) });
}) satisfies RequestHandler;
4 changes: 2 additions & 2 deletions src/routes/api/user/search/+server.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import * as db from "$lib/server/db";
import { json } from "@sveltejs/kit";
import { apiValidate } from "sveltekit-api-fetch/server";
import { validate } from "sveltekit-typesafe-api/server";
import { z } from "zod";
import type { RequestHandler } from "../../friends/$types";

export const GET = (async ({ locals, url }) => {
const { data } = await apiValidate(url, { searchParams: z.object({ query: z.string() }) });
const { data } = await validate(url, { searchParams: z.object({ query: z.string() }) });

const results = [];

Expand Down
4 changes: 2 additions & 2 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { sveltekit } from "@sveltejs/kit/vite";
import { apiFetch } from "sveltekit-api-fetch/vite";
import { typesafeApi } from "sveltekit-typesafe-api/vite";
import { defineConfig } from "vite";

export default defineConfig({
plugins: [sveltekit(), apiFetch()],
plugins: [sveltekit(), typesafeApi()],
});

0 comments on commit 845b67e

Please sign in to comment.