@statelyai/graph 0.13.0 → 1.0.0

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.
Files changed (55) hide show
  1. package/README.md +3 -1
  2. package/dist/{adjacency-list-Ca0VjKIf.mjs → adjacency-list-VsUaH9SJ.mjs} +2 -2
  3. package/dist/{algorithms-BNDQcHU3.mjs → algorithms-Ba7o7niK.mjs} +29 -25
  4. package/dist/{algorithms-BlM-qoJb.d.mts → algorithms-fTqmvhzP.d.mts} +1 -1
  5. package/dist/algorithms.d.mts +1 -1
  6. package/dist/algorithms.mjs +1 -1
  7. package/dist/{converter-Dspillnn.mjs → converter-udLITX36.mjs} +2 -2
  8. package/dist/{edge-list-gKe8-iRa.mjs → edge-list-DP4otyPU.mjs} +1 -1
  9. package/dist/format-support.mjs +31 -2
  10. package/dist/formats/adjacency-list/index.d.mts +1 -1
  11. package/dist/formats/adjacency-list/index.mjs +1 -1
  12. package/dist/formats/converter/index.d.mts +1 -60
  13. package/dist/formats/converter/index.mjs +1 -1
  14. package/dist/formats/cytoscape/index.d.mts +1 -1
  15. package/dist/formats/cytoscape/index.mjs +3 -3
  16. package/dist/formats/d2/index.d.mts +109 -0
  17. package/dist/formats/d2/index.mjs +1086 -0
  18. package/dist/formats/d3/index.d.mts +2 -2
  19. package/dist/formats/d3/index.mjs +3 -3
  20. package/dist/formats/dot/index.d.mts +1 -1
  21. package/dist/formats/dot/index.mjs +3 -3
  22. package/dist/formats/edge-list/index.d.mts +1 -1
  23. package/dist/formats/edge-list/index.mjs +1 -1
  24. package/dist/formats/elk/index.d.mts +1 -1
  25. package/dist/formats/elk/index.mjs +2 -2
  26. package/dist/formats/gexf/index.d.mts +1 -1
  27. package/dist/formats/gexf/index.mjs +9 -3
  28. package/dist/formats/gml/index.d.mts +1 -1
  29. package/dist/formats/gml/index.mjs +3 -3
  30. package/dist/formats/graphml/index.d.mts +1 -1
  31. package/dist/formats/graphml/index.mjs +11 -4
  32. package/dist/formats/jgf/index.d.mts +1 -1
  33. package/dist/formats/jgf/index.mjs +3 -3
  34. package/dist/formats/mermaid/index.d.mts +1 -1
  35. package/dist/formats/mermaid/index.mjs +9 -9
  36. package/dist/formats/tgf/index.d.mts +1 -1
  37. package/dist/formats/tgf/index.mjs +2 -2
  38. package/dist/formats/xyflow/index.d.mts +1 -1
  39. package/dist/formats/xyflow/index.mjs +2 -2
  40. package/dist/index-CHoriXZD.d.mts +638 -0
  41. package/dist/index-D9Kj6Fe3.d.mts +61 -0
  42. package/dist/index.d.mts +6 -631
  43. package/dist/index.mjs +8 -7
  44. package/dist/mode-D8OnHFBk.mjs +15 -0
  45. package/dist/queries-BlkA1HAN.d.mts +516 -0
  46. package/dist/queries.d.mts +1 -514
  47. package/dist/queries.mjs +17 -15
  48. package/dist/schemas.d.mts +21 -10
  49. package/dist/schemas.mjs +12 -2
  50. package/dist/{types-CnZ01raw.d.mts → types-3-FS9NV2.d.mts} +30 -7
  51. package/package.json +2 -1
  52. package/schemas/edge.schema.json +11 -0
  53. package/schemas/graph.schema.json +24 -3
  54. package/schemas/node.schema.json +6 -0
  55. /package/dist/{indexing-DUl3kTqm.mjs → indexing-DR8M1vBy.mjs} +0 -0
package/dist/schemas.mjs CHANGED
@@ -1,7 +1,16 @@
1
1
  import * as z from "zod";
2
2
 
3
3
  //#region src/schemas.ts
4
- const StyleSchema = z.record(z.string(), z.union([z.string(), z.number()]));
4
+ const StyleSchema = z.record(z.string(), z.union([
5
+ z.string(),
6
+ z.number(),
7
+ z.boolean()
8
+ ]));
9
+ const ModeSchema = z.enum([
10
+ "directed",
11
+ "undirected",
12
+ "bidirectional"
13
+ ]);
5
14
  const PortDirectionSchema = z.enum([
6
15
  "in",
7
16
  "out",
@@ -43,6 +52,7 @@ const EdgeSchema = z.object({
43
52
  weight: z.number().optional(),
44
53
  sourcePort: z.string().optional(),
45
54
  targetPort: z.string().optional(),
55
+ mode: ModeSchema.optional(),
46
56
  data: z.any(),
47
57
  x: z.number().optional(),
48
58
  y: z.number().optional(),
@@ -53,7 +63,7 @@ const EdgeSchema = z.object({
53
63
  });
54
64
  const GraphSchema = z.object({
55
65
  id: z.string(),
56
- type: z.enum(["directed", "undirected"]),
66
+ mode: ModeSchema,
57
67
  initialNodeId: z.string().nullable().optional(),
58
68
  nodes: z.array(NodeSchema),
59
69
  edges: z.array(EdgeSchema),
@@ -1,4 +1,15 @@
1
1
  //#region src/types.d.ts
2
+ /**
3
+ * Directedness of a graph or an individual edge.
4
+ *
5
+ * - `'directed'` — edge points from source to target.
6
+ * - `'undirected'` — edge has no direction; traversable both ways.
7
+ * - `'bidirectional'` — edge points both ways (arrows on both ends).
8
+ *
9
+ * Set at the graph level as the default ({@link Graph.mode}); individual edges
10
+ * may override it ({@link GraphEdge.mode}).
11
+ */
12
+ type GraphMode = 'directed' | 'undirected' | 'bidirectional';
2
13
  interface EntityRect {
3
14
  x: number;
4
15
  y: number;
@@ -11,7 +22,7 @@ interface GraphEntity {
11
22
  y?: number;
12
23
  width?: number;
13
24
  height?: number;
14
- style?: Record<string, string | number>;
25
+ style?: Record<string, string | number | boolean>;
15
26
  }
16
27
  /** Visual entity base — required position/size. */
17
28
  interface VisualGraphEntity {
@@ -19,7 +30,7 @@ interface VisualGraphEntity {
19
30
  y: number;
20
31
  width: number;
21
32
  height: number;
22
- style?: Record<string, string | number>;
33
+ style?: Record<string, string | number | boolean>;
23
34
  }
24
35
  type PortDirection = 'in' | 'out' | 'inout';
25
36
  interface PortConfig<TPortData = any> extends GraphEntity {
@@ -42,13 +53,14 @@ interface VisualPort<TPortData = any> extends GraphPort<TPortData> {
42
53
  }
43
54
  interface GraphConfig<TNodeData = any, TEdgeData = any, TGraphData = any, TPortData = any> {
44
55
  id?: string;
45
- type?: 'directed' | 'undirected';
56
+ /** Default directedness for all edges. Defaults to `'directed'`. */
57
+ mode?: GraphMode;
46
58
  initialNodeId?: string;
47
59
  nodes?: NodeConfig<TNodeData, TPortData>[];
48
60
  edges?: EdgeConfig<TEdgeData>[];
49
61
  data?: TGraphData;
50
62
  direction?: 'up' | 'down' | 'left' | 'right';
51
- style?: Record<string, string | number>;
63
+ style?: Record<string, string | number | boolean>;
52
64
  }
53
65
  interface NodeConfig<TNodeData = any, TPortData = any> extends GraphEntity {
54
66
  id: string;
@@ -87,18 +99,24 @@ interface EdgeConfig<TEdgeData = any> extends GraphEntity {
87
99
  sourcePort?: string;
88
100
  /** Port name on the target node this edge connects to. */
89
101
  targetPort?: string;
102
+ /**
103
+ * Per-edge directedness override. When absent, the edge inherits the graph's
104
+ * {@link GraphConfig.mode}.
105
+ */
106
+ mode?: GraphMode;
90
107
  data?: TEdgeData;
91
108
  color?: string;
92
109
  }
93
110
  interface Graph<TNodeData = any, TEdgeData = any, TGraphData = any, TPortData = any> {
94
111
  id: string;
95
- type: 'directed' | 'undirected';
112
+ /** Default directedness for all edges. */
113
+ mode: GraphMode;
96
114
  initialNodeId?: string | null;
97
115
  nodes: GraphNode<TNodeData, TPortData>[];
98
116
  edges: GraphEdge<TEdgeData>[];
99
117
  data: TGraphData;
100
118
  direction?: 'up' | 'down' | 'left' | 'right';
101
- style?: Record<string, string | number>;
119
+ style?: Record<string, string | number | boolean>;
102
120
  }
103
121
  interface GraphNode<TNodeData = any, TPortData = any> extends GraphEntity {
104
122
  type: 'node';
@@ -127,6 +145,11 @@ interface GraphEdge<TEdgeData = any> extends GraphEntity {
127
145
  sourcePort?: string;
128
146
  /** Port name on the target node this edge connects to. */
129
147
  targetPort?: string;
148
+ /**
149
+ * Per-edge directedness override. When absent, the edge inherits the graph's
150
+ * {@link Graph.mode}.
151
+ */
152
+ mode?: GraphMode;
130
153
  data: TEdgeData;
131
154
  color?: string;
132
155
  }
@@ -352,4 +375,4 @@ interface TransitionOptions<TState, TEvent> {
352
375
  id?: string;
353
376
  }
354
377
  //#endregion
355
- export { VisualEdge as A, NodeConfig as C, SinglePathOptions as D, PortDirection as E, VisualNode as F, VisualPort as I, WalkContext as L, VisualGraphConfig as M, VisualGraphEntity as N, TransitionOptions as O, VisualGraphFormatConverter as P, WalkOptions as R, NodeChange as S, PortConfig as T, GraphPatch as _, EdgeChange as a, GraphStep as b, EntitiesUpdate as c, GraphConfig as d, GraphDiff as f, GraphNode as g, GraphFormatConverter as h, DeleteNodeOptions as i, VisualGraph as j, TraversalOptions as k, EntityRect as l, GraphEntity as m, AllPairsShortestPathsOptions as n, EdgeConfig as o, GraphEdge as p, CoverageStats as r, EntitiesConfig as s, AStarOptions as t, Graph as u, GraphPath as v, PathOptions as w, MSTOptions as x, GraphPort as y, WeightedWalkOptions as z };
378
+ export { TraversalOptions as A, WeightedWalkOptions as B, NodeChange as C, PortDirection as D, PortConfig as E, VisualGraphFormatConverter as F, VisualNode as I, VisualPort as L, VisualGraph as M, VisualGraphConfig as N, SinglePathOptions as O, VisualGraphEntity as P, WalkContext as R, MSTOptions as S, PathOptions as T, GraphNode as _, EdgeChange as a, GraphPort as b, EntitiesUpdate as c, GraphConfig as d, GraphDiff as f, GraphMode as g, GraphFormatConverter as h, DeleteNodeOptions as i, VisualEdge as j, TransitionOptions as k, EntityRect as l, GraphEntity as m, AllPairsShortestPathsOptions as n, EdgeConfig as o, GraphEdge as p, CoverageStats as r, EntitiesConfig as s, AStarOptions as t, Graph as u, GraphPatch as v, NodeConfig as w, GraphStep as x, GraphPath as y, WalkOptions as z };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@statelyai/graph",
3
3
  "type": "module",
4
- "version": "0.13.0",
4
+ "version": "1.0.0",
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",
@@ -28,6 +28,7 @@
28
28
  "./adjacency-list": "./dist/formats/adjacency-list/index.mjs",
29
29
  "./converter": "./dist/formats/converter/index.mjs",
30
30
  "./cytoscape": "./dist/formats/cytoscape/index.mjs",
31
+ "./d2": "./dist/formats/d2/index.mjs",
31
32
  "./d3": "./dist/formats/d3/index.mjs",
32
33
  "./dot": "./dist/formats/dot/index.mjs",
33
34
  "./edge-list": "./dist/formats/edge-list/index.mjs",
@@ -34,6 +34,14 @@
34
34
  "targetPort": {
35
35
  "type": "string"
36
36
  },
37
+ "mode": {
38
+ "type": "string",
39
+ "enum": [
40
+ "directed",
41
+ "undirected",
42
+ "bidirectional"
43
+ ]
44
+ },
37
45
  "data": {},
38
46
  "x": {
39
47
  "type": "number"
@@ -62,6 +70,9 @@
62
70
  },
63
71
  {
64
72
  "type": "number"
73
+ },
74
+ {
75
+ "type": "boolean"
65
76
  }
66
77
  ]
67
78
  }
@@ -5,11 +5,12 @@
5
5
  "id": {
6
6
  "type": "string"
7
7
  },
8
- "type": {
8
+ "mode": {
9
9
  "type": "string",
10
10
  "enum": [
11
11
  "directed",
12
- "undirected"
12
+ "undirected",
13
+ "bidirectional"
13
14
  ]
14
15
  },
15
16
  "initialNodeId": {
@@ -95,6 +96,9 @@
95
96
  },
96
97
  {
97
98
  "type": "number"
99
+ },
100
+ {
101
+ "type": "boolean"
98
102
  }
99
103
  ]
100
104
  }
@@ -143,6 +147,9 @@
143
147
  },
144
148
  {
145
149
  "type": "number"
150
+ },
151
+ {
152
+ "type": "boolean"
146
153
  }
147
154
  ]
148
155
  }
@@ -202,6 +209,14 @@
202
209
  "targetPort": {
203
210
  "type": "string"
204
211
  },
212
+ "mode": {
213
+ "type": "string",
214
+ "enum": [
215
+ "directed",
216
+ "undirected",
217
+ "bidirectional"
218
+ ]
219
+ },
205
220
  "data": {},
206
221
  "x": {
207
222
  "type": "number"
@@ -230,6 +245,9 @@
230
245
  },
231
246
  {
232
247
  "type": "number"
248
+ },
249
+ {
250
+ "type": "boolean"
233
251
  }
234
252
  ]
235
253
  }
@@ -267,6 +285,9 @@
267
285
  },
268
286
  {
269
287
  "type": "number"
288
+ },
289
+ {
290
+ "type": "boolean"
270
291
  }
271
292
  ]
272
293
  }
@@ -274,7 +295,7 @@
274
295
  },
275
296
  "required": [
276
297
  "id",
277
- "type",
298
+ "mode",
278
299
  "nodes",
279
300
  "edges",
280
301
  "data"
@@ -70,6 +70,9 @@
70
70
  },
71
71
  {
72
72
  "type": "number"
73
+ },
74
+ {
75
+ "type": "boolean"
73
76
  }
74
77
  ]
75
78
  }
@@ -118,6 +121,9 @@
118
121
  },
119
122
  {
120
123
  "type": "number"
124
+ },
125
+ {
126
+ "type": "boolean"
121
127
  }
122
128
  ]
123
129
  }