@shaclmate/compiler 4.0.14 → 4.0.15

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 (31) hide show
  1. package/dist/Compiler.d.ts +4 -1
  2. package/dist/Compiler.js +3 -1
  3. package/dist/ShapesGraphToAstTransformer.d.ts +10 -2
  4. package/dist/ShapesGraphToAstTransformer.js +72 -1
  5. package/dist/_ShapesGraphToAstTransformer/nodeShapeIdentifierMintingStrategy.js +14 -13
  6. package/dist/_ShapesGraphToAstTransformer/shapeNodeKinds.js +18 -17
  7. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstCompoundType.js +6 -2
  8. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstListType.js +8 -8
  9. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstObjectType.js +10 -5
  10. package/dist/generators/ts/AbstractCollectionType.js +1 -7
  11. package/dist/generators/ts/AbstractTermType.d.ts +1 -0
  12. package/dist/generators/ts/AbstractTermType.js +6 -0
  13. package/dist/generators/ts/AbstractUnionType.d.ts +31 -9
  14. package/dist/generators/ts/AbstractUnionType.js +252 -126
  15. package/dist/generators/ts/SetType.d.ts +1 -0
  16. package/dist/generators/ts/SetType.js +12 -0
  17. package/dist/input/ShapesGraph.d.ts +38 -21
  18. package/dist/input/ShapesGraph.js +56 -58
  19. package/dist/input/generated.d.ts +204 -39
  20. package/dist/input/generated.js +2281 -676
  21. package/dist/input/index.d.ts +1 -3
  22. package/dist/input/index.js +1 -3
  23. package/package.json +2 -2
  24. package/dist/input/NodeShape.d.ts +0 -11
  25. package/dist/input/NodeShape.js +0 -2
  26. package/dist/input/Shape.d.ts +0 -4
  27. package/dist/input/Shape.js +0 -2
  28. package/dist/input/ancestorClassIris.d.ts +0 -4
  29. package/dist/input/ancestorClassIris.js +0 -24
  30. package/dist/input/descendantClassIris.d.ts +0 -4
  31. package/dist/input/descendantClassIris.js +0 -27
@@ -1,68 +1,66 @@
1
- import { ShapesGraph as _ShapesGraph, } from "@shaclmate/shacl-ast";
2
- import { owl, rdf, rdfs } from "@tpluscode/rdf-ns-builders";
3
- import { ancestorClassIris } from "./ancestorClassIris.js";
4
- import { descendantClassIris } from "./descendantClassIris.js";
1
+ import { AbstractShapesGraph } from "@shaclmate/shacl-ast";
2
+ import { Compiler } from "../Compiler.js";
3
+ import { ShapesGraphToAstTransformer } from "../ShapesGraphToAstTransformer.js";
5
4
  import * as generated from "./generated.js";
6
- export var ShapesGraph;
5
+ const typeFunctions = {
6
+ NodeShape: generated.NodeShape,
7
+ Ontology: generated.Ontology,
8
+ PropertyGroup: generated.PropertyGroup,
9
+ PropertyShape: generated.PropertyShape,
10
+ };
11
+ export class ShapesGraph extends AbstractShapesGraph {
12
+ typeFunctions = typeFunctions;
13
+ /**
14
+ * Compile the shapes graph using the given generator and return the generator's output.
15
+ */
16
+ compile(parameters) {
17
+ return new Compiler(parameters).compile(this);
18
+ }
19
+ static builder() {
20
+ return new ShapesGraph.Builder();
21
+ }
22
+ /**
23
+ * Transform the shapes graph to an AST.
24
+ */
25
+ toAst(options) {
26
+ return new ShapesGraphToAstTransformer({
27
+ ...options,
28
+ shapesGraph: this,
29
+ }).transform();
30
+ }
31
+ }
7
32
  (function (ShapesGraph) {
8
- class Factory extends _ShapesGraph.Factory {
9
- createNodeShape({ resource, }) {
10
- return generated.NodeShape.$fromRdfResource(resource, {
11
- ignoreRdfType: true,
12
- preferredLanguages: this.preferredLanguages,
13
- }).map((generatedShape) => {
14
- let isClass = resource.isInstanceOf(owl.Class) || resource.isInstanceOf(rdfs.Class);
15
- const isList = resource.isSubClassOf(rdf.List);
16
- if (isList) {
17
- isClass = true; // RDFS entailment: if A rdfs:subClassOf rdf:List then A is an rdfs:Class
18
- }
19
- const ancestorClassIris_ = ancestorClassIris(resource, Number.MAX_SAFE_INTEGER).filter((ancestorClassIri) => !ancestorClassIri.equals(rdf.List));
20
- if (ancestorClassIris_.length > 0) {
21
- isClass = true; // RDFS entailment: if A rdfs:subClassOf B then both A and B are rdfs:Class's
22
- }
23
- const descendantClassIris_ = descendantClassIris(resource, Number.MAX_SAFE_INTEGER);
24
- if (descendantClassIris_.length > 0) {
25
- isClass = true; // RDFS entailment, see above
26
- }
27
- return {
28
- ...generatedShape,
29
- ancestorClassIris: ancestorClassIris_,
30
- childClassIris: descendantClassIris(resource, 1),
31
- descendantClassIris: descendantClassIris_,
32
- isClass,
33
- isList,
34
- parentClassIris: ancestorClassIris(resource, 1).filter((ancestorClassIri) => !ancestorClassIri.equals(rdf.List)),
35
- };
33
+ class Builder extends AbstractShapesGraph.AbstractBuilder {
34
+ typeFunctions = typeFunctions;
35
+ build() {
36
+ return new ShapesGraph({
37
+ nodeShapesByIdentifier: this.nodeShapesByIdentifier,
38
+ ontologiesByIdentifier: this.ontologiesByIdentifier,
39
+ propertyGroupsByIdentifier: this.propertyGroupsByIdentifier,
40
+ propertyShapesByIdentifier: this.propertyShapesByIdentifier,
36
41
  });
37
42
  }
38
- createOntology({ resource, }) {
39
- return generated.Ontology.$fromRdfResource(resource, {
40
- ignoreRdfType: true,
41
- preferredLanguages: this.preferredLanguages,
42
- });
43
+ nodeShape(parameters) {
44
+ const nodeShape = generated.NodeShape.$create(parameters);
45
+ this.add(nodeShape);
46
+ return nodeShape;
43
47
  }
44
- createPropertyGroup({ resource, }) {
45
- return generated.PropertyGroup.$fromRdfResource(resource, {
46
- ignoreRdfType: true,
47
- preferredLanguages: this.preferredLanguages,
48
- });
48
+ ontology(parameters) {
49
+ const ontology = generated.Ontology.$create(parameters);
50
+ this.add(ontology);
51
+ return ontology;
49
52
  }
50
- createPropertyShape({ curieFactory, resource, }) {
51
- return generated.PropertyShape.$fromRdfResource(resource, {
52
- ignoreRdfType: true,
53
- preferredLanguages: this.preferredLanguages,
54
- }).map((generatedShape) => ({
55
- ...generatedShape,
56
- path: (generatedShape.path.termType === "NamedNode"
57
- ? curieFactory.create(generatedShape.path).extract()
58
- : undefined) ?? generatedShape.path,
59
- }));
53
+ propertyGroup(parameters) {
54
+ const propertyGroup = generated.PropertyGroup.$create(parameters);
55
+ this.add(propertyGroup);
56
+ return propertyGroup;
57
+ }
58
+ propertyShape(parameters) {
59
+ const propertyShape = generated.PropertyShape.$create(parameters);
60
+ this.add(propertyShape);
61
+ return propertyShape;
60
62
  }
61
63
  }
62
- const factory = new Factory();
63
- function create(parameters) {
64
- return factory.createShapesGraph(parameters);
65
- }
66
- ShapesGraph.create = create;
64
+ ShapesGraph.Builder = Builder;
67
65
  })(ShapesGraph || (ShapesGraph = {}));
68
66
  //# sourceMappingURL=ShapesGraph.js.map