@shaclmate/compiler 4.0.14 → 4.0.16

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/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/ast/ObjectCompoundType.js +1 -1
  11. package/dist/ast/ObjectType.d.ts +1 -1
  12. package/dist/ast/ObjectType.js +1 -1
  13. package/dist/generators/json/AstJsonGenerator.js +1 -1
  14. package/dist/generators/ts/AbstractCollectionType.js +1 -7
  15. package/dist/generators/ts/AbstractTermType.d.ts +1 -0
  16. package/dist/generators/ts/AbstractTermType.js +6 -0
  17. package/dist/generators/ts/AbstractUnionType.d.ts +31 -9
  18. package/dist/generators/ts/AbstractUnionType.js +252 -126
  19. package/dist/generators/ts/DefaultValueType.js +1 -1
  20. package/dist/generators/ts/NamedObjectUnionType.js +1 -1
  21. package/dist/generators/ts/SetType.d.ts +1 -0
  22. package/dist/generators/ts/SetType.js +12 -0
  23. package/dist/generators/ts/TypeFactory.js +1 -1
  24. package/dist/generators/ts/_NamedObjectType/ShaclProperty.d.ts +1 -1
  25. package/dist/generators/ts/imports.js +4 -4
  26. package/dist/input/ShapesGraph.d.ts +38 -21
  27. package/dist/input/ShapesGraph.js +56 -58
  28. package/dist/input/generated.d.ts +211 -46
  29. package/dist/input/generated.js +2283 -677
  30. package/dist/input/index.d.ts +1 -3
  31. package/dist/input/index.js +1 -3
  32. package/package.json +5 -10
  33. package/dist/input/NodeShape.d.ts +0 -11
  34. package/dist/input/NodeShape.js +0 -2
  35. package/dist/input/Shape.d.ts +0 -4
  36. package/dist/input/Shape.js +0 -2
  37. package/dist/input/ancestorClassIris.d.ts +0 -4
  38. package/dist/input/ancestorClassIris.js +0 -24
  39. package/dist/input/descendantClassIris.d.ts +0 -4
  40. package/dist/input/descendantClassIris.js +0 -27
@@ -1,27 +1,44 @@
1
- import { ShapesGraph as _ShapesGraph, type CurieFactory } from "@shaclmate/shacl-ast";
1
+ import { AbstractShapesGraph } from "@shaclmate/shacl-ast";
2
2
  import type { Either } from "purify-ts";
3
- import type { Resource } from "rdfjs-resource";
3
+ import type { Ast } from "../ast/Ast.js";
4
+ import type { TsFeature } from "../enums/TsFeature.js";
5
+ import type { Generator } from "../generators/Generator.js";
4
6
  import * as generated from "./generated.js";
5
- import type { NodeShape } from "./NodeShape.js";
6
- import type { Shape } from "./Shape.js";
7
- export type ShapesGraph = _ShapesGraph<NodeShape, generated.Ontology, generated.PropertyGroup, generated.PropertyShape, Shape>;
7
+ export declare class ShapesGraph extends AbstractShapesGraph<generated.NodeShape, generated.Ontology, generated.PropertyGroup, generated.PropertyShape> {
8
+ protected readonly typeFunctions: {
9
+ readonly NodeShape: typeof generated.NodeShape;
10
+ readonly Ontology: typeof generated.Ontology;
11
+ readonly PropertyGroup: typeof generated.PropertyGroup;
12
+ readonly PropertyShape: typeof generated.PropertyShape;
13
+ };
14
+ /**
15
+ * Compile the shapes graph using the given generator and return the generator's output.
16
+ */
17
+ compile(parameters: {
18
+ generator: Generator;
19
+ tsFeaturesDefault?: ReadonlySet<TsFeature>;
20
+ }): Either<Error, string>;
21
+ static builder(): ShapesGraph.Builder;
22
+ /**
23
+ * Transform the shapes graph to an AST.
24
+ */
25
+ toAst(options?: {
26
+ tsFeaturesDefault?: ReadonlySet<TsFeature>;
27
+ }): Either<Error, Ast>;
28
+ }
8
29
  export declare namespace ShapesGraph {
9
- class Factory extends _ShapesGraph.Factory<NodeShape, generated.Ontology, generated.PropertyGroup, generated.PropertyShape, Shape> {
10
- protected createNodeShape({ resource, }: {
11
- resource: Resource;
12
- }): Either<Error, NodeShape>;
13
- protected createOntology({ resource, }: {
14
- resource: Resource;
15
- }): Either<Error, generated.Ontology>;
16
- protected createPropertyGroup({ resource, }: {
17
- resource: Resource;
18
- }): Either<Error, generated.PropertyGroup>;
19
- protected createPropertyShape({ curieFactory, resource, }: {
20
- curieFactory: CurieFactory;
21
- resource: Resource;
22
- }): Either<Error, generated.PropertyShape>;
30
+ class Builder extends AbstractShapesGraph.AbstractBuilder<generated.NodeShape, generated.Ontology, generated.PropertyGroup, generated.PropertyShape> {
31
+ protected readonly typeFunctions: {
32
+ readonly NodeShape: typeof generated.NodeShape;
33
+ readonly Ontology: typeof generated.Ontology;
34
+ readonly PropertyGroup: typeof generated.PropertyGroup;
35
+ readonly PropertyShape: typeof generated.PropertyShape;
36
+ };
37
+ build(): ShapesGraph;
38
+ nodeShape(parameters?: Parameters<typeof generated.NodeShape.$create>[0]): generated.NodeShape;
39
+ ontology(parameters?: Parameters<typeof generated.Ontology.$create>[0]): generated.Ontology;
40
+ propertyGroup(parameters?: Parameters<typeof generated.PropertyGroup.$create>[0]): generated.PropertyGroup;
41
+ propertyShape(parameters: Parameters<typeof generated.PropertyShape.$create>[0]): generated.PropertyShape;
23
42
  }
24
- export function create(parameters: Parameters<Factory["createShapesGraph"]>[0]): Either<Error, ShapesGraph>;
25
- export {};
26
43
  }
27
44
  //# sourceMappingURL=ShapesGraph.d.ts.map
@@ -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