@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
@@ -1,10 +1,11 @@
1
1
  import type * as rdfjs from "@rdfjs/types";
2
2
  import { Maybe } from "purify-ts";
3
- import { TsFeature } from "../enums/index.js";
4
- type TsFeatureIri = rdfjs.NamedNode<"http://purl.org/shaclmate/ontology#_TsFeature_All" | "http://purl.org/shaclmate/ontology#_TsFeature_Create" | "http://purl.org/shaclmate/ontology#_TsFeature_Equals" | "http://purl.org/shaclmate/ontology#_TsFeature_FromJson" | "http://purl.org/shaclmate/ontology#_TsFeature_FromRdf" | "http://purl.org/shaclmate/ontology#_TsFeature_Json" | "http://purl.org/shaclmate/ontology#_TsFeature_JsonSchema" | "http://purl.org/shaclmate/ontology#_TsFeature_JsonUiSchema" | "http://purl.org/shaclmate/ontology#_TsFeature_Hash" | "http://purl.org/shaclmate/ontology#_TsFeature_None" | "http://purl.org/shaclmate/ontology#_TsFeature_Rdf" | "http://purl.org/shaclmate/ontology#_TsFeature_Sparql" | "http://purl.org/shaclmate/ontology#_TsFeature_ToJson" | "http://purl.org/shaclmate/ontology#_TsFeature_ToRdf">;
3
+ import type { TsFeature } from "../enums/index.js";
4
+ type TsFeatureIri = rdfjs.NamedNode<"http://purl.org/shaclmate/ontology#_TsFeatures_All" | "http://purl.org/shaclmate/ontology#_TsFeature_Create" | "http://purl.org/shaclmate/ontology#_TsFeatures_Default" | "http://purl.org/shaclmate/ontology#_TsFeature_Equals" | "http://purl.org/shaclmate/ontology#_TsFeature_Graphql" | "http://purl.org/shaclmate/ontology#_TsFeature_Json" | "http://purl.org/shaclmate/ontology#_TsFeature_Hash" | "http://purl.org/shaclmate/ontology#_TsFeatures_None" | "http://purl.org/shaclmate/ontology#_TsFeature_Rdf" | "http://purl.org/shaclmate/ontology#_TsFeature_Sparql">;
5
5
  export declare function tsFeatures(generated: {
6
6
  readonly tsFeatureExcludes: readonly TsFeatureIri[];
7
7
  readonly tsFeatureIncludes: readonly TsFeatureIri[];
8
8
  }): Maybe<Set<TsFeature>>;
9
+ export declare const tsFeaturesDefault: readonly TsFeature[];
9
10
  export {};
10
11
  //# sourceMappingURL=tsFeatures.d.ts.map
@@ -1,50 +1,67 @@
1
1
  import { Maybe } from "purify-ts";
2
- import { TsFeature } from "../enums/index.js";
3
2
  function iriToTsFeatures(iri) {
4
3
  switch (iri.value) {
5
- case "http://purl.org/shaclmate/ontology#_TsFeature_All":
6
- return TsFeature.MEMBERS;
4
+ case "http://purl.org/shaclmate/ontology#_TsFeatures_All":
5
+ return tsFeaturesAll;
7
6
  case "http://purl.org/shaclmate/ontology#_TsFeature_Create":
8
7
  return ["create"];
8
+ case "http://purl.org/shaclmate/ontology#_TsFeatures_Default":
9
+ return tsFeaturesDefault;
9
10
  case "http://purl.org/shaclmate/ontology#_TsFeature_Equals":
10
11
  return ["equals"];
11
- case "http://purl.org/shaclmate/ontology#_TsFeature_FromJson":
12
- return ["fromJson"];
13
- case "http://purl.org/shaclmate/ontology#_TsFeature_FromRdf":
14
- return ["fromRdf"];
12
+ case "http://purl.org/shaclmate/ontology#_TsFeature_Graphql":
13
+ return ["graphql"];
14
+ case "http://purl.org/shaclmate/ontology#_TsFeature_Json":
15
+ return ["json"];
16
+ case "http://purl.org/shaclmate/ontology#_TsFeature_Rdf":
17
+ return ["rdf"];
15
18
  case "http://purl.org/shaclmate/ontology#_TsFeature_Hash":
16
19
  return ["hash"];
17
- case "http://purl.org/shaclmate/ontology#_TsFeature_Json":
18
- return ["fromJson", "jsonSchema", "jsonUiSchema", "toJson"];
19
- case "http://purl.org/shaclmate/ontology#_TsFeature_JsonSchema":
20
- return ["jsonSchema"];
21
- case "http://purl.org/shaclmate/ontology#_TsFeature_JsonUiSchema":
22
- return ["jsonUiSchema"];
23
- case "http://purl.org/shaclmate/ontology#_TsFeature_None":
20
+ case "http://purl.org/shaclmate/ontology#_TsFeatures_None":
24
21
  return [];
25
22
  case "http://purl.org/shaclmate/ontology#_TsFeature_Sparql":
26
23
  return ["sparql"];
27
- case "http://purl.org/shaclmate/ontology#_TsFeature_Rdf":
28
- return ["fromRdf", "toRdf"];
29
- case "http://purl.org/shaclmate/ontology#_TsFeature_ToJson":
30
- return ["toJson"];
31
- case "http://purl.org/shaclmate/ontology#_TsFeature_ToRdf":
32
- return ["toRdf"];
33
24
  }
34
25
  }
35
26
  export function tsFeatures(generated) {
36
27
  const tsFeatureIncludes = generated.tsFeatureIncludes.flatMap(iriToTsFeatures);
37
28
  const tsFeatureExcludes = generated.tsFeatureExcludes.flatMap(iriToTsFeatures);
29
+ if (tsFeatureExcludes.length === 0 && tsFeatureIncludes.length === 0) {
30
+ return Maybe.empty();
31
+ }
32
+ const tsFeatures = new Set();
38
33
  if (tsFeatureIncludes.length > 0) {
39
- return Maybe.of(new Set(tsFeatureIncludes));
34
+ for (const tsFeatureInclude of tsFeatureIncludes) {
35
+ tsFeatures.add(tsFeatureInclude);
36
+ }
40
37
  }
41
- if (tsFeatureExcludes.length > 0) {
42
- const tsFeatures = new Set(TsFeature.MEMBERS);
43
- for (const tsFeatureExclude of tsFeatureExcludes) {
44
- tsFeatures.delete(tsFeatureExclude);
38
+ else {
39
+ for (const tsFeature of tsFeaturesDefault) {
40
+ tsFeatures.add(tsFeature);
45
41
  }
46
- return Maybe.of(tsFeatures);
47
42
  }
48
- return Maybe.empty();
43
+ for (const tsFeatureExclude of tsFeatureExcludes) {
44
+ tsFeatures.delete(tsFeatureExclude);
45
+ }
46
+ if (tsFeatures.has("graphql")) {
47
+ tsFeatures.add("rdf");
48
+ }
49
+ return Maybe.of(tsFeatures);
49
50
  }
51
+ const tsFeaturesAll = [
52
+ "create",
53
+ "equals",
54
+ "graphql",
55
+ "hash",
56
+ "json",
57
+ "rdf",
58
+ "sparql",
59
+ ];
60
+ export const tsFeaturesDefault = [
61
+ "create",
62
+ "equals",
63
+ "hash",
64
+ "json",
65
+ "rdf",
66
+ ];
50
67
  //# sourceMappingURL=tsFeatures.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "dependencies": {
3
- "@shaclmate/shacl-ast": "2.0.22",
3
+ "@shaclmate/shacl-ast": "2.0.24",
4
4
  "@rdfjs/prefix-map": "^0.1.2",
5
5
  "@rdfjs/term-map": "^2.0.2",
6
6
  "@rdfjs/term-set": "^2.0.3",
@@ -13,15 +13,22 @@
13
13
  "@types/toposort": "2.0.7",
14
14
  "change-case": "^5.4.4",
15
15
  "pino": "^9.1.0",
16
+ "plur": "^5.1.0",
17
+ "purify-ts": "^2.1.0",
16
18
  "reserved-identifiers": "^1.0.0",
17
19
  "toposort": "2.0.2",
18
20
  "ts-invariant": "^0.10.3",
19
- "ts-morph": "^24.0.0",
21
+ "ts-morph": "^26.0.0",
20
22
  "typescript-memoize": "^1.1.1"
21
23
  },
22
24
  "devDependencies": {
23
- "@shaclmate/runtime": "2.0.22",
24
- "oxigraph": "^0.4.0"
25
+ "@shaclmate/kitchen-sink-example": "2.0.24",
26
+ "@shaclmate/runtime": "2.0.24",
27
+ "@kos-kit/sparql-client": "2.0.115",
28
+ "@types/n3": "^1.21.1",
29
+ "oxigraph": "0.4.11",
30
+ "n3": "^1.21.3",
31
+ "rdfjs-resource": "1.0.22"
25
32
  },
26
33
  "exports": {
27
34
  ".": {
@@ -51,31 +58,26 @@
51
58
  ],
52
59
  "license": "Apache-2.0",
53
60
  "name": "@shaclmate/compiler",
61
+ "packageManager": "npm@10.9.0",
54
62
  "repository": {
55
63
  "type": "git",
56
64
  "url": "git+https://github.com/minorg/shaclmate"
57
65
  },
58
66
  "scripts": {
59
67
  "build": "tsc -b",
68
+ "build:noEmit": "tsc --noEmit",
60
69
  "check": "biome check",
61
70
  "check:write": "biome check --write",
62
71
  "check:write:unsafe": "biome check --write --unsafe",
63
72
  "clean": "rimraf dist",
64
- "format": "biome format",
65
- "format:write": "biome format --write",
66
- "format:write:unsafe": "biome format --write --unsafe",
67
- "rebuild": "run-s clean build",
73
+ "dev": "tsc -w --preserveWatchOutput",
74
+ "dev:noEmit": "tsc --noEmit -w --preserveWatchOutput",
68
75
  "link-dependencies": "npm link rdfjs-resource",
69
- "lint": "biome lint",
70
- "lint:write": "biome lint --write",
71
- "lint:write:unsafe": "biome lint --write --unsafe",
72
76
  "test": "biome check && vitest run",
73
77
  "test:coverage": "biome check && vitest run --coverage",
74
- "test:watch": "vitest watch",
75
- "unlink": "npm unlink -g @shaclmate/compiler",
76
- "watch": "tsc -w --preserveWatchOutput",
77
- "watch:noEmit": "tsc --noEmit -w --preserveWatchOutput"
78
+ "test:watch": "biome check && vitest watch",
79
+ "unlink": "npm unlink -g @shaclmate/compiler"
78
80
  },
79
81
  "type": "module",
80
- "version": "2.0.22"
82
+ "version": "2.0.24"
81
83
  }
@@ -1,13 +0,0 @@
1
- import type { BlankNode, Literal, NamedNode } from "@rdfjs/types";
2
- import { Either, Maybe } from "purify-ts";
3
- import type { ShapesGraphToAstTransformer } from "../ShapesGraphToAstTransformer.js";
4
- import type * as ast from "../ast/index.js";
5
- import * as input from "../input/index.js";
6
- /**
7
- * Try to convert a property shape to a composite type (intersection or union) using some heuristics.
8
- */
9
- export declare function transformPropertyShapeToAstCompositeType(this: ShapesGraphToAstTransformer, shape: input.Shape, inherited: {
10
- defaultValue: Maybe<BlankNode | Literal | NamedNode>;
11
- extern: Maybe<boolean>;
12
- } | null): Either<Error, ast.Type>;
13
- //# sourceMappingURL=transformPropertyShapeToAstCompositeType.d.ts.map
@@ -1,200 +0,0 @@
1
- import { owl, rdfs } from "@tpluscode/rdf-ns-builders";
2
- import { Either, Left, Maybe } from "purify-ts";
3
- import { invariant } from "ts-invariant";
4
- import * as input from "../input/index.js";
5
- import { logger } from "../logger.js";
6
- /**
7
- * Try to convert a property shape to a composite type (intersection or union) using some heuristics.
8
- */
9
- export function transformPropertyShapeToAstCompositeType(shape, inherited) {
10
- const defaultValue = (shape instanceof input.PropertyShape ? shape.defaultValue : Maybe.empty()).alt(inherited !== null ? inherited.defaultValue : Maybe.empty());
11
- const hasValues = shape.constraints.hasValues;
12
- const extern = shape.extern.alt(inherited !== null ? inherited.extern : Maybe.empty());
13
- let memberTypeEithers;
14
- let compositeTypeKind;
15
- const transformNodeShapeToAstCompositeMemberType = (nodeShape) => {
16
- const astTypeEither = this.transformNodeShapeToAstType(nodeShape);
17
- if (astTypeEither.isLeft()) {
18
- return astTypeEither;
19
- }
20
- const astType = astTypeEither.unsafeCoerce();
21
- if (extern.orDefault(false)) {
22
- // Use the identifier type instead
23
- let nodeKinds;
24
- switch (astType.kind) {
25
- case "ListType":
26
- nodeKinds = new Set();
27
- nodeKinds.add(astType.identifierNodeKind);
28
- break;
29
- case "ObjectType":
30
- nodeKinds = astType.identifierKinds;
31
- break;
32
- case "ObjectIntersectionType":
33
- case "ObjectUnionType":
34
- nodeKinds = new Set();
35
- for (const memberType of astType.memberTypes) {
36
- for (const nodeKind of memberType.identifierKinds) {
37
- nodeKinds.add(nodeKind);
38
- }
39
- }
40
- }
41
- return Either.of({
42
- defaultValue: defaultValue.filter((term) => term.termType === "NamedNode"),
43
- hasValues: [],
44
- in_: [],
45
- kind: "IdentifierType",
46
- nodeKinds,
47
- });
48
- }
49
- // Not extern, use the type
50
- return Either.of(astType);
51
- };
52
- if (shape.constraints.and.length > 0) {
53
- memberTypeEithers = shape.constraints.and.map((memberShape) => this.transformPropertyShapeToAstType(memberShape, {
54
- defaultValue,
55
- extern: extern,
56
- }));
57
- compositeTypeKind = "IntersectionType";
58
- }
59
- else if (shape.constraints.classes.length > 0) {
60
- memberTypeEithers = shape.constraints.classes.map((classIri) => {
61
- if (classIri.equals(owl.Class) ||
62
- classIri.equals(owl.Thing) ||
63
- classIri.equals(rdfs.Class)) {
64
- return Left(new Error(`class ${classIri.value} is not transformable`));
65
- }
66
- const classNodeShape = this.shapesGraph
67
- .nodeShapeByIdentifier(classIri)
68
- .extractNullable();
69
- if (classNodeShape === null) {
70
- return Left(new Error(`class ${classIri.value} did not resolve to a node shape`));
71
- }
72
- return transformNodeShapeToAstCompositeMemberType(classNodeShape);
73
- });
74
- compositeTypeKind = "IntersectionType";
75
- if (Either.rights(memberTypeEithers).length === 0) {
76
- // This frequently happens with e.g., sh:class skos:Concept
77
- logger.debug("shape %s sh:class(es) did not map to any node shapes", shape);
78
- return memberTypeEithers[0];
79
- }
80
- }
81
- else if (shape.constraints.nodes.length > 0) {
82
- memberTypeEithers = shape.constraints.nodes.map((nodeShape) => transformNodeShapeToAstCompositeMemberType(nodeShape));
83
- compositeTypeKind = "IntersectionType";
84
- }
85
- else if (shape.constraints.xone.length > 0) {
86
- memberTypeEithers = shape.constraints.xone.map((memberShape) => this.transformPropertyShapeToAstType(memberShape, {
87
- defaultValue,
88
- extern: extern,
89
- }));
90
- compositeTypeKind = "UnionType";
91
- }
92
- else {
93
- return Left(new Error(`unable to transform ${shape} into an AST type`));
94
- }
95
- invariant(memberTypeEithers.length > 0);
96
- const memberTypes = Either.rights(memberTypeEithers);
97
- if (memberTypes.length !== memberTypeEithers.length) {
98
- logger.warn("shape %s composition did not map all member types successfully: %s", shape, Either.lefts(memberTypeEithers)
99
- .map((left) => left.message)
100
- .join("; "));
101
- return memberTypeEithers[0];
102
- }
103
- invariant(memberTypes.length > 0);
104
- if (memberTypes.length === 1) {
105
- return Either.of(memberTypes[0]);
106
- }
107
- // Get the type underlying a set or option
108
- const memberItemTypes = memberTypes.map((memberType) => {
109
- switch (memberType.kind) {
110
- case "SetType":
111
- return memberType.itemType;
112
- case "OptionType":
113
- return memberType.itemType;
114
- default:
115
- return memberType;
116
- }
117
- });
118
- if (hasValues.length === 0) {
119
- // Can't handle hasValues when coalescing types
120
- const canCoalesce = (memberItemType) => {
121
- if (memberItemType.in_.length > 0) {
122
- return false;
123
- }
124
- switch (memberItemType.kind) {
125
- case "LiteralType": {
126
- if (memberItemType.maxExclusive.isJust()) {
127
- return false;
128
- }
129
- if (memberItemType.maxInclusive.isJust()) {
130
- return false;
131
- }
132
- if (memberItemType.minExclusive.isJust()) {
133
- return false;
134
- }
135
- if (memberItemType.minInclusive.isJust()) {
136
- return false;
137
- }
138
- }
139
- }
140
- return true;
141
- };
142
- if (memberItemTypes.every((memberItemType) => memberItemType.kind === "IdentifierType" &&
143
- canCoalesce(memberItemType))) {
144
- // Special case: all member types are identifiers without further constraints
145
- return Either.of({
146
- defaultValue: defaultValue.filter((term) => term.termType === "NamedNode"),
147
- hasValues: [],
148
- in_: [],
149
- kind: "IdentifierType",
150
- nodeKinds: new Set(memberItemTypes
151
- .filter((memberItemType) => memberItemType.kind === "IdentifierType")
152
- .flatMap((memberItemType) => [
153
- ...memberItemType.nodeKinds,
154
- ])),
155
- });
156
- }
157
- if (memberItemTypes.every((memberItemType) => memberItemType.kind === "LiteralType" && canCoalesce(memberItemType))) {
158
- // Special case: all the member types are Literals without further constraints,
159
- // like dash:StringOrLangString
160
- // Don't try to coalesce range constraints.
161
- return Either.of({
162
- datatype: Maybe.empty(),
163
- defaultValue: defaultValue.filter((term) => term.termType === "Literal"),
164
- hasValues: [],
165
- in_: [],
166
- kind: "LiteralType",
167
- languageIn: [],
168
- maxExclusive: Maybe.empty(),
169
- maxInclusive: Maybe.empty(),
170
- minExclusive: Maybe.empty(),
171
- minInclusive: Maybe.empty(),
172
- nodeKinds: new Set(["Literal"]),
173
- });
174
- }
175
- if (memberItemTypes.every((memberItemType) => (memberItemType.kind === "IdentifierType" ||
176
- memberItemType.kind === "LiteralType" ||
177
- memberItemType.kind === "TermType") &&
178
- canCoalesce(memberItemType))) {
179
- // Special case: all member types are terms without further constraints
180
- const nodeKinds = new Set(memberItemTypes.flatMap((memberItemType) => [
181
- ...memberItemType
182
- .nodeKinds,
183
- ]));
184
- invariant(nodeKinds.has("Literal") &&
185
- (nodeKinds.has("BlankNode") || nodeKinds.has("NamedNode"))); // The identifier-identifier and literal-literal cases should have been caught above
186
- return Either.of({
187
- defaultValue,
188
- hasValues: [],
189
- in_: [],
190
- kind: "TermType",
191
- nodeKinds,
192
- });
193
- }
194
- }
195
- return Either.of({
196
- kind: compositeTypeKind,
197
- memberTypes: memberTypes,
198
- });
199
- }
200
- //# sourceMappingURL=transformPropertyShapeToAstCompositeType.js.map
@@ -1,12 +0,0 @@
1
- import type { BlankNode, Literal, NamedNode } from "@rdfjs/types";
2
- import { Either, Maybe } from "purify-ts";
3
- import type { ShapesGraphToAstTransformer } from "../ShapesGraphToAstTransformer.js";
4
- import type * as ast from "../ast/index.js";
5
- import * as input from "../input/index.js";
6
- /**
7
- * Try to convert a property shape to an AST IdentifierType using some heuristics.
8
- */
9
- export declare function transformPropertyShapeToAstIdentifierType(this: ShapesGraphToAstTransformer, shape: input.Shape, inherited: {
10
- defaultValue: Maybe<BlankNode | Literal | NamedNode>;
11
- } | null): Either<Error, ast.IdentifierType>;
12
- //# sourceMappingURL=transformPropertyShapeToAstIdentifierType.d.ts.map
@@ -1,29 +0,0 @@
1
- import { Either, Left, Maybe } from "purify-ts";
2
- import * as input from "../input/index.js";
3
- import { propertyShapeNodeKinds } from "./propertyShapeNodeKinds.js";
4
- /**
5
- * Try to convert a property shape to an AST IdentifierType using some heuristics.
6
- */
7
- export function transformPropertyShapeToAstIdentifierType(shape, inherited) {
8
- // defaultValue / hasValue / in only makes sense with IRIs
9
- const identifierDefaultValue = (shape instanceof input.PropertyShape ? shape.defaultValue : Maybe.empty())
10
- .alt(inherited !== null ? inherited.defaultValue : Maybe.empty())
11
- .filter((value) => value.termType === "NamedNode");
12
- const identifierHasValues = shape.constraints.hasValues.filter((term) => term.termType === "NamedNode");
13
- const identifierIn = shape.constraints.in_.filter((term) => term.termType === "NamedNode");
14
- const nodeKinds = propertyShapeNodeKinds(shape);
15
- if (identifierHasValues.length > 0 ||
16
- identifierDefaultValue.isJust() ||
17
- identifierIn.length > 0 ||
18
- (nodeKinds.size > 0 && nodeKinds.size <= 2 && !nodeKinds.has("Literal"))) {
19
- return Either.of({
20
- defaultValue: identifierDefaultValue,
21
- hasValues: identifierHasValues,
22
- in_: identifierIn,
23
- kind: "IdentifierType",
24
- nodeKinds: nodeKinds,
25
- });
26
- }
27
- return Left(new Error(`unable to transform ${shape} into an AST type`));
28
- }
29
- //# sourceMappingURL=transformPropertyShapeToAstIdentifierType.js.map
@@ -1,12 +0,0 @@
1
- import type { BlankNode, Literal, NamedNode } from "@rdfjs/types";
2
- import { Either, Maybe } from "purify-ts";
3
- import type { ShapesGraphToAstTransformer } from "../ShapesGraphToAstTransformer.js";
4
- import type * as ast from "../ast/index.js";
5
- import * as input from "../input/index.js";
6
- /**
7
- * Try to convert a property shape to an AST LiteralType using some heuristics.
8
- */
9
- export declare function transformPropertyShapeToAstLiteralType(this: ShapesGraphToAstTransformer, shape: input.Shape, inherited: {
10
- defaultValue: Maybe<BlankNode | Literal | NamedNode>;
11
- } | null): Either<Error, ast.LiteralType>;
12
- //# sourceMappingURL=transformPropertyShapeToAstLiteralType.d.ts.map
@@ -1,43 +0,0 @@
1
- import { Either, Left, Maybe } from "purify-ts";
2
- import * as input from "../input/index.js";
3
- import { propertyShapeNodeKinds } from "./propertyShapeNodeKinds.js";
4
- /**
5
- * Try to convert a property shape to an AST LiteralType using some heuristics.
6
- */
7
- export function transformPropertyShapeToAstLiteralType(shape, inherited) {
8
- const literalDefaultValue = (shape instanceof input.PropertyShape ? shape.defaultValue : Maybe.empty())
9
- .alt(inherited !== null ? inherited.defaultValue : Maybe.empty())
10
- .filter((term) => term.termType === "Literal");
11
- const literalHasValues = shape.constraints.hasValues.filter((term) => term.termType === "Literal");
12
- const literalIn = shape.constraints.in_.filter((term) => term.termType === "Literal");
13
- const nodeKinds = propertyShapeNodeKinds(shape);
14
- if ([
15
- // Treat any shape with the constraints in the list as a literal type
16
- shape.constraints.datatype,
17
- shape.constraints.maxExclusive,
18
- shape.constraints.maxInclusive,
19
- shape.constraints.minExclusive,
20
- shape.constraints.minInclusive,
21
- ].some((constraint) => constraint.isJust()) ||
22
- shape.constraints.languageIn.length > 0 ||
23
- literalDefaultValue.isJust() ||
24
- literalHasValues.length > 0 ||
25
- literalIn.length > 0 ||
26
- // Treat any shape with a single sh:nodeKind of sh:Literal as a literal type
27
- (nodeKinds.size === 1 && nodeKinds.has("Literal")))
28
- return Either.of({
29
- datatype: shape.constraints.datatype,
30
- defaultValue: literalDefaultValue,
31
- hasValues: literalHasValues,
32
- in_: literalIn,
33
- kind: "LiteralType",
34
- languageIn: shape.constraints.languageIn,
35
- maxExclusive: shape.constraints.maxExclusive,
36
- maxInclusive: shape.constraints.maxInclusive,
37
- minExclusive: shape.constraints.minExclusive,
38
- minInclusive: shape.constraints.minInclusive,
39
- nodeKinds: new Set(["Literal"]),
40
- });
41
- return Left(new Error(`unable to transform ${shape} into an AST type`));
42
- }
43
- //# sourceMappingURL=transformPropertyShapeToAstLiteralType.js.map
@@ -1,14 +0,0 @@
1
- import type { BlankNode, Literal, NamedNode } from "@rdfjs/types";
2
- import { Either, Maybe } from "purify-ts";
3
- import type { ShapesGraphToAstTransformer } from "../ShapesGraphToAstTransformer.js";
4
- import type * as ast from "../ast/index.js";
5
- import * as input from "../input/index.js";
6
- /**
7
- * Try to convert a property shape to an AST TermType using some heuristics.
8
- */
9
- export declare function transformPropertyShapeToAstTermType(this: ShapesGraphToAstTransformer, shape: input.Shape, inherited: {
10
- defaultValue: Maybe<BlankNode | Literal | NamedNode>;
11
- } | null): Either<Error, Omit<ast.TermType<BlankNode | Literal | NamedNode>, "kind"> & {
12
- readonly kind: "TermType";
13
- }>;
14
- //# sourceMappingURL=transformPropertyShapeToAstTermType.d.ts.map
@@ -1,21 +0,0 @@
1
- import { Either, Maybe } from "purify-ts";
2
- import * as input from "../input/index.js";
3
- import { propertyShapeNodeKinds } from "./propertyShapeNodeKinds.js";
4
- /**
5
- * Try to convert a property shape to an AST TermType using some heuristics.
6
- */
7
- export function transformPropertyShapeToAstTermType(shape, inherited) {
8
- const nodeKinds = propertyShapeNodeKinds(shape);
9
- return Either.of({
10
- defaultValue: (shape instanceof input.PropertyShape
11
- ? shape.defaultValue
12
- : Maybe.empty()).alt(inherited !== null ? inherited.defaultValue : Maybe.empty()),
13
- hasValues: shape.constraints.hasValues,
14
- in_: shape.constraints.in_,
15
- kind: "TermType",
16
- nodeKinds: nodeKinds.size > 0
17
- ? nodeKinds
18
- : new Set(["BlankNode", "NamedNode", "Literal"]),
19
- });
20
- }
21
- //# sourceMappingURL=transformPropertyShapeToAstTermType.js.map
@@ -1,16 +0,0 @@
1
- import type { BlankNode, Literal, NamedNode } from "@rdfjs/types";
2
- import type { Either, Maybe } from "purify-ts";
3
- import type { ShapesGraphToAstTransformer } from "../ShapesGraphToAstTransformer.js";
4
- import type * as ast from "../ast/index.js";
5
- import * as input from "../input/index.js";
6
- /**
7
- * Try to convert a property shape to a type using some heuristics.
8
- *
9
- * We don't try to handle exotic cases allowed by the SHACL spec, such as combinations of sh:in and sh:node. Instead we assume
10
- * a shape has one type.
11
- */
12
- export declare function transformPropertyShapeToAstType(this: ShapesGraphToAstTransformer, shape: input.Shape, inherited: {
13
- defaultValue: Maybe<BlankNode | Literal | NamedNode>;
14
- extern: Maybe<boolean>;
15
- } | null): Either<Error, ast.Type>;
16
- //# sourceMappingURL=transformPropertyShapeToAstType.d.ts.map
@@ -1,60 +0,0 @@
1
- import { invariant } from "ts-invariant";
2
- import * as input from "../input/index.js";
3
- /**
4
- * Try to convert a property shape to a type using some heuristics.
5
- *
6
- * We don't try to handle exotic cases allowed by the SHACL spec, such as combinations of sh:in and sh:node. Instead we assume
7
- * a shape has one type.
8
- */
9
- export function transformPropertyShapeToAstType(shape, inherited) {
10
- // Try to transform the property shape into an AST type without cardinality constraints
11
- return this.transformPropertyShapeToAstCompositeType(shape, inherited)
12
- .altLazy(() => this.transformPropertyShapeToAstIdentifierType(shape, inherited))
13
- .altLazy(() => this.transformPropertyShapeToAstLiteralType(shape, inherited))
14
- .altLazy(() => this.transformPropertyShapeToAstTermType(shape, inherited))
15
- .map((itemType) => {
16
- // Handle cardinality constraints
17
- if ((shape instanceof input.PropertyShape && shape.defaultValue.isJust()) ||
18
- inherited?.defaultValue.isJust()) {
19
- // Ignore other cardinality constraints if there's a default value and treat the type as minCount=maxCount=1
20
- return itemType;
21
- }
22
- const maxCount = shape.constraints.maxCount;
23
- const minCount = shape.constraints.minCount;
24
- if (maxCount.isNothing() && minCount.isNothing()) {
25
- // The shape has no cardinality constraints
26
- if (inherited === null) {
27
- // The shape is top-level (not an sh:xone/sh:and of a top-level shape)
28
- // Treat it as a Set, the default in RDF.
29
- // We want Set to be the outermost type unless it's explicitly requested with sh:minCount 0.
30
- return {
31
- itemType,
32
- kind: "SetType",
33
- mutable: shape.mutable,
34
- minCount: 0,
35
- };
36
- }
37
- // else the shape is not top-level
38
- // We want Set to be the outermost type, so just return the itemType here
39
- return itemType;
40
- }
41
- if (minCount.orDefault(0) === 0 && maxCount.extractNullable() === 1) {
42
- return {
43
- itemType,
44
- kind: "OptionType",
45
- };
46
- }
47
- if (minCount.orDefault(0) === 1 && maxCount.extractNullable() === 1) {
48
- return itemType;
49
- }
50
- invariant(minCount.isJust() || maxCount.isJust());
51
- // There are cardinality constraints for a Set. It may be an inner type.
52
- return {
53
- itemType,
54
- kind: "SetType",
55
- minCount: minCount.orDefault(0),
56
- mutable: shape.mutable,
57
- };
58
- });
59
- }
60
- //# sourceMappingURL=transformPropertyShapeToAstType.js.map
@@ -1,4 +0,0 @@
1
- import { type FunctionDeclarationStructure } from "ts-morph";
2
- import type { ObjectType } from "../ObjectType.js";
3
- export declare function fromJsonFunctionDeclarations(this: ObjectType): readonly FunctionDeclarationStructure[];
4
- //# sourceMappingURL=fromJsonFunctionDeclarations.d.ts.map