lightflow-engine 0.2.1 → 0.2.3
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/dist/src/compat/workflow.js +25 -0
- package/package.json +21 -6
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
* webpack loader (workflow/next) or explicit step() wrappers.
|
|
9
9
|
*/
|
|
10
10
|
import { createHash } from "node:crypto";
|
|
11
|
+
import { step, registerStep, } from "../index.js";
|
|
11
12
|
import { current } from "../index.js";
|
|
12
13
|
export { FatalError, CancelledError, sleep } from "../index.js";
|
|
13
14
|
export { getWorkflowMetadata } from "../compat/metadata.js";
|
|
@@ -69,3 +70,27 @@ export function workflowIdFor(fn) {
|
|
|
69
70
|
return "wf_" + createHash("sha256")
|
|
70
71
|
.update(String(fn).slice(0, 512)).digest("hex").slice(0, 16);
|
|
71
72
|
}
|
|
73
|
+
/**
|
|
74
|
+
* makeStep — turns a plain async function into a durable step callable.
|
|
75
|
+
*
|
|
76
|
+
* Entry's "use step" functions take arguments; lightflow's step() takes a
|
|
77
|
+
* thunk. makeStep wraps both: the returned function is a drop-in for the
|
|
78
|
+
* original (same signature), but each call becomes a memoized, retrying,
|
|
79
|
+
* replayable step keyed by call position. Outside a workflow it degrades
|
|
80
|
+
* to a plain call, so tests and non-durable paths keep working.
|
|
81
|
+
*/
|
|
82
|
+
export function makeStep(fn, opts) {
|
|
83
|
+
const wrapped = async (...args) => step(() => fn(...args));
|
|
84
|
+
Object.defineProperty(wrapped, "__lightflowStepId", {
|
|
85
|
+
value: `step_${workflowIdFor(fn)}`,
|
|
86
|
+
enumerable: false,
|
|
87
|
+
});
|
|
88
|
+
if (opts?.retries !== undefined) {
|
|
89
|
+
Object.defineProperty(wrapped, "__lightflowRetries", {
|
|
90
|
+
value: opts.retries,
|
|
91
|
+
enumerable: false,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
registerStep(wrapped.__lightflowStepId, fn);
|
|
95
|
+
return wrapped;
|
|
96
|
+
}
|
package/package.json
CHANGED
|
@@ -1,17 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lightflow-engine",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "A tiny durable workflow engine for Node.js and Postgres \u2014 with a Vercel Workflow drop-in compat layer.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "dist/index.js",
|
|
8
8
|
"types": "dist/index.d.ts",
|
|
9
9
|
"exports": {
|
|
10
|
-
".":
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
"./
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./pg": {
|
|
15
|
+
"types": "./dist/pg-store.d.ts",
|
|
16
|
+
"default": "./dist/pg-store.js"
|
|
17
|
+
},
|
|
18
|
+
"./compat/workflow": {
|
|
19
|
+
"types": "./dist/compat/workflow.d.ts",
|
|
20
|
+
"default": "./dist/compat/workflow.js"
|
|
21
|
+
},
|
|
22
|
+
"./compat/api": {
|
|
23
|
+
"types": "./dist/compat/api.d.ts",
|
|
24
|
+
"default": "./dist/compat/api.js"
|
|
25
|
+
},
|
|
26
|
+
"./compat/next": {
|
|
27
|
+
"types": "./dist/compat/next.d.ts",
|
|
28
|
+
"default": "./dist/compat/next.js"
|
|
29
|
+
}
|
|
15
30
|
},
|
|
16
31
|
"files": [
|
|
17
32
|
"dist",
|