@dxos/graph 0.7.5-feature-compute.4d9d99a

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,381 @@
1
+ import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
2
+
3
+ // packages/common/graph/src/model.ts
4
+ import { inspectCustom } from "@dxos/debug";
5
+ import { failedInvariant, invariant as invariant2 } from "@dxos/invariant";
6
+ import { getSnapshot } from "@dxos/live-object";
7
+ import { isNotFalsy, removeBy, stripUndefined } from "@dxos/util";
8
+
9
+ // packages/common/graph/src/util.ts
10
+ import { FormatEnum } from "@dxos/echo-schema";
11
+ import { invariant } from "@dxos/invariant";
12
+ import { getSchema, create } from "@dxos/live-object";
13
+ import { log } from "@dxos/log";
14
+ import { getSchemaProperties } from "@dxos/schema";
15
+
16
+ // packages/common/graph/src/types.ts
17
+ import { S } from "@dxos/echo-schema";
18
+ var BaseGraphNode = S.Struct({
19
+ id: S.String,
20
+ type: S.optional(S.String),
21
+ data: S.optional(S.Any)
22
+ });
23
+ var BaseGraphEdge = S.Struct({
24
+ id: S.String,
25
+ type: S.optional(S.String),
26
+ data: S.optional(S.Any),
27
+ source: S.String,
28
+ target: S.String
29
+ });
30
+ var ExtendableBaseGraphNode = S.extend(BaseGraphNode, S.Struct({}, {
31
+ key: S.String,
32
+ value: S.Any
33
+ }));
34
+ var Graph = S.Struct({
35
+ id: S.optional(S.String),
36
+ nodes: S.mutable(S.Array(ExtendableBaseGraphNode)),
37
+ edges: S.mutable(S.Array(BaseGraphEdge))
38
+ });
39
+
40
+ // packages/common/graph/src/util.ts
41
+ var __dxlog_file = "/home/runner/work/dxos/dxos/packages/common/graph/src/util.ts";
42
+ var KEY_REGEX = /\w+/;
43
+ var createEdgeId = ({ source, target, relation }) => {
44
+ invariant(source.match(KEY_REGEX), `invalid source: ${source}`, {
45
+ F: __dxlog_file,
46
+ L: 21,
47
+ S: void 0,
48
+ A: [
49
+ "source.match(KEY_REGEX)",
50
+ "`invalid source: ${source}`"
51
+ ]
52
+ });
53
+ invariant(target.match(KEY_REGEX), `invalid target: ${target}`, {
54
+ F: __dxlog_file,
55
+ L: 22,
56
+ S: void 0,
57
+ A: [
58
+ "target.match(KEY_REGEX)",
59
+ "`invalid target: ${target}`"
60
+ ]
61
+ });
62
+ return [
63
+ source,
64
+ relation,
65
+ target
66
+ ].join("_");
67
+ };
68
+ var parseEdgeId = (id) => {
69
+ const [source, relation, target] = id.split("_");
70
+ invariant(source.length && target.length, void 0, {
71
+ F: __dxlog_file,
72
+ L: 28,
73
+ S: void 0,
74
+ A: [
75
+ "source.length && target.length",
76
+ ""
77
+ ]
78
+ });
79
+ return {
80
+ source,
81
+ relation: relation.length ? relation : void 0,
82
+ target
83
+ };
84
+ };
85
+ var createGraph = (objects) => {
86
+ const graph = new GraphModel(create(Graph, {
87
+ nodes: [],
88
+ edges: []
89
+ }));
90
+ objects.forEach((object) => {
91
+ graph.addNode({
92
+ id: object.id,
93
+ type: object.typename,
94
+ data: object
95
+ });
96
+ });
97
+ objects.forEach((object) => {
98
+ const schema = getSchema(object);
99
+ if (!schema) {
100
+ log.info("no schema for object", {
101
+ id: object.id.slice(0, 8)
102
+ }, {
103
+ F: __dxlog_file,
104
+ L: 48,
105
+ S: void 0,
106
+ C: (f, a) => f(...a)
107
+ });
108
+ return;
109
+ }
110
+ for (const prop of getSchemaProperties(schema.ast, object)) {
111
+ if (prop.format === FormatEnum.Ref) {
112
+ const source = object;
113
+ const target = object[prop.name]?.target;
114
+ if (target) {
115
+ graph.addEdge({
116
+ id: createEdgeId({
117
+ source: source.id,
118
+ target: target.id,
119
+ relation: String(prop.name)
120
+ }),
121
+ source: source.id,
122
+ target: target.id
123
+ });
124
+ }
125
+ }
126
+ }
127
+ });
128
+ return graph;
129
+ };
130
+
131
+ // packages/common/graph/src/model.ts
132
+ var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/common/graph/src/model.ts";
133
+ var ReadonlyGraphModel = class {
134
+ /**
135
+ * NOTE: Pass in simple Graph or ReactiveObject.
136
+ */
137
+ constructor(graph) {
138
+ this._graph = graph ?? {
139
+ nodes: [],
140
+ edges: []
141
+ };
142
+ }
143
+ [inspectCustom]() {
144
+ return this.toJSON();
145
+ }
146
+ /**
147
+ * Return stable sorted JSON representation of graph.
148
+ */
149
+ // TODO(burdon): Create separate toJson method with computed signal.
150
+ toJSON() {
151
+ const { id, nodes, edges } = getSnapshot(this._graph);
152
+ nodes.sort(({ id: a }, { id: b }) => a.localeCompare(b));
153
+ edges.sort(({ id: a }, { id: b }) => a.localeCompare(b));
154
+ return stripUndefined({
155
+ id,
156
+ nodes,
157
+ edges
158
+ });
159
+ }
160
+ get graph() {
161
+ return this._graph;
162
+ }
163
+ get nodes() {
164
+ return this._graph.nodes;
165
+ }
166
+ get edges() {
167
+ return this._graph.edges;
168
+ }
169
+ //
170
+ // Nodes
171
+ //
172
+ findNode(id) {
173
+ return this.nodes.find((node) => node.id === id);
174
+ }
175
+ getNode(id) {
176
+ return this.findNode(id) ?? failedInvariant();
177
+ }
178
+ filterNodes({ type } = {}) {
179
+ return this.nodes.filter((node) => !type || type === node.type);
180
+ }
181
+ //
182
+ // Edges
183
+ //
184
+ findEdge(id) {
185
+ return this.edges.find((edge) => edge.id === id);
186
+ }
187
+ getEdge(id) {
188
+ return this.findEdge(id) ?? failedInvariant();
189
+ }
190
+ filterEdges({ type, source, target } = {}) {
191
+ return this.edges.filter((edge) => (!type || type === edge.type) && (!source || source === edge.source) && (!target || target === edge.target));
192
+ }
193
+ //
194
+ // Traverse
195
+ //
196
+ traverse(root) {
197
+ return this._traverse(root);
198
+ }
199
+ _traverse(root, visited = /* @__PURE__ */ new Set()) {
200
+ if (visited.has(root.id)) {
201
+ return [];
202
+ }
203
+ visited.add(root.id);
204
+ const targets = this.filterEdges({
205
+ source: root.id
206
+ }).map((edge) => this.getNode(edge.target)).filter(isNotFalsy);
207
+ return [
208
+ root,
209
+ ...targets.flatMap((target) => this._traverse(target, visited))
210
+ ];
211
+ }
212
+ };
213
+ var AbstractGraphModel = class extends ReadonlyGraphModel {
214
+ clear() {
215
+ this._graph.nodes.length = 0;
216
+ this._graph.edges.length = 0;
217
+ return this;
218
+ }
219
+ addGraph(graph) {
220
+ this.addNodes(graph.nodes);
221
+ this.addEdges(graph.edges);
222
+ return this;
223
+ }
224
+ addGraphs(graphs) {
225
+ graphs.forEach((graph) => {
226
+ this.addNodes(graph.nodes);
227
+ this.addEdges(graph.edges);
228
+ });
229
+ return this;
230
+ }
231
+ addNode(node) {
232
+ invariant2(node.id, "ID is required", {
233
+ F: __dxlog_file2,
234
+ L: 153,
235
+ S: this,
236
+ A: [
237
+ "node.id",
238
+ "'ID is required'"
239
+ ]
240
+ });
241
+ invariant2(!this.findNode(node.id), `node already exists: ${node.id}`, {
242
+ F: __dxlog_file2,
243
+ L: 154,
244
+ S: this,
245
+ A: [
246
+ "!this.findNode(node.id)",
247
+ "`node already exists: ${node.id}`"
248
+ ]
249
+ });
250
+ this._graph.nodes.push(node);
251
+ return node;
252
+ }
253
+ addNodes(nodes) {
254
+ return nodes.map((node) => this.addNode(node));
255
+ }
256
+ addEdge(edge) {
257
+ invariant2(edge.source, void 0, {
258
+ F: __dxlog_file2,
259
+ L: 164,
260
+ S: this,
261
+ A: [
262
+ "edge.source",
263
+ ""
264
+ ]
265
+ });
266
+ invariant2(edge.target, void 0, {
267
+ F: __dxlog_file2,
268
+ L: 165,
269
+ S: this,
270
+ A: [
271
+ "edge.target",
272
+ ""
273
+ ]
274
+ });
275
+ if (!edge.id) {
276
+ edge = {
277
+ id: createEdgeId(edge),
278
+ ...edge
279
+ };
280
+ }
281
+ invariant2(!this.findNode(edge.id), void 0, {
282
+ F: __dxlog_file2,
283
+ L: 170,
284
+ S: this,
285
+ A: [
286
+ "!this.findNode(edge.id!)",
287
+ ""
288
+ ]
289
+ });
290
+ this._graph.edges.push(edge);
291
+ return edge;
292
+ }
293
+ addEdges(edges) {
294
+ return edges.map((edge) => this.addEdge(edge));
295
+ }
296
+ removeNode(id) {
297
+ const nodes = removeBy(this._graph.nodes, (node) => node.id === id);
298
+ const edges = removeBy(this._graph.edges, (edge) => edge.source === id || edge.target === id);
299
+ return this.copy({
300
+ nodes,
301
+ edges
302
+ });
303
+ }
304
+ removeNodes(ids) {
305
+ const graphs = ids.map((id) => this.removeNode(id));
306
+ return this.copy().addGraphs(graphs);
307
+ }
308
+ removeEdge(id) {
309
+ const edges = removeBy(this._graph.edges, (edge) => edge.id === id);
310
+ return this.copy({
311
+ nodes: [],
312
+ edges
313
+ });
314
+ }
315
+ removeEdges(ids) {
316
+ const graphs = ids.map((id) => this.removeEdge(id));
317
+ return this.copy().addGraphs(graphs);
318
+ }
319
+ };
320
+ var AbstractGraphBuilder = class {
321
+ constructor(_model) {
322
+ this._model = _model;
323
+ }
324
+ get model() {
325
+ return this._model;
326
+ }
327
+ call(cb) {
328
+ cb(this);
329
+ return this;
330
+ }
331
+ getNode(id) {
332
+ return this.model.getNode(id);
333
+ }
334
+ addNode(node) {
335
+ this._model.addNode(node);
336
+ return this;
337
+ }
338
+ addEdge(edge) {
339
+ this._model.addEdge(edge);
340
+ return this;
341
+ }
342
+ addNodes(nodes) {
343
+ this._model.addNodes(nodes);
344
+ return this;
345
+ }
346
+ addEdges(edges) {
347
+ this._model.addEdges(edges);
348
+ return this;
349
+ }
350
+ };
351
+ var GraphModel = class _GraphModel extends AbstractGraphModel {
352
+ get builder() {
353
+ return new GraphBuilder(this);
354
+ }
355
+ copy(graph) {
356
+ return new _GraphModel({
357
+ nodes: graph?.nodes ?? [],
358
+ edges: graph?.edges ?? []
359
+ });
360
+ }
361
+ };
362
+ var GraphBuilder = class extends AbstractGraphBuilder {
363
+ call(cb) {
364
+ cb(this);
365
+ return this;
366
+ }
367
+ };
368
+ export {
369
+ AbstractGraphBuilder,
370
+ AbstractGraphModel,
371
+ BaseGraphEdge,
372
+ BaseGraphNode,
373
+ Graph,
374
+ GraphBuilder,
375
+ GraphModel,
376
+ ReadonlyGraphModel,
377
+ createEdgeId,
378
+ createGraph,
379
+ parseEdgeId
380
+ };
381
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/model.ts", "../../../src/util.ts", "../../../src/types.ts"],
4
+ "sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { inspectCustom } from '@dxos/debug';\nimport { failedInvariant, invariant } from '@dxos/invariant';\nimport { getSnapshot } from '@dxos/live-object';\nimport { type MakeOptional, isNotFalsy, removeBy, stripUndefined } from '@dxos/util';\n\nimport { type Graph, type GraphNode, type GraphEdge, type BaseGraphNode, type BaseGraphEdge } from './types';\nimport { createEdgeId } from './util';\n\n/**\n * Wrapper class contains reactive nodes and edges.\n */\nexport class ReadonlyGraphModel<\n Node extends BaseGraphNode = BaseGraphNode,\n Edge extends BaseGraphEdge = BaseGraphEdge,\n> {\n protected readonly _graph: Graph;\n\n /**\n * NOTE: Pass in simple Graph or ReactiveObject.\n */\n constructor(graph?: Graph) {\n this._graph = graph ?? { nodes: [], edges: [] };\n }\n\n [inspectCustom]() {\n return this.toJSON();\n }\n\n /**\n * Return stable sorted JSON representation of graph.\n */\n // TODO(burdon): Create separate toJson method with computed signal.\n toJSON() {\n const { id, nodes, edges } = getSnapshot(this._graph);\n nodes.sort(({ id: a }, { id: b }) => a.localeCompare(b));\n edges.sort(({ id: a }, { id: b }) => a.localeCompare(b));\n return stripUndefined({ id, nodes, edges });\n }\n\n get graph(): Graph {\n return this._graph;\n }\n\n get nodes(): Node[] {\n return this._graph.nodes as Node[];\n }\n\n get edges(): Edge[] {\n return this._graph.edges as Edge[];\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<GraphNode> = {}): 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<GraphEdge> = {}): 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(isNotFalsy);\n\n return [root, ...targets.flatMap((target) => this._traverse(target, visited))];\n }\n}\n\n/**\n * Typed wrapper.\n */\nexport abstract class AbstractGraphModel<\n Node extends BaseGraphNode,\n Edge extends BaseGraphEdge,\n Model extends AbstractGraphModel<Node, Edge, Model, Builder>,\n Builder extends AbstractGraphBuilder<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>): Model;\n\n clear(): this {\n this._graph.nodes.length = 0;\n this._graph.edges.length = 0;\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._graph.nodes.push(node);\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: createEdgeId(edge), ...edge };\n }\n invariant(!this.findNode(edge.id!));\n this._graph.edges.push(edge as Edge);\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 const nodes = removeBy<Node>(this._graph.nodes as Node[], (node) => node.id === id);\n const edges = removeBy<Edge>(this._graph.edges as Edge[], (edge) => edge.source === id || edge.target === id);\n return this.copy({ nodes, edges });\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 const edges = removeBy<Edge>(this._graph.edges as Edge[], (edge) => edge.id === id);\n return this.copy({ nodes: [], edges });\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 wrapper\n */\nexport abstract class AbstractGraphBuilder<\n Node extends BaseGraphNode,\n Edge extends BaseGraphEdge,\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\nexport class GraphModel<\n Node extends BaseGraphNode = BaseGraphNode,\n Edge extends BaseGraphEdge = BaseGraphEdge,\n> extends AbstractGraphModel<Node, Edge, GraphModel<Node, Edge>, GraphBuilder<Node, Edge>> {\n override get builder() {\n return new GraphBuilder<Node, Edge>(this);\n }\n\n override copy(graph?: Partial<Graph>) {\n return new GraphModel<Node, Edge>({ nodes: graph?.nodes ?? [], edges: graph?.edges ?? [] });\n }\n}\n\nexport class GraphBuilder<\n Node extends BaseGraphNode = BaseGraphNode,\n Edge extends BaseGraphEdge = BaseGraphEdge,\n> extends AbstractGraphBuilder<Node, Edge, GraphModel<Node, Edge>> {\n override call(cb: (builder: this) => void) {\n cb(this);\n return this;\n }\n}\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { type ReactiveEchoObject } from '@dxos/echo-db';\nimport { FormatEnum } from '@dxos/echo-schema';\nimport { invariant } from '@dxos/invariant';\nimport { getSchema, create } from '@dxos/live-object';\nimport { log } from '@dxos/log';\nimport { getSchemaProperties } from '@dxos/schema';\n\nimport { GraphModel } from './model';\nimport { Graph, type GraphNode } from './types';\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 * Creates a new reactive graph from a set of ECHO objects.\n * References are mapped onto graph edges.\n */\nexport const createGraph = (objects: ReactiveEchoObject<any>[]): GraphModel<GraphNode<ReactiveEchoObject<any>>> => {\n const graph = new GraphModel<GraphNode<ReactiveEchoObject<any>>>(create(Graph, { nodes: [], edges: [] }));\n\n // Map objects.\n objects.forEach((object) => {\n graph.addNode({ id: object.id, type: object.typename, data: object });\n });\n\n // Find references.\n objects.forEach((object) => {\n const schema = getSchema(object);\n if (!schema) {\n log.info('no schema for object', { id: object.id.slice(0, 8) });\n return;\n }\n\n // Parse schema to follow referenced objects.\n for (const prop of getSchemaProperties(schema.ast, object)) {\n if (prop.format === FormatEnum.Ref) {\n const source = object;\n const target = object[prop.name]?.target;\n if (target) {\n graph.addEdge({\n id: createEdgeId({ source: source.id, target: target.id, relation: String(prop.name) }),\n source: source.id,\n target: target.id,\n });\n }\n }\n }\n });\n\n return graph;\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { S } from '@dxos/echo-schema';\nimport { type Specialize } from '@dxos/util';\n\nexport const BaseGraphNode = S.Struct({\n id: S.String,\n type: S.optional(S.String),\n data: S.optional(S.Any),\n});\n\n/** Raw base type. */\nexport type BaseGraphNode = S.Schema.Type<typeof BaseGraphNode>;\n/** Typed node data. */\nexport type GraphNode<Data = any, Optional extends boolean = false> = Specialize<\n BaseGraphNode,\n Optional extends true ? { data?: Data } : { data: Data }\n>;\n\nexport declare namespace GraphNode {\n export type Optional<T = any> = GraphNode<T, true>;\n}\n\nexport const BaseGraphEdge = S.Struct({\n id: S.String,\n type: S.optional(S.String),\n data: S.optional(S.Any),\n source: S.String,\n target: S.String,\n});\n\n/** Raw base type. */\nexport type BaseGraphEdge = S.Schema.Type<typeof BaseGraphEdge>;\n\n/** Typed edge data. */\nexport type GraphEdge<Data = any, Optional extends boolean = false> = Specialize<\n BaseGraphEdge,\n Optional extends true ? { data?: Data } : { data: Data }\n>;\n\nexport declare namespace GraphEdge {\n export type Optional<T = any> = GraphEdge<T, true>;\n}\n\n/**\n * Allows any additional properties on graph nodes.\n */\nconst ExtendableBaseGraphNode = S.extend(BaseGraphNode, S.Struct({}, { key: S.String, value: S.Any }));\n\n/**\n * Generic graph.\n */\nexport const Graph = S.Struct({\n id: S.optional(S.String),\n nodes: S.mutable(S.Array(ExtendableBaseGraphNode)),\n edges: S.mutable(S.Array(BaseGraphEdge)),\n});\n\nexport type Graph = S.Schema.Type<typeof Graph>;\n"],
5
+ "mappings": ";;;AAIA,SAASA,qBAAqB;AAC9B,SAASC,iBAAiBC,aAAAA,kBAAiB;AAC3C,SAASC,mBAAmB;AAC5B,SAA4BC,Y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EAAGV,UAAUC,MAAAA;EAC/B;AACF;AAKO,IAAec,uBAAf,MAAeA;EAKpB5D,YAA+B6D,QAAe;SAAfA,SAAAA;EAAgB;EAE/C,IAAIC,QAAe;AACjB,WAAO,KAAKD;EACd;EAEAE,KAAKC,IAAmC;AACtCA,OAAG,IAAI;AACP,WAAO;EACT;EAEA/C,QAAQV,IAAkB;AACxB,WAAO,KAAKuD,MAAM7C,QAAQV,EAAAA;EAC5B;EAEAyC,QAAQhC,MAAkB;AACxB,SAAK6C,OAAOb,QAAQhC,IAAAA;AACpB,WAAO;EACT;EAEAmC,QAAQ5B,MAAsC;AAC5C,SAAKsC,OAAOV,QAAQ5B,IAAAA;AACpB,WAAO;EACT;EAEAoB,SAASxC,OAAqB;AAC5B,SAAK0D,OAAOlB,SAASxC,KAAAA;AACrB,WAAO;EACT;EAEAyC,SAASxC,OAAqB;AAC5B,SAAKyD,OAAOjB,SAASxC,KAAAA;AACrB,WAAO;EACT;AACF;AAEO,IAAM6D,aAAN,MAAMA,oBAGH1B,mBAAAA;EACR,IAAa2B,UAAU;AACrB,WAAO,IAAIC,aAAyB,IAAI;EAC1C;EAESZ,KAAKtD,OAAwB;AACpC,WAAO,IAAIgE,YAAuB;MAAE9D,OAAOF,OAAOE,SAAS,CAAA;MAAIC,OAAOH,OAAOG,SAAS,CAAA;IAAG,CAAA;EAC3F;AACF;AAEO,IAAM+D,eAAN,cAGGP,qBAAAA;EACCG,KAAKC,IAA6B;AACzCA,OAAG,IAAI;AACP,WAAO;EACT;AACF;",
6
+ "names": ["inspectCustom", "failedInvariant", "invariant", "getSnapshot", "isNotFalsy", "removeBy", "stripUndefined", "FormatEnum", "invariant", "getSchema", "create", "log", "getSchemaProperties", "S", "BaseGraphNode", "S", "Struct", "id", "String", "type", "optional", "data", "Any", "BaseGraphEdge", "source", "target", "ExtendableBaseGraphNode", "extend", "key", "value", "Graph", "nodes", "mutable", "Array", "edges", "KEY_REGEX", "createEdgeId", "source", "target", "relation", "invariant", "match", "join", "parseEdgeId", "id", "split", "length", "undefined", "createGraph", "objects", "graph", "GraphModel", "create", "Graph", "nodes", "edges", "forEach", "object", "addNode", "type", "typename", "data", "schema", "getSchema", "log", "info", "slice", "prop", "getSchemaProperties", "ast", "format", "FormatEnum", "Ref", "name", "addEdge", "String", "ReadonlyGraphModel", "constructor", "graph", "_graph", "nodes", "edges", "inspectCustom", "toJSON", "id", "getSnapshot", "sort", "a", "b", "localeCompare", "stripUndefined", "findNode", "find", "node", "getNode", "failedInvariant", "filterNodes", "type", "filter", "findEdge", "edge", "getEdge", "filterEdges", "source", "target", "traverse", "root", "_traverse", "visited", "Set", "has", "add", "targets", "map", "isNotFalsy", "flatMap", "AbstractGraphModel", "clear", "length", "addGraph", "addNodes", "addEdges", "addGraphs", "graphs", "forEach", "addNode", "invariant", "push", "addEdge", "createEdgeId", "removeNode", "removeBy", "copy", "removeNodes", "ids", "removeEdge", "removeEdges", "AbstractGraphBuilder", "_model", "model", "call", "cb", "GraphModel", "builder", "GraphBuilder"]
7
+ }
@@ -0,0 +1 @@
1
+ {"inputs":{"packages/common/graph/src/types.ts":{"bytes":4437,"imports":[{"path":"@dxos/echo-schema","kind":"import-statement","external":true}],"format":"esm"},"packages/common/graph/src/util.ts":{"bytes":9104,"imports":[{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/live-object","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/schema","kind":"import-statement","external":true},{"path":"packages/common/graph/src/model.ts","kind":"import-statement","original":"./model"},{"path":"packages/common/graph/src/types.ts","kind":"import-statement","original":"./types"}],"format":"esm"},"packages/common/graph/src/model.ts":{"bytes":23788,"imports":[{"path":"@dxos/debug","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/live-object","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"packages/common/graph/src/util.ts","kind":"import-statement","original":"./util"}],"format":"esm"},"packages/common/graph/src/index.ts":{"bytes":647,"imports":[{"path":"packages/common/graph/src/model.ts","kind":"import-statement","original":"./model"},{"path":"packages/common/graph/src/types.ts","kind":"import-statement","original":"./types"},{"path":"packages/common/graph/src/util.ts","kind":"import-statement","original":"./util"}],"format":"esm"}},"outputs":{"packages/common/graph/dist/lib/node-esm/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":18690},"packages/common/graph/dist/lib/node-esm/index.mjs":{"imports":[{"path":"@dxos/debug","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/live-object","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/live-object","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/schema","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true}],"exports":["AbstractGraphBuilder","AbstractGraphModel","BaseGraphEdge","BaseGraphNode","Graph","GraphBuilder","GraphModel","ReadonlyGraphModel","createEdgeId","createGraph","parseEdgeId"],"entryPoint":"packages/common/graph/src/index.ts","inputs":{"packages/common/graph/src/model.ts":{"bytesInOutput":5449},"packages/common/graph/src/util.ts":{"bytesInOutput":2277},"packages/common/graph/src/types.ts":{"bytesInOutput":551},"packages/common/graph/src/index.ts":{"bytesInOutput":0}},"bytes":8795}}}
@@ -0,0 +1,4 @@
1
+ export * from './model';
2
+ export * from './types';
3
+ export * from './util';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC"}
@@ -0,0 +1,107 @@
1
+ import { inspectCustom } from '@dxos/debug';
2
+ import { type MakeOptional } from '@dxos/util';
3
+ import { type Graph, type GraphNode, type GraphEdge, type BaseGraphNode, type BaseGraphEdge } from './types';
4
+ /**
5
+ * Wrapper class contains reactive nodes and edges.
6
+ */
7
+ export declare class ReadonlyGraphModel<Node extends BaseGraphNode = BaseGraphNode, Edge extends BaseGraphEdge = BaseGraphEdge> {
8
+ protected readonly _graph: Graph;
9
+ /**
10
+ * NOTE: Pass in simple Graph or ReactiveObject.
11
+ */
12
+ constructor(graph?: Graph);
13
+ [inspectCustom](): {
14
+ id: string | undefined;
15
+ nodes: ({
16
+ readonly id: string;
17
+ readonly type?: string | undefined;
18
+ readonly data?: any;
19
+ } & {
20
+ readonly [x: string]: any;
21
+ })[];
22
+ edges: {
23
+ readonly id: string;
24
+ readonly type?: string | undefined;
25
+ readonly data?: any;
26
+ readonly source: string;
27
+ readonly target: string;
28
+ }[];
29
+ };
30
+ /**
31
+ * Return stable sorted JSON representation of graph.
32
+ */
33
+ toJSON(): {
34
+ id: string | undefined;
35
+ nodes: ({
36
+ readonly id: string;
37
+ readonly type?: string | undefined;
38
+ readonly data?: any;
39
+ } & {
40
+ readonly [x: string]: any;
41
+ })[];
42
+ edges: {
43
+ readonly id: string;
44
+ readonly type?: string | undefined;
45
+ readonly data?: any;
46
+ readonly source: string;
47
+ readonly target: string;
48
+ }[];
49
+ };
50
+ get graph(): Graph;
51
+ get nodes(): Node[];
52
+ get edges(): Edge[];
53
+ findNode(id: string): Node | undefined;
54
+ getNode(id: string): Node;
55
+ filterNodes({ type }?: Partial<GraphNode>): Node[];
56
+ findEdge(id: string): Edge | undefined;
57
+ getEdge(id: string): Edge;
58
+ filterEdges({ type, source, target }?: Partial<GraphEdge>): Edge[];
59
+ traverse(root: Node): Node[];
60
+ private _traverse;
61
+ }
62
+ /**
63
+ * Typed wrapper.
64
+ */
65
+ export declare abstract class AbstractGraphModel<Node extends BaseGraphNode, Edge extends BaseGraphEdge, Model extends AbstractGraphModel<Node, Edge, Model, Builder>, Builder extends AbstractGraphBuilder<Node, Edge, Model>> extends ReadonlyGraphModel<Node, Edge> {
66
+ /**
67
+ * Allows chaining.
68
+ */
69
+ abstract get builder(): Builder;
70
+ /**
71
+ * Shallow copy of provided graph.
72
+ */
73
+ abstract copy(graph?: Partial<Graph>): Model;
74
+ clear(): this;
75
+ addGraph(graph: Model): this;
76
+ addGraphs(graphs: Model[]): this;
77
+ addNode(node: Node): Node;
78
+ addNodes(nodes: Node[]): Node[];
79
+ addEdge(edge: MakeOptional<Edge, 'id'>): Edge;
80
+ addEdges(edges: Edge[]): Edge[];
81
+ removeNode(id: string): Model;
82
+ removeNodes(ids: string[]): Model;
83
+ removeEdge(id: string): Model;
84
+ removeEdges(ids: string[]): Model;
85
+ }
86
+ /**
87
+ * Chainable wrapper
88
+ */
89
+ export declare abstract class AbstractGraphBuilder<Node extends BaseGraphNode, Edge extends BaseGraphEdge, Model extends GraphModel<Node, Edge>> {
90
+ protected readonly _model: Model;
91
+ constructor(_model: Model);
92
+ get model(): Model;
93
+ call(cb: (builder: this) => void): this;
94
+ getNode(id: string): Node;
95
+ addNode(node: Node): this;
96
+ addEdge(edge: MakeOptional<Edge, 'id'>): this;
97
+ addNodes(nodes: Node[]): this;
98
+ addEdges(edges: Edge[]): this;
99
+ }
100
+ export declare class GraphModel<Node extends BaseGraphNode = BaseGraphNode, Edge extends BaseGraphEdge = BaseGraphEdge> extends AbstractGraphModel<Node, Edge, GraphModel<Node, Edge>, GraphBuilder<Node, Edge>> {
101
+ get builder(): GraphBuilder<Node, Edge>;
102
+ copy(graph?: Partial<Graph>): GraphModel<Node, Edge>;
103
+ }
104
+ export declare class GraphBuilder<Node extends BaseGraphNode = BaseGraphNode, Edge extends BaseGraphEdge = BaseGraphEdge> extends AbstractGraphBuilder<Node, Edge, GraphModel<Node, Edge>> {
105
+ call(cb: (builder: this) => void): this;
106
+ }
107
+ //# sourceMappingURL=model.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file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C,IAAI,KAAK,IAAI,KAAK,CAEjB;IAED,IAAI,CAAC,EAAE,EAAE,CAAC,OAAO,EAAE,IAAI,KAAK,IAAI,GAAG,IAAI;IAKvC,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI;IAIzB,OAAO,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI;IAKzB,OAAO,CAAC,IAAI,EAAE,YAAY,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,IAAI;IAK7C,QAAQ,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,IAAI;IAK7B,QAAQ,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,IAAI;CAI9B;AAED,qBAAa,UAAU,CACrB,IAAI,SAAS,aAAa,GAAG,aAAa,EAC1C,IAAI,SAAS,aAAa,GAAG,aAAa,CAC1C,SAAQ,kBAAkB,CAAC,IAAI,EAAE,IAAI,EAAE,UAAU,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,YAAY,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACxF,IAAa,OAAO,6BAEnB;IAEQ,IAAI,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,KAAK,CAAC;CAGrC;AAED,qBAAa,YAAY,CACvB,IAAI,SAAS,aAAa,GAAG,aAAa,EAC1C,IAAI,SAAS,aAAa,GAAG,aAAa,CAC1C,SAAQ,oBAAoB,CAAC,IAAI,EAAE,IAAI,EAAE,UAAU,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACvD,IAAI,CAAC,EAAE,EAAE,CAAC,OAAO,EAAE,IAAI,KAAK,IAAI;CAI1C"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=model.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model.test.d.ts","sourceRoot":"","sources":["../../../src/model.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,59 @@
1
+ import { S } from '@dxos/echo-schema';
2
+ import { type Specialize } from '@dxos/util';
3
+ export declare const BaseGraphNode: S.Struct<{
4
+ id: typeof S.String;
5
+ type: S.optional<typeof S.String>;
6
+ data: S.optional<typeof S.Any>;
7
+ }>;
8
+ /** Raw base type. */
9
+ export type BaseGraphNode = S.Schema.Type<typeof BaseGraphNode>;
10
+ /** Typed node data. */
11
+ export type GraphNode<Data = any, Optional extends boolean = false> = Specialize<BaseGraphNode, Optional extends true ? {
12
+ data?: Data;
13
+ } : {
14
+ data: Data;
15
+ }>;
16
+ export declare namespace GraphNode {
17
+ type Optional<T = any> = GraphNode<T, true>;
18
+ }
19
+ export declare const BaseGraphEdge: S.Struct<{
20
+ id: typeof S.String;
21
+ type: S.optional<typeof S.String>;
22
+ data: S.optional<typeof S.Any>;
23
+ source: typeof S.String;
24
+ target: typeof S.String;
25
+ }>;
26
+ /** Raw base type. */
27
+ export type BaseGraphEdge = S.Schema.Type<typeof BaseGraphEdge>;
28
+ /** Typed edge data. */
29
+ export type GraphEdge<Data = any, Optional extends boolean = false> = Specialize<BaseGraphEdge, Optional extends true ? {
30
+ data?: Data;
31
+ } : {
32
+ data: Data;
33
+ }>;
34
+ export declare namespace GraphEdge {
35
+ type Optional<T = any> = GraphEdge<T, true>;
36
+ }
37
+ /**
38
+ * Generic graph.
39
+ */
40
+ export declare const Graph: S.Struct<{
41
+ id: S.optional<typeof S.String>;
42
+ nodes: S.mutable<S.Array$<S.extend<S.Struct<{
43
+ id: typeof S.String;
44
+ type: S.optional<typeof S.String>;
45
+ data: S.optional<typeof S.Any>;
46
+ }>, S.TypeLiteral<{}, readonly [{
47
+ readonly key: typeof S.String;
48
+ readonly value: typeof S.Any;
49
+ }]>>>>;
50
+ edges: S.mutable<S.Array$<S.Struct<{
51
+ id: typeof S.String;
52
+ type: S.optional<typeof S.String>;
53
+ data: S.optional<typeof S.Any>;
54
+ source: typeof S.String;
55
+ target: typeof S.String;
56
+ }>>>;
57
+ }>;
58
+ export type Graph = S.Schema.Type<typeof Graph>;
59
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0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,IAAI,CAAC,CAAC;CACpD;AAOD;;GAEG;AACH,eAAO,MAAM,KAAK;;;;;;;;;;;;;;;;;EAIhB,CAAC;AAEH,MAAM,MAAM,KAAK,GAAG,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,KAAK,CAAC,CAAC"}
@@ -0,0 +1,17 @@
1
+ import { type ReactiveEchoObject } from '@dxos/echo-db';
2
+ import { GraphModel } from './model';
3
+ import { type GraphNode } from './types';
4
+ type EdgeMeta = {
5
+ source: string;
6
+ target: string;
7
+ relation?: string;
8
+ };
9
+ export declare const createEdgeId: ({ source, target, relation }: EdgeMeta) => string;
10
+ export declare const parseEdgeId: (id: string) => EdgeMeta;
11
+ /**
12
+ * Creates a new reactive graph from a set of ECHO objects.
13
+ * References are mapped onto graph edges.
14
+ */
15
+ export declare const createGraph: (objects: ReactiveEchoObject<any>[]) => GraphModel<GraphNode<ReactiveEchoObject<any>>>;
16
+ export {};
17
+ //# sourceMappingURL=util.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../../src/util.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAOxD,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAS,KAAK,SAAS,EAAE,MAAM,SAAS,CAAC;AAKhD,KAAK,QAAQ,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAEtE,eAAO,MAAM,YAAY,iCAAkC,QAAQ,WAIlE,CAAC;AAEF,eAAO,MAAM,WAAW,OAAQ,MAAM,KAAG,QAIxC,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,WAAW,YAAa,kBAAkB,CAAC,GAAG,CAAC,EAAE,KAAG,UAAU,CAAC,SAAS,CAAC,kBAAkB,CAAC,GAAG,CAAC,CAAC,CAiC7G,CAAC"}
@@ -0,0 +1 @@
1
+ {"version":"5.7.2"}