@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
@@ -8,18 +8,22 @@ import { Maybe } from "purify-ts";
8
8
  import { invariant } from "ts-invariant";
9
9
  import { Memoize } from "typescript-memoize";
10
10
  import { AbstractType } from "./AbstractType.js";
11
- import { code, joinCode, literalOf } from "./ts-poet-wrapper.js";
12
- export class AbstractUnionType extends AbstractType {
11
+ import { code, def, joinCode, literalOf, } from "./ts-poet-wrapper.js";
12
+ export class UnionType extends AbstractType {
13
13
  discriminant;
14
+ graphqlArgs = Maybe.empty();
14
15
  identifierType;
16
+ kind = "Union";
15
17
  recursive;
18
+ synthetic;
16
19
  validationFunction = Maybe.empty();
17
- constructor({ identifierType, members, recursive, ...superParameters }) {
20
+ constructor({ identifierType, members, recursive, synthetic, ...superParameters }) {
18
21
  super(superParameters);
19
22
  this.identifierType = identifierType;
20
23
  invariant(members.length >= 2);
21
24
  this.recursive = recursive;
22
25
  this.discriminant = Discriminant.infer(members);
26
+ this.synthetic = synthetic;
23
27
  this.lazyMembers = () => members.map((member, memberI) => {
24
28
  let discriminantValues;
25
29
  invariant(this.discriminant.memberValues.length === members.length);
@@ -28,32 +32,11 @@ export class AbstractUnionType extends AbstractType {
28
32
  discriminantValues = [this.discriminant.memberValues[memberI]];
29
33
  break;
30
34
  case "Hybrid":
31
- discriminantValues =
32
- this.discriminant.memberValues[memberI].ownValues;
35
+ discriminantValues = this.discriminant.memberValues[memberI].values;
33
36
  break;
34
37
  case "Intrinsic": {
35
- // A member type's combined discriminant property values are its "own" values plus any descendant values that are
36
- // not the "own" values of some other member type.
37
- // So if you have type A, type B, and B inherits A, then
38
- // A has
39
- // own discriminant property values: ["A"]
40
- // descendant discriminant property values: ["B"]
41
- // and B has
42
- // own discriminant property values: ["B"]
43
- // descendant discriminant property values ["B"]
44
- // In this case A shouldn't have "B" as a combined discriminant property value since it's "claimed" by B.
45
- const memberOwnDiscriminantPropertyValues = new Set();
46
- for (const member of members) {
47
- for (const ownDiscriminantPropertyValue of member.type.discriminantProperty.unsafeCoerce()
48
- .ownValues) {
49
- memberOwnDiscriminantPropertyValues.add(ownDiscriminantPropertyValue);
50
- }
51
- }
52
- discriminantValues = member.type.discriminantProperty
53
- .unsafeCoerce()
54
- .ownValues.concat(member.type.discriminantProperty
55
- .unsafeCoerce()
56
- .descendantValues.filter((value) => !memberOwnDiscriminantPropertyValues.has(value)));
38
+ discriminantValues =
39
+ member.type.discriminantProperty.unsafeCoerce().values;
57
40
  break;
58
41
  }
59
42
  case "Typeof":
@@ -70,10 +53,9 @@ export class AbstractUnionType extends AbstractType {
70
53
  }
71
54
  if (discriminant.kind === "Intrinsic" && !json) {
72
55
  switch (member.type.kind) {
73
- case "NamedObjectUnion":
74
- case "NamedUnion":
75
- case "NamedObjectType":
76
- return code `${member.type.name}.is${member.type.name}(${instance})`;
56
+ case "Object":
57
+ case "ObjectUnion":
58
+ return code `${member.type.alias.unsafeCoerce()}.is${member.type.alias.unsafeCoerce()}(${instance})`;
77
59
  }
78
60
  }
79
61
  const discriminantName = json
@@ -87,7 +69,7 @@ export class AbstractUnionType extends AbstractType {
87
69
  includeDiscriminantProperty: this.discriminant.kind === "Intrinsic" ||
88
70
  (this.discriminant.kind === "Hybrid" &&
89
71
  this.discriminant.memberValues[memberI].kind === "Intrinsic"),
90
- }).name,
72
+ }).expression,
91
73
  jsonTypeCheck: typeCheck(true),
92
74
  primaryDiscriminantValue: discriminantValues[0],
93
75
  type: member.type,
@@ -133,40 +115,61 @@ export class AbstractUnionType extends AbstractType {
133
115
  return Maybe.of({
134
116
  code: code `${this.reusables.snippets.identityConversionFunction}`,
135
117
  sourceTypes: this.discriminant.kind === "Typeof"
136
- ? this.members.map(({ primaryDiscriminantValue, type }) => ({
137
- name: type.name,
138
- typeof: primaryDiscriminantValue,
139
- }))
118
+ ? this.members.flatMap(({ type }) => type.jsTypes.map((jsType) => ({
119
+ expression: type.expression,
120
+ jsType,
121
+ })))
140
122
  : [
141
123
  {
142
- name: this.name,
143
- typeof: "object",
124
+ expression: this.expression,
125
+ jsType: {
126
+ instanceof: "Object",
127
+ typeof: "object",
128
+ },
144
129
  },
145
130
  ],
146
131
  });
147
132
  }
133
+ get declaration() {
134
+ const alias = this.alias.extract();
135
+ if (!alias) {
136
+ return Maybe.empty();
137
+ }
138
+ const declarations = [];
139
+ if (this.configuration.features.has("Object.type")) {
140
+ declarations.push(code `export type ${def(alias)} = ${this.inlineExpression};`);
141
+ }
142
+ const staticModuleDeclarations = Object.entries(this.staticModuleDeclarations);
143
+ if (staticModuleDeclarations.length > 0) {
144
+ declarations.push(code `\
145
+ export namespace ${def(alias)} {
146
+ ${joinCode(staticModuleDeclarations
147
+ .sort((left, right) => left[0].localeCompare(right[0]))
148
+ .map((_) => _[1]), { on: "\n\n" })}
149
+ }`);
150
+ }
151
+ return Maybe.of(joinCode(declarations, { on: "\n\n" }));
152
+ }
148
153
  get discriminantProperty() {
149
154
  switch (this.discriminant.kind) {
150
155
  case "Extrinsic":
151
156
  return Maybe.of({
152
157
  descendantValues: [],
153
158
  jsonName: this.discriminant.jsonName,
154
- ownValues: this.discriminant.memberValues,
155
159
  name: this.discriminant.name,
160
+ values: this.discriminant.memberValues,
156
161
  });
157
162
  case "Hybrid":
158
163
  return Maybe.of({
159
- descendantValues: [],
160
164
  jsonName: this.discriminant.jsonName,
161
- ownValues: this.discriminant.memberValues.flatMap((_) => _.ownValues),
162
165
  name: "termType",
166
+ values: this.discriminant.memberValues.flatMap((_) => _.values),
163
167
  });
164
168
  case "Intrinsic":
165
169
  return Maybe.of({
166
- descendantValues: this.discriminant.memberValues.flatMap((_) => _.descendantValues),
167
170
  jsonName: this.discriminant.jsonName,
168
171
  name: this.discriminant.name,
169
- ownValues: this.discriminant.memberValues.flatMap((_) => _.ownValues),
172
+ values: this.discriminant.memberValues,
170
173
  });
171
174
  case "Typeof":
172
175
  return Maybe.empty();
@@ -174,12 +177,60 @@ export class AbstractUnionType extends AbstractType {
174
177
  throw this.discriminant;
175
178
  }
176
179
  }
180
+ get equalsFunction() {
181
+ return this.alias
182
+ .map((alias) => code `${alias}.equals`)
183
+ .orDefault(this.inlineEqualsFunction);
184
+ }
185
+ get filterFunction() {
186
+ return this.alias
187
+ .map((alias) => code `${alias}.filter`)
188
+ .orDefault(this.inlineFilterFunction);
189
+ }
190
+ get filterType() {
191
+ return this.alias
192
+ .map((alias) => code `${alias}.Filter`)
193
+ .orDefault(this.inlineFilterType);
194
+ }
195
+ get graphqlType() {
196
+ const alias = this.alias.extract();
197
+ if (!alias ||
198
+ !this.members.every((member) => member.type.kind === "Object")) {
199
+ throw new Error("not implemented");
200
+ }
201
+ return new AbstractType.GraphqlType(code `${alias}.GraphQL`, this.reusables);
202
+ }
203
+ get hashFunction() {
204
+ return this.alias
205
+ .map((alias) => code `${alias}.hash`)
206
+ .orDefault(this.inlineHashFunction);
207
+ }
208
+ get jsonSchemaFunctionDeclaration() {
209
+ const meta = {
210
+ // id: this.name,
211
+ };
212
+ this.comment.ifJust((description) => {
213
+ meta["description"] = description;
214
+ });
215
+ this.label.ifJust((label) => {
216
+ meta["title"] = label;
217
+ });
218
+ return code `export const schema = () => ${this.inlineJsonSchema}.meta(${meta});`;
219
+ }
220
+ get jsonTypeAliasDeclaration() {
221
+ return code `export type Json = ${this.inlineJsonType.expression}`;
222
+ }
177
223
  get members() {
178
224
  return this.lazyMembers();
179
225
  }
180
226
  get mutable() {
181
227
  return this.members.some((member) => member.type.mutable);
182
228
  }
229
+ get expression() {
230
+ return this.alias
231
+ .map((alias) => code `${alias}`)
232
+ .orDefault(this.inlineExpression);
233
+ }
183
234
  get referencesObjectType() {
184
235
  return this.members.some((member) => member.type.referencesObjectType);
185
236
  }
@@ -201,14 +252,32 @@ export class AbstractUnionType extends AbstractType {
201
252
  }
202
253
  return set;
203
254
  }
204
- get typeofs() {
205
- return [...new Set(this.members.flatMap((member) => member.type.typeofs))];
255
+ get jsTypes() {
256
+ const jsTypes = [];
257
+ for (const member of this.members) {
258
+ for (const memberJsType of member.type.jsTypes) {
259
+ if (!jsTypes.some((jsType) => AbstractType.JsType.equals(jsType, memberJsType))) {
260
+ jsTypes.push(memberJsType);
261
+ }
262
+ }
263
+ }
264
+ return jsTypes;
265
+ }
266
+ get valueSparqlConstructTriplesFunction() {
267
+ return this.alias
268
+ .map((alias) => code `${alias}.valueSparqlConstructTriples`)
269
+ .orDefault(this.inlineValueSparqlConstructTriplesFunction);
270
+ }
271
+ get valueSparqlWherePatternsFunction() {
272
+ return this.alias
273
+ .map((alias) => code `${alias}.valueSparqlWherePatterns`)
274
+ .orDefault(this.inlineValueSparqlWherePatternsFunction);
206
275
  }
207
276
  get inlineEqualsFunction() {
208
277
  return code `\
209
- ((left: ${this.name}, right: ${this.name}) => {
278
+ ((left: ${this.expression}, right: ${this.expression}) => {
210
279
  ${joinCode(this.members.map(({ type, typeCheck, unwrap }) => code `if (${typeCheck(code `left`)} && ${typeCheck(code `right`)}) {
211
- return ${type.equalsFunction}(${unwrap(code `left`)} as ${type.name}, ${unwrap(code `right`)} as ${type.name});
280
+ return ${type.equalsFunction}(${unwrap(code `left`)} as ${type.expression}, ${unwrap(code `right`)} as ${type.expression});
212
281
  }`))}
213
282
 
214
283
  return ${this.reusables.imports.Left}({ left, right, propertyName: "type", propertyValuesUnequal: { left: typeof left, right: typeof right, type: "boolean" as const }, type: "property" as const });
@@ -217,7 +286,7 @@ ${joinCode(this.members.map(({ type, typeCheck, unwrap }) => code `if (${typeChe
217
286
  get inlineFilterFunction() {
218
287
  const syntheticNamePrefix = this.configuration.syntheticNamePrefix;
219
288
  return code `\
220
- ((filter: ${this.filterType}, value: ${this.name}) => {
289
+ ((filter: ${this.filterType}, value: ${this.expression}) => {
221
290
  ${joinCode([
222
291
  ...this.identifierType
223
292
  .map((identifierType) => code `\
@@ -246,7 +315,7 @@ if (filter.on?.[${literalOf(primaryDiscriminantValue)}] !== undefined && ${typeC
246
315
  }
247
316
  get inlineFromJsonFunction() {
248
317
  return code `\
249
- ((value: ${this.jsonType().name}): ${this.reusables.imports.Either}<Error, ${this.name}> => {
318
+ ((value: ${this.jsonType().expression}): ${this.reusables.imports.Either}<Error, ${this.expression}> => {
250
319
  ${joinCode(this.members.map(({ jsonType, jsonTypeCheck, type, unwrap, wrap }) => code `if (${jsonTypeCheck(code `value`)}) { return ${type.fromJsonExpression({
251
320
  variables: {
252
321
  value: code `(${unwrap(code `value`)} as ${jsonType})`,
@@ -286,19 +355,19 @@ ${joinCode(this.members.map(({ jsonType, jsonTypeCheck, type, unwrap, wrap }) =>
286
355
  if (this.discriminant.kind === "Extrinsic" ||
287
356
  (this.discriminant.kind === "Hybrid" &&
288
357
  this.discriminant.memberValues[memberI].kind === "Extrinsic")) {
289
- typeExpression = code `${typeExpression}.map(values => values.map(value => ({ ${this.discriminant.name}: ${literalOf(primaryDiscriminantValue)} as const, value }) as (${this.name})))`;
358
+ typeExpression = code `${typeExpression}.map(values => values.map(value => ({ ${this.discriminant.name}: ${literalOf(primaryDiscriminantValue)} as const, value }) as (${this.expression})))`;
290
359
  }
291
- typeExpression = code `(${typeExpression} as ${this.reusables.imports.Either}<Error, ${this.reusables.imports.Resource}.Values<${this.name}>>)`;
360
+ typeExpression = code `(${typeExpression} as ${this.reusables.imports.Either}<Error, ${this.reusables.imports.Resource}.Values<${this.expression}>>)`;
292
361
  return expression !== null
293
362
  ? code `${expression}.altLazy(() => ${typeExpression})`
294
363
  : typeExpression;
295
364
  }, null)}.chain(values => values.head());
296
365
  }))
297
- ) satisfies ${this.reusables.snippets.FromRdfResourceValuesFunction}<${this.name}>)`;
366
+ ) satisfies ${this.reusables.snippets.FromRdfResourceValuesFunction}<${this.expression}>)`;
298
367
  }
299
368
  get inlineHashFunction() {
300
369
  return code `\
301
- (<HasherT extends ${this.reusables.snippets.Hasher}>(hasher: HasherT, value: ${this.name}): HasherT => {
370
+ (<HasherT extends ${this.reusables.snippets.Hasher}>(hasher: HasherT, value: ${this.expression}): HasherT => {
302
371
  ${joinCode(this.members.map(({ type, typeCheck, unwrap }) => code `if (${typeCheck(code `value`)}) { return ${type.hashFunction}(hasher, ${unwrap(code `value`)}); }`))}
303
372
  return hasher;
304
373
  })`;
@@ -356,30 +425,30 @@ ${joinCode(this.members.map(({ type, typeCheck, unwrap }) => code `if (${typeChe
356
425
  throw discriminant;
357
426
  }
358
427
  }
359
- get inlineName() {
428
+ get inlineExpression() {
360
429
  const discriminant = this.discriminant; // To get type narrowing to work
361
430
  switch (discriminant.kind) {
362
431
  case "Extrinsic":
363
- return code `(${joinCode(this.members.map(({ type, primaryDiscriminantValue }) => code `{ ${discriminant.name}: ${literalOf(primaryDiscriminantValue)}, value: ${type.name} }`), { on: "|" })})`;
432
+ return code `(${joinCode(this.members.map(({ type, primaryDiscriminantValue }) => code `{ ${discriminant.name}: ${literalOf(primaryDiscriminantValue)}, value: ${type.expression} }`), { on: "|" })})`;
364
433
  case "Hybrid":
365
434
  return code `(${joinCode(this.members.map(({ primaryDiscriminantValue, type }, memberI) => {
366
435
  switch (discriminant.memberValues[memberI].kind) {
367
436
  case "Extrinsic":
368
- return code `{ ${discriminant.name}: ${literalOf(primaryDiscriminantValue)}, value: ${type.name} }`;
437
+ return code `{ ${discriminant.name}: ${literalOf(primaryDiscriminantValue)}, value: ${type.expression} }`;
369
438
  case "Intrinsic":
370
- return code `${type.name}`;
439
+ return code `${type.expression}`;
371
440
  default:
372
441
  throw new Error();
373
442
  }
374
443
  }), { on: "|" })})`;
375
444
  case "Intrinsic":
376
- // If every type shares a discriminant (e.g., RDF/JS "termType" or generated NamedObjectType "type"),
445
+ // If every type shares a discriminant (e.g., RDF/JS "termType" or generated ObjectType "type"),
377
446
  // just join their names with "|"
378
- return code `(${joinCode(this.members.map(({ type }) => code `${type.name}`), { on: "|" })})`;
447
+ return code `(${joinCode(this.members.map(({ type }) => code `${type.expression}`), { on: "|" })})`;
379
448
  case "Typeof":
380
449
  // The type.name may include literal values, but they should still be unambiguous with other member types since the typeofs
381
450
  // of the different member types are known to be different.
382
- return code `(${joinCode(this.members.map(({ type }) => code `${type.name}`), { on: "|" })})`;
451
+ return code `(${joinCode(this.members.map(({ type }) => code `${type.expression}`), { on: "|" })})`;
383
452
  default:
384
453
  discriminant;
385
454
  throw new Error("should never reach this point");
@@ -387,7 +456,7 @@ ${joinCode(this.members.map(({ type, typeCheck, unwrap }) => code `if (${typeChe
387
456
  }
388
457
  get inlineToJsonFunction() {
389
458
  return code `\
390
- ((value: ${this.name}): ${this.jsonType().name} => {
459
+ ((value: ${this.expression}): ${this.jsonType().expression} => {
391
460
  ${joinCode(this.members.map(({ typeCheck, typeToJsonExpression, unwrap, wrap }) => code `if (${typeCheck(code `value`)}) { return ${wrap(typeToJsonExpression(unwrap(code `value`)))}; }`))}
392
461
 
393
462
  throw new Error("unable to serialize to JSON");
@@ -419,11 +488,11 @@ ${joinCode(this.members.map(({ type, unwrap, typeCheck }) => code `if (${typeChe
419
488
  })}; }`))}
420
489
 
421
490
  throw new Error("unable to serialize to RDF");
422
- }) satisfies ${this.reusables.snippets.ToRdfResourceValuesFunction}<${this.name}>)`;
491
+ }) satisfies ${this.reusables.snippets.ToRdfResourceValuesFunction}<${this.expression}>)`;
423
492
  }
424
493
  get inlineToStringFunction() {
425
494
  return code `\
426
- ((value: ${this.name}): string => {
495
+ ((value: ${this.expression}): string => {
427
496
  ${joinCode(this.members.map(({ type, typeCheck, unwrap }) => code `if (${typeCheck(code `value`)}) { return ${type.toStringExpression({
428
497
  variables: { value: unwrap(code `value`) },
429
498
  })}; }`))}
@@ -459,50 +528,180 @@ unionPatterns.push({ patterns: ${type.valueSparqlWherePatternsFunction}({ ...oth
459
528
  type: type.schema,
460
529
  }}`), { on: "," })} }`);
461
530
  }
531
+ get staticModuleDeclarations() {
532
+ const alias = this.alias.unsafeCoerce();
533
+ const staticModuleDeclarations = {};
534
+ if (this.configuration.features.has("Object.equals")) {
535
+ staticModuleDeclarations[`equals`] =
536
+ code `export const equals = ${this.inlineEqualsFunction};`;
537
+ }
538
+ if (this.configuration.features.has("Object.filter")) {
539
+ staticModuleDeclarations[`Filter`] =
540
+ code `export type Filter = ${this.inlineFilterType};`;
541
+ staticModuleDeclarations[`filter`] =
542
+ code `export const filter = ${this.inlineFilterFunction};`;
543
+ }
544
+ if (this.configuration.features.has("Object.hash")) {
545
+ staticModuleDeclarations[`hash`] =
546
+ code `export const hash = ${this.inlineHashFunction};`;
547
+ }
548
+ if (this.configuration.features.has("Object.JSON.type")) {
549
+ staticModuleDeclarations[`Json.type`] =
550
+ code `${this.jsonTypeAliasDeclaration}`;
551
+ }
552
+ if (this.configuration.features.has("Object.JSON.schema")) {
553
+ staticModuleDeclarations[`Json.namespace`] = code `\
554
+ export namespace Json {
555
+ ${this.jsonSchemaFunctionDeclaration}
556
+
557
+ export function parse(json: unknown): ${this.reusables.imports.Either}<Error, Json> {
558
+ const jsonSafeParseResult = schema().safeParse(json);
559
+ if (!jsonSafeParseResult.success) { return ${this.reusables.imports.Left}(jsonSafeParseResult.error); }
560
+ return ${this.reusables.imports.Right}(jsonSafeParseResult.data);
561
+ }
562
+ }`;
563
+ }
564
+ if (this.configuration.features.has("Object.fromJson")) {
565
+ staticModuleDeclarations[`fromJson`] =
566
+ code `export const fromJson = ${this.inlineFromJsonFunction};`;
567
+ }
568
+ if (this.configuration.features.has("Object.fromRdf")) {
569
+ staticModuleDeclarations[`fromRdfResourceValues`] =
570
+ code `export const fromRdfResourceValues: ${this.reusables.snippets.FromRdfResourceValuesFunction}<${alias}> = ${this.inlineFromRdfResourceValuesFunction};`;
571
+ }
572
+ if (this.configuration.features.has("Object.toJson")) {
573
+ staticModuleDeclarations[`toJson`] =
574
+ code `export const toJson = ${this.inlineToJsonFunction};`;
575
+ }
576
+ if (this.configuration.features.has("Object.toRdf")) {
577
+ staticModuleDeclarations[`toRdfResourceValues`] =
578
+ code `export const toRdfResourceValues = ${this.inlineToRdfResourceValuesFunction};`;
579
+ }
580
+ if (this.configuration.features.has("Object.SPARQL")) {
581
+ staticModuleDeclarations[`valueSparqlConstructTriples`] =
582
+ code `export const valueSparqlConstructTriples: ${this.reusables.snippets.ValueSparqlConstructTriplesFunction}<${this.filterType}, ${this.schemaType}> = ${this.inlineValueSparqlConstructTriplesFunction};`;
583
+ staticModuleDeclarations[`valueSparqlWherePatterns`] =
584
+ code `export const valueSparqlWherePatterns: ${this.reusables.snippets.ValueSparqlWherePatternsFunction}<${this.filterType}, ${this.schemaType}> = ${this.inlineValueSparqlWherePatternsFunction};`;
585
+ }
586
+ if (this.configuration.features.has("Object.toString")) {
587
+ const syntheticNamePrefix = this.configuration.syntheticNamePrefix;
588
+ staticModuleDeclarations[`${syntheticNamePrefix}toString`] =
589
+ code `export const ${syntheticNamePrefix}toString = ${this.inlineToStringFunction};`;
590
+ }
591
+ return staticModuleDeclarations;
592
+ }
593
+ fromJsonExpression({ variables, }) {
594
+ return code `${this.alias.map((alias) => code `${alias}.fromJson`).orDefault(this.inlineFromJsonFunction)}(${variables.value})`;
595
+ }
596
+ fromRdfResourceValuesExpression({ variables, }) {
597
+ const { resourceValues: resourceValuesVariable, ...fromRdfResourceValuesOptionsTemp } = variables;
598
+ const fromRdfResourceValuesOptions = fromRdfResourceValuesOptionsTemp;
599
+ if (!this.configuration.features.has("ObjectSet")) {
600
+ delete fromRdfResourceValuesOptions["objectSet"];
601
+ }
602
+ return code `${this.alias.map((alias) => code `${alias}.fromRdfResourceValues`).orDefault(this.inlineFromRdfResourceValuesFunction)}(${resourceValuesVariable}, ${fromRdfResourceValuesOptions})`;
603
+ }
604
+ graphqlResolveExpression({ variables, }) {
605
+ return variables.value;
606
+ }
607
+ jsonSchema({ context, }) {
608
+ const expression = this.alias
609
+ .map((alias) => code `${alias}.Json.schema()`)
610
+ .orDefault(this.inlineJsonSchema);
611
+ if (context === "property" && this.recursive) {
612
+ return code `${this.reusables.imports.z}.lazy((): ${this.reusables.imports.z}.ZodType<${this.jsonType().expression}> => ${expression})`;
613
+ }
614
+ return expression;
615
+ }
616
+ jsonType() {
617
+ return this.alias
618
+ .map((alias) => new AbstractType.JsonType(code `${alias}.Json`))
619
+ .orDefault(this.inlineJsonType);
620
+ }
462
621
  jsonUiSchemaElement() {
463
622
  return Maybe.empty();
464
623
  }
624
+ toJsonExpression({ variables, }) {
625
+ return code `${this.alias.map((alias) => code `${alias}.toJson`).orDefault(this.inlineToJsonFunction)}(${variables.value})`;
626
+ }
627
+ toRdfResourceValuesExpression({ variables, }) {
628
+ const { value: valueVariable, ...otherVariables } = variables;
629
+ return code `${this.alias.map((alias) => code `${alias}.toRdfResourceValues`).orDefault(this.inlineToRdfResourceValuesFunction)}(${valueVariable}, ${otherVariables})`;
630
+ }
631
+ toStringExpression({ variables, }) {
632
+ return code `${this.alias.map((alias) => code `${alias}.${this.configuration.syntheticNamePrefix}toString`).orDefault(this.inlineToStringFunction)}(${variables.value})`;
633
+ }
465
634
  lazyMembers;
466
635
  }
467
636
  __decorate([
468
637
  Memoize()
469
- ], AbstractUnionType.prototype, "conversionFunction", null);
638
+ ], UnionType.prototype, "conversionFunction", null);
639
+ __decorate([
640
+ Memoize()
641
+ ], UnionType.prototype, "declaration", null);
642
+ __decorate([
643
+ Memoize()
644
+ ], UnionType.prototype, "discriminantProperty", null);
645
+ __decorate([
646
+ Memoize()
647
+ ], UnionType.prototype, "equalsFunction", null);
648
+ __decorate([
649
+ Memoize()
650
+ ], UnionType.prototype, "filterFunction", null);
651
+ __decorate([
652
+ Memoize()
653
+ ], UnionType.prototype, "filterType", null);
654
+ __decorate([
655
+ Memoize()
656
+ ], UnionType.prototype, "graphqlType", null);
657
+ __decorate([
658
+ Memoize()
659
+ ], UnionType.prototype, "hashFunction", null);
470
660
  __decorate([
471
661
  Memoize()
472
- ], AbstractUnionType.prototype, "discriminantProperty", null);
662
+ ], UnionType.prototype, "members", null);
473
663
  __decorate([
474
664
  Memoize()
475
- ], AbstractUnionType.prototype, "members", null);
665
+ ], UnionType.prototype, "mutable", null);
476
666
  __decorate([
477
667
  Memoize()
478
- ], AbstractUnionType.prototype, "mutable", null);
668
+ ], UnionType.prototype, "expression", null);
479
669
  __decorate([
480
670
  Memoize()
481
- ], AbstractUnionType.prototype, "toRdfResourceValueTypes", null);
671
+ ], UnionType.prototype, "toRdfResourceValueTypes", null);
482
672
  __decorate([
483
673
  Memoize()
484
- ], AbstractUnionType.prototype, "typeofs", null);
674
+ ], UnionType.prototype, "jsTypes", null);
485
675
  __decorate([
486
676
  Memoize()
487
- ], AbstractUnionType.prototype, "inlineEqualsFunction", null);
677
+ ], UnionType.prototype, "valueSparqlConstructTriplesFunction", null);
488
678
  __decorate([
489
679
  Memoize()
490
- ], AbstractUnionType.prototype, "inlineFilterFunction", null);
680
+ ], UnionType.prototype, "valueSparqlWherePatternsFunction", null);
491
681
  __decorate([
492
682
  Memoize()
493
- ], AbstractUnionType.prototype, "inlineFilterType", null);
683
+ ], UnionType.prototype, "inlineEqualsFunction", null);
494
684
  __decorate([
495
685
  Memoize()
496
- ], AbstractUnionType.prototype, "inlineJsonType", null);
686
+ ], UnionType.prototype, "inlineFilterFunction", null);
497
687
  __decorate([
498
688
  Memoize()
499
- ], AbstractUnionType.prototype, "inlineName", null);
689
+ ], UnionType.prototype, "inlineFilterType", null);
500
690
  __decorate([
501
691
  Memoize()
502
- ], AbstractUnionType.prototype, "inlineValueSparqlConstructTriplesFunction", null);
692
+ ], UnionType.prototype, "inlineJsonType", null);
503
693
  __decorate([
504
694
  Memoize()
505
- ], AbstractUnionType.prototype, "inlineValueSparqlWherePatternsFunction", null);
695
+ ], UnionType.prototype, "inlineExpression", null);
696
+ __decorate([
697
+ Memoize()
698
+ ], UnionType.prototype, "inlineValueSparqlConstructTriplesFunction", null);
699
+ __decorate([
700
+ Memoize()
701
+ ], UnionType.prototype, "inlineValueSparqlWherePatternsFunction", null);
702
+ __decorate([
703
+ Memoize()
704
+ ], UnionType.prototype, "jsonType", null);
506
705
  function termTypes(type) {
507
706
  switch (type.kind) {
508
707
  case "BlankNode":
@@ -532,7 +731,7 @@ export var Discriminant;
532
731
  // intrinsic
533
732
  {
534
733
  let inlineDiscriminantProperty;
535
- const memberValues = [];
734
+ let memberValues = [];
536
735
  for (const memberType of memberTypes) {
537
736
  const memberTypeDiscriminantProperty = memberType.discriminantProperty.extract();
538
737
  if (!memberTypeDiscriminantProperty) {
@@ -547,10 +746,7 @@ export var Discriminant;
547
746
  inlineDiscriminantProperty = undefined;
548
747
  break;
549
748
  }
550
- memberValues.push({
551
- descendantValues: memberTypeDiscriminantProperty.descendantValues,
552
- ownValues: memberTypeDiscriminantProperty.ownValues,
553
- });
749
+ memberValues = memberValues.concat(memberTypeDiscriminantProperty.values);
554
750
  }
555
751
  if (inlineDiscriminantProperty) {
556
752
  return {
@@ -563,15 +759,17 @@ export var Discriminant;
563
759
  }
564
760
  // typeof
565
761
  {
762
+ const memberTypeofs = [];
566
763
  const memberTypeofsSet = new Set();
567
764
  for (const memberType of memberTypes) {
568
- for (const memberTypeof of memberType.typeofs) {
569
- memberTypeofsSet.add(memberTypeof);
765
+ for (const memberJsType of memberType.jsTypes) {
766
+ memberTypeofs.push(memberJsType.typeof);
767
+ memberTypeofsSet.add(memberJsType.typeof);
570
768
  }
571
769
  }
572
770
  if (memberTypeofsSet.size === memberTypes.length) {
573
771
  return {
574
- memberValues: memberTypes.flatMap((memberType) => memberType.typeofs),
772
+ memberValues: memberTypeofs,
575
773
  kind: "Typeof",
576
774
  };
577
775
  }
@@ -579,15 +777,15 @@ export var Discriminant;
579
777
  // hybrid
580
778
  // If some member type is an RDF/JS term then reuse "termType" as the discriminant.
581
779
  if (memberTypes.some((memberType) => termTypes(memberType).size > 0)) {
582
- const extrinsicMemberTypeNamesSet = new Set();
780
+ const extrinsicMemberTypeAliasesSet = new Set();
583
781
  let extrinsicMemberTypeCount = 0;
584
782
  for (const memberType of memberTypes) {
585
783
  if (termTypes(memberType).size > 0) {
586
784
  continue;
587
785
  }
588
786
  extrinsicMemberTypeCount++;
589
- if (typeof memberType.name === "string") {
590
- extrinsicMemberTypeNamesSet.add(memberType.name);
787
+ if (memberType.alias.isJust()) {
788
+ extrinsicMemberTypeAliasesSet.add(memberType.alias.extract());
591
789
  }
592
790
  else {
593
791
  break;
@@ -601,13 +799,13 @@ export var Discriminant;
601
799
  if (memberTermTypes.size > 0) {
602
800
  return {
603
801
  kind: "Intrinsic",
604
- ownValues: [...memberTermTypes],
802
+ values: [...memberTermTypes],
605
803
  };
606
804
  }
607
805
  return {
608
806
  kind: "Extrinsic",
609
- ownValues: extrinsicMemberTypeNamesSet.size === extrinsicMemberTypeCount
610
- ? [memberType.name]
807
+ values: extrinsicMemberTypeAliasesSet.size === extrinsicMemberTypeCount
808
+ ? [memberType.alias.unsafeCoerce()]
611
809
  : [memberTypeI.toString()],
612
810
  };
613
811
  }),
@@ -618,21 +816,14 @@ export var Discriminant;
618
816
  {
619
817
  let memberValues;
620
818
  {
621
- const memberTypeNames = memberTypes.map((memberType) => memberType.name);
622
- if (memberTypeNames.every((memberTypeName) => typeof memberTypeName === "string")) {
623
- const memberTypeNamesSet = new Set(memberTypeNames);
624
- if (memberTypeNamesSet.size === memberTypeNames.length) {
625
- memberValues = memberTypeNames;
626
- }
627
- else {
628
- // Otherwise prefix the non-unique strings with an index and use those as the discriminant values.
629
- memberValues = memberTypeNames.map((memberTypeName, memberTypeI) => `${memberTypeI}-${memberTypeName}`);
630
- }
819
+ const memberTypeNames = memberTypes.map((memberType) => memberType.alias.orDefault(memberType.jsTypes[0].typeof));
820
+ const memberTypeNamesSet = new Set(memberTypeNames);
821
+ if (memberTypeNamesSet.size === memberTypeNames.length) {
822
+ memberValues = memberTypeNames;
631
823
  }
632
824
  else {
633
- // At least one member type name is Code
634
- // Use member type indices as the discriminant values.
635
- memberValues = memberTypes.map((_, memberTypeI) => memberTypeI);
825
+ // Otherwise prefix the non-unique strings with an index and use those as the discriminant values.
826
+ memberValues = memberTypeNames.map((memberTypeName, memberTypeI) => `${memberTypeI}-${memberTypeName}`);
636
827
  }
637
828
  }
638
829
  invariant(memberValues.length === memberTypes.length);
@@ -640,10 +831,10 @@ export var Discriminant;
640
831
  jsonName: "type",
641
832
  kind: "Extrinsic",
642
833
  name: "type",
643
- memberValues: memberValues,
834
+ memberValues,
644
835
  };
645
836
  }
646
837
  }
647
838
  Discriminant.infer = infer;
648
839
  })(Discriminant || (Discriminant = {}));
649
- //# sourceMappingURL=AbstractUnionType.js.map
840
+ //# sourceMappingURL=UnionType.js.map