lightflow-engine 0.2.7 → 0.2.8

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.
@@ -12,18 +12,19 @@
12
12
  */
13
13
  import { Engine, registerWorkflow } from "../index.js";
14
14
  import { workflowIdFor } from "./workflow.js";
15
- let sharedEngine = null;
16
- let sharedStore = null;
15
+ const g = globalThis;
16
+ if (!g.__lightflowCompat)
17
+ g.__lightflowCompat = { engine: null, store: null };
17
18
  /** Configure the compat layer with a store/engine (call once at boot). */
18
19
  export function initWorkflowApi(store, engine) {
19
- sharedStore = store;
20
- sharedEngine = engine ?? new Engine(store);
20
+ g.__lightflowCompat.store = store;
21
+ g.__lightflowCompat.engine = engine ?? new Engine(store);
21
22
  }
22
23
  export function getEngine() {
23
- if (!sharedEngine) {
24
+ if (!g.__lightflowCompat.engine) {
24
25
  throw new Error("workflow/api not initialized — call initWorkflowApi(store) at startup");
25
26
  }
26
- return sharedEngine;
27
+ return g.__lightflowCompat.engine;
27
28
  }
28
29
  /**
29
30
  * Register a workflow function under a stable id and start it. Mirrors
@@ -31,7 +32,7 @@ export function getEngine() {
31
32
  */
32
33
  function makeRunHandle(runId) {
33
34
  const engine = getEngine();
34
- const store = sharedStore;
35
+ const store = g.__lightflowCompat.store;
35
36
  /** One DB read -> Vercel status vocabulary. */
36
37
  const readStatus = async () => {
37
38
  const row = await store.getRun(runId);
package/dist/index.js CHANGED
@@ -26,8 +26,13 @@ export class FatalError extends Error {
26
26
  this.name = "FatalError";
27
27
  }
28
28
  }
29
- const workflows = new Map();
30
- const steps = new Map();
29
+ const reg = globalThis;
30
+ if (!reg.__lightflowWorkflows)
31
+ reg.__lightflowWorkflows = new Map();
32
+ if (!reg.__lightflowSteps)
33
+ reg.__lightflowSteps = new Map();
34
+ const workflows = reg.__lightflowWorkflows;
35
+ const steps = reg.__lightflowSteps;
31
36
  export function registerWorkflow(id, fn) {
32
37
  workflows.set(id, fn);
33
38
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lightflow-engine",
3
- "version": "0.2.7",
3
+ "version": "0.2.8",
4
4
  "description": "A tiny durable workflow engine for Node.js and Postgres — with a Vercel Workflow drop-in compat layer.",
5
5
  "license": "MIT",
6
6
  "type": "module",