@shaclmate/compiler 2.0.13 → 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 +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 +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,5 @@
1
+ import type { ShapesGraphToAstTransformer } from "../ShapesGraphToAstTransformer.js";
2
+ import type * as ast from "../ast/index.js";
3
+ import * as input from "../input/index.js";
4
+ export declare function shapeAstName(this: ShapesGraphToAstTransformer, shape: input.Shape): ast.Name;
5
+ //# sourceMappingURL=shapeAstName.d.ts.map
@@ -0,0 +1,28 @@
1
+ import { Maybe } from "purify-ts";
2
+ import * as input from "../input/index.js";
3
+ import { pickLiteral } from "./pickLiteral.js";
4
+ export function shapeAstName(shape) {
5
+ let propertyPath = Maybe.empty();
6
+ let shName = Maybe.empty();
7
+ if (shape instanceof input.PropertyShape) {
8
+ if (shape.path.kind === "PredicatePath") {
9
+ const pathIri = shape.path.iri;
10
+ propertyPath = Maybe.of({
11
+ curie: Maybe.fromNullable(this.iriPrefixMap.shrink(pathIri)?.value),
12
+ identifier: pathIri,
13
+ });
14
+ }
15
+ shName = pickLiteral(shape.names).map((literal) => literal.value);
16
+ }
17
+ return {
18
+ curie: shape.identifier.termType === "NamedNode"
19
+ ? Maybe.fromNullable(this.iriPrefixMap.shrink(shape.identifier)?.value)
20
+ : Maybe.empty(),
21
+ identifier: shape.identifier,
22
+ label: pickLiteral(shape.labels).map((literal) => literal.value),
23
+ propertyPath,
24
+ shName: shName,
25
+ shaclmateName: shape.shaclmateName,
26
+ };
27
+ }
28
+ //# sourceMappingURL=shapeAstName.js.map
@@ -0,0 +1,6 @@
1
+ import { Either } from "purify-ts";
2
+ import type { ShapesGraphToAstTransformer } from "../ShapesGraphToAstTransformer.js";
3
+ import * as input from "../input/index.js";
4
+ import type { NodeShapeAstType } from "./NodeShapeAstType.js";
5
+ export declare function transformNodeShapeToAstType(this: ShapesGraphToAstTransformer, nodeShape: input.NodeShape): Either<Error, NodeShapeAstType>;
6
+ //# sourceMappingURL=transformNodeShapeToAstType.d.ts.map
@@ -0,0 +1,165 @@
1
+ import { rdf } from "@tpluscode/rdf-ns-builders";
2
+ import { Either, Left } from "purify-ts";
3
+ import { invariant } from "ts-invariant";
4
+ import { TsFeature } from "../enums/TsFeature.js";
5
+ import * as input from "../input/index.js";
6
+ import { logger } from "../logger.js";
7
+ import { pickLiteral } from "./pickLiteral.js";
8
+ /**
9
+ * Is an ast.ObjectType actually the shape of an RDF list?
10
+ * If so, return the type of its rdf:first.
11
+ */
12
+ function transformNodeShapeToListType(nodeShape) {
13
+ invariant(nodeShape.isList);
14
+ // Put a placeholder in the cache to deal with cyclic references
15
+ const listType = {
16
+ comment: pickLiteral(nodeShape.comments).map((literal) => literal.value),
17
+ identifierNodeKind: nodeShape.nodeKinds.has("BlankNode")
18
+ ? "BlankNode"
19
+ : "NamedNode",
20
+ itemType: {
21
+ kind: "PlaceholderType",
22
+ },
23
+ kind: "ListType",
24
+ label: pickLiteral(nodeShape.labels).map((literal) => literal.value),
25
+ mutable: nodeShape.mutable,
26
+ name: this.shapeAstName(nodeShape),
27
+ mintingStrategy: nodeShape.mintingStrategy,
28
+ toRdfTypes: nodeShape.toRdfTypes,
29
+ };
30
+ this.nodeShapeAstTypesByIdentifier.set(nodeShape.identifier, listType);
31
+ const properties = [];
32
+ for (const propertyShape of nodeShape.constraints.properties) {
33
+ const propertyEither = this.transformPropertyShapeToAstObjectTypeProperty(propertyShape);
34
+ if (propertyEither.isLeft()) {
35
+ logger.warn("error transforming %s %s: %s", nodeShape, propertyShape, propertyEither.extract().message);
36
+ continue;
37
+ // return property;
38
+ }
39
+ properties.push(propertyEither.unsafeCoerce());
40
+ }
41
+ if (properties.length !== 2) {
42
+ return Left(new Error(`${nodeShape} does not have exactly two properties`));
43
+ }
44
+ // rdf:first can have any type
45
+ // The type of the rdf:first property is the list item type.
46
+ const firstProperty = properties.find((property) => property.path.iri.equals(rdf.first));
47
+ if (!firstProperty) {
48
+ return Left(new Error(`${nodeShape} does not have an rdf:first property`));
49
+ }
50
+ const restProperty = properties.find((property) => property.path.iri.equals(rdf.rest));
51
+ if (!restProperty) {
52
+ return Left(new Error(`${nodeShape} does not have an rdf:rest property`));
53
+ }
54
+ if (restProperty.type.kind !== "UnionType") {
55
+ return Left(new Error(`${nodeShape} rdf:rest property is not sh:xone`));
56
+ }
57
+ if (restProperty.type.memberTypes.length !== 2) {
58
+ return Left(new Error(`${nodeShape} rdf:rest property sh:xone does not have exactly two member types`));
59
+ }
60
+ // rdf:rest should be sh:xone ( [ sh:class nodeShape ] [ sh:hasValue rdf:nil ] )
61
+ if (!restProperty.type.memberTypes.find((type) => type.kind === "ListType" &&
62
+ type.name.identifier.equals(nodeShape.identifier))) {
63
+ return Left(new Error(`${nodeShape} rdf:rest property sh:xone is not recursive into the node shape`));
64
+ }
65
+ if (!restProperty.type.memberTypes.find((type) => type.kind === "IdentifierType")) {
66
+ return Left(new Error(`${nodeShape} rdf:rest property sh:xone does not include sh:hasValue rdf:nil`));
67
+ }
68
+ listType.itemType = firstProperty.type;
69
+ return Either.of(listType);
70
+ }
71
+ export function transformNodeShapeToAstType(nodeShape) {
72
+ {
73
+ const type = this.nodeShapeAstTypesByIdentifier.get(nodeShape.identifier);
74
+ if (type) {
75
+ return Either.of(type);
76
+ }
77
+ }
78
+ if (nodeShape.isList) {
79
+ return transformNodeShapeToListType.bind(this)(nodeShape);
80
+ }
81
+ const export_ = nodeShape.export.orDefault(true);
82
+ if (nodeShape.constraints.and.length > 0 ||
83
+ nodeShape.constraints.xone.length > 0) {
84
+ let compositeTypeShapes;
85
+ let compositeTypeKind;
86
+ if (nodeShape.constraints.and.length > 0) {
87
+ compositeTypeShapes = nodeShape.constraints.and;
88
+ compositeTypeKind = "ObjectIntersectionType";
89
+ }
90
+ else {
91
+ compositeTypeShapes = nodeShape.constraints.xone;
92
+ compositeTypeKind = "ObjectUnionType";
93
+ }
94
+ const compositeTypeNodeShapes = compositeTypeShapes.filter((shape) => shape instanceof input.NodeShape);
95
+ if (compositeTypeNodeShapes.length === 0) {
96
+ return Left(new Error(`${nodeShape} has no node shapes in its logical constraint`));
97
+ }
98
+ // Put a placeholder in the cache to deal with cyclic references
99
+ const compositeType = {
100
+ comment: pickLiteral(nodeShape.comments).map((literal) => literal.value),
101
+ export: export_,
102
+ kind: compositeTypeKind,
103
+ label: pickLiteral(nodeShape.labels).map((literal) => literal.value),
104
+ memberTypes: [],
105
+ name: this.shapeAstName(nodeShape),
106
+ tsFeatures: nodeShape.tsFeatures.orDefault(new Set(TsFeature.MEMBERS)),
107
+ };
108
+ this.nodeShapeAstTypesByIdentifier.set(nodeShape.identifier, compositeType);
109
+ compositeType.memberTypes.push(...Either.rights(compositeTypeNodeShapes.map((nodeShape) => this.transformNodeShapeToAstType(nodeShape))).filter((nodeShapeAstType) => nodeShapeAstType.kind === "ObjectType"));
110
+ if (compositeType.memberTypes.length < compositeTypeNodeShapes.length) {
111
+ return Left(new Error(`${nodeShape} has one or more non-ObjectType node shapes in its logical constraint`));
112
+ }
113
+ return Either.of(compositeType);
114
+ }
115
+ // Put a placeholder in the cache to deal with cyclic references
116
+ // If this node shape's properties (directly or indirectly) refer to the node shape itself,
117
+ // we'll return this placeholder.
118
+ const objectType = {
119
+ abstract: nodeShape.abstract.orDefault(false),
120
+ ancestorObjectTypes: [],
121
+ childObjectTypes: [],
122
+ comment: pickLiteral(nodeShape.comments).map((literal) => literal.value),
123
+ descendantObjectTypes: [],
124
+ export: export_,
125
+ extern: nodeShape.extern.orDefault(false),
126
+ fromRdfType: nodeShape.fromRdfType,
127
+ label: pickLiteral(nodeShape.labels).map((literal) => literal.value),
128
+ kind: "ObjectType",
129
+ mintingStrategy: nodeShape.mintingStrategy,
130
+ name: this.shapeAstName(nodeShape),
131
+ nodeKinds: nodeShape.nodeKinds,
132
+ properties: [], // This is mutable, we'll populate it below.
133
+ parentObjectTypes: [], // This is mutable, we'll populate it below
134
+ toRdfTypes: nodeShape.toRdfTypes,
135
+ tsFeatures: nodeShape.tsFeatures.orDefault(new Set(TsFeature.MEMBERS)),
136
+ tsIdentifierPropertyName: nodeShape.tsObjectIdentifierPropertyName.orDefault("identifier"),
137
+ tsImports: nodeShape.tsImports,
138
+ tsObjectDeclarationType: nodeShape.tsObjectDeclarationType.orDefault("class"),
139
+ tsTypeDiscriminatorPropertyName: nodeShape.tsObjectTypeDiscriminatorPropertyName.orDefault("type"),
140
+ };
141
+ this.nodeShapeAstTypesByIdentifier.set(nodeShape.identifier, objectType);
142
+ // Populate ancestor and descendant object types
143
+ const relatedObjectTypes = (relatedNodeShapes) => {
144
+ return relatedNodeShapes.flatMap((relatedNodeShape) => this.transformNodeShapeToAstType(relatedNodeShape)
145
+ .toMaybe()
146
+ .filter((astType) => astType.kind === "ObjectType")
147
+ .toList());
148
+ };
149
+ objectType.ancestorObjectTypes.push(...relatedObjectTypes(nodeShape.ancestorNodeShapes));
150
+ objectType.childObjectTypes.push(...relatedObjectTypes(nodeShape.childNodeShapes));
151
+ objectType.descendantObjectTypes.push(...relatedObjectTypes(nodeShape.descendantNodeShapes));
152
+ objectType.parentObjectTypes.push(...relatedObjectTypes(nodeShape.parentNodeShapes));
153
+ // Populate properties
154
+ for (const propertyShape of nodeShape.constraints.properties) {
155
+ const propertyEither = this.transformPropertyShapeToAstObjectTypeProperty(propertyShape);
156
+ if (propertyEither.isLeft()) {
157
+ logger.warn("error transforming %s %s: %s", nodeShape, propertyShape, propertyEither.extract().message);
158
+ continue;
159
+ // return property;
160
+ }
161
+ objectType.properties.push(propertyEither.unsafeCoerce());
162
+ }
163
+ return Either.of(objectType);
164
+ }
165
+ //# sourceMappingURL=transformNodeShapeToAstType.js.map
@@ -0,0 +1,13 @@
1
+ import type { BlankNode, Literal, NamedNode } from "@rdfjs/types";
2
+ import { Either, Maybe } from "purify-ts";
3
+ import type { ShapesGraphToAstTransformer } from "../ShapesGraphToAstTransformer.js";
4
+ import type * as ast from "../ast/index.js";
5
+ import * as input from "../input/index.js";
6
+ /**
7
+ * Try to convert a property shape to a composite type (intersection or union) using some heuristics.
8
+ */
9
+ export declare function transformPropertyShapeToAstCompositeType(this: ShapesGraphToAstTransformer, shape: input.Shape, inherited: {
10
+ defaultValue: Maybe<BlankNode | Literal | NamedNode>;
11
+ extern: Maybe<boolean>;
12
+ } | null): Either<Error, ast.Type>;
13
+ //# sourceMappingURL=transformPropertyShapeToAstCompositeType.d.ts.map
@@ -0,0 +1,198 @@
1
+ import { owl, rdfs } from "@tpluscode/rdf-ns-builders";
2
+ import { Either, Left, Maybe } from "purify-ts";
3
+ import { invariant } from "ts-invariant";
4
+ import * as input from "../input/index.js";
5
+ import { logger } from "../logger.js";
6
+ /**
7
+ * Try to convert a property shape to a composite type (intersection or union) using some heuristics.
8
+ */
9
+ export function transformPropertyShapeToAstCompositeType(shape, inherited) {
10
+ const defaultValue = (shape instanceof input.PropertyShape ? shape.defaultValue : Maybe.empty()).alt(inherited !== null ? inherited.defaultValue : Maybe.empty());
11
+ const hasValues = shape.constraints.hasValues;
12
+ const extern = shape.extern.alt(inherited !== null ? inherited.extern : Maybe.empty());
13
+ let memberTypeEithers;
14
+ let compositeTypeKind;
15
+ const transformNodeShapeToAstCompositeMemberType = (nodeShape) => {
16
+ const astTypeEither = this.transformNodeShapeToAstType(nodeShape);
17
+ if (astTypeEither.isLeft()) {
18
+ return astTypeEither;
19
+ }
20
+ const astType = astTypeEither.unsafeCoerce();
21
+ if (extern.orDefault(false)) {
22
+ // Use the identifier type instead
23
+ let nodeKinds;
24
+ switch (astType.kind) {
25
+ case "ListType":
26
+ nodeKinds = new Set();
27
+ nodeKinds.add(astType.identifierNodeKind);
28
+ break;
29
+ case "ObjectType":
30
+ nodeKinds = astType.nodeKinds;
31
+ break;
32
+ case "ObjectIntersectionType":
33
+ case "ObjectUnionType":
34
+ nodeKinds = new Set();
35
+ for (const memberType of astType.memberTypes) {
36
+ for (const nodeKind of memberType.nodeKinds) {
37
+ nodeKinds.add(nodeKind);
38
+ }
39
+ }
40
+ }
41
+ return Either.of({
42
+ defaultValue: defaultValue.filter((term) => term.termType === "NamedNode"),
43
+ hasValues: [],
44
+ in_: [],
45
+ kind: "IdentifierType",
46
+ nodeKinds,
47
+ });
48
+ }
49
+ // Not extern, use the type
50
+ return Either.of(astType);
51
+ };
52
+ if (shape.constraints.and.length > 0) {
53
+ memberTypeEithers = shape.constraints.and.map((memberShape) => this.transformPropertyShapeToAstType(memberShape, {
54
+ defaultValue,
55
+ extern: extern,
56
+ }));
57
+ compositeTypeKind = "IntersectionType";
58
+ }
59
+ else if (shape.constraints.classes.length > 0) {
60
+ memberTypeEithers = shape.constraints.classes.map((classIri) => {
61
+ if (classIri.equals(owl.Class) ||
62
+ classIri.equals(owl.Thing) ||
63
+ classIri.equals(rdfs.Class)) {
64
+ return Left(new Error(`class ${classIri.value} is not transformable`));
65
+ }
66
+ const classNodeShape = this.shapesGraph
67
+ .nodeShapeByIdentifier(classIri)
68
+ .extractNullable();
69
+ if (classNodeShape === null) {
70
+ return Left(new Error(`class ${classIri.value} did not resolve to a node shape`));
71
+ }
72
+ return transformNodeShapeToAstCompositeMemberType(classNodeShape);
73
+ });
74
+ compositeTypeKind = "IntersectionType";
75
+ if (Either.rights(memberTypeEithers).length === 0) {
76
+ // This frequently happens with e.g., sh:class skos:Concept
77
+ logger.debug("shape %s sh:class(es) did not map to any node shapes", shape);
78
+ return memberTypeEithers[0];
79
+ }
80
+ }
81
+ else if (shape.constraints.nodes.length > 0) {
82
+ memberTypeEithers = shape.constraints.nodes.map((nodeShape) => transformNodeShapeToAstCompositeMemberType(nodeShape));
83
+ compositeTypeKind = "IntersectionType";
84
+ }
85
+ else if (shape.constraints.xone.length > 0) {
86
+ memberTypeEithers = shape.constraints.xone.map((memberShape) => this.transformPropertyShapeToAstType(memberShape, {
87
+ defaultValue,
88
+ extern: extern,
89
+ }));
90
+ compositeTypeKind = "UnionType";
91
+ }
92
+ else {
93
+ return Left(new Error(`unable to transform ${shape} into an AST type`));
94
+ }
95
+ invariant(memberTypeEithers.length > 0);
96
+ const memberTypes = Either.rights(memberTypeEithers);
97
+ if (memberTypes.length !== memberTypeEithers.length) {
98
+ logger.warn("shape %s composition did not map all member types successfully", shape);
99
+ return memberTypeEithers[0];
100
+ }
101
+ invariant(memberTypes.length > 0);
102
+ if (memberTypes.length === 1) {
103
+ return Either.of(memberTypes[0]);
104
+ }
105
+ // Get the type underlying a set or option
106
+ const memberItemTypes = memberTypes.map((memberType) => {
107
+ switch (memberType.kind) {
108
+ case "SetType":
109
+ return memberType.itemType;
110
+ case "OptionType":
111
+ return memberType.itemType;
112
+ default:
113
+ return memberType;
114
+ }
115
+ });
116
+ if (hasValues.length === 0) {
117
+ // Can't handle hasValues when coalescing types
118
+ const canCoalesce = (memberItemType) => {
119
+ if (memberItemType.in_.length > 0) {
120
+ return false;
121
+ }
122
+ switch (memberItemType.kind) {
123
+ case "LiteralType": {
124
+ if (memberItemType.maxExclusive.isJust()) {
125
+ return false;
126
+ }
127
+ if (memberItemType.maxInclusive.isJust()) {
128
+ return false;
129
+ }
130
+ if (memberItemType.minExclusive.isJust()) {
131
+ return false;
132
+ }
133
+ if (memberItemType.minInclusive.isJust()) {
134
+ return false;
135
+ }
136
+ }
137
+ }
138
+ return true;
139
+ };
140
+ if (memberItemTypes.every((memberItemType) => memberItemType.kind === "IdentifierType" &&
141
+ canCoalesce(memberItemType))) {
142
+ // Special case: all member types are identifiers without further constraints
143
+ return Either.of({
144
+ defaultValue: defaultValue.filter((term) => term.termType === "NamedNode"),
145
+ hasValues: [],
146
+ in_: [],
147
+ kind: "IdentifierType",
148
+ nodeKinds: new Set(memberItemTypes
149
+ .filter((memberItemType) => memberItemType.kind === "IdentifierType")
150
+ .flatMap((memberItemType) => [
151
+ ...memberItemType.nodeKinds,
152
+ ])),
153
+ });
154
+ }
155
+ if (memberItemTypes.every((memberItemType) => memberItemType.kind === "LiteralType" && canCoalesce(memberItemType))) {
156
+ // Special case: all the member types are Literals without further constraints,
157
+ // like dash:StringOrLangString
158
+ // Don't try to coalesce range constraints.
159
+ return Either.of({
160
+ datatype: Maybe.empty(),
161
+ defaultValue: defaultValue.filter((term) => term.termType === "Literal"),
162
+ hasValues: [],
163
+ in_: [],
164
+ kind: "LiteralType",
165
+ languageIn: [],
166
+ maxExclusive: Maybe.empty(),
167
+ maxInclusive: Maybe.empty(),
168
+ minExclusive: Maybe.empty(),
169
+ minInclusive: Maybe.empty(),
170
+ nodeKinds: new Set(["Literal"]),
171
+ });
172
+ }
173
+ if (memberItemTypes.every((memberItemType) => (memberItemType.kind === "IdentifierType" ||
174
+ memberItemType.kind === "LiteralType" ||
175
+ memberItemType.kind === "TermType") &&
176
+ canCoalesce(memberItemType))) {
177
+ // Special case: all member types are terms without further constraints
178
+ const nodeKinds = new Set(memberItemTypes.flatMap((memberItemType) => [
179
+ ...memberItemType
180
+ .nodeKinds,
181
+ ]));
182
+ invariant(nodeKinds.has("Literal") &&
183
+ (nodeKinds.has("BlankNode") || nodeKinds.has("NamedNode"))); // The identifier-identifier and literal-literal cases should have been caught above
184
+ return Either.of({
185
+ defaultValue,
186
+ hasValues: [],
187
+ in_: [],
188
+ kind: "TermType",
189
+ nodeKinds,
190
+ });
191
+ }
192
+ }
193
+ return Either.of({
194
+ kind: compositeTypeKind,
195
+ memberTypes: memberTypes,
196
+ });
197
+ }
198
+ //# sourceMappingURL=transformPropertyShapeToAstCompositeType.js.map
@@ -0,0 +1,12 @@
1
+ import type { BlankNode, Literal, NamedNode } from "@rdfjs/types";
2
+ import { Either, Maybe } from "purify-ts";
3
+ import type { ShapesGraphToAstTransformer } from "../ShapesGraphToAstTransformer.js";
4
+ import type * as ast from "../ast/index.js";
5
+ import * as input from "../input/index.js";
6
+ /**
7
+ * Try to convert a property shape to an AST IdentifierType using some heuristics.
8
+ */
9
+ export declare function transformPropertyShapeToAstIdentifierType(this: ShapesGraphToAstTransformer, shape: input.Shape, inherited: {
10
+ defaultValue: Maybe<BlankNode | Literal | NamedNode>;
11
+ } | null): Either<Error, ast.IdentifierType>;
12
+ //# sourceMappingURL=transformPropertyShapeToAstIdentifierType.d.ts.map
@@ -0,0 +1,29 @@
1
+ import { Either, Left, Maybe } from "purify-ts";
2
+ import * as input from "../input/index.js";
3
+ import { propertyShapeNodeKinds } from "./propertyShapeNodeKinds.js";
4
+ /**
5
+ * Try to convert a property shape to an AST IdentifierType using some heuristics.
6
+ */
7
+ export function transformPropertyShapeToAstIdentifierType(shape, inherited) {
8
+ // defaultValue / hasValue / in only makes sense with IRIs
9
+ const identifierDefaultValue = (shape instanceof input.PropertyShape ? shape.defaultValue : Maybe.empty())
10
+ .alt(inherited !== null ? inherited.defaultValue : Maybe.empty())
11
+ .filter((value) => value.termType === "NamedNode");
12
+ const identifierHasValues = shape.constraints.hasValues.filter((term) => term.termType === "NamedNode");
13
+ const identifierIn = shape.constraints.in_.filter((term) => term.termType === "NamedNode");
14
+ const nodeKinds = propertyShapeNodeKinds(shape);
15
+ if (identifierHasValues.length > 0 ||
16
+ identifierDefaultValue.isJust() ||
17
+ identifierIn.length > 0 ||
18
+ (nodeKinds.size > 0 && nodeKinds.size <= 2 && !nodeKinds.has("Literal"))) {
19
+ return Either.of({
20
+ defaultValue: identifierDefaultValue,
21
+ hasValues: identifierHasValues,
22
+ in_: identifierIn,
23
+ kind: "IdentifierType",
24
+ nodeKinds: nodeKinds,
25
+ });
26
+ }
27
+ return Left(new Error(`unable to transform ${shape} into an AST type`));
28
+ }
29
+ //# sourceMappingURL=transformPropertyShapeToAstIdentifierType.js.map
@@ -0,0 +1,12 @@
1
+ import type { BlankNode, Literal, NamedNode } from "@rdfjs/types";
2
+ import { Either, Maybe } from "purify-ts";
3
+ import type { ShapesGraphToAstTransformer } from "../ShapesGraphToAstTransformer.js";
4
+ import type * as ast from "../ast/index.js";
5
+ import * as input from "../input/index.js";
6
+ /**
7
+ * Try to convert a property shape to an AST LiteralType using some heuristics.
8
+ */
9
+ export declare function transformPropertyShapeToAstLiteralType(this: ShapesGraphToAstTransformer, shape: input.Shape, inherited: {
10
+ defaultValue: Maybe<BlankNode | Literal | NamedNode>;
11
+ } | null): Either<Error, ast.LiteralType>;
12
+ //# sourceMappingURL=transformPropertyShapeToAstLiteralType.d.ts.map
@@ -0,0 +1,43 @@
1
+ import { Either, Left, Maybe } from "purify-ts";
2
+ import * as input from "../input/index.js";
3
+ import { propertyShapeNodeKinds } from "./propertyShapeNodeKinds.js";
4
+ /**
5
+ * Try to convert a property shape to an AST LiteralType using some heuristics.
6
+ */
7
+ export function transformPropertyShapeToAstLiteralType(shape, inherited) {
8
+ const literalDefaultValue = (shape instanceof input.PropertyShape ? shape.defaultValue : Maybe.empty())
9
+ .alt(inherited !== null ? inherited.defaultValue : Maybe.empty())
10
+ .filter((term) => term.termType === "Literal");
11
+ const literalHasValues = shape.constraints.hasValues.filter((term) => term.termType === "Literal");
12
+ const literalIn = shape.constraints.in_.filter((term) => term.termType === "Literal");
13
+ const nodeKinds = propertyShapeNodeKinds(shape);
14
+ if ([
15
+ // Treat any shape with the constraints in the list as a literal type
16
+ shape.constraints.datatype,
17
+ shape.constraints.maxExclusive,
18
+ shape.constraints.maxInclusive,
19
+ shape.constraints.minExclusive,
20
+ shape.constraints.minInclusive,
21
+ ].some((constraint) => constraint.isJust()) ||
22
+ shape.constraints.languageIn.length > 0 ||
23
+ literalDefaultValue.isJust() ||
24
+ literalHasValues.length > 0 ||
25
+ literalIn.length > 0 ||
26
+ // Treat any shape with a single sh:nodeKind of sh:Literal as a literal type
27
+ (nodeKinds.size === 1 && nodeKinds.has("Literal")))
28
+ return Either.of({
29
+ datatype: shape.constraints.datatype,
30
+ defaultValue: literalDefaultValue,
31
+ hasValues: literalHasValues,
32
+ in_: literalIn,
33
+ kind: "LiteralType",
34
+ languageIn: shape.constraints.languageIn,
35
+ maxExclusive: shape.constraints.maxExclusive,
36
+ maxInclusive: shape.constraints.maxInclusive,
37
+ minExclusive: shape.constraints.minExclusive,
38
+ minInclusive: shape.constraints.minInclusive,
39
+ nodeKinds: new Set(["Literal"]),
40
+ });
41
+ return Left(new Error(`unable to transform ${shape} into an AST type`));
42
+ }
43
+ //# sourceMappingURL=transformPropertyShapeToAstLiteralType.js.map
@@ -0,0 +1,6 @@
1
+ import { Either } from "purify-ts";
2
+ import type { ShapesGraphToAstTransformer } from "../ShapesGraphToAstTransformer.js";
3
+ import type * as ast from "../ast/index.js";
4
+ import type * as input from "../input/index.js";
5
+ export declare function transformPropertyShapeToAstObjectTypeProperty(this: ShapesGraphToAstTransformer, propertyShape: input.PropertyShape): Either<Error, ast.ObjectType.Property>;
6
+ //# sourceMappingURL=transformPropertyShapeToAstObjectTypeProperty.d.ts.map
@@ -0,0 +1,31 @@
1
+ import { Either, Left } from "purify-ts";
2
+ import { pickLiteral } from "./pickLiteral.js";
3
+ export function transformPropertyShapeToAstObjectTypeProperty(propertyShape) {
4
+ {
5
+ const property = this.astObjectTypePropertiesByIdentifier.get(propertyShape.identifier);
6
+ if (property) {
7
+ return Either.of(property);
8
+ }
9
+ }
10
+ const type = this.transformPropertyShapeToAstType(propertyShape, null);
11
+ if (type.isLeft()) {
12
+ return type;
13
+ }
14
+ const path = propertyShape.path;
15
+ if (path.kind !== "PredicatePath") {
16
+ return Left(new Error(`${propertyShape} has non-predicate path, unsupported`));
17
+ }
18
+ const property = {
19
+ comment: pickLiteral(propertyShape.comments).map((literal) => literal.value),
20
+ description: pickLiteral(propertyShape.descriptions).map((literal) => literal.value),
21
+ label: pickLiteral(propertyShape.labels).map((literal) => literal.value),
22
+ mutable: propertyShape.mutable,
23
+ name: this.shapeAstName(propertyShape),
24
+ path,
25
+ type: type.extract(),
26
+ visibility: propertyShape.visibility,
27
+ };
28
+ this.astObjectTypePropertiesByIdentifier.set(propertyShape.identifier, property);
29
+ return Either.of(property);
30
+ }
31
+ //# sourceMappingURL=transformPropertyShapeToAstObjectTypeProperty.js.map
@@ -0,0 +1,14 @@
1
+ import type { BlankNode, Literal, NamedNode } from "@rdfjs/types";
2
+ import { Either, Maybe } from "purify-ts";
3
+ import type { ShapesGraphToAstTransformer } from "../ShapesGraphToAstTransformer.js";
4
+ import type * as ast from "../ast/index.js";
5
+ import * as input from "../input/index.js";
6
+ /**
7
+ * Try to convert a property shape to an AST TermType using some heuristics.
8
+ */
9
+ export declare function transformPropertyShapeToAstTermType(this: ShapesGraphToAstTransformer, shape: input.Shape, inherited: {
10
+ defaultValue: Maybe<BlankNode | Literal | NamedNode>;
11
+ } | null): Either<Error, Omit<ast.TermType<BlankNode | Literal | NamedNode>, "kind"> & {
12
+ readonly kind: "TermType";
13
+ }>;
14
+ //# sourceMappingURL=transformPropertyShapeToAstTermType.d.ts.map
@@ -0,0 +1,21 @@
1
+ import { Either, Maybe } from "purify-ts";
2
+ import * as input from "../input/index.js";
3
+ import { propertyShapeNodeKinds } from "./propertyShapeNodeKinds.js";
4
+ /**
5
+ * Try to convert a property shape to an AST TermType using some heuristics.
6
+ */
7
+ export function transformPropertyShapeToAstTermType(shape, inherited) {
8
+ const nodeKinds = propertyShapeNodeKinds(shape);
9
+ return Either.of({
10
+ defaultValue: (shape instanceof input.PropertyShape
11
+ ? shape.defaultValue
12
+ : Maybe.empty()).alt(inherited !== null ? inherited.defaultValue : Maybe.empty()),
13
+ hasValues: shape.constraints.hasValues,
14
+ in_: shape.constraints.in_,
15
+ kind: "TermType",
16
+ nodeKinds: nodeKinds.size > 0
17
+ ? nodeKinds
18
+ : new Set(["BlankNode", "NamedNode", "Literal"]),
19
+ });
20
+ }
21
+ //# sourceMappingURL=transformPropertyShapeToAstTermType.js.map
@@ -0,0 +1,16 @@
1
+ import type { BlankNode, Literal, NamedNode } from "@rdfjs/types";
2
+ import type { Either, Maybe } from "purify-ts";
3
+ import type { ShapesGraphToAstTransformer } from "../ShapesGraphToAstTransformer.js";
4
+ import type * as ast from "../ast/index.js";
5
+ import * as input from "../input/index.js";
6
+ /**
7
+ * Try to convert a property shape to a type using some heuristics.
8
+ *
9
+ * 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
10
+ * a shape has one type.
11
+ */
12
+ export declare function transformPropertyShapeToAstType(this: ShapesGraphToAstTransformer, shape: input.Shape, inherited: {
13
+ defaultValue: Maybe<BlankNode | Literal | NamedNode>;
14
+ extern: Maybe<boolean>;
15
+ } | null): Either<Error, ast.Type>;
16
+ //# sourceMappingURL=transformPropertyShapeToAstType.d.ts.map