@dxos/graph 0.8.2-main.f11618f → 0.8.2-main.fbd8ed0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/browser/index.mjs +81 -78
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +77 -76
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +81 -78
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/create.d.ts +9 -0
- package/dist/types/src/create.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +1 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/model.d.ts +1 -1
- package/dist/types/src/model.d.ts.map +1 -1
- package/dist/types/src/types.d.ts +29 -29
- package/dist/types/src/types.d.ts.map +1 -1
- package/dist/types/src/util.d.ts +0 -8
- package/dist/types/src/util.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +17 -13
- package/src/create.ts +52 -0
- package/src/index.ts +1 -0
- package/src/model.test.ts +5 -6
- package/src/model.ts +1 -1
- package/src/types.ts +23 -19
- package/src/util.ts +0 -47
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Schema } from 'effect';
|
|
2
2
|
import { type Specialize } from '@dxos/util';
|
|
3
|
-
export declare const BaseGraphNode:
|
|
4
|
-
id: typeof
|
|
5
|
-
type:
|
|
6
|
-
data:
|
|
3
|
+
export declare const BaseGraphNode: Schema.Struct<{
|
|
4
|
+
id: typeof Schema.String;
|
|
5
|
+
type: Schema.optional<typeof Schema.String>;
|
|
6
|
+
data: Schema.optional<typeof Schema.Any>;
|
|
7
7
|
}>;
|
|
8
8
|
/** Raw base type. */
|
|
9
|
-
export type BaseGraphNode =
|
|
9
|
+
export type BaseGraphNode = Schema.Schema.Type<typeof BaseGraphNode>;
|
|
10
10
|
/** Typed node data. */
|
|
11
11
|
export type GraphNode<Data = any, Optional extends boolean = false> = Specialize<BaseGraphNode, Optional extends true ? {
|
|
12
12
|
data?: Data;
|
|
@@ -16,15 +16,15 @@ export type GraphNode<Data = any, Optional extends boolean = false> = Specialize
|
|
|
16
16
|
export declare namespace GraphNode {
|
|
17
17
|
type Optional<T = any> = GraphNode<T, true>;
|
|
18
18
|
}
|
|
19
|
-
export declare const BaseGraphEdge:
|
|
20
|
-
id: typeof
|
|
21
|
-
type:
|
|
22
|
-
data:
|
|
23
|
-
source: typeof
|
|
24
|
-
target: typeof
|
|
19
|
+
export declare const BaseGraphEdge: Schema.Struct<{
|
|
20
|
+
id: typeof Schema.String;
|
|
21
|
+
type: Schema.optional<typeof Schema.String>;
|
|
22
|
+
data: Schema.optional<typeof Schema.Any>;
|
|
23
|
+
source: typeof Schema.String;
|
|
24
|
+
target: typeof Schema.String;
|
|
25
25
|
}>;
|
|
26
26
|
/** Raw base type. */
|
|
27
|
-
export type BaseGraphEdge =
|
|
27
|
+
export type BaseGraphEdge = Schema.Schema.Type<typeof BaseGraphEdge>;
|
|
28
28
|
/** Typed edge data. */
|
|
29
29
|
export type GraphEdge<Data = any, Optional extends boolean = false> = Specialize<BaseGraphEdge, Optional extends true ? {
|
|
30
30
|
data?: Data;
|
|
@@ -37,23 +37,23 @@ export declare namespace GraphEdge {
|
|
|
37
37
|
/**
|
|
38
38
|
* Generic graph.
|
|
39
39
|
*/
|
|
40
|
-
export declare const Graph:
|
|
41
|
-
id:
|
|
42
|
-
nodes:
|
|
43
|
-
id: typeof
|
|
44
|
-
type:
|
|
45
|
-
data:
|
|
46
|
-
}>,
|
|
47
|
-
readonly key: typeof
|
|
48
|
-
readonly value: typeof
|
|
40
|
+
export declare const Graph: Schema.Struct<{
|
|
41
|
+
id: Schema.optional<typeof Schema.String>;
|
|
42
|
+
nodes: Schema.mutable<Schema.Array$<Schema.extend<Schema.Struct<{
|
|
43
|
+
id: typeof Schema.String;
|
|
44
|
+
type: Schema.optional<typeof Schema.String>;
|
|
45
|
+
data: Schema.optional<typeof Schema.Any>;
|
|
46
|
+
}>, Schema.TypeLiteral<{}, readonly [{
|
|
47
|
+
readonly key: typeof Schema.String;
|
|
48
|
+
readonly value: typeof Schema.Any;
|
|
49
49
|
}]>>>>;
|
|
50
|
-
edges:
|
|
51
|
-
id: typeof
|
|
52
|
-
type:
|
|
53
|
-
data:
|
|
54
|
-
source: typeof
|
|
55
|
-
target: typeof
|
|
50
|
+
edges: Schema.mutable<Schema.Array$<Schema.Struct<{
|
|
51
|
+
id: typeof Schema.String;
|
|
52
|
+
type: Schema.optional<typeof Schema.String>;
|
|
53
|
+
data: Schema.optional<typeof Schema.Any>;
|
|
54
|
+
source: typeof Schema.String;
|
|
55
|
+
target: typeof Schema.String;
|
|
56
56
|
}>>>;
|
|
57
57
|
}>;
|
|
58
|
-
export type Graph =
|
|
58
|
+
export type Graph = Schema.Schema.Type<typeof Graph>;
|
|
59
59
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/types.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/types.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,eAAO,MAAM,aAAa;;;;EAIxB,CAAC;AAEH,qBAAqB;AACrB,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,aAAa,CAAC,CAAC;AAErE,uBAAuB;AACvB,MAAM,MAAM,SAAS,CAAC,IAAI,GAAG,GAAG,EAAE,QAAQ,SAAS,OAAO,GAAG,KAAK,IAAI,UAAU,CAC9E,aAAa,EACb,QAAQ,SAAS,IAAI,GAAG;IAAE,IAAI,CAAC,EAAE,IAAI,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,IAAI,CAAA;CAAE,CACzD,CAAC;AAEF,MAAM,CAAC,OAAO,WAAW,SAAS,CAAC;IACjC,KAAY,QAAQ,CAAC,CAAC,GAAG,GAAG,IAAI,SAAS,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;CACpD;AAED,eAAO,MAAM,aAAa;;;;;;EAMxB,CAAC;AAEH,qBAAqB;AACrB,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,aAAa,CAAC,CAAC;AAErE,uBAAuB;AACvB,MAAM,MAAM,SAAS,CAAC,IAAI,GAAG,GAAG,EAAE,QAAQ,SAAS,OAAO,GAAG,KAAK,IAAI,UAAU,CAC9E,aAAa,EACb,QAAQ,SAAS,IAAI,GAAG;IAAE,IAAI,CAAC,EAAE,IAAI,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,IAAI,CAAA;CAAE,CACzD,CAAC;AAEF,MAAM,CAAC,OAAO,WAAW,SAAS,CAAC;IACjC,KAAY,QAAQ,CAAC,CAAC,GAAG,GAAG,IAAI,SAAS,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;CACpD;AAUD;;GAEG;AACH,eAAO,MAAM,KAAK;;;;;;;;;;;;;;;;;EAIhB,CAAC;AAEH,MAAM,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,KAAK,CAAC,CAAC"}
|
package/dist/types/src/util.d.ts
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import { type ReactiveEchoObject } from '@dxos/echo-db';
|
|
2
|
-
import { GraphModel } from './model';
|
|
3
|
-
import { type GraphNode } from './types';
|
|
4
1
|
type EdgeMeta = {
|
|
5
2
|
source: string;
|
|
6
3
|
target: string;
|
|
@@ -8,10 +5,5 @@ type EdgeMeta = {
|
|
|
8
5
|
};
|
|
9
6
|
export declare const createEdgeId: ({ source, target, relation }: EdgeMeta) => string;
|
|
10
7
|
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
8
|
export {};
|
|
17
9
|
//# sourceMappingURL=util.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../../src/util.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../../src/util.ts"],"names":[],"mappings":"AASA,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,GAAI,8BAA8B,QAAQ,WAIlE,CAAC;AAEF,eAAO,MAAM,WAAW,GAAI,IAAI,MAAM,KAAG,QAIxC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"5.
|
|
1
|
+
{"version":"5.8.3"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/graph",
|
|
3
|
-
"version": "0.8.2-main.
|
|
3
|
+
"version": "0.8.2-main.fbd8ed0",
|
|
4
4
|
"description": "Low-level graph API",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -32,24 +32,28 @@
|
|
|
32
32
|
],
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@preact/signals-core": "^1.6.0",
|
|
35
|
+
"effect": "3.14.21",
|
|
35
36
|
"lodash.defaultsdeep": "^4.6.1",
|
|
36
|
-
"@dxos/async": "0.8.2-main.
|
|
37
|
-
"@dxos/
|
|
38
|
-
"@dxos/
|
|
39
|
-
"@dxos/
|
|
40
|
-
"@dxos/
|
|
41
|
-
"@dxos/schema": "0.8.2-main.
|
|
42
|
-
"@dxos/
|
|
43
|
-
"@dxos/
|
|
44
|
-
"@dxos/
|
|
37
|
+
"@dxos/async": "0.8.2-main.fbd8ed0",
|
|
38
|
+
"@dxos/debug": "0.8.2-main.fbd8ed0",
|
|
39
|
+
"@dxos/echo-db": "0.8.2-main.fbd8ed0",
|
|
40
|
+
"@dxos/invariant": "0.8.2-main.fbd8ed0",
|
|
41
|
+
"@dxos/log": "0.8.2-main.fbd8ed0",
|
|
42
|
+
"@dxos/echo-schema": "0.8.2-main.fbd8ed0",
|
|
43
|
+
"@dxos/live-object": "0.8.2-main.fbd8ed0",
|
|
44
|
+
"@dxos/schema": "0.8.2-main.fbd8ed0",
|
|
45
|
+
"@dxos/util": "0.8.2-main.fbd8ed0"
|
|
45
46
|
},
|
|
46
47
|
"devDependencies": {
|
|
47
48
|
"@antv/graphlib": "^2.0.4",
|
|
48
49
|
"@antv/layout": "^1.2.13",
|
|
49
50
|
"@types/lodash.defaultsdeep": "^4.6.6",
|
|
50
|
-
"@dxos/echo-
|
|
51
|
-
"@dxos/random": "0.8.2-main.
|
|
52
|
-
"@dxos/echo-
|
|
51
|
+
"@dxos/echo-schema": "0.8.2-main.fbd8ed0",
|
|
52
|
+
"@dxos/random": "0.8.2-main.fbd8ed0",
|
|
53
|
+
"@dxos/echo-db": "0.8.2-main.fbd8ed0"
|
|
54
|
+
},
|
|
55
|
+
"peerDependencies": {
|
|
56
|
+
"effect": "^3.13.3"
|
|
53
57
|
},
|
|
54
58
|
"publishConfig": {
|
|
55
59
|
"access": "public"
|
package/src/create.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { type AnyLiveObject } from '@dxos/echo-db';
|
|
6
|
+
import { FormatEnum, getSchema } from '@dxos/echo-schema';
|
|
7
|
+
import { live } from '@dxos/live-object';
|
|
8
|
+
import { log } from '@dxos/log';
|
|
9
|
+
import { getSchemaProperties } from '@dxos/schema';
|
|
10
|
+
|
|
11
|
+
import { GraphModel } from './model';
|
|
12
|
+
import { Graph, type GraphNode } from './types';
|
|
13
|
+
import { createEdgeId } from './util';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Creates a new reactive graph from a set of ECHO objects.
|
|
17
|
+
* References are mapped onto graph edges.
|
|
18
|
+
*/
|
|
19
|
+
export const createGraph = (objects: AnyLiveObject<any>[]): GraphModel<GraphNode<AnyLiveObject<any>>> => {
|
|
20
|
+
const graph = new GraphModel<GraphNode<AnyLiveObject<any>>>(live(Graph, { nodes: [], edges: [] }));
|
|
21
|
+
|
|
22
|
+
// Map objects.
|
|
23
|
+
objects.forEach((object) => {
|
|
24
|
+
graph.addNode({ id: object.id, type: object.typename, data: object });
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
// Find references.
|
|
28
|
+
objects.forEach((object) => {
|
|
29
|
+
const schema = getSchema(object);
|
|
30
|
+
if (!schema) {
|
|
31
|
+
log.info('no schema for object', { id: object.id.slice(0, 8) });
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Parse schema to follow referenced objects.
|
|
36
|
+
for (const prop of getSchemaProperties(schema.ast, object)) {
|
|
37
|
+
if (prop.format === FormatEnum.Ref) {
|
|
38
|
+
const source = object;
|
|
39
|
+
const target = object[prop.name]?.target;
|
|
40
|
+
if (target) {
|
|
41
|
+
graph.addEdge({
|
|
42
|
+
id: createEdgeId({ source: source.id, target: target.id, relation: String(prop.name) }),
|
|
43
|
+
source: source.id,
|
|
44
|
+
target: target.id,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
return graph;
|
|
52
|
+
};
|
package/src/index.ts
CHANGED
package/src/model.test.ts
CHANGED
|
@@ -2,21 +2,20 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import { Schema } from 'effect';
|
|
5
6
|
import { describe, test } from 'vitest';
|
|
6
7
|
|
|
7
|
-
import { S } from '@dxos/echo-schema';
|
|
8
|
-
|
|
9
8
|
import { GraphModel } from './model';
|
|
10
9
|
import { BaseGraphNode, type GraphNode } from './types';
|
|
11
10
|
|
|
12
|
-
const TestNode =
|
|
11
|
+
const TestNode = Schema.extend(
|
|
13
12
|
BaseGraphNode,
|
|
14
|
-
|
|
15
|
-
value:
|
|
13
|
+
Schema.Struct({
|
|
14
|
+
value: Schema.String,
|
|
16
15
|
}),
|
|
17
16
|
);
|
|
18
17
|
|
|
19
|
-
type TestNode =
|
|
18
|
+
type TestNode = Schema.Schema.Type<typeof TestNode>;
|
|
20
19
|
|
|
21
20
|
type TestData = { value: string };
|
|
22
21
|
|
package/src/model.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { failedInvariant, invariant } from '@dxos/invariant';
|
|
|
7
7
|
import { getSnapshot } from '@dxos/live-object';
|
|
8
8
|
import { type MakeOptional, isNotFalsy, removeBy, stripUndefined } from '@dxos/util';
|
|
9
9
|
|
|
10
|
-
import { type
|
|
10
|
+
import { type BaseGraphEdge, type BaseGraphNode, type Graph, type GraphEdge, type GraphNode } from './types';
|
|
11
11
|
import { createEdgeId } from './util';
|
|
12
12
|
|
|
13
13
|
/**
|
package/src/types.ts
CHANGED
|
@@ -2,17 +2,18 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { Schema } from 'effect';
|
|
6
|
+
|
|
6
7
|
import { type Specialize } from '@dxos/util';
|
|
7
8
|
|
|
8
|
-
export const BaseGraphNode =
|
|
9
|
-
id:
|
|
10
|
-
type:
|
|
11
|
-
data:
|
|
9
|
+
export const BaseGraphNode = Schema.Struct({
|
|
10
|
+
id: Schema.String,
|
|
11
|
+
type: Schema.optional(Schema.String),
|
|
12
|
+
data: Schema.optional(Schema.Any),
|
|
12
13
|
});
|
|
13
14
|
|
|
14
15
|
/** Raw base type. */
|
|
15
|
-
export type BaseGraphNode =
|
|
16
|
+
export type BaseGraphNode = Schema.Schema.Type<typeof BaseGraphNode>;
|
|
16
17
|
|
|
17
18
|
/** Typed node data. */
|
|
18
19
|
export type GraphNode<Data = any, Optional extends boolean = false> = Specialize<
|
|
@@ -24,16 +25,16 @@ export declare namespace GraphNode {
|
|
|
24
25
|
export type Optional<T = any> = GraphNode<T, true>;
|
|
25
26
|
}
|
|
26
27
|
|
|
27
|
-
export const BaseGraphEdge =
|
|
28
|
-
id:
|
|
29
|
-
type:
|
|
30
|
-
data:
|
|
31
|
-
source:
|
|
32
|
-
target:
|
|
28
|
+
export const BaseGraphEdge = Schema.Struct({
|
|
29
|
+
id: Schema.String,
|
|
30
|
+
type: Schema.optional(Schema.String),
|
|
31
|
+
data: Schema.optional(Schema.Any),
|
|
32
|
+
source: Schema.String,
|
|
33
|
+
target: Schema.String,
|
|
33
34
|
});
|
|
34
35
|
|
|
35
36
|
/** Raw base type. */
|
|
36
|
-
export type BaseGraphEdge =
|
|
37
|
+
export type BaseGraphEdge = Schema.Schema.Type<typeof BaseGraphEdge>;
|
|
37
38
|
|
|
38
39
|
/** Typed edge data. */
|
|
39
40
|
export type GraphEdge<Data = any, Optional extends boolean = false> = Specialize<
|
|
@@ -48,15 +49,18 @@ export declare namespace GraphEdge {
|
|
|
48
49
|
/**
|
|
49
50
|
* Allows any additional properties on graph nodes.
|
|
50
51
|
*/
|
|
51
|
-
const ExtendableBaseGraphNode =
|
|
52
|
+
const ExtendableBaseGraphNode = Schema.extend(
|
|
53
|
+
BaseGraphNode,
|
|
54
|
+
Schema.Struct({}, { key: Schema.String, value: Schema.Any }),
|
|
55
|
+
);
|
|
52
56
|
|
|
53
57
|
/**
|
|
54
58
|
* Generic graph.
|
|
55
59
|
*/
|
|
56
|
-
export const Graph =
|
|
57
|
-
id:
|
|
58
|
-
nodes:
|
|
59
|
-
edges:
|
|
60
|
+
export const Graph = Schema.Struct({
|
|
61
|
+
id: Schema.optional(Schema.String),
|
|
62
|
+
nodes: Schema.mutable(Schema.Array(ExtendableBaseGraphNode)),
|
|
63
|
+
edges: Schema.mutable(Schema.Array(BaseGraphEdge)),
|
|
60
64
|
});
|
|
61
65
|
|
|
62
|
-
export type Graph =
|
|
66
|
+
export type Graph = Schema.Schema.Type<typeof Graph>;
|
package/src/util.ts
CHANGED
|
@@ -2,15 +2,7 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { type ReactiveEchoObject } from '@dxos/echo-db';
|
|
6
|
-
import { FormatEnum, getSchema } from '@dxos/echo-schema';
|
|
7
5
|
import { invariant } from '@dxos/invariant';
|
|
8
|
-
import { live } from '@dxos/live-object';
|
|
9
|
-
import { log } from '@dxos/log';
|
|
10
|
-
import { getSchemaProperties } from '@dxos/schema';
|
|
11
|
-
|
|
12
|
-
import { GraphModel } from './model';
|
|
13
|
-
import { Graph, type GraphNode } from './types';
|
|
14
6
|
|
|
15
7
|
const KEY_REGEX = /\w+/;
|
|
16
8
|
|
|
@@ -28,42 +20,3 @@ export const parseEdgeId = (id: string): EdgeMeta => {
|
|
|
28
20
|
invariant(source.length && target.length);
|
|
29
21
|
return { source, relation: relation.length ? relation : undefined, target };
|
|
30
22
|
};
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Creates a new reactive graph from a set of ECHO objects.
|
|
34
|
-
* References are mapped onto graph edges.
|
|
35
|
-
*/
|
|
36
|
-
export const createGraph = (objects: ReactiveEchoObject<any>[]): GraphModel<GraphNode<ReactiveEchoObject<any>>> => {
|
|
37
|
-
const graph = new GraphModel<GraphNode<ReactiveEchoObject<any>>>(live(Graph, { nodes: [], edges: [] }));
|
|
38
|
-
|
|
39
|
-
// Map objects.
|
|
40
|
-
objects.forEach((object) => {
|
|
41
|
-
graph.addNode({ id: object.id, type: object.typename, data: object });
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
// Find references.
|
|
45
|
-
objects.forEach((object) => {
|
|
46
|
-
const schema = getSchema(object);
|
|
47
|
-
if (!schema) {
|
|
48
|
-
log.info('no schema for object', { id: object.id.slice(0, 8) });
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// Parse schema to follow referenced objects.
|
|
53
|
-
for (const prop of getSchemaProperties(schema.ast, object)) {
|
|
54
|
-
if (prop.format === FormatEnum.Ref) {
|
|
55
|
-
const source = object;
|
|
56
|
-
const target = object[prop.name]?.target;
|
|
57
|
-
if (target) {
|
|
58
|
-
graph.addEdge({
|
|
59
|
-
id: createEdgeId({ source: source.id, target: target.id, relation: String(prop.name) }),
|
|
60
|
-
source: source.id,
|
|
61
|
-
target: target.id,
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
return graph;
|
|
69
|
-
};
|