@shaclmate/compiler 2.0.22 → 2.0.23

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 (172) hide show
  1. package/dist/ShapesGraphToAstTransformer.d.ts +1 -0
  2. package/dist/ShapesGraphToAstTransformer.js +56 -12
  3. package/dist/_ShapesGraphToAstTransformer/flattenAstObjectCompositeTypeMemberTypes.d.ts +13 -0
  4. package/dist/_ShapesGraphToAstTransformer/flattenAstObjectCompositeTypeMemberTypes.js +51 -0
  5. package/dist/_ShapesGraphToAstTransformer/shapeAstName.js +53 -12
  6. package/dist/_ShapesGraphToAstTransformer/transformNodeShapeToAstType.d.ts +5 -0
  7. package/dist/_ShapesGraphToAstTransformer/transformNodeShapeToAstType.js +130 -54
  8. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstCompositeType.d.ts +2 -3
  9. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstCompositeType.js +122 -129
  10. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstIdentifierType.d.ts +2 -2
  11. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstLiteralType.d.ts +2 -2
  12. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstObjectTypeProperty.js +127 -5
  13. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstTermType.d.ts +3 -3
  14. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstType.d.ts +2 -3
  15. package/dist/ast/Ast.d.ts +0 -1
  16. package/dist/ast/Curie.d.ts +14 -0
  17. package/dist/ast/Curie.js +21 -0
  18. package/dist/ast/IdentifierType.d.ts +3 -2
  19. package/dist/ast/ListType.d.ts +2 -1
  20. package/dist/ast/LiteralType.d.ts +1 -1
  21. package/dist/ast/Name.d.ts +40 -5
  22. package/dist/ast/ObjectCompositeType.d.ts +11 -0
  23. package/dist/ast/ObjectType.d.ts +18 -13
  24. package/dist/ast/ObjectUnionType.d.ts +0 -11
  25. package/dist/ast/OptionType.d.ts +2 -2
  26. package/dist/ast/SetType.d.ts +2 -2
  27. package/dist/ast/TermType.d.ts +12 -4
  28. package/dist/ast/Type.d.ts +1 -1
  29. package/dist/enums/TsFeature.d.ts +1 -4
  30. package/dist/enums/TsFeature.js +1 -15
  31. package/dist/generators/json/AstJsonGenerator.js +19 -3
  32. package/dist/generators/ts/BooleanType.d.ts +3 -1
  33. package/dist/generators/ts/BooleanType.js +11 -2
  34. package/dist/generators/ts/DateTimeType.d.ts +8 -7
  35. package/dist/generators/ts/DateTimeType.js +31 -7
  36. package/dist/generators/ts/DateType.d.ts +5 -2
  37. package/dist/generators/ts/DateType.js +15 -1
  38. package/dist/generators/ts/DeclaredType.d.ts +2 -2
  39. package/dist/generators/ts/DeclaredType.js +2 -2
  40. package/dist/generators/ts/FloatType.d.ts +6 -0
  41. package/dist/generators/ts/FloatType.js +18 -0
  42. package/dist/generators/ts/IdentifierType.d.ts +12 -7
  43. package/dist/generators/ts/IdentifierType.js +94 -6
  44. package/dist/generators/ts/Import.d.ts +2 -0
  45. package/dist/generators/ts/Import.js +10 -0
  46. package/dist/generators/ts/IntType.d.ts +6 -0
  47. package/dist/generators/ts/IntType.js +18 -0
  48. package/dist/generators/ts/ListType.d.ts +15 -12
  49. package/dist/generators/ts/ListType.js +98 -57
  50. package/dist/generators/ts/LiteralType.d.ts +10 -9
  51. package/dist/generators/ts/LiteralType.js +13 -2
  52. package/dist/generators/ts/NumberType.d.ts +2 -1
  53. package/dist/generators/ts/NumberType.js +7 -2
  54. package/dist/generators/ts/ObjectType.d.ts +66 -43
  55. package/dist/generators/ts/ObjectType.js +144 -123
  56. package/dist/generators/ts/ObjectUnionType.d.ts +49 -8
  57. package/dist/generators/ts/ObjectUnionType.js +290 -97
  58. package/dist/generators/ts/OptionType.d.ts +14 -10
  59. package/dist/generators/ts/OptionType.js +60 -34
  60. package/dist/generators/ts/PrimitiveType.d.ts +4 -4
  61. package/dist/generators/ts/PrimitiveType.js +18 -3
  62. package/dist/generators/ts/SetType.d.ts +16 -12
  63. package/dist/generators/ts/SetType.js +69 -40
  64. package/dist/generators/ts/SnippetDeclarations.d.ts +13 -8
  65. package/dist/generators/ts/SnippetDeclarations.js +215 -101
  66. package/dist/generators/ts/StringType.d.ts +3 -1
  67. package/dist/generators/ts/StringType.js +14 -2
  68. package/dist/generators/ts/TermType.d.ts +22 -14
  69. package/dist/generators/ts/TermType.js +53 -25
  70. package/dist/generators/ts/TsGenerator.d.ts +2 -1
  71. package/dist/generators/ts/TsGenerator.js +23 -12
  72. package/dist/generators/ts/Type.d.ts +89 -31
  73. package/dist/generators/ts/Type.js +57 -54
  74. package/dist/generators/ts/TypeFactory.d.ts +4 -5
  75. package/dist/generators/ts/TypeFactory.js +290 -226
  76. package/dist/generators/ts/UnionType.d.ts +14 -10
  77. package/dist/generators/ts/UnionType.js +319 -142
  78. package/dist/generators/ts/_ObjectType/EagerShaclProperty.d.ts +12 -0
  79. package/dist/generators/ts/_ObjectType/EagerShaclProperty.js +30 -0
  80. package/dist/generators/ts/_ObjectType/IdentifierPrefixProperty.d.ts +13 -12
  81. package/dist/generators/ts/_ObjectType/IdentifierPrefixProperty.js +46 -47
  82. package/dist/generators/ts/_ObjectType/IdentifierProperty.d.ts +20 -13
  83. package/dist/generators/ts/_ObjectType/IdentifierProperty.js +152 -124
  84. package/dist/generators/ts/_ObjectType/LazyShaclProperty.d.ts +87 -0
  85. package/dist/generators/ts/_ObjectType/LazyShaclProperty.js +237 -0
  86. package/dist/generators/ts/_ObjectType/Property.d.ts +39 -44
  87. package/dist/generators/ts/_ObjectType/Property.js +1 -10
  88. package/dist/generators/ts/_ObjectType/ShaclProperty.d.ts +25 -30
  89. package/dist/generators/ts/_ObjectType/ShaclProperty.js +108 -85
  90. package/dist/generators/ts/_ObjectType/TypeDiscriminatorProperty.d.ts +21 -17
  91. package/dist/generators/ts/_ObjectType/TypeDiscriminatorProperty.js +61 -53
  92. package/dist/generators/ts/_ObjectType/classDeclaration.js +6 -5
  93. package/dist/generators/ts/_ObjectType/createFunctionDeclaration.js +5 -4
  94. package/dist/generators/ts/_ObjectType/equalsFunctionOrMethodDeclaration.js +5 -4
  95. package/dist/generators/ts/_ObjectType/fromRdfTypeVariableStatement.d.ts +1 -1
  96. package/dist/generators/ts/_ObjectType/fromRdfTypeVariableStatement.js +8 -5
  97. package/dist/generators/ts/_ObjectType/graphqlTypeVariableStatement.d.ts +5 -0
  98. package/dist/generators/ts/_ObjectType/graphqlTypeVariableStatement.js +37 -0
  99. package/dist/generators/ts/_ObjectType/hashFunctionOrMethodDeclarations.js +7 -8
  100. package/dist/generators/ts/_ObjectType/identifierTypeDeclarations.d.ts +7 -0
  101. package/dist/generators/ts/_ObjectType/identifierTypeDeclarations.js +54 -0
  102. package/dist/generators/ts/_ObjectType/index.d.ts +9 -7
  103. package/dist/generators/ts/_ObjectType/index.js +9 -7
  104. package/dist/generators/ts/_ObjectType/interfaceDeclaration.js +1 -1
  105. package/dist/generators/ts/_ObjectType/jsonFunctionDeclarations.d.ts +4 -0
  106. package/dist/generators/ts/_ObjectType/jsonFunctionDeclarations.js +189 -0
  107. package/dist/generators/ts/_ObjectType/jsonTypeAliasDeclaration.d.ts +5 -0
  108. package/dist/generators/ts/_ObjectType/jsonTypeAliasDeclaration.js +28 -0
  109. package/dist/generators/ts/_ObjectType/objectSetMethodNames.d.ts +9 -0
  110. package/dist/generators/ts/_ObjectType/objectSetMethodNames.js +18 -0
  111. package/dist/generators/ts/_ObjectType/propertiesVariableStatement.d.ts +5 -0
  112. package/dist/generators/ts/_ObjectType/propertiesVariableStatement.js +37 -0
  113. package/dist/generators/ts/_ObjectType/rdfFunctionDeclarations.d.ts +4 -0
  114. package/dist/generators/ts/_ObjectType/rdfFunctionDeclarations.js +152 -0
  115. package/dist/generators/ts/_ObjectType/sparqlConstructQueryFunctionDeclaration.d.ts +1 -1
  116. package/dist/generators/ts/_ObjectType/sparqlConstructQueryFunctionDeclaration.js +4 -3
  117. package/dist/generators/ts/_ObjectType/sparqlConstructQueryStringFunctionDeclaration.d.ts +1 -1
  118. package/dist/generators/ts/_ObjectType/sparqlConstructQueryStringFunctionDeclaration.js +3 -2
  119. package/dist/generators/ts/_ObjectType/sparqlFunctionDeclarations.js +103 -35
  120. package/dist/generators/ts/_ObjectType/toJsonFunctionOrMethodDeclaration.js +6 -6
  121. package/dist/generators/ts/_ObjectType/toRdfFunctionOrMethodDeclaration.js +15 -13
  122. package/dist/generators/ts/graphqlSchemaVariableStatement.d.ts +9 -0
  123. package/dist/generators/ts/graphqlSchemaVariableStatement.js +86 -0
  124. package/dist/generators/ts/objectSetDeclarations.d.ts +8 -0
  125. package/dist/generators/ts/objectSetDeclarations.js +59 -0
  126. package/dist/generators/ts/objectSetInterfaceDeclaration.d.ts +8 -0
  127. package/dist/generators/ts/objectSetInterfaceDeclaration.js +46 -0
  128. package/dist/generators/ts/objectSetMethodSignatures.d.ts +11 -0
  129. package/dist/generators/ts/objectSetMethodSignatures.js +52 -0
  130. package/dist/generators/ts/rdfjsDatasetObjectSetClassDeclaration.d.ts +8 -0
  131. package/dist/generators/ts/rdfjsDatasetObjectSetClassDeclaration.js +393 -0
  132. package/dist/generators/ts/rdfjsTermExpression.d.ts +3 -0
  133. package/dist/generators/ts/rdfjsTermExpression.js +57 -0
  134. package/dist/generators/ts/sparqlObjectSetClassDeclaration.d.ts +8 -0
  135. package/dist/generators/ts/sparqlObjectSetClassDeclaration.js +415 -0
  136. package/dist/generators/ts/syntheticNamePrefix.d.ts +2 -0
  137. package/dist/generators/ts/syntheticNamePrefix.js +2 -0
  138. package/dist/generators/ts/tsName.js +27 -13
  139. package/dist/generators/ts/unsupportedObjectSetMethodDeclarations.d.ts +10 -0
  140. package/dist/generators/ts/unsupportedObjectSetMethodDeclarations.js +19 -0
  141. package/dist/input/NodeShape.d.ts +6 -8
  142. package/dist/input/NodeShape.js +20 -44
  143. package/dist/input/Ontology.d.ts +0 -3
  144. package/dist/input/Ontology.js +0 -9
  145. package/dist/input/PropertyPath.d.ts +6 -5
  146. package/dist/input/PropertyPath.js +14 -22
  147. package/dist/input/PropertyShape.d.ts +3 -1
  148. package/dist/input/PropertyShape.js +8 -2
  149. package/dist/input/ShapesGraph.js +4 -4
  150. package/dist/input/generated.d.ts +923 -105
  151. package/dist/input/generated.js +1865 -969
  152. package/dist/input/tsFeatures.d.ts +3 -2
  153. package/dist/input/tsFeatures.js +44 -27
  154. package/package.json +18 -16
  155. package/dist/generators/ts/_ObjectType/fromJsonFunctionDeclarations.d.ts +0 -4
  156. package/dist/generators/ts/_ObjectType/fromJsonFunctionDeclarations.js +0 -78
  157. package/dist/generators/ts/_ObjectType/fromRdfFunctionDeclarations.d.ts +0 -4
  158. package/dist/generators/ts/_ObjectType/fromRdfFunctionDeclarations.js +0 -91
  159. package/dist/generators/ts/_ObjectType/jsonSchemaFunctionDeclaration.d.ts +0 -5
  160. package/dist/generators/ts/_ObjectType/jsonSchemaFunctionDeclaration.js +0 -19
  161. package/dist/generators/ts/_ObjectType/jsonUiSchemaFunctionDeclaration.d.ts +0 -5
  162. package/dist/generators/ts/_ObjectType/jsonUiSchemaFunctionDeclaration.js +0 -31
  163. package/dist/generators/ts/_ObjectType/jsonZodSchemaFunctionDeclaration.d.ts +0 -5
  164. package/dist/generators/ts/_ObjectType/jsonZodSchemaFunctionDeclaration.js +0 -37
  165. package/dist/generators/ts/_ObjectType/rdfjsTermExpression.d.ts +0 -6
  166. package/dist/generators/ts/_ObjectType/rdfjsTermExpression.js +0 -17
  167. package/dist/generators/ts/_ObjectType/toJsonFunctionDeclaration.d.ts +0 -5
  168. package/dist/generators/ts/_ObjectType/toJsonFunctionDeclaration.js +0 -19
  169. package/dist/generators/ts/_ObjectType/toJsonReturnType.d.ts +0 -3
  170. package/dist/generators/ts/_ObjectType/toJsonReturnType.js +0 -17
  171. package/dist/generators/ts/_ObjectType/toRdfFunctionDeclaration.d.ts +0 -5
  172. package/dist/generators/ts/_ObjectType/toRdfFunctionDeclaration.js +0 -19
@@ -0,0 +1,415 @@
1
+ import { Scope, StructureKind, } from "ts-morph";
2
+ import { objectSetMethodSignatures } from "./objectSetMethodSignatures.js";
3
+ import { syntheticNamePrefix } from "./syntheticNamePrefix.js";
4
+ import { unsupportedObjectSetMethodDeclarations } from "./unsupportedObjectSetMethodDeclarations.js";
5
+ export function sparqlObjectSetClassDeclaration({ objectTypes, objectUnionTypes, }) {
6
+ const typeParameters = {
7
+ ObjectT: {
8
+ name: "ObjectT",
9
+ },
10
+ ObjectIdentifierT: {
11
+ constraint: "rdfjs.BlankNode | rdfjs.NamedNode",
12
+ name: "ObjectIdentifierT",
13
+ },
14
+ };
15
+ const sparqlWherePatternsFunctionType = `(parameters?: { subject?: sparqljs.Triple["subject"]; }) => readonly sparqljs.Pattern[]`;
16
+ const parameters = {
17
+ constructObjectType: {
18
+ name: "objectType",
19
+ type: `{\
20
+ ${syntheticNamePrefix}fromRdf: (parameters: { objectSet: ${syntheticNamePrefix}ObjectSet, resource: rdfjsResource.Resource }) => purify.Either<Error, ${typeParameters.ObjectT.name}>;
21
+ ${syntheticNamePrefix}sparqlConstructQueryString: (parameters?: { subject?: sparqljs.Triple["subject"]; } & Omit<sparqljs.ConstructQuery, "prefixes" | "queryType" | "type"> & sparqljs.GeneratorOptions) => string;
22
+ ${syntheticNamePrefix}sparqlWherePatterns: ${sparqlWherePatternsFunctionType};
23
+ }`,
24
+ },
25
+ query: {
26
+ hasQuestionToken: true,
27
+ name: "query",
28
+ type: `${syntheticNamePrefix}SparqlObjectSet.Query<${typeParameters.ObjectIdentifierT.name}>`,
29
+ },
30
+ selectObjectTypeType: {
31
+ name: "objectType",
32
+ type: `{ ${syntheticNamePrefix}sparqlWherePatterns: ${sparqlWherePatternsFunctionType} }`,
33
+ },
34
+ where: {
35
+ hasQuestionToken: true,
36
+ name: "where",
37
+ type: `${syntheticNamePrefix}SparqlObjectSet.Where<${typeParameters.ObjectIdentifierT.name}>`,
38
+ },
39
+ };
40
+ return [
41
+ {
42
+ ctors: [
43
+ {
44
+ parameters: [
45
+ {
46
+ name: "{ sparqlClient }",
47
+ type: `{ sparqlClient: ${syntheticNamePrefix}SparqlObjectSet["${syntheticNamePrefix}sparqlClient"] }`,
48
+ },
49
+ ],
50
+ statements: [
51
+ `this.${syntheticNamePrefix}sparqlClient = sparqlClient;`,
52
+ ],
53
+ },
54
+ ],
55
+ implements: [`${syntheticNamePrefix}ObjectSet`],
56
+ isExported: true,
57
+ kind: StructureKind.Class,
58
+ name: `${syntheticNamePrefix}SparqlObjectSet`,
59
+ // methods: [
60
+ methods: [...objectTypes, ...objectUnionTypes].flatMap((objectType) => {
61
+ if (!objectType.features.has("sparql")) {
62
+ return unsupportedObjectSetMethodDeclarations({
63
+ objectType,
64
+ });
65
+ }
66
+ const methodSignatures = objectSetMethodSignatures({
67
+ objectType,
68
+ queryT: `${syntheticNamePrefix}SparqlObjectSet.Query`,
69
+ });
70
+ const runtimeObjectType = objectType.staticModuleName;
71
+ return [
72
+ {
73
+ ...methodSignatures.object,
74
+ kind: StructureKind.Method,
75
+ isAsync: true,
76
+ statements: [
77
+ `return (await this.${methodSignatures.objects.name}({ where: { identifiers: [identifier], type: "identifiers" } })).map(objects => objects[0]);`,
78
+ ],
79
+ },
80
+ {
81
+ ...methodSignatures.objectIdentifiers,
82
+ kind: StructureKind.Method,
83
+ isAsync: true,
84
+ statements: [
85
+ `return this.${syntheticNamePrefix}objectIdentifiers<${objectType.identifierTypeAlias}>(${runtimeObjectType}, query);`,
86
+ ],
87
+ },
88
+ {
89
+ ...methodSignatures.objects,
90
+ kind: StructureKind.Method,
91
+ isAsync: true,
92
+ statements: [
93
+ `return this.${syntheticNamePrefix}objects<${objectType.name}, ${objectType.identifierTypeAlias}>(${runtimeObjectType}, query);`,
94
+ ],
95
+ },
96
+ {
97
+ ...methodSignatures.objectsCount,
98
+ isAsync: true,
99
+ kind: StructureKind.Method,
100
+ statements: [
101
+ `return this.${syntheticNamePrefix}objectsCount<${objectType.identifierTypeAlias}>(${runtimeObjectType}, query);`,
102
+ ],
103
+ },
104
+ ];
105
+ }).concat({
106
+ kind: StructureKind.Method,
107
+ name: `${syntheticNamePrefix}mapBindingsToCount`,
108
+ parameters: [
109
+ {
110
+ name: "bindings",
111
+ type: "readonly Record<string, rdfjs.BlankNode | rdfjs.Literal | rdfjs.NamedNode>[]",
112
+ },
113
+ {
114
+ name: "variable",
115
+ type: "string",
116
+ },
117
+ ],
118
+ returnType: "purify.Either<Error, number>",
119
+ scope: Scope.Protected,
120
+ statements: [
121
+ `\
122
+ if (bindings.length === 0) {
123
+ return purify.Left(new Error("empty result rows"));
124
+ }
125
+ if (bindings.length > 1) {
126
+ return purify.Left(new Error("more than one result row"));
127
+ }
128
+ const count = bindings[0][variable];
129
+ if (typeof count === "undefined") {
130
+ return purify.Left(new Error("no 'count' variable in result row"));
131
+ }
132
+ if (count.termType !== "Literal") {
133
+ return purify.Left(new Error("'count' variable is not a Literal"));
134
+ }
135
+ const parsedCount = Number.parseInt(count.value);
136
+ if (Number.isNaN(parsedCount)) {
137
+ return purify.Left(new Error("'count' variable is NaN"));
138
+ }
139
+ return purify.Either.of(parsedCount);`,
140
+ ],
141
+ }, {
142
+ kind: StructureKind.Method,
143
+ name: `${syntheticNamePrefix}mapBindingsToIdentifiers`,
144
+ parameters: [
145
+ {
146
+ name: "bindings",
147
+ type: "readonly Record<string, rdfjs.BlankNode | rdfjs.Literal | rdfjs.NamedNode>[]",
148
+ },
149
+ {
150
+ name: "variable",
151
+ type: "string",
152
+ },
153
+ ],
154
+ returnType: "readonly rdfjs.NamedNode[]",
155
+ scope: Scope.Protected,
156
+ statements: [
157
+ `\
158
+ const identifiers: rdfjs.NamedNode[] = [];
159
+ for (const bindings_ of bindings) {
160
+ const identifier = bindings_[variable];
161
+ if (
162
+ typeof identifier !== "undefined" &&
163
+ identifier.termType === "NamedNode"
164
+ ) {
165
+ identifiers.push(identifier);
166
+ }
167
+ }
168
+ return identifiers;`,
169
+ ],
170
+ }, {
171
+ kind: StructureKind.Method,
172
+ isAsync: true,
173
+ name: `${syntheticNamePrefix}objectIdentifiers`,
174
+ parameters: [parameters.selectObjectTypeType, parameters.query],
175
+ returnType: `Promise<purify.Either<Error, readonly ${typeParameters.ObjectIdentifierT.name}[]>>`,
176
+ scope: Scope.Protected,
177
+ statements: [
178
+ `\
179
+ const limit = query?.limit ?? Number.MAX_SAFE_INTEGER;
180
+ if (limit <= 0) {
181
+ return purify.Either.of([]);
182
+ }
183
+
184
+ let offset = query?.offset ?? 0;
185
+ if (offset < 0) {
186
+ offset = 0;
187
+ }
188
+
189
+ const wherePatterns = this.${syntheticNamePrefix}wherePatterns(objectType, query?.where).filter(pattern => pattern.type !== "optional");
190
+ if (wherePatterns.length === 0) {
191
+ return purify.Left(new Error("no required SPARQL WHERE patterns for identifiers"));
192
+ }
193
+
194
+ const selectQueryString = \
195
+ this.${syntheticNamePrefix}sparqlGenerator.stringify({
196
+ distinct: true,
197
+ limit: limit < Number.MAX_SAFE_INTEGER ? limit : undefined,
198
+ offset,
199
+ order: query?.order ? query.order(this.${syntheticNamePrefix}objectVariable).concat() : [{ expression: this.${syntheticNamePrefix}objectVariable }],
200
+ prefixes: {},
201
+ queryType: "SELECT",
202
+ type: "query",
203
+ variables: [this.${syntheticNamePrefix}objectVariable],
204
+ where: wherePatterns
205
+ });
206
+
207
+ return purify.EitherAsync(async () =>
208
+ this.${syntheticNamePrefix}mapBindingsToIdentifiers(
209
+ await this.${syntheticNamePrefix}sparqlClient.queryBindings(selectQueryString),
210
+ this.${syntheticNamePrefix}objectVariable.value,
211
+ ) as readonly ${typeParameters.ObjectIdentifierT.name}[],
212
+ );`,
213
+ ],
214
+ typeParameters: [typeParameters.ObjectIdentifierT],
215
+ }, {
216
+ isAsync: true,
217
+ kind: StructureKind.Method,
218
+ name: `${syntheticNamePrefix}objects`,
219
+ parameters: [parameters.constructObjectType, parameters.query],
220
+ returnType: `Promise<purify.Either<Error, readonly ${typeParameters.ObjectT.name}[]>>`,
221
+ statements: [
222
+ `\
223
+ const identifiersEither = await this.${syntheticNamePrefix}objectIdentifiers<${typeParameters.ObjectIdentifierT.name}>(objectType, query);
224
+ if (identifiersEither.isLeft()) {
225
+ return identifiersEither;
226
+ }
227
+ const identifiers = identifiersEither.unsafeCoerce();
228
+ if (identifiers.length === 0) {
229
+ return purify.Either.of([]);
230
+ }
231
+
232
+ const constructQueryString = objectType.${syntheticNamePrefix}sparqlConstructQueryString({
233
+ subject: this.${syntheticNamePrefix}objectVariable,
234
+ where: [{
235
+ type: "values" as const,
236
+ values: identifiers.map((identifier) => {
237
+ const valuePatternRow: sparqljs.ValuePatternRow = {};
238
+ valuePatternRow["?object"] = identifier as rdfjs.NamedNode;
239
+ return valuePatternRow;
240
+ }),
241
+ }]
242
+ });
243
+
244
+ let quads: readonly rdfjs.Quad[];
245
+ try {
246
+ quads = await this.${syntheticNamePrefix}sparqlClient.queryQuads(constructQueryString);
247
+ } catch (e) {
248
+ return purify.Left(e as Error);
249
+ }
250
+
251
+ const dataset: rdfjs.DatasetCore = new N3.Store(quads.concat());
252
+ const objects: ${typeParameters.ObjectT.name}[] = [];
253
+ for (const identifier of identifiers) {
254
+ const objectEither = objectType.${syntheticNamePrefix}fromRdf({
255
+ objectSet: this,
256
+ resource: new rdfjsResource.Resource<rdfjs.NamedNode>({ dataset, identifier: identifier as rdfjs.NamedNode })
257
+ });
258
+ if (objectEither.isLeft()) {
259
+ return objectEither;
260
+ }
261
+ objects.push(objectEither.unsafeCoerce());
262
+ }
263
+ return purify.Either.of(objects);`,
264
+ ],
265
+ typeParameters: [
266
+ typeParameters.ObjectT,
267
+ typeParameters.ObjectIdentifierT,
268
+ ],
269
+ }, {
270
+ kind: StructureKind.Method,
271
+ isAsync: true,
272
+ name: `${syntheticNamePrefix}objectsCount`,
273
+ parameters: [parameters.selectObjectTypeType, parameters.query],
274
+ returnType: "Promise<purify.Either<Error, number>>",
275
+ scope: Scope.Protected,
276
+ statements: [
277
+ `\
278
+ const wherePatterns = this.${syntheticNamePrefix}wherePatterns(objectType, query?.where).filter(pattern => pattern.type !== "optional");
279
+ if (wherePatterns.length === 0) {
280
+ return purify.Left(new Error("no required SPARQL WHERE patterns for count"));
281
+ }
282
+
283
+ const selectQueryString = \
284
+ this.${syntheticNamePrefix}sparqlGenerator.stringify({
285
+ prefixes: {},
286
+ queryType: "SELECT",
287
+ type: "query",
288
+ variables: [
289
+ {
290
+ expression: {
291
+ aggregation: "COUNT",
292
+ distinct: true,
293
+ expression: this.${syntheticNamePrefix}objectVariable,
294
+ type: "aggregate",
295
+ },
296
+ variable: this.${syntheticNamePrefix}countVariable,
297
+ },
298
+ ],
299
+ where: wherePatterns
300
+ });
301
+
302
+ return purify.EitherAsync(async ({ liftEither }) =>
303
+ liftEither(
304
+ this.${syntheticNamePrefix}mapBindingsToCount(
305
+ await this.${syntheticNamePrefix}sparqlClient.queryBindings(selectQueryString),
306
+ this.${syntheticNamePrefix}countVariable.value,
307
+ ),
308
+ ),
309
+ );`,
310
+ ],
311
+ typeParameters: [typeParameters.ObjectIdentifierT],
312
+ }, {
313
+ kind: StructureKind.Method,
314
+ name: `${syntheticNamePrefix}wherePatterns`,
315
+ parameters: [parameters.selectObjectTypeType, parameters.where],
316
+ returnType: "sparqljs.Pattern[]",
317
+ scope: Scope.Protected,
318
+ statements: [
319
+ `\
320
+ const patterns: sparqljs.Pattern[] = [];
321
+
322
+ // Patterns should be most to least specific.
323
+
324
+ if (where) {
325
+ // Assign a separate variable so the compiler catches any missing cases
326
+ let wherePatterns: readonly sparqljs.Pattern[];
327
+ switch (where.type) {
328
+ case "identifiers": {
329
+ const valuePatternRowKey = \`?\${this.${syntheticNamePrefix}objectVariable.value}\`;
330
+ wherePatterns = [{
331
+ type: "values" as const,
332
+ values: where.identifiers.map((identifier) => {
333
+ const valuePatternRow: sparqljs.ValuePatternRow = {};
334
+ valuePatternRow[valuePatternRowKey] = identifier as rdfjs.NamedNode;
335
+ return valuePatternRow;
336
+ }),
337
+ }];
338
+ break;
339
+ }
340
+ case "sparql-patterns": {
341
+ wherePatterns = where.sparqlPatterns(this.${syntheticNamePrefix}objectVariable);
342
+ break;
343
+ }
344
+ case "triple-objects": {
345
+ wherePatterns = [{
346
+ triples: [{
347
+ subject: where.subject,
348
+ predicate: where.predicate,
349
+ object: this.${syntheticNamePrefix}objectVariable
350
+ }],
351
+ type: "bgp"
352
+ }];
353
+ break;
354
+ }
355
+ }
356
+ patterns.push(...wherePatterns);
357
+ }
358
+
359
+ patterns.push(...objectType.${syntheticNamePrefix}sparqlWherePatterns({ subject: this.${syntheticNamePrefix}objectVariable }));
360
+
361
+ return patterns;`,
362
+ ],
363
+ typeParameters: [typeParameters.ObjectIdentifierT],
364
+ }),
365
+ properties: [
366
+ {
367
+ initializer: `dataFactory.variable!("count");`,
368
+ isReadonly: true,
369
+ name: `${syntheticNamePrefix}countVariable`,
370
+ scope: Scope.Protected,
371
+ },
372
+ {
373
+ initializer: `dataFactory.variable!("object");`,
374
+ isReadonly: true,
375
+ name: `${syntheticNamePrefix}objectVariable`,
376
+ scope: Scope.Protected,
377
+ },
378
+ {
379
+ isReadonly: true,
380
+ name: `${syntheticNamePrefix}sparqlClient`,
381
+ scope: Scope.Protected,
382
+ type: "{ queryBindings: (query: string) => Promise<readonly Record<string, rdfjs.BlankNode | rdfjs.Literal | rdfjs.NamedNode>[]>; queryQuads: (query: string) => Promise<readonly rdfjs.Quad[]>; }",
383
+ },
384
+ {
385
+ initializer: "new sparqljs.Generator()",
386
+ isReadonly: true,
387
+ name: `${syntheticNamePrefix}sparqlGenerator`,
388
+ scope: Scope.Protected,
389
+ },
390
+ ],
391
+ },
392
+ {
393
+ isExported: true,
394
+ kind: StructureKind.Module,
395
+ name: `${syntheticNamePrefix}SparqlObjectSet`,
396
+ statements: [
397
+ {
398
+ isExported: true,
399
+ kind: StructureKind.TypeAlias,
400
+ name: "Query",
401
+ type: `Omit<${syntheticNamePrefix}ObjectSet.Query<${typeParameters.ObjectIdentifierT.name}>, "where"> & { readonly order?: (objectVariable: rdfjs.Variable) => readonly sparqljs.Ordering[]; readonly where?: Where<${typeParameters.ObjectIdentifierT.name}> }`,
402
+ typeParameters: [typeParameters.ObjectIdentifierT],
403
+ },
404
+ {
405
+ kind: StructureKind.TypeAlias,
406
+ isExported: true,
407
+ name: "Where",
408
+ type: `${syntheticNamePrefix}ObjectSet.Where<${typeParameters.ObjectIdentifierT.name}> | { readonly sparqlPatterns: (objectVariable: rdfjs.Variable) => readonly sparqljs.Pattern[]; readonly type: "sparql-patterns" }`,
409
+ typeParameters: [typeParameters.ObjectIdentifierT],
410
+ },
411
+ ],
412
+ },
413
+ ];
414
+ }
415
+ //# sourceMappingURL=sparqlObjectSetClassDeclaration.js.map
@@ -0,0 +1,2 @@
1
+ export declare const syntheticNamePrefix = "$";
2
+ //# sourceMappingURL=syntheticNamePrefix.d.ts.map
@@ -0,0 +1,2 @@
1
+ export const syntheticNamePrefix = "$";
2
+ //# sourceMappingURL=syntheticNamePrefix.js.map
@@ -1,19 +1,33 @@
1
1
  import { Resource } from "rdfjs-resource";
2
2
  import { stringToValidTsIdentifier } from "./stringToValidTsIdentifier.js";
3
+ import { syntheticNamePrefix } from "./syntheticNamePrefix.js";
4
+ function* tsNameAlternatives(astName) {
5
+ yield astName.shaclmateName.extract();
6
+ yield astName.shName.extract()?.replace(" ", "_");
7
+ yield astName.label.extract()?.replace(" ", "_");
8
+ yield astName.propertyPath
9
+ .chain((propertyPath) => propertyPath.uniqueLocalPart())
10
+ .extract();
11
+ yield astName.propertyPath
12
+ .chain((propertyPath) => propertyPath.curie.map((curie) => `${curie.prefix}_${curie.reference}`))
13
+ .extract();
14
+ if (astName.identifier.termType === "NamedNode") {
15
+ yield astName.identifier.uniqueLocalPart().extract();
16
+ yield astName.identifier.curie
17
+ .map((curie) => `${curie.prefix}_${curie.reference}`)
18
+ .extract();
19
+ }
20
+ yield astName.propertyPath
21
+ .map((propertyPath) => Resource.Identifier.toString(propertyPath))
22
+ .extract();
23
+ yield Resource.Identifier.toString(astName.identifier);
24
+ }
3
25
  export function tsName(astName) {
4
- for (const tsNameAlternative of [
5
- astName.shaclmateName.extract(),
6
- astName.shName.extract()?.replace(" ", "_"),
7
- astName.label.extract()?.replace(" ", "_"),
8
- astName.curie.map((curie) => curie.replace(":", "_")).extract(),
9
- astName.propertyPath
10
- .chain((propertyPath) => propertyPath.curie.map((curie) => curie.replace(":", "_")))
11
- .extract(),
12
- astName.propertyPath
13
- .map((propertyPath) => Resource.Identifier.toString(propertyPath.identifier))
14
- .extract(),
15
- Resource.Identifier.toString(astName.identifier),
16
- ]) {
26
+ const syntheticName = astName.syntheticName.extract();
27
+ if (syntheticName) {
28
+ return `${syntheticNamePrefix}${syntheticName}`;
29
+ }
30
+ for (const tsNameAlternative of tsNameAlternatives(astName)) {
17
31
  if (tsNameAlternative) {
18
32
  return stringToValidTsIdentifier(tsNameAlternative);
19
33
  }
@@ -0,0 +1,10 @@
1
+ import { type MethodDeclarationStructure } from "ts-morph";
2
+ import type { ObjectType } from "./ObjectType.js";
3
+ export declare function unsupportedObjectSetMethodDeclarations({ objectType, }: {
4
+ objectType: {
5
+ readonly identifierTypeAlias: string;
6
+ readonly objectSetMethodNames: ObjectType.ObjectSetMethodNames;
7
+ readonly name: string;
8
+ };
9
+ }): readonly MethodDeclarationStructure[];
10
+ //# sourceMappingURL=unsupportedObjectSetMethodDeclarations.d.ts.map
@@ -0,0 +1,19 @@
1
+ import { StructureKind } from "ts-morph";
2
+ import { objectSetMethodSignatures } from "./objectSetMethodSignatures.js";
3
+ export function unsupportedObjectSetMethodDeclarations({ objectType, }) {
4
+ return Object.entries(objectSetMethodSignatures({ objectType })).map(([methodName, methodSignature]) => ({
5
+ ...methodSignature,
6
+ kind: StructureKind.Method,
7
+ parameters: methodSignature.parameters
8
+ ? methodSignature.parameters.map((parameter) => ({
9
+ ...parameter,
10
+ name: `_${parameter.name}`,
11
+ }))
12
+ : methodSignature.parameters,
13
+ isAsync: true,
14
+ statements: methodName === "objects"
15
+ ? [`return [purify.Left(new Error("${methodName}: not supported"))];`]
16
+ : [`return purify.Left(new Error("${methodName}: not supported"));`],
17
+ }));
18
+ }
19
+ //# sourceMappingURL=unsupportedObjectSetMethodDeclarations.js.map
@@ -1,18 +1,18 @@
1
1
  import type { NamedNode } from "@rdfjs/types";
2
- import { NodeShape as ShaclCoreNodeShape } from "@shaclmate/shacl-ast";
2
+ import { type IdentifierNodeKind, NodeShape as ShaclCoreNodeShape } from "@shaclmate/shacl-ast";
3
3
  import { Maybe } from "purify-ts";
4
+ import type * as generated from "./generated.js";
4
5
  import type { IdentifierMintingStrategy, TsFeature, TsObjectDeclarationType } from "../enums/index.js";
5
6
  import type { Shape } from "./Shape.js";
6
- import type * as generated from "./generated.js";
7
7
  import type { Ontology, PropertyGroup, PropertyShape, ShapesGraph } from "./index.js";
8
8
  export declare class NodeShape extends ShaclCoreNodeShape<any, Ontology, PropertyGroup, PropertyShape, Shape> {
9
- readonly isClass: boolean;
10
- readonly isList: boolean;
11
9
  private readonly ancestorClassIris;
12
10
  private readonly childClassIris;
13
11
  private readonly descendantClassIris;
14
12
  private readonly generatedShaclmateNodeShape;
15
13
  private readonly parentClassIris;
14
+ readonly isClass: boolean;
15
+ readonly isList: boolean;
16
16
  constructor({ ancestorClassIris, childClassIris, descendantClassIris, generatedShaclmateNodeShape, isClass, isList, parentClassIris, shapesGraph, }: {
17
17
  ancestorClassIris: readonly NamedNode[];
18
18
  generatedShaclmateNodeShape: generated.ShaclmateNodeShape;
@@ -32,16 +32,14 @@ export declare class NodeShape extends ShaclCoreNodeShape<any, Ontology, Propert
32
32
  get fromRdfType(): Maybe<NamedNode>;
33
33
  get identifierMintingStrategy(): Maybe<IdentifierMintingStrategy>;
34
34
  get mutable(): Maybe<boolean>;
35
- get nodeKinds(): Set<"BlankNode" | "NamedNode">;
35
+ get nodeKinds(): Set<IdentifierNodeKind>;
36
36
  get parentNodeShapes(): readonly NodeShape[];
37
+ get rdfType(): Maybe<NamedNode>;
37
38
  get shaclmateName(): Maybe<string>;
38
39
  get toRdfTypes(): readonly NamedNode[];
39
40
  get tsFeatures(): Maybe<Set<TsFeature>>;
40
41
  get tsImports(): readonly string[];
41
42
  get tsObjectDeclarationType(): Maybe<TsObjectDeclarationType>;
42
- get tsObjectIdentifierPrefixPropertyName(): Maybe<string>;
43
- get tsObjectIdentifierPropertyName(): Maybe<string>;
44
- get tsObjectTypeDiscriminatorPropertyName(): Maybe<string>;
45
43
  private get _mintingStrategy();
46
44
  }
47
45
  //# sourceMappingURL=NodeShape.d.ts.map
@@ -1,14 +1,14 @@
1
- import { NodeShape as ShaclCoreNodeShape } from "@shaclmate/shacl-ast";
1
+ import { NodeShape as ShaclCoreNodeShape, } from "@shaclmate/shacl-ast";
2
2
  import { Maybe } from "purify-ts";
3
3
  import { tsFeatures } from "./tsFeatures.js";
4
4
  export class NodeShape extends ShaclCoreNodeShape {
5
- isClass;
6
- isList;
7
5
  ancestorClassIris;
8
6
  childClassIris;
9
7
  descendantClassIris;
10
8
  generatedShaclmateNodeShape;
11
9
  parentClassIris;
10
+ isClass;
11
+ isList;
12
12
  constructor({ ancestorClassIris, childClassIris, descendantClassIris, generatedShaclmateNodeShape, isClass, isList, parentClassIris, shapesGraph, }) {
13
13
  super(generatedShaclmateNodeShape, shapesGraph);
14
14
  this.ancestorClassIris = ancestorClassIris;
@@ -44,19 +44,7 @@ export class NodeShape extends ShaclCoreNodeShape {
44
44
  return this.generatedShaclmateNodeShape.extern;
45
45
  }
46
46
  get fromRdfType() {
47
- // Check for an explicit shaclmate:fromRdfType
48
- const fromRdfType = this.generatedShaclmateNodeShape.fromRdfType;
49
- if (fromRdfType.isJust()) {
50
- return fromRdfType;
51
- }
52
- // No explicit shaclmate:fromRdfType
53
- // If the shape is a class, not abstract, and identified by an IRI then use the shape IRI as the fromRdfType.
54
- if (!this.abstract.orDefault(false) &&
55
- this.isClass &&
56
- this.identifier.termType === "NamedNode") {
57
- return Maybe.of(this.identifier);
58
- }
59
- return Maybe.empty();
47
+ return this.generatedShaclmateNodeShape.fromRdfType;
60
48
  }
61
49
  get identifierMintingStrategy() {
62
50
  const thisMintingStrategy = this._mintingStrategy;
@@ -106,28 +94,26 @@ export class NodeShape extends ShaclCoreNodeShape {
106
94
  ? this.parentClassIris.flatMap((classIri) => this.shapesGraph.nodeShapeByIdentifier(classIri).toList())
107
95
  : [];
108
96
  }
97
+ get rdfType() {
98
+ // Check for an explicit shaclmate:rdfType
99
+ const rdfType = this.generatedShaclmateNodeShape.rdfType;
100
+ if (rdfType.isJust()) {
101
+ return rdfType;
102
+ }
103
+ // No explicit shaclmate:rdfType
104
+ // If the shape is a class, not abstract, and identified by an IRI then use the shape IRI as the fromRdfType.
105
+ if (!this.abstract.orDefault(false) &&
106
+ this.isClass &&
107
+ this.identifier.termType === "NamedNode") {
108
+ return Maybe.of(this.identifier);
109
+ }
110
+ return Maybe.empty();
111
+ }
109
112
  get shaclmateName() {
110
113
  return this.generatedShaclmateNodeShape.name;
111
114
  }
112
115
  get toRdfTypes() {
113
- // Look for one or more explicit shaclmate:toRdfType's
114
- const toRdfTypes = this.generatedShaclmateNodeShape.toRdfTypes.concat();
115
- // Ensure the toRdfTypes includes the fromRdfType if there is one
116
- this.fromRdfType.ifJust((fromRdfType) => {
117
- if (!toRdfTypes.some((toRdfType) => toRdfType.equals(fromRdfType))) {
118
- toRdfTypes.push(fromRdfType);
119
- }
120
- });
121
- if (toRdfTypes.length === 0) {
122
- // No explicit shaclmate:toRdfType's
123
- // If the shape is a class, not abstract, and identified by an IRI then use the shape IRI as the fromRdfType.
124
- if (!this.abstract.orDefault(false) &&
125
- this.isClass &&
126
- this.identifier.termType === "NamedNode") {
127
- toRdfTypes.push(this.identifier);
128
- }
129
- }
130
- return toRdfTypes;
116
+ return this.generatedShaclmateNodeShape.toRdfTypes;
131
117
  }
132
118
  get tsFeatures() {
133
119
  return tsFeatures(this.generatedShaclmateNodeShape).altLazy(() => this.isDefinedBy.chain((ontology) => ontology.tsFeatures));
@@ -149,16 +135,6 @@ export class NodeShape extends ShaclCoreNodeShape {
149
135
  })
150
136
  .altLazy(() => this.isDefinedBy.chain((ontology) => ontology.tsObjectDeclarationType));
151
137
  }
152
- get tsObjectIdentifierPrefixPropertyName() {
153
- return this.generatedShaclmateNodeShape.tsObjectIdentifierPrefixPropertyName.altLazy(() => this.isDefinedBy.chain((ontology) => ontology.tsObjectIdentifierPrefixPropertyName));
154
- }
155
- get tsObjectIdentifierPropertyName() {
156
- return this.generatedShaclmateNodeShape.tsObjectIdentifierPrefixPropertyName.altLazy(() => this.isDefinedBy.chain((ontology) => ontology.tsObjectIdentifierPropertyName));
157
- }
158
- get tsObjectTypeDiscriminatorPropertyName() {
159
- return this.generatedShaclmateNodeShape
160
- .tsObjectTypeDiscriminatorPropertyName;
161
- }
162
138
  get _mintingStrategy() {
163
139
  return this.generatedShaclmateNodeShape.identifierMintingStrategy.map((iri) => {
164
140
  switch (iri.value) {
@@ -5,11 +5,8 @@ import type * as generated from "./generated.js";
5
5
  export declare class Ontology extends OwlOntology {
6
6
  private readonly generatedShaclmateOntology;
7
7
  constructor(generatedShaclmateOntology: generated.ShaclmateOntology);
8
- get tsDataFactoryVariable(): Maybe<string>;
9
8
  get tsFeatures(): Maybe<Set<TsFeature>>;
10
9
  get tsImports(): readonly string[];
11
10
  get tsObjectDeclarationType(): Maybe<TsObjectDeclarationType>;
12
- get tsObjectIdentifierPrefixPropertyName(): Maybe<string>;
13
- get tsObjectIdentifierPropertyName(): Maybe<string>;
14
11
  }
15
12
  //# sourceMappingURL=Ontology.d.ts.map
@@ -6,9 +6,6 @@ export class Ontology extends OwlOntology {
6
6
  super(generatedShaclmateOntology);
7
7
  this.generatedShaclmateOntology = generatedShaclmateOntology;
8
8
  }
9
- get tsDataFactoryVariable() {
10
- return this.generatedShaclmateOntology.tsDataFactoryVariable;
11
- }
12
9
  get tsFeatures() {
13
10
  return tsFeatures(this.generatedShaclmateOntology);
14
11
  }
@@ -27,11 +24,5 @@ export class Ontology extends OwlOntology {
27
24
  }
28
25
  });
29
26
  }
30
- get tsObjectIdentifierPrefixPropertyName() {
31
- return this.generatedShaclmateOntology.tsObjectIdentifierPrefixPropertyName;
32
- }
33
- get tsObjectIdentifierPropertyName() {
34
- return this.generatedShaclmateOntology.tsObjectIdentifierPropertyName;
35
- }
36
27
  }
37
28
  //# sourceMappingURL=Ontology.js.map