@barnum/barnum 0.0.0-main-330fcf0a → 0.0.0-main-ef6df91f

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.
Binary file
Binary file
Binary file
Binary file
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barnum/barnum",
3
- "version": "0.0.0-main-330fcf0a",
3
+ "version": "0.0.0-main-ef6df91f",
4
4
  "description": "Barnum workflow engine",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
package/src/ast.ts CHANGED
@@ -1089,7 +1089,7 @@ export class RunnableConfig<Out = any> {
1089
1089
  // Dynamic import to avoid pulling in Node.js APIs at module load time
1090
1090
  // (keeps ast.ts importable in non-Node environments for type checking).
1091
1091
  const { run } = await import("./run.js");
1092
- run(this.toJSON());
1092
+ await run(this.toJSON());
1093
1093
  }
1094
1094
 
1095
1095
  /** Serialize to the same shape as Config. */
package/src/bind.ts CHANGED
@@ -131,7 +131,7 @@ export function bind<TBindings extends Action[], TOut>(
131
131
  }
132
132
 
133
133
  // 5. All(...bindings, identity()) → nested Handles
134
- const allActions = [...bindings.map((b) => b as Action), identity() as Action];
134
+ const allActions = [...bindings.map((b) => b as Action), identity as Action];
135
135
  return typedAction({
136
136
  kind: "Chain",
137
137
  first: { kind: "All", actions: allActions },
@@ -156,7 +156,7 @@ export function bind<TBindings extends Action[], TOut>(
156
156
  export function bindInput<TIn, TOut = any>(
157
157
  body: (input: VarRef<TIn>) => BodyResult<TOut>,
158
158
  ): TypedAction<TIn, TOut> {
159
- return bind([identity<TIn>()], ([input]) =>
159
+ return bind([identity], ([input]) =>
160
160
  pipe(drop, body(input)),
161
161
  );
162
162
  }
package/src/builtins.ts CHANGED
@@ -23,12 +23,10 @@ export function constant<TValue>(value: TValue): TypedAction<any, TValue> {
23
23
  // Identity — pass input through unchanged
24
24
  // ---------------------------------------------------------------------------
25
25
 
26
- export function identity<TValue>(): TypedAction<TValue, TValue> {
27
- return typedAction({
28
- kind: "Invoke",
29
- handler: { kind: "Builtin", builtin: { kind: "Identity" } },
30
- });
31
- }
26
+ export const identity: TypedAction<any, any> = typedAction({
27
+ kind: "Invoke",
28
+ handler: { kind: "Builtin", builtin: { kind: "Identity" } },
29
+ });
32
30
 
33
31
  // ---------------------------------------------------------------------------
34
32
  // Drop — discard pipeline value
@@ -200,7 +198,7 @@ export function withResource<
200
198
  const acquireAndMerge = chain(
201
199
  typedAction<TIn, [TResource, TIn]>({
202
200
  kind: "All",
203
- actions: [create as Action, identity() as Action],
201
+ actions: [create as Action, identity as Action],
204
202
  }),
205
203
  typedAction<[TResource, TIn], TResource & TIn>(mergeBuiltin),
206
204
  );
@@ -209,7 +207,7 @@ export function withResource<
209
207
  // Keep merged object so dispose can access resource fields.
210
208
  const actionAndKeepMerged = typedAction<TResource & TIn, [TOut, TResource & TIn]>({
211
209
  kind: "All",
212
- actions: [action as Action, identity() as Action],
210
+ actions: [action as Action, identity as Action],
213
211
  });
214
212
 
215
213
  // Step 3: all(extractIndex(0), chain(extractIndex(1), dispose)) → [TOut, unknown]
@@ -257,7 +255,7 @@ export function augment<
257
255
  kind: "Chain",
258
256
  first: {
259
257
  kind: "All",
260
- actions: [action as Action, identity() as Action],
258
+ actions: [action as Action, identity as Action],
261
259
  },
262
260
  rest: { kind: "Invoke", handler: { kind: "Builtin", builtin: { kind: "Merge" } } },
263
261
  });
package/src/pipe.ts CHANGED
@@ -113,7 +113,7 @@ export function pipe<
113
113
  ): TypedAction<PipeIn<T1>, T11, R1 | R2 | R3 | R4 | R5 | R6 | R7 | R8 | R9 | R10>;
114
114
  export function pipe(...actions: Action[]): Action {
115
115
  if (actions.length === 0) {
116
- return identity();
116
+ return identity;
117
117
  }
118
118
  if (actions.length === 1) {
119
119
  return actions[0];
package/src/run.ts CHANGED
@@ -3,7 +3,7 @@
3
3
  * script, then spawns the workflow as a subprocess.
4
4
  */
5
5
 
6
- import { execFileSync } from "node:child_process";
6
+ import { execFileSync, spawn as nodeSpawn } from "node:child_process";
7
7
  import { createRequire } from "node:module";
8
8
  import { existsSync } from "node:fs";
9
9
  import os from "node:os";
@@ -90,7 +90,7 @@ function buildBinary(): void {
90
90
  }
91
91
 
92
92
  /** Run a workflow config to completion. Prints result to stdout. */
93
- export function run(config: Config): void {
93
+ export async function run(config: Config): Promise<void> {
94
94
  const binaryResolution = resolveBinary();
95
95
  if (binaryResolution.kind === "Local") {
96
96
  buildBinary();
@@ -99,10 +99,37 @@ export function run(config: Config): void {
99
99
  const worker = resolveWorker();
100
100
  const configJson = JSON.stringify(config);
101
101
 
102
- execFileSync(binaryResolution.path, [
103
- "run",
104
- "--config", configJson,
105
- "--executor", executor,
106
- "--worker", worker,
107
- ], { stdio: "inherit" });
102
+ return new Promise<void>((resolve, reject) => {
103
+ const child = nodeSpawn(binaryResolution.path, [
104
+ "run",
105
+ "--config", configJson,
106
+ "--executor", executor,
107
+ "--worker", worker,
108
+ ], {
109
+ stdio: ["inherit", "inherit", "pipe"],
110
+ });
111
+
112
+ const stderrChunks: Buffer[] = [];
113
+
114
+ child.stderr!.on("data", (chunk: Buffer) => {
115
+ stderrChunks.push(chunk);
116
+ process.stderr.write(chunk);
117
+ });
118
+
119
+ child.on("error", (error) => {
120
+ reject(new Error(`Failed to spawn barnum: ${error.message}`));
121
+ });
122
+
123
+ child.on("close", (code) => {
124
+ if (code !== 0) {
125
+ const stderr = Buffer.concat(stderrChunks).toString("utf-8").trim();
126
+ const message = stderr
127
+ ? `barnum exited with code ${code}:\n${stderr}`
128
+ : `barnum exited with code ${code} (no stderr output)`;
129
+ reject(new Error(message));
130
+ return;
131
+ }
132
+ resolve();
133
+ });
134
+ });
108
135
  }