@shaclmate/compiler 2.0.22 → 2.0.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (194) hide show
  1. package/dist/ShapesGraphToAstTransformer.d.ts +6 -5
  2. package/dist/ShapesGraphToAstTransformer.js +61 -17
  3. package/dist/_ShapesGraphToAstTransformer/InheritableShapeConstraints.d.ts +2 -0
  4. package/dist/_ShapesGraphToAstTransformer/InheritableShapeConstraints.js +2 -0
  5. package/dist/_ShapesGraphToAstTransformer/ShapeStack.d.ts +15 -0
  6. package/dist/_ShapesGraphToAstTransformer/ShapeStack.js +51 -0
  7. package/dist/_ShapesGraphToAstTransformer/flattenAstObjectCompositeTypeMemberTypes.d.ts +13 -0
  8. package/dist/_ShapesGraphToAstTransformer/flattenAstObjectCompositeTypeMemberTypes.js +51 -0
  9. package/dist/_ShapesGraphToAstTransformer/index.d.ts +5 -5
  10. package/dist/_ShapesGraphToAstTransformer/index.js +5 -5
  11. package/dist/_ShapesGraphToAstTransformer/shapeAstName.js +53 -12
  12. package/dist/_ShapesGraphToAstTransformer/transformNodeShapeToAstType.d.ts +5 -0
  13. package/dist/_ShapesGraphToAstTransformer/transformNodeShapeToAstType.js +130 -54
  14. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstObjectTypeProperty.js +175 -5
  15. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstCompositeType.d.ts +10 -0
  16. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstCompositeType.js +185 -0
  17. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstIdentifierType.d.ts +10 -0
  18. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstIdentifierType.js +32 -0
  19. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstLiteralType.d.ts +10 -0
  20. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstLiteralType.js +46 -0
  21. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstTermType.d.ts +12 -0
  22. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstTermType.js +24 -0
  23. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstType.d.ts +13 -0
  24. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstType.js +14 -0
  25. package/dist/ast/Ast.d.ts +0 -1
  26. package/dist/ast/Curie.d.ts +14 -0
  27. package/dist/ast/Curie.js +21 -0
  28. package/dist/ast/IdentifierType.d.ts +3 -2
  29. package/dist/ast/ListType.d.ts +2 -1
  30. package/dist/ast/LiteralType.d.ts +1 -1
  31. package/dist/ast/Name.d.ts +40 -5
  32. package/dist/ast/ObjectCompositeType.d.ts +11 -0
  33. package/dist/ast/ObjectType.d.ts +18 -13
  34. package/dist/ast/ObjectUnionType.d.ts +0 -11
  35. package/dist/ast/OptionType.d.ts +2 -4
  36. package/dist/ast/SetType.d.ts +2 -7
  37. package/dist/ast/TermType.d.ts +12 -4
  38. package/dist/ast/Type.d.ts +1 -1
  39. package/dist/ast/index.d.ts +1 -0
  40. package/dist/ast/index.js +1 -0
  41. package/dist/enums/TsFeature.d.ts +1 -4
  42. package/dist/enums/TsFeature.js +1 -15
  43. package/dist/generators/json/AstJsonGenerator.js +26 -4
  44. package/dist/generators/ts/BooleanType.d.ts +4 -2
  45. package/dist/generators/ts/BooleanType.js +12 -3
  46. package/dist/generators/ts/DateTimeType.d.ts +9 -8
  47. package/dist/generators/ts/DateTimeType.js +32 -8
  48. package/dist/generators/ts/DateType.d.ts +5 -2
  49. package/dist/generators/ts/DateType.js +15 -1
  50. package/dist/generators/ts/DeclaredType.d.ts +2 -2
  51. package/dist/generators/ts/DeclaredType.js +2 -2
  52. package/dist/generators/ts/FloatType.d.ts +6 -0
  53. package/dist/generators/ts/FloatType.js +18 -0
  54. package/dist/generators/ts/IdentifierType.d.ts +17 -7
  55. package/dist/generators/ts/IdentifierType.js +112 -18
  56. package/dist/generators/ts/Import.d.ts +2 -0
  57. package/dist/generators/ts/Import.js +10 -0
  58. package/dist/generators/ts/IntType.d.ts +6 -0
  59. package/dist/generators/ts/IntType.js +18 -0
  60. package/dist/generators/ts/ListType.d.ts +15 -12
  61. package/dist/generators/ts/ListType.js +113 -61
  62. package/dist/generators/ts/LiteralType.d.ts +17 -9
  63. package/dist/generators/ts/LiteralType.js +92 -17
  64. package/dist/generators/ts/NumberType.d.ts +3 -2
  65. package/dist/generators/ts/NumberType.js +8 -3
  66. package/dist/generators/ts/ObjectType.d.ts +65 -43
  67. package/dist/generators/ts/ObjectType.js +143 -123
  68. package/dist/generators/ts/ObjectUnionType.d.ts +50 -8
  69. package/dist/generators/ts/ObjectUnionType.js +303 -101
  70. package/dist/generators/ts/OptionType.d.ts +14 -10
  71. package/dist/generators/ts/OptionType.js +62 -34
  72. package/dist/generators/ts/PrimitiveType.d.ts +23 -5
  73. package/dist/generators/ts/PrimitiveType.js +34 -6
  74. package/dist/generators/ts/SetType.d.ts +17 -13
  75. package/dist/generators/ts/SetType.js +76 -44
  76. package/dist/generators/ts/SnippetDeclarations.d.ts +13 -8
  77. package/dist/generators/ts/SnippetDeclarations.js +226 -101
  78. package/dist/generators/ts/StringType.d.ts +4 -2
  79. package/dist/generators/ts/StringType.js +20 -8
  80. package/dist/generators/ts/TermType.d.ts +29 -33
  81. package/dist/generators/ts/TermType.js +89 -68
  82. package/dist/generators/ts/TsGenerator.d.ts +2 -1
  83. package/dist/generators/ts/TsGenerator.js +26 -12
  84. package/dist/generators/ts/Type.d.ts +100 -32
  85. package/dist/generators/ts/Type.js +58 -54
  86. package/dist/generators/ts/TypeFactory.d.ts +12 -5
  87. package/dist/generators/ts/TypeFactory.js +380 -226
  88. package/dist/generators/ts/UnionType.d.ts +14 -10
  89. package/dist/generators/ts/UnionType.js +319 -142
  90. package/dist/generators/ts/_ObjectType/EagerShaclProperty.d.ts +12 -0
  91. package/dist/generators/ts/_ObjectType/EagerShaclProperty.js +31 -0
  92. package/dist/generators/ts/_ObjectType/IdentifierPrefixProperty.d.ts +13 -12
  93. package/dist/generators/ts/_ObjectType/IdentifierPrefixProperty.js +59 -46
  94. package/dist/generators/ts/_ObjectType/IdentifierProperty.d.ts +20 -13
  95. package/dist/generators/ts/_ObjectType/IdentifierProperty.js +198 -140
  96. package/dist/generators/ts/_ObjectType/LazyShaclProperty.d.ts +100 -0
  97. package/dist/generators/ts/_ObjectType/LazyShaclProperty.js +315 -0
  98. package/dist/generators/ts/_ObjectType/Property.d.ts +47 -46
  99. package/dist/generators/ts/_ObjectType/Property.js +1 -10
  100. package/dist/generators/ts/_ObjectType/ShaclProperty.d.ts +25 -30
  101. package/dist/generators/ts/_ObjectType/ShaclProperty.js +120 -85
  102. package/dist/generators/ts/_ObjectType/TypeDiscriminatorProperty.d.ts +21 -17
  103. package/dist/generators/ts/_ObjectType/TypeDiscriminatorProperty.js +61 -53
  104. package/dist/generators/ts/_ObjectType/classDeclaration.js +22 -17
  105. package/dist/generators/ts/_ObjectType/createFunctionDeclaration.js +26 -13
  106. package/dist/generators/ts/_ObjectType/equalsFunctionOrMethodDeclaration.js +8 -5
  107. package/dist/generators/ts/_ObjectType/fromRdfTypeVariableStatement.d.ts +1 -1
  108. package/dist/generators/ts/_ObjectType/fromRdfTypeVariableStatement.js +8 -5
  109. package/dist/generators/ts/_ObjectType/graphqlTypeVariableStatement.d.ts +5 -0
  110. package/dist/generators/ts/_ObjectType/graphqlTypeVariableStatement.js +49 -0
  111. package/dist/generators/ts/_ObjectType/hashFunctionOrMethodDeclarations.js +7 -8
  112. package/dist/generators/ts/_ObjectType/identifierTypeDeclarations.d.ts +7 -0
  113. package/dist/generators/ts/_ObjectType/identifierTypeDeclarations.js +54 -0
  114. package/dist/generators/ts/_ObjectType/index.d.ts +9 -7
  115. package/dist/generators/ts/_ObjectType/index.js +9 -7
  116. package/dist/generators/ts/_ObjectType/interfaceDeclaration.js +1 -1
  117. package/dist/generators/ts/_ObjectType/jsonFunctionDeclarations.d.ts +4 -0
  118. package/dist/generators/ts/_ObjectType/jsonFunctionDeclarations.js +189 -0
  119. package/dist/generators/ts/_ObjectType/jsonTypeAliasDeclaration.d.ts +5 -0
  120. package/dist/generators/ts/_ObjectType/jsonTypeAliasDeclaration.js +28 -0
  121. package/dist/generators/ts/_ObjectType/objectSetMethodNames.d.ts +9 -0
  122. package/dist/generators/ts/_ObjectType/objectSetMethodNames.js +18 -0
  123. package/dist/generators/ts/_ObjectType/propertiesVariableStatement.d.ts +5 -0
  124. package/dist/generators/ts/_ObjectType/propertiesVariableStatement.js +37 -0
  125. package/dist/generators/ts/_ObjectType/rdfFunctionDeclarations.d.ts +4 -0
  126. package/dist/generators/ts/_ObjectType/rdfFunctionDeclarations.js +144 -0
  127. package/dist/generators/ts/_ObjectType/sparqlConstructQueryFunctionDeclaration.d.ts +1 -1
  128. package/dist/generators/ts/_ObjectType/sparqlConstructQueryFunctionDeclaration.js +6 -5
  129. package/dist/generators/ts/_ObjectType/sparqlConstructQueryStringFunctionDeclaration.d.ts +1 -1
  130. package/dist/generators/ts/_ObjectType/sparqlConstructQueryStringFunctionDeclaration.js +4 -3
  131. package/dist/generators/ts/_ObjectType/sparqlFunctionDeclarations.js +109 -37
  132. package/dist/generators/ts/_ObjectType/toJsonFunctionOrMethodDeclaration.js +6 -6
  133. package/dist/generators/ts/_ObjectType/toRdfFunctionOrMethodDeclaration.js +33 -24
  134. package/dist/generators/ts/graphqlSchemaVariableStatement.d.ts +9 -0
  135. package/dist/generators/ts/graphqlSchemaVariableStatement.js +86 -0
  136. package/dist/generators/ts/objectSetDeclarations.d.ts +8 -0
  137. package/dist/generators/ts/objectSetDeclarations.js +59 -0
  138. package/dist/generators/ts/objectSetInterfaceDeclaration.d.ts +8 -0
  139. package/dist/generators/ts/objectSetInterfaceDeclaration.js +46 -0
  140. package/dist/generators/ts/objectSetMethodSignatures.d.ts +11 -0
  141. package/dist/generators/ts/objectSetMethodSignatures.js +52 -0
  142. package/dist/generators/ts/rdfjsDatasetObjectSetClassDeclaration.d.ts +8 -0
  143. package/dist/generators/ts/rdfjsDatasetObjectSetClassDeclaration.js +393 -0
  144. package/dist/generators/ts/rdfjsTermExpression.d.ts +3 -0
  145. package/dist/generators/ts/rdfjsTermExpression.js +57 -0
  146. package/dist/generators/ts/sparqlObjectSetClassDeclaration.d.ts +8 -0
  147. package/dist/generators/ts/sparqlObjectSetClassDeclaration.js +415 -0
  148. package/dist/generators/ts/syntheticNamePrefix.d.ts +2 -0
  149. package/dist/generators/ts/syntheticNamePrefix.js +2 -0
  150. package/dist/generators/ts/tsName.js +27 -13
  151. package/dist/generators/ts/unsupportedObjectSetMethodDeclarations.d.ts +10 -0
  152. package/dist/generators/ts/unsupportedObjectSetMethodDeclarations.js +19 -0
  153. package/dist/input/NodeShape.d.ts +6 -8
  154. package/dist/input/NodeShape.js +20 -44
  155. package/dist/input/Ontology.d.ts +0 -3
  156. package/dist/input/Ontology.js +0 -9
  157. package/dist/input/PropertyPath.d.ts +5 -5
  158. package/dist/input/PropertyPath.js +14 -24
  159. package/dist/input/PropertyShape.d.ts +3 -1
  160. package/dist/input/PropertyShape.js +8 -2
  161. package/dist/input/ShapesGraph.js +4 -8
  162. package/dist/input/generated.d.ts +967 -107
  163. package/dist/input/generated.js +2548 -1046
  164. package/dist/input/tsFeatures.d.ts +3 -2
  165. package/dist/input/tsFeatures.js +44 -27
  166. package/package.json +18 -16
  167. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstCompositeType.d.ts +0 -13
  168. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstCompositeType.js +0 -200
  169. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstIdentifierType.d.ts +0 -12
  170. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstIdentifierType.js +0 -29
  171. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstLiteralType.d.ts +0 -12
  172. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstLiteralType.js +0 -43
  173. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstTermType.d.ts +0 -14
  174. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstTermType.js +0 -21
  175. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstType.d.ts +0 -16
  176. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstType.js +0 -60
  177. package/dist/generators/ts/_ObjectType/fromJsonFunctionDeclarations.d.ts +0 -4
  178. package/dist/generators/ts/_ObjectType/fromJsonFunctionDeclarations.js +0 -78
  179. package/dist/generators/ts/_ObjectType/fromRdfFunctionDeclarations.d.ts +0 -4
  180. package/dist/generators/ts/_ObjectType/fromRdfFunctionDeclarations.js +0 -91
  181. package/dist/generators/ts/_ObjectType/jsonSchemaFunctionDeclaration.d.ts +0 -5
  182. package/dist/generators/ts/_ObjectType/jsonSchemaFunctionDeclaration.js +0 -19
  183. package/dist/generators/ts/_ObjectType/jsonUiSchemaFunctionDeclaration.d.ts +0 -5
  184. package/dist/generators/ts/_ObjectType/jsonUiSchemaFunctionDeclaration.js +0 -31
  185. package/dist/generators/ts/_ObjectType/jsonZodSchemaFunctionDeclaration.d.ts +0 -5
  186. package/dist/generators/ts/_ObjectType/jsonZodSchemaFunctionDeclaration.js +0 -37
  187. package/dist/generators/ts/_ObjectType/rdfjsTermExpression.d.ts +0 -6
  188. package/dist/generators/ts/_ObjectType/rdfjsTermExpression.js +0 -17
  189. package/dist/generators/ts/_ObjectType/toJsonFunctionDeclaration.d.ts +0 -5
  190. package/dist/generators/ts/_ObjectType/toJsonFunctionDeclaration.js +0 -19
  191. package/dist/generators/ts/_ObjectType/toJsonReturnType.d.ts +0 -3
  192. package/dist/generators/ts/_ObjectType/toJsonReturnType.js +0 -17
  193. package/dist/generators/ts/_ObjectType/toRdfFunctionDeclaration.d.ts +0 -5
  194. package/dist/generators/ts/_ObjectType/toRdfFunctionDeclaration.js +0 -19
@@ -7,14 +7,93 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
7
7
  import { camelCase, pascalCase } from "change-case";
8
8
  import { Maybe } from "purify-ts";
9
9
  import { invariant } from "ts-invariant";
10
- import { StructureKind, } from "ts-morph";
10
+ import { StructureKind, VariableDeclarationKind, } from "ts-morph";
11
11
  import { Memoize } from "typescript-memoize";
12
12
  import { DeclaredType } from "./DeclaredType.js";
13
+ import { Type } from "./Type.js";
13
14
  import { hasherTypeConstraint } from "./_ObjectType/hashFunctionOrMethodDeclarations.js";
15
+ import { objectSetMethodNames } from "./_ObjectType/objectSetMethodNames.js";
14
16
  import { sparqlConstructQueryFunctionDeclaration } from "./_ObjectType/sparqlConstructQueryFunctionDeclaration.js";
15
17
  import { sparqlConstructQueryStringFunctionDeclaration } from "./_ObjectType/sparqlConstructQueryStringFunctionDeclaration.js";
16
18
  import { objectInitializer } from "./objectInitializer.js";
19
+ import { syntheticNamePrefix } from "./syntheticNamePrefix.js";
17
20
  import { tsComment } from "./tsComment.js";
21
+ class MemberType {
22
+ delegate;
23
+ universe;
24
+ constructor({ delegate, universe, }) {
25
+ this.delegate = delegate;
26
+ this.universe = universe;
27
+ }
28
+ get declarationType() {
29
+ return this.delegate.declarationType;
30
+ }
31
+ get discriminatorPropertyValues() {
32
+ // A member type's combined discriminator property values are its "own" values plus any descendant values that are
33
+ // not the "own" values of some other member type.
34
+ // So if you have type A, type B, and B inherits A, then
35
+ // A has
36
+ // own discriminator property values: ["A"]
37
+ // descendant discriminator property values: ["B"]
38
+ // and B has
39
+ // own discriminator property values: ["B"]
40
+ // descendant discriminator property values ["B"]
41
+ // In this case A shouldn't have "B" as a combined discriminator property value since it's "claimed" by B.
42
+ const memberOwnDiscriminatorPropertyValues = new Set();
43
+ for (const memberType of this.universe) {
44
+ for (const ownDiscriminatorPropertyValue of memberType.discriminatorProperty.unsafeCoerce()
45
+ .ownValues) {
46
+ memberOwnDiscriminatorPropertyValues.add(ownDiscriminatorPropertyValue);
47
+ }
48
+ }
49
+ return this.delegate._discriminatorProperty.ownValues.concat(this.delegate._discriminatorProperty.descendantValues.filter((value) => !memberOwnDiscriminatorPropertyValues.has(value)));
50
+ }
51
+ get features() {
52
+ return this.delegate.features;
53
+ }
54
+ get fromRdfType() {
55
+ return this.delegate.fromRdfType;
56
+ }
57
+ get fromRdfTypeVariable() {
58
+ return this.delegate.fromRdfTypeVariable;
59
+ }
60
+ get graphqlName() {
61
+ return this.delegate.graphqlName;
62
+ }
63
+ get identifierTypeAlias() {
64
+ return this.delegate.identifierTypeAlias;
65
+ }
66
+ get jsonName() {
67
+ return this.delegate.jsonName;
68
+ }
69
+ get mutable() {
70
+ return this.delegate.mutable;
71
+ }
72
+ get name() {
73
+ return this.delegate.name;
74
+ }
75
+ get staticModuleName() {
76
+ return this.delegate.staticModuleName;
77
+ }
78
+ get toRdfjsResourceType() {
79
+ return this.delegate.toRdfjsResourceType;
80
+ }
81
+ jsonZodSchema(parameters) {
82
+ return this.delegate.jsonZodSchema(parameters);
83
+ }
84
+ newExpression(parameters) {
85
+ return this.delegate.newExpression(parameters);
86
+ }
87
+ snippetDeclarations(parameters) {
88
+ return this.delegate.snippetDeclarations(parameters);
89
+ }
90
+ useImports() {
91
+ return this.delegate.useImports();
92
+ }
93
+ }
94
+ __decorate([
95
+ Memoize()
96
+ ], MemberType.prototype, "discriminatorPropertyValues", null);
18
97
  /**
19
98
  * A union of object types, generated as a type alias
20
99
  *
@@ -26,28 +105,34 @@ import { tsComment } from "./tsComment.js";
26
105
  * It also generates SPARQL graph patterns that UNION the member object types.
27
106
  */
28
107
  export class ObjectUnionType extends DeclaredType {
29
- kind = "ObjectUnionType";
30
108
  _discriminatorProperty;
31
109
  comment;
32
110
  label;
111
+ identifierType;
112
+ kind = "ObjectUnionType";
33
113
  memberTypes;
34
- constructor({ comment, label, memberTypes, ...superParameters }) {
114
+ typeof = "object";
115
+ constructor({ comment, identifierType, label, memberTypes, ...superParameters }) {
35
116
  super(superParameters);
36
117
  this.comment = comment;
118
+ this.identifierType = identifierType;
37
119
  this.label = label;
38
120
  invariant(memberTypes.length > 0);
39
- this.memberTypes = memberTypes;
121
+ const discriminatorPropertyDescendantValues = [];
40
122
  const discriminatorPropertyName = memberTypes[0].discriminatorProperty.unsafeCoerce().name;
41
- const discriminatorPropertyValues = [];
42
- for (const memberType of this.memberTypes) {
123
+ const discriminatorPropertyOwnValues = [];
124
+ for (const memberType of memberTypes) {
43
125
  invariant(memberType.declarationType === memberTypes[0].declarationType);
44
126
  invariant(memberType._discriminatorProperty.name === discriminatorPropertyName);
45
- discriminatorPropertyValues.push(...memberType._discriminatorProperty.values);
127
+ discriminatorPropertyDescendantValues.push(...memberType._discriminatorProperty.descendantValues);
128
+ discriminatorPropertyOwnValues.push(...memberType._discriminatorProperty.ownValues);
46
129
  }
47
130
  this._discriminatorProperty = {
131
+ descendantValues: discriminatorPropertyDescendantValues,
48
132
  name: discriminatorPropertyName,
49
- values: discriminatorPropertyValues,
133
+ ownValues: discriminatorPropertyOwnValues,
50
134
  };
135
+ this.memberTypes = memberTypes.map((memberType) => new MemberType({ delegate: memberType, universe: memberTypes }));
51
136
  }
52
137
  get conversions() {
53
138
  return [
@@ -59,26 +144,29 @@ export class ObjectUnionType extends DeclaredType {
59
144
  ];
60
145
  }
61
146
  get declarationImports() {
62
- return this.memberTypes.flatMap((memberType) => memberType.useImports(this.features));
147
+ return this.memberTypes.flatMap((memberType) => memberType.useImports());
63
148
  }
64
149
  get declarations() {
65
150
  const declarations = [this.typeAliasDeclaration];
66
- const moduleStatements = [
151
+ const staticModuleStatements = [
67
152
  ...this.equalsFunctionDeclaration.toList(),
68
153
  ...this.fromJsonFunctionDeclaration.toList(),
69
154
  ...this.fromRdfFunctionDeclaration.toList(),
155
+ ...this.graphqlTypeVariableStatement.toList(),
70
156
  ...this.hashFunctionDeclaration.toList(),
157
+ ...this.jsonTypeAliasDeclaration.toList(),
71
158
  ...this.jsonZodSchemaFunctionDeclaration.toList(),
159
+ ...this.identifierTypeDeclarations,
72
160
  ...this.sparqlFunctionDeclarations,
73
161
  ...this.toJsonFunctionDeclaration.toList(),
74
162
  ...this.toRdfFunctionDeclaration.toList(),
75
163
  ];
76
- if (moduleStatements.length > 0) {
164
+ if (staticModuleStatements.length > 0) {
77
165
  declarations.push({
78
166
  isExported: this.export,
79
167
  kind: StructureKind.Module,
80
- name: this.name,
81
- statements: moduleStatements,
168
+ name: this.staticModuleName,
169
+ statements: staticModuleStatements,
82
170
  });
83
171
  }
84
172
  return declarations;
@@ -87,16 +175,26 @@ export class ObjectUnionType extends DeclaredType {
87
175
  return Maybe.of(this._discriminatorProperty);
88
176
  }
89
177
  get equalsFunction() {
90
- return `${this.name}.equals`;
178
+ return `${this.staticModuleName}.${syntheticNamePrefix}equals`;
179
+ }
180
+ get graphqlName() {
181
+ return new Type.GraphqlName(`${this.staticModuleName}.${syntheticNamePrefix}GraphQL`);
182
+ }
183
+ get identifierTypeAlias() {
184
+ return `${this.staticModuleName}.${syntheticNamePrefix}Identifier`;
91
185
  }
92
186
  get jsonName() {
93
- return this.memberTypes
94
- .map((memberType) => memberType.jsonName)
95
- .join(" | ");
187
+ return new Type.JsonName(this.memberTypes.map((memberType) => memberType.jsonName).join(" | "));
96
188
  }
97
189
  get mutable() {
98
190
  return this.memberTypes.some((memberType) => memberType.mutable);
99
191
  }
192
+ get objectSetMethodNames() {
193
+ return objectSetMethodNames.bind(this)();
194
+ }
195
+ get staticModuleName() {
196
+ return this.name;
197
+ }
100
198
  get thisVariable() {
101
199
  return `_${camelCase(this.name)}`;
102
200
  }
@@ -108,18 +206,19 @@ export class ObjectUnionType extends DeclaredType {
108
206
  let returnExpression;
109
207
  switch (memberType.declarationType) {
110
208
  case "class":
111
- returnExpression = `left.equals(right as unknown as ${memberType.name})`;
209
+ returnExpression = `left.${syntheticNamePrefix}equals(right as unknown as ${memberType.name})`;
112
210
  break;
113
211
  case "interface":
114
- returnExpression = `${memberType.name}.equals(left, right as unknown as ${memberType.name})`;
212
+ returnExpression = `${memberType.staticModuleName}.${syntheticNamePrefix}equals(left, right as unknown as ${memberType.name})`;
115
213
  break;
116
214
  }
117
- return `case "${memberType.name}": return ${returnExpression};`;
215
+ return `${memberType.discriminatorPropertyValues.map((discriminatorPropertyValue) => `case "${discriminatorPropertyValue}":`).join("\n")} return ${returnExpression};`;
118
216
  });
217
+ caseBlocks.push('default: left satisfies never; throw new Error("unrecognized type");');
119
218
  return Maybe.of({
120
219
  isExported: true,
121
220
  kind: StructureKind.Function,
122
- name: "equals",
221
+ name: `${syntheticNamePrefix}equals`,
123
222
  parameters: [
124
223
  {
125
224
  name: "left",
@@ -130,9 +229,9 @@ export class ObjectUnionType extends DeclaredType {
130
229
  type: this.name,
131
230
  },
132
231
  ],
133
- returnType: "EqualsResult",
232
+ returnType: `${syntheticNamePrefix}EqualsResult`,
134
233
  statements: `\
135
- return strictEquals(left.type, right.type).chain(() => {
234
+ return ${syntheticNamePrefix}strictEquals(left.${syntheticNamePrefix}type, right.${syntheticNamePrefix}type).chain(() => {
136
235
  switch (left.${this._discriminatorProperty.name}) {
137
236
  ${caseBlocks.join(" ")}
138
237
  }
@@ -140,13 +239,13 @@ return strictEquals(left.type, right.type).chain(() => {
140
239
  });
141
240
  }
142
241
  get fromJsonFunctionDeclaration() {
143
- if (!this.features.has("fromJson")) {
242
+ if (!this.features.has("json")) {
144
243
  return Maybe.empty();
145
244
  }
146
245
  return Maybe.of({
147
246
  isExported: true,
148
247
  kind: StructureKind.Function,
149
- name: "fromJson",
248
+ name: `${syntheticNamePrefix}fromJson`,
150
249
  parameters: [
151
250
  {
152
251
  name: "json",
@@ -156,7 +255,7 @@ return strictEquals(left.type, right.type).chain(() => {
156
255
  returnType: `purify.Either<zod.ZodError, ${this.name}>`,
157
256
  statements: [
158
257
  `return ${this.memberTypes.reduce((expression, memberType) => {
159
- const memberTypeExpression = `(${memberType.name}.fromJson(json) as purify.Either<zod.ZodError, ${this.name}>)`;
258
+ const memberTypeExpression = `(${memberType.staticModuleName}.${syntheticNamePrefix}fromJson(json) as purify.Either<zod.ZodError, ${this.name}>)`;
160
259
  return expression.length > 0
161
260
  ? `${expression}.altLazy(() => ${memberTypeExpression})`
162
261
  : memberTypeExpression;
@@ -165,23 +264,28 @@ return strictEquals(left.type, right.type).chain(() => {
165
264
  });
166
265
  }
167
266
  get fromRdfFunctionDeclaration() {
168
- if (!this.features.has("fromRdf")) {
267
+ if (!this.features.has("rdf")) {
169
268
  return Maybe.empty();
170
269
  }
171
270
  return Maybe.of({
172
271
  isExported: true,
173
272
  kind: StructureKind.Function,
174
- name: "fromRdf",
273
+ name: `${syntheticNamePrefix}fromRdf`,
175
274
  parameters: [
176
275
  {
177
- name: "{ ignoreRdfType, resource, ...context }",
178
- type: `{ [_index: string]: any; ignoreRdfType?: boolean; resource: ${this.rdfjsResourceType().name}; }`,
276
+ name: "resource",
277
+ type: "rdfjsResource.Resource",
278
+ },
279
+ {
280
+ hasQuestionToken: true,
281
+ name: "options",
282
+ type: `{ [_index: string]: any; ignoreRdfType?: boolean; languageIn?: readonly string[]; objectSet?: ${syntheticNamePrefix}ObjectSet }`,
179
283
  },
180
284
  ],
181
- returnType: `purify.Either<rdfjsResource.Resource.ValueError, ${this.name}>`,
285
+ returnType: `purify.Either<Error, ${this.name}>`,
182
286
  statements: [
183
287
  `return ${this.memberTypes.reduce((expression, memberType) => {
184
- const memberTypeExpression = `(${memberType.name}.fromRdf({ ...context, resource }) as purify.Either<rdfjsResource.Resource.ValueError, ${this.name}>)`;
288
+ const memberTypeExpression = `(${memberType.staticModuleName}.${syntheticNamePrefix}fromRdf(resource, { ...options, ignoreRdfType: false }) as purify.Either<Error, ${this.name}>)`;
185
289
  return expression.length > 0
186
290
  ? `${expression}.altLazy(() => ${memberTypeExpression})`
187
291
  : memberTypeExpression;
@@ -189,6 +293,27 @@ return strictEquals(left.type, right.type).chain(() => {
189
293
  ],
190
294
  });
191
295
  }
296
+ get graphqlTypeVariableStatement() {
297
+ if (!this.features.has("graphql")) {
298
+ return Maybe.empty();
299
+ }
300
+ return Maybe.of({
301
+ declarationKind: VariableDeclarationKind.Const,
302
+ kind: StructureKind.VariableStatement,
303
+ declarations: [
304
+ {
305
+ name: `${syntheticNamePrefix}GraphQL`,
306
+ initializer: `new graphql.GraphQLUnionType(${objectInitializer({
307
+ description: this.comment.map(JSON.stringify).extract(),
308
+ name: `"${this.name}"`,
309
+ resolveType: `(value: ${this.name}) => value.${syntheticNamePrefix}type`,
310
+ types: `[${this.memberTypes.map((memberType) => memberType.graphqlName.nullableName).join(", ")}]`,
311
+ })})`,
312
+ },
313
+ ],
314
+ isExported: true,
315
+ });
316
+ }
192
317
  get hashFunctionDeclaration() {
193
318
  if (!this.features.has("hash")) {
194
319
  return Maybe.empty();
@@ -198,18 +323,19 @@ return strictEquals(left.type, right.type).chain(() => {
198
323
  let returnExpression;
199
324
  switch (memberType.declarationType) {
200
325
  case "class":
201
- returnExpression = `${this.thisVariable}.hash(${hasherVariable})`;
326
+ returnExpression = `${this.thisVariable}.${syntheticNamePrefix}hash(${hasherVariable})`;
202
327
  break;
203
328
  case "interface":
204
- returnExpression = `${memberType.name}.${memberType.hashFunctionName}(${this.thisVariable}, ${hasherVariable})`;
329
+ returnExpression = `${memberType.staticModuleName}.${syntheticNamePrefix}hash(${this.thisVariable}, ${hasherVariable})`;
205
330
  break;
206
331
  }
207
- return `case "${memberType.name}": return ${returnExpression};`;
332
+ return `${memberType.discriminatorPropertyValues.map((discriminatorPropertyValue) => `case "${discriminatorPropertyValue}":`).join("\n")} return ${returnExpression};`;
208
333
  });
334
+ caseBlocks.push(`default: ${this.thisVariable} satisfies never; throw new Error("unrecognized type");`);
209
335
  return Maybe.of({
210
336
  isExported: true,
211
337
  kind: StructureKind.Function,
212
- name: "hash",
338
+ name: `${syntheticNamePrefix}hash`,
213
339
  parameters: [
214
340
  {
215
341
  name: this.thisVariable,
@@ -230,16 +356,48 @@ return strictEquals(left.type, right.type).chain(() => {
230
356
  ],
231
357
  });
232
358
  }
359
+ get identifierTypeDeclarations() {
360
+ return [
361
+ {
362
+ isExported: true,
363
+ kind: StructureKind.TypeAlias,
364
+ name: `${syntheticNamePrefix}Identifier`,
365
+ type: this.identifierType.name,
366
+ },
367
+ {
368
+ isExported: true,
369
+ kind: StructureKind.Module,
370
+ name: `${syntheticNamePrefix}Identifier`,
371
+ statements: [
372
+ this.identifierType.fromStringFunctionDeclaration,
373
+ this.identifierType.toStringFunctionDeclaration,
374
+ ],
375
+ },
376
+ ];
377
+ }
378
+ get jsonTypeAliasDeclaration() {
379
+ if (!this.features.has("json")) {
380
+ return Maybe.empty();
381
+ }
382
+ return Maybe.of({
383
+ isExported: true,
384
+ kind: StructureKind.TypeAlias,
385
+ name: `${syntheticNamePrefix}Json`,
386
+ type: this.memberTypes
387
+ .map((memberType) => memberType.jsonName)
388
+ .join(" | "),
389
+ });
390
+ }
233
391
  get jsonZodSchemaFunctionDeclaration() {
234
- if (!this.features.has("fromJson")) {
392
+ if (!this.features.has("json")) {
235
393
  return Maybe.empty();
236
394
  }
237
395
  const variables = { zod: "zod" };
238
396
  return Maybe.of({
239
397
  isExported: true,
240
398
  kind: StructureKind.Function,
241
- name: "jsonZodSchema",
242
- statements: `return ${variables.zod}.discriminatedUnion("${this._discriminatorProperty.name}", [${this.memberTypes.map((memberType) => memberType.jsonZodSchema({ variables })).join(", ")}]);`,
399
+ name: `${syntheticNamePrefix}jsonZodSchema`,
400
+ statements: `return ${variables.zod}.discriminatedUnion("${this._discriminatorProperty.name}", [${this.memberTypes.map((memberType) => memberType.jsonZodSchema({ context: "type", variables })).join(", ")}]);`,
243
401
  });
244
402
  }
245
403
  get sparqlFunctionDeclarations() {
@@ -252,10 +410,11 @@ return strictEquals(left.type, right.type).chain(() => {
252
410
  {
253
411
  isExported: true,
254
412
  kind: StructureKind.Function,
255
- name: "sparqlConstructTemplateTriples",
413
+ name: `${syntheticNamePrefix}sparqlConstructTemplateTriples`,
256
414
  // Accept ignoreRdfType in order to reuse code but don't pass it through, since deserialization may depend on it
257
415
  parameters: [
258
416
  {
417
+ hasQuestionToken: true,
259
418
  name: "parameters",
260
419
  type: '{ ignoreRdfType?: boolean, subject?: sparqljs.Triple["subject"], variablePrefix?: string }',
261
420
  },
@@ -263,26 +422,27 @@ return strictEquals(left.type, right.type).chain(() => {
263
422
  returnType: "readonly sparqljs.Triple[]",
264
423
  statements: [
265
424
  `return [${this.memberTypes
266
- .map((memberType) => `...${memberType.name}.sparqlConstructTemplateTriples({ subject: parameters.subject ?? ${this.dataFactoryVariable}.variable!("${camelCase(this.name)}${pascalCase(memberType.name)}"), variablePrefix: parameters?.variablePrefix ? \`\${parameters.variablePrefix}${pascalCase(memberType.name)}\` : "${camelCase(this.name)}${pascalCase(memberType.name)}" }).concat()`)
425
+ .map((memberType) => `...${memberType.staticModuleName}.${syntheticNamePrefix}sparqlConstructTemplateTriples({ subject: parameters?.subject ?? dataFactory.variable!("${camelCase(this.name)}${pascalCase(memberType.name)}"), variablePrefix: parameters?.variablePrefix ? \`\${parameters.variablePrefix}${pascalCase(memberType.name)}\` : "${camelCase(this.name)}${pascalCase(memberType.name)}" }).concat()`)
267
426
  .join(", ")}];`,
268
427
  ],
269
428
  },
270
429
  {
271
430
  isExported: true,
272
431
  kind: StructureKind.Function,
273
- name: "sparqlWherePatterns",
432
+ name: `${syntheticNamePrefix}sparqlWherePatterns`,
274
433
  // Accept ignoreRdfType in order to reuse code but don't pass it through, since deserialization may depend on it
275
434
  parameters: [
276
435
  {
436
+ hasQuestionToken: true,
277
437
  name: "parameters",
278
- type: '{ ignoreRdfType?: boolean; subject?: sparqljs.Triple["subject"], variablePrefix?: string }',
438
+ type: '{ ignoreRdfType?: boolean; languageIn?: readonly string[]; subject?: sparqljs.Triple["subject"], variablePrefix?: string }',
279
439
  },
280
440
  ],
281
441
  returnType: "readonly sparqljs.Pattern[]",
282
442
  statements: [
283
443
  `return [{ patterns: [${this.memberTypes
284
444
  .map((memberType) => objectInitializer({
285
- patterns: `${memberType.name}.sparqlWherePatterns({ subject: parameters.subject ?? ${this.dataFactoryVariable}.variable!("${camelCase(this.name)}${pascalCase(memberType.name)}"), variablePrefix: parameters?.variablePrefix ? \`\${parameters.variablePrefix}${pascalCase(memberType.name)}\` : "${camelCase(this.name)}${pascalCase(memberType.name)}" }).concat()`,
445
+ patterns: `${memberType.staticModuleName}.${syntheticNamePrefix}sparqlWherePatterns({ subject: parameters?.subject ?? dataFactory.variable!("${camelCase(this.name)}${pascalCase(memberType.name)}"), variablePrefix: parameters?.variablePrefix ? \`\${parameters.variablePrefix}${pascalCase(memberType.name)}\` : "${camelCase(this.name)}${pascalCase(memberType.name)}" }).concat()`,
286
446
  type: '"group"',
287
447
  }))
288
448
  .join(", ")}], type: "union" }];`,
@@ -291,37 +451,38 @@ return strictEquals(left.type, right.type).chain(() => {
291
451
  ];
292
452
  }
293
453
  get toJsonFunctionDeclaration() {
294
- if (!this.features.has("toJson")) {
454
+ if (!this.features.has("json")) {
295
455
  return Maybe.empty();
296
456
  }
297
457
  const caseBlocks = this.memberTypes.map((memberType) => {
298
458
  let returnExpression;
299
459
  switch (memberType.declarationType) {
300
460
  case "class":
301
- returnExpression = `${this.thisVariable}.toJson()`;
461
+ returnExpression = `${this.thisVariable}.${syntheticNamePrefix}toJson()`;
302
462
  break;
303
463
  case "interface":
304
- returnExpression = `${memberType.name}.toJson(${this.thisVariable})`;
464
+ returnExpression = `${memberType.staticModuleName}.${syntheticNamePrefix}toJson(${this.thisVariable})`;
305
465
  break;
306
466
  }
307
- return `case "${memberType.name}": return ${returnExpression};`;
467
+ return `${memberType.discriminatorPropertyValues.map((discriminatorPropertyValue) => `case "${discriminatorPropertyValue}":`).join("\n")} return ${returnExpression};`;
308
468
  });
469
+ caseBlocks.push(`default: ${this.thisVariable} satisfies never; throw new Error("unrecognized type");`);
309
470
  return Maybe.of({
310
471
  isExported: true,
311
472
  kind: StructureKind.Function,
312
- name: "toJson",
473
+ name: `${syntheticNamePrefix}toJson`,
313
474
  parameters: [
314
475
  {
315
476
  name: this.thisVariable,
316
477
  type: this.name,
317
478
  },
318
479
  ],
319
- returnType: this.jsonName,
480
+ returnType: this.jsonName.toString(),
320
481
  statements: `switch (${this.thisVariable}.${this._discriminatorProperty.name}) { ${caseBlocks.join(" ")} }`,
321
482
  });
322
483
  }
323
484
  get toRdfFunctionDeclaration() {
324
- if (!this.features.has("toRdf")) {
485
+ if (!this.features.has("rdf")) {
325
486
  return Maybe.empty();
326
487
  }
327
488
  const parametersVariable = "_parameters";
@@ -329,29 +490,44 @@ return strictEquals(left.type, right.type).chain(() => {
329
490
  let returnExpression;
330
491
  switch (memberType.declarationType) {
331
492
  case "class":
332
- returnExpression = `${this.thisVariable}.toRdf(${parametersVariable})`;
493
+ returnExpression = `${this.thisVariable}.${syntheticNamePrefix}toRdf(${parametersVariable})`;
333
494
  break;
334
495
  case "interface":
335
- returnExpression = `${memberType.name}.toRdf(${this.thisVariable}, ${parametersVariable})`;
496
+ returnExpression = `${memberType.staticModuleName}.${syntheticNamePrefix}toRdf(${this.thisVariable}, ${parametersVariable})`;
336
497
  break;
337
498
  }
338
- return `case "${memberType.name}": return ${returnExpression};`;
499
+ return `${memberType.discriminatorPropertyValues.map((discriminatorPropertyValue) => `case "${discriminatorPropertyValue}":`).join("\n")} return ${returnExpression};`;
339
500
  });
501
+ caseBlocks.push(`default: ${this.thisVariable} satisfies never; throw new Error("unrecognized type");`);
340
502
  return Maybe.of({
341
503
  isExported: true,
342
504
  kind: StructureKind.Function,
343
- name: "toRdf",
505
+ name: `${syntheticNamePrefix}toRdf`,
344
506
  parameters: [
345
507
  {
346
508
  name: this.thisVariable,
347
509
  type: this.name,
348
510
  },
349
511
  {
512
+ hasQuestionToken: true,
350
513
  name: parametersVariable,
351
- type: "{ mutateGraph: rdfjsResource.MutableResource.MutateGraph, resourceSet: rdfjsResource.MutableResourceSet }",
514
+ type: "{ mutateGraph?: rdfjsResource.MutableResource.MutateGraph, resourceSet?: rdfjsResource.MutableResourceSet }",
352
515
  },
353
516
  ],
354
- returnType: this.rdfjsResourceType({ mutable: true }).name,
517
+ returnType: (() => {
518
+ let returnType;
519
+ for (const memberType of this.memberTypes) {
520
+ const memberRdfjsResourceType = memberType.toRdfjsResourceType;
521
+ if (typeof returnType === "undefined") {
522
+ returnType = memberRdfjsResourceType;
523
+ }
524
+ else if (memberRdfjsResourceType !== returnType) {
525
+ return "rdfjsResource.Resource";
526
+ }
527
+ }
528
+ // The types agree
529
+ return returnType;
530
+ })(),
355
531
  statements: `switch (${this.thisVariable}.${this._discriminatorProperty.name}) { ${caseBlocks.join(" ")} }`,
356
532
  });
357
533
  }
@@ -366,45 +542,66 @@ return strictEquals(left.type, right.type).chain(() => {
366
542
  }
367
543
  fromJsonExpression({ variables, }) {
368
544
  // Assumes the JSON object has been recursively validated already.
369
- return `${this.name}.fromJson(${variables.value}).unsafeCoerce()`;
545
+ return `${this.staticModuleName}.${syntheticNamePrefix}fromJson(${variables.value}).unsafeCoerce()`;
370
546
  }
371
547
  fromRdfExpression({ variables, }) {
372
548
  // Don't ignoreRdfType, we may need it to distinguish the union members
373
- return `${variables.resourceValues}.head().chain(value => value.to${this.rdfjsResourceType().named ? "Named" : ""}Resource()).chain(_resource => ${this.name}.fromRdf({ ...${variables.context}, languageIn: ${variables.languageIn}, resource: _resource }))`;
549
+ return `${variables.resourceValues}.chain(values => values.chainMap(value => value.toResource().chain(resource => ${this.staticModuleName}.${syntheticNamePrefix}fromRdf(resource, { ...${variables.context}, ignoreRdfType: false, languageIn: ${variables.languageIn}, objectSet: ${variables.objectSet} }))))`;
550
+ }
551
+ graphqlResolveExpression({ variables, }) {
552
+ return variables.value;
374
553
  }
375
554
  hashStatements({ variables, }) {
376
555
  switch (this.memberTypes[0].declarationType) {
377
556
  case "class":
378
- return [`${variables.value}.hash(${variables.hasher});`];
557
+ return [
558
+ `${variables.value}.${syntheticNamePrefix}hash(${variables.hasher});`,
559
+ ];
379
560
  case "interface":
380
- return [`${this.name}.hash(${variables.value}, ${variables.hasher});`];
561
+ return [
562
+ `${this.staticModuleName}.${syntheticNamePrefix}hash(${variables.value}, ${variables.hasher});`,
563
+ ];
381
564
  }
382
565
  }
566
+ jsonUiSchemaElement() {
567
+ return Maybe.empty();
568
+ }
383
569
  jsonZodSchema() {
384
- return `${this.name}.jsonZodSchema()`;
570
+ return `${this.staticModuleName}.${syntheticNamePrefix}jsonZodSchema()`;
385
571
  }
386
- sparqlConstructTemplateTriples({ context, variables, }) {
387
- switch (context) {
388
- case "property":
389
- return super.sparqlConstructTemplateTriples({ context, variables });
390
- case "type":
572
+ snippetDeclarations(parameters) {
573
+ const { recursionStack } = parameters;
574
+ if (recursionStack.some((type) => Object.is(type, this))) {
575
+ return [];
576
+ }
577
+ recursionStack.push(this);
578
+ const result = this.memberTypes.flatMap((memberType) => memberType.snippetDeclarations(parameters));
579
+ invariant(Object.is(recursionStack.pop(), this));
580
+ return result;
581
+ }
582
+ sparqlConstructTemplateTriples(parameters) {
583
+ switch (parameters.context) {
584
+ case "object":
585
+ return super.sparqlConstructTemplateTriples(parameters);
586
+ case "subject":
391
587
  return [
392
- `...${this.name}.sparqlConstructTemplateTriples(${objectInitializer({
393
- subject: variables.subject,
394
- variablePrefix: variables.variablePrefix,
588
+ `...${this.staticModuleName}.${syntheticNamePrefix}sparqlConstructTemplateTriples(${objectInitializer({
589
+ subject: parameters.variables.subject,
590
+ variablePrefix: parameters.variables.variablePrefix,
395
591
  })})`,
396
592
  ];
397
593
  }
398
594
  }
399
- sparqlWherePatterns({ context, variables, }) {
400
- switch (context) {
401
- case "property":
402
- return super.sparqlWherePatterns({ context, variables });
403
- case "type":
595
+ sparqlWherePatterns(parameters) {
596
+ switch (parameters.context) {
597
+ case "object":
598
+ return super.sparqlWherePatterns(parameters);
599
+ case "subject":
404
600
  return [
405
- `...${this.name}.sparqlWherePatterns(${objectInitializer({
406
- subject: variables.subject,
407
- variablePrefix: variables.variablePrefix,
601
+ `...${this.staticModuleName}.${syntheticNamePrefix}sparqlWherePatterns(${objectInitializer({
602
+ languageIn: parameters.variables.languageIn,
603
+ subject: parameters.variables.subject,
604
+ variablePrefix: parameters.variables.variablePrefix,
408
605
  })})`,
409
606
  ];
410
607
  }
@@ -412,43 +609,48 @@ return strictEquals(left.type, right.type).chain(() => {
412
609
  toJsonExpression({ variables, }) {
413
610
  switch (this.memberTypes[0].declarationType) {
414
611
  case "class":
415
- return `${variables.value}.toJson()`;
612
+ return `${variables.value}.${syntheticNamePrefix}toJson()`;
416
613
  case "interface":
417
- throw new Error("not implemented: need a freestanding toJson function like the toRdf function");
418
- // return `${this.name}.toJson(${variables.value})`;
614
+ return `${this.staticModuleName}.${syntheticNamePrefix}toJson(${variables.value})`;
419
615
  }
420
616
  }
421
617
  toRdfExpression({ variables, }) {
422
618
  const options = `{ mutateGraph: ${variables.mutateGraph}, resourceSet: ${variables.resourceSet} }`;
423
619
  switch (this.memberTypes[0].declarationType) {
424
620
  case "class":
425
- return `${variables.value}.toRdf(${options})`;
621
+ return `${variables.value}.${syntheticNamePrefix}toRdf(${options})`;
426
622
  case "interface":
427
- return `${this.name}.toRdf(${variables.value}, ${options})`;
623
+ return `${this.staticModuleName}.${syntheticNamePrefix}toRdf(${variables.value}, ${options})`;
428
624
  }
429
625
  }
430
626
  useImports() {
431
627
  return [];
432
628
  }
433
- rdfjsResourceType(options) {
434
- const memberRdfjsResourceTypes = [];
435
- for (const memberType of this.memberTypes) {
436
- const memberRdfjsResourceType = memberType.rdfjsResourceType(options);
437
- if (memberRdfjsResourceTypes.some((existingMemberRdfjsResourceType) => existingMemberRdfjsResourceType.name !==
438
- memberRdfjsResourceType.name)) {
439
- // The types don't agree, return a generic type
440
- return {
441
- mutable: !!options?.mutable,
442
- name: "rdfjsResource.Resource",
443
- named: false,
444
- };
445
- }
446
- memberRdfjsResourceTypes.push(memberRdfjsResourceType);
447
- }
448
- // The types agree
449
- return memberRdfjsResourceTypes[0];
450
- }
451
629
  }
630
+ __decorate([
631
+ Memoize()
632
+ ], ObjectUnionType.prototype, "conversions", null);
633
+ __decorate([
634
+ Memoize()
635
+ ], ObjectUnionType.prototype, "discriminatorProperty", null);
636
+ __decorate([
637
+ Memoize()
638
+ ], ObjectUnionType.prototype, "equalsFunction", null);
639
+ __decorate([
640
+ Memoize()
641
+ ], ObjectUnionType.prototype, "graphqlName", null);
642
+ __decorate([
643
+ Memoize()
644
+ ], ObjectUnionType.prototype, "identifierTypeAlias", null);
645
+ __decorate([
646
+ Memoize()
647
+ ], ObjectUnionType.prototype, "jsonName", null);
648
+ __decorate([
649
+ Memoize()
650
+ ], ObjectUnionType.prototype, "mutable", null);
651
+ __decorate([
652
+ Memoize()
653
+ ], ObjectUnionType.prototype, "objectSetMethodNames", null);
452
654
  __decorate([
453
655
  Memoize()
454
656
  ], ObjectUnionType.prototype, "thisVariable", null);