@shaclmate/compiler 2.0.15 → 2.0.17

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 (219) hide show
  1. package/{Compiler.js → dist/Compiler.js} +2 -0
  2. package/{ShapesGraphToAstTransformer.js → dist/ShapesGraphToAstTransformer.js} +13 -11
  3. package/{_ShapesGraphToAstTransformer → dist/_ShapesGraphToAstTransformer}/transformNodeShapeToAstType.js +8 -4
  4. package/{_ShapesGraphToAstTransformer → dist/_ShapesGraphToAstTransformer}/transformPropertyShapeToAstCompositeType.js +2 -2
  5. package/{_ShapesGraphToAstTransformer → dist/_ShapesGraphToAstTransformer}/transformPropertyShapeToAstType.js +2 -0
  6. package/{ast → dist/ast}/ListType.d.ts +2 -2
  7. package/{ast → dist/ast}/ObjectType.d.ts +18 -12
  8. package/dist/ast/SetType.d.ts +23 -0
  9. package/dist/enums/IdentifierMintingStrategy.d.ts +5 -0
  10. package/dist/enums/IdentifierMintingStrategy.js +2 -0
  11. package/{enums → dist/enums}/index.d.ts +1 -1
  12. package/{enums → dist/enums}/index.js +1 -1
  13. package/{generators → dist/generators}/index.d.ts +1 -0
  14. package/{generators → dist/generators}/index.js +1 -0
  15. package/{generators → dist/generators}/json/AstJsonGenerator.js +5 -1
  16. package/{generators → dist/generators}/ts/BooleanType.js +1 -4
  17. package/{generators → dist/generators}/ts/DateTimeType.d.ts +4 -1
  18. package/{generators → dist/generators}/ts/DateTimeType.js +11 -10
  19. package/dist/generators/ts/DateType.d.ts +9 -0
  20. package/dist/generators/ts/DateType.js +11 -0
  21. package/{generators → dist/generators}/ts/DeclaredType.js +3 -0
  22. package/{generators → dist/generators}/ts/IdentifierType.d.ts +2 -0
  23. package/{generators → dist/generators}/ts/IdentifierType.js +11 -3
  24. package/{generators → dist/generators}/ts/ListType.d.ts +6 -5
  25. package/{generators → dist/generators}/ts/ListType.js +28 -14
  26. package/{generators → dist/generators}/ts/LiteralType.js +1 -0
  27. package/{generators → dist/generators}/ts/NumberType.js +1 -4
  28. package/{generators → dist/generators}/ts/ObjectType.d.ts +4 -4
  29. package/{generators → dist/generators}/ts/ObjectType.js +17 -3
  30. package/{generators → dist/generators}/ts/ObjectUnionType.js +13 -8
  31. package/{generators → dist/generators}/ts/OptionType.js +5 -2
  32. package/{generators → dist/generators}/ts/PrimitiveType.js +3 -1
  33. package/{generators → dist/generators}/ts/SetType.d.ts +3 -1
  34. package/{generators → dist/generators}/ts/SetType.js +16 -10
  35. package/{generators → dist/generators}/ts/StringType.js +1 -4
  36. package/{generators → dist/generators}/ts/TermType.js +9 -5
  37. package/{generators → dist/generators}/ts/Type.js +1 -0
  38. package/{generators → dist/generators}/ts/TypeFactory.js +12 -9
  39. package/{generators → dist/generators}/ts/UnionType.js +3 -1
  40. package/{generators → dist/generators}/ts/_ObjectType/IdentifierProperty.d.ts +5 -5
  41. package/{generators → dist/generators}/ts/_ObjectType/IdentifierProperty.js +91 -21
  42. package/{generators → dist/generators}/ts/_ObjectType/Property.js +14 -0
  43. package/{generators → dist/generators}/ts/_ObjectType/ShaclProperty.js +5 -0
  44. package/{generators → dist/generators}/ts/_ObjectType/TypeDiscriminatorProperty.js +7 -2
  45. package/dist/generators/ts/_ObjectType/fromRdfTypeVariableStatement.d.ts +5 -0
  46. package/dist/generators/ts/_ObjectType/fromRdfTypeVariableStatement.js +25 -0
  47. package/{generators → dist/generators}/ts/_ObjectType/index.d.ts +1 -0
  48. package/{generators → dist/generators}/ts/_ObjectType/index.js +1 -0
  49. package/{generators → dist/generators}/ts/_ObjectType/toRdfFunctionOrMethodDeclaration.js +3 -3
  50. package/dist/index.d.ts +3 -0
  51. package/dist/index.js +3 -0
  52. package/{input → dist/input}/NodeShape.d.ts +2 -2
  53. package/{input → dist/input}/NodeShape.js +11 -4
  54. package/{input → dist/input}/Ontology.js +1 -0
  55. package/{input → dist/input}/PropertyShape.js +1 -0
  56. package/{input → dist/input}/generated.d.ts +19 -12
  57. package/{input → dist/input}/generated.js +51 -22
  58. package/dist/input/tsFeatures.d.ts +10 -0
  59. package/{input → dist/input}/tsFeatures.js +4 -0
  60. package/package.json +28 -24
  61. package/ast/SetType.d.ts +0 -12
  62. package/enums/MintingStrategy.d.ts +0 -5
  63. package/enums/MintingStrategy.js +0 -2
  64. package/index.d.ts +0 -2
  65. package/index.js +0 -2
  66. package/input/tsFeatures.d.ts +0 -10
  67. /package/{Compiler.d.ts → dist/Compiler.d.ts} +0 -0
  68. /package/{ShapesGraphToAstTransformer.d.ts → dist/ShapesGraphToAstTransformer.d.ts} +0 -0
  69. /package/{_ShapesGraphToAstTransformer → dist/_ShapesGraphToAstTransformer}/NodeShapeAstType.d.ts +0 -0
  70. /package/{_ShapesGraphToAstTransformer → dist/_ShapesGraphToAstTransformer}/NodeShapeAstType.js +0 -0
  71. /package/{_ShapesGraphToAstTransformer → dist/_ShapesGraphToAstTransformer}/index.d.ts +0 -0
  72. /package/{_ShapesGraphToAstTransformer → dist/_ShapesGraphToAstTransformer}/index.js +0 -0
  73. /package/{_ShapesGraphToAstTransformer → dist/_ShapesGraphToAstTransformer}/pickLiteral.d.ts +0 -0
  74. /package/{_ShapesGraphToAstTransformer → dist/_ShapesGraphToAstTransformer}/pickLiteral.js +0 -0
  75. /package/{_ShapesGraphToAstTransformer → dist/_ShapesGraphToAstTransformer}/propertyShapeNodeKinds.d.ts +0 -0
  76. /package/{_ShapesGraphToAstTransformer → dist/_ShapesGraphToAstTransformer}/propertyShapeNodeKinds.js +0 -0
  77. /package/{_ShapesGraphToAstTransformer → dist/_ShapesGraphToAstTransformer}/shapeAstName.d.ts +0 -0
  78. /package/{_ShapesGraphToAstTransformer → dist/_ShapesGraphToAstTransformer}/shapeAstName.js +0 -0
  79. /package/{_ShapesGraphToAstTransformer → dist/_ShapesGraphToAstTransformer}/transformNodeShapeToAstType.d.ts +0 -0
  80. /package/{_ShapesGraphToAstTransformer → dist/_ShapesGraphToAstTransformer}/transformPropertyShapeToAstCompositeType.d.ts +0 -0
  81. /package/{_ShapesGraphToAstTransformer → dist/_ShapesGraphToAstTransformer}/transformPropertyShapeToAstIdentifierType.d.ts +0 -0
  82. /package/{_ShapesGraphToAstTransformer → dist/_ShapesGraphToAstTransformer}/transformPropertyShapeToAstIdentifierType.js +0 -0
  83. /package/{_ShapesGraphToAstTransformer → dist/_ShapesGraphToAstTransformer}/transformPropertyShapeToAstLiteralType.d.ts +0 -0
  84. /package/{_ShapesGraphToAstTransformer → dist/_ShapesGraphToAstTransformer}/transformPropertyShapeToAstLiteralType.js +0 -0
  85. /package/{_ShapesGraphToAstTransformer → dist/_ShapesGraphToAstTransformer}/transformPropertyShapeToAstObjectTypeProperty.d.ts +0 -0
  86. /package/{_ShapesGraphToAstTransformer → dist/_ShapesGraphToAstTransformer}/transformPropertyShapeToAstObjectTypeProperty.js +0 -0
  87. /package/{_ShapesGraphToAstTransformer → dist/_ShapesGraphToAstTransformer}/transformPropertyShapeToAstTermType.d.ts +0 -0
  88. /package/{_ShapesGraphToAstTransformer → dist/_ShapesGraphToAstTransformer}/transformPropertyShapeToAstTermType.js +0 -0
  89. /package/{_ShapesGraphToAstTransformer → dist/_ShapesGraphToAstTransformer}/transformPropertyShapeToAstType.d.ts +0 -0
  90. /package/{ast → dist/ast}/Ast.d.ts +0 -0
  91. /package/{ast → dist/ast}/Ast.js +0 -0
  92. /package/{ast → dist/ast}/CompositeType.d.ts +0 -0
  93. /package/{ast → dist/ast}/CompositeType.js +0 -0
  94. /package/{ast → dist/ast}/IdentifierType.d.ts +0 -0
  95. /package/{ast → dist/ast}/IdentifierType.js +0 -0
  96. /package/{ast → dist/ast}/IntersectionType.d.ts +0 -0
  97. /package/{ast → dist/ast}/IntersectionType.js +0 -0
  98. /package/{ast → dist/ast}/ListType.js +0 -0
  99. /package/{ast → dist/ast}/LiteralType.d.ts +0 -0
  100. /package/{ast → dist/ast}/LiteralType.js +0 -0
  101. /package/{ast → dist/ast}/Name.d.ts +0 -0
  102. /package/{ast → dist/ast}/Name.js +0 -0
  103. /package/{ast → dist/ast}/ObjectCompositeType.d.ts +0 -0
  104. /package/{ast → dist/ast}/ObjectCompositeType.js +0 -0
  105. /package/{ast → dist/ast}/ObjectIntersectionType.d.ts +0 -0
  106. /package/{ast → dist/ast}/ObjectIntersectionType.js +0 -0
  107. /package/{ast → dist/ast}/ObjectType.js +0 -0
  108. /package/{ast → dist/ast}/ObjectUnionType.d.ts +0 -0
  109. /package/{ast → dist/ast}/ObjectUnionType.js +0 -0
  110. /package/{ast → dist/ast}/OptionType.d.ts +0 -0
  111. /package/{ast → dist/ast}/OptionType.js +0 -0
  112. /package/{ast → dist/ast}/PlaceholderType.d.ts +0 -0
  113. /package/{ast → dist/ast}/PlaceholderType.js +0 -0
  114. /package/{ast → dist/ast}/SetType.js +0 -0
  115. /package/{ast → dist/ast}/TermType.d.ts +0 -0
  116. /package/{ast → dist/ast}/TermType.js +0 -0
  117. /package/{ast → dist/ast}/Type.d.ts +0 -0
  118. /package/{ast → dist/ast}/Type.js +0 -0
  119. /package/{ast → dist/ast}/UnionType.d.ts +0 -0
  120. /package/{ast → dist/ast}/UnionType.js +0 -0
  121. /package/{ast → dist/ast}/index.d.ts +0 -0
  122. /package/{ast → dist/ast}/index.js +0 -0
  123. /package/{enums → dist/enums}/PropertyVisibility.d.ts +0 -0
  124. /package/{enums → dist/enums}/PropertyVisibility.js +0 -0
  125. /package/{enums → dist/enums}/TsFeature.d.ts +0 -0
  126. /package/{enums → dist/enums}/TsFeature.js +0 -0
  127. /package/{enums → dist/enums}/TsObjectDeclarationType.d.ts +0 -0
  128. /package/{enums → dist/enums}/TsObjectDeclarationType.js +0 -0
  129. /package/{generators → dist/generators}/Generator.d.ts +0 -0
  130. /package/{generators → dist/generators}/Generator.js +0 -0
  131. /package/{generators → dist/generators}/json/AstJsonGenerator.d.ts +0 -0
  132. /package/{generators → dist/generators}/json/index.d.ts +0 -0
  133. /package/{generators → dist/generators}/json/index.js +0 -0
  134. /package/{generators → dist/generators}/ts/BooleanType.d.ts +0 -0
  135. /package/{generators → dist/generators}/ts/DeclaredType.d.ts +0 -0
  136. /package/{generators → dist/generators}/ts/Import.d.ts +0 -0
  137. /package/{generators → dist/generators}/ts/Import.js +0 -0
  138. /package/{generators → dist/generators}/ts/LiteralType.d.ts +0 -0
  139. /package/{generators → dist/generators}/ts/NumberType.d.ts +0 -0
  140. /package/{generators → dist/generators}/ts/ObjectUnionType.d.ts +0 -0
  141. /package/{generators → dist/generators}/ts/OptionType.d.ts +0 -0
  142. /package/{generators → dist/generators}/ts/PrimitiveType.d.ts +0 -0
  143. /package/{generators → dist/generators}/ts/SnippetDeclarations.d.ts +0 -0
  144. /package/{generators → dist/generators}/ts/SnippetDeclarations.js +0 -0
  145. /package/{generators → dist/generators}/ts/StringType.d.ts +0 -0
  146. /package/{generators → dist/generators}/ts/TermType.d.ts +0 -0
  147. /package/{generators → dist/generators}/ts/TsGenerator.d.ts +0 -0
  148. /package/{generators → dist/generators}/ts/TsGenerator.js +0 -0
  149. /package/{generators → dist/generators}/ts/Type.d.ts +0 -0
  150. /package/{generators → dist/generators}/ts/TypeFactory.d.ts +0 -0
  151. /package/{generators → dist/generators}/ts/UnionType.d.ts +0 -0
  152. /package/{generators → dist/generators}/ts/_ObjectType/Property.d.ts +0 -0
  153. /package/{generators → dist/generators}/ts/_ObjectType/ShaclProperty.d.ts +0 -0
  154. /package/{generators → dist/generators}/ts/_ObjectType/TypeDiscriminatorProperty.d.ts +0 -0
  155. /package/{generators → dist/generators}/ts/_ObjectType/classDeclaration.d.ts +0 -0
  156. /package/{generators → dist/generators}/ts/_ObjectType/classDeclaration.js +0 -0
  157. /package/{generators → dist/generators}/ts/_ObjectType/createFunctionDeclaration.d.ts +0 -0
  158. /package/{generators → dist/generators}/ts/_ObjectType/createFunctionDeclaration.js +0 -0
  159. /package/{generators → dist/generators}/ts/_ObjectType/equalsFunctionDeclaration.d.ts +0 -0
  160. /package/{generators → dist/generators}/ts/_ObjectType/equalsFunctionDeclaration.js +0 -0
  161. /package/{generators → dist/generators}/ts/_ObjectType/equalsFunctionOrMethodDeclaration.d.ts +0 -0
  162. /package/{generators → dist/generators}/ts/_ObjectType/equalsFunctionOrMethodDeclaration.js +0 -0
  163. /package/{generators → dist/generators}/ts/_ObjectType/fromJsonFunctionDeclarations.d.ts +0 -0
  164. /package/{generators → dist/generators}/ts/_ObjectType/fromJsonFunctionDeclarations.js +0 -0
  165. /package/{generators → dist/generators}/ts/_ObjectType/fromRdfFunctionDeclarations.d.ts +0 -0
  166. /package/{generators → dist/generators}/ts/_ObjectType/fromRdfFunctionDeclarations.js +0 -0
  167. /package/{generators → dist/generators}/ts/_ObjectType/hashFunctionDeclaration.d.ts +0 -0
  168. /package/{generators → dist/generators}/ts/_ObjectType/hashFunctionDeclaration.js +0 -0
  169. /package/{generators → dist/generators}/ts/_ObjectType/hashFunctionOrMethodDeclaration.d.ts +0 -0
  170. /package/{generators → dist/generators}/ts/_ObjectType/hashFunctionOrMethodDeclaration.js +0 -0
  171. /package/{generators → dist/generators}/ts/_ObjectType/interfaceDeclaration.d.ts +0 -0
  172. /package/{generators → dist/generators}/ts/_ObjectType/interfaceDeclaration.js +0 -0
  173. /package/{generators → dist/generators}/ts/_ObjectType/jsonSchemaFunctionDeclaration.d.ts +0 -0
  174. /package/{generators → dist/generators}/ts/_ObjectType/jsonSchemaFunctionDeclaration.js +0 -0
  175. /package/{generators → dist/generators}/ts/_ObjectType/jsonUiSchemaFunctionDeclaration.d.ts +0 -0
  176. /package/{generators → dist/generators}/ts/_ObjectType/jsonUiSchemaFunctionDeclaration.js +0 -0
  177. /package/{generators → dist/generators}/ts/_ObjectType/jsonZodSchemaFunctionDeclaration.d.ts +0 -0
  178. /package/{generators → dist/generators}/ts/_ObjectType/jsonZodSchemaFunctionDeclaration.js +0 -0
  179. /package/{generators → dist/generators}/ts/_ObjectType/rdfjsTermExpression.d.ts +0 -0
  180. /package/{generators → dist/generators}/ts/_ObjectType/rdfjsTermExpression.js +0 -0
  181. /package/{generators → dist/generators}/ts/_ObjectType/sparqlConstructQueryFunctionDeclaration.d.ts +0 -0
  182. /package/{generators → dist/generators}/ts/_ObjectType/sparqlConstructQueryFunctionDeclaration.js +0 -0
  183. /package/{generators → dist/generators}/ts/_ObjectType/sparqlConstructQueryStringFunctionDeclaration.d.ts +0 -0
  184. /package/{generators → dist/generators}/ts/_ObjectType/sparqlConstructQueryStringFunctionDeclaration.js +0 -0
  185. /package/{generators → dist/generators}/ts/_ObjectType/sparqlFunctionDeclarations.d.ts +0 -0
  186. /package/{generators → dist/generators}/ts/_ObjectType/sparqlFunctionDeclarations.js +0 -0
  187. /package/{generators → dist/generators}/ts/_ObjectType/toJsonFunctionDeclaration.d.ts +0 -0
  188. /package/{generators → dist/generators}/ts/_ObjectType/toJsonFunctionDeclaration.js +0 -0
  189. /package/{generators → dist/generators}/ts/_ObjectType/toJsonFunctionOrMethodDeclaration.d.ts +0 -0
  190. /package/{generators → dist/generators}/ts/_ObjectType/toJsonFunctionOrMethodDeclaration.js +0 -0
  191. /package/{generators → dist/generators}/ts/_ObjectType/toJsonReturnType.d.ts +0 -0
  192. /package/{generators → dist/generators}/ts/_ObjectType/toJsonReturnType.js +0 -0
  193. /package/{generators → dist/generators}/ts/_ObjectType/toRdfFunctionDeclaration.d.ts +0 -0
  194. /package/{generators → dist/generators}/ts/_ObjectType/toRdfFunctionDeclaration.js +0 -0
  195. /package/{generators → dist/generators}/ts/_ObjectType/toRdfFunctionOrMethodDeclaration.d.ts +0 -0
  196. /package/{generators → dist/generators}/ts/index.d.ts +0 -0
  197. /package/{generators → dist/generators}/ts/index.js +0 -0
  198. /package/{generators → dist/generators}/ts/objectInitializer.d.ts +0 -0
  199. /package/{generators → dist/generators}/ts/objectInitializer.js +0 -0
  200. /package/{generators → dist/generators}/ts/stringToValidTsIdentifier.d.ts +0 -0
  201. /package/{generators → dist/generators}/ts/stringToValidTsIdentifier.js +0 -0
  202. /package/{generators → dist/generators}/ts/tsComment.d.ts +0 -0
  203. /package/{generators → dist/generators}/ts/tsComment.js +0 -0
  204. /package/{generators → dist/generators}/ts/tsName.d.ts +0 -0
  205. /package/{generators → dist/generators}/ts/tsName.js +0 -0
  206. /package/{input → dist/input}/Ontology.d.ts +0 -0
  207. /package/{input → dist/input}/PropertyShape.d.ts +0 -0
  208. /package/{input → dist/input}/Shape.d.ts +0 -0
  209. /package/{input → dist/input}/Shape.js +0 -0
  210. /package/{input → dist/input}/ShapesGraph.d.ts +0 -0
  211. /package/{input → dist/input}/ShapesGraph.js +0 -0
  212. /package/{input → dist/input}/ancestorClassIris.d.ts +0 -0
  213. /package/{input → dist/input}/ancestorClassIris.js +0 -0
  214. /package/{input → dist/input}/descendantClassIris.d.ts +0 -0
  215. /package/{input → dist/input}/descendantClassIris.js +0 -0
  216. /package/{input → dist/input}/index.d.ts +0 -0
  217. /package/{input → dist/input}/index.js +0 -0
  218. /package/{logger.d.ts → dist/logger.d.ts} +0 -0
  219. /package/{logger.js → dist/logger.js} +0 -0
@@ -16,9 +16,22 @@ import * as _ObjectType from "./_ObjectType/index.js";
16
16
  import { IdentifierProperty, TypeDiscriminatorProperty, } from "./_ObjectType/index.js";
17
17
  import { objectInitializer } from "./objectInitializer.js";
18
18
  export class ObjectType extends DeclaredType {
19
- constructor({ abstract, comment, declarationType, extern, fromRdfType, label, lazyAncestorObjectTypes, lazyDescendantObjectTypes, lazyParentObjectTypes, lazyProperties, imports, mintingStrategy, toRdfTypes, ...superParameters }) {
19
+ abstract;
20
+ declarationType;
21
+ kind = "ObjectType";
22
+ comment;
23
+ extern;
24
+ fromRdfType;
25
+ label;
26
+ identifierMintingStrategy;
27
+ toRdfTypes;
28
+ imports;
29
+ lazyAncestorObjectTypes;
30
+ lazyDescendantObjectTypes;
31
+ lazyParentObjectTypes;
32
+ lazyProperties;
33
+ constructor({ abstract, comment, declarationType, extern, fromRdfType, label, lazyAncestorObjectTypes, lazyDescendantObjectTypes, lazyParentObjectTypes, lazyProperties, imports, identifierMintingStrategy, toRdfTypes, ...superParameters }) {
20
34
  super(superParameters);
21
- this.kind = "ObjectType";
22
35
  this.abstract = abstract;
23
36
  this.comment = comment;
24
37
  this.declarationType = declarationType;
@@ -31,7 +44,7 @@ export class ObjectType extends DeclaredType {
31
44
  this.lazyDescendantObjectTypes = lazyDescendantObjectTypes;
32
45
  this.lazyParentObjectTypes = lazyParentObjectTypes;
33
46
  this.lazyProperties = lazyProperties;
34
- this.mintingStrategy = mintingStrategy;
47
+ this.identifierMintingStrategy = identifierMintingStrategy;
35
48
  this.toRdfTypes = toRdfTypes;
36
49
  }
37
50
  get _discriminatorProperty() {
@@ -84,6 +97,7 @@ export class ObjectType extends DeclaredType {
84
97
  ..._ObjectType.equalsFunctionDeclaration.bind(this)().toList(),
85
98
  ..._ObjectType.fromJsonFunctionDeclarations.bind(this)(),
86
99
  ..._ObjectType.fromRdfFunctionDeclarations.bind(this)(),
100
+ ..._ObjectType.fromRdfTypeVariableDeclaration.bind(this)().toList(),
87
101
  ..._ObjectType.jsonSchemaFunctionDeclaration.bind(this)().toList(),
88
102
  ..._ObjectType.jsonUiSchemaFunctionDeclaration.bind(this)().toList(),
89
103
  ..._ObjectType.jsonZodSchemaFunctionDeclaration.bind(this)().toList(),
@@ -26,9 +26,13 @@ import { tsComment } from "./tsComment.js";
26
26
  * It also generates SPARQL graph patterns that UNION the member object types.
27
27
  */
28
28
  export class ObjectUnionType extends DeclaredType {
29
+ kind = "ObjectUnionType";
30
+ _discriminatorProperty;
31
+ comment;
32
+ label;
33
+ memberTypes;
29
34
  constructor({ comment, label, memberTypes, ...superParameters }) {
30
35
  super(superParameters);
31
- this.kind = "ObjectUnionType";
32
36
  this.comment = comment;
33
37
  this.label = label;
34
38
  invariant(memberTypes.length > 0);
@@ -170,14 +174,14 @@ return strictEquals(left.type, right.type).chain(() => {
170
174
  name: "fromRdf",
171
175
  parameters: [
172
176
  {
173
- name: "parameters",
177
+ name: "{ ignoreRdfType, resource, ...context }",
174
178
  type: `{ [_index: string]: any; ignoreRdfType?: boolean; resource: ${this.rdfjsResourceType().name}; }`,
175
179
  },
176
180
  ],
177
181
  returnType: `purify.Either<rdfjsResource.Resource.ValueError, ${this.name}>`,
178
182
  statements: [
179
183
  `return ${this.memberTypes.reduce((expression, memberType) => {
180
- const memberTypeExpression = `(${memberType.name}.fromRdf(parameters) as purify.Either<rdfjsResource.Resource.ValueError, ${this.name}>)`;
184
+ const memberTypeExpression = `(${memberType.name}.fromRdf({ ...context, resource }) as purify.Either<rdfjsResource.Resource.ValueError, ${this.name}>)`;
181
185
  return expression.length > 0
182
186
  ? `${expression}.altLazy(() => ${memberTypeExpression})`
183
187
  : memberTypeExpression;
@@ -249,6 +253,7 @@ return strictEquals(left.type, right.type).chain(() => {
249
253
  isExported: true,
250
254
  kind: StructureKind.Function,
251
255
  name: "sparqlConstructTemplateTriples",
256
+ // Accept ignoreRdfType in order to reuse code but don't pass it through, since deserialization may depend on it
252
257
  parameters: [
253
258
  {
254
259
  name: "parameters",
@@ -258,7 +263,7 @@ return strictEquals(left.type, right.type).chain(() => {
258
263
  returnType: "readonly sparqljs.Triple[]",
259
264
  statements: [
260
265
  `return [${this.memberTypes
261
- .map((memberType) => `...${memberType.name}.sparqlConstructTemplateTriples({ ignoreRdfType: parameters?.ignoreRdfType, 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()`)
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()`)
262
267
  .join(", ")}];`,
263
268
  ],
264
269
  },
@@ -266,6 +271,7 @@ return strictEquals(left.type, right.type).chain(() => {
266
271
  isExported: true,
267
272
  kind: StructureKind.Function,
268
273
  name: "sparqlWherePatterns",
274
+ // Accept ignoreRdfType in order to reuse code but don't pass it through, since deserialization may depend on it
269
275
  parameters: [
270
276
  {
271
277
  name: "parameters",
@@ -276,7 +282,7 @@ return strictEquals(left.type, right.type).chain(() => {
276
282
  statements: [
277
283
  `return [{ patterns: [${this.memberTypes
278
284
  .map((memberType) => objectInitializer({
279
- patterns: `${memberType.name}.sparqlWherePatterns({ ignoreRdfType: parameters?.ignoreRdfType, 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()`,
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()`,
280
286
  type: '"group"',
281
287
  }))
282
288
  .join(", ")}], type: "union" }];`,
@@ -363,7 +369,8 @@ return strictEquals(left.type, right.type).chain(() => {
363
369
  return `${this.name}.fromJson(${variables.value}).unsafeCoerce()`;
364
370
  }
365
371
  fromRdfExpression({ variables, }) {
366
- return `${variables.resourceValues}.head().chain(value => value.to${this.rdfjsResourceType().named ? "Named" : ""}Resource()).chain(_resource => ${this.name}.fromRdf({ ...${variables.context}, resource: _resource }))`;
372
+ // 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 }))`;
367
374
  }
368
375
  hashStatements({ variables, }) {
369
376
  switch (this.memberTypes[0].declarationType) {
@@ -383,7 +390,6 @@ return strictEquals(left.type, right.type).chain(() => {
383
390
  case "type":
384
391
  return [
385
392
  `...${this.name}.sparqlConstructTemplateTriples(${objectInitializer({
386
- ignoreRdfType: true,
387
393
  subject: variables.subject,
388
394
  variablePrefix: variables.variablePrefix,
389
395
  })})`,
@@ -397,7 +403,6 @@ return strictEquals(left.type, right.type).chain(() => {
397
403
  case "type":
398
404
  return [
399
405
  `...${this.name}.sparqlWherePatterns(${objectInitializer({
400
- ignoreRdfType: true,
401
406
  subject: variables.subject,
402
407
  variablePrefix: variables.variablePrefix,
403
408
  })})`,
@@ -9,9 +9,10 @@ import { Import } from "./Import.js";
9
9
  import { SnippetDeclarations } from "./SnippetDeclarations.js";
10
10
  import { Type } from "./Type.js";
11
11
  export class OptionType extends Type {
12
+ itemType;
13
+ kind = "OptionType";
12
14
  constructor({ itemType, ...superParameters }) {
13
15
  super(superParameters);
14
- this.kind = "OptionType";
15
16
  this.itemType = itemType;
16
17
  }
17
18
  get conversions() {
@@ -80,7 +81,9 @@ export class OptionType extends Type {
80
81
  return `${this.itemType.jsonZodSchema(parameters)}.optional()`;
81
82
  }
82
83
  snippetDeclarations(features) {
83
- const snippetDeclarations = [];
84
+ const snippetDeclarations = this.itemType
85
+ .snippetDeclarations(features)
86
+ .concat();
84
87
  if (features.has("equals")) {
85
88
  snippetDeclarations.push(SnippetDeclarations.maybeEquals);
86
89
  }
@@ -2,9 +2,11 @@ import { Maybe } from "purify-ts";
2
2
  import { LiteralType } from "./LiteralType.js";
3
3
  import { SnippetDeclarations } from "./SnippetDeclarations.js";
4
4
  export class PrimitiveType extends LiteralType {
5
+ equalsFunction = "strictEquals";
6
+ primitiveDefaultValue;
7
+ primitiveIn;
5
8
  constructor({ primitiveDefaultValue, primitiveIn, ...superParameters }) {
6
9
  super(superParameters);
7
- this.equalsFunction = "strictEquals";
8
10
  this.primitiveDefaultValue = primitiveDefaultValue;
9
11
  this.primitiveIn = primitiveIn;
10
12
  }
@@ -5,8 +5,10 @@ export declare class SetType extends Type {
5
5
  readonly itemType: Type;
6
6
  readonly kind = "SetType";
7
7
  private readonly minCount;
8
- constructor({ itemType, minCount, ...superParameters }: ConstructorParameters<typeof Type>[0] & {
8
+ private readonly _mutable;
9
+ constructor({ itemType, minCount, mutable, ...superParameters }: ConstructorParameters<typeof Type>[0] & {
9
10
  itemType: Type;
11
+ mutable: boolean;
10
12
  minCount: number;
11
13
  });
12
14
  get conversions(): readonly Type.Conversion[];
@@ -10,12 +10,16 @@ import { SnippetDeclarations } from "./SnippetDeclarations.js";
10
10
  import { Type } from "./Type.js";
11
11
  import { objectInitializer } from "./objectInitializer.js";
12
12
  export class SetType extends Type {
13
- constructor({ itemType, minCount, ...superParameters }) {
13
+ itemType;
14
+ kind = "SetType";
15
+ minCount;
16
+ _mutable;
17
+ constructor({ itemType, minCount, mutable, ...superParameters }) {
14
18
  super(superParameters);
15
- this.kind = "SetType";
16
19
  this.itemType = itemType;
17
20
  this.minCount = minCount;
18
21
  invariant(this.minCount >= 0);
22
+ this._mutable = mutable;
19
23
  }
20
24
  get conversions() {
21
25
  const conversions = [];
@@ -44,15 +48,15 @@ export class SetType extends Type {
44
48
  return `((left, right) => arrayEquals(left, right, ${this.itemType.equalsFunction}))`;
45
49
  }
46
50
  get jsonName() {
47
- if (this.minCount === 0) {
48
- return `readonly (${this.itemType.jsonName})[]`;
49
- }
50
- return `purify.NonEmptyList<${this.itemType.jsonName}>`;
51
+ return `readonly (${this.itemType.jsonName})[]`;
51
52
  }
52
53
  get mutable() {
53
- return this.itemType.mutable;
54
+ return this._mutable || this.itemType.mutable;
54
55
  }
55
56
  get name() {
57
+ if (this._mutable) {
58
+ return `(${this.itemType.name})[]`;
59
+ }
56
60
  if (this.minCount === 0) {
57
61
  return `readonly (${this.itemType.name})[]`;
58
62
  }
@@ -60,7 +64,7 @@ export class SetType extends Type {
60
64
  }
61
65
  fromJsonExpression({ variables, }) {
62
66
  let expression = variables.value;
63
- if (this.minCount > 0) {
67
+ if (!this._mutable && this.minCount > 0) {
64
68
  expression = `purify.NonEmptyList.fromArray(${expression}).unsafeCoerce()`;
65
69
  }
66
70
  const itemFromJsonExpression = this.itemType.fromJsonExpression({
@@ -74,7 +78,7 @@ export class SetType extends Type {
74
78
  const itemFromRdfExpression = this.itemType.fromRdfExpression({
75
79
  variables: { ...variables, resourceValues: "_item.toValues()" },
76
80
  });
77
- if (this.minCount === 0) {
81
+ if (this._mutable || this.minCount === 0) {
78
82
  return `purify.Either.of([...${variables.resourceValues}.flatMap(_item => ${itemFromRdfExpression}.toMaybe().toList())])`;
79
83
  }
80
84
  return `purify.NonEmptyList.fromArray([...${variables.resourceValues}.flatMap(_item => ${itemFromRdfExpression}.toMaybe().toList())]).toEither(new rdfjsResource.Resource.ValueError(${objectInitializer({ focusResource: variables.resource, message: `\`\${rdfjsResource.Resource.Identifier.toString(${variables.resource}.identifier)} is empty\``, predicate: variables.predicate })}))`;
@@ -103,7 +107,9 @@ export class SetType extends Type {
103
107
  return schema;
104
108
  }
105
109
  snippetDeclarations(features) {
106
- const snippetDeclarations = [];
110
+ const snippetDeclarations = this.itemType
111
+ .snippetDeclarations(features)
112
+ .concat();
107
113
  if (features.has("equals")) {
108
114
  snippetDeclarations.push(SnippetDeclarations.arrayEquals);
109
115
  }
@@ -8,10 +8,7 @@ import { Memoize } from "typescript-memoize";
8
8
  import { PrimitiveType } from "./PrimitiveType.js";
9
9
  import { objectInitializer } from "./objectInitializer.js";
10
10
  export class StringType extends PrimitiveType {
11
- constructor() {
12
- super(...arguments);
13
- this.kind = "StringType";
14
- }
11
+ kind = "StringType";
15
12
  get conversions() {
16
13
  const conversions = [
17
14
  {
@@ -16,10 +16,14 @@ import { objectInitializer } from "./objectInitializer.js";
16
16
  * Abstract base class for IdentifierType and LiteralType.
17
17
  */
18
18
  export class TermType extends Type {
19
+ defaultValue;
20
+ equalsFunction = "booleanEquals";
21
+ hasValues;
22
+ in_;
23
+ mutable = false;
24
+ nodeKinds;
19
25
  constructor({ defaultValue, hasValues, in_, nodeKinds, ...superParameters }) {
20
26
  super(superParameters);
21
- this.equalsFunction = "booleanEquals";
22
- this.mutable = false;
23
27
  this.defaultValue = defaultValue;
24
28
  this.hasValues = hasValues;
25
29
  this.in_ = in_;
@@ -30,15 +34,15 @@ export class TermType extends Type {
30
34
  const conversions = [];
31
35
  if (this.nodeKinds.has("Literal")) {
32
36
  conversions.push({
33
- conversionExpression: (value) => `rdfLiteral.toRdf(${value})`,
37
+ conversionExpression: (value) => `rdfLiteral.toRdf(${value}, ${objectInitializer({ dataFactory: this.dataFactoryVariable })})`,
34
38
  sourceTypeCheckExpression: (value) => `typeof ${value} === "boolean"`,
35
39
  sourceTypeName: "boolean",
36
40
  }, {
37
- conversionExpression: (value) => `rdfLiteral.toRdf(${value})`,
41
+ conversionExpression: (value) => `rdfLiteral.toRdf(${value}, ${objectInitializer({ dataFactory: this.dataFactoryVariable })})`,
38
42
  sourceTypeCheckExpression: (value) => `typeof ${value} === "object" && ${value} instanceof Date`,
39
43
  sourceTypeName: "Date",
40
44
  }, {
41
- conversionExpression: (value) => `rdfLiteral.toRdf(${value})`,
45
+ conversionExpression: (value) => `rdfLiteral.toRdf(${value}, ${objectInitializer({ dataFactory: this.dataFactoryVariable })})`,
42
46
  sourceTypeCheckExpression: (value) => `typeof ${value} === "number"`,
43
47
  sourceTypeName: "number",
44
48
  }, {
@@ -8,6 +8,7 @@ import { objectInitializer } from "./objectInitializer.js";
8
8
  * Subclasses are used for both property types (c.f., property* methods) and node/object types.
9
9
  */
10
10
  export class Type {
11
+ dataFactoryVariable;
11
12
  constructor({ dataFactoryVariable, }) {
12
13
  this.dataFactoryVariable = dataFactoryVariable;
13
14
  }
@@ -6,6 +6,7 @@ import { fromRdf } from "rdf-literal";
6
6
  import { logger } from "../../logger.js";
7
7
  import { BooleanType } from "./BooleanType.js";
8
8
  import { DateTimeType } from "./DateTimeType.js";
9
+ import { DateType } from "./DateType.js";
9
10
  import { IdentifierType } from "./IdentifierType.js";
10
11
  import { ListType } from "./ListType.js";
11
12
  import { LiteralType } from "./LiteralType.js";
@@ -19,9 +20,10 @@ import { TermType } from "./TermType.js";
19
20
  import { UnionType } from "./UnionType.js";
20
21
  import { tsName } from "./tsName.js";
21
22
  export class TypeFactory {
23
+ cachedObjectTypePropertiesByIdentifier = new TermMap();
24
+ cachedObjectTypesByIdentifier = new TermMap();
25
+ dataFactoryVariable;
22
26
  constructor({ dataFactoryVariable }) {
23
- this.cachedObjectTypePropertiesByIdentifier = new TermMap();
24
- this.cachedObjectTypesByIdentifier = new TermMap();
25
27
  this.dataFactoryVariable = dataFactoryVariable;
26
28
  }
27
29
  createTypeFromAstType(astType) {
@@ -42,7 +44,7 @@ export class TypeFactory {
42
44
  identifierNodeKind: astType.identifierNodeKind,
43
45
  itemType: this.createTypeFromAstType(astType.itemType),
44
46
  mutable: astType.mutable.orDefault(false),
45
- mintingStrategy: astType.mintingStrategy,
47
+ identifierMintingStrategy: astType.identifierMintingStrategy,
46
48
  toRdfTypes: astType.toRdfTypes,
47
49
  });
48
50
  }
@@ -76,8 +78,8 @@ export class TypeFactory {
76
78
  .filter((value) => typeof value === "boolean"),
77
79
  });
78
80
  }
79
- if (datatype.equals(xsd.dateTime)) {
80
- return new DateTimeType({
81
+ if (datatype.equals(xsd.date) || datatype.equals(xsd.dateTime)) {
82
+ return new (datatype.equals(xsd.date) ? DateType : DateTimeType)({
81
83
  dataFactoryVariable: this.dataFactoryVariable,
82
84
  defaultValue: astType.defaultValue,
83
85
  hasValues: astType.hasValues,
@@ -186,6 +188,7 @@ export class TypeFactory {
186
188
  return new SetType({
187
189
  dataFactoryVariable: this.dataFactoryVariable,
188
190
  itemType: this.createTypeFromAstType(astType.itemType),
191
+ mutable: astType.mutable.orDefault(false),
189
192
  minCount: astType.minCount,
190
193
  });
191
194
  case "TermType":
@@ -214,8 +217,8 @@ export class TypeFactory {
214
217
  dataFactoryVariable: this.dataFactoryVariable,
215
218
  defaultValue: Maybe.empty(),
216
219
  hasValues: [],
217
- in_: [],
218
- nodeKinds: astType.nodeKinds,
220
+ in_: astType.identifierIn,
221
+ nodeKinds: astType.identifierKinds,
219
222
  });
220
223
  const objectType = new ObjectType({
221
224
  abstract: astType.abstract,
@@ -253,7 +256,7 @@ export class TypeFactory {
253
256
  abstract: astType.abstract,
254
257
  classDeclarationVisibility: identifierPropertyClassDeclarationVisibility,
255
258
  dataFactoryVariable: this.dataFactoryVariable,
256
- mintingStrategy: astType.mintingStrategy,
259
+ identifierMintingStrategy: astType.identifierMintingStrategy,
257
260
  name: astType.tsIdentifierPropertyName,
258
261
  lazyObjectTypeMutable: () => properties.some((property) => property.mutable || property.type.mutable),
259
262
  objectType: {
@@ -295,7 +298,7 @@ export class TypeFactory {
295
298
  }
296
299
  return properties.sort((left, right) => left.name.localeCompare(right.name));
297
300
  },
298
- mintingStrategy: astType.mintingStrategy,
301
+ identifierMintingStrategy: astType.identifierMintingStrategy,
299
302
  name: tsName(astType.name),
300
303
  toRdfTypes: astType.toRdfTypes,
301
304
  });
@@ -10,13 +10,15 @@ import { Memoize } from "typescript-memoize";
10
10
  import { Type } from "./Type.js";
11
11
  import { objectInitializer } from "./objectInitializer.js";
12
12
  export class UnionType extends Type {
13
+ kind = "UnionType";
14
+ memberTypes;
13
15
  constructor({ memberTypes, name, ...superParameters }) {
14
16
  super(superParameters);
15
- this.kind = "UnionType";
16
17
  invariant(memberTypes.length >= 2);
17
18
  this.memberTypes = memberTypes;
18
19
  this._name = name;
19
20
  }
21
+ _name;
20
22
  get name() {
21
23
  if (typeof this._name === "undefined") {
22
24
  switch (this._discriminatorProperty.kind) {
@@ -1,6 +1,6 @@
1
1
  import { Maybe } from "purify-ts";
2
2
  import type { GetAccessorDeclarationStructure, OptionalKind, PropertyDeclarationStructure, PropertySignatureStructure } from "ts-morph";
3
- import type { MintingStrategy, PropertyVisibility } from "../../../enums/index.js";
3
+ import type { IdentifierMintingStrategy, PropertyVisibility } from "../../../enums/index.js";
4
4
  import type { IdentifierType } from "../IdentifierType.js";
5
5
  import { Import } from "../Import.js";
6
6
  import { Property } from "./Property.js";
@@ -9,14 +9,14 @@ export declare class IdentifierProperty extends Property<IdentifierType> {
9
9
  readonly equalsFunction = "booleanEquals";
10
10
  readonly mutable = false;
11
11
  private readonly classDeclarationVisibility;
12
+ private readonly identifierMintingStrategy;
12
13
  private readonly lazyObjectTypeMutable;
13
- private readonly mintingStrategy;
14
14
  private readonly override;
15
- constructor({ abstract, classDeclarationVisibility, lazyObjectTypeMutable, mintingStrategy, override, ...superParameters }: {
15
+ constructor({ abstract, classDeclarationVisibility, lazyObjectTypeMutable, identifierMintingStrategy, override, ...superParameters }: {
16
16
  abstract: boolean;
17
17
  classDeclarationVisibility: Maybe<PropertyVisibility>;
18
18
  lazyObjectTypeMutable: () => boolean;
19
- mintingStrategy: Maybe<MintingStrategy>;
19
+ identifierMintingStrategy: Maybe<IdentifierMintingStrategy>;
20
20
  override: boolean;
21
21
  type: IdentifierType;
22
22
  } & ConstructorParameters<typeof Property>[0]);
@@ -30,7 +30,7 @@ export declare class IdentifierProperty extends Property<IdentifierType> {
30
30
  classConstructorStatements({ variables, }: Parameters<Property<IdentifierType>["classConstructorStatements"]>[0]): readonly string[];
31
31
  fromJsonStatements({ variables, }: Parameters<Property<IdentifierType>["fromJsonStatements"]>[0]): readonly string[];
32
32
  fromRdfStatements({ variables, }: Parameters<Property<IdentifierType>["fromRdfStatements"]>[0]): readonly string[];
33
- hashStatements(): readonly string[];
33
+ hashStatements({ variables, }: Parameters<Property<IdentifierType>["hashStatements"]>[0]): readonly string[];
34
34
  interfaceConstructorStatements({ variables, }: Parameters<Property<IdentifierType>["interfaceConstructorStatements"]>[0]): readonly string[];
35
35
  jsonUiSchemaElement({ variables, }: Parameters<Property<IdentifierType>["jsonUiSchemaElement"]>[0]): Maybe<string>;
36
36
  jsonZodSchema({ variables, }: Parameters<Property<IdentifierType>["jsonZodSchema"]>[0]): ReturnType<Property<IdentifierType>["jsonZodSchema"]>;
@@ -1,24 +1,30 @@
1
+ import { rdf } from "@tpluscode/rdf-ns-builders";
1
2
  import { Maybe } from "purify-ts";
2
3
  import { invariant } from "ts-invariant";
3
4
  import { Import } from "../Import.js";
4
5
  import { SnippetDeclarations } from "../SnippetDeclarations.js";
5
6
  import { Property } from "./Property.js";
6
7
  export class IdentifierProperty extends Property {
7
- constructor({ abstract, classDeclarationVisibility, lazyObjectTypeMutable, mintingStrategy, override, ...superParameters }) {
8
+ abstract;
9
+ equalsFunction = "booleanEquals";
10
+ mutable = false;
11
+ classDeclarationVisibility;
12
+ identifierMintingStrategy;
13
+ lazyObjectTypeMutable;
14
+ override;
15
+ constructor({ abstract, classDeclarationVisibility, lazyObjectTypeMutable, identifierMintingStrategy, override, ...superParameters }) {
8
16
  super(superParameters);
9
- this.equalsFunction = "booleanEquals";
10
- this.mutable = false;
11
17
  invariant(this.visibility === "public");
12
18
  this.abstract = abstract;
13
19
  this.classDeclarationVisibility = classDeclarationVisibility;
14
- if (mintingStrategy.isJust()) {
15
- this.mintingStrategy = mintingStrategy.unsafeCoerce();
20
+ if (identifierMintingStrategy.isJust()) {
21
+ this.identifierMintingStrategy = identifierMintingStrategy.unsafeCoerce();
16
22
  }
17
23
  else if (this.type.nodeKinds.has("BlankNode")) {
18
- this.mintingStrategy = "blankNode";
24
+ this.identifierMintingStrategy = "blankNode";
19
25
  }
20
26
  else {
21
- this.mintingStrategy = "none";
27
+ this.identifierMintingStrategy = "none";
22
28
  }
23
29
  this.lazyObjectTypeMutable = lazyObjectTypeMutable;
24
30
  this.override = override;
@@ -28,7 +34,7 @@ export class IdentifierProperty extends Property {
28
34
  return Maybe.empty();
29
35
  }
30
36
  let mintIdentifier;
31
- switch (this.mintingStrategy) {
37
+ switch (this.identifierMintingStrategy) {
32
38
  case "blankNode":
33
39
  mintIdentifier = "dataFactory.blankNode()";
34
40
  break;
@@ -72,7 +78,7 @@ export class IdentifierProperty extends Property {
72
78
  if (!this.classDeclarationVisibility.isJust()) {
73
79
  return Maybe.empty();
74
80
  }
75
- switch (this.mintingStrategy) {
81
+ switch (this.identifierMintingStrategy) {
76
82
  case "none":
77
83
  // Immutable, public identifier property, no getter
78
84
  return Maybe.of({
@@ -95,19 +101,25 @@ export class IdentifierProperty extends Property {
95
101
  if (this.objectType.declarationType === "class" && this.abstract) {
96
102
  return Maybe.empty();
97
103
  }
104
+ const typeNames = new Set(); // Remove duplicates with a set
105
+ for (const conversion of this.type.conversions) {
106
+ if (conversion.sourceTypeName !== "undefined") {
107
+ typeNames.add(conversion.sourceTypeName);
108
+ }
109
+ }
98
110
  return Maybe.of({
99
111
  hasQuestionToken: this.objectType.declarationType === "class" &&
100
- this.mintingStrategy !== "none",
112
+ this.identifierMintingStrategy !== "none",
101
113
  isReadonly: true,
102
114
  name: this.name,
103
- type: this.type.name,
115
+ type: [...typeNames].sort().join(" | "),
104
116
  });
105
117
  }
106
118
  get declarationImports() {
107
119
  const imports = this.type.useImports().concat();
108
120
  if (this.objectType.features.has("hash") &&
109
121
  this.objectType.declarationType === "class") {
110
- switch (this.mintingStrategy) {
122
+ switch (this.identifierMintingStrategy) {
111
123
  case "sha256":
112
124
  imports.push(Import.SHA256);
113
125
  break;
@@ -143,11 +155,27 @@ export class IdentifierProperty extends Property {
143
155
  if (this.abstract) {
144
156
  return [];
145
157
  }
146
- return this.classPropertyDeclaration
147
- .map((classPropertyDeclaration) => [
148
- `this.${classPropertyDeclaration.name} = ${variables.parameter};`,
149
- ])
150
- .orDefault([]);
158
+ if (this.classPropertyDeclaration.isNothing()) {
159
+ return [];
160
+ }
161
+ const classPropertyDeclaration = this.classPropertyDeclaration.unsafeCoerce();
162
+ const typeConversions = this.type.conversions;
163
+ if (typeConversions.length === 1) {
164
+ return [
165
+ `this.${classPropertyDeclaration.name} = ${variables.parameter};`,
166
+ ];
167
+ }
168
+ const statements = [];
169
+ for (const conversion of this.type.conversions) {
170
+ invariant(conversion.sourceTypeName !== "undefined");
171
+ statements.push(`if (${conversion.sourceTypeCheckExpression(variables.parameter)}) { this.${classPropertyDeclaration.name} = ${conversion.conversionExpression(variables.parameter)}; }`);
172
+ }
173
+ if (classPropertyDeclaration.name.startsWith("_")) {
174
+ statements.push(`if (typeof ${variables.parameter} === "undefined") { }`);
175
+ }
176
+ // We shouldn't need this else, since the parameter now has the never type, but have to add it to appease the TypeScript compiler
177
+ statements.push(`{ this.${classPropertyDeclaration.name} =( ${variables.parameter}) as never;\n }`);
178
+ return [statements.join(" else ")];
151
179
  }
152
180
  fromJsonStatements({ variables, }) {
153
181
  return [
@@ -155,21 +183,63 @@ export class IdentifierProperty extends Property {
155
183
  ];
156
184
  }
157
185
  fromRdfStatements({ variables, }) {
186
+ if (this.type.in_.length > 0 && this.type.isNamedNodeKind) {
187
+ // Treat sh:in as a union of the IRIs
188
+ // rdfjs.NamedNode<"http://example.com/1" | "http://example.com/2">
189
+ return [
190
+ `let ${this.name}: ${this.type.name};`,
191
+ `switch (${variables.resource}.identifier.value) { ${this.type.in_.map((iri) => `case "${iri.value}": ${this.name} = ${this.rdfjsTermExpression(iri)}; break;`).join(" ")} default: return purify.Left(new rdfjsResource.Resource.MistypedValueError({ actualValue: ${variables.resource}.identifier, expectedValueType: ${JSON.stringify(this.type.name)}, focusResource: ${variables.resource}, predicate: ${this.rdfjsTermExpression(rdf.subject)} })); }`,
192
+ ];
193
+ }
158
194
  return [`const ${this.name} = ${variables.resource}.identifier`];
159
195
  }
160
- hashStatements() {
161
- return [];
196
+ hashStatements({ variables, }) {
197
+ if (this.abstract) {
198
+ // Identifier will only be hashed by a concrete class.
199
+ return [];
200
+ }
201
+ switch (this.identifierMintingStrategy) {
202
+ case "blankNode":
203
+ case "none":
204
+ case "uuidv4":
205
+ // The identifier minting won't call hash, so we should hash the identifier.
206
+ return [`${variables.hasher}.update(${variables.value}.value);`];
207
+ case "sha256":
208
+ // The identifier minting will call hash, so we can't hash the identifier.
209
+ return [];
210
+ }
162
211
  }
163
212
  interfaceConstructorStatements({ variables, }) {
164
- return [`const ${this.name} = ${variables.parameter}`];
213
+ const typeConversions = this.type.conversions;
214
+ if (typeConversions.length === 1) {
215
+ return [`const ${this.name} = ${variables.parameter};`];
216
+ }
217
+ const statements = [`let ${this.name}: ${this.type.name};`];
218
+ const conversionBranches = [];
219
+ for (const conversion of this.type.conversions) {
220
+ conversionBranches.push(`if (${conversion.sourceTypeCheckExpression(variables.parameter)}) { ${this.name} = ${conversion.conversionExpression(variables.parameter)}; }`);
221
+ }
222
+ // We shouldn't need this else, since the parameter now has the never type, but have to add it to appease the TypeScript compiler
223
+ conversionBranches.push(`{ ${this.name} =( ${variables.parameter}) as never;\n }`);
224
+ statements.push(conversionBranches.join(" else "));
225
+ return statements;
165
226
  }
166
227
  jsonUiSchemaElement({ variables, }) {
167
228
  return Maybe.of(`{ label: "Identifier", scope: \`\${${variables.scopePrefix}}/properties/${this.jsonPropertySignature.name}\`, type: "Control" }`);
168
229
  }
169
230
  jsonZodSchema({ variables, }) {
231
+ let schema;
232
+ if (this.type.in_.length > 0 && this.type.isNamedNodeKind) {
233
+ // Treat sh:in as a union of the IRIs
234
+ // rdfjs.NamedNode<"http://example.com/1" | "http://example.com/2">
235
+ schema = `${variables.zod}.enum(${JSON.stringify(this.type.in_.map((iri) => iri.value))})`;
236
+ }
237
+ else {
238
+ schema = `${variables.zod}.string().min(1)`;
239
+ }
170
240
  return {
171
241
  key: this.jsonPropertySignature.name,
172
- schema: `${variables.zod}.string().min(1)`,
242
+ schema,
173
243
  };
174
244
  }
175
245
  sparqlConstructTemplateTriples() {
@@ -1,6 +1,20 @@
1
1
  import { Scope, } from "ts-morph";
2
2
  import { rdfjsTermExpression } from "./rdfjsTermExpression.js";
3
3
  export class Property {
4
+ /**
5
+ * TypeScript identifier-safe name of the property.
6
+ */
7
+ name;
8
+ /**
9
+ * Property type
10
+ . */
11
+ type;
12
+ /**
13
+ * Property visibility: private, protected, public.
14
+ */
15
+ visibility;
16
+ dataFactoryVariable;
17
+ objectType;
4
18
  constructor({ dataFactoryVariable, name, objectType, type, visibility, }) {
5
19
  this.dataFactoryVariable = dataFactoryVariable;
6
20
  this.name = name;