@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,58 @@
|
|
|
1
|
+
import { invariant } from "ts-invariant";
|
|
2
|
+
import * as input from "../input/index.js";
|
|
3
|
+
/**
|
|
4
|
+
* Try to convert a property shape to a type using some heuristics.
|
|
5
|
+
*
|
|
6
|
+
* 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
|
|
7
|
+
* a shape has one type.
|
|
8
|
+
*/
|
|
9
|
+
export function transformPropertyShapeToAstType(shape, inherited) {
|
|
10
|
+
// Try to transform the property shape into an AST type without cardinality constraints
|
|
11
|
+
return this.transformPropertyShapeToAstCompositeType(shape, inherited)
|
|
12
|
+
.altLazy(() => this.transformPropertyShapeToAstIdentifierType(shape, inherited))
|
|
13
|
+
.altLazy(() => this.transformPropertyShapeToAstLiteralType(shape, inherited))
|
|
14
|
+
.altLazy(() => this.transformPropertyShapeToAstTermType(shape, inherited))
|
|
15
|
+
.map((itemType) => {
|
|
16
|
+
// Handle cardinality constraints
|
|
17
|
+
if ((shape instanceof input.PropertyShape && shape.defaultValue.isJust()) ||
|
|
18
|
+
inherited?.defaultValue.isJust()) {
|
|
19
|
+
// Ignore other cardinality constraints if there's a default value and treat the type as minCount=maxCount=1
|
|
20
|
+
return itemType;
|
|
21
|
+
}
|
|
22
|
+
const maxCount = shape.constraints.maxCount;
|
|
23
|
+
const minCount = shape.constraints.minCount;
|
|
24
|
+
if (maxCount.isNothing() && minCount.isNothing()) {
|
|
25
|
+
// The shape has no cardinality constraints
|
|
26
|
+
if (inherited === null) {
|
|
27
|
+
// The shape is top-level (not an sh:xone/sh:and of a top-level shape)
|
|
28
|
+
// Treat it as a Set, the default in RDF.
|
|
29
|
+
// We want Set to be the outermost type unless it's explicitly requested with sh:minCount 0.
|
|
30
|
+
return {
|
|
31
|
+
itemType,
|
|
32
|
+
kind: "SetType",
|
|
33
|
+
minCount: 0,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
// else the shape is not top-level
|
|
37
|
+
// We want Set to be the outermost type, so just return the itemType here
|
|
38
|
+
return itemType;
|
|
39
|
+
}
|
|
40
|
+
if (minCount.orDefault(0) === 0 && maxCount.extractNullable() === 1) {
|
|
41
|
+
return {
|
|
42
|
+
itemType,
|
|
43
|
+
kind: "OptionType",
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
if (minCount.orDefault(0) === 1 && maxCount.extractNullable() === 1) {
|
|
47
|
+
return itemType;
|
|
48
|
+
}
|
|
49
|
+
invariant(minCount.isJust() || maxCount.isJust());
|
|
50
|
+
// There are cardinality constraints for a Set. It may be an inner type.
|
|
51
|
+
return {
|
|
52
|
+
itemType,
|
|
53
|
+
kind: "SetType",
|
|
54
|
+
minCount: minCount.orDefault(0),
|
|
55
|
+
};
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=transformPropertyShapeToAstType.js.map
|
package/ast/Ast.d.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
|
+
import type { ObjectIntersectionType } from "./ObjectIntersectionType.js";
|
|
1
2
|
import type { ObjectType } from "./ObjectType.js";
|
|
3
|
+
import type { ObjectUnionType } from "./ObjectUnionType.js";
|
|
2
4
|
export interface Ast {
|
|
5
|
+
readonly objectIntersectionTypes: readonly ObjectIntersectionType[];
|
|
3
6
|
readonly objectTypes: readonly ObjectType[];
|
|
7
|
+
readonly objectUnionTypes: readonly ObjectUnionType[];
|
|
8
|
+
readonly tsDataFactoryVariable: string;
|
|
4
9
|
}
|
|
5
10
|
//# sourceMappingURL=Ast.d.ts.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Type } from "./Type.js";
|
|
2
|
+
/**
|
|
3
|
+
* A composite of types, such as an intersection or union.
|
|
4
|
+
*/
|
|
5
|
+
export interface CompositeType<MemberTypeT extends Type> {
|
|
6
|
+
/**
|
|
7
|
+
* Member types.
|
|
8
|
+
*
|
|
9
|
+
* Mutable to support cycle-handling logic in the compiler.
|
|
10
|
+
*/
|
|
11
|
+
readonly memberTypes: MemberTypeT[];
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=CompositeType.d.ts.map
|
package/ast/IdentifierType.d.ts
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
import type { BlankNode, NamedNode } from "@rdfjs/types";
|
|
2
|
-
import type {
|
|
3
|
-
import type { Maybe } from "purify-ts";
|
|
2
|
+
import type { TermType } from "./TermType.js";
|
|
4
3
|
/**
|
|
5
4
|
* A type corresponding to sh:nodeKind of a blank node or IRI, and not corresponding to a node shape.
|
|
6
5
|
*/
|
|
7
|
-
export interface IdentifierType {
|
|
8
|
-
readonly defaultValue: Maybe<BlankNode | NamedNode>;
|
|
9
|
-
readonly hasValue: Maybe<BlankNode | NamedNode>;
|
|
6
|
+
export interface IdentifierType extends TermType<BlankNode | NamedNode> {
|
|
10
7
|
readonly kind: "IdentifierType";
|
|
11
|
-
readonly nodeKinds: Set<
|
|
8
|
+
readonly nodeKinds: Set<"BlankNode" | "NamedNode">;
|
|
12
9
|
}
|
|
13
10
|
//# sourceMappingURL=IdentifierType.d.ts.map
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import type { CompositeType } from "./CompositeType.js";
|
|
1
2
|
import type { Type } from "./Type.js";
|
|
2
3
|
/**
|
|
3
4
|
* A conjunction ("and") of types, corresponding to an sh:and.
|
|
4
5
|
*/
|
|
5
|
-
export interface IntersectionType {
|
|
6
|
+
export interface IntersectionType extends CompositeType<Type> {
|
|
6
7
|
readonly kind: "IntersectionType";
|
|
7
|
-
readonly memberTypes: readonly Type[];
|
|
8
8
|
}
|
|
9
9
|
//# sourceMappingURL=IntersectionType.d.ts.map
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { NamedNode } from "@rdfjs/types";
|
|
2
|
+
import type { Maybe } from "purify-ts";
|
|
3
|
+
import type { MintingStrategy } from "../enums/MintingStrategy.js";
|
|
4
|
+
import type { Name } from "./Name.js";
|
|
5
|
+
import type { Type } from "./Type.js";
|
|
6
|
+
/**
|
|
7
|
+
* An ordered sequence of items with zero or one values of an item type.
|
|
8
|
+
*
|
|
9
|
+
* ListType is transformed from a SHACL node shape that models an RDF list (https://www.w3.org/TR/rdf11-schema/#ch_collectionvocab).
|
|
10
|
+
*
|
|
11
|
+
* Contrast SetType, which is transformed from any SHACL property shape with no maxCount or maxCount greater than 1.
|
|
12
|
+
*/
|
|
13
|
+
export interface ListType {
|
|
14
|
+
/**
|
|
15
|
+
* Documentation comment from rdfs:comment.
|
|
16
|
+
*/
|
|
17
|
+
readonly comment: Maybe<string>;
|
|
18
|
+
/**
|
|
19
|
+
* Type of identifier (blank or named node) to use for lists and sub-lists.
|
|
20
|
+
*/
|
|
21
|
+
readonly identifierNodeKind: "BlankNode" | "NamedNode";
|
|
22
|
+
/**
|
|
23
|
+
* List item type.
|
|
24
|
+
*
|
|
25
|
+
* Mutable to support cycle-handling logic in the compiler.
|
|
26
|
+
*/
|
|
27
|
+
itemType: Type;
|
|
28
|
+
readonly kind: "ListType";
|
|
29
|
+
/**
|
|
30
|
+
* Human-readable label from rdfs:label.
|
|
31
|
+
*/
|
|
32
|
+
readonly label: Maybe<string>;
|
|
33
|
+
/**
|
|
34
|
+
* Strategy for minting new list and sub-list identifiers.
|
|
35
|
+
*/
|
|
36
|
+
readonly mintingStrategy: Maybe<MintingStrategy>;
|
|
37
|
+
/**
|
|
38
|
+
* The list should be mutable in generated code.
|
|
39
|
+
*/
|
|
40
|
+
readonly mutable: Maybe<boolean>;
|
|
41
|
+
/**
|
|
42
|
+
* Name of this type, usually derived from sh:name or shaclmate:name.
|
|
43
|
+
*/
|
|
44
|
+
readonly name: Name;
|
|
45
|
+
/**
|
|
46
|
+
* rdf:type's that will be added to this object when it's serialized toRdf.
|
|
47
|
+
*
|
|
48
|
+
* This is usually the identifier of an sh:NodeShape that is also an rdfs:Class (i.e., a node shape with implicit
|
|
49
|
+
* class targets).
|
|
50
|
+
*/
|
|
51
|
+
readonly toRdfTypes: readonly NamedNode[];
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=ListType.d.ts.map
|
package/ast/ListType.js
ADDED
package/ast/LiteralType.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import type { Literal, NamedNode } from "@rdfjs/types";
|
|
2
2
|
import type { Maybe } from "purify-ts";
|
|
3
|
-
|
|
3
|
+
import type { TermType } from "./TermType.js";
|
|
4
|
+
export interface LiteralType extends TermType<Literal> {
|
|
4
5
|
readonly datatype: Maybe<NamedNode>;
|
|
5
|
-
readonly defaultValue: Maybe<Literal>;
|
|
6
|
-
readonly hasValue: Maybe<Literal>;
|
|
7
6
|
readonly kind: "LiteralType";
|
|
7
|
+
readonly languageIn: readonly string[];
|
|
8
8
|
readonly maxExclusive: Maybe<Literal>;
|
|
9
9
|
readonly maxInclusive: Maybe<Literal>;
|
|
10
10
|
readonly minExclusive: Maybe<Literal>;
|
|
11
11
|
readonly minInclusive: Maybe<Literal>;
|
|
12
|
+
readonly nodeKinds: Set<"Literal">;
|
|
12
13
|
}
|
|
13
14
|
//# sourceMappingURL=LiteralType.d.ts.map
|
package/ast/Name.d.ts
CHANGED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Maybe } from "purify-ts";
|
|
2
|
+
import type { CompositeType } from "./CompositeType.js";
|
|
3
|
+
import type { Name } from "./Name.js";
|
|
4
|
+
import type { ObjectType } from "./ObjectType.js";
|
|
5
|
+
/**
|
|
6
|
+
* A composite of object types, such as an intersection or union.
|
|
7
|
+
*/
|
|
8
|
+
export interface ObjectCompositeType extends CompositeType<ObjectType> {
|
|
9
|
+
/**
|
|
10
|
+
* Documentation comment from rdfs:comment.
|
|
11
|
+
*/
|
|
12
|
+
readonly comment: Maybe<string>;
|
|
13
|
+
/**
|
|
14
|
+
* Human-readable label from rdfs:label.
|
|
15
|
+
*/
|
|
16
|
+
readonly label: Maybe<string>;
|
|
17
|
+
/**
|
|
18
|
+
* Name of this type, usually derived from sh:name or shaclmate:name.
|
|
19
|
+
*/
|
|
20
|
+
readonly name: Name;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=ObjectCompositeType.d.ts.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ObjectCompositeType } from "./ObjectCompositeType.js";
|
|
2
|
+
/**
|
|
3
|
+
* A conjunction/intersection of object types, corresponding to an sh:and on a node shape.
|
|
4
|
+
*/
|
|
5
|
+
export interface ObjectIntersectionType extends ObjectCompositeType {
|
|
6
|
+
readonly kind: "ObjectIntersectionType";
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=ObjectIntersectionType.d.ts.map
|
package/ast/ObjectType.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { NamedNode } from "@rdfjs/types";
|
|
2
|
-
import type { NodeKind } from "@shaclmate/shacl-ast";
|
|
3
2
|
import type { PredicatePath } from "@shaclmate/shacl-ast";
|
|
4
3
|
import type { Maybe } from "purify-ts";
|
|
5
|
-
import type {
|
|
6
|
-
import type {
|
|
4
|
+
import type { MintingStrategy, PropertyVisibility, TsFeature, TsObjectDeclarationType } from "../enums/index.js";
|
|
5
|
+
import type { Name } from "./Name.js";
|
|
6
|
+
import type { Type } from "./Type.js";
|
|
7
7
|
export interface ObjectType {
|
|
8
8
|
/**
|
|
9
9
|
* Classes generated from this type are abstract / cannot be instantiated themselves.
|
|
@@ -14,19 +14,23 @@ export interface ObjectType {
|
|
|
14
14
|
/**
|
|
15
15
|
* Ancestor (parents, their parents, ad nauseum) ObjectTypes of this ObjectType.
|
|
16
16
|
*
|
|
17
|
-
* Mutable to support cycle-handling logic in the
|
|
17
|
+
* Mutable to support cycle-handling logic in the compiler.
|
|
18
18
|
*/
|
|
19
19
|
readonly ancestorObjectTypes: ObjectType[];
|
|
20
20
|
/**
|
|
21
21
|
* Immediate child ObjectTypes of this ObjectType.
|
|
22
22
|
*
|
|
23
|
-
* Mutable to support cycle-handling logic in the
|
|
23
|
+
* Mutable to support cycle-handling logic in the compiler.
|
|
24
24
|
*/
|
|
25
25
|
readonly childObjectTypes: ObjectType[];
|
|
26
|
+
/**
|
|
27
|
+
* Documentation comment from rdfs:comment.
|
|
28
|
+
*/
|
|
29
|
+
readonly comment: Maybe<string>;
|
|
26
30
|
/**
|
|
27
31
|
* Descendant (children, their children, ad nauseum) ObjectTypes of this ObjectType.
|
|
28
32
|
*
|
|
29
|
-
* Mutable to support cycle-handling logic in the
|
|
33
|
+
* Mutable to support cycle-handling logic in the compiler.
|
|
30
34
|
*/
|
|
31
35
|
readonly descendantObjectTypes: ObjectType[];
|
|
32
36
|
/**
|
|
@@ -35,20 +39,33 @@ export interface ObjectType {
|
|
|
35
39
|
* Defaults to true.
|
|
36
40
|
*/
|
|
37
41
|
readonly export: boolean;
|
|
38
|
-
readonly kind: "ObjectType";
|
|
39
42
|
/**
|
|
40
|
-
* If the ObjectType is
|
|
41
|
-
*
|
|
43
|
+
* If true, the code for this ObjectType is defined externally and should not be generated.
|
|
44
|
+
*
|
|
45
|
+
* Defaults to false.
|
|
46
|
+
*/
|
|
47
|
+
readonly extern: boolean;
|
|
48
|
+
/**
|
|
49
|
+
* The expected rdf:type of instances of this ObjectType.
|
|
42
50
|
*
|
|
43
|
-
*
|
|
51
|
+
* This is usually the identifier of an sh:NodeShape that is also an rdfs:Class (i.e., a node shape with implicit
|
|
52
|
+
* class targets).
|
|
53
|
+
*/
|
|
54
|
+
readonly fromRdfType: Maybe<NamedNode>;
|
|
55
|
+
/**
|
|
56
|
+
* Type discriminator.
|
|
57
|
+
*/
|
|
58
|
+
readonly kind: "ObjectType";
|
|
59
|
+
/**
|
|
60
|
+
* Human-readable label from rdfs:label.
|
|
44
61
|
*/
|
|
45
|
-
|
|
62
|
+
readonly label: Maybe<string>;
|
|
46
63
|
/**
|
|
47
|
-
* Strategy for minting new object identifiers.
|
|
64
|
+
* Strategy for minting new object identifiers.
|
|
48
65
|
*/
|
|
49
66
|
readonly mintingStrategy: Maybe<MintingStrategy>;
|
|
50
67
|
/**
|
|
51
|
-
* Name of this
|
|
68
|
+
* Name of this type, usually derived from sh:name or shaclmate:name.
|
|
52
69
|
*/
|
|
53
70
|
readonly name: Name;
|
|
54
71
|
/**
|
|
@@ -56,33 +73,88 @@ export interface ObjectType {
|
|
|
56
73
|
*
|
|
57
74
|
* Used to associate instances with an RDF identifier.
|
|
58
75
|
*/
|
|
59
|
-
readonly nodeKinds: Set<
|
|
76
|
+
readonly nodeKinds: Set<"BlankNode" | "NamedNode">;
|
|
60
77
|
/**
|
|
61
78
|
* Immediate parent ObjectTypes of this Object types.
|
|
62
79
|
*
|
|
63
|
-
* Mutable to support cycle-handling logic in the
|
|
80
|
+
* Mutable to support cycle-handling logic in the compiler.
|
|
64
81
|
*/
|
|
65
82
|
readonly parentObjectTypes: ObjectType[];
|
|
66
83
|
/**
|
|
67
84
|
* Properties of this ObjectType.
|
|
68
85
|
*
|
|
69
|
-
* Mutable to support cycle-handling logic in the
|
|
86
|
+
* Mutable to support cycle-handling logic in the compiler.
|
|
70
87
|
*/
|
|
71
88
|
readonly properties: ObjectType.Property[];
|
|
72
89
|
/**
|
|
73
|
-
*
|
|
90
|
+
* rdf:type's that will be added to this object when it's serialized toRdf.
|
|
74
91
|
*
|
|
75
92
|
* This is usually the identifier of an sh:NodeShape that is also an rdfs:Class (i.e., a node shape with implicit
|
|
76
93
|
* class targets).
|
|
77
94
|
*/
|
|
78
|
-
readonly
|
|
95
|
+
readonly toRdfTypes: readonly NamedNode[];
|
|
96
|
+
/**
|
|
97
|
+
* TypeScript features to generate.
|
|
98
|
+
*/
|
|
99
|
+
readonly tsFeatures: Set<TsFeature>;
|
|
100
|
+
/**
|
|
101
|
+
* Name of the identifier property in TypeScript-generated classes/interfaces.
|
|
102
|
+
*/
|
|
103
|
+
readonly tsIdentifierPropertyName: string;
|
|
104
|
+
/**
|
|
105
|
+
* TypeScript imports to add to generated code.
|
|
106
|
+
*
|
|
107
|
+
* This is often used in conjunction with extern=true to import the extern'd ObjectType code in order for generated
|
|
108
|
+
* code to reference it.
|
|
109
|
+
*
|
|
110
|
+
* import { MyType } from "./MyType.js"
|
|
111
|
+
*/
|
|
112
|
+
readonly tsImports: readonly string[];
|
|
113
|
+
/**
|
|
114
|
+
* Whether to generate a TypeScript class or interface for this type.
|
|
115
|
+
*/
|
|
116
|
+
readonly tsObjectDeclarationType: TsObjectDeclarationType;
|
|
117
|
+
/**
|
|
118
|
+
* Name of the type discriminator property in TypeScript-generated classes/interfaces.
|
|
119
|
+
*/
|
|
120
|
+
readonly tsTypeDiscriminatorPropertyName: string;
|
|
79
121
|
}
|
|
80
122
|
export declare namespace ObjectType {
|
|
81
123
|
interface Property {
|
|
82
|
-
|
|
124
|
+
/**
|
|
125
|
+
* Documentation comment from rdfs:comment.
|
|
126
|
+
*/
|
|
127
|
+
readonly comment: Maybe<string>;
|
|
128
|
+
/**
|
|
129
|
+
* Description from sh:description.
|
|
130
|
+
*/
|
|
131
|
+
readonly description: Maybe<string>;
|
|
132
|
+
/**
|
|
133
|
+
* Human-readable label from rdfs:label.
|
|
134
|
+
*/
|
|
135
|
+
readonly label: Maybe<string>;
|
|
136
|
+
/**
|
|
137
|
+
* The property should be mutable in generated code i.e., it should be re-assignable. The property value may or may
|
|
138
|
+
* not be mutable.
|
|
139
|
+
*/
|
|
140
|
+
readonly mutable: Maybe<boolean>;
|
|
141
|
+
/**
|
|
142
|
+
* Name of this property.
|
|
143
|
+
*/
|
|
83
144
|
readonly name: Name;
|
|
145
|
+
/**
|
|
146
|
+
* SHACL property path (https://www.w3.org/TR/shacl/#property-paths)
|
|
147
|
+
*/
|
|
84
148
|
readonly path: PredicatePath;
|
|
149
|
+
/**
|
|
150
|
+
* Type of this property.
|
|
151
|
+
*/
|
|
85
152
|
readonly type: Type;
|
|
153
|
+
/**
|
|
154
|
+
* Visibility: private, protected, public.
|
|
155
|
+
*/
|
|
156
|
+
readonly visibility: PropertyVisibility;
|
|
86
157
|
}
|
|
158
|
+
function toposort(objectTypes: readonly ObjectType[]): readonly ObjectType[];
|
|
87
159
|
}
|
|
88
160
|
//# sourceMappingURL=ObjectType.d.ts.map
|
package/ast/ObjectType.js
CHANGED
|
@@ -1,2 +1,27 @@
|
|
|
1
|
-
|
|
1
|
+
import { Resource } from "rdfjs-resource";
|
|
2
|
+
import genericToposort from "toposort";
|
|
3
|
+
export var ObjectType;
|
|
4
|
+
(function (ObjectType) {
|
|
5
|
+
function toposort(objectTypes) {
|
|
6
|
+
const objectTypesByIdentifier = {};
|
|
7
|
+
const objectTypeGraphNodes = [];
|
|
8
|
+
const objectTypeGraphEdges = [];
|
|
9
|
+
for (const objectType of objectTypes) {
|
|
10
|
+
const objectTypeIdentifier = Resource.Identifier.toString(objectType.name.identifier);
|
|
11
|
+
objectTypesByIdentifier[objectTypeIdentifier] = objectType;
|
|
12
|
+
objectTypeGraphNodes.push(objectTypeIdentifier);
|
|
13
|
+
for (const parentAstObjectType of objectType.parentObjectTypes) {
|
|
14
|
+
objectTypeGraphEdges.push([
|
|
15
|
+
objectTypeIdentifier,
|
|
16
|
+
Resource.Identifier.toString(parentAstObjectType.name.identifier),
|
|
17
|
+
]);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return genericToposort
|
|
21
|
+
.array(objectTypeGraphNodes, objectTypeGraphEdges)
|
|
22
|
+
.map((objectTypeIdentifier) => objectTypesByIdentifier[objectTypeIdentifier])
|
|
23
|
+
.reverse();
|
|
24
|
+
}
|
|
25
|
+
ObjectType.toposort = toposort;
|
|
26
|
+
})(ObjectType || (ObjectType = {}));
|
|
2
27
|
//# sourceMappingURL=ObjectType.js.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { TsFeature } from "../enums/index.js";
|
|
2
|
+
import type { ObjectCompositeType } from "./ObjectCompositeType.js";
|
|
3
|
+
/**
|
|
4
|
+
* A disjunction/union of object types, corresponding to an sh:xone on a node shape.
|
|
5
|
+
*/
|
|
6
|
+
export interface ObjectUnionType extends ObjectCompositeType {
|
|
7
|
+
/**
|
|
8
|
+
* Should generated code derived from this ObjectType be visible outside its module?
|
|
9
|
+
*
|
|
10
|
+
* Defaults to true.
|
|
11
|
+
*/
|
|
12
|
+
readonly export: boolean;
|
|
13
|
+
readonly kind: "ObjectUnionType";
|
|
14
|
+
/**
|
|
15
|
+
* TypeScript features to generate.
|
|
16
|
+
*/
|
|
17
|
+
readonly tsFeatures: Set<TsFeature>;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=ObjectUnionType.d.ts.map
|
package/ast/SetType.d.ts
CHANGED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { BlankNode, Literal, NamedNode } from "@rdfjs/types";
|
|
2
|
+
import type { NodeKind } from "@shaclmate/shacl-ast";
|
|
3
|
+
import type { Maybe } from "purify-ts";
|
|
4
|
+
export interface TermType<TermT extends BlankNode | Literal | NamedNode> {
|
|
5
|
+
readonly defaultValue: Maybe<TermT>;
|
|
6
|
+
readonly hasValues: readonly TermT[];
|
|
7
|
+
readonly in_: readonly TermT[];
|
|
8
|
+
readonly kind: "IdentifierType" | "LiteralType" | "TermType";
|
|
9
|
+
readonly nodeKinds: Set<NodeKind>;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=TermType.d.ts.map
|
package/ast/TermType.js
ADDED
package/ast/Type.d.ts
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
|
+
import type { BlankNode, Literal, NamedNode } from "@rdfjs/types";
|
|
1
2
|
import type { IdentifierType } from "./IdentifierType.js";
|
|
2
3
|
import type { IntersectionType } from "./IntersectionType.js";
|
|
4
|
+
import type { ListType } from "./ListType.js";
|
|
3
5
|
import type { LiteralType } from "./LiteralType.js";
|
|
6
|
+
import type { ObjectIntersectionType } from "./ObjectIntersectionType.js";
|
|
4
7
|
import type { ObjectType } from "./ObjectType.js";
|
|
5
|
-
import type {
|
|
6
|
-
import type {
|
|
8
|
+
import type { ObjectUnionType } from "./ObjectUnionType.js";
|
|
9
|
+
import type { OptionType } from "./OptionType.js";
|
|
10
|
+
import type { PlaceholderType } from "./PlaceholderType.js";
|
|
11
|
+
import type { SetType } from "./SetType.js";
|
|
12
|
+
import type { TermType } from "./TermType.js";
|
|
7
13
|
import type { UnionType } from "./UnionType.js";
|
|
8
|
-
export type Type = IdentifierType | IntersectionType | LiteralType | ObjectType | OptionType | SetType |
|
|
14
|
+
export type Type = IdentifierType | IntersectionType | ListType | LiteralType | ObjectIntersectionType | ObjectType | ObjectUnionType | OptionType | PlaceholderType | SetType | (Omit<TermType<BlankNode | Literal | NamedNode>, "kind"> & {
|
|
15
|
+
readonly kind: "TermType";
|
|
16
|
+
}) | UnionType;
|
|
9
17
|
//# sourceMappingURL=Type.d.ts.map
|
package/ast/UnionType.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import type { CompositeType } from "./CompositeType.js";
|
|
1
2
|
import type { Type } from "./Type.js";
|
|
2
3
|
/**
|
|
3
|
-
* A disjunction/union of types, corresponding to an sh:
|
|
4
|
+
* A disjunction/union of types, corresponding to an sh:xone.
|
|
4
5
|
*/
|
|
5
|
-
export interface UnionType {
|
|
6
|
+
export interface UnionType extends CompositeType<Type> {
|
|
6
7
|
readonly kind: "UnionType";
|
|
7
|
-
readonly memberTypes: readonly Type[];
|
|
8
8
|
}
|
|
9
9
|
//# sourceMappingURL=UnionType.d.ts.map
|
package/ast/index.d.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
export * from "./Ast.js";
|
|
2
2
|
export * from "./IdentifierType.js";
|
|
3
|
-
export * from "./IntersectionType";
|
|
3
|
+
export * from "./IntersectionType.js";
|
|
4
|
+
export * from "./ListType.js";
|
|
4
5
|
export * from "./LiteralType.js";
|
|
5
|
-
export * from "./MintingStrategy.js";
|
|
6
6
|
export * from "./Name.js";
|
|
7
|
+
export * from "./ObjectIntersectionType.js";
|
|
7
8
|
export * from "./ObjectType.js";
|
|
8
|
-
export * from "./
|
|
9
|
+
export * from "./ObjectUnionType.js";
|
|
10
|
+
export * from "./UnionType.js";
|
|
11
|
+
export * from "./TermType.js";
|
|
9
12
|
export * from "./Type.js";
|
|
10
13
|
//# sourceMappingURL=index.d.ts.map
|
package/ast/index.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
export * from "./Ast.js";
|
|
2
2
|
export * from "./IdentifierType.js";
|
|
3
|
-
export * from "./IntersectionType";
|
|
3
|
+
export * from "./IntersectionType.js";
|
|
4
|
+
export * from "./ListType.js";
|
|
4
5
|
export * from "./LiteralType.js";
|
|
5
|
-
export * from "./MintingStrategy.js";
|
|
6
6
|
export * from "./Name.js";
|
|
7
|
+
export * from "./ObjectIntersectionType.js";
|
|
7
8
|
export * from "./ObjectType.js";
|
|
8
|
-
export * from "./
|
|
9
|
+
export * from "./ObjectUnionType.js";
|
|
10
|
+
export * from "./UnionType.js";
|
|
11
|
+
export * from "./TermType.js";
|
|
9
12
|
export * from "./Type.js";
|
|
10
13
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export var TsFeature;
|
|
2
|
+
(function (TsFeature) {
|
|
3
|
+
TsFeature.MEMBERS = [
|
|
4
|
+
"create",
|
|
5
|
+
"equals",
|
|
6
|
+
"fromJson",
|
|
7
|
+
"fromRdf",
|
|
8
|
+
"hash",
|
|
9
|
+
"jsonSchema",
|
|
10
|
+
"jsonUiSchema",
|
|
11
|
+
"sparql",
|
|
12
|
+
"toJson",
|
|
13
|
+
"toRdf",
|
|
14
|
+
];
|
|
15
|
+
})(TsFeature || (TsFeature = {}));
|
|
16
|
+
//# sourceMappingURL=TsFeature.js.map
|