@statelyai/graph 0.4.0 → 0.5.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 (45) hide show
  1. package/dist/{algorithms-CnTmuX9t.mjs → algorithms-DldwenLt.mjs} +1 -1
  2. package/dist/algorithms.d.mts +1 -1
  3. package/dist/algorithms.mjs +1 -1
  4. package/dist/{converter-C5DlzzHs.mjs → converter-B5CUD0r9.mjs} +2 -2
  5. package/dist/formats/adjacency-list/index.d.mts +1 -1
  6. package/dist/formats/adjacency-list/index.mjs +1 -1
  7. package/dist/formats/converter/index.d.mts +2 -2
  8. package/dist/formats/converter/index.mjs +1 -1
  9. package/dist/formats/cytoscape/index.d.mts +1 -1
  10. package/dist/formats/cytoscape/index.mjs +1 -1
  11. package/dist/formats/d3/index.d.mts +1 -1
  12. package/dist/formats/d3/index.mjs +1 -1
  13. package/dist/formats/dot/index.d.mts +1 -1
  14. package/dist/formats/dot/index.mjs +1 -1
  15. package/dist/formats/edge-list/index.d.mts +1 -1
  16. package/dist/formats/edge-list/index.mjs +1 -1
  17. package/dist/formats/elk/index.d.mts +61 -0
  18. package/dist/formats/elk/index.mjs +176 -0
  19. package/dist/formats/gexf/index.d.mts +1 -1
  20. package/dist/formats/gexf/index.mjs +1 -1
  21. package/dist/formats/gml/index.d.mts +1 -1
  22. package/dist/formats/gml/index.mjs +1 -1
  23. package/dist/formats/graphml/index.d.mts +1 -1
  24. package/dist/formats/graphml/index.mjs +1 -1
  25. package/dist/formats/jgf/index.d.mts +1 -1
  26. package/dist/formats/jgf/index.mjs +1 -1
  27. package/dist/formats/mermaid/index.d.mts +46 -33
  28. package/dist/formats/mermaid/index.mjs +315 -31
  29. package/dist/formats/tgf/index.d.mts +1 -1
  30. package/dist/formats/tgf/index.mjs +1 -1
  31. package/dist/formats/xyflow/index.d.mts +1 -1
  32. package/dist/index.d.mts +1 -1
  33. package/dist/index.mjs +3 -3
  34. package/dist/queries.d.mts +1 -1
  35. package/dist/queries.mjs +1 -1
  36. package/dist/schemas.d.mts +37 -4
  37. package/dist/schemas.mjs +26 -5
  38. package/dist/{types-Bq_fmLwW.d.mts → types-FBZCrmnG.d.mts} +6 -6
  39. package/package.json +7 -1
  40. package/schemas/edge.schema.json +32 -1
  41. package/schemas/graph.schema.json +114 -4
  42. package/schemas/node.schema.json +45 -2
  43. /package/dist/{adjacency-list-Bv4tfiM3.mjs → adjacency-list-fldj-QAL.mjs} +0 -0
  44. /package/dist/{edge-list-R1SUbHwe.mjs → edge-list-Br05wXMg.mjs} +0 -0
  45. /package/dist/{indexing-DitHphT7.mjs → indexing-DyfgLuzw.mjs} +0 -0
@@ -4,10 +4,17 @@ import * as z from "zod";
4
4
  declare const NodeSchema: z.ZodObject<{
5
5
  type: z.ZodLiteral<"node">;
6
6
  id: z.ZodString;
7
- parentId: z.ZodNullable<z.ZodString>;
8
- initialNodeId: z.ZodNullable<z.ZodString>;
7
+ parentId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
8
+ initialNodeId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
9
9
  label: z.ZodString;
10
10
  data: z.ZodAny;
11
+ x: z.ZodOptional<z.ZodNumber>;
12
+ y: z.ZodOptional<z.ZodNumber>;
13
+ width: z.ZodOptional<z.ZodNumber>;
14
+ height: z.ZodOptional<z.ZodNumber>;
15
+ shape: z.ZodOptional<z.ZodString>;
16
+ color: z.ZodOptional<z.ZodString>;
17
+ style: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>>;
11
18
  }, z.core.$strip>;
12
19
  declare const EdgeSchema: z.ZodObject<{
13
20
  type: z.ZodLiteral<"edge">;
@@ -16,6 +23,12 @@ declare const EdgeSchema: z.ZodObject<{
16
23
  targetId: z.ZodString;
17
24
  label: z.ZodString;
18
25
  data: z.ZodAny;
26
+ x: z.ZodOptional<z.ZodNumber>;
27
+ y: z.ZodOptional<z.ZodNumber>;
28
+ width: z.ZodOptional<z.ZodNumber>;
29
+ height: z.ZodOptional<z.ZodNumber>;
30
+ color: z.ZodOptional<z.ZodString>;
31
+ style: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>>;
19
32
  }, z.core.$strip>;
20
33
  declare const GraphSchema: z.ZodObject<{
21
34
  id: z.ZodString;
@@ -27,10 +40,17 @@ declare const GraphSchema: z.ZodObject<{
27
40
  nodes: z.ZodArray<z.ZodObject<{
28
41
  type: z.ZodLiteral<"node">;
29
42
  id: z.ZodString;
30
- parentId: z.ZodNullable<z.ZodString>;
31
- initialNodeId: z.ZodNullable<z.ZodString>;
43
+ parentId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
44
+ initialNodeId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
32
45
  label: z.ZodString;
33
46
  data: z.ZodAny;
47
+ x: z.ZodOptional<z.ZodNumber>;
48
+ y: z.ZodOptional<z.ZodNumber>;
49
+ width: z.ZodOptional<z.ZodNumber>;
50
+ height: z.ZodOptional<z.ZodNumber>;
51
+ shape: z.ZodOptional<z.ZodString>;
52
+ color: z.ZodOptional<z.ZodString>;
53
+ style: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>>;
34
54
  }, z.core.$strip>>;
35
55
  edges: z.ZodArray<z.ZodObject<{
36
56
  type: z.ZodLiteral<"edge">;
@@ -39,8 +59,21 @@ declare const GraphSchema: z.ZodObject<{
39
59
  targetId: z.ZodString;
40
60
  label: z.ZodString;
41
61
  data: z.ZodAny;
62
+ x: z.ZodOptional<z.ZodNumber>;
63
+ y: z.ZodOptional<z.ZodNumber>;
64
+ width: z.ZodOptional<z.ZodNumber>;
65
+ height: z.ZodOptional<z.ZodNumber>;
66
+ color: z.ZodOptional<z.ZodString>;
67
+ style: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>>;
42
68
  }, z.core.$strip>>;
43
69
  data: z.ZodAny;
70
+ direction: z.ZodOptional<z.ZodEnum<{
71
+ up: "up";
72
+ down: "down";
73
+ left: "left";
74
+ right: "right";
75
+ }>>;
76
+ style: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>>;
44
77
  }, z.core.$strip>;
45
78
  //#endregion
46
79
  export { EdgeSchema, GraphSchema, NodeSchema };
package/dist/schemas.mjs CHANGED
@@ -1,13 +1,21 @@
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
5
  const NodeSchema = z.object({
5
6
  type: z.literal("node"),
6
7
  id: z.string(),
7
- parentId: z.string().nullable(),
8
- initialNodeId: z.string().nullable(),
8
+ parentId: z.string().nullable().optional(),
9
+ initialNodeId: z.string().nullable().optional(),
9
10
  label: z.string(),
10
- data: z.any()
11
+ data: z.any(),
12
+ x: z.number().optional(),
13
+ y: z.number().optional(),
14
+ width: z.number().optional(),
15
+ height: z.number().optional(),
16
+ shape: z.string().optional(),
17
+ color: z.string().optional(),
18
+ style: StyleSchema.optional()
11
19
  });
12
20
  const EdgeSchema = z.object({
13
21
  type: z.literal("edge"),
@@ -15,7 +23,13 @@ const EdgeSchema = z.object({
15
23
  sourceId: z.string(),
16
24
  targetId: z.string(),
17
25
  label: z.string(),
18
- data: z.any()
26
+ data: z.any(),
27
+ x: z.number().optional(),
28
+ y: z.number().optional(),
29
+ width: z.number().optional(),
30
+ height: z.number().optional(),
31
+ color: z.string().optional(),
32
+ style: StyleSchema.optional()
19
33
  });
20
34
  const GraphSchema = z.object({
21
35
  id: z.string(),
@@ -23,7 +37,14 @@ const GraphSchema = z.object({
23
37
  initialNodeId: z.string().nullable(),
24
38
  nodes: z.array(NodeSchema),
25
39
  edges: z.array(EdgeSchema),
26
- data: z.any()
40
+ data: z.any(),
41
+ direction: z.enum([
42
+ "up",
43
+ "down",
44
+ "left",
45
+ "right"
46
+ ]).optional(),
47
+ style: StyleSchema.optional()
27
48
  });
28
49
 
29
50
  //#endregion
@@ -228,22 +228,22 @@ type GraphPatch<TNodeData = any, TEdgeData = any> = {
228
228
  * };
229
229
  * ```
230
230
  */
231
- interface GraphFormatConverter<TSerial> {
231
+ interface GraphFormatConverter<TSerial, N = any, E = any, G = any> {
232
232
  /** Convert a Graph to the serialized format. */
233
- to(graph: Graph): TSerial;
233
+ to(graph: Graph<N, E, G>): TSerial;
234
234
  /** Convert from the serialized format to a Graph. */
235
- from(input: TSerial): Graph;
235
+ from(input: TSerial): Graph<N, E, G>;
236
236
  }
237
237
  /**
238
238
  * A bidirectional converter between `VisualGraph` and a serialized format.
239
239
  *
240
240
  * Use this for formats that carry position/size data (e.g. xyflow, cytoscape).
241
241
  */
242
- interface VisualGraphFormatConverter<TSerial> {
242
+ interface VisualGraphFormatConverter<TSerial, N = any, E = any, G = any> {
243
243
  /** Convert a VisualGraph to the serialized format. */
244
- to(graph: VisualGraph): TSerial;
244
+ to(graph: VisualGraph<N, E, G>): TSerial;
245
245
  /** Convert from the serialized format to a VisualGraph. */
246
- from(input: TSerial): VisualGraph;
246
+ from(input: TSerial): VisualGraph<N, E, G>;
247
247
  }
248
248
  interface TransitionOptions<TState, TEvent> {
249
249
  /** Initial state to begin BFS exploration from. */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@statelyai/graph",
3
3
  "type": "module",
4
- "version": "0.4.0",
4
+ "version": "0.5.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",
@@ -30,6 +30,7 @@
30
30
  "./d3": "./dist/formats/d3/index.mjs",
31
31
  "./dot": "./dist/formats/dot/index.mjs",
32
32
  "./edge-list": "./dist/formats/edge-list/index.mjs",
33
+ "./elk": "./dist/formats/elk/index.mjs",
33
34
  "./gexf": "./dist/formats/gexf/index.mjs",
34
35
  "./gml": "./dist/formats/gml/index.mjs",
35
36
  "./graphml": "./dist/formats/graphml/index.mjs",
@@ -60,6 +61,7 @@
60
61
  "d3-array": "^3.2.4",
61
62
  "d3-force": "^3.0.0",
62
63
  "dotparser": "^1.1.1",
64
+ "elkjs": "^0.11.1",
63
65
  "fast-xml-parser": "^5.3.4",
64
66
  "tsdown": "^0.18.1",
65
67
  "tsx": "^4.21.0",
@@ -72,6 +74,7 @@
72
74
  "cytoscape": "^3.0.0",
73
75
  "d3-force": "^3.0.0",
74
76
  "dotparser": "^1.0.0",
77
+ "elkjs": "^0.9.0 || ^0.10.0 || ^0.11.0",
75
78
  "fast-xml-parser": "^5.0.0",
76
79
  "zod": "^4.0.0"
77
80
  },
@@ -85,6 +88,9 @@
85
88
  "dotparser": {
86
89
  "optional": true
87
90
  },
91
+ "elkjs": {
92
+ "optional": true
93
+ },
88
94
  "fast-xml-parser": {
89
95
  "optional": true
90
96
  },
@@ -18,7 +18,38 @@
18
18
  "label": {
19
19
  "type": "string"
20
20
  },
21
- "data": {}
21
+ "data": {},
22
+ "x": {
23
+ "type": "number"
24
+ },
25
+ "y": {
26
+ "type": "number"
27
+ },
28
+ "width": {
29
+ "type": "number"
30
+ },
31
+ "height": {
32
+ "type": "number"
33
+ },
34
+ "color": {
35
+ "type": "string"
36
+ },
37
+ "style": {
38
+ "type": "object",
39
+ "propertyNames": {
40
+ "type": "string"
41
+ },
42
+ "additionalProperties": {
43
+ "anyOf": [
44
+ {
45
+ "type": "string"
46
+ },
47
+ {
48
+ "type": "number"
49
+ }
50
+ ]
51
+ }
52
+ }
22
53
  },
23
54
  "required": [
24
55
  "type",
@@ -12,6 +12,16 @@
12
12
  "undirected"
13
13
  ]
14
14
  },
15
+ "initialNodeId": {
16
+ "anyOf": [
17
+ {
18
+ "type": "string"
19
+ },
20
+ {
21
+ "type": "null"
22
+ }
23
+ ]
24
+ },
15
25
  "nodes": {
16
26
  "type": "array",
17
27
  "items": {
@@ -34,15 +44,58 @@
34
44
  }
35
45
  ]
36
46
  },
47
+ "initialNodeId": {
48
+ "anyOf": [
49
+ {
50
+ "type": "string"
51
+ },
52
+ {
53
+ "type": "null"
54
+ }
55
+ ]
56
+ },
37
57
  "label": {
38
58
  "type": "string"
39
59
  },
40
- "data": {}
60
+ "data": {},
61
+ "x": {
62
+ "type": "number"
63
+ },
64
+ "y": {
65
+ "type": "number"
66
+ },
67
+ "width": {
68
+ "type": "number"
69
+ },
70
+ "height": {
71
+ "type": "number"
72
+ },
73
+ "shape": {
74
+ "type": "string"
75
+ },
76
+ "color": {
77
+ "type": "string"
78
+ },
79
+ "style": {
80
+ "type": "object",
81
+ "propertyNames": {
82
+ "type": "string"
83
+ },
84
+ "additionalProperties": {
85
+ "anyOf": [
86
+ {
87
+ "type": "string"
88
+ },
89
+ {
90
+ "type": "number"
91
+ }
92
+ ]
93
+ }
94
+ }
41
95
  },
42
96
  "required": [
43
97
  "type",
44
98
  "id",
45
- "parentId",
46
99
  "label",
47
100
  "data"
48
101
  ],
@@ -70,7 +123,38 @@
70
123
  "label": {
71
124
  "type": "string"
72
125
  },
73
- "data": {}
126
+ "data": {},
127
+ "x": {
128
+ "type": "number"
129
+ },
130
+ "y": {
131
+ "type": "number"
132
+ },
133
+ "width": {
134
+ "type": "number"
135
+ },
136
+ "height": {
137
+ "type": "number"
138
+ },
139
+ "color": {
140
+ "type": "string"
141
+ },
142
+ "style": {
143
+ "type": "object",
144
+ "propertyNames": {
145
+ "type": "string"
146
+ },
147
+ "additionalProperties": {
148
+ "anyOf": [
149
+ {
150
+ "type": "string"
151
+ },
152
+ {
153
+ "type": "number"
154
+ }
155
+ ]
156
+ }
157
+ }
74
158
  },
75
159
  "required": [
76
160
  "type",
@@ -83,11 +167,37 @@
83
167
  "additionalProperties": false
84
168
  }
85
169
  },
86
- "data": {}
170
+ "data": {},
171
+ "direction": {
172
+ "type": "string",
173
+ "enum": [
174
+ "up",
175
+ "down",
176
+ "left",
177
+ "right"
178
+ ]
179
+ },
180
+ "style": {
181
+ "type": "object",
182
+ "propertyNames": {
183
+ "type": "string"
184
+ },
185
+ "additionalProperties": {
186
+ "anyOf": [
187
+ {
188
+ "type": "string"
189
+ },
190
+ {
191
+ "type": "number"
192
+ }
193
+ ]
194
+ }
195
+ }
87
196
  },
88
197
  "required": [
89
198
  "id",
90
199
  "type",
200
+ "initialNodeId",
91
201
  "nodes",
92
202
  "edges",
93
203
  "data"
@@ -19,15 +19,58 @@
19
19
  }
20
20
  ]
21
21
  },
22
+ "initialNodeId": {
23
+ "anyOf": [
24
+ {
25
+ "type": "string"
26
+ },
27
+ {
28
+ "type": "null"
29
+ }
30
+ ]
31
+ },
22
32
  "label": {
23
33
  "type": "string"
24
34
  },
25
- "data": {}
35
+ "data": {},
36
+ "x": {
37
+ "type": "number"
38
+ },
39
+ "y": {
40
+ "type": "number"
41
+ },
42
+ "width": {
43
+ "type": "number"
44
+ },
45
+ "height": {
46
+ "type": "number"
47
+ },
48
+ "shape": {
49
+ "type": "string"
50
+ },
51
+ "color": {
52
+ "type": "string"
53
+ },
54
+ "style": {
55
+ "type": "object",
56
+ "propertyNames": {
57
+ "type": "string"
58
+ },
59
+ "additionalProperties": {
60
+ "anyOf": [
61
+ {
62
+ "type": "string"
63
+ },
64
+ {
65
+ "type": "number"
66
+ }
67
+ ]
68
+ }
69
+ }
26
70
  },
27
71
  "required": [
28
72
  "type",
29
73
  "id",
30
- "parentId",
31
74
  "label",
32
75
  "data"
33
76
  ],