@dxos/app-graph 0.8.4-main.8360d9e660 → 0.8.4-main.8baae0fced
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/LICENSE +102 -5
- package/README.md +1 -1
- package/dist/lib/{browser/index.mjs → neutral/chunk-32XXJE6M.mjs} +247 -349
- package/dist/lib/neutral/chunk-32XXJE6M.mjs.map +7 -0
- package/dist/lib/neutral/chunk-J5LGTIGS.mjs +10 -0
- package/dist/lib/neutral/chunk-J5LGTIGS.mjs.map +7 -0
- package/dist/lib/neutral/index.mjs +40 -0
- package/dist/lib/neutral/index.mjs.map +7 -0
- package/dist/lib/neutral/meta.json +1 -0
- package/dist/lib/neutral/scheduler.mjs +15 -0
- package/dist/lib/neutral/scheduler.mjs.map +7 -0
- package/dist/lib/neutral/testing/index.mjs +40 -0
- package/dist/lib/neutral/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.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 +42 -16
- package/dist/types/src/node-matcher.d.ts.map +1 -1
- package/dist/types/src/node.d.ts +9 -3
- package/dist/types/src/node.d.ts.map +1 -1
- package/dist/types/src/scheduler.browser.d.ts +2 -0
- package/dist/types/src/scheduler.browser.d.ts.map +1 -0
- package/dist/types/src/scheduler.d.ts +8 -0
- package/dist/types/src/scheduler.d.ts.map +1 -0
- 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 +20 -14
- package/dist/types/src/util.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +38 -27
- package/src/graph-builder.test.ts +276 -25
- package/src/graph-builder.ts +45 -17
- package/src/graph.ts +15 -17
- package/src/index.ts +1 -0
- package/src/node-matcher.ts +57 -25
- package/src/node.ts +29 -3
- package/src/scheduler.browser.ts +5 -0
- package/src/scheduler.ts +17 -0
- package/src/stories/EchoGraph.stories.tsx +10 -12
- package/src/testing/index.ts +5 -0
- package/src/testing/setup-graph-builder.ts +41 -0
- package/src/util.ts +48 -18
- package/dist/lib/browser/index.mjs.map +0 -7
- package/dist/lib/browser/meta.json +0 -1
- package/dist/lib/node-esm/index.mjs +0 -1580
- package/dist/lib/node-esm/index.mjs.map +0 -7
- package/dist/lib/node-esm/meta.json +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/app-graph",
|
|
3
|
-
"version": "0.8.4-main.
|
|
3
|
+
"version": "0.8.4-main.8baae0fced",
|
|
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",
|
|
@@ -8,62 +8,73 @@
|
|
|
8
8
|
"type": "git",
|
|
9
9
|
"url": "https://github.com/dxos/dxos"
|
|
10
10
|
},
|
|
11
|
-
"license": "
|
|
11
|
+
"license": "FSL-1.1-Apache-2.0",
|
|
12
12
|
"author": "DXOS.org",
|
|
13
13
|
"sideEffects": false,
|
|
14
14
|
"type": "module",
|
|
15
|
+
"imports": {
|
|
16
|
+
"#scheduler": {
|
|
17
|
+
"source": {
|
|
18
|
+
"browser": "./src/scheduler.browser.ts",
|
|
19
|
+
"default": "./src/scheduler.ts"
|
|
20
|
+
},
|
|
21
|
+
"types": "./dist/types/src/scheduler.d.ts",
|
|
22
|
+
"default": "./dist/lib/neutral/scheduler.mjs"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
15
25
|
"exports": {
|
|
16
26
|
".": {
|
|
17
27
|
"source": "./src/index.ts",
|
|
18
28
|
"types": "./dist/types/src/index.d.ts",
|
|
19
|
-
"
|
|
20
|
-
|
|
29
|
+
"default": "./dist/lib/neutral/index.mjs"
|
|
30
|
+
},
|
|
31
|
+
"./testing": {
|
|
32
|
+
"source": "./src/testing/index.ts",
|
|
33
|
+
"types": "./dist/types/src/testing/index.d.ts",
|
|
34
|
+
"default": "./dist/lib/neutral/testing/index.mjs"
|
|
21
35
|
}
|
|
22
36
|
},
|
|
23
37
|
"types": "dist/types/src/index.d.ts",
|
|
24
|
-
"typesVersions": {
|
|
25
|
-
"*": {}
|
|
26
|
-
},
|
|
27
38
|
"files": [
|
|
28
39
|
"dist",
|
|
29
40
|
"src"
|
|
30
41
|
],
|
|
31
42
|
"dependencies": {
|
|
32
43
|
"main-thread-scheduling": "^14.1.1",
|
|
33
|
-
"@dxos/async": "0.8.4-main.
|
|
34
|
-
"@dxos/
|
|
35
|
-
"@dxos/echo-atom": "0.8.4-main.
|
|
36
|
-
"@dxos/
|
|
37
|
-
"@dxos/log": "0.8.4-main.
|
|
38
|
-
"@dxos/
|
|
39
|
-
"@dxos/util": "0.8.4-main.
|
|
44
|
+
"@dxos/async": "0.8.4-main.8baae0fced",
|
|
45
|
+
"@dxos/echo": "0.8.4-main.8baae0fced",
|
|
46
|
+
"@dxos/echo-atom": "0.8.4-main.8baae0fced",
|
|
47
|
+
"@dxos/debug": "0.8.4-main.8baae0fced",
|
|
48
|
+
"@dxos/log": "0.8.4-main.8baae0fced",
|
|
49
|
+
"@dxos/invariant": "0.8.4-main.8baae0fced",
|
|
50
|
+
"@dxos/util": "0.8.4-main.8baae0fced"
|
|
40
51
|
},
|
|
41
52
|
"devDependencies": {
|
|
42
53
|
"@effect-atom/atom-react": "^0.5.0",
|
|
43
54
|
"@effect/platform": "0.94.4",
|
|
44
55
|
"@types/react": "~19.2.7",
|
|
45
56
|
"@types/react-dom": "~19.2.3",
|
|
46
|
-
"effect": "3.
|
|
57
|
+
"effect": "3.20.0",
|
|
47
58
|
"react": "~19.2.3",
|
|
48
59
|
"react-dom": "~19.2.3",
|
|
49
|
-
"vite": "^
|
|
50
|
-
"@dxos/
|
|
51
|
-
"@dxos/
|
|
52
|
-
"@dxos/react-ui": "0.8.4-main.
|
|
53
|
-
"@dxos/react-
|
|
54
|
-
"@dxos/react-
|
|
55
|
-
"@dxos/
|
|
56
|
-
"@dxos/ui-
|
|
57
|
-
"@dxos/
|
|
60
|
+
"vite": "^8.0.13",
|
|
61
|
+
"@dxos/random": "0.8.4-main.8baae0fced",
|
|
62
|
+
"@dxos/echo-db": "0.8.4-main.8baae0fced",
|
|
63
|
+
"@dxos/react-ui-list": "0.8.4-main.8baae0fced",
|
|
64
|
+
"@dxos/react-ui": "0.8.4-main.8baae0fced",
|
|
65
|
+
"@dxos/react-client": "0.8.4-main.8baae0fced",
|
|
66
|
+
"@dxos/storybook-utils": "0.8.4-main.8baae0fced",
|
|
67
|
+
"@dxos/react-ui-tabs": "0.8.4-main.8baae0fced",
|
|
68
|
+
"@dxos/ui-theme": "0.8.4-main.8baae0fced"
|
|
58
69
|
},
|
|
59
70
|
"peerDependencies": {
|
|
60
71
|
"@effect-atom/atom-react": "^0.5.0",
|
|
61
72
|
"@effect/platform": "0.94.4",
|
|
62
|
-
"effect": "3.
|
|
73
|
+
"effect": "3.20.0",
|
|
63
74
|
"react": "~19.2.3",
|
|
64
75
|
"react-dom": "~19.2.3",
|
|
65
|
-
"@dxos/
|
|
66
|
-
"@dxos/ui
|
|
76
|
+
"@dxos/ui-theme": "0.8.4-main.8baae0fced",
|
|
77
|
+
"@dxos/react-ui": "0.8.4-main.8baae0fced"
|
|
67
78
|
},
|
|
68
79
|
"publishConfig": {
|
|
69
80
|
"access": "public"
|
|
@@ -17,13 +17,12 @@ import * as Graph from './graph';
|
|
|
17
17
|
import * as GraphBuilder from './graph-builder';
|
|
18
18
|
import * as Node from './node';
|
|
19
19
|
import * as NodeMatcher from './node-matcher';
|
|
20
|
+
import { qualifyId } from './util';
|
|
20
21
|
|
|
21
22
|
const exampleId = (id: number) => `dx:test:${id}`;
|
|
22
23
|
const EXAMPLE_ID = exampleId(1);
|
|
23
24
|
const EXAMPLE_TYPE = 'org.dxos.type.example';
|
|
24
25
|
|
|
25
|
-
const qualifiedId = (...segments: string[]) => segments.join('/');
|
|
26
|
-
|
|
27
26
|
describe('GraphBuilder', () => {
|
|
28
27
|
describe('resolver', () => {
|
|
29
28
|
test('works', async () => {
|
|
@@ -81,6 +80,132 @@ describe('GraphBuilder', () => {
|
|
|
81
80
|
}
|
|
82
81
|
});
|
|
83
82
|
|
|
83
|
+
test('connects resolved node to parent via child edge', async ({ expect }) => {
|
|
84
|
+
const registry = Registry.make();
|
|
85
|
+
const builder = GraphBuilder.make({ registry });
|
|
86
|
+
const childId = qualifyId('root', '~child');
|
|
87
|
+
|
|
88
|
+
GraphBuilder.addExtension(
|
|
89
|
+
builder,
|
|
90
|
+
GraphBuilder.createExtensionRaw({
|
|
91
|
+
id: 'resolver',
|
|
92
|
+
resolver: (id) =>
|
|
93
|
+
id === childId ? Atom.make({ id: childId, type: EXAMPLE_TYPE, data: 'resolved' }) : Atom.make(null),
|
|
94
|
+
}),
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
const graph = builder.graph;
|
|
98
|
+
await Graph.initialize(graph, childId);
|
|
99
|
+
|
|
100
|
+
{
|
|
101
|
+
const node = Graph.getNode(graph, childId).pipe(Option.getOrNull);
|
|
102
|
+
expect(node?.id).to.equal(childId);
|
|
103
|
+
expect(node?.data).to.equal('resolved');
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Verify the resolved node is a child of root.
|
|
107
|
+
{
|
|
108
|
+
const children = registry.get(graph.connections('root', 'child'));
|
|
109
|
+
expect(children.some((n) => n.id === childId)).to.be.true;
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
test('out-of-order: resolver fires before parent exists', async ({ expect }) => {
|
|
114
|
+
const registry = Registry.make();
|
|
115
|
+
const builder = GraphBuilder.make({ registry });
|
|
116
|
+
const parentId = qualifyId('root', 'parent');
|
|
117
|
+
const childId = qualifyId('root', 'parent', '~child');
|
|
118
|
+
|
|
119
|
+
GraphBuilder.addExtension(builder, [
|
|
120
|
+
GraphBuilder.createExtensionRaw({
|
|
121
|
+
id: 'resolver',
|
|
122
|
+
resolver: (id) =>
|
|
123
|
+
id === childId ? Atom.make({ id: childId, type: EXAMPLE_TYPE, data: 'resolved-child' }) : Atom.make(null),
|
|
124
|
+
}),
|
|
125
|
+
GraphBuilder.createExtensionRaw({
|
|
126
|
+
id: 'connector',
|
|
127
|
+
connector: (node) =>
|
|
128
|
+
Atom.make((get) =>
|
|
129
|
+
Function.pipe(
|
|
130
|
+
get(node),
|
|
131
|
+
Option.filter((n) => n.id === 'root'),
|
|
132
|
+
Option.map(() => [{ id: 'parent', type: EXAMPLE_TYPE, data: 'parent-data' }]),
|
|
133
|
+
Option.getOrElse(() => []),
|
|
134
|
+
),
|
|
135
|
+
),
|
|
136
|
+
}),
|
|
137
|
+
]);
|
|
138
|
+
|
|
139
|
+
const graph = builder.graph;
|
|
140
|
+
|
|
141
|
+
// Resolve child BEFORE parent exists in the graph.
|
|
142
|
+
await Graph.initialize(graph, childId);
|
|
143
|
+
|
|
144
|
+
{
|
|
145
|
+
const node = Graph.getNode(graph, childId).pipe(Option.getOrNull);
|
|
146
|
+
expect(node?.id).to.equal(childId);
|
|
147
|
+
expect(node?.data).to.equal('resolved-child');
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// Now expand root to create parent via connector.
|
|
151
|
+
Graph.expand(graph, Node.RootId, 'child');
|
|
152
|
+
await GraphBuilder.flush(builder);
|
|
153
|
+
|
|
154
|
+
{
|
|
155
|
+
const parent = Graph.getNode(graph, parentId).pipe(Option.getOrNull);
|
|
156
|
+
expect(parent?.data).to.equal('parent-data');
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// The resolved child should be connected to the parent.
|
|
160
|
+
{
|
|
161
|
+
const children = registry.get(graph.connections(parentId, 'child'));
|
|
162
|
+
expect(children.some((n) => n.id === childId)).to.be.true;
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
test('onNone does not remove connector-owned node', async ({ expect }) => {
|
|
167
|
+
const registry = Registry.make();
|
|
168
|
+
const builder = GraphBuilder.make({ registry });
|
|
169
|
+
const nodeId = qualifyId('root', 'shared');
|
|
170
|
+
|
|
171
|
+
// Connector that produces root/shared. No resolver matches root/shared.
|
|
172
|
+
GraphBuilder.addExtension(
|
|
173
|
+
builder,
|
|
174
|
+
GraphBuilder.createExtensionRaw({
|
|
175
|
+
id: 'connector',
|
|
176
|
+
connector: (node) =>
|
|
177
|
+
Atom.make((get) =>
|
|
178
|
+
Function.pipe(
|
|
179
|
+
get(node),
|
|
180
|
+
Option.filter((n) => n.id === 'root'),
|
|
181
|
+
Option.map(() => [{ id: 'shared', type: EXAMPLE_TYPE, data: 'from-connector' }]),
|
|
182
|
+
Option.getOrElse(() => []),
|
|
183
|
+
),
|
|
184
|
+
),
|
|
185
|
+
}),
|
|
186
|
+
);
|
|
187
|
+
|
|
188
|
+
const graph = builder.graph;
|
|
189
|
+
|
|
190
|
+
// Connector produces root/shared.
|
|
191
|
+
Graph.expand(graph, Node.RootId, 'child');
|
|
192
|
+
await GraphBuilder.flush(builder);
|
|
193
|
+
|
|
194
|
+
{
|
|
195
|
+
const node = Graph.getNode(graph, nodeId).pipe(Option.getOrNull);
|
|
196
|
+
expect(node?.data).to.equal('from-connector');
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// Initialize fires for the same ID. No resolver matches, so onNone fires.
|
|
200
|
+
// The connector-owned node should NOT be removed.
|
|
201
|
+
await Graph.initialize(graph, nodeId);
|
|
202
|
+
|
|
203
|
+
{
|
|
204
|
+
const node = Graph.getNode(graph, nodeId).pipe(Option.getOrNull);
|
|
205
|
+
expect(node?.data).to.equal('from-connector');
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
|
|
84
209
|
test('does not overwrite connector-produced node', async () => {
|
|
85
210
|
const registry = Registry.make();
|
|
86
211
|
const builder = GraphBuilder.make({ registry });
|
|
@@ -90,8 +215,8 @@ describe('GraphBuilder', () => {
|
|
|
90
215
|
GraphBuilder.createExtensionRaw({
|
|
91
216
|
id: 'resolver',
|
|
92
217
|
resolver: (id) =>
|
|
93
|
-
id ===
|
|
94
|
-
? Atom.make((get) => ({ id:
|
|
218
|
+
id === qualifyId('root', 'shared')
|
|
219
|
+
? Atom.make((get) => ({ id: qualifyId('root', 'shared'), type: EXAMPLE_TYPE, data: get(resolverData) }))
|
|
95
220
|
: Atom.make(null),
|
|
96
221
|
}),
|
|
97
222
|
GraphBuilder.createExtensionRaw({
|
|
@@ -115,15 +240,15 @@ describe('GraphBuilder', () => {
|
|
|
115
240
|
await GraphBuilder.flush(builder);
|
|
116
241
|
|
|
117
242
|
{
|
|
118
|
-
const node = Graph.getNode(graph,
|
|
243
|
+
const node = Graph.getNode(graph, qualifyId('root', 'shared')).pipe(Option.getOrNull);
|
|
119
244
|
expect(node?.data).to.equal('from-connector');
|
|
120
245
|
}
|
|
121
246
|
|
|
122
247
|
// Resolver fires for the same ID but should not overwrite.
|
|
123
|
-
await Graph.initialize(graph,
|
|
248
|
+
await Graph.initialize(graph, qualifyId('root', 'shared'));
|
|
124
249
|
|
|
125
250
|
{
|
|
126
|
-
const node = Graph.getNode(graph,
|
|
251
|
+
const node = Graph.getNode(graph, qualifyId('root', 'shared')).pipe(Option.getOrNull);
|
|
127
252
|
expect(node?.data).to.equal('from-connector');
|
|
128
253
|
}
|
|
129
254
|
|
|
@@ -131,7 +256,7 @@ describe('GraphBuilder', () => {
|
|
|
131
256
|
registry.set(resolverData, 'updated-resolver');
|
|
132
257
|
|
|
133
258
|
{
|
|
134
|
-
const node = Graph.getNode(graph,
|
|
259
|
+
const node = Graph.getNode(graph, qualifyId('root', 'shared')).pipe(Option.getOrNull);
|
|
135
260
|
expect(node?.data).to.equal('from-connector');
|
|
136
261
|
}
|
|
137
262
|
});
|
|
@@ -294,8 +419,8 @@ describe('GraphBuilder', () => {
|
|
|
294
419
|
{
|
|
295
420
|
const nodes = registry.get(graph.connections(Node.RootId, 'child'));
|
|
296
421
|
expect(nodes).has.length(2);
|
|
297
|
-
expect(nodes[0].id).to.equal(
|
|
298
|
-
expect(nodes[1].id).to.equal(
|
|
422
|
+
expect(nodes[0].id).to.equal(qualifyId('root', exampleId(1)));
|
|
423
|
+
expect(nodes[1].id).to.equal(qualifyId('root', exampleId(2)));
|
|
299
424
|
}
|
|
300
425
|
|
|
301
426
|
registry.set(nodes, [{ id: exampleId(3), type: EXAMPLE_TYPE }]);
|
|
@@ -304,7 +429,7 @@ describe('GraphBuilder', () => {
|
|
|
304
429
|
{
|
|
305
430
|
const nodes = registry.get(graph.connections(Node.RootId, 'child'));
|
|
306
431
|
expect(nodes).has.length(1);
|
|
307
|
-
expect(nodes[0].id).to.equal(
|
|
432
|
+
expect(nodes[0].id).to.equal(qualifyId('root', exampleId(3)));
|
|
308
433
|
}
|
|
309
434
|
});
|
|
310
435
|
|
|
@@ -333,7 +458,7 @@ describe('GraphBuilder', () => {
|
|
|
333
458
|
|
|
334
459
|
let count = 0;
|
|
335
460
|
let exists = false;
|
|
336
|
-
const cancel = registry.subscribe(graph.node(
|
|
461
|
+
const cancel = registry.subscribe(graph.node(qualifyId('root', EXAMPLE_ID)), (node) => {
|
|
337
462
|
count++;
|
|
338
463
|
exists = Option.isSome(node);
|
|
339
464
|
});
|
|
@@ -360,6 +485,132 @@ describe('GraphBuilder', () => {
|
|
|
360
485
|
expect(exists).to.be.true;
|
|
361
486
|
});
|
|
362
487
|
|
|
488
|
+
describe('inline nodes', () => {
|
|
489
|
+
const parent = (child?: Node.NodeArg<any>): Node.NodeArg<any> => ({
|
|
490
|
+
id: 'parent-node',
|
|
491
|
+
type: EXAMPLE_TYPE,
|
|
492
|
+
data: null,
|
|
493
|
+
nodes: child ? [child] : [],
|
|
494
|
+
});
|
|
495
|
+
|
|
496
|
+
const inlineChild = (overrides?: Partial<Node.NodeArg<any>>): Node.NodeArg<any> => ({
|
|
497
|
+
id: 'inline-child',
|
|
498
|
+
type: EXAMPLE_TYPE,
|
|
499
|
+
data: null,
|
|
500
|
+
...overrides,
|
|
501
|
+
});
|
|
502
|
+
|
|
503
|
+
const makeGraph = () => {
|
|
504
|
+
const registry = Registry.make();
|
|
505
|
+
const builder = GraphBuilder.make({ registry });
|
|
506
|
+
const nodesAtom = Atom.make<Node.NodeArg<any>[]>([]);
|
|
507
|
+
GraphBuilder.addExtension(
|
|
508
|
+
builder,
|
|
509
|
+
GraphBuilder.createExtensionRaw({
|
|
510
|
+
id: 'inline-connector',
|
|
511
|
+
connector: () => Atom.make((get) => get(nodesAtom)),
|
|
512
|
+
}),
|
|
513
|
+
);
|
|
514
|
+
const graph = builder.graph;
|
|
515
|
+
Graph.expand(graph, Node.RootId, 'child');
|
|
516
|
+
return { registry, builder, graph, nodesAtom };
|
|
517
|
+
};
|
|
518
|
+
|
|
519
|
+
const getInlineChild = (graph: Graph.ExpandableGraph) =>
|
|
520
|
+
Graph.getNode(graph, 'root/parent-node/inline-child').pipe(Option.getOrNull);
|
|
521
|
+
|
|
522
|
+
test('are removed when connector re-runs with data change', async () => {
|
|
523
|
+
const { registry, builder, graph, nodesAtom } = makeGraph();
|
|
524
|
+
registry.set(nodesAtom, [parent(inlineChild())]);
|
|
525
|
+
await GraphBuilder.flush(builder);
|
|
526
|
+
|
|
527
|
+
expect(getInlineChild(graph)).to.not.be.null;
|
|
528
|
+
|
|
529
|
+
// Remove inline child while also changing parent data to trigger the update.
|
|
530
|
+
registry.set(nodesAtom, [{ ...parent(), data: 'v2' }]);
|
|
531
|
+
await GraphBuilder.flush(builder);
|
|
532
|
+
|
|
533
|
+
expect(getInlineChild(graph)).to.be.null;
|
|
534
|
+
});
|
|
535
|
+
|
|
536
|
+
test('are removed when only inline children change', async () => {
|
|
537
|
+
const { registry, builder, graph, nodesAtom } = makeGraph();
|
|
538
|
+
registry.set(nodesAtom, [parent(inlineChild())]);
|
|
539
|
+
await GraphBuilder.flush(builder);
|
|
540
|
+
|
|
541
|
+
expect(getInlineChild(graph)).to.not.be.null;
|
|
542
|
+
|
|
543
|
+
// Remove inline child without touching parent — tests change detection covers inline children.
|
|
544
|
+
registry.set(nodesAtom, [parent()]);
|
|
545
|
+
await GraphBuilder.flush(builder);
|
|
546
|
+
|
|
547
|
+
expect(getInlineChild(graph)).to.be.null;
|
|
548
|
+
});
|
|
549
|
+
|
|
550
|
+
test('are added when connector re-runs', async () => {
|
|
551
|
+
const { registry, builder, graph, nodesAtom } = makeGraph();
|
|
552
|
+
registry.set(nodesAtom, [parent()]);
|
|
553
|
+
await GraphBuilder.flush(builder);
|
|
554
|
+
|
|
555
|
+
expect(getInlineChild(graph)).to.be.null;
|
|
556
|
+
|
|
557
|
+
registry.set(nodesAtom, [parent(inlineChild())]);
|
|
558
|
+
await GraphBuilder.flush(builder);
|
|
559
|
+
|
|
560
|
+
expect(getInlineChild(graph)).to.not.be.null;
|
|
561
|
+
});
|
|
562
|
+
|
|
563
|
+
test('reactively update data', async ({ expect }) => {
|
|
564
|
+
const { registry, builder, graph, nodesAtom } = makeGraph();
|
|
565
|
+
registry.set(nodesAtom, [parent(inlineChild({ data: 'v1' }))]);
|
|
566
|
+
await GraphBuilder.flush(builder);
|
|
567
|
+
|
|
568
|
+
expect(getInlineChild(graph)?.data).to.equal('v1');
|
|
569
|
+
|
|
570
|
+
// Change only the inline child's data — parent is unchanged.
|
|
571
|
+
registry.set(nodesAtom, [parent(inlineChild({ data: 'v2' }))]);
|
|
572
|
+
await GraphBuilder.flush(builder);
|
|
573
|
+
|
|
574
|
+
expect(getInlineChild(graph)?.data).to.equal('v2');
|
|
575
|
+
});
|
|
576
|
+
|
|
577
|
+
test('reactively update properties', async ({ expect }) => {
|
|
578
|
+
const { registry, builder, graph, nodesAtom } = makeGraph();
|
|
579
|
+
registry.set(nodesAtom, [parent(inlineChild({ properties: { label: 'before' } }))]);
|
|
580
|
+
await GraphBuilder.flush(builder);
|
|
581
|
+
|
|
582
|
+
expect(getInlineChild(graph)?.properties.label).to.equal('before');
|
|
583
|
+
|
|
584
|
+
registry.set(nodesAtom, [parent(inlineChild({ properties: { label: 'after' } }))]);
|
|
585
|
+
await GraphBuilder.flush(builder);
|
|
586
|
+
|
|
587
|
+
expect(getInlineChild(graph)?.properties.label).to.equal('after');
|
|
588
|
+
});
|
|
589
|
+
|
|
590
|
+
test('deeply nested inline nodes reactively update', async ({ expect }) => {
|
|
591
|
+
const { registry, builder, graph, nodesAtom } = makeGraph();
|
|
592
|
+
|
|
593
|
+
const withGrandchild = (data: string) =>
|
|
594
|
+
parent({
|
|
595
|
+
id: 'child',
|
|
596
|
+
type: EXAMPLE_TYPE,
|
|
597
|
+
data: null,
|
|
598
|
+
nodes: [{ id: 'grandchild', type: EXAMPLE_TYPE, data }],
|
|
599
|
+
});
|
|
600
|
+
|
|
601
|
+
registry.set(nodesAtom, [withGrandchild('v1')]);
|
|
602
|
+
await GraphBuilder.flush(builder);
|
|
603
|
+
|
|
604
|
+
expect(Graph.getNode(graph, 'root/parent-node/child/grandchild').pipe(Option.getOrNull)?.data).to.equal('v1');
|
|
605
|
+
|
|
606
|
+
// Change only the grandchild's data — all ancestors unchanged.
|
|
607
|
+
registry.set(nodesAtom, [withGrandchild('v2')]);
|
|
608
|
+
await GraphBuilder.flush(builder);
|
|
609
|
+
|
|
610
|
+
expect(Graph.getNode(graph, 'root/parent-node/child/grandchild').pipe(Option.getOrNull)?.data).to.equal('v2');
|
|
611
|
+
});
|
|
612
|
+
});
|
|
613
|
+
|
|
363
614
|
test('sort edges', async () => {
|
|
364
615
|
const registry = Registry.make();
|
|
365
616
|
const builder = GraphBuilder.make({ registry });
|
|
@@ -382,9 +633,9 @@ describe('GraphBuilder', () => {
|
|
|
382
633
|
{
|
|
383
634
|
const nodes = registry.get(graph.connections(Node.RootId, 'child'));
|
|
384
635
|
expect(nodes).has.length(3);
|
|
385
|
-
expect(nodes[0].id).to.equal(
|
|
386
|
-
expect(nodes[1].id).to.equal(
|
|
387
|
-
expect(nodes[2].id).to.equal(
|
|
636
|
+
expect(nodes[0].id).to.equal(qualifyId('root', exampleId(1)));
|
|
637
|
+
expect(nodes[1].id).to.equal(qualifyId('root', exampleId(2)));
|
|
638
|
+
expect(nodes[2].id).to.equal(qualifyId('root', exampleId(3)));
|
|
388
639
|
}
|
|
389
640
|
|
|
390
641
|
registry.set(nodes, [
|
|
@@ -397,9 +648,9 @@ describe('GraphBuilder', () => {
|
|
|
397
648
|
{
|
|
398
649
|
const nodes = registry.get(graph.connections(Node.RootId, 'child'));
|
|
399
650
|
expect(nodes).has.length(3);
|
|
400
|
-
expect(nodes[0].id).to.equal(
|
|
401
|
-
expect(nodes[1].id).to.equal(
|
|
402
|
-
expect(nodes[2].id).to.equal(
|
|
651
|
+
expect(nodes[0].id).to.equal(qualifyId('root', exampleId(3)));
|
|
652
|
+
expect(nodes[1].id).to.equal(qualifyId('root', exampleId(1)));
|
|
653
|
+
expect(nodes[2].id).to.equal(qualifyId('root', exampleId(2)));
|
|
403
654
|
}
|
|
404
655
|
});
|
|
405
656
|
|
|
@@ -430,7 +681,7 @@ describe('GraphBuilder', () => {
|
|
|
430
681
|
Function.pipe(
|
|
431
682
|
get(node),
|
|
432
683
|
Option.flatMap((node) =>
|
|
433
|
-
node.id ===
|
|
684
|
+
node.id === qualifyId('root', EXAMPLE_ID) ? Option.some(get(sub)) : Option.none(),
|
|
434
685
|
),
|
|
435
686
|
Option.map((sub) => [{ id: exampleId(2), type: EXAMPLE_TYPE, data: sub }]),
|
|
436
687
|
Option.getOrElse(() => []),
|
|
@@ -444,7 +695,7 @@ describe('GraphBuilder', () => {
|
|
|
444
695
|
Function.pipe(
|
|
445
696
|
get(node),
|
|
446
697
|
Option.flatMap((node) =>
|
|
447
|
-
node.id ===
|
|
698
|
+
node.id === qualifyId('root', EXAMPLE_ID) ? Option.some(node.data) : Option.none(),
|
|
448
699
|
),
|
|
449
700
|
Option.map((data) => [{ id: exampleId(3), type: EXAMPLE_TYPE, data }]),
|
|
450
701
|
Option.getOrElse(() => []),
|
|
@@ -456,19 +707,19 @@ describe('GraphBuilder', () => {
|
|
|
456
707
|
const graph = builder.graph;
|
|
457
708
|
|
|
458
709
|
let parentCount = 0;
|
|
459
|
-
const parentCancel = registry.subscribe(graph.node(
|
|
710
|
+
const parentCancel = registry.subscribe(graph.node(qualifyId('root', EXAMPLE_ID)), (_) => {
|
|
460
711
|
parentCount++;
|
|
461
712
|
});
|
|
462
713
|
onTestFinished(() => parentCancel());
|
|
463
714
|
|
|
464
715
|
let independentCount = 0;
|
|
465
|
-
const independentCancel = registry.subscribe(graph.node(
|
|
716
|
+
const independentCancel = registry.subscribe(graph.node(qualifyId('root', EXAMPLE_ID, exampleId(2))), (_) => {
|
|
466
717
|
independentCount++;
|
|
467
718
|
});
|
|
468
719
|
onTestFinished(() => independentCancel());
|
|
469
720
|
|
|
470
721
|
let dependentCount = 0;
|
|
471
|
-
const dependentCancel = registry.subscribe(graph.node(
|
|
722
|
+
const dependentCancel = registry.subscribe(graph.node(qualifyId('root', EXAMPLE_ID, exampleId(3))), (_) => {
|
|
472
723
|
dependentCount++;
|
|
473
724
|
});
|
|
474
725
|
onTestFinished(() => dependentCancel());
|
|
@@ -481,7 +732,7 @@ describe('GraphBuilder', () => {
|
|
|
481
732
|
expect(dependentCount).to.equal(0);
|
|
482
733
|
|
|
483
734
|
// Counts should increment when the node is expanded.
|
|
484
|
-
Graph.expand(graph,
|
|
735
|
+
Graph.expand(graph, qualifyId('root', EXAMPLE_ID), 'child');
|
|
485
736
|
await GraphBuilder.flush(builder);
|
|
486
737
|
expect(parentCount).to.equal(1);
|
|
487
738
|
expect(independentCount).to.equal(1);
|
|
@@ -519,7 +770,7 @@ describe('GraphBuilder', () => {
|
|
|
519
770
|
expect(dependentCount).to.equal(3);
|
|
520
771
|
|
|
521
772
|
// Counts should not increment when the node is expanded again.
|
|
522
|
-
Graph.expand(graph,
|
|
773
|
+
Graph.expand(graph, qualifyId('root', EXAMPLE_ID), 'child');
|
|
523
774
|
await GraphBuilder.flush(builder);
|
|
524
775
|
expect(parentCount).to.equal(3);
|
|
525
776
|
expect(independentCount).to.equal(3);
|