@dxos/graph 0.7.5-main.ff8607b → 0.7.5-staging.2ff1350
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 +9 -0
- package/dist/lib/browser/index.mjs +274 -107
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +272 -101
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +274 -107
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/index.d.ts +2 -2
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/model.d.ts +107 -0
- package/dist/types/src/model.d.ts.map +1 -0
- package/dist/types/src/model.test.d.ts +2 -0
- package/dist/types/src/model.test.d.ts.map +1 -0
- package/dist/types/src/types.d.ts +28 -10
- package/dist/types/src/types.d.ts.map +1 -1
- package/dist/types/src/util.d.ts +16 -1
- package/dist/types/src/util.d.ts.map +1 -1
- package/package.json +14 -16
- package/src/index.ts +2 -2
- package/src/model.test.ts +120 -0
- package/src/model.ts +266 -0
- package/src/types.ts +31 -12
- package/src/util.ts +62 -10
- package/dist/types/src/buidler.d.ts +0 -16
- package/dist/types/src/buidler.d.ts.map +0 -1
- package/dist/types/src/graph.d.ts +0 -30
- package/dist/types/src/graph.d.ts.map +0 -1
- package/dist/types/src/graph.test.d.ts +0 -2
- package/dist/types/src/graph.test.d.ts.map +0 -1
- package/src/buidler.ts +0 -62
- package/src/graph.test.ts +0 -56
- package/src/graph.ts +0 -127
package/README.md
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
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,13 +1,16 @@
|
|
|
1
|
-
// packages/common/graph/src/
|
|
1
|
+
// packages/common/graph/src/model.ts
|
|
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
|
|
2
8
|
import { FormatEnum } from "@dxos/echo-schema";
|
|
3
9
|
import { invariant } from "@dxos/invariant";
|
|
4
|
-
import { getSchema } from "@dxos/live-object";
|
|
10
|
+
import { getSchema, create } from "@dxos/live-object";
|
|
5
11
|
import { log } from "@dxos/log";
|
|
6
12
|
import { getSchemaProperties } from "@dxos/schema";
|
|
7
13
|
|
|
8
|
-
// packages/common/graph/src/graph.ts
|
|
9
|
-
import { create } from "@dxos/live-object";
|
|
10
|
-
|
|
11
14
|
// packages/common/graph/src/types.ts
|
|
12
15
|
import { S } from "@dxos/echo-schema";
|
|
13
16
|
var BaseGraphNode = S.Struct({
|
|
@@ -18,43 +21,140 @@ var BaseGraphNode = S.Struct({
|
|
|
18
21
|
var BaseGraphEdge = S.Struct({
|
|
19
22
|
id: S.String,
|
|
20
23
|
type: S.optional(S.String),
|
|
24
|
+
data: S.optional(S.Any),
|
|
21
25
|
source: S.String,
|
|
22
|
-
target: S.String
|
|
23
|
-
data: S.optional(S.Any)
|
|
26
|
+
target: S.String
|
|
24
27
|
});
|
|
28
|
+
var ExtendableBaseGraphNode = S.extend(BaseGraphNode, S.Struct({}, {
|
|
29
|
+
key: S.String,
|
|
30
|
+
value: S.Any
|
|
31
|
+
}));
|
|
25
32
|
var Graph = S.Struct({
|
|
26
|
-
|
|
33
|
+
id: S.optional(S.String),
|
|
34
|
+
nodes: S.mutable(S.Array(ExtendableBaseGraphNode)),
|
|
27
35
|
edges: S.mutable(S.Array(BaseGraphEdge))
|
|
28
36
|
});
|
|
29
|
-
var emptyGraph = {
|
|
30
|
-
nodes: [],
|
|
31
|
-
edges: []
|
|
32
|
-
};
|
|
33
37
|
|
|
34
38
|
// packages/common/graph/src/util.ts
|
|
35
|
-
var
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
39
|
+
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/common/graph/src/util.ts";
|
|
40
|
+
var KEY_REGEX = /\w+/;
|
|
41
|
+
var createEdgeId = ({ source, target, relation }) => {
|
|
42
|
+
invariant(source.match(KEY_REGEX), `invalid source: ${source}`, {
|
|
43
|
+
F: __dxlog_file,
|
|
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;
|
|
40
107
|
}
|
|
41
|
-
|
|
42
|
-
|
|
108
|
+
for (const prop of getSchemaProperties(schema.ast, object)) {
|
|
109
|
+
if (prop.format === FormatEnum.Ref) {
|
|
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;
|
|
43
127
|
};
|
|
44
128
|
|
|
45
|
-
// packages/common/graph/src/
|
|
129
|
+
// packages/common/graph/src/model.ts
|
|
130
|
+
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/common/graph/src/model.ts";
|
|
46
131
|
var ReadonlyGraphModel = class {
|
|
47
|
-
|
|
48
|
-
|
|
132
|
+
/**
|
|
133
|
+
* NOTE: Pass in simple Graph or ReactiveObject.
|
|
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,
|
|
49
154
|
nodes,
|
|
50
155
|
edges
|
|
51
156
|
});
|
|
52
157
|
}
|
|
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
|
-
}
|
|
58
158
|
get graph() {
|
|
59
159
|
return this._graph;
|
|
60
160
|
}
|
|
@@ -64,20 +164,51 @@ var ReadonlyGraphModel = class {
|
|
|
64
164
|
get edges() {
|
|
65
165
|
return this._graph.edges;
|
|
66
166
|
}
|
|
67
|
-
|
|
167
|
+
//
|
|
168
|
+
// Nodes
|
|
169
|
+
//
|
|
170
|
+
findNode(id) {
|
|
68
171
|
return this.nodes.find((node) => node.id === id);
|
|
69
172
|
}
|
|
70
|
-
|
|
173
|
+
getNode(id) {
|
|
174
|
+
return this.findNode(id) ?? failedInvariant();
|
|
175
|
+
}
|
|
176
|
+
filterNodes({ type } = {}) {
|
|
71
177
|
return this.nodes.filter((node) => !type || type === node.type);
|
|
72
178
|
}
|
|
73
|
-
|
|
179
|
+
//
|
|
180
|
+
// Edges
|
|
181
|
+
//
|
|
182
|
+
findEdge(id) {
|
|
74
183
|
return this.edges.find((edge) => edge.id === id);
|
|
75
184
|
}
|
|
76
|
-
|
|
185
|
+
getEdge(id) {
|
|
186
|
+
return this.findEdge(id) ?? failedInvariant();
|
|
187
|
+
}
|
|
188
|
+
filterEdges({ type, source, target } = {}) {
|
|
77
189
|
return this.edges.filter((edge) => (!type || type === edge.type) && (!source || source === edge.source) && (!target || target === edge.target));
|
|
78
190
|
}
|
|
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
|
+
}
|
|
79
210
|
};
|
|
80
|
-
var
|
|
211
|
+
var AbstractGraphModel = class extends ReadonlyGraphModel {
|
|
81
212
|
clear() {
|
|
82
213
|
this._graph.nodes.length = 0;
|
|
83
214
|
this._graph.edges.length = 0;
|
|
@@ -96,117 +227,153 @@ var GraphModel = class _GraphModel extends ReadonlyGraphModel {
|
|
|
96
227
|
return this;
|
|
97
228
|
}
|
|
98
229
|
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
|
+
});
|
|
99
248
|
this._graph.nodes.push(node);
|
|
100
|
-
return
|
|
249
|
+
return node;
|
|
101
250
|
}
|
|
102
251
|
addNodes(nodes) {
|
|
103
|
-
nodes.
|
|
104
|
-
return this;
|
|
252
|
+
return nodes.map((node) => this.addNode(node));
|
|
105
253
|
}
|
|
106
254
|
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
|
+
});
|
|
107
288
|
this._graph.edges.push(edge);
|
|
108
|
-
return
|
|
289
|
+
return edge;
|
|
109
290
|
}
|
|
110
291
|
addEdges(edges) {
|
|
111
|
-
edges.
|
|
112
|
-
return this;
|
|
292
|
+
return edges.map((edge) => this.addEdge(edge));
|
|
113
293
|
}
|
|
114
|
-
// TODO(burdon): Return graph.
|
|
115
294
|
removeNode(id) {
|
|
116
|
-
const nodes =
|
|
117
|
-
const edges =
|
|
118
|
-
return
|
|
295
|
+
const nodes = removeBy(this._graph.nodes, (node) => node.id === id);
|
|
296
|
+
const edges = removeBy(this._graph.edges, (edge) => edge.source === id || edge.target === id);
|
|
297
|
+
return this.copy({
|
|
119
298
|
nodes,
|
|
120
299
|
edges
|
|
121
300
|
});
|
|
122
301
|
}
|
|
123
302
|
removeNodes(ids) {
|
|
124
303
|
const graphs = ids.map((id) => this.removeNode(id));
|
|
125
|
-
return
|
|
304
|
+
return this.copy().addGraphs(graphs);
|
|
126
305
|
}
|
|
127
306
|
removeEdge(id) {
|
|
128
|
-
const edges =
|
|
129
|
-
return
|
|
307
|
+
const edges = removeBy(this._graph.edges, (edge) => edge.id === id);
|
|
308
|
+
return this.copy({
|
|
309
|
+
nodes: [],
|
|
130
310
|
edges
|
|
131
311
|
});
|
|
132
312
|
}
|
|
133
313
|
removeEdges(ids) {
|
|
134
314
|
const graphs = ids.map((id) => this.removeEdge(id));
|
|
135
|
-
return
|
|
315
|
+
return this.copy().addGraphs(graphs);
|
|
136
316
|
}
|
|
137
317
|
};
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
318
|
+
var AbstractGraphBuilder = class {
|
|
319
|
+
constructor(_model) {
|
|
320
|
+
this._model = _model;
|
|
321
|
+
}
|
|
322
|
+
get model() {
|
|
323
|
+
return this._model;
|
|
324
|
+
}
|
|
325
|
+
call(cb) {
|
|
326
|
+
cb(this);
|
|
327
|
+
return this;
|
|
328
|
+
}
|
|
329
|
+
getNode(id) {
|
|
330
|
+
return this.model.getNode(id);
|
|
331
|
+
}
|
|
332
|
+
addNode(node) {
|
|
333
|
+
this._model.addNode(node);
|
|
334
|
+
return this;
|
|
335
|
+
}
|
|
336
|
+
addEdge(edge) {
|
|
337
|
+
this._model.addEdge(edge);
|
|
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
|
+
}
|
|
158
348
|
};
|
|
159
|
-
var
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
349
|
+
var GraphModel = class _GraphModel extends AbstractGraphModel {
|
|
350
|
+
get builder() {
|
|
351
|
+
return new GraphBuilder(this);
|
|
352
|
+
}
|
|
353
|
+
copy(graph) {
|
|
354
|
+
return new _GraphModel({
|
|
355
|
+
nodes: graph?.nodes ?? [],
|
|
356
|
+
edges: graph?.edges ?? []
|
|
166
357
|
});
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
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;
|
|
358
|
+
}
|
|
359
|
+
};
|
|
360
|
+
var GraphBuilder = class extends AbstractGraphBuilder {
|
|
361
|
+
call(cb) {
|
|
362
|
+
cb(this);
|
|
363
|
+
return this;
|
|
364
|
+
}
|
|
200
365
|
};
|
|
201
366
|
export {
|
|
367
|
+
AbstractGraphBuilder,
|
|
368
|
+
AbstractGraphModel,
|
|
202
369
|
BaseGraphEdge,
|
|
203
370
|
BaseGraphNode,
|
|
204
371
|
Graph,
|
|
372
|
+
GraphBuilder,
|
|
205
373
|
GraphModel,
|
|
206
374
|
ReadonlyGraphModel,
|
|
207
375
|
createEdgeId,
|
|
208
376
|
createGraph,
|
|
209
|
-
emptyGraph,
|
|
210
377
|
parseEdgeId
|
|
211
378
|
};
|
|
212
379
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../../src/
|
|
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": ";
|
|
6
|
-
"names": ["FormatEnum", "invariant", "getSchema", "
|
|
3
|
+
"sources": ["../../../src/model.ts", "../../../src/util.ts", "../../../src/types.ts"],
|
|
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 2024 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": ";AAIA,SAASA,qBAAqB;AAC9B,SAASC,iBAAiBC,aAAAA,kBAAiB;AAC3C,SAASC,mBAAmB;AAC5B,SAA4BC,YAAYC,UAAUC,sBAAsB;;;ACFxE,SAASC,kBAAkB;AAC3B,SAASC,iBAAiB;AAC1B,SAASC,WAAWC,cAAc;AAClC,SAASC,WAAW;AACpB,SAASC,2BAA2B;;;ACLpC,SAASC,SAAS;AAGX,IAAMC,gBAAgBC,EAAEC,OAAO;EACpCC,IAAIF,EAAEG;EACNC,MAAMJ,EAAEK,SAASL,EAAEG,MAAM;EACzBG,MAAMN,EAAEK,SAASL,EAAEO,GAAG;AACxB,CAAA;AAcO,IAAMC,gBAAgBR,EAAEC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,IAAAA;AACpB,WAAO;EACT;EAEAmC,QAAQ5B,MAAsC;AAC5C,SAAKsC,OAAOV,QAAQ5B,IAAAA;AACpB,WAAO;EACT;EAEAoB,SAASxC,OAAqB;AAC5B,SAAK0D,OAAOlB,SAASxC,KAAAA;AACrB,WAAO;EACT;EAEAyC,SAASxC,OAAqB;AAC5B,SAAKyD,OAAOjB,SAASxC,KAAAA;AACrB,WAAO;EACT;AACF;AAEO,IAAM6D,aAAN,MAAMA,oBAGH1B,mBAAAA;EACR,IAAa2B,UAAU;AACrB,WAAO,IAAIC,aAAyB,IAAI;EAC1C;EAESZ,KAAKtD,OAAwB;AACpC,WAAO,IAAIgE,YAAuB;MAAE9D,OAAOF,OAAOE,SAAS,CAAA;MAAIC,OAAOH,OAAOG,SAAS,CAAA;IAAG,CAAA;EAC3F;AACF;AAEO,IAAM+D,eAAN,cAGGP,qBAAAA;EACCG,KAAKC,IAA6B;AACzCA,OAAG,IAAI;AACP,WAAO;EACT;AACF;",
|
|
6
|
+
"names": ["inspectCustom", "failedInvariant", "invariant", "getSnapshot", "isNotFalsy", "removeBy", "stripUndefined", "FormatEnum", "invariant", "getSchema", "create", "log", "getSchemaProperties", "S", "BaseGraphNode", "S", "Struct", "id", "String", "type", "optional", "data", "Any", "BaseGraphEdge", "source", "target", "ExtendableBaseGraphNode", "extend", "key", "value", "Graph", "nodes", "mutable", "Array", "edges", "KEY_REGEX", "createEdgeId", "source", "target", "relation", "invariant", "match", "join", "parseEdgeId", "id", "split", "length", "undefined", "createGraph", "objects", "graph", "GraphModel", "create", "Graph", "nodes", "edges", "forEach", "object", "addNode", "type", "typename", "data", "schema", "getSchema", "log", "info", "slice", "prop", "getSchemaProperties", "ast", "format", "FormatEnum", "Ref", "name", "addEdge", "String", "ReadonlyGraphModel", "constructor", "graph", "_graph", "nodes", "edges", "inspectCustom", "toJSON", "id", "getSnapshot", "sort", "a", "b", "localeCompare", "stripUndefined", "findNode", "find", "node", "getNode", "failedInvariant", "filterNodes", "type", "filter", "findEdge", "edge", "getEdge", "filterEdges", "source", "target", "traverse", "root", "_traverse", "visited", "Set", "has", "add", "targets", "map", "isNotFalsy", "flatMap", "AbstractGraphModel", "clear", "length", "addGraph", "addNodes", "addEdges", "addGraphs", "graphs", "forEach", "addNode", "invariant", "push", "addEdge", "createEdgeId", "removeNode", "removeBy", "copy", "removeNodes", "ids", "removeEdge", "removeEdges", "AbstractGraphBuilder", "_model", "model", "call", "cb", "GraphModel", "builder", "GraphBuilder"]
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"packages/common/graph/src/types.ts":{"bytes":
|
|
1
|
+
{"inputs":{"packages/common/graph/src/types.ts":{"bytes":4437,"imports":[{"path":"@dxos/echo-schema","kind":"import-statement","external":true}],"format":"esm"},"packages/common/graph/src/util.ts":{"bytes":9104,"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/model.ts","kind":"import-statement","original":"./model"},{"path":"packages/common/graph/src/types.ts","kind":"import-statement","original":"./types"}],"format":"esm"},"packages/common/graph/src/model.ts":{"bytes":23788,"imports":[{"path":"@dxos/debug","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/live-object","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"packages/common/graph/src/util.ts","kind":"import-statement","original":"./util"}],"format":"esm"},"packages/common/graph/src/index.ts":{"bytes":647,"imports":[{"path":"packages/common/graph/src/model.ts","kind":"import-statement","original":"./model"},{"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"}},"outputs":{"packages/common/graph/dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":18688},"packages/common/graph/dist/lib/browser/index.mjs":{"imports":[{"path":"@dxos/debug","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/live-object","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"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/echo-schema","kind":"import-statement","external":true}],"exports":["AbstractGraphBuilder","AbstractGraphModel","BaseGraphEdge","BaseGraphNode","Graph","GraphBuilder","GraphModel","ReadonlyGraphModel","createEdgeId","createGraph","parseEdgeId"],"entryPoint":"packages/common/graph/src/index.ts","inputs":{"packages/common/graph/src/model.ts":{"bytesInOutput":5449},"packages/common/graph/src/util.ts":{"bytesInOutput":2277},"packages/common/graph/src/types.ts":{"bytesInOutput":551},"packages/common/graph/src/index.ts":{"bytesInOutput":0}},"bytes":8702}}}
|