@shaclmate/compiler 2.0.15 → 2.0.17
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.js → dist/Compiler.js} +2 -0
- package/{ShapesGraphToAstTransformer.js → dist/ShapesGraphToAstTransformer.js} +13 -11
- package/{_ShapesGraphToAstTransformer → dist/_ShapesGraphToAstTransformer}/transformNodeShapeToAstType.js +8 -4
- package/{_ShapesGraphToAstTransformer → dist/_ShapesGraphToAstTransformer}/transformPropertyShapeToAstCompositeType.js +2 -2
- package/{_ShapesGraphToAstTransformer → dist/_ShapesGraphToAstTransformer}/transformPropertyShapeToAstType.js +2 -0
- package/{ast → dist/ast}/ListType.d.ts +2 -2
- package/{ast → dist/ast}/ObjectType.d.ts +18 -12
- package/dist/ast/SetType.d.ts +23 -0
- package/dist/enums/IdentifierMintingStrategy.d.ts +5 -0
- package/dist/enums/IdentifierMintingStrategy.js +2 -0
- package/{enums → dist/enums}/index.d.ts +1 -1
- package/{enums → dist/enums}/index.js +1 -1
- package/{generators → dist/generators}/index.d.ts +1 -0
- package/{generators → dist/generators}/index.js +1 -0
- package/{generators → dist/generators}/json/AstJsonGenerator.js +5 -1
- package/{generators → dist/generators}/ts/BooleanType.js +1 -4
- package/{generators → dist/generators}/ts/DateTimeType.d.ts +4 -1
- package/{generators → dist/generators}/ts/DateTimeType.js +11 -10
- package/dist/generators/ts/DateType.d.ts +9 -0
- package/dist/generators/ts/DateType.js +11 -0
- package/{generators → dist/generators}/ts/DeclaredType.js +3 -0
- package/{generators → dist/generators}/ts/IdentifierType.d.ts +2 -0
- package/{generators → dist/generators}/ts/IdentifierType.js +11 -3
- package/{generators → dist/generators}/ts/ListType.d.ts +6 -5
- package/{generators → dist/generators}/ts/ListType.js +28 -14
- package/{generators → dist/generators}/ts/LiteralType.js +1 -0
- package/{generators → dist/generators}/ts/NumberType.js +1 -4
- package/{generators → dist/generators}/ts/ObjectType.d.ts +4 -4
- package/{generators → dist/generators}/ts/ObjectType.js +17 -3
- package/{generators → dist/generators}/ts/ObjectUnionType.js +13 -8
- package/{generators → dist/generators}/ts/OptionType.js +5 -2
- package/{generators → dist/generators}/ts/PrimitiveType.js +3 -1
- package/{generators → dist/generators}/ts/SetType.d.ts +3 -1
- package/{generators → dist/generators}/ts/SetType.js +16 -10
- package/{generators → dist/generators}/ts/StringType.js +1 -4
- package/{generators → dist/generators}/ts/TermType.js +9 -5
- package/{generators → dist/generators}/ts/Type.js +1 -0
- package/{generators → dist/generators}/ts/TypeFactory.js +12 -9
- package/{generators → dist/generators}/ts/UnionType.js +3 -1
- package/{generators → dist/generators}/ts/_ObjectType/IdentifierProperty.d.ts +5 -5
- package/{generators → dist/generators}/ts/_ObjectType/IdentifierProperty.js +91 -21
- package/{generators → dist/generators}/ts/_ObjectType/Property.js +14 -0
- package/{generators → dist/generators}/ts/_ObjectType/ShaclProperty.js +5 -0
- package/{generators → dist/generators}/ts/_ObjectType/TypeDiscriminatorProperty.js +7 -2
- package/dist/generators/ts/_ObjectType/fromRdfTypeVariableStatement.d.ts +5 -0
- package/dist/generators/ts/_ObjectType/fromRdfTypeVariableStatement.js +25 -0
- package/{generators → dist/generators}/ts/_ObjectType/index.d.ts +1 -0
- package/{generators → dist/generators}/ts/_ObjectType/index.js +1 -0
- package/{generators → dist/generators}/ts/_ObjectType/toRdfFunctionOrMethodDeclaration.js +3 -3
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/{input → dist/input}/NodeShape.d.ts +2 -2
- package/{input → dist/input}/NodeShape.js +11 -4
- package/{input → dist/input}/Ontology.js +1 -0
- package/{input → dist/input}/PropertyShape.js +1 -0
- package/{input → dist/input}/generated.d.ts +19 -12
- package/{input → dist/input}/generated.js +51 -22
- package/dist/input/tsFeatures.d.ts +10 -0
- package/{input → dist/input}/tsFeatures.js +4 -0
- package/package.json +28 -24
- package/ast/SetType.d.ts +0 -12
- package/enums/MintingStrategy.d.ts +0 -5
- package/enums/MintingStrategy.js +0 -2
- package/index.d.ts +0 -2
- package/index.js +0 -2
- package/input/tsFeatures.d.ts +0 -10
- /package/{Compiler.d.ts → dist/Compiler.d.ts} +0 -0
- /package/{ShapesGraphToAstTransformer.d.ts → dist/ShapesGraphToAstTransformer.d.ts} +0 -0
- /package/{_ShapesGraphToAstTransformer → dist/_ShapesGraphToAstTransformer}/NodeShapeAstType.d.ts +0 -0
- /package/{_ShapesGraphToAstTransformer → dist/_ShapesGraphToAstTransformer}/NodeShapeAstType.js +0 -0
- /package/{_ShapesGraphToAstTransformer → dist/_ShapesGraphToAstTransformer}/index.d.ts +0 -0
- /package/{_ShapesGraphToAstTransformer → dist/_ShapesGraphToAstTransformer}/index.js +0 -0
- /package/{_ShapesGraphToAstTransformer → dist/_ShapesGraphToAstTransformer}/pickLiteral.d.ts +0 -0
- /package/{_ShapesGraphToAstTransformer → dist/_ShapesGraphToAstTransformer}/pickLiteral.js +0 -0
- /package/{_ShapesGraphToAstTransformer → dist/_ShapesGraphToAstTransformer}/propertyShapeNodeKinds.d.ts +0 -0
- /package/{_ShapesGraphToAstTransformer → dist/_ShapesGraphToAstTransformer}/propertyShapeNodeKinds.js +0 -0
- /package/{_ShapesGraphToAstTransformer → dist/_ShapesGraphToAstTransformer}/shapeAstName.d.ts +0 -0
- /package/{_ShapesGraphToAstTransformer → dist/_ShapesGraphToAstTransformer}/shapeAstName.js +0 -0
- /package/{_ShapesGraphToAstTransformer → dist/_ShapesGraphToAstTransformer}/transformNodeShapeToAstType.d.ts +0 -0
- /package/{_ShapesGraphToAstTransformer → dist/_ShapesGraphToAstTransformer}/transformPropertyShapeToAstCompositeType.d.ts +0 -0
- /package/{_ShapesGraphToAstTransformer → dist/_ShapesGraphToAstTransformer}/transformPropertyShapeToAstIdentifierType.d.ts +0 -0
- /package/{_ShapesGraphToAstTransformer → dist/_ShapesGraphToAstTransformer}/transformPropertyShapeToAstIdentifierType.js +0 -0
- /package/{_ShapesGraphToAstTransformer → dist/_ShapesGraphToAstTransformer}/transformPropertyShapeToAstLiteralType.d.ts +0 -0
- /package/{_ShapesGraphToAstTransformer → dist/_ShapesGraphToAstTransformer}/transformPropertyShapeToAstLiteralType.js +0 -0
- /package/{_ShapesGraphToAstTransformer → dist/_ShapesGraphToAstTransformer}/transformPropertyShapeToAstObjectTypeProperty.d.ts +0 -0
- /package/{_ShapesGraphToAstTransformer → dist/_ShapesGraphToAstTransformer}/transformPropertyShapeToAstObjectTypeProperty.js +0 -0
- /package/{_ShapesGraphToAstTransformer → dist/_ShapesGraphToAstTransformer}/transformPropertyShapeToAstTermType.d.ts +0 -0
- /package/{_ShapesGraphToAstTransformer → dist/_ShapesGraphToAstTransformer}/transformPropertyShapeToAstTermType.js +0 -0
- /package/{_ShapesGraphToAstTransformer → dist/_ShapesGraphToAstTransformer}/transformPropertyShapeToAstType.d.ts +0 -0
- /package/{ast → dist/ast}/Ast.d.ts +0 -0
- /package/{ast → dist/ast}/Ast.js +0 -0
- /package/{ast → dist/ast}/CompositeType.d.ts +0 -0
- /package/{ast → dist/ast}/CompositeType.js +0 -0
- /package/{ast → dist/ast}/IdentifierType.d.ts +0 -0
- /package/{ast → dist/ast}/IdentifierType.js +0 -0
- /package/{ast → dist/ast}/IntersectionType.d.ts +0 -0
- /package/{ast → dist/ast}/IntersectionType.js +0 -0
- /package/{ast → dist/ast}/ListType.js +0 -0
- /package/{ast → dist/ast}/LiteralType.d.ts +0 -0
- /package/{ast → dist/ast}/LiteralType.js +0 -0
- /package/{ast → dist/ast}/Name.d.ts +0 -0
- /package/{ast → dist/ast}/Name.js +0 -0
- /package/{ast → dist/ast}/ObjectCompositeType.d.ts +0 -0
- /package/{ast → dist/ast}/ObjectCompositeType.js +0 -0
- /package/{ast → dist/ast}/ObjectIntersectionType.d.ts +0 -0
- /package/{ast → dist/ast}/ObjectIntersectionType.js +0 -0
- /package/{ast → dist/ast}/ObjectType.js +0 -0
- /package/{ast → dist/ast}/ObjectUnionType.d.ts +0 -0
- /package/{ast → dist/ast}/ObjectUnionType.js +0 -0
- /package/{ast → dist/ast}/OptionType.d.ts +0 -0
- /package/{ast → dist/ast}/OptionType.js +0 -0
- /package/{ast → dist/ast}/PlaceholderType.d.ts +0 -0
- /package/{ast → dist/ast}/PlaceholderType.js +0 -0
- /package/{ast → dist/ast}/SetType.js +0 -0
- /package/{ast → dist/ast}/TermType.d.ts +0 -0
- /package/{ast → dist/ast}/TermType.js +0 -0
- /package/{ast → dist/ast}/Type.d.ts +0 -0
- /package/{ast → dist/ast}/Type.js +0 -0
- /package/{ast → dist/ast}/UnionType.d.ts +0 -0
- /package/{ast → dist/ast}/UnionType.js +0 -0
- /package/{ast → dist/ast}/index.d.ts +0 -0
- /package/{ast → dist/ast}/index.js +0 -0
- /package/{enums → dist/enums}/PropertyVisibility.d.ts +0 -0
- /package/{enums → dist/enums}/PropertyVisibility.js +0 -0
- /package/{enums → dist/enums}/TsFeature.d.ts +0 -0
- /package/{enums → dist/enums}/TsFeature.js +0 -0
- /package/{enums → dist/enums}/TsObjectDeclarationType.d.ts +0 -0
- /package/{enums → dist/enums}/TsObjectDeclarationType.js +0 -0
- /package/{generators → dist/generators}/Generator.d.ts +0 -0
- /package/{generators → dist/generators}/Generator.js +0 -0
- /package/{generators → dist/generators}/json/AstJsonGenerator.d.ts +0 -0
- /package/{generators → dist/generators}/json/index.d.ts +0 -0
- /package/{generators → dist/generators}/json/index.js +0 -0
- /package/{generators → dist/generators}/ts/BooleanType.d.ts +0 -0
- /package/{generators → dist/generators}/ts/DeclaredType.d.ts +0 -0
- /package/{generators → dist/generators}/ts/Import.d.ts +0 -0
- /package/{generators → dist/generators}/ts/Import.js +0 -0
- /package/{generators → dist/generators}/ts/LiteralType.d.ts +0 -0
- /package/{generators → dist/generators}/ts/NumberType.d.ts +0 -0
- /package/{generators → dist/generators}/ts/ObjectUnionType.d.ts +0 -0
- /package/{generators → dist/generators}/ts/OptionType.d.ts +0 -0
- /package/{generators → dist/generators}/ts/PrimitiveType.d.ts +0 -0
- /package/{generators → dist/generators}/ts/SnippetDeclarations.d.ts +0 -0
- /package/{generators → dist/generators}/ts/SnippetDeclarations.js +0 -0
- /package/{generators → dist/generators}/ts/StringType.d.ts +0 -0
- /package/{generators → dist/generators}/ts/TermType.d.ts +0 -0
- /package/{generators → dist/generators}/ts/TsGenerator.d.ts +0 -0
- /package/{generators → dist/generators}/ts/TsGenerator.js +0 -0
- /package/{generators → dist/generators}/ts/Type.d.ts +0 -0
- /package/{generators → dist/generators}/ts/TypeFactory.d.ts +0 -0
- /package/{generators → dist/generators}/ts/UnionType.d.ts +0 -0
- /package/{generators → dist/generators}/ts/_ObjectType/Property.d.ts +0 -0
- /package/{generators → dist/generators}/ts/_ObjectType/ShaclProperty.d.ts +0 -0
- /package/{generators → dist/generators}/ts/_ObjectType/TypeDiscriminatorProperty.d.ts +0 -0
- /package/{generators → dist/generators}/ts/_ObjectType/classDeclaration.d.ts +0 -0
- /package/{generators → dist/generators}/ts/_ObjectType/classDeclaration.js +0 -0
- /package/{generators → dist/generators}/ts/_ObjectType/createFunctionDeclaration.d.ts +0 -0
- /package/{generators → dist/generators}/ts/_ObjectType/createFunctionDeclaration.js +0 -0
- /package/{generators → dist/generators}/ts/_ObjectType/equalsFunctionDeclaration.d.ts +0 -0
- /package/{generators → dist/generators}/ts/_ObjectType/equalsFunctionDeclaration.js +0 -0
- /package/{generators → dist/generators}/ts/_ObjectType/equalsFunctionOrMethodDeclaration.d.ts +0 -0
- /package/{generators → dist/generators}/ts/_ObjectType/equalsFunctionOrMethodDeclaration.js +0 -0
- /package/{generators → dist/generators}/ts/_ObjectType/fromJsonFunctionDeclarations.d.ts +0 -0
- /package/{generators → dist/generators}/ts/_ObjectType/fromJsonFunctionDeclarations.js +0 -0
- /package/{generators → dist/generators}/ts/_ObjectType/fromRdfFunctionDeclarations.d.ts +0 -0
- /package/{generators → dist/generators}/ts/_ObjectType/fromRdfFunctionDeclarations.js +0 -0
- /package/{generators → dist/generators}/ts/_ObjectType/hashFunctionDeclaration.d.ts +0 -0
- /package/{generators → dist/generators}/ts/_ObjectType/hashFunctionDeclaration.js +0 -0
- /package/{generators → dist/generators}/ts/_ObjectType/hashFunctionOrMethodDeclaration.d.ts +0 -0
- /package/{generators → dist/generators}/ts/_ObjectType/hashFunctionOrMethodDeclaration.js +0 -0
- /package/{generators → dist/generators}/ts/_ObjectType/interfaceDeclaration.d.ts +0 -0
- /package/{generators → dist/generators}/ts/_ObjectType/interfaceDeclaration.js +0 -0
- /package/{generators → dist/generators}/ts/_ObjectType/jsonSchemaFunctionDeclaration.d.ts +0 -0
- /package/{generators → dist/generators}/ts/_ObjectType/jsonSchemaFunctionDeclaration.js +0 -0
- /package/{generators → dist/generators}/ts/_ObjectType/jsonUiSchemaFunctionDeclaration.d.ts +0 -0
- /package/{generators → dist/generators}/ts/_ObjectType/jsonUiSchemaFunctionDeclaration.js +0 -0
- /package/{generators → dist/generators}/ts/_ObjectType/jsonZodSchemaFunctionDeclaration.d.ts +0 -0
- /package/{generators → dist/generators}/ts/_ObjectType/jsonZodSchemaFunctionDeclaration.js +0 -0
- /package/{generators → dist/generators}/ts/_ObjectType/rdfjsTermExpression.d.ts +0 -0
- /package/{generators → dist/generators}/ts/_ObjectType/rdfjsTermExpression.js +0 -0
- /package/{generators → dist/generators}/ts/_ObjectType/sparqlConstructQueryFunctionDeclaration.d.ts +0 -0
- /package/{generators → dist/generators}/ts/_ObjectType/sparqlConstructQueryFunctionDeclaration.js +0 -0
- /package/{generators → dist/generators}/ts/_ObjectType/sparqlConstructQueryStringFunctionDeclaration.d.ts +0 -0
- /package/{generators → dist/generators}/ts/_ObjectType/sparqlConstructQueryStringFunctionDeclaration.js +0 -0
- /package/{generators → dist/generators}/ts/_ObjectType/sparqlFunctionDeclarations.d.ts +0 -0
- /package/{generators → dist/generators}/ts/_ObjectType/sparqlFunctionDeclarations.js +0 -0
- /package/{generators → dist/generators}/ts/_ObjectType/toJsonFunctionDeclaration.d.ts +0 -0
- /package/{generators → dist/generators}/ts/_ObjectType/toJsonFunctionDeclaration.js +0 -0
- /package/{generators → dist/generators}/ts/_ObjectType/toJsonFunctionOrMethodDeclaration.d.ts +0 -0
- /package/{generators → dist/generators}/ts/_ObjectType/toJsonFunctionOrMethodDeclaration.js +0 -0
- /package/{generators → dist/generators}/ts/_ObjectType/toJsonReturnType.d.ts +0 -0
- /package/{generators → dist/generators}/ts/_ObjectType/toJsonReturnType.js +0 -0
- /package/{generators → dist/generators}/ts/_ObjectType/toRdfFunctionDeclaration.d.ts +0 -0
- /package/{generators → dist/generators}/ts/_ObjectType/toRdfFunctionDeclaration.js +0 -0
- /package/{generators → dist/generators}/ts/_ObjectType/toRdfFunctionOrMethodDeclaration.d.ts +0 -0
- /package/{generators → dist/generators}/ts/index.d.ts +0 -0
- /package/{generators → dist/generators}/ts/index.js +0 -0
- /package/{generators → dist/generators}/ts/objectInitializer.d.ts +0 -0
- /package/{generators → dist/generators}/ts/objectInitializer.js +0 -0
- /package/{generators → dist/generators}/ts/stringToValidTsIdentifier.d.ts +0 -0
- /package/{generators → dist/generators}/ts/stringToValidTsIdentifier.js +0 -0
- /package/{generators → dist/generators}/ts/tsComment.d.ts +0 -0
- /package/{generators → dist/generators}/ts/tsComment.js +0 -0
- /package/{generators → dist/generators}/ts/tsName.d.ts +0 -0
- /package/{generators → dist/generators}/ts/tsName.js +0 -0
- /package/{input → dist/input}/Ontology.d.ts +0 -0
- /package/{input → dist/input}/PropertyShape.d.ts +0 -0
- /package/{input → dist/input}/Shape.d.ts +0 -0
- /package/{input → dist/input}/Shape.js +0 -0
- /package/{input → dist/input}/ShapesGraph.d.ts +0 -0
- /package/{input → dist/input}/ShapesGraph.js +0 -0
- /package/{input → dist/input}/ancestorClassIris.d.ts +0 -0
- /package/{input → dist/input}/ancestorClassIris.js +0 -0
- /package/{input → dist/input}/descendantClassIris.d.ts +0 -0
- /package/{input → dist/input}/descendantClassIris.js +0 -0
- /package/{input → dist/input}/index.d.ts +0 -0
- /package/{input → dist/input}/index.js +0 -0
- /package/{logger.d.ts → dist/logger.d.ts} +0 -0
- /package/{logger.js → dist/logger.js} +0 -0
|
@@ -2,6 +2,8 @@ import PrefixMap from "@rdfjs/prefix-map/PrefixMap.js";
|
|
|
2
2
|
import { ShapesGraphToAstTransformer } from "./ShapesGraphToAstTransformer.js";
|
|
3
3
|
import { ShapesGraph } from "./input/ShapesGraph.js";
|
|
4
4
|
export class Compiler {
|
|
5
|
+
generator;
|
|
6
|
+
iriPrefixMap;
|
|
5
7
|
constructor({ generator, iriPrefixMap, }) {
|
|
6
8
|
this.generator = generator;
|
|
7
9
|
this.iriPrefixMap = iriPrefixMap ?? new PrefixMap();
|
|
@@ -3,18 +3,20 @@ import { dash } from "@tpluscode/rdf-ns-builders";
|
|
|
3
3
|
import { Either, Maybe } from "purify-ts";
|
|
4
4
|
import * as _ShapesGraphToAstTransformer from "./_ShapesGraphToAstTransformer/index.js";
|
|
5
5
|
export class ShapesGraphToAstTransformer {
|
|
6
|
+
// Members are protected so they're accessible to the bound functions
|
|
7
|
+
astObjectTypePropertiesByIdentifier = new TermMap();
|
|
8
|
+
iriPrefixMap;
|
|
9
|
+
nodeShapeAstTypesByIdentifier = new TermMap();
|
|
10
|
+
shapeAstName = _ShapesGraphToAstTransformer.shapeAstName;
|
|
11
|
+
shapesGraph;
|
|
12
|
+
transformNodeShapeToAstType = _ShapesGraphToAstTransformer.transformNodeShapeToAstType;
|
|
13
|
+
transformPropertyShapeToAstCompositeType = _ShapesGraphToAstTransformer.transformPropertyShapeToAstCompositeType;
|
|
14
|
+
transformPropertyShapeToAstIdentifierType = _ShapesGraphToAstTransformer.transformPropertyShapeToAstIdentifierType;
|
|
15
|
+
transformPropertyShapeToAstLiteralType = _ShapesGraphToAstTransformer.transformPropertyShapeToAstLiteralType;
|
|
16
|
+
transformPropertyShapeToAstObjectTypeProperty = _ShapesGraphToAstTransformer.transformPropertyShapeToAstObjectTypeProperty;
|
|
17
|
+
transformPropertyShapeToAstTermType = _ShapesGraphToAstTransformer.transformPropertyShapeToAstTermType;
|
|
18
|
+
transformPropertyShapeToAstType = _ShapesGraphToAstTransformer.transformPropertyShapeToAstType;
|
|
6
19
|
constructor({ iriPrefixMap, shapesGraph, }) {
|
|
7
|
-
// Members are protected so they're accessible to the bound functions
|
|
8
|
-
this.astObjectTypePropertiesByIdentifier = new TermMap();
|
|
9
|
-
this.nodeShapeAstTypesByIdentifier = new TermMap();
|
|
10
|
-
this.shapeAstName = _ShapesGraphToAstTransformer.shapeAstName;
|
|
11
|
-
this.transformNodeShapeToAstType = _ShapesGraphToAstTransformer.transformNodeShapeToAstType;
|
|
12
|
-
this.transformPropertyShapeToAstCompositeType = _ShapesGraphToAstTransformer.transformPropertyShapeToAstCompositeType;
|
|
13
|
-
this.transformPropertyShapeToAstIdentifierType = _ShapesGraphToAstTransformer.transformPropertyShapeToAstIdentifierType;
|
|
14
|
-
this.transformPropertyShapeToAstLiteralType = _ShapesGraphToAstTransformer.transformPropertyShapeToAstLiteralType;
|
|
15
|
-
this.transformPropertyShapeToAstObjectTypeProperty = _ShapesGraphToAstTransformer.transformPropertyShapeToAstObjectTypeProperty;
|
|
16
|
-
this.transformPropertyShapeToAstTermType = _ShapesGraphToAstTransformer.transformPropertyShapeToAstTermType;
|
|
17
|
-
this.transformPropertyShapeToAstType = _ShapesGraphToAstTransformer.transformPropertyShapeToAstType;
|
|
18
20
|
this.iriPrefixMap = iriPrefixMap;
|
|
19
21
|
this.shapesGraph = shapesGraph;
|
|
20
22
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { rdf } from "@tpluscode/rdf-ns-builders";
|
|
2
|
-
import { Either, Left } from "purify-ts";
|
|
2
|
+
import { Either, Left, Maybe } from "purify-ts";
|
|
3
3
|
import { invariant } from "ts-invariant";
|
|
4
4
|
import { TsFeature } from "../enums/index.js";
|
|
5
5
|
import * as input from "../input/index.js";
|
|
@@ -24,7 +24,7 @@ function transformNodeShapeToListType(nodeShape) {
|
|
|
24
24
|
label: pickLiteral(nodeShape.labels).map((literal) => literal.value),
|
|
25
25
|
mutable: nodeShape.mutable,
|
|
26
26
|
name: this.shapeAstName(nodeShape),
|
|
27
|
-
|
|
27
|
+
identifierMintingStrategy: nodeShape.identifierMintingStrategy,
|
|
28
28
|
toRdfTypes: nodeShape.toRdfTypes,
|
|
29
29
|
};
|
|
30
30
|
this.nodeShapeAstTypesByIdentifier.set(nodeShape.identifier, listType);
|
|
@@ -125,6 +125,7 @@ export function transformNodeShapeToAstType(nodeShape) {
|
|
|
125
125
|
}
|
|
126
126
|
return Either.of(compositeType);
|
|
127
127
|
}
|
|
128
|
+
const identifierIn = nodeShape.constraints.in_.filter((term) => term.termType === "NamedNode");
|
|
128
129
|
// Put a placeholder in the cache to deal with cyclic references
|
|
129
130
|
// If this node shape's properties (directly or indirectly) refer to the node shape itself,
|
|
130
131
|
// we'll return this placeholder.
|
|
@@ -139,9 +140,12 @@ export function transformNodeShapeToAstType(nodeShape) {
|
|
|
139
140
|
fromRdfType: nodeShape.fromRdfType,
|
|
140
141
|
label: pickLiteral(nodeShape.labels).map((literal) => literal.value),
|
|
141
142
|
kind: "ObjectType",
|
|
142
|
-
|
|
143
|
+
identifierIn,
|
|
144
|
+
identifierMintingStrategy: identifierIn.length === 0
|
|
145
|
+
? nodeShape.identifierMintingStrategy
|
|
146
|
+
: Maybe.empty(),
|
|
147
|
+
identifierKinds: identifierIn.length === 0 ? nodeShape.nodeKinds : new Set(["NamedNode"]),
|
|
143
148
|
name: this.shapeAstName(nodeShape),
|
|
144
|
-
nodeKinds: nodeShape.nodeKinds,
|
|
145
149
|
properties: [], // This is mutable, we'll populate it below.
|
|
146
150
|
parentObjectTypes: [], // This is mutable, we'll populate it below
|
|
147
151
|
toRdfTypes: nodeShape.toRdfTypes,
|
|
@@ -27,13 +27,13 @@ export function transformPropertyShapeToAstCompositeType(shape, inherited) {
|
|
|
27
27
|
nodeKinds.add(astType.identifierNodeKind);
|
|
28
28
|
break;
|
|
29
29
|
case "ObjectType":
|
|
30
|
-
nodeKinds = astType.
|
|
30
|
+
nodeKinds = astType.identifierKinds;
|
|
31
31
|
break;
|
|
32
32
|
case "ObjectIntersectionType":
|
|
33
33
|
case "ObjectUnionType":
|
|
34
34
|
nodeKinds = new Set();
|
|
35
35
|
for (const memberType of astType.memberTypes) {
|
|
36
|
-
for (const nodeKind of memberType.
|
|
36
|
+
for (const nodeKind of memberType.identifierKinds) {
|
|
37
37
|
nodeKinds.add(nodeKind);
|
|
38
38
|
}
|
|
39
39
|
}
|
|
@@ -30,6 +30,7 @@ export function transformPropertyShapeToAstType(shape, inherited) {
|
|
|
30
30
|
return {
|
|
31
31
|
itemType,
|
|
32
32
|
kind: "SetType",
|
|
33
|
+
mutable: shape.mutable,
|
|
33
34
|
minCount: 0,
|
|
34
35
|
};
|
|
35
36
|
}
|
|
@@ -52,6 +53,7 @@ export function transformPropertyShapeToAstType(shape, inherited) {
|
|
|
52
53
|
itemType,
|
|
53
54
|
kind: "SetType",
|
|
54
55
|
minCount: minCount.orDefault(0),
|
|
56
|
+
mutable: shape.mutable,
|
|
55
57
|
};
|
|
56
58
|
});
|
|
57
59
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { NamedNode } from "@rdfjs/types";
|
|
2
2
|
import type { Maybe } from "purify-ts";
|
|
3
|
-
import type {
|
|
3
|
+
import type { IdentifierMintingStrategy } from "../enums/IdentifierMintingStrategy.js";
|
|
4
4
|
import type { Name } from "./Name.js";
|
|
5
5
|
import type { Type } from "./Type.js";
|
|
6
6
|
/**
|
|
@@ -33,7 +33,7 @@ export interface ListType {
|
|
|
33
33
|
/**
|
|
34
34
|
* Strategy for minting new list and sub-list identifiers.
|
|
35
35
|
*/
|
|
36
|
-
readonly
|
|
36
|
+
readonly identifierMintingStrategy: Maybe<IdentifierMintingStrategy>;
|
|
37
37
|
/**
|
|
38
38
|
* The list should be mutable in generated code.
|
|
39
39
|
*/
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { NamedNode } from "@rdfjs/types";
|
|
2
|
-
import type { PredicatePath } from "@shaclmate/shacl-ast";
|
|
2
|
+
import type { NodeKind, PredicatePath } from "@shaclmate/shacl-ast";
|
|
3
3
|
import type { Maybe } from "purify-ts";
|
|
4
|
-
import type {
|
|
4
|
+
import type { IdentifierMintingStrategy, PropertyVisibility, TsFeature, TsObjectDeclarationType } from "../enums/index.js";
|
|
5
5
|
import type { Name } from "./Name.js";
|
|
6
6
|
import type { Type } from "./Type.js";
|
|
7
7
|
export interface ObjectType {
|
|
@@ -52,6 +52,22 @@ export interface ObjectType {
|
|
|
52
52
|
* class targets).
|
|
53
53
|
*/
|
|
54
54
|
readonly fromRdfType: Maybe<NamedNode>;
|
|
55
|
+
/**
|
|
56
|
+
* Instances of this ObjectType must have explicit identifiers and the identifiers must be in this list of IRIs.
|
|
57
|
+
*
|
|
58
|
+
* Mutually exclusive with minting strategies
|
|
59
|
+
*/
|
|
60
|
+
readonly identifierIn: readonly NamedNode[];
|
|
61
|
+
/**
|
|
62
|
+
* The RDF node kinds this ObjectType may be identified by.
|
|
63
|
+
*
|
|
64
|
+
* Used to associate instances with an RDF identifier.
|
|
65
|
+
*/
|
|
66
|
+
readonly identifierKinds: Set<Exclude<NodeKind, "Literal">>;
|
|
67
|
+
/**
|
|
68
|
+
* Strategy for minting new object identifiers.
|
|
69
|
+
*/
|
|
70
|
+
readonly identifierMintingStrategy: Maybe<IdentifierMintingStrategy>;
|
|
55
71
|
/**
|
|
56
72
|
* Type discriminator.
|
|
57
73
|
*/
|
|
@@ -60,20 +76,10 @@ export interface ObjectType {
|
|
|
60
76
|
* Human-readable label from rdfs:label.
|
|
61
77
|
*/
|
|
62
78
|
readonly label: Maybe<string>;
|
|
63
|
-
/**
|
|
64
|
-
* Strategy for minting new object identifiers.
|
|
65
|
-
*/
|
|
66
|
-
readonly mintingStrategy: Maybe<MintingStrategy>;
|
|
67
79
|
/**
|
|
68
80
|
* Name of this type, usually derived from sh:name or shaclmate:name.
|
|
69
81
|
*/
|
|
70
82
|
readonly name: Name;
|
|
71
|
-
/**
|
|
72
|
-
* The RDF node kinds this ObjectType may be identified by.
|
|
73
|
-
*
|
|
74
|
-
* Used to associate instances with an RDF identifier.
|
|
75
|
-
*/
|
|
76
|
-
readonly nodeKinds: Set<"BlankNode" | "NamedNode">;
|
|
77
83
|
/**
|
|
78
84
|
* Immediate parent ObjectTypes of this Object types.
|
|
79
85
|
*
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Maybe } from "purify-ts";
|
|
2
|
+
import type { Type } from "./Type.js";
|
|
3
|
+
/**
|
|
4
|
+
* An unordered set of items of a specific type.
|
|
5
|
+
*
|
|
6
|
+
* This is a property with sh:maxCount != 1.
|
|
7
|
+
*/
|
|
8
|
+
export interface SetType {
|
|
9
|
+
/**
|
|
10
|
+
* Set item type.
|
|
11
|
+
*/
|
|
12
|
+
readonly itemType: Type;
|
|
13
|
+
readonly kind: "SetType";
|
|
14
|
+
/**
|
|
15
|
+
* Minimum number of items in the set.
|
|
16
|
+
*/
|
|
17
|
+
readonly minCount: number;
|
|
18
|
+
/**
|
|
19
|
+
* The set should be mutable in generated code.
|
|
20
|
+
*/
|
|
21
|
+
readonly mutable: Maybe<boolean>;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=SetType.d.ts.map
|
|
@@ -70,7 +70,11 @@ function typeToJson(type) {
|
|
|
70
70
|
parentObjectTypes: type.parentObjectTypes.length > 0
|
|
71
71
|
? type.parentObjectTypes.map((type) => nameToJson(type.name))
|
|
72
72
|
: undefined,
|
|
73
|
-
|
|
73
|
+
identifierIn: type.identifierIn.length > 0
|
|
74
|
+
? type.identifierIn.map(termToJson)
|
|
75
|
+
: undefined,
|
|
76
|
+
identifierKinds: [...type.identifierKinds],
|
|
77
|
+
identifierMintingStrategy: type.identifierMintingStrategy.extract(),
|
|
74
78
|
toRdfTypes: type.toRdfTypes.length > 0
|
|
75
79
|
? type.toRdfTypes.map(termToJson)
|
|
76
80
|
: undefined,
|
|
@@ -8,10 +8,7 @@ import { Memoize } from "typescript-memoize";
|
|
|
8
8
|
import { PrimitiveType } from "./PrimitiveType.js";
|
|
9
9
|
import { objectInitializer } from "./objectInitializer.js";
|
|
10
10
|
export class BooleanType extends PrimitiveType {
|
|
11
|
-
|
|
12
|
-
super(...arguments);
|
|
13
|
-
this.kind = "BooleanType";
|
|
14
|
-
}
|
|
11
|
+
kind = "BooleanType";
|
|
15
12
|
get conversions() {
|
|
16
13
|
const conversions = [
|
|
17
14
|
{
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
+
import type { NamedNode } from "@rdfjs/types";
|
|
1
2
|
import type { TsFeature } from "../../enums/index.js";
|
|
2
3
|
import { PrimitiveType } from "./PrimitiveType.js";
|
|
3
4
|
import type { Type } from "./Type.js";
|
|
4
5
|
export declare class DateTimeType extends PrimitiveType<Date> {
|
|
5
6
|
readonly equalsFunction = "dateEquals";
|
|
6
|
-
readonly kind
|
|
7
|
+
readonly kind: "DateTimeType" | "DateType";
|
|
7
8
|
readonly mutable = true;
|
|
9
|
+
protected readonly xsdDatatype: NamedNode;
|
|
10
|
+
protected readonly zodDatatype: string;
|
|
8
11
|
get conversions(): readonly Type.Conversion[];
|
|
9
12
|
get jsonName(): string;
|
|
10
13
|
get name(): string;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
+
import { xsd } from "@tpluscode/rdf-ns-builders";
|
|
1
2
|
import { PrimitiveType } from "./PrimitiveType.js";
|
|
2
3
|
import { SnippetDeclarations } from "./SnippetDeclarations.js";
|
|
3
4
|
import { objectInitializer } from "./objectInitializer.js";
|
|
4
5
|
export class DateTimeType extends PrimitiveType {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
6
|
+
equalsFunction = "dateEquals";
|
|
7
|
+
kind = "DateTimeType";
|
|
8
|
+
mutable = true;
|
|
9
|
+
xsdDatatype = xsd.dateTime;
|
|
10
|
+
zodDatatype = "datetime";
|
|
11
11
|
get conversions() {
|
|
12
12
|
const conversions = [
|
|
13
13
|
{
|
|
@@ -38,12 +38,12 @@ export class DateTimeType extends PrimitiveType {
|
|
|
38
38
|
return [`${variables.hasher}.update(${variables.value}.toISOString());`];
|
|
39
39
|
}
|
|
40
40
|
jsonZodSchema({ variables, }) {
|
|
41
|
-
return `${variables.zod}.string().
|
|
41
|
+
return `${variables.zod}.string().${this.zodDatatype}()`;
|
|
42
42
|
}
|
|
43
43
|
propertyFromRdfResourceValueExpression({ variables, }) {
|
|
44
44
|
let expression = `${variables.resourceValue}.toDate()`;
|
|
45
45
|
if (this.primitiveIn.length > 0) {
|
|
46
|
-
expression = `${expression}.chain(value => { ${this.primitiveIn.map((value) => `if (value.getTime() === ${value.getTime()}) { return purify.Either.of(value); }`).join(" ")} return purify.Left(new rdfjsResource.Resource.MistypedValueError(${objectInitializer({ actualValue:
|
|
46
|
+
expression = `${expression}.chain(value => { ${this.primitiveIn.map((value) => `if (value.getTime() === ${value.getTime()}) { return purify.Either.of(value); }`).join(" ")} return purify.Left(new rdfjsResource.Resource.MistypedValueError(${objectInitializer({ actualValue: `rdfLiteral.toRdf(value, ${objectInitializer({ dataFactory: this.dataFactoryVariable, datatype: this.rdfjsTermExpression(this.xsdDatatype) })})`, expectedValueType: JSON.stringify(this.name), focusResource: variables.resource, predicate: variables.predicate })})); })`;
|
|
47
47
|
}
|
|
48
48
|
return expression;
|
|
49
49
|
}
|
|
@@ -58,9 +58,10 @@ export class DateTimeType extends PrimitiveType {
|
|
|
58
58
|
return `${variables.value}.toISOString()`;
|
|
59
59
|
}
|
|
60
60
|
toRdfExpression({ variables, }) {
|
|
61
|
+
const valueToRdf = `rdfLiteral.toRdf(${variables.value}, ${objectInitializer({ dataFactory: this.dataFactoryVariable, datatype: this.rdfjsTermExpression(this.xsdDatatype) })})`;
|
|
61
62
|
return this.primitiveDefaultValue
|
|
62
|
-
.map((defaultValue) => `${variables.value}.getTime() !== ${defaultValue.getTime()} ? ${
|
|
63
|
-
.orDefault(
|
|
63
|
+
.map((defaultValue) => `${variables.value}.getTime() !== ${defaultValue.getTime()} ? ${valueToRdf} : undefined`)
|
|
64
|
+
.orDefault(valueToRdf);
|
|
64
65
|
}
|
|
65
66
|
}
|
|
66
67
|
//# sourceMappingURL=DateTimeType.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { DateTimeType } from "./DateTimeType.js";
|
|
2
|
+
import type { PrimitiveType } from "./PrimitiveType.js";
|
|
3
|
+
export declare class DateType extends DateTimeType {
|
|
4
|
+
readonly kind = "DateType";
|
|
5
|
+
protected readonly xsdDatatype: import("@rdfjs/types").NamedNode<string> & import("@rdfjs/types").NamedNode<"http://www.w3.org/2001/XMLSchema#date">;
|
|
6
|
+
protected readonly zodDatatype = "date";
|
|
7
|
+
toJsonExpression({ variables, }: Parameters<PrimitiveType<Date>["toJsonExpression"]>[0]): string;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=DateType.d.ts.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { xsd } from "@tpluscode/rdf-ns-builders";
|
|
2
|
+
import { DateTimeType } from "./DateTimeType.js";
|
|
3
|
+
export class DateType extends DateTimeType {
|
|
4
|
+
kind = "DateType";
|
|
5
|
+
xsdDatatype = xsd.date;
|
|
6
|
+
zodDatatype = "date";
|
|
7
|
+
toJsonExpression({ variables, }) {
|
|
8
|
+
return `${variables.value}.toISOString().replace(/T.*$/, '')`;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=DateType.js.map
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type { BlankNode, NamedNode } from "@rdfjs/types";
|
|
2
2
|
import { TermType } from "./TermType.js";
|
|
3
|
+
import type { Type } from "./Type.js";
|
|
3
4
|
export declare class IdentifierType extends TermType<BlankNode | NamedNode> {
|
|
4
5
|
readonly kind = "IdentifierType";
|
|
6
|
+
get conversions(): readonly Type.Conversion[];
|
|
5
7
|
get isNamedNodeKind(): boolean;
|
|
6
8
|
get jsonName(): string;
|
|
7
9
|
get name(): string;
|
|
@@ -7,9 +7,17 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
import { Memoize } from "typescript-memoize";
|
|
8
8
|
import { TermType } from "./TermType.js";
|
|
9
9
|
export class IdentifierType extends TermType {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
kind = "IdentifierType";
|
|
11
|
+
get conversions() {
|
|
12
|
+
return super.conversions.concat([
|
|
13
|
+
{
|
|
14
|
+
conversionExpression: (value) => `${this.dataFactoryVariable}.namedNode(${value})`,
|
|
15
|
+
sourceTypeCheckExpression: (value) => `typeof ${value} === "string"`,
|
|
16
|
+
sourceTypeName: this.in_.length > 0
|
|
17
|
+
? this.in_.map((iri) => `"${iri.value}"`).join(" | ")
|
|
18
|
+
: "string",
|
|
19
|
+
},
|
|
20
|
+
]);
|
|
13
21
|
}
|
|
14
22
|
get isNamedNodeKind() {
|
|
15
23
|
return this.nodeKinds.size === 1 && this.nodeKinds.has("NamedNode");
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import type { NamedNode } from "@rdfjs/types";
|
|
2
2
|
import { Maybe } from "purify-ts";
|
|
3
|
-
import type {
|
|
3
|
+
import type { IdentifierMintingStrategy, TsFeature } from "../../enums/index.js";
|
|
4
4
|
import { Import } from "./Import.js";
|
|
5
5
|
import { Type } from "./Type.js";
|
|
6
6
|
export declare class ListType extends Type {
|
|
7
7
|
readonly itemType: Type;
|
|
8
8
|
readonly kind = "ListType";
|
|
9
|
-
readonly mutable: boolean;
|
|
10
9
|
private readonly identifierNodeKind;
|
|
11
|
-
private readonly
|
|
10
|
+
private readonly identifierMintingStrategy;
|
|
11
|
+
private readonly _mutable;
|
|
12
12
|
private readonly toRdfTypes;
|
|
13
|
-
constructor({ identifierNodeKind, itemType,
|
|
13
|
+
constructor({ identifierNodeKind, itemType, identifierMintingStrategy, mutable, toRdfTypes, ...superParameters }: {
|
|
14
14
|
identifierNodeKind: ListType["identifierNodeKind"];
|
|
15
15
|
itemType: Type;
|
|
16
|
-
|
|
16
|
+
identifierMintingStrategy: Maybe<IdentifierMintingStrategy>;
|
|
17
17
|
mutable: boolean;
|
|
18
18
|
toRdfTypes: readonly NamedNode[];
|
|
19
19
|
} & ConstructorParameters<typeof Type>[0]);
|
|
@@ -21,6 +21,7 @@ export declare class ListType extends Type {
|
|
|
21
21
|
get discriminatorProperty(): Maybe<Type.DiscriminatorProperty>;
|
|
22
22
|
get equalsFunction(): string;
|
|
23
23
|
get jsonName(): string;
|
|
24
|
+
get mutable(): boolean;
|
|
24
25
|
get name(): string;
|
|
25
26
|
fromJsonExpression({ variables, }: Parameters<Type["fromJsonExpression"]>[0]): string;
|
|
26
27
|
fromRdfExpression({ variables, }: Parameters<Type["fromRdfExpression"]>[0]): string;
|
|
@@ -5,13 +5,19 @@ import { SnippetDeclarations } from "./SnippetDeclarations.js";
|
|
|
5
5
|
import { Type } from "./Type.js";
|
|
6
6
|
import { objectInitializer } from "./objectInitializer.js";
|
|
7
7
|
export class ListType extends Type {
|
|
8
|
-
|
|
8
|
+
itemType;
|
|
9
|
+
kind = "ListType";
|
|
10
|
+
identifierNodeKind;
|
|
11
|
+
identifierMintingStrategy;
|
|
12
|
+
_mutable;
|
|
13
|
+
toRdfTypes;
|
|
14
|
+
constructor({ identifierNodeKind, itemType, identifierMintingStrategy, mutable, toRdfTypes, ...superParameters }) {
|
|
9
15
|
super(superParameters);
|
|
10
|
-
this.kind = "ListType";
|
|
11
16
|
this.identifierNodeKind = identifierNodeKind;
|
|
12
17
|
this.itemType = itemType;
|
|
13
|
-
this.
|
|
14
|
-
|
|
18
|
+
this.identifierMintingStrategy =
|
|
19
|
+
identifierMintingStrategy.orDefault("sha256");
|
|
20
|
+
this._mutable = mutable;
|
|
15
21
|
this.toRdfTypes = toRdfTypes;
|
|
16
22
|
}
|
|
17
23
|
get conversions() {
|
|
@@ -32,8 +38,11 @@ export class ListType extends Type {
|
|
|
32
38
|
get jsonName() {
|
|
33
39
|
return `readonly (${this.itemType.jsonName})[]`;
|
|
34
40
|
}
|
|
41
|
+
get mutable() {
|
|
42
|
+
return this._mutable || this.itemType.mutable;
|
|
43
|
+
}
|
|
35
44
|
get name() {
|
|
36
|
-
return `${this.
|
|
45
|
+
return `${this._mutable ? "" : "readonly "}${this.itemType.name}[]`;
|
|
37
46
|
}
|
|
38
47
|
fromJsonExpression({ variables, }) {
|
|
39
48
|
return `${variables.value}.map(_item => (${this.itemType.fromJsonExpression({ variables: { value: "_item" } })}))`;
|
|
@@ -57,7 +66,9 @@ export class ListType extends Type {
|
|
|
57
66
|
return `${this.itemType.jsonZodSchema(parameters)}.array()`;
|
|
58
67
|
}
|
|
59
68
|
snippetDeclarations(features) {
|
|
60
|
-
const snippetDeclarations =
|
|
69
|
+
const snippetDeclarations = this.itemType
|
|
70
|
+
.snippetDeclarations(features)
|
|
71
|
+
.concat();
|
|
61
72
|
if (features.has("equals")) {
|
|
62
73
|
snippetDeclarations.push(SnippetDeclarations.arrayEquals);
|
|
63
74
|
}
|
|
@@ -124,6 +135,10 @@ export class ListType extends Type {
|
|
|
124
135
|
}
|
|
125
136
|
}
|
|
126
137
|
sparqlWherePatterns({ variables, context, }) {
|
|
138
|
+
// Need to handle two cases:
|
|
139
|
+
// (1) (?s, ?p, ?list) where ?list binds to rdf:nil
|
|
140
|
+
// (2) (?s, ?p, ?list) (?list, rdf:first, "element") (?list, rdf:rest, rdf:nil) etc. where list binds to the head of a list
|
|
141
|
+
// Case (2) is case (1) with OPTIONAL graph patterns to handle actual list elements.
|
|
127
142
|
switch (context) {
|
|
128
143
|
case "property":
|
|
129
144
|
return super.sparqlWherePatterns({ context, variables });
|
|
@@ -186,7 +201,8 @@ export class ListType extends Type {
|
|
|
186
201
|
object: variable("RestNBasic"),
|
|
187
202
|
})}] }`);
|
|
188
203
|
patterns.push(`{ type: "optional", patterns: [${optionalPatterns.join(", ")}] }`);
|
|
189
|
-
|
|
204
|
+
// Having an optional around everything handles the rdf:nil case
|
|
205
|
+
return [`{ type: "optional", patterns: [${patterns.join(", ")}] }`];
|
|
190
206
|
}
|
|
191
207
|
}
|
|
192
208
|
}
|
|
@@ -213,7 +229,7 @@ export class ListType extends Type {
|
|
|
213
229
|
break;
|
|
214
230
|
}
|
|
215
231
|
case "NamedNode": {
|
|
216
|
-
switch (this.
|
|
232
|
+
switch (this.identifierMintingStrategy) {
|
|
217
233
|
case "sha256":
|
|
218
234
|
listIdentifier = `dataFactory.namedNode(\`urn:shaclmate:list:\${${variables.value}.reduce(
|
|
219
235
|
(_hasher, _item) => {
|
|
@@ -236,12 +252,11 @@ export class ListType extends Type {
|
|
|
236
252
|
break;
|
|
237
253
|
}
|
|
238
254
|
}
|
|
239
|
-
return `${variables.value}.reduce(({ currentSubListResource, listResource }, item, itemIndex, list) => {
|
|
255
|
+
return `${variables.value}.length > 0 ? ${variables.value}.reduce(({ currentSubListResource, listResource }, item, itemIndex, list) => {
|
|
240
256
|
if (itemIndex === 0) {
|
|
241
257
|
currentSubListResource = listResource;
|
|
242
258
|
} else {
|
|
243
|
-
const newSubListResource = ${variables.resourceSet}.${resourceSetMethodName}(${objectInitializer({
|
|
244
|
-
identifier: subListIdentifier,
|
|
259
|
+
const newSubListResource = ${variables.resourceSet}.${resourceSetMethodName}(${subListIdentifier}, ${objectInitializer({
|
|
245
260
|
mutateGraph: variables.mutateGraph,
|
|
246
261
|
})});
|
|
247
262
|
currentSubListResource!.add(dataFactory.namedNode("${rdf.rest.value}"), newSubListResource.identifier);
|
|
@@ -260,15 +275,14 @@ export class ListType extends Type {
|
|
|
260
275
|
},
|
|
261
276
|
{
|
|
262
277
|
currentSubListResource: null,
|
|
263
|
-
listResource: resourceSet.${resourceSetMethodName}(${objectInitializer({
|
|
264
|
-
identifier: listIdentifier,
|
|
278
|
+
listResource: resourceSet.${resourceSetMethodName}(${listIdentifier}, ${objectInitializer({
|
|
265
279
|
mutateGraph: variables.mutateGraph,
|
|
266
280
|
})}),
|
|
267
281
|
} as {
|
|
268
282
|
currentSubListResource: ${mutableResourceTypeName} | null;
|
|
269
283
|
listResource: ${mutableResourceTypeName};
|
|
270
284
|
},
|
|
271
|
-
).listResource.identifier`;
|
|
285
|
+
).listResource.identifier : dataFactory.namedNode("${rdf.nil.value}")`;
|
|
272
286
|
}
|
|
273
287
|
useImports(features) {
|
|
274
288
|
const imports = this.itemType.useImports(features).concat();
|
|
@@ -8,10 +8,7 @@ import { Memoize } from "typescript-memoize";
|
|
|
8
8
|
import { PrimitiveType } from "./PrimitiveType.js";
|
|
9
9
|
import { objectInitializer } from "./objectInitializer.js";
|
|
10
10
|
export class NumberType extends PrimitiveType {
|
|
11
|
-
|
|
12
|
-
super(...arguments);
|
|
13
|
-
this.kind = "NumberType";
|
|
14
|
-
}
|
|
11
|
+
kind = "NumberType";
|
|
15
12
|
get conversions() {
|
|
16
13
|
const conversions = [
|
|
17
14
|
{
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { NamedNode } from "@rdfjs/types";
|
|
2
2
|
import { Maybe } from "purify-ts";
|
|
3
3
|
import { type ClassDeclarationStructure, type InterfaceDeclarationStructure, type ModuleDeclarationStructure } from "ts-morph";
|
|
4
|
-
import type {
|
|
4
|
+
import type { IdentifierMintingStrategy, TsFeature, TsObjectDeclarationType } from "../../enums/index.js";
|
|
5
5
|
import { DeclaredType } from "./DeclaredType.js";
|
|
6
6
|
import type { IdentifierType } from "./IdentifierType.js";
|
|
7
7
|
import { Import } from "./Import.js";
|
|
@@ -15,14 +15,14 @@ export declare class ObjectType extends DeclaredType {
|
|
|
15
15
|
protected readonly extern: boolean;
|
|
16
16
|
protected readonly fromRdfType: Maybe<NamedNode>;
|
|
17
17
|
protected readonly label: Maybe<string>;
|
|
18
|
-
protected readonly
|
|
18
|
+
protected readonly identifierMintingStrategy: Maybe<IdentifierMintingStrategy>;
|
|
19
19
|
protected readonly toRdfTypes: readonly NamedNode[];
|
|
20
20
|
private readonly imports;
|
|
21
21
|
private readonly lazyAncestorObjectTypes;
|
|
22
22
|
private readonly lazyDescendantObjectTypes;
|
|
23
23
|
private readonly lazyParentObjectTypes;
|
|
24
24
|
private readonly lazyProperties;
|
|
25
|
-
constructor({ abstract, comment, declarationType, extern, fromRdfType, label, lazyAncestorObjectTypes, lazyDescendantObjectTypes, lazyParentObjectTypes, lazyProperties, imports,
|
|
25
|
+
constructor({ abstract, comment, declarationType, extern, fromRdfType, label, lazyAncestorObjectTypes, lazyDescendantObjectTypes, lazyParentObjectTypes, lazyProperties, imports, identifierMintingStrategy, toRdfTypes, ...superParameters }: {
|
|
26
26
|
abstract: boolean;
|
|
27
27
|
comment: Maybe<string>;
|
|
28
28
|
declarationType: TsObjectDeclarationType;
|
|
@@ -34,7 +34,7 @@ export declare class ObjectType extends DeclaredType {
|
|
|
34
34
|
lazyDescendantObjectTypes: () => readonly ObjectType[];
|
|
35
35
|
lazyParentObjectTypes: () => readonly ObjectType[];
|
|
36
36
|
lazyProperties: () => readonly ObjectType.Property[];
|
|
37
|
-
|
|
37
|
+
identifierMintingStrategy: Maybe<IdentifierMintingStrategy>;
|
|
38
38
|
toRdfTypes: readonly NamedNode[];
|
|
39
39
|
} & ConstructorParameters<typeof DeclaredType>[0]);
|
|
40
40
|
get _discriminatorProperty(): Type.DiscriminatorProperty;
|