@shaclmate/compiler 2.0.13 → 2.0.14
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 +165 -0
- package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstCompositeType.d.ts +13 -0
- package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstCompositeType.js +198 -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 +17 -0
- package/generators/ts/DateTimeType.js +58 -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 +18 -0
- package/generators/ts/Import.js +59 -0
- package/generators/ts/ListType.d.ts +18 -8
- package/generators/ts/ListType.js +197 -43
- 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 +47 -25
- package/generators/ts/ObjectType.js +222 -49
- package/generators/ts/ObjectUnionType.d.ts +58 -0
- package/generators/ts/ObjectUnionType.js +481 -0
- package/generators/ts/OptionType.d.ts +12 -4
- package/generators/ts/OptionType.js +65 -16
- package/generators/ts/PrimitiveType.d.ts +15 -5
- package/generators/ts/PrimitiveType.js +20 -29
- package/generators/ts/SetType.d.ts +12 -4
- package/generators/ts/SetType.js +103 -29
- package/generators/ts/StringType.d.ts +8 -3
- package/generators/ts/StringType.js +57 -3
- package/generators/ts/TermType.d.ts +52 -0
- package/generators/ts/TermType.js +234 -0
- package/generators/ts/TsGenerator.d.ts +4 -12
- package/generators/ts/TsGenerator.js +44 -100
- package/generators/ts/Type.d.ts +107 -46
- package/generators/ts/Type.js +78 -61
- package/generators/ts/TypeFactory.d.ts +4 -5
- package/generators/ts/TypeFactory.js +212 -89
- package/generators/ts/UnionType.d.ts +19 -6
- package/generators/ts/UnionType.js +230 -120
- package/generators/ts/_ObjectType/IdentifierProperty.d.ts +27 -7
- package/generators/ts/_ObjectType/IdentifierProperty.js +143 -31
- package/generators/ts/_ObjectType/Property.d.ts +125 -9
- package/generators/ts/_ObjectType/Property.js +25 -3
- package/generators/ts/_ObjectType/ShaclProperty.d.ts +23 -5
- package/generators/ts/_ObjectType/ShaclProperty.js +100 -26
- package/generators/ts/_ObjectType/TypeDiscriminatorProperty.d.ts +24 -6
- package/generators/ts/_ObjectType/TypeDiscriminatorProperty.js +75 -13
- 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/sparqlFunctionDeclarations.d.ts +4 -0
- package/generators/ts/_ObjectType/sparqlFunctionDeclarations.js +101 -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 +274 -0
- package/input/generated.js +1420 -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 +42 -0
- package/package.json +14 -8
- 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
|
@@ -1,101 +1,204 @@
|
|
|
1
1
|
import TermMap from "@rdfjs/term-map";
|
|
2
|
-
import
|
|
3
|
-
import { xsd } from "@tpluscode/rdf-ns-builders";
|
|
2
|
+
import TermSet from "@rdfjs/term-set";
|
|
3
|
+
import { rdf, xsd } from "@tpluscode/rdf-ns-builders";
|
|
4
4
|
import { Maybe } from "purify-ts";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
5
|
+
import { fromRdf } from "rdf-literal";
|
|
6
|
+
import { logger } from "../../logger.js";
|
|
7
|
+
import { BooleanType } from "./BooleanType.js";
|
|
8
|
+
import { DateTimeType } from "./DateTimeType.js";
|
|
9
|
+
import { IdentifierType } from "./IdentifierType.js";
|
|
8
10
|
import { ListType } from "./ListType.js";
|
|
9
11
|
import { LiteralType } from "./LiteralType.js";
|
|
10
12
|
import { NumberType } from "./NumberType.js";
|
|
11
13
|
import { ObjectType } from "./ObjectType.js";
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
+
import { ObjectUnionType } from "./ObjectUnionType.js";
|
|
15
|
+
import { OptionType } from "./OptionType.js";
|
|
16
|
+
import { SetType } from "./SetType.js";
|
|
14
17
|
import { StringType } from "./StringType.js";
|
|
15
|
-
import {
|
|
18
|
+
import { TermType } from "./TermType.js";
|
|
19
|
+
import { UnionType } from "./UnionType.js";
|
|
16
20
|
import { tsName } from "./tsName.js";
|
|
17
21
|
export class TypeFactory {
|
|
18
|
-
constructor({
|
|
22
|
+
constructor({ dataFactoryVariable }) {
|
|
19
23
|
this.cachedObjectTypePropertiesByIdentifier = new TermMap();
|
|
20
24
|
this.cachedObjectTypesByIdentifier = new TermMap();
|
|
21
|
-
this.
|
|
25
|
+
this.dataFactoryVariable = dataFactoryVariable;
|
|
22
26
|
}
|
|
23
27
|
createTypeFromAstType(astType) {
|
|
24
28
|
switch (astType.kind) {
|
|
25
29
|
case "IdentifierType":
|
|
26
30
|
return new IdentifierType({
|
|
27
|
-
|
|
31
|
+
dataFactoryVariable: this.dataFactoryVariable,
|
|
28
32
|
defaultValue: astType.defaultValue,
|
|
29
|
-
|
|
33
|
+
hasValues: astType.hasValues,
|
|
34
|
+
in_: astType.in_,
|
|
30
35
|
nodeKinds: astType.nodeKinds,
|
|
31
36
|
});
|
|
32
37
|
case "IntersectionType":
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
38
|
+
throw new Error("not implemented");
|
|
39
|
+
case "ListType": {
|
|
40
|
+
return new ListType({
|
|
41
|
+
dataFactoryVariable: this.dataFactoryVariable,
|
|
42
|
+
identifierNodeKind: astType.identifierNodeKind,
|
|
43
|
+
itemType: this.createTypeFromAstType(astType.itemType),
|
|
44
|
+
mutable: astType.mutable.orDefault(false),
|
|
45
|
+
mintingStrategy: astType.mintingStrategy,
|
|
46
|
+
toRdfTypes: astType.toRdfTypes,
|
|
36
47
|
});
|
|
48
|
+
}
|
|
37
49
|
case "LiteralType": {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
50
|
+
// Look at sh:datatype as well as sh:defaultValue/sh:hasValue/sh:in term datatypes
|
|
51
|
+
// If there's one common datatype than we can refine the type
|
|
52
|
+
// Otherwise default to rdfjs.Literal
|
|
53
|
+
const datatypes = new TermSet();
|
|
54
|
+
astType.datatype.ifJust((datatype) => datatypes.add(datatype));
|
|
55
|
+
astType.defaultValue.ifJust((defaultValue) => datatypes.add(defaultValue.datatype));
|
|
56
|
+
for (const hasValue of astType.hasValues) {
|
|
57
|
+
datatypes.add(hasValue.datatype);
|
|
58
|
+
}
|
|
59
|
+
for (const value of astType.in_) {
|
|
60
|
+
datatypes.add(value.datatype);
|
|
61
|
+
}
|
|
62
|
+
if (datatypes.size === 1) {
|
|
63
|
+
const datatype = [...datatypes][0];
|
|
43
64
|
if (datatype.equals(xsd.boolean)) {
|
|
44
65
|
return new BooleanType({
|
|
45
|
-
|
|
66
|
+
dataFactoryVariable: this.dataFactoryVariable,
|
|
46
67
|
defaultValue: astType.defaultValue,
|
|
47
|
-
|
|
68
|
+
hasValues: astType.hasValues,
|
|
69
|
+
languageIn: [],
|
|
70
|
+
in_: astType.in_,
|
|
71
|
+
primitiveDefaultValue: astType.defaultValue
|
|
72
|
+
.map((value) => fromRdf(value, true))
|
|
73
|
+
.filter((value) => typeof value === "boolean"),
|
|
74
|
+
primitiveIn: astType.in_
|
|
75
|
+
.map((value) => fromRdf(value, true))
|
|
76
|
+
.filter((value) => typeof value === "boolean"),
|
|
48
77
|
});
|
|
49
78
|
}
|
|
50
|
-
if (datatype.equals(xsd.
|
|
51
|
-
return new
|
|
52
|
-
|
|
79
|
+
if (datatype.equals(xsd.dateTime)) {
|
|
80
|
+
return new DateTimeType({
|
|
81
|
+
dataFactoryVariable: this.dataFactoryVariable,
|
|
53
82
|
defaultValue: astType.defaultValue,
|
|
54
|
-
|
|
83
|
+
hasValues: astType.hasValues,
|
|
84
|
+
in_: astType.in_,
|
|
85
|
+
languageIn: [],
|
|
86
|
+
primitiveDefaultValue: astType.defaultValue
|
|
87
|
+
.map((value) => fromRdf(value, true))
|
|
88
|
+
.filter((value) => typeof value === "object" && value instanceof Date),
|
|
89
|
+
primitiveIn: astType.in_
|
|
90
|
+
.map((value) => fromRdf(value, true))
|
|
91
|
+
.filter((value) => typeof value === "object" && value instanceof Date),
|
|
55
92
|
});
|
|
56
93
|
}
|
|
94
|
+
for (const numberDatatype of [
|
|
95
|
+
// Integers
|
|
96
|
+
xsd.byte,
|
|
97
|
+
xsd.int,
|
|
98
|
+
xsd.integer,
|
|
99
|
+
xsd.long,
|
|
100
|
+
xsd.negativeInteger,
|
|
101
|
+
xsd.nonNegativeInteger,
|
|
102
|
+
xsd.nonPositiveInteger,
|
|
103
|
+
xsd.positiveInteger,
|
|
104
|
+
xsd.short,
|
|
105
|
+
xsd.unsignedByte,
|
|
106
|
+
xsd.unsignedInt,
|
|
107
|
+
xsd.unsignedLong,
|
|
108
|
+
xsd.unsignedShort,
|
|
109
|
+
// Floating point
|
|
110
|
+
xsd.decimal,
|
|
111
|
+
xsd.double,
|
|
112
|
+
xsd.float,
|
|
113
|
+
]) {
|
|
114
|
+
if (datatype.equals(numberDatatype)) {
|
|
115
|
+
return new NumberType({
|
|
116
|
+
dataFactoryVariable: this.dataFactoryVariable,
|
|
117
|
+
defaultValue: astType.defaultValue,
|
|
118
|
+
hasValues: astType.hasValues,
|
|
119
|
+
in_: astType.in_,
|
|
120
|
+
languageIn: [],
|
|
121
|
+
primitiveDefaultValue: astType.defaultValue
|
|
122
|
+
.map((value) => fromRdf(value, true))
|
|
123
|
+
.filter((value) => typeof value === "number"),
|
|
124
|
+
primitiveIn: astType.in_
|
|
125
|
+
.map((value) => fromRdf(value, true))
|
|
126
|
+
.filter((value) => typeof value === "number"),
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
}
|
|
57
130
|
if (datatype.equals(xsd.anyURI) || datatype.equals(xsd.string)) {
|
|
58
131
|
return new StringType({
|
|
59
|
-
|
|
132
|
+
dataFactoryVariable: this.dataFactoryVariable,
|
|
60
133
|
defaultValue: astType.defaultValue,
|
|
61
|
-
|
|
134
|
+
hasValues: astType.hasValues,
|
|
135
|
+
languageIn: [],
|
|
136
|
+
in_: astType.in_,
|
|
137
|
+
primitiveDefaultValue: astType.defaultValue.map((value) => value.value),
|
|
138
|
+
primitiveIn: astType.in_.map((value) => value.value),
|
|
62
139
|
});
|
|
63
140
|
}
|
|
141
|
+
if (datatype.equals(rdf.langString)) {
|
|
142
|
+
// Drop down
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
logger.warn("unrecognized literal datatype: %s", datatype.value);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
else if (datatypes.size > 0) {
|
|
149
|
+
logger.warn("literal type has multiple datatypes: %s", JSON.stringify([...datatypes].map((datatype) => datatype.value)));
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
logger.debug("literal type has no datatypes");
|
|
64
153
|
}
|
|
65
154
|
return new LiteralType({
|
|
66
|
-
|
|
155
|
+
dataFactoryVariable: this.dataFactoryVariable,
|
|
67
156
|
defaultValue: astType.defaultValue,
|
|
68
|
-
|
|
157
|
+
hasValues: astType.hasValues,
|
|
158
|
+
in_: astType.in_,
|
|
159
|
+
languageIn: astType.languageIn,
|
|
69
160
|
});
|
|
70
161
|
}
|
|
71
|
-
case "
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
configuration: this.configuration,
|
|
75
|
-
identifierNodeKind: astType.nodeKinds.has(NodeKind.BLANK_NODE)
|
|
76
|
-
? NodeKind.BLANK_NODE
|
|
77
|
-
: NodeKind.IRI,
|
|
78
|
-
itemType: this.createTypeFromAstType(astType.listItemType.unsafeCoerce()),
|
|
79
|
-
mintingStrategy: astType.mintingStrategy,
|
|
80
|
-
rdfType: astType.rdfType,
|
|
81
|
-
});
|
|
82
|
-
}
|
|
162
|
+
case "ObjectIntersectionType":
|
|
163
|
+
throw new Error("not implemented");
|
|
164
|
+
case "ObjectType":
|
|
83
165
|
return this.createObjectTypeFromAstType(astType);
|
|
84
|
-
|
|
166
|
+
case "ObjectUnionType":
|
|
167
|
+
return new ObjectUnionType({
|
|
168
|
+
comment: astType.comment,
|
|
169
|
+
dataFactoryVariable: this.dataFactoryVariable,
|
|
170
|
+
export_: astType.export,
|
|
171
|
+
features: astType.tsFeatures,
|
|
172
|
+
label: astType.label,
|
|
173
|
+
memberTypes: astType.memberTypes
|
|
174
|
+
.map((astType) => this.createTypeFromAstType(astType))
|
|
175
|
+
.filter((memberType) => memberType instanceof ObjectType),
|
|
176
|
+
name: tsName(astType.name),
|
|
177
|
+
});
|
|
85
178
|
case "OptionType":
|
|
86
179
|
return new OptionType({
|
|
87
|
-
|
|
180
|
+
dataFactoryVariable: this.dataFactoryVariable,
|
|
88
181
|
itemType: this.createTypeFromAstType(astType.itemType),
|
|
89
182
|
});
|
|
183
|
+
case "PlaceholderType":
|
|
184
|
+
throw new Error(astType.kind);
|
|
90
185
|
case "SetType":
|
|
91
186
|
return new SetType({
|
|
92
|
-
|
|
187
|
+
dataFactoryVariable: this.dataFactoryVariable,
|
|
93
188
|
itemType: this.createTypeFromAstType(astType.itemType),
|
|
94
189
|
minCount: astType.minCount,
|
|
95
190
|
});
|
|
191
|
+
case "TermType":
|
|
192
|
+
return new TermType({
|
|
193
|
+
dataFactoryVariable: this.dataFactoryVariable,
|
|
194
|
+
defaultValue: astType.defaultValue,
|
|
195
|
+
hasValues: astType.hasValues,
|
|
196
|
+
in_: astType.in_,
|
|
197
|
+
nodeKinds: astType.nodeKinds,
|
|
198
|
+
});
|
|
96
199
|
case "UnionType":
|
|
97
200
|
return new UnionType({
|
|
98
|
-
|
|
201
|
+
dataFactoryVariable: this.dataFactoryVariable,
|
|
99
202
|
memberTypes: astType.memberTypes.map((astType) => this.createTypeFromAstType(astType)),
|
|
100
203
|
});
|
|
101
204
|
}
|
|
@@ -108,29 +211,57 @@ export class TypeFactory {
|
|
|
108
211
|
}
|
|
109
212
|
}
|
|
110
213
|
const identifierType = new IdentifierType({
|
|
111
|
-
|
|
214
|
+
dataFactoryVariable: this.dataFactoryVariable,
|
|
112
215
|
defaultValue: Maybe.empty(),
|
|
113
|
-
|
|
216
|
+
hasValues: [],
|
|
217
|
+
in_: [],
|
|
114
218
|
nodeKinds: astType.nodeKinds,
|
|
115
219
|
});
|
|
116
220
|
const objectType = new ObjectType({
|
|
117
221
|
abstract: astType.abstract,
|
|
118
|
-
|
|
222
|
+
comment: astType.comment,
|
|
223
|
+
dataFactoryVariable: this.dataFactoryVariable,
|
|
224
|
+
declarationType: astType.tsObjectDeclarationType,
|
|
119
225
|
export_: astType.export,
|
|
120
|
-
|
|
226
|
+
extern: astType.extern,
|
|
227
|
+
features: astType.tsFeatures,
|
|
228
|
+
fromRdfType: astType.fromRdfType,
|
|
229
|
+
imports: astType.tsImports,
|
|
230
|
+
label: astType.label,
|
|
121
231
|
lazyAncestorObjectTypes: () => astType.ancestorObjectTypes.map((astType) => this.createObjectTypeFromAstType(astType)),
|
|
122
232
|
lazyDescendantObjectTypes: () => astType.descendantObjectTypes.map((astType) => this.createObjectTypeFromAstType(astType)),
|
|
123
233
|
lazyParentObjectTypes: () => astType.parentObjectTypes.map((astType) => this.createObjectTypeFromAstType(astType)),
|
|
124
234
|
lazyProperties: () => {
|
|
125
235
|
const properties = astType.properties.map((astProperty) => this.createObjectTypePropertyFromAstProperty(astProperty));
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
236
|
+
let identifierPropertyClassDeclarationVisibility;
|
|
237
|
+
if (astType.abstract) {
|
|
238
|
+
// If the type is abstract, don't declare a property.
|
|
239
|
+
identifierPropertyClassDeclarationVisibility = Maybe.empty();
|
|
240
|
+
}
|
|
241
|
+
else if (astType.ancestorObjectTypes.some((ancestorObjectType) => !ancestorObjectType.abstract)) {
|
|
242
|
+
// If the type has a non-abstract ancestor, that ancestor will declare the identifier property
|
|
243
|
+
identifierPropertyClassDeclarationVisibility = Maybe.empty();
|
|
244
|
+
}
|
|
245
|
+
else if (astType.descendantObjectTypes.some((descendantObjectType) => !descendantObjectType.abstract)) {
|
|
246
|
+
// If the type has a non-abstract descendant, declare the identifier property for it
|
|
247
|
+
identifierPropertyClassDeclarationVisibility = Maybe.of("protected");
|
|
248
|
+
}
|
|
249
|
+
else {
|
|
250
|
+
identifierPropertyClassDeclarationVisibility = Maybe.of("private");
|
|
251
|
+
}
|
|
252
|
+
const identifierProperty = new ObjectType.IdentifierProperty({
|
|
253
|
+
abstract: astType.abstract,
|
|
254
|
+
classDeclarationVisibility: identifierPropertyClassDeclarationVisibility,
|
|
255
|
+
dataFactoryVariable: this.dataFactoryVariable,
|
|
256
|
+
mintingStrategy: astType.mintingStrategy,
|
|
257
|
+
name: astType.tsIdentifierPropertyName,
|
|
258
|
+
lazyObjectTypeMutable: () => properties.some((property) => property.mutable || property.type.mutable),
|
|
259
|
+
objectTypeDeclarationType: astType.tsObjectDeclarationType,
|
|
260
|
+
override: astType.parentObjectTypes.length > 0,
|
|
261
|
+
type: identifierType,
|
|
262
|
+
visibility: "public",
|
|
263
|
+
});
|
|
264
|
+
properties.push(identifierProperty);
|
|
134
265
|
// Type discriminator property
|
|
135
266
|
const typeDiscriminatorValues = new Set();
|
|
136
267
|
if (!astType.abstract) {
|
|
@@ -141,25 +272,26 @@ export class TypeFactory {
|
|
|
141
272
|
typeDiscriminatorValues.add(descendantObjectType.discriminatorValue);
|
|
142
273
|
}
|
|
143
274
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
.
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
275
|
+
if (typeDiscriminatorValues.size > 0) {
|
|
276
|
+
properties.push(new ObjectType.TypeDiscriminatorProperty({
|
|
277
|
+
abstract: astType.abstract,
|
|
278
|
+
dataFactoryVariable: this.dataFactoryVariable,
|
|
279
|
+
name: astType.tsTypeDiscriminatorPropertyName,
|
|
280
|
+
objectTypeDeclarationType: objectType.declarationType,
|
|
281
|
+
override: objectType.parentObjectTypes.length > 0,
|
|
282
|
+
type: new ObjectType.TypeDiscriminatorProperty.Type({
|
|
283
|
+
mutable: false,
|
|
284
|
+
values: [...typeDiscriminatorValues].sort(),
|
|
285
|
+
}),
|
|
286
|
+
visibility: "public",
|
|
287
|
+
value: objectType.discriminatorValue,
|
|
288
|
+
}));
|
|
289
|
+
}
|
|
158
290
|
return properties.sort((left, right) => left.name.localeCompare(right.name));
|
|
159
291
|
},
|
|
160
292
|
mintingStrategy: astType.mintingStrategy,
|
|
161
293
|
name: tsName(astType.name),
|
|
162
|
-
|
|
294
|
+
toRdfTypes: astType.toRdfTypes,
|
|
163
295
|
});
|
|
164
296
|
this.cachedObjectTypesByIdentifier.set(astType.name.identifier, objectType);
|
|
165
297
|
return objectType;
|
|
@@ -171,25 +303,16 @@ export class TypeFactory {
|
|
|
171
303
|
return cachedProperty;
|
|
172
304
|
}
|
|
173
305
|
}
|
|
174
|
-
let type;
|
|
175
|
-
if (astObjectTypeProperty.type.kind === "ObjectType" &&
|
|
176
|
-
!astObjectTypeProperty.inline) {
|
|
177
|
-
// Non-inlined object type = its identifier
|
|
178
|
-
type = new IdentifierType({
|
|
179
|
-
configuration: this.configuration,
|
|
180
|
-
defaultValue: Maybe.empty(),
|
|
181
|
-
hasValue: Maybe.empty(),
|
|
182
|
-
nodeKinds: astObjectTypeProperty.type.nodeKinds,
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
else {
|
|
186
|
-
type = this.createTypeFromAstType(astObjectTypeProperty.type);
|
|
187
|
-
}
|
|
188
306
|
const property = new ObjectType.ShaclProperty({
|
|
189
|
-
|
|
307
|
+
comment: astObjectTypeProperty.comment,
|
|
308
|
+
dataFactoryVariable: this.dataFactoryVariable,
|
|
309
|
+
description: astObjectTypeProperty.description,
|
|
310
|
+
label: astObjectTypeProperty.label,
|
|
311
|
+
mutable: astObjectTypeProperty.mutable.orDefault(false),
|
|
190
312
|
name: tsName(astObjectTypeProperty.name),
|
|
191
313
|
path: astObjectTypeProperty.path.iri,
|
|
192
|
-
type,
|
|
314
|
+
type: this.createTypeFromAstType(astObjectTypeProperty.type),
|
|
315
|
+
visibility: astObjectTypeProperty.visibility,
|
|
193
316
|
});
|
|
194
317
|
this.cachedObjectTypePropertiesByIdentifier.set(astObjectTypeProperty.name.identifier, property);
|
|
195
318
|
return property;
|
|
@@ -1,18 +1,31 @@
|
|
|
1
1
|
import { Maybe } from "purify-ts";
|
|
2
|
+
import type { Import } from "./Import.js";
|
|
2
3
|
import { Type } from "./Type.js";
|
|
3
4
|
export declare class UnionType extends Type {
|
|
4
5
|
readonly kind = "UnionType";
|
|
5
6
|
readonly memberTypes: readonly Type[];
|
|
6
|
-
constructor({ memberTypes, ...superParameters }: ConstructorParameters<typeof Type>[0] & {
|
|
7
|
+
constructor({ memberTypes, name, ...superParameters }: ConstructorParameters<typeof Type>[0] & {
|
|
7
8
|
memberTypes: readonly Type[];
|
|
9
|
+
name?: string;
|
|
8
10
|
});
|
|
9
|
-
|
|
11
|
+
private _name?;
|
|
10
12
|
get name(): string;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
+
get conversions(): readonly Type.Conversion[];
|
|
14
|
+
get discriminatorProperty(): Maybe<Type.DiscriminatorProperty>;
|
|
15
|
+
get equalsFunction(): string;
|
|
16
|
+
get jsonName(): string;
|
|
17
|
+
get mutable(): boolean;
|
|
18
|
+
get useImports(): readonly Import[];
|
|
19
|
+
private get _discriminatorProperty();
|
|
20
|
+
private get memberTypeTraits();
|
|
21
|
+
fromJsonExpression({ variables, }: Parameters<Type["fromJsonExpression"]>[0]): string;
|
|
13
22
|
fromRdfExpression(parameters: Parameters<Type["fromRdfExpression"]>[0]): string;
|
|
14
|
-
hashStatements({ variables, }: Parameters<Type["hashStatements"]>[0]): readonly string[];
|
|
15
|
-
|
|
23
|
+
hashStatements({ depth, variables, }: Parameters<Type["hashStatements"]>[0]): readonly string[];
|
|
24
|
+
jsonZodSchema({ variables, }: Parameters<Type["jsonZodSchema"]>[0]): ReturnType<Type["jsonZodSchema"]>;
|
|
25
|
+
sparqlConstructTemplateTriples(parameters: Parameters<Type["sparqlConstructTemplateTriples"]>[0]): readonly string[];
|
|
26
|
+
sparqlWherePatterns(parameters: Parameters<Type["sparqlWherePatterns"]>[0]): readonly string[];
|
|
27
|
+
toJsonExpression({ variables, }: Parameters<Type["toJsonExpression"]>[0]): string;
|
|
16
28
|
toRdfExpression({ variables, }: Parameters<Type["toRdfExpression"]>[0]): string;
|
|
29
|
+
private ternaryExpression;
|
|
17
30
|
}
|
|
18
31
|
//# sourceMappingURL=UnionType.d.ts.map
|