@barnum/barnum 0.3.0 → 0.4.0

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.
Files changed (109) hide show
  1. package/artifacts/linux-arm64/barnum +0 -0
  2. package/artifacts/linux-x64/barnum +0 -0
  3. package/artifacts/macos-arm64/barnum +0 -0
  4. package/artifacts/macos-x64/barnum +0 -0
  5. package/artifacts/win-x64/barnum.exe +0 -0
  6. package/dist/all.d.ts +41 -10
  7. package/dist/all.d.ts.map +1 -0
  8. package/dist/all.js +1 -1
  9. package/dist/ast.d.ts +199 -98
  10. package/dist/ast.d.ts.map +1 -0
  11. package/dist/ast.js +271 -233
  12. package/dist/bind.d.ts +9 -12
  13. package/dist/bind.d.ts.map +1 -0
  14. package/dist/bind.js +14 -51
  15. package/dist/builtins/array.d.ts +36 -0
  16. package/dist/builtins/array.d.ts.map +1 -0
  17. package/dist/builtins/array.js +93 -0
  18. package/dist/builtins/index.d.ts +6 -0
  19. package/dist/builtins/index.d.ts.map +1 -0
  20. package/dist/builtins/index.js +5 -0
  21. package/dist/builtins/scalar.d.ts +12 -0
  22. package/dist/builtins/scalar.d.ts.map +1 -0
  23. package/dist/builtins/scalar.js +41 -0
  24. package/dist/builtins/struct.d.ts +25 -0
  25. package/dist/builtins/struct.d.ts.map +1 -0
  26. package/dist/builtins/struct.js +67 -0
  27. package/dist/builtins/tagged-union.d.ts +54 -0
  28. package/dist/builtins/tagged-union.d.ts.map +1 -0
  29. package/dist/builtins/tagged-union.js +81 -0
  30. package/dist/builtins/with-resource.d.ts +23 -0
  31. package/dist/builtins/with-resource.d.ts.map +1 -0
  32. package/dist/builtins/with-resource.js +35 -0
  33. package/dist/chain.d.ts +1 -0
  34. package/dist/chain.d.ts.map +1 -0
  35. package/dist/chain.js +3 -3
  36. package/dist/effect-id.d.ts +1 -0
  37. package/dist/effect-id.d.ts.map +1 -0
  38. package/dist/handler.d.ts +7 -6
  39. package/dist/handler.d.ts.map +1 -0
  40. package/dist/handler.js +5 -21
  41. package/dist/index.d.ts +10 -6
  42. package/dist/index.d.ts.map +1 -0
  43. package/dist/index.js +4 -2
  44. package/dist/iterator.d.ts +32 -0
  45. package/dist/iterator.d.ts.map +1 -0
  46. package/dist/iterator.js +123 -0
  47. package/dist/option.d.ts +74 -0
  48. package/dist/option.d.ts.map +1 -0
  49. package/dist/option.js +141 -0
  50. package/dist/pipe.d.ts +11 -10
  51. package/dist/pipe.d.ts.map +1 -0
  52. package/dist/pipe.js +5 -4
  53. package/dist/race.d.ts +5 -4
  54. package/dist/race.d.ts.map +1 -0
  55. package/dist/race.js +17 -42
  56. package/dist/recursive.d.ts +9 -3
  57. package/dist/recursive.d.ts.map +1 -0
  58. package/dist/recursive.js +18 -13
  59. package/dist/result.d.ts +50 -0
  60. package/dist/result.d.ts.map +1 -0
  61. package/dist/result.js +117 -0
  62. package/dist/run.d.ts +9 -2
  63. package/dist/run.d.ts.map +1 -0
  64. package/dist/run.js +37 -20
  65. package/dist/runtime.d.ts +6 -0
  66. package/dist/runtime.d.ts.map +1 -0
  67. package/dist/runtime.js +7 -0
  68. package/dist/schema.d.ts +1 -0
  69. package/dist/schema.d.ts.map +1 -0
  70. package/dist/schemas.d.ts +5 -0
  71. package/dist/schemas.d.ts.map +1 -0
  72. package/dist/schemas.js +13 -0
  73. package/dist/try-catch.d.ts +2 -1
  74. package/dist/try-catch.d.ts.map +1 -0
  75. package/dist/try-catch.js +10 -9
  76. package/dist/values.d.ts +6 -0
  77. package/dist/values.d.ts.map +1 -0
  78. package/dist/values.js +12 -0
  79. package/dist/worker.d.ts +5 -1
  80. package/dist/worker.d.ts.map +1 -0
  81. package/dist/worker.js +15 -3
  82. package/package.json +8 -6
  83. package/src/all.ts +118 -74
  84. package/src/ast.ts +773 -350
  85. package/src/bind.ts +32 -62
  86. package/src/builtins/array.ts +121 -0
  87. package/src/builtins/index.ts +17 -0
  88. package/src/builtins/scalar.ts +49 -0
  89. package/src/builtins/struct.ts +111 -0
  90. package/src/builtins/tagged-union.ts +142 -0
  91. package/src/builtins/with-resource.ts +69 -0
  92. package/src/chain.ts +4 -4
  93. package/src/handler.ts +12 -28
  94. package/src/index.ts +24 -17
  95. package/src/iterator.ts +243 -0
  96. package/src/option.ts +199 -0
  97. package/src/pipe.ts +123 -78
  98. package/src/race.ts +41 -51
  99. package/src/recursive.ts +44 -27
  100. package/src/result.ts +168 -0
  101. package/src/run.ts +53 -25
  102. package/src/runtime.ts +16 -0
  103. package/src/schemas.ts +21 -0
  104. package/src/try-catch.ts +14 -10
  105. package/src/values.ts +21 -0
  106. package/src/worker.ts +17 -2
  107. package/dist/builtins.d.ts +0 -257
  108. package/dist/builtins.js +0 -600
  109. package/src/builtins.ts +0 -804
package/dist/worker.js CHANGED
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  /**
3
2
  * Worker script: invoked as `tsx worker.ts <module> <export>`.
4
3
  *
@@ -6,9 +5,17 @@
6
5
  * Rust → stdin: JSON `{ "value": <any> }`
7
6
  * stdout → Rust: JSON result (handler return value)
8
7
  *
8
+ * stdout is reserved for the protocol. All console output is redirected to
9
+ * stderr so that handler code can freely use console.log for debugging.
10
+ *
9
11
  * If the handler throws or the module/export can't be resolved, the
10
12
  * process exits non-zero. Rust interprets that as a fatal workflow error.
11
13
  */
14
+ // Redirect all console output to stderr — stdout is the protocol channel.
15
+ // This must happen before any handler code is imported or executed.
16
+ import { Console } from "node:console";
17
+ const stderrConsole = new Console({ stdout: process.stderr });
18
+ globalThis.console = stderrConsole;
12
19
  // Suppress EPIPE — when the Rust binary exits (e.g., a race was resolved),
13
20
  // orphan workers get broken pipe on stdout. This is expected, not an error.
14
21
  process.stdout.on("error", (error) => {
@@ -37,8 +44,13 @@ async function main() {
37
44
  process.exit(1);
38
45
  }
39
46
  const result = await handler.__definition.handle({ value: input.value });
40
- // Write result to stdout
41
- process.stdout.write(JSON.stringify(result) ?? "null");
47
+ // Write result to stdout, then exit. Explicit exit is required because
48
+ // importing the handler module may leave open handles (timers, servers,
49
+ // etc.) that keep the Node event loop alive indefinitely.
50
+ const json = JSON.stringify(result) ?? "null";
51
+ process.stdout.write(json, () => {
52
+ process.exit(0);
53
+ });
42
54
  }
43
55
  main().catch((error) => {
44
56
  process.stderr.write(`worker: ${error}\n`);
package/package.json CHANGED
@@ -1,17 +1,19 @@
1
1
  {
2
2
  "name": "@barnum/barnum",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "Barnum workflow engine",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
8
8
  "exports": {
9
- ".": {
9
+ "./pipeline": {
10
10
  "types": "./dist/index.d.ts",
11
11
  "default": "./dist/index.js"
12
12
  },
13
- "./dist/*": "./dist/*",
14
- "./src/*": "./src/*",
13
+ "./runtime": {
14
+ "types": "./dist/runtime.d.ts",
15
+ "default": "./dist/runtime.js"
16
+ },
15
17
  "./package.json": "./package.json"
16
18
  },
17
19
  "bin": {
@@ -48,10 +50,10 @@
48
50
  "oxlint": "^1.57.0",
49
51
  "prettier": "^3.8.1",
50
52
  "tsx": "^4.21.0",
51
- "typescript": "^5.7.0",
53
+ "typescript": "^6.0.3",
52
54
  "vitest": "^3.0.0"
53
55
  },
54
- "dependencies": {
56
+ "peerDependencies": {
55
57
  "zod": "^4.3.6"
56
58
  }
57
59
  }
package/src/all.ts CHANGED
@@ -4,83 +4,127 @@ import {
4
4
  type TypedAction,
5
5
  typedAction,
6
6
  } from "./ast.js";
7
- import { constant } from "./builtins.js";
7
+ import { constant } from "./builtins/index.js";
8
8
 
9
9
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
10
10
  export function all(): TypedAction<any, []>;
11
- export function all<In, O1>(a1: Pipeable<In, O1>): TypedAction<In, [O1]>;
12
- export function all<In, O1, O2>(
13
- a1: Pipeable<In, O1>,
14
- a2: Pipeable<In, O2>,
15
- ): TypedAction<In, [O1, O2]>;
16
- export function all<In, O1, O2, O3>(
17
- a1: Pipeable<In, O1>,
18
- a2: Pipeable<In, O2>,
19
- a3: Pipeable<In, O3>,
20
- ): TypedAction<In, [O1, O2, O3]>;
21
- export function all<In, O1, O2, O3, O4>(
22
- a1: Pipeable<In, O1>,
23
- a2: Pipeable<In, O2>,
24
- a3: Pipeable<In, O3>,
25
- a4: Pipeable<In, O4>,
26
- ): TypedAction<In, [O1, O2, O3, O4]>;
27
- export function all<In, O1, O2, O3, O4, O5>(
28
- a1: Pipeable<In, O1>,
29
- a2: Pipeable<In, O2>,
30
- a3: Pipeable<In, O3>,
31
- a4: Pipeable<In, O4>,
32
- a5: Pipeable<In, O5>,
33
- ): TypedAction<In, [O1, O2, O3, O4, O5]>;
34
- export function all<In, O1, O2, O3, O4, O5, O6>(
35
- a1: Pipeable<In, O1>,
36
- a2: Pipeable<In, O2>,
37
- a3: Pipeable<In, O3>,
38
- a4: Pipeable<In, O4>,
39
- a5: Pipeable<In, O5>,
40
- a6: Pipeable<In, O6>,
41
- ): TypedAction<In, [O1, O2, O3, O4, O5, O6]>;
42
- export function all<In, O1, O2, O3, O4, O5, O6, O7>(
43
- a1: Pipeable<In, O1>,
44
- a2: Pipeable<In, O2>,
45
- a3: Pipeable<In, O3>,
46
- a4: Pipeable<In, O4>,
47
- a5: Pipeable<In, O5>,
48
- a6: Pipeable<In, O6>,
49
- a7: Pipeable<In, O7>,
50
- ): TypedAction<In, [O1, O2, O3, O4, O5, O6, O7]>;
51
- export function all<In, O1, O2, O3, O4, O5, O6, O7, O8>(
52
- a1: Pipeable<In, O1>,
53
- a2: Pipeable<In, O2>,
54
- a3: Pipeable<In, O3>,
55
- a4: Pipeable<In, O4>,
56
- a5: Pipeable<In, O5>,
57
- a6: Pipeable<In, O6>,
58
- a7: Pipeable<In, O7>,
59
- a8: Pipeable<In, O8>,
60
- ): TypedAction<In, [O1, O2, O3, O4, O5, O6, O7, O8]>;
61
- export function all<In, O1, O2, O3, O4, O5, O6, O7, O8, O9>(
62
- a1: Pipeable<In, O1>,
63
- a2: Pipeable<In, O2>,
64
- a3: Pipeable<In, O3>,
65
- a4: Pipeable<In, O4>,
66
- a5: Pipeable<In, O5>,
67
- a6: Pipeable<In, O6>,
68
- a7: Pipeable<In, O7>,
69
- a8: Pipeable<In, O8>,
70
- a9: Pipeable<In, O9>,
71
- ): TypedAction<In, [O1, O2, O3, O4, O5, O6, O7, O8, O9]>;
72
- export function all<In, O1, O2, O3, O4, O5, O6, O7, O8, O9, O10>(
73
- a1: Pipeable<In, O1>,
74
- a2: Pipeable<In, O2>,
75
- a3: Pipeable<In, O3>,
76
- a4: Pipeable<In, O4>,
77
- a5: Pipeable<In, O5>,
78
- a6: Pipeable<In, O6>,
79
- a7: Pipeable<In, O7>,
80
- a8: Pipeable<In, O8>,
81
- a9: Pipeable<In, O9>,
82
- a10: Pipeable<In, O10>,
83
- ): TypedAction<In, [O1, O2, O3, O4, O5, O6, O7, O8, O9, O10]>;
11
+ export function all<TInput, TOut1>(
12
+ a1: Pipeable<TInput, TOut1>,
13
+ ): TypedAction<TInput, [TOut1]>;
14
+ export function all<TInput, TOut1, TOut2>(
15
+ a1: Pipeable<TInput, TOut1>,
16
+ a2: Pipeable<TInput, TOut2>,
17
+ ): TypedAction<TInput, [TOut1, TOut2]>;
18
+ export function all<TInput, TOut1, TOut2, TOut3>(
19
+ a1: Pipeable<TInput, TOut1>,
20
+ a2: Pipeable<TInput, TOut2>,
21
+ a3: Pipeable<TInput, TOut3>,
22
+ ): TypedAction<TInput, [TOut1, TOut2, TOut3]>;
23
+ export function all<TInput, TOut1, TOut2, TOut3, TOut4>(
24
+ a1: Pipeable<TInput, TOut1>,
25
+ a2: Pipeable<TInput, TOut2>,
26
+ a3: Pipeable<TInput, TOut3>,
27
+ a4: Pipeable<TInput, TOut4>,
28
+ ): TypedAction<TInput, [TOut1, TOut2, TOut3, TOut4]>;
29
+ export function all<TInput, TOut1, TOut2, TOut3, TOut4, TOut5>(
30
+ a1: Pipeable<TInput, TOut1>,
31
+ a2: Pipeable<TInput, TOut2>,
32
+ a3: Pipeable<TInput, TOut3>,
33
+ a4: Pipeable<TInput, TOut4>,
34
+ a5: Pipeable<TInput, TOut5>,
35
+ ): TypedAction<TInput, [TOut1, TOut2, TOut3, TOut4, TOut5]>;
36
+ export function all<TInput, TOut1, TOut2, TOut3, TOut4, TOut5, TOut6>(
37
+ a1: Pipeable<TInput, TOut1>,
38
+ a2: Pipeable<TInput, TOut2>,
39
+ a3: Pipeable<TInput, TOut3>,
40
+ a4: Pipeable<TInput, TOut4>,
41
+ a5: Pipeable<TInput, TOut5>,
42
+ a6: Pipeable<TInput, TOut6>,
43
+ ): TypedAction<TInput, [TOut1, TOut2, TOut3, TOut4, TOut5, TOut6]>;
44
+ export function all<TInput, TOut1, TOut2, TOut3, TOut4, TOut5, TOut6, TOut7>(
45
+ a1: Pipeable<TInput, TOut1>,
46
+ a2: Pipeable<TInput, TOut2>,
47
+ a3: Pipeable<TInput, TOut3>,
48
+ a4: Pipeable<TInput, TOut4>,
49
+ a5: Pipeable<TInput, TOut5>,
50
+ a6: Pipeable<TInput, TOut6>,
51
+ a7: Pipeable<TInput, TOut7>,
52
+ ): TypedAction<TInput, [TOut1, TOut2, TOut3, TOut4, TOut5, TOut6, TOut7]>;
53
+ export function all<
54
+ TInput,
55
+ TOut1,
56
+ TOut2,
57
+ TOut3,
58
+ TOut4,
59
+ TOut5,
60
+ TOut6,
61
+ TOut7,
62
+ TOut8,
63
+ >(
64
+ a1: Pipeable<TInput, TOut1>,
65
+ a2: Pipeable<TInput, TOut2>,
66
+ a3: Pipeable<TInput, TOut3>,
67
+ a4: Pipeable<TInput, TOut4>,
68
+ a5: Pipeable<TInput, TOut5>,
69
+ a6: Pipeable<TInput, TOut6>,
70
+ a7: Pipeable<TInput, TOut7>,
71
+ a8: Pipeable<TInput, TOut8>,
72
+ ): TypedAction<
73
+ TInput,
74
+ [TOut1, TOut2, TOut3, TOut4, TOut5, TOut6, TOut7, TOut8]
75
+ >;
76
+ export function all<
77
+ TInput,
78
+ TOut1,
79
+ TOut2,
80
+ TOut3,
81
+ TOut4,
82
+ TOut5,
83
+ TOut6,
84
+ TOut7,
85
+ TOut8,
86
+ TOut9,
87
+ >(
88
+ a1: Pipeable<TInput, TOut1>,
89
+ a2: Pipeable<TInput, TOut2>,
90
+ a3: Pipeable<TInput, TOut3>,
91
+ a4: Pipeable<TInput, TOut4>,
92
+ a5: Pipeable<TInput, TOut5>,
93
+ a6: Pipeable<TInput, TOut6>,
94
+ a7: Pipeable<TInput, TOut7>,
95
+ a8: Pipeable<TInput, TOut8>,
96
+ a9: Pipeable<TInput, TOut9>,
97
+ ): TypedAction<
98
+ TInput,
99
+ [TOut1, TOut2, TOut3, TOut4, TOut5, TOut6, TOut7, TOut8, TOut9]
100
+ >;
101
+ export function all<
102
+ TInput,
103
+ TOut1,
104
+ TOut2,
105
+ TOut3,
106
+ TOut4,
107
+ TOut5,
108
+ TOut6,
109
+ TOut7,
110
+ TOut8,
111
+ TOut9,
112
+ TOut10,
113
+ >(
114
+ a1: Pipeable<TInput, TOut1>,
115
+ a2: Pipeable<TInput, TOut2>,
116
+ a3: Pipeable<TInput, TOut3>,
117
+ a4: Pipeable<TInput, TOut4>,
118
+ a5: Pipeable<TInput, TOut5>,
119
+ a6: Pipeable<TInput, TOut6>,
120
+ a7: Pipeable<TInput, TOut7>,
121
+ a8: Pipeable<TInput, TOut8>,
122
+ a9: Pipeable<TInput, TOut9>,
123
+ a10: Pipeable<TInput, TOut10>,
124
+ ): TypedAction<
125
+ TInput,
126
+ [TOut1, TOut2, TOut3, TOut4, TOut5, TOut6, TOut7, TOut8, TOut9, TOut10]
127
+ >;
84
128
  export function all(...actions: Action[]): Action {
85
129
  if (actions.length === 0) {
86
130
  return constant([]);