diff --git a/.changeset/violet-dogs-help.md b/.changeset/violet-dogs-help.md new file mode 100644 index 000000000..14342dbb1 --- /dev/null +++ b/.changeset/violet-dogs-help.md @@ -0,0 +1,5 @@ +--- +"@cube-creator/cli": major +--- + +Use [cube.link shapes](https://github.com/zazuko/cube-link/tree/main/validation) for validation diff --git a/cli/package.json b/cli/package.json index 53b5d6445..0da89c734 100644 --- a/cli/package.json +++ b/cli/package.json @@ -46,6 +46,7 @@ "barnard59-base": "^1.1.0", "barnard59-formats": "^1.1.0", "barnard59-graph-store": "^1.0.0", + "barnard59-http": "^1.1.1", "barnard59-rdf": "^1.0.0", "barnard59-validate-shacl": "^0.3.8", "body-parser": "^1.19.0", diff --git a/cli/pipelines/publish.ttl b/cli/pipelines/publish.ttl index 76cb64519..22d39e94e 100644 --- a/cli/pipelines/publish.ttl +++ b/cli/pipelines/publish.ttl @@ -60,7 +60,7 @@ code:link ] ; code:arguments - [ code:name "shape" ; code:value <#loadShapes> ] , + [ code:name "shape" ; code:value <#concatShapes> ] , [ code:name "maxErrors" ; code:value 100 ] , [ code:name "onViolation" ; @@ -68,6 +68,29 @@ ] ; . +<#concatShapes> a :Pipeline, :ReadableObjectMode ; + :steps [ + :stepList + ( + <#loadAllShapes> + ) + ]. + + +<#loadAllShapes> + a :Step ; + code:implementedBy + [ + a code:EcmaScriptModule ; + code:link + ] ; + code:arguments + ( + <#loadShapes> + <#loadCubeShapes> + ) +. + <#loadShapes> a :Pipeline, :ReadableObjectMode ; :steps @@ -94,6 +117,70 @@ ) ] . +<#loadCubeShapes> + a :Pipeline, :ReadableObjectMode ; + :steps + [ + :stepList + ( + <#shapeURLs> + <#getShapes> + ) + ] . + +<#shapeURLs> a :Step ; + code:implementedBy [ + a code:EcmaScriptModule ; + code:link ; + ] ; + code:arguments ( + """[ + 'https://cube.link/v0.1.0/shape/standalone-constraint-constraint', + // 'https://cube.link/v0.1.0/shape/datacatalog-constraint', + ]"""^^code:EcmaScript + ) + . + +<#getShapes> a :Step ; + code:implementedBy [ + a code:EcmaScriptModule ; + code:link ; + ] ; + code:arguments ( <#getShape> "shapeURL" ) + . + +<#getShape> a :Pipeline , :ReadableObjectMode; + :steps + [ + :stepList + ( + <#fetch> + <#parse> + ) + ] . + +<#fetch> a :Step ; + code:implementedBy + [ + a code:EcmaScriptModule ; + code:link + ] ; + code:arguments + [ + code:name "url"; + code:value "shapeURL"^^:VariableName ; + ] +. + +<#parse> a :Step ; + code:implementedBy + [ + code:link ; + a code:EcmaScriptModule ; + ] + . + + <#flatten> a :Step ; code:implementedBy [ diff --git a/cli/shapes.ttl b/cli/shapes.ttl index 952a250e1..e316c4497 100644 --- a/cli/shapes.ttl +++ b/cli/shapes.ttl @@ -25,7 +25,7 @@ base sh:message "cube:Cube needs at least one cube:ObservationSet" ; ] , [ sh:path cube:observationConstraint ; - sh:node ; + sh:node ; # from cube.link sh:message "cube:Cube must point to a valid cube:Constraint" ; ] ; . @@ -60,84 +60,6 @@ base ] ; . - - a sh:NodeShape ; - sh:property [ - # we assume at least 3 dimensions, otherwise we would have an empty list of dimensions - # one for cube:observedBy, one for rdf:type and at least one cube dimension - sh:path sh:property ; - sh:minCount 3 ; - sh:message "cube:Constraint needs at least {$minCount} sh:properties" ; - ] , [ - sh:path sh:property ; - sh:node ; - ] , [ - sh:path sh:closed ; - sh:hasValue true ; - ] ; -. - - a sh:NodeShape; - sh:property [ - sh:path qudt:scaleType ; - sh:in ( qudt:IntervalScale qudt:NominalScale qudt:EnumerationScale qudt:RatioScale qudt:OrdinalScale) ; - sh:message "If qudt:scale is used it needs to be within" ; - ] , [ - sh:path sh:path ; - sh:minCount 1 ; - sh:maxCount 1 ; - sh:message "a sh:path is needed on a property" ; - ] , [ - sh:path sh:in ; - sh:node ; - sh:message "sh:in needs to be a list" ; - ] , [ - sh:message "needs a schema:name" ; - sh:or ( - [ - sh:path schema:name ; - sh:minCount 1 ; - sh:datatype xsd:string ; - ] - [ - sh:path schema:name ; - sh:minCount 1 ; - sh:datatype rdf:langString ; - ] - [ - sh:path sh:path ; - sh:in (rdf:type cube:observedBy) ; - ] - ) ; - ] , [ - sh:message "needs a sh:datatype or sh:nodeKind" ; - sh:or ( - [ - sh:path sh:datatype ; - sh:minCount 1 ; - ] - [ - sh:path sh:nodeKind ; - sh:minCount 1 ; - ] - ) ; - ] ; -. - -# Testing proper rdf:list construction - a sh:NodeShape ; - sh:property [ - sh:path rdf:first ; - sh:minCount 1 ; - sh:maxCount 1 ; - ] , [ - sh:path rdf:rest ; - sh:minCount 1 ; - sh:maxCount 1 ; - sh:message "a rdf:List can only have one rdf:rest node, multiples nodes need to be linked" ; - #sh:node ; - ] ; -. a sh:NodeShape ;