lightflow-engine 0.2.1 → 0.2.2
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 +1 -1
|
@@ -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