@protobase/workflows 0.100.22 → 0.100.24

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.
@@ -0,0 +1,41 @@
1
+ import { Reference } from "./references.js";
2
+ //#region src/definition/pins/conditions.d.ts
3
+ /** A Comparison's operator, as JSONata writes it: Equals, Not equals, Greater and Less. */
4
+ export type CompareOp = '=' | '!=' | '>' | '<';
5
+ /** A value a condition node takes: one read by name, or a value of its own. */
6
+ export type ConditionOperand = {
7
+ read: Reference;
8
+ } | {
9
+ value: string | number | boolean;
10
+ };
11
+ /**
12
+ * A Condition taken apart into the editor's nodes: a Comparison of two values, an And or an Or of two conditions, or a
13
+ * Not of one, where a condition is another of these or a value of its own or read by name.
14
+ */
15
+ export type ConditionPart = {
16
+ kind: 'compare';
17
+ op: CompareOp;
18
+ sides: [ConditionOperand, ConditionOperand];
19
+ } | {
20
+ kind: 'logic';
21
+ op: 'and' | 'or';
22
+ sides: [ConditionSide, ConditionSide];
23
+ } | {
24
+ kind: 'not';
25
+ sides: [ConditionSide];
26
+ };
27
+ /** What a condition node's input takes: a node of its own, or a value. */
28
+ export type ConditionSide = ConditionPart | ConditionOperand;
29
+ /** What a step's status can be, as `$states.context.Steps.<name>.Status` reads it. */
30
+ export declare const stepStatuses: readonly ["SUCCEEDED", "FAILED", "TIMED_OUT", "ABORTED", "SKIPPED"];
31
+ /** Whether a side is a node of its own rather than a value. */
32
+ export declare const isConditionPart: (side: ConditionSide) => side is ConditionPart;
33
+ /** The Condition a node and what it takes write: `{% $states.context.Steps.Save.Status = 'SUCCEEDED' %}`. */
34
+ export declare const conditionValue: (part: ConditionPart) => string;
35
+ /**
36
+ * A Condition taken apart into nodes, when it is a Comparison, an And, an Or or a Not of values and reads by name and
37
+ * writing those nodes back gives it exactly as it is; undefined for any other, such as one that computes, or is spaced
38
+ * or bracketed otherwise, which stays an expression, so no Condition is ever rewritten.
39
+ */
40
+ export declare const conditionParts: (value: unknown) => ConditionPart | undefined;
41
+ //#endregion
@@ -0,0 +1,113 @@
1
+ import { expressionSource, parse } from "../expressions.js";
2
+ import { readText } from "./references.js";
3
+ //#region src/definition/pins/conditions.ts
4
+ /** What a step's status can be, as `$states.context.Steps.<name>.Status` reads it. */
5
+ const stepStatuses = [
6
+ "SUCCEEDED",
7
+ "FAILED",
8
+ "TIMED_OUT",
9
+ "ABORTED",
10
+ "SKIPPED"
11
+ ];
12
+ const compareOps = [
13
+ "=",
14
+ "!=",
15
+ ">",
16
+ "<"
17
+ ];
18
+ /** Whether a side is a node of its own rather than a value. */
19
+ const isConditionPart = (side) => "kind" in side;
20
+ const plainStep = (step) => Object.keys(step).every((key) => key === "type" || key === "value" || key === "position");
21
+ const referenceOf = (node) => {
22
+ if (node.type === "variable" && plainStep(node) && typeof node.value === "string" && node.value !== "" && node.value !== "states") return {
23
+ base: { variable: node.value },
24
+ path: []
25
+ };
26
+ if (node.type !== "path" || !node.steps || !node.steps.every(plainStep)) return;
27
+ const [first, ...rest] = node.steps;
28
+ if (first?.type !== "variable" || typeof first.value !== "string" || !rest.every((step) => step.type === "name" && typeof step.value === "string")) return;
29
+ const names = rest.map((step) => step.value);
30
+ if (first.value !== "states") return first.value === "" ? void 0 : {
31
+ base: { variable: first.value },
32
+ path: names
33
+ };
34
+ if (names[0] === "context" && names[1] === "Steps" && names.length > 2) return {
35
+ base: { step: names[2] },
36
+ path: names.slice(3)
37
+ };
38
+ if (names[0] === "context" && names[1] === "Execution" && names[2] === "Input") return {
39
+ base: { input: true },
40
+ path: names.slice(3)
41
+ };
42
+ };
43
+ const operandOf = (node) => {
44
+ if (node.type === "string" || node.type === "number" || node.type === "value" && typeof node.value === "boolean") return { value: node.value };
45
+ const read = referenceOf(node);
46
+ return read && { read };
47
+ };
48
+ const partOf = (node) => {
49
+ if (node.type === "block" && node.expressions?.length === 1) return partOf(node.expressions[0]);
50
+ if (node.type === "binary" && (node.value === "and" || node.value === "or")) {
51
+ const [lhs, rhs] = [sideOf(node.lhs), sideOf(node.rhs)];
52
+ return lhs && rhs && {
53
+ kind: "logic",
54
+ op: node.value,
55
+ sides: [lhs, rhs]
56
+ };
57
+ }
58
+ if (node.type === "binary" && compareOps.includes(node.value)) {
59
+ const [lhs, rhs] = [operandOf(node.lhs), operandOf(node.rhs)];
60
+ return lhs && rhs && {
61
+ kind: "compare",
62
+ op: node.value,
63
+ sides: [lhs, rhs]
64
+ };
65
+ }
66
+ if (node.type === "function" && node.procedure?.type === "variable" && node.procedure.value === "not" && node.arguments?.length === 1) {
67
+ const side = sideOf(node.arguments[0]);
68
+ return side && {
69
+ kind: "not",
70
+ sides: [side]
71
+ };
72
+ }
73
+ };
74
+ const sideOf = (node) => {
75
+ const part = partOf(node);
76
+ if (part) return part;
77
+ const operand = operandOf(node);
78
+ return operand && ("read" in operand || typeof operand.value === "boolean") ? operand : void 0;
79
+ };
80
+ const quoted = (value) => /^[^'\\\x00-\x1f]*$/.test(value) ? `'${value}'` : JSON.stringify(value);
81
+ const operandText = (operand) => {
82
+ if ("read" in operand) return readText(operand.read);
83
+ return typeof operand.value === "string" ? quoted(operand.value) : String(operand.value);
84
+ };
85
+ const sideText = (side, parent, right) => {
86
+ if (!isConditionPart(side)) return operandText(side);
87
+ const text = partText(side);
88
+ if (side.kind !== "logic") return text;
89
+ return parent === "and" && side.op === "or" || right && side.op === parent ? `(${text})` : text;
90
+ };
91
+ const partText = (part) => {
92
+ if (part.kind === "compare") return `${operandText(part.sides[0])} ${part.op} ${operandText(part.sides[1])}`;
93
+ if (part.kind === "logic") return `${sideText(part.sides[0], part.op, false)} ${part.op} ${sideText(part.sides[1], part.op, true)}`;
94
+ const [side] = part.sides;
95
+ return `$not(${isConditionPart(side) ? partText(side) : operandText(side)})`;
96
+ };
97
+ /** The Condition a node and what it takes write: `{% $states.context.Steps.Save.Status = 'SUCCEEDED' %}`. */
98
+ const conditionValue = (part) => `{% ${partText(part)} %}`;
99
+ /**
100
+ * A Condition taken apart into nodes, when it is a Comparison, an And, an Or or a Not of values and reads by name and
101
+ * writing those nodes back gives it exactly as it is; undefined for any other, such as one that computes, or is spaced
102
+ * or bracketed otherwise, which stays an expression, so no Condition is ever rewritten.
103
+ */
104
+ const conditionParts = (value) => {
105
+ const source = expressionSource(value);
106
+ if (source === void 0) return;
107
+ const parsed = parse(source);
108
+ if ("error" in parsed) return;
109
+ const part = partOf(parsed.expression.ast());
110
+ return part && conditionValue(part) === value ? part : void 0;
111
+ };
112
+ //#endregion
113
+ export { conditionParts, conditionValue, isConditionPart, stepStatuses };
package/dist/index.d.ts CHANGED
@@ -9,6 +9,7 @@ import { dataflowDefinitionSchema, definitionSchema } from "./definition/schema.
9
9
  import { DefinitionParts, definitionFromParts, partOfProblem, partsOfDefinition } from "./definition/parts.js";
10
10
  import { expressionSource } from "./definition/expressions.js";
11
11
  import { PinKind, PinType, fits, pinType, pinTypeText } from "./definition/pins/pin-type.js";
12
+ import { CompareOp, ConditionOperand, ConditionPart, ConditionSide, conditionParts, conditionValue, isConditionPart, stepStatuses } from "./definition/pins/conditions.js";
12
13
  import { definitionWarnings } from "./definition/check-warnings.js";
13
14
  import { allStates, blockDefinition, findBlock, innerMachine } from "./definition/inner.js";
14
15
  import { resources, usedConnections } from "./definition/used-connections.js";
@@ -41,4 +42,4 @@ import { CompletedVersion, JobCompletion, jobAnswer, jobErrors } from "./runners
41
42
  import { BuildReport, JobBuild, JobFile, RunnerJob, RunnerOrder, buildKind, buildStatuses, fileInputName, fileProperties } from "./runners/job-contract.js";
42
43
  import { customPlugin, customStepOf } from "./plugin/custom-step-id.js";
43
44
  import { CustomStepBuildStatus, CustomStepManifest, CustomStepVersion, ManifestProblem, customStepEntry, customStepTestDefinition, customStepTestState, latestCustomSteps, manifestProblems, withCustomSteps } from "./plugin/custom-steps.js";
44
- export { type AnswerRefusal, type BlockCache, type BlockRun, type BlockRunStore, type BlockShare, type BlockState, type BuildReport, type CacheCall, type CacheEntry, type CacheIdentity, type CatalogEntry, type Catcher, type CheckOptions, type Checkpoint, type ChoiceRule, type ChoiceState, type CompletedVersion, type ConnectionHeader, type ConnectionHeaders, type ConnectionSupport, type CustomStepBuildStatus, type CustomStepJob, type CustomStepJobs, type CustomStepManifest, type CustomStepVersion, type Definition, type DefinitionParts, type Dependencies, type EarlierCheckpoint, type ErrorOutput, type JobBuild, type JobCompletion, type JobFile, type KeptAnswer, type KeyShape, type KnownRunner, type LoadedPlugin, type LoadedRun, type Machine, type ManifestProblem, type MapState, type MatchSettings, type Order, type PinKind, type PinSchemas, type PinType, type Placement, type PollingRunner, type Problem, type QueuedJob, type ReadBase, type RecordSchemas, type RecordUse, type Redactor, type Reference, type ReplayedStep, type RerunFrom, type Retrier, type RunChange, type RunStatus, type RunStore, type Runner, type RunnerJob, type RunnerOrder, type RunnerPort, type RunnerState, type SegmentInput, type SegmentQueue, type State, type StateMachine, type StepCacheStore, StepError, type StepLog, type StepRecord, type StepStatus, type StepWiring, type TaskAnswer, type TaskContext, type TaskHandler, type TaskHandlers, type TaskState, type TaskTokenStore, type Tier, type TraceMode, type TraceSink, type Trigger, type TriggerCheck, type TypeCatalog, type TypeEntry, type Unavailable, type WaitingTask, allStates, assignedNames, blockDefinition, buildKind, buildStatuses, checkDefinition, connectionUnavailable, createRunner, customPlugin, customStepEntry, customStepOf, customStepTestDefinition, customStepTestState, dataflowDefinitionSchema, definitionFromParts, definitionSchema, definitionWarnings, dependsOn, expressionReferences, expressionSource, fileInputName, fileProperties, findBlock, fits, heldBackLog, importStateMachine, innerMachine, inputSchema, jobAnswer, jobErrors, jobKind, keptAssigned, latestCustomSteps, limits, loadPlugins, machineDependencies, manifestProblems, matchJobs, nestingDepth, orderOf, parseReference, partOfProblem, partsOfDefinition, pinType, pinTypeText, problemText, readText, redacted, referenceSchema, referenceValue, rerunCheckpoint, rerunFrom, rerunProblem, resolveSchema, resources, resultRead, resultSchema, resultState, runSegment, schemaAt, secretRedactor, shortestSecret, stepHandlers, stepStatusSchema, taskResource, taskTokenHash, tierOf, tokenPattern, triggerChecks, triggerSchema, typeCatalog, typeList, usedConnections, waitSuffix, waitsForToken, withCustomSteps };
45
+ export { type AnswerRefusal, type BlockCache, type BlockRun, type BlockRunStore, type BlockShare, type BlockState, type BuildReport, type CacheCall, type CacheEntry, type CacheIdentity, type CatalogEntry, type Catcher, type CheckOptions, type Checkpoint, type ChoiceRule, type ChoiceState, type CompareOp, type CompletedVersion, type ConditionOperand, type ConditionPart, type ConditionSide, type ConnectionHeader, type ConnectionHeaders, type ConnectionSupport, type CustomStepBuildStatus, type CustomStepJob, type CustomStepJobs, type CustomStepManifest, type CustomStepVersion, type Definition, type DefinitionParts, type Dependencies, type EarlierCheckpoint, type ErrorOutput, type JobBuild, type JobCompletion, type JobFile, type KeptAnswer, type KeyShape, type KnownRunner, type LoadedPlugin, type LoadedRun, type Machine, type ManifestProblem, type MapState, type MatchSettings, type Order, type PinKind, type PinSchemas, type PinType, type Placement, type PollingRunner, type Problem, type QueuedJob, type ReadBase, type RecordSchemas, type RecordUse, type Redactor, type Reference, type ReplayedStep, type RerunFrom, type Retrier, type RunChange, type RunStatus, type RunStore, type Runner, type RunnerJob, type RunnerOrder, type RunnerPort, type RunnerState, type SegmentInput, type SegmentQueue, type State, type StateMachine, type StepCacheStore, StepError, type StepLog, type StepRecord, type StepStatus, type StepWiring, type TaskAnswer, type TaskContext, type TaskHandler, type TaskHandlers, type TaskState, type TaskTokenStore, type Tier, type TraceMode, type TraceSink, type Trigger, type TriggerCheck, type TypeCatalog, type TypeEntry, type Unavailable, type WaitingTask, allStates, assignedNames, blockDefinition, buildKind, buildStatuses, checkDefinition, conditionParts, conditionValue, connectionUnavailable, createRunner, customPlugin, customStepEntry, customStepOf, customStepTestDefinition, customStepTestState, dataflowDefinitionSchema, definitionFromParts, definitionSchema, definitionWarnings, dependsOn, expressionReferences, expressionSource, fileInputName, fileProperties, findBlock, fits, heldBackLog, importStateMachine, innerMachine, inputSchema, isConditionPart, jobAnswer, jobErrors, jobKind, keptAssigned, latestCustomSteps, limits, loadPlugins, machineDependencies, manifestProblems, matchJobs, nestingDepth, orderOf, parseReference, partOfProblem, partsOfDefinition, pinType, pinTypeText, problemText, readText, redacted, referenceSchema, referenceValue, rerunCheckpoint, rerunFrom, rerunProblem, resolveSchema, resources, resultRead, resultSchema, resultState, runSegment, schemaAt, secretRedactor, shortestSecret, stepHandlers, stepStatusSchema, stepStatuses, taskResource, taskTokenHash, tierOf, tokenPattern, triggerChecks, triggerSchema, typeCatalog, typeList, usedConnections, waitSuffix, waitsForToken, withCustomSteps };
package/dist/index.js CHANGED
@@ -16,6 +16,7 @@ import { orderOf } from "./definition/types.js";
16
16
  import { customPlugin, customStepOf } from "./plugin/custom-step-id.js";
17
17
  import { checkDefinition } from "./definition/check-definition.js";
18
18
  import { definitionFromParts, partOfProblem, partsOfDefinition } from "./definition/parts.js";
19
+ import { conditionParts, conditionValue, isConditionPart, stepStatuses } from "./definition/pins/conditions.js";
19
20
  import { definitionWarnings } from "./definition/check-warnings.js";
20
21
  import { importStateMachine } from "./definition/import/import-machine.js";
21
22
  import { StepError } from "./run/errors.js";
@@ -36,4 +37,4 @@ import { connectionUnavailable } from "./plugin/connection-availability.js";
36
37
  import { typeCatalog } from "./plugin/type-catalog.js";
37
38
  import { jobKind, matchJobs, tierOf } from "./runners/match-jobs.js";
38
39
  import { jobAnswer, jobErrors } from "./runners/job-answer.js";
39
- export { StepError, allStates, assignedNames, blockDefinition, buildKind, buildStatuses, checkDefinition, connectionUnavailable, createRunner, customPlugin, customStepEntry, customStepOf, customStepTestDefinition, customStepTestState, dataflowDefinitionSchema, definitionFromParts, definitionSchema, definitionWarnings, dependsOn, expressionReferences, expressionSource, fileInputName, fileProperties, findBlock, fits, heldBackLog, importStateMachine, innerMachine, inputSchema, jobAnswer, jobErrors, jobKind, keptAssigned, latestCustomSteps, limits, loadPlugins, machineDependencies, manifestProblems, matchJobs, nestingDepth, orderOf, parseReference, partOfProblem, partsOfDefinition, pinType, pinTypeText, problemText, readText, redacted, referenceSchema, referenceValue, rerunCheckpoint, rerunFrom, rerunProblem, resolveSchema, resources, resultRead, resultSchema, resultState, runSegment, schemaAt, secretRedactor, shortestSecret, stepHandlers, stepStatusSchema, taskResource, taskTokenHash, tierOf, tokenPattern, triggerChecks, triggerSchema, typeCatalog, typeList, usedConnections, waitSuffix, waitsForToken, withCustomSteps };
40
+ export { StepError, allStates, assignedNames, blockDefinition, buildKind, buildStatuses, checkDefinition, conditionParts, conditionValue, connectionUnavailable, createRunner, customPlugin, customStepEntry, customStepOf, customStepTestDefinition, customStepTestState, dataflowDefinitionSchema, definitionFromParts, definitionSchema, definitionWarnings, dependsOn, expressionReferences, expressionSource, fileInputName, fileProperties, findBlock, fits, heldBackLog, importStateMachine, innerMachine, inputSchema, isConditionPart, jobAnswer, jobErrors, jobKind, keptAssigned, latestCustomSteps, limits, loadPlugins, machineDependencies, manifestProblems, matchJobs, nestingDepth, orderOf, parseReference, partOfProblem, partsOfDefinition, pinType, pinTypeText, problemText, readText, redacted, referenceSchema, referenceValue, rerunCheckpoint, rerunFrom, rerunProblem, resolveSchema, resources, resultRead, resultSchema, resultState, runSegment, schemaAt, secretRedactor, shortestSecret, stepHandlers, stepStatusSchema, stepStatuses, taskResource, taskTokenHash, tierOf, tokenPattern, triggerChecks, triggerSchema, typeCatalog, typeList, usedConnections, waitSuffix, waitsForToken, withCustomSteps };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@protobase/workflows",
3
- "version": "0.100.22",
3
+ "version": "0.100.24",
4
4
  "description": "Workflows as state machines with JSONata expressions: their check, a runner that saves only what a run needs to go on and traces every step, and the plugin interface for trigger and step types.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {