@shaclmate/cli 3.0.4 → 4.0.0
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/cli.js +55 -56
- package/package.json +18 -30
- package/dist/dashDataset.d.ts +0 -8
- package/dist/dashDataset.js +0 -69
package/dist/cli.js
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import * as fs from "node:fs";
|
|
3
3
|
import PrefixMap from "@rdfjs/prefix-map/PrefixMap.js";
|
|
4
|
-
import { Compiler } from "@shaclmate/compiler";
|
|
5
|
-
import { generators } from "@shaclmate/compiler";
|
|
4
|
+
import { AstJsonGenerator, Compiler, ShapesGraph, TsGenerator, } from "@shaclmate/compiler";
|
|
6
5
|
import { command, option, restPositionals, run, string, subcommands, } from "cmd-ts";
|
|
7
6
|
import { ExistingPath } from "cmd-ts/dist/cjs/batteries/fs.js";
|
|
8
|
-
import
|
|
9
|
-
import { DataFactory, Parser, Store } from "n3";
|
|
7
|
+
import { DataFactory, Parser, Store, Writer } from "n3";
|
|
10
8
|
import { pino } from "pino";
|
|
11
9
|
import SHACLValidator from "rdf-validate-shacl";
|
|
12
|
-
import { dashDataset } from "./dashDataset.js";
|
|
13
10
|
import { shaclShaclDataset } from "./shaclShaclDataset.js";
|
|
14
11
|
const inputFilePaths = restPositionals({
|
|
15
12
|
displayName: "inputFilePaths",
|
|
@@ -35,15 +32,10 @@ function generate({ generator, inputFilePaths, outputFilePath, }) {
|
|
|
35
32
|
}
|
|
36
33
|
const inputParser = new Parser();
|
|
37
34
|
const dataset = new Store();
|
|
38
|
-
for (const quad of dashDataset) {
|
|
39
|
-
dataset.add(quad);
|
|
40
|
-
}
|
|
41
35
|
const iriPrefixes = [];
|
|
42
36
|
for (const inputFilePath of inputFilePaths) {
|
|
43
37
|
dataset.addQuads(inputParser.parse(fs.readFileSync(inputFilePath).toString(), null, (prefix, prefixNode) => {
|
|
44
|
-
const existingIriPrefix = iriPrefixes.find(
|
|
45
|
-
// @ts-ignore
|
|
46
|
-
(iriPrefix) => iriPrefix[0] === prefix || iriPrefix[1].equals(prefixNode));
|
|
38
|
+
const existingIriPrefix = iriPrefixes.find((iriPrefix) => iriPrefix[0] === prefix || iriPrefix[1].equals(prefixNode));
|
|
47
39
|
if (existingIriPrefix) {
|
|
48
40
|
if (existingIriPrefix[0] !== prefix ||
|
|
49
41
|
!existingIriPrefix[1].equals(prefixNode)) {
|
|
@@ -55,25 +47,27 @@ function generate({ generator, inputFilePaths, outputFilePath, }) {
|
|
|
55
47
|
}));
|
|
56
48
|
}
|
|
57
49
|
const iriPrefixMap = new PrefixMap(iriPrefixes, { factory: DataFactory });
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
50
|
+
{
|
|
51
|
+
const validationReport = new SHACLValidator(shaclShaclDataset, {}).validate(dataset);
|
|
52
|
+
if (!validationReport.conforms) {
|
|
53
|
+
process.stderr.write("input is not valid SHACL:\n");
|
|
54
|
+
const n3WriterPrefixes = {};
|
|
55
|
+
for (const prefixEntry of iriPrefixMap.entries()) {
|
|
56
|
+
n3WriterPrefixes[prefixEntry[0]] = prefixEntry[1].value;
|
|
57
|
+
}
|
|
58
|
+
const n3Writer = new Writer({
|
|
59
|
+
format: "text/turtle",
|
|
60
|
+
prefixes: n3WriterPrefixes,
|
|
61
|
+
});
|
|
62
|
+
for (const quad of validationReport.dataset) {
|
|
63
|
+
n3Writer.addQuad(quad);
|
|
64
|
+
}
|
|
65
|
+
n3Writer.end((_error, result) => process.stderr.write(result));
|
|
66
|
+
return;
|
|
71
67
|
}
|
|
72
|
-
n3Writer.end((_error, result) => process.stderr.write(result));
|
|
73
|
-
return;
|
|
74
68
|
}
|
|
75
|
-
|
|
76
|
-
|
|
69
|
+
ShapesGraph.create({ dataset })
|
|
70
|
+
.chain((shapesGraph) => new Compiler({ generator, iriPrefixMap }).compile(shapesGraph))
|
|
77
71
|
.ifLeft((error) => {
|
|
78
72
|
throw error;
|
|
79
73
|
})
|
|
@@ -88,35 +82,40 @@ function generate({ generator, inputFilePaths, outputFilePath, }) {
|
|
|
88
82
|
}
|
|
89
83
|
run(subcommands({
|
|
90
84
|
cmds: {
|
|
91
|
-
generate:
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
85
|
+
generate: subcommands({
|
|
86
|
+
cmds: {
|
|
87
|
+
"ast-json": command({
|
|
88
|
+
name: "ast-json",
|
|
89
|
+
description: "generate AST JSON for the SHACL Shapes Graph AST",
|
|
90
|
+
args: {
|
|
91
|
+
inputFilePaths,
|
|
92
|
+
outputFilePath,
|
|
93
|
+
},
|
|
94
|
+
handler: async ({ inputFilePaths, outputFilePath }) => {
|
|
95
|
+
generate({
|
|
96
|
+
generator: new AstJsonGenerator(),
|
|
97
|
+
inputFilePaths,
|
|
98
|
+
outputFilePath,
|
|
99
|
+
});
|
|
100
|
+
},
|
|
101
|
+
}),
|
|
102
|
+
ts: command({
|
|
103
|
+
name: "ts",
|
|
104
|
+
description: "generate TypeScript for the SHACL Shapes Graph AST",
|
|
105
|
+
args: {
|
|
106
|
+
inputFilePaths,
|
|
107
|
+
outputFilePath,
|
|
108
|
+
},
|
|
109
|
+
handler: async ({ inputFilePaths, outputFilePath }) => {
|
|
110
|
+
generate({
|
|
111
|
+
generator: new TsGenerator(),
|
|
112
|
+
inputFilePaths,
|
|
113
|
+
outputFilePath,
|
|
114
|
+
});
|
|
115
|
+
},
|
|
116
|
+
}),
|
|
119
117
|
},
|
|
118
|
+
name: "generate",
|
|
120
119
|
}),
|
|
121
120
|
},
|
|
122
121
|
description: "shaclmate command line interface",
|
package/package.json
CHANGED
|
@@ -3,27 +3,23 @@
|
|
|
3
3
|
"shaclmate": "dist/cli.js"
|
|
4
4
|
},
|
|
5
5
|
"dependencies": {
|
|
6
|
-
"@shaclmate/compiler": "
|
|
7
|
-
"@rdfjs/
|
|
8
|
-
"@rdfjs/
|
|
9
|
-
"@types/n3": "
|
|
10
|
-
"@types/rdfjs__prefix-map": "
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"rdf-validate-shacl": "^0.5.6"
|
|
6
|
+
"@shaclmate/compiler": "4.0.0",
|
|
7
|
+
"@rdfjs/prefix-map": "~0.1.2",
|
|
8
|
+
"@rdfjs/types": "~2.0.1",
|
|
9
|
+
"@types/n3": "~1.26.0",
|
|
10
|
+
"@types/rdfjs__prefix-map": "~0.1.5",
|
|
11
|
+
"cmd-ts": "~0.13.0",
|
|
12
|
+
"n3": "~1.26.0",
|
|
13
|
+
"pino": "~9.1.0",
|
|
14
|
+
"rdf-validate-shacl": "0.5.8"
|
|
16
15
|
},
|
|
17
16
|
"devDependencies": {
|
|
18
|
-
"@
|
|
19
|
-
"@tsconfig/
|
|
20
|
-
"@
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"typescript": "5.8.2",
|
|
25
|
-
"vitest": "^3.2.4",
|
|
26
|
-
"@vitest/coverage-v8": "^3.2.4"
|
|
17
|
+
"@tsconfig/node18": "~18.2.4",
|
|
18
|
+
"@tsconfig/strictest": "~2.0.8",
|
|
19
|
+
"@types/node": "~18",
|
|
20
|
+
"depcheck": "~1.4.7",
|
|
21
|
+
"rimraf": "~6.0.1",
|
|
22
|
+
"typescript": "5.9.3"
|
|
27
23
|
},
|
|
28
24
|
"files": [
|
|
29
25
|
"dist/*.d.ts",
|
|
@@ -39,21 +35,13 @@
|
|
|
39
35
|
},
|
|
40
36
|
"scripts": {
|
|
41
37
|
"build": "tsc -b && chmod +x dist/cli.js",
|
|
42
|
-
"build:noEmit": "tsc --noEmit",
|
|
43
|
-
"check": "biome check",
|
|
44
|
-
"check:write": "biome check --write",
|
|
45
|
-
"check:write:unsafe": "biome check --write --unsafe",
|
|
46
38
|
"clean": "rimraf dist",
|
|
47
39
|
"depcheck": "depcheck .",
|
|
48
40
|
"dev": "tsc -w --preserveWatchOutput",
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"test": "biome check && vitest run",
|
|
52
|
-
"test:coverage": "biome check && vitest run --coverage",
|
|
53
|
-
"test:watch": "biome check && vitest watch",
|
|
54
|
-
"unlink": "npm unlink -g @shaclmate/cli"
|
|
41
|
+
"typecheck": "tsc --noEmit",
|
|
42
|
+
"typecheck:watch": "tsc --noEmit -w --preserveWatchOutput"
|
|
55
43
|
},
|
|
56
44
|
"type": "module",
|
|
57
45
|
"types": "./dist/index.d.ts",
|
|
58
|
-
"version": "
|
|
46
|
+
"version": "4.0.0"
|
|
59
47
|
}
|
package/dist/dashDataset.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { DatasetCore } from "@rdfjs/types";
|
|
2
|
-
/**
|
|
3
|
-
* A subset of DASH (https://datashapes.org/dash.html) that's added to command line inputs for convenience.
|
|
4
|
-
*
|
|
5
|
-
* Parts that don't validate with SHACL-SHACL have been excised.
|
|
6
|
-
*/
|
|
7
|
-
export declare const dashDataset: DatasetCore;
|
|
8
|
-
//# sourceMappingURL=dashDataset.d.ts.map
|
package/dist/dashDataset.js
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { Parser, Store } from "n3";
|
|
2
|
-
/**
|
|
3
|
-
* A subset of DASH (https://datashapes.org/dash.html) that's added to command line inputs for convenience.
|
|
4
|
-
*
|
|
5
|
-
* Parts that don't validate with SHACL-SHACL have been excised.
|
|
6
|
-
*/
|
|
7
|
-
export const dashDataset = new Store(new Parser({ format: "text/turtle" }).parse(`
|
|
8
|
-
# baseURI: http://datashapes.org/dash
|
|
9
|
-
# imports: http://www.w3.org/ns/shacl#
|
|
10
|
-
# prefix: dash
|
|
11
|
-
|
|
12
|
-
@prefix dash: <http://datashapes.org/dash#> .
|
|
13
|
-
@prefix owl: <http://www.w3.org/2002/07/owl#> .
|
|
14
|
-
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
|
|
15
|
-
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
|
|
16
|
-
@prefix sh: <http://www.w3.org/ns/shacl#> .
|
|
17
|
-
@prefix tosh: <http://topbraid.org/tosh#> .
|
|
18
|
-
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
|
|
19
|
-
|
|
20
|
-
<http://datashapes.org/dash>
|
|
21
|
-
a owl:Ontology ;
|
|
22
|
-
rdfs:comment "DASH is a SHACL library for frequently needed features and design patterns. The constraint components in this library are 100% standards compliant and will work on any engine that fully supports SHACL." ;
|
|
23
|
-
rdfs:label "DASH Data Shapes Vocabulary" ;
|
|
24
|
-
owl:imports sh: ;
|
|
25
|
-
sh:declare [
|
|
26
|
-
sh:namespace "http://datashapes.org/dash#"^^xsd:anyURI ;
|
|
27
|
-
sh:prefix "dash" ;
|
|
28
|
-
] ;
|
|
29
|
-
sh:declare [
|
|
30
|
-
sh:namespace "http://purl.org/dc/terms/"^^xsd:anyURI ;
|
|
31
|
-
sh:prefix "dcterms" ;
|
|
32
|
-
] ;
|
|
33
|
-
sh:declare [
|
|
34
|
-
sh:namespace "http://www.w3.org/1999/02/22-rdf-syntax-ns#"^^xsd:anyURI ;
|
|
35
|
-
sh:prefix "rdf" ;
|
|
36
|
-
] ;
|
|
37
|
-
sh:declare [
|
|
38
|
-
sh:namespace "http://www.w3.org/2000/01/rdf-schema#"^^xsd:anyURI ;
|
|
39
|
-
sh:prefix "rdfs" ;
|
|
40
|
-
] ;
|
|
41
|
-
sh:declare [
|
|
42
|
-
sh:namespace "http://www.w3.org/2001/XMLSchema#"^^xsd:anyURI ;
|
|
43
|
-
sh:prefix "xsd" ;
|
|
44
|
-
] ;
|
|
45
|
-
sh:declare [
|
|
46
|
-
sh:namespace "http://www.w3.org/2002/07/owl#"^^xsd:anyURI ;
|
|
47
|
-
sh:prefix "owl" ;
|
|
48
|
-
] ;
|
|
49
|
-
sh:declare [
|
|
50
|
-
sh:namespace "http://www.w3.org/2004/02/skos/core#"^^xsd:anyURI ;
|
|
51
|
-
sh:prefix "skos" ;
|
|
52
|
-
] ;
|
|
53
|
-
.
|
|
54
|
-
|
|
55
|
-
dash:StringOrLangString
|
|
56
|
-
a rdf:List ;
|
|
57
|
-
rdf:first [
|
|
58
|
-
sh:datatype xsd:string ;
|
|
59
|
-
] ;
|
|
60
|
-
rdf:rest (
|
|
61
|
-
[
|
|
62
|
-
sh:datatype rdf:langString ;
|
|
63
|
-
]
|
|
64
|
-
) ;
|
|
65
|
-
rdfs:comment "An rdf:List that can be used in property constraints as value for sh:or to indicate that all values of a property must be either xsd:string or rdf:langString." ;
|
|
66
|
-
rdfs:label "String or langString" ;
|
|
67
|
-
.
|
|
68
|
-
`));
|
|
69
|
-
//# sourceMappingURL=dashDataset.js.map
|