@shaclmate/compiler 4.0.39 → 4.0.40

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 (163) hide show
  1. package/dist/generators/ts/AbstractCollectionType.d.ts +1 -1
  2. package/dist/generators/ts/AbstractCollectionType.js +10 -10
  3. package/dist/generators/ts/AbstractContainerType.d.ts +4 -5
  4. package/dist/generators/ts/AbstractContainerType.js +4 -5
  5. package/dist/generators/ts/AbstractDateType.d.ts +3 -3
  6. package/dist/generators/ts/AbstractDateType.js +2 -2
  7. package/dist/generators/ts/AbstractLazyObjectType.d.ts +8 -8
  8. package/dist/generators/ts/AbstractLazyObjectType.js +19 -19
  9. package/dist/generators/ts/AbstractNumericType.d.ts +1 -1
  10. package/dist/generators/ts/AbstractNumericType.js +3 -3
  11. package/dist/generators/ts/AbstractObjectSetType.d.ts +10 -9
  12. package/dist/generators/ts/AbstractObjectSetType.js +2 -2
  13. package/dist/generators/ts/AbstractPrimitiveType.js +2 -2
  14. package/dist/generators/ts/AbstractTermType.js +2 -2
  15. package/dist/generators/ts/AbstractType.d.ts +15 -10
  16. package/dist/generators/ts/AbstractType.js +6 -1
  17. package/dist/generators/ts/BigDecimalType.d.ts +1 -1
  18. package/dist/generators/ts/BigDecimalType.js +2 -2
  19. package/dist/generators/ts/BigIntType.js +2 -2
  20. package/dist/generators/ts/BlankNodeType.d.ts +3 -3
  21. package/dist/generators/ts/BlankNodeType.js +11 -11
  22. package/dist/generators/ts/BooleanType.d.ts +2 -2
  23. package/dist/generators/ts/BooleanType.js +10 -5
  24. package/dist/generators/ts/DefaultValueType.d.ts +1 -1
  25. package/dist/generators/ts/DefaultValueType.js +8 -9
  26. package/dist/generators/ts/GraphqlSchema.d.ts +4 -4
  27. package/dist/generators/ts/GraphqlSchema.js +4 -4
  28. package/dist/generators/ts/IdentifierType.d.ts +3 -3
  29. package/dist/generators/ts/IdentifierType.js +13 -13
  30. package/dist/generators/ts/IriType.d.ts +2 -2
  31. package/dist/generators/ts/IriType.js +17 -17
  32. package/dist/generators/ts/LazyObjectOptionType.d.ts +1 -0
  33. package/dist/generators/ts/LazyObjectOptionType.js +6 -6
  34. package/dist/generators/ts/LazyObjectSetType.js +5 -5
  35. package/dist/generators/ts/LazyObjectType.js +4 -4
  36. package/dist/generators/ts/ListType.d.ts +4 -5
  37. package/dist/generators/ts/ListType.js +3 -4
  38. package/dist/generators/ts/LiteralType.d.ts +1 -1
  39. package/dist/generators/ts/LiteralType.js +5 -5
  40. package/dist/generators/ts/{NamedObjectType.d.ts → ObjectType.d.ts} +23 -24
  41. package/dist/generators/ts/ObjectType.js +350 -0
  42. package/dist/generators/ts/ObjectUnionType.d.ts +20 -0
  43. package/dist/generators/ts/{NamedObjectUnionType.js → ObjectUnionType.js} +50 -58
  44. package/dist/generators/ts/OptionType.d.ts +1 -1
  45. package/dist/generators/ts/OptionType.js +10 -10
  46. package/dist/generators/ts/RdfjsDatasetObjectSetType.js +8 -8
  47. package/dist/generators/ts/SparqlObjectSetType.js +2 -2
  48. package/dist/generators/ts/StringType.d.ts +2 -2
  49. package/dist/generators/ts/StringType.js +10 -5
  50. package/dist/generators/ts/TermType.d.ts +2 -2
  51. package/dist/generators/ts/TermType.js +12 -12
  52. package/dist/generators/ts/TsGenerator.js +12 -9
  53. package/dist/generators/ts/Type.d.ts +4 -5
  54. package/dist/generators/ts/TypeFactory.d.ts +7 -8
  55. package/dist/generators/ts/TypeFactory.js +61 -62
  56. package/dist/generators/ts/{AbstractUnionType.d.ts → UnionType.d.ts} +33 -5
  57. package/dist/generators/ts/{AbstractUnionType.js → UnionType.js} +262 -58
  58. package/dist/generators/ts/ZodGenerator.js +7 -9
  59. package/dist/generators/ts/{_NamedObjectType → _ObjectType}/AbstractProperty.d.ts +6 -6
  60. package/dist/generators/ts/{_NamedObjectType → _ObjectType}/AbstractProperty.js +3 -3
  61. package/dist/generators/ts/{_NamedObjectType → _ObjectType}/DiscriminantProperty.d.ts +1 -1
  62. package/dist/generators/ts/{_NamedObjectType → _ObjectType}/DiscriminantProperty.js +8 -8
  63. package/dist/generators/ts/{_NamedObjectType → _ObjectType}/IdentifierProperty.d.ts +1 -5
  64. package/dist/generators/ts/{_NamedObjectType → _ObjectType}/IdentifierProperty.js +15 -10
  65. package/dist/generators/ts/_ObjectType/ObjectType_createFunctionDeclaration.d.ts +5 -0
  66. package/dist/generators/ts/{_NamedObjectType/NamedObjectType_createFunctionDeclaration.js → _ObjectType/ObjectType_createFunctionDeclaration.js} +6 -6
  67. package/dist/generators/ts/_ObjectType/ObjectType_equalsFunctionDeclaration.d.ts +5 -0
  68. package/dist/generators/ts/{_NamedObjectType/NamedObjectType_equalsFunctionDeclaration.js → _ObjectType/ObjectType_equalsFunctionDeclaration.js} +4 -4
  69. package/dist/generators/ts/_ObjectType/ObjectType_filterFunctionDeclaration.d.ts +5 -0
  70. package/dist/generators/ts/{_NamedObjectType/NamedObjectType_filterFunctionDeclaration.js → _ObjectType/ObjectType_filterFunctionDeclaration.js} +3 -3
  71. package/dist/generators/ts/_ObjectType/ObjectType_filterTypeDeclaration.d.ts +5 -0
  72. package/dist/generators/ts/{_NamedObjectType/NamedObjectType_filterTypeDeclaration.js → _ObjectType/ObjectType_filterTypeDeclaration.js} +3 -3
  73. package/dist/generators/ts/_ObjectType/ObjectType_focusSparqlConstructTriplesFunctionDeclaration.d.ts +5 -0
  74. package/dist/generators/ts/{_NamedObjectType/NamedObjectType_focusSparqlConstructTriplesFunctionDeclaration.js → _ObjectType/ObjectType_focusSparqlConstructTriplesFunctionDeclaration.js} +3 -3
  75. package/dist/generators/ts/_ObjectType/ObjectType_focusSparqlWherePatternsFunctionDeclaration.d.ts +5 -0
  76. package/dist/generators/ts/{_NamedObjectType/NamedObjectType_focusSparqlWherePatternsFunctionDeclaration.js → _ObjectType/ObjectType_focusSparqlWherePatternsFunctionDeclaration.js} +3 -3
  77. package/dist/generators/ts/_ObjectType/ObjectType_fromJsonFunctionDeclaration.d.ts +5 -0
  78. package/dist/generators/ts/{_NamedObjectType/NamedObjectType_fromJsonFunctionDeclaration.js → _ObjectType/ObjectType_fromJsonFunctionDeclaration.js} +4 -4
  79. package/dist/generators/ts/_ObjectType/ObjectType_fromRdfResourceFunctionDeclaration.d.ts +5 -0
  80. package/dist/generators/ts/{_NamedObjectType/NamedObjectType_fromRdfResourceFunctionDeclaration.js → _ObjectType/ObjectType_fromRdfResourceFunctionDeclaration.js} +4 -4
  81. package/dist/generators/ts/_ObjectType/ObjectType_fromRdfResourceValuesFunctionDeclaration.d.ts +5 -0
  82. package/dist/generators/ts/_ObjectType/ObjectType_fromRdfResourceValuesFunctionDeclaration.js +15 -0
  83. package/dist/generators/ts/_ObjectType/ObjectType_fromRdfTypeVariableStatement.d.ts +5 -0
  84. package/dist/generators/ts/{_NamedObjectType/NamedObjectType_fromRdfTypeVariableStatement.js → _ObjectType/ObjectType_fromRdfTypeVariableStatement.js} +2 -2
  85. package/dist/generators/ts/_ObjectType/ObjectType_graphqlTypeVariableStatement.d.ts +5 -0
  86. package/dist/generators/ts/{_NamedObjectType/NamedObjectType_graphqlTypeVariableStatement.js → _ObjectType/ObjectType_graphqlTypeVariableStatement.js} +4 -4
  87. package/dist/generators/ts/_ObjectType/ObjectType_hashFunctionDeclarations.d.ts +4 -0
  88. package/dist/generators/ts/{_NamedObjectType/NamedObjectType_hashFunctionDeclarations.js → _ObjectType/ObjectType_hashFunctionDeclarations.js} +6 -6
  89. package/dist/generators/ts/_ObjectType/ObjectType_interfaceDeclaration.d.ts +4 -0
  90. package/dist/generators/ts/{_NamedObjectType/NamedObjectType_interfaceDeclaration.js → _ObjectType/ObjectType_interfaceDeclaration.js} +4 -4
  91. package/dist/generators/ts/_ObjectType/ObjectType_isTypeFunctionDeclaration.d.ts +5 -0
  92. package/dist/generators/ts/{_NamedObjectType/NamedObjectType_isTypeFunctionDeclaration.js → _ObjectType/ObjectType_isTypeFunctionDeclaration.js} +3 -3
  93. package/dist/generators/ts/_ObjectType/ObjectType_jsonParseFunctionDeclaration.d.ts +5 -0
  94. package/dist/generators/ts/{_NamedObjectType/NamedObjectType_jsonParseFunctionDeclaration.js → _ObjectType/ObjectType_jsonParseFunctionDeclaration.js} +2 -2
  95. package/dist/generators/ts/_ObjectType/ObjectType_jsonSchemaFunctionDeclaration.d.ts +5 -0
  96. package/dist/generators/ts/{_NamedObjectType/NamedObjectType_jsonSchemaFunctionDeclaration.js → _ObjectType/ObjectType_jsonSchemaFunctionDeclaration.js} +2 -2
  97. package/dist/generators/ts/_ObjectType/ObjectType_jsonTypeAliasDeclaration.d.ts +5 -0
  98. package/dist/generators/ts/{_NamedObjectType/NamedObjectType_jsonTypeAliasDeclaration.js → _ObjectType/ObjectType_jsonTypeAliasDeclaration.js} +2 -2
  99. package/dist/generators/ts/_ObjectType/ObjectType_jsonUiSchemaFunctionDeclaration.d.ts +5 -0
  100. package/dist/generators/ts/{_NamedObjectType/NamedObjectType_jsonUiSchemaFunctionDeclaration.js → _ObjectType/ObjectType_jsonUiSchemaFunctionDeclaration.js} +4 -4
  101. package/dist/generators/ts/{_NamedObjectType/NamedObjectType_objectSetMethodNames.d.ts → _ObjectType/ObjectType_objectSetMethodNames.d.ts} +3 -3
  102. package/dist/generators/ts/{_NamedObjectType/NamedObjectType_objectSetMethodNames.js → _ObjectType/ObjectType_objectSetMethodNames.js} +4 -4
  103. package/dist/generators/ts/_ObjectType/ObjectType_schemaVariableStatement.d.ts +5 -0
  104. package/dist/generators/ts/_ObjectType/ObjectType_schemaVariableStatement.js +14 -0
  105. package/dist/generators/ts/{_NamedObjectType/NamedObjectType_sparqlConstructQueryFunctionDeclaration.d.ts → _ObjectType/ObjectType_sparqlConstructQueryFunctionDeclaration.d.ts} +3 -3
  106. package/dist/generators/ts/{_NamedObjectType/NamedObjectType_sparqlConstructQueryFunctionDeclaration.js → _ObjectType/ObjectType_sparqlConstructQueryFunctionDeclaration.js} +5 -5
  107. package/dist/generators/ts/{_NamedObjectType/NamedObjectType_sparqlConstructQueryStringFunctionDeclaration.d.ts → _ObjectType/ObjectType_sparqlConstructQueryStringFunctionDeclaration.d.ts} +3 -3
  108. package/dist/generators/ts/_ObjectType/ObjectType_sparqlConstructQueryStringFunctionDeclaration.js +12 -0
  109. package/dist/generators/ts/_ObjectType/ObjectType_toJsonFunctionDeclaration.d.ts +5 -0
  110. package/dist/generators/ts/{_NamedObjectType/NamedObjectType_toJsonFunctionDeclaration.js → _ObjectType/ObjectType_toJsonFunctionDeclaration.js} +4 -4
  111. package/dist/generators/ts/_ObjectType/ObjectType_toRdfResourceFunctionDeclaration.d.ts +5 -0
  112. package/dist/generators/ts/{_NamedObjectType/NamedObjectType_toRdfResourceFunctionDeclaration.js → _ObjectType/ObjectType_toRdfResourceFunctionDeclaration.js} +4 -4
  113. package/dist/generators/ts/_ObjectType/ObjectType_toStringFunctionDeclarations.d.ts +4 -0
  114. package/dist/generators/ts/{_NamedObjectType/NamedObjectType_toStringFunctionDeclarations.js → _ObjectType/ObjectType_toStringFunctionDeclarations.js} +6 -6
  115. package/dist/generators/ts/_ObjectType/ObjectType_valueSparqlConstructTriplesFunctionDeclaration.d.ts +5 -0
  116. package/dist/generators/ts/{_NamedObjectType/NamedObjectType_valueSparqlConstructTriplesFunctionDeclaration.js → _ObjectType/ObjectType_valueSparqlConstructTriplesFunctionDeclaration.js} +3 -3
  117. package/dist/generators/ts/_ObjectType/ObjectType_valueSparqlWherePatternsFunctionDeclaration.d.ts +5 -0
  118. package/dist/generators/ts/{_NamedObjectType/NamedObjectType_valueSparqlWherePatternsFunctionDeclaration.js → _ObjectType/ObjectType_valueSparqlWherePatternsFunctionDeclaration.js} +3 -3
  119. package/dist/generators/ts/{_NamedObjectType → _ObjectType}/ShaclProperty.js +7 -7
  120. package/dist/generators/ts/_ObjectType/identifierTypeDeclarations.d.ts +4 -0
  121. package/dist/generators/ts/{_NamedObjectType → _ObjectType}/identifierTypeDeclarations.js +4 -2
  122. package/dist/input/generated.d.ts +2 -2
  123. package/dist/input/generated.js +2 -2
  124. package/package.json +4 -4
  125. package/dist/generators/ts/AbstractNamedUnionType.d.ts +0 -30
  126. package/dist/generators/ts/AbstractNamedUnionType.js +0 -190
  127. package/dist/generators/ts/AnonymousUnionType.d.ts +0 -27
  128. package/dist/generators/ts/AnonymousUnionType.js +0 -59
  129. package/dist/generators/ts/NamedObjectType.js +0 -342
  130. package/dist/generators/ts/NamedObjectUnionType.d.ts +0 -37
  131. package/dist/generators/ts/NamedUnionType.d.ts +0 -11
  132. package/dist/generators/ts/NamedUnionType.js +0 -13
  133. package/dist/generators/ts/_NamedObjectType/NamedObjectType_createFunctionDeclaration.d.ts +0 -5
  134. package/dist/generators/ts/_NamedObjectType/NamedObjectType_equalsFunctionDeclaration.d.ts +0 -5
  135. package/dist/generators/ts/_NamedObjectType/NamedObjectType_filterFunctionDeclaration.d.ts +0 -5
  136. package/dist/generators/ts/_NamedObjectType/NamedObjectType_filterTypeDeclaration.d.ts +0 -5
  137. package/dist/generators/ts/_NamedObjectType/NamedObjectType_focusSparqlConstructTriplesFunctionDeclaration.d.ts +0 -5
  138. package/dist/generators/ts/_NamedObjectType/NamedObjectType_focusSparqlWherePatternsFunctionDeclaration.d.ts +0 -5
  139. package/dist/generators/ts/_NamedObjectType/NamedObjectType_fromJsonFunctionDeclaration.d.ts +0 -5
  140. package/dist/generators/ts/_NamedObjectType/NamedObjectType_fromRdfResourceFunctionDeclaration.d.ts +0 -5
  141. package/dist/generators/ts/_NamedObjectType/NamedObjectType_fromRdfResourceValuesFunctionDeclaration.d.ts +0 -5
  142. package/dist/generators/ts/_NamedObjectType/NamedObjectType_fromRdfResourceValuesFunctionDeclaration.js +0 -15
  143. package/dist/generators/ts/_NamedObjectType/NamedObjectType_fromRdfTypeVariableStatement.d.ts +0 -5
  144. package/dist/generators/ts/_NamedObjectType/NamedObjectType_graphqlTypeVariableStatement.d.ts +0 -5
  145. package/dist/generators/ts/_NamedObjectType/NamedObjectType_hashFunctionDeclarations.d.ts +0 -4
  146. package/dist/generators/ts/_NamedObjectType/NamedObjectType_interfaceDeclaration.d.ts +0 -4
  147. package/dist/generators/ts/_NamedObjectType/NamedObjectType_isTypeFunctionDeclaration.d.ts +0 -5
  148. package/dist/generators/ts/_NamedObjectType/NamedObjectType_jsonParseFunctionDeclaration.d.ts +0 -5
  149. package/dist/generators/ts/_NamedObjectType/NamedObjectType_jsonSchemaFunctionDeclaration.d.ts +0 -5
  150. package/dist/generators/ts/_NamedObjectType/NamedObjectType_jsonTypeAliasDeclaration.d.ts +0 -5
  151. package/dist/generators/ts/_NamedObjectType/NamedObjectType_jsonUiSchemaFunctionDeclaration.d.ts +0 -5
  152. package/dist/generators/ts/_NamedObjectType/NamedObjectType_schemaVariableStatement.d.ts +0 -5
  153. package/dist/generators/ts/_NamedObjectType/NamedObjectType_schemaVariableStatement.js +0 -12
  154. package/dist/generators/ts/_NamedObjectType/NamedObjectType_sparqlConstructQueryStringFunctionDeclaration.js +0 -12
  155. package/dist/generators/ts/_NamedObjectType/NamedObjectType_toJsonFunctionDeclaration.d.ts +0 -5
  156. package/dist/generators/ts/_NamedObjectType/NamedObjectType_toRdfResourceFunctionDeclaration.d.ts +0 -5
  157. package/dist/generators/ts/_NamedObjectType/NamedObjectType_toStringFunctionDeclarations.d.ts +0 -4
  158. package/dist/generators/ts/_NamedObjectType/NamedObjectType_valueSparqlConstructTriplesFunctionDeclaration.d.ts +0 -5
  159. package/dist/generators/ts/_NamedObjectType/NamedObjectType_valueSparqlWherePatternsFunctionDeclaration.d.ts +0 -5
  160. package/dist/generators/ts/_NamedObjectType/identifierTypeDeclarations.d.ts +0 -4
  161. /package/dist/generators/ts/{_NamedObjectType → _ObjectType}/Property.d.ts +0 -0
  162. /package/dist/generators/ts/{_NamedObjectType → _ObjectType}/Property.js +0 -0
  163. /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);
@@ -70,10 +74,9 @@ export class AbstractUnionType extends AbstractType {
70
74
  }
71
75
  if (discriminant.kind === "Intrinsic" && !json) {
72
76
  switch (member.type.kind) {
73
- case "NamedObjectUnion":
74
- case "NamedUnion":
75
- case "NamedObjectType":
76
- return code `${member.type.name}.is${member.type.name}(${instance})`;
77
+ case "Object":
78
+ case "ObjectUnion":
79
+ return code `${member.type.alias.unsafeCoerce()}.is${member.type.alias.unsafeCoerce()}(${instance})`;
77
80
  }
78
81
  }
79
82
  const discriminantName = json
@@ -134,17 +137,37 @@ export class AbstractUnionType extends AbstractType {
134
137
  code: code `${this.reusables.snippets.identityConversionFunction}`,
135
138
  sourceTypes: this.discriminant.kind === "Typeof"
136
139
  ? this.members.map(({ primaryDiscriminantValue, type }) => ({
137
- name: type.name,
140
+ expression: type.expression,
138
141
  typeof: primaryDiscriminantValue,
139
142
  }))
140
143
  : [
141
144
  {
142
- name: this.name,
145
+ expression: this.expression,
143
146
  typeof: "object",
144
147
  },
145
148
  ],
146
149
  });
147
150
  }
151
+ get declaration() {
152
+ const alias = this.alias.extract();
153
+ if (!alias) {
154
+ return Maybe.empty();
155
+ }
156
+ const declarations = [];
157
+ if (this.configuration.features.has("Object.type")) {
158
+ declarations.push(code `export type ${def(alias)} = ${this.inlineExpression};`);
159
+ }
160
+ const staticModuleDeclarations = Object.entries(this.staticModuleDeclarations);
161
+ if (staticModuleDeclarations.length > 0) {
162
+ declarations.push(code `\
163
+ export namespace ${def(alias)} {
164
+ ${joinCode(staticModuleDeclarations
165
+ .sort((left, right) => left[0].localeCompare(right[0]))
166
+ .map((_) => _[1]), { on: "\n\n" })}
167
+ }`);
168
+ }
169
+ return Maybe.of(joinCode(declarations, { on: "\n\n" }));
170
+ }
148
171
  get discriminantProperty() {
149
172
  switch (this.discriminant.kind) {
150
173
  case "Extrinsic":
@@ -174,12 +197,60 @@ export class AbstractUnionType extends AbstractType {
174
197
  throw this.discriminant;
175
198
  }
176
199
  }
200
+ get equalsFunction() {
201
+ return this.alias
202
+ .map((alias) => code `${alias}.equals`)
203
+ .orDefault(this.inlineEqualsFunction);
204
+ }
205
+ get filterFunction() {
206
+ return this.alias
207
+ .map((alias) => code `${alias}.filter`)
208
+ .orDefault(this.inlineFilterFunction);
209
+ }
210
+ get filterType() {
211
+ return this.alias
212
+ .map((alias) => code `${alias}.Filter`)
213
+ .orDefault(this.inlineFilterType);
214
+ }
215
+ get graphqlType() {
216
+ const alias = this.alias.extract();
217
+ if (!alias ||
218
+ !this.members.every((member) => member.type.kind === "Object")) {
219
+ throw new Error("not implemented");
220
+ }
221
+ return new AbstractType.GraphqlType(code `${alias}.GraphQL`, this.reusables);
222
+ }
223
+ get hashFunction() {
224
+ return this.alias
225
+ .map((alias) => code `${alias}.hash`)
226
+ .orDefault(this.inlineHashFunction);
227
+ }
228
+ get jsonSchemaFunctionDeclaration() {
229
+ const meta = {
230
+ // id: this.name,
231
+ };
232
+ this.comment.ifJust((description) => {
233
+ meta["description"] = description;
234
+ });
235
+ this.label.ifJust((label) => {
236
+ meta["title"] = label;
237
+ });
238
+ return code `export const schema = () => ${this.inlineJsonSchema}.meta(${meta});`;
239
+ }
240
+ get jsonTypeAliasDeclaration() {
241
+ return code `export type Json = ${this.inlineJsonType.name}`;
242
+ }
177
243
  get members() {
178
244
  return this.lazyMembers();
179
245
  }
180
246
  get mutable() {
181
247
  return this.members.some((member) => member.type.mutable);
182
248
  }
249
+ get expression() {
250
+ return this.alias
251
+ .map((alias) => code `${alias}`)
252
+ .orDefault(this.inlineExpression);
253
+ }
183
254
  get referencesObjectType() {
184
255
  return this.members.some((member) => member.type.referencesObjectType);
185
256
  }
@@ -204,11 +275,21 @@ export class AbstractUnionType extends AbstractType {
204
275
  get typeofs() {
205
276
  return [...new Set(this.members.flatMap((member) => member.type.typeofs))];
206
277
  }
278
+ get valueSparqlConstructTriplesFunction() {
279
+ return this.alias
280
+ .map((alias) => code `${alias}.valueSparqlConstructTriples`)
281
+ .orDefault(this.inlineValueSparqlConstructTriplesFunction);
282
+ }
283
+ get valueSparqlWherePatternsFunction() {
284
+ return this.alias
285
+ .map((alias) => code `${alias}.valueSparqlWherePatterns`)
286
+ .orDefault(this.inlineValueSparqlWherePatternsFunction);
287
+ }
207
288
  get inlineEqualsFunction() {
208
289
  return code `\
209
- ((left: ${this.name}, right: ${this.name}) => {
290
+ ((left: ${this.expression}, right: ${this.expression}) => {
210
291
  ${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});
292
+ return ${type.equalsFunction}(${unwrap(code `left`)} as ${type.expression}, ${unwrap(code `right`)} as ${type.expression});
212
293
  }`))}
213
294
 
214
295
  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 +298,7 @@ ${joinCode(this.members.map(({ type, typeCheck, unwrap }) => code `if (${typeChe
217
298
  get inlineFilterFunction() {
218
299
  const syntheticNamePrefix = this.configuration.syntheticNamePrefix;
219
300
  return code `\
220
- ((filter: ${this.filterType}, value: ${this.name}) => {
301
+ ((filter: ${this.filterType}, value: ${this.expression}) => {
221
302
  ${joinCode([
222
303
  ...this.identifierType
223
304
  .map((identifierType) => code `\
@@ -246,7 +327,7 @@ if (filter.on?.[${literalOf(primaryDiscriminantValue)}] !== undefined && ${typeC
246
327
  }
247
328
  get inlineFromJsonFunction() {
248
329
  return code `\
249
- ((value: ${this.jsonType().name}): ${this.reusables.imports.Either}<Error, ${this.name}> => {
330
+ ((value: ${this.jsonType().name}): ${this.reusables.imports.Either}<Error, ${this.expression}> => {
250
331
  ${joinCode(this.members.map(({ jsonType, jsonTypeCheck, type, unwrap, wrap }) => code `if (${jsonTypeCheck(code `value`)}) { return ${type.fromJsonExpression({
251
332
  variables: {
252
333
  value: code `(${unwrap(code `value`)} as ${jsonType})`,
@@ -286,19 +367,19 @@ ${joinCode(this.members.map(({ jsonType, jsonTypeCheck, type, unwrap, wrap }) =>
286
367
  if (this.discriminant.kind === "Extrinsic" ||
287
368
  (this.discriminant.kind === "Hybrid" &&
288
369
  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})))`;
370
+ typeExpression = code `${typeExpression}.map(values => values.map(value => ({ ${this.discriminant.name}: ${literalOf(primaryDiscriminantValue)} as const, value }) as (${this.expression})))`;
290
371
  }
291
- typeExpression = code `(${typeExpression} as ${this.reusables.imports.Either}<Error, ${this.reusables.imports.Resource}.Values<${this.name}>>)`;
372
+ typeExpression = code `(${typeExpression} as ${this.reusables.imports.Either}<Error, ${this.reusables.imports.Resource}.Values<${this.expression}>>)`;
292
373
  return expression !== null
293
374
  ? code `${expression}.altLazy(() => ${typeExpression})`
294
375
  : typeExpression;
295
376
  }, null)}.chain(values => values.head());
296
377
  }))
297
- ) satisfies ${this.reusables.snippets.FromRdfResourceValuesFunction}<${this.name}>)`;
378
+ ) satisfies ${this.reusables.snippets.FromRdfResourceValuesFunction}<${this.expression}>)`;
298
379
  }
299
380
  get inlineHashFunction() {
300
381
  return code `\
301
- (<HasherT extends ${this.reusables.snippets.Hasher}>(hasher: HasherT, value: ${this.name}): HasherT => {
382
+ (<HasherT extends ${this.reusables.snippets.Hasher}>(hasher: HasherT, value: ${this.expression}): HasherT => {
302
383
  ${joinCode(this.members.map(({ type, typeCheck, unwrap }) => code `if (${typeCheck(code `value`)}) { return ${type.hashFunction}(hasher, ${unwrap(code `value`)}); }`))}
303
384
  return hasher;
304
385
  })`;
@@ -356,30 +437,30 @@ ${joinCode(this.members.map(({ type, typeCheck, unwrap }) => code `if (${typeChe
356
437
  throw discriminant;
357
438
  }
358
439
  }
359
- get inlineName() {
440
+ get inlineExpression() {
360
441
  const discriminant = this.discriminant; // To get type narrowing to work
361
442
  switch (discriminant.kind) {
362
443
  case "Extrinsic":
363
- return code `(${joinCode(this.members.map(({ type, primaryDiscriminantValue }) => code `{ ${discriminant.name}: ${literalOf(primaryDiscriminantValue)}, value: ${type.name} }`), { on: "|" })})`;
444
+ return code `(${joinCode(this.members.map(({ type, primaryDiscriminantValue }) => code `{ ${discriminant.name}: ${literalOf(primaryDiscriminantValue)}, value: ${type.expression} }`), { on: "|" })})`;
364
445
  case "Hybrid":
365
446
  return code `(${joinCode(this.members.map(({ primaryDiscriminantValue, type }, memberI) => {
366
447
  switch (discriminant.memberValues[memberI].kind) {
367
448
  case "Extrinsic":
368
- return code `{ ${discriminant.name}: ${literalOf(primaryDiscriminantValue)}, value: ${type.name} }`;
449
+ return code `{ ${discriminant.name}: ${literalOf(primaryDiscriminantValue)}, value: ${type.expression} }`;
369
450
  case "Intrinsic":
370
- return code `${type.name}`;
451
+ return code `${type.expression}`;
371
452
  default:
372
453
  throw new Error();
373
454
  }
374
455
  }), { on: "|" })})`;
375
456
  case "Intrinsic":
376
- // If every type shares a discriminant (e.g., RDF/JS "termType" or generated NamedObjectType "type"),
457
+ // If every type shares a discriminant (e.g., RDF/JS "termType" or generated ObjectType "type"),
377
458
  // just join their names with "|"
378
- return code `(${joinCode(this.members.map(({ type }) => code `${type.name}`), { on: "|" })})`;
459
+ return code `(${joinCode(this.members.map(({ type }) => code `${type.expression}`), { on: "|" })})`;
379
460
  case "Typeof":
380
461
  // The type.name may include literal values, but they should still be unambiguous with other member types since the typeofs
381
462
  // of the different member types are known to be different.
382
- return code `(${joinCode(this.members.map(({ type }) => code `${type.name}`), { on: "|" })})`;
463
+ return code `(${joinCode(this.members.map(({ type }) => code `${type.expression}`), { on: "|" })})`;
383
464
  default:
384
465
  discriminant;
385
466
  throw new Error("should never reach this point");
@@ -387,7 +468,7 @@ ${joinCode(this.members.map(({ type, typeCheck, unwrap }) => code `if (${typeChe
387
468
  }
388
469
  get inlineToJsonFunction() {
389
470
  return code `\
390
- ((value: ${this.name}): ${this.jsonType().name} => {
471
+ ((value: ${this.expression}): ${this.jsonType().name} => {
391
472
  ${joinCode(this.members.map(({ typeCheck, typeToJsonExpression, unwrap, wrap }) => code `if (${typeCheck(code `value`)}) { return ${wrap(typeToJsonExpression(unwrap(code `value`)))}; }`))}
392
473
 
393
474
  throw new Error("unable to serialize to JSON");
@@ -419,11 +500,11 @@ ${joinCode(this.members.map(({ type, unwrap, typeCheck }) => code `if (${typeChe
419
500
  })}; }`))}
420
501
 
421
502
  throw new Error("unable to serialize to RDF");
422
- }) satisfies ${this.reusables.snippets.ToRdfResourceValuesFunction}<${this.name}>)`;
503
+ }) satisfies ${this.reusables.snippets.ToRdfResourceValuesFunction}<${this.expression}>)`;
423
504
  }
424
505
  get inlineToStringFunction() {
425
506
  return code `\
426
- ((value: ${this.name}): string => {
507
+ ((value: ${this.expression}): string => {
427
508
  ${joinCode(this.members.map(({ type, typeCheck, unwrap }) => code `if (${typeCheck(code `value`)}) { return ${type.toStringExpression({
428
509
  variables: { value: unwrap(code `value`) },
429
510
  })}; }`))}
@@ -459,50 +540,180 @@ unionPatterns.push({ patterns: ${type.valueSparqlWherePatternsFunction}({ ...oth
459
540
  type: type.schema,
460
541
  }}`), { on: "," })} }`);
461
542
  }
543
+ get staticModuleDeclarations() {
544
+ const alias = this.alias.unsafeCoerce();
545
+ const staticModuleDeclarations = {};
546
+ if (this.configuration.features.has("Object.equals")) {
547
+ staticModuleDeclarations[`equals`] =
548
+ code `export const equals = ${this.inlineEqualsFunction};`;
549
+ }
550
+ if (this.configuration.features.has("Object.filter")) {
551
+ staticModuleDeclarations[`Filter`] =
552
+ code `export type Filter = ${this.inlineFilterType};`;
553
+ staticModuleDeclarations[`filter`] =
554
+ code `export const filter = ${this.inlineFilterFunction};`;
555
+ }
556
+ if (this.configuration.features.has("Object.hash")) {
557
+ staticModuleDeclarations[`hash`] =
558
+ code `export const hash = ${this.inlineHashFunction};`;
559
+ }
560
+ if (this.configuration.features.has("Object.JSON.type")) {
561
+ staticModuleDeclarations[`Json.type`] =
562
+ code `${this.jsonTypeAliasDeclaration}`;
563
+ }
564
+ if (this.configuration.features.has("Object.JSON.schema")) {
565
+ staticModuleDeclarations[`Json.namespace`] = code `\
566
+ export namespace Json {
567
+ ${this.jsonSchemaFunctionDeclaration}
568
+
569
+ export function parse(json: unknown): ${this.reusables.imports.Either}<Error, Json> {
570
+ const jsonSafeParseResult = schema().safeParse(json);
571
+ if (!jsonSafeParseResult.success) { return ${this.reusables.imports.Left}(jsonSafeParseResult.error); }
572
+ return ${this.reusables.imports.Right}(jsonSafeParseResult.data);
573
+ }
574
+ }`;
575
+ }
576
+ if (this.configuration.features.has("Object.fromJson")) {
577
+ staticModuleDeclarations[`fromJson`] =
578
+ code `export const fromJson = ${this.inlineFromJsonFunction};`;
579
+ }
580
+ if (this.configuration.features.has("Object.fromRdf")) {
581
+ staticModuleDeclarations[`fromRdfResourceValues`] =
582
+ code `export const fromRdfResourceValues: ${this.reusables.snippets.FromRdfResourceValuesFunction}<${alias}> = ${this.inlineFromRdfResourceValuesFunction};`;
583
+ }
584
+ if (this.configuration.features.has("Object.toJson")) {
585
+ staticModuleDeclarations[`toJson`] =
586
+ code `export const toJson = ${this.inlineToJsonFunction};`;
587
+ }
588
+ if (this.configuration.features.has("Object.toRdf")) {
589
+ staticModuleDeclarations[`toRdfResourceValues`] =
590
+ code `export const toRdfResourceValues = ${this.inlineToRdfResourceValuesFunction};`;
591
+ }
592
+ if (this.configuration.features.has("Object.SPARQL")) {
593
+ staticModuleDeclarations[`valueSparqlConstructTriples`] =
594
+ code `export const valueSparqlConstructTriples: ${this.reusables.snippets.ValueSparqlConstructTriplesFunction}<${this.filterType}, ${this.schemaType}> = ${this.inlineValueSparqlConstructTriplesFunction};`;
595
+ staticModuleDeclarations[`valueSparqlWherePatterns`] =
596
+ code `export const valueSparqlWherePatterns: ${this.reusables.snippets.ValueSparqlWherePatternsFunction}<${this.filterType}, ${this.schemaType}> = ${this.inlineValueSparqlWherePatternsFunction};`;
597
+ }
598
+ if (this.configuration.features.has("Object.toString")) {
599
+ const syntheticNamePrefix = this.configuration.syntheticNamePrefix;
600
+ staticModuleDeclarations[`${syntheticNamePrefix}toString`] =
601
+ code `export const ${syntheticNamePrefix}toString = ${this.inlineToStringFunction};`;
602
+ }
603
+ return staticModuleDeclarations;
604
+ }
605
+ fromJsonExpression({ variables, }) {
606
+ return code `${this.alias.map((alias) => code `${alias}.fromJson`).orDefault(this.inlineFromJsonFunction)}(${variables.value})`;
607
+ }
608
+ fromRdfResourceValuesExpression({ variables, }) {
609
+ const { resourceValues: resourceValuesVariable, ...fromRdfResourceValuesOptionsTemp } = variables;
610
+ const fromRdfResourceValuesOptions = fromRdfResourceValuesOptionsTemp;
611
+ if (!this.configuration.features.has("ObjectSet")) {
612
+ delete fromRdfResourceValuesOptions["objectSet"];
613
+ }
614
+ return code `${this.alias.map((alias) => code `${alias}.fromRdfResourceValues`).orDefault(this.inlineFromRdfResourceValuesFunction)}(${resourceValuesVariable}, ${fromRdfResourceValuesOptions})`;
615
+ }
616
+ graphqlResolveExpression({ variables, }) {
617
+ return variables.value;
618
+ }
619
+ jsonSchema({ context, }) {
620
+ const expression = this.alias
621
+ .map((alias) => code `${alias}.Json.schema()`)
622
+ .orDefault(this.inlineJsonSchema);
623
+ if (context === "property" && this.recursive) {
624
+ return code `${this.reusables.imports.z}.lazy((): ${this.reusables.imports.z}.ZodType<${this.jsonType().name}> => ${expression})`;
625
+ }
626
+ return expression;
627
+ }
628
+ jsonType() {
629
+ return this.alias
630
+ .map((alias) => new AbstractType.JsonType(`${alias}.Json`))
631
+ .orDefault(this.inlineJsonType);
632
+ }
462
633
  jsonUiSchemaElement() {
463
634
  return Maybe.empty();
464
635
  }
636
+ toJsonExpression({ variables, }) {
637
+ return code `${this.alias.map((alias) => code `${alias}.toJson`).orDefault(this.inlineToJsonFunction)}(${variables.value})`;
638
+ }
639
+ toRdfResourceValuesExpression({ variables, }) {
640
+ const { value: valueVariable, ...otherVariables } = variables;
641
+ return code `${this.alias.map((alias) => code `${alias}.toRdfResourceValues`).orDefault(this.inlineToRdfResourceValuesFunction)}(${valueVariable}, ${otherVariables})`;
642
+ }
643
+ toStringExpression({ variables, }) {
644
+ return code `${this.alias.map((alias) => code `${alias}.${this.configuration.syntheticNamePrefix}toString`).orDefault(this.inlineToStringFunction)}(${variables.value})`;
645
+ }
465
646
  lazyMembers;
466
647
  }
467
648
  __decorate([
468
649
  Memoize()
469
- ], AbstractUnionType.prototype, "conversionFunction", null);
650
+ ], UnionType.prototype, "conversionFunction", null);
651
+ __decorate([
652
+ Memoize()
653
+ ], UnionType.prototype, "declaration", null);
654
+ __decorate([
655
+ Memoize()
656
+ ], UnionType.prototype, "discriminantProperty", null);
657
+ __decorate([
658
+ Memoize()
659
+ ], UnionType.prototype, "equalsFunction", null);
470
660
  __decorate([
471
661
  Memoize()
472
- ], AbstractUnionType.prototype, "discriminantProperty", null);
662
+ ], UnionType.prototype, "filterFunction", null);
473
663
  __decorate([
474
664
  Memoize()
475
- ], AbstractUnionType.prototype, "members", null);
665
+ ], UnionType.prototype, "filterType", null);
476
666
  __decorate([
477
667
  Memoize()
478
- ], AbstractUnionType.prototype, "mutable", null);
668
+ ], UnionType.prototype, "graphqlType", null);
479
669
  __decorate([
480
670
  Memoize()
481
- ], AbstractUnionType.prototype, "toRdfResourceValueTypes", null);
671
+ ], UnionType.prototype, "hashFunction", null);
482
672
  __decorate([
483
673
  Memoize()
484
- ], AbstractUnionType.prototype, "typeofs", null);
674
+ ], UnionType.prototype, "members", null);
485
675
  __decorate([
486
676
  Memoize()
487
- ], AbstractUnionType.prototype, "inlineEqualsFunction", null);
677
+ ], UnionType.prototype, "mutable", null);
488
678
  __decorate([
489
679
  Memoize()
490
- ], AbstractUnionType.prototype, "inlineFilterFunction", null);
680
+ ], UnionType.prototype, "expression", null);
491
681
  __decorate([
492
682
  Memoize()
493
- ], AbstractUnionType.prototype, "inlineFilterType", null);
683
+ ], UnionType.prototype, "toRdfResourceValueTypes", null);
494
684
  __decorate([
495
685
  Memoize()
496
- ], AbstractUnionType.prototype, "inlineJsonType", null);
686
+ ], UnionType.prototype, "typeofs", null);
497
687
  __decorate([
498
688
  Memoize()
499
- ], AbstractUnionType.prototype, "inlineName", null);
689
+ ], UnionType.prototype, "valueSparqlConstructTriplesFunction", null);
500
690
  __decorate([
501
691
  Memoize()
502
- ], AbstractUnionType.prototype, "inlineValueSparqlConstructTriplesFunction", null);
692
+ ], UnionType.prototype, "valueSparqlWherePatternsFunction", null);
503
693
  __decorate([
504
694
  Memoize()
505
- ], AbstractUnionType.prototype, "inlineValueSparqlWherePatternsFunction", null);
695
+ ], UnionType.prototype, "inlineEqualsFunction", null);
696
+ __decorate([
697
+ Memoize()
698
+ ], UnionType.prototype, "inlineFilterFunction", null);
699
+ __decorate([
700
+ Memoize()
701
+ ], UnionType.prototype, "inlineFilterType", null);
702
+ __decorate([
703
+ Memoize()
704
+ ], UnionType.prototype, "inlineJsonType", null);
705
+ __decorate([
706
+ Memoize()
707
+ ], UnionType.prototype, "inlineExpression", null);
708
+ __decorate([
709
+ Memoize()
710
+ ], UnionType.prototype, "inlineValueSparqlConstructTriplesFunction", null);
711
+ __decorate([
712
+ Memoize()
713
+ ], UnionType.prototype, "inlineValueSparqlWherePatternsFunction", null);
714
+ __decorate([
715
+ Memoize()
716
+ ], UnionType.prototype, "jsonType", null);
506
717
  function termTypes(type) {
507
718
  switch (type.kind) {
508
719
  case "BlankNode":
@@ -586,8 +797,8 @@ export var Discriminant;
586
797
  continue;
587
798
  }
588
799
  extrinsicMemberTypeCount++;
589
- if (typeof memberType.name === "string") {
590
- extrinsicMemberTypeNamesSet.add(memberType.name);
800
+ if (memberType.alias.isJust()) {
801
+ extrinsicMemberTypeNamesSet.add(memberType.alias.extract());
591
802
  }
592
803
  else {
593
804
  break;
@@ -607,7 +818,7 @@ export var Discriminant;
607
818
  return {
608
819
  kind: "Extrinsic",
609
820
  ownValues: extrinsicMemberTypeNamesSet.size === extrinsicMemberTypeCount
610
- ? [memberType.name]
821
+ ? [memberType.alias.unsafeCoerce()]
611
822
  : [memberTypeI.toString()],
612
823
  };
613
824
  }),
@@ -618,21 +829,14 @@ export var Discriminant;
618
829
  {
619
830
  let memberValues;
620
831
  {
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
- }
832
+ const memberTypeNames = memberTypes.map((memberType) => memberType.alias.orDefault(memberType.typeofs[0]));
833
+ const memberTypeNamesSet = new Set(memberTypeNames);
834
+ if (memberTypeNamesSet.size === memberTypeNames.length) {
835
+ memberValues = memberTypeNames;
631
836
  }
632
837
  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);
838
+ // Otherwise prefix the non-unique strings with an index and use those as the discriminant values.
839
+ memberValues = memberTypeNames.map((memberTypeName, memberTypeI) => `${memberTypeI}-${memberTypeName}`);
636
840
  }
637
841
  }
638
842
  invariant(memberValues.length === memberTypes.length);
@@ -640,10 +844,10 @@ export var Discriminant;
640
844
  jsonName: "type",
641
845
  kind: "Extrinsic",
642
846
  name: "type",
643
- memberValues: memberValues,
847
+ memberValues,
644
848
  };
645
849
  }
646
850
  }
647
851
  Discriminant.infer = infer;
648
852
  })(Discriminant || (Discriminant = {}));
649
- //# sourceMappingURL=AbstractUnionType.js.map
853
+ //# sourceMappingURL=UnionType.js.map
@@ -1,7 +1,6 @@
1
- import { invariant } from "ts-invariant";
2
1
  import * as ast from "../../ast/index.js";
3
- import { NamedObjectType_jsonSchemaFunctionDeclaration } from "./_NamedObjectType/NamedObjectType_jsonSchemaFunctionDeclaration.js";
4
- import { NamedObjectType_jsonTypeAliasDeclaration } from "./_NamedObjectType/NamedObjectType_jsonTypeAliasDeclaration.js";
2
+ import { ObjectType_jsonSchemaFunctionDeclaration } from "./_ObjectType/ObjectType_jsonSchemaFunctionDeclaration.js";
3
+ import { ObjectType_jsonTypeAliasDeclaration } from "./_ObjectType/ObjectType_jsonTypeAliasDeclaration.js";
5
4
  import { Reusables } from "./Reusables.js";
6
5
  import { TsGenerator } from "./TsGenerator.js";
7
6
  import { TypeFactory } from "./TypeFactory.js";
@@ -20,20 +19,19 @@ export class ZodGenerator {
20
19
  reusables,
21
20
  });
22
21
  const declarations = [];
23
- for (const namedObjectType of ast.ObjectType.toposort(ast_.namedObjectTypes).map((astObjectType) => typeFactory.createNamedObjectType(astObjectType))) {
22
+ for (const namedObjectType of ast.ObjectType.toposort(ast_.namedObjectTypes).map((astObjectType) => typeFactory.createObjectType(astObjectType))) {
24
23
  declarations.push(code `\
25
- export namespace ${namedObjectType.name} {
26
- ${joinCode(NamedObjectType_jsonTypeAliasDeclaration.call(namedObjectType).toList())}
24
+ export namespace ${namedObjectType.alias.unsafeCoerce()} {
25
+ ${joinCode(ObjectType_jsonTypeAliasDeclaration.call(namedObjectType).toList())}
27
26
 
28
27
  export namespace Json {
29
- ${joinCode(NamedObjectType_jsonSchemaFunctionDeclaration.call(namedObjectType).toList())}
28
+ ${joinCode(ObjectType_jsonSchemaFunctionDeclaration.call(namedObjectType).toList())}
30
29
  }
31
30
  }`);
32
31
  }
33
32
  for (const astNamedUnionType of ast_.namedUnionTypes.map((astNamedUnionType) => typeFactory.createUnionType(astNamedUnionType))) {
34
- invariant(astNamedUnionType.kind !== "AnonymousUnion");
35
33
  declarations.push(code `\
36
- export namespace ${astNamedUnionType.name} {
34
+ export namespace ${astNamedUnionType.alias.unsafeCoerce()} {
37
35
  ${astNamedUnionType.jsonTypeAliasDeclaration}
38
36
  export namespace Json {
39
37
  ${astNamedUnionType.jsonSchemaFunctionDeclaration}
@@ -1,15 +1,15 @@
1
1
  import { Maybe } from "purify-ts";
2
2
  import type { Logger } from "ts-log";
3
- import type { NamedObjectType } from "../NamedObjectType.js";
3
+ import type { ObjectType } from "../ObjectType.js";
4
4
  import type { Reusables } from "../Reusables.js";
5
5
  import { rdfjsTermExpression } from "../rdfjsTermExpression.js";
6
6
  import type { TsGenerator } from "../TsGenerator.js";
7
7
  import type { Type } from "../Type.js";
8
8
  import { type Code } from "../ts-poet-wrapper.js";
9
- export declare abstract class AbstractProperty<TypeT extends Pick<Type, "filterFunction" | "mutable" | "name" | "schema">> {
9
+ export declare abstract class AbstractProperty<TypeT extends Pick<Type, "expression" | "filterFunction" | "mutable" | "schema">> {
10
10
  protected readonly configuration: TsGenerator.Configuration;
11
11
  protected readonly logger: Logger;
12
- protected readonly namedObjectType: NamedObjectType;
12
+ protected readonly objectType: ObjectType;
13
13
  protected readonly reusables: Reusables;
14
14
  /**
15
15
  * Optional parameter to include in the parameters object of constructor function.
@@ -62,18 +62,18 @@ export declare abstract class AbstractProperty<TypeT extends Pick<Type, "filterF
62
62
  */
63
63
  readonly name: string;
64
64
  /**
65
- * Is the property's type the NamedObjectType or does its type indirectly reference the NamedObjectType?
65
+ * Is the property's type the ObjectType or does its type indirectly reference the ObjectType?
66
66
  */
67
67
  abstract readonly recursive: boolean;
68
68
  /**
69
69
  * Property type
70
70
  . */
71
71
  readonly type: TypeT;
72
- constructor({ configuration, logger, name, namedObjectType, reusables, type, }: {
72
+ constructor({ configuration, logger, name, objectType, reusables, type, }: {
73
73
  configuration: TsGenerator.Configuration;
74
74
  logger: Logger;
75
75
  name: string;
76
- namedObjectType: NamedObjectType;
76
+ objectType: ObjectType;
77
77
  reusables: Reusables;
78
78
  type: TypeT;
79
79
  });
@@ -11,7 +11,7 @@ import { code, joinCode, literalOf } from "../ts-poet-wrapper.js";
11
11
  export class AbstractProperty {
12
12
  configuration;
13
13
  logger;
14
- namedObjectType;
14
+ objectType;
15
15
  reusables;
16
16
  /**
17
17
  * TypeScript identifier-safe name of the property.
@@ -21,11 +21,11 @@ export class AbstractProperty {
21
21
  * Property type
22
22
  . */
23
23
  type;
24
- constructor({ configuration, logger, name, namedObjectType, reusables, type, }) {
24
+ constructor({ configuration, logger, name, objectType, reusables, type, }) {
25
25
  this.configuration = configuration;
26
26
  this.logger = logger;
27
27
  this.name = name;
28
- this.namedObjectType = namedObjectType;
28
+ this.objectType = objectType;
29
29
  this.reusables = reusables;
30
30
  this.type = type;
31
31
  this.rdfjsTermExpression = rdfjsTermExpression.bind({
@@ -39,7 +39,7 @@ export declare namespace DiscriminantProperty {
39
39
  mutable: boolean;
40
40
  ownValues: readonly string[];
41
41
  });
42
- get name(): string;
42
+ get expression(): Code;
43
43
  get schema(): Code;
44
44
  get values(): string[];
45
45
  }