@shaclmate/shacl-ast 4.0.8 → 4.0.9
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/Curie.d.ts +21 -0
- package/dist/Curie.js +29 -0
- package/dist/CurieFactory.d.ts +16 -0
- package/dist/CurieFactory.js +46 -0
- package/dist/PropertyShape.js +1 -1
- package/dist/ShapesGraph.d.ts +12 -2
- package/dist/ShapesGraph.js +35 -11
- package/dist/generated.d.ts +1506 -75
- package/dist/generated.js +591 -437
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/package.json +2 -2
package/dist/Curie.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { BlankNode, NamedNode } from "@rdfjs/types";
|
|
2
|
+
/**
|
|
3
|
+
* A Compact URI (https://www.w3.org/TR/curie)
|
|
4
|
+
*/
|
|
5
|
+
export declare class Curie implements NamedNode {
|
|
6
|
+
#private;
|
|
7
|
+
readonly prefix: string;
|
|
8
|
+
readonly reference: string;
|
|
9
|
+
readonly termType = "NamedNode";
|
|
10
|
+
readonly value: string;
|
|
11
|
+
constructor({ hasUniqueReference, prefix, reference, value, }: {
|
|
12
|
+
hasUniqueReference?: () => boolean;
|
|
13
|
+
prefix: string;
|
|
14
|
+
reference: string;
|
|
15
|
+
value: string;
|
|
16
|
+
});
|
|
17
|
+
equals(other: BlankNode | NamedNode): boolean;
|
|
18
|
+
get hasUniqueReference(): boolean;
|
|
19
|
+
toString(): string;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=Curie.d.ts.map
|
package/dist/Curie.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A Compact URI (https://www.w3.org/TR/curie)
|
|
3
|
+
*/
|
|
4
|
+
export class Curie {
|
|
5
|
+
prefix;
|
|
6
|
+
#hasUniqueReference;
|
|
7
|
+
reference;
|
|
8
|
+
termType = "NamedNode";
|
|
9
|
+
value;
|
|
10
|
+
constructor({ hasUniqueReference, prefix, reference, value, }) {
|
|
11
|
+
this.#hasUniqueReference = hasUniqueReference ?? (() => false);
|
|
12
|
+
this.prefix = prefix;
|
|
13
|
+
this.reference = reference;
|
|
14
|
+
this.value = value;
|
|
15
|
+
}
|
|
16
|
+
equals(other) {
|
|
17
|
+
if (other.termType === "BlankNode") {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
return this.value === other.value; // Allow a Curie to equal a NamedNode
|
|
21
|
+
}
|
|
22
|
+
get hasUniqueReference() {
|
|
23
|
+
return this.#hasUniqueReference();
|
|
24
|
+
}
|
|
25
|
+
toString() {
|
|
26
|
+
return `${this.prefix}:${this.reference}`;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=Curie.js.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type PrefixMap from "@rdfjs/prefix-map/PrefixMap.js";
|
|
2
|
+
import type { NamedNode } from "@rdfjs/types";
|
|
3
|
+
import { Maybe } from "purify-ts";
|
|
4
|
+
import { Curie } from "./Curie.js";
|
|
5
|
+
/**
|
|
6
|
+
* Factory for Compact URIs (CURIEs). Tracks whether the reference part of the CURIE is unique.
|
|
7
|
+
*/
|
|
8
|
+
export declare class CurieFactory {
|
|
9
|
+
private readonly prefixMap;
|
|
10
|
+
private readonly referenceCounts;
|
|
11
|
+
constructor({ prefixMap }: {
|
|
12
|
+
prefixMap: PrefixMap;
|
|
13
|
+
});
|
|
14
|
+
create(namedNode: NamedNode): Maybe<Curie>;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=CurieFactory.d.ts.map
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Maybe } from "purify-ts";
|
|
2
|
+
import { invariant } from "ts-invariant";
|
|
3
|
+
import { Curie } from "./Curie.js";
|
|
4
|
+
/**
|
|
5
|
+
* Factory for Compact URIs (CURIEs). Tracks whether the reference part of the CURIE is unique.
|
|
6
|
+
*/
|
|
7
|
+
export class CurieFactory {
|
|
8
|
+
prefixMap;
|
|
9
|
+
referenceCounts = {};
|
|
10
|
+
constructor({ prefixMap }) {
|
|
11
|
+
this.prefixMap = prefixMap;
|
|
12
|
+
}
|
|
13
|
+
create(namedNode) {
|
|
14
|
+
return Maybe.fromNullable(this.prefixMap.shrink(namedNode)?.value).map((value) => {
|
|
15
|
+
const split = value.split(":", 2);
|
|
16
|
+
invariant(split.length === 2);
|
|
17
|
+
const prefix = split[0];
|
|
18
|
+
const reference = split[1];
|
|
19
|
+
if (this.referenceCounts[reference] === undefined) {
|
|
20
|
+
this.referenceCounts[reference] = {};
|
|
21
|
+
}
|
|
22
|
+
if (this.referenceCounts[reference][prefix] === undefined) {
|
|
23
|
+
this.referenceCounts[reference][prefix] = 1;
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
this.referenceCounts[reference][prefix] += 1;
|
|
27
|
+
}
|
|
28
|
+
return new Curie({
|
|
29
|
+
hasUniqueReference: () => {
|
|
30
|
+
const referenceCounts = this.referenceCounts[reference];
|
|
31
|
+
if (Object.entries(referenceCounts).length === 1) {
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
// logger.debug(
|
|
35
|
+
// `duplicate local part ${reference} in ${JSON.stringify(referenceCounts)}`,
|
|
36
|
+
// );
|
|
37
|
+
return false;
|
|
38
|
+
},
|
|
39
|
+
prefix: split[0],
|
|
40
|
+
reference: split[1],
|
|
41
|
+
value: namedNode.value,
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=CurieFactory.js.map
|
package/dist/PropertyShape.js
CHANGED
|
@@ -37,7 +37,7 @@ export class PropertyShape extends Shape {
|
|
|
37
37
|
toString() {
|
|
38
38
|
return `PropertyShape(${[
|
|
39
39
|
`identifier=${Resource.Identifier.toString(this.identifier)}`,
|
|
40
|
-
`path=${PropertyPath
|
|
40
|
+
`path=${PropertyPath.toString(this.path)}`,
|
|
41
41
|
].join(", ")})`;
|
|
42
42
|
}
|
|
43
43
|
}
|
package/dist/ShapesGraph.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import PrefixMap from "@rdfjs/prefix-map/PrefixMap.js";
|
|
1
2
|
import TermMap from "@rdfjs/term-map";
|
|
2
3
|
import type { BlankNode, DatasetCore, NamedNode } from "@rdfjs/types";
|
|
3
4
|
import { Either } from "purify-ts";
|
|
4
5
|
import { Resource } from "rdfjs-resource";
|
|
6
|
+
import { CurieFactory } from "./CurieFactory.js";
|
|
5
7
|
import { NodeShape } from "./NodeShape.js";
|
|
6
8
|
import { Ontology } from "./Ontology.js";
|
|
7
9
|
import type { OntologyLike } from "./OntologyLike.js";
|
|
@@ -35,23 +37,28 @@ export declare namespace ShapesGraph {
|
|
|
35
37
|
constructor(parameters?: {
|
|
36
38
|
preferredLanguages?: readonly string[];
|
|
37
39
|
});
|
|
38
|
-
createShapesGraph({ dataset, ignoreUndefinedShapes, }: {
|
|
40
|
+
createShapesGraph({ dataset, prefixMap, ignoreUndefinedShapes, }: {
|
|
39
41
|
dataset: DatasetCore;
|
|
42
|
+
prefixMap?: PrefixMap;
|
|
40
43
|
ignoreUndefinedShapes?: boolean;
|
|
41
44
|
}): Either<Error, ShapesGraph<NodeShapeT, OntologyT, PropertyGroupT, PropertyShapeT, ShapeT>>;
|
|
42
45
|
protected abstract createNodeShape(parameters: {
|
|
46
|
+
curieFactory: CurieFactory;
|
|
43
47
|
resource: Resource;
|
|
44
48
|
shapesGraph: ShapesGraph<NodeShapeT, OntologyT, PropertyGroupT, PropertyShapeT, ShapeT>;
|
|
45
49
|
}): Either<Error, NodeShapeT>;
|
|
46
50
|
protected abstract createOntology(parameters: {
|
|
51
|
+
curieFactory: CurieFactory;
|
|
47
52
|
resource: Resource;
|
|
48
53
|
shapesGraph: ShapesGraph<NodeShapeT, OntologyT, PropertyGroupT, PropertyShapeT, ShapeT>;
|
|
49
54
|
}): Either<Error, OntologyT>;
|
|
50
55
|
protected abstract createPropertyGroup(parameters: {
|
|
56
|
+
curieFactory: CurieFactory;
|
|
51
57
|
resource: Resource;
|
|
52
58
|
shapesGraph: ShapesGraph<NodeShapeT, OntologyT, PropertyGroupT, PropertyShapeT, ShapeT>;
|
|
53
59
|
}): Either<Error, PropertyGroupT>;
|
|
54
60
|
protected abstract createPropertyShape(parameters: {
|
|
61
|
+
curieFactory: CurieFactory;
|
|
55
62
|
resource: Resource;
|
|
56
63
|
shapesGraph: ShapesGraph<NodeShapeT, OntologyT, PropertyGroupT, PropertyShapeT, ShapeT>;
|
|
57
64
|
}): Either<Error, PropertyShapeT>;
|
|
@@ -66,14 +73,17 @@ export declare namespace ShapesGraph {
|
|
|
66
73
|
shapesGraph: DefaultShapesGraph;
|
|
67
74
|
}): Either<Error, NodeShape<DefaultNodeShape, Ontology, PropertyGroup, DefaultPropertyShape, DefaultShape>>;
|
|
68
75
|
protected createOntology({ resource, }: {
|
|
76
|
+
curieFactory: CurieFactory;
|
|
69
77
|
resource: Resource;
|
|
70
78
|
shapesGraph: DefaultShapesGraph;
|
|
71
79
|
}): Either<Error, Ontology>;
|
|
72
80
|
protected createPropertyGroup({ resource, }: {
|
|
81
|
+
curieFactory: CurieFactory;
|
|
73
82
|
resource: Resource;
|
|
74
83
|
shapesGraph: DefaultShapesGraph;
|
|
75
84
|
}): Either<Error, PropertyGroup>;
|
|
76
|
-
protected createPropertyShape({ resource, shapesGraph, }: {
|
|
85
|
+
protected createPropertyShape({ curieFactory, resource, shapesGraph, }: {
|
|
86
|
+
curieFactory: CurieFactory;
|
|
77
87
|
resource: Resource;
|
|
78
88
|
shapesGraph: DefaultShapesGraph;
|
|
79
89
|
}): Either<Error, DefaultPropertyShape>;
|
package/dist/ShapesGraph.js
CHANGED
|
@@ -4,12 +4,15 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
4
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
|
+
import DataFactory from "@rdfjs/data-model";
|
|
8
|
+
import PrefixMap from "@rdfjs/prefix-map/PrefixMap.js";
|
|
7
9
|
import TermMap from "@rdfjs/term-map";
|
|
8
10
|
import TermSet from "@rdfjs/term-set";
|
|
9
11
|
import { owl, sh } from "@tpluscode/rdf-ns-builders";
|
|
10
12
|
import { Either, Left } from "purify-ts";
|
|
11
13
|
import { Resource, ResourceSet } from "rdfjs-resource";
|
|
12
14
|
import { Memoize } from "typescript-memoize";
|
|
15
|
+
import { CurieFactory } from "./CurieFactory.js";
|
|
13
16
|
import * as generated from "./generated.js";
|
|
14
17
|
import { NodeShape } from "./NodeShape.js";
|
|
15
18
|
import { Ontology } from "./Ontology.js";
|
|
@@ -84,14 +87,26 @@ __decorate([
|
|
|
84
87
|
constructor(parameters) {
|
|
85
88
|
this.preferredLanguages = parameters?.preferredLanguages ?? ["en", ""];
|
|
86
89
|
}
|
|
87
|
-
createShapesGraph({ dataset, ignoreUndefinedShapes, }) {
|
|
90
|
+
createShapesGraph({ dataset, prefixMap, ignoreUndefinedShapes, }) {
|
|
88
91
|
function datasetHasMatch(subject, predicate, object, graph) {
|
|
89
92
|
for (const _ of dataset.match(subject, predicate, object, graph)) {
|
|
90
93
|
return true;
|
|
91
94
|
}
|
|
92
95
|
return false;
|
|
93
96
|
}
|
|
97
|
+
const curieFactory = new CurieFactory({
|
|
98
|
+
prefixMap: prefixMap ?? new PrefixMap(undefined, { factory: DataFactory }),
|
|
99
|
+
});
|
|
94
100
|
const resourceSet = new ResourceSet(dataset);
|
|
101
|
+
const curieResource = (identifier) => {
|
|
102
|
+
if (identifier.termType === "NamedNode") {
|
|
103
|
+
const curie = curieFactory.create(identifier).extract();
|
|
104
|
+
if (curie) {
|
|
105
|
+
return resourceSet.resource(curie);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return resourceSet.resource(identifier);
|
|
109
|
+
};
|
|
95
110
|
const nodeShapesByIdentifier = new TermMap();
|
|
96
111
|
const ontologiesByIdentifier = new TermMap();
|
|
97
112
|
const propertyGroupsByIdentifier = new TermMap();
|
|
@@ -132,7 +147,8 @@ __decorate([
|
|
|
132
147
|
continue;
|
|
133
148
|
}
|
|
134
149
|
this.createOntology({
|
|
135
|
-
|
|
150
|
+
curieFactory,
|
|
151
|
+
resource: curieResource(ontologyResource.identifier),
|
|
136
152
|
shapesGraph,
|
|
137
153
|
}).ifRight((ontology) => ontologiesByIdentifier.set(ontologyResource.identifier, ontology));
|
|
138
154
|
}
|
|
@@ -145,7 +161,8 @@ __decorate([
|
|
|
145
161
|
continue;
|
|
146
162
|
}
|
|
147
163
|
this.createPropertyGroup({
|
|
148
|
-
|
|
164
|
+
curieFactory,
|
|
165
|
+
resource: curieResource(propertyGroupResource.identifier),
|
|
149
166
|
shapesGraph,
|
|
150
167
|
}).ifRight((propertyGroup) => propertyGroupsByIdentifier.set(propertyGroupResource.identifier, propertyGroup));
|
|
151
168
|
}
|
|
@@ -260,14 +277,16 @@ __decorate([
|
|
|
260
277
|
if (dataset.match(shapeNode, sh.path, null, graph).size > 0) {
|
|
261
278
|
// A property shape is a shape in the shapes graph that is the subject of a triple that has sh:path as its predicate. A shape has at most one value for sh:path. Each value of sh:path in a shape must be a well-formed SHACL property path. It is recommended, but not required, for a property shape to be declared as a SHACL instance of sh:PropertyShape. SHACL instances of sh:PropertyShape have one value for the property sh:path.
|
|
262
279
|
propertyShapesByIdentifier.set(shapeNode, this.createPropertyShape({
|
|
263
|
-
|
|
280
|
+
curieFactory,
|
|
281
|
+
resource: curieResource(shapeNode),
|
|
264
282
|
shapesGraph,
|
|
265
283
|
}).unsafeCoerce());
|
|
266
284
|
}
|
|
267
285
|
else {
|
|
268
286
|
// A node shape is a shape in the shapes graph that is not the subject of a triple with sh:path as its predicate. It is recommended, but not required, for a node shape to be declared as a SHACL instance of sh:NodeShape. SHACL instances of sh:NodeShape cannot have a value for the property sh:path.
|
|
269
287
|
nodeShapesByIdentifier.set(shapeNode, this.createNodeShape({
|
|
270
|
-
|
|
288
|
+
curieFactory,
|
|
289
|
+
resource: curieResource(shapeNode),
|
|
271
290
|
shapesGraph,
|
|
272
291
|
}).unsafeCoerce());
|
|
273
292
|
}
|
|
@@ -279,28 +298,33 @@ __decorate([
|
|
|
279
298
|
ShapesGraph.Factory = Factory;
|
|
280
299
|
class DefaultFactory extends Factory {
|
|
281
300
|
createNodeShape({ resource, shapesGraph, }) {
|
|
282
|
-
return generated.NodeShape.$
|
|
301
|
+
return generated.NodeShape.$fromRdfResource(resource, {
|
|
283
302
|
ignoreRdfType: true,
|
|
284
303
|
preferredLanguages: this.preferredLanguages,
|
|
285
304
|
}).map((generatedShape) => new NodeShape(generatedShape, shapesGraph));
|
|
286
305
|
}
|
|
287
306
|
createOntology({ resource, }) {
|
|
288
|
-
return generated.Ontology.$
|
|
307
|
+
return generated.Ontology.$fromRdfResource(resource, {
|
|
289
308
|
ignoreRdfType: true,
|
|
290
309
|
preferredLanguages: this.preferredLanguages,
|
|
291
310
|
}).map((generatedOntology) => new Ontology(generatedOntology));
|
|
292
311
|
}
|
|
293
312
|
createPropertyGroup({ resource, }) {
|
|
294
|
-
return generated.PropertyGroup.$
|
|
313
|
+
return generated.PropertyGroup.$fromRdfResource(resource, {
|
|
295
314
|
ignoreRdfType: true,
|
|
296
315
|
preferredLanguages: this.preferredLanguages,
|
|
297
316
|
}).map((propertyGroup) => new PropertyGroup(propertyGroup));
|
|
298
317
|
}
|
|
299
|
-
createPropertyShape({ resource, shapesGraph, }) {
|
|
300
|
-
return generated.PropertyShape.$
|
|
318
|
+
createPropertyShape({ curieFactory, resource, shapesGraph, }) {
|
|
319
|
+
return generated.PropertyShape.$fromRdfResource(resource, {
|
|
301
320
|
ignoreRdfType: true,
|
|
302
321
|
preferredLanguages: this.preferredLanguages,
|
|
303
|
-
}).map((generatedShape) => new PropertyShape(
|
|
322
|
+
}).map((generatedShape) => new PropertyShape({
|
|
323
|
+
...generatedShape,
|
|
324
|
+
path: (generatedShape.path.termType === "NamedNode"
|
|
325
|
+
? curieFactory.create(generatedShape.path).extract()
|
|
326
|
+
: undefined) ?? generatedShape.path,
|
|
327
|
+
}, shapesGraph));
|
|
304
328
|
}
|
|
305
329
|
}
|
|
306
330
|
const defaultFactory = new DefaultFactory();
|