@shaclmate/compiler 2.0.12 → 2.0.14

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 (204) 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 +165 -0
  17. package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstCompositeType.d.ts +13 -0
  18. package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstCompositeType.js +198 -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 +92 -20
  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 +17 -0
  74. package/generators/ts/DateTimeType.js +58 -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 +18 -0
  80. package/generators/ts/Import.js +59 -0
  81. package/generators/ts/ListType.d.ts +18 -8
  82. package/generators/ts/ListType.js +197 -43
  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 +47 -25
  88. package/generators/ts/ObjectType.js +222 -49
  89. package/generators/ts/ObjectUnionType.d.ts +58 -0
  90. package/generators/ts/ObjectUnionType.js +481 -0
  91. package/generators/ts/OptionType.d.ts +12 -4
  92. package/generators/ts/OptionType.js +65 -16
  93. package/generators/ts/PrimitiveType.d.ts +15 -5
  94. package/generators/ts/PrimitiveType.js +20 -29
  95. package/generators/ts/SetType.d.ts +12 -4
  96. package/generators/ts/SetType.js +103 -29
  97. package/generators/ts/StringType.d.ts +8 -3
  98. package/generators/ts/StringType.js +57 -3
  99. package/generators/ts/TermType.d.ts +52 -0
  100. package/generators/ts/TermType.js +234 -0
  101. package/generators/ts/TsGenerator.d.ts +4 -12
  102. package/generators/ts/TsGenerator.js +44 -100
  103. package/generators/ts/Type.d.ts +107 -46
  104. package/generators/ts/Type.js +78 -61
  105. package/generators/ts/TypeFactory.d.ts +4 -5
  106. package/generators/ts/TypeFactory.js +212 -89
  107. package/generators/ts/UnionType.d.ts +19 -6
  108. package/generators/ts/UnionType.js +230 -120
  109. package/generators/ts/_ObjectType/IdentifierProperty.d.ts +27 -7
  110. package/generators/ts/_ObjectType/IdentifierProperty.js +143 -31
  111. package/generators/ts/_ObjectType/Property.d.ts +125 -9
  112. package/generators/ts/_ObjectType/Property.js +25 -3
  113. package/generators/ts/_ObjectType/ShaclProperty.d.ts +23 -5
  114. package/generators/ts/_ObjectType/ShaclProperty.js +100 -26
  115. package/generators/ts/_ObjectType/TypeDiscriminatorProperty.d.ts +24 -6
  116. package/generators/ts/_ObjectType/TypeDiscriminatorProperty.js +75 -13
  117. package/generators/ts/_ObjectType/classDeclaration.d.ts +2 -1
  118. package/generators/ts/_ObjectType/classDeclaration.js +79 -111
  119. package/generators/ts/_ObjectType/createFunctionDeclaration.d.ts +5 -0
  120. package/generators/ts/_ObjectType/createFunctionDeclaration.js +60 -0
  121. package/generators/ts/_ObjectType/equalsFunctionDeclaration.d.ts +2 -1
  122. package/generators/ts/_ObjectType/equalsFunctionDeclaration.js +12 -20
  123. package/generators/ts/_ObjectType/equalsFunctionOrMethodDeclaration.d.ts +11 -0
  124. package/generators/ts/_ObjectType/equalsFunctionOrMethodDeclaration.js +70 -0
  125. package/generators/ts/_ObjectType/fromJsonFunctionDeclarations.d.ts +4 -0
  126. package/generators/ts/_ObjectType/fromJsonFunctionDeclarations.js +78 -0
  127. package/generators/ts/_ObjectType/fromRdfFunctionDeclarations.d.ts +4 -0
  128. package/generators/ts/_ObjectType/fromRdfFunctionDeclarations.js +91 -0
  129. package/generators/ts/_ObjectType/hashFunctionDeclaration.d.ts +3 -3
  130. package/generators/ts/_ObjectType/hashFunctionDeclaration.js +11 -55
  131. package/generators/ts/_ObjectType/hashFunctionOrMethodDeclaration.d.ts +11 -0
  132. package/generators/ts/_ObjectType/hashFunctionOrMethodDeclaration.js +64 -0
  133. package/generators/ts/_ObjectType/index.d.ts +8 -2
  134. package/generators/ts/_ObjectType/index.js +8 -2
  135. package/generators/ts/_ObjectType/interfaceDeclaration.d.ts +3 -2
  136. package/generators/ts/_ObjectType/interfaceDeclaration.js +11 -2
  137. package/generators/ts/_ObjectType/jsonSchemaFunctionDeclaration.d.ts +5 -0
  138. package/generators/ts/_ObjectType/jsonSchemaFunctionDeclaration.js +19 -0
  139. package/generators/ts/_ObjectType/jsonUiSchemaFunctionDeclaration.d.ts +5 -0
  140. package/generators/ts/_ObjectType/jsonUiSchemaFunctionDeclaration.js +31 -0
  141. package/generators/ts/_ObjectType/jsonZodSchemaFunctionDeclaration.d.ts +5 -0
  142. package/generators/ts/_ObjectType/jsonZodSchemaFunctionDeclaration.js +37 -0
  143. package/generators/ts/_ObjectType/rdfjsTermExpression.d.ts +6 -0
  144. package/generators/ts/{rdfjsTermExpression.js → _ObjectType/rdfjsTermExpression.js} +3 -1
  145. package/generators/ts/_ObjectType/sparqlFunctionDeclarations.d.ts +4 -0
  146. package/generators/ts/_ObjectType/sparqlFunctionDeclarations.js +101 -0
  147. package/generators/ts/_ObjectType/toJsonFunctionDeclaration.d.ts +5 -0
  148. package/generators/ts/_ObjectType/toJsonFunctionDeclaration.js +19 -0
  149. package/generators/ts/_ObjectType/toJsonFunctionOrMethodDeclaration.d.ts +10 -0
  150. package/generators/ts/_ObjectType/toJsonFunctionOrMethodDeclaration.js +59 -0
  151. package/generators/ts/_ObjectType/toJsonReturnType.d.ts +3 -0
  152. package/generators/ts/_ObjectType/toJsonReturnType.js +19 -0
  153. package/generators/ts/_ObjectType/toRdfFunctionDeclaration.d.ts +3 -2
  154. package/generators/ts/_ObjectType/toRdfFunctionDeclaration.js +11 -45
  155. package/generators/ts/_ObjectType/toRdfFunctionOrMethodDeclaration.d.ts +10 -0
  156. package/generators/ts/_ObjectType/toRdfFunctionOrMethodDeclaration.js +67 -0
  157. package/generators/ts/objectInitializer.d.ts +2 -0
  158. package/generators/ts/objectInitializer.js +14 -0
  159. package/generators/ts/tsComment.d.ts +5 -0
  160. package/generators/ts/tsComment.js +11 -0
  161. package/generators/ts/tsName.d.ts +1 -1
  162. package/generators/ts/tsName.js +1 -0
  163. package/index.d.ts +1 -1
  164. package/index.js +1 -1
  165. package/input/NodeShape.d.ts +46 -0
  166. package/input/NodeShape.js +165 -0
  167. package/input/Ontology.d.ts +13 -0
  168. package/input/Ontology.js +30 -0
  169. package/input/PropertyShape.d.ts +15 -0
  170. package/input/PropertyShape.js +34 -0
  171. package/input/Shape.d.ts +4 -0
  172. package/input/Shape.js +2 -0
  173. package/input/ShapesGraph.d.ts +9 -0
  174. package/input/ShapesGraph.js +50 -0
  175. package/input/ancestorClassIris.d.ts +4 -0
  176. package/input/ancestorClassIris.js +21 -0
  177. package/input/descendantClassIris.d.ts +4 -0
  178. package/input/descendantClassIris.js +21 -0
  179. package/input/generated.d.ts +274 -0
  180. package/input/generated.js +1420 -0
  181. package/input/index.d.ts +7 -0
  182. package/input/index.js +7 -0
  183. package/input/tsFeatures.d.ts +10 -0
  184. package/input/tsFeatures.js +42 -0
  185. package/package.json +14 -8
  186. package/ast/MintingStrategy.d.ts +0 -8
  187. package/ast/MintingStrategy.js +0 -9
  188. package/generators/ts/Configuration.d.ts +0 -29
  189. package/generators/ts/Configuration.js +0 -40
  190. package/generators/ts/IntersectionType.d.ts +0 -14
  191. package/generators/ts/IntersectionType.js +0 -26
  192. package/generators/ts/RdfjsTermType.d.ts +0 -25
  193. package/generators/ts/RdfjsTermType.js +0 -46
  194. package/generators/ts/_ObjectType/fromRdfFunctionDeclaration.d.ts +0 -4
  195. package/generators/ts/_ObjectType/fromRdfFunctionDeclaration.js +0 -72
  196. package/generators/ts/_ObjectType/sparqlGraphPatternsClassDeclaration.d.ts +0 -4
  197. package/generators/ts/_ObjectType/sparqlGraphPatternsClassDeclaration.js +0 -46
  198. package/generators/ts/rdfjsTermExpression.d.ts +0 -5
  199. package/vocabularies/dashDataset.d.ts +0 -3
  200. package/vocabularies/dashDataset.js +0 -2370
  201. package/vocabularies/index.d.ts +0 -2
  202. package/vocabularies/index.js +0 -2
  203. package/vocabularies/shaclmate.d.ts +0 -15
  204. package/vocabularies/shaclmate.js +0 -6
@@ -0,0 +1,58 @@
1
+ import { invariant } from "ts-invariant";
2
+ import * as input from "../input/index.js";
3
+ /**
4
+ * Try to convert a property shape to a type using some heuristics.
5
+ *
6
+ * We don't try to handle exotic cases allowed by the SHACL spec, such as combinations of sh:in and sh:node. Instead we assume
7
+ * a shape has one type.
8
+ */
9
+ export function transformPropertyShapeToAstType(shape, inherited) {
10
+ // Try to transform the property shape into an AST type without cardinality constraints
11
+ return this.transformPropertyShapeToAstCompositeType(shape, inherited)
12
+ .altLazy(() => this.transformPropertyShapeToAstIdentifierType(shape, inherited))
13
+ .altLazy(() => this.transformPropertyShapeToAstLiteralType(shape, inherited))
14
+ .altLazy(() => this.transformPropertyShapeToAstTermType(shape, inherited))
15
+ .map((itemType) => {
16
+ // Handle cardinality constraints
17
+ if ((shape instanceof input.PropertyShape && shape.defaultValue.isJust()) ||
18
+ inherited?.defaultValue.isJust()) {
19
+ // Ignore other cardinality constraints if there's a default value and treat the type as minCount=maxCount=1
20
+ return itemType;
21
+ }
22
+ const maxCount = shape.constraints.maxCount;
23
+ const minCount = shape.constraints.minCount;
24
+ if (maxCount.isNothing() && minCount.isNothing()) {
25
+ // The shape has no cardinality constraints
26
+ if (inherited === null) {
27
+ // The shape is top-level (not an sh:xone/sh:and of a top-level shape)
28
+ // Treat it as a Set, the default in RDF.
29
+ // We want Set to be the outermost type unless it's explicitly requested with sh:minCount 0.
30
+ return {
31
+ itemType,
32
+ kind: "SetType",
33
+ minCount: 0,
34
+ };
35
+ }
36
+ // else the shape is not top-level
37
+ // We want Set to be the outermost type, so just return the itemType here
38
+ return itemType;
39
+ }
40
+ if (minCount.orDefault(0) === 0 && maxCount.extractNullable() === 1) {
41
+ return {
42
+ itemType,
43
+ kind: "OptionType",
44
+ };
45
+ }
46
+ if (minCount.orDefault(0) === 1 && maxCount.extractNullable() === 1) {
47
+ return itemType;
48
+ }
49
+ invariant(minCount.isJust() || maxCount.isJust());
50
+ // There are cardinality constraints for a Set. It may be an inner type.
51
+ return {
52
+ itemType,
53
+ kind: "SetType",
54
+ minCount: minCount.orDefault(0),
55
+ };
56
+ });
57
+ }
58
+ //# sourceMappingURL=transformPropertyShapeToAstType.js.map
package/ast/Ast.d.ts CHANGED
@@ -1,5 +1,10 @@
1
+ import type { ObjectIntersectionType } from "./ObjectIntersectionType.js";
1
2
  import type { ObjectType } from "./ObjectType.js";
3
+ import type { ObjectUnionType } from "./ObjectUnionType.js";
2
4
  export interface Ast {
5
+ readonly objectIntersectionTypes: readonly ObjectIntersectionType[];
3
6
  readonly objectTypes: readonly ObjectType[];
7
+ readonly objectUnionTypes: readonly ObjectUnionType[];
8
+ readonly tsDataFactoryVariable: string;
4
9
  }
5
10
  //# sourceMappingURL=Ast.d.ts.map
@@ -0,0 +1,13 @@
1
+ import type { Type } from "./Type.js";
2
+ /**
3
+ * A composite of types, such as an intersection or union.
4
+ */
5
+ export interface CompositeType<MemberTypeT extends Type> {
6
+ /**
7
+ * Member types.
8
+ *
9
+ * Mutable to support cycle-handling logic in the compiler.
10
+ */
11
+ readonly memberTypes: MemberTypeT[];
12
+ }
13
+ //# sourceMappingURL=CompositeType.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=CompositeType.js.map
@@ -1,13 +1,10 @@
1
1
  import type { BlankNode, NamedNode } from "@rdfjs/types";
2
- import type { Maybe } from "purify-ts";
3
- import type { NodeKind } from "shacl-ast";
2
+ import type { TermType } from "./TermType.js";
4
3
  /**
5
4
  * A type corresponding to sh:nodeKind of a blank node or IRI, and not corresponding to a node shape.
6
5
  */
7
- export interface IdentifierType {
8
- readonly defaultValue: Maybe<BlankNode | NamedNode>;
9
- readonly hasValue: Maybe<BlankNode | NamedNode>;
6
+ export interface IdentifierType extends TermType<BlankNode | NamedNode> {
10
7
  readonly kind: "IdentifierType";
11
- readonly nodeKinds: Set<NodeKind.BLANK_NODE | NodeKind.IRI>;
8
+ readonly nodeKinds: Set<"BlankNode" | "NamedNode">;
12
9
  }
13
10
  //# sourceMappingURL=IdentifierType.d.ts.map
@@ -1,9 +1,9 @@
1
+ import type { CompositeType } from "./CompositeType.js";
1
2
  import type { Type } from "./Type.js";
2
3
  /**
3
4
  * A conjunction ("and") of types, corresponding to an sh:and.
4
5
  */
5
- export interface IntersectionType {
6
+ export interface IntersectionType extends CompositeType<Type> {
6
7
  readonly kind: "IntersectionType";
7
- readonly memberTypes: readonly Type[];
8
8
  }
9
9
  //# sourceMappingURL=IntersectionType.d.ts.map
@@ -0,0 +1,53 @@
1
+ import type { NamedNode } from "@rdfjs/types";
2
+ import type { Maybe } from "purify-ts";
3
+ import type { MintingStrategy } from "../enums/MintingStrategy.js";
4
+ import type { Name } from "./Name.js";
5
+ import type { Type } from "./Type.js";
6
+ /**
7
+ * An ordered sequence of items with zero or one values of an item type.
8
+ *
9
+ * ListType is transformed from a SHACL node shape that models an RDF list (https://www.w3.org/TR/rdf11-schema/#ch_collectionvocab).
10
+ *
11
+ * Contrast SetType, which is transformed from any SHACL property shape with no maxCount or maxCount greater than 1.
12
+ */
13
+ export interface ListType {
14
+ /**
15
+ * Documentation comment from rdfs:comment.
16
+ */
17
+ readonly comment: Maybe<string>;
18
+ /**
19
+ * Type of identifier (blank or named node) to use for lists and sub-lists.
20
+ */
21
+ readonly identifierNodeKind: "BlankNode" | "NamedNode";
22
+ /**
23
+ * List item type.
24
+ *
25
+ * Mutable to support cycle-handling logic in the compiler.
26
+ */
27
+ itemType: Type;
28
+ readonly kind: "ListType";
29
+ /**
30
+ * Human-readable label from rdfs:label.
31
+ */
32
+ readonly label: Maybe<string>;
33
+ /**
34
+ * Strategy for minting new list and sub-list identifiers.
35
+ */
36
+ readonly mintingStrategy: Maybe<MintingStrategy>;
37
+ /**
38
+ * The list should be mutable in generated code.
39
+ */
40
+ readonly mutable: Maybe<boolean>;
41
+ /**
42
+ * Name of this type, usually derived from sh:name or shaclmate:name.
43
+ */
44
+ readonly name: Name;
45
+ /**
46
+ * rdf:type's that will be added to this object when it's serialized toRdf.
47
+ *
48
+ * This is usually the identifier of an sh:NodeShape that is also an rdfs:Class (i.e., a node shape with implicit
49
+ * class targets).
50
+ */
51
+ readonly toRdfTypes: readonly NamedNode[];
52
+ }
53
+ //# sourceMappingURL=ListType.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=ListType.js.map
@@ -1,13 +1,14 @@
1
1
  import type { Literal, NamedNode } from "@rdfjs/types";
2
2
  import type { Maybe } from "purify-ts";
3
- export interface LiteralType {
3
+ import type { TermType } from "./TermType.js";
4
+ export interface LiteralType extends TermType<Literal> {
4
5
  readonly datatype: Maybe<NamedNode>;
5
- readonly defaultValue: Maybe<Literal>;
6
- readonly hasValue: Maybe<Literal>;
7
6
  readonly kind: "LiteralType";
7
+ readonly languageIn: readonly string[];
8
8
  readonly maxExclusive: Maybe<Literal>;
9
9
  readonly maxInclusive: Maybe<Literal>;
10
10
  readonly minExclusive: Maybe<Literal>;
11
11
  readonly minInclusive: Maybe<Literal>;
12
+ readonly nodeKinds: Set<"Literal">;
12
13
  }
13
14
  //# sourceMappingURL=LiteralType.d.ts.map
package/ast/Name.d.ts CHANGED
@@ -3,6 +3,7 @@ import type { Maybe } from "purify-ts";
3
3
  export interface Name {
4
4
  readonly curie: Maybe<string>;
5
5
  readonly identifier: BlankNode | NamedNode;
6
+ readonly label: Maybe<string>;
6
7
  readonly propertyPath: Maybe<{
7
8
  curie: Maybe<string>;
8
9
  identifier: NamedNode;
@@ -0,0 +1,22 @@
1
+ import type { Maybe } from "purify-ts";
2
+ import type { CompositeType } from "./CompositeType.js";
3
+ import type { Name } from "./Name.js";
4
+ import type { ObjectType } from "./ObjectType.js";
5
+ /**
6
+ * A composite of object types, such as an intersection or union.
7
+ */
8
+ export interface ObjectCompositeType extends CompositeType<ObjectType> {
9
+ /**
10
+ * Documentation comment from rdfs:comment.
11
+ */
12
+ readonly comment: Maybe<string>;
13
+ /**
14
+ * Human-readable label from rdfs:label.
15
+ */
16
+ readonly label: Maybe<string>;
17
+ /**
18
+ * Name of this type, usually derived from sh:name or shaclmate:name.
19
+ */
20
+ readonly name: Name;
21
+ }
22
+ //# sourceMappingURL=ObjectCompositeType.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=ObjectCompositeType.js.map
@@ -0,0 +1,8 @@
1
+ import type { ObjectCompositeType } from "./ObjectCompositeType.js";
2
+ /**
3
+ * A conjunction/intersection of object types, corresponding to an sh:and on a node shape.
4
+ */
5
+ export interface ObjectIntersectionType extends ObjectCompositeType {
6
+ readonly kind: "ObjectIntersectionType";
7
+ }
8
+ //# sourceMappingURL=ObjectIntersectionType.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=ObjectIntersectionType.js.map
@@ -1,9 +1,9 @@
1
1
  import type { NamedNode } from "@rdfjs/types";
2
+ import type { PredicatePath } from "@shaclmate/shacl-ast";
2
3
  import type { Maybe } from "purify-ts";
3
- import type { NodeKind } from "shacl-ast";
4
- import type { PredicatePath } from "shacl-ast";
5
- import type { Name, Type } from ".";
6
- import type { MintingStrategy } from "./MintingStrategy";
4
+ import type { MintingStrategy, PropertyVisibility, TsFeature, TsObjectDeclarationType } from "../enums/index.js";
5
+ import type { Name } from "./Name.js";
6
+ import type { Type } from "./Type.js";
7
7
  export interface ObjectType {
8
8
  /**
9
9
  * Classes generated from this type are abstract / cannot be instantiated themselves.
@@ -14,19 +14,23 @@ export interface ObjectType {
14
14
  /**
15
15
  * Ancestor (parents, their parents, ad nauseum) ObjectTypes of this ObjectType.
16
16
  *
17
- * Mutable to support cycle-handling logic in the transformer.
17
+ * Mutable to support cycle-handling logic in the compiler.
18
18
  */
19
19
  readonly ancestorObjectTypes: ObjectType[];
20
20
  /**
21
21
  * Immediate child ObjectTypes of this ObjectType.
22
22
  *
23
- * Mutable to support cycle-handling logic in the transformer.
23
+ * Mutable to support cycle-handling logic in the compiler.
24
24
  */
25
25
  readonly childObjectTypes: ObjectType[];
26
+ /**
27
+ * Documentation comment from rdfs:comment.
28
+ */
29
+ readonly comment: Maybe<string>;
26
30
  /**
27
31
  * Descendant (children, their children, ad nauseum) ObjectTypes of this ObjectType.
28
32
  *
29
- * Mutable to support cycle-handling logic in the transformer.
33
+ * Mutable to support cycle-handling logic in the compiler.
30
34
  */
31
35
  readonly descendantObjectTypes: ObjectType[];
32
36
  /**
@@ -35,20 +39,33 @@ export interface ObjectType {
35
39
  * Defaults to true.
36
40
  */
37
41
  readonly export: boolean;
38
- readonly kind: "ObjectType";
39
42
  /**
40
- * If the ObjectType is an RDF list, this is the type of rdf:first.
41
- * https://www.w3.org/TR/rdf-schema/#ch_collectionvocab
43
+ * If true, the code for this ObjectType is defined externally and should not be generated.
44
+ *
45
+ * Defaults to false.
46
+ */
47
+ readonly extern: boolean;
48
+ /**
49
+ * The expected rdf:type of instances of this ObjectType.
42
50
  *
43
- * Mutable to support cycle-handling logic in the transformer.
51
+ * This is usually the identifier of an sh:NodeShape that is also an rdfs:Class (i.e., a node shape with implicit
52
+ * class targets).
53
+ */
54
+ readonly fromRdfType: Maybe<NamedNode>;
55
+ /**
56
+ * Type discriminator.
57
+ */
58
+ readonly kind: "ObjectType";
59
+ /**
60
+ * Human-readable label from rdfs:label.
44
61
  */
45
- listItemType: Maybe<Type>;
62
+ readonly label: Maybe<string>;
46
63
  /**
47
- * Strategy for minting new object identifiers. If not specified, require an identifier on construction.
64
+ * Strategy for minting new object identifiers.
48
65
  */
49
66
  readonly mintingStrategy: Maybe<MintingStrategy>;
50
67
  /**
51
- * Name of this ObjectType, usually derived from sh:name or shaclmate:name.
68
+ * Name of this type, usually derived from sh:name or shaclmate:name.
52
69
  */
53
70
  readonly name: Name;
54
71
  /**
@@ -56,33 +73,88 @@ export interface ObjectType {
56
73
  *
57
74
  * Used to associate instances with an RDF identifier.
58
75
  */
59
- readonly nodeKinds: Set<NodeKind.BLANK_NODE | NodeKind.IRI>;
76
+ readonly nodeKinds: Set<"BlankNode" | "NamedNode">;
60
77
  /**
61
78
  * Immediate parent ObjectTypes of this Object types.
62
79
  *
63
- * Mutable to support cycle-handling logic in the transformer.
80
+ * Mutable to support cycle-handling logic in the compiler.
64
81
  */
65
82
  readonly parentObjectTypes: ObjectType[];
66
83
  /**
67
84
  * Properties of this ObjectType.
68
85
  *
69
- * Mutable to support cycle-handling logic in the transformer.
86
+ * Mutable to support cycle-handling logic in the compiler.
70
87
  */
71
88
  readonly properties: ObjectType.Property[];
72
89
  /**
73
- * The expected rdf:type of instances of this ObjectType.
90
+ * rdf:type's that will be added to this object when it's serialized toRdf.
74
91
  *
75
92
  * This is usually the identifier of an sh:NodeShape that is also an rdfs:Class (i.e., a node shape with implicit
76
93
  * class targets).
77
94
  */
78
- readonly rdfType: Maybe<NamedNode>;
95
+ readonly toRdfTypes: readonly NamedNode[];
96
+ /**
97
+ * TypeScript features to generate.
98
+ */
99
+ readonly tsFeatures: Set<TsFeature>;
100
+ /**
101
+ * Name of the identifier property in TypeScript-generated classes/interfaces.
102
+ */
103
+ readonly tsIdentifierPropertyName: string;
104
+ /**
105
+ * TypeScript imports to add to generated code.
106
+ *
107
+ * This is often used in conjunction with extern=true to import the extern'd ObjectType code in order for generated
108
+ * code to reference it.
109
+ *
110
+ * import { MyType } from "./MyType.js"
111
+ */
112
+ readonly tsImports: readonly string[];
113
+ /**
114
+ * Whether to generate a TypeScript class or interface for this type.
115
+ */
116
+ readonly tsObjectDeclarationType: TsObjectDeclarationType;
117
+ /**
118
+ * Name of the type discriminator property in TypeScript-generated classes/interfaces.
119
+ */
120
+ readonly tsTypeDiscriminatorPropertyName: string;
79
121
  }
80
122
  export declare namespace ObjectType {
81
123
  interface Property {
82
- readonly inline: boolean;
124
+ /**
125
+ * Documentation comment from rdfs:comment.
126
+ */
127
+ readonly comment: Maybe<string>;
128
+ /**
129
+ * Description from sh:description.
130
+ */
131
+ readonly description: Maybe<string>;
132
+ /**
133
+ * Human-readable label from rdfs:label.
134
+ */
135
+ readonly label: Maybe<string>;
136
+ /**
137
+ * The property should be mutable in generated code i.e., it should be re-assignable. The property value may or may
138
+ * not be mutable.
139
+ */
140
+ readonly mutable: Maybe<boolean>;
141
+ /**
142
+ * Name of this property.
143
+ */
83
144
  readonly name: Name;
145
+ /**
146
+ * SHACL property path (https://www.w3.org/TR/shacl/#property-paths)
147
+ */
84
148
  readonly path: PredicatePath;
149
+ /**
150
+ * Type of this property.
151
+ */
85
152
  readonly type: Type;
153
+ /**
154
+ * Visibility: private, protected, public.
155
+ */
156
+ readonly visibility: PropertyVisibility;
86
157
  }
158
+ function toposort(objectTypes: readonly ObjectType[]): readonly ObjectType[];
87
159
  }
88
160
  //# sourceMappingURL=ObjectType.d.ts.map
package/ast/ObjectType.js CHANGED
@@ -1,2 +1,27 @@
1
- export {};
1
+ import { Resource } from "rdfjs-resource";
2
+ import genericToposort from "toposort";
3
+ export var ObjectType;
4
+ (function (ObjectType) {
5
+ function toposort(objectTypes) {
6
+ const objectTypesByIdentifier = {};
7
+ const objectTypeGraphNodes = [];
8
+ const objectTypeGraphEdges = [];
9
+ for (const objectType of objectTypes) {
10
+ const objectTypeIdentifier = Resource.Identifier.toString(objectType.name.identifier);
11
+ objectTypesByIdentifier[objectTypeIdentifier] = objectType;
12
+ objectTypeGraphNodes.push(objectTypeIdentifier);
13
+ for (const parentAstObjectType of objectType.parentObjectTypes) {
14
+ objectTypeGraphEdges.push([
15
+ objectTypeIdentifier,
16
+ Resource.Identifier.toString(parentAstObjectType.name.identifier),
17
+ ]);
18
+ }
19
+ }
20
+ return genericToposort
21
+ .array(objectTypeGraphNodes, objectTypeGraphEdges)
22
+ .map((objectTypeIdentifier) => objectTypesByIdentifier[objectTypeIdentifier])
23
+ .reverse();
24
+ }
25
+ ObjectType.toposort = toposort;
26
+ })(ObjectType || (ObjectType = {}));
2
27
  //# sourceMappingURL=ObjectType.js.map
@@ -0,0 +1,19 @@
1
+ import type { TsFeature } from "../enums/index.js";
2
+ import type { ObjectCompositeType } from "./ObjectCompositeType.js";
3
+ /**
4
+ * A disjunction/union of object types, corresponding to an sh:xone on a node shape.
5
+ */
6
+ export interface ObjectUnionType extends ObjectCompositeType {
7
+ /**
8
+ * Should generated code derived from this ObjectType be visible outside its module?
9
+ *
10
+ * Defaults to true.
11
+ */
12
+ readonly export: boolean;
13
+ readonly kind: "ObjectUnionType";
14
+ /**
15
+ * TypeScript features to generate.
16
+ */
17
+ readonly tsFeatures: Set<TsFeature>;
18
+ }
19
+ //# sourceMappingURL=ObjectUnionType.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=ObjectUnionType.js.map
@@ -0,0 +1,7 @@
1
+ /**
2
+ * A placeholder used temporarily when a type is being resolved.
3
+ */
4
+ export interface PlaceholderType {
5
+ kind: "PlaceholderType";
6
+ }
7
+ //# sourceMappingURL=PlaceholderType.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=PlaceholderType.js.map
package/ast/SetType.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { Type } from "./Type.js";
2
2
  /**
3
- * A set of items of a specific type.
3
+ * An unordered set of items of a specific type.
4
4
  *
5
5
  * This is a property with sh:maxCount != 1.
6
6
  */
@@ -0,0 +1,11 @@
1
+ import type { BlankNode, Literal, NamedNode } from "@rdfjs/types";
2
+ import type { NodeKind } from "@shaclmate/shacl-ast";
3
+ import type { Maybe } from "purify-ts";
4
+ export interface TermType<TermT extends BlankNode | Literal | NamedNode> {
5
+ readonly defaultValue: Maybe<TermT>;
6
+ readonly hasValues: readonly TermT[];
7
+ readonly in_: readonly TermT[];
8
+ readonly kind: "IdentifierType" | "LiteralType" | "TermType";
9
+ readonly nodeKinds: Set<NodeKind>;
10
+ }
11
+ //# sourceMappingURL=TermType.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=TermType.js.map
package/ast/Type.d.ts CHANGED
@@ -1,9 +1,17 @@
1
+ import type { BlankNode, Literal, NamedNode } from "@rdfjs/types";
1
2
  import type { IdentifierType } from "./IdentifierType.js";
2
3
  import type { IntersectionType } from "./IntersectionType.js";
4
+ import type { ListType } from "./ListType.js";
3
5
  import type { LiteralType } from "./LiteralType.js";
6
+ import type { ObjectIntersectionType } from "./ObjectIntersectionType.js";
4
7
  import type { ObjectType } from "./ObjectType.js";
5
- import type { OptionType } from "./OptionType";
6
- import type { SetType } from "./SetType";
8
+ import type { ObjectUnionType } from "./ObjectUnionType.js";
9
+ import type { OptionType } from "./OptionType.js";
10
+ import type { PlaceholderType } from "./PlaceholderType.js";
11
+ import type { SetType } from "./SetType.js";
12
+ import type { TermType } from "./TermType.js";
7
13
  import type { UnionType } from "./UnionType.js";
8
- export type Type = IdentifierType | IntersectionType | LiteralType | ObjectType | OptionType | SetType | UnionType;
14
+ export type Type = IdentifierType | IntersectionType | ListType | LiteralType | ObjectIntersectionType | ObjectType | ObjectUnionType | OptionType | PlaceholderType | SetType | (Omit<TermType<BlankNode | Literal | NamedNode>, "kind"> & {
15
+ readonly kind: "TermType";
16
+ }) | UnionType;
9
17
  //# sourceMappingURL=Type.d.ts.map
@@ -1,9 +1,9 @@
1
+ import type { CompositeType } from "./CompositeType.js";
1
2
  import type { Type } from "./Type.js";
2
3
  /**
3
- * A disjunction/union of types, corresponding to an sh:or.
4
+ * A disjunction/union of types, corresponding to an sh:xone.
4
5
  */
5
- export interface UnionType {
6
+ export interface UnionType extends CompositeType<Type> {
6
7
  readonly kind: "UnionType";
7
- readonly memberTypes: readonly Type[];
8
8
  }
9
9
  //# sourceMappingURL=UnionType.d.ts.map
package/ast/index.d.ts CHANGED
@@ -1,10 +1,13 @@
1
1
  export * from "./Ast.js";
2
2
  export * from "./IdentifierType.js";
3
- export * from "./IntersectionType";
3
+ export * from "./IntersectionType.js";
4
+ export * from "./ListType.js";
4
5
  export * from "./LiteralType.js";
5
- export * from "./MintingStrategy.js";
6
6
  export * from "./Name.js";
7
+ export * from "./ObjectIntersectionType.js";
7
8
  export * from "./ObjectType.js";
8
- export * from "./UnionType";
9
+ export * from "./ObjectUnionType.js";
10
+ export * from "./UnionType.js";
11
+ export * from "./TermType.js";
9
12
  export * from "./Type.js";
10
13
  //# sourceMappingURL=index.d.ts.map
package/ast/index.js CHANGED
@@ -1,10 +1,13 @@
1
1
  export * from "./Ast.js";
2
2
  export * from "./IdentifierType.js";
3
- export * from "./IntersectionType";
3
+ export * from "./IntersectionType.js";
4
+ export * from "./ListType.js";
4
5
  export * from "./LiteralType.js";
5
- export * from "./MintingStrategy.js";
6
6
  export * from "./Name.js";
7
+ export * from "./ObjectIntersectionType.js";
7
8
  export * from "./ObjectType.js";
8
- export * from "./UnionType";
9
+ export * from "./ObjectUnionType.js";
10
+ export * from "./UnionType.js";
11
+ export * from "./TermType.js";
9
12
  export * from "./Type.js";
10
13
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,5 @@
1
+ /**
2
+ * TypeScript enum corresponding to shaclmate:mintingStrategy, for simpler manipulation.
3
+ */
4
+ export type MintingStrategy = "sha256" | "uuidv4";
5
+ //# sourceMappingURL=MintingStrategy.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=MintingStrategy.js.map
@@ -0,0 +1,2 @@
1
+ export type PropertyVisibility = "private" | "protected" | "public";
2
+ //# sourceMappingURL=PropertyVisibility.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=PropertyVisibility.js.map
@@ -0,0 +1,5 @@
1
+ export type TsFeature = "create" | "equals" | "fromJson" | "fromRdf" | "hash" | "jsonSchema" | "jsonUiSchema" | "sparql" | "toJson" | "toRdf";
2
+ export declare namespace TsFeature {
3
+ const MEMBERS: readonly TsFeature[];
4
+ }
5
+ //# sourceMappingURL=TsFeature.d.ts.map
@@ -0,0 +1,16 @@
1
+ export var TsFeature;
2
+ (function (TsFeature) {
3
+ TsFeature.MEMBERS = [
4
+ "create",
5
+ "equals",
6
+ "fromJson",
7
+ "fromRdf",
8
+ "hash",
9
+ "jsonSchema",
10
+ "jsonUiSchema",
11
+ "sparql",
12
+ "toJson",
13
+ "toRdf",
14
+ ];
15
+ })(TsFeature || (TsFeature = {}));
16
+ //# sourceMappingURL=TsFeature.js.map
@@ -0,0 +1,5 @@
1
+ /**
2
+ * TypeScript enum corresponding to shaclmate:tsObjectDeclarationType, for simpler manipulation.
3
+ */
4
+ export type TsObjectDeclarationType = "class" | "interface";
5
+ //# sourceMappingURL=TsObjectDeclarationType.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=TsObjectDeclarationType.js.map
@@ -0,0 +1,5 @@
1
+ export * from "./MintingStrategy.js";
2
+ export * from "./PropertyVisibility.js";
3
+ export * from "./TsFeature.js";
4
+ export * from "./TsObjectDeclarationType.js";
5
+ //# sourceMappingURL=index.d.ts.map