@shaclmate/compiler 2.0.13 → 2.0.15

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 (210) hide show
  1. package/Compiler.d.ts +15 -0
  2. package/Compiler.js +20 -0
  3. package/ShapesGraphToAstTransformer.d.ts +18 -23
  4. package/ShapesGraphToAstTransformer.js +21 -447
  5. package/_ShapesGraphToAstTransformer/NodeShapeAstType.d.ts +3 -0
  6. package/_ShapesGraphToAstTransformer/NodeShapeAstType.js +2 -0
  7. package/_ShapesGraphToAstTransformer/index.d.ts +10 -0
  8. package/_ShapesGraphToAstTransformer/index.js +10 -0
  9. package/_ShapesGraphToAstTransformer/pickLiteral.d.ts +4 -0
  10. package/_ShapesGraphToAstTransformer/pickLiteral.js +18 -0
  11. package/_ShapesGraphToAstTransformer/propertyShapeNodeKinds.d.ts +4 -0
  12. package/_ShapesGraphToAstTransformer/propertyShapeNodeKinds.js +26 -0
  13. package/_ShapesGraphToAstTransformer/shapeAstName.d.ts +5 -0
  14. package/_ShapesGraphToAstTransformer/shapeAstName.js +28 -0
  15. package/_ShapesGraphToAstTransformer/transformNodeShapeToAstType.d.ts +6 -0
  16. package/_ShapesGraphToAstTransformer/transformNodeShapeToAstType.js +178 -0
  17. package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstCompositeType.d.ts +13 -0
  18. package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstCompositeType.js +200 -0
  19. package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstIdentifierType.d.ts +12 -0
  20. package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstIdentifierType.js +29 -0
  21. package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstLiteralType.d.ts +12 -0
  22. package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstLiteralType.js +43 -0
  23. package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstObjectTypeProperty.d.ts +6 -0
  24. package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstObjectTypeProperty.js +31 -0
  25. package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstTermType.d.ts +14 -0
  26. package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstTermType.js +21 -0
  27. package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstType.d.ts +16 -0
  28. package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstType.js +58 -0
  29. package/ast/Ast.d.ts +5 -0
  30. package/ast/CompositeType.d.ts +13 -0
  31. package/ast/CompositeType.js +2 -0
  32. package/ast/IdentifierType.d.ts +3 -6
  33. package/ast/IntersectionType.d.ts +2 -2
  34. package/ast/ListType.d.ts +53 -0
  35. package/ast/ListType.js +2 -0
  36. package/ast/LiteralType.d.ts +4 -3
  37. package/ast/Name.d.ts +1 -0
  38. package/ast/ObjectCompositeType.d.ts +22 -0
  39. package/ast/ObjectCompositeType.js +2 -0
  40. package/ast/ObjectIntersectionType.d.ts +8 -0
  41. package/ast/ObjectIntersectionType.js +2 -0
  42. package/ast/ObjectType.d.ts +91 -19
  43. package/ast/ObjectType.js +26 -1
  44. package/ast/ObjectUnionType.d.ts +19 -0
  45. package/ast/ObjectUnionType.js +2 -0
  46. package/ast/PlaceholderType.d.ts +7 -0
  47. package/ast/PlaceholderType.js +2 -0
  48. package/ast/SetType.d.ts +1 -1
  49. package/ast/TermType.d.ts +11 -0
  50. package/ast/TermType.js +2 -0
  51. package/ast/Type.d.ts +11 -3
  52. package/ast/UnionType.d.ts +3 -3
  53. package/ast/index.d.ts +6 -3
  54. package/ast/index.js +6 -3
  55. package/enums/MintingStrategy.d.ts +5 -0
  56. package/enums/MintingStrategy.js +2 -0
  57. package/enums/PropertyVisibility.d.ts +2 -0
  58. package/enums/PropertyVisibility.js +2 -0
  59. package/enums/TsFeature.d.ts +5 -0
  60. package/enums/TsFeature.js +16 -0
  61. package/enums/TsObjectDeclarationType.d.ts +5 -0
  62. package/enums/TsObjectDeclarationType.js +2 -0
  63. package/enums/index.d.ts +5 -0
  64. package/enums/index.js +5 -0
  65. package/generators/Generator.d.ts +5 -0
  66. package/generators/Generator.js +2 -0
  67. package/generators/index.d.ts +2 -2
  68. package/generators/index.js +2 -2
  69. package/generators/json/AstJsonGenerator.d.ts +4 -5
  70. package/generators/json/AstJsonGenerator.js +31 -22
  71. package/generators/ts/BooleanType.d.ts +7 -3
  72. package/generators/ts/BooleanType.js +58 -4
  73. package/generators/ts/DateTimeType.d.ts +19 -0
  74. package/generators/ts/DateTimeType.js +66 -0
  75. package/generators/ts/DeclaredType.d.ts +17 -0
  76. package/generators/ts/DeclaredType.js +10 -0
  77. package/generators/ts/IdentifierType.d.ts +7 -17
  78. package/generators/ts/IdentifierType.js +69 -60
  79. package/generators/ts/Import.d.ts +17 -0
  80. package/generators/ts/Import.js +54 -0
  81. package/generators/ts/ListType.d.ts +19 -8
  82. package/generators/ts/ListType.js +206 -44
  83. package/generators/ts/LiteralType.d.ts +13 -11
  84. package/generators/ts/LiteralType.js +36 -51
  85. package/generators/ts/NumberType.d.ts +7 -3
  86. package/generators/ts/NumberType.js +55 -4
  87. package/generators/ts/ObjectType.d.ts +48 -25
  88. package/generators/ts/ObjectType.js +234 -50
  89. package/generators/ts/ObjectUnionType.d.ts +58 -0
  90. package/generators/ts/ObjectUnionType.js +450 -0
  91. package/generators/ts/OptionType.d.ts +14 -4
  92. package/generators/ts/OptionType.js +70 -20
  93. package/generators/ts/PrimitiveType.d.ts +15 -5
  94. package/generators/ts/PrimitiveType.js +27 -31
  95. package/generators/ts/SetType.d.ts +14 -4
  96. package/generators/ts/SetType.js +108 -30
  97. package/generators/ts/SnippetDeclarations.d.ts +11 -0
  98. package/generators/ts/SnippetDeclarations.js +215 -0
  99. package/generators/ts/StringType.d.ts +8 -3
  100. package/generators/ts/StringType.js +57 -3
  101. package/generators/ts/TermType.d.ts +54 -0
  102. package/generators/ts/TermType.js +242 -0
  103. package/generators/ts/TsGenerator.d.ts +4 -12
  104. package/generators/ts/TsGenerator.js +57 -99
  105. package/generators/ts/Type.d.ts +117 -46
  106. package/generators/ts/Type.js +93 -59
  107. package/generators/ts/TypeFactory.d.ts +4 -5
  108. package/generators/ts/TypeFactory.js +224 -91
  109. package/generators/ts/UnionType.d.ts +20 -6
  110. package/generators/ts/UnionType.js +230 -120
  111. package/generators/ts/_ObjectType/IdentifierProperty.d.ts +27 -8
  112. package/generators/ts/_ObjectType/IdentifierProperty.js +153 -32
  113. package/generators/ts/_ObjectType/Property.d.ts +139 -9
  114. package/generators/ts/_ObjectType/Property.js +26 -3
  115. package/generators/ts/_ObjectType/ShaclProperty.d.ts +24 -5
  116. package/generators/ts/_ObjectType/ShaclProperty.js +103 -26
  117. package/generators/ts/_ObjectType/TypeDiscriminatorProperty.d.ts +23 -7
  118. package/generators/ts/_ObjectType/TypeDiscriminatorProperty.js +83 -14
  119. package/generators/ts/_ObjectType/classDeclaration.d.ts +2 -1
  120. package/generators/ts/_ObjectType/classDeclaration.js +79 -111
  121. package/generators/ts/_ObjectType/createFunctionDeclaration.d.ts +5 -0
  122. package/generators/ts/_ObjectType/createFunctionDeclaration.js +60 -0
  123. package/generators/ts/_ObjectType/equalsFunctionDeclaration.d.ts +2 -1
  124. package/generators/ts/_ObjectType/equalsFunctionDeclaration.js +12 -20
  125. package/generators/ts/_ObjectType/equalsFunctionOrMethodDeclaration.d.ts +11 -0
  126. package/generators/ts/_ObjectType/equalsFunctionOrMethodDeclaration.js +70 -0
  127. package/generators/ts/_ObjectType/fromJsonFunctionDeclarations.d.ts +4 -0
  128. package/generators/ts/_ObjectType/fromJsonFunctionDeclarations.js +78 -0
  129. package/generators/ts/_ObjectType/fromRdfFunctionDeclarations.d.ts +4 -0
  130. package/generators/ts/_ObjectType/fromRdfFunctionDeclarations.js +91 -0
  131. package/generators/ts/_ObjectType/hashFunctionDeclaration.d.ts +3 -3
  132. package/generators/ts/_ObjectType/hashFunctionDeclaration.js +11 -55
  133. package/generators/ts/_ObjectType/hashFunctionOrMethodDeclaration.d.ts +11 -0
  134. package/generators/ts/_ObjectType/hashFunctionOrMethodDeclaration.js +64 -0
  135. package/generators/ts/_ObjectType/index.d.ts +8 -2
  136. package/generators/ts/_ObjectType/index.js +8 -2
  137. package/generators/ts/_ObjectType/interfaceDeclaration.d.ts +3 -2
  138. package/generators/ts/_ObjectType/interfaceDeclaration.js +11 -2
  139. package/generators/ts/_ObjectType/jsonSchemaFunctionDeclaration.d.ts +5 -0
  140. package/generators/ts/_ObjectType/jsonSchemaFunctionDeclaration.js +19 -0
  141. package/generators/ts/_ObjectType/jsonUiSchemaFunctionDeclaration.d.ts +5 -0
  142. package/generators/ts/_ObjectType/jsonUiSchemaFunctionDeclaration.js +31 -0
  143. package/generators/ts/_ObjectType/jsonZodSchemaFunctionDeclaration.d.ts +5 -0
  144. package/generators/ts/_ObjectType/jsonZodSchemaFunctionDeclaration.js +37 -0
  145. package/generators/ts/_ObjectType/rdfjsTermExpression.d.ts +6 -0
  146. package/generators/ts/{rdfjsTermExpression.js → _ObjectType/rdfjsTermExpression.js} +3 -1
  147. package/generators/ts/_ObjectType/sparqlConstructQueryFunctionDeclaration.d.ts +5 -0
  148. package/generators/ts/_ObjectType/sparqlConstructQueryFunctionDeclaration.js +21 -0
  149. package/generators/ts/_ObjectType/sparqlConstructQueryStringFunctionDeclaration.d.ts +5 -0
  150. package/generators/ts/_ObjectType/sparqlConstructQueryStringFunctionDeclaration.js +20 -0
  151. package/generators/ts/_ObjectType/sparqlFunctionDeclarations.d.ts +4 -0
  152. package/generators/ts/_ObjectType/sparqlFunctionDeclarations.js +78 -0
  153. package/generators/ts/_ObjectType/toJsonFunctionDeclaration.d.ts +5 -0
  154. package/generators/ts/_ObjectType/toJsonFunctionDeclaration.js +19 -0
  155. package/generators/ts/_ObjectType/toJsonFunctionOrMethodDeclaration.d.ts +10 -0
  156. package/generators/ts/_ObjectType/toJsonFunctionOrMethodDeclaration.js +59 -0
  157. package/generators/ts/_ObjectType/toJsonReturnType.d.ts +3 -0
  158. package/generators/ts/_ObjectType/toJsonReturnType.js +19 -0
  159. package/generators/ts/_ObjectType/toRdfFunctionDeclaration.d.ts +3 -2
  160. package/generators/ts/_ObjectType/toRdfFunctionDeclaration.js +11 -45
  161. package/generators/ts/_ObjectType/toRdfFunctionOrMethodDeclaration.d.ts +10 -0
  162. package/generators/ts/_ObjectType/toRdfFunctionOrMethodDeclaration.js +67 -0
  163. package/generators/ts/objectInitializer.d.ts +2 -0
  164. package/generators/ts/objectInitializer.js +14 -0
  165. package/generators/ts/tsComment.d.ts +5 -0
  166. package/generators/ts/tsComment.js +11 -0
  167. package/generators/ts/tsName.d.ts +1 -1
  168. package/generators/ts/tsName.js +1 -0
  169. package/index.d.ts +1 -1
  170. package/index.js +1 -1
  171. package/input/NodeShape.d.ts +46 -0
  172. package/input/NodeShape.js +165 -0
  173. package/input/Ontology.d.ts +13 -0
  174. package/input/Ontology.js +30 -0
  175. package/input/PropertyShape.d.ts +15 -0
  176. package/input/PropertyShape.js +34 -0
  177. package/input/Shape.d.ts +4 -0
  178. package/input/Shape.js +2 -0
  179. package/input/ShapesGraph.d.ts +9 -0
  180. package/input/ShapesGraph.js +50 -0
  181. package/input/ancestorClassIris.d.ts +4 -0
  182. package/input/ancestorClassIris.js +21 -0
  183. package/input/descendantClassIris.d.ts +4 -0
  184. package/input/descendantClassIris.js +21 -0
  185. package/input/generated.d.ts +275 -0
  186. package/input/generated.js +1436 -0
  187. package/input/index.d.ts +7 -0
  188. package/input/index.js +7 -0
  189. package/input/tsFeatures.d.ts +10 -0
  190. package/input/tsFeatures.js +46 -0
  191. package/package.json +15 -9
  192. package/ast/MintingStrategy.d.ts +0 -8
  193. package/ast/MintingStrategy.js +0 -9
  194. package/generators/ts/Configuration.d.ts +0 -29
  195. package/generators/ts/Configuration.js +0 -40
  196. package/generators/ts/IntersectionType.d.ts +0 -14
  197. package/generators/ts/IntersectionType.js +0 -26
  198. package/generators/ts/RdfjsTermType.d.ts +0 -25
  199. package/generators/ts/RdfjsTermType.js +0 -46
  200. package/generators/ts/_ObjectType/fromRdfFunctionDeclaration.d.ts +0 -4
  201. package/generators/ts/_ObjectType/fromRdfFunctionDeclaration.js +0 -72
  202. package/generators/ts/_ObjectType/sparqlGraphPatternsClassDeclaration.d.ts +0 -4
  203. package/generators/ts/_ObjectType/sparqlGraphPatternsClassDeclaration.js +0 -46
  204. package/generators/ts/rdfjsTermExpression.d.ts +0 -5
  205. package/vocabularies/dashDataset.d.ts +0 -3
  206. package/vocabularies/dashDataset.js +0 -2370
  207. package/vocabularies/index.d.ts +0 -2
  208. package/vocabularies/index.js +0 -2
  209. package/vocabularies/shaclmate.d.ts +0 -15
  210. package/vocabularies/shaclmate.js +0 -6
@@ -1,58 +1,122 @@
1
1
  import { Maybe } from "purify-ts";
2
- import { Scope, } from "ts-morph";
3
- import { MintingStrategy } from "../../../ast";
2
+ import { invariant } from "ts-invariant";
3
+ import { Import } from "../Import.js";
4
+ import { SnippetDeclarations } from "../SnippetDeclarations.js";
4
5
  import { Property } from "./Property.js";
5
6
  export class IdentifierProperty extends Property {
6
- constructor({ mintingStrategy, ...superParameters }) {
7
+ constructor({ abstract, classDeclarationVisibility, lazyObjectTypeMutable, mintingStrategy, override, ...superParameters }) {
7
8
  super(superParameters);
8
- this.equalsFunction = "purifyHelpers.Equatable.booleanEquals";
9
- this.mintingStrategy = mintingStrategy;
10
- }
11
- get classConstructorParametersPropertySignature() {
12
- return Maybe.of({
13
- hasQuestionToken: this.mintingStrategy.isJust(),
14
- isReadonly: true,
15
- name: this.name,
16
- type: this.type.name,
17
- });
9
+ this.equalsFunction = "booleanEquals";
10
+ this.mutable = false;
11
+ invariant(this.visibility === "public");
12
+ this.abstract = abstract;
13
+ this.classDeclarationVisibility = classDeclarationVisibility;
14
+ if (mintingStrategy.isJust()) {
15
+ this.mintingStrategy = mintingStrategy.unsafeCoerce();
16
+ }
17
+ else if (this.type.nodeKinds.has("BlankNode")) {
18
+ this.mintingStrategy = "blankNode";
19
+ }
20
+ else {
21
+ this.mintingStrategy = "none";
22
+ }
23
+ this.lazyObjectTypeMutable = lazyObjectTypeMutable;
24
+ this.override = override;
18
25
  }
19
26
  get classGetAccessorDeclaration() {
20
- if (!this.mintingStrategy.isJust()) {
27
+ if (this.abstract) {
21
28
  return Maybe.empty();
22
29
  }
23
30
  let mintIdentifier;
24
- switch (this.mintingStrategy.unsafeCoerce()) {
25
- case MintingStrategy.SHA256:
31
+ switch (this.mintingStrategy) {
32
+ case "blankNode":
33
+ mintIdentifier = "dataFactory.blankNode()";
34
+ break;
35
+ case "none":
36
+ // If there's no minting strategy the identifier will be required by the constructor and assigned to a public property.
37
+ return Maybe.empty();
38
+ case "sha256":
26
39
  mintIdentifier =
27
40
  "dataFactory.namedNode(`urn:shaclmate:object:${this.type}:${this.hash(sha256.create())}`)";
28
41
  break;
29
- case MintingStrategy.UUIDv4:
42
+ case "uuidv4":
30
43
  mintIdentifier =
31
44
  "dataFactory.namedNode(`urn:shaclmate:object:${this.type}:${uuid.v4()}`)";
32
45
  break;
33
46
  }
34
47
  return Maybe.of({
48
+ leadingTrivia: this.override ? "override " : undefined,
35
49
  name: this.name,
36
50
  returnType: this.type.name,
37
51
  statements: [
38
- `if (typeof this._${this.name} === "undefined") { this._${this.name} = ${mintIdentifier}; } return this._${this.name};`,
52
+ this.lazyObjectTypeMutable()
53
+ ? `return (typeof this._${this.name} !== "undefined") ? this._${this.name} : ${mintIdentifier}`
54
+ : `if (typeof this._${this.name} === "undefined") { this._${this.name} = ${mintIdentifier}; } return this._${this.name};`,
39
55
  ],
40
56
  });
41
57
  }
42
58
  get classPropertyDeclaration() {
43
- if (this.mintingStrategy.isJust()) {
44
- // Mutable _identifier that will be lazily initialized by the getter
45
- return {
46
- name: `_${this.name}`,
47
- scope: Scope.Private,
48
- type: `${this.type.name} | undefined`,
49
- };
59
+ if (this.abstract) {
60
+ // Abstract version of the accessor
61
+ // Work around a ts-morph bug that puts the override keyword before the abstract keyword
62
+ return Maybe.of({
63
+ hasOverrideKeyword: this.abstract && this.override ? undefined : this.override,
64
+ isAbstract: this.abstract && this.override ? undefined : this.abstract,
65
+ isReadonly: true,
66
+ leadingTrivia: this.abstract && this.override ? "abstract override " : undefined,
67
+ name: this.name,
68
+ type: this.type.name,
69
+ });
50
70
  }
51
- return {
71
+ // See note in TypeFactory re: the logic of whether to declare the identifier in the class or not.
72
+ if (!this.classDeclarationVisibility.isJust()) {
73
+ return Maybe.empty();
74
+ }
75
+ switch (this.mintingStrategy) {
76
+ case "none":
77
+ // Immutable, public identifier property, no getter
78
+ return Maybe.of({
79
+ isReadonly: true,
80
+ name: this.name,
81
+ type: this.type.name,
82
+ });
83
+ default:
84
+ // Mutable _identifier property that will be lazily initialized by the getter to mint the identifier
85
+ return Maybe.of({
86
+ name: `_${this.name}`,
87
+ scope: this.classDeclarationVisibility
88
+ .map(Property.visibilityToScope)
89
+ .unsafeCoerce(),
90
+ type: `${this.type.name} | undefined`,
91
+ });
92
+ }
93
+ }
94
+ get constructorParametersPropertySignature() {
95
+ if (this.objectType.declarationType === "class" && this.abstract) {
96
+ return Maybe.empty();
97
+ }
98
+ return Maybe.of({
99
+ hasQuestionToken: this.objectType.declarationType === "class" &&
100
+ this.mintingStrategy !== "none",
52
101
  isReadonly: true,
53
102
  name: this.name,
54
103
  type: this.type.name,
55
- };
104
+ });
105
+ }
106
+ get declarationImports() {
107
+ const imports = this.type.useImports().concat();
108
+ if (this.objectType.features.has("hash") &&
109
+ this.objectType.declarationType === "class") {
110
+ switch (this.mintingStrategy) {
111
+ case "sha256":
112
+ imports.push(Import.SHA256);
113
+ break;
114
+ case "uuidv4":
115
+ imports.push(Import.UUID);
116
+ break;
117
+ }
118
+ }
119
+ return imports;
56
120
  }
57
121
  get interfacePropertySignature() {
58
122
  return {
@@ -61,19 +125,76 @@ export class IdentifierProperty extends Property {
61
125
  type: this.type.name,
62
126
  };
63
127
  }
128
+ get jsonPropertySignature() {
129
+ return {
130
+ isReadonly: true,
131
+ name: "@id",
132
+ type: "string",
133
+ };
134
+ }
135
+ get snippetDeclarations() {
136
+ const snippetDeclarations = [];
137
+ if (this.objectType.features.has("equals")) {
138
+ snippetDeclarations.push(SnippetDeclarations.booleanEquals);
139
+ }
140
+ return snippetDeclarations;
141
+ }
64
142
  classConstructorStatements({ variables, }) {
143
+ if (this.abstract) {
144
+ return [];
145
+ }
146
+ return this.classPropertyDeclaration
147
+ .map((classPropertyDeclaration) => [
148
+ `this.${classPropertyDeclaration.name} = ${variables.parameter};`,
149
+ ])
150
+ .orDefault([]);
151
+ }
152
+ fromJsonStatements({ variables, }) {
65
153
  return [
66
- `this.${this.mintingStrategy.isJust() ? "_" : ""}${this.name} = ${variables.parameter};`,
154
+ `const ${this.name} = ${this.type.fromJsonExpression({ variables: { value: variables.jsonObject } })};`,
67
155
  ];
68
156
  }
69
157
  fromRdfStatements({ variables, }) {
70
158
  return [`const ${this.name} = ${variables.resource}.identifier`];
71
159
  }
72
- hashStatements(parameters) {
73
- return this.type.hashStatements(parameters);
160
+ hashStatements() {
161
+ return [];
162
+ }
163
+ interfaceConstructorStatements({ variables, }) {
164
+ return [`const ${this.name} = ${variables.parameter}`];
74
165
  }
75
- sparqlGraphPatternExpression() {
76
- return Maybe.empty();
166
+ jsonUiSchemaElement({ variables, }) {
167
+ return Maybe.of(`{ label: "Identifier", scope: \`\${${variables.scopePrefix}}/properties/${this.jsonPropertySignature.name}\`, type: "Control" }`);
168
+ }
169
+ jsonZodSchema({ variables, }) {
170
+ return {
171
+ key: this.jsonPropertySignature.name,
172
+ schema: `${variables.zod}.string().min(1)`,
173
+ };
174
+ }
175
+ sparqlConstructTemplateTriples() {
176
+ return [];
177
+ }
178
+ sparqlWherePatterns() {
179
+ return [];
180
+ }
181
+ toJsonObjectMember({ variables, }) {
182
+ const nodeKinds = [...this.type.nodeKinds];
183
+ const valueToNodeKinds = nodeKinds.map((nodeKind) => {
184
+ switch (nodeKind) {
185
+ case "BlankNode":
186
+ return `\`_:\${${variables.value}.value}\``;
187
+ case "NamedNode":
188
+ return `${variables.value}.value`;
189
+ default:
190
+ throw new RangeError(nodeKind);
191
+ }
192
+ });
193
+ if (valueToNodeKinds.length === 1) {
194
+ return `"@id": ${valueToNodeKinds[0]}`;
195
+ }
196
+ invariant(valueToNodeKinds.length === 2);
197
+ return `"@id": ${variables.value}.termType === "${nodeKinds[0]}" ? ${valueToNodeKinds[0]} : ${valueToNodeKinds[1]}`;
77
198
  }
78
199
  toRdfStatements() {
79
200
  return [];
@@ -1,38 +1,168 @@
1
+ import type { BlankNode, Literal, NamedNode, Variable } from "@rdfjs/types";
1
2
  import type { Maybe } from "purify-ts";
2
- import type { GetAccessorDeclarationStructure, OptionalKind, PropertyDeclarationStructure, PropertySignatureStructure } from "ts-morph";
3
- import type { Configuration } from "../Configuration.js";
3
+ import { type GetAccessorDeclarationStructure, type OptionalKind, type PropertyDeclarationStructure, type PropertySignatureStructure, Scope } from "ts-morph";
4
+ import type { PropertyVisibility, TsFeature, TsObjectDeclarationType } from "../../../enums/index.js";
5
+ import type { Import } from "../Import.js";
4
6
  import type { Type } from "../Type.js";
5
7
  export declare abstract class Property<TypeT extends {
8
+ readonly mutable: boolean;
6
9
  readonly name: string;
7
10
  }> {
8
- abstract readonly classConstructorParametersPropertySignature: Maybe<OptionalKind<PropertySignatureStructure>>;
11
+ /**
12
+ * Optional get accessor to include in a class declaration of the object type.
13
+ */
9
14
  abstract readonly classGetAccessorDeclaration: Maybe<OptionalKind<GetAccessorDeclarationStructure>>;
10
- abstract readonly classPropertyDeclaration: OptionalKind<PropertyDeclarationStructure>;
15
+ /**
16
+ * Optional property declaration to include in a class declaration of the object type.
17
+ */
18
+ abstract readonly classPropertyDeclaration: Maybe<OptionalKind<PropertyDeclarationStructure>>;
19
+ /**
20
+ * Optional property to include in the parameters object of a class constructor.
21
+ */
22
+ abstract readonly constructorParametersPropertySignature: Maybe<OptionalKind<PropertySignatureStructure>>;
23
+ /**
24
+ * Function declaration that takes two values of the property and compares them, returning and EqualsResult.
25
+ */
11
26
  abstract readonly equalsFunction: string;
27
+ /**
28
+ * Signature of the property in an interface version of the object.
29
+ */
12
30
  abstract readonly interfacePropertySignature: OptionalKind<PropertySignatureStructure>;
31
+ /**
32
+ * Signature of the property when serialized to JSON (the type of toJsonObjectMember).
33
+ */
34
+ abstract readonly jsonPropertySignature: OptionalKind<PropertySignatureStructure>;
35
+ /**
36
+ * Is the property reassignable?
37
+ */
38
+ abstract readonly mutable: boolean;
39
+ /**
40
+ * TypeScript identifier-safe name of the property.
41
+ */
13
42
  readonly name: string;
43
+ /**
44
+ * Reusable function, type, and other declarations that are not particular to this property but that property-specific code
45
+ * relies on. For example, the equals function/method of ObjectType has a custom return type that's the same across all
46
+ * ObjectType's. Instead of re-declaring the return type anonymously on every equals function, declare a named type
47
+ * as a snippet and reference it.
48
+ *
49
+ * The generator deduplicates snippet declarations across all types before adding them to the source.
50
+ */
51
+ abstract readonly snippetDeclarations: readonly string[];
52
+ /**
53
+ * Property type
54
+ . */
14
55
  readonly type: TypeT;
15
- protected readonly configuration: Configuration;
16
- constructor({ configuration, name, type, }: {
17
- configuration: Configuration;
56
+ /**
57
+ * Property visibility: private, protected, public.
58
+ */
59
+ readonly visibility: PropertyVisibility;
60
+ protected readonly dataFactoryVariable: string;
61
+ protected readonly objectType: {
62
+ readonly declarationType: TsObjectDeclarationType;
63
+ readonly features: Set<TsFeature>;
64
+ };
65
+ constructor({ dataFactoryVariable, name, objectType, type, visibility, }: {
66
+ dataFactoryVariable: string;
18
67
  name: string;
68
+ objectType: Property<TypeT>["objectType"];
19
69
  type: TypeT;
70
+ visibility: PropertyVisibility;
20
71
  });
21
- get importStatements(): readonly string[];
72
+ /**
73
+ * Imports this property requires when declared in an object.
74
+ */
75
+ get declarationImports(): readonly Import[];
76
+ protected static visibilityToScope(visibility: PropertyVisibility): Scope | undefined;
77
+ /**
78
+ * Statements to assign the parameter of described by constructorParametersPropertySignature to a class member.
79
+ */
22
80
  abstract classConstructorStatements(parameters: {
23
81
  variables: {
24
82
  parameter: string;
25
83
  };
26
84
  }): readonly string[];
85
+ /**
86
+ * Statements to deserialize JSON for this property (as described by toJsonObjectMember) to a typed value of the property.
87
+ */
88
+ abstract fromJsonStatements(parameters: {
89
+ variables: {
90
+ jsonObject: string;
91
+ };
92
+ }): readonly string[];
93
+ /**
94
+ * Statements to deserialize RDF for this property to a typed value of the property.
95
+ */
27
96
  abstract fromRdfStatements(parameters: {
28
97
  variables: {
98
+ context: string;
99
+ languageIn: string;
29
100
  resource: string;
30
101
  };
31
102
  }): readonly string[];
103
+ /**
104
+ * Statements to hash this property using a hasher instance.
105
+ */
32
106
  abstract hashStatements(parameters: Parameters<Type["hashStatements"]>[0]): readonly string[];
33
- abstract sparqlGraphPatternExpression(): Maybe<string>;
107
+ /**
108
+ * Companion to classConstructorStatements with a similar purpose in an interface's create() function.
109
+ */
110
+ abstract interfaceConstructorStatements(parameters: {
111
+ variables: {
112
+ parameter: string;
113
+ };
114
+ }): readonly string[];
115
+ /**
116
+ * Element object (usually a control https://jsonforms.io/docs/uischema/controls) for a JSON Forms UI schema.
117
+ */
118
+ abstract jsonUiSchemaElement(parameters: {
119
+ variables: {
120
+ scopePrefix: string;
121
+ };
122
+ }): Maybe<string>;
123
+ /**
124
+ * zod Object key: schema pair on the property serialized by toJsonObjectMember.
125
+ */
126
+ abstract jsonZodSchema(parameters: {
127
+ variables: {
128
+ zod: string;
129
+ };
130
+ }): {
131
+ readonly key: string;
132
+ readonly schema: string;
133
+ };
134
+ /**
135
+ * An array of SPARQL.js CONSTRUCT template triples for this property as strings (so they can incorporate runtime calls).
136
+ */
137
+ abstract sparqlConstructTemplateTriples(parameters: {
138
+ variables: {
139
+ subject: string;
140
+ variablePrefix: string;
141
+ };
142
+ }): readonly string[];
143
+ /**
144
+ * An array of SPARQL.js where patterns for this property as strings (so they can incorporate runtime calls).
145
+ */
146
+ abstract sparqlWherePatterns(parameters: {
147
+ variables: {
148
+ subject: string;
149
+ variablePrefix: string;
150
+ };
151
+ }): readonly string[];
152
+ /**
153
+ * property: expression to serialize a property to a JSON object member.
154
+ */
155
+ abstract toJsonObjectMember(parameters: {
156
+ variables: {
157
+ value: string;
158
+ };
159
+ }): string;
160
+ /**
161
+ * Statements to serialize this property to an RDF resource.
162
+ */
34
163
  abstract toRdfStatements(parameters: {
35
164
  variables: Omit<Parameters<Type["toRdfExpression"]>[0]["variables"], "predicate">;
36
165
  }): readonly string[];
166
+ protected rdfjsTermExpression(rdfjsTerm: Omit<BlankNode, "equals"> | Omit<Literal, "equals"> | Omit<NamedNode, "equals"> | Omit<Variable, "equals">): string;
37
167
  }
38
168
  //# sourceMappingURL=Property.d.ts.map
@@ -1,11 +1,34 @@
1
+ import { Scope, } from "ts-morph";
2
+ import { rdfjsTermExpression } from "./rdfjsTermExpression.js";
1
3
  export class Property {
2
- constructor({ configuration, name, type, }) {
3
- this.configuration = configuration;
4
+ constructor({ dataFactoryVariable, name, objectType, type, visibility, }) {
5
+ this.dataFactoryVariable = dataFactoryVariable;
4
6
  this.name = name;
7
+ this.objectType = objectType;
5
8
  this.type = type;
9
+ this.visibility = visibility;
6
10
  }
7
- get importStatements() {
11
+ /**
12
+ * Imports this property requires when declared in an object.
13
+ */
14
+ get declarationImports() {
8
15
  return [];
9
16
  }
17
+ static visibilityToScope(visibility) {
18
+ switch (visibility) {
19
+ case "private":
20
+ return Scope.Private;
21
+ case "protected":
22
+ return Scope.Protected;
23
+ case "public":
24
+ return undefined;
25
+ }
26
+ }
27
+ rdfjsTermExpression(rdfjsTerm) {
28
+ return rdfjsTermExpression({
29
+ dataFactoryVariable: this.dataFactoryVariable,
30
+ rdfjsTerm,
31
+ });
32
+ }
10
33
  }
11
34
  //# sourceMappingURL=Property.js.map
@@ -1,25 +1,44 @@
1
1
  import type * as rdfjs from "@rdfjs/types";
2
2
  import { Maybe } from "purify-ts";
3
3
  import type { GetAccessorDeclarationStructure, OptionalKind, PropertyDeclarationStructure, PropertySignatureStructure } from "ts-morph";
4
+ import type { IdentifierType } from "../IdentifierType.js";
5
+ import type { Import } from "../Import.js";
4
6
  import type { Type } from "../Type.js";
5
7
  import { Property } from "./Property.js";
6
8
  export declare class ShaclProperty extends Property<Type> {
9
+ readonly mutable: boolean;
10
+ private readonly comment;
11
+ private readonly description;
12
+ private readonly label;
7
13
  private readonly path;
8
- constructor({ path, ...superParameters }: {
14
+ constructor({ comment, description, label, mutable, path, ...superParameters }: {
15
+ comment: Maybe<string>;
16
+ description: Maybe<string>;
17
+ label: Maybe<string>;
18
+ mutable: boolean;
9
19
  path: rdfjs.NamedNode;
10
20
  type: Type;
11
21
  } & ConstructorParameters<typeof Property>[0]);
12
- get classConstructorParametersPropertySignature(): Maybe<OptionalKind<PropertySignatureStructure>>;
13
22
  get classGetAccessorDeclaration(): Maybe<OptionalKind<GetAccessorDeclarationStructure>>;
14
- get classPropertyDeclaration(): OptionalKind<PropertyDeclarationStructure>;
23
+ get classPropertyDeclaration(): Maybe<OptionalKind<PropertyDeclarationStructure>>;
24
+ get constructorParametersPropertySignature(): Maybe<OptionalKind<PropertySignatureStructure>>;
25
+ get declarationImports(): readonly Import[];
15
26
  get equalsFunction(): string;
16
- get importStatements(): readonly string[];
17
27
  get interfacePropertySignature(): OptionalKind<PropertySignatureStructure>;
28
+ get jsonPropertySignature(): OptionalKind<PropertySignatureStructure>;
29
+ get snippetDeclarations(): readonly string[];
30
+ private get declarationComment();
18
31
  private get pathExpression();
19
32
  classConstructorStatements({ variables, }: Parameters<Property<Type>["classConstructorStatements"]>[0]): readonly string[];
33
+ fromJsonStatements({ variables, }: Parameters<Property<IdentifierType>["fromJsonStatements"]>[0]): readonly string[];
20
34
  fromRdfStatements({ variables, }: Parameters<Property<Type>["fromRdfStatements"]>[0]): readonly string[];
21
35
  hashStatements(parameters: Parameters<Property<Type>["hashStatements"]>[0]): readonly string[];
22
- sparqlGraphPatternExpression(): Maybe<string>;
36
+ interfaceConstructorStatements({ variables, }: Parameters<Property<Type>["interfaceConstructorStatements"]>[0]): readonly string[];
37
+ jsonUiSchemaElement({ variables, }: Parameters<Property<Type>["jsonUiSchemaElement"]>[0]): Maybe<string>;
38
+ jsonZodSchema(parameters: Parameters<Property<Type>["jsonZodSchema"]>[0]): ReturnType<Property<Type>["jsonZodSchema"]>;
39
+ sparqlConstructTemplateTriples({ variables, }: Parameters<Property<Type>["sparqlConstructTemplateTriples"]>[0]): readonly string[];
40
+ sparqlWherePatterns({ variables, }: Parameters<Property<Type>["sparqlWherePatterns"]>[0]): readonly string[];
41
+ toJsonObjectMember(parameters: Parameters<Property<Type>["toJsonObjectMember"]>[0]): string;
23
42
  toRdfStatements({ variables, }: Parameters<Property<Type>["toRdfStatements"]>[0]): readonly string[];
24
43
  }
25
44
  //# sourceMappingURL=ShaclProperty.d.ts.map