@barnum/barnum 0.2.3 → 0.3.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 (56) 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/cli.cjs +33 -0
  7. package/dist/all.d.ts +12 -0
  8. package/dist/all.js +8 -0
  9. package/dist/ast.d.ts +375 -0
  10. package/dist/ast.js +381 -0
  11. package/dist/bind.d.ts +62 -0
  12. package/dist/bind.js +106 -0
  13. package/dist/builtins.d.ts +257 -0
  14. package/dist/builtins.js +600 -0
  15. package/dist/chain.d.ts +2 -0
  16. package/dist/chain.js +8 -0
  17. package/dist/effect-id.d.ts +14 -0
  18. package/dist/effect-id.js +16 -0
  19. package/dist/handler.d.ts +50 -0
  20. package/dist/handler.js +146 -0
  21. package/dist/index.d.ts +8 -0
  22. package/dist/index.js +5 -0
  23. package/dist/pipe.d.ts +11 -0
  24. package/dist/pipe.js +11 -0
  25. package/dist/race.d.ts +53 -0
  26. package/dist/race.js +141 -0
  27. package/dist/recursive.d.ts +34 -0
  28. package/dist/recursive.js +53 -0
  29. package/dist/run.d.ts +7 -0
  30. package/dist/run.js +143 -0
  31. package/dist/schema.d.ts +8 -0
  32. package/dist/schema.js +95 -0
  33. package/dist/try-catch.d.ts +23 -0
  34. package/dist/try-catch.js +36 -0
  35. package/dist/worker.d.ts +11 -0
  36. package/dist/worker.js +46 -0
  37. package/package.json +40 -16
  38. package/src/all.ts +89 -0
  39. package/src/ast.ts +878 -0
  40. package/src/bind.ts +192 -0
  41. package/src/builtins.ts +804 -0
  42. package/src/chain.ts +17 -0
  43. package/src/effect-id.ts +30 -0
  44. package/src/handler.ts +279 -0
  45. package/src/index.ts +30 -0
  46. package/src/pipe.ts +93 -0
  47. package/src/race.ts +183 -0
  48. package/src/recursive.ts +112 -0
  49. package/src/run.ts +181 -0
  50. package/src/schema.ts +118 -0
  51. package/src/try-catch.ts +53 -0
  52. package/src/worker.ts +56 -0
  53. package/README.md +0 -19
  54. package/barnum-config-schema.json +0 -408
  55. package/cli.js +0 -20
  56. package/index.js +0 -23
@@ -0,0 +1,257 @@
1
+ import { type Action, type Option as OptionT, type Pipeable, type Result as ResultT, type TaggedUnion, type TypedAction } from "./ast.js";
2
+ /**
3
+ * Typed combinators for structural data transformations.
4
+ *
5
+ * All builtins emit `{ kind: "Builtin", builtin: { kind: ... } }` handler
6
+ * kinds. The Rust scheduler executes them inline (no subprocess).
7
+ */
8
+ export declare function constant<TValue>(value: TValue): TypedAction<any, TValue>;
9
+ export declare const identity: TypedAction<any, any>;
10
+ export declare const drop: TypedAction<any, never>;
11
+ /**
12
+ * Wrap input as a tagged union member. Requires the full variant map TDef
13
+ * so the output type carries __def for branch decomposition.
14
+ *
15
+ * Usage: tag<{ Ok: string; Err: number }, "Ok">("Ok")
16
+ * input: string → output: TaggedUnion<{ Ok: string; Err: number }>
17
+ */
18
+ export declare function tag<TDef extends Record<string, unknown>, TKind extends keyof TDef & string>(kind: TKind): TypedAction<TDef[TKind], TaggedUnion<TDef>>;
19
+ type UnionToIntersection<U> = (U extends any ? (x: U) => void : never) extends (x: infer I) => void ? I : never;
20
+ export declare function merge<TObjects extends Record<string, unknown>[]>(): TypedAction<TObjects, UnionToIntersection<TObjects[number]>>;
21
+ export declare function flatten<TElement>(): TypedAction<TElement[][], TElement[]>;
22
+ export declare function extractField<TObj extends Record<string, unknown>, TField extends keyof TObj & string>(field: TField): TypedAction<TObj, TObj[TField]>;
23
+ export declare function extractIndex<TTuple extends unknown[], TIndex extends number>(index: TIndex): TypedAction<TTuple, TTuple[TIndex]>;
24
+ export declare function pick<TObj extends Record<string, unknown>, TKeys extends (keyof TObj & string)[]>(...keys: TKeys): TypedAction<TObj, Pick<TObj, TKeys[number]>>;
25
+ export declare function dropResult<TInput, TOutput>(action: Pipeable<TInput, TOutput>): TypedAction<TInput, never>;
26
+ /**
27
+ * RAII-style resource management combinator.
28
+ *
29
+ * Runs `create` to acquire a resource, then merges the resource with the
30
+ * original input into a flat object (`TResource & TIn`) for the action.
31
+ * After the action completes, `dispose` receives the resource for cleanup.
32
+ * The overall combinator returns the action's output.
33
+ *
34
+ * ```
35
+ * TIn → create → TResource
36
+ * → merge(TResource, TIn) → TResource & TIn
37
+ * → action(TResource & TIn) → TOut
38
+ * → dispose(TResource) → (discarded)
39
+ * → TOut
40
+ * ```
41
+ */
42
+ export declare function withResource<TIn extends Record<string, unknown>, TResource extends Record<string, unknown>, TOut, TDisposeOut = unknown>({ create, action, dispose, }: {
43
+ create: Pipeable<TIn, TResource>;
44
+ action: Pipeable<TResource & TIn, TOut>;
45
+ dispose: Pipeable<TResource, TDisposeOut>;
46
+ }): TypedAction<TIn, TOut>;
47
+ /**
48
+ * Run `action` on the input, then merge the action's output fields back
49
+ * into the original input object. The action must accept exactly `TInput`.
50
+ * Use `pick` inside the action's pipe if the inner handler needs a subset.
51
+ *
52
+ * Example:
53
+ * augment(pipe(pick("file"), migrate))
54
+ * // { file, outputPath } → { file, outputPath, content, migrated }
55
+ */
56
+ export declare function augment<TInput extends Record<string, unknown>, TOutput extends Record<string, unknown>>(action: Pipeable<TInput, TOutput>): TypedAction<TInput, TInput & TOutput>;
57
+ /**
58
+ * Run `action` on the input for its side effects, then discard the action's
59
+ * output and return the original input unchanged. The action must accept
60
+ * exactly `TInput`. Use `pick` inside the action's pipe if the inner
61
+ * handler needs a subset.
62
+ *
63
+ * Constraint: input must be an object (uses augment internally, which
64
+ * relies on all + merge).
65
+ *
66
+ * Example:
67
+ * pipe(tap(pipe(pick("worktreePath", "description"), implement)), createPR)
68
+ */
69
+ export declare function tap<TInput extends Record<string, unknown>>(action: Pipeable<TInput, any>): TypedAction<TInput, TInput>;
70
+ export declare function range(start: number, end: number): TypedAction<any, number[]>;
71
+ /**
72
+ * Option namespace. All combinators produce TypedAction AST nodes that
73
+ * desugar to branch + existing builtins, except collect which uses the
74
+ * CollectSome builtin.
75
+ */
76
+ export declare const Option: {
77
+ /**
78
+ * Wrap a value as Some. `T → Option<T>`
79
+ *
80
+ * Equivalent to `tag<OptionDef<T>, "Some">("Some")`.
81
+ */
82
+ readonly some: <T>() => TypedAction<T, OptionT<T>>;
83
+ /**
84
+ * Produce a None. `never → Option<T>`
85
+ *
86
+ * Chain after `.drop()` to discard the current value first.
87
+ * Equivalent to `tag<OptionDef<T>, "None">("None")`.
88
+ */
89
+ readonly none: <T>() => TypedAction<never, OptionT<T>>;
90
+ /**
91
+ * Transform the Some value. `Option<T> → Option<U>`
92
+ *
93
+ * Desugars to: `branch({ Some: pipe(action, tag("Some")), None: tag("None") })`
94
+ */
95
+ readonly map: <T, U>(action: Pipeable<T, U>) => TypedAction<OptionT<T>, OptionT<U>>;
96
+ /**
97
+ * Monadic bind (flatMap). If Some, pass the value to action which
98
+ * returns Option<U>. If None, stay None. `Option<T> → Option<U>`
99
+ *
100
+ * This is the most fundamental combinator — map, flatten, and filter
101
+ * are all derivable from andThen + constructors.
102
+ *
103
+ * Desugars to: `branch({ Some: action, None: tag("None") })`
104
+ */
105
+ readonly andThen: <T, U>(action: Pipeable<T, OptionT<U>>) => TypedAction<OptionT<T>, OptionT<U>>;
106
+ /**
107
+ * Extract the Some value or produce a default from an action.
108
+ * `Option<T> → T`
109
+ *
110
+ * The defaultAction takes no meaningful input (never) and must produce T.
111
+ * Use `Option.unwrapOr(constant("fallback"))`.
112
+ *
113
+ * The None branch drops its void payload before calling defaultAction,
114
+ * matching Rust's `unwrap_or_else(|| default)` where the closure takes
115
+ * no arguments.
116
+ *
117
+ * Desugars to: `branch({ Some: identity(), None: pipe(drop(), defaultAction) })`
118
+ */
119
+ readonly unwrapOr: <T>(defaultAction: Pipeable<never, T>) => TypedAction<OptionT<T>, T>;
120
+ /**
121
+ * Unwrap a nested Option. `Option<Option<T>> → Option<T>`
122
+ *
123
+ * Desugars to: `branch({ Some: identity(), None: tag("None") })`
124
+ */
125
+ readonly flatten: <T>() => TypedAction<OptionT<OptionT<T>>, OptionT<T>>;
126
+ /**
127
+ * Conditional keep. If Some, pass value to predicate which returns
128
+ * Option<T> (some() to keep, none() to discard). If None, stay None.
129
+ * `Option<T> → Option<T>`
130
+ *
131
+ * This has the same signature and desugaring as andThen with T=U.
132
+ * Named "filter" for readability when the intent is filtering.
133
+ *
134
+ * Desugars to: `branch({ Some: predicate, None: tag("None") })`
135
+ */
136
+ readonly filter: <T>(predicate: Pipeable<T, OptionT<T>>) => TypedAction<OptionT<T>, OptionT<T>>;
137
+ /**
138
+ * Collect Some values from an array, discarding Nones.
139
+ * `Option<T>[] → T[]`
140
+ *
141
+ * This is a builtin handler (CollectSome) — it can't be expressed
142
+ * as a composition of existing AST nodes because it requires
143
+ * array-level filtering logic.
144
+ */
145
+ readonly collect: <T = any>() => TypedAction<OptionT<T>[], T[]>;
146
+ /**
147
+ * Test if the value is Some. `Option<T> → boolean`
148
+ *
149
+ * Rarely useful — branch on Some/None directly instead.
150
+ *
151
+ * Desugars to: `branch({ Some: pipe(drop(), constant(true)), None: pipe(drop(), constant(false)) })`
152
+ */
153
+ readonly isSome: <T>() => TypedAction<OptionT<T>, boolean>;
154
+ /**
155
+ * Test if the value is None. `Option<T> → boolean`
156
+ *
157
+ * Rarely useful — branch on Some/None directly instead.
158
+ *
159
+ * Desugars to: `branch({ Some: pipe(drop(), constant(false)), None: pipe(drop(), constant(true)) })`
160
+ */
161
+ readonly isNone: <T>() => TypedAction<OptionT<T>, boolean>;
162
+ };
163
+ /**
164
+ * Result namespace. All combinators produce TypedAction AST nodes that
165
+ * desugar to branch + existing builtins.
166
+ */
167
+ export declare const Result: {
168
+ /**
169
+ * Wrap a value as Ok. `TValue → Result<TValue, TError>`
170
+ */
171
+ readonly ok: <TValue, TError>() => TypedAction<TValue, ResultT<TValue, TError>>;
172
+ /**
173
+ * Wrap a value as Err. `TError → Result<TValue, TError>`
174
+ */
175
+ readonly err: <TValue, TError>() => TypedAction<TError, ResultT<TValue, TError>>;
176
+ /**
177
+ * Transform the Ok value. `Result<TValue, TError> → Result<TOut, TError>`
178
+ *
179
+ * Desugars to: `branch({ Ok: pipe(action, tag("Ok")), Err: tag("Err") })`
180
+ */
181
+ readonly map: <TValue, TOut, TError>(action: Pipeable<TValue, TOut>) => TypedAction<ResultT<TValue, TError>, ResultT<TOut, TError>>;
182
+ /**
183
+ * Transform the Err value. `Result<TValue, TError> → Result<TValue, TErrorOut>`
184
+ *
185
+ * Desugars to: `branch({ Ok: tag("Ok"), Err: pipe(action, tag("Err")) })`
186
+ */
187
+ readonly mapErr: <TValue, TError, TErrorOut>(action: Pipeable<TError, TErrorOut>) => TypedAction<ResultT<TValue, TError>, ResultT<TValue, TErrorOut>>;
188
+ /**
189
+ * Monadic bind (flatMap) for Ok. If Ok, pass value to action which
190
+ * returns Result<TOut, TError>. If Err, propagate.
191
+ *
192
+ * Desugars to: `branch({ Ok: action, Err: tag("Err") })`
193
+ */
194
+ readonly andThen: <TValue, TOut, TError>(action: Pipeable<TValue, ResultT<TOut, TError>>) => TypedAction<ResultT<TValue, TError>, ResultT<TOut, TError>>;
195
+ /**
196
+ * Fallback on Err. If Ok, keep it. If Err, pass error to fallback
197
+ * which returns a new Result.
198
+ *
199
+ * Desugars to: `branch({ Ok: tag("Ok"), Err: fallback })`
200
+ */
201
+ readonly or: <TValue, TError, TErrorOut>(fallback: Pipeable<TError, ResultT<TValue, TErrorOut>>) => TypedAction<ResultT<TValue, TError>, ResultT<TValue, TErrorOut>>;
202
+ /**
203
+ * Replace Ok value with another Result. If Ok, discard value and
204
+ * return other. If Err, propagate.
205
+ *
206
+ * Desugars to: `branch({ Ok: pipe(drop(), other), Err: tag("Err") })`
207
+ */
208
+ readonly and: <TValue, TOut, TError>(other: Pipeable<never, ResultT<TOut, TError>>) => TypedAction<ResultT<TValue, TError>, ResultT<TOut, TError>>;
209
+ /**
210
+ * Extract Ok or compute default from Err. `Result<TValue, TError> → TValue`
211
+ *
212
+ * Takes an action that receives the Err payload and produces a fallback.
213
+ * Uses covariant output checking so throw tokens (Out=never) are assignable
214
+ * when TValue is provided explicitly: `Result.unwrapOr<string, string>(throwError)`.
215
+ *
216
+ * For inference-free usage with throw tokens, prefer the postfix method:
217
+ * `handler.unwrapOr(throwError)` — the `this` constraint provides TValue.
218
+ *
219
+ * Desugars to: `branch({ Ok: identity(), Err: defaultAction })`
220
+ */
221
+ readonly unwrapOr: <TValue, TError>(defaultAction: Action & {
222
+ __in?: (input: TError) => void;
223
+ __out?: () => TValue;
224
+ }) => TypedAction<ResultT<TValue, TError>, TValue>;
225
+ /**
226
+ * Unwrap nested Result. `Result<Result<TValue, TError>, TError> → Result<TValue, TError>`
227
+ *
228
+ * Desugars to: `branch({ Ok: identity(), Err: tag("Err") })`
229
+ */
230
+ readonly flatten: <TValue, TError>() => TypedAction<ResultT<ResultT<TValue, TError>, TError>, ResultT<TValue, TError>>;
231
+ /**
232
+ * Convert Ok to Some, Err to None. `Result<TValue, TError> → Option<TValue>`
233
+ *
234
+ * Desugars to: `branch({ Ok: tag("Some"), Err: pipe(drop(), tag("None")) })`
235
+ */
236
+ readonly toOption: <TValue, TError>() => TypedAction<ResultT<TValue, TError>, OptionT<TValue>>;
237
+ /**
238
+ * Convert Err to Some, Ok to None. `Result<TValue, TError> → Option<TError>`
239
+ *
240
+ * Desugars to: `branch({ Ok: pipe(drop(), tag("None")), Err: tag("Some") })`
241
+ */
242
+ readonly toOptionErr: <TValue, TError>() => TypedAction<ResultT<TValue, TError>, OptionT<TError>>;
243
+ /**
244
+ * Swap Result/Option nesting.
245
+ * `Result<Option<TValue>, TError> → Option<Result<TValue, TError>>`
246
+ */
247
+ readonly transpose: <TValue, TError>() => TypedAction<ResultT<OptionT<TValue>, TError>, OptionT<ResultT<TValue, TError>>>;
248
+ /**
249
+ * Test if the value is Ok. `Result<TValue, TError> → boolean`
250
+ */
251
+ readonly isOk: <TValue, TError>() => TypedAction<ResultT<TValue, TError>, boolean>;
252
+ /**
253
+ * Test if the value is Err. `Result<TValue, TError> → boolean`
254
+ */
255
+ readonly isErr: <TValue, TError>() => TypedAction<ResultT<TValue, TError>, boolean>;
256
+ };
257
+ export {};