@smthrs/plan 0.0.0-stage → 1.0.0-rc.4

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 (199) hide show
  1. package/CHANGELOG.md +183 -0
  2. package/LICENSE +21 -0
  3. package/README.md +228 -2
  4. package/dist/cjs/CachePolicy.d.ts +131 -0
  5. package/dist/cjs/CachePolicy.d.ts.map +1 -0
  6. package/dist/cjs/CachePolicy.js +50 -0
  7. package/dist/cjs/CachePolicy.js.map +7 -0
  8. package/dist/cjs/Effects.d.ts +240 -0
  9. package/dist/cjs/Effects.d.ts.map +1 -0
  10. package/dist/cjs/Effects.js +76 -0
  11. package/dist/cjs/Effects.js.map +7 -0
  12. package/dist/cjs/FileSet.d.ts +288 -0
  13. package/dist/cjs/FileSet.d.ts.map +1 -0
  14. package/dist/cjs/FileSet.js +191 -0
  15. package/dist/cjs/FileSet.js.map +7 -0
  16. package/dist/cjs/GraphBuildError.d.ts +122 -0
  17. package/dist/cjs/GraphBuildError.d.ts.map +1 -0
  18. package/dist/cjs/GraphBuildError.js +71 -0
  19. package/dist/cjs/GraphBuildError.js.map +7 -0
  20. package/dist/cjs/KeyMaterial.d.ts +102 -0
  21. package/dist/cjs/KeyMaterial.d.ts.map +1 -0
  22. package/dist/cjs/KeyMaterial.js +64 -0
  23. package/dist/cjs/KeyMaterial.js.map +7 -0
  24. package/dist/cjs/Node.d.ts +606 -0
  25. package/dist/cjs/Node.d.ts.map +1 -0
  26. package/dist/cjs/Node.js +207 -0
  27. package/dist/cjs/Node.js.map +7 -0
  28. package/dist/cjs/Placement.d.ts +117 -0
  29. package/dist/cjs/Placement.d.ts.map +1 -0
  30. package/dist/cjs/Placement.js +46 -0
  31. package/dist/cjs/Placement.js.map +7 -0
  32. package/dist/cjs/Plan.d.ts +440 -0
  33. package/dist/cjs/Plan.d.ts.map +1 -0
  34. package/dist/cjs/Plan.js +508 -0
  35. package/dist/cjs/Plan.js.map +7 -0
  36. package/dist/cjs/PlanDiff.d.ts +58 -0
  37. package/dist/cjs/PlanDiff.d.ts.map +1 -0
  38. package/dist/cjs/PlanDiff.js +124 -0
  39. package/dist/cjs/PlanDiff.js.map +7 -0
  40. package/dist/cjs/Planned.d.ts +121 -0
  41. package/dist/cjs/Planned.d.ts.map +1 -0
  42. package/dist/cjs/Planned.js +72 -0
  43. package/dist/cjs/Planned.js.map +7 -0
  44. package/dist/cjs/Repetition.d.ts +31 -0
  45. package/dist/cjs/Repetition.d.ts.map +1 -0
  46. package/dist/cjs/Repetition.js +36 -0
  47. package/dist/cjs/Repetition.js.map +7 -0
  48. package/dist/cjs/Scheduling.d.ts +89 -0
  49. package/dist/cjs/Scheduling.d.ts.map +1 -0
  50. package/dist/cjs/Scheduling.js +76 -0
  51. package/dist/cjs/Scheduling.js.map +7 -0
  52. package/dist/cjs/StepKey.d.ts +333 -0
  53. package/dist/cjs/StepKey.d.ts.map +1 -0
  54. package/dist/cjs/StepKey.js +311 -0
  55. package/dist/cjs/StepKey.js.map +7 -0
  56. package/dist/cjs/index.d.ts +91 -0
  57. package/dist/cjs/index.d.ts.map +1 -0
  58. package/dist/cjs/index.js +59 -0
  59. package/dist/cjs/index.js.map +7 -0
  60. package/dist/cjs/internal/ConflictAnnotation.d.ts +59 -0
  61. package/dist/cjs/internal/ConflictAnnotation.d.ts.map +1 -0
  62. package/dist/cjs/internal/ConflictAnnotation.js +247 -0
  63. package/dist/cjs/internal/ConflictAnnotation.js.map +7 -0
  64. package/dist/cjs/internal/EffectCandidates.d.ts +19 -0
  65. package/dist/cjs/internal/EffectCandidates.d.ts.map +1 -0
  66. package/dist/cjs/internal/EffectCandidates.js +92 -0
  67. package/dist/cjs/internal/EffectCandidates.js.map +7 -0
  68. package/dist/cjs/internal/JsonMirror.d.ts +34 -0
  69. package/dist/cjs/internal/JsonMirror.d.ts.map +1 -0
  70. package/dist/cjs/internal/JsonMirror.js +195 -0
  71. package/dist/cjs/internal/JsonMirror.js.map +7 -0
  72. package/dist/cjs/internal/effects.d.ts +245 -0
  73. package/dist/cjs/internal/effects.d.ts.map +1 -0
  74. package/dist/cjs/internal/effects.js +290 -0
  75. package/dist/cjs/internal/effects.js.map +7 -0
  76. package/dist/cjs/internal/node.d.ts +526 -0
  77. package/dist/cjs/internal/node.d.ts.map +1 -0
  78. package/dist/cjs/internal/node.js +312 -0
  79. package/dist/cjs/internal/node.js.map +7 -0
  80. package/dist/cjs/package.json +1 -0
  81. package/dist/cjs/test/PlanFixtures.d.ts +127 -0
  82. package/dist/cjs/test/PlanFixtures.d.ts.map +1 -0
  83. package/dist/cjs/test/PlanFixtures.js +59 -0
  84. package/dist/cjs/test/PlanFixtures.js.map +7 -0
  85. package/dist/esm/CachePolicy.d.ts +131 -0
  86. package/dist/esm/CachePolicy.d.ts.map +1 -0
  87. package/dist/esm/CachePolicy.js +117 -0
  88. package/dist/esm/CachePolicy.js.map +1 -0
  89. package/dist/esm/Effects.d.ts +240 -0
  90. package/dist/esm/Effects.d.ts.map +1 -0
  91. package/dist/esm/Effects.js +167 -0
  92. package/dist/esm/Effects.js.map +1 -0
  93. package/dist/esm/FileSet.d.ts +288 -0
  94. package/dist/esm/FileSet.d.ts.map +1 -0
  95. package/dist/esm/FileSet.js +324 -0
  96. package/dist/esm/FileSet.js.map +1 -0
  97. package/dist/esm/GraphBuildError.d.ts +122 -0
  98. package/dist/esm/GraphBuildError.d.ts.map +1 -0
  99. package/dist/esm/GraphBuildError.js +146 -0
  100. package/dist/esm/GraphBuildError.js.map +1 -0
  101. package/dist/esm/KeyMaterial.d.ts +102 -0
  102. package/dist/esm/KeyMaterial.d.ts.map +1 -0
  103. package/dist/esm/KeyMaterial.js +85 -0
  104. package/dist/esm/KeyMaterial.js.map +1 -0
  105. package/dist/esm/Node.d.ts +606 -0
  106. package/dist/esm/Node.d.ts.map +1 -0
  107. package/dist/esm/Node.js +521 -0
  108. package/dist/esm/Node.js.map +1 -0
  109. package/dist/esm/Placement.d.ts +117 -0
  110. package/dist/esm/Placement.d.ts.map +1 -0
  111. package/dist/esm/Placement.js +65 -0
  112. package/dist/esm/Placement.js.map +1 -0
  113. package/dist/esm/Plan.d.ts +440 -0
  114. package/dist/esm/Plan.d.ts.map +1 -0
  115. package/dist/esm/Plan.js +673 -0
  116. package/dist/esm/Plan.js.map +1 -0
  117. package/dist/esm/PlanDiff.d.ts +58 -0
  118. package/dist/esm/PlanDiff.d.ts.map +1 -0
  119. package/dist/esm/PlanDiff.js +159 -0
  120. package/dist/esm/PlanDiff.js.map +1 -0
  121. package/dist/esm/Planned.d.ts +121 -0
  122. package/dist/esm/Planned.d.ts.map +1 -0
  123. package/dist/esm/Planned.js +147 -0
  124. package/dist/esm/Planned.js.map +1 -0
  125. package/dist/esm/Repetition.d.ts +31 -0
  126. package/dist/esm/Repetition.d.ts.map +1 -0
  127. package/dist/esm/Repetition.js +24 -0
  128. package/dist/esm/Repetition.js.map +1 -0
  129. package/dist/esm/Scheduling.d.ts +89 -0
  130. package/dist/esm/Scheduling.d.ts.map +1 -0
  131. package/dist/esm/Scheduling.js +82 -0
  132. package/dist/esm/Scheduling.js.map +1 -0
  133. package/dist/esm/StepKey.d.ts +333 -0
  134. package/dist/esm/StepKey.d.ts.map +1 -0
  135. package/dist/esm/StepKey.js +478 -0
  136. package/dist/esm/StepKey.js.map +1 -0
  137. package/dist/esm/index.d.ts +91 -0
  138. package/dist/esm/index.d.ts.map +1 -0
  139. package/dist/esm/index.js +91 -0
  140. package/dist/esm/index.js.map +1 -0
  141. package/dist/esm/internal/ConflictAnnotation.d.ts +59 -0
  142. package/dist/esm/internal/ConflictAnnotation.d.ts.map +1 -0
  143. package/dist/esm/internal/ConflictAnnotation.js +332 -0
  144. package/dist/esm/internal/ConflictAnnotation.js.map +1 -0
  145. package/dist/esm/internal/EffectCandidates.d.ts +19 -0
  146. package/dist/esm/internal/EffectCandidates.d.ts.map +1 -0
  147. package/dist/esm/internal/EffectCandidates.js +86 -0
  148. package/dist/esm/internal/EffectCandidates.js.map +1 -0
  149. package/dist/esm/internal/JsonMirror.d.ts +34 -0
  150. package/dist/esm/internal/JsonMirror.d.ts.map +1 -0
  151. package/dist/esm/internal/JsonMirror.js +204 -0
  152. package/dist/esm/internal/JsonMirror.js.map +1 -0
  153. package/dist/esm/internal/effects.d.ts +245 -0
  154. package/dist/esm/internal/effects.d.ts.map +1 -0
  155. package/dist/esm/internal/effects.js +459 -0
  156. package/dist/esm/internal/effects.js.map +1 -0
  157. package/dist/esm/internal/node.d.ts +526 -0
  158. package/dist/esm/internal/node.d.ts.map +1 -0
  159. package/dist/esm/internal/node.js +564 -0
  160. package/dist/esm/internal/node.js.map +1 -0
  161. package/dist/esm/test/PlanFixtures.d.ts +127 -0
  162. package/dist/esm/test/PlanFixtures.d.ts.map +1 -0
  163. package/dist/esm/test/PlanFixtures.js +60 -0
  164. package/dist/esm/test/PlanFixtures.js.map +1 -0
  165. package/docs/README.md +165 -0
  166. package/docs/api.md +1475 -0
  167. package/docs/concepts/authoring-ast.md +203 -0
  168. package/docs/concepts/effects-and-conflicts.md +135 -0
  169. package/docs/concepts/plan-value.md +168 -0
  170. package/docs/concepts/step-keys.md +179 -0
  171. package/docs/guides/author-a-node-graph.md +182 -0
  172. package/docs/guides/compile-a-plan.md +146 -0
  173. package/docs/guides/declare-file-effects.md +143 -0
  174. package/docs/guides/diff-two-plans.md +101 -0
  175. package/docs/installation.md +71 -0
  176. package/docs/quickstart.md +128 -0
  177. package/docs/testing.md +73 -0
  178. package/docs/troubleshooting.md +314 -0
  179. package/package.json +254 -3
  180. package/src/CachePolicy.ts +143 -0
  181. package/src/Effects.ts +284 -0
  182. package/src/FileSet.ts +411 -0
  183. package/src/GraphBuildError.ts +158 -0
  184. package/src/KeyMaterial.ts +106 -0
  185. package/src/Node.ts +871 -0
  186. package/src/Placement.ts +99 -0
  187. package/src/Plan.ts +868 -0
  188. package/src/PlanDiff.ts +199 -0
  189. package/src/Planned.ts +208 -0
  190. package/src/Repetition.ts +33 -0
  191. package/src/Scheduling.ts +154 -0
  192. package/src/StepKey.ts +710 -0
  193. package/src/index.ts +103 -0
  194. package/src/internal/ConflictAnnotation.ts +374 -0
  195. package/src/internal/EffectCandidates.ts +89 -0
  196. package/src/internal/JsonMirror.ts +255 -0
  197. package/src/internal/effects.ts +543 -0
  198. package/src/internal/node.ts +858 -0
  199. package/src/test/PlanFixtures.ts +76 -0
package/src/Node.ts ADDED
@@ -0,0 +1,871 @@
1
+ /**
2
+ * Pure, pipeable nodes: the shape a flow body describes and nothing more.
3
+ *
4
+ * Building a node records an inspectable AST and executes nothing — the same
5
+ * split as Bazel's `ctx.actions.run`, which declares an action rather than
6
+ * running one. A plan is
7
+ * always a DAG, so there is no loop node here and never will be: repetition
8
+ * lives one level up, in what a flow settles with.
9
+ *
10
+ * A node also carries Effect's requirement channel, `R`, and carries it as a
11
+ * PHANTOM: building a plan demands nothing, and every combinator here unions
12
+ * `R` without ever reading it. What fills the channel is a call to something
13
+ * whose code lives elsewhere — an action — so the type of a plan states which
14
+ * implementations executing it will need, and the place that executes it is
15
+ * where the compiler asks for them.
16
+ *
17
+ * Control flow is structure. {@link branch} takes both arms and evaluates each
18
+ * ONCE, symbolically, so the exit condition and the handoff site are visible
19
+ * topology before anything runs; its predicate is digested and runs later on
20
+ * the real value. {@link map} is transformation only. The rule the authoring
21
+ * note states, and this module encodes: **map transforms; branch decides.**
22
+ *
23
+ * Adapted from `@smthrs/core` (`packages/smithers/flows/core`) `Node.ts`.
24
+ * `Dynamic` is gone — a model call is an ordinary action, and nothing
25
+ * model-shaped belongs in this package — and node annotations are gone with
26
+ * it, because the AST has to stay JSON serializable.
27
+ *
28
+ * @since 0.1.0
29
+ */
30
+
31
+ import { dual } from "effect/Function"
32
+ import type * as Pipeable from "effect/Pipeable"
33
+ import type * as Schema from "effect/Schema"
34
+ import type * as Types from "effect/Types"
35
+ import { GraphBuildError } from "./GraphBuildError.ts"
36
+ import * as internal from "./internal/node.ts"
37
+ import * as Planned from "./Planned.ts"
38
+
39
+ /**
40
+ * The runtime type identifier carried by every node.
41
+ *
42
+ * @since 0.1.0
43
+ * @category type ids
44
+ * @slop
45
+ */
46
+ export const TypeId: TypeId = internal.TypeId
47
+
48
+ /**
49
+ * The type-level form of {@link TypeId}.
50
+ *
51
+ * @since 0.1.0
52
+ * @category type ids
53
+ * @slop
54
+ */
55
+ export type TypeId = "~@smthrs/plan/Node"
56
+
57
+ /**
58
+ * The inspectable AST a node stores: closure-free, and JSON serializable for
59
+ * every JSON payload an author puts in it.
60
+ *
61
+ * @since 0.1.0
62
+ * @category models
63
+ * @slop
64
+ */
65
+ export type Ast = internal.NodeAst
66
+
67
+ /**
68
+ * How a flow call joins the caller's plan: `inline` splices the callee's body
69
+ * in, `boundary` makes it one child execution, and `handoff` names the next
70
+ * trampoline round.
71
+ *
72
+ * This is the ONE call-mode vocabulary. {@link flowCall} takes it and
73
+ * `@smthrs/flow`'s graph builder switches on it, so a second spelling in
74
+ * either package would fork the moment one gained a mode.
75
+ *
76
+ * @since 0.1.0
77
+ * @category models
78
+ * @slop
79
+ */
80
+ export const CallMode = internal.CallMode
81
+
82
+ /**
83
+ * The value form of {@link CallMode}.
84
+ *
85
+ * @since 0.1.0
86
+ * @category models
87
+ * @slop
88
+ */
89
+ export type CallMode = internal.CallMode
90
+
91
+ /**
92
+ * The serializable stand-in an AST keeps for a plan-time function: a digest of
93
+ * its normalized source, hashed in place of a closure that could not be
94
+ * shipped, stored, or compared.
95
+ *
96
+ * @since 0.1.0
97
+ * @category models
98
+ * @slop
99
+ */
100
+ export type FunctionIdentity = Extract<Ast, { readonly _tag: "Map" }>["mapper"]
101
+
102
+ /**
103
+ * Reads the inert AST reference created for a planned value.
104
+ *
105
+ * Structural lookalikes remain ordinary payload data. This accessor is the
106
+ * only recognition path because the marker itself is deliberately private to
107
+ * the AST cloner.
108
+ *
109
+ * @since 1.0.0
110
+ * @category accessors
111
+ */
112
+ export const plannedReference = internal.plannedReference
113
+
114
+ /**
115
+ * A pure graph-building value, covariant in what it will succeed and fail
116
+ * with and in what it will need to run. It is a description: holding one has
117
+ * run nothing.
118
+ *
119
+ * `R` is Effect's requirement channel, and it is PHANTOM here. Nothing at plan
120
+ * time reads it: the AST, the graph built from it, its key material, and every
121
+ * digest are identical whatever `R` says. It exists so a value that names an
122
+ * implementation it does not carry — an action call — can say so in its type,
123
+ * and so the place that finally has to run that implementation can demand it.
124
+ * Building a plan therefore stays requirement-free; only executing one is not.
125
+ *
126
+ * @since 0.1.0
127
+ * @category models
128
+ * @slop
129
+ */
130
+ export interface Node<out A, out E = never, out R = never> extends Pipeable.Pipeable {
131
+ readonly [TypeId]: {
132
+ readonly _A: Types.Covariant<A>
133
+ readonly _E: Types.Covariant<E>
134
+ readonly _R: Types.Covariant<R>
135
+ }
136
+ readonly ast: Ast
137
+ }
138
+
139
+ /**
140
+ * Any node, whatever it succeeds or fails with and whatever it requires.
141
+ *
142
+ * @since 0.1.0
143
+ * @category models
144
+ * @slop
145
+ */
146
+ export type Any = Node<unknown, unknown, any>
147
+
148
+ /**
149
+ * The success type of a node.
150
+ *
151
+ * @since 0.1.0
152
+ * @category models
153
+ * @slop
154
+ */
155
+ export type Success<N> = N extends Node<infer A, infer _E, infer _R> ? A : never
156
+
157
+ /**
158
+ * The error type of a node.
159
+ *
160
+ * @since 0.1.0
161
+ * @category models
162
+ * @slop
163
+ */
164
+ export type Error<N> = N extends Node<infer _A, infer E, infer _R> ? E : never
165
+
166
+ /**
167
+ * The requirements of a node: what has to be provided wherever it is finally
168
+ * executed, and nothing that has to be provided to build it.
169
+ *
170
+ * @since 0.1.0
171
+ * @category models
172
+ * @slop
173
+ */
174
+ export type Services<N> = N extends Node<infer _A, infer _E, infer R> ? R : never
175
+
176
+ /**
177
+ * The node reference a branch arm's symbolic subject carries. Arms are built
178
+ * before the graph assigns ids, so every reference an arm records names this
179
+ * placeholder, and graph building rewrites it to the branch's own upstream
180
+ * node — which is `first`, structurally, and therefore not a guess.
181
+ *
182
+ * @since 0.1.0
183
+ * @category constants
184
+ * @slop
185
+ */
186
+ export const branchSubject = "branch/subject"
187
+
188
+ /** @private */
189
+ const subjectsKey = Symbol.for("@smthrs/plan/Node/subjects/v1")
190
+ const globals = globalThis as typeof globalThis & { [subjectsKey]?: { branch: number; catch: number } }
191
+ const subjects = globals[subjectsKey] ??= { branch: 0, catch: 0 }
192
+
193
+ /**
194
+ * The prefix of the node reference a catch failure arm's symbolic error
195
+ * carries. Each {@link catch_} mints its own token under this prefix, so an
196
+ * outer error captured inside a nested failure arm keeps naming the outer
197
+ * catch, and graph building rewrites each token to the node that catch
198
+ * protects.
199
+ *
200
+ * @since 0.1.0
201
+ * @category constants
202
+ * @slop
203
+ */
204
+ export const catchSubject = "catch/subject"
205
+
206
+ /**
207
+ * The two arms of a decision plus the predicate that chooses between them.
208
+ *
209
+ * `if` runs at RUN time on the real value. `then` and `else` run at PLAN time,
210
+ * once each, against a {@link module:Planned.Planned} placeholder — they
211
+ * describe topology, so they may pass the value on but never compute on it.
212
+ *
213
+ * @since 0.1.0
214
+ * @category models
215
+ * @slop
216
+ */
217
+ export interface BranchOptions<A, B1, E1, R1, B2, E2, R2> {
218
+ readonly if: (value: A) => boolean
219
+ readonly then: (value: Planned.Planned<A>) => Node<B1, E1, R1>
220
+ readonly else: (value: Planned.Planned<A>) => Node<B2, E2, R2>
221
+ }
222
+
223
+ /**
224
+ * The statically planned recovery arm and optional schema selecting which
225
+ * typed failures it handles.
226
+ *
227
+ * @since 0.1.0
228
+ * @category models
229
+ * @slop
230
+ */
231
+ export interface CatchOptions<E, B, E2, R2 = never, Handled = E> {
232
+ readonly error?: Schema.Schema<Handled> | undefined
233
+ readonly onFailure: (error: Planned.Planned<Handled>) => Node<B, E2, R2>
234
+ }
235
+
236
+ /**
237
+ * Checks whether a value is a node.
238
+ *
239
+ * A node this package built is recognized by registration at construction. A
240
+ * node that crossed a serialization boundary, an object sharing the node
241
+ * prototype whose own `ast` is a well-formed AST, is recognized by that shape,
242
+ * because `@smthrs/flow` hands a rehydrated AST back as a node and its side
243
+ * tables are all a round trip loses. The {@link TypeId} marker is a public
244
+ * string any object can carry, so it counts for nothing on its own: every
245
+ * combinator that admits a node reads its `ast` as trusted topology, and an
246
+ * object carrying the marker on any other prototype, one inheriting it from a
247
+ * node, and one whose `ast` is missing, malformed, cyclic, or an accessor are
248
+ * all refused with the same `GraphBuildError` as any other non-node. A proxy
249
+ * is judged by the shape it forwards: one that forwards a node unchanged
250
+ * passes, and one that diverges from it does not.
251
+ *
252
+ * @since 0.1.0
253
+ * @category guards
254
+ * @slop
255
+ */
256
+ export const isNode = (value: unknown): value is Any => internal.isNode(value)
257
+
258
+ /**
259
+ * The inert value delivered by {@link succeed}. Planned references resolve to
260
+ * their result type; other values follow the payload's JSON projection.
261
+ * Invalid dates serialize to null. Members without a JSON representation are
262
+ * omitted from objects and replaced with null in arrays.
263
+ *
264
+ * @since 1.0.0
265
+ * @category models
266
+ */
267
+ export type Succeed<A> = A extends Planned.Planned<infer Value> ? Value
268
+ : A extends Date ? string | null
269
+ : A extends { toJSON: (...args: any) => infer Value } ? Succeed<Value>
270
+ : A extends (...args: any) => any ? undefined
271
+ : A extends symbol ? undefined
272
+ : A extends ReadonlyArray<unknown> ? { [K in keyof A]: SucceedArrayMember<A[K]> }
273
+ : A extends object ? {
274
+ [K in keyof A as K extends string | number ? [Succeed<A[K]>] extends [undefined] ? never : K : never]: Succeed<
275
+ A[K]
276
+ >
277
+ }
278
+ : A
279
+
280
+ /** @private */
281
+ type SucceedArrayMember<A> = A extends Planned.Planned<infer Value> ? Value
282
+ : A extends unknown ? Succeed<A> extends infer Value ? Value extends undefined ? null : Value
283
+ : never
284
+ : never
285
+
286
+ /**
287
+ * A node that succeeds with the constant's inert JSON projection.
288
+ *
289
+ * Dates produce strings (or null for invalid dates), URLs produce strings,
290
+ * and callable object members are omitted. Use {@link map} to reconstruct a
291
+ * domain value explicitly after this serialization boundary.
292
+ *
293
+ * @since 0.1.0
294
+ * @category constructors
295
+ */
296
+ export const succeed = <A>(value: A): Node<Succeed<A>> => internal.makeNode<Succeed<A>>(internal.succeed(value))
297
+
298
+ /**
299
+ * The inert error delivered by {@link fail}: the same JSON projection
300
+ * {@link Succeed} describes, because a plan stores an error exactly as it
301
+ * stores a value.
302
+ *
303
+ * @since 1.0.0
304
+ * @category models
305
+ */
306
+ export type Fail<E> = Succeed<E>
307
+
308
+ /**
309
+ * A node that fails with the constant's inert JSON projection, in the typed
310
+ * error channel.
311
+ *
312
+ * It is how a plan states a refusal it already knows about — an unsupported
313
+ * input, an exhausted budget, a compensation that has nothing left to undo —
314
+ * without an action that exists only to fail. {@link catch} recovers it exactly
315
+ * as it recovers an action's failure, and an uncaught one is the flow's typed
316
+ * failure.
317
+ *
318
+ * @since 1.0.0
319
+ * @category constructors
320
+ */
321
+ export const fail = <E>(error: E): Node<never, Fail<E>> => internal.makeNode<never, Fail<E>>(internal.fail(error))
322
+
323
+ /**
324
+ * Combines independent children into one node, keyed by name.
325
+ *
326
+ * Width is fixed here, at plan time. Fanning out over something a step
327
+ * discovered is not this: end the round and carry the list in the next flow's
328
+ * payload, where it is real data.
329
+ *
330
+ * @since 0.1.0
331
+ * @category constructors
332
+ * @slop
333
+ */
334
+ export const all = <const Nodes extends Readonly<Record<string, Any>>>(
335
+ nodes: Nodes
336
+ ): Node<
337
+ Types.Simplify<{ readonly [K in keyof Nodes]: Success<Nodes[K]> }>,
338
+ Error<Nodes[keyof Nodes]>,
339
+ Services<Nodes[keyof Nodes]>
340
+ > => internal.makeNode(internal.all(memberAsts(nodes, "all", "invalid_all_member")))
341
+
342
+ /**
343
+ * The member ASTs of a combination, keyed by name, refusing a non-node member.
344
+ *
345
+ * @private
346
+ */
347
+ const memberAsts = (
348
+ nodes: Readonly<Record<string, unknown>>,
349
+ combinator: string,
350
+ code: "invalid_all_member" | "invalid_join"
351
+ ): Record<string, Ast> => {
352
+ const asts: Record<string, Ast> = Object.create(null) as Record<string, Ast>
353
+ for (const [member, node] of Object.entries(nodes)) {
354
+ if (!isNode(node)) {
355
+ throw new GraphBuildError({
356
+ code,
357
+ node: member,
358
+ path: [],
359
+ message: `Node.${combinator} expected a Node at member "${member}"`
360
+ })
361
+ }
362
+ Object.defineProperty(asts, member, {
363
+ configurable: true,
364
+ enumerable: true,
365
+ value: node.ast,
366
+ writable: true
367
+ })
368
+ }
369
+ return asts
370
+ }
371
+
372
+ /**
373
+ * Builds a join that settles early, refusing a member set it could never
374
+ * decide on.
375
+ *
376
+ * @private
377
+ */
378
+ const join = (mode: internal.RaceMode, count: number, nodes: Readonly<Record<string, unknown>>): Ast => {
379
+ const asts = memberAsts(nodes, mode, "invalid_join")
380
+ const width = Object.keys(asts).length
381
+ if (!internal.isRaceCount(mode, count, width)) {
382
+ throw new GraphBuildError({
383
+ code: "invalid_join",
384
+ node: mode,
385
+ path: [],
386
+ message: mode === "quorum"
387
+ ? `Node.quorum needs a whole number of successes between 1 and its ${width} members, got ${String(count)}`
388
+ : `Node.${mode} needs at least one member`
389
+ })
390
+ }
391
+ return internal.race(mode, count, asts)
392
+ }
393
+
394
+ /**
395
+ * The members of an early-settling join, keyed by name.
396
+ *
397
+ * @since 1.0.0
398
+ * @category models
399
+ */
400
+ export type Members = Readonly<Record<string, Any>>
401
+
402
+ /**
403
+ * Settles with the first member to settle, success or typed failure.
404
+ *
405
+ * The other members are interrupted. The winner is journaled, so a resumed run
406
+ * settles the same member and never starts the others again.
407
+ *
408
+ * @since 1.0.0
409
+ * @category constructors
410
+ */
411
+ export const race = <const Nodes extends Members>(
412
+ nodes: Nodes
413
+ ): Node<Success<Nodes[keyof Nodes]>, Error<Nodes[keyof Nodes]>, Services<Nodes[keyof Nodes]>> =>
414
+ internal.makeNode(join("race", 1, nodes))
415
+
416
+ /**
417
+ * Settles with the first member to succeed, ignoring typed failures while a
418
+ * member is still running.
419
+ *
420
+ * It fails with the last failure when every member fails. The other members
421
+ * are interrupted, and the winner is journaled as {@link race} journals it.
422
+ *
423
+ * @since 1.0.0
424
+ * @category constructors
425
+ */
426
+ export const any = <const Nodes extends Members>(
427
+ nodes: Nodes
428
+ ): Node<Success<Nodes[keyof Nodes]>, Error<Nodes[keyof Nodes]>, Services<Nodes[keyof Nodes]>> =>
429
+ internal.makeNode(join("any", 1, nodes))
430
+
431
+ /**
432
+ * Succeeds once `count` members succeed, with exactly those members' values
433
+ * keyed by name.
434
+ *
435
+ * It fails with the failure that leaves fewer than `count` members able to
436
+ * succeed. Either way the members still running are interrupted, and the
437
+ * members that decided are journaled as {@link race} journals its winner.
438
+ *
439
+ * @since 1.0.0
440
+ * @category constructors
441
+ */
442
+ export const quorum = <const Nodes extends Members>(
443
+ count: number,
444
+ nodes: Nodes
445
+ ): Node<
446
+ Types.Simplify<{ readonly [K in keyof Nodes]?: Success<Nodes[K]> }>,
447
+ Error<Nodes[keyof Nodes]>,
448
+ Services<Nodes[keyof Nodes]>
449
+ > => internal.makeNode(join("quorum", count, nodes))
450
+
451
+ /**
452
+ * Transforms an eventual success value with a deferred pure function.
453
+ *
454
+ * The function is digested, not run: it executes later, on the real value.
455
+ * This is where computation on a step result belongs — and only computation. A
456
+ * `map` that decides what happens next is a `branch` written wrongly.
457
+ *
458
+ * @since 0.1.0
459
+ * @category mapping
460
+ * @slop
461
+ */
462
+ export const map: {
463
+ <A, B>(f: (a: A) => B): <E, R>(self: Node<A, E, R>) => Node<B, E, R>
464
+ <A, E, R, B>(self: Node<A, E, R>, f: (a: A) => B): Node<B, E, R>
465
+ } = dual(
466
+ 2,
467
+ <A, E, R, B>(self: Node<A, E, R>, f: (a: A) => B): Node<B, E, R> =>
468
+ internal.makeNode<B, E, R>(internal.map(self.ast, (value) => f(value as A), f))
469
+ )
470
+
471
+ /**
472
+ * Starts the entire next subtree only after this node succeeds, without
473
+ * consuming its result. Failure or interruption prevents that subtree from
474
+ * starting, including actions nested inside combinations or inline flows.
475
+ *
476
+ * Use {@link bindPlanned} to build a dependency from a symbolic result, or
477
+ * {@link map} to compute on the eventual value.
478
+ *
479
+ * @since 0.1.0
480
+ * @category sequencing
481
+ * @slop
482
+ */
483
+ export const andThen: {
484
+ <B, E2, R2>(next: Node<B, E2, R2>): <A, E, R>(self: Node<A, E, R>) => Node<B, E | E2, R | R2>
485
+ <A, E, R, B, E2, R2>(self: Node<A, E, R>, next: Node<B, E2, R2>): Node<B, E | E2, R | R2>
486
+ } = dual(
487
+ 2,
488
+ <A, E, R, B, E2, R2>(
489
+ self: Node<A, E, R>,
490
+ next: Node<B, E2, R2>
491
+ ): Node<B, E | E2, R | R2> => {
492
+ if (!isNode(next)) {
493
+ throw new GraphBuildError({
494
+ code: "invalid_continuation",
495
+ node: "andThen/next",
496
+ path: [],
497
+ message:
498
+ "Node.andThen expects a Node; use Node.bindPlanned for a symbolic builder or Node.map for value computation"
499
+ })
500
+ }
501
+ return internal.makeNode<B, E | E2, R | R2>(internal.andThenNode(self.ast, next.ast))
502
+ }
503
+ )
504
+
505
+ /**
506
+ * Builds a dependency using a symbolic reference to this node's future result.
507
+ *
508
+ * The builder runs during planning. Its argument is a {@link module:Planned.Planned}
509
+ * reference, not the value the node will eventually produce. Pass references
510
+ * into action payloads; use {@link branch} for decisions and {@link map} for
511
+ * computation on real results. JavaScript truthiness and reference equality
512
+ * cannot inspect a planned result. Enable type-aware ESLint's
513
+ * `@typescript-eslint/strict-boolean-expressions` to reject planned conditions.
514
+ * Independent descendants of the built subtree can start while this producer
515
+ * is running; consumers of its reference wait for its value. Use
516
+ * {@link andThen} when the whole next subtree must wait for success.
517
+ *
518
+ * @since 1.0.0
519
+ * @category sequencing
520
+ */
521
+ export const bindPlanned: {
522
+ <A, B, E2, R2>(
523
+ build: (reference: Planned.Planned<A>) => Node<B, E2, R2>
524
+ ): <E, R>(self: Node<A, E, R>) => Node<B, E | E2, R | R2>
525
+ <A, E, R, B, E2, R2>(
526
+ self: Node<A, E, R>,
527
+ build: (reference: Planned.Planned<A>) => Node<B, E2, R2>
528
+ ): Node<B, E | E2, R | R2>
529
+ } = dual(
530
+ 2,
531
+ <A, E, R, B, E2, R2>(
532
+ self: Node<A, E, R>,
533
+ build: (reference: Planned.Planned<A>) => Node<B, E2, R2>
534
+ ): Node<B, E | E2, R | R2> =>
535
+ internal.makeNode<B, E | E2, R | R2>(
536
+ internal.andThen(self.ast, (value) => build(value as Planned.Planned<A>), build)
537
+ )
538
+ )
539
+
540
+ /**
541
+ * Builds one arm, once, against the symbolic subject.
542
+ *
543
+ * @private
544
+ */
545
+ const arm = <A, B, E, R>(
546
+ build: (value: Planned.Planned<A>) => Node<B, E, R>,
547
+ subject: Planned.Planned<A>,
548
+ side: string
549
+ ): Ast => {
550
+ const node = build(subject)
551
+ if (!isNode(node)) {
552
+ throw new GraphBuildError({
553
+ code: "invalid_continuation",
554
+ node: `${branchSubject}/${side}`,
555
+ path: [],
556
+ message: `Node.branch expected its "${side}" arm to return a Node`
557
+ })
558
+ }
559
+ return node.ast
560
+ }
561
+
562
+ /**
563
+ * Decides between two arms, both of them static topology.
564
+ *
565
+ * Each arm builder is evaluated exactly once, here, against a
566
+ * {@link module:Planned.Planned} placeholder, and the resulting ASTs are what
567
+ * the node stores — so a plan shows the exit condition and both continuations
568
+ * before it runs. The predicate is digested and evaluated at run time on the
569
+ * real value, which is why none of the plan-time placeholder machinery leaks
570
+ * into control flow.
571
+ *
572
+ * Both arms contribute their requirements, because both arms are topology the
573
+ * plan carries. A run takes one of them, but which one is not known until the
574
+ * predicate sees the real value, so an execution has to be able to take either.
575
+ *
576
+ * @since 0.1.0
577
+ * @category sequencing
578
+ * @slop
579
+ */
580
+ export const branch: {
581
+ <A, B1, E1, R1, B2, E2, R2>(
582
+ options: BranchOptions<A, B1, E1, R1, B2, E2, R2>
583
+ ): <E, R>(self: Node<A, E, R>) => Node<B1 | B2, E | E1 | E2, R | R1 | R2>
584
+ <A, E, R, B1, E1, R1, B2, E2, R2>(
585
+ self: Node<A, E, R>,
586
+ options: BranchOptions<A, B1, E1, R1, B2, E2, R2>
587
+ ): Node<B1 | B2, E | E1 | E2, R | R1 | R2>
588
+ } = dual(
589
+ 2,
590
+ <A, E, R, B1, E1, R1, B2, E2, R2>(
591
+ self: Node<A, E, R>,
592
+ options: BranchOptions<A, B1, E1, R1, B2, E2, R2>
593
+ ): Node<B1 | B2, E | E1 | E2, R | R1 | R2> => {
594
+ const predicate = options.if
595
+ const subjectToken = `${branchSubject}/${subjects.branch++}`
596
+ const subject = Planned.make<A>(subjectToken)
597
+ return internal.makeNode<B1 | B2, E | E1 | E2, R | R1 | R2>(
598
+ internal.branch(
599
+ subjectToken,
600
+ self.ast,
601
+ (value) => predicate(value as A),
602
+ predicate,
603
+ arm(options.then, subject, "then"),
604
+ arm(options.else, subject, "else")
605
+ )
606
+ )
607
+ }
608
+ )
609
+
610
+ /**
611
+ * Recovers from matching typed failures with static failure topology.
612
+ *
613
+ * The protected graph and failure arm are both stored in the AST. The arm is
614
+ * built once at plan time against a strict planned error placeholder. With no
615
+ * schema the whole typed error channel is handled. A schema handles only the
616
+ * values it accepts, so its overloads retain E: a refinement can reject values
617
+ * without narrowing its TypeScript type. Runtime schema callbacks enter the
618
+ * filter identity along with its JSON Schema. Uncaptured callbacks are local
619
+ * to this process, just like uncaptured mappers.
620
+ *
621
+ * The failure arm contributes its requirements to the node's, for the same
622
+ * reason a branch's arms do: it is topology the plan carries, and a run reaches
623
+ * it whenever the protected graph fails.
624
+ *
625
+ * @since 0.1.0
626
+ * @category sequencing
627
+ * @slop
628
+ */
629
+ const catch_: {
630
+ <Handled, B, E2, R2>(
631
+ options: CatchOptions<unknown, B, E2, R2, Handled> & {
632
+ readonly error: Schema.Schema<Handled>
633
+ }
634
+ ): <A, E, R>(self: Node<A, E, R>) => Node<A | B, E | E2, R | R2>
635
+ <E, B, E2, R2>(
636
+ options: CatchOptions<E, B, E2, R2> & {
637
+ readonly error?: undefined
638
+ }
639
+ ): <A, R>(self: Node<A, E, R>) => Node<A | B, E2, R | R2>
640
+ <A, E, R, Handled, B, E2, R2>(
641
+ self: Node<A, E, R>,
642
+ options: CatchOptions<E, B, E2, R2, Handled> & {
643
+ readonly error: Schema.Schema<Handled>
644
+ }
645
+ ): Node<A | B, E | E2, R | R2>
646
+ <A, E, R, B, E2, R2>(
647
+ self: Node<A, E, R>,
648
+ options: CatchOptions<E, B, E2, R2> & {
649
+ readonly error?: undefined
650
+ }
651
+ ): Node<A | B, E2, R | R2>
652
+ } = dual(
653
+ 2,
654
+ <A, E, R, Handled, B, E2, R2>(
655
+ self: Node<A, E, R>,
656
+ options: CatchOptions<E, B, E2, R2, Handled>
657
+ ): Node<A | B, E | E2, R | R2> => {
658
+ const subjectToken = `${catchSubject}/${subjects.catch++}`
659
+ const failure = options.onFailure(Planned.make<Handled>(subjectToken))
660
+ if (!isNode(failure)) {
661
+ throw new GraphBuildError({
662
+ code: "invalid_continuation",
663
+ node: catchSubject,
664
+ path: [],
665
+ message: "Node.catch expected its failure arm to return a Node"
666
+ })
667
+ }
668
+ return internal.makeNode(internal.catch_(subjectToken, self.ast, failure.ast, options.error))
669
+ }
670
+ )
671
+
672
+ export { catch_ as catch }
673
+
674
+ /**
675
+ * Attaches a scheduling priority to a node, leaving the original unchanged.
676
+ *
677
+ * The scheduler runs ready work with a higher number first, so a priority
678
+ * changes LATENCY and nothing else. It never enters key material: a node
679
+ * ordered ahead of another still computes the same result, so re-keying it
680
+ * would throw away a legitimate cache hit. Children inherit the value
681
+ * lexically when the graph is built, and a child that states its own keeps it.
682
+ *
683
+ * @since 0.1.0
684
+ * @category annotations
685
+ * @slop
686
+ */
687
+ export const priority: {
688
+ (value: number): <A, E, R>(self: Node<A, E, R>) => Node<A, E, R>
689
+ <A, E, R>(self: Node<A, E, R>, value: number): Node<A, E, R>
690
+ } = dual(
691
+ 2,
692
+ <A, E, R>(self: Node<A, E, R>, value: number): Node<A, E, R> => {
693
+ if (!Number.isSafeInteger(value)) {
694
+ throw new GraphBuildError({
695
+ code: "invalid_priority",
696
+ node: self.ast._tag,
697
+ path: [],
698
+ message: `Node.priority expects a safe integer, received ${value}`
699
+ })
700
+ }
701
+ return internal.makeNode<A, E, R>(internal.withPriority(self.ast, value))
702
+ }
703
+ )
704
+
705
+ /**
706
+ * Reads the scheduling priority a node carries, or `undefined` when it states
707
+ * none and inherits from whatever encloses it.
708
+ *
709
+ * @since 0.1.0
710
+ * @category accessors
711
+ * @slop
712
+ */
713
+ export const declaredPriority = (ast: Ast): number | undefined => ast.priority
714
+
715
+ /**
716
+ * Constructs the flow-call node used by `@smthrs/flow` without making flow
717
+ * calls part of the public authoring surface of this package.
718
+ *
719
+ * Reserved for `@smthrs/flow`, which owns flow authoring. It is not part
720
+ * of this package's authoring surface, and it validates nothing: an unknown
721
+ * flow tag becomes a call node the graph keeps as a leaf.
722
+ *
723
+ * @since 0.1.0
724
+ * @category engine
725
+ * @slop
726
+ */
727
+ export const flowCall = <A = unknown, E = never, R = never>(
728
+ declaration: unknown,
729
+ flow: string,
730
+ mode: CallMode,
731
+ payload: unknown
732
+ ): Node<A, E, R> => internal.makeNode<A, E, R>(internal.flowCall(declaration, flow, mode, payload))
733
+
734
+ /**
735
+ * Constructs the action-call node used by `@smthrs/flow` without making
736
+ * action calls part of the public authoring surface of this package.
737
+ *
738
+ * Reserved for `@smthrs/flow`, which owns action authoring. It is not part
739
+ * of this package's authoring surface, and an unknown action tag becomes a
740
+ * call node the graph keeps as a leaf.
741
+ *
742
+ * @since 0.1.0
743
+ * @category engine
744
+ * @slop
745
+ */
746
+ export const actionCall = <A = unknown, E = never, R = never>(
747
+ declaration: unknown,
748
+ action: string,
749
+ payload: unknown
750
+ ): Node<A, E, R> => internal.makeNode<A, E, R>(internal.actionCall(declaration, action, payload))
751
+
752
+ /**
753
+ * Reads the flow or action declaration a call node names, so `@smthrs/flow`
754
+ * can expand a call it recorded. It is `undefined` for an AST that was
755
+ * rehydrated from JSON, because the declaration lives beside the AST rather
756
+ * than inside it — a graph built from such an AST keeps the call as a leaf.
757
+ *
758
+ * Reserved for `@smthrs/flow`, which files the declaration when it builds
759
+ * the call. Authors never call it.
760
+ *
761
+ * @since 0.1.0
762
+ * @category engine
763
+ * @slop
764
+ */
765
+ export const declaration = (
766
+ ast: Extract<Ast, { readonly _tag: "ActionCall" | "FlowCall" }>
767
+ ): unknown => internal.declaration(ast)
768
+
769
+ /**
770
+ * Reads the continuation builder of a sequenced node, which graph building
771
+ * evaluates once against a placeholder. It is `undefined` when the author
772
+ * supplied a node directly — the topology is already in `next` — and for a
773
+ * rehydrated AST, whose side table did not survive serialization.
774
+ *
775
+ * Reserved for `@smthrs/flow`'s graph walk. Authors never call it.
776
+ *
777
+ * @since 0.1.0
778
+ * @category engine
779
+ * @slop
780
+ */
781
+ export const continuation = (
782
+ ast: Extract<Ast, { readonly _tag: "AndThen" }>
783
+ ): ((value: Planned.Planned<unknown>) => unknown) | undefined => internal.operation(ast)
784
+
785
+ /**
786
+ * Reads the deferred mapper of a {@link map} node, which a driver applies to
787
+ * the real upstream value once it has one. It is `undefined` for every other
788
+ * variant, and for a rehydrated AST whose side table did not survive
789
+ * serialization.
790
+ *
791
+ * Reserved for `@smthrs/flow`'s interpreter. Authors never call it.
792
+ *
793
+ * @since 0.1.0
794
+ * @category engine
795
+ * @slop
796
+ */
797
+ export const mapper = (ast: Ast): ((value: unknown) => unknown) | undefined =>
798
+ ast._tag === "Map" ? internal.operation(ast) : undefined
799
+
800
+ /**
801
+ * Reads the run-time predicate of a {@link branch} node, which a driver
802
+ * evaluates on the real subject value to choose an arm. It is `undefined` for
803
+ * every other variant, and for a rehydrated AST whose side table did not
804
+ * survive serialization.
805
+ *
806
+ * Reserved for `@smthrs/flow`'s interpreter. Authors never call it.
807
+ *
808
+ * @since 0.1.0
809
+ * @category engine
810
+ * @slop
811
+ */
812
+ export const predicate = (ast: Ast): ((value: unknown) => boolean) | undefined =>
813
+ ast._tag === "Branch" ? internal.predicate(ast) : undefined
814
+
815
+ /**
816
+ * Reads the optional schema selecting failures handled by a {@link catch_}.
817
+ *
818
+ * Reserved for `@smthrs/flow`'s interpreter. It is `undefined` for every
819
+ * variant but `catch_`, and for a rehydrated AST whose side table did not
820
+ * survive serialization.
821
+ *
822
+ * @since 0.1.0
823
+ * @category engine
824
+ * @slop
825
+ */
826
+ export const catchFilter = (ast: Ast): Schema.Top | undefined => ast._tag === "Catch" ? internal.filter(ast) : undefined
827
+
828
+ /**
829
+ * Identifies a plan-time function the AST does NOT store, a flow's `body`,
830
+ * exactly as the AST identifies the mapper and continuation it does store.
831
+ * A call that keeps its callee as a leaf still has to re-key when that
832
+ * callee's body is edited, and this is the identity it folds in. Unannotated
833
+ * functions fail closed with process-local identity; use {@link capture} to
834
+ * declare inert captures and obtain deterministic identity.
835
+ *
836
+ * Reserved for `@smthrs/flow`, which folds a callee body's identity into a
837
+ * call it keeps as a leaf. Authors never call it; it throws a `TypeError`
838
+ * when handed anything but a function.
839
+ *
840
+ * @since 0.1.0
841
+ * @category engine
842
+ * @slop
843
+ */
844
+ export const functionIdentity = (operation: unknown): FunctionIdentity => internal.functionIdentity(operation)
845
+
846
+ /**
847
+ * Binds a frozen plain copy of inert captures as the callback's this receiver.
848
+ *
849
+ * Use a function expression to read the snapshot while keeping the ordinary
850
+ * callback arguments: Node.capture({ factor: 3 }, function(value: number) {
851
+ * return value * this.factor
852
+ * }). Caller objects remain unchanged; lexical aliases still name originals
853
+ * and must not be used as mutable semantic inputs. Nested captures retain the
854
+ * inner callback's snapshot and compose the two identities.
855
+ *
856
+ * Admission walks original descriptors once, rejects built-in brands and
857
+ * non-plain prototypes without evaluating getters, then uses structuredClone
858
+ * to refuse Proxies. Hosts without that API refuse object capture. Only the
859
+ * owned frozen copy enters identity and the wrapper. Sealed, non-extensible,
860
+ * frozen and Immer ordinary data are supported equally. Unsupported values
861
+ * raise a TypeError naming the path. See core docs/api.md#nodecapture for the
862
+ * complete algorithm and the migration from original-object locking.
863
+ *
864
+ * @category constructors
865
+ * @since 0.1.0
866
+ * @slop
867
+ */
868
+ export const capture = <C extends Readonly<Record<string, unknown>>, Args extends ReadonlyArray<unknown>, A>(
869
+ captures: C,
870
+ operation: (this: Readonly<C>, ...args: Args) => A
871
+ ): (...args: Args) => A => internal.capture(captures, operation)