@statelyai/graph 0.10.0 → 0.11.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.
Files changed (49) hide show
  1. package/README.md +26 -6
  2. package/dist/{algorithms-C-S7u40k.mjs → algorithms-BHHg7lGq.mjs} +1509 -2132
  3. package/dist/algorithms-BlM-qoJb.d.mts +178 -0
  4. package/dist/algorithms.d.mts +1 -1
  5. package/dist/algorithms.mjs +1 -1
  6. package/dist/{converter-B5CUD0r9.mjs → converter-Dspillnn.mjs} +2 -2
  7. package/dist/format-support.d.mts +22 -0
  8. package/dist/format-support.mjs +309 -0
  9. package/dist/formats/adjacency-list/index.d.mts +1 -1
  10. package/dist/formats/adjacency-list/index.mjs +1 -1
  11. package/dist/formats/converter/index.d.mts +1 -1
  12. package/dist/formats/converter/index.mjs +1 -1
  13. package/dist/formats/cytoscape/index.d.mts +1 -1
  14. package/dist/formats/cytoscape/index.mjs +1 -1
  15. package/dist/formats/d3/index.d.mts +1 -1
  16. package/dist/formats/d3/index.mjs +1 -1
  17. package/dist/formats/dot/index.d.mts +1 -1
  18. package/dist/formats/dot/index.mjs +1 -1
  19. package/dist/formats/edge-list/index.d.mts +1 -1
  20. package/dist/formats/edge-list/index.mjs +1 -1
  21. package/dist/formats/elk/index.d.mts +1 -1
  22. package/dist/formats/gexf/index.d.mts +1 -1
  23. package/dist/formats/gexf/index.mjs +1 -1
  24. package/dist/formats/gml/index.d.mts +1 -1
  25. package/dist/formats/gml/index.mjs +1 -1
  26. package/dist/formats/graphml/index.d.mts +1 -1
  27. package/dist/formats/graphml/index.mjs +34 -1
  28. package/dist/formats/jgf/index.d.mts +1 -1
  29. package/dist/formats/jgf/index.mjs +1 -1
  30. package/dist/formats/mermaid/index.d.mts +47 -3
  31. package/dist/formats/mermaid/index.mjs +234 -29
  32. package/dist/formats/tgf/index.d.mts +1 -1
  33. package/dist/formats/tgf/index.mjs +1 -1
  34. package/dist/formats/xyflow/index.d.mts +1 -1
  35. package/dist/index.d.mts +2 -2
  36. package/dist/index.mjs +3 -3
  37. package/dist/queries.d.mts +1 -1
  38. package/dist/queries.mjs +1 -1
  39. package/dist/schemas.d.mts +52 -3
  40. package/dist/schemas.mjs +22 -3
  41. package/package.json +6 -2
  42. package/schemas/edge.schema.json +16 -1
  43. package/schemas/graph.schema.json +80 -4
  44. package/schemas/node.schema.json +64 -2
  45. package/dist/algorithms-DdjFO-ft.d.mts +0 -787
  46. /package/dist/{adjacency-list-fldj-QAL.mjs → adjacency-list-Ca0VjKIf.mjs} +0 -0
  47. /package/dist/{edge-list-Br05wXMg.mjs → edge-list-gKe8-iRa.mjs} +0 -0
  48. /package/dist/{indexing-DyfgLuzw.mjs → indexing-CJc-ul8e.mjs} +0 -0
  49. /package/dist/{types-F3j-sr2X.d.mts → types-CnZ01raw.d.mts} +0 -0
@@ -1,12 +1,27 @@
1
1
  import * as z from "zod";
2
2
 
3
3
  //#region src/schemas.d.ts
4
+ declare const PortSchema: z.ZodObject<{
5
+ name: z.ZodString;
6
+ direction: z.ZodOptional<z.ZodEnum<{
7
+ in: "in";
8
+ out: "out";
9
+ inout: "inout";
10
+ }>>;
11
+ label: z.ZodOptional<z.ZodString>;
12
+ data: z.ZodAny;
13
+ x: z.ZodOptional<z.ZodNumber>;
14
+ y: z.ZodOptional<z.ZodNumber>;
15
+ width: z.ZodOptional<z.ZodNumber>;
16
+ height: z.ZodOptional<z.ZodNumber>;
17
+ style: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>>;
18
+ }, z.core.$strip>;
4
19
  declare const NodeSchema: z.ZodObject<{
5
20
  type: z.ZodLiteral<"node">;
6
21
  id: z.ZodString;
7
22
  parentId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
8
23
  initialNodeId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
9
- label: z.ZodOptional<z.ZodString>;
24
+ label: z.ZodOptional<z.ZodNullable<z.ZodString>>;
10
25
  data: z.ZodAny;
11
26
  x: z.ZodOptional<z.ZodNumber>;
12
27
  y: z.ZodOptional<z.ZodNumber>;
@@ -15,6 +30,21 @@ declare const NodeSchema: z.ZodObject<{
15
30
  shape: z.ZodOptional<z.ZodString>;
16
31
  color: z.ZodOptional<z.ZodString>;
17
32
  style: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>>;
33
+ ports: z.ZodOptional<z.ZodArray<z.ZodObject<{
34
+ name: z.ZodString;
35
+ direction: z.ZodOptional<z.ZodEnum<{
36
+ in: "in";
37
+ out: "out";
38
+ inout: "inout";
39
+ }>>;
40
+ label: z.ZodOptional<z.ZodString>;
41
+ data: z.ZodAny;
42
+ x: z.ZodOptional<z.ZodNumber>;
43
+ y: z.ZodOptional<z.ZodNumber>;
44
+ width: z.ZodOptional<z.ZodNumber>;
45
+ height: z.ZodOptional<z.ZodNumber>;
46
+ style: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>>;
47
+ }, z.core.$strip>>>;
18
48
  }, z.core.$strip>;
19
49
  declare const EdgeSchema: z.ZodObject<{
20
50
  type: z.ZodLiteral<"edge">;
@@ -23,6 +53,8 @@ declare const EdgeSchema: z.ZodObject<{
23
53
  targetId: z.ZodString;
24
54
  label: z.ZodOptional<z.ZodNullable<z.ZodString>>;
25
55
  weight: z.ZodOptional<z.ZodNumber>;
56
+ sourcePort: z.ZodOptional<z.ZodString>;
57
+ targetPort: z.ZodOptional<z.ZodString>;
26
58
  data: z.ZodAny;
27
59
  x: z.ZodOptional<z.ZodNumber>;
28
60
  y: z.ZodOptional<z.ZodNumber>;
@@ -43,7 +75,7 @@ declare const GraphSchema: z.ZodObject<{
43
75
  id: z.ZodString;
44
76
  parentId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
45
77
  initialNodeId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
46
- label: z.ZodOptional<z.ZodString>;
78
+ label: z.ZodOptional<z.ZodNullable<z.ZodString>>;
47
79
  data: z.ZodAny;
48
80
  x: z.ZodOptional<z.ZodNumber>;
49
81
  y: z.ZodOptional<z.ZodNumber>;
@@ -52,6 +84,21 @@ declare const GraphSchema: z.ZodObject<{
52
84
  shape: z.ZodOptional<z.ZodString>;
53
85
  color: z.ZodOptional<z.ZodString>;
54
86
  style: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>>;
87
+ ports: z.ZodOptional<z.ZodArray<z.ZodObject<{
88
+ name: z.ZodString;
89
+ direction: z.ZodOptional<z.ZodEnum<{
90
+ in: "in";
91
+ out: "out";
92
+ inout: "inout";
93
+ }>>;
94
+ label: z.ZodOptional<z.ZodString>;
95
+ data: z.ZodAny;
96
+ x: z.ZodOptional<z.ZodNumber>;
97
+ y: z.ZodOptional<z.ZodNumber>;
98
+ width: z.ZodOptional<z.ZodNumber>;
99
+ height: z.ZodOptional<z.ZodNumber>;
100
+ style: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>>;
101
+ }, z.core.$strip>>>;
55
102
  }, z.core.$strip>>;
56
103
  edges: z.ZodArray<z.ZodObject<{
57
104
  type: z.ZodLiteral<"edge">;
@@ -60,6 +107,8 @@ declare const GraphSchema: z.ZodObject<{
60
107
  targetId: z.ZodString;
61
108
  label: z.ZodOptional<z.ZodNullable<z.ZodString>>;
62
109
  weight: z.ZodOptional<z.ZodNumber>;
110
+ sourcePort: z.ZodOptional<z.ZodString>;
111
+ targetPort: z.ZodOptional<z.ZodString>;
63
112
  data: z.ZodAny;
64
113
  x: z.ZodOptional<z.ZodNumber>;
65
114
  y: z.ZodOptional<z.ZodNumber>;
@@ -78,4 +127,4 @@ declare const GraphSchema: z.ZodObject<{
78
127
  style: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>>;
79
128
  }, z.core.$strip>;
80
129
  //#endregion
81
- export { EdgeSchema, GraphSchema, NodeSchema };
130
+ export { EdgeSchema, GraphSchema, NodeSchema, PortSchema };
package/dist/schemas.mjs CHANGED
@@ -2,12 +2,28 @@ import * as z from "zod";
2
2
 
3
3
  //#region src/schemas.ts
4
4
  const StyleSchema = z.record(z.string(), z.union([z.string(), z.number()]));
5
+ const PortDirectionSchema = z.enum([
6
+ "in",
7
+ "out",
8
+ "inout"
9
+ ]);
10
+ const PortSchema = z.object({
11
+ name: z.string(),
12
+ direction: PortDirectionSchema.optional(),
13
+ label: z.string().optional(),
14
+ data: z.any(),
15
+ x: z.number().optional(),
16
+ y: z.number().optional(),
17
+ width: z.number().optional(),
18
+ height: z.number().optional(),
19
+ style: StyleSchema.optional()
20
+ });
5
21
  const NodeSchema = z.object({
6
22
  type: z.literal("node"),
7
23
  id: z.string(),
8
24
  parentId: z.string().nullable().optional(),
9
25
  initialNodeId: z.string().nullable().optional(),
10
- label: z.string().optional(),
26
+ label: z.string().nullable().optional(),
11
27
  data: z.any(),
12
28
  x: z.number().optional(),
13
29
  y: z.number().optional(),
@@ -15,7 +31,8 @@ const NodeSchema = z.object({
15
31
  height: z.number().optional(),
16
32
  shape: z.string().optional(),
17
33
  color: z.string().optional(),
18
- style: StyleSchema.optional()
34
+ style: StyleSchema.optional(),
35
+ ports: z.array(PortSchema).optional()
19
36
  });
20
37
  const EdgeSchema = z.object({
21
38
  type: z.literal("edge"),
@@ -24,6 +41,8 @@ const EdgeSchema = z.object({
24
41
  targetId: z.string(),
25
42
  label: z.string().nullable().optional(),
26
43
  weight: z.number().optional(),
44
+ sourcePort: z.string().optional(),
45
+ targetPort: z.string().optional(),
27
46
  data: z.any(),
28
47
  x: z.number().optional(),
29
48
  y: z.number().optional(),
@@ -49,4 +68,4 @@ const GraphSchema = z.object({
49
68
  });
50
69
 
51
70
  //#endregion
52
- export { EdgeSchema, GraphSchema, NodeSchema };
71
+ export { EdgeSchema, GraphSchema, NodeSchema, PortSchema };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@statelyai/graph",
3
3
  "type": "module",
4
- "version": "0.10.0",
4
+ "version": "0.11.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,6 +24,7 @@
24
24
  "exports": {
25
25
  ".": "./dist/index.mjs",
26
26
  "./algorithms": "./dist/algorithms.mjs",
27
+ "./format-support": "./dist/format-support.mjs",
27
28
  "./adjacency-list": "./dist/formats/adjacency-list/index.mjs",
28
29
  "./converter": "./dist/formats/converter/index.mjs",
29
30
  "./cytoscape": "./dist/formats/cytoscape/index.mjs",
@@ -101,10 +102,13 @@
101
102
  },
102
103
  "scripts": {
103
104
  "build": "tsdown",
105
+ "bench": "vitest bench --run",
104
106
  "dev": "tsdown --watch",
107
+ "fix:generated": "pnpm generate-schema",
105
108
  "test": "vitest",
106
109
  "typecheck": "tsc --noEmit",
107
- "verify": "pnpm typecheck && pnpm test -- --run && pnpm build && pnpm validate:package",
110
+ "check:generated": "tsx scripts/generate-json-schema.ts --check",
111
+ "verify": "pnpm typecheck && pnpm check:generated && pnpm test -- --run && pnpm build && pnpm validate:package",
108
112
  "validate:package": "publint && tsx scripts/smoke-package.ts",
109
113
  "generate-schema": "tsx scripts/generate-json-schema.ts",
110
114
  "changeset": "changeset",
@@ -16,6 +16,22 @@
16
16
  "type": "string"
17
17
  },
18
18
  "label": {
19
+ "anyOf": [
20
+ {
21
+ "type": "string"
22
+ },
23
+ {
24
+ "type": "null"
25
+ }
26
+ ]
27
+ },
28
+ "weight": {
29
+ "type": "number"
30
+ },
31
+ "sourcePort": {
32
+ "type": "string"
33
+ },
34
+ "targetPort": {
19
35
  "type": "string"
20
36
  },
21
37
  "data": {},
@@ -56,7 +72,6 @@
56
72
  "id",
57
73
  "sourceId",
58
74
  "targetId",
59
- "label",
60
75
  "data"
61
76
  ],
62
77
  "additionalProperties": false
@@ -55,7 +55,14 @@
55
55
  ]
56
56
  },
57
57
  "label": {
58
- "type": "string"
58
+ "anyOf": [
59
+ {
60
+ "type": "string"
61
+ },
62
+ {
63
+ "type": "null"
64
+ }
65
+ ]
59
66
  },
60
67
  "data": {},
61
68
  "x": {
@@ -91,12 +98,67 @@
91
98
  }
92
99
  ]
93
100
  }
101
+ },
102
+ "ports": {
103
+ "type": "array",
104
+ "items": {
105
+ "type": "object",
106
+ "properties": {
107
+ "name": {
108
+ "type": "string"
109
+ },
110
+ "direction": {
111
+ "type": "string",
112
+ "enum": [
113
+ "in",
114
+ "out",
115
+ "inout"
116
+ ]
117
+ },
118
+ "label": {
119
+ "type": "string"
120
+ },
121
+ "data": {},
122
+ "x": {
123
+ "type": "number"
124
+ },
125
+ "y": {
126
+ "type": "number"
127
+ },
128
+ "width": {
129
+ "type": "number"
130
+ },
131
+ "height": {
132
+ "type": "number"
133
+ },
134
+ "style": {
135
+ "type": "object",
136
+ "propertyNames": {
137
+ "type": "string"
138
+ },
139
+ "additionalProperties": {
140
+ "anyOf": [
141
+ {
142
+ "type": "string"
143
+ },
144
+ {
145
+ "type": "number"
146
+ }
147
+ ]
148
+ }
149
+ }
150
+ },
151
+ "required": [
152
+ "name",
153
+ "data"
154
+ ],
155
+ "additionalProperties": false
156
+ }
94
157
  }
95
158
  },
96
159
  "required": [
97
160
  "type",
98
161
  "id",
99
- "label",
100
162
  "data"
101
163
  ],
102
164
  "additionalProperties": false
@@ -121,6 +183,22 @@
121
183
  "type": "string"
122
184
  },
123
185
  "label": {
186
+ "anyOf": [
187
+ {
188
+ "type": "string"
189
+ },
190
+ {
191
+ "type": "null"
192
+ }
193
+ ]
194
+ },
195
+ "weight": {
196
+ "type": "number"
197
+ },
198
+ "sourcePort": {
199
+ "type": "string"
200
+ },
201
+ "targetPort": {
124
202
  "type": "string"
125
203
  },
126
204
  "data": {},
@@ -161,7 +239,6 @@
161
239
  "id",
162
240
  "sourceId",
163
241
  "targetId",
164
- "label",
165
242
  "data"
166
243
  ],
167
244
  "additionalProperties": false
@@ -197,7 +274,6 @@
197
274
  "required": [
198
275
  "id",
199
276
  "type",
200
- "initialNodeId",
201
277
  "nodes",
202
278
  "edges",
203
279
  "data"
@@ -30,7 +30,14 @@
30
30
  ]
31
31
  },
32
32
  "label": {
33
- "type": "string"
33
+ "anyOf": [
34
+ {
35
+ "type": "string"
36
+ },
37
+ {
38
+ "type": "null"
39
+ }
40
+ ]
34
41
  },
35
42
  "data": {},
36
43
  "x": {
@@ -66,12 +73,67 @@
66
73
  }
67
74
  ]
68
75
  }
76
+ },
77
+ "ports": {
78
+ "type": "array",
79
+ "items": {
80
+ "type": "object",
81
+ "properties": {
82
+ "name": {
83
+ "type": "string"
84
+ },
85
+ "direction": {
86
+ "type": "string",
87
+ "enum": [
88
+ "in",
89
+ "out",
90
+ "inout"
91
+ ]
92
+ },
93
+ "label": {
94
+ "type": "string"
95
+ },
96
+ "data": {},
97
+ "x": {
98
+ "type": "number"
99
+ },
100
+ "y": {
101
+ "type": "number"
102
+ },
103
+ "width": {
104
+ "type": "number"
105
+ },
106
+ "height": {
107
+ "type": "number"
108
+ },
109
+ "style": {
110
+ "type": "object",
111
+ "propertyNames": {
112
+ "type": "string"
113
+ },
114
+ "additionalProperties": {
115
+ "anyOf": [
116
+ {
117
+ "type": "string"
118
+ },
119
+ {
120
+ "type": "number"
121
+ }
122
+ ]
123
+ }
124
+ }
125
+ },
126
+ "required": [
127
+ "name",
128
+ "data"
129
+ ],
130
+ "additionalProperties": false
131
+ }
69
132
  }
70
133
  },
71
134
  "required": [
72
135
  "type",
73
136
  "id",
74
- "label",
75
137
  "data"
76
138
  ],
77
139
  "additionalProperties": false