feat: add support for SHACL

main
Jesse Wright 3 months ago
parent cc7ace8cfc
commit b4453c640f
  1. 45978
      package-lock.json
  2. 5
      packages/cli/package.json
  3. 54
      packages/cli/src/util/forAllShapes.ts
  4. 2
      packages/connected-nextgraph/package.json
  5. 2
      packages/connected-solid/package.json
  6. 2
      packages/test-solid-server/package.json

45978
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -40,6 +40,7 @@
"rimraf": "^3.0.2"
},
"dependencies": {
"@jeswr/shacl2shex": "^1.1.0",
"@ldo/ldo": "^1.0.0-alpha.21",
"@ldo/schema-converter-shex": "^1.0.0-alpha.21",
"@shexjs/parser": "^1.0.0-alpha.24",
@ -50,6 +51,8 @@
"loading-cli": "^1.1.0",
"prettier": "^3.0.3",
"prompts": "^2.4.2",
"rdf-dereference-store": "^1.4.0",
"rdf-namespaces": "^1.13.1",
"ts-morph": "^24.0.0",
"type-fest": "^2.19.0"
},
@ -61,4 +64,4 @@
"access": "public"
},
"gitHead": "840910c56ec3f61416f031cc76771a5673af6757"
}
}

@ -1,5 +1,22 @@
import fs from "fs";
import path from "path";
import { shaclStoreToShexSchema, writeShexSchema } from "@jeswr/shacl2shex";
import { dereferenceToStore } from "rdf-dereference-store";
import type { Store } from "n3";
import { DataFactory as DF } from "n3";
import { rdf } from "rdf-namespaces";
function hasMatch(store: Store, predicate: string, object: string) {
for (const _ in store.match(
null,
DF.namedNode(predicate),
DF.namedNode(object),
DF.defaultGraph(),
)) {
return true;
}
return false;
}
export async function forAllShapes(
shapePath: string,
@ -12,7 +29,7 @@ export async function forAllShapes(
const shexFiles = shapeDir.filter(
(file) => file.isFile() && file.name.endsWith(".shex"),
);
await Promise.all(
const shexPromise = Promise.all(
shexFiles.map(async (file) => {
const fileName = path.parse(file.name).name;
// Get the content of each document
@ -23,4 +40,39 @@ export async function forAllShapes(
await callback(fileName, shexC);
}),
);
const shaclPromise = Promise.all(
shapeDir.map(async (file) => {
if (file.isFile()) {
let store: Awaited<ReturnType<typeof dereferenceToStore>>;
try {
store = await dereferenceToStore(path.join(shapePath, file.name), {
localFiles: true,
});
} catch (e) {
return;
}
// Make sure the RDF file contains a SHACL shape
if (
hasMatch(
store.store,
rdf.type,
"http://www.w3.org/ns/shacl#NodeShape",
) ||
hasMatch(
store.store,
rdf.type,
"http://www.w3.org/ns/shacl#PropertyShape",
)
) {
const shex = await writeShexSchema(
await shaclStoreToShexSchema(store.store),
store.prefixes,
);
await callback(path.parse(file.name).name, shex);
}
}
}),
);
await Promise.all([shexPromise, shaclPromise]);
}

@ -42,7 +42,7 @@
"@ldo/cli": "^1.0.0-alpha.21",
"@rdfjs/types": "^1.0.1",
"@solid-notifications/types": "^0.1.2",
"@solid/community-server": "^7.1.3",
"@solid/community-server": "8.0.0-alpha.0",
"cross-env": "^7.0.3",
"dotenv": "^16.3.1",
"jest-rdf": "^1.8.0",

@ -41,7 +41,7 @@
"@ldo/test-solid-server": "^1.0.0-alpha.24",
"@rdfjs/types": "^1.0.1",
"@solid-notifications/types": "^0.1.2",
"@solid/community-server": "^7.1.3",
"@solid/community-server": "8.0.0-alpha.0",
"cross-env": "^7.0.3",
"ts-node": "^10.9.1",
"typed-emitter": "^2.1.0",

@ -35,7 +35,7 @@
"homepage": "https://github.com/o-development/ldo/tree/main/packages/solid#readme",
"dependencies": {
"@inrupt/solid-client-authn-core": "^2.2.6",
"@solid/community-server": "^7.1.3",
"@solid/community-server": "8.0.0-alpha.0",
"cross-env": "^7.0.3"
},
"files": [

Loading…
Cancel
Save