@dxos/graph 0.10.0 → 0.11.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/graph",
3
- "version": "0.10.0",
3
+ "version": "0.11.1",
4
4
  "description": "Low-level graph API",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -16,8 +16,7 @@
16
16
  ".": {
17
17
  "source": "./src/index.ts",
18
18
  "types": "./dist/types/src/index.d.ts",
19
- "browser": "./dist/lib/browser/index.mjs",
20
- "node": "./dist/lib/node-esm/index.mjs"
19
+ "import": "./dist/lib/index.mjs"
21
20
  }
22
21
  },
23
22
  "types": "dist/types/src/index.d.ts",
@@ -26,16 +25,16 @@
26
25
  "src"
27
26
  ],
28
27
  "dependencies": {
29
- "@effect-atom/atom-react": "^0.5.0",
30
- "@dxos/async": "0.10.0",
31
- "@dxos/util": "0.10.0",
32
- "@dxos/debug": "0.10.0",
33
- "@dxos/invariant": "0.10.0"
28
+ "@effect-atom/atom": "^0.5.3",
29
+ "@dxos/async": "0.11.1",
30
+ "@dxos/debug": "0.11.1",
31
+ "@dxos/invariant": "0.11.1",
32
+ "@dxos/util": "0.11.1"
34
33
  },
35
34
  "devDependencies": {
36
35
  "effect": "3.21.4",
37
- "@dxos/random": "0.10.0",
38
- "@dxos/echo": "0.10.0"
36
+ "@dxos/echo": "0.11.1",
37
+ "@dxos/random": "0.11.1"
39
38
  },
40
39
  "peerDependencies": {
41
40
  "effect": "3.21.4"
@@ -2,7 +2,7 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- import { Registry } from '@effect-atom/atom-react';
5
+ import { Registry } from '@effect-atom/atom';
6
6
  import * as Schema from 'effect/Schema';
7
7
  import { describe, test } from 'vitest';
8
8
 
package/src/GraphModel.ts CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  // @import-as-namespace
6
6
 
7
- import { Atom, type Registry } from '@effect-atom/atom-react';
7
+ import { Atom, type Registry } from '@effect-atom/atom';
8
8
 
9
9
  import { inspectCustom } from '@dxos/debug';
10
10
  import { failedInvariant, invariant } from '@dxos/invariant';
package/src/selection.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- import { Atom, Registry } from '@effect-atom/atom-react';
5
+ import { Atom, Registry } from '@effect-atom/atom';
6
6
 
7
7
  import { invariant } from '@dxos/invariant';
8
8
 
@@ -1,508 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __export = (target, all) => {
3
- for (var name in all)
4
- __defProp(target, name, { get: all[name], enumerable: true });
5
- };
6
-
7
- // src/selection.ts
8
- import { Atom, Registry } from "@effect-atom/atom-react";
9
- import { invariant } from "@dxos/invariant";
10
- var __dxlog_file = "/__w/dxos/dxos/packages/common/graph/src/selection.ts";
11
- var SelectionModel = class {
12
- _registry;
13
- _selected;
14
- _mode;
15
- constructor({ mode = "multi" } = {}) {
16
- this._registry = Registry.make();
17
- this._selected = Atom.make(/* @__PURE__ */ new Set());
18
- this._mode = mode;
19
- }
20
- /**
21
- * Returns the selected IDs atom for subscription.
22
- */
23
- get selected() {
24
- return this._selected;
25
- }
26
- /**
27
- * Gets the current selected IDs as a Set.
28
- */
29
- getSelected() {
30
- return this._registry.get(this._selected);
31
- }
32
- /**
33
- * Gets the current selected IDs as an array.
34
- */
35
- getSelectedIds() {
36
- return Array.from(this._registry.get(this._selected).values());
37
- }
38
- /**
39
- * Subscribe to selection changes.
40
- */
41
- subscribe(cb) {
42
- this._registry.get(this._selected);
43
- return this._registry.subscribe(this._selected, () => {
44
- cb(this._registry.get(this._selected));
45
- });
46
- }
47
- toJSON() {
48
- return {
49
- selected: this.getSelectedIds()
50
- };
51
- }
52
- /**
53
- * Gets the current selection size.
54
- */
55
- getSize() {
56
- return this._registry.get(this._selected).size;
57
- }
58
- contains(id) {
59
- return this._registry.get(this._selected).has(id);
60
- }
61
- clear() {
62
- this._registry.set(this._selected, /* @__PURE__ */ new Set());
63
- }
64
- add(id) {
65
- invariant(id, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 59, S: this, A: ["id", ""] });
66
- const current = this._registry.get(this._selected);
67
- this._registry.set(this._selected, new Set(this._mode === "single" ? [
68
- id
69
- ] : [
70
- ...Array.from(current.values()),
71
- id
72
- ]));
73
- }
74
- remove(id) {
75
- invariant(id, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 69, S: this, A: ["id", ""] });
76
- const current = this._registry.get(this._selected);
77
- this._registry.set(this._selected, new Set(Array.from(current.values()).filter((_id) => _id !== id)));
78
- }
79
- // TODO(burdon): Handle single select.
80
- setSelected(ids, subtract = false) {
81
- const current = this._registry.get(this._selected);
82
- this._registry.set(this._selected, /* @__PURE__ */ new Set([
83
- ...subtract ? Array.from(current.values()) : [],
84
- ...ids
85
- ]));
86
- }
87
- toggleSelected(ids, subtract = false) {
88
- const current = this._registry.get(this._selected);
89
- const set = new Set(subtract ? Array.from(current.values()) : void 0);
90
- ids.forEach((id) => {
91
- if (current.has(id)) {
92
- set.delete(id);
93
- } else {
94
- set.add(id);
95
- }
96
- });
97
- this._registry.set(this._selected, set);
98
- }
99
- };
100
-
101
- // src/Graph.ts
102
- var Graph_exports = {};
103
- __export(Graph_exports, {
104
- Edge: () => Edge,
105
- Graph: () => Graph,
106
- Node: () => Node,
107
- createEdgeId: () => createEdgeId,
108
- parseEdgeId: () => parseEdgeId
109
- });
110
- import * as Schema from "effect/Schema";
111
- import { invariant as invariant2 } from "@dxos/invariant";
112
- var __dxlog_file2 = "/__w/dxos/dxos/packages/common/graph/src/Graph.ts";
113
- var Node = Schema.Struct({
114
- id: Schema.String,
115
- type: Schema.optional(Schema.String),
116
- data: Schema.optional(Schema.Any)
117
- });
118
- var Edge = Schema.Struct({
119
- id: Schema.String,
120
- type: Schema.optional(Schema.String),
121
- source: Schema.String,
122
- target: Schema.String,
123
- data: Schema.optional(Schema.Any)
124
- });
125
- var KEY_REGEX = /\w+/;
126
- var createEdgeId = ({ source, target, relation }) => {
127
- invariant2(source.match(KEY_REGEX), `invalid source: ${source}`, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 27, S: void 0, A: ["source.match(KEY_REGEX)", "`invalid source: ${source}`"] });
128
- invariant2(target.match(KEY_REGEX), `invalid target: ${target}`, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 28, S: void 0, A: ["target.match(KEY_REGEX)", "`invalid target: ${target}`"] });
129
- return [
130
- source,
131
- relation,
132
- target
133
- ].join("_");
134
- };
135
- var parseEdgeId = (id) => {
136
- const [source, relation, target] = id.split("_");
137
- invariant2(source.length && target.length, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 37, S: void 0, A: ["source.length && target.length", ""] });
138
- return {
139
- source,
140
- relation: relation.length ? relation : void 0,
141
- target
142
- };
143
- };
144
- var Graph = Schema.Struct({
145
- id: Schema.optional(Schema.String),
146
- nodes: Schema.mutable(Schema.Array(Node)),
147
- edges: Schema.mutable(Schema.Array(Edge))
148
- });
149
-
150
- // src/GraphModel.ts
151
- var GraphModel_exports = {};
152
- __export(GraphModel_exports, {
153
- AbstractBuilder: () => AbstractBuilder,
154
- AbstractGraphModel: () => AbstractGraphModel,
155
- Builder: () => Builder,
156
- GraphModel: () => GraphModel,
157
- ReactiveGraphModel: () => ReactiveGraphModel,
158
- ReadonlyGraphModel: () => ReadonlyGraphModel
159
- });
160
- import { Atom as Atom2 } from "@effect-atom/atom-react";
161
- import { inspectCustom } from "@dxos/debug";
162
- import { failedInvariant, invariant as invariant3 } from "@dxos/invariant";
163
- import { isTruthy, removeBy } from "@dxos/util";
164
- var __dxlog_file3 = "/__w/dxos/dxos/packages/common/graph/src/GraphModel.ts";
165
- var ReadonlyGraphModel = class {
166
- _graph;
167
- /**
168
- * Optional function to wrap mutations.
169
- * When set, all graph mutations are wrapped in this function.
170
- */
171
- _change;
172
- /**
173
- * NOTE: Pass in simple Graph or Live.
174
- * @param graph - The graph data.
175
- * @param change - Optional function to wrap mutations (e.g., Obj.update for ECHO objects).
176
- */
177
- constructor(graph, change) {
178
- this._graph = graph ?? {
179
- nodes: [],
180
- edges: []
181
- };
182
- this._change = change;
183
- }
184
- [inspectCustom]() {
185
- return this.toJSON();
186
- }
187
- /**
188
- * Return stable sorted JSON representation of graph.
189
- */
190
- toJSON() {
191
- return {
192
- nodes: this.nodes.length,
193
- edges: this.edges.length
194
- };
195
- }
196
- get graph() {
197
- return this._graph;
198
- }
199
- get nodes() {
200
- return this._graph.nodes;
201
- }
202
- get edges() {
203
- return this._graph.edges;
204
- }
205
- //
206
- // Nodes
207
- //
208
- findNode(id) {
209
- return this.nodes.find((node) => node.id === id);
210
- }
211
- getNode(id) {
212
- return this.findNode(id) ?? failedInvariant();
213
- }
214
- filterNodes({ type } = {}) {
215
- return this.nodes.filter((node) => !type || type === node.type);
216
- }
217
- //
218
- // Edges
219
- //
220
- findEdge(id) {
221
- return this.edges.find((edge) => edge.id === id);
222
- }
223
- getEdge(id) {
224
- return this.findEdge(id) ?? failedInvariant();
225
- }
226
- filterEdges({ type, source, target } = {}) {
227
- return this.edges.filter((edge) => (!type || type === edge.type) && (!source || source === edge.source) && (!target || target === edge.target));
228
- }
229
- //
230
- // Traverse
231
- //
232
- traverse(root) {
233
- return this._traverse(root);
234
- }
235
- _traverse(root, visited = /* @__PURE__ */ new Set()) {
236
- if (visited.has(root.id)) {
237
- return [];
238
- }
239
- visited.add(root.id);
240
- const targets = this.filterEdges({
241
- source: root.id
242
- }).map((edge) => this.getNode(edge.target)).filter(isTruthy);
243
- return [
244
- root,
245
- ...targets.flatMap((target) => this._traverse(target, visited))
246
- ];
247
- }
248
- };
249
- var AbstractGraphModel = class extends ReadonlyGraphModel {
250
- /**
251
- * Execute a mutation on the graph.
252
- * If a change function is set, wraps the mutation in it.
253
- */
254
- _mutate(fn) {
255
- if (this._change != null) {
256
- this._change(() => fn(this._graph));
257
- } else {
258
- fn(this._graph);
259
- }
260
- }
261
- clear() {
262
- this._mutate((graph) => {
263
- graph.nodes.length = 0;
264
- graph.edges.length = 0;
265
- });
266
- return this;
267
- }
268
- addGraph(graph) {
269
- this.addNodes(graph.nodes);
270
- this.addEdges(graph.edges);
271
- return this;
272
- }
273
- addGraphs(graphs) {
274
- graphs.forEach((graph) => {
275
- this.addNodes(graph.nodes);
276
- this.addEdges(graph.edges);
277
- });
278
- return this;
279
- }
280
- addNode(node) {
281
- invariant3(node.id, "ID is required", { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 126, S: this, A: ["node.id", "'ID is required'"] });
282
- invariant3(!this.findNode(node.id), `node already exists: ${node.id}`, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 127, S: this, A: ["!this.findNode(node.id)", "`node already exists: ${node.id}`"] });
283
- this._mutate((graph) => {
284
- graph.nodes.push(node);
285
- });
286
- return node;
287
- }
288
- addNodes(nodes) {
289
- return nodes.map((node) => this.addNode(node));
290
- }
291
- addEdge(edge) {
292
- invariant3(edge.source, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 137, S: this, A: ["edge.source", ""] });
293
- invariant3(edge.target, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 138, S: this, A: ["edge.target", ""] });
294
- if (!edge.id) {
295
- edge = {
296
- id: createEdgeId(edge),
297
- ...edge
298
- };
299
- }
300
- invariant3(!this.findNode(edge.id), void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 146, S: this, A: ["!this.findNode(edge.id)", ""] });
301
- this._mutate((graph) => {
302
- graph.edges.push(edge);
303
- });
304
- return edge;
305
- }
306
- addEdges(edges) {
307
- return edges.map((edge) => this.addEdge(edge));
308
- }
309
- removeNode(id) {
310
- let removedEdges = [];
311
- let removedNodes = [];
312
- this._mutate((graph) => {
313
- removedEdges = removeBy(graph.edges, (edge) => edge.source === id || edge.target === id);
314
- removedNodes = removeBy(graph.nodes, (node) => node.id === id);
315
- });
316
- return this.copy({
317
- nodes: removedNodes,
318
- edges: removedEdges
319
- });
320
- }
321
- removeNodes(ids) {
322
- const graphs = ids.map((id) => this.removeNode(id));
323
- return this.copy().addGraphs(graphs);
324
- }
325
- removeEdge(id) {
326
- let removedEdges = [];
327
- this._mutate((graph) => {
328
- removedEdges = removeBy(graph.edges, (edge) => edge.id === id);
329
- });
330
- return this.copy({
331
- nodes: [],
332
- edges: removedEdges
333
- });
334
- }
335
- removeEdges(ids) {
336
- const graphs = ids.map((id) => this.removeEdge(id));
337
- return this.copy().addGraphs(graphs);
338
- }
339
- };
340
- var AbstractBuilder = class {
341
- _model;
342
- constructor(_model) {
343
- this._model = _model;
344
- }
345
- get model() {
346
- return this._model;
347
- }
348
- call(cb) {
349
- cb(this);
350
- return this;
351
- }
352
- getNode(id) {
353
- return this.model.getNode(id);
354
- }
355
- addNode(node) {
356
- this._model.addNode(node);
357
- return this;
358
- }
359
- addEdge(edge) {
360
- this._model.addEdge(edge);
361
- return this;
362
- }
363
- addNodes(nodes) {
364
- this._model.addNodes(nodes);
365
- return this;
366
- }
367
- addEdges(edges) {
368
- this._model.addEdges(edges);
369
- return this;
370
- }
371
- };
372
- var GraphModel = class _GraphModel extends AbstractGraphModel {
373
- get builder() {
374
- return new Builder(this);
375
- }
376
- copy(graph) {
377
- return new _GraphModel(graph);
378
- }
379
- };
380
- var ReactiveGraphModel = class _ReactiveGraphModel extends GraphModel {
381
- _registry;
382
- _graphAtom;
383
- constructor(_registry, graph) {
384
- const initialGraph = {
385
- nodes: graph?.nodes ?? [],
386
- edges: graph?.edges ?? []
387
- };
388
- super(initialGraph), this._registry = _registry;
389
- this._graphAtom = Atom2.make(initialGraph);
390
- }
391
- get registry() {
392
- return this._registry;
393
- }
394
- /**
395
- * Get the graph atom for reactive subscriptions.
396
- */
397
- get graphAtom() {
398
- return this._graphAtom;
399
- }
400
- get graph() {
401
- return this._registry.get(this._graphAtom);
402
- }
403
- get nodes() {
404
- return this.graph.nodes;
405
- }
406
- get edges() {
407
- return this.graph.edges;
408
- }
409
- copy(graph) {
410
- return new _ReactiveGraphModel(this._registry, graph);
411
- }
412
- clear() {
413
- this._registry.set(this._graphAtom, {
414
- nodes: [],
415
- edges: []
416
- });
417
- return this;
418
- }
419
- /**
420
- * Set the entire graph at once, triggering a single notification.
421
- */
422
- setGraph(graph) {
423
- this._registry.set(this._graphAtom, graph);
424
- return this;
425
- }
426
- addNode(node) {
427
- invariant3(node.id, "ID is required", { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 280, S: this, A: ["node.id", "'ID is required'"] });
428
- invariant3(!this.findNode(node.id), `node already exists: ${node.id}`, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 281, S: this, A: ["!this.findNode(node.id)", "`node already exists: ${node.id}`"] });
429
- const current = this._registry.get(this._graphAtom);
430
- this._registry.set(this._graphAtom, {
431
- ...current,
432
- nodes: [
433
- ...current.nodes,
434
- node
435
- ]
436
- });
437
- return node;
438
- }
439
- addEdge(edge) {
440
- invariant3(edge.source, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 293, S: this, A: ["edge.source", ""] });
441
- invariant3(edge.target, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 294, S: this, A: ["edge.target", ""] });
442
- if (!edge.id) {
443
- edge = {
444
- id: createEdgeId(edge),
445
- ...edge
446
- };
447
- }
448
- invariant3(!this.findNode(edge.id), void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 301, S: this, A: ["!this.findNode(edge.id)", ""] });
449
- const current = this._registry.get(this._graphAtom);
450
- this._registry.set(this._graphAtom, {
451
- ...current,
452
- edges: [
453
- ...current.edges,
454
- edge
455
- ]
456
- });
457
- return edge;
458
- }
459
- removeNode(id) {
460
- const current = this._registry.get(this._graphAtom);
461
- const removedEdges = current.edges.filter((edge) => edge.source === id || edge.target === id);
462
- const removedNodes = current.nodes.filter((node) => node.id === id);
463
- this._registry.set(this._graphAtom, {
464
- nodes: current.nodes.filter((node) => node.id !== id),
465
- edges: current.edges.filter((edge) => edge.source !== id && edge.target !== id)
466
- });
467
- return this.copy({
468
- nodes: removedNodes,
469
- edges: removedEdges
470
- });
471
- }
472
- removeEdge(id) {
473
- const current = this._registry.get(this._graphAtom);
474
- const removedEdges = current.edges.filter((edge) => edge.id === id);
475
- this._registry.set(this._graphAtom, {
476
- ...current,
477
- edges: current.edges.filter((edge) => edge.id !== id)
478
- });
479
- return this.copy({
480
- nodes: [],
481
- edges: removedEdges
482
- });
483
- }
484
- /**
485
- * Subscribe to graph changes.
486
- */
487
- subscribe(cb, fire = false) {
488
- if (fire) {
489
- cb(this, this.graph);
490
- }
491
- this._registry.get(this._graphAtom);
492
- return this._registry.subscribe(this._graphAtom, () => {
493
- cb(this, this.graph);
494
- });
495
- }
496
- };
497
- var Builder = class extends AbstractBuilder {
498
- call(cb) {
499
- cb(this);
500
- return this;
501
- }
502
- };
503
- export {
504
- Graph_exports as Graph,
505
- GraphModel_exports as GraphModel,
506
- SelectionModel
507
- };
508
- //# sourceMappingURL=index.mjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/selection.ts", "../../../src/Graph.ts", "../../../src/GraphModel.ts"],
4
- "sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { Atom, Registry } from '@effect-atom/atom-react';\n\nimport { invariant } from '@dxos/invariant';\n\nexport type SelectionMode = 'single' | 'multi';\n\nexport type SelectionModelProps = {\n mode?: SelectionMode;\n};\n\n/**\n * Reactive selection model.\n */\n// TODO(burdon): Reconcile with react-ui-attention.\nexport class SelectionModel {\n private readonly _registry: Registry.Registry;\n private readonly _selected: Atom.Writable<Set<string>>;\n private readonly _mode: SelectionMode;\n\n constructor({ mode = 'multi' }: SelectionModelProps = {}) {\n this._registry = Registry.make();\n this._selected = Atom.make<Set<string>>(new Set<string>());\n this._mode = mode;\n }\n\n /**\n * Returns the selected IDs atom for subscription.\n */\n get selected(): Atom.Atom<Set<string>> {\n return this._selected;\n }\n\n /**\n * Gets the current selected IDs as a Set.\n */\n getSelected(): Set<string> {\n return this._registry.get(this._selected);\n }\n\n /**\n * Gets the current selected IDs as an array.\n */\n getSelectedIds(): string[] {\n return Array.from(this._registry.get(this._selected).values());\n }\n\n /**\n * Subscribe to selection changes.\n */\n subscribe(cb: (selected: Set<string>) => void): () => void {\n // Prime the atom by reading before subscribing.\n this._registry.get(this._selected);\n\n return this._registry.subscribe(this._selected, () => {\n cb(this._registry.get(this._selected));\n });\n }\n\n toJSON(): { selected: string[] } {\n return {\n selected: this.getSelectedIds(),\n };\n }\n\n /**\n * Gets the current selection size.\n */\n getSize(): number {\n return this._registry.get(this._selected).size;\n }\n\n contains(id: string): boolean {\n return this._registry.get(this._selected).has(id);\n }\n\n clear(): void {\n this._registry.set(this._selected, new Set());\n }\n\n add(id: string): void {\n invariant(id);\n const current = this._registry.get(this._selected);\n this._registry.set(\n this._selected,\n new Set<string>(this._mode === 'single' ? [id] : [...Array.from(current.values()), id]),\n );\n }\n\n remove(id: string): void {\n invariant(id);\n const current = this._registry.get(this._selected);\n this._registry.set(this._selected, new Set<string>(Array.from(current.values()).filter((_id) => _id !== id)));\n }\n\n // TODO(burdon): Handle single select.\n\n setSelected(ids: string[], subtract = false): void {\n const current = this._registry.get(this._selected);\n this._registry.set(this._selected, new Set([...(subtract ? Array.from(current.values()) : []), ...ids]));\n }\n\n toggleSelected(ids: string[], subtract = false): void {\n const current = this._registry.get(this._selected);\n const set = new Set<string>(subtract ? Array.from(current.values()) : undefined);\n ids.forEach((id) => {\n if (current.has(id)) {\n set.delete(id);\n } else {\n set.add(id);\n }\n });\n\n this._registry.set(this._selected, set);\n }\n}\n", "//\n// Copyright 2024 DXOS.org\n//\n\n// @import-as-namespace\n\nimport * as Schema from 'effect/Schema';\n\nimport { invariant } from '@dxos/invariant';\nimport { type Specialize } from '@dxos/util';\n\n//\n// Node\n//\n\nexport const Node = Schema.Struct({\n id: Schema.String,\n type: Schema.optional(Schema.String),\n data: Schema.optional(Schema.Any),\n});\n\ninterface BaseNode extends Schema.Schema.Type<typeof Node> {}\n\nexport declare namespace Node {\n export type Any = Specialize<BaseNode, { data?: any }>;\n export type Node<Data = any> = Specialize<BaseNode, { data: Data }>;\n}\n\n//\n// Edge\n//\n\nexport const Edge = Schema.Struct({\n id: Schema.String,\n type: Schema.optional(Schema.String),\n source: Schema.String,\n target: Schema.String,\n data: Schema.optional(Schema.Any),\n});\n\ninterface BaseEdge extends Schema.Schema.Type<typeof Edge> {}\n\nexport declare namespace Edge {\n export type Any = Specialize<BaseEdge, { data?: any }>;\n export type Edge<Data = any> = Specialize<BaseEdge, { data: Data }>;\n}\n\nconst KEY_REGEX = /\\w+/;\n\n// NOTE: The `relation` is different from the `type`.\ntype EdgeMeta = { source: string; target: string; relation?: string };\n\nexport const createEdgeId = ({ source, target, relation }: EdgeMeta) => {\n invariant(source.match(KEY_REGEX), `invalid source: ${source}`);\n invariant(target.match(KEY_REGEX), `invalid target: ${target}`);\n return [source, relation, target].join('_');\n};\n\nexport const parseEdgeId = (id: string): EdgeMeta => {\n const [source, relation, target] = id.split('_');\n invariant(source.length && target.length);\n return { source, relation: relation.length ? relation : undefined, target };\n};\n\n//\n// Graph\n//\n\nexport const Graph = Schema.Struct({\n id: Schema.optional(Schema.String),\n nodes: Schema.mutable(Schema.Array(Node)),\n edges: Schema.mutable(Schema.Array(Edge)),\n});\n\nexport interface Any extends Schema.Schema.Type<typeof Graph> {}\n\nexport type Graph<Node extends Node.Any, Edge extends Edge.Any> = Specialize<\n Any,\n {\n nodes: Node[];\n edges: Edge[];\n }\n>;\n", "//\n// Copyright 2024 DXOS.org\n//\n\n// @import-as-namespace\n\nimport { Atom, type Registry } from '@effect-atom/atom-react';\n\nimport { inspectCustom } from '@dxos/debug';\nimport { failedInvariant, invariant } from '@dxos/invariant';\nimport { type MakeOptional, isTruthy, removeBy } from '@dxos/util';\n\nimport * as Graph from './Graph';\n\n/**\n * Optional function to wrap mutations (e.g., for ECHO objects that require Obj.update).\n */\nexport type GraphChangeFunction = (fn: () => void) => void;\n\n/**\n * Readonly Graph wrapper.\n */\nexport class ReadonlyGraphModel<\n Node extends Graph.Node.Any = Graph.Node.Any,\n Edge extends Graph.Edge.Any = Graph.Edge.Any,\n> {\n protected readonly _graph: Graph.Graph<Node, Edge>;\n /**\n * Optional function to wrap mutations.\n * When set, all graph mutations are wrapped in this function.\n */\n protected readonly _change?: GraphChangeFunction;\n\n /**\n * NOTE: Pass in simple Graph or Live.\n * @param graph - The graph data.\n * @param change - Optional function to wrap mutations (e.g., Obj.update for ECHO objects).\n */\n constructor(graph?: Graph.Graph<Node, Edge>, change?: GraphChangeFunction) {\n this._graph = graph ?? {\n nodes: [],\n edges: [],\n };\n this._change = change;\n }\n\n [inspectCustom]() {\n return this.toJSON();\n }\n\n /**\n * Return stable sorted JSON representation of graph.\n */\n toJSON() {\n return {\n nodes: this.nodes.length,\n edges: this.edges.length,\n };\n }\n\n get graph(): Graph.Graph<Node, Edge> {\n return this._graph;\n }\n\n get nodes(): Node[] {\n return this._graph.nodes;\n }\n\n get edges(): Edge[] {\n return this._graph.edges;\n }\n\n //\n // Nodes\n //\n\n findNode(id: string): Node | undefined {\n return this.nodes.find((node) => node.id === id);\n }\n\n getNode(id: string): Node {\n return this.findNode(id) ?? failedInvariant();\n }\n\n filterNodes({ type }: Partial<Graph.Node.Any> = {}): Node[] {\n return this.nodes.filter((node) => !type || type === node.type);\n }\n\n //\n // Edges\n //\n\n findEdge(id: string): Edge | undefined {\n return this.edges.find((edge) => edge.id === id);\n }\n\n getEdge(id: string): Edge {\n return this.findEdge(id) ?? failedInvariant();\n }\n\n filterEdges({ type, source, target }: Partial<Graph.Edge.Any> = {}): Edge[] {\n return this.edges.filter(\n (edge) =>\n (!type || type === edge.type) && (!source || source === edge.source) && (!target || target === edge.target),\n );\n }\n\n //\n // Traverse\n //\n\n traverse(root: Node): Node[] {\n return this._traverse(root);\n }\n\n private _traverse(root: Node, visited: Set<string> = new Set()): Node[] {\n if (visited.has(root.id)) {\n return [];\n }\n\n visited.add(root.id);\n const targets = this.filterEdges({ source: root.id })\n .map((edge) => this.getNode(edge.target))\n .filter(isTruthy);\n\n return [root, ...targets.flatMap((target) => this._traverse(target, visited))];\n }\n}\n\n/**\n * Mutable Graph wrapper.\n */\nexport abstract class AbstractGraphModel<\n Node extends Graph.Node.Any = Graph.Node.Any,\n Edge extends Graph.Edge.Any = Graph.Edge.Any,\n Model extends AbstractGraphModel<Node, Edge, Model, Builder> = any,\n Builder extends AbstractBuilder<Node, Edge, Model> = AbstractBuilder<Node, Edge, Model>,\n> extends ReadonlyGraphModel<Node, Edge> {\n /**\n * Allows chaining.\n */\n abstract get builder(): Builder;\n\n /**\n * Shallow copy of provided graph.\n */\n abstract copy(graph?: Partial<Graph.Graph<Node, Edge>>): Model;\n\n /**\n * Execute a mutation on the graph.\n * If a change function is set, wraps the mutation in it.\n */\n protected _mutate(fn: (graph: Graph.Graph<Node, Edge>) => void): void {\n if (this._change != null) {\n this._change(() => fn(this._graph));\n } else {\n fn(this._graph);\n }\n }\n\n clear(): this {\n this._mutate((graph) => {\n graph.nodes.length = 0;\n graph.edges.length = 0;\n });\n return this;\n }\n\n addGraph(graph: Model): this {\n this.addNodes(graph.nodes);\n this.addEdges(graph.edges);\n return this;\n }\n\n addGraphs(graphs: Model[]): this {\n graphs.forEach((graph) => {\n this.addNodes(graph.nodes);\n this.addEdges(graph.edges);\n });\n return this;\n }\n\n addNode(node: Node): Node {\n invariant(node.id, 'ID is required');\n invariant(!this.findNode(node.id), `node already exists: ${node.id}`);\n this._mutate((graph) => {\n graph.nodes.push(node);\n });\n return node;\n }\n\n addNodes(nodes: Node[]): Node[] {\n return nodes.map((node) => this.addNode(node));\n }\n\n addEdge(edge: MakeOptional<Edge, 'id'>): Edge {\n invariant(edge.source);\n invariant(edge.target);\n if (!edge.id) {\n // TODO(burdon): Generate random id.\n edge = { id: Graph.createEdgeId(edge), ...edge };\n }\n invariant(!this.findNode(edge.id!));\n this._mutate((graph) => {\n graph.edges.push(edge as Edge);\n });\n return edge as Edge;\n }\n\n addEdges(edges: Edge[]): Edge[] {\n return edges.map((edge) => this.addEdge(edge));\n }\n\n removeNode(id: string): Model {\n let removedEdges: Edge[] = [];\n let removedNodes: Node[] = [];\n this._mutate((graph) => {\n removedEdges = removeBy<Edge>(graph.edges as Edge[], (edge) => edge.source === id || edge.target === id);\n removedNodes = removeBy<Node>(graph.nodes as Node[], (node) => node.id === id);\n });\n return this.copy({ nodes: removedNodes, edges: removedEdges });\n }\n\n removeNodes(ids: string[]): Model {\n const graphs = ids.map((id) => this.removeNode(id));\n return this.copy().addGraphs(graphs);\n }\n\n removeEdge(id: string): Model {\n let removedEdges: Edge[] = [];\n this._mutate((graph) => {\n removedEdges = removeBy<Edge>(graph.edges as Edge[], (edge) => edge.id === id);\n });\n return this.copy({ nodes: [], edges: removedEdges });\n }\n\n removeEdges(ids: string[]): Model {\n const graphs = ids.map((id) => this.removeEdge(id));\n return this.copy().addGraphs(graphs);\n }\n}\n\n/**\n * Chainable builder wrapper\n */\nexport abstract class AbstractBuilder<\n Node extends Graph.Node.Any,\n Edge extends Graph.Edge.Any,\n Model extends GraphModel<Node, Edge>,\n> {\n constructor(protected readonly _model: Model) {}\n\n get model(): Model {\n return this._model;\n }\n\n call(cb: (builder: this) => void): this {\n cb(this);\n return this;\n }\n\n getNode(id: string): Node {\n return this.model.getNode(id);\n }\n\n addNode(node: Node): this {\n this._model.addNode(node);\n return this;\n }\n\n addEdge(edge: MakeOptional<Edge, 'id'>): this {\n this._model.addEdge(edge);\n return this;\n }\n\n addNodes(nodes: Node[]): this {\n this._model.addNodes(nodes);\n return this;\n }\n\n addEdges(edges: Edge[]): this {\n this._model.addEdges(edges);\n return this;\n }\n}\n\n/**\n * Basic model.\n */\nexport class GraphModel<\n Node extends Graph.Node.Any = Graph.Node.Any,\n Edge extends Graph.Edge.Any = Graph.Edge.Any,\n> extends AbstractGraphModel<Node, Edge, GraphModel<Node, Edge>, Builder<Node, Edge>> {\n override get builder() {\n return new Builder<Node, Edge>(this);\n }\n\n override copy(graph?: Partial<Graph.Graph<Node, Edge>>): GraphModel<Node, Edge> {\n return new GraphModel<Node, Edge>(graph as Graph.Graph<Node, Edge>);\n }\n}\n\nexport type Subscription = <Node extends Graph.Node.Any = Graph.Node.Any, Edge extends Graph.Edge.Any = Graph.Edge.Any>(\n model: ReactiveGraphModel<Node, Edge>,\n graph: Graph.Graph<Node, Edge>,\n) => void;\n\n/**\n * Basic reactive model using Effect Atoms.\n */\n// NOTE: Unlike Preact Signals' `live()` which uses proxies for transparent reactivity,\n// Effect Atom requires explicit `registry.set()` calls. All mutation methods must be\n// overridden to update the atom immutably rather than mutating `_graph` directly.\nexport class ReactiveGraphModel<\n Node extends Graph.Node.Any = Graph.Node.Any,\n Edge extends Graph.Edge.Any = Graph.Edge.Any,\n> extends GraphModel<Node, Edge> {\n private readonly _graphAtom: Atom.Writable<Graph.Graph<Node, Edge>>;\n\n constructor(\n private readonly _registry: Registry.Registry,\n graph?: Partial<Graph.Graph<Node, Edge>>,\n ) {\n const initialGraph: Graph.Graph<Node, Edge> = {\n nodes: (graph?.nodes ?? []) as Node[],\n edges: (graph?.edges ?? []) as Edge[],\n };\n super(initialGraph);\n this._graphAtom = Atom.make<Graph.Graph<Node, Edge>>(initialGraph);\n }\n\n get registry(): Registry.Registry {\n return this._registry;\n }\n\n /**\n * Get the graph atom for reactive subscriptions.\n */\n get graphAtom(): Atom.Writable<Graph.Graph<Node, Edge>> {\n return this._graphAtom;\n }\n\n override get graph(): Graph.Graph<Node, Edge> {\n return this._registry.get(this._graphAtom);\n }\n\n override get nodes(): Node[] {\n return this.graph.nodes;\n }\n\n override get edges(): Edge[] {\n return this.graph.edges;\n }\n\n override copy(graph?: Partial<Graph.Graph<Node, Edge>>): ReactiveGraphModel<Node, Edge> {\n return new ReactiveGraphModel<Node, Edge>(this._registry, graph);\n }\n\n override clear(): this {\n this._registry.set(this._graphAtom, {\n nodes: [],\n edges: [],\n });\n return this;\n }\n\n /**\n * Set the entire graph at once, triggering a single notification.\n */\n setGraph(graph: Graph.Graph<Node, Edge>): this {\n this._registry.set(this._graphAtom, graph);\n return this;\n }\n\n override addNode(node: Node): Node {\n invariant(node.id, 'ID is required');\n invariant(!this.findNode(node.id), `node already exists: ${node.id}`);\n const current = this._registry.get(this._graphAtom);\n this._registry.set(this._graphAtom, {\n ...current,\n nodes: [...current.nodes, node],\n });\n return node;\n }\n\n override addEdge(edge: MakeOptional<Edge, 'id'>): Edge {\n invariant(edge.source);\n invariant(edge.target);\n if (!edge.id) {\n edge = { id: Graph.createEdgeId(edge), ...edge };\n }\n invariant(!this.findNode(edge.id!));\n const current = this._registry.get(this._graphAtom);\n this._registry.set(this._graphAtom, {\n ...current,\n edges: [...current.edges, edge as Edge],\n });\n return edge as Edge;\n }\n\n override removeNode(id: string): ReactiveGraphModel<Node, Edge> {\n const current = this._registry.get(this._graphAtom);\n const removedEdges = current.edges.filter((edge) => edge.source === id || edge.target === id);\n const removedNodes = current.nodes.filter((node) => node.id === id);\n\n this._registry.set(this._graphAtom, {\n nodes: current.nodes.filter((node) => node.id !== id),\n edges: current.edges.filter((edge) => edge.source !== id && edge.target !== id),\n });\n\n return this.copy({ nodes: removedNodes, edges: removedEdges });\n }\n\n override removeEdge(id: string): ReactiveGraphModel<Node, Edge> {\n const current = this._registry.get(this._graphAtom);\n const removedEdges = current.edges.filter((edge) => edge.id === id);\n\n this._registry.set(this._graphAtom, {\n ...current,\n edges: current.edges.filter((edge) => edge.id !== id),\n });\n\n return this.copy({ nodes: [], edges: removedEdges });\n }\n\n /**\n * Subscribe to graph changes.\n */\n subscribe(cb: Subscription, fire = false): () => void {\n if (fire) {\n cb(this, this.graph);\n }\n\n // Prime the atom by reading before subscribing to avoid double-fire on first mutation.\n this._registry.get(this._graphAtom);\n return this._registry.subscribe(this._graphAtom, () => {\n cb(this, this.graph);\n });\n }\n}\n\n/**\n * Basic builder.\n */\nexport class Builder<\n Node extends Graph.Node.Any = Graph.Node.Any,\n Edge extends Graph.Edge.Any = Graph.Edge.Any,\n> extends AbstractBuilder<Node, Edge, GraphModel<Node, Edge>> {\n override call(cb: (builder: this) => void): this {\n cb(this);\n return this;\n }\n}\n"],
5
- "mappings": ";;;;;;;AAIA,SAASA,MAAMC,gBAAgB;AAE/B,SAASC,iBAAiB;AAQ1B,IAAA,eAAA;AAMmBC,IAAAA,iBAAAA,MAAsC;EACtCC;EAEjB;;cAEOD,EAAAA,OAAYH,QAAKK,IAAkB,CAAA,GAAIC;AAC5C,SAAKF,YAAQG,SAAAA,KAAAA;AACf,SAAA,YAAA,KAAA,KAAA,oBAAA,IAAA,CAAA;AAEA,SAAA,QAAA;;;;;EAKA,IAAA,WAAA;AAEA,WAAA,KAAA;;;;;EAKA,cAAA;AAEA,WAAA,KAAA,UAAA,IAAA,KAAA,SAAA;;;;;EAKA,iBAAA;AAEA,WAAA,MAAA,KAAA,KAAA,UAAA,IAAA,KAAA,SAAA,EAAA,OAAA,CAAA;;;;;YAKOC,IAAAA;SAGHC,UAAQD,IAAAA,KAAUE,SAASP;AAC7B,WAAA,KAAA,UAAA,UAAA,KAAA,WAAA,MAAA;AACF,SAAA,KAAA,UAAA,IAAA,KAAA,SAAA,CAAA;IAEAQ,CAAAA;;WAEIC;AACF,WAAA;MACF,UAAA,KAAA,eAAA;IAEA;;;;;EAKA,UAAA;AAEAC,WAAmB,KAAW,UAAA,IAAA,KAAA,SAAA,EAAA;;EAE9B,SAAA,IAAA;AAEAC,WAAc,KAAA,UAAA,IAAA,KAAA,SAAA,EAAA,IAAA,EAAA;;EAEd,QAAA;AAEIC,SAAkB,UAAA,IAAA,KAAA,WAAA,oBAAA,IAAA,CAAA;;MAEpB,IAAA;AACA,cAAKP,IAAAA,QACH,EAAA,YAAKL,YACW,GAAA,cAAe,GAAA,IAAA,GAAA,MAAW,GAAA,CAAA,MAAA,EAAA,EAAA,CAAA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"make", "Set", "mode", "_registry", "cb", "get", "toJSON", "selected", "contains", "clear", "id", "remove", "current", "Array", "values", "filter", "_id", "setSelected", "subtract", "ids", "toggleSelected", "set", "forEach", "has", "delete", "add", "Schema", "invariant", "__dxlog_file", "type", "String", "data", "source", "target", "optional", "KEY_REGEX", "relation", "join", "parseEdgeId", "nodes", "Array", "edges", "Atom", "inspectCustom", "failedInvariant", "invariant", "isTruthy", "removeBy", "__dxlog_file", "nodes", "edges", "_change", "inspectCustom", "graph", "getNode", "filterNodes", "type", "getEdge", "filterEdges", "source", "target", "_traverse", "root", "visited", "Set", "id", "targets", "fn", "_graph", "clear", "addGraph", "addEdges", "addGraphs", "graphs", "addNodes", "addNode", "node", "invariant", "_mutate", "push", "addEdge", "edge", "removeNode", "removedNodes", "removedEdges", "removeBy", "removeNodes", "copy", "removeEdge", "removeEdges", "_model", "model", "call", "_graphAtom", "initialGraph", "_registry", "registry", "Atom", "current", "set", "Graph", "filter", "cb"]
7
- }
@@ -1 +0,0 @@
1
- {"inputs":{"src/selection.ts":{"bytes":10953,"imports":[{"path":"@effect-atom/atom-react","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true}],"format":"esm"},"src/Graph.ts":{"bytes":6561,"imports":[{"path":"effect/Schema","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true}],"format":"esm"},"src/GraphModel.ts":{"bytes":39340,"imports":[{"path":"@effect-atom/atom-react","kind":"import-statement","external":true},{"path":"@dxos/debug","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"src/Graph.ts","kind":"import-statement","original":"./Graph"}],"format":"esm"},"src/index.ts":{"bytes":679,"imports":[{"path":"src/selection.ts","kind":"import-statement","original":"./selection"},{"path":"src/Graph.ts","kind":"import-statement","original":"./Graph"},{"path":"src/GraphModel.ts","kind":"import-statement","original":"./GraphModel"}],"format":"esm"}},"outputs":{"dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":28012},"dist/lib/browser/index.mjs":{"imports":[{"path":"@effect-atom/atom-react","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"effect/Schema","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@effect-atom/atom-react","kind":"import-statement","external":true},{"path":"@dxos/debug","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"exports":["Graph","GraphModel","SelectionModel"],"entryPoint":"src/index.ts","inputs":{"src/selection.ts":{"bytesInOutput":2620},"src/index.ts":{"bytesInOutput":0},"src/Graph.ts":{"bytesInOutput":1691},"src/GraphModel.ts":{"bytesInOutput":9582}},"bytes":14246}}}