@shaclmate/shacl-ast 4.0.7 → 4.0.9

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.
@@ -0,0 +1,21 @@
1
+ import type { BlankNode, NamedNode } from "@rdfjs/types";
2
+ /**
3
+ * A Compact URI (https://www.w3.org/TR/curie)
4
+ */
5
+ export declare class Curie implements NamedNode {
6
+ #private;
7
+ readonly prefix: string;
8
+ readonly reference: string;
9
+ readonly termType = "NamedNode";
10
+ readonly value: string;
11
+ constructor({ hasUniqueReference, prefix, reference, value, }: {
12
+ hasUniqueReference?: () => boolean;
13
+ prefix: string;
14
+ reference: string;
15
+ value: string;
16
+ });
17
+ equals(other: BlankNode | NamedNode): boolean;
18
+ get hasUniqueReference(): boolean;
19
+ toString(): string;
20
+ }
21
+ //# sourceMappingURL=Curie.d.ts.map
package/dist/Curie.js ADDED
@@ -0,0 +1,29 @@
1
+ /**
2
+ * A Compact URI (https://www.w3.org/TR/curie)
3
+ */
4
+ export class Curie {
5
+ prefix;
6
+ #hasUniqueReference;
7
+ reference;
8
+ termType = "NamedNode";
9
+ value;
10
+ constructor({ hasUniqueReference, prefix, reference, value, }) {
11
+ this.#hasUniqueReference = hasUniqueReference ?? (() => false);
12
+ this.prefix = prefix;
13
+ this.reference = reference;
14
+ this.value = value;
15
+ }
16
+ equals(other) {
17
+ if (other.termType === "BlankNode") {
18
+ return false;
19
+ }
20
+ return this.value === other.value; // Allow a Curie to equal a NamedNode
21
+ }
22
+ get hasUniqueReference() {
23
+ return this.#hasUniqueReference();
24
+ }
25
+ toString() {
26
+ return `${this.prefix}:${this.reference}`;
27
+ }
28
+ }
29
+ //# sourceMappingURL=Curie.js.map
@@ -0,0 +1,16 @@
1
+ import type PrefixMap from "@rdfjs/prefix-map/PrefixMap.js";
2
+ import type { NamedNode } from "@rdfjs/types";
3
+ import { Maybe } from "purify-ts";
4
+ import { Curie } from "./Curie.js";
5
+ /**
6
+ * Factory for Compact URIs (CURIEs). Tracks whether the reference part of the CURIE is unique.
7
+ */
8
+ export declare class CurieFactory {
9
+ private readonly prefixMap;
10
+ private readonly referenceCounts;
11
+ constructor({ prefixMap }: {
12
+ prefixMap: PrefixMap;
13
+ });
14
+ create(namedNode: NamedNode): Maybe<Curie>;
15
+ }
16
+ //# sourceMappingURL=CurieFactory.d.ts.map
@@ -0,0 +1,46 @@
1
+ import { Maybe } from "purify-ts";
2
+ import { invariant } from "ts-invariant";
3
+ import { Curie } from "./Curie.js";
4
+ /**
5
+ * Factory for Compact URIs (CURIEs). Tracks whether the reference part of the CURIE is unique.
6
+ */
7
+ export class CurieFactory {
8
+ prefixMap;
9
+ referenceCounts = {};
10
+ constructor({ prefixMap }) {
11
+ this.prefixMap = prefixMap;
12
+ }
13
+ create(namedNode) {
14
+ return Maybe.fromNullable(this.prefixMap.shrink(namedNode)?.value).map((value) => {
15
+ const split = value.split(":", 2);
16
+ invariant(split.length === 2);
17
+ const prefix = split[0];
18
+ const reference = split[1];
19
+ if (this.referenceCounts[reference] === undefined) {
20
+ this.referenceCounts[reference] = {};
21
+ }
22
+ if (this.referenceCounts[reference][prefix] === undefined) {
23
+ this.referenceCounts[reference][prefix] = 1;
24
+ }
25
+ else {
26
+ this.referenceCounts[reference][prefix] += 1;
27
+ }
28
+ return new Curie({
29
+ hasUniqueReference: () => {
30
+ const referenceCounts = this.referenceCounts[reference];
31
+ if (Object.entries(referenceCounts).length === 1) {
32
+ return true;
33
+ }
34
+ // logger.debug(
35
+ // `duplicate local part ${reference} in ${JSON.stringify(referenceCounts)}`,
36
+ // );
37
+ return false;
38
+ },
39
+ prefix: split[0],
40
+ reference: split[1],
41
+ value: namedNode.value,
42
+ });
43
+ });
44
+ }
45
+ }
46
+ //# sourceMappingURL=CurieFactory.js.map
@@ -5,13 +5,13 @@ import { Shape } from "./Shape.js";
5
5
  import type { ShapesGraph } from "./ShapesGraph.js";
6
6
  export declare class NodeShape<NodeShapeT extends ShapeT, OntologyT extends OntologyLike, PropertyGroupT, PropertyShapeT extends ShapeT, ShapeT> extends Shape<NodeShapeT, OntologyT, PropertyGroupT, PropertyShapeT, ShapeT> {
7
7
  readonly constraints: NodeShape.Constraints<NodeShapeT, OntologyT, PropertyGroupT, PropertyShapeT, ShapeT>;
8
- constructor(generatedShaclCoreNodeShape: Omit<generated.ShaclCoreNodeShape, "$type">, shapesGraph: ShapesGraph<NodeShapeT, OntologyT, PropertyGroupT, PropertyShapeT, ShapeT>);
8
+ constructor(generatedNodeShape: Omit<generated.NodeShape, "$type">, shapesGraph: ShapesGraph<NodeShapeT, OntologyT, PropertyGroupT, PropertyShapeT, ShapeT>);
9
9
  toString(): string;
10
10
  }
11
11
  export declare namespace NodeShape {
12
12
  class Constraints<NodeShapeT extends ShapeT, OntologyT extends OntologyLike, PropertyGroupT, PropertyShapeT extends ShapeT, ShapeT> extends Shape.Constraints<NodeShapeT, OntologyT, PropertyGroupT, PropertyShapeT, ShapeT> {
13
- private readonly generatedShaclCoreNodeShape;
14
- constructor(generatedShaclCoreNodeShape: Omit<generated.ShaclCoreNodeShape, "$type">, shapesGraph: ShapesGraph<NodeShapeT, OntologyT, PropertyGroupT, PropertyShapeT, ShapeT>);
13
+ private readonly generatedNodeShape;
14
+ constructor(generatedNodeShape: Omit<generated.NodeShape, "$type">, shapesGraph: ShapesGraph<NodeShapeT, OntologyT, PropertyGroupT, PropertyShapeT, ShapeT>);
15
15
  get closed(): Maybe<boolean>;
16
16
  get properties(): Either<Error, readonly PropertyShapeT[]>;
17
17
  }
package/dist/NodeShape.js CHANGED
@@ -10,9 +10,9 @@ import { Memoize } from "typescript-memoize";
10
10
  import { Shape } from "./Shape.js";
11
11
  export class NodeShape extends Shape {
12
12
  constraints;
13
- constructor(generatedShaclCoreNodeShape, shapesGraph) {
14
- super(generatedShaclCoreNodeShape, shapesGraph);
15
- this.constraints = new NodeShape.Constraints(generatedShaclCoreNodeShape, shapesGraph);
13
+ constructor(generatedNodeShape, shapesGraph) {
14
+ super(generatedNodeShape, shapesGraph);
15
+ this.constraints = new NodeShape.Constraints(generatedNodeShape, shapesGraph);
16
16
  }
17
17
  toString() {
18
18
  return `NodeShape(identifier=${Resource.Identifier.toString(this.identifier)})`;
@@ -23,16 +23,16 @@ __decorate([
23
23
  ], NodeShape.prototype, "toString", null);
24
24
  (function (NodeShape) {
25
25
  class Constraints extends Shape.Constraints {
26
- generatedShaclCoreNodeShape;
27
- constructor(generatedShaclCoreNodeShape, shapesGraph) {
28
- super(generatedShaclCoreNodeShape, shapesGraph);
29
- this.generatedShaclCoreNodeShape = generatedShaclCoreNodeShape;
26
+ generatedNodeShape;
27
+ constructor(generatedNodeShape, shapesGraph) {
28
+ super(generatedNodeShape, shapesGraph);
29
+ this.generatedNodeShape = generatedNodeShape;
30
30
  }
31
31
  get closed() {
32
- return this.generatedShaclCoreNodeShape.closed;
32
+ return this.generatedNodeShape.closed;
33
33
  }
34
34
  get properties() {
35
- return Either.sequence(this.generatedShaclCoreNodeShape.properties.map((identifier) => this.shapesGraph.propertyShapeByIdentifier(identifier)));
35
+ return Either.sequence(this.generatedNodeShape.properties.map((identifier) => this.shapesGraph.propertyShapeByIdentifier(identifier)));
36
36
  }
37
37
  }
38
38
  __decorate([
@@ -3,7 +3,7 @@ import type * as generated from "./generated.js";
3
3
  import type { OntologyLike } from "./OntologyLike.js";
4
4
  export declare class Ontology implements OntologyLike {
5
5
  private readonly generatedOntology;
6
- constructor(generatedOntology: Omit<generated.OwlOntology, "$type">);
6
+ constructor(generatedOntology: Omit<generated.Ontology, "$type">);
7
7
  get identifier(): BlankNode | NamedNode;
8
8
  toString(): string;
9
9
  }
@@ -2,7 +2,7 @@ import type { BlankNode, NamedNode } from "@rdfjs/types";
2
2
  import type * as generated from "./generated.js";
3
3
  export declare class PropertyGroup {
4
4
  private readonly delegate;
5
- constructor(delegate: generated.ShaclCorePropertyGroup);
5
+ constructor(delegate: generated.PropertyGroup);
6
6
  get comments(): readonly string[];
7
7
  get identifier(): BlankNode | NamedNode;
8
8
  get labels(): readonly string[];
@@ -6,9 +6,9 @@ import type { OntologyLike } from "./OntologyLike.js";
6
6
  import { Shape } from "./Shape.js";
7
7
  import type { ShapesGraph } from "./ShapesGraph.js";
8
8
  export declare class PropertyShape<NodeShapeT extends ShapeT, OntologyT extends OntologyLike, PropertyGroupT, PropertyShapeT extends ShapeT, ShapeT> extends Shape<NodeShapeT, OntologyT, PropertyGroupT, PropertyShapeT, ShapeT> {
9
- private readonly generatedShaclCorePropertyShape;
9
+ private readonly generatedPropertyShape;
10
10
  readonly constraints: Shape.Constraints<NodeShapeT, OntologyT, PropertyGroupT, PropertyShapeT, ShapeT>;
11
- constructor(generatedShaclCorePropertyShape: Omit<generated.ShaclCorePropertyShape, "$type">, shapesGraph: ShapesGraph<NodeShapeT, OntologyT, PropertyGroupT, PropertyShapeT, ShapeT>);
11
+ constructor(generatedPropertyShape: Omit<generated.PropertyShape, "$type">, shapesGraph: ShapesGraph<NodeShapeT, OntologyT, PropertyGroupT, PropertyShapeT, ShapeT>);
12
12
  get defaultValue(): Maybe<Literal | NamedNode>;
13
13
  get descriptions(): readonly string[];
14
14
  get groups(): Either<Error, readonly PropertyGroupT[]>;
@@ -9,35 +9,35 @@ import { PropertyPath, Resource } from "rdfjs-resource";
9
9
  import { Memoize } from "typescript-memoize";
10
10
  import { Shape } from "./Shape.js";
11
11
  export class PropertyShape extends Shape {
12
- generatedShaclCorePropertyShape;
12
+ generatedPropertyShape;
13
13
  constraints;
14
- constructor(generatedShaclCorePropertyShape, shapesGraph) {
15
- super(generatedShaclCorePropertyShape, shapesGraph);
16
- this.generatedShaclCorePropertyShape = generatedShaclCorePropertyShape;
17
- this.constraints = new Shape.Constraints(generatedShaclCorePropertyShape, shapesGraph);
14
+ constructor(generatedPropertyShape, shapesGraph) {
15
+ super(generatedPropertyShape, shapesGraph);
16
+ this.generatedPropertyShape = generatedPropertyShape;
17
+ this.constraints = new Shape.Constraints(generatedPropertyShape, shapesGraph);
18
18
  }
19
19
  get defaultValue() {
20
- return this.generatedShaclCorePropertyShape.defaultValue;
20
+ return this.generatedPropertyShape.defaultValue;
21
21
  }
22
22
  get descriptions() {
23
- return this.generatedShaclCorePropertyShape.descriptions;
23
+ return this.generatedPropertyShape.descriptions;
24
24
  }
25
25
  get groups() {
26
- return Either.sequence(this.generatedShaclCorePropertyShape.groups.map((identifier) => this.shapesGraph.propertyGroupByIdentifier(identifier)));
26
+ return Either.sequence(this.generatedPropertyShape.groups.map((identifier) => this.shapesGraph.propertyGroupByIdentifier(identifier)));
27
27
  }
28
28
  get names() {
29
- return this.generatedShaclCorePropertyShape.names;
29
+ return this.generatedPropertyShape.names;
30
30
  }
31
31
  get order() {
32
- return this.generatedShaclCorePropertyShape.order;
32
+ return this.generatedPropertyShape.order;
33
33
  }
34
34
  get path() {
35
- return this.generatedShaclCorePropertyShape.path;
35
+ return this.generatedPropertyShape.path;
36
36
  }
37
37
  toString() {
38
38
  return `PropertyShape(${[
39
39
  `identifier=${Resource.Identifier.toString(this.identifier)}`,
40
- `path=${PropertyPath.$toString(this.path)}`,
40
+ `path=${PropertyPath.toString(this.path)}`,
41
41
  ].join(", ")})`;
42
42
  }
43
43
  }
package/dist/Shape.d.ts CHANGED
@@ -5,10 +5,10 @@ import type { NodeKind } from "./NodeKind.js";
5
5
  import type { OntologyLike } from "./OntologyLike.js";
6
6
  import type { ShapesGraph } from "./ShapesGraph.js";
7
7
  export declare abstract class Shape<NodeShapeT extends ShapeT, OntologyT extends OntologyLike, PropertyGroupT, PropertyShapeT extends ShapeT, ShapeT> {
8
- private readonly generatedShaclCoreShape;
8
+ private readonly generatedShape;
9
9
  protected readonly shapesGraph: ShapesGraph<NodeShapeT, OntologyT, PropertyGroupT, PropertyShapeT, ShapeT>;
10
10
  abstract readonly constraints: Shape.Constraints<NodeShapeT, OntologyT, PropertyGroupT, PropertyShapeT, ShapeT>;
11
- constructor(generatedShaclCoreShape: Omit<generated.ShaclCoreShape, "$type">, shapesGraph: ShapesGraph<NodeShapeT, OntologyT, PropertyGroupT, PropertyShapeT, ShapeT>);
11
+ constructor(generatedShape: Omit<generated.Shape, "$type">, shapesGraph: ShapesGraph<NodeShapeT, OntologyT, PropertyGroupT, PropertyShapeT, ShapeT>);
12
12
  get comments(): readonly string[];
13
13
  get identifier(): BlankNode | NamedNode;
14
14
  get isDefinedBy(): Either<Error, Maybe<OntologyT>>;
@@ -16,9 +16,9 @@ export declare abstract class Shape<NodeShapeT extends ShapeT, OntologyT extends
16
16
  }
17
17
  export declare namespace Shape {
18
18
  class Constraints<NodeShapeT extends ShapeT, OntologyT extends OntologyLike, PropertyGroupT, PropertyShapeT extends ShapeT, ShapeT> {
19
- private readonly generatedShaclCoreShape;
19
+ private readonly generatedShape;
20
20
  protected readonly shapesGraph: ShapesGraph<NodeShapeT, OntologyT, PropertyGroupT, PropertyShapeT, ShapeT>;
21
- constructor(generatedShaclCoreShape: Omit<generated.ShaclCoreShape, "$type">, shapesGraph: ShapesGraph<NodeShapeT, OntologyT, PropertyGroupT, PropertyShapeT, ShapeT>);
21
+ constructor(generatedShape: Omit<generated.Shape, "$type">, shapesGraph: ShapesGraph<NodeShapeT, OntologyT, PropertyGroupT, PropertyShapeT, ShapeT>);
22
22
  get and(): Either<Error, readonly ShapeT[]>;
23
23
  get classes(): readonly NamedNode[];
24
24
  get datatype(): Maybe<NamedNode>;
package/dist/Shape.js CHANGED
@@ -7,23 +7,23 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
7
7
  import { Either, Maybe } from "purify-ts";
8
8
  import { Memoize } from "typescript-memoize";
9
9
  export class Shape {
10
- generatedShaclCoreShape;
10
+ generatedShape;
11
11
  shapesGraph;
12
- constructor(generatedShaclCoreShape, shapesGraph) {
13
- this.generatedShaclCoreShape = generatedShaclCoreShape;
12
+ constructor(generatedShape, shapesGraph) {
13
+ this.generatedShape = generatedShape;
14
14
  this.shapesGraph = shapesGraph;
15
15
  }
16
16
  get comments() {
17
- return this.generatedShaclCoreShape.comments;
17
+ return this.generatedShape.comments;
18
18
  }
19
19
  get identifier() {
20
- return this.generatedShaclCoreShape.$identifier;
20
+ return this.generatedShape.$identifier;
21
21
  }
22
22
  get isDefinedBy() {
23
- if (this.generatedShaclCoreShape.isDefinedBy.isJust()) {
23
+ if (this.generatedShape.isDefinedBy.isJust()) {
24
24
  // If there's an rdfs:isDefinedBy statement on the shape then don't fall back to anything else
25
25
  return this.shapesGraph
26
- .ontologyByIdentifier(this.generatedShaclCoreShape.isDefinedBy.unsafeCoerce())
26
+ .ontologyByIdentifier(this.generatedShape.isDefinedBy.unsafeCoerce())
27
27
  .map(Maybe.of);
28
28
  }
29
29
  // No rdfs:isDefinedBy statement on the shape
@@ -43,7 +43,7 @@ export class Shape {
43
43
  return Either.of(Maybe.empty());
44
44
  }
45
45
  get labels() {
46
- return this.generatedShaclCoreShape.labels;
46
+ return this.generatedShape.labels;
47
47
  }
48
48
  }
49
49
  __decorate([
@@ -51,50 +51,50 @@ __decorate([
51
51
  ], Shape.prototype, "isDefinedBy", null);
52
52
  (function (Shape) {
53
53
  class Constraints {
54
- generatedShaclCoreShape;
54
+ generatedShape;
55
55
  shapesGraph;
56
- constructor(generatedShaclCoreShape, shapesGraph) {
57
- this.generatedShaclCoreShape = generatedShaclCoreShape;
56
+ constructor(generatedShape, shapesGraph) {
57
+ this.generatedShape = generatedShape;
58
58
  this.shapesGraph = shapesGraph;
59
59
  }
60
60
  get and() {
61
- return this.shapeListTakingConstraint(this.generatedShaclCoreShape.and);
61
+ return this.shapeListTakingConstraint(this.generatedShape.and);
62
62
  }
63
63
  get classes() {
64
- return this.generatedShaclCoreShape.classes;
64
+ return this.generatedShape.classes;
65
65
  }
66
66
  get datatype() {
67
- return this.generatedShaclCoreShape.datatype;
67
+ return this.generatedShape.datatype;
68
68
  }
69
69
  get hasValues() {
70
- return this.generatedShaclCoreShape.hasValues;
70
+ return this.generatedShape.hasValues;
71
71
  }
72
72
  get in_() {
73
- return this.generatedShaclCoreShape.in_.orDefault([]);
73
+ return this.generatedShape.in_.orDefault([]);
74
74
  }
75
75
  get languageIn() {
76
- return this.generatedShaclCoreShape.languageIn.orDefault([]);
76
+ return this.generatedShape.languageIn.orDefault([]);
77
77
  }
78
78
  get maxCount() {
79
- return this.generatedShaclCoreShape.maxCount;
79
+ return this.generatedShape.maxCount;
80
80
  }
81
81
  get maxExclusive() {
82
- return this.generatedShaclCoreShape.maxExclusive;
82
+ return this.generatedShape.maxExclusive;
83
83
  }
84
84
  get maxInclusive() {
85
- return this.generatedShaclCoreShape.maxInclusive;
85
+ return this.generatedShape.maxInclusive;
86
86
  }
87
87
  get minCount() {
88
- return this.generatedShaclCoreShape.minCount;
88
+ return this.generatedShape.minCount;
89
89
  }
90
90
  get minExclusive() {
91
- return this.generatedShaclCoreShape.minExclusive;
91
+ return this.generatedShape.minExclusive;
92
92
  }
93
93
  get minInclusive() {
94
- return this.generatedShaclCoreShape.minInclusive;
94
+ return this.generatedShape.minInclusive;
95
95
  }
96
96
  get nodeKinds() {
97
- return this.generatedShaclCoreShape.nodeKind
97
+ return this.generatedShape.nodeKind
98
98
  .map((iri) => {
99
99
  const nodeKinds = new Set();
100
100
  switch (iri.value) {
@@ -125,16 +125,16 @@ __decorate([
125
125
  .orDefault(new Set([]));
126
126
  }
127
127
  get nodes() {
128
- return Either.sequence(this.generatedShaclCoreShape.nodes.map((identifier) => this.shapesGraph.nodeShapeByIdentifier(identifier)));
128
+ return Either.sequence(this.generatedShape.nodes.map((identifier) => this.shapesGraph.nodeShapeByIdentifier(identifier)));
129
129
  }
130
130
  get not() {
131
- return Either.sequence(this.generatedShaclCoreShape.not.map((identifier) => this.shapesGraph.shapeByIdentifier(identifier)));
131
+ return Either.sequence(this.generatedShape.not.map((identifier) => this.shapesGraph.shapeByIdentifier(identifier)));
132
132
  }
133
133
  get or() {
134
- return this.shapeListTakingConstraint(this.generatedShaclCoreShape.or);
134
+ return this.shapeListTakingConstraint(this.generatedShape.or);
135
135
  }
136
136
  get xone() {
137
- return this.shapeListTakingConstraint(this.generatedShaclCoreShape.xone);
137
+ return this.shapeListTakingConstraint(this.generatedShape.xone);
138
138
  }
139
139
  shapeListTakingConstraint(identifiers) {
140
140
  return Either.sequence(identifiers.flatMap((identifiers) => identifiers.map((identifier) => this.shapesGraph.shapeByIdentifier(identifier))));
@@ -1,7 +1,9 @@
1
+ import PrefixMap from "@rdfjs/prefix-map/PrefixMap.js";
1
2
  import TermMap from "@rdfjs/term-map";
2
3
  import type { BlankNode, DatasetCore, NamedNode } from "@rdfjs/types";
3
4
  import { Either } from "purify-ts";
4
5
  import { Resource } from "rdfjs-resource";
6
+ import { CurieFactory } from "./CurieFactory.js";
5
7
  import { NodeShape } from "./NodeShape.js";
6
8
  import { Ontology } from "./Ontology.js";
7
9
  import type { OntologyLike } from "./OntologyLike.js";
@@ -35,23 +37,28 @@ export declare namespace ShapesGraph {
35
37
  constructor(parameters?: {
36
38
  preferredLanguages?: readonly string[];
37
39
  });
38
- createShapesGraph({ dataset, ignoreUndefinedShapes, }: {
40
+ createShapesGraph({ dataset, prefixMap, ignoreUndefinedShapes, }: {
39
41
  dataset: DatasetCore;
42
+ prefixMap?: PrefixMap;
40
43
  ignoreUndefinedShapes?: boolean;
41
44
  }): Either<Error, ShapesGraph<NodeShapeT, OntologyT, PropertyGroupT, PropertyShapeT, ShapeT>>;
42
45
  protected abstract createNodeShape(parameters: {
46
+ curieFactory: CurieFactory;
43
47
  resource: Resource;
44
48
  shapesGraph: ShapesGraph<NodeShapeT, OntologyT, PropertyGroupT, PropertyShapeT, ShapeT>;
45
49
  }): Either<Error, NodeShapeT>;
46
50
  protected abstract createOntology(parameters: {
51
+ curieFactory: CurieFactory;
47
52
  resource: Resource;
48
53
  shapesGraph: ShapesGraph<NodeShapeT, OntologyT, PropertyGroupT, PropertyShapeT, ShapeT>;
49
54
  }): Either<Error, OntologyT>;
50
55
  protected abstract createPropertyGroup(parameters: {
56
+ curieFactory: CurieFactory;
51
57
  resource: Resource;
52
58
  shapesGraph: ShapesGraph<NodeShapeT, OntologyT, PropertyGroupT, PropertyShapeT, ShapeT>;
53
59
  }): Either<Error, PropertyGroupT>;
54
60
  protected abstract createPropertyShape(parameters: {
61
+ curieFactory: CurieFactory;
55
62
  resource: Resource;
56
63
  shapesGraph: ShapesGraph<NodeShapeT, OntologyT, PropertyGroupT, PropertyShapeT, ShapeT>;
57
64
  }): Either<Error, PropertyShapeT>;
@@ -66,14 +73,17 @@ export declare namespace ShapesGraph {
66
73
  shapesGraph: DefaultShapesGraph;
67
74
  }): Either<Error, NodeShape<DefaultNodeShape, Ontology, PropertyGroup, DefaultPropertyShape, DefaultShape>>;
68
75
  protected createOntology({ resource, }: {
76
+ curieFactory: CurieFactory;
69
77
  resource: Resource;
70
78
  shapesGraph: DefaultShapesGraph;
71
79
  }): Either<Error, Ontology>;
72
80
  protected createPropertyGroup({ resource, }: {
81
+ curieFactory: CurieFactory;
73
82
  resource: Resource;
74
83
  shapesGraph: DefaultShapesGraph;
75
84
  }): Either<Error, PropertyGroup>;
76
- protected createPropertyShape({ resource, shapesGraph, }: {
85
+ protected createPropertyShape({ curieFactory, resource, shapesGraph, }: {
86
+ curieFactory: CurieFactory;
77
87
  resource: Resource;
78
88
  shapesGraph: DefaultShapesGraph;
79
89
  }): Either<Error, DefaultPropertyShape>;
@@ -4,12 +4,15 @@ 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 DataFactory from "@rdfjs/data-model";
8
+ import PrefixMap from "@rdfjs/prefix-map/PrefixMap.js";
7
9
  import TermMap from "@rdfjs/term-map";
8
10
  import TermSet from "@rdfjs/term-set";
9
11
  import { owl, sh } from "@tpluscode/rdf-ns-builders";
10
12
  import { Either, Left } from "purify-ts";
11
13
  import { Resource, ResourceSet } from "rdfjs-resource";
12
14
  import { Memoize } from "typescript-memoize";
15
+ import { CurieFactory } from "./CurieFactory.js";
13
16
  import * as generated from "./generated.js";
14
17
  import { NodeShape } from "./NodeShape.js";
15
18
  import { Ontology } from "./Ontology.js";
@@ -84,14 +87,26 @@ __decorate([
84
87
  constructor(parameters) {
85
88
  this.preferredLanguages = parameters?.preferredLanguages ?? ["en", ""];
86
89
  }
87
- createShapesGraph({ dataset, ignoreUndefinedShapes, }) {
90
+ createShapesGraph({ dataset, prefixMap, ignoreUndefinedShapes, }) {
88
91
  function datasetHasMatch(subject, predicate, object, graph) {
89
92
  for (const _ of dataset.match(subject, predicate, object, graph)) {
90
93
  return true;
91
94
  }
92
95
  return false;
93
96
  }
97
+ const curieFactory = new CurieFactory({
98
+ prefixMap: prefixMap ?? new PrefixMap(undefined, { factory: DataFactory }),
99
+ });
94
100
  const resourceSet = new ResourceSet(dataset);
101
+ const curieResource = (identifier) => {
102
+ if (identifier.termType === "NamedNode") {
103
+ const curie = curieFactory.create(identifier).extract();
104
+ if (curie) {
105
+ return resourceSet.resource(curie);
106
+ }
107
+ }
108
+ return resourceSet.resource(identifier);
109
+ };
95
110
  const nodeShapesByIdentifier = new TermMap();
96
111
  const ontologiesByIdentifier = new TermMap();
97
112
  const propertyGroupsByIdentifier = new TermMap();
@@ -132,7 +147,8 @@ __decorate([
132
147
  continue;
133
148
  }
134
149
  this.createOntology({
135
- resource: ontologyResource,
150
+ curieFactory,
151
+ resource: curieResource(ontologyResource.identifier),
136
152
  shapesGraph,
137
153
  }).ifRight((ontology) => ontologiesByIdentifier.set(ontologyResource.identifier, ontology));
138
154
  }
@@ -145,7 +161,8 @@ __decorate([
145
161
  continue;
146
162
  }
147
163
  this.createPropertyGroup({
148
- resource: propertyGroupResource,
164
+ curieFactory,
165
+ resource: curieResource(propertyGroupResource.identifier),
149
166
  shapesGraph,
150
167
  }).ifRight((propertyGroup) => propertyGroupsByIdentifier.set(propertyGroupResource.identifier, propertyGroup));
151
168
  }
@@ -260,14 +277,16 @@ __decorate([
260
277
  if (dataset.match(shapeNode, sh.path, null, graph).size > 0) {
261
278
  // A property shape is a shape in the shapes graph that is the subject of a triple that has sh:path as its predicate. A shape has at most one value for sh:path. Each value of sh:path in a shape must be a well-formed SHACL property path. It is recommended, but not required, for a property shape to be declared as a SHACL instance of sh:PropertyShape. SHACL instances of sh:PropertyShape have one value for the property sh:path.
262
279
  propertyShapesByIdentifier.set(shapeNode, this.createPropertyShape({
263
- resource: resourceSet.resource(shapeNode),
280
+ curieFactory,
281
+ resource: curieResource(shapeNode),
264
282
  shapesGraph,
265
283
  }).unsafeCoerce());
266
284
  }
267
285
  else {
268
286
  // A node shape is a shape in the shapes graph that is not the subject of a triple with sh:path as its predicate. It is recommended, but not required, for a node shape to be declared as a SHACL instance of sh:NodeShape. SHACL instances of sh:NodeShape cannot have a value for the property sh:path.
269
287
  nodeShapesByIdentifier.set(shapeNode, this.createNodeShape({
270
- resource: resourceSet.resource(shapeNode),
288
+ curieFactory,
289
+ resource: curieResource(shapeNode),
271
290
  shapesGraph,
272
291
  }).unsafeCoerce());
273
292
  }
@@ -279,28 +298,33 @@ __decorate([
279
298
  ShapesGraph.Factory = Factory;
280
299
  class DefaultFactory extends Factory {
281
300
  createNodeShape({ resource, shapesGraph, }) {
282
- return generated.ShaclCoreNodeShape.$fromRdf(resource, {
301
+ return generated.NodeShape.$fromRdfResource(resource, {
283
302
  ignoreRdfType: true,
284
303
  preferredLanguages: this.preferredLanguages,
285
304
  }).map((generatedShape) => new NodeShape(generatedShape, shapesGraph));
286
305
  }
287
306
  createOntology({ resource, }) {
288
- return generated.OwlOntology.$fromRdf(resource, {
307
+ return generated.Ontology.$fromRdfResource(resource, {
289
308
  ignoreRdfType: true,
290
309
  preferredLanguages: this.preferredLanguages,
291
310
  }).map((generatedOntology) => new Ontology(generatedOntology));
292
311
  }
293
312
  createPropertyGroup({ resource, }) {
294
- return generated.ShaclCorePropertyGroup.$fromRdf(resource, {
313
+ return generated.PropertyGroup.$fromRdfResource(resource, {
295
314
  ignoreRdfType: true,
296
315
  preferredLanguages: this.preferredLanguages,
297
316
  }).map((propertyGroup) => new PropertyGroup(propertyGroup));
298
317
  }
299
- createPropertyShape({ resource, shapesGraph, }) {
300
- return generated.ShaclCorePropertyShape.$fromRdf(resource, {
318
+ createPropertyShape({ curieFactory, resource, shapesGraph, }) {
319
+ return generated.PropertyShape.$fromRdfResource(resource, {
301
320
  ignoreRdfType: true,
302
321
  preferredLanguages: this.preferredLanguages,
303
- }).map((generatedShape) => new PropertyShape(generatedShape, shapesGraph));
322
+ }).map((generatedShape) => new PropertyShape({
323
+ ...generatedShape,
324
+ path: (generatedShape.path.termType === "NamedNode"
325
+ ? curieFactory.create(generatedShape.path).extract()
326
+ : undefined) ?? generatedShape.path,
327
+ }, shapesGraph));
304
328
  }
305
329
  }
306
330
  const defaultFactory = new DefaultFactory();