deltafold 0.1.0 → 0.2.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.
- package/README.md +64 -1
- package/dist/index.d.ts +307 -60
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +232 -36
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/features/execution/executor.ts +232 -45
- package/src/features/execution/handler.ts +181 -60
- package/src/features/execution/interaction.ts +174 -0
- package/src/features/execution/promise-callback.ts +76 -0
- package/src/features/planning/rewrite.ts +1 -1
- package/src/index.ts +2 -0
package/package.json
CHANGED
|
@@ -17,6 +17,7 @@ import type * as Action from "../../foundation/action.ts";
|
|
|
17
17
|
import type * as Plan from "../../foundation/plan.ts";
|
|
18
18
|
import type { Node, Occurrence } from "../../foundation/plan.ts";
|
|
19
19
|
import * as Handler from "./handler.ts";
|
|
20
|
+
import type * as Interaction from "./interaction.ts";
|
|
20
21
|
import { SettlementReference } from "./settlement.ts";
|
|
21
22
|
|
|
22
23
|
/**
|
|
@@ -25,8 +26,20 @@ import { SettlementReference } from "./settlement.ts";
|
|
|
25
26
|
* @since @next
|
|
26
27
|
*/
|
|
27
28
|
export type Outcome<E = unknown> =
|
|
28
|
-
| { readonly _tag: "Completed" }
|
|
29
|
+
| { readonly _tag: "Completed"; readonly performer: "automated" }
|
|
30
|
+
| {
|
|
31
|
+
readonly _tag: "Completed";
|
|
32
|
+
readonly performer: "manual";
|
|
33
|
+
/**
|
|
34
|
+
* What supports completion. `asserted`: the person said so and nothing checked
|
|
35
|
+
* it. `verified`: the person said so and the handler's `verify` check passed.
|
|
36
|
+
* Neither proves how the work was done.
|
|
37
|
+
*/
|
|
38
|
+
readonly confirmation: "asserted" | "verified";
|
|
39
|
+
}
|
|
29
40
|
| { readonly _tag: "Skipped"; readonly reason: string }
|
|
41
|
+
/** The person asked to confirm manual work answered that it is not done. */
|
|
42
|
+
| { readonly _tag: "Declined" }
|
|
30
43
|
| {
|
|
31
44
|
readonly _tag: "Failed";
|
|
32
45
|
readonly phase: Handler.Phase;
|
|
@@ -48,10 +61,22 @@ export type Outcome<E = unknown> =
|
|
|
48
61
|
}
|
|
49
62
|
/** Not started because execution stopped first. */
|
|
50
63
|
| { readonly _tag: "Unattempted" }
|
|
51
|
-
/**
|
|
52
|
-
|
|
64
|
+
/**
|
|
65
|
+
* `evaluated`: whether a prepare phase ran and decided to apply. A `manual` occurrence
|
|
66
|
+
* would wait for a person; a dry run never asks.
|
|
67
|
+
*/
|
|
68
|
+
| {
|
|
69
|
+
readonly _tag: "WouldExecute";
|
|
70
|
+
readonly evaluated: boolean;
|
|
71
|
+
readonly performer: Handler.Performer;
|
|
72
|
+
}
|
|
53
73
|
| { readonly _tag: "WouldSkip"; readonly reason: string }
|
|
54
|
-
| {
|
|
74
|
+
| {
|
|
75
|
+
readonly _tag: "Undetermined";
|
|
76
|
+
readonly reason: string;
|
|
77
|
+
/** A `manual` occurrence would wait for a person if it executes. */
|
|
78
|
+
readonly performer: Handler.Performer;
|
|
79
|
+
}
|
|
55
80
|
| {
|
|
56
81
|
readonly _tag: "PreparationFailed";
|
|
57
82
|
readonly error: E | undefined;
|
|
@@ -81,8 +106,8 @@ export type Report<A extends Action.Any = Action.Any, E = unknown> = {
|
|
|
81
106
|
/** Every occurrence in plan order. */
|
|
82
107
|
readonly occurrences: ReadonlyArray<OccurrenceReport<A, E>>;
|
|
83
108
|
/**
|
|
84
|
-
* Whether any apply phase started
|
|
85
|
-
* state.
|
|
109
|
+
* Whether any apply phase started or any person was asked to do manual work. Either
|
|
110
|
+
* may have partially changed state.
|
|
86
111
|
*/
|
|
87
112
|
readonly bodiesStarted: boolean;
|
|
88
113
|
/** Progress is not persisted. Rerunning the plan repeats completed actions. */
|
|
@@ -133,10 +158,44 @@ export class HandlerCoverageError<A extends Action.Any = Action.Any> extends Han
|
|
|
133
158
|
}
|
|
134
159
|
}
|
|
135
160
|
|
|
161
|
+
const InteractionUnavailableBase = Data.TaggedError("InteractionUnavailable");
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* The plan has manual handlers, and the run has no `interaction` to ask a person. The
|
|
165
|
+
* run fails before any handler phase or prompt.
|
|
166
|
+
*
|
|
167
|
+
* @since @next
|
|
168
|
+
*/
|
|
169
|
+
export class InteractionUnavailable<
|
|
170
|
+
A extends Action.Any = Action.Any,
|
|
171
|
+
> extends InteractionUnavailableBase<{
|
|
172
|
+
/** The occurrences that a manual handler covers, in plan order. */
|
|
173
|
+
readonly occurrences: ReadonlyArray<Occurrence<A>>;
|
|
174
|
+
readonly report: Report<A, never>;
|
|
175
|
+
}> {
|
|
176
|
+
override get message() {
|
|
177
|
+
return `No interaction is available to confirm manual work for ${this.occurrences
|
|
178
|
+
.map((occurrence) => `"${occurrence.id}" (${occurrence.action.description})`)
|
|
179
|
+
.join(
|
|
180
|
+
", ",
|
|
181
|
+
)}. Supply the \`interaction\` option, or bind automated handlers to these actions.`;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const listIds = (entries: ReadonlyArray<OccurrenceReport>) =>
|
|
186
|
+
entries
|
|
187
|
+
.map((entry) =>
|
|
188
|
+
entry.outcome._tag === "Failed"
|
|
189
|
+
? `"${entry.occurrence.id}" (${entry.outcome.phase})`
|
|
190
|
+
: `"${entry.occurrence.id}"`,
|
|
191
|
+
)
|
|
192
|
+
.join(", ");
|
|
193
|
+
|
|
136
194
|
const ExecutionFailedBase = Data.TaggedError("ExecutionFailed");
|
|
137
195
|
|
|
138
196
|
/**
|
|
139
|
-
* An occurrence failed
|
|
197
|
+
* An occurrence failed, or a person declined manual work. Execution stopped admitting
|
|
198
|
+
* new actions; started ones settled.
|
|
140
199
|
*
|
|
141
200
|
* @since @next
|
|
142
201
|
*/
|
|
@@ -145,12 +204,23 @@ export class ExecutionFailed<
|
|
|
145
204
|
E = unknown,
|
|
146
205
|
> extends ExecutionFailedBase<{
|
|
147
206
|
readonly failures: ReadonlyArray<OccurrenceReport<A, E>>;
|
|
207
|
+
/** Manual occurrences that a person declined. */
|
|
208
|
+
readonly declined: ReadonlyArray<OccurrenceReport<A, E>>;
|
|
148
209
|
readonly report: Report<A, E>;
|
|
149
210
|
}> {
|
|
150
211
|
override get message() {
|
|
151
|
-
|
|
152
|
-
.
|
|
153
|
-
|
|
212
|
+
const parts = [
|
|
213
|
+
...(this.failures.length === 0
|
|
214
|
+
? []
|
|
215
|
+
: [`Execution failed at ${listIds(this.failures)}.`]),
|
|
216
|
+
...(this.declined.length === 0
|
|
217
|
+
? []
|
|
218
|
+
: [
|
|
219
|
+
`Manual work was declined at ${listIds(this.declined)}, which stopped the run.`,
|
|
220
|
+
]),
|
|
221
|
+
];
|
|
222
|
+
|
|
223
|
+
return `${parts.join(" ")} Completed actions were not rolled back.`;
|
|
154
224
|
}
|
|
155
225
|
}
|
|
156
226
|
|
|
@@ -199,6 +269,7 @@ export class ExecutionInterrupted<
|
|
|
199
269
|
/** @since @next */
|
|
200
270
|
export type ExecutionError<A extends Action.Any, E> =
|
|
201
271
|
| HandlerCoverageError<A>
|
|
272
|
+
| InteractionUnavailable<A>
|
|
202
273
|
| ExecutionFailed<A, E>
|
|
203
274
|
| ExecutionInterrupted<A, E>;
|
|
204
275
|
|
|
@@ -230,18 +301,25 @@ type CoverageCheck<A extends Action.Any, H, C extends Plan.Coverage> = [
|
|
|
230
301
|
*
|
|
231
302
|
* @since @next
|
|
232
303
|
*/
|
|
233
|
-
export type Errors<H> = Handler.Error<H>;
|
|
304
|
+
export type Errors<H, I = never> = Handler.Error<H> | Interaction.Error<I>;
|
|
234
305
|
|
|
235
306
|
/**
|
|
236
|
-
* Effect services an execution requires: the services of its handlers
|
|
307
|
+
* Effect services an execution requires: the services of its handlers and of its
|
|
308
|
+
* interaction.
|
|
237
309
|
*
|
|
238
310
|
* @since @next
|
|
239
311
|
*/
|
|
240
|
-
export type Requirements<H> = Handler.Services<H>;
|
|
312
|
+
export type Requirements<H, I = never> = Handler.Services<H> | Interaction.Services<I>;
|
|
241
313
|
|
|
242
314
|
/** @since @next */
|
|
243
|
-
export type Options<H extends Handler.Any> = {
|
|
315
|
+
export type Options<H extends Handler.Any, I extends Interaction.Any = never> = {
|
|
244
316
|
readonly handlers?: ReadonlyArray<H>;
|
|
317
|
+
/**
|
|
318
|
+
* Asks a person to confirm the work of manual handlers. A run whose plan has manual
|
|
319
|
+
* handlers fails with `InteractionUnavailable` before it starts when this is absent.
|
|
320
|
+
* A dry run never asks and does not need it.
|
|
321
|
+
*/
|
|
322
|
+
readonly interaction?: I;
|
|
245
323
|
/**
|
|
246
324
|
* Run prepare phases without running any apply phase. A prepare phase that may
|
|
247
325
|
* depend on an earlier action is reported `Undetermined`, because the dry run does
|
|
@@ -250,8 +328,10 @@ export type Options<H extends Handler.Any> = {
|
|
|
250
328
|
readonly dryRun?: boolean;
|
|
251
329
|
/**
|
|
252
330
|
* Limit for each phase of an occurrence: the prepare phase and the apply phase each
|
|
253
|
-
* get the full limit
|
|
254
|
-
* ones. It applies to dry-run prepare
|
|
331
|
+
* get the full limit, and so does the verification of manual work. Exceeding it
|
|
332
|
+
* interrupts that action and stops admitting new ones. It applies to dry-run prepare
|
|
333
|
+
* phases too. It never limits the wait for a person to confirm manual work; cancel
|
|
334
|
+
* the run to end that wait.
|
|
255
335
|
*/
|
|
256
336
|
readonly timeout?: Duration.Input;
|
|
257
337
|
/**
|
|
@@ -383,6 +463,9 @@ type PhaseResult<T, E> =
|
|
|
383
463
|
|
|
384
464
|
type ControlOptions = Pick<Options<never>, "timeout" | "settleTimeout">;
|
|
385
465
|
|
|
466
|
+
/** Waiting for a person is `untimed`: only cancellation ends it. */
|
|
467
|
+
type Timing = "timed" | "untimed";
|
|
468
|
+
|
|
386
469
|
/**
|
|
387
470
|
* Logs a cleanup failure that the report cannot carry, with the occurrence or the
|
|
388
471
|
* services layer that owned the resources.
|
|
@@ -400,7 +483,10 @@ const makeControl = (options: ControlOptions, subscribe: Subscribe | undefined)
|
|
|
400
483
|
const stop = (reason: StopReason) => {
|
|
401
484
|
halt.reason ??= reason;
|
|
402
485
|
};
|
|
486
|
+
// A failure can be the first stop reason, so cancellation is also tracked on its own.
|
|
487
|
+
let cancellationArrived = false;
|
|
403
488
|
subscribe?.(() => {
|
|
489
|
+
cancellationArrived = true;
|
|
404
490
|
stop("cancelled");
|
|
405
491
|
Deferred.doneUnsafe(cancelled, Exit.succeed("cancelled"));
|
|
406
492
|
});
|
|
@@ -412,6 +498,7 @@ const makeControl = (options: ControlOptions, subscribe: Subscribe | undefined)
|
|
|
412
498
|
const runPhase = <T, E, R>(
|
|
413
499
|
work: Effect.Effect<T, E, R>,
|
|
414
500
|
unsettled: Array<Promise<void>>,
|
|
501
|
+
timing: Timing = "timed",
|
|
415
502
|
): Effect.Effect<PhaseResult<T, E>, never, R> =>
|
|
416
503
|
Effect.gen(function* () {
|
|
417
504
|
let settled = true;
|
|
@@ -427,7 +514,7 @@ const makeControl = (options: ControlOptions, subscribe: Subscribe | undefined)
|
|
|
427
514
|
const stopSignals: Array<Effect.Effect<"cancelled" | "timeout">> = [
|
|
428
515
|
Deferred.await(cancelled),
|
|
429
516
|
];
|
|
430
|
-
if (options.timeout !== undefined) {
|
|
517
|
+
if (options.timeout !== undefined && timing === "timed") {
|
|
431
518
|
stopSignals.push(Effect.as(Effect.sleep(options.timeout), "timeout" as const));
|
|
432
519
|
}
|
|
433
520
|
const result = yield* Effect.raceFirst(
|
|
@@ -445,7 +532,7 @@ const makeControl = (options: ControlOptions, subscribe: Subscribe | undefined)
|
|
|
445
532
|
return { _tag: "Interrupted" as const, reason: result.reason, settled };
|
|
446
533
|
});
|
|
447
534
|
|
|
448
|
-
return { halt, stop, runPhase };
|
|
535
|
+
return { halt, stop, runPhase, isCancelled: () => cancellationArrived };
|
|
449
536
|
});
|
|
450
537
|
|
|
451
538
|
/**
|
|
@@ -528,13 +615,14 @@ const unsuccessful = <T, E>(
|
|
|
528
615
|
const execute = <A extends Action.Any, E, R>(
|
|
529
616
|
plan: Plan.Plan<A, Plan.Coverage>,
|
|
530
617
|
resolved: Resolved<E, R>,
|
|
618
|
+
interaction: Interaction.Interaction<E, R> | undefined,
|
|
531
619
|
options: ControlOptions,
|
|
532
620
|
subscribe: Subscribe | undefined,
|
|
533
621
|
retain: Retain,
|
|
534
622
|
): Effect.Effect<Report<A, E>, ExecutionFailed<A, E> | ExecutionInterrupted<A, E>, R> =>
|
|
535
623
|
Effect.gen(function* () {
|
|
536
624
|
const outcomes = new Map<string, Outcome<E>>();
|
|
537
|
-
const { halt, stop, runPhase } = yield* makeControl(options, subscribe);
|
|
625
|
+
const { halt, stop, runPhase, isCancelled } = yield* makeControl(options, subscribe);
|
|
538
626
|
let bodiesStarted = false;
|
|
539
627
|
|
|
540
628
|
const runOccurrence = (occurrence: Occurrence) => {
|
|
@@ -575,6 +663,58 @@ const execute = <A extends Action.Any, E, R>(
|
|
|
575
663
|
step = started.value;
|
|
576
664
|
}
|
|
577
665
|
if (step._tag === "Skip") return end({ _tag: "Skipped", reason: step.reason });
|
|
666
|
+
if (step._tag === "Confirm") {
|
|
667
|
+
// The interaction preflight guarantees one for every manual occurrence.
|
|
668
|
+
if (interaction === undefined) return Exit.void;
|
|
669
|
+
|
|
670
|
+
phase = "confirmation";
|
|
671
|
+
// The person may start changing state as soon as they are asked.
|
|
672
|
+
bodiesStarted = true;
|
|
673
|
+
const asked = yield* runPhase(
|
|
674
|
+
interaction.confirm({ occurrence }),
|
|
675
|
+
unsettled,
|
|
676
|
+
"untimed",
|
|
677
|
+
);
|
|
678
|
+
const unanswered = unsuccessful("confirmation", asked, stop);
|
|
679
|
+
if (unanswered !== undefined) return end(unanswered);
|
|
680
|
+
if (asked._tag !== "Done") return Exit.void;
|
|
681
|
+
if (Exit.isFailure(asked.exit)) return fail(asked.exit.cause);
|
|
682
|
+
if (asked.exit.value === "declined") {
|
|
683
|
+
stop("failure");
|
|
684
|
+
|
|
685
|
+
return end({ _tag: "Declined" });
|
|
686
|
+
}
|
|
687
|
+
if (step.verify === undefined) {
|
|
688
|
+
return end({
|
|
689
|
+
_tag: "Completed",
|
|
690
|
+
performer: "manual",
|
|
691
|
+
confirmation: "asserted",
|
|
692
|
+
});
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
phase = "verification";
|
|
696
|
+
// Cancellation that arrived with the confirmation keeps the check from
|
|
697
|
+
// starting.
|
|
698
|
+
if (isCancelled()) {
|
|
699
|
+
return end({
|
|
700
|
+
_tag: "Interrupted",
|
|
701
|
+
phase,
|
|
702
|
+
reason: "cancelled",
|
|
703
|
+
settled: true,
|
|
704
|
+
});
|
|
705
|
+
}
|
|
706
|
+
const checked = yield* runPhase(step.verify, unsettled);
|
|
707
|
+
const unchecked = unsuccessful("verification", checked, stop);
|
|
708
|
+
if (unchecked !== undefined) return end(unchecked);
|
|
709
|
+
if (checked._tag !== "Done") return Exit.void;
|
|
710
|
+
if (Exit.isFailure(checked.exit)) return fail(checked.exit.cause);
|
|
711
|
+
|
|
712
|
+
return end({
|
|
713
|
+
_tag: "Completed",
|
|
714
|
+
performer: "manual",
|
|
715
|
+
confirmation: "verified",
|
|
716
|
+
});
|
|
717
|
+
}
|
|
578
718
|
|
|
579
719
|
phase = "apply";
|
|
580
720
|
bodiesStarted = true;
|
|
@@ -584,7 +724,7 @@ const execute = <A extends Action.Any, E, R>(
|
|
|
584
724
|
if (applied._tag !== "Done") return Exit.void;
|
|
585
725
|
if (Exit.isFailure(applied.exit)) return fail(applied.exit.cause);
|
|
586
726
|
|
|
587
|
-
return end({ _tag: "Completed" });
|
|
727
|
+
return end({ _tag: "Completed", performer: "automated" });
|
|
588
728
|
});
|
|
589
729
|
|
|
590
730
|
// A finalizer that fails before the report is part of the execution: it fails an
|
|
@@ -638,6 +778,7 @@ const execute = <A extends Action.Any, E, R>(
|
|
|
638
778
|
|
|
639
779
|
return yield* new ExecutionFailed({
|
|
640
780
|
failures: result.occurrences.filter((entry) => entry.outcome._tag === "Failed"),
|
|
781
|
+
declined: result.occurrences.filter((entry) => entry.outcome._tag === "Declined"),
|
|
641
782
|
report: result,
|
|
642
783
|
});
|
|
643
784
|
}
|
|
@@ -684,7 +825,11 @@ const dryRun = <A extends Action.Any, E, R>(
|
|
|
684
825
|
return end(
|
|
685
826
|
step._tag === "Skip"
|
|
686
827
|
? { _tag: "WouldSkip", reason: step.reason }
|
|
687
|
-
: {
|
|
828
|
+
: {
|
|
829
|
+
_tag: "WouldExecute",
|
|
830
|
+
evaluated: true,
|
|
831
|
+
performer: handler.performer,
|
|
832
|
+
},
|
|
688
833
|
);
|
|
689
834
|
});
|
|
690
835
|
const onCleanupFailure = (cause: Cause.Cause<never>) =>
|
|
@@ -734,12 +879,17 @@ const dryRun = <A extends Action.Any, E, R>(
|
|
|
734
879
|
outcomes.set(node.id, {
|
|
735
880
|
_tag: "Undetermined",
|
|
736
881
|
reason: `Execution would stop at the failed preparation of "${failedAt}".`,
|
|
882
|
+
performer: handler.performer,
|
|
737
883
|
});
|
|
738
884
|
|
|
739
885
|
return true;
|
|
740
886
|
}
|
|
741
887
|
if (!handler.prepares) {
|
|
742
|
-
outcomes.set(node.id, {
|
|
888
|
+
outcomes.set(node.id, {
|
|
889
|
+
_tag: "WouldExecute",
|
|
890
|
+
evaluated: false,
|
|
891
|
+
performer: handler.performer,
|
|
892
|
+
});
|
|
743
893
|
|
|
744
894
|
return true;
|
|
745
895
|
}
|
|
@@ -747,6 +897,7 @@ const dryRun = <A extends Action.Any, E, R>(
|
|
|
747
897
|
outcomes.set(node.id, {
|
|
748
898
|
_tag: "Undetermined",
|
|
749
899
|
reason: "The prepare phase depends on earlier actions that a dry run does not apply.",
|
|
900
|
+
performer: handler.performer,
|
|
750
901
|
});
|
|
751
902
|
|
|
752
903
|
return true;
|
|
@@ -774,16 +925,25 @@ const dryRun = <A extends Action.Any, E, R>(
|
|
|
774
925
|
);
|
|
775
926
|
});
|
|
776
927
|
|
|
777
|
-
const run = <
|
|
928
|
+
const run = <
|
|
929
|
+
A extends Action.Any,
|
|
930
|
+
C extends Plan.Coverage,
|
|
931
|
+
H extends Handler.Any,
|
|
932
|
+
I extends Interaction.Any,
|
|
933
|
+
>(
|
|
778
934
|
plan: Plan.Plan<A, C>,
|
|
779
|
-
options: Options<H>,
|
|
935
|
+
options: Options<H, I>,
|
|
780
936
|
subscribe: Subscribe | undefined,
|
|
781
937
|
retain: Retain,
|
|
782
|
-
): Effect.Effect<Report<A, Errors<H>>, ExecutionError<A, Errors<H>>, Requirements<H>> => {
|
|
783
|
-
// Handlers are covariant in their errors and services, and
|
|
784
|
-
// `Requirements<H>` collect them from each handler in `H
|
|
785
|
-
//
|
|
786
|
-
|
|
938
|
+
): Effect.Effect<Report<A, Errors<H, I>>, ExecutionError<A, Errors<H, I>>, Requirements<H, I>> => {
|
|
939
|
+
// Handlers and interactions are covariant in their errors and services, and
|
|
940
|
+
// `Errors<H, I>` and `Requirements<H, I>` collect them from each handler in `H` and
|
|
941
|
+
// from `I`, so every handler and the interaction fit these shapes. From here on the
|
|
942
|
+
// compiler checks both channels.
|
|
943
|
+
const handlers: ReadonlyArray<Internal<Errors<H, I>, Requirements<H, I>>> =
|
|
944
|
+
options.handlers ?? [];
|
|
945
|
+
const interaction: Interaction.Interaction<Errors<H, I>, Requirements<H, I>> | undefined =
|
|
946
|
+
options.interaction;
|
|
787
947
|
|
|
788
948
|
return Effect.gen(function* () {
|
|
789
949
|
const checked = coverage(plan, handlers);
|
|
@@ -800,14 +960,34 @@ const run = <A extends Action.Any, C extends Plan.Coverage, H extends Handler.An
|
|
|
800
960
|
});
|
|
801
961
|
}
|
|
802
962
|
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
963
|
+
if (options.dryRun === true) {
|
|
964
|
+
return yield* dryRun(plan, checked.resolved, options, subscribe, retain);
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
// Nobody can answer for manual work, so the run must not start and stop halfway.
|
|
968
|
+
const manual = plan.occurrences.filter(
|
|
969
|
+
(occurrence) => checked.resolved.get(occurrence.id)?.performer === "manual",
|
|
970
|
+
);
|
|
971
|
+
if (manual.length > 0 && interaction === undefined) {
|
|
972
|
+
return yield* new InteractionUnavailable({
|
|
973
|
+
occurrences: manual,
|
|
974
|
+
report: report(
|
|
975
|
+
plan,
|
|
976
|
+
"execute",
|
|
977
|
+
"not-started",
|
|
978
|
+
new Map<string, Outcome<never>>(),
|
|
979
|
+
false,
|
|
980
|
+
),
|
|
981
|
+
});
|
|
982
|
+
}
|
|
983
|
+
|
|
984
|
+
return yield* execute(plan, checked.resolved, interaction, options, subscribe, retain);
|
|
806
985
|
});
|
|
807
986
|
};
|
|
808
987
|
|
|
809
988
|
/**
|
|
810
|
-
* Runs a plan as an Effect. Coverage
|
|
989
|
+
* Runs a plan as an Effect. Coverage, and the interaction that manual handlers need,
|
|
990
|
+
* are checked before any handler phase runs. Steps
|
|
811
991
|
* are sequential barriers; parallel groups run their branches concurrently. On failure,
|
|
812
992
|
* no new action starts, and actions already running settle before the effect fails
|
|
813
993
|
* with the partial report.
|
|
@@ -827,34 +1007,40 @@ export const effect = <
|
|
|
827
1007
|
A extends Action.Any,
|
|
828
1008
|
C extends Plan.Coverage,
|
|
829
1009
|
H extends Handler.Any = never,
|
|
1010
|
+
I extends Interaction.Any = never,
|
|
830
1011
|
>(
|
|
831
1012
|
plan: Plan.Plan<A, C>,
|
|
832
|
-
options: Options<H> & CoverageCheck<A, H, C>,
|
|
833
|
-
): Effect.Effect<Report<A, Errors<H>>, ExecutionError<A, Errors<H>>, Requirements<H>> =>
|
|
1013
|
+
options: Options<H, I> & CoverageCheck<A, H, C>,
|
|
1014
|
+
): Effect.Effect<Report<A, Errors<H, I>>, ExecutionError<A, Errors<H, I>>, Requirements<H, I>> =>
|
|
834
1015
|
run(plan, options, undefined, () => {});
|
|
835
1016
|
|
|
836
1017
|
type ServicesOption<R, LE> = [R] extends [never]
|
|
837
1018
|
? {
|
|
838
|
-
/** Handlers without Effect services need none. */
|
|
1019
|
+
/** Handlers and interactions without Effect services need none. */
|
|
839
1020
|
readonly services?: Context.Context<never> | Layer.Layer<never, LE>;
|
|
840
1021
|
}
|
|
841
1022
|
: {
|
|
842
|
-
/** Supplies the handlers
|
|
1023
|
+
/** Supplies the Effect services of the handlers and the interaction. */
|
|
843
1024
|
readonly services: Context.Context<R> | Layer.Layer<R, LE>;
|
|
844
1025
|
};
|
|
845
1026
|
|
|
846
1027
|
/** @since @next */
|
|
847
|
-
export type PromiseOptions<H extends Handler.Any> = Options<
|
|
1028
|
+
export type PromiseOptions<H extends Handler.Any, I extends Interaction.Any = never> = Options<
|
|
1029
|
+
H,
|
|
1030
|
+
I
|
|
1031
|
+
> & {
|
|
848
1032
|
/**
|
|
849
|
-
* Explicit cancellation. Aborting stops admission, interrupts running actions
|
|
850
|
-
* rejects with `ExecutionInterrupted` and the partial
|
|
1033
|
+
* Explicit cancellation. Aborting stops admission, interrupts running actions and
|
|
1034
|
+
* pending confirmations, and rejects with `ExecutionInterrupted` and the partial
|
|
1035
|
+
* report.
|
|
851
1036
|
*/
|
|
852
1037
|
readonly signal?: AbortSignal;
|
|
853
1038
|
};
|
|
854
1039
|
|
|
855
1040
|
/**
|
|
856
1041
|
* Runs a plan and returns a Promise. It rejects with `HandlerCoverageError`,
|
|
857
|
-
* `ExecutionFailed`, or `ExecutionInterrupted`, each carrying
|
|
1042
|
+
* `InteractionUnavailable`, `ExecutionFailed`, or `ExecutionInterrupted`, each carrying
|
|
1043
|
+
* the partial report.
|
|
858
1044
|
* Building a supplied services layer can also reject with the layer's own error,
|
|
859
1045
|
* without a report.
|
|
860
1046
|
*
|
|
@@ -871,11 +1057,12 @@ export const runPromise = <
|
|
|
871
1057
|
A extends Action.Any,
|
|
872
1058
|
C extends Plan.Coverage,
|
|
873
1059
|
H extends Handler.Any = never,
|
|
1060
|
+
I extends Interaction.Any = never,
|
|
874
1061
|
LE = never,
|
|
875
1062
|
>(
|
|
876
1063
|
plan: Plan.Plan<A, C>,
|
|
877
|
-
options: PromiseOptions<H> & ServicesOption<Requirements<H>, LE> & CoverageCheck<A, H, C>,
|
|
878
|
-
): Promise<Report<A, Errors<H>>> => {
|
|
1064
|
+
options: PromiseOptions<H, I> & ServicesOption<Requirements<H, I>, LE> & CoverageCheck<A, H, C>,
|
|
1065
|
+
): Promise<Report<A, Errors<H, I>>> => {
|
|
879
1066
|
const { signal } = options;
|
|
880
1067
|
const notStarted = () =>
|
|
881
1068
|
new ExecutionInterrupted({
|
|
@@ -884,7 +1071,7 @@ export const runPromise = <
|
|
|
884
1071
|
plan,
|
|
885
1072
|
options.dryRun === true ? "dry-run" : "execute",
|
|
886
1073
|
"interrupted",
|
|
887
|
-
new Map<string, Outcome<Errors<H>>>(),
|
|
1074
|
+
new Map<string, Outcome<Errors<H, I>>>(),
|
|
888
1075
|
false,
|
|
889
1076
|
),
|
|
890
1077
|
});
|
|
@@ -957,7 +1144,7 @@ export const runPromise = <
|
|
|
957
1144
|
// `ServicesOption` requires services that cover every requirement. A layer that
|
|
958
1145
|
// fails to build rejects with its own error.
|
|
959
1146
|
// oxlint-disable-next-line typescript/no-unsafe-type-assertion, effecttsgo/unsafe-effect-type-assertion
|
|
960
|
-
cancellable as Effect.Effect<Report<A, Errors<H>>, ExecutionError<A, Errors<H>> | LE>,
|
|
1147
|
+
cancellable as Effect.Effect<Report<A, Errors<H, I>>, ExecutionError<A, Errors<H, I>> | LE>,
|
|
961
1148
|
)
|
|
962
1149
|
.finally(() => signal?.removeEventListener("abort", onAbort))
|
|
963
1150
|
.then((exit) => {
|