@dxos/graph 0.8.4-main.66e292d → 0.8.4-main.69d29f4

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.
@@ -0,0 +1,452 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ import { Atom, type Registry } from '@effect-atom/atom-react';
6
+
7
+ import { inspectCustom } from '@dxos/debug';
8
+ import { failedInvariant, invariant } from '@dxos/invariant';
9
+ import { type MakeOptional, isTruthy, removeBy } from '@dxos/util';
10
+
11
+ import * as Graph from './Graph';
12
+
13
+ /**
14
+ * Optional function to wrap mutations (e.g., for ECHO objects that require Obj.change).
15
+ */
16
+ export type GraphChangeFunction = (fn: () => void) => void;
17
+
18
+ /**
19
+ * Readonly Graph wrapper.
20
+ */
21
+ export class ReadonlyGraphModel<
22
+ Node extends Graph.Node.Any = Graph.Node.Any,
23
+ Edge extends Graph.Edge.Any = Graph.Edge.Any,
24
+ > {
25
+ protected readonly _graph: Graph.Graph<Node, Edge>;
26
+ /**
27
+ * Optional function to wrap mutations.
28
+ * When set, all graph mutations are wrapped in this function.
29
+ */
30
+ protected readonly _change?: GraphChangeFunction;
31
+
32
+ /**
33
+ * NOTE: Pass in simple Graph or Live.
34
+ * @param graph - The graph data.
35
+ * @param change - Optional function to wrap mutations (e.g., Obj.change for ECHO objects).
36
+ */
37
+ constructor(graph?: Graph.Graph<Node, Edge>, change?: GraphChangeFunction) {
38
+ this._graph = graph ?? {
39
+ nodes: [],
40
+ edges: [],
41
+ };
42
+ this._change = change;
43
+ }
44
+
45
+ [inspectCustom]() {
46
+ return this.toJSON();
47
+ }
48
+
49
+ /**
50
+ * Return stable sorted JSON representation of graph.
51
+ */
52
+ toJSON() {
53
+ return {
54
+ nodes: this.nodes.length,
55
+ edges: this.edges.length,
56
+ };
57
+ }
58
+
59
+ get graph(): Graph.Graph<Node, Edge> {
60
+ return this._graph;
61
+ }
62
+
63
+ get nodes(): Node[] {
64
+ return this._graph.nodes;
65
+ }
66
+
67
+ get edges(): Edge[] {
68
+ return this._graph.edges;
69
+ }
70
+
71
+ //
72
+ // Nodes
73
+ //
74
+
75
+ findNode(id: string): Node | undefined {
76
+ return this.nodes.find((node) => node.id === id);
77
+ }
78
+
79
+ getNode(id: string): Node {
80
+ return this.findNode(id) ?? failedInvariant();
81
+ }
82
+
83
+ filterNodes({ type }: Partial<Graph.Node.Any> = {}): Node[] {
84
+ return this.nodes.filter((node) => !type || type === node.type);
85
+ }
86
+
87
+ //
88
+ // Edges
89
+ //
90
+
91
+ findEdge(id: string): Edge | undefined {
92
+ return this.edges.find((edge) => edge.id === id);
93
+ }
94
+
95
+ getEdge(id: string): Edge {
96
+ return this.findEdge(id) ?? failedInvariant();
97
+ }
98
+
99
+ filterEdges({ type, source, target }: Partial<Graph.Edge.Any> = {}): Edge[] {
100
+ return this.edges.filter(
101
+ (edge) =>
102
+ (!type || type === edge.type) && (!source || source === edge.source) && (!target || target === edge.target),
103
+ );
104
+ }
105
+
106
+ //
107
+ // Traverse
108
+ //
109
+
110
+ traverse(root: Node): Node[] {
111
+ return this._traverse(root);
112
+ }
113
+
114
+ private _traverse(root: Node, visited: Set<string> = new Set()): Node[] {
115
+ if (visited.has(root.id)) {
116
+ return [];
117
+ }
118
+
119
+ visited.add(root.id);
120
+ const targets = this.filterEdges({ source: root.id })
121
+ .map((edge) => this.getNode(edge.target))
122
+ .filter(isTruthy);
123
+
124
+ return [root, ...targets.flatMap((target) => this._traverse(target, visited))];
125
+ }
126
+ }
127
+
128
+ /**
129
+ * Mutable Graph wrapper.
130
+ */
131
+ export abstract class AbstractGraphModel<
132
+ Node extends Graph.Node.Any = Graph.Node.Any,
133
+ Edge extends Graph.Edge.Any = Graph.Edge.Any,
134
+ Model extends AbstractGraphModel<Node, Edge, Model, Builder> = any,
135
+ Builder extends AbstractBuilder<Node, Edge, Model> = AbstractBuilder<Node, Edge, Model>,
136
+ > extends ReadonlyGraphModel<Node, Edge> {
137
+ /**
138
+ * Allows chaining.
139
+ */
140
+ abstract get builder(): Builder;
141
+
142
+ /**
143
+ * Shallow copy of provided graph.
144
+ */
145
+ abstract copy(graph?: Partial<Graph.Graph<Node, Edge>>): Model;
146
+
147
+ /**
148
+ * Execute a mutation on the graph.
149
+ * If a change function is set, wraps the mutation in it.
150
+ */
151
+ protected _mutate(fn: (graph: Graph.Graph<Node, Edge>) => void): void {
152
+ if (this._change != null) {
153
+ this._change(() => fn(this._graph));
154
+ } else {
155
+ fn(this._graph);
156
+ }
157
+ }
158
+
159
+ clear(): this {
160
+ this._mutate((graph) => {
161
+ graph.nodes.length = 0;
162
+ graph.edges.length = 0;
163
+ });
164
+ return this;
165
+ }
166
+
167
+ addGraph(graph: Model): this {
168
+ this.addNodes(graph.nodes);
169
+ this.addEdges(graph.edges);
170
+ return this;
171
+ }
172
+
173
+ addGraphs(graphs: Model[]): this {
174
+ graphs.forEach((graph) => {
175
+ this.addNodes(graph.nodes);
176
+ this.addEdges(graph.edges);
177
+ });
178
+ return this;
179
+ }
180
+
181
+ addNode(node: Node): Node {
182
+ invariant(node.id, 'ID is required');
183
+ invariant(!this.findNode(node.id), `node already exists: ${node.id}`);
184
+ this._mutate((graph) => {
185
+ graph.nodes.push(node);
186
+ });
187
+ return node;
188
+ }
189
+
190
+ addNodes(nodes: Node[]): Node[] {
191
+ return nodes.map((node) => this.addNode(node));
192
+ }
193
+
194
+ addEdge(edge: MakeOptional<Edge, 'id'>): Edge {
195
+ invariant(edge.source);
196
+ invariant(edge.target);
197
+ if (!edge.id) {
198
+ // TODO(burdon): Generate random id.
199
+ edge = { id: Graph.createEdgeId(edge), ...edge };
200
+ }
201
+ invariant(!this.findNode(edge.id!));
202
+ this._mutate((graph) => {
203
+ graph.edges.push(edge as Edge);
204
+ });
205
+ return edge as Edge;
206
+ }
207
+
208
+ addEdges(edges: Edge[]): Edge[] {
209
+ return edges.map((edge) => this.addEdge(edge));
210
+ }
211
+
212
+ removeNode(id: string): Model {
213
+ let removedEdges: Edge[] = [];
214
+ let removedNodes: Node[] = [];
215
+ this._mutate((graph) => {
216
+ removedEdges = removeBy<Edge>(graph.edges as Edge[], (edge) => edge.source === id || edge.target === id);
217
+ removedNodes = removeBy<Node>(graph.nodes as Node[], (node) => node.id === id);
218
+ });
219
+ return this.copy({ nodes: removedNodes, edges: removedEdges });
220
+ }
221
+
222
+ removeNodes(ids: string[]): Model {
223
+ const graphs = ids.map((id) => this.removeNode(id));
224
+ return this.copy().addGraphs(graphs);
225
+ }
226
+
227
+ removeEdge(id: string): Model {
228
+ let removedEdges: Edge[] = [];
229
+ this._mutate((graph) => {
230
+ removedEdges = removeBy<Edge>(graph.edges as Edge[], (edge) => edge.id === id);
231
+ });
232
+ return this.copy({ nodes: [], edges: removedEdges });
233
+ }
234
+
235
+ removeEdges(ids: string[]): Model {
236
+ const graphs = ids.map((id) => this.removeEdge(id));
237
+ return this.copy().addGraphs(graphs);
238
+ }
239
+ }
240
+
241
+ /**
242
+ * Chainable builder wrapper
243
+ */
244
+ export abstract class AbstractBuilder<
245
+ Node extends Graph.Node.Any,
246
+ Edge extends Graph.Edge.Any,
247
+ Model extends GraphModel<Node, Edge>,
248
+ > {
249
+ constructor(protected readonly _model: Model) {}
250
+
251
+ get model(): Model {
252
+ return this._model;
253
+ }
254
+
255
+ call(cb: (builder: this) => void): this {
256
+ cb(this);
257
+ return this;
258
+ }
259
+
260
+ getNode(id: string): Node {
261
+ return this.model.getNode(id);
262
+ }
263
+
264
+ addNode(node: Node): this {
265
+ this._model.addNode(node);
266
+ return this;
267
+ }
268
+
269
+ addEdge(edge: MakeOptional<Edge, 'id'>): this {
270
+ this._model.addEdge(edge);
271
+ return this;
272
+ }
273
+
274
+ addNodes(nodes: Node[]): this {
275
+ this._model.addNodes(nodes);
276
+ return this;
277
+ }
278
+
279
+ addEdges(edges: Edge[]): this {
280
+ this._model.addEdges(edges);
281
+ return this;
282
+ }
283
+ }
284
+
285
+ /**
286
+ * Basic model.
287
+ */
288
+ export class GraphModel<
289
+ Node extends Graph.Node.Any = Graph.Node.Any,
290
+ Edge extends Graph.Edge.Any = Graph.Edge.Any,
291
+ > extends AbstractGraphModel<Node, Edge, GraphModel<Node, Edge>, Builder<Node, Edge>> {
292
+ override get builder() {
293
+ return new Builder<Node, Edge>(this);
294
+ }
295
+
296
+ override copy(graph?: Partial<Graph.Graph<Node, Edge>>): GraphModel<Node, Edge> {
297
+ return new GraphModel<Node, Edge>(graph as Graph.Graph<Node, Edge>);
298
+ }
299
+ }
300
+
301
+ export type Subscription = <Node extends Graph.Node.Any = Graph.Node.Any, Edge extends Graph.Edge.Any = Graph.Edge.Any>(
302
+ model: ReactiveGraphModel<Node, Edge>,
303
+ graph: Graph.Graph<Node, Edge>,
304
+ ) => void;
305
+
306
+ /**
307
+ * Basic reactive model using Effect Atoms.
308
+ */
309
+ // NOTE: Unlike Preact Signals' `live()` which uses proxies for transparent reactivity,
310
+ // Effect Atom requires explicit `registry.set()` calls. All mutation methods must be
311
+ // overridden to update the atom immutably rather than mutating `_graph` directly.
312
+ export class ReactiveGraphModel<
313
+ Node extends Graph.Node.Any = Graph.Node.Any,
314
+ Edge extends Graph.Edge.Any = Graph.Edge.Any,
315
+ > extends GraphModel<Node, Edge> {
316
+ private readonly _graphAtom: Atom.Writable<Graph.Graph<Node, Edge>>;
317
+
318
+ constructor(
319
+ private readonly _registry: Registry.Registry,
320
+ graph?: Partial<Graph.Graph<Node, Edge>>,
321
+ ) {
322
+ const initialGraph: Graph.Graph<Node, Edge> = {
323
+ nodes: (graph?.nodes ?? []) as Node[],
324
+ edges: (graph?.edges ?? []) as Edge[],
325
+ };
326
+ super(initialGraph);
327
+ this._graphAtom = Atom.make<Graph.Graph<Node, Edge>>(initialGraph);
328
+ }
329
+
330
+ get registry(): Registry.Registry {
331
+ return this._registry;
332
+ }
333
+
334
+ /**
335
+ * Get the graph atom for reactive subscriptions.
336
+ */
337
+ get graphAtom(): Atom.Writable<Graph.Graph<Node, Edge>> {
338
+ return this._graphAtom;
339
+ }
340
+
341
+ override get graph(): Graph.Graph<Node, Edge> {
342
+ return this._registry.get(this._graphAtom);
343
+ }
344
+
345
+ override get nodes(): Node[] {
346
+ return this.graph.nodes;
347
+ }
348
+
349
+ override get edges(): Edge[] {
350
+ return this.graph.edges;
351
+ }
352
+
353
+ override copy(graph?: Partial<Graph.Graph<Node, Edge>>): ReactiveGraphModel<Node, Edge> {
354
+ return new ReactiveGraphModel<Node, Edge>(this._registry, graph);
355
+ }
356
+
357
+ override clear(): this {
358
+ this._registry.set(this._graphAtom, {
359
+ nodes: [],
360
+ edges: [],
361
+ });
362
+ return this;
363
+ }
364
+
365
+ /**
366
+ * Set the entire graph at once, triggering a single notification.
367
+ */
368
+ setGraph(graph: Graph.Graph<Node, Edge>): this {
369
+ this._registry.set(this._graphAtom, graph);
370
+ return this;
371
+ }
372
+
373
+ override addNode(node: Node): Node {
374
+ invariant(node.id, 'ID is required');
375
+ invariant(!this.findNode(node.id), `node already exists: ${node.id}`);
376
+ const current = this._registry.get(this._graphAtom);
377
+ this._registry.set(this._graphAtom, {
378
+ ...current,
379
+ nodes: [...current.nodes, node],
380
+ });
381
+ return node;
382
+ }
383
+
384
+ override addEdge(edge: MakeOptional<Edge, 'id'>): Edge {
385
+ invariant(edge.source);
386
+ invariant(edge.target);
387
+ if (!edge.id) {
388
+ edge = { id: Graph.createEdgeId(edge), ...edge };
389
+ }
390
+ invariant(!this.findNode(edge.id!));
391
+ const current = this._registry.get(this._graphAtom);
392
+ this._registry.set(this._graphAtom, {
393
+ ...current,
394
+ edges: [...current.edges, edge as Edge],
395
+ });
396
+ return edge as Edge;
397
+ }
398
+
399
+ override removeNode(id: string): ReactiveGraphModel<Node, Edge> {
400
+ const current = this._registry.get(this._graphAtom);
401
+ const removedEdges = current.edges.filter((edge) => edge.source === id || edge.target === id);
402
+ const removedNodes = current.nodes.filter((node) => node.id === id);
403
+
404
+ this._registry.set(this._graphAtom, {
405
+ nodes: current.nodes.filter((node) => node.id !== id),
406
+ edges: current.edges.filter((edge) => edge.source !== id && edge.target !== id),
407
+ });
408
+
409
+ return this.copy({ nodes: removedNodes, edges: removedEdges });
410
+ }
411
+
412
+ override removeEdge(id: string): ReactiveGraphModel<Node, Edge> {
413
+ const current = this._registry.get(this._graphAtom);
414
+ const removedEdges = current.edges.filter((edge) => edge.id === id);
415
+
416
+ this._registry.set(this._graphAtom, {
417
+ ...current,
418
+ edges: current.edges.filter((edge) => edge.id !== id),
419
+ });
420
+
421
+ return this.copy({ nodes: [], edges: removedEdges });
422
+ }
423
+
424
+ /**
425
+ * Subscribe to graph changes.
426
+ */
427
+ subscribe(cb: Subscription, fire = false): () => void {
428
+ if (fire) {
429
+ cb(this, this.graph);
430
+ }
431
+
432
+ // Prime the atom by reading before subscribing to avoid double-fire on first mutation.
433
+ this._registry.get(this._graphAtom);
434
+
435
+ return this._registry.subscribe(this._graphAtom, () => {
436
+ cb(this, this.graph);
437
+ });
438
+ }
439
+ }
440
+
441
+ /**
442
+ * Basic builder.
443
+ */
444
+ export class Builder<
445
+ Node extends Graph.Node.Any = Graph.Node.Any,
446
+ Edge extends Graph.Edge.Any = Graph.Edge.Any,
447
+ > extends AbstractBuilder<Node, Edge, GraphModel<Node, Edge>> {
448
+ override call(cb: (builder: this) => void): this {
449
+ cb(this);
450
+ return this;
451
+ }
452
+ }
package/src/index.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
- export * from './model';
6
5
  export * from './selection';
7
- export * from './types';
8
- export * from './util';
6
+
7
+ export * as Graph from './Graph';
8
+ export * as GraphModel from './GraphModel';
package/src/selection.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- import { type ReadonlySignal, type Signal, computed, signal } from '@preact/signals-core';
5
+ import { Atom, Registry } from '@effect-atom/atom-react';
6
6
 
7
7
  import { invariant } from '@dxos/invariant';
8
8
 
@@ -10,61 +10,101 @@ import { invariant } from '@dxos/invariant';
10
10
  * Reactive selection model.
11
11
  */
12
12
  export class SelectionModel {
13
- private readonly _selected: Signal<Set<string>> = signal(new Set<string>());
14
- private readonly _selectedIds = computed(() => Array.from(this._selected.value.values()));
13
+ private readonly _registry: Registry.Registry;
14
+ private readonly _selected: Atom.Writable<Set<string>>;
15
15
 
16
- constructor(private readonly _singleSelect: boolean = false) {}
16
+ constructor(private readonly _singleSelect: boolean = false) {
17
+ this._registry = Registry.make();
18
+ this._selected = Atom.make<Set<string>>(new Set<string>());
19
+ }
20
+
21
+ /**
22
+ * Returns the selected IDs atom for subscription.
23
+ */
24
+ get selected(): Atom.Atom<Set<string>> {
25
+ return this._selected;
26
+ }
27
+
28
+ /**
29
+ * Gets the current selected IDs as a Set.
30
+ */
31
+ getSelected(): Set<string> {
32
+ return this._registry.get(this._selected);
33
+ }
34
+
35
+ /**
36
+ * Gets the current selected IDs as an array.
37
+ */
38
+ getSelectedIds(): string[] {
39
+ return Array.from(this._registry.get(this._selected).values());
40
+ }
41
+
42
+ /**
43
+ * Subscribe to selection changes.
44
+ */
45
+ subscribe(cb: (selected: Set<string>) => void): () => void {
46
+ // Prime the atom by reading before subscribing.
47
+ this._registry.get(this._selected);
48
+
49
+ return this._registry.subscribe(this._selected, () => {
50
+ cb(this._registry.get(this._selected));
51
+ });
52
+ }
17
53
 
18
54
  toJSON(): { selected: string[] } {
19
55
  return {
20
- selected: Array.from(this._selected.value.values()),
56
+ selected: this.getSelectedIds(),
21
57
  };
22
58
  }
23
59
 
24
- get size(): number {
25
- return this._selected.value.size;
26
- }
27
-
28
- get selected(): ReadonlySignal<string[]> {
29
- return this._selectedIds;
60
+ /**
61
+ * Gets the current selection size.
62
+ */
63
+ getSize(): number {
64
+ return this._registry.get(this._selected).size;
30
65
  }
31
66
 
32
67
  contains(id: string): boolean {
33
- return this._selected.value.has(id);
68
+ return this._registry.get(this._selected).has(id);
34
69
  }
35
70
 
36
71
  clear(): void {
37
- this._selected.value = new Set();
72
+ this._registry.set(this._selected, new Set());
38
73
  }
39
74
 
40
75
  add(id: string): void {
41
76
  invariant(id);
42
- this._selected.value = new Set<string>(
43
- this._singleSelect ? [id] : [...Array.from(this._selected.value.values()), id],
77
+ const current = this._registry.get(this._selected);
78
+ this._registry.set(
79
+ this._selected,
80
+ new Set<string>(this._singleSelect ? [id] : [...Array.from(current.values()), id]),
44
81
  );
45
82
  }
46
83
 
47
84
  remove(id: string): void {
48
85
  invariant(id);
49
- this._selected.value = new Set<string>(Array.from(this._selected.value.values()).filter((_id) => _id !== id));
86
+ const current = this._registry.get(this._selected);
87
+ this._registry.set(this._selected, new Set<string>(Array.from(current.values()).filter((_id) => _id !== id)));
50
88
  }
51
89
 
52
90
  // TODO(burdon): Handle single select.
53
91
 
54
- setSelected(ids: string[], shift = false): void {
55
- this._selected.value = new Set([...(shift ? Array.from(this._selected.value.values()) : []), ...ids]);
92
+ setSelected(ids: string[], subtract = false): void {
93
+ const current = this._registry.get(this._selected);
94
+ this._registry.set(this._selected, new Set([...(subtract ? Array.from(current.values()) : []), ...ids]));
56
95
  }
57
96
 
58
- toggleSelected(ids: string[], shift = false): void {
59
- const set = new Set<string>(shift ? Array.from(this._selected.value.values()) : undefined);
97
+ toggleSelected(ids: string[], subtract = false): void {
98
+ const current = this._registry.get(this._selected);
99
+ const set = new Set<string>(subtract ? Array.from(current.values()) : undefined);
60
100
  ids.forEach((id) => {
61
- if (this._selected.value.has(id)) {
101
+ if (current.has(id)) {
62
102
  set.delete(id);
63
103
  } else {
64
104
  set.add(id);
65
105
  }
66
106
  });
67
107
 
68
- this._selected.value = set;
108
+ this._registry.set(this._selected, set);
69
109
  }
70
110
  }
@@ -1,102 +0,0 @@
1
- import { inspectCustom } from '@dxos/debug';
2
- import { type Live } from '@dxos/live-object';
3
- import { type MakeOptional } from '@dxos/util';
4
- import { type BaseGraphEdge, type BaseGraphNode, type Graph, type GraphEdge, type GraphNode } from './types';
5
- /**
6
- * Readonly Graph wrapper.
7
- */
8
- export declare class ReadonlyGraphModel<Node extends BaseGraphNode = BaseGraphNode, Edge extends BaseGraphEdge = BaseGraphEdge> {
9
- protected readonly _graph: Graph;
10
- /**
11
- * NOTE: Pass in simple Graph or Live.
12
- */
13
- constructor(graph?: Graph);
14
- [inspectCustom](): {
15
- nodes: number;
16
- edges: number;
17
- };
18
- /**
19
- * Return stable sorted JSON representation of graph.
20
- */
21
- toJSON(): {
22
- nodes: number;
23
- edges: number;
24
- };
25
- get graph(): Graph;
26
- get nodes(): Node[];
27
- get edges(): Edge[];
28
- findNode(id: string): Node | undefined;
29
- getNode(id: string): Node;
30
- filterNodes({ type }?: Partial<GraphNode.Any>): Node[];
31
- findEdge(id: string): Edge | undefined;
32
- getEdge(id: string): Edge;
33
- filterEdges({ type, source, target }?: Partial<GraphEdge>): Edge[];
34
- traverse(root: Node): Node[];
35
- private _traverse;
36
- }
37
- /**
38
- * Mutable Graph wrapper.
39
- */
40
- export declare abstract class AbstractGraphModel<Node extends BaseGraphNode = BaseGraphNode, Edge extends BaseGraphEdge = BaseGraphEdge, Model extends AbstractGraphModel<Node, Edge, Model, Builder> = any, Builder extends AbstractGraphBuilder<Node, Edge, Model> = AbstractGraphBuilder<Node, Edge, Model>> extends ReadonlyGraphModel<Node, Edge> {
41
- /**
42
- * Allows chaining.
43
- */
44
- abstract get builder(): Builder;
45
- /**
46
- * Shallow copy of provided graph.
47
- */
48
- abstract copy(graph?: Partial<Graph>): Model;
49
- clear(): this;
50
- addGraph(graph: Model): this;
51
- addGraphs(graphs: Model[]): this;
52
- addNode(node: Node): Node;
53
- addNodes(nodes: Node[]): Node[];
54
- addEdge(edge: MakeOptional<Edge, 'id'>): Edge;
55
- addEdges(edges: Edge[]): Edge[];
56
- removeNode(id: string): Model;
57
- removeNodes(ids: string[]): Model;
58
- removeEdge(id: string): Model;
59
- removeEdges(ids: string[]): Model;
60
- }
61
- /**
62
- * Chainable builder wrapper
63
- */
64
- export declare abstract class AbstractGraphBuilder<Node extends BaseGraphNode, Edge extends BaseGraphEdge, Model extends GraphModel<Node, Edge>> {
65
- protected readonly _model: Model;
66
- constructor(_model: Model);
67
- get model(): Model;
68
- call(cb: (builder: this) => void): this;
69
- getNode(id: string): Node;
70
- addNode(node: Node): this;
71
- addEdge(edge: MakeOptional<Edge, 'id'>): this;
72
- addNodes(nodes: Node[]): this;
73
- addEdges(edges: Edge[]): this;
74
- }
75
- /**
76
- * Basic model.
77
- */
78
- export declare class GraphModel<Node extends BaseGraphNode = BaseGraphNode, Edge extends BaseGraphEdge = BaseGraphEdge> extends AbstractGraphModel<Node, Edge, GraphModel<Node, Edge>, GraphBuilder<Node, Edge>> {
79
- get builder(): GraphBuilder<Node, Edge>;
80
- copy(graph?: Partial<Graph>): GraphModel<Node, Edge>;
81
- }
82
- export type GraphModelSubscription = (model: GraphModel, graph: Live<Graph>) => void;
83
- /**
84
- * Subscription.
85
- * NOTE: Requires `registerSignalsRuntime` to be called.
86
- */
87
- export declare const subscribe: (model: GraphModel, cb: GraphModelSubscription, fire?: boolean) => () => void;
88
- /**
89
- * Basic reactive model.
90
- */
91
- export declare class ReactiveGraphModel<Node extends BaseGraphNode = BaseGraphNode, Edge extends BaseGraphEdge = BaseGraphEdge> extends GraphModel<Node, Edge> {
92
- constructor(graph?: Partial<Graph>);
93
- copy(graph?: Partial<Graph>): ReactiveGraphModel<Node, Edge>;
94
- subscribe(cb: GraphModelSubscription, fire?: boolean): () => void;
95
- }
96
- /**
97
- * Basic builder.
98
- */
99
- export declare class GraphBuilder<Node extends BaseGraphNode = BaseGraphNode, Edge extends BaseGraphEdge = BaseGraphEdge> extends AbstractGraphBuilder<Node, Edge, GraphModel<Node, Edge>> {
100
- call(cb: (builder: this) => void): this;
101
- }
102
- //# sourceMappingURL=model.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../../src/model.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AA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