From d412a62b3a4a667f3a04839bfb6772f9678b73da Mon Sep 17 00:00:00 2001 From: James Martinez Date: Wed, 4 Feb 2026 17:16:55 -0600 Subject: [PATCH 1/3] Add support for Bun --- packages/openworkflow/sqlite/backend.ts | 8 ++---- packages/openworkflow/sqlite/sqlite.ts | 34 ++++++++++++++++++++++--- 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/packages/openworkflow/sqlite/backend.ts b/packages/openworkflow/sqlite/backend.ts index 3c913c3f..ba875cb2 100644 --- a/packages/openworkflow/sqlite/backend.ts +++ b/packages/openworkflow/sqlite/backend.ts @@ -532,9 +532,7 @@ export class BackendSqlite implements Backend { }); } - const rows = rawRows.map((row) => - rowToWorkflowRun(row as unknown as WorkflowRunRow), - ); + const rows = rawRows.map((row) => rowToWorkflowRun(row as WorkflowRunRow)); return Promise.resolve( this.processPaginationResults(rows, limit, !!after, !!before), @@ -601,9 +599,7 @@ export class BackendSqlite implements Backend { }); } - const rows = rawRows.map((row) => - rowToStepAttempt(row as unknown as StepAttemptRow), - ); + const rows = rawRows.map((row) => rowToStepAttempt(row as StepAttemptRow)); return Promise.resolve( this.processPaginationResults(rows, limit, !!after, !!before), diff --git a/packages/openworkflow/sqlite/sqlite.ts b/packages/openworkflow/sqlite/sqlite.ts index 332ea26e..ba2e78c9 100644 --- a/packages/openworkflow/sqlite/sqlite.ts +++ b/packages/openworkflow/sqlite/sqlite.ts @@ -1,15 +1,43 @@ import { randomUUID } from "node:crypto"; -import { DatabaseSync } from "node:sqlite"; -export type Database = DatabaseSync; +/** + * Common database interface that both Node and Bun SQLite drivers satisfy. + */ +export interface Database { + exec(sql: string): void; + prepare(sql: string): { + run(...params: unknown[]): { changes: number }; + get(...params: unknown[]): unknown; + all(...params: unknown[]): unknown[]; + }; + close(): void; +} /** * newDatabase creates a new SQLite database connection. + * Uses node:sqlite in Node.js or bun:sqlite in Bun. * @param path - Database file path (or ":memory:") for testing * @returns SQLite database connection */ export function newDatabase(path: string): Database { - const db = new DatabaseSync(path); + let db: Database; + + const isBun = (globalThis as { Bun?: unknown }).Bun !== undefined; + + if (isBun) { + // eslint-disable-next-line @typescript-eslint/no-require-imports + const { Database: BunDatabase } = require("bun:sqlite") as { + Database: new (path: string) => Database; + }; + db = new BunDatabase(path); + } else { + // eslint-disable-next-line @typescript-eslint/no-require-imports + const { DatabaseSync } = require("node:sqlite") as { + DatabaseSync: new (path: string) => Database; + }; + db = new DatabaseSync(path); + } + // Only enable WAL mode for file-based databases if (path !== ":memory:") { db.exec("PRAGMA journal_mode = WAL;"); From 76d1a5f3b1c36d3a300510e6ca1e913a89b9f192 Mon Sep 17 00:00:00 2001 From: James Martinez Date: Wed, 4 Feb 2026 17:34:29 -0600 Subject: [PATCH 2/3] Update docs for Bun support --- packages/docs/docs/cli.mdx | 35 ++++++++++++++++++++++++++++ packages/docs/docs/configuration.mdx | 4 ++++ packages/docs/docs/core-concepts.mdx | 4 ++++ packages/docs/docs/dashboard.mdx | 4 ++++ packages/docs/docs/migration-v6.mdx | 12 ++++++++++ packages/docs/docs/namespaces.mdx | 9 +++++++ packages/docs/docs/postgres.mdx | 4 ++++ packages/docs/docs/production.mdx | 4 ++++ packages/docs/docs/quickstart.mdx | 16 +++++++++++++ packages/docs/docs/retries.mdx | 4 ++++ packages/docs/docs/sqlite.mdx | 2 +- packages/docs/docs/workers.mdx | 24 +++++++++++++++++++ packages/docs/index.mdx | 4 ++++ 13 files changed, 125 insertions(+), 1 deletion(-) diff --git a/packages/docs/docs/cli.mdx b/packages/docs/docs/cli.mdx index 6f79e912..e61ea9b9 100644 --- a/packages/docs/docs/cli.mdx +++ b/packages/docs/docs/cli.mdx @@ -17,6 +17,10 @@ npm install -D @openworkflow/cli pnpm add -D @openworkflow/cli ``` +```bash bun +bun add -D @openworkflow/cli +``` + ## Commands @@ -34,6 +38,10 @@ npx @openworkflow/cli init pnpx @openworkflow/cli init ``` +```bash bun +bunx @openworkflow/cli init +``` + This interactive command: @@ -59,6 +67,10 @@ npx @openworkflow/cli worker start pnpx @openworkflow/cli worker start ``` +```bash bun +bunx @openworkflow/cli worker start +``` + Options: @@ -77,6 +89,11 @@ npx @openworkflow/cli worker start --concurrency 4 pnpx @openworkflow/cli worker start --concurrency 4 ``` +```bash bun +# Run with 4 concurrent workflows +bunx @openworkflow/cli worker start --concurrency 4 +``` + The worker: @@ -100,6 +117,10 @@ npx @openworkflow/cli dashboard pnpx @openworkflow/cli dashboard ``` +```bash bun +bunx @openworkflow/cli dashboard +``` + This launches the OpenWorkflow dashboard on `http://localhost:3000`. See @@ -118,6 +139,10 @@ npx @openworkflow/cli doctor pnpx @openworkflow/cli doctor ``` +```bash bun +bunx @openworkflow/cli doctor +``` + This command checks: @@ -164,6 +189,10 @@ npx @openworkflow/cli --version pnpx @openworkflow/cli --version ``` +```bash bun +bunx @openworkflow/cli --version +``` + ### `--help` @@ -183,6 +212,12 @@ pnpx @openworkflow/cli worker --help pnpx @openworkflow/cli worker start --help ``` +```bash bun +bunx @openworkflow/cli --help +bunx @openworkflow/cli worker --help +bunx @openworkflow/cli worker start --help +``` + ## Environment Variables diff --git a/packages/docs/docs/configuration.mdx b/packages/docs/docs/configuration.mdx index ca42ad26..77cc8cb1 100644 --- a/packages/docs/docs/configuration.mdx +++ b/packages/docs/docs/configuration.mdx @@ -17,6 +17,10 @@ npm i openworkflow postgres pnpm add openworkflow postgres ``` +```bash bun +bun add openworkflow postgres +``` + ## Config File diff --git a/packages/docs/docs/core-concepts.mdx b/packages/docs/docs/core-concepts.mdx index 0cfa9677..d5aa7ff3 100644 --- a/packages/docs/docs/core-concepts.mdx +++ b/packages/docs/docs/core-concepts.mdx @@ -71,6 +71,10 @@ npx @openworkflow/cli worker start pnpx @openworkflow/cli worker start ``` +```bash bun +bunx @openworkflow/cli worker start +``` + ## How it Works diff --git a/packages/docs/docs/dashboard.mdx b/packages/docs/docs/dashboard.mdx index 5334d993..6f815252 100644 --- a/packages/docs/docs/dashboard.mdx +++ b/packages/docs/docs/dashboard.mdx @@ -17,6 +17,10 @@ npx @openworkflow/cli dashboard pnpx @openworkflow/cli dashboard ``` +```bash bun +bunx @openworkflow/cli dashboard +``` + The dashboard starts on `http://localhost:3000`. diff --git a/packages/docs/docs/migration-v6.mdx b/packages/docs/docs/migration-v6.mdx index 0836eead..1f0db5e6 100644 --- a/packages/docs/docs/migration-v6.mdx +++ b/packages/docs/docs/migration-v6.mdx @@ -36,6 +36,10 @@ npm uninstall @openworkflow/backend-postgres @openworkflow/backend-sqlite pnpm remove @openworkflow/backend-postgres @openworkflow/backend-sqlite ``` +```bash bun +bun remove @openworkflow/backend-postgres @openworkflow/backend-sqlite +``` + If you're using PostgreSQL, install the `postgres` driver directly: @@ -49,6 +53,10 @@ npm install postgres pnpm add postgres ``` +```bash bun +bun add postgres +``` + Your `package.json` should now look like: @@ -79,6 +87,10 @@ npx @openworkflow/cli init pnpx @openworkflow/cli init ``` +```bash bun +bunx @openworkflow/cli init +``` + The CLI now generates code with the new import paths automatically. diff --git a/packages/docs/docs/namespaces.mdx b/packages/docs/docs/namespaces.mdx index 9c4f0ea5..4a2a8016 100644 --- a/packages/docs/docs/namespaces.mdx +++ b/packages/docs/docs/namespaces.mdx @@ -79,6 +79,15 @@ NAMESPACE=staging pnpm run worker NAMESPACE=production pnpm run worker ``` +```bash bun +# Development +NAMESPACE=development bun run worker +# Staging +NAMESPACE=staging bun run worker +# Production +NAMESPACE=production bun run worker +``` + ### Multi-Tenancy diff --git a/packages/docs/docs/postgres.mdx b/packages/docs/docs/postgres.mdx index e464353f..570d955b 100644 --- a/packages/docs/docs/postgres.mdx +++ b/packages/docs/docs/postgres.mdx @@ -20,6 +20,10 @@ npm i openworkflow postgres pnpm add openworkflow postgres ``` +```bash bun +bun add openworkflow postgres +``` + ## Setup diff --git a/packages/docs/docs/production.mdx b/packages/docs/docs/production.mdx index 38deb6cf..ccabbfbd 100644 --- a/packages/docs/docs/production.mdx +++ b/packages/docs/docs/production.mdx @@ -45,6 +45,10 @@ npx @openworkflow/cli dashboard pnpx @openworkflow/cli dashboard ``` +```bash bun +bunx @openworkflow/cli dashboard +``` + - Review step attempts and errors for failed workflows diff --git a/packages/docs/docs/quickstart.mdx b/packages/docs/docs/quickstart.mdx index 1a06b7d1..f74c7b13 100644 --- a/packages/docs/docs/quickstart.mdx +++ b/packages/docs/docs/quickstart.mdx @@ -21,6 +21,10 @@ npx @openworkflow/cli init pnpx @openworkflow/cli init ``` +```bash bun +bunx @openworkflow/cli init +``` + The CLI will help you set up OpenWorkflow, create your `openworkflow.config.ts`, @@ -37,6 +41,10 @@ npx @openworkflow/cli worker start pnpx @openworkflow/cli worker start ``` +```bash bun +bunx @openworkflow/cli worker start +``` + This starts the worker using `openworkflow.config.{ts,js}` and auto-loads @@ -59,6 +67,10 @@ pnpx tsx openworkflow/hello-world.run.ts node openworkflow/hello-world.run.js ``` +```bash bun +bun openworkflow/hello-world.run.ts +``` + This script runs the `helloWorld` workflow and waits for it to complete. @@ -81,6 +93,10 @@ npx @openworkflow/cli dashboard pnpx @openworkflow/cli dashboard ``` +```bash bun +bunx @openworkflow/cli dashboard +``` + The dashboard provides a UI for monitoring workflow runs, viewing step details, diff --git a/packages/docs/docs/retries.mdx b/packages/docs/docs/retries.mdx index 96b1ec65..4cf98c1e 100644 --- a/packages/docs/docs/retries.mdx +++ b/packages/docs/docs/retries.mdx @@ -164,4 +164,8 @@ npx @openworkflow/cli dashboard pnpx @openworkflow/cli dashboard ``` +```bash bun +bunx @openworkflow/cli dashboard +``` + diff --git a/packages/docs/docs/sqlite.mdx b/packages/docs/docs/sqlite.mdx index f81ed5e1..8dad9964 100644 --- a/packages/docs/docs/sqlite.mdx +++ b/packages/docs/docs/sqlite.mdx @@ -6,7 +6,7 @@ description: Lightweight SQLite storage for development and testing The SQLite backend is perfect for local development, testing, and single-server deployments. It requires no external database server. -Requires Node.js 22.5+ for `node:sqlite`. +Uses `bun:sqlite` for Bun and `node:sqlite` for Node.js. ## Setup diff --git a/packages/docs/docs/workers.mdx b/packages/docs/docs/workers.mdx index 59358751..22cdd4ae 100644 --- a/packages/docs/docs/workers.mdx +++ b/packages/docs/docs/workers.mdx @@ -20,6 +20,10 @@ npx @openworkflow/cli worker start pnpx @openworkflow/cli worker start ``` +```bash bun +bunx @openworkflow/cli worker start +``` + This command: @@ -68,6 +72,10 @@ npx @openworkflow/cli worker start --concurrency 10 pnpx @openworkflow/cli worker start --concurrency 10 ``` +```bash bun +bunx @openworkflow/cli worker start --concurrency 10 +``` + @@ -107,6 +115,13 @@ pnpx @openworkflow/cli worker start --concurrency 10 pnpx @openworkflow/cli worker start --concurrency 10 ``` +```bash bun +# Terminal 1 +bunx @openworkflow/cli worker start --concurrency 10 +# Terminal 2 +bunx @openworkflow/cli worker start --concurrency 10 +``` + Workers coordinate through the database: @@ -145,6 +160,15 @@ pnpx @openworkflow/cli worker start # [info] Worker stopped ``` +```bash bun +# The worker handles Ctrl+C gracefully +bunx @openworkflow/cli worker start +^C +# [info] Shutting down worker... +# [info] Waiting for active workflows to complete... +# [info] Worker stopped +``` + ## Workflow Discovery diff --git a/packages/docs/index.mdx b/packages/docs/index.mdx index 62f526d6..57e30e68 100644 --- a/packages/docs/index.mdx +++ b/packages/docs/index.mdx @@ -14,6 +14,10 @@ npx @openworkflow/cli init pnpx @openworkflow/cli init ``` +```bash bun +bunx @openworkflow/cli init +``` + ![OpenWorkflow Dashboard](/assets/dashboard.png) From 41de670ccb7e40176662c536bbbe606084477337 Mon Sep 17 00:00:00 2001 From: James Martinez Date: Wed, 4 Feb 2026 17:46:41 -0600 Subject: [PATCH 3/3] Add gh workflow for Bun tests --- .github/workflows/ci.bun.yaml | 25 +++++++++++++++++++++++++ packages/openworkflow/sqlite/sqlite.ts | 2 ++ 2 files changed, 27 insertions(+) create mode 100644 .github/workflows/ci.bun.yaml diff --git a/.github/workflows/ci.bun.yaml b/.github/workflows/ci.bun.yaml new file mode 100644 index 00000000..d93b8156 --- /dev/null +++ b/.github/workflows/ci.bun.yaml @@ -0,0 +1,25 @@ +name: CI (Bun) +permissions: + contents: read +on: + workflow_call: +jobs: + ci: + runs-on: ubuntu-latest + services: + postgres: + image: postgres + env: + POSTGRES_PASSWORD: postgres + ports: + - 5432:5432 + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + steps: + - uses: actions/checkout@v6 + - uses: oven-sh/setup-bun@v2 + - run: bun ci + - run: bun run test diff --git a/packages/openworkflow/sqlite/sqlite.ts b/packages/openworkflow/sqlite/sqlite.ts index ba2e78c9..57ed9478 100644 --- a/packages/openworkflow/sqlite/sqlite.ts +++ b/packages/openworkflow/sqlite/sqlite.ts @@ -25,10 +25,12 @@ export function newDatabase(path: string): Database { const isBun = (globalThis as { Bun?: unknown }).Bun !== undefined; if (isBun) { + // istanbul ignore next -- Bun tested in CI // eslint-disable-next-line @typescript-eslint/no-require-imports const { Database: BunDatabase } = require("bun:sqlite") as { Database: new (path: string) => Database; }; + // istanbul ignore next -- Bun tested in CI db = new BunDatabase(path); } else { // eslint-disable-next-line @typescript-eslint/no-require-imports