openworkflow 0.4.0 → 0.5.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.
- package/README.md +57 -46
- package/dist/backend-postgres/index.d.ts +44 -0
- package/dist/backend-postgres/index.d.ts.map +1 -0
- package/dist/backend-postgres/index.js +535 -0
- package/dist/backend-postgres/index.js.map +1 -0
- package/dist/backend-postgres/postgres.d.ts +42 -0
- package/dist/backend-postgres/postgres.d.ts.map +1 -0
- package/dist/backend-postgres/postgres.js +234 -0
- package/dist/backend-postgres/postgres.js.map +1 -0
- package/dist/backend-sqlite/index.d.ts +42 -0
- package/dist/backend-sqlite/index.d.ts.map +1 -0
- package/dist/backend-sqlite/index.js +655 -0
- package/dist/backend-sqlite/index.js.map +1 -0
- package/dist/backend-sqlite/sqlite.d.ts +61 -0
- package/dist/backend-sqlite/sqlite.d.ts.map +1 -0
- package/dist/backend-sqlite/sqlite.js +247 -0
- package/dist/backend-sqlite/sqlite.js.map +1 -0
- package/dist/backend.d.ts +21 -89
- package/dist/backend.d.ts.map +1 -1
- package/dist/backend.js +0 -21
- package/dist/backend.js.map +1 -1
- package/dist/bin/openworkflow.d.ts +3 -0
- package/dist/bin/openworkflow.d.ts.map +1 -0
- package/dist/bin/openworkflow.js +44 -0
- package/dist/bin/openworkflow.js.map +1 -0
- package/dist/client.d.ts +68 -80
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +83 -53
- package/dist/client.js.map +1 -1
- package/dist/config.d.ts +34 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +49 -0
- package/dist/config.js.map +1 -0
- package/dist/{duration.d.ts → core/duration.d.ts} +5 -2
- package/dist/core/duration.d.ts.map +1 -0
- package/dist/{duration.js → core/duration.js} +9 -6
- package/dist/core/duration.js.map +1 -0
- package/dist/core/error.d.ts +14 -0
- package/dist/core/error.d.ts.map +1 -0
- package/dist/core/error.js +18 -0
- package/dist/core/error.js.map +1 -0
- package/dist/core/json.d.ts +5 -0
- package/dist/core/json.d.ts.map +1 -0
- package/dist/core/json.js +2 -0
- package/dist/core/json.js.map +1 -0
- package/dist/core/result.d.ts +22 -0
- package/dist/core/result.d.ts.map +1 -0
- package/dist/core/result.js +17 -0
- package/dist/core/result.js.map +1 -0
- package/dist/core/retry.d.ts +7 -0
- package/dist/core/retry.d.ts.map +1 -0
- package/dist/core/retry.js +7 -0
- package/dist/core/retry.js.map +1 -0
- package/dist/core/schema.d.ts.map +1 -0
- package/dist/core/schema.js.map +1 -0
- package/dist/core/step.d.ts +89 -0
- package/dist/core/step.d.ts.map +1 -0
- package/dist/core/step.js +66 -0
- package/dist/core/step.js.map +1 -0
- package/dist/core/workflow.d.ts +63 -0
- package/dist/core/workflow.d.ts.map +1 -0
- package/dist/core/workflow.js +35 -0
- package/dist/core/workflow.js.map +1 -0
- package/dist/execution.d.ts +69 -0
- package/dist/execution.d.ts.map +1 -0
- package/dist/execution.js +188 -0
- package/dist/execution.js.map +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/internal.d.ts +8 -0
- package/dist/internal.d.ts.map +1 -0
- package/dist/internal.js +5 -0
- package/dist/internal.js.map +1 -0
- package/dist/pg/backend.d.ts +42 -0
- package/dist/pg/backend.d.ts.map +1 -0
- package/dist/pg/backend.js +534 -0
- package/dist/pg/backend.js.map +1 -0
- package/dist/pg/index.d.ts +3 -0
- package/dist/pg/index.d.ts.map +1 -0
- package/dist/pg/index.js +3 -0
- package/dist/pg/index.js.map +1 -0
- package/dist/pg/postgres.d.ts +42 -0
- package/dist/pg/postgres.d.ts.map +1 -0
- package/dist/pg/postgres.js +234 -0
- package/dist/pg/postgres.js.map +1 -0
- package/dist/pg/scripts/db-migrate.d.ts +2 -0
- package/dist/pg/scripts/db-migrate.d.ts.map +1 -0
- package/dist/pg/scripts/db-migrate.js +5 -0
- package/dist/pg/scripts/db-migrate.js.map +1 -0
- package/dist/pg/scripts/db-reset.d.ts +2 -0
- package/dist/pg/scripts/db-reset.d.ts.map +1 -0
- package/dist/pg/scripts/db-reset.js +6 -0
- package/dist/pg/scripts/db-reset.js.map +1 -0
- package/dist/pg/scripts/squawk.d.ts +2 -0
- package/dist/pg/scripts/squawk.d.ts.map +1 -0
- package/dist/pg/scripts/squawk.js +17 -0
- package/dist/pg/scripts/squawk.js.map +1 -0
- package/dist/pg/vitest.global-setup.d.ts +3 -0
- package/dist/pg/vitest.global-setup.d.ts.map +1 -0
- package/dist/pg/vitest.global-setup.js +8 -0
- package/dist/pg/vitest.global-setup.js.map +1 -0
- package/dist/registry.d.ts +27 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +49 -0
- package/dist/registry.js.map +1 -0
- package/dist/sqlite/backend.d.ts +40 -0
- package/dist/sqlite/backend.d.ts.map +1 -0
- package/dist/sqlite/backend.js +654 -0
- package/dist/sqlite/backend.js.map +1 -0
- package/dist/sqlite/index.d.ts +3 -0
- package/dist/sqlite/index.d.ts.map +1 -0
- package/dist/sqlite/index.js +3 -0
- package/dist/sqlite/index.js.map +1 -0
- package/dist/sqlite/sqlite.d.ts +61 -0
- package/dist/sqlite/sqlite.d.ts.map +1 -0
- package/dist/sqlite/sqlite.js +247 -0
- package/dist/sqlite/sqlite.js.map +1 -0
- package/dist/testing/backend.testsuite.d.ts +20 -0
- package/dist/testing/backend.testsuite.d.ts.map +1 -0
- package/dist/testing/backend.testsuite.js +1091 -0
- package/dist/testing/backend.testsuite.js.map +1 -0
- package/dist/testing/index.d.ts +2 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +2 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/worker.d.ts +10 -3
- package/dist/worker.d.ts.map +1 -1
- package/dist/worker.js +29 -195
- package/dist/worker.js.map +1 -1
- package/dist/workflow.d.ts +60 -0
- package/dist/workflow.d.ts.map +1 -0
- package/dist/workflow.js +49 -0
- package/dist/workflow.js.map +1 -0
- package/package.json +16 -6
- package/dist/duration.d.ts.map +0 -1
- package/dist/duration.js.map +0 -1
- package/dist/schema.d.ts.map +0 -1
- package/dist/schema.js.map +0 -1
- /package/dist/{schema.d.ts → core/schema.d.ts} +0 -0
- /package/dist/{schema.js → core/schema.js} +0 -0
package/README.md
CHANGED
|
@@ -8,31 +8,13 @@ OpenWorkflow is a TypeScript framework for building durable, resumable workflows
|
|
|
8
8
|
that can pause for seconds or months, survive crashes and deploys, and resume
|
|
9
9
|
exactly where they left off - all without extra servers to manage.
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
> [Roadmap](#roadmap) for what’s coming next.
|
|
13
|
-
|
|
14
|
-
## Quick Start
|
|
15
|
-
|
|
16
|
-
Prerequisites:
|
|
17
|
-
|
|
18
|
-
- Node.js
|
|
19
|
-
- PostgreSQL (support for additional backends like Redis and SQLite coming soon.
|
|
20
|
-
See [Roadmap](#roadmap) for details.)
|
|
21
|
-
|
|
22
|
-
### 1. Install
|
|
23
|
-
|
|
24
|
-
```bash
|
|
25
|
-
npm install openworkflow @openworkflow/backend-postgres
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
### 2. Define a workflow
|
|
11
|
+
Define a workflow in a few lines:
|
|
29
12
|
|
|
30
13
|
```ts
|
|
31
|
-
import {
|
|
14
|
+
import { BackendSqlite } from "@openworkflow/backend-sqlite";
|
|
32
15
|
import { OpenWorkflow } from "openworkflow";
|
|
33
16
|
|
|
34
|
-
const
|
|
35
|
-
const backend = await BackendPostgres.connect(postgresUrl);
|
|
17
|
+
const backend = BackendSqlite.connect("openworkflow/backend.db");
|
|
36
18
|
const ow = new OpenWorkflow({ backend });
|
|
37
19
|
|
|
38
20
|
const sendWelcomeEmail = ow.defineWorkflow(
|
|
@@ -61,29 +43,44 @@ const sendWelcomeEmail = ow.defineWorkflow(
|
|
|
61
43
|
);
|
|
62
44
|
```
|
|
63
45
|
|
|
64
|
-
|
|
46
|
+
> OpenWorkflow is in active development and moving quickly. Check out the
|
|
47
|
+
> [Roadmap](#roadmap) for what’s coming next.
|
|
48
|
+
|
|
49
|
+
## Quick Start
|
|
65
50
|
|
|
66
|
-
|
|
67
|
-
separate process or the same one as your app:
|
|
51
|
+
Prerequisites:
|
|
68
52
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
53
|
+
- Node.js
|
|
54
|
+
- PostgreSQL (and/or SQLite)
|
|
55
|
+
|
|
56
|
+
### 1. Install
|
|
57
|
+
|
|
58
|
+
Install and set up OpenWorkflow with:
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
npx @openworkflow/cli init
|
|
72
62
|
```
|
|
73
63
|
|
|
74
|
-
|
|
64
|
+
The CLI will prompt for your backend, installs dependencies, and generates:
|
|
65
|
+
`openworkflow.config.ts`, `openworkflow/hello-world.ts`, `.env`, `.gitignore`,
|
|
66
|
+
and a `worker` script.
|
|
75
67
|
|
|
76
|
-
|
|
68
|
+
### 2. Start a worker
|
|
77
69
|
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
const runHandle = await sendWelcomeEmail.run({ userId: req.params.id });
|
|
83
|
-
res.json({ runId: runHandle.workflowRun.id });
|
|
84
|
-
});
|
|
70
|
+
```bash
|
|
71
|
+
npm run worker
|
|
72
|
+
# or
|
|
73
|
+
npx @openworkflow/cli worker start
|
|
85
74
|
```
|
|
86
75
|
|
|
76
|
+
This runs the worker using `openworkflow.config.ts` and auto-loads workflows
|
|
77
|
+
from the configured directories (default: `openworkflow/`).
|
|
78
|
+
|
|
79
|
+
### 3. Run workflows from your app
|
|
80
|
+
|
|
81
|
+
Edit the generated workflow file and run it from your application code using the
|
|
82
|
+
OpenWorkflow client APIs (see examples below).
|
|
83
|
+
|
|
87
84
|
That's it. Your workflow is now durable, resumable, and fault-tolerant.
|
|
88
85
|
|
|
89
86
|
## Core Concepts
|
|
@@ -127,9 +124,24 @@ the email.
|
|
|
127
124
|
### Workers
|
|
128
125
|
|
|
129
126
|
Workers are long-running processes that poll your database for pending workflows
|
|
130
|
-
and execute them.
|
|
127
|
+
and execute them. Run workers via the CLI so workflow discovery stays in sync
|
|
128
|
+
with your `openworkflow.config.ts`:
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
npm run worker
|
|
132
|
+
# or
|
|
133
|
+
npx @openworkflow/cli worker start
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
Or, for more control, you can write your own workers:
|
|
131
137
|
|
|
132
138
|
```ts
|
|
139
|
+
import { BackendSqlite } from "@openworkflow/backend-sqlite";
|
|
140
|
+
import { OpenWorkflow } from "openworkflow";
|
|
141
|
+
|
|
142
|
+
const backend = BackendSqlite.connect("openworkflow/backend.db");
|
|
143
|
+
const ow = new OpenWorkflow({ backend });
|
|
144
|
+
|
|
133
145
|
const worker = ow.newWorker({ concurrency: 20 });
|
|
134
146
|
await worker.start();
|
|
135
147
|
|
|
@@ -220,7 +232,7 @@ Durations accept a number followed by a unit:
|
|
|
220
232
|
| years | `y`, `yr`, `yrs` | `1y`, `2yr` |
|
|
221
233
|
|
|
222
234
|
See more examples of accepted duration formats and aliases in the
|
|
223
|
-
[tests](https://github.com/openworkflowdev/openworkflow/blob/main/packages/openworkflow/duration.test.ts).
|
|
235
|
+
[tests](https://github.com/openworkflowdev/openworkflow/blob/main/packages/openworkflow/core/duration.test.ts).
|
|
224
236
|
|
|
225
237
|
### Type Safety
|
|
226
238
|
|
|
@@ -360,7 +372,8 @@ and Yup.
|
|
|
360
372
|
|
|
361
373
|
**Live in current `npm` release:**
|
|
362
374
|
|
|
363
|
-
- ✅ PostgreSQL
|
|
375
|
+
- ✅ PostgreSQL and SQLite backends
|
|
376
|
+
- ✅ CLI (`npx @openworkflow/cli`)
|
|
364
377
|
- ✅ Worker with concurrency control
|
|
365
378
|
- ✅ Step memoization & retries
|
|
366
379
|
- ✅ Graceful shutdown
|
|
@@ -371,20 +384,18 @@ and Yup.
|
|
|
371
384
|
|
|
372
385
|
**Coming Soon:**
|
|
373
386
|
|
|
374
|
-
> These releases don't yet include a dashboard UI
|
|
375
|
-
>
|
|
376
|
-
>
|
|
377
|
-
>
|
|
387
|
+
> These releases don't yet include a dashboard UI. For now, you can inspect
|
|
388
|
+
> workflow and step state directly in PostgreSQL or SQLite (workflow_runs and
|
|
389
|
+
> step_attempts tables). A dashboard is planned for an upcoming release to make
|
|
390
|
+
> debugging and monitoring much easier.
|
|
378
391
|
|
|
379
|
-
- Improved local dev experience (coming in v0.5)
|
|
380
|
-
- CLI (coming in v0.5)
|
|
381
392
|
- Dashboard UI
|
|
382
393
|
- Idempotency keys
|
|
383
394
|
- Rollback / compensation functions
|
|
384
395
|
- Configurable retry policies
|
|
385
396
|
- Signals for external events
|
|
386
397
|
- Native OpenTelemetry integration
|
|
387
|
-
- Additional backends (Redis
|
|
398
|
+
- Additional backends (Redis)
|
|
388
399
|
- Additional languages (Go, Python)
|
|
389
400
|
|
|
390
401
|
## Bugs & feature requests
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { Backend, CancelWorkflowRunParams, ClaimWorkflowRunParams, CompleteStepAttemptParams, CompleteWorkflowRunParams, CreateStepAttemptParams, CreateWorkflowRunParams, ExtendWorkflowRunLeaseParams, FailStepAttemptParams, FailWorkflowRunParams, GetStepAttemptParams, GetWorkflowRunParams, ListStepAttemptsParams, ListWorkflowRunsParams, PaginatedResponse, SleepWorkflowRunParams } from "../backend.js";
|
|
2
|
+
import type { StepAttempt } from "../core/step.js";
|
|
3
|
+
import type { WorkflowRun } from "../core/workflow.js";
|
|
4
|
+
interface BackendPostgresOptions {
|
|
5
|
+
namespaceId?: string;
|
|
6
|
+
runMigrations?: boolean;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Manages a connection to a Postgres database for workflow operations.
|
|
10
|
+
*/
|
|
11
|
+
export declare class BackendPostgres implements Backend {
|
|
12
|
+
private pg;
|
|
13
|
+
private namespaceId;
|
|
14
|
+
private constructor();
|
|
15
|
+
/**
|
|
16
|
+
* Create and initialize a new BackendPostgres instance. This will
|
|
17
|
+
* automatically run migrations on startup unless `runMigrations` is set to
|
|
18
|
+
* false.
|
|
19
|
+
* @param url - Postgres connection URL
|
|
20
|
+
* @param options - Backend options
|
|
21
|
+
* @returns A connected backend instance
|
|
22
|
+
*/
|
|
23
|
+
static connect(url: string, options?: BackendPostgresOptions): Promise<BackendPostgres>;
|
|
24
|
+
stop(): Promise<void>;
|
|
25
|
+
createWorkflowRun(params: CreateWorkflowRunParams): Promise<WorkflowRun>;
|
|
26
|
+
getWorkflowRun(params: GetWorkflowRunParams): Promise<WorkflowRun | null>;
|
|
27
|
+
listWorkflowRuns(params: ListWorkflowRunsParams): Promise<PaginatedResponse<WorkflowRun>>;
|
|
28
|
+
private buildListWorkflowRunsWhere;
|
|
29
|
+
claimWorkflowRun(params: ClaimWorkflowRunParams): Promise<WorkflowRun | null>;
|
|
30
|
+
extendWorkflowRunLease(params: ExtendWorkflowRunLeaseParams): Promise<WorkflowRun>;
|
|
31
|
+
sleepWorkflowRun(params: SleepWorkflowRunParams): Promise<WorkflowRun>;
|
|
32
|
+
completeWorkflowRun(params: CompleteWorkflowRunParams): Promise<WorkflowRun>;
|
|
33
|
+
failWorkflowRun(params: FailWorkflowRunParams): Promise<WorkflowRun>;
|
|
34
|
+
cancelWorkflowRun(params: CancelWorkflowRunParams): Promise<WorkflowRun>;
|
|
35
|
+
createStepAttempt(params: CreateStepAttemptParams): Promise<StepAttempt>;
|
|
36
|
+
getStepAttempt(params: GetStepAttemptParams): Promise<StepAttempt | null>;
|
|
37
|
+
listStepAttempts(params: ListStepAttemptsParams): Promise<PaginatedResponse<StepAttempt>>;
|
|
38
|
+
private buildListStepAttemptsWhere;
|
|
39
|
+
private processPaginationResults;
|
|
40
|
+
completeStepAttempt(params: CompleteStepAttemptParams): Promise<StepAttempt>;
|
|
41
|
+
failStepAttempt(params: FailStepAttemptParams): Promise<StepAttempt>;
|
|
42
|
+
}
|
|
43
|
+
export {};
|
|
44
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/backend-postgres/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,OAAO,EACP,uBAAuB,EACvB,sBAAsB,EACtB,yBAAyB,EACzB,yBAAyB,EACzB,uBAAuB,EACvB,uBAAuB,EACvB,4BAA4B,EAC5B,qBAAqB,EACrB,qBAAqB,EACrB,oBAAoB,EACpB,oBAAoB,EACpB,sBAAsB,EACtB,sBAAsB,EACtB,iBAAiB,EACjB,sBAAsB,EACvB,MAAM,eAAe,CAAC;AAGvB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAWvD,UAAU,sBAAsB;IAC9B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAED;;GAEG;AACH,qBAAa,eAAgB,YAAW,OAAO;IAC7C,OAAO,CAAC,EAAE,CAAW;IACrB,OAAO,CAAC,WAAW,CAAS;IAE5B,OAAO;IAKP;;;;;;;OAOG;WACU,OAAO,CAClB,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,sBAAsB,GAC/B,OAAO,CAAC,eAAe,CAAC;IAiBrB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAIrB,iBAAiB,CACrB,MAAM,EAAE,uBAAuB,GAC9B,OAAO,CAAC,WAAW,CAAC;IA0CjB,cAAc,CAClB,MAAM,EAAE,oBAAoB,GAC3B,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;IAYxB,gBAAgB,CACpB,MAAM,EAAE,sBAAsB,GAC7B,OAAO,CAAC,iBAAiB,CAAC,WAAW,CAAC,CAAC;IA2B1C,OAAO,CAAC,0BAA0B;IA0B5B,gBAAgB,CACpB,MAAM,EAAE,sBAAsB,GAC7B,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;IAmDxB,sBAAsB,CAC1B,MAAM,EAAE,4BAA4B,GACnC,OAAO,CAAC,WAAW,CAAC;IAkBjB,gBAAgB,CAAC,MAAM,EAAE,sBAAsB,GAAG,OAAO,CAAC,WAAW,CAAC;IAwBtE,mBAAmB,CACvB,MAAM,EAAE,yBAAyB,GAChC,OAAO,CAAC,WAAW,CAAC;IAuBjB,eAAe,CAAC,MAAM,EAAE,qBAAqB,GAAG,OAAO,CAAC,WAAW,CAAC;IAgEpE,iBAAiB,CACrB,MAAM,EAAE,uBAAuB,GAC9B,OAAO,CAAC,WAAW,CAAC;IA2CjB,iBAAiB,CACrB,MAAM,EAAE,uBAAuB,GAC9B,OAAO,CAAC,WAAW,CAAC;IAoCjB,cAAc,CAClB,MAAM,EAAE,oBAAoB,GAC3B,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;IAWxB,gBAAgB,CACpB,MAAM,EAAE,sBAAsB,GAC7B,OAAO,CAAC,iBAAiB,CAAC,WAAW,CAAC,CAAC;IA2B1C,OAAO,CAAC,0BAA0B;IA6BlC,OAAO,CAAC,wBAAwB;IAyC1B,mBAAmB,CACvB,MAAM,EAAE,yBAAyB,GAChC,OAAO,CAAC,WAAW,CAAC;IA0BjB,eAAe,CAAC,MAAM,EAAE,qBAAqB,GAAG,OAAO,CAAC,WAAW,CAAC;CAyB3E"}
|