@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/src/graph.test.ts CHANGED
@@ -12,7 +12,7 @@ import * as Node from './node';
12
12
 
13
13
  const exampleId = (id: number) => `dx:test:${id}`;
14
14
  const EXAMPLE_ID = exampleId(1);
15
- const EXAMPLE_TYPE = 'dxos.org/type/example';
15
+ const EXAMPLE_TYPE = 'org.dxos.type.example';
16
16
  const CHILD_RELATION_KEY = Graph.relationKey('child');
17
17
  const CHILD_INBOUND_RELATION_KEY = Graph.relationKey(Node.childRelation('inbound'));
18
18
  const ACTIONS_RELATION_KEY = Graph.relationKey('action');
@@ -602,6 +602,26 @@ describe('Graph', () => {
602
602
  expect(nodes).to.deep.equal(['root', 'test1']);
603
603
  });
604
604
 
605
+ test('traversal with multiple relations follows all edge types', () => {
606
+ const graph = Graph.make();
607
+ Graph.addNode(graph, {
608
+ id: Node.RootId,
609
+ type: Node.RootType,
610
+ nodes: [{ id: 'child1', type: 'test' }],
611
+ });
612
+ Graph.addNode(graph, { id: 'action1', type: Node.ActionType });
613
+ Graph.addEdge(graph, { source: Node.RootId, target: 'action1', relation: 'action' });
614
+
615
+ const nodes: string[] = [];
616
+ Graph.traverse(graph, {
617
+ relation: ['child', 'action'],
618
+ visitor: (node) => {
619
+ nodes.push(node.id);
620
+ },
621
+ });
622
+ expect(nodes).to.deep.equal(['root', 'child1', 'action1']);
623
+ });
624
+
605
625
  test('traverse curried', () => {
606
626
  const graph = Graph.make();
607
627
  Graph.addNode(graph, {
package/src/graph.ts CHANGED
@@ -49,8 +49,8 @@ export type GraphTraversalOptions = {
49
49
  */
50
50
  source?: string;
51
51
 
52
- /** The relation to traverse graph edges. */
53
- relation: Node.RelationInput;
52
+ /** The relation(s) to traverse graph edges. */
53
+ relation: Node.RelationInput | Node.RelationInput[];
54
54
  };
55
55
 
56
56
  export type GraphProps = {
@@ -183,6 +183,9 @@ class GraphImpl implements WritableGraph {
183
183
  // TODO(wittjosiah): Atom feature request, support for something akin to `ComplexMap` to allow for complex arguments.
184
184
  readonly _connections = Atom.family<string, Atom.Atom<Node.Node[]>>((key) => {
185
185
  return Atom.make((get) => {
186
+ if (!key || key.indexOf(Separators.primary) <= 0) {
187
+ return [];
188
+ }
186
189
  const { id, relation } = relationFromConnectionKey(key);
187
190
  const edges = get(this._edges(id));
188
191
  return (edges[relationKey(relation)] ?? [])
@@ -194,6 +197,9 @@ class GraphImpl implements WritableGraph {
194
197
 
195
198
  readonly _actions = Atom.family<string, Atom.Atom<(Node.Action | Node.ActionGroup)[]>>((id) => {
196
199
  return Atom.make((get) => {
200
+ if (!id) {
201
+ return [];
202
+ }
197
203
  return get(this._connections(connectionKey(id, Node.actionRelation()))) as (Node.Action | Node.ActionGroup)[];
198
204
  }).pipe(Atom.withLabel(`graph:actions:${id}`));
199
205
  });
@@ -515,9 +521,16 @@ const traverseImpl = (graph: BaseGraph, options: GraphTraversalOptions, path: st
515
521
  return;
516
522
  }
517
523
 
518
- Object.values(getConnections(graph, source, relation)).forEach((child) =>
519
- traverseImpl(graph, { source: child.id, relation, visitor }, [...path, source]),
520
- );
524
+ const relations = Array.isArray(relation) ? relation : [relation];
525
+ const seen = new Set<string>();
526
+ for (const rel of relations) {
527
+ for (const connected of getConnections(graph, source, rel)) {
528
+ if (!seen.has(connected.id)) {
529
+ seen.add(connected.id);
530
+ traverseImpl(graph, { source: connected.id, relation, visitor }, [...path, source]);
531
+ }
532
+ }
533
+ }
521
534
  };
522
535
 
523
536
  /**
@@ -69,7 +69,7 @@ export const whenId =
69
69
  * ```ts
70
70
  * GraphBuilder.createExtension({
71
71
  * id: 'space-settings-extension',
72
- * match: NodeMatcher.whenNodeType('dxos.org/plugin/space/settings'),
72
+ * match: NodeMatcher.whenNodeType('org.dxos.plugin.space.settings'),
73
73
  * connector: (node) => Effect.succeed([...]),
74
74
  * });
75
75
  * ```
@@ -129,7 +129,7 @@ export const whenEchoType =
129
129
  * connector: (object) => {
130
130
  * // `object` is typed as Obj.Unknown
131
131
  * const id = Obj.getDXN(object).toString();
132
- * return Effect.succeed([{ id: `${id}/settings`, ... }]);
132
+ * return Effect.succeed([{ id: `${id}.settings`, ... }]);
133
133
  * },
134
134
  * });
135
135
  * ```
package/src/node.ts CHANGED
@@ -15,17 +15,17 @@ export const RootId = 'root';
15
15
  /**
16
16
  * Root node type.
17
17
  */
18
- export const RootType = 'dxos.org/type/GraphRoot';
18
+ export const RootType = 'org.dxos.type.graph-root';
19
19
 
20
20
  /**
21
21
  * Action node type.
22
22
  */
23
- export const ActionType = 'dxos.org/type/GraphAction';
23
+ export const ActionType = 'org.dxos.type.graph-action';
24
24
 
25
25
  /**
26
26
  * Action group node type.
27
27
  */
28
- export const ActionGroupType = 'dxos.org/type/GraphActionGroup';
28
+ export const ActionGroupType = 'org.dxos.type.graph-action-group';
29
29
 
30
30
  /**
31
31
  * Represents a node in the graph.
@@ -107,6 +107,9 @@ export type InvokeProps = {
107
107
  /** Node the invoked action is connected to. */
108
108
  parent?: Node;
109
109
 
110
+ /** Path from root to the node in the current tree context. */
111
+ path?: string[];
112
+
110
113
  caller?: string;
111
114
  };
112
115
 
@@ -64,7 +64,7 @@ const createGraph = (client: Client, registry: Registry.Registry): Graph.Expanda
64
64
  const propertiesSnapshot = get(AtomObj.make(space.properties));
65
65
  return {
66
66
  id: space.id,
67
- type: 'dxos.org/type/Space',
67
+ type: 'org.dxos.type.space',
68
68
  properties: {
69
69
  label: propertiesSnapshot.name,
70
70
  },
@@ -88,7 +88,7 @@ const createGraph = (client: Client, registry: Registry.Registry): Graph.Expanda
88
88
  const objects = get(AtomQuery.make(space.db, Query.type(TestSchema.Expando, { type: 'test' })));
89
89
  return objects.map((object) => ({
90
90
  id: object.id,
91
- type: 'dxos.org/type/test',
91
+ type: 'org.dxos.type.test',
92
92
  properties: { label: object.name },
93
93
  data: object,
94
94
  }));
@@ -347,7 +347,7 @@ export const TreeView: Story = {
347
347
  return {
348
348
  id: node.id,
349
349
  label: node.id,
350
- icon: node.type === 'dxos.org/type/Space' ? 'ph--planet--regular' : 'ph--placeholder--regular',
350
+ icon: node.type === 'org.dxos.type.space' ? 'ph--planet--regular' : 'ph--placeholder--regular',
351
351
  parentOf,
352
352
  };
353
353
  });
package/src/util.ts CHANGED
@@ -2,17 +2,21 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
+ import { invariant } from '@dxos/invariant';
6
+
5
7
  import * as Node from './node';
6
8
 
7
9
  /**
8
10
  * Key separators for compound string keys used across the app-graph package.
9
11
  * `primary` separates top-level components (e.g., node ID from relation).
10
12
  * `secondary` separates sub-components within an encoded value (e.g., relation kind from direction).
13
+ * `path` separates segments in qualified node IDs (e.g., parent path from local segment).
11
14
  * Two distinct characters are needed because secondary separators appear inside primary-separated fields.
12
15
  */
13
16
  export const Separators = {
14
17
  primary: '\u0001',
15
18
  secondary: '\u0002',
19
+ path: '/',
16
20
  } as const;
17
21
 
18
22
  /**
@@ -53,3 +57,15 @@ export const nodeArgsUnchanged = (prev: Node.NodeArg<any>[], next: Node.NodeArg<
53
57
  );
54
58
  });
55
59
  };
60
+
61
+ /**
62
+ * Build a qualified node ID by joining a parent path with a local segment.
63
+ */
64
+ export const qualifyId = (parentId: string, segmentId: string): string => `${parentId}${Separators.path}${segmentId}`;
65
+
66
+ /**
67
+ * Validate that a segment ID does not contain the path separator.
68
+ */
69
+ export const validateSegmentId = (id: string): void => {
70
+ invariant(!id.includes(Separators.path), `Node segment ID must not contain '${Separators.path}': ${id}`);
71
+ };