@ldo/cli 1.0.0-alpha.21 → 1.0.0-alpha.28
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"forAllShapes.d.ts","sourceRoot":"","sources":["../../src/util/forAllShapes.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"forAllShapes.d.ts","sourceRoot":"","sources":["../../src/util/forAllShapes.ts"],"names":[],"mappings":"AAoBA,wBAAsB,YAAY,CAChC,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,GAC3D,OAAO,CAAC,IAAI,CAAC,CAsDf"}
|
|
@@ -1,16 +1,46 @@
|
|
|
1
1
|
import fs from "fs";
|
|
2
2
|
import path from "path";
|
|
3
|
+
import { shaclStoreToShexSchema, writeShexSchema } from "@jeswr/shacl2shex";
|
|
4
|
+
import { dereferenceToStore } from "rdf-dereference-store";
|
|
5
|
+
import { DataFactory as DF } from "n3";
|
|
6
|
+
import { rdf } from "rdf-namespaces";
|
|
7
|
+
function hasMatch(store, predicate, object) {
|
|
8
|
+
for (const _ in store.match(null, DF.namedNode(predicate), DF.namedNode(object), DF.defaultGraph())) {
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
3
13
|
export async function forAllShapes(shapePath, callback) {
|
|
4
14
|
const shapeDir = await fs.promises.readdir(shapePath, {
|
|
5
15
|
withFileTypes: true,
|
|
6
16
|
});
|
|
7
17
|
// Filter out non-shex documents
|
|
8
18
|
const shexFiles = shapeDir.filter((file) => file.isFile() && file.name.endsWith(".shex"));
|
|
9
|
-
|
|
19
|
+
const shexPromise = Promise.all(shexFiles.map(async (file) => {
|
|
10
20
|
const fileName = path.parse(file.name).name;
|
|
11
21
|
// Get the content of each document
|
|
12
22
|
const shexC = await fs.promises.readFile(path.join(shapePath, file.name), "utf8");
|
|
13
23
|
await callback(fileName, shexC);
|
|
14
24
|
}));
|
|
25
|
+
const shaclPromise = Promise.all(shapeDir.map(async (file) => {
|
|
26
|
+
if (file.isFile()) {
|
|
27
|
+
let store;
|
|
28
|
+
try {
|
|
29
|
+
store = await dereferenceToStore(path.join(shapePath, file.name), {
|
|
30
|
+
localFiles: true,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
catch (e) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
// Make sure the RDF file contains a SHACL shape
|
|
37
|
+
if (hasMatch(store.store, rdf.type, "http://www.w3.org/ns/shacl#NodeShape") ||
|
|
38
|
+
hasMatch(store.store, rdf.type, "http://www.w3.org/ns/shacl#PropertyShape")) {
|
|
39
|
+
const shex = await writeShexSchema(await shaclStoreToShexSchema(store.store), store.prefixes);
|
|
40
|
+
await callback(path.parse(file.name).name, shex);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}));
|
|
44
|
+
await Promise.all([shexPromise, shaclPromise]);
|
|
15
45
|
}
|
|
16
46
|
//# sourceMappingURL=forAllShapes.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"forAllShapes.js","sourceRoot":"","sources":["../../src/util/forAllShapes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"forAllShapes.js","sourceRoot":"","sources":["../../src/util/forAllShapes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,sBAAsB,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAC5E,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAE3D,OAAO,EAAE,WAAW,IAAI,EAAE,EAAE,M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,CAAC,GAAG,CAC9B,QAAQ,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;QAC1B,IAAI,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC;YAClB,IAAI,KAAqD,CAAC;YAC1D,IAAI,CAAC;gBACH,KAAK,GAAG,MAAM,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,IAAI,CAAC,EAAE;oBAChE,UAAU,EAAE,IAAI;iBACjB,CAAC,CAAC;YACL,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACX,OAAO;YACT,CAAC;YACD,gDAAgD;YAChD,IACE,QAAQ,CACN,KAAK,CAAC,KAAK,EACX,GAAG,CAAC,IAAI,EACR,sCAAsC,CACvC;gBACD,QAAQ,CACN,KAAK,CAAC,KAAK,EACX,GAAG,CAAC,IAAI,EACR,0CAA0C,CAC3C,EACD,CAAC;gBACD,MAAM,IAAI,GAAG,MAAM,eAAe,CAChC,MAAM,sBAAsB,CAAC,KAAK,CAAC,KAAK,CAAC,EACzC,KAAK,CAAC,QAAQ,CACf,CAAC;gBACF,MAAM,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;YACnD,CAAC;QACH,CAAC;IACH,CAAC,CAAC,CACH,CAAC;IACF,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,WAAW,EAAE,YAAY,CAAC,CAAC,CAAC;AACjD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ldo/cli",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.28",
|
|
4
4
|
"description": "A Command Line Interface for Linked Data Objects",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
"ldo": "./dist/index.js"
|
|
9
9
|
},
|
|
10
10
|
"scripts": {
|
|
11
|
-
"build": "npm run
|
|
11
|
+
"build": "npm run remove-dist && npm run build:ts && npm run copy-files && npm run update-permission",
|
|
12
12
|
"build:ts": "tsc --project tsconfig.cjs.json",
|
|
13
|
-
"
|
|
13
|
+
"remove-dist": "rimraf dist/",
|
|
14
14
|
"copy-files": "copyfiles -u 1 \"./src/**/*.ejs\" dist/",
|
|
15
15
|
"update-permission": "chmod +x ./dist/index.js",
|
|
16
16
|
"test": "jest --coverage",
|
|
@@ -40,8 +40,9 @@
|
|
|
40
40
|
"rimraf": "^3.0.2"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@
|
|
44
|
-
"@ldo/
|
|
43
|
+
"@jeswr/shacl2shex": "^1.1.0",
|
|
44
|
+
"@ldo/ldo": "^1.0.0-alpha.28",
|
|
45
|
+
"@ldo/schema-converter-shex": "^1.0.0-alpha.28",
|
|
45
46
|
"@shexjs/parser": "^1.0.0-alpha.24",
|
|
46
47
|
"child-process-promise": "^2.2.1",
|
|
47
48
|
"commander": "^9.3.0",
|
|
@@ -50,6 +51,8 @@
|
|
|
50
51
|
"loading-cli": "^1.1.0",
|
|
51
52
|
"prettier": "^3.0.3",
|
|
52
53
|
"prompts": "^2.4.2",
|
|
54
|
+
"rdf-dereference-store": "^1.4.0",
|
|
55
|
+
"rdf-namespaces": "^1.13.1",
|
|
53
56
|
"ts-morph": "^24.0.0",
|
|
54
57
|
"type-fest": "^2.19.0"
|
|
55
58
|
},
|
|
@@ -60,5 +63,5 @@
|
|
|
60
63
|
"publishConfig": {
|
|
61
64
|
"access": "public"
|
|
62
65
|
},
|
|
63
|
-
"gitHead": "
|
|
66
|
+
"gitHead": "45452a32a0166f8a3301c9810119780caa63707d"
|
|
64
67
|
}
|
package/src/util/forAllShapes.ts
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
import fs from "fs";
|
|
2
2
|
import path from "path";
|
|
3
|
+
import { shaclStoreToShexSchema, writeShexSchema } from "@jeswr/shacl2shex";
|
|
4
|
+
import { dereferenceToStore } from "rdf-dereference-store";
|
|
5
|
+
import type { Store } from "n3";
|
|
6
|
+
import { DataFactory as DF } from "n3";
|
|
7
|
+
import { rdf } from "rdf-namespaces";
|
|
8
|
+
|
|
9
|
+
function hasMatch(store: Store, predicate: string, object: string) {
|
|
10
|
+
for (const _ in store.match(
|
|
11
|
+
null,
|
|
12
|
+
DF.namedNode(predicate),
|
|
13
|
+
DF.namedNode(object),
|
|
14
|
+
DF.defaultGraph(),
|
|
15
|
+
)) {
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
3
20
|
|
|
4
21
|
export async function forAllShapes(
|
|
5
22
|
shapePath: string,
|
|
@@ -12,7 +29,7 @@ export async function forAllShapes(
|
|
|
12
29
|
const shexFiles = shapeDir.filter(
|
|
13
30
|
(file) => file.isFile() && file.name.endsWith(".shex"),
|
|
14
31
|
);
|
|
15
|
-
|
|
32
|
+
const shexPromise = Promise.all(
|
|
16
33
|
shexFiles.map(async (file) => {
|
|
17
34
|
const fileName = path.parse(file.name).name;
|
|
18
35
|
// Get the content of each document
|
|
@@ -23,4 +40,39 @@ export async function forAllShapes(
|
|
|
23
40
|
await callback(fileName, shexC);
|
|
24
41
|
}),
|
|
25
42
|
);
|
|
43
|
+
|
|
44
|
+
const shaclPromise = Promise.all(
|
|
45
|
+
shapeDir.map(async (file) => {
|
|
46
|
+
if (file.isFile()) {
|
|
47
|
+
let store: Awaited<ReturnType<typeof dereferenceToStore>>;
|
|
48
|
+
try {
|
|
49
|
+
store = await dereferenceToStore(path.join(shapePath, file.name), {
|
|
50
|
+
localFiles: true,
|
|
51
|
+
});
|
|
52
|
+
} catch (e) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
// Make sure the RDF file contains a SHACL shape
|
|
56
|
+
if (
|
|
57
|
+
hasMatch(
|
|
58
|
+
store.store,
|
|
59
|
+
rdf.type,
|
|
60
|
+
"http://www.w3.org/ns/shacl#NodeShape",
|
|
61
|
+
) ||
|
|
62
|
+
hasMatch(
|
|
63
|
+
store.store,
|
|
64
|
+
rdf.type,
|
|
65
|
+
"http://www.w3.org/ns/shacl#PropertyShape",
|
|
66
|
+
)
|
|
67
|
+
) {
|
|
68
|
+
const shex = await writeShexSchema(
|
|
69
|
+
await shaclStoreToShexSchema(store.store),
|
|
70
|
+
store.prefixes,
|
|
71
|
+
);
|
|
72
|
+
await callback(path.parse(file.name).name, shex);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}),
|
|
76
|
+
);
|
|
77
|
+
await Promise.all([shexPromise, shaclPromise]);
|
|
26
78
|
}
|