@dxos/app-graph 0.8.4-main.c85a9c8dae → 0.8.4-main.d05673bc65

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/app-graph",
3
- "version": "0.8.4-main.c85a9c8dae",
3
+ "version": "0.8.4-main.d05673bc65",
4
4
  "description": "Constructs knowledge graphs for the purpose of building applications on top of",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -30,13 +30,13 @@
30
30
  ],
31
31
  "dependencies": {
32
32
  "main-thread-scheduling": "^14.1.1",
33
- "@dxos/async": "0.8.4-main.c85a9c8dae",
34
- "@dxos/echo": "0.8.4-main.c85a9c8dae",
35
- "@dxos/debug": "0.8.4-main.c85a9c8dae",
36
- "@dxos/invariant": "0.8.4-main.c85a9c8dae",
37
- "@dxos/log": "0.8.4-main.c85a9c8dae",
38
- "@dxos/util": "0.8.4-main.c85a9c8dae",
39
- "@dxos/echo-atom": "0.8.4-main.c85a9c8dae"
33
+ "@dxos/async": "0.8.4-main.d05673bc65",
34
+ "@dxos/debug": "0.8.4-main.d05673bc65",
35
+ "@dxos/echo-atom": "0.8.4-main.d05673bc65",
36
+ "@dxos/echo": "0.8.4-main.d05673bc65",
37
+ "@dxos/invariant": "0.8.4-main.d05673bc65",
38
+ "@dxos/log": "0.8.4-main.d05673bc65",
39
+ "@dxos/util": "0.8.4-main.d05673bc65"
40
40
  },
41
41
  "devDependencies": {
42
42
  "@effect-atom/atom-react": "^0.5.0",
@@ -47,14 +47,14 @@
47
47
  "react": "~19.2.3",
48
48
  "react-dom": "~19.2.3",
49
49
  "vite": "^7.1.11",
50
- "@dxos/echo-db": "0.8.4-main.c85a9c8dae",
51
- "@dxos/react-client": "0.8.4-main.c85a9c8dae",
52
- "@dxos/react-ui": "0.8.4-main.c85a9c8dae",
53
- "@dxos/react-ui-list": "0.8.4-main.c85a9c8dae",
54
- "@dxos/react-ui-tabs": "0.8.4-main.c85a9c8dae",
55
- "@dxos/storybook-utils": "0.8.4-main.c85a9c8dae",
56
- "@dxos/ui-theme": "0.8.4-main.c85a9c8dae",
57
- "@dxos/random": "0.8.4-main.c85a9c8dae"
50
+ "@dxos/echo-db": "0.8.4-main.d05673bc65",
51
+ "@dxos/random": "0.8.4-main.d05673bc65",
52
+ "@dxos/react-ui": "0.8.4-main.d05673bc65",
53
+ "@dxos/react-client": "0.8.4-main.d05673bc65",
54
+ "@dxos/react-ui-tabs": "0.8.4-main.d05673bc65",
55
+ "@dxos/storybook-utils": "0.8.4-main.d05673bc65",
56
+ "@dxos/ui-theme": "0.8.4-main.d05673bc65",
57
+ "@dxos/react-ui-list": "0.8.4-main.d05673bc65"
58
58
  },
59
59
  "peerDependencies": {
60
60
  "@effect-atom/atom-react": "^0.5.0",
@@ -62,8 +62,8 @@
62
62
  "effect": "3.19.16",
63
63
  "react": "~19.2.3",
64
64
  "react-dom": "~19.2.3",
65
- "@dxos/react-ui": "0.8.4-main.c85a9c8dae",
66
- "@dxos/ui-theme": "0.8.4-main.c85a9c8dae"
65
+ "@dxos/react-ui": "0.8.4-main.d05673bc65",
66
+ "@dxos/ui-theme": "0.8.4-main.d05673bc65"
67
67
  },
68
68
  "publishConfig": {
69
69
  "access": "public"
@@ -20,7 +20,9 @@ import * as NodeMatcher from './node-matcher';
20
20
 
21
21
  const exampleId = (id: number) => `dx:test:${id}`;
22
22
  const EXAMPLE_ID = exampleId(1);
23
- const EXAMPLE_TYPE = 'dxos.org/type/example';
23
+ const EXAMPLE_TYPE = 'org.dxos.type.example';
24
+
25
+ const qualifiedId = (...segments: string[]) => segments.join('/');
24
26
 
25
27
  describe('GraphBuilder', () => {
26
28
  describe('resolver', () => {
@@ -78,6 +80,61 @@ describe('GraphBuilder', () => {
78
80
  expect(node?.data).to.equal('updated');
79
81
  }
80
82
  });
83
+
84
+ test('does not overwrite connector-produced node', async () => {
85
+ const registry = Registry.make();
86
+ const builder = GraphBuilder.make({ registry });
87
+ const resolverData = Atom.make('from-resolver');
88
+
89
+ GraphBuilder.addExtension(builder, [
90
+ GraphBuilder.createExtensionRaw({
91
+ id: 'resolver',
92
+ resolver: (id) =>
93
+ id === qualifiedId('root', 'shared')
94
+ ? Atom.make((get) => ({ id: qualifiedId('root', 'shared'), type: EXAMPLE_TYPE, data: get(resolverData) }))
95
+ : Atom.make(null),
96
+ }),
97
+ GraphBuilder.createExtensionRaw({
98
+ id: 'connector',
99
+ connector: (node) =>
100
+ Atom.make((get) =>
101
+ Function.pipe(
102
+ get(node),
103
+ Option.filter((n) => n.id === 'root'),
104
+ Option.map(() => [{ id: 'shared', type: EXAMPLE_TYPE, data: 'from-connector' }]),
105
+ Option.getOrElse(() => []),
106
+ ),
107
+ ),
108
+ }),
109
+ ]);
110
+
111
+ const graph = builder.graph;
112
+
113
+ // Connector produces root/shared.
114
+ Graph.expand(graph, Node.RootId, 'child');
115
+ await GraphBuilder.flush(builder);
116
+
117
+ {
118
+ const node = Graph.getNode(graph, qualifiedId('root', 'shared')).pipe(Option.getOrNull);
119
+ expect(node?.data).to.equal('from-connector');
120
+ }
121
+
122
+ // Resolver fires for the same ID but should not overwrite.
123
+ await Graph.initialize(graph, qualifiedId('root', 'shared'));
124
+
125
+ {
126
+ const node = Graph.getNode(graph, qualifiedId('root', 'shared')).pipe(Option.getOrNull);
127
+ expect(node?.data).to.equal('from-connector');
128
+ }
129
+
130
+ // Updating the resolver's atom should still not overwrite.
131
+ registry.set(resolverData, 'updated-resolver');
132
+
133
+ {
134
+ const node = Graph.getNode(graph, qualifiedId('root', 'shared')).pipe(Option.getOrNull);
135
+ expect(node?.data).to.equal('from-connector');
136
+ }
137
+ });
81
138
  });
82
139
 
83
140
  describe('connector', () => {
@@ -109,10 +166,10 @@ describe('GraphBuilder', () => {
109
166
  const inbound = registry.get(graph.connections(Node.RootId, Node.childRelation('inbound')));
110
167
 
111
168
  expect(outbound).has.length(1);
112
- expect(outbound[0].id).to.equal('child');
169
+ expect(outbound[0].id).to.equal('root/child');
113
170
  expect(outbound[0].data).to.equal(2);
114
171
  expect(inbound).has.length(1);
115
- expect(inbound[0].id).to.equal('parent');
172
+ expect(inbound[0].id).to.equal('root/parent');
116
173
  expect(inbound[0].data).to.equal(0);
117
174
  });
118
175
 
@@ -237,8 +294,8 @@ describe('GraphBuilder', () => {
237
294
  {
238
295
  const nodes = registry.get(graph.connections(Node.RootId, 'child'));
239
296
  expect(nodes).has.length(2);
240
- expect(nodes[0].id).to.equal(exampleId(1));
241
- expect(nodes[1].id).to.equal(exampleId(2));
297
+ expect(nodes[0].id).to.equal(qualifiedId('root', exampleId(1)));
298
+ expect(nodes[1].id).to.equal(qualifiedId('root', exampleId(2)));
242
299
  }
243
300
 
244
301
  registry.set(nodes, [{ id: exampleId(3), type: EXAMPLE_TYPE }]);
@@ -247,7 +304,7 @@ describe('GraphBuilder', () => {
247
304
  {
248
305
  const nodes = registry.get(graph.connections(Node.RootId, 'child'));
249
306
  expect(nodes).has.length(1);
250
- expect(nodes[0].id).to.equal(exampleId(3));
307
+ expect(nodes[0].id).to.equal(qualifiedId('root', exampleId(3)));
251
308
  }
252
309
  });
253
310
 
@@ -276,7 +333,7 @@ describe('GraphBuilder', () => {
276
333
 
277
334
  let count = 0;
278
335
  let exists = false;
279
- const cancel = registry.subscribe(graph.node(EXAMPLE_ID), (node) => {
336
+ const cancel = registry.subscribe(graph.node(qualifiedId('root', EXAMPLE_ID)), (node) => {
280
337
  count++;
281
338
  exists = Option.isSome(node);
282
339
  });
@@ -325,9 +382,9 @@ describe('GraphBuilder', () => {
325
382
  {
326
383
  const nodes = registry.get(graph.connections(Node.RootId, 'child'));
327
384
  expect(nodes).has.length(3);
328
- expect(nodes[0].id).to.equal(exampleId(1));
329
- expect(nodes[1].id).to.equal(exampleId(2));
330
- expect(nodes[2].id).to.equal(exampleId(3));
385
+ expect(nodes[0].id).to.equal(qualifiedId('root', exampleId(1)));
386
+ expect(nodes[1].id).to.equal(qualifiedId('root', exampleId(2)));
387
+ expect(nodes[2].id).to.equal(qualifiedId('root', exampleId(3)));
331
388
  }
332
389
 
333
390
  registry.set(nodes, [
@@ -340,9 +397,9 @@ describe('GraphBuilder', () => {
340
397
  {
341
398
  const nodes = registry.get(graph.connections(Node.RootId, 'child'));
342
399
  expect(nodes).has.length(3);
343
- expect(nodes[0].id).to.equal(exampleId(3));
344
- expect(nodes[1].id).to.equal(exampleId(1));
345
- expect(nodes[2].id).to.equal(exampleId(2));
400
+ expect(nodes[0].id).to.equal(qualifiedId('root', exampleId(3)));
401
+ expect(nodes[1].id).to.equal(qualifiedId('root', exampleId(1)));
402
+ expect(nodes[2].id).to.equal(qualifiedId('root', exampleId(2)));
346
403
  }
347
404
  });
348
405
 
@@ -372,7 +429,9 @@ describe('GraphBuilder', () => {
372
429
  Atom.make((get) =>
373
430
  Function.pipe(
374
431
  get(node),
375
- Option.flatMap((node) => (node.id === EXAMPLE_ID ? Option.some(get(sub)) : Option.none())),
432
+ Option.flatMap((node) =>
433
+ node.id === qualifiedId('root', EXAMPLE_ID) ? Option.some(get(sub)) : Option.none(),
434
+ ),
376
435
  Option.map((sub) => [{ id: exampleId(2), type: EXAMPLE_TYPE, data: sub }]),
377
436
  Option.getOrElse(() => []),
378
437
  ),
@@ -384,7 +443,9 @@ describe('GraphBuilder', () => {
384
443
  Atom.make((get) =>
385
444
  Function.pipe(
386
445
  get(node),
387
- Option.flatMap((node) => (node.id === EXAMPLE_ID ? Option.some(node.data) : Option.none())),
446
+ Option.flatMap((node) =>
447
+ node.id === qualifiedId('root', EXAMPLE_ID) ? Option.some(node.data) : Option.none(),
448
+ ),
388
449
  Option.map((data) => [{ id: exampleId(3), type: EXAMPLE_TYPE, data }]),
389
450
  Option.getOrElse(() => []),
390
451
  ),
@@ -395,19 +456,19 @@ describe('GraphBuilder', () => {
395
456
  const graph = builder.graph;
396
457
 
397
458
  let parentCount = 0;
398
- const parentCancel = registry.subscribe(graph.node(EXAMPLE_ID), (_) => {
459
+ const parentCancel = registry.subscribe(graph.node(qualifiedId('root', EXAMPLE_ID)), (_) => {
399
460
  parentCount++;
400
461
  });
401
462
  onTestFinished(() => parentCancel());
402
463
 
403
464
  let independentCount = 0;
404
- const independentCancel = registry.subscribe(graph.node(exampleId(2)), (_) => {
465
+ const independentCancel = registry.subscribe(graph.node(qualifiedId('root', EXAMPLE_ID, exampleId(2))), (_) => {
405
466
  independentCount++;
406
467
  });
407
468
  onTestFinished(() => independentCancel());
408
469
 
409
470
  let dependentCount = 0;
410
- const dependentCancel = registry.subscribe(graph.node(exampleId(3)), (_) => {
471
+ const dependentCancel = registry.subscribe(graph.node(qualifiedId('root', EXAMPLE_ID, exampleId(3))), (_) => {
411
472
  dependentCount++;
412
473
  });
413
474
  onTestFinished(() => dependentCancel());
@@ -420,7 +481,7 @@ describe('GraphBuilder', () => {
420
481
  expect(dependentCount).to.equal(0);
421
482
 
422
483
  // Counts should increment when the node is expanded.
423
- Graph.expand(graph, EXAMPLE_ID, 'child');
484
+ Graph.expand(graph, qualifiedId('root', EXAMPLE_ID), 'child');
424
485
  await GraphBuilder.flush(builder);
425
486
  expect(parentCount).to.equal(1);
426
487
  expect(independentCount).to.equal(1);
@@ -458,7 +519,7 @@ describe('GraphBuilder', () => {
458
519
  expect(dependentCount).to.equal(3);
459
520
 
460
521
  // Counts should not increment when the node is expanded again.
461
- Graph.expand(graph, EXAMPLE_ID, 'child');
522
+ Graph.expand(graph, qualifiedId('root', EXAMPLE_ID), 'child');
462
523
  await GraphBuilder.flush(builder);
463
524
  expect(parentCount).to.equal(3);
464
525
  expect(independentCount).to.equal(3);
@@ -559,7 +620,7 @@ describe('GraphBuilder', () => {
559
620
 
560
621
  const connections = registry.get(graph.connections(Node.RootId, 'child'));
561
622
  expect(connections).has.length(1);
562
- expect(connections[0].id).to.equal('child');
623
+ expect(connections[0].id).to.equal('root/child');
563
624
  });
564
625
  });
565
626
 
@@ -586,7 +647,7 @@ describe('GraphBuilder', () => {
586
647
 
587
648
  const connections = registry.get(graph.connections('parent', 'child'));
588
649
  expect(connections).has.length(1);
589
- expect(connections[0].id).to.equal('child');
650
+ expect(connections[0].id).to.equal('parent/child');
590
651
  expect(connections[0].data).to.equal('test');
591
652
  });
592
653
 
@@ -619,11 +680,11 @@ describe('GraphBuilder', () => {
619
680
 
620
681
  const edges = registry.get(graph.edges('parent'));
621
682
  expect(edges[Graph.relationKey('action')] ?? []).to.have.length(1);
622
- expect(edges[Graph.relationKey('action')] ?? []).to.include('test-action');
683
+ expect(edges[Graph.relationKey('action')] ?? []).to.include('parent/test-action');
623
684
  expect(edges[Graph.relationKey('child')] ?? []).to.have.length(0);
624
685
  const actions = registry.get(graph.actions('parent'));
625
686
  expect(actions).has.length(1);
626
- expect(actions[0].id).to.equal('test-action');
687
+ expect(actions[0].id).to.equal('parent/test-action');
627
688
  });
628
689
 
629
690
  test('actions expand automatically with child relation', async ({ expect }) => {
@@ -649,14 +710,14 @@ describe('GraphBuilder', () => {
649
710
  await GraphBuilder.flush(builder);
650
711
 
651
712
  const edges = registry.get(graph.edges('parent'));
652
- expect(edges[Graph.relationKey('child')] ?? []).to.include('child');
653
- expect(edges[Graph.relationKey('action')] ?? []).to.include('act1');
713
+ expect(edges[Graph.relationKey('child')] ?? []).to.include('parent/child');
714
+ expect(edges[Graph.relationKey('action')] ?? []).to.include('parent/act1');
654
715
  const actions = registry.get(graph.actions('parent'));
655
716
  expect(actions).has.length(1);
656
- expect(actions[0].id).to.equal('act1');
717
+ expect(actions[0].id).to.equal('parent/act1');
657
718
  const connections = registry.get(graph.connections('parent', 'child'));
658
719
  expect(connections).has.length(1);
659
- expect(connections[0].id).to.equal('child');
720
+ expect(connections[0].id).to.equal('parent/child');
660
721
  });
661
722
 
662
723
  test('actions appear when extension registered after expand', async ({ expect }) => {
@@ -684,10 +745,10 @@ describe('GraphBuilder', () => {
684
745
  await GraphBuilder.flush(builder);
685
746
 
686
747
  const edges = registry.get(graph.edges('parent'));
687
- expect(edges[Graph.relationKey('action')] ?? []).to.include('late-act');
748
+ expect(edges[Graph.relationKey('action')] ?? []).to.include('parent/late-act');
688
749
  const actions = registry.get(graph.actions('parent'));
689
750
  expect(actions).has.length(1);
690
- expect(actions[0].id).to.equal('late-act');
751
+ expect(actions[0].id).to.equal('parent/late-act');
691
752
  });
692
753
 
693
754
  test('_actionContext captures and provides services to action execution', async () => {
@@ -809,13 +870,13 @@ describe('GraphBuilder', () => {
809
870
  const connections = registry.get(graph.connections('parent', 'child'));
810
871
  // Should have both the child node and the action node.
811
872
  expect(connections.length).to.be.greaterThanOrEqual(1);
812
- const childNode = connections.find((n) => n.id === 'child');
873
+ const childNode = connections.find((n) => n.id === 'parent/child');
813
874
  expect(childNode).to.not.be.undefined;
814
875
  expect(childNode?.data).to.equal('test');
815
876
 
816
877
  const actions = registry.get(graph.actions('parent'));
817
878
  expect(actions).has.length(1);
818
- expect(actions[0].id).to.equal('test-action');
879
+ expect(actions[0].id).to.equal('parent/test-action');
819
880
  });
820
881
 
821
882
  test('works with reactive connector using get context', async () => {
@@ -970,7 +1031,7 @@ describe('GraphBuilder', () => {
970
1031
  // The working extension should still produce its node.
971
1032
  const connections = registry.get(graph.connections('parent', 'child'));
972
1033
  expect(connections).has.length(1);
973
- expect(connections[0].id).to.equal('child-from-working');
1034
+ expect(connections[0].id).to.equal('parent/child-from-working');
974
1035
  expect(connections[0].data).to.equal('success');
975
1036
  });
976
1037
  });
@@ -999,9 +1060,199 @@ describe('GraphBuilder', () => {
999
1060
 
1000
1061
  const connections = registry.get(graph.connections('parent', 'child'));
1001
1062
  expect(connections).has.length(1);
1002
- expect(connections[0].id).to.equal('child');
1063
+ expect(connections[0].id).to.equal('parent/child');
1003
1064
  expect(connections[0].data).to.equal(testObject);
1004
1065
  });
1005
1066
  });
1006
1067
  });
1068
+ describe('path-based ID qualification', () => {
1069
+ test('rejects segment IDs containing slash', async () => {
1070
+ const registry = Registry.make();
1071
+ const builder = GraphBuilder.make({ registry });
1072
+ GraphBuilder.addExtension(
1073
+ builder,
1074
+ GraphBuilder.createExtensionRaw({
1075
+ id: 'bad-connector',
1076
+ connector: () => Atom.make([{ id: 'foo/bar', type: EXAMPLE_TYPE, data: null }]),
1077
+ }),
1078
+ );
1079
+
1080
+ expect(() => Graph.expand(builder.graph, Node.RootId, 'child')).toThrow(/must not contain/);
1081
+ });
1082
+
1083
+ test('multi-level path qualification', async () => {
1084
+ const registry = Registry.make();
1085
+ const builder = GraphBuilder.make({ registry });
1086
+ GraphBuilder.addExtension(builder, [
1087
+ GraphBuilder.createExtensionRaw({
1088
+ id: 'level1',
1089
+ connector: (node) =>
1090
+ Atom.make((get) =>
1091
+ Function.pipe(
1092
+ get(node),
1093
+ Option.filter((n) => n.id === 'root'),
1094
+ Option.map(() => [{ id: 'A', type: EXAMPLE_TYPE, data: 'a' }]),
1095
+ Option.getOrElse(() => []),
1096
+ ),
1097
+ ),
1098
+ }),
1099
+ GraphBuilder.createExtensionRaw({
1100
+ id: 'level2',
1101
+ connector: (node) =>
1102
+ Atom.make((get) =>
1103
+ Function.pipe(
1104
+ get(node),
1105
+ Option.filter((n) => n.id === 'root/A'),
1106
+ Option.map(() => [{ id: 'B', type: EXAMPLE_TYPE, data: 'b' }]),
1107
+ Option.getOrElse(() => []),
1108
+ ),
1109
+ ),
1110
+ }),
1111
+ ]);
1112
+
1113
+ const graph = builder.graph;
1114
+
1115
+ Graph.expand(graph, Node.RootId, 'child');
1116
+ await GraphBuilder.flush(builder);
1117
+
1118
+ const level1 = registry.get(graph.connections(Node.RootId, 'child'));
1119
+ expect(level1).has.length(1);
1120
+ expect(level1[0].id).to.equal('root/A');
1121
+
1122
+ Graph.expand(graph, 'root/A', 'child');
1123
+ await GraphBuilder.flush(builder);
1124
+
1125
+ const level2 = registry.get(graph.connections('root/A', 'child'));
1126
+ expect(level2).has.length(1);
1127
+ expect(level2[0].id).to.equal('root/A/B');
1128
+ });
1129
+
1130
+ test('inline nodes are recursively qualified', async () => {
1131
+ const registry = Registry.make();
1132
+ const builder = GraphBuilder.make({ registry });
1133
+ GraphBuilder.addExtension(
1134
+ builder,
1135
+ GraphBuilder.createExtensionRaw({
1136
+ id: 'inline-connector',
1137
+ connector: () =>
1138
+ Atom.make([
1139
+ {
1140
+ id: 'parent-node',
1141
+ type: EXAMPLE_TYPE,
1142
+ data: null,
1143
+ nodes: [
1144
+ {
1145
+ id: 'inline-child',
1146
+ type: EXAMPLE_TYPE,
1147
+ data: null,
1148
+ nodes: [{ id: 'deep-child', type: EXAMPLE_TYPE, data: null }],
1149
+ },
1150
+ ],
1151
+ },
1152
+ ]),
1153
+ }),
1154
+ );
1155
+
1156
+ const graph = builder.graph;
1157
+ Graph.expand(graph, Node.RootId, 'child');
1158
+ await GraphBuilder.flush(builder);
1159
+
1160
+ const connections = registry.get(graph.connections(Node.RootId, 'child'));
1161
+ expect(connections).has.length(1);
1162
+ expect(connections[0].id).to.equal('root/parent-node');
1163
+
1164
+ const inlineNode = Graph.getNode(graph, 'root/parent-node/inline-child').pipe(Option.getOrNull);
1165
+ expect(inlineNode).to.not.be.null;
1166
+ expect(inlineNode?.id).to.equal('root/parent-node/inline-child');
1167
+
1168
+ const deepNode = Graph.getNode(graph, 'root/parent-node/inline-child/deep-child').pipe(Option.getOrNull);
1169
+ expect(deepNode).to.not.be.null;
1170
+ expect(deepNode?.id).to.equal('root/parent-node/inline-child/deep-child');
1171
+ });
1172
+
1173
+ test('constant connector produces distinct nodes under different parents', async () => {
1174
+ const registry = Registry.make();
1175
+ const builder = GraphBuilder.make({ registry });
1176
+
1177
+ GraphBuilder.addExtension(builder, [
1178
+ GraphBuilder.createExtensionRaw({
1179
+ id: 'parents',
1180
+ connector: (node) =>
1181
+ Atom.make((get) =>
1182
+ Function.pipe(
1183
+ get(node),
1184
+ Option.filter((n) => n.id === 'root'),
1185
+ Option.map(() => [
1186
+ { id: 'A', type: EXAMPLE_TYPE, data: 'a' },
1187
+ { id: 'B', type: EXAMPLE_TYPE, data: 'b' },
1188
+ ]),
1189
+ Option.getOrElse(() => []),
1190
+ ),
1191
+ ),
1192
+ }),
1193
+ GraphBuilder.createExtensionRaw({
1194
+ id: 'constant-child',
1195
+ connector: () => Atom.make([{ id: 'shared', type: EXAMPLE_TYPE, data: 'constant' }]),
1196
+ }),
1197
+ ]);
1198
+
1199
+ const graph = builder.graph;
1200
+
1201
+ Graph.expand(graph, Node.RootId, 'child');
1202
+ await GraphBuilder.flush(builder);
1203
+
1204
+ Graph.expand(graph, 'root/A', 'child');
1205
+ Graph.expand(graph, 'root/B', 'child');
1206
+ await GraphBuilder.flush(builder);
1207
+
1208
+ const childrenOfA = registry.get(graph.connections('root/A', 'child'));
1209
+ const childrenOfB = registry.get(graph.connections('root/B', 'child'));
1210
+
1211
+ expect(childrenOfA).has.length(1);
1212
+ expect(childrenOfB).has.length(1);
1213
+ expect(childrenOfA[0].id).to.equal('root/A/shared');
1214
+ expect(childrenOfB[0].id).to.equal('root/B/shared');
1215
+
1216
+ const nodeA = Graph.getNode(graph, 'root/A/shared').pipe(Option.getOrNull);
1217
+ const nodeB = Graph.getNode(graph, 'root/B/shared').pipe(Option.getOrNull);
1218
+ expect(nodeA).to.not.be.null;
1219
+ expect(nodeB).to.not.be.null;
1220
+ expect(nodeA?.id).to.not.equal(nodeB?.id);
1221
+ });
1222
+
1223
+ test('explore qualifies node IDs', async () => {
1224
+ const builder = GraphBuilder.make();
1225
+ GraphBuilder.addExtension(
1226
+ builder,
1227
+ GraphBuilder.createExtensionRaw({
1228
+ id: 'connector',
1229
+ connector: (node) =>
1230
+ Atom.make((get) =>
1231
+ Function.pipe(
1232
+ get(node),
1233
+ Option.filter((n) => n.id === 'root'),
1234
+ Option.map(() => [
1235
+ { id: 'first', type: EXAMPLE_TYPE, data: 1 },
1236
+ { id: 'second', type: EXAMPLE_TYPE, data: 2 },
1237
+ ]),
1238
+ Option.getOrElse(() => []),
1239
+ ),
1240
+ ),
1241
+ }),
1242
+ );
1243
+
1244
+ const visited: Array<{ id: string; path: string[] }> = [];
1245
+ await GraphBuilder.explore(builder, {
1246
+ relation: 'child',
1247
+ visitor: (node, path) => {
1248
+ visited.push({ id: node.id, path });
1249
+ },
1250
+ });
1251
+
1252
+ expect(visited).has.length(3);
1253
+ expect(visited[0].id).to.equal('root');
1254
+ expect(visited[1].id).to.equal('root/first');
1255
+ expect(visited[2].id).to.equal('root/second');
1256
+ });
1257
+ });
1007
1258
  });
@@ -21,7 +21,7 @@ import { type MaybePromise, type Position, byPosition, getDebugName, isNonNullab
21
21
  import * as Graph from './graph';
22
22
  import * as Node from './node';
23
23
  import * as NodeMatcher from './node-matcher';
24
- import { Separators, nodeArgsUnchanged, normalizeRelation } from './util';
24
+ import { Separators, nodeArgsUnchanged, normalizeRelation, qualifyId, validateSegmentId } from './util';
25
25
 
26
26
  //
27
27
  // Extension Types
@@ -71,7 +71,7 @@ export type GraphBuilderTraverseOptions = {
71
71
  visitor: (node: Node.Node, path: string[]) => MaybePromise<boolean | void>;
72
72
  registry?: Registry.Registry;
73
73
  source?: string;
74
- relation: Node.RelationInput;
74
+ relation: Node.RelationInput | Node.RelationInput[];
75
75
  };
76
76
 
77
77
  /**
@@ -105,7 +105,9 @@ class GraphBuilderImpl implements GraphBuilder {
105
105
  }
106
106
 
107
107
  // TODO(wittjosiah): Use Context.
108
+ /** Active subscriptions keyed by composite ID, cleaned up on node removal. */
108
109
  readonly _subscriptions = new Map<string, CleanupFn>();
110
+ /** Connector updates pending flush, keyed by connector key. */
109
111
  readonly _dirtyConnectors = new Map<
110
112
  string,
111
113
  {
@@ -113,16 +115,24 @@ class GraphBuilderImpl implements GraphBuilder {
113
115
  previous: string[];
114
116
  }
115
117
  >();
118
+ /** Last-flushed node IDs per connector key, used for edge removal on update. */
116
119
  readonly _connectorPrevious = new Map<string, string[]>();
120
+ /** Last-flushed node args per connector key, used for change detection. */
117
121
  readonly _connectorPreviousArgs = new Map<string, Node.NodeArg<any>[]>();
122
+ /** Whether a dirty-flush task is already scheduled. */
118
123
  _flushScheduled = false;
124
+ /** Resolves when the current flush completes. */
119
125
  _flushPromise: Promise<void> = Promise.resolve();
126
+ /** Registered builder extensions keyed by extension ID. */
120
127
  readonly _extensions = Atom.make(Record.empty<string, BuilderExtension>()).pipe(
121
128
  Atom.keepAlive,
122
129
  Atom.withLabel('graph-builder:extensions'),
123
130
  );
131
+ /** Triggers signalling that a node's resolver has fired at least once. */
124
132
  readonly _initialized: Record<string, Trigger> = {};
133
+ /** Shared atom registry for reactive subscriptions. */
125
134
  readonly _registry: Registry.Registry;
135
+ /** Backing graph with internal accessors for node atoms and construction. */
126
136
  readonly _graph: Graph.Graph & {
127
137
  _node: (id: string) => Atom.Writable<Option.Option<Node.Node>>;
128
138
  _constructNode: (node: Node.NodeArg<any>) => Option.Option<Node.Node>;
@@ -263,7 +273,8 @@ class GraphBuilderImpl implements GraphBuilder {
263
273
 
264
274
  const cancel = this._registry.subscribe(
265
275
  connectors,
266
- (nodes) => {
276
+ (rawNodes) => {
277
+ const nodes = qualifyNodeArgs(id)(rawNodes);
267
278
  const previous = this._connectorPrevious.get(key) ?? [];
268
279
  const ids = nodes.map((n) => n.id);
269
280
 
@@ -295,7 +306,10 @@ class GraphBuilderImpl implements GraphBuilder {
295
306
  const trigger = this._initialized[id];
296
307
  Option.match(node, {
297
308
  onSome: (node) => {
298
- Graph.addNodes(this._graph, [node]);
309
+ const connectorOwned = [...this._connectorPrevious.values()].some((ids) => ids.includes(id));
310
+ if (!connectorOwned) {
311
+ Graph.addNodes(this._graph, [node]);
312
+ }
299
313
  trigger?.wake();
300
314
  },
301
315
  onNone: () => {
@@ -425,11 +439,14 @@ const exploreImpl = async (
425
439
  return;
426
440
  }
427
441
 
428
- const nodes = Object.values(internal._registry.get(internal._extensions))
429
- .filter((extension) => Graph.relationKey(extension.relation ?? 'child') === Graph.relationKey(relation))
430
- .map((extension) => extension.connector)
431
- .filter(isNonNullable)
432
- .flatMap((connector) => registry.get(connector(internal._graph.node(source))));
442
+ const nodes = Function.pipe(
443
+ internal._registry.get(internal._extensions),
444
+ Record.values,
445
+ Array.map((extension) => extension.connector),
446
+ Array.filter(isNonNullable),
447
+ Array.flatMap((connector) => registry.get(connector(internal._graph.node(source)))),
448
+ qualifyNodeArgs(source),
449
+ );
433
450
 
434
451
  await Promise.all(
435
452
  nodes.map((nodeArg) => {
@@ -793,6 +810,24 @@ export const createTypeExtension = <T extends Type.AnyEntity, R = never>(
793
810
  // Extension Utilities
794
811
  //
795
812
 
813
+ /**
814
+ * Qualify node IDs by prefixing with the parent path.
815
+ * Validates that segment IDs do not contain the path separator.
816
+ * Recursively qualifies inline child nodes.
817
+ */
818
+ const qualifyNodeArgs =
819
+ (parentId: string) =>
820
+ (nodes: Node.NodeArg<any>[]): Node.NodeArg<any>[] =>
821
+ nodes.map((node) => {
822
+ validateSegmentId(node.id);
823
+ const qualified = qualifyId(parentId, node.id);
824
+ return {
825
+ ...node,
826
+ id: qualified,
827
+ nodes: node.nodes ? qualifyNodeArgs(qualified)(node.nodes) : undefined,
828
+ };
829
+ });
830
+
796
831
  const connectorKey = (id: string, relation: Node.RelationInput): string =>
797
832
  `${id}${Separators.primary}${Graph.relationKey(relation)}`;
798
833