openworkflow 0.3.0 → 0.4.1
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 +54 -18
- package/dist/backend-sqlite/backend.d.ts +38 -0
- package/dist/backend-sqlite/backend.d.ts.map +1 -0
- package/dist/backend-sqlite/backend.js +628 -0
- package/dist/backend-sqlite/backend.js.map +1 -0
- package/dist/backend-sqlite/index.d.ts +2 -0
- package/dist/backend-sqlite/index.d.ts.map +1 -0
- package/dist/backend-sqlite/index.js +2 -0
- package/dist/backend-sqlite/index.js.map +1 -0
- package/dist/backend-sqlite/sqlite.d.ts +45 -0
- package/dist/backend-sqlite/sqlite.d.ts.map +1 -0
- package/dist/backend-sqlite/sqlite.js +229 -0
- package/dist/backend-sqlite/sqlite.js.map +1 -0
- package/dist/config/config.d.ts +102 -0
- package/dist/config/config.d.ts.map +1 -0
- package/dist/config/config.js +29 -0
- package/dist/config/config.js.map +1 -0
- package/dist/config/index.d.ts +3 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +2 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config.d.ts +28 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +41 -0
- package/dist/config.js.map +1 -0
- package/dist/core/backend-test-suite.d.ts +22 -0
- package/dist/core/backend-test-suite.d.ts.map +1 -0
- package/dist/core/backend-test-suite.js +960 -0
- package/dist/core/backend-test-suite.js.map +1 -0
- package/dist/core/backend.d.ts +103 -0
- package/dist/core/backend.d.ts.map +1 -0
- package/dist/core/backend.js +2 -0
- package/dist/core/backend.js.map +1 -0
- package/dist/core/backend.testsuite.d.ts +21 -0
- package/dist/core/backend.testsuite.d.ts.map +1 -0
- package/dist/core/backend.testsuite.js +958 -0
- package/dist/core/backend.testsuite.js.map +1 -0
- package/dist/{duration.d.ts → core/duration.d.ts} +2 -1
- package/dist/core/duration.d.ts.map +1 -0
- package/dist/{duration.js → core/duration.js} +6 -5
- package/dist/core/duration.js.map +1 -0
- package/dist/core/duration.test.d.ts +2 -0
- package/dist/core/duration.test.d.ts.map +1 -0
- package/dist/core/duration.test.js +264 -0
- package/dist/core/duration.test.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 +12 -0
- package/dist/core/result.d.ts.map +1 -0
- package/dist/core/result.js +7 -0
- package/dist/core/result.js.map +1 -0
- package/dist/core/result.test.d.ts +2 -0
- package/dist/core/result.test.d.ts.map +1 -0
- package/dist/core/result.test.js +11 -0
- package/dist/core/result.test.js.map +1 -0
- package/dist/core/retry.d.ts +16 -0
- package/dist/core/retry.d.ts.map +1 -0
- package/dist/{backend.js → core/retry.js} +1 -3
- package/dist/core/retry.js.map +1 -0
- package/dist/core/retry.test.d.ts +2 -0
- package/dist/core/retry.test.d.ts.map +1 -0
- package/dist/core/retry.test.js +36 -0
- package/dist/core/retry.test.js.map +1 -0
- package/dist/core/schema.d.ts +57 -0
- package/dist/core/schema.d.ts.map +1 -0
- package/dist/core/schema.js +2 -0
- package/dist/core/schema.js.map +1 -0
- package/dist/core/step.d.ts +120 -0
- package/dist/core/step.d.ts.map +1 -0
- package/dist/core/step.js +101 -0
- package/dist/core/step.js.map +1 -0
- package/dist/core/step.test.d.ts +2 -0
- package/dist/core/step.test.d.ts.map +1 -0
- package/dist/core/step.test.js +340 -0
- package/dist/core/step.test.js.map +1 -0
- package/dist/core/workflow.d.ts +108 -0
- package/dist/core/workflow.d.ts.map +1 -0
- package/dist/core/workflow.js +79 -0
- package/dist/core/workflow.js.map +1 -0
- package/dist/core/workflow.test.d.ts +2 -0
- package/dist/core/workflow.test.d.ts.map +1 -0
- package/dist/core/workflow.test.js +216 -0
- package/dist/core/workflow.test.js.map +1 -0
- package/dist/execution/execution.d.ts +91 -0
- package/dist/execution/execution.d.ts.map +1 -0
- package/dist/execution/execution.js +188 -0
- package/dist/execution/execution.js.map +1 -0
- package/dist/execution/execution.test.d.ts +2 -0
- package/dist/execution/execution.test.d.ts.map +1 -0
- package/dist/execution/execution.test.js +382 -0
- package/dist/execution/execution.test.js.map +1 -0
- package/dist/global.d.ts +62 -0
- package/dist/global.d.ts.map +1 -0
- package/dist/global.js +78 -0
- package/dist/global.js.map +1 -0
- package/dist/index.d.ts +9 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -3
- package/dist/index.js.map +1 -1
- package/dist/sdk/sdk.d.ts +182 -0
- package/dist/sdk/sdk.d.ts.map +1 -0
- package/dist/sdk/sdk.js +208 -0
- package/dist/sdk/sdk.js.map +1 -0
- package/dist/sdk/sdk.test.d.ts +2 -0
- package/dist/sdk/sdk.test.d.ts.map +1 -0
- package/dist/sdk/sdk.test.js +195 -0
- package/dist/sdk/sdk.test.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/{worker.d.ts → worker/worker.d.ts} +4 -4
- package/dist/worker/worker.d.ts.map +1 -0
- package/dist/worker/worker.js +208 -0
- package/dist/worker/worker.js.map +1 -0
- package/dist/worker/worker.test.d.ts +2 -0
- package/dist/worker/worker.test.d.ts.map +1 -0
- package/dist/worker/worker.test.js +786 -0
- package/dist/worker/worker.test.js.map +1 -0
- package/package.json +9 -3
- package/dist/backend.d.ts +0 -159
- package/dist/backend.d.ts.map +0 -1
- package/dist/backend.js.map +0 -1
- package/dist/client.d.ts +0 -141
- package/dist/client.d.ts.map +0 -1
- package/dist/client.js +0 -135
- package/dist/client.js.map +0 -1
- package/dist/duration.d.ts.map +0 -1
- package/dist/duration.js.map +0 -1
- package/dist/worker.d.ts.map +0 -1
- package/dist/worker.js +0 -375
- package/dist/worker.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# OpenWorkflow
|
|
2
2
|
|
|
3
|
-
[](https://www.npmjs.com/package/openworkflow)
|
|
4
|
+
[](https://github.com/openworkflowdev/openworkflow/actions/workflows/ci.yaml)
|
|
5
|
+
[](https://codecov.io/github/openworkflowdev/openworkflow)
|
|
6
6
|
|
|
7
7
|
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
|
|
@@ -16,23 +16,29 @@ exactly where they left off - all without extra servers to manage.
|
|
|
16
16
|
Prerequisites:
|
|
17
17
|
|
|
18
18
|
- Node.js
|
|
19
|
-
- PostgreSQL (
|
|
20
|
-
See [Roadmap](#roadmap) for details.)
|
|
19
|
+
- PostgreSQL (and/or SQLite)
|
|
21
20
|
|
|
22
21
|
### 1. Install
|
|
23
22
|
|
|
24
23
|
```bash
|
|
25
|
-
npm install openworkflow @openworkflow/backend-postgres
|
|
24
|
+
npm install openworkflow @openworkflow/backend-postgres @openworkflow/backend-sqlite
|
|
26
25
|
```
|
|
27
26
|
|
|
27
|
+
You only need to install the backend package(s) for the database you plan to
|
|
28
|
+
use.
|
|
29
|
+
|
|
28
30
|
### 2. Define a workflow
|
|
29
31
|
|
|
30
32
|
```ts
|
|
31
33
|
import { BackendPostgres } from "@openworkflow/backend-postgres";
|
|
34
|
+
import { BackendSqlite } from "@openworkflow/backend-sqlite";
|
|
32
35
|
import { OpenWorkflow } from "openworkflow";
|
|
33
36
|
|
|
34
|
-
|
|
35
|
-
const backend =
|
|
37
|
+
// use Postgres if DATABASE_URL is set, otherwise use SQLite
|
|
38
|
+
const backend = process.env["DATABASE_URL"]
|
|
39
|
+
? await BackendPostgres.connect(process.env["DATABASE_URL"])
|
|
40
|
+
: BackendSqlite.connect(); // optionally provide SQLite file path
|
|
41
|
+
|
|
36
42
|
const ow = new OpenWorkflow({ backend });
|
|
37
43
|
|
|
38
44
|
const sendWelcomeEmail = ow.defineWorkflow(
|
|
@@ -149,7 +155,7 @@ Your database is the source of truth.
|
|
|
149
155
|
3. **The worker executes steps**: Each step is recorded in the `step_attempts`
|
|
150
156
|
table. If a step succeeds, its result is cached.
|
|
151
157
|
4. **The workflow completes**: The worker updates the `workflow_run` status to
|
|
152
|
-
`
|
|
158
|
+
`completed` or `failed`.
|
|
153
159
|
5. **If the worker crashes**: The workflow becomes visible to other workers via
|
|
154
160
|
a heartbeat timeout. Another worker picks it up, loads the cached step
|
|
155
161
|
results, and resumes from the next step.
|
|
@@ -220,7 +226,7 @@ Durations accept a number followed by a unit:
|
|
|
220
226
|
| years | `y`, `yr`, `yrs` | `1y`, `2yr` |
|
|
221
227
|
|
|
222
228
|
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).
|
|
229
|
+
[tests](https://github.com/openworkflowdev/openworkflow/blob/main/packages/openworkflow/core/duration.test.ts).
|
|
224
230
|
|
|
225
231
|
### Type Safety
|
|
226
232
|
|
|
@@ -297,6 +303,35 @@ const workflow = ow.defineWorkflow(
|
|
|
297
303
|
);
|
|
298
304
|
```
|
|
299
305
|
|
|
306
|
+
### Validating Workflow Inputs
|
|
307
|
+
|
|
308
|
+
You can require `.run()` callers to provide specific inputs by supplying a
|
|
309
|
+
`schema` when defining the workflow. The schema is evaluated before the run is
|
|
310
|
+
enqueued, so invalid requests fail immediately.
|
|
311
|
+
|
|
312
|
+
```ts
|
|
313
|
+
import { z } from "zod";
|
|
314
|
+
|
|
315
|
+
const summarizeDoc = ow.defineWorkflow(
|
|
316
|
+
{
|
|
317
|
+
name: "summarize",
|
|
318
|
+
schema: z.object({
|
|
319
|
+
docUrl: z.string().url(),
|
|
320
|
+
}),
|
|
321
|
+
},
|
|
322
|
+
async ({ input, step }) => {
|
|
323
|
+
// `input` has type { docUrl: string }
|
|
324
|
+
},
|
|
325
|
+
);
|
|
326
|
+
|
|
327
|
+
// Throws before enqueueing the workflow because the input isn't a URL
|
|
328
|
+
await summarizeDoc.run({ docUrl: "not-a-url" });
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
Any validator function works as long as it throws on invalid data (great for
|
|
332
|
+
custom logic or lightweight checks). Libraries such as Zod, ArkType, Valibot,
|
|
333
|
+
and Yup.
|
|
334
|
+
|
|
300
335
|
## Production Checklist
|
|
301
336
|
|
|
302
337
|
- **Database**: Use a production-ready Postgres instance
|
|
@@ -331,7 +366,7 @@ const workflow = ow.defineWorkflow(
|
|
|
331
366
|
|
|
332
367
|
**Live in current `npm` release:**
|
|
333
368
|
|
|
334
|
-
- ✅ PostgreSQL
|
|
369
|
+
- ✅ PostgreSQL and SQLite backends
|
|
335
370
|
- ✅ Worker with concurrency control
|
|
336
371
|
- ✅ Step memoization & retries
|
|
337
372
|
- ✅ Graceful shutdown
|
|
@@ -342,19 +377,20 @@ const workflow = ow.defineWorkflow(
|
|
|
342
377
|
|
|
343
378
|
**Coming Soon:**
|
|
344
379
|
|
|
345
|
-
> These
|
|
346
|
-
> inspect workflow and step state directly in PostgreSQL
|
|
347
|
-
> step_runs tables). A CLI and dashboard are planned for an
|
|
348
|
-
> make debugging and monitoring much easier.
|
|
380
|
+
> These releases don't yet include a dashboard UI or CLI. For now, you can
|
|
381
|
+
> inspect workflow and step state directly in PostgreSQL or SQLite
|
|
382
|
+
> (workflow_runs and step_runs tables). A CLI and dashboard are planned for an
|
|
383
|
+
> upcoming release to make debugging and monitoring much easier.
|
|
349
384
|
|
|
350
|
-
- Improved local dev experience
|
|
351
|
-
- CLI
|
|
385
|
+
- Improved local dev experience (coming in v0.5)
|
|
386
|
+
- CLI (coming in v0.5)
|
|
352
387
|
- Dashboard UI
|
|
353
388
|
- Idempotency keys
|
|
354
389
|
- Rollback / compensation functions
|
|
355
390
|
- Configurable retry policies
|
|
356
391
|
- Signals for external events
|
|
357
|
-
-
|
|
392
|
+
- Native OpenTelemetry integration
|
|
393
|
+
- Additional backends (Redis)
|
|
358
394
|
- Additional languages (Go, Python)
|
|
359
395
|
|
|
360
396
|
## Bugs & feature requests
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Backend, CancelWorkflowRunParams, ClaimWorkflowRunParams, CreateStepAttemptParams, CreateWorkflowRunParams, GetStepAttemptParams, GetWorkflowRunParams, ExtendWorkflowRunLeaseParams, ListStepAttemptsParams, ListWorkflowRunsParams, PaginatedResponse, FailStepAttemptParams, CompleteStepAttemptParams, FailWorkflowRunParams, CompleteWorkflowRunParams, SleepWorkflowRunParams, StepAttempt, WorkflowRun } from "../index.js";
|
|
2
|
+
export declare const DEFAULT_PAGINATION_PAGE_SIZE = 100;
|
|
3
|
+
interface BackendSqliteOptions {
|
|
4
|
+
namespaceId?: string;
|
|
5
|
+
runMigrations?: boolean;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Manages a connection to a SQLite database for workflow operations.
|
|
9
|
+
*/
|
|
10
|
+
export declare class BackendSqlite implements Backend {
|
|
11
|
+
private db;
|
|
12
|
+
private namespaceId;
|
|
13
|
+
private constructor();
|
|
14
|
+
/**
|
|
15
|
+
* Create and initialize a new BackendSqlite instance. This will
|
|
16
|
+
* automatically run migrations on startup unless `runMigrations` is set to
|
|
17
|
+
* false.
|
|
18
|
+
*/
|
|
19
|
+
static connect(path?: string, options?: BackendSqliteOptions): BackendSqlite;
|
|
20
|
+
stop(): void;
|
|
21
|
+
createWorkflowRun(params: CreateWorkflowRunParams): Promise<WorkflowRun>;
|
|
22
|
+
getWorkflowRun(params: GetWorkflowRunParams): Promise<WorkflowRun | null>;
|
|
23
|
+
claimWorkflowRun(params: ClaimWorkflowRunParams): Promise<WorkflowRun | null>;
|
|
24
|
+
extendWorkflowRunLease(params: ExtendWorkflowRunLeaseParams): Promise<WorkflowRun>;
|
|
25
|
+
sleepWorkflowRun(params: SleepWorkflowRunParams): Promise<WorkflowRun>;
|
|
26
|
+
completeWorkflowRun(params: CompleteWorkflowRunParams): Promise<WorkflowRun>;
|
|
27
|
+
failWorkflowRun(params: FailWorkflowRunParams): Promise<WorkflowRun>;
|
|
28
|
+
cancelWorkflowRun(params: CancelWorkflowRunParams): Promise<WorkflowRun>;
|
|
29
|
+
listWorkflowRuns(params: ListWorkflowRunsParams): Promise<PaginatedResponse<WorkflowRun>>;
|
|
30
|
+
listStepAttempts(params: ListStepAttemptsParams): Promise<PaginatedResponse<StepAttempt>>;
|
|
31
|
+
private processPaginationResults;
|
|
32
|
+
createStepAttempt(params: CreateStepAttemptParams): Promise<StepAttempt>;
|
|
33
|
+
getStepAttempt(params: GetStepAttemptParams): Promise<StepAttempt | null>;
|
|
34
|
+
completeStepAttempt(params: CompleteStepAttemptParams): Promise<StepAttempt>;
|
|
35
|
+
failStepAttempt(params: FailStepAttemptParams): Promise<StepAttempt>;
|
|
36
|
+
}
|
|
37
|
+
export {};
|
|
38
|
+
//# sourceMappingURL=backend.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"backend.d.ts","sourceRoot":"","sources":["../../backend-sqlite/backend.ts"],"names":[],"mappings":"AAaA,OAAO,EAEL,OAAO,EACP,uBAAuB,EACvB,sBAAsB,EACtB,uBAAuB,EACvB,uBAAuB,EACvB,oBAAoB,EACpB,oBAAoB,EACpB,4BAA4B,EAC5B,sBAAsB,EACtB,sBAAsB,EACtB,iBAAiB,EACjB,qBAAqB,EACrB,yBAAyB,EACzB,qBAAqB,EACrB,yBAAyB,EACzB,sBAAsB,EACtB,WAAW,EACX,WAAW,EAGZ,MAAM,aAAa,CAAC;AAErB,eAAO,MAAM,4BAA4B,MAAM,CAAC;AAEhD,UAAU,oBAAoB;IAC5B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAED;;GAEG;AACH,qBAAa,aAAc,YAAW,OAAO;IAC3C,OAAO,CAAC,EAAE,CAAW;IACrB,OAAO,CAAC,WAAW,CAAS;IAE5B,OAAO;IAKP;;;;OAIG;IACH,MAAM,CAAC,OAAO,CACZ,IAAI,GAAE,MAA8B,EACpC,OAAO,CAAC,EAAE,oBAAoB,GAC7B,aAAa;IAgBhB,IAAI,IAAI,IAAI;IAIN,iBAAiB,CACrB,MAAM,EAAE,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