Merge branch 'main' of github.com:o-development/ldo

main
Jackson Morgan 3 months ago
commit 93668183e0
  1. 1164
      package-lock.json
  2. 3
      packages/cli/package.json
  3. 54
      packages/cli/src/util/forAllShapes.ts

1164
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.12.0",
"ts-morph": "^24.0.0",
"type-fest": "^2.19.0"
},

@ -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]);
}

Loading…
Cancel
Save