@dxos/app-graph 0.6.13 → 0.6.14-main.1366248
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 +97 -20
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +97 -20
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +885 -0
- package/dist/lib/node-esm/index.mjs.map +7 -0
- package/dist/lib/node-esm/meta.json +1 -0
- package/dist/types/src/graph-builder.d.ts +8 -2
- package/dist/types/src/graph-builder.d.ts.map +1 -1
- package/dist/types/src/graph.d.ts +11 -6
- package/dist/types/src/graph.d.ts.map +1 -1
- package/dist/types/src/stories/EchoGraph.stories.d.ts +1 -1
- package/dist/types/src/stories/EchoGraph.stories.d.ts.map +1 -1
- package/package.json +22 -20
- package/src/graph-builder.test.ts +41 -8
- package/src/graph-builder.ts +20 -2
- package/src/graph.test.ts +11 -9
- package/src/graph.ts +60 -14
- package/src/stories/EchoGraph.stories.tsx +45 -51
- package/src/stories/Tree.tsx +7 -7
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/graph.ts", "../../../src/node.ts", "../../../src/graph-builder.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { batch, effect, untracked } from '@preact/signals-core';\n\nimport { asyncTimeout, Trigger } from '@dxos/async';\nimport { type ReactiveObject, create } from '@dxos/echo-schema';\nimport { invariant } from '@dxos/invariant';\nimport { log } from '@dxos/log';\nimport { nonNullable } from '@dxos/util';\n\nimport { type Relation, type Node, type NodeArg, type NodeFilter, isActionLike, actionGroupSymbol } from './node';\n\nconst graphSymbol = Symbol('graph');\ntype DeepWriteable<T> = { -readonly [K in keyof T]: DeepWriteable<T[K]> };\ntype NodeInternal = DeepWriteable<Node> & { [graphSymbol]: Graph };\n\nexport const getGraph = (node: Node): Graph => {\n const graph = (node as NodeInternal)[graphSymbol];\n invariant(graph, 'Node is not associated with a graph.');\n return graph;\n};\n\nexport const ROOT_ID = 'root';\nexport const ROOT_TYPE = 'dxos.org/type/GraphRoot';\nexport const ACTION_TYPE = 'dxos.org/type/GraphAction';\nexport const ACTION_GROUP_TYPE = 'dxos.org/type/GraphActionGroup';\n\nexport type NodesOptions<T = any, U extends Record<string, any> = Record<string, any>> = {\n relation?: Relation;\n filter?: NodeFilter<T, U>;\n expansion?: boolean;\n type?: string;\n};\n\n// TODO(wittjosiah): Consider having default be undefined. This is current default for backwards compatibility.\nconst DEFAULT_FILTER = (node: Node) => untracked(() => !isActionLike(node));\n\nexport type GraphTraversalOptions = {\n /**\n * A callback which is called for each node visited during traversal.\n *\n * If the callback returns `false`, traversal is stops recursing.\n */\n visitor: (node: Node, path: string[]) => boolean | void;\n\n /**\n * The node to start traversing from.\n *\n * @default root\n */\n node?: Node;\n\n /**\n * The relation to traverse graph edges.\n *\n * @default 'outbound'\n */\n relation?: Relation;\n\n /**\n * Allow traversal to trigger expansion of the graph via `onInitialNodes`.\n */\n expansion?: boolean;\n};\n\nexport type GraphParams = {\n // TODO(wittjosiah): Make data optional instead of omitting.\n nodes?: Omit<Node, 'data'>[];\n edges?: Record<string, string[]>;\n onInitialNode?: Graph['_onInitialNode'];\n onInitialNodes?: Graph['_onInitialNodes'];\n onRemoveNode?: Graph['_onRemoveNode'];\n};\n\n/**\n * The Graph represents the structure of the application constructed via plugins.\n */\nexport class Graph {\n private readonly _onInitialNode?: (id: string) => Promise<void>;\n private readonly _onInitialNodes?: (node: Node, relation: Relation, type?: string) => Promise<void>;\n private readonly _onRemoveNode?: (id: string) => Promise<void>;\n\n private readonly _waitingForNodes: Record<string, Trigger<Node>> = {};\n private readonly _initialized: Record<string, boolean> = {};\n\n /**\n * @internal\n */\n readonly _nodes: Record<string, ReactiveObject<NodeInternal>> = {};\n\n /**\n * @internal\n */\n readonly _edges: Record<string, ReactiveObject<{ inbound: string[]; outbound: string[] }>> = {};\n\n constructor({ nodes, edges, onInitialNode, onInitialNodes, onRemoveNode }: GraphParams = {}) {\n this._nodes[ROOT_ID] = this._constructNode({ id: ROOT_ID, type: ROOT_TYPE, properties: {}, data: null });\n if (nodes) {\n nodes.forEach((node) => {\n if (node.type === ACTION_TYPE) {\n this._addNode({ ...node, data: () => log.warn('Pickled action invocation') });\n } else if (node.type === ACTION_GROUP_TYPE) {\n this._addNode({ ...node, data: actionGroupSymbol });\n } else {\n this._addNode(node);\n }\n });\n }\n\n this._edges[ROOT_ID] = create({ inbound: [], outbound: [] });\n if (edges) {\n Object.entries(edges).forEach(([source, edges]) => {\n edges.forEach((target) => {\n this._addEdge({ source, target });\n });\n this._sortEdges(source, 'outbound', edges);\n });\n }\n\n this._onInitialNode = onInitialNode;\n this._onInitialNodes = onInitialNodes;\n this._onRemoveNode = onRemoveNode;\n }\n\n static from(pickle: string, options: Omit<GraphParams, 'nodes' | 'edges'> = {}) {\n const { nodes, edges } = JSON.parse(pickle);\n return new Graph({ nodes, edges, ...options });\n }\n\n /**\n * Alias for `findNode('root')`.\n */\n get root() {\n return this.findNode(ROOT_ID)!;\n }\n\n /**\n * Convert the graph to a JSON object.\n */\n toJSON({ id = ROOT_ID, maxLength = 32 }: { id?: string; maxLength?: number } = {}) {\n const toJSON = (node: Node, seen: string[] = []): any => {\n const nodes = this.nodes(node);\n const obj: Record<string, any> = {\n id: node.id.length > maxLength ? `${node.id.slice(0, maxLength - 3)}...` : node.id,\n type: node.type,\n };\n if (node.properties.label) {\n obj.label = node.properties.label;\n }\n if (nodes.length) {\n obj.nodes = nodes\n .map((n) => {\n // Break cycles.\n const nextSeen = [...seen, node.id];\n return nextSeen.includes(n.id) ? undefined : toJSON(n, nextSeen);\n })\n .filter(nonNullable);\n }\n return obj;\n };\n\n const root = this.findNode(id);\n invariant(root, `Node not found: ${id}`);\n return toJSON(root);\n }\n\n pickle() {\n const nodes = Object.values(this._nodes).map((node) => {\n return {\n id: node.id,\n type: node.type,\n properties: node.properties,\n };\n });\n\n const edges = Object.fromEntries(\n Object.entries(this._edges)\n .map(([id, { outbound }]): [string, string[]] => [id, outbound])\n .toSorted(([a], [b]) => a.localeCompare(b)),\n );\n\n return JSON.stringify({ nodes, edges });\n }\n\n /**\n * Find the node with the given id in the graph.\n *\n * If a node is not found within the graph and an `onInitialNode` callback is provided,\n * it is called with the id and type of the node, potentially initializing the node.\n */\n findNode(id: string, expansion = true): Node | undefined {\n const existingNode = this._nodes[id];\n if (!existingNode && expansion) {\n void this._onInitialNode?.(id);\n }\n\n return existingNode;\n }\n\n /**\n * Wait for a node to be added to the graph.\n *\n * If the node is already present in the graph, the promise resolves immediately.\n *\n * @param id The id of the node to wait for.\n * @param timeout The time in milliseconds to wait for the node to be added.\n */\n async waitForNode(id: string, timeout?: number): Promise<Node> {\n const trigger = this._waitingForNodes[id] ?? (this._waitingForNodes[id] = new Trigger<Node>());\n const node = this.findNode(id);\n if (node) {\n delete this._waitingForNodes[id];\n return node;\n }\n\n if (timeout === undefined) {\n return trigger.wait();\n } else {\n return asyncTimeout(trigger.wait(), timeout, `Node not found: ${id}`);\n }\n }\n\n /**\n * Nodes that this node is connected to in default order.\n */\n nodes<T = any, U extends Record<string, any> = Record<string, any>>(node: Node, options: NodesOptions<T, U> = {}) {\n const { relation, expansion, filter = DEFAULT_FILTER, type } = options;\n const nodes = this._getNodes({ node, relation, expansion, type });\n return nodes.filter((n) => filter(n, node));\n }\n\n /**\n * Edges that this node is connected to in default order.\n */\n edges(node: Node, { relation = 'outbound' }: { relation?: Relation } = {}) {\n return this._edges[node.id]?.[relation] ?? [];\n }\n\n /**\n * Actions or action groups that this node is connected to in default order.\n */\n actions(node: Node, { expansion }: { expansion?: boolean } = {}) {\n return [\n ...this._getNodes({ node, expansion, type: ACTION_GROUP_TYPE }),\n ...this._getNodes({ node, expansion, type: ACTION_TYPE }),\n ];\n }\n\n async expand(node: Node, relation: Relation = 'outbound', type?: string) {\n const key = this._key(node, relation, type);\n const initialized = this._initialized[key];\n if (!initialized && this._onInitialNodes) {\n await this._onInitialNodes(node, relation, type);\n this._initialized[key] = true;\n }\n }\n\n private _key(node: Node, relation: Relation, type?: string) {\n return `${node.id}-${relation}-${type}`;\n }\n\n /**\n * Recursive depth-first traversal of the graph.\n *\n * @param options.node The node to start traversing from.\n * @param options.relation The relation to traverse graph edges.\n * @param options.visitor A callback which is called for each node visited during traversal.\n */\n traverse(\n { visitor, node = this.root, relation = 'outbound', expansion }: GraphTraversalOptions,\n path: string[] = [],\n ): void {\n // Break cycles.\n if (path.includes(node.id)) {\n return;\n }\n\n const shouldContinue = visitor(node, [...path, node.id]);\n if (shouldContinue === false) {\n return;\n }\n\n Object.values(this._getNodes({ node, relation, expansion })).forEach((child) =>\n this.traverse({ node: child, relation, visitor, expansion }, [...path, node.id]),\n );\n }\n\n /**\n * Recursive depth-first traversal of the graph wrapping each visitor call in an effect.\n *\n * @param options.node The node to start traversing from.\n * @param options.relation The relation to traverse graph edges.\n * @param options.visitor A callback which is called for each node visited during traversal.\n */\n subscribeTraverse(\n { visitor, node = this.root, relation = 'outbound', expansion }: GraphTraversalOptions,\n currentPath: string[] = [],\n ) {\n return effect(() => {\n const path = [...currentPath, node.id];\n const result = visitor(node, path);\n if (result === false) {\n return;\n }\n\n const nodes = this._getNodes({ node, relation, expansion });\n const nodeSubscriptions = nodes.map((n) => this.subscribeTraverse({ node: n, visitor, expansion }, path));\n\n return () => {\n nodeSubscriptions.forEach((unsubscribe) => unsubscribe());\n };\n });\n }\n\n /**\n * Get the path between two nodes in the graph.\n */\n getPath({ source = 'root', target }: { source?: string; target: string }): string[] | undefined {\n const start = this.findNode(source);\n if (!start) {\n return undefined;\n }\n\n let found: string[] | undefined;\n this.traverse({\n node: start,\n visitor: (node, path) => {\n if (found) {\n return false;\n }\n\n if (node.id === target) {\n found = path;\n }\n },\n });\n\n return found;\n }\n\n /**\n * Add nodes to the graph.\n *\n * @internal\n */\n _addNodes<TData = null, TProperties extends Record<string, any> = Record<string, any>>(\n nodes: NodeArg<TData, TProperties>[],\n ): Node<TData, TProperties>[] {\n return batch(() => nodes.map((node) => this._addNode(node)));\n }\n\n private _addNode<TData, TProperties extends Record<string, any> = Record<string, any>>({\n nodes,\n edges,\n ..._node\n }: NodeArg<TData, TProperties>): Node<TData, TProperties> {\n return untracked(() => {\n const existingNode = this._nodes[_node.id];\n const node = existingNode ?? this._constructNode({ data: null, properties: {}, ..._node });\n if (existingNode) {\n const { data, properties, type } = _node;\n if (data && data !== node.data) {\n node.data = data;\n }\n\n if (type !== node.type) {\n node.type = type;\n }\n\n for (const key in properties) {\n if (properties[key] !== node.properties[key]) {\n node.properties[key] = properties[key];\n }\n }\n } else {\n this._nodes[node.id] = node;\n this._edges[node.id] = create({ inbound: [], outbound: [] });\n }\n\n const trigger = this._waitingForNodes[node.id];\n if (trigger) {\n trigger.wake(node);\n delete this._waitingForNodes[node.id];\n }\n\n if (nodes) {\n nodes.forEach((subNode) => {\n this._addNode(subNode);\n this._addEdge({ source: node.id, target: subNode.id });\n });\n }\n\n if (edges) {\n edges.forEach(([id, relation]) =>\n relation === 'outbound'\n ? this._addEdge({ source: node.id, target: id })\n : this._addEdge({ source: id, target: node.id }),\n );\n }\n\n return node as unknown as Node<TData, TProperties>;\n });\n }\n\n /**\n * Remove nodes from the graph.\n *\n * @param ids The id of the node to remove.\n * @param edges Whether to remove edges connected to the node from the graph as well.\n * @internal\n */\n _removeNodes(ids: string[], edges = false) {\n batch(() => ids.forEach((id) => this._removeNode(id, edges)));\n }\n\n private _removeNode(id: string, edges = false) {\n untracked(() => {\n const node = this.findNode(id);\n if (!node) {\n return;\n }\n\n if (edges) {\n // Remove edges from connected nodes.\n this._getNodes({ node }).forEach((node) => {\n this._removeEdge({ source: id, target: node.id });\n });\n this._getNodes({ node, relation: 'inbound' }).forEach((node) => {\n this._removeEdge({ source: node.id, target: id });\n });\n\n // Remove edges from node.\n delete this._edges[id];\n }\n\n // Remove node.\n delete this._nodes[id];\n Object.keys(this._initialized)\n .filter((key) => key.startsWith(id))\n .forEach((key) => {\n delete this._initialized[key];\n });\n void this._onRemoveNode?.(id);\n });\n }\n\n /**\n * Add edges to the graph.\n *\n * @internal\n */\n _addEdges(edges: { source: string; target: string }[]) {\n batch(() => edges.forEach((edge) => this._addEdge(edge)));\n }\n\n private _addEdge({ source, target }: { source: string; target: string }) {\n untracked(() => {\n if (!this._edges[source]) {\n this._edges[source] = create({ inbound: [], outbound: [] });\n }\n if (!this._edges[target]) {\n this._edges[target] = create({ inbound: [], outbound: [] });\n }\n\n const sourceEdges = this._edges[source];\n if (!sourceEdges.outbound.includes(target)) {\n sourceEdges.outbound.push(target);\n }\n\n const targetEdges = this._edges[target];\n if (!targetEdges.inbound.includes(source)) {\n targetEdges.inbound.push(source);\n }\n });\n }\n\n /**\n * Remove edges from the graph.\n * @internal\n */\n _removeEdges(edges: { source: string; target: string }[], removeOrphans = false) {\n batch(() => edges.forEach((edge) => this._removeEdge(edge, removeOrphans)));\n }\n\n private _removeEdge({ source, target }: { source: string; target: string }, removeOrphans = false) {\n untracked(() => {\n batch(() => {\n const outboundIndex = this._edges[source]?.outbound.findIndex((id) => id === target);\n if (outboundIndex !== undefined && outboundIndex !== -1) {\n this._edges[source].outbound.splice(outboundIndex, 1);\n }\n\n const inboundIndex = this._edges[target]?.inbound.findIndex((id) => id === source);\n if (inboundIndex !== undefined && inboundIndex !== -1) {\n this._edges[target].inbound.splice(inboundIndex, 1);\n }\n\n if (removeOrphans) {\n if (\n this._edges[source]?.outbound.length === 0 &&\n this._edges[source]?.inbound.length === 0 &&\n source !== ROOT_ID\n ) {\n this._removeNode(source, true);\n }\n if (\n this._edges[target]?.outbound.length === 0 &&\n this._edges[target]?.inbound.length === 0 &&\n target !== ROOT_ID\n ) {\n this._removeNode(target, true);\n }\n }\n });\n });\n }\n\n /**\n * Sort edges for a node.\n *\n * Edges not included in the sorted list are appended to the end of the list.\n *\n * @param nodeId The id of the node to sort edges for.\n * @param relation The relation of the edges from the node to sort.\n * @param edges The ordered list of edges.\n * @ignore\n */\n _sortEdges(nodeId: string, relation: Relation, edges: string[]) {\n untracked(() => {\n batch(() => {\n const current = this._edges[nodeId];\n if (current) {\n const unsorted = current[relation].filter((id) => !edges.includes(id)) ?? [];\n const sorted = edges.filter((id) => current[relation].includes(id)) ?? [];\n current[relation].splice(0, current[relation].length, ...[...sorted, ...unsorted]);\n }\n });\n });\n }\n\n private _constructNode = (node: Omit<Node, typeof graphSymbol>) => {\n return create<NodeInternal>({ ...node, [graphSymbol]: this });\n };\n\n private _getNodes({\n node,\n relation = 'outbound',\n type,\n expansion,\n }: {\n node: Node;\n relation?: Relation;\n type?: string;\n expansion?: boolean;\n }): Node[] {\n if (expansion) {\n void this.expand(node, relation, type);\n }\n\n const edges = this._edges[node.id];\n if (!edges) {\n return [];\n } else {\n return edges[relation]\n .map((id) => this._nodes[id])\n .filter(nonNullable)\n .filter((n) => !type || n.type === type);\n }\n }\n}\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { type MaybePromise, type MakeOptional } from '@dxos/util';\n\n/**\n * Represents a node in the graph.\n */\n// TODO(wittjosiah): Use Effect Schema.\n// TODO(burdon): Rename GraphNode. Node is already in the global namespace.\nexport type Node<TData = any, TProperties extends Record<string, any> = Record<string, any>> = Readonly<{\n /**\n * Globally unique ID.\n */\n id: string;\n\n /**\n * Typename of the data the node represents.\n */\n type: string;\n\n /**\n * Properties of the node relevant to displaying the node.\n */\n properties: Readonly<TProperties>;\n\n /**\n * Data the node represents.\n */\n // TODO(burdon): Type system (e.g., minimally provide identifier string vs. TypedObject vs. Graph mixin type system)?\n // type field would prevent convoluted sniffing of object properties. And allow direct pass-through for ECHO TypedObjects.\n data: TData;\n}>;\n\nexport type NodeFilter<T = any, U extends Record<string, any> = Record<string, any>> = (\n node: Node<unknown, Record<string, any>>,\n connectedNode: Node,\n) => node is Node<T, U>;\n\nexport type Relation = 'outbound' | 'inbound';\n\nexport const isGraphNode = (data: unknown): data is Node =>\n data && typeof data === 'object' && 'id' in data && 'properties' in data && data.properties\n ? typeof data.properties === 'object' && 'data' in data\n : false;\n\nexport type NodeArg<TData, TProperties extends Record<string, any> = Record<string, any>> = MakeOptional<\n Node<TData, TProperties>,\n 'data' | 'properties'\n> & {\n /** Will automatically add nodes with an edge from this node to each. */\n nodes?: NodeArg<unknown>[];\n\n /** Will automatically add specified edges. */\n edges?: [string, Relation][];\n};\n\n//\n// Actions\n//\n\nexport type InvokeParams = {\n /** Node the invoked action is connected to. */\n node: Node;\n\n caller?: string;\n};\n\nexport type ActionData = (params: InvokeParams) => MaybePromise<void>;\n\nexport type Action<TProperties extends Record<string, any> = Record<string, any>> = Readonly<\n Omit<Node<ActionData, TProperties>, 'properties'> & {\n properties: Readonly<TProperties>;\n }\n>;\n\nexport const isAction = (data: unknown): data is Action =>\n isGraphNode(data) ? typeof data.data === 'function' : false;\n\nexport const actionGroupSymbol = Symbol('ActionGroup');\n\nexport type ActionGroup = Readonly<\n Omit<Node<typeof actionGroupSymbol, Record<string, any>>, 'properties'> & {\n properties: Readonly<Record<string, any>>;\n }\n>;\n\nexport const isActionGroup = (data: unknown): data is ActionGroup =>\n isGraphNode(data) ? data.data === actionGroupSymbol : false;\n\nexport type ActionLike = Action | ActionGroup;\n\nexport const isActionLike = (data: unknown): data is Action | ActionGroup => isAction(data) || isActionGroup(data);\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { type Signal, effect, signal } from '@preact/signals-core';\n\nimport { type UnsubscribeCallback } from '@dxos/async';\nimport { create } from '@dxos/echo-schema';\nimport { invariant } from '@dxos/invariant';\nimport { log } from '@dxos/log';\nimport { isNode, type MaybePromise, nonNullable } from '@dxos/util';\n\nimport { ACTION_GROUP_TYPE, ACTION_TYPE, Graph, type GraphParams } from './graph';\nimport { type Relation, type NodeArg, type Node, type ActionData, actionGroupSymbol } from './node';\n\n/**\n * Graph builder extension for adding nodes to the graph based on just the node id.\n * This is useful for creating the first node in a graph or for hydrating cached nodes with data.\n *\n * @param params.id The id of the node to resolve.\n */\nexport type ResolverExtension = (params: { id: string }) => NodeArg<any> | undefined;\n\n/**\n * Graph builder extension for adding nodes to the graph based on a connection to an existing node.\n *\n * @param params.node The existing node the returned nodes will be connected to.\n */\nexport type ConnectorExtension<T = any> = (params: { node: Node<T> }) => NodeArg<any>[] | undefined;\n\n/**\n * Constrained case of the connector extension for more easily adding actions to the graph.\n */\nexport type ActionsExtension<T = any> = (params: {\n node: Node<T>;\n}) => Omit<NodeArg<ActionData>, 'type' | 'nodes' | 'edges'>[] | undefined;\n\n/**\n * Constrained case of the connector extension for more easily adding action groups to the graph.\n */\nexport type ActionGroupsExtension<T = any> = (params: {\n node: Node<T>;\n}) => Omit<NodeArg<typeof actionGroupSymbol>, 'type' | 'data' | 'nodes' | 'edges'>[] | undefined;\n\ntype GuardedNodeType<T> = T extends (value: any) => value is infer N ? (N extends Node<infer D> ? D : unknown) : never;\n\n/**\n * A graph builder extension is used to add nodes to the graph.\n *\n * @param params.id The unique id of the extension.\n * @param params.relation The relation the graph is being expanded from the existing node.\n * @param params.type If provided, all nodes returned are expected to have this type.\n * @param params.filter A filter function to determine if an extension should act on a node.\n * @param params.resolver A function to add nodes to the graph based on just the node id.\n * @param params.connector A function to add nodes to the graph based on a connection to an existing node.\n * @param params.actions A function to add actions to the graph based on a connection to an existing node.\n * @param params.actionGroups A function to add action groups to the graph based on a connection to an existing node.\n */\nexport type CreateExtensionOptions<T = any> = {\n id: string;\n relation?: Relation;\n type?: string;\n filter?: (node: Node) => node is Node<T>;\n resolver?: ResolverExtension;\n connector?: ConnectorExtension<GuardedNodeType<CreateExtensionOptions<T>['filter']>>;\n actions?: ActionsExtension<GuardedNodeType<CreateExtensionOptions<T>['filter']>>;\n actionGroups?: ActionGroupsExtension<GuardedNodeType<CreateExtensionOptions<T>['filter']>>;\n};\n\n/**\n * Create a graph builder extension.\n */\nexport const createExtension = <T = any>(extension: CreateExtensionOptions<T>): BuilderExtension[] => {\n const { id, resolver, connector, actions, actionGroups, ...rest } = extension;\n const getId = (key: string) => `${id}/${key}`;\n return [\n resolver ? { id: getId('resolver'), resolver } : undefined,\n connector ? { ...rest, id: getId('connector'), connector } : undefined,\n actionGroups\n ? ({\n ...rest,\n id: getId('actionGroups'),\n type: ACTION_GROUP_TYPE,\n relation: 'outbound',\n connector: ({ node }) =>\n actionGroups({ node })?.map((arg) => ({ ...arg, data: actionGroupSymbol, type: ACTION_GROUP_TYPE })),\n } satisfies BuilderExtension)\n : undefined,\n actions\n ? ({\n ...rest,\n id: getId('actions'),\n type: ACTION_TYPE,\n relation: 'outbound',\n connector: ({ node }) => actions({ node })?.map((arg) => ({ ...arg, type: ACTION_TYPE })),\n } satisfies BuilderExtension)\n : undefined,\n ].filter(nonNullable);\n};\n\nexport type GraphBuilderTraverseOptions = {\n visitor: (node: Node, path: string[]) => MaybePromise<boolean | void>;\n node?: Node;\n relation?: Relation;\n};\n\n/**\n * The dispatcher is used to keep track of the current extension and state when memoizing functions.\n */\nclass Dispatcher {\n currentExtension?: string;\n stateIndex = 0;\n state: Record<string, any[]> = {};\n cleanup: (() => void)[] = [];\n}\n\nclass BuilderInternal {\n // This must be static to avoid passing the dispatcher instance to every memoized function.\n // If the dispatcher is not set that means that the memoized function is being called outside of the graph builder.\n static currentDispatcher?: Dispatcher;\n}\n\n/**\n * Allows code to be memoized within the context of a graph builder extension.\n * This is useful for creating instances which should be subscribed to rather than recreated.\n */\nexport const memoize = <T>(fn: () => T, key = 'result'): T => {\n const dispatcher = BuilderInternal.currentDispatcher;\n invariant(dispatcher?.currentExtension, 'memoize must be called within an extension');\n const all = dispatcher.state[dispatcher.currentExtension][dispatcher.stateIndex] ?? {};\n const current = all[key];\n const result = current ? current.result : fn();\n dispatcher.state[dispatcher.currentExtension][dispatcher.stateIndex] = { ...all, [key]: { result } };\n dispatcher.stateIndex++;\n return result;\n};\n\n/**\n * Register a cleanup function to be called when the graph builder is destroyed.\n */\nexport const cleanup = (fn: () => void): void => {\n memoize(() => {\n const dispatcher = BuilderInternal.currentDispatcher;\n invariant(dispatcher, 'cleanup must be called within an extension');\n dispatcher.cleanup.push(fn);\n });\n};\n\n/**\n * Convert a subscribe/get pair into a signal.\n */\nexport const toSignal = <T>(\n subscribe: (onChange: () => void) => () => void,\n get: () => T | undefined,\n key?: string,\n) => {\n const thisSignal = memoize(() => {\n return signal(get());\n }, key);\n const unsubscribe = memoize(() => {\n return subscribe(() => (thisSignal.value = get()));\n }, key);\n cleanup(() => {\n unsubscribe();\n });\n return thisSignal.value;\n};\n\nexport type BuilderExtension = {\n id: string;\n resolver?: ResolverExtension;\n connector?: ConnectorExtension;\n // Only for connector.\n relation?: Relation;\n type?: string;\n filter?: (node: Node) => boolean;\n};\n\ntype ExtensionArg = BuilderExtension | BuilderExtension[] | ExtensionArg[];\n\n/**\n * The builder provides an extensible way to compose the construction of the graph.\n */\n// TODO(wittjosiah): Add api for setting subscription set and/or radius.\n// Should unsubscribe from nodes that are not in the set/radius.\n// Should track LRU nodes that are not in the set/radius and remove them beyond a certain threshold.\nexport class GraphBuilder {\n private readonly _dispatcher = new Dispatcher();\n private readonly _extensions = create<Record<string, BuilderExtension>>({});\n private readonly _resolverSubscriptions = new Map<string, UnsubscribeCallback>();\n private readonly _connectorSubscriptions = new Map<string, UnsubscribeCallback>();\n private readonly _nodeChanged: Record<string, Signal<{}>> = {};\n private _graph: Graph;\n\n constructor(params: Pick<GraphParams, 'nodes' | 'edges'> = {}) {\n this._graph = new Graph({\n ...params,\n onInitialNode: (id) => this._onInitialNode(id),\n onInitialNodes: (node, relation, type) => this._onInitialNodes(node, relation, type),\n onRemoveNode: (id) => this._onRemoveNode(id),\n });\n }\n\n static from(pickle?: string) {\n if (!pickle) {\n return new GraphBuilder();\n }\n\n const { nodes, edges } = JSON.parse(pickle);\n return new GraphBuilder({ nodes, edges });\n }\n\n /**\n * If graph is being restored from a pickle, the data will be null.\n * Initialize the data of each node by calling resolvers.\n */\n async initialize() {\n return Promise.all(Object.keys(this._graph._nodes).map((id) => this._onInitialNode(id)));\n }\n\n get graph() {\n return this._graph;\n }\n\n /**\n * Register a node builder which will be called in order to construct the graph.\n */\n addExtension(extension: ExtensionArg): GraphBuilder {\n if (Array.isArray(extension)) {\n extension.forEach((ext) => this.addExtension(ext));\n return this;\n }\n\n this._dispatcher.state[extension.id] = [];\n this._extensions[extension.id] = extension;\n return this;\n }\n\n /**\n * Remove a node builder from the graph builder.\n */\n removeExtension(id: string): GraphBuilder {\n delete this._extensions[id];\n return this;\n }\n\n destroy() {\n this._dispatcher.cleanup.forEach((fn) => fn());\n this._resolverSubscriptions.forEach((unsubscribe) => unsubscribe());\n this._connectorSubscriptions.forEach((unsubscribe) => unsubscribe());\n this._resolverSubscriptions.clear();\n this._connectorSubscriptions.clear();\n }\n\n /**\n * A graph traversal using just the connector extensions, without subscribing to any signals or persisting any nodes.\n */\n async explore(\n { node = this._graph.root, relation = 'outbound', visitor }: GraphBuilderTraverseOptions,\n path: string[] = [],\n ) {\n // Break cycles.\n if (path.includes(node.id)) {\n return;\n }\n\n // TODO(wittjosiah): This is a workaround for esm not working in the test runner.\n // Switching to vitest is blocked by having node esm versions of echo-schema & echo-signals.\n if (!isNode()) {\n const { yieldOrContinue } = await import('main-thread-scheduling');\n await yieldOrContinue('idle');\n }\n const shouldContinue = await visitor(node, [...path, node.id]);\n if (shouldContinue === false) {\n return;\n }\n\n const nodes = Object.values(this._extensions)\n .filter((extension) => relation === (extension.relation ?? 'outbound'))\n .filter((extension) => !extension.filter || extension.filter(node))\n .flatMap((extension) => {\n this._dispatcher.currentExtension = extension.id;\n this._dispatcher.stateIndex = 0;\n BuilderInternal.currentDispatcher = this._dispatcher;\n const result = extension.connector?.({ node }) ?? [];\n BuilderInternal.currentDispatcher = undefined;\n return result;\n })\n .map(\n (arg): Node => ({\n id: arg.id,\n type: arg.type,\n data: arg.data ?? null,\n properties: arg.properties ?? {},\n }),\n );\n\n await Promise.all(nodes.map((n) => this.explore({ node: n, relation, visitor }, [...path, node.id])));\n }\n\n private async _onInitialNode(nodeId: string) {\n this._nodeChanged[nodeId] = this._nodeChanged[nodeId] ?? signal({});\n this._resolverSubscriptions.set(\n nodeId,\n effect(() => {\n for (const { id, resolver } of Object.values(this._extensions)) {\n if (!resolver) {\n continue;\n }\n\n this._dispatcher.currentExtension = id;\n this._dispatcher.stateIndex = 0;\n BuilderInternal.currentDispatcher = this._dispatcher;\n let node: NodeArg<any> | undefined;\n try {\n node = resolver({ id: nodeId });\n } catch (err) {\n log.catch(err, { extension: id });\n log.error(`Previous error occurred in extension: ${id}`);\n } finally {\n BuilderInternal.currentDispatcher = undefined;\n }\n\n if (node) {\n this.graph._addNodes([node]);\n if (this._nodeChanged[node.id]) {\n this._nodeChanged[node.id].value = {};\n }\n break;\n }\n }\n }),\n );\n }\n\n private async _onInitialNodes(node: Node, nodesRelation: Relation, nodesType?: string) {\n this._nodeChanged[node.id] = this._nodeChanged[node.id] ?? signal({});\n let first = true;\n let previous: string[] = [];\n this._connectorSubscriptions.set(\n node.id,\n effect(() => {\n // TODO(wittjosiah): This is a workaround for a race between the node removal and the effect re-running.\n // To cause this case to happen, remove a collection and then undo the removal.\n if (!first && !this._connectorSubscriptions.has(node.id)) {\n return;\n }\n first = false;\n\n // Subscribe to extensions being added.\n Object.keys(this._extensions);\n // Subscribe to connected node changes.\n this._nodeChanged[node.id].value;\n\n // TODO(wittjosiah): Consider allowing extensions to collaborate on the same node by merging their results.\n const nodes: NodeArg<any>[] = [];\n for (const { id, connector, filter, type, relation = 'outbound' } of Object.values(this._extensions)) {\n if (\n !connector ||\n relation !== nodesRelation ||\n (nodesType && type !== nodesType) ||\n (filter && !filter(node))\n ) {\n continue;\n }\n\n this._dispatcher.currentExtension = id;\n this._dispatcher.stateIndex = 0;\n BuilderInternal.currentDispatcher = this._dispatcher;\n try {\n nodes.push(...(connector({ node }) ?? []));\n } catch (err) {\n log.catch(err, { extension: id });\n log.error(`Previous error occurred in extension: ${id}`);\n } finally {\n BuilderInternal.currentDispatcher = undefined;\n }\n }\n\n const ids = nodes.map((n) => n.id);\n const removed = previous.filter((id) => !ids.includes(id));\n previous = ids;\n\n // Remove edges and only remove nodes that are orphaned.\n this.graph._removeEdges(\n removed.map((target) => ({ source: node.id, target })),\n true,\n );\n this.graph._addNodes(nodes);\n this.graph._addEdges(\n nodes.map(({ id }) =>\n nodesRelation === 'outbound' ? { source: node.id, target: id } : { source: id, target: node.id },\n ),\n );\n this.graph._sortEdges(\n node.id,\n nodesRelation,\n nodes.map(({ id }) => id),\n );\n nodes.forEach((n) => {\n if (this._nodeChanged[n.id]) {\n this._nodeChanged[n.id].value = {};\n }\n });\n }),\n );\n }\n\n private async _onRemoveNode(nodeId: string) {\n this._resolverSubscriptions.get(nodeId)?.();\n this._connectorSubscriptions.get(nodeId)?.();\n this._resolverSubscriptions.delete(nodeId);\n this._connectorSubscriptions.delete(nodeId);\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;AAIA,SAASA,OAAOC,QAAQC,iBAAiB;AAEzC,SAASC,cAAcC,eAAe;AACtC,SAA8BC,cAAc;AAC5C,SAASC,iBAAiB;AAC1B,SAASC,WAAW;AACpB,SAASC,mBAAmB;;;ACgCrB,IAAMC,cAAc,CAACC,SAC1BA,QAAQ,OAAOA,SAAS,YAAY,QAAQA,QAAQ,gBAAgBA,QAAQA,KAAKC,aAC7E,OAAOD,KAAKC,eAAe,YAAY,UAAUD,OACjD;AAgCC,IAAME,WAAW,CAACF,SACvBD,YAAYC,IAAAA,IAAQ,OAAOA,KAAKA,SAAS,aAAa;AAEjD,IAAMG,oBAAoBC,OAAO,aAAA;AAQjC,IAAMC,gBAAgB,CAACL,SAC5BD,YAAYC,IAAAA,IAAQA,KAAKA,SAASG,oBAAoB;AAIjD,IAAMG,eAAe,CAACN,SAAgDE,SAASF,IAAAA,KAASK,cAAcL,IAAAA;;;;AD/E7G,I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AE,MACboG,kBAAkB,aAAa;QAAES,QAAQjG,KAAKZ;QAAI4G,QAAQ5G;MAAG,IAAI;QAAE6G,QAAQ7G;QAAI4G,QAAQhG,KAAKZ;MAAG,CAAA,CAAA;AAGnG,WAAKuE,MAAMwC,WACTnG,KAAKZ,IACLoG,eACAtC,MAAMjD,IAAI,CAAC,EAAEb,GAAE,MAAOA,EAAAA,CAAAA;AAExB8D,YAAMa,QAAQ,CAACgB,MAAAA;AACb,YAAI,KAAKxC,aAAawC,EAAE3F,EAAE,GAAG;AAC3B,eAAKmD,aAAawC,EAAE3F,EAAE,EAAEyC,QAAQ,CAAC;QACnC;MACF,CAAA;IACF,CAAA,CAAA;EAEJ;EAEA,MAAckB,cAAciC,QAAgB;AAC1C,SAAK5C,uBAAuBX,IAAIuD,MAAAA,IAAAA;AAChC,SAAK1C,wBAAwBb,IAAIuD,MAAAA,IAAAA;AACjC,SAAK5C,uBAAuBgE,OAAOpB,MAAAA;AACnC,SAAK1C,wBAAwB8D,OAAOpB,MAAAA;EACtC;AACF;",
|
|
6
|
+
"names": ["batch", "effect", "untracked", "asyncTimeout", "Trigger", "create", "invariant", "log", "nonNullable", "isGraphNode", "data", "properties", "isAction", "actionGroupSymbol", "Symbol", "isActionGroup", "isActionLike", "graphSymbol", "Symbol", "getGraph", "node", "graph", "invariant", "ROOT_ID", "ROOT_TYPE", "ACTION_TYPE", "ACTION_GROUP_TYPE", "DEFAULT_FILTER", "untracked", "isActionLike", "Graph", "constructor", "nodes", "edges", "onInitialNode", "onInitialNodes", "onRemoveNode", "_waitingForNodes", "_initialized", "_nodes", "_edges", "_constructNode", "create", "id", "type", "properties", "data", "forEach", "_addNode", "log", "warn", "actionGroupSymbol", "inbound", "outbound", "Object", "entries", "source", "target", "_addEdge", "_sortEdges", "_onInitialNode", "_onInitialNodes", "_onRemoveNode", "from", "pickle", "options", "JSON", "parse", "root", "findNode", "toJSON", "maxLength", "seen", "obj", "length", "slice", "label", "map", "n", "nextSeen", "includes", "undefined", "filter", "nonNullable", "values", "fromEntries", "toSorted", "a", "b", "localeCompare", "stringify", "expansion", "existingNode", "waitForNode", "timeout", "trigger", "Trigger", "wait", "asyncTimeout", "relation", "_getNodes", "actions", "expand", "key", "_key", "initialized", "traverse", "visitor", "path", "shouldContinue", "child", "subscribeTraverse", "currentPath", "effect", "result", "nodeSubscriptions", "unsubscribe", "getPath", "start", "found", "_addNodes", "batch", "_node", "wake", "subNode", "_removeNodes", "ids", "_removeNode", "_removeEdge", "keys", "startsWith", "_addEdges", "edge", "sourceEdges", "push", "targetEdges", "_removeEdges", "removeOrphans", "outboundIndex", "findIndex", "splice", "inboundIndex", "nodeId", "current", "unsorted", "sorted", "effect", "signal", "create", "invariant", "log", "isNode", "nonNullable", "createExtension", "extension", "id", "resolver", "connector", "actions", "actionGroups", "rest", "getId", "key", "undefined", "type", "ACTION_GROUP_TYPE", "relation", "node", "map", "arg", "data", "actionGroupSymbol", "ACTION_TYPE", "filter", "nonNullable", "Dispatcher", "stateIndex", "state", "cleanup", "BuilderInternal", "memoize", "fn", "dispatcher", "currentDispatcher", "invariant", "currentExtension", "all", "current", "result", "push", "toSignal", "subscribe", "get", "thisSignal", "signal", "unsubscribe", "value", "GraphBuilder", "constructor", "params", "_dispatcher", "_extensions", "create", "_resolverSubscriptions", "Map", "_connectorSubscriptions", "_nodeChanged", "_graph", "Graph", "onInitialNode", "_onInitialNode", "onInitialNodes", "_onInitialNodes", "onRemoveNode", "_onRemoveNode", "from", "pickle", "nodes", "edges", "JSON", "parse", "initialize", "Promise", "Object", "keys", "_nodes", "graph", "addExtension", "Array", "isArray", "forEach", "ext", "removeExtension", "destroy", "clear", "explore", "root", "visitor", "path", "includes", "isNode", "yieldOrContinue", "shouldContinue", "values", "flatMap", "properties", "n", "nodeId", "set", "effect", "err", "log", "catch", "error", "_addNodes", "nodesRelation", "nodesType", "first", "previous", "has", "ids", "removed", "_removeEdges", "target", "source", "_addEdges", "_sortEdges", "delete"]
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"inputs":{"packages/sdk/app-graph/src/node.ts":{"bytes":5363,"imports":[],"format":"esm"},"packages/sdk/app-graph/src/graph.ts":{"bytes":59394,"imports":[{"path":"@preact/signals-core","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"packages/sdk/app-graph/src/node.ts","kind":"import-statement","original":"./node"}],"format":"esm"},"packages/sdk/app-graph/src/graph-builder.ts":{"bytes":46212,"imports":[{"path":"@preact/signals-core","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"packages/sdk/app-graph/src/graph.ts","kind":"import-statement","original":"./graph"},{"path":"packages/sdk/app-graph/src/node.ts","kind":"import-statement","original":"./node"},{"path":"main-thread-scheduling","kind":"dynamic-import","external":true}],"format":"esm"},"packages/sdk/app-graph/src/index.ts":{"bytes":672,"imports":[{"path":"packages/sdk/app-graph/src/graph.ts","kind":"import-statement","original":"./graph"},{"path":"packages/sdk/app-graph/src/graph-builder.ts","kind":"import-statement","original":"./graph-builder"},{"path":"packages/sdk/app-graph/src/node.ts","kind":"import-statement","original":"./node"}],"format":"esm"}},"outputs":{"packages/sdk/app-graph/dist/lib/node-esm/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":55803},"packages/sdk/app-graph/dist/lib/node-esm/index.mjs":{"imports":[{"path":"@preact/signals-core","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"@preact/signals-core","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"main-thread-scheduling","kind":"dynamic-import","external":true}],"exports":["ACTION_GROUP_TYPE","ACTION_TYPE","Graph","GraphBuilder","ROOT_ID","ROOT_TYPE","actionGroupSymbol","cleanup","createExtension","getGraph","isAction","isActionGroup","isActionLike","isGraphNode","memoize","toSignal"],"entryPoint":"packages/sdk/app-graph/src/index.ts","inputs":{"packages/sdk/app-graph/src/graph.ts":{"bytesInOutput":14502},"packages/sdk/app-graph/src/node.ts":{"bytesInOutput":477},"packages/sdk/app-graph/src/index.ts":{"bytesInOutput":0},"packages/sdk/app-graph/src/graph-builder.ts":{"bytesInOutput":9707}},"bytes":25222}}}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type MaybePromise } from '@dxos/util';
|
|
2
|
-
import { Graph } from './graph';
|
|
2
|
+
import { Graph, type GraphParams } from './graph';
|
|
3
3
|
import { type Relation, type NodeArg, type Node, type ActionData, actionGroupSymbol } from './node';
|
|
4
4
|
/**
|
|
5
5
|
* Graph builder extension for adding nodes to the graph based on just the node id.
|
|
@@ -94,7 +94,13 @@ export declare class GraphBuilder {
|
|
|
94
94
|
private readonly _connectorSubscriptions;
|
|
95
95
|
private readonly _nodeChanged;
|
|
96
96
|
private _graph;
|
|
97
|
-
constructor();
|
|
97
|
+
constructor(params?: Pick<GraphParams, 'nodes' | 'edges'>);
|
|
98
|
+
static from(pickle?: string): GraphBuilder;
|
|
99
|
+
/**
|
|
100
|
+
* If graph is being restored from a pickle, the data will be null.
|
|
101
|
+
* Initialize the data of each node by calling resolvers.
|
|
102
|
+
*/
|
|
103
|
+
initialize(): Promise<void[]>;
|
|
98
104
|
get graph(): Graph;
|
|
99
105
|
/**
|
|
100
106
|
* Register a node builder which will be called in order to construct the graph.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graph-builder.d.ts","sourceRoot":"","sources":["../../../src/graph-builder.ts"],"names":[],"mappings":"AAUA,OAAO,EAAU,KAAK,YAAY,EAAe,MAAM,YAAY,CAAC;AAEpE,OAAO,EAAkC,KAAK,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"graph-builder.d.ts","sourceRoot":"","sources":["../../../src/graph-builder.ts"],"names":[],"mappings":"AAUA,OAAO,EAAU,KAAK,YAAY,EAAe,MAAM,YAAY,CAAC;AAEpE,OAAO,EAAkC,KAAK,EAAE,KAAK,WAAW,EAAE,MAAM,SAAS,CAAC;AAClF,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,OAAO,EAAE,KAAK,IAAI,EAAE,KAAK,UAAU,EAAE,iBAAiB,EAAE,MAAM,QAAQ,CAAC;AAEpG;;;;;GAKG;AACH,MAAM,MAAM,iBAAiB,GAAG,CAAC,MAAM,EAAE;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,KAAK,OAAO,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC;AAErF;;;;GAIG;AACH,MAAM,MAAM,kBAAkB,CAAC,CAAC,GAAG,GAAG,IAAI,CAAC,MAAM,EAAE;IAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,CAAA;CAAE,KAAK,OAAO,CAAC,GAAG,CAAC,EAAE,GAAG,SAAS,CAAC;AAEpG;;GAEG;AACH,MAAM,MAAM,gBAAgB,CAAC,CAAC,GAAG,GAAG,IAAI,CAAC,MAAM,EAAE;IAC/C,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;CACf,KAAK,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,OAAO,CAAC,EAAE,GAAG,SAAS,CAAC;AAE1E;;GAEG;AACH,MAAM,MAAM,qBAAqB,CAAC,CAAC,GAAG,GAA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WAAW,EAAE,OAAO,GAAG,OAAO,CAAM;IAS7D,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,MAAM;IAS3B;;;OAGG;IACG,UAAU;IAIhB,IAAI,KAAK,UAER;IAED;;OAEG;IACH,YAAY,CAAC,SAAS,EAAE,YAAY,GAAG,YAAY;IAWnD;;OAEG;IACH,eAAe,CAAC,EAAE,EAAE,MAAM,GAAG,YAAY;IAKzC,OAAO;IAQP;;OAEG;IACG,OAAO,CACX,EAAE,IAAuB,EAAE,QAAqB,EAAE,OAAO,EAAE,EAAE,2BAA2B,EACxF,IAAI,GAAE,MAAM,EAAO;YAyCP,cAAc;YAmCd,eAAe;YAyEf,aAAa;CAM5B"}
|
|
@@ -34,6 +34,13 @@ export type GraphTraversalOptions = {
|
|
|
34
34
|
*/
|
|
35
35
|
expansion?: boolean;
|
|
36
36
|
};
|
|
37
|
+
export type GraphParams = {
|
|
38
|
+
nodes?: Omit<Node, 'data'>[];
|
|
39
|
+
edges?: Record<string, string[]>;
|
|
40
|
+
onInitialNode?: Graph['_onInitialNode'];
|
|
41
|
+
onInitialNodes?: Graph['_onInitialNodes'];
|
|
42
|
+
onRemoveNode?: Graph['_onRemoveNode'];
|
|
43
|
+
};
|
|
37
44
|
/**
|
|
38
45
|
* The Graph represents the structure of the application constructed via plugins.
|
|
39
46
|
*/
|
|
@@ -43,11 +50,8 @@ export declare class Graph {
|
|
|
43
50
|
private readonly _onRemoveNode?;
|
|
44
51
|
private readonly _waitingForNodes;
|
|
45
52
|
private readonly _initialized;
|
|
46
|
-
constructor({ onInitialNode, onInitialNodes, onRemoveNode
|
|
47
|
-
|
|
48
|
-
onInitialNodes?: Graph['_onInitialNodes'];
|
|
49
|
-
onRemoveNode?: Graph['_onRemoveNode'];
|
|
50
|
-
});
|
|
53
|
+
constructor({ nodes, edges, onInitialNode, onInitialNodes, onRemoveNode }?: GraphParams);
|
|
54
|
+
static from(pickle: string, options?: Omit<GraphParams, 'nodes' | 'edges'>): Graph;
|
|
51
55
|
/**
|
|
52
56
|
* Alias for `findNode('root')`.
|
|
53
57
|
*/
|
|
@@ -64,13 +68,14 @@ export declare class Graph {
|
|
|
64
68
|
id?: string;
|
|
65
69
|
maxLength?: number;
|
|
66
70
|
}): any;
|
|
71
|
+
pickle(): string;
|
|
67
72
|
/**
|
|
68
73
|
* Find the node with the given id in the graph.
|
|
69
74
|
*
|
|
70
75
|
* If a node is not found within the graph and an `onInitialNode` callback is provided,
|
|
71
76
|
* it is called with the id and type of the node, potentially initializing the node.
|
|
72
77
|
*/
|
|
73
|
-
findNode(id: string): Node | undefined;
|
|
78
|
+
findNode(id: string, expansion?: boolean): Node | undefined;
|
|
74
79
|
/**
|
|
75
80
|
* Wait for a node to be added to the graph.
|
|
76
81
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graph.d.ts","sourceRoot":"","sources":["../../../src/graph.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"graph.d.ts","sourceRoot":"","sources":["../../../src/graph.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,IAAI,EAAgB,KAAK,UAAU,EAAmC,MAAM,QAAQ,CAAC;AAMlH,eAAO,MAAM,QAAQ,SAAU,IAAI,KAAG,KAIrC,CAAC;AAEF,eAAO,MAAM,OAAO,SAAS,CAAC;AAC9B,eAAO,MAAM,SAAS,4BAA4B,CAAC;AACnD,eAAO,MAAM,WAAW,8BAA8B,CAAC;AACvD,eAAO,MAAM,iBAAiB,mCAAmC,CAAC;AAElE,MAAM,MAAM,YAAY,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,IAAI;IACvF,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,MAAM,CAAC,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAC1B,SAA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E,SAAS,EAAE,EAAE,qBAAqB,EACtF,WAAW,GAAE,MAAM,EAAO;IAkB5B;;OAEG;IACH,OAAO,CAAC,EAAE,MAAe,EAAE,MAAM,EAAE,EAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,GAAG,MAAM,EAAE,GAAG,SAAS;IAkC/F,OAAO,CAAC,QAAQ;IAgEhB,OAAO,CAAC,WAAW;IAwCnB,OAAO,CAAC,QAAQ;IA6BhB,OAAO,CAAC,WAAW;IAiCnB;;;;;;;;;OASG;IACH,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE;IAa9D,OAAO,CAAC,cAAc,CAEpB;IAEF,OAAO,CAAC,SAAS;CAyBlB"}
|
|
@@ -2,8 +2,8 @@ import '@dxos-theme';
|
|
|
2
2
|
import React from 'react';
|
|
3
3
|
declare const _default: {
|
|
4
4
|
title: string;
|
|
5
|
-
decorators: import("@storybook/react/*").Decorator[];
|
|
6
5
|
render: () => React.JSX.Element;
|
|
6
|
+
decorators: import("@storybook/react/*").Decorator[];
|
|
7
7
|
};
|
|
8
8
|
export default _default;
|
|
9
9
|
export declare const Default: {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EchoGraph.stories.d.ts","sourceRoot":"","sources":["../../../../src/stories/EchoGraph.stories.tsx"],"names":[],"mappings":"AAIA,OAAO,aAAa,CAAC;AAGrB,OAAO,KAA8B,MAAM,OAAO,CAAC;;;;;;
|
|
1
|
+
{"version":3,"file":"EchoGraph.stories.d.ts","sourceRoot":"","sources":["../../../../src/stories/EchoGraph.stories.tsx"],"names":[],"mappings":"AAIA,OAAO,aAAa,CAAC;AAGrB,OAAO,KAA8B,MAAM,OAAO,CAAC;;;;;;AAoPnD,wBAaE;AAEF,eAAO,MAAM,OAAO,IAAK,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/app-graph",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.14-main.1366248",
|
|
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",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"author": "DXOS.org",
|
|
9
|
+
"sideEffects": true,
|
|
9
10
|
"exports": {
|
|
10
11
|
".": {
|
|
12
|
+
"types": "./dist/types/src/index.d.ts",
|
|
11
13
|
"browser": "./dist/lib/browser/index.mjs",
|
|
12
|
-
"node":
|
|
13
|
-
"default": "./dist/lib/node/index.cjs"
|
|
14
|
-
},
|
|
15
|
-
"types": "./dist/types/src/index.d.ts"
|
|
14
|
+
"node": "./dist/lib/node-esm/index.mjs"
|
|
16
15
|
}
|
|
17
16
|
},
|
|
18
17
|
"types": "dist/types/src/index.d.ts",
|
|
@@ -26,13 +25,13 @@
|
|
|
26
25
|
"dependencies": {
|
|
27
26
|
"@preact/signals-core": "^1.6.0",
|
|
28
27
|
"main-thread-scheduling": "^14.1.1",
|
|
29
|
-
"@dxos/debug": "0.6.
|
|
30
|
-
"@dxos/
|
|
31
|
-
"@dxos/
|
|
32
|
-
"@dxos/echo-signals": "0.6.
|
|
33
|
-
"@dxos/
|
|
34
|
-
"@dxos/
|
|
35
|
-
"@dxos/util": "0.6.
|
|
28
|
+
"@dxos/debug": "0.6.14-main.1366248",
|
|
29
|
+
"@dxos/echo-schema": "0.6.14-main.1366248",
|
|
30
|
+
"@dxos/async": "0.6.14-main.1366248",
|
|
31
|
+
"@dxos/echo-signals": "0.6.14-main.1366248",
|
|
32
|
+
"@dxos/log": "0.6.14-main.1366248",
|
|
33
|
+
"@dxos/invariant": "0.6.14-main.1366248",
|
|
34
|
+
"@dxos/util": "0.6.14-main.1366248"
|
|
36
35
|
},
|
|
37
36
|
"devDependencies": {
|
|
38
37
|
"@phosphor-icons/react": "^2.1.5",
|
|
@@ -40,16 +39,19 @@
|
|
|
40
39
|
"@types/react-dom": "~18.2.0",
|
|
41
40
|
"react": "~18.2.0",
|
|
42
41
|
"react-dom": "~18.2.0",
|
|
43
|
-
"vite": "
|
|
44
|
-
"@dxos/random": "0.6.
|
|
45
|
-
"@dxos/react-client": "0.6.
|
|
46
|
-
"@dxos/react-ui": "0.6.
|
|
47
|
-
"@dxos/
|
|
48
|
-
"@dxos/
|
|
42
|
+
"vite": "5.4.7",
|
|
43
|
+
"@dxos/random": "0.6.14-main.1366248",
|
|
44
|
+
"@dxos/react-client": "0.6.14-main.1366248",
|
|
45
|
+
"@dxos/react-ui-theme": "0.6.14-main.1366248",
|
|
46
|
+
"@dxos/storybook-utils": "0.6.14-main.1366248",
|
|
47
|
+
"@dxos/react-ui": "0.6.14-main.1366248"
|
|
49
48
|
},
|
|
50
49
|
"peerDependencies": {
|
|
51
|
-
"react": "^
|
|
52
|
-
"react
|
|
50
|
+
"@phosphor-icons/react": "^2.1.5",
|
|
51
|
+
"react": "~18.2.0",
|
|
52
|
+
"react-dom": "~18.2.0",
|
|
53
|
+
"@dxos/react-ui": "0.6.14-main.1366248",
|
|
54
|
+
"@dxos/react-ui-theme": "0.6.14-main.1366248"
|
|
53
55
|
},
|
|
54
56
|
"publishConfig": {
|
|
55
57
|
"access": "public"
|
|
@@ -3,17 +3,12 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { batch, signal } from '@preact/signals-core';
|
|
6
|
-
import
|
|
7
|
-
import chaiAsPromised from 'chai-as-promised';
|
|
6
|
+
import { describe, expect, test } from 'vitest';
|
|
8
7
|
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
import { ACTION_TYPE } from './graph';
|
|
8
|
+
import { ACTION_TYPE, ROOT_ID, ROOT_TYPE } from './graph';
|
|
12
9
|
import { GraphBuilder, createExtension, memoize } from './graph-builder';
|
|
13
10
|
import { type Node } from './node';
|
|
14
11
|
|
|
15
|
-
chai.use(chaiAsPromised);
|
|
16
|
-
|
|
17
12
|
const exampleId = (id: number) => `dx:test:${id}`;
|
|
18
13
|
const EXAMPLE_ID = exampleId(1);
|
|
19
14
|
const EXAMPLE_TYPE = 'dxos.org/type/example';
|
|
@@ -89,6 +84,44 @@ describe('GraphBuilder', () => {
|
|
|
89
84
|
expect(count).to.equal(4);
|
|
90
85
|
expect(memoizedCount).to.equal(1);
|
|
91
86
|
});
|
|
87
|
+
|
|
88
|
+
test('resolving pickled graph', async () => {
|
|
89
|
+
const pickle =
|
|
90
|
+
'{"nodes":[{"id":"root","type":"dxos.org/type/GraphRoot","properties":{}},{"id":"test1","type":"test","properties":{"value":1}},{"id":"test2","type":"test","properties":{"value":2}}],"edges":{"root":["test1","test2"],"test1":["test2"],"test2":[]}}';
|
|
91
|
+
const builder = GraphBuilder.from(pickle);
|
|
92
|
+
const graph = builder.graph;
|
|
93
|
+
|
|
94
|
+
builder.addExtension(
|
|
95
|
+
createExtension({
|
|
96
|
+
id: 'resolver',
|
|
97
|
+
resolver: ({ id }) => {
|
|
98
|
+
if (id === ROOT_ID) {
|
|
99
|
+
return { id: ROOT_ID, type: ROOT_TYPE };
|
|
100
|
+
} else {
|
|
101
|
+
return { id, type: EXAMPLE_TYPE, data: id, properties: { value: parseInt(id.replace('test', '')) } };
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
}),
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
{
|
|
108
|
+
expect(graph.findNode('test1', false)).toBeDefined();
|
|
109
|
+
expect(graph.findNode('test1', false)?.data).to.equal(null);
|
|
110
|
+
expect(graph.findNode('test1', false)?.properties.value).to.equal(1);
|
|
111
|
+
expect(graph.findNode('test2', false)).toBeDefined();
|
|
112
|
+
expect(graph.findNode('test2', false)?.data).to.equal(null);
|
|
113
|
+
expect(graph.findNode('test2', false)?.properties.value).to.equal(2);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
await builder.initialize();
|
|
117
|
+
|
|
118
|
+
{
|
|
119
|
+
expect(graph.findNode('test1', false)?.data).to.equal('test1');
|
|
120
|
+
expect(graph.findNode('test1', false)?.properties.value).to.equal(1);
|
|
121
|
+
expect(graph.findNode('test2', false)?.data).to.equal('test2');
|
|
122
|
+
expect(graph.findNode('test2', false)?.properties.value).to.equal(2);
|
|
123
|
+
}
|
|
124
|
+
});
|
|
92
125
|
});
|
|
93
126
|
|
|
94
127
|
describe('connector', () => {
|
|
@@ -259,7 +292,7 @@ describe('GraphBuilder', () => {
|
|
|
259
292
|
expect(actions?.[0].id).to.equal('action');
|
|
260
293
|
expect(actions?.[0].type).to.equal(ACTION_TYPE);
|
|
261
294
|
|
|
262
|
-
await expect(graph.waitForNode('not-action', 10)).
|
|
295
|
+
await expect(graph.waitForNode('not-action', 10)).rejects.toBeInstanceOf(Error);
|
|
263
296
|
|
|
264
297
|
await graph.expand(graph.root);
|
|
265
298
|
const nodes = graph.nodes(graph.root);
|
package/src/graph-builder.ts
CHANGED
|
@@ -10,7 +10,7 @@ import { invariant } from '@dxos/invariant';
|
|
|
10
10
|
import { log } from '@dxos/log';
|
|
11
11
|
import { isNode, type MaybePromise, nonNullable } from '@dxos/util';
|
|
12
12
|
|
|
13
|
-
import { ACTION_GROUP_TYPE, ACTION_TYPE, Graph } from './graph';
|
|
13
|
+
import { ACTION_GROUP_TYPE, ACTION_TYPE, Graph, type GraphParams } from './graph';
|
|
14
14
|
import { type Relation, type NodeArg, type Node, type ActionData, actionGroupSymbol } from './node';
|
|
15
15
|
|
|
16
16
|
/**
|
|
@@ -192,14 +192,32 @@ export class GraphBuilder {
|
|
|
192
192
|
private readonly _nodeChanged: Record<string, Signal<{}>> = {};
|
|
193
193
|
private _graph: Graph;
|
|
194
194
|
|
|
195
|
-
constructor() {
|
|
195
|
+
constructor(params: Pick<GraphParams, 'nodes' | 'edges'> = {}) {
|
|
196
196
|
this._graph = new Graph({
|
|
197
|
+
...params,
|
|
197
198
|
onInitialNode: (id) => this._onInitialNode(id),
|
|
198
199
|
onInitialNodes: (node, relation, type) => this._onInitialNodes(node, relation, type),
|
|
199
200
|
onRemoveNode: (id) => this._onRemoveNode(id),
|
|
200
201
|
});
|
|
201
202
|
}
|
|
202
203
|
|
|
204
|
+
static from(pickle?: string) {
|
|
205
|
+
if (!pickle) {
|
|
206
|
+
return new GraphBuilder();
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
const { nodes, edges } = JSON.parse(pickle);
|
|
210
|
+
return new GraphBuilder({ nodes, edges });
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* If graph is being restored from a pickle, the data will be null.
|
|
215
|
+
* Initialize the data of each node by calling resolvers.
|
|
216
|
+
*/
|
|
217
|
+
async initialize() {
|
|
218
|
+
return Promise.all(Object.keys(this._graph._nodes).map((id) => this._onInitialNode(id)));
|
|
219
|
+
}
|
|
220
|
+
|
|
203
221
|
get graph() {
|
|
204
222
|
return this._graph;
|
|
205
223
|
}
|
package/src/graph.test.ts
CHANGED
|
@@ -3,15 +3,16 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { effect } from '@preact/signals-core';
|
|
6
|
-
import { expect } from '
|
|
6
|
+
import { describe, expect, test } from 'vitest';
|
|
7
7
|
|
|
8
8
|
import { updateCounter } from '@dxos/echo-schema/testing';
|
|
9
|
-
import {
|
|
10
|
-
import { describe, test } from '@dxos/test';
|
|
9
|
+
import { registerSignalsRuntime } from '@dxos/echo-signals';
|
|
11
10
|
|
|
12
11
|
import { Graph, ROOT_ID, ROOT_TYPE, getGraph } from './graph';
|
|
13
12
|
import { type Node, type NodeFilter } from './node';
|
|
14
13
|
|
|
14
|
+
registerSignalsRuntime();
|
|
15
|
+
|
|
15
16
|
const longestPaths = new Map<string, string[]>();
|
|
16
17
|
|
|
17
18
|
const filterLongestPath: NodeFilter = (node, connectedNode): node is Node => {
|
|
@@ -248,8 +249,14 @@ describe('Graph', () => {
|
|
|
248
249
|
});
|
|
249
250
|
});
|
|
250
251
|
|
|
252
|
+
test('pickle', () => {
|
|
253
|
+
const pickle =
|
|
254
|
+
'{"nodes":[{"id":"root","type":"dxos.org/type/GraphRoot","properties":{}},{"id":"test1","type":"test","properties":{"value":1}},{"id":"test2","type":"test","properties":{"value":2}}],"edges":{"root":["test1","test2"],"test1":["test2"],"test2":[]}}';
|
|
255
|
+
const graph = Graph.from(pickle);
|
|
256
|
+
expect(graph.pickle()).to.equal(pickle);
|
|
257
|
+
});
|
|
258
|
+
|
|
251
259
|
test('waitForNode', async () => {
|
|
252
|
-
registerSignalRuntime();
|
|
253
260
|
const graph = new Graph();
|
|
254
261
|
const promise = graph.waitForNode('test1');
|
|
255
262
|
graph._addNodes([{ id: 'test1', type: 'test', data: 1 }]);
|
|
@@ -259,7 +266,6 @@ describe('Graph', () => {
|
|
|
259
266
|
});
|
|
260
267
|
|
|
261
268
|
test('updates are constrained on data', () => {
|
|
262
|
-
registerSignalRuntime();
|
|
263
269
|
const graph = new Graph();
|
|
264
270
|
const [node1] = graph._addNodes([{ id: 'test1', type: 'test', data: 1 }]);
|
|
265
271
|
using updates = updateCounter(() => {
|
|
@@ -275,7 +281,6 @@ describe('Graph', () => {
|
|
|
275
281
|
});
|
|
276
282
|
|
|
277
283
|
test('updates are constrained on properties', () => {
|
|
278
|
-
registerSignalRuntime();
|
|
279
284
|
const graph = new Graph();
|
|
280
285
|
const [node1] = graph._addNodes([{ id: 'test1', type: 'test', properties: { value: 1 } }]);
|
|
281
286
|
using updates = updateCounter(() => {
|
|
@@ -289,7 +294,6 @@ describe('Graph', () => {
|
|
|
289
294
|
});
|
|
290
295
|
|
|
291
296
|
test('updates are constrained on connected nodes', () => {
|
|
292
|
-
registerSignalRuntime();
|
|
293
297
|
const graph = new Graph();
|
|
294
298
|
const [node1] = graph._addNodes([{ id: 'test1', type: 'test', properties: { value: 1 } }]);
|
|
295
299
|
using updates = updateCounter(() => {
|
|
@@ -469,7 +473,6 @@ describe('Graph', () => {
|
|
|
469
473
|
});
|
|
470
474
|
|
|
471
475
|
test('traversing the graph subscribes to changes', () => {
|
|
472
|
-
registerSignalRuntime();
|
|
473
476
|
const graph = new Graph();
|
|
474
477
|
|
|
475
478
|
graph._addNodes([
|
|
@@ -542,7 +545,6 @@ describe('Graph', () => {
|
|
|
542
545
|
});
|
|
543
546
|
|
|
544
547
|
test('traversal can be reactive', async () => {
|
|
545
|
-
registerSignalRuntime();
|
|
546
548
|
const graph = new Graph();
|
|
547
549
|
const latest: Record<string, any> = {};
|
|
548
550
|
const updates: Record<string, number> = {};
|