@shaclmate/compiler 4.0.40 → 4.0.41
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/ShapesGraphToAstTransformer.d.ts +0 -8
- package/dist/ShapesGraphToAstTransformer.js +5 -85
- package/dist/_ShapesGraphToAstTransformer/shapeNodeKinds.js +128 -160
- package/dist/_ShapesGraphToAstTransformer/transformShapeToAstObjectType.d.ts +1 -1
- package/dist/_ShapesGraphToAstTransformer/transformShapeToAstObjectType.js +0 -16
- package/dist/ast/AbstractCompoundType.d.ts +2 -1
- package/dist/ast/AbstractCompoundType.js +1 -1
- package/dist/ast/AbstractLazyObjectType.d.ts +0 -2
- package/dist/ast/Ast.d.ts +1 -3
- package/dist/ast/ListType.d.ts +1 -1
- package/dist/ast/ListType.js +1 -1
- package/dist/ast/ObjectType.d.ts +0 -12
- package/dist/ast/ObjectType.js +0 -78
- package/dist/generators/AstJsonGenerator.js +7 -3
- package/dist/generators/transformAstToLabeledPropertyGraph.js +59 -56
- package/dist/generators/ts/AbstractCollectionType.d.ts +4 -11
- package/dist/generators/ts/AbstractCollectionType.js +3 -62
- package/dist/generators/ts/AbstractContainerType.d.ts +0 -1
- package/dist/generators/ts/AbstractContainerType.js +1 -4
- package/dist/generators/ts/AbstractDateType.d.ts +4 -1
- package/dist/generators/ts/AbstractDateType.js +6 -1
- package/dist/generators/ts/AbstractIdentifierType.d.ts +4 -0
- package/dist/generators/ts/AbstractIdentifierType.js +3 -0
- package/dist/generators/ts/AbstractLazyObjectType.d.ts +1 -1
- package/dist/generators/ts/AbstractLazyObjectType.js +12 -1
- package/dist/generators/ts/AbstractLiteralType.d.ts +1 -0
- package/dist/generators/ts/AbstractNumericType.js +7 -7
- package/dist/generators/ts/AbstractPrimitiveType.d.ts +1 -0
- package/dist/generators/ts/AbstractTermType.d.ts +1 -2
- package/dist/generators/ts/AbstractTermType.js +1 -3
- package/dist/generators/ts/AbstractType.d.ts +46 -16
- package/dist/generators/ts/AbstractType.js +31 -16
- package/dist/generators/ts/BigDecimalType.d.ts +4 -0
- package/dist/generators/ts/BigDecimalType.js +4 -1
- package/dist/generators/ts/BigIntType.d.ts +3 -1
- package/dist/generators/ts/BigIntType.js +1 -1
- package/dist/generators/ts/BlankNodeType.d.ts +1 -1
- package/dist/generators/ts/BlankNodeType.js +3 -3
- package/dist/generators/ts/BooleanType.d.ts +3 -1
- package/dist/generators/ts/BooleanType.js +1 -1
- package/dist/generators/ts/DefaultValueType.d.ts +39 -1
- package/dist/generators/ts/DefaultValueType.js +6 -3
- package/dist/generators/ts/FloatType.d.ts +3 -1
- package/dist/generators/ts/FloatType.js +1 -1
- package/dist/generators/ts/GraphqlSchema.js +2 -2
- package/dist/generators/ts/IdentifierType.d.ts +1 -1
- package/dist/generators/ts/IdentifierType.js +7 -5
- package/dist/generators/ts/IntType.d.ts +3 -1
- package/dist/generators/ts/IntType.js +1 -1
- package/dist/generators/ts/IriType.js +4 -2
- package/dist/generators/ts/LazyObjectOptionType.d.ts +1 -0
- package/dist/generators/ts/LazyObjectOptionType.js +8 -4
- package/dist/generators/ts/LazyObjectSetType.js +9 -3
- package/dist/generators/ts/LazyObjectType.js +5 -2
- package/dist/generators/ts/ListType.d.ts +10 -1
- package/dist/generators/ts/ListType.js +45 -8
- package/dist/generators/ts/LiteralType.d.ts +4 -0
- package/dist/generators/ts/LiteralType.js +6 -3
- package/dist/generators/ts/ObjectType.d.ts +8 -22
- package/dist/generators/ts/ObjectType.js +6 -74
- package/dist/generators/ts/ObjectUnionType.js +2 -2
- package/dist/generators/ts/OptionType.d.ts +5 -1
- package/dist/generators/ts/OptionType.js +10 -5
- package/dist/generators/ts/RdfjsDatasetObjectSetType.js +1 -4
- package/dist/generators/ts/SetType.d.ts +16 -1
- package/dist/generators/ts/SetType.js +80 -2
- package/dist/generators/ts/Snippets.d.ts +3 -1
- package/dist/generators/ts/Snippets.js +18 -4
- package/dist/generators/ts/StringType.d.ts +3 -1
- package/dist/generators/ts/StringType.js +5 -1
- package/dist/generators/ts/TermType.d.ts +4 -0
- package/dist/generators/ts/TermType.js +3 -0
- package/dist/generators/ts/TsGenerator.d.ts +1 -1
- package/dist/generators/ts/TsGenerator.js +53 -28
- package/dist/generators/ts/TypeFactory.js +12 -25
- package/dist/generators/ts/UnionType.d.ts +3 -6
- package/dist/generators/ts/UnionType.js +42 -55
- package/dist/generators/ts/ZodGenerator.d.ts +1 -1
- package/dist/generators/ts/ZodGenerator.js +19 -12
- package/dist/generators/ts/_ObjectType/AbstractProperty.d.ts +6 -3
- package/dist/generators/ts/_ObjectType/DiscriminantProperty.d.ts +8 -12
- package/dist/generators/ts/_ObjectType/DiscriminantProperty.js +18 -35
- package/dist/generators/ts/_ObjectType/IdentifierProperty.js +5 -5
- package/dist/generators/ts/_ObjectType/ObjectType_createFunctionDeclaration.js +9 -30
- package/dist/generators/ts/_ObjectType/ObjectType_equalsFunctionDeclaration.js +0 -4
- package/dist/generators/ts/_ObjectType/ObjectType_filterFunctionDeclaration.js +0 -3
- package/dist/generators/ts/_ObjectType/ObjectType_filterTypeDeclaration.js +0 -3
- package/dist/generators/ts/_ObjectType/ObjectType_focusSparqlConstructTriplesFunctionDeclaration.js +0 -4
- package/dist/generators/ts/_ObjectType/ObjectType_focusSparqlWherePatternsFunctionDeclaration.js +3 -22
- package/dist/generators/ts/_ObjectType/ObjectType_fromJsonFunctionDeclaration.js +4 -29
- package/dist/generators/ts/_ObjectType/ObjectType_fromRdfResourceFunctionDeclaration.js +10 -39
- package/dist/generators/ts/_ObjectType/ObjectType_hashFunctionDeclarations.js +25 -29
- package/dist/generators/ts/_ObjectType/ObjectType_interfaceDeclaration.js +1 -5
- package/dist/generators/ts/_ObjectType/ObjectType_isTypeFunctionDeclaration.js +11 -8
- package/dist/generators/ts/_ObjectType/ObjectType_jsonSchemaFunctionDeclaration.js +3 -9
- package/dist/generators/ts/_ObjectType/ObjectType_jsonTypeAliasDeclaration.js +1 -8
- package/dist/generators/ts/_ObjectType/ObjectType_jsonUiSchemaFunctionDeclaration.js +1 -3
- package/dist/generators/ts/_ObjectType/ObjectType_schemaVariableStatement.js +2 -4
- package/dist/generators/ts/_ObjectType/ObjectType_toJsonFunctionDeclaration.js +10 -31
- package/dist/generators/ts/_ObjectType/ObjectType_toRdfResourceFunctionDeclaration.js +1 -1
- package/dist/generators/ts/_ObjectType/ObjectType_toStringFunctionDeclarations.js +2 -9
- package/dist/generators/ts/_ObjectType/ShaclProperty.js +6 -6
- package/dist/generators/ts/_ObjectType/identifierTypeDeclarations.js +0 -11
- package/dist/generators/ts/_snippets/snippets_convertToArraySet.d.ts +3 -0
- package/dist/generators/ts/_snippets/snippets_convertToArraySet.js +8 -0
- package/dist/generators/ts/_snippets/snippets_convertToList.d.ts +3 -0
- package/dist/generators/ts/_snippets/snippets_convertToList.js +7 -0
- package/dist/generators/ts/_snippets/snippets_convertToScalarSet.d.ts +3 -0
- package/dist/generators/ts/_snippets/snippets_convertToScalarSet.js +15 -0
- package/dist/input/generated.d.ts +756 -115
- package/dist/input/generated.js +634 -126
- package/package.json +2 -4
- package/dist/generators/ts/_snippets/snippets_convertToArray.d.ts +0 -3
- package/dist/generators/ts/_snippets/snippets_convertToArray.js +0 -8
|
@@ -4,22 +4,14 @@ import { Either } from "purify-ts";
|
|
|
4
4
|
import type { Logger } from "ts-log";
|
|
5
5
|
import type * as ast from "./ast/index.js";
|
|
6
6
|
import type * as input from "./input/index.js";
|
|
7
|
-
interface RelatedNodeShapes {
|
|
8
|
-
readonly ancestors: input.NodeShape[];
|
|
9
|
-
readonly children: input.NodeShape[];
|
|
10
|
-
readonly parents: input.NodeShape[];
|
|
11
|
-
readonly descendants: input.NodeShape[];
|
|
12
|
-
}
|
|
13
7
|
export declare class ShapesGraphToAstTransformer {
|
|
14
8
|
protected readonly cachedAstTypesByShapeIdentifier: TermMap<BlankNode | NamedNode, ast.Type>;
|
|
15
9
|
protected readonly logger: Logger;
|
|
16
10
|
protected readonly shapesGraph: input.ShapesGraph;
|
|
17
|
-
protected readonly relatedNodeShapesByIdentifier: TermMap<BlankNode | NamedNode, RelatedNodeShapes>;
|
|
18
11
|
constructor({ logger, shapesGraph, }: {
|
|
19
12
|
logger: Logger;
|
|
20
13
|
shapesGraph: input.ShapesGraph;
|
|
21
14
|
});
|
|
22
15
|
transform(): Either<Error, ast.Ast>;
|
|
23
16
|
}
|
|
24
|
-
export {};
|
|
25
17
|
//# sourceMappingURL=ShapesGraphToAstTransformer.d.ts.map
|
|
@@ -4,92 +4,18 @@ import { Either } from "purify-ts";
|
|
|
4
4
|
import { invariant } from "ts-invariant";
|
|
5
5
|
import { ShapeStack } from "./_ShapesGraphToAstTransformer/ShapeStack.js";
|
|
6
6
|
import { transformShapeToAstType } from "./_ShapesGraphToAstTransformer/transformShapeToAstType.js";
|
|
7
|
-
function relatedNodeShapes({ logger, shapesGraph, }) {
|
|
8
|
-
const immediateRelatedNodeShapes = new TermMap();
|
|
9
|
-
for (const childNodeShape of shapesGraph.nodeShapes) {
|
|
10
|
-
let childRelatedNodeShapes = immediateRelatedNodeShapes.get(childNodeShape.$identifier());
|
|
11
|
-
if (!childRelatedNodeShapes) {
|
|
12
|
-
childRelatedNodeShapes = {
|
|
13
|
-
children: new TermMap(),
|
|
14
|
-
parents: new TermMap(),
|
|
15
|
-
};
|
|
16
|
-
immediateRelatedNodeShapes.set(childNodeShape.$identifier(), childRelatedNodeShapes);
|
|
17
|
-
}
|
|
18
|
-
for (const parentClassIdentifier of childNodeShape.subClassOf) {
|
|
19
|
-
shapesGraph
|
|
20
|
-
.nodeShape(parentClassIdentifier)
|
|
21
|
-
.ifLeft((error) => {
|
|
22
|
-
logger.error("%s is rdfs:subClassOf %s which is either missing or not a node shape: %s", childNodeShape, parentClassIdentifier, error.message);
|
|
23
|
-
})
|
|
24
|
-
.ifRight((parentNodeShape) => {
|
|
25
|
-
childRelatedNodeShapes.parents.set(parentNodeShape.$identifier(), parentNodeShape);
|
|
26
|
-
let parentRelatedNodeShapes = immediateRelatedNodeShapes.get(parentNodeShape.$identifier());
|
|
27
|
-
if (!parentRelatedNodeShapes) {
|
|
28
|
-
parentRelatedNodeShapes = {
|
|
29
|
-
children: new TermMap(),
|
|
30
|
-
parents: new TermMap(),
|
|
31
|
-
};
|
|
32
|
-
immediateRelatedNodeShapes.set(parentNodeShape.$identifier(), parentRelatedNodeShapes);
|
|
33
|
-
}
|
|
34
|
-
parentRelatedNodeShapes.children.set(childNodeShape.$identifier(), childNodeShape);
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
const result = new TermMap();
|
|
39
|
-
for (const nodeShape of shapesGraph.nodeShapes) {
|
|
40
|
-
const { children: childNodeShapes, parents: parentNodeShapes } = immediateRelatedNodeShapes.get(nodeShape.$identifier());
|
|
41
|
-
const ancestorNodeShapes = new TermMap();
|
|
42
|
-
function recurseAncestorNodeShapes(nodeShape) {
|
|
43
|
-
for (const parentNodeShape of immediateRelatedNodeShapes
|
|
44
|
-
.get(nodeShape.$identifier())
|
|
45
|
-
.parents.values()) {
|
|
46
|
-
if (!ancestorNodeShapes.has(parentNodeShape.$identifier())) {
|
|
47
|
-
ancestorNodeShapes.set(parentNodeShape.$identifier(), parentNodeShape);
|
|
48
|
-
recurseAncestorNodeShapes(parentNodeShape);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
recurseAncestorNodeShapes(nodeShape);
|
|
53
|
-
const descendantNodeShapes = new TermMap();
|
|
54
|
-
function recurseDescendantNodeShapes(nodeShape) {
|
|
55
|
-
for (const childNodeShape of immediateRelatedNodeShapes
|
|
56
|
-
.get(nodeShape.$identifier())
|
|
57
|
-
.children.values()) {
|
|
58
|
-
if (!descendantNodeShapes.has(childNodeShape.$identifier())) {
|
|
59
|
-
descendantNodeShapes.set(childNodeShape.$identifier(), childNodeShape);
|
|
60
|
-
recurseDescendantNodeShapes(childNodeShape);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
recurseDescendantNodeShapes(nodeShape);
|
|
65
|
-
result.set(nodeShape.$identifier(), {
|
|
66
|
-
ancestors: [...ancestorNodeShapes.values()],
|
|
67
|
-
children: [...childNodeShapes.values()],
|
|
68
|
-
descendants: [...descendantNodeShapes.values()],
|
|
69
|
-
parents: [...parentNodeShapes.values()],
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
return result;
|
|
73
|
-
}
|
|
74
7
|
export class ShapesGraphToAstTransformer {
|
|
75
8
|
// Members are protected so they're accessible to functions in other files
|
|
76
9
|
cachedAstTypesByShapeIdentifier = new TermMap();
|
|
77
10
|
logger;
|
|
78
11
|
shapesGraph;
|
|
79
|
-
relatedNodeShapesByIdentifier = new TermMap();
|
|
80
12
|
constructor({ logger, shapesGraph, }) {
|
|
81
13
|
this.logger = logger;
|
|
82
|
-
this.relatedNodeShapesByIdentifier = relatedNodeShapes({
|
|
83
|
-
logger: this.logger,
|
|
84
|
-
shapesGraph,
|
|
85
|
-
});
|
|
86
14
|
this.shapesGraph = shapesGraph;
|
|
87
15
|
}
|
|
88
16
|
transform() {
|
|
89
|
-
const
|
|
90
|
-
const astObjectTypes = [];
|
|
17
|
+
const astNamedTypes = [];
|
|
91
18
|
const syntheticAstObjectTypesByName = {};
|
|
92
|
-
const astNamedUnionTypes = [];
|
|
93
19
|
for (const nodeShape of this.shapesGraph.nodeShapes) {
|
|
94
20
|
if (nodeShape.$identifier().termType !== "NamedNode") {
|
|
95
21
|
continue;
|
|
@@ -104,13 +30,14 @@ export class ShapesGraphToAstTransformer {
|
|
|
104
30
|
const nodeShapeAstType = nodeShapeAstTypeEither.unsafeCoerce();
|
|
105
31
|
switch (nodeShapeAstType.kind) {
|
|
106
32
|
case "Intersection":
|
|
33
|
+
case "Union":
|
|
107
34
|
if (nodeShapeAstType.name.isJust()) {
|
|
108
|
-
|
|
35
|
+
astNamedTypes.push(nodeShapeAstType);
|
|
109
36
|
}
|
|
110
37
|
break;
|
|
111
38
|
case "Object": {
|
|
112
39
|
invariant(nodeShapeAstType.name.isJust(), `node shape missing name: ${nodeShapeAstType.shapeIdentifier}`);
|
|
113
|
-
|
|
40
|
+
astNamedTypes.push(nodeShapeAstType);
|
|
114
41
|
for (const property of nodeShapeAstType.properties) {
|
|
115
42
|
switch (property.type.kind) {
|
|
116
43
|
case "LazyObjectOption":
|
|
@@ -133,11 +60,6 @@ export class ShapesGraphToAstTransformer {
|
|
|
133
60
|
}
|
|
134
61
|
break;
|
|
135
62
|
}
|
|
136
|
-
case "Union":
|
|
137
|
-
if (nodeShapeAstType.name.isJust()) {
|
|
138
|
-
astNamedUnionTypes.push(nodeShapeAstType);
|
|
139
|
-
}
|
|
140
|
-
break;
|
|
141
63
|
default:
|
|
142
64
|
break;
|
|
143
65
|
}
|
|
@@ -153,9 +75,7 @@ export class ShapesGraphToAstTransformer {
|
|
|
153
75
|
return acc;
|
|
154
76
|
}
|
|
155
77
|
}, 0),
|
|
156
|
-
|
|
157
|
-
namedObjectTypes: astObjectTypes.concat(Object.values(syntheticAstObjectTypesByName)),
|
|
158
|
-
namedUnionTypes: astNamedUnionTypes,
|
|
78
|
+
namedTypes: astNamedTypes.concat(Object.values(syntheticAstObjectTypesByName)),
|
|
159
79
|
});
|
|
160
80
|
}
|
|
161
81
|
}
|
|
@@ -6,177 +6,145 @@ const defaultPropertyShapeNodeKinds = new Set([
|
|
|
6
6
|
"IRI",
|
|
7
7
|
"Literal",
|
|
8
8
|
]);
|
|
9
|
-
function
|
|
10
|
-
const
|
|
9
|
+
export function shapeNodeKinds(shape, options) {
|
|
10
|
+
const explicitNodeKinds = shape.nodeKind
|
|
11
11
|
.map(NodeKind.fromIri)
|
|
12
12
|
.orDefault(new Set());
|
|
13
|
-
//
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
13
|
+
// Consider constraints that dictate certain node kinds, like sh:datatype dictates a Literal nodeKind.
|
|
14
|
+
const constraintExcludeNodeKinds = new Set();
|
|
15
|
+
const constraintIncludeNodeKinds = new Set();
|
|
16
|
+
for (const [constraint, { excludeNodeKinds, includeNodeKinds }] of [
|
|
17
|
+
[
|
|
18
|
+
"sh:class",
|
|
19
|
+
shape.classes.length > 0
|
|
20
|
+
? { excludeNodeKinds: ["Literal"] }
|
|
21
|
+
: {},
|
|
22
|
+
],
|
|
23
|
+
[
|
|
24
|
+
"sh:datatype",
|
|
25
|
+
{
|
|
26
|
+
includeNodeKinds: shape.datatype
|
|
27
|
+
.map(() => ["Literal"])
|
|
28
|
+
.orDefault([]),
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
[
|
|
32
|
+
"sh:defaultValue",
|
|
33
|
+
{
|
|
34
|
+
includeNodeKinds: shape.$type === "PropertyShape"
|
|
35
|
+
? shape.defaultValue
|
|
36
|
+
.map((value) => NodeKind.fromTermType(value.termType))
|
|
37
|
+
.toList()
|
|
38
|
+
: [],
|
|
39
|
+
},
|
|
40
|
+
],
|
|
41
|
+
[
|
|
42
|
+
"sh:hasValue",
|
|
43
|
+
{
|
|
44
|
+
includeNodeKinds: shape.hasValues.map((value) => NodeKind.fromTermType(value.termType)),
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
[
|
|
48
|
+
"sh:in",
|
|
49
|
+
{
|
|
50
|
+
includeNodeKinds: shape.in_
|
|
51
|
+
.orDefault([])
|
|
52
|
+
.map((in_) => NodeKind.fromTermType(in_.termType)),
|
|
53
|
+
},
|
|
54
|
+
],
|
|
55
|
+
[
|
|
56
|
+
"sh:languageIn",
|
|
57
|
+
shape.languageIn.orDefault([]).length > 0
|
|
58
|
+
? { includeNodeKinds: ["Literal"] }
|
|
59
|
+
: {},
|
|
60
|
+
],
|
|
61
|
+
[
|
|
62
|
+
"sh:maxExclusive",
|
|
63
|
+
{
|
|
64
|
+
includeNodeKinds: shape.maxExclusive
|
|
65
|
+
.map(() => ["Literal"])
|
|
66
|
+
.orDefault([]),
|
|
67
|
+
},
|
|
68
|
+
],
|
|
69
|
+
[
|
|
70
|
+
"sh:maxInclusive",
|
|
71
|
+
{
|
|
72
|
+
includeNodeKinds: shape.maxInclusive
|
|
73
|
+
.map(() => ["Literal"])
|
|
74
|
+
.orDefault([]),
|
|
75
|
+
},
|
|
76
|
+
],
|
|
77
|
+
[
|
|
78
|
+
"sh:minExclusive",
|
|
79
|
+
{
|
|
80
|
+
includeNodeKinds: shape.minExclusive
|
|
81
|
+
.map(() => ["Literal"])
|
|
82
|
+
.orDefault([]),
|
|
83
|
+
},
|
|
84
|
+
],
|
|
85
|
+
[
|
|
86
|
+
"sh:minInclusive",
|
|
87
|
+
{
|
|
88
|
+
includeNodeKinds: shape.minInclusive
|
|
89
|
+
.map(() => ["Literal"])
|
|
90
|
+
.orDefault([]),
|
|
91
|
+
},
|
|
92
|
+
],
|
|
93
|
+
]) {
|
|
94
|
+
for (const excludeNodeKind of excludeNodeKinds ?? []) {
|
|
95
|
+
if (explicitNodeKinds.size > 0 &&
|
|
96
|
+
explicitNodeKinds.has(excludeNodeKind)) {
|
|
97
|
+
return Left(new Error(`${shape} has ${constraint} that conflicts with sh:nodeKind`));
|
|
21
98
|
}
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
if (parentNodeKinds.size > 0) {
|
|
25
|
-
if (thisNodeKinds.size === 0) {
|
|
26
|
-
return Either.of(parentNodeKinds);
|
|
99
|
+
constraintExcludeNodeKinds.add(excludeNodeKind);
|
|
27
100
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return Left(new Error(`${
|
|
101
|
+
for (const includeNodeKind of includeNodeKinds ?? []) {
|
|
102
|
+
if (explicitNodeKinds.size > 0 &&
|
|
103
|
+
!explicitNodeKinds.has(includeNodeKind)) {
|
|
104
|
+
return Left(new Error(`${shape} has ${constraint} that conflicts with sh:nodeKind`));
|
|
32
105
|
}
|
|
106
|
+
constraintIncludeNodeKinds.add(includeNodeKind);
|
|
33
107
|
}
|
|
34
108
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
// Consider constraints that dictate certain node kinds, like sh:datatype dictates a Literal nodeKind.
|
|
45
|
-
const constraintExcludeNodeKinds = new Set();
|
|
46
|
-
const constraintIncludeNodeKinds = new Set();
|
|
47
|
-
for (const [constraint, { excludeNodeKinds, includeNodeKinds }] of [
|
|
48
|
-
[
|
|
49
|
-
"sh:class",
|
|
50
|
-
shape.classes.length > 0
|
|
51
|
-
? { excludeNodeKinds: ["Literal"] }
|
|
52
|
-
: {},
|
|
53
|
-
],
|
|
54
|
-
[
|
|
55
|
-
"sh:datatype",
|
|
56
|
-
{
|
|
57
|
-
includeNodeKinds: shape.datatype
|
|
58
|
-
.map(() => ["Literal"])
|
|
59
|
-
.orDefault([]),
|
|
60
|
-
},
|
|
61
|
-
],
|
|
62
|
-
[
|
|
63
|
-
"sh:defaultValue",
|
|
64
|
-
{
|
|
65
|
-
includeNodeKinds: shape.$type === "PropertyShape"
|
|
66
|
-
? shape.defaultValue
|
|
67
|
-
.map((value) => NodeKind.fromTermType(value.termType))
|
|
68
|
-
.toList()
|
|
69
|
-
: [],
|
|
70
|
-
},
|
|
71
|
-
],
|
|
72
|
-
[
|
|
73
|
-
"sh:hasValue",
|
|
74
|
-
{
|
|
75
|
-
includeNodeKinds: shape.hasValues.map((value) => NodeKind.fromTermType(value.termType)),
|
|
76
|
-
},
|
|
77
|
-
],
|
|
78
|
-
[
|
|
79
|
-
"sh:in",
|
|
80
|
-
{
|
|
81
|
-
includeNodeKinds: shape.in_
|
|
82
|
-
.orDefault([])
|
|
83
|
-
.map((in_) => NodeKind.fromTermType(in_.termType)),
|
|
84
|
-
},
|
|
85
|
-
],
|
|
86
|
-
[
|
|
87
|
-
"sh:languageIn",
|
|
88
|
-
shape.languageIn.orDefault([]).length > 0
|
|
89
|
-
? { includeNodeKinds: ["Literal"] }
|
|
90
|
-
: {},
|
|
91
|
-
],
|
|
92
|
-
[
|
|
93
|
-
"sh:maxExclusive",
|
|
94
|
-
{
|
|
95
|
-
includeNodeKinds: shape.maxExclusive
|
|
96
|
-
.map(() => ["Literal"])
|
|
97
|
-
.orDefault([]),
|
|
98
|
-
},
|
|
99
|
-
],
|
|
100
|
-
[
|
|
101
|
-
"sh:maxInclusive",
|
|
102
|
-
{
|
|
103
|
-
includeNodeKinds: shape.maxInclusive
|
|
104
|
-
.map(() => ["Literal"])
|
|
105
|
-
.orDefault([]),
|
|
106
|
-
},
|
|
107
|
-
],
|
|
108
|
-
[
|
|
109
|
-
"sh:minExclusive",
|
|
110
|
-
{
|
|
111
|
-
includeNodeKinds: shape.minExclusive
|
|
112
|
-
.map(() => ["Literal"])
|
|
113
|
-
.orDefault([]),
|
|
114
|
-
},
|
|
115
|
-
],
|
|
116
|
-
[
|
|
117
|
-
"sh:minInclusive",
|
|
118
|
-
{
|
|
119
|
-
includeNodeKinds: shape.minInclusive
|
|
120
|
-
.map(() => ["Literal"])
|
|
121
|
-
.orDefault([]),
|
|
122
|
-
},
|
|
123
|
-
],
|
|
124
|
-
]) {
|
|
125
|
-
for (const excludeNodeKind of excludeNodeKinds ?? []) {
|
|
126
|
-
if (explicitNodeKinds.size > 0 &&
|
|
127
|
-
explicitNodeKinds.has(excludeNodeKind)) {
|
|
128
|
-
return Left(new Error(`${shape} has ${constraint} that conflicts with sh:nodeKind`));
|
|
129
|
-
}
|
|
130
|
-
constraintExcludeNodeKinds.add(excludeNodeKind);
|
|
131
|
-
}
|
|
132
|
-
for (const includeNodeKind of includeNodeKinds ?? []) {
|
|
133
|
-
if (explicitNodeKinds.size > 0 &&
|
|
134
|
-
!explicitNodeKinds.has(includeNodeKind)) {
|
|
135
|
-
return Left(new Error(`${shape} has ${constraint} that conflicts with sh:nodeKind`));
|
|
136
|
-
}
|
|
137
|
-
constraintIncludeNodeKinds.add(includeNodeKind);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
if (explicitNodeKinds.size > 0) {
|
|
141
|
-
return Either.of(explicitNodeKinds);
|
|
142
|
-
}
|
|
143
|
-
// There were no explicit sh:nodeKind, try to infer the shape's node kind from the node kinds excluded and included by constraints
|
|
144
|
-
const constraintNodeKinds = new Set();
|
|
145
|
-
if (constraintIncludeNodeKinds.size > 0) {
|
|
146
|
-
// If constraints dictated/included certain node kinds be included. Add those to the set.
|
|
147
|
-
for (const constraintIncludeNodeKind of constraintIncludeNodeKinds) {
|
|
148
|
-
constraintNodeKinds.add(constraintIncludeNodeKind);
|
|
149
|
-
}
|
|
150
|
-
// Check whether other constraints' excluded node kinds conflict.
|
|
151
|
-
if (constraintExcludeNodeKinds.size > 0) {
|
|
152
|
-
for (const constraintExcludeNodeKind of constraintExcludeNodeKinds) {
|
|
153
|
-
if (constraintIncludeNodeKinds.has(constraintExcludeNodeKind)) {
|
|
154
|
-
return Left(new Error(`${shape} has constraints with conflicting exclude/include node kinds`));
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
}
|
|
109
|
+
if (explicitNodeKinds.size > 0) {
|
|
110
|
+
return Either.of(explicitNodeKinds);
|
|
111
|
+
}
|
|
112
|
+
// There were no explicit sh:nodeKind, try to infer the shape's node kind from the node kinds excluded and included by constraints
|
|
113
|
+
const constraintNodeKinds = new Set();
|
|
114
|
+
if (constraintIncludeNodeKinds.size > 0) {
|
|
115
|
+
// If constraints dictated/included certain node kinds be included. Add those to the set.
|
|
116
|
+
for (const constraintIncludeNodeKind of constraintIncludeNodeKinds) {
|
|
117
|
+
constraintNodeKinds.add(constraintIncludeNodeKind);
|
|
158
118
|
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
// Start with all node kinds and exclude.
|
|
162
|
-
constraintNodeKinds.add("BlankNode");
|
|
163
|
-
constraintNodeKinds.add("IRI");
|
|
164
|
-
constraintNodeKinds.add("Literal");
|
|
119
|
+
// Check whether other constraints' excluded node kinds conflict.
|
|
120
|
+
if (constraintExcludeNodeKinds.size > 0) {
|
|
165
121
|
for (const constraintExcludeNodeKind of constraintExcludeNodeKinds) {
|
|
166
|
-
|
|
122
|
+
if (constraintIncludeNodeKinds.has(constraintExcludeNodeKind)) {
|
|
123
|
+
return Left(new Error(`${shape} has constraints with conflicting exclude/include node kinds`));
|
|
124
|
+
}
|
|
167
125
|
}
|
|
168
126
|
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
127
|
+
}
|
|
128
|
+
else if (constraintExcludeNodeKinds.size > 0) {
|
|
129
|
+
// No constraint dictated that certain node kinds be included, but some constraint dictated that certain node kinds be excluded.
|
|
130
|
+
// Start with all node kinds and exclude.
|
|
131
|
+
constraintNodeKinds.add("BlankNode");
|
|
132
|
+
constraintNodeKinds.add("IRI");
|
|
133
|
+
constraintNodeKinds.add("Literal");
|
|
134
|
+
for (const constraintExcludeNodeKind of constraintExcludeNodeKinds) {
|
|
135
|
+
constraintNodeKinds.delete(constraintExcludeNodeKind);
|
|
178
136
|
}
|
|
179
|
-
|
|
180
|
-
|
|
137
|
+
}
|
|
138
|
+
if (constraintNodeKinds.size > 0) {
|
|
139
|
+
return Either.of(constraintNodeKinds);
|
|
140
|
+
}
|
|
141
|
+
if (shape.$type === "NodeShape") {
|
|
142
|
+
return Either.of(options?.defaultNodeShapeNodeKinds ?? defaultNodeShapeNodeKinds);
|
|
143
|
+
}
|
|
144
|
+
if (shape.path.termType === "InversePath") {
|
|
145
|
+
// Inverse paths can only have blank nodes and IRIs as values, because the value is the subject of a triple.
|
|
146
|
+
return Either.of(new Set(["BlankNode", "IRI"]));
|
|
147
|
+
}
|
|
148
|
+
return Either.of(defaultPropertyShapeNodeKinds);
|
|
181
149
|
}
|
|
182
150
|
//# sourceMappingURL=shapeNodeKinds.js.map
|
|
@@ -2,6 +2,6 @@ import { Either, Maybe } from "purify-ts";
|
|
|
2
2
|
import * as ast from "../ast/index.js";
|
|
3
3
|
import type * as input from "../input/index.js";
|
|
4
4
|
import type { ShapesGraphToAstTransformer } from "../ShapesGraphToAstTransformer.js";
|
|
5
|
-
import { ShapeStack } from "./ShapeStack.js";
|
|
5
|
+
import type { ShapeStack } from "./ShapeStack.js";
|
|
6
6
|
export declare function transformShapeToAstObjectType(this: ShapesGraphToAstTransformer, shape: input.Shape, shapeStack: ShapeStack): Either<Error, Maybe<ast.Type>>;
|
|
7
7
|
//# sourceMappingURL=transformShapeToAstObjectType.d.ts.map
|
|
@@ -4,7 +4,6 @@ import { invariant } from "ts-invariant";
|
|
|
4
4
|
import * as ast from "../ast/index.js";
|
|
5
5
|
import { Eithers } from "../Eithers.js";
|
|
6
6
|
import { defaultNodeShapeNodeKinds } from "./defaultNodeShapeNodeKinds.js";
|
|
7
|
-
import { ShapeStack } from "./ShapeStack.js";
|
|
8
7
|
import { shapeAstTypeName } from "./shapeAstTypeName.js";
|
|
9
8
|
import { shapeNodeKinds } from "./shapeNodeKinds.js";
|
|
10
9
|
import { transformPropertyShapeToAstObjectTypeProperty } from "./transformPropertyShapeToAstObjectTypeProperty.js";
|
|
@@ -61,9 +60,7 @@ export function transformShapeToAstObjectType(shape, shapeStack) {
|
|
|
61
60
|
}
|
|
62
61
|
return Eithers.chain2(shapeNodeKinds.call(this, nodeShape, { defaultNodeShapeNodeKinds }), Either.sequence(nodeShape.properties.map((propertyShapeIdentifier) => this.shapesGraph.propertyShape(propertyShapeIdentifier)))).chain(([nodeKinds, propertyShapes]) => {
|
|
63
62
|
const nodeShapeIdentifier = nodeShape.$identifier();
|
|
64
|
-
const { ancestors: ancestorNodeShapes, descendants: descendantNodeShapes, children: childNodeShapes, parents: parentNodeShapes, } = this.relatedNodeShapesByIdentifier.get(nodeShapeIdentifier);
|
|
65
63
|
const isClass = nodeShape.subClassOf.length > 0 ||
|
|
66
|
-
descendantNodeShapes.length > 0 || // A node shape that is the object of an rdfs:subClassOf is itself an rdfs:Class
|
|
67
64
|
nodeShape.types.some((type) => type.equals(owl.Class) || type.equals(rdfs.Class));
|
|
68
65
|
let fromRdfType = nodeShape.fromRdfType.alt(nodeShape.rdfType);
|
|
69
66
|
if (isClass && nodeShapeIdentifier.termType === "NamedNode") {
|
|
@@ -131,19 +128,6 @@ export function transformShapeToAstObjectType(shape, shapeStack) {
|
|
|
131
128
|
});
|
|
132
129
|
this.cachedAstTypesByShapeIdentifier.set(nodeShape.$identifier(), objectType);
|
|
133
130
|
return (() => {
|
|
134
|
-
// Populate ancestor and descendant object types
|
|
135
|
-
const relatedObjectTypes = (relatedNodeShapes) => {
|
|
136
|
-
return relatedNodeShapes
|
|
137
|
-
.flatMap((relatedNodeShape) => transformShapeToAstType
|
|
138
|
-
.call(this, relatedNodeShape, new ShapeStack())
|
|
139
|
-
.toMaybe()
|
|
140
|
-
.toList())
|
|
141
|
-
.filter((astType) => astType.kind === "Object");
|
|
142
|
-
};
|
|
143
|
-
objectType.addAncestorObjectTypes(...relatedObjectTypes(ancestorNodeShapes));
|
|
144
|
-
objectType.addChildObjectTypes(...relatedObjectTypes(childNodeShapes));
|
|
145
|
-
objectType.addDescendantObjectTypes(...relatedObjectTypes(descendantNodeShapes));
|
|
146
|
-
objectType.addParentObjectTypes(...relatedObjectTypes(parentNodeShapes));
|
|
147
131
|
// Populate properties
|
|
148
132
|
for (const propertyShape of propertyShapes) {
|
|
149
133
|
const propertyEither = transformPropertyShapeToAstObjectTypeProperty.call(this, {
|
|
@@ -4,6 +4,7 @@ import type { BlankNodeType } from "./BlankNodeType.js";
|
|
|
4
4
|
import type { IdentifierType } from "./IdentifierType.js";
|
|
5
5
|
import type { IntersectionType } from "./IntersectionType.js";
|
|
6
6
|
import type { IriType } from "./IriType.js";
|
|
7
|
+
import type { ListType } from "./ListType.js";
|
|
7
8
|
import type { LiteralType } from "./LiteralType.js";
|
|
8
9
|
import type { ObjectType } from "./ObjectType.js";
|
|
9
10
|
import type { TermType } from "./TermType.js";
|
|
@@ -38,7 +39,7 @@ export declare namespace AbstractCompoundType {
|
|
|
38
39
|
interface Member<TypeT extends MemberType> {
|
|
39
40
|
readonly type: TypeT;
|
|
40
41
|
}
|
|
41
|
-
type MemberType = BlankNodeType | IdentifierType | IntersectionType | IriType | LiteralType | ObjectType | TermType | UnionType;
|
|
42
|
+
type MemberType = BlankNodeType | IdentifierType | IntersectionType | IriType | ListType | LiteralType | ObjectType | TermType | UnionType;
|
|
42
43
|
function isMemberType(type: Type): type is MemberType;
|
|
43
44
|
}
|
|
44
45
|
//# sourceMappingURL=AbstractCompoundType.d.ts.map
|
|
@@ -61,6 +61,7 @@ __decorate([
|
|
|
61
61
|
case "Identifier":
|
|
62
62
|
case "Intersection":
|
|
63
63
|
case "Iri":
|
|
64
|
+
case "List":
|
|
64
65
|
case "Literal":
|
|
65
66
|
case "Object":
|
|
66
67
|
case "Term":
|
|
@@ -70,7 +71,6 @@ __decorate([
|
|
|
70
71
|
case "LazyObjectOption":
|
|
71
72
|
case "LazyObjectSet":
|
|
72
73
|
case "LazyObject":
|
|
73
|
-
case "List":
|
|
74
74
|
case "Option":
|
|
75
75
|
case "Set":
|
|
76
76
|
return false;
|
|
@@ -32,7 +32,6 @@ export declare abstract class AbstractLazyObjectType<PartialTypeT extends Abstra
|
|
|
32
32
|
recursive: boolean | undefined;
|
|
33
33
|
shapeIdentifier: import("@rdfjs/types").BlankNode | import("@rdfjs/types").NamedNode<string>;
|
|
34
34
|
};
|
|
35
|
-
parentObjectTypes: (string | import("@rdfjs/types").BlankNode | import("@rdfjs/types").NamedNode<string>)[] | undefined;
|
|
36
35
|
synthetic: boolean | undefined;
|
|
37
36
|
toRdfTypes: readonly import("@rdfjs/types").NamedNode<string>[] | undefined;
|
|
38
37
|
comment: string | undefined;
|
|
@@ -74,7 +73,6 @@ export declare abstract class AbstractLazyObjectType<PartialTypeT extends Abstra
|
|
|
74
73
|
recursive: boolean | undefined;
|
|
75
74
|
shapeIdentifier: import("@rdfjs/types").BlankNode | import("@rdfjs/types").NamedNode<string>;
|
|
76
75
|
};
|
|
77
|
-
parentObjectTypes: (string | import("@rdfjs/types").BlankNode | import("@rdfjs/types").NamedNode<string>)[] | undefined;
|
|
78
76
|
synthetic: boolean | undefined;
|
|
79
77
|
toRdfTypes: readonly import("@rdfjs/types").NamedNode<string>[] | undefined;
|
|
80
78
|
comment: string | undefined;
|
package/dist/ast/Ast.d.ts
CHANGED
|
@@ -3,8 +3,6 @@ import type { ObjectType } from "./ObjectType.js";
|
|
|
3
3
|
import type { UnionType } from "./UnionType.js";
|
|
4
4
|
export interface Ast {
|
|
5
5
|
readonly lazyTypesCount: number;
|
|
6
|
-
readonly
|
|
7
|
-
readonly namedObjectTypes: readonly ObjectType[];
|
|
8
|
-
readonly namedUnionTypes: readonly UnionType[];
|
|
6
|
+
readonly namedTypes: readonly (IntersectionType | ObjectType | UnionType)[];
|
|
9
7
|
}
|
|
10
8
|
//# sourceMappingURL=Ast.d.ts.map
|
package/dist/ast/ListType.d.ts
CHANGED
|
@@ -38,7 +38,7 @@ export declare class ListType<ItemTypeT extends ListType.ItemType = ListType.Ite
|
|
|
38
38
|
equals(other: ListType<ItemTypeT>): boolean;
|
|
39
39
|
}
|
|
40
40
|
export declare namespace ListType {
|
|
41
|
-
type ItemType = BlankNodeType | IdentifierType | IntersectionType | IriType | LiteralType | ObjectType | TermType | UnionType;
|
|
41
|
+
type ItemType = BlankNodeType | IdentifierType | IntersectionType | IriType | ListType | LiteralType | ObjectType | TermType | UnionType;
|
|
42
42
|
function isItemType(type: Type): type is ItemType;
|
|
43
43
|
}
|
|
44
44
|
//# sourceMappingURL=ListType.d.ts.map
|
package/dist/ast/ListType.js
CHANGED
|
@@ -36,6 +36,7 @@ export class ListType extends AbstractCollectionType {
|
|
|
36
36
|
case "Identifier":
|
|
37
37
|
case "Intersection":
|
|
38
38
|
case "Iri":
|
|
39
|
+
case "List":
|
|
39
40
|
case "Literal":
|
|
40
41
|
case "Object":
|
|
41
42
|
case "Term":
|
|
@@ -45,7 +46,6 @@ export class ListType extends AbstractCollectionType {
|
|
|
45
46
|
case "LazyObjectOption":
|
|
46
47
|
case "LazyObjectSet":
|
|
47
48
|
case "LazyObject":
|
|
48
|
-
case "List":
|
|
49
49
|
case "Option":
|
|
50
50
|
case "Set":
|
|
51
51
|
return false;
|
package/dist/ast/ObjectType.d.ts
CHANGED
|
@@ -59,16 +59,8 @@ export declare class ObjectType extends AbstractType {
|
|
|
59
59
|
toRdfTypes: readonly NamedNode[];
|
|
60
60
|
tsImports: readonly string[];
|
|
61
61
|
} & ConstructorParameters<typeof AbstractType>[0]);
|
|
62
|
-
get ancestorObjectTypes(): readonly ObjectType[];
|
|
63
|
-
get childObjectTypes(): readonly ObjectType[];
|
|
64
|
-
get descendantObjectTypes(): readonly ObjectType[];
|
|
65
|
-
get parentObjectTypes(): readonly ObjectType[];
|
|
66
62
|
get properties(): readonly ObjectType.Property[];
|
|
67
63
|
get recursive(): boolean;
|
|
68
|
-
addAncestorObjectTypes(...ancestorObjectTypes: readonly ObjectType[]): void;
|
|
69
|
-
addChildObjectTypes(...childObjectTypes: readonly ObjectType[]): void;
|
|
70
|
-
addDescendantObjectTypes(...descendantObjectTypes: readonly ObjectType[]): void;
|
|
71
|
-
addParentObjectTypes(...parentObjectTypes: readonly ObjectType[]): void;
|
|
72
64
|
addProperties(...properties: readonly ObjectType.Property[]): void;
|
|
73
65
|
equals(other: ObjectType): boolean;
|
|
74
66
|
sortProperties(): void;
|
|
@@ -85,7 +77,6 @@ export declare class ObjectType extends AbstractType {
|
|
|
85
77
|
recursive: boolean | undefined;
|
|
86
78
|
shapeIdentifier: BlankNode | NamedNode<string>;
|
|
87
79
|
};
|
|
88
|
-
parentObjectTypes: (string | BlankNode | NamedNode<string>)[] | undefined;
|
|
89
80
|
synthetic: boolean | undefined;
|
|
90
81
|
toRdfTypes: readonly NamedNode<string>[] | undefined;
|
|
91
82
|
comment: string | undefined;
|
|
@@ -183,7 +174,4 @@ export declare namespace ObjectType {
|
|
|
183
174
|
toString(): string;
|
|
184
175
|
}
|
|
185
176
|
}
|
|
186
|
-
export declare namespace ObjectType {
|
|
187
|
-
function toposort(objectTypes: readonly ObjectType[]): readonly ObjectType[];
|
|
188
|
-
}
|
|
189
177
|
//# sourceMappingURL=ObjectType.d.ts.map
|