@barnum/barnum 0.0.0-main-ef57b8fd → 0.0.0-main-50effdfd

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/dist/ast.d.ts CHANGED
@@ -78,6 +78,10 @@ export type BuiltinKind = {
78
78
  value: string[];
79
79
  } | {
80
80
  kind: "CollectSome";
81
+ } | {
82
+ kind: "SplitFirst";
83
+ } | {
84
+ kind: "SplitLast";
81
85
  } | {
82
86
  kind: "WrapInField";
83
87
  value: string;
@@ -138,6 +142,10 @@ export type TypedAction<In = unknown, Out = unknown, Refs extends string = never
138
142
  merge(): TypedAction<In, MergeTuple<Out>, Refs>;
139
143
  /** Select fields from the output. `a.pick("x", "y")` ≡ `pipe(a, pick("x", "y"))`. */
140
144
  pick<TKeys extends (keyof Out & string)[]>(...keys: TKeys): TypedAction<In, Pick<Out, TKeys[number]>, Refs>;
145
+ /** Head/tail decomposition. Only callable when Out is TElement[]. */
146
+ splitFirst<TIn, TElement, TRefs extends string>(this: TypedAction<TIn, TElement[], TRefs>): TypedAction<TIn, Option<[TElement, TElement[]]>, TRefs>;
147
+ /** Init/last decomposition. Only callable when Out is TElement[]. */
148
+ splitLast<TIn, TElement, TRefs extends string>(this: TypedAction<TIn, TElement[], TRefs>): TypedAction<TIn, Option<[TElement[], TElement]>, TRefs>;
141
149
  /**
142
150
  * Transform the Some value inside an Option output. Only callable when
143
151
  * Out is Option<T>. Uses `this` parameter constraint to gate availability.
package/dist/ast.js CHANGED
@@ -95,6 +95,26 @@ function pickMethod(...keys) {
95
95
  },
96
96
  });
97
97
  }
98
+ function splitFirstMethod() {
99
+ return typedAction({
100
+ kind: "Chain",
101
+ first: this,
102
+ rest: {
103
+ kind: "Invoke",
104
+ handler: { kind: "Builtin", builtin: { kind: "SplitFirst" } },
105
+ },
106
+ });
107
+ }
108
+ function splitLastMethod() {
109
+ return typedAction({
110
+ kind: "Chain",
111
+ first: this,
112
+ rest: {
113
+ kind: "Invoke",
114
+ handler: { kind: "Builtin", builtin: { kind: "SplitLast" } },
115
+ },
116
+ });
117
+ }
98
118
  function mapOptionMethod(action) {
99
119
  // Desugars to: self.then(branch({ Some: pipe(action, tag("Some")), None: tag("None") }))
100
120
  // But branch auto-unwraps value, so:
@@ -186,6 +206,8 @@ export function typedAction(action) {
186
206
  wrapInField: { value: wrapInFieldMethod, configurable: true },
187
207
  merge: { value: mergeMethod, configurable: true },
188
208
  pick: { value: pickMethod, configurable: true },
209
+ splitFirst: { value: splitFirstMethod, configurable: true },
210
+ splitLast: { value: splitLastMethod, configurable: true },
189
211
  mapOption: { value: mapOptionMethod, configurable: true },
190
212
  mapErr: { value: mapErrMethod, configurable: true },
191
213
  unwrapOr: { value: unwrapOrMethod, configurable: true },
@@ -57,6 +57,29 @@ export declare function withResource<TIn extends Record<string, unknown>, TResou
57
57
  export declare function tap<TInput extends Record<string, unknown>>(action: Pipeable<TInput, any>): TypedAction<TInput, TInput>;
58
58
  export declare function wrapInField<TField extends string, TValue>(field: TField): TypedAction<TValue, Record<TField, TValue>>;
59
59
  export declare function range(start: number, end: number): TypedAction<any, number[]>;
60
+ /**
61
+ * Deconstruct an array into its first element and the remaining elements.
62
+ * `TElement[] → Option<[TElement, TElement[]]>`
63
+ *
64
+ * Returns `Some([first, rest])` for non-empty arrays, `None` for empty arrays.
65
+ * This is the array equivalent of cons/uncons — enables recursive iteration
66
+ * patterns via `loop` + `splitFirst` + `branch`.
67
+ *
68
+ * This is a builtin (SplitFirst) because it requires array-length branching
69
+ * that can't be composed from existing AST nodes.
70
+ */
71
+ export declare function splitFirst<TElement>(): TypedAction<TElement[], OptionT<[TElement, TElement[]]>>;
72
+ /**
73
+ * Deconstruct an array into the leading elements and the last element.
74
+ * `TElement[] → Option<[TElement[], TElement]>`
75
+ *
76
+ * Returns `Some([init, last])` for non-empty arrays, `None` for empty arrays.
77
+ * Mirror of `splitFirst` — enables processing from the tail end.
78
+ *
79
+ * This is a builtin (SplitLast) because it requires array-length branching
80
+ * that can't be composed from existing AST nodes.
81
+ */
82
+ export declare function splitLast<TElement>(): TypedAction<TElement[], OptionT<[TElement[], TElement]>>;
60
83
  /**
61
84
  * Option namespace. All combinators produce TypedAction AST nodes that
62
85
  * desugar to branch + existing builtins, except collect which uses the
package/dist/builtins.js CHANGED
@@ -227,6 +227,45 @@ export function range(start, end) {
227
227
  });
228
228
  }
229
229
  // ---------------------------------------------------------------------------
230
+ // SplitFirst — head/tail decomposition of an array
231
+ // ---------------------------------------------------------------------------
232
+ /**
233
+ * Deconstruct an array into its first element and the remaining elements.
234
+ * `TElement[] → Option<[TElement, TElement[]]>`
235
+ *
236
+ * Returns `Some([first, rest])` for non-empty arrays, `None` for empty arrays.
237
+ * This is the array equivalent of cons/uncons — enables recursive iteration
238
+ * patterns via `loop` + `splitFirst` + `branch`.
239
+ *
240
+ * This is a builtin (SplitFirst) because it requires array-length branching
241
+ * that can't be composed from existing AST nodes.
242
+ */
243
+ export function splitFirst() {
244
+ return typedAction({
245
+ kind: "Invoke",
246
+ handler: { kind: "Builtin", builtin: { kind: "SplitFirst" } },
247
+ });
248
+ }
249
+ // ---------------------------------------------------------------------------
250
+ // SplitLast — init/last decomposition of an array
251
+ // ---------------------------------------------------------------------------
252
+ /**
253
+ * Deconstruct an array into the leading elements and the last element.
254
+ * `TElement[] → Option<[TElement[], TElement]>`
255
+ *
256
+ * Returns `Some([init, last])` for non-empty arrays, `None` for empty arrays.
257
+ * Mirror of `splitFirst` — enables processing from the tail end.
258
+ *
259
+ * This is a builtin (SplitLast) because it requires array-length branching
260
+ * that can't be composed from existing AST nodes.
261
+ */
262
+ export function splitLast() {
263
+ return typedAction({
264
+ kind: "Invoke",
265
+ handler: { kind: "Builtin", builtin: { kind: "SplitLast" } },
266
+ });
267
+ }
268
+ // ---------------------------------------------------------------------------
230
269
  // Option namespace — combinators for Option<T> tagged unions
231
270
  // ---------------------------------------------------------------------------
232
271
  // Shared AST fragments for Option desugaring
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { TaggedUnion, OptionDef, ResultDef } from "./ast.js";
2
2
  export * from "./ast.js";
3
- export { constant, identity, drop, tag, merge, flatten, extractField, extractIndex, pick, dropResult, withResource, tap, range, wrapInField, Option, Result, } from "./builtins.js";
3
+ export { constant, identity, drop, tag, merge, flatten, extractField, extractIndex, pick, dropResult, withResource, tap, range, splitFirst, splitLast, wrapInField, Option, Result, } from "./builtins.js";
4
4
  export * from "./handler.js";
5
5
  export { runPipeline, type RunPipelineOptions, type LogLevel } from "./run.js";
6
6
  export { zodToCheckedJsonSchema } from "./schema.js";
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  export * from "./ast.js";
2
- export { constant, identity, drop, tag, merge, flatten, extractField, extractIndex, pick, dropResult, withResource, tap, range, wrapInField, Option, Result, } from "./builtins.js";
2
+ export { constant, identity, drop, tag, merge, flatten, extractField, extractIndex, pick, dropResult, withResource, tap, range, splitFirst, splitLast, wrapInField, Option, Result, } from "./builtins.js";
3
3
  export * from "./handler.js";
4
4
  export { runPipeline } from "./run.js";
5
5
  export { zodToCheckedJsonSchema } from "./schema.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barnum/barnum",
3
- "version": "0.0.0-main-ef57b8fd",
3
+ "version": "0.0.0-main-50effdfd",
4
4
  "description": "Barnum workflow engine",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
package/src/ast.ts CHANGED
@@ -95,6 +95,8 @@ export type BuiltinKind =
95
95
  | { kind: "ExtractIndex"; value: number }
96
96
  | { kind: "Pick"; value: string[] }
97
97
  | { kind: "CollectSome" }
98
+ | { kind: "SplitFirst" }
99
+ | { kind: "SplitLast" }
98
100
  | { kind: "WrapInField"; value: string }
99
101
  | { kind: "Sleep"; value: number };
100
102
 
@@ -195,6 +197,14 @@ export type TypedAction<
195
197
  pick<TKeys extends (keyof Out & string)[]>(
196
198
  ...keys: TKeys
197
199
  ): TypedAction<In, Pick<Out, TKeys[number]>, Refs>;
200
+ /** Head/tail decomposition. Only callable when Out is TElement[]. */
201
+ splitFirst<TIn, TElement, TRefs extends string>(
202
+ this: TypedAction<TIn, TElement[], TRefs>,
203
+ ): TypedAction<TIn, Option<[TElement, TElement[]]>, TRefs>;
204
+ /** Init/last decomposition. Only callable when Out is TElement[]. */
205
+ splitLast<TIn, TElement, TRefs extends string>(
206
+ this: TypedAction<TIn, TElement[], TRefs>,
207
+ ): TypedAction<TIn, Option<[TElement[], TElement]>, TRefs>;
198
208
  /**
199
209
  * Transform the Some value inside an Option output. Only callable when
200
210
  * Out is Option<T>. Uses `this` parameter constraint to gate availability.
@@ -468,6 +478,28 @@ function pickMethod(this: TypedAction, ...keys: string[]): TypedAction {
468
478
  });
469
479
  }
470
480
 
481
+ function splitFirstMethod(this: TypedAction): TypedAction {
482
+ return typedAction({
483
+ kind: "Chain",
484
+ first: this,
485
+ rest: {
486
+ kind: "Invoke",
487
+ handler: { kind: "Builtin", builtin: { kind: "SplitFirst" } },
488
+ },
489
+ });
490
+ }
491
+
492
+ function splitLastMethod(this: TypedAction): TypedAction {
493
+ return typedAction({
494
+ kind: "Chain",
495
+ first: this,
496
+ rest: {
497
+ kind: "Invoke",
498
+ handler: { kind: "Builtin", builtin: { kind: "SplitLast" } },
499
+ },
500
+ });
501
+ }
502
+
471
503
  function mapOptionMethod(this: TypedAction, action: Action): TypedAction {
472
504
  // Desugars to: self.then(branch({ Some: pipe(action, tag("Some")), None: tag("None") }))
473
505
  // But branch auto-unwraps value, so:
@@ -566,6 +598,8 @@ export function typedAction<
566
598
  wrapInField: { value: wrapInFieldMethod, configurable: true },
567
599
  merge: { value: mergeMethod, configurable: true },
568
600
  pick: { value: pickMethod, configurable: true },
601
+ splitFirst: { value: splitFirstMethod, configurable: true },
602
+ splitLast: { value: splitLastMethod, configurable: true },
569
603
  mapOption: { value: mapOptionMethod, configurable: true },
570
604
  mapErr: { value: mapErrMethod, configurable: true },
571
605
  unwrapOr: { value: unwrapOrMethod, configurable: true },
package/src/builtins.ts CHANGED
@@ -317,6 +317,55 @@ export function range(start: number, end: number): TypedAction<any, number[]> {
317
317
  });
318
318
  }
319
319
 
320
+ // ---------------------------------------------------------------------------
321
+ // SplitFirst — head/tail decomposition of an array
322
+ // ---------------------------------------------------------------------------
323
+
324
+ /**
325
+ * Deconstruct an array into its first element and the remaining elements.
326
+ * `TElement[] → Option<[TElement, TElement[]]>`
327
+ *
328
+ * Returns `Some([first, rest])` for non-empty arrays, `None` for empty arrays.
329
+ * This is the array equivalent of cons/uncons — enables recursive iteration
330
+ * patterns via `loop` + `splitFirst` + `branch`.
331
+ *
332
+ * This is a builtin (SplitFirst) because it requires array-length branching
333
+ * that can't be composed from existing AST nodes.
334
+ */
335
+ export function splitFirst<TElement>(): TypedAction<
336
+ TElement[],
337
+ OptionT<[TElement, TElement[]]>
338
+ > {
339
+ return typedAction({
340
+ kind: "Invoke",
341
+ handler: { kind: "Builtin", builtin: { kind: "SplitFirst" } },
342
+ });
343
+ }
344
+
345
+ // ---------------------------------------------------------------------------
346
+ // SplitLast — init/last decomposition of an array
347
+ // ---------------------------------------------------------------------------
348
+
349
+ /**
350
+ * Deconstruct an array into the leading elements and the last element.
351
+ * `TElement[] → Option<[TElement[], TElement]>`
352
+ *
353
+ * Returns `Some([init, last])` for non-empty arrays, `None` for empty arrays.
354
+ * Mirror of `splitFirst` — enables processing from the tail end.
355
+ *
356
+ * This is a builtin (SplitLast) because it requires array-length branching
357
+ * that can't be composed from existing AST nodes.
358
+ */
359
+ export function splitLast<TElement>(): TypedAction<
360
+ TElement[],
361
+ OptionT<[TElement[], TElement]>
362
+ > {
363
+ return typedAction({
364
+ kind: "Invoke",
365
+ handler: { kind: "Builtin", builtin: { kind: "SplitLast" } },
366
+ });
367
+ }
368
+
320
369
  // ---------------------------------------------------------------------------
321
370
  // Option namespace — combinators for Option<T> tagged unions
322
371
  // ---------------------------------------------------------------------------
package/src/index.ts CHANGED
@@ -15,6 +15,8 @@ export {
15
15
  withResource,
16
16
  tap,
17
17
  range,
18
+ splitFirst,
19
+ splitLast,
18
20
  wrapInField,
19
21
  Option,
20
22
  Result,