@rdfx/builder 0.0.32 → 0.0.34
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.
- package/dist/BuilderBuilderParameters.d.ts +11 -0
- package/dist/BuilderBuilderParameters.js +2 -0
- package/dist/IdentifierLike.d.ts +5 -0
- package/dist/IdentifierLike.js +2 -0
- package/dist/IriLike.d.ts +4 -0
- package/dist/IriLike.js +2 -0
- package/dist/builder.d.ts +163 -40
- package/dist/builder.js +35 -2
- package/dist/index.d.ts +18 -1
- package/dist/index.js +11 -1
- package/dist/sh.d.ts +97 -9
- package/dist/sh.js +141 -70
- package/dist/shapes.d.ts +80 -80
- package/dist/shapes.js +7 -7
- package/dist/skos.d.ts +4 -3
- package/dist/skos.js +23 -11
- package/package.json +6 -5
- package/dist/toIri.d.ts +0 -4
- package/dist/toIri.js +0 -11
package/dist/sh.js
CHANGED
|
@@ -1,56 +1,61 @@
|
|
|
1
1
|
import dataFactory from "@rdfx/data-factory";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
$identifierTerm = dataFactory.blankNode();
|
|
19
|
-
break;
|
|
20
|
-
default:
|
|
21
|
-
throw new RangeError(typeof $identifier);
|
|
22
|
-
}
|
|
23
|
-
let in_;
|
|
24
|
-
// let inConceptScheme: ConceptScheme<any> | undefined;
|
|
25
|
-
// if (inParameter) {
|
|
26
|
-
// if (Array.isArray(inParameter)) {
|
|
27
|
-
// in_ = inParameter;
|
|
28
|
-
// } else {
|
|
29
|
-
// inConceptScheme = inParameter as ConceptScheme<any>;
|
|
30
|
-
// in_ = Object.values(inConceptScheme.concepts).map(
|
|
31
|
-
// (concept) => concept.identifier,
|
|
32
|
-
// );
|
|
33
|
-
// }
|
|
34
|
-
// }
|
|
35
|
-
let path;
|
|
36
|
-
switch (typeof pathParameter) {
|
|
37
|
-
case "object":
|
|
38
|
-
path = pathParameter;
|
|
39
|
-
break;
|
|
40
|
-
case "string":
|
|
41
|
-
path = toIri(pathParameter, namespace);
|
|
42
|
-
break;
|
|
43
|
-
case "undefined":
|
|
44
|
-
if ($identifierTerm.termType === "BlankNode") {
|
|
45
|
-
throw new Error("must specify a path if identifier is a BlankNode/undefined");
|
|
46
|
-
}
|
|
47
|
-
path = $identifierTerm;
|
|
48
|
-
break;
|
|
49
|
-
default:
|
|
50
|
-
throw new RangeError(typeof pathParameter);
|
|
2
|
+
import { LiteralFactory } from "@rdfx/literal";
|
|
3
|
+
import { sh as _namespace, owl, rdfs } from "@tpluscode/rdf-ns-builders";
|
|
4
|
+
import { sh_NodeShape, sh_PropertyShape, } from "./shapes.js";
|
|
5
|
+
const literalFactory = new LiteralFactory({ dataFactory });
|
|
6
|
+
function convertIn(in_) {
|
|
7
|
+
if (!in_) {
|
|
8
|
+
return undefined;
|
|
9
|
+
}
|
|
10
|
+
if (Array.isArray(in_)) {
|
|
11
|
+
const inArray = in_;
|
|
12
|
+
return inArray.map((item) => {
|
|
13
|
+
if (typeof item === "object") {
|
|
14
|
+
if (item instanceof Date) {
|
|
15
|
+
return literalFactory.date(item);
|
|
16
|
+
}
|
|
17
|
+
return item;
|
|
51
18
|
}
|
|
52
|
-
|
|
53
|
-
|
|
19
|
+
return literalFactory.primitive(item);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
const inConceptScheme = in_;
|
|
23
|
+
return inConceptScheme.concepts.map((concept) => concept.termType === "NamedNode" ? concept : concept.$identifier());
|
|
24
|
+
}
|
|
25
|
+
function convertNodeKind(nodeKind) {
|
|
26
|
+
if (!nodeKind) {
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
if (typeof nodeKind === "object") {
|
|
30
|
+
return nodeKind;
|
|
31
|
+
}
|
|
32
|
+
return _namespace[nodeKind];
|
|
33
|
+
}
|
|
34
|
+
export function sh({ namespace, toIdentifier, toIri, toIriArray, }) {
|
|
35
|
+
function PropertyShape($identifier, parameters) {
|
|
36
|
+
// Order of default population matters here.
|
|
37
|
+
const { cardinality: cardinalityParameter, class: classParameter, in_: inParameter, path: pathParameter, node: nodeParameter, nodeKind: nodeKindParameter, resolve: resolveParameter, ...otherParameters } = parameters ?? {};
|
|
38
|
+
const $identifierTerm = toIdentifier($identifier);
|
|
39
|
+
let path;
|
|
40
|
+
switch (typeof pathParameter) {
|
|
41
|
+
case "object":
|
|
42
|
+
path = pathParameter;
|
|
43
|
+
break;
|
|
44
|
+
case "string":
|
|
45
|
+
path = toIri(pathParameter);
|
|
46
|
+
break;
|
|
47
|
+
case "undefined":
|
|
48
|
+
if ($identifierTerm.termType === "BlankNode") {
|
|
49
|
+
throw new Error("must specify a path if identifier is a BlankNode/undefined");
|
|
50
|
+
}
|
|
51
|
+
path = $identifierTerm;
|
|
52
|
+
break;
|
|
53
|
+
default:
|
|
54
|
+
throw new RangeError(typeof pathParameter);
|
|
55
|
+
}
|
|
56
|
+
let maxCount;
|
|
57
|
+
let minCount;
|
|
58
|
+
if (cardinalityParameter) {
|
|
54
59
|
switch (cardinalityParameter) {
|
|
55
60
|
case "optional":
|
|
56
61
|
maxCount = 1n;
|
|
@@ -62,28 +67,94 @@ export function sh({ namespace, }) {
|
|
|
62
67
|
case "set":
|
|
63
68
|
break;
|
|
64
69
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
70
|
+
}
|
|
71
|
+
return sh_PropertyShape.createUnsafe({
|
|
72
|
+
...otherParameters,
|
|
73
|
+
$identifier: $identifierTerm,
|
|
74
|
+
class_: classParameter ? toIriArray(classParameter) : undefined,
|
|
75
|
+
in_: convertIn(inParameter),
|
|
76
|
+
maxCount,
|
|
77
|
+
minCount,
|
|
78
|
+
node: nodeParameter ? toIri(nodeParameter) : undefined,
|
|
79
|
+
nodeKind: nodeKindParameter
|
|
80
|
+
? convertNodeKind(nodeKindParameter)
|
|
81
|
+
: undefined,
|
|
82
|
+
path,
|
|
83
|
+
resolve: resolveParameter ? toIri(resolveParameter) : undefined,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
return {
|
|
87
|
+
namespace: _namespace,
|
|
88
|
+
NodeShape: ($identifier, parameters) => {
|
|
89
|
+
const nodeShapeIdentifier = toIdentifier($identifier);
|
|
90
|
+
let { implicitClassTarget, in_: inParameter, nodeKind: nodeKindParameter, properties: propertiesParameter, shaclmateName, type: typeParameter, xone: xoneParameter, ...otherParameters } = parameters ?? {};
|
|
91
|
+
let properties;
|
|
92
|
+
if (propertiesParameter) {
|
|
93
|
+
if (Array.isArray(propertiesParameter)) {
|
|
94
|
+
properties = propertiesParameter.map((property) => {
|
|
95
|
+
if (typeof property === "string") {
|
|
96
|
+
return toIri(property);
|
|
97
|
+
}
|
|
98
|
+
return property;
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
properties = Object.entries(propertiesParameter).map(([key, propertyParameters]) => {
|
|
103
|
+
let { $identifier, path, name, shaclmateName, ...otherPropertyParameters } = propertyParameters;
|
|
104
|
+
// Order of checks here is important.
|
|
105
|
+
let identifierTerm;
|
|
106
|
+
if ($identifier) {
|
|
107
|
+
identifierTerm = toIdentifier($identifier);
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
if (nodeShapeIdentifier.termType === "NamedNode") {
|
|
111
|
+
identifierTerm = dataFactory.namedNode(`${nodeShapeIdentifier.value}-${key}`);
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
identifierTerm = dataFactory.blankNode();
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
if (!name && !shaclmateName) {
|
|
118
|
+
name = key;
|
|
119
|
+
}
|
|
120
|
+
if (!path) {
|
|
121
|
+
path = namespace(key);
|
|
122
|
+
}
|
|
123
|
+
return PropertyShape(identifierTerm, {
|
|
124
|
+
...otherPropertyParameters,
|
|
125
|
+
name,
|
|
126
|
+
path,
|
|
127
|
+
shaclmateName,
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
if (!shaclmateName && typeof $identifier === "string") {
|
|
133
|
+
shaclmateName = $identifier;
|
|
134
|
+
}
|
|
135
|
+
let type;
|
|
136
|
+
if (typeParameter) {
|
|
137
|
+
type = toIriArray(typeParameter).concat();
|
|
138
|
+
if (implicitClassTarget &&
|
|
139
|
+
!type.some((type) => type.equals(rdfs.Class) || type.equals(owl.Class))) {
|
|
140
|
+
type.push(rdfs.Class);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
else if (implicitClassTarget) {
|
|
144
|
+
type = [rdfs.Class];
|
|
68
145
|
}
|
|
69
|
-
|
|
70
|
-
// classes = [(namespace as any)(inConceptScheme.className)];
|
|
71
|
-
// }
|
|
72
|
-
const finalParameters = {
|
|
146
|
+
return sh_NodeShape.createUnsafe({
|
|
73
147
|
...otherParameters,
|
|
74
|
-
$identifier:
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
? toIri(resolveParameter, namespace)
|
|
83
|
-
: undefined,
|
|
84
|
-
};
|
|
85
|
-
return sh_PropertyShape.createUnsafe(finalParameters);
|
|
148
|
+
$identifier: nodeShapeIdentifier,
|
|
149
|
+
in_: convertIn(inParameter),
|
|
150
|
+
nodeKind: convertNodeKind(nodeKindParameter),
|
|
151
|
+
properties,
|
|
152
|
+
shaclmateName,
|
|
153
|
+
type,
|
|
154
|
+
xone: xoneParameter ? xoneParameter.map(toIri) : undefined,
|
|
155
|
+
});
|
|
86
156
|
},
|
|
157
|
+
PropertyShape,
|
|
87
158
|
};
|
|
88
159
|
}
|
|
89
160
|
//# sourceMappingURL=sh.js.map
|