@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.cjs
CHANGED
|
@@ -30,6 +30,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
30
30
|
enumerable: true
|
|
31
31
|
}) : target, mod));
|
|
32
32
|
//#endregion
|
|
33
|
+
let semver_functions_satisfies_js = require("semver/functions/satisfies.js");
|
|
34
|
+
semver_functions_satisfies_js = __toESM(semver_functions_satisfies_js);
|
|
33
35
|
let ajv_dist_2020_js = require("ajv/dist/2020.js");
|
|
34
36
|
ajv_dist_2020_js = __toESM(ajv_dist_2020_js);
|
|
35
37
|
let ajv_formats = require("ajv-formats");
|
|
@@ -141,11 +143,12 @@ var ArrayHydrator = class extends Array {
|
|
|
141
143
|
};
|
|
142
144
|
//#endregion
|
|
143
145
|
//#region package.json
|
|
144
|
-
var
|
|
146
|
+
var supportedDslVersions = ">=1.0.0 <=1.0.3";
|
|
145
147
|
//#endregion
|
|
146
148
|
//#region src/lib/hooks/workflow-hooks.ts
|
|
147
149
|
const WorkflowHooks = { preValidation(instance) {
|
|
148
|
-
|
|
150
|
+
const dsl = instance?.document?.dsl;
|
|
151
|
+
if (!(typeof dsl === "string" && (0, semver_functions_satisfies_js.default)(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}'.`);
|
|
149
152
|
} };
|
|
150
153
|
//#endregion
|
|
151
154
|
//#region src/lib/lifecycle-hooks.ts
|
|
@@ -6664,7 +6667,7 @@ const _ExternalScript = class ExternalScript extends ObjectHydrator {
|
|
|
6664
6667
|
return getLifecycleHooks("ExternalScript")?.normalize?.(copy) || copy;
|
|
6665
6668
|
}
|
|
6666
6669
|
};
|
|
6667
|
-
const _FlowDirective = class FlowDirective
|
|
6670
|
+
const _FlowDirective = class FlowDirective extends ObjectHydrator {
|
|
6668
6671
|
/**
|
|
6669
6672
|
* Instanciates a new instance of the FlowDirective class.
|
|
6670
6673
|
* Initializes properties based on the provided model if it is an object.
|
|
@@ -6680,7 +6683,7 @@ const _FlowDirective = class FlowDirective$1 extends ObjectHydrator {
|
|
|
6680
6683
|
* Throws if invalid.
|
|
6681
6684
|
*/
|
|
6682
6685
|
validate(workflow) {
|
|
6683
|
-
validate("FlowDirective", new FlowDirective
|
|
6686
|
+
validate("FlowDirective", new FlowDirective(this), workflow);
|
|
6684
6687
|
}
|
|
6685
6688
|
/**
|
|
6686
6689
|
* Normalizes the current instance of the FlowDirective.
|
|
@@ -6689,7 +6692,7 @@ const _FlowDirective = class FlowDirective$1 extends ObjectHydrator {
|
|
|
6689
6692
|
* @returns A normalized version of the FlowDirective instance.
|
|
6690
6693
|
*/
|
|
6691
6694
|
normalize() {
|
|
6692
|
-
const copy = new FlowDirective
|
|
6695
|
+
const copy = new FlowDirective(this);
|
|
6693
6696
|
return getLifecycleHooks("FlowDirective")?.normalize?.(copy) || copy;
|
|
6694
6697
|
}
|
|
6695
6698
|
};
|
|
@@ -8453,7 +8456,6 @@ const entrySuffix = "-entry-node";
|
|
|
8453
8456
|
const exitSuffix = "-exit-node";
|
|
8454
8457
|
const rootId = "root";
|
|
8455
8458
|
const doReference = "/do";
|
|
8456
|
-
const forReference = "/for";
|
|
8457
8459
|
const catchReference = "/catch";
|
|
8458
8460
|
const branchReference = "/fork/branches";
|
|
8459
8461
|
const tryReference = "/try";
|
|
@@ -8483,15 +8485,6 @@ let GraphNodeType = /* @__PURE__ */ function(GraphNodeType) {
|
|
|
8483
8485
|
return GraphNodeType;
|
|
8484
8486
|
}({});
|
|
8485
8487
|
/**
|
|
8486
|
-
* Enumeration of possible workflow flow directives.
|
|
8487
|
-
*/
|
|
8488
|
-
var FlowDirective = /* @__PURE__ */ function(FlowDirective) {
|
|
8489
|
-
FlowDirective["Exit"] = "exit";
|
|
8490
|
-
FlowDirective["End"] = "end";
|
|
8491
|
-
FlowDirective["Continue"] = "continue";
|
|
8492
|
-
return FlowDirective;
|
|
8493
|
-
}(FlowDirective || {});
|
|
8494
|
-
/**
|
|
8495
8488
|
* Converts an array of TaskItem objects into a Map for easy lookup.
|
|
8496
8489
|
*
|
|
8497
8490
|
* @param tasksList An array of TaskItem objects.
|
|
@@ -8525,12 +8518,12 @@ function initGraph(type, id = rootId, task = void 0, label = void 0, parent = vo
|
|
|
8525
8518
|
edges: []
|
|
8526
8519
|
};
|
|
8527
8520
|
const entryNode = {
|
|
8528
|
-
type: id === rootId ?
|
|
8521
|
+
type: id === rootId ? "start" : "entry",
|
|
8529
8522
|
id: `${id}${entrySuffix}`,
|
|
8530
8523
|
parent: graph
|
|
8531
8524
|
};
|
|
8532
8525
|
const exitNode = {
|
|
8533
|
-
type: id === rootId ?
|
|
8526
|
+
type: id === rootId ? "end" : "exit",
|
|
8534
8527
|
id: `${id}${exitSuffix}`,
|
|
8535
8528
|
parent: graph
|
|
8536
8529
|
};
|
|
@@ -8549,23 +8542,23 @@ function initGraph(type, id = rootId, task = void 0, label = void 0, parent = vo
|
|
|
8549
8542
|
*/
|
|
8550
8543
|
function getNextTask(tasksList, taskName = void 0, transition = void 0) {
|
|
8551
8544
|
if (!tasksList?.size) return {
|
|
8552
|
-
name:
|
|
8545
|
+
name: "exit",
|
|
8553
8546
|
index: -1
|
|
8554
8547
|
};
|
|
8555
8548
|
const currentTask = tasksList.get(taskName || "");
|
|
8556
8549
|
transition = transition || currentTask?.then || "";
|
|
8557
|
-
if (transition ==
|
|
8550
|
+
if (transition == "end" || transition == "exit") return {
|
|
8558
8551
|
name: transition,
|
|
8559
8552
|
index: -1
|
|
8560
8553
|
};
|
|
8561
8554
|
let index = 0;
|
|
8562
|
-
if (transition && transition !=
|
|
8555
|
+
if (transition && transition != "continue") {
|
|
8563
8556
|
index = Array.from(tasksList.keys()).indexOf(transition);
|
|
8564
8557
|
if (index === -1) throw new Error(`Unable to find task to transition to '${transition}' from '${taskName}'`);
|
|
8565
8558
|
} else if (currentTask) {
|
|
8566
8559
|
index = Array.from(tasksList.values()).indexOf(currentTask) + 1;
|
|
8567
8560
|
if (index >= tasksList.size) return {
|
|
8568
|
-
name:
|
|
8561
|
+
name: "exit",
|
|
8569
8562
|
index: -1
|
|
8570
8563
|
};
|
|
8571
8564
|
}
|
|
@@ -8605,10 +8598,10 @@ function buildTransition(sourceNode, transition, context) {
|
|
|
8605
8598
|
taskName: transition.name
|
|
8606
8599
|
});
|
|
8607
8600
|
buildEdge(context.graph, context.knownEdges, exitAnchor, targetNode.entryNode || targetNode, transition.label);
|
|
8608
|
-
} else if (transition.name ===
|
|
8601
|
+
} else if (transition.name === "exit") {
|
|
8609
8602
|
if (!context.graph.exitNode) throw new Error(`Missing exit node on graph id '${context.graph.id}'`);
|
|
8610
8603
|
buildEdge(context.graph, context.knownEdges, exitAnchor, context.graph.exitNode, transition.label);
|
|
8611
|
-
} else if (transition.name ===
|
|
8604
|
+
} else if (transition.name === "end") buildEdge(context.graph, context.knownEdges, exitAnchor, getEndNode(context.graph), transition.label);
|
|
8612
8605
|
else throw new Error("Invalid transition");
|
|
8613
8606
|
}
|
|
8614
8607
|
/**
|
|
@@ -8622,7 +8615,7 @@ function buildTransitions(sourceNode, context) {
|
|
|
8622
8615
|
transitions.push(nextTransition);
|
|
8623
8616
|
while (nextTransition?.task?.if) {
|
|
8624
8617
|
nextTransition.label = nextTransition?.task?.if;
|
|
8625
|
-
nextTransition = getNextTask(context.taskList, nextTransition.name,
|
|
8618
|
+
nextTransition = getNextTask(context.taskList, nextTransition.name, "continue");
|
|
8626
8619
|
transitions.push(nextTransition);
|
|
8627
8620
|
}
|
|
8628
8621
|
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));
|
|
@@ -8676,7 +8669,7 @@ function buildGenericTaskNode(task, type, context) {
|
|
|
8676
8669
|
* @returns A graph node for the provided task
|
|
8677
8670
|
*/
|
|
8678
8671
|
function buildCallTaskNode(task, context) {
|
|
8679
|
-
return buildGenericTaskNode(task,
|
|
8672
|
+
return buildGenericTaskNode(task, "call", context);
|
|
8680
8673
|
}
|
|
8681
8674
|
/**
|
|
8682
8675
|
* Builds a graph for the provided do task
|
|
@@ -8685,7 +8678,7 @@ function buildCallTaskNode(task, context) {
|
|
|
8685
8678
|
* @returns A graph for the provided task
|
|
8686
8679
|
*/
|
|
8687
8680
|
function buildDoTaskNode(task, context) {
|
|
8688
|
-
const subgraph = initGraph(
|
|
8681
|
+
const subgraph = initGraph("do", context.taskReference, task, context.taskName, context.graph);
|
|
8689
8682
|
const doContext = {
|
|
8690
8683
|
...context,
|
|
8691
8684
|
graph: subgraph,
|
|
@@ -8705,7 +8698,7 @@ function buildDoTaskNode(task, context) {
|
|
|
8705
8698
|
* @returns A graph node for the provided task
|
|
8706
8699
|
*/
|
|
8707
8700
|
function buildEmitTaskNode(task, context) {
|
|
8708
|
-
return buildGenericTaskNode(task,
|
|
8701
|
+
return buildGenericTaskNode(task, "emit", context);
|
|
8709
8702
|
}
|
|
8710
8703
|
/**
|
|
8711
8704
|
* Builds a graph for the provided for task
|
|
@@ -8714,11 +8707,11 @@ function buildEmitTaskNode(task, context) {
|
|
|
8714
8707
|
* @returns A graph for the provided task
|
|
8715
8708
|
*/
|
|
8716
8709
|
function buildForTaskNode(task, context) {
|
|
8717
|
-
const subgraph = initGraph(
|
|
8710
|
+
const subgraph = initGraph("for", context.taskReference, task, context.taskName, context.graph);
|
|
8718
8711
|
const forContext = {
|
|
8719
8712
|
...context,
|
|
8720
8713
|
graph: subgraph,
|
|
8721
|
-
taskListReference: subgraph.id +
|
|
8714
|
+
taskListReference: subgraph.id + "/for/do",
|
|
8722
8715
|
taskList: mapTasks(task.do),
|
|
8723
8716
|
taskName: void 0
|
|
8724
8717
|
};
|
|
@@ -8734,7 +8727,7 @@ function buildForTaskNode(task, context) {
|
|
|
8734
8727
|
* @returns A graph for the provided task
|
|
8735
8728
|
*/
|
|
8736
8729
|
function buildForkTaskNode(task, context) {
|
|
8737
|
-
const subgraph = initGraph(
|
|
8730
|
+
const subgraph = initGraph("fork", context.taskReference, task, context.taskName, context.graph);
|
|
8738
8731
|
for (let i = 0, c = task.fork?.branches.length || 0; i < c; i++) {
|
|
8739
8732
|
const branchItem = task.fork?.branches[i];
|
|
8740
8733
|
if (!branchItem) continue;
|
|
@@ -8762,7 +8755,7 @@ function buildForkTaskNode(task, context) {
|
|
|
8762
8755
|
* @returns A graph node for the provided task
|
|
8763
8756
|
*/
|
|
8764
8757
|
function buildListenTaskNode(task, context) {
|
|
8765
|
-
return buildGenericTaskNode(task,
|
|
8758
|
+
return buildGenericTaskNode(task, "listen", context);
|
|
8766
8759
|
}
|
|
8767
8760
|
/**
|
|
8768
8761
|
* Builds a graph node for the provided rasie task
|
|
@@ -8771,7 +8764,7 @@ function buildListenTaskNode(task, context) {
|
|
|
8771
8764
|
* @returns A graph node for the provided task
|
|
8772
8765
|
*/
|
|
8773
8766
|
function buildRaiseTaskNode(task, context) {
|
|
8774
|
-
return buildGenericTaskNode(task,
|
|
8767
|
+
return buildGenericTaskNode(task, "raise", context);
|
|
8775
8768
|
}
|
|
8776
8769
|
/**
|
|
8777
8770
|
* Builds a graph node for the provided run task
|
|
@@ -8780,7 +8773,7 @@ function buildRaiseTaskNode(task, context) {
|
|
|
8780
8773
|
* @returns A graph node for the provided task
|
|
8781
8774
|
*/
|
|
8782
8775
|
function buildRunTaskNode(task, context) {
|
|
8783
|
-
return buildGenericTaskNode(task,
|
|
8776
|
+
return buildGenericTaskNode(task, "run", context);
|
|
8784
8777
|
}
|
|
8785
8778
|
/**
|
|
8786
8779
|
* Builds a graph node for the provided set task
|
|
@@ -8789,7 +8782,7 @@ function buildRunTaskNode(task, context) {
|
|
|
8789
8782
|
* @returns A graph node for the provided task
|
|
8790
8783
|
*/
|
|
8791
8784
|
function buildSetTaskNode(task, context) {
|
|
8792
|
-
return buildGenericTaskNode(task,
|
|
8785
|
+
return buildGenericTaskNode(task, "set", context);
|
|
8793
8786
|
}
|
|
8794
8787
|
/**
|
|
8795
8788
|
* Builds a graph node for the provided switch task
|
|
@@ -8798,7 +8791,7 @@ function buildSetTaskNode(task, context) {
|
|
|
8798
8791
|
* @returns A graph node for the provided task
|
|
8799
8792
|
*/
|
|
8800
8793
|
function buildSwitchTaskNode(task, context) {
|
|
8801
|
-
const node = buildGenericTaskNode(task,
|
|
8794
|
+
const node = buildGenericTaskNode(task, "switch", context);
|
|
8802
8795
|
let hasDefaultCase = false;
|
|
8803
8796
|
task.switch?.forEach((switchItem) => {
|
|
8804
8797
|
const [caseName, switchCase] = Object.entries(switchItem)[0];
|
|
@@ -8817,8 +8810,8 @@ function buildSwitchTaskNode(task, context) {
|
|
|
8817
8810
|
* @returns A graph for the provided task
|
|
8818
8811
|
*/
|
|
8819
8812
|
function buildTryCatchTaskNode(task, context) {
|
|
8820
|
-
const containerSubgraph = initGraph(
|
|
8821
|
-
const trySubgraph = initGraph(
|
|
8813
|
+
const containerSubgraph = initGraph("try-catch", context.taskReference, task, context.taskName, context.graph);
|
|
8814
|
+
const trySubgraph = initGraph("try", context.taskReference + tryReference, task, context.taskName + " (try)", containerSubgraph);
|
|
8822
8815
|
if (!containerSubgraph.entryNode) throw new Error(`Missing 'entryNode' on graph id '${containerSubgraph.id}'`);
|
|
8823
8816
|
if (!trySubgraph.entryNode) throw new Error(`Missing 'entryNode' on graph id '${trySubgraph.id}'`);
|
|
8824
8817
|
buildEdge(containerSubgraph, context.knownEdges, containerSubgraph.entryNode, trySubgraph.entryNode);
|
|
@@ -8834,7 +8827,7 @@ function buildTryCatchTaskNode(task, context) {
|
|
|
8834
8827
|
if (!task.catch?.do?.length) {
|
|
8835
8828
|
const catchNode = {
|
|
8836
8829
|
task,
|
|
8837
|
-
type:
|
|
8830
|
+
type: "catch",
|
|
8838
8831
|
parent: containerSubgraph,
|
|
8839
8832
|
id: context.taskReference + catchReference,
|
|
8840
8833
|
label: context.taskName + " (catch)"
|
|
@@ -8845,7 +8838,7 @@ function buildTryCatchTaskNode(task, context) {
|
|
|
8845
8838
|
buildEdge(containerSubgraph, context.knownEdges, trySubgraph.exitNode, catchNode);
|
|
8846
8839
|
buildEdge(containerSubgraph, context.knownEdges, catchNode, containerSubgraph.exitNode);
|
|
8847
8840
|
} else {
|
|
8848
|
-
const catchSubgraph = initGraph(
|
|
8841
|
+
const catchSubgraph = initGraph("catch", context.taskReference + "/catch/do", task, context.taskName + " (catch)", containerSubgraph);
|
|
8849
8842
|
if (!trySubgraph.exitNode) throw new Error(`Missing 'exitNode' on graph id '${trySubgraph.id}'`);
|
|
8850
8843
|
if (!catchSubgraph.entryNode) throw new Error(`Missing 'entryNode' on graph id '${catchSubgraph.entryNode}'`);
|
|
8851
8844
|
buildEdge(containerSubgraph, context.knownEdges, trySubgraph.exitNode, catchSubgraph.entryNode);
|
|
@@ -8871,7 +8864,7 @@ function buildTryCatchTaskNode(task, context) {
|
|
|
8871
8864
|
* @returns A graph node for the provided task
|
|
8872
8865
|
*/
|
|
8873
8866
|
function buildWaitTaskNode(task, context) {
|
|
8874
|
-
return buildGenericTaskNode(task,
|
|
8867
|
+
return buildGenericTaskNode(task, "wait", context);
|
|
8875
8868
|
}
|
|
8876
8869
|
/**
|
|
8877
8870
|
* Builds an edge between two elements
|
|
@@ -8965,7 +8958,7 @@ function flattenGraph(graph, removePorts = false) {
|
|
|
8965
8958
|
return {
|
|
8966
8959
|
...flatGraph,
|
|
8967
8960
|
edges: remapEdges(flatGraph.edges),
|
|
8968
|
-
nodes: flatGraph.nodes.filter((node) => node.type !==
|
|
8961
|
+
nodes: flatGraph.nodes.filter((node) => node.type !== "entry" && node.type !== "exit")
|
|
8969
8962
|
};
|
|
8970
8963
|
}
|
|
8971
8964
|
/**
|
|
@@ -8975,7 +8968,7 @@ function flattenGraph(graph, removePorts = false) {
|
|
|
8975
8968
|
* @returns A graph representation of the workflow.
|
|
8976
8969
|
*/
|
|
8977
8970
|
function buildGraph(workflow) {
|
|
8978
|
-
const graph = initGraph(
|
|
8971
|
+
const graph = initGraph("root");
|
|
8979
8972
|
if (!graph.entryNode) throw new Error("The root graph should have an entry node.");
|
|
8980
8973
|
buildTransitions(graph.entryNode, {
|
|
8981
8974
|
graph,
|
|
@@ -9030,14 +9023,14 @@ function convertNodeToCode(root, node) {
|
|
|
9030
9023
|
else {
|
|
9031
9024
|
code = node.id;
|
|
9032
9025
|
switch (node.type) {
|
|
9033
|
-
case
|
|
9034
|
-
case
|
|
9026
|
+
case "entry":
|
|
9027
|
+
case "exit":
|
|
9035
9028
|
code += "[ ]:::hidden";
|
|
9036
9029
|
break;
|
|
9037
|
-
case
|
|
9030
|
+
case "start":
|
|
9038
9031
|
code += "(( ))";
|
|
9039
9032
|
break;
|
|
9040
|
-
case
|
|
9033
|
+
case "end":
|
|
9041
9034
|
code += "((( )))";
|
|
9042
9035
|
break;
|
|
9043
9036
|
default: code += `["${node.label || " "}"]`;
|
|
@@ -9069,6 +9062,7 @@ classDef hidden width: 1px, height: 1px;`;
|
|
|
9069
9062
|
* This class takes a workflow definition and converts it into a Mermaid.js-compatible diagram.
|
|
9070
9063
|
*/
|
|
9071
9064
|
var MermaidDiagram = class {
|
|
9065
|
+
workflow;
|
|
9072
9066
|
constructor(workflow) {
|
|
9073
9067
|
this.workflow = workflow;
|
|
9074
9068
|
}
|