@dxos/app-graph 0.3.3-main.052ad73

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.
Files changed (40) hide show
  1. package/LICENSE +8 -0
  2. package/README.md +13 -0
  3. package/dist/lib/browser/index.mjs +252 -0
  4. package/dist/lib/browser/index.mjs.map +7 -0
  5. package/dist/lib/browser/meta.json +1 -0
  6. package/dist/lib/browser/testing.mjs +98 -0
  7. package/dist/lib/browser/testing.mjs.map +7 -0
  8. package/dist/lib/node/index.cjs +290 -0
  9. package/dist/lib/node/index.cjs.map +7 -0
  10. package/dist/lib/node/meta.json +1 -0
  11. package/dist/lib/node/testing.cjs +124 -0
  12. package/dist/lib/node/testing.cjs.map +7 -0
  13. package/dist/types/src/action.d.ts +53 -0
  14. package/dist/types/src/action.d.ts.map +1 -0
  15. package/dist/types/src/graph-builder.d.ts +31 -0
  16. package/dist/types/src/graph-builder.d.ts.map +1 -0
  17. package/dist/types/src/graph.d.ts +45 -0
  18. package/dist/types/src/graph.d.ts.map +1 -0
  19. package/dist/types/src/graph.test.d.ts +2 -0
  20. package/dist/types/src/graph.test.d.ts.map +1 -0
  21. package/dist/types/src/index.d.ts +5 -0
  22. package/dist/types/src/index.d.ts.map +1 -0
  23. package/dist/types/src/node.d.ts +71 -0
  24. package/dist/types/src/node.d.ts.map +1 -0
  25. package/dist/types/src/stories/EchoGraph.stories.d.ts +10 -0
  26. package/dist/types/src/stories/EchoGraph.stories.d.ts.map +1 -0
  27. package/dist/types/src/stories/Tree.d.ts +14 -0
  28. package/dist/types/src/stories/Tree.d.ts.map +1 -0
  29. package/dist/types/src/testing.d.ts +52 -0
  30. package/dist/types/src/testing.d.ts.map +1 -0
  31. package/package.json +74 -0
  32. package/src/action.ts +69 -0
  33. package/src/graph-builder.ts +200 -0
  34. package/src/graph.test.ts +220 -0
  35. package/src/graph.ts +110 -0
  36. package/src/index.ts +8 -0
  37. package/src/node.ts +101 -0
  38. package/src/stories/EchoGraph.stories.tsx +233 -0
  39. package/src/stories/Tree.tsx +79 -0
  40. package/src/testing.ts +152 -0
@@ -0,0 +1,290 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // packages/sdk/app-graph/src/index.ts
31
+ var src_exports = {};
32
+ __export(src_exports, {
33
+ Graph: () => Graph,
34
+ GraphBuilder: () => GraphBuilder
35
+ });
36
+ module.exports = __toCommonJS(src_exports);
37
+
38
+ // packages/sdk/app-graph/src/graph.ts
39
+ var import_react = require("deepsignal/react");
40
+ var import_lodash = __toESM(require("lodash.get"));
41
+ var Graph = class {
42
+ constructor(_root) {
43
+ this._root = _root;
44
+ this._index = (0, import_react.deepSignal)({});
45
+ }
46
+ toJSON() {
47
+ const toLabel = (label) => Array.isArray(label) ? `${label[1].ns}[${label[0]}]` : label;
48
+ const toJSON = (node) => {
49
+ return {
50
+ id: node.id.slice(0, 16),
51
+ label: toLabel(node.label),
52
+ children: node.children.length ? node.children.map((node2) => toJSON(node2)) : void 0,
53
+ actions: node.actions.length ? node.actions.map(({ id, label }) => ({
54
+ id,
55
+ label: toLabel(label)
56
+ })) : void 0
57
+ };
58
+ };
59
+ return toJSON(this._root);
60
+ }
61
+ /**
62
+ * The root node of the graph which is the entry point for all knowledge.
63
+ */
64
+ get root() {
65
+ return this._root;
66
+ }
67
+ /**
68
+ * Get the path through the graph from the root to the node with the given id.
69
+ */
70
+ getPath(id) {
71
+ return this._index[id];
72
+ }
73
+ /**
74
+ * @internal
75
+ */
76
+ _setPath(id, path) {
77
+ this._index[id] = path;
78
+ }
79
+ /**
80
+ * Find the node with the given id in the graph.
81
+ */
82
+ findNode(id) {
83
+ const path = this.getPath(id);
84
+ if (!path) {
85
+ return void 0;
86
+ }
87
+ return path.length > 0 ? (0, import_lodash.default)(this._root, path) : this._root;
88
+ }
89
+ /**
90
+ * Recursive breadth-first traversal.
91
+ */
92
+ traverse({ node = this._root, direction = "down", filter, visitor }, depth = 0) {
93
+ if (!filter || filter(node)) {
94
+ visitor?.(node);
95
+ }
96
+ if (direction === "down") {
97
+ Object.values(node.children).forEach((child) => this.traverse({
98
+ node: child,
99
+ filter,
100
+ visitor
101
+ }));
102
+ } else if (direction === "up" && node.parent) {
103
+ this.traverse({
104
+ node: node.parent,
105
+ direction,
106
+ filter,
107
+ visitor
108
+ }, depth + 1);
109
+ }
110
+ }
111
+ };
112
+
113
+ // packages/sdk/app-graph/src/graph-builder.ts
114
+ var import_signals_react = require("@preact/signals-react");
115
+ var import_react2 = require("deepsignal/react");
116
+ var import_mousetrap = __toESM(require("mousetrap"));
117
+ var import_async = require("@dxos/async");
118
+ var GraphBuilder = class {
119
+ constructor() {
120
+ this._nodeBuilders = /* @__PURE__ */ new Map();
121
+ this._unsubscribe = /* @__PURE__ */ new Map();
122
+ }
123
+ /**
124
+ * Register a node builder which will be called in order to construct the graph.
125
+ */
126
+ addNodeBuilder(id, builder) {
127
+ this._nodeBuilders.set(id, builder);
128
+ return this;
129
+ }
130
+ /**
131
+ * Remove a node builder from the graph builder.
132
+ */
133
+ removeNodeBuilder(id) {
134
+ this._nodeBuilders.delete(id);
135
+ return this;
136
+ }
137
+ /**
138
+ * Construct the graph, starting by calling all registered node builders on the root node.
139
+ * Node builders will be filtered out as they are used such that they are only used once on any given path.
140
+ * @param root
141
+ * @param path
142
+ */
143
+ build(root, path = []) {
144
+ const graph = new Graph(root ?? this._createNode(() => graph, {
145
+ id: "root",
146
+ label: "Root"
147
+ }));
148
+ return this._build(graph, graph.root, path);
149
+ }
150
+ /**
151
+ * Called recursively.
152
+ */
153
+ _build(graph, node, path = [], ignoreBuilders = []) {
154
+ graph._setPath(node.id, path);
155
+ const subscriptions = this._unsubscribe.get(node.id) ?? new import_async.EventSubscriptions();
156
+ subscriptions.clear();
157
+ Array.from(this._nodeBuilders.entries()).filter(([id]) => ignoreBuilders.findIndex((ignore) => ignore === id) === -1).forEach(([_, builder]) => {
158
+ const unsubscribe = builder(node);
159
+ unsubscribe && subscriptions.add(unsubscribe);
160
+ });
161
+ this._unsubscribe.set(node.id, subscriptions);
162
+ return graph;
163
+ }
164
+ _createNode(getGraph, partial, path = [], ignoreBuilders = []) {
165
+ const node = (0, import_react2.deepSignal)({
166
+ parent: null,
167
+ data: null,
168
+ properties: {},
169
+ childrenMap: {},
170
+ actionsMap: {},
171
+ // TODO(burdon): Document.
172
+ ...partial,
173
+ // TODO(wittjosiah): Default sort.
174
+ get children() {
175
+ return Object.values(node.childrenMap);
176
+ },
177
+ get actions() {
178
+ return Object.values(node.actionsMap);
179
+ },
180
+ addProperty: (key, value) => {
181
+ (0, import_signals_react.untracked)(() => {
182
+ node.properties[key] = value;
183
+ });
184
+ },
185
+ removeProperty: (key) => {
186
+ (0, import_signals_react.untracked)(() => {
187
+ delete node.properties[key];
188
+ });
189
+ },
190
+ addNode: (builder, ...partials) => {
191
+ return (0, import_signals_react.untracked)(() => {
192
+ return partials.map((partial2) => {
193
+ const builders = [
194
+ ...ignoreBuilders,
195
+ builder
196
+ ];
197
+ const childPath = [
198
+ ...path,
199
+ "childrenMap",
200
+ partial2.id
201
+ ];
202
+ const child = this._createNode(getGraph, {
203
+ ...partial2,
204
+ parent: node
205
+ }, childPath, builders);
206
+ node.childrenMap[child.id] = child;
207
+ this._build(getGraph(), child, childPath, builders);
208
+ return child;
209
+ });
210
+ });
211
+ },
212
+ removeNode: (id) => {
213
+ return (0, import_signals_react.untracked)(() => {
214
+ const child = node.childrenMap[id];
215
+ delete node.childrenMap[id];
216
+ return child;
217
+ });
218
+ },
219
+ addAction: (...partials) => {
220
+ return (0, import_signals_react.untracked)(() => {
221
+ return partials.map((partial2) => {
222
+ const action = this._createAction(partial2);
223
+ if (action.keyBinding) {
224
+ import_mousetrap.default.bind(action.keyBinding, () => {
225
+ action.invoke();
226
+ });
227
+ }
228
+ node.actionsMap[action.id] = action;
229
+ return action;
230
+ });
231
+ });
232
+ },
233
+ removeAction: (id) => {
234
+ return (0, import_signals_react.untracked)(() => {
235
+ const action = node.actionsMap[id];
236
+ if (action.keyBinding) {
237
+ import_mousetrap.default.unbind(action.keyBinding);
238
+ }
239
+ delete node.actionsMap[id];
240
+ return action;
241
+ });
242
+ }
243
+ });
244
+ return node;
245
+ }
246
+ _createAction(partial) {
247
+ const action = (0, import_react2.deepSignal)({
248
+ properties: {},
249
+ actionsMap: {},
250
+ ...partial,
251
+ // TODO(wittjosiah): Default sort.
252
+ get actions() {
253
+ return Object.values(action.actionsMap);
254
+ },
255
+ addAction: (...partials) => {
256
+ return (0, import_signals_react.untracked)(() => {
257
+ return partials.map((partial2) => {
258
+ const subAction = this._createAction(partial2);
259
+ action.actionsMap[subAction.id] = subAction;
260
+ return subAction;
261
+ });
262
+ });
263
+ },
264
+ removeAction: (id) => {
265
+ return (0, import_signals_react.untracked)(() => {
266
+ const subAction = action.actionsMap[id];
267
+ delete action.actionsMap[id];
268
+ return subAction;
269
+ });
270
+ },
271
+ addProperty: (key, value) => {
272
+ return (0, import_signals_react.untracked)(() => {
273
+ action.properties[key] = value;
274
+ });
275
+ },
276
+ removeProperty: (key) => {
277
+ return (0, import_signals_react.untracked)(() => {
278
+ delete action.properties[key];
279
+ });
280
+ }
281
+ });
282
+ return action;
283
+ }
284
+ };
285
+ // Annotate the CommonJS export names for ESM import in node:
286
+ 0 && (module.exports = {
287
+ Graph,
288
+ GraphBuilder
289
+ });
290
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/index.ts", "../../../src/graph.ts", "../../../src/graph-builder.ts"],
4
+ "sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nexport * from './action';\nexport * from './graph';\nexport * from './graph-builder';\nexport * from './node';\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { deepSignal } from 'deepsignal/react';\n// TODO(wittjosiah): Remove lodash dependency.\nimport get from 'lodash.get';\n\nimport { type Label } from './action';\nimport { type Node } from './node';\n\nexport type TraversalOptions = {\n /**\n * The node to start traversing from. Defaults to the root node.\n */\n node?: Node;\n\n /**\n * The direction to traverse the graph. Defaults to 'down'.\n */\n direction?: 'up' | 'down';\n\n /**\n * A predicate to filter nodes which are passed to the `visitor` callback.\n */\n filter?: (node: Node) => boolean;\n\n /**\n * A callback which is called for each node visited during traversal.\n */\n visitor?: (node: Node) => void;\n};\n\n/**\n * The Graph represents...\n */\nexport class Graph {\n // TODO(burdon): Document.\n // TODO(wittjosiah): Should this support multiple paths to the same node?\n private readonly _index = deepSignal<{ [key: string]: string[] }>({});\n\n constructor(private readonly _root: Node) {}\n\n toJSON() {\n const toLabel = (label: Label) => (Array.isArray(label) ? `${label[1].ns}[${label[0]}]` : label);\n const toJSON = (node: Node): any => {\n return {\n id: node.id.slice(0, 16),\n label: toLabel(node.label),\n children: node.children.length ? node.children.map((node) => toJSON(node)) : undefined,\n actions: node.actions.length\n ? node.actions.map(({ id, label }) => ({\n id,\n label: toLabel(label),\n }))\n : undefined,\n };\n };\n\n return toJSON(this._root);\n }\n\n /**\n * The root node of the graph which is the entry point for all knowledge.\n */\n get root(): Node {\n return this._root;\n }\n\n /**\n * Get the path through the graph from the root to the node with the given id.\n */\n getPath(id: string): string[] | undefined {\n return this._index[id];\n }\n\n /**\n * @internal\n */\n _setPath(id: string, path: string[]) {\n this._index[id] = path;\n }\n\n /**\n * Find the node with the given id in the graph.\n */\n findNode(id: string): Node | undefined {\n const path = this.getPath(id);\n if (!path) {\n return undefined;\n }\n\n return path.length > 0 ? get(this._root, path) : this._root;\n }\n\n /**\n * Recursive breadth-first traversal.\n */\n traverse({ node = this._root, direction = 'down', filter, visitor }: TraversalOptions, depth = 0): void {\n if (!filter || filter(node)) {\n visitor?.(node);\n }\n\n if (direction === 'down') {\n Object.values(node.children).forEach((child) => this.traverse({ node: child, filter, visitor }));\n } else if (direction === 'up' && node.parent) {\n this.traverse({ node: node.parent, direction, filter, visitor }, depth + 1);\n }\n }\n}\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { untracked } from '@preact/signals-react';\nimport { type RevertDeepSignal, deepSignal } from 'deepsignal/react';\nimport Mousetrap from 'mousetrap';\n\nimport { EventSubscriptions } from '@dxos/async';\n\nimport { type Action } from './action';\nimport { Graph } from './graph';\nimport { type Node, type NodeBuilder } from './node';\n\n/**\n * The builder...\n */\nexport class GraphBuilder {\n private readonly _nodeBuilders = new Map<string, NodeBuilder>();\n private readonly _unsubscribe = new Map<string, EventSubscriptions>();\n\n /**\n * Register a node builder which will be called in order to construct the graph.\n */\n addNodeBuilder(id: string, builder: NodeBuilder): GraphBuilder {\n this._nodeBuilders.set(id, builder);\n return this;\n }\n\n /**\n * Remove a node builder from the graph builder.\n */\n removeNodeBuilder(id: string): GraphBuilder {\n this._nodeBuilders.delete(id);\n return this;\n }\n\n /**\n * Construct the graph, starting by calling all registered node builders on the root node.\n * Node builders will be filtered out as they are used such that they are only used once on any given path.\n * @param root\n * @param path\n */\n build(root?: Node, path: string[] = []): Graph {\n const graph: Graph = new Graph(root ?? this._createNode(() => graph, { id: 'root', label: 'Root' }));\n return this._build(graph, graph.root, path);\n }\n\n /**\n * Called recursively.\n */\n private _build(graph: Graph, node: Node, path: string[] = [], ignoreBuilders: string[] = []): Graph {\n // TODO(wittjosiah): Should this support multiple paths to the same node?\n graph._setPath(node.id, path);\n\n // TODO(burdon): Document.\n const subscriptions = this._unsubscribe.get(node.id) ?? new EventSubscriptions();\n subscriptions.clear();\n\n Array.from(this._nodeBuilders.entries())\n .filter(([id]) => ignoreBuilders.findIndex((ignore) => ignore === id) === -1)\n .forEach(([_, builder]) => {\n const unsubscribe = builder(node);\n unsubscribe && subscriptions.add(unsubscribe);\n });\n\n this._unsubscribe.set(node.id, subscriptions);\n\n return graph;\n }\n\n private _createNode<TData = null, TProperties extends Record<string, any> = Record<string, any>>(\n getGraph: () => Graph,\n partial: Pick<Node, 'id' | 'label'> & Partial<Node<TData, TProperties>>,\n path: string[] = [],\n ignoreBuilders: string[] = [],\n ): Node<TData, TProperties> {\n // TODO(burdon): Document implications and rationale of deepSignal.\n const node: Node<TData, TProperties> = deepSignal({\n parent: null,\n data: null as TData, // TODO(burdon): Allow null property?\n properties: {} as TProperties,\n childrenMap: {},\n actionsMap: {},\n // TODO(burdon): Document.\n ...partial,\n\n // TODO(wittjosiah): Default sort.\n get children() {\n return Object.values(node.childrenMap);\n },\n get actions() {\n return Object.values(node.actionsMap);\n },\n\n addProperty: (key, value) => {\n untracked(() => {\n (node.properties as Record<string, any>)[key] = value;\n });\n },\n removeProperty: (key) => {\n untracked(() => {\n delete (node.properties as Record<string, any>)[key];\n });\n },\n\n addNode: (builder, ...partials) => {\n return untracked(() => {\n return partials.map((partial) => {\n const builders = [...ignoreBuilders, builder];\n const childPath = [...path, 'childrenMap', partial.id];\n const child = this._createNode(getGraph, { ...partial, parent: node }, childPath, builders);\n node.childrenMap[child.id] = child;\n // TOOD(burdon): Defer triggering recursive updates until task has completed.\n this._build(getGraph(), child, childPath, builders);\n return child;\n });\n });\n },\n removeNode: (id) => {\n return untracked(() => {\n const child = node.childrenMap[id];\n delete node.childrenMap[id];\n return child;\n });\n },\n\n addAction: (...partials) => {\n return untracked(() => {\n return partials.map((partial) => {\n const action = this._createAction(partial);\n if (action.keyBinding) {\n Mousetrap.bind(action.keyBinding, () => {\n action.invoke();\n });\n }\n\n node.actionsMap[action.id] = action;\n return action;\n });\n });\n },\n removeAction: (id) => {\n return untracked(() => {\n const action = node.actionsMap[id];\n if (action.keyBinding) {\n Mousetrap.unbind(action.keyBinding);\n }\n\n delete node.actionsMap[id];\n return action;\n });\n },\n }) as RevertDeepSignal<Node<TData, TProperties>>;\n\n return node;\n }\n\n private _createAction<TProperties extends Record<string, any> = Record<string, any>>(\n partial: Pick<Action, 'id' | 'label' | 'invoke'> & Partial<Action<TProperties>>,\n ): Action<TProperties> {\n const action: Action<TProperties> = deepSignal({\n properties: {} as TProperties,\n actionsMap: {},\n ...partial,\n // TODO(wittjosiah): Default sort.\n get actions() {\n return Object.values(action.actionsMap);\n },\n addAction: (...partials) => {\n return untracked(() => {\n return partials.map((partial) => {\n const subAction = this._createAction(partial);\n action.actionsMap[subAction.id] = subAction;\n return subAction;\n });\n });\n },\n removeAction: (id) => {\n return untracked(() => {\n const subAction = action.actionsMap[id];\n delete action.actionsMap[id];\n return subAction;\n });\n },\n addProperty: (key, value) => {\n return untracked(() => {\n (action.properties as Record<string, any>)[key] = value;\n });\n },\n removeProperty: (key) => {\n return untracked(() => {\n delete (action.properties as Record<string, any>)[key];\n });\n },\n }) as RevertDeepSignal<Action<TProperties>>;\n\n return action;\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;ACIA,mBAA2B;AAE3B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;AACf,gBAAMkB,YAAYR,OAAOlB,WAAWrC,EAAAA;AACpC,iBAAOuD,OAAOlB,WAAWrC,EAAAA;AACzB,iBAAO+D;QACT,CAAA;MACF;MACArB,aAAa,CAACC,KAAKC,UAAAA;AACjB,mBAAOC,gCAAU,MAAA;AACdU,iBAAOpB,WAAmCQ,GAAAA,IAAOC;QACpD,CAAA;MACF;MACAE,gBAAgB,CAACH,QAAAA;AACf,mBAAOE,gCAAU,MAAA;AACf,iBAAQU,OAAOpB,WAAmCQ,GAAAA;QACpD,CAAA;MACF;IACF,CAAA;AAEA,WAAOY;EACT;AACF;",
6
+ "names": ["Graph", "constructor", "_root", "_index", "deepSignal", "toJSON", "toLabel", "label", "Array", "isArray", "ns", "node", "id", "slice", "children", "length", "map", "undefined", "actions", "root", "getPath", "_setPath", "path", "findNode", "get", "traverse", "direction", "filter", "visitor", "depth", "Object", "values", "forEach", "child", "parent", "import_react", "GraphBuilder", "_nodeBuilders", "Map", "_unsubscribe", "addNodeBuilder", "id", "builder", "set", "removeNodeBuilder", "delete", "build", "root", "path", "graph", "Graph", "_createNode", "label", "_build", "node", "ignoreBuilders", "_setPath", "subscriptions", "get", "EventSubscriptions", "clear", "Array", "from", "entries", "filter", "findIndex", "ignore", "forEach", "_", "unsubscribe", "add", "getGraph", "partial", "deepSignal", "parent", "data", "properties", "childrenMap", "actionsMap", "children", "Object", "values", "actions", "addProperty", "key", "value", "untracked", "removeProperty", "addNode", "partials", "map", "builders", "childPath", "child", "removeNode", "addAction", "action", "_createAction", "keyBinding", "Mousetrap", "bind", "invoke", "removeAction", "unbind", "subAction"]
7
+ }
@@ -0,0 +1 @@
1
+ {"inputs":{"packages/sdk/app-graph/src/action.ts":{"bytes":2779,"imports":[],"format":"esm"},"packages/sdk/app-graph/src/graph.ts":{"bytes":9066,"imports":[{"path":"deepsignal/react","kind":"import-statement","external":true},{"path":"lodash.get","kind":"import-statement","external":true}],"format":"esm"},"packages/sdk/app-graph/src/graph-builder.ts":{"bytes":21055,"imports":[{"path":"@preact/signals-react","kind":"import-statement","external":true},{"path":"deepsignal/react","kind":"import-statement","external":true},{"path":"mousetrap","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"packages/sdk/app-graph/src/graph.ts","kind":"import-statement","original":"./graph"}],"format":"esm"},"packages/sdk/app-graph/src/node.ts":{"bytes":4185,"imports":[],"format":"esm"},"packages/sdk/app-graph/src/index.ts":{"bytes":722,"imports":[{"path":"packages/sdk/app-graph/src/action.ts","kind":"import-statement","original":"./action"},{"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"},"packages/sdk/app-graph/src/testing.ts":{"bytes":11884,"imports":[],"format":"esm"}},"outputs":{"packages/sdk/app-graph/dist/lib/node/index.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":15424},"packages/sdk/app-graph/dist/lib/node/index.cjs":{"imports":[{"path":"deepsignal/react","kind":"require-call","external":true},{"path":"lodash.get","kind":"require-call","external":true},{"path":"@preact/signals-react","kind":"require-call","external":true},{"path":"deepsignal/react","kind":"require-call","external":true},{"path":"mousetrap","kind":"require-call","external":true},{"path":"@dxos/async","kind":"require-call","external":true}],"exports":[],"entryPoint":"packages/sdk/app-graph/src/index.ts","inputs":{"packages/sdk/app-graph/src/index.ts":{"bytesInOutput":151},"packages/sdk/app-graph/src/graph.ts":{"bytesInOutput":1882},"packages/sdk/app-graph/src/graph-builder.ts":{"bytesInOutput":5381}},"bytes":9088},"packages/sdk/app-graph/dist/lib/node/testing.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":6196},"packages/sdk/app-graph/dist/lib/node/testing.cjs":{"imports":[],"exports":[],"entryPoint":"packages/sdk/app-graph/src/testing.ts","inputs":{"packages/sdk/app-graph/src/testing.ts":{"bytesInOutput":2371}},"bytes":3378}}}
@@ -0,0 +1,124 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // packages/sdk/app-graph/src/testing.ts
21
+ var testing_exports = {};
22
+ __export(testing_exports, {
23
+ buildGraph: () => buildGraph,
24
+ createTestNodeBuilder: () => createTestNodeBuilder
25
+ });
26
+ module.exports = __toCommonJS(testing_exports);
27
+ var createTestNodeBuilder = (id, depth = 1) => {
28
+ const nodes = /* @__PURE__ */ new Map();
29
+ const nodeBuilder = (parent) => {
30
+ if (checkDepth(parent) >= depth) {
31
+ return;
32
+ }
33
+ const [child] = parent.addNode(id, {
34
+ id: `${parent.id}-${id}`,
35
+ label: `${parent.id}-${id}`,
36
+ data: null,
37
+ parent
38
+ });
39
+ parent.addAction({
40
+ id: `${parent.id}-${id}`,
41
+ label: `${parent.id}-${id}`,
42
+ invoke: () => {
43
+ }
44
+ });
45
+ nodes.set(parent.id, parent);
46
+ nodes.set(child.id, child);
47
+ };
48
+ const addNode = (parentId, node) => {
49
+ const parent = nodes.get(parentId);
50
+ if (!parent) {
51
+ return;
52
+ }
53
+ const [child] = parent.addNode(id, node);
54
+ nodes.set(child.id, child);
55
+ return child;
56
+ };
57
+ const removeNode = (parentId, id2) => {
58
+ const parent = nodes.get(parentId);
59
+ if (!parent) {
60
+ return;
61
+ }
62
+ return parent.removeNode(id2);
63
+ };
64
+ const addAction = (parentId, action) => {
65
+ const parent = nodes.get(parentId);
66
+ if (!parent) {
67
+ return;
68
+ }
69
+ return parent.addAction(action);
70
+ };
71
+ const removeAction = (parentId, id2) => {
72
+ const parent = nodes.get(parentId);
73
+ if (!parent) {
74
+ return;
75
+ }
76
+ return parent.removeAction(id2);
77
+ };
78
+ const addProperty = (parentId, key, value) => {
79
+ const parent = nodes.get(parentId);
80
+ if (!parent) {
81
+ return;
82
+ }
83
+ return parent.addProperty(key, value);
84
+ };
85
+ const removeProperty = (parentId, key) => {
86
+ const parent = nodes.get(parentId);
87
+ if (!parent) {
88
+ return;
89
+ }
90
+ return parent.removeProperty(key);
91
+ };
92
+ return {
93
+ nodeBuilder,
94
+ addNode,
95
+ removeNode,
96
+ addAction,
97
+ removeAction,
98
+ addProperty,
99
+ removeProperty
100
+ };
101
+ };
102
+ var buildGraph = (graph, id, nodes) => {
103
+ addNodes(graph.root, id, nodes);
104
+ return graph;
105
+ };
106
+ var addNodes = (root, id, nodes) => {
107
+ nodes.forEach((node) => {
108
+ const [child] = root.addNode(id, node);
109
+ addNodes(child, id, node.children || []);
110
+ node.actions?.forEach((action) => child.addAction(action));
111
+ });
112
+ };
113
+ var checkDepth = (node, depth = 0) => {
114
+ if (!node.parent) {
115
+ return depth;
116
+ }
117
+ return checkDepth(node.parent, depth + 1);
118
+ };
119
+ // Annotate the CommonJS export names for ESM import in node:
120
+ 0 && (module.exports = {
121
+ buildGraph,
122
+ createTestNodeBuilder
123
+ });
124
+ //# sourceMappingURL=testing.cjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/testing.ts"],
4
+ "sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { type Action } from './action';\nimport { type Graph } from './graph';\nimport { type NodeBuilder, type Node } from './node';\n\n/**\n * Create a test node builder that always adds nodes and actions to the specified depth.\n *\n * @param id The id of the node builder, used to identify nodes created by this builder.\n * @param depth The depth at which to add nodes and actions.\n * @default 1\n *\n * @returns A test node builder\n */\n// TODO(burdon): Change to TestNodeBuilder class (see other builder/generator patterns in client/echo).\nexport const createTestNodeBuilder = (id: string, depth = 1) => {\n const nodes = new Map<string, Node>();\n const nodeBuilder: NodeBuilder = (parent) => {\n if (checkDepth(parent) >= depth) {\n return;\n }\n\n const [child] = parent.addNode(id, {\n id: `${parent.id}-${id}`,\n label: `${parent.id}-${id}`,\n data: null,\n parent,\n });\n\n parent.addAction({\n id: `${parent.id}-${id}`,\n label: `${parent.id}-${id}`,\n invoke: () => {},\n });\n\n nodes.set(parent.id, parent);\n nodes.set(child.id, child);\n };\n\n const addNode = (parentId: string, node: Pick<Node, 'id' | 'label'> & Partial<Node>) => {\n const parent = nodes.get(parentId);\n if (!parent) {\n return;\n }\n\n const [child] = parent.addNode(id, node);\n nodes.set(child.id, child);\n return child;\n };\n\n const removeNode = (parentId: string, id: string) => {\n const parent = nodes.get(parentId);\n if (!parent) {\n return;\n }\n\n return parent.removeNode(id);\n };\n\n const addAction = (parentId: string, action: Pick<Action, 'id' | 'label' | 'invoke'> & Partial<Action>) => {\n const parent = nodes.get(parentId);\n if (!parent) {\n return;\n }\n\n return parent.addAction(action);\n };\n\n const removeAction = (parentId: string, id: string) => {\n const parent = nodes.get(parentId);\n if (!parent) {\n return;\n }\n\n return parent.removeAction(id);\n };\n\n const addProperty = (parentId: string, key: string, value: any) => {\n const parent = nodes.get(parentId);\n if (!parent) {\n return;\n }\n\n return parent.addProperty(key, value);\n };\n\n const removeProperty = (parentId: string, key: string) => {\n const parent = nodes.get(parentId);\n if (!parent) {\n return;\n }\n\n return parent.removeProperty(key);\n };\n\n return { nodeBuilder, addNode, removeNode, addAction, removeAction, addProperty, removeProperty };\n};\n\n/**\n * Build a graph from a nested list of nodes.\n *\n * @param graph Graph to add nodes to.\n * @param nodes Nodes to add to the\n *\n * @example\n * const graph = new GraphStore();\n * buildGraph(graph, [\n * {\n * id: 'test1',\n * label: 'test1',\n * children: [\n * {\n * id: 'test1.1',\n * label: 'test1.1',\n * },\n * {\n * id: 'test1.2',\n * label: 'test1.2',\n * },\n * ],\n * },\n * {\n * id: 'test2',\n * label: 'test2',\n * },\n * ]);\n */\n\n// TODO(wittjosiah): Type nodes.\nexport const buildGraph = (graph: Graph, id: string, nodes: any[]) => {\n addNodes(graph.root, id, nodes);\n return graph;\n};\n\nconst addNodes = (root: Node, id: string, nodes: any[]) => {\n nodes.forEach((node) => {\n const [child] = root.addNode(id, node);\n addNodes(child, id, node.children || []);\n node.actions?.forEach((action: any) => child.addAction(action));\n });\n};\n\nconst checkDepth = (node: Node, depth = 0): number => {\n if (!node.parent) {\n return depth;\n }\n\n return checkDepth(node.parent, depth + 1);\n};\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;;;;;;AAkBO,IAAMA,wBAAwB,CAACC,IAAYC,QAAQ,MAAC;AACzD,QAAMC,QAAQ,oBAAIC,IAAAA;AAClB,QAAMC,cAA2B,CAACC,WAAAA;AAChC,QAAIC,WAAWD,MAAAA,KAAWJ,OAAO;AAC/B;IACF;AAEA,UAAM,CAACM,KAAAA,IAASF,OAAOG,QAAQR,IAAI;MACjCA,IAAI,GAAGK,OAAOL,EAAE,IAAIA,EAAAA;MACpBS,OAAO,GAAGJ,OAAOL,EAAE,IAAIA,EAAAA;MACvBU,MAAM;MACNL;IACF,CAAA;AAEAA,WAAOM,UAAU;MACfX,IAAI,GAAGK,OAAOL,EAAE,IAAIA,EAAAA;MACpBS,OAAO,GAAGJ,OAAOL,EAAE,IAAIA,EAAAA;MACvBY,QAAQ,MAAA;MAAO;IACjB,CAAA;AAEAV,UAAMW,IAAIR,OAAOL,IAAIK,MAAAA;AACrBH,UAAMW,IAAIN,MAAMP,IAAIO,KAAAA;EACtB;AAEA,QAAMC,UAAU,CAACM,UAAkBC,SAAAA;AACjC,UAAMV,SAASH,MAAM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AAM0B,QAAQ,CAACb,SAAAA;AACb,UAAM,CAACR,KAAAA,IAASoB,KAAKnB,QAAQR,IAAIe,IAAAA;AACjCW,aAASnB,OAAOP,IAAIe,KAAKc,YAAY,CAAA,CAAE;AACvCd,SAAKe,SAASF,QAAQ,CAACV,WAAgBX,MAAMI,UAAUO,MAAAA,CAAAA;EACzD,CAAA;AACF;AAEA,IAAMZ,aAAa,CAACS,MAAYd,QAAQ,MAAC;AACvC,MAAI,CAACc,KAAKV,QAAQ;AAChB,WAAOJ;EACT;AAEA,SAAOK,WAAWS,KAAKV,QAAQJ,QAAQ,CAAA;AACzC;",
6
+ "names": ["createTestNodeBuilder", "id", "depth", "nodes", "Map", "nodeBuilder", "parent", "checkDepth", "child", "addNode", "label", "data", "addAction", "invoke", "set", "parentId", "node", "get", "removeNode", "action", "removeAction", "addProperty", "key", "value", "removeProperty", "buildGraph", "graph", "addNodes", "root", "forEach", "children", "actions"]
7
+ }
@@ -0,0 +1,53 @@
1
+ import type { IconProps } from '@phosphor-icons/react';
2
+ import type { FC } from 'react';
3
+ import type { MaybePromise } from '@dxos/util';
4
+ export type Label = string | [string, {
5
+ ns: string;
6
+ count?: number;
7
+ }];
8
+ /**
9
+ * An action on a node in the graph which may be invoked by sending the associated intent.
10
+ */
11
+ export type Action<TProperties extends Record<string, any> = Record<string, any>> = {
12
+ /**
13
+ * Locally unique ID.
14
+ */
15
+ id: string;
16
+ /**
17
+ * Label to be used when displaying the node.
18
+ * For default labels, use a translated string.
19
+ *
20
+ * @example 'Test Action'
21
+ * @example ['test action label, { ns: 'example-plugin' }]
22
+ */
23
+ label: Label;
24
+ /**
25
+ * Icon to be used when displaying the node.
26
+ */
27
+ icon?: FC<IconProps>;
28
+ /**
29
+ * Key binding.
30
+ * NOTE: Alphanumeric characters should be declared in lowercase.
31
+ */
32
+ keyBinding?: string;
33
+ /**
34
+ * Properties of the node relevant to displaying the action.
35
+ *
36
+ * @example { index: 'a1' }
37
+ */
38
+ properties: TProperties;
39
+ /**
40
+ * Sub-actions of the node stored by their id.
41
+ */
42
+ actionsMap: Record<string, Action>;
43
+ /**
44
+ * Actions of the node in default order.
45
+ */
46
+ get actions(): Action[];
47
+ invoke: () => MaybePromise<any>;
48
+ addProperty(key: string, value: any): void;
49
+ removeProperty(key: string): void;
50
+ addAction<TActionProperties extends Record<string, any> = Record<string, any>>(...action: (Pick<Action, 'id' | 'label' | 'invoke'> & Partial<Action<TActionProperties>>)[]): Action<TActionProperties>[];
51
+ removeAction(id: string): Action;
52
+ };
53
+ //# sourceMappingURL=action.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"action.d.ts","sourceRoot":"","sources":["../../../src/action.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAEhC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAG/C,MAAM,MAAM,KAAK,GAAG,MAAM,GAAG,CAAC,MAAM,EAAE;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC;AAEtE;;GAEG;AACH,MAAM,MAAM,MAAM,CAAC,WAAW,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,IAAI;IAClF;;OAEG;IACH,EAAE,EAAE,MAAM,CAAC;IAEX;;;;;;OAMG;IACH,KAAK,EAAE,KAAK,CAAC;IAEb;;OAEG;IACH,IAAI,CAAC,EAAE,EAAE,CAAC,SAAS,CAAC,CAAC;IAErB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;;OAIG;IACH,UAAU,EAAE,WAAW,CAAC;IAExB;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAEnC;;OAEG;IAEH,IAAI,OAAO,IAAI,MAAM,EAAE,CAAC;IAExB,MAAM,EAAE,MAAM,YAAY,CAAC,GAAG,CAAC,CAAC;IAEhC,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,IAAI,CAAC;IAC3C,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IAElC,SAAS,CAAC,iBAAiB,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC3E,GAAG,MAAM,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,GAAG,OAAO,GAAG,QAAQ,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC,CAAC,EAAE,GAC1F,MAAM,CAAC,iBAAiB,CAAC,EAAE,CAAC;IAC/B,YAAY,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC;CAClC,CAAC"}
@@ -0,0 +1,31 @@
1
+ import { Graph } from './graph';
2
+ import { type Node, type NodeBuilder } from './node';
3
+ /**
4
+ * The builder...
5
+ */
6
+ export declare class GraphBuilder {
7
+ private readonly _nodeBuilders;
8
+ private readonly _unsubscribe;
9
+ /**
10
+ * Register a node builder which will be called in order to construct the graph.
11
+ */
12
+ addNodeBuilder(id: string, builder: NodeBuilder): GraphBuilder;
13
+ /**
14
+ * Remove a node builder from the graph builder.
15
+ */
16
+ removeNodeBuilder(id: string): GraphBuilder;
17
+ /**
18
+ * Construct the graph, starting by calling all registered node builders on the root node.
19
+ * Node builders will be filtered out as they are used such that they are only used once on any given path.
20
+ * @param root
21
+ * @param path
22
+ */
23
+ build(root?: Node, path?: string[]): Graph;
24
+ /**
25
+ * Called recursively.
26
+ */
27
+ private _build;
28
+ private _createNode;
29
+ private _createAction;
30
+ }
31
+ //# sourceMappingURL=graph-builder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graph-builder.d.ts","sourceRoot":"","sources":["../../../src/graph-builder.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,KAAK,IAAI,EAAE,KAAK,WAAW,EAAE,MAAM,QAAQ,CAAC;AAErD;;GAEG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAkC;IAChE,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAyC;IAEtE;;OAEG;IACH,cAAc,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,GAAG,YAAY;IAK9D;;OAEG;IACH,iBAAiB,CAAC,EAAE,EAAE,MAAM,GAAG,YAAY;IAK3C;;;;;OAKG;IACH,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,IAAI,GAAE,MAAM,EAAO,GAAG,KAAK;IAK9C;;OAEG;IACH,OAAO,CAAC,MAAM;IAoBd,OAAO,CAAC,WAAW;IAuFnB,OAAO,CAAC,aAAa;CAyCtB"}
@@ -0,0 +1,45 @@
1
+ import { type Node } from './node';
2
+ export type TraversalOptions = {
3
+ /**
4
+ * The node to start traversing from. Defaults to the root node.
5
+ */
6
+ node?: Node;
7
+ /**
8
+ * The direction to traverse the graph. Defaults to 'down'.
9
+ */
10
+ direction?: 'up' | 'down';
11
+ /**
12
+ * A predicate to filter nodes which are passed to the `visitor` callback.
13
+ */
14
+ filter?: (node: Node) => boolean;
15
+ /**
16
+ * A callback which is called for each node visited during traversal.
17
+ */
18
+ visitor?: (node: Node) => void;
19
+ };
20
+ /**
21
+ * The Graph represents...
22
+ */
23
+ export declare class Graph {
24
+ private readonly _root;
25
+ private readonly _index;
26
+ constructor(_root: Node);
27
+ toJSON(): any;
28
+ /**
29
+ * The root node of the graph which is the entry point for all knowledge.
30
+ */
31
+ get root(): Node;
32
+ /**
33
+ * Get the path through the graph from the root to the node with the given id.
34
+ */
35
+ getPath(id: string): string[] | undefined;
36
+ /**
37
+ * Find the node with the given id in the graph.
38
+ */
39
+ findNode(id: string): Node | undefined;
40
+ /**
41
+ * Recursive breadth-first traversal.
42
+ */
43
+ traverse({ node, direction, filter, visitor }: TraversalOptions, depth?: number): void;
44
+ }
45
+ //# sourceMappingURL=graph.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graph.d.ts","sourceRoot":"","sources":["../../../src/graph.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,QAAQ,CAAC;AAEnC,MAAM,MAAM,gBAAgB,GAAG;IAC7B;;OAEG;IACH,IAAI,CAAC,EAAE,IAAI,CAAC;IAEZ;;OAEG;IACH,SAAS,CAAC,EAAE,IAAI,GAAG,MAAM,CAAC;IAE1B;;OAEG;IACH,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC;IAEjC;;OAEG;IACH,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,CAAC;CAChC,CAAC;AAEF;;GAEG;AACH,qBAAa,KAAK;IAKJ,OAAO,CAAC,QAAQ,CAAC,KAAK;IAFlC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA+C;gBAEzC,KAAK,EAAE,IAAI;IAExC,MAAM;IAmBN;;OAEG;IACH,IAAI,IAAI,IAAI,IAAI,CAEf;IAED;;OAEG;IACH,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS;IAWzC;;OAEG;IACH,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS;IAStC;;OAEG;IACH,QAAQ,CAAC,EAAE,IAAiB,EAAE,SAAkB,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,gBAAgB,EAAE,KAAK,SAAI,GAAG,IAAI;CAWxG"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=graph.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graph.test.d.ts","sourceRoot":"","sources":["../../../src/graph.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,5 @@
1
+ export * from './action';
2
+ export * from './graph';
3
+ export * from './graph-builder';
4
+ export * from './node';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,iBAAiB,CAAC;AAChC,cAAc,QAAQ,CAAC"}