refactor(worker): 🚚 Move queue code to plugin-kit package
Some checks failed
Mirror to Codeberg / Mirror (push) Failing after 1s
Test Publish / build (client) (push) Failing after 1s
Test Publish / build (sdk) (push) Failing after 1s

This commit is contained in:
Jesse Wierzbinski 2025-06-29 22:56:52 +02:00
parent dc802ff5f6
commit 7de4b573e3
No known key found for this signature in database
27 changed files with 68 additions and 57 deletions

View file

@ -100,6 +100,7 @@
"altcha-lib": "catalog:",
"bun-bagel": "catalog:",
"chalk": "catalog:",
"confbox": "catalog:",
"drizzle-orm": "catalog:",
"hono": "catalog:",
"hono-openapi": "catalog:",
@ -168,12 +169,14 @@
"@versia/client": "workspace:*",
"@versia/sdk": "workspace:*",
"altcha-lib": "catalog:",
"bullmq": "catalog:",
"chalk": "catalog:",
"drizzle-orm": "catalog:",
"hono": "catalog:",
"hono-openapi": "catalog:",
"html-to-text": "catalog:",
"ioredis": "catalog:",
"ip-matching": "catalog:",
"linkify-html": "catalog:",
"magic-regexp": "catalog:",
"markdown-it": "catalog:",
@ -182,6 +185,7 @@
"mitt": "catalog:",
"qs": "catalog:",
"sharp": "catalog:",
"web-push": "catalog:",
"zod": "catalog:",
"zod-to-json-schema": "catalog:",
"zod-validation-error": "catalog:",

View file

@ -6,7 +6,7 @@ import { versionPlugin } from "@clerc/plugin-version";
import { setupDatabase } from "@versia-server/kit/db";
import { Clerc } from "clerc";
import { searchManager } from "~/classes/search/search-manager.ts";
import pkg from "~/package.json" with { type: "json" };
import pkg from "../package.json" with { type: "json" };
import { rebuildIndexCommand } from "./index/rebuild.ts";
import { refetchInstanceCommand } from "./instance/refetch.ts";
import { createUserCommand } from "./user/create.ts";

View file

@ -1,11 +1,11 @@
import { Instance } from "@versia-server/kit/db";
import { FetchJobType, fetchQueue } from "@versia-server/kit/queues/fetch";
import { Instances } from "@versia-server/kit/tables";
import chalk from "chalk";
// @ts-expect-error - Root import is required or the Clec type definitions won't work
// biome-ignore lint/correctness/noUnusedImports: Root import is required or the Clec type definitions won't work
import { defineCommand, type Root } from "clerc";
import { eq } from "drizzle-orm";
import { FetchJobType, fetchQueue } from "~/classes/queues/fetch.ts";
export const refetchInstanceCommand = defineCommand(
{

View file

@ -13,14 +13,14 @@ import { secureHeaders } from "hono/secure-headers";
import { openAPISpecs } from "hono-openapi";
import { Youch } from "youch";
import { applyToHono } from "@/bull-board.ts";
import pkg from "~/package.json" with { type: "application/json" };
import { PluginLoader } from "../../classes/plugin/loader.ts";
import pkg from "../../package.json" with { type: "application/json" };
import type { ApiRouteExports, HonoEnv } from "../../types/api.ts";
import { agentBans } from "./middlewares/agent-bans.ts";
import { boundaryCheck } from "./middlewares/boundary-check.ts";
import { ipBans } from "./middlewares/ip-bans.ts";
import { logger } from "./middlewares/logger.ts";
import { rateLimit } from "./middlewares/rate-limit.ts";
import { PluginLoader } from "./plugin-loader.ts";
import { routes } from "./routes.ts";
// Extends Zod with OpenAPI schema generation
import "zod-openapi/extend";

View file

@ -68,6 +68,7 @@
"magic-regexp": "catalog:",
"altcha-lib": "catalog:",
"@hono/zod-validator": "catalog:",
"zod-validation-error": "catalog:"
"zod-validation-error": "catalog:",
"confbox": "catalog:"
}
}

View file

@ -10,13 +10,13 @@ import {
withUserParam,
} from "@versia-server/kit/api";
import { Relationship } from "@versia-server/kit/db";
import { describeRoute } from "hono-openapi";
import { resolver, validator } from "hono-openapi/zod";
import { z } from "zod";
import {
RelationshipJobType,
relationshipQueue,
} from "~/classes/queues/relationships";
} from "@versia-server/kit/queues/relationships";
import { describeRoute } from "hono-openapi";
import { resolver, validator } from "hono-openapi/zod";
import { z } from "zod";
export default apiRoute((app) =>
app.post(

View file

@ -8,7 +8,7 @@ import { and, eq, isNull } from "drizzle-orm";
import { describeRoute } from "hono-openapi";
import { resolver } from "hono-openapi/zod";
import type { z } from "zod";
import manifest from "~/package.json" with { type: "json" };
import manifest from "../../../../../../package.json" with { type: "json" };
export default apiRoute((app) =>
app.get(

View file

@ -6,7 +6,7 @@ import { Users } from "@versia-server/kit/tables";
import { and, eq, isNull } from "drizzle-orm";
import { describeRoute } from "hono-openapi";
import { resolver } from "hono-openapi/zod";
import pkg from "~/package.json" with { type: "json" };
import pkg from "../../../../../../package.json" with { type: "json" };
export default apiRoute((app) =>
app.get(

View file

@ -1,8 +1,8 @@
import { apiRoute, handleZodError } from "@versia-server/kit/api";
import { InboxJobType, inboxQueue } from "@versia-server/kit/queues/inbox";
import { describeRoute } from "hono-openapi";
import { validator } from "hono-openapi/zod";
import { z } from "zod";
import { InboxJobType, inboxQueue } from "~/classes/queues/inbox";
export default apiRoute((app) =>
app.post(

View file

@ -1,9 +1,9 @@
import { ApiError } from "@versia-server/kit";
import { apiRoute, handleZodError } from "@versia-server/kit/api";
import { InboxJobType, inboxQueue } from "@versia-server/kit/queues/inbox";
import { describeRoute } from "hono-openapi";
import { resolver, validator } from "hono-openapi/zod";
import { z } from "zod";
import { InboxJobType, inboxQueue } from "~/classes/queues/inbox";
export default apiRoute((app) =>
app.post(

View file

@ -4,7 +4,7 @@ import { Note, User } from "@versia-server/kit/db";
import { describeRoute } from "hono-openapi";
import { resolver } from "hono-openapi/zod";
import { z } from "zod";
import manifest from "~/package.json" with { type: "json" };
import manifest from "../../../../../../package.json" with { type: "json" };
export default apiRoute((app) =>
app.get(

View file

@ -7,7 +7,7 @@ import { asc } from "drizzle-orm";
import { describeRoute } from "hono-openapi";
import { resolver } from "hono-openapi/zod";
import { urlToContentFormat } from "@/content_types";
import pkg from "~/package.json" with { type: "json" };
import pkg from "../../../../package.json" with { type: "json" };
export default apiRoute((app) =>
app.get(

View file

@ -23,7 +23,7 @@ import sharp from "sharp";
import type { z } from "zod";
import { mimeLookup } from "@/content_types.ts";
import { getMediaHash } from "../../../classes/media/media-hasher.ts";
import { MediaJobType, mediaQueue } from "../../../classes/queues/media.ts";
import { MediaJobType, mediaQueue } from "../queues/media.ts";
import { BaseInterface } from "./base.ts";
type MediaType = InferSelectModel<typeof Medias>;

View file

@ -30,10 +30,7 @@ import { createRegExp, exactly, global } from "magic-regexp";
import type { z } from "zod";
import { mergeAndDeduplicate } from "@/lib.ts";
import { sanitizedHtmlStrip } from "@/sanitization";
import {
DeliveryJobType,
deliveryQueue,
} from "../../../classes/queues/delivery.ts";
import { DeliveryJobType, deliveryQueue } from "../queues/delivery.ts";
import { Application } from "./application.ts";
import { BaseInterface } from "./base.ts";
import { Emoji } from "./emoji.ts";

View file

@ -54,11 +54,8 @@ import { getBestContentType } from "@/content_types";
import { randomString } from "@/math";
import { searchManager } from "~/classes/search/search-manager";
import type { HttpVerb, KnownEntity } from "~/types/api.ts";
import {
DeliveryJobType,
deliveryQueue,
} from "../../../classes/queues/delivery.ts";
import { PushJobType, pushQueue } from "../../../classes/queues/push.ts";
import { DeliveryJobType, deliveryQueue } from "../queues/delivery.ts";
import { PushJobType, pushQueue } from "../queues/push.ts";
import { BaseInterface } from "./base.ts";
import { Emoji } from "./emoji.ts";
import { Instance } from "./instance.ts";

View file

@ -55,7 +55,10 @@
"markdown-it": "catalog:",
"markdown-it-toc-done-right": "catalog:",
"markdown-it-container": "catalog:",
"@hackmd/markdown-it-task-lists": "catalog:"
"@hackmd/markdown-it-task-lists": "catalog:",
"bullmq": "catalog:",
"web-push": "catalog:",
"ip-matching": "catalog:"
},
"files": [
"tables/migrations"
@ -85,6 +88,10 @@
"import": "./regex.ts",
"default": "./regex.ts"
},
"./queues/*": {
"import": "./queues/*.ts",
"default": "./queues/*.ts"
},
"./markdown": {
"import": "./markdown.ts",
"default": "./markdown.ts"

View file

@ -1,10 +1,10 @@
import type { JSONObject } from "@versia/sdk";
import * as VersiaEntities from "@versia/sdk/entities";
import { config } from "@versia-server/config";
import { User } from "@versia-server/kit/db";
import { connection } from "@versia-server/kit/redis";
import { Queue, Worker } from "bullmq";
import chalk from "chalk";
import { User } from "../db/user.ts";
import { connection } from "../redis.ts";
export enum DeliveryJobType {
FederateEntity = "federateEntity",

View file

@ -1,9 +1,9 @@
import { config } from "@versia-server/config";
import { Instance } from "@versia-server/kit/db";
import { connection } from "@versia-server/kit/redis";
import { Instances } from "@versia-server/kit/tables";
import { Queue, Worker } from "bullmq";
import { eq } from "drizzle-orm";
import { Instance } from "../db/instance.ts";
import { connection } from "../redis.ts";
import { Instances } from "../tables/schema.ts";
export enum FetchJobType {
Instance = "instance",

View file

@ -1,11 +1,12 @@
import type { JSONObject } from "@versia/sdk";
import { config } from "@versia-server/config";
import { ApiError } from "@versia-server/kit";
import { Instance, User } from "@versia-server/kit/db";
import { connection } from "@versia-server/kit/redis";
import { Queue, Worker } from "bullmq";
import type { SocketAddress } from "bun";
import { InboxProcessor } from "../inbox/processor.ts";
import { ApiError } from "../api-error.ts";
import { Instance } from "../db/instance.ts";
import { User } from "../db/user.ts";
import { InboxProcessor } from "../inbox-processor.ts";
import { connection } from "../redis.ts";
export enum InboxJobType {
ProcessEntity = "processEntity",

View file

@ -1,9 +1,9 @@
import { config } from "@versia-server/config";
import { Media } from "@versia-server/kit/db";
import { connection } from "@versia-server/kit/redis";
import { Queue, Worker } from "bullmq";
import { calculateBlurhash } from "../media/preprocessors/blurhash.ts";
import { convertImage } from "../media/preprocessors/image-conversion.ts";
import { calculateBlurhash } from "../../../classes/media/preprocessors/blurhash.ts";
import { convertImage } from "../../../classes/media/preprocessors/image-conversion.ts";
import { Media } from "../db/media.ts";
import { connection } from "../redis.ts";
export enum MediaJobType {
ConvertMedia = "convertMedia",

View file

@ -1,9 +1,12 @@
import { config } from "@versia-server/config";
import { Note, PushSubscription, Token, User } from "@versia-server/kit/db";
import { connection } from "@versia-server/kit/redis";
import { Queue, Worker } from "bullmq";
import { sendNotification } from "web-push";
import { htmlToText } from "@/content_types.ts";
import { Note } from "../db/note.ts";
import { PushSubscription } from "../db/pushsubscription.ts";
import { Token } from "../db/token.ts";
import { User } from "../db/user.ts";
import { connection } from "../redis.ts";
export enum PushJobType {
Notify = "notify",

View file

@ -1,7 +1,8 @@
import { config } from "@versia-server/config";
import { Relationship, User } from "@versia-server/kit/db";
import { connection } from "@versia-server/kit/redis";
import { Queue, Worker } from "bullmq";
import { Relationship } from "../db/relationship.ts";
import { User } from "../db/user.ts";
import { connection } from "../redis.ts";
export enum RelationshipJobType {
Unmute = "unmute",

View file

@ -1,9 +1,9 @@
import { getDeliveryWorker } from "~/classes/queues/delivery";
import { getFetchWorker } from "~/classes/queues/fetch";
import { getInboxWorker } from "~/classes/queues/inbox";
import { getMediaWorker } from "~/classes/queues/media";
import { getPushWorker } from "~/classes/queues/push";
import { getRelationshipWorker } from "~/classes/queues/relationships";
import { getDeliveryWorker } from "@versia-server/kit/queues/delivery";
import { getFetchWorker } from "@versia-server/kit/queues/fetch";
import { getInboxWorker } from "@versia-server/kit/queues/inbox";
import { getMediaWorker } from "@versia-server/kit/queues/media";
import { getPushWorker } from "@versia-server/kit/queues/push";
import { getRelationshipWorker } from "@versia-server/kit/queues/relationships";
export const workers = {
fetch: getFetchWorker,

View file

@ -7,7 +7,7 @@ import { and, eq, type SQL } from "drizzle-orm";
import { describeRoute } from "hono-openapi";
import { resolver, validator } from "hono-openapi/zod";
import { z } from "zod";
import type { PluginType } from "~/plugins/openid";
import type { PluginType } from "../../../index.ts";
export default (plugin: PluginType): void => {
plugin.registerRoute("/api/v1/sso/:id", (app) => {

View file

@ -2,16 +2,16 @@ import { createBullBoard } from "@bull-board/api";
import { BullMQAdapter } from "@bull-board/api/bullMQAdapter";
import { HonoAdapter } from "@bull-board/hono";
import { config } from "@versia-server/config";
import { deliveryQueue } from "@versia-server/kit/queues/delivery";
import { fetchQueue } from "@versia-server/kit/queues/fetch";
import { inboxQueue } from "@versia-server/kit/queues/inbox";
import { mediaQueue } from "@versia-server/kit/queues/media";
import { pushQueue } from "@versia-server/kit/queues/push";
import { relationshipQueue } from "@versia-server/kit/queues/relationships";
import type { Hono } from "hono";
import { serveStatic } from "hono/bun";
import { deliveryQueue } from "~/classes/queues/delivery";
import { fetchQueue } from "~/classes/queues/fetch";
import { inboxQueue } from "~/classes/queues/inbox";
import { mediaQueue } from "~/classes/queues/media";
import { pushQueue } from "~/classes/queues/push";
import { relationshipQueue } from "~/classes/queues/relationships";
import pkg from "~/package.json" with { type: "json" };
import type { HonoEnv } from "~/types/api";
import pkg from "../package.json" with { type: "json" };
export const applyToHono = (app: Hono<HonoEnv>): void => {
const serverAdapter = new HonoAdapter(serveStatic);