Skip to content

Commit

Permalink
Merge pull request #73 from zazuko/bogus-lookup-src
Browse files Browse the repository at this point in the history
test: ensure no source has two types
  • Loading branch information
tpluscode authored Jan 26, 2024
2 parents 9b62e6d + a9061c8 commit cabfb33
Show file tree
Hide file tree
Showing 25 changed files with 728 additions and 345 deletions.
6 changes: 6 additions & 0 deletions .changeset/nervous-moles-buy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@view-builder/publish-views": patch
"@view-builder/core": patch
---

Clashing blank nodes would cause invalid views being published
26 changes: 15 additions & 11 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,21 @@ on:
jobs:
Build:
runs-on: ubuntu-latest
env:
NODE_OPTIONS: --openssl-legacy-provider
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 16
node-version: 18
- run: yarn install --frozen-lockfile
- run: yarn build

test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 18
- run: yarn install --frozen-lockfile
Expand All @@ -34,8 +36,8 @@ jobs:
if: false
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- uses: docker-practice/[email protected]
with:
docker_version: 20.10.8
Expand All @@ -52,7 +54,7 @@ jobs:
if: false
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: docker-practice/[email protected]
with:
docker_version: 20.10.8
Expand All @@ -66,8 +68,8 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- run: yarn
- run: yarn lint

Expand All @@ -76,7 +78,9 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
Expand Down
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM docker.io/library/node:16-alpine
FROM docker.io/library/node:18-alpine

WORKDIR /app

Expand All @@ -7,6 +7,8 @@ COPY . ./

RUN apk add --no-cache gettext jq

ENV NODE_OPTIONS=--openssl-legacy-provider

# first do the build
RUN yarn --frozen-lockfile \
&& yarn build \
Expand Down
2 changes: 1 addition & 1 deletion apps/www/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"content-disposition": "^0.5.4",
"@view-builder/core": "0.0.0",
"@view-builder/view-util": "0.0.1",
"@zazuko/env": "^2.0.3",
"@zazuko/prefixes": "^2.0.0",
"@zazuko/vocabulary-extras": "^2.0.1",
"alcaeus": "^2.3.2",
Expand All @@ -45,7 +46,6 @@
"lit": "^2.3.0",
"n3": "^1.16.2",
"nanoid": "^4.0.0",
"rdf-ext": "^2.0.1",
"rdf-literal": "^1.3.0",
"rdf-validate-shacl": "^0.4.4",
"sparql-http-client": "^2.4.1",
Expand Down
2 changes: 1 addition & 1 deletion apps/www/src/state/plugin/viewForm/toggleButtons.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import generateDimensionsShapeQuads from '@view-builder/core/shape/ViewWithSource.ttl'
import viewValidationShapeQuads from '@view-builder/core/shape/ViewValidationShape.ttl'
import { prepareViewPointer } from '@view-builder/view-util'
import $rdf from 'rdf-ext'
import $rdf from '@zazuko/env'

const GenerateDimensionsShapes = $rdf.dataset(generateDimensionsShapeQuads($rdf))

Expand Down
2 changes: 1 addition & 1 deletion apps/www/test/automation.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from 'chai'
import sinon from 'sinon'
import $rdf from 'rdf-ext'
import $rdf from '@zazuko/env'
import { rdfs, rdf } from '@tpluscode/rdf-ns-builders'
import { viewBuilder, view } from '@view-builder/core/ns.js'
import { ex, testData } from '@view-builder/testing'
Expand Down
7 changes: 4 additions & 3 deletions packages/core/env.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { createEnv } from '@rdfine/env'
import Environment from '@zazuko/env/Environment.js'
import RdfineEnv from '@rdfine/env'
import { ShFactory } from '@rdfine/shacl/Factory'
import { HydraFactory } from '@rdfine/hydra/Factory'

export default createEnv(
export default new Environment([
ShFactory,
HydraFactory,
)
], { parent: RdfineEnv })
7 changes: 4 additions & 3 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
"version": "0.0.0",
"type": "module",
"dependencies": {
"@rdfine/env": "^1.0.4",
"@rdfine/hydra": "^0.10.3",
"@rdfine/shacl": "^0.10.3",
"@rdfine/env": "^1.1.0",
"@rdfine/hydra": "^0.10.4",
"@rdfine/shacl": "^0.10.4",
"@rdfjs/namespace": "^2.0.0",
"@zazuko/env": "^2.0.3",
"@zazuko/vocabulary-extras": "^2.0.1"
}
}
12 changes: 12 additions & 0 deletions packages/core/shape/ViewValidationShape.ttl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX sh: <http://www.w3.org/ns/shacl#>
prefix view: <https://cube.link/view/>

Expand Down Expand Up @@ -78,6 +79,17 @@ prefix view: <https://cube.link/view/>
sh:minCount 1 ;
sh:maxCount 1 ;
] ;
sh:xone
(
[
sh:path rdf:type ;
sh:hasValue view:CubeSource
]
[
sh:path rdf:type ;
sh:hasValue view:LookupSource
]
)
.

<#TermSetFilter>
Expand Down
16 changes: 7 additions & 9 deletions packages/publish-views/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import Runner from 'barnard59/runner.js'
import fromFile from 'rdf-utils-fs/fromFile.js'
import $rdf from 'rdf-ext'
import clownface from 'clownface'
import $rdf from 'barnard59-env'
import path from 'path'
import { fileURLToPath } from 'url'
import { PassThrough } from 'stream'
Expand All @@ -19,7 +17,7 @@ export function toNtriples({
loadViewsStepsPath = loadViewsFromStoreStepPath,
}) {
return startRun({
term: 'ToFile',
term: 'urn:pipeline:ToFile',
steps: [ntriplesStepsPath, fileStepsPath, loadViewsStepsPath],
variables: {
outFile,
Expand All @@ -30,19 +28,19 @@ export function toNtriples({

export async function toStore(variables = {}) {
return startRun({
term: 'ToStore',
term: 'urn:pipeline:ToStore',
steps: [storeStepsPath, loadViewsFromStoreStepPath],
variables,
})
}

async function startRun({ term, steps, variables }) {
const dataset = await $rdf.dataset().import(fromFile(path.resolve(__dirname, pipelinePath)))
await Promise.all(steps.map(src => dataset.import(fromFile(path.resolve(__dirname, src)))))
const pipeline = clownface({ dataset }).namedNode(term)
const dataset = await $rdf.dataset().import($rdf.fromFile(path.resolve(__dirname, pipelinePath)))
await Promise.all(steps.map(src => dataset.import($rdf.fromFile(path.resolve(__dirname, src)))))
const pipeline = $rdf.clownface({ dataset }).namedNode(term)

const outputStream = new PassThrough()
const run = await Runner(pipeline, {
const run = await Runner(pipeline, $rdf, {
basePath: __dirname,
variables: new Map(Object.entries(variables)),
outputStream,
Expand Down
10 changes: 4 additions & 6 deletions packages/publish-views/lib/ValidationError.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { rdf, sh } from '@tpluscode/rdf-ns-builders'
import $rdf from 'rdf-ext'
import clownface from 'clownface'
import $rdf from 'barnard59-env'

export class ValidationError extends Error {
constructor(reports) {
const total = reports.reduce((sum, { pointer }) => {
const violations = pointer.any().has(sh.resultSeverity).terms.length
const violations = pointer.any().has($rdf.ns.sh.resultSeverity).terms.length
return sum + violations
}, 0)

Expand All @@ -17,8 +15,8 @@ export class ValidationError extends Error {
})
Object.defineProperty(this, 'reports', {
enumerable: false,
value: clownface({ dataset: this.dataset })
.has(rdf.type, sh.ValidationReport),
value: $rdf.clownface({ dataset: this.dataset })
.has($rdf.ns.rdf.type, $rdf.ns.sh.ValidationReport),
})
}
}
Expand Down
16 changes: 7 additions & 9 deletions packages/publish-views/lib/loadViews.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { CONSTRUCT, SELECT } from '@tpluscode/sparql-builder'
import * as ns from '@view-builder/core/ns.js'
import through2 from 'through2'
import $rdf from 'rdf-ext'
import clownface from 'clownface'
import { schema } from '@tpluscode/rdf-ns-builders'
import $rdf from 'barnard59-env'
import * as shapeTo from '@hydrofoil/shape-to-query'
import toStream from 'rdf-dataset-ext/toStream.js'
import { viewShape } from './shapes.js'
import { getViewBuilderClient, getMetadataClient } from './sparql.js'

Expand All @@ -17,8 +14,8 @@ export default async function loadViewsToPublish() {
.WHERE`
?viewBuilderView
a ${ns.view.View} ;
${schema.sameAs} ?publishedView ;
${schema.isBasedOn} ?metaObject ;
${$rdf.ns.schema.sameAs} ?publishedView ;
${$rdf.ns.schema.isBasedOn} ?metaObject ;
${ns.viewBuilder.publish} true ;
`
.execute(client.query)
Expand All @@ -34,7 +31,7 @@ export default async function loadViewsToPublish() {

const dataset = $rdf.dataset()
await Promise.all([dataset.import(viewQuads), dataset.import(metaQuads)])
this.push(clownface({ dataset, term: viewBuilderView }))
this.push($rdf.clownface({ dataset, term: viewBuilderView }))

next()
}))
Expand All @@ -45,11 +42,12 @@ async function loadViewMeta(publishedView, metaObject, client) {

const subjectVariable = 'view'
const query = shapeTo.constructQuery(shape, { focusNode: metaObject, subjectVariable })
const dataset = await query.execute(client.query, {
const quads = await query.execute(client.query, {
operation: 'postDirect',
})

return toStream(dataset).pipe(through2.obj(viewIdTransform(metaObject, publishedView)))
return $rdf.dataset(quads).toStream()
.pipe(through2.obj(viewIdTransform(metaObject, publishedView)))
}

function viewIdTransform(from, to) {
Expand Down
12 changes: 5 additions & 7 deletions packages/publish-views/lib/shapes.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import onetime from 'onetime'
import { fromFile } from 'rdf-utils-fs'
import $rdf from 'rdf-ext'
import clownface from 'clownface'
import $rdf from 'barnard59-env'
import { schema, sh } from '@tpluscode/rdf-ns-builders'
import { createRequire } from 'module'
import concat from 'barnard59-base/concat.js'
Expand All @@ -11,15 +9,15 @@ const metadataShapesPath = require.resolve('../shapes.ttl')
const viewShapesPath = require.resolve('@view-builder/core/shape/ViewValidationShape.ttl')

export const viewShape = onetime(async () => {
const dataset = await $rdf.dataset().import(fromFile(metadataShapesPath))
const dataset = await $rdf.dataset().import($rdf.fromFile(metadataShapesPath))

return clownface({ dataset })
return $rdf.clownface({ dataset })
.has(sh.targetClass, schema.Dataset)
})

export function validationShapes() {
const metadataShapes = fromFile(metadataShapesPath)
const viewShapes = fromFile(viewShapesPath)
const metadataShapes = $rdf.fromFile(metadataShapesPath)
const viewShapes = $rdf.fromFile(viewShapesPath)

return concat.object(metadataShapes, viewShapes)
}
27 changes: 11 additions & 16 deletions packages/publish-views/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,28 @@
"type": "module",
"main": "index.js",
"scripts": {
"run:pipeline": "npx --node-options '--loader node-loader-raw --inspect' barnard59 run --pipeline",
"run:pipeline": "node --loader node-loader-raw --inspect ../../node_modules/barnard59/bin/barnard59.js run --pipeline",
"postinstall": "mkdir -p .pipeline output",
"prestart:file": "cat pipeline/main.ttl pipeline/to-ntriples.ttl pipeline/to-file.ttl pipeline/steps/*.ttl > .pipeline/to-file.ttl",
"start:file": "dotenv -e ../../.env.local -e .env.local -- yarn run:pipeline ToFile --variable-all .pipeline/to-file.ttl",
"prestart:store": "mkdir .pipeline; cat pipeline/main.ttl pipeline/to-ntriples.ttl pipeline/to-store.ttl > .pipeline/to-store.ttl",
"start:store": "dotenv -e ../../.env.local -e .env.local -- yarn run:pipeline ToStore --variable-all .pipeline/to-store.ttl",
"start:file": "dotenv -e ../../.env -e ../../.env.local -e .env.local -- yarn run:pipeline urn:pipeline:ToFile --variable-all pipeline/to-file.ttl",
"start:store": "dotenv -e ../../.env.local -e .env.local -- yarn run:pipeline urn:pipeline:ToStore --variable-all pipeline/to-store.ttl",
"pretest": "yarn postinstall; yarn start:file",
"test": "shacl-cli validate --shapes test/shape*.ttl --shapes ../../packages/core/shape/ViewValidationShape.ttl --data output/views.nt"
},
"dependencies": {
"@hydrofoil/shape-to-query": "^0.8.1",
"@tpluscode/rdf-ns-builders": "^4.1.0",
"@tpluscode/rdf-ns-builders": "^4.1.1",
"@tpluscode/sparql-builder": "^1.1.0",
"@view-builder/core": "^0.0.0",
"@view-builder/view-util": "^0.0.1",
"barnard59": "^3.0.2",
"barnard59-base": "^1.2.2",
"barnard59-formats": "^1.4.2",
"barnard59-graph-store": "^1.1.1",
"barnard59-rdf": "^1.4.5",
"barnard59-validate-shacl": "^0.3.8",
"clownface": "^2",
"barnard59": "^4.5.3",
"barnard59-base": "^2.4.0",
"barnard59-env": "^1.2.3",
"barnard59-formats": "^2.1.0",
"barnard59-graph-store": "^5.1.1",
"barnard59-rdf": "^3.4.0",
"barnard59-shacl": "^1.4.1",
"node-loader-raw": "^0.0.0",
"onetime": "^6.0.0",
"rdf-dataset-ext": "^1.0.1",
"rdf-ext": "^2.1.0",
"rdf-utils-fs": "^2.2.0",
"rimraf": "^3.0.2",
"sparql-http-client": "^2.4.1",
"through2": "^4.0.2"
Expand Down
Loading

0 comments on commit cabfb33

Please sign in to comment.