otomato-sdk 2.0.50 → 2.0.52
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.
|
@@ -1,81 +1,67 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import ELK from 'elkjs/lib/elk.bundled.js';
|
|
11
|
-
export const xSpacing = 700; // similar to Dagre’s node separation
|
|
1
|
+
// Note: Using 'dagre' for layered DAG layout
|
|
2
|
+
import * as dagre from '@dagrejs/dagre';
|
|
3
|
+
// or: import * as dagre from 'dagre';
|
|
4
|
+
export const xSpacing = 700; // used by dagre as node separation
|
|
12
5
|
export const ySpacing = 75;
|
|
13
|
-
export const ROOT_X = 400; //
|
|
6
|
+
export const ROOT_X = 400; // we’ll keep references, but Dagre decides actual positions
|
|
14
7
|
export const ROOT_Y = 120;
|
|
15
|
-
// Create a single ELK instance for reuse
|
|
16
|
-
const elk = new ELK();
|
|
17
8
|
/**
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* 4) It calls elk.layout() (asynchronously) to compute positions.
|
|
25
|
-
* 5) It then updates each node in workflow.nodes with the computed positions.
|
|
26
|
-
*
|
|
27
|
-
* Note: ELK returns (x,y) for the top-left of each node’s bounding box.
|
|
28
|
-
* If your SDK expects center positions, we adjust by adding half the width/height.
|
|
9
|
+
* Dagre-based layout for the “top-down” pass. We’re effectively ignoring the old
|
|
10
|
+
* manual code. Instead, we:
|
|
11
|
+
* 1) Build a dagre graph
|
|
12
|
+
* 2) Add all nodes & edges
|
|
13
|
+
* 3) dagre.layout(g)
|
|
14
|
+
* 4) Extract positions & write them back to workflow.nodes
|
|
29
15
|
*/
|
|
30
16
|
export function positionWorkflowNodes(workflow) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
17
|
+
// 1) Create a new directed graph
|
|
18
|
+
// doc: https://github.com/dagrejs/dagre
|
|
19
|
+
const g = new dagre.graphlib.Graph({ multigraph: false, compound: false });
|
|
20
|
+
g.setGraph({
|
|
21
|
+
// Some layout options:
|
|
22
|
+
rankdir: 'TB', // "top-bottom" layering
|
|
23
|
+
nodesep: xSpacing * 0.5, // horizontal spacing
|
|
24
|
+
ranksep: ySpacing, // vertical spacing between levels
|
|
25
|
+
marginx: 20, // how much margin to leave around the left/right
|
|
26
|
+
marginy: 20, // how much margin to leave around the top/bottom
|
|
27
|
+
});
|
|
28
|
+
g.setDefaultEdgeLabel(() => ({}));
|
|
29
|
+
// 2) Add nodes to the graph
|
|
30
|
+
// Dagre requires each node have an id and some approximate width/height
|
|
31
|
+
workflow.nodes.forEach((node) => {
|
|
32
|
+
const nodeId = node.getRef();
|
|
33
|
+
// For a typical text-based node, approximate width & height
|
|
34
|
+
g.setNode(nodeId, {
|
|
35
|
+
label: nodeId,
|
|
36
|
+
width: 100,
|
|
37
|
+
height: 50
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
// 3) Add edges
|
|
41
|
+
// Dagre identifies edges by (sourceId, targetId). We don’t need labels for layout,
|
|
42
|
+
// but we can store them if we want. If you rely on “true/false” ordering, we can tweak
|
|
43
|
+
// e.g. use edge label as a tie-break. (See advanced docs.)
|
|
44
|
+
workflow.edges.forEach((edge) => {
|
|
45
|
+
var _a;
|
|
46
|
+
const fromId = edge.source.getRef();
|
|
47
|
+
const toId = edge.target.getRef();
|
|
48
|
+
g.setEdge(fromId, toId, { label: (_a = edge.label) !== null && _a !== void 0 ? _a : '' });
|
|
49
|
+
});
|
|
50
|
+
// 4) Run Dagre layout
|
|
51
|
+
dagre.layout(g);
|
|
52
|
+
// 5) Extract positions from Dagre graph and store them back to your Node objects
|
|
53
|
+
g.nodes().forEach((nodeId) => {
|
|
54
|
+
const dagreNode = g.node(nodeId); // { x, y, width, height, ... }
|
|
55
|
+
const nodeObj = workflow.nodes.find((n) => n.getRef() === nodeId);
|
|
56
|
+
if (!nodeObj || !dagreNode)
|
|
57
|
+
return;
|
|
58
|
+
// Store x,y in your node’s position
|
|
59
|
+
nodeObj.setPosition(dagreNode.x, dagreNode.y);
|
|
74
60
|
});
|
|
75
61
|
}
|
|
76
62
|
/**
|
|
77
|
-
*
|
|
78
|
-
*
|
|
63
|
+
* We keep these helper functions the same for external usage (if your code or tests need them),
|
|
64
|
+
* but we’re not actively using them in the new Dagre-based layout.
|
|
79
65
|
*/
|
|
80
66
|
export function getChildren(node, edges) {
|
|
81
67
|
return edges
|
|
@@ -102,7 +88,9 @@ export function getEndNodePositions(workflow) {
|
|
|
102
88
|
});
|
|
103
89
|
}
|
|
104
90
|
/**
|
|
105
|
-
*
|
|
91
|
+
* In Dagre, we no longer do an explicit “identify leaf nodes” or “center parents by average,”
|
|
92
|
+
* because the layout library handles that.
|
|
93
|
+
* But here’s your old method if something else depends on it.
|
|
106
94
|
*/
|
|
107
95
|
export function identifyLeafNodes(workflow) {
|
|
108
96
|
const sources = new Set(workflow.edges.map((edge) => edge.source.getRef()));
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "2.0.
|
|
1
|
+
export declare const SDK_VERSION = "2.0.51";
|
|
2
2
|
export declare function compareVersions(v1: string, v2: string): number;
|
|
@@ -6,22 +6,17 @@ export declare const ySpacing = 75;
|
|
|
6
6
|
export declare const ROOT_X = 400;
|
|
7
7
|
export declare const ROOT_Y = 120;
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* 4) It calls elk.layout() (asynchronously) to compute positions.
|
|
16
|
-
* 5) It then updates each node in workflow.nodes with the computed positions.
|
|
17
|
-
*
|
|
18
|
-
* Note: ELK returns (x,y) for the top-left of each node’s bounding box.
|
|
19
|
-
* If your SDK expects center positions, we adjust by adding half the width/height.
|
|
9
|
+
* Dagre-based layout for the “top-down” pass. We’re effectively ignoring the old
|
|
10
|
+
* manual code. Instead, we:
|
|
11
|
+
* 1) Build a dagre graph
|
|
12
|
+
* 2) Add all nodes & edges
|
|
13
|
+
* 3) dagre.layout(g)
|
|
14
|
+
* 4) Extract positions & write them back to workflow.nodes
|
|
20
15
|
*/
|
|
21
|
-
export declare function positionWorkflowNodes(workflow: Workflow):
|
|
16
|
+
export declare function positionWorkflowNodes(workflow: Workflow): void;
|
|
22
17
|
/**
|
|
23
|
-
*
|
|
24
|
-
*
|
|
18
|
+
* We keep these helper functions the same for external usage (if your code or tests need them),
|
|
19
|
+
* but we’re not actively using them in the new Dagre-based layout.
|
|
25
20
|
*/
|
|
26
21
|
export declare function getChildren(node: Node, edges: Edge[]): Node[];
|
|
27
22
|
export declare function getParents(node: Node, edges: Edge[]): Node[];
|
|
@@ -31,7 +26,9 @@ export declare function getEndNodePositions(workflow: Workflow): {
|
|
|
31
26
|
y: number;
|
|
32
27
|
}[];
|
|
33
28
|
/**
|
|
34
|
-
*
|
|
29
|
+
* In Dagre, we no longer do an explicit “identify leaf nodes” or “center parents by average,”
|
|
30
|
+
* because the layout library handles that.
|
|
31
|
+
* But here’s your old method if something else depends on it.
|
|
35
32
|
*/
|
|
36
33
|
export declare function identifyLeafNodes(workflow: Workflow): Node[];
|
|
37
34
|
export declare function identityStartingNodes(workflow: Workflow): Node[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "otomato-sdk",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.52",
|
|
4
4
|
"description": "An SDK for building and managing automations on Otomato",
|
|
5
5
|
"main": "dist/src/index.js",
|
|
6
6
|
"types": "dist/types/src/index.d.ts",
|
|
@@ -43,9 +43,9 @@
|
|
|
43
43
|
"typescript": "^5.4.5"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
+
"@dagrejs/dagre": "^1.1.4",
|
|
46
47
|
"axios": "^1.7.2",
|
|
47
48
|
"dagre": "^0.8.5",
|
|
48
|
-
"elkjs": "^0.9.3",
|
|
49
49
|
"ethers": "^6.13.1",
|
|
50
50
|
"jsonwebtoken": "^9.0.2",
|
|
51
51
|
"mustache": "^4.2.0"
|