@lde/pipeline-shacl-validator 0.2.0 → 0.4.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/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/shacl-validator.d.ts +4 -0
- package/dist/shacl-validator.d.ts.map +1 -1
- package/dist/shacl-validator.js +20 -31
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export type { Validator, ValidationReport, ValidationResult, } from '@lde/pipeline';
|
|
1
|
+
export type { Validator, ValidationReport, ValidationResult, SerializationFormat, } from '@lde/pipeline';
|
|
2
2
|
export { ShaclValidator, type ShaclValidatorOptions, } from './shacl-validator.js';
|
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,SAAS,EACT,gBAAgB,EAChB,gBAAgB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,SAAS,EACT,gBAAgB,EAChB,gBAAgB,EAChB,mBAAmB,GACpB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,cAAc,EACd,KAAK,qBAAqB,GAC3B,MAAM,sBAAsB,CAAC"}
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import type { Quad } from '@rdfjs/types';
|
|
2
2
|
import type { Dataset } from '@lde/dataset';
|
|
3
3
|
import type { Validator, ValidationResult, ValidationReport } from '@lde/pipeline';
|
|
4
|
+
import { type SerializationFormat } from '@lde/pipeline';
|
|
4
5
|
/** Options for {@link ShaclValidator}. */
|
|
5
6
|
export interface ShaclValidatorOptions {
|
|
6
7
|
/** Path to an RDF file containing SHACL shapes (any format supported by rdf-dereference). */
|
|
7
8
|
shapesFile: string;
|
|
8
9
|
/** Directory for validation report files. */
|
|
9
10
|
reportDir: string;
|
|
11
|
+
/** Serialization format for report files. @default 'Turtle' */
|
|
12
|
+
reportFormat?: SerializationFormat;
|
|
10
13
|
}
|
|
11
14
|
/**
|
|
12
15
|
* SHACL-based {@link Validator} for `@lde/pipeline`.
|
|
@@ -18,6 +21,7 @@ export interface ShaclValidatorOptions {
|
|
|
18
21
|
export declare class ShaclValidator implements Validator {
|
|
19
22
|
private readonly shapesFile;
|
|
20
23
|
private readonly reportDir;
|
|
24
|
+
private readonly reportFormat;
|
|
21
25
|
private shapesDataset;
|
|
22
26
|
private readonly accumulators;
|
|
23
27
|
constructor(options: ShaclValidatorOptions);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shacl-validator.d.ts","sourceRoot":"","sources":["../src/shacl-validator.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"shacl-validator.d.ts","sourceRoot":"","sources":["../src/shacl-validator.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C,OAAO,KAAK,EACV,SAAS,EACT,gBAAgB,EAChB,gBAAgB,EACjB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAkB,KAAK,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAezE,0CAA0C;AAC1C,MAAM,WAAW,qBAAqB;IACpC,6FAA6F;IAC7F,UAAU,EAAE,MAAM,CAAC;IACnB,6CAA6C;IAC7C,SAAS,EAAE,MAAM,CAAC;IAClB,+DAA+D;IAC/D,YAAY,CAAC,EAAE,mBAAmB,CAAC;CACpC;AAQD;;;;;;GAMG;AACH,qBAAa,cAAe,YAAW,SAAS;IAC9C,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IACpC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAsB;IAEnD,OAAO,CAAC,aAAa,CAAkB;IACvC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAyC;gBAE1D,OAAO,EAAE,qBAAqB;IAMpC,QAAQ,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAmCpE,MAAM,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,gBAAgB,CAAC;YAc3C,SAAS;YAUT,eAAe;CA0B9B"}
|
package/dist/shacl-validator.js
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
import { mkdir, appendFile, writeFile } from 'node:fs/promises';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
|
-
import {
|
|
3
|
+
import { serializeQuads } from '@lde/pipeline';
|
|
4
4
|
// @ts-expect-error -- shacl-engine has no type declarations.
|
|
5
5
|
import ShaclEngine from 'shacl-engine/Validator.js';
|
|
6
6
|
// @ts-expect-error -- rdf-ext has no type declarations.
|
|
7
7
|
import rdf from 'rdf-ext';
|
|
8
8
|
import { rdfDereferencer } from 'rdf-dereference';
|
|
9
9
|
import filenamifyUrl from 'filenamify-url';
|
|
10
|
+
/** File extension per serialization format. */
|
|
11
|
+
const formatExtensions = {
|
|
12
|
+
Turtle: '.ttl',
|
|
13
|
+
'N-Triples': '.nt',
|
|
14
|
+
'N-Quads': '.nq',
|
|
15
|
+
};
|
|
10
16
|
/**
|
|
11
17
|
* SHACL-based {@link Validator} for `@lde/pipeline`.
|
|
12
18
|
*
|
|
@@ -17,12 +23,14 @@ import filenamifyUrl from 'filenamify-url';
|
|
|
17
23
|
export class ShaclValidator {
|
|
18
24
|
shapesFile;
|
|
19
25
|
reportDir;
|
|
26
|
+
reportFormat;
|
|
20
27
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
21
28
|
shapesDataset;
|
|
22
29
|
accumulators = new Map();
|
|
23
30
|
constructor(options) {
|
|
24
31
|
this.shapesFile = options.shapesFile;
|
|
25
32
|
this.reportDir = options.reportDir;
|
|
33
|
+
this.reportFormat = options.reportFormat ?? 'Turtle';
|
|
26
34
|
}
|
|
27
35
|
async validate(quads, dataset) {
|
|
28
36
|
if (quads.length === 0) {
|
|
@@ -67,16 +75,12 @@ export class ShaclValidator {
|
|
|
67
75
|
}
|
|
68
76
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
69
77
|
async getShapes() {
|
|
70
|
-
if (this.shapesDataset)
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
const dataset = rdf.dataset();
|
|
76
|
-
for await (const quad of data) {
|
|
77
|
-
dataset.add(quad);
|
|
78
|
+
if (!this.shapesDataset) {
|
|
79
|
+
const { data } = await rdfDereferencer.dereference(this.shapesFile, {
|
|
80
|
+
localFiles: true,
|
|
81
|
+
});
|
|
82
|
+
this.shapesDataset = await rdf.dataset().import(data);
|
|
78
83
|
}
|
|
79
|
-
this.shapesDataset = dataset;
|
|
80
84
|
return this.shapesDataset;
|
|
81
85
|
}
|
|
82
86
|
async writeReportFile(dataset,
|
|
@@ -84,31 +88,16 @@ export class ShaclValidator {
|
|
|
84
88
|
report) {
|
|
85
89
|
await mkdir(this.reportDir, { recursive: true });
|
|
86
90
|
const datasetName = filenamifyUrl(dataset.iri.toString());
|
|
87
|
-
const
|
|
88
|
-
|
|
91
|
+
const extension = formatExtensions[this.reportFormat];
|
|
92
|
+
const filePath = join(this.reportDir, `${datasetName}.validation${extension}`);
|
|
89
93
|
const reportQuads = [...report.dataset];
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
prefixes: {
|
|
93
|
-
sh: 'http://www.w3.org/ns/shacl#',
|
|
94
|
-
},
|
|
95
|
-
});
|
|
96
|
-
for (const quad of reportQuads) {
|
|
97
|
-
writer.addQuad(quad);
|
|
98
|
-
}
|
|
99
|
-
writer.end((error, result) => {
|
|
100
|
-
if (error)
|
|
101
|
-
reject(error);
|
|
102
|
-
else
|
|
103
|
-
resolve(result);
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
// Check if file exists; if so, append. Otherwise, create.
|
|
94
|
+
const serialized = await serializeQuads(reportQuads, this.reportFormat);
|
|
95
|
+
// Append to existing file or create a new one.
|
|
107
96
|
try {
|
|
108
|
-
await appendFile(filePath, '\n' +
|
|
97
|
+
await appendFile(filePath, '\n' + serialized);
|
|
109
98
|
}
|
|
110
99
|
catch {
|
|
111
|
-
await writeFile(filePath,
|
|
100
|
+
await writeFile(filePath, serialized);
|
|
112
101
|
}
|
|
113
102
|
return filePath;
|
|
114
103
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lde/pipeline-shacl-validator",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "SHACL validation for @lde/pipeline",
|
|
5
5
|
"repository": {
|
|
6
6
|
"url": "git+https://github.com/ldelements/lde.git",
|
|
@@ -32,10 +32,10 @@
|
|
|
32
32
|
"tslib": "^2.3.0"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"n3": "^2.0.
|
|
35
|
+
"n3": "^2.0.3"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
38
|
"@lde/dataset": "0.7.1",
|
|
39
|
-
"@lde/pipeline": "0.
|
|
39
|
+
"@lde/pipeline": "0.22.1"
|
|
40
40
|
}
|
|
41
41
|
}
|