@shaclmate/cli 3.0.4 → 4.0.1

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/README.md ADDED
@@ -0,0 +1,23 @@
1
+ # @shaclmate/cli
2
+
3
+ > ⚠️ **Under active development.** SHACLmate is experimental — both the compiler and generated code should be considered unstable and subject to breaking changes.
4
+
5
+ Command line tool for generating [TypeScript](https://www.typescriptlang.org/) code from [SHACL](https://www.w3.org/TR/shacl/) shapes.
6
+
7
+ ## Prerequisites
8
+
9
+ * [Node.js](https://nodejs.org/) 18+
10
+
11
+ ## Usage
12
+
13
+ npx -y "@shaclmate/cli@latest" generate ts your-shapes.shaclmate.ttl >generated.ts
14
+
15
+ The generated code is serialized with minimal indentation and newlines. You will probably want to format it using a tool like [Biome](https://biomejs.dev/) or [prettier](https://prettier.io/).
16
+
17
+ ## Runtime dependencies
18
+
19
+ The generated TypeScript code relies on various third-party libraries. The exact set of dependencies will depend on the code generated. See the [GitHub repository](https://github.com/YOUR_ORG/shaclmate) for examples and full documentation.
20
+
21
+ ## License
22
+
23
+ [Apache 2.0](https://github.com/YOUR_ORG/shaclmate/blob/main/LICENSE)
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 * as N3 from "n3";
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
- const validationReport = new SHACLValidator(shaclShaclDataset).validate(dataset);
59
- if (!validationReport.conforms) {
60
- process.stderr.write("input is not valid SHACL:\n");
61
- const n3WriterPrefixes = {};
62
- for (const prefixEntry of iriPrefixMap.entries()) {
63
- n3WriterPrefixes[prefixEntry[0]] = prefixEntry[1].value;
64
- }
65
- const n3Writer = new N3.Writer({
66
- format: "text/turtle",
67
- prefixes: n3WriterPrefixes,
68
- });
69
- for (const quad of validationReport.dataset) {
70
- n3Writer.addQuad(quad);
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
- const output = new Compiler({ generator, iriPrefixMap }).compile(dataset);
76
- output
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: command({
92
- name: "generate",
93
- description: "generate TypeScript for the SHACL Shapes Graph AST",
94
- args: {
95
- inputFilePaths,
96
- outputFilePath,
97
- },
98
- handler: async ({ inputFilePaths, outputFilePath }) => {
99
- generate({
100
- generator: new generators.ts.TsGenerator(),
101
- inputFilePaths,
102
- outputFilePath,
103
- });
104
- },
105
- }),
106
- "show-ast-json": command({
107
- name: "show-ast-json",
108
- description: "show AST JSON for the SHACL Shapes Graph AST",
109
- args: {
110
- inputFilePaths,
111
- outputFilePath,
112
- },
113
- handler: async ({ inputFilePaths, outputFilePath }) => {
114
- generate({
115
- generator: new generators.json.AstJsonGenerator(),
116
- inputFilePaths,
117
- outputFilePath,
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,57 +3,53 @@
3
3
  "shaclmate": "dist/cli.js"
4
4
  },
5
5
  "dependencies": {
6
- "@shaclmate/compiler": "3.0.4",
7
- "@rdfjs/types": "^1.1.0",
8
- "@rdfjs/prefix-map": "^0.1.2",
9
- "@types/n3": "^1.26.0",
10
- "@types/rdfjs__prefix-map": "^0.1.5",
11
- "@types/rdf-validate-shacl": "^0.4.7",
12
- "cmd-ts": "^0.13.0",
13
- "n3": "^1.26.0",
14
- "pino": "^9.1.0",
15
- "rdf-validate-shacl": "^0.5.6"
6
+ "@shaclmate/compiler": "4.0.1",
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
  },
16
+ "description": "Command line program to generate TypeScript code from SHACL shapes",
17
17
  "devDependencies": {
18
- "@biomejs/biome": "1.9.4",
19
- "@tsconfig/node18": "^18.2.4",
20
- "@tsconfig/strictest": "^2.0.5",
21
- "@types/node": "^22",
22
- "depcheck": "^1.4.7",
23
- "rimraf": "^6.0.1",
24
- "typescript": "5.8.2",
25
- "vitest": "^3.2.4",
26
- "@vitest/coverage-v8": "^3.2.4"
18
+ "@tsconfig/node18": "~18.2.4",
19
+ "@tsconfig/strictest": "~2.0.8",
20
+ "@types/node": "~18",
21
+ "depcheck": "~1.4.7",
22
+ "rimraf": "~6.0.1",
23
+ "typescript": "5.9.3"
27
24
  },
28
25
  "files": [
26
+ "README.md",
29
27
  "dist/*.d.ts",
30
28
  "dist/*.js"
31
29
  ],
30
+ "homepage": "https://github.com/minorg/shaclmate",
31
+ "keywords": [
32
+ "rdf",
33
+ "shacl",
34
+ "typescript"
35
+ ],
32
36
  "license": "Apache-2.0",
33
37
  "main": "./dist/index.js",
34
38
  "name": "@shaclmate/cli",
35
39
  "packageManager": "npm@10.9.0",
36
40
  "repository": {
37
41
  "type": "git",
38
- "url": "git+https://github.com/minorg/shaclmate"
42
+ "url": "git+https://github.com/minorg/shaclmate.git"
39
43
  },
40
44
  "scripts": {
41
45
  "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
46
  "clean": "rimraf dist",
47
47
  "depcheck": "depcheck .",
48
48
  "dev": "tsc -w --preserveWatchOutput",
49
- "dev:noEmit": "tsc --noEmit -w --preserveWatchOutput",
50
- "link-dependencies": "npm link rdfjs-resource",
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"
49
+ "typecheck": "tsc --noEmit",
50
+ "typecheck:watch": "tsc --noEmit -w --preserveWatchOutput"
55
51
  },
56
52
  "type": "module",
57
53
  "types": "./dist/index.d.ts",
58
- "version": "3.0.4"
54
+ "version": "4.0.1"
59
55
  }
@@ -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
@@ -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