@protobase/workflows 0.76.0 → 0.76.1

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.
@@ -28,6 +28,7 @@ const located = (pointer) => {
28
28
  const message = (error) => {
29
29
  if (error.keyword === "additionalProperties") return `${error.params.additionalProperty} is not a field here`;
30
30
  if (error.keyword === "required") return `${error.params.missingProperty} is missing`;
31
+ if (error.keyword === "minItems") return `is missing; it needs at least ${String(error.params.limit)}`;
31
32
  if (error.keyword === "const") return `must be ${JSON.stringify(error.params.allowedValue)}`;
32
33
  if (error.keyword === "discriminator") return "must be one of Task, Choice, Pass, Map, Wait, Succeed and Fail";
33
34
  if (error.keyword === "pattern" && error.instancePath === "/trigger") return "names a trigger type <plugin>:<key>, such as app:record, or manual";
package/dist/index.d.ts CHANGED
@@ -11,7 +11,7 @@ import { Redactor, redacted, secretRedactor, shortestSecret } from "./run/redact
11
11
  import { KeyShape } from "./run/cache/cache-key.js";
12
12
  import { CacheCall, CacheEntry, CacheIdentity, StepCacheStore } from "./run/cache/cache-port.js";
13
13
  import { LoadedRun, RunChange, RunStatus, RunStore, SavedStep, SegmentQueue, StepLog, StepRecord, StepStatus, TaskContext, TaskHandler, TaskHandlers } from "./run/port.js";
14
- import { EarlierStep, rerunSteps } from "./run/rerun.js";
14
+ import { EarlierStep, keptAssigned, rerunFromSteps, rerunSteps, resultRead } from "./run/rerun.js";
15
15
  import { heldBackLog } from "./run/replay.js";
16
16
  import { Runner, RunnerPort, createRunner } from "./run/runner.js";
17
17
  import { SegmentInput, runSegment } from "./run/segment.js";
@@ -21,4 +21,4 @@ import { triggerChecks } from "./plugin/trigger-checks.js";
21
21
  import { TypeEntry, Unavailable, typeList } from "./plugin/type-list.js";
22
22
  import { ConnectionSupport, connectionUnavailable } from "./plugin/connection-availability.js";
23
23
  import { CatalogEntry, TypeCatalog, typeCatalog } from "./plugin/type-catalog.js";
24
- export { type CacheCall, type CacheEntry, type CacheIdentity, type CatalogEntry, type Catcher, type CheckOptions, type ChoiceRule, type ChoiceState, type ConnectionSupport, type Definition, type EarlierStep, type ErrorOutput, type KeyShape, type LoadedPlugin, type LoadedRun, type Machine, type MapState, type Problem, type Redactor, type Retrier, type RunChange, type RunStatus, type RunStore, type Runner, type RunnerPort, type SavedStep, type SegmentInput, type SegmentQueue, type State, type StateMachine, type StepCacheStore, StepError, type StepLog, type StepRecord, type StepStatus, type StepWiring, type TaskContext, type TaskHandler, type TaskHandlers, type TaskState, type Trigger, type TriggerCheck, type TypeCatalog, type TypeEntry, type Unavailable, checkDefinition, connectionUnavailable, createRunner, definitionSchema, heldBackLog, limits, loadPlugins, nestingDepth, problemText, redacted, rerunSteps, runSegment, secretRedactor, shortestSecret, stepHandlers, triggerChecks, typeCatalog, typeList, usedConnections };
24
+ export { type CacheCall, type CacheEntry, type CacheIdentity, type CatalogEntry, type Catcher, type CheckOptions, type ChoiceRule, type ChoiceState, type ConnectionSupport, type Definition, type EarlierStep, type ErrorOutput, type KeyShape, type LoadedPlugin, type LoadedRun, type Machine, type MapState, type Problem, type Redactor, type Retrier, type RunChange, type RunStatus, type RunStore, type Runner, type RunnerPort, type SavedStep, type SegmentInput, type SegmentQueue, type State, type StateMachine, type StepCacheStore, StepError, type StepLog, type StepRecord, type StepStatus, type StepWiring, type TaskContext, type TaskHandler, type TaskHandlers, type TaskState, type Trigger, type TriggerCheck, type TypeCatalog, type TypeEntry, type Unavailable, checkDefinition, connectionUnavailable, createRunner, definitionSchema, heldBackLog, keptAssigned, limits, loadPlugins, nestingDepth, problemText, redacted, rerunFromSteps, rerunSteps, resultRead, runSegment, secretRedactor, shortestSecret, stepHandlers, triggerChecks, typeCatalog, typeList, usedConnections };
package/dist/index.js CHANGED
@@ -6,7 +6,7 @@ import { nestingDepth } from "./nesting.js";
6
6
  import { checkDefinition } from "./definition/check-definition.js";
7
7
  import { StepError } from "./run/errors.js";
8
8
  import { redacted, secretRedactor, shortestSecret } from "./run/redact.js";
9
- import { rerunSteps } from "./run/rerun.js";
9
+ import { keptAssigned, rerunFromSteps, rerunSteps, resultRead } from "./run/rerun.js";
10
10
  import { heldBackLog } from "./run/replay.js";
11
11
  import { runSegment } from "./run/segment.js";
12
12
  import { createRunner } from "./run/runner.js";
@@ -16,4 +16,4 @@ import { triggerChecks } from "./plugin/trigger-checks.js";
16
16
  import { typeList } from "./plugin/type-list.js";
17
17
  import { connectionUnavailable } from "./plugin/connection-availability.js";
18
18
  import { typeCatalog } from "./plugin/type-catalog.js";
19
- export { StepError, checkDefinition, connectionUnavailable, createRunner, definitionSchema, heldBackLog, limits, loadPlugins, nestingDepth, problemText, redacted, rerunSteps, runSegment, secretRedactor, shortestSecret, stepHandlers, triggerChecks, typeCatalog, typeList, usedConnections };
19
+ export { StepError, checkDefinition, connectionUnavailable, createRunner, definitionSchema, heldBackLog, keptAssigned, limits, loadPlugins, nestingDepth, problemText, redacted, rerunFromSteps, rerunSteps, resultRead, runSegment, secretRedactor, shortestSecret, stepHandlers, triggerChecks, typeCatalog, typeList, usedConnections };
@@ -15,4 +15,33 @@ export declare const rerunSteps: <S extends EarlierStep>(machine: Machine, steps
15
15
  } | {
16
16
  problem: string;
17
17
  };
18
+ /** How a state keeps its whole result in a variable. */
19
+ export declare const resultRead = "{% $states.result %}";
20
+ /**
21
+ * What a kept step assigned, with each variable its state has on the version a re-run runs that keeps its whole result
22
+ * holding that result, whatever it held then: a step kept as it ran still gives what a later step now reads from it, and
23
+ * nothing runs again for it. Its other variables stay as they ran, and so does all a step that did not succeed assigned.
24
+ * The step's output is its whole result only where its state in `ran`, the version the earlier run ran, had no `Output`:
25
+ * a step whose result was shaped then keeps what it assigned, as nothing knows its whole result any more.
26
+ */
27
+ export declare const keptAssigned: (machine: Machine, ran: Machine, step: {
28
+ scope: string;
29
+ state: string;
30
+ status: string;
31
+ output?: unknown;
32
+ assigned?: unknown;
33
+ }) => {
34
+ [x: string]: unknown;
35
+ } | undefined;
36
+ /**
37
+ * The steps of an ended run that a re-run from `state`, a state of the workflow itself and not of a Map, keeps: those
38
+ * before its first visit, with the items of the Maps among them as they ran, so the run goes on at `state` with `machine`,
39
+ * the workflow's version now, and everything from there runs again. Returns the problem instead when the run never
40
+ * reached it, or the version does not have it or starts elsewhere.
41
+ */
42
+ export declare const rerunFromSteps: <S extends EarlierStep>(machine: Machine, steps: readonly S[], state: string) => {
43
+ steps: S[];
44
+ } | {
45
+ problem: string;
46
+ };
18
47
  //#endregion
package/dist/run/rerun.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { expressionSource } from "../definition/expressions.js";
1
2
  //#region src/run/rerun.ts
2
3
  const itemOf = (scope) => {
3
4
  const slash = scope.lastIndexOf("/");
@@ -58,5 +59,43 @@ const rerunSteps = (machine, steps) => {
58
59
  const problem = keepFrom("", machine);
59
60
  return problem ? { problem } : { steps: kept };
60
61
  };
62
+ /** How a state keeps its whole result in a variable. */
63
+ const resultRead = "{% $states.result %}";
64
+ /**
65
+ * What a kept step assigned, with each variable its state has on the version a re-run runs that keeps its whole result
66
+ * holding that result, whatever it held then: a step kept as it ran still gives what a later step now reads from it, and
67
+ * nothing runs again for it. Its other variables stay as they ran, and so does all a step that did not succeed assigned.
68
+ * The step's output is its whole result only where its state in `ran`, the version the earlier run ran, had no `Output`:
69
+ * a step whose result was shaped then keeps what it assigned, as nothing knows its whole result any more.
70
+ */
71
+ const keptAssigned = (machine, ran, step) => {
72
+ const state = step.scope === "" && step.status === "succeeded" ? machine.States[step.state] : void 0;
73
+ const before = ran.States[step.state];
74
+ const assign = state && "Assign" in state ? state.Assign : void 0;
75
+ if (!state || !assign || !before || "Output" in before && before.Output !== void 0) return void 0;
76
+ const assigned = step.assigned ?? {};
77
+ const whole = Object.keys(assign).filter((name) => expressionSource(assign[name])?.trim() === "$states.result" && JSON.stringify(assigned[name]) !== JSON.stringify(step.output));
78
+ return whole.length === 0 ? void 0 : {
79
+ ...assigned,
80
+ ...Object.fromEntries(whole.map((name) => [name, step.output]))
81
+ };
82
+ };
83
+ /**
84
+ * The steps of an ended run that a re-run from `state`, a state of the workflow itself and not of a Map, keeps: those
85
+ * before its first visit, with the items of the Maps among them as they ran, so the run goes on at `state` with `machine`,
86
+ * the workflow's version now, and everything from there runs again. Returns the problem instead when the run never
87
+ * reached it, or the version does not have it or starts elsewhere.
88
+ */
89
+ const rerunFromSteps = (machine, steps, state) => {
90
+ const own = steps.filter((step) => step.scope === "").sort((a, b) => a.seq - b.seq);
91
+ const from = own.findIndex((step) => step.state === state);
92
+ if (from === -1) return { problem: `The run never reached state "${state}"` };
93
+ if (!Object.hasOwn(machine.States, state)) return { problem: `The workflow no longer has state "${state}"` };
94
+ if (from === 0 && machine.StartAt !== state) return { problem: `The workflow no longer starts at state "${state}"` };
95
+ const kept = own.slice(0, from);
96
+ const seqs = new Set(kept.map((step) => step.seq));
97
+ const inner = steps.filter((step) => step.scope !== "" && seqs.has(itemOf(step.scope.split("/")[0]).seq));
98
+ return { steps: [...kept, ...inner] };
99
+ };
61
100
  //#endregion
62
- export { rerunSteps };
101
+ export { keptAssigned, rerunFromSteps, rerunSteps, resultRead };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@protobase/workflows",
3
- "version": "0.76.0",
3
+ "version": "0.76.1",
4
4
  "description": "Workflows as state machines with JSONata expressions: their check, a runner that saves every step, and the plugin interface for trigger and step types.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {