diff --git a/README.md b/README.md index bdec214e..9961af9d 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ With this library you get a beautiful UI for visualizing what's happening with e ## Packages | Name | Version | -|--------------------------------------------------------------------------|-------------------------------------------------------------------| +| ------------------------------------------------------------------------ | ----------------------------------------------------------------- | | [@bull-board/api](https://www.npmjs.com/package/@bull-board/api) | ![npm (scoped)](https://img.shields.io/npm/v/@bull-board/api) | | [@bull-board/ui](https://www.npmjs.com/package/@bull-board/ui) | ![npm (scoped)](https://img.shields.io/npm/v/@bull-board/ui) | | [@bull-board/express](https://www.npmjs.com/package/@bull-board/express) | ![npm (scoped)](https://img.shields.io/npm/v/@bull-board/express) | @@ -29,6 +29,7 @@ With this library you get a beautiful UI for visualizing what's happening with e | [@bull-board/nestjs](https://www.npmjs.com/package/@bull-board/nestjs) | ![npm (scoped)](https://img.shields.io/npm/v/@bull-board/nestjs) | | [@bull-board/hono](https://www.npmjs.com/package/@bull-board/hono) | ![npm (scoped)](https://img.shields.io/npm/v/@bull-board/hono) | | [@bull-board/h3](https://www.npmjs.com/package/@bull-board/h3) | ![npm (scoped)](https://img.shields.io/npm/v/@bull-board/h3) | +| [@bull-board/elysia](https://www.npmjs.com/package/@bull-board/elysia) | ![npm (scoped)](https://img.shields.io/npm/v/@bull-board/elysia) | ## Notes @@ -59,9 +60,12 @@ yarn add @bull-board/nestjs yarn add @bull-board/hono # or yarn add @bull-board/h3 +# or +bun add @bull-board/elysia ``` ### NestJS specific setup + @bull-board provides a module for easy integration with NestJS, for reference on how to use the module refer to the [NestJS Module](https://github.com/felixmosh/bull-board/tree/master/packages/nestjs) package ## Hello World @@ -104,8 +108,8 @@ app.listen(3000, () => { That's it! Now you can access the `/admin/queues` route, and you will be able to monitor everything that is happening in your queues 😁 - For more advanced usages check the `examples` folder, currently it contains: + 1. [Basic authentication example](https://github.com/felixmosh/bull-board/tree/master/examples/with-express-auth) 2. [Multiple instance of the board](https://github.com/felixmosh/bull-board/tree/master/examples/with-multiple-instances) 3. [With Fastify server](https://github.com/felixmosh/bull-board/tree/master/examples/with-fastify) @@ -114,23 +118,24 @@ For more advanced usages check the `examples` folder, currently it contains: 6. [With Nest.js server using the built-in module](https://github.com/felixmosh/bull-board/tree/master/examples/with-nestjs-module) (Thanx to @dennissnijder) 7. [With Nest.js server using the express adapter](https://github.com/felixmosh/bull-board/tree/master/examples/with-nestjs) (Thanx to @lodi-g) 8. [With Hono server](https://github.com/felixmosh/bull-board/tree/master/examples/with-hono) (Thanks to @nihalgonsalves) -8. [With H3 server using the h3 adapter](https://github.com/felixmosh/bull-board/tree/master/examples/with-h3) (Thanx to @genu) - +9. [With H3 server using the h3 adapter](https://github.com/felixmosh/bull-board/tree/master/examples/with-h3) (Thanx to @genu) +10. [With Elysia server using the Elysia adapter](https://github.com/felixmosh/bull-board/tree/master/examples/with-elysia) (Thanx to @genu) ### Board options + 1. `uiConfig.boardTitle` (default: `Bull Dashboard`) -The Board and page titles + The Board and page titles 2. `uiConfig.boardLogo` (default: `empty`) `{ path: string; width?: number | string; height?: number | string }` -An object that allows you to specify a different logo + An object that allows you to specify a different logo 3. `uiConfig.miscLinks` (default: `empty`) `Array< { text: string; url: string }>` -An array of misc link that you can add to the dashboard, such as logout link. + An array of misc link that you can add to the dashboard, such as logout link. 4. uiConfig.favIcon (default: `{ default: 'static/images/logo.svg', alternative: 'static/favicon-32x32.png', }`) `{ default: string; alternative: 'string' }` -An object that allows you to specify the default and alternative favicons. + An object that allows you to specify the default and alternative favicons. ```js const QueueMQ = require('bullmq'); -const {createBullBoard} = require('@bull-board/api'); -const {BullMQAdapter} = require('@bull-board/api/bullMQAdapter'); +const { createBullBoard } = require('@bull-board/api'); +const { BullMQAdapter } = require('@bull-board/api/bullMQAdapter'); const queueMQ = new QueueMQ(); @@ -145,7 +150,7 @@ createBullBoard({ width: '100px', height: 200, }, - miscLinks: [{text: 'Logout', url: '/logout'}], + miscLinks: [{ text: 'Logout', url: '/logout' }], favIcon: { default: 'static/images/logo.svg', alternative: 'static/favicon-32x32.png', @@ -156,45 +161,46 @@ createBullBoard({ ``` ### Queue options + 1. `readOnlyMode` (default: `false`) -Makes the UI as read only, hides all queue & job related actions + Makes the UI as read only, hides all queue & job related actions ```js -const Queue = require('bull') -const QueueMQ = require('bullmq') -const { createBullBoard } = require('@bull-board/api') -const { BullMQAdapter } = require('@bull-board/api/bullMQAdapter') -const { BullAdapter } = require('@bull-board/api/bullAdapter') +const Queue = require('bull'); +const QueueMQ = require('bullmq'); +const { createBullBoard } = require('@bull-board/api'); +const { BullMQAdapter } = require('@bull-board/api/bullMQAdapter'); +const { BullAdapter } = require('@bull-board/api/bullAdapter'); -const someQueue = new Queue() -const queueMQ = new QueueMQ() +const someQueue = new Queue(); +const queueMQ = new QueueMQ(); createBullBoard({ queues: [ new BullAdapter(someQueue, { readOnlyMode: true }), // only this queue will be in read only mode new BullMQAdapter(queueMQ, { readOnlyMode: true }), - ] -}) + ], +}); ``` 2. `allowRetries` (default: `true`) -When set to `false` the UI removes the job retry buttons for a queue. This option will be ignored if `readOnlyMode` is `true`. + When set to `false` the UI removes the job retry buttons for a queue. This option will be ignored if `readOnlyMode` is `true`. ```js -const QueueMQ = require('bullmq') -const { createBullBoard } = require('@bull-board/api') -const { BullMQAdapter } = require('@bull-board/api/bullMQAdapter') -const { BullAdapter } = require('@bull-board/api/bullAdapter') +const QueueMQ = require('bullmq'); +const { createBullBoard } = require('@bull-board/api'); +const { BullMQAdapter } = require('@bull-board/api/bullMQAdapter'); +const { BullAdapter } = require('@bull-board/api/bullAdapter'); -const someQueue = new Queue() -const queueMQ = new QueueMQ() +const someQueue = new Queue(); +const queueMQ = new QueueMQ(); createBullBoard({ queues: [ new BullAdapter(someQueue, { allowRetries: false }), // No retry buttons new BullMQAdapter(queueMQ, { allowRetries: true, readOnlyMode: true }), // allowRetries will be ignored in this case in lieu of readOnlyMode - ] -}) + ], +}); ``` 3. `description` (default: `empty`) @@ -212,18 +218,18 @@ const { createBullBoard } = require('@bull-board/api'); const { BullMQAdapter } = require('@bull-board/api/bullMQAdapter'); const redact = fastRedact({ - paths: ['headers.cookie', 'password', 'access_token'] -}) + paths: ['headers.cookie', 'password', 'access_token'], +}); -const queueMQ = new QueueMQ() +const queueMQ = new QueueMQ(); const queueAdapter = new BullMQAdapter(queueMQ); queueAdapter.setFormatter('name', (job) => `#Queue1 - ${job.name}`); queueAdapter.setFormatter('data', (data) => redact(data)); queueAdapter.setFormatter('returnValue', (returnValue) => redact(returnValue)); createBullBoard({ - queues: [queueAdapter] -}) + queues: [queueAdapter], +}); ``` ### Hosting router on a sub path @@ -231,23 +237,21 @@ createBullBoard({ If you host your express service on a different path than root (/) ie. https:////, then you can add the following code to provide the configuration to the bull-board router. In this example the sub path will be `my-base-path`. ```js -const Queue = require('bull') -const { createBullBoard } = require('@bull-board/api') -const { BullAdapter } = require('@bull-board/api/bullAdapter') -const { ExpressAdapter } = require('@bull-board/express') +const Queue = require('bull'); +const { createBullBoard } = require('@bull-board/api'); +const { BullAdapter } = require('@bull-board/api/bullAdapter'); +const { ExpressAdapter } = require('@bull-board/express'); const basePath = '/my-base-path'; -const someQueue = new Queue('someQueueName') +const someQueue = new Queue('someQueueName'); const serverAdapter = new ExpressAdapter(); -serverAdapter.setBasePath(basePath) +serverAdapter.setBasePath(basePath); createBullBoard({ - queues: [ - new BullAdapter(someQueue), - ], - serverAdapter -}) + queues: [new BullAdapter(someQueue)], + serverAdapter, +}); // ... express server configuration diff --git a/examples/with-elysia/README.md b/examples/with-elysia/README.md new file mode 100644 index 00000000..b6c4895a --- /dev/null +++ b/examples/with-elysia/README.md @@ -0,0 +1,3 @@ +# Elysia example + +This example shows how to use [Elysia](https://elysiajs.com/) as a server for bull-board. diff --git a/examples/with-elysia/index.ts b/examples/with-elysia/index.ts new file mode 100644 index 00000000..45a88005 --- /dev/null +++ b/examples/with-elysia/index.ts @@ -0,0 +1,64 @@ +import { createBullBoard } from "@bull-board/api"; +import { BullMQAdapter } from "@bull-board/api/bullMQAdapter"; +import { ElysiaAdapter } from "@bull-board/elysia"; +import { Queue as QueueMQ, Worker } from "bullmq"; +import Elysia from "elysia"; + +const sleep = (t: number) => + new Promise((resolve) => setTimeout(resolve, t * 1000)); + +const redisOptions = { + port: 6379, + host: "localhost", + password: "", +}; + +const createQueueMQ = (name: string) => + new QueueMQ(name, { connection: redisOptions }); + +async function setupBullMQProcessor(queueName: string) { + new Worker( + queueName, + async (job) => { + for (let i = 0; i <= 100; i++) { + await sleep(Math.random()); + await job.updateProgress(i); + await job.log(`Processing job at interval ${i}`); + + if (Math.random() * 200 < 1) throw new Error(`Random error ${i}`); + } + + return { jobId: `This is the return value of job (${job.id})` }; + }, + { connection: redisOptions }, + ); +} + +const exampleBullMq = createQueueMQ("BullMQ"); + +await setupBullMQProcessor(exampleBullMq.name); + +const serverAdapter = new ElysiaAdapter("/ui"); + +createBullBoard({ + queues: [new BullMQAdapter(exampleBullMq)], + serverAdapter, +}); + +const app = new Elysia() + .use(serverAdapter.registerPlugin()) + .get("/add", async ({ query }) => { + await exampleBullMq.add("Add", { title: query.title }); + + return { ok: true }; + }); + +app.listen(3000, ({ port, url }) => { + /* eslint-disable no-console */ + console.log(`Running on ${url.hostname}:${port}...`); + console.log(`For the UI of instance1, open http://localhost:${port}/ui`); + console.log("Make sure Redis is running on port 6379 by default"); + console.log("To populate the queue, run:"); + console.log(` curl http://localhost:${port}/add?title=Example`); + /* eslint-enable no-console */ +}); diff --git a/examples/with-elysia/package.json b/examples/with-elysia/package.json new file mode 100644 index 00000000..7ee14149 --- /dev/null +++ b/examples/with-elysia/package.json @@ -0,0 +1,18 @@ +{ + "name": "bull-board-with-elysia", + "type": "module", + "version": "1.0.0", + "description": "Example of how to use Elysia server with bull-board", + "module": "index.ts", + "scripts": { + "start": "bun index.ts", + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "kravetsone", + "license": "ISC", + "dependencies": { + "@bull-board/elysia": "^5.20.1", + "bullmq": "^4.6.0", + "elysia": "^1.0.22" + } +} diff --git a/examples/with-elysia/tsconfig.json b/examples/with-elysia/tsconfig.json new file mode 100644 index 00000000..4c4b6f9b --- /dev/null +++ b/examples/with-elysia/tsconfig.json @@ -0,0 +1,15 @@ +{ + "compilerOptions": { + "lib": ["ESNext"], + "module": "ESNext", + "target": "ESNext", + "moduleResolution": "Bundler", + "esModuleInterop": true, + "strict": true, + "skipLibCheck": true, + "allowSyntheticDefaultImports": true, + "rootDir": "./src", + "noEmit": true + }, + "include": ["src"] +} diff --git a/examples/with-elysia/yarn.lock b/examples/with-elysia/yarn.lock new file mode 100644 index 00000000..fde012bb --- /dev/null +++ b/examples/with-elysia/yarn.lock @@ -0,0 +1,427 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +"@bull-board/api@5.20.1": + version "5.20.1" + resolved "https://registry.yarnpkg.com/@bull-board/api/-/api-5.20.1.tgz#826567731aeea8ce006aa6f5ea0d1d7cc2f5a7a7" + integrity sha512-45aDhnOzWRrtUUAKHxdClSnLIus5f8BK3ATzb2IwI/BRgOi1lWTe1YG266hVqDdWXsUDxKzf75DAANKfAoEsRA== + dependencies: + redis-info "^3.0.8" + +"@bull-board/elysia@../../packages/elysia": + version "5.20.1" + dependencies: + "@bull-board/api" "5.20.1" + "@bull-board/ui" "5.20.1" + "@elysiajs/static" "^1.0.3" + ejs "^3.1.10" + +"@bull-board/ui@5.20.1": + version "5.20.1" + resolved "https://registry.yarnpkg.com/@bull-board/ui/-/ui-5.20.1.tgz#bf05cd6e1c1e7010baf49b4f0353c03a81cc44f3" + integrity sha512-RzNinC4FKHNuxzkIRsCL+n9iO5RxmF5YM7byCuuv1/UeFjtCtsLHFi6TI9ZgJsXETA2Uxq9Mg7ppncojUjrINw== + dependencies: + "@bull-board/api" "5.20.1" + +"@elysiajs/static@^1.0.3": + version "1.0.3" + resolved "https://registry.yarnpkg.com/@elysiajs/static/-/static-1.0.3.tgz#0175a14762aecf1e0250b7bd961616e645cbafa3" + integrity sha512-+oMDfqRC8OFgzsrHQBUjlMHTUqYAyFpq3HPaHochgs9a+i/SBKfX6Ow4kepBIOMTlf43knw3wfHu6sEVsXzLRw== + dependencies: + node-cache "^5.1.2" + +"@ioredis/commands@^1.1.1": + version "1.2.0" + resolved "https://registry.yarnpkg.com/@ioredis/commands/-/commands-1.2.0.tgz#6d61b3097470af1fdbbe622795b8921d42018e11" + integrity sha512-Sx1pU8EM64o2BrqNpEO1CNLtKQwyhuXuqyfH7oGKCk+1a33d2r5saW8zNwm3j6BTExtjrv2BxTgzzkMwts6vGg== + +"@msgpackr-extract/msgpackr-extract-darwin-arm64@3.0.3": + version "3.0.3" + resolved "https://registry.yarnpkg.com/@msgpackr-extract/msgpackr-extract-darwin-arm64/-/msgpackr-extract-darwin-arm64-3.0.3.tgz#9edec61b22c3082018a79f6d1c30289ddf3d9d11" + integrity sha512-QZHtlVgbAdy2zAqNA9Gu1UpIuI8Xvsd1v8ic6B2pZmeFnFcMWiPLfWXh7TVw4eGEZ/C9TH281KwhVoeQUKbyjw== + +"@msgpackr-extract/msgpackr-extract-darwin-x64@3.0.3": + version "3.0.3" + resolved "https://registry.yarnpkg.com/@msgpackr-extract/msgpackr-extract-darwin-x64/-/msgpackr-extract-darwin-x64-3.0.3.tgz#33677a275204898ad8acbf62734fc4dc0b6a4855" + integrity sha512-mdzd3AVzYKuUmiWOQ8GNhl64/IoFGol569zNRdkLReh6LRLHOXxU4U8eq0JwaD8iFHdVGqSy4IjFL4reoWCDFw== + +"@msgpackr-extract/msgpackr-extract-linux-arm64@3.0.3": + version "3.0.3" + resolved "https://registry.yarnpkg.com/@msgpackr-extract/msgpackr-extract-linux-arm64/-/msgpackr-extract-linux-arm64-3.0.3.tgz#19edf7cdc2e7063ee328403c1d895a86dd28f4bb" + integrity sha512-YxQL+ax0XqBJDZiKimS2XQaf+2wDGVa1enVRGzEvLLVFeqa5kx2bWbtcSXgsxjQB7nRqqIGFIcLteF/sHeVtQg== + +"@msgpackr-extract/msgpackr-extract-linux-arm@3.0.3": + version "3.0.3" + resolved "https://registry.yarnpkg.com/@msgpackr-extract/msgpackr-extract-linux-arm/-/msgpackr-extract-linux-arm-3.0.3.tgz#94fb0543ba2e28766c3fc439cabbe0440ae70159" + integrity sha512-fg0uy/dG/nZEXfYilKoRe7yALaNmHoYeIoJuJ7KJ+YyU2bvY8vPv27f7UKhGRpY6euFYqEVhxCFZgAUNQBM3nw== + +"@msgpackr-extract/msgpackr-extract-linux-x64@3.0.3": + version "3.0.3" + resolved "https://registry.yarnpkg.com/@msgpackr-extract/msgpackr-extract-linux-x64/-/msgpackr-extract-linux-x64-3.0.3.tgz#4a0609ab5fe44d07c9c60a11e4484d3c38bbd6e3" + integrity sha512-cvwNfbP07pKUfq1uH+S6KJ7dT9K8WOE4ZiAcsrSes+UY55E/0jLYc+vq+DO7jlmqRb5zAggExKm0H7O/CBaesg== + +"@msgpackr-extract/msgpackr-extract-win32-x64@3.0.3": + version "3.0.3" + resolved "https://registry.yarnpkg.com/@msgpackr-extract/msgpackr-extract-win32-x64/-/msgpackr-extract-win32-x64-3.0.3.tgz#0aa5502d547b57abfc4ac492de68e2006e417242" + integrity sha512-x0fWaQtYp4E6sktbsdAqnehxDgEc/VwM7uLsRCYWaiGu0ykYdZPiS8zCWdnjHwyiumousxfBm4SO31eXqwEZhQ== + +"@sinclair/typebox@^0.32.15": + version "0.32.32" + resolved "https://registry.yarnpkg.com/@sinclair/typebox/-/typebox-0.32.32.tgz#e12172fe394e7adc868c62354f4f677e3196630e" + integrity sha512-m+A3zFSI87TCtoz6vQCSnd+t/kDKL78JmzhKYkON+7SnHSa+794qraIVpm6ozFGK+5svnVOt1LJ7BUEhGkIvgg== + +ansi-styles@^4.1.0: + version "4.3.0" + resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-4.3.0.tgz#edd803628ae71c04c85ae7a0906edad34b648937" + integrity sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg== + dependencies: + color-convert "^2.0.1" + +async@^3.2.3: + version "3.2.5" + resolved "https://registry.yarnpkg.com/async/-/async-3.2.5.tgz#ebd52a8fdaf7a2289a24df399f8d8485c8a46b66" + integrity sha512-baNZyqaaLhyLVKm/DlvdW051MSgO6b8eVfIezl9E5PqWxFgzLm/wQntEW4zOytVburDEr0JlALEpdOFwvErLsg== + +balanced-match@^1.0.0: + version "1.0.2" + resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.2.tgz#e83e3a7e3f300b34cb9d87f615fa0cbf357690ee" + integrity sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw== + +brace-expansion@^1.1.7: + version "1.1.11" + resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd" + integrity sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA== + dependencies: + balanced-match "^1.0.0" + concat-map "0.0.1" + +brace-expansion@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-2.0.1.tgz#1edc459e0f0c548486ecf9fc99f2221364b9a0ae" + integrity sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA== + dependencies: + balanced-match "^1.0.0" + +bullmq@^4.6.0: + version "4.17.0" + resolved "https://registry.yarnpkg.com/bullmq/-/bullmq-4.17.0.tgz#f8f61bea80fb72ab690c1e926de0464f3222f1ea" + integrity sha512-URnHgB01rlCP8RTpmW3kFnvv3vdd2aI1OcBMYQwnqODxGiJUlz9MibDVXE83mq7ee1eS1IvD9lMQqGszX6E5Pw== + dependencies: + cron-parser "^4.6.0" + glob "^8.0.3" + ioredis "^5.3.2" + lodash "^4.17.21" + msgpackr "^1.6.2" + node-abort-controller "^3.1.1" + semver "^7.5.4" + tslib "^2.0.0" + uuid "^9.0.0" + +chalk@^4.0.2: + version "4.1.2" + resolved "https://registry.yarnpkg.com/chalk/-/chalk-4.1.2.tgz#aac4e2b7734a740867aeb16bf02aad556a1e7a01" + integrity sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA== + dependencies: + ansi-styles "^4.1.0" + supports-color "^7.1.0" + +clone@2.x: + version "2.1.2" + resolved "https://registry.yarnpkg.com/clone/-/clone-2.1.2.tgz#1b7f4b9f591f1e8f83670401600345a02887435f" + integrity sha512-3Pe/CF1Nn94hyhIYpjtiLhdCoEoz0DqQ+988E9gmeEdQZlojxnOb74wctFyuwWQHzqyf9X7C7MG8juUpqBJT8w== + +cluster-key-slot@^1.1.0: + version "1.1.2" + resolved "https://registry.yarnpkg.com/cluster-key-slot/-/cluster-key-slot-1.1.2.tgz#88ddaa46906e303b5de30d3153b7d9fe0a0c19ac" + integrity sha512-RMr0FhtfXemyinomL4hrWcYJxmX6deFdCxpJzhDttxgO1+bcCnkk+9drydLVDmAMG7NE6aN/fl4F7ucU/90gAA== + +color-convert@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/color-convert/-/color-convert-2.0.1.tgz#72d3a68d598c9bdb3af2ad1e84f21d896abd4de3" + integrity sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ== + dependencies: + color-name "~1.1.4" + +color-name@~1.1.4: + version "1.1.4" + resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.4.tgz#c2a09a87acbde69543de6f63fa3995c826c536a2" + integrity sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA== + +concat-map@0.0.1: + version "0.0.1" + resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b" + integrity sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg== + +cookie@^0.6.0: + version "0.6.0" + resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.6.0.tgz#2798b04b071b0ecbff0dbb62a505a8efa4e19051" + integrity sha512-U71cyTamuh1CRNCfpGY6to28lxvNwPG4Guz/EVjgf3Jmzv0vlDp1atT9eS5dDjMYHucpHbWns6Lwf3BKz6svdw== + +cron-parser@^4.6.0: + version "4.9.0" + resolved "https://registry.yarnpkg.com/cron-parser/-/cron-parser-4.9.0.tgz#0340694af3e46a0894978c6f52a6dbb5c0f11ad5" + integrity sha512-p0SaNjrHOnQeR8/VnfGbmg9te2kfyYSQ7Sc/j/6DtPL3JQvKxmjO9TSjNFpujqV3vEYYBvNNvXSxzyksBWAx1Q== + dependencies: + luxon "^3.2.1" + +debug@^4.3.4: + version "4.3.5" + resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.5.tgz#e83444eceb9fedd4a1da56d671ae2446a01a6e1e" + integrity sha512-pt0bNEmneDIvdL1Xsd9oDQ/wrQRkXDT4AUWlNZNPKvW5x/jyO9VFXkJUP07vQ2upmw5PlaITaPKc31jK13V+jg== + dependencies: + ms "2.1.2" + +denque@^2.1.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/denque/-/denque-2.1.0.tgz#e93e1a6569fb5e66f16a3c2a2964617d349d6ab1" + integrity sha512-HVQE3AAb/pxF8fQAoiqpvg9i3evqug3hoiwakOyZAwJm+6vZehbkYXZ0l4JxS+I3QxM97v5aaRNhj8v5oBhekw== + +detect-libc@^2.0.1: + version "2.0.3" + resolved "https://registry.yarnpkg.com/detect-libc/-/detect-libc-2.0.3.tgz#f0cd503b40f9939b894697d19ad50895e30cf700" + integrity sha512-bwy0MGW55bG41VqxxypOsdSdGqLwXPI/focwgTYCFMbdUiBAxLg9CFzG08sz2aqzknwiX7Hkl0bQENjg8iLByw== + +ejs@^3.1.10: + version "3.1.10" + resolved "https://registry.yarnpkg.com/ejs/-/ejs-3.1.10.tgz#69ab8358b14e896f80cc39e62087b88500c3ac3b" + integrity sha512-UeJmFfOrAQS8OJWPZ4qtgHyWExa088/MtK5UEyoJGFH67cDEXkZSviOiKRCZ4Xij0zxI3JECgYs3oKx+AizQBA== + dependencies: + jake "^10.8.5" + +elysia@^1.0.22: + version "1.0.23" + resolved "https://registry.yarnpkg.com/elysia/-/elysia-1.0.23.tgz#6ace54f28c4018219734dd4feef27cd38bd65a65" + integrity sha512-484cI3C9bHGMVHuYxvz2qXMOonVix+1AyD1LI0Mgyh+XVDIL4nKqksW/rsyIs7wkfFbt0bz5XbxaOblqBwiXSQ== + dependencies: + "@sinclair/typebox" "^0.32.15" + cookie "^0.6.0" + eventemitter3 "^5.0.1" + fast-decode-uri-component "^1.0.1" + fast-querystring "^1.1.2" + openapi-types "^12.1.3" + +eventemitter3@^5.0.1: + version "5.0.1" + resolved "https://registry.yarnpkg.com/eventemitter3/-/eventemitter3-5.0.1.tgz#53f5ffd0a492ac800721bb42c66b841de96423c4" + integrity sha512-GWkBvjiSZK87ELrYOSESUYeVIc9mvLLf/nXalMOS5dYrgZq9o5OVkbZAVM06CVxYsCwH9BDZFPlQTlPA1j4ahA== + +fast-decode-uri-component@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/fast-decode-uri-component/-/fast-decode-uri-component-1.0.1.tgz#46f8b6c22b30ff7a81357d4f59abfae938202543" + integrity sha512-WKgKWg5eUxvRZGwW8FvfbaH7AXSh2cL+3j5fMGzUMCxWBJ3dV3a7Wz8y2f/uQ0e3B6WmodD3oS54jTQ9HVTIIg== + +fast-querystring@^1.1.2: + version "1.1.2" + resolved "https://registry.yarnpkg.com/fast-querystring/-/fast-querystring-1.1.2.tgz#a6d24937b4fc6f791b4ee31dcb6f53aeafb89f53" + integrity sha512-g6KuKWmFXc0fID8WWH0jit4g0AGBoJhCkJMb1RmbsSEUNvQ+ZC8D6CUZ+GtF8nMzSPXnhiePyyqqipzNNEnHjg== + dependencies: + fast-decode-uri-component "^1.0.1" + +filelist@^1.0.4: + version "1.0.4" + resolved "https://registry.yarnpkg.com/filelist/-/filelist-1.0.4.tgz#f78978a1e944775ff9e62e744424f215e58352b5" + integrity sha512-w1cEuf3S+DrLCQL7ET6kz+gmlJdbq9J7yXCSjK/OZCPA+qEN1WyF4ZAf0YYJa4/shHJra2t/d/r8SV4Ji+x+8Q== + dependencies: + minimatch "^5.0.1" + +fs.realpath@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f" + integrity sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw== + +glob@^8.0.3: + version "8.1.0" + resolved "https://registry.yarnpkg.com/glob/-/glob-8.1.0.tgz#d388f656593ef708ee3e34640fdfb99a9fd1c33e" + integrity sha512-r8hpEjiQEYlF2QU0df3dS+nxxSIreXQS1qRhMJM0Q5NDdR386C7jb7Hwwod8Fgiuex+k0GFjgft18yvxm5XoCQ== + dependencies: + fs.realpath "^1.0.0" + inflight "^1.0.4" + inherits "2" + minimatch "^5.0.1" + once "^1.3.0" + +has-flag@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-4.0.0.tgz#944771fd9c81c81265c4d6941860da06bb59479b" + integrity sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ== + +inflight@^1.0.4: + version "1.0.6" + resolved "https://registry.yarnpkg.com/inflight/-/inflight-1.0.6.tgz#49bd6331d7d02d0c09bc910a1075ba8165b56df9" + integrity sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA== + dependencies: + once "^1.3.0" + wrappy "1" + +inherits@2: + version "2.0.4" + resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c" + integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ== + +ioredis@^5.3.2: + version "5.4.1" + resolved "https://registry.yarnpkg.com/ioredis/-/ioredis-5.4.1.tgz#1c56b70b759f01465913887375ed809134296f40" + integrity sha512-2YZsvl7jopIa1gaePkeMtd9rAcSjOOjPtpcLlOeusyO+XH2SK5ZcT+UCrElPP+WVIInh2TzeI4XW9ENaSLVVHA== + dependencies: + "@ioredis/commands" "^1.1.1" + cluster-key-slot "^1.1.0" + debug "^4.3.4" + denque "^2.1.0" + lodash.defaults "^4.2.0" + lodash.isarguments "^3.1.0" + redis-errors "^1.2.0" + redis-parser "^3.0.0" + standard-as-callback "^2.1.0" + +jake@^10.8.5: + version "10.9.1" + resolved "https://registry.yarnpkg.com/jake/-/jake-10.9.1.tgz#8dc96b7fcc41cb19aa502af506da4e1d56f5e62b" + integrity sha512-61btcOHNnLnsOdtLgA5efqQWjnSi/vow5HbI7HMdKKWqvrKR1bLK3BPlJn9gcSaP2ewuamUSMB5XEy76KUIS2w== + dependencies: + async "^3.2.3" + chalk "^4.0.2" + filelist "^1.0.4" + minimatch "^3.1.2" + +lodash.defaults@^4.2.0: + version "4.2.0" + resolved "https://registry.yarnpkg.com/lodash.defaults/-/lodash.defaults-4.2.0.tgz#d09178716ffea4dde9e5fb7b37f6f0802274580c" + integrity sha512-qjxPLHd3r5DnsdGacqOMU6pb/avJzdh9tFX2ymgoZE27BmjXrNy/y4LoaiTeAb+O3gL8AfpJGtqfX/ae2leYYQ== + +lodash.isarguments@^3.1.0: + version "3.1.0" + resolved "https://registry.yarnpkg.com/lodash.isarguments/-/lodash.isarguments-3.1.0.tgz#2f573d85c6a24289ff00663b491c1d338ff3458a" + integrity sha512-chi4NHZlZqZD18a0imDHnZPrDeBbTtVN7GXMwuGdRH9qotxAjYs3aVLKc7zNOG9eddR5Ksd8rvFEBc9SsggPpg== + +lodash@^4.17.11, lodash@^4.17.21: + version "4.17.21" + resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c" + integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg== + +luxon@^3.2.1: + version "3.4.4" + resolved "https://registry.yarnpkg.com/luxon/-/luxon-3.4.4.tgz#cf20dc27dc532ba41a169c43fdcc0063601577af" + integrity sha512-zobTr7akeGHnv7eBOXcRgMeCP6+uyYsczwmeRCauvpvaAltgNyTbLH/+VaEAPUeWBT+1GuNmz4wC/6jtQzbbVA== + +minimatch@^3.1.2: + version "3.1.2" + resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.1.2.tgz#19cd194bfd3e428f049a70817c038d89ab4be35b" + integrity sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw== + dependencies: + brace-expansion "^1.1.7" + +minimatch@^5.0.1: + version "5.1.6" + resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-5.1.6.tgz#1cfcb8cf5522ea69952cd2af95ae09477f122a96" + integrity sha512-lKwV/1brpG6mBUFHtb7NUmtABCb2WZZmm2wNiOA5hAb8VdCS4B3dtMWyvcoViccwAW/COERjXLt0zP1zXUN26g== + dependencies: + brace-expansion "^2.0.1" + +ms@2.1.2: + version "2.1.2" + resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009" + integrity sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w== + +msgpackr-extract@^3.0.2: + version "3.0.3" + resolved "https://registry.yarnpkg.com/msgpackr-extract/-/msgpackr-extract-3.0.3.tgz#e9d87023de39ce714872f9e9504e3c1996d61012" + integrity sha512-P0efT1C9jIdVRefqjzOQ9Xml57zpOXnIuS+csaB4MdZbTdmGDLo8XhzBG1N7aO11gKDDkJvBLULeFTo46wwreA== + dependencies: + node-gyp-build-optional-packages "5.2.2" + optionalDependencies: + "@msgpackr-extract/msgpackr-extract-darwin-arm64" "3.0.3" + "@msgpackr-extract/msgpackr-extract-darwin-x64" "3.0.3" + "@msgpackr-extract/msgpackr-extract-linux-arm" "3.0.3" + "@msgpackr-extract/msgpackr-extract-linux-arm64" "3.0.3" + "@msgpackr-extract/msgpackr-extract-linux-x64" "3.0.3" + "@msgpackr-extract/msgpackr-extract-win32-x64" "3.0.3" + +msgpackr@^1.6.2: + version "1.10.2" + resolved "https://registry.yarnpkg.com/msgpackr/-/msgpackr-1.10.2.tgz#a73de4767f76659e8c69cf9c80fdfce83937a44a" + integrity sha512-L60rsPynBvNE+8BWipKKZ9jHcSGbtyJYIwjRq0VrIvQ08cRjntGXJYW/tmciZ2IHWIY8WEW32Qa2xbh5+SKBZA== + optionalDependencies: + msgpackr-extract "^3.0.2" + +node-abort-controller@^3.1.1: + version "3.1.1" + resolved "https://registry.yarnpkg.com/node-abort-controller/-/node-abort-controller-3.1.1.tgz#a94377e964a9a37ac3976d848cb5c765833b8548" + integrity sha512-AGK2yQKIjRuqnc6VkX2Xj5d+QW8xZ87pa1UK6yA6ouUyuxfHuMP6umE5QK7UmTeOAymo+Zx1Fxiuw9rVx8taHQ== + +node-cache@^5.1.2: + version "5.1.2" + resolved "https://registry.yarnpkg.com/node-cache/-/node-cache-5.1.2.tgz#f264dc2ccad0a780e76253a694e9fd0ed19c398d" + integrity sha512-t1QzWwnk4sjLWaQAS8CHgOJ+RAfmHpxFWmc36IWTiWHQfs0w5JDMBS1b1ZxQteo0vVVuWJvIUKHDkkeK7vIGCg== + dependencies: + clone "2.x" + +node-gyp-build-optional-packages@5.2.2: + version "5.2.2" + resolved "https://registry.yarnpkg.com/node-gyp-build-optional-packages/-/node-gyp-build-optional-packages-5.2.2.tgz#522f50c2d53134d7f3a76cd7255de4ab6c96a3a4" + integrity sha512-s+w+rBWnpTMwSFbaE0UXsRlg7hU4FjekKU4eyAih5T8nJuNZT1nNsskXpxmeqSK9UzkBl6UgRlnKc8hz8IEqOw== + dependencies: + detect-libc "^2.0.1" + +once@^1.3.0: + version "1.4.0" + resolved "https://registry.yarnpkg.com/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1" + integrity sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w== + dependencies: + wrappy "1" + +openapi-types@^12.1.3: + version "12.1.3" + resolved "https://registry.yarnpkg.com/openapi-types/-/openapi-types-12.1.3.tgz#471995eb26c4b97b7bd356aacf7b91b73e777dd3" + integrity sha512-N4YtSYJqghVu4iek2ZUvcN/0aqH1kRDuNqzcycDxhOUpg7GdvLa2F3DgS6yBNhInhv2r/6I0Flkn7CqL8+nIcw== + +redis-errors@^1.0.0, redis-errors@^1.2.0: + version "1.2.0" + resolved "https://registry.yarnpkg.com/redis-errors/-/redis-errors-1.2.0.tgz#eb62d2adb15e4eaf4610c04afe1529384250abad" + integrity sha512-1qny3OExCf0UvUV/5wpYKf2YwPcOqXzkwKKSmKHiE6ZMQs5heeE/c8eXK+PNllPvmjgAbfnsbpkGZWy8cBpn9w== + +redis-info@^3.0.8: + version "3.1.0" + resolved "https://registry.yarnpkg.com/redis-info/-/redis-info-3.1.0.tgz#5e349c8720e82d27ac84c73136dce0931e10469a" + integrity sha512-ER4L9Sh/vm63DkIE0bkSjxluQlioBiBgf5w1UuldaW/3vPcecdljVDisZhmnCMvsxHNiARTTDDHGg9cGwTfrKg== + dependencies: + lodash "^4.17.11" + +redis-parser@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/redis-parser/-/redis-parser-3.0.0.tgz#b66d828cdcafe6b4b8a428a7def4c6bcac31c8b4" + integrity sha512-DJnGAeenTdpMEH6uAJRK/uiyEIH9WVsUmoLwzudwGJUwZPp80PDBWPHXSAGNPwNvIXAbe7MSUB1zQFugFml66A== + dependencies: + redis-errors "^1.0.0" + +semver@^7.5.4: + version "7.6.2" + resolved "https://registry.yarnpkg.com/semver/-/semver-7.6.2.tgz#1e3b34759f896e8f14d6134732ce798aeb0c6e13" + integrity sha512-FNAIBWCx9qcRhoHcgcJ0gvU7SN1lYU2ZXuSfl04bSC5OpvDHFyJCjdNHomPXxjQlCBU67YW64PzY7/VIEH7F2w== + +standard-as-callback@^2.1.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/standard-as-callback/-/standard-as-callback-2.1.0.tgz#8953fc05359868a77b5b9739a665c5977bb7df45" + integrity sha512-qoRRSyROncaz1z0mvYqIE4lCd9p2R90i6GxW3uZv5ucSu8tU7B5HXUP1gG8pVZsYNVaXjk8ClXHPttLyxAL48A== + +supports-color@^7.1.0: + version "7.2.0" + resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-7.2.0.tgz#1b7dcdcb32b8138801b3e478ba6a51caa89648da" + integrity sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw== + dependencies: + has-flag "^4.0.0" + +tslib@^2.0.0: + version "2.6.3" + resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.6.3.tgz#0438f810ad7a9edcde7a241c3d80db693c8cbfe0" + integrity sha512-xNvxJEOUiWPGhUuUdQgAJPKOOJfGnIyKySOc09XkKsgdUV/3E2zvwZYdejjmRgPCgcym1juLH3226yA7sEFJKQ== + +uuid@^9.0.0: + version "9.0.1" + resolved "https://registry.yarnpkg.com/uuid/-/uuid-9.0.1.tgz#e188d4c8853cc722220392c424cd637f32293f30" + integrity sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA== + +wrappy@1: + version "1.0.2" + resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f" + integrity sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ== diff --git a/packages/api/tsconfig.json b/packages/api/tsconfig.json index 8233d290..90aef305 100644 --- a/packages/api/tsconfig.json +++ b/packages/api/tsconfig.json @@ -12,7 +12,8 @@ "noUnusedParameters": true, "noUnusedLocals": true, "resolveJsonModule": true, - "declaration": true + "declaration": true, + "skipLibCheck": true }, "include": ["./src", "./typings/*.ts"] } diff --git a/packages/elysia/README.md b/packages/elysia/README.md new file mode 100644 index 00000000..a00581c9 --- /dev/null +++ b/packages/elysia/README.md @@ -0,0 +1,29 @@ +# @bull-board @bull-board/elysia + +[Elysia](https://github.com/elysiajs/elysia) server adapter for `bull-board`. + +

+ + npm version + + + npm downloads + + + licence + +

+ +![Overview](https://raw.githubusercontent.com/felixmosh/bull-board/master/screenshots/overview.png) +![UI](https://raw.githubusercontent.com/felixmosh/bull-board/master/screenshots/dashboard.png) + +# Usage examples + +1. [Simple Elysia setup](https://github.com/felixmosh/bull-board/tree/master/examples/with-elysia) + +For more info visit the main [README](https://github.com/felixmosh/bull-board#readme) + +### Authors + +- [@kravetsone](https://github.com/kravetsone) - author of this adapter +- [@felixmosh](https://github.com/felixmosh) - author of bull board core diff --git a/packages/elysia/package.json b/packages/elysia/package.json new file mode 100644 index 00000000..b6fe5d9b --- /dev/null +++ b/packages/elysia/package.json @@ -0,0 +1,53 @@ +{ + "name": "@bull-board/elysia", + "type": "commonjs", + "version": "5.20.1", + "description": "A Elysia server adapter for Bull-Board dashboard.", + "keywords": [ + "bull", + "bullmq", + "redis", + "elysia", + "elysia-plugin", + "adapter", + "queue", + "monitoring", + "dashboard" + ], + "repository": { + "type": "git", + "url": "git+https://github.com/felixmosh/bull-board.git", + "directory": "packages/elysia" + }, + "license": "MIT", + "author": { + "name": "kravetsone", + "url": "https://github.com/kravetsone" + }, + "main": "./dist/index.js", + "types": "./dist/index.d.ts", + "files": [ + "dist" + ], + "scripts": { + "build": "tsc", + "clean": "rm -rf dist" + }, + "dependencies": { + "@bull-board/api": "6.3.3", + "@bull-board/ui": "6.3.3", + "@elysiajs/static": "^1.1.1", + "ejs": "^3.1.10" + }, + "peerDependencies": { + "elysia": "^1.0.22" + }, + "publishConfig": { + "access": "public" + }, + "devDependencies": { + "@types/bun": "^1.1.13", + "@types/ejs": "^3.1.5", + "elysia": "^1.1.24" + } +} diff --git a/packages/elysia/src/ElysiaAdapter.ts b/packages/elysia/src/ElysiaAdapter.ts new file mode 100644 index 00000000..ebdf9ddf --- /dev/null +++ b/packages/elysia/src/ElysiaAdapter.ts @@ -0,0 +1,180 @@ +import type { + AppControllerRoute, + AppViewRoute, + BullBoardQueues, + ControllerHandlerReturnType, + HTTPMethod, + IServerAdapter, + UIConfig, +} from "@bull-board/api/dist/typings/app"; +import staticPlugin from "@elysiajs/static"; +import ejs from "ejs"; +import { Elysia } from "elysia"; + +export class ElysiaAdapter implements IServerAdapter { + private plugin: Elysia; + private basePath = ""; + + constructor(basePath = "") { + this.basePath = basePath; + this.plugin = new Elysia({ + name: "@bull-board/elysia", + prefix: basePath, + }); + } + + private entryRoute: AppViewRoute | undefined; + private statics: { path: string; route: string } | undefined; + private bullBoardQueues: BullBoardQueues | undefined; + private viewPath: string | undefined; + private uiConfig: UIConfig = {}; + + public setStaticPath( + staticsRoute: string, + staticsPath: string, + ): ElysiaAdapter { + this.statics = { route: staticsRoute, path: staticsPath }; + + return this; + } + + public setViewsPath(viewPath: string): ElysiaAdapter { + this.viewPath = viewPath; + + return this; + } + + public setErrorHandler( + handler: (error: Error) => ControllerHandlerReturnType, + ) { + this.plugin.onError(({ error, set }) => { + const response = handler(error); + set.status = response.status || 500; + + return response.body; + }); + + return this; + } + + public setApiRoutes(routes: AppControllerRoute[]): ElysiaAdapter { + for (const { route, handler, method } of routes) { + const methods = Array.isArray(method) ? method : [method]; + + for (const method of methods) { + this.registerRoute(route, method, handler); + } + } + + return this; + } + + public setEntryRoute(routeDef: AppViewRoute): ElysiaAdapter { + this.entryRoute = routeDef; + + return this; + } + + public setQueues(bullBoardQueues: BullBoardQueues): ElysiaAdapter { + this.bullBoardQueues = bullBoardQueues; + return this; + } + + public setUIConfig(config: UIConfig = {}): ElysiaAdapter { + this.uiConfig = config; + + return this; + } + + public registerPlugin() { + if (!this.statics) { + throw new Error( + `Please call 'setStaticPath' before using 'registerHandlers'`, + ); + } + if (!this.entryRoute) { + throw new Error( + `Please call 'setEntryRoute' before using 'registerHandlers'`, + ); + } + if (!this.viewPath) { + throw new Error( + `Please call 'setViewsPath' before using 'registerHandlers'`, + ); + } + + if (!this.uiConfig) { + throw new Error( + `Please call 'setUIConfig' before using 'registerHandlers'`, + ); + } + + const { method, route, handler } = this.entryRoute; + + const routes = Array.isArray(route) ? route : [route]; + + for (const route of routes) { + this.plugin.route(method.toUpperCase(), route, async () => { + const { name: filename, params } = handler({ + basePath: this.basePath, + uiConfig: this.uiConfig, + }); + + return new Response( + await ejs.renderFile(`${this.viewPath}/${filename}`, params), + { + headers: { + "content-type": "text/html", + }, + }, + ); + }); + } + + this.plugin.use( + staticPlugin({ + prefix: this.statics.route, + assets: this.statics.path, + }), + ); + + return this.plugin; + } + + private registerRoute( + routeOrRoutes: string | string[], + method: HTTPMethod, + handler: AppControllerRoute["handler"], + ) { + const { bullBoardQueues } = this; + + if (!bullBoardQueues) { + throw new Error( + `Please call 'setQueues' before using 'registerHandlers'`, + ); + } + + const routes = Array.isArray(routeOrRoutes) + ? routeOrRoutes + : [routeOrRoutes]; + + for (const route of routes) { + this.plugin.route( + method.toUpperCase(), + route, + async ({ params, body, query, set }) => { + const response = await handler({ + queues: this.bullBoardQueues as BullBoardQueues, + params, + body: body as Record, + query, + }); + + if(response.status) set.status = response.status; + + return response.body; + }, + ); + } + } +} diff --git a/packages/elysia/src/index.ts b/packages/elysia/src/index.ts new file mode 100644 index 00000000..1711f391 --- /dev/null +++ b/packages/elysia/src/index.ts @@ -0,0 +1 @@ +export * from "./ElysiaAdapter"; diff --git a/packages/elysia/tsconfig.json b/packages/elysia/tsconfig.json new file mode 100644 index 00000000..231300fe --- /dev/null +++ b/packages/elysia/tsconfig.json @@ -0,0 +1,25 @@ +{ + "compilerOptions": { + "outDir": "dist", + "esModuleInterop": true, + "lib": [ + "es2019", + "DOM" + ], + "module": "CommonJS", + "moduleResolution": "node", + "noImplicitAny": true, + "sourceMap": true, + "strict": true, + "target": "es2019", + "noUnusedParameters": true, + "noUnusedLocals": true, + "resolveJsonModule": true, + "declaration": true, + "skipLibCheck": true + }, + "include": [ + "./src", + "./typings/*.d.ts" + ] +} \ No newline at end of file diff --git a/packages/express/tsconfig.json b/packages/express/tsconfig.json index e03a32cf..09fc71b6 100644 --- a/packages/express/tsconfig.json +++ b/packages/express/tsconfig.json @@ -12,7 +12,8 @@ "noUnusedParameters": true, "noUnusedLocals": true, "resolveJsonModule": true, - "declaration": true + "declaration": true, + "skipLibCheck": true }, "include": ["./src", "./typings/*.d.ts"] } diff --git a/packages/fastify/tsconfig.json b/packages/fastify/tsconfig.json index e03a32cf..09fc71b6 100644 --- a/packages/fastify/tsconfig.json +++ b/packages/fastify/tsconfig.json @@ -12,7 +12,8 @@ "noUnusedParameters": true, "noUnusedLocals": true, "resolveJsonModule": true, - "declaration": true + "declaration": true, + "skipLibCheck": true }, "include": ["./src", "./typings/*.d.ts"] } diff --git a/packages/hapi/tsconfig.json b/packages/hapi/tsconfig.json index e03a32cf..09fc71b6 100644 --- a/packages/hapi/tsconfig.json +++ b/packages/hapi/tsconfig.json @@ -12,7 +12,8 @@ "noUnusedParameters": true, "noUnusedLocals": true, "resolveJsonModule": true, - "declaration": true + "declaration": true, + "skipLibCheck": true }, "include": ["./src", "./typings/*.d.ts"] } diff --git a/packages/hono/tsconfig.json b/packages/hono/tsconfig.json index 59f5bfff..3a05cf07 100644 --- a/packages/hono/tsconfig.json +++ b/packages/hono/tsconfig.json @@ -12,7 +12,8 @@ "noUnusedParameters": true, "noUnusedLocals": true, "resolveJsonModule": true, - "declaration": true + "declaration": true, + "skipLibCheck": true }, "include": ["./src", "./typings/*.d.ts"] } diff --git a/packages/koa/tsconfig.json b/packages/koa/tsconfig.json index e03a32cf..09fc71b6 100644 --- a/packages/koa/tsconfig.json +++ b/packages/koa/tsconfig.json @@ -12,7 +12,8 @@ "noUnusedParameters": true, "noUnusedLocals": true, "resolveJsonModule": true, - "declaration": true + "declaration": true, + "skipLibCheck": true }, "include": ["./src", "./typings/*.d.ts"] } diff --git a/packages/ui/tsconfig.json b/packages/ui/tsconfig.json index f29f804a..b5786086 100644 --- a/packages/ui/tsconfig.json +++ b/packages/ui/tsconfig.json @@ -14,7 +14,8 @@ "noUnusedLocals": true, "resolveJsonModule": true, "declaration": true, - "noEmit": true + "noEmit": true, + "skipLibCheck": true }, "include": ["./src", "./typings/*.d.ts"] } diff --git a/tsconfig.json b/tsconfig.json index 99b9f092..5922b021 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -11,6 +11,7 @@ "noUnusedParameters": true, "noUnusedLocals": true, "resolveJsonModule": true, - "declaration": true + "declaration": true, + "skipLibCheck": true }, } diff --git a/yarn.lock b/yarn.lock index 30537811..24930196 100644 --- a/yarn.lock +++ b/yarn.lock @@ -500,6 +500,13 @@ dependencies: "@jridgewell/trace-mapping" "0.3.9" +"@elysiajs/static@^1.1.1": + version "1.1.1" + resolved "https://registry.yarnpkg.com/@elysiajs/static/-/static-1.1.1.tgz#f6ba0406a1e9cd7614aeaad754d6481252513e72" + integrity sha512-H1KqsuNHhHKYKUkPoies0pPQBgbA4qsfre840FKraeF99jz++2P/igrOagp8cWqwFGrHP1V+nwGlGm9U6rZAEg== + dependencies: + node-cache "^5.1.2" + "@eslint-community/eslint-utils@^4.2.0": version "4.4.0" resolved "https://registry.yarnpkg.com/@eslint-community/eslint-utils/-/eslint-utils-4.4.0.tgz#a23514e8fb9af1269d5f7788aa556798d61c6b59" @@ -3125,6 +3132,11 @@ resolved "https://registry.yarnpkg.com/@sideway/pinpoint/-/pinpoint-2.0.0.tgz#cff8ffadc372ad29fd3f78277aeb29e632cc70df" integrity sha512-RNiOoTPkptFtSVzQevY/yWtZwf/RxyVnPy/OcA9HBM3MlGDnBEYL5B41H0MTn0Uec8Hi+2qUtTfG2WWZBmMejQ== +"@sinclair/typebox@0.32.34": + version "0.32.34" + resolved "https://registry.yarnpkg.com/@sinclair/typebox/-/typebox-0.32.34.tgz#a1c59d4df30982263cc7aa64c2c853878050838d" + integrity sha512-a3Z3ytYl6R/+7ldxx04PO1semkwWlX/8pTqxsPw4quIcIXDFPZhOc1Wx8azWmkU26ccK3mHwcWenn0avNgAKQg== + "@sinclair/typebox@^0.27.8": version "0.27.8" resolved "https://registry.yarnpkg.com/@sinclair/typebox/-/typebox-0.27.8.tgz#6667fac16c436b5434a387a34dedb013198f6e6e" @@ -3236,6 +3248,13 @@ "@types/connect" "*" "@types/node" "*" +"@types/bun@^1.1.13": + version "1.1.13" + resolved "https://registry.yarnpkg.com/@types/bun/-/bun-1.1.13.tgz#a53b3a64c8f539bbe33ceb0a9f3b98c6a79a3407" + integrity sha512-KmQxSBgVWCl6RSuerlLGZlIWfdxkKqat0nxN61+qu4y1KDn0Ll3j7v1Pl8GnaL3a/U6GGWVTJh75ap62kR1E8Q== + dependencies: + bun-types "1.1.34" + "@types/co-body@^6.1.3": version "6.1.3" resolved "https://registry.yarnpkg.com/@types/co-body/-/co-body-6.1.3.tgz#201796c6389066b400cfcb4e1ec5c3db798265a2" @@ -3538,6 +3557,13 @@ dependencies: undici-types "~5.26.4" +"@types/node@~20.12.8": + version "20.12.14" + resolved "https://registry.yarnpkg.com/@types/node/-/node-20.12.14.tgz#0c5cf7ef26aedfd64b0539bba9380ed1f57dcc77" + integrity sha512-scnD59RpYD91xngrQQLGkE+6UrHUPzeKZWhhjBSa3HSkwjbQc38+q3RoIVEwxQGRw3M+j5hpNAM+lgV3cVormg== + dependencies: + undici-types "~5.26.4" + "@types/normalize-package-data@^2.4.0": version "2.4.1" resolved "https://registry.yarnpkg.com/@types/normalize-package-data/-/normalize-package-data-2.4.1.tgz#d3357479a0fdfdd5907fe67e17e0a85c906e1301" @@ -3563,7 +3589,7 @@ resolved "https://registry.yarnpkg.com/@types/range-parser/-/range-parser-1.2.4.tgz#cd667bcfdd025213aafb7ca5915a932590acdcdc" integrity sha512-EEhsLsD6UsDM1yFhAvy0Cjr6VwmpMWqFBCb9w07wVugF7w9nfajxLuVmngTIpgS6svCnm6Vaw+MZhoDCKnOfsw== -"@types/react-dom@^17.0.14": +"@types/react-dom@17.0.20", "@types/react-dom@^17.0.14": version "17.0.20" resolved "https://registry.yarnpkg.com/@types/react-dom/-/react-dom-17.0.20.tgz#e0c8901469d732b36d8473b40b679ad899da1b53" integrity sha512-4pzIjSxDueZZ90F52mU3aPoogkHIoSIDG+oQ+wQK7Cy2B9S+MvOqY0uEA/qawKz381qrEDkvpwyt8Bm31I8sbA== @@ -3594,7 +3620,7 @@ "@types/history" "^4.7.11" "@types/react" "*" -"@types/react@*", "@types/react@^17", "@types/react@^17.0.14": +"@types/react@*", "@types/react@17.0.63", "@types/react@^17", "@types/react@^17.0.14": version "17.0.63" resolved "https://registry.yarnpkg.com/@types/react/-/react-17.0.63.tgz#78ca41a34b1e4fd5ba9398d33bc78a81bfd5c180" integrity sha512-T+aaG8RlIkgJ4VzWLJYbMW9QX7sIAV8CcuyV6FU6Hm7yu3Bee1YBZQRu2vYEm/dU8kre+/mzl2aGYh5MFgVLaQ== @@ -3670,6 +3696,13 @@ resolved "https://registry.yarnpkg.com/@types/unist/-/unist-3.0.3.tgz#acaab0f919ce69cce629c2d4ed2eb4adc1b6c20c" integrity sha512-ko/gIFJRv177XgZsZcBwnqJN5x/Gien8qNOn0D5bQU/zAzVf9Zt3BlcUiLqhV9y4ARk0GbT3tnUiPNgnTXzc/Q== +"@types/ws@~8.5.10": + version "8.5.10" + resolved "https://registry.yarnpkg.com/@types/ws/-/ws-8.5.10.tgz#4acfb517970853fa6574a3a6886791d04a396787" + integrity sha512-vmQSUcfalpIq0R9q7uTo2lXs6eGIpt9wtnLdMv9LVpIjCA/+ufZRozlVoVelIYixx1ugCBKDhn89vnsEGOCx9A== + dependencies: + "@types/node" "*" + "@types/yargs-parser@*": version "21.0.0" resolved "https://registry.yarnpkg.com/@types/yargs-parser/-/yargs-parser-21.0.0.tgz#0c60e537fa790f5f9472ed2776c2b71ec117351b" @@ -4633,6 +4666,14 @@ bullmq@^4.6.0: tslib "^2.0.0" uuid "^9.0.0" +bun-types@1.1.34: + version "1.1.34" + resolved "https://registry.yarnpkg.com/bun-types/-/bun-types-1.1.34.tgz#cf0e1dc5aa8875573a3acb09bead0f23bab5aca2" + integrity sha512-br5QygTEL/TwB4uQOb96Ky22j4Gq2WxWH/8Oqv20fk5HagwKXo/akB+LiYgSfzexCt6kkcUaVm+bKiPl71xPvw== + dependencies: + "@types/node" "~20.12.8" + "@types/ws" "~8.5.10" + bundle-name@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/bundle-name/-/bundle-name-3.0.0.tgz#ba59bcc9ac785fb67ccdbf104a2bf60c099f0e1a" @@ -4931,6 +4972,11 @@ clone-deep@^4.0.1: kind-of "^6.0.2" shallow-clone "^3.0.0" +clone@2.x: + version "2.1.2" + resolved "https://registry.yarnpkg.com/clone/-/clone-2.1.2.tgz#1b7f4b9f591f1e8f83670401600345a02887435f" + integrity sha512-3Pe/CF1Nn94hyhIYpjtiLhdCoEoz0DqQ+988E9gmeEdQZlojxnOb74wctFyuwWQHzqyf9X7C7MG8juUpqBJT8w== + clone@^1.0.2: version "1.0.4" resolved "https://registry.yarnpkg.com/clone/-/clone-1.0.4.tgz#da309cc263df15994c688ca902179ca3c7cd7c7e" @@ -5283,6 +5329,11 @@ cookie@^0.6.0: resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.6.0.tgz#2798b04b071b0ecbff0dbb62a505a8efa4e19051" integrity sha512-U71cyTamuh1CRNCfpGY6to28lxvNwPG4Guz/EVjgf3Jmzv0vlDp1atT9eS5dDjMYHucpHbWns6Lwf3BKz6svdw== +cookie@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/cookie/-/cookie-1.0.1.tgz#e1a00d20420e0266aff817815640289eef142751" + integrity sha512-Xd8lFX4LM9QEEwxQpF9J9NTUh8pmdJO0cyRJhFiDoLTk2eH8FXlRv2IFGYVadZpqI3j8fhNrSdKCeYPxiAhLXw== + cookiejar@^2.1.4: version "2.1.4" resolved "https://registry.yarnpkg.com/cookiejar/-/cookiejar-2.1.4.tgz#ee669c1fea2cf42dc31585469d193fef0d65771b" @@ -5777,9 +5828,19 @@ electron-to-chromium@^1.4.477: integrity sha512-FFa8QKjQK/A5QuFr2167myhMesGrhlOBD+3cYNxO9/S4XzHEXesyTD/1/xF644gC8buFPz3ca6G1LOQD0tZrrg== electron-to-chromium@^1.5.28: - version "1.5.35" - resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.5.35.tgz#1d38d386186c72b1fa6e74c3a7de5f888b503100" - integrity sha512-hOSRInrIDm0Brzp4IHW2F/VM+638qOL2CzE0DgpnGzKW27C95IqqeqgKz/hxHGnvPxvQGpHUGD5qRVC9EZY2+A== + version "1.5.55" + resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.5.55.tgz#73684752aa2e1aa49cafb355a41386c6637e76a9" + integrity sha512-6maZ2ASDOTBtjt9FhqYPRnbvKU5tjG0IN9SztUOWYw2AzNDNpKJYLJmlK0/En4Hs/aiWnB+JZ+gW19PIGszgKg== + +elysia@^1.1.24: + version "1.1.24" + resolved "https://registry.yarnpkg.com/elysia/-/elysia-1.1.24.tgz#093eeb60c8338e4e14bae33e3718b54682dbcabe" + integrity sha512-viJOb+PADrxJn7ntlQfoXsLuVgHNS09gn9dj2yroHnwqheN0hZp81WCGRQXkvh4kW5zGISX50/eqAcoNDpdL/g== + dependencies: + "@sinclair/typebox" "0.32.34" + cookie "^1.0.1" + fast-decode-uri-component "^1.0.1" + openapi-types "^12.1.3" emittery@^0.13.1: version "0.13.1" @@ -9635,6 +9696,13 @@ node-abort-controller@^3.0.1, node-abort-controller@^3.1.1: resolved "https://registry.yarnpkg.com/node-abort-controller/-/node-abort-controller-3.1.1.tgz#a94377e964a9a37ac3976d848cb5c765833b8548" integrity sha512-AGK2yQKIjRuqnc6VkX2Xj5d+QW8xZ87pa1UK6yA6ouUyuxfHuMP6umE5QK7UmTeOAymo+Zx1Fxiuw9rVx8taHQ== +node-cache@^5.1.2: + version "5.1.2" + resolved "https://registry.yarnpkg.com/node-cache/-/node-cache-5.1.2.tgz#f264dc2ccad0a780e76253a694e9fd0ed19c398d" + integrity sha512-t1QzWwnk4sjLWaQAS8CHgOJ+RAfmHpxFWmc36IWTiWHQfs0w5JDMBS1b1ZxQteo0vVVuWJvIUKHDkkeK7vIGCg== + dependencies: + clone "2.x" + node-domexception@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/node-domexception/-/node-domexception-1.0.0.tgz#6888db46a1f71c0b76b3f7555016b63fe64766e5" @@ -10031,6 +10099,11 @@ open@9.1.0: is-inside-container "^1.0.0" is-wsl "^2.2.0" +openapi-types@^12.1.3: + version "12.1.3" + resolved "https://registry.yarnpkg.com/openapi-types/-/openapi-types-12.1.3.tgz#471995eb26c4b97b7bd356aacf7b91b73e777dd3" + integrity sha512-N4YtSYJqghVu4iek2ZUvcN/0aqH1kRDuNqzcycDxhOUpg7GdvLa2F3DgS6yBNhInhv2r/6I0Flkn7CqL8+nIcw== + optionator@^0.8.1: version "0.8.3" resolved "https://registry.yarnpkg.com/optionator/-/optionator-0.8.3.tgz#84fa1d036fe9d3c7e21d99884b601167ec8fb495"