@shaclmate/compiler 2.0.20 → 2.0.23

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 (172) hide show
  1. package/dist/ShapesGraphToAstTransformer.d.ts +1 -0
  2. package/dist/ShapesGraphToAstTransformer.js +56 -12
  3. package/dist/_ShapesGraphToAstTransformer/flattenAstObjectCompositeTypeMemberTypes.d.ts +13 -0
  4. package/dist/_ShapesGraphToAstTransformer/flattenAstObjectCompositeTypeMemberTypes.js +51 -0
  5. package/dist/_ShapesGraphToAstTransformer/shapeAstName.js +53 -12
  6. package/dist/_ShapesGraphToAstTransformer/transformNodeShapeToAstType.d.ts +5 -0
  7. package/dist/_ShapesGraphToAstTransformer/transformNodeShapeToAstType.js +130 -54
  8. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstCompositeType.d.ts +2 -3
  9. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstCompositeType.js +122 -129
  10. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstIdentifierType.d.ts +2 -2
  11. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstLiteralType.d.ts +2 -2
  12. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstObjectTypeProperty.js +127 -5
  13. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstTermType.d.ts +3 -3
  14. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstType.d.ts +2 -3
  15. package/dist/ast/Ast.d.ts +0 -1
  16. package/dist/ast/Curie.d.ts +14 -0
  17. package/dist/ast/Curie.js +21 -0
  18. package/dist/ast/IdentifierType.d.ts +3 -2
  19. package/dist/ast/ListType.d.ts +2 -1
  20. package/dist/ast/LiteralType.d.ts +1 -1
  21. package/dist/ast/Name.d.ts +40 -5
  22. package/dist/ast/ObjectCompositeType.d.ts +11 -0
  23. package/dist/ast/ObjectType.d.ts +18 -13
  24. package/dist/ast/ObjectUnionType.d.ts +0 -11
  25. package/dist/ast/OptionType.d.ts +2 -2
  26. package/dist/ast/SetType.d.ts +2 -2
  27. package/dist/ast/TermType.d.ts +12 -4
  28. package/dist/ast/Type.d.ts +1 -1
  29. package/dist/enums/TsFeature.d.ts +1 -4
  30. package/dist/enums/TsFeature.js +1 -15
  31. package/dist/generators/json/AstJsonGenerator.js +19 -3
  32. package/dist/generators/ts/BooleanType.d.ts +3 -1
  33. package/dist/generators/ts/BooleanType.js +11 -2
  34. package/dist/generators/ts/DateTimeType.d.ts +8 -7
  35. package/dist/generators/ts/DateTimeType.js +31 -7
  36. package/dist/generators/ts/DateType.d.ts +5 -2
  37. package/dist/generators/ts/DateType.js +15 -1
  38. package/dist/generators/ts/DeclaredType.d.ts +2 -2
  39. package/dist/generators/ts/DeclaredType.js +2 -2
  40. package/dist/generators/ts/FloatType.d.ts +6 -0
  41. package/dist/generators/ts/FloatType.js +18 -0
  42. package/dist/generators/ts/IdentifierType.d.ts +12 -7
  43. package/dist/generators/ts/IdentifierType.js +94 -6
  44. package/dist/generators/ts/Import.d.ts +2 -0
  45. package/dist/generators/ts/Import.js +10 -0
  46. package/dist/generators/ts/IntType.d.ts +6 -0
  47. package/dist/generators/ts/IntType.js +18 -0
  48. package/dist/generators/ts/ListType.d.ts +15 -12
  49. package/dist/generators/ts/ListType.js +98 -57
  50. package/dist/generators/ts/LiteralType.d.ts +10 -9
  51. package/dist/generators/ts/LiteralType.js +13 -2
  52. package/dist/generators/ts/NumberType.d.ts +2 -1
  53. package/dist/generators/ts/NumberType.js +7 -2
  54. package/dist/generators/ts/ObjectType.d.ts +66 -43
  55. package/dist/generators/ts/ObjectType.js +144 -123
  56. package/dist/generators/ts/ObjectUnionType.d.ts +49 -8
  57. package/dist/generators/ts/ObjectUnionType.js +290 -97
  58. package/dist/generators/ts/OptionType.d.ts +14 -10
  59. package/dist/generators/ts/OptionType.js +60 -34
  60. package/dist/generators/ts/PrimitiveType.d.ts +4 -4
  61. package/dist/generators/ts/PrimitiveType.js +18 -3
  62. package/dist/generators/ts/SetType.d.ts +16 -12
  63. package/dist/generators/ts/SetType.js +69 -40
  64. package/dist/generators/ts/SnippetDeclarations.d.ts +13 -8
  65. package/dist/generators/ts/SnippetDeclarations.js +215 -101
  66. package/dist/generators/ts/StringType.d.ts +3 -1
  67. package/dist/generators/ts/StringType.js +14 -2
  68. package/dist/generators/ts/TermType.d.ts +22 -14
  69. package/dist/generators/ts/TermType.js +53 -25
  70. package/dist/generators/ts/TsGenerator.d.ts +2 -1
  71. package/dist/generators/ts/TsGenerator.js +23 -12
  72. package/dist/generators/ts/Type.d.ts +89 -31
  73. package/dist/generators/ts/Type.js +57 -54
  74. package/dist/generators/ts/TypeFactory.d.ts +4 -5
  75. package/dist/generators/ts/TypeFactory.js +290 -226
  76. package/dist/generators/ts/UnionType.d.ts +14 -10
  77. package/dist/generators/ts/UnionType.js +319 -142
  78. package/dist/generators/ts/_ObjectType/EagerShaclProperty.d.ts +12 -0
  79. package/dist/generators/ts/_ObjectType/EagerShaclProperty.js +30 -0
  80. package/dist/generators/ts/_ObjectType/IdentifierPrefixProperty.d.ts +13 -12
  81. package/dist/generators/ts/_ObjectType/IdentifierPrefixProperty.js +46 -47
  82. package/dist/generators/ts/_ObjectType/IdentifierProperty.d.ts +20 -13
  83. package/dist/generators/ts/_ObjectType/IdentifierProperty.js +152 -124
  84. package/dist/generators/ts/_ObjectType/LazyShaclProperty.d.ts +87 -0
  85. package/dist/generators/ts/_ObjectType/LazyShaclProperty.js +237 -0
  86. package/dist/generators/ts/_ObjectType/Property.d.ts +39 -44
  87. package/dist/generators/ts/_ObjectType/Property.js +1 -10
  88. package/dist/generators/ts/_ObjectType/ShaclProperty.d.ts +25 -30
  89. package/dist/generators/ts/_ObjectType/ShaclProperty.js +108 -85
  90. package/dist/generators/ts/_ObjectType/TypeDiscriminatorProperty.d.ts +21 -17
  91. package/dist/generators/ts/_ObjectType/TypeDiscriminatorProperty.js +61 -53
  92. package/dist/generators/ts/_ObjectType/classDeclaration.js +6 -5
  93. package/dist/generators/ts/_ObjectType/createFunctionDeclaration.js +5 -4
  94. package/dist/generators/ts/_ObjectType/equalsFunctionOrMethodDeclaration.js +5 -4
  95. package/dist/generators/ts/_ObjectType/fromRdfTypeVariableStatement.d.ts +1 -1
  96. package/dist/generators/ts/_ObjectType/fromRdfTypeVariableStatement.js +8 -5
  97. package/dist/generators/ts/_ObjectType/graphqlTypeVariableStatement.d.ts +5 -0
  98. package/dist/generators/ts/_ObjectType/graphqlTypeVariableStatement.js +37 -0
  99. package/dist/generators/ts/_ObjectType/hashFunctionOrMethodDeclarations.js +7 -8
  100. package/dist/generators/ts/_ObjectType/identifierTypeDeclarations.d.ts +7 -0
  101. package/dist/generators/ts/_ObjectType/identifierTypeDeclarations.js +54 -0
  102. package/dist/generators/ts/_ObjectType/index.d.ts +9 -7
  103. package/dist/generators/ts/_ObjectType/index.js +9 -7
  104. package/dist/generators/ts/_ObjectType/interfaceDeclaration.js +1 -1
  105. package/dist/generators/ts/_ObjectType/jsonFunctionDeclarations.d.ts +4 -0
  106. package/dist/generators/ts/_ObjectType/jsonFunctionDeclarations.js +189 -0
  107. package/dist/generators/ts/_ObjectType/jsonTypeAliasDeclaration.d.ts +5 -0
  108. package/dist/generators/ts/_ObjectType/jsonTypeAliasDeclaration.js +28 -0
  109. package/dist/generators/ts/_ObjectType/objectSetMethodNames.d.ts +9 -0
  110. package/dist/generators/ts/_ObjectType/objectSetMethodNames.js +18 -0
  111. package/dist/generators/ts/_ObjectType/propertiesVariableStatement.d.ts +5 -0
  112. package/dist/generators/ts/_ObjectType/propertiesVariableStatement.js +37 -0
  113. package/dist/generators/ts/_ObjectType/rdfFunctionDeclarations.d.ts +4 -0
  114. package/dist/generators/ts/_ObjectType/rdfFunctionDeclarations.js +152 -0
  115. package/dist/generators/ts/_ObjectType/sparqlConstructQueryFunctionDeclaration.d.ts +1 -1
  116. package/dist/generators/ts/_ObjectType/sparqlConstructQueryFunctionDeclaration.js +4 -3
  117. package/dist/generators/ts/_ObjectType/sparqlConstructQueryStringFunctionDeclaration.d.ts +1 -1
  118. package/dist/generators/ts/_ObjectType/sparqlConstructQueryStringFunctionDeclaration.js +3 -2
  119. package/dist/generators/ts/_ObjectType/sparqlFunctionDeclarations.js +103 -35
  120. package/dist/generators/ts/_ObjectType/toJsonFunctionOrMethodDeclaration.js +6 -6
  121. package/dist/generators/ts/_ObjectType/toRdfFunctionOrMethodDeclaration.js +15 -13
  122. package/dist/generators/ts/graphqlSchemaVariableStatement.d.ts +9 -0
  123. package/dist/generators/ts/graphqlSchemaVariableStatement.js +86 -0
  124. package/dist/generators/ts/objectSetDeclarations.d.ts +8 -0
  125. package/dist/generators/ts/objectSetDeclarations.js +59 -0
  126. package/dist/generators/ts/objectSetInterfaceDeclaration.d.ts +8 -0
  127. package/dist/generators/ts/objectSetInterfaceDeclaration.js +46 -0
  128. package/dist/generators/ts/objectSetMethodSignatures.d.ts +11 -0
  129. package/dist/generators/ts/objectSetMethodSignatures.js +52 -0
  130. package/dist/generators/ts/rdfjsDatasetObjectSetClassDeclaration.d.ts +8 -0
  131. package/dist/generators/ts/rdfjsDatasetObjectSetClassDeclaration.js +393 -0
  132. package/dist/generators/ts/rdfjsTermExpression.d.ts +3 -0
  133. package/dist/generators/ts/rdfjsTermExpression.js +57 -0
  134. package/dist/generators/ts/sparqlObjectSetClassDeclaration.d.ts +8 -0
  135. package/dist/generators/ts/sparqlObjectSetClassDeclaration.js +415 -0
  136. package/dist/generators/ts/syntheticNamePrefix.d.ts +2 -0
  137. package/dist/generators/ts/syntheticNamePrefix.js +2 -0
  138. package/dist/generators/ts/tsName.js +27 -13
  139. package/dist/generators/ts/unsupportedObjectSetMethodDeclarations.d.ts +10 -0
  140. package/dist/generators/ts/unsupportedObjectSetMethodDeclarations.js +19 -0
  141. package/dist/input/NodeShape.d.ts +6 -8
  142. package/dist/input/NodeShape.js +20 -44
  143. package/dist/input/Ontology.d.ts +0 -3
  144. package/dist/input/Ontology.js +0 -9
  145. package/dist/input/PropertyPath.d.ts +6 -5
  146. package/dist/input/PropertyPath.js +14 -22
  147. package/dist/input/PropertyShape.d.ts +3 -1
  148. package/dist/input/PropertyShape.js +8 -2
  149. package/dist/input/ShapesGraph.js +4 -4
  150. package/dist/input/generated.d.ts +923 -105
  151. package/dist/input/generated.js +1865 -969
  152. package/dist/input/tsFeatures.d.ts +3 -2
  153. package/dist/input/tsFeatures.js +44 -27
  154. package/package.json +18 -16
  155. package/dist/generators/ts/_ObjectType/fromJsonFunctionDeclarations.d.ts +0 -4
  156. package/dist/generators/ts/_ObjectType/fromJsonFunctionDeclarations.js +0 -78
  157. package/dist/generators/ts/_ObjectType/fromRdfFunctionDeclarations.d.ts +0 -4
  158. package/dist/generators/ts/_ObjectType/fromRdfFunctionDeclarations.js +0 -91
  159. package/dist/generators/ts/_ObjectType/jsonSchemaFunctionDeclaration.d.ts +0 -5
  160. package/dist/generators/ts/_ObjectType/jsonSchemaFunctionDeclaration.js +0 -19
  161. package/dist/generators/ts/_ObjectType/jsonUiSchemaFunctionDeclaration.d.ts +0 -5
  162. package/dist/generators/ts/_ObjectType/jsonUiSchemaFunctionDeclaration.js +0 -31
  163. package/dist/generators/ts/_ObjectType/jsonZodSchemaFunctionDeclaration.d.ts +0 -5
  164. package/dist/generators/ts/_ObjectType/jsonZodSchemaFunctionDeclaration.js +0 -37
  165. package/dist/generators/ts/_ObjectType/rdfjsTermExpression.d.ts +0 -6
  166. package/dist/generators/ts/_ObjectType/rdfjsTermExpression.js +0 -17
  167. package/dist/generators/ts/_ObjectType/toJsonFunctionDeclaration.d.ts +0 -5
  168. package/dist/generators/ts/_ObjectType/toJsonFunctionDeclaration.js +0 -19
  169. package/dist/generators/ts/_ObjectType/toJsonReturnType.d.ts +0 -3
  170. package/dist/generators/ts/_ObjectType/toJsonReturnType.js +0 -17
  171. package/dist/generators/ts/_ObjectType/toRdfFunctionDeclaration.d.ts +0 -5
  172. package/dist/generators/ts/_ObjectType/toRdfFunctionDeclaration.js +0 -19
@@ -9,41 +9,45 @@ import { Maybe } from "purify-ts";
9
9
  import { invariant } from "ts-invariant";
10
10
  import { StructureKind, } from "ts-morph";
11
11
  import { Memoize } from "typescript-memoize";
12
+ import * as _ObjectType from "./_ObjectType/index.js";
12
13
  import { DeclaredType } from "./DeclaredType.js";
13
14
  import { Import } from "./Import.js";
14
15
  import { SnippetDeclarations } from "./SnippetDeclarations.js";
15
- import * as _ObjectType from "./_ObjectType/index.js";
16
+ import { Type } from "./Type.js";
16
17
  import { objectInitializer } from "./objectInitializer.js";
18
+ import { syntheticNamePrefix } from "./syntheticNamePrefix.js";
17
19
  export class ObjectType extends DeclaredType {
20
+ imports;
21
+ comment;
22
+ identifierMintingStrategy;
23
+ label;
24
+ toRdfTypes;
18
25
  abstract;
19
26
  declarationType;
20
- kind = "ObjectType";
21
- comment;
22
27
  extern;
23
28
  fromRdfType;
24
- label;
25
- identifierMintingStrategy;
26
- toRdfTypes;
27
- imports;
28
- lazyAncestorObjectTypes;
29
- lazyDescendantObjectTypes;
30
- lazyParentObjectTypes;
31
- lazyProperties;
32
- constructor({ abstract, comment, declarationType, extern, fromRdfType, label, lazyAncestorObjectTypes, lazyDescendantObjectTypes, lazyParentObjectTypes, lazyProperties, imports, identifierMintingStrategy, toRdfTypes, ...superParameters }) {
29
+ kind = "ObjectType";
30
+ staticModuleName;
31
+ synthetic;
32
+ typeof = "object";
33
+ constructor({ abstract, comment, declarationType, extern, fromRdfType, imports, identifierMintingStrategy, label, lazyAncestorObjectTypes, lazyChildObjectTypes, lazyDescendantObjectTypes, lazyParentObjectTypes, lazyProperties, staticModuleName, synthetic, toRdfTypes, ...superParameters }) {
33
34
  super(superParameters);
34
35
  this.abstract = abstract;
35
36
  this.comment = comment;
36
37
  this.declarationType = declarationType;
37
38
  this.extern = extern;
38
39
  this.fromRdfType = fromRdfType;
40
+ this.identifierMintingStrategy = identifierMintingStrategy;
39
41
  this.imports = imports;
40
42
  this.label = label;
41
43
  // Lazily initialize some members in getters to avoid recursive construction
42
44
  this.lazyAncestorObjectTypes = lazyAncestorObjectTypes;
45
+ this.lazyChildObjectTypes = lazyChildObjectTypes;
43
46
  this.lazyDescendantObjectTypes = lazyDescendantObjectTypes;
44
47
  this.lazyParentObjectTypes = lazyParentObjectTypes;
45
48
  this.lazyProperties = lazyProperties;
46
- this.identifierMintingStrategy = identifierMintingStrategy;
49
+ this.staticModuleName = staticModuleName;
50
+ this.synthetic = synthetic;
47
51
  this.toRdfTypes = toRdfTypes;
48
52
  }
49
53
  get _discriminatorProperty() {
@@ -51,12 +55,16 @@ export class ObjectType extends DeclaredType {
51
55
  invariant(discriminatorProperty);
52
56
  return {
53
57
  name: discriminatorProperty.name,
54
- values: [this.discriminatorValue],
58
+ ownValues: discriminatorProperty.type.ownValues,
59
+ descendantValues: discriminatorProperty.type.descendantValues,
55
60
  };
56
61
  }
57
62
  get ancestorObjectTypes() {
58
63
  return this.lazyAncestorObjectTypes();
59
64
  }
65
+ get childObjectTypes() {
66
+ return this.lazyChildObjectTypes();
67
+ }
60
68
  get conversions() {
61
69
  return [
62
70
  {
@@ -71,13 +79,15 @@ export class ObjectType extends DeclaredType {
71
79
  return [];
72
80
  }
73
81
  const imports = this.properties.flatMap((property) => property.declarationImports);
74
- if (this.features.has("fromJson") || this.features.has("jsonSchema")) {
75
- imports.push(Import.ZOD);
82
+ if (this.features.has("graphql")) {
83
+ imports.push(Import.GRAPHQL);
84
+ imports.push(Import.GRAPHQL_SCALARS);
76
85
  }
77
- if (this.features.has("jsonSchema")) {
86
+ if (this.features.has("json")) {
87
+ imports.push(Import.ZOD);
78
88
  imports.push(Import.ZOD_TO_JSON_SCHEMA);
79
89
  }
80
- if (this.features.has("fromRdf") || this.features.has("toRdf")) {
90
+ if (this.features.has("rdf")) {
81
91
  imports.push(Import.PURIFY);
82
92
  imports.push(Import.RDFJS_RESOURCE);
83
93
  }
@@ -91,26 +101,25 @@ export class ObjectType extends DeclaredType {
91
101
  ..._ObjectType.classDeclaration.bind(this)().toList(),
92
102
  ..._ObjectType.interfaceDeclaration.bind(this)().toList(),
93
103
  ];
94
- const moduleStatements = [
104
+ const staticModuleStatements = [
95
105
  ..._ObjectType.createFunctionDeclaration.bind(this)().toList(),
96
106
  ..._ObjectType.equalsFunctionDeclaration.bind(this)().toList(),
97
- ..._ObjectType.fromJsonFunctionDeclarations.bind(this)(),
98
- ..._ObjectType.fromRdfFunctionDeclarations.bind(this)(),
99
- ..._ObjectType.fromRdfTypeVariableDeclaration.bind(this)().toList(),
100
- ..._ObjectType.jsonSchemaFunctionDeclaration.bind(this)().toList(),
101
- ..._ObjectType.jsonUiSchemaFunctionDeclaration.bind(this)().toList(),
102
- ..._ObjectType.jsonZodSchemaFunctionDeclaration.bind(this)().toList(),
107
+ ..._ObjectType.fromRdfTypeVariableStatement.bind(this)().toList(),
108
+ ..._ObjectType.graphqlTypeVariableStatement.bind(this)().toList(),
109
+ ..._ObjectType.identifierTypeDeclarations.bind(this)(),
110
+ ..._ObjectType.jsonTypeAliasDeclaration.bind(this)().toList(),
111
+ ..._ObjectType.jsonFunctionDeclarations.bind(this)(),
103
112
  ..._ObjectType.hashFunctionDeclarations.bind(this)(),
113
+ ..._ObjectType.rdfFunctionDeclarations.bind(this)(),
114
+ ..._ObjectType.propertiesVariableStatement.bind(this)().toList(),
104
115
  ..._ObjectType.sparqlFunctionDeclarations.bind(this)(),
105
- ..._ObjectType.toJsonFunctionDeclaration.bind(this)().toList(),
106
- ..._ObjectType.toRdfFunctionDeclaration.bind(this)().toList(),
107
116
  ];
108
- if (moduleStatements.length > 0) {
117
+ if (staticModuleStatements.length > 0) {
109
118
  declarations.push({
110
119
  isExported: this.export,
111
120
  kind: StructureKind.Module,
112
- name: this.name,
113
- statements: moduleStatements,
121
+ name: this.staticModuleName,
122
+ statements: staticModuleStatements,
114
123
  });
115
124
  }
116
125
  return declarations;
@@ -127,24 +136,18 @@ export class ObjectType extends DeclaredType {
127
136
  get equalsFunction() {
128
137
  switch (this.declarationType) {
129
138
  case "class":
130
- return "((left, right) => left.equals(right))";
139
+ return `((left, right) => left.${syntheticNamePrefix}equals(right))`;
131
140
  case "interface":
132
- return `${this.name}.equals`;
141
+ return `${this.staticModuleName}.${syntheticNamePrefix}equals`;
133
142
  default:
134
143
  throw new RangeError(this.declarationType);
135
144
  }
136
145
  }
137
- get hashFunctionName() {
138
- if (this.ancestorObjectTypes.length > 0 ||
139
- this.descendantObjectTypes.length > 0)
140
- return `hash${this.name}`;
141
- return "hash";
146
+ get fromRdfTypeVariable() {
147
+ return this.fromRdfType.map(() => `${this.staticModuleName}.${syntheticNamePrefix}fromRdfType`);
142
148
  }
143
- get hashShaclPropertiesFunctionName() {
144
- if (this.ancestorObjectTypes.length > 0 ||
145
- this.descendantObjectTypes.length > 0)
146
- return `_hash${this.name}ShaclProperties`;
147
- return "_hashShaclProperties";
149
+ get graphqlName() {
150
+ return new Type.GraphqlName(`${this.staticModuleName}.${syntheticNamePrefix}GraphQL`);
148
151
  }
149
152
  get identifierProperty() {
150
153
  const identifierProperty = this.properties.find((property) => property instanceof ObjectType.IdentifierProperty);
@@ -154,37 +157,26 @@ export class ObjectType extends DeclaredType {
154
157
  get identifierType() {
155
158
  return this.identifierProperty.type;
156
159
  }
157
- get jsonName() {
158
- if (this.features.has("toJson")) {
159
- switch (this.declarationType) {
160
- case "class":
161
- return `ReturnType<${this.name}["toJson"]>`;
162
- case "interface":
163
- return `ReturnType<typeof ${this.name}.toJson>`;
164
- default:
165
- throw new RangeError(this.declarationType);
166
- }
167
- }
168
- if (this.features.has("fromJson")) {
169
- return `Parameters<typeof ${this.name}.fromJson>[0]`;
170
- }
171
- throw new RangeError(`${this.name}: jsonName called when neither fromJson nor toJson features are enabled`);
172
- }
173
- get jsonUiSchemaFunctionName() {
174
- if (this.ancestorObjectTypes.length > 0 ||
175
- this.descendantObjectTypes.length > 0)
176
- return `${camelCase(this.name)}JsonUiSchema`;
177
- return "jsonUiSchema";
160
+ get identifierTypeAlias() {
161
+ return `${this.staticModuleName}.${syntheticNamePrefix}Identifier`;
178
162
  }
179
- get jsonZodSchemaFunctionName() {
180
- if (this.ancestorObjectTypes.length > 0 ||
181
- this.descendantObjectTypes.length > 0)
182
- return `${camelCase(this.name)}JsonZodSchema`;
183
- return "jsonZodSchema";
163
+ get jsonName() {
164
+ return new Type.JsonName(`${this.staticModuleName}.${syntheticNamePrefix}Json`);
184
165
  }
185
166
  get mutable() {
186
167
  return this.properties.some((property) => property.mutable);
187
168
  }
169
+ newExpression({ parameters }) {
170
+ switch (this.declarationType) {
171
+ case "class":
172
+ return `new ${this.name}(${parameters})`;
173
+ case "interface":
174
+ return `${this.staticModuleName}.create(${parameters})`;
175
+ }
176
+ }
177
+ get objectSetMethodNames() {
178
+ return _ObjectType.objectSetMethodNames.bind(this)();
179
+ }
188
180
  get ownProperties() {
189
181
  if (this.parentObjectTypes.length === 0) {
190
182
  // Consider that a root of the object type hierarchy "owns" the identifier and type discriminator properties
@@ -201,7 +193,7 @@ export class ObjectType extends DeclaredType {
201
193
  return this.lazyParentObjectTypes();
202
194
  }
203
195
  get properties() {
204
- const properties = this.lazyProperties();
196
+ const properties = this.lazyProperties(this);
205
197
  const propertyNames = new Set();
206
198
  for (const property of properties) {
207
199
  if (propertyNames.has(property.name)) {
@@ -210,6 +202,12 @@ export class ObjectType extends DeclaredType {
210
202
  }
211
203
  return properties;
212
204
  }
205
+ get toRdfjsResourceType() {
206
+ if (this.parentObjectTypes.length > 0) {
207
+ return this.parentObjectTypes[0].toRdfjsResourceType;
208
+ }
209
+ return `rdfjsResource.MutableResource${this.identifierType.isNamedNodeKind ? "<rdfjs.NamedNode>" : ""}`;
210
+ }
213
211
  get thisVariable() {
214
212
  switch (this.declarationType) {
215
213
  case "class":
@@ -222,79 +220,89 @@ export class ObjectType extends DeclaredType {
222
220
  }
223
221
  fromJsonExpression({ variables, }) {
224
222
  // Assumes the JSON object has been recursively validated already.
225
- return `${this.name}.fromJson(${variables.value}).unsafeCoerce()`;
223
+ return `${this.staticModuleName}.${syntheticNamePrefix}fromJson(${variables.value}).unsafeCoerce()`;
226
224
  }
227
225
  fromRdfExpression({ variables, }) {
228
- // Ignore the rdf:type if the instance of this type is the object of another property.
229
- // Instead, assume the property has the correct range.
230
- // This also accommodates the case where the object of a property is a dangling identifier that's not the
231
- // subject of any statements.
232
- return `${variables.resourceValues}.head().chain(value => value.to${this.rdfjsResourceType().named ? "Named" : ""}Resource()).chain(_resource => ${this.name}.fromRdf({ ...${variables.context}, ignoreRdfType: true, languageIn: ${variables.languageIn}, resource: _resource }))`;
226
+ return `${variables.resourceValues}.head().chain(value => value.toResource()).chain(_resource => ${this.staticModuleName}.${syntheticNamePrefix}fromRdf({ ...${variables.context}, ${variables.ignoreRdfType ? "ignoreRdfType: true, " : ""}languageIn: ${variables.languageIn}, objectSet: ${variables.objectSet}, resource: _resource }))`;
227
+ }
228
+ graphqlResolveExpression({ variables, }) {
229
+ return variables.value;
233
230
  }
234
231
  hashStatements({ variables, }) {
235
232
  switch (this.declarationType) {
236
233
  case "class":
237
- return [`${variables.value}.hash(${variables.hasher});`];
234
+ return [
235
+ `${variables.value}.${syntheticNamePrefix}hash(${variables.hasher});`,
236
+ ];
238
237
  case "interface":
239
238
  return [
240
- `${this.name}.${this.hashFunctionName}(${variables.value}, ${variables.hasher});`,
239
+ `${this.staticModuleName}.${syntheticNamePrefix}hash(${variables.value}, ${variables.hasher});`,
241
240
  ];
242
241
  }
243
242
  }
244
243
  jsonUiSchemaElement({ variables, }) {
245
- return Maybe.of(`${this.name}.${this.jsonUiSchemaFunctionName}({ scopePrefix: ${variables.scopePrefix} })`);
246
- }
247
- jsonZodSchema(_parameters) {
248
- return `${this.name}.${this.jsonZodSchemaFunctionName}()`;
244
+ return Maybe.of(`${this.staticModuleName}.${syntheticNamePrefix}jsonUiSchema({ scopePrefix: ${variables.scopePrefix} })`);
249
245
  }
250
- rdfjsResourceType(options) {
251
- if (this.parentObjectTypes.length > 0) {
252
- return this.parentObjectTypes[0].rdfjsResourceType(options);
246
+ jsonZodSchema({ context, variables, }) {
247
+ let expression = `${this.staticModuleName}.${syntheticNamePrefix}jsonZodSchema()`;
248
+ if (context === "property" &&
249
+ this.properties.some((property) => property.recursive)) {
250
+ expression = `${variables.zod}.lazy((): ${variables.zod}.ZodType<${this.staticModuleName}.${syntheticNamePrefix}Json> => ${expression})`;
253
251
  }
254
- return {
255
- mutable: !!options?.mutable,
256
- name: `rdfjsResource.${options?.mutable ? "Mutable" : ""}Resource${this.identifierType.isNamedNodeKind ? "<rdfjs.NamedNode>" : ""}`,
257
- named: this.identifierType.isNamedNodeKind,
258
- };
252
+ return expression;
259
253
  }
260
- snippetDeclarations() {
254
+ snippetDeclarations({ recursionStack, }) {
255
+ if (recursionStack.some((type) => Object.is(type, this))) {
256
+ return [];
257
+ }
261
258
  const snippetDeclarations = [];
262
259
  if (this.features.has("equals")) {
263
260
  snippetDeclarations.push(SnippetDeclarations.EqualsResult);
264
261
  }
265
- if ((this.features.has("fromJson") || this.features.has("fromRdf")) &&
262
+ if (this.features.has("rdf")) {
263
+ snippetDeclarations.push(SnippetDeclarations.RdfVocabularies);
264
+ }
265
+ if (this.features.has("sparql") && this.fromRdfType.isJust()) {
266
+ snippetDeclarations.push(SnippetDeclarations.sparqlInstancesOfPattern);
267
+ }
268
+ if ((this.features.has("json") || this.features.has("rdf")) &&
266
269
  this.parentObjectTypes.length > 0) {
267
270
  snippetDeclarations.push(SnippetDeclarations.UnwrapR);
268
271
  }
272
+ recursionStack.push(this);
269
273
  for (const property of this.ownProperties) {
270
- snippetDeclarations.push(...property.snippetDeclarations);
274
+ snippetDeclarations.push(...property.snippetDeclarations({
275
+ features: this.features,
276
+ recursionStack,
277
+ }));
271
278
  }
279
+ invariant(Object.is(recursionStack.pop(), this));
272
280
  return snippetDeclarations;
273
281
  }
274
- sparqlConstructTemplateTriples({ context, variables, }) {
275
- switch (context) {
276
- case "property":
277
- return super.sparqlConstructTemplateTriples({ context, variables });
278
- case "type":
282
+ sparqlConstructTemplateTriples(parameters) {
283
+ switch (parameters.context) {
284
+ case "object":
285
+ return super.sparqlConstructTemplateTriples(parameters);
286
+ case "subject":
279
287
  return [
280
- `...${this.name}.sparqlConstructTemplateTriples(${objectInitializer({
281
- ignoreRdfType: true, // Can ignore the rdf:type when the object is nested
282
- subject: variables.subject,
283
- variablePrefix: variables.variablePrefix,
288
+ `...${this.staticModuleName}.${syntheticNamePrefix}sparqlConstructTemplateTriples(${objectInitializer({
289
+ ignoreRdfType: parameters.allowIgnoreRdfType ? true : undefined, // Can ignore the rdf:type when the object is nested
290
+ subject: parameters.variables.subject,
291
+ variablePrefix: parameters.variables.variablePrefix,
284
292
  })})`,
285
293
  ];
286
294
  }
287
295
  }
288
- sparqlWherePatterns({ context, variables, }) {
289
- switch (context) {
290
- case "property":
291
- return super.sparqlWherePatterns({ context, variables });
292
- case "type":
296
+ sparqlWherePatterns(parameters) {
297
+ switch (parameters.context) {
298
+ case "object":
299
+ return super.sparqlWherePatterns(parameters);
300
+ case "subject":
293
301
  return [
294
- `...${this.name}.sparqlWherePatterns(${objectInitializer({
295
- ignoreRdfType: true, // Can ignore the rdf:type when the object is nested
296
- subject: variables.subject,
297
- variablePrefix: variables.variablePrefix,
302
+ `...${this.staticModuleName}.${syntheticNamePrefix}sparqlWherePatterns(${objectInitializer({
303
+ ignoreRdfType: parameters.allowIgnoreRdfType ? true : undefined, // Can ignore the rdf:type when the object is nested
304
+ subject: parameters.variables.subject,
305
+ variablePrefix: parameters.variables.variablePrefix,
298
306
  })})`,
299
307
  ];
300
308
  }
@@ -302,20 +310,20 @@ export class ObjectType extends DeclaredType {
302
310
  toJsonExpression({ variables, }) {
303
311
  switch (this.declarationType) {
304
312
  case "class":
305
- return `${variables.value}.toJson()`;
313
+ return `${variables.value}.${syntheticNamePrefix}toJson()`;
306
314
  case "interface":
307
- return `${this.name}.toJson(${variables.value})`;
315
+ return `${this.staticModuleName}.${syntheticNamePrefix}toJson(${variables.value})`;
308
316
  }
309
317
  }
310
318
  toRdfExpression({ variables, }) {
311
319
  switch (this.declarationType) {
312
320
  case "class":
313
- return `${variables.value}.toRdf({ mutateGraph: ${variables.mutateGraph}, resourceSet: ${variables.resourceSet} })`;
321
+ return `${variables.value}.${syntheticNamePrefix}toRdf({ mutateGraph: ${variables.mutateGraph}, resourceSet: ${variables.resourceSet} })`;
314
322
  case "interface":
315
- return `${this.name}.toRdf(${variables.value}, { mutateGraph: ${variables.mutateGraph}, resourceSet: ${variables.resourceSet} })`;
323
+ return `${this.staticModuleName}.${syntheticNamePrefix}toRdf(${variables.value}, { mutateGraph: ${variables.mutateGraph}, resourceSet: ${variables.resourceSet} })`;
316
324
  }
317
325
  }
318
- useImports(_features) {
326
+ useImports() {
319
327
  return this.imports;
320
328
  }
321
329
  ensureAtMostOneSuperObjectType() {
@@ -323,6 +331,11 @@ export class ObjectType extends DeclaredType {
323
331
  throw new RangeError(`object type '${this.name}' has multiple super object types`);
324
332
  }
325
333
  }
334
+ lazyAncestorObjectTypes;
335
+ lazyChildObjectTypes;
336
+ lazyDescendantObjectTypes;
337
+ lazyParentObjectTypes;
338
+ lazyProperties;
326
339
  }
327
340
  __decorate([
328
341
  Memoize()
@@ -332,10 +345,10 @@ __decorate([
332
345
  ], ObjectType.prototype, "ancestorObjectTypes", null);
333
346
  __decorate([
334
347
  Memoize()
335
- ], ObjectType.prototype, "conversions", null);
348
+ ], ObjectType.prototype, "childObjectTypes", null);
336
349
  __decorate([
337
350
  Memoize()
338
- ], ObjectType.prototype, "declarationImports", null);
351
+ ], ObjectType.prototype, "conversions", null);
339
352
  __decorate([
340
353
  Memoize()
341
354
  ], ObjectType.prototype, "descendantObjectTypes", null);
@@ -350,10 +363,10 @@ __decorate([
350
363
  ], ObjectType.prototype, "equalsFunction", null);
351
364
  __decorate([
352
365
  Memoize()
353
- ], ObjectType.prototype, "hashFunctionName", null);
366
+ ], ObjectType.prototype, "fromRdfTypeVariable", null);
354
367
  __decorate([
355
368
  Memoize()
356
- ], ObjectType.prototype, "hashShaclPropertiesFunctionName", null);
369
+ ], ObjectType.prototype, "graphqlName", null);
357
370
  __decorate([
358
371
  Memoize()
359
372
  ], ObjectType.prototype, "identifierProperty", null);
@@ -362,16 +375,16 @@ __decorate([
362
375
  ], ObjectType.prototype, "identifierType", null);
363
376
  __decorate([
364
377
  Memoize()
365
- ], ObjectType.prototype, "jsonName", null);
378
+ ], ObjectType.prototype, "identifierTypeAlias", null);
366
379
  __decorate([
367
380
  Memoize()
368
- ], ObjectType.prototype, "jsonUiSchemaFunctionName", null);
381
+ ], ObjectType.prototype, "jsonName", null);
369
382
  __decorate([
370
383
  Memoize()
371
- ], ObjectType.prototype, "jsonZodSchemaFunctionName", null);
384
+ ], ObjectType.prototype, "mutable", null);
372
385
  __decorate([
373
386
  Memoize()
374
- ], ObjectType.prototype, "mutable", null);
387
+ ], ObjectType.prototype, "objectSetMethodNames", null);
375
388
  __decorate([
376
389
  Memoize()
377
390
  ], ObjectType.prototype, "ownProperties", null);
@@ -384,12 +397,20 @@ __decorate([
384
397
  __decorate([
385
398
  Memoize()
386
399
  ], ObjectType.prototype, "properties", null);
400
+ __decorate([
401
+ Memoize()
402
+ ], ObjectType.prototype, "toRdfjsResourceType", null);
387
403
  __decorate([
388
404
  Memoize()
389
405
  ], ObjectType.prototype, "thisVariable", null);
406
+ __decorate([
407
+ Memoize()
408
+ ], ObjectType.prototype, "useImports", null);
390
409
  (function (ObjectType) {
410
+ ObjectType.EagerShaclProperty = _ObjectType.EagerShaclProperty;
391
411
  ObjectType.IdentifierPrefixProperty = _ObjectType.IdentifierPrefixProperty;
392
412
  ObjectType.IdentifierProperty = _ObjectType.IdentifierProperty;
413
+ ObjectType.LazyShaclProperty = _ObjectType.LazyShaclProperty;
393
414
  ObjectType.Property = _ObjectType.Property;
394
415
  ObjectType.ShaclProperty = _ObjectType.ShaclProperty;
395
416
  ObjectType.TypeDiscriminatorProperty = _ObjectType.TypeDiscriminatorProperty;
@@ -1,9 +1,33 @@
1
1
  import { Maybe } from "purify-ts";
2
2
  import { type ModuleDeclarationStructure, type TypeAliasDeclarationStructure } from "ts-morph";
3
3
  import { DeclaredType } from "./DeclaredType.js";
4
+ import type { IdentifierType } from "./IdentifierType.js";
4
5
  import type { Import } from "./Import.js";
5
6
  import type { ObjectType } from "./ObjectType.js";
6
- import type { Type } from "./Type.js";
7
+ import { Type } from "./Type.js";
8
+ declare class MemberType {
9
+ private readonly delegate;
10
+ private readonly universe;
11
+ constructor({ delegate, universe, }: {
12
+ delegate: ObjectType;
13
+ universe: readonly ObjectType[];
14
+ });
15
+ get declarationType(): import("../../enums/TsObjectDeclarationType.js").TsObjectDeclarationType;
16
+ get discriminatorPropertyValues(): readonly string[];
17
+ get features(): Set<import("../../enums/TsFeature.js").TsFeature>;
18
+ get fromRdfType(): Maybe<import("@rdfjs/types").NamedNode<string>>;
19
+ get fromRdfTypeVariable(): Maybe<string>;
20
+ get graphqlName(): Type.GraphqlName;
21
+ get identifierTypeAlias(): string;
22
+ get jsonName(): Type.JsonName;
23
+ get mutable(): boolean;
24
+ get name(): string;
25
+ get staticModuleName(): string;
26
+ get toRdfjsResourceType(): string;
27
+ jsonZodSchema(parameters: Parameters<DeclaredType["jsonZodSchema"]>[0]): string;
28
+ snippetDeclarations(parameters: Parameters<DeclaredType["snippetDeclarations"]>[0]): readonly string[];
29
+ useImports(): readonly Import[];
30
+ }
7
31
  /**
8
32
  * A union of object types, generated as a type alias
9
33
  *
@@ -15,14 +39,17 @@ import type { Type } from "./Type.js";
15
39
  * It also generates SPARQL graph patterns that UNION the member object types.
16
40
  */
17
41
  export declare class ObjectUnionType extends DeclaredType {
18
- readonly kind = "ObjectUnionType";
19
42
  private readonly _discriminatorProperty;
20
43
  private readonly comment;
21
44
  private readonly label;
22
- private readonly memberTypes;
23
- constructor({ comment, label, memberTypes, ...superParameters }: ConstructorParameters<typeof DeclaredType>[0] & {
45
+ readonly identifierType: IdentifierType;
46
+ readonly kind = "ObjectUnionType";
47
+ readonly memberTypes: readonly MemberType[];
48
+ readonly typeof = "object";
49
+ constructor({ comment, identifierType, label, memberTypes, ...superParameters }: ConstructorParameters<typeof DeclaredType>[0] & {
24
50
  comment: Maybe<string>;
25
51
  export_: boolean;
52
+ identifierType: IdentifierType;
26
53
  label: Maybe<string>;
27
54
  memberTypes: readonly ObjectType[];
28
55
  name: string;
@@ -32,13 +59,20 @@ export declare class ObjectUnionType extends DeclaredType {
32
59
  get declarations(): (ModuleDeclarationStructure | TypeAliasDeclarationStructure)[];
33
60
  get discriminatorProperty(): Maybe<Type.DiscriminatorProperty>;
34
61
  get equalsFunction(): string;
35
- get jsonName(): string;
62
+ get graphqlName(): Type.GraphqlName;
63
+ get identifierTypeAlias(): string;
64
+ get jsonName(): Type.JsonName;
36
65
  get mutable(): boolean;
66
+ get objectSetMethodNames(): ObjectType.ObjectSetMethodNames;
67
+ get staticModuleName(): string;
37
68
  protected get thisVariable(): string;
38
69
  private get equalsFunctionDeclaration();
39
70
  private get fromJsonFunctionDeclaration();
40
71
  private get fromRdfFunctionDeclaration();
72
+ private get graphqlTypeVariableStatement();
41
73
  private get hashFunctionDeclaration();
74
+ private get identifierTypeDeclarations();
75
+ private get jsonTypeAliasDeclaration();
42
76
  private get jsonZodSchemaFunctionDeclaration();
43
77
  private get sparqlFunctionDeclarations();
44
78
  private get toJsonFunctionDeclaration();
@@ -46,13 +80,20 @@ export declare class ObjectUnionType extends DeclaredType {
46
80
  private get typeAliasDeclaration();
47
81
  fromJsonExpression({ variables, }: Parameters<Type["fromJsonExpression"]>[0]): string;
48
82
  fromRdfExpression({ variables, }: Parameters<Type["fromRdfExpression"]>[0]): string;
83
+ graphqlResolveExpression({ variables, }: {
84
+ variables: {
85
+ value: string;
86
+ };
87
+ }): string;
49
88
  hashStatements({ variables, }: Parameters<Type["hashStatements"]>[0]): readonly string[];
89
+ jsonUiSchemaElement(): Maybe<string>;
50
90
  jsonZodSchema(): ReturnType<Type["jsonZodSchema"]>;
51
- sparqlConstructTemplateTriples({ context, variables, }: Parameters<Type["sparqlConstructTemplateTriples"]>[0]): readonly string[];
52
- sparqlWherePatterns({ context, variables, }: Parameters<Type["sparqlWherePatterns"]>[0]): readonly string[];
91
+ snippetDeclarations(parameters: Parameters<DeclaredType["snippetDeclarations"]>[0]): readonly string[];
92
+ sparqlConstructTemplateTriples(parameters: Parameters<Type["sparqlConstructTemplateTriples"]>[0]): readonly string[];
93
+ sparqlWherePatterns(parameters: Parameters<Type["sparqlWherePatterns"]>[0]): readonly string[];
53
94
  toJsonExpression({ variables, }: Parameters<Type["toJsonExpression"]>[0]): string;
54
95
  toRdfExpression({ variables, }: Parameters<Type["toRdfExpression"]>[0]): string;
55
96
  useImports(): readonly Import[];
56
- private rdfjsResourceType;
57
97
  }
98
+ export {};
58
99
  //# sourceMappingURL=ObjectUnionType.d.ts.map