@shaclmate/compiler 2.0.13 → 2.0.14
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/Compiler.d.ts +15 -0
- package/Compiler.js +20 -0
- package/ShapesGraphToAstTransformer.d.ts +18 -23
- package/ShapesGraphToAstTransformer.js +21 -447
- package/_ShapesGraphToAstTransformer/NodeShapeAstType.d.ts +3 -0
- package/_ShapesGraphToAstTransformer/NodeShapeAstType.js +2 -0
- package/_ShapesGraphToAstTransformer/index.d.ts +10 -0
- package/_ShapesGraphToAstTransformer/index.js +10 -0
- package/_ShapesGraphToAstTransformer/pickLiteral.d.ts +4 -0
- package/_ShapesGraphToAstTransformer/pickLiteral.js +18 -0
- package/_ShapesGraphToAstTransformer/propertyShapeNodeKinds.d.ts +4 -0
- package/_ShapesGraphToAstTransformer/propertyShapeNodeKinds.js +26 -0
- package/_ShapesGraphToAstTransformer/shapeAstName.d.ts +5 -0
- package/_ShapesGraphToAstTransformer/shapeAstName.js +28 -0
- package/_ShapesGraphToAstTransformer/transformNodeShapeToAstType.d.ts +6 -0
- package/_ShapesGraphToAstTransformer/transformNodeShapeToAstType.js +165 -0
- package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstCompositeType.d.ts +13 -0
- package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstCompositeType.js +198 -0
- package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstIdentifierType.d.ts +12 -0
- package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstIdentifierType.js +29 -0
- package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstLiteralType.d.ts +12 -0
- package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstLiteralType.js +43 -0
- package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstObjectTypeProperty.d.ts +6 -0
- package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstObjectTypeProperty.js +31 -0
- package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstTermType.d.ts +14 -0
- package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstTermType.js +21 -0
- package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstType.d.ts +16 -0
- package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstType.js +58 -0
- package/ast/Ast.d.ts +5 -0
- package/ast/CompositeType.d.ts +13 -0
- package/ast/CompositeType.js +2 -0
- package/ast/IdentifierType.d.ts +3 -6
- package/ast/IntersectionType.d.ts +2 -2
- package/ast/ListType.d.ts +53 -0
- package/ast/ListType.js +2 -0
- package/ast/LiteralType.d.ts +4 -3
- package/ast/Name.d.ts +1 -0
- package/ast/ObjectCompositeType.d.ts +22 -0
- package/ast/ObjectCompositeType.js +2 -0
- package/ast/ObjectIntersectionType.d.ts +8 -0
- package/ast/ObjectIntersectionType.js +2 -0
- package/ast/ObjectType.d.ts +91 -19
- package/ast/ObjectType.js +26 -1
- package/ast/ObjectUnionType.d.ts +19 -0
- package/ast/ObjectUnionType.js +2 -0
- package/ast/PlaceholderType.d.ts +7 -0
- package/ast/PlaceholderType.js +2 -0
- package/ast/SetType.d.ts +1 -1
- package/ast/TermType.d.ts +11 -0
- package/ast/TermType.js +2 -0
- package/ast/Type.d.ts +11 -3
- package/ast/UnionType.d.ts +3 -3
- package/ast/index.d.ts +6 -3
- package/ast/index.js +6 -3
- package/enums/MintingStrategy.d.ts +5 -0
- package/enums/MintingStrategy.js +2 -0
- package/enums/PropertyVisibility.d.ts +2 -0
- package/enums/PropertyVisibility.js +2 -0
- package/enums/TsFeature.d.ts +5 -0
- package/enums/TsFeature.js +16 -0
- package/enums/TsObjectDeclarationType.d.ts +5 -0
- package/enums/TsObjectDeclarationType.js +2 -0
- package/enums/index.d.ts +5 -0
- package/enums/index.js +5 -0
- package/generators/Generator.d.ts +5 -0
- package/generators/Generator.js +2 -0
- package/generators/index.d.ts +2 -2
- package/generators/index.js +2 -2
- package/generators/json/AstJsonGenerator.d.ts +4 -5
- package/generators/json/AstJsonGenerator.js +31 -22
- package/generators/ts/BooleanType.d.ts +7 -3
- package/generators/ts/BooleanType.js +58 -4
- package/generators/ts/DateTimeType.d.ts +17 -0
- package/generators/ts/DateTimeType.js +58 -0
- package/generators/ts/DeclaredType.d.ts +17 -0
- package/generators/ts/DeclaredType.js +10 -0
- package/generators/ts/IdentifierType.d.ts +7 -17
- package/generators/ts/IdentifierType.js +69 -60
- package/generators/ts/Import.d.ts +18 -0
- package/generators/ts/Import.js +59 -0
- package/generators/ts/ListType.d.ts +18 -8
- package/generators/ts/ListType.js +197 -43
- package/generators/ts/LiteralType.d.ts +13 -11
- package/generators/ts/LiteralType.js +36 -51
- package/generators/ts/NumberType.d.ts +7 -3
- package/generators/ts/NumberType.js +55 -4
- package/generators/ts/ObjectType.d.ts +47 -25
- package/generators/ts/ObjectType.js +222 -49
- package/generators/ts/ObjectUnionType.d.ts +58 -0
- package/generators/ts/ObjectUnionType.js +481 -0
- package/generators/ts/OptionType.d.ts +12 -4
- package/generators/ts/OptionType.js +65 -16
- package/generators/ts/PrimitiveType.d.ts +15 -5
- package/generators/ts/PrimitiveType.js +20 -29
- package/generators/ts/SetType.d.ts +12 -4
- package/generators/ts/SetType.js +103 -29
- package/generators/ts/StringType.d.ts +8 -3
- package/generators/ts/StringType.js +57 -3
- package/generators/ts/TermType.d.ts +52 -0
- package/generators/ts/TermType.js +234 -0
- package/generators/ts/TsGenerator.d.ts +4 -12
- package/generators/ts/TsGenerator.js +44 -100
- package/generators/ts/Type.d.ts +107 -46
- package/generators/ts/Type.js +78 -61
- package/generators/ts/TypeFactory.d.ts +4 -5
- package/generators/ts/TypeFactory.js +212 -89
- package/generators/ts/UnionType.d.ts +19 -6
- package/generators/ts/UnionType.js +230 -120
- package/generators/ts/_ObjectType/IdentifierProperty.d.ts +27 -7
- package/generators/ts/_ObjectType/IdentifierProperty.js +143 -31
- package/generators/ts/_ObjectType/Property.d.ts +125 -9
- package/generators/ts/_ObjectType/Property.js +25 -3
- package/generators/ts/_ObjectType/ShaclProperty.d.ts +23 -5
- package/generators/ts/_ObjectType/ShaclProperty.js +100 -26
- package/generators/ts/_ObjectType/TypeDiscriminatorProperty.d.ts +24 -6
- package/generators/ts/_ObjectType/TypeDiscriminatorProperty.js +75 -13
- package/generators/ts/_ObjectType/classDeclaration.d.ts +2 -1
- package/generators/ts/_ObjectType/classDeclaration.js +79 -111
- package/generators/ts/_ObjectType/createFunctionDeclaration.d.ts +5 -0
- package/generators/ts/_ObjectType/createFunctionDeclaration.js +60 -0
- package/generators/ts/_ObjectType/equalsFunctionDeclaration.d.ts +2 -1
- package/generators/ts/_ObjectType/equalsFunctionDeclaration.js +12 -20
- package/generators/ts/_ObjectType/equalsFunctionOrMethodDeclaration.d.ts +11 -0
- package/generators/ts/_ObjectType/equalsFunctionOrMethodDeclaration.js +70 -0
- package/generators/ts/_ObjectType/fromJsonFunctionDeclarations.d.ts +4 -0
- package/generators/ts/_ObjectType/fromJsonFunctionDeclarations.js +78 -0
- package/generators/ts/_ObjectType/fromRdfFunctionDeclarations.d.ts +4 -0
- package/generators/ts/_ObjectType/fromRdfFunctionDeclarations.js +91 -0
- package/generators/ts/_ObjectType/hashFunctionDeclaration.d.ts +3 -3
- package/generators/ts/_ObjectType/hashFunctionDeclaration.js +11 -55
- package/generators/ts/_ObjectType/hashFunctionOrMethodDeclaration.d.ts +11 -0
- package/generators/ts/_ObjectType/hashFunctionOrMethodDeclaration.js +64 -0
- package/generators/ts/_ObjectType/index.d.ts +8 -2
- package/generators/ts/_ObjectType/index.js +8 -2
- package/generators/ts/_ObjectType/interfaceDeclaration.d.ts +3 -2
- package/generators/ts/_ObjectType/interfaceDeclaration.js +11 -2
- package/generators/ts/_ObjectType/jsonSchemaFunctionDeclaration.d.ts +5 -0
- package/generators/ts/_ObjectType/jsonSchemaFunctionDeclaration.js +19 -0
- package/generators/ts/_ObjectType/jsonUiSchemaFunctionDeclaration.d.ts +5 -0
- package/generators/ts/_ObjectType/jsonUiSchemaFunctionDeclaration.js +31 -0
- package/generators/ts/_ObjectType/jsonZodSchemaFunctionDeclaration.d.ts +5 -0
- package/generators/ts/_ObjectType/jsonZodSchemaFunctionDeclaration.js +37 -0
- package/generators/ts/_ObjectType/rdfjsTermExpression.d.ts +6 -0
- package/generators/ts/{rdfjsTermExpression.js → _ObjectType/rdfjsTermExpression.js} +3 -1
- package/generators/ts/_ObjectType/sparqlFunctionDeclarations.d.ts +4 -0
- package/generators/ts/_ObjectType/sparqlFunctionDeclarations.js +101 -0
- package/generators/ts/_ObjectType/toJsonFunctionDeclaration.d.ts +5 -0
- package/generators/ts/_ObjectType/toJsonFunctionDeclaration.js +19 -0
- package/generators/ts/_ObjectType/toJsonFunctionOrMethodDeclaration.d.ts +10 -0
- package/generators/ts/_ObjectType/toJsonFunctionOrMethodDeclaration.js +59 -0
- package/generators/ts/_ObjectType/toJsonReturnType.d.ts +3 -0
- package/generators/ts/_ObjectType/toJsonReturnType.js +19 -0
- package/generators/ts/_ObjectType/toRdfFunctionDeclaration.d.ts +3 -2
- package/generators/ts/_ObjectType/toRdfFunctionDeclaration.js +11 -45
- package/generators/ts/_ObjectType/toRdfFunctionOrMethodDeclaration.d.ts +10 -0
- package/generators/ts/_ObjectType/toRdfFunctionOrMethodDeclaration.js +67 -0
- package/generators/ts/objectInitializer.d.ts +2 -0
- package/generators/ts/objectInitializer.js +14 -0
- package/generators/ts/tsComment.d.ts +5 -0
- package/generators/ts/tsComment.js +11 -0
- package/generators/ts/tsName.d.ts +1 -1
- package/generators/ts/tsName.js +1 -0
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/input/NodeShape.d.ts +46 -0
- package/input/NodeShape.js +165 -0
- package/input/Ontology.d.ts +13 -0
- package/input/Ontology.js +30 -0
- package/input/PropertyShape.d.ts +15 -0
- package/input/PropertyShape.js +34 -0
- package/input/Shape.d.ts +4 -0
- package/input/Shape.js +2 -0
- package/input/ShapesGraph.d.ts +9 -0
- package/input/ShapesGraph.js +50 -0
- package/input/ancestorClassIris.d.ts +4 -0
- package/input/ancestorClassIris.js +21 -0
- package/input/descendantClassIris.d.ts +4 -0
- package/input/descendantClassIris.js +21 -0
- package/input/generated.d.ts +274 -0
- package/input/generated.js +1420 -0
- package/input/index.d.ts +7 -0
- package/input/index.js +7 -0
- package/input/tsFeatures.d.ts +10 -0
- package/input/tsFeatures.js +42 -0
- package/package.json +14 -8
- package/ast/MintingStrategy.d.ts +0 -8
- package/ast/MintingStrategy.js +0 -9
- package/generators/ts/Configuration.d.ts +0 -29
- package/generators/ts/Configuration.js +0 -40
- package/generators/ts/IntersectionType.d.ts +0 -14
- package/generators/ts/IntersectionType.js +0 -26
- package/generators/ts/RdfjsTermType.d.ts +0 -25
- package/generators/ts/RdfjsTermType.js +0 -46
- package/generators/ts/_ObjectType/fromRdfFunctionDeclaration.d.ts +0 -4
- package/generators/ts/_ObjectType/fromRdfFunctionDeclaration.js +0 -72
- package/generators/ts/_ObjectType/sparqlGraphPatternsClassDeclaration.d.ts +0 -4
- package/generators/ts/_ObjectType/sparqlGraphPatternsClassDeclaration.js +0 -46
- package/generators/ts/rdfjsTermExpression.d.ts +0 -5
- package/vocabularies/dashDataset.d.ts +0 -3
- package/vocabularies/dashDataset.js +0 -2370
- package/vocabularies/index.d.ts +0 -2
- package/vocabularies/index.js +0 -2
- package/vocabularies/shaclmate.d.ts +0 -15
- package/vocabularies/shaclmate.js +0 -6
package/Compiler.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import PrefixMap from "@rdfjs/prefix-map/PrefixMap.js";
|
|
2
|
+
import type { DatasetCore } from "@rdfjs/types";
|
|
3
|
+
import type { Either } from "purify-ts";
|
|
4
|
+
import type { Generator } from "./generators/Generator.js";
|
|
5
|
+
import { ShapesGraph } from "./input/ShapesGraph.js";
|
|
6
|
+
export declare class Compiler {
|
|
7
|
+
private readonly generator;
|
|
8
|
+
private readonly iriPrefixMap;
|
|
9
|
+
constructor({ generator, iriPrefixMap, }: {
|
|
10
|
+
generator: Generator;
|
|
11
|
+
iriPrefixMap?: PrefixMap;
|
|
12
|
+
});
|
|
13
|
+
compile(input: DatasetCore | ShapesGraph): Either<Error, string>;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=Compiler.d.ts.map
|
package/Compiler.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import PrefixMap from "@rdfjs/prefix-map/PrefixMap.js";
|
|
2
|
+
import { ShapesGraphToAstTransformer } from "./ShapesGraphToAstTransformer.js";
|
|
3
|
+
import { ShapesGraph } from "./input/ShapesGraph.js";
|
|
4
|
+
export class Compiler {
|
|
5
|
+
constructor({ generator, iriPrefixMap, }) {
|
|
6
|
+
this.generator = generator;
|
|
7
|
+
this.iriPrefixMap = iriPrefixMap ?? new PrefixMap();
|
|
8
|
+
}
|
|
9
|
+
compile(input) {
|
|
10
|
+
const shapesGraph = input instanceof ShapesGraph
|
|
11
|
+
? input
|
|
12
|
+
: new ShapesGraph({ dataset: input });
|
|
13
|
+
const astEither = new ShapesGraphToAstTransformer({
|
|
14
|
+
iriPrefixMap: this.iriPrefixMap,
|
|
15
|
+
shapesGraph,
|
|
16
|
+
}).transform();
|
|
17
|
+
return astEither.map((ast) => this.generator.generate(ast));
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=Compiler.js.map
|
|
@@ -1,32 +1,27 @@
|
|
|
1
1
|
import type PrefixMap from "@rdfjs/prefix-map/PrefixMap.js";
|
|
2
|
-
import
|
|
2
|
+
import TermMap from "@rdfjs/term-map";
|
|
3
|
+
import type * as rdfjs from "@rdfjs/types";
|
|
3
4
|
import { Either } from "purify-ts";
|
|
4
|
-
import
|
|
5
|
+
import * as _ShapesGraphToAstTransformer from "./_ShapesGraphToAstTransformer/index.js";
|
|
6
|
+
import type * as ast from "./ast/index.js";
|
|
7
|
+
import type * as input from "./input/index.js";
|
|
5
8
|
export declare class ShapesGraphToAstTransformer {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
protected readonly astObjectTypePropertiesByIdentifier: TermMap<rdfjs.BlankNode | rdfjs.NamedNode, ast.ObjectType.Property>;
|
|
10
|
+
protected readonly iriPrefixMap: PrefixMap;
|
|
11
|
+
protected readonly nodeShapeAstTypesByIdentifier: TermMap<rdfjs.BlankNode | rdfjs.NamedNode, _ShapesGraphToAstTransformer.NodeShapeAstType>;
|
|
12
|
+
protected shapeAstName: typeof _ShapesGraphToAstTransformer.shapeAstName;
|
|
13
|
+
protected readonly shapesGraph: input.ShapesGraph;
|
|
14
|
+
protected transformNodeShapeToAstType: typeof _ShapesGraphToAstTransformer.transformNodeShapeToAstType;
|
|
15
|
+
protected transformPropertyShapeToAstCompositeType: typeof _ShapesGraphToAstTransformer.transformPropertyShapeToAstCompositeType;
|
|
16
|
+
protected transformPropertyShapeToAstIdentifierType: typeof _ShapesGraphToAstTransformer.transformPropertyShapeToAstIdentifierType;
|
|
17
|
+
protected transformPropertyShapeToAstLiteralType: typeof _ShapesGraphToAstTransformer.transformPropertyShapeToAstLiteralType;
|
|
18
|
+
protected transformPropertyShapeToAstObjectTypeProperty: typeof _ShapesGraphToAstTransformer.transformPropertyShapeToAstObjectTypeProperty;
|
|
19
|
+
protected transformPropertyShapeToAstTermType: typeof _ShapesGraphToAstTransformer.transformPropertyShapeToAstTermType;
|
|
20
|
+
protected transformPropertyShapeToAstType: typeof _ShapesGraphToAstTransformer.transformPropertyShapeToAstType;
|
|
10
21
|
constructor({ iriPrefixMap, shapesGraph, }: {
|
|
11
22
|
iriPrefixMap: PrefixMap;
|
|
12
|
-
shapesGraph:
|
|
23
|
+
shapesGraph: input.ShapesGraph;
|
|
13
24
|
});
|
|
14
25
|
transform(): Either<Error, ast.Ast>;
|
|
15
|
-
/**
|
|
16
|
-
* Is an ast.ObjectType actually the shape of an RDF list?
|
|
17
|
-
* If so, return the type of its rdf:first.
|
|
18
|
-
*/
|
|
19
|
-
private astObjectTypeListItemType;
|
|
20
|
-
private nodeShapeAstType;
|
|
21
|
-
private propertyShapeAstObjectTypeProperty;
|
|
22
|
-
/**
|
|
23
|
-
* Try to convert a property shape to a type using some heuristics.
|
|
24
|
-
*
|
|
25
|
-
* We don't try to handle exotic cases allowed by the SHACL spec, such as combinations of sh:in and sh:node. Instead we assume
|
|
26
|
-
* a shape has one type.
|
|
27
|
-
*/
|
|
28
|
-
private propertyShapeAstType;
|
|
29
|
-
private resolveClassAstObjectType;
|
|
30
|
-
private shapeName;
|
|
31
26
|
}
|
|
32
27
|
//# sourceMappingURL=ShapesGraphToAstTransformer.d.ts.map
|
|
@@ -1,461 +1,35 @@
|
|
|
1
1
|
import TermMap from "@rdfjs/term-map";
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import { Either, Left, Maybe } from "purify-ts";
|
|
6
|
-
import { invariant } from "ts-invariant";
|
|
7
|
-
import { MintingStrategy } from "./ast/MintingStrategy";
|
|
8
|
-
import { logger } from "./logger.js";
|
|
9
|
-
import { shaclmate } from "./vocabularies/";
|
|
10
|
-
function ancestorClassIris(classResource, maxDepth) {
|
|
11
|
-
const ancestorClassIris = new TermSet();
|
|
12
|
-
function ancestorClassIrisRecursive(classResource, depth) {
|
|
13
|
-
for (const parentClassValue of classResource.values(rdfs.subClassOf)) {
|
|
14
|
-
parentClassValue.toNamedResource().ifRight((parentClassResource) => {
|
|
15
|
-
if (ancestorClassIris.has(parentClassResource.identifier)) {
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
ancestorClassIris.add(parentClassResource.identifier);
|
|
19
|
-
if (depth < maxDepth) {
|
|
20
|
-
ancestorClassIrisRecursive(parentClassResource, depth + 1);
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
ancestorClassIrisRecursive(classResource, 1);
|
|
26
|
-
return [...ancestorClassIris];
|
|
27
|
-
}
|
|
28
|
-
function descendantClassIris(classResource, maxDepth) {
|
|
29
|
-
const descendantClassIris = new TermSet();
|
|
30
|
-
function descendantClassIrisRecursive(classResource, depth) {
|
|
31
|
-
for (const childClassValue of classResource.valuesOf(rdfs.subClassOf)) {
|
|
32
|
-
childClassValue.toNamedResource().ifRight((childClassResource) => {
|
|
33
|
-
if (descendantClassIris.has(childClassResource.identifier)) {
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
descendantClassIris.add(childClassResource.identifier);
|
|
37
|
-
if (depth < maxDepth) {
|
|
38
|
-
descendantClassIrisRecursive(childClassResource, depth + 1);
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
descendantClassIrisRecursive(classResource, 1);
|
|
44
|
-
return [...descendantClassIris];
|
|
45
|
-
}
|
|
46
|
-
function shaclmateInline(shape) {
|
|
47
|
-
return shape.resource
|
|
48
|
-
.value(shaclmate.inline)
|
|
49
|
-
.chain((value) => value.toBoolean())
|
|
50
|
-
.toMaybe();
|
|
51
|
-
}
|
|
52
|
-
function shaclmateName(shape) {
|
|
53
|
-
return shape.resource
|
|
54
|
-
.value(shaclmate.name)
|
|
55
|
-
.chain((value) => value.toString())
|
|
56
|
-
.toMaybe();
|
|
57
|
-
}
|
|
2
|
+
import { dash } from "@tpluscode/rdf-ns-builders";
|
|
3
|
+
import { Either, Maybe } from "purify-ts";
|
|
4
|
+
import * as _ShapesGraphToAstTransformer from "./_ShapesGraphToAstTransformer/index.js";
|
|
58
5
|
export class ShapesGraphToAstTransformer {
|
|
59
6
|
constructor({ iriPrefixMap, shapesGraph, }) {
|
|
7
|
+
// Members are protected so they're accessible to the bound functions
|
|
60
8
|
this.astObjectTypePropertiesByIdentifier = new TermMap();
|
|
61
9
|
this.nodeShapeAstTypesByIdentifier = new TermMap();
|
|
10
|
+
this.shapeAstName = _ShapesGraphToAstTransformer.shapeAstName;
|
|
11
|
+
this.transformNodeShapeToAstType = _ShapesGraphToAstTransformer.transformNodeShapeToAstType;
|
|
12
|
+
this.transformPropertyShapeToAstCompositeType = _ShapesGraphToAstTransformer.transformPropertyShapeToAstCompositeType;
|
|
13
|
+
this.transformPropertyShapeToAstIdentifierType = _ShapesGraphToAstTransformer.transformPropertyShapeToAstIdentifierType;
|
|
14
|
+
this.transformPropertyShapeToAstLiteralType = _ShapesGraphToAstTransformer.transformPropertyShapeToAstLiteralType;
|
|
15
|
+
this.transformPropertyShapeToAstObjectTypeProperty = _ShapesGraphToAstTransformer.transformPropertyShapeToAstObjectTypeProperty;
|
|
16
|
+
this.transformPropertyShapeToAstTermType = _ShapesGraphToAstTransformer.transformPropertyShapeToAstTermType;
|
|
17
|
+
this.transformPropertyShapeToAstType = _ShapesGraphToAstTransformer.transformPropertyShapeToAstType;
|
|
62
18
|
this.iriPrefixMap = iriPrefixMap;
|
|
63
19
|
this.shapesGraph = shapesGraph;
|
|
64
20
|
}
|
|
65
21
|
transform() {
|
|
66
22
|
return Either.sequence(this.shapesGraph.nodeShapes
|
|
67
|
-
.filter((nodeShape) => nodeShape.
|
|
68
|
-
!nodeShape.
|
|
69
|
-
.map((nodeShape) => this.
|
|
70
|
-
|
|
23
|
+
.filter((nodeShape) => nodeShape.identifier.termType === "NamedNode" &&
|
|
24
|
+
!nodeShape.identifier.value.startsWith(dash[""].value))
|
|
25
|
+
.map((nodeShape) => this.transformNodeShapeToAstType(nodeShape))).map((nodeShapeAstTypes) => ({
|
|
26
|
+
objectIntersectionTypes: nodeShapeAstTypes.filter((nodeShapeAstType) => nodeShapeAstType.kind === "ObjectIntersectionType"),
|
|
27
|
+
objectTypes: nodeShapeAstTypes.filter((nodeShapeAstType) => nodeShapeAstType.kind === "ObjectType"),
|
|
28
|
+
objectUnionTypes: nodeShapeAstTypes.filter((nodeShapeAstType) => nodeShapeAstType.kind === "ObjectUnionType"),
|
|
29
|
+
tsDataFactoryVariable: (this.shapesGraph.ontologies.length === 1
|
|
30
|
+
? this.shapesGraph.ontologies[0].tsDataFactoryVariable
|
|
31
|
+
: Maybe.empty()).orDefault("dataFactory"),
|
|
71
32
|
}));
|
|
72
33
|
}
|
|
73
|
-
/**
|
|
74
|
-
* Is an ast.ObjectType actually the shape of an RDF list?
|
|
75
|
-
* If so, return the type of its rdf:first.
|
|
76
|
-
*/
|
|
77
|
-
astObjectTypeListItemType(astObjectType, nodeShape) {
|
|
78
|
-
if (!nodeShape.resource.isSubClassOf(rdf.List)) {
|
|
79
|
-
return Left(new Error(`${nodeShape} is not an rdfs:subClassOf rdf:List`));
|
|
80
|
-
}
|
|
81
|
-
if (astObjectType.properties.length !== 2) {
|
|
82
|
-
return Left(new Error(`${nodeShape} does not have exactly two properties`));
|
|
83
|
-
}
|
|
84
|
-
// rdf:first can have any type
|
|
85
|
-
// The type of the rdf:first property is the list item type.
|
|
86
|
-
const firstProperty = astObjectType.properties.find((property) => property.path.iri.equals(rdf.first));
|
|
87
|
-
if (!firstProperty) {
|
|
88
|
-
return Left(new Error(`${nodeShape} does not have an rdf:first property`));
|
|
89
|
-
}
|
|
90
|
-
const restProperty = astObjectType.properties.find((property) => property.path.iri.equals(rdf.rest));
|
|
91
|
-
if (!restProperty) {
|
|
92
|
-
return Left(new Error(`${nodeShape} does not have an rdf:rest property`));
|
|
93
|
-
}
|
|
94
|
-
if (restProperty.type.kind !== "UnionType") {
|
|
95
|
-
return Left(new Error(`${nodeShape} rdf:rest property is not sh:or`));
|
|
96
|
-
}
|
|
97
|
-
if (restProperty.type.memberTypes.length !== 2) {
|
|
98
|
-
return Left(new Error(`${nodeShape} rdf:rest property sh:or does not have exactly two member types`));
|
|
99
|
-
}
|
|
100
|
-
// rdf:rest should be sh:or ( [ sh:class nodeShape ] [ sh:hasValue rdf:nil ] )
|
|
101
|
-
if (!restProperty.type.memberTypes.find((type) => type.kind === "ObjectType" &&
|
|
102
|
-
type.name.identifier.equals(nodeShape.resource.identifier))) {
|
|
103
|
-
return Left(new Error(`${nodeShape} rdf:rest property sh:or is not recursive into the node shape`));
|
|
104
|
-
}
|
|
105
|
-
if (!restProperty.type.memberTypes.find((type) => type.kind === "IdentifierType")) {
|
|
106
|
-
return Left(new Error(`${nodeShape} rdf:rest property sh:or does not include sh:hasValue rdf:nil`));
|
|
107
|
-
}
|
|
108
|
-
return Either.of(firstProperty.type);
|
|
109
|
-
}
|
|
110
|
-
nodeShapeAstType(nodeShape) {
|
|
111
|
-
{
|
|
112
|
-
const type = this.nodeShapeAstTypesByIdentifier.get(nodeShape.resource.identifier);
|
|
113
|
-
if (type) {
|
|
114
|
-
return Either.of(type);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
// https://www.w3.org/TR/shacl/#implicit-targetClass
|
|
118
|
-
// If the node shape is an owl:class or rdfs:Class, make the ObjectType have an rdf:type of the NodeShape.
|
|
119
|
-
const rdfType = nodeShape.resource.isInstanceOf(owl.Class) ||
|
|
120
|
-
nodeShape.resource.isInstanceOf(rdfs.Class)
|
|
121
|
-
? Maybe.of(nodeShape.resource.identifier)
|
|
122
|
-
: Maybe.empty();
|
|
123
|
-
const nodeKinds = new Set([...nodeShape.constraints.nodeKinds].filter((nodeKind) => nodeKind !== shaclAst.NodeKind.LITERAL));
|
|
124
|
-
if (nodeKinds.size === 0) {
|
|
125
|
-
return Left(new Error(`${nodeShape} has no non-Literal node kinds`));
|
|
126
|
-
}
|
|
127
|
-
// Put a placeholder in the cache to deal with cyclic references
|
|
128
|
-
// If this node shape's properties (directly or indirectly) refer to the node shape itself,
|
|
129
|
-
// we'll return this placeholder.
|
|
130
|
-
const objectType = {
|
|
131
|
-
abstract: nodeShape.resource
|
|
132
|
-
.value(shaclmate.abstract)
|
|
133
|
-
.chain((value) => value.toBoolean())
|
|
134
|
-
.orDefault(false),
|
|
135
|
-
ancestorObjectTypes: [],
|
|
136
|
-
childObjectTypes: [],
|
|
137
|
-
descendantObjectTypes: [],
|
|
138
|
-
export: nodeShape.resource
|
|
139
|
-
.value(shaclmate.export)
|
|
140
|
-
.chain((value) => value.toBoolean())
|
|
141
|
-
.orDefault(true),
|
|
142
|
-
kind: "ObjectType",
|
|
143
|
-
listItemType: Maybe.empty(),
|
|
144
|
-
mintingStrategy: nodeShape.resource
|
|
145
|
-
.value(shaclmate.mintingStrategy)
|
|
146
|
-
.chain((value) => value.toIri())
|
|
147
|
-
.chain((iri) => {
|
|
148
|
-
if (iri.equals(shaclmate.SHA256)) {
|
|
149
|
-
return Either.of(MintingStrategy.SHA256);
|
|
150
|
-
}
|
|
151
|
-
if (iri.equals(shaclmate.UUIDv4)) {
|
|
152
|
-
return Either.of(MintingStrategy.UUIDv4);
|
|
153
|
-
}
|
|
154
|
-
return Left(new Error(`unrecognizing minting strategy: ${iri.value}`));
|
|
155
|
-
})
|
|
156
|
-
.toMaybe(),
|
|
157
|
-
name: this.shapeName(nodeShape),
|
|
158
|
-
nodeKinds,
|
|
159
|
-
properties: [], // This is mutable, we'll populate it below.
|
|
160
|
-
rdfType,
|
|
161
|
-
parentObjectTypes: [], // This is mutable, we'll populate it below
|
|
162
|
-
};
|
|
163
|
-
this.nodeShapeAstTypesByIdentifier.set(nodeShape.resource.identifier, objectType);
|
|
164
|
-
// Populate ancestor and descendant object types
|
|
165
|
-
// Ancestors
|
|
166
|
-
for (const classIri of ancestorClassIris(nodeShape.resource, Number.MAX_SAFE_INTEGER)) {
|
|
167
|
-
this.resolveClassAstObjectType(classIri).ifRight((ancestorObjectType) => objectType.ancestorObjectTypes.push(ancestorObjectType));
|
|
168
|
-
}
|
|
169
|
-
// Parents
|
|
170
|
-
for (const classIri of ancestorClassIris(nodeShape.resource, 1)) {
|
|
171
|
-
this.resolveClassAstObjectType(classIri).ifRight((parentObjectType) => objectType.parentObjectTypes.push(parentObjectType));
|
|
172
|
-
}
|
|
173
|
-
// Descendants
|
|
174
|
-
for (const classIri of descendantClassIris(nodeShape.resource, Number.MAX_SAFE_INTEGER)) {
|
|
175
|
-
this.resolveClassAstObjectType(classIri).ifRight((descendantObjectType) => objectType.descendantObjectTypes.push(descendantObjectType));
|
|
176
|
-
}
|
|
177
|
-
// Children
|
|
178
|
-
for (const classIri of descendantClassIris(nodeShape.resource, 1)) {
|
|
179
|
-
this.resolveClassAstObjectType(classIri).ifRight((childObjectType) => objectType.childObjectTypes.push(childObjectType));
|
|
180
|
-
}
|
|
181
|
-
// Populate properties
|
|
182
|
-
for (const propertyShape of nodeShape.constraints.properties) {
|
|
183
|
-
const propertyEither = this.propertyShapeAstObjectTypeProperty(propertyShape);
|
|
184
|
-
if (propertyEither.isLeft()) {
|
|
185
|
-
logger.warn("error transforming %s %s: %s", nodeShape, propertyShape, propertyEither.extract().message);
|
|
186
|
-
continue;
|
|
187
|
-
// return property;
|
|
188
|
-
}
|
|
189
|
-
objectType.properties.push(propertyEither.unsafeCoerce());
|
|
190
|
-
}
|
|
191
|
-
// Is the object type an RDF list?
|
|
192
|
-
objectType.listItemType = this.astObjectTypeListItemType(objectType, nodeShape).toMaybe();
|
|
193
|
-
return Either.of(objectType);
|
|
194
|
-
}
|
|
195
|
-
propertyShapeAstObjectTypeProperty(propertyShape) {
|
|
196
|
-
{
|
|
197
|
-
const property = this.astObjectTypePropertiesByIdentifier.get(propertyShape.resource.identifier);
|
|
198
|
-
if (property) {
|
|
199
|
-
return Either.of(property);
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
const type = this.propertyShapeAstType(propertyShape, null);
|
|
203
|
-
if (type.isLeft()) {
|
|
204
|
-
return type;
|
|
205
|
-
}
|
|
206
|
-
const path = propertyShape.path;
|
|
207
|
-
if (path.kind !== "PredicatePath") {
|
|
208
|
-
return Left(new Error(`${propertyShape} has non-predicate path, unsupported`));
|
|
209
|
-
}
|
|
210
|
-
const property = {
|
|
211
|
-
inline: shaclmateInline(propertyShape).orDefault(false),
|
|
212
|
-
name: this.shapeName(propertyShape),
|
|
213
|
-
path,
|
|
214
|
-
type: type.extract(),
|
|
215
|
-
};
|
|
216
|
-
this.astObjectTypePropertiesByIdentifier.set(propertyShape.resource.identifier, property);
|
|
217
|
-
return Either.of(property);
|
|
218
|
-
}
|
|
219
|
-
/**
|
|
220
|
-
* Try to convert a property shape to a type using some heuristics.
|
|
221
|
-
*
|
|
222
|
-
* We don't try to handle exotic cases allowed by the SHACL spec, such as combinations of sh:in and sh:node. Instead we assume
|
|
223
|
-
* a shape has one type.
|
|
224
|
-
*/
|
|
225
|
-
propertyShapeAstType(shape, inherited) {
|
|
226
|
-
const defaultValue = (shape instanceof shaclAst.PropertyShape
|
|
227
|
-
? shape.defaultValue
|
|
228
|
-
: Maybe.empty()).alt(inherited !== null ? inherited.defaultValue : Maybe.empty());
|
|
229
|
-
const hasValue = shape.constraints.hasValue;
|
|
230
|
-
const inline = shaclmateInline(shape).alt(inherited !== null ? inherited.inline : Maybe.empty());
|
|
231
|
-
return (() => {
|
|
232
|
-
// Conjunctions/disjunctions of multiple types
|
|
233
|
-
if (shape.constraints.and.length > 0 ||
|
|
234
|
-
shape.constraints.classes.length > 0 ||
|
|
235
|
-
shape.constraints.nodes.length > 0 ||
|
|
236
|
-
shape.constraints.or.length > 0) {
|
|
237
|
-
let memberTypeEithers;
|
|
238
|
-
let compositeTypeKind;
|
|
239
|
-
if (shape.constraints.and.length > 0) {
|
|
240
|
-
memberTypeEithers = shape.constraints.and.map((memberShape) => this.propertyShapeAstType(memberShape, {
|
|
241
|
-
defaultValue,
|
|
242
|
-
inline,
|
|
243
|
-
}));
|
|
244
|
-
compositeTypeKind = "IntersectionType";
|
|
245
|
-
}
|
|
246
|
-
else if (shape.constraints.classes.length > 0) {
|
|
247
|
-
memberTypeEithers = shape.constraints.classes.map((classIri) => this.resolveClassAstObjectType(classIri).map((classObjectType) => inline.orDefault(false)
|
|
248
|
-
? classObjectType
|
|
249
|
-
: {
|
|
250
|
-
defaultValue: defaultValue.filter((term) => term.termType !== "Literal"),
|
|
251
|
-
hasValue: Maybe.empty(),
|
|
252
|
-
kind: "IdentifierType",
|
|
253
|
-
nodeKinds: classObjectType.nodeKinds,
|
|
254
|
-
}));
|
|
255
|
-
compositeTypeKind = "IntersectionType";
|
|
256
|
-
}
|
|
257
|
-
else if (shape.constraints.nodes.length > 0) {
|
|
258
|
-
memberTypeEithers = shape.constraints.nodes.map((nodeShape) => this.nodeShapeAstType(nodeShape));
|
|
259
|
-
compositeTypeKind = "IntersectionType";
|
|
260
|
-
}
|
|
261
|
-
else {
|
|
262
|
-
memberTypeEithers = shape.constraints.or.map((memberShape) => this.propertyShapeAstType(memberShape, {
|
|
263
|
-
defaultValue,
|
|
264
|
-
inline,
|
|
265
|
-
}));
|
|
266
|
-
compositeTypeKind = "UnionType";
|
|
267
|
-
}
|
|
268
|
-
invariant(memberTypeEithers.length > 0);
|
|
269
|
-
const memberTypes = Either.rights(memberTypeEithers);
|
|
270
|
-
if (memberTypes.length !== memberTypeEithers.length) {
|
|
271
|
-
logger.warn("shape %s composition did not map all member types successfully", shape);
|
|
272
|
-
return memberTypeEithers[0];
|
|
273
|
-
}
|
|
274
|
-
invariant(memberTypes.length > 0);
|
|
275
|
-
if (memberTypes.length === 1) {
|
|
276
|
-
return Either.of(memberTypes[0]);
|
|
277
|
-
}
|
|
278
|
-
// Get the type underlying a set or option
|
|
279
|
-
const memberItemTypes = memberTypes.map((memberType) => {
|
|
280
|
-
switch (memberType.kind) {
|
|
281
|
-
case "SetType":
|
|
282
|
-
return memberType.itemType;
|
|
283
|
-
case "OptionType":
|
|
284
|
-
return memberType.itemType;
|
|
285
|
-
default:
|
|
286
|
-
return memberType;
|
|
287
|
-
}
|
|
288
|
-
});
|
|
289
|
-
if (hasValue.isNothing() &&
|
|
290
|
-
memberItemTypes.every((memberItemType) => memberItemType.kind === "LiteralType" &&
|
|
291
|
-
memberItemType.maxExclusive.isNothing() &&
|
|
292
|
-
memberItemType.maxInclusive.isNothing() &&
|
|
293
|
-
memberItemType.minExclusive.isNothing() &&
|
|
294
|
-
memberItemType.minInclusive.isNothing())) {
|
|
295
|
-
// Special case: all the member types are Literals without further constraints,
|
|
296
|
-
// like dash:StringOrLangString
|
|
297
|
-
return Either.of({
|
|
298
|
-
datatype: Maybe.empty(),
|
|
299
|
-
defaultValue: defaultValue.filter((term) => term.termType === "Literal"),
|
|
300
|
-
hasValue: Maybe.empty(),
|
|
301
|
-
kind: "LiteralType",
|
|
302
|
-
maxExclusive: Maybe.empty(),
|
|
303
|
-
maxInclusive: Maybe.empty(),
|
|
304
|
-
minExclusive: Maybe.empty(),
|
|
305
|
-
minInclusive: Maybe.empty(),
|
|
306
|
-
});
|
|
307
|
-
}
|
|
308
|
-
if (hasValue.isNothing() &&
|
|
309
|
-
memberItemTypes.every((memberItemType) => memberItemType.kind === "IdentifierType")) {
|
|
310
|
-
// Special case: all member types are blank or named nodes without further constraints
|
|
311
|
-
return Either.of({
|
|
312
|
-
defaultValue: defaultValue.filter((term) => term.termType !== "Literal"),
|
|
313
|
-
hasValue: Maybe.empty(),
|
|
314
|
-
kind: "IdentifierType",
|
|
315
|
-
nodeKinds: new Set(memberItemTypes
|
|
316
|
-
.filter((memberItemType) => memberItemType.kind === "IdentifierType")
|
|
317
|
-
.flatMap((memberItemType) => [...memberItemType.nodeKinds])),
|
|
318
|
-
});
|
|
319
|
-
}
|
|
320
|
-
return Either.of({
|
|
321
|
-
kind: compositeTypeKind,
|
|
322
|
-
memberTypes: memberTypes,
|
|
323
|
-
});
|
|
324
|
-
}
|
|
325
|
-
if (
|
|
326
|
-
// Treat any shape with the constraints in the list as a literal type
|
|
327
|
-
[
|
|
328
|
-
shape.constraints.datatype,
|
|
329
|
-
shape.constraints.maxExclusive,
|
|
330
|
-
shape.constraints.maxInclusive,
|
|
331
|
-
shape.constraints.minExclusive,
|
|
332
|
-
shape.constraints.minInclusive,
|
|
333
|
-
].some((constraint) => constraint.isJust()) ||
|
|
334
|
-
// Treat any shape with a literal value as a literal type
|
|
335
|
-
hasValue.extractNullable()?.termType === "Literal" ||
|
|
336
|
-
// Treat any shape with a single sh:nodeKind of sh:Literal as a literal type
|
|
337
|
-
(shape.constraints.nodeKinds.size === 1 &&
|
|
338
|
-
shape.constraints.nodeKinds.has(shaclAst.NodeKind.LITERAL))) {
|
|
339
|
-
return Either.of({
|
|
340
|
-
datatype: shape.constraints.datatype,
|
|
341
|
-
defaultValue: defaultValue.filter((term) => term.termType === "Literal"),
|
|
342
|
-
hasValue: hasValue.filter((term) => term.termType === "Literal"),
|
|
343
|
-
kind: "LiteralType",
|
|
344
|
-
maxExclusive: shape.constraints.maxExclusive,
|
|
345
|
-
maxInclusive: shape.constraints.maxInclusive,
|
|
346
|
-
minExclusive: shape.constraints.minExclusive,
|
|
347
|
-
minInclusive: shape.constraints.minInclusive,
|
|
348
|
-
});
|
|
349
|
-
}
|
|
350
|
-
// Treat any shape with sh:nodeKind blank node or IRI as an identifier type
|
|
351
|
-
const identifierDefaultValue = defaultValue.filter((value) => value.termType !== "Literal");
|
|
352
|
-
const hasIdentifierValue = hasValue.filter((value) => value.termType !== "Literal");
|
|
353
|
-
if (hasIdentifierValue.isJust() ||
|
|
354
|
-
identifierDefaultValue.isJust() ||
|
|
355
|
-
(shape.constraints.nodeKinds.size > 0 &&
|
|
356
|
-
shape.constraints.nodeKinds.size <= 2 &&
|
|
357
|
-
!shape.constraints.nodeKinds.has(shaclAst.NodeKind.LITERAL))) {
|
|
358
|
-
const nodeKinds = hasIdentifierValue
|
|
359
|
-
.map((value) => {
|
|
360
|
-
const nodeKinds = new Set();
|
|
361
|
-
switch (value.termType) {
|
|
362
|
-
case "BlankNode":
|
|
363
|
-
nodeKinds.add(shaclAst.NodeKind.BLANK_NODE);
|
|
364
|
-
break;
|
|
365
|
-
case "NamedNode":
|
|
366
|
-
nodeKinds.add(shaclAst.NodeKind.IRI);
|
|
367
|
-
break;
|
|
368
|
-
}
|
|
369
|
-
return nodeKinds;
|
|
370
|
-
})
|
|
371
|
-
.orDefaultLazy(() => shape.constraints.nodeKinds);
|
|
372
|
-
invariant(nodeKinds.size > 0);
|
|
373
|
-
return Either.of({
|
|
374
|
-
defaultValue: identifierDefaultValue,
|
|
375
|
-
hasValue: hasIdentifierValue,
|
|
376
|
-
kind: "IdentifierType",
|
|
377
|
-
nodeKinds,
|
|
378
|
-
});
|
|
379
|
-
}
|
|
380
|
-
return Left(new Error(`unable to transform type on ${shape}`));
|
|
381
|
-
})().map((itemType) => {
|
|
382
|
-
// Handle cardinality constraints
|
|
383
|
-
if (defaultValue.isJust()) {
|
|
384
|
-
// Ignore other cardinality constraints if there's a default value and treat the type as minCount=maxCount=1
|
|
385
|
-
return itemType;
|
|
386
|
-
}
|
|
387
|
-
const maxCount = shape.constraints.maxCount;
|
|
388
|
-
const minCount = shape.constraints.minCount;
|
|
389
|
-
if (maxCount.isNothing() && minCount.isNothing()) {
|
|
390
|
-
// The shape has no cardinality constraints
|
|
391
|
-
if (inherited === null) {
|
|
392
|
-
// The shape is top-level (not an sh:or/sh:and of a top-level shape)
|
|
393
|
-
// Treat it as a Set, the default in RDF.
|
|
394
|
-
// We want Set to be the outermost type unless it's explicitly requested with sh:minCount 0.
|
|
395
|
-
return {
|
|
396
|
-
itemType,
|
|
397
|
-
kind: "SetType",
|
|
398
|
-
minCount: 0,
|
|
399
|
-
};
|
|
400
|
-
}
|
|
401
|
-
// else the shape is not top-level
|
|
402
|
-
// We want Set to be the outermost type, so just return the itemType here
|
|
403
|
-
return itemType;
|
|
404
|
-
}
|
|
405
|
-
if (minCount.orDefault(0) === 0 && maxCount.extractNullable() === 1) {
|
|
406
|
-
return {
|
|
407
|
-
itemType,
|
|
408
|
-
kind: "OptionType",
|
|
409
|
-
};
|
|
410
|
-
}
|
|
411
|
-
if (minCount.orDefault(0) === 1 && maxCount.extractNullable() === 1) {
|
|
412
|
-
return itemType;
|
|
413
|
-
}
|
|
414
|
-
invariant(minCount.isJust() || maxCount.isJust());
|
|
415
|
-
// There are cardinality constraints for a Set. It may be an inner type.
|
|
416
|
-
return {
|
|
417
|
-
itemType,
|
|
418
|
-
kind: "SetType",
|
|
419
|
-
minCount: minCount.orDefault(0),
|
|
420
|
-
};
|
|
421
|
-
});
|
|
422
|
-
}
|
|
423
|
-
resolveClassAstObjectType(classIri) {
|
|
424
|
-
let nodeShape;
|
|
425
|
-
if (classIri.equals(owl.Class) ||
|
|
426
|
-
classIri.equals(owl.Thing) ||
|
|
427
|
-
classIri.equals(rdfs.Class)) {
|
|
428
|
-
nodeShape = Maybe.empty();
|
|
429
|
-
}
|
|
430
|
-
else {
|
|
431
|
-
nodeShape = this.shapesGraph.nodeShapeByNode(classIri);
|
|
432
|
-
}
|
|
433
|
-
return nodeShape
|
|
434
|
-
.toEither(new Error(`${classIri.value} does not correspond to a node shape`))
|
|
435
|
-
.chain((nodeShape) => this.nodeShapeAstType(nodeShape))
|
|
436
|
-
.ifLeft((error) => {
|
|
437
|
-
logger.debug("class %s did not resolve to an object type: %s", classIri.value, error.message);
|
|
438
|
-
});
|
|
439
|
-
}
|
|
440
|
-
shapeName(shape) {
|
|
441
|
-
let propertyPath = Maybe.empty();
|
|
442
|
-
if (shape instanceof shaclAst.PropertyShape &&
|
|
443
|
-
shape.path.kind === "PredicatePath") {
|
|
444
|
-
const pathIri = shape.path.iri;
|
|
445
|
-
propertyPath = Maybe.of({
|
|
446
|
-
curie: Maybe.fromNullable(this.iriPrefixMap.shrink(pathIri)?.value),
|
|
447
|
-
identifier: pathIri,
|
|
448
|
-
});
|
|
449
|
-
}
|
|
450
|
-
return {
|
|
451
|
-
curie: shape.resource.identifier.termType === "NamedNode"
|
|
452
|
-
? Maybe.fromNullable(this.iriPrefixMap.shrink(shape.resource.identifier)?.value)
|
|
453
|
-
: Maybe.empty(),
|
|
454
|
-
identifier: shape.resource.identifier,
|
|
455
|
-
propertyPath,
|
|
456
|
-
shName: shape.name.map((name) => name.value),
|
|
457
|
-
shaclmateName: shaclmateName(shape),
|
|
458
|
-
};
|
|
459
|
-
}
|
|
460
34
|
}
|
|
461
35
|
//# sourceMappingURL=ShapesGraphToAstTransformer.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from "./NodeShapeAstType.js";
|
|
2
|
+
export * from "./shapeAstName.js";
|
|
3
|
+
export * from "./transformNodeShapeToAstType.js";
|
|
4
|
+
export * from "./transformPropertyShapeToAstObjectTypeProperty.js";
|
|
5
|
+
export * from "./transformPropertyShapeToAstCompositeType.js";
|
|
6
|
+
export * from "./transformPropertyShapeToAstIdentifierType.js";
|
|
7
|
+
export * from "./transformPropertyShapeToAstLiteralType.js";
|
|
8
|
+
export * from "./transformPropertyShapeToAstType.js";
|
|
9
|
+
export * from "./transformPropertyShapeToAstTermType.js";
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from "./NodeShapeAstType.js";
|
|
2
|
+
export * from "./shapeAstName.js";
|
|
3
|
+
export * from "./transformNodeShapeToAstType.js";
|
|
4
|
+
export * from "./transformPropertyShapeToAstObjectTypeProperty.js";
|
|
5
|
+
export * from "./transformPropertyShapeToAstCompositeType.js";
|
|
6
|
+
export * from "./transformPropertyShapeToAstIdentifierType.js";
|
|
7
|
+
export * from "./transformPropertyShapeToAstLiteralType.js";
|
|
8
|
+
export * from "./transformPropertyShapeToAstType.js";
|
|
9
|
+
export * from "./transformPropertyShapeToAstTermType.js";
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Maybe } from "purify-ts";
|
|
2
|
+
export function pickLiteral(literals) {
|
|
3
|
+
if (literals.length === 0) {
|
|
4
|
+
return Maybe.empty();
|
|
5
|
+
}
|
|
6
|
+
for (const literal of literals) {
|
|
7
|
+
if (literal.language === "en") {
|
|
8
|
+
return Maybe.of(literal);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
for (const literal of literals) {
|
|
12
|
+
if (literal.language.length === 0) {
|
|
13
|
+
return Maybe.of(literal);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return Maybe.of(literals[0]);
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=pickLiteral.js.map
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import * as input from "../input/index.js";
|
|
2
|
+
export function propertyShapeNodeKinds(shape) {
|
|
3
|
+
const nodeKinds = new Set([
|
|
4
|
+
...shape.constraints.nodeKinds.orDefault(new Set()),
|
|
5
|
+
]);
|
|
6
|
+
if (nodeKinds.size > 0) {
|
|
7
|
+
return nodeKinds;
|
|
8
|
+
}
|
|
9
|
+
if (shape instanceof input.PropertyShape) {
|
|
10
|
+
shape.defaultValue.ifJust((defaultValue) => nodeKinds.add(defaultValue.termType));
|
|
11
|
+
if (nodeKinds.size > 0) {
|
|
12
|
+
return nodeKinds;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
for (const hasValue of shape.constraints.hasValues) {
|
|
16
|
+
nodeKinds.add(hasValue.termType);
|
|
17
|
+
}
|
|
18
|
+
if (nodeKinds.size > 0) {
|
|
19
|
+
return nodeKinds;
|
|
20
|
+
}
|
|
21
|
+
for (const term of shape.constraints.in_) {
|
|
22
|
+
nodeKinds.add(term.termType);
|
|
23
|
+
}
|
|
24
|
+
return nodeKinds;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=propertyShapeNodeKinds.js.map
|