@barnum/barnum 0.0.0-main-bf5fee51 → 0.0.0-main-37d1e610

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.
@@ -2,22 +2,21 @@ import { type Pipeable, type TypedAction } from "../ast.js";
2
2
  /**
3
3
  * RAII-style resource management combinator.
4
4
  *
5
- * Runs `create` to acquire a resource, then merges the resource with the
6
- * original input into a flat object (`TResource & TIn`) for the action.
7
- * After the action completes, `dispose` receives the resource for cleanup.
8
- * The overall combinator returns the action's output.
5
+ * Runs `create` to acquire a resource, then passes `[TResource, TIn]`
6
+ * as a tuple to the action. After the action completes, `dispose`
7
+ * receives the resource for cleanup. The overall combinator returns
8
+ * the action's output.
9
9
  *
10
10
  * ```
11
11
  * TIn → create → TResource
12
- * → merge(TResource, TIn) → TResource & TIn
13
- * → action(TResource & TIn) → TOut
12
+ * → action([TResource, TIn]) → TOut
14
13
  * → dispose(TResource) → (discarded)
15
14
  * → TOut
16
15
  * ```
17
16
  */
18
- export declare function withResource<TIn extends Record<string, unknown>, TResource extends Record<string, unknown>, TOut, TDisposeOut = unknown>({ create, action, dispose, }: {
17
+ export declare function withResource<TIn, TResource, TOut, TDisposeOut = unknown>({ create, action, dispose, }: {
19
18
  create: Pipeable<TIn, TResource>;
20
- action: Pipeable<TResource & TIn, TOut>;
19
+ action: Pipeable<[TResource, TIn], TOut>;
21
20
  dispose: Pipeable<TResource, TDisposeOut>;
22
21
  }): TypedAction<TIn, TOut>;
23
22
  //# sourceMappingURL=with-resource.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"with-resource.d.ts","sourceRoot":"","sources":["../../src/builtins/with-resource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,WAAW,EAAY,MAAM,WAAW,CAAC;AAWtE;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,YAAY,CAC1B,GAAG,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACnC,SAAS,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACzC,IAAI,EACJ,WAAW,GAAG,OAAO,EACrB,EACA,MAAM,EACN,MAAM,EACN,OAAO,GACR,EAAE;IACD,MAAM,EAAE,QAAQ,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;IACjC,MAAM,EAAE,QAAQ,CAAC,SAAS,GAAG,GAAG,EAAE,IAAI,CAAC,CAAC;IACxC,OAAO,EAAE,QAAQ,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;CAC3C,GAAG,WAAW,CAAC,GAAG,EAAE,IAAI,CAAC,CA4BzB"}
1
+ {"version":3,"file":"with-resource.d.ts","sourceRoot":"","sources":["../../src/builtins/with-resource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,WAAW,EAAY,MAAM,WAAW,CAAC;AAUtE;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,SAAS,EAAE,IAAI,EAAE,WAAW,GAAG,OAAO,EAAE,EACxE,MAAM,EACN,MAAM,EACN,OAAO,GACR,EAAE;IACD,MAAM,EAAE,QAAQ,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;IACjC,MAAM,EAAE,QAAQ,CAAC,CAAC,SAAS,EAAE,GAAG,CAAC,EAAE,IAAI,CAAC,CAAC;IACzC,OAAO,EAAE,QAAQ,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;CAC3C,GAAG,WAAW,CAAC,GAAG,EAAE,IAAI,CAAC,CA6BzB"}
@@ -2,7 +2,6 @@ import { toAction } from "../ast.js";
2
2
  import { chain } from "../chain.js";
3
3
  import { all } from "../all.js";
4
4
  import { identity } from "./scalar.js";
5
- import { merge } from "./struct.js";
6
5
  import { getIndex } from "./array.js";
7
6
  // ---------------------------------------------------------------------------
8
7
  // WithResource — RAII-style create/action/dispose
@@ -10,26 +9,26 @@ import { getIndex } from "./array.js";
10
9
  /**
11
10
  * RAII-style resource management combinator.
12
11
  *
13
- * Runs `create` to acquire a resource, then merges the resource with the
14
- * original input into a flat object (`TResource & TIn`) for the action.
15
- * After the action completes, `dispose` receives the resource for cleanup.
16
- * The overall combinator returns the action's output.
12
+ * Runs `create` to acquire a resource, then passes `[TResource, TIn]`
13
+ * as a tuple to the action. After the action completes, `dispose`
14
+ * receives the resource for cleanup. The overall combinator returns
15
+ * the action's output.
17
16
  *
18
17
  * ```
19
18
  * TIn → create → TResource
20
- * → merge(TResource, TIn) → TResource & TIn
21
- * → action(TResource & TIn) → TOut
19
+ * → action([TResource, TIn]) → TOut
22
20
  * → dispose(TResource) → (discarded)
23
21
  * → TOut
24
22
  * ```
25
23
  */
26
24
  export function withResource({ create, action, dispose, }) {
27
- // Step 1: all(create, identity) → [TResource, TIn] → merge → TResource & TIn
28
- const acquireAndMerge = chain(toAction(all(create, identity())), toAction(merge()));
29
- // Step 2: all(action, identity) → [TOut, TResource & TIn]
30
- const actionAndKeepMerged = all(toAction(action), toAction(identity()));
31
- // Step 3: all(getIndex(0).unwrap(), chain(getIndex(1).unwrap(), dispose)) → [TOut, unknown]
25
+ // Step 1: all(create, identity) → [TResource, TIn]
26
+ const acquireParallel = all(create, identity());
27
+ // Step 2: all(action, getIndex(0)) → [TOut, TResource]
28
+ // Run action on the tuple, keep raw TResource for dispose
29
+ const runActionKeepResource = all(toAction(action), toAction(getIndex(0).unwrap()));
30
+ // Step 3: all(getIndex(0) → TOut, getIndex(1) → dispose) → [TOut, TDisposeOut]
32
31
  const disposeAndKeepResult = all(toAction(getIndex(0).unwrap()), chain(toAction(getIndex(1).unwrap()), toAction(dispose)));
33
32
  // Step 4: getIndex(0).unwrap() → TOut
34
- return chain(toAction(chain(toAction(chain(toAction(acquireAndMerge), toAction(actionAndKeepMerged))), toAction(disposeAndKeepResult))), toAction(getIndex(0).unwrap()));
33
+ return chain(toAction(chain(toAction(chain(toAction(acquireParallel), toAction(runActionKeepResource))), toAction(disposeAndKeepResult))), toAction(getIndex(0).unwrap()));
35
34
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barnum/barnum",
3
- "version": "0.0.0-main-bf5fee51",
3
+ "version": "0.0.0-main-37d1e610",
4
4
  "description": "Barnum workflow engine",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -2,7 +2,6 @@ import { type Pipeable, type TypedAction, toAction } from "../ast.js";
2
2
  import { chain } from "../chain.js";
3
3
  import { all } from "../all.js";
4
4
  import { identity } from "./scalar.js";
5
- import { merge } from "./struct.js";
6
5
  import { getIndex } from "./array.js";
7
6
 
8
7
  // ---------------------------------------------------------------------------
@@ -12,43 +11,38 @@ import { getIndex } from "./array.js";
12
11
  /**
13
12
  * RAII-style resource management combinator.
14
13
  *
15
- * Runs `create` to acquire a resource, then merges the resource with the
16
- * original input into a flat object (`TResource & TIn`) for the action.
17
- * After the action completes, `dispose` receives the resource for cleanup.
18
- * The overall combinator returns the action's output.
14
+ * Runs `create` to acquire a resource, then passes `[TResource, TIn]`
15
+ * as a tuple to the action. After the action completes, `dispose`
16
+ * receives the resource for cleanup. The overall combinator returns
17
+ * the action's output.
19
18
  *
20
19
  * ```
21
20
  * TIn → create → TResource
22
- * → merge(TResource, TIn) → TResource & TIn
23
- * → action(TResource & TIn) → TOut
21
+ * → action([TResource, TIn]) → TOut
24
22
  * → dispose(TResource) → (discarded)
25
23
  * → TOut
26
24
  * ```
27
25
  */
28
- export function withResource<
29
- TIn extends Record<string, unknown>,
30
- TResource extends Record<string, unknown>,
31
- TOut,
32
- TDisposeOut = unknown,
33
- >({
26
+ export function withResource<TIn, TResource, TOut, TDisposeOut = unknown>({
34
27
  create,
35
28
  action,
36
29
  dispose,
37
30
  }: {
38
31
  create: Pipeable<TIn, TResource>;
39
- action: Pipeable<TResource & TIn, TOut>;
32
+ action: Pipeable<[TResource, TIn], TOut>;
40
33
  dispose: Pipeable<TResource, TDisposeOut>;
41
34
  }): TypedAction<TIn, TOut> {
42
- // Step 1: all(create, identity) → [TResource, TIn] → merge → TResource & TIn
43
- const acquireAndMerge = chain(
44
- toAction(all(create, identity())),
45
- toAction(merge()),
46
- );
35
+ // Step 1: all(create, identity) → [TResource, TIn]
36
+ const acquireParallel = all(create, identity());
47
37
 
48
- // Step 2: all(action, identity) → [TOut, TResource & TIn]
49
- const actionAndKeepMerged = all(toAction(action), toAction(identity()));
38
+ // Step 2: all(action, getIndex(0)) → [TOut, TResource]
39
+ // Run action on the tuple, keep raw TResource for dispose
40
+ const runActionKeepResource = all(
41
+ toAction(action),
42
+ toAction(getIndex(0).unwrap()),
43
+ );
50
44
 
51
- // Step 3: all(getIndex(0).unwrap(), chain(getIndex(1).unwrap(), dispose)) → [TOut, unknown]
45
+ // Step 3: all(getIndex(0) → TOut, getIndex(1) dispose) → [TOut, TDisposeOut]
52
46
  const disposeAndKeepResult = all(
53
47
  toAction(getIndex(0).unwrap()),
54
48
  chain(toAction(getIndex(1).unwrap()), toAction(dispose)),
@@ -59,7 +53,7 @@ export function withResource<
59
53
  toAction(
60
54
  chain(
61
55
  toAction(
62
- chain(toAction(acquireAndMerge), toAction(actionAndKeepMerged)),
56
+ chain(toAction(acquireParallel), toAction(runActionKeepResource)),
63
57
  ),
64
58
  toAction(disposeAndKeepResult),
65
59
  ),