@barnum/barnum 0.0.0-main-cb3a2cd4 → 0.0.0-main-9c142eea

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/src/handler.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { fileURLToPath } from "node:url";
2
2
  import type { JSONSchema7 } from "json-schema";
3
3
  import type { z } from "zod";
4
- import { type TypedAction, toAction, typedAction } from "./ast.js";
4
+ import { type TypedAction, typedAction } from "./ast.js";
5
5
  import { chain } from "./chain.js";
6
6
  import { all } from "./all.js";
7
7
  import { constant, identity } from "./builtins/index.js";
@@ -248,7 +248,7 @@ export function createHandlerWithConfig(
248
248
  // __definition for the worker to find (the worker imports the module
249
249
  // and accesses the named export, which is this function).
250
250
  const factory = (config: unknown): TypedAction =>
251
- chain(toAction(all(identity(), constant(config))), toAction(invokeAction));
251
+ chain(all(identity(), constant(config)), invokeAction);
252
252
 
253
253
  Object.defineProperty(factory, HANDLER_BRAND, {
254
254
  value: true,
package/src/iterator.ts CHANGED
@@ -102,7 +102,7 @@ export const Iterator = {
102
102
  ): TypedAction<IteratorT<TIn>, IteratorT<TOut>> {
103
103
  return chain(
104
104
  toAction(getField("value")),
105
- chain(toAction(forEach(action)), Iterator.fromArray<TOut>()),
105
+ chain(forEach(action), Iterator.fromArray<TOut>()),
106
106
  ) as TypedAction<IteratorT<TIn>, IteratorT<TOut>>;
107
107
  },
108
108
 
@@ -114,7 +114,7 @@ export const Iterator = {
114
114
  toAction(getField("value")),
115
115
  chain(
116
116
  toAction(forEach(chain(action, intoIteratorNormalize))),
117
- chain(toAction(flatten()), Iterator.fromArray<TOut>()),
117
+ chain(flatten<TOut>(), Iterator.fromArray<TOut>()),
118
118
  ),
119
119
  ) as TypedAction<IteratorT<TIn>, IteratorT<TOut>>;
120
120
  },
@@ -178,39 +178,35 @@ export const Iterator = {
178
178
  // Use bind + typedAction to bridge VoidToNull<TAcc> → TAcc (TypeScript
179
179
  // can't simplify the conditional type for generic TAcc).
180
180
  return typedAction<IteratorT<TElement>, TAcc>(
181
- toAction(
182
- Iterator.collect<TElement>().then(
183
- bind([identity<Array<TElement>>()], ([elements]) =>
184
- pipe(
185
- drop,
186
- all(init, elements).then(
187
- loop<[TAcc, Array<TElement>], TAcc>((recur, done) => {
188
- const doneTAcc = typedAction<TAcc, never>(toAction(done));
189
-
190
- return typedAction<[TAcc, Array<TElement>], never>(
191
- toAction(
192
- bindInput<[TAcc, Array<TElement>], never>((state) => {
193
- const [acc, remaining] = state.split();
194
-
195
- return remaining.splitFirst().branch({
196
- None: acc.then(doneTAcc),
197
- Some: bindInput<[TElement, Array<TElement>], never>(
198
- (headTail) => {
199
- const [head, tail] = headTail.split();
200
-
201
- return all(acc, head)
202
- .then(body)
203
- .bindInput<never>((newAcc) =>
204
- all(newAcc, tail).then(recur),
205
- );
206
- },
207
- ),
208
- });
209
- }),
210
- ),
211
- );
212
- }),
213
- ),
181
+ Iterator.collect<TElement>().then(
182
+ bind([identity<Array<TElement>>()], ([elements]) =>
183
+ pipe(
184
+ drop,
185
+ all(init, elements).then(
186
+ loop<[TAcc, Array<TElement>], TAcc>((recur, done) => {
187
+ const doneTAcc = typedAction<TAcc, never>(done);
188
+
189
+ return typedAction<[TAcc, Array<TElement>], never>(
190
+ bindInput<[TAcc, Array<TElement>], never>((state) => {
191
+ const [acc, remaining] = state.split();
192
+
193
+ return remaining.splitFirst().branch({
194
+ None: acc.then(doneTAcc),
195
+ Some: bindInput<[TElement, Array<TElement>], never>(
196
+ (headTail) => {
197
+ const [head, tail] = headTail.split();
198
+
199
+ return all(acc, head)
200
+ .then(body)
201
+ .bindInput<never>((newAcc) =>
202
+ all(newAcc, tail).then(recur),
203
+ );
204
+ },
205
+ ),
206
+ });
207
+ }),
208
+ );
209
+ }),
214
210
  ),
215
211
  ),
216
212
  ),
@@ -225,10 +221,7 @@ export const Iterator = {
225
221
  ): TypedAction<IteratorT<TElement>, IteratorT<TElement>> {
226
222
  return chain(
227
223
  Iterator.collect<TElement>(),
228
- chain(
229
- toAction(slice<TElement>(start, end)),
230
- Iterator.fromArray<TElement>(),
231
- ),
224
+ chain(slice<TElement>(start, end), Iterator.fromArray<TElement>()),
232
225
  );
233
226
  },
234
227
 
package/src/option.ts CHANGED
@@ -5,7 +5,6 @@ import {
5
5
  type Result as ResultT,
6
6
  type TypedAction,
7
7
  branch,
8
- toAction,
9
8
  typedAction,
10
9
  } from "./ast.js";
11
10
  import { chain } from "./chain.js";
@@ -171,10 +170,10 @@ export function first<TElement>(): TypedAction<
171
170
  Array<TElement>,
172
171
  OptionT<TElement>
173
172
  > {
174
- return chain(
175
- toAction(splitFirst()),
176
- toAction(Option.map(toAction(getIndex(0).unwrap()))),
177
- ) as TypedAction<Array<TElement>, OptionT<TElement>>;
173
+ return chain(splitFirst(), Option.map(getIndex(0).unwrap())) as TypedAction<
174
+ Array<TElement>,
175
+ OptionT<TElement>
176
+ >;
178
177
  }
179
178
 
180
179
  // ---------------------------------------------------------------------------
@@ -192,8 +191,8 @@ export function last<TElement>(): TypedAction<
192
191
  Array<TElement>,
193
192
  OptionT<TElement>
194
193
  > {
195
- return chain(
196
- toAction(splitLast()),
197
- toAction(Option.map(toAction(getIndex(1).unwrap()))),
198
- ) as TypedAction<Array<TElement>, OptionT<TElement>>;
194
+ return chain(splitLast(), Option.map(getIndex(1).unwrap())) as TypedAction<
195
+ Array<TElement>,
196
+ OptionT<TElement>
197
+ >;
199
198
  }
package/src/pipe.ts CHANGED
@@ -1,10 +1,4 @@
1
- import {
2
- type Action,
3
- type PipeIn,
4
- type Pipeable,
5
- type TypedAction,
6
- toAction,
7
- } from "./ast.js";
1
+ import type { Action, PipeIn, Pipeable, TypedAction } from "./ast.js";
8
2
  import { chain } from "./chain.js";
9
3
  import { identity } from "./builtins/index.js";
10
4
 
@@ -1098,7 +1092,5 @@ export function pipe(...actions: Array<Action>): Action {
1098
1092
  if (actions.length === 1) {
1099
1093
  return actions[0];
1100
1094
  }
1101
- return actions.reduceRight((rest, first) =>
1102
- toAction(chain(toAction(first), toAction(rest))),
1103
- );
1095
+ return actions.reduceRight((rest, first) => chain(first, rest));
1104
1096
  }
package/src/race.ts CHANGED
@@ -4,7 +4,6 @@ import {
4
4
  type Result as ResultT,
5
5
  type TypedAction,
6
6
  buildRestartBranchAction,
7
- toAction,
8
7
  typedAction,
9
8
  } from "./ast.js";
10
9
  import { chain } from "./chain.js";
@@ -21,12 +20,10 @@ import {
21
20
  * restarts the body; Branch takes the Break arm (identity), `RestartHandle` exits.
22
21
  */
23
22
  function breakPerform(restartHandlerId: RestartHandlerId): Action {
24
- return toAction(
25
- chain(toAction(tag("Break", "LoopResult")), {
26
- kind: "RestartPerform",
27
- restart_handler_id: restartHandlerId,
28
- }),
29
- );
23
+ return chain(tag("Break", "LoopResult"), {
24
+ kind: "RestartPerform",
25
+ restart_handler_id: restartHandlerId,
26
+ });
30
27
  }
31
28
 
32
29
  // ---------------------------------------------------------------------------
@@ -57,14 +54,14 @@ export function race<TIn, TOut>(
57
54
  const restartHandlerId = allocateRestartHandlerId();
58
55
  const perform = breakPerform(restartHandlerId);
59
56
 
60
- const branches = actions.map((action) =>
61
- toAction(chain(toAction(action), toAction(perform))),
57
+ const branches: Array<Action> = actions.map((action) =>
58
+ chain(action, perform),
62
59
  );
63
60
 
64
61
  const allAction: Action = { kind: "All", actions: branches };
65
62
 
66
63
  return typedAction(
67
- buildRestartBranchAction(restartHandlerId, allAction, toAction(identity())),
64
+ buildRestartBranchAction(restartHandlerId, allAction, identity()),
68
65
  );
69
66
  }
70
67
 
@@ -144,30 +141,18 @@ export function withTimeout<TIn, TOut>(
144
141
  const restartHandlerId = allocateRestartHandlerId();
145
142
  const perform = breakPerform(restartHandlerId);
146
143
 
147
- // Branch 1: body → Tag("Ok") → Break → RestartPerform
148
- const bodyBranch = toAction(
149
- chain(
150
- toAction(chain(toAction(body), toAction(Result.ok()))),
151
- toAction(perform),
152
- ),
153
- );
144
+ // Branch 1: body → Ok → Break → RestartPerform
145
+ const bodyBranch: Action = chain(chain(body, Result.ok()), perform);
154
146
 
155
- // Branch 2: ms → sleep() → Tag("Err") → Break → RestartPerform
156
- const sleepBranch = toAction(
157
- chain(
158
- toAction(
159
- chain(
160
- toAction(chain(toAction(ms), toAction(DYNAMIC_SLEEP_INVOKE))),
161
- toAction(Result.err()),
162
- ),
163
- ),
164
- toAction(perform),
165
- ),
147
+ // Branch 2: ms → sleep() → Err → Break → RestartPerform
148
+ const sleepBranch: Action = chain(
149
+ chain(chain(ms, DYNAMIC_SLEEP_INVOKE), Result.err()),
150
+ perform,
166
151
  );
167
152
 
168
153
  const allAction: Action = { kind: "All", actions: [bodyBranch, sleepBranch] };
169
154
 
170
155
  return typedAction(
171
- buildRestartBranchAction(restartHandlerId, allAction, toAction(identity())),
156
+ buildRestartBranchAction(restartHandlerId, allAction, identity()),
172
157
  );
173
158
  }
package/src/recursive.ts CHANGED
@@ -73,49 +73,34 @@ export function defineRecursiveFunctions<TDefs extends Array<FunctionDef>>(
73
73
  // Call tokens: Chain(Tag("CallN"), ResumePerform(resumeHandlerId))
74
74
  const fnCount = bodiesFn.length;
75
75
  const callTokens = Array.from({ length: fnCount }, (_, i) =>
76
- typedAction(
77
- toAction(
78
- chain(
79
- toAction(tag(`Call${i}`, "RecursiveDispatch")),
80
- toAction(resumePerform),
81
- ),
82
- ),
83
- ),
76
+ typedAction(chain(tag(`Call${i}`, "RecursiveDispatch"), resumePerform)),
84
77
  );
85
78
 
86
79
  // Get function body ASTs
87
- const bodyActions = (
88
- bodiesFn(...(callTokens as FunctionRefs<TDefs>)) as Array<Pipeable>
89
- ).map(toAction);
80
+ const bodyActions: Array<Action> = bodiesFn(
81
+ ...(callTokens as FunctionRefs<TDefs>),
82
+ ) as Array<Pipeable>;
90
83
 
91
84
  // Branch cases: CallN → GetField("value") → bodyN
92
85
  const cases: Record<string, Action> = {};
93
86
  for (let i = 0; i < bodyActions.length; i++) {
94
- cases[`Call${i}`] = toAction(
95
- chain(toAction(getField("value")), toAction(bodyActions[i])),
96
- );
87
+ cases[`Call${i}`] = chain(getField("value"), bodyActions[i]);
97
88
  }
98
89
 
99
90
  // Return curried entry-point combinator
100
91
  return <TOut>(entryFn: (...fns: FunctionRefs<TDefs>) => BodyResult<TOut>) => {
101
- const userBody = toAction(entryFn(...(callTokens as FunctionRefs<TDefs>)));
92
+ const userBody: Action = entryFn(...(callTokens as FunctionRefs<TDefs>));
102
93
 
103
94
  return typedAction<any, TOut>(
104
- toAction(
105
- chain(toAction(all(identity(), constant(UNUSED_STATE))), {
106
- kind: "ResumeHandle",
107
- resume_handler_id: resumeHandlerId,
108
- body: toAction(
109
- chain(toAction(getIndex(0).unwrap()), toAction(userBody)),
110
- ),
111
- handler: toAction(
112
- all(
113
- chain(toAction(getIndex(0).unwrap()), toAction(branch(cases))),
114
- constant(UNUSED_STATE),
115
- ),
116
- ),
117
- }),
118
- ),
95
+ chain(all(identity(), constant(UNUSED_STATE)), {
96
+ kind: "ResumeHandle",
97
+ resume_handler_id: resumeHandlerId,
98
+ body: chain(toAction(getIndex(0).unwrap()), userBody),
99
+ handler: all(
100
+ chain(toAction(getIndex(0).unwrap()), branch(cases)),
101
+ constant(UNUSED_STATE),
102
+ ),
103
+ }),
119
104
  );
120
105
  };
121
106
  }
package/src/run.ts CHANGED
@@ -8,12 +8,7 @@ import { createRequire } from "node:module";
8
8
  import { existsSync, mkdtempSync, unlinkSync, writeFileSync } from "node:fs";
9
9
  import os from "node:os";
10
10
  import path from "node:path";
11
- import {
12
- type Action,
13
- type Config,
14
- type ExtractOutput,
15
- toAction,
16
- } from "./ast.js";
11
+ import type { Action, Config, ExtractOutput } from "./ast.js";
17
12
  import { chain } from "./chain.js";
18
13
  import { constant } from "./builtins/index.js";
19
14
 
@@ -135,9 +130,7 @@ export function runPipeline<TPipeline extends Action>(
135
130
  options?: RunPipelineOptions,
136
131
  ): Promise<ExtractOutput<TPipeline>> {
137
132
  const workflow =
138
- input === undefined
139
- ? pipeline
140
- : toAction(chain(toAction(constant(input)), toAction(pipeline)));
133
+ input === undefined ? pipeline : chain(constant(input), pipeline);
141
134
  return spawnBarnum({ workflow }, options?.logLevel);
142
135
  }
143
136
 
package/src/try-catch.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import {
2
+ type Action,
2
3
  type Pipeable,
3
4
  type TypedAction,
4
5
  buildRestartBranchAction,
5
- toAction,
6
6
  typedAction,
7
7
  } from "./ast.js";
8
8
  import { chain } from "./chain.js";
@@ -41,17 +41,15 @@ export function tryCatch<TIn, TOut, TError>(
41
41
  const restartHandlerId = allocateRestartHandlerId();
42
42
 
43
43
  const throwError = typedAction<TError, never>(
44
- toAction(
45
- chain(toAction(tag("Break", "LoopResult")), {
46
- kind: "RestartPerform",
47
- restart_handler_id: restartHandlerId,
48
- }),
49
- ),
44
+ chain(tag("Break", "LoopResult"), {
45
+ kind: "RestartPerform",
46
+ restart_handler_id: restartHandlerId,
47
+ }),
50
48
  );
51
49
 
52
- const bodyAction = toAction(body(throwError));
50
+ const bodyAction: Action = body(throwError);
53
51
 
54
52
  return typedAction(
55
- buildRestartBranchAction(restartHandlerId, bodyAction, toAction(recovery)),
53
+ buildRestartBranchAction(restartHandlerId, bodyAction, recovery),
56
54
  );
57
55
  }