@dxos/app-graph 0.6.3-main.9e4e207 → 0.6.3-main.a95c491
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/dist/lib/browser/index.mjs +76 -85
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +75 -84
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/types/src/graph-builder.d.ts.map +1 -1
- package/dist/types/src/graph.d.ts +10 -10
- package/dist/types/src/graph.d.ts.map +1 -1
- package/dist/types/src/stories/EchoGraph.stories.d.ts.map +1 -1
- package/package.json +13 -13
- package/src/graph-builder.test.ts +30 -18
- package/src/graph-builder.ts +30 -35
- package/src/graph.ts +54 -54
- package/src/stories/EchoGraph.stories.tsx +10 -4
package/dist/lib/node/index.cjs
CHANGED
|
@@ -69,7 +69,6 @@ var ROOT_ID = "root";
|
|
|
69
69
|
var ROOT_TYPE = "dxos.org/type/GraphRoot";
|
|
70
70
|
var ACTION_TYPE = "dxos.org/type/GraphAction";
|
|
71
71
|
var ACTION_GROUP_TYPE = "dxos.org/type/GraphActionGroup";
|
|
72
|
-
var NODE_TIMEOUT = 5e3;
|
|
73
72
|
var Graph = class {
|
|
74
73
|
constructor({ onInitialNode, onInitialNodes, onRemoveNode } = {}) {
|
|
75
74
|
this._waitingForNodes = {};
|
|
@@ -105,11 +104,9 @@ var Graph = class {
|
|
|
105
104
|
/**
|
|
106
105
|
* Convert the graph to a JSON object.
|
|
107
106
|
*/
|
|
108
|
-
toJSON({ id = ROOT_ID, maxLength = 32
|
|
107
|
+
toJSON({ id = ROOT_ID, maxLength = 32 } = {}) {
|
|
109
108
|
const toJSON = (node, seen = []) => {
|
|
110
|
-
const nodes = this.nodes(node
|
|
111
|
-
onlyLoaded
|
|
112
|
-
});
|
|
109
|
+
const nodes = this.nodes(node);
|
|
113
110
|
const obj = {
|
|
114
111
|
id: node.id.length > maxLength ? `${node.id.slice(0, maxLength - 3)}...` : node.id,
|
|
115
112
|
type: node.type
|
|
@@ -131,7 +128,7 @@ var Graph = class {
|
|
|
131
128
|
const root = this.findNode(id);
|
|
132
129
|
(0, import_invariant.invariant)(root, `Node not found: ${id}`, {
|
|
133
130
|
F: __dxlog_file,
|
|
134
|
-
L:
|
|
131
|
+
L: 134,
|
|
135
132
|
S: this,
|
|
136
133
|
A: [
|
|
137
134
|
"root",
|
|
@@ -146,10 +143,12 @@ var Graph = class {
|
|
|
146
143
|
* If a node is not found within the graph and an `onInitialNode` callback is provided,
|
|
147
144
|
* it is called with the id and type of the node, potentially initializing the node.
|
|
148
145
|
*/
|
|
149
|
-
findNode(id
|
|
146
|
+
findNode(id) {
|
|
150
147
|
const existingNode = this._nodes[id];
|
|
151
|
-
|
|
152
|
-
|
|
148
|
+
if (!existingNode) {
|
|
149
|
+
void this._onInitialNode?.(id);
|
|
150
|
+
}
|
|
151
|
+
return existingNode;
|
|
153
152
|
}
|
|
154
153
|
/**
|
|
155
154
|
* Wait for a node to be added to the graph.
|
|
@@ -159,25 +158,29 @@ var Graph = class {
|
|
|
159
158
|
* @param id The id of the node to wait for.
|
|
160
159
|
* @param timeout The time in milliseconds to wait for the node to be added.
|
|
161
160
|
*/
|
|
162
|
-
waitForNode(id, timeout
|
|
163
|
-
if (this._nodes[id]) {
|
|
164
|
-
return Promise.resolve(this._nodes[id]);
|
|
165
|
-
}
|
|
161
|
+
async waitForNode(id, timeout) {
|
|
166
162
|
const trigger = this._waitingForNodes[id] ?? (this._waitingForNodes[id] = new import_async.Trigger());
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
163
|
+
const node = this.findNode(id);
|
|
164
|
+
if (node) {
|
|
165
|
+
delete this._waitingForNodes[id];
|
|
166
|
+
return node;
|
|
167
|
+
}
|
|
168
|
+
if (timeout === void 0) {
|
|
169
|
+
return trigger.wait();
|
|
170
|
+
} else {
|
|
171
|
+
return (0, import_async.asyncTimeout)(trigger.wait(), timeout, `Node not found: ${id}`);
|
|
172
|
+
}
|
|
170
173
|
}
|
|
171
174
|
/**
|
|
172
175
|
* Nodes that this node is connected to in default order.
|
|
173
176
|
*/
|
|
174
177
|
nodes(node, options = {}) {
|
|
175
|
-
const {
|
|
178
|
+
const { relation, expansion, filter, type } = options;
|
|
176
179
|
const nodes = this._getNodes({
|
|
177
180
|
node,
|
|
178
181
|
relation,
|
|
179
|
-
|
|
180
|
-
|
|
182
|
+
expansion,
|
|
183
|
+
type
|
|
181
184
|
});
|
|
182
185
|
return nodes.filter((n) => (0, import_signals_core.untracked)(() => !isActionLike(n))).filter((n) => filter?.(n, node) ?? true);
|
|
183
186
|
}
|
|
@@ -190,20 +193,28 @@ var Graph = class {
|
|
|
190
193
|
/**
|
|
191
194
|
* Actions or action groups that this node is connected to in default order.
|
|
192
195
|
*/
|
|
193
|
-
actions(node, {
|
|
196
|
+
actions(node, { expansion } = {}) {
|
|
194
197
|
return [
|
|
195
198
|
...this._getNodes({
|
|
196
199
|
node,
|
|
197
|
-
|
|
198
|
-
|
|
200
|
+
expansion,
|
|
201
|
+
type: ACTION_GROUP_TYPE
|
|
199
202
|
}),
|
|
200
203
|
...this._getNodes({
|
|
201
204
|
node,
|
|
202
|
-
|
|
203
|
-
|
|
205
|
+
expansion,
|
|
206
|
+
type: ACTION_TYPE
|
|
204
207
|
})
|
|
205
208
|
];
|
|
206
209
|
}
|
|
210
|
+
async expand(node, relation = "outbound", type) {
|
|
211
|
+
const key = `${node.id}-${relation}-${type}`;
|
|
212
|
+
const initialized = this._initialized[key];
|
|
213
|
+
if (!initialized && this._onInitialNodes) {
|
|
214
|
+
await this._onInitialNodes(node, relation, type);
|
|
215
|
+
this._initialized[key] = true;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
207
218
|
/**
|
|
208
219
|
* Recursive depth-first traversal of the graph.
|
|
209
220
|
*
|
|
@@ -211,7 +222,7 @@ var Graph = class {
|
|
|
211
222
|
* @param options.relation The relation to traverse graph edges.
|
|
212
223
|
* @param options.visitor A callback which is called for each node visited during traversal.
|
|
213
224
|
*/
|
|
214
|
-
traverse({ visitor, node = this.root, relation = "outbound",
|
|
225
|
+
traverse({ visitor, node = this.root, relation = "outbound", expansion }, path = []) {
|
|
215
226
|
if (path.includes(node.id)) {
|
|
216
227
|
return;
|
|
217
228
|
}
|
|
@@ -225,12 +236,12 @@ var Graph = class {
|
|
|
225
236
|
Object.values(this._getNodes({
|
|
226
237
|
node,
|
|
227
238
|
relation,
|
|
228
|
-
|
|
239
|
+
expansion
|
|
229
240
|
})).forEach((child) => this.traverse({
|
|
230
241
|
node: child,
|
|
231
242
|
relation,
|
|
232
243
|
visitor,
|
|
233
|
-
|
|
244
|
+
expansion
|
|
234
245
|
}, [
|
|
235
246
|
...path,
|
|
236
247
|
node.id
|
|
@@ -243,7 +254,7 @@ var Graph = class {
|
|
|
243
254
|
* @param options.relation The relation to traverse graph edges.
|
|
244
255
|
* @param options.visitor A callback which is called for each node visited during traversal.
|
|
245
256
|
*/
|
|
246
|
-
subscribeTraverse({ visitor, node = this.root, relation = "outbound",
|
|
257
|
+
subscribeTraverse({ visitor, node = this.root, relation = "outbound", expansion }, currentPath = []) {
|
|
247
258
|
return (0, import_signals_core.effect)(() => {
|
|
248
259
|
const path = [
|
|
249
260
|
...currentPath,
|
|
@@ -256,12 +267,12 @@ var Graph = class {
|
|
|
256
267
|
const nodes = this._getNodes({
|
|
257
268
|
node,
|
|
258
269
|
relation,
|
|
259
|
-
|
|
270
|
+
expansion
|
|
260
271
|
});
|
|
261
272
|
const nodeSubscriptions = nodes.map((n) => this.subscribeTraverse({
|
|
262
273
|
node: n,
|
|
263
274
|
visitor,
|
|
264
|
-
|
|
275
|
+
expansion
|
|
265
276
|
}, path));
|
|
266
277
|
return () => {
|
|
267
278
|
nodeSubscriptions.forEach((unsubscribe) => unsubscribe());
|
|
@@ -278,7 +289,6 @@ var Graph = class {
|
|
|
278
289
|
}
|
|
279
290
|
let found;
|
|
280
291
|
this.traverse({
|
|
281
|
-
onlyLoaded: true,
|
|
282
292
|
node: start,
|
|
283
293
|
visitor: (node, path) => {
|
|
284
294
|
if (found) {
|
|
@@ -371,8 +381,7 @@ var Graph = class {
|
|
|
371
381
|
}
|
|
372
382
|
if (edges) {
|
|
373
383
|
this._getNodes({
|
|
374
|
-
node
|
|
375
|
-
onlyLoaded: true
|
|
384
|
+
node
|
|
376
385
|
}).forEach((node2) => {
|
|
377
386
|
this._removeEdge({
|
|
378
387
|
source: id,
|
|
@@ -381,8 +390,7 @@ var Graph = class {
|
|
|
381
390
|
});
|
|
382
391
|
this._getNodes({
|
|
383
392
|
node,
|
|
384
|
-
relation: "inbound"
|
|
385
|
-
onlyLoaded: true
|
|
393
|
+
relation: "inbound"
|
|
386
394
|
}).forEach((node2) => {
|
|
387
395
|
this._removeEdge({
|
|
388
396
|
source: node2.id,
|
|
@@ -392,7 +400,7 @@ var Graph = class {
|
|
|
392
400
|
delete this._edges[id];
|
|
393
401
|
}
|
|
394
402
|
delete this._nodes[id];
|
|
395
|
-
this._onRemoveNode?.(id);
|
|
403
|
+
void this._onRemoveNode?.(id);
|
|
396
404
|
});
|
|
397
405
|
}
|
|
398
406
|
/**
|
|
@@ -473,22 +481,9 @@ var Graph = class {
|
|
|
473
481
|
});
|
|
474
482
|
});
|
|
475
483
|
}
|
|
476
|
-
_getNodes({ node, relation = "outbound", type,
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
if (!initialized && !onlyLoaded && this._onInitialNodes) {
|
|
480
|
-
const args = this._onInitialNodes(node, relation, type)?.filter((n) => !type || n.type === type);
|
|
481
|
-
this._initialized[key] = true;
|
|
482
|
-
if (args && args.length > 0) {
|
|
483
|
-
const nodes = this._addNodes(args);
|
|
484
|
-
this._addEdges(nodes.map(({ id }) => relation === "outbound" ? {
|
|
485
|
-
source: node.id,
|
|
486
|
-
target: id
|
|
487
|
-
} : {
|
|
488
|
-
source: id,
|
|
489
|
-
target: node.id
|
|
490
|
-
}));
|
|
491
|
-
}
|
|
484
|
+
_getNodes({ node, relation = "outbound", type, expansion }) {
|
|
485
|
+
if (expansion) {
|
|
486
|
+
void this.expand(node, relation, type);
|
|
492
487
|
}
|
|
493
488
|
const edges = this._edges[node.id];
|
|
494
489
|
if (!edges) {
|
|
@@ -606,7 +601,7 @@ var GraphBuilder = class {
|
|
|
606
601
|
this._connectorSubscriptions = /* @__PURE__ */ new Map();
|
|
607
602
|
this._nodeChanged = {};
|
|
608
603
|
this._graph = new Graph({
|
|
609
|
-
onInitialNode: (id
|
|
604
|
+
onInitialNode: (id) => this._onInitialNode(id),
|
|
610
605
|
onInitialNodes: (node, relation, type) => this._onInitialNodes(node, relation, type),
|
|
611
606
|
onRemoveNode: (id) => this._onRemoveNode(id)
|
|
612
607
|
});
|
|
@@ -669,11 +664,11 @@ var GraphBuilder = class {
|
|
|
669
664
|
node.id
|
|
670
665
|
])));
|
|
671
666
|
}
|
|
672
|
-
_onInitialNode(nodeId
|
|
667
|
+
async _onInitialNode(nodeId) {
|
|
673
668
|
this._nodeChanged[nodeId] = this._nodeChanged[nodeId] ?? (0, import_signals_core2.signal)({});
|
|
674
|
-
let
|
|
675
|
-
for (const { id,
|
|
676
|
-
if (
|
|
669
|
+
let resolved = false;
|
|
670
|
+
for (const { id, resolver } of Object.values(this._extensions)) {
|
|
671
|
+
if (resolved || !resolver) {
|
|
677
672
|
continue;
|
|
678
673
|
}
|
|
679
674
|
const unsubscribe = (0, import_signals_core2.effect)(() => {
|
|
@@ -684,29 +679,27 @@ var GraphBuilder = class {
|
|
|
684
679
|
id: nodeId
|
|
685
680
|
});
|
|
686
681
|
BuilderInternal.currentDispatcher = void 0;
|
|
687
|
-
if (node
|
|
682
|
+
if (node) {
|
|
683
|
+
resolved = true;
|
|
688
684
|
this.graph._addNodes([
|
|
689
685
|
node
|
|
690
686
|
]);
|
|
691
|
-
if (this._nodeChanged[
|
|
692
|
-
this._nodeChanged[
|
|
687
|
+
if (this._nodeChanged[node.id]) {
|
|
688
|
+
this._nodeChanged[node.id].value = {};
|
|
693
689
|
}
|
|
694
|
-
} else if (node) {
|
|
695
|
-
initialized = node;
|
|
696
690
|
}
|
|
697
691
|
});
|
|
698
|
-
if (
|
|
692
|
+
if (resolved) {
|
|
693
|
+
this._resolverSubscriptions.get(nodeId)?.();
|
|
699
694
|
this._resolverSubscriptions.set(nodeId, unsubscribe);
|
|
700
695
|
break;
|
|
701
696
|
} else {
|
|
702
697
|
unsubscribe();
|
|
703
698
|
}
|
|
704
699
|
}
|
|
705
|
-
return initialized;
|
|
706
700
|
}
|
|
707
|
-
_onInitialNodes(node, nodesRelation, nodesType) {
|
|
701
|
+
async _onInitialNodes(node, nodesRelation, nodesType) {
|
|
708
702
|
this._nodeChanged[node.id] = this._nodeChanged[node.id] ?? (0, import_signals_core2.signal)({});
|
|
709
|
-
let initialized;
|
|
710
703
|
let previous = [];
|
|
711
704
|
this._connectorSubscriptions.set(node.id, (0, import_signals_core2.effect)(() => {
|
|
712
705
|
Object.keys(this._extensions);
|
|
@@ -727,26 +720,24 @@ var GraphBuilder = class {
|
|
|
727
720
|
const ids = nodes.map((n) => n.id);
|
|
728
721
|
const removed = previous.filter((id) => !ids.includes(id));
|
|
729
722
|
previous = ids;
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
}
|
|
723
|
+
this.graph._removeNodes(removed, true);
|
|
724
|
+
this.graph._addNodes(nodes);
|
|
725
|
+
this.graph._addEdges(nodes.map(({ id }) => nodesRelation === "outbound" ? {
|
|
726
|
+
source: node.id,
|
|
727
|
+
target: id
|
|
728
|
+
} : {
|
|
729
|
+
source: id,
|
|
730
|
+
target: node.id
|
|
731
|
+
}));
|
|
732
|
+
this.graph._sortEdges(node.id, nodesRelation, nodes.map(({ id }) => id));
|
|
733
|
+
nodes.forEach((n) => {
|
|
734
|
+
if (this._nodeChanged[n.id]) {
|
|
735
|
+
this._nodeChanged[n.id].value = {};
|
|
736
|
+
}
|
|
737
|
+
});
|
|
746
738
|
}));
|
|
747
|
-
return initialized;
|
|
748
739
|
}
|
|
749
|
-
_onRemoveNode(nodeId) {
|
|
740
|
+
async _onRemoveNode(nodeId) {
|
|
750
741
|
this._resolverSubscriptions.get(nodeId)?.();
|
|
751
742
|
this._connectorSubscriptions.get(nodeId)?.();
|
|
752
743
|
this._resolverSubscriptions.delete(nodeId);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/graph.ts", "../../../src/node.ts", "../../../src/graph-builder.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { batch, effect, untracked } from '@preact/signals-core';\n\nimport { Trigger } from '@dxos/async';\nimport { type ReactiveObject, create } from '@dxos/echo-schema';\nimport { invariant } from '@dxos/invariant';\nimport { nonNullable } from '@dxos/util';\n\nimport { type Relation, type Node, type NodeArg, type NodeFilter, isActionLike } from './node';\n\nconst graphSymbol = Symbol('graph');\ntype DeepWriteable<T> = { -readonly [K in keyof T]: DeepWriteable<T[K]> };\ntype NodeInternal = DeepWriteable<Node> & { [graphSymbol]: Graph };\n\nexport const getGraph = (node: Node): Graph => {\n const graph = (node as NodeInternal)[graphSymbol];\n invariant(graph, 'Node is not associated with a graph.');\n return graph;\n};\n\nexport const ROOT_ID = 'root';\nexport const ROOT_TYPE = 'dxos.org/type/GraphRoot';\nexport const ACTION_TYPE = 'dxos.org/type/GraphAction';\nexport const ACTION_GROUP_TYPE = 'dxos.org/type/GraphActionGroup';\n\nconst NODE_TIMEOUT = 5_000;\n\nexport type NodesOptions<T = any, U extends Record<string, any> = Record<string, any>> = {\n relation?: Relation;\n filter?: NodeFilter<T, U>;\n onlyLoaded?: boolean;\n type?: string;\n};\n\nexport type GraphTraversalOptions = {\n /**\n * A callback which is called for each node visited during traversal.\n *\n * If the callback returns `false`, traversal is stops recursing.\n */\n visitor: (node: Node, path: string[]) => boolean | void;\n\n /**\n * The node to start traversing from.\n *\n * @default root\n */\n node?: Node;\n\n /**\n * The relation to traverse graph edges.\n *\n * @default 'outbound'\n */\n relation?: Relation;\n\n /**\n * Only traverse nodes that are already loaded.\n */\n onlyLoaded?: boolean;\n};\n\n/**\n * The Graph represents the structure of the application constructed via plugins.\n */\nexport class Graph {\n private readonly _onInitialNode?: (id: string, type?: string) => NodeArg<any> | undefined;\n private readonly _onInitialNodes?: (node: Node, relation: Relation, type?: string) => NodeArg<any>[] | undefined;\n private readonly _onRemoveNode?: (id: string) => void;\n\n private readonly _waitingForNodes: Record<string, Trigger<Node>> = {};\n private readonly _initialized: Record<string, boolean> = {};\n\n /**\n * @internal\n */\n readonly _nodes: Record<string, ReactiveObject<NodeInternal>> = {};\n\n /**\n * @internal\n */\n readonly _edges: Record<string, ReactiveObject<{ inbound: string[]; outbound: string[] }>> = {};\n\n constructor({\n onInitialNode,\n onInitialNodes,\n onRemoveNode,\n }: {\n onInitialNode?: Graph['_onInitialNode'];\n onInitialNodes?: Graph['_onInitialNodes'];\n onRemoveNode?: Graph['_onRemoveNode'];\n } = {}) {\n this._onInitialNode = onInitialNode;\n this._onInitialNodes = onInitialNodes;\n this._onRemoveNode = onRemoveNode;\n this._nodes[ROOT_ID] = this._constructNode({ id: ROOT_ID, type: ROOT_TYPE, properties: {}, data: null });\n this._edges[ROOT_ID] = create({ inbound: [], outbound: [] });\n }\n\n /**\n * Alias for `findNode('root')`.\n */\n get root() {\n return this.findNode(ROOT_ID)!;\n }\n\n /**\n * Convert the graph to a JSON object.\n */\n toJSON({\n id = ROOT_ID,\n maxLength = 32,\n onlyLoaded = true,\n }: { id?: string; maxLength?: number; onlyLoaded?: boolean } = {}) {\n const toJSON = (node: Node, seen: string[] = []): any => {\n const nodes = this.nodes(node, { onlyLoaded });\n const obj: Record<string, any> = {\n id: node.id.length > maxLength ? `${node.id.slice(0, maxLength - 3)}...` : node.id,\n type: node.type,\n };\n if (node.properties.label) {\n obj.label = node.properties.label;\n }\n if (nodes.length) {\n obj.nodes = nodes\n .map((n) => {\n // Break cycles.\n const nextSeen = [...seen, node.id];\n return nextSeen.includes(n.id) ? undefined : toJSON(n, nextSeen);\n })\n .filter(nonNullable);\n }\n return obj;\n };\n\n const root = this.findNode(id);\n invariant(root, `Node not found: ${id}`);\n return toJSON(root);\n }\n\n /**\n * Find the node with the given id in the graph.\n *\n * If a node is not found within the graph and an `onInitialNode` callback is provided,\n * it is called with the id and type of the node, potentially initializing the node.\n */\n findNode(id: string, type?: string): Node | undefined {\n const existingNode = this._nodes[id];\n const nodeArg = !existingNode && this._onInitialNode?.(id, type);\n return existingNode ?? (nodeArg ? this._addNode(nodeArg) : undefined);\n }\n\n /**\n * Wait for a node to be added to the graph.\n *\n * If the node is already present in the graph, the promise resolves immediately.\n *\n * @param id The id of the node to wait for.\n * @param timeout The time in milliseconds to wait for the node to be added.\n */\n waitForNode(id: string, timeout = NODE_TIMEOUT): Promise<Node> {\n if (this._nodes[id]) {\n return Promise.resolve(this._nodes[id]);\n }\n\n const trigger = this._waitingForNodes[id] ?? (this._waitingForNodes[id] = new Trigger<Node>());\n return trigger.wait({ timeout });\n }\n\n /**\n * Nodes that this node is connected to in default order.\n */\n nodes<T = any, U extends Record<string, any> = Record<string, any>>(node: Node, options: NodesOptions<T, U> = {}) {\n const { onlyLoaded, relation, filter, type } = options;\n const nodes = this._getNodes({ node, relation, type, onlyLoaded });\n return nodes.filter((n) => untracked(() => !isActionLike(n))).filter((n) => filter?.(n, node) ?? true);\n }\n\n /**\n * Edges that this node is connected to in default order.\n */\n edges(node: Node, { relation = 'outbound' }: { relation?: Relation } = {}) {\n return this._edges[node.id]?.[relation] ?? [];\n }\n\n /**\n * Actions or action groups that this node is connected to in default order.\n */\n actions(node: Node, { onlyLoaded }: { onlyLoaded?: boolean } = {}) {\n return [\n ...this._getNodes({ node, type: ACTION_GROUP_TYPE, onlyLoaded }),\n ...this._getNodes({ node, type: ACTION_TYPE, onlyLoaded }),\n ];\n }\n\n /**\n * Recursive depth-first traversal of the graph.\n *\n * @param options.node The node to start traversing from.\n * @param options.relation The relation to traverse graph edges.\n * @param options.visitor A callback which is called for each node visited during traversal.\n */\n traverse(\n { visitor, node = this.root, relation = 'outbound', onlyLoaded }: GraphTraversalOptions,\n path: string[] = [],\n ): void {\n // Break cycles.\n if (path.includes(node.id)) {\n return;\n }\n\n const shouldContinue = visitor(node, [...path, node.id]);\n if (shouldContinue === false) {\n return;\n }\n\n Object.values(this._getNodes({ node, relation, onlyLoaded })).forEach((child) =>\n this.traverse({ node: child, relation, visitor, onlyLoaded }, [...path, node.id]),\n );\n }\n\n /**\n * Recursive depth-first traversal of the graph wrapping each visitor call in an effect.\n *\n * @param options.node The node to start traversing from.\n * @param options.relation The relation to traverse graph edges.\n * @param options.visitor A callback which is called for each node visited during traversal.\n */\n subscribeTraverse(\n { visitor, node = this.root, relation = 'outbound', onlyLoaded }: GraphTraversalOptions,\n currentPath: string[] = [],\n ) {\n return effect(() => {\n const path = [...currentPath, node.id];\n const result = visitor(node, path);\n if (result === false) {\n return;\n }\n\n const nodes = this._getNodes({ node, relation, onlyLoaded });\n const nodeSubscriptions = nodes.map((n) => this.subscribeTraverse({ node: n, visitor, onlyLoaded }, path));\n\n return () => {\n nodeSubscriptions.forEach((unsubscribe) => unsubscribe());\n };\n });\n }\n\n /**\n * Get the path between two nodes in the graph.\n */\n getPath({ source = 'root', target }: { source?: string; target: string }): string[] | undefined {\n const start = this.findNode(source);\n if (!start) {\n return undefined;\n }\n\n let found: string[] | undefined;\n this.traverse({\n onlyLoaded: true,\n node: start,\n visitor: (node, path) => {\n if (found) {\n return false;\n }\n\n if (node.id === target) {\n found = path;\n }\n },\n });\n\n return found;\n }\n\n /**\n * Add nodes to the graph.\n *\n * @internal\n */\n _addNodes<TData = null, TProperties extends Record<string, any> = Record<string, any>>(\n nodes: NodeArg<TData, TProperties>[],\n ): Node<TData, TProperties>[] {\n return batch(() => nodes.map((node) => this._addNode(node)));\n }\n\n private _addNode<TData, TProperties extends Record<string, any> = Record<string, any>>({\n nodes,\n edges,\n ..._node\n }: NodeArg<TData, TProperties>): Node<TData, TProperties> {\n return untracked(() => {\n const existingNode = this._nodes[_node.id];\n const node = existingNode ?? this._constructNode({ data: null, properties: {}, ..._node });\n if (existingNode) {\n const { data, properties, type } = _node;\n if (data && data !== node.data) {\n node.data = data;\n }\n\n if (type !== node.type) {\n node.type = type;\n }\n\n for (const key in properties) {\n if (properties[key] !== node.properties[key]) {\n node.properties[key] = properties[key];\n }\n }\n } else {\n this._nodes[node.id] = node;\n this._edges[node.id] = create({ inbound: [], outbound: [] });\n }\n\n const trigger = this._waitingForNodes[node.id];\n if (trigger) {\n trigger.wake(node);\n delete this._waitingForNodes[node.id];\n }\n\n if (nodes) {\n nodes.forEach((subNode) => {\n this._addNode(subNode);\n this._addEdge({ source: node.id, target: subNode.id });\n });\n }\n\n if (edges) {\n edges.forEach(([id, relation]) =>\n relation === 'outbound'\n ? this._addEdge({ source: node.id, target: id })\n : this._addEdge({ source: id, target: node.id }),\n );\n }\n\n return node as unknown as Node<TData, TProperties>;\n });\n }\n\n /**\n * Remove nodes from the graph.\n *\n * @param ids The id of the node to remove.\n * @param edges Whether to remove edges connected to the node from the graph as well.\n * @internal\n */\n _removeNodes(ids: string[], edges = false) {\n batch(() => ids.forEach((id) => this._removeNode(id, edges)));\n }\n\n private _removeNode(id: string, edges = false) {\n untracked(() => {\n const node = this.findNode(id);\n if (!node) {\n return;\n }\n\n if (edges) {\n // Remove edges from connected nodes.\n this._getNodes({ node, onlyLoaded: true }).forEach((node) => {\n this._removeEdge({ source: id, target: node.id });\n });\n this._getNodes({ node, relation: 'inbound', onlyLoaded: true }).forEach((node) => {\n this._removeEdge({ source: node.id, target: id });\n });\n\n // Remove edges from node.\n delete this._edges[id];\n }\n\n // Remove node.\n delete this._nodes[id];\n this._onRemoveNode?.(id);\n });\n }\n\n /**\n * Add edges to the graph.\n *\n * @internal\n */\n _addEdges(edges: { source: string; target: string }[]) {\n batch(() => edges.forEach((edge) => this._addEdge(edge)));\n }\n\n private _addEdge({ source, target }: { source: string; target: string }) {\n untracked(() => {\n if (!this._edges[source]) {\n this._edges[source] = create({ inbound: [], outbound: [] });\n }\n if (!this._edges[target]) {\n this._edges[target] = create({ inbound: [], outbound: [] });\n }\n\n const sourceEdges = this._edges[source];\n if (!sourceEdges.outbound.includes(target)) {\n sourceEdges.outbound.push(target);\n }\n\n const targetEdges = this._edges[target];\n if (!targetEdges.inbound.includes(source)) {\n targetEdges.inbound.push(source);\n }\n });\n }\n\n /**\n * Remove edges from the graph.\n * @internal\n */\n _removeEdges(edges: { source: string; target: string }[]) {\n batch(() => edges.forEach((edge) => this._removeEdge(edge)));\n }\n\n private _removeEdge({ source, target }: { source: string; target: string }) {\n untracked(() => {\n batch(() => {\n const outboundIndex = this._edges[source]?.outbound.findIndex((id) => id === target);\n if (outboundIndex !== undefined && outboundIndex !== -1) {\n this._edges[source].outbound.splice(outboundIndex, 1);\n }\n\n const inboundIndex = this._edges[target]?.inbound.findIndex((id) => id === source);\n if (inboundIndex !== undefined && inboundIndex !== -1) {\n this._edges[target].inbound.splice(inboundIndex, 1);\n }\n });\n });\n }\n\n /**\n * Sort edges for a node.\n *\n * Edges not included in the sorted list are appended to the end of the list.\n *\n * @param nodeId The id of the node to sort edges for.\n * @param relation The relation of the edges from the node to sort.\n * @param edges The ordered list of edges.\n * @ignore\n */\n _sortEdges(nodeId: string, relation: Relation, edges: string[]) {\n untracked(() => {\n batch(() => {\n const current = this._edges[nodeId];\n if (current) {\n const unsorted = current[relation].filter((id) => !edges.includes(id)) ?? [];\n const sorted = edges.filter((id) => current[relation].includes(id)) ?? [];\n current[relation].splice(0, current[relation].length, ...[...sorted, ...unsorted]);\n }\n });\n });\n }\n\n private _constructNode = (node: Omit<Node, typeof graphSymbol>) => {\n return create<NodeInternal>({ ...node, [graphSymbol]: this });\n };\n\n private _getNodes({\n node,\n relation = 'outbound',\n type,\n onlyLoaded,\n }: {\n node: Node;\n relation?: Relation;\n type?: string;\n onlyLoaded?: boolean;\n }): Node[] {\n // TODO(wittjosiah): Factor out helper.\n const key = `${node.id}-${relation}-${type}`;\n const initialized = this._initialized[key];\n if (!initialized && !onlyLoaded && this._onInitialNodes) {\n const args = this._onInitialNodes(node, relation, type)?.filter((n) => !type || n.type === type);\n this._initialized[key] = true;\n if (args && args.length > 0) {\n const nodes = this._addNodes(args);\n this._addEdges(\n nodes.map(({ id }) =>\n relation === 'outbound' ? { source: node.id, target: id } : { source: id, target: node.id },\n ),\n );\n }\n }\n\n const edges = this._edges[node.id];\n if (!edges) {\n return [];\n } else {\n return edges[relation]\n .map((id) => this._nodes[id])\n .filter(nonNullable)\n .filter((n) => !type || n.type === type);\n }\n }\n}\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { type MaybePromise, type MakeOptional } from '@dxos/util';\n\n/**\n * Represents a node in the graph.\n */\n// TODO(wittjosiah): Use Effect Schema.\nexport type Node<TData = any, TProperties extends Record<string, any> = Record<string, any>> = Readonly<{\n /**\n * Globally unique ID.\n */\n id: string;\n\n /**\n * Typename of the data the node represents.\n */\n type: string;\n\n /**\n * Properties of the node relevant to displaying the node.\n */\n properties: Readonly<TProperties>;\n\n /**\n * Data the node represents.\n */\n // TODO(burdon): Type system (e.g., minimally provide identifier string vs. TypedObject vs. Graph mixin type system)?\n // type field would prevent convoluted sniffing of object properties. And allow direct pass-through for ECHO TypedObjects.\n data: TData;\n}>;\n\nexport type NodeFilter<T = any, U extends Record<string, any> = Record<string, any>> = (\n node: Node<unknown, Record<string, any>>,\n connectedNode: Node,\n) => node is Node<T, U>;\n\nexport type Relation = 'outbound' | 'inbound';\n\nexport const isGraphNode = (data: unknown): data is Node =>\n data && typeof data === 'object' && 'id' in data && 'properties' in data && data.properties\n ? typeof data.properties === 'object' && 'data' in data\n : false;\n\nexport type NodeArg<TData, TProperties extends Record<string, any> = Record<string, any>> = MakeOptional<\n Node<TData, TProperties>,\n 'data' | 'properties'\n> & {\n /** Will automatically add nodes with an edge from this node to each. */\n nodes?: NodeArg<unknown>[];\n\n /** Will automatically add specified edges. */\n edges?: [string, Relation][];\n};\n\n//\n// Actions\n//\n\nexport type InvokeParams = {\n /** Node the invoked action is connected to. */\n node: Node;\n\n caller?: string;\n};\n\nexport type ActionData = (params: InvokeParams) => MaybePromise<void>;\n\nexport type Action<TProperties extends Record<string, any> = Record<string, any>> = Readonly<\n Omit<Node<ActionData, TProperties>, 'properties'> & {\n properties: Readonly<TProperties>;\n }\n>;\n\nexport const isAction = (data: unknown): data is Action =>\n isGraphNode(data) ? typeof data.data === 'function' : false;\n\nexport const actionGroupSymbol = Symbol('ActionGroup');\n\nexport type ActionGroup = Readonly<\n Omit<Node<typeof actionGroupSymbol, Record<string, any>>, 'properties'> & {\n properties: Readonly<Record<string, any>>;\n }\n>;\n\nexport const isActionGroup = (data: unknown): data is ActionGroup =>\n isGraphNode(data) ? data.data === actionGroupSymbol : false;\n\nexport type ActionLike = Action | ActionGroup;\n\nexport const isActionLike = (data: unknown): data is Action | ActionGroup => isAction(data) || isActionGroup(data);\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { type Signal, effect, signal } from '@preact/signals-core';\n// import { yieldOrContinue } from 'main-thread-scheduling';\n\nimport { type UnsubscribeCallback } from '@dxos/async';\nimport { create } from '@dxos/echo-schema';\nimport { invariant } from '@dxos/invariant';\nimport { nonNullable } from '@dxos/util';\n\nimport { ACTION_GROUP_TYPE, ACTION_TYPE, Graph } from './graph';\nimport { type Relation, type NodeArg, type Node, type ActionData, actionGroupSymbol } from './node';\n\n/**\n * Graph builder extension for adding nodes to the graph based on just the node id.\n * This is useful for creating the first node in a graph or for hydrating cached nodes with data.\n *\n * @param params.id The id of the node to resolve.\n */\nexport type ResolverExtension = (params: { id: string }) => NodeArg<any> | undefined;\n\n/**\n * Graph builder extension for adding nodes to the graph based on a connection to an existing node.\n *\n * @param params.node The existing node the returned nodes will be connected to.\n */\nexport type ConnectorExtension<T = any> = (params: { node: Node<T> }) => NodeArg<any>[] | undefined;\n\n/**\n * Constrained case of the connector extension for more easily adding actions to the graph.\n */\nexport type ActionsExtension<T = any> = (params: {\n node: Node<T>;\n}) => Omit<NodeArg<ActionData>, 'type' | 'nodes' | 'edges'>[] | undefined;\n\n/**\n * Constrained case of the connector extension for more easily adding action groups to the graph.\n */\nexport type ActionGroupsExtension<T = any> = (params: {\n node: Node<T>;\n}) => Omit<NodeArg<typeof actionGroupSymbol>, 'type' | 'data' | 'nodes' | 'edges'>[] | undefined;\n\ntype GuardedNodeType<T> = T extends (value: any) => value is infer N ? (N extends Node<infer D> ? D : unknown) : never;\n\n/**\n * A graph builder extension is used to add nodes to the graph.\n *\n * @param params.id The unique id of the extension.\n * @param params.relation The relation the graph is being expanded from the existing node.\n * @param params.type If provided, all nodes returned are expected to have this type.\n * @param params.filter A filter function to determine if an extension should act on a node.\n * @param params.resolver A function to add nodes to the graph based on just the node id.\n * @param params.connector A function to add nodes to the graph based on a connection to an existing node.\n * @param params.actions A function to add actions to the graph based on a connection to an existing node.\n * @param params.actionGroups A function to add action groups to the graph based on a connection to an existing node.\n */\nexport type CreateExtensionOptions<T = any> = {\n id: string;\n relation?: Relation;\n type?: string;\n filter?: (node: Node) => node is Node<T>;\n resolver?: ResolverExtension;\n connector?: ConnectorExtension<GuardedNodeType<CreateExtensionOptions<T>['filter']>>;\n actions?: ActionsExtension<GuardedNodeType<CreateExtensionOptions<T>['filter']>>;\n actionGroups?: ActionGroupsExtension<GuardedNodeType<CreateExtensionOptions<T>['filter']>>;\n};\n\n/**\n * Create a graph builder extension.\n */\nexport const createExtension = <T = any>(extension: CreateExtensionOptions<T>): BuilderExtension[] => {\n const { id, resolver, connector, actions, actionGroups, ...rest } = extension;\n const getId = (key: string) => `${id}/${key}`;\n return [\n resolver ? { id: getId('resolver'), resolver } : undefined,\n connector ? { ...rest, id: getId('connector'), connector } : undefined,\n actionGroups\n ? ({\n ...rest,\n id: getId('actionGroups'),\n type: ACTION_GROUP_TYPE,\n relation: 'outbound',\n connector: ({ node }) =>\n actionGroups({ node })?.map((arg) => ({ ...arg, data: actionGroupSymbol, type: ACTION_GROUP_TYPE })),\n } satisfies BuilderExtension)\n : undefined,\n actions\n ? ({\n ...rest,\n id: getId('actions'),\n type: ACTION_TYPE,\n relation: 'outbound',\n connector: ({ node }) => actions({ node })?.map((arg) => ({ ...arg, type: ACTION_TYPE })),\n } satisfies BuilderExtension)\n : undefined,\n ].filter(nonNullable);\n};\n\nexport type GraphBuilderTraverseOptions = {\n node: Node;\n relation?: Relation;\n visitor: (node: Node, path: string[]) => void;\n};\n\n/**\n * The dispatcher is used to keep track of the current extension and state when memoizing functions.\n */\nclass Dispatcher {\n currentExtension?: string;\n stateIndex = 0;\n state: Record<string, any[]> = {};\n cleanup: (() => void)[] = [];\n}\n\nclass BuilderInternal {\n // This must be static to avoid passing the dispatcher instance to every memoized function.\n // If the dispatcher is not set that means that the memoized function is being called outside of the graph builder.\n static currentDispatcher?: Dispatcher;\n}\n\n/**\n * Allows code to be memoized within the context of a graph builder extension.\n * This is useful for creating instances which should be subscribed to rather than recreated.\n */\nexport const memoize = <T>(fn: () => T, key = 'result'): T => {\n const dispatcher = BuilderInternal.currentDispatcher;\n invariant(dispatcher?.currentExtension, 'memoize must be called within an extension');\n const all = dispatcher.state[dispatcher.currentExtension][dispatcher.stateIndex] ?? {};\n const current = all[key];\n const result = current ? current.result : fn();\n dispatcher.state[dispatcher.currentExtension][dispatcher.stateIndex] = { ...all, [key]: { result } };\n dispatcher.stateIndex++;\n return result;\n};\n\n/**\n * Register a cleanup function to be called when the graph builder is destroyed.\n */\nexport const cleanup = (fn: () => void): void => {\n memoize(() => {\n const dispatcher = BuilderInternal.currentDispatcher;\n invariant(dispatcher, 'cleanup must be called within an extension');\n dispatcher.cleanup.push(fn);\n });\n};\n\n/**\n * Convert a subscribe/get pair into a signal.\n */\nexport const toSignal = <T>(\n subscribe: (onChange: () => void) => () => void,\n get: () => T | undefined,\n key?: string,\n) => {\n const thisSignal = memoize(() => {\n return signal(get());\n }, key);\n const unsubscribe = memoize(() => {\n return subscribe(() => (thisSignal.value = get()));\n }, key);\n cleanup(() => {\n unsubscribe();\n });\n return thisSignal.value;\n};\n\nexport type BuilderExtension = {\n id: string;\n resolver?: ResolverExtension;\n connector?: ConnectorExtension;\n // Only for connector.\n relation?: Relation;\n type?: string;\n filter?: (node: Node) => boolean;\n};\n\ntype ExtensionArg = BuilderExtension | BuilderExtension[] | ExtensionArg[];\n\n/**\n * The builder provides an extensible way to compose the construction of the graph.\n */\n// TODO(wittjosiah): Add api for setting subscription set and/or radius.\n// Should unsubscribe from nodes that are not in the set/radius.\n// Should track LRU nodes that are not in the set/radius and remove them beyond a certain threshold.\nexport class GraphBuilder {\n private readonly _dispatcher = new Dispatcher();\n private readonly _extensions = create<Record<string, BuilderExtension>>({});\n private readonly _resolverSubscriptions = new Map<string, UnsubscribeCallback>();\n private readonly _connectorSubscriptions = new Map<string, UnsubscribeCallback>();\n private readonly _nodeChanged: Record<string, Signal<{}>> = {};\n private _graph: Graph;\n\n constructor() {\n this._graph = new Graph({\n onInitialNode: (id, type) => this._onInitialNode(id, type),\n onInitialNodes: (node, relation, type) => this._onInitialNodes(node, relation, type),\n onRemoveNode: (id) => this._onRemoveNode(id),\n });\n }\n\n get graph() {\n return this._graph;\n }\n\n /**\n * Register a node builder which will be called in order to construct the graph.\n */\n addExtension(extension: ExtensionArg): GraphBuilder {\n if (Array.isArray(extension)) {\n extension.forEach((ext) => this.addExtension(ext));\n return this;\n }\n\n this._dispatcher.state[extension.id] = [];\n this._extensions[extension.id] = extension;\n return this;\n }\n\n /**\n * Remove a node builder from the graph builder.\n */\n removeExtension(id: string): GraphBuilder {\n delete this._extensions[id];\n return this;\n }\n\n destroy() {\n this._dispatcher.cleanup.forEach((fn) => fn());\n this._resolverSubscriptions.forEach((unsubscribe) => unsubscribe());\n this._connectorSubscriptions.forEach((unsubscribe) => unsubscribe());\n this._resolverSubscriptions.clear();\n this._connectorSubscriptions.clear();\n }\n\n /**\n * Traverse a graph using just the connector extensions, without subscribing to any signals or persisting any nodes.\n */\n // TODO(wittjosiah): Rename? This is not traversing the graph proper.\n async traverse({ node, relation = 'outbound', visitor }: GraphBuilderTraverseOptions, path: string[] = []) {\n // Break cycles.\n if (path.includes(node.id)) {\n return;\n }\n\n // TODO(wittjosiah): Failed in test environment. ESM only?\n // await yieldOrContinue('idle');\n visitor(node, [...path, node.id]);\n\n const nodes = Object.values(this._extensions)\n .filter((extension) => relation === (extension.relation ?? 'outbound'))\n .flatMap((extension) => extension.connector?.({ node }) ?? [])\n .map(\n (arg): Node => ({\n id: arg.id,\n type: arg.type,\n data: arg.data ?? null,\n properties: arg.properties ?? {},\n }),\n );\n\n await Promise.all(nodes.map((n) => this.traverse({ node: n, relation, visitor }, [...path, node.id])));\n }\n\n private _onInitialNode(nodeId: string, nodeType?: string) {\n this._nodeChanged[nodeId] = this._nodeChanged[nodeId] ?? signal({});\n let initialized: NodeArg<any> | undefined;\n for (const { id, type, resolver } of Object.values(this._extensions)) {\n if (!resolver || (nodeType && type !== nodeType)) {\n continue;\n }\n\n const unsubscribe = effect(() => {\n this._dispatcher.currentExtension = id;\n this._dispatcher.stateIndex = 0;\n BuilderInternal.currentDispatcher = this._dispatcher;\n const node = resolver({ id: nodeId });\n BuilderInternal.currentDispatcher = undefined;\n if (node && initialized) {\n this.graph._addNodes([node]);\n if (this._nodeChanged[initialized.id]) {\n this._nodeChanged[initialized.id].value = {};\n }\n } else if (node) {\n initialized = node;\n }\n });\n\n if (initialized) {\n this._resolverSubscriptions.set(nodeId, unsubscribe);\n break;\n } else {\n unsubscribe();\n }\n }\n\n return initialized;\n }\n\n private _onInitialNodes(node: Node, nodesRelation: Relation, nodesType?: string) {\n this._nodeChanged[node.id] = this._nodeChanged[node.id] ?? signal({});\n let initialized: NodeArg<any>[] | undefined;\n let previous: string[] = [];\n this._connectorSubscriptions.set(\n node.id,\n effect(() => {\n // Subscribe to extensions being added.\n Object.keys(this._extensions);\n // Subscribe to connected node changes.\n this._nodeChanged[node.id].value;\n\n // TODO(wittjosiah): Consider allowing extensions to collaborate on the same node by merging their results.\n const nodes: NodeArg<any>[] = [];\n for (const { id, connector, filter, type, relation = 'outbound' } of Object.values(this._extensions)) {\n if (\n !connector ||\n relation !== nodesRelation ||\n (nodesType && type !== nodesType) ||\n (filter && !filter(node))\n ) {\n continue;\n }\n\n this._dispatcher.currentExtension = id;\n this._dispatcher.stateIndex = 0;\n BuilderInternal.currentDispatcher = this._dispatcher;\n nodes.push(...(connector({ node }) ?? []));\n BuilderInternal.currentDispatcher = undefined;\n }\n const ids = nodes.map((n) => n.id);\n const removed = previous.filter((id) => !ids.includes(id));\n previous = ids;\n\n if (initialized) {\n this.graph._removeNodes(removed, true);\n this.graph._addNodes(nodes);\n this.graph._addEdges(nodes.map(({ id }) => ({ source: node.id, target: id })));\n this.graph._sortEdges(\n node.id,\n 'outbound',\n nodes.map(({ id }) => id),\n );\n nodes.forEach((n) => {\n if (this._nodeChanged[n.id]) {\n this._nodeChanged[n.id].value = {};\n }\n });\n } else {\n initialized = nodes;\n }\n }),\n );\n\n return initialized;\n }\n\n private _onRemoveNode(nodeId: string) {\n this._resolverSubscriptions.get(nodeId)?.();\n this._connectorSubscriptions.get(nodeId)?.();\n this._resolverSubscriptions.delete(nodeId);\n this._connectorSubscriptions.delete(nodeId);\n }\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,0BAAyC;AAEzC,mBAAwB;AACxB,yBAA4C;AAC5C,uBAA0B;AAC1B,kBAA4B;AEL5B,IAAAA,uBAA4C;AAI5C,IAAAC,sBAAuB;AACvB,IAAAC,oBAA0B;AAC1B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3E,KAAKqB;UAAIuD,QAAQvD;QAAG,EAAA,CAAA;AAC1E,aAAKpB,MAAMmG,WACTpG,KAAKqB,IACL,YACAW,MAAMK,IAAI,CAAC,EAAEhB,GAAE,MAAOA,EAAAA,CAAAA;AAExBW,cAAMkC,QAAQ,CAAC5B,MAAAA;AACb,cAAI,KAAKoG,aAAapG,EAAEjB,EAAE,GAAG;AAC3B,iBAAKqH,aAAapG,EAAEjB,EAAE,EAAE8G,QAAQ,CAAC;UACnC;QACF,CAAA;MACF,OAAO;AACL1B,sBAAczE;MAChB;IACF,CAAA,CAAA;AAGF,WAAOyE;EACT;EAEQtF,cAAckF,QAAgB;AACpC,SAAKkC,uBAAuBP,IAAI3B,MAAAA,IAAAA;AAChC,SAAKoC,wBAAwBT,IAAI3B,MAAAA,IAAAA;AACjC,SAAKkC,uBAAuBoB,OAAOtD,MAAAA;AACnC,SAAKoC,wBAAwBkB,OAAOtD,MAAAA;EACtC;AACF;",
|
|
6
|
-
"names": ["import_signals_core", "import_echo_schema", "import_invariant", "import_util", "isGraphNode", "data", "properties", "isAction", "actionGroupSymbol", "Symbol", "isActionGroup", "isActionLike", "graphSymbol", "getGraph", "node", "graph", "invariant", "ROOT_ID", "ROOT_TYPE", "ACTION_TYPE", "ACTION_GROUP_TYPE", "
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { batch, effect, untracked } from '@preact/signals-core';\n\nimport { asyncTimeout, Trigger } from '@dxos/async';\nimport { type ReactiveObject, create } from '@dxos/echo-schema';\nimport { invariant } from '@dxos/invariant';\nimport { nonNullable } from '@dxos/util';\n\nimport { type Relation, type Node, type NodeArg, type NodeFilter, isActionLike } from './node';\n\nconst graphSymbol = Symbol('graph');\ntype DeepWriteable<T> = { -readonly [K in keyof T]: DeepWriteable<T[K]> };\ntype NodeInternal = DeepWriteable<Node> & { [graphSymbol]: Graph };\n\nexport const getGraph = (node: Node): Graph => {\n const graph = (node as NodeInternal)[graphSymbol];\n invariant(graph, 'Node is not associated with a graph.');\n return graph;\n};\n\nexport const ROOT_ID = 'root';\nexport const ROOT_TYPE = 'dxos.org/type/GraphRoot';\nexport const ACTION_TYPE = 'dxos.org/type/GraphAction';\nexport const ACTION_GROUP_TYPE = 'dxos.org/type/GraphActionGroup';\n\nexport type NodesOptions<T = any, U extends Record<string, any> = Record<string, any>> = {\n relation?: Relation;\n filter?: NodeFilter<T, U>;\n expansion?: boolean;\n type?: string;\n};\n\nexport type GraphTraversalOptions = {\n /**\n * A callback which is called for each node visited during traversal.\n *\n * If the callback returns `false`, traversal is stops recursing.\n */\n visitor: (node: Node, path: string[]) => boolean | void;\n\n /**\n * The node to start traversing from.\n *\n * @default root\n */\n node?: Node;\n\n /**\n * The relation to traverse graph edges.\n *\n * @default 'outbound'\n */\n relation?: Relation;\n\n /**\n * Allow traversal to trigger expansion of the graph via `onInitialNodes`.\n */\n expansion?: boolean;\n};\n\n/**\n * The Graph represents the structure of the application constructed via plugins.\n */\nexport class Graph {\n private readonly _onInitialNode?: (id: string) => Promise<void>;\n private readonly _onInitialNodes?: (node: Node, relation: Relation, type?: string) => Promise<void>;\n private readonly _onRemoveNode?: (id: string) => Promise<void>;\n\n private readonly _waitingForNodes: Record<string, Trigger<Node>> = {};\n private readonly _initialized: Record<string, boolean> = {};\n\n /**\n * @internal\n */\n readonly _nodes: Record<string, ReactiveObject<NodeInternal>> = {};\n\n /**\n * @internal\n */\n readonly _edges: Record<string, ReactiveObject<{ inbound: string[]; outbound: string[] }>> = {};\n\n constructor({\n onInitialNode,\n onInitialNodes,\n onRemoveNode,\n }: {\n onInitialNode?: Graph['_onInitialNode'];\n onInitialNodes?: Graph['_onInitialNodes'];\n onRemoveNode?: Graph['_onRemoveNode'];\n } = {}) {\n this._onInitialNode = onInitialNode;\n this._onInitialNodes = onInitialNodes;\n this._onRemoveNode = onRemoveNode;\n this._nodes[ROOT_ID] = this._constructNode({ id: ROOT_ID, type: ROOT_TYPE, properties: {}, data: null });\n this._edges[ROOT_ID] = create({ inbound: [], outbound: [] });\n }\n\n /**\n * Alias for `findNode('root')`.\n */\n get root() {\n return this.findNode(ROOT_ID)!;\n }\n\n /**\n * Convert the graph to a JSON object.\n */\n toJSON({ id = ROOT_ID, maxLength = 32 }: { id?: string; maxLength?: number } = {}) {\n const toJSON = (node: Node, seen: string[] = []): any => {\n const nodes = this.nodes(node);\n const obj: Record<string, any> = {\n id: node.id.length > maxLength ? `${node.id.slice(0, maxLength - 3)}...` : node.id,\n type: node.type,\n };\n if (node.properties.label) {\n obj.label = node.properties.label;\n }\n if (nodes.length) {\n obj.nodes = nodes\n .map((n) => {\n // Break cycles.\n const nextSeen = [...seen, node.id];\n return nextSeen.includes(n.id) ? undefined : toJSON(n, nextSeen);\n })\n .filter(nonNullable);\n }\n return obj;\n };\n\n const root = this.findNode(id);\n invariant(root, `Node not found: ${id}`);\n return toJSON(root);\n }\n\n /**\n * Find the node with the given id in the graph.\n *\n * If a node is not found within the graph and an `onInitialNode` callback is provided,\n * it is called with the id and type of the node, potentially initializing the node.\n */\n findNode(id: string): Node | undefined {\n const existingNode = this._nodes[id];\n if (!existingNode) {\n void this._onInitialNode?.(id);\n }\n\n return existingNode;\n }\n\n /**\n * Wait for a node to be added to the graph.\n *\n * If the node is already present in the graph, the promise resolves immediately.\n *\n * @param id The id of the node to wait for.\n * @param timeout The time in milliseconds to wait for the node to be added.\n */\n async waitForNode(id: string, timeout?: number): Promise<Node> {\n const trigger = this._waitingForNodes[id] ?? (this._waitingForNodes[id] = new Trigger<Node>());\n const node = this.findNode(id);\n if (node) {\n delete this._waitingForNodes[id];\n return node;\n }\n\n if (timeout === undefined) {\n return trigger.wait();\n } else {\n return asyncTimeout(trigger.wait(), timeout, `Node not found: ${id}`);\n }\n }\n\n /**\n * Nodes that this node is connected to in default order.\n */\n nodes<T = any, U extends Record<string, any> = Record<string, any>>(node: Node, options: NodesOptions<T, U> = {}) {\n const { relation, expansion, filter, type } = options;\n const nodes = this._getNodes({ node, relation, expansion, type });\n return nodes.filter((n) => untracked(() => !isActionLike(n))).filter((n) => filter?.(n, node) ?? true);\n }\n\n /**\n * Edges that this node is connected to in default order.\n */\n edges(node: Node, { relation = 'outbound' }: { relation?: Relation } = {}) {\n return this._edges[node.id]?.[relation] ?? [];\n }\n\n /**\n * Actions or action groups that this node is connected to in default order.\n */\n actions(node: Node, { expansion }: { expansion?: boolean } = {}) {\n return [\n ...this._getNodes({ node, expansion, type: ACTION_GROUP_TYPE }),\n ...this._getNodes({ node, expansion, type: ACTION_TYPE }),\n ];\n }\n\n async expand(node: Node, relation: Relation = 'outbound', type?: string) {\n // TODO(wittjosiah): Factor out helper.\n const key = `${node.id}-${relation}-${type}`;\n const initialized = this._initialized[key];\n if (!initialized && this._onInitialNodes) {\n await this._onInitialNodes(node, relation, type);\n this._initialized[key] = true;\n }\n }\n\n /**\n * Recursive depth-first traversal of the graph.\n *\n * @param options.node The node to start traversing from.\n * @param options.relation The relation to traverse graph edges.\n * @param options.visitor A callback which is called for each node visited during traversal.\n */\n traverse(\n { visitor, node = this.root, relation = 'outbound', expansion }: GraphTraversalOptions,\n path: string[] = [],\n ): void {\n // Break cycles.\n if (path.includes(node.id)) {\n return;\n }\n\n const shouldContinue = visitor(node, [...path, node.id]);\n if (shouldContinue === false) {\n return;\n }\n\n Object.values(this._getNodes({ node, relation, expansion })).forEach((child) =>\n this.traverse({ node: child, relation, visitor, expansion }, [...path, node.id]),\n );\n }\n\n /**\n * Recursive depth-first traversal of the graph wrapping each visitor call in an effect.\n *\n * @param options.node The node to start traversing from.\n * @param options.relation The relation to traverse graph edges.\n * @param options.visitor A callback which is called for each node visited during traversal.\n */\n subscribeTraverse(\n { visitor, node = this.root, relation = 'outbound', expansion }: GraphTraversalOptions,\n currentPath: string[] = [],\n ) {\n return effect(() => {\n const path = [...currentPath, node.id];\n const result = visitor(node, path);\n if (result === false) {\n return;\n }\n\n const nodes = this._getNodes({ node, relation, expansion });\n const nodeSubscriptions = nodes.map((n) => this.subscribeTraverse({ node: n, visitor, expansion }, path));\n\n return () => {\n nodeSubscriptions.forEach((unsubscribe) => unsubscribe());\n };\n });\n }\n\n /**\n * Get the path between two nodes in the graph.\n */\n getPath({ source = 'root', target }: { source?: string; target: string }): string[] | undefined {\n const start = this.findNode(source);\n if (!start) {\n return undefined;\n }\n\n let found: string[] | undefined;\n this.traverse({\n node: start,\n visitor: (node, path) => {\n if (found) {\n return false;\n }\n\n if (node.id === target) {\n found = path;\n }\n },\n });\n\n return found;\n }\n\n /**\n * Add nodes to the graph.\n *\n * @internal\n */\n _addNodes<TData = null, TProperties extends Record<string, any> = Record<string, any>>(\n nodes: NodeArg<TData, TProperties>[],\n ): Node<TData, TProperties>[] {\n return batch(() => nodes.map((node) => this._addNode(node)));\n }\n\n private _addNode<TData, TProperties extends Record<string, any> = Record<string, any>>({\n nodes,\n edges,\n ..._node\n }: NodeArg<TData, TProperties>): Node<TData, TProperties> {\n return untracked(() => {\n const existingNode = this._nodes[_node.id];\n const node = existingNode ?? this._constructNode({ data: null, properties: {}, ..._node });\n if (existingNode) {\n const { data, properties, type } = _node;\n if (data && data !== node.data) {\n node.data = data;\n }\n\n if (type !== node.type) {\n node.type = type;\n }\n\n for (const key in properties) {\n if (properties[key] !== node.properties[key]) {\n node.properties[key] = properties[key];\n }\n }\n } else {\n this._nodes[node.id] = node;\n this._edges[node.id] = create({ inbound: [], outbound: [] });\n }\n\n const trigger = this._waitingForNodes[node.id];\n if (trigger) {\n trigger.wake(node);\n delete this._waitingForNodes[node.id];\n }\n\n if (nodes) {\n nodes.forEach((subNode) => {\n this._addNode(subNode);\n this._addEdge({ source: node.id, target: subNode.id });\n });\n }\n\n if (edges) {\n edges.forEach(([id, relation]) =>\n relation === 'outbound'\n ? this._addEdge({ source: node.id, target: id })\n : this._addEdge({ source: id, target: node.id }),\n );\n }\n\n return node as unknown as Node<TData, TProperties>;\n });\n }\n\n /**\n * Remove nodes from the graph.\n *\n * @param ids The id of the node to remove.\n * @param edges Whether to remove edges connected to the node from the graph as well.\n * @internal\n */\n _removeNodes(ids: string[], edges = false) {\n batch(() => ids.forEach((id) => this._removeNode(id, edges)));\n }\n\n private _removeNode(id: string, edges = false) {\n untracked(() => {\n const node = this.findNode(id);\n if (!node) {\n return;\n }\n\n if (edges) {\n // Remove edges from connected nodes.\n this._getNodes({ node }).forEach((node) => {\n this._removeEdge({ source: id, target: node.id });\n });\n this._getNodes({ node, relation: 'inbound' }).forEach((node) => {\n this._removeEdge({ source: node.id, target: id });\n });\n\n // Remove edges from node.\n delete this._edges[id];\n }\n\n // Remove node.\n delete this._nodes[id];\n void this._onRemoveNode?.(id);\n });\n }\n\n /**\n * Add edges to the graph.\n *\n * @internal\n */\n _addEdges(edges: { source: string; target: string }[]) {\n batch(() => edges.forEach((edge) => this._addEdge(edge)));\n }\n\n private _addEdge({ source, target }: { source: string; target: string }) {\n untracked(() => {\n if (!this._edges[source]) {\n this._edges[source] = create({ inbound: [], outbound: [] });\n }\n if (!this._edges[target]) {\n this._edges[target] = create({ inbound: [], outbound: [] });\n }\n\n const sourceEdges = this._edges[source];\n if (!sourceEdges.outbound.includes(target)) {\n sourceEdges.outbound.push(target);\n }\n\n const targetEdges = this._edges[target];\n if (!targetEdges.inbound.includes(source)) {\n targetEdges.inbound.push(source);\n }\n });\n }\n\n /**\n * Remove edges from the graph.\n * @internal\n */\n _removeEdges(edges: { source: string; target: string }[]) {\n batch(() => edges.forEach((edge) => this._removeEdge(edge)));\n }\n\n private _removeEdge({ source, target }: { source: string; target: string }) {\n untracked(() => {\n batch(() => {\n const outboundIndex = this._edges[source]?.outbound.findIndex((id) => id === target);\n if (outboundIndex !== undefined && outboundIndex !== -1) {\n this._edges[source].outbound.splice(outboundIndex, 1);\n }\n\n const inboundIndex = this._edges[target]?.inbound.findIndex((id) => id === source);\n if (inboundIndex !== undefined && inboundIndex !== -1) {\n this._edges[target].inbound.splice(inboundIndex, 1);\n }\n });\n });\n }\n\n /**\n * Sort edges for a node.\n *\n * Edges not included in the sorted list are appended to the end of the list.\n *\n * @param nodeId The id of the node to sort edges for.\n * @param relation The relation of the edges from the node to sort.\n * @param edges The ordered list of edges.\n * @ignore\n */\n _sortEdges(nodeId: string, relation: Relation, edges: string[]) {\n untracked(() => {\n batch(() => {\n const current = this._edges[nodeId];\n if (current) {\n const unsorted = current[relation].filter((id) => !edges.includes(id)) ?? [];\n const sorted = edges.filter((id) => current[relation].includes(id)) ?? [];\n current[relation].splice(0, current[relation].length, ...[...sorted, ...unsorted]);\n }\n });\n });\n }\n\n private _constructNode = (node: Omit<Node, typeof graphSymbol>) => {\n return create<NodeInternal>({ ...node, [graphSymbol]: this });\n };\n\n private _getNodes({\n node,\n relation = 'outbound',\n type,\n expansion,\n }: {\n node: Node;\n relation?: Relation;\n type?: string;\n expansion?: boolean;\n }): Node[] {\n if (expansion) {\n void this.expand(node, relation, type);\n }\n\n const edges = this._edges[node.id];\n if (!edges) {\n return [];\n } else {\n return edges[relation]\n .map((id) => this._nodes[id])\n .filter(nonNullable)\n .filter((n) => !type || n.type === type);\n }\n }\n}\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { type MaybePromise, type MakeOptional } from '@dxos/util';\n\n/**\n * Represents a node in the graph.\n */\n// TODO(wittjosiah): Use Effect Schema.\nexport type Node<TData = any, TProperties extends Record<string, any> = Record<string, any>> = Readonly<{\n /**\n * Globally unique ID.\n */\n id: string;\n\n /**\n * Typename of the data the node represents.\n */\n type: string;\n\n /**\n * Properties of the node relevant to displaying the node.\n */\n properties: Readonly<TProperties>;\n\n /**\n * Data the node represents.\n */\n // TODO(burdon): Type system (e.g., minimally provide identifier string vs. TypedObject vs. Graph mixin type system)?\n // type field would prevent convoluted sniffing of object properties. And allow direct pass-through for ECHO TypedObjects.\n data: TData;\n}>;\n\nexport type NodeFilter<T = any, U extends Record<string, any> = Record<string, any>> = (\n node: Node<unknown, Record<string, any>>,\n connectedNode: Node,\n) => node is Node<T, U>;\n\nexport type Relation = 'outbound' | 'inbound';\n\nexport const isGraphNode = (data: unknown): data is Node =>\n data && typeof data === 'object' && 'id' in data && 'properties' in data && data.properties\n ? typeof data.properties === 'object' && 'data' in data\n : false;\n\nexport type NodeArg<TData, TProperties extends Record<string, any> = Record<string, any>> = MakeOptional<\n Node<TData, TProperties>,\n 'data' | 'properties'\n> & {\n /** Will automatically add nodes with an edge from this node to each. */\n nodes?: NodeArg<unknown>[];\n\n /** Will automatically add specified edges. */\n edges?: [string, Relation][];\n};\n\n//\n// Actions\n//\n\nexport type InvokeParams = {\n /** Node the invoked action is connected to. */\n node: Node;\n\n caller?: string;\n};\n\nexport type ActionData = (params: InvokeParams) => MaybePromise<void>;\n\nexport type Action<TProperties extends Record<string, any> = Record<string, any>> = Readonly<\n Omit<Node<ActionData, TProperties>, 'properties'> & {\n properties: Readonly<TProperties>;\n }\n>;\n\nexport const isAction = (data: unknown): data is Action =>\n isGraphNode(data) ? typeof data.data === 'function' : false;\n\nexport const actionGroupSymbol = Symbol('ActionGroup');\n\nexport type ActionGroup = Readonly<\n Omit<Node<typeof actionGroupSymbol, Record<string, any>>, 'properties'> & {\n properties: Readonly<Record<string, any>>;\n }\n>;\n\nexport const isActionGroup = (data: unknown): data is ActionGroup =>\n isGraphNode(data) ? data.data === actionGroupSymbol : false;\n\nexport type ActionLike = Action | ActionGroup;\n\nexport const isActionLike = (data: unknown): data is Action | ActionGroup => isAction(data) || isActionGroup(data);\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { type Signal, effect, signal } from '@preact/signals-core';\n// import { yieldOrContinue } from 'main-thread-scheduling';\n\nimport { type UnsubscribeCallback } from '@dxos/async';\nimport { create } from '@dxos/echo-schema';\nimport { invariant } from '@dxos/invariant';\nimport { nonNullable } from '@dxos/util';\n\nimport { ACTION_GROUP_TYPE, ACTION_TYPE, Graph } from './graph';\nimport { type Relation, type NodeArg, type Node, type ActionData, actionGroupSymbol } from './node';\n\n/**\n * Graph builder extension for adding nodes to the graph based on just the node id.\n * This is useful for creating the first node in a graph or for hydrating cached nodes with data.\n *\n * @param params.id The id of the node to resolve.\n */\nexport type ResolverExtension = (params: { id: string }) => NodeArg<any> | undefined;\n\n/**\n * Graph builder extension for adding nodes to the graph based on a connection to an existing node.\n *\n * @param params.node The existing node the returned nodes will be connected to.\n */\nexport type ConnectorExtension<T = any> = (params: { node: Node<T> }) => NodeArg<any>[] | undefined;\n\n/**\n * Constrained case of the connector extension for more easily adding actions to the graph.\n */\nexport type ActionsExtension<T = any> = (params: {\n node: Node<T>;\n}) => Omit<NodeArg<ActionData>, 'type' | 'nodes' | 'edges'>[] | undefined;\n\n/**\n * Constrained case of the connector extension for more easily adding action groups to the graph.\n */\nexport type ActionGroupsExtension<T = any> = (params: {\n node: Node<T>;\n}) => Omit<NodeArg<typeof actionGroupSymbol>, 'type' | 'data' | 'nodes' | 'edges'>[] | undefined;\n\ntype GuardedNodeType<T> = T extends (value: any) => value is infer N ? (N extends Node<infer D> ? D : unknown) : never;\n\n/**\n * A graph builder extension is used to add nodes to the graph.\n *\n * @param params.id The unique id of the extension.\n * @param params.relation The relation the graph is being expanded from the existing node.\n * @param params.type If provided, all nodes returned are expected to have this type.\n * @param params.filter A filter function to determine if an extension should act on a node.\n * @param params.resolver A function to add nodes to the graph based on just the node id.\n * @param params.connector A function to add nodes to the graph based on a connection to an existing node.\n * @param params.actions A function to add actions to the graph based on a connection to an existing node.\n * @param params.actionGroups A function to add action groups to the graph based on a connection to an existing node.\n */\nexport type CreateExtensionOptions<T = any> = {\n id: string;\n relation?: Relation;\n type?: string;\n filter?: (node: Node) => node is Node<T>;\n resolver?: ResolverExtension;\n connector?: ConnectorExtension<GuardedNodeType<CreateExtensionOptions<T>['filter']>>;\n actions?: ActionsExtension<GuardedNodeType<CreateExtensionOptions<T>['filter']>>;\n actionGroups?: ActionGroupsExtension<GuardedNodeType<CreateExtensionOptions<T>['filter']>>;\n};\n\n/**\n * Create a graph builder extension.\n */\nexport const createExtension = <T = any>(extension: CreateExtensionOptions<T>): BuilderExtension[] => {\n const { id, resolver, connector, actions, actionGroups, ...rest } = extension;\n const getId = (key: string) => `${id}/${key}`;\n return [\n resolver ? { id: getId('resolver'), resolver } : undefined,\n connector ? { ...rest, id: getId('connector'), connector } : undefined,\n actionGroups\n ? ({\n ...rest,\n id: getId('actionGroups'),\n type: ACTION_GROUP_TYPE,\n relation: 'outbound',\n connector: ({ node }) =>\n actionGroups({ node })?.map((arg) => ({ ...arg, data: actionGroupSymbol, type: ACTION_GROUP_TYPE })),\n } satisfies BuilderExtension)\n : undefined,\n actions\n ? ({\n ...rest,\n id: getId('actions'),\n type: ACTION_TYPE,\n relation: 'outbound',\n connector: ({ node }) => actions({ node })?.map((arg) => ({ ...arg, type: ACTION_TYPE })),\n } satisfies BuilderExtension)\n : undefined,\n ].filter(nonNullable);\n};\n\nexport type GraphBuilderTraverseOptions = {\n node: Node;\n relation?: Relation;\n visitor: (node: Node, path: string[]) => void;\n};\n\n/**\n * The dispatcher is used to keep track of the current extension and state when memoizing functions.\n */\nclass Dispatcher {\n currentExtension?: string;\n stateIndex = 0;\n state: Record<string, any[]> = {};\n cleanup: (() => void)[] = [];\n}\n\nclass BuilderInternal {\n // This must be static to avoid passing the dispatcher instance to every memoized function.\n // If the dispatcher is not set that means that the memoized function is being called outside of the graph builder.\n static currentDispatcher?: Dispatcher;\n}\n\n/**\n * Allows code to be memoized within the context of a graph builder extension.\n * This is useful for creating instances which should be subscribed to rather than recreated.\n */\nexport const memoize = <T>(fn: () => T, key = 'result'): T => {\n const dispatcher = BuilderInternal.currentDispatcher;\n invariant(dispatcher?.currentExtension, 'memoize must be called within an extension');\n const all = dispatcher.state[dispatcher.currentExtension][dispatcher.stateIndex] ?? {};\n const current = all[key];\n const result = current ? current.result : fn();\n dispatcher.state[dispatcher.currentExtension][dispatcher.stateIndex] = { ...all, [key]: { result } };\n dispatcher.stateIndex++;\n return result;\n};\n\n/**\n * Register a cleanup function to be called when the graph builder is destroyed.\n */\nexport const cleanup = (fn: () => void): void => {\n memoize(() => {\n const dispatcher = BuilderInternal.currentDispatcher;\n invariant(dispatcher, 'cleanup must be called within an extension');\n dispatcher.cleanup.push(fn);\n });\n};\n\n/**\n * Convert a subscribe/get pair into a signal.\n */\nexport const toSignal = <T>(\n subscribe: (onChange: () => void) => () => void,\n get: () => T | undefined,\n key?: string,\n) => {\n const thisSignal = memoize(() => {\n return signal(get());\n }, key);\n const unsubscribe = memoize(() => {\n return subscribe(() => (thisSignal.value = get()));\n }, key);\n cleanup(() => {\n unsubscribe();\n });\n return thisSignal.value;\n};\n\nexport type BuilderExtension = {\n id: string;\n resolver?: ResolverExtension;\n connector?: ConnectorExtension;\n // Only for connector.\n relation?: Relation;\n type?: string;\n filter?: (node: Node) => boolean;\n};\n\ntype ExtensionArg = BuilderExtension | BuilderExtension[] | ExtensionArg[];\n\n/**\n * The builder provides an extensible way to compose the construction of the graph.\n */\n// TODO(wittjosiah): Add api for setting subscription set and/or radius.\n// Should unsubscribe from nodes that are not in the set/radius.\n// Should track LRU nodes that are not in the set/radius and remove them beyond a certain threshold.\nexport class GraphBuilder {\n private readonly _dispatcher = new Dispatcher();\n private readonly _extensions = create<Record<string, BuilderExtension>>({});\n private readonly _resolverSubscriptions = new Map<string, UnsubscribeCallback>();\n private readonly _connectorSubscriptions = new Map<string, UnsubscribeCallback>();\n private readonly _nodeChanged: Record<string, Signal<{}>> = {};\n private _graph: Graph;\n\n constructor() {\n this._graph = new Graph({\n onInitialNode: (id) => this._onInitialNode(id),\n onInitialNodes: (node, relation, type) => this._onInitialNodes(node, relation, type),\n onRemoveNode: (id) => this._onRemoveNode(id),\n });\n }\n\n get graph() {\n return this._graph;\n }\n\n /**\n * Register a node builder which will be called in order to construct the graph.\n */\n addExtension(extension: ExtensionArg): GraphBuilder {\n if (Array.isArray(extension)) {\n extension.forEach((ext) => this.addExtension(ext));\n return this;\n }\n\n this._dispatcher.state[extension.id] = [];\n this._extensions[extension.id] = extension;\n return this;\n }\n\n /**\n * Remove a node builder from the graph builder.\n */\n removeExtension(id: string): GraphBuilder {\n delete this._extensions[id];\n return this;\n }\n\n destroy() {\n this._dispatcher.cleanup.forEach((fn) => fn());\n this._resolverSubscriptions.forEach((unsubscribe) => unsubscribe());\n this._connectorSubscriptions.forEach((unsubscribe) => unsubscribe());\n this._resolverSubscriptions.clear();\n this._connectorSubscriptions.clear();\n }\n\n /**\n * Traverse a graph using just the connector extensions, without subscribing to any signals or persisting any nodes.\n */\n // TODO(wittjosiah): Rename? This is not traversing the graph proper.\n async traverse({ node, relation = 'outbound', visitor }: GraphBuilderTraverseOptions, path: string[] = []) {\n // Break cycles.\n if (path.includes(node.id)) {\n return;\n }\n\n // TODO(wittjosiah): Failed in test environment. ESM only?\n // await yieldOrContinue('idle');\n visitor(node, [...path, node.id]);\n\n const nodes = Object.values(this._extensions)\n .filter((extension) => relation === (extension.relation ?? 'outbound'))\n .flatMap((extension) => extension.connector?.({ node }) ?? [])\n .map(\n (arg): Node => ({\n id: arg.id,\n type: arg.type,\n data: arg.data ?? null,\n properties: arg.properties ?? {},\n }),\n );\n\n await Promise.all(nodes.map((n) => this.traverse({ node: n, relation, visitor }, [...path, node.id])));\n }\n\n private async _onInitialNode(nodeId: string) {\n this._nodeChanged[nodeId] = this._nodeChanged[nodeId] ?? signal({});\n let resolved = false;\n for (const { id, resolver } of Object.values(this._extensions)) {\n if (resolved || !resolver) {\n continue;\n }\n\n const unsubscribe = effect(() => {\n this._dispatcher.currentExtension = id;\n this._dispatcher.stateIndex = 0;\n BuilderInternal.currentDispatcher = this._dispatcher;\n const node = resolver({ id: nodeId });\n BuilderInternal.currentDispatcher = undefined;\n if (node) {\n resolved = true;\n this.graph._addNodes([node]);\n if (this._nodeChanged[node.id]) {\n this._nodeChanged[node.id].value = {};\n }\n }\n });\n\n if (resolved) {\n this._resolverSubscriptions.get(nodeId)?.();\n this._resolverSubscriptions.set(nodeId, unsubscribe);\n break;\n } else {\n unsubscribe();\n }\n }\n }\n\n private async _onInitialNodes(node: Node, nodesRelation: Relation, nodesType?: string) {\n this._nodeChanged[node.id] = this._nodeChanged[node.id] ?? signal({});\n let previous: string[] = [];\n this._connectorSubscriptions.set(\n node.id,\n effect(() => {\n // Subscribe to extensions being added.\n Object.keys(this._extensions);\n // Subscribe to connected node changes.\n this._nodeChanged[node.id].value;\n\n // TODO(wittjosiah): Consider allowing extensions to collaborate on the same node by merging their results.\n const nodes: NodeArg<any>[] = [];\n for (const { id, connector, filter, type, relation = 'outbound' } of Object.values(this._extensions)) {\n if (\n !connector ||\n relation !== nodesRelation ||\n (nodesType && type !== nodesType) ||\n (filter && !filter(node))\n ) {\n continue;\n }\n\n this._dispatcher.currentExtension = id;\n this._dispatcher.stateIndex = 0;\n BuilderInternal.currentDispatcher = this._dispatcher;\n nodes.push(...(connector({ node }) ?? []));\n BuilderInternal.currentDispatcher = undefined;\n }\n const ids = nodes.map((n) => n.id);\n const removed = previous.filter((id) => !ids.includes(id));\n previous = ids;\n\n this.graph._removeNodes(removed, true);\n this.graph._addNodes(nodes);\n this.graph._addEdges(\n nodes.map(({ id }) =>\n nodesRelation === 'outbound' ? { source: node.id, target: id } : { source: id, target: node.id },\n ),\n );\n this.graph._sortEdges(\n node.id,\n nodesRelation,\n nodes.map(({ id }) => id),\n );\n nodes.forEach((n) => {\n if (this._nodeChanged[n.id]) {\n this._nodeChanged[n.id].value = {};\n }\n });\n }),\n );\n }\n\n private async _onRemoveNode(nodeId: string) {\n this._resolverSubscriptions.get(nodeId)?.();\n this._connectorSubscriptions.get(nodeId)?.();\n this._resolverSubscriptions.delete(nodeId);\n this._connectorSubscriptions.delete(nodeId);\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,0BAAyC;AAEzC,mBAAsC;AACtC,yBAA4C;AAC5C,uBAA0B;AAC1B,kBAA4B;AEL5B,IAAAA,uBAA4C;AAI5C,IAAAC,sBAAuB;AACvB,IAAAC,oBAA0B;AAC1B,IAAAC,eAA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A;IACF,CAAA,CAAA;EAEJ;EAEA,MAAc9G,cAAckF,QAAgB;AAC1C,SAAKgC,uBAAuBP,IAAIzB,MAAAA,IAAAA;AAChC,SAAKkC,wBAAwBT,IAAIzB,MAAAA,IAAAA;AACjC,SAAKgC,uBAAuBqB,OAAOrD,MAAAA;AACnC,SAAKkC,wBAAwBmB,OAAOrD,MAAAA;EACtC;AACF;",
|
|
6
|
+
"names": ["import_signals_core", "import_echo_schema", "import_invariant", "import_util", "isGraphNode", "data", "properties", "isAction", "actionGroupSymbol", "Symbol", "isActionGroup", "isActionLike", "graphSymbol", "getGraph", "node", "graph", "invariant", "ROOT_ID", "ROOT_TYPE", "ACTION_TYPE", "ACTION_GROUP_TYPE", "Graph", "constructor", "onInitialNode", "onInitialNodes", "onRemoveNode", "_waitingForNodes", "_initialized", "_constructNode", "create", "_onInitialNode", "_onInitialNodes", "_onRemoveNode", "_nodes", "id", "type", "_edges", "inbound", "outbound", "root", "findNode", "toJSON", "maxLength", "seen", "nodes", "obj", "length", "slice", "label", "map", "n", "nextSeen", "includes", "undefined", "filter", "nonNullable", "existingNode", "waitForNode", "timeout", "trigger", "Trigger", "wait", "asyncTimeout", "options", "relation", "expansion", "_getNodes", "untracked", "edges", "actions", "expand", "key", "initialized", "traverse", "visitor", "path", "shouldContinue", "Object", "values", "forEach", "child", "subscribeTraverse", "currentPath", "effect", "result", "nodeSubscriptions", "unsubscribe", "getPath", "source", "target", "start", "found", "_addNodes", "batch", "_addNode", "_node", "wake", "subNode", "_addEdge", "_removeNodes", "ids", "_removeNode", "_removeEdge", "_addEdges", "edge", "sourceEdges", "push", "targetEdges", "_removeEdges", "outboundIndex", "findIndex", "splice", "inboundIndex", "_sortEdges", "nodeId", "current", "unsorted", "sorted", "createExtension", "extension", "resolver", "connector", "actionGroups", "rest", "getId", "arg", "Dispatcher", "stateIndex", "state", "cleanup", "BuilderInternal", "memoize", "fn", "dispatcher", "currentDispatcher", "currentExtension", "all", "toSignal", "subscribe", "get", "thisSignal", "signal", "value", "GraphBuilder", "_dispatcher", "_extensions", "_resolverSubscriptions", "Map", "_connectorSubscriptions", "_nodeChanged", "_graph", "addExtension", "Array", "isArray", "ext", "removeExtension", "destroy", "clear", "flatMap", "Promise", "resolved", "set", "nodesRelation", "nodesType", "previous", "keys", "removed", "delete"]
|
|
7
7
|
}
|
package/dist/lib/node/meta.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"packages/sdk/app-graph/src/node.ts":{"bytes":5259,"imports":[],"format":"esm"},"packages/sdk/app-graph/src/graph.ts":{"bytes":
|
|
1
|
+
{"inputs":{"packages/sdk/app-graph/src/node.ts":{"bytes":5259,"imports":[],"format":"esm"},"packages/sdk/app-graph/src/graph.ts":{"bytes":50171,"imports":[{"path":"@preact/signals-core","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"packages/sdk/app-graph/src/node.ts","kind":"import-statement","original":"./node"}],"format":"esm"},"packages/sdk/app-graph/src/graph-builder.ts":{"bytes":38696,"imports":[{"path":"@preact/signals-core","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"packages/sdk/app-graph/src/graph.ts","kind":"import-statement","original":"./graph"},{"path":"packages/sdk/app-graph/src/node.ts","kind":"import-statement","original":"./node"}],"format":"esm"},"packages/sdk/app-graph/src/index.ts":{"bytes":672,"imports":[{"path":"packages/sdk/app-graph/src/graph.ts","kind":"import-statement","original":"./graph"},{"path":"packages/sdk/app-graph/src/graph-builder.ts","kind":"import-statement","original":"./graph-builder"},{"path":"packages/sdk/app-graph/src/node.ts","kind":"import-statement","original":"./node"}],"format":"esm"}},"outputs":{"packages/sdk/app-graph/dist/lib/node/index.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":47906},"packages/sdk/app-graph/dist/lib/node/index.cjs":{"imports":[{"path":"@preact/signals-core","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"@preact/signals-core","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"exports":["ACTION_GROUP_TYPE","ACTION_TYPE","Graph","GraphBuilder","ROOT_ID","ROOT_TYPE","actionGroupSymbol","cleanup","createExtension","getGraph","isAction","isActionGroup","isActionLike","isGraphNode","memoize","toSignal"],"entryPoint":"packages/sdk/app-graph/src/index.ts","inputs":{"packages/sdk/app-graph/src/graph.ts":{"bytesInOutput":12265},"packages/sdk/app-graph/src/node.ts":{"bytesInOutput":477},"packages/sdk/app-graph/src/index.ts":{"bytesInOutput":0},"packages/sdk/app-graph/src/graph-builder.ts":{"bytesInOutput":7747}},"bytes":20932}}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graph-builder.d.ts","sourceRoot":"","sources":["../../../src/graph-builder.ts"],"names":[],"mappings":"AAYA,OAAO,EAAkC,KAAK,EAAE,MAAM,SAAS,CAAC;AAChE,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,OAAO,EAAE,KAAK,IAAI,EAAE,KAAK,UAAU,EAAE,iBAAiB,EAAE,MAAM,QAAQ,CAAC;AAEpG;;;;;GAKG;AACH,MAAM,MAAM,iBAAiB,GAAG,CAAC,MAAM,EAAE;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,KAAK,OAAO,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC;AAErF;;;;GAIG;AACH,MAAM,MAAM,kBAAkB,CAAC,CAAC,GAAG,GAAG,IAAI,CAAC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