@dxos/plugin-graph 0.8.4-main.e8ec1fe → 0.8.4-main.effb148878
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/neutral/GraphPlugin.mjs +9 -0
- package/dist/lib/neutral/GraphPlugin.mjs.map +7 -0
- package/dist/lib/neutral/chunk-QECLJ7AR.mjs +60 -0
- package/dist/lib/neutral/chunk-QECLJ7AR.mjs.map +7 -0
- package/dist/lib/neutral/chunk-S2DLYPRU.mjs +22 -0
- package/dist/lib/neutral/chunk-S2DLYPRU.mjs.map +7 -0
- package/dist/lib/neutral/chunk-Y5TMPZGE.mjs +19 -0
- package/dist/lib/neutral/chunk-Y5TMPZGE.mjs.map +7 -0
- package/dist/lib/neutral/graph-RCKCHDM6.mjs +48 -0
- package/dist/lib/neutral/graph-RCKCHDM6.mjs.map +7 -0
- package/dist/lib/neutral/hooks/index.mjs +15 -0
- package/dist/lib/neutral/hooks/index.mjs.map +7 -0
- package/dist/lib/neutral/index.mjs +24 -0
- package/dist/lib/neutral/index.mjs.map +7 -0
- package/dist/lib/neutral/meta.json +1 -0
- package/dist/lib/neutral/meta.mjs +7 -0
- package/dist/lib/neutral/meta.mjs.map +7 -0
- package/dist/lib/neutral/plugin.mjs +11 -0
- package/dist/lib/neutral/plugin.mjs.map +7 -0
- package/dist/lib/neutral/testing.mjs +7 -0
- package/dist/lib/neutral/testing.mjs.map +7 -0
- package/dist/types/src/GraphPlugin.d.ts +3 -1
- package/dist/types/src/GraphPlugin.d.ts.map +1 -1
- package/dist/types/src/GraphPlugin.test.d.ts +2 -0
- package/dist/types/src/GraphPlugin.test.d.ts.map +1 -0
- package/dist/types/src/action.d.ts +12 -0
- package/dist/types/src/action.d.ts.map +1 -0
- package/dist/types/src/graph.d.ts +7 -3
- package/dist/types/src/graph.d.ts.map +1 -1
- package/dist/types/src/hooks/index.d.ts +1 -0
- package/dist/types/src/hooks/index.d.ts.map +1 -1
- package/dist/types/src/hooks/useActionRunner.d.ts +7 -0
- package/dist/types/src/hooks/useActionRunner.d.ts.map +1 -0
- package/dist/types/src/hooks/useNode.d.ts +19 -4
- package/dist/types/src/hooks/useNode.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +2 -2
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/meta.d.ts +2 -2
- package/dist/types/src/meta.d.ts.map +1 -1
- package/dist/types/src/plugin.d.ts +3 -0
- package/dist/types/src/plugin.d.ts.map +1 -0
- package/dist/types/src/testing.d.ts +2 -0
- package/dist/types/src/testing.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +58 -28
- package/src/GraphPlugin.test.ts +26 -0
- package/src/GraphPlugin.ts +15 -10
- package/src/action.ts +34 -0
- package/src/graph.ts +50 -34
- package/src/hooks/index.ts +1 -0
- package/src/hooks/useActionRunner.ts +25 -0
- package/src/hooks/useNode.ts +32 -6
- package/src/index.ts +5 -2
- package/src/meta.ts +5 -3
- package/src/plugin.ts +9 -0
- package/src/testing.ts +7 -0
- package/dist/lib/browser/graph-FFQ77VLS.mjs +0 -37
- package/dist/lib/browser/graph-FFQ77VLS.mjs.map +0 -7
- package/dist/lib/browser/index.mjs +0 -53
- package/dist/lib/browser/index.mjs.map +0 -7
- package/dist/lib/browser/meta.json +0 -1
- package/dist/lib/node-esm/graph-7GDCGF7M.mjs +0 -39
- package/dist/lib/node-esm/graph-7GDCGF7M.mjs.map +0 -7
- package/dist/lib/node-esm/index.mjs +0 -55
- package/dist/lib/node-esm/index.mjs.map +0 -7
- package/dist/lib/node-esm/meta.json +0 -1
package/package.json
CHANGED
|
@@ -1,55 +1,85 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/plugin-graph",
|
|
3
|
-
"version": "0.8.4-main.
|
|
3
|
+
"version": "0.8.4-main.effb148878",
|
|
4
4
|
"description": "DXOS Surface plugin for constructing knowledge graphs",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
7
|
-
"
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/dxos/dxos"
|
|
10
|
+
},
|
|
11
|
+
"license": "FSL-1.1-Apache-2.0",
|
|
8
12
|
"author": "DXOS.org",
|
|
9
13
|
"sideEffects": true,
|
|
10
14
|
"type": "module",
|
|
15
|
+
"imports": {
|
|
16
|
+
"#hooks": {
|
|
17
|
+
"source": "./src/hooks/index.ts",
|
|
18
|
+
"types": "./dist/types/src/hooks/index.d.ts",
|
|
19
|
+
"default": "./dist/lib/neutral/hooks/index.mjs"
|
|
20
|
+
},
|
|
21
|
+
"#meta": {
|
|
22
|
+
"source": "./src/meta.ts",
|
|
23
|
+
"types": "./dist/types/src/meta.d.ts",
|
|
24
|
+
"default": "./dist/lib/neutral/meta.mjs"
|
|
25
|
+
},
|
|
26
|
+
"#plugin": {
|
|
27
|
+
"source": "./src/GraphPlugin.ts",
|
|
28
|
+
"types": "./dist/types/src/GraphPlugin.d.ts",
|
|
29
|
+
"default": "./dist/lib/neutral/GraphPlugin.mjs"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
11
32
|
"exports": {
|
|
12
33
|
".": {
|
|
13
34
|
"source": "./src/index.ts",
|
|
14
35
|
"types": "./dist/types/src/index.d.ts",
|
|
15
|
-
"
|
|
16
|
-
|
|
36
|
+
"default": "./dist/lib/neutral/index.mjs"
|
|
37
|
+
},
|
|
38
|
+
"./plugin": {
|
|
39
|
+
"source": "./src/plugin.ts",
|
|
40
|
+
"types": "./dist/types/src/plugin.d.ts",
|
|
41
|
+
"default": "./dist/lib/neutral/plugin.mjs"
|
|
42
|
+
},
|
|
43
|
+
"./testing": {
|
|
44
|
+
"source": "./src/testing.ts",
|
|
45
|
+
"types": "./dist/types/src/testing.d.ts",
|
|
46
|
+
"default": "./dist/lib/neutral/testing.mjs"
|
|
17
47
|
}
|
|
18
48
|
},
|
|
19
49
|
"types": "dist/types/src/index.d.ts",
|
|
20
|
-
"typesVersions": {
|
|
21
|
-
"*": {}
|
|
22
|
-
},
|
|
23
50
|
"files": [
|
|
24
51
|
"dist",
|
|
25
52
|
"src"
|
|
26
53
|
],
|
|
27
54
|
"dependencies": {
|
|
28
|
-
"@
|
|
29
|
-
"@dxos/app-
|
|
30
|
-
"@dxos/
|
|
31
|
-
"@dxos/
|
|
32
|
-
"@dxos/
|
|
33
|
-
"@dxos/
|
|
55
|
+
"@dxos/app-framework": "0.8.4-main.effb148878",
|
|
56
|
+
"@dxos/app-toolkit": "0.8.4-main.effb148878",
|
|
57
|
+
"@dxos/compute": "0.8.4-main.effb148878",
|
|
58
|
+
"@dxos/debug": "0.8.4-main.effb148878",
|
|
59
|
+
"@dxos/effect": "0.8.4-main.effb148878",
|
|
60
|
+
"@dxos/operation": "0.8.4-main.effb148878",
|
|
61
|
+
"@dxos/util": "0.8.4-main.effb148878",
|
|
62
|
+
"@dxos/app-graph": "0.8.4-main.effb148878",
|
|
63
|
+
"@dxos/async": "0.8.4-main.effb148878"
|
|
34
64
|
},
|
|
35
65
|
"devDependencies": {
|
|
36
|
-
"@effect-atom/atom-react": "^0.
|
|
37
|
-
"@effect/platform": "0.
|
|
38
|
-
"@types/react": "~19.2.
|
|
39
|
-
"@types/react-dom": "~19.2.
|
|
40
|
-
"effect": "3.
|
|
41
|
-
"react": "~19.2.
|
|
42
|
-
"react-dom": "~19.2.
|
|
43
|
-
"vite": "
|
|
44
|
-
"@dxos/
|
|
45
|
-
"@dxos/
|
|
66
|
+
"@effect-atom/atom-react": "^0.5.0",
|
|
67
|
+
"@effect/platform": "0.94.4",
|
|
68
|
+
"@types/react": "~19.2.7",
|
|
69
|
+
"@types/react-dom": "~19.2.3",
|
|
70
|
+
"effect": "3.20.0",
|
|
71
|
+
"react": "~19.2.3",
|
|
72
|
+
"react-dom": "~19.2.3",
|
|
73
|
+
"vite": "^8.0.14",
|
|
74
|
+
"@dxos/storybook-utils": "0.8.4-main.effb148878",
|
|
75
|
+
"@dxos/react-client": "0.8.4-main.effb148878"
|
|
46
76
|
},
|
|
47
77
|
"peerDependencies": {
|
|
48
|
-
"@effect-atom/atom-react": "^0.
|
|
49
|
-
"@effect/platform": "
|
|
50
|
-
"effect": "
|
|
51
|
-
"react": "
|
|
52
|
-
"react-dom": "
|
|
78
|
+
"@effect-atom/atom-react": "^0.5.0",
|
|
79
|
+
"@effect/platform": "0.94.4",
|
|
80
|
+
"effect": "3.20.0",
|
|
81
|
+
"react": "~19.2.3",
|
|
82
|
+
"react-dom": "~19.2.3"
|
|
53
83
|
},
|
|
54
84
|
"publishConfig": {
|
|
55
85
|
"access": "public"
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2026 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { describe, test } from 'vitest';
|
|
6
|
+
|
|
7
|
+
import { ProcessManagerPlugin } from '@dxos/app-framework';
|
|
8
|
+
import { createTestApp } from '@dxos/app-framework/testing';
|
|
9
|
+
|
|
10
|
+
import { GraphPlugin } from '#plugin';
|
|
11
|
+
|
|
12
|
+
import { meta } from './meta';
|
|
13
|
+
|
|
14
|
+
const moduleId = (name: string) => `${meta.id}.module.${name}`;
|
|
15
|
+
|
|
16
|
+
describe('GraphPlugin', () => {
|
|
17
|
+
test('modules activate on the expected events', async ({ expect }) => {
|
|
18
|
+
// Use createTestApp directly — createComposerTestApp already includes GraphPlugin.
|
|
19
|
+
await using harness = await createTestApp({
|
|
20
|
+
plugins: [GraphPlugin(), ProcessManagerPlugin()],
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
// Graph activates on Startup; fires SetupAppGraph + SetupMetadata before, AppGraphReady after.
|
|
24
|
+
expect(harness.manager.getActive()).toContain(moduleId('Graph'));
|
|
25
|
+
});
|
|
26
|
+
});
|
package/src/GraphPlugin.ts
CHANGED
|
@@ -2,21 +2,26 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { ActivationEvents, Capability, Plugin } from '@dxos/app-framework';
|
|
6
|
+
import { AppActivationEvents } from '@dxos/app-toolkit';
|
|
6
7
|
|
|
7
|
-
import { meta } from '
|
|
8
|
+
import { meta } from '#meta';
|
|
9
|
+
|
|
10
|
+
const Graph = Capability.lazy('Graph', () => import('./graph'));
|
|
8
11
|
|
|
9
12
|
/**
|
|
10
13
|
* Manages the state of the graph for the application.
|
|
11
14
|
* Enables other plugins to register node builders to add nodes to the graph.
|
|
12
15
|
* This includes actions and annotation each other's nodes.
|
|
13
16
|
*/
|
|
14
|
-
export const GraphPlugin =
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
activate: lazy(() => import('./graph')),
|
|
17
|
+
export const GraphPlugin = Plugin.define(meta).pipe(
|
|
18
|
+
Plugin.addModule({
|
|
19
|
+
activatesOn: ActivationEvents.Startup,
|
|
20
|
+
firesBeforeActivation: [AppActivationEvents.SetupAppGraph],
|
|
21
|
+
firesAfterActivation: [AppActivationEvents.AppGraphReady],
|
|
22
|
+
activate: Graph,
|
|
21
23
|
}),
|
|
22
|
-
|
|
24
|
+
Plugin.make,
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
export default GraphPlugin;
|
package/src/action.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Effect from 'effect/Effect';
|
|
6
|
+
import * as Function from 'effect/Function';
|
|
7
|
+
|
|
8
|
+
import { Capability, type CapabilityManager } from '@dxos/app-framework';
|
|
9
|
+
import { type Node } from '@dxos/app-graph';
|
|
10
|
+
import { Operation } from '@dxos/compute';
|
|
11
|
+
import { runAndForwardErrors } from '@dxos/effect';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Run an action with required layers: Operation.Service, Capability.Service, and captured context.
|
|
15
|
+
* @param invoker The operation invoker to use for Operation.Service.
|
|
16
|
+
* @param capabilityManager The capability manager for Capability.Service.
|
|
17
|
+
* @param action The action to execute.
|
|
18
|
+
* @param params Parameters to pass to the action.
|
|
19
|
+
*/
|
|
20
|
+
export const runAction = async (
|
|
21
|
+
invoker: Operation.OperationService,
|
|
22
|
+
capabilityManager: CapabilityManager.CapabilityManager,
|
|
23
|
+
action: Node.Action,
|
|
24
|
+
params: Node.InvokeProps = {},
|
|
25
|
+
): Promise<void> =>
|
|
26
|
+
runAndForwardErrors(
|
|
27
|
+
action
|
|
28
|
+
.data(params)
|
|
29
|
+
.pipe(
|
|
30
|
+
Effect.provideService(Operation.Service, invoker),
|
|
31
|
+
Effect.provideService(Capability.Service, capabilityManager),
|
|
32
|
+
action._actionContext ? Effect.provide(action._actionContext) : Function.identity,
|
|
33
|
+
),
|
|
34
|
+
);
|
package/src/graph.ts
CHANGED
|
@@ -2,48 +2,64 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import * as Effect from 'effect/Effect';
|
|
5
6
|
import * as Record from 'effect/Record';
|
|
6
7
|
|
|
7
|
-
import { Capabilities,
|
|
8
|
-
import {
|
|
8
|
+
import { Capabilities, Capability } from '@dxos/app-framework';
|
|
9
|
+
import { Graph, GraphBuilder, Node } from '@dxos/app-graph';
|
|
10
|
+
import { AppCapabilities } from '@dxos/app-toolkit';
|
|
9
11
|
|
|
10
12
|
// TODO(wittjosiah): Remove or restore graph caching.
|
|
11
13
|
// import { meta } from './meta';
|
|
12
14
|
|
|
13
|
-
// const KEY = `${meta.id}
|
|
14
|
-
|
|
15
|
-
export default
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
15
|
+
// const KEY = `${meta.id}.app-graph`;
|
|
16
|
+
|
|
17
|
+
export default Capability.makeModule(
|
|
18
|
+
Effect.fnUntraced(function* () {
|
|
19
|
+
const registry = yield* Capability.get(Capabilities.AtomRegistry);
|
|
20
|
+
const extensionsByModuleAtom = yield* Capability.atomByModule(AppCapabilities.AppGraphBuilder);
|
|
21
|
+
|
|
22
|
+
const builder = GraphBuilder.from(/* localStorage.getItem(KEY) ?? */ undefined, registry);
|
|
23
|
+
// const interval = setInterval(() => {
|
|
24
|
+
// localStorage.setItem(KEY, builder.graph.pickle());
|
|
25
|
+
// }, 5_000);
|
|
26
|
+
|
|
27
|
+
const unsubscribe = registry.subscribe(
|
|
28
|
+
extensionsByModuleAtom,
|
|
29
|
+
(extensionsByModule) => {
|
|
30
|
+
const next: GraphBuilder.BuilderExtension[] = [];
|
|
31
|
+
for (const [moduleId, extensions] of Object.entries(extensionsByModule)) {
|
|
32
|
+
for (const ext of GraphBuilder.flattenExtensions(extensions)) {
|
|
33
|
+
next.push({ ...ext, id: `${moduleId}.${ext.id}` });
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
const current = Record.values(registry.get(builder.extensions));
|
|
37
|
+
const removed = current.filter(({ id }) => !next.some(({ id: nextId }) => nextId === id));
|
|
38
|
+
removed.forEach((extension) => GraphBuilder.removeExtension(builder, extension.id));
|
|
39
|
+
next.forEach((extension) => GraphBuilder.addExtension(builder, extension));
|
|
40
|
+
},
|
|
41
|
+
{ immediate: true },
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
// await builder.initialize();
|
|
45
|
+
void Graph.expand(builder.graph, Node.RootId, 'child');
|
|
46
|
+
|
|
47
|
+
setupDevtools(builder.graph);
|
|
48
|
+
|
|
49
|
+
return Capability.contributes(
|
|
50
|
+
AppCapabilities.AppGraph,
|
|
51
|
+
{ graph: builder.graph, explore: GraphBuilder.explore },
|
|
52
|
+
() =>
|
|
53
|
+
Effect.sync(() => {
|
|
54
|
+
// clearInterval(interval);
|
|
55
|
+
unsubscribe();
|
|
56
|
+
}),
|
|
57
|
+
);
|
|
58
|
+
}),
|
|
59
|
+
);
|
|
44
60
|
|
|
45
61
|
// Expose the graph to the window for debugging.
|
|
46
|
-
const setupDevtools = (graph: ExpandableGraph) => {
|
|
62
|
+
const setupDevtools = (graph: Graph.ExpandableGraph) => {
|
|
47
63
|
(globalThis as any).composer ??= {};
|
|
48
64
|
(globalThis as any).composer.graph = graph;
|
|
49
65
|
};
|
package/src/hooks/index.ts
CHANGED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { useCallback } from 'react';
|
|
6
|
+
|
|
7
|
+
import { useOperationInvoker, usePluginManager } from '@dxos/app-framework/ui';
|
|
8
|
+
import { type Node } from '@dxos/app-graph';
|
|
9
|
+
|
|
10
|
+
import { runAction } from '../action';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Hook that returns a function to run action Effects.
|
|
14
|
+
* Provides Operation.Service, PluginContextService, and captured plugin context.
|
|
15
|
+
*/
|
|
16
|
+
export const useActionRunner = () => {
|
|
17
|
+
const invoker = useOperationInvoker();
|
|
18
|
+
const pluginManager = usePluginManager();
|
|
19
|
+
|
|
20
|
+
return useCallback(
|
|
21
|
+
(action: Node.Action, params: Node.InvokeProps = {}) =>
|
|
22
|
+
runAction(invoker, pluginManager.capabilities, action, params),
|
|
23
|
+
[invoker, pluginManager.capabilities],
|
|
24
|
+
);
|
|
25
|
+
};
|
package/src/hooks/useNode.ts
CHANGED
|
@@ -4,8 +4,9 @@
|
|
|
4
4
|
|
|
5
5
|
import { useAtomValue } from '@effect-atom/atom-react';
|
|
6
6
|
import * as Option from 'effect/Option';
|
|
7
|
+
import { useMemo } from 'react';
|
|
7
8
|
|
|
8
|
-
import { type
|
|
9
|
+
import { type Graph, type Node } from '@dxos/app-graph';
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* React hook to get a node from the graph.
|
|
@@ -16,14 +17,39 @@ import { type Node, type ReadableGraph, type Relation } from '@dxos/app-graph';
|
|
|
16
17
|
* @returns Node if found, undefined otherwise.
|
|
17
18
|
*/
|
|
18
19
|
// TODO(wittjosiah): Factor out to @dxos/app-graph/react.
|
|
19
|
-
export const useNode = <T = any>(graph: ReadableGraph, id?: string): Node<T> | undefined => {
|
|
20
|
-
|
|
20
|
+
export const useNode = <T = any>(graph: Graph.ReadableGraph, id?: string): Node.Node<T> | undefined => {
|
|
21
|
+
const atom = useMemo(() => graph.node(id ?? ''), [graph, id]);
|
|
22
|
+
return Option.getOrElse(useAtomValue(atom), () => undefined);
|
|
21
23
|
};
|
|
22
24
|
|
|
23
|
-
export const useConnections = (
|
|
25
|
+
export const useConnections = (
|
|
26
|
+
graph: Graph.ReadableGraph,
|
|
27
|
+
id: string | undefined,
|
|
28
|
+
relation: Node.RelationInput,
|
|
29
|
+
): Node.Node[] => {
|
|
24
30
|
return useAtomValue(graph.connections(id ?? '', relation));
|
|
25
31
|
};
|
|
26
32
|
|
|
27
|
-
|
|
28
|
-
|
|
33
|
+
/**
|
|
34
|
+
* React hook to get actions available for a node.
|
|
35
|
+
*
|
|
36
|
+
* @param graph Graph containing the node.
|
|
37
|
+
* @param id Id of the node.
|
|
38
|
+
* @returns Actions available for the node.
|
|
39
|
+
*/
|
|
40
|
+
export const useActions = (graph: Graph.ReadableGraph, id?: string): Node.Node[] => {
|
|
41
|
+
const atom = useMemo(() => graph.actions(id ?? ''), [graph, id]);
|
|
42
|
+
return useAtomValue(atom);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Subscribe to just the edge topology (inbound/outbound IDs) of a node without subscribing to node content.
|
|
47
|
+
*
|
|
48
|
+
* @param graph Graph containing the node.
|
|
49
|
+
* @param id Id of the node.
|
|
50
|
+
* @returns Edge topology for the node.
|
|
51
|
+
*/
|
|
52
|
+
export const useEdges = (graph: Graph.ReadableGraph, id?: string): Graph.Edges => {
|
|
53
|
+
const atom = useMemo(() => graph.edges(id ?? ''), [graph, id]);
|
|
54
|
+
return useAtomValue(atom);
|
|
29
55
|
};
|
package/src/index.ts
CHANGED
|
@@ -2,8 +2,11 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
export * from './meta';
|
|
6
|
+
|
|
5
7
|
export * from '@dxos/app-graph';
|
|
6
8
|
|
|
7
|
-
export * from './
|
|
9
|
+
export * from './action';
|
|
10
|
+
// TODO(wittjosiah): Hooks should not be exported from the plugin package at all.
|
|
11
|
+
// Either refactor callers to not need them or factor them out to a shared package.
|
|
8
12
|
export * from './hooks';
|
|
9
|
-
export * from './meta';
|
package/src/meta.ts
CHANGED
|
@@ -2,14 +2,16 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { type
|
|
5
|
+
import { type Plugin } from '@dxos/app-framework';
|
|
6
6
|
import { trim } from '@dxos/util';
|
|
7
7
|
|
|
8
|
-
export const meta:
|
|
9
|
-
id: 'dxos.
|
|
8
|
+
export const meta: Plugin.Meta = {
|
|
9
|
+
id: 'org.dxos.plugin.graph',
|
|
10
10
|
name: 'Graph',
|
|
11
|
+
author: 'DXOS',
|
|
11
12
|
description: trim`
|
|
12
13
|
Graph database layer providing relationship modeling and queries for workspace objects.
|
|
13
14
|
Build knowledge graphs and explore complex data relationships.
|
|
14
15
|
`,
|
|
16
|
+
tags: ['system'],
|
|
15
17
|
};
|
package/src/plugin.ts
ADDED
package/src/testing.ts
ADDED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
// src/graph.ts
|
|
2
|
-
import * as Record from "effect/Record";
|
|
3
|
-
import { Capabilities, contributes } from "@dxos/app-framework";
|
|
4
|
-
import { GraphBuilder, ROOT_ID, flattenExtensions } from "@dxos/app-graph";
|
|
5
|
-
var graph_default = (async (context) => {
|
|
6
|
-
const registry = context.getCapability(Capabilities.AtomRegistry);
|
|
7
|
-
const builder = GraphBuilder.from(
|
|
8
|
-
/* localStorage.getItem(KEY) ?? */
|
|
9
|
-
void 0,
|
|
10
|
-
registry
|
|
11
|
-
);
|
|
12
|
-
const unsubscribe = registry.subscribe(context.capabilities(Capabilities.AppGraphBuilder), (extensions) => {
|
|
13
|
-
const next = flattenExtensions(extensions);
|
|
14
|
-
const current = Record.values(registry.get(builder.extensions));
|
|
15
|
-
const removed = current.filter(({ id }) => !next.some(({ id: nextId }) => nextId === id));
|
|
16
|
-
removed.forEach((extension) => builder.removeExtension(extension.id));
|
|
17
|
-
next.forEach((extension) => builder.addExtension(extension));
|
|
18
|
-
}, {
|
|
19
|
-
immediate: true
|
|
20
|
-
});
|
|
21
|
-
void builder.graph.expand(ROOT_ID);
|
|
22
|
-
setupDevtools(builder.graph);
|
|
23
|
-
return contributes(Capabilities.AppGraph, {
|
|
24
|
-
graph: builder.graph,
|
|
25
|
-
explore: builder.explore
|
|
26
|
-
}, () => {
|
|
27
|
-
unsubscribe();
|
|
28
|
-
});
|
|
29
|
-
});
|
|
30
|
-
var setupDevtools = (graph) => {
|
|
31
|
-
globalThis.composer ??= {};
|
|
32
|
-
globalThis.composer.graph = graph;
|
|
33
|
-
};
|
|
34
|
-
export {
|
|
35
|
-
graph_default as default
|
|
36
|
-
};
|
|
37
|
-
//# sourceMappingURL=graph-FFQ77VLS.mjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/graph.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Record from 'effect/Record';\n\nimport { Capabilities, type PluginContext, contributes } from '@dxos/app-framework';\nimport { type ExpandableGraph, GraphBuilder, ROOT_ID, flattenExtensions } from '@dxos/app-graph';\n\n// TODO(wittjosiah): Remove or restore graph caching.\n// import { meta } from './meta';\n\n// const KEY = `${meta.id}/app-graph`;\n\nexport default async (context: PluginContext) => {\n const registry = context.getCapability(Capabilities.AtomRegistry);\n const builder = GraphBuilder.from(/* localStorage.getItem(KEY) ?? */ undefined, registry);\n // const interval = setInterval(() => {\n // localStorage.setItem(KEY, builder.graph.pickle());\n // }, 5_000);\n\n const unsubscribe = registry.subscribe(\n context.capabilities(Capabilities.AppGraphBuilder),\n (extensions) => {\n const next = flattenExtensions(extensions);\n const current = Record.values(registry.get(builder.extensions));\n const removed = current.filter(({ id }) => !next.some(({ id: nextId }) => nextId === id));\n removed.forEach((extension) => builder.removeExtension(extension.id));\n next.forEach((extension) => builder.addExtension(extension));\n },\n { immediate: true },\n );\n\n // await builder.initialize();\n void builder.graph.expand(ROOT_ID);\n\n setupDevtools(builder.graph);\n\n return contributes(Capabilities.AppGraph, { graph: builder.graph, explore: builder.explore }, () => {\n // clearInterval(interval);\n unsubscribe();\n });\n};\n\n// Expose the graph to the window for debugging.\nconst setupDevtools = (graph: ExpandableGraph) => {\n (globalThis as any).composer ??= {};\n (globalThis as any).composer.graph = graph;\n};\n"],
|
|
5
|
-
"mappings": ";AAIA,YAAYA,YAAY;AAExB,SAASC,cAAkCC,mBAAmB;AAC9D,SAA+BC,cAAcC,SAASC,yBAAyB;AAO/E,IAAA,iBAAe,OAAOC,YAAAA;AACpB,QAAMC,WAAWD,QAAQE,cAAcC,aAAaC,YAAY;AAChE,QAAMC,UAAUC,aAAaC;;IAAwCC;IAAWP;EAAAA;AAKhF,QAAMQ,cAAcR,SAASS,UAC3BV,QAAQW,aAAaR,aAAaS,eAAe,GACjD,CAACC,eAAAA;AACC,UAAMC,OAAOC,kBAAkBF,UAAAA;AAC/B,UAAMG,UAAiBC,cAAOhB,SAASiB,IAAIb,QAAQQ,UAAU,CAAA;AAC7D,UAAMM,UAAUH,QAAQI,OAAO,CAAC,EAAEC,GAAE,MAAO,CAACP,KAAKQ,KAAK,CAAC,EAAED,IAAIE,OAAM,MAAOA,WAAWF,EAAAA,CAAAA;AACrFF,YAAQK,QAAQ,CAACC,cAAcpB,QAAQqB,gBAAgBD,UAAUJ,EAAE,CAAA;AACnEP,SAAKU,QAAQ,CAACC,cAAcpB,QAAQsB,aAAaF,SAAAA,CAAAA;EACnD,GACA;IAAEG,WAAW;EAAK,CAAA;AAIpB,OAAKvB,QAAQwB,MAAMC,OAAOC,OAAAA;AAE1BC,gBAAc3B,QAAQwB,KAAK;AAE3B,SAAOI,YAAY9B,aAAa+B,UAAU;IAAEL,OAAOxB,QAAQwB;IAAOM,SAAS9B,QAAQ8B;EAAQ,GAAG,MAAA;AAE5F1B,gBAAAA;EACF,CAAA;AACF;AAGA,IAAMuB,gBAAgB,CAACH,UAAAA;AACpBO,aAAmBC,aAAa,CAAC;AACjCD,aAAmBC,SAASR,QAAQA;AACvC;",
|
|
6
|
-
"names": ["Record", "Capabilities", "contributes", "GraphBuilder", "ROOT_ID", "flattenExtensions", "context", "registry", "getCapability", "Capabilities", "AtomRegistry", "builder", "GraphBuilder", "from", "undefined", "unsubscribe", "subscribe", "capabilities", "AppGraphBuilder", "extensions", "next", "flattenExtensions", "current", "values", "get", "removed", "filter", "id", "some", "nextId", "forEach", "extension", "removeExtension", "addExtension", "immediate", "graph", "expand", "ROOT_ID", "setupDevtools", "contributes", "AppGraph", "explore", "globalThis", "composer"]
|
|
7
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
// src/index.ts
|
|
2
|
-
export * from "@dxos/app-graph";
|
|
3
|
-
|
|
4
|
-
// src/GraphPlugin.ts
|
|
5
|
-
import { Events, defineModule, definePlugin, lazy } from "@dxos/app-framework";
|
|
6
|
-
|
|
7
|
-
// src/meta.ts
|
|
8
|
-
import { trim } from "@dxos/util";
|
|
9
|
-
var meta = {
|
|
10
|
-
id: "dxos.org/plugin/graph",
|
|
11
|
-
name: "Graph",
|
|
12
|
-
description: trim`
|
|
13
|
-
Graph database layer providing relationship modeling and queries for workspace objects.
|
|
14
|
-
Build knowledge graphs and explore complex data relationships.
|
|
15
|
-
`
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
// src/GraphPlugin.ts
|
|
19
|
-
var GraphPlugin = definePlugin(meta, () => [
|
|
20
|
-
defineModule({
|
|
21
|
-
id: `${meta.id}/module/graph`,
|
|
22
|
-
activatesOn: Events.Startup,
|
|
23
|
-
activatesBefore: [
|
|
24
|
-
Events.SetupAppGraph,
|
|
25
|
-
Events.SetupMetadata
|
|
26
|
-
],
|
|
27
|
-
activatesAfter: [
|
|
28
|
-
Events.AppGraphReady
|
|
29
|
-
],
|
|
30
|
-
activate: lazy(() => import("./graph-FFQ77VLS.mjs"))
|
|
31
|
-
})
|
|
32
|
-
]);
|
|
33
|
-
|
|
34
|
-
// src/hooks/useNode.ts
|
|
35
|
-
import { useAtomValue } from "@effect-atom/atom-react";
|
|
36
|
-
import * as Option from "effect/Option";
|
|
37
|
-
var useNode = (graph, id) => {
|
|
38
|
-
return Option.getOrElse(useAtomValue(graph.node(id ?? "")), () => void 0);
|
|
39
|
-
};
|
|
40
|
-
var useConnections = (graph, id, relation) => {
|
|
41
|
-
return useAtomValue(graph.connections(id ?? "", relation));
|
|
42
|
-
};
|
|
43
|
-
var useActions = (graph, id) => {
|
|
44
|
-
return useAtomValue(graph.actions(id ?? ""));
|
|
45
|
-
};
|
|
46
|
-
export {
|
|
47
|
-
GraphPlugin,
|
|
48
|
-
meta,
|
|
49
|
-
useActions,
|
|
50
|
-
useConnections,
|
|
51
|
-
useNode
|
|
52
|
-
};
|
|
53
|
-
//# sourceMappingURL=index.mjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/index.ts", "../../../src/GraphPlugin.ts", "../../../src/meta.ts", "../../../src/hooks/useNode.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nexport * from '@dxos/app-graph';\n\nexport * from './GraphPlugin';\nexport * from './hooks';\nexport * from './meta';\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { Events, defineModule, definePlugin, lazy } from '@dxos/app-framework';\n\nimport { meta } from './meta';\n\n/**\n * Manages the state of the graph for the application.\n * Enables other plugins to register node builders to add nodes to the graph.\n * This includes actions and annotation each other's nodes.\n */\nexport const GraphPlugin = definePlugin(meta, () => [\n defineModule({\n id: `${meta.id}/module/graph`,\n activatesOn: Events.Startup,\n activatesBefore: [Events.SetupAppGraph, Events.SetupMetadata],\n activatesAfter: [Events.AppGraphReady],\n activate: lazy(() => import('./graph')),\n }),\n]);\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { type PluginMeta } from '@dxos/app-framework';\nimport { trim } from '@dxos/util';\n\nexport const meta: PluginMeta = {\n id: 'dxos.org/plugin/graph',\n name: 'Graph',\n description: trim`\n Graph database layer providing relationship modeling and queries for workspace objects.\n Build knowledge graphs and explore complex data relationships.\n `,\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { useAtomValue } from '@effect-atom/atom-react';\nimport * as Option from 'effect/Option';\n\nimport { type Node, type ReadableGraph, type Relation } from '@dxos/app-graph';\n\n/**\n * React hook to get a node from the graph.\n *\n * @param graph Graph to find the node in.\n * @param id Id of the node to find.\n * @param timeout Optional timeout in milliseconds to wait for the node to be found.\n * @returns Node if found, undefined otherwise.\n */\n// TODO(wittjosiah): Factor out to @dxos/app-graph/react.\nexport const useNode = <T = any>(graph: ReadableGraph, id?: string): Node<T> | undefined => {\n return Option.getOrElse(useAtomValue(graph.node(id ?? '')), () => undefined);\n};\n\nexport const useConnections = (graph: ReadableGraph, id?: string, relation?: Relation): Node[] => {\n return useAtomValue(graph.connections(id ?? '', relation));\n};\n\nexport const useActions = (graph: ReadableGraph, id?: string): Node[] => {\n return useAtomValue(graph.actions(id ?? ''));\n};\n"],
|
|
5
|
-
"mappings": ";AAIA,cAAc;;;ACAd,SAASA,QAAQC,cAAcC,cAAcC,YAAY;;;ACCzD,SAASC,YAAY;AAEd,IAAMC,OAAmB;EAC9BC,IAAI;EACJC,MAAM;EACNC,aAAaC;;;;AAIf;;;ADDO,IAAMC,cAAcC,aAAaC,MAAM,MAAM;EAClDC,aAAa;IACXC,IAAI,GAAGF,KAAKE,EAAE;IACdC,aAAaC,OAAOC;IACpBC,iBAAiB;MAACF,OAAOG;MAAeH,OAAOI;;IAC/CC,gBAAgB;MAACL,OAAOM;;IACxBC,UAAUC,KAAK,MAAM,OAAO,sBAAA,CAAA;EAC9B,CAAA;CACD;;;AEjBD,SAASC,oBAAoB;AAC7B,YAAYC,YAAY;AAajB,IAAMC,UAAU,CAAUC,OAAsBC,OAAAA;AACrD,SAAcC,iBAAUC,aAAaH,MAAMI,KAAKH,MAAM,EAAA,CAAA,GAAM,MAAMI,MAAAA;AACpE;AAEO,IAAMC,iBAAiB,CAACN,OAAsBC,IAAaM,aAAAA;AAChE,SAAOJ,aAAaH,MAAMQ,YAAYP,MAAM,IAAIM,QAAAA,CAAAA;AAClD;AAEO,IAAME,aAAa,CAACT,OAAsBC,OAAAA;AAC/C,SAAOE,aAAaH,MAAMU,QAAQT,MAAM,EAAA,CAAA;AAC1C;",
|
|
6
|
-
"names": ["Events", "defineModule", "definePlugin", "lazy", "trim", "meta", "id", "name", "description", "trim", "GraphPlugin", "definePlugin", "meta", "defineModule", "id", "activatesOn", "Events", "Startup", "activatesBefore", "SetupAppGraph", "SetupMetadata", "activatesAfter", "AppGraphReady", "activate", "lazy", "useAtomValue", "Option", "useNode", "graph", "id", "getOrElse", "useAtomValue", "node", "undefined", "useConnections", "relation", "connections", "useActions", "actions"]
|
|
7
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"inputs":{"src/meta.ts":{"bytes":1369,"imports":[{"path":"@dxos/util","kind":"import-statement","external":true}],"format":"esm"},"src/graph.ts":{"bytes":6297,"imports":[{"path":"effect/Record","kind":"import-statement","external":true},{"path":"@dxos/app-framework","kind":"import-statement","external":true},{"path":"@dxos/app-graph","kind":"import-statement","external":true}],"format":"esm"},"src/GraphPlugin.ts":{"bytes":2709,"imports":[{"path":"@dxos/app-framework","kind":"import-statement","external":true},{"path":"src/meta.ts","kind":"import-statement","original":"./meta"},{"path":"src/graph.ts","kind":"dynamic-import","original":"./graph"}],"format":"esm"},"src/hooks/useNode.ts":{"bytes":3168,"imports":[{"path":"@effect-atom/atom-react","kind":"import-statement","external":true},{"path":"effect/Option","kind":"import-statement","external":true}],"format":"esm"},"src/hooks/index.ts":{"bytes":461,"imports":[{"path":"src/hooks/useNode.ts","kind":"import-statement","original":"./useNode"}],"format":"esm"},"src/index.ts":{"bytes":733,"imports":[{"path":"@dxos/app-graph","kind":"import-statement","external":true},{"path":"src/GraphPlugin.ts","kind":"import-statement","original":"./GraphPlugin"},{"path":"src/hooks/index.ts","kind":"import-statement","original":"./hooks"},{"path":"src/meta.ts","kind":"import-statement","original":"./meta"}],"format":"esm"}},"outputs":{"dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":3653},"dist/lib/browser/index.mjs":{"imports":[{"path":"@dxos/app-graph","kind":"import-statement","external":true},{"path":"@dxos/app-framework","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"dist/lib/browser/graph-FFQ77VLS.mjs","kind":"dynamic-import"},{"path":"@effect-atom/atom-react","kind":"import-statement","external":true},{"path":"effect/Option","kind":"import-statement","external":true}],"exports":["GraphPlugin","meta","useActions","useConnections","useNode"],"entryPoint":"src/index.ts","inputs":{"src/index.ts":{"bytesInOutput":33},"src/GraphPlugin.ts":{"bytesInOutput":417},"src/meta.ts":{"bytesInOutput":283},"src/hooks/useNode.ts":{"bytesInOutput":406},"src/hooks/index.ts":{"bytesInOutput":0}},"bytes":1354},"dist/lib/browser/graph-FFQ77VLS.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":3313},"dist/lib/browser/graph-FFQ77VLS.mjs":{"imports":[{"path":"effect/Record","kind":"import-statement","external":true},{"path":"@dxos/app-framework","kind":"import-statement","external":true},{"path":"@dxos/app-graph","kind":"import-statement","external":true}],"exports":["default"],"entryPoint":"src/graph.ts","inputs":{"src/graph.ts":{"bytesInOutput":1212}},"bytes":1311}}}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
|
|
2
|
-
|
|
3
|
-
// src/graph.ts
|
|
4
|
-
import * as Record from "effect/Record";
|
|
5
|
-
import { Capabilities, contributes } from "@dxos/app-framework";
|
|
6
|
-
import { GraphBuilder, ROOT_ID, flattenExtensions } from "@dxos/app-graph";
|
|
7
|
-
var graph_default = (async (context) => {
|
|
8
|
-
const registry = context.getCapability(Capabilities.AtomRegistry);
|
|
9
|
-
const builder = GraphBuilder.from(
|
|
10
|
-
/* localStorage.getItem(KEY) ?? */
|
|
11
|
-
void 0,
|
|
12
|
-
registry
|
|
13
|
-
);
|
|
14
|
-
const unsubscribe = registry.subscribe(context.capabilities(Capabilities.AppGraphBuilder), (extensions) => {
|
|
15
|
-
const next = flattenExtensions(extensions);
|
|
16
|
-
const current = Record.values(registry.get(builder.extensions));
|
|
17
|
-
const removed = current.filter(({ id }) => !next.some(({ id: nextId }) => nextId === id));
|
|
18
|
-
removed.forEach((extension) => builder.removeExtension(extension.id));
|
|
19
|
-
next.forEach((extension) => builder.addExtension(extension));
|
|
20
|
-
}, {
|
|
21
|
-
immediate: true
|
|
22
|
-
});
|
|
23
|
-
void builder.graph.expand(ROOT_ID);
|
|
24
|
-
setupDevtools(builder.graph);
|
|
25
|
-
return contributes(Capabilities.AppGraph, {
|
|
26
|
-
graph: builder.graph,
|
|
27
|
-
explore: builder.explore
|
|
28
|
-
}, () => {
|
|
29
|
-
unsubscribe();
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
var setupDevtools = (graph) => {
|
|
33
|
-
globalThis.composer ??= {};
|
|
34
|
-
globalThis.composer.graph = graph;
|
|
35
|
-
};
|
|
36
|
-
export {
|
|
37
|
-
graph_default as default
|
|
38
|
-
};
|
|
39
|
-
//# sourceMappingURL=graph-7GDCGF7M.mjs.map
|