@dxos/app-graph 0.8.4-main.5ad4a44 → 0.8.4-main.66e292d
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/index.mjs +201 -223
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +201 -223
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/graph-builder.d.ts +15 -15
- package/dist/types/src/graph-builder.d.ts.map +1 -1
- package/dist/types/src/graph.d.ts +18 -18
- package/dist/types/src/graph.d.ts.map +1 -1
- package/dist/types/src/node.d.ts +1 -1
- 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.d.ts +3 -4
- package/dist/types/src/testing.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +22 -22
- package/src/graph-builder.test.ts +26 -26
- package/src/graph-builder.ts +44 -42
- package/src/graph.test.ts +2 -2
- package/src/graph.ts +111 -71
- package/src/node.ts +1 -1
- package/src/signals-integration.test.ts +32 -27
- package/src/stories/EchoGraph.stories.tsx +32 -33
- package/src/stories/Tree.tsx +1 -1
- package/src/testing.ts +6 -5
- package/dist/types/src/experimental/graph-projections.test.d.ts +0 -25
- package/dist/types/src/experimental/graph-projections.test.d.ts.map +0 -1
- package/src/experimental/graph-projections.test.ts +0 -56
|
@@ -2,24 +2,15 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { type Registry, RegistryContext,
|
|
5
|
+
import { Atom, type Registry, RegistryContext, useAtomValue } from '@effect-atom/atom-react';
|
|
6
6
|
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
7
7
|
import * as Function from 'effect/Function';
|
|
8
8
|
import * as Option from 'effect/Option';
|
|
9
|
+
import type * as Schema from 'effect/Schema';
|
|
9
10
|
import React, { type PropsWithChildren, useCallback, useContext, useEffect, useMemo, useState } from 'react';
|
|
10
11
|
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
Filter,
|
|
14
|
-
type Live,
|
|
15
|
-
Query,
|
|
16
|
-
type QueryResult,
|
|
17
|
-
type Space,
|
|
18
|
-
SpaceState,
|
|
19
|
-
isSpace,
|
|
20
|
-
live,
|
|
21
|
-
} from '@dxos/client/echo';
|
|
22
|
-
import { Obj, Type } from '@dxos/echo';
|
|
12
|
+
import { Filter, type Live, Query, type Space, SpaceState, isSpace, live } from '@dxos/client/echo';
|
|
13
|
+
import { type Database, Obj, Type } from '@dxos/echo';
|
|
23
14
|
import { faker } from '@dxos/random';
|
|
24
15
|
import { type Client, useClient } from '@dxos/react-client';
|
|
25
16
|
import { withClientProvider } from '@dxos/react-client/testing';
|
|
@@ -30,9 +21,9 @@ import { getSize, mx } from '@dxos/react-ui-theme';
|
|
|
30
21
|
import { byPosition, isNonNullable, safeParseInt } from '@dxos/util';
|
|
31
22
|
|
|
32
23
|
import { type ExpandableGraph, ROOT_ID } from '../graph';
|
|
33
|
-
import { GraphBuilder,
|
|
24
|
+
import { GraphBuilder, atomFromObservable, atomFromSignal, createExtension } from '../graph-builder';
|
|
34
25
|
import { type Node } from '../node';
|
|
35
|
-
import {
|
|
26
|
+
import { atomFromQuery } from '../testing';
|
|
36
27
|
|
|
37
28
|
import { JsonTree } from './Tree';
|
|
38
29
|
|
|
@@ -60,18 +51,20 @@ const createGraph = (client: Client, registry: Registry.Registry): ExpandableGra
|
|
|
60
51
|
const spaceBuilderExtension = createExtension({
|
|
61
52
|
id: 'space',
|
|
62
53
|
connector: (node) =>
|
|
63
|
-
|
|
54
|
+
Atom.make((get) =>
|
|
64
55
|
Function.pipe(
|
|
65
56
|
get(node),
|
|
66
57
|
Option.flatMap((node) => (node.id === ROOT_ID ? Option.some(node) : Option.none())),
|
|
67
58
|
Option.map(() => {
|
|
68
|
-
const spaces = get(
|
|
59
|
+
const spaces = get(atomFromObservable(client.spaces)) ?? [];
|
|
69
60
|
return spaces
|
|
70
|
-
.filter((space) => get(
|
|
61
|
+
.filter((space) => get(atomFromObservable(space.state)) === SpaceState.SPACE_READY)
|
|
71
62
|
.map((space) => ({
|
|
72
63
|
id: space.id,
|
|
73
64
|
type: 'dxos.org/type/Space',
|
|
74
|
-
properties: {
|
|
65
|
+
properties: {
|
|
66
|
+
label: get(atomFromSignal(() => space.properties.name)),
|
|
67
|
+
},
|
|
75
68
|
data: space,
|
|
76
69
|
}));
|
|
77
70
|
}),
|
|
@@ -83,16 +76,18 @@ const createGraph = (client: Client, registry: Registry.Registry): ExpandableGra
|
|
|
83
76
|
const objectBuilderExtension = createExtension({
|
|
84
77
|
id: 'object',
|
|
85
78
|
connector: (node) => {
|
|
86
|
-
|
|
87
|
-
|
|
79
|
+
// TODO(wittjosiah): Find a simpler way to define this type.
|
|
80
|
+
let result: Database.QueryResult<Schema.Schema.Type<typeof Type.Expando>> | undefined;
|
|
81
|
+
return Atom.make((get) =>
|
|
88
82
|
Function.pipe(
|
|
89
83
|
get(node),
|
|
90
84
|
Option.flatMap((node) => (isSpace(node.data) ? Option.some(node.data) : Option.none())),
|
|
91
85
|
Option.map((space) => {
|
|
92
|
-
if (!
|
|
93
|
-
|
|
86
|
+
if (!result) {
|
|
87
|
+
result = space.db.query(Query.type(Type.Expando, { type: 'test' }));
|
|
94
88
|
}
|
|
95
|
-
|
|
89
|
+
|
|
90
|
+
const objects = get(atomFromQuery(result));
|
|
96
91
|
return objects.map((object) => ({
|
|
97
92
|
id: object.id,
|
|
98
93
|
type: 'dxos.org/type/test',
|
|
@@ -114,7 +109,6 @@ const createGraph = (client: Client, registry: Registry.Registry): ExpandableGra
|
|
|
114
109
|
});
|
|
115
110
|
graph.expand(ROOT_ID);
|
|
116
111
|
(window as any).graph = graph;
|
|
117
|
-
|
|
118
112
|
return graph;
|
|
119
113
|
};
|
|
120
114
|
|
|
@@ -134,7 +128,7 @@ const getRandomSpace = (client: Client): Space | undefined => {
|
|
|
134
128
|
const getSpaceWithObjects = async (client: Client): Promise<Space | undefined> => {
|
|
135
129
|
const readySpaces = client.spaces.get().filter((space) => space.state.get() === SpaceState.SPACE_READY);
|
|
136
130
|
const spaceQueries = await Promise.all(
|
|
137
|
-
readySpaces.map((space) => space.db.query(Filter.type(Expando, { type: 'test' })).run()),
|
|
131
|
+
readySpaces.map((space) => space.db.query(Filter.type(Type.Expando, { type: 'test' })).run()),
|
|
138
132
|
);
|
|
139
133
|
const spaces = readySpaces.filter((space, index) => spaceQueries[index].objects.length > 0);
|
|
140
134
|
return spaces[Math.floor(Math.random() * spaces.length)];
|
|
@@ -159,13 +153,18 @@ const runAction = async (client: Client, action: Action) => {
|
|
|
159
153
|
}
|
|
160
154
|
|
|
161
155
|
case Action.ADD_OBJECT:
|
|
162
|
-
getRandomSpace(client)?.db.add(
|
|
156
|
+
getRandomSpace(client)?.db.add(
|
|
157
|
+
Obj.make(Type.Expando, {
|
|
158
|
+
type: 'test',
|
|
159
|
+
name: faker.commerce.productName(),
|
|
160
|
+
}),
|
|
161
|
+
);
|
|
163
162
|
break;
|
|
164
163
|
|
|
165
164
|
case Action.REMOVE_OBJECT: {
|
|
166
165
|
const space = await getSpaceWithObjects(client);
|
|
167
166
|
if (space) {
|
|
168
|
-
const { objects } = await space.db.query(Filter.type(Expando, { type: 'test' })).run();
|
|
167
|
+
const { objects } = await space.db.query(Filter.type(Type.Expando, { type: 'test' })).run();
|
|
169
168
|
space.db.remove(objects[Math.floor(Math.random() * objects.length)]);
|
|
170
169
|
}
|
|
171
170
|
break;
|
|
@@ -174,7 +173,7 @@ const runAction = async (client: Client, action: Action) => {
|
|
|
174
173
|
case Action.RENAME_OBJECT: {
|
|
175
174
|
const space = await getSpaceWithObjects(client);
|
|
176
175
|
if (space) {
|
|
177
|
-
const { objects } = await space.db.query(Filter.type(Expando, { type: 'test' })).run();
|
|
176
|
+
const { objects } = await space.db.query(Filter.type(Type.Expando, { type: 'test' })).run();
|
|
178
177
|
objects[Math.floor(Math.random() * objects.length)].name = faker.commerce.productName();
|
|
179
178
|
}
|
|
180
179
|
break;
|
|
@@ -214,7 +213,7 @@ const Controls = ({ children }: PropsWithChildren) => {
|
|
|
214
213
|
<Input.TextInput
|
|
215
214
|
autoComplete='off'
|
|
216
215
|
size={5}
|
|
217
|
-
classNames='
|
|
216
|
+
classNames='is-[100px] text-right pie-[22px]'
|
|
218
217
|
placeholder='Interval'
|
|
219
218
|
value={actionInterval}
|
|
220
219
|
onChange={({ target: { value } }) => setActionInterval(value)}
|
|
@@ -258,7 +257,7 @@ const meta = {
|
|
|
258
257
|
},
|
|
259
258
|
}),
|
|
260
259
|
],
|
|
261
|
-
} satisfies Meta
|
|
260
|
+
} satisfies Meta;
|
|
262
261
|
|
|
263
262
|
export default meta;
|
|
264
263
|
|
|
@@ -269,7 +268,7 @@ export const JsonView: Story = {
|
|
|
269
268
|
const client = useClient();
|
|
270
269
|
const registry = useContext(RegistryContext);
|
|
271
270
|
const graph = useMemo(() => createGraph(client, registry), [client, registry]);
|
|
272
|
-
const data =
|
|
271
|
+
const data = useAtomValue(graph.json());
|
|
273
272
|
|
|
274
273
|
return (
|
|
275
274
|
<>
|
|
@@ -289,7 +288,7 @@ export const TreeView: Story = {
|
|
|
289
288
|
|
|
290
289
|
const useItems = useCallback(
|
|
291
290
|
(node?: Node, options?: { disposition?: string; sort?: boolean }) => {
|
|
292
|
-
const connections =
|
|
291
|
+
const connections = useAtomValue(graph.connections(node?.id ?? ROOT_ID));
|
|
293
292
|
return options?.sort ? connections.toSorted((a, b) => byPosition(a.properties, b.properties)) : connections;
|
|
294
293
|
},
|
|
295
294
|
[graph],
|
package/src/stories/Tree.tsx
CHANGED
|
@@ -72,7 +72,7 @@ const Scalar: FC<{ value: any }> = ({ value }) => {
|
|
|
72
72
|
|
|
73
73
|
const Box: FC<HTMLAttributes<HTMLDivElement>> = ({ children, className, ...props }) => {
|
|
74
74
|
return (
|
|
75
|
-
<div className={mx('flex
|
|
75
|
+
<div className={mx('flex pli-2 border border-l-0 font-mono truncate', className)} {...props}>
|
|
76
76
|
{children}
|
|
77
77
|
</div>
|
|
78
78
|
);
|
package/src/testing.ts
CHANGED
|
@@ -2,13 +2,14 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { Atom } from '@effect-atom/atom-react';
|
|
6
6
|
|
|
7
|
-
import { type
|
|
8
|
-
import { type QueryResult } from '@dxos/echo-db';
|
|
7
|
+
import { type Database, type Entity } from '@dxos/echo';
|
|
9
8
|
|
|
10
|
-
export const
|
|
11
|
-
|
|
9
|
+
export const atomFromQuery = <T extends Entity.Unknown = Entity.Unknown>(
|
|
10
|
+
query: Database.QueryResult<T>,
|
|
11
|
+
): Atom.Atom<T[]> => {
|
|
12
|
+
return Atom.make((get) => {
|
|
12
13
|
const unsubscribe = query.subscribe((result) => {
|
|
13
14
|
get.setSelf(result.objects);
|
|
14
15
|
});
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
type Cb = () => void;
|
|
2
|
-
interface Query {
|
|
3
|
-
id?: string[];
|
|
4
|
-
typename?: string[];
|
|
5
|
-
}
|
|
6
|
-
/**
|
|
7
|
-
* Lazy query result that can be executed.
|
|
8
|
-
* Does not run without the run function being called.
|
|
9
|
-
*/
|
|
10
|
-
interface QueryResult<T> {
|
|
11
|
-
/**
|
|
12
|
-
* Execute the query and subscribe to the result.
|
|
13
|
-
* @param next Called at least once with the first value (maybe synchronously) and then for every subsequent update.
|
|
14
|
-
* @param error Called on error. `next` is never called after that.
|
|
15
|
-
* @returns Function to dispose the query and unsubscribe.
|
|
16
|
-
*/
|
|
17
|
-
run(onData: (value?: T[]) => void, onError: (err: Error) => void): Cb;
|
|
18
|
-
}
|
|
19
|
-
declare const QueryResult: Readonly<{
|
|
20
|
-
fromPromise: <T>(run: (onDispose: (cb: Cb) => void) => Promise<T[]>) => QueryResult<T>;
|
|
21
|
-
}>;
|
|
22
|
-
interface _Resolver<T> {
|
|
23
|
-
query(query: Query): QueryResult<T>;
|
|
24
|
-
}
|
|
25
|
-
//# sourceMappingURL=graph-projections.test.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"graph-projections.test.d.ts","sourceRoot":"","sources":["../../../../src/experimental/graph-projections.test.ts"],"names":[],"mappings":"AAIA,KAAK,EAAE,GAAG,MAAM,IAAI,CAAC;AAErB,UAAU,KAAK;IACb,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;CACrB;AAED;;;GAGG;AACH,UAAU,WAAW,CAAC,CAAC;IACrB;;;;;OAKG;IACH,GAAG,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,KAAK,IAAI,EAAE,OAAO,EAAE,CAAC,GAAG,EAAE,KAAK,KAAK,IAAI,GAAG,EAAE,CAAC;CACvE;AAED,QAAA,MAAM,WAAW;kBACD,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC,EAAE,EAAE,EAAE,KAAK,IAAI,KAAK,OAAO,CAAC,CAAC,EAAE,CAAC,KAAG,WAAW,CAAC,CAAC,CAAC;EAyBpF,CAAC;AAEH,UAAU,SAAS,CAAC,CAAC;IACnB,KAAK,CAAC,KAAK,EAAE,KAAK,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC;CACrC"}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
type Cb = () => void;
|
|
6
|
-
|
|
7
|
-
interface Query {
|
|
8
|
-
id?: string[];
|
|
9
|
-
typename?: string[];
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Lazy query result that can be executed.
|
|
14
|
-
* Does not run without the run function being called.
|
|
15
|
-
*/
|
|
16
|
-
interface QueryResult<T> {
|
|
17
|
-
/**
|
|
18
|
-
* Execute the query and subscribe to the result.
|
|
19
|
-
* @param next Called at least once with the first value (maybe synchronously) and then for every subsequent update.
|
|
20
|
-
* @param error Called on error. `next` is never called after that.
|
|
21
|
-
* @returns Function to dispose the query and unsubscribe.
|
|
22
|
-
*/
|
|
23
|
-
run(onData: (value?: T[]) => void, onError: (err: Error) => void): Cb;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const QueryResult = Object.freeze({
|
|
27
|
-
fromPromise: <T>(run: (onDispose: (cb: Cb) => void) => Promise<T[]>): QueryResult<T> => {
|
|
28
|
-
return {
|
|
29
|
-
run: (onData, onError) => {
|
|
30
|
-
const cbs: Cb[] = [];
|
|
31
|
-
let disposed = false;
|
|
32
|
-
const dispose = () => {
|
|
33
|
-
cbs.forEach((cb) => cb());
|
|
34
|
-
disposed = true;
|
|
35
|
-
};
|
|
36
|
-
run((cb) => (disposed ? cb() : cbs.push(cb))).then(
|
|
37
|
-
(data) => {
|
|
38
|
-
if (disposed) {
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
onData(data);
|
|
42
|
-
},
|
|
43
|
-
(err) => {
|
|
44
|
-
dispose();
|
|
45
|
-
onError(err);
|
|
46
|
-
},
|
|
47
|
-
);
|
|
48
|
-
return dispose;
|
|
49
|
-
},
|
|
50
|
-
};
|
|
51
|
-
},
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
interface _Resolver<T> {
|
|
55
|
-
query(query: Query): QueryResult<T>;
|
|
56
|
-
}
|