@shaclmate/compiler 2.0.12 → 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.
Files changed (204) hide show
  1. package/Compiler.d.ts +15 -0
  2. package/Compiler.js +20 -0
  3. package/ShapesGraphToAstTransformer.d.ts +18 -23
  4. package/ShapesGraphToAstTransformer.js +21 -447
  5. package/_ShapesGraphToAstTransformer/NodeShapeAstType.d.ts +3 -0
  6. package/_ShapesGraphToAstTransformer/NodeShapeAstType.js +2 -0
  7. package/_ShapesGraphToAstTransformer/index.d.ts +10 -0
  8. package/_ShapesGraphToAstTransformer/index.js +10 -0
  9. package/_ShapesGraphToAstTransformer/pickLiteral.d.ts +4 -0
  10. package/_ShapesGraphToAstTransformer/pickLiteral.js +18 -0
  11. package/_ShapesGraphToAstTransformer/propertyShapeNodeKinds.d.ts +4 -0
  12. package/_ShapesGraphToAstTransformer/propertyShapeNodeKinds.js +26 -0
  13. package/_ShapesGraphToAstTransformer/shapeAstName.d.ts +5 -0
  14. package/_ShapesGraphToAstTransformer/shapeAstName.js +28 -0
  15. package/_ShapesGraphToAstTransformer/transformNodeShapeToAstType.d.ts +6 -0
  16. package/_ShapesGraphToAstTransformer/transformNodeShapeToAstType.js +165 -0
  17. package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstCompositeType.d.ts +13 -0
  18. package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstCompositeType.js +198 -0
  19. package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstIdentifierType.d.ts +12 -0
  20. package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstIdentifierType.js +29 -0
  21. package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstLiteralType.d.ts +12 -0
  22. package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstLiteralType.js +43 -0
  23. package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstObjectTypeProperty.d.ts +6 -0
  24. package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstObjectTypeProperty.js +31 -0
  25. package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstTermType.d.ts +14 -0
  26. package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstTermType.js +21 -0
  27. package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstType.d.ts +16 -0
  28. package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstType.js +58 -0
  29. package/ast/Ast.d.ts +5 -0
  30. package/ast/CompositeType.d.ts +13 -0
  31. package/ast/CompositeType.js +2 -0
  32. package/ast/IdentifierType.d.ts +3 -6
  33. package/ast/IntersectionType.d.ts +2 -2
  34. package/ast/ListType.d.ts +53 -0
  35. package/ast/ListType.js +2 -0
  36. package/ast/LiteralType.d.ts +4 -3
  37. package/ast/Name.d.ts +1 -0
  38. package/ast/ObjectCompositeType.d.ts +22 -0
  39. package/ast/ObjectCompositeType.js +2 -0
  40. package/ast/ObjectIntersectionType.d.ts +8 -0
  41. package/ast/ObjectIntersectionType.js +2 -0
  42. package/ast/ObjectType.d.ts +92 -20
  43. package/ast/ObjectType.js +26 -1
  44. package/ast/ObjectUnionType.d.ts +19 -0
  45. package/ast/ObjectUnionType.js +2 -0
  46. package/ast/PlaceholderType.d.ts +7 -0
  47. package/ast/PlaceholderType.js +2 -0
  48. package/ast/SetType.d.ts +1 -1
  49. package/ast/TermType.d.ts +11 -0
  50. package/ast/TermType.js +2 -0
  51. package/ast/Type.d.ts +11 -3
  52. package/ast/UnionType.d.ts +3 -3
  53. package/ast/index.d.ts +6 -3
  54. package/ast/index.js +6 -3
  55. package/enums/MintingStrategy.d.ts +5 -0
  56. package/enums/MintingStrategy.js +2 -0
  57. package/enums/PropertyVisibility.d.ts +2 -0
  58. package/enums/PropertyVisibility.js +2 -0
  59. package/enums/TsFeature.d.ts +5 -0
  60. package/enums/TsFeature.js +16 -0
  61. package/enums/TsObjectDeclarationType.d.ts +5 -0
  62. package/enums/TsObjectDeclarationType.js +2 -0
  63. package/enums/index.d.ts +5 -0
  64. package/enums/index.js +5 -0
  65. package/generators/Generator.d.ts +5 -0
  66. package/generators/Generator.js +2 -0
  67. package/generators/index.d.ts +2 -2
  68. package/generators/index.js +2 -2
  69. package/generators/json/AstJsonGenerator.d.ts +4 -5
  70. package/generators/json/AstJsonGenerator.js +31 -22
  71. package/generators/ts/BooleanType.d.ts +7 -3
  72. package/generators/ts/BooleanType.js +58 -4
  73. package/generators/ts/DateTimeType.d.ts +17 -0
  74. package/generators/ts/DateTimeType.js +58 -0
  75. package/generators/ts/DeclaredType.d.ts +17 -0
  76. package/generators/ts/DeclaredType.js +10 -0
  77. package/generators/ts/IdentifierType.d.ts +7 -17
  78. package/generators/ts/IdentifierType.js +69 -60
  79. package/generators/ts/Import.d.ts +18 -0
  80. package/generators/ts/Import.js +59 -0
  81. package/generators/ts/ListType.d.ts +18 -8
  82. package/generators/ts/ListType.js +197 -43
  83. package/generators/ts/LiteralType.d.ts +13 -11
  84. package/generators/ts/LiteralType.js +36 -51
  85. package/generators/ts/NumberType.d.ts +7 -3
  86. package/generators/ts/NumberType.js +55 -4
  87. package/generators/ts/ObjectType.d.ts +47 -25
  88. package/generators/ts/ObjectType.js +222 -49
  89. package/generators/ts/ObjectUnionType.d.ts +58 -0
  90. package/generators/ts/ObjectUnionType.js +481 -0
  91. package/generators/ts/OptionType.d.ts +12 -4
  92. package/generators/ts/OptionType.js +65 -16
  93. package/generators/ts/PrimitiveType.d.ts +15 -5
  94. package/generators/ts/PrimitiveType.js +20 -29
  95. package/generators/ts/SetType.d.ts +12 -4
  96. package/generators/ts/SetType.js +103 -29
  97. package/generators/ts/StringType.d.ts +8 -3
  98. package/generators/ts/StringType.js +57 -3
  99. package/generators/ts/TermType.d.ts +52 -0
  100. package/generators/ts/TermType.js +234 -0
  101. package/generators/ts/TsGenerator.d.ts +4 -12
  102. package/generators/ts/TsGenerator.js +44 -100
  103. package/generators/ts/Type.d.ts +107 -46
  104. package/generators/ts/Type.js +78 -61
  105. package/generators/ts/TypeFactory.d.ts +4 -5
  106. package/generators/ts/TypeFactory.js +212 -89
  107. package/generators/ts/UnionType.d.ts +19 -6
  108. package/generators/ts/UnionType.js +230 -120
  109. package/generators/ts/_ObjectType/IdentifierProperty.d.ts +27 -7
  110. package/generators/ts/_ObjectType/IdentifierProperty.js +143 -31
  111. package/generators/ts/_ObjectType/Property.d.ts +125 -9
  112. package/generators/ts/_ObjectType/Property.js +25 -3
  113. package/generators/ts/_ObjectType/ShaclProperty.d.ts +23 -5
  114. package/generators/ts/_ObjectType/ShaclProperty.js +100 -26
  115. package/generators/ts/_ObjectType/TypeDiscriminatorProperty.d.ts +24 -6
  116. package/generators/ts/_ObjectType/TypeDiscriminatorProperty.js +75 -13
  117. package/generators/ts/_ObjectType/classDeclaration.d.ts +2 -1
  118. package/generators/ts/_ObjectType/classDeclaration.js +79 -111
  119. package/generators/ts/_ObjectType/createFunctionDeclaration.d.ts +5 -0
  120. package/generators/ts/_ObjectType/createFunctionDeclaration.js +60 -0
  121. package/generators/ts/_ObjectType/equalsFunctionDeclaration.d.ts +2 -1
  122. package/generators/ts/_ObjectType/equalsFunctionDeclaration.js +12 -20
  123. package/generators/ts/_ObjectType/equalsFunctionOrMethodDeclaration.d.ts +11 -0
  124. package/generators/ts/_ObjectType/equalsFunctionOrMethodDeclaration.js +70 -0
  125. package/generators/ts/_ObjectType/fromJsonFunctionDeclarations.d.ts +4 -0
  126. package/generators/ts/_ObjectType/fromJsonFunctionDeclarations.js +78 -0
  127. package/generators/ts/_ObjectType/fromRdfFunctionDeclarations.d.ts +4 -0
  128. package/generators/ts/_ObjectType/fromRdfFunctionDeclarations.js +91 -0
  129. package/generators/ts/_ObjectType/hashFunctionDeclaration.d.ts +3 -3
  130. package/generators/ts/_ObjectType/hashFunctionDeclaration.js +11 -55
  131. package/generators/ts/_ObjectType/hashFunctionOrMethodDeclaration.d.ts +11 -0
  132. package/generators/ts/_ObjectType/hashFunctionOrMethodDeclaration.js +64 -0
  133. package/generators/ts/_ObjectType/index.d.ts +8 -2
  134. package/generators/ts/_ObjectType/index.js +8 -2
  135. package/generators/ts/_ObjectType/interfaceDeclaration.d.ts +3 -2
  136. package/generators/ts/_ObjectType/interfaceDeclaration.js +11 -2
  137. package/generators/ts/_ObjectType/jsonSchemaFunctionDeclaration.d.ts +5 -0
  138. package/generators/ts/_ObjectType/jsonSchemaFunctionDeclaration.js +19 -0
  139. package/generators/ts/_ObjectType/jsonUiSchemaFunctionDeclaration.d.ts +5 -0
  140. package/generators/ts/_ObjectType/jsonUiSchemaFunctionDeclaration.js +31 -0
  141. package/generators/ts/_ObjectType/jsonZodSchemaFunctionDeclaration.d.ts +5 -0
  142. package/generators/ts/_ObjectType/jsonZodSchemaFunctionDeclaration.js +37 -0
  143. package/generators/ts/_ObjectType/rdfjsTermExpression.d.ts +6 -0
  144. package/generators/ts/{rdfjsTermExpression.js → _ObjectType/rdfjsTermExpression.js} +3 -1
  145. package/generators/ts/_ObjectType/sparqlFunctionDeclarations.d.ts +4 -0
  146. package/generators/ts/_ObjectType/sparqlFunctionDeclarations.js +101 -0
  147. package/generators/ts/_ObjectType/toJsonFunctionDeclaration.d.ts +5 -0
  148. package/generators/ts/_ObjectType/toJsonFunctionDeclaration.js +19 -0
  149. package/generators/ts/_ObjectType/toJsonFunctionOrMethodDeclaration.d.ts +10 -0
  150. package/generators/ts/_ObjectType/toJsonFunctionOrMethodDeclaration.js +59 -0
  151. package/generators/ts/_ObjectType/toJsonReturnType.d.ts +3 -0
  152. package/generators/ts/_ObjectType/toJsonReturnType.js +19 -0
  153. package/generators/ts/_ObjectType/toRdfFunctionDeclaration.d.ts +3 -2
  154. package/generators/ts/_ObjectType/toRdfFunctionDeclaration.js +11 -45
  155. package/generators/ts/_ObjectType/toRdfFunctionOrMethodDeclaration.d.ts +10 -0
  156. package/generators/ts/_ObjectType/toRdfFunctionOrMethodDeclaration.js +67 -0
  157. package/generators/ts/objectInitializer.d.ts +2 -0
  158. package/generators/ts/objectInitializer.js +14 -0
  159. package/generators/ts/tsComment.d.ts +5 -0
  160. package/generators/ts/tsComment.js +11 -0
  161. package/generators/ts/tsName.d.ts +1 -1
  162. package/generators/ts/tsName.js +1 -0
  163. package/index.d.ts +1 -1
  164. package/index.js +1 -1
  165. package/input/NodeShape.d.ts +46 -0
  166. package/input/NodeShape.js +165 -0
  167. package/input/Ontology.d.ts +13 -0
  168. package/input/Ontology.js +30 -0
  169. package/input/PropertyShape.d.ts +15 -0
  170. package/input/PropertyShape.js +34 -0
  171. package/input/Shape.d.ts +4 -0
  172. package/input/Shape.js +2 -0
  173. package/input/ShapesGraph.d.ts +9 -0
  174. package/input/ShapesGraph.js +50 -0
  175. package/input/ancestorClassIris.d.ts +4 -0
  176. package/input/ancestorClassIris.js +21 -0
  177. package/input/descendantClassIris.d.ts +4 -0
  178. package/input/descendantClassIris.js +21 -0
  179. package/input/generated.d.ts +274 -0
  180. package/input/generated.js +1420 -0
  181. package/input/index.d.ts +7 -0
  182. package/input/index.js +7 -0
  183. package/input/tsFeatures.d.ts +10 -0
  184. package/input/tsFeatures.js +42 -0
  185. package/package.json +14 -8
  186. package/ast/MintingStrategy.d.ts +0 -8
  187. package/ast/MintingStrategy.js +0 -9
  188. package/generators/ts/Configuration.d.ts +0 -29
  189. package/generators/ts/Configuration.js +0 -40
  190. package/generators/ts/IntersectionType.d.ts +0 -14
  191. package/generators/ts/IntersectionType.js +0 -26
  192. package/generators/ts/RdfjsTermType.d.ts +0 -25
  193. package/generators/ts/RdfjsTermType.js +0 -46
  194. package/generators/ts/_ObjectType/fromRdfFunctionDeclaration.d.ts +0 -4
  195. package/generators/ts/_ObjectType/fromRdfFunctionDeclaration.js +0 -72
  196. package/generators/ts/_ObjectType/sparqlGraphPatternsClassDeclaration.d.ts +0 -4
  197. package/generators/ts/_ObjectType/sparqlGraphPatternsClassDeclaration.js +0 -46
  198. package/generators/ts/rdfjsTermExpression.d.ts +0 -5
  199. package/vocabularies/dashDataset.d.ts +0 -3
  200. package/vocabularies/dashDataset.js +0 -2370
  201. package/vocabularies/index.d.ts +0 -2
  202. package/vocabularies/index.js +0 -2
  203. package/vocabularies/shaclmate.d.ts +0 -15
  204. package/vocabularies/shaclmate.js +0 -6
@@ -1,101 +1,204 @@
1
1
  import TermMap from "@rdfjs/term-map";
2
- import { xsd } from "@tpluscode/rdf-ns-builders";
2
+ import TermSet from "@rdfjs/term-set";
3
+ import { rdf, xsd } from "@tpluscode/rdf-ns-builders";
3
4
  import { Maybe } from "purify-ts";
4
- import { NodeKind } from "shacl-ast";
5
- import { BooleanType } from "./BooleanType";
6
- import { IdentifierType } from "./IdentifierType";
7
- import { IntersectionType } from "./IntersectionType";
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 { OptionType } from "./OptionType";
13
- import { SetType } from "./SetType";
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 { UnionType } from "./UnionType";
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({ configuration }) {
22
+ constructor({ dataFactoryVariable }) {
19
23
  this.cachedObjectTypePropertiesByIdentifier = new TermMap();
20
24
  this.cachedObjectTypesByIdentifier = new TermMap();
21
- this.configuration = configuration;
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
- configuration: this.configuration,
31
+ dataFactoryVariable: this.dataFactoryVariable,
28
32
  defaultValue: astType.defaultValue,
29
- hasValue: astType.hasValue,
33
+ hasValues: astType.hasValues,
34
+ in_: astType.in_,
30
35
  nodeKinds: astType.nodeKinds,
31
36
  });
32
37
  case "IntersectionType":
33
- return new IntersectionType({
34
- configuration: this.configuration,
35
- memberTypes: astType.memberTypes.map((astType) => this.createTypeFromAstType(astType)),
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
- const datatype = astType.datatype
39
- .altLazy(() => astType.defaultValue.map((defaultValue) => defaultValue.datatype))
40
- .altLazy(() => astType.hasValue.map((hasValue) => hasValue.datatype))
41
- .extractNullable();
42
- if (datatype !== null) {
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
- configuration: this.configuration,
66
+ dataFactoryVariable: this.dataFactoryVariable,
46
67
  defaultValue: astType.defaultValue,
47
- hasValue: astType.hasValue,
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.integer)) {
51
- return new NumberType({
52
- configuration: this.configuration,
79
+ if (datatype.equals(xsd.dateTime)) {
80
+ return new DateTimeType({
81
+ dataFactoryVariable: this.dataFactoryVariable,
53
82
  defaultValue: astType.defaultValue,
54
- hasValue: astType.hasValue,
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
- configuration: this.configuration,
132
+ dataFactoryVariable: this.dataFactoryVariable,
60
133
  defaultValue: astType.defaultValue,
61
- hasValue: astType.hasValue,
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
- configuration: this.configuration,
155
+ dataFactoryVariable: this.dataFactoryVariable,
67
156
  defaultValue: astType.defaultValue,
68
- hasValue: astType.hasValue,
157
+ hasValues: astType.hasValues,
158
+ in_: astType.in_,
159
+ languageIn: astType.languageIn,
69
160
  });
70
161
  }
71
- case "ObjectType": {
72
- if (astType.listItemType.isJust()) {
73
- return new ListType({
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
- configuration: this.configuration,
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
- configuration: this.configuration,
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
- configuration: this.configuration,
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
- configuration: this.configuration,
214
+ dataFactoryVariable: this.dataFactoryVariable,
112
215
  defaultValue: Maybe.empty(),
113
- hasValue: Maybe.empty(),
216
+ hasValues: [],
217
+ in_: [],
114
218
  nodeKinds: astType.nodeKinds,
115
219
  });
116
220
  const objectType = new ObjectType({
117
221
  abstract: astType.abstract,
118
- configuration: this.configuration,
222
+ comment: astType.comment,
223
+ dataFactoryVariable: this.dataFactoryVariable,
224
+ declarationType: astType.tsObjectDeclarationType,
119
225
  export_: astType.export,
120
- identifierType,
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
- if (astType.parentObjectTypes.length === 0) {
127
- properties.push(new ObjectType.IdentifierProperty({
128
- configuration: this.configuration,
129
- mintingStrategy: astType.mintingStrategy,
130
- name: this.configuration.objectTypeIdentifierPropertyName,
131
- type: identifierType,
132
- }));
133
- } // Else parent will have the identifier property
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
- properties.push(new ObjectType.TypeDiscriminatorProperty({
145
- abstract: astType.abstract,
146
- configuration: this.configuration,
147
- name: this.configuration.objectTypeDiscriminatorPropertyName,
148
- override: objectType.parentObjectTypes.length > 0 &&
149
- !objectType.parentObjectTypes[0].abstract,
150
- type: {
151
- name: [...typeDiscriminatorValues]
152
- .sort()
153
- .map((name) => `"${name}"`)
154
- .join("|"),
155
- },
156
- value: objectType.discriminatorValue,
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
- rdfType: astType.rdfType,
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
- configuration: this.configuration,
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
- get discriminatorProperty(): Maybe<Type.DiscriminatorProperty>;
11
+ private _name?;
10
12
  get name(): string;
11
- private get typesSharedDiscriminatorProperty();
12
- equalsFunction(): string;
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
- propertySparqlGraphPatternExpression(parameters: Parameters<Type["propertySparqlGraphPatternExpression"]>[0]): Type.SparqlGraphPatternExpression | Type.SparqlGraphPatternsExpression;
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