@shaclmate/compiler 4.0.13 → 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 (55) 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 +74 -3
  5. package/dist/_ShapesGraphToAstTransformer/ShapeStack.js +6 -5
  6. package/dist/_ShapesGraphToAstTransformer/nodeShapeIdentifierMintingStrategy.d.ts +3 -2
  7. package/dist/_ShapesGraphToAstTransformer/nodeShapeIdentifierMintingStrategy.js +17 -13
  8. package/dist/_ShapesGraphToAstTransformer/nodeShapeTsFeatures.js +2 -1
  9. package/dist/_ShapesGraphToAstTransformer/shapeAstTypeName.js +6 -6
  10. package/dist/_ShapesGraphToAstTransformer/shapeNodeKinds.d.ts +2 -1
  11. package/dist/_ShapesGraphToAstTransformer/shapeNodeKinds.js +37 -30
  12. package/dist/_ShapesGraphToAstTransformer/shapeOntology.d.ts +5 -0
  13. package/dist/_ShapesGraphToAstTransformer/shapeOntology.js +25 -0
  14. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstObjectTypeProperty.js +23 -16
  15. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstCompoundType.js +10 -6
  16. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstListType.js +22 -22
  17. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstObjectType.js +127 -118
  18. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstTermType.js +10 -8
  19. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstType.js +3 -3
  20. package/dist/ast/ObjectType.d.ts +3 -3
  21. package/dist/enums/IdentifierMintingStrategy.d.ts +4 -0
  22. package/dist/enums/IdentifierMintingStrategy.js +17 -1
  23. package/dist/enums/TsObjectDeclarationType.d.ts +4 -0
  24. package/dist/enums/TsObjectDeclarationType.js +15 -1
  25. package/dist/enums/Visibility.d.ts +6 -0
  26. package/dist/enums/Visibility.js +18 -0
  27. package/dist/generators/ts/AbstractCollectionType.js +1 -7
  28. package/dist/generators/ts/AbstractTermType.d.ts +1 -0
  29. package/dist/generators/ts/AbstractTermType.js +6 -0
  30. package/dist/generators/ts/AbstractUnionType.d.ts +31 -9
  31. package/dist/generators/ts/AbstractUnionType.js +252 -126
  32. package/dist/generators/ts/SetType.d.ts +1 -0
  33. package/dist/generators/ts/SetType.js +12 -0
  34. package/dist/generators/ts/_NamedObjectType/AbstractProperty.d.ts +3 -3
  35. package/dist/input/ShapesGraph.d.ts +39 -22
  36. package/dist/input/ShapesGraph.js +56 -60
  37. package/dist/input/generated.d.ts +389 -191
  38. package/dist/input/generated.js +2501 -829
  39. package/dist/input/index.d.ts +1 -5
  40. package/dist/input/index.js +1 -5
  41. package/package.json +2 -2
  42. package/dist/enums/PropertyVisibility.d.ts +0 -2
  43. package/dist/enums/PropertyVisibility.js +0 -2
  44. package/dist/input/NodeShape.d.ts +0 -49
  45. package/dist/input/NodeShape.js +0 -154
  46. package/dist/input/Ontology.d.ts +0 -13
  47. package/dist/input/Ontology.js +0 -40
  48. package/dist/input/PropertyShape.d.ts +0 -20
  49. package/dist/input/PropertyShape.js +0 -78
  50. package/dist/input/Shape.d.ts +0 -4
  51. package/dist/input/Shape.js +0 -2
  52. package/dist/input/ancestorClassIris.d.ts +0 -4
  53. package/dist/input/ancestorClassIris.js +0 -24
  54. package/dist/input/descendantClassIris.d.ts +0 -4
  55. 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";
4
- import { NodeShape, Ontology, PropertyGroup, PropertyShape, type Shape } from "./index.js";
5
- export type ShapesGraph = _ShapesGraph<NodeShape, Ontology, PropertyGroup, PropertyShape, Shape>;
3
+ import type { Ast } from "../ast/Ast.js";
4
+ import type { TsFeature } from "../enums/TsFeature.js";
5
+ import type { Generator } from "../generators/Generator.js";
6
+ import * as generated from "./generated.js";
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
+ }
6
29
  export declare namespace ShapesGraph {
7
- class Factory extends _ShapesGraph.Factory<NodeShape, Ontology, PropertyGroup, PropertyShape, Shape> {
8
- protected createNodeShape({ resource, shapesGraph, }: {
9
- resource: Resource;
10
- shapesGraph: ShapesGraph;
11
- }): Either<Error, NodeShape>;
12
- protected createOntology({ resource, }: {
13
- resource: Resource;
14
- }): Either<Error, Ontology>;
15
- protected createPropertyGroup({ resource, }: {
16
- resource: Resource;
17
- }): Either<Error, PropertyGroup>;
18
- protected createPropertyShape({ curieFactory, resource, shapesGraph, }: {
19
- curieFactory: CurieFactory;
20
- resource: Resource;
21
- shapesGraph: ShapesGraph;
22
- }): Either<Error, 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,70 +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
- import { NodeShape, Ontology, PropertyGroup, PropertyShape, } from "./index.js";
7
- 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
+ }
8
32
  (function (ShapesGraph) {
9
- class Factory extends _ShapesGraph.Factory {
10
- createNodeShape({ resource, shapesGraph, }) {
11
- return generated.NodeShape.$fromRdfResource(resource, {
12
- ignoreRdfType: true,
13
- preferredLanguages: this.preferredLanguages,
14
- }).map((generatedShape) => {
15
- let isClass = resource.isInstanceOf(owl.Class) || resource.isInstanceOf(rdfs.Class);
16
- const isList = resource.isSubClassOf(rdf.List);
17
- if (isList) {
18
- isClass = true; // RDFS entailment: if A rdfs:subClassOf rdf:List then A is an rdfs:Class
19
- }
20
- const ancestorClassIris_ = ancestorClassIris(resource, Number.MAX_SAFE_INTEGER);
21
- if (ancestorClassIris_.length > 0) {
22
- isClass = true; // RDFS entailment: if A rdfs:subClassOf B then both A and B are rdfs:Class's
23
- }
24
- const descendantClassIris_ = descendantClassIris(resource, Number.MAX_SAFE_INTEGER);
25
- if (descendantClassIris_.length > 0) {
26
- isClass = true; // RDFS entailment, see above
27
- }
28
- return new NodeShape({
29
- ancestorClassIris: ancestorClassIris_,
30
- childClassIris: descendantClassIris(resource, 1),
31
- descendantClassIris: descendantClassIris_,
32
- generatedNodeShape: generatedShape,
33
- isClass,
34
- isList,
35
- parentClassIris: ancestorClassIris(resource, 1),
36
- shapesGraph,
37
- });
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,
38
41
  });
39
42
  }
40
- createOntology({ resource, }) {
41
- return generated.Ontology.$fromRdfResource(resource, {
42
- ignoreRdfType: true,
43
- preferredLanguages: this.preferredLanguages,
44
- }).map((generatedOntology) => new Ontology(generatedOntology));
43
+ nodeShape(parameters) {
44
+ const nodeShape = generated.NodeShape.$create(parameters);
45
+ this.add(nodeShape);
46
+ return nodeShape;
45
47
  }
46
- createPropertyGroup({ resource, }) {
47
- return generated.PropertyGroup.$fromRdfResource(resource, {
48
- ignoreRdfType: true,
49
- preferredLanguages: this.preferredLanguages,
50
- }).map((generatedPropertyGroup) => new PropertyGroup(generatedPropertyGroup));
48
+ ontology(parameters) {
49
+ const ontology = generated.Ontology.$create(parameters);
50
+ this.add(ontology);
51
+ return ontology;
51
52
  }
52
- createPropertyShape({ curieFactory, resource, shapesGraph, }) {
53
- return generated.PropertyShape.$fromRdfResource(resource, {
54
- ignoreRdfType: true,
55
- preferredLanguages: this.preferredLanguages,
56
- }).map((generatedShape) => new PropertyShape({
57
- ...generatedShape,
58
- path: (generatedShape.path.termType === "NamedNode"
59
- ? curieFactory.create(generatedShape.path).extract()
60
- : undefined) ?? generatedShape.path,
61
- }, shapesGraph));
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;
62
62
  }
63
63
  }
64
- const factory = new Factory();
65
- function create(parameters) {
66
- return factory.createShapesGraph(parameters);
67
- }
68
- ShapesGraph.create = create;
64
+ ShapesGraph.Builder = Builder;
69
65
  })(ShapesGraph || (ShapesGraph = {}));
70
66
  //# sourceMappingURL=ShapesGraph.js.map