@dxos/app-graph 0.8.4-main.c85a9c8dae → 0.8.4-main.cb12b3f963
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/chunk-3T75MQOS.mjs +1480 -0
- package/dist/lib/browser/chunk-3T75MQOS.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +17 -1501
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +39 -0
- package/dist/lib/browser/testing/index.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-UEXRLXMS.mjs +1481 -0
- package/dist/lib/node-esm/chunk-UEXRLXMS.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +17 -1501
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +40 -0
- package/dist/lib/node-esm/testing/index.mjs.map +7 -0
- package/dist/types/src/atoms.d.ts.map +1 -1
- package/dist/types/src/graph-builder.d.ts +2 -2
- package/dist/types/src/graph-builder.d.ts.map +1 -1
- package/dist/types/src/graph.d.ts +2 -2
- package/dist/types/src/graph.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +1 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/node-matcher.d.ts +44 -18
- package/dist/types/src/node-matcher.d.ts.map +1 -1
- package/dist/types/src/node.d.ts +11 -3
- package/dist/types/src/node.d.ts.map +1 -1
- package/dist/types/src/stories/EchoGraph.stories.d.ts.map +1 -1
- package/dist/types/src/testing/index.d.ts +2 -0
- package/dist/types/src/testing/index.d.ts.map +1 -0
- package/dist/types/src/testing/setup-graph-builder.d.ts +31 -0
- package/dist/types/src/testing/setup-graph-builder.d.ts.map +1 -0
- package/dist/types/src/util.d.ts +26 -10
- package/dist/types/src/util.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +27 -24
- package/src/graph-builder.test.ts +536 -34
- package/src/graph-builder.ts +83 -21
- package/src/graph.test.ts +21 -1
- package/src/graph.ts +32 -21
- package/src/index.ts +1 -0
- package/src/node-matcher.ts +59 -27
- package/src/node.ts +32 -3
- package/src/stories/EchoGraph.stories.tsx +11 -13
- package/src/testing/index.ts +5 -0
- package/src/testing/setup-graph-builder.ts +41 -0
- package/src/util.ts +59 -13
|
@@ -10,14 +10,14 @@ import React, { type PropsWithChildren, useCallback, useContext, useEffect, useM
|
|
|
10
10
|
|
|
11
11
|
import { Filter, type Space, SpaceState, isSpace } from '@dxos/client/echo';
|
|
12
12
|
import { Obj, Query } from '@dxos/echo';
|
|
13
|
-
import { TestSchema } from '@dxos/echo/testing';
|
|
14
13
|
import { AtomObj, AtomQuery } from '@dxos/echo-atom';
|
|
15
|
-
import {
|
|
14
|
+
import { TestSchema } from '@dxos/echo/testing';
|
|
15
|
+
import { random } from '@dxos/random';
|
|
16
16
|
import { type Client, useClient } from '@dxos/react-client';
|
|
17
17
|
import { withClientProvider } from '@dxos/react-client/testing';
|
|
18
18
|
import { Icon, IconButton, Input, Select } from '@dxos/react-ui';
|
|
19
|
-
import { withTheme } from '@dxos/react-ui/testing';
|
|
20
19
|
import { Path, Tree, type TreeModel } from '@dxos/react-ui-list';
|
|
20
|
+
import { withTheme } from '@dxos/react-ui/testing';
|
|
21
21
|
import { getSize, mx } from '@dxos/ui-theme';
|
|
22
22
|
import { safeParseInt } from '@dxos/util';
|
|
23
23
|
|
|
@@ -25,7 +25,6 @@ import * as CreateAtom from '../atoms';
|
|
|
25
25
|
import * as Graph from '../graph';
|
|
26
26
|
import * as GraphBuilder from '../graph-builder';
|
|
27
27
|
import * as Node from '../node';
|
|
28
|
-
|
|
29
28
|
import { JsonTree } from './Tree';
|
|
30
29
|
|
|
31
30
|
const DEFAULT_PERIOD = 500;
|
|
@@ -64,7 +63,7 @@ const createGraph = (client: Client, registry: Registry.Registry): Graph.Expanda
|
|
|
64
63
|
const propertiesSnapshot = get(AtomObj.make(space.properties));
|
|
65
64
|
return {
|
|
66
65
|
id: space.id,
|
|
67
|
-
type: 'dxos.
|
|
66
|
+
type: 'org.dxos.type.space',
|
|
68
67
|
properties: {
|
|
69
68
|
label: propertiesSnapshot.name,
|
|
70
69
|
},
|
|
@@ -88,7 +87,7 @@ const createGraph = (client: Client, registry: Registry.Registry): Graph.Expanda
|
|
|
88
87
|
const objects = get(AtomQuery.make(space.db, Query.type(TestSchema.Expando, { type: 'test' })));
|
|
89
88
|
return objects.map((object) => ({
|
|
90
89
|
id: object.id,
|
|
91
|
-
type: 'dxos.
|
|
90
|
+
type: 'org.dxos.type.test',
|
|
92
91
|
properties: { label: object.name },
|
|
93
92
|
data: object,
|
|
94
93
|
}));
|
|
@@ -146,8 +145,8 @@ const runAction = async (client: Client, action: Action) => {
|
|
|
146
145
|
case Action.RENAME_SPACE: {
|
|
147
146
|
const space = getRandomSpace(client);
|
|
148
147
|
if (space) {
|
|
149
|
-
Obj.
|
|
150
|
-
|
|
148
|
+
Obj.update(space.properties, (obj) => {
|
|
149
|
+
obj.name = random.commerce.productName();
|
|
151
150
|
});
|
|
152
151
|
}
|
|
153
152
|
break;
|
|
@@ -157,7 +156,7 @@ const runAction = async (client: Client, action: Action) => {
|
|
|
157
156
|
getRandomSpace(client)?.db.add(
|
|
158
157
|
Obj.make(TestSchema.Expando, {
|
|
159
158
|
type: 'test',
|
|
160
|
-
name:
|
|
159
|
+
name: random.commerce.productName(),
|
|
161
160
|
}),
|
|
162
161
|
);
|
|
163
162
|
break;
|
|
@@ -176,8 +175,8 @@ const runAction = async (client: Client, action: Action) => {
|
|
|
176
175
|
if (space) {
|
|
177
176
|
const objects = await space.db.query(Filter.type(TestSchema.Expando, { type: 'test' })).run();
|
|
178
177
|
const object = objects[Math.floor(Math.random() * objects.length)];
|
|
179
|
-
Obj.
|
|
180
|
-
|
|
178
|
+
Obj.update(object, (object) => {
|
|
179
|
+
object.name = random.commerce.productName();
|
|
181
180
|
});
|
|
182
181
|
}
|
|
183
182
|
break;
|
|
@@ -216,7 +215,6 @@ const Controls = ({ children }: PropsWithChildren) => {
|
|
|
216
215
|
<Input.Root>
|
|
217
216
|
<Input.TextInput
|
|
218
217
|
autoComplete='off'
|
|
219
|
-
size={5}
|
|
220
218
|
classNames='w-[100px] text-right pe-[22px]'
|
|
221
219
|
placeholder='Interval'
|
|
222
220
|
value={actionInterval}
|
|
@@ -347,7 +345,7 @@ export const TreeView: Story = {
|
|
|
347
345
|
return {
|
|
348
346
|
id: node.id,
|
|
349
347
|
label: node.id,
|
|
350
|
-
icon: node.type === 'dxos.
|
|
348
|
+
icon: node.type === 'org.dxos.type.space' ? 'ph--planet--regular' : 'ph--placeholder--regular',
|
|
351
349
|
parentOf,
|
|
352
350
|
};
|
|
353
351
|
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2026 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { Registry } from '@effect-atom/atom-react';
|
|
6
|
+
import * as Option from 'effect/Option';
|
|
7
|
+
|
|
8
|
+
import * as Graph from '../graph';
|
|
9
|
+
import * as GraphBuilder from '../graph-builder';
|
|
10
|
+
import * as Node from '../node';
|
|
11
|
+
|
|
12
|
+
export type SetupGraphBuilderOptions = {
|
|
13
|
+
registry?: Registry.Registry;
|
|
14
|
+
extensions?: GraphBuilder.BuilderExtensions;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const setupGraphBuilder = ({ registry = Registry.make(), extensions }: SetupGraphBuilderOptions = {}) => {
|
|
18
|
+
const builder = GraphBuilder.make({ registry });
|
|
19
|
+
const graph = builder.graph;
|
|
20
|
+
|
|
21
|
+
if (extensions) {
|
|
22
|
+
GraphBuilder.addExtension(builder, extensions);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return {
|
|
26
|
+
registry,
|
|
27
|
+
builder,
|
|
28
|
+
graph,
|
|
29
|
+
addExtensions: (nextExtensions: GraphBuilder.BuilderExtensions) => {
|
|
30
|
+
GraphBuilder.addExtension(builder, nextExtensions);
|
|
31
|
+
},
|
|
32
|
+
expand: async (id: string, relation: Node.RelationInput = 'child') => {
|
|
33
|
+
Graph.expand(graph, id, relation);
|
|
34
|
+
await GraphBuilder.flush(builder);
|
|
35
|
+
},
|
|
36
|
+
flush: () => GraphBuilder.flush(builder),
|
|
37
|
+
getConnections: (id: string, relation: Node.RelationInput = 'child') =>
|
|
38
|
+
registry.get(graph.connections(id, relation)),
|
|
39
|
+
getNode: (id: string) => Graph.getNode(graph, id).pipe(Option.getOrNull),
|
|
40
|
+
};
|
|
41
|
+
};
|
package/src/util.ts
CHANGED
|
@@ -2,18 +2,30 @@
|
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
9
|
+
// PRIMARY separates top-level components (e.g., node ID from relation) in compound string keys used within the app-graph package.
|
|
10
|
+
const PRIMARY = '\u0001';
|
|
11
|
+
|
|
12
|
+
// SECONDARY separates sub-components within an encoded value (e.g., relation kind from direction) in the same context.
|
|
13
|
+
const SECONDARY = '\u0002';
|
|
14
|
+
|
|
15
|
+
// PATH separates segments in qualified node IDs (e.g., parent path from local segment).
|
|
16
|
+
const PATH = '/';
|
|
17
|
+
|
|
18
|
+
/** Join parts with the primary separator. */
|
|
19
|
+
export const primaryKey = (...parts: string[]): string => parts.join(PRIMARY);
|
|
20
|
+
|
|
21
|
+
/** Split a key on the primary separator. */
|
|
22
|
+
export const primaryParts = (key: string): string[] => key.split(PRIMARY);
|
|
23
|
+
|
|
24
|
+
/** Join parts with the secondary separator. */
|
|
25
|
+
export const secondaryKey = (...parts: string[]): string => parts.join(SECONDARY);
|
|
26
|
+
|
|
27
|
+
/** Split a key on the secondary separator. */
|
|
28
|
+
export const secondaryParts = (key: string): string[] => key.split(SECONDARY);
|
|
17
29
|
|
|
18
30
|
/**
|
|
19
31
|
* Normalize a relation input to a full Relation object.
|
|
@@ -25,8 +37,12 @@ export const normalizeRelation = (relation?: Node.RelationInput): Node.Relation
|
|
|
25
37
|
* Shallow-compare two values: same reference, or same own-keys with === values.
|
|
26
38
|
*/
|
|
27
39
|
export const shallowEqual = (a: unknown, b: unknown): boolean => {
|
|
28
|
-
if (a === b)
|
|
29
|
-
|
|
40
|
+
if (a === b) {
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
if (a == null || b == null || typeof a !== 'object' || typeof b !== 'object') {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
30
46
|
const keysA = Object.keys(a as Record<string, unknown>);
|
|
31
47
|
const keysB = Object.keys(b as Record<string, unknown>);
|
|
32
48
|
if (keysA.length !== keysB.length) {
|
|
@@ -37,6 +53,7 @@ export const shallowEqual = (a: unknown, b: unknown): boolean => {
|
|
|
37
53
|
|
|
38
54
|
/**
|
|
39
55
|
* Returns true if two NodeArg arrays are semantically identical (same id, type, data, properties per index).
|
|
56
|
+
* Inline child nodes (the `nodes` field) are compared recursively.
|
|
40
57
|
*/
|
|
41
58
|
export const nodeArgsUnchanged = (prev: Node.NodeArg<any>[], next: Node.NodeArg<any>[]): boolean => {
|
|
42
59
|
if (prev.length !== next.length) {
|
|
@@ -49,7 +66,36 @@ export const nodeArgsUnchanged = (prev: Node.NodeArg<any>[], next: Node.NodeArg<
|
|
|
49
66
|
prevNode.id === nextNode.id &&
|
|
50
67
|
prevNode.type === nextNode.type &&
|
|
51
68
|
shallowEqual(prevNode.data, nextNode.data) &&
|
|
52
|
-
shallowEqual(prevNode.properties, nextNode.properties)
|
|
69
|
+
shallowEqual(prevNode.properties, nextNode.properties) &&
|
|
70
|
+
nodeArgsUnchanged(prevNode.nodes ?? [], nextNode.nodes ?? [])
|
|
53
71
|
);
|
|
54
72
|
});
|
|
55
73
|
};
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Build a qualified node ID by joining path segments.
|
|
77
|
+
*/
|
|
78
|
+
export const qualifyId = (parentId: string, ...segmentIds: string[]): string => [parentId, ...segmentIds].join(PATH);
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Validate that a segment ID does not contain the path separator.
|
|
82
|
+
*/
|
|
83
|
+
export const validateSegmentId = (id: string): void => {
|
|
84
|
+
invariant(!id.includes(PATH), `Node segment ID must not contain '${PATH}': ${id}`);
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Extract the parent qualified ID (everything before the last path separator).
|
|
89
|
+
* Returns undefined for IDs with no parent (single segment).
|
|
90
|
+
*/
|
|
91
|
+
export const getParentId = (qualifiedId: string): string | undefined => {
|
|
92
|
+
const lastSlash = qualifiedId.lastIndexOf(PATH);
|
|
93
|
+
return lastSlash > 0 ? qualifiedId.slice(0, lastSlash) : undefined;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Extract the last segment of a qualified ID.
|
|
98
|
+
*/
|
|
99
|
+
export const getSegmentId = (qualifiedId: string): string => {
|
|
100
|
+
return qualifiedId.split(PATH).pop() ?? qualifiedId;
|
|
101
|
+
};
|