@shaclmate/compiler 4.0.39 → 4.0.41

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 (211) hide show
  1. package/dist/ShapesGraphToAstTransformer.d.ts +0 -8
  2. package/dist/ShapesGraphToAstTransformer.js +5 -85
  3. package/dist/_ShapesGraphToAstTransformer/shapeNodeKinds.js +128 -160
  4. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstObjectType.d.ts +1 -1
  5. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstObjectType.js +0 -16
  6. package/dist/ast/AbstractCompoundType.d.ts +2 -1
  7. package/dist/ast/AbstractCompoundType.js +1 -1
  8. package/dist/ast/AbstractLazyObjectType.d.ts +0 -2
  9. package/dist/ast/Ast.d.ts +1 -3
  10. package/dist/ast/ListType.d.ts +1 -1
  11. package/dist/ast/ListType.js +1 -1
  12. package/dist/ast/ObjectType.d.ts +0 -12
  13. package/dist/ast/ObjectType.js +0 -78
  14. package/dist/generators/AstJsonGenerator.js +7 -3
  15. package/dist/generators/transformAstToLabeledPropertyGraph.js +59 -56
  16. package/dist/generators/ts/AbstractCollectionType.d.ts +5 -12
  17. package/dist/generators/ts/AbstractCollectionType.js +9 -68
  18. package/dist/generators/ts/AbstractContainerType.d.ts +4 -6
  19. package/dist/generators/ts/AbstractContainerType.js +5 -9
  20. package/dist/generators/ts/AbstractDateType.d.ts +6 -3
  21. package/dist/generators/ts/AbstractDateType.js +7 -2
  22. package/dist/generators/ts/AbstractIdentifierType.d.ts +4 -0
  23. package/dist/generators/ts/AbstractIdentifierType.js +3 -0
  24. package/dist/generators/ts/AbstractLazyObjectType.d.ts +9 -9
  25. package/dist/generators/ts/AbstractLazyObjectType.js +30 -19
  26. package/dist/generators/ts/AbstractLiteralType.d.ts +1 -0
  27. package/dist/generators/ts/AbstractNumericType.d.ts +1 -1
  28. package/dist/generators/ts/AbstractNumericType.js +9 -9
  29. package/dist/generators/ts/AbstractObjectSetType.d.ts +10 -9
  30. package/dist/generators/ts/AbstractObjectSetType.js +2 -2
  31. package/dist/generators/ts/AbstractPrimitiveType.d.ts +1 -0
  32. package/dist/generators/ts/AbstractPrimitiveType.js +2 -2
  33. package/dist/generators/ts/AbstractTermType.d.ts +1 -2
  34. package/dist/generators/ts/AbstractTermType.js +3 -5
  35. package/dist/generators/ts/AbstractType.d.ts +61 -26
  36. package/dist/generators/ts/AbstractType.js +37 -17
  37. package/dist/generators/ts/BigDecimalType.d.ts +5 -1
  38. package/dist/generators/ts/BigDecimalType.js +6 -3
  39. package/dist/generators/ts/BigIntType.d.ts +3 -1
  40. package/dist/generators/ts/BigIntType.js +3 -3
  41. package/dist/generators/ts/BlankNodeType.d.ts +3 -3
  42. package/dist/generators/ts/BlankNodeType.js +13 -13
  43. package/dist/generators/ts/BooleanType.d.ts +5 -3
  44. package/dist/generators/ts/BooleanType.js +11 -6
  45. package/dist/generators/ts/DefaultValueType.d.ts +40 -2
  46. package/dist/generators/ts/DefaultValueType.js +14 -12
  47. package/dist/generators/ts/FloatType.d.ts +3 -1
  48. package/dist/generators/ts/FloatType.js +1 -1
  49. package/dist/generators/ts/GraphqlSchema.d.ts +4 -4
  50. package/dist/generators/ts/GraphqlSchema.js +6 -6
  51. package/dist/generators/ts/IdentifierType.d.ts +3 -3
  52. package/dist/generators/ts/IdentifierType.js +19 -17
  53. package/dist/generators/ts/IntType.d.ts +3 -1
  54. package/dist/generators/ts/IntType.js +1 -1
  55. package/dist/generators/ts/IriType.d.ts +2 -2
  56. package/dist/generators/ts/IriType.js +21 -19
  57. package/dist/generators/ts/LazyObjectOptionType.d.ts +2 -0
  58. package/dist/generators/ts/LazyObjectOptionType.js +14 -10
  59. package/dist/generators/ts/LazyObjectSetType.js +14 -8
  60. package/dist/generators/ts/LazyObjectType.js +9 -6
  61. package/dist/generators/ts/ListType.d.ts +13 -5
  62. package/dist/generators/ts/ListType.js +48 -12
  63. package/dist/generators/ts/LiteralType.d.ts +5 -1
  64. package/dist/generators/ts/LiteralType.js +11 -8
  65. package/dist/generators/ts/{NamedObjectType.d.ts → ObjectType.d.ts} +19 -34
  66. package/dist/generators/ts/ObjectType.js +282 -0
  67. package/dist/generators/ts/ObjectUnionType.d.ts +20 -0
  68. package/dist/generators/ts/{NamedObjectUnionType.js → ObjectUnionType.js} +52 -60
  69. package/dist/generators/ts/OptionType.d.ts +6 -2
  70. package/dist/generators/ts/OptionType.js +20 -15
  71. package/dist/generators/ts/RdfjsDatasetObjectSetType.js +8 -11
  72. package/dist/generators/ts/SetType.d.ts +16 -1
  73. package/dist/generators/ts/SetType.js +80 -2
  74. package/dist/generators/ts/Snippets.d.ts +3 -1
  75. package/dist/generators/ts/Snippets.js +18 -4
  76. package/dist/generators/ts/SparqlObjectSetType.js +2 -2
  77. package/dist/generators/ts/StringType.d.ts +5 -3
  78. package/dist/generators/ts/StringType.js +15 -6
  79. package/dist/generators/ts/TermType.d.ts +6 -2
  80. package/dist/generators/ts/TermType.js +15 -12
  81. package/dist/generators/ts/TsGenerator.d.ts +1 -1
  82. package/dist/generators/ts/TsGenerator.js +60 -32
  83. package/dist/generators/ts/Type.d.ts +4 -5
  84. package/dist/generators/ts/TypeFactory.d.ts +7 -8
  85. package/dist/generators/ts/TypeFactory.js +62 -76
  86. package/dist/generators/ts/{AbstractUnionType.d.ts → UnionType.d.ts} +36 -11
  87. package/dist/generators/ts/{AbstractUnionType.js → UnionType.js} +296 -105
  88. package/dist/generators/ts/ZodGenerator.d.ts +1 -1
  89. package/dist/generators/ts/ZodGenerator.js +21 -16
  90. package/dist/generators/ts/{_NamedObjectType → _ObjectType}/AbstractProperty.d.ts +9 -6
  91. package/dist/generators/ts/{_NamedObjectType → _ObjectType}/AbstractProperty.js +3 -3
  92. package/dist/generators/ts/{_NamedObjectType → _ObjectType}/DiscriminantProperty.d.ts +9 -13
  93. package/dist/generators/ts/{_NamedObjectType → _ObjectType}/DiscriminantProperty.js +22 -39
  94. package/dist/generators/ts/{_NamedObjectType → _ObjectType}/IdentifierProperty.d.ts +1 -5
  95. package/dist/generators/ts/{_NamedObjectType → _ObjectType}/IdentifierProperty.js +18 -13
  96. package/dist/generators/ts/_ObjectType/ObjectType_createFunctionDeclaration.d.ts +5 -0
  97. package/dist/generators/ts/_ObjectType/ObjectType_createFunctionDeclaration.js +44 -0
  98. package/dist/generators/ts/_ObjectType/ObjectType_equalsFunctionDeclaration.d.ts +5 -0
  99. package/dist/generators/ts/{_NamedObjectType/NamedObjectType_equalsFunctionDeclaration.js → _ObjectType/ObjectType_equalsFunctionDeclaration.js} +3 -7
  100. package/dist/generators/ts/_ObjectType/ObjectType_filterFunctionDeclaration.d.ts +5 -0
  101. package/dist/generators/ts/{_NamedObjectType/NamedObjectType_filterFunctionDeclaration.js → _ObjectType/ObjectType_filterFunctionDeclaration.js} +3 -6
  102. package/dist/generators/ts/_ObjectType/ObjectType_filterTypeDeclaration.d.ts +5 -0
  103. package/dist/generators/ts/{_NamedObjectType/NamedObjectType_filterTypeDeclaration.js → _ObjectType/ObjectType_filterTypeDeclaration.js} +2 -5
  104. package/dist/generators/ts/_ObjectType/ObjectType_focusSparqlConstructTriplesFunctionDeclaration.d.ts +5 -0
  105. package/dist/generators/ts/{_NamedObjectType/NamedObjectType_focusSparqlConstructTriplesFunctionDeclaration.js → _ObjectType/ObjectType_focusSparqlConstructTriplesFunctionDeclaration.js} +2 -6
  106. package/dist/generators/ts/_ObjectType/ObjectType_focusSparqlWherePatternsFunctionDeclaration.d.ts +5 -0
  107. package/dist/generators/ts/{_NamedObjectType/NamedObjectType_focusSparqlWherePatternsFunctionDeclaration.js → _ObjectType/ObjectType_focusSparqlWherePatternsFunctionDeclaration.js} +5 -24
  108. package/dist/generators/ts/_ObjectType/ObjectType_fromJsonFunctionDeclaration.d.ts +5 -0
  109. package/dist/generators/ts/_ObjectType/ObjectType_fromJsonFunctionDeclaration.js +18 -0
  110. package/dist/generators/ts/_ObjectType/ObjectType_fromRdfResourceFunctionDeclaration.d.ts +5 -0
  111. package/dist/generators/ts/_ObjectType/ObjectType_fromRdfResourceFunctionDeclaration.js +51 -0
  112. package/dist/generators/ts/_ObjectType/ObjectType_fromRdfResourceValuesFunctionDeclaration.d.ts +5 -0
  113. package/dist/generators/ts/_ObjectType/ObjectType_fromRdfResourceValuesFunctionDeclaration.js +15 -0
  114. package/dist/generators/ts/_ObjectType/ObjectType_fromRdfTypeVariableStatement.d.ts +5 -0
  115. package/dist/generators/ts/{_NamedObjectType/NamedObjectType_fromRdfTypeVariableStatement.js → _ObjectType/ObjectType_fromRdfTypeVariableStatement.js} +2 -2
  116. package/dist/generators/ts/_ObjectType/ObjectType_graphqlTypeVariableStatement.d.ts +5 -0
  117. package/dist/generators/ts/{_NamedObjectType/NamedObjectType_graphqlTypeVariableStatement.js → _ObjectType/ObjectType_graphqlTypeVariableStatement.js} +4 -4
  118. package/dist/generators/ts/_ObjectType/ObjectType_hashFunctionDeclarations.d.ts +4 -0
  119. package/dist/generators/ts/_ObjectType/ObjectType_hashFunctionDeclarations.js +41 -0
  120. package/dist/generators/ts/_ObjectType/ObjectType_interfaceDeclaration.d.ts +4 -0
  121. package/dist/generators/ts/_ObjectType/ObjectType_interfaceDeclaration.js +12 -0
  122. package/dist/generators/ts/_ObjectType/ObjectType_isTypeFunctionDeclaration.d.ts +5 -0
  123. package/dist/generators/ts/_ObjectType/ObjectType_isTypeFunctionDeclaration.js +20 -0
  124. package/dist/generators/ts/_ObjectType/ObjectType_jsonParseFunctionDeclaration.d.ts +5 -0
  125. package/dist/generators/ts/{_NamedObjectType/NamedObjectType_jsonParseFunctionDeclaration.js → _ObjectType/ObjectType_jsonParseFunctionDeclaration.js} +2 -2
  126. package/dist/generators/ts/_ObjectType/ObjectType_jsonSchemaFunctionDeclaration.d.ts +5 -0
  127. package/dist/generators/ts/{_NamedObjectType/NamedObjectType_jsonSchemaFunctionDeclaration.js → _ObjectType/ObjectType_jsonSchemaFunctionDeclaration.js} +5 -11
  128. package/dist/generators/ts/_ObjectType/ObjectType_jsonTypeAliasDeclaration.d.ts +5 -0
  129. package/dist/generators/ts/_ObjectType/ObjectType_jsonTypeAliasDeclaration.js +9 -0
  130. package/dist/generators/ts/_ObjectType/ObjectType_jsonUiSchemaFunctionDeclaration.d.ts +5 -0
  131. package/dist/generators/ts/{_NamedObjectType/NamedObjectType_jsonUiSchemaFunctionDeclaration.js → _ObjectType/ObjectType_jsonUiSchemaFunctionDeclaration.js} +4 -6
  132. package/dist/generators/ts/{_NamedObjectType/NamedObjectType_objectSetMethodNames.d.ts → _ObjectType/ObjectType_objectSetMethodNames.d.ts} +3 -3
  133. package/dist/generators/ts/{_NamedObjectType/NamedObjectType_objectSetMethodNames.js → _ObjectType/ObjectType_objectSetMethodNames.js} +4 -4
  134. package/dist/generators/ts/_ObjectType/ObjectType_schemaVariableStatement.d.ts +5 -0
  135. package/dist/generators/ts/_ObjectType/ObjectType_schemaVariableStatement.js +12 -0
  136. package/dist/generators/ts/{_NamedObjectType/NamedObjectType_sparqlConstructQueryFunctionDeclaration.d.ts → _ObjectType/ObjectType_sparqlConstructQueryFunctionDeclaration.d.ts} +3 -3
  137. package/dist/generators/ts/{_NamedObjectType/NamedObjectType_sparqlConstructQueryFunctionDeclaration.js → _ObjectType/ObjectType_sparqlConstructQueryFunctionDeclaration.js} +5 -5
  138. package/dist/generators/ts/{_NamedObjectType/NamedObjectType_sparqlConstructQueryStringFunctionDeclaration.d.ts → _ObjectType/ObjectType_sparqlConstructQueryStringFunctionDeclaration.d.ts} +3 -3
  139. package/dist/generators/ts/_ObjectType/ObjectType_sparqlConstructQueryStringFunctionDeclaration.js +12 -0
  140. package/dist/generators/ts/_ObjectType/ObjectType_toJsonFunctionDeclaration.d.ts +5 -0
  141. package/dist/generators/ts/_ObjectType/ObjectType_toJsonFunctionDeclaration.js +20 -0
  142. package/dist/generators/ts/_ObjectType/ObjectType_toRdfResourceFunctionDeclaration.d.ts +5 -0
  143. package/dist/generators/ts/{_NamedObjectType/NamedObjectType_toRdfResourceFunctionDeclaration.js → _ObjectType/ObjectType_toRdfResourceFunctionDeclaration.js} +4 -4
  144. package/dist/generators/ts/_ObjectType/ObjectType_toStringFunctionDeclarations.d.ts +4 -0
  145. package/dist/generators/ts/{_NamedObjectType/NamedObjectType_toStringFunctionDeclarations.js → _ObjectType/ObjectType_toStringFunctionDeclarations.js} +7 -14
  146. package/dist/generators/ts/_ObjectType/ObjectType_valueSparqlConstructTriplesFunctionDeclaration.d.ts +5 -0
  147. package/dist/generators/ts/{_NamedObjectType/NamedObjectType_valueSparqlConstructTriplesFunctionDeclaration.js → _ObjectType/ObjectType_valueSparqlConstructTriplesFunctionDeclaration.js} +3 -3
  148. package/dist/generators/ts/_ObjectType/ObjectType_valueSparqlWherePatternsFunctionDeclaration.d.ts +5 -0
  149. package/dist/generators/ts/{_NamedObjectType/NamedObjectType_valueSparqlWherePatternsFunctionDeclaration.js → _ObjectType/ObjectType_valueSparqlWherePatternsFunctionDeclaration.js} +3 -3
  150. package/dist/generators/ts/{_NamedObjectType → _ObjectType}/ShaclProperty.js +12 -12
  151. package/dist/generators/ts/_ObjectType/identifierTypeDeclarations.d.ts +4 -0
  152. package/dist/generators/ts/_ObjectType/identifierTypeDeclarations.js +16 -0
  153. package/dist/generators/ts/_snippets/snippets_convertToArraySet.d.ts +3 -0
  154. package/dist/generators/ts/_snippets/snippets_convertToArraySet.js +8 -0
  155. package/dist/generators/ts/_snippets/snippets_convertToList.d.ts +3 -0
  156. package/dist/generators/ts/_snippets/snippets_convertToList.js +7 -0
  157. package/dist/generators/ts/_snippets/snippets_convertToScalarSet.d.ts +3 -0
  158. package/dist/generators/ts/_snippets/snippets_convertToScalarSet.js +15 -0
  159. package/dist/input/generated.d.ts +758 -117
  160. package/dist/input/generated.js +636 -128
  161. package/package.json +4 -6
  162. package/dist/generators/ts/AbstractNamedUnionType.d.ts +0 -30
  163. package/dist/generators/ts/AbstractNamedUnionType.js +0 -190
  164. package/dist/generators/ts/AnonymousUnionType.d.ts +0 -27
  165. package/dist/generators/ts/AnonymousUnionType.js +0 -59
  166. package/dist/generators/ts/NamedObjectType.js +0 -342
  167. package/dist/generators/ts/NamedObjectUnionType.d.ts +0 -37
  168. package/dist/generators/ts/NamedUnionType.d.ts +0 -11
  169. package/dist/generators/ts/NamedUnionType.js +0 -13
  170. package/dist/generators/ts/_NamedObjectType/NamedObjectType_createFunctionDeclaration.d.ts +0 -5
  171. package/dist/generators/ts/_NamedObjectType/NamedObjectType_createFunctionDeclaration.js +0 -65
  172. package/dist/generators/ts/_NamedObjectType/NamedObjectType_equalsFunctionDeclaration.d.ts +0 -5
  173. package/dist/generators/ts/_NamedObjectType/NamedObjectType_filterFunctionDeclaration.d.ts +0 -5
  174. package/dist/generators/ts/_NamedObjectType/NamedObjectType_filterTypeDeclaration.d.ts +0 -5
  175. package/dist/generators/ts/_NamedObjectType/NamedObjectType_focusSparqlConstructTriplesFunctionDeclaration.d.ts +0 -5
  176. package/dist/generators/ts/_NamedObjectType/NamedObjectType_focusSparqlWherePatternsFunctionDeclaration.d.ts +0 -5
  177. package/dist/generators/ts/_NamedObjectType/NamedObjectType_fromJsonFunctionDeclaration.d.ts +0 -5
  178. package/dist/generators/ts/_NamedObjectType/NamedObjectType_fromJsonFunctionDeclaration.js +0 -43
  179. package/dist/generators/ts/_NamedObjectType/NamedObjectType_fromRdfResourceFunctionDeclaration.d.ts +0 -5
  180. package/dist/generators/ts/_NamedObjectType/NamedObjectType_fromRdfResourceFunctionDeclaration.js +0 -80
  181. package/dist/generators/ts/_NamedObjectType/NamedObjectType_fromRdfResourceValuesFunctionDeclaration.d.ts +0 -5
  182. package/dist/generators/ts/_NamedObjectType/NamedObjectType_fromRdfResourceValuesFunctionDeclaration.js +0 -15
  183. package/dist/generators/ts/_NamedObjectType/NamedObjectType_fromRdfTypeVariableStatement.d.ts +0 -5
  184. package/dist/generators/ts/_NamedObjectType/NamedObjectType_graphqlTypeVariableStatement.d.ts +0 -5
  185. package/dist/generators/ts/_NamedObjectType/NamedObjectType_hashFunctionDeclarations.d.ts +0 -4
  186. package/dist/generators/ts/_NamedObjectType/NamedObjectType_hashFunctionDeclarations.js +0 -45
  187. package/dist/generators/ts/_NamedObjectType/NamedObjectType_interfaceDeclaration.d.ts +0 -4
  188. package/dist/generators/ts/_NamedObjectType/NamedObjectType_interfaceDeclaration.js +0 -16
  189. package/dist/generators/ts/_NamedObjectType/NamedObjectType_isTypeFunctionDeclaration.d.ts +0 -5
  190. package/dist/generators/ts/_NamedObjectType/NamedObjectType_isTypeFunctionDeclaration.js +0 -17
  191. package/dist/generators/ts/_NamedObjectType/NamedObjectType_jsonParseFunctionDeclaration.d.ts +0 -5
  192. package/dist/generators/ts/_NamedObjectType/NamedObjectType_jsonSchemaFunctionDeclaration.d.ts +0 -5
  193. package/dist/generators/ts/_NamedObjectType/NamedObjectType_jsonTypeAliasDeclaration.d.ts +0 -5
  194. package/dist/generators/ts/_NamedObjectType/NamedObjectType_jsonTypeAliasDeclaration.js +0 -16
  195. package/dist/generators/ts/_NamedObjectType/NamedObjectType_jsonUiSchemaFunctionDeclaration.d.ts +0 -5
  196. package/dist/generators/ts/_NamedObjectType/NamedObjectType_schemaVariableStatement.d.ts +0 -5
  197. package/dist/generators/ts/_NamedObjectType/NamedObjectType_schemaVariableStatement.js +0 -12
  198. package/dist/generators/ts/_NamedObjectType/NamedObjectType_sparqlConstructQueryStringFunctionDeclaration.js +0 -12
  199. package/dist/generators/ts/_NamedObjectType/NamedObjectType_toJsonFunctionDeclaration.d.ts +0 -5
  200. package/dist/generators/ts/_NamedObjectType/NamedObjectType_toJsonFunctionDeclaration.js +0 -41
  201. package/dist/generators/ts/_NamedObjectType/NamedObjectType_toRdfResourceFunctionDeclaration.d.ts +0 -5
  202. package/dist/generators/ts/_NamedObjectType/NamedObjectType_toStringFunctionDeclarations.d.ts +0 -4
  203. package/dist/generators/ts/_NamedObjectType/NamedObjectType_valueSparqlConstructTriplesFunctionDeclaration.d.ts +0 -5
  204. package/dist/generators/ts/_NamedObjectType/NamedObjectType_valueSparqlWherePatternsFunctionDeclaration.d.ts +0 -5
  205. package/dist/generators/ts/_NamedObjectType/identifierTypeDeclarations.d.ts +0 -4
  206. package/dist/generators/ts/_NamedObjectType/identifierTypeDeclarations.js +0 -25
  207. package/dist/generators/ts/_snippets/snippets_convertToArray.d.ts +0 -3
  208. package/dist/generators/ts/_snippets/snippets_convertToArray.js +0 -8
  209. /package/dist/generators/ts/{_NamedObjectType → _ObjectType}/Property.d.ts +0 -0
  210. /package/dist/generators/ts/{_NamedObjectType → _ObjectType}/Property.js +0 -0
  211. /package/dist/generators/ts/{_NamedObjectType → _ObjectType}/ShaclProperty.d.ts +0 -0
@@ -56,7 +56,7 @@ async ${methodSignatures.object.name}(${methodSignatures.object.parameters}): ${
56
56
  }`,
57
57
  // objectSync
58
58
  code `\
59
- ${methodSignatures.object.name}Sync(${methodSignatures.object.parameters}): ${this.reusables.imports.Either}<Error, ${namedObjectType.name}> {
59
+ ${methodSignatures.object.name}Sync(${methodSignatures.object.parameters}): ${this.reusables.imports.Either}<Error, ${namedObjectType.expression}> {
60
60
  return this.${methodSignatures.objects.name}Sync({ identifiers: [identifier], preferredLanguages: options?.preferredLanguages }).map(objects => objects[0]);
61
61
  }`,
62
62
  // objectCount
@@ -87,22 +87,19 @@ async ${methodSignatures.objects.name}(${methodSignatures.objects.parameters}):
87
87
  // objectsSync has per-object type logic, not just forwarding
88
88
  ];
89
89
  const runtimeObjectType = (filterFunction, namedObjectType) => {
90
- const fromRdfTypes = namedObjectType.fromRdfTypeVariable
91
- .toList()
92
- .concat(namedObjectType.descendantFromRdfTypeVariables);
93
- return code `{ filter: ${filterFunction}, fromRdfResource: ${namedObjectType.name}.fromRdfResource, fromRdfTypes: ${fromRdfTypes.length > 0 ? code `[${joinCode(fromRdfTypes, { on: ", " })}]` : "[]"} }`;
90
+ return code `{ filter: ${filterFunction}, fromRdfResource: ${namedObjectType.expression}.fromRdfResource, fromRdfTypes: ${namedObjectType.fromRdfTypeVariable.map((fromRdfTypeVariable) => code `[${fromRdfTypeVariable}]`).orDefault(code `[]`)} }`;
94
91
  };
95
92
  switch (namedObjectType.kind) {
96
- case "NamedObjectType": {
93
+ case "Object": {
97
94
  return delegatingMethods.concat(code `\
98
- ${methodSignatures.objects.name}Sync(${methodSignatures.objects.parameters}): ${this.reusables.imports.Either}<Error, readonly ${namedObjectType.name}[]> {
99
- return this.#objectsSync<${namedObjectType.name}, ${namedObjectType.filterType}, ${namedObjectType.identifierTypeAlias}>(${runtimeObjectType(namedObjectType.filterFunction, namedObjectType)}, query);
95
+ ${methodSignatures.objects.name}Sync(${methodSignatures.objects.parameters}): ${this.reusables.imports.Either}<Error, readonly ${namedObjectType.expression}[]> {
96
+ return this.#objectsSync<${namedObjectType.expression}, ${namedObjectType.filterType}, ${namedObjectType.identifierTypeAlias}>(${runtimeObjectType(namedObjectType.filterFunction, namedObjectType)}, query);
100
97
  }`);
101
98
  }
102
- case "NamedObjectUnion":
99
+ case "ObjectUnion":
103
100
  return delegatingMethods.concat(code `\
104
- ${methodSignatures.objects.name}Sync(${methodSignatures.objects.parameters}): ${this.reusables.imports.Either}<Error, readonly ${namedObjectType.name}[]> {
105
- return this.#objectUnionsSync<${namedObjectType.name}, ${namedObjectType.filterType}, ${namedObjectType.identifierTypeAlias}>([
101
+ ${methodSignatures.objects.name}Sync(${methodSignatures.objects.parameters}): ${this.reusables.imports.Either}<Error, readonly ${namedObjectType.expression}[]> {
102
+ return this.#objectUnionsSync<${namedObjectType.expression}, ${namedObjectType.filterType}, ${namedObjectType.identifierTypeAlias}>([
106
103
  ${joinCode(namedObjectType.members.map((member) => runtimeObjectType(namedObjectType.filterFunction, member.type)), { on: ", " })}
107
104
  ], query);
108
105
  }`);
@@ -1,17 +1,32 @@
1
+ import { Maybe } from "purify-ts";
1
2
  import { AbstractCollectionType } from "./AbstractCollectionType.js";
3
+ import type { AbstractContainerType } from "./AbstractContainerType.js";
2
4
  import { type Code } from "./ts-poet-wrapper.js";
3
5
  export declare class SetType<ItemTypeT extends SetType.ItemType> extends AbstractCollectionType<ItemTypeT> {
4
6
  readonly graphqlArgs: AbstractCollectionType<ItemTypeT>["graphqlArgs"];
5
7
  readonly kind = "Set";
8
+ readonly minCount: bigint;
9
+ readonly jsTypes: readonly [{
10
+ readonly instanceof: "Array";
11
+ readonly typeof: "object";
12
+ }];
13
+ constructor({ minCount, ...superParameters }: {
14
+ minCount: bigint;
15
+ } & ConstructorParameters<typeof AbstractCollectionType<ItemTypeT>>[0]);
16
+ get conversionFunction(): Maybe<AbstractCollectionType.ConversionFunction>;
17
+ get toRdfResourceValueTypes(): AbstractCollectionType<ItemTypeT>["toRdfResourceValueTypes"];
6
18
  get valueSparqlConstructTriplesFunction(): Code;
7
19
  get valueSparqlWherePatternsFunction(): Code;
20
+ protected get schemaInitializers(): readonly Code[];
21
+ fromJsonExpression({ variables, }: Parameters<AbstractContainerType<ItemTypeT>["fromJsonExpression"]>[0]): Code;
8
22
  fromRdfResourceValuesExpression(parameters: Parameters<AbstractCollectionType<ItemTypeT>["fromRdfResourceValuesExpression"]>[0]): Code;
23
+ jsonSchema(parameters: Parameters<AbstractContainerType<ItemTypeT>["jsonSchema"]>[0]): Code;
9
24
  jsonType(): AbstractCollectionType.JsonType;
10
25
  toRdfResourceValuesExpression({ variables, }: Parameters<AbstractCollectionType<ItemTypeT>["toRdfResourceValuesExpression"]>[0]): Code;
11
26
  toStringExpression({ variables, }: Parameters<AbstractCollectionType<ItemTypeT>["toStringExpression"]>[0]): Code;
12
27
  }
13
28
  export declare namespace SetType {
14
29
  type ItemType = AbstractCollectionType.ItemType;
15
- const isItemType: typeof import("./AbstractContainerType.js").AbstractContainerType.isItemType;
30
+ const isItemType: typeof AbstractContainerType.isItemType;
16
31
  }
17
32
  //# sourceMappingURL=SetType.d.ts.map
@@ -5,18 +5,80 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
5
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6
6
  };
7
7
  import { Maybe } from "purify-ts";
8
+ import { invariant } from "ts-invariant";
8
9
  import { Memoize } from "typescript-memoize";
9
10
  import { AbstractCollectionType } from "./AbstractCollectionType.js";
10
- import { code, joinCode } from "./ts-poet-wrapper.js";
11
+ import { code, joinCode, literalOf } from "./ts-poet-wrapper.js";
11
12
  export class SetType extends AbstractCollectionType {
12
13
  graphqlArgs = Maybe.empty();
13
14
  kind = "Set";
15
+ minCount;
16
+ jsTypes = [
17
+ { instanceof: "Array", typeof: "object" },
18
+ ];
19
+ constructor({ minCount, ...superParameters }) {
20
+ super(superParameters);
21
+ this.minCount = minCount;
22
+ invariant(this.minCount >= 0n);
23
+ if (this._mutable) {
24
+ invariant(this.minCount === 0n);
25
+ }
26
+ }
27
+ get conversionFunction() {
28
+ const itemConversionFunction = this.itemType.conversionFunction.orDefault(this.itemConversionFunctionDefault);
29
+ let conversionFunction;
30
+ const sourceTypes = [];
31
+ if (itemConversionFunction.sourceTypes.some((sourceType) => sourceType.jsType.typeof === "object" &&
32
+ sourceType.jsType.instanceof === "Array")) {
33
+ conversionFunction = this.reusables.snippets.convertToArraySet;
34
+ }
35
+ else {
36
+ conversionFunction = this.reusables.snippets.convertToScalarSet;
37
+ // Convert from a single item
38
+ sourceTypes.push(...itemConversionFunction.sourceTypes);
39
+ }
40
+ // Convert from an array of items
41
+ sourceTypes.push({
42
+ expression: code `readonly (${joinCode(itemConversionFunction.sourceTypes.map((itemSourceType) => code `${itemSourceType.expression}`), { on: " | " })})[]`,
43
+ jsType: { instanceof: "Array", typeof: "object" },
44
+ });
45
+ // Convert from undefined to an empty array
46
+ if (this.minCount === 0n) {
47
+ sourceTypes.push({
48
+ expression: code `undefined`,
49
+ jsType: { typeof: "undefined" },
50
+ });
51
+ }
52
+ return Maybe.of({
53
+ code: code `${conversionFunction}(${itemConversionFunction.code}, ${literalOf(!this._mutable)})`,
54
+ sourceTypes,
55
+ });
56
+ }
57
+ get toRdfResourceValueTypes() {
58
+ return this.itemType.toRdfResourceValueTypes;
59
+ }
14
60
  get valueSparqlConstructTriplesFunction() {
15
61
  return code `${this.reusables.snippets.setSparqlConstructTriples}<${this.itemType.filterType}, ${this.itemType.schemaType}>(${this.itemType.valueSparqlConstructTriplesFunction})`;
16
62
  }
17
63
  get valueSparqlWherePatternsFunction() {
18
64
  return code `${this.reusables.snippets.setSparqlWherePatterns}<${this.itemType.filterType}, ${this.itemType.schemaType}>(${this.itemType.valueSparqlWherePatternsFunction})`;
19
65
  }
66
+ get schemaInitializers() {
67
+ let schemaInitializers = super.schemaInitializers;
68
+ if (this.minCount > 0n) {
69
+ schemaInitializers = schemaInitializers.concat(code `minCount: ${Number(this.minCount)}`);
70
+ }
71
+ return schemaInitializers;
72
+ }
73
+ fromJsonExpression({ variables, }) {
74
+ let expression = variables.value;
75
+ if (this.minCount === 0n) {
76
+ expression = code `(${expression} ?? [])`;
77
+ }
78
+ return code `${this.reusables.imports.Either}.sequence<Error, ${this.itemType.expression}>(${expression}.map(item => (${this.itemType.fromJsonExpression({
79
+ variables: { value: code `item` },
80
+ })})))`;
81
+ }
20
82
  fromRdfResourceValuesExpression(parameters) {
21
83
  const { variables } = parameters;
22
84
  return joinCode([
@@ -25,8 +87,21 @@ export class SetType extends AbstractCollectionType {
25
87
  code `map(valuesArray => ${this.reusables.imports.Resource}.Values.fromValue({ focusResource: ${variables.resource}, propertyPath: ${variables.propertyPath}, value: valuesArray }))`,
26
88
  ], { on: "." });
27
89
  }
90
+ jsonSchema(parameters) {
91
+ let schema = code `${this.itemType.jsonSchema(parameters)}.array()`;
92
+ if (this.minCount > 0n) {
93
+ schema = code `${schema}.nonempty().min(${this.minCount})`;
94
+ }
95
+ else {
96
+ schema = code `${schema}.optional()`;
97
+ }
98
+ if (!this._mutable) {
99
+ schema = code `${schema}.readonly()`;
100
+ }
101
+ return schema;
102
+ }
28
103
  jsonType() {
29
- const name = code `${!this.mutable ? "readonly " : ""}(${this.itemType.jsonType().name})[]`;
104
+ const name = code `${!this.mutable ? "readonly " : ""}(${this.itemType.jsonType().expression})[]`;
30
105
  if (this.minCount === 0n) {
31
106
  return new AbstractCollectionType.JsonType(name, { optional: true });
32
107
  }
@@ -41,6 +116,9 @@ export class SetType extends AbstractCollectionType {
41
116
  return code `(${variables.value}.length > 0 ? \`[\${${variables.value}.map(item => (${this.itemType.toStringExpression({ variables: { value: code `item` } })}))}]\` : undefined)`;
42
117
  }
43
118
  }
119
+ __decorate([
120
+ Memoize()
121
+ ], SetType.prototype, "conversionFunction", null);
44
122
  __decorate([
45
123
  Memoize()
46
124
  ], SetType.prototype, "valueSparqlConstructTriplesFunction", null);
@@ -69,7 +69,7 @@ export declare class Snippets {
69
69
  get booleanEquals(): Snippet;
70
70
  get booleanSparqlWherePatterns(): Snippet;
71
71
  get compactRecord(): Snippet;
72
- get convertToArray(): Snippet;
72
+ get convertToArraySet(): Snippet;
73
73
  get convertToBlankNode(): Snippet;
74
74
  get convertToBlankNodeIdentifierProperty(): Snippet;
75
75
  get convertToIdentifier(): Snippet;
@@ -79,8 +79,10 @@ export declare class Snippets {
79
79
  get convertToLazyObject(): Snippet;
80
80
  get convertToLazyObjectOption(): Snippet;
81
81
  get convertToLazyObjectSet(): Snippet;
82
+ get convertToList(): Snippet;
82
83
  get convertToLiteral(): Snippet;
83
84
  get convertToMaybe(): Snippet;
85
+ get convertToScalarSet(): Snippet;
84
86
  get convertWithDefaultValue(): Snippet;
85
87
  get dateEquals(): Snippet;
86
88
  get dateSparqlWherePatterns(): Snippet;
@@ -23,7 +23,7 @@ import { snippets_CollectionFilter } from "./_snippets/snippets_CollectionFilter
23
23
  import { snippets_CollectionSchema } from "./_snippets/snippets_CollectionSchema.js";
24
24
  import { snippets_ConversionFunction } from "./_snippets/snippets_ConversionFunction.js";
25
25
  import { snippets_compactRecord } from "./_snippets/snippets_compactRecord.js";
26
- import { snippets_convertToArray } from "./_snippets/snippets_convertToArray.js";
26
+ import { snippets_convertToArraySet } from "./_snippets/snippets_convertToArraySet.js";
27
27
  import { snippets_convertToBlankNode } from "./_snippets/snippets_convertToBlankNode.js";
28
28
  import { snippets_convertToBlankNodeIdentifierProperty } from "./_snippets/snippets_convertToBlankNodeIdentifierProperty.js";
29
29
  import { snippets_convertToIdentifier } from "./_snippets/snippets_convertToIdentifier.js";
@@ -33,8 +33,10 @@ import { snippets_convertToIriIdentifierProperty } from "./_snippets/snippets_co
33
33
  import { snippets_convertToLazyObject } from "./_snippets/snippets_convertToLazyObject.js";
34
34
  import { snippets_convertToLazyObjectOption } from "./_snippets/snippets_convertToLazyObjectOption.js";
35
35
  import { snippets_convertToLazyObjectSet } from "./_snippets/snippets_convertToLazyObjectSet.js";
36
+ import { snippets_convertToList } from "./_snippets/snippets_convertToList.js";
36
37
  import { snippets_convertToLiteral } from "./_snippets/snippets_convertToLiteral.js";
37
38
  import { snippets_convertToMaybe } from "./_snippets/snippets_convertToMaybe.js";
39
+ import { snippets_convertToScalarSet } from "./_snippets/snippets_convertToScalarSet.js";
38
40
  import { snippets_convertWithDefaultValue } from "./_snippets/snippets_convertWithDefaultValue.js";
39
41
  import { snippets_DateFilter } from "./_snippets/snippets_DateFilter.js";
40
42
  import { snippets_DateSchema } from "./_snippets/snippets_DateSchema.js";
@@ -326,8 +328,8 @@ export class Snippets {
326
328
  get compactRecord() {
327
329
  return this.snippet(snippets_compactRecord);
328
330
  }
329
- get convertToArray() {
330
- return this.snippet(snippets_convertToArray);
331
+ get convertToArraySet() {
332
+ return this.snippet(snippets_convertToArraySet);
331
333
  }
332
334
  get convertToBlankNode() {
333
335
  return this.snippet(snippets_convertToBlankNode);
@@ -356,12 +358,18 @@ export class Snippets {
356
358
  get convertToLazyObjectSet() {
357
359
  return this.snippet(snippets_convertToLazyObjectSet);
358
360
  }
361
+ get convertToList() {
362
+ return this.snippet(snippets_convertToList);
363
+ }
359
364
  get convertToLiteral() {
360
365
  return this.snippet(snippets_convertToLiteral);
361
366
  }
362
367
  get convertToMaybe() {
363
368
  return this.snippet(snippets_convertToMaybe);
364
369
  }
370
+ get convertToScalarSet() {
371
+ return this.snippet(snippets_convertToScalarSet);
372
+ }
365
373
  get convertWithDefaultValue() {
366
374
  return this.snippet(snippets_convertWithDefaultValue);
367
375
  }
@@ -779,7 +787,7 @@ __decorate([
779
787
  ], Snippets.prototype, "compactRecord", null);
780
788
  __decorate([
781
789
  Memoize()
782
- ], Snippets.prototype, "convertToArray", null);
790
+ ], Snippets.prototype, "convertToArraySet", null);
783
791
  __decorate([
784
792
  Memoize()
785
793
  ], Snippets.prototype, "convertToBlankNode", null);
@@ -807,12 +815,18 @@ __decorate([
807
815
  __decorate([
808
816
  Memoize()
809
817
  ], Snippets.prototype, "convertToLazyObjectSet", null);
818
+ __decorate([
819
+ Memoize()
820
+ ], Snippets.prototype, "convertToList", null);
810
821
  __decorate([
811
822
  Memoize()
812
823
  ], Snippets.prototype, "convertToLiteral", null);
813
824
  __decorate([
814
825
  Memoize()
815
826
  ], Snippets.prototype, "convertToMaybe", null);
827
+ __decorate([
828
+ Memoize()
829
+ ], Snippets.prototype, "convertToScalarSet", null);
816
830
  __decorate([
817
831
  Memoize()
818
832
  ], Snippets.prototype, "convertWithDefaultValue", null);
@@ -42,7 +42,7 @@ ${joinCode([...this.namedObjectTypes, ...this.namedObjectUnionTypes].flatMap((na
42
42
  const methodSignatures = this.methodSignatures(namedObjectType, {
43
43
  queryT: `${syntheticNamePrefix}SparqlObjectSet.Query`,
44
44
  });
45
- const runtimeObjectType = namedObjectType.name;
45
+ const runtimeObjectType = namedObjectType.expression;
46
46
  return [
47
47
  code `\
48
48
  async ${methodSignatures.object.name}(${methodSignatures.object.parameters}): ${methodSignatures.object.returnType} {
@@ -58,7 +58,7 @@ async ${methodSignatures.objectIdentifiers.name}(${methodSignatures.objectIdenti
58
58
  }`,
59
59
  code `\
60
60
  async ${methodSignatures.objects.name}(${methodSignatures.objects.parameters}): ${methodSignatures.objects.returnType} {
61
- return this.#objects<${namedObjectType.name}, ${namedObjectType.filterType}, ${namedObjectType.identifierTypeAlias}>(${runtimeObjectType}, query);
61
+ return this.#objects<${namedObjectType.expression}, ${namedObjectType.filterType}, ${namedObjectType.identifierTypeAlias}>(${runtimeObjectType}, query);
62
62
  }`,
63
63
  ];
64
64
  }), { on: "\n\n" })}
@@ -6,11 +6,13 @@ export declare class StringType extends AbstractPrimitiveType<string> {
6
6
  readonly filterType: Code;
7
7
  readonly graphqlType: import("./AbstractType.js").AbstractType.GraphqlType;
8
8
  readonly hashFunction: Code;
9
+ readonly jsTypes: readonly [{
10
+ readonly typeof: "string";
11
+ }];
9
12
  readonly kind = "String";
10
- readonly schemaType: Code;
11
- readonly typeofs: "string"[];
12
13
  readonly valueSparqlWherePatternsFunction: Code;
13
- get name(): string;
14
+ get expression(): Code;
15
+ get schemaType(): Code;
14
16
  jsonSchema(_parameters: Parameters<AbstractPrimitiveType<string>["jsonSchema"]>[0]): Code;
15
17
  literalExpression(literal: Literal | string): Code;
16
18
  toRdfResourceValuesExpression({ variables, }: Parameters<AbstractPrimitiveType<string>["toRdfResourceValuesExpression"]>[0]): Code;
@@ -13,15 +13,21 @@ export class StringType extends AbstractPrimitiveType {
13
13
  filterType = code `${this.reusables.snippets.StringFilter}`;
14
14
  graphqlType = new AbstractPrimitiveType.GraphqlType(code `${this.reusables.imports.GraphQLString}`, this.reusables);
15
15
  hashFunction = code `${this.reusables.snippets.hashString}`;
16
+ jsTypes = [
17
+ {
18
+ typeof: "string",
19
+ },
20
+ ];
16
21
  kind = "String";
17
- schemaType = code `${this.reusables.snippets.StringSchema}<${this.name}>`;
18
- typeofs = ["string"];
19
22
  valueSparqlWherePatternsFunction = code `${this.reusables.snippets.stringSparqlWherePatterns}`;
20
- get name() {
23
+ get expression() {
21
24
  if (this.primitiveIn.length > 0) {
22
- return `${this.primitiveIn.map((value) => `"${value}"`).join(" | ")}`;
25
+ return code `${this.primitiveIn.map((value) => `"${value}"`).join(" | ")}`;
23
26
  }
24
- return `string`;
27
+ return code `string`;
28
+ }
29
+ get schemaType() {
30
+ return code `${this.reusables.snippets.StringSchema}<${this.expression}>`;
25
31
  }
26
32
  jsonSchema(_parameters) {
27
33
  switch (this.primitiveIn.length) {
@@ -48,5 +54,8 @@ export class StringType extends AbstractPrimitiveType {
48
54
  }
49
55
  __decorate([
50
56
  Memoize()
51
- ], StringType.prototype, "name", null);
57
+ ], StringType.prototype, "expression", null);
58
+ __decorate([
59
+ Memoize()
60
+ ], StringType.prototype, "schemaType", null);
52
61
  //# sourceMappingURL=StringType.js.map
@@ -10,16 +10,20 @@ export declare class TermType<ConstantTermT extends Literal | NamedNode = Litera
10
10
  readonly kind = "Term";
11
11
  readonly nodeKinds: ReadonlySet<NodeKind>;
12
12
  readonly schemaType: Code;
13
+ readonly jsTypes: readonly [{
14
+ readonly instanceof: "Object";
15
+ readonly typeof: "object";
16
+ }];
13
17
  readonly valueSparqlWherePatternsFunction: Code;
14
18
  constructor({ nodeKinds, ...superParameters }: ConstructorParameters<typeof AbstractTermType<ConstantTermT, RuntimeTermT>>[0] & {
15
19
  nodeKinds: ReadonlySet<NodeKind>;
16
20
  });
21
+ get expression(): Code;
17
22
  get graphqlType(): AbstractTermType.GraphqlType;
18
- get name(): Code;
19
23
  fromJsonExpression({ variables, }: Parameters<AbstractTermType["fromJsonExpression"]>[0]): Code;
20
24
  graphqlResolveExpression(_parameters: Parameters<AbstractTermType["graphqlResolveExpression"]>[0]): Code;
21
- jsonType(): AbstractTermType.JsonType;
22
25
  jsonSchema(_parameters: Parameters<AbstractTermType["jsonSchema"]>[0]): Code;
26
+ jsonType(): AbstractTermType.JsonType;
23
27
  toJsonExpression({ variables, }: Parameters<AbstractTermType["toJsonExpression"]>[0]): Code;
24
28
  }
25
29
  //# sourceMappingURL=TermType.d.ts.map
@@ -18,6 +18,9 @@ export class TermType extends AbstractTermType {
18
18
  kind = "Term";
19
19
  nodeKinds;
20
20
  schemaType = code `${this.reusables.snippets.TermSchema}`;
21
+ jsTypes = [
22
+ { instanceof: "Object", typeof: "object" },
23
+ ];
21
24
  valueSparqlWherePatternsFunction = code `${this.reusables.snippets.termSparqlWherePatterns}`;
22
25
  constructor({ nodeKinds, ...superParameters }) {
23
26
  super(superParameters);
@@ -25,10 +28,7 @@ export class TermType extends AbstractTermType {
25
28
  invariant(this.nodeKinds.has("Literal") &&
26
29
  (this.nodeKinds.has("BlankNode") || this.nodeKinds.has("IRI")), "should be IdentifierType or LiteralType");
27
30
  }
28
- get graphqlType() {
29
- throw new Error("not implemented");
30
- }
31
- get name() {
31
+ get expression() {
32
32
  return code `(${joinCode([...this.nodeKinds]
33
33
  .map((nodeKind) => {
34
34
  switch (nodeKind) {
@@ -45,8 +45,11 @@ export class TermType extends AbstractTermType {
45
45
  })
46
46
  .map((import_) => code `${import_}`), { on: " | " })})`;
47
47
  }
48
+ get graphqlType() {
49
+ throw new Error("not implemented");
50
+ }
48
51
  fromJsonExpression({ variables, }) {
49
- return code `${this.reusables.imports.Either}.of<Error, ${this.name}>(${[
52
+ return code `${this.reusables.imports.Either}.of<Error, ${this.expression}>(${[
50
53
  ...this.nodeKinds,
51
54
  ].reduce((expression, nodeKind) => {
52
55
  let valueToNodeKind;
@@ -71,12 +74,6 @@ export class TermType extends AbstractTermType {
71
74
  graphqlResolveExpression(_parameters) {
72
75
  throw new Error("not implemented");
73
76
  }
74
- jsonType() {
75
- return new AbstractTermType.JsonType(code `{ readonly "@id": string, readonly termType: ${[...this.nodeKinds]
76
- .filter((nodeKind) => nodeKind !== "Literal")
77
- .map((nodeKind) => `"${NodeKind.toTermType(nodeKind)}"`)
78
- .join(" | ")} } | { readonly "@language"?: string, readonly "@type"?: string, readonly "@value": string, readonly termType: "Literal" }`);
79
- }
80
77
  jsonSchema(_parameters) {
81
78
  return code `${this.reusables.imports.z}.discriminatedUnion("termType", [${joinCode([...this.nodeKinds].map((nodeKind) => {
82
79
  switch (nodeKind) {
@@ -90,6 +87,12 @@ export class TermType extends AbstractTermType {
90
87
  }
91
88
  }), { on: "," })}])`;
92
89
  }
90
+ jsonType() {
91
+ return new AbstractTermType.JsonType(code `{ readonly "@id": string, readonly termType: ${[...this.nodeKinds]
92
+ .filter((nodeKind) => nodeKind !== "Literal")
93
+ .map((nodeKind) => `"${NodeKind.toTermType(nodeKind)}"`)
94
+ .join(" | ")} } | { readonly "@language"?: string, readonly "@type"?: string, readonly "@value": string, readonly termType: "Literal" }`);
95
+ }
93
96
  toJsonExpression({ variables, }) {
94
97
  return [...this.nodeKinds].reduce((expression, nodeKind) => {
95
98
  let valueToNodeKind;
@@ -114,7 +117,7 @@ export class TermType extends AbstractTermType {
114
117
  }
115
118
  __decorate([
116
119
  Memoize()
117
- ], TermType.prototype, "name", null);
120
+ ], TermType.prototype, "expression", null);
118
121
  __decorate([
119
122
  Memoize()
120
123
  ], TermType.prototype, "jsonType", null);
@@ -1,5 +1,5 @@
1
1
  import type { Logger } from "ts-log";
2
- import * as ast from "../../ast/index.js";
2
+ import type * as ast from "../../ast/index.js";
3
3
  import type { Generator } from "../Generator.js";
4
4
  import type { TsFeature } from "./TsFeature.js";
5
5
  export declare class TsGenerator implements Generator {
@@ -1,17 +1,19 @@
1
1
  import { Maybe } from "purify-ts";
2
2
  import { invariant } from "ts-invariant";
3
- import * as ast from "../../ast/index.js";
4
3
  import { BlankNodeType } from "./BlankNodeType.js";
5
4
  import { GraphqlSchema } from "./GraphqlSchema.js";
6
5
  import { IdentifierType } from "./IdentifierType.js";
7
6
  import { IriType } from "./IriType.js";
8
- import { NamedObjectUnionType } from "./NamedObjectUnionType.js";
9
7
  import { ObjectSetType } from "./ObjectSetType.js";
8
+ import { ObjectUnionType } from "./ObjectUnionType.js";
10
9
  import { RdfjsDatasetObjectSetType } from "./RdfjsDatasetObjectSetType.js";
11
10
  import { Reusables } from "./Reusables.js";
12
11
  import { SparqlObjectSetType } from "./SparqlObjectSetType.js";
13
12
  import { TypeFactory } from "./TypeFactory.js";
14
13
  import { code, joinCode } from "./ts-poet-wrapper.js";
14
+ function compareTsNamedType(left, right) {
15
+ return left.alias.unsafeCoerce().localeCompare(right.alias.unsafeCoerce());
16
+ }
15
17
  export class TsGenerator {
16
18
  configuration;
17
19
  logger;
@@ -31,54 +33,77 @@ export class TsGenerator {
31
33
  reusables,
32
34
  });
33
35
  let declarations = [];
34
- for (const namedObjectType of ast_.namedObjectTypes) {
35
- for (const tsImport of namedObjectType.tsImports) {
36
- declarations.push(code `${tsImport}`);
36
+ const tsNamedTypes = [];
37
+ const tsNamedObjectTypes = [];
38
+ const tsNamedObjectUnionTypes = [];
39
+ for (const astNamedType of ast_.namedTypes) {
40
+ const tsNamedType = typeFactory.createType(astNamedType);
41
+ tsNamedTypes.push(tsNamedType);
42
+ if (astNamedType.kind === "Object") {
43
+ for (const tsImport of astNamedType.tsImports) {
44
+ declarations.push(code `${tsImport}`);
45
+ }
37
46
  }
38
- }
39
- for (const astNamedUnionType of ast_.namedUnionTypes) {
40
- if (astNamedUnionType.isObjectUnionType()) {
41
- continue;
47
+ switch (tsNamedType.kind) {
48
+ case "Object":
49
+ tsNamedObjectTypes.push(tsNamedType);
50
+ break;
51
+ case "ObjectUnion":
52
+ tsNamedObjectUnionTypes.push(tsNamedType);
53
+ break;
42
54
  }
43
- declarations = declarations.concat(typeFactory.createType(astNamedUnionType).declaration.toList());
44
55
  }
45
- const namedObjectTypesToposorted = ast.ObjectType.toposort(ast_.namedObjectTypes).map((astObjectType) => typeFactory.createNamedObjectType(astObjectType));
46
- const namedObjectUnionTypesToposorted = ast_.namedUnionTypes
47
- .filter((_) => _.isObjectUnionType())
48
- .map((astObjectUnionType) => typeFactory.createNamedObjectUnionType(astObjectUnionType));
49
- for (const namedObjectType of namedObjectTypesToposorted) {
50
- declarations = declarations.concat(namedObjectType.declaration.toList());
56
+ tsNamedTypes.sort(compareTsNamedType);
57
+ tsNamedObjectTypes.sort(compareTsNamedType);
58
+ tsNamedObjectUnionTypes.sort(compareTsNamedType);
59
+ for (const tsNamedType of tsNamedTypes) {
60
+ switch (tsNamedType.kind) {
61
+ case "ObjectUnion":
62
+ case "Union":
63
+ continue; // Declare compound types last.
64
+ }
65
+ tsNamedType.declaration.ifJust((declaration) => {
66
+ declarations.push(declaration);
67
+ });
51
68
  }
52
- for (const namedObjectUnionType of namedObjectUnionTypesToposorted) {
53
- declarations = declarations.concat(namedObjectUnionType.declaration.toList());
69
+ // Declare compound types last.
70
+ for (const tsNamedType of tsNamedTypes) {
71
+ switch (tsNamedType.kind) {
72
+ case "ObjectUnion":
73
+ case "Union":
74
+ break;
75
+ default:
76
+ continue;
77
+ }
78
+ tsNamedType.declaration.ifJust((declaration) => {
79
+ declarations.push(declaration);
80
+ });
54
81
  }
55
- const namedObjectTypesNameSorted = namedObjectTypesToposorted.toSorted((left, right) => left.name.localeCompare(right.name));
56
- const namedObjectUnionTypesNameSorted = namedObjectUnionTypesToposorted.toSorted((left, right) => left.name.localeCompare(right.name));
57
- switch (namedObjectTypesNameSorted.length) {
82
+ switch (tsNamedObjectTypes.length) {
58
83
  case 0:
59
84
  break;
60
85
  case 1:
61
- declarations.push(code `type ${configuration.syntheticNamePrefix}Object = ${namedObjectTypesNameSorted[0].name};`);
86
+ declarations.push(code `type ${configuration.syntheticNamePrefix}Object = ${tsNamedObjectTypes[0].expression};`);
62
87
  break;
63
88
  default: {
64
89
  const uberObjectUnionType = this.synthesizeUberObjectUnionType({
65
90
  configuration,
66
- namedObjectTypes: namedObjectTypesToposorted.toReversed(), // Reverse topological order so children ane before parents
91
+ namedObjectTypes: tsNamedObjectTypes,
67
92
  reusables,
68
93
  });
69
94
  declarations = declarations.concat(uberObjectUnionType.declaration.toList());
70
- namedObjectUnionTypesNameSorted.push(uberObjectUnionType);
95
+ tsNamedObjectUnionTypes.push(uberObjectUnionType);
71
96
  }
72
97
  }
73
98
  declarations.push(...this.objectSetTypeDeclarations({
74
99
  configuration,
75
- namedObjectTypes: namedObjectTypesNameSorted,
76
- namedObjectUnionTypes: namedObjectUnionTypesNameSorted,
100
+ namedObjectTypes: tsNamedObjectTypes,
101
+ namedObjectUnionTypes: tsNamedObjectUnionTypes,
77
102
  reusables,
78
103
  }));
79
104
  if (configuration.features.has("GraphQL")) {
80
- const graphqlNamedObjectTypes = namedObjectTypesNameSorted.filter((namedObjectType) => !namedObjectType.synthetic);
81
- const graphqlNamedObjectUnionTypes = namedObjectUnionTypesNameSorted.filter((namedObjectUnionType) => !namedObjectUnionType.synthetic);
105
+ const graphqlNamedObjectTypes = tsNamedObjectTypes.filter((tsNamedObjectType) => !tsNamedObjectType.synthetic);
106
+ const graphqlNamedObjectUnionTypes = tsNamedObjectUnionTypes.filter((tsNamedObjectUnionType) => !tsNamedObjectUnionType.synthetic);
82
107
  if (graphqlNamedObjectTypes.length > 0) {
83
108
  declarations.push(new GraphqlSchema({
84
109
  configuration,
@@ -116,7 +141,7 @@ export class TsGenerator {
116
141
  * Synthesize the $Object union.
117
142
  */
118
143
  synthesizeUberObjectUnionType({ configuration, namedObjectTypes, reusables, }) {
119
- const filteredNamedObjectTypes = namedObjectTypes.filter((namedObjectType) => !namedObjectType.extern);
144
+ const filteredNamedObjectTypes = namedObjectTypes.filter((namedObjectType) => !namedObjectType.extern && !namedObjectType.synthetic);
120
145
  invariant(filteredNamedObjectTypes.length > 0);
121
146
  const nodeKinds = filteredNamedObjectTypes.reduce((nodeKinds, namedObjectType) => {
122
147
  for (const nodeKind of namedObjectType.identifierType.nodeKinds) {
@@ -127,6 +152,7 @@ export class TsGenerator {
127
152
  let identifierType;
128
153
  if (nodeKinds.size === 2) {
129
154
  identifierType = new IdentifierType({
155
+ alias: Maybe.empty(),
130
156
  comment: Maybe.empty(),
131
157
  configuration,
132
158
  label: Maybe.empty(),
@@ -138,6 +164,7 @@ export class TsGenerator {
138
164
  switch ([...nodeKinds][0]) {
139
165
  case "BlankNode":
140
166
  identifierType = new BlankNodeType({
167
+ alias: Maybe.empty(),
141
168
  comment: Maybe.empty(),
142
169
  configuration,
143
170
  label: Maybe.empty(),
@@ -147,6 +174,7 @@ export class TsGenerator {
147
174
  break;
148
175
  case "IRI":
149
176
  identifierType = new IriType({
177
+ alias: Maybe.empty(),
150
178
  comment: Maybe.empty(),
151
179
  configuration,
152
180
  hasValues: [],
@@ -158,17 +186,17 @@ export class TsGenerator {
158
186
  break;
159
187
  }
160
188
  }
161
- return new NamedObjectUnionType({
189
+ return new ObjectUnionType({
190
+ alias: Maybe.of(`${configuration.syntheticNamePrefix}Object`),
162
191
  comment: Maybe.empty(),
163
192
  configuration,
164
- identifierType,
193
+ identifierType: Maybe.of(identifierType),
165
194
  label: Maybe.empty(),
166
195
  logger: this.logger,
167
196
  members: filteredNamedObjectTypes.map((namedObjectType) => ({
168
197
  discriminantValue: Maybe.empty(),
169
198
  type: namedObjectType,
170
199
  })),
171
- name: `${configuration.syntheticNamePrefix}Object`,
172
200
  recursive: false,
173
201
  reusables,
174
202
  synthetic: true,