@shaclmate/compiler 2.0.13 → 2.0.15
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 +178 -0
- package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstCompositeType.d.ts +13 -0
- package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstCompositeType.js +200 -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 +19 -0
- package/generators/ts/DateTimeType.js +66 -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 +17 -0
- package/generators/ts/Import.js +54 -0
- package/generators/ts/ListType.d.ts +19 -8
- package/generators/ts/ListType.js +206 -44
- 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 +48 -25
- package/generators/ts/ObjectType.js +234 -50
- package/generators/ts/ObjectUnionType.d.ts +58 -0
- package/generators/ts/ObjectUnionType.js +450 -0
- package/generators/ts/OptionType.d.ts +14 -4
- package/generators/ts/OptionType.js +70 -20
- package/generators/ts/PrimitiveType.d.ts +15 -5
- package/generators/ts/PrimitiveType.js +27 -31
- package/generators/ts/SetType.d.ts +14 -4
- package/generators/ts/SetType.js +108 -30
- package/generators/ts/SnippetDeclarations.d.ts +11 -0
- package/generators/ts/SnippetDeclarations.js +215 -0
- package/generators/ts/StringType.d.ts +8 -3
- package/generators/ts/StringType.js +57 -3
- package/generators/ts/TermType.d.ts +54 -0
- package/generators/ts/TermType.js +242 -0
- package/generators/ts/TsGenerator.d.ts +4 -12
- package/generators/ts/TsGenerator.js +57 -99
- package/generators/ts/Type.d.ts +117 -46
- package/generators/ts/Type.js +93 -59
- package/generators/ts/TypeFactory.d.ts +4 -5
- package/generators/ts/TypeFactory.js +224 -91
- package/generators/ts/UnionType.d.ts +20 -6
- package/generators/ts/UnionType.js +230 -120
- package/generators/ts/_ObjectType/IdentifierProperty.d.ts +27 -8
- package/generators/ts/_ObjectType/IdentifierProperty.js +153 -32
- package/generators/ts/_ObjectType/Property.d.ts +139 -9
- package/generators/ts/_ObjectType/Property.js +26 -3
- package/generators/ts/_ObjectType/ShaclProperty.d.ts +24 -5
- package/generators/ts/_ObjectType/ShaclProperty.js +103 -26
- package/generators/ts/_ObjectType/TypeDiscriminatorProperty.d.ts +23 -7
- package/generators/ts/_ObjectType/TypeDiscriminatorProperty.js +83 -14
- 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/sparqlConstructQueryFunctionDeclaration.d.ts +5 -0
- package/generators/ts/_ObjectType/sparqlConstructQueryFunctionDeclaration.js +21 -0
- package/generators/ts/_ObjectType/sparqlConstructQueryStringFunctionDeclaration.d.ts +5 -0
- package/generators/ts/_ObjectType/sparqlConstructQueryStringFunctionDeclaration.js +20 -0
- package/generators/ts/_ObjectType/sparqlFunctionDeclarations.d.ts +4 -0
- package/generators/ts/_ObjectType/sparqlFunctionDeclarations.js +78 -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 +275 -0
- package/input/generated.js +1436 -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 +46 -0
- package/package.json +15 -9
- 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
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ShapesGraphToAstTransformer } from "../ShapesGraphToAstTransformer.js";
|
|
2
|
+
import type * as ast from "../ast/index.js";
|
|
3
|
+
import * as input from "../input/index.js";
|
|
4
|
+
export declare function shapeAstName(this: ShapesGraphToAstTransformer, shape: input.Shape): ast.Name;
|
|
5
|
+
//# sourceMappingURL=shapeAstName.d.ts.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Maybe } from "purify-ts";
|
|
2
|
+
import * as input from "../input/index.js";
|
|
3
|
+
import { pickLiteral } from "./pickLiteral.js";
|
|
4
|
+
export function shapeAstName(shape) {
|
|
5
|
+
let propertyPath = Maybe.empty();
|
|
6
|
+
let shName = Maybe.empty();
|
|
7
|
+
if (shape instanceof input.PropertyShape) {
|
|
8
|
+
if (shape.path.kind === "PredicatePath") {
|
|
9
|
+
const pathIri = shape.path.iri;
|
|
10
|
+
propertyPath = Maybe.of({
|
|
11
|
+
curie: Maybe.fromNullable(this.iriPrefixMap.shrink(pathIri)?.value),
|
|
12
|
+
identifier: pathIri,
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
shName = pickLiteral(shape.names).map((literal) => literal.value);
|
|
16
|
+
}
|
|
17
|
+
return {
|
|
18
|
+
curie: shape.identifier.termType === "NamedNode"
|
|
19
|
+
? Maybe.fromNullable(this.iriPrefixMap.shrink(shape.identifier)?.value)
|
|
20
|
+
: Maybe.empty(),
|
|
21
|
+
identifier: shape.identifier,
|
|
22
|
+
label: pickLiteral(shape.labels).map((literal) => literal.value),
|
|
23
|
+
propertyPath,
|
|
24
|
+
shName: shName,
|
|
25
|
+
shaclmateName: shape.shaclmateName,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=shapeAstName.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Either } from "purify-ts";
|
|
2
|
+
import type { ShapesGraphToAstTransformer } from "../ShapesGraphToAstTransformer.js";
|
|
3
|
+
import * as input from "../input/index.js";
|
|
4
|
+
import type { NodeShapeAstType } from "./NodeShapeAstType.js";
|
|
5
|
+
export declare function transformNodeShapeToAstType(this: ShapesGraphToAstTransformer, nodeShape: input.NodeShape): Either<Error, NodeShapeAstType>;
|
|
6
|
+
//# sourceMappingURL=transformNodeShapeToAstType.d.ts.map
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { rdf } from "@tpluscode/rdf-ns-builders";
|
|
2
|
+
import { Either, Left } from "purify-ts";
|
|
3
|
+
import { invariant } from "ts-invariant";
|
|
4
|
+
import { TsFeature } from "../enums/index.js";
|
|
5
|
+
import * as input from "../input/index.js";
|
|
6
|
+
import { logger } from "../logger.js";
|
|
7
|
+
import { pickLiteral } from "./pickLiteral.js";
|
|
8
|
+
/**
|
|
9
|
+
* Is an ast.ObjectType actually the shape of an RDF list?
|
|
10
|
+
* If so, return the type of its rdf:first.
|
|
11
|
+
*/
|
|
12
|
+
function transformNodeShapeToListType(nodeShape) {
|
|
13
|
+
invariant(nodeShape.isList);
|
|
14
|
+
// Put a placeholder in the cache to deal with cyclic references
|
|
15
|
+
const listType = {
|
|
16
|
+
comment: pickLiteral(nodeShape.comments).map((literal) => literal.value),
|
|
17
|
+
identifierNodeKind: nodeShape.nodeKinds.has("BlankNode")
|
|
18
|
+
? "BlankNode"
|
|
19
|
+
: "NamedNode",
|
|
20
|
+
itemType: {
|
|
21
|
+
kind: "PlaceholderType",
|
|
22
|
+
},
|
|
23
|
+
kind: "ListType",
|
|
24
|
+
label: pickLiteral(nodeShape.labels).map((literal) => literal.value),
|
|
25
|
+
mutable: nodeShape.mutable,
|
|
26
|
+
name: this.shapeAstName(nodeShape),
|
|
27
|
+
mintingStrategy: nodeShape.mintingStrategy,
|
|
28
|
+
toRdfTypes: nodeShape.toRdfTypes,
|
|
29
|
+
};
|
|
30
|
+
this.nodeShapeAstTypesByIdentifier.set(nodeShape.identifier, listType);
|
|
31
|
+
const properties = [];
|
|
32
|
+
for (const propertyShape of nodeShape.constraints.properties) {
|
|
33
|
+
const propertyEither = this.transformPropertyShapeToAstObjectTypeProperty(propertyShape);
|
|
34
|
+
if (propertyEither.isLeft()) {
|
|
35
|
+
logger.warn("error transforming %s %s: %s", nodeShape, propertyShape, propertyEither.extract().message);
|
|
36
|
+
continue;
|
|
37
|
+
// return property;
|
|
38
|
+
}
|
|
39
|
+
properties.push(propertyEither.unsafeCoerce());
|
|
40
|
+
}
|
|
41
|
+
if (properties.length !== 2) {
|
|
42
|
+
return Left(new Error(`${nodeShape} does not have exactly two properties`));
|
|
43
|
+
}
|
|
44
|
+
// rdf:first can have any type
|
|
45
|
+
// The type of the rdf:first property is the list item type.
|
|
46
|
+
const firstProperty = properties.find((property) => property.path.iri.equals(rdf.first));
|
|
47
|
+
if (!firstProperty) {
|
|
48
|
+
return Left(new Error(`${nodeShape} does not have an rdf:first property`));
|
|
49
|
+
}
|
|
50
|
+
const restProperty = properties.find((property) => property.path.iri.equals(rdf.rest));
|
|
51
|
+
if (!restProperty) {
|
|
52
|
+
return Left(new Error(`${nodeShape} does not have an rdf:rest property`));
|
|
53
|
+
}
|
|
54
|
+
if (restProperty.type.kind !== "UnionType") {
|
|
55
|
+
return Left(new Error(`${nodeShape} rdf:rest property is not sh:xone`));
|
|
56
|
+
}
|
|
57
|
+
if (restProperty.type.memberTypes.length !== 2) {
|
|
58
|
+
return Left(new Error(`${nodeShape} rdf:rest property sh:xone does not have exactly two member types`));
|
|
59
|
+
}
|
|
60
|
+
// rdf:rest should be sh:xone ( [ sh:class nodeShape ] [ sh:hasValue rdf:nil ] )
|
|
61
|
+
if (!restProperty.type.memberTypes.find((type) => type.kind === "ListType" &&
|
|
62
|
+
type.name.identifier.equals(nodeShape.identifier))) {
|
|
63
|
+
return Left(new Error(`${nodeShape} rdf:rest property sh:xone is not recursive into the node shape`));
|
|
64
|
+
}
|
|
65
|
+
if (!restProperty.type.memberTypes.find((type) => type.kind === "IdentifierType")) {
|
|
66
|
+
return Left(new Error(`${nodeShape} rdf:rest property sh:xone does not include sh:hasValue rdf:nil`));
|
|
67
|
+
}
|
|
68
|
+
listType.itemType = firstProperty.type;
|
|
69
|
+
return Either.of(listType);
|
|
70
|
+
}
|
|
71
|
+
export function transformNodeShapeToAstType(nodeShape) {
|
|
72
|
+
{
|
|
73
|
+
const type = this.nodeShapeAstTypesByIdentifier.get(nodeShape.identifier);
|
|
74
|
+
if (type) {
|
|
75
|
+
return Either.of(type);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
if (nodeShape.isList) {
|
|
79
|
+
return transformNodeShapeToListType.bind(this)(nodeShape);
|
|
80
|
+
}
|
|
81
|
+
const export_ = nodeShape.export.orDefault(true);
|
|
82
|
+
if (nodeShape.constraints.and.length > 0 ||
|
|
83
|
+
nodeShape.constraints.xone.length > 0) {
|
|
84
|
+
let compositeTypeShapes;
|
|
85
|
+
let compositeTypeKind;
|
|
86
|
+
if (nodeShape.constraints.and.length > 0) {
|
|
87
|
+
compositeTypeShapes = nodeShape.constraints.and;
|
|
88
|
+
compositeTypeKind = "ObjectIntersectionType";
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
compositeTypeShapes = nodeShape.constraints.xone;
|
|
92
|
+
compositeTypeKind = "ObjectUnionType";
|
|
93
|
+
}
|
|
94
|
+
const compositeTypeNodeShapes = compositeTypeShapes.filter((shape) => shape instanceof input.NodeShape);
|
|
95
|
+
if (compositeTypeNodeShapes.length === 0) {
|
|
96
|
+
return Left(new Error(`${nodeShape} has no node shapes in its logical constraint`));
|
|
97
|
+
}
|
|
98
|
+
// Put a placeholder in the cache to deal with cyclic references
|
|
99
|
+
const compositeType = {
|
|
100
|
+
comment: pickLiteral(nodeShape.comments).map((literal) => literal.value),
|
|
101
|
+
export: export_,
|
|
102
|
+
kind: compositeTypeKind,
|
|
103
|
+
label: pickLiteral(nodeShape.labels).map((literal) => literal.value),
|
|
104
|
+
memberTypes: [],
|
|
105
|
+
name: this.shapeAstName(nodeShape),
|
|
106
|
+
tsFeatures: nodeShape.tsFeatures.orDefault(new Set(TsFeature.MEMBERS)),
|
|
107
|
+
};
|
|
108
|
+
this.nodeShapeAstTypesByIdentifier.set(nodeShape.identifier, compositeType);
|
|
109
|
+
for (const memberNodeShape of compositeTypeNodeShapes) {
|
|
110
|
+
const memberAstTypeEither = this.transformNodeShapeToAstType(memberNodeShape);
|
|
111
|
+
if (memberAstTypeEither.isLeft()) {
|
|
112
|
+
return memberAstTypeEither;
|
|
113
|
+
}
|
|
114
|
+
const memberAstType = memberAstTypeEither.unsafeCoerce();
|
|
115
|
+
switch (memberAstType.kind) {
|
|
116
|
+
case "ObjectType":
|
|
117
|
+
compositeType.memberTypes.push(memberAstType);
|
|
118
|
+
break;
|
|
119
|
+
case "ObjectUnionType":
|
|
120
|
+
compositeType.memberTypes.push(...memberAstType.memberTypes);
|
|
121
|
+
break;
|
|
122
|
+
default:
|
|
123
|
+
return Left(new Error(`${nodeShape} has one or more non-ObjectType node shapes in its logical constraint`));
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return Either.of(compositeType);
|
|
127
|
+
}
|
|
128
|
+
// Put a placeholder in the cache to deal with cyclic references
|
|
129
|
+
// If this node shape's properties (directly or indirectly) refer to the node shape itself,
|
|
130
|
+
// we'll return this placeholder.
|
|
131
|
+
const objectType = {
|
|
132
|
+
abstract: nodeShape.abstract.orDefault(false),
|
|
133
|
+
ancestorObjectTypes: [],
|
|
134
|
+
childObjectTypes: [],
|
|
135
|
+
comment: pickLiteral(nodeShape.comments).map((literal) => literal.value),
|
|
136
|
+
descendantObjectTypes: [],
|
|
137
|
+
export: export_,
|
|
138
|
+
extern: nodeShape.extern.orDefault(false),
|
|
139
|
+
fromRdfType: nodeShape.fromRdfType,
|
|
140
|
+
label: pickLiteral(nodeShape.labels).map((literal) => literal.value),
|
|
141
|
+
kind: "ObjectType",
|
|
142
|
+
mintingStrategy: nodeShape.mintingStrategy,
|
|
143
|
+
name: this.shapeAstName(nodeShape),
|
|
144
|
+
nodeKinds: nodeShape.nodeKinds,
|
|
145
|
+
properties: [], // This is mutable, we'll populate it below.
|
|
146
|
+
parentObjectTypes: [], // This is mutable, we'll populate it below
|
|
147
|
+
toRdfTypes: nodeShape.toRdfTypes,
|
|
148
|
+
tsFeatures: nodeShape.tsFeatures.orDefault(new Set(TsFeature.MEMBERS)),
|
|
149
|
+
tsIdentifierPropertyName: nodeShape.tsObjectIdentifierPropertyName.orDefault("identifier"),
|
|
150
|
+
tsImports: nodeShape.tsImports,
|
|
151
|
+
tsObjectDeclarationType: nodeShape.tsObjectDeclarationType.orDefault("class"),
|
|
152
|
+
tsTypeDiscriminatorPropertyName: nodeShape.tsObjectTypeDiscriminatorPropertyName.orDefault("type"),
|
|
153
|
+
};
|
|
154
|
+
this.nodeShapeAstTypesByIdentifier.set(nodeShape.identifier, objectType);
|
|
155
|
+
// Populate ancestor and descendant object types
|
|
156
|
+
const relatedObjectTypes = (relatedNodeShapes) => {
|
|
157
|
+
return relatedNodeShapes.flatMap((relatedNodeShape) => this.transformNodeShapeToAstType(relatedNodeShape)
|
|
158
|
+
.toMaybe()
|
|
159
|
+
.filter((astType) => astType.kind === "ObjectType")
|
|
160
|
+
.toList());
|
|
161
|
+
};
|
|
162
|
+
objectType.ancestorObjectTypes.push(...relatedObjectTypes(nodeShape.ancestorNodeShapes));
|
|
163
|
+
objectType.childObjectTypes.push(...relatedObjectTypes(nodeShape.childNodeShapes));
|
|
164
|
+
objectType.descendantObjectTypes.push(...relatedObjectTypes(nodeShape.descendantNodeShapes));
|
|
165
|
+
objectType.parentObjectTypes.push(...relatedObjectTypes(nodeShape.parentNodeShapes));
|
|
166
|
+
// Populate properties
|
|
167
|
+
for (const propertyShape of nodeShape.constraints.properties) {
|
|
168
|
+
const propertyEither = this.transformPropertyShapeToAstObjectTypeProperty(propertyShape);
|
|
169
|
+
if (propertyEither.isLeft()) {
|
|
170
|
+
logger.warn("error transforming %s %s: %s", nodeShape, propertyShape, propertyEither.extract().message);
|
|
171
|
+
continue;
|
|
172
|
+
// return property;
|
|
173
|
+
}
|
|
174
|
+
objectType.properties.push(propertyEither.unsafeCoerce());
|
|
175
|
+
}
|
|
176
|
+
return Either.of(objectType);
|
|
177
|
+
}
|
|
178
|
+
//# sourceMappingURL=transformNodeShapeToAstType.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { BlankNode, Literal, NamedNode } from "@rdfjs/types";
|
|
2
|
+
import { Either, Maybe } from "purify-ts";
|
|
3
|
+
import type { ShapesGraphToAstTransformer } from "../ShapesGraphToAstTransformer.js";
|
|
4
|
+
import type * as ast from "../ast/index.js";
|
|
5
|
+
import * as input from "../input/index.js";
|
|
6
|
+
/**
|
|
7
|
+
* Try to convert a property shape to a composite type (intersection or union) using some heuristics.
|
|
8
|
+
*/
|
|
9
|
+
export declare function transformPropertyShapeToAstCompositeType(this: ShapesGraphToAstTransformer, shape: input.Shape, inherited: {
|
|
10
|
+
defaultValue: Maybe<BlankNode | Literal | NamedNode>;
|
|
11
|
+
extern: Maybe<boolean>;
|
|
12
|
+
} | null): Either<Error, ast.Type>;
|
|
13
|
+
//# sourceMappingURL=transformPropertyShapeToAstCompositeType.d.ts.map
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { owl, rdfs } from "@tpluscode/rdf-ns-builders";
|
|
2
|
+
import { Either, Left, Maybe } from "purify-ts";
|
|
3
|
+
import { invariant } from "ts-invariant";
|
|
4
|
+
import * as input from "../input/index.js";
|
|
5
|
+
import { logger } from "../logger.js";
|
|
6
|
+
/**
|
|
7
|
+
* Try to convert a property shape to a composite type (intersection or union) using some heuristics.
|
|
8
|
+
*/
|
|
9
|
+
export function transformPropertyShapeToAstCompositeType(shape, inherited) {
|
|
10
|
+
const defaultValue = (shape instanceof input.PropertyShape ? shape.defaultValue : Maybe.empty()).alt(inherited !== null ? inherited.defaultValue : Maybe.empty());
|
|
11
|
+
const hasValues = shape.constraints.hasValues;
|
|
12
|
+
const extern = shape.extern.alt(inherited !== null ? inherited.extern : Maybe.empty());
|
|
13
|
+
let memberTypeEithers;
|
|
14
|
+
let compositeTypeKind;
|
|
15
|
+
const transformNodeShapeToAstCompositeMemberType = (nodeShape) => {
|
|
16
|
+
const astTypeEither = this.transformNodeShapeToAstType(nodeShape);
|
|
17
|
+
if (astTypeEither.isLeft()) {
|
|
18
|
+
return astTypeEither;
|
|
19
|
+
}
|
|
20
|
+
const astType = astTypeEither.unsafeCoerce();
|
|
21
|
+
if (extern.orDefault(false)) {
|
|
22
|
+
// Use the identifier type instead
|
|
23
|
+
let nodeKinds;
|
|
24
|
+
switch (astType.kind) {
|
|
25
|
+
case "ListType":
|
|
26
|
+
nodeKinds = new Set();
|
|
27
|
+
nodeKinds.add(astType.identifierNodeKind);
|
|
28
|
+
break;
|
|
29
|
+
case "ObjectType":
|
|
30
|
+
nodeKinds = astType.nodeKinds;
|
|
31
|
+
break;
|
|
32
|
+
case "ObjectIntersectionType":
|
|
33
|
+
case "ObjectUnionType":
|
|
34
|
+
nodeKinds = new Set();
|
|
35
|
+
for (const memberType of astType.memberTypes) {
|
|
36
|
+
for (const nodeKind of memberType.nodeKinds) {
|
|
37
|
+
nodeKinds.add(nodeKind);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return Either.of({
|
|
42
|
+
defaultValue: defaultValue.filter((term) => term.termType === "NamedNode"),
|
|
43
|
+
hasValues: [],
|
|
44
|
+
in_: [],
|
|
45
|
+
kind: "IdentifierType",
|
|
46
|
+
nodeKinds,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
// Not extern, use the type
|
|
50
|
+
return Either.of(astType);
|
|
51
|
+
};
|
|
52
|
+
if (shape.constraints.and.length > 0) {
|
|
53
|
+
memberTypeEithers = shape.constraints.and.map((memberShape) => this.transformPropertyShapeToAstType(memberShape, {
|
|
54
|
+
defaultValue,
|
|
55
|
+
extern: extern,
|
|
56
|
+
}));
|
|
57
|
+
compositeTypeKind = "IntersectionType";
|
|
58
|
+
}
|
|
59
|
+
else if (shape.constraints.classes.length > 0) {
|
|
60
|
+
memberTypeEithers = shape.constraints.classes.map((classIri) => {
|
|
61
|
+
if (classIri.equals(owl.Class) ||
|
|
62
|
+
classIri.equals(owl.Thing) ||
|
|
63
|
+
classIri.equals(rdfs.Class)) {
|
|
64
|
+
return Left(new Error(`class ${classIri.value} is not transformable`));
|
|
65
|
+
}
|
|
66
|
+
const classNodeShape = this.shapesGraph
|
|
67
|
+
.nodeShapeByIdentifier(classIri)
|
|
68
|
+
.extractNullable();
|
|
69
|
+
if (classNodeShape === null) {
|
|
70
|
+
return Left(new Error(`class ${classIri.value} did not resolve to a node shape`));
|
|
71
|
+
}
|
|
72
|
+
return transformNodeShapeToAstCompositeMemberType(classNodeShape);
|
|
73
|
+
});
|
|
74
|
+
compositeTypeKind = "IntersectionType";
|
|
75
|
+
if (Either.rights(memberTypeEithers).length === 0) {
|
|
76
|
+
// This frequently happens with e.g., sh:class skos:Concept
|
|
77
|
+
logger.debug("shape %s sh:class(es) did not map to any node shapes", shape);
|
|
78
|
+
return memberTypeEithers[0];
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
else if (shape.constraints.nodes.length > 0) {
|
|
82
|
+
memberTypeEithers = shape.constraints.nodes.map((nodeShape) => transformNodeShapeToAstCompositeMemberType(nodeShape));
|
|
83
|
+
compositeTypeKind = "IntersectionType";
|
|
84
|
+
}
|
|
85
|
+
else if (shape.constraints.xone.length > 0) {
|
|
86
|
+
memberTypeEithers = shape.constraints.xone.map((memberShape) => this.transformPropertyShapeToAstType(memberShape, {
|
|
87
|
+
defaultValue,
|
|
88
|
+
extern: extern,
|
|
89
|
+
}));
|
|
90
|
+
compositeTypeKind = "UnionType";
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
return Left(new Error(`unable to transform ${shape} into an AST type`));
|
|
94
|
+
}
|
|
95
|
+
invariant(memberTypeEithers.length > 0);
|
|
96
|
+
const memberTypes = Either.rights(memberTypeEithers);
|
|
97
|
+
if (memberTypes.length !== memberTypeEithers.length) {
|
|
98
|
+
logger.warn("shape %s composition did not map all member types successfully: %s", shape, Either.lefts(memberTypeEithers)
|
|
99
|
+
.map((left) => left.message)
|
|
100
|
+
.join("; "));
|
|
101
|
+
return memberTypeEithers[0];
|
|
102
|
+
}
|
|
103
|
+
invariant(memberTypes.length > 0);
|
|
104
|
+
if (memberTypes.length === 1) {
|
|
105
|
+
return Either.of(memberTypes[0]);
|
|
106
|
+
}
|
|
107
|
+
// Get the type underlying a set or option
|
|
108
|
+
const memberItemTypes = memberTypes.map((memberType) => {
|
|
109
|
+
switch (memberType.kind) {
|
|
110
|
+
case "SetType":
|
|
111
|
+
return memberType.itemType;
|
|
112
|
+
case "OptionType":
|
|
113
|
+
return memberType.itemType;
|
|
114
|
+
default:
|
|
115
|
+
return memberType;
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
if (hasValues.length === 0) {
|
|
119
|
+
// Can't handle hasValues when coalescing types
|
|
120
|
+
const canCoalesce = (memberItemType) => {
|
|
121
|
+
if (memberItemType.in_.length > 0) {
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
switch (memberItemType.kind) {
|
|
125
|
+
case "LiteralType": {
|
|
126
|
+
if (memberItemType.maxExclusive.isJust()) {
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
if (memberItemType.maxInclusive.isJust()) {
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
if (memberItemType.minExclusive.isJust()) {
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
if (memberItemType.minInclusive.isJust()) {
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return true;
|
|
141
|
+
};
|
|
142
|
+
if (memberItemTypes.every((memberItemType) => memberItemType.kind === "IdentifierType" &&
|
|
143
|
+
canCoalesce(memberItemType))) {
|
|
144
|
+
// Special case: all member types are identifiers without further constraints
|
|
145
|
+
return Either.of({
|
|
146
|
+
defaultValue: defaultValue.filter((term) => term.termType === "NamedNode"),
|
|
147
|
+
hasValues: [],
|
|
148
|
+
in_: [],
|
|
149
|
+
kind: "IdentifierType",
|
|
150
|
+
nodeKinds: new Set(memberItemTypes
|
|
151
|
+
.filter((memberItemType) => memberItemType.kind === "IdentifierType")
|
|
152
|
+
.flatMap((memberItemType) => [
|
|
153
|
+
...memberItemType.nodeKinds,
|
|
154
|
+
])),
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
if (memberItemTypes.every((memberItemType) => memberItemType.kind === "LiteralType" && canCoalesce(memberItemType))) {
|
|
158
|
+
// Special case: all the member types are Literals without further constraints,
|
|
159
|
+
// like dash:StringOrLangString
|
|
160
|
+
// Don't try to coalesce range constraints.
|
|
161
|
+
return Either.of({
|
|
162
|
+
datatype: Maybe.empty(),
|
|
163
|
+
defaultValue: defaultValue.filter((term) => term.termType === "Literal"),
|
|
164
|
+
hasValues: [],
|
|
165
|
+
in_: [],
|
|
166
|
+
kind: "LiteralType",
|
|
167
|
+
languageIn: [],
|
|
168
|
+
maxExclusive: Maybe.empty(),
|
|
169
|
+
maxInclusive: Maybe.empty(),
|
|
170
|
+
minExclusive: Maybe.empty(),
|
|
171
|
+
minInclusive: Maybe.empty(),
|
|
172
|
+
nodeKinds: new Set(["Literal"]),
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
if (memberItemTypes.every((memberItemType) => (memberItemType.kind === "IdentifierType" ||
|
|
176
|
+
memberItemType.kind === "LiteralType" ||
|
|
177
|
+
memberItemType.kind === "TermType") &&
|
|
178
|
+
canCoalesce(memberItemType))) {
|
|
179
|
+
// Special case: all member types are terms without further constraints
|
|
180
|
+
const nodeKinds = new Set(memberItemTypes.flatMap((memberItemType) => [
|
|
181
|
+
...memberItemType
|
|
182
|
+
.nodeKinds,
|
|
183
|
+
]));
|
|
184
|
+
invariant(nodeKinds.has("Literal") &&
|
|
185
|
+
(nodeKinds.has("BlankNode") || nodeKinds.has("NamedNode"))); // The identifier-identifier and literal-literal cases should have been caught above
|
|
186
|
+
return Either.of({
|
|
187
|
+
defaultValue,
|
|
188
|
+
hasValues: [],
|
|
189
|
+
in_: [],
|
|
190
|
+
kind: "TermType",
|
|
191
|
+
nodeKinds,
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return Either.of({
|
|
196
|
+
kind: compositeTypeKind,
|
|
197
|
+
memberTypes: memberTypes,
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
//# sourceMappingURL=transformPropertyShapeToAstCompositeType.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { BlankNode, Literal, NamedNode } from "@rdfjs/types";
|
|
2
|
+
import { Either, Maybe } from "purify-ts";
|
|
3
|
+
import type { ShapesGraphToAstTransformer } from "../ShapesGraphToAstTransformer.js";
|
|
4
|
+
import type * as ast from "../ast/index.js";
|
|
5
|
+
import * as input from "../input/index.js";
|
|
6
|
+
/**
|
|
7
|
+
* Try to convert a property shape to an AST IdentifierType using some heuristics.
|
|
8
|
+
*/
|
|
9
|
+
export declare function transformPropertyShapeToAstIdentifierType(this: ShapesGraphToAstTransformer, shape: input.Shape, inherited: {
|
|
10
|
+
defaultValue: Maybe<BlankNode | Literal | NamedNode>;
|
|
11
|
+
} | null): Either<Error, ast.IdentifierType>;
|
|
12
|
+
//# sourceMappingURL=transformPropertyShapeToAstIdentifierType.d.ts.map
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Either, Left, Maybe } from "purify-ts";
|
|
2
|
+
import * as input from "../input/index.js";
|
|
3
|
+
import { propertyShapeNodeKinds } from "./propertyShapeNodeKinds.js";
|
|
4
|
+
/**
|
|
5
|
+
* Try to convert a property shape to an AST IdentifierType using some heuristics.
|
|
6
|
+
*/
|
|
7
|
+
export function transformPropertyShapeToAstIdentifierType(shape, inherited) {
|
|
8
|
+
// defaultValue / hasValue / in only makes sense with IRIs
|
|
9
|
+
const identifierDefaultValue = (shape instanceof input.PropertyShape ? shape.defaultValue : Maybe.empty())
|
|
10
|
+
.alt(inherited !== null ? inherited.defaultValue : Maybe.empty())
|
|
11
|
+
.filter((value) => value.termType === "NamedNode");
|
|
12
|
+
const identifierHasValues = shape.constraints.hasValues.filter((term) => term.termType === "NamedNode");
|
|
13
|
+
const identifierIn = shape.constraints.in_.filter((term) => term.termType === "NamedNode");
|
|
14
|
+
const nodeKinds = propertyShapeNodeKinds(shape);
|
|
15
|
+
if (identifierHasValues.length > 0 ||
|
|
16
|
+
identifierDefaultValue.isJust() ||
|
|
17
|
+
identifierIn.length > 0 ||
|
|
18
|
+
(nodeKinds.size > 0 && nodeKinds.size <= 2 && !nodeKinds.has("Literal"))) {
|
|
19
|
+
return Either.of({
|
|
20
|
+
defaultValue: identifierDefaultValue,
|
|
21
|
+
hasValues: identifierHasValues,
|
|
22
|
+
in_: identifierIn,
|
|
23
|
+
kind: "IdentifierType",
|
|
24
|
+
nodeKinds: nodeKinds,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
return Left(new Error(`unable to transform ${shape} into an AST type`));
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=transformPropertyShapeToAstIdentifierType.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { BlankNode, Literal, NamedNode } from "@rdfjs/types";
|
|
2
|
+
import { Either, Maybe } from "purify-ts";
|
|
3
|
+
import type { ShapesGraphToAstTransformer } from "../ShapesGraphToAstTransformer.js";
|
|
4
|
+
import type * as ast from "../ast/index.js";
|
|
5
|
+
import * as input from "../input/index.js";
|
|
6
|
+
/**
|
|
7
|
+
* Try to convert a property shape to an AST LiteralType using some heuristics.
|
|
8
|
+
*/
|
|
9
|
+
export declare function transformPropertyShapeToAstLiteralType(this: ShapesGraphToAstTransformer, shape: input.Shape, inherited: {
|
|
10
|
+
defaultValue: Maybe<BlankNode | Literal | NamedNode>;
|
|
11
|
+
} | null): Either<Error, ast.LiteralType>;
|
|
12
|
+
//# sourceMappingURL=transformPropertyShapeToAstLiteralType.d.ts.map
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Either, Left, Maybe } from "purify-ts";
|
|
2
|
+
import * as input from "../input/index.js";
|
|
3
|
+
import { propertyShapeNodeKinds } from "./propertyShapeNodeKinds.js";
|
|
4
|
+
/**
|
|
5
|
+
* Try to convert a property shape to an AST LiteralType using some heuristics.
|
|
6
|
+
*/
|
|
7
|
+
export function transformPropertyShapeToAstLiteralType(shape, inherited) {
|
|
8
|
+
const literalDefaultValue = (shape instanceof input.PropertyShape ? shape.defaultValue : Maybe.empty())
|
|
9
|
+
.alt(inherited !== null ? inherited.defaultValue : Maybe.empty())
|
|
10
|
+
.filter((term) => term.termType === "Literal");
|
|
11
|
+
const literalHasValues = shape.constraints.hasValues.filter((term) => term.termType === "Literal");
|
|
12
|
+
const literalIn = shape.constraints.in_.filter((term) => term.termType === "Literal");
|
|
13
|
+
const nodeKinds = propertyShapeNodeKinds(shape);
|
|
14
|
+
if ([
|
|
15
|
+
// Treat any shape with the constraints in the list as a literal type
|
|
16
|
+
shape.constraints.datatype,
|
|
17
|
+
shape.constraints.maxExclusive,
|
|
18
|
+
shape.constraints.maxInclusive,
|
|
19
|
+
shape.constraints.minExclusive,
|
|
20
|
+
shape.constraints.minInclusive,
|
|
21
|
+
].some((constraint) => constraint.isJust()) ||
|
|
22
|
+
shape.constraints.languageIn.length > 0 ||
|
|
23
|
+
literalDefaultValue.isJust() ||
|
|
24
|
+
literalHasValues.length > 0 ||
|
|
25
|
+
literalIn.length > 0 ||
|
|
26
|
+
// Treat any shape with a single sh:nodeKind of sh:Literal as a literal type
|
|
27
|
+
(nodeKinds.size === 1 && nodeKinds.has("Literal")))
|
|
28
|
+
return Either.of({
|
|
29
|
+
datatype: shape.constraints.datatype,
|
|
30
|
+
defaultValue: literalDefaultValue,
|
|
31
|
+
hasValues: literalHasValues,
|
|
32
|
+
in_: literalIn,
|
|
33
|
+
kind: "LiteralType",
|
|
34
|
+
languageIn: shape.constraints.languageIn,
|
|
35
|
+
maxExclusive: shape.constraints.maxExclusive,
|
|
36
|
+
maxInclusive: shape.constraints.maxInclusive,
|
|
37
|
+
minExclusive: shape.constraints.minExclusive,
|
|
38
|
+
minInclusive: shape.constraints.minInclusive,
|
|
39
|
+
nodeKinds: new Set(["Literal"]),
|
|
40
|
+
});
|
|
41
|
+
return Left(new Error(`unable to transform ${shape} into an AST type`));
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=transformPropertyShapeToAstLiteralType.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Either } from "purify-ts";
|
|
2
|
+
import type { ShapesGraphToAstTransformer } from "../ShapesGraphToAstTransformer.js";
|
|
3
|
+
import type * as ast from "../ast/index.js";
|
|
4
|
+
import type * as input from "../input/index.js";
|
|
5
|
+
export declare function transformPropertyShapeToAstObjectTypeProperty(this: ShapesGraphToAstTransformer, propertyShape: input.PropertyShape): Either<Error, ast.ObjectType.Property>;
|
|
6
|
+
//# sourceMappingURL=transformPropertyShapeToAstObjectTypeProperty.d.ts.map
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Either, Left } from "purify-ts";
|
|
2
|
+
import { pickLiteral } from "./pickLiteral.js";
|
|
3
|
+
export function transformPropertyShapeToAstObjectTypeProperty(propertyShape) {
|
|
4
|
+
{
|
|
5
|
+
const property = this.astObjectTypePropertiesByIdentifier.get(propertyShape.identifier);
|
|
6
|
+
if (property) {
|
|
7
|
+
return Either.of(property);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
const type = this.transformPropertyShapeToAstType(propertyShape, null);
|
|
11
|
+
if (type.isLeft()) {
|
|
12
|
+
return type;
|
|
13
|
+
}
|
|
14
|
+
const path = propertyShape.path;
|
|
15
|
+
if (path.kind !== "PredicatePath") {
|
|
16
|
+
return Left(new Error(`${propertyShape} has non-predicate path, unsupported`));
|
|
17
|
+
}
|
|
18
|
+
const property = {
|
|
19
|
+
comment: pickLiteral(propertyShape.comments).map((literal) => literal.value),
|
|
20
|
+
description: pickLiteral(propertyShape.descriptions).map((literal) => literal.value),
|
|
21
|
+
label: pickLiteral(propertyShape.labels).map((literal) => literal.value),
|
|
22
|
+
mutable: propertyShape.mutable,
|
|
23
|
+
name: this.shapeAstName(propertyShape),
|
|
24
|
+
path,
|
|
25
|
+
type: type.extract(),
|
|
26
|
+
visibility: propertyShape.visibility,
|
|
27
|
+
};
|
|
28
|
+
this.astObjectTypePropertiesByIdentifier.set(propertyShape.identifier, property);
|
|
29
|
+
return Either.of(property);
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=transformPropertyShapeToAstObjectTypeProperty.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { BlankNode, Literal, NamedNode } from "@rdfjs/types";
|
|
2
|
+
import { Either, Maybe } from "purify-ts";
|
|
3
|
+
import type { ShapesGraphToAstTransformer } from "../ShapesGraphToAstTransformer.js";
|
|
4
|
+
import type * as ast from "../ast/index.js";
|
|
5
|
+
import * as input from "../input/index.js";
|
|
6
|
+
/**
|
|
7
|
+
* Try to convert a property shape to an AST TermType using some heuristics.
|
|
8
|
+
*/
|
|
9
|
+
export declare function transformPropertyShapeToAstTermType(this: ShapesGraphToAstTransformer, shape: input.Shape, inherited: {
|
|
10
|
+
defaultValue: Maybe<BlankNode | Literal | NamedNode>;
|
|
11
|
+
} | null): Either<Error, Omit<ast.TermType<BlankNode | Literal | NamedNode>, "kind"> & {
|
|
12
|
+
readonly kind: "TermType";
|
|
13
|
+
}>;
|
|
14
|
+
//# sourceMappingURL=transformPropertyShapeToAstTermType.d.ts.map
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Either, Maybe } from "purify-ts";
|
|
2
|
+
import * as input from "../input/index.js";
|
|
3
|
+
import { propertyShapeNodeKinds } from "./propertyShapeNodeKinds.js";
|
|
4
|
+
/**
|
|
5
|
+
* Try to convert a property shape to an AST TermType using some heuristics.
|
|
6
|
+
*/
|
|
7
|
+
export function transformPropertyShapeToAstTermType(shape, inherited) {
|
|
8
|
+
const nodeKinds = propertyShapeNodeKinds(shape);
|
|
9
|
+
return Either.of({
|
|
10
|
+
defaultValue: (shape instanceof input.PropertyShape
|
|
11
|
+
? shape.defaultValue
|
|
12
|
+
: Maybe.empty()).alt(inherited !== null ? inherited.defaultValue : Maybe.empty()),
|
|
13
|
+
hasValues: shape.constraints.hasValues,
|
|
14
|
+
in_: shape.constraints.in_,
|
|
15
|
+
kind: "TermType",
|
|
16
|
+
nodeKinds: nodeKinds.size > 0
|
|
17
|
+
? nodeKinds
|
|
18
|
+
: new Set(["BlankNode", "NamedNode", "Literal"]),
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=transformPropertyShapeToAstTermType.js.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { BlankNode, Literal, NamedNode } from "@rdfjs/types";
|
|
2
|
+
import type { Either, Maybe } from "purify-ts";
|
|
3
|
+
import type { ShapesGraphToAstTransformer } from "../ShapesGraphToAstTransformer.js";
|
|
4
|
+
import type * as ast from "../ast/index.js";
|
|
5
|
+
import * as input from "../input/index.js";
|
|
6
|
+
/**
|
|
7
|
+
* Try to convert a property shape to a type using some heuristics.
|
|
8
|
+
*
|
|
9
|
+
* 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
|
|
10
|
+
* a shape has one type.
|
|
11
|
+
*/
|
|
12
|
+
export declare function transformPropertyShapeToAstType(this: ShapesGraphToAstTransformer, shape: input.Shape, inherited: {
|
|
13
|
+
defaultValue: Maybe<BlankNode | Literal | NamedNode>;
|
|
14
|
+
extern: Maybe<boolean>;
|
|
15
|
+
} | null): Either<Error, ast.Type>;
|
|
16
|
+
//# sourceMappingURL=transformPropertyShapeToAstType.d.ts.map
|