@shaclmate/compiler 2.0.22 → 2.0.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (194) hide show
  1. package/dist/ShapesGraphToAstTransformer.d.ts +6 -5
  2. package/dist/ShapesGraphToAstTransformer.js +61 -17
  3. package/dist/_ShapesGraphToAstTransformer/InheritableShapeConstraints.d.ts +2 -0
  4. package/dist/_ShapesGraphToAstTransformer/InheritableShapeConstraints.js +2 -0
  5. package/dist/_ShapesGraphToAstTransformer/ShapeStack.d.ts +15 -0
  6. package/dist/_ShapesGraphToAstTransformer/ShapeStack.js +51 -0
  7. package/dist/_ShapesGraphToAstTransformer/flattenAstObjectCompositeTypeMemberTypes.d.ts +13 -0
  8. package/dist/_ShapesGraphToAstTransformer/flattenAstObjectCompositeTypeMemberTypes.js +51 -0
  9. package/dist/_ShapesGraphToAstTransformer/index.d.ts +5 -5
  10. package/dist/_ShapesGraphToAstTransformer/index.js +5 -5
  11. package/dist/_ShapesGraphToAstTransformer/shapeAstName.js +53 -12
  12. package/dist/_ShapesGraphToAstTransformer/transformNodeShapeToAstType.d.ts +5 -0
  13. package/dist/_ShapesGraphToAstTransformer/transformNodeShapeToAstType.js +130 -54
  14. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstObjectTypeProperty.js +175 -5
  15. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstCompositeType.d.ts +10 -0
  16. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstCompositeType.js +185 -0
  17. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstIdentifierType.d.ts +10 -0
  18. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstIdentifierType.js +32 -0
  19. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstLiteralType.d.ts +10 -0
  20. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstLiteralType.js +46 -0
  21. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstTermType.d.ts +12 -0
  22. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstTermType.js +24 -0
  23. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstType.d.ts +13 -0
  24. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstType.js +14 -0
  25. package/dist/ast/Ast.d.ts +0 -1
  26. package/dist/ast/Curie.d.ts +14 -0
  27. package/dist/ast/Curie.js +21 -0
  28. package/dist/ast/IdentifierType.d.ts +3 -2
  29. package/dist/ast/ListType.d.ts +2 -1
  30. package/dist/ast/LiteralType.d.ts +1 -1
  31. package/dist/ast/Name.d.ts +40 -5
  32. package/dist/ast/ObjectCompositeType.d.ts +11 -0
  33. package/dist/ast/ObjectType.d.ts +18 -13
  34. package/dist/ast/ObjectUnionType.d.ts +0 -11
  35. package/dist/ast/OptionType.d.ts +2 -4
  36. package/dist/ast/SetType.d.ts +2 -7
  37. package/dist/ast/TermType.d.ts +12 -4
  38. package/dist/ast/Type.d.ts +1 -1
  39. package/dist/ast/index.d.ts +1 -0
  40. package/dist/ast/index.js +1 -0
  41. package/dist/enums/TsFeature.d.ts +1 -4
  42. package/dist/enums/TsFeature.js +1 -15
  43. package/dist/generators/json/AstJsonGenerator.js +26 -4
  44. package/dist/generators/ts/BooleanType.d.ts +4 -2
  45. package/dist/generators/ts/BooleanType.js +12 -3
  46. package/dist/generators/ts/DateTimeType.d.ts +9 -8
  47. package/dist/generators/ts/DateTimeType.js +32 -8
  48. package/dist/generators/ts/DateType.d.ts +5 -2
  49. package/dist/generators/ts/DateType.js +15 -1
  50. package/dist/generators/ts/DeclaredType.d.ts +2 -2
  51. package/dist/generators/ts/DeclaredType.js +2 -2
  52. package/dist/generators/ts/FloatType.d.ts +6 -0
  53. package/dist/generators/ts/FloatType.js +18 -0
  54. package/dist/generators/ts/IdentifierType.d.ts +17 -7
  55. package/dist/generators/ts/IdentifierType.js +112 -18
  56. package/dist/generators/ts/Import.d.ts +2 -0
  57. package/dist/generators/ts/Import.js +10 -0
  58. package/dist/generators/ts/IntType.d.ts +6 -0
  59. package/dist/generators/ts/IntType.js +18 -0
  60. package/dist/generators/ts/ListType.d.ts +15 -12
  61. package/dist/generators/ts/ListType.js +113 -61
  62. package/dist/generators/ts/LiteralType.d.ts +17 -9
  63. package/dist/generators/ts/LiteralType.js +92 -17
  64. package/dist/generators/ts/NumberType.d.ts +3 -2
  65. package/dist/generators/ts/NumberType.js +8 -3
  66. package/dist/generators/ts/ObjectType.d.ts +65 -43
  67. package/dist/generators/ts/ObjectType.js +143 -123
  68. package/dist/generators/ts/ObjectUnionType.d.ts +50 -8
  69. package/dist/generators/ts/ObjectUnionType.js +303 -101
  70. package/dist/generators/ts/OptionType.d.ts +14 -10
  71. package/dist/generators/ts/OptionType.js +62 -34
  72. package/dist/generators/ts/PrimitiveType.d.ts +23 -5
  73. package/dist/generators/ts/PrimitiveType.js +34 -6
  74. package/dist/generators/ts/SetType.d.ts +17 -13
  75. package/dist/generators/ts/SetType.js +76 -44
  76. package/dist/generators/ts/SnippetDeclarations.d.ts +13 -8
  77. package/dist/generators/ts/SnippetDeclarations.js +226 -101
  78. package/dist/generators/ts/StringType.d.ts +4 -2
  79. package/dist/generators/ts/StringType.js +20 -8
  80. package/dist/generators/ts/TermType.d.ts +29 -33
  81. package/dist/generators/ts/TermType.js +89 -68
  82. package/dist/generators/ts/TsGenerator.d.ts +2 -1
  83. package/dist/generators/ts/TsGenerator.js +26 -12
  84. package/dist/generators/ts/Type.d.ts +100 -32
  85. package/dist/generators/ts/Type.js +58 -54
  86. package/dist/generators/ts/TypeFactory.d.ts +12 -5
  87. package/dist/generators/ts/TypeFactory.js +380 -226
  88. package/dist/generators/ts/UnionType.d.ts +14 -10
  89. package/dist/generators/ts/UnionType.js +319 -142
  90. package/dist/generators/ts/_ObjectType/EagerShaclProperty.d.ts +12 -0
  91. package/dist/generators/ts/_ObjectType/EagerShaclProperty.js +31 -0
  92. package/dist/generators/ts/_ObjectType/IdentifierPrefixProperty.d.ts +13 -12
  93. package/dist/generators/ts/_ObjectType/IdentifierPrefixProperty.js +59 -46
  94. package/dist/generators/ts/_ObjectType/IdentifierProperty.d.ts +20 -13
  95. package/dist/generators/ts/_ObjectType/IdentifierProperty.js +198 -140
  96. package/dist/generators/ts/_ObjectType/LazyShaclProperty.d.ts +100 -0
  97. package/dist/generators/ts/_ObjectType/LazyShaclProperty.js +315 -0
  98. package/dist/generators/ts/_ObjectType/Property.d.ts +47 -46
  99. package/dist/generators/ts/_ObjectType/Property.js +1 -10
  100. package/dist/generators/ts/_ObjectType/ShaclProperty.d.ts +25 -30
  101. package/dist/generators/ts/_ObjectType/ShaclProperty.js +120 -85
  102. package/dist/generators/ts/_ObjectType/TypeDiscriminatorProperty.d.ts +21 -17
  103. package/dist/generators/ts/_ObjectType/TypeDiscriminatorProperty.js +61 -53
  104. package/dist/generators/ts/_ObjectType/classDeclaration.js +22 -17
  105. package/dist/generators/ts/_ObjectType/createFunctionDeclaration.js +26 -13
  106. package/dist/generators/ts/_ObjectType/equalsFunctionOrMethodDeclaration.js +8 -5
  107. package/dist/generators/ts/_ObjectType/fromRdfTypeVariableStatement.d.ts +1 -1
  108. package/dist/generators/ts/_ObjectType/fromRdfTypeVariableStatement.js +8 -5
  109. package/dist/generators/ts/_ObjectType/graphqlTypeVariableStatement.d.ts +5 -0
  110. package/dist/generators/ts/_ObjectType/graphqlTypeVariableStatement.js +49 -0
  111. package/dist/generators/ts/_ObjectType/hashFunctionOrMethodDeclarations.js +7 -8
  112. package/dist/generators/ts/_ObjectType/identifierTypeDeclarations.d.ts +7 -0
  113. package/dist/generators/ts/_ObjectType/identifierTypeDeclarations.js +54 -0
  114. package/dist/generators/ts/_ObjectType/index.d.ts +9 -7
  115. package/dist/generators/ts/_ObjectType/index.js +9 -7
  116. package/dist/generators/ts/_ObjectType/interfaceDeclaration.js +1 -1
  117. package/dist/generators/ts/_ObjectType/jsonFunctionDeclarations.d.ts +4 -0
  118. package/dist/generators/ts/_ObjectType/jsonFunctionDeclarations.js +189 -0
  119. package/dist/generators/ts/_ObjectType/jsonTypeAliasDeclaration.d.ts +5 -0
  120. package/dist/generators/ts/_ObjectType/jsonTypeAliasDeclaration.js +28 -0
  121. package/dist/generators/ts/_ObjectType/objectSetMethodNames.d.ts +9 -0
  122. package/dist/generators/ts/_ObjectType/objectSetMethodNames.js +18 -0
  123. package/dist/generators/ts/_ObjectType/propertiesVariableStatement.d.ts +5 -0
  124. package/dist/generators/ts/_ObjectType/propertiesVariableStatement.js +37 -0
  125. package/dist/generators/ts/_ObjectType/rdfFunctionDeclarations.d.ts +4 -0
  126. package/dist/generators/ts/_ObjectType/rdfFunctionDeclarations.js +144 -0
  127. package/dist/generators/ts/_ObjectType/sparqlConstructQueryFunctionDeclaration.d.ts +1 -1
  128. package/dist/generators/ts/_ObjectType/sparqlConstructQueryFunctionDeclaration.js +6 -5
  129. package/dist/generators/ts/_ObjectType/sparqlConstructQueryStringFunctionDeclaration.d.ts +1 -1
  130. package/dist/generators/ts/_ObjectType/sparqlConstructQueryStringFunctionDeclaration.js +4 -3
  131. package/dist/generators/ts/_ObjectType/sparqlFunctionDeclarations.js +109 -37
  132. package/dist/generators/ts/_ObjectType/toJsonFunctionOrMethodDeclaration.js +6 -6
  133. package/dist/generators/ts/_ObjectType/toRdfFunctionOrMethodDeclaration.js +33 -24
  134. package/dist/generators/ts/graphqlSchemaVariableStatement.d.ts +9 -0
  135. package/dist/generators/ts/graphqlSchemaVariableStatement.js +86 -0
  136. package/dist/generators/ts/objectSetDeclarations.d.ts +8 -0
  137. package/dist/generators/ts/objectSetDeclarations.js +59 -0
  138. package/dist/generators/ts/objectSetInterfaceDeclaration.d.ts +8 -0
  139. package/dist/generators/ts/objectSetInterfaceDeclaration.js +46 -0
  140. package/dist/generators/ts/objectSetMethodSignatures.d.ts +11 -0
  141. package/dist/generators/ts/objectSetMethodSignatures.js +52 -0
  142. package/dist/generators/ts/rdfjsDatasetObjectSetClassDeclaration.d.ts +8 -0
  143. package/dist/generators/ts/rdfjsDatasetObjectSetClassDeclaration.js +393 -0
  144. package/dist/generators/ts/rdfjsTermExpression.d.ts +3 -0
  145. package/dist/generators/ts/rdfjsTermExpression.js +57 -0
  146. package/dist/generators/ts/sparqlObjectSetClassDeclaration.d.ts +8 -0
  147. package/dist/generators/ts/sparqlObjectSetClassDeclaration.js +415 -0
  148. package/dist/generators/ts/syntheticNamePrefix.d.ts +2 -0
  149. package/dist/generators/ts/syntheticNamePrefix.js +2 -0
  150. package/dist/generators/ts/tsName.js +27 -13
  151. package/dist/generators/ts/unsupportedObjectSetMethodDeclarations.d.ts +10 -0
  152. package/dist/generators/ts/unsupportedObjectSetMethodDeclarations.js +19 -0
  153. package/dist/input/NodeShape.d.ts +6 -8
  154. package/dist/input/NodeShape.js +20 -44
  155. package/dist/input/Ontology.d.ts +0 -3
  156. package/dist/input/Ontology.js +0 -9
  157. package/dist/input/PropertyPath.d.ts +5 -5
  158. package/dist/input/PropertyPath.js +14 -24
  159. package/dist/input/PropertyShape.d.ts +3 -1
  160. package/dist/input/PropertyShape.js +8 -2
  161. package/dist/input/ShapesGraph.js +4 -8
  162. package/dist/input/generated.d.ts +967 -107
  163. package/dist/input/generated.js +2548 -1046
  164. package/dist/input/tsFeatures.d.ts +3 -2
  165. package/dist/input/tsFeatures.js +44 -27
  166. package/package.json +18 -16
  167. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstCompositeType.d.ts +0 -13
  168. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstCompositeType.js +0 -200
  169. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstIdentifierType.d.ts +0 -12
  170. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstIdentifierType.js +0 -29
  171. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstLiteralType.d.ts +0 -12
  172. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstLiteralType.js +0 -43
  173. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstTermType.d.ts +0 -14
  174. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstTermType.js +0 -21
  175. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstType.d.ts +0 -16
  176. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstType.js +0 -60
  177. package/dist/generators/ts/_ObjectType/fromJsonFunctionDeclarations.d.ts +0 -4
  178. package/dist/generators/ts/_ObjectType/fromJsonFunctionDeclarations.js +0 -78
  179. package/dist/generators/ts/_ObjectType/fromRdfFunctionDeclarations.d.ts +0 -4
  180. package/dist/generators/ts/_ObjectType/fromRdfFunctionDeclarations.js +0 -91
  181. package/dist/generators/ts/_ObjectType/jsonSchemaFunctionDeclaration.d.ts +0 -5
  182. package/dist/generators/ts/_ObjectType/jsonSchemaFunctionDeclaration.js +0 -19
  183. package/dist/generators/ts/_ObjectType/jsonUiSchemaFunctionDeclaration.d.ts +0 -5
  184. package/dist/generators/ts/_ObjectType/jsonUiSchemaFunctionDeclaration.js +0 -31
  185. package/dist/generators/ts/_ObjectType/jsonZodSchemaFunctionDeclaration.d.ts +0 -5
  186. package/dist/generators/ts/_ObjectType/jsonZodSchemaFunctionDeclaration.js +0 -37
  187. package/dist/generators/ts/_ObjectType/rdfjsTermExpression.d.ts +0 -6
  188. package/dist/generators/ts/_ObjectType/rdfjsTermExpression.js +0 -17
  189. package/dist/generators/ts/_ObjectType/toJsonFunctionDeclaration.d.ts +0 -5
  190. package/dist/generators/ts/_ObjectType/toJsonFunctionDeclaration.js +0 -19
  191. package/dist/generators/ts/_ObjectType/toJsonReturnType.d.ts +0 -3
  192. package/dist/generators/ts/_ObjectType/toJsonReturnType.js +0 -17
  193. package/dist/generators/ts/_ObjectType/toRdfFunctionDeclaration.d.ts +0 -5
  194. package/dist/generators/ts/_ObjectType/toRdfFunctionDeclaration.js +0 -19
@@ -1,94 +1,33 @@
1
1
  import { rdf } from "@tpluscode/rdf-ns-builders";
2
2
  import { Maybe } from "purify-ts";
3
3
  import { invariant } from "ts-invariant";
4
+ import { logger } from "../../../logger.js";
4
5
  import { Import } from "../Import.js";
5
6
  import { SnippetDeclarations } from "../SnippetDeclarations.js";
7
+ import { rdfjsTermExpression } from "../rdfjsTermExpression.js";
8
+ import { syntheticNamePrefix } from "../syntheticNamePrefix.js";
6
9
  import { Property } from "./Property.js";
7
10
  export class IdentifierProperty extends Property {
8
- abstract;
9
- equalsFunction = "booleanEquals";
10
- mutable = false;
11
- classDeclarationVisibility;
11
+ getAccessorScope;
12
12
  identifierMintingStrategy;
13
+ identifierPrefixPropertyName;
13
14
  override;
14
- constructor({ abstract, classDeclarationVisibility, identifierMintingStrategy, override, ...superParameters }) {
15
+ propertyDeclarationVisibility;
16
+ typeAlias;
17
+ abstract;
18
+ equalsFunction = Maybe.of(`${syntheticNamePrefix}booleanEquals`);
19
+ mutable = false;
20
+ recursive = false;
21
+ constructor({ abstract, getAccessorScope, identifierMintingStrategy, identifierPrefixPropertyName, override, propertyDeclarationVisibility, typeAlias, ...superParameters }) {
15
22
  super(superParameters);
16
23
  invariant(this.visibility === "public");
17
24
  this.abstract = abstract;
18
- this.classDeclarationVisibility = classDeclarationVisibility;
25
+ this.getAccessorScope = getAccessorScope;
26
+ this.propertyDeclarationVisibility = propertyDeclarationVisibility;
19
27
  this.identifierMintingStrategy = identifierMintingStrategy;
28
+ this.identifierPrefixPropertyName = identifierPrefixPropertyName;
20
29
  this.override = override;
21
- }
22
- get classGetAccessorDeclaration() {
23
- if (this.abstract) {
24
- return Maybe.empty();
25
- }
26
- if (this.identifierMintingStrategy.isNothing()) {
27
- return Maybe.empty();
28
- }
29
- let memoizeMintedIdentifier;
30
- let mintIdentifier;
31
- switch (this.identifierMintingStrategy.unsafeCoerce()) {
32
- case "blankNode":
33
- memoizeMintedIdentifier = true;
34
- mintIdentifier = "dataFactory.blankNode()";
35
- break;
36
- case "sha256":
37
- // If the object is mutable don't memoize the minted identifier, since the hash will change if the object mutates.
38
- memoizeMintedIdentifier = !this.objectType.mutable();
39
- mintIdentifier =
40
- "dataFactory.namedNode(`${this.identifierPrefix}${this.hashShaclProperties(sha256.create())}`)";
41
- break;
42
- case "uuidv4":
43
- memoizeMintedIdentifier = true;
44
- mintIdentifier =
45
- "dataFactory.namedNode(`${this.identifierPrefix}${uuid.v4()}`)";
46
- break;
47
- }
48
- return Maybe.of({
49
- leadingTrivia: this.override ? "override " : undefined,
50
- name: this.name,
51
- returnType: this.type.name,
52
- statements: [
53
- memoizeMintedIdentifier
54
- ? `if (typeof this._${this.name} === "undefined") { this._${this.name} = ${mintIdentifier}; } return this._${this.name};`
55
- : `return (typeof this._${this.name} !== "undefined") ? this._${this.name} : ${mintIdentifier}`,
56
- ],
57
- });
58
- }
59
- get classPropertyDeclaration() {
60
- if (this.abstract) {
61
- // Abstract version of the accessor
62
- // Work around a ts-morph bug that puts the override keyword before the abstract keyword
63
- return Maybe.of({
64
- hasOverrideKeyword: this.abstract && this.override ? undefined : this.override,
65
- isAbstract: this.abstract && this.override ? undefined : this.abstract,
66
- isReadonly: true,
67
- leadingTrivia: this.abstract && this.override ? "abstract override " : undefined,
68
- name: this.name,
69
- type: this.type.name,
70
- });
71
- }
72
- // See note in TypeFactory re: the logic of whether to declare the identifier in the class or not.
73
- if (!this.classDeclarationVisibility.isJust()) {
74
- return Maybe.empty();
75
- }
76
- if (this.identifierMintingStrategy.isJust()) {
77
- // Mutable _identifier property that will be lazily initialized by the getter to mint the identifier
78
- return Maybe.of({
79
- name: `_${this.name}`,
80
- scope: this.classDeclarationVisibility
81
- .map(Property.visibilityToScope)
82
- .unsafeCoerce(),
83
- type: `${this.type.name} | undefined`,
84
- });
85
- }
86
- // Immutable, public identifier property, no getter
87
- return Maybe.of({
88
- isReadonly: true,
89
- name: this.name,
90
- type: this.type.name,
91
- });
30
+ this.typeAlias = typeAlias;
92
31
  }
93
32
  get constructorParametersPropertySignature() {
94
33
  if (this.objectType.declarationType === "class" && this.abstract) {
@@ -100,9 +39,21 @@ export class IdentifierProperty extends Property {
100
39
  typeNames.add(conversion.sourceTypeName);
101
40
  }
102
41
  }
42
+ let hasQuestionToken;
43
+ switch (this.objectType.declarationType) {
44
+ case "class":
45
+ hasQuestionToken = this.identifierMintingStrategy.isJust();
46
+ break;
47
+ case "interface": {
48
+ const identifierMintingStrategy = this.identifierMintingStrategy.extract();
49
+ hasQuestionToken =
50
+ typeof identifierMintingStrategy !== "undefined" &&
51
+ identifierMintingStrategy !== "sha256";
52
+ break;
53
+ }
54
+ }
103
55
  return Maybe.of({
104
- hasQuestionToken: this.objectType.declarationType === "class" &&
105
- this.identifierMintingStrategy.isJust(),
56
+ hasQuestionToken,
106
57
  isReadonly: true,
107
58
  name: this.name,
108
59
  type: [...typeNames].sort().join(" | "),
@@ -110,26 +61,68 @@ export class IdentifierProperty extends Property {
110
61
  }
111
62
  get declarationImports() {
112
63
  const imports = this.type.useImports().concat();
113
- if (this.objectType.features.has("hash") &&
114
- this.objectType.declarationType === "class") {
115
- this.identifierMintingStrategy.ifJust((identifierMintingStrategy) => {
116
- switch (identifierMintingStrategy) {
117
- case "sha256":
118
- imports.push(Import.SHA256);
119
- break;
120
- case "uuidv4":
121
- imports.push(Import.UUID);
122
- break;
123
- }
124
- });
125
- }
64
+ this.identifierMintingStrategy.ifJust((identifierMintingStrategy) => {
65
+ switch (identifierMintingStrategy) {
66
+ case "sha256":
67
+ imports.push(Import.SHA256);
68
+ break;
69
+ case "uuidv4":
70
+ imports.push(Import.UUID);
71
+ break;
72
+ }
73
+ });
126
74
  return imports;
127
75
  }
128
- get interfacePropertySignature() {
76
+ get getAccessorDeclaration() {
77
+ if (this.getAccessorScope.isNothing()) {
78
+ return Maybe.empty();
79
+ }
80
+ invariant(this.getAccessorScope.unsafeCoerce() === "public");
81
+ if (this.identifierMintingStrategy.isJust()) {
82
+ let memoizeMintedIdentifier;
83
+ let mintIdentifier;
84
+ switch (this.identifierMintingStrategy.unsafeCoerce()) {
85
+ case "blankNode":
86
+ memoizeMintedIdentifier = true;
87
+ mintIdentifier = "dataFactory.blankNode()";
88
+ break;
89
+ case "sha256":
90
+ // If the object is mutable don't memoize the minted identifier, since the hash will change if the object mutates.
91
+ memoizeMintedIdentifier = !this.objectType.mutable;
92
+ mintIdentifier = `dataFactory.namedNode(\`\${this.${this.identifierPrefixPropertyName}}\${this.${syntheticNamePrefix}hashShaclProperties(sha256.create())}\`)`;
93
+ break;
94
+ case "uuidv4":
95
+ memoizeMintedIdentifier = true;
96
+ mintIdentifier = `dataFactory.namedNode(\`\${this.${this.identifierPrefixPropertyName}}\${uuid.v4()}\`)`;
97
+ break;
98
+ }
99
+ return Maybe.of({
100
+ leadingTrivia: this.override ? "override " : undefined,
101
+ name: this.name,
102
+ returnType: this.typeAlias,
103
+ statements: [
104
+ memoizeMintedIdentifier
105
+ ? `if (typeof this._${this.name} === "undefined") { this._${this.name} = ${mintIdentifier}; } return this._${this.name};`
106
+ : `return (typeof this._${this.name} !== "undefined") ? this._${this.name} : ${mintIdentifier}`,
107
+ ],
108
+ });
109
+ }
110
+ invariant(this.propertyDeclaration.isNothing());
129
111
  return Maybe.of({
130
- isReadonly: true,
112
+ leadingTrivia: this.override ? "override " : undefined,
131
113
  name: this.name,
132
- type: this.type.name,
114
+ returnType: this.typeAlias,
115
+ statements: [`return super.${this.name} as ${this.typeAlias}`],
116
+ });
117
+ }
118
+ get graphqlField() {
119
+ invariant(this.name.startsWith(syntheticNamePrefix));
120
+ return Maybe.of({
121
+ args: Maybe.empty(),
122
+ description: Maybe.empty(),
123
+ name: `_${this.name.substring(syntheticNamePrefix.length)}`,
124
+ resolve: `(source) => ${this.typeAlias}.toString(source.${this.name})`,
125
+ type: this.type.graphqlName.toString(),
133
126
  });
134
127
  }
135
128
  get jsonPropertySignature() {
@@ -139,38 +132,64 @@ export class IdentifierProperty extends Property {
139
132
  type: "string",
140
133
  });
141
134
  }
142
- get snippetDeclarations() {
143
- const snippetDeclarations = [];
144
- if (this.objectType.features.has("equals")) {
145
- snippetDeclarations.push(SnippetDeclarations.booleanEquals);
146
- }
147
- return snippetDeclarations;
148
- }
149
- classConstructorStatements({ variables, }) {
150
- if (this.abstract) {
151
- return [];
152
- }
153
- if (this.classPropertyDeclaration.isNothing()) {
154
- return [];
155
- }
156
- const classPropertyDeclaration = this.classPropertyDeclaration.unsafeCoerce();
135
+ constructorStatements({ variables, }) {
136
+ let lhs;
137
+ const statements = [];
157
138
  const typeConversions = this.type.conversions;
158
- if (typeConversions.length === 1) {
159
- return [
160
- `this.${classPropertyDeclaration.name} = ${variables.parameter};`,
161
- ];
139
+ switch (this.objectType.declarationType) {
140
+ case "class": {
141
+ if (this.abstract) {
142
+ return [];
143
+ }
144
+ if (this.propertyDeclaration.isNothing()) {
145
+ return [];
146
+ }
147
+ const propertyDeclaration = this.propertyDeclaration.unsafeCoerce();
148
+ if (typeConversions.length === 1) {
149
+ return [`this.${propertyDeclaration.name} = ${variables.parameter};`];
150
+ }
151
+ lhs = `this.${propertyDeclaration.name}`;
152
+ break;
153
+ }
154
+ case "interface":
155
+ if (typeConversions.length === 1) {
156
+ return [`const ${this.name} = ${variables.parameter};`];
157
+ }
158
+ lhs = this.name;
159
+ statements.push(`let ${this.name}: ${this.typeAlias};`);
160
+ break;
162
161
  }
163
- const statements = [];
164
- for (const conversion of this.type.conversions) {
162
+ const conversionBranches = [];
163
+ for (const conversion of typeConversions) {
165
164
  invariant(conversion.sourceTypeName !== "undefined");
166
- statements.push(`if (${conversion.sourceTypeCheckExpression(variables.parameter)}) { this.${classPropertyDeclaration.name} = ${conversion.conversionExpression(variables.parameter)}; }`);
167
- }
168
- if (classPropertyDeclaration.name.startsWith("_")) {
169
- statements.push(`if (typeof ${variables.parameter} === "undefined") { }`);
165
+ conversionBranches.push(`if (${conversion.sourceTypeCheckExpression(variables.parameter)}) { ${lhs} = ${conversion.conversionExpression(variables.parameter)}; }`);
170
166
  }
167
+ this.identifierMintingStrategy.ifJust((identifierMintingStrategy) => {
168
+ switch (this.objectType.declarationType) {
169
+ case "class":
170
+ conversionBranches.push(`if (typeof ${variables.parameter} === "undefined") { }`);
171
+ break;
172
+ case "interface": {
173
+ let mintIdentifier;
174
+ switch (identifierMintingStrategy) {
175
+ case "blankNode":
176
+ mintIdentifier = "dataFactory.blankNode()";
177
+ break;
178
+ case "sha256":
179
+ logger.warn("minting %s identifiers with %s is unsupported", this.objectType.declarationType, identifierMintingStrategy);
180
+ return;
181
+ case "uuidv4":
182
+ mintIdentifier = `dataFactory.namedNode(\`\${${variables.parameters}.${this.identifierPrefixPropertyName} ?? "urn:shaclmate:${this.objectType.discriminatorValue}:"}\${uuid.v4()}\`)`;
183
+ break;
184
+ }
185
+ conversionBranches.push(`if (typeof ${variables.parameter} === "undefined") { ${lhs} = ${mintIdentifier}; }`);
186
+ }
187
+ }
188
+ });
171
189
  // We shouldn't need this else, since the parameter now has the never type, but have to add it to appease the TypeScript compiler
172
- statements.push(`{ this.${classPropertyDeclaration.name} =( ${variables.parameter}) as never;\n }`);
173
- return [statements.join(" else ")];
190
+ conversionBranches.push(`{ ${lhs} = (${variables.parameter}) satisfies never;\n }`);
191
+ statements.push(conversionBranches.join(" else "));
192
+ return statements;
174
193
  }
175
194
  fromJsonStatements({ variables, }) {
176
195
  return [
@@ -182,30 +201,20 @@ export class IdentifierProperty extends Property {
182
201
  // Treat sh:in as a union of the IRIs
183
202
  // rdfjs.NamedNode<"http://example.com/1" | "http://example.com/2">
184
203
  return [
185
- `let ${this.name}: ${this.type.name};`,
186
- `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)} })); }`,
204
+ `let ${this.name}: ${this.typeAlias};`,
205
+ `switch (${variables.resource}.identifier.value) { ${this.type.in_.map((iri) => `case "${iri.value}": ${this.name} = ${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: ${rdfjsTermExpression(rdf.subject)} })); }`,
187
206
  ];
188
207
  }
189
- return [`const ${this.name} = ${variables.resource}.identifier`];
208
+ const statements = [];
209
+ if (this.type.isNamedNodeKind) {
210
+ statements.push(`if (${variables.resource}.identifier.termType !== "NamedNode") { return purify.Left(new rdfjsResource.Resource.MistypedValueError({ actualValue: ${variables.resource}.identifier, expectedValueType: ${JSON.stringify(this.type.name)}, focusResource: ${variables.resource}, predicate: ${rdfjsTermExpression(rdf.subject)} })); }`);
211
+ }
212
+ statements.push(`const ${this.name}: ${this.typeAlias} = ${variables.resource}.identifier;`);
213
+ return statements;
190
214
  }
191
215
  hashStatements({ variables, }) {
192
216
  return [`${variables.hasher}.update(${variables.value}.value);`];
193
217
  }
194
- interfaceConstructorStatements({ variables, }) {
195
- const typeConversions = this.type.conversions;
196
- if (typeConversions.length === 1) {
197
- return [`const ${this.name} = ${variables.parameter};`];
198
- }
199
- const statements = [`let ${this.name}: ${this.type.name};`];
200
- const conversionBranches = [];
201
- for (const conversion of this.type.conversions) {
202
- conversionBranches.push(`if (${conversion.sourceTypeCheckExpression(variables.parameter)}) { ${this.name} = ${conversion.conversionExpression(variables.parameter)}; }`);
203
- }
204
- // We shouldn't need this else, since the parameter now has the never type, but have to add it to appease the TypeScript compiler
205
- conversionBranches.push(`{ ${this.name} =( ${variables.parameter}) as never;\n }`);
206
- statements.push(conversionBranches.join(" else "));
207
- return statements;
208
- }
209
218
  jsonUiSchemaElement({ variables, }) {
210
219
  return Maybe.of(`{ label: "Identifier", scope: \`\${${variables.scopePrefix}}/properties/${this.jsonPropertySignature.unsafeCoerce().name}\`, type: "Control" }`);
211
220
  }
@@ -224,6 +233,55 @@ export class IdentifierProperty extends Property {
224
233
  schema,
225
234
  });
226
235
  }
236
+ get propertyDeclaration() {
237
+ if (this.abstract) {
238
+ // Abstract version of the accessor
239
+ // Work around a ts-morph bug that puts the override keyword before the abstract keyword
240
+ return Maybe.of({
241
+ hasOverrideKeyword: this.abstract && this.override ? undefined : this.override,
242
+ isAbstract: this.abstract && this.override ? undefined : this.abstract,
243
+ isReadonly: true,
244
+ leadingTrivia: this.abstract && this.override ? "abstract override " : undefined,
245
+ name: this.name,
246
+ type: this.typeAlias,
247
+ });
248
+ }
249
+ // See note in TypeFactory re: the logic of whether to declare the identifier in the class or not.
250
+ if (!this.propertyDeclarationVisibility.isJust()) {
251
+ return Maybe.empty();
252
+ }
253
+ if (this.identifierMintingStrategy.isJust()) {
254
+ // Mutable _identifier property that will be lazily initialized by the getter to mint the identifier
255
+ return Maybe.of({
256
+ hasQuestionToken: true,
257
+ name: `_${this.name}`,
258
+ scope: this.propertyDeclarationVisibility
259
+ .map(Property.visibilityToScope)
260
+ .unsafeCoerce(),
261
+ type: `${this.typeAlias}`,
262
+ });
263
+ }
264
+ // Immutable, public identifier property, no getter
265
+ return Maybe.of({
266
+ isReadonly: true,
267
+ name: this.name,
268
+ type: this.typeAlias,
269
+ });
270
+ }
271
+ get propertySignature() {
272
+ return Maybe.of({
273
+ isReadonly: true,
274
+ name: this.name,
275
+ type: this.typeAlias,
276
+ });
277
+ }
278
+ snippetDeclarations() {
279
+ const snippetDeclarations = [];
280
+ if (this.objectType.features.has("equals")) {
281
+ snippetDeclarations.push(SnippetDeclarations.booleanEquals);
282
+ }
283
+ return snippetDeclarations;
284
+ }
227
285
  sparqlConstructTemplateTriples() {
228
286
  return [];
229
287
  }
@@ -0,0 +1,100 @@
1
+ import { Maybe } from "purify-ts";
2
+ import "ts-morph";
3
+ import type { TsFeature } from "../../../enums/TsFeature.js";
4
+ import { Import } from "../Import.js";
5
+ import type { ObjectType } from "../ObjectType.js";
6
+ import type { ObjectUnionType } from "../ObjectUnionType.js";
7
+ import type { OptionType } from "../OptionType.js";
8
+ import type { SetType } from "../SetType.js";
9
+ import { Type as _Type } from "../Type.js";
10
+ import { ShaclProperty } from "./ShaclProperty.js";
11
+ export declare class LazyShaclProperty<LazyTypeT extends LazyShaclProperty.Type<ResolvedTypeT, StubTypeT>, ResolvedTypeT extends LazyShaclProperty.Type.ResolvedTypeConstraint, StubTypeT extends LazyShaclProperty.Type.StubTypeConstraint> extends ShaclProperty<LazyTypeT> {
12
+ readonly mutable = false;
13
+ readonly recursive = false;
14
+ get graphqlField(): ShaclProperty<LazyShaclProperty.Type<StubTypeT, ResolvedTypeT>>["graphqlField"];
15
+ }
16
+ export declare namespace LazyShaclProperty {
17
+ export abstract class Type<ResolvedTypeT extends Type.ResolvedTypeConstraint, StubTypeT extends Type.StubTypeConstraint> extends _Type {
18
+ readonly discriminatorProperty: _Type["discriminatorProperty"];
19
+ readonly mutable = false;
20
+ readonly typeof = "object";
21
+ abstract readonly graphqlArgs: Maybe<Record<string, {
22
+ type: string;
23
+ }>>;
24
+ protected readonly resolvedType: ResolvedTypeT;
25
+ protected readonly runtimeClass: {
26
+ readonly name: string;
27
+ readonly rawName: string;
28
+ readonly snippetDeclaration: string;
29
+ readonly stubPropertyName: string;
30
+ };
31
+ protected readonly stubType: StubTypeT;
32
+ constructor({ stubType, resolvedType, runtimeClass, }: {
33
+ stubType: StubTypeT;
34
+ resolvedType: ResolvedTypeT;
35
+ runtimeClass: Type<ResolvedTypeT, StubTypeT>["runtimeClass"];
36
+ });
37
+ get conversions(): readonly _Type.Conversion[];
38
+ get equalsFunction(): string;
39
+ get graphqlName(): _Type.GraphqlName;
40
+ hashStatements({ depth, variables, }: Parameters<_Type["hashStatements"]>[0]): readonly string[];
41
+ get jsonName(): _Type.JsonName;
42
+ jsonUiSchemaElement(parameters: Parameters<_Type["jsonUiSchemaElement"]>[0]): Maybe<string>;
43
+ jsonZodSchema(parameters: Parameters<_Type["jsonZodSchema"]>[0]): string;
44
+ get name(): string;
45
+ snippetDeclarations(parameters: Parameters<_Type["snippetDeclarations"]>[0]): readonly string[];
46
+ sparqlConstructTemplateTriples(parameters: Parameters<_Type["sparqlConstructTemplateTriples"]>[0]): readonly string[];
47
+ sparqlWherePatterns(parameters: Parameters<_Type["sparqlWherePatterns"]>[0]): readonly string[];
48
+ toJsonExpression({ variables, }: Parameters<_Type["toJsonExpression"]>[0]): string;
49
+ toRdfExpression({ variables, }: Parameters<_Type["toRdfExpression"]>[0]): string;
50
+ useImports(parameters: {
51
+ features: Set<TsFeature>;
52
+ }): readonly Import[];
53
+ }
54
+ export namespace Type {
55
+ type ResolvedTypeConstraint = ObjectType | ObjectUnionType | OptionType<ObjectType | ObjectUnionType> | SetType<ObjectType | ObjectUnionType>;
56
+ type StubTypeConstraint = ResolvedTypeConstraint;
57
+ }
58
+ export class ObjectSetType<ResolvedTypeT extends SetType<ObjectType | ObjectUnionType>, StubTypeT extends SetType<ObjectType | ObjectUnionType>> extends Type<ResolvedTypeT, StubTypeT> {
59
+ constructor({ resolvedType, stubType, }: {
60
+ resolvedType: ResolvedTypeT;
61
+ stubType: StubTypeT;
62
+ });
63
+ get conversions(): readonly _Type.Conversion[];
64
+ fromJsonExpression(parameters: Parameters<_Type["fromJsonExpression"]>[0]): string;
65
+ fromRdfExpression(parameters: Parameters<_Type["fromRdfExpression"]>[0]): string;
66
+ get graphqlArgs(): Maybe<{
67
+ limit: {
68
+ type: string;
69
+ };
70
+ offset: {
71
+ type: string;
72
+ };
73
+ }>;
74
+ graphqlResolveExpression({ variables, }: Parameters<_Type["graphqlResolveExpression"]>[0]): string;
75
+ }
76
+ abstract class SingleObjectType<ResolvedTypeT extends Exclude<Type.ResolvedTypeConstraint, SetType<ObjectType | ObjectUnionType>>, StubTypeT extends Exclude<Type.StubTypeConstraint, SetType<ObjectType | ObjectUnionType>>> extends Type<ResolvedTypeT, StubTypeT> {
77
+ fromJsonExpression(parameters: Parameters<_Type["fromJsonExpression"]>[0]): string;
78
+ get graphqlArgs(): Type<ResolvedTypeT, ObjectUnionType>["graphqlArgs"];
79
+ graphqlResolveExpression({ variables, }: Parameters<_Type["graphqlResolveExpression"]>[0]): string;
80
+ }
81
+ export class OptionalObjectType<ResolvedTypeT extends OptionType<ObjectType | ObjectUnionType>, StubTypeT extends OptionType<ObjectType | ObjectUnionType>> extends SingleObjectType<ResolvedTypeT, StubTypeT> {
82
+ constructor({ resolvedType, stubType, }: {
83
+ resolvedType: ResolvedTypeT;
84
+ stubType: StubTypeT;
85
+ });
86
+ get conversions(): readonly _Type.Conversion[];
87
+ fromRdfExpression(parameters: Parameters<_Type["fromRdfExpression"]>[0]): string;
88
+ graphqlResolveExpression(parameters: Parameters<_Type["graphqlResolveExpression"]>[0]): string;
89
+ }
90
+ export class RequiredObjectType<ResolvedTypeT extends ObjectType | ObjectUnionType, StubTypeT extends ObjectType | ObjectUnionType> extends SingleObjectType<ResolvedTypeT, StubTypeT> {
91
+ constructor({ resolvedType, stubType, }: {
92
+ resolvedType: ResolvedTypeT;
93
+ stubType: StubTypeT;
94
+ });
95
+ get conversions(): readonly _Type.Conversion[];
96
+ fromRdfExpression(parameters: Parameters<_Type["fromRdfExpression"]>[0]): string;
97
+ }
98
+ export {};
99
+ }
100
+ //# sourceMappingURL=LazyShaclProperty.d.ts.map