@shaclmate/compiler 2.0.16 → 2.0.18
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 +4 -2
- package/{_ShapesGraphToAstTransformer → dist/_ShapesGraphToAstTransformer}/transformPropertyShapeToAstType.js +2 -0
- package/{ast → dist/ast}/ListType.d.ts +1 -1
- package/dist/ast/SetType.d.ts +23 -0
- package/dist/enums/IdentifierMintingStrategy.d.ts +5 -0
- package/{generators → dist/generators}/index.d.ts +1 -0
- package/{generators → dist/generators}/index.js +1 -0
- 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.js +1 -4
- package/{generators → dist/generators}/ts/ListType.d.ts +5 -4
- package/{generators → dist/generators}/ts/ListType.js +18 -7
- 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 +3 -3
- package/{generators → dist/generators}/ts/ObjectType.js +16 -3
- package/{generators → dist/generators}/ts/ObjectUnionType.js +5 -1
- 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 +9 -6
- package/{generators → dist/generators}/ts/UnionType.js +3 -1
- package/{generators → dist/generators}/ts/_ObjectType/IdentifierProperty.js +13 -8
- 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/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/{input → dist/input}/NodeShape.d.ts +1 -1
- package/{input → dist/input}/NodeShape.js +11 -4
- package/{input → dist/input}/Ontology.js +1 -0
- package/dist/input/PropertyPath.d.ts +41 -0
- package/dist/input/PropertyPath.js +105 -0
- package/{input → dist/input}/PropertyShape.js +1 -0
- package/{input → dist/input}/generated.d.ts +3 -3
- package/{input → dist/input}/generated.js +11 -11
- package/package.json +28 -24
- package/ast/SetType.d.ts +0 -12
- package/enums/IdentifierMintingStrategy.d.ts +0 -5
- package/index.d.ts +0 -2
- package/index.js +0 -2
- /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}/transformPropertyShapeToAstCompositeType.js +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.d.ts +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}/IdentifierMintingStrategy.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/{enums → dist/enums}/index.d.ts +0 -0
- /package/{enums → dist/enums}/index.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/AstJsonGenerator.js +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/IdentifierType.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/IdentifierProperty.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/fromRdfTypeVariableStatement.d.ts +0 -0
- /package/{generators → dist/generators}/ts/_ObjectType/fromRdfTypeVariableStatement.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/index.d.ts +0 -0
- /package/{generators → dist/generators}/ts/_ObjectType/index.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/_ObjectType/toRdfFunctionOrMethodDeclaration.js +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/{input → dist/input}/tsFeatures.d.ts +0 -0
- /package/{input → dist/input}/tsFeatures.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
|
}
|
|
@@ -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);
|
|
@@ -141,7 +141,9 @@ export function transformNodeShapeToAstType(nodeShape) {
|
|
|
141
141
|
label: pickLiteral(nodeShape.labels).map((literal) => literal.value),
|
|
142
142
|
kind: "ObjectType",
|
|
143
143
|
identifierIn,
|
|
144
|
-
identifierMintingStrategy: identifierIn.length === 0
|
|
144
|
+
identifierMintingStrategy: identifierIn.length === 0
|
|
145
|
+
? nodeShape.identifierMintingStrategy
|
|
146
|
+
: Maybe.empty(),
|
|
145
147
|
identifierKinds: identifierIn.length === 0 ? nodeShape.nodeKinds : new Set(["NamedNode"]),
|
|
146
148
|
name: this.shapeAstName(nodeShape),
|
|
147
149
|
properties: [], // This is mutable, we'll populate it below.
|
|
@@ -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
|
}
|
|
@@ -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
|
*/
|
|
@@ -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
|
|
@@ -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
|
|
@@ -7,10 +7,7 @@ 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
|
-
super(...arguments);
|
|
12
|
-
this.kind = "IdentifierType";
|
|
13
|
-
}
|
|
10
|
+
kind = "IdentifierType";
|
|
14
11
|
get conversions() {
|
|
15
12
|
return super.conversions.concat([
|
|
16
13
|
{
|
|
@@ -6,14 +6,14 @@ 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
|
}
|
|
@@ -218,7 +229,7 @@ export class ListType extends Type {
|
|
|
218
229
|
break;
|
|
219
230
|
}
|
|
220
231
|
case "NamedNode": {
|
|
221
|
-
switch (this.
|
|
232
|
+
switch (this.identifierMintingStrategy) {
|
|
222
233
|
case "sha256":
|
|
223
234
|
listIdentifier = `dataFactory.namedNode(\`urn:shaclmate:list:\${${variables.value}.reduce(
|
|
224
235
|
(_hasher, _item) => {
|
|
@@ -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
|
{
|
|
@@ -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;
|
|
@@ -16,9 +16,22 @@ import * as _ObjectType from "./_ObjectType/index.js";
|
|
|
16
16
|
import { IdentifierProperty, TypeDiscriminatorProperty, } from "./_ObjectType/index.js";
|
|
17
17
|
import { objectInitializer } from "./objectInitializer.js";
|
|
18
18
|
export class ObjectType extends DeclaredType {
|
|
19
|
-
|
|
19
|
+
abstract;
|
|
20
|
+
declarationType;
|
|
21
|
+
kind = "ObjectType";
|
|
22
|
+
comment;
|
|
23
|
+
extern;
|
|
24
|
+
fromRdfType;
|
|
25
|
+
label;
|
|
26
|
+
identifierMintingStrategy;
|
|
27
|
+
toRdfTypes;
|
|
28
|
+
imports;
|
|
29
|
+
lazyAncestorObjectTypes;
|
|
30
|
+
lazyDescendantObjectTypes;
|
|
31
|
+
lazyParentObjectTypes;
|
|
32
|
+
lazyProperties;
|
|
33
|
+
constructor({ abstract, comment, declarationType, extern, fromRdfType, label, lazyAncestorObjectTypes, lazyDescendantObjectTypes, lazyParentObjectTypes, lazyProperties, imports, identifierMintingStrategy, toRdfTypes, ...superParameters }) {
|
|
20
34
|
super(superParameters);
|
|
21
|
-
this.kind = "ObjectType";
|
|
22
35
|
this.abstract = abstract;
|
|
23
36
|
this.comment = comment;
|
|
24
37
|
this.declarationType = declarationType;
|
|
@@ -31,7 +44,7 @@ export class ObjectType extends DeclaredType {
|
|
|
31
44
|
this.lazyDescendantObjectTypes = lazyDescendantObjectTypes;
|
|
32
45
|
this.lazyParentObjectTypes = lazyParentObjectTypes;
|
|
33
46
|
this.lazyProperties = lazyProperties;
|
|
34
|
-
this.
|
|
47
|
+
this.identifierMintingStrategy = identifierMintingStrategy;
|
|
35
48
|
this.toRdfTypes = toRdfTypes;
|
|
36
49
|
}
|
|
37
50
|
get _discriminatorProperty() {
|
|
@@ -26,9 +26,13 @@ import { tsComment } from "./tsComment.js";
|
|
|
26
26
|
* It also generates SPARQL graph patterns that UNION the member object types.
|
|
27
27
|
*/
|
|
28
28
|
export class ObjectUnionType extends DeclaredType {
|
|
29
|
+
kind = "ObjectUnionType";
|
|
30
|
+
_discriminatorProperty;
|
|
31
|
+
comment;
|
|
32
|
+
label;
|
|
33
|
+
memberTypes;
|
|
29
34
|
constructor({ comment, label, memberTypes, ...superParameters }) {
|
|
30
35
|
super(superParameters);
|
|
31
|
-
this.kind = "ObjectUnionType";
|
|
32
36
|
this.comment = comment;
|
|
33
37
|
this.label = label;
|
|
34
38
|
invariant(memberTypes.length > 0);
|
|
@@ -9,9 +9,10 @@ import { Import } from "./Import.js";
|
|
|
9
9
|
import { SnippetDeclarations } from "./SnippetDeclarations.js";
|
|
10
10
|
import { Type } from "./Type.js";
|
|
11
11
|
export class OptionType extends Type {
|
|
12
|
+
itemType;
|
|
13
|
+
kind = "OptionType";
|
|
12
14
|
constructor({ itemType, ...superParameters }) {
|
|
13
15
|
super(superParameters);
|
|
14
|
-
this.kind = "OptionType";
|
|
15
16
|
this.itemType = itemType;
|
|
16
17
|
}
|
|
17
18
|
get conversions() {
|
|
@@ -80,7 +81,9 @@ export class OptionType extends Type {
|
|
|
80
81
|
return `${this.itemType.jsonZodSchema(parameters)}.optional()`;
|
|
81
82
|
}
|
|
82
83
|
snippetDeclarations(features) {
|
|
83
|
-
const snippetDeclarations =
|
|
84
|
+
const snippetDeclarations = this.itemType
|
|
85
|
+
.snippetDeclarations(features)
|
|
86
|
+
.concat();
|
|
84
87
|
if (features.has("equals")) {
|
|
85
88
|
snippetDeclarations.push(SnippetDeclarations.maybeEquals);
|
|
86
89
|
}
|
|
@@ -2,9 +2,11 @@ import { Maybe } from "purify-ts";
|
|
|
2
2
|
import { LiteralType } from "./LiteralType.js";
|
|
3
3
|
import { SnippetDeclarations } from "./SnippetDeclarations.js";
|
|
4
4
|
export class PrimitiveType extends LiteralType {
|
|
5
|
+
equalsFunction = "strictEquals";
|
|
6
|
+
primitiveDefaultValue;
|
|
7
|
+
primitiveIn;
|
|
5
8
|
constructor({ primitiveDefaultValue, primitiveIn, ...superParameters }) {
|
|
6
9
|
super(superParameters);
|
|
7
|
-
this.equalsFunction = "strictEquals";
|
|
8
10
|
this.primitiveDefaultValue = primitiveDefaultValue;
|
|
9
11
|
this.primitiveIn = primitiveIn;
|
|
10
12
|
}
|
|
@@ -5,8 +5,10 @@ export declare class SetType extends Type {
|
|
|
5
5
|
readonly itemType: Type;
|
|
6
6
|
readonly kind = "SetType";
|
|
7
7
|
private readonly minCount;
|
|
8
|
-
|
|
8
|
+
private readonly _mutable;
|
|
9
|
+
constructor({ itemType, minCount, mutable, ...superParameters }: ConstructorParameters<typeof Type>[0] & {
|
|
9
10
|
itemType: Type;
|
|
11
|
+
mutable: boolean;
|
|
10
12
|
minCount: number;
|
|
11
13
|
});
|
|
12
14
|
get conversions(): readonly Type.Conversion[];
|
|
@@ -10,12 +10,16 @@ import { SnippetDeclarations } from "./SnippetDeclarations.js";
|
|
|
10
10
|
import { Type } from "./Type.js";
|
|
11
11
|
import { objectInitializer } from "./objectInitializer.js";
|
|
12
12
|
export class SetType extends Type {
|
|
13
|
-
|
|
13
|
+
itemType;
|
|
14
|
+
kind = "SetType";
|
|
15
|
+
minCount;
|
|
16
|
+
_mutable;
|
|
17
|
+
constructor({ itemType, minCount, mutable, ...superParameters }) {
|
|
14
18
|
super(superParameters);
|
|
15
|
-
this.kind = "SetType";
|
|
16
19
|
this.itemType = itemType;
|
|
17
20
|
this.minCount = minCount;
|
|
18
21
|
invariant(this.minCount >= 0);
|
|
22
|
+
this._mutable = mutable;
|
|
19
23
|
}
|
|
20
24
|
get conversions() {
|
|
21
25
|
const conversions = [];
|
|
@@ -44,15 +48,15 @@ export class SetType extends Type {
|
|
|
44
48
|
return `((left, right) => arrayEquals(left, right, ${this.itemType.equalsFunction}))`;
|
|
45
49
|
}
|
|
46
50
|
get jsonName() {
|
|
47
|
-
|
|
48
|
-
return `readonly (${this.itemType.jsonName})[]`;
|
|
49
|
-
}
|
|
50
|
-
return `purify.NonEmptyList<${this.itemType.jsonName}>`;
|
|
51
|
+
return `readonly (${this.itemType.jsonName})[]`;
|
|
51
52
|
}
|
|
52
53
|
get mutable() {
|
|
53
|
-
return this.itemType.mutable;
|
|
54
|
+
return this._mutable || this.itemType.mutable;
|
|
54
55
|
}
|
|
55
56
|
get name() {
|
|
57
|
+
if (this._mutable) {
|
|
58
|
+
return `(${this.itemType.name})[]`;
|
|
59
|
+
}
|
|
56
60
|
if (this.minCount === 0) {
|
|
57
61
|
return `readonly (${this.itemType.name})[]`;
|
|
58
62
|
}
|
|
@@ -60,7 +64,7 @@ export class SetType extends Type {
|
|
|
60
64
|
}
|
|
61
65
|
fromJsonExpression({ variables, }) {
|
|
62
66
|
let expression = variables.value;
|
|
63
|
-
if (this.minCount > 0) {
|
|
67
|
+
if (!this._mutable && this.minCount > 0) {
|
|
64
68
|
expression = `purify.NonEmptyList.fromArray(${expression}).unsafeCoerce()`;
|
|
65
69
|
}
|
|
66
70
|
const itemFromJsonExpression = this.itemType.fromJsonExpression({
|
|
@@ -74,7 +78,7 @@ export class SetType extends Type {
|
|
|
74
78
|
const itemFromRdfExpression = this.itemType.fromRdfExpression({
|
|
75
79
|
variables: { ...variables, resourceValues: "_item.toValues()" },
|
|
76
80
|
});
|
|
77
|
-
if (this.minCount === 0) {
|
|
81
|
+
if (this._mutable || this.minCount === 0) {
|
|
78
82
|
return `purify.Either.of([...${variables.resourceValues}.flatMap(_item => ${itemFromRdfExpression}.toMaybe().toList())])`;
|
|
79
83
|
}
|
|
80
84
|
return `purify.NonEmptyList.fromArray([...${variables.resourceValues}.flatMap(_item => ${itemFromRdfExpression}.toMaybe().toList())]).toEither(new rdfjsResource.Resource.ValueError(${objectInitializer({ focusResource: variables.resource, message: `\`\${rdfjsResource.Resource.Identifier.toString(${variables.resource}.identifier)} is empty\``, predicate: variables.predicate })}))`;
|
|
@@ -103,7 +107,9 @@ export class SetType extends Type {
|
|
|
103
107
|
return schema;
|
|
104
108
|
}
|
|
105
109
|
snippetDeclarations(features) {
|
|
106
|
-
const snippetDeclarations =
|
|
110
|
+
const snippetDeclarations = this.itemType
|
|
111
|
+
.snippetDeclarations(features)
|
|
112
|
+
.concat();
|
|
107
113
|
if (features.has("equals")) {
|
|
108
114
|
snippetDeclarations.push(SnippetDeclarations.arrayEquals);
|
|
109
115
|
}
|
|
@@ -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 StringType extends PrimitiveType {
|
|
11
|
-
|
|
12
|
-
super(...arguments);
|
|
13
|
-
this.kind = "StringType";
|
|
14
|
-
}
|
|
11
|
+
kind = "StringType";
|
|
15
12
|
get conversions() {
|
|
16
13
|
const conversions = [
|
|
17
14
|
{
|
|
@@ -16,10 +16,14 @@ import { objectInitializer } from "./objectInitializer.js";
|
|
|
16
16
|
* Abstract base class for IdentifierType and LiteralType.
|
|
17
17
|
*/
|
|
18
18
|
export class TermType extends Type {
|
|
19
|
+
defaultValue;
|
|
20
|
+
equalsFunction = "booleanEquals";
|
|
21
|
+
hasValues;
|
|
22
|
+
in_;
|
|
23
|
+
mutable = false;
|
|
24
|
+
nodeKinds;
|
|
19
25
|
constructor({ defaultValue, hasValues, in_, nodeKinds, ...superParameters }) {
|
|
20
26
|
super(superParameters);
|
|
21
|
-
this.equalsFunction = "booleanEquals";
|
|
22
|
-
this.mutable = false;
|
|
23
27
|
this.defaultValue = defaultValue;
|
|
24
28
|
this.hasValues = hasValues;
|
|
25
29
|
this.in_ = in_;
|
|
@@ -30,15 +34,15 @@ export class TermType extends Type {
|
|
|
30
34
|
const conversions = [];
|
|
31
35
|
if (this.nodeKinds.has("Literal")) {
|
|
32
36
|
conversions.push({
|
|
33
|
-
conversionExpression: (value) => `rdfLiteral.toRdf(${value})`,
|
|
37
|
+
conversionExpression: (value) => `rdfLiteral.toRdf(${value}, ${objectInitializer({ dataFactory: this.dataFactoryVariable })})`,
|
|
34
38
|
sourceTypeCheckExpression: (value) => `typeof ${value} === "boolean"`,
|
|
35
39
|
sourceTypeName: "boolean",
|
|
36
40
|
}, {
|
|
37
|
-
conversionExpression: (value) => `rdfLiteral.toRdf(${value})`,
|
|
41
|
+
conversionExpression: (value) => `rdfLiteral.toRdf(${value}, ${objectInitializer({ dataFactory: this.dataFactoryVariable })})`,
|
|
38
42
|
sourceTypeCheckExpression: (value) => `typeof ${value} === "object" && ${value} instanceof Date`,
|
|
39
43
|
sourceTypeName: "Date",
|
|
40
44
|
}, {
|
|
41
|
-
conversionExpression: (value) => `rdfLiteral.toRdf(${value})`,
|
|
45
|
+
conversionExpression: (value) => `rdfLiteral.toRdf(${value}, ${objectInitializer({ dataFactory: this.dataFactoryVariable })})`,
|
|
42
46
|
sourceTypeCheckExpression: (value) => `typeof ${value} === "number"`,
|
|
43
47
|
sourceTypeName: "number",
|
|
44
48
|
}, {
|
|
@@ -8,6 +8,7 @@ import { objectInitializer } from "./objectInitializer.js";
|
|
|
8
8
|
* Subclasses are used for both property types (c.f., property* methods) and node/object types.
|
|
9
9
|
*/
|
|
10
10
|
export class Type {
|
|
11
|
+
dataFactoryVariable;
|
|
11
12
|
constructor({ dataFactoryVariable, }) {
|
|
12
13
|
this.dataFactoryVariable = dataFactoryVariable;
|
|
13
14
|
}
|