@shaclmate/shacl-ast 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.
@@ -1,8 +1,10 @@
1
+ import type { NamedNode } from "@rdfjs/types";
1
2
  /**
2
3
  * TypeScript enum corresponding to sh:NodeKind, for simpler manipulation.
3
4
  */
4
5
  export type NodeKind = "BlankNode" | "IRI" | "Literal";
5
6
  export declare namespace NodeKind {
7
+ function fromIri(iri: NamedNode<"http://www.w3.org/ns/shacl#BlankNode" | "http://www.w3.org/ns/shacl#BlankNodeOrIRI" | "http://www.w3.org/ns/shacl#BlankNodeOrLiteral" | "http://www.w3.org/ns/shacl#IRI" | "http://www.w3.org/ns/shacl#IRIOrLiteral" | "http://www.w3.org/ns/shacl#Literal">): ReadonlySet<NodeKind>;
6
8
  function fromTermType(termType: "BlankNode" | "Literal" | "NamedNode"): NodeKind;
7
9
  function toTermType(nodeKind: NodeKind): "BlankNode" | "Literal" | "NamedNode";
8
10
  }
package/dist/NodeKind.js CHANGED
@@ -1,5 +1,36 @@
1
1
  export var NodeKind;
2
2
  (function (NodeKind) {
3
+ function fromIri(iri) {
4
+ const nodeKinds = new Set();
5
+ switch (iri.value) {
6
+ case "http://www.w3.org/ns/shacl#BlankNode":
7
+ nodeKinds.add("BlankNode");
8
+ break;
9
+ case "http://www.w3.org/ns/shacl#BlankNodeOrIRI":
10
+ nodeKinds.add("BlankNode");
11
+ nodeKinds.add("IRI");
12
+ break;
13
+ case "http://www.w3.org/ns/shacl#BlankNodeOrLiteral":
14
+ nodeKinds.add("BlankNode");
15
+ nodeKinds.add("Literal");
16
+ break;
17
+ case "http://www.w3.org/ns/shacl#IRI":
18
+ nodeKinds.add("IRI");
19
+ break;
20
+ case "http://www.w3.org/ns/shacl#IRIOrLiteral":
21
+ nodeKinds.add("IRI");
22
+ nodeKinds.add("Literal");
23
+ break;
24
+ case "http://www.w3.org/ns/shacl#Literal":
25
+ nodeKinds.add("Literal");
26
+ break;
27
+ default:
28
+ iri.value;
29
+ throw new RangeError(iri.value);
30
+ }
31
+ return nodeKinds;
32
+ }
33
+ NodeKind.fromIri = fromIri;
3
34
  function fromTermType(termType) {
4
35
  return termType === "NamedNode" ? "IRI" : termType;
5
36
  }
@@ -4,13 +4,8 @@ import type { BlankNode, DatasetCore, NamedNode } from "@rdfjs/types";
4
4
  import { Either } from "purify-ts";
5
5
  import { Resource } from "rdfjs-resource";
6
6
  import { CurieFactory } from "./CurieFactory.js";
7
- import { NodeShape } from "./NodeShape.js";
8
- import { Ontology } from "./Ontology.js";
9
- import type { OntologyLike } from "./OntologyLike.js";
10
- import { PropertyGroup } from "./PropertyGroup.js";
11
- import { PropertyShape } from "./PropertyShape.js";
12
- import type { Shape } from "./Shape.js";
13
- export declare class ShapesGraph<NodeShapeT extends ShapeT, OntologyT extends OntologyLike, PropertyGroupT, PropertyShapeT extends ShapeT, ShapeT> {
7
+ import * as generated from "./generated.js";
8
+ export declare class ShapesGraph<NodeShapeT extends ShapeT, OntologyT extends generated.Ontology, PropertyGroupT extends generated.PropertyGroup, PropertyShapeT extends ShapeT, ShapeT extends generated.Shape> {
14
9
  private readonly nodeShapesByIdentifier;
15
10
  private readonly ontologiesByIdentifier;
16
11
  private readonly propertyGroupsByIdentifier;
@@ -22,17 +17,17 @@ export declare class ShapesGraph<NodeShapeT extends ShapeT, OntologyT extends On
22
17
  propertyShapesByIdentifier: TermMap<BlankNode | NamedNode, PropertyShapeT>;
23
18
  });
24
19
  get nodeShapes(): readonly NodeShapeT[];
25
- nodeShapeByIdentifier(identifier: BlankNode | NamedNode): Either<Error, NodeShapeT>;
26
20
  get ontologies(): readonly OntologyT[];
27
- ontologyByIdentifier(identifier: BlankNode | NamedNode): Either<Error, OntologyT>;
28
- propertyGroupByIdentifier(identifier: BlankNode | NamedNode): Either<Error, PropertyGroupT>;
29
21
  get propertyGroups(): readonly PropertyGroupT[];
30
- propertyShapeByIdentifier(identifier: BlankNode | NamedNode): Either<Error, PropertyShapeT>;
31
22
  get propertyShapes(): readonly PropertyShapeT[];
32
- shapeByIdentifier(identifier: BlankNode | NamedNode): Either<Error, ShapeT>;
23
+ nodeShape(identifier: BlankNode | NamedNode): Either<Error, NodeShapeT>;
24
+ ontology(identifier: BlankNode | NamedNode): Either<Error, OntologyT>;
25
+ propertyGroup(identifier: BlankNode | NamedNode): Either<Error, PropertyGroupT>;
26
+ propertyShape(identifier: BlankNode | NamedNode): Either<Error, PropertyShapeT>;
27
+ shape(identifier: BlankNode | NamedNode): Either<Error, ShapeT>;
33
28
  }
34
29
  export declare namespace ShapesGraph {
35
- export abstract class Factory<NodeShapeT extends ShapeT, OntologyT extends OntologyLike, PropertyGroupT, PropertyShapeT extends ShapeT, ShapeT> {
30
+ export abstract class Factory<NodeShapeT extends generated.NodeShape & ShapeT, OntologyT extends generated.Ontology, PropertyGroupT extends generated.PropertyGroup, PropertyShapeT extends generated.PropertyShape & ShapeT, ShapeT extends generated.Shape> {
36
31
  protected preferredLanguages: readonly string[];
37
32
  constructor(parameters?: {
38
33
  preferredLanguages?: readonly string[];
@@ -63,30 +58,21 @@ export declare namespace ShapesGraph {
63
58
  shapesGraph: ShapesGraph<NodeShapeT, OntologyT, PropertyGroupT, PropertyShapeT, ShapeT>;
64
59
  }): Either<Error, PropertyShapeT>;
65
60
  }
66
- type DefaultNodeShape = NodeShape<any, Ontology, PropertyGroup, DefaultPropertyShape, DefaultShape>;
67
- type DefaultPropertyShape = PropertyShape<DefaultNodeShape, Ontology, PropertyGroup, any, DefaultShape>;
68
- type DefaultShape = Shape<DefaultNodeShape, Ontology, PropertyGroup, DefaultPropertyShape, any>;
69
- type DefaultShapesGraph = ShapesGraph<DefaultNodeShape, Ontology, PropertyGroup, DefaultPropertyShape, DefaultShape>;
70
- class DefaultFactory extends Factory<DefaultNodeShape, Ontology, PropertyGroup, DefaultPropertyShape, DefaultShape> {
71
- protected createNodeShape({ resource, shapesGraph, }: {
61
+ type DefaultShapesGraph = ShapesGraph<generated.NodeShape, generated.Ontology, generated.PropertyGroup, generated.PropertyShape, generated.Shape>;
62
+ class DefaultFactory extends Factory<generated.NodeShape, generated.Ontology, generated.PropertyGroup, generated.PropertyShape, generated.Shape> {
63
+ protected createNodeShape({ resource }: {
72
64
  resource: Resource;
73
- shapesGraph: DefaultShapesGraph;
74
- }): Either<Error, NodeShape<DefaultNodeShape, Ontology, PropertyGroup, DefaultPropertyShape, DefaultShape>>;
65
+ }): Either<Error, generated.NodeShape>;
75
66
  protected createOntology({ resource, }: {
76
- curieFactory: CurieFactory;
77
67
  resource: Resource;
78
- shapesGraph: DefaultShapesGraph;
79
- }): Either<Error, Ontology>;
68
+ }): Either<Error, generated.Ontology>;
80
69
  protected createPropertyGroup({ resource, }: {
81
- curieFactory: CurieFactory;
82
70
  resource: Resource;
83
- shapesGraph: DefaultShapesGraph;
84
- }): Either<Error, PropertyGroup>;
85
- protected createPropertyShape({ curieFactory, resource, shapesGraph, }: {
71
+ }): Either<Error, generated.PropertyGroup>;
72
+ protected createPropertyShape({ curieFactory, resource, }: {
86
73
  curieFactory: CurieFactory;
87
74
  resource: Resource;
88
- shapesGraph: DefaultShapesGraph;
89
- }): Either<Error, DefaultPropertyShape>;
75
+ }): Either<Error, generated.PropertyShape>;
90
76
  }
91
77
  export function create(parameters: Parameters<DefaultFactory["createShapesGraph"]>[0]): Either<Error, DefaultShapesGraph>;
92
78
  export {};
@@ -14,10 +14,6 @@ import { Resource, ResourceSet } from "rdfjs-resource";
14
14
  import { Memoize } from "typescript-memoize";
15
15
  import { CurieFactory } from "./CurieFactory.js";
16
16
  import * as generated from "./generated.js";
17
- import { NodeShape } from "./NodeShape.js";
18
- import { Ontology } from "./Ontology.js";
19
- import { PropertyGroup } from "./PropertyGroup.js";
20
- import { PropertyShape } from "./PropertyShape.js";
21
17
  export class ShapesGraph {
22
18
  nodeShapesByIdentifier;
23
19
  ontologiesByIdentifier;
@@ -32,41 +28,41 @@ export class ShapesGraph {
32
28
  get nodeShapes() {
33
29
  return [...this.nodeShapesByIdentifier.values()];
34
30
  }
35
- nodeShapeByIdentifier(identifier) {
31
+ get ontologies() {
32
+ return [...this.ontologiesByIdentifier.values()];
33
+ }
34
+ get propertyGroups() {
35
+ return [...this.propertyGroupsByIdentifier.values()];
36
+ }
37
+ get propertyShapes() {
38
+ return [...this.propertyShapesByIdentifier.values()];
39
+ }
40
+ nodeShape(identifier) {
36
41
  const nodeShape = this.nodeShapesByIdentifier.get(identifier);
37
42
  return nodeShape
38
43
  ? Either.of(nodeShape)
39
44
  : Left(new Error(`no such node shape ${Resource.Identifier.toString(identifier)}`));
40
45
  }
41
- get ontologies() {
42
- return [...this.ontologiesByIdentifier.values()];
43
- }
44
- ontologyByIdentifier(identifier) {
46
+ ontology(identifier) {
45
47
  const ontology = this.ontologiesByIdentifier.get(identifier);
46
48
  return ontology
47
49
  ? Either.of(ontology)
48
50
  : Left(new Error(`no such ontology ${Resource.Identifier.toString(identifier)}`));
49
51
  }
50
- propertyGroupByIdentifier(identifier) {
52
+ propertyGroup(identifier) {
51
53
  const propertyGroup = this.propertyGroupsByIdentifier.get(identifier);
52
54
  return propertyGroup
53
55
  ? Either.of(propertyGroup)
54
56
  : Left(new Error(`no such property group ${Resource.Identifier.toString(identifier)}`));
55
57
  }
56
- get propertyGroups() {
57
- return [...this.propertyGroupsByIdentifier.values()];
58
- }
59
- propertyShapeByIdentifier(identifier) {
58
+ propertyShape(identifier) {
60
59
  const propertyShape = this.propertyShapesByIdentifier.get(identifier);
61
60
  return propertyShape
62
61
  ? Either.of(propertyShape)
63
62
  : Left(new Error(`no such property shape ${Resource.Identifier.toString(identifier)}`));
64
63
  }
65
- get propertyShapes() {
66
- return [...this.propertyShapesByIdentifier.values()];
67
- }
68
- shapeByIdentifier(identifier) {
69
- return this.nodeShapeByIdentifier(identifier).alt(this.propertyShapeByIdentifier(identifier));
64
+ shape(identifier) {
65
+ return this.nodeShape(identifier).alt(this.propertyShape(identifier));
70
66
  }
71
67
  }
72
68
  __decorate([
@@ -297,34 +293,34 @@ __decorate([
297
293
  }
298
294
  ShapesGraph.Factory = Factory;
299
295
  class DefaultFactory extends Factory {
300
- createNodeShape({ resource, shapesGraph, }) {
296
+ createNodeShape({ resource }) {
301
297
  return generated.NodeShape.$fromRdfResource(resource, {
302
298
  ignoreRdfType: true,
303
299
  preferredLanguages: this.preferredLanguages,
304
- }).map((generatedShape) => new NodeShape(generatedShape, shapesGraph));
300
+ });
305
301
  }
306
302
  createOntology({ resource, }) {
307
303
  return generated.Ontology.$fromRdfResource(resource, {
308
304
  ignoreRdfType: true,
309
305
  preferredLanguages: this.preferredLanguages,
310
- }).map((generatedOntology) => new Ontology(generatedOntology));
306
+ });
311
307
  }
312
308
  createPropertyGroup({ resource, }) {
313
309
  return generated.PropertyGroup.$fromRdfResource(resource, {
314
310
  ignoreRdfType: true,
315
311
  preferredLanguages: this.preferredLanguages,
316
- }).map((propertyGroup) => new PropertyGroup(propertyGroup));
312
+ });
317
313
  }
318
- createPropertyShape({ curieFactory, resource, shapesGraph, }) {
314
+ createPropertyShape({ curieFactory, resource, }) {
319
315
  return generated.PropertyShape.$fromRdfResource(resource, {
320
316
  ignoreRdfType: true,
321
317
  preferredLanguages: this.preferredLanguages,
322
- }).map((generatedShape) => new PropertyShape({
318
+ }).map((generatedShape) => ({
323
319
  ...generatedShape,
324
320
  path: (generatedShape.path.termType === "NamedNode"
325
321
  ? curieFactory.create(generatedShape.path).extract()
326
322
  : undefined) ?? generatedShape.path,
327
- }, shapesGraph));
323
+ }));
328
324
  }
329
325
  }
330
326
  const defaultFactory = new DefaultFactory();