From 9eac364e0173e68986e2299945f8506244d6fb45 Mon Sep 17 00:00:00 2001 From: Jesse Wierzbinski Date: Mon, 26 May 2025 19:00:24 +0200 Subject: [PATCH] refactor(database): :fire: Always import SQL operators directly from drizzle --- api/api/v1/markers/index.ts | 4 ++-- api/api/v1/statuses/[id]/pin.ts | 4 ++-- api/api/v2/filters/[id]/index.ts | 4 ++-- api/api/v2/filters/index.ts | 5 ++--- bun.lock | 2 +- classes/database/note.ts | 4 ++-- classes/database/relationship.ts | 2 +- classes/database/role.ts | 3 +-- classes/database/user.ts | 2 +- plugins/openid/routes/oauth/callback.ts | 4 ++-- plugins/openid/routes/sso/:id/index.ts | 6 +++--- plugins/openid/utils.ts | 4 ++-- tsconfig.json | 2 +- utils/api.ts | 2 +- 14 files changed, 23 insertions(+), 25 deletions(-) diff --git a/api/api/v1/markers/index.ts b/api/api/v1/markers/index.ts index 01a82bc4..354831fb 100644 --- a/api/api/v1/markers/index.ts +++ b/api/api/v1/markers/index.ts @@ -76,7 +76,7 @@ export default apiRoute((app) => { if (timeline.includes("home")) { const found = await db.query.Markers.findFirst({ - where: (marker, { and, eq }): SQL | undefined => + where: (marker): SQL | undefined => and( eq(marker.userId, user.id), eq(marker.timeline, "home"), @@ -102,7 +102,7 @@ export default apiRoute((app) => { if (timeline.includes("notifications")) { const found = await db.query.Markers.findFirst({ - where: (marker, { and, eq }): SQL | undefined => + where: (marker): SQL | undefined => and( eq(marker.userId, user.id), eq(marker.timeline, "notifications"), diff --git a/api/api/v1/statuses/[id]/pin.ts b/api/api/v1/statuses/[id]/pin.ts index b4e0268a..3b9e9fa6 100644 --- a/api/api/v1/statuses/[id]/pin.ts +++ b/api/api/v1/statuses/[id]/pin.ts @@ -1,6 +1,6 @@ import { RolePermission, Status as StatusSchema } from "@versia/client/schemas"; import { db } from "@versia/kit/db"; -import type { SQL } from "drizzle-orm"; +import { and, eq, type SQL } from "drizzle-orm"; import { describeRoute } from "hono-openapi"; import { resolver } from "hono-openapi/zod"; import { apiRoute, auth, withNoteParam } from "@/api"; @@ -51,7 +51,7 @@ export default apiRoute((app) => if ( await db.query.UserToPinnedNotes.findFirst({ - where: (userPinnedNote, { and, eq }): SQL | undefined => + where: (userPinnedNote): SQL | undefined => and( eq(userPinnedNote.noteId, note.data.id), eq(userPinnedNote.userId, user.id), diff --git a/api/api/v2/filters/[id]/index.ts b/api/api/v2/filters/[id]/index.ts index 75a9b2c9..5cf1fdaf 100644 --- a/api/api/v2/filters/[id]/index.ts +++ b/api/api/v2/filters/[id]/index.ts @@ -56,7 +56,7 @@ export default apiRoute((app) => { const { id } = context.req.valid("param"); const userFilter = await db.query.Filters.findFirst({ - where: (filter, { eq, and }): SQL | undefined => + where: (filter): SQL | undefined => and(eq(filter.userId, user.id), eq(filter.id, id)), with: { keywords: true, @@ -224,7 +224,7 @@ export default apiRoute((app) => { } const updatedFilter = await db.query.Filters.findFirst({ - where: (filter, { eq, and }): SQL | undefined => + where: (filter): SQL | undefined => and(eq(filter.userId, user.id), eq(filter.id, id)), with: { keywords: true, diff --git a/api/api/v2/filters/index.ts b/api/api/v2/filters/index.ts index 514772d0..84797a38 100644 --- a/api/api/v2/filters/index.ts +++ b/api/api/v2/filters/index.ts @@ -6,7 +6,7 @@ import { import { db } from "@versia/kit/db"; import { FilterKeywords, Filters } from "@versia/kit/tables"; import { randomUUIDv7 } from "bun"; -import type { SQL } from "drizzle-orm"; +import { eq, type SQL } from "drizzle-orm"; import { describeRoute } from "hono-openapi"; import { resolver, validator } from "hono-openapi/zod"; import { z } from "zod"; @@ -44,8 +44,7 @@ export default apiRoute((app) => { const { user } = context.get("auth"); const userFilters = await db.query.Filters.findMany({ - where: (filter, { eq }): SQL | undefined => - eq(filter.userId, user.id), + where: (filter): SQL | undefined => eq(filter.userId, user.id), with: { keywords: true, }, diff --git a/bun.lock b/bun.lock index ceaeb193..c6558b8a 100644 --- a/bun.lock +++ b/bun.lock @@ -86,7 +86,7 @@ }, "packages/client": { "name": "@versia/client", - "version": "0.2.0-alpha.1", + "version": "0.2.0-alpha.3", "dependencies": { "@badgateway/oauth2-client": "^3.0.0", "iso-639-1": "^3.1.5", diff --git a/classes/database/note.ts b/classes/database/note.ts index 2f2cba9f..1fc973af 100644 --- a/classes/database/note.ts +++ b/classes/database/note.ts @@ -261,7 +261,7 @@ export class Note extends BaseInterface { { with: { relationships: { - where: (relationship, { eq, and }): SQL | undefined => + where: (relationship): SQL | undefined => and( eq(relationship.subjectId, this.data.authorId), eq(relationship.following, true), @@ -597,7 +597,7 @@ export class Note extends BaseInterface { if (this.data.visibility === "private") { return user ? !!(await db.query.Relationships.findFirst({ - where: (relationship, { and, eq }): SQL | undefined => + where: (relationship): SQL | undefined => and( eq(relationship.ownerId, user?.id), eq(relationship.subjectId, Notes.authorId), diff --git a/classes/database/relationship.ts b/classes/database/relationship.ts index 82d288cf..107c1aec 100644 --- a/classes/database/relationship.ts +++ b/classes/database/relationship.ts @@ -204,7 +204,7 @@ export class Relationship extends BaseInterface< ownerId: string; }): Promise { let output = await db.query.Relationships.findFirst({ - where: (rel, { and, eq }): SQL | undefined => + where: (rel): SQL | undefined => and( eq(rel.ownerId, oppositeTo.subjectId), eq(rel.subjectId, oppositeTo.ownerId), diff --git a/classes/database/role.ts b/classes/database/role.ts index 7d303812..356040ee 100644 --- a/classes/database/role.ts +++ b/classes/database/role.ts @@ -91,8 +91,7 @@ export class Role extends BaseInterface { ): Promise { return ( await db.query.RoleToUsers.findMany({ - where: (role, { eq }): SQL | undefined => - eq(role.userId, userId), + where: (role): SQL | undefined => eq(role.userId, userId), with: { role: true, user: { diff --git a/classes/database/user.ts b/classes/database/user.ts index d7987bf4..1ab6615d 100644 --- a/classes/database/user.ts +++ b/classes/database/user.ts @@ -464,7 +464,7 @@ export class User extends BaseInterface { > { // Get all linked accounts const accounts = await db.query.OpenIdAccounts.findMany({ - where: (User, { eq }): SQL | undefined => eq(User.userId, this.id), + where: (User): SQL | undefined => eq(User.userId, this.id), }); return accounts diff --git a/plugins/openid/routes/oauth/callback.ts b/plugins/openid/routes/oauth/callback.ts index 887ef5f9..a73bd9d8 100644 --- a/plugins/openid/routes/oauth/callback.ts +++ b/plugins/openid/routes/oauth/callback.ts @@ -156,7 +156,7 @@ export default (plugin: PluginType): void => { // Check if account is already linked const account = await db.query.OpenIdAccounts.findFirst({ - where: (account, { eq, and }): SQL | undefined => + where: (account): SQL | undefined => and( eq(account.serverId, sub), eq(account.issuerId, issuer.id), @@ -195,7 +195,7 @@ export default (plugin: PluginType): void => { let userId = ( await db.query.OpenIdAccounts.findFirst({ - where: (account, { eq, and }): SQL | undefined => + where: (account): SQL | undefined => and( eq(account.serverId, sub), eq(account.issuerId, issuer.id), diff --git a/plugins/openid/routes/sso/:id/index.ts b/plugins/openid/routes/sso/:id/index.ts index da64e512..85c152fe 100644 --- a/plugins/openid/routes/sso/:id/index.ts +++ b/plugins/openid/routes/sso/:id/index.ts @@ -1,6 +1,6 @@ import { RolePermission } from "@versia/client/schemas"; import { db } from "@versia/kit/db"; -import { eq, type SQL } from "@versia/kit/drizzle"; +import { and, eq, type SQL } from "@versia/kit/drizzle"; import { OpenIdAccounts } from "@versia/kit/tables"; import { describeRoute } from "hono-openapi"; import { resolver, validator } from "hono-openapi/zod"; @@ -58,7 +58,7 @@ export default (plugin: PluginType): void => { } const account = await db.query.OpenIdAccounts.findFirst({ - where: (account, { eq, and }): SQL | undefined => + where: (account): SQL | undefined => and( eq(account.userId, user.id), eq(account.issuerId, issuerId), @@ -127,7 +127,7 @@ export default (plugin: PluginType): void => { } const account = await db.query.OpenIdAccounts.findFirst({ - where: (account, { eq, and }): SQL | undefined => + where: (account): SQL | undefined => and( eq(account.userId, user.id), eq(account.issuerId, issuerId), diff --git a/plugins/openid/utils.ts b/plugins/openid/utils.ts index b11cbeb6..b924088d 100644 --- a/plugins/openid/utils.ts +++ b/plugins/openid/utils.ts @@ -1,5 +1,5 @@ import { type Application, db } from "@versia/kit/db"; -import type { InferSelectModel, SQL } from "@versia/kit/drizzle"; +import { eq, type InferSelectModel, type SQL } from "@versia/kit/drizzle"; import type { OpenIdLoginFlows } from "@versia/kit/tables"; import { type AuthorizationResponseError, @@ -39,7 +39,7 @@ const getFlow = ( | undefined > => { return db.query.OpenIdLoginFlows.findFirst({ - where: (flow, { eq }): SQL | undefined => eq(flow.id, flowId), + where: (flow): SQL | undefined => eq(flow.id, flowId), with: { application: true, }, diff --git a/tsconfig.json b/tsconfig.json index 8b1288ec..67247604 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -26,7 +26,7 @@ //"isolatedDeclarations": true, "verbatimModuleSyntax": true, "moduleDetection": "force", - "target": "esnext", + "target": "ESNext", "jsx": "preserve", "lib": ["ESNext", "DOM", "DOM.Iterable"], "composite": true, diff --git a/utils/api.ts b/utils/api.ts index df805649..040b8df7 100644 --- a/utils/api.ts +++ b/utils/api.ts @@ -170,7 +170,7 @@ export const checkRouteNeedsChallenge = async ( } const challenge = await db.query.Challenges.findFirst({ - where: (c, { eq }): SQL | undefined => eq(c.id, challenge_id), + where: (c): SQL | undefined => eq(c.id, challenge_id), }); if (!challenge) {