@serverlessworkflow/sdk 1.0.3-alpha1 → 1.0.3-alpha3
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/index.cjs +40 -46
- package/index.cjs.map +1 -1
- package/index.d.cts.map +1 -1
- package/index.d.mts.map +1 -1
- package/index.mjs +40 -47
- package/index.mjs.map +1 -1
- package/index.umd.js +3832 -2448
- package/index.umd.js.map +1 -1
- package/index.umd.min.js +37 -37
- package/index.umd.min.js.map +1 -1
- package/package.json +5 -3
- /package/{chunk.mjs → rolldown-runtime.mjs} +0 -0
package/index.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { t as __exportAll } from "./
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime.mjs";
|
|
2
|
+
import satisfies from "semver/functions/satisfies.js";
|
|
2
3
|
import Ajv from "ajv/dist/2020.js";
|
|
3
4
|
import addFormats from "ajv-formats";
|
|
4
5
|
import * as yaml from "js-yaml";
|
|
@@ -107,11 +108,12 @@ var ArrayHydrator = class extends Array {
|
|
|
107
108
|
};
|
|
108
109
|
//#endregion
|
|
109
110
|
//#region package.json
|
|
110
|
-
var
|
|
111
|
+
var supportedDslVersions = ">=1.0.0 <=1.0.3";
|
|
111
112
|
//#endregion
|
|
112
113
|
//#region src/lib/hooks/workflow-hooks.ts
|
|
113
114
|
const WorkflowHooks = { preValidation(instance) {
|
|
114
|
-
|
|
115
|
+
const dsl = instance?.document?.dsl;
|
|
116
|
+
if (!(typeof dsl === "string" && satisfies(dsl, supportedDslVersions, { includePrerelease: true }))) throw new Error(`'Workflow' is invalid - The DSL version of the workflow '${dsl}' does not satisfy the DSL version range supported by this SDK '${supportedDslVersions}'.`);
|
|
115
117
|
} };
|
|
116
118
|
//#endregion
|
|
117
119
|
//#region src/lib/lifecycle-hooks.ts
|
|
@@ -6630,7 +6632,7 @@ const _ExternalScript = class ExternalScript extends ObjectHydrator {
|
|
|
6630
6632
|
return getLifecycleHooks("ExternalScript")?.normalize?.(copy) || copy;
|
|
6631
6633
|
}
|
|
6632
6634
|
};
|
|
6633
|
-
const _FlowDirective = class FlowDirective
|
|
6635
|
+
const _FlowDirective = class FlowDirective extends ObjectHydrator {
|
|
6634
6636
|
/**
|
|
6635
6637
|
* Instanciates a new instance of the FlowDirective class.
|
|
6636
6638
|
* Initializes properties based on the provided model if it is an object.
|
|
@@ -6646,7 +6648,7 @@ const _FlowDirective = class FlowDirective$1 extends ObjectHydrator {
|
|
|
6646
6648
|
* Throws if invalid.
|
|
6647
6649
|
*/
|
|
6648
6650
|
validate(workflow) {
|
|
6649
|
-
validate("FlowDirective", new FlowDirective
|
|
6651
|
+
validate("FlowDirective", new FlowDirective(this), workflow);
|
|
6650
6652
|
}
|
|
6651
6653
|
/**
|
|
6652
6654
|
* Normalizes the current instance of the FlowDirective.
|
|
@@ -6655,7 +6657,7 @@ const _FlowDirective = class FlowDirective$1 extends ObjectHydrator {
|
|
|
6655
6657
|
* @returns A normalized version of the FlowDirective instance.
|
|
6656
6658
|
*/
|
|
6657
6659
|
normalize() {
|
|
6658
|
-
const copy = new FlowDirective
|
|
6660
|
+
const copy = new FlowDirective(this);
|
|
6659
6661
|
return getLifecycleHooks("FlowDirective")?.normalize?.(copy) || copy;
|
|
6660
6662
|
}
|
|
6661
6663
|
};
|
|
@@ -8419,7 +8421,6 @@ const entrySuffix = "-entry-node";
|
|
|
8419
8421
|
const exitSuffix = "-exit-node";
|
|
8420
8422
|
const rootId = "root";
|
|
8421
8423
|
const doReference = "/do";
|
|
8422
|
-
const forReference = "/for";
|
|
8423
8424
|
const catchReference = "/catch";
|
|
8424
8425
|
const branchReference = "/fork/branches";
|
|
8425
8426
|
const tryReference = "/try";
|
|
@@ -8449,15 +8450,6 @@ let GraphNodeType = /* @__PURE__ */ function(GraphNodeType) {
|
|
|
8449
8450
|
return GraphNodeType;
|
|
8450
8451
|
}({});
|
|
8451
8452
|
/**
|
|
8452
|
-
* Enumeration of possible workflow flow directives.
|
|
8453
|
-
*/
|
|
8454
|
-
var FlowDirective = /* @__PURE__ */ function(FlowDirective) {
|
|
8455
|
-
FlowDirective["Exit"] = "exit";
|
|
8456
|
-
FlowDirective["End"] = "end";
|
|
8457
|
-
FlowDirective["Continue"] = "continue";
|
|
8458
|
-
return FlowDirective;
|
|
8459
|
-
}(FlowDirective || {});
|
|
8460
|
-
/**
|
|
8461
8453
|
* Converts an array of TaskItem objects into a Map for easy lookup.
|
|
8462
8454
|
*
|
|
8463
8455
|
* @param tasksList An array of TaskItem objects.
|
|
@@ -8491,12 +8483,12 @@ function initGraph(type, id = rootId, task = void 0, label = void 0, parent = vo
|
|
|
8491
8483
|
edges: []
|
|
8492
8484
|
};
|
|
8493
8485
|
const entryNode = {
|
|
8494
|
-
type: id === rootId ?
|
|
8486
|
+
type: id === rootId ? "start" : "entry",
|
|
8495
8487
|
id: `${id}${entrySuffix}`,
|
|
8496
8488
|
parent: graph
|
|
8497
8489
|
};
|
|
8498
8490
|
const exitNode = {
|
|
8499
|
-
type: id === rootId ?
|
|
8491
|
+
type: id === rootId ? "end" : "exit",
|
|
8500
8492
|
id: `${id}${exitSuffix}`,
|
|
8501
8493
|
parent: graph
|
|
8502
8494
|
};
|
|
@@ -8515,23 +8507,23 @@ function initGraph(type, id = rootId, task = void 0, label = void 0, parent = vo
|
|
|
8515
8507
|
*/
|
|
8516
8508
|
function getNextTask(tasksList, taskName = void 0, transition = void 0) {
|
|
8517
8509
|
if (!tasksList?.size) return {
|
|
8518
|
-
name:
|
|
8510
|
+
name: "exit",
|
|
8519
8511
|
index: -1
|
|
8520
8512
|
};
|
|
8521
8513
|
const currentTask = tasksList.get(taskName || "");
|
|
8522
8514
|
transition = transition || currentTask?.then || "";
|
|
8523
|
-
if (transition ==
|
|
8515
|
+
if (transition == "end" || transition == "exit") return {
|
|
8524
8516
|
name: transition,
|
|
8525
8517
|
index: -1
|
|
8526
8518
|
};
|
|
8527
8519
|
let index = 0;
|
|
8528
|
-
if (transition && transition !=
|
|
8520
|
+
if (transition && transition != "continue") {
|
|
8529
8521
|
index = Array.from(tasksList.keys()).indexOf(transition);
|
|
8530
8522
|
if (index === -1) throw new Error(`Unable to find task to transition to '${transition}' from '${taskName}'`);
|
|
8531
8523
|
} else if (currentTask) {
|
|
8532
8524
|
index = Array.from(tasksList.values()).indexOf(currentTask) + 1;
|
|
8533
8525
|
if (index >= tasksList.size) return {
|
|
8534
|
-
name:
|
|
8526
|
+
name: "exit",
|
|
8535
8527
|
index: -1
|
|
8536
8528
|
};
|
|
8537
8529
|
}
|
|
@@ -8571,10 +8563,10 @@ function buildTransition(sourceNode, transition, context) {
|
|
|
8571
8563
|
taskName: transition.name
|
|
8572
8564
|
});
|
|
8573
8565
|
buildEdge(context.graph, context.knownEdges, exitAnchor, targetNode.entryNode || targetNode, transition.label);
|
|
8574
|
-
} else if (transition.name ===
|
|
8566
|
+
} else if (transition.name === "exit") {
|
|
8575
8567
|
if (!context.graph.exitNode) throw new Error(`Missing exit node on graph id '${context.graph.id}'`);
|
|
8576
8568
|
buildEdge(context.graph, context.knownEdges, exitAnchor, context.graph.exitNode, transition.label);
|
|
8577
|
-
} else if (transition.name ===
|
|
8569
|
+
} else if (transition.name === "end") buildEdge(context.graph, context.knownEdges, exitAnchor, getEndNode(context.graph), transition.label);
|
|
8578
8570
|
else throw new Error("Invalid transition");
|
|
8579
8571
|
}
|
|
8580
8572
|
/**
|
|
@@ -8588,7 +8580,7 @@ function buildTransitions(sourceNode, context) {
|
|
|
8588
8580
|
transitions.push(nextTransition);
|
|
8589
8581
|
while (nextTransition?.task?.if) {
|
|
8590
8582
|
nextTransition.label = nextTransition?.task?.if;
|
|
8591
|
-
nextTransition = getNextTask(context.taskList, nextTransition.name,
|
|
8583
|
+
nextTransition = getNextTask(context.taskList, nextTransition.name, "continue");
|
|
8592
8584
|
transitions.push(nextTransition);
|
|
8593
8585
|
}
|
|
8594
8586
|
transitions.filter((transition, index) => transitions.findIndex((t) => t.index === transition.index && t.name === transition.name && t.task === transition.task) === index).forEach((transition) => buildTransition(sourceNode, transition, context));
|
|
@@ -8642,7 +8634,7 @@ function buildGenericTaskNode(task, type, context) {
|
|
|
8642
8634
|
* @returns A graph node for the provided task
|
|
8643
8635
|
*/
|
|
8644
8636
|
function buildCallTaskNode(task, context) {
|
|
8645
|
-
return buildGenericTaskNode(task,
|
|
8637
|
+
return buildGenericTaskNode(task, "call", context);
|
|
8646
8638
|
}
|
|
8647
8639
|
/**
|
|
8648
8640
|
* Builds a graph for the provided do task
|
|
@@ -8651,7 +8643,7 @@ function buildCallTaskNode(task, context) {
|
|
|
8651
8643
|
* @returns A graph for the provided task
|
|
8652
8644
|
*/
|
|
8653
8645
|
function buildDoTaskNode(task, context) {
|
|
8654
|
-
const subgraph = initGraph(
|
|
8646
|
+
const subgraph = initGraph("do", context.taskReference, task, context.taskName, context.graph);
|
|
8655
8647
|
const doContext = {
|
|
8656
8648
|
...context,
|
|
8657
8649
|
graph: subgraph,
|
|
@@ -8671,7 +8663,7 @@ function buildDoTaskNode(task, context) {
|
|
|
8671
8663
|
* @returns A graph node for the provided task
|
|
8672
8664
|
*/
|
|
8673
8665
|
function buildEmitTaskNode(task, context) {
|
|
8674
|
-
return buildGenericTaskNode(task,
|
|
8666
|
+
return buildGenericTaskNode(task, "emit", context);
|
|
8675
8667
|
}
|
|
8676
8668
|
/**
|
|
8677
8669
|
* Builds a graph for the provided for task
|
|
@@ -8680,11 +8672,11 @@ function buildEmitTaskNode(task, context) {
|
|
|
8680
8672
|
* @returns A graph for the provided task
|
|
8681
8673
|
*/
|
|
8682
8674
|
function buildForTaskNode(task, context) {
|
|
8683
|
-
const subgraph = initGraph(
|
|
8675
|
+
const subgraph = initGraph("for", context.taskReference, task, context.taskName, context.graph);
|
|
8684
8676
|
const forContext = {
|
|
8685
8677
|
...context,
|
|
8686
8678
|
graph: subgraph,
|
|
8687
|
-
taskListReference: subgraph.id +
|
|
8679
|
+
taskListReference: subgraph.id + "/for/do",
|
|
8688
8680
|
taskList: mapTasks(task.do),
|
|
8689
8681
|
taskName: void 0
|
|
8690
8682
|
};
|
|
@@ -8700,7 +8692,7 @@ function buildForTaskNode(task, context) {
|
|
|
8700
8692
|
* @returns A graph for the provided task
|
|
8701
8693
|
*/
|
|
8702
8694
|
function buildForkTaskNode(task, context) {
|
|
8703
|
-
const subgraph = initGraph(
|
|
8695
|
+
const subgraph = initGraph("fork", context.taskReference, task, context.taskName, context.graph);
|
|
8704
8696
|
for (let i = 0, c = task.fork?.branches.length || 0; i < c; i++) {
|
|
8705
8697
|
const branchItem = task.fork?.branches[i];
|
|
8706
8698
|
if (!branchItem) continue;
|
|
@@ -8728,7 +8720,7 @@ function buildForkTaskNode(task, context) {
|
|
|
8728
8720
|
* @returns A graph node for the provided task
|
|
8729
8721
|
*/
|
|
8730
8722
|
function buildListenTaskNode(task, context) {
|
|
8731
|
-
return buildGenericTaskNode(task,
|
|
8723
|
+
return buildGenericTaskNode(task, "listen", context);
|
|
8732
8724
|
}
|
|
8733
8725
|
/**
|
|
8734
8726
|
* Builds a graph node for the provided rasie task
|
|
@@ -8737,7 +8729,7 @@ function buildListenTaskNode(task, context) {
|
|
|
8737
8729
|
* @returns A graph node for the provided task
|
|
8738
8730
|
*/
|
|
8739
8731
|
function buildRaiseTaskNode(task, context) {
|
|
8740
|
-
return buildGenericTaskNode(task,
|
|
8732
|
+
return buildGenericTaskNode(task, "raise", context);
|
|
8741
8733
|
}
|
|
8742
8734
|
/**
|
|
8743
8735
|
* Builds a graph node for the provided run task
|
|
@@ -8746,7 +8738,7 @@ function buildRaiseTaskNode(task, context) {
|
|
|
8746
8738
|
* @returns A graph node for the provided task
|
|
8747
8739
|
*/
|
|
8748
8740
|
function buildRunTaskNode(task, context) {
|
|
8749
|
-
return buildGenericTaskNode(task,
|
|
8741
|
+
return buildGenericTaskNode(task, "run", context);
|
|
8750
8742
|
}
|
|
8751
8743
|
/**
|
|
8752
8744
|
* Builds a graph node for the provided set task
|
|
@@ -8755,7 +8747,7 @@ function buildRunTaskNode(task, context) {
|
|
|
8755
8747
|
* @returns A graph node for the provided task
|
|
8756
8748
|
*/
|
|
8757
8749
|
function buildSetTaskNode(task, context) {
|
|
8758
|
-
return buildGenericTaskNode(task,
|
|
8750
|
+
return buildGenericTaskNode(task, "set", context);
|
|
8759
8751
|
}
|
|
8760
8752
|
/**
|
|
8761
8753
|
* Builds a graph node for the provided switch task
|
|
@@ -8764,7 +8756,7 @@ function buildSetTaskNode(task, context) {
|
|
|
8764
8756
|
* @returns A graph node for the provided task
|
|
8765
8757
|
*/
|
|
8766
8758
|
function buildSwitchTaskNode(task, context) {
|
|
8767
|
-
const node = buildGenericTaskNode(task,
|
|
8759
|
+
const node = buildGenericTaskNode(task, "switch", context);
|
|
8768
8760
|
let hasDefaultCase = false;
|
|
8769
8761
|
task.switch?.forEach((switchItem) => {
|
|
8770
8762
|
const [caseName, switchCase] = Object.entries(switchItem)[0];
|
|
@@ -8783,8 +8775,8 @@ function buildSwitchTaskNode(task, context) {
|
|
|
8783
8775
|
* @returns A graph for the provided task
|
|
8784
8776
|
*/
|
|
8785
8777
|
function buildTryCatchTaskNode(task, context) {
|
|
8786
|
-
const containerSubgraph = initGraph(
|
|
8787
|
-
const trySubgraph = initGraph(
|
|
8778
|
+
const containerSubgraph = initGraph("try-catch", context.taskReference, task, context.taskName, context.graph);
|
|
8779
|
+
const trySubgraph = initGraph("try", context.taskReference + tryReference, task, context.taskName + " (try)", containerSubgraph);
|
|
8788
8780
|
if (!containerSubgraph.entryNode) throw new Error(`Missing 'entryNode' on graph id '${containerSubgraph.id}'`);
|
|
8789
8781
|
if (!trySubgraph.entryNode) throw new Error(`Missing 'entryNode' on graph id '${trySubgraph.id}'`);
|
|
8790
8782
|
buildEdge(containerSubgraph, context.knownEdges, containerSubgraph.entryNode, trySubgraph.entryNode);
|
|
@@ -8800,7 +8792,7 @@ function buildTryCatchTaskNode(task, context) {
|
|
|
8800
8792
|
if (!task.catch?.do?.length) {
|
|
8801
8793
|
const catchNode = {
|
|
8802
8794
|
task,
|
|
8803
|
-
type:
|
|
8795
|
+
type: "catch",
|
|
8804
8796
|
parent: containerSubgraph,
|
|
8805
8797
|
id: context.taskReference + catchReference,
|
|
8806
8798
|
label: context.taskName + " (catch)"
|
|
@@ -8811,7 +8803,7 @@ function buildTryCatchTaskNode(task, context) {
|
|
|
8811
8803
|
buildEdge(containerSubgraph, context.knownEdges, trySubgraph.exitNode, catchNode);
|
|
8812
8804
|
buildEdge(containerSubgraph, context.knownEdges, catchNode, containerSubgraph.exitNode);
|
|
8813
8805
|
} else {
|
|
8814
|
-
const catchSubgraph = initGraph(
|
|
8806
|
+
const catchSubgraph = initGraph("catch", context.taskReference + "/catch/do", task, context.taskName + " (catch)", containerSubgraph);
|
|
8815
8807
|
if (!trySubgraph.exitNode) throw new Error(`Missing 'exitNode' on graph id '${trySubgraph.id}'`);
|
|
8816
8808
|
if (!catchSubgraph.entryNode) throw new Error(`Missing 'entryNode' on graph id '${catchSubgraph.entryNode}'`);
|
|
8817
8809
|
buildEdge(containerSubgraph, context.knownEdges, trySubgraph.exitNode, catchSubgraph.entryNode);
|
|
@@ -8837,7 +8829,7 @@ function buildTryCatchTaskNode(task, context) {
|
|
|
8837
8829
|
* @returns A graph node for the provided task
|
|
8838
8830
|
*/
|
|
8839
8831
|
function buildWaitTaskNode(task, context) {
|
|
8840
|
-
return buildGenericTaskNode(task,
|
|
8832
|
+
return buildGenericTaskNode(task, "wait", context);
|
|
8841
8833
|
}
|
|
8842
8834
|
/**
|
|
8843
8835
|
* Builds an edge between two elements
|
|
@@ -8931,7 +8923,7 @@ function flattenGraph(graph, removePorts = false) {
|
|
|
8931
8923
|
return {
|
|
8932
8924
|
...flatGraph,
|
|
8933
8925
|
edges: remapEdges(flatGraph.edges),
|
|
8934
|
-
nodes: flatGraph.nodes.filter((node) => node.type !==
|
|
8926
|
+
nodes: flatGraph.nodes.filter((node) => node.type !== "entry" && node.type !== "exit")
|
|
8935
8927
|
};
|
|
8936
8928
|
}
|
|
8937
8929
|
/**
|
|
@@ -8941,7 +8933,7 @@ function flattenGraph(graph, removePorts = false) {
|
|
|
8941
8933
|
* @returns A graph representation of the workflow.
|
|
8942
8934
|
*/
|
|
8943
8935
|
function buildGraph(workflow) {
|
|
8944
|
-
const graph = initGraph(
|
|
8936
|
+
const graph = initGraph("root");
|
|
8945
8937
|
if (!graph.entryNode) throw new Error("The root graph should have an entry node.");
|
|
8946
8938
|
buildTransitions(graph.entryNode, {
|
|
8947
8939
|
graph,
|
|
@@ -8996,14 +8988,14 @@ function convertNodeToCode(root, node) {
|
|
|
8996
8988
|
else {
|
|
8997
8989
|
code = node.id;
|
|
8998
8990
|
switch (node.type) {
|
|
8999
|
-
case
|
|
9000
|
-
case
|
|
8991
|
+
case "entry":
|
|
8992
|
+
case "exit":
|
|
9001
8993
|
code += "[ ]:::hidden";
|
|
9002
8994
|
break;
|
|
9003
|
-
case
|
|
8995
|
+
case "start":
|
|
9004
8996
|
code += "(( ))";
|
|
9005
8997
|
break;
|
|
9006
|
-
case
|
|
8998
|
+
case "end":
|
|
9007
8999
|
code += "((( )))";
|
|
9008
9000
|
break;
|
|
9009
9001
|
default: code += `["${node.label || " "}"]`;
|
|
@@ -9035,6 +9027,7 @@ classDef hidden width: 1px, height: 1px;`;
|
|
|
9035
9027
|
* This class takes a workflow definition and converts it into a Mermaid.js-compatible diagram.
|
|
9036
9028
|
*/
|
|
9037
9029
|
var MermaidDiagram = class {
|
|
9030
|
+
workflow;
|
|
9038
9031
|
constructor(workflow) {
|
|
9039
9032
|
this.workflow = workflow;
|
|
9040
9033
|
}
|