@shaclmate/compiler 4.0.8 → 4.0.10

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 (372) 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 +5 -5
  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 +17 -15
  59. package/dist/generators/ts/AbstractCollectionType.d.ts +1 -1
  60. package/dist/generators/ts/AbstractCollectionType.js +10 -12
  61. package/dist/generators/ts/AbstractContainerType.d.ts +9 -4
  62. package/dist/generators/ts/AbstractContainerType.js +10 -3
  63. package/dist/generators/ts/AbstractDateType.d.ts +2 -2
  64. package/dist/generators/ts/AbstractDateType.js +2 -2
  65. package/dist/generators/ts/AbstractIdentifierType.d.ts +1 -1
  66. package/dist/generators/ts/AbstractIdentifierType.js +1 -1
  67. package/dist/generators/ts/AbstractLazyObjectType.d.ts +13 -10
  68. package/dist/generators/ts/AbstractLazyObjectType.js +21 -16
  69. package/dist/generators/ts/AbstractNamedUnionType.d.ts +33 -0
  70. package/dist/generators/ts/AbstractNamedUnionType.js +195 -0
  71. package/dist/generators/ts/AbstractNumericType.d.ts +3 -3
  72. package/dist/generators/ts/AbstractNumericType.js +4 -4
  73. package/dist/generators/ts/AbstractTermType.d.ts +7 -4
  74. package/dist/generators/ts/AbstractTermType.js +7 -4
  75. package/dist/generators/ts/AbstractType.d.ts +34 -19
  76. package/dist/generators/ts/AbstractUnionType.d.ts +80 -0
  77. package/dist/generators/ts/AbstractUnionType.js +514 -0
  78. package/dist/generators/ts/AnonymousUnionType.d.ts +26 -0
  79. package/dist/generators/ts/AnonymousUnionType.js +56 -0
  80. package/dist/generators/ts/BigDecimalType.d.ts +4 -4
  81. package/dist/generators/ts/BigDecimalType.js +5 -5
  82. package/dist/generators/ts/BigIntType.d.ts +1 -1
  83. package/dist/generators/ts/BigIntType.js +1 -1
  84. package/dist/generators/ts/BlankNodeType.d.ts +2 -2
  85. package/dist/generators/ts/BlankNodeType.js +2 -2
  86. package/dist/generators/ts/BooleanType.d.ts +3 -3
  87. package/dist/generators/ts/BooleanType.js +3 -3
  88. package/dist/generators/ts/DateTimeType.d.ts +1 -1
  89. package/dist/generators/ts/DateTimeType.js +1 -1
  90. package/dist/generators/ts/DateType.d.ts +1 -1
  91. package/dist/generators/ts/DateType.js +1 -1
  92. package/dist/generators/ts/DefaultValueType.d.ts +5 -5
  93. package/dist/generators/ts/DefaultValueType.js +17 -16
  94. package/dist/generators/ts/IdentifierType.d.ts +2 -2
  95. package/dist/generators/ts/IdentifierType.js +2 -2
  96. package/dist/generators/ts/IriType.d.ts +2 -2
  97. package/dist/generators/ts/IriType.js +2 -2
  98. package/dist/generators/ts/LazyObjectOptionType.d.ts +1 -1
  99. package/dist/generators/ts/LazyObjectOptionType.js +10 -10
  100. package/dist/generators/ts/LazyObjectSetType.d.ts +1 -1
  101. package/dist/generators/ts/LazyObjectSetType.js +8 -8
  102. package/dist/generators/ts/LazyObjectType.d.ts +1 -1
  103. package/dist/generators/ts/LazyObjectType.js +9 -10
  104. package/dist/generators/ts/ListType.d.ts +9 -8
  105. package/dist/generators/ts/ListType.js +15 -14
  106. package/dist/generators/ts/LiteralType.d.ts +2 -2
  107. package/dist/generators/ts/LiteralType.js +3 -3
  108. package/dist/generators/ts/NamedObjectType.d.ts +126 -0
  109. package/dist/generators/ts/NamedObjectType.js +420 -0
  110. package/dist/generators/ts/NamedObjectUnionType.d.ts +35 -0
  111. package/dist/generators/ts/NamedObjectUnionType.js +217 -0
  112. package/dist/generators/ts/NamedUnionType.d.ts +11 -0
  113. package/dist/generators/ts/NamedUnionType.js +13 -0
  114. package/dist/generators/ts/OptionType.d.ts +5 -5
  115. package/dist/generators/ts/OptionType.js +12 -12
  116. package/dist/generators/ts/SetType.d.ts +4 -4
  117. package/dist/generators/ts/SetType.js +13 -11
  118. package/dist/generators/ts/StringType.d.ts +3 -3
  119. package/dist/generators/ts/StringType.js +3 -3
  120. package/dist/generators/ts/TermType.d.ts +2 -2
  121. package/dist/generators/ts/TermType.js +3 -3
  122. package/dist/generators/ts/TsGenerator.js +28 -20
  123. package/dist/generators/ts/Type.d.ts +5 -4
  124. package/dist/generators/ts/TypeFactory.d.ts +9 -7
  125. package/dist/generators/ts/TypeFactory.js +139 -112
  126. package/dist/generators/ts/ZodGenerator.js +18 -16
  127. package/dist/generators/ts/{_ObjectType → _NamedObjectType}/AbstractProperty.d.ts +9 -9
  128. package/dist/generators/ts/{_ObjectType → _NamedObjectType}/AbstractProperty.js +3 -3
  129. package/dist/generators/ts/{_ObjectType/TypeDiscriminantProperty.d.ts → _NamedObjectType/DiscriminantProperty.d.ts} +14 -14
  130. package/dist/generators/ts/{_ObjectType/TypeDiscriminantProperty.js → _NamedObjectType/DiscriminantProperty.js} +22 -20
  131. package/dist/generators/ts/{_ObjectType → _NamedObjectType}/IdentifierPrefixProperty.d.ts +3 -3
  132. package/dist/generators/ts/{_ObjectType → _NamedObjectType}/IdentifierPrefixProperty.js +6 -6
  133. package/dist/generators/ts/{_ObjectType → _NamedObjectType}/IdentifierProperty.d.ts +3 -3
  134. package/dist/generators/ts/{_ObjectType → _NamedObjectType}/IdentifierProperty.js +31 -28
  135. package/dist/generators/ts/_NamedObjectType/NamedObjectType_classDeclaration.d.ts +4 -0
  136. package/dist/generators/ts/{_ObjectType/ObjectType_classDeclaration.js → _NamedObjectType/NamedObjectType_classDeclaration.js} +15 -15
  137. package/dist/generators/ts/_NamedObjectType/NamedObjectType_createFunctionDeclaration.d.ts +5 -0
  138. package/dist/generators/ts/{_ObjectType/ObjectType_createFunctionDeclaration.js → _NamedObjectType/NamedObjectType_createFunctionDeclaration.js} +2 -2
  139. package/dist/generators/ts/_NamedObjectType/NamedObjectType_equalsFunctionOrMethodDeclaration.d.ts +5 -0
  140. package/dist/generators/ts/{_ObjectType/ObjectType_equalsFunctionOrMethodDeclaration.js → _NamedObjectType/NamedObjectType_equalsFunctionOrMethodDeclaration.js} +2 -2
  141. package/dist/generators/ts/_NamedObjectType/NamedObjectType_filterFunctionDeclaration.d.ts +4 -0
  142. package/dist/generators/ts/{_ObjectType/ObjectType_filterFunctionDeclaration.js → _NamedObjectType/NamedObjectType_filterFunctionDeclaration.js} +2 -2
  143. package/dist/generators/ts/_NamedObjectType/NamedObjectType_filterTypeDeclaration.d.ts +4 -0
  144. package/dist/generators/ts/{_ObjectType/ObjectType_filterTypeDeclaration.js → _NamedObjectType/NamedObjectType_filterTypeDeclaration.js} +2 -2
  145. package/dist/generators/ts/_NamedObjectType/NamedObjectType_focusSparqlConstructTriplesFunctionDeclaration.d.ts +5 -0
  146. package/dist/generators/ts/{_ObjectType/ObjectType_sparqlConstructTriplesFunctionDeclaration.js → _NamedObjectType/NamedObjectType_focusSparqlConstructTriplesFunctionDeclaration.js} +6 -5
  147. package/dist/generators/ts/_NamedObjectType/NamedObjectType_focusSparqlWherePatternsFunctionDeclaration.d.ts +5 -0
  148. package/dist/generators/ts/{_ObjectType/ObjectType_sparqlWherePatternsFunctionDeclarations.js → _NamedObjectType/NamedObjectType_focusSparqlWherePatternsFunctionDeclaration.js} +5 -5
  149. package/dist/generators/ts/_NamedObjectType/NamedObjectType_fromJsonFunctionDeclaration.d.ts +5 -0
  150. package/dist/generators/ts/_NamedObjectType/NamedObjectType_fromJsonFunctionDeclaration.js +20 -0
  151. package/dist/generators/ts/_NamedObjectType/NamedObjectType_fromRdfResourceFunctionDeclaration.d.ts +5 -0
  152. package/dist/generators/ts/{_ObjectType/ObjectType_fromRdfFunctionDeclaration.js → _NamedObjectType/NamedObjectType_fromRdfResourceFunctionDeclaration.js} +6 -7
  153. package/dist/generators/ts/_NamedObjectType/NamedObjectType_fromRdfResourceValuesFunctionDeclaration.d.ts +5 -0
  154. package/dist/generators/ts/_NamedObjectType/NamedObjectType_fromRdfResourceValuesFunctionDeclaration.js +20 -0
  155. package/dist/generators/ts/_NamedObjectType/NamedObjectType_fromRdfTypeVariableStatement.d.ts +5 -0
  156. package/dist/generators/ts/{_ObjectType/ObjectType_fromRdfTypeVariableStatement.js → _NamedObjectType/NamedObjectType_fromRdfTypeVariableStatement.js} +2 -2
  157. package/dist/generators/ts/_NamedObjectType/NamedObjectType_graphqlTypeVariableStatement.d.ts +5 -0
  158. package/dist/generators/ts/{_ObjectType/ObjectType_graphqlTypeVariableStatement.js → _NamedObjectType/NamedObjectType_graphqlTypeVariableStatement.js} +2 -2
  159. package/dist/generators/ts/_NamedObjectType/NamedObjectType_hashFunctionOrMethodDeclarations.d.ts +4 -0
  160. package/dist/generators/ts/{_ObjectType/ObjectType_hashFunctionOrMethodDeclarations.js → _NamedObjectType/NamedObjectType_hashFunctionOrMethodDeclarations.js} +2 -2
  161. package/dist/generators/ts/_NamedObjectType/NamedObjectType_interfaceDeclaration.d.ts +4 -0
  162. package/dist/generators/ts/{_ObjectType/ObjectType_interfaceDeclaration.js → _NamedObjectType/NamedObjectType_interfaceDeclaration.js} +2 -2
  163. package/dist/generators/ts/_NamedObjectType/NamedObjectType_isTypeFunctionDeclaration.d.ts +4 -0
  164. package/dist/generators/ts/{_ObjectType/ObjectType_isTypeFunctionDeclaration.js → _NamedObjectType/NamedObjectType_isTypeFunctionDeclaration.js} +4 -4
  165. package/dist/generators/ts/_NamedObjectType/NamedObjectType_jsonParseFunctionDeclaration.d.ts +5 -0
  166. package/dist/generators/ts/_NamedObjectType/NamedObjectType_jsonParseFunctionDeclaration.js +19 -0
  167. package/dist/generators/ts/_NamedObjectType/NamedObjectType_jsonSchemaFunctionDeclaration.d.ts +5 -0
  168. package/dist/generators/ts/{_ObjectType/ObjectType_jsonZodSchemaFunctionDeclaration.js → _NamedObjectType/NamedObjectType_jsonSchemaFunctionDeclaration.js} +5 -5
  169. package/dist/generators/ts/_NamedObjectType/NamedObjectType_jsonTypeAliasDeclaration.d.ts +5 -0
  170. package/dist/generators/ts/{_ObjectType/ObjectType_jsonTypeAliasDeclaration.js → _NamedObjectType/NamedObjectType_jsonTypeAliasDeclaration.js} +2 -2
  171. package/dist/generators/ts/_NamedObjectType/NamedObjectType_jsonUiSchemaFunctionDeclaration.d.ts +5 -0
  172. package/dist/generators/ts/{_ObjectType/ObjectType_jsonUiSchemaFunctionDeclaration.js → _NamedObjectType/NamedObjectType_jsonUiSchemaFunctionDeclaration.js} +4 -4
  173. package/dist/generators/ts/_NamedObjectType/NamedObjectType_objectSetMethodNames.d.ts +9 -0
  174. package/dist/generators/ts/{_ObjectType/ObjectType_objectSetMethodNames.js → _NamedObjectType/NamedObjectType_objectSetMethodNames.js} +2 -2
  175. package/dist/generators/ts/_NamedObjectType/NamedObjectType_propertiesFromJsonFunctionDeclaration.d.ts +5 -0
  176. package/dist/generators/ts/_NamedObjectType/NamedObjectType_propertiesFromJsonFunctionDeclaration.js +38 -0
  177. package/dist/generators/ts/_NamedObjectType/NamedObjectType_propertiesFromRdfResourceFunctionDeclaration.d.ts +5 -0
  178. package/dist/generators/ts/{_ObjectType/ObjectType_propertiesFromRdfFunctionDeclaration.js → _NamedObjectType/NamedObjectType_propertiesFromRdfResourceFunctionDeclaration.js} +16 -15
  179. package/dist/generators/ts/_NamedObjectType/NamedObjectType_schemaVariableStatement.d.ts +4 -0
  180. package/dist/generators/ts/{_ObjectType/ObjectType_schemaVariableStatement.js → _NamedObjectType/NamedObjectType_schemaVariableStatement.js} +3 -4
  181. package/dist/generators/ts/{_ObjectType/ObjectType_sparqlConstructQueryFunctionDeclaration.d.ts → _NamedObjectType/NamedObjectType_sparqlConstructQueryFunctionDeclaration.d.ts} +2 -2
  182. package/dist/generators/ts/{_ObjectType/ObjectType_sparqlConstructQueryFunctionDeclaration.js → _NamedObjectType/NamedObjectType_sparqlConstructQueryFunctionDeclaration.js} +4 -4
  183. package/dist/generators/ts/{_ObjectType/ObjectType_sparqlConstructQueryStringFunctionDeclaration.d.ts → _NamedObjectType/NamedObjectType_sparqlConstructQueryStringFunctionDeclaration.d.ts} +2 -2
  184. package/dist/generators/ts/{_ObjectType/ObjectType_sparqlConstructQueryStringFunctionDeclaration.js → _NamedObjectType/NamedObjectType_sparqlConstructQueryStringFunctionDeclaration.js} +2 -2
  185. package/dist/generators/ts/_NamedObjectType/NamedObjectType_toJsonFunctionOrMethodDeclaration.d.ts +5 -0
  186. package/dist/generators/ts/{_ObjectType/ObjectType_toJsonFunctionOrMethodDeclaration.js → _NamedObjectType/NamedObjectType_toJsonFunctionOrMethodDeclaration.js} +2 -2
  187. package/dist/generators/ts/_NamedObjectType/NamedObjectType_toRdfResourceFunctionOrMethodDeclaration.d.ts +5 -0
  188. package/dist/generators/ts/{_ObjectType/ObjectType_toRdfFunctionOrMethodDeclaration.js → _NamedObjectType/NamedObjectType_toRdfResourceFunctionOrMethodDeclaration.js} +10 -8
  189. package/dist/generators/ts/_NamedObjectType/NamedObjectType_valueSparqlConstructTriplesFunctionDeclaration.d.ts +5 -0
  190. package/dist/generators/ts/_NamedObjectType/NamedObjectType_valueSparqlConstructTriplesFunctionDeclaration.js +13 -0
  191. package/dist/generators/ts/_NamedObjectType/NamedObjectType_valueSparqlWherePatternsFunctionDeclaration.d.ts +5 -0
  192. package/dist/generators/ts/_NamedObjectType/NamedObjectType_valueSparqlWherePatternsFunctionDeclaration.js +15 -0
  193. package/dist/generators/ts/{_ObjectType → _NamedObjectType}/Property.d.ts +2 -2
  194. package/dist/generators/ts/{_ObjectType → _NamedObjectType}/ShaclProperty.d.ts +3 -3
  195. package/dist/generators/ts/{_ObjectType → _NamedObjectType}/ShaclProperty.js +14 -14
  196. package/dist/generators/ts/_NamedObjectType/identifierTypeDeclarations.d.ts +4 -0
  197. package/dist/generators/ts/_snippets/snippets_FocusSparqlConstructTriplesFunction.d.ts +2 -0
  198. package/dist/generators/ts/_snippets/snippets_FocusSparqlConstructTriplesFunction.js +12 -0
  199. package/dist/generators/ts/_snippets/snippets_FocusSparqlWherePatternsFunction.d.ts +2 -0
  200. package/dist/generators/ts/_snippets/snippets_FocusSparqlWherePatternsFunction.js +14 -0
  201. package/dist/generators/ts/_snippets/snippets_FromRdfResourceFunction.d.ts +2 -0
  202. package/dist/generators/ts/_snippets/snippets_FromRdfResourceFunction.js +15 -0
  203. package/dist/generators/ts/_snippets/snippets_FromRdfResourceValuesFunction.d.ts +2 -0
  204. package/dist/generators/ts/_snippets/snippets_FromRdfResourceValuesFunction.js +17 -0
  205. package/dist/generators/ts/_snippets/snippets_PropertiesFromRdfResourceFunction.d.ts +2 -0
  206. package/dist/generators/ts/_snippets/snippets_PropertiesFromRdfResourceFunction.js +15 -0
  207. package/dist/generators/ts/_snippets/snippets_PropertyPath.d.ts +5 -0
  208. package/dist/generators/ts/_snippets/snippets_PropertyPath.js +35 -0
  209. package/dist/generators/ts/_snippets/snippets_ShaclPropertySchema.js +2 -2
  210. package/dist/generators/ts/_snippets/snippets_ToRdfResourceFunction.d.ts +2 -0
  211. package/dist/generators/ts/_snippets/snippets_ToRdfResourceFunction.js +7 -0
  212. package/dist/generators/ts/_snippets/snippets_ToRdfResourceValuesFunction.d.ts +2 -0
  213. package/dist/generators/ts/_snippets/snippets_ToRdfResourceValuesFunction.js +16 -0
  214. package/dist/generators/ts/_snippets/snippets_ValueSparqlConstructTriplesFunction.d.ts +2 -0
  215. package/dist/generators/ts/_snippets/snippets_ValueSparqlConstructTriplesFunction.js +13 -0
  216. package/dist/generators/ts/_snippets/snippets_ValueSparqlWherePatternsFunction.d.ts +2 -0
  217. package/dist/generators/ts/_snippets/snippets_ValueSparqlWherePatternsFunction.js +16 -0
  218. package/dist/generators/ts/_snippets/snippets_bigDecimalSparqlWherePatterns.js +2 -2
  219. package/dist/generators/ts/_snippets/snippets_blankNodeSparqlWherePatterns.js +2 -2
  220. package/dist/generators/ts/_snippets/snippets_booleanEquals.js +1 -1
  221. package/dist/generators/ts/_snippets/snippets_booleanSparqlWherePatterns.js +2 -2
  222. package/dist/generators/ts/_snippets/snippets_dateSparqlWherePatterns.js +2 -2
  223. package/dist/generators/ts/_snippets/snippets_defaultValueSparqlWherePatterns.js +2 -2
  224. package/dist/generators/ts/_snippets/snippets_fromRdfLanguageIn.js +1 -1
  225. package/dist/generators/ts/_snippets/snippets_identifierSparqlWherePatterns.js +2 -2
  226. package/dist/generators/ts/_snippets/snippets_iriSparqlWherePatterns.js +2 -2
  227. package/dist/generators/ts/_snippets/snippets_listSparqlConstructTriples.js +2 -2
  228. package/dist/generators/ts/_snippets/snippets_listSparqlWherePatterns.js +2 -2
  229. package/dist/generators/ts/_snippets/snippets_literalSparqlWherePatterns.js +2 -2
  230. package/dist/generators/ts/_snippets/snippets_maybeSparqlConstructTriples.js +2 -2
  231. package/dist/generators/ts/_snippets/snippets_maybeSparqlWherePatterns.js +2 -2
  232. package/dist/generators/ts/_snippets/snippets_numericSparqlWherePatterns.js +2 -3
  233. package/dist/generators/ts/_snippets/snippets_setSparqlConstructTriples.js +2 -2
  234. package/dist/generators/ts/_snippets/snippets_setSparqlWherePatterns.js +2 -2
  235. package/dist/generators/ts/_snippets/snippets_shaclPropertySparqlConstructTriples.js +4 -3
  236. package/dist/generators/ts/_snippets/snippets_shaclPropertySparqlWherePatterns.js +4 -3
  237. package/dist/generators/ts/_snippets/snippets_sparqlPropertyPath.js +3 -2
  238. package/dist/generators/ts/_snippets/snippets_stringSparqlWherePatterns.js +2 -2
  239. package/dist/generators/ts/_snippets/snippets_termSparqlWherePatterns.js +2 -2
  240. package/dist/generators/ts/graphqlSchemaVariableStatement.d.ts +4 -4
  241. package/dist/generators/ts/graphqlSchemaVariableStatement.js +25 -25
  242. package/dist/generators/ts/imports.d.ts +1 -1
  243. package/dist/generators/ts/imports.js +1 -1
  244. package/dist/generators/ts/objectSetDeclarations.d.ts +5 -5
  245. package/dist/generators/ts/objectSetDeclarations.js +34 -31
  246. package/dist/generators/ts/objectSetInterfaceDeclaration.d.ts +5 -5
  247. package/dist/generators/ts/objectSetInterfaceDeclaration.js +6 -4
  248. package/dist/generators/ts/objectSetMethodSignatures.d.ts +4 -4
  249. package/dist/generators/ts/objectSetMethodSignatures.js +9 -9
  250. package/dist/generators/ts/rdfjsDatasetObjectSetClassDeclaration.d.ts +5 -5
  251. package/dist/generators/ts/rdfjsDatasetObjectSetClassDeclaration.js +54 -53
  252. package/dist/generators/ts/singleEntryRecord.d.ts +2 -0
  253. package/dist/generators/ts/singleEntryRecord.js +6 -0
  254. package/dist/generators/ts/snippets.d.ts +10 -6
  255. package/dist/generators/ts/snippets.js +20 -12
  256. package/dist/generators/ts/sparqlObjectSetClassDeclaration.d.ts +5 -5
  257. package/dist/generators/ts/sparqlObjectSetClassDeclaration.js +19 -20
  258. package/dist/generators/ts/synthesizeUberObjectUnionType.d.ts +4 -4
  259. package/dist/generators/ts/synthesizeUberObjectUnionType.js +14 -9
  260. package/dist/generators/ts/unsupportedObjectSetMethodDeclarations.d.ts +5 -5
  261. package/dist/generators/ts/unsupportedObjectSetMethodDeclarations.js +2 -2
  262. package/dist/input/NodeShape.d.ts +0 -1
  263. package/dist/input/NodeShape.js +0 -3
  264. package/dist/input/ShapesGraph.d.ts +3 -2
  265. package/dist/input/ShapesGraph.js +12 -7
  266. package/dist/input/generated.d.ts +1899 -88
  267. package/dist/input/generated.js +676 -564
  268. package/package.json +5 -7
  269. package/dist/_ShapesGraphToAstTransformer/CurieFactory.d.ts +0 -16
  270. package/dist/_ShapesGraphToAstTransformer/CurieFactory.js +0 -45
  271. package/dist/_ShapesGraphToAstTransformer/NodeShapeAstType.d.ts +0 -3
  272. package/dist/_ShapesGraphToAstTransformer/NodeShapeAstType.js +0 -2
  273. package/dist/_ShapesGraphToAstTransformer/index.d.ts +0 -6
  274. package/dist/_ShapesGraphToAstTransformer/index.js +0 -6
  275. package/dist/_ShapesGraphToAstTransformer/shapeIdentifier.d.ts +0 -5
  276. package/dist/_ShapesGraphToAstTransformer/shapeIdentifier.js +0 -9
  277. package/dist/_ShapesGraphToAstTransformer/transformNodeShapeToAstType.d.ts +0 -11
  278. package/dist/_ShapesGraphToAstTransformer/transformNodeShapeToAstType.js +0 -338
  279. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstAbstractTypeProperties.d.ts +0 -12
  280. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstAbstractTypeProperties.js +0 -31
  281. package/dist/ast/AbstractObjectCompoundType.d.ts +0 -45
  282. package/dist/ast/AbstractObjectCompoundType.js +0 -180
  283. package/dist/ast/Curie.d.ts +0 -21
  284. package/dist/ast/Curie.js +0 -29
  285. package/dist/ast/PlaceholderType.d.ts +0 -15
  286. package/dist/ast/PlaceholderType.js +0 -19
  287. package/dist/generators/codeName.d.ts +0 -6
  288. package/dist/generators/codeName.js +0 -66
  289. package/dist/generators/ts/AbstractDeclaredType.d.ts +0 -23
  290. package/dist/generators/ts/AbstractDeclaredType.js +0 -17
  291. package/dist/generators/ts/ObjectType.d.ts +0 -117
  292. package/dist/generators/ts/ObjectType.js +0 -402
  293. package/dist/generators/ts/ObjectUnionType.d.ts +0 -65
  294. package/dist/generators/ts/ObjectUnionType.js +0 -257
  295. package/dist/generators/ts/UnionType.d.ts +0 -40
  296. package/dist/generators/ts/UnionType.js +0 -527
  297. package/dist/generators/ts/_ObjectType/ObjectType_classDeclaration.d.ts +0 -4
  298. package/dist/generators/ts/_ObjectType/ObjectType_createFunctionDeclaration.d.ts +0 -5
  299. package/dist/generators/ts/_ObjectType/ObjectType_equalsFunctionOrMethodDeclaration.d.ts +0 -5
  300. package/dist/generators/ts/_ObjectType/ObjectType_filterFunctionDeclaration.d.ts +0 -4
  301. package/dist/generators/ts/_ObjectType/ObjectType_filterTypeDeclaration.d.ts +0 -4
  302. package/dist/generators/ts/_ObjectType/ObjectType_fromJsonFunctionDeclarations.d.ts +0 -4
  303. package/dist/generators/ts/_ObjectType/ObjectType_fromJsonFunctionDeclarations.js +0 -66
  304. package/dist/generators/ts/_ObjectType/ObjectType_fromRdfFunctionDeclaration.d.ts +0 -5
  305. package/dist/generators/ts/_ObjectType/ObjectType_fromRdfTypeVariableStatement.d.ts +0 -5
  306. package/dist/generators/ts/_ObjectType/ObjectType_graphqlTypeVariableStatement.d.ts +0 -5
  307. package/dist/generators/ts/_ObjectType/ObjectType_hashFunctionOrMethodDeclarations.d.ts +0 -4
  308. package/dist/generators/ts/_ObjectType/ObjectType_interfaceDeclaration.d.ts +0 -4
  309. package/dist/generators/ts/_ObjectType/ObjectType_isTypeFunctionDeclaration.d.ts +0 -4
  310. package/dist/generators/ts/_ObjectType/ObjectType_jsonSchemaFunctionDeclaration.d.ts +0 -5
  311. package/dist/generators/ts/_ObjectType/ObjectType_jsonSchemaFunctionDeclaration.js +0 -14
  312. package/dist/generators/ts/_ObjectType/ObjectType_jsonTypeAliasDeclaration.d.ts +0 -5
  313. package/dist/generators/ts/_ObjectType/ObjectType_jsonUiSchemaFunctionDeclaration.d.ts +0 -5
  314. package/dist/generators/ts/_ObjectType/ObjectType_jsonZodSchemaFunctionDeclaration.d.ts +0 -5
  315. package/dist/generators/ts/_ObjectType/ObjectType_objectSetMethodNames.d.ts +0 -9
  316. package/dist/generators/ts/_ObjectType/ObjectType_propertiesFromRdfFunctionDeclaration.d.ts +0 -5
  317. package/dist/generators/ts/_ObjectType/ObjectType_schemaVariableStatement.d.ts +0 -4
  318. package/dist/generators/ts/_ObjectType/ObjectType_sparqlConstructTriplesFunctionDeclaration.d.ts +0 -5
  319. package/dist/generators/ts/_ObjectType/ObjectType_sparqlWherePatternsFunctionDeclarations.d.ts +0 -5
  320. package/dist/generators/ts/_ObjectType/ObjectType_toJsonFunctionOrMethodDeclaration.d.ts +0 -5
  321. package/dist/generators/ts/_ObjectType/ObjectType_toRdfFunctionOrMethodDeclaration.d.ts +0 -5
  322. package/dist/generators/ts/_ObjectType/identifierTypeDeclarations.d.ts +0 -4
  323. package/dist/generators/ts/_ObjectUnionType/MemberType.d.ts +0 -34
  324. package/dist/generators/ts/_ObjectUnionType/MemberType.js +0 -105
  325. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_equalsFunctionDeclaration.d.ts +0 -5
  326. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_equalsFunctionDeclaration.js +0 -29
  327. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_filterFunctionDeclaration.d.ts +0 -4
  328. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_filterFunctionDeclaration.js +0 -19
  329. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_filterTypeDeclaration.d.ts +0 -4
  330. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_filterTypeDeclaration.js +0 -10
  331. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_fromJsonFunctionDeclaration.d.ts +0 -5
  332. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_fromJsonFunctionDeclaration.js +0 -19
  333. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_fromRdfFunctionDeclarations.d.ts +0 -5
  334. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_fromRdfFunctionDeclarations.js +0 -20
  335. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_graphqlTypeVariableStatement.d.ts +0 -5
  336. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_graphqlTypeVariableStatement.js +0 -18
  337. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_hashFunctionDeclaration.d.ts +0 -5
  338. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_hashFunctionDeclaration.js +0 -28
  339. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_identifierTypeDeclarations.d.ts +0 -4
  340. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_identifierTypeDeclarations.js +0 -9
  341. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_isTypeFunctionDeclaration.d.ts +0 -5
  342. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_isTypeFunctionDeclaration.js +0 -13
  343. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_jsonTypeAliasDeclaration.d.ts +0 -5
  344. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_jsonTypeAliasDeclaration.js +0 -10
  345. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_jsonZodSchemaFunctionDeclaration.d.ts +0 -5
  346. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_jsonZodSchemaFunctionDeclaration.js +0 -14
  347. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_schemaVariableStatement.d.ts +0 -4
  348. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_schemaVariableStatement.js +0 -37
  349. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_sparqlConstructTriplesFunctionDeclaration.d.ts +0 -5
  350. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_sparqlConstructTriplesFunctionDeclaration.js +0 -15
  351. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_sparqlWherePatternsFunctionDeclaration.d.ts +0 -5
  352. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_sparqlWherePatternsFunctionDeclaration.js +0 -35
  353. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_toJsonFunctionDeclaration.d.ts +0 -5
  354. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_toJsonFunctionDeclaration.js +0 -26
  355. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_toRdfFunctionDeclarations.d.ts +0 -5
  356. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_toRdfFunctionDeclarations.js +0 -43
  357. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_typeAliasDeclaration.d.ts +0 -4
  358. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_typeAliasDeclaration.js +0 -10
  359. package/dist/generators/ts/_snippets/snippets_FromRdfOptions.d.ts +0 -2
  360. package/dist/generators/ts/_snippets/snippets_FromRdfOptions.js +0 -5
  361. package/dist/generators/ts/_snippets/snippets_PropertiesFromRdfParameters.d.ts +0 -2
  362. package/dist/generators/ts/_snippets/snippets_PropertiesFromRdfParameters.js +0 -5
  363. package/dist/generators/ts/_snippets/snippets_SparqlConstructTriplesFunction.d.ts +0 -2
  364. package/dist/generators/ts/_snippets/snippets_SparqlConstructTriplesFunction.js +0 -6
  365. package/dist/generators/ts/_snippets/snippets_SparqlConstructTriplesFunctionParameters.d.ts +0 -2
  366. package/dist/generators/ts/_snippets/snippets_SparqlConstructTriplesFunctionParameters.js +0 -12
  367. package/dist/generators/ts/_snippets/snippets_SparqlWherePatternsFunction.d.ts +0 -2
  368. package/dist/generators/ts/_snippets/snippets_SparqlWherePatternsFunction.js +0 -6
  369. package/dist/generators/ts/_snippets/snippets_SparqlWherePatternsFunctionParameters.d.ts +0 -2
  370. package/dist/generators/ts/_snippets/snippets_SparqlWherePatternsFunctionParameters.js +0 -15
  371. /package/dist/generators/ts/{_ObjectType → _NamedObjectType}/Property.js +0 -0
  372. /package/dist/generators/ts/{_ObjectType → _NamedObjectType}/identifierTypeDeclarations.js +0 -0
@@ -2,11 +2,13 @@ import TermMap from "@rdfjs/term-map";
2
2
  import TermSet from "@rdfjs/term-set";
3
3
  import base62 from "@sindresorhus/base62";
4
4
  import { rdf, xsd } from "@tpluscode/rdf-ns-builders";
5
+ import { Maybe } from "purify-ts";
5
6
  import { LiteralDecoder, literalDatatypeDefinitions } from "rdfjs-resource";
6
7
  import reservedTsIdentifiers_ from "reserved-identifiers";
7
8
  import { invariant } from "ts-invariant";
9
+ import * as ast from "../../ast/index.js";
8
10
  import { logger } from "../../logger.js";
9
- import { codeName } from "../codeName.js";
11
+ import { AnonymousUnionType } from "./AnonymousUnionType.js";
10
12
  import { BigDecimalType } from "./BigDecimalType.js";
11
13
  import { BigIntType } from "./BigIntType.js";
12
14
  import { BlankNodeType } from "./BlankNodeType.js";
@@ -23,31 +25,42 @@ import { LazyObjectSetType } from "./LazyObjectSetType.js";
23
25
  import { LazyObjectType } from "./LazyObjectType.js";
24
26
  import { ListType } from "./ListType.js";
25
27
  import { LiteralType } from "./LiteralType.js";
26
- import { ObjectType } from "./ObjectType.js";
27
- import { ObjectUnionType } from "./ObjectUnionType.js";
28
+ import { NamedObjectType } from "./NamedObjectType.js";
29
+ import { NamedObjectUnionType } from "./NamedObjectUnionType.js";
30
+ import { NamedUnionType } from "./NamedUnionType.js";
28
31
  import { OptionType } from "./OptionType.js";
29
32
  import { SetType } from "./SetType.js";
30
33
  import { StringType } from "./StringType.js";
31
34
  import { syntheticNamePrefix } from "./syntheticNamePrefix.js";
32
35
  import { TermType } from "./TermType.js";
33
36
  import { code } from "./ts-poet-wrapper.js";
34
- import { UnionType } from "./UnionType.js";
35
- const reservedTsIdentifiers = reservedTsIdentifiers_({
36
- includeGlobalProperties: true,
37
- });
38
- const tsName = codeName((value) => {
39
- // Adapted from https://github.com/sindresorhus/to-valid-identifier , MIT license
40
- if (reservedTsIdentifiers.has(value)) {
41
- // We prefix with underscore to avoid any potential conflicts with the Base62 encoded string.
42
- return `$_${value}$`;
43
- }
44
- return value.replaceAll(/\P{ID_Continue}/gu, (x) => `$${base62.encodeInteger(x.codePointAt(0))}$`);
45
- }, syntheticNamePrefix);
46
37
  export class TypeFactory {
38
+ cachedNamedObjectUnionTypesByShapeIdentifier = new TermMap();
47
39
  cachedObjectTypePropertiesByShapeIdentifier = new TermMap();
48
40
  cachedObjectTypesByShapeIdentifier = new TermMap();
49
- cachedObjectUnionTypesByShapeIdentifier = new TermMap();
50
- createObjectType(astType) {
41
+ createNamedObjectUnionType(astType) {
42
+ {
43
+ const cachedNamedObjectUnionType = this.cachedNamedObjectUnionTypesByShapeIdentifier.get(astType.shapeIdentifier);
44
+ if (cachedNamedObjectUnionType) {
45
+ return cachedNamedObjectUnionType;
46
+ }
47
+ }
48
+ const namedObjectUnionType = new NamedObjectUnionType({
49
+ comment: astType.comment,
50
+ features: astType.tsFeatures,
51
+ identifierType: this.createIdentifierType(ast.ObjectCompoundType.identifierType(astType)),
52
+ label: astType.label,
53
+ members: ast.ObjectCompoundType.memberObjectTypes(astType).map((namedObjectType) => ({
54
+ discriminantValue: Maybe.empty(),
55
+ type: this.createNamedObjectType(namedObjectType),
56
+ })),
57
+ name: tsName(astType.name.unsafeCoerce()),
58
+ recursive: astType.recursive,
59
+ });
60
+ this.cachedNamedObjectUnionTypesByShapeIdentifier.set(astType.shapeIdentifier, namedObjectUnionType);
61
+ return namedObjectUnionType;
62
+ }
63
+ createNamedObjectType(astType) {
51
64
  {
52
65
  const cachedObjectType = this.cachedObjectTypesByShapeIdentifier.get(astType.shapeIdentifier);
53
66
  if (cachedObjectType) {
@@ -55,25 +68,56 @@ export class TypeFactory {
55
68
  }
56
69
  }
57
70
  const identifierType = this.createIdentifierType(astType.identifierType);
58
- const staticModuleName = astType.childObjectTypes.length > 0
59
- ? `${tsName(astType)}Static`
60
- : tsName(astType);
61
- const objectType = new ObjectType({
71
+ const name = tsName(astType.name.unsafeCoerce(), {
72
+ synthetic: astType.synthetic,
73
+ });
74
+ const staticModuleName = astType.childObjectTypes.length > 0 ? `${name}Static` : name;
75
+ const namedObjectType = new NamedObjectType({
62
76
  abstract: astType.abstract,
63
77
  comment: astType.comment,
64
78
  declarationType: astType.tsObjectDeclarationType,
65
- export_: astType.export,
66
79
  extern: astType.extern,
67
80
  features: astType.tsFeatures,
68
81
  fromRdfType: astType.fromRdfType,
69
82
  identifierType,
70
83
  imports: astType.tsImports,
71
84
  label: astType.label,
72
- lazyAncestorObjectTypes: () => astType.ancestorObjectTypes.map((astType) => this.createObjectType(astType)),
73
- lazyChildObjectTypes: () => astType.childObjectTypes.map((astType) => this.createObjectType(astType)),
74
- lazyDescendantObjectTypes: () => astType.descendantObjectTypes.map((astType) => this.createObjectType(astType)),
75
- lazyParentObjectTypes: () => astType.parentObjectTypes.map((astType) => this.createObjectType(astType)),
76
- lazyProperties: (objectType) => {
85
+ lazyAncestorObjectTypes: () => astType.ancestorObjectTypes.map((astType) => this.createNamedObjectType(astType)),
86
+ lazyChildObjectTypes: () => astType.childObjectTypes.map((astType) => this.createNamedObjectType(astType)),
87
+ lazyDescendantObjectTypes: () => astType.descendantObjectTypes.map((astType) => this.createNamedObjectType(astType)),
88
+ lazyDiscriminantProperty: (namedObjectType) => {
89
+ // Discriminant property
90
+ const discriminantOwnValue = !astType.abstract
91
+ ? namedObjectType.discriminantValue
92
+ : undefined;
93
+ const discriminantDescendantValues = new Set();
94
+ for (const descendantObjectType of namedObjectType.descendantObjectTypes) {
95
+ if (!descendantObjectType.abstract) {
96
+ discriminantDescendantValues.add(descendantObjectType.discriminantValue);
97
+ }
98
+ }
99
+ return new NamedObjectType.DiscriminantProperty({
100
+ name: `${syntheticNamePrefix}type`,
101
+ namedObjectType,
102
+ type: new NamedObjectType.DiscriminantProperty.Type({
103
+ descendantValues: [...discriminantDescendantValues].sort(),
104
+ mutable: false,
105
+ ownValues: discriminantOwnValue ? [discriminantOwnValue] : [],
106
+ }),
107
+ visibility: "public",
108
+ });
109
+ },
110
+ lazyIdentifierProperty: (namedObjectType) => new NamedObjectType.IdentifierProperty({
111
+ identifierMintingStrategy: astType.identifierMintingStrategy,
112
+ identifierPrefixPropertyName: `${syntheticNamePrefix}identifierPrefix`,
113
+ name: `${syntheticNamePrefix}identifier`,
114
+ namedObjectType,
115
+ type: identifierType,
116
+ typeAlias: code `${staticModuleName}.${syntheticNamePrefix}Identifier`,
117
+ visibility: "public",
118
+ }),
119
+ lazyParentObjectTypes: () => astType.parentObjectTypes.map((astType) => this.createNamedObjectType(astType)),
120
+ lazyProperties: (namedObjectType) => {
77
121
  const properties = astType.properties
78
122
  .toSorted((left, right) => {
79
123
  if (left.order < right.order) {
@@ -82,43 +126,22 @@ export class TypeFactory {
82
126
  if (left.order > right.order) {
83
127
  return 1;
84
128
  }
85
- return tsName(left).localeCompare(tsName(right));
129
+ return tsName(left.name).localeCompare(tsName(right.name));
86
130
  })
87
131
  .map((astProperty) => this.createObjectTypeProperty({
88
132
  astObjectTypeProperty: astProperty,
89
- objectType,
133
+ namedObjectType,
90
134
  }));
91
- // Type discriminant property
92
- const typeDiscriminantOwnValue = !astType.abstract
93
- ? objectType.discriminantValue
94
- : undefined;
95
- const typeDiscriminantDescendantValues = new Set();
96
- for (const descendantObjectType of objectType.descendantObjectTypes) {
97
- if (!descendantObjectType.abstract) {
98
- typeDiscriminantDescendantValues.add(descendantObjectType.discriminantValue);
99
- }
100
- }
101
- if (typeDiscriminantOwnValue ||
102
- typeDiscriminantDescendantValues.size > 0) {
103
- properties.splice(0, 0, new ObjectType.TypeDiscriminantProperty({
104
- name: `${syntheticNamePrefix}type`,
105
- objectType,
106
- type: new ObjectType.TypeDiscriminantProperty.Type({
107
- descendantValues: [...typeDiscriminantDescendantValues].sort(),
108
- mutable: false,
109
- ownValues: typeDiscriminantOwnValue
110
- ? [typeDiscriminantOwnValue]
111
- : [],
112
- }),
113
- visibility: "public",
114
- }));
135
+ if (namedObjectType._discriminantProperty.type.ownValues.length > 0 ||
136
+ namedObjectType._discriminantProperty.type.descendantValues.length > 0) {
137
+ properties.splice(0, 0, namedObjectType._discriminantProperty);
115
138
  }
116
139
  // Some ObjectTypes have an identifierPrefix property, depending on their identifier minting strategy.
117
- if (objectTypeNeedsIdentifierPrefixProperty(astType)) {
118
- properties.splice(0, 0, new ObjectType.IdentifierPrefixProperty({
140
+ if (namedObjectTypeNeedsIdentifierPrefixProperty(astType)) {
141
+ properties.splice(0, 0, new NamedObjectType.IdentifierPrefixProperty({
119
142
  name: `${syntheticNamePrefix}identifierPrefix`,
120
- objectType,
121
- own: !astType.ancestorObjectTypes.some(objectTypeNeedsIdentifierPrefixProperty),
143
+ namedObjectType,
144
+ own: !astType.ancestorObjectTypes.some(namedObjectTypeNeedsIdentifierPrefixProperty),
122
145
  type: new StringType({
123
146
  comment: astType.comment,
124
147
  datatype: xsd.string,
@@ -131,45 +154,18 @@ export class TypeFactory {
131
154
  visibility: "protected",
132
155
  }));
133
156
  }
134
- // Every ObjectType has an identifier property. Some are abstract.
135
- properties.splice(0, 0, new ObjectType.IdentifierProperty({
136
- identifierMintingStrategy: astType.identifierMintingStrategy,
137
- identifierPrefixPropertyName: `${syntheticNamePrefix}identifierPrefix`,
138
- name: `${syntheticNamePrefix}identifier`,
139
- objectType,
140
- type: identifierType,
141
- typeAlias: code `${staticModuleName}.${syntheticNamePrefix}Identifier`,
142
- visibility: "public",
143
- }));
157
+ // Every NamedObjectType has an identifier property. Some are abstract.
158
+ properties.splice(0, 0, namedObjectType.identifierProperty);
144
159
  return properties;
145
160
  },
146
- identifierMintingStrategy: astType.identifierMintingStrategy,
147
- name: tsName(astType),
161
+ name,
162
+ recursive: astType.recursive,
148
163
  staticModuleName,
149
164
  synthetic: astType.synthetic,
150
165
  toRdfTypes: astType.toRdfTypes,
151
166
  });
152
- this.cachedObjectTypesByShapeIdentifier.set(astType.shapeIdentifier, objectType);
153
- return objectType;
154
- }
155
- createObjectUnionType(astType) {
156
- {
157
- const cachedObjectUnionType = this.cachedObjectUnionTypesByShapeIdentifier.get(astType.shapeIdentifier);
158
- if (cachedObjectUnionType) {
159
- return cachedObjectUnionType;
160
- }
161
- }
162
- const objectUnionType = new ObjectUnionType({
163
- comment: astType.comment,
164
- export_: astType.export,
165
- features: astType.tsFeatures,
166
- identifierType: this.createIdentifierType(astType.identifierType),
167
- label: astType.label,
168
- memberTypes: astType.memberObjectTypes.map((objectType) => this.createObjectType(objectType)),
169
- name: tsName(astType),
170
- });
171
- this.cachedObjectUnionTypesByShapeIdentifier.set(astType.shapeIdentifier, objectUnionType);
172
- return objectUnionType;
167
+ this.cachedObjectTypesByShapeIdentifier.set(astType.shapeIdentifier, namedObjectType);
168
+ return namedObjectType;
173
169
  }
174
170
  createType(astType, parameters) {
175
171
  switch (astType.kind) {
@@ -193,16 +189,10 @@ export class TypeFactory {
193
189
  return this.createListType(astType);
194
190
  case "LiteralType":
195
191
  return this.createLiteralType(astType, parameters);
196
- case "ObjectIntersectionType":
197
- throw new Error("not implemented");
198
192
  case "ObjectType":
199
- return this.createObjectType(astType);
200
- case "ObjectUnionType":
201
- return this.createObjectUnionType(astType);
193
+ return this.createNamedObjectType(astType);
202
194
  case "OptionType":
203
195
  return this.createOptionType(astType);
204
- case "PlaceholderType":
205
- throw new Error(astType.kind);
206
196
  case "SetType":
207
197
  return this.createSetType(astType);
208
198
  case "TermType":
@@ -211,6 +201,34 @@ export class TypeFactory {
211
201
  return this.createUnionType(astType);
212
202
  }
213
203
  }
204
+ createUnionType(astType) {
205
+ if (astType.isObjectUnionType()) {
206
+ return this.createNamedObjectUnionType(astType);
207
+ }
208
+ return astType.name
209
+ .map((name) => new NamedUnionType({
210
+ comment: astType.comment,
211
+ features: astType.tsFeatures,
212
+ identifierType: Maybe.empty(),
213
+ label: astType.label,
214
+ members: astType.members.map((member) => ({
215
+ discriminantValue: member.discriminantValue,
216
+ type: this.createType(member.type),
217
+ })),
218
+ name,
219
+ recursive: astType.recursive,
220
+ }))
221
+ .orDefaultLazy(() => new AnonymousUnionType({
222
+ comment: astType.comment,
223
+ label: astType.label,
224
+ identifierType: Maybe.empty(),
225
+ members: astType.members.map((member) => ({
226
+ discriminantValue: member.discriminantValue,
227
+ type: this.createType(member.type),
228
+ })),
229
+ recursive: astType.recursive,
230
+ }));
231
+ }
214
232
  createBlankNodeType(astType) {
215
233
  return new BlankNodeType({
216
234
  comment: astType.comment,
@@ -401,21 +419,20 @@ export class TypeFactory {
401
419
  languageIn: astType.languageIn,
402
420
  });
403
421
  }
404
- createObjectTypeProperty({ astObjectTypeProperty, objectType, }) {
422
+ createObjectTypeProperty({ astObjectTypeProperty, namedObjectType, }) {
405
423
  {
406
424
  const cachedProperty = this.cachedObjectTypePropertiesByShapeIdentifier.get(astObjectTypeProperty.shapeIdentifier);
407
425
  if (cachedProperty) {
408
426
  return cachedProperty;
409
427
  }
410
428
  }
411
- const name = tsName(astObjectTypeProperty);
412
- const property = new ObjectType.ShaclProperty({
429
+ const property = new NamedObjectType.ShaclProperty({
413
430
  comment: astObjectTypeProperty.comment,
414
431
  description: astObjectTypeProperty.description,
415
432
  label: astObjectTypeProperty.label,
416
433
  mutable: astObjectTypeProperty.mutable,
417
- objectType,
418
- name,
434
+ namedObjectType,
435
+ name: tsName(astObjectTypeProperty.name),
419
436
  path: astObjectTypeProperty.path,
420
437
  recursive: !!astObjectTypeProperty.recursive,
421
438
  type: this.createType(astObjectTypeProperty.type),
@@ -453,17 +470,9 @@ export class TypeFactory {
453
470
  nodeKinds: astType.nodeKinds,
454
471
  });
455
472
  }
456
- createUnionType(astType) {
457
- return new UnionType({
458
- comment: astType.comment,
459
- label: astType.label,
460
- memberDiscriminantValues: astType.memberDiscriminantValues,
461
- memberTypes: astType.memberTypes.map((astType) => this.createType(astType)),
462
- });
463
- }
464
473
  }
465
- function objectTypeNeedsIdentifierPrefixProperty(objectType) {
466
- return objectType.identifierMintingStrategy
474
+ function namedObjectTypeNeedsIdentifierPrefixProperty(namedObjectType) {
475
+ return namedObjectType.identifierMintingStrategy
467
476
  .map((identifierMintingStrategy) => {
468
477
  switch (identifierMintingStrategy) {
469
478
  case "blankNode":
@@ -478,4 +487,22 @@ function objectTypeNeedsIdentifierPrefixProperty(objectType) {
478
487
  })
479
488
  .orDefault(false);
480
489
  }
490
+ function tsName(name, options) {
491
+ if (name[0] === "$") {
492
+ return name;
493
+ }
494
+ // Adapted from https://github.com/sindresorhus/to-valid-identifier , MIT license
495
+ if (reservedTsIdentifiers.has(name)) {
496
+ // We prefix with underscore to avoid any potential conflicts with the Base62 encoded string.
497
+ return `$_${name}$`;
498
+ }
499
+ let tsName = name.replaceAll(/\P{ID_Continue}/gu, (x) => `$${base62.encodeInteger(x.codePointAt(0))}$`);
500
+ if (options?.synthetic) {
501
+ tsName = `${syntheticNamePrefix}${tsName}`;
502
+ }
503
+ return tsName;
504
+ }
505
+ const reservedTsIdentifiers = reservedTsIdentifiers_({
506
+ includeGlobalProperties: true,
507
+ });
481
508
  //# sourceMappingURL=TypeFactory.js.map
@@ -1,31 +1,33 @@
1
+ import { invariant } from "ts-invariant";
1
2
  import * as ast from "../../ast/index.js";
2
- import { ObjectType_jsonTypeAliasDeclaration } from "./_ObjectType/ObjectType_jsonTypeAliasDeclaration.js";
3
- import { ObjectType_jsonZodSchemaFunctionDeclaration } from "./_ObjectType/ObjectType_jsonZodSchemaFunctionDeclaration.js";
4
- import { ObjectUnionType_jsonTypeAliasDeclaration } from "./_ObjectUnionType/ObjectUnionType_jsonTypeAliasDeclaration.js";
5
- import { ObjectUnionType_jsonZodSchemaFunctionDeclaration } from "./_ObjectUnionType/ObjectUnionType_jsonZodSchemaFunctionDeclaration.js";
3
+ import { NamedObjectType_jsonSchemaFunctionDeclaration } from "./_NamedObjectType/NamedObjectType_jsonSchemaFunctionDeclaration.js";
4
+ import { NamedObjectType_jsonTypeAliasDeclaration } from "./_NamedObjectType/NamedObjectType_jsonTypeAliasDeclaration.js";
6
5
  import { snippets } from "./snippets.js";
6
+ import { syntheticNamePrefix } from "./syntheticNamePrefix.js";
7
7
  import { TypeFactory } from "./TypeFactory.js";
8
8
  import { code, joinCode } from "./ts-poet-wrapper.js";
9
9
  export class ZodGenerator {
10
10
  typeFactory = new TypeFactory();
11
11
  generate(ast_) {
12
12
  const declarations = [];
13
- for (const objectType of ast.ObjectType.toposort(ast_.objectTypes).map((astObjectType) => this.typeFactory.createObjectType(astObjectType))) {
13
+ for (const namedObjectType of ast.ObjectType.toposort(ast_.namedObjectTypes).map((astObjectType) => this.typeFactory.createNamedObjectType(astObjectType))) {
14
14
  declarations.push(code `\
15
- export namespace ${objectType.staticModuleName} {
16
- ${joinCode([
17
- ...ObjectType_jsonTypeAliasDeclaration.bind(objectType)().toList(),
18
- ...ObjectType_jsonZodSchemaFunctionDeclaration.bind(objectType)().toList(),
19
- ], { on: "\n\n" })}
15
+ export namespace ${namedObjectType.staticModuleName} {
16
+ ${joinCode(NamedObjectType_jsonTypeAliasDeclaration.bind(namedObjectType)().toList())}
17
+
18
+ export namespace ${syntheticNamePrefix}Json {
19
+ ${joinCode(NamedObjectType_jsonSchemaFunctionDeclaration.bind(namedObjectType)().toList())}
20
+ }
20
21
  }`);
21
22
  }
22
- for (const objectUnionType of ast_.objectUnionTypes.map((astObjectUnionType) => this.typeFactory.createObjectUnionType(astObjectUnionType))) {
23
+ for (const astNamedUnionType of ast_.namedUnionTypes.map((astNamedUnionType) => this.typeFactory.createUnionType(astNamedUnionType))) {
24
+ invariant(astNamedUnionType.kind !== "AnonymousUnionType");
23
25
  declarations.push(code `\
24
- export namespace ${objectUnionType.staticModuleName} {
25
- ${joinCode([
26
- ...ObjectUnionType_jsonTypeAliasDeclaration.bind(objectUnionType)().toList(),
27
- ...ObjectUnionType_jsonZodSchemaFunctionDeclaration.bind(objectUnionType)().toList(),
28
- ], { on: "\n\n" })}
26
+ export namespace ${astNamedUnionType.staticModuleName} {
27
+ ${astNamedUnionType.jsonTypeAliasDeclaration}
28
+ export namespace ${syntheticNamePrefix}Json {
29
+ ${astNamedUnionType.jsonSchemaFunctionDeclaration}
30
+ }
29
31
  }`);
30
32
  }
31
33
  declarations.splice(0, 0, joinCode(Object.values(snippets)
@@ -1,10 +1,10 @@
1
1
  import type { Maybe } from "purify-ts";
2
2
  import type { PropertyVisibility } from "../../../enums/PropertyVisibility.js";
3
- import type { ObjectType } from "../ObjectType.js";
3
+ import type { NamedObjectType } from "../NamedObjectType.js";
4
4
  import type { Type } from "../Type.js";
5
5
  import { type Code } from "../ts-poet-wrapper.js";
6
6
  export declare abstract class AbstractProperty<TypeT extends Pick<Type, "filterFunction" | "mutable" | "name" | "schema">> {
7
- protected readonly objectType: ObjectType;
7
+ protected readonly namedObjectType: NamedObjectType;
8
8
  /**
9
9
  * Optional property to include in the parameters object of a class constructor.
10
10
  */
@@ -47,7 +47,7 @@ export declare abstract class AbstractProperty<TypeT extends Pick<Type, "filterF
47
47
  /**
48
48
  * zod Object key: schema pair on the property serialized by toJsonObjectMember.
49
49
  */
50
- abstract readonly jsonZodSchema: Maybe<{
50
+ abstract readonly jsonZchema: Maybe<{
51
51
  readonly key: string;
52
52
  readonly schema: Code;
53
53
  }>;
@@ -64,7 +64,7 @@ export declare abstract class AbstractProperty<TypeT extends Pick<Type, "filterF
64
64
  */
65
65
  readonly name: string;
66
66
  /**
67
- * Is the property's type the ObjectType or does its type indirectly reference the ObjectType?
67
+ * Is the property's type the NamedObjectType or does its type indirectly reference the NamedObjectType?
68
68
  */
69
69
  abstract readonly recursive: boolean;
70
70
  /**
@@ -75,9 +75,9 @@ export declare abstract class AbstractProperty<TypeT extends Pick<Type, "filterF
75
75
  * Property visibility: private, protected, public.
76
76
  */
77
77
  readonly visibility: PropertyVisibility;
78
- constructor({ name, objectType, type, visibility, }: {
78
+ constructor({ name, namedObjectType, type, visibility, }: {
79
79
  name: string;
80
- objectType: ObjectType;
80
+ namedObjectType: NamedObjectType;
81
81
  type: TypeT;
82
82
  visibility: PropertyVisibility;
83
83
  });
@@ -109,7 +109,7 @@ export declare abstract class AbstractProperty<TypeT extends Pick<Type, "filterF
109
109
  /**
110
110
  * Expression to deserialize this property on the given rdfjsResource.Resource to a Either<Error, this property type>.
111
111
  */
112
- abstract fromRdfExpression(parameters: {
112
+ abstract fromRdfResourceValuesExpression(parameters: {
113
113
  variables: {
114
114
  context: Code;
115
115
  graph: Code;
@@ -184,8 +184,8 @@ export declare abstract class AbstractProperty<TypeT extends Pick<Type, "filterF
184
184
  /**
185
185
  * Statements to serialize this property to an RDF resource.
186
186
  */
187
- abstract toRdfStatements(parameters: {
188
- variables: Omit<Parameters<Type["toRdfExpression"]>[0]["variables"], "propertyPath">;
187
+ abstract toRdfRdfResourceValuesStatements(parameters: {
188
+ variables: Omit<Parameters<Type["toRdfResourceValuesExpression"]>[0]["variables"], "propertyPath">;
189
189
  }): readonly Code[];
190
190
  }
191
191
  //# sourceMappingURL=AbstractProperty.d.ts.map
@@ -9,7 +9,7 @@ import { Memoize } from "typescript-memoize";
9
9
  import { removeUndefined } from "../removeUndefined.js";
10
10
  import { code, literalOf } from "../ts-poet-wrapper.js";
11
11
  export class AbstractProperty {
12
- objectType;
12
+ namedObjectType;
13
13
  /**
14
14
  * TypeScript identifier-safe name of the property.
15
15
  */
@@ -22,9 +22,9 @@ export class AbstractProperty {
22
22
  * Property visibility: private, protected, public.
23
23
  */
24
24
  visibility;
25
- constructor({ name, objectType, type, visibility, }) {
25
+ constructor({ name, namedObjectType, type, visibility, }) {
26
26
  this.name = name;
27
- this.objectType = objectType;
27
+ this.namedObjectType = namedObjectType;
28
28
  this.type = type;
29
29
  this.visibility = visibility;
30
30
  }
@@ -1,35 +1,35 @@
1
1
  import { Maybe } from "purify-ts";
2
2
  import { type Code } from "../ts-poet-wrapper.js";
3
3
  import { AbstractProperty } from "./AbstractProperty.js";
4
- export declare class TypeDiscriminantProperty extends AbstractProperty<TypeDiscriminantProperty.Type> {
4
+ export declare class DiscriminantProperty extends AbstractProperty<DiscriminantProperty.Type> {
5
5
  readonly constructorParametersSignature: Maybe<Code>;
6
6
  readonly equalsFunction: Maybe<Code>;
7
- readonly filterProperty: AbstractProperty<TypeDiscriminantProperty.Type>["filterProperty"];
7
+ readonly filterProperty: AbstractProperty<DiscriminantProperty.Type>["filterProperty"];
8
8
  readonly getAccessorDeclaration: Maybe<Code>;
9
- readonly graphqlField: AbstractProperty<TypeDiscriminantProperty.Type>["graphqlField"];
10
- readonly kind = "TypeDiscriminantProperty";
9
+ readonly graphqlField: AbstractProperty<DiscriminantProperty.Type>["graphqlField"];
10
+ readonly kind = "DiscriminantProperty";
11
11
  readonly mutable = false;
12
12
  readonly recursive = false;
13
13
  constructor({ type, ...superParameters }: {
14
- type: TypeDiscriminantProperty.Type;
14
+ type: DiscriminantProperty.Type;
15
15
  } & ConstructorParameters<typeof AbstractProperty>[0]);
16
16
  get declaration(): Maybe<Code>;
17
17
  get jsonSignature(): Maybe<Code>;
18
- get jsonZodSchema(): AbstractProperty<TypeDiscriminantProperty.Type>["jsonZodSchema"];
18
+ get jsonZchema(): AbstractProperty<DiscriminantProperty.Type>["jsonZchema"];
19
19
  private get abstract();
20
20
  private get initializer();
21
21
  private get override();
22
22
  constructorStatements(): readonly Code[];
23
23
  fromJsonStatements(): readonly Code[];
24
- fromRdfExpression(): Maybe<Code>;
25
- hashStatements({ variables, }: Parameters<AbstractProperty<TypeDiscriminantProperty.Type>["hashStatements"]>[0]): readonly Code[];
26
- jsonUiSchemaElement({ variables, }: Parameters<AbstractProperty<TypeDiscriminantProperty.Type>["jsonUiSchemaElement"]>[0]): Maybe<Code>;
24
+ fromRdfResourceValuesExpression(): Maybe<Code>;
25
+ hashStatements({ variables, }: Parameters<AbstractProperty<DiscriminantProperty.Type>["hashStatements"]>[0]): readonly Code[];
26
+ jsonUiSchemaElement({ variables, }: Parameters<AbstractProperty<DiscriminantProperty.Type>["jsonUiSchemaElement"]>[0]): Maybe<Code>;
27
27
  sparqlConstructTriplesExpression(): Maybe<Code>;
28
- sparqlWherePatternsExpression(): ReturnType<AbstractProperty<TypeDiscriminantProperty.Type>["sparqlWherePatternsExpression"]>;
29
- toJsonObjectMemberExpression({ variables, }: Parameters<AbstractProperty<TypeDiscriminantProperty.Type>["toJsonObjectMemberExpression"]>[0]): Maybe<Code>;
30
- toRdfStatements(): readonly Code[];
28
+ sparqlWherePatternsExpression(): ReturnType<AbstractProperty<DiscriminantProperty.Type>["sparqlWherePatternsExpression"]>;
29
+ toJsonObjectMemberExpression({ variables, }: Parameters<AbstractProperty<DiscriminantProperty.Type>["toJsonObjectMemberExpression"]>[0]): Maybe<Code>;
30
+ toRdfRdfResourceValuesStatements(): readonly Code[];
31
31
  }
32
- export declare namespace TypeDiscriminantProperty {
32
+ export declare namespace DiscriminantProperty {
33
33
  class Type {
34
34
  readonly filterFunction: Code;
35
35
  readonly mutable: boolean;
@@ -45,4 +45,4 @@ export declare namespace TypeDiscriminantProperty {
45
45
  get values(): string[];
46
46
  }
47
47
  }
48
- //# sourceMappingURL=TypeDiscriminantProperty.d.ts.map
48
+ //# sourceMappingURL=DiscriminantProperty.d.ts.map