npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

workflow-world-surrealdb

v0.1.1

Published

A SurrealDB-backed World implementation that uses LIVE SELECT for queueing and streaming

Readme

workflow-world-surrealdb

SurrealDB-backed World implementation for Workflow SDK. This package stores workflow state in SurrealDB and uses LIVE SELECT to drive queue wake-ups and stream fan-out, with SHOW CHANGES as the recovery path after a live subscription reconnects.

Installation

npm install workflow-world-surrealdb
# or
pnpm add workflow-world-surrealdb
# or
yarn add workflow-world-surrealdb

Usage

Set the target world:

export WORKFLOW_TARGET_WORLD="workflow-world-surrealdb"

Configuration

export WORKFLOW_SURREAL_URL="ws://127.0.0.1:8000/rpc"
export WORKFLOW_SURREAL_NAMESPACE="workflow"
export WORKFLOW_SURREAL_DATABASE="workflow"

# Optional auth
export WORKFLOW_SURREAL_USERNAME="root"
export WORKFLOW_SURREAL_PASSWORD="root"
# or
export WORKFLOW_SURREAL_TOKEN="..."

# Optional queue tuning
export WORKFLOW_SURREAL_QUEUE_CONCURRENCY="10"
export WORKFLOW_SURREAL_QUEUE_LEASE_MS="300000"
export WORKFLOW_SURREAL_QUEUE_HEARTBEAT_MS="10000"
export WORKFLOW_SURREAL_QUEUE_LANE_SHARDS="16"
export WORKFLOW_SURREAL_STEP_QUEUE_LANE_SHARDS="16"
export WORKFLOW_SURREAL_WORKFLOW_QUEUE_LANE_SHARDS="16"
export WORKFLOW_SURREAL_LIVE_RECONNECT_DELAY_MS="1000"

# Optional local execution base URL override
export WORKFLOW_LOCAL_BASE_URL="http://127.0.0.1:3000"

Local Docker Compose

A ready-to-use compose file is included at packages/world-surreal/docker-compose.yml:

cd packages/world-surreal
export SURREAL_DB_PASS="root"
docker compose up -d

export WORKFLOW_SURREAL_URL="ws://127.0.0.1:8000/rpc"
export WORKFLOW_SURREAL_NAMESPACE="workflow"
export WORKFLOW_SURREAL_DATABASE="workflow"
export WORKFLOW_SURREAL_USERNAME="root"
export WORKFLOW_SURREAL_PASSWORD="$SURREAL_DB_PASS"

This compose setup uses a named Docker volume plus surrealkv:///data/workflow.db?versioned=true, so the database survives container restarts.

Programmatic usage

import { createWorld } from 'workflow-world-surrealdb';

const world = createWorld({
  url: 'ws://127.0.0.1:8000/rpc',
  namespace: 'workflow',
  database: 'workflow',
  auth: {
    username: 'root',
    password: 'root',
  },
});

Schema setup

This package lazily defines its tables on first use, but you can also create them explicitly:

pnpm exec workflow-surreal-setup
# or
pnpm --filter workflow-world-surrealdb db:push

Design notes

  • Workflow entities still follow the same event-sourced contract as the other worlds: events.create() is the only write entrypoint for run, step, hook, and wait state.
  • The schema is Surreal-first: tables are SCHEMAFULL, hot query paths are indexed explicitly, and hook uniqueness is enforced with tokenHash instead of an auxiliary lock table.
  • Queue scheduling is live-first: workers subscribe to lane summary rows with readyCount > 0, and a short idle poll only refreshes due lanes and expired leases instead of scanning the whole jobs table each cycle.
  • Queue retry timing now follows a Graphile-style exponential backoff for handler failures, with the delay computed inside SurrealDB functions so retry scheduling uses database time instead of process-local time.
  • Queue lane summaries are maintained incrementally in SurrealDB so enqueue, claim, complete, and retry paths stay on single-row control-plane updates.
  • Completed queue jobs are deleted after acknowledgement, keeping the hot queue table compact instead of accumulating completed rows.
  • Queue recovery is changefeed-backed: after the live socket reconnects, the worker replays SHOW CHANGES FOR TABLE workflow_queue_jobs from the last seen timestamp before resubscribing.
  • Stream reads are chunk-based: writers append chunk rows, readers consume an initial snapshot plus live chunk notifications.
  • Opaque workflow payloads are stored as CBOR payloads, while native Surreal-friendly fields such as timestamps, statuses, and execution metadata remain directly queryable.

Current limitations

  • This package is currently optimized for the single-node Live Query model described in SurrealDB’s documentation.
  • This package does not preserve any pre-Surreal legacy storage mode; it expects records created by the current workflow-world-surrealdb implementation.