@shaclmate/compiler 2.0.17 → 2.0.18

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,41 @@
1
+ import type { NamedNode } from "@rdfjs/types";
2
+ import type * as purify from "purify-ts";
3
+ import type * as rdfjsResource from "rdfjs-resource";
4
+ export interface AlternativePath {
5
+ readonly kind: "AlternativePath";
6
+ readonly members: readonly PropertyPath[];
7
+ }
8
+ export interface InversePath {
9
+ readonly kind: "InversePath";
10
+ readonly path: PropertyPath;
11
+ }
12
+ export interface OneOrMorePath {
13
+ readonly kind: "OneOrMorePath";
14
+ readonly path: PropertyPath;
15
+ }
16
+ export interface PredicatePath {
17
+ readonly iri: NamedNode;
18
+ readonly kind: "PredicatePath";
19
+ }
20
+ export interface SequencePath {
21
+ readonly kind: "SequencePath";
22
+ readonly members: readonly PropertyPath[];
23
+ }
24
+ export interface ZeroOrMorePath {
25
+ readonly kind: "ZeroOrMorePath";
26
+ readonly path: PropertyPath;
27
+ }
28
+ export interface ZeroOrOnePath {
29
+ readonly kind: "ZeroOrOnePath";
30
+ readonly path: PropertyPath;
31
+ }
32
+ export type PropertyPath = AlternativePath | InversePath | OneOrMorePath | PredicatePath | SequencePath | ZeroOrMorePath | ZeroOrOnePath;
33
+ export declare namespace PropertyPath {
34
+ function fromRdf({ resource, }: {
35
+ [_index: string]: any;
36
+ ignoreRdfType?: boolean;
37
+ languageIn?: readonly string[];
38
+ resource: rdfjsResource.Resource;
39
+ }): purify.Either<rdfjsResource.Resource.ValueError, PropertyPath>;
40
+ }
41
+ //# sourceMappingURL=PropertyPath.d.ts.map
@@ -0,0 +1,105 @@
1
+ import { rdf, sh } from "@tpluscode/rdf-ns-builders";
2
+ import { Either, Left } from "purify-ts";
3
+ import { Resource } from "rdfjs-resource";
4
+ export var PropertyPath;
5
+ (function (PropertyPath) {
6
+ function fromRdf({ resource, }) {
7
+ // Predicate path
8
+ // sh:path ex:parent
9
+ if (resource.identifier.termType === "NamedNode") {
10
+ return Either.of({ iri: resource.identifier, kind: "PredicatePath" });
11
+ }
12
+ // The other property path types are BlankNodes
13
+ const getPropertyPathList = (listResource) => {
14
+ return listResource.toList().chain((values) => {
15
+ const members = [];
16
+ for (const value of values) {
17
+ const memberResource = value.toResource().toMaybe();
18
+ if (memberResource.isNothing()) {
19
+ return Left(new Resource.ValueError({
20
+ focusResource: resource,
21
+ message: "non-identifier in property path list",
22
+ predicate: rdf.subject,
23
+ }));
24
+ }
25
+ const member = PropertyPath.fromRdf({
26
+ resource: memberResource.unsafeCoerce(),
27
+ });
28
+ if (member.isLeft()) {
29
+ return member;
30
+ }
31
+ members.push(member.unsafeCoerce());
32
+ }
33
+ return Either.of(members);
34
+ });
35
+ };
36
+ for (const quad of resource.dataset.match(resource.identifier, null, null, null)) {
37
+ switch (quad.object.termType) {
38
+ case "BlankNode":
39
+ case "NamedNode":
40
+ break;
41
+ default:
42
+ return Left(new Resource.ValueError({
43
+ focusResource: resource,
44
+ message: `non-BlankNode/NamedNode property path object on path ${resource.identifier.value}: ${quad.object.termType} ${quad.object.value}`,
45
+ predicate: quad.predicate,
46
+ }));
47
+ }
48
+ const objectResource = new Resource({
49
+ dataset: resource.dataset,
50
+ identifier: quad.object,
51
+ });
52
+ // Alternative path
53
+ // sh:path: [ sh:alternativePath ( ex:father ex:mother ) ]
54
+ if (quad.predicate.equals(sh.alternativePath)) {
55
+ return getPropertyPathList(objectResource).map((members) => ({
56
+ kind: "AlternativePath",
57
+ members,
58
+ }));
59
+ }
60
+ // Inverse path
61
+ // sh:path: [ sh:inversePath ex:parent ]
62
+ if (quad.predicate.equals(sh.inversePath)) {
63
+ return PropertyPath.fromRdf({ resource: objectResource }).map((path) => ({
64
+ kind: "InversePath",
65
+ path,
66
+ }));
67
+ }
68
+ // One or more path
69
+ if (quad.predicate.equals(sh.oneOrMorePath)) {
70
+ return PropertyPath.fromRdf({ resource: objectResource }).map((path) => ({
71
+ kind: "OneOrMorePath",
72
+ path,
73
+ }));
74
+ }
75
+ // Sequence path
76
+ // sh:path ( ex:parent ex:firstName )
77
+ if (quad.predicate.equals(rdf.first)) {
78
+ return getPropertyPathList(objectResource).map((members) => ({
79
+ kind: "SequencePath",
80
+ members,
81
+ }));
82
+ }
83
+ // Zero or more path
84
+ if (quad.predicate.equals(sh.zeroOrMorePath)) {
85
+ return PropertyPath.fromRdf({ resource: objectResource }).map((path) => ({
86
+ kind: "ZeroOrMorePath",
87
+ path,
88
+ }));
89
+ }
90
+ if (quad.predicate.equals(sh.zeroOrOnePath)) {
91
+ return PropertyPath.fromRdf({ resource: objectResource }).map((path) => ({
92
+ kind: "ZeroOrOnePath",
93
+ path,
94
+ }));
95
+ }
96
+ }
97
+ return Left(new Resource.ValueError({
98
+ focusResource: resource,
99
+ message: `unrecognized or ill-formed SHACL property path ${resource.identifier.value}`,
100
+ predicate: rdf.subject,
101
+ }));
102
+ }
103
+ PropertyPath.fromRdf = fromRdf;
104
+ })(PropertyPath || (PropertyPath = {}));
105
+ //# sourceMappingURL=PropertyPath.js.map
@@ -1,7 +1,7 @@
1
1
  import type * as rdfjs from "@rdfjs/types";
2
- import { PropertyPath } from "@shaclmate/shacl-ast/PropertyPath.js";
3
2
  import * as purify from "purify-ts";
4
3
  import * as rdfjsResource from "rdfjs-resource";
4
+ import { PropertyPath } from "./PropertyPath.js";
5
5
  type UnwrapR<T> = T extends purify.Either<any, infer R> ? R : never;
6
6
  export interface BaseShaclCoreShape {
7
7
  readonly and: readonly (readonly (rdfjs.BlankNode | rdfjs.NamedNode)[])[];
@@ -1,7 +1,7 @@
1
- import { PropertyPath } from "@shaclmate/shacl-ast/PropertyPath.js";
2
1
  import { DataFactory as dataFactory } from "n3";
3
2
  import * as purify from "purify-ts";
4
3
  import * as rdfjsResource from "rdfjs-resource";
4
+ import { PropertyPath } from "./PropertyPath.js";
5
5
  export var BaseShaclCoreShape;
6
6
  (function (BaseShaclCoreShape) {
7
7
  function propertiesFromRdf({ ignoreRdfType: _ignoreRdfType, languageIn: _languageIn, resource: _resource,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "dependencies": {
3
- "@shaclmate/shacl-ast": "2.0.17",
3
+ "@shaclmate/shacl-ast": "2.0.18",
4
4
  "@rdfjs/prefix-map": "^0.1.2",
5
5
  "@rdfjs/term-map": "^2.0.2",
6
6
  "@rdfjs/term-set": "^2.0.3",
@@ -20,7 +20,7 @@
20
20
  "typescript-memoize": "^1.1.1"
21
21
  },
22
22
  "devDependencies": {
23
- "@shaclmate/runtime": "2.0.17",
23
+ "@shaclmate/runtime": "2.0.18",
24
24
  "oxigraph": "^0.4.0"
25
25
  },
26
26
  "exports": {
@@ -77,5 +77,5 @@
77
77
  "url": "git+https://github.com/minorg/shaclmate"
78
78
  },
79
79
  "type": "module",
80
- "version": "2.0.17"
80
+ "version": "2.0.18"
81
81
  }