@shaclmate/compiler 4.0.7 → 4.0.9

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 (306) hide show
  1. package/dist/Compiler.d.ts +1 -4
  2. package/dist/Compiler.js +1 -5
  3. package/dist/ShapesGraphToAstTransformer.d.ts +2 -11
  4. package/dist/ShapesGraphToAstTransformer.js +25 -27
  5. package/dist/_ShapesGraphToAstTransformer/defaultNodeShapeNodeKinds.d.ts +3 -0
  6. package/dist/_ShapesGraphToAstTransformer/defaultNodeShapeNodeKinds.js +5 -0
  7. package/dist/_ShapesGraphToAstTransformer/shapeAstTypeName.d.ts +4 -0
  8. package/dist/_ShapesGraphToAstTransformer/shapeAstTypeName.js +27 -0
  9. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstObjectTypeProperty.js +74 -19
  10. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstCompoundType.d.ts +1 -1
  11. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstCompoundType.js +45 -91
  12. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstListType.d.ts +11 -0
  13. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstListType.js +146 -0
  14. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstObjectType.d.ts +7 -0
  15. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstObjectType.js +182 -0
  16. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstTermType.js +9 -7
  17. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstType.d.ts +3 -5
  18. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstType.js +33 -10
  19. package/dist/ast/AbstractCompoundType.d.ts +26 -8
  20. package/dist/ast/AbstractCompoundType.js +84 -16
  21. package/dist/ast/AbstractContainerType.d.ts +2 -4
  22. package/dist/ast/AbstractContainerType.js +3 -4
  23. package/dist/ast/AbstractLazyObjectType.d.ts +1 -0
  24. package/dist/ast/AbstractLazyObjectType.js +3 -0
  25. package/dist/ast/AbstractTermType.d.ts +1 -0
  26. package/dist/ast/AbstractTermType.js +1 -0
  27. package/dist/ast/AbstractType.d.ts +16 -1
  28. package/dist/ast/AbstractType.js +11 -1
  29. package/dist/ast/Ast.d.ts +4 -4
  30. package/dist/ast/BlankNodeType.d.ts +1 -1
  31. package/dist/ast/DefaultValueType.d.ts +1 -2
  32. package/dist/ast/DefaultValueType.js +2 -0
  33. package/dist/ast/IdentifierType.d.ts +1 -1
  34. package/dist/ast/IntersectionType.d.ts +7 -2
  35. package/dist/ast/IntersectionType.js +8 -0
  36. package/dist/ast/ListType.d.ts +2 -9
  37. package/dist/ast/ListType.js +1 -9
  38. package/dist/ast/LiteralType.d.ts +1 -0
  39. package/dist/ast/LiteralType.js +26 -0
  40. package/dist/ast/ObjectCompoundType.d.ts +12 -0
  41. package/dist/ast/ObjectCompoundType.js +88 -0
  42. package/dist/ast/ObjectIntersectionType.d.ts +3 -7
  43. package/dist/ast/ObjectIntersectionType.js +1 -7
  44. package/dist/ast/ObjectType.d.ts +14 -31
  45. package/dist/ast/ObjectType.js +41 -73
  46. package/dist/ast/ObjectUnionType.d.ts +3 -7
  47. package/dist/ast/ObjectUnionType.js +1 -7
  48. package/dist/ast/OptionType.d.ts +1 -2
  49. package/dist/ast/OptionType.js +2 -0
  50. package/dist/ast/SetType.d.ts +1 -2
  51. package/dist/ast/SetType.js +2 -0
  52. package/dist/ast/Type.d.ts +1 -4
  53. package/dist/ast/Type.js +0 -6
  54. package/dist/ast/UnionType.d.ts +11 -6
  55. package/dist/ast/UnionType.js +6 -4
  56. package/dist/ast/index.d.ts +1 -2
  57. package/dist/ast/index.js +1 -2
  58. package/dist/generators/json/AstJsonGenerator.js +16 -14
  59. package/dist/generators/ts/AbstractCollectionType.js +8 -10
  60. package/dist/generators/ts/AbstractContainerType.d.ts +8 -3
  61. package/dist/generators/ts/AbstractContainerType.js +9 -2
  62. package/dist/generators/ts/AbstractDateType.d.ts +2 -2
  63. package/dist/generators/ts/AbstractDateType.js +2 -2
  64. package/dist/generators/ts/AbstractIdentifierType.d.ts +1 -1
  65. package/dist/generators/ts/AbstractIdentifierType.js +1 -1
  66. package/dist/generators/ts/AbstractLazyObjectType.d.ts +11 -8
  67. package/dist/generators/ts/AbstractLazyObjectType.js +19 -14
  68. package/dist/generators/ts/AbstractNamedUnionType.d.ts +33 -0
  69. package/dist/generators/ts/AbstractNamedUnionType.js +193 -0
  70. package/dist/generators/ts/AbstractNumericType.d.ts +2 -2
  71. package/dist/generators/ts/AbstractNumericType.js +3 -3
  72. package/dist/generators/ts/AbstractTermType.d.ts +7 -4
  73. package/dist/generators/ts/AbstractTermType.js +7 -4
  74. package/dist/generators/ts/AbstractType.d.ts +29 -14
  75. package/dist/generators/ts/AbstractUnionType.d.ts +80 -0
  76. package/dist/generators/ts/AbstractUnionType.js +514 -0
  77. package/dist/generators/ts/AnonymousUnionType.d.ts +26 -0
  78. package/dist/generators/ts/AnonymousUnionType.js +56 -0
  79. package/dist/generators/ts/BigDecimalType.d.ts +3 -3
  80. package/dist/generators/ts/BigDecimalType.js +3 -3
  81. package/dist/generators/ts/BlankNodeType.d.ts +1 -1
  82. package/dist/generators/ts/BlankNodeType.js +1 -1
  83. package/dist/generators/ts/BooleanType.d.ts +2 -2
  84. package/dist/generators/ts/BooleanType.js +2 -2
  85. package/dist/generators/ts/DefaultValueType.d.ts +4 -4
  86. package/dist/generators/ts/DefaultValueType.js +14 -13
  87. package/dist/generators/ts/IdentifierType.d.ts +1 -1
  88. package/dist/generators/ts/IdentifierType.js +1 -1
  89. package/dist/generators/ts/IriType.d.ts +1 -1
  90. package/dist/generators/ts/IriType.js +1 -1
  91. package/dist/generators/ts/LazyObjectOptionType.d.ts +1 -1
  92. package/dist/generators/ts/LazyObjectOptionType.js +9 -9
  93. package/dist/generators/ts/LazyObjectSetType.d.ts +1 -1
  94. package/dist/generators/ts/LazyObjectSetType.js +7 -7
  95. package/dist/generators/ts/LazyObjectType.d.ts +1 -1
  96. package/dist/generators/ts/LazyObjectType.js +7 -8
  97. package/dist/generators/ts/ListType.d.ts +8 -7
  98. package/dist/generators/ts/ListType.js +14 -13
  99. package/dist/generators/ts/LiteralType.d.ts +1 -1
  100. package/dist/generators/ts/LiteralType.js +2 -2
  101. package/dist/generators/ts/NamedObjectUnionType.d.ts +35 -0
  102. package/dist/generators/ts/NamedObjectUnionType.js +221 -0
  103. package/dist/generators/ts/NamedUnionType.d.ts +11 -0
  104. package/dist/generators/ts/NamedUnionType.js +13 -0
  105. package/dist/generators/ts/ObjectType.d.ts +34 -25
  106. package/dist/generators/ts/ObjectType.js +62 -52
  107. package/dist/generators/ts/OptionType.d.ts +4 -4
  108. package/dist/generators/ts/OptionType.js +10 -10
  109. package/dist/generators/ts/SetType.d.ts +4 -4
  110. package/dist/generators/ts/SetType.js +13 -11
  111. package/dist/generators/ts/StringType.d.ts +2 -2
  112. package/dist/generators/ts/StringType.js +2 -2
  113. package/dist/generators/ts/TermType.d.ts +1 -1
  114. package/dist/generators/ts/TermType.js +2 -2
  115. package/dist/generators/ts/TsGenerator.js +23 -15
  116. package/dist/generators/ts/Type.d.ts +4 -3
  117. package/dist/generators/ts/TypeFactory.d.ts +7 -5
  118. package/dist/generators/ts/TypeFactory.js +117 -90
  119. package/dist/generators/ts/ZodGenerator.js +6 -6
  120. package/dist/generators/ts/_ObjectType/AbstractProperty.d.ts +3 -3
  121. package/dist/generators/ts/_ObjectType/{TypeDiscriminantProperty.d.ts → DiscriminantProperty.d.ts} +14 -14
  122. package/dist/generators/ts/_ObjectType/{TypeDiscriminantProperty.js → DiscriminantProperty.js} +10 -10
  123. package/dist/generators/ts/_ObjectType/IdentifierPrefixProperty.d.ts +2 -2
  124. package/dist/generators/ts/_ObjectType/IdentifierPrefixProperty.js +2 -2
  125. package/dist/generators/ts/_ObjectType/IdentifierProperty.d.ts +2 -2
  126. package/dist/generators/ts/_ObjectType/IdentifierProperty.js +7 -4
  127. package/dist/generators/ts/_ObjectType/ObjectType_classDeclaration.js +8 -8
  128. package/dist/generators/ts/_ObjectType/ObjectType_focusSparqlConstructTriplesFunctionDeclaration.d.ts +5 -0
  129. package/dist/generators/ts/_ObjectType/{ObjectType_sparqlConstructTriplesFunctionDeclaration.js → ObjectType_focusSparqlConstructTriplesFunctionDeclaration.js} +6 -5
  130. package/dist/generators/ts/_ObjectType/ObjectType_focusSparqlWherePatternsFunctionDeclaration.d.ts +5 -0
  131. package/dist/generators/ts/_ObjectType/{ObjectType_sparqlWherePatternsFunctionDeclarations.js → ObjectType_focusSparqlWherePatternsFunctionDeclaration.js} +5 -5
  132. package/dist/generators/ts/_ObjectType/ObjectType_fromJsonFunctionDeclaration.d.ts +5 -0
  133. package/dist/generators/ts/_ObjectType/ObjectType_fromJsonFunctionDeclaration.js +20 -0
  134. package/dist/generators/ts/_ObjectType/ObjectType_fromRdfResourceFunctionDeclaration.d.ts +5 -0
  135. package/dist/generators/ts/_ObjectType/{ObjectType_fromRdfFunctionDeclaration.js → ObjectType_fromRdfResourceFunctionDeclaration.js} +6 -7
  136. package/dist/generators/ts/_ObjectType/ObjectType_fromRdfResourceValuesFunctionDeclaration.d.ts +5 -0
  137. package/dist/generators/ts/_ObjectType/ObjectType_fromRdfResourceValuesFunctionDeclaration.js +20 -0
  138. package/dist/generators/ts/_ObjectType/ObjectType_isTypeFunctionDeclaration.js +2 -2
  139. package/dist/generators/ts/_ObjectType/ObjectType_parseJsonFunctionDeclaration.d.ts +5 -0
  140. package/dist/generators/ts/_ObjectType/ObjectType_parseJsonFunctionDeclaration.js +19 -0
  141. package/dist/generators/ts/_ObjectType/ObjectType_propertiesFromJsonFunctionDeclaration.d.ts +5 -0
  142. package/dist/generators/ts/_ObjectType/ObjectType_propertiesFromJsonFunctionDeclaration.js +38 -0
  143. package/dist/generators/ts/_ObjectType/ObjectType_propertiesFromRdfResourceFunctionDeclaration.d.ts +5 -0
  144. package/dist/generators/ts/_ObjectType/{ObjectType_propertiesFromRdfFunctionDeclaration.js → ObjectType_propertiesFromRdfResourceFunctionDeclaration.js} +16 -15
  145. package/dist/generators/ts/_ObjectType/ObjectType_schemaVariableStatement.js +1 -2
  146. package/dist/generators/ts/_ObjectType/ObjectType_sparqlConstructQueryFunctionDeclaration.js +2 -2
  147. package/dist/generators/ts/_ObjectType/ObjectType_toRdfResourceFunctionOrMethodDeclaration.d.ts +5 -0
  148. package/dist/generators/ts/_ObjectType/{ObjectType_toRdfFunctionOrMethodDeclaration.js → ObjectType_toRdfResourceFunctionOrMethodDeclaration.js} +10 -8
  149. package/dist/generators/ts/_ObjectType/ObjectType_valueSparqlConstructTriplesFunctionDeclaration.d.ts +5 -0
  150. package/dist/generators/ts/_ObjectType/ObjectType_valueSparqlConstructTriplesFunctionDeclaration.js +13 -0
  151. package/dist/generators/ts/_ObjectType/ObjectType_valueSparqlWherePatternsFunctionDeclaration.d.ts +5 -0
  152. package/dist/generators/ts/_ObjectType/ObjectType_valueSparqlWherePatternsFunctionDeclaration.js +15 -0
  153. package/dist/generators/ts/_ObjectType/Property.d.ts +2 -2
  154. package/dist/generators/ts/_ObjectType/ShaclProperty.d.ts +2 -2
  155. package/dist/generators/ts/_ObjectType/ShaclProperty.js +6 -6
  156. package/dist/generators/ts/_snippets/snippets_FocusSparqlConstructTriplesFunction.d.ts +2 -0
  157. package/dist/generators/ts/_snippets/snippets_FocusSparqlConstructTriplesFunction.js +12 -0
  158. package/dist/generators/ts/_snippets/snippets_FocusSparqlWherePatternsFunction.d.ts +2 -0
  159. package/dist/generators/ts/_snippets/snippets_FocusSparqlWherePatternsFunction.js +14 -0
  160. package/dist/generators/ts/_snippets/snippets_FromRdfResourceFunction.d.ts +2 -0
  161. package/dist/generators/ts/_snippets/snippets_FromRdfResourceFunction.js +15 -0
  162. package/dist/generators/ts/_snippets/snippets_FromRdfResourceValuesFunction.d.ts +2 -0
  163. package/dist/generators/ts/_snippets/snippets_FromRdfResourceValuesFunction.js +17 -0
  164. package/dist/generators/ts/_snippets/snippets_PropertiesFromRdfResourceFunction.d.ts +2 -0
  165. package/dist/generators/ts/_snippets/snippets_PropertiesFromRdfResourceFunction.js +15 -0
  166. package/dist/generators/ts/_snippets/snippets_PropertyPath.d.ts +5 -0
  167. package/dist/generators/ts/_snippets/snippets_PropertyPath.js +35 -0
  168. package/dist/generators/ts/_snippets/snippets_ShaclPropertySchema.js +2 -2
  169. package/dist/generators/ts/_snippets/snippets_ToRdfResourceFunction.d.ts +2 -0
  170. package/dist/generators/ts/_snippets/snippets_ToRdfResourceFunction.js +7 -0
  171. package/dist/generators/ts/_snippets/snippets_ToRdfResourceValuesFunction.d.ts +2 -0
  172. package/dist/generators/ts/_snippets/snippets_ToRdfResourceValuesFunction.js +16 -0
  173. package/dist/generators/ts/_snippets/snippets_ValueSparqlConstructTriplesFunction.d.ts +2 -0
  174. package/dist/generators/ts/_snippets/snippets_ValueSparqlConstructTriplesFunction.js +13 -0
  175. package/dist/generators/ts/_snippets/snippets_ValueSparqlWherePatternsFunction.d.ts +2 -0
  176. package/dist/generators/ts/_snippets/snippets_ValueSparqlWherePatternsFunction.js +16 -0
  177. package/dist/generators/ts/_snippets/snippets_bigDecimalSparqlWherePatterns.js +2 -2
  178. package/dist/generators/ts/_snippets/snippets_blankNodeSparqlWherePatterns.js +2 -2
  179. package/dist/generators/ts/_snippets/snippets_booleanEquals.js +1 -1
  180. package/dist/generators/ts/_snippets/snippets_booleanSparqlWherePatterns.js +2 -2
  181. package/dist/generators/ts/_snippets/snippets_dateSparqlWherePatterns.js +2 -2
  182. package/dist/generators/ts/_snippets/snippets_defaultValueSparqlWherePatterns.js +2 -2
  183. package/dist/generators/ts/_snippets/snippets_fromRdfLanguageIn.js +1 -1
  184. package/dist/generators/ts/_snippets/snippets_identifierSparqlWherePatterns.js +2 -2
  185. package/dist/generators/ts/_snippets/snippets_iriSparqlWherePatterns.js +2 -2
  186. package/dist/generators/ts/_snippets/snippets_listSparqlConstructTriples.js +2 -2
  187. package/dist/generators/ts/_snippets/snippets_listSparqlWherePatterns.js +2 -2
  188. package/dist/generators/ts/_snippets/snippets_literalSparqlWherePatterns.js +2 -2
  189. package/dist/generators/ts/_snippets/snippets_maybeSparqlConstructTriples.js +2 -2
  190. package/dist/generators/ts/_snippets/snippets_maybeSparqlWherePatterns.js +2 -2
  191. package/dist/generators/ts/_snippets/snippets_numericSparqlWherePatterns.js +2 -3
  192. package/dist/generators/ts/_snippets/snippets_setSparqlConstructTriples.js +2 -2
  193. package/dist/generators/ts/_snippets/snippets_setSparqlWherePatterns.js +2 -2
  194. package/dist/generators/ts/_snippets/snippets_shaclPropertySparqlConstructTriples.js +4 -3
  195. package/dist/generators/ts/_snippets/snippets_shaclPropertySparqlWherePatterns.js +4 -3
  196. package/dist/generators/ts/_snippets/snippets_sparqlPropertyPath.js +3 -2
  197. package/dist/generators/ts/_snippets/snippets_stringSparqlWherePatterns.js +2 -2
  198. package/dist/generators/ts/_snippets/snippets_termSparqlWherePatterns.js +2 -2
  199. package/dist/generators/ts/graphqlSchemaVariableStatement.d.ts +2 -2
  200. package/dist/generators/ts/graphqlSchemaVariableStatement.js +4 -4
  201. package/dist/generators/ts/imports.d.ts +1 -1
  202. package/dist/generators/ts/imports.js +1 -1
  203. package/dist/generators/ts/objectSetDeclarations.d.ts +3 -3
  204. package/dist/generators/ts/objectSetDeclarations.js +15 -15
  205. package/dist/generators/ts/objectSetInterfaceDeclaration.d.ts +3 -3
  206. package/dist/generators/ts/objectSetInterfaceDeclaration.js +2 -2
  207. package/dist/generators/ts/rdfjsDatasetObjectSetClassDeclaration.d.ts +3 -3
  208. package/dist/generators/ts/rdfjsDatasetObjectSetClassDeclaration.js +16 -17
  209. package/dist/generators/ts/snippets.d.ts +10 -6
  210. package/dist/generators/ts/snippets.js +20 -12
  211. package/dist/generators/ts/sparqlObjectSetClassDeclaration.d.ts +3 -3
  212. package/dist/generators/ts/sparqlObjectSetClassDeclaration.js +7 -8
  213. package/dist/generators/ts/synthesizeUberObjectUnionType.d.ts +2 -2
  214. package/dist/generators/ts/synthesizeUberObjectUnionType.js +9 -4
  215. package/dist/input/NodeShape.d.ts +5 -6
  216. package/dist/input/NodeShape.js +19 -22
  217. package/dist/input/Ontology.d.ts +4 -4
  218. package/dist/input/Ontology.js +10 -10
  219. package/dist/input/PropertyShape.d.ts +4 -4
  220. package/dist/input/PropertyShape.js +10 -10
  221. package/dist/input/ShapesGraph.d.ts +3 -2
  222. package/dist/input/ShapesGraph.js +13 -8
  223. package/dist/input/generated.d.ts +2551 -2040
  224. package/dist/input/generated.js +2806 -2346
  225. package/package.json +3 -5
  226. package/dist/_ShapesGraphToAstTransformer/CurieFactory.d.ts +0 -16
  227. package/dist/_ShapesGraphToAstTransformer/CurieFactory.js +0 -45
  228. package/dist/_ShapesGraphToAstTransformer/NodeShapeAstType.d.ts +0 -3
  229. package/dist/_ShapesGraphToAstTransformer/NodeShapeAstType.js +0 -2
  230. package/dist/_ShapesGraphToAstTransformer/index.d.ts +0 -6
  231. package/dist/_ShapesGraphToAstTransformer/index.js +0 -6
  232. package/dist/_ShapesGraphToAstTransformer/shapeIdentifier.d.ts +0 -5
  233. package/dist/_ShapesGraphToAstTransformer/shapeIdentifier.js +0 -9
  234. package/dist/_ShapesGraphToAstTransformer/transformNodeShapeToAstType.d.ts +0 -11
  235. package/dist/_ShapesGraphToAstTransformer/transformNodeShapeToAstType.js +0 -338
  236. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstAbstractTypeProperties.d.ts +0 -12
  237. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstAbstractTypeProperties.js +0 -31
  238. package/dist/ast/AbstractObjectCompoundType.d.ts +0 -45
  239. package/dist/ast/AbstractObjectCompoundType.js +0 -180
  240. package/dist/ast/Curie.d.ts +0 -21
  241. package/dist/ast/Curie.js +0 -29
  242. package/dist/ast/PlaceholderType.d.ts +0 -15
  243. package/dist/ast/PlaceholderType.js +0 -19
  244. package/dist/generators/codeName.d.ts +0 -6
  245. package/dist/generators/codeName.js +0 -66
  246. package/dist/generators/ts/AbstractDeclaredType.d.ts +0 -23
  247. package/dist/generators/ts/AbstractDeclaredType.js +0 -17
  248. package/dist/generators/ts/ObjectUnionType.d.ts +0 -65
  249. package/dist/generators/ts/ObjectUnionType.js +0 -257
  250. package/dist/generators/ts/UnionType.d.ts +0 -40
  251. package/dist/generators/ts/UnionType.js +0 -527
  252. package/dist/generators/ts/_ObjectType/ObjectType_fromJsonFunctionDeclarations.d.ts +0 -4
  253. package/dist/generators/ts/_ObjectType/ObjectType_fromJsonFunctionDeclarations.js +0 -66
  254. package/dist/generators/ts/_ObjectType/ObjectType_fromRdfFunctionDeclaration.d.ts +0 -5
  255. package/dist/generators/ts/_ObjectType/ObjectType_propertiesFromRdfFunctionDeclaration.d.ts +0 -5
  256. package/dist/generators/ts/_ObjectType/ObjectType_sparqlConstructTriplesFunctionDeclaration.d.ts +0 -5
  257. package/dist/generators/ts/_ObjectType/ObjectType_sparqlWherePatternsFunctionDeclarations.d.ts +0 -5
  258. package/dist/generators/ts/_ObjectType/ObjectType_toRdfFunctionOrMethodDeclaration.d.ts +0 -5
  259. package/dist/generators/ts/_ObjectUnionType/MemberType.d.ts +0 -34
  260. package/dist/generators/ts/_ObjectUnionType/MemberType.js +0 -105
  261. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_equalsFunctionDeclaration.d.ts +0 -5
  262. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_equalsFunctionDeclaration.js +0 -29
  263. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_filterFunctionDeclaration.d.ts +0 -4
  264. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_filterFunctionDeclaration.js +0 -19
  265. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_filterTypeDeclaration.d.ts +0 -4
  266. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_filterTypeDeclaration.js +0 -10
  267. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_fromJsonFunctionDeclaration.d.ts +0 -5
  268. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_fromJsonFunctionDeclaration.js +0 -19
  269. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_fromRdfFunctionDeclarations.d.ts +0 -5
  270. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_fromRdfFunctionDeclarations.js +0 -20
  271. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_graphqlTypeVariableStatement.d.ts +0 -5
  272. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_graphqlTypeVariableStatement.js +0 -18
  273. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_hashFunctionDeclaration.d.ts +0 -5
  274. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_hashFunctionDeclaration.js +0 -28
  275. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_identifierTypeDeclarations.d.ts +0 -4
  276. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_identifierTypeDeclarations.js +0 -9
  277. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_isTypeFunctionDeclaration.d.ts +0 -5
  278. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_isTypeFunctionDeclaration.js +0 -13
  279. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_jsonTypeAliasDeclaration.d.ts +0 -5
  280. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_jsonTypeAliasDeclaration.js +0 -10
  281. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_jsonZodSchemaFunctionDeclaration.d.ts +0 -5
  282. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_jsonZodSchemaFunctionDeclaration.js +0 -14
  283. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_schemaVariableStatement.d.ts +0 -4
  284. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_schemaVariableStatement.js +0 -37
  285. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_sparqlConstructTriplesFunctionDeclaration.d.ts +0 -5
  286. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_sparqlConstructTriplesFunctionDeclaration.js +0 -15
  287. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_sparqlWherePatternsFunctionDeclaration.d.ts +0 -5
  288. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_sparqlWherePatternsFunctionDeclaration.js +0 -35
  289. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_toJsonFunctionDeclaration.d.ts +0 -5
  290. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_toJsonFunctionDeclaration.js +0 -26
  291. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_toRdfFunctionDeclarations.d.ts +0 -5
  292. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_toRdfFunctionDeclarations.js +0 -43
  293. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_typeAliasDeclaration.d.ts +0 -4
  294. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_typeAliasDeclaration.js +0 -10
  295. package/dist/generators/ts/_snippets/snippets_FromRdfOptions.d.ts +0 -2
  296. package/dist/generators/ts/_snippets/snippets_FromRdfOptions.js +0 -5
  297. package/dist/generators/ts/_snippets/snippets_PropertiesFromRdfParameters.d.ts +0 -2
  298. package/dist/generators/ts/_snippets/snippets_PropertiesFromRdfParameters.js +0 -5
  299. package/dist/generators/ts/_snippets/snippets_SparqlConstructTriplesFunction.d.ts +0 -2
  300. package/dist/generators/ts/_snippets/snippets_SparqlConstructTriplesFunction.js +0 -6
  301. package/dist/generators/ts/_snippets/snippets_SparqlConstructTriplesFunctionParameters.d.ts +0 -2
  302. package/dist/generators/ts/_snippets/snippets_SparqlConstructTriplesFunctionParameters.js +0 -12
  303. package/dist/generators/ts/_snippets/snippets_SparqlWherePatternsFunction.d.ts +0 -2
  304. package/dist/generators/ts/_snippets/snippets_SparqlWherePatternsFunction.js +0 -6
  305. package/dist/generators/ts/_snippets/snippets_SparqlWherePatternsFunctionParameters.d.ts +0 -2
  306. package/dist/generators/ts/_snippets/snippets_SparqlWherePatternsFunctionParameters.js +0 -15
@@ -1,13 +1,10 @@
1
- import PrefixMap from "@rdfjs/prefix-map/PrefixMap.js";
2
1
  import type { Either } from "purify-ts";
3
2
  import type { Generator } from "./generators/Generator.js";
4
3
  import type { ShapesGraph } from "./input/ShapesGraph.js";
5
4
  export declare class Compiler {
6
5
  private readonly generator;
7
- private readonly iriPrefixMap;
8
- constructor({ generator, iriPrefixMap, }: {
6
+ constructor({ generator }: {
9
7
  generator: Generator;
10
- iriPrefixMap?: PrefixMap;
11
8
  });
12
9
  compile(shapesGraph: ShapesGraph): Either<Error, string>;
13
10
  }
package/dist/Compiler.js CHANGED
@@ -1,15 +1,11 @@
1
- import PrefixMap from "@rdfjs/prefix-map/PrefixMap.js";
2
1
  import { ShapesGraphToAstTransformer } from "./ShapesGraphToAstTransformer.js";
3
2
  export class Compiler {
4
3
  generator;
5
- iriPrefixMap;
6
- constructor({ generator, iriPrefixMap, }) {
4
+ constructor({ generator }) {
7
5
  this.generator = generator;
8
- this.iriPrefixMap = iriPrefixMap ?? new PrefixMap();
9
6
  }
10
7
  compile(shapesGraph) {
11
8
  return new ShapesGraphToAstTransformer({
12
- iriPrefixMap: this.iriPrefixMap,
13
9
  shapesGraph,
14
10
  })
15
11
  .transform()
@@ -1,23 +1,14 @@
1
- import type PrefixMap from "@rdfjs/prefix-map/PrefixMap.js";
2
1
  import TermMap from "@rdfjs/term-map";
3
2
  import type * as rdfjs from "@rdfjs/types";
4
3
  import { Either } from "purify-ts";
5
- import { CurieFactory } from "./_ShapesGraphToAstTransformer/CurieFactory.js";
6
- import * as _ShapesGraphToAstTransformer from "./_ShapesGraphToAstTransformer/index.js";
7
4
  import type * as ast from "./ast/index.js";
8
5
  import type { TsFeature } from "./enums/TsFeature.js";
9
6
  import type * as input from "./input/index.js";
10
7
  export declare class ShapesGraphToAstTransformer {
11
- protected readonly curieFactory: CurieFactory;
12
- protected readonly nodeShapeAstTypesByIdentifier: TermMap<rdfjs.BlankNode | rdfjs.NamedNode, _ShapesGraphToAstTransformer.NodeShapeAstType>;
8
+ protected readonly cachedAstTypesByShapeIdentifier: TermMap<rdfjs.BlankNode | rdfjs.NamedNode, ast.Type>;
13
9
  protected readonly shapesGraph: input.ShapesGraph;
14
- protected shapeIdentifier: typeof _ShapesGraphToAstTransformer.shapeIdentifier;
15
- protected transformNodeShapeToAstType: typeof _ShapesGraphToAstTransformer.transformNodeShapeToAstType;
16
- protected transformPropertyShapeToAstObjectTypeProperty: typeof _ShapesGraphToAstTransformer.transformPropertyShapeToAstObjectTypeProperty;
17
- protected transformShapeToAstType: typeof _ShapesGraphToAstTransformer.transformShapeToAstType;
18
10
  protected tsFeaturesDefault: ReadonlySet<TsFeature>;
19
- constructor({ iriPrefixMap, shapesGraph, tsFeaturesDefault, }: {
20
- iriPrefixMap: PrefixMap;
11
+ constructor({ shapesGraph, tsFeaturesDefault, }: {
21
12
  shapesGraph: input.ShapesGraph;
22
13
  tsFeaturesDefault?: ReadonlySet<TsFeature>;
23
14
  });
@@ -1,30 +1,25 @@
1
1
  import TermMap from "@rdfjs/term-map";
2
2
  import { dash } from "@tpluscode/rdf-ns-builders";
3
3
  import { Either } from "purify-ts";
4
- import { CurieFactory } from "./_ShapesGraphToAstTransformer/CurieFactory.js";
5
- import * as _ShapesGraphToAstTransformer from "./_ShapesGraphToAstTransformer/index.js";
4
+ import { invariant } from "ts-invariant";
5
+ import { ShapeStack } from "./_ShapesGraphToAstTransformer/ShapeStack.js";
6
+ import { transformShapeToAstType } from "./_ShapesGraphToAstTransformer/transformShapeToAstType.js";
6
7
  export class ShapesGraphToAstTransformer {
7
- // Members are protected so they're accessible to the bound functions
8
- curieFactory;
9
- nodeShapeAstTypesByIdentifier = new TermMap();
8
+ // Members are protected so they're accessible to functions in other files
9
+ cachedAstTypesByShapeIdentifier = new TermMap();
10
10
  shapesGraph;
11
- shapeIdentifier = _ShapesGraphToAstTransformer.shapeIdentifier;
12
- transformNodeShapeToAstType = _ShapesGraphToAstTransformer.transformNodeShapeToAstType;
13
- transformPropertyShapeToAstObjectTypeProperty = _ShapesGraphToAstTransformer.transformPropertyShapeToAstObjectTypeProperty;
14
- transformShapeToAstType = _ShapesGraphToAstTransformer.transformShapeToAstType;
15
11
  tsFeaturesDefault;
16
- constructor({ iriPrefixMap, shapesGraph, tsFeaturesDefault, }) {
17
- this.curieFactory = new CurieFactory({ prefixMap: iriPrefixMap });
12
+ constructor({ shapesGraph, tsFeaturesDefault, }) {
18
13
  this.shapesGraph = shapesGraph;
19
14
  this.tsFeaturesDefault =
20
15
  tsFeaturesDefault ??
21
16
  new Set(["create", "equals", "hash", "json", "rdf"]);
22
17
  }
23
18
  transform() {
24
- const nodeShapeAstObjectIntersectionTypes = [];
25
- const nodeShapeAstObjectTypes = [];
19
+ const astNamedIntersectionTypes = [];
20
+ const astObjectTypes = [];
26
21
  const syntheticAstObjectTypesByName = {};
27
- const nodeShapeAstObjectUnionTypes = [];
22
+ const astNamedUnionTypes = [];
28
23
  for (const nodeShape of this.shapesGraph.nodeShapes) {
29
24
  if (nodeShape.identifier.termType !== "NamedNode") {
30
25
  continue;
@@ -32,26 +27,27 @@ export class ShapesGraphToAstTransformer {
32
27
  if (nodeShape.identifier.value.startsWith(dash[""].value)) {
33
28
  continue;
34
29
  }
35
- const nodeShapeAstTypeEither = this.transformNodeShapeToAstType(nodeShape);
30
+ const nodeShapeAstTypeEither = transformShapeToAstType.call(this, nodeShape, new ShapeStack());
36
31
  if (nodeShapeAstTypeEither.isLeft()) {
37
32
  return nodeShapeAstTypeEither;
38
33
  }
39
34
  const nodeShapeAstType = nodeShapeAstTypeEither.unsafeCoerce();
40
35
  switch (nodeShapeAstType.kind) {
41
- case "ListType":
42
- break; // Ignore
43
- case "ObjectIntersectionType":
44
- nodeShapeAstObjectIntersectionTypes.push(nodeShapeAstType);
36
+ case "IntersectionType":
37
+ if (nodeShapeAstType.name.isJust()) {
38
+ astNamedIntersectionTypes.push(nodeShapeAstType);
39
+ }
45
40
  break;
46
41
  case "ObjectType": {
47
- nodeShapeAstObjectTypes.push(nodeShapeAstType);
42
+ invariant(nodeShapeAstType.name.isJust());
43
+ astObjectTypes.push(nodeShapeAstType);
48
44
  for (const property of nodeShapeAstType.properties) {
49
45
  switch (property.type.kind) {
50
46
  case "LazyObjectOptionType":
51
47
  case "LazyObjectSetType":
52
48
  case "LazyObjectType": {
53
49
  const partialItemType = property.type.partialType.kind === "ObjectType" ||
54
- property.type.partialType.kind === "ObjectUnionType"
50
+ property.type.partialType.kind === "UnionType"
55
51
  ? property.type.partialType
56
52
  : property.type.partialType.itemType;
57
53
  if (partialItemType.kind === "ObjectType" &&
@@ -67,17 +63,19 @@ export class ShapesGraphToAstTransformer {
67
63
  }
68
64
  break;
69
65
  }
70
- case "ObjectUnionType":
71
- nodeShapeAstObjectUnionTypes.push(nodeShapeAstType);
66
+ case "UnionType":
67
+ if (nodeShapeAstType.name.isJust()) {
68
+ astNamedUnionTypes.push(nodeShapeAstType);
69
+ }
72
70
  break;
73
71
  default:
74
- nodeShapeAstType;
72
+ break;
75
73
  }
76
74
  }
77
75
  return Either.of({
78
- objectIntersectionTypes: nodeShapeAstObjectIntersectionTypes,
79
- objectTypes: nodeShapeAstObjectTypes.concat(Object.values(syntheticAstObjectTypesByName)),
80
- objectUnionTypes: nodeShapeAstObjectUnionTypes,
76
+ namedIntersectionTypes: astNamedIntersectionTypes,
77
+ objectTypes: astObjectTypes.concat(Object.values(syntheticAstObjectTypesByName)),
78
+ namedUnionTypes: astNamedUnionTypes,
81
79
  });
82
80
  }
83
81
  }
@@ -0,0 +1,3 @@
1
+ import type { NodeKind } from "@shaclmate/shacl-ast";
2
+ export declare const defaultNodeShapeNodeKinds: ReadonlySet<NodeKind>;
3
+ //# sourceMappingURL=defaultNodeShapeNodeKinds.d.ts.map
@@ -0,0 +1,5 @@
1
+ export const defaultNodeShapeNodeKinds = new Set([
2
+ "BlankNode",
3
+ "IRI",
4
+ ]);
5
+ //# sourceMappingURL=defaultNodeShapeNodeKinds.js.map
@@ -0,0 +1,4 @@
1
+ import { Maybe } from "purify-ts";
2
+ import type * as input from "../input/index.js";
3
+ export declare function shapeAstTypeName(shape: input.Shape): Maybe<string>;
4
+ //# sourceMappingURL=shapeAstTypeName.d.ts.map
@@ -0,0 +1,27 @@
1
+ import { Curie } from "@shaclmate/shacl-ast";
2
+ import { Maybe } from "purify-ts";
3
+ export function shapeAstTypeName(shape) {
4
+ if (shape.kind !== "NodeShape") {
5
+ return Maybe.empty();
6
+ }
7
+ if (shape.identifier.termType !== "NamedNode") {
8
+ return Maybe.empty();
9
+ }
10
+ // Explicit shaclmate:name
11
+ if (shape.shaclmateName.isJust()) {
12
+ return shape.shaclmateName;
13
+ }
14
+ // Explicit rdfs:label
15
+ if (shape.label.isJust()) {
16
+ return shape.label;
17
+ }
18
+ // CURIE shape identifier
19
+ if (shape.identifier instanceof Curie) {
20
+ if (shape.identifier.hasUniqueReference) {
21
+ return Maybe.of(shape.identifier.reference);
22
+ }
23
+ return Maybe.of(`${shape.identifier.prefix}_${shape.identifier.reference}`);
24
+ }
25
+ return Maybe.empty();
26
+ }
27
+ //# sourceMappingURL=shapeAstTypeName.js.map
@@ -1,10 +1,11 @@
1
1
  import dataFactory from "@rdfjs/data-model";
2
+ import { Curie } from "@shaclmate/shacl-ast";
2
3
  import { Either, Left, Maybe } from "purify-ts";
3
4
  import { invariant } from "ts-invariant";
4
5
  import * as ast from "../ast/index.js";
5
6
  import { Eithers } from "../Eithers.js";
6
7
  import { ShapeStack } from "./ShapeStack.js";
7
- import { transformShapeToAstAbstractTypeProperties } from "./transformShapeToAstAbstractTypeProperties.js";
8
+ import { transformShapeToAstType } from "./transformShapeToAstType.js";
8
9
  function synthesizePartialAstObjectType({ identifierType, tsFeatures, }) {
9
10
  let syntheticName;
10
11
  switch (identifierType.kind) {
@@ -20,7 +21,6 @@ function synthesizePartialAstObjectType({ identifierType, tsFeatures, }) {
20
21
  return new ast.ObjectType({
21
22
  abstract: false,
22
23
  comment: Maybe.empty(),
23
- export_: true,
24
24
  extern: false,
25
25
  fromRdfType: Maybe.empty(),
26
26
  identifierType,
@@ -35,13 +35,55 @@ function synthesizePartialAstObjectType({ identifierType, tsFeatures, }) {
35
35
  tsObjectDeclarationType: "class",
36
36
  });
37
37
  }
38
- function transformPropertyShapeToAstType(propertyShape) {
38
+ function propertyName(objectType, propertyShape) {
39
+ // Explicit shaclmate:name or sh:name
40
+ const name = propertyShape.shaclmateName.alt(propertyShape.name).extract();
41
+ if (name) {
42
+ return name;
43
+ }
44
+ // Explicit rdfs:label
45
+ const label = propertyShape.label.extract();
46
+ if (label) {
47
+ return label;
48
+ }
49
+ // Pick up the common pattern of a property shape identifier being the node shape's identifier -localName,
50
+ // like ex:NodeShape-property
51
+ if (propertyShape.identifier.termType === "NamedNode" &&
52
+ objectType.shapeIdentifier.termType === "NamedNode") {
53
+ const propertyShapeIdentifierPrefix = `${objectType.shapeIdentifier.value}-`;
54
+ if (propertyShape.identifier.value.startsWith(propertyShapeIdentifierPrefix) &&
55
+ propertyShape.identifier.value.length >
56
+ propertyShapeIdentifierPrefix.length) {
57
+ return propertyShape.identifier.value.substring(propertyShapeIdentifierPrefix.length);
58
+ }
59
+ }
60
+ // sh:path CURIE reference
61
+ if (propertyShape.path instanceof Curie) {
62
+ return propertyShape.path.reference;
63
+ }
64
+ // Shape identifier CURIE reference
65
+ if (propertyShape.identifier instanceof Curie) {
66
+ return propertyShape.identifier.reference;
67
+ }
68
+ // Shape identifier IRI
69
+ if (propertyShape.identifier.termType === "NamedNode") {
70
+ return propertyShape.identifier.value;
71
+ }
72
+ // sh:path IRI
73
+ if (propertyShape.path.termType === "NamedNode") {
74
+ return propertyShape.path.value;
75
+ }
76
+ throw new Error(`${propertyShape}: unable to infer name`);
77
+ }
78
+ function transformPropertyShapeToAstType(propertyShape, shapeStack) {
39
79
  // if (
40
80
  // propertyShape.path.kind === "PredicatePath" &&
41
81
  // propertyShape.path.iri.value.endsWith("termProperty")
42
82
  // ) {
43
83
  // }
44
- return this.transformShapeToAstType(propertyShape, new ShapeStack()).chain((propertyShapeAstType) => {
84
+ return transformShapeToAstType
85
+ .call(this, propertyShape, shapeStack)
86
+ .chain((propertyShapeAstType) => {
45
87
  let maxCount = propertyShape.constraints.maxCount.orDefault(Number.MAX_SAFE_INTEGER);
46
88
  let minCount = propertyShape.constraints.minCount.orDefault(0);
47
89
  if (minCount < 0) {
@@ -84,17 +126,23 @@ function transformPropertyShapeToAstType(propertyShape) {
84
126
  });
85
127
  }
86
128
  export function transformPropertyShapeToAstObjectTypeProperty({ objectType, propertyShape, }) {
87
- return Eithers.chain3(transformShapeToAstAbstractTypeProperties(propertyShape), propertyShape.resolve, transformPropertyShapeToAstType.bind(this)(propertyShape)).chain(([astAbstractTypeProperties, propertyShapeResolve, astType]) => {
129
+ const shapeStack = new ShapeStack(); // Start a new ShapeStack per property shape
130
+ return Eithers.chain2(propertyShape.resolve, transformPropertyShapeToAstType.call(this, propertyShape, shapeStack)).chain(([propertyShapeResolve, astType]) => {
88
131
  let astResolveItemType;
89
132
  if (propertyShapeResolve.isJust()) {
90
- const astResolveTypeEither = this.transformNodeShapeToAstType(propertyShapeResolve.unsafeCoerce()).chain((astResolveType) => {
133
+ const astResolveTypeEither = transformShapeToAstType
134
+ .call(this, propertyShapeResolve.unsafeCoerce(), shapeStack)
135
+ .chain((astResolveType) => {
91
136
  switch (astResolveType.kind) {
92
- case "ListType":
93
- case "ObjectIntersectionType":
94
- return Left(new Error(`${propertyShape} resolve cannot refer to a ${astResolveType.kind}`));
95
137
  case "ObjectType":
96
- case "ObjectUnionType":
97
138
  return Either.of(astResolveType);
139
+ case "UnionType":
140
+ if (!astResolveType.isObjectUnionType()) {
141
+ return Left(new Error(`${propertyShape} resolve cannot refer to a ${astResolveType.kind} with non-ObjectType members`));
142
+ }
143
+ return Either.of(astResolveType);
144
+ default:
145
+ return Left(new Error(`${propertyShape} resolve cannot refer to a ${astResolveType.kind}`));
98
146
  }
99
147
  });
100
148
  if (astResolveTypeEither.isLeft()) {
@@ -130,18 +178,29 @@ export function transformPropertyShapeToAstObjectTypeProperty({ objectType, prop
130
178
  });
131
179
  break;
132
180
  case "ObjectType":
133
- case "ObjectUnionType":
181
+ astPartialItemType = astItemType;
182
+ break;
183
+ case "UnionType":
184
+ if (!astItemType.isObjectUnionType()) {
185
+ return Left(new Error(`${propertyShape} partial type cannot be a ${astItemType.kind} with non-ObjectType members`));
186
+ }
134
187
  astPartialItemType = astItemType;
135
188
  break;
136
189
  default:
137
190
  return Left(new Error(`${propertyShape} has a resolve with an incompatible partial type ${astItemType.kind}`));
138
191
  }
192
+ const astAbstractTypeProperties = {
193
+ comment: Maybe.empty(),
194
+ label: Maybe.empty(),
195
+ name: Maybe.empty(),
196
+ shapeIdentifier: propertyShape.identifier,
197
+ };
139
198
  switch (astType.kind) {
140
199
  case "BlankNodeType":
141
200
  case "IdentifierType":
142
201
  case "IriType":
143
202
  case "ObjectType":
144
- case "ObjectUnionType":
203
+ case "UnionType":
145
204
  astType = new ast.LazyObjectType({
146
205
  ...astAbstractTypeProperties,
147
206
  partialType: astPartialItemType,
@@ -183,15 +242,11 @@ export function transformPropertyShapeToAstObjectTypeProperty({ objectType, prop
183
242
  description: propertyShape.description,
184
243
  label: propertyShape.label,
185
244
  mutable: propertyShape.mutable.orDefault(false),
186
- name: propertyShape.shaclmateName.alt(propertyShape.name),
245
+ name: propertyName.call(this, objectType, propertyShape),
187
246
  objectType,
188
247
  order: propertyShape.order.orDefault(0),
189
- path: (propertyShape.path.termType === "NamedNode"
190
- ? this.curieFactory.create(propertyShape.path).extract()
191
- : undefined) ?? propertyShape.path,
192
- shapeIdentifier: (propertyShape.identifier.termType === "NamedNode"
193
- ? this.curieFactory.create(propertyShape.identifier).extract()
194
- : undefined) ?? propertyShape.identifier,
248
+ path: propertyShape.path,
249
+ shapeIdentifier: propertyShape.identifier,
195
250
  type: astType,
196
251
  visibility: propertyShape.visibility,
197
252
  }));
@@ -6,5 +6,5 @@ import type { ShapeStack } from "./ShapeStack.js";
6
6
  /**
7
7
  * Try to convert a shape to a compound type (intersection or union) using some heuristics.
8
8
  */
9
- export declare function transformShapeToAstCompoundType(this: ShapesGraphToAstTransformer, shape: input.Shape, shapeStack: ShapeStack): Either<Error, Maybe<Exclude<ast.Type, ast.PlaceholderType>>>;
9
+ export declare function transformShapeToAstCompoundType(this: ShapesGraphToAstTransformer, shape: input.Shape, shapeStack: ShapeStack): Either<Error, Maybe<ast.Type>>;
10
10
  //# sourceMappingURL=transformShapeToAstCompoundType.d.ts.map
@@ -2,25 +2,28 @@ import { Either, Left, Maybe } from "purify-ts";
2
2
  import { invariant } from "ts-invariant";
3
3
  import * as ast from "../ast/index.js";
4
4
  import { Eithers } from "../Eithers.js";
5
- import { transformShapeToAstAbstractTypeProperties } from "./transformShapeToAstAbstractTypeProperties.js";
5
+ import { nodeShapeTsFeatures } from "./nodeShapeTsFeatures.js";
6
+ import { shapeAstTypeName } from "./shapeAstTypeName.js";
7
+ import { transformShapeToAstType } from "./transformShapeToAstType.js";
6
8
  /**
7
9
  * Try to convert a shape to a compound type (intersection or union) using some heuristics.
8
10
  */
9
11
  export function transformShapeToAstCompoundType(shape, shapeStack) {
10
12
  shapeStack.push(shape);
11
13
  try {
12
- return Eithers.chain3(shape.constraints.and, shape.constraints.nodes, shape.constraints.xone).chain(([andConstraintShapes, nodeConstraintShapes, xoneConstraintShapes]) => {
14
+ return Eithers.chain4(shape.constraints.and, shape.constraints.nodes, shape.kind === "NodeShape"
15
+ ? nodeShapeTsFeatures.call(this, shape)
16
+ : Either.of(new Set()), shape.constraints.xone).chain(([andConstraintShapes, nodeConstraintShapes, tsFeatures, xoneConstraintShapes,]) => {
13
17
  let compoundTypeKind;
14
18
  // Distinguish constraints that take arbitrary shapes from those that only take node shapes
15
19
  // With the latter we'll do special transformations.
16
20
  let memberShapes;
17
- let memberNodeShapes;
18
21
  if (andConstraintShapes.length > 0) {
19
22
  memberShapes = andConstraintShapes;
20
23
  compoundTypeKind = "IntersectionType";
21
24
  }
22
25
  else if (nodeConstraintShapes.length > 0) {
23
- memberNodeShapes = nodeConstraintShapes;
26
+ memberShapes = nodeConstraintShapes;
24
27
  compoundTypeKind = "IntersectionType";
25
28
  }
26
29
  else if (xoneConstraintShapes.length > 0) {
@@ -30,107 +33,58 @@ export function transformShapeToAstCompoundType(shape, shapeStack) {
30
33
  else {
31
34
  return Either.of(Maybe.empty());
32
35
  }
33
- const memberDiscriminantValues = [];
34
- const memberTypes = [];
35
- if (memberNodeShapes) {
36
- invariant(memberNodeShapes.length > 0);
37
- invariant(!memberShapes);
38
- for (const memberNodeShape of memberNodeShapes) {
39
- const memberTypeEither = this.transformNodeShapeToAstType(memberNodeShape);
40
- if (memberTypeEither.isLeft()) {
41
- return memberTypeEither;
42
- }
43
- memberTypes.push(memberTypeEither.unsafeCoerce());
44
- if (compoundTypeKind === "UnionType") {
45
- const memberDiscriminantValue = memberNodeShape.discriminantValue.extract();
46
- if (memberDiscriminantValue) {
47
- memberDiscriminantValues.push(memberDiscriminantValue);
48
- }
49
- else if (memberDiscriminantValues.length > 0) {
50
- return Left(new Error(`${shape} does not have a discriminant value while the other members of the compound type do`));
51
- }
52
- }
53
- }
36
+ invariant(memberShapes.length > 0);
37
+ const memberDiscriminantValues = new Set();
38
+ const compoundType = new (compoundTypeKind === "IntersectionType"
39
+ ? ast.IntersectionType
40
+ : ast.UnionType)({
41
+ comment: shape.comment,
42
+ label: shape.label,
43
+ name: shapeAstTypeName(shape),
44
+ shapeIdentifier: shape.identifier,
45
+ tsFeatures,
46
+ });
47
+ if (memberShapes.length === 1) {
48
+ return transformShapeToAstType
49
+ .call(this, memberShapes[0], shapeStack)
50
+ .map(Maybe.of);
54
51
  }
55
- else if (memberShapes) {
56
- invariant(memberShapes.length > 0);
57
- for (const memberShape of memberShapes) {
58
- const memberTypeEither = this.transformShapeToAstType(memberShape, shapeStack);
59
- if (memberTypeEither.isLeft()) {
60
- return memberTypeEither;
52
+ // Put a placeholder in the cache to deal with cyclic references
53
+ this.cachedAstTypesByShapeIdentifier.set(shape.identifier, compoundType);
54
+ return Either.sequence(memberShapes.map((memberShape) => transformShapeToAstType.call(this, memberShape, shapeStack)))
55
+ .chain((memberShapeTypes) => {
56
+ for (let memberI = 0; memberI < memberShapes.length; memberI++) {
57
+ const memberShape = memberShapes[memberI];
58
+ const memberType = memberShapeTypes[memberI];
59
+ if (!ast.IntersectionType.isMemberType(memberType)) {
60
+ return Left(new Error(`${shape} has an invalid member type kind "${memberType.kind}"`));
61
61
  }
62
- memberTypes.push(memberTypeEither.unsafeCoerce());
62
+ if (memberI > 0 &&
63
+ compoundType.members.some((existingMember) => ast.Type.equals(memberType, existingMember.type))) {
64
+ return Left(new Error(`${shape} has duplicate ${compoundTypeKind} member type: ${memberType}`));
65
+ }
66
+ let memberDiscriminantValue;
63
67
  if (compoundTypeKind === "UnionType") {
64
- let memberDiscriminantValue;
65
68
  if (memberShape.kind === "NodeShape") {
66
69
  memberDiscriminantValue =
67
70
  memberShape.discriminantValue.extract();
68
71
  }
69
72
  if (memberDiscriminantValue) {
70
- if (memberDiscriminantValues.includes(memberDiscriminantValue)) {
73
+ if (memberDiscriminantValues.has(memberDiscriminantValue)) {
71
74
  return Left(new Error(`${shape} member ${memberShape} has a duplicate discriminant value: ${memberDiscriminantValue}`));
72
75
  }
73
- memberDiscriminantValues.push(memberDiscriminantValue);
74
- }
75
- else if (memberDiscriminantValues.length > 0) {
76
- return Left(new Error(`${shape} member ${memberShape} does not have a discriminant value while the other members of the compound type do`));
76
+ memberDiscriminantValues.add(memberDiscriminantValue);
77
77
  }
78
78
  }
79
- }
80
- }
81
- else {
82
- invariant(false);
83
- }
84
- if (memberTypes.length === 1) {
85
- return Either.of(Maybe.of(memberTypes[0]));
86
- }
87
- return transformShapeToAstAbstractTypeProperties(shape).chain((astAbstractTypeProperties) => {
88
- // If every member type is an ObjectType, ObjectIntersectionType, or ObjectUnionType (the latter of which can be flattened to ObjectTypes),
89
- // produce a different AST type (ObjectIntersectionType or ObjectUnionType).
90
- if (memberTypes.every((memberType) => {
91
- switch (memberType.kind) {
92
- case "ObjectType":
93
- case "ObjectIntersectionType":
94
- case "ObjectUnionType":
95
- return true;
96
- default:
97
- return false;
98
- }
99
- })) {
100
- const compoundType = new (compoundTypeKind === "IntersectionType"
101
- ? ast.ObjectIntersectionType
102
- : ast.ObjectUnionType)({
103
- ...astAbstractTypeProperties,
104
- export_: true,
105
- name: shape.shaclmateName,
106
- shapeIdentifier: this.shapeIdentifier(shape),
107
- tsFeatures: this.tsFeaturesDefault,
79
+ compoundType.addMember({
80
+ discriminantValue: Maybe.fromNullable(memberDiscriminantValue),
81
+ type: memberType,
108
82
  });
109
- for (const memberType of memberTypes) {
110
- const addMemberTypeResult = compoundType.addMemberType(memberType);
111
- if (addMemberTypeResult.isLeft()) {
112
- return addMemberTypeResult;
113
- }
114
- }
115
- }
116
- // Compound type doesn't solely consist of ObjectTypes
117
- switch (compoundTypeKind) {
118
- case "IntersectionType":
119
- return Either.of(Maybe.of(new ast.IntersectionType({
120
- ...astAbstractTypeProperties,
121
- memberTypes,
122
- })));
123
- case "UnionType":
124
- if (memberDiscriminantValues.length > 0 &&
125
- memberDiscriminantValues.length !== memberTypes.length) {
126
- return Left(new Error(`${shape} has members without discriminant values`));
127
- }
128
- return Either.of(Maybe.of(new ast.UnionType({
129
- ...astAbstractTypeProperties,
130
- memberDiscriminantValues,
131
- memberTypes,
132
- })));
133
83
  }
84
+ return Either.of(Maybe.of(compoundType));
85
+ })
86
+ .ifLeft(() => {
87
+ this.cachedAstTypesByShapeIdentifier.delete(shape.identifier);
134
88
  });
135
89
  });
136
90
  }
@@ -0,0 +1,11 @@
1
+ import { Either, Maybe } from "purify-ts";
2
+ import * as ast from "../ast/index.js";
3
+ import type * as input from "../input/index.js";
4
+ import type { ShapesGraphToAstTransformer } from "../ShapesGraphToAstTransformer.js";
5
+ import type { ShapeStack } from "./ShapeStack.js";
6
+ /**
7
+ * Is an ast.ObjectType actually the shape of an RDF list?
8
+ * If so, return the type of its rdf:first.
9
+ */
10
+ export declare function transformShapeToAstListType(this: ShapesGraphToAstTransformer, shape: input.Shape, shapeStack: ShapeStack): Either<Error, Maybe<ast.ListType>>;
11
+ //# sourceMappingURL=transformShapeToAstListType.d.ts.map