@barnum/barnum 0.0.0-main-5534c655 → 0.0.0-main-ef57b8fd
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/dist/ast.d.ts +2 -9
- package/dist/ast.js +7 -16
- package/dist/builtins.d.ts +3 -16
- package/dist/builtins.js +5 -32
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/src/ast.ts +11 -25
- package/src/builtins.ts +7 -47
- package/src/index.ts +0 -1
package/dist/ast.d.ts
CHANGED
|
@@ -132,15 +132,8 @@ export type TypedAction<In = unknown, Out = unknown, Refs extends string = never
|
|
|
132
132
|
tag<TDef extends Record<string, unknown>, TKind extends keyof TDef & string>(kind: TKind): TypedAction<In, TaggedUnion<TDef>, Refs>;
|
|
133
133
|
/** Extract a field from the output object. `a.get("name")` ≡ `pipe(a, extractField("name"))`. */
|
|
134
134
|
get<TField extends keyof Out & string>(field: TField): TypedAction<In, Out[TField], Refs>;
|
|
135
|
-
/**
|
|
136
|
-
|
|
137
|
-
* `pipe(extractField("x"), transform).augment()` takes `In`, runs the
|
|
138
|
-
* sub-pipeline to get `Out`, and returns `In & Out`.
|
|
139
|
-
*
|
|
140
|
-
* Unlike the standalone `augment()` function, the postfix form has access
|
|
141
|
-
* to `In` so the intersection types correctly.
|
|
142
|
-
*/
|
|
143
|
-
augment(): TypedAction<In, In & Out, Refs>;
|
|
135
|
+
/** Wrap output in an object under a field name. `a.wrapInField("foo")` ≡ `pipe(a, wrapInField("foo"))`. */
|
|
136
|
+
wrapInField<TField extends string>(field: TField): TypedAction<In, Record<TField, Out>, Refs>;
|
|
144
137
|
/** Merge a tuple of objects into a single object. `a.merge()` ≡ `pipe(a, merge())`. */
|
|
145
138
|
merge(): TypedAction<In, MergeTuple<Out>, Refs>;
|
|
146
139
|
/** Select fields from the output. `a.pick("x", "y")` ≡ `pipe(a, pick("x", "y"))`. */
|
package/dist/ast.js
CHANGED
|
@@ -62,25 +62,16 @@ function getMethod(field) {
|
|
|
62
62
|
},
|
|
63
63
|
});
|
|
64
64
|
}
|
|
65
|
-
function
|
|
66
|
-
// Construct: All(this, identity) → Merge
|
|
67
|
-
// "this" is the sub-pipeline. augment() wraps it so the original input
|
|
68
|
-
// flows through identity alongside the sub-pipeline, then merges the results.
|
|
65
|
+
function wrapInFieldMethod(field) {
|
|
69
66
|
return typedAction({
|
|
70
67
|
kind: "Chain",
|
|
71
|
-
first:
|
|
72
|
-
kind: "All",
|
|
73
|
-
actions: [
|
|
74
|
-
this,
|
|
75
|
-
{
|
|
76
|
-
kind: "Invoke",
|
|
77
|
-
handler: { kind: "Builtin", builtin: { kind: "Identity" } },
|
|
78
|
-
},
|
|
79
|
-
],
|
|
80
|
-
},
|
|
68
|
+
first: this,
|
|
81
69
|
rest: {
|
|
82
70
|
kind: "Invoke",
|
|
83
|
-
handler: {
|
|
71
|
+
handler: {
|
|
72
|
+
kind: "Builtin",
|
|
73
|
+
builtin: { kind: "WrapInField", value: field },
|
|
74
|
+
},
|
|
84
75
|
},
|
|
85
76
|
});
|
|
86
77
|
}
|
|
@@ -192,7 +183,7 @@ export function typedAction(action) {
|
|
|
192
183
|
drop: { value: dropMethod, configurable: true },
|
|
193
184
|
tag: { value: tagMethod, configurable: true },
|
|
194
185
|
get: { value: getMethod, configurable: true },
|
|
195
|
-
|
|
186
|
+
wrapInField: { value: wrapInFieldMethod, configurable: true },
|
|
196
187
|
merge: { value: mergeMethod, configurable: true },
|
|
197
188
|
pick: { value: pickMethod, configurable: true },
|
|
198
189
|
mapOption: { value: mapOptionMethod, configurable: true },
|
package/dist/builtins.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Action, type Option as OptionT, type Pipeable, type Result as ResultT, type TaggedUnion, type TypedAction } from "./ast.js";
|
|
1
|
+
import { type Action, type MergeTuple, type Option as OptionT, type Pipeable, type Result as ResultT, type TaggedUnion, type TypedAction } from "./ast.js";
|
|
2
2
|
/**
|
|
3
3
|
* Typed combinators for structural data transformations.
|
|
4
4
|
*
|
|
@@ -16,8 +16,7 @@ export declare const drop: TypedAction<any, never>;
|
|
|
16
16
|
* input: string → output: TaggedUnion<{ Ok: string; Err: number }>
|
|
17
17
|
*/
|
|
18
18
|
export declare function tag<TDef extends Record<string, unknown>, TKind extends keyof TDef & string>(kind: TKind): TypedAction<TDef[TKind], TaggedUnion<TDef>>;
|
|
19
|
-
|
|
20
|
-
export declare function merge<TObjects extends Record<string, unknown>[]>(): TypedAction<TObjects, UnionToIntersection<TObjects[number]>>;
|
|
19
|
+
export declare function merge<TTuple extends Record<string, unknown>[]>(): TypedAction<TTuple, MergeTuple<TTuple>>;
|
|
21
20
|
export declare function flatten<TElement>(): TypedAction<TElement[][], TElement[]>;
|
|
22
21
|
export declare function extractField<TObj extends Record<string, unknown>, TField extends keyof TObj & string>(field: TField): TypedAction<TObj, TObj[TField]>;
|
|
23
22
|
export declare function extractIndex<TTuple extends unknown[], TIndex extends number>(index: TIndex): TypedAction<TTuple, TTuple[TIndex]>;
|
|
@@ -44,24 +43,13 @@ export declare function withResource<TIn extends Record<string, unknown>, TResou
|
|
|
44
43
|
action: Pipeable<TResource & TIn, TOut>;
|
|
45
44
|
dispose: Pipeable<TResource, TDisposeOut>;
|
|
46
45
|
}): 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
46
|
/**
|
|
58
47
|
* Run `action` on the input for its side effects, then discard the action's
|
|
59
48
|
* output and return the original input unchanged. The action must accept
|
|
60
49
|
* exactly `TInput`. Use `pick` inside the action's pipe if the inner
|
|
61
50
|
* handler needs a subset.
|
|
62
51
|
*
|
|
63
|
-
* Constraint: input must be an object (uses
|
|
64
|
-
* relies on all + merge).
|
|
52
|
+
* Constraint: input must be an object (uses all + merge internally).
|
|
65
53
|
*
|
|
66
54
|
* Example:
|
|
67
55
|
* pipe(tap(pipe(pick("worktreePath", "description"), implement)), createPR)
|
|
@@ -255,4 +243,3 @@ export declare const Result: {
|
|
|
255
243
|
*/
|
|
256
244
|
readonly isErr: <TValue, TError>() => TypedAction<ResultT<TValue, TError>, boolean>;
|
|
257
245
|
};
|
|
258
|
-
export {};
|
package/dist/builtins.js
CHANGED
|
@@ -45,6 +45,9 @@ export function tag(kind) {
|
|
|
45
45
|
handler: { kind: "Builtin", builtin: { kind: "Tag", value: kind } },
|
|
46
46
|
});
|
|
47
47
|
}
|
|
48
|
+
// ---------------------------------------------------------------------------
|
|
49
|
+
// Merge — merge a tuple of objects into a single object
|
|
50
|
+
// ---------------------------------------------------------------------------
|
|
48
51
|
export function merge() {
|
|
49
52
|
return typedAction({
|
|
50
53
|
kind: "Invoke",
|
|
@@ -155,33 +158,6 @@ export function withResource({ create, action, dispose, }) {
|
|
|
155
158
|
return chain(chain(chain(acquireAndMerge, actionAndKeepMerged), disposeAndKeepResult), extractIndex(0));
|
|
156
159
|
}
|
|
157
160
|
// ---------------------------------------------------------------------------
|
|
158
|
-
// Augment — run a transform, merge its output back into the original input
|
|
159
|
-
// ---------------------------------------------------------------------------
|
|
160
|
-
/**
|
|
161
|
-
* Run `action` on the input, then merge the action's output fields back
|
|
162
|
-
* into the original input object. The action must accept exactly `TInput`.
|
|
163
|
-
* Use `pick` inside the action's pipe if the inner handler needs a subset.
|
|
164
|
-
*
|
|
165
|
-
* Example:
|
|
166
|
-
* augment(pipe(pick("file"), migrate))
|
|
167
|
-
* // { file, outputPath } → { file, outputPath, content, migrated }
|
|
168
|
-
*/
|
|
169
|
-
export function augment(action) {
|
|
170
|
-
// Build AST directly — chain inference fails because [TOutput, TInput]
|
|
171
|
-
// doesn't match merge()'s Record<string, unknown>[] with invariance.
|
|
172
|
-
return typedAction({
|
|
173
|
-
kind: "Chain",
|
|
174
|
-
first: {
|
|
175
|
-
kind: "All",
|
|
176
|
-
actions: [action, identity],
|
|
177
|
-
},
|
|
178
|
-
rest: {
|
|
179
|
-
kind: "Invoke",
|
|
180
|
-
handler: { kind: "Builtin", builtin: { kind: "Merge" } },
|
|
181
|
-
},
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
|
-
// ---------------------------------------------------------------------------
|
|
185
161
|
// Tap — run an action for side effects, preserve original input
|
|
186
162
|
// ---------------------------------------------------------------------------
|
|
187
163
|
/**
|
|
@@ -190,16 +166,13 @@ export function augment(action) {
|
|
|
190
166
|
* exactly `TInput`. Use `pick` inside the action's pipe if the inner
|
|
191
167
|
* handler needs a subset.
|
|
192
168
|
*
|
|
193
|
-
* Constraint: input must be an object (uses
|
|
194
|
-
* relies on all + merge).
|
|
169
|
+
* Constraint: input must be an object (uses all + merge internally).
|
|
195
170
|
*
|
|
196
171
|
* Example:
|
|
197
172
|
* pipe(tap(pipe(pick("worktreePath", "description"), implement)), createPR)
|
|
198
173
|
*/
|
|
199
174
|
export function tap(action) {
|
|
200
|
-
//
|
|
201
|
-
// can't go through typed chain/augment with invariant phantom fields.
|
|
202
|
-
// tap: all(chain(action, constant({})), identity()) → merge
|
|
175
|
+
// all(chain(action, constant({})), identity) → merge
|
|
203
176
|
return typedAction({
|
|
204
177
|
kind: "Chain",
|
|
205
178
|
first: {
|
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,
|
|
3
|
+
export { constant, identity, drop, tag, merge, flatten, extractField, extractIndex, pick, dropResult, withResource, tap, range, 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,
|
|
2
|
+
export { constant, identity, drop, tag, merge, flatten, extractField, extractIndex, pick, dropResult, withResource, tap, range, 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
package/src/ast.ts
CHANGED
|
@@ -185,15 +185,10 @@ export type TypedAction<
|
|
|
185
185
|
get<TField extends keyof Out & string>(
|
|
186
186
|
field: TField,
|
|
187
187
|
): TypedAction<In, Out[TField], Refs>;
|
|
188
|
-
/**
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
*
|
|
193
|
-
* Unlike the standalone `augment()` function, the postfix form has access
|
|
194
|
-
* to `In` so the intersection types correctly.
|
|
195
|
-
*/
|
|
196
|
-
augment(): TypedAction<In, In & Out, Refs>;
|
|
188
|
+
/** Wrap output in an object under a field name. `a.wrapInField("foo")` ≡ `pipe(a, wrapInField("foo"))`. */
|
|
189
|
+
wrapInField<TField extends string>(
|
|
190
|
+
field: TField,
|
|
191
|
+
): TypedAction<In, Record<TField, Out>, Refs>;
|
|
197
192
|
/** Merge a tuple of objects into a single object. `a.merge()` ≡ `pipe(a, merge())`. */
|
|
198
193
|
merge(): TypedAction<In, MergeTuple<Out>, Refs>;
|
|
199
194
|
/** Select fields from the output. `a.pick("x", "y")` ≡ `pipe(a, pick("x", "y"))`. */
|
|
@@ -437,25 +432,16 @@ function getMethod(this: TypedAction, field: string): TypedAction {
|
|
|
437
432
|
});
|
|
438
433
|
}
|
|
439
434
|
|
|
440
|
-
function
|
|
441
|
-
// Construct: All(this, identity) → Merge
|
|
442
|
-
// "this" is the sub-pipeline. augment() wraps it so the original input
|
|
443
|
-
// flows through identity alongside the sub-pipeline, then merges the results.
|
|
435
|
+
function wrapInFieldMethod(this: TypedAction, field: string): TypedAction {
|
|
444
436
|
return typedAction({
|
|
445
437
|
kind: "Chain",
|
|
446
|
-
first:
|
|
447
|
-
kind: "All",
|
|
448
|
-
actions: [
|
|
449
|
-
this as Action,
|
|
450
|
-
{
|
|
451
|
-
kind: "Invoke",
|
|
452
|
-
handler: { kind: "Builtin", builtin: { kind: "Identity" } },
|
|
453
|
-
},
|
|
454
|
-
],
|
|
455
|
-
},
|
|
438
|
+
first: this,
|
|
456
439
|
rest: {
|
|
457
440
|
kind: "Invoke",
|
|
458
|
-
handler: {
|
|
441
|
+
handler: {
|
|
442
|
+
kind: "Builtin",
|
|
443
|
+
builtin: { kind: "WrapInField", value: field },
|
|
444
|
+
},
|
|
459
445
|
},
|
|
460
446
|
});
|
|
461
447
|
}
|
|
@@ -577,7 +563,7 @@ export function typedAction<
|
|
|
577
563
|
drop: { value: dropMethod, configurable: true },
|
|
578
564
|
tag: { value: tagMethod, configurable: true },
|
|
579
565
|
get: { value: getMethod, configurable: true },
|
|
580
|
-
|
|
566
|
+
wrapInField: { value: wrapInFieldMethod, configurable: true },
|
|
581
567
|
merge: { value: mergeMethod, configurable: true },
|
|
582
568
|
pick: { value: pickMethod, configurable: true },
|
|
583
569
|
mapOption: { value: mapOptionMethod, configurable: true },
|
package/src/builtins.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
type Action,
|
|
3
|
+
type MergeTuple,
|
|
3
4
|
type Option as OptionT,
|
|
4
5
|
type Pipeable,
|
|
5
6
|
type Result as ResultT,
|
|
@@ -70,16 +71,10 @@ export function tag<
|
|
|
70
71
|
// Merge — merge a tuple of objects into a single object
|
|
71
72
|
// ---------------------------------------------------------------------------
|
|
72
73
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
? I
|
|
78
|
-
: never;
|
|
79
|
-
|
|
80
|
-
export function merge<
|
|
81
|
-
TObjects extends Record<string, unknown>[],
|
|
82
|
-
>(): TypedAction<TObjects, UnionToIntersection<TObjects[number]>> {
|
|
74
|
+
export function merge<TTuple extends Record<string, unknown>[]>(): TypedAction<
|
|
75
|
+
TTuple,
|
|
76
|
+
MergeTuple<TTuple>
|
|
77
|
+
> {
|
|
83
78
|
return typedAction({
|
|
84
79
|
kind: "Invoke",
|
|
85
80
|
handler: { kind: "Builtin", builtin: { kind: "Merge" } },
|
|
@@ -243,38 +238,6 @@ export function withResource<
|
|
|
243
238
|
) as TypedAction<TIn, TOut>;
|
|
244
239
|
}
|
|
245
240
|
|
|
246
|
-
// ---------------------------------------------------------------------------
|
|
247
|
-
// Augment — run a transform, merge its output back into the original input
|
|
248
|
-
// ---------------------------------------------------------------------------
|
|
249
|
-
|
|
250
|
-
/**
|
|
251
|
-
* Run `action` on the input, then merge the action's output fields back
|
|
252
|
-
* into the original input object. The action must accept exactly `TInput`.
|
|
253
|
-
* Use `pick` inside the action's pipe if the inner handler needs a subset.
|
|
254
|
-
*
|
|
255
|
-
* Example:
|
|
256
|
-
* augment(pipe(pick("file"), migrate))
|
|
257
|
-
* // { file, outputPath } → { file, outputPath, content, migrated }
|
|
258
|
-
*/
|
|
259
|
-
export function augment<
|
|
260
|
-
TInput extends Record<string, unknown>,
|
|
261
|
-
TOutput extends Record<string, unknown>,
|
|
262
|
-
>(action: Pipeable<TInput, TOutput>): TypedAction<TInput, TInput & TOutput> {
|
|
263
|
-
// Build AST directly — chain inference fails because [TOutput, TInput]
|
|
264
|
-
// doesn't match merge()'s Record<string, unknown>[] with invariance.
|
|
265
|
-
return typedAction({
|
|
266
|
-
kind: "Chain",
|
|
267
|
-
first: {
|
|
268
|
-
kind: "All",
|
|
269
|
-
actions: [action as Action, identity as Action],
|
|
270
|
-
},
|
|
271
|
-
rest: {
|
|
272
|
-
kind: "Invoke",
|
|
273
|
-
handler: { kind: "Builtin", builtin: { kind: "Merge" } },
|
|
274
|
-
},
|
|
275
|
-
});
|
|
276
|
-
}
|
|
277
|
-
|
|
278
241
|
// ---------------------------------------------------------------------------
|
|
279
242
|
// Tap — run an action for side effects, preserve original input
|
|
280
243
|
// ---------------------------------------------------------------------------
|
|
@@ -285,8 +248,7 @@ export function augment<
|
|
|
285
248
|
* exactly `TInput`. Use `pick` inside the action's pipe if the inner
|
|
286
249
|
* handler needs a subset.
|
|
287
250
|
*
|
|
288
|
-
* Constraint: input must be an object (uses
|
|
289
|
-
* relies on all + merge).
|
|
251
|
+
* Constraint: input must be an object (uses all + merge internally).
|
|
290
252
|
*
|
|
291
253
|
* Example:
|
|
292
254
|
* pipe(tap(pipe(pick("worktreePath", "description"), implement)), createPR)
|
|
@@ -294,9 +256,7 @@ export function augment<
|
|
|
294
256
|
export function tap<TInput extends Record<string, unknown>>(
|
|
295
257
|
action: Pipeable<TInput, any>,
|
|
296
258
|
): TypedAction<TInput, TInput> {
|
|
297
|
-
//
|
|
298
|
-
// can't go through typed chain/augment with invariant phantom fields.
|
|
299
|
-
// tap: all(chain(action, constant({})), identity()) → merge
|
|
259
|
+
// all(chain(action, constant({})), identity) → merge
|
|
300
260
|
return typedAction({
|
|
301
261
|
kind: "Chain",
|
|
302
262
|
first: {
|