@shaclmate/compiler 4.0.10 → 4.0.12

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.
@@ -1,10 +1,6 @@
1
1
  import { NodeKind } from "@shaclmate/shacl-ast";
2
2
  import { Either, Left } from "purify-ts";
3
- const defaultNodeShapeNodeKinds = new Set([
4
- "BlankNode",
5
- "IRI",
6
- "Literal",
7
- ]);
3
+ import { defaultNodeShapeNodeKinds } from "./defaultNodeShapeNodeKinds.js";
8
4
  const defaultPropertyShapeNodeKinds = new Set([
9
5
  "BlankNode",
10
6
  "IRI",
@@ -169,7 +165,11 @@ export function shapeNodeKinds(shape, options) {
169
165
  if (shape.kind === "NodeShape") {
170
166
  return Either.of(options?.defaultNodeShapeNodeKinds ?? defaultNodeShapeNodeKinds);
171
167
  }
172
- return Either.of(options?.defaultPropertyShapeNodeKinds ?? defaultPropertyShapeNodeKinds);
168
+ if (shape.path.termType === "InversePath") {
169
+ // Inverse paths can only have blank nodes and IRIs as values, because the value is the subject of a triple.
170
+ return Either.of(new Set(["BlankNode", "IRI"]));
171
+ }
172
+ return Either.of(defaultPropertyShapeNodeKinds);
173
173
  });
174
174
  }
175
175
  //# sourceMappingURL=shapeNodeKinds.js.map
@@ -137,7 +137,10 @@ export function transformPropertyShapeToAstObjectTypeProperty({ objectType, prop
137
137
  case "ObjectType":
138
138
  return Either.of(astResolveType);
139
139
  case "UnionType":
140
- if (!astResolveType.isObjectUnionType()) {
140
+ if (
141
+ // This check relies on .members being populated, which may not happen in cycles
142
+ astResolveType.members.length > 0 &&
143
+ !astResolveType.isObjectUnionType()) {
141
144
  return Left(new Error(`${propertyShape} resolve cannot refer to a ${astResolveType.kind} with non-ObjectType members`));
142
145
  }
143
146
  return Either.of(astResolveType);
@@ -237,6 +240,10 @@ export function transformPropertyShapeToAstObjectTypeProperty({ objectType, prop
237
240
  invariant(false, `unexpected lazy AST type ${astType.kind}`);
238
241
  }
239
242
  }
243
+ if (propertyShape.path.termType === "InversePath" &&
244
+ astType.nodeKinds.has("Literal")) {
245
+ return Left(new Error(`${propertyShape}: property shapes with inverse paths can only have blank node or IRI node kinds`));
246
+ }
240
247
  return Either.of(new ast.ObjectType.Property({
241
248
  comment: propertyShape.comment,
242
249
  description: propertyShape.description,
@@ -1,3 +1,4 @@
1
+ import type { NodeKind } from "@shaclmate/shacl-ast";
1
2
  import type { TsFeature } from "../enums/TsFeature.js";
2
3
  import { AbstractType } from "./AbstractType.js";
3
4
  import type { BlankNodeType } from "./BlankNodeType.js";
@@ -25,6 +26,7 @@ export declare abstract class AbstractCompoundType<MemberT extends AbstractCompo
25
26
  tsFeatures: ReadonlySet<TsFeature>;
26
27
  } & ConstructorParameters<typeof AbstractType>[0]);
27
28
  get members(): readonly MemberT[];
29
+ get nodeKinds(): ReadonlySet<NodeKind>;
28
30
  get recursive(): boolean;
29
31
  get tsFeatures(): ReadonlySet<TsFeature>;
30
32
  addMember(member: MemberT): void;
@@ -4,7 +4,6 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
4
4
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6
6
  };
7
- import { invariant } from "ts-invariant";
8
7
  import { Memoize } from "typescript-memoize";
9
8
  import { AbstractType } from "./AbstractType.js";
10
9
  /**
@@ -29,9 +28,17 @@ export class AbstractCompoundType extends AbstractType {
29
28
  this.#tsFeatures = tsFeatures;
30
29
  }
31
30
  get members() {
32
- invariant(this.#members.length > 0);
33
31
  return this.#members;
34
32
  }
33
+ get nodeKinds() {
34
+ const nodeKinds = new Set();
35
+ for (const member of this.members) {
36
+ for (const nodeKind of member.type.nodeKinds) {
37
+ nodeKinds.add(nodeKind);
38
+ }
39
+ }
40
+ return nodeKinds;
41
+ }
35
42
  get recursive() {
36
43
  return this.members.some((member) => member.type.recursive);
37
44
  }
@@ -77,6 +84,9 @@ export class AbstractCompoundType extends AbstractType {
77
84
  return `${this.kind}(memberTypes=[${this.members.map((memberType) => memberType.toString()).join(", ")}])`;
78
85
  }
79
86
  }
87
+ __decorate([
88
+ Memoize()
89
+ ], AbstractCompoundType.prototype, "nodeKinds", null);
80
90
  __decorate([
81
91
  Memoize()
82
92
  ], AbstractCompoundType.prototype, "tsFeatures", null);
@@ -1,3 +1,4 @@
1
+ import type { NodeKind } from "@shaclmate/shacl-ast";
1
2
  import { AbstractType } from "./AbstractType.js";
2
3
  import type { BlankNodeType } from "./BlankNodeType.js";
3
4
  import type { IdentifierType } from "./IdentifierType.js";
@@ -23,6 +24,7 @@ export declare abstract class AbstractContainerType<ItemTypeT extends AbstractCo
23
24
  constructor({ itemType, ...superParameters }: {
24
25
  itemType: ItemTypeT;
25
26
  } & ConstructorParameters<typeof AbstractType>[0]);
27
+ get nodeKinds(): ReadonlySet<NodeKind>;
26
28
  get recursive(): boolean;
27
29
  equals(other: AbstractContainerType<ItemTypeT>): boolean;
28
30
  toString(): string;
@@ -14,6 +14,9 @@ export class AbstractContainerType extends AbstractType {
14
14
  super(superParameters);
15
15
  this.itemType = itemType;
16
16
  }
17
+ get nodeKinds() {
18
+ return this.itemType.nodeKinds;
19
+ }
17
20
  get recursive() {
18
21
  return this.itemType.recursive;
19
22
  }
@@ -1,3 +1,4 @@
1
+ import type { NodeKind } from "@shaclmate/shacl-ast";
1
2
  import { AbstractType } from "./AbstractType.js";
2
3
  import type { ObjectType } from "./ObjectType.js";
3
4
  import type { ObjectUnionType } from "./ObjectUnionType.js";
@@ -14,6 +15,7 @@ export declare abstract class AbstractLazyObjectType<PartialTypeT extends Abstra
14
15
  partialType: PartialTypeT;
15
16
  resolveType: ResolveTypeT;
16
17
  } & ConstructorParameters<typeof AbstractType>[0]);
18
+ get nodeKinds(): ReadonlySet<NodeKind>;
17
19
  get recursive(): boolean;
18
20
  equals(other: AbstractLazyObjectType<PartialTypeT, ResolveTypeT>): boolean;
19
21
  toString(): string;
@@ -11,6 +11,9 @@ export class AbstractLazyObjectType extends AbstractType {
11
11
  this.partialType = partialType;
12
12
  this.resolveType = resolveType;
13
13
  }
14
+ get nodeKinds() {
15
+ return this.partialType.nodeKinds;
16
+ }
14
17
  get recursive() {
15
18
  return this.partialType.recursive;
16
19
  }
@@ -1,5 +1,4 @@
1
1
  import type { BlankNode, Literal, NamedNode } from "@rdfjs/types";
2
- import type { NodeKind } from "@shaclmate/shacl-ast";
3
2
  import { AbstractType } from "./AbstractType.js";
4
3
  /**
5
4
  * Abstract base class of term types (BlankNodeType, IdentifierType, LiteralType, IriType, TermType).
@@ -13,7 +12,6 @@ export declare abstract class AbstractTermType<ConstantTermT extends Literal | N
13
12
  readonly hasValues: readonly ConstantTermT[];
14
13
  readonly in_: readonly ConstantTermT[];
15
14
  abstract readonly kind: "BlankNodeType" | "IdentifierType" | "IriType" | "LiteralType" | "TermType";
16
- abstract readonly nodeKinds: ReadonlySet<NodeKind>;
17
15
  readonly recursive = false;
18
16
  constructor({ hasValues, in_, ...superParameters }: {
19
17
  hasValues: readonly ConstantTermT[];
@@ -1,4 +1,5 @@
1
1
  import type { BlankNode, NamedNode } from "@rdfjs/types";
2
+ import type { NodeKind } from "@shaclmate/shacl-ast";
2
3
  import { Maybe } from "purify-ts";
3
4
  /**
4
5
  * Abstract base class for Types.
@@ -16,6 +17,12 @@ export declare abstract class AbstractType {
16
17
  * Name of this type, from shaclmate:name or sh:name.
17
18
  */
18
19
  readonly name: Maybe<string>;
20
+ /**
21
+ * The range of node kinds of this type.
22
+ *
23
+ * For example, an object type has blank and IRI node kinds, while a string type has a Literal node kind.
24
+ */
25
+ abstract readonly nodeKinds: ReadonlySet<NodeKind>;
19
26
  /**
20
27
  * Does this type directly or indirectly reference itself?
21
28
  */
@@ -5,9 +5,10 @@ import { AbstractCompoundType } from "./AbstractCompoundType.js";
5
5
  export class IntersectionType extends AbstractCompoundType {
6
6
  kind = "IntersectionType";
7
7
  isObjectIntersectionType() {
8
- return this.members.every((member) => member.type.kind === "ObjectType" ||
9
- (member.type.kind === "IntersectionType" &&
10
- member.type.isObjectIntersectionType()));
8
+ return (this.members.length > 0 &&
9
+ this.members.every((member) => member.type.kind === "ObjectType" ||
10
+ (member.type.kind === "IntersectionType" &&
11
+ member.type.isObjectIntersectionType())));
11
12
  }
12
13
  }
13
14
  (function (IntersectionType) {
@@ -1,4 +1,5 @@
1
1
  import type { BlankNode, NamedNode } from "@rdfjs/types";
2
+ import type { NodeKind } from "@shaclmate/shacl-ast";
2
3
  import type { Maybe } from "purify-ts";
3
4
  import { PropertyPath } from "rdfjs-resource";
4
5
  import type { IdentifierMintingStrategy } from "../enums/IdentifierMintingStrategy.js";
@@ -43,6 +44,7 @@ export declare class ObjectType extends AbstractType {
43
44
  * Type discriminant.
44
45
  */
45
46
  readonly kind = "ObjectType";
47
+ readonly nodeKinds: ReadonlySet<NodeKind>;
46
48
  /**
47
49
  * Was this type synthesized or did it come from SHACL?
48
50
  */
@@ -73,6 +73,7 @@ export class ObjectType extends AbstractType {
73
73
  * Type discriminant.
74
74
  */
75
75
  kind = "ObjectType";
76
+ nodeKinds = nodeKinds;
76
77
  /**
77
78
  * Was this type synthesized or did it come from SHACL?
78
79
  */
@@ -169,6 +170,7 @@ export class ObjectType extends AbstractType {
169
170
  return `${this.kind}(shapeIdentifier=${Resource.Identifier.toString(this.shapeIdentifier)})`;
170
171
  }
171
172
  }
173
+ const nodeKinds = new Set(["BlankNode", "IRI"]);
172
174
  (function (ObjectType) {
173
175
  class Property {
174
176
  /**
@@ -5,8 +5,9 @@ import { AbstractCompoundType } from "./AbstractCompoundType.js";
5
5
  export class UnionType extends AbstractCompoundType {
6
6
  kind = "UnionType";
7
7
  isObjectUnionType() {
8
- return this.members.every((member) => member.type.kind === "ObjectType" ||
9
- (member.type.kind === "UnionType" && member.type.isObjectUnionType()));
8
+ return (this.members.length > 0 &&
9
+ this.members.every((member) => member.type.kind === "ObjectType" ||
10
+ (member.type.kind === "UnionType" && member.type.isObjectUnionType())));
10
11
  }
11
12
  }
12
13
  (function (UnionType) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "dependencies": {
3
- "@shaclmate/shacl-ast": "4.0.10",
3
+ "@shaclmate/shacl-ast": "4.0.12",
4
4
  "@rdfjs/data-model": "~2.1.1",
5
5
  "@rdfjs/dataset": "~2.0.2",
6
6
  "@rdfjs/prefix-map": "~0.1.2",
@@ -78,5 +78,5 @@
78
78
  },
79
79
  "type": "module",
80
80
  "types": "./dist/index.d.ts",
81
- "version": "4.0.10"
81
+ "version": "4.0.12"
82
82
  }