Skip to content

Commit c51b191

Browse files
Merge pull request #56 from commitd/stuarthendren/separation
Separates rdf and JSONGraph into modules
2 parents 5ba2fe4 + 294cd38 commit c51b191

32 files changed

+328
-711
lines changed

.github/workflows/ci.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ jobs:
9898
path: |
9999
./packages/all/dist
100100
./packages/graph/dist
101+
./packages/graph-rdf/dist
102+
./packages/graph-json/dist
101103
./packages/react/dist
102104
retention-days: 1
103105
unit-test-scan:
@@ -288,6 +290,11 @@ jobs:
288290
key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }}
289291
restore-keys: |
290292
${{ runner.os }}-npm-
293+
- name: Download build artifacts
294+
uses: actions/download-artifact@v2
295+
with:
296+
name: build-output
297+
path: packages
291298
- name: Publish Storybook
292299
if: github.ref == 'refs/heads/main'
293300
run: npm run storybook:deploy

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ This builds to the relevant `/dist` folders.
3737
The project is published as `@committed/components-graph` but is further separated into modules so the non-ui code can be used in the backend.
3838

3939
- `@committed/graph` - contains the graph models, types and API
40+
- `@committed/graph-rdf` - contains code to create graph models from RDF
41+
- `@committed/graph-json` - contains code to create graph models from JSONGraph
4042
- `@committed/component-graph-react` - contains the react specific UI components
4143

4244
### Storybook

package-lock.json

Lines changed: 58 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@
9494
"preset": "rollpkg",
9595
"projects": [
9696
"<rootDir>/packages/graph",
97+
"<rootDir>/packages/graph-json",
98+
"<rootDir>/packages/graph-rdf",
9799
"<rootDir>/packages/react",
98100
"<rootDir>/packages/all"
99101
],
@@ -170,6 +172,8 @@
170172
},
171173
"workspaces": [
172174
"packages/graph",
175+
"packages/graph-rdf",
176+
"packages/graph-json",
173177
"packages/react",
174178
"packages/all"
175179
]

packages/all/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
},
2727
"dependencies": {
2828
"@committed/graph": "*",
29+
"@committed/graph-json": "*",
30+
"@committed/graph-rdf": "*",
2931
"@committed/components-graph-react": "*"
3032
},
3133
"scripts": {

packages/all/src/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,11 @@
11
export * from '@committed/graph'
2+
export * from '@committed/graph-rdf'
23
export * from '@committed/components-graph-react'
4+
5+
import { Json } from '@committed/graph-json'
6+
import { Rdf } from '@committed/graph-rdf'
7+
8+
export const GraphBuilder = {
9+
fromJsonGraph: Json.buildGraph,
10+
fromRdfGraph: Rdf.buildGraph,
11+
}

packages/graph-json/package.json

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
{
2+
"name": "@committed/graph-json",
3+
"version": "0.0.0-development",
4+
"description": "Support for creating GraphModels from JSONGraph",
5+
"author": "Committed",
6+
"private": false,
7+
"license": "MIT",
8+
"main": "dist/committed-graph-json.cjs.js",
9+
"module": "dist/committed-graph-json.esm.js",
10+
"typings": "dist/index.d.ts",
11+
"sideEffects": false,
12+
"files": [
13+
"dist"
14+
],
15+
"publishConfig": {
16+
"access": "public",
17+
"registry": "https://registry.npmjs.org/"
18+
},
19+
"repository": {
20+
"type": "git",
21+
"url": "git+https://github.com/commitd/components-graph.git"
22+
},
23+
"bugs": {
24+
"url": "https://github.com/commitd/components-graph/issues"
25+
},
26+
"homepage": "https://github.com/commitd/components-graph#readme",
27+
"engines": {
28+
"node": ">=10"
29+
},
30+
"jest": {
31+
"preset": "rollpkg",
32+
"collectCoverage": true,
33+
"testResultsProcessor": "jest-sonar-reporter",
34+
"moduleDirectories": [
35+
"node_modules",
36+
"src"
37+
],
38+
"collectCoverageFrom": [
39+
"src/**/*.{ts,tsx}",
40+
"!src/types/**/*"
41+
],
42+
"coveragePathIgnorePatterns": [
43+
"/src/typings.d.ts",
44+
"test/*",
45+
".*/index.ts",
46+
".*.test.ts",
47+
".*.test.tsx",
48+
".*.stories.tsx"
49+
]
50+
},
51+
"lint-staged": {
52+
"*.{ts,tsx}": [
53+
"jest --bail --passWithNoTests"
54+
]
55+
},
56+
"scripts": {
57+
"clean": "shx rm -rf dist",
58+
"build": "rollpkg build --noStats --tsconfig ./tsconfig.build.json",
59+
"watch": "rollpkg watch",
60+
"lint": "eslint './src/**/*.{ts,tsx}'",
61+
"test": "jest --passWithNoTests",
62+
"test:ci": "jest --coverage",
63+
"test:watch": "jest --watchAll",
64+
"precommit": "lint-staged"
65+
},
66+
"dependencies": {
67+
"@committed/graph": "*",
68+
"uuid": "^8.3.2"
69+
}
70+
}

packages/graph/src/graph/fromJsonGraph.test.ts renamed to packages/graph-json/src/JsonGraph.test.ts

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
import {
2-
largeGraph,
3-
smallGraph,
4-
veryLargeGraph,
5-
} from 'test/data/jsonGraphExamples'
6-
import { fromJsonGraph } from './fromJsonGraph'
7-
import { JSONGraph, ModelNode } from './types'
1+
import { largeGraph, smallGraph, veryLargeGraph } from 'examples'
2+
import { buildGraph, Graph as JSONGraph } from 'JsonGraph'
3+
import { ModelNode } from '@committed/graph'
84

95
it('Create from json graph spec graph values', () => {
10-
const contentModel = fromJsonGraph(smallGraph)
6+
const contentModel = buildGraph(smallGraph)
117
expect(Object.keys(contentModel.nodes)).toHaveLength(4)
128
expect(Object.keys(contentModel.edges)).toHaveLength(2)
139

@@ -23,7 +19,7 @@ it('Create from json graph spec graph values', () => {
2319
})
2420

2521
it('Create from json graph', () => {
26-
const contentModel = fromJsonGraph({
22+
const contentModel = buildGraph({
2723
nodes: {
2824
n1: {
2925
metadata: { a1: true, a2: 10, a3: 'test', a4: { object: 'example' } },
@@ -55,40 +51,40 @@ it('Create from json graph', () => {
5551
})
5652

5753
it('Create from json graph spec graph values', () => {
58-
const contentModel = fromJsonGraph(largeGraph)
54+
const contentModel = buildGraph(largeGraph)
5955
expect(Object.keys(contentModel.nodes)).toHaveLength(9)
6056
expect(Object.keys(contentModel.edges)).toHaveLength(8)
6157
})
6258

6359
it('ContentModel does support single from graphs', () => {
64-
const contentModel = fromJsonGraph({
60+
const contentModel = buildGraph({
6561
graphs: [smallGraph.graph as JSONGraph],
6662
})
6763
expect(Object.keys(contentModel.nodes)).toHaveLength(4)
6864
expect(Object.keys(contentModel.edges)).toHaveLength(2)
6965
})
7066

7167
it('Create from json graph spec graph directly', () => {
72-
const contentModel = fromJsonGraph(largeGraph.graph as JSONGraph)
68+
const contentModel = buildGraph(largeGraph.graph as JSONGraph)
7369
expect(Object.keys(contentModel.nodes)).toHaveLength(9)
7470
expect(Object.keys(contentModel.edges)).toHaveLength(8)
7571
})
7672

7773
it('ContentModel does not support empty from graphs', () => {
7874
expect(() =>
79-
fromJsonGraph({
75+
buildGraph({
8076
graphs: [],
8177
})
8278
).toThrow()
8379
})
8480

8581
it('ContentModel does not support empty model', () => {
86-
expect(() => fromJsonGraph({})).toThrow()
82+
expect(() => buildGraph({})).toThrow()
8783
})
8884

8985
it('ContentModel does not support multiple from graphs', () => {
9086
expect(() =>
91-
fromJsonGraph({
87+
buildGraph({
9288
graphs: [smallGraph.graph as JSONGraph, largeGraph.graph as JSONGraph],
9389
})
9490
).toThrow()
@@ -100,14 +96,14 @@ it('ContentModel does not support hyperedges from graphs', () => {
10096
hyperedges: smallGraph.graph?.edges,
10197
} as unknown as JSONGraph
10298
expect(() =>
103-
fromJsonGraph({
99+
buildGraph({
104100
graph: hyperGraph,
105101
})
106102
).toThrow()
107103
})
108104

109105
it('loads very large graph', () => {
110-
const contentModel = fromJsonGraph(veryLargeGraph)
106+
const contentModel = buildGraph(veryLargeGraph)
111107
expect(Object.keys(contentModel.nodes)).toHaveLength(1000)
112108
expect(Object.keys(contentModel.edges)).toHaveLength(1000)
113109
})

0 commit comments

Comments
 (0)