rdf-validate-shacl
Advanced tools
Comparing version 0.3.1 to 0.3.2
# Changelog | ||
## 0.3.2 (2021-05-14) | ||
* Add `validateNode` function to validate a given node against a given shape. | ||
[[#59](https://github.com/zazuko/rdf-validate-shacl/issues/59)] | ||
[[#65](https://github.com/zazuko/rdf-validate-shacl/pull/65)] | ||
## 0.3.1 (2021-05-03) | ||
* Use provided data factory everywhere | ||
[[#52][https://github.com/zazuko/rdf-validate-shacl/issues/52]] | ||
[[#62][https://github.com/zazuko/rdf-validate-shacl/pull/62]] | ||
[[#52](https://github.com/zazuko/rdf-validate-shacl/issues/52)] | ||
[[#62](https://github.com/zazuko/rdf-validate-shacl/pull/62)] | ||
@@ -16,4 +22,4 @@ ## 0.3.0 (2021-04-13) | ||
`minInclusive` and `maxInclusive` constraints. | ||
[[#23][https://github.com/zazuko/rdf-validate-shacl/issues/23]] | ||
[[#55][https://github.com/zazuko/rdf-validate-shacl/pull/55]] | ||
[[#23](https://github.com/zazuko/rdf-validate-shacl/issues/23)] | ||
[[#55](https://github.com/zazuko/rdf-validate-shacl/pull/55)] | ||
@@ -20,0 +26,0 @@ ## 0.2.6 (2021-02-22) |
14
index.js
@@ -41,2 +41,16 @@ const clownface = require('clownface') | ||
/** | ||
* Validates the provided focus node against the provided shape | ||
* | ||
* @param {DatasetCore} data - Dataset containing the data to validate | ||
* @param {Term} focusNode - Node to validate | ||
* @param {Term} shapeNode - Shape used to validate the node. It must be present in the shapes graph. | ||
* @returns {ValidationReport} - Result of the validation | ||
*/ | ||
validateNode (data, focusNode, shapeNode) { | ||
this.$data = clownface({ dataset: data, factory: this.factory }) | ||
this.nodeConformsToShape(focusNode, shapeNode) | ||
return this.validationEngine.getReport() | ||
} | ||
/** | ||
* Load SHACL shapes constraints from dataset. | ||
@@ -43,0 +57,0 @@ * |
{ | ||
"name": "rdf-validate-shacl", | ||
"version": "0.3.1", | ||
"version": "0.3.2", | ||
"description": "RDF SHACL validator", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
# rdf-validate-shacl | ||
JavaScript SHACL validation ([RDF/JS](https://rdf.js.org/) compatible) | ||
Validate RDF data purely in JavaScript. An implementation of the [W3C SHACL](https://www.w3.org/TR/shacl/) specification on top of the [RDFJS](https://www.w3.org/TR/shacl/) stack. | ||
@@ -6,0 +6,0 @@ [](https://badge.fury.io/js/rdf-validate-shacl) |
@@ -169,4 +169,4 @@ // Design: | ||
getMessages (shape) { | ||
const generic = shape.isPropertyShape() ? this.propertyValidationFunctionGeneric : this.nodeValidationFunctionGeneric | ||
const validatorType = generic ? 'validator' : (shape.isPropertyShape() ? 'propertyValidator' : 'nodeValidator') | ||
const generic = shape.isPropertyShape ? this.propertyValidationFunctionGeneric : this.nodeValidationFunctionGeneric | ||
const validatorType = generic ? 'validator' : (shape.isPropertyShape ? 'propertyValidator' : 'nodeValidator') | ||
const validator = this.findValidator(validatorType) | ||
@@ -209,15 +209,12 @@ | ||
this.context = context | ||
this.shapeNode = shapeNode | ||
this.shapeNodePointer = $shapes.node(shapeNode) | ||
this.severity = this.shapeNodePointer.out(sh.severity).term | ||
if (!this.severity) { | ||
this.severity = sh.Violation | ||
} | ||
this.severity = this.shapeNodePointer.out(sh.severity).term || sh.Violation | ||
this.deactivated = this.shapeNodePointer.out(sh.deactivated).value === 'true' | ||
this.path = this.shapeNodePointer.out(sh.path).term | ||
this.isPropertyShape = this.path != null | ||
this._pathObject = undefined | ||
this.shapeNode = shapeNode | ||
this.constraints = [] | ||
const handled = new NodeSet() | ||
@@ -297,8 +294,4 @@ const shapeProperties = [...$shapes.dataset.match(shapeNode, null, null)] | ||
} | ||
isPropertyShape () { | ||
return this.path != null | ||
} | ||
} | ||
module.exports = ShapesGraph |
@@ -65,3 +65,3 @@ const ValidationReport = require('./validation-report') | ||
const result = this.createResult(constraint, focusNode, valueNode) | ||
if (constraint.shape.isPropertyShape()) { | ||
if (constraint.shape.isPropertyShape) { | ||
this.addResultPropertyDeep(result, sh.resultPath, constraint.shape.path, true) | ||
@@ -76,3 +76,3 @@ } | ||
const result = this.createResult(constraint, focusNode, valueNode) | ||
if (constraint.shape.isPropertyShape()) { | ||
if (constraint.shape.isPropertyShape) { | ||
this.addResultPropertyDeep(result, sh.resultPath, constraint.shape.path, true) | ||
@@ -90,3 +90,3 @@ } | ||
this.addResultPropertyDeep(result, sh.resultPath, obj.path, true) | ||
} else if (constraint.shape.isPropertyShape()) { | ||
} else if (constraint.shape.isPropertyShape) { | ||
this.addResultPropertyDeep(result, sh.resultPath, constraint.shape.path, true) | ||
@@ -147,5 +147,3 @@ } | ||
validateAll (dataGraph) { | ||
if (this.maxErrorsReached()) { | ||
return true | ||
} | ||
if (this.maxErrorsReached()) return true | ||
@@ -176,9 +174,5 @@ this.validationError = null | ||
validateNodeAgainstShape (focusNode, shape, dataGraph) { | ||
if (this.maxErrorsReached()) { | ||
return true | ||
} | ||
if (this.maxErrorsReached()) return true | ||
if (shape.deactivated) { | ||
return false | ||
} | ||
if (shape.deactivated) return false | ||
@@ -198,5 +192,3 @@ const valueNodes = shape.getValueNodes(focusNode, dataGraph) | ||
if (this.maxErrorsReached()) { | ||
return true | ||
} | ||
if (this.maxErrorsReached()) return true | ||
@@ -213,7 +205,7 @@ if (sh.PropertyConstraintComponent.equals(constraint.component.node)) { | ||
const validationFunction = constraint.shape.isPropertyShape() | ||
const validationFunction = constraint.shape.isPropertyShape | ||
? constraint.component.propertyValidationFunction | ||
: constraint.component.nodeValidationFunction | ||
if (validationFunction) { | ||
const generic = constraint.shape.isPropertyShape() | ||
const generic = constraint.shape.isPropertyShape | ||
? constraint.component.propertyValidationFunctionGeneric | ||
@@ -220,0 +212,0 @@ : constraint.component.nodeValidationFunctionGeneric |
399950