@statelyai/graph 0.1.0 → 0.3.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.
- package/README.md +65 -15
- package/dist/{adjacency-list-CXpOCibq.mjs → adjacency-list-ITO40kmn.mjs} +34 -1
- package/dist/{algorithms-R35X6ro4.mjs → algorithms-NWSB2RWj.mjs} +753 -19
- package/dist/algorithms.d.mts +488 -11
- package/dist/algorithms.mjs +2 -2
- package/dist/converter-CchokMDg.mjs +67 -0
- package/dist/edge-list-CgX6bBIF.mjs +71 -0
- package/dist/formats/adjacency-list/index.d.mts +44 -0
- package/dist/formats/adjacency-list/index.mjs +3 -0
- package/dist/formats/converter/index.d.mts +61 -0
- package/dist/formats/converter/index.mjs +3 -0
- package/dist/formats/cytoscape/index.d.mts +83 -0
- package/dist/formats/cytoscape/index.mjs +135 -0
- package/dist/formats/d3/index.d.mts +68 -0
- package/dist/formats/d3/index.mjs +111 -0
- package/dist/formats/dot/index.d.mts +63 -0
- package/dist/formats/dot/index.mjs +288 -0
- package/dist/formats/edge-list/index.d.mts +43 -0
- package/dist/formats/edge-list/index.mjs +3 -0
- package/dist/formats/gexf/index.d.mts +9 -0
- package/dist/formats/gexf/index.mjs +249 -0
- package/dist/formats/gml/index.d.mts +65 -0
- package/dist/formats/gml/index.mjs +291 -0
- package/dist/formats/graphml/index.d.mts +9 -0
- package/dist/{graphml-CUTNRXqd.mjs → formats/graphml/index.mjs} +18 -4
- package/dist/formats/jgf/index.d.mts +79 -0
- package/dist/formats/jgf/index.mjs +134 -0
- package/dist/formats/mermaid/index.d.mts +381 -0
- package/dist/formats/mermaid/index.mjs +2237 -0
- package/dist/formats/tgf/index.d.mts +54 -0
- package/dist/formats/tgf/index.mjs +111 -0
- package/dist/index.d.mts +332 -21
- package/dist/index.mjs +117 -13
- package/dist/{indexing-BHg1VhqN.mjs → indexing-eNDrXdDA.mjs} +31 -2
- package/dist/queries.d.mts +430 -9
- package/dist/queries.mjs +472 -9
- package/dist/{types-XV3S5Jnh.d.mts → types-BDXC1O5b.d.mts} +37 -2
- package/package.json +43 -17
- package/dist/adjacency-list-DW-lAUe8.d.mts +0 -10
- package/dist/dot-BRtq3e3c.mjs +0 -59
- package/dist/dot-HmJeUMsj.d.mts +0 -6
- package/dist/edge-list-BRujEnnU.mjs +0 -39
- package/dist/edge-list-CJmfoNu2.d.mts +0 -10
- package/dist/formats/adjacency-list.d.mts +0 -2
- package/dist/formats/adjacency-list.mjs +0 -3
- package/dist/formats/dot.d.mts +0 -2
- package/dist/formats/dot.mjs +0 -3
- package/dist/formats/edge-list.d.mts +0 -2
- package/dist/formats/edge-list.mjs +0 -3
- package/dist/formats/graphml.d.mts +0 -2
- package/dist/formats/graphml.mjs +0 -3
- package/dist/graphml-CMjPzSfY.d.mts +0 -7
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@statelyai/graph",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.1
|
|
4
|
+
"version": "0.3.1",
|
|
5
5
|
"description": "A TypeScript-first graph library with plain JSON-serializable objects",
|
|
6
6
|
"author": "David Khourshid <david@stately.ai>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -24,10 +24,18 @@
|
|
|
24
24
|
"exports": {
|
|
25
25
|
".": "./dist/index.mjs",
|
|
26
26
|
"./algorithms": "./dist/algorithms.mjs",
|
|
27
|
-
"./
|
|
28
|
-
"./
|
|
29
|
-
"./
|
|
30
|
-
"./
|
|
27
|
+
"./adjacency-list": "./dist/formats/adjacency-list/index.mjs",
|
|
28
|
+
"./converter": "./dist/formats/converter/index.mjs",
|
|
29
|
+
"./cytoscape": "./dist/formats/cytoscape/index.mjs",
|
|
30
|
+
"./d3": "./dist/formats/d3/index.mjs",
|
|
31
|
+
"./dot": "./dist/formats/dot/index.mjs",
|
|
32
|
+
"./edge-list": "./dist/formats/edge-list/index.mjs",
|
|
33
|
+
"./gexf": "./dist/formats/gexf/index.mjs",
|
|
34
|
+
"./gml": "./dist/formats/gml/index.mjs",
|
|
35
|
+
"./graphml": "./dist/formats/graphml/index.mjs",
|
|
36
|
+
"./jgf": "./dist/formats/jgf/index.mjs",
|
|
37
|
+
"./mermaid": "./dist/formats/mermaid/index.mjs",
|
|
38
|
+
"./tgf": "./dist/formats/tgf/index.mjs",
|
|
31
39
|
"./queries": "./dist/queries.mjs",
|
|
32
40
|
"./schemas": "./dist/schemas.mjs",
|
|
33
41
|
"./package.json": "./package.json"
|
|
@@ -39,39 +47,57 @@
|
|
|
39
47
|
"dist",
|
|
40
48
|
"schemas"
|
|
41
49
|
],
|
|
42
|
-
"scripts": {
|
|
43
|
-
"build": "tsdown",
|
|
44
|
-
"dev": "tsdown --watch",
|
|
45
|
-
"test": "vitest",
|
|
46
|
-
"typecheck": "tsc --noEmit",
|
|
47
|
-
"generate-schema": "tsx scripts/generate-json-schema.ts",
|
|
48
|
-
"changeset": "changeset",
|
|
49
|
-
"version": "changeset version",
|
|
50
|
-
"release": "pnpm run build && changeset publish",
|
|
51
|
-
"prepublishOnly": "pnpm run build"
|
|
52
|
-
},
|
|
53
50
|
"devDependencies": {
|
|
54
51
|
"@changesets/changelog-github": "^0.5.2",
|
|
55
52
|
"@changesets/cli": "^2.29.8",
|
|
53
|
+
"@types/d3-array": "^3.2.2",
|
|
54
|
+
"@types/d3-force": "^3.0.10",
|
|
56
55
|
"@types/node": "^25.0.3",
|
|
57
56
|
"bumpp": "^10.3.2",
|
|
57
|
+
"cytoscape": "^3.33.1",
|
|
58
|
+
"d3-array": "^3.2.4",
|
|
59
|
+
"d3-force": "^3.0.0",
|
|
60
|
+
"dotparser": "^1.1.1",
|
|
58
61
|
"fast-xml-parser": "^5.3.4",
|
|
59
62
|
"tsdown": "^0.18.1",
|
|
60
63
|
"tsx": "^4.21.0",
|
|
61
64
|
"typescript": "^5.9.3",
|
|
62
65
|
"vitest": "^4.0.16",
|
|
66
|
+
"xstate": "^5.28.0",
|
|
63
67
|
"zod": "^4.3.6"
|
|
64
68
|
},
|
|
65
69
|
"peerDependencies": {
|
|
70
|
+
"cytoscape": "^3.0.0",
|
|
71
|
+
"d3-force": "^3.0.0",
|
|
72
|
+
"dotparser": "^1.0.0",
|
|
66
73
|
"fast-xml-parser": "^5.0.0",
|
|
67
74
|
"zod": "^4.0.0"
|
|
68
75
|
},
|
|
69
76
|
"peerDependenciesMeta": {
|
|
77
|
+
"cytoscape": {
|
|
78
|
+
"optional": true
|
|
79
|
+
},
|
|
80
|
+
"d3-force": {
|
|
81
|
+
"optional": true
|
|
82
|
+
},
|
|
83
|
+
"dotparser": {
|
|
84
|
+
"optional": true
|
|
85
|
+
},
|
|
70
86
|
"fast-xml-parser": {
|
|
71
87
|
"optional": true
|
|
72
88
|
},
|
|
73
89
|
"zod": {
|
|
74
90
|
"optional": true
|
|
75
91
|
}
|
|
92
|
+
},
|
|
93
|
+
"scripts": {
|
|
94
|
+
"build": "tsdown",
|
|
95
|
+
"dev": "tsdown --watch",
|
|
96
|
+
"test": "vitest",
|
|
97
|
+
"typecheck": "tsc --noEmit",
|
|
98
|
+
"generate-schema": "tsx scripts/generate-json-schema.ts",
|
|
99
|
+
"changeset": "changeset",
|
|
100
|
+
"version": "changeset version",
|
|
101
|
+
"release": "pnpm run build && changeset publish"
|
|
76
102
|
}
|
|
77
|
-
}
|
|
103
|
+
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { c as Graph } from "./types-XV3S5Jnh.mjs";
|
|
2
|
-
|
|
3
|
-
//#region src/formats/adjacency-list.d.ts
|
|
4
|
-
declare function toAdjacencyList(graph: Graph): Record<string, string[]>;
|
|
5
|
-
declare function fromAdjacencyList(adj: Record<string, string[]>, options?: {
|
|
6
|
-
directed?: boolean;
|
|
7
|
-
id?: string;
|
|
8
|
-
}): Graph;
|
|
9
|
-
//#endregion
|
|
10
|
-
export { toAdjacencyList as n, fromAdjacencyList as t };
|
package/dist/dot-BRtq3e3c.mjs
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
//#region src/formats/dot.ts
|
|
2
|
-
/** Escape a DOT identifier */
|
|
3
|
-
function escapeId(id) {
|
|
4
|
-
if (/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(id)) return id;
|
|
5
|
-
return `"${id.replace(/\\/g, "\\\\").replace(/"/g, "\\\"")}"`;
|
|
6
|
-
}
|
|
7
|
-
/** Escape a DOT label string */
|
|
8
|
-
function escapeLabel(label) {
|
|
9
|
-
return label.replace(/\\/g, "\\\\").replace(/"/g, "\\\"");
|
|
10
|
-
}
|
|
11
|
-
const DIRECTION_TO_RANKDIR = {
|
|
12
|
-
down: "TB",
|
|
13
|
-
up: "BT",
|
|
14
|
-
right: "LR",
|
|
15
|
-
left: "RL"
|
|
16
|
-
};
|
|
17
|
-
const SHAPE_TO_DOT = {
|
|
18
|
-
rectangle: "box",
|
|
19
|
-
ellipse: "ellipse",
|
|
20
|
-
circle: "circle",
|
|
21
|
-
diamond: "diamond",
|
|
22
|
-
hexagon: "hexagon",
|
|
23
|
-
cylinder: "cylinder",
|
|
24
|
-
parallelogram: "parallelogram"
|
|
25
|
-
};
|
|
26
|
-
function toDOT(graph) {
|
|
27
|
-
const isDirected = graph.type === "directed";
|
|
28
|
-
const keyword = isDirected ? "digraph" : "graph";
|
|
29
|
-
const edgeOp = isDirected ? "->" : "--";
|
|
30
|
-
const lines = [];
|
|
31
|
-
lines.push(`${keyword} ${escapeId(graph.id)} {`);
|
|
32
|
-
if (graph.direction) {
|
|
33
|
-
const rankdir = DIRECTION_TO_RANKDIR[graph.direction] ?? "TB";
|
|
34
|
-
lines.push(` rankdir=${rankdir};`);
|
|
35
|
-
}
|
|
36
|
-
for (const node of graph.nodes) {
|
|
37
|
-
const attrs = [];
|
|
38
|
-
if (node.label) attrs.push(`label="${escapeLabel(node.label)}"`);
|
|
39
|
-
if (node.shape) {
|
|
40
|
-
const dotShape = SHAPE_TO_DOT[node.shape] ?? node.shape;
|
|
41
|
-
attrs.push(`shape=${dotShape}`);
|
|
42
|
-
}
|
|
43
|
-
if (node.color) attrs.push(`fillcolor="${escapeLabel(node.color)}" style=filled`);
|
|
44
|
-
if (attrs.length > 0) lines.push(` ${escapeId(node.id)} [${attrs.join(", ")}];`);
|
|
45
|
-
else lines.push(` ${escapeId(node.id)};`);
|
|
46
|
-
}
|
|
47
|
-
for (const edge of graph.edges) {
|
|
48
|
-
const attrs = [];
|
|
49
|
-
if (edge.label) attrs.push(`label="${escapeLabel(edge.label)}"`);
|
|
50
|
-
if (edge.color) attrs.push(`color="${escapeLabel(edge.color)}"`);
|
|
51
|
-
const attrStr = attrs.length > 0 ? ` [${attrs.join(", ")}]` : "";
|
|
52
|
-
lines.push(` ${escapeId(edge.sourceId)} ${edgeOp} ${escapeId(edge.targetId)}${attrStr};`);
|
|
53
|
-
}
|
|
54
|
-
lines.push("}");
|
|
55
|
-
return lines.join("\n");
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
//#endregion
|
|
59
|
-
export { toDOT as t };
|
package/dist/dot-HmJeUMsj.d.mts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
//#region src/formats/edge-list.ts
|
|
2
|
-
function toEdgeList(graph) {
|
|
3
|
-
return graph.edges.map((e) => [e.sourceId, e.targetId]);
|
|
4
|
-
}
|
|
5
|
-
function fromEdgeList(edges, options) {
|
|
6
|
-
const directed = options?.directed ?? true;
|
|
7
|
-
const nodeIds = /* @__PURE__ */ new Set();
|
|
8
|
-
for (const [source, target] of edges) {
|
|
9
|
-
nodeIds.add(source);
|
|
10
|
-
nodeIds.add(target);
|
|
11
|
-
}
|
|
12
|
-
const nodes = [...nodeIds].map((id) => ({
|
|
13
|
-
type: "node",
|
|
14
|
-
id,
|
|
15
|
-
parentId: null,
|
|
16
|
-
initialNodeId: null,
|
|
17
|
-
label: "",
|
|
18
|
-
data: void 0
|
|
19
|
-
}));
|
|
20
|
-
const edgeObjects = edges.map(([sourceId, targetId], i) => ({
|
|
21
|
-
type: "edge",
|
|
22
|
-
id: `e${i}`,
|
|
23
|
-
sourceId,
|
|
24
|
-
targetId,
|
|
25
|
-
label: "",
|
|
26
|
-
data: void 0
|
|
27
|
-
}));
|
|
28
|
-
return {
|
|
29
|
-
id: options?.id ?? "",
|
|
30
|
-
type: directed ? "directed" : "undirected",
|
|
31
|
-
initialNodeId: null,
|
|
32
|
-
nodes,
|
|
33
|
-
edges: edgeObjects,
|
|
34
|
-
data: void 0
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
//#endregion
|
|
39
|
-
export { toEdgeList as n, fromEdgeList as t };
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { c as Graph } from "./types-XV3S5Jnh.mjs";
|
|
2
|
-
|
|
3
|
-
//#region src/formats/edge-list.d.ts
|
|
4
|
-
declare function toEdgeList(graph: Graph): [string, string][];
|
|
5
|
-
declare function fromEdgeList(edges: [string, string][], options?: {
|
|
6
|
-
directed?: boolean;
|
|
7
|
-
id?: string;
|
|
8
|
-
}): Graph;
|
|
9
|
-
//#endregion
|
|
10
|
-
export { toEdgeList as n, fromEdgeList as t };
|
package/dist/formats/dot.d.mts
DELETED
package/dist/formats/dot.mjs
DELETED
package/dist/formats/graphml.mjs
DELETED