@dxos/graph 0.7.5-labs.a279d8c → 0.7.5-main.2567c87
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 +0 -9
- package/dist/lib/browser/index.mjs +107 -274
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +101 -272
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +107 -274
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/buidler.d.ts +16 -0
- package/dist/types/src/buidler.d.ts.map +1 -0
- package/dist/types/src/graph.d.ts +30 -0
- package/dist/types/src/graph.d.ts.map +1 -0
- package/dist/types/src/graph.test.d.ts +2 -0
- package/dist/types/src/graph.test.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +2 -2
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/types.d.ts +10 -28
- package/dist/types/src/types.d.ts.map +1 -1
- package/dist/types/src/util.d.ts +1 -16
- package/dist/types/src/util.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +16 -14
- package/src/buidler.ts +62 -0
- package/src/graph.test.ts +56 -0
- package/src/graph.ts +127 -0
- package/src/index.ts +2 -2
- package/src/types.ts +12 -31
- package/src/util.ts +10 -62
- package/dist/types/src/model.d.ts +0 -107
- package/dist/types/src/model.d.ts.map +0 -1
- package/dist/types/src/model.test.d.ts +0 -2
- package/dist/types/src/model.test.d.ts.map +0 -1
- package/src/model.test.ts +0 -120
- package/src/model.ts +0 -266
package/README.md
CHANGED
|
@@ -1,12 +1,3 @@
|
|
|
1
1
|
# @dxos/graph
|
|
2
2
|
|
|
3
3
|
Basic graph API.
|
|
4
|
-
|
|
5
|
-
## Prior art
|
|
6
|
-
|
|
7
|
-
- [Graphology](https://graphology.github.io) (TS, tree-shakable, multiple packages for extensions)
|
|
8
|
-
- [Graphlib](https://github.com/dagrejs/graphlib) (mature, extensive)
|
|
9
|
-
- [tiny-graph](https://github.com/avoidwork/tiny-graph)
|
|
10
|
-
- levelgraph (LevelDB)
|
|
11
|
-
- oxigraph (Rust WASM)
|
|
12
|
-
- Neo4J
|
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
// packages/common/graph/src/
|
|
2
|
-
import { inspectCustom } from "@dxos/debug";
|
|
3
|
-
import { failedInvariant, invariant as invariant2 } from "@dxos/invariant";
|
|
4
|
-
import { getSnapshot } from "@dxos/live-object";
|
|
5
|
-
import { isNotFalsy, removeBy, stripUndefined } from "@dxos/util";
|
|
6
|
-
|
|
7
|
-
// packages/common/graph/src/util.ts
|
|
1
|
+
// packages/common/graph/src/buidler.ts
|
|
8
2
|
import { FormatEnum } from "@dxos/echo-schema";
|
|
9
3
|
import { invariant } from "@dxos/invariant";
|
|
10
|
-
import { getSchema
|
|
4
|
+
import { getSchema } from "@dxos/live-object";
|
|
11
5
|
import { log } from "@dxos/log";
|
|
12
6
|
import { getSchemaProperties } from "@dxos/schema";
|
|
13
7
|
|
|
8
|
+
// packages/common/graph/src/graph.ts
|
|
9
|
+
import { create } from "@dxos/live-object";
|
|
10
|
+
|
|
14
11
|
// packages/common/graph/src/types.ts
|
|
15
12
|
import { S } from "@dxos/echo-schema";
|
|
16
13
|
var BaseGraphNode = S.Struct({
|
|
@@ -21,140 +18,43 @@ var BaseGraphNode = S.Struct({
|
|
|
21
18
|
var BaseGraphEdge = S.Struct({
|
|
22
19
|
id: S.String,
|
|
23
20
|
type: S.optional(S.String),
|
|
24
|
-
data: S.optional(S.Any),
|
|
25
21
|
source: S.String,
|
|
26
|
-
target: S.String
|
|
22
|
+
target: S.String,
|
|
23
|
+
data: S.optional(S.Any)
|
|
27
24
|
});
|
|
28
|
-
var ExtendableBaseGraphNode = S.extend(BaseGraphNode, S.Struct({}, {
|
|
29
|
-
key: S.String,
|
|
30
|
-
value: S.Any
|
|
31
|
-
}));
|
|
32
25
|
var Graph = S.Struct({
|
|
33
|
-
|
|
34
|
-
nodes: S.mutable(S.Array(ExtendableBaseGraphNode)),
|
|
26
|
+
nodes: S.mutable(S.Array(BaseGraphNode)),
|
|
35
27
|
edges: S.mutable(S.Array(BaseGraphEdge))
|
|
36
28
|
});
|
|
29
|
+
var emptyGraph = {
|
|
30
|
+
nodes: [],
|
|
31
|
+
edges: []
|
|
32
|
+
};
|
|
37
33
|
|
|
38
34
|
// packages/common/graph/src/util.ts
|
|
39
|
-
var
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
L: 21,
|
|
45
|
-
S: void 0,
|
|
46
|
-
A: [
|
|
47
|
-
"source.match(KEY_REGEX)",
|
|
48
|
-
"`invalid source: ${source}`"
|
|
49
|
-
]
|
|
50
|
-
});
|
|
51
|
-
invariant(target.match(KEY_REGEX), `invalid target: ${target}`, {
|
|
52
|
-
F: __dxlog_file,
|
|
53
|
-
L: 22,
|
|
54
|
-
S: void 0,
|
|
55
|
-
A: [
|
|
56
|
-
"target.match(KEY_REGEX)",
|
|
57
|
-
"`invalid target: ${target}`"
|
|
58
|
-
]
|
|
59
|
-
});
|
|
60
|
-
return [
|
|
61
|
-
source,
|
|
62
|
-
relation,
|
|
63
|
-
target
|
|
64
|
-
].join("_");
|
|
65
|
-
};
|
|
66
|
-
var parseEdgeId = (id) => {
|
|
67
|
-
const [source, relation, target] = id.split("_");
|
|
68
|
-
invariant(source.length && target.length, void 0, {
|
|
69
|
-
F: __dxlog_file,
|
|
70
|
-
L: 28,
|
|
71
|
-
S: void 0,
|
|
72
|
-
A: [
|
|
73
|
-
"source.length && target.length",
|
|
74
|
-
""
|
|
75
|
-
]
|
|
76
|
-
});
|
|
77
|
-
return {
|
|
78
|
-
source,
|
|
79
|
-
relation: relation.length ? relation : void 0,
|
|
80
|
-
target
|
|
81
|
-
};
|
|
82
|
-
};
|
|
83
|
-
var createGraph = (objects) => {
|
|
84
|
-
const graph = new GraphModel(create(Graph, {
|
|
85
|
-
nodes: [],
|
|
86
|
-
edges: []
|
|
87
|
-
}));
|
|
88
|
-
objects.forEach((object) => {
|
|
89
|
-
graph.addNode({
|
|
90
|
-
id: object.id,
|
|
91
|
-
type: object.typename,
|
|
92
|
-
data: object
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
objects.forEach((object) => {
|
|
96
|
-
const schema = getSchema(object);
|
|
97
|
-
if (!schema) {
|
|
98
|
-
log.info("no schema for object", {
|
|
99
|
-
id: object.id.slice(0, 8)
|
|
100
|
-
}, {
|
|
101
|
-
F: __dxlog_file,
|
|
102
|
-
L: 48,
|
|
103
|
-
S: void 0,
|
|
104
|
-
C: (f, a) => f(...a)
|
|
105
|
-
});
|
|
106
|
-
return;
|
|
35
|
+
var removeElements = (array, predicate) => {
|
|
36
|
+
const deleted = [];
|
|
37
|
+
for (let i = array.length - 1; i >= 0; i--) {
|
|
38
|
+
if (predicate(array[i], i)) {
|
|
39
|
+
deleted.push(...array.splice(i, 1));
|
|
107
40
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
const source = object;
|
|
111
|
-
const target = object[prop.name]?.target;
|
|
112
|
-
if (target) {
|
|
113
|
-
graph.addEdge({
|
|
114
|
-
id: createEdgeId({
|
|
115
|
-
source: source.id,
|
|
116
|
-
target: target.id,
|
|
117
|
-
relation: String(prop.name)
|
|
118
|
-
}),
|
|
119
|
-
source: source.id,
|
|
120
|
-
target: target.id
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
});
|
|
126
|
-
return graph;
|
|
41
|
+
}
|
|
42
|
+
return deleted;
|
|
127
43
|
};
|
|
128
44
|
|
|
129
|
-
// packages/common/graph/src/
|
|
130
|
-
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/common/graph/src/model.ts";
|
|
45
|
+
// packages/common/graph/src/graph.ts
|
|
131
46
|
var ReadonlyGraphModel = class {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
*/
|
|
135
|
-
constructor(graph) {
|
|
136
|
-
this._graph = graph ?? {
|
|
137
|
-
nodes: [],
|
|
138
|
-
edges: []
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
[inspectCustom]() {
|
|
142
|
-
return this.toJSON();
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* Return stable sorted JSON representation of graph.
|
|
146
|
-
*/
|
|
147
|
-
// TODO(burdon): Create separate toJson method with computed signal.
|
|
148
|
-
toJSON() {
|
|
149
|
-
const { id, nodes, edges } = getSnapshot(this._graph);
|
|
150
|
-
nodes.sort(({ id: a }, { id: b }) => a.localeCompare(b));
|
|
151
|
-
edges.sort(({ id: a }, { id: b }) => a.localeCompare(b));
|
|
152
|
-
return stripUndefined({
|
|
153
|
-
id,
|
|
47
|
+
constructor({ nodes = [], edges = [] } = {}) {
|
|
48
|
+
this._graph = create(Graph, {
|
|
154
49
|
nodes,
|
|
155
50
|
edges
|
|
156
51
|
});
|
|
157
52
|
}
|
|
53
|
+
toJSON() {
|
|
54
|
+
this._graph.nodes.sort(({ id: a }, { id: b }) => a.localeCompare(b));
|
|
55
|
+
this._graph.edges.sort(({ id: a }, { id: b }) => a.localeCompare(b));
|
|
56
|
+
return JSON.parse(JSON.stringify(this._graph));
|
|
57
|
+
}
|
|
158
58
|
get graph() {
|
|
159
59
|
return this._graph;
|
|
160
60
|
}
|
|
@@ -164,51 +64,20 @@ var ReadonlyGraphModel = class {
|
|
|
164
64
|
get edges() {
|
|
165
65
|
return this._graph.edges;
|
|
166
66
|
}
|
|
167
|
-
//
|
|
168
|
-
// Nodes
|
|
169
|
-
//
|
|
170
|
-
findNode(id) {
|
|
171
|
-
return this.nodes.find((node) => node.id === id);
|
|
172
|
-
}
|
|
173
67
|
getNode(id) {
|
|
174
|
-
return this.
|
|
68
|
+
return this.nodes.find((node) => node.id === id);
|
|
175
69
|
}
|
|
176
|
-
|
|
70
|
+
getNodes({ type }) {
|
|
177
71
|
return this.nodes.filter((node) => !type || type === node.type);
|
|
178
72
|
}
|
|
179
|
-
//
|
|
180
|
-
// Edges
|
|
181
|
-
//
|
|
182
|
-
findEdge(id) {
|
|
183
|
-
return this.edges.find((edge) => edge.id === id);
|
|
184
|
-
}
|
|
185
73
|
getEdge(id) {
|
|
186
|
-
return this.
|
|
74
|
+
return this.edges.find((edge) => edge.id === id);
|
|
187
75
|
}
|
|
188
|
-
|
|
76
|
+
getEdges({ type, source, target }) {
|
|
189
77
|
return this.edges.filter((edge) => (!type || type === edge.type) && (!source || source === edge.source) && (!target || target === edge.target));
|
|
190
78
|
}
|
|
191
|
-
//
|
|
192
|
-
// Traverse
|
|
193
|
-
//
|
|
194
|
-
traverse(root) {
|
|
195
|
-
return this._traverse(root);
|
|
196
|
-
}
|
|
197
|
-
_traverse(root, visited = /* @__PURE__ */ new Set()) {
|
|
198
|
-
if (visited.has(root.id)) {
|
|
199
|
-
return [];
|
|
200
|
-
}
|
|
201
|
-
visited.add(root.id);
|
|
202
|
-
const targets = this.filterEdges({
|
|
203
|
-
source: root.id
|
|
204
|
-
}).map((edge) => this.getNode(edge.target)).filter(isNotFalsy);
|
|
205
|
-
return [
|
|
206
|
-
root,
|
|
207
|
-
...targets.flatMap((target) => this._traverse(target, visited))
|
|
208
|
-
];
|
|
209
|
-
}
|
|
210
79
|
};
|
|
211
|
-
var
|
|
80
|
+
var GraphModel = class _GraphModel extends ReadonlyGraphModel {
|
|
212
81
|
clear() {
|
|
213
82
|
this._graph.nodes.length = 0;
|
|
214
83
|
this._graph.edges.length = 0;
|
|
@@ -227,153 +96,117 @@ var AbstractGraphModel = class extends ReadonlyGraphModel {
|
|
|
227
96
|
return this;
|
|
228
97
|
}
|
|
229
98
|
addNode(node) {
|
|
230
|
-
invariant2(node.id, "ID is required", {
|
|
231
|
-
F: __dxlog_file2,
|
|
232
|
-
L: 153,
|
|
233
|
-
S: this,
|
|
234
|
-
A: [
|
|
235
|
-
"node.id",
|
|
236
|
-
"'ID is required'"
|
|
237
|
-
]
|
|
238
|
-
});
|
|
239
|
-
invariant2(!this.findNode(node.id), `node already exists: ${node.id}`, {
|
|
240
|
-
F: __dxlog_file2,
|
|
241
|
-
L: 154,
|
|
242
|
-
S: this,
|
|
243
|
-
A: [
|
|
244
|
-
"!this.findNode(node.id)",
|
|
245
|
-
"`node already exists: ${node.id}`"
|
|
246
|
-
]
|
|
247
|
-
});
|
|
248
99
|
this._graph.nodes.push(node);
|
|
249
|
-
return
|
|
100
|
+
return this;
|
|
250
101
|
}
|
|
251
102
|
addNodes(nodes) {
|
|
252
|
-
|
|
103
|
+
nodes.forEach((node) => this.addNode(node));
|
|
104
|
+
return this;
|
|
253
105
|
}
|
|
254
106
|
addEdge(edge) {
|
|
255
|
-
invariant2(edge.source, void 0, {
|
|
256
|
-
F: __dxlog_file2,
|
|
257
|
-
L: 164,
|
|
258
|
-
S: this,
|
|
259
|
-
A: [
|
|
260
|
-
"edge.source",
|
|
261
|
-
""
|
|
262
|
-
]
|
|
263
|
-
});
|
|
264
|
-
invariant2(edge.target, void 0, {
|
|
265
|
-
F: __dxlog_file2,
|
|
266
|
-
L: 165,
|
|
267
|
-
S: this,
|
|
268
|
-
A: [
|
|
269
|
-
"edge.target",
|
|
270
|
-
""
|
|
271
|
-
]
|
|
272
|
-
});
|
|
273
|
-
if (!edge.id) {
|
|
274
|
-
edge = {
|
|
275
|
-
id: createEdgeId(edge),
|
|
276
|
-
...edge
|
|
277
|
-
};
|
|
278
|
-
}
|
|
279
|
-
invariant2(!this.findNode(edge.id), void 0, {
|
|
280
|
-
F: __dxlog_file2,
|
|
281
|
-
L: 170,
|
|
282
|
-
S: this,
|
|
283
|
-
A: [
|
|
284
|
-
"!this.findNode(edge.id!)",
|
|
285
|
-
""
|
|
286
|
-
]
|
|
287
|
-
});
|
|
288
107
|
this._graph.edges.push(edge);
|
|
289
|
-
return
|
|
108
|
+
return this;
|
|
290
109
|
}
|
|
291
110
|
addEdges(edges) {
|
|
292
|
-
|
|
111
|
+
edges.forEach((edge) => this.addEdge(edge));
|
|
112
|
+
return this;
|
|
293
113
|
}
|
|
114
|
+
// TODO(burdon): Return graph.
|
|
294
115
|
removeNode(id) {
|
|
295
|
-
const nodes =
|
|
296
|
-
const edges =
|
|
297
|
-
return
|
|
116
|
+
const nodes = removeElements(this._graph.nodes, (node) => node.id === id);
|
|
117
|
+
const edges = removeElements(this._graph.edges, (edge) => edge.source === id || edge.target === id);
|
|
118
|
+
return new _GraphModel({
|
|
298
119
|
nodes,
|
|
299
120
|
edges
|
|
300
121
|
});
|
|
301
122
|
}
|
|
302
123
|
removeNodes(ids) {
|
|
303
124
|
const graphs = ids.map((id) => this.removeNode(id));
|
|
304
|
-
return
|
|
125
|
+
return new _GraphModel().addGraphs(graphs);
|
|
305
126
|
}
|
|
306
127
|
removeEdge(id) {
|
|
307
|
-
const edges =
|
|
308
|
-
return
|
|
309
|
-
nodes: [],
|
|
128
|
+
const edges = removeElements(this._graph.edges, (edge) => edge.id === id);
|
|
129
|
+
return new _GraphModel({
|
|
310
130
|
edges
|
|
311
131
|
});
|
|
312
132
|
}
|
|
313
133
|
removeEdges(ids) {
|
|
314
134
|
const graphs = ids.map((id) => this.removeEdge(id));
|
|
315
|
-
return
|
|
135
|
+
return new _GraphModel().addGraphs(graphs);
|
|
316
136
|
}
|
|
317
137
|
};
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
return this;
|
|
339
|
-
}
|
|
340
|
-
addNodes(nodes) {
|
|
341
|
-
this._model.addNodes(nodes);
|
|
342
|
-
return this;
|
|
343
|
-
}
|
|
344
|
-
addEdges(edges) {
|
|
345
|
-
this._model.addEdges(edges);
|
|
346
|
-
return this;
|
|
347
|
-
}
|
|
138
|
+
|
|
139
|
+
// packages/common/graph/src/buidler.ts
|
|
140
|
+
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/common/graph/src/buidler.ts";
|
|
141
|
+
var createEdgeId = ({ source, target, relation }) => `${source}-${relation}-${target}`;
|
|
142
|
+
var parseEdgeId = (id) => {
|
|
143
|
+
const [source, relation, target] = id.split("-");
|
|
144
|
+
invariant(source && target && relation, void 0, {
|
|
145
|
+
F: __dxlog_file,
|
|
146
|
+
L: 22,
|
|
147
|
+
S: void 0,
|
|
148
|
+
A: [
|
|
149
|
+
"source && target && relation",
|
|
150
|
+
""
|
|
151
|
+
]
|
|
152
|
+
});
|
|
153
|
+
return {
|
|
154
|
+
source,
|
|
155
|
+
relation,
|
|
156
|
+
target
|
|
157
|
+
};
|
|
348
158
|
};
|
|
349
|
-
var
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
edges: graph?.edges ?? []
|
|
159
|
+
var createGraph = (objects) => {
|
|
160
|
+
const graph = new GraphModel();
|
|
161
|
+
objects.forEach((object) => {
|
|
162
|
+
graph.addNode({
|
|
163
|
+
id: object.id,
|
|
164
|
+
type: object.typename,
|
|
165
|
+
data: object
|
|
357
166
|
});
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
167
|
+
});
|
|
168
|
+
objects.forEach((object) => {
|
|
169
|
+
const schema = getSchema(object);
|
|
170
|
+
if (!schema) {
|
|
171
|
+
log.info("no schema for object", {
|
|
172
|
+
id: object.id.slice(0, 8)
|
|
173
|
+
}, {
|
|
174
|
+
F: __dxlog_file,
|
|
175
|
+
L: 41,
|
|
176
|
+
S: void 0,
|
|
177
|
+
C: (f, a) => f(...a)
|
|
178
|
+
});
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
for (const prop of getSchemaProperties(schema.ast, object)) {
|
|
182
|
+
if (prop.format === FormatEnum.Ref) {
|
|
183
|
+
const source = object;
|
|
184
|
+
const target = object[prop.name]?.target;
|
|
185
|
+
if (target) {
|
|
186
|
+
graph.addEdge({
|
|
187
|
+
id: createEdgeId({
|
|
188
|
+
source: source.id,
|
|
189
|
+
target: target.id,
|
|
190
|
+
relation: String(prop.name)
|
|
191
|
+
}),
|
|
192
|
+
source: source.id,
|
|
193
|
+
target: target.id
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
return graph;
|
|
365
200
|
};
|
|
366
201
|
export {
|
|
367
|
-
AbstractGraphBuilder,
|
|
368
|
-
AbstractGraphModel,
|
|
369
202
|
BaseGraphEdge,
|
|
370
203
|
BaseGraphNode,
|
|
371
204
|
Graph,
|
|
372
|
-
GraphBuilder,
|
|
373
205
|
GraphModel,
|
|
374
206
|
ReadonlyGraphModel,
|
|
375
207
|
createEdgeId,
|
|
376
208
|
createGraph,
|
|
209
|
+
emptyGraph,
|
|
377
210
|
parseEdgeId
|
|
378
211
|
};
|
|
379
212
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../../src/
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { inspectCustom } from '@dxos/debug';\nimport { failedInvariant, invariant } from '@dxos/invariant';\nimport { getSnapshot } from '@dxos/live-object';\nimport { type MakeOptional, isNotFalsy, removeBy, stripUndefined } from '@dxos/util';\n\nimport { type Graph, type GraphNode, type GraphEdge, type BaseGraphNode, type BaseGraphEdge } from './types';\nimport { createEdgeId } from './util';\n\n/**\n * Wrapper class contains reactive nodes and edges.\n */\nexport class ReadonlyGraphModel<\n Node extends BaseGraphNode = BaseGraphNode,\n Edge extends BaseGraphEdge = BaseGraphEdge,\n> {\n protected readonly _graph: Graph;\n\n /**\n * NOTE: Pass in simple Graph or ReactiveObject.\n */\n constructor(graph?: Graph) {\n this._graph = graph ?? { nodes: [], edges: [] };\n }\n\n [inspectCustom]() {\n return this.toJSON();\n }\n\n /**\n * Return stable sorted JSON representation of graph.\n */\n // TODO(burdon): Create separate toJson method with computed signal.\n toJSON() {\n const { id, nodes, edges } = getSnapshot(this._graph);\n nodes.sort(({ id: a }, { id: b }) => a.localeCompare(b));\n edges.sort(({ id: a }, { id: b }) => a.localeCompare(b));\n return stripUndefined({ id, nodes, edges });\n }\n\n get graph(): Graph {\n return this._graph;\n }\n\n get nodes(): Node[] {\n return this._graph.nodes as Node[];\n }\n\n get edges(): Edge[] {\n return this._graph.edges as Edge[];\n }\n\n //\n // Nodes\n //\n\n findNode(id: string): Node | undefined {\n return this.nodes.find((node) => node.id === id);\n }\n\n getNode(id: string): Node {\n return this.findNode(id) ?? failedInvariant();\n }\n\n filterNodes({ type }: Partial<GraphNode> = {}): Node[] {\n return this.nodes.filter((node) => !type || type === node.type);\n }\n\n //\n // Edges\n //\n\n findEdge(id: string): Edge | undefined {\n return this.edges.find((edge) => edge.id === id);\n }\n\n getEdge(id: string): Edge {\n return this.findEdge(id) ?? failedInvariant();\n }\n\n filterEdges({ type, source, target }: Partial<GraphEdge> = {}): Edge[] {\n return this.edges.filter(\n (edge) =>\n (!type || type === edge.type) && (!source || source === edge.source) && (!target || target === edge.target),\n );\n }\n\n //\n // Traverse\n //\n\n traverse(root: Node): Node[] {\n return this._traverse(root);\n }\n\n private _traverse(root: Node, visited: Set<string> = new Set()): Node[] {\n if (visited.has(root.id)) {\n return [];\n }\n\n visited.add(root.id);\n const targets = this.filterEdges({ source: root.id })\n .map((edge) => this.getNode(edge.target))\n .filter(isNotFalsy);\n\n return [root, ...targets.flatMap((target) => this._traverse(target, visited))];\n }\n}\n\n/**\n * Typed wrapper.\n */\nexport abstract class AbstractGraphModel<\n Node extends BaseGraphNode,\n Edge extends BaseGraphEdge,\n Model extends AbstractGraphModel<Node, Edge, Model, Builder>,\n Builder extends AbstractGraphBuilder<Node, Edge, Model>,\n> extends ReadonlyGraphModel<Node, Edge> {\n /**\n * Allows chaining.\n */\n abstract get builder(): Builder;\n\n /**\n * Shallow copy of provided graph.\n */\n abstract copy(graph?: Partial<Graph>): Model;\n\n clear(): this {\n this._graph.nodes.length = 0;\n this._graph.edges.length = 0;\n return this;\n }\n\n addGraph(graph: Model): this {\n this.addNodes(graph.nodes);\n this.addEdges(graph.edges);\n return this;\n }\n\n addGraphs(graphs: Model[]): this {\n graphs.forEach((graph) => {\n this.addNodes(graph.nodes);\n this.addEdges(graph.edges);\n });\n return this;\n }\n\n addNode(node: Node): Node {\n invariant(node.id, 'ID is required');\n invariant(!this.findNode(node.id), `node already exists: ${node.id}`);\n this._graph.nodes.push(node);\n return node;\n }\n\n addNodes(nodes: Node[]): Node[] {\n return nodes.map((node) => this.addNode(node));\n }\n\n addEdge(edge: MakeOptional<Edge, 'id'>): Edge {\n invariant(edge.source);\n invariant(edge.target);\n if (!edge.id) {\n // TODO(burdon): Generate random id.\n edge = { id: createEdgeId(edge), ...edge };\n }\n invariant(!this.findNode(edge.id!));\n this._graph.edges.push(edge as Edge);\n return edge as Edge;\n }\n\n addEdges(edges: Edge[]): Edge[] {\n return edges.map((edge) => this.addEdge(edge));\n }\n\n removeNode(id: string): Model {\n const nodes = removeBy<Node>(this._graph.nodes as Node[], (node) => node.id === id);\n const edges = removeBy<Edge>(this._graph.edges as Edge[], (edge) => edge.source === id || edge.target === id);\n return this.copy({ nodes, edges });\n }\n\n removeNodes(ids: string[]): Model {\n const graphs = ids.map((id) => this.removeNode(id));\n return this.copy().addGraphs(graphs);\n }\n\n removeEdge(id: string): Model {\n const edges = removeBy<Edge>(this._graph.edges as Edge[], (edge) => edge.id === id);\n return this.copy({ nodes: [], edges });\n }\n\n removeEdges(ids: string[]): Model {\n const graphs = ids.map((id) => this.removeEdge(id));\n return this.copy().addGraphs(graphs);\n }\n}\n\n/**\n * Chainable wrapper\n */\nexport abstract class AbstractGraphBuilder<\n Node extends BaseGraphNode,\n Edge extends BaseGraphEdge,\n Model extends GraphModel<Node, Edge>,\n> {\n constructor(protected readonly _model: Model) {}\n\n get model(): Model {\n return this._model;\n }\n\n call(cb: (builder: this) => void): this {\n cb(this);\n return this;\n }\n\n getNode(id: string): Node {\n return this.model.getNode(id);\n }\n\n addNode(node: Node): this {\n this._model.addNode(node);\n return this;\n }\n\n addEdge(edge: MakeOptional<Edge, 'id'>): this {\n this._model.addEdge(edge);\n return this;\n }\n\n addNodes(nodes: Node[]): this {\n this._model.addNodes(nodes);\n return this;\n }\n\n addEdges(edges: Edge[]): this {\n this._model.addEdges(edges);\n return this;\n }\n}\n\nexport class GraphModel<\n Node extends BaseGraphNode = BaseGraphNode,\n Edge extends BaseGraphEdge = BaseGraphEdge,\n> extends AbstractGraphModel<Node, Edge, GraphModel<Node, Edge>, GraphBuilder<Node, Edge>> {\n override get builder() {\n return new GraphBuilder<Node, Edge>(this);\n }\n\n override copy(graph?: Partial<Graph>) {\n return new GraphModel<Node, Edge>({ nodes: graph?.nodes ?? [], edges: graph?.edges ?? [] });\n }\n}\n\nexport class GraphBuilder<\n Node extends BaseGraphNode = BaseGraphNode,\n Edge extends BaseGraphEdge = BaseGraphEdge,\n> extends AbstractGraphBuilder<Node, Edge, GraphModel<Node, Edge>> {\n override call(cb: (builder: this) => void) {\n cb(this);\n return this;\n }\n}\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { type ReactiveEchoObject } from '@dxos/echo-db';\nimport { FormatEnum } from '@dxos/echo-schema';\nimport { invariant } from '@dxos/invariant';\nimport { getSchema, create } from '@dxos/live-object';\nimport { log } from '@dxos/log';\nimport { getSchemaProperties } from '@dxos/schema';\n\nimport { GraphModel } from './model';\nimport { Graph, type GraphNode } from './types';\n\nconst KEY_REGEX = /\\w+/;\n\n// NOTE: The `relation` is different from the `type`.\ntype EdgeMeta = { source: string; target: string; relation?: string };\n\nexport const createEdgeId = ({ source, target, relation }: EdgeMeta) => {\n invariant(source.match(KEY_REGEX), `invalid source: ${source}`);\n invariant(target.match(KEY_REGEX), `invalid target: ${target}`);\n return [source, relation, target].join('_');\n};\n\nexport const parseEdgeId = (id: string): EdgeMeta => {\n const [source, relation, target] = id.split('_');\n invariant(source.length && target.length);\n return { source, relation: relation.length ? relation : undefined, target };\n};\n\n/**\n * Creates a new reactive graph from a set of ECHO objects.\n * References are mapped onto graph edges.\n */\nexport const createGraph = (objects: ReactiveEchoObject<any>[]): GraphModel<GraphNode<ReactiveEchoObject<any>>> => {\n const graph = new GraphModel<GraphNode<ReactiveEchoObject<any>>>(create(Graph, { nodes: [], edges: [] }));\n\n // Map objects.\n objects.forEach((object) => {\n graph.addNode({ id: object.id, type: object.typename, data: object });\n });\n\n // Find references.\n objects.forEach((object) => {\n const schema = getSchema(object);\n if (!schema) {\n log.info('no schema for object', { id: object.id.slice(0, 8) });\n return;\n }\n\n // Parse schema to follow referenced objects.\n for (const prop of getSchemaProperties(schema.ast, object)) {\n if (prop.format === FormatEnum.Ref) {\n const source = object;\n const target = object[prop.name]?.target;\n if (target) {\n graph.addEdge({\n id: createEdgeId({ source: source.id, target: target.id, relation: String(prop.name) }),\n source: source.id,\n target: target.id,\n });\n }\n }\n }\n });\n\n return graph;\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { S } from '@dxos/echo-schema';\nimport { type Specialize } from '@dxos/util';\n\nexport const BaseGraphNode = S.Struct({\n id: S.String,\n type: S.optional(S.String),\n data: S.optional(S.Any),\n});\n\n/** Raw base type. */\nexport type BaseGraphNode = S.Schema.Type<typeof BaseGraphNode>;\n/** Typed node data. */\nexport type GraphNode<Data = any, Optional extends boolean = false> = Specialize<\n BaseGraphNode,\n Optional extends true ? { data?: Data } : { data: Data }\n>;\n\nexport declare namespace GraphNode {\n export type Optional<T = any> = GraphNode<T, true>;\n}\n\nexport const BaseGraphEdge = S.Struct({\n id: S.String,\n type: S.optional(S.String),\n data: S.optional(S.Any),\n source: S.String,\n target: S.String,\n});\n\n/** Raw base type. */\nexport type BaseGraphEdge = S.Schema.Type<typeof BaseGraphEdge>;\n\n/** Typed edge data. */\nexport type GraphEdge<Data = any, Optional extends boolean = false> = Specialize<\n BaseGraphEdge,\n Optional extends true ? { data?: Data } : { data: Data }\n>;\n\nexport declare namespace GraphEdge {\n export type Optional<T = any> = GraphEdge<T, true>;\n}\n\n/**\n * Allows any additional properties on graph nodes.\n */\nconst ExtendableBaseGraphNode = S.extend(BaseGraphNode, S.Struct({}, { key: S.String, value: S.Any }));\n\n/**\n * Generic graph.\n */\nexport const Graph = S.Struct({\n id: S.optional(S.String),\n nodes: S.mutable(S.Array(ExtendableBaseGraphNode)),\n edges: S.mutable(S.Array(BaseGraphEdge)),\n});\n\nexport type Graph = S.Schema.Type<typeof Graph>;\n"],
|
|
5
|
-
"mappings": ";
|
|
6
|
-
"names": ["
|
|
3
|
+
"sources": ["../../../src/buidler.ts", "../../../src/graph.ts", "../../../src/types.ts", "../../../src/util.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { type ReactiveEchoObject } from '@dxos/echo-db';\nimport { FormatEnum } from '@dxos/echo-schema';\nimport { invariant } from '@dxos/invariant';\nimport { getSchema } from '@dxos/live-object';\nimport { log } from '@dxos/log';\nimport { getSchemaProperties } from '@dxos/schema';\n\nimport { GraphModel } from './graph';\nimport { type GraphNode } from './types';\n\n// NOTE: The `relation` is different from the `type`.\ntype Edge = { source: string; target: string; relation: string };\n\nexport const createEdgeId = ({ source, target, relation }: Edge) => `${source}-${relation}-${target}`;\n\nexport const parseEdgeId = (id: string): Edge => {\n const [source, relation, target] = id.split('-');\n invariant(source && target && relation);\n return { source, relation, target };\n};\n\n/**\n * Maps an ECHO object graph onto a layout graph.\n */\nexport const createGraph = (objects: ReactiveEchoObject<any>[]): GraphModel<GraphNode<ReactiveEchoObject<any>>> => {\n const graph = new GraphModel<GraphNode<ReactiveEchoObject<any>>>();\n\n // Map objects.\n objects.forEach((object) => {\n graph.addNode({ id: object.id, type: object.typename, data: object });\n });\n\n // Find references.\n objects.forEach((object) => {\n const schema = getSchema(object);\n if (!schema) {\n log.info('no schema for object', { id: object.id.slice(0, 8) });\n return;\n }\n\n // Parse schema to follow referenced objects.\n for (const prop of getSchemaProperties(schema.ast, object)) {\n if (prop.format === FormatEnum.Ref) {\n const source = object;\n const target = object[prop.name]?.target;\n if (target) {\n graph.addEdge({\n id: createEdgeId({ source: source.id, target: target.id, relation: String(prop.name) }),\n source: source.id,\n target: target.id,\n });\n }\n }\n }\n });\n\n return graph;\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { create } from '@dxos/live-object';\n\nimport { Graph, type GraphNode, type GraphEdge } from './types';\nimport { removeElements } from './util';\n\n// TODO(burdon): Traversal/visitor.\n\n/**\n * Typed reactive object graph.\n */\nexport class ReadonlyGraphModel<Node extends GraphNode = any, Edge extends GraphEdge = any> {\n protected readonly _graph: Graph;\n\n constructor({ nodes = [], edges = [] }: Partial<Graph> = {}) {\n this._graph = create(Graph, { nodes, edges });\n }\n\n toJSON() {\n // Sort to enable stable comparisons.\n this._graph.nodes.sort(({ id: a }, { id: b }) => a.localeCompare(b));\n this._graph.edges.sort(({ id: a }, { id: b }) => a.localeCompare(b));\n return JSON.parse(JSON.stringify(this._graph));\n }\n\n get graph(): Graph {\n return this._graph;\n }\n\n get nodes(): Node[] {\n return this._graph.nodes as Node[];\n }\n\n get edges(): Edge[] {\n return this._graph.edges as Edge[];\n }\n\n getNode(id: string): Node | undefined {\n return this.nodes.find((node) => node.id === id);\n }\n\n getNodes({ type }: Partial<Node>): Node[] {\n return this.nodes.filter((node) => !type || type === node.type);\n }\n\n getEdge(id: string): Edge | undefined {\n return this.edges.find((edge) => edge.id === id);\n }\n\n getEdges({ type, source, target }: Partial<Edge>): Edge[] {\n return this.edges.filter(\n (edge) =>\n (!type || type === edge.type) && (!source || source === edge.source) && (!target || target === edge.target),\n );\n }\n}\n\nexport class GraphModel<Node extends GraphNode = any, Edge extends GraphEdge = any> extends ReadonlyGraphModel<\n Node,\n Edge\n> {\n clear(): this {\n this._graph.nodes.length = 0;\n this._graph.edges.length = 0;\n return this;\n }\n\n addGraph(graph: GraphModel<Node, Edge>): this {\n this.addNodes(graph.nodes);\n this.addEdges(graph.edges);\n return this;\n }\n\n addGraphs(graphs: GraphModel<Node, Edge>[]): this {\n graphs.forEach((graph) => {\n this.addNodes(graph.nodes);\n this.addEdges(graph.edges);\n });\n return this;\n }\n\n addNode(node: Node): this {\n this._graph.nodes.push(node);\n return this;\n }\n\n addNodes(nodes: Node[]): this {\n nodes.forEach((node) => this.addNode(node));\n return this;\n }\n\n addEdge(edge: Edge): this {\n this._graph.edges.push(edge);\n return this;\n }\n\n addEdges(edges: Edge[]): this {\n edges.forEach((edge) => this.addEdge(edge));\n return this;\n }\n\n // TODO(burdon): Return graph.\n\n removeNode(id: string): GraphModel<Node, Edge> {\n const nodes = removeElements(this._graph.nodes, (node) => node.id === id);\n const edges = removeElements(this._graph.edges, (edge) => edge.source === id || edge.target === id);\n return new GraphModel<Node, Edge>({ nodes, edges });\n }\n\n removeNodes(ids: string[]): GraphModel<Node, Edge> {\n const graphs = ids.map((id) => this.removeNode(id));\n return new GraphModel<Node, Edge>().addGraphs(graphs);\n }\n\n removeEdge(id: string): GraphModel<Node, Edge> {\n const edges = removeElements(this._graph.edges, (edge) => edge.id === id);\n return new GraphModel<Node, Edge>({ edges });\n }\n\n removeEdges(ids: string[]): GraphModel<Node, Edge> {\n const graphs = ids.map((id) => this.removeEdge(id));\n return new GraphModel<Node, Edge>().addGraphs(graphs);\n }\n}\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { S } from '@dxos/echo-schema';\n\n// Prior art:\n// - https://graphology.github.io (TS, tree-shakable, multiple packages for extensions)\n// - https://github.com/dagrejs/graphlib (mature, extensive)\n// - https://github.com/avoidwork/tiny-graph\n\nexport const BaseGraphNode = S.Struct({\n id: S.String,\n type: S.optional(S.String),\n data: S.optional(S.Any),\n});\n\nexport type BaseGraphNode = S.Schema.Type<typeof BaseGraphNode>;\nexport type GraphNode<Data extends object | void = void> = BaseGraphNode & { data: Data };\n\nexport const BaseGraphEdge = S.Struct({\n id: S.String,\n type: S.optional(S.String),\n source: S.String,\n target: S.String,\n data: S.optional(S.Any),\n});\n\nexport type BaseGraphEdge = S.Schema.Type<typeof BaseGraphEdge>;\nexport type GraphEdge<Data extends object | void = void> = BaseGraphEdge & { data: Data };\n\n/**\n * Generic graph abstraction.\n */\nexport const Graph = S.Struct({\n nodes: S.mutable(S.Array(BaseGraphNode)),\n edges: S.mutable(S.Array(BaseGraphEdge)),\n});\n\nexport type Graph = S.Schema.Type<typeof Graph>;\n\nexport const emptyGraph: Graph = { nodes: [], edges: [] };\n", "//\n// Copyright 2024 DXOS.org\n//\n\n// TODO(burdon): GraphBuilder.\n\n// TODO(burdon): Move to @dxos/live-object?\nexport const removeElements = <T>(array: T[], predicate: (element: T, index: number) => boolean): T[] => {\n const deleted: T[] = [];\n for (let i = array.length - 1; i >= 0; i--) {\n if (predicate(array[i], i)) {\n deleted.push(...array.splice(i, 1));\n }\n }\n\n return deleted;\n};\n"],
|
|
5
|
+
"mappings": ";AAKA,SAASA,kBAAkB;AAC3B,SAASC,iBAAiB;AAC1B,SAASC,iBAAiB;AAC1B,SAASC,WAAW;AACpB,SAASC,2BAA2B;;;ACLpC,SAASC,cAAc;;;ACAvB,SAASC,SAAS;AAOX,IAAMC,gBAAgBC,EAAEC,OAAO;EACpCC,IAAIF,EAAEG;EACNC,MAAMJ,EAAEK,SAASL,EAAEG,MAAM;EACzBG,MAAMN,EAAEK,SAASL,EAAEO,GAAG;AACxB,CAAA;AAKO,IAAMC,gBAAgBR,EAAEC,OAAO;EACpCC,IAAIF,EAAEG;EACNC,MAAMJ,EAAEK,SAASL,EAAEG,MAAM;EACzBM,QAA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IC,WAAAA;AAGlBF,UAAQG,QAAQ,CAACC,WAAAA;AACfH,UAAMI,QAAQ;MAAET,IAAIQ,OAAOR;MAAIU,MAAMF,OAAOG;MAAUC,MAAMJ;IAAO,CAAA;EACrE,CAAA;AAGAJ,UAAQG,QAAQ,CAACC,WAAAA;AACf,UAAMK,SAASC,UAAUN,MAAAA;AACzB,QAAI,CAACK,QAAQ;AACXE,UAAIC,KAAK,wBAAwB;QAAEhB,IAAIQ,OAAOR,GAAGiB,MAAM,GAAG,CAAA;MAAG,GAAA;;;;;;AAC7D;IACF;AAGA,eAAWC,QAAQC,oBAAoBN,OAAOO,KAAKZ,MAAAA,GAAS;AAC1D,UAAIU,KAAKG,WAAWC,WAAWC,KAAK;AAClC,cAAM3B,SAASY;AACf,cAAMX,SAASW,OAAOU,KAAKM,IAAI,GAAG3B;AAClC,YAAIA,QAAQ;AACVQ,gBAAMoB,QAAQ;YACZzB,IAAIL,aAAa;cAAEC,QAAQA,OAAOI;cAAIH,QAAQA,OAAOG;cAAIF,UAAU4B,OAAOR,KAAKM,IAAI;YAAE,CAAA;YACrF5B,QAAQA,OAAOI;YACfH,QAAQA,OAAOG;UACjB,CAAA;QACF;MACF;IACF;EACF,CAAA;AAEA,SAAOK;AACT;",
|
|
6
|
+
"names": ["FormatEnum", "invariant", "getSchema", "log", "getSchemaProperties", "create", "S", "BaseGraphNode", "S", "Struct", "id", "String", "type", "optional", "data", "Any", "BaseGraphEdge", "source", "target", "Graph", "nodes", "mutable", "Array", "edges", "emptyGraph", "removeElements", "array", "predicate", "deleted", "i", "length", "push", "splice", "ReadonlyGraphModel", "constructor", "nodes", "edges", "_graph", "create", "Graph", "toJSON", "sort", "id", "a", "b", "localeCompare", "JSON", "parse", "stringify", "graph", "getNode", "find", "node", "getNodes", "type", "filter", "getEdge", "edge", "getEdges", "source", "target", "GraphModel", "clear", "length", "addGraph", "addNodes", "addEdges", "addGraphs", "graphs", "forEach", "addNode", "push", "addEdge", "removeNode", "removeElements", "removeNodes", "ids", "map", "removeEdge", "removeEdges", "createEdgeId", "source", "target", "relation", "parseEdgeId", "id", "split", "invariant", "createGraph", "objects", "graph", "GraphModel", "forEach", "object", "addNode", "type", "typename", "data", "schema", "getSchema", "log", "info", "slice", "prop", "getSchemaProperties", "ast", "format", "FormatEnum", "Ref", "name", "addEdge", "String"]
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"packages/common/graph/src/types.ts":{"bytes":
|
|
1
|
+
{"inputs":{"packages/common/graph/src/types.ts":{"bytes":3825,"imports":[{"path":"@dxos/echo-schema","kind":"import-statement","external":true}],"format":"esm"},"packages/common/graph/src/util.ts":{"bytes":1705,"imports":[],"format":"esm"},"packages/common/graph/src/graph.ts":{"bytes":12508,"imports":[{"path":"@dxos/live-object","kind":"import-statement","external":true},{"path":"packages/common/graph/src/types.ts","kind":"import-statement","original":"./types"},{"path":"packages/common/graph/src/util.ts","kind":"import-statement","original":"./util"}],"format":"esm"},"packages/common/graph/src/buidler.ts":{"bytes":7346,"imports":[{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/live-object","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/schema","kind":"import-statement","external":true},{"path":"packages/common/graph/src/graph.ts","kind":"import-statement","original":"./graph"}],"format":"esm"},"packages/common/graph/src/index.ts":{"bytes":654,"imports":[{"path":"packages/common/graph/src/buidler.ts","kind":"import-statement","original":"./buidler"},{"path":"packages/common/graph/src/graph.ts","kind":"import-statement","original":"./graph"},{"path":"packages/common/graph/src/types.ts","kind":"import-statement","original":"./types"}],"format":"esm"}},"outputs":{"packages/common/graph/dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":12611},"packages/common/graph/dist/lib/browser/index.mjs":{"imports":[{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/live-object","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/schema","kind":"import-statement","external":true},{"path":"@dxos/live-object","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true}],"exports":["BaseGraphEdge","BaseGraphNode","Graph","GraphModel","ReadonlyGraphModel","createEdgeId","createGraph","emptyGraph","parseEdgeId"],"entryPoint":"packages/common/graph/src/index.ts","inputs":{"packages/common/graph/src/buidler.ts":{"bytesInOutput":1716},"packages/common/graph/src/graph.ts":{"bytesInOutput":2460},"packages/common/graph/src/types.ts":{"bytesInOutput":454},"packages/common/graph/src/util.ts":{"bytesInOutput":223},"packages/common/graph/src/index.ts":{"bytesInOutput":0}},"bytes":5274}}}
|