@shaclmate/compiler 4.0.13 → 4.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 (40) hide show
  1. package/dist/ShapesGraphToAstTransformer.js +2 -2
  2. package/dist/_ShapesGraphToAstTransformer/ShapeStack.js +6 -5
  3. package/dist/_ShapesGraphToAstTransformer/nodeShapeIdentifierMintingStrategy.d.ts +3 -2
  4. package/dist/_ShapesGraphToAstTransformer/nodeShapeIdentifierMintingStrategy.js +8 -5
  5. package/dist/_ShapesGraphToAstTransformer/nodeShapeTsFeatures.js +2 -1
  6. package/dist/_ShapesGraphToAstTransformer/shapeAstTypeName.js +6 -6
  7. package/dist/_ShapesGraphToAstTransformer/shapeNodeKinds.d.ts +2 -1
  8. package/dist/_ShapesGraphToAstTransformer/shapeNodeKinds.js +23 -17
  9. package/dist/_ShapesGraphToAstTransformer/shapeOntology.d.ts +5 -0
  10. package/dist/_ShapesGraphToAstTransformer/shapeOntology.js +25 -0
  11. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstObjectTypeProperty.js +23 -16
  12. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstCompoundType.js +6 -6
  13. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstListType.js +15 -15
  14. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstObjectType.js +122 -118
  15. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstTermType.js +10 -8
  16. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstType.js +3 -3
  17. package/dist/ast/ObjectType.d.ts +3 -3
  18. package/dist/enums/IdentifierMintingStrategy.d.ts +4 -0
  19. package/dist/enums/IdentifierMintingStrategy.js +17 -1
  20. package/dist/enums/TsObjectDeclarationType.d.ts +4 -0
  21. package/dist/enums/TsObjectDeclarationType.js +15 -1
  22. package/dist/enums/Visibility.d.ts +6 -0
  23. package/dist/enums/Visibility.js +18 -0
  24. package/dist/generators/ts/_NamedObjectType/AbstractProperty.d.ts +3 -3
  25. package/dist/input/NodeShape.d.ts +8 -46
  26. package/dist/input/NodeShape.js +1 -153
  27. package/dist/input/Shape.d.ts +2 -2
  28. package/dist/input/ShapesGraph.d.ts +10 -10
  29. package/dist/input/ShapesGraph.js +11 -13
  30. package/dist/input/generated.d.ts +185 -152
  31. package/dist/input/generated.js +316 -249
  32. package/dist/input/index.d.ts +1 -3
  33. package/dist/input/index.js +1 -3
  34. package/package.json +2 -2
  35. package/dist/enums/PropertyVisibility.d.ts +0 -2
  36. package/dist/enums/PropertyVisibility.js +0 -2
  37. package/dist/input/Ontology.d.ts +0 -13
  38. package/dist/input/Ontology.js +0 -40
  39. package/dist/input/PropertyShape.d.ts +0 -20
  40. package/dist/input/PropertyShape.js +0 -78
@@ -21,10 +21,10 @@ export class ShapesGraphToAstTransformer {
21
21
  const syntheticAstObjectTypesByName = {};
22
22
  const astNamedUnionTypes = [];
23
23
  for (const nodeShape of this.shapesGraph.nodeShapes) {
24
- if (nodeShape.identifier.termType !== "NamedNode") {
24
+ if (nodeShape.$identifier.termType !== "NamedNode") {
25
25
  continue;
26
26
  }
27
- if (nodeShape.identifier.value.startsWith(dash[""].value)) {
27
+ if (nodeShape.$identifier.value.startsWith(dash[""].value)) {
28
28
  continue;
29
29
  }
30
30
  const nodeShapeAstTypeEither = transformShapeToAstType.call(this, nodeShape, new ShapeStack());
@@ -7,16 +7,17 @@ export class ShapeStack {
7
7
  this.constraints = {
8
8
  get hasValues() {
9
9
  for (const shape of stack.toReversed()) {
10
- if (shape.constraints.hasValues.length > 0) {
11
- return shape.constraints.hasValues;
10
+ if (shape.hasValues.length > 0) {
11
+ return shape.hasValues;
12
12
  }
13
13
  }
14
14
  return [];
15
15
  },
16
16
  get in_() {
17
17
  for (const shape of stack.toReversed()) {
18
- if (shape.constraints.in_.length > 0) {
19
- return shape.constraints.in_;
18
+ const shapeIn = shape.in_.orDefault([]);
19
+ if (shapeIn.length > 0) {
20
+ return shapeIn;
20
21
  }
21
22
  }
22
23
  return [];
@@ -26,7 +27,7 @@ export class ShapeStack {
26
27
  constraints;
27
28
  get defaultValue() {
28
29
  for (const shape of this.stack.toReversed()) {
29
- if (shape.kind !== "PropertyShape") {
30
+ if (shape.$type !== "PropertyShape") {
30
31
  continue;
31
32
  }
32
33
  if (shape.defaultValue.isJust()) {
@@ -1,5 +1,6 @@
1
1
  import { Either, Maybe } from "purify-ts";
2
- import type { IdentifierMintingStrategy } from "../enums/IdentifierMintingStrategy.js";
2
+ import { IdentifierMintingStrategy } from "../enums/IdentifierMintingStrategy.js";
3
3
  import type * as input from "../input/index.js";
4
- export declare function nodeShapeIdentifierMintingStrategy(nodeShape: input.NodeShape): Either<Error, Maybe<IdentifierMintingStrategy>>;
4
+ import type { ShapesGraphToAstTransformer } from "../ShapesGraphToAstTransformer.js";
5
+ export declare function nodeShapeIdentifierMintingStrategy(this: ShapesGraphToAstTransformer, nodeShape: input.NodeShape): Either<Error, Maybe<IdentifierMintingStrategy>>;
5
6
  //# sourceMappingURL=nodeShapeIdentifierMintingStrategy.d.ts.map
@@ -1,4 +1,5 @@
1
1
  import { Either, Left, Maybe } from "purify-ts";
2
+ import { IdentifierMintingStrategy } from "../enums/IdentifierMintingStrategy.js";
2
3
  import { shapeNodeKinds } from "./shapeNodeKinds.js";
3
4
  const defaultNodeShapeNodeKinds = new Set([
4
5
  "BlankNode",
@@ -6,18 +7,20 @@ const defaultNodeShapeNodeKinds = new Set([
6
7
  ]);
7
8
  export function nodeShapeIdentifierMintingStrategy(nodeShape) {
8
9
  if (nodeShape.identifierMintingStrategy.isJust()) {
9
- if (nodeShape.identifierIn.length > 0) {
10
+ if (nodeShape.in_.filter((_) => _.length > 0).isJust()) {
10
11
  return Left(new Error(`${nodeShape} cannot have an identifier minting strategy and sh:in`));
11
12
  }
12
- return Either.of(nodeShape.identifierMintingStrategy);
13
+ return Either.of(nodeShape.identifierMintingStrategy.map(IdentifierMintingStrategy.fromIri));
13
14
  }
14
- return nodeShape.ancestorNodeShapes.chain((ancestorNodeShapes) => {
15
+ return Either.sequence(nodeShape.ancestorClassIris.map((nodeShapeIdentifier) => this.shapesGraph.nodeShape(nodeShapeIdentifier))).chain((ancestorNodeShapes) => {
15
16
  for (const ancestorNodeShape of ancestorNodeShapes) {
16
17
  if (ancestorNodeShape.identifierMintingStrategy.isJust()) {
17
- return Either.of(ancestorNodeShape.identifierMintingStrategy);
18
+ return Either.of(ancestorNodeShape.identifierMintingStrategy.map(IdentifierMintingStrategy.fromIri));
18
19
  }
19
20
  }
20
- return shapeNodeKinds(nodeShape, { defaultNodeShapeNodeKinds }).map((nodeKinds) => {
21
+ return shapeNodeKinds
22
+ .call(this, nodeShape, { defaultNodeShapeNodeKinds })
23
+ .map((nodeKinds) => {
21
24
  if (nodeKinds.has("BlankNode")) {
22
25
  return Maybe.of("blankNode");
23
26
  }
@@ -1,5 +1,6 @@
1
1
  import { Either } from "purify-ts";
2
2
  import { TS_FEATURES } from "../enums/TsFeature.js";
3
+ import { shapeOntology } from "./shapeOntology.js";
3
4
  export function nodeShapeTsFeatures(nodeShape) {
4
5
  const tsFeaturesDefault = this.tsFeaturesDefault;
5
6
  function iriToTsFeatures(iri) {
@@ -26,7 +27,7 @@ export function nodeShapeTsFeatures(nodeShape) {
26
27
  return ["sparql"];
27
28
  }
28
29
  }
29
- return nodeShape.isDefinedBy.chain((ontologyMaybe) => {
30
+ return shapeOntology.call(this, nodeShape).chain((ontologyMaybe) => {
30
31
  let tsFeatureExcludes = nodeShape.tsFeatureExcludes.flatMap(iriToTsFeatures);
31
32
  let tsFeatureIncludes = nodeShape.tsFeatureIncludes.flatMap(iriToTsFeatures);
32
33
  if (tsFeatureExcludes.length === 0 && tsFeatureIncludes.length === 0) {
@@ -1,10 +1,10 @@
1
1
  import { Curie } from "@shaclmate/shacl-ast";
2
2
  import { Maybe } from "purify-ts";
3
3
  export function shapeAstTypeName(shape) {
4
- if (shape.kind !== "NodeShape") {
4
+ if (shape.$type !== "NodeShape") {
5
5
  return Maybe.empty();
6
6
  }
7
- if (shape.identifier.termType !== "NamedNode") {
7
+ if (shape.$identifier.termType !== "NamedNode") {
8
8
  return Maybe.empty();
9
9
  }
10
10
  // Explicit shaclmate:name
@@ -16,11 +16,11 @@ export function shapeAstTypeName(shape) {
16
16
  return shape.label;
17
17
  }
18
18
  // CURIE shape identifier
19
- if (shape.identifier instanceof Curie) {
20
- if (shape.identifier.hasUniqueReference) {
21
- return Maybe.of(shape.identifier.reference);
19
+ if (shape.$identifier instanceof Curie) {
20
+ if (shape.$identifier.hasUniqueReference) {
21
+ return Maybe.of(shape.$identifier.reference);
22
22
  }
23
- return Maybe.of(`${shape.identifier.prefix}_${shape.identifier.reference}`);
23
+ return Maybe.of(`${shape.$identifier.prefix}_${shape.$identifier.reference}`);
24
24
  }
25
25
  return Maybe.empty();
26
26
  }
@@ -1,7 +1,8 @@
1
1
  import { NodeKind } from "@shaclmate/shacl-ast";
2
2
  import { Either } from "purify-ts";
3
3
  import type * as input from "../input/index.js";
4
- export declare function shapeNodeKinds(shape: input.Shape, options?: {
4
+ import type { ShapesGraphToAstTransformer } from "../ShapesGraphToAstTransformer.js";
5
+ export declare function shapeNodeKinds(this: ShapesGraphToAstTransformer, shape: input.Shape, options?: {
5
6
  defaultNodeShapeNodeKinds: ReadonlySet<NodeKind>;
6
7
  defaultPropertyShapeNodeKinds?: ReadonlySet<NodeKind>;
7
8
  }): Either<Error, ReadonlySet<NodeKind>>;
@@ -7,11 +7,15 @@ const defaultPropertyShapeNodeKinds = new Set([
7
7
  "Literal",
8
8
  ]);
9
9
  function nodeShapeNodeKinds(nodeShape) {
10
- const thisNodeKinds = nodeShape.constraints.nodeKinds;
11
- return nodeShape.parentNodeShapes.chain((parentNodeShapes) => {
10
+ const thisNodeKinds = nodeShape.nodeKind
11
+ .map(NodeKind.fromIri)
12
+ .orDefault(new Set());
13
+ return Either.sequence(nodeShape.parentClassIris.map((nodeShapeIdentifier) => this.shapesGraph.nodeShape(nodeShapeIdentifier))).chain((parentNodeShapes) => {
12
14
  const parentNodeKinds = new Set();
13
15
  for (const parentNodeShape of parentNodeShapes) {
14
- for (const parentNodeKind of parentNodeShape.constraints.nodeKinds) {
16
+ for (const parentNodeKind of parentNodeShape.nodeKind
17
+ .map(NodeKind.fromIri)
18
+ .orDefault(new Set())) {
15
19
  parentNodeKinds.add(parentNodeKind);
16
20
  }
17
21
  }
@@ -30,11 +34,11 @@ function nodeShapeNodeKinds(nodeShape) {
30
34
  });
31
35
  }
32
36
  function propertyShapeNodeKinds(propertyShape) {
33
- return Either.of(propertyShape.constraints.nodeKinds);
37
+ return Either.of(propertyShape.nodeKind.map(NodeKind.fromIri).orDefault(new Set()));
34
38
  }
35
39
  export function shapeNodeKinds(shape, options) {
36
- return (shape.kind === "NodeShape"
37
- ? nodeShapeNodeKinds(shape)
40
+ return (shape.$type === "NodeShape"
41
+ ? nodeShapeNodeKinds.call(this, shape)
38
42
  : propertyShapeNodeKinds(shape)).chain((explicitNodeKinds) => {
39
43
  // Consider constraints that dictate certain node kinds, like sh:datatype dictates a Literal nodeKind.
40
44
  const constraintExcludeNodeKinds = new Set();
@@ -42,14 +46,14 @@ export function shapeNodeKinds(shape, options) {
42
46
  for (const [constraint, { excludeNodeKinds, includeNodeKinds }] of [
43
47
  [
44
48
  "sh:class",
45
- shape.constraints.classes.length > 0
49
+ shape.classes.length > 0
46
50
  ? { excludeNodeKinds: ["Literal"] }
47
51
  : {},
48
52
  ],
49
53
  [
50
54
  "sh:datatype",
51
55
  {
52
- includeNodeKinds: shape.constraints.datatype
56
+ includeNodeKinds: shape.datatype
53
57
  .map(() => ["Literal"])
54
58
  .orDefault([]),
55
59
  },
@@ -57,7 +61,7 @@ export function shapeNodeKinds(shape, options) {
57
61
  [
58
62
  "sh:defaultValue",
59
63
  {
60
- includeNodeKinds: shape.kind === "PropertyShape"
64
+ includeNodeKinds: shape.$type === "PropertyShape"
61
65
  ? shape.defaultValue
62
66
  .map((value) => NodeKind.fromTermType(value.termType))
63
67
  .toList()
@@ -67,25 +71,27 @@ export function shapeNodeKinds(shape, options) {
67
71
  [
68
72
  "sh:hasValue",
69
73
  {
70
- includeNodeKinds: shape.constraints.hasValues.map((value) => NodeKind.fromTermType(value.termType)),
74
+ includeNodeKinds: shape.hasValues.map((value) => NodeKind.fromTermType(value.termType)),
71
75
  },
72
76
  ],
73
77
  [
74
78
  "sh:in",
75
79
  {
76
- includeNodeKinds: shape.constraints.in_.map((in_) => NodeKind.fromTermType(in_.termType)),
80
+ includeNodeKinds: shape.in_
81
+ .orDefault([])
82
+ .map((in_) => NodeKind.fromTermType(in_.termType)),
77
83
  },
78
84
  ],
79
85
  [
80
86
  "sh:languageIn",
81
- shape.constraints.languageIn.length > 0
87
+ shape.languageIn.orDefault([]).length > 0
82
88
  ? { includeNodeKinds: ["Literal"] }
83
89
  : {},
84
90
  ],
85
91
  [
86
92
  "sh:maxExclusive",
87
93
  {
88
- includeNodeKinds: shape.constraints.maxExclusive
94
+ includeNodeKinds: shape.maxExclusive
89
95
  .map(() => ["Literal"])
90
96
  .orDefault([]),
91
97
  },
@@ -93,7 +99,7 @@ export function shapeNodeKinds(shape, options) {
93
99
  [
94
100
  "sh:maxInclusive",
95
101
  {
96
- includeNodeKinds: shape.constraints.maxInclusive
102
+ includeNodeKinds: shape.maxInclusive
97
103
  .map(() => ["Literal"])
98
104
  .orDefault([]),
99
105
  },
@@ -101,7 +107,7 @@ export function shapeNodeKinds(shape, options) {
101
107
  [
102
108
  "sh:minExclusive",
103
109
  {
104
- includeNodeKinds: shape.constraints.minExclusive
110
+ includeNodeKinds: shape.minExclusive
105
111
  .map(() => ["Literal"])
106
112
  .orDefault([]),
107
113
  },
@@ -109,7 +115,7 @@ export function shapeNodeKinds(shape, options) {
109
115
  [
110
116
  "sh:minInclusive",
111
117
  {
112
- includeNodeKinds: shape.constraints.minInclusive
118
+ includeNodeKinds: shape.minInclusive
113
119
  .map(() => ["Literal"])
114
120
  .orDefault([]),
115
121
  },
@@ -162,7 +168,7 @@ export function shapeNodeKinds(shape, options) {
162
168
  if (constraintNodeKinds.size > 0) {
163
169
  return Either.of(constraintNodeKinds);
164
170
  }
165
- if (shape.kind === "NodeShape") {
171
+ if (shape.$type === "NodeShape") {
166
172
  return Either.of(options?.defaultNodeShapeNodeKinds ?? defaultNodeShapeNodeKinds);
167
173
  }
168
174
  if (shape.path.termType === "InversePath") {
@@ -0,0 +1,5 @@
1
+ import { Either, Maybe } from "purify-ts";
2
+ import type * as input from "../input/index.js";
3
+ import type { ShapesGraphToAstTransformer } from "../ShapesGraphToAstTransformer.js";
4
+ export declare function shapeOntology(this: ShapesGraphToAstTransformer, shape: input.Shape): Either<Error, Maybe<input.Ontology>>;
5
+ //# sourceMappingURL=shapeOntology.d.ts.map
@@ -0,0 +1,25 @@
1
+ import { Either, Maybe } from "purify-ts";
2
+ export function shapeOntology(shape) {
3
+ if (shape.isDefinedBy.isJust()) {
4
+ // If there's an rdfs:isDefinedBy statement on the shape then don't fall back to anything else
5
+ return this.shapesGraph
6
+ .ontology(shape.isDefinedBy.unsafeCoerce())
7
+ .map(Maybe.of);
8
+ }
9
+ // No rdfs:isDefinedBy statement on the shape
10
+ const ontologies = this.shapesGraph.ontologies;
11
+ if (ontologies.length === 1) {
12
+ // If there's a single ontology in the shapes graph, consider the shape a part of the ontology
13
+ return Either.of(Maybe.of(ontologies[0]));
14
+ }
15
+ if (shape.$identifier.termType === "NamedNode") {
16
+ const prefixOntologies = ontologies.filter((ontology) => ontology.$identifier.termType === "NamedNode" &&
17
+ shape.$identifier.value.startsWith(ontology.$identifier.value));
18
+ if (prefixOntologies.length === 1) {
19
+ // If there's a single ontology whose IRI is a prefix of this shape's IRI, consider the shape a part of the ontology
20
+ return Either.of(Maybe.of(prefixOntologies[0]));
21
+ }
22
+ }
23
+ return Either.of(Maybe.empty());
24
+ }
25
+ //# sourceMappingURL=shapeOntology.js.map
@@ -4,6 +4,7 @@ import { Either, Left, Maybe } from "purify-ts";
4
4
  import { invariant } from "ts-invariant";
5
5
  import * as ast from "../ast/index.js";
6
6
  import { Eithers } from "../Eithers.js";
7
+ import { Visibility } from "../enums/Visibility.js";
7
8
  import { ShapeStack } from "./ShapeStack.js";
8
9
  import { transformShapeToAstType } from "./transformShapeToAstType.js";
9
10
  function synthesizePartialAstObjectType({ identifierType, tsFeatures, }) {
@@ -48,13 +49,13 @@ function propertyName(objectType, propertyShape) {
48
49
  }
49
50
  // Pick up the common pattern of a property shape identifier being the node shape's identifier -localName,
50
51
  // like ex:NodeShape-property
51
- if (propertyShape.identifier.termType === "NamedNode" &&
52
+ if (propertyShape.$identifier.termType === "NamedNode" &&
52
53
  objectType.shapeIdentifier.termType === "NamedNode") {
53
54
  const propertyShapeIdentifierPrefix = `${objectType.shapeIdentifier.value}-`;
54
- if (propertyShape.identifier.value.startsWith(propertyShapeIdentifierPrefix) &&
55
- propertyShape.identifier.value.length >
55
+ if (propertyShape.$identifier.value.startsWith(propertyShapeIdentifierPrefix) &&
56
+ propertyShape.$identifier.value.length >
56
57
  propertyShapeIdentifierPrefix.length) {
57
- return propertyShape.identifier.value.substring(propertyShapeIdentifierPrefix.length);
58
+ return propertyShape.$identifier.value.substring(propertyShapeIdentifierPrefix.length);
58
59
  }
59
60
  }
60
61
  // sh:path CURIE reference
@@ -62,12 +63,12 @@ function propertyName(objectType, propertyShape) {
62
63
  return propertyShape.path.reference;
63
64
  }
64
65
  // Shape identifier CURIE reference
65
- if (propertyShape.identifier instanceof Curie) {
66
- return propertyShape.identifier.reference;
66
+ if (propertyShape.$identifier instanceof Curie) {
67
+ return propertyShape.$identifier.reference;
67
68
  }
68
69
  // Shape identifier IRI
69
- if (propertyShape.identifier.termType === "NamedNode") {
70
- return propertyShape.identifier.value;
70
+ if (propertyShape.$identifier.termType === "NamedNode") {
71
+ return propertyShape.$identifier.value;
71
72
  }
72
73
  // sh:path IRI
73
74
  if (propertyShape.path.termType === "NamedNode") {
@@ -84,13 +85,13 @@ function transformPropertyShapeToAstType(propertyShape, shapeStack) {
84
85
  return transformShapeToAstType
85
86
  .call(this, propertyShape, shapeStack)
86
87
  .chain((propertyShapeAstType) => {
87
- let maxCount = propertyShape.constraints.maxCount.orDefault(Number.MAX_SAFE_INTEGER);
88
- let minCount = propertyShape.constraints.minCount.orDefault(0);
88
+ let maxCount = propertyShape.maxCount.orDefault(Number.MAX_SAFE_INTEGER);
89
+ let minCount = propertyShape.minCount.orDefault(0);
89
90
  if (minCount < 0) {
90
91
  minCount = 0;
91
92
  }
92
- if (propertyShape.constraints.hasValues.length > minCount) {
93
- minCount = propertyShape.constraints.hasValues.length;
93
+ if (propertyShape.hasValues.length > minCount) {
94
+ minCount = propertyShape.hasValues.length;
94
95
  }
95
96
  if (maxCount < minCount) {
96
97
  maxCount = minCount;
@@ -127,7 +128,11 @@ function transformPropertyShapeToAstType(propertyShape, shapeStack) {
127
128
  }
128
129
  export function transformPropertyShapeToAstObjectTypeProperty({ objectType, propertyShape, }) {
129
130
  const shapeStack = new ShapeStack(); // Start a new ShapeStack per property shape
130
- return Eithers.chain2(propertyShape.resolve, transformPropertyShapeToAstType.call(this, propertyShape, shapeStack)).chain(([propertyShapeResolve, astType]) => {
131
+ return Eithers.chain2(propertyShape.resolve.isJust()
132
+ ? this.shapesGraph
133
+ .nodeShape(propertyShape.resolve.extract())
134
+ .map(Maybe.of)
135
+ : Either.of(Maybe.empty()), transformPropertyShapeToAstType.call(this, propertyShape, shapeStack)).chain(([propertyShapeResolve, astType]) => {
131
136
  let astResolveItemType;
132
137
  if (propertyShapeResolve.isJust()) {
133
138
  const astResolveTypeEither = transformShapeToAstType
@@ -196,7 +201,7 @@ export function transformPropertyShapeToAstObjectTypeProperty({ objectType, prop
196
201
  comment: Maybe.empty(),
197
202
  label: Maybe.empty(),
198
203
  name: Maybe.empty(),
199
- shapeIdentifier: propertyShape.identifier,
204
+ shapeIdentifier: propertyShape.$identifier,
200
205
  };
201
206
  switch (astType.kind) {
202
207
  case "BlankNodeType":
@@ -253,9 +258,11 @@ export function transformPropertyShapeToAstObjectTypeProperty({ objectType, prop
253
258
  objectType,
254
259
  order: propertyShape.order.orDefault(0),
255
260
  path: propertyShape.path,
256
- shapeIdentifier: propertyShape.identifier,
261
+ shapeIdentifier: propertyShape.$identifier,
257
262
  type: astType,
258
- visibility: propertyShape.visibility,
263
+ visibility: propertyShape.visibility
264
+ .map(Visibility.fromIri)
265
+ .orDefault("public"),
259
266
  }));
260
267
  });
261
268
  }
@@ -11,9 +11,9 @@ import { transformShapeToAstType } from "./transformShapeToAstType.js";
11
11
  export function transformShapeToAstCompoundType(shape, shapeStack) {
12
12
  shapeStack.push(shape);
13
13
  try {
14
- return Eithers.chain4(shape.constraints.and, shape.constraints.nodes, shape.kind === "NodeShape"
14
+ return Eithers.chain4(Either.sequence(shape.and.flatMap((and) => and.map((shapeIdentifier) => this.shapesGraph.shape(shapeIdentifier)))), Either.sequence(shape.nodes.map((nodeShapeIdentifier) => this.shapesGraph.nodeShape(nodeShapeIdentifier))), shape.$type === "NodeShape"
15
15
  ? nodeShapeTsFeatures.call(this, shape)
16
- : Either.of(new Set()), shape.constraints.xone).chain(([andConstraintShapes, nodeConstraintShapes, tsFeatures, xoneConstraintShapes,]) => {
16
+ : Either.of(new Set()), Either.sequence(shape.xone.flatMap((xone) => xone.map((shapeIdentifier) => this.shapesGraph.shape(shapeIdentifier))))).chain(([andConstraintShapes, nodeConstraintShapes, tsFeatures, xoneConstraintShapes,]) => {
17
17
  let compoundTypeKind;
18
18
  // Distinguish constraints that take arbitrary shapes from those that only take node shapes
19
19
  // With the latter we'll do special transformations.
@@ -41,7 +41,7 @@ export function transformShapeToAstCompoundType(shape, shapeStack) {
41
41
  comment: shape.comment,
42
42
  label: shape.label,
43
43
  name: shapeAstTypeName(shape),
44
- shapeIdentifier: shape.identifier,
44
+ shapeIdentifier: shape.$identifier,
45
45
  tsFeatures,
46
46
  });
47
47
  if (memberShapes.length === 1) {
@@ -50,7 +50,7 @@ export function transformShapeToAstCompoundType(shape, shapeStack) {
50
50
  .map(Maybe.of);
51
51
  }
52
52
  // Put a placeholder in the cache to deal with cyclic references
53
- this.cachedAstTypesByShapeIdentifier.set(shape.identifier, compoundType);
53
+ this.cachedAstTypesByShapeIdentifier.set(shape.$identifier, compoundType);
54
54
  return Either.sequence(memberShapes.map((memberShape) => transformShapeToAstType.call(this, memberShape, shapeStack)))
55
55
  .chain((memberShapeTypes) => {
56
56
  for (let memberI = 0; memberI < memberShapes.length; memberI++) {
@@ -65,7 +65,7 @@ export function transformShapeToAstCompoundType(shape, shapeStack) {
65
65
  }
66
66
  let memberDiscriminantValue;
67
67
  if (compoundTypeKind === "UnionType") {
68
- if (memberShape.kind === "NodeShape") {
68
+ if (memberShape.$type === "NodeShape") {
69
69
  memberDiscriminantValue =
70
70
  memberShape.discriminantValue.extract();
71
71
  }
@@ -84,7 +84,7 @@ export function transformShapeToAstCompoundType(shape, shapeStack) {
84
84
  return Either.of(Maybe.of(compoundType));
85
85
  })
86
86
  .ifLeft(() => {
87
- this.cachedAstTypesByShapeIdentifier.delete(shape.identifier);
87
+ this.cachedAstTypesByShapeIdentifier.delete(shape.$identifier);
88
88
  });
89
89
  });
90
90
  }
@@ -42,14 +42,14 @@ const astListTypePlaceholderItemType = new ast.BlankNodeType({
42
42
  export function transformShapeToAstListType(shape, shapeStack) {
43
43
  shapeStack.push(shape);
44
44
  try {
45
- if (shape.kind !== "NodeShape") {
45
+ if (shape.$type !== "NodeShape") {
46
46
  return Either.of(Maybe.empty());
47
47
  }
48
48
  const nodeShape = shape;
49
49
  if (!nodeShape.isList) {
50
50
  return Either.of(Maybe.empty());
51
51
  }
52
- return Eithers.chain3(nodeShapeIdentifierMintingStrategy(nodeShape), shapeNodeKinds(nodeShape, { defaultNodeShapeNodeKinds }), nodeShape.constraints.xone).chain(([identifierMintingStrategy, nodeKinds, xone]) => {
52
+ return Eithers.chain3(nodeShapeIdentifierMintingStrategy.call(this, nodeShape), shapeNodeKinds.call(this, nodeShape, { defaultNodeShapeNodeKinds }), Either.sequence(nodeShape.xone.flatMap((xone) => xone.map((shapeIdentifier) => this.shapesGraph.shape(shapeIdentifier))))).chain(([identifierMintingStrategy, nodeKinds, xone]) => {
53
53
  // Put a placeholder in the cache to deal with cyclic references
54
54
  // Remove the placeholder if the transformation fails.
55
55
  const listType = new ast.ListType({
@@ -60,27 +60,27 @@ export function transformShapeToAstListType(shape, shapeStack) {
60
60
  mutable: nodeShape.mutable.orDefault(false),
61
61
  name: shapeAstTypeName(nodeShape),
62
62
  identifierMintingStrategy,
63
- shapeIdentifier: nodeShape.identifier,
63
+ shapeIdentifier: nodeShape.$identifier,
64
64
  toRdfTypes: nodeShape.toRdfTypes,
65
65
  });
66
- this.cachedAstTypesByShapeIdentifier.set(nodeShape.identifier, listType);
66
+ this.cachedAstTypesByShapeIdentifier.set(nodeShape.$identifier, listType);
67
67
  return (() => {
68
68
  let emptyListShape;
69
69
  let nonEmptyListShape;
70
70
  for (const shape of xone) {
71
- if (shape.constraints.hasValues.length === 1 &&
72
- shape.constraints.hasValues[0].equals(rdf.nil)) {
71
+ if (shape.hasValues.length === 1 &&
72
+ shape.hasValues[0].equals(rdf.nil)) {
73
73
  emptyListShape = shape;
74
74
  }
75
- else if (shape.kind === "NodeShape" &&
76
- shape.constraints.properties.orDefault([]).length >= 2) {
75
+ else if (shape.$type === "NodeShape" &&
76
+ shape.properties.length >= 2) {
77
77
  nonEmptyListShape = shape;
78
78
  }
79
79
  }
80
80
  if (!emptyListShape || !nonEmptyListShape) {
81
81
  return Left(new Error(`${nodeShape} does not have an sh:xone with exactly two shapes, one for the empty list and one for the non-empty list`));
82
82
  }
83
- return nonEmptyListShape.constraints.properties.chain((nonEmptyListShapeProperties) => {
83
+ return Either.sequence(nonEmptyListShape.properties.map((propertyShapeIdentifier) => this.shapesGraph.propertyShape(propertyShapeIdentifier))).chain((nonEmptyListShapeProperties) => {
84
84
  let firstPropertyShape;
85
85
  let restPropertyShape;
86
86
  for (const propertyShape of nonEmptyListShapeProperties) {
@@ -97,15 +97,15 @@ export function transformShapeToAstListType(shape, shapeStack) {
97
97
  if (!firstPropertyShape) {
98
98
  return Left(new Error(`${nodeShape} has a non-empty list shape without an sh:property shape whose sh:path is rdf:first`));
99
99
  }
100
- if (firstPropertyShape.constraints.maxCount.extract() !== 1 ||
101
- firstPropertyShape.constraints.minCount.extract() !== 1) {
100
+ if (firstPropertyShape.maxCount.extract() !== 1 ||
101
+ firstPropertyShape.minCount.extract() !== 1) {
102
102
  return Left(new Error(`${nodeShape} non-empty list shape rdf:first property shape does not have sh:maxCount=1 and/or sh:minCount=1`));
103
103
  }
104
104
  if (!restPropertyShape) {
105
105
  return Left(new Error(`${nodeShape} has a non-empty list shape without an sh:property shape whose sh:path is rdf:rest`));
106
106
  }
107
- if (restPropertyShape.constraints.maxCount.extract() !== 1 ||
108
- restPropertyShape.constraints.minCount.extract() !== 1) {
107
+ if (restPropertyShape.maxCount.extract() !== 1 ||
108
+ restPropertyShape.minCount.extract() !== 1) {
109
109
  return Left(new Error(`${nodeShape} non-empty list shape rdf:rest property shape does not have sh:maxCount=1 and/or sh:minCount=1`));
110
110
  }
111
111
  return transformPropertyShapeToAstObjectTypeProperty
@@ -127,7 +127,7 @@ export function transformShapeToAstListType(shape, shapeStack) {
127
127
  })
128
128
  .chain((restProperty) => {
129
129
  if (restProperty.type.kind !== "ListType" ||
130
- !restProperty.type.shapeIdentifier.equals(nodeShape.identifier)) {
130
+ !restProperty.type.shapeIdentifier.equals(nodeShape.$identifier)) {
131
131
  return Left(new Error(`${nodeShape} rdf:rest property is not recursive into the node shape`));
132
132
  }
133
133
  return Either.of(Maybe.of(listType));
@@ -135,7 +135,7 @@ export function transformShapeToAstListType(shape, shapeStack) {
135
135
  });
136
136
  });
137
137
  })().ifLeft(() => {
138
- this.cachedAstTypesByShapeIdentifier.delete(nodeShape.identifier);
138
+ this.cachedAstTypesByShapeIdentifier.delete(nodeShape.$identifier);
139
139
  });
140
140
  });
141
141
  }