@workflow/world-postgres 4.0.1-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +112 -0
  3. package/package.json +50 -0
package/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Vercel, Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,112 @@
1
+ # @workflow/world-postgres
2
+
3
+ An embedded worker/workflow system backed by PostgreSQL for multi-host self-hosted solutions. This is a reference implementation - a production-ready solution might run workers in separate processes with a more robust queuing system.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @workflow/world-postgres
9
+ # or
10
+ pnpm add @workflow/world-postgres
11
+ # or
12
+ yarn add @workflow/world-postgres
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ### Basic Setup
18
+
19
+ The postgres world can be configured by setting the `WORKFLOW_TARGET_WORLD` environment variable to the package name:
20
+
21
+ ```bash
22
+ export WORKFLOW_TARGET_WORLD="@workflow/world-postgres"
23
+ ```
24
+
25
+ ### Configuration
26
+
27
+ Configure the PostgreSQL world using environment variables:
28
+
29
+ ```bash
30
+ # Required: PostgreSQL connection string
31
+ export WORKFLOW_POSTGRES_URL="postgres://username:password@localhost:5432/database"
32
+
33
+ # Optional: Job prefix for queue operations
34
+ export WORKFLOW_POSTGRES_JOB_PREFIX="myapp"
35
+
36
+ # Optional: Worker concurrency (default: 10)
37
+ export WORKFLOW_POSTGRES_WORKER_CONCURRENCY="10"
38
+ ```
39
+
40
+ ### Programmatic Usage
41
+
42
+ You can also create a PostgreSQL world directly in your code:
43
+
44
+ ```typescript
45
+ import { createWorld } from "@workflow/world-postgres";
46
+
47
+ const world = createWorld({
48
+ connectionString: "postgres://username:password@localhost:5432/database",
49
+ jobPrefix: "myapp", // optional
50
+ queueConcurrency: 10, // optional
51
+ });
52
+ ```
53
+
54
+ ## Configuration Options
55
+
56
+ | Option | Type | Default | Description |
57
+ | ------------------ | -------- | -------------------------------------------------------------------------------------- | ----------------------------------- |
58
+ | `connectionString` | `string` | `process.env.WORKFLOW_POSTGRES_URL` or `'postgres://world:world@localhost:5432/world'` | PostgreSQL connection string |
59
+ | `jobPrefix` | `string` | `process.env.WORKFLOW_POSTGRES_JOB_PREFIX` | Optional prefix for queue job names |
60
+ | `queueConcurrency` | `number` | `10` | Number of concurrent queue workers |
61
+
62
+ ## Environment Variables
63
+
64
+ | Variable | Description | Default |
65
+ | -------------------------------------- | ------------------------------------------------------------ | ----------------------------------------------- |
66
+ | `WORKFLOW_TARGET_WORLD` | Set to `"@workflow/world-postgres"` to use this world | - |
67
+ | `WORKFLOW_POSTGRES_URL` | PostgreSQL connection string | `'postgres://world:world@localhost:5432/world'` |
68
+ | `WORKFLOW_POSTGRES_JOB_PREFIX` | Prefix for queue job names | - |
69
+ | `WORKFLOW_POSTGRES_WORKER_CONCURRENCY` | Number of concurrent workers | `10` |
70
+
71
+ ## Database Setup
72
+
73
+ This package uses PostgreSQL with the following components:
74
+
75
+ - **pg-boss**: For queue processing and job management
76
+ - **Drizzle ORM**: For database operations and schema management
77
+ - **postgres**: For PostgreSQL client connections
78
+
79
+ Make sure your PostgreSQL database is accessible and the user has sufficient permissions to create tables and manage jobs.
80
+
81
+ ## Features
82
+
83
+ - **Durable Storage**: Stores workflow runs, events, steps, hooks, and webhooks in PostgreSQL
84
+ - **Queue Processing**: Uses pg-boss for reliable job queue processing
85
+ - **Streaming**: Real-time event streaming capabilities
86
+ - **Health Checks**: Built-in connection health monitoring
87
+ - **Configurable Concurrency**: Adjustable worker concurrency for queue processing
88
+
89
+ ## Development
90
+
91
+ For local development, you can use the included Docker Compose configuration:
92
+
93
+ ```bash
94
+ # Start PostgreSQL database
95
+ docker-compose up -d
96
+
97
+ # Create and run migrations
98
+ pnpm drizzle-kit generate
99
+ pnpm drizzle-kit migrate
100
+
101
+ # Set environment variables for local development
102
+ export WORKFLOW_POSTGRES_URL="postgres://world:world@localhost:5432/world"
103
+ export WORKFLOW_TARGET_WORLD="@workflow/world-postgres"
104
+ ```
105
+
106
+ ## World Selection
107
+
108
+ To use the PostgreSQL world, set the `WORKFLOW_TARGET_WORLD` environment variable to the package name:
109
+
110
+ ```bash
111
+ export WORKFLOW_TARGET_WORLD="@workflow/world-postgres"
112
+ ```
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@workflow/world-postgres",
3
+ "version": "4.0.1-beta.0",
4
+ "description": "A reference World implementation based on PostgreSQL",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "files": [
8
+ "dist"
9
+ ],
10
+ "publishConfig": {
11
+ "access": "public"
12
+ },
13
+ "exports": {
14
+ ".": {
15
+ "types": "./dist/index.d.ts",
16
+ "default": "./dist/index.js"
17
+ }
18
+ },
19
+ "dependencies": {
20
+ "@vercel/queue": "0.0.0-alpha.23",
21
+ "drizzle-orm": "^0.31.2",
22
+ "pg-boss": "^11.0.7",
23
+ "postgres": "^3.4.7",
24
+ "ulid": "^3.0.1",
25
+ "zod": "4.1.11",
26
+ "@workflow/errors": "4.0.1-beta.0",
27
+ "@workflow/world": "4.0.1-beta.0",
28
+ "@workflow/world-local": "4.0.1-beta.0"
29
+ },
30
+ "devDependencies": {
31
+ "@testcontainers/postgresql": "^11.7.1",
32
+ "@types/node": "24.6.2",
33
+ "drizzle-kit": "^0.22.7",
34
+ "vitest": "^3.2.4",
35
+ "@workflow/errors": "4.0.1-beta.0",
36
+ "@workflow/world-testing": "4.0.1-beta.0",
37
+ "@workflow/tsconfig": "4.0.1-beta.0"
38
+ },
39
+ "keywords": [],
40
+ "author": "",
41
+ "license": "MIT",
42
+ "scripts": {
43
+ "build": "tsc",
44
+ "dev": "tsc --watch",
45
+ "clean": "tsc --build --clean",
46
+ "test": "vitest run",
47
+ "typecheck": "tsc --noEmit",
48
+ "db:push": "pnpm exec drizzle-kit --version && drizzle-kit push"
49
+ }
50
+ }