@workflow/world-postgres 4.0.1-beta.2 → 4.1.0-beta.4
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.
- package/README.md +33 -0
- package/bin/setup.js +12 -0
- package/dist/boss.d.ts +15 -0
- package/dist/boss.d.ts.map +1 -0
- package/dist/boss.js +18 -0
- package/dist/boss.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +44 -0
- package/dist/cli.js.map +1 -0
- package/dist/config.d.ts +6 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +2 -0
- package/dist/config.js.map +1 -0
- package/dist/drizzle/index.d.ts +6 -0
- package/dist/drizzle/index.d.ts.map +1 -0
- package/dist/drizzle/index.js +7 -0
- package/dist/drizzle/index.js.map +1 -0
- package/dist/drizzle/schema.d.ts +594 -0
- package/dist/drizzle/schema.d.ts.map +1 -0
- package/dist/drizzle/schema.js +89 -0
- package/dist/drizzle/schema.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +40 -0
- package/dist/index.js.map +1 -0
- package/dist/queue.d.ts +17 -0
- package/dist/queue.d.ts.map +1 -0
- package/dist/queue.js +103 -0
- package/dist/queue.js.map +1 -0
- package/dist/storage.d.ts +7 -0
- package/dist/storage.d.ts.map +1 -0
- package/dist/storage.js +369 -0
- package/dist/storage.js.map +1 -0
- package/dist/streamer.d.ts +5 -0
- package/dist/streamer.d.ts.map +1 -0
- package/dist/streamer.js +157 -0
- package/dist/streamer.js.map +1 -0
- package/dist/util.d.ts +6 -0
- package/dist/util.d.ts.map +1 -0
- package/dist/util.js +20 -0
- package/dist/util.js.map +1 -0
- package/dist/zod.d.ts +3 -0
- package/dist/zod.d.ts.map +1 -0
- package/dist/zod.js +10 -0
- package/dist/zod.js.map +1 -0
- package/package.json +23 -8
- package/src/drizzle/migrations/0000_redundant_smasher.sql +80 -0
package/README.md
CHANGED
|
@@ -76,6 +76,39 @@ This package uses PostgreSQL with the following components:
|
|
|
76
76
|
- **Drizzle ORM**: For database operations and schema management
|
|
77
77
|
- **postgres**: For PostgreSQL client connections
|
|
78
78
|
|
|
79
|
+
### Quick Setup with CLI
|
|
80
|
+
|
|
81
|
+
The easiest way to set up your database is using the included CLI tool:
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
pnpm exec workflow-postgres-setup
|
|
85
|
+
# or
|
|
86
|
+
npm exec workflow-postgres-setup
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
The CLI automatically loads `.env` files and will use the connection string from:
|
|
90
|
+
1. `WORKFLOW_POSTGRES_URL` environment variable
|
|
91
|
+
2. `DATABASE_URL` environment variable
|
|
92
|
+
3. Default: `postgres://world:world@localhost:5432/world`
|
|
93
|
+
|
|
94
|
+
### Database Schema
|
|
95
|
+
|
|
96
|
+
The setup creates the following tables:
|
|
97
|
+
|
|
98
|
+
- `workflow_runs` - Stores workflow execution runs
|
|
99
|
+
- `workflow_events` - Stores workflow events
|
|
100
|
+
- `workflow_steps` - Stores individual workflow steps
|
|
101
|
+
- `workflow_hooks` - Stores webhook hooks
|
|
102
|
+
- `workflow_stream_chunks` - Stores streaming data chunks
|
|
103
|
+
|
|
104
|
+
You can also access the schema programmatically:
|
|
105
|
+
|
|
106
|
+
```typescript
|
|
107
|
+
import { runs, events, steps, hooks, streams } from '@workflow/world-postgres';
|
|
108
|
+
// or
|
|
109
|
+
import * as schema from '@workflow/world-postgres/schema';
|
|
110
|
+
```
|
|
111
|
+
|
|
79
112
|
Make sure your PostgreSQL database is accessible and the user has sufficient permissions to create tables and manage jobs.
|
|
80
113
|
|
|
81
114
|
## Features
|
package/bin/setup.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// Simple wrapper to run the CLI from the bin directory
|
|
4
|
+
import('../dist/cli.js')
|
|
5
|
+
.then((module) => {
|
|
6
|
+
// Call the setupDatabase function
|
|
7
|
+
return module.setupDatabase();
|
|
8
|
+
})
|
|
9
|
+
.catch((err) => {
|
|
10
|
+
console.error('Failed to load CLI:', err);
|
|
11
|
+
process.exit(1);
|
|
12
|
+
});
|
package/dist/boss.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as z from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
/* pgboss is using JSON under the hood, so we need to base64 encode
|
|
4
|
+
/* the body to ensure binary safety
|
|
5
|
+
/* maybe later we can have a `blobs` table for larger payloads
|
|
6
|
+
**/
|
|
7
|
+
export declare const MessageData: z.ZodObject<{
|
|
8
|
+
attempt: z.ZodNumber;
|
|
9
|
+
messageId: z.core.$ZodBranded<z.ZodString, "MessageId">;
|
|
10
|
+
idempotencyKey: z.ZodOptional<z.ZodString>;
|
|
11
|
+
id: z.ZodString;
|
|
12
|
+
data: z.ZodCodec<z.ZodBase64, z.ZodCustom<Buffer<ArrayBufferLike>, Buffer<ArrayBufferLike>>>;
|
|
13
|
+
}, z.core.$strip>;
|
|
14
|
+
export type MessageData = z.infer<typeof MessageData>;
|
|
15
|
+
//# sourceMappingURL=boss.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"boss.d.ts","sourceRoot":"","sources":["../src/boss.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AAGzB;;;;IAII;AACJ,eAAO,MAAM,WAAW;;;;;;iBAUtB,CAAC;AACH,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,WAAW,CAAC,CAAC"}
|
package/dist/boss.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { MessageId } from '@workflow/world';
|
|
2
|
+
import * as z from 'zod';
|
|
3
|
+
import { Base64Buffer } from './zod.js';
|
|
4
|
+
/**
|
|
5
|
+
/* pgboss is using JSON under the hood, so we need to base64 encode
|
|
6
|
+
/* the body to ensure binary safety
|
|
7
|
+
/* maybe later we can have a `blobs` table for larger payloads
|
|
8
|
+
**/
|
|
9
|
+
export const MessageData = z.object({
|
|
10
|
+
attempt: z.number().describe('The attempt number of the message'),
|
|
11
|
+
messageId: MessageId.describe('The unique ID of the message'),
|
|
12
|
+
idempotencyKey: z.string().optional(),
|
|
13
|
+
id: z
|
|
14
|
+
.string()
|
|
15
|
+
.describe("The ID of the sub-queue. For workflows, it's the workflow name. For steps, it's the step name."),
|
|
16
|
+
data: Base64Buffer.describe('The message that was sent'),
|
|
17
|
+
});
|
|
18
|
+
//# sourceMappingURL=boss.js.map
|
package/dist/boss.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"boss.js","sourceRoot":"","sources":["../src/boss.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AACzB,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAExC;;;;IAII;AACJ,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,CAAC,MAAM,CAAC;IAClC,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,mCAAmC,CAAC;IACjE,SAAS,EAAE,SAAS,CAAC,QAAQ,CAAC,8BAA8B,CAAC;IAC7D,cAAc,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IACrC,EAAE,EAAE,CAAC;SACF,MAAM,EAAE;SACR,QAAQ,CACP,gGAAgG,CACjG;IACH,IAAI,EAAE,YAAY,CAAC,QAAQ,CAAC,2BAA2B,CAAC;CACzD,CAAC,CAAC"}
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAQA,iBAAe,aAAa,kBA+C3B;AAOD,OAAO,EAAE,aAAa,EAAE,CAAC"}
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { dirname, join } from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import { config } from 'dotenv';
|
|
5
|
+
import postgres from 'postgres';
|
|
6
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
7
|
+
async function setupDatabase() {
|
|
8
|
+
// Load .env file if it exists
|
|
9
|
+
config();
|
|
10
|
+
const connectionString = process.env.WORKFLOW_POSTGRES_URL ||
|
|
11
|
+
process.env.DATABASE_URL ||
|
|
12
|
+
'postgres://world:world@localhost:5432/world';
|
|
13
|
+
console.log('🔧 Setting up database schema...');
|
|
14
|
+
console.log(`📍 Connection: ${connectionString.replace(/^(\w+:\/\/)([^@]+)@/, '$1[redacted]@')}`);
|
|
15
|
+
try {
|
|
16
|
+
const sql = postgres(connectionString);
|
|
17
|
+
// Read the migration SQL file
|
|
18
|
+
// The migrations are in src/drizzle/migrations, and this CLI is in dist/
|
|
19
|
+
// So we need to go up one level from dist/ to reach src/
|
|
20
|
+
const migrationPath = join(__dirname, '..', 'src', 'drizzle', 'migrations', '0000_redundant_smasher.sql');
|
|
21
|
+
const migrationSQL = await readFile(migrationPath, 'utf-8');
|
|
22
|
+
// Execute the migration
|
|
23
|
+
await sql.unsafe(migrationSQL);
|
|
24
|
+
console.log('✅ Database schema created successfully!');
|
|
25
|
+
console.log('\nCreated tables:');
|
|
26
|
+
console.log(' - workflow_runs');
|
|
27
|
+
console.log(' - workflow_events');
|
|
28
|
+
console.log(' - workflow_steps');
|
|
29
|
+
console.log(' - workflow_hooks');
|
|
30
|
+
console.log(' - workflow_stream_chunks');
|
|
31
|
+
await sql.end();
|
|
32
|
+
process.exit(0);
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
console.error('❌ Failed to setup database:', error);
|
|
36
|
+
process.exit(1);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
// Check if running as main module
|
|
40
|
+
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
41
|
+
setupDatabase();
|
|
42
|
+
}
|
|
43
|
+
export { setupDatabase };
|
|
44
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,QAAQ,MAAM,UAAU,CAAC;AAEhC,MAAM,SAAS,GAAG,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AAE1D,KAAK,UAAU,aAAa;IAC1B,8BAA8B;IAC9B,MAAM,EAAE,CAAC;IAET,MAAM,gBAAgB,GACpB,OAAO,CAAC,GAAG,CAAC,qBAAqB;QACjC,OAAO,CAAC,GAAG,CAAC,YAAY;QACxB,6CAA6C,CAAC;IAEhD,OAAO,CAAC,GAAG,CAAC,kCAAkC,CAAC,CAAC;IAChD,OAAO,CAAC,GAAG,CACT,kBAAkB,gBAAgB,CAAC,OAAO,CAAC,qBAAqB,EAAE,eAAe,CAAC,EAAE,CACrF,CAAC;IAEF,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,QAAQ,CAAC,gBAAgB,CAAC,CAAC;QAEvC,8BAA8B;QAC9B,yEAAyE;QACzE,yDAAyD;QACzD,MAAM,aAAa,GAAG,IAAI,CACxB,SAAS,EACT,IAAI,EACJ,KAAK,EACL,SAAS,EACT,YAAY,EACZ,4BAA4B,CAC7B,CAAC;QACF,MAAM,YAAY,GAAG,MAAM,QAAQ,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;QAE5D,wBAAwB;QACxB,MAAM,GAAG,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;QAE/B,OAAO,CAAC,GAAG,CAAC,yCAAyC,CAAC,CAAC;QACvD,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;QACjC,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;QACjC,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC;QACnC,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC;QAClC,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC;QAClC,OAAO,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC;QAE1C,MAAM,GAAG,CAAC,GAAG,EAAE,CAAC;QAChB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,6BAA6B,EAAE,KAAK,CAAC,CAAC;QACpD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC;AAED,kCAAkC;AAClC,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,KAAK,UAAU,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;IACpD,aAAa,EAAE,CAAC;AAClB,CAAC;AAED,OAAO,EAAE,aAAa,EAAE,CAAC"}
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,mBAAmB;IAClC,gBAAgB,EAAE,MAAM,CAAC;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B"}
|
package/dist/config.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type Postgres from 'postgres';
|
|
2
|
+
import * as Schema from './schema.js';
|
|
3
|
+
export { Schema };
|
|
4
|
+
export type Drizzle = ReturnType<typeof createClient>;
|
|
5
|
+
export declare function createClient(postgres: Postgres.Sql): import("drizzle-orm/postgres-js").PostgresJsDatabase<typeof Schema>;
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/drizzle/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,QAAQ,MAAM,UAAU,CAAC;AACrC,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AAEtC,OAAO,EAAE,MAAM,EAAE,CAAC;AAElB,MAAM,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,YAAY,CAAC,CAAC;AACtD,wBAAgB,YAAY,CAAC,QAAQ,EAAE,QAAQ,CAAC,GAAG,uEAElD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/drizzle/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAElD,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AAEtC,OAAO,EAAE,MAAM,EAAE,CAAC;AAGlB,MAAM,UAAU,YAAY,CAAC,QAAsB;IACjD,OAAO,OAAO,CAAC,QAAQ,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;AAC/C,CAAC"}
|