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:", "altcha-lib": "catalog:",
"bun-bagel": "catalog:", "bun-bagel": "catalog:",
"chalk": "catalog:", "chalk": "catalog:",
"confbox": "catalog:",
"drizzle-orm": "catalog:", "drizzle-orm": "catalog:",
"hono": "catalog:", "hono": "catalog:",
"hono-openapi": "catalog:", "hono-openapi": "catalog:",
@ -168,12 +169,14 @@
"@versia/client": "workspace:*", "@versia/client": "workspace:*",
"@versia/sdk": "workspace:*", "@versia/sdk": "workspace:*",
"altcha-lib": "catalog:", "altcha-lib": "catalog:",
"bullmq": "catalog:",
"chalk": "catalog:", "chalk": "catalog:",
"drizzle-orm": "catalog:", "drizzle-orm": "catalog:",
"hono": "catalog:", "hono": "catalog:",
"hono-openapi": "catalog:", "hono-openapi": "catalog:",
"html-to-text": "catalog:", "html-to-text": "catalog:",
"ioredis": "catalog:", "ioredis": "catalog:",
"ip-matching": "catalog:",
"linkify-html": "catalog:", "linkify-html": "catalog:",
"magic-regexp": "catalog:", "magic-regexp": "catalog:",
"markdown-it": "catalog:", "markdown-it": "catalog:",
@ -182,6 +185,7 @@
"mitt": "catalog:", "mitt": "catalog:",
"qs": "catalog:", "qs": "catalog:",
"sharp": "catalog:", "sharp": "catalog:",
"web-push": "catalog:",
"zod": "catalog:", "zod": "catalog:",
"zod-to-json-schema": "catalog:", "zod-to-json-schema": "catalog:",
"zod-validation-error": "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 { setupDatabase } from "@versia-server/kit/db";
import { Clerc } from "clerc"; import { Clerc } from "clerc";
import { searchManager } from "~/classes/search/search-manager.ts"; 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 { rebuildIndexCommand } from "./index/rebuild.ts";
import { refetchInstanceCommand } from "./instance/refetch.ts"; import { refetchInstanceCommand } from "./instance/refetch.ts";
import { createUserCommand } from "./user/create.ts"; import { createUserCommand } from "./user/create.ts";

View file

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

View file

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

View file

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

View file

@ -10,13 +10,13 @@ import {
withUserParam, withUserParam,
} from "@versia-server/kit/api"; } from "@versia-server/kit/api";
import { Relationship } from "@versia-server/kit/db"; import { Relationship } from "@versia-server/kit/db";
import { describeRoute } from "hono-openapi";
import { resolver, validator } from "hono-openapi/zod";
import { z } from "zod";
import { import {
RelationshipJobType, RelationshipJobType,
relationshipQueue, 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) => export default apiRoute((app) =>
app.post( app.post(

View file

@ -8,7 +8,7 @@ import { and, eq, isNull } from "drizzle-orm";
import { describeRoute } from "hono-openapi"; import { describeRoute } from "hono-openapi";
import { resolver } from "hono-openapi/zod"; import { resolver } from "hono-openapi/zod";
import type { z } from "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) => export default apiRoute((app) =>
app.get( app.get(

View file

@ -6,7 +6,7 @@ import { Users } from "@versia-server/kit/tables";
import { and, eq, isNull } from "drizzle-orm"; import { and, eq, isNull } from "drizzle-orm";
import { describeRoute } from "hono-openapi"; import { describeRoute } from "hono-openapi";
import { resolver } from "hono-openapi/zod"; 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) => export default apiRoute((app) =>
app.get( app.get(

View file

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

View file

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

View file

@ -4,7 +4,7 @@ import { Note, User } from "@versia-server/kit/db";
import { describeRoute } from "hono-openapi"; import { describeRoute } from "hono-openapi";
import { resolver } from "hono-openapi/zod"; import { resolver } from "hono-openapi/zod";
import { z } from "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) => export default apiRoute((app) =>
app.get( app.get(

View file

@ -7,7 +7,7 @@ import { asc } from "drizzle-orm";
import { describeRoute } from "hono-openapi"; import { describeRoute } from "hono-openapi";
import { resolver } from "hono-openapi/zod"; import { resolver } from "hono-openapi/zod";
import { urlToContentFormat } from "@/content_types"; 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) => export default apiRoute((app) =>
app.get( app.get(

View file

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

View file

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

View file

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

View file

@ -55,7 +55,10 @@
"markdown-it": "catalog:", "markdown-it": "catalog:",
"markdown-it-toc-done-right": "catalog:", "markdown-it-toc-done-right": "catalog:",
"markdown-it-container": "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": [ "files": [
"tables/migrations" "tables/migrations"
@ -85,6 +88,10 @@
"import": "./regex.ts", "import": "./regex.ts",
"default": "./regex.ts" "default": "./regex.ts"
}, },
"./queues/*": {
"import": "./queues/*.ts",
"default": "./queues/*.ts"
},
"./markdown": { "./markdown": {
"import": "./markdown.ts", "import": "./markdown.ts",
"default": "./markdown.ts" "default": "./markdown.ts"

View file

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

View file

@ -1,9 +1,9 @@
import { config } from "@versia-server/config"; 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 { Queue, Worker } from "bullmq";
import { eq } from "drizzle-orm"; 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 { export enum FetchJobType {
Instance = "instance", Instance = "instance",

View file

@ -1,11 +1,12 @@
import type { JSONObject } from "@versia/sdk"; import type { JSONObject } from "@versia/sdk";
import { config } from "@versia-server/config"; 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 { Queue, Worker } from "bullmq";
import type { SocketAddress } from "bun"; 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 { export enum InboxJobType {
ProcessEntity = "processEntity", ProcessEntity = "processEntity",

View file

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

View file

@ -1,9 +1,12 @@
import { config } from "@versia-server/config"; 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 { Queue, Worker } from "bullmq";
import { sendNotification } from "web-push"; import { sendNotification } from "web-push";
import { htmlToText } from "@/content_types.ts"; 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 { export enum PushJobType {
Notify = "notify", Notify = "notify",

View file

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

View file

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

View file

@ -7,7 +7,7 @@ import { and, eq, type SQL } from "drizzle-orm";
import { describeRoute } from "hono-openapi"; import { describeRoute } from "hono-openapi";
import { resolver, validator } from "hono-openapi/zod"; import { resolver, validator } from "hono-openapi/zod";
import { z } from "zod"; import { z } from "zod";
import type { PluginType } from "~/plugins/openid"; import type { PluginType } from "../../../index.ts";
export default (plugin: PluginType): void => { export default (plugin: PluginType): void => {
plugin.registerRoute("/api/v1/sso/:id", (app) => { 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 { BullMQAdapter } from "@bull-board/api/bullMQAdapter";
import { HonoAdapter } from "@bull-board/hono"; import { HonoAdapter } from "@bull-board/hono";
import { config } from "@versia-server/config"; 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 type { Hono } from "hono";
import { serveStatic } from "hono/bun"; 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 type { HonoEnv } from "~/types/api";
import pkg from "../package.json" with { type: "json" };
export const applyToHono = (app: Hono<HonoEnv>): void => { export const applyToHono = (app: Hono<HonoEnv>): void => {
const serverAdapter = new HonoAdapter(serveStatic); const serverAdapter = new HonoAdapter(serveStatic);