@statelyai/graph 0.12.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.
- package/README.md +26 -16
- package/dist/{adjacency-list-Ca0VjKIf.mjs → adjacency-list-VsUaH9SJ.mjs} +2 -2
- package/dist/{algorithms-BHHg7lGq.mjs → algorithms-Ba7o7niK.mjs} +35 -31
- package/dist/{algorithms-BlM-qoJb.d.mts → algorithms-fTqmvhzP.d.mts} +1 -1
- package/dist/algorithms.d.mts +1 -1
- package/dist/algorithms.mjs +1 -1
- package/dist/{converter-Dspillnn.mjs → converter-udLITX36.mjs} +2 -2
- package/dist/{edge-list-gKe8-iRa.mjs → edge-list-DP4otyPU.mjs} +1 -1
- package/dist/format-support.d.mts +6 -0
- package/dist/format-support.mjs +68 -33
- package/dist/formats/adjacency-list/index.d.mts +1 -1
- package/dist/formats/adjacency-list/index.mjs +1 -1
- package/dist/formats/converter/index.d.mts +1 -60
- package/dist/formats/converter/index.mjs +1 -1
- package/dist/formats/cytoscape/index.d.mts +1 -1
- package/dist/formats/cytoscape/index.mjs +19 -3
- package/dist/formats/d2/index.d.mts +109 -0
- package/dist/formats/d2/index.mjs +1086 -0
- package/dist/formats/d3/index.d.mts +8 -1
- package/dist/formats/d3/index.mjs +35 -7
- package/dist/formats/dot/index.d.mts +1 -1
- package/dist/formats/dot/index.mjs +3 -3
- package/dist/formats/edge-list/index.d.mts +1 -1
- package/dist/formats/edge-list/index.mjs +1 -1
- package/dist/formats/elk/index.d.mts +1 -1
- package/dist/formats/elk/index.mjs +86 -23
- package/dist/formats/gexf/index.d.mts +1 -1
- package/dist/formats/gexf/index.mjs +102 -4
- package/dist/formats/gml/index.d.mts +1 -1
- package/dist/formats/gml/index.mjs +43 -16
- package/dist/formats/graphml/index.d.mts +1 -1
- package/dist/formats/graphml/index.mjs +11 -4
- package/dist/formats/jgf/index.d.mts +1 -1
- package/dist/formats/jgf/index.mjs +19 -3
- package/dist/formats/mermaid/index.d.mts +2 -1
- package/dist/formats/mermaid/index.mjs +48 -18
- package/dist/formats/tgf/index.d.mts +1 -1
- package/dist/formats/tgf/index.mjs +2 -2
- package/dist/formats/xyflow/index.d.mts +2 -1
- package/dist/formats/xyflow/index.mjs +97 -40
- package/dist/index-CHoriXZD.d.mts +638 -0
- package/dist/index-D9Kj6Fe3.d.mts +61 -0
- package/dist/index.d.mts +6 -631
- package/dist/index.mjs +8 -7
- package/dist/{indexing-CJc-ul8e.mjs → indexing-DR8M1vBy.mjs} +18 -4
- package/dist/mode-D8OnHFBk.mjs +15 -0
- package/dist/queries-BlkA1HAN.d.mts +516 -0
- package/dist/queries.d.mts +1 -514
- package/dist/queries.mjs +17 -15
- package/dist/schemas.d.mts +29 -17
- package/dist/schemas.mjs +139 -6
- package/dist/{types-CnZ01raw.d.mts → types-3-FS9NV2.d.mts} +30 -7
- package/package.json +2 -1
- package/schemas/edge.schema.json +11 -0
- package/schemas/graph.schema.json +25 -3
- package/schemas/node.schema.json +7 -0
|
@@ -1,61 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
//#region src/formats/converter/index.d.ts
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Create a `GraphFormatConverter` from a pair of `to`/`from` functions.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```ts
|
|
10
|
-
* import { createFormatConverter } from '@statelyai/graph';
|
|
11
|
-
*
|
|
12
|
-
* const yamlConverter = createFormatConverter(
|
|
13
|
-
* (graph) => toYAML(graph),
|
|
14
|
-
* (yaml) => fromYAML(yaml),
|
|
15
|
-
* );
|
|
16
|
-
*
|
|
17
|
-
* const yaml = yamlConverter.to(graph);
|
|
18
|
-
* const graph = yamlConverter.from(yaml);
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
|
-
declare function createFormatConverter<TSerial, N = any, E = any, G = any>(to: (graph: Graph<N, E, G>) => TSerial, from: (input: TSerial) => Graph<N, E, G>): GraphFormatConverter<TSerial, N, E, G>;
|
|
22
|
-
/**
|
|
23
|
-
* Bidirectional converter for adjacency-list format (`Record<string, string[]>`).
|
|
24
|
-
*
|
|
25
|
-
* @example
|
|
26
|
-
* ```ts
|
|
27
|
-
* import { adjacencyListConverter, createGraph } from '@statelyai/graph';
|
|
28
|
-
*
|
|
29
|
-
* const graph = createGraph({
|
|
30
|
-
* nodes: { a: {}, b: {} },
|
|
31
|
-
* edges: [{ source: 'a', target: 'b' }],
|
|
32
|
-
* });
|
|
33
|
-
*
|
|
34
|
-
* const adj = adjacencyListConverter.to(graph);
|
|
35
|
-
* // { a: ['b'], b: [] }
|
|
36
|
-
*
|
|
37
|
-
* const roundTripped = adjacencyListConverter.from(adj);
|
|
38
|
-
* ```
|
|
39
|
-
*/
|
|
40
|
-
declare const adjacencyListConverter: GraphFormatConverter<Record<string, string[]>>;
|
|
41
|
-
/**
|
|
42
|
-
* Bidirectional converter for edge-list format (`[source, target][]`).
|
|
43
|
-
*
|
|
44
|
-
* @example
|
|
45
|
-
* ```ts
|
|
46
|
-
* import { edgeListConverter, createGraph } from '@statelyai/graph';
|
|
47
|
-
*
|
|
48
|
-
* const graph = createGraph({
|
|
49
|
-
* nodes: { a: {}, b: {} },
|
|
50
|
-
* edges: [{ source: 'a', target: 'b' }],
|
|
51
|
-
* });
|
|
52
|
-
*
|
|
53
|
-
* const edges = edgeListConverter.to(graph);
|
|
54
|
-
* // [['a', 'b']]
|
|
55
|
-
*
|
|
56
|
-
* const roundTripped = edgeListConverter.from(edges);
|
|
57
|
-
* ```
|
|
58
|
-
*/
|
|
59
|
-
declare const edgeListConverter: GraphFormatConverter<[string, string][]>;
|
|
60
|
-
//#endregion
|
|
1
|
+
import { n as createFormatConverter, r as edgeListConverter, t as adjacencyListConverter } from "../../index-D9Kj6Fe3.mjs";
|
|
61
2
|
export { adjacencyListConverter, createFormatConverter, edgeListConverter };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { n as createFormatConverter, r as edgeListConverter, t as adjacencyListConverter } from "../../converter-
|
|
1
|
+
import { n as createFormatConverter, r as edgeListConverter, t as adjacencyListConverter } from "../../converter-udLITX36.mjs";
|
|
2
2
|
|
|
3
3
|
export { adjacencyListConverter, createFormatConverter, edgeListConverter };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as createFormatConverter } from "../../converter-
|
|
1
|
+
import { n as createFormatConverter } from "../../converter-udLITX36.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/formats/cytoscape/index.ts
|
|
4
4
|
/**
|
|
@@ -21,10 +21,11 @@ import { n as createFormatConverter } from "../../converter-Dspillnn.mjs";
|
|
|
21
21
|
function toCytoscapeJSON(graph) {
|
|
22
22
|
const graphData = {};
|
|
23
23
|
if (graph.id) graphData.id = graph.id;
|
|
24
|
-
graphData.
|
|
24
|
+
graphData.mode = graph.mode;
|
|
25
25
|
if (graph.initialNodeId) graphData.initialNodeId = graph.initialNodeId;
|
|
26
26
|
if (graph.data !== void 0) graphData.graphData = graph.data;
|
|
27
27
|
if (graph.direction) graphData.direction = graph.direction;
|
|
28
|
+
if (graph.style !== void 0) graphData.style = graph.style;
|
|
28
29
|
return {
|
|
29
30
|
...Object.keys(graphData).length > 0 && { data: graphData },
|
|
30
31
|
elements: {
|
|
@@ -38,6 +39,7 @@ function toCytoscapeJSON(graph) {
|
|
|
38
39
|
if (n.height !== void 0) data.height = n.height;
|
|
39
40
|
if (n.shape) data.shape = n.shape;
|
|
40
41
|
if (n.color) data.color = n.color;
|
|
42
|
+
if (n.style !== void 0) data.style = n.style;
|
|
41
43
|
if (n.ports !== void 0) data.ports = n.ports;
|
|
42
44
|
const node = { data };
|
|
43
45
|
if (n.x !== void 0 && n.y !== void 0) node.position = {
|
|
@@ -54,7 +56,13 @@ function toCytoscapeJSON(graph) {
|
|
|
54
56
|
};
|
|
55
57
|
if (e.label) data.label = e.label;
|
|
56
58
|
if (e.data !== void 0) data.edgeData = e.data;
|
|
59
|
+
if (e.weight !== void 0) data.weight = e.weight;
|
|
60
|
+
if (e.x !== void 0) data.x = e.x;
|
|
61
|
+
if (e.y !== void 0) data.y = e.y;
|
|
62
|
+
if (e.width !== void 0) data.width = e.width;
|
|
63
|
+
if (e.height !== void 0) data.height = e.height;
|
|
57
64
|
if (e.color) data.color = e.color;
|
|
65
|
+
if (e.style !== void 0) data.style = e.style;
|
|
58
66
|
if (e.sourcePort !== void 0) data.sourcePort = e.sourcePort;
|
|
59
67
|
if (e.targetPort !== void 0) data.targetPort = e.targetPort;
|
|
60
68
|
return { data };
|
|
@@ -84,10 +92,11 @@ function fromCytoscapeJSON(cyto) {
|
|
|
84
92
|
if (!Array.isArray(cyto.elements.edges)) throw new Error("Cytoscape: \"elements.edges\" must be an array");
|
|
85
93
|
return {
|
|
86
94
|
id: cyto.data?.id ?? "",
|
|
87
|
-
|
|
95
|
+
mode: cyto.data?.mode ?? "directed",
|
|
88
96
|
initialNodeId: cyto.data?.initialNodeId ?? null,
|
|
89
97
|
data: cyto.data?.graphData,
|
|
90
98
|
...cyto.data?.direction && { direction: cyto.data.direction },
|
|
99
|
+
...cyto.data?.style !== void 0 && { style: cyto.data.style },
|
|
91
100
|
nodes: cyto.elements.nodes.map((n) => ({
|
|
92
101
|
type: "node",
|
|
93
102
|
id: n.data.id,
|
|
@@ -103,6 +112,7 @@ function fromCytoscapeJSON(cyto) {
|
|
|
103
112
|
...n.data.height !== void 0 && { height: n.data.height },
|
|
104
113
|
...n.data.shape && { shape: n.data.shape },
|
|
105
114
|
...n.data.color && { color: n.data.color },
|
|
115
|
+
...n.data.style !== void 0 && { style: n.data.style },
|
|
106
116
|
...n.data.ports !== void 0 && { ports: n.data.ports }
|
|
107
117
|
})),
|
|
108
118
|
edges: cyto.elements.edges.map((e, i) => ({
|
|
@@ -112,7 +122,13 @@ function fromCytoscapeJSON(cyto) {
|
|
|
112
122
|
targetId: e.data.target,
|
|
113
123
|
label: e.data.label ?? "",
|
|
114
124
|
data: e.data.edgeData,
|
|
125
|
+
...e.data.weight !== void 0 && { weight: e.data.weight },
|
|
126
|
+
...e.data.x !== void 0 && { x: e.data.x },
|
|
127
|
+
...e.data.y !== void 0 && { y: e.data.y },
|
|
128
|
+
...e.data.width !== void 0 && { width: e.data.width },
|
|
129
|
+
...e.data.height !== void 0 && { height: e.data.height },
|
|
115
130
|
...e.data.color && { color: e.data.color },
|
|
131
|
+
...e.data.style !== void 0 && { style: e.data.style },
|
|
116
132
|
...e.data.sourcePort !== void 0 && { sourcePort: e.data.sourcePort },
|
|
117
133
|
...e.data.targetPort !== void 0 && { targetPort: e.data.targetPort }
|
|
118
134
|
}))
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { h as GraphFormatConverter, u as Graph } from "../../types-3-FS9NV2.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/formats/d2/shared.d.ts
|
|
4
|
+
type D2Arrow = '->' | '<-' | '--' | '<->';
|
|
5
|
+
/** Descriptor for a typed/block label (`|md ...|`, `|js ...|`, block strings). */
|
|
6
|
+
interface D2LabelBlock {
|
|
7
|
+
kind: 'md' | 'code' | 'latex' | 'block';
|
|
8
|
+
/** Language tag for code blocks (e.g. `js`, `go`). */
|
|
9
|
+
lang?: string;
|
|
10
|
+
/** The fence delimiter used (`|`, `||`, `` |` ``, etc.), preserved for emit. */
|
|
11
|
+
fence: string;
|
|
12
|
+
}
|
|
13
|
+
interface D2GridSpec {
|
|
14
|
+
rows?: number;
|
|
15
|
+
columns?: number;
|
|
16
|
+
gap?: number;
|
|
17
|
+
verticalGap?: number;
|
|
18
|
+
horizontalGap?: number;
|
|
19
|
+
}
|
|
20
|
+
/** Source-level abstractions preserved from the original d2 text. */
|
|
21
|
+
interface D2Source {
|
|
22
|
+
/** `vars: { ... }` blocks, stored as nested key/value maps. */
|
|
23
|
+
vars?: Record<string, any>;
|
|
24
|
+
/** `classes: { name: { ...style } }` definitions. */
|
|
25
|
+
classes?: Record<string, Record<string, string | number | boolean>>;
|
|
26
|
+
/** `@path` import references in declaration order. */
|
|
27
|
+
imports?: string[];
|
|
28
|
+
}
|
|
29
|
+
interface D2GraphData {
|
|
30
|
+
diagramType: 'd2';
|
|
31
|
+
source?: D2Source;
|
|
32
|
+
/** Comments before any statement / at file top. */
|
|
33
|
+
leadingComments?: string[];
|
|
34
|
+
/** Comments after the last statement. */
|
|
35
|
+
trailingComments?: string[];
|
|
36
|
+
}
|
|
37
|
+
interface D2NodeData {
|
|
38
|
+
/** Whether the author declared this node via dot-path or a `{ }` block. */
|
|
39
|
+
declarationForm?: 'dot' | 'block';
|
|
40
|
+
/** Relative positioning keyword/target (`near: top-center`, `near: a.b`). */
|
|
41
|
+
near?: string;
|
|
42
|
+
/** Icon URL. */
|
|
43
|
+
icon?: string;
|
|
44
|
+
tooltip?: string;
|
|
45
|
+
link?: string;
|
|
46
|
+
/** Names of `classes` applied to this node via `class:`. */
|
|
47
|
+
classes?: string[];
|
|
48
|
+
/** Typed/block label descriptor; absent for plain labels. */
|
|
49
|
+
labelBlock?: D2LabelBlock;
|
|
50
|
+
/** Grid layout spec for grid containers. */
|
|
51
|
+
grid?: D2GridSpec;
|
|
52
|
+
/**
|
|
53
|
+
* Source-order list of direct child node IDs and edge IDs, used by
|
|
54
|
+
* sequence diagrams (and any ordering-sensitive container) to replay
|
|
55
|
+
* statement order on emit.
|
|
56
|
+
*/
|
|
57
|
+
order?: string[];
|
|
58
|
+
/** Comments immediately preceding this node's declaration. */
|
|
59
|
+
commentsBefore?: string[];
|
|
60
|
+
/** Reserved keywords with no canonical/typed home, preserved verbatim. */
|
|
61
|
+
reserved?: Record<string, string | number | boolean>;
|
|
62
|
+
}
|
|
63
|
+
interface D2ArrowheadSpec {
|
|
64
|
+
shape?: string;
|
|
65
|
+
label?: string;
|
|
66
|
+
}
|
|
67
|
+
interface D2EdgeData {
|
|
68
|
+
/** Authored connector glyph, for faithful re-emit (incl. reversed `<-`). */
|
|
69
|
+
arrow: D2Arrow;
|
|
70
|
+
sourceArrowhead?: D2ArrowheadSpec;
|
|
71
|
+
targetArrowhead?: D2ArrowheadSpec;
|
|
72
|
+
classes?: string[];
|
|
73
|
+
labelBlock?: D2LabelBlock;
|
|
74
|
+
commentsBefore?: string[];
|
|
75
|
+
reserved?: Record<string, string | number | boolean>;
|
|
76
|
+
}
|
|
77
|
+
interface D2PortData {
|
|
78
|
+
/** SQL column type (`int`, `varchar`, ...) or class member type. */
|
|
79
|
+
typeName?: string;
|
|
80
|
+
/** SQL constraints (`primary_key`, `foreign_key`, `unique`). */
|
|
81
|
+
constraint?: string[];
|
|
82
|
+
/** Class member visibility marker (`+`, `-`, `#`). */
|
|
83
|
+
visibility?: string;
|
|
84
|
+
/** True when this port came from a `shape: class` member rather than sql_table. */
|
|
85
|
+
classMember?: boolean;
|
|
86
|
+
}
|
|
87
|
+
type D2Graph = Graph<D2NodeData, D2EdgeData, D2GraphData, D2PortData>;
|
|
88
|
+
//#endregion
|
|
89
|
+
//#region src/formats/d2/parser.d.ts
|
|
90
|
+
declare function fromD2(input: string): D2Graph;
|
|
91
|
+
//#endregion
|
|
92
|
+
//#region src/formats/d2/emitter.d.ts
|
|
93
|
+
declare function toD2(graph: D2Graph): string;
|
|
94
|
+
//#endregion
|
|
95
|
+
//#region src/formats/d2/index.d.ts
|
|
96
|
+
/**
|
|
97
|
+
* Bidirectional converter for [d2](https://d2lang.com/) diagram syntax.
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```ts
|
|
101
|
+
* import { d2Converter } from '@statelyai/graph/d2';
|
|
102
|
+
*
|
|
103
|
+
* const graph = d2Converter.from('a -> b: hello');
|
|
104
|
+
* const text = d2Converter.to(graph);
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
declare const d2Converter: GraphFormatConverter<string, D2NodeData, D2EdgeData, D2GraphData>;
|
|
108
|
+
//#endregion
|
|
109
|
+
export { type D2Arrow, type D2ArrowheadSpec, type D2EdgeData, type D2Graph, type D2GraphData, type D2GridSpec, type D2LabelBlock, type D2NodeData, type D2PortData, type D2Source, d2Converter, fromD2, toD2 };
|