@shaclmate/compiler 2.0.22 → 2.0.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ShapesGraphToAstTransformer.d.ts +6 -5
- package/dist/ShapesGraphToAstTransformer.js +61 -17
- package/dist/_ShapesGraphToAstTransformer/InheritableShapeConstraints.d.ts +2 -0
- package/dist/_ShapesGraphToAstTransformer/InheritableShapeConstraints.js +2 -0
- package/dist/_ShapesGraphToAstTransformer/ShapeStack.d.ts +15 -0
- package/dist/_ShapesGraphToAstTransformer/ShapeStack.js +51 -0
- package/dist/_ShapesGraphToAstTransformer/flattenAstObjectCompositeTypeMemberTypes.d.ts +13 -0
- package/dist/_ShapesGraphToAstTransformer/flattenAstObjectCompositeTypeMemberTypes.js +51 -0
- package/dist/_ShapesGraphToAstTransformer/index.d.ts +5 -5
- package/dist/_ShapesGraphToAstTransformer/index.js +5 -5
- package/dist/_ShapesGraphToAstTransformer/shapeAstName.js +53 -12
- package/dist/_ShapesGraphToAstTransformer/transformNodeShapeToAstType.d.ts +5 -0
- package/dist/_ShapesGraphToAstTransformer/transformNodeShapeToAstType.js +130 -54
- package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstObjectTypeProperty.js +175 -5
- package/dist/_ShapesGraphToAstTransformer/transformShapeToAstCompositeType.d.ts +10 -0
- package/dist/_ShapesGraphToAstTransformer/transformShapeToAstCompositeType.js +185 -0
- package/dist/_ShapesGraphToAstTransformer/transformShapeToAstIdentifierType.d.ts +10 -0
- package/dist/_ShapesGraphToAstTransformer/transformShapeToAstIdentifierType.js +32 -0
- package/dist/_ShapesGraphToAstTransformer/transformShapeToAstLiteralType.d.ts +10 -0
- package/dist/_ShapesGraphToAstTransformer/transformShapeToAstLiteralType.js +46 -0
- package/dist/_ShapesGraphToAstTransformer/transformShapeToAstTermType.d.ts +12 -0
- package/dist/_ShapesGraphToAstTransformer/transformShapeToAstTermType.js +24 -0
- package/dist/_ShapesGraphToAstTransformer/transformShapeToAstType.d.ts +13 -0
- package/dist/_ShapesGraphToAstTransformer/transformShapeToAstType.js +14 -0
- package/dist/ast/Ast.d.ts +0 -1
- package/dist/ast/Curie.d.ts +14 -0
- package/dist/ast/Curie.js +21 -0
- package/dist/ast/IdentifierType.d.ts +3 -2
- package/dist/ast/ListType.d.ts +2 -1
- package/dist/ast/LiteralType.d.ts +1 -1
- package/dist/ast/Name.d.ts +40 -5
- package/dist/ast/ObjectCompositeType.d.ts +11 -0
- package/dist/ast/ObjectType.d.ts +18 -13
- package/dist/ast/ObjectUnionType.d.ts +0 -11
- package/dist/ast/OptionType.d.ts +2 -4
- package/dist/ast/SetType.d.ts +2 -7
- package/dist/ast/TermType.d.ts +12 -4
- package/dist/ast/Type.d.ts +1 -1
- package/dist/ast/index.d.ts +1 -0
- package/dist/ast/index.js +1 -0
- package/dist/enums/TsFeature.d.ts +1 -4
- package/dist/enums/TsFeature.js +1 -15
- package/dist/generators/json/AstJsonGenerator.js +26 -4
- package/dist/generators/ts/BooleanType.d.ts +4 -2
- package/dist/generators/ts/BooleanType.js +12 -3
- package/dist/generators/ts/DateTimeType.d.ts +9 -8
- package/dist/generators/ts/DateTimeType.js +32 -8
- package/dist/generators/ts/DateType.d.ts +5 -2
- package/dist/generators/ts/DateType.js +15 -1
- package/dist/generators/ts/DeclaredType.d.ts +2 -2
- package/dist/generators/ts/DeclaredType.js +2 -2
- package/dist/generators/ts/FloatType.d.ts +6 -0
- package/dist/generators/ts/FloatType.js +18 -0
- package/dist/generators/ts/IdentifierType.d.ts +17 -7
- package/dist/generators/ts/IdentifierType.js +112 -18
- package/dist/generators/ts/Import.d.ts +2 -0
- package/dist/generators/ts/Import.js +10 -0
- package/dist/generators/ts/IntType.d.ts +6 -0
- package/dist/generators/ts/IntType.js +18 -0
- package/dist/generators/ts/ListType.d.ts +15 -12
- package/dist/generators/ts/ListType.js +113 -61
- package/dist/generators/ts/LiteralType.d.ts +17 -9
- package/dist/generators/ts/LiteralType.js +92 -17
- package/dist/generators/ts/NumberType.d.ts +3 -2
- package/dist/generators/ts/NumberType.js +8 -3
- package/dist/generators/ts/ObjectType.d.ts +65 -43
- package/dist/generators/ts/ObjectType.js +143 -123
- package/dist/generators/ts/ObjectUnionType.d.ts +50 -8
- package/dist/generators/ts/ObjectUnionType.js +303 -101
- package/dist/generators/ts/OptionType.d.ts +14 -10
- package/dist/generators/ts/OptionType.js +62 -34
- package/dist/generators/ts/PrimitiveType.d.ts +23 -5
- package/dist/generators/ts/PrimitiveType.js +34 -6
- package/dist/generators/ts/SetType.d.ts +17 -13
- package/dist/generators/ts/SetType.js +76 -44
- package/dist/generators/ts/SnippetDeclarations.d.ts +13 -8
- package/dist/generators/ts/SnippetDeclarations.js +226 -101
- package/dist/generators/ts/StringType.d.ts +4 -2
- package/dist/generators/ts/StringType.js +20 -8
- package/dist/generators/ts/TermType.d.ts +29 -33
- package/dist/generators/ts/TermType.js +89 -68
- package/dist/generators/ts/TsGenerator.d.ts +2 -1
- package/dist/generators/ts/TsGenerator.js +26 -12
- package/dist/generators/ts/Type.d.ts +100 -32
- package/dist/generators/ts/Type.js +58 -54
- package/dist/generators/ts/TypeFactory.d.ts +12 -5
- package/dist/generators/ts/TypeFactory.js +380 -226
- package/dist/generators/ts/UnionType.d.ts +14 -10
- package/dist/generators/ts/UnionType.js +319 -142
- package/dist/generators/ts/_ObjectType/EagerShaclProperty.d.ts +12 -0
- package/dist/generators/ts/_ObjectType/EagerShaclProperty.js +31 -0
- package/dist/generators/ts/_ObjectType/IdentifierPrefixProperty.d.ts +13 -12
- package/dist/generators/ts/_ObjectType/IdentifierPrefixProperty.js +59 -46
- package/dist/generators/ts/_ObjectType/IdentifierProperty.d.ts +20 -13
- package/dist/generators/ts/_ObjectType/IdentifierProperty.js +198 -140
- package/dist/generators/ts/_ObjectType/LazyShaclProperty.d.ts +100 -0
- package/dist/generators/ts/_ObjectType/LazyShaclProperty.js +315 -0
- package/dist/generators/ts/_ObjectType/Property.d.ts +47 -46
- package/dist/generators/ts/_ObjectType/Property.js +1 -10
- package/dist/generators/ts/_ObjectType/ShaclProperty.d.ts +25 -30
- package/dist/generators/ts/_ObjectType/ShaclProperty.js +120 -85
- package/dist/generators/ts/_ObjectType/TypeDiscriminatorProperty.d.ts +21 -17
- package/dist/generators/ts/_ObjectType/TypeDiscriminatorProperty.js +61 -53
- package/dist/generators/ts/_ObjectType/classDeclaration.js +22 -17
- package/dist/generators/ts/_ObjectType/createFunctionDeclaration.js +26 -13
- package/dist/generators/ts/_ObjectType/equalsFunctionOrMethodDeclaration.js +8 -5
- package/dist/generators/ts/_ObjectType/fromRdfTypeVariableStatement.d.ts +1 -1
- package/dist/generators/ts/_ObjectType/fromRdfTypeVariableStatement.js +8 -5
- package/dist/generators/ts/_ObjectType/graphqlTypeVariableStatement.d.ts +5 -0
- package/dist/generators/ts/_ObjectType/graphqlTypeVariableStatement.js +49 -0
- package/dist/generators/ts/_ObjectType/hashFunctionOrMethodDeclarations.js +7 -8
- package/dist/generators/ts/_ObjectType/identifierTypeDeclarations.d.ts +7 -0
- package/dist/generators/ts/_ObjectType/identifierTypeDeclarations.js +54 -0
- package/dist/generators/ts/_ObjectType/index.d.ts +9 -7
- package/dist/generators/ts/_ObjectType/index.js +9 -7
- package/dist/generators/ts/_ObjectType/interfaceDeclaration.js +1 -1
- package/dist/generators/ts/_ObjectType/jsonFunctionDeclarations.d.ts +4 -0
- package/dist/generators/ts/_ObjectType/jsonFunctionDeclarations.js +189 -0
- package/dist/generators/ts/_ObjectType/jsonTypeAliasDeclaration.d.ts +5 -0
- package/dist/generators/ts/_ObjectType/jsonTypeAliasDeclaration.js +28 -0
- package/dist/generators/ts/_ObjectType/objectSetMethodNames.d.ts +9 -0
- package/dist/generators/ts/_ObjectType/objectSetMethodNames.js +18 -0
- package/dist/generators/ts/_ObjectType/propertiesVariableStatement.d.ts +5 -0
- package/dist/generators/ts/_ObjectType/propertiesVariableStatement.js +37 -0
- package/dist/generators/ts/_ObjectType/rdfFunctionDeclarations.d.ts +4 -0
- package/dist/generators/ts/_ObjectType/rdfFunctionDeclarations.js +144 -0
- package/dist/generators/ts/_ObjectType/sparqlConstructQueryFunctionDeclaration.d.ts +1 -1
- package/dist/generators/ts/_ObjectType/sparqlConstructQueryFunctionDeclaration.js +6 -5
- package/dist/generators/ts/_ObjectType/sparqlConstructQueryStringFunctionDeclaration.d.ts +1 -1
- package/dist/generators/ts/_ObjectType/sparqlConstructQueryStringFunctionDeclaration.js +4 -3
- package/dist/generators/ts/_ObjectType/sparqlFunctionDeclarations.js +109 -37
- package/dist/generators/ts/_ObjectType/toJsonFunctionOrMethodDeclaration.js +6 -6
- package/dist/generators/ts/_ObjectType/toRdfFunctionOrMethodDeclaration.js +33 -24
- package/dist/generators/ts/graphqlSchemaVariableStatement.d.ts +9 -0
- package/dist/generators/ts/graphqlSchemaVariableStatement.js +86 -0
- package/dist/generators/ts/objectSetDeclarations.d.ts +8 -0
- package/dist/generators/ts/objectSetDeclarations.js +59 -0
- package/dist/generators/ts/objectSetInterfaceDeclaration.d.ts +8 -0
- package/dist/generators/ts/objectSetInterfaceDeclaration.js +46 -0
- package/dist/generators/ts/objectSetMethodSignatures.d.ts +11 -0
- package/dist/generators/ts/objectSetMethodSignatures.js +52 -0
- package/dist/generators/ts/rdfjsDatasetObjectSetClassDeclaration.d.ts +8 -0
- package/dist/generators/ts/rdfjsDatasetObjectSetClassDeclaration.js +393 -0
- package/dist/generators/ts/rdfjsTermExpression.d.ts +3 -0
- package/dist/generators/ts/rdfjsTermExpression.js +57 -0
- package/dist/generators/ts/sparqlObjectSetClassDeclaration.d.ts +8 -0
- package/dist/generators/ts/sparqlObjectSetClassDeclaration.js +415 -0
- package/dist/generators/ts/syntheticNamePrefix.d.ts +2 -0
- package/dist/generators/ts/syntheticNamePrefix.js +2 -0
- package/dist/generators/ts/tsName.js +27 -13
- package/dist/generators/ts/unsupportedObjectSetMethodDeclarations.d.ts +10 -0
- package/dist/generators/ts/unsupportedObjectSetMethodDeclarations.js +19 -0
- package/dist/input/NodeShape.d.ts +6 -8
- package/dist/input/NodeShape.js +20 -44
- package/dist/input/Ontology.d.ts +0 -3
- package/dist/input/Ontology.js +0 -9
- package/dist/input/PropertyPath.d.ts +5 -5
- package/dist/input/PropertyPath.js +14 -24
- package/dist/input/PropertyShape.d.ts +3 -1
- package/dist/input/PropertyShape.js +8 -2
- package/dist/input/ShapesGraph.js +4 -8
- package/dist/input/generated.d.ts +967 -107
- package/dist/input/generated.js +2548 -1046
- package/dist/input/tsFeatures.d.ts +3 -2
- package/dist/input/tsFeatures.js +44 -27
- package/package.json +18 -16
- package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstCompositeType.d.ts +0 -13
- package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstCompositeType.js +0 -200
- package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstIdentifierType.d.ts +0 -12
- package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstIdentifierType.js +0 -29
- package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstLiteralType.d.ts +0 -12
- package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstLiteralType.js +0 -43
- package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstTermType.d.ts +0 -14
- package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstTermType.js +0 -21
- package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstType.d.ts +0 -16
- package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstType.js +0 -60
- package/dist/generators/ts/_ObjectType/fromJsonFunctionDeclarations.d.ts +0 -4
- package/dist/generators/ts/_ObjectType/fromJsonFunctionDeclarations.js +0 -78
- package/dist/generators/ts/_ObjectType/fromRdfFunctionDeclarations.d.ts +0 -4
- package/dist/generators/ts/_ObjectType/fromRdfFunctionDeclarations.js +0 -91
- package/dist/generators/ts/_ObjectType/jsonSchemaFunctionDeclaration.d.ts +0 -5
- package/dist/generators/ts/_ObjectType/jsonSchemaFunctionDeclaration.js +0 -19
- package/dist/generators/ts/_ObjectType/jsonUiSchemaFunctionDeclaration.d.ts +0 -5
- package/dist/generators/ts/_ObjectType/jsonUiSchemaFunctionDeclaration.js +0 -31
- package/dist/generators/ts/_ObjectType/jsonZodSchemaFunctionDeclaration.d.ts +0 -5
- package/dist/generators/ts/_ObjectType/jsonZodSchemaFunctionDeclaration.js +0 -37
- package/dist/generators/ts/_ObjectType/rdfjsTermExpression.d.ts +0 -6
- package/dist/generators/ts/_ObjectType/rdfjsTermExpression.js +0 -17
- package/dist/generators/ts/_ObjectType/toJsonFunctionDeclaration.d.ts +0 -5
- package/dist/generators/ts/_ObjectType/toJsonFunctionDeclaration.js +0 -19
- package/dist/generators/ts/_ObjectType/toJsonReturnType.d.ts +0 -3
- package/dist/generators/ts/_ObjectType/toJsonReturnType.js +0 -17
- package/dist/generators/ts/_ObjectType/toRdfFunctionDeclaration.d.ts +0 -5
- package/dist/generators/ts/_ObjectType/toRdfFunctionDeclaration.js +0 -19
|
@@ -3,14 +3,17 @@ import TermSet from "@rdfjs/term-set";
|
|
|
3
3
|
import { rdf, xsd } from "@tpluscode/rdf-ns-builders";
|
|
4
4
|
import { Maybe } from "purify-ts";
|
|
5
5
|
import { fromRdf } from "rdf-literal";
|
|
6
|
+
import { invariant } from "ts-invariant";
|
|
7
|
+
import { Scope } from "ts-morph";
|
|
6
8
|
import { logger } from "../../logger.js";
|
|
7
9
|
import { BooleanType } from "./BooleanType.js";
|
|
8
10
|
import { DateTimeType } from "./DateTimeType.js";
|
|
9
11
|
import { DateType } from "./DateType.js";
|
|
12
|
+
import { FloatType } from "./FloatType.js";
|
|
10
13
|
import { IdentifierType } from "./IdentifierType.js";
|
|
14
|
+
import { IntType } from "./IntType.js";
|
|
11
15
|
import { ListType } from "./ListType.js";
|
|
12
16
|
import { LiteralType } from "./LiteralType.js";
|
|
13
|
-
import { NumberType } from "./NumberType.js";
|
|
14
17
|
import { ObjectType } from "./ObjectType.js";
|
|
15
18
|
import { ObjectUnionType } from "./ObjectUnionType.js";
|
|
16
19
|
import { OptionType } from "./OptionType.js";
|
|
@@ -18,42 +21,227 @@ import { SetType } from "./SetType.js";
|
|
|
18
21
|
import { StringType } from "./StringType.js";
|
|
19
22
|
import { TermType } from "./TermType.js";
|
|
20
23
|
import { UnionType } from "./UnionType.js";
|
|
24
|
+
import { syntheticNamePrefix } from "./syntheticNamePrefix.js";
|
|
21
25
|
import { tsName } from "./tsName.js";
|
|
22
|
-
function objectTypeNeedsIdentifierPrefixProperty(objectType) {
|
|
23
|
-
return objectType.identifierMintingStrategy
|
|
24
|
-
.map((identifierMintingStrategy) => {
|
|
25
|
-
switch (identifierMintingStrategy) {
|
|
26
|
-
case "blankNode":
|
|
27
|
-
return false;
|
|
28
|
-
case "sha256":
|
|
29
|
-
case "uuidv4":
|
|
30
|
-
return true;
|
|
31
|
-
}
|
|
32
|
-
})
|
|
33
|
-
.orDefault(false);
|
|
34
|
-
}
|
|
35
26
|
export class TypeFactory {
|
|
27
|
+
cachedBooleanType = new BooleanType({
|
|
28
|
+
defaultValue: Maybe.empty(),
|
|
29
|
+
hasValues: [],
|
|
30
|
+
in_: [],
|
|
31
|
+
languageIn: [],
|
|
32
|
+
primitiveDefaultValue: Maybe.empty(),
|
|
33
|
+
primitiveIn: [],
|
|
34
|
+
});
|
|
35
|
+
cachedDateType = new DateType({
|
|
36
|
+
defaultValue: Maybe.empty(),
|
|
37
|
+
hasValues: [],
|
|
38
|
+
in_: [],
|
|
39
|
+
languageIn: [],
|
|
40
|
+
primitiveDefaultValue: Maybe.empty(),
|
|
41
|
+
primitiveIn: [],
|
|
42
|
+
});
|
|
43
|
+
cachedDateTimeType = new DateTimeType({
|
|
44
|
+
defaultValue: Maybe.empty(),
|
|
45
|
+
hasValues: [],
|
|
46
|
+
in_: [],
|
|
47
|
+
languageIn: [],
|
|
48
|
+
primitiveDefaultValue: Maybe.empty(),
|
|
49
|
+
primitiveIn: [],
|
|
50
|
+
});
|
|
51
|
+
cachedFloatType = new FloatType({
|
|
52
|
+
defaultValue: Maybe.empty(),
|
|
53
|
+
hasValues: [],
|
|
54
|
+
in_: [],
|
|
55
|
+
languageIn: [],
|
|
56
|
+
primitiveDefaultValue: Maybe.empty(),
|
|
57
|
+
primitiveIn: [],
|
|
58
|
+
});
|
|
59
|
+
cachedIdentifierType = new IdentifierType({
|
|
60
|
+
defaultValue: Maybe.empty(),
|
|
61
|
+
hasValues: [],
|
|
62
|
+
in_: [],
|
|
63
|
+
nodeKinds: new Set(["BlankNode", "NamedNode"]),
|
|
64
|
+
});
|
|
65
|
+
cachedIntType = new IntType({
|
|
66
|
+
defaultValue: Maybe.empty(),
|
|
67
|
+
hasValues: [],
|
|
68
|
+
in_: [],
|
|
69
|
+
languageIn: [],
|
|
70
|
+
primitiveDefaultValue: Maybe.empty(),
|
|
71
|
+
primitiveIn: [],
|
|
72
|
+
});
|
|
73
|
+
cachedNamedIdentifierType = new IdentifierType({
|
|
74
|
+
defaultValue: Maybe.empty(),
|
|
75
|
+
hasValues: [],
|
|
76
|
+
in_: [],
|
|
77
|
+
nodeKinds: new Set(["NamedNode"]),
|
|
78
|
+
});
|
|
36
79
|
cachedObjectTypePropertiesByIdentifier = new TermMap();
|
|
37
80
|
cachedObjectTypesByIdentifier = new TermMap();
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
81
|
+
cachedObjectUnionTypesByIdentifier = new TermMap();
|
|
82
|
+
cachedStringType = new StringType({
|
|
83
|
+
defaultValue: Maybe.empty(),
|
|
84
|
+
hasValues: [],
|
|
85
|
+
in_: [],
|
|
86
|
+
languageIn: [],
|
|
87
|
+
primitiveDefaultValue: Maybe.empty(),
|
|
88
|
+
primitiveIn: [],
|
|
89
|
+
});
|
|
90
|
+
createObjectTypeFromAstType(astType) {
|
|
91
|
+
{
|
|
92
|
+
const cachedObjectType = this.cachedObjectTypesByIdentifier.get(astType.name.identifier);
|
|
93
|
+
if (cachedObjectType) {
|
|
94
|
+
return cachedObjectType;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
const identifierType = new IdentifierType({
|
|
98
|
+
defaultValue: Maybe.empty(),
|
|
99
|
+
hasValues: [],
|
|
100
|
+
in_: astType.identifierIn,
|
|
101
|
+
nodeKinds: astType.identifierNodeKinds,
|
|
102
|
+
});
|
|
103
|
+
const staticModuleName = astType.childObjectTypes.length > 0
|
|
104
|
+
? `${tsName(astType.name)}Static`
|
|
105
|
+
: tsName(astType.name);
|
|
106
|
+
const objectType = new ObjectType({
|
|
107
|
+
abstract: astType.abstract,
|
|
108
|
+
comment: astType.comment,
|
|
109
|
+
declarationType: astType.tsObjectDeclarationType,
|
|
110
|
+
export_: astType.export,
|
|
111
|
+
extern: astType.extern,
|
|
112
|
+
features: astType.tsFeatures,
|
|
113
|
+
fromRdfType: astType.fromRdfType,
|
|
114
|
+
imports: astType.tsImports,
|
|
115
|
+
label: astType.label,
|
|
116
|
+
lazyAncestorObjectTypes: () => astType.ancestorObjectTypes.map((astType) => this.createObjectTypeFromAstType(astType)),
|
|
117
|
+
lazyChildObjectTypes: () => astType.childObjectTypes.map((astType) => this.createObjectTypeFromAstType(astType)),
|
|
118
|
+
lazyDescendantObjectTypes: () => astType.descendantObjectTypes.map((astType) => this.createObjectTypeFromAstType(astType)),
|
|
119
|
+
lazyParentObjectTypes: () => astType.parentObjectTypes.map((astType) => this.createObjectTypeFromAstType(astType)),
|
|
120
|
+
lazyProperties: (objectType) => {
|
|
121
|
+
const properties = astType.properties
|
|
122
|
+
.toSorted((left, right) => {
|
|
123
|
+
if (left.order < right.order) {
|
|
124
|
+
return -1;
|
|
125
|
+
}
|
|
126
|
+
if (left.order > right.order) {
|
|
127
|
+
return 1;
|
|
128
|
+
}
|
|
129
|
+
return tsName(left.name).localeCompare(tsName(right.name));
|
|
130
|
+
})
|
|
131
|
+
.map((astProperty) => this.createObjectTypePropertyFromAstProperty({
|
|
132
|
+
astObjectTypeProperty: astProperty,
|
|
133
|
+
objectType,
|
|
134
|
+
}));
|
|
135
|
+
// Type discriminator property
|
|
136
|
+
const typeDiscriminatorOwnValue = !astType.abstract
|
|
137
|
+
? objectType.discriminatorValue
|
|
138
|
+
: undefined;
|
|
139
|
+
const typeDiscriminatorDescendantValues = new Set();
|
|
140
|
+
for (const descendantObjectType of objectType.descendantObjectTypes) {
|
|
141
|
+
if (!descendantObjectType.abstract) {
|
|
142
|
+
typeDiscriminatorDescendantValues.add(descendantObjectType.discriminatorValue);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
if (typeDiscriminatorOwnValue ||
|
|
146
|
+
typeDiscriminatorDescendantValues.size > 0) {
|
|
147
|
+
properties.splice(0, 0, new ObjectType.TypeDiscriminatorProperty({
|
|
148
|
+
abstract: astType.abstract,
|
|
149
|
+
name: `${syntheticNamePrefix}type`,
|
|
150
|
+
initializer: objectType.discriminatorValue,
|
|
151
|
+
objectType,
|
|
152
|
+
override: objectType.parentObjectTypes.length > 0,
|
|
153
|
+
type: new ObjectType.TypeDiscriminatorProperty.Type({
|
|
154
|
+
descendantValues: [...typeDiscriminatorDescendantValues].sort(),
|
|
155
|
+
mutable: false,
|
|
156
|
+
ownValues: typeDiscriminatorOwnValue
|
|
157
|
+
? [typeDiscriminatorOwnValue]
|
|
158
|
+
: [],
|
|
159
|
+
}),
|
|
160
|
+
visibility: "public",
|
|
161
|
+
}));
|
|
162
|
+
}
|
|
163
|
+
// Some ObjectTypes have an identifierPrefix property, depending on their identifier minting strategy.
|
|
164
|
+
if (objectTypeNeedsIdentifierPrefixProperty(astType)) {
|
|
165
|
+
properties.splice(0, 0, new ObjectType.IdentifierPrefixProperty({
|
|
166
|
+
own: !astType.ancestorObjectTypes.some(objectTypeNeedsIdentifierPrefixProperty),
|
|
167
|
+
name: `${syntheticNamePrefix}identifierPrefix`,
|
|
168
|
+
objectType,
|
|
169
|
+
type: this.cachedStringType,
|
|
170
|
+
visibility: "protected",
|
|
171
|
+
}));
|
|
172
|
+
}
|
|
173
|
+
// Every ObjectType has an identifier property. Some are abstract.
|
|
174
|
+
properties.splice(0, 0, new ObjectType.IdentifierProperty({
|
|
175
|
+
abstract: astType.abstract,
|
|
176
|
+
getAccessorScope: (() => {
|
|
177
|
+
if (astType.abstract) {
|
|
178
|
+
return Maybe.empty();
|
|
179
|
+
}
|
|
180
|
+
if (astType.identifierMintingStrategy.isJust() ||
|
|
181
|
+
astType.ancestorObjectTypes.some((ancestorObjectType) => ancestorObjectType.identifierMintingStrategy.isJust())) {
|
|
182
|
+
return Maybe.of(Scope.Public);
|
|
183
|
+
}
|
|
184
|
+
return Maybe.empty();
|
|
185
|
+
})(),
|
|
186
|
+
identifierMintingStrategy: astType.identifierMintingStrategy,
|
|
187
|
+
identifierPrefixPropertyName: `${syntheticNamePrefix}identifierPrefix`,
|
|
188
|
+
name: `${syntheticNamePrefix}identifier`,
|
|
189
|
+
objectType,
|
|
190
|
+
override: astType.parentObjectTypes.length > 0,
|
|
191
|
+
propertyDeclarationVisibility: (() => {
|
|
192
|
+
if (astType.abstract) {
|
|
193
|
+
// If the type is abstract, don't declare an identifier property.
|
|
194
|
+
return Maybe.empty();
|
|
195
|
+
}
|
|
196
|
+
if (astType.ancestorObjectTypes.some((ancestorObjectType) => !ancestorObjectType.abstract)) {
|
|
197
|
+
// If the type has a non-abstract ancestor, that ancestor will declare the identifier property.
|
|
198
|
+
return Maybe.empty();
|
|
199
|
+
}
|
|
200
|
+
if (astType.descendantObjectTypes.some((descendantObjectType) => !descendantObjectType.abstract)) {
|
|
201
|
+
// If the type has a non-abstract descendant, declare the identifier property for it.
|
|
202
|
+
return Maybe.of("protected");
|
|
203
|
+
}
|
|
204
|
+
return Maybe.of("private");
|
|
205
|
+
})(),
|
|
206
|
+
type: identifierType,
|
|
207
|
+
typeAlias: `${staticModuleName}.${syntheticNamePrefix}Identifier`,
|
|
208
|
+
visibility: "public",
|
|
209
|
+
}));
|
|
210
|
+
return properties;
|
|
211
|
+
},
|
|
212
|
+
identifierMintingStrategy: astType.identifierMintingStrategy,
|
|
213
|
+
name: tsName(astType.name),
|
|
214
|
+
staticModuleName,
|
|
215
|
+
synthetic: astType.synthetic,
|
|
216
|
+
toRdfTypes: astType.toRdfTypes,
|
|
217
|
+
});
|
|
218
|
+
this.cachedObjectTypesByIdentifier.set(astType.name.identifier, objectType);
|
|
219
|
+
return objectType;
|
|
41
220
|
}
|
|
42
221
|
createTypeFromAstType(astType) {
|
|
43
222
|
switch (astType.kind) {
|
|
44
223
|
case "IdentifierType":
|
|
224
|
+
if (astType.defaultValue.isNothing() &&
|
|
225
|
+
astType.hasValues.length === 0 &&
|
|
226
|
+
astType.in_.length === 0) {
|
|
227
|
+
if (astType.nodeKinds.size === 2) {
|
|
228
|
+
return this.cachedIdentifierType;
|
|
229
|
+
}
|
|
230
|
+
if (astType.nodeKinds.size === 1 &&
|
|
231
|
+
astType.nodeKinds.has("NamedNode")) {
|
|
232
|
+
return this.cachedNamedIdentifierType;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
45
235
|
return new IdentifierType({
|
|
46
|
-
dataFactoryVariable: this.dataFactoryVariable,
|
|
47
236
|
defaultValue: astType.defaultValue,
|
|
48
237
|
hasValues: astType.hasValues,
|
|
49
|
-
in_: astType.in_,
|
|
238
|
+
in_: astType.in_.filter((_) => _.termType === "NamedNode"),
|
|
50
239
|
nodeKinds: astType.nodeKinds,
|
|
51
240
|
});
|
|
52
241
|
case "IntersectionType":
|
|
53
242
|
throw new Error("not implemented");
|
|
54
243
|
case "ListType": {
|
|
55
244
|
return new ListType({
|
|
56
|
-
dataFactoryVariable: this.dataFactoryVariable,
|
|
57
245
|
identifierNodeKind: astType.identifierNodeKind,
|
|
58
246
|
itemType: this.createTypeFromAstType(astType.itemType),
|
|
59
247
|
mutable: astType.mutable.orDefault(false),
|
|
@@ -77,8 +265,12 @@ export class TypeFactory {
|
|
|
77
265
|
if (datatypes.size === 1) {
|
|
78
266
|
const datatype = [...datatypes][0];
|
|
79
267
|
if (datatype.equals(xsd.boolean)) {
|
|
268
|
+
if (astType.defaultValue.isNothing() &&
|
|
269
|
+
astType.hasValues.length === 0 &&
|
|
270
|
+
astType.in_.length === 0) {
|
|
271
|
+
return this.cachedBooleanType;
|
|
272
|
+
}
|
|
80
273
|
return new BooleanType({
|
|
81
|
-
dataFactoryVariable: this.dataFactoryVariable,
|
|
82
274
|
defaultValue: astType.defaultValue,
|
|
83
275
|
hasValues: astType.hasValues,
|
|
84
276
|
languageIn: [],
|
|
@@ -92,8 +284,14 @@ export class TypeFactory {
|
|
|
92
284
|
});
|
|
93
285
|
}
|
|
94
286
|
if (datatype.equals(xsd.date) || datatype.equals(xsd.dateTime)) {
|
|
287
|
+
if (astType.defaultValue.isNothing() &&
|
|
288
|
+
astType.hasValues.length === 0 &&
|
|
289
|
+
astType.in_.length === 0) {
|
|
290
|
+
return datatype.equals(xsd.date)
|
|
291
|
+
? this.cachedDateType
|
|
292
|
+
: this.cachedDateTimeType;
|
|
293
|
+
}
|
|
95
294
|
return new (datatype.equals(xsd.date) ? DateType : DateTimeType)({
|
|
96
|
-
dataFactoryVariable: this.dataFactoryVariable,
|
|
97
295
|
defaultValue: astType.defaultValue,
|
|
98
296
|
hasValues: astType.hasValues,
|
|
99
297
|
in_: astType.in_,
|
|
@@ -106,45 +304,38 @@ export class TypeFactory {
|
|
|
106
304
|
.filter((value) => typeof value === "object" && value instanceof Date),
|
|
107
305
|
});
|
|
108
306
|
}
|
|
109
|
-
for (const
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
defaultValue: astType.defaultValue,
|
|
133
|
-
hasValues: astType.hasValues,
|
|
134
|
-
in_: astType.in_,
|
|
135
|
-
languageIn: [],
|
|
136
|
-
primitiveDefaultValue: astType.defaultValue
|
|
137
|
-
.map((value) => fromRdf(value, true))
|
|
138
|
-
.filter((value) => typeof value === "number"),
|
|
139
|
-
primitiveIn: astType.in_
|
|
140
|
-
.map((value) => fromRdf(value, true))
|
|
141
|
-
.filter((value) => typeof value === "number"),
|
|
142
|
-
});
|
|
307
|
+
for (const [floatOrInt, numberDatatypes_] of Object.entries(numberDatatypes)) {
|
|
308
|
+
for (const numberDatatype of numberDatatypes_) {
|
|
309
|
+
if (datatype.equals(numberDatatype)) {
|
|
310
|
+
if (astType.defaultValue.isNothing() &&
|
|
311
|
+
astType.hasValues.length === 0 &&
|
|
312
|
+
astType.in_.length === 0) {
|
|
313
|
+
return floatOrInt === "float"
|
|
314
|
+
? this.cachedFloatType
|
|
315
|
+
: this.cachedIntType;
|
|
316
|
+
}
|
|
317
|
+
return new (floatOrInt === "float" ? FloatType : IntType)({
|
|
318
|
+
defaultValue: astType.defaultValue,
|
|
319
|
+
hasValues: astType.hasValues,
|
|
320
|
+
in_: astType.in_,
|
|
321
|
+
languageIn: [],
|
|
322
|
+
primitiveDefaultValue: astType.defaultValue
|
|
323
|
+
.map((value) => fromRdf(value, true))
|
|
324
|
+
.filter((value) => typeof value === "number"),
|
|
325
|
+
primitiveIn: astType.in_
|
|
326
|
+
.map((value) => fromRdf(value, true))
|
|
327
|
+
.filter((value) => typeof value === "number"),
|
|
328
|
+
});
|
|
329
|
+
}
|
|
143
330
|
}
|
|
144
331
|
}
|
|
145
332
|
if (datatype.equals(xsd.anyURI) || datatype.equals(xsd.string)) {
|
|
333
|
+
if (astType.defaultValue.isNothing() &&
|
|
334
|
+
astType.hasValues.length === 0 &&
|
|
335
|
+
astType.in_.length === 0) {
|
|
336
|
+
return this.cachedStringType;
|
|
337
|
+
}
|
|
146
338
|
return new StringType({
|
|
147
|
-
dataFactoryVariable: this.dataFactoryVariable,
|
|
148
339
|
defaultValue: astType.defaultValue,
|
|
149
340
|
hasValues: astType.hasValues,
|
|
150
341
|
languageIn: [],
|
|
@@ -167,7 +358,6 @@ export class TypeFactory {
|
|
|
167
358
|
logger.debug("literal type has no datatypes");
|
|
168
359
|
}
|
|
169
360
|
return new LiteralType({
|
|
170
|
-
dataFactoryVariable: this.dataFactoryVariable,
|
|
171
361
|
defaultValue: astType.defaultValue,
|
|
172
362
|
hasValues: astType.hasValues,
|
|
173
363
|
in_: astType.in_,
|
|
@@ -179,205 +369,169 @@ export class TypeFactory {
|
|
|
179
369
|
case "ObjectType":
|
|
180
370
|
return this.createObjectTypeFromAstType(astType);
|
|
181
371
|
case "ObjectUnionType":
|
|
182
|
-
return
|
|
183
|
-
comment: astType.comment,
|
|
184
|
-
dataFactoryVariable: this.dataFactoryVariable,
|
|
185
|
-
export_: astType.export,
|
|
186
|
-
features: astType.tsFeatures,
|
|
187
|
-
label: astType.label,
|
|
188
|
-
memberTypes: astType.memberTypes
|
|
189
|
-
.map((astType) => this.createTypeFromAstType(astType))
|
|
190
|
-
.filter((memberType) => memberType instanceof ObjectType),
|
|
191
|
-
name: tsName(astType.name),
|
|
192
|
-
});
|
|
372
|
+
return this.createObjectUnionTypeFromAstType(astType);
|
|
193
373
|
case "OptionType":
|
|
194
374
|
return new OptionType({
|
|
195
|
-
dataFactoryVariable: this.dataFactoryVariable,
|
|
196
375
|
itemType: this.createTypeFromAstType(astType.itemType),
|
|
197
376
|
});
|
|
198
377
|
case "PlaceholderType":
|
|
199
378
|
throw new Error(astType.kind);
|
|
200
379
|
case "SetType":
|
|
201
380
|
return new SetType({
|
|
202
|
-
dataFactoryVariable: this.dataFactoryVariable,
|
|
203
381
|
itemType: this.createTypeFromAstType(astType.itemType),
|
|
204
382
|
mutable: astType.mutable.orDefault(false),
|
|
205
383
|
minCount: astType.minCount,
|
|
206
384
|
});
|
|
207
385
|
case "TermType":
|
|
208
386
|
return new TermType({
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
nodeKinds: astType.nodeKinds,
|
|
387
|
+
defaultValue: astType["defaultValue"],
|
|
388
|
+
hasValues: astType["hasValues"],
|
|
389
|
+
in_: astType["in_"],
|
|
390
|
+
nodeKinds: astType["nodeKinds"],
|
|
214
391
|
});
|
|
215
392
|
case "UnionType":
|
|
216
393
|
return new UnionType({
|
|
217
|
-
dataFactoryVariable: this.dataFactoryVariable,
|
|
218
394
|
memberTypes: astType.memberTypes.map((astType) => this.createTypeFromAstType(astType)),
|
|
219
395
|
});
|
|
220
396
|
}
|
|
221
397
|
}
|
|
222
|
-
|
|
398
|
+
createObjectTypePropertyFromAstProperty({ astObjectTypeProperty, objectType, }) {
|
|
223
399
|
{
|
|
224
|
-
const
|
|
225
|
-
if (
|
|
226
|
-
return
|
|
400
|
+
const cachedProperty = this.cachedObjectTypePropertiesByIdentifier.get(astObjectTypeProperty.name.identifier);
|
|
401
|
+
if (cachedProperty) {
|
|
402
|
+
return cachedProperty;
|
|
227
403
|
}
|
|
228
404
|
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
405
|
+
let property;
|
|
406
|
+
const name = tsName(astObjectTypeProperty.name);
|
|
407
|
+
if (astObjectTypeProperty.stubType.isJust()) {
|
|
408
|
+
const resolvedType = this.createTypeFromAstType(astObjectTypeProperty.type);
|
|
409
|
+
let lazyType;
|
|
410
|
+
const stubType = this.createTypeFromAstType(astObjectTypeProperty.stubType.unsafeCoerce());
|
|
411
|
+
if (resolvedType instanceof OptionType) {
|
|
412
|
+
invariant(resolvedType.itemType instanceof ObjectType ||
|
|
413
|
+
resolvedType.itemType instanceof ObjectUnionType, `lazy property ${name} on ${objectType.name} has ${resolvedType.kind} ${resolvedType.itemType.kind} items`);
|
|
414
|
+
invariant(stubType instanceof OptionType, `lazy property ${name} on ${objectType.name} has ${stubType.kind} stubs`);
|
|
415
|
+
lazyType = new ObjectType.LazyShaclProperty.OptionalObjectType({
|
|
416
|
+
resolvedType,
|
|
417
|
+
stubType,
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
else if (resolvedType instanceof ObjectType ||
|
|
421
|
+
resolvedType instanceof ObjectUnionType) {
|
|
422
|
+
invariant(stubType instanceof ObjectType || stubType instanceof ObjectUnionType, `lazy property ${name} on ${objectType.name} has ${stubType.kind} stubs`);
|
|
423
|
+
lazyType = new ObjectType.LazyShaclProperty.RequiredObjectType({
|
|
424
|
+
resolvedType: resolvedType,
|
|
425
|
+
stubType: stubType,
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
else if (resolvedType instanceof SetType) {
|
|
429
|
+
invariant(resolvedType.itemType instanceof ObjectType ||
|
|
430
|
+
resolvedType.itemType instanceof ObjectUnionType, `lazy property ${name} on ${objectType.name} has ${resolvedType.kind} ${resolvedType.itemType.kind} items`);
|
|
431
|
+
invariant(stubType instanceof SetType, `lazy property ${name} on ${objectType.name} has ${stubType.kind} stubs`);
|
|
432
|
+
lazyType = new ObjectType.LazyShaclProperty.ObjectSetType({
|
|
433
|
+
resolvedType,
|
|
434
|
+
stubType,
|
|
435
|
+
});
|
|
436
|
+
}
|
|
437
|
+
else {
|
|
438
|
+
throw new Error(`lazy property ${name} on ${objectType.name} has ${resolvedType.kind}`);
|
|
439
|
+
}
|
|
440
|
+
property = new ObjectType.LazyShaclProperty({
|
|
441
|
+
comment: astObjectTypeProperty.comment,
|
|
442
|
+
description: astObjectTypeProperty.description,
|
|
443
|
+
label: astObjectTypeProperty.label,
|
|
444
|
+
objectType,
|
|
445
|
+
name,
|
|
446
|
+
path: astObjectTypeProperty.path.iri,
|
|
447
|
+
type: lazyType,
|
|
448
|
+
visibility: astObjectTypeProperty.visibility,
|
|
449
|
+
});
|
|
450
|
+
}
|
|
451
|
+
else {
|
|
452
|
+
property = new ObjectType.EagerShaclProperty({
|
|
453
|
+
comment: astObjectTypeProperty.comment,
|
|
454
|
+
description: astObjectTypeProperty.description,
|
|
455
|
+
label: astObjectTypeProperty.label,
|
|
456
|
+
mutable: astObjectTypeProperty.mutable.orDefault(false),
|
|
457
|
+
objectType,
|
|
458
|
+
name,
|
|
459
|
+
path: astObjectTypeProperty.path.iri,
|
|
460
|
+
recursive: !!astObjectTypeProperty.recursive,
|
|
461
|
+
type: this.createTypeFromAstType(astObjectTypeProperty.type),
|
|
462
|
+
visibility: astObjectTypeProperty.visibility,
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
this.cachedObjectTypePropertiesByIdentifier.set(astObjectTypeProperty.name.identifier, property);
|
|
466
|
+
return property;
|
|
467
|
+
}
|
|
468
|
+
createObjectUnionTypeFromAstType(astType) {
|
|
469
|
+
{
|
|
470
|
+
const cachedObjectUnionType = this.cachedObjectUnionTypesByIdentifier.get(astType.name.identifier);
|
|
471
|
+
if (cachedObjectUnionType) {
|
|
472
|
+
return cachedObjectUnionType;
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
const memberTypes = astType.memberTypes
|
|
476
|
+
.map((astType) => this.createTypeFromAstType(astType))
|
|
477
|
+
.filter((memberType) => memberType instanceof ObjectType);
|
|
478
|
+
const memberIdentifierTypeNodeKinds = new Set();
|
|
479
|
+
const memberIdentifierTypesIn = new TermSet();
|
|
480
|
+
for (const memberType of memberTypes) {
|
|
481
|
+
for (const nodeKind of memberType.identifierType.nodeKinds) {
|
|
482
|
+
memberIdentifierTypeNodeKinds.add(nodeKind);
|
|
483
|
+
}
|
|
484
|
+
for (const in_ of memberType.identifierType.in_) {
|
|
485
|
+
memberIdentifierTypesIn.add(in_);
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
const objectUnionType = new ObjectUnionType({
|
|
238
489
|
comment: astType.comment,
|
|
239
|
-
dataFactoryVariable: this.dataFactoryVariable,
|
|
240
|
-
declarationType: astType.tsObjectDeclarationType,
|
|
241
490
|
export_: astType.export,
|
|
242
|
-
extern: astType.extern,
|
|
243
491
|
features: astType.tsFeatures,
|
|
244
|
-
|
|
245
|
-
|
|
492
|
+
identifierType: new IdentifierType({
|
|
493
|
+
defaultValue: Maybe.empty(),
|
|
494
|
+
hasValues: [],
|
|
495
|
+
in_: [...memberIdentifierTypesIn],
|
|
496
|
+
nodeKinds: memberIdentifierTypeNodeKinds,
|
|
497
|
+
}),
|
|
246
498
|
label: astType.label,
|
|
247
|
-
|
|
248
|
-
lazyDescendantObjectTypes: () => astType.descendantObjectTypes.map((astType) => this.createObjectTypeFromAstType(astType)),
|
|
249
|
-
lazyParentObjectTypes: () => astType.parentObjectTypes.map((astType) => this.createObjectTypeFromAstType(astType)),
|
|
250
|
-
lazyProperties: () => {
|
|
251
|
-
const properties = astType.properties
|
|
252
|
-
.toSorted((left, right) => {
|
|
253
|
-
if (left.order < right.order) {
|
|
254
|
-
return -1;
|
|
255
|
-
}
|
|
256
|
-
if (left.order > right.order) {
|
|
257
|
-
return 1;
|
|
258
|
-
}
|
|
259
|
-
return tsName(left.name).localeCompare(tsName(right.name));
|
|
260
|
-
})
|
|
261
|
-
.map((astProperty) => this.createObjectTypePropertyFromAstProperty(astType, astProperty));
|
|
262
|
-
const lazyMutable = () => properties.some((property) => property.mutable || property.type.mutable);
|
|
263
|
-
// Type discriminator property
|
|
264
|
-
const typeDiscriminatorValues = new Set();
|
|
265
|
-
if (!astType.abstract) {
|
|
266
|
-
typeDiscriminatorValues.add(objectType.discriminatorValue);
|
|
267
|
-
}
|
|
268
|
-
for (const descendantObjectType of objectType.descendantObjectTypes) {
|
|
269
|
-
if (!descendantObjectType.abstract) {
|
|
270
|
-
typeDiscriminatorValues.add(descendantObjectType.discriminatorValue);
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
if (typeDiscriminatorValues.size > 0) {
|
|
274
|
-
properties.splice(0, 0, new ObjectType.TypeDiscriminatorProperty({
|
|
275
|
-
abstract: astType.abstract,
|
|
276
|
-
dataFactoryVariable: this.dataFactoryVariable,
|
|
277
|
-
name: astType.tsTypeDiscriminatorPropertyName,
|
|
278
|
-
objectType: {
|
|
279
|
-
declarationType: astType.tsObjectDeclarationType,
|
|
280
|
-
features: astType.tsFeatures,
|
|
281
|
-
mutable: lazyMutable,
|
|
282
|
-
},
|
|
283
|
-
override: objectType.parentObjectTypes.length > 0,
|
|
284
|
-
type: new ObjectType.TypeDiscriminatorProperty.Type({
|
|
285
|
-
mutable: false,
|
|
286
|
-
values: [...typeDiscriminatorValues].sort(),
|
|
287
|
-
}),
|
|
288
|
-
visibility: "public",
|
|
289
|
-
value: objectType.discriminatorValue,
|
|
290
|
-
}));
|
|
291
|
-
}
|
|
292
|
-
// Some ObjectTypes have an identifierPrefix property, depending on their identifier minting strategy.
|
|
293
|
-
if (objectTypeNeedsIdentifierPrefixProperty(astType)) {
|
|
294
|
-
properties.splice(0, 0, new ObjectType.IdentifierPrefixProperty({
|
|
295
|
-
dataFactoryVariable: this.dataFactoryVariable,
|
|
296
|
-
own: !astType.ancestorObjectTypes.some(objectTypeNeedsIdentifierPrefixProperty),
|
|
297
|
-
name: astType.tsIdentifierPrefixPropertyName,
|
|
298
|
-
objectType: {
|
|
299
|
-
declarationType: astType.tsObjectDeclarationType,
|
|
300
|
-
features: astType.tsFeatures,
|
|
301
|
-
mutable: lazyMutable,
|
|
302
|
-
},
|
|
303
|
-
type: new StringType({
|
|
304
|
-
dataFactoryVariable: this.dataFactoryVariable,
|
|
305
|
-
defaultValue: Maybe.empty(),
|
|
306
|
-
hasValues: [],
|
|
307
|
-
in_: [],
|
|
308
|
-
languageIn: [],
|
|
309
|
-
primitiveDefaultValue: Maybe.empty(),
|
|
310
|
-
primitiveIn: [],
|
|
311
|
-
}),
|
|
312
|
-
visibility: "protected",
|
|
313
|
-
}));
|
|
314
|
-
}
|
|
315
|
-
// Every ObjectType has an identifier property. Some are abstract.
|
|
316
|
-
properties.splice(0, 0, new ObjectType.IdentifierProperty({
|
|
317
|
-
abstract: astType.abstract,
|
|
318
|
-
classDeclarationVisibility: (() => {
|
|
319
|
-
if (astType.abstract) {
|
|
320
|
-
// If the type is abstract, don't declare an identifier property.
|
|
321
|
-
return Maybe.empty();
|
|
322
|
-
}
|
|
323
|
-
if (astType.ancestorObjectTypes.some((ancestorObjectType) => !ancestorObjectType.abstract)) {
|
|
324
|
-
// If the type has a non-abstract ancestor, that ancestor will declare the identifier property.
|
|
325
|
-
return Maybe.empty();
|
|
326
|
-
}
|
|
327
|
-
if (astType.descendantObjectTypes.some((descendantObjectType) => !descendantObjectType.abstract)) {
|
|
328
|
-
// If the type has a non-abstract descendant, declare the identifier property for it.
|
|
329
|
-
return Maybe.of("protected");
|
|
330
|
-
}
|
|
331
|
-
return Maybe.of("private");
|
|
332
|
-
})(),
|
|
333
|
-
dataFactoryVariable: this.dataFactoryVariable,
|
|
334
|
-
identifierMintingStrategy: astType.identifierMintingStrategy,
|
|
335
|
-
name: astType.tsIdentifierPropertyName,
|
|
336
|
-
objectType: {
|
|
337
|
-
declarationType: astType.tsObjectDeclarationType,
|
|
338
|
-
features: astType.tsFeatures,
|
|
339
|
-
mutable: lazyMutable,
|
|
340
|
-
},
|
|
341
|
-
override: astType.parentObjectTypes.length > 0,
|
|
342
|
-
type: identifierType,
|
|
343
|
-
visibility: "public",
|
|
344
|
-
}));
|
|
345
|
-
return properties;
|
|
346
|
-
},
|
|
347
|
-
identifierMintingStrategy: astType.identifierMintingStrategy,
|
|
499
|
+
memberTypes,
|
|
348
500
|
name: tsName(astType.name),
|
|
349
|
-
toRdfTypes: astType.toRdfTypes,
|
|
350
501
|
});
|
|
351
|
-
this.
|
|
352
|
-
return
|
|
502
|
+
this.cachedObjectUnionTypesByIdentifier.set(astType.name.identifier, objectUnionType);
|
|
503
|
+
return objectUnionType;
|
|
353
504
|
}
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
505
|
+
}
|
|
506
|
+
function objectTypeNeedsIdentifierPrefixProperty(objectType) {
|
|
507
|
+
return objectType.identifierMintingStrategy
|
|
508
|
+
.map((identifierMintingStrategy) => {
|
|
509
|
+
switch (identifierMintingStrategy) {
|
|
510
|
+
case "blankNode":
|
|
511
|
+
return false;
|
|
512
|
+
case "sha256":
|
|
513
|
+
case "uuidv4":
|
|
514
|
+
return true;
|
|
360
515
|
}
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
dataFactoryVariable: this.dataFactoryVariable,
|
|
364
|
-
description: astObjectTypeProperty.description,
|
|
365
|
-
label: astObjectTypeProperty.label,
|
|
366
|
-
mutable: astObjectTypeProperty.mutable.orDefault(false),
|
|
367
|
-
objectType: {
|
|
368
|
-
declarationType: astObjectType.tsObjectDeclarationType,
|
|
369
|
-
features: astObjectType.tsFeatures,
|
|
370
|
-
mutable: () => {
|
|
371
|
-
throw new Error("not implemented");
|
|
372
|
-
},
|
|
373
|
-
},
|
|
374
|
-
name: tsName(astObjectTypeProperty.name),
|
|
375
|
-
path: astObjectTypeProperty.path.iri,
|
|
376
|
-
type: this.createTypeFromAstType(astObjectTypeProperty.type),
|
|
377
|
-
visibility: astObjectTypeProperty.visibility,
|
|
378
|
-
});
|
|
379
|
-
this.cachedObjectTypePropertiesByIdentifier.set(astObjectTypeProperty.name.identifier, property);
|
|
380
|
-
return property;
|
|
381
|
-
}
|
|
516
|
+
})
|
|
517
|
+
.orDefault(false);
|
|
382
518
|
}
|
|
519
|
+
const numberDatatypes = {
|
|
520
|
+
float: [xsd.decimal, xsd.double, xsd.float],
|
|
521
|
+
int: [
|
|
522
|
+
xsd.byte,
|
|
523
|
+
xsd.int,
|
|
524
|
+
xsd.integer,
|
|
525
|
+
xsd.long,
|
|
526
|
+
xsd.negativeInteger,
|
|
527
|
+
xsd.nonNegativeInteger,
|
|
528
|
+
xsd.nonPositiveInteger,
|
|
529
|
+
xsd.positiveInteger,
|
|
530
|
+
xsd.short,
|
|
531
|
+
xsd.unsignedByte,
|
|
532
|
+
xsd.unsignedInt,
|
|
533
|
+
xsd.unsignedLong,
|
|
534
|
+
xsd.unsignedShort,
|
|
535
|
+
],
|
|
536
|
+
};
|
|
383
537
|
//# sourceMappingURL=TypeFactory.js.map
|