refactor: ♻️ Always use explicit types in every function

This commit is contained in:
Jesse Wierzbinski 2024-11-02 00:43:33 +01:00
parent 54cea29ce9
commit c1dcdc78ae
No known key found for this signature in database
62 changed files with 359 additions and 226 deletions

View file

@ -86,7 +86,11 @@ const route = createRoute({
},
});
const returnError = (context: Context, error: string, description: string) => {
const returnError = (
context: Context,
error: string,
description: string,
): Response => {
const searchParams = new URLSearchParams();
// Add all data that is not undefined except email and password

View file

@ -49,7 +49,7 @@ export default apiRoute((app) =>
app.openapi(route, async (context) => {
const { redirect_uri, client_id, code } = context.req.valid("query");
const redirectToLogin = (error: string) =>
const redirectToLogin = (error: string): Response =>
context.redirect(
`${config.frontend.routes.login}?${new URLSearchParams({
...context.req.query,

View file

@ -54,7 +54,7 @@ const returnError = (
token: string,
error: string,
description: string,
) => {
): Response => {
const searchParams = new URLSearchParams();
searchParams.append("error", error);

View file

@ -2,7 +2,7 @@ import { apiRoute, applyConfig, auth, qsQuery } from "@/api";
import { createRoute } from "@hono/zod-openapi";
import { User, db } from "@versia/kit/db";
import { RolePermissions, Users } from "@versia/kit/tables";
import { inArray } from "drizzle-orm";
import { type SQL, inArray } from "drizzle-orm";
import { z } from "zod";
import { ErrorSchema } from "~/types/api";
@ -70,7 +70,7 @@ export default apiRoute((app) =>
columns: {
ownerId: true,
},
where: (relationship, { inArray, and, eq }) =>
where: (relationship, { inArray, and, eq }): SQL | undefined =>
and(
inArray(
relationship.subjectId,
@ -89,7 +89,7 @@ export default apiRoute((app) =>
columns: {
subjectId: true,
},
where: (relationship, { inArray, and, eq }) =>
where: (relationship, { inArray, and, eq }): SQL | undefined =>
and(
eq(relationship.ownerId, self.id),
inArray(

View file

@ -3,7 +3,7 @@ import { createRoute } from "@hono/zod-openapi";
import type { Marker as ApiMarker } from "@versia/client/types";
import { db } from "@versia/kit/db";
import { Markers, RolePermissions } from "@versia/kit/tables";
import { and, eq } from "drizzle-orm";
import { type SQL, and, eq } from "drizzle-orm";
import { z } from "zod";
import { ErrorSchema } from "~/types/api";
@ -133,7 +133,7 @@ export default apiRoute((app) => {
if (timeline.includes("home")) {
const found = await db.query.Markers.findFirst({
where: (marker, { and, eq }) =>
where: (marker, { and, eq }): SQL | undefined =>
and(
eq(marker.userId, user.id),
eq(marker.timeline, "home"),
@ -156,7 +156,7 @@ export default apiRoute((app) => {
if (timeline.includes("notifications")) {
const found = await db.query.Markers.findFirst({
where: (marker, { and, eq }) =>
where: (marker, { and, eq }): SQL | undefined =>
and(
eq(marker.userId, user.id),
eq(marker.timeline, "notifications"),

View file

@ -2,6 +2,7 @@ import { apiRoute, applyConfig, auth } from "@/api";
import { createRoute } from "@hono/zod-openapi";
import { Note, User } from "@versia/kit/db";
import { RolePermissions } from "@versia/kit/tables";
import type { SQL } from "drizzle-orm";
import { z } from "zod";
import {
findManyNotifications,
@ -103,7 +104,8 @@ export default apiRoute((app) =>
const notification = (
await findManyNotifications(
{
where: (notification, { eq }) => eq(notification.id, id),
where: (notification, { eq }): SQL | undefined =>
eq(notification.id, id),
limit: 1,
},
user.id,

View file

@ -3,7 +3,9 @@ import type { Notification as ApiNotification } from "@versia/client/types";
import { fakeRequest, getTestStatuses, getTestUsers } from "~/tests/utils";
import { meta } from "./index.ts";
const getFormData = (object: Record<string, string | number | boolean>) =>
const getFormData = (
object: Record<string, string | number | boolean>,
): FormData =>
Object.keys(object).reduce((formData, key) => {
formData.append(key, String(object[key]));
return formData;

View file

@ -3,7 +3,7 @@ import { fetchTimeline } from "@/timelines";
import { createRoute } from "@hono/zod-openapi";
import { Note, User } from "@versia/kit/db";
import { RolePermissions } from "@versia/kit/tables";
import { sql } from "drizzle-orm";
import { type SQL, sql } from "drizzle-orm";
import { z } from "zod";
import {
findManyNotifications,
@ -159,7 +159,7 @@ export default apiRoute((app) =>
notification,
// @ts-expect-error Yes I KNOW the types are wrong
{ lt, gte, gt, and, eq, not, inArray },
) =>
): SQL | undefined =>
and(
max_id ? lt(notification.id, max_id) : undefined,
since_id
@ -200,7 +200,8 @@ export default apiRoute((app) =>
),
limit,
// @ts-expect-error Yes I KNOW the types are wrong
orderBy: (notification, { desc }) => desc(notification.id),
orderBy: (notification, { desc }): SQL | undefined =>
desc(notification.id),
},
context.req.raw,
user.id,

View file

@ -2,6 +2,7 @@ import { apiRoute, applyConfig, auth, idValidator } from "@/api";
import { createRoute } from "@hono/zod-openapi";
import { Note, db } from "@versia/kit/db";
import { RolePermissions } from "@versia/kit/tables";
import type { SQL } from "drizzle-orm";
import { z } from "zod";
import { ErrorSchema } from "~/types/api";
@ -90,7 +91,7 @@ export default apiRoute((app) =>
if (
await db.query.UserToPinnedNotes.findFirst({
where: (userPinnedNote, { and, eq }) =>
where: (userPinnedNote, { and, eq }): SQL | undefined =>
and(
eq(userPinnedNote.noteId, foundStatus.data.id),
eq(userPinnedNote.userId, user.id),

View file

@ -2,7 +2,7 @@ import { apiRoute, applyConfig, auth, jsonOrForm } from "@/api";
import { createRoute } from "@hono/zod-openapi";
import { db } from "@versia/kit/db";
import { FilterKeywords, Filters, RolePermissions } from "@versia/kit/tables";
import { and, eq, inArray } from "drizzle-orm";
import { type SQL, and, eq, inArray } from "drizzle-orm";
import { z } from "zod";
import { ErrorSchema } from "~/types/api";
@ -204,7 +204,7 @@ export default apiRoute((app) => {
}
const userFilter = await db.query.Filters.findFirst({
where: (filter, { eq, and }) =>
where: (filter, { eq, and }): SQL | undefined =>
and(eq(filter.userId, user.id), eq(filter.id, id)),
with: {
keywords: true,
@ -300,7 +300,7 @@ export default apiRoute((app) => {
}
const updatedFilter = await db.query.Filters.findFirst({
where: (filter, { eq, and }) =>
where: (filter, { eq, and }): SQL | undefined =>
and(eq(filter.userId, user.id), eq(filter.id, id)),
with: {
keywords: true,

View file

@ -2,6 +2,7 @@ import { apiRoute, applyConfig, auth, jsonOrForm } from "@/api";
import { createRoute } from "@hono/zod-openapi";
import { db } from "@versia/kit/db";
import { FilterKeywords, Filters, RolePermissions } from "@versia/kit/tables";
import type { SQL } from "drizzle-orm";
import { z } from "zod";
import { ErrorSchema } from "~/types/api";
export const meta = applyConfig({
@ -139,7 +140,8 @@ export default apiRoute((app) => {
}
const userFilters = await db.query.Filters.findMany({
where: (filter, { eq }) => eq(filter.userId, user.id),
where: (filter, { eq }): SQL | undefined =>
eq(filter.userId, user.id),
with: {
keywords: true,
},