@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.
Files changed (194) hide show
  1. package/dist/ShapesGraphToAstTransformer.d.ts +6 -5
  2. package/dist/ShapesGraphToAstTransformer.js +61 -17
  3. package/dist/_ShapesGraphToAstTransformer/InheritableShapeConstraints.d.ts +2 -0
  4. package/dist/_ShapesGraphToAstTransformer/InheritableShapeConstraints.js +2 -0
  5. package/dist/_ShapesGraphToAstTransformer/ShapeStack.d.ts +15 -0
  6. package/dist/_ShapesGraphToAstTransformer/ShapeStack.js +51 -0
  7. package/dist/_ShapesGraphToAstTransformer/flattenAstObjectCompositeTypeMemberTypes.d.ts +13 -0
  8. package/dist/_ShapesGraphToAstTransformer/flattenAstObjectCompositeTypeMemberTypes.js +51 -0
  9. package/dist/_ShapesGraphToAstTransformer/index.d.ts +5 -5
  10. package/dist/_ShapesGraphToAstTransformer/index.js +5 -5
  11. package/dist/_ShapesGraphToAstTransformer/shapeAstName.js +53 -12
  12. package/dist/_ShapesGraphToAstTransformer/transformNodeShapeToAstType.d.ts +5 -0
  13. package/dist/_ShapesGraphToAstTransformer/transformNodeShapeToAstType.js +130 -54
  14. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstObjectTypeProperty.js +175 -5
  15. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstCompositeType.d.ts +10 -0
  16. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstCompositeType.js +185 -0
  17. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstIdentifierType.d.ts +10 -0
  18. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstIdentifierType.js +32 -0
  19. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstLiteralType.d.ts +10 -0
  20. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstLiteralType.js +46 -0
  21. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstTermType.d.ts +12 -0
  22. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstTermType.js +24 -0
  23. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstType.d.ts +13 -0
  24. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstType.js +14 -0
  25. package/dist/ast/Ast.d.ts +0 -1
  26. package/dist/ast/Curie.d.ts +14 -0
  27. package/dist/ast/Curie.js +21 -0
  28. package/dist/ast/IdentifierType.d.ts +3 -2
  29. package/dist/ast/ListType.d.ts +2 -1
  30. package/dist/ast/LiteralType.d.ts +1 -1
  31. package/dist/ast/Name.d.ts +40 -5
  32. package/dist/ast/ObjectCompositeType.d.ts +11 -0
  33. package/dist/ast/ObjectType.d.ts +18 -13
  34. package/dist/ast/ObjectUnionType.d.ts +0 -11
  35. package/dist/ast/OptionType.d.ts +2 -4
  36. package/dist/ast/SetType.d.ts +2 -7
  37. package/dist/ast/TermType.d.ts +12 -4
  38. package/dist/ast/Type.d.ts +1 -1
  39. package/dist/ast/index.d.ts +1 -0
  40. package/dist/ast/index.js +1 -0
  41. package/dist/enums/TsFeature.d.ts +1 -4
  42. package/dist/enums/TsFeature.js +1 -15
  43. package/dist/generators/json/AstJsonGenerator.js +26 -4
  44. package/dist/generators/ts/BooleanType.d.ts +4 -2
  45. package/dist/generators/ts/BooleanType.js +12 -3
  46. package/dist/generators/ts/DateTimeType.d.ts +9 -8
  47. package/dist/generators/ts/DateTimeType.js +32 -8
  48. package/dist/generators/ts/DateType.d.ts +5 -2
  49. package/dist/generators/ts/DateType.js +15 -1
  50. package/dist/generators/ts/DeclaredType.d.ts +2 -2
  51. package/dist/generators/ts/DeclaredType.js +2 -2
  52. package/dist/generators/ts/FloatType.d.ts +6 -0
  53. package/dist/generators/ts/FloatType.js +18 -0
  54. package/dist/generators/ts/IdentifierType.d.ts +17 -7
  55. package/dist/generators/ts/IdentifierType.js +112 -18
  56. package/dist/generators/ts/Import.d.ts +2 -0
  57. package/dist/generators/ts/Import.js +10 -0
  58. package/dist/generators/ts/IntType.d.ts +6 -0
  59. package/dist/generators/ts/IntType.js +18 -0
  60. package/dist/generators/ts/ListType.d.ts +15 -12
  61. package/dist/generators/ts/ListType.js +113 -61
  62. package/dist/generators/ts/LiteralType.d.ts +17 -9
  63. package/dist/generators/ts/LiteralType.js +92 -17
  64. package/dist/generators/ts/NumberType.d.ts +3 -2
  65. package/dist/generators/ts/NumberType.js +8 -3
  66. package/dist/generators/ts/ObjectType.d.ts +65 -43
  67. package/dist/generators/ts/ObjectType.js +143 -123
  68. package/dist/generators/ts/ObjectUnionType.d.ts +50 -8
  69. package/dist/generators/ts/ObjectUnionType.js +303 -101
  70. package/dist/generators/ts/OptionType.d.ts +14 -10
  71. package/dist/generators/ts/OptionType.js +62 -34
  72. package/dist/generators/ts/PrimitiveType.d.ts +23 -5
  73. package/dist/generators/ts/PrimitiveType.js +34 -6
  74. package/dist/generators/ts/SetType.d.ts +17 -13
  75. package/dist/generators/ts/SetType.js +76 -44
  76. package/dist/generators/ts/SnippetDeclarations.d.ts +13 -8
  77. package/dist/generators/ts/SnippetDeclarations.js +226 -101
  78. package/dist/generators/ts/StringType.d.ts +4 -2
  79. package/dist/generators/ts/StringType.js +20 -8
  80. package/dist/generators/ts/TermType.d.ts +29 -33
  81. package/dist/generators/ts/TermType.js +89 -68
  82. package/dist/generators/ts/TsGenerator.d.ts +2 -1
  83. package/dist/generators/ts/TsGenerator.js +26 -12
  84. package/dist/generators/ts/Type.d.ts +100 -32
  85. package/dist/generators/ts/Type.js +58 -54
  86. package/dist/generators/ts/TypeFactory.d.ts +12 -5
  87. package/dist/generators/ts/TypeFactory.js +380 -226
  88. package/dist/generators/ts/UnionType.d.ts +14 -10
  89. package/dist/generators/ts/UnionType.js +319 -142
  90. package/dist/generators/ts/_ObjectType/EagerShaclProperty.d.ts +12 -0
  91. package/dist/generators/ts/_ObjectType/EagerShaclProperty.js +31 -0
  92. package/dist/generators/ts/_ObjectType/IdentifierPrefixProperty.d.ts +13 -12
  93. package/dist/generators/ts/_ObjectType/IdentifierPrefixProperty.js +59 -46
  94. package/dist/generators/ts/_ObjectType/IdentifierProperty.d.ts +20 -13
  95. package/dist/generators/ts/_ObjectType/IdentifierProperty.js +198 -140
  96. package/dist/generators/ts/_ObjectType/LazyShaclProperty.d.ts +100 -0
  97. package/dist/generators/ts/_ObjectType/LazyShaclProperty.js +315 -0
  98. package/dist/generators/ts/_ObjectType/Property.d.ts +47 -46
  99. package/dist/generators/ts/_ObjectType/Property.js +1 -10
  100. package/dist/generators/ts/_ObjectType/ShaclProperty.d.ts +25 -30
  101. package/dist/generators/ts/_ObjectType/ShaclProperty.js +120 -85
  102. package/dist/generators/ts/_ObjectType/TypeDiscriminatorProperty.d.ts +21 -17
  103. package/dist/generators/ts/_ObjectType/TypeDiscriminatorProperty.js +61 -53
  104. package/dist/generators/ts/_ObjectType/classDeclaration.js +22 -17
  105. package/dist/generators/ts/_ObjectType/createFunctionDeclaration.js +26 -13
  106. package/dist/generators/ts/_ObjectType/equalsFunctionOrMethodDeclaration.js +8 -5
  107. package/dist/generators/ts/_ObjectType/fromRdfTypeVariableStatement.d.ts +1 -1
  108. package/dist/generators/ts/_ObjectType/fromRdfTypeVariableStatement.js +8 -5
  109. package/dist/generators/ts/_ObjectType/graphqlTypeVariableStatement.d.ts +5 -0
  110. package/dist/generators/ts/_ObjectType/graphqlTypeVariableStatement.js +49 -0
  111. package/dist/generators/ts/_ObjectType/hashFunctionOrMethodDeclarations.js +7 -8
  112. package/dist/generators/ts/_ObjectType/identifierTypeDeclarations.d.ts +7 -0
  113. package/dist/generators/ts/_ObjectType/identifierTypeDeclarations.js +54 -0
  114. package/dist/generators/ts/_ObjectType/index.d.ts +9 -7
  115. package/dist/generators/ts/_ObjectType/index.js +9 -7
  116. package/dist/generators/ts/_ObjectType/interfaceDeclaration.js +1 -1
  117. package/dist/generators/ts/_ObjectType/jsonFunctionDeclarations.d.ts +4 -0
  118. package/dist/generators/ts/_ObjectType/jsonFunctionDeclarations.js +189 -0
  119. package/dist/generators/ts/_ObjectType/jsonTypeAliasDeclaration.d.ts +5 -0
  120. package/dist/generators/ts/_ObjectType/jsonTypeAliasDeclaration.js +28 -0
  121. package/dist/generators/ts/_ObjectType/objectSetMethodNames.d.ts +9 -0
  122. package/dist/generators/ts/_ObjectType/objectSetMethodNames.js +18 -0
  123. package/dist/generators/ts/_ObjectType/propertiesVariableStatement.d.ts +5 -0
  124. package/dist/generators/ts/_ObjectType/propertiesVariableStatement.js +37 -0
  125. package/dist/generators/ts/_ObjectType/rdfFunctionDeclarations.d.ts +4 -0
  126. package/dist/generators/ts/_ObjectType/rdfFunctionDeclarations.js +144 -0
  127. package/dist/generators/ts/_ObjectType/sparqlConstructQueryFunctionDeclaration.d.ts +1 -1
  128. package/dist/generators/ts/_ObjectType/sparqlConstructQueryFunctionDeclaration.js +6 -5
  129. package/dist/generators/ts/_ObjectType/sparqlConstructQueryStringFunctionDeclaration.d.ts +1 -1
  130. package/dist/generators/ts/_ObjectType/sparqlConstructQueryStringFunctionDeclaration.js +4 -3
  131. package/dist/generators/ts/_ObjectType/sparqlFunctionDeclarations.js +109 -37
  132. package/dist/generators/ts/_ObjectType/toJsonFunctionOrMethodDeclaration.js +6 -6
  133. package/dist/generators/ts/_ObjectType/toRdfFunctionOrMethodDeclaration.js +33 -24
  134. package/dist/generators/ts/graphqlSchemaVariableStatement.d.ts +9 -0
  135. package/dist/generators/ts/graphqlSchemaVariableStatement.js +86 -0
  136. package/dist/generators/ts/objectSetDeclarations.d.ts +8 -0
  137. package/dist/generators/ts/objectSetDeclarations.js +59 -0
  138. package/dist/generators/ts/objectSetInterfaceDeclaration.d.ts +8 -0
  139. package/dist/generators/ts/objectSetInterfaceDeclaration.js +46 -0
  140. package/dist/generators/ts/objectSetMethodSignatures.d.ts +11 -0
  141. package/dist/generators/ts/objectSetMethodSignatures.js +52 -0
  142. package/dist/generators/ts/rdfjsDatasetObjectSetClassDeclaration.d.ts +8 -0
  143. package/dist/generators/ts/rdfjsDatasetObjectSetClassDeclaration.js +393 -0
  144. package/dist/generators/ts/rdfjsTermExpression.d.ts +3 -0
  145. package/dist/generators/ts/rdfjsTermExpression.js +57 -0
  146. package/dist/generators/ts/sparqlObjectSetClassDeclaration.d.ts +8 -0
  147. package/dist/generators/ts/sparqlObjectSetClassDeclaration.js +415 -0
  148. package/dist/generators/ts/syntheticNamePrefix.d.ts +2 -0
  149. package/dist/generators/ts/syntheticNamePrefix.js +2 -0
  150. package/dist/generators/ts/tsName.js +27 -13
  151. package/dist/generators/ts/unsupportedObjectSetMethodDeclarations.d.ts +10 -0
  152. package/dist/generators/ts/unsupportedObjectSetMethodDeclarations.js +19 -0
  153. package/dist/input/NodeShape.d.ts +6 -8
  154. package/dist/input/NodeShape.js +20 -44
  155. package/dist/input/Ontology.d.ts +0 -3
  156. package/dist/input/Ontology.js +0 -9
  157. package/dist/input/PropertyPath.d.ts +5 -5
  158. package/dist/input/PropertyPath.js +14 -24
  159. package/dist/input/PropertyShape.d.ts +3 -1
  160. package/dist/input/PropertyShape.js +8 -2
  161. package/dist/input/ShapesGraph.js +4 -8
  162. package/dist/input/generated.d.ts +967 -107
  163. package/dist/input/generated.js +2548 -1046
  164. package/dist/input/tsFeatures.d.ts +3 -2
  165. package/dist/input/tsFeatures.js +44 -27
  166. package/package.json +18 -16
  167. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstCompositeType.d.ts +0 -13
  168. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstCompositeType.js +0 -200
  169. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstIdentifierType.d.ts +0 -12
  170. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstIdentifierType.js +0 -29
  171. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstLiteralType.d.ts +0 -12
  172. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstLiteralType.js +0 -43
  173. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstTermType.d.ts +0 -14
  174. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstTermType.js +0 -21
  175. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstType.d.ts +0 -16
  176. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstType.js +0 -60
  177. package/dist/generators/ts/_ObjectType/fromJsonFunctionDeclarations.d.ts +0 -4
  178. package/dist/generators/ts/_ObjectType/fromJsonFunctionDeclarations.js +0 -78
  179. package/dist/generators/ts/_ObjectType/fromRdfFunctionDeclarations.d.ts +0 -4
  180. package/dist/generators/ts/_ObjectType/fromRdfFunctionDeclarations.js +0 -91
  181. package/dist/generators/ts/_ObjectType/jsonSchemaFunctionDeclaration.d.ts +0 -5
  182. package/dist/generators/ts/_ObjectType/jsonSchemaFunctionDeclaration.js +0 -19
  183. package/dist/generators/ts/_ObjectType/jsonUiSchemaFunctionDeclaration.d.ts +0 -5
  184. package/dist/generators/ts/_ObjectType/jsonUiSchemaFunctionDeclaration.js +0 -31
  185. package/dist/generators/ts/_ObjectType/jsonZodSchemaFunctionDeclaration.d.ts +0 -5
  186. package/dist/generators/ts/_ObjectType/jsonZodSchemaFunctionDeclaration.js +0 -37
  187. package/dist/generators/ts/_ObjectType/rdfjsTermExpression.d.ts +0 -6
  188. package/dist/generators/ts/_ObjectType/rdfjsTermExpression.js +0 -17
  189. package/dist/generators/ts/_ObjectType/toJsonFunctionDeclaration.d.ts +0 -5
  190. package/dist/generators/ts/_ObjectType/toJsonFunctionDeclaration.js +0 -19
  191. package/dist/generators/ts/_ObjectType/toJsonReturnType.d.ts +0 -3
  192. package/dist/generators/ts/_ObjectType/toJsonReturnType.js +0 -17
  193. package/dist/generators/ts/_ObjectType/toRdfFunctionDeclaration.d.ts +0 -5
  194. package/dist/generators/ts/_ObjectType/toRdfFunctionDeclaration.js +0 -19
@@ -0,0 +1,3 @@
1
+ import type { BlankNode, Literal, NamedNode, Variable } from "@rdfjs/types";
2
+ export declare function rdfjsTermExpression(rdfjsTerm: Omit<BlankNode, "equals"> | Omit<Literal, "equals"> | Omit<NamedNode, "equals"> | Omit<Variable, "equals">): string;
3
+ //# sourceMappingURL=rdfjsTermExpression.d.ts.map
@@ -0,0 +1,57 @@
1
+ import { rdf, rdfs, xsd } from "@tpluscode/rdf-ns-builders";
2
+ import { logger } from "../../logger.js";
3
+ import { syntheticNamePrefix } from "./syntheticNamePrefix.js";
4
+ export function rdfjsTermExpression(rdfjsTerm) {
5
+ switch (rdfjsTerm.termType) {
6
+ case "BlankNode":
7
+ return `dataFactory.blankNode("${rdfjsTerm.value}")`;
8
+ case "Literal":
9
+ if (rdfjsTerm.datatype.equals(xsd.string)) {
10
+ if (rdfjsTerm.language.length === 0) {
11
+ return `dataFactory.literal("${rdfjsTerm.value}")`;
12
+ }
13
+ return `dataFactory.literal("${rdfjsTerm.value}", "${rdfjsTerm.language}")`;
14
+ }
15
+ return `dataFactory.literal("${rdfjsTerm.value}", ${rdfjsTermExpression(rdfjsTerm.datatype)})`;
16
+ case "NamedNode": {
17
+ if (rdfjsTerm.value.startsWith(rdf[""].value)) {
18
+ const unqualifiedName = rdfjsTerm.value.substring(rdf[""].value.length);
19
+ switch (unqualifiedName) {
20
+ case "first":
21
+ case "nil":
22
+ case "rest":
23
+ case "subject":
24
+ case "type":
25
+ return `${syntheticNamePrefix}RdfVocabularies.rdf.${unqualifiedName}`;
26
+ default:
27
+ logger.warn("unrecognized rdf IRI: %s", rdfjsTerm.value);
28
+ }
29
+ }
30
+ else if (rdfjsTerm.value.startsWith(rdfs[""].value)) {
31
+ const unqualifiedName = rdfjsTerm.value.substring(rdfs[""].value.length);
32
+ switch (unqualifiedName) {
33
+ case "subClassOf":
34
+ return `${syntheticNamePrefix}RdfVocabularies.rdfs.${unqualifiedName}`;
35
+ default:
36
+ logger.warn("unrecognized rdfs IRI: %s", rdfjsTerm.value);
37
+ }
38
+ }
39
+ else if (rdfjsTerm.value.startsWith(xsd[""].value)) {
40
+ const unqualifiedName = rdfjsTerm.value.substring(xsd[""].value.length);
41
+ switch (unqualifiedName) {
42
+ case "boolean":
43
+ case "date":
44
+ case "dateTime":
45
+ case "integer":
46
+ return `${syntheticNamePrefix}RdfVocabularies.xsd.${unqualifiedName}`;
47
+ default:
48
+ logger.warn("unrecognized xsd IRI: %s", rdfjsTerm.value);
49
+ }
50
+ }
51
+ return `dataFactory.namedNode("${rdfjsTerm.value}")`;
52
+ }
53
+ case "Variable":
54
+ return `dataFactory.variable!("${rdfjsTerm.value}")`;
55
+ }
56
+ }
57
+ //# sourceMappingURL=rdfjsTermExpression.js.map
@@ -0,0 +1,8 @@
1
+ import { type ClassDeclarationStructure, type ModuleDeclarationStructure } from "ts-morph";
2
+ import type { ObjectType } from "./ObjectType.js";
3
+ import type { ObjectUnionType } from "./ObjectUnionType.js";
4
+ export declare function sparqlObjectSetClassDeclaration({ objectTypes, objectUnionTypes, }: {
5
+ objectTypes: readonly ObjectType[];
6
+ objectUnionTypes: readonly ObjectUnionType[];
7
+ }): readonly (ClassDeclarationStructure | ModuleDeclarationStructure)[];
8
+ //# sourceMappingURL=sparqlObjectSetClassDeclaration.d.ts.map
@@ -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: (resource: rdfjsResource.Resource, options: { objectSet: ${syntheticNamePrefix}ObjectSet }) => 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 = datasetFactory.dataset(quads.concat());
252
+ const objects: ${typeParameters.ObjectT.name}[] = [];
253
+ for (const identifier of identifiers) {
254
+ const objectEither = objectType.${syntheticNamePrefix}fromRdf(
255
+ new rdfjsResource.Resource<rdfjs.NamedNode>({ dataset, identifier: identifier as rdfjs.NamedNode }),
256
+ { objectSet: this }
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