@shaclmate/shacl-ast 3.0.3 → 4.0.0

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/generated.js CHANGED
@@ -1,6 +1,169 @@
1
- import { dataFactory, datasetFactory, purify, rdfjsResource, } from "@shaclmate/runtime";
2
- import { PropertyPath } from "./PropertyPath.js";
3
- export var $RdfVocabularies;
1
+ import dataFactory from "@rdfjs/data-model";
2
+ import datasetFactory from "@rdfjs/dataset";
3
+ import { Either, Left, Maybe, Right } from "purify-ts";
4
+ import { LiteralFactory, PropertyPath, Resource, ResourceSet, } from "rdfjs-resource";
5
+ function $filterArray(filterItem) {
6
+ return (filter, values) => {
7
+ for (const value of values) {
8
+ if (!filterItem(filter, value)) {
9
+ return false;
10
+ }
11
+ }
12
+ if (filter.$maxCount !== undefined && values.length > filter.$maxCount) {
13
+ return false;
14
+ }
15
+ if (filter.$minCount !== undefined && values.length < filter.$minCount) {
16
+ return false;
17
+ }
18
+ return true;
19
+ };
20
+ }
21
+ function $filterBoolean(filter, value) {
22
+ if (filter.value !== undefined && value !== filter.value) {
23
+ return false;
24
+ }
25
+ return true;
26
+ }
27
+ function $filterIdentifier(filter, value) {
28
+ if (filter.in !== undefined &&
29
+ !filter.in.some((inValue) => inValue.equals(value))) {
30
+ return false;
31
+ }
32
+ if (filter.type !== undefined && value.termType !== filter.type) {
33
+ return false;
34
+ }
35
+ return true;
36
+ }
37
+ function $filterIri(filter, value) {
38
+ if (filter.in !== undefined &&
39
+ !filter.in.some((inValue) => inValue.equals(value))) {
40
+ return false;
41
+ }
42
+ return true;
43
+ }
44
+ function $filterLiteral(filter, value) {
45
+ return $filterTerm(filter, value);
46
+ }
47
+ function $filterMaybe(filterItem) {
48
+ return (filter, value) => {
49
+ if (filter !== null) {
50
+ if (value.isNothing()) {
51
+ return false;
52
+ }
53
+ if (!filterItem(filter, value.extract())) {
54
+ return false;
55
+ }
56
+ }
57
+ else {
58
+ if (value.isJust()) {
59
+ return false;
60
+ }
61
+ }
62
+ return true;
63
+ };
64
+ }
65
+ function $filterNumeric(filter, value) {
66
+ if (filter.in !== undefined &&
67
+ !filter.in.some((inValue) => inValue === value)) {
68
+ return false;
69
+ }
70
+ if (filter.maxExclusive !== undefined && value >= filter.maxExclusive) {
71
+ return false;
72
+ }
73
+ if (filter.maxInclusive !== undefined && value > filter.maxInclusive) {
74
+ return false;
75
+ }
76
+ if (filter.minExclusive !== undefined && value <= filter.minExclusive) {
77
+ return false;
78
+ }
79
+ if (filter.minInclusive !== undefined && value < filter.minInclusive) {
80
+ return false;
81
+ }
82
+ return true;
83
+ }
84
+ function $filterString(filter, value) {
85
+ if (filter.in !== undefined &&
86
+ !filter.in.some((inValue) => inValue === value)) {
87
+ return false;
88
+ }
89
+ if (filter.maxLength !== undefined && value.length > filter.maxLength) {
90
+ return false;
91
+ }
92
+ if (filter.minLength !== undefined && value.length < filter.minLength) {
93
+ return false;
94
+ }
95
+ return true;
96
+ }
97
+ function $filterTerm(filter, value) {
98
+ if (filter.datatypeIn !== undefined &&
99
+ (value.termType !== "Literal" ||
100
+ !filter.datatypeIn.some((inDatatype) => inDatatype.equals(value.datatype)))) {
101
+ return false;
102
+ }
103
+ if (filter.in !== undefined &&
104
+ !filter.in.some((inTerm) => inTerm.equals(value))) {
105
+ return false;
106
+ }
107
+ if (filter.languageIn !== undefined &&
108
+ (value.termType !== "Literal" ||
109
+ !filter.languageIn.some((inLanguage) => inLanguage === value.language))) {
110
+ return false;
111
+ }
112
+ if (filter.typeIn !== undefined &&
113
+ !filter.typeIn.some((inType) => inType === value.termType)) {
114
+ return false;
115
+ }
116
+ return true;
117
+ }
118
+ function $fromRdfPreferredLanguages(values, preferredLanguages) {
119
+ if (!preferredLanguages || preferredLanguages.length === 0) {
120
+ return Right(values);
121
+ }
122
+ // Return all literals for the first preferredLanguage, then all literals for the second preferredLanguage, etc.
123
+ // Within a preferredLanguage the literals may be in any order.
124
+ const filteredValues = [];
125
+ for (const preferredLanguage of preferredLanguages) {
126
+ for (const value of values) {
127
+ value.toLiteral().ifRight((literal) => {
128
+ if (literal.language === preferredLanguage) {
129
+ filteredValues.push(value);
130
+ }
131
+ });
132
+ }
133
+ }
134
+ return Right(Resource.Values.fromArray({
135
+ focusResource: values.focusResource,
136
+ propertyPath: values.propertyPath,
137
+ values: filteredValues,
138
+ }));
139
+ }
140
+ function $identifierFromString(identifier) {
141
+ return Either.encase(() => Resource.Identifier.fromString({ dataFactory, identifier }));
142
+ }
143
+ class $IdentifierSet {
144
+ blankNodeValues = new Set();
145
+ namedNodeValues = new Set();
146
+ add(identifier) {
147
+ switch (identifier.termType) {
148
+ case "BlankNode":
149
+ this.blankNodeValues.add(identifier.value);
150
+ return this;
151
+ case "NamedNode":
152
+ this.namedNodeValues.add(identifier.value);
153
+ return this;
154
+ }
155
+ }
156
+ has(identifier) {
157
+ switch (identifier.termType) {
158
+ case "BlankNode":
159
+ return this.blankNodeValues.has(identifier.value);
160
+ case "NamedNode":
161
+ return this.namedNodeValues.has(identifier.value);
162
+ }
163
+ }
164
+ }
165
+ const $literalFactory = new LiteralFactory({ dataFactory: dataFactory });
166
+ var $RdfVocabularies;
4
167
  (function ($RdfVocabularies) {
5
168
  let rdf;
6
169
  (function (rdf) {
@@ -17,723 +180,617 @@ export var $RdfVocabularies;
17
180
  let xsd;
18
181
  (function (xsd) {
19
182
  xsd.boolean = dataFactory.namedNode("http://www.w3.org/2001/XMLSchema#boolean");
183
+ xsd.byte = dataFactory.namedNode("http://www.w3.org/2001/XMLSchema#byte");
20
184
  xsd.date = dataFactory.namedNode("http://www.w3.org/2001/XMLSchema#date");
21
185
  xsd.dateTime = dataFactory.namedNode("http://www.w3.org/2001/XMLSchema#dateTime");
186
+ xsd.decimal = dataFactory.namedNode("http://www.w3.org/2001/XMLSchema#decimal");
187
+ xsd.double = dataFactory.namedNode("http://www.w3.org/2001/XMLSchema#double");
188
+ xsd.float = dataFactory.namedNode("http://www.w3.org/2001/XMLSchema#float");
189
+ xsd.int = dataFactory.namedNode("http://www.w3.org/2001/XMLSchema#int");
22
190
  xsd.integer = dataFactory.namedNode("http://www.w3.org/2001/XMLSchema#integer");
191
+ xsd.long = dataFactory.namedNode("http://www.w3.org/2001/XMLSchema#long");
192
+ xsd.negativeInteger = dataFactory.namedNode("http://www.w3.org/2001/XMLSchema#negativeInteger");
193
+ xsd.nonNegativeInteger = dataFactory.namedNode("http://www.w3.org/2001/XMLSchema#nonNegativeInteger");
194
+ xsd.nonPositiveInteger = dataFactory.namedNode("http://www.w3.org/2001/XMLSchema#nonPositiveInteger");
195
+ xsd.positiveInteger = dataFactory.namedNode("http://www.w3.org/2001/XMLSchema#positiveInteger");
196
+ xsd.short = dataFactory.namedNode("http://www.w3.org/2001/XMLSchema#short");
197
+ xsd.string = dataFactory.namedNode("http://www.w3.org/2001/XMLSchema#string");
198
+ xsd.unsignedByte = dataFactory.namedNode("http://www.w3.org/2001/XMLSchema#unsignedByte");
199
+ xsd.unsignedInt = dataFactory.namedNode("http://www.w3.org/2001/XMLSchema#unsignedInt");
200
+ xsd.unsignedLong = dataFactory.namedNode("http://www.w3.org/2001/XMLSchema#unsignedLong");
201
+ xsd.unsignedShort = dataFactory.namedNode("http://www.w3.org/2001/XMLSchema#unsignedShort");
23
202
  })(xsd = $RdfVocabularies.xsd || ($RdfVocabularies.xsd = {}));
24
203
  })($RdfVocabularies || ($RdfVocabularies = {}));
204
+ function $shaclPropertyFromRdf({ graph, propertySchema, resource, typeFromRdf, }) {
205
+ return typeFromRdf(Right(resource.values(propertySchema.path, { graph, unique: true }))).chain((values) => values.head());
206
+ }
25
207
  export var BaseShaclCoreShapeStatic;
26
208
  (function (BaseShaclCoreShapeStatic) {
27
- let $Identifier;
28
- (function ($Identifier) {
29
- function fromString(identifier) {
30
- return purify.Either.encase(() => rdfjsResource.Resource.Identifier.fromString({
31
- dataFactory,
32
- identifier,
33
- }));
209
+ function $filter(filter, value) {
210
+ if (filter.$identifier !== undefined &&
211
+ !$filterIdentifier(filter.$identifier, value.$identifier)) {
212
+ return false;
34
213
  }
35
- $Identifier.fromString = fromString;
36
- $Identifier.toString = rdfjsResource.Resource.Identifier.toString;
37
- })($Identifier = BaseShaclCoreShapeStatic.$Identifier || (BaseShaclCoreShapeStatic.$Identifier = {}));
38
- function $fromRdf(resource, options) {
39
- let { ignoreRdfType = false, objectSet, preferredLanguages, ...context } = options ?? {};
40
- if (!objectSet) {
41
- objectSet = new $RdfjsDatasetObjectSet({ dataset: resource.dataset });
214
+ if (filter.and !== undefined &&
215
+ !$filterArray($filterArray($filterIdentifier))(filter.and, value.and)) {
216
+ return false;
42
217
  }
43
- return ShaclCoreNodeShape.$fromRdf(resource, {
44
- ...context,
45
- ignoreRdfType: false,
46
- objectSet,
47
- }).altLazy(() => ShaclCorePropertyShape.$fromRdf(resource, {
48
- ...context,
49
- ignoreRdfType: false,
50
- objectSet,
51
- }));
52
- }
53
- BaseShaclCoreShapeStatic.$fromRdf = $fromRdf;
54
- function $propertiesFromRdf({ ignoreRdfType: $ignoreRdfType, objectSet: $objectSet, preferredLanguages: $preferredLanguages, resource: $resource,
55
- // @ts-ignore
56
- ...$context }) {
57
- const $identifier = $resource.identifier;
58
- const _andEither = purify.Either.of($resource.values(BaseShaclCoreShapeStatic.$properties.and["identifier"], { unique: true }))
59
- .chain((values) => values.chainMap((value) => value.toList()))
60
- .chain((valueLists) => valueLists.chainMap((valueList) => purify.Either.of(rdfjsResource.Resource.Values.fromArray({
61
- objects: valueList,
62
- predicate: BaseShaclCoreShapeStatic.$properties.and["identifier"],
63
- subject: $resource,
64
- })).chain((values) => values.chainMap((value) => value.toIdentifier()))))
65
- .map((valueLists) => valueLists.map((valueList) => valueList.toArray()))
66
- .map((values) => values.toArray())
67
- .map((valuesArray) => rdfjsResource.Resource.Values.fromValue({
68
- object: valuesArray,
69
- predicate: BaseShaclCoreShapeStatic.$properties.and["identifier"],
70
- subject: $resource,
71
- }))
72
- .chain((values) => values.head());
73
- if (_andEither.isLeft()) {
74
- return _andEither;
75
- }
76
- const and = _andEither.unsafeCoerce();
77
- const _classesEither = purify.Either.of($resource.values(BaseShaclCoreShapeStatic.$properties.classes["identifier"], { unique: true }))
78
- .chain((values) => values.chainMap((value) => value.toIri()))
79
- .map((values) => values.toArray())
80
- .map((valuesArray) => rdfjsResource.Resource.Values.fromValue({
81
- object: valuesArray,
82
- predicate: BaseShaclCoreShapeStatic.$properties.classes["identifier"],
83
- subject: $resource,
84
- }))
85
- .chain((values) => values.head());
86
- if (_classesEither.isLeft()) {
87
- return _classesEither;
88
- }
89
- const classes = _classesEither.unsafeCoerce();
90
- const _commentsEither = purify.Either.of($resource.values(BaseShaclCoreShapeStatic.$properties.comments["identifier"], { unique: true }))
91
- .chain((values) => {
92
- if (!$preferredLanguages || $preferredLanguages.length === 0) {
93
- return purify.Either.of(values);
94
- }
95
- const literalValuesEither = values.chainMap((value) => value.toLiteral());
96
- if (literalValuesEither.isLeft()) {
97
- return literalValuesEither;
98
- }
99
- const literalValues = literalValuesEither.unsafeCoerce();
100
- // Return all literals for the first preferredLanguage, then all literals for the second preferredLanguage, etc.
101
- // Within a preferredLanguage the literals may be in any order.
102
- let filteredLiteralValues;
103
- for (const preferredLanguage of $preferredLanguages) {
104
- if (!filteredLiteralValues) {
105
- filteredLiteralValues = literalValues.filter((value) => value.language === preferredLanguage);
106
- }
107
- else {
108
- filteredLiteralValues = filteredLiteralValues.concat(...literalValues
109
- .filter((value) => value.language === preferredLanguage)
110
- .toArray());
111
- }
112
- }
113
- return purify.Either.of(filteredLiteralValues.map((literalValue) => new rdfjsResource.Resource.Value({
114
- object: literalValue,
115
- predicate: BaseShaclCoreShapeStatic.$properties.comments["identifier"],
116
- subject: $resource,
117
- })));
118
- })
119
- .chain((values) => values.chainMap((value) => value.toLiteral()))
120
- .map((values) => values.toArray())
121
- .map((valuesArray) => rdfjsResource.Resource.Values.fromValue({
122
- object: valuesArray,
123
- predicate: BaseShaclCoreShapeStatic.$properties.comments["identifier"],
124
- subject: $resource,
125
- }))
126
- .chain((values) => values.head());
127
- if (_commentsEither.isLeft()) {
128
- return _commentsEither;
129
- }
130
- const comments = _commentsEither.unsafeCoerce();
131
- const _datatypeEither = purify.Either.of($resource.values(BaseShaclCoreShapeStatic.$properties.datatype["identifier"], { unique: true }))
132
- .chain((values) => values.chainMap((value) => value.toIri()))
133
- .map((values) => values.length > 0
134
- ? values.map((value) => purify.Maybe.of(value))
135
- : rdfjsResource.Resource.Values.fromValue({
136
- object: purify.Maybe.empty(),
137
- predicate: BaseShaclCoreShapeStatic.$properties.datatype["identifier"],
138
- subject: $resource,
139
- }))
140
- .chain((values) => values.head());
141
- if (_datatypeEither.isLeft()) {
142
- return _datatypeEither;
143
- }
144
- const datatype = _datatypeEither.unsafeCoerce();
145
- const _deactivatedEither = purify.Either.of($resource.values(BaseShaclCoreShapeStatic.$properties.deactivated["identifier"], { unique: true }))
146
- .chain((values) => values.chainMap((value) => value.toBoolean()))
147
- .map((values) => values.length > 0
148
- ? values.map((value) => purify.Maybe.of(value))
149
- : rdfjsResource.Resource.Values.fromValue({
150
- object: purify.Maybe.empty(),
151
- predicate: BaseShaclCoreShapeStatic.$properties.deactivated["identifier"],
152
- subject: $resource,
153
- }))
154
- .chain((values) => values.head());
155
- if (_deactivatedEither.isLeft()) {
156
- return _deactivatedEither;
157
- }
158
- const deactivated = _deactivatedEither.unsafeCoerce();
159
- const _flagsEither = purify.Either.of($resource.values(BaseShaclCoreShapeStatic.$properties.flags["identifier"], { unique: true }))
160
- .chain((values) => {
161
- if (!$preferredLanguages || $preferredLanguages.length === 0) {
162
- return purify.Either.of(values);
163
- }
164
- const literalValuesEither = values.chainMap((value) => value.toLiteral());
165
- if (literalValuesEither.isLeft()) {
166
- return literalValuesEither;
167
- }
168
- const literalValues = literalValuesEither.unsafeCoerce();
169
- // Return all literals for the first preferredLanguage, then all literals for the second preferredLanguage, etc.
170
- // Within a preferredLanguage the literals may be in any order.
171
- let filteredLiteralValues;
172
- for (const preferredLanguage of $preferredLanguages) {
173
- if (!filteredLiteralValues) {
174
- filteredLiteralValues = literalValues.filter((value) => value.language === preferredLanguage);
175
- }
176
- else {
177
- filteredLiteralValues = filteredLiteralValues.concat(...literalValues
178
- .filter((value) => value.language === preferredLanguage)
179
- .toArray());
180
- }
181
- }
182
- return purify.Either.of(filteredLiteralValues.map((literalValue) => new rdfjsResource.Resource.Value({
183
- object: literalValue,
184
- predicate: BaseShaclCoreShapeStatic.$properties.flags["identifier"],
185
- subject: $resource,
186
- })));
187
- })
188
- .chain((values) => values.chainMap((value) => value.toString()))
189
- .map((values) => values.toArray())
190
- .map((valuesArray) => rdfjsResource.Resource.Values.fromValue({
191
- object: valuesArray,
192
- predicate: BaseShaclCoreShapeStatic.$properties.flags["identifier"],
193
- subject: $resource,
194
- }))
195
- .chain((values) => values.head());
196
- if (_flagsEither.isLeft()) {
197
- return _flagsEither;
198
- }
199
- const flags = _flagsEither.unsafeCoerce();
200
- const _hasValuesEither = purify.Either.of($resource.values(BaseShaclCoreShapeStatic.$properties.hasValues["identifier"], { unique: true }))
201
- .chain((values) => values.chainMap((value) => purify.Either.of(value.toTerm()).chain((term) => {
202
- switch (term.termType) {
203
- case "Literal":
204
- case "NamedNode":
205
- return purify.Either.of(term);
206
- default:
207
- return purify.Left(new rdfjsResource.Resource.MistypedValueError({
208
- actualValue: term,
209
- expectedValueType: "(rdfjs.Literal | rdfjs.NamedNode)",
210
- focusResource: $resource,
211
- predicate: BaseShaclCoreShapeStatic.$properties.hasValues["identifier"],
212
- }));
213
- }
214
- })))
215
- .map((values) => values.toArray())
216
- .map((valuesArray) => rdfjsResource.Resource.Values.fromValue({
217
- object: valuesArray,
218
- predicate: BaseShaclCoreShapeStatic.$properties.hasValues["identifier"],
219
- subject: $resource,
220
- }))
221
- .chain((values) => values.head());
222
- if (_hasValuesEither.isLeft()) {
223
- return _hasValuesEither;
224
- }
225
- const hasValues = _hasValuesEither.unsafeCoerce();
226
- const _in_Either = purify.Either.of($resource.values(BaseShaclCoreShapeStatic.$properties.in_["identifier"], { unique: true }))
227
- .chain((values) => values.chainMap((value) => value.toList()))
228
- .chain((valueLists) => valueLists.chainMap((valueList) => purify.Either.of(rdfjsResource.Resource.Values.fromArray({
229
- objects: valueList,
230
- predicate: BaseShaclCoreShapeStatic.$properties.in_["identifier"],
231
- subject: $resource,
232
- })).chain((values) => values.chainMap((value) => purify.Either.of(value.toTerm()).chain((term) => {
233
- switch (term.termType) {
234
- case "Literal":
235
- case "NamedNode":
236
- return purify.Either.of(term);
237
- default:
238
- return purify.Left(new rdfjsResource.Resource.MistypedValueError({
239
- actualValue: term,
240
- expectedValueType: "(rdfjs.Literal | rdfjs.NamedNode)",
241
- focusResource: $resource,
242
- predicate: BaseShaclCoreShapeStatic.$properties.in_["identifier"],
243
- }));
244
- }
245
- })))))
246
- .map((valueLists) => valueLists.map((valueList) => valueList.toArray()))
247
- .map((values) => values.length > 0
248
- ? values.map((value) => purify.Maybe.of(value))
249
- : rdfjsResource.Resource.Values.fromValue({
250
- object: purify.Maybe.empty(),
251
- predicate: BaseShaclCoreShapeStatic.$properties.in_["identifier"],
252
- subject: $resource,
253
- }))
254
- .chain((values) => values.head());
255
- if (_in_Either.isLeft()) {
256
- return _in_Either;
218
+ if (filter.classes !== undefined &&
219
+ !$filterArray($filterIri)(filter.classes, value.classes)) {
220
+ return false;
257
221
  }
258
- const in_ = _in_Either.unsafeCoerce();
259
- const _isDefinedByEither = purify.Either.of($resource.values(BaseShaclCoreShapeStatic.$properties.isDefinedBy["identifier"], { unique: true }))
260
- .chain((values) => values.chainMap((value) => value.toIdentifier()))
261
- .map((values) => values.length > 0
262
- ? values.map((value) => purify.Maybe.of(value))
263
- : rdfjsResource.Resource.Values.fromValue({
264
- object: purify.Maybe.empty(),
265
- predicate: BaseShaclCoreShapeStatic.$properties.isDefinedBy["identifier"],
266
- subject: $resource,
267
- }))
268
- .chain((values) => values.head());
269
- if (_isDefinedByEither.isLeft()) {
270
- return _isDefinedByEither;
271
- }
272
- const isDefinedBy = _isDefinedByEither.unsafeCoerce();
273
- const _labelsEither = purify.Either.of($resource.values(BaseShaclCoreShapeStatic.$properties.labels["identifier"], { unique: true }))
274
- .chain((values) => {
275
- if (!$preferredLanguages || $preferredLanguages.length === 0) {
276
- return purify.Either.of(values);
277
- }
278
- const literalValuesEither = values.chainMap((value) => value.toLiteral());
279
- if (literalValuesEither.isLeft()) {
280
- return literalValuesEither;
281
- }
282
- const literalValues = literalValuesEither.unsafeCoerce();
283
- // Return all literals for the first preferredLanguage, then all literals for the second preferredLanguage, etc.
284
- // Within a preferredLanguage the literals may be in any order.
285
- let filteredLiteralValues;
286
- for (const preferredLanguage of $preferredLanguages) {
287
- if (!filteredLiteralValues) {
288
- filteredLiteralValues = literalValues.filter((value) => value.language === preferredLanguage);
289
- }
290
- else {
291
- filteredLiteralValues = filteredLiteralValues.concat(...literalValues
292
- .filter((value) => value.language === preferredLanguage)
293
- .toArray());
294
- }
295
- }
296
- return purify.Either.of(filteredLiteralValues.map((literalValue) => new rdfjsResource.Resource.Value({
297
- object: literalValue,
298
- predicate: BaseShaclCoreShapeStatic.$properties.labels["identifier"],
299
- subject: $resource,
300
- })));
301
- })
302
- .chain((values) => values.chainMap((value) => value.toLiteral()))
303
- .map((values) => values.toArray())
304
- .map((valuesArray) => rdfjsResource.Resource.Values.fromValue({
305
- object: valuesArray,
306
- predicate: BaseShaclCoreShapeStatic.$properties.labels["identifier"],
307
- subject: $resource,
308
- }))
309
- .chain((values) => values.head());
310
- if (_labelsEither.isLeft()) {
311
- return _labelsEither;
312
- }
313
- const labels = _labelsEither.unsafeCoerce();
314
- const _languageInEither = purify.Either.of($resource.values(BaseShaclCoreShapeStatic.$properties.languageIn["identifier"], { unique: true }))
315
- .chain((values) => values.chainMap((value) => value.toList()))
316
- .chain((valueLists) => valueLists.chainMap((valueList) => purify.Either.of(rdfjsResource.Resource.Values.fromArray({
317
- objects: valueList,
318
- predicate: BaseShaclCoreShapeStatic.$properties.languageIn["identifier"],
319
- subject: $resource,
320
- }))
321
- .chain((values) => {
322
- if (!$preferredLanguages || $preferredLanguages.length === 0) {
323
- return purify.Either.of(values);
324
- }
325
- const literalValuesEither = values.chainMap((value) => value.toLiteral());
326
- if (literalValuesEither.isLeft()) {
327
- return literalValuesEither;
328
- }
329
- const literalValues = literalValuesEither.unsafeCoerce();
330
- // Return all literals for the first preferredLanguage, then all literals for the second preferredLanguage, etc.
331
- // Within a preferredLanguage the literals may be in any order.
332
- let filteredLiteralValues;
333
- for (const preferredLanguage of $preferredLanguages) {
334
- if (!filteredLiteralValues) {
335
- filteredLiteralValues = literalValues.filter((value) => value.language === preferredLanguage);
336
- }
337
- else {
338
- filteredLiteralValues = filteredLiteralValues.concat(...literalValues
339
- .filter((value) => value.language === preferredLanguage)
340
- .toArray());
341
- }
342
- }
343
- return purify.Either.of(filteredLiteralValues.map((literalValue) => new rdfjsResource.Resource.Value({
344
- object: literalValue,
345
- predicate: BaseShaclCoreShapeStatic.$properties.languageIn["identifier"],
346
- subject: $resource,
347
- })));
348
- })
349
- .chain((values) => values.chainMap((value) => value.toString()))))
350
- .map((valueLists) => valueLists.map((valueList) => valueList.toArray()))
351
- .map((values) => values.length > 0
352
- ? values.map((value) => purify.Maybe.of(value))
353
- : rdfjsResource.Resource.Values.fromValue({
354
- object: purify.Maybe.empty(),
355
- predicate: BaseShaclCoreShapeStatic.$properties.languageIn["identifier"],
356
- subject: $resource,
357
- }))
358
- .chain((values) => values.head());
359
- if (_languageInEither.isLeft()) {
360
- return _languageInEither;
361
- }
362
- const languageIn = _languageInEither.unsafeCoerce();
363
- const _maxCountEither = purify.Either.of($resource.values(BaseShaclCoreShapeStatic.$properties.maxCount["identifier"], { unique: true }))
364
- .chain((values) => values.chainMap((value) => value.toNumber()))
365
- .map((values) => values.length > 0
366
- ? values.map((value) => purify.Maybe.of(value))
367
- : rdfjsResource.Resource.Values.fromValue({
368
- object: purify.Maybe.empty(),
369
- predicate: BaseShaclCoreShapeStatic.$properties.maxCount["identifier"],
370
- subject: $resource,
371
- }))
372
- .chain((values) => values.head());
373
- if (_maxCountEither.isLeft()) {
374
- return _maxCountEither;
222
+ if (filter.comments !== undefined &&
223
+ !$filterArray($filterString)(filter.comments, value.comments)) {
224
+ return false;
375
225
  }
376
- const maxCount = _maxCountEither.unsafeCoerce();
377
- const _maxExclusiveEither = purify.Either.of($resource.values(BaseShaclCoreShapeStatic.$properties.maxExclusive["identifier"], {
378
- unique: true,
379
- }))
380
- .chain((values) => {
381
- if (!$preferredLanguages || $preferredLanguages.length === 0) {
382
- return purify.Either.of(values);
383
- }
384
- const literalValuesEither = values.chainMap((value) => value.toLiteral());
385
- if (literalValuesEither.isLeft()) {
386
- return literalValuesEither;
387
- }
388
- const literalValues = literalValuesEither.unsafeCoerce();
389
- // Return all literals for the first preferredLanguage, then all literals for the second preferredLanguage, etc.
390
- // Within a preferredLanguage the literals may be in any order.
391
- let filteredLiteralValues;
392
- for (const preferredLanguage of $preferredLanguages) {
393
- if (!filteredLiteralValues) {
394
- filteredLiteralValues = literalValues.filter((value) => value.language === preferredLanguage);
395
- }
396
- else {
397
- filteredLiteralValues = filteredLiteralValues.concat(...literalValues
398
- .filter((value) => value.language === preferredLanguage)
399
- .toArray());
400
- }
401
- }
402
- return purify.Either.of(filteredLiteralValues.map((literalValue) => new rdfjsResource.Resource.Value({
403
- object: literalValue,
404
- predicate: BaseShaclCoreShapeStatic.$properties.maxExclusive["identifier"],
405
- subject: $resource,
406
- })));
407
- })
408
- .chain((values) => values.chainMap((value) => value.toLiteral()))
409
- .map((values) => values.length > 0
410
- ? values.map((value) => purify.Maybe.of(value))
411
- : rdfjsResource.Resource.Values.fromValue({
412
- object: purify.Maybe.empty(),
413
- predicate: BaseShaclCoreShapeStatic.$properties.maxExclusive["identifier"],
414
- subject: $resource,
415
- }))
416
- .chain((values) => values.head());
417
- if (_maxExclusiveEither.isLeft()) {
418
- return _maxExclusiveEither;
226
+ if (filter.datatype !== undefined &&
227
+ !$filterMaybe($filterIri)(filter.datatype, value.datatype)) {
228
+ return false;
419
229
  }
420
- const maxExclusive = _maxExclusiveEither.unsafeCoerce();
421
- const _maxInclusiveEither = purify.Either.of($resource.values(BaseShaclCoreShapeStatic.$properties.maxInclusive["identifier"], {
422
- unique: true,
423
- }))
424
- .chain((values) => {
425
- if (!$preferredLanguages || $preferredLanguages.length === 0) {
426
- return purify.Either.of(values);
427
- }
428
- const literalValuesEither = values.chainMap((value) => value.toLiteral());
429
- if (literalValuesEither.isLeft()) {
430
- return literalValuesEither;
431
- }
432
- const literalValues = literalValuesEither.unsafeCoerce();
433
- // Return all literals for the first preferredLanguage, then all literals for the second preferredLanguage, etc.
434
- // Within a preferredLanguage the literals may be in any order.
435
- let filteredLiteralValues;
436
- for (const preferredLanguage of $preferredLanguages) {
437
- if (!filteredLiteralValues) {
438
- filteredLiteralValues = literalValues.filter((value) => value.language === preferredLanguage);
439
- }
440
- else {
441
- filteredLiteralValues = filteredLiteralValues.concat(...literalValues
442
- .filter((value) => value.language === preferredLanguage)
443
- .toArray());
444
- }
445
- }
446
- return purify.Either.of(filteredLiteralValues.map((literalValue) => new rdfjsResource.Resource.Value({
447
- object: literalValue,
448
- predicate: BaseShaclCoreShapeStatic.$properties.maxInclusive["identifier"],
449
- subject: $resource,
450
- })));
451
- })
452
- .chain((values) => values.chainMap((value) => value.toLiteral()))
453
- .map((values) => values.length > 0
454
- ? values.map((value) => purify.Maybe.of(value))
455
- : rdfjsResource.Resource.Values.fromValue({
456
- object: purify.Maybe.empty(),
457
- predicate: BaseShaclCoreShapeStatic.$properties.maxInclusive["identifier"],
458
- subject: $resource,
459
- }))
460
- .chain((values) => values.head());
461
- if (_maxInclusiveEither.isLeft()) {
462
- return _maxInclusiveEither;
463
- }
464
- const maxInclusive = _maxInclusiveEither.unsafeCoerce();
465
- const _maxLengthEither = purify.Either.of($resource.values(BaseShaclCoreShapeStatic.$properties.maxLength["identifier"], { unique: true }))
466
- .chain((values) => values.chainMap((value) => value.toNumber()))
467
- .map((values) => values.length > 0
468
- ? values.map((value) => purify.Maybe.of(value))
469
- : rdfjsResource.Resource.Values.fromValue({
470
- object: purify.Maybe.empty(),
471
- predicate: BaseShaclCoreShapeStatic.$properties.maxLength["identifier"],
472
- subject: $resource,
473
- }))
474
- .chain((values) => values.head());
475
- if (_maxLengthEither.isLeft()) {
476
- return _maxLengthEither;
477
- }
478
- const maxLength = _maxLengthEither.unsafeCoerce();
479
- const _minCountEither = purify.Either.of($resource.values(BaseShaclCoreShapeStatic.$properties.minCount["identifier"], { unique: true }))
480
- .chain((values) => values.chainMap((value) => value.toNumber()))
481
- .map((values) => values.length > 0
482
- ? values.map((value) => purify.Maybe.of(value))
483
- : rdfjsResource.Resource.Values.fromValue({
484
- object: purify.Maybe.empty(),
485
- predicate: BaseShaclCoreShapeStatic.$properties.minCount["identifier"],
486
- subject: $resource,
487
- }))
488
- .chain((values) => values.head());
489
- if (_minCountEither.isLeft()) {
490
- return _minCountEither;
230
+ if (filter.deactivated !== undefined &&
231
+ !$filterMaybe($filterBoolean)(filter.deactivated, value.deactivated)) {
232
+ return false;
491
233
  }
492
- const minCount = _minCountEither.unsafeCoerce();
493
- const _minExclusiveEither = purify.Either.of($resource.values(BaseShaclCoreShapeStatic.$properties.minExclusive["identifier"], {
494
- unique: true,
495
- }))
496
- .chain((values) => {
497
- if (!$preferredLanguages || $preferredLanguages.length === 0) {
498
- return purify.Either.of(values);
499
- }
500
- const literalValuesEither = values.chainMap((value) => value.toLiteral());
501
- if (literalValuesEither.isLeft()) {
502
- return literalValuesEither;
503
- }
504
- const literalValues = literalValuesEither.unsafeCoerce();
505
- // Return all literals for the first preferredLanguage, then all literals for the second preferredLanguage, etc.
506
- // Within a preferredLanguage the literals may be in any order.
507
- let filteredLiteralValues;
508
- for (const preferredLanguage of $preferredLanguages) {
509
- if (!filteredLiteralValues) {
510
- filteredLiteralValues = literalValues.filter((value) => value.language === preferredLanguage);
511
- }
512
- else {
513
- filteredLiteralValues = filteredLiteralValues.concat(...literalValues
514
- .filter((value) => value.language === preferredLanguage)
515
- .toArray());
516
- }
517
- }
518
- return purify.Either.of(filteredLiteralValues.map((literalValue) => new rdfjsResource.Resource.Value({
519
- object: literalValue,
520
- predicate: BaseShaclCoreShapeStatic.$properties.minExclusive["identifier"],
521
- subject: $resource,
522
- })));
523
- })
524
- .chain((values) => values.chainMap((value) => value.toLiteral()))
525
- .map((values) => values.length > 0
526
- ? values.map((value) => purify.Maybe.of(value))
527
- : rdfjsResource.Resource.Values.fromValue({
528
- object: purify.Maybe.empty(),
529
- predicate: BaseShaclCoreShapeStatic.$properties.minExclusive["identifier"],
530
- subject: $resource,
531
- }))
532
- .chain((values) => values.head());
533
- if (_minExclusiveEither.isLeft()) {
534
- return _minExclusiveEither;
234
+ if (filter.flags !== undefined &&
235
+ !$filterArray($filterString)(filter.flags, value.flags)) {
236
+ return false;
535
237
  }
536
- const minExclusive = _minExclusiveEither.unsafeCoerce();
537
- const _minInclusiveEither = purify.Either.of($resource.values(BaseShaclCoreShapeStatic.$properties.minInclusive["identifier"], {
538
- unique: true,
539
- }))
540
- .chain((values) => {
541
- if (!$preferredLanguages || $preferredLanguages.length === 0) {
542
- return purify.Either.of(values);
543
- }
544
- const literalValuesEither = values.chainMap((value) => value.toLiteral());
545
- if (literalValuesEither.isLeft()) {
546
- return literalValuesEither;
547
- }
548
- const literalValues = literalValuesEither.unsafeCoerce();
549
- // Return all literals for the first preferredLanguage, then all literals for the second preferredLanguage, etc.
550
- // Within a preferredLanguage the literals may be in any order.
551
- let filteredLiteralValues;
552
- for (const preferredLanguage of $preferredLanguages) {
553
- if (!filteredLiteralValues) {
554
- filteredLiteralValues = literalValues.filter((value) => value.language === preferredLanguage);
555
- }
556
- else {
557
- filteredLiteralValues = filteredLiteralValues.concat(...literalValues
558
- .filter((value) => value.language === preferredLanguage)
559
- .toArray());
560
- }
561
- }
562
- return purify.Either.of(filteredLiteralValues.map((literalValue) => new rdfjsResource.Resource.Value({
563
- object: literalValue,
564
- predicate: BaseShaclCoreShapeStatic.$properties.minInclusive["identifier"],
565
- subject: $resource,
566
- })));
567
- })
568
- .chain((values) => values.chainMap((value) => value.toLiteral()))
569
- .map((values) => values.length > 0
570
- ? values.map((value) => purify.Maybe.of(value))
571
- : rdfjsResource.Resource.Values.fromValue({
572
- object: purify.Maybe.empty(),
573
- predicate: BaseShaclCoreShapeStatic.$properties.minInclusive["identifier"],
574
- subject: $resource,
575
- }))
576
- .chain((values) => values.head());
577
- if (_minInclusiveEither.isLeft()) {
578
- return _minInclusiveEither;
579
- }
580
- const minInclusive = _minInclusiveEither.unsafeCoerce();
581
- const _minLengthEither = purify.Either.of($resource.values(BaseShaclCoreShapeStatic.$properties.minLength["identifier"], { unique: true }))
582
- .chain((values) => values.chainMap((value) => value.toNumber()))
583
- .map((values) => values.length > 0
584
- ? values.map((value) => purify.Maybe.of(value))
585
- : rdfjsResource.Resource.Values.fromValue({
586
- object: purify.Maybe.empty(),
587
- predicate: BaseShaclCoreShapeStatic.$properties.minLength["identifier"],
588
- subject: $resource,
589
- }))
590
- .chain((values) => values.head());
591
- if (_minLengthEither.isLeft()) {
592
- return _minLengthEither;
593
- }
594
- const minLength = _minLengthEither.unsafeCoerce();
595
- const _nodeKindEither = purify.Either.of($resource.values(BaseShaclCoreShapeStatic.$properties.nodeKind["identifier"], { unique: true }))
596
- .chain((values) => values.chainMap((value) => value.toIri().chain((iri) => {
597
- switch (iri.value) {
598
- case "http://www.w3.org/ns/shacl#BlankNode":
599
- return purify.Either.of(iri);
600
- case "http://www.w3.org/ns/shacl#BlankNodeOrIRI":
601
- return purify.Either.of(iri);
602
- case "http://www.w3.org/ns/shacl#BlankNodeOrLiteral":
603
- return purify.Either.of(iri);
604
- case "http://www.w3.org/ns/shacl#IRI":
605
- return purify.Either.of(iri);
606
- case "http://www.w3.org/ns/shacl#IRIOrLiteral":
607
- return purify.Either.of(iri);
608
- case "http://www.w3.org/ns/shacl#Literal":
609
- return purify.Either.of(iri);
610
- default:
611
- return purify.Left(new rdfjsResource.Resource.MistypedValueError({
612
- actualValue: iri,
613
- expectedValueType: 'rdfjs.NamedNode<"http://www.w3.org/ns/shacl#BlankNode" | "http://www.w3.org/ns/shacl#BlankNodeOrIRI" | "http://www.w3.org/ns/shacl#BlankNodeOrLiteral" | "http://www.w3.org/ns/shacl#IRI" | "http://www.w3.org/ns/shacl#IRIOrLiteral" | "http://www.w3.org/ns/shacl#Literal">',
614
- focusResource: $resource,
615
- predicate: BaseShaclCoreShapeStatic.$properties.nodeKind["identifier"],
616
- }));
617
- }
618
- })))
619
- .map((values) => values.length > 0
620
- ? values.map((value) => purify.Maybe.of(value))
621
- : rdfjsResource.Resource.Values.fromValue({
622
- object: purify.Maybe.empty(),
623
- predicate: BaseShaclCoreShapeStatic.$properties.nodeKind["identifier"],
624
- subject: $resource,
625
- }))
626
- .chain((values) => values.head());
627
- if (_nodeKindEither.isLeft()) {
628
- return _nodeKindEither;
238
+ if (filter.hasValues !== undefined &&
239
+ !$filterArray($filterTerm)(filter.hasValues, value.hasValues)) {
240
+ return false;
629
241
  }
630
- const nodeKind = _nodeKindEither.unsafeCoerce();
631
- const _nodesEither = purify.Either.of($resource.values(BaseShaclCoreShapeStatic.$properties.nodes["identifier"], { unique: true }))
632
- .chain((values) => values.chainMap((value) => value.toIdentifier()))
633
- .map((values) => values.toArray())
634
- .map((valuesArray) => rdfjsResource.Resource.Values.fromValue({
635
- object: valuesArray,
636
- predicate: BaseShaclCoreShapeStatic.$properties.nodes["identifier"],
637
- subject: $resource,
638
- }))
639
- .chain((values) => values.head());
640
- if (_nodesEither.isLeft()) {
641
- return _nodesEither;
242
+ if (filter.in_ !== undefined &&
243
+ !$filterMaybe($filterArray($filterTerm))(filter.in_, value.in_)) {
244
+ return false;
245
+ }
246
+ if (filter.isDefinedBy !== undefined &&
247
+ !$filterMaybe($filterIdentifier)(filter.isDefinedBy, value.isDefinedBy)) {
248
+ return false;
249
+ }
250
+ if (filter.labels !== undefined &&
251
+ !$filterArray($filterString)(filter.labels, value.labels)) {
252
+ return false;
253
+ }
254
+ if (filter.languageIn !== undefined &&
255
+ !$filterMaybe($filterArray($filterString))(filter.languageIn, value.languageIn)) {
256
+ return false;
257
+ }
258
+ if (filter.maxCount !== undefined &&
259
+ !$filterMaybe(($filterNumeric))(filter.maxCount, value.maxCount)) {
260
+ return false;
261
+ }
262
+ if (filter.maxExclusive !== undefined &&
263
+ !$filterMaybe($filterLiteral)(filter.maxExclusive, value.maxExclusive)) {
264
+ return false;
265
+ }
266
+ if (filter.maxInclusive !== undefined &&
267
+ !$filterMaybe($filterLiteral)(filter.maxInclusive, value.maxInclusive)) {
268
+ return false;
269
+ }
270
+ if (filter.maxLength !== undefined &&
271
+ !$filterMaybe(($filterNumeric))(filter.maxLength, value.maxLength)) {
272
+ return false;
273
+ }
274
+ if (filter.minCount !== undefined &&
275
+ !$filterMaybe(($filterNumeric))(filter.minCount, value.minCount)) {
276
+ return false;
277
+ }
278
+ if (filter.minExclusive !== undefined &&
279
+ !$filterMaybe($filterLiteral)(filter.minExclusive, value.minExclusive)) {
280
+ return false;
281
+ }
282
+ if (filter.minInclusive !== undefined &&
283
+ !$filterMaybe($filterLiteral)(filter.minInclusive, value.minInclusive)) {
284
+ return false;
285
+ }
286
+ if (filter.minLength !== undefined &&
287
+ !$filterMaybe(($filterNumeric))(filter.minLength, value.minLength)) {
288
+ return false;
289
+ }
290
+ if (filter.nodeKind !== undefined &&
291
+ !$filterMaybe($filterIri)(filter.nodeKind, value.nodeKind)) {
292
+ return false;
293
+ }
294
+ if (filter.nodes !== undefined &&
295
+ !$filterArray($filterIdentifier)(filter.nodes, value.nodes)) {
296
+ return false;
297
+ }
298
+ if (filter.not !== undefined &&
299
+ !$filterArray($filterIdentifier)(filter.not, value.not)) {
300
+ return false;
301
+ }
302
+ if (filter.or !== undefined &&
303
+ !$filterArray($filterArray($filterIdentifier))(filter.or, value.or)) {
304
+ return false;
305
+ }
306
+ if (filter.patterns !== undefined &&
307
+ !$filterArray($filterString)(filter.patterns, value.patterns)) {
308
+ return false;
309
+ }
310
+ if (filter.xone !== undefined &&
311
+ !$filterArray($filterArray($filterIdentifier))(filter.xone, value.xone)) {
312
+ return false;
313
+ }
314
+ return true;
315
+ }
316
+ BaseShaclCoreShapeStatic.$filter = $filter;
317
+ let $Identifier;
318
+ (function ($Identifier) {
319
+ $Identifier.fromString = $identifierFromString; // biome-ignore lint/suspicious/noShadowRestrictedNames: allow toString
320
+ $Identifier.toString = Resource.Identifier.toString;
321
+ })($Identifier = BaseShaclCoreShapeStatic.$Identifier || (BaseShaclCoreShapeStatic.$Identifier = {}));
322
+ function isBaseShaclCoreShape(object) {
323
+ switch (object.$type) {
324
+ case "ShaclCoreNodeShape":
325
+ case "ShaclCorePropertyShape":
326
+ return true;
327
+ default:
328
+ return false;
642
329
  }
643
- const nodes = _nodesEither.unsafeCoerce();
644
- const _notEither = purify.Either.of($resource.values(BaseShaclCoreShapeStatic.$properties.not["identifier"], { unique: true }))
330
+ }
331
+ BaseShaclCoreShapeStatic.isBaseShaclCoreShape = isBaseShaclCoreShape;
332
+ function $propertiesFromRdf($parameters) {
333
+ return Right(new Resource.Value({
334
+ dataFactory: dataFactory,
335
+ focusResource: $parameters.resource,
336
+ propertyPath: $RdfVocabularies.rdf.subject,
337
+ term: $parameters.resource.identifier,
338
+ }).toValues())
645
339
  .chain((values) => values.chainMap((value) => value.toIdentifier()))
646
- .map((values) => values.toArray())
647
- .map((valuesArray) => rdfjsResource.Resource.Values.fromValue({
648
- object: valuesArray,
649
- predicate: BaseShaclCoreShapeStatic.$properties.not["identifier"],
650
- subject: $resource,
651
- }))
652
- .chain((values) => values.head());
653
- if (_notEither.isLeft()) {
654
- return _notEither;
655
- }
656
- const not = _notEither.unsafeCoerce();
657
- const _orEither = purify.Either.of($resource.values(BaseShaclCoreShapeStatic.$properties.or["identifier"], { unique: true }))
658
- .chain((values) => values.chainMap((value) => value.toList()))
659
- .chain((valueLists) => valueLists.chainMap((valueList) => purify.Either.of(rdfjsResource.Resource.Values.fromArray({
660
- objects: valueList,
661
- predicate: BaseShaclCoreShapeStatic.$properties.or["identifier"],
662
- subject: $resource,
663
- })).chain((values) => values.chainMap((value) => value.toIdentifier()))))
664
- .map((valueLists) => valueLists.map((valueList) => valueList.toArray()))
665
- .map((values) => values.toArray())
666
- .map((valuesArray) => rdfjsResource.Resource.Values.fromValue({
667
- object: valuesArray,
668
- predicate: BaseShaclCoreShapeStatic.$properties.or["identifier"],
669
- subject: $resource,
670
- }))
671
- .chain((values) => values.head());
672
- if (_orEither.isLeft()) {
673
- return _orEither;
674
- }
675
- const or = _orEither.unsafeCoerce();
676
- const _patternsEither = purify.Either.of($resource.values(BaseShaclCoreShapeStatic.$properties.patterns["identifier"], { unique: true }))
677
- .chain((values) => {
678
- if (!$preferredLanguages || $preferredLanguages.length === 0) {
679
- return purify.Either.of(values);
680
- }
681
- const literalValuesEither = values.chainMap((value) => value.toLiteral());
682
- if (literalValuesEither.isLeft()) {
683
- return literalValuesEither;
684
- }
685
- const literalValues = literalValuesEither.unsafeCoerce();
686
- // Return all literals for the first preferredLanguage, then all literals for the second preferredLanguage, etc.
687
- // Within a preferredLanguage the literals may be in any order.
688
- let filteredLiteralValues;
689
- for (const preferredLanguage of $preferredLanguages) {
690
- if (!filteredLiteralValues) {
691
- filteredLiteralValues = literalValues.filter((value) => value.language === preferredLanguage);
340
+ .chain((values) => values.head())
341
+ .chain(($identifier) => $shaclPropertyFromRdf({
342
+ graph: $parameters.graph,
343
+ resource: $parameters.resource,
344
+ propertySchema: BaseShaclCoreShapeStatic.$schema.properties.and,
345
+ typeFromRdf: (resourceValues) => resourceValues
346
+ .chain((values) => values.chainMap((value) => value.toList({ graph: $parameters.graph })))
347
+ .chain((valueLists) => valueLists.chainMap((valueList) => Right(Resource.Values.fromArray({
348
+ focusResource: $parameters.resource,
349
+ propertyPath: BaseShaclCoreShapeStatic.$schema.properties.and.path,
350
+ values: valueList.toArray(),
351
+ })).chain((values) => values.chainMap((value) => value.toIdentifier()))))
352
+ .map((valueLists) => valueLists.map((valueList) => valueList.toArray()))
353
+ .map((values) => values.toArray())
354
+ .map((valuesArray) => Resource.Values.fromValue({
355
+ focusResource: $parameters.resource,
356
+ propertyPath: BaseShaclCoreShapeStatic.$schema.properties.and.path,
357
+ value: valuesArray,
358
+ })),
359
+ }).chain((and) => $shaclPropertyFromRdf({
360
+ graph: $parameters.graph,
361
+ resource: $parameters.resource,
362
+ propertySchema: BaseShaclCoreShapeStatic.$schema.properties.classes,
363
+ typeFromRdf: (resourceValues) => resourceValues
364
+ .chain((values) => values.chainMap((value) => value.toIri()))
365
+ .map((values) => values.toArray())
366
+ .map((valuesArray) => Resource.Values.fromValue({
367
+ focusResource: $parameters.resource,
368
+ propertyPath: BaseShaclCoreShapeStatic.$schema.properties.classes.path,
369
+ value: valuesArray,
370
+ })),
371
+ }).chain((classes) => $shaclPropertyFromRdf({
372
+ graph: $parameters.graph,
373
+ resource: $parameters.resource,
374
+ propertySchema: BaseShaclCoreShapeStatic.$schema.properties.comments,
375
+ typeFromRdf: (resourceValues) => resourceValues
376
+ .chain((values) => $fromRdfPreferredLanguages(values, $parameters.preferredLanguages))
377
+ .chain((values) => values.chainMap((value) => value.toString()))
378
+ .map((values) => values.toArray())
379
+ .map((valuesArray) => Resource.Values.fromValue({
380
+ focusResource: $parameters.resource,
381
+ propertyPath: BaseShaclCoreShapeStatic.$schema.properties.comments
382
+ .path,
383
+ value: valuesArray,
384
+ })),
385
+ }).chain((comments) => $shaclPropertyFromRdf({
386
+ graph: $parameters.graph,
387
+ resource: $parameters.resource,
388
+ propertySchema: BaseShaclCoreShapeStatic.$schema.properties.datatype,
389
+ typeFromRdf: (resourceValues) => resourceValues
390
+ .chain((values) => values.chainMap((value) => value.toIri()))
391
+ .map((values) => values.length > 0
392
+ ? values.map((value) => Maybe.of(value))
393
+ : Resource.Values.fromValue({
394
+ focusResource: $parameters.resource,
395
+ propertyPath: BaseShaclCoreShapeStatic.$schema.properties
396
+ .datatype.path,
397
+ value: Maybe.empty(),
398
+ })),
399
+ }).chain((datatype) => $shaclPropertyFromRdf({
400
+ graph: $parameters.graph,
401
+ resource: $parameters.resource,
402
+ propertySchema: BaseShaclCoreShapeStatic.$schema.properties.deactivated,
403
+ typeFromRdf: (resourceValues) => resourceValues
404
+ .chain((values) => values.chainMap((value) => value.toBoolean()))
405
+ .map((values) => values.length > 0
406
+ ? values.map((value) => Maybe.of(value))
407
+ : Resource.Values.fromValue({
408
+ focusResource: $parameters.resource,
409
+ propertyPath: BaseShaclCoreShapeStatic.$schema.properties
410
+ .deactivated.path,
411
+ value: Maybe.empty(),
412
+ })),
413
+ }).chain((deactivated) => $shaclPropertyFromRdf({
414
+ graph: $parameters.graph,
415
+ resource: $parameters.resource,
416
+ propertySchema: BaseShaclCoreShapeStatic.$schema.properties.flags,
417
+ typeFromRdf: (resourceValues) => resourceValues
418
+ .chain((values) => $fromRdfPreferredLanguages(values, $parameters.preferredLanguages))
419
+ .chain((values) => values.chainMap((value) => value.toString()))
420
+ .map((values) => values.toArray())
421
+ .map((valuesArray) => Resource.Values.fromValue({
422
+ focusResource: $parameters.resource,
423
+ propertyPath: BaseShaclCoreShapeStatic.$schema.properties.flags
424
+ .path,
425
+ value: valuesArray,
426
+ })),
427
+ }).chain((flags) => $shaclPropertyFromRdf({
428
+ graph: $parameters.graph,
429
+ resource: $parameters.resource,
430
+ propertySchema: BaseShaclCoreShapeStatic.$schema.properties.hasValues,
431
+ typeFromRdf: (resourceValues) => resourceValues
432
+ .chain((values) => values.chainMap((value) => value.toTerm().chain((term) => {
433
+ switch (term.termType) {
434
+ case "NamedNode":
435
+ case "Literal":
436
+ return Either.of(term);
437
+ default:
438
+ return Left(new Resource.MistypedTermValueError({
439
+ actualValue: term,
440
+ expectedValueType: "(NamedNode | Literal)",
441
+ focusResource: $parameters.resource,
442
+ propertyPath: BaseShaclCoreShapeStatic.$schema
443
+ .properties.hasValues.path,
444
+ }));
692
445
  }
693
- else {
694
- filteredLiteralValues = filteredLiteralValues.concat(...literalValues
695
- .filter((value) => value.language === preferredLanguage)
696
- .toArray());
446
+ })))
447
+ .map((values) => values.toArray())
448
+ .map((valuesArray) => Resource.Values.fromValue({
449
+ focusResource: $parameters.resource,
450
+ propertyPath: BaseShaclCoreShapeStatic.$schema.properties
451
+ .hasValues.path,
452
+ value: valuesArray,
453
+ })),
454
+ }).chain((hasValues) => $shaclPropertyFromRdf({
455
+ graph: $parameters.graph,
456
+ resource: $parameters.resource,
457
+ propertySchema: BaseShaclCoreShapeStatic.$schema.properties.in_,
458
+ typeFromRdf: (resourceValues) => resourceValues
459
+ .chain((values) => values.chainMap((value) => value.toList({ graph: $parameters.graph })))
460
+ .chain((valueLists) => valueLists.chainMap((valueList) => Right(Resource.Values.fromArray({
461
+ focusResource: $parameters.resource,
462
+ propertyPath: BaseShaclCoreShapeStatic.$schema
463
+ .properties.in_.path,
464
+ values: valueList.toArray(),
465
+ })).chain((values) => values.chainMap((value) => value.toTerm().chain((term) => {
466
+ switch (term.termType) {
467
+ case "NamedNode":
468
+ case "Literal":
469
+ return Either.of(term);
470
+ default:
471
+ return Left(new Resource.MistypedTermValueError({
472
+ actualValue: term,
473
+ expectedValueType: "(NamedNode | Literal)",
474
+ focusResource: $parameters.resource,
475
+ propertyPath: BaseShaclCoreShapeStatic
476
+ .$schema.properties.in_
477
+ .path,
478
+ }));
697
479
  }
698
- }
699
- return purify.Either.of(filteredLiteralValues.map((literalValue) => new rdfjsResource.Resource.Value({
700
- object: literalValue,
701
- predicate: BaseShaclCoreShapeStatic.$properties.patterns["identifier"],
702
- subject: $resource,
703
- })));
704
- })
705
- .chain((values) => values.chainMap((value) => value.toString()))
706
- .map((values) => values.toArray())
707
- .map((valuesArray) => rdfjsResource.Resource.Values.fromValue({
708
- object: valuesArray,
709
- predicate: BaseShaclCoreShapeStatic.$properties.patterns["identifier"],
710
- subject: $resource,
711
- }))
712
- .chain((values) => values.head());
713
- if (_patternsEither.isLeft()) {
714
- return _patternsEither;
715
- }
716
- const patterns = _patternsEither.unsafeCoerce();
717
- const _xoneEither = purify.Either.of($resource.values(BaseShaclCoreShapeStatic.$properties.xone["identifier"], { unique: true }))
718
- .chain((values) => values.chainMap((value) => value.toList()))
719
- .chain((valueLists) => valueLists.chainMap((valueList) => purify.Either.of(rdfjsResource.Resource.Values.fromArray({
720
- objects: valueList,
721
- predicate: BaseShaclCoreShapeStatic.$properties.xone["identifier"],
722
- subject: $resource,
723
- })).chain((values) => values.chainMap((value) => value.toIdentifier()))))
724
- .map((valueLists) => valueLists.map((valueList) => valueList.toArray()))
725
- .map((values) => values.toArray())
726
- .map((valuesArray) => rdfjsResource.Resource.Values.fromValue({
727
- object: valuesArray,
728
- predicate: BaseShaclCoreShapeStatic.$properties.xone["identifier"],
729
- subject: $resource,
730
- }))
731
- .chain((values) => values.head());
732
- if (_xoneEither.isLeft()) {
733
- return _xoneEither;
734
- }
735
- const xone = _xoneEither.unsafeCoerce();
736
- return purify.Either.of({
480
+ })))))
481
+ .map((valueLists) => valueLists.map((valueList) => valueList.toArray()))
482
+ .map((values) => values.length > 0
483
+ ? values.map((value) => Maybe.of(value))
484
+ : Resource.Values.fromValue({
485
+ focusResource: $parameters.resource,
486
+ propertyPath: BaseShaclCoreShapeStatic.$schema
487
+ .properties.in_.path,
488
+ value: Maybe.empty(),
489
+ })),
490
+ }).chain((in_) => $shaclPropertyFromRdf({
491
+ graph: $parameters.graph,
492
+ resource: $parameters.resource,
493
+ propertySchema: BaseShaclCoreShapeStatic.$schema.properties.isDefinedBy,
494
+ typeFromRdf: (resourceValues) => resourceValues
495
+ .chain((values) => values.chainMap((value) => value.toIdentifier()))
496
+ .map((values) => values.length > 0
497
+ ? values.map((value) => Maybe.of(value))
498
+ : Resource.Values.fromValue({
499
+ focusResource: $parameters.resource,
500
+ propertyPath: BaseShaclCoreShapeStatic.$schema
501
+ .properties.isDefinedBy.path,
502
+ value: Maybe.empty(),
503
+ })),
504
+ }).chain((isDefinedBy) => $shaclPropertyFromRdf({
505
+ graph: $parameters.graph,
506
+ resource: $parameters.resource,
507
+ propertySchema: BaseShaclCoreShapeStatic.$schema.properties.labels,
508
+ typeFromRdf: (resourceValues) => resourceValues
509
+ .chain((values) => $fromRdfPreferredLanguages(values, $parameters.preferredLanguages))
510
+ .chain((values) => values.chainMap((value) => value.toString()))
511
+ .map((values) => values.toArray())
512
+ .map((valuesArray) => Resource.Values.fromValue({
513
+ focusResource: $parameters.resource,
514
+ propertyPath: BaseShaclCoreShapeStatic.$schema
515
+ .properties.labels.path,
516
+ value: valuesArray,
517
+ })),
518
+ }).chain((labels) => $shaclPropertyFromRdf({
519
+ graph: $parameters.graph,
520
+ resource: $parameters.resource,
521
+ propertySchema: BaseShaclCoreShapeStatic.$schema.properties.languageIn,
522
+ typeFromRdf: (resourceValues) => resourceValues
523
+ .chain((values) => values.chainMap((value) => value.toList({
524
+ graph: $parameters.graph,
525
+ })))
526
+ .chain((valueLists) => valueLists.chainMap((valueList) => Right(Resource.Values.fromArray({
527
+ focusResource: $parameters.resource,
528
+ propertyPath: BaseShaclCoreShapeStatic.$schema
529
+ .properties.languageIn.path,
530
+ values: valueList.toArray(),
531
+ }))
532
+ .chain((values) => $fromRdfPreferredLanguages(values, $parameters.preferredLanguages))
533
+ .chain((values) => values.chainMap((value) => value.toString()))))
534
+ .map((valueLists) => valueLists.map((valueList) => valueList.toArray()))
535
+ .map((values) => values.length > 0
536
+ ? values.map((value) => Maybe.of(value))
537
+ : Resource.Values.fromValue({
538
+ focusResource: $parameters.resource,
539
+ propertyPath: BaseShaclCoreShapeStatic.$schema
540
+ .properties.languageIn.path,
541
+ value: Maybe.empty(),
542
+ })),
543
+ }).chain((languageIn) => $shaclPropertyFromRdf({
544
+ graph: $parameters.graph,
545
+ resource: $parameters.resource,
546
+ propertySchema: BaseShaclCoreShapeStatic.$schema.properties.maxCount,
547
+ typeFromRdf: (resourceValues) => resourceValues
548
+ .chain((values) => values.chainMap((value) => value.toInt()))
549
+ .map((values) => values.length > 0
550
+ ? values.map((value) => Maybe.of(value))
551
+ : Resource.Values.fromValue({
552
+ focusResource: $parameters.resource,
553
+ propertyPath: BaseShaclCoreShapeStatic.$schema
554
+ .properties.maxCount.path,
555
+ value: Maybe.empty(),
556
+ })),
557
+ }).chain((maxCount) => $shaclPropertyFromRdf({
558
+ graph: $parameters.graph,
559
+ resource: $parameters.resource,
560
+ propertySchema: BaseShaclCoreShapeStatic.$schema.properties.maxExclusive,
561
+ typeFromRdf: (resourceValues) => resourceValues
562
+ .chain((values) => $fromRdfPreferredLanguages(values, $parameters.preferredLanguages))
563
+ .chain((values) => values.chainMap((value) => value.toLiteral()))
564
+ .map((values) => values.length > 0
565
+ ? values.map((value) => Maybe.of(value))
566
+ : Resource.Values.fromValue({
567
+ focusResource: $parameters.resource,
568
+ propertyPath: BaseShaclCoreShapeStatic.$schema
569
+ .properties.maxExclusive.path,
570
+ value: Maybe.empty(),
571
+ })),
572
+ }).chain((maxExclusive) => $shaclPropertyFromRdf({
573
+ graph: $parameters.graph,
574
+ resource: $parameters.resource,
575
+ propertySchema: BaseShaclCoreShapeStatic.$schema.properties.maxInclusive,
576
+ typeFromRdf: (resourceValues) => resourceValues
577
+ .chain((values) => $fromRdfPreferredLanguages(values, $parameters.preferredLanguages))
578
+ .chain((values) => values.chainMap((value) => value.toLiteral()))
579
+ .map((values) => values.length > 0
580
+ ? values.map((value) => Maybe.of(value))
581
+ : Resource.Values.fromValue({
582
+ focusResource: $parameters.resource,
583
+ propertyPath: BaseShaclCoreShapeStatic
584
+ .$schema.properties
585
+ .maxInclusive.path,
586
+ value: Maybe.empty(),
587
+ })),
588
+ }).chain((maxInclusive) => $shaclPropertyFromRdf({
589
+ graph: $parameters.graph,
590
+ resource: $parameters.resource,
591
+ propertySchema: BaseShaclCoreShapeStatic.$schema.properties.maxLength,
592
+ typeFromRdf: (resourceValues) => resourceValues
593
+ .chain((values) => values.chainMap((value) => value.toInt()))
594
+ .map((values) => values.length > 0
595
+ ? values.map((value) => Maybe.of(value))
596
+ : Resource.Values.fromValue({
597
+ focusResource: $parameters.resource,
598
+ propertyPath: BaseShaclCoreShapeStatic
599
+ .$schema.properties
600
+ .maxLength.path,
601
+ value: Maybe.empty(),
602
+ })),
603
+ }).chain((maxLength) => $shaclPropertyFromRdf({
604
+ graph: $parameters.graph,
605
+ resource: $parameters.resource,
606
+ propertySchema: BaseShaclCoreShapeStatic.$schema.properties.minCount,
607
+ typeFromRdf: (resourceValues) => resourceValues
608
+ .chain((values) => values.chainMap((value) => value.toInt()))
609
+ .map((values) => values.length > 0
610
+ ? values.map((value) => Maybe.of(value))
611
+ : Resource.Values.fromValue({
612
+ focusResource: $parameters.resource,
613
+ propertyPath: BaseShaclCoreShapeStatic
614
+ .$schema.properties
615
+ .minCount.path,
616
+ value: Maybe.empty(),
617
+ })),
618
+ }).chain((minCount) => $shaclPropertyFromRdf({
619
+ graph: $parameters.graph,
620
+ resource: $parameters.resource,
621
+ propertySchema: BaseShaclCoreShapeStatic.$schema.properties.minExclusive,
622
+ typeFromRdf: (resourceValues) => resourceValues
623
+ .chain((values) => $fromRdfPreferredLanguages(values, $parameters.preferredLanguages))
624
+ .chain((values) => values.chainMap((value) => value.toLiteral()))
625
+ .map((values) => values.length > 0
626
+ ? values.map((value) => Maybe.of(value))
627
+ : Resource.Values.fromValue({
628
+ focusResource: $parameters.resource,
629
+ propertyPath: BaseShaclCoreShapeStatic
630
+ .$schema.properties
631
+ .minExclusive.path,
632
+ value: Maybe.empty(),
633
+ })),
634
+ }).chain((minExclusive) => $shaclPropertyFromRdf({
635
+ graph: $parameters.graph,
636
+ resource: $parameters.resource,
637
+ propertySchema: BaseShaclCoreShapeStatic.$schema.properties.minInclusive,
638
+ typeFromRdf: (resourceValues) => resourceValues
639
+ .chain((values) => $fromRdfPreferredLanguages(values, $parameters.preferredLanguages))
640
+ .chain((values) => values.chainMap((value) => value.toLiteral()))
641
+ .map((values) => values.length > 0
642
+ ? values.map((value) => Maybe.of(value))
643
+ : Resource.Values.fromValue({
644
+ focusResource: $parameters.resource,
645
+ propertyPath: BaseShaclCoreShapeStatic
646
+ .$schema.properties
647
+ .minInclusive.path,
648
+ value: Maybe.empty(),
649
+ })),
650
+ }).chain((minInclusive) => $shaclPropertyFromRdf({
651
+ graph: $parameters.graph,
652
+ resource: $parameters.resource,
653
+ propertySchema: BaseShaclCoreShapeStatic.$schema.properties.minLength,
654
+ typeFromRdf: (resourceValues) => resourceValues
655
+ .chain((values) => values.chainMap((value) => value.toInt()))
656
+ .map((values) => values.length > 0
657
+ ? values.map((value) => Maybe.of(value))
658
+ : Resource.Values.fromValue({
659
+ focusResource: $parameters.resource,
660
+ propertyPath: BaseShaclCoreShapeStatic
661
+ .$schema
662
+ .properties
663
+ .minLength.path,
664
+ value: Maybe.empty(),
665
+ })),
666
+ }).chain((minLength) => $shaclPropertyFromRdf({
667
+ graph: $parameters.graph,
668
+ resource: $parameters.resource,
669
+ propertySchema: BaseShaclCoreShapeStatic.$schema.properties.nodeKind,
670
+ typeFromRdf: (resourceValues) => resourceValues
671
+ .chain((values) => values.chainMap((value) => value.toIri([
672
+ dataFactory.namedNode("http://www.w3.org/ns/shacl#BlankNode"),
673
+ dataFactory.namedNode("http://www.w3.org/ns/shacl#BlankNodeOrIRI"),
674
+ dataFactory.namedNode("http://www.w3.org/ns/shacl#BlankNodeOrLiteral"),
675
+ dataFactory.namedNode("http://www.w3.org/ns/shacl#IRI"),
676
+ dataFactory.namedNode("http://www.w3.org/ns/shacl#IRIOrLiteral"),
677
+ dataFactory.namedNode("http://www.w3.org/ns/shacl#Literal"),
678
+ ])))
679
+ .map((values) => values.length > 0
680
+ ? values.map((value) => Maybe.of(value))
681
+ : Resource.Values.fromValue({
682
+ focusResource: $parameters.resource,
683
+ propertyPath: BaseShaclCoreShapeStatic
684
+ .$schema
685
+ .properties
686
+ .nodeKind.path,
687
+ value: Maybe.empty(),
688
+ })),
689
+ }).chain((nodeKind) => $shaclPropertyFromRdf({
690
+ graph: $parameters.graph,
691
+ resource: $parameters.resource,
692
+ propertySchema: BaseShaclCoreShapeStatic.$schema.properties.nodes,
693
+ typeFromRdf: (resourceValues) => resourceValues
694
+ .chain((values) => values.chainMap((value) => value.toIdentifier()))
695
+ .map((values) => values.toArray())
696
+ .map((valuesArray) => Resource.Values.fromValue({
697
+ focusResource: $parameters.resource,
698
+ propertyPath: BaseShaclCoreShapeStatic
699
+ .$schema
700
+ .properties
701
+ .nodes.path,
702
+ value: valuesArray,
703
+ })),
704
+ }).chain((nodes) => $shaclPropertyFromRdf({
705
+ graph: $parameters.graph,
706
+ resource: $parameters.resource,
707
+ propertySchema: BaseShaclCoreShapeStatic.$schema.properties.not,
708
+ typeFromRdf: (resourceValues) => resourceValues
709
+ .chain((values) => values.chainMap((value) => value.toIdentifier()))
710
+ .map((values) => values.toArray())
711
+ .map((valuesArray) => Resource.Values.fromValue({
712
+ focusResource: $parameters.resource,
713
+ propertyPath: BaseShaclCoreShapeStatic
714
+ .$schema
715
+ .properties
716
+ .not.path,
717
+ value: valuesArray,
718
+ })),
719
+ }).chain((not) => $shaclPropertyFromRdf({
720
+ graph: $parameters.graph,
721
+ resource: $parameters.resource,
722
+ propertySchema: BaseShaclCoreShapeStatic.$schema.properties.or,
723
+ typeFromRdf: (resourceValues) => resourceValues
724
+ .chain((values) => values.chainMap((value) => value.toList({
725
+ graph: $parameters.graph,
726
+ })))
727
+ .chain((valueLists) => valueLists.chainMap((valueList) => Right(Resource.Values.fromArray({
728
+ focusResource: $parameters.resource,
729
+ propertyPath: BaseShaclCoreShapeStatic
730
+ .$schema
731
+ .properties
732
+ .or
733
+ .path,
734
+ values: valueList.toArray(),
735
+ })).chain((values) => values.chainMap((value) => value.toIdentifier()))))
736
+ .map((valueLists) => valueLists.map((valueList) => valueList.toArray()))
737
+ .map((values) => values.toArray())
738
+ .map((valuesArray) => Resource.Values.fromValue({
739
+ focusResource: $parameters.resource,
740
+ propertyPath: BaseShaclCoreShapeStatic
741
+ .$schema
742
+ .properties
743
+ .or.path,
744
+ value: valuesArray,
745
+ })),
746
+ }).chain((or) => $shaclPropertyFromRdf({
747
+ graph: $parameters.graph,
748
+ resource: $parameters.resource,
749
+ propertySchema: BaseShaclCoreShapeStatic.$schema.properties
750
+ .patterns,
751
+ typeFromRdf: (resourceValues) => resourceValues
752
+ .chain((values) => $fromRdfPreferredLanguages(values, $parameters.preferredLanguages))
753
+ .chain((values) => values.chainMap((value) => value.toString()))
754
+ .map((values) => values.toArray())
755
+ .map((valuesArray) => Resource.Values.fromValue({
756
+ focusResource: $parameters.resource,
757
+ propertyPath: BaseShaclCoreShapeStatic
758
+ .$schema
759
+ .properties
760
+ .patterns
761
+ .path,
762
+ value: valuesArray,
763
+ })),
764
+ }).chain((patterns) => $shaclPropertyFromRdf({
765
+ graph: $parameters.graph,
766
+ resource: $parameters.resource,
767
+ propertySchema: BaseShaclCoreShapeStatic.$schema.properties
768
+ .xone,
769
+ typeFromRdf: (resourceValues) => resourceValues
770
+ .chain((values) => values.chainMap((value) => value.toList({
771
+ graph: $parameters.graph,
772
+ })))
773
+ .chain((valueLists) => valueLists.chainMap((valueList) => Right(Resource.Values.fromArray({
774
+ focusResource: $parameters.resource,
775
+ propertyPath: BaseShaclCoreShapeStatic
776
+ .$schema
777
+ .properties
778
+ .xone
779
+ .path,
780
+ values: valueList.toArray(),
781
+ })).chain((values) => values.chainMap((value) => value.toIdentifier()))))
782
+ .map((valueLists) => valueLists.map((valueList) => valueList.toArray()))
783
+ .map((values) => values.toArray())
784
+ .map((valuesArray) => Resource.Values.fromValue({
785
+ focusResource: $parameters.resource,
786
+ propertyPath: BaseShaclCoreShapeStatic
787
+ .$schema
788
+ .properties
789
+ .xone
790
+ .path,
791
+ value: valuesArray,
792
+ })),
793
+ }).map((xone) => ({
737
794
  $identifier,
738
795
  and,
739
796
  classes,
@@ -760,235 +817,474 @@ export var BaseShaclCoreShapeStatic;
760
817
  or,
761
818
  patterns,
762
819
  xone,
763
- });
820
+ })))))))))))))))))))))))))));
764
821
  }
765
822
  BaseShaclCoreShapeStatic.$propertiesFromRdf = $propertiesFromRdf;
766
823
  function $toRdf(_baseShaclCoreShape, options) {
767
- const mutateGraph = options?.mutateGraph;
768
824
  const resourceSet = options?.resourceSet ??
769
- new rdfjsResource.MutableResourceSet({
770
- dataFactory,
771
- dataset: datasetFactory.dataset(),
772
- });
773
- const resource = resourceSet.mutableResource(_baseShaclCoreShape.$identifier, { mutateGraph });
774
- resource.add(BaseShaclCoreShapeStatic.$properties.and["identifier"], ..._baseShaclCoreShape.and.flatMap((item) => [
825
+ new ResourceSet(datasetFactory.dataset(), { dataFactory: dataFactory });
826
+ const resource = resourceSet.resource(_baseShaclCoreShape.$identifier);
827
+ resource.add(dataFactory.namedNode("http://www.w3.org/ns/shacl#and"), _baseShaclCoreShape.and.flatMap((item) => [
775
828
  item.length > 0
776
829
  ? item.reduce(({ currentSubListResource, listResource }, item, itemIndex, list) => {
777
830
  if (itemIndex === 0) {
778
831
  currentSubListResource = listResource;
779
832
  }
780
833
  else {
781
- const newSubListResource = resourceSet.mutableResource(dataFactory.blankNode(), { mutateGraph });
782
- currentSubListResource.add($RdfVocabularies.rdf.rest, newSubListResource.identifier);
834
+ const newSubListResource = resourceSet.resource(dataFactory.blankNode());
835
+ currentSubListResource.add($RdfVocabularies.rdf.rest, newSubListResource.identifier, options?.graph);
783
836
  currentSubListResource = newSubListResource;
784
837
  }
785
- currentSubListResource.add($RdfVocabularies.rdf.first, ...[item]);
838
+ currentSubListResource.add($RdfVocabularies.rdf.first, [item], options?.graph);
786
839
  if (itemIndex + 1 === list.length) {
787
- currentSubListResource.add($RdfVocabularies.rdf.rest, $RdfVocabularies.rdf.nil);
840
+ currentSubListResource.add($RdfVocabularies.rdf.rest, $RdfVocabularies.rdf.nil, options?.graph);
788
841
  }
789
842
  return { currentSubListResource, listResource };
790
843
  }, {
791
844
  currentSubListResource: null,
792
- listResource: resourceSet.mutableResource(dataFactory.blankNode(), { mutateGraph }),
845
+ listResource: resourceSet.resource(dataFactory.blankNode()),
793
846
  }).listResource.identifier
794
847
  : $RdfVocabularies.rdf.nil,
795
- ]));
796
- resource.add(BaseShaclCoreShapeStatic.$properties.classes["identifier"], ..._baseShaclCoreShape.classes.flatMap((item) => [item]));
797
- resource.add(BaseShaclCoreShapeStatic.$properties.comments["identifier"], ..._baseShaclCoreShape.comments.flatMap((item) => [item]));
798
- resource.add(BaseShaclCoreShapeStatic.$properties.datatype["identifier"], ..._baseShaclCoreShape.datatype.toList());
799
- resource.add(BaseShaclCoreShapeStatic.$properties.deactivated["identifier"], ..._baseShaclCoreShape.deactivated.toList().flat());
800
- resource.add(BaseShaclCoreShapeStatic.$properties.flags["identifier"], ..._baseShaclCoreShape.flags.flatMap((item) => [item]));
801
- resource.add(BaseShaclCoreShapeStatic.$properties.hasValues["identifier"], ..._baseShaclCoreShape.hasValues.flatMap((item) => [item]));
802
- resource.add(BaseShaclCoreShapeStatic.$properties.in_["identifier"], ..._baseShaclCoreShape.in_.toList().flatMap((value) => [
848
+ ]), options?.graph);
849
+ resource.add(dataFactory.namedNode("http://www.w3.org/ns/shacl#class"), _baseShaclCoreShape.classes.flatMap((item) => [item]), options?.graph);
850
+ resource.add(dataFactory.namedNode("http://www.w3.org/2000/01/rdf-schema#comment"), _baseShaclCoreShape.comments.flatMap((item) => [
851
+ $literalFactory.string(item),
852
+ ]), options?.graph);
853
+ resource.add(dataFactory.namedNode("http://www.w3.org/ns/shacl#datatype"), _baseShaclCoreShape.datatype.toList(), options?.graph);
854
+ resource.add(dataFactory.namedNode("http://www.w3.org/ns/shacl#deactivated"), _baseShaclCoreShape.deactivated
855
+ .toList()
856
+ .flatMap((value) => [
857
+ $literalFactory.boolean(value, $RdfVocabularies.xsd.boolean),
858
+ ]), options?.graph);
859
+ resource.add(dataFactory.namedNode("http://www.w3.org/ns/shacl#flags"), _baseShaclCoreShape.flags.flatMap((item) => [
860
+ $literalFactory.string(item),
861
+ ]), options?.graph);
862
+ resource.add(dataFactory.namedNode("http://www.w3.org/ns/shacl#hasValue"), _baseShaclCoreShape.hasValues.flatMap((item) => [item]), options?.graph);
863
+ resource.add(dataFactory.namedNode("http://www.w3.org/ns/shacl#in"), _baseShaclCoreShape.in_.toList().flatMap((value) => [
803
864
  value.length > 0
804
865
  ? value.reduce(({ currentSubListResource, listResource }, item, itemIndex, list) => {
805
866
  if (itemIndex === 0) {
806
867
  currentSubListResource = listResource;
807
868
  }
808
869
  else {
809
- const newSubListResource = resourceSet.mutableResource(dataFactory.blankNode(), { mutateGraph });
810
- currentSubListResource.add($RdfVocabularies.rdf.rest, newSubListResource.identifier);
870
+ const newSubListResource = resourceSet.resource(dataFactory.blankNode());
871
+ currentSubListResource.add($RdfVocabularies.rdf.rest, newSubListResource.identifier, options?.graph);
811
872
  currentSubListResource = newSubListResource;
812
873
  }
813
- currentSubListResource.add($RdfVocabularies.rdf.first, ...[item]);
874
+ currentSubListResource.add($RdfVocabularies.rdf.first, [item], options?.graph);
814
875
  if (itemIndex + 1 === list.length) {
815
- currentSubListResource.add($RdfVocabularies.rdf.rest, $RdfVocabularies.rdf.nil);
876
+ currentSubListResource.add($RdfVocabularies.rdf.rest, $RdfVocabularies.rdf.nil, options?.graph);
816
877
  }
817
878
  return { currentSubListResource, listResource };
818
879
  }, {
819
880
  currentSubListResource: null,
820
- listResource: resourceSet.mutableResource(dataFactory.blankNode(), { mutateGraph }),
881
+ listResource: resourceSet.resource(dataFactory.blankNode()),
821
882
  }).listResource.identifier
822
883
  : $RdfVocabularies.rdf.nil,
823
- ]));
824
- resource.add(BaseShaclCoreShapeStatic.$properties.isDefinedBy["identifier"], ..._baseShaclCoreShape.isDefinedBy.toList());
825
- resource.add(BaseShaclCoreShapeStatic.$properties.labels["identifier"], ..._baseShaclCoreShape.labels.flatMap((item) => [item]));
826
- resource.add(BaseShaclCoreShapeStatic.$properties.languageIn["identifier"], ..._baseShaclCoreShape.languageIn.toList().flatMap((value) => [
884
+ ]), options?.graph);
885
+ resource.add(dataFactory.namedNode("http://www.w3.org/2000/01/rdf-schema#isDefinedBy"), _baseShaclCoreShape.isDefinedBy.toList(), options?.graph);
886
+ resource.add(dataFactory.namedNode("http://www.w3.org/2000/01/rdf-schema#label"), _baseShaclCoreShape.labels.flatMap((item) => [
887
+ $literalFactory.string(item),
888
+ ]), options?.graph);
889
+ resource.add(dataFactory.namedNode("http://www.w3.org/ns/shacl#languageIn"), _baseShaclCoreShape.languageIn.toList().flatMap((value) => [
827
890
  value.length > 0
828
891
  ? value.reduce(({ currentSubListResource, listResource }, item, itemIndex, list) => {
829
892
  if (itemIndex === 0) {
830
893
  currentSubListResource = listResource;
831
894
  }
832
895
  else {
833
- const newSubListResource = resourceSet.mutableResource(dataFactory.blankNode(), { mutateGraph });
834
- currentSubListResource.add($RdfVocabularies.rdf.rest, newSubListResource.identifier);
896
+ const newSubListResource = resourceSet.resource(dataFactory.blankNode());
897
+ currentSubListResource.add($RdfVocabularies.rdf.rest, newSubListResource.identifier, options?.graph);
835
898
  currentSubListResource = newSubListResource;
836
899
  }
837
- currentSubListResource.add($RdfVocabularies.rdf.first, ...[item]);
900
+ currentSubListResource.add($RdfVocabularies.rdf.first, [$literalFactory.string(item)], options?.graph);
838
901
  if (itemIndex + 1 === list.length) {
839
- currentSubListResource.add($RdfVocabularies.rdf.rest, $RdfVocabularies.rdf.nil);
902
+ currentSubListResource.add($RdfVocabularies.rdf.rest, $RdfVocabularies.rdf.nil, options?.graph);
840
903
  }
841
904
  return { currentSubListResource, listResource };
842
905
  }, {
843
906
  currentSubListResource: null,
844
- listResource: resourceSet.mutableResource(dataFactory.blankNode(), { mutateGraph }),
907
+ listResource: resourceSet.resource(dataFactory.blankNode()),
845
908
  }).listResource.identifier
846
909
  : $RdfVocabularies.rdf.nil,
847
- ]));
848
- resource.add(BaseShaclCoreShapeStatic.$properties.maxCount["identifier"], ..._baseShaclCoreShape.maxCount.toList());
849
- resource.add(BaseShaclCoreShapeStatic.$properties.maxExclusive["identifier"], ..._baseShaclCoreShape.maxExclusive.toList());
850
- resource.add(BaseShaclCoreShapeStatic.$properties.maxInclusive["identifier"], ..._baseShaclCoreShape.maxInclusive.toList());
851
- resource.add(BaseShaclCoreShapeStatic.$properties.maxLength["identifier"], ..._baseShaclCoreShape.maxLength.toList());
852
- resource.add(BaseShaclCoreShapeStatic.$properties.minCount["identifier"], ..._baseShaclCoreShape.minCount.toList());
853
- resource.add(BaseShaclCoreShapeStatic.$properties.minExclusive["identifier"], ..._baseShaclCoreShape.minExclusive.toList());
854
- resource.add(BaseShaclCoreShapeStatic.$properties.minInclusive["identifier"], ..._baseShaclCoreShape.minInclusive.toList());
855
- resource.add(BaseShaclCoreShapeStatic.$properties.minLength["identifier"], ..._baseShaclCoreShape.minLength.toList());
856
- resource.add(BaseShaclCoreShapeStatic.$properties.nodeKind["identifier"], ..._baseShaclCoreShape.nodeKind.toList());
857
- resource.add(BaseShaclCoreShapeStatic.$properties.nodes["identifier"], ..._baseShaclCoreShape.nodes.flatMap((item) => [item]));
858
- resource.add(BaseShaclCoreShapeStatic.$properties.not["identifier"], ..._baseShaclCoreShape.not.flatMap((item) => [item]));
859
- resource.add(BaseShaclCoreShapeStatic.$properties.or["identifier"], ..._baseShaclCoreShape.or.flatMap((item) => [
910
+ ]), options?.graph);
911
+ resource.add(dataFactory.namedNode("http://www.w3.org/ns/shacl#maxCount"), _baseShaclCoreShape.maxCount
912
+ .toList()
913
+ .flatMap((value) => [
914
+ $literalFactory.number(value, $RdfVocabularies.xsd.unsignedInt),
915
+ ]), options?.graph);
916
+ resource.add(dataFactory.namedNode("http://www.w3.org/ns/shacl#maxExclusive"), _baseShaclCoreShape.maxExclusive.toList(), options?.graph);
917
+ resource.add(dataFactory.namedNode("http://www.w3.org/ns/shacl#maxInclusive"), _baseShaclCoreShape.maxInclusive.toList(), options?.graph);
918
+ resource.add(dataFactory.namedNode("http://www.w3.org/ns/shacl#maxLength"), _baseShaclCoreShape.maxLength
919
+ .toList()
920
+ .flatMap((value) => [
921
+ $literalFactory.number(value, $RdfVocabularies.xsd.unsignedInt),
922
+ ]), options?.graph);
923
+ resource.add(dataFactory.namedNode("http://www.w3.org/ns/shacl#minCount"), _baseShaclCoreShape.minCount
924
+ .toList()
925
+ .flatMap((value) => [
926
+ $literalFactory.number(value, $RdfVocabularies.xsd.unsignedInt),
927
+ ]), options?.graph);
928
+ resource.add(dataFactory.namedNode("http://www.w3.org/ns/shacl#minExclusive"), _baseShaclCoreShape.minExclusive.toList(), options?.graph);
929
+ resource.add(dataFactory.namedNode("http://www.w3.org/ns/shacl#minInclusive"), _baseShaclCoreShape.minInclusive.toList(), options?.graph);
930
+ resource.add(dataFactory.namedNode("http://www.w3.org/ns/shacl#minLength"), _baseShaclCoreShape.minLength
931
+ .toList()
932
+ .flatMap((value) => [
933
+ $literalFactory.number(value, $RdfVocabularies.xsd.unsignedInt),
934
+ ]), options?.graph);
935
+ resource.add(dataFactory.namedNode("http://www.w3.org/ns/shacl#nodeKind"), _baseShaclCoreShape.nodeKind.toList(), options?.graph);
936
+ resource.add(dataFactory.namedNode("http://www.w3.org/ns/shacl#node"), _baseShaclCoreShape.nodes.flatMap((item) => [item]), options?.graph);
937
+ resource.add(dataFactory.namedNode("http://www.w3.org/ns/shacl#not"), _baseShaclCoreShape.not.flatMap((item) => [item]), options?.graph);
938
+ resource.add(dataFactory.namedNode("http://www.w3.org/ns/shacl#or"), _baseShaclCoreShape.or.flatMap((item) => [
860
939
  item.length > 0
861
940
  ? item.reduce(({ currentSubListResource, listResource }, item, itemIndex, list) => {
862
941
  if (itemIndex === 0) {
863
942
  currentSubListResource = listResource;
864
943
  }
865
944
  else {
866
- const newSubListResource = resourceSet.mutableResource(dataFactory.blankNode(), { mutateGraph });
867
- currentSubListResource.add($RdfVocabularies.rdf.rest, newSubListResource.identifier);
945
+ const newSubListResource = resourceSet.resource(dataFactory.blankNode());
946
+ currentSubListResource.add($RdfVocabularies.rdf.rest, newSubListResource.identifier, options?.graph);
868
947
  currentSubListResource = newSubListResource;
869
948
  }
870
- currentSubListResource.add($RdfVocabularies.rdf.first, ...[item]);
949
+ currentSubListResource.add($RdfVocabularies.rdf.first, [item], options?.graph);
871
950
  if (itemIndex + 1 === list.length) {
872
- currentSubListResource.add($RdfVocabularies.rdf.rest, $RdfVocabularies.rdf.nil);
951
+ currentSubListResource.add($RdfVocabularies.rdf.rest, $RdfVocabularies.rdf.nil, options?.graph);
873
952
  }
874
953
  return { currentSubListResource, listResource };
875
954
  }, {
876
955
  currentSubListResource: null,
877
- listResource: resourceSet.mutableResource(dataFactory.blankNode(), { mutateGraph }),
956
+ listResource: resourceSet.resource(dataFactory.blankNode()),
878
957
  }).listResource.identifier
879
958
  : $RdfVocabularies.rdf.nil,
880
- ]));
881
- resource.add(BaseShaclCoreShapeStatic.$properties.patterns["identifier"], ..._baseShaclCoreShape.patterns.flatMap((item) => [item]));
882
- resource.add(BaseShaclCoreShapeStatic.$properties.xone["identifier"], ..._baseShaclCoreShape.xone.flatMap((item) => [
959
+ ]), options?.graph);
960
+ resource.add(dataFactory.namedNode("http://www.w3.org/ns/shacl#pattern"), _baseShaclCoreShape.patterns.flatMap((item) => [
961
+ $literalFactory.string(item),
962
+ ]), options?.graph);
963
+ resource.add(dataFactory.namedNode("http://www.w3.org/ns/shacl#xone"), _baseShaclCoreShape.xone.flatMap((item) => [
883
964
  item.length > 0
884
965
  ? item.reduce(({ currentSubListResource, listResource }, item, itemIndex, list) => {
885
966
  if (itemIndex === 0) {
886
967
  currentSubListResource = listResource;
887
968
  }
888
969
  else {
889
- const newSubListResource = resourceSet.mutableResource(dataFactory.blankNode(), { mutateGraph });
890
- currentSubListResource.add($RdfVocabularies.rdf.rest, newSubListResource.identifier);
970
+ const newSubListResource = resourceSet.resource(dataFactory.blankNode());
971
+ currentSubListResource.add($RdfVocabularies.rdf.rest, newSubListResource.identifier, options?.graph);
891
972
  currentSubListResource = newSubListResource;
892
973
  }
893
- currentSubListResource.add($RdfVocabularies.rdf.first, ...[item]);
974
+ currentSubListResource.add($RdfVocabularies.rdf.first, [item], options?.graph);
894
975
  if (itemIndex + 1 === list.length) {
895
- currentSubListResource.add($RdfVocabularies.rdf.rest, $RdfVocabularies.rdf.nil);
976
+ currentSubListResource.add($RdfVocabularies.rdf.rest, $RdfVocabularies.rdf.nil, options?.graph);
896
977
  }
897
978
  return { currentSubListResource, listResource };
898
979
  }, {
899
980
  currentSubListResource: null,
900
- listResource: resourceSet.mutableResource(dataFactory.blankNode(), { mutateGraph }),
981
+ listResource: resourceSet.resource(dataFactory.blankNode()),
901
982
  }).listResource.identifier
902
983
  : $RdfVocabularies.rdf.nil,
903
- ]));
984
+ ]), options?.graph);
904
985
  return resource;
905
986
  }
906
987
  BaseShaclCoreShapeStatic.$toRdf = $toRdf;
907
- BaseShaclCoreShapeStatic.$properties = {
908
- and: {
909
- identifier: dataFactory.namedNode("http://www.w3.org/ns/shacl#and"),
910
- },
911
- classes: {
912
- identifier: dataFactory.namedNode("http://www.w3.org/ns/shacl#class"),
913
- },
914
- comments: {
915
- identifier: dataFactory.namedNode("http://www.w3.org/2000/01/rdf-schema#comment"),
916
- },
917
- datatype: {
918
- identifier: dataFactory.namedNode("http://www.w3.org/ns/shacl#datatype"),
919
- },
920
- deactivated: {
921
- identifier: dataFactory.namedNode("http://www.w3.org/ns/shacl#deactivated"),
922
- },
923
- flags: {
924
- identifier: dataFactory.namedNode("http://www.w3.org/ns/shacl#flags"),
925
- },
926
- hasValues: {
927
- identifier: dataFactory.namedNode("http://www.w3.org/ns/shacl#hasValue"),
928
- },
929
- in_: { identifier: dataFactory.namedNode("http://www.w3.org/ns/shacl#in") },
930
- isDefinedBy: {
931
- identifier: dataFactory.namedNode("http://www.w3.org/2000/01/rdf-schema#isDefinedBy"),
932
- },
933
- labels: {
934
- identifier: dataFactory.namedNode("http://www.w3.org/2000/01/rdf-schema#label"),
935
- },
936
- languageIn: {
937
- identifier: dataFactory.namedNode("http://www.w3.org/ns/shacl#languageIn"),
938
- },
939
- maxCount: {
940
- identifier: dataFactory.namedNode("http://www.w3.org/ns/shacl#maxCount"),
941
- },
942
- maxExclusive: {
943
- identifier: dataFactory.namedNode("http://www.w3.org/ns/shacl#maxExclusive"),
944
- },
945
- maxInclusive: {
946
- identifier: dataFactory.namedNode("http://www.w3.org/ns/shacl#maxInclusive"),
947
- },
948
- maxLength: {
949
- identifier: dataFactory.namedNode("http://www.w3.org/ns/shacl#maxLength"),
950
- },
951
- minCount: {
952
- identifier: dataFactory.namedNode("http://www.w3.org/ns/shacl#minCount"),
953
- },
954
- minExclusive: {
955
- identifier: dataFactory.namedNode("http://www.w3.org/ns/shacl#minExclusive"),
956
- },
957
- minInclusive: {
958
- identifier: dataFactory.namedNode("http://www.w3.org/ns/shacl#minInclusive"),
959
- },
960
- minLength: {
961
- identifier: dataFactory.namedNode("http://www.w3.org/ns/shacl#minLength"),
962
- },
963
- nodeKind: {
964
- identifier: dataFactory.namedNode("http://www.w3.org/ns/shacl#nodeKind"),
965
- },
966
- nodes: {
967
- identifier: dataFactory.namedNode("http://www.w3.org/ns/shacl#node"),
968
- },
969
- not: {
970
- identifier: dataFactory.namedNode("http://www.w3.org/ns/shacl#not"),
971
- },
972
- or: { identifier: dataFactory.namedNode("http://www.w3.org/ns/shacl#or") },
973
- patterns: {
974
- identifier: dataFactory.namedNode("http://www.w3.org/ns/shacl#pattern"),
975
- },
976
- xone: {
977
- identifier: dataFactory.namedNode("http://www.w3.org/ns/shacl#xone"),
988
+ BaseShaclCoreShapeStatic.$schema = {
989
+ properties: {
990
+ $identifier: {
991
+ kind: "Identifier",
992
+ type: () => ({ kind: "Identifier" }),
993
+ },
994
+ $type: {
995
+ kind: "TypeDiscriminant",
996
+ type: () => ({
997
+ descendantValues: ["ShaclCoreNodeShape", "ShaclCorePropertyShape"],
998
+ kind: "TypeDiscriminant",
999
+ }),
1000
+ },
1001
+ and: {
1002
+ kind: "Shacl",
1003
+ type: () => ({
1004
+ kind: "Set",
1005
+ item: () => ({
1006
+ kind: "List",
1007
+ item: () => ({ kind: "Identifier" }),
1008
+ }),
1009
+ }),
1010
+ path: dataFactory.namedNode("http://www.w3.org/ns/shacl#and"),
1011
+ },
1012
+ classes: {
1013
+ kind: "Shacl",
1014
+ type: () => ({
1015
+ kind: "Set",
1016
+ item: () => ({ kind: "Iri" }),
1017
+ }),
1018
+ path: dataFactory.namedNode("http://www.w3.org/ns/shacl#class"),
1019
+ },
1020
+ comments: {
1021
+ kind: "Shacl",
1022
+ type: () => ({
1023
+ kind: "Set",
1024
+ item: () => ({ kind: "String" }),
1025
+ }),
1026
+ path: dataFactory.namedNode("http://www.w3.org/2000/01/rdf-schema#comment"),
1027
+ },
1028
+ datatype: {
1029
+ kind: "Shacl",
1030
+ type: () => ({
1031
+ kind: "Maybe",
1032
+ item: () => ({ kind: "Iri" }),
1033
+ }),
1034
+ path: dataFactory.namedNode("http://www.w3.org/ns/shacl#datatype"),
1035
+ },
1036
+ deactivated: {
1037
+ kind: "Shacl",
1038
+ type: () => ({
1039
+ kind: "Maybe",
1040
+ item: () => ({ kind: "Boolean" }),
1041
+ }),
1042
+ path: dataFactory.namedNode("http://www.w3.org/ns/shacl#deactivated"),
1043
+ },
1044
+ flags: {
1045
+ kind: "Shacl",
1046
+ type: () => ({
1047
+ kind: "Set",
1048
+ item: () => ({ kind: "String" }),
1049
+ }),
1050
+ path: dataFactory.namedNode("http://www.w3.org/ns/shacl#flags"),
1051
+ },
1052
+ hasValues: {
1053
+ kind: "Shacl",
1054
+ type: () => ({
1055
+ kind: "Set",
1056
+ item: () => ({ kind: "Term" }),
1057
+ }),
1058
+ path: dataFactory.namedNode("http://www.w3.org/ns/shacl#hasValue"),
1059
+ },
1060
+ in_: {
1061
+ kind: "Shacl",
1062
+ type: () => ({
1063
+ kind: "Maybe",
1064
+ item: () => ({
1065
+ kind: "List",
1066
+ item: () => ({ kind: "Term" }),
1067
+ }),
1068
+ }),
1069
+ path: dataFactory.namedNode("http://www.w3.org/ns/shacl#in"),
1070
+ },
1071
+ isDefinedBy: {
1072
+ kind: "Shacl",
1073
+ type: () => ({
1074
+ kind: "Maybe",
1075
+ item: () => ({ kind: "Identifier" }),
1076
+ }),
1077
+ path: dataFactory.namedNode("http://www.w3.org/2000/01/rdf-schema#isDefinedBy"),
1078
+ },
1079
+ labels: {
1080
+ kind: "Shacl",
1081
+ type: () => ({
1082
+ kind: "Set",
1083
+ item: () => ({ kind: "String" }),
1084
+ }),
1085
+ path: dataFactory.namedNode("http://www.w3.org/2000/01/rdf-schema#label"),
1086
+ },
1087
+ languageIn: {
1088
+ kind: "Shacl",
1089
+ type: () => ({
1090
+ kind: "Maybe",
1091
+ item: () => ({
1092
+ kind: "List",
1093
+ item: () => ({ kind: "String" }),
1094
+ }),
1095
+ }),
1096
+ path: dataFactory.namedNode("http://www.w3.org/ns/shacl#languageIn"),
1097
+ },
1098
+ maxCount: {
1099
+ kind: "Shacl",
1100
+ type: () => ({
1101
+ kind: "Maybe",
1102
+ item: () => ({ kind: "Int" }),
1103
+ }),
1104
+ path: dataFactory.namedNode("http://www.w3.org/ns/shacl#maxCount"),
1105
+ },
1106
+ maxExclusive: {
1107
+ kind: "Shacl",
1108
+ type: () => ({
1109
+ kind: "Maybe",
1110
+ item: () => ({ kind: "Literal" }),
1111
+ }),
1112
+ path: dataFactory.namedNode("http://www.w3.org/ns/shacl#maxExclusive"),
1113
+ },
1114
+ maxInclusive: {
1115
+ kind: "Shacl",
1116
+ type: () => ({
1117
+ kind: "Maybe",
1118
+ item: () => ({ kind: "Literal" }),
1119
+ }),
1120
+ path: dataFactory.namedNode("http://www.w3.org/ns/shacl#maxInclusive"),
1121
+ },
1122
+ maxLength: {
1123
+ kind: "Shacl",
1124
+ type: () => ({
1125
+ kind: "Maybe",
1126
+ item: () => ({ kind: "Int" }),
1127
+ }),
1128
+ path: dataFactory.namedNode("http://www.w3.org/ns/shacl#maxLength"),
1129
+ },
1130
+ minCount: {
1131
+ kind: "Shacl",
1132
+ type: () => ({
1133
+ kind: "Maybe",
1134
+ item: () => ({ kind: "Int" }),
1135
+ }),
1136
+ path: dataFactory.namedNode("http://www.w3.org/ns/shacl#minCount"),
1137
+ },
1138
+ minExclusive: {
1139
+ kind: "Shacl",
1140
+ type: () => ({
1141
+ kind: "Maybe",
1142
+ item: () => ({ kind: "Literal" }),
1143
+ }),
1144
+ path: dataFactory.namedNode("http://www.w3.org/ns/shacl#minExclusive"),
1145
+ },
1146
+ minInclusive: {
1147
+ kind: "Shacl",
1148
+ type: () => ({
1149
+ kind: "Maybe",
1150
+ item: () => ({ kind: "Literal" }),
1151
+ }),
1152
+ path: dataFactory.namedNode("http://www.w3.org/ns/shacl#minInclusive"),
1153
+ },
1154
+ minLength: {
1155
+ kind: "Shacl",
1156
+ type: () => ({
1157
+ kind: "Maybe",
1158
+ item: () => ({ kind: "Int" }),
1159
+ }),
1160
+ path: dataFactory.namedNode("http://www.w3.org/ns/shacl#minLength"),
1161
+ },
1162
+ nodeKind: {
1163
+ kind: "Shacl",
1164
+ type: () => ({
1165
+ kind: "Maybe",
1166
+ item: () => ({
1167
+ kind: "Iri",
1168
+ in: [
1169
+ dataFactory.namedNode("http://www.w3.org/ns/shacl#BlankNode"),
1170
+ dataFactory.namedNode("http://www.w3.org/ns/shacl#BlankNodeOrIRI"),
1171
+ dataFactory.namedNode("http://www.w3.org/ns/shacl#BlankNodeOrLiteral"),
1172
+ dataFactory.namedNode("http://www.w3.org/ns/shacl#IRI"),
1173
+ dataFactory.namedNode("http://www.w3.org/ns/shacl#IRIOrLiteral"),
1174
+ dataFactory.namedNode("http://www.w3.org/ns/shacl#Literal"),
1175
+ ],
1176
+ }),
1177
+ }),
1178
+ path: dataFactory.namedNode("http://www.w3.org/ns/shacl#nodeKind"),
1179
+ },
1180
+ nodes: {
1181
+ kind: "Shacl",
1182
+ type: () => ({
1183
+ kind: "Set",
1184
+ item: () => ({ kind: "Identifier" }),
1185
+ }),
1186
+ path: dataFactory.namedNode("http://www.w3.org/ns/shacl#node"),
1187
+ },
1188
+ not: {
1189
+ kind: "Shacl",
1190
+ type: () => ({
1191
+ kind: "Set",
1192
+ item: () => ({ kind: "Identifier" }),
1193
+ }),
1194
+ path: dataFactory.namedNode("http://www.w3.org/ns/shacl#not"),
1195
+ },
1196
+ or: {
1197
+ kind: "Shacl",
1198
+ type: () => ({
1199
+ kind: "Set",
1200
+ item: () => ({
1201
+ kind: "List",
1202
+ item: () => ({ kind: "Identifier" }),
1203
+ }),
1204
+ }),
1205
+ path: dataFactory.namedNode("http://www.w3.org/ns/shacl#or"),
1206
+ },
1207
+ patterns: {
1208
+ kind: "Shacl",
1209
+ type: () => ({
1210
+ kind: "Set",
1211
+ item: () => ({ kind: "String" }),
1212
+ }),
1213
+ path: dataFactory.namedNode("http://www.w3.org/ns/shacl#pattern"),
1214
+ },
1215
+ xone: {
1216
+ kind: "Shacl",
1217
+ type: () => ({
1218
+ kind: "Set",
1219
+ item: () => ({
1220
+ kind: "List",
1221
+ item: () => ({ kind: "Identifier" }),
1222
+ }),
1223
+ }),
1224
+ path: dataFactory.namedNode("http://www.w3.org/ns/shacl#xone"),
1225
+ },
978
1226
  },
979
1227
  };
980
1228
  })(BaseShaclCoreShapeStatic || (BaseShaclCoreShapeStatic = {}));
981
1229
  export var ShaclCorePropertyShape;
982
1230
  (function (ShaclCorePropertyShape) {
1231
+ function $filter(filter, value) {
1232
+ if (!BaseShaclCoreShapeStatic.$filter(filter, value)) {
1233
+ return false;
1234
+ }
1235
+ if (filter.defaultValue !== undefined &&
1236
+ !$filterMaybe($filterTerm)(filter.defaultValue, value.defaultValue)) {
1237
+ return false;
1238
+ }
1239
+ if (filter.descriptions !== undefined &&
1240
+ !$filterArray($filterString)(filter.descriptions, value.descriptions)) {
1241
+ return false;
1242
+ }
1243
+ if (filter.groups !== undefined &&
1244
+ !$filterArray($filterIdentifier)(filter.groups, value.groups)) {
1245
+ return false;
1246
+ }
1247
+ if (filter.names !== undefined &&
1248
+ !$filterArray($filterString)(filter.names, value.names)) {
1249
+ return false;
1250
+ }
1251
+ if (filter.order !== undefined &&
1252
+ !$filterMaybe(($filterNumeric))(filter.order, value.order)) {
1253
+ return false;
1254
+ }
1255
+ if (filter.path !== undefined &&
1256
+ !PropertyPath.$filter(filter.path, value.path)) {
1257
+ return false;
1258
+ }
1259
+ if (filter.uniqueLang !== undefined &&
1260
+ !$filterMaybe($filterBoolean)(filter.uniqueLang, value.uniqueLang)) {
1261
+ return false;
1262
+ }
1263
+ return true;
1264
+ }
1265
+ ShaclCorePropertyShape.$filter = $filter;
983
1266
  ShaclCorePropertyShape.$fromRdfType = dataFactory.namedNode("http://www.w3.org/ns/shacl#PropertyShape");
984
- ShaclCorePropertyShape.$Identifier = BaseShaclCoreShapeStatic.$Identifier;
1267
+ let $Identifier;
1268
+ (function ($Identifier) {
1269
+ $Identifier.fromString = $identifierFromString; // biome-ignore lint/suspicious/noShadowRestrictedNames: allow toString
1270
+ $Identifier.toString = Resource.Identifier.toString;
1271
+ })($Identifier = ShaclCorePropertyShape.$Identifier || (ShaclCorePropertyShape.$Identifier = {}));
1272
+ function isShaclCorePropertyShape(object) {
1273
+ switch (object.$type) {
1274
+ case "ShaclCorePropertyShape":
1275
+ return true;
1276
+ default:
1277
+ return false;
1278
+ }
1279
+ }
1280
+ ShaclCorePropertyShape.isShaclCorePropertyShape = isShaclCorePropertyShape;
985
1281
  function $fromRdf(resource, options) {
986
- let { ignoreRdfType = false, objectSet, preferredLanguages, ...context } = options ?? {};
1282
+ let { context, ignoreRdfType = false, objectSet, preferredLanguages, } = options ?? {};
987
1283
  if (!objectSet) {
988
- objectSet = new $RdfjsDatasetObjectSet({ dataset: resource.dataset });
1284
+ objectSet = new $RdfjsDatasetObjectSet(resource.dataset);
989
1285
  }
990
1286
  return ShaclCorePropertyShape.$propertiesFromRdf({
991
- ...context,
1287
+ context,
992
1288
  ignoreRdfType,
993
1289
  objectSet,
994
1290
  preferredLanguages,
@@ -996,209 +1292,142 @@ export var ShaclCorePropertyShape;
996
1292
  });
997
1293
  }
998
1294
  ShaclCorePropertyShape.$fromRdf = $fromRdf;
999
- function $propertiesFromRdf({ ignoreRdfType: $ignoreRdfType, objectSet: $objectSet, preferredLanguages: $preferredLanguages, resource: $resource,
1000
- // @ts-ignore
1001
- ...$context }) {
1002
- const $super0Either = BaseShaclCoreShapeStatic.$propertiesFromRdf({
1003
- ...$context,
1295
+ function $propertiesFromRdf($parameters) {
1296
+ return BaseShaclCoreShapeStatic.$propertiesFromRdf({
1297
+ ...$parameters,
1004
1298
  ignoreRdfType: true,
1005
- objectSet: $objectSet,
1006
- preferredLanguages: $preferredLanguages,
1007
- resource: $resource,
1008
- });
1009
- if ($super0Either.isLeft()) {
1010
- return $super0Either;
1011
- }
1012
- const $super0 = $super0Either.unsafeCoerce();
1013
- if (!$ignoreRdfType) {
1014
- const $rdfTypeCheck = $resource
1015
- .value($RdfVocabularies.rdf.type)
1299
+ }).chain(($super0) => (!$parameters.ignoreRdfType
1300
+ ? $parameters.resource
1301
+ .value($RdfVocabularies.rdf.type, { graph: $parameters.graph })
1016
1302
  .chain((actualRdfType) => actualRdfType.toIri())
1017
1303
  .chain((actualRdfType) => {
1018
1304
  // Check the expected type and its known subtypes
1019
1305
  switch (actualRdfType.value) {
1020
1306
  case "http://www.w3.org/ns/shacl#PropertyShape":
1021
- return purify.Either.of(true);
1307
+ return Right(true);
1022
1308
  }
1023
1309
  // Check arbitrary rdfs:subClassOf's of the expected type
1024
- if ($resource.isInstanceOf(ShaclCorePropertyShape.$fromRdfType)) {
1025
- return purify.Either.of(true);
1310
+ if ($parameters.resource.isInstanceOf(ShaclCorePropertyShape.$fromRdfType, { graph: $parameters.graph })) {
1311
+ return Right(true);
1026
1312
  }
1027
- return purify.Left(new Error(`${rdfjsResource.Resource.Identifier.toString($resource.identifier)} has unexpected RDF type (actual: ${actualRdfType.value}, expected: http://www.w3.org/ns/shacl#PropertyShape)`));
1028
- });
1029
- if ($rdfTypeCheck.isLeft()) {
1030
- return $rdfTypeCheck;
1031
- }
1032
- }
1033
- const $identifier = $resource.identifier;
1034
- const $type = "ShaclCorePropertyShape";
1035
- const _defaultValueEither = purify.Either.of($resource.values(ShaclCorePropertyShape.$properties.defaultValue["identifier"], {
1036
- unique: true,
1037
- }))
1038
- .chain((values) => values.chainMap((value) => purify.Either.of(value.toTerm()).chain((term) => {
1039
- switch (term.termType) {
1040
- case "Literal":
1041
- case "NamedNode":
1042
- return purify.Either.of(term);
1043
- default:
1044
- return purify.Left(new rdfjsResource.Resource.MistypedValueError({
1045
- actualValue: term,
1046
- expectedValueType: "(rdfjs.Literal | rdfjs.NamedNode)",
1047
- focusResource: $resource,
1048
- predicate: ShaclCorePropertyShape.$properties.defaultValue["identifier"],
1049
- }));
1050
- }
1051
- })))
1052
- .map((values) => values.length > 0
1053
- ? values.map((value) => purify.Maybe.of(value))
1054
- : rdfjsResource.Resource.Values.fromValue({
1055
- object: purify.Maybe.empty(),
1056
- predicate: ShaclCorePropertyShape.$properties.defaultValue["identifier"],
1057
- subject: $resource,
1058
- }))
1059
- .chain((values) => values.head());
1060
- if (_defaultValueEither.isLeft()) {
1061
- return _defaultValueEither;
1062
- }
1063
- const defaultValue = _defaultValueEither.unsafeCoerce();
1064
- const _descriptionsEither = purify.Either.of($resource.values(ShaclCorePropertyShape.$properties.descriptions["identifier"], {
1065
- unique: true,
1066
- }))
1067
- .chain((values) => {
1068
- if (!$preferredLanguages || $preferredLanguages.length === 0) {
1069
- return purify.Either.of(values);
1070
- }
1071
- const literalValuesEither = values.chainMap((value) => value.toLiteral());
1072
- if (literalValuesEither.isLeft()) {
1073
- return literalValuesEither;
1074
- }
1075
- const literalValues = literalValuesEither.unsafeCoerce();
1076
- // Return all literals for the first preferredLanguage, then all literals for the second preferredLanguage, etc.
1077
- // Within a preferredLanguage the literals may be in any order.
1078
- let filteredLiteralValues;
1079
- for (const preferredLanguage of $preferredLanguages) {
1080
- if (!filteredLiteralValues) {
1081
- filteredLiteralValues = literalValues.filter((value) => value.language === preferredLanguage);
1082
- }
1083
- else {
1084
- filteredLiteralValues = filteredLiteralValues.concat(...literalValues
1085
- .filter((value) => value.language === preferredLanguage)
1086
- .toArray());
1087
- }
1088
- }
1089
- return purify.Either.of(filteredLiteralValues.map((literalValue) => new rdfjsResource.Resource.Value({
1090
- object: literalValue,
1091
- predicate: ShaclCorePropertyShape.$properties.descriptions["identifier"],
1092
- subject: $resource,
1093
- })));
1094
- })
1095
- .chain((values) => values.chainMap((value) => value.toLiteral()))
1096
- .map((values) => values.toArray())
1097
- .map((valuesArray) => rdfjsResource.Resource.Values.fromValue({
1098
- object: valuesArray,
1099
- predicate: ShaclCorePropertyShape.$properties.descriptions["identifier"],
1100
- subject: $resource,
1101
- }))
1102
- .chain((values) => values.head());
1103
- if (_descriptionsEither.isLeft()) {
1104
- return _descriptionsEither;
1105
- }
1106
- const descriptions = _descriptionsEither.unsafeCoerce();
1107
- const _groupsEither = purify.Either.of($resource.values(ShaclCorePropertyShape.$properties.groups["identifier"], { unique: true }))
1313
+ return Left(new Error(`${Resource.Identifier.toString($parameters.resource.identifier)} has unexpected RDF type (actual: ${actualRdfType.value}, expected: http://www.w3.org/ns/shacl#PropertyShape)`));
1314
+ })
1315
+ : Right(true)).chain((_rdfTypeCheck) => Right(new Resource.Value({
1316
+ dataFactory: dataFactory,
1317
+ focusResource: $parameters.resource,
1318
+ propertyPath: $RdfVocabularies.rdf.subject,
1319
+ term: $parameters.resource.identifier,
1320
+ }).toValues())
1108
1321
  .chain((values) => values.chainMap((value) => value.toIdentifier()))
1109
- .map((values) => values.toArray())
1110
- .map((valuesArray) => rdfjsResource.Resource.Values.fromValue({
1111
- object: valuesArray,
1112
- predicate: ShaclCorePropertyShape.$properties.groups["identifier"],
1113
- subject: $resource,
1114
- }))
1115
- .chain((values) => values.head());
1116
- if (_groupsEither.isLeft()) {
1117
- return _groupsEither;
1118
- }
1119
- const groups = _groupsEither.unsafeCoerce();
1120
- const _namesEither = purify.Either.of($resource.values(ShaclCorePropertyShape.$properties.names["identifier"], { unique: true }))
1121
- .chain((values) => {
1122
- if (!$preferredLanguages || $preferredLanguages.length === 0) {
1123
- return purify.Either.of(values);
1124
- }
1125
- const literalValuesEither = values.chainMap((value) => value.toLiteral());
1126
- if (literalValuesEither.isLeft()) {
1127
- return literalValuesEither;
1128
- }
1129
- const literalValues = literalValuesEither.unsafeCoerce();
1130
- // Return all literals for the first preferredLanguage, then all literals for the second preferredLanguage, etc.
1131
- // Within a preferredLanguage the literals may be in any order.
1132
- let filteredLiteralValues;
1133
- for (const preferredLanguage of $preferredLanguages) {
1134
- if (!filteredLiteralValues) {
1135
- filteredLiteralValues = literalValues.filter((value) => value.language === preferredLanguage);
1322
+ .chain((values) => values.head())
1323
+ .chain(($identifier) => Right("ShaclCorePropertyShape").chain(($type) => $shaclPropertyFromRdf({
1324
+ graph: $parameters.graph,
1325
+ resource: $parameters.resource,
1326
+ propertySchema: ShaclCorePropertyShape.$schema.properties.defaultValue,
1327
+ typeFromRdf: (resourceValues) => resourceValues
1328
+ .chain((values) => values.chainMap((value) => value.toTerm().chain((term) => {
1329
+ switch (term.termType) {
1330
+ case "NamedNode":
1331
+ case "Literal":
1332
+ return Either.of(term);
1333
+ default:
1334
+ return Left(new Resource.MistypedTermValueError({
1335
+ actualValue: term,
1336
+ expectedValueType: "(NamedNode | Literal)",
1337
+ focusResource: $parameters.resource,
1338
+ propertyPath: ShaclCorePropertyShape.$schema.properties
1339
+ .defaultValue.path,
1340
+ }));
1136
1341
  }
1137
- else {
1138
- filteredLiteralValues = filteredLiteralValues.concat(...literalValues
1139
- .filter((value) => value.language === preferredLanguage)
1140
- .toArray());
1141
- }
1142
- }
1143
- return purify.Either.of(filteredLiteralValues.map((literalValue) => new rdfjsResource.Resource.Value({
1144
- object: literalValue,
1145
- predicate: ShaclCorePropertyShape.$properties.names["identifier"],
1146
- subject: $resource,
1147
- })));
1148
- })
1149
- .chain((values) => values.chainMap((value) => value.toLiteral()))
1150
- .map((values) => values.toArray())
1151
- .map((valuesArray) => rdfjsResource.Resource.Values.fromValue({
1152
- object: valuesArray,
1153
- predicate: ShaclCorePropertyShape.$properties.names["identifier"],
1154
- subject: $resource,
1155
- }))
1156
- .chain((values) => values.head());
1157
- if (_namesEither.isLeft()) {
1158
- return _namesEither;
1159
- }
1160
- const names = _namesEither.unsafeCoerce();
1161
- const _orderEither = purify.Either.of($resource.values(ShaclCorePropertyShape.$properties.order["identifier"], { unique: true }))
1162
- .chain((values) => values.chainMap((value) => value.toNumber()))
1163
- .map((values) => values.length > 0
1164
- ? values.map((value) => purify.Maybe.of(value))
1165
- : rdfjsResource.Resource.Values.fromValue({
1166
- object: purify.Maybe.empty(),
1167
- predicate: ShaclCorePropertyShape.$properties.order["identifier"],
1168
- subject: $resource,
1169
- }))
1170
- .chain((values) => values.head());
1171
- if (_orderEither.isLeft()) {
1172
- return _orderEither;
1173
- }
1174
- const order = _orderEither.unsafeCoerce();
1175
- const _pathEither = purify.Either.of($resource.values(ShaclCorePropertyShape.$properties.path["identifier"], { unique: true }))
1176
- .chain((values) => values.chainMap((value) => value.toResource().chain((resource) => PropertyPath.$fromRdf(resource, {
1177
- ...$context,
1178
- ignoreRdfType: true,
1179
- objectSet: $objectSet,
1180
- preferredLanguages: $preferredLanguages,
1181
- }))))
1182
- .chain((values) => values.head());
1183
- if (_pathEither.isLeft()) {
1184
- return _pathEither;
1185
- }
1186
- const path = _pathEither.unsafeCoerce();
1187
- const _uniqueLangEither = purify.Either.of($resource.values(ShaclCorePropertyShape.$properties.uniqueLang["identifier"], { unique: true }))
1188
- .chain((values) => values.chainMap((value) => value.toBoolean()))
1189
- .map((values) => values.length > 0
1190
- ? values.map((value) => purify.Maybe.of(value))
1191
- : rdfjsResource.Resource.Values.fromValue({
1192
- object: purify.Maybe.empty(),
1193
- predicate: ShaclCorePropertyShape.$properties.uniqueLang["identifier"],
1194
- subject: $resource,
1195
- }))
1196
- .chain((values) => values.head());
1197
- if (_uniqueLangEither.isLeft()) {
1198
- return _uniqueLangEither;
1199
- }
1200
- const uniqueLang = _uniqueLangEither.unsafeCoerce();
1201
- return purify.Either.of({
1342
+ })))
1343
+ .map((values) => values.length > 0
1344
+ ? values.map((value) => Maybe.of(value))
1345
+ : Resource.Values.fromValue({
1346
+ focusResource: $parameters.resource,
1347
+ propertyPath: ShaclCorePropertyShape.$schema.properties
1348
+ .defaultValue.path,
1349
+ value: Maybe.empty(),
1350
+ })),
1351
+ }).chain((defaultValue) => $shaclPropertyFromRdf({
1352
+ graph: $parameters.graph,
1353
+ resource: $parameters.resource,
1354
+ propertySchema: ShaclCorePropertyShape.$schema.properties.descriptions,
1355
+ typeFromRdf: (resourceValues) => resourceValues
1356
+ .chain((values) => $fromRdfPreferredLanguages(values, $parameters.preferredLanguages))
1357
+ .chain((values) => values.chainMap((value) => value.toString()))
1358
+ .map((values) => values.toArray())
1359
+ .map((valuesArray) => Resource.Values.fromValue({
1360
+ focusResource: $parameters.resource,
1361
+ propertyPath: ShaclCorePropertyShape.$schema.properties
1362
+ .descriptions.path,
1363
+ value: valuesArray,
1364
+ })),
1365
+ }).chain((descriptions) => $shaclPropertyFromRdf({
1366
+ graph: $parameters.graph,
1367
+ resource: $parameters.resource,
1368
+ propertySchema: ShaclCorePropertyShape.$schema.properties.groups,
1369
+ typeFromRdf: (resourceValues) => resourceValues
1370
+ .chain((values) => values.chainMap((value) => value.toIdentifier()))
1371
+ .map((values) => values.toArray())
1372
+ .map((valuesArray) => Resource.Values.fromValue({
1373
+ focusResource: $parameters.resource,
1374
+ propertyPath: ShaclCorePropertyShape.$schema.properties.groups
1375
+ .path,
1376
+ value: valuesArray,
1377
+ })),
1378
+ }).chain((groups) => $shaclPropertyFromRdf({
1379
+ graph: $parameters.graph,
1380
+ resource: $parameters.resource,
1381
+ propertySchema: ShaclCorePropertyShape.$schema.properties.names,
1382
+ typeFromRdf: (resourceValues) => resourceValues
1383
+ .chain((values) => $fromRdfPreferredLanguages(values, $parameters.preferredLanguages))
1384
+ .chain((values) => values.chainMap((value) => value.toString()))
1385
+ .map((values) => values.toArray())
1386
+ .map((valuesArray) => Resource.Values.fromValue({
1387
+ focusResource: $parameters.resource,
1388
+ propertyPath: ShaclCorePropertyShape.$schema.properties.names
1389
+ .path,
1390
+ value: valuesArray,
1391
+ })),
1392
+ }).chain((names) => $shaclPropertyFromRdf({
1393
+ graph: $parameters.graph,
1394
+ resource: $parameters.resource,
1395
+ propertySchema: ShaclCorePropertyShape.$schema.properties.order,
1396
+ typeFromRdf: (resourceValues) => resourceValues
1397
+ .chain((values) => values.chainMap((value) => value.toFloat()))
1398
+ .map((values) => values.length > 0
1399
+ ? values.map((value) => Maybe.of(value))
1400
+ : Resource.Values.fromValue({
1401
+ focusResource: $parameters.resource,
1402
+ propertyPath: ShaclCorePropertyShape.$schema.properties
1403
+ .order.path,
1404
+ value: Maybe.empty(),
1405
+ })),
1406
+ }).chain((order) => $shaclPropertyFromRdf({
1407
+ graph: $parameters.graph,
1408
+ resource: $parameters.resource,
1409
+ propertySchema: ShaclCorePropertyShape.$schema.properties.path,
1410
+ typeFromRdf: (resourceValues) => resourceValues.chain((values) => values.chainMap((value) => value.toResource().chain((resource) => PropertyPath.$fromRdf(resource, {
1411
+ context: $parameters.context,
1412
+ ignoreRdfType: true,
1413
+ objectSet: $parameters.objectSet,
1414
+ preferredLanguages: $parameters.preferredLanguages,
1415
+ })))),
1416
+ }).chain((path) => $shaclPropertyFromRdf({
1417
+ graph: $parameters.graph,
1418
+ resource: $parameters.resource,
1419
+ propertySchema: ShaclCorePropertyShape.$schema.properties.uniqueLang,
1420
+ typeFromRdf: (resourceValues) => resourceValues
1421
+ .chain((values) => values.chainMap((value) => value.toBoolean()))
1422
+ .map((values) => values.length > 0
1423
+ ? values.map((value) => Maybe.of(value))
1424
+ : Resource.Values.fromValue({
1425
+ focusResource: $parameters.resource,
1426
+ propertyPath: ShaclCorePropertyShape.$schema
1427
+ .properties.uniqueLang.path,
1428
+ value: Maybe.empty(),
1429
+ })),
1430
+ }).map((uniqueLang) => ({
1202
1431
  ...$super0,
1203
1432
  $identifier,
1204
1433
  $type,
@@ -1209,87 +1438,146 @@ export var ShaclCorePropertyShape;
1209
1438
  order,
1210
1439
  path,
1211
1440
  uniqueLang,
1212
- });
1441
+ }))))))))))));
1213
1442
  }
1214
1443
  ShaclCorePropertyShape.$propertiesFromRdf = $propertiesFromRdf;
1215
1444
  function $toRdf(_shaclCorePropertyShape, options) {
1216
- const ignoreRdfType = !!options?.ignoreRdfType;
1217
- const mutateGraph = options?.mutateGraph;
1218
1445
  const resourceSet = options?.resourceSet ??
1219
- new rdfjsResource.MutableResourceSet({
1220
- dataFactory,
1221
- dataset: datasetFactory.dataset(),
1222
- });
1446
+ new ResourceSet(datasetFactory.dataset(), { dataFactory: dataFactory });
1223
1447
  const resource = BaseShaclCoreShapeStatic.$toRdf(_shaclCorePropertyShape, {
1224
1448
  ignoreRdfType: true,
1225
- mutateGraph,
1449
+ graph: options?.graph,
1226
1450
  resourceSet,
1227
1451
  });
1228
- if (!ignoreRdfType) {
1229
- resource.add($RdfVocabularies.rdf.type, resource.dataFactory.namedNode("http://purl.org/shaclmate/ontology#ShaclCorePropertyShape"));
1230
- resource.add($RdfVocabularies.rdf.type, resource.dataFactory.namedNode("http://www.w3.org/ns/shacl#PropertyShape"));
1231
- }
1232
- resource.add(ShaclCorePropertyShape.$properties.defaultValue["identifier"], ..._shaclCorePropertyShape.defaultValue.toList());
1233
- resource.add(ShaclCorePropertyShape.$properties.descriptions["identifier"], ..._shaclCorePropertyShape.descriptions.flatMap((item) => [item]));
1234
- resource.add(ShaclCorePropertyShape.$properties.groups["identifier"], ..._shaclCorePropertyShape.groups.flatMap((item) => [item]));
1235
- resource.add(ShaclCorePropertyShape.$properties.names["identifier"], ..._shaclCorePropertyShape.names.flatMap((item) => [item]));
1236
- resource.add(ShaclCorePropertyShape.$properties.order["identifier"], ..._shaclCorePropertyShape.order.toList());
1237
- resource.add(ShaclCorePropertyShape.$properties.path["identifier"], ...[
1452
+ if (!options?.ignoreRdfType) {
1453
+ resource.add($RdfVocabularies.rdf.type, dataFactory.namedNode("http://www.w3.org/ns/shacl#PropertyShape"), options?.graph);
1454
+ }
1455
+ resource.add(dataFactory.namedNode("http://www.w3.org/ns/shacl#defaultValue"), _shaclCorePropertyShape.defaultValue.toList(), options?.graph);
1456
+ resource.add(dataFactory.namedNode("http://www.w3.org/ns/shacl#description"), _shaclCorePropertyShape.descriptions.flatMap((item) => [
1457
+ $literalFactory.string(item),
1458
+ ]), options?.graph);
1459
+ resource.add(dataFactory.namedNode("http://www.w3.org/ns/shacl#group"), _shaclCorePropertyShape.groups.flatMap((item) => [item]), options?.graph);
1460
+ resource.add(dataFactory.namedNode("http://www.w3.org/ns/shacl#name"), _shaclCorePropertyShape.names.flatMap((item) => [
1461
+ $literalFactory.string(item),
1462
+ ]), options?.graph);
1463
+ resource.add(dataFactory.namedNode("http://www.w3.org/ns/shacl#order"), _shaclCorePropertyShape.order
1464
+ .toList()
1465
+ .flatMap((value) => [
1466
+ $literalFactory.number(value, $RdfVocabularies.xsd.double),
1467
+ ]), options?.graph);
1468
+ resource.add(dataFactory.namedNode("http://www.w3.org/ns/shacl#path"), [
1238
1469
  PropertyPath.$toRdf(_shaclCorePropertyShape.path, {
1239
- mutateGraph: mutateGraph,
1470
+ graph: options?.graph,
1240
1471
  resourceSet: resourceSet,
1241
1472
  }).identifier,
1242
- ]);
1243
- resource.add(ShaclCorePropertyShape.$properties.uniqueLang["identifier"], ..._shaclCorePropertyShape.uniqueLang.toList().flat());
1473
+ ], options?.graph);
1474
+ resource.add(dataFactory.namedNode("http://www.w3.org/ns/shacl#uniqueLang"), _shaclCorePropertyShape.uniqueLang
1475
+ .toList()
1476
+ .flatMap((value) => [
1477
+ $literalFactory.boolean(value, $RdfVocabularies.xsd.boolean),
1478
+ ]), options?.graph);
1244
1479
  return resource;
1245
1480
  }
1246
1481
  ShaclCorePropertyShape.$toRdf = $toRdf;
1247
- ShaclCorePropertyShape.$properties = {
1248
- ...BaseShaclCoreShapeStatic.$properties,
1249
- defaultValue: {
1250
- identifier: dataFactory.namedNode("http://www.w3.org/ns/shacl#defaultValue"),
1251
- },
1252
- descriptions: {
1253
- identifier: dataFactory.namedNode("http://www.w3.org/ns/shacl#description"),
1254
- },
1255
- groups: {
1256
- identifier: dataFactory.namedNode("http://www.w3.org/ns/shacl#group"),
1257
- },
1258
- names: {
1259
- identifier: dataFactory.namedNode("http://www.w3.org/ns/shacl#name"),
1260
- },
1261
- order: {
1262
- identifier: dataFactory.namedNode("http://www.w3.org/ns/shacl#order"),
1263
- },
1264
- path: {
1265
- identifier: dataFactory.namedNode("http://www.w3.org/ns/shacl#path"),
1266
- },
1267
- uniqueLang: {
1268
- identifier: dataFactory.namedNode("http://www.w3.org/ns/shacl#uniqueLang"),
1482
+ ShaclCorePropertyShape.$schema = {
1483
+ properties: {
1484
+ ...BaseShaclCoreShapeStatic.$schema.properties,
1485
+ defaultValue: {
1486
+ kind: "Shacl",
1487
+ type: () => ({
1488
+ kind: "Maybe",
1489
+ item: () => ({ kind: "Term" }),
1490
+ }),
1491
+ path: dataFactory.namedNode("http://www.w3.org/ns/shacl#defaultValue"),
1492
+ },
1493
+ descriptions: {
1494
+ kind: "Shacl",
1495
+ type: () => ({
1496
+ kind: "Set",
1497
+ item: () => ({ kind: "String" }),
1498
+ }),
1499
+ path: dataFactory.namedNode("http://www.w3.org/ns/shacl#description"),
1500
+ },
1501
+ groups: {
1502
+ kind: "Shacl",
1503
+ type: () => ({
1504
+ kind: "Set",
1505
+ item: () => ({ kind: "Identifier" }),
1506
+ }),
1507
+ path: dataFactory.namedNode("http://www.w3.org/ns/shacl#group"),
1508
+ },
1509
+ names: {
1510
+ kind: "Shacl",
1511
+ type: () => ({
1512
+ kind: "Set",
1513
+ item: () => ({ kind: "String" }),
1514
+ }),
1515
+ path: dataFactory.namedNode("http://www.w3.org/ns/shacl#name"),
1516
+ },
1517
+ order: {
1518
+ kind: "Shacl",
1519
+ type: () => ({
1520
+ kind: "Maybe",
1521
+ item: () => ({ kind: "Float" }),
1522
+ }),
1523
+ path: dataFactory.namedNode("http://www.w3.org/ns/shacl#order"),
1524
+ },
1525
+ path: {
1526
+ kind: "Shacl",
1527
+ type: () => PropertyPath.$schema,
1528
+ path: dataFactory.namedNode("http://www.w3.org/ns/shacl#path"),
1529
+ },
1530
+ uniqueLang: {
1531
+ kind: "Shacl",
1532
+ type: () => ({
1533
+ kind: "Maybe",
1534
+ item: () => ({ kind: "Boolean" }),
1535
+ }),
1536
+ path: dataFactory.namedNode("http://www.w3.org/ns/shacl#uniqueLang"),
1537
+ },
1269
1538
  },
1270
1539
  };
1271
1540
  })(ShaclCorePropertyShape || (ShaclCorePropertyShape = {}));
1272
1541
  export var ShaclCorePropertyGroup;
1273
1542
  (function (ShaclCorePropertyGroup) {
1543
+ function $filter(filter, value) {
1544
+ if (filter.$identifier !== undefined &&
1545
+ !$filterIdentifier(filter.$identifier, value.$identifier)) {
1546
+ return false;
1547
+ }
1548
+ if (filter.comments !== undefined &&
1549
+ !$filterArray($filterString)(filter.comments, value.comments)) {
1550
+ return false;
1551
+ }
1552
+ if (filter.labels !== undefined &&
1553
+ !$filterArray($filterString)(filter.labels, value.labels)) {
1554
+ return false;
1555
+ }
1556
+ return true;
1557
+ }
1558
+ ShaclCorePropertyGroup.$filter = $filter;
1274
1559
  ShaclCorePropertyGroup.$fromRdfType = dataFactory.namedNode("http://www.w3.org/ns/shacl#PropertyGroup");
1275
1560
  let $Identifier;
1276
1561
  (function ($Identifier) {
1277
- function fromString(identifier) {
1278
- return purify.Either.encase(() => rdfjsResource.Resource.Identifier.fromString({
1279
- dataFactory,
1280
- identifier,
1281
- }));
1282
- }
1283
- $Identifier.fromString = fromString;
1284
- $Identifier.toString = rdfjsResource.Resource.Identifier.toString;
1562
+ $Identifier.fromString = $identifierFromString; // biome-ignore lint/suspicious/noShadowRestrictedNames: allow toString
1563
+ $Identifier.toString = Resource.Identifier.toString;
1285
1564
  })($Identifier = ShaclCorePropertyGroup.$Identifier || (ShaclCorePropertyGroup.$Identifier = {}));
1565
+ function isShaclCorePropertyGroup(object) {
1566
+ switch (object.$type) {
1567
+ case "ShaclCorePropertyGroup":
1568
+ return true;
1569
+ default:
1570
+ return false;
1571
+ }
1572
+ }
1573
+ ShaclCorePropertyGroup.isShaclCorePropertyGroup = isShaclCorePropertyGroup;
1286
1574
  function $fromRdf(resource, options) {
1287
- let { ignoreRdfType = false, objectSet, preferredLanguages, ...context } = options ?? {};
1575
+ let { context, ignoreRdfType = false, objectSet, preferredLanguages, } = options ?? {};
1288
1576
  if (!objectSet) {
1289
- objectSet = new $RdfjsDatasetObjectSet({ dataset: resource.dataset });
1577
+ objectSet = new $RdfjsDatasetObjectSet(resource.dataset);
1290
1578
  }
1291
1579
  return ShaclCorePropertyGroup.$propertiesFromRdf({
1292
- ...context,
1580
+ context,
1293
1581
  ignoreRdfType,
1294
1582
  objectSet,
1295
1583
  preferredLanguages,
@@ -1297,153 +1585,151 @@ export var ShaclCorePropertyGroup;
1297
1585
  });
1298
1586
  }
1299
1587
  ShaclCorePropertyGroup.$fromRdf = $fromRdf;
1300
- function $propertiesFromRdf({ ignoreRdfType: $ignoreRdfType, objectSet: $objectSet, preferredLanguages: $preferredLanguages, resource: $resource,
1301
- // @ts-ignore
1302
- ...$context }) {
1303
- if (!$ignoreRdfType) {
1304
- const $rdfTypeCheck = $resource
1305
- .value($RdfVocabularies.rdf.type)
1588
+ function $propertiesFromRdf($parameters) {
1589
+ return (!$parameters.ignoreRdfType
1590
+ ? $parameters.resource
1591
+ .value($RdfVocabularies.rdf.type, { graph: $parameters.graph })
1306
1592
  .chain((actualRdfType) => actualRdfType.toIri())
1307
1593
  .chain((actualRdfType) => {
1308
1594
  // Check the expected type and its known subtypes
1309
1595
  switch (actualRdfType.value) {
1310
1596
  case "http://www.w3.org/ns/shacl#PropertyGroup":
1311
- return purify.Either.of(true);
1597
+ return Right(true);
1312
1598
  }
1313
1599
  // Check arbitrary rdfs:subClassOf's of the expected type
1314
- if ($resource.isInstanceOf(ShaclCorePropertyGroup.$fromRdfType)) {
1315
- return purify.Either.of(true);
1600
+ if ($parameters.resource.isInstanceOf(ShaclCorePropertyGroup.$fromRdfType, { graph: $parameters.graph })) {
1601
+ return Right(true);
1316
1602
  }
1317
- return purify.Left(new Error(`${rdfjsResource.Resource.Identifier.toString($resource.identifier)} has unexpected RDF type (actual: ${actualRdfType.value}, expected: http://www.w3.org/ns/shacl#PropertyGroup)`));
1318
- });
1319
- if ($rdfTypeCheck.isLeft()) {
1320
- return $rdfTypeCheck;
1321
- }
1322
- }
1323
- const $identifier = $resource.identifier;
1324
- const $type = "ShaclCorePropertyGroup";
1325
- const _commentsEither = purify.Either.of($resource.values(ShaclCorePropertyGroup.$properties.comments["identifier"], { unique: true }))
1326
- .chain((values) => {
1327
- if (!$preferredLanguages || $preferredLanguages.length === 0) {
1328
- return purify.Either.of(values);
1329
- }
1330
- const literalValuesEither = values.chainMap((value) => value.toLiteral());
1331
- if (literalValuesEither.isLeft()) {
1332
- return literalValuesEither;
1333
- }
1334
- const literalValues = literalValuesEither.unsafeCoerce();
1335
- // Return all literals for the first preferredLanguage, then all literals for the second preferredLanguage, etc.
1336
- // Within a preferredLanguage the literals may be in any order.
1337
- let filteredLiteralValues;
1338
- for (const preferredLanguage of $preferredLanguages) {
1339
- if (!filteredLiteralValues) {
1340
- filteredLiteralValues = literalValues.filter((value) => value.language === preferredLanguage);
1341
- }
1342
- else {
1343
- filteredLiteralValues = filteredLiteralValues.concat(...literalValues
1344
- .filter((value) => value.language === preferredLanguage)
1345
- .toArray());
1346
- }
1347
- }
1348
- return purify.Either.of(filteredLiteralValues.map((literalValue) => new rdfjsResource.Resource.Value({
1349
- object: literalValue,
1350
- predicate: ShaclCorePropertyGroup.$properties.comments["identifier"],
1351
- subject: $resource,
1352
- })));
1353
- })
1354
- .chain((values) => values.chainMap((value) => value.toLiteral()))
1355
- .map((values) => values.toArray())
1356
- .map((valuesArray) => rdfjsResource.Resource.Values.fromValue({
1357
- object: valuesArray,
1358
- predicate: ShaclCorePropertyGroup.$properties.comments["identifier"],
1359
- subject: $resource,
1360
- }))
1361
- .chain((values) => values.head());
1362
- if (_commentsEither.isLeft()) {
1363
- return _commentsEither;
1364
- }
1365
- const comments = _commentsEither.unsafeCoerce();
1366
- const _labelsEither = purify.Either.of($resource.values(ShaclCorePropertyGroup.$properties.labels["identifier"], { unique: true }))
1367
- .chain((values) => {
1368
- if (!$preferredLanguages || $preferredLanguages.length === 0) {
1369
- return purify.Either.of(values);
1370
- }
1371
- const literalValuesEither = values.chainMap((value) => value.toLiteral());
1372
- if (literalValuesEither.isLeft()) {
1373
- return literalValuesEither;
1374
- }
1375
- const literalValues = literalValuesEither.unsafeCoerce();
1376
- // Return all literals for the first preferredLanguage, then all literals for the second preferredLanguage, etc.
1377
- // Within a preferredLanguage the literals may be in any order.
1378
- let filteredLiteralValues;
1379
- for (const preferredLanguage of $preferredLanguages) {
1380
- if (!filteredLiteralValues) {
1381
- filteredLiteralValues = literalValues.filter((value) => value.language === preferredLanguage);
1382
- }
1383
- else {
1384
- filteredLiteralValues = filteredLiteralValues.concat(...literalValues
1385
- .filter((value) => value.language === preferredLanguage)
1386
- .toArray());
1387
- }
1388
- }
1389
- return purify.Either.of(filteredLiteralValues.map((literalValue) => new rdfjsResource.Resource.Value({
1390
- object: literalValue,
1391
- predicate: ShaclCorePropertyGroup.$properties.labels["identifier"],
1392
- subject: $resource,
1393
- })));
1394
- })
1395
- .chain((values) => values.chainMap((value) => value.toLiteral()))
1396
- .map((values) => values.toArray())
1397
- .map((valuesArray) => rdfjsResource.Resource.Values.fromValue({
1398
- object: valuesArray,
1399
- predicate: ShaclCorePropertyGroup.$properties.labels["identifier"],
1400
- subject: $resource,
1401
- }))
1402
- .chain((values) => values.head());
1403
- if (_labelsEither.isLeft()) {
1404
- return _labelsEither;
1405
- }
1406
- const labels = _labelsEither.unsafeCoerce();
1407
- return purify.Either.of({ $identifier, $type, comments, labels });
1603
+ return Left(new Error(`${Resource.Identifier.toString($parameters.resource.identifier)} has unexpected RDF type (actual: ${actualRdfType.value}, expected: http://www.w3.org/ns/shacl#PropertyGroup)`));
1604
+ })
1605
+ : Right(true)).chain((_rdfTypeCheck) => Right(new Resource.Value({
1606
+ dataFactory: dataFactory,
1607
+ focusResource: $parameters.resource,
1608
+ propertyPath: $RdfVocabularies.rdf.subject,
1609
+ term: $parameters.resource.identifier,
1610
+ }).toValues())
1611
+ .chain((values) => values.chainMap((value) => value.toIdentifier()))
1612
+ .chain((values) => values.head())
1613
+ .chain(($identifier) => Right("ShaclCorePropertyGroup").chain(($type) => $shaclPropertyFromRdf({
1614
+ graph: $parameters.graph,
1615
+ resource: $parameters.resource,
1616
+ propertySchema: ShaclCorePropertyGroup.$schema.properties.comments,
1617
+ typeFromRdf: (resourceValues) => resourceValues
1618
+ .chain((values) => $fromRdfPreferredLanguages(values, $parameters.preferredLanguages))
1619
+ .chain((values) => values.chainMap((value) => value.toString()))
1620
+ .map((values) => values.toArray())
1621
+ .map((valuesArray) => Resource.Values.fromValue({
1622
+ focusResource: $parameters.resource,
1623
+ propertyPath: ShaclCorePropertyGroup.$schema.properties.comments.path,
1624
+ value: valuesArray,
1625
+ })),
1626
+ }).chain((comments) => $shaclPropertyFromRdf({
1627
+ graph: $parameters.graph,
1628
+ resource: $parameters.resource,
1629
+ propertySchema: ShaclCorePropertyGroup.$schema.properties.labels,
1630
+ typeFromRdf: (resourceValues) => resourceValues
1631
+ .chain((values) => $fromRdfPreferredLanguages(values, $parameters.preferredLanguages))
1632
+ .chain((values) => values.chainMap((value) => value.toString()))
1633
+ .map((values) => values.toArray())
1634
+ .map((valuesArray) => Resource.Values.fromValue({
1635
+ focusResource: $parameters.resource,
1636
+ propertyPath: ShaclCorePropertyGroup.$schema.properties.labels.path,
1637
+ value: valuesArray,
1638
+ })),
1639
+ }).map((labels) => ({ $identifier, $type, comments, labels }))))));
1408
1640
  }
1409
1641
  ShaclCorePropertyGroup.$propertiesFromRdf = $propertiesFromRdf;
1410
1642
  function $toRdf(_shaclCorePropertyGroup, options) {
1411
- const ignoreRdfType = !!options?.ignoreRdfType;
1412
- const mutateGraph = options?.mutateGraph;
1413
1643
  const resourceSet = options?.resourceSet ??
1414
- new rdfjsResource.MutableResourceSet({
1415
- dataFactory,
1416
- dataset: datasetFactory.dataset(),
1417
- });
1418
- const resource = resourceSet.mutableResource(_shaclCorePropertyGroup.$identifier, { mutateGraph });
1419
- if (!ignoreRdfType) {
1420
- resource.add($RdfVocabularies.rdf.type, resource.dataFactory.namedNode("http://www.w3.org/ns/shacl#PropertyGroup"));
1421
- }
1422
- resource.add(ShaclCorePropertyGroup.$properties.comments["identifier"], ..._shaclCorePropertyGroup.comments.flatMap((item) => [item]));
1423
- resource.add(ShaclCorePropertyGroup.$properties.labels["identifier"], ..._shaclCorePropertyGroup.labels.flatMap((item) => [item]));
1644
+ new ResourceSet(datasetFactory.dataset(), { dataFactory: dataFactory });
1645
+ const resource = resourceSet.resource(_shaclCorePropertyGroup.$identifier);
1646
+ if (!options?.ignoreRdfType) {
1647
+ resource.add($RdfVocabularies.rdf.type, dataFactory.namedNode("http://www.w3.org/ns/shacl#PropertyGroup"), options?.graph);
1648
+ }
1649
+ resource.add(dataFactory.namedNode("http://www.w3.org/2000/01/rdf-schema#comment"), _shaclCorePropertyGroup.comments.flatMap((item) => [
1650
+ $literalFactory.string(item),
1651
+ ]), options?.graph);
1652
+ resource.add(dataFactory.namedNode("http://www.w3.org/2000/01/rdf-schema#label"), _shaclCorePropertyGroup.labels.flatMap((item) => [
1653
+ $literalFactory.string(item),
1654
+ ]), options?.graph);
1424
1655
  return resource;
1425
1656
  }
1426
1657
  ShaclCorePropertyGroup.$toRdf = $toRdf;
1427
- ShaclCorePropertyGroup.$properties = {
1428
- comments: {
1429
- identifier: dataFactory.namedNode("http://www.w3.org/2000/01/rdf-schema#comment"),
1430
- },
1431
- labels: {
1432
- identifier: dataFactory.namedNode("http://www.w3.org/2000/01/rdf-schema#label"),
1658
+ ShaclCorePropertyGroup.$schema = {
1659
+ properties: {
1660
+ $identifier: {
1661
+ kind: "Identifier",
1662
+ type: () => ({ kind: "Identifier" }),
1663
+ },
1664
+ $type: {
1665
+ kind: "TypeDiscriminant",
1666
+ type: () => ({
1667
+ kind: "TypeDiscriminant",
1668
+ ownValues: ["ShaclCorePropertyGroup"],
1669
+ }),
1670
+ },
1671
+ comments: {
1672
+ kind: "Shacl",
1673
+ type: () => ({
1674
+ kind: "Set",
1675
+ item: () => ({ kind: "String" }),
1676
+ }),
1677
+ path: dataFactory.namedNode("http://www.w3.org/2000/01/rdf-schema#comment"),
1678
+ },
1679
+ labels: {
1680
+ kind: "Shacl",
1681
+ type: () => ({
1682
+ kind: "Set",
1683
+ item: () => ({ kind: "String" }),
1684
+ }),
1685
+ path: dataFactory.namedNode("http://www.w3.org/2000/01/rdf-schema#label"),
1686
+ },
1433
1687
  },
1434
1688
  };
1435
1689
  })(ShaclCorePropertyGroup || (ShaclCorePropertyGroup = {}));
1436
1690
  export var ShaclCoreNodeShape;
1437
1691
  (function (ShaclCoreNodeShape) {
1692
+ function $filter(filter, value) {
1693
+ if (!BaseShaclCoreShapeStatic.$filter(filter, value)) {
1694
+ return false;
1695
+ }
1696
+ if (filter.closed !== undefined &&
1697
+ !$filterMaybe($filterBoolean)(filter.closed, value.closed)) {
1698
+ return false;
1699
+ }
1700
+ if (filter.ignoredProperties !== undefined &&
1701
+ !$filterMaybe($filterArray($filterIri))(filter.ignoredProperties, value.ignoredProperties)) {
1702
+ return false;
1703
+ }
1704
+ if (filter.properties !== undefined &&
1705
+ !$filterArray($filterIdentifier)(filter.properties, value.properties)) {
1706
+ return false;
1707
+ }
1708
+ return true;
1709
+ }
1710
+ ShaclCoreNodeShape.$filter = $filter;
1438
1711
  ShaclCoreNodeShape.$fromRdfType = dataFactory.namedNode("http://www.w3.org/ns/shacl#NodeShape");
1439
- ShaclCoreNodeShape.$Identifier = BaseShaclCoreShapeStatic.$Identifier;
1712
+ let $Identifier;
1713
+ (function ($Identifier) {
1714
+ $Identifier.fromString = $identifierFromString; // biome-ignore lint/suspicious/noShadowRestrictedNames: allow toString
1715
+ $Identifier.toString = Resource.Identifier.toString;
1716
+ })($Identifier = ShaclCoreNodeShape.$Identifier || (ShaclCoreNodeShape.$Identifier = {}));
1717
+ function isShaclCoreNodeShape(object) {
1718
+ switch (object.$type) {
1719
+ case "ShaclCoreNodeShape":
1720
+ return true;
1721
+ default:
1722
+ return false;
1723
+ }
1724
+ }
1725
+ ShaclCoreNodeShape.isShaclCoreNodeShape = isShaclCoreNodeShape;
1440
1726
  function $fromRdf(resource, options) {
1441
- let { ignoreRdfType = false, objectSet, preferredLanguages, ...context } = options ?? {};
1727
+ let { context, ignoreRdfType = false, objectSet, preferredLanguages, } = options ?? {};
1442
1728
  if (!objectSet) {
1443
- objectSet = new $RdfjsDatasetObjectSet({ dataset: resource.dataset });
1729
+ objectSet = new $RdfjsDatasetObjectSet(resource.dataset);
1444
1730
  }
1445
1731
  return ShaclCoreNodeShape.$propertiesFromRdf({
1446
- ...context,
1732
+ context,
1447
1733
  ignoreRdfType,
1448
1734
  objectSet,
1449
1735
  preferredLanguages,
@@ -1451,179 +1737,203 @@ export var ShaclCoreNodeShape;
1451
1737
  });
1452
1738
  }
1453
1739
  ShaclCoreNodeShape.$fromRdf = $fromRdf;
1454
- function $propertiesFromRdf({ ignoreRdfType: $ignoreRdfType, objectSet: $objectSet, preferredLanguages: $preferredLanguages, resource: $resource,
1455
- // @ts-ignore
1456
- ...$context }) {
1457
- const $super0Either = BaseShaclCoreShapeStatic.$propertiesFromRdf({
1458
- ...$context,
1740
+ function $propertiesFromRdf($parameters) {
1741
+ return BaseShaclCoreShapeStatic.$propertiesFromRdf({
1742
+ ...$parameters,
1459
1743
  ignoreRdfType: true,
1460
- objectSet: $objectSet,
1461
- preferredLanguages: $preferredLanguages,
1462
- resource: $resource,
1463
- });
1464
- if ($super0Either.isLeft()) {
1465
- return $super0Either;
1466
- }
1467
- const $super0 = $super0Either.unsafeCoerce();
1468
- if (!$ignoreRdfType) {
1469
- const $rdfTypeCheck = $resource
1470
- .value($RdfVocabularies.rdf.type)
1744
+ }).chain(($super0) => (!$parameters.ignoreRdfType
1745
+ ? $parameters.resource
1746
+ .value($RdfVocabularies.rdf.type, { graph: $parameters.graph })
1471
1747
  .chain((actualRdfType) => actualRdfType.toIri())
1472
1748
  .chain((actualRdfType) => {
1473
1749
  // Check the expected type and its known subtypes
1474
1750
  switch (actualRdfType.value) {
1475
1751
  case "http://www.w3.org/ns/shacl#NodeShape":
1476
- return purify.Either.of(true);
1752
+ return Right(true);
1477
1753
  }
1478
1754
  // Check arbitrary rdfs:subClassOf's of the expected type
1479
- if ($resource.isInstanceOf(ShaclCoreNodeShape.$fromRdfType)) {
1480
- return purify.Either.of(true);
1755
+ if ($parameters.resource.isInstanceOf(ShaclCoreNodeShape.$fromRdfType, { graph: $parameters.graph })) {
1756
+ return Right(true);
1481
1757
  }
1482
- return purify.Left(new Error(`${rdfjsResource.Resource.Identifier.toString($resource.identifier)} has unexpected RDF type (actual: ${actualRdfType.value}, expected: http://www.w3.org/ns/shacl#NodeShape)`));
1483
- });
1484
- if ($rdfTypeCheck.isLeft()) {
1485
- return $rdfTypeCheck;
1486
- }
1487
- }
1488
- const $identifier = $resource.identifier;
1489
- const $type = "ShaclCoreNodeShape";
1490
- const _closedEither = purify.Either.of($resource.values(ShaclCoreNodeShape.$properties.closed["identifier"], { unique: true }))
1491
- .chain((values) => values.chainMap((value) => value.toBoolean()))
1492
- .map((values) => values.length > 0
1493
- ? values.map((value) => purify.Maybe.of(value))
1494
- : rdfjsResource.Resource.Values.fromValue({
1495
- object: purify.Maybe.empty(),
1496
- predicate: ShaclCoreNodeShape.$properties.closed["identifier"],
1497
- subject: $resource,
1498
- }))
1499
- .chain((values) => values.head());
1500
- if (_closedEither.isLeft()) {
1501
- return _closedEither;
1502
- }
1503
- const closed = _closedEither.unsafeCoerce();
1504
- const _ignoredPropertiesEither = purify.Either.of($resource.values(ShaclCoreNodeShape.$properties.ignoredProperties["identifier"], {
1505
- unique: true,
1506
- }))
1507
- .chain((values) => values.chainMap((value) => value.toList()))
1508
- .chain((valueLists) => valueLists.chainMap((valueList) => purify.Either.of(rdfjsResource.Resource.Values.fromArray({
1509
- objects: valueList,
1510
- predicate: ShaclCoreNodeShape.$properties.ignoredProperties["identifier"],
1511
- subject: $resource,
1512
- })).chain((values) => values.chainMap((value) => value.toIri()))))
1513
- .map((valueLists) => valueLists.map((valueList) => valueList.toArray()))
1514
- .map((values) => values.length > 0
1515
- ? values.map((value) => purify.Maybe.of(value))
1516
- : rdfjsResource.Resource.Values.fromValue({
1517
- object: purify.Maybe.empty(),
1518
- predicate: ShaclCoreNodeShape.$properties.ignoredProperties["identifier"],
1519
- subject: $resource,
1520
- }))
1521
- .chain((values) => values.head());
1522
- if (_ignoredPropertiesEither.isLeft()) {
1523
- return _ignoredPropertiesEither;
1524
- }
1525
- const ignoredProperties = _ignoredPropertiesEither.unsafeCoerce();
1526
- const _propertiesEither = purify.Either.of($resource.values(ShaclCoreNodeShape.$properties.properties["identifier"], { unique: true }))
1758
+ return Left(new Error(`${Resource.Identifier.toString($parameters.resource.identifier)} has unexpected RDF type (actual: ${actualRdfType.value}, expected: http://www.w3.org/ns/shacl#NodeShape)`));
1759
+ })
1760
+ : Right(true)).chain((_rdfTypeCheck) => Right(new Resource.Value({
1761
+ dataFactory: dataFactory,
1762
+ focusResource: $parameters.resource,
1763
+ propertyPath: $RdfVocabularies.rdf.subject,
1764
+ term: $parameters.resource.identifier,
1765
+ }).toValues())
1527
1766
  .chain((values) => values.chainMap((value) => value.toIdentifier()))
1528
- .map((values) => values.toArray())
1529
- .map((valuesArray) => rdfjsResource.Resource.Values.fromValue({
1530
- object: valuesArray,
1531
- predicate: ShaclCoreNodeShape.$properties.properties["identifier"],
1532
- subject: $resource,
1533
- }))
1534
- .chain((values) => values.head());
1535
- if (_propertiesEither.isLeft()) {
1536
- return _propertiesEither;
1537
- }
1538
- const properties = _propertiesEither.unsafeCoerce();
1539
- return purify.Either.of({
1767
+ .chain((values) => values.head())
1768
+ .chain(($identifier) => Right("ShaclCoreNodeShape").chain(($type) => $shaclPropertyFromRdf({
1769
+ graph: $parameters.graph,
1770
+ resource: $parameters.resource,
1771
+ propertySchema: ShaclCoreNodeShape.$schema.properties.closed,
1772
+ typeFromRdf: (resourceValues) => resourceValues
1773
+ .chain((values) => values.chainMap((value) => value.toBoolean()))
1774
+ .map((values) => values.length > 0
1775
+ ? values.map((value) => Maybe.of(value))
1776
+ : Resource.Values.fromValue({
1777
+ focusResource: $parameters.resource,
1778
+ propertyPath: ShaclCoreNodeShape.$schema.properties.closed
1779
+ .path,
1780
+ value: Maybe.empty(),
1781
+ })),
1782
+ }).chain((closed) => $shaclPropertyFromRdf({
1783
+ graph: $parameters.graph,
1784
+ resource: $parameters.resource,
1785
+ propertySchema: ShaclCoreNodeShape.$schema.properties.ignoredProperties,
1786
+ typeFromRdf: (resourceValues) => resourceValues
1787
+ .chain((values) => values.chainMap((value) => value.toList({ graph: $parameters.graph })))
1788
+ .chain((valueLists) => valueLists.chainMap((valueList) => Right(Resource.Values.fromArray({
1789
+ focusResource: $parameters.resource,
1790
+ propertyPath: ShaclCoreNodeShape.$schema.properties
1791
+ .ignoredProperties.path,
1792
+ values: valueList.toArray(),
1793
+ })).chain((values) => values.chainMap((value) => value.toIri()))))
1794
+ .map((valueLists) => valueLists.map((valueList) => valueList.toArray()))
1795
+ .map((values) => values.length > 0
1796
+ ? values.map((value) => Maybe.of(value))
1797
+ : Resource.Values.fromValue({
1798
+ focusResource: $parameters.resource,
1799
+ propertyPath: ShaclCoreNodeShape.$schema.properties
1800
+ .ignoredProperties.path,
1801
+ value: Maybe.empty(),
1802
+ })),
1803
+ }).chain((ignoredProperties) => $shaclPropertyFromRdf({
1804
+ graph: $parameters.graph,
1805
+ resource: $parameters.resource,
1806
+ propertySchema: ShaclCoreNodeShape.$schema.properties.properties,
1807
+ typeFromRdf: (resourceValues) => resourceValues
1808
+ .chain((values) => values.chainMap((value) => value.toIdentifier()))
1809
+ .map((values) => values.toArray())
1810
+ .map((valuesArray) => Resource.Values.fromValue({
1811
+ focusResource: $parameters.resource,
1812
+ propertyPath: ShaclCoreNodeShape.$schema.properties.properties
1813
+ .path,
1814
+ value: valuesArray,
1815
+ })),
1816
+ }).map((properties) => ({
1540
1817
  ...$super0,
1541
1818
  $identifier,
1542
1819
  $type,
1543
1820
  closed,
1544
1821
  ignoredProperties,
1545
1822
  properties,
1546
- });
1823
+ }))))))));
1547
1824
  }
1548
1825
  ShaclCoreNodeShape.$propertiesFromRdf = $propertiesFromRdf;
1549
1826
  function $toRdf(_shaclCoreNodeShape, options) {
1550
- const ignoreRdfType = !!options?.ignoreRdfType;
1551
- const mutateGraph = options?.mutateGraph;
1552
1827
  const resourceSet = options?.resourceSet ??
1553
- new rdfjsResource.MutableResourceSet({
1554
- dataFactory,
1555
- dataset: datasetFactory.dataset(),
1556
- });
1828
+ new ResourceSet(datasetFactory.dataset(), { dataFactory: dataFactory });
1557
1829
  const resource = BaseShaclCoreShapeStatic.$toRdf(_shaclCoreNodeShape, {
1558
1830
  ignoreRdfType: true,
1559
- mutateGraph,
1831
+ graph: options?.graph,
1560
1832
  resourceSet,
1561
1833
  });
1562
- if (!ignoreRdfType) {
1563
- resource.add($RdfVocabularies.rdf.type, resource.dataFactory.namedNode("http://purl.org/shaclmate/ontology#ShaclCoreNodeShape"));
1564
- resource.add($RdfVocabularies.rdf.type, resource.dataFactory.namedNode("http://www.w3.org/ns/shacl#NodeShape"));
1565
- }
1566
- resource.add(ShaclCoreNodeShape.$properties.closed["identifier"], ..._shaclCoreNodeShape.closed.toList().flat());
1567
- resource.add(ShaclCoreNodeShape.$properties.ignoredProperties["identifier"], ..._shaclCoreNodeShape.ignoredProperties.toList().flatMap((value) => [
1834
+ if (!options?.ignoreRdfType) {
1835
+ resource.add($RdfVocabularies.rdf.type, dataFactory.namedNode("http://www.w3.org/ns/shacl#NodeShape"), options?.graph);
1836
+ }
1837
+ resource.add(dataFactory.namedNode("http://www.w3.org/ns/shacl#closed"), _shaclCoreNodeShape.closed
1838
+ .toList()
1839
+ .flatMap((value) => [
1840
+ $literalFactory.boolean(value, $RdfVocabularies.xsd.boolean),
1841
+ ]), options?.graph);
1842
+ resource.add(dataFactory.namedNode("http://www.w3.org/ns/shacl#ignoredProperties"), _shaclCoreNodeShape.ignoredProperties.toList().flatMap((value) => [
1568
1843
  value.length > 0
1569
1844
  ? value.reduce(({ currentSubListResource, listResource }, item, itemIndex, list) => {
1570
1845
  if (itemIndex === 0) {
1571
1846
  currentSubListResource = listResource;
1572
1847
  }
1573
1848
  else {
1574
- const newSubListResource = resourceSet.mutableResource(dataFactory.blankNode(), { mutateGraph });
1575
- currentSubListResource.add($RdfVocabularies.rdf.rest, newSubListResource.identifier);
1849
+ const newSubListResource = resourceSet.resource(dataFactory.blankNode());
1850
+ currentSubListResource.add($RdfVocabularies.rdf.rest, newSubListResource.identifier, options?.graph);
1576
1851
  currentSubListResource = newSubListResource;
1577
1852
  }
1578
- currentSubListResource.add($RdfVocabularies.rdf.first, ...[item]);
1853
+ currentSubListResource.add($RdfVocabularies.rdf.first, [item], options?.graph);
1579
1854
  if (itemIndex + 1 === list.length) {
1580
- currentSubListResource.add($RdfVocabularies.rdf.rest, $RdfVocabularies.rdf.nil);
1855
+ currentSubListResource.add($RdfVocabularies.rdf.rest, $RdfVocabularies.rdf.nil, options?.graph);
1581
1856
  }
1582
1857
  return { currentSubListResource, listResource };
1583
1858
  }, {
1584
1859
  currentSubListResource: null,
1585
- listResource: resourceSet.mutableResource(dataFactory.blankNode(), { mutateGraph }),
1860
+ listResource: resourceSet.resource(dataFactory.blankNode()),
1586
1861
  }).listResource.identifier
1587
1862
  : $RdfVocabularies.rdf.nil,
1588
- ]));
1589
- resource.add(ShaclCoreNodeShape.$properties.properties["identifier"], ..._shaclCoreNodeShape.properties.flatMap((item) => [item]));
1863
+ ]), options?.graph);
1864
+ resource.add(dataFactory.namedNode("http://www.w3.org/ns/shacl#property"), _shaclCoreNodeShape.properties.flatMap((item) => [item]), options?.graph);
1590
1865
  return resource;
1591
1866
  }
1592
1867
  ShaclCoreNodeShape.$toRdf = $toRdf;
1593
- ShaclCoreNodeShape.$properties = {
1594
- ...BaseShaclCoreShapeStatic.$properties,
1595
- closed: {
1596
- identifier: dataFactory.namedNode("http://www.w3.org/ns/shacl#closed"),
1597
- },
1598
- ignoredProperties: {
1599
- identifier: dataFactory.namedNode("http://www.w3.org/ns/shacl#ignoredProperties"),
1600
- },
1868
+ ShaclCoreNodeShape.$schema = {
1601
1869
  properties: {
1602
- identifier: dataFactory.namedNode("http://www.w3.org/ns/shacl#property"),
1870
+ ...BaseShaclCoreShapeStatic.$schema.properties,
1871
+ closed: {
1872
+ kind: "Shacl",
1873
+ type: () => ({
1874
+ kind: "Maybe",
1875
+ item: () => ({ kind: "Boolean" }),
1876
+ }),
1877
+ path: dataFactory.namedNode("http://www.w3.org/ns/shacl#closed"),
1878
+ },
1879
+ ignoredProperties: {
1880
+ kind: "Shacl",
1881
+ type: () => ({
1882
+ kind: "Maybe",
1883
+ item: () => ({
1884
+ kind: "List",
1885
+ item: () => ({ kind: "Iri" }),
1886
+ }),
1887
+ }),
1888
+ path: dataFactory.namedNode("http://www.w3.org/ns/shacl#ignoredProperties"),
1889
+ },
1890
+ properties: {
1891
+ kind: "Shacl",
1892
+ type: () => ({
1893
+ kind: "Set",
1894
+ item: () => ({ kind: "Identifier" }),
1895
+ }),
1896
+ path: dataFactory.namedNode("http://www.w3.org/ns/shacl#property"),
1897
+ },
1603
1898
  },
1604
1899
  };
1605
1900
  })(ShaclCoreNodeShape || (ShaclCoreNodeShape = {}));
1606
1901
  export var OwlOntology;
1607
1902
  (function (OwlOntology) {
1903
+ function $filter(filter, value) {
1904
+ if (filter.$identifier !== undefined &&
1905
+ !$filterIdentifier(filter.$identifier, value.$identifier)) {
1906
+ return false;
1907
+ }
1908
+ if (filter.labels !== undefined &&
1909
+ !$filterArray($filterString)(filter.labels, value.labels)) {
1910
+ return false;
1911
+ }
1912
+ return true;
1913
+ }
1914
+ OwlOntology.$filter = $filter;
1608
1915
  OwlOntology.$fromRdfType = dataFactory.namedNode("http://www.w3.org/2002/07/owl#Ontology");
1609
1916
  let $Identifier;
1610
1917
  (function ($Identifier) {
1611
- function fromString(identifier) {
1612
- return purify.Either.encase(() => rdfjsResource.Resource.Identifier.fromString({
1613
- dataFactory,
1614
- identifier,
1615
- }));
1616
- }
1617
- $Identifier.fromString = fromString;
1618
- $Identifier.toString = rdfjsResource.Resource.Identifier.toString;
1918
+ $Identifier.fromString = $identifierFromString; // biome-ignore lint/suspicious/noShadowRestrictedNames: allow toString
1919
+ $Identifier.toString = Resource.Identifier.toString;
1619
1920
  })($Identifier = OwlOntology.$Identifier || (OwlOntology.$Identifier = {}));
1921
+ function isOwlOntology(object) {
1922
+ switch (object.$type) {
1923
+ case "OwlOntology":
1924
+ return true;
1925
+ default:
1926
+ return false;
1927
+ }
1928
+ }
1929
+ OwlOntology.isOwlOntology = isOwlOntology;
1620
1930
  function $fromRdf(resource, options) {
1621
- let { ignoreRdfType = false, objectSet, preferredLanguages, ...context } = options ?? {};
1931
+ let { context, ignoreRdfType = false, objectSet, preferredLanguages, } = options ?? {};
1622
1932
  if (!objectSet) {
1623
- objectSet = new $RdfjsDatasetObjectSet({ dataset: resource.dataset });
1933
+ objectSet = new $RdfjsDatasetObjectSet(resource.dataset);
1624
1934
  }
1625
1935
  return OwlOntology.$propertiesFromRdf({
1626
- ...context,
1936
+ context,
1627
1937
  ignoreRdfType,
1628
1938
  objectSet,
1629
1939
  preferredLanguages,
@@ -1631,102 +1941,343 @@ export var OwlOntology;
1631
1941
  });
1632
1942
  }
1633
1943
  OwlOntology.$fromRdf = $fromRdf;
1634
- function $propertiesFromRdf({ ignoreRdfType: $ignoreRdfType, objectSet: $objectSet, preferredLanguages: $preferredLanguages, resource: $resource,
1635
- // @ts-ignore
1636
- ...$context }) {
1637
- if (!$ignoreRdfType) {
1638
- const $rdfTypeCheck = $resource
1639
- .value($RdfVocabularies.rdf.type)
1944
+ function $propertiesFromRdf($parameters) {
1945
+ return (!$parameters.ignoreRdfType
1946
+ ? $parameters.resource
1947
+ .value($RdfVocabularies.rdf.type, { graph: $parameters.graph })
1640
1948
  .chain((actualRdfType) => actualRdfType.toIri())
1641
1949
  .chain((actualRdfType) => {
1642
1950
  // Check the expected type and its known subtypes
1643
1951
  switch (actualRdfType.value) {
1644
1952
  case "http://www.w3.org/2002/07/owl#Ontology":
1645
- return purify.Either.of(true);
1953
+ return Right(true);
1646
1954
  }
1647
1955
  // Check arbitrary rdfs:subClassOf's of the expected type
1648
- if ($resource.isInstanceOf(OwlOntology.$fromRdfType)) {
1649
- return purify.Either.of(true);
1650
- }
1651
- return purify.Left(new Error(`${rdfjsResource.Resource.Identifier.toString($resource.identifier)} has unexpected RDF type (actual: ${actualRdfType.value}, expected: http://www.w3.org/2002/07/owl#Ontology)`));
1652
- });
1653
- if ($rdfTypeCheck.isLeft()) {
1654
- return $rdfTypeCheck;
1655
- }
1656
- }
1657
- const $identifier = $resource.identifier;
1658
- const $type = "OwlOntology";
1659
- const _labelsEither = purify.Either.of($resource.values(OwlOntology.$properties.labels["identifier"], { unique: true }))
1660
- .chain((values) => {
1661
- if (!$preferredLanguages || $preferredLanguages.length === 0) {
1662
- return purify.Either.of(values);
1663
- }
1664
- const literalValuesEither = values.chainMap((value) => value.toLiteral());
1665
- if (literalValuesEither.isLeft()) {
1666
- return literalValuesEither;
1667
- }
1668
- const literalValues = literalValuesEither.unsafeCoerce();
1669
- // Return all literals for the first preferredLanguage, then all literals for the second preferredLanguage, etc.
1670
- // Within a preferredLanguage the literals may be in any order.
1671
- let filteredLiteralValues;
1672
- for (const preferredLanguage of $preferredLanguages) {
1673
- if (!filteredLiteralValues) {
1674
- filteredLiteralValues = literalValues.filter((value) => value.language === preferredLanguage);
1675
- }
1676
- else {
1677
- filteredLiteralValues = filteredLiteralValues.concat(...literalValues
1678
- .filter((value) => value.language === preferredLanguage)
1679
- .toArray());
1956
+ if ($parameters.resource.isInstanceOf(OwlOntology.$fromRdfType, {
1957
+ graph: $parameters.graph,
1958
+ })) {
1959
+ return Right(true);
1680
1960
  }
1681
- }
1682
- return purify.Either.of(filteredLiteralValues.map((literalValue) => new rdfjsResource.Resource.Value({
1683
- object: literalValue,
1684
- predicate: OwlOntology.$properties.labels["identifier"],
1685
- subject: $resource,
1686
- })));
1687
- })
1688
- .chain((values) => values.chainMap((value) => value.toLiteral()))
1689
- .map((values) => values.toArray())
1690
- .map((valuesArray) => rdfjsResource.Resource.Values.fromValue({
1691
- object: valuesArray,
1692
- predicate: OwlOntology.$properties.labels["identifier"],
1693
- subject: $resource,
1694
- }))
1695
- .chain((values) => values.head());
1696
- if (_labelsEither.isLeft()) {
1697
- return _labelsEither;
1698
- }
1699
- const labels = _labelsEither.unsafeCoerce();
1700
- return purify.Either.of({ $identifier, $type, labels });
1961
+ return Left(new Error(`${Resource.Identifier.toString($parameters.resource.identifier)} has unexpected RDF type (actual: ${actualRdfType.value}, expected: http://www.w3.org/2002/07/owl#Ontology)`));
1962
+ })
1963
+ : Right(true)).chain((_rdfTypeCheck) => Right(new Resource.Value({
1964
+ dataFactory: dataFactory,
1965
+ focusResource: $parameters.resource,
1966
+ propertyPath: $RdfVocabularies.rdf.subject,
1967
+ term: $parameters.resource.identifier,
1968
+ }).toValues())
1969
+ .chain((values) => values.chainMap((value) => value.toIdentifier()))
1970
+ .chain((values) => values.head())
1971
+ .chain(($identifier) => Right("OwlOntology").chain(($type) => $shaclPropertyFromRdf({
1972
+ graph: $parameters.graph,
1973
+ resource: $parameters.resource,
1974
+ propertySchema: OwlOntology.$schema.properties.labels,
1975
+ typeFromRdf: (resourceValues) => resourceValues
1976
+ .chain((values) => $fromRdfPreferredLanguages(values, $parameters.preferredLanguages))
1977
+ .chain((values) => values.chainMap((value) => value.toString()))
1978
+ .map((values) => values.toArray())
1979
+ .map((valuesArray) => Resource.Values.fromValue({
1980
+ focusResource: $parameters.resource,
1981
+ propertyPath: OwlOntology.$schema.properties.labels.path,
1982
+ value: valuesArray,
1983
+ })),
1984
+ }).map((labels) => ({ $identifier, $type, labels })))));
1701
1985
  }
1702
1986
  OwlOntology.$propertiesFromRdf = $propertiesFromRdf;
1703
1987
  function $toRdf(_owlOntology, options) {
1704
- const ignoreRdfType = !!options?.ignoreRdfType;
1705
- const mutateGraph = options?.mutateGraph;
1706
1988
  const resourceSet = options?.resourceSet ??
1707
- new rdfjsResource.MutableResourceSet({
1708
- dataFactory,
1709
- dataset: datasetFactory.dataset(),
1710
- });
1711
- const resource = resourceSet.mutableResource(_owlOntology.$identifier, {
1712
- mutateGraph,
1713
- });
1714
- if (!ignoreRdfType) {
1715
- resource.add($RdfVocabularies.rdf.type, resource.dataFactory.namedNode("http://purl.org/shaclmate/ontology#OwlOntology"));
1716
- resource.add($RdfVocabularies.rdf.type, resource.dataFactory.namedNode("http://www.w3.org/2002/07/owl#Ontology"));
1989
+ new ResourceSet(datasetFactory.dataset(), { dataFactory: dataFactory });
1990
+ const resource = resourceSet.resource(_owlOntology.$identifier);
1991
+ if (!options?.ignoreRdfType) {
1992
+ resource.add($RdfVocabularies.rdf.type, dataFactory.namedNode("http://www.w3.org/2002/07/owl#Ontology"), options?.graph);
1717
1993
  }
1718
- resource.add(OwlOntology.$properties.labels["identifier"], ..._owlOntology.labels.flatMap((item) => [item]));
1994
+ resource.add(dataFactory.namedNode("http://www.w3.org/2000/01/rdf-schema#label"), _owlOntology.labels.flatMap((item) => [$literalFactory.string(item)]), options?.graph);
1719
1995
  return resource;
1720
1996
  }
1721
1997
  OwlOntology.$toRdf = $toRdf;
1722
- OwlOntology.$properties = {
1723
- labels: {
1724
- identifier: dataFactory.namedNode("http://www.w3.org/2000/01/rdf-schema#label"),
1998
+ OwlOntology.$schema = {
1999
+ properties: {
2000
+ $identifier: {
2001
+ kind: "Identifier",
2002
+ type: () => ({ kind: "Identifier" }),
2003
+ },
2004
+ $type: {
2005
+ kind: "TypeDiscriminant",
2006
+ type: () => ({
2007
+ kind: "TypeDiscriminant",
2008
+ ownValues: ["OwlOntology"],
2009
+ }),
2010
+ },
2011
+ labels: {
2012
+ kind: "Shacl",
2013
+ type: () => ({
2014
+ kind: "Set",
2015
+ item: () => ({ kind: "String" }),
2016
+ }),
2017
+ path: dataFactory.namedNode("http://www.w3.org/2000/01/rdf-schema#label"),
2018
+ },
1725
2019
  },
1726
2020
  };
1727
2021
  })(OwlOntology || (OwlOntology = {}));
1728
2022
  export var ShaclCoreShape;
1729
2023
  (function (ShaclCoreShape) {
2024
+ function $filter(filter, value) {
2025
+ if (filter.$identifier !== undefined &&
2026
+ !$filterIdentifier(filter.$identifier, value.$identifier)) {
2027
+ return false;
2028
+ }
2029
+ if (ShaclCoreNodeShape.isShaclCoreNodeShape(value) &&
2030
+ filter.on?.ShaclCoreNodeShape &&
2031
+ !ShaclCoreNodeShape.$filter(filter.on.ShaclCoreNodeShape, value)) {
2032
+ return false;
2033
+ }
2034
+ if (ShaclCorePropertyShape.isShaclCorePropertyShape(value) &&
2035
+ filter.on?.ShaclCorePropertyShape &&
2036
+ !ShaclCorePropertyShape.$filter(filter.on.ShaclCorePropertyShape, value)) {
2037
+ return false;
2038
+ }
2039
+ return true;
2040
+ }
2041
+ ShaclCoreShape.$filter = $filter;
2042
+ let $Identifier;
2043
+ (function ($Identifier) {
2044
+ $Identifier.fromString = $identifierFromString; // biome-ignore lint/suspicious/noShadowRestrictedNames: allow toString
2045
+ $Identifier.toString = Resource.Identifier.toString;
2046
+ })($Identifier = ShaclCoreShape.$Identifier || (ShaclCoreShape.$Identifier = {}));
2047
+ function isShaclCoreShape(object) {
2048
+ return (ShaclCoreNodeShape.isShaclCoreNodeShape(object) ||
2049
+ ShaclCorePropertyShape.isShaclCorePropertyShape(object));
2050
+ }
2051
+ ShaclCoreShape.isShaclCoreShape = isShaclCoreShape;
2052
+ ShaclCoreShape.$schema = {
2053
+ properties: {
2054
+ and: {
2055
+ kind: "Shacl",
2056
+ type: () => ({
2057
+ kind: "Set",
2058
+ item: () => ({
2059
+ kind: "List",
2060
+ item: () => ({ kind: "Identifier" }),
2061
+ }),
2062
+ }),
2063
+ path: dataFactory.namedNode("http://www.w3.org/ns/shacl#and"),
2064
+ },
2065
+ classes: {
2066
+ kind: "Shacl",
2067
+ type: () => ({
2068
+ kind: "Set",
2069
+ item: () => ({ kind: "Iri" }),
2070
+ }),
2071
+ path: dataFactory.namedNode("http://www.w3.org/ns/shacl#class"),
2072
+ },
2073
+ comments: {
2074
+ kind: "Shacl",
2075
+ type: () => ({
2076
+ kind: "Set",
2077
+ item: () => ({ kind: "String" }),
2078
+ }),
2079
+ path: dataFactory.namedNode("http://www.w3.org/2000/01/rdf-schema#comment"),
2080
+ },
2081
+ datatype: {
2082
+ kind: "Shacl",
2083
+ type: () => ({
2084
+ kind: "Maybe",
2085
+ item: () => ({ kind: "Iri" }),
2086
+ }),
2087
+ path: dataFactory.namedNode("http://www.w3.org/ns/shacl#datatype"),
2088
+ },
2089
+ deactivated: {
2090
+ kind: "Shacl",
2091
+ type: () => ({
2092
+ kind: "Maybe",
2093
+ item: () => ({ kind: "Boolean" }),
2094
+ }),
2095
+ path: dataFactory.namedNode("http://www.w3.org/ns/shacl#deactivated"),
2096
+ },
2097
+ flags: {
2098
+ kind: "Shacl",
2099
+ type: () => ({
2100
+ kind: "Set",
2101
+ item: () => ({ kind: "String" }),
2102
+ }),
2103
+ path: dataFactory.namedNode("http://www.w3.org/ns/shacl#flags"),
2104
+ },
2105
+ hasValues: {
2106
+ kind: "Shacl",
2107
+ type: () => ({
2108
+ kind: "Set",
2109
+ item: () => ({ kind: "Term" }),
2110
+ }),
2111
+ path: dataFactory.namedNode("http://www.w3.org/ns/shacl#hasValue"),
2112
+ },
2113
+ in_: {
2114
+ kind: "Shacl",
2115
+ type: () => ({
2116
+ kind: "Maybe",
2117
+ item: () => ({
2118
+ kind: "List",
2119
+ item: () => ({ kind: "Term" }),
2120
+ }),
2121
+ }),
2122
+ path: dataFactory.namedNode("http://www.w3.org/ns/shacl#in"),
2123
+ },
2124
+ isDefinedBy: {
2125
+ kind: "Shacl",
2126
+ type: () => ({
2127
+ kind: "Maybe",
2128
+ item: () => ({ kind: "Identifier" }),
2129
+ }),
2130
+ path: dataFactory.namedNode("http://www.w3.org/2000/01/rdf-schema#isDefinedBy"),
2131
+ },
2132
+ labels: {
2133
+ kind: "Shacl",
2134
+ type: () => ({
2135
+ kind: "Set",
2136
+ item: () => ({ kind: "String" }),
2137
+ }),
2138
+ path: dataFactory.namedNode("http://www.w3.org/2000/01/rdf-schema#label"),
2139
+ },
2140
+ languageIn: {
2141
+ kind: "Shacl",
2142
+ type: () => ({
2143
+ kind: "Maybe",
2144
+ item: () => ({
2145
+ kind: "List",
2146
+ item: () => ({ kind: "String" }),
2147
+ }),
2148
+ }),
2149
+ path: dataFactory.namedNode("http://www.w3.org/ns/shacl#languageIn"),
2150
+ },
2151
+ maxCount: {
2152
+ kind: "Shacl",
2153
+ type: () => ({
2154
+ kind: "Maybe",
2155
+ item: () => ({ kind: "Int" }),
2156
+ }),
2157
+ path: dataFactory.namedNode("http://www.w3.org/ns/shacl#maxCount"),
2158
+ },
2159
+ maxExclusive: {
2160
+ kind: "Shacl",
2161
+ type: () => ({
2162
+ kind: "Maybe",
2163
+ item: () => ({ kind: "Literal" }),
2164
+ }),
2165
+ path: dataFactory.namedNode("http://www.w3.org/ns/shacl#maxExclusive"),
2166
+ },
2167
+ maxInclusive: {
2168
+ kind: "Shacl",
2169
+ type: () => ({
2170
+ kind: "Maybe",
2171
+ item: () => ({ kind: "Literal" }),
2172
+ }),
2173
+ path: dataFactory.namedNode("http://www.w3.org/ns/shacl#maxInclusive"),
2174
+ },
2175
+ maxLength: {
2176
+ kind: "Shacl",
2177
+ type: () => ({
2178
+ kind: "Maybe",
2179
+ item: () => ({ kind: "Int" }),
2180
+ }),
2181
+ path: dataFactory.namedNode("http://www.w3.org/ns/shacl#maxLength"),
2182
+ },
2183
+ minCount: {
2184
+ kind: "Shacl",
2185
+ type: () => ({
2186
+ kind: "Maybe",
2187
+ item: () => ({ kind: "Int" }),
2188
+ }),
2189
+ path: dataFactory.namedNode("http://www.w3.org/ns/shacl#minCount"),
2190
+ },
2191
+ minExclusive: {
2192
+ kind: "Shacl",
2193
+ type: () => ({
2194
+ kind: "Maybe",
2195
+ item: () => ({ kind: "Literal" }),
2196
+ }),
2197
+ path: dataFactory.namedNode("http://www.w3.org/ns/shacl#minExclusive"),
2198
+ },
2199
+ minInclusive: {
2200
+ kind: "Shacl",
2201
+ type: () => ({
2202
+ kind: "Maybe",
2203
+ item: () => ({ kind: "Literal" }),
2204
+ }),
2205
+ path: dataFactory.namedNode("http://www.w3.org/ns/shacl#minInclusive"),
2206
+ },
2207
+ minLength: {
2208
+ kind: "Shacl",
2209
+ type: () => ({
2210
+ kind: "Maybe",
2211
+ item: () => ({ kind: "Int" }),
2212
+ }),
2213
+ path: dataFactory.namedNode("http://www.w3.org/ns/shacl#minLength"),
2214
+ },
2215
+ nodeKind: {
2216
+ kind: "Shacl",
2217
+ type: () => ({
2218
+ kind: "Maybe",
2219
+ item: () => ({
2220
+ kind: "Iri",
2221
+ in: [
2222
+ dataFactory.namedNode("http://www.w3.org/ns/shacl#BlankNode"),
2223
+ dataFactory.namedNode("http://www.w3.org/ns/shacl#BlankNodeOrIRI"),
2224
+ dataFactory.namedNode("http://www.w3.org/ns/shacl#BlankNodeOrLiteral"),
2225
+ dataFactory.namedNode("http://www.w3.org/ns/shacl#IRI"),
2226
+ dataFactory.namedNode("http://www.w3.org/ns/shacl#IRIOrLiteral"),
2227
+ dataFactory.namedNode("http://www.w3.org/ns/shacl#Literal"),
2228
+ ],
2229
+ }),
2230
+ }),
2231
+ path: dataFactory.namedNode("http://www.w3.org/ns/shacl#nodeKind"),
2232
+ },
2233
+ nodes: {
2234
+ kind: "Shacl",
2235
+ type: () => ({
2236
+ kind: "Set",
2237
+ item: () => ({ kind: "Identifier" }),
2238
+ }),
2239
+ path: dataFactory.namedNode("http://www.w3.org/ns/shacl#node"),
2240
+ },
2241
+ not: {
2242
+ kind: "Shacl",
2243
+ type: () => ({
2244
+ kind: "Set",
2245
+ item: () => ({ kind: "Identifier" }),
2246
+ }),
2247
+ path: dataFactory.namedNode("http://www.w3.org/ns/shacl#not"),
2248
+ },
2249
+ or: {
2250
+ kind: "Shacl",
2251
+ type: () => ({
2252
+ kind: "Set",
2253
+ item: () => ({
2254
+ kind: "List",
2255
+ item: () => ({ kind: "Identifier" }),
2256
+ }),
2257
+ }),
2258
+ path: dataFactory.namedNode("http://www.w3.org/ns/shacl#or"),
2259
+ },
2260
+ patterns: {
2261
+ kind: "Shacl",
2262
+ type: () => ({
2263
+ kind: "Set",
2264
+ item: () => ({ kind: "String" }),
2265
+ }),
2266
+ path: dataFactory.namedNode("http://www.w3.org/ns/shacl#pattern"),
2267
+ },
2268
+ xone: {
2269
+ kind: "Shacl",
2270
+ type: () => ({
2271
+ kind: "Set",
2272
+ item: () => ({
2273
+ kind: "List",
2274
+ item: () => ({ kind: "Identifier" }),
2275
+ }),
2276
+ }),
2277
+ path: dataFactory.namedNode("http://www.w3.org/ns/shacl#xone"),
2278
+ },
2279
+ },
2280
+ };
1730
2281
  function $fromRdf(resource, options) {
1731
2282
  return ShaclCoreNodeShape.$fromRdf(resource, {
1732
2283
  ...options,
@@ -1737,128 +2288,145 @@ export var ShaclCoreShape;
1737
2288
  }));
1738
2289
  }
1739
2290
  ShaclCoreShape.$fromRdf = $fromRdf;
1740
- let $Identifier;
1741
- (function ($Identifier) {
1742
- function fromString(identifier) {
1743
- return purify.Either.encase(() => rdfjsResource.Resource.Identifier.fromString({
1744
- dataFactory,
1745
- identifier,
1746
- }));
1747
- }
1748
- $Identifier.fromString = fromString;
1749
- $Identifier.toString = rdfjsResource.Resource.Identifier.toString;
1750
- })($Identifier = ShaclCoreShape.$Identifier || (ShaclCoreShape.$Identifier = {}));
1751
2291
  function $toRdf(_shaclCoreShape, _parameters) {
1752
- switch (_shaclCoreShape.$type) {
1753
- case "ShaclCoreNodeShape":
1754
- return ShaclCoreNodeShape.$toRdf(_shaclCoreShape, _parameters);
1755
- case "ShaclCorePropertyShape":
1756
- return ShaclCorePropertyShape.$toRdf(_shaclCoreShape, _parameters);
1757
- default:
1758
- _shaclCoreShape;
1759
- throw new Error("unrecognized type");
2292
+ if (ShaclCoreNodeShape.isShaclCoreNodeShape(_shaclCoreShape)) {
2293
+ return ShaclCoreNodeShape.$toRdf(_shaclCoreShape, _parameters);
1760
2294
  }
2295
+ if (ShaclCorePropertyShape.isShaclCorePropertyShape(_shaclCoreShape)) {
2296
+ return ShaclCorePropertyShape.$toRdf(_shaclCoreShape, _parameters);
2297
+ }
2298
+ throw new Error("unrecognized type");
1761
2299
  }
1762
2300
  ShaclCoreShape.$toRdf = $toRdf;
1763
2301
  })(ShaclCoreShape || (ShaclCoreShape = {}));
1764
- export class $ForwardingObjectSet {
1765
- owlOntology(identifier) {
1766
- return this.$delegate.owlOntology(identifier);
1767
- }
1768
- owlOntologyIdentifiers(query) {
1769
- return this.$delegate.owlOntologyIdentifiers(query);
1770
- }
1771
- owlOntologies(query) {
1772
- return this.$delegate.owlOntologies(query);
1773
- }
1774
- owlOntologiesCount(query) {
1775
- return this.$delegate.owlOntologiesCount(query);
1776
- }
1777
- shaclCoreNodeShape(identifier) {
1778
- return this.$delegate.shaclCoreNodeShape(identifier);
1779
- }
1780
- shaclCoreNodeShapeIdentifiers(query) {
1781
- return this.$delegate.shaclCoreNodeShapeIdentifiers(query);
1782
- }
1783
- shaclCoreNodeShapes(query) {
1784
- return this.$delegate.shaclCoreNodeShapes(query);
1785
- }
1786
- shaclCoreNodeShapesCount(query) {
1787
- return this.$delegate.shaclCoreNodeShapesCount(query);
1788
- }
1789
- shaclCorePropertyGroup(identifier) {
1790
- return this.$delegate.shaclCorePropertyGroup(identifier);
1791
- }
1792
- shaclCorePropertyGroupIdentifiers(query) {
1793
- return this.$delegate.shaclCorePropertyGroupIdentifiers(query);
1794
- }
1795
- shaclCorePropertyGroups(query) {
1796
- return this.$delegate.shaclCorePropertyGroups(query);
1797
- }
1798
- shaclCorePropertyGroupsCount(query) {
1799
- return this.$delegate.shaclCorePropertyGroupsCount(query);
1800
- }
1801
- shaclCorePropertyShape(identifier) {
1802
- return this.$delegate.shaclCorePropertyShape(identifier);
1803
- }
1804
- shaclCorePropertyShapeIdentifiers(query) {
1805
- return this.$delegate.shaclCorePropertyShapeIdentifiers(query);
1806
- }
1807
- shaclCorePropertyShapes(query) {
1808
- return this.$delegate.shaclCorePropertyShapes(query);
1809
- }
1810
- shaclCorePropertyShapesCount(query) {
1811
- return this.$delegate.shaclCorePropertyShapesCount(query);
1812
- }
1813
- shaclCoreShape(identifier) {
1814
- return this.$delegate.shaclCoreShape(identifier);
2302
+ export var $Object;
2303
+ (function ($Object) {
2304
+ function $filter(filter, value) {
2305
+ if (filter.$identifier !== undefined &&
2306
+ !$filterIdentifier(filter.$identifier, value.$identifier)) {
2307
+ return false;
2308
+ }
2309
+ if (OwlOntology.isOwlOntology(value) &&
2310
+ filter.on?.OwlOntology &&
2311
+ !OwlOntology.$filter(filter.on.OwlOntology, value)) {
2312
+ return false;
2313
+ }
2314
+ if (ShaclCoreNodeShape.isShaclCoreNodeShape(value) &&
2315
+ filter.on?.ShaclCoreNodeShape &&
2316
+ !ShaclCoreNodeShape.$filter(filter.on.ShaclCoreNodeShape, value)) {
2317
+ return false;
2318
+ }
2319
+ if (ShaclCorePropertyGroup.isShaclCorePropertyGroup(value) &&
2320
+ filter.on?.ShaclCorePropertyGroup &&
2321
+ !ShaclCorePropertyGroup.$filter(filter.on.ShaclCorePropertyGroup, value)) {
2322
+ return false;
2323
+ }
2324
+ if (ShaclCorePropertyShape.isShaclCorePropertyShape(value) &&
2325
+ filter.on?.ShaclCorePropertyShape &&
2326
+ !ShaclCorePropertyShape.$filter(filter.on.ShaclCorePropertyShape, value)) {
2327
+ return false;
2328
+ }
2329
+ if (BaseShaclCoreShapeStatic.isBaseShaclCoreShape(value) &&
2330
+ filter.on?.BaseShaclCoreShape &&
2331
+ !BaseShaclCoreShapeStatic.$filter(filter.on.BaseShaclCoreShape, value)) {
2332
+ return false;
2333
+ }
2334
+ return true;
2335
+ }
2336
+ $Object.$filter = $filter;
2337
+ let $Identifier;
2338
+ (function ($Identifier) {
2339
+ $Identifier.fromString = $identifierFromString; // biome-ignore lint/suspicious/noShadowRestrictedNames: allow toString
2340
+ $Identifier.toString = Resource.Identifier.toString;
2341
+ })($Identifier = $Object.$Identifier || ($Object.$Identifier = {}));
2342
+ $Object.$schema = {
2343
+ properties: {
2344
+ labels: {
2345
+ kind: "Shacl",
2346
+ type: () => ({
2347
+ kind: "Set",
2348
+ item: () => ({ kind: "String" }),
2349
+ }),
2350
+ path: dataFactory.namedNode("http://www.w3.org/2000/01/rdf-schema#label"),
2351
+ },
2352
+ },
2353
+ };
2354
+ function $fromRdf(resource, options) {
2355
+ return OwlOntology.$fromRdf(resource, {
2356
+ ...options,
2357
+ ignoreRdfType: false,
2358
+ })
2359
+ .altLazy(() => ShaclCoreNodeShape.$fromRdf(resource, {
2360
+ ...options,
2361
+ ignoreRdfType: false,
2362
+ }))
2363
+ .altLazy(() => ShaclCorePropertyGroup.$fromRdf(resource, {
2364
+ ...options,
2365
+ ignoreRdfType: false,
2366
+ }))
2367
+ .altLazy(() => ShaclCorePropertyShape.$fromRdf(resource, {
2368
+ ...options,
2369
+ ignoreRdfType: false,
2370
+ }));
1815
2371
  }
1816
- shaclCoreShapeIdentifiers(query) {
1817
- return this.$delegate.shaclCoreShapeIdentifiers(query);
2372
+ $Object.$fromRdf = $fromRdf;
2373
+ function $toRdf(_object, _parameters) {
2374
+ if (OwlOntology.isOwlOntology(_object)) {
2375
+ return OwlOntology.$toRdf(_object, _parameters);
2376
+ }
2377
+ if (ShaclCoreNodeShape.isShaclCoreNodeShape(_object)) {
2378
+ return ShaclCoreNodeShape.$toRdf(_object, _parameters);
2379
+ }
2380
+ if (ShaclCorePropertyGroup.isShaclCorePropertyGroup(_object)) {
2381
+ return ShaclCorePropertyGroup.$toRdf(_object, _parameters);
2382
+ }
2383
+ if (ShaclCorePropertyShape.isShaclCorePropertyShape(_object)) {
2384
+ return ShaclCorePropertyShape.$toRdf(_object, _parameters);
2385
+ }
2386
+ throw new Error("unrecognized type");
1818
2387
  }
1819
- shaclCoreShapes(query) {
1820
- return this.$delegate.shaclCoreShapes(query);
2388
+ $Object.$toRdf = $toRdf;
2389
+ })($Object || ($Object = {}));
2390
+ export class $RdfjsDatasetObjectSet {
2391
+ $graph;
2392
+ #dataset;
2393
+ constructor(dataset, options) {
2394
+ this.#dataset = dataset;
2395
+ this.$graph = options?.graph;
1821
2396
  }
1822
- shaclCoreShapesCount(query) {
1823
- return this.$delegate.shaclCoreShapesCount(query);
2397
+ $dataset() {
2398
+ if (typeof this.#dataset === "object") {
2399
+ return this.#dataset;
2400
+ }
2401
+ return this.#dataset();
1824
2402
  }
1825
- }
1826
- export class $RdfjsDatasetObjectSet {
1827
- resourceSet;
1828
- constructor({ dataset }) {
1829
- this.resourceSet = new rdfjsResource.ResourceSet({ dataset });
2403
+ $resourceSet() {
2404
+ return new ResourceSet(this.$dataset(), { dataFactory: dataFactory });
1830
2405
  }
1831
2406
  async owlOntology(identifier) {
1832
2407
  return this.owlOntologySync(identifier);
1833
2408
  }
1834
2409
  owlOntologySync(identifier) {
1835
- return this.owlOntologiesSync({
1836
- where: { identifiers: [identifier], type: "identifiers" },
1837
- }).map((objects) => objects[0]);
2410
+ return this.owlOntologiesSync({ identifiers: [identifier] }).map((objects) => objects[0]);
2411
+ }
2412
+ async owlOntologyCount(query) {
2413
+ return this.owlOntologyCountSync(query);
2414
+ }
2415
+ owlOntologyCountSync(query) {
2416
+ return this.owlOntologiesSync(query).map((objects) => objects.length);
1838
2417
  }
1839
2418
  async owlOntologyIdentifiers(query) {
1840
2419
  return this.owlOntologyIdentifiersSync(query);
1841
2420
  }
1842
2421
  owlOntologyIdentifiersSync(query) {
1843
- return this.$objectIdentifiersSync({
1844
- $fromRdf: OwlOntology.$fromRdf,
1845
- $fromRdfTypes: [OwlOntology.$fromRdfType],
1846
- }, query);
2422
+ return this.owlOntologiesSync(query).map((objects) => objects.map((object) => object.$identifier));
1847
2423
  }
1848
2424
  async owlOntologies(query) {
1849
2425
  return this.owlOntologiesSync(query);
1850
2426
  }
1851
2427
  owlOntologiesSync(query) {
1852
2428
  return this.$objectsSync({
1853
- $fromRdf: OwlOntology.$fromRdf,
1854
- $fromRdfTypes: [OwlOntology.$fromRdfType],
1855
- }, query);
1856
- }
1857
- async owlOntologiesCount(query) {
1858
- return this.owlOntologiesCountSync(query);
1859
- }
1860
- owlOntologiesCountSync(query) {
1861
- return this.$objectsCountSync({
2429
+ $filter: OwlOntology.$filter,
1862
2430
  $fromRdf: OwlOntology.$fromRdf,
1863
2431
  $fromRdfTypes: [OwlOntology.$fromRdfType],
1864
2432
  }, query);
@@ -1867,33 +2435,26 @@ export class $RdfjsDatasetObjectSet {
1867
2435
  return this.shaclCoreNodeShapeSync(identifier);
1868
2436
  }
1869
2437
  shaclCoreNodeShapeSync(identifier) {
1870
- return this.shaclCoreNodeShapesSync({
1871
- where: { identifiers: [identifier], type: "identifiers" },
1872
- }).map((objects) => objects[0]);
2438
+ return this.shaclCoreNodeShapesSync({ identifiers: [identifier] }).map((objects) => objects[0]);
2439
+ }
2440
+ async shaclCoreNodeShapeCount(query) {
2441
+ return this.shaclCoreNodeShapeCountSync(query);
2442
+ }
2443
+ shaclCoreNodeShapeCountSync(query) {
2444
+ return this.shaclCoreNodeShapesSync(query).map((objects) => objects.length);
1873
2445
  }
1874
2446
  async shaclCoreNodeShapeIdentifiers(query) {
1875
2447
  return this.shaclCoreNodeShapeIdentifiersSync(query);
1876
2448
  }
1877
2449
  shaclCoreNodeShapeIdentifiersSync(query) {
1878
- return this.$objectIdentifiersSync({
1879
- $fromRdf: ShaclCoreNodeShape.$fromRdf,
1880
- $fromRdfTypes: [ShaclCoreNodeShape.$fromRdfType],
1881
- }, query);
2450
+ return this.shaclCoreNodeShapesSync(query).map((objects) => objects.map((object) => object.$identifier));
1882
2451
  }
1883
2452
  async shaclCoreNodeShapes(query) {
1884
2453
  return this.shaclCoreNodeShapesSync(query);
1885
2454
  }
1886
2455
  shaclCoreNodeShapesSync(query) {
1887
2456
  return this.$objectsSync({
1888
- $fromRdf: ShaclCoreNodeShape.$fromRdf,
1889
- $fromRdfTypes: [ShaclCoreNodeShape.$fromRdfType],
1890
- }, query);
1891
- }
1892
- async shaclCoreNodeShapesCount(query) {
1893
- return this.shaclCoreNodeShapesCountSync(query);
1894
- }
1895
- shaclCoreNodeShapesCountSync(query) {
1896
- return this.$objectsCountSync({
2457
+ $filter: ShaclCoreNodeShape.$filter,
1897
2458
  $fromRdf: ShaclCoreNodeShape.$fromRdf,
1898
2459
  $fromRdfTypes: [ShaclCoreNodeShape.$fromRdfType],
1899
2460
  }, query);
@@ -1902,33 +2463,26 @@ export class $RdfjsDatasetObjectSet {
1902
2463
  return this.shaclCorePropertyGroupSync(identifier);
1903
2464
  }
1904
2465
  shaclCorePropertyGroupSync(identifier) {
1905
- return this.shaclCorePropertyGroupsSync({
1906
- where: { identifiers: [identifier], type: "identifiers" },
1907
- }).map((objects) => objects[0]);
2466
+ return this.shaclCorePropertyGroupsSync({ identifiers: [identifier] }).map((objects) => objects[0]);
2467
+ }
2468
+ async shaclCorePropertyGroupCount(query) {
2469
+ return this.shaclCorePropertyGroupCountSync(query);
2470
+ }
2471
+ shaclCorePropertyGroupCountSync(query) {
2472
+ return this.shaclCorePropertyGroupsSync(query).map((objects) => objects.length);
1908
2473
  }
1909
2474
  async shaclCorePropertyGroupIdentifiers(query) {
1910
2475
  return this.shaclCorePropertyGroupIdentifiersSync(query);
1911
2476
  }
1912
2477
  shaclCorePropertyGroupIdentifiersSync(query) {
1913
- return this.$objectIdentifiersSync({
1914
- $fromRdf: ShaclCorePropertyGroup.$fromRdf,
1915
- $fromRdfTypes: [ShaclCorePropertyGroup.$fromRdfType],
1916
- }, query);
2478
+ return this.shaclCorePropertyGroupsSync(query).map((objects) => objects.map((object) => object.$identifier));
1917
2479
  }
1918
2480
  async shaclCorePropertyGroups(query) {
1919
2481
  return this.shaclCorePropertyGroupsSync(query);
1920
2482
  }
1921
2483
  shaclCorePropertyGroupsSync(query) {
1922
2484
  return this.$objectsSync({
1923
- $fromRdf: ShaclCorePropertyGroup.$fromRdf,
1924
- $fromRdfTypes: [ShaclCorePropertyGroup.$fromRdfType],
1925
- }, query);
1926
- }
1927
- async shaclCorePropertyGroupsCount(query) {
1928
- return this.shaclCorePropertyGroupsCountSync(query);
1929
- }
1930
- shaclCorePropertyGroupsCountSync(query) {
1931
- return this.$objectsCountSync({
2485
+ $filter: ShaclCorePropertyGroup.$filter,
1932
2486
  $fromRdf: ShaclCorePropertyGroup.$fromRdf,
1933
2487
  $fromRdfTypes: [ShaclCorePropertyGroup.$fromRdfType],
1934
2488
  }, query);
@@ -1937,33 +2491,26 @@ export class $RdfjsDatasetObjectSet {
1937
2491
  return this.shaclCorePropertyShapeSync(identifier);
1938
2492
  }
1939
2493
  shaclCorePropertyShapeSync(identifier) {
1940
- return this.shaclCorePropertyShapesSync({
1941
- where: { identifiers: [identifier], type: "identifiers" },
1942
- }).map((objects) => objects[0]);
2494
+ return this.shaclCorePropertyShapesSync({ identifiers: [identifier] }).map((objects) => objects[0]);
2495
+ }
2496
+ async shaclCorePropertyShapeCount(query) {
2497
+ return this.shaclCorePropertyShapeCountSync(query);
2498
+ }
2499
+ shaclCorePropertyShapeCountSync(query) {
2500
+ return this.shaclCorePropertyShapesSync(query).map((objects) => objects.length);
1943
2501
  }
1944
2502
  async shaclCorePropertyShapeIdentifiers(query) {
1945
2503
  return this.shaclCorePropertyShapeIdentifiersSync(query);
1946
2504
  }
1947
2505
  shaclCorePropertyShapeIdentifiersSync(query) {
1948
- return this.$objectIdentifiersSync({
1949
- $fromRdf: ShaclCorePropertyShape.$fromRdf,
1950
- $fromRdfTypes: [ShaclCorePropertyShape.$fromRdfType],
1951
- }, query);
2506
+ return this.shaclCorePropertyShapesSync(query).map((objects) => objects.map((object) => object.$identifier));
1952
2507
  }
1953
2508
  async shaclCorePropertyShapes(query) {
1954
2509
  return this.shaclCorePropertyShapesSync(query);
1955
2510
  }
1956
2511
  shaclCorePropertyShapesSync(query) {
1957
2512
  return this.$objectsSync({
1958
- $fromRdf: ShaclCorePropertyShape.$fromRdf,
1959
- $fromRdfTypes: [ShaclCorePropertyShape.$fromRdfType],
1960
- }, query);
1961
- }
1962
- async shaclCorePropertyShapesCount(query) {
1963
- return this.shaclCorePropertyShapesCountSync(query);
1964
- }
1965
- shaclCorePropertyShapesCountSync(query) {
1966
- return this.$objectsCountSync({
2513
+ $filter: ShaclCorePropertyShape.$filter,
1967
2514
  $fromRdf: ShaclCorePropertyShape.$fromRdf,
1968
2515
  $fromRdfTypes: [ShaclCorePropertyShape.$fromRdfType],
1969
2516
  }, query);
@@ -1972,24 +2519,19 @@ export class $RdfjsDatasetObjectSet {
1972
2519
  return this.shaclCoreShapeSync(identifier);
1973
2520
  }
1974
2521
  shaclCoreShapeSync(identifier) {
1975
- return this.shaclCoreShapesSync({
1976
- where: { identifiers: [identifier], type: "identifiers" },
1977
- }).map((objects) => objects[0]);
2522
+ return this.shaclCoreShapesSync({ identifiers: [identifier] }).map((objects) => objects[0]);
2523
+ }
2524
+ async shaclCoreShapeCount(query) {
2525
+ return this.shaclCoreShapeCountSync(query);
2526
+ }
2527
+ shaclCoreShapeCountSync(query) {
2528
+ return this.shaclCoreShapesSync(query).map((objects) => objects.length);
1978
2529
  }
1979
2530
  async shaclCoreShapeIdentifiers(query) {
1980
2531
  return this.shaclCoreShapeIdentifiersSync(query);
1981
2532
  }
1982
2533
  shaclCoreShapeIdentifiersSync(query) {
1983
- return this.$objectUnionIdentifiersSync([
1984
- {
1985
- $fromRdf: ShaclCoreNodeShape.$fromRdf,
1986
- $fromRdfTypes: [ShaclCoreNodeShape.$fromRdfType],
1987
- },
1988
- {
1989
- $fromRdf: ShaclCorePropertyShape.$fromRdf,
1990
- $fromRdfTypes: [ShaclCorePropertyShape.$fromRdfType],
1991
- },
1992
- ], query);
2534
+ return this.shaclCoreShapesSync(query).map((objects) => objects.map((object) => object.$identifier));
1993
2535
  }
1994
2536
  async shaclCoreShapes(query) {
1995
2537
  return this.shaclCoreShapesSync(query);
@@ -1997,204 +2539,269 @@ export class $RdfjsDatasetObjectSet {
1997
2539
  shaclCoreShapesSync(query) {
1998
2540
  return this.$objectUnionsSync([
1999
2541
  {
2542
+ $filter: ShaclCoreShape.$filter,
2000
2543
  $fromRdf: ShaclCoreNodeShape.$fromRdf,
2001
2544
  $fromRdfTypes: [ShaclCoreNodeShape.$fromRdfType],
2002
2545
  },
2003
2546
  {
2547
+ $filter: ShaclCoreShape.$filter,
2004
2548
  $fromRdf: ShaclCorePropertyShape.$fromRdf,
2005
2549
  $fromRdfTypes: [ShaclCorePropertyShape.$fromRdfType],
2006
2550
  },
2007
2551
  ], query);
2008
2552
  }
2009
- async shaclCoreShapesCount(query) {
2010
- return this.shaclCoreShapesCountSync(query);
2553
+ async object(identifier) {
2554
+ return this.objectSync(identifier);
2555
+ }
2556
+ objectSync(identifier) {
2557
+ return this.objectsSync({ identifiers: [identifier] }).map((objects) => objects[0]);
2558
+ }
2559
+ async objectCount(query) {
2560
+ return this.objectCountSync(query);
2561
+ }
2562
+ objectCountSync(query) {
2563
+ return this.objectsSync(query).map((objects) => objects.length);
2011
2564
  }
2012
- shaclCoreShapesCountSync(query) {
2013
- return this.$objectUnionsCountSync([
2565
+ async objectIdentifiers(query) {
2566
+ return this.objectIdentifiersSync(query);
2567
+ }
2568
+ objectIdentifiersSync(query) {
2569
+ return this.objectsSync(query).map((objects) => objects.map((object) => object.$identifier));
2570
+ }
2571
+ async objects(query) {
2572
+ return this.objectsSync(query);
2573
+ }
2574
+ objectsSync(query) {
2575
+ return this.$objectUnionsSync([
2014
2576
  {
2577
+ $filter: $Object.$filter,
2578
+ $fromRdf: OwlOntology.$fromRdf,
2579
+ $fromRdfTypes: [OwlOntology.$fromRdfType],
2580
+ },
2581
+ {
2582
+ $filter: $Object.$filter,
2015
2583
  $fromRdf: ShaclCoreNodeShape.$fromRdf,
2016
2584
  $fromRdfTypes: [ShaclCoreNodeShape.$fromRdfType],
2017
2585
  },
2018
2586
  {
2587
+ $filter: $Object.$filter,
2588
+ $fromRdf: ShaclCorePropertyGroup.$fromRdf,
2589
+ $fromRdfTypes: [ShaclCorePropertyGroup.$fromRdfType],
2590
+ },
2591
+ {
2592
+ $filter: $Object.$filter,
2019
2593
  $fromRdf: ShaclCorePropertyShape.$fromRdf,
2020
2594
  $fromRdfTypes: [ShaclCorePropertyShape.$fromRdfType],
2021
2595
  },
2022
2596
  ], query);
2023
2597
  }
2024
- $objectIdentifiersSync(objectType, query) {
2025
- return this.$objectsSync(objectType, query).map((objects) => objects.map((object) => object.$identifier));
2026
- }
2027
2598
  $objectsSync(objectType, query) {
2599
+ const graph = query?.graph ?? this.$graph;
2028
2600
  const limit = query?.limit ?? Number.MAX_SAFE_INTEGER;
2029
2601
  if (limit <= 0) {
2030
- return purify.Either.of([]);
2602
+ return Right([]);
2031
2603
  }
2032
2604
  let offset = query?.offset ?? 0;
2033
2605
  if (offset < 0) {
2034
2606
  offset = 0;
2035
2607
  }
2036
- if (query?.where) {
2037
- // Assign identifiers in each case block so the compiler will catch missing cases.
2038
- let identifiers;
2039
- switch (query.where.type) {
2040
- case "identifiers": {
2041
- identifiers = query.where.identifiers.slice(offset, offset + limit);
2042
- break;
2043
- }
2044
- case "triple-objects": {
2045
- let identifierI = 0;
2046
- identifiers = [];
2047
- for (const quad of this.resourceSet.dataset.match(query.where.subject, query.where.predicate, null)) {
2048
- if (quad.object.termType === "BlankNode" ||
2049
- quad.object.termType === "NamedNode") {
2050
- if (++identifierI >= offset) {
2051
- identifiers.push(quad.object);
2052
- if (identifiers.length === limit) {
2053
- break;
2054
- }
2055
- }
2056
- }
2057
- else {
2058
- return purify.Left(new Error(`subject=${query.where.subject.value} predicate=${query.where.predicate.value} pattern matches non-identifier (${quad.object.termType}) triple`));
2059
- }
2608
+ let resources;
2609
+ const resourceSet = this.$resourceSet(); // Access once, in case it's instantiated lazily
2610
+ let sortResources;
2611
+ if (query?.identifiers) {
2612
+ resources = query.identifiers.map((identifier) => ({
2613
+ resource: resourceSet.resource(identifier),
2614
+ }));
2615
+ sortResources = false;
2616
+ }
2617
+ else if (objectType.$fromRdfTypes.length > 0) {
2618
+ const identifierSet = new $IdentifierSet();
2619
+ resources = [];
2620
+ sortResources = true;
2621
+ for (const fromRdfType of objectType.$fromRdfTypes) {
2622
+ for (const resource of resourceSet.instancesOf(fromRdfType, {
2623
+ graph,
2624
+ })) {
2625
+ if (!identifierSet.has(resource.identifier)) {
2626
+ identifierSet.add(resource.identifier);
2627
+ resources.push({ resource });
2060
2628
  }
2061
- break;
2062
2629
  }
2063
2630
  }
2064
- const objects = [];
2065
- for (const identifier of identifiers) {
2066
- const either = objectType.$fromRdf(this.resourceSet.resource(identifier), { objectSet: this });
2067
- if (either.isLeft()) {
2068
- return either;
2631
+ }
2632
+ else {
2633
+ const identifierSet = new $IdentifierSet();
2634
+ resources = [];
2635
+ sortResources = true;
2636
+ for (const quad of resourceSet.dataset) {
2637
+ if (graph && !quad.graph.equals(graph)) {
2638
+ continue;
2069
2639
  }
2070
- objects.push(either.unsafeCoerce());
2640
+ switch (quad.subject.termType) {
2641
+ case "BlankNode":
2642
+ case "NamedNode":
2643
+ break;
2644
+ default:
2645
+ continue;
2646
+ }
2647
+ if (identifierSet.has(quad.subject)) {
2648
+ continue;
2649
+ }
2650
+ identifierSet.add(quad.subject);
2651
+ const resource = resourceSet.resource(quad.subject);
2652
+ // Eagerly eliminate the majority of resources that won't match the object type
2653
+ objectType
2654
+ .$fromRdf(resource, { graph, objectSet: this })
2655
+ .ifRight((object) => {
2656
+ resources.push({ object, resource });
2657
+ });
2071
2658
  }
2072
- return purify.Either.of(objects);
2073
2659
  }
2074
- if (objectType.$fromRdfTypes.length === 0) {
2075
- return purify.Either.of([]);
2660
+ if (sortResources) {
2661
+ // Sort resources by identifier so limit and offset are deterministic
2662
+ resources.sort((left, right) => left.resource.identifier.value.localeCompare(right.resource.identifier.value));
2076
2663
  }
2077
- const resources = [];
2078
- for (const fromRdfType of objectType.$fromRdfTypes) {
2079
- for (const resource of this.resourceSet.instancesOf(fromRdfType)) {
2080
- if (!resources.some((existingResource) => existingResource.identifier.equals(resource.identifier))) {
2081
- resources.push(resource);
2664
+ let objectI = 0;
2665
+ const objects = [];
2666
+ for (let { object, resource } of resources) {
2667
+ if (!object) {
2668
+ const objectEither = objectType.$fromRdf(resource, {
2669
+ graph,
2670
+ objectSet: this,
2671
+ });
2672
+ if (objectEither.isLeft()) {
2673
+ return objectEither;
2082
2674
  }
2675
+ object = objectEither.unsafeCoerce();
2083
2676
  }
2084
- }
2085
- // Sort resources by identifier so limit and offset are deterministic
2086
- resources.sort((left, right) => left.identifier.value.localeCompare(right.identifier.value));
2087
- const objects = [];
2088
- let objectI = 0;
2089
- for (const resource of resources) {
2090
- const either = objectType.$fromRdf(resource, { objectSet: this });
2091
- if (either.isLeft()) {
2092
- return either;
2677
+ if (query?.filter && !objectType.$filter(query.filter, object)) {
2678
+ continue;
2093
2679
  }
2094
2680
  if (objectI++ >= offset) {
2095
- objects.push(either.unsafeCoerce());
2681
+ objects.push(object);
2096
2682
  if (objects.length === limit) {
2097
- return purify.Either.of(objects);
2683
+ return Right(objects);
2098
2684
  }
2099
2685
  }
2100
2686
  }
2101
- return purify.Either.of(objects);
2102
- }
2103
- $objectsCountSync(objectType, query) {
2104
- return this.$objectsSync(objectType, query).map((objects) => objects.length);
2105
- }
2106
- $objectUnionIdentifiersSync(objectTypes, query) {
2107
- return this.$objectUnionsSync(objectTypes, query).map((objects) => objects.map((object) => object.$identifier));
2687
+ return Right(objects);
2108
2688
  }
2109
2689
  $objectUnionsSync(objectTypes, query) {
2690
+ const graph = query?.graph ?? this.$graph;
2110
2691
  const limit = query?.limit ?? Number.MAX_SAFE_INTEGER;
2111
2692
  if (limit <= 0) {
2112
- return purify.Either.of([]);
2693
+ return Right([]);
2113
2694
  }
2114
2695
  let offset = query?.offset ?? 0;
2115
2696
  if (offset < 0) {
2116
2697
  offset = 0;
2117
2698
  }
2118
- if (query?.where) {
2119
- // Assign identifiers in each case block so the compiler will catch missing cases.
2120
- let identifiers;
2121
- switch (query.where.type) {
2122
- case "identifiers": {
2123
- identifiers = query.where.identifiers.slice(offset, offset + limit);
2124
- break;
2125
- }
2126
- case "triple-objects": {
2127
- let identifierI = 0;
2128
- identifiers = [];
2129
- for (const quad of this.resourceSet.dataset.match(query.where.subject, query.where.predicate, null)) {
2130
- if (quad.object.termType === "BlankNode" ||
2131
- quad.object.termType === "NamedNode") {
2132
- if (++identifierI >= offset) {
2133
- identifiers.push(quad.object);
2134
- if (identifiers.length === limit) {
2135
- break;
2136
- }
2137
- }
2138
- }
2139
- else {
2140
- return purify.Left(new Error(`subject=${query.where.subject.value} predicate=${query.where.predicate.value} pattern matches non-identifier (${quad.object.termType}) triple`));
2699
+ let resources;
2700
+ const resourceSet = this.$resourceSet(); // Access once, in case it's instantiated lazily
2701
+ let sortResources;
2702
+ if (query?.identifiers) {
2703
+ resources = query.identifiers.map((identifier) => ({
2704
+ resource: resourceSet.resource(identifier),
2705
+ }));
2706
+ sortResources = false;
2707
+ }
2708
+ else if (objectTypes.every((objectType) => objectType.$fromRdfTypes.length > 0)) {
2709
+ const identifierSet = new $IdentifierSet();
2710
+ resources = [];
2711
+ sortResources = true;
2712
+ for (const objectType of objectTypes) {
2713
+ for (const fromRdfType of objectType.$fromRdfTypes) {
2714
+ for (const resource of resourceSet.instancesOf(fromRdfType, {
2715
+ graph,
2716
+ })) {
2717
+ if (!identifierSet.has(resource.identifier)) {
2718
+ identifierSet.add(resource.identifier);
2719
+ resources.push({ objectType, resource });
2141
2720
  }
2142
2721
  }
2143
- break;
2144
2722
  }
2145
2723
  }
2146
- const objects = [];
2147
- for (const identifier of identifiers) {
2148
- const resource = this.resourceSet.resource(identifier);
2149
- const lefts = [];
2150
- for (const objectType of objectTypes) {
2151
- const either = objectType.$fromRdf(resource, { objectSet: this });
2152
- if (either.isRight()) {
2153
- objects.push(either.unsafeCoerce());
2724
+ }
2725
+ else {
2726
+ const identifierSet = new $IdentifierSet();
2727
+ resources = [];
2728
+ sortResources = true;
2729
+ for (const quad of resourceSet.dataset) {
2730
+ if (graph && !quad.graph.equals(graph)) {
2731
+ continue;
2732
+ }
2733
+ switch (quad.subject.termType) {
2734
+ case "BlankNode":
2735
+ case "NamedNode":
2154
2736
  break;
2155
- }
2156
- lefts.push(either);
2737
+ default:
2738
+ continue;
2157
2739
  }
2158
- // Doesn't appear to belong to any of the known object types, just assume the first
2159
- if (lefts.length === objectTypes.length) {
2160
- return lefts[0];
2740
+ if (identifierSet.has(quad.subject)) {
2741
+ continue;
2161
2742
  }
2162
- }
2163
- return purify.Either.of(objects);
2164
- }
2165
- const resources = [];
2166
- for (const objectType of objectTypes) {
2167
- if (objectType.$fromRdfTypes.length === 0) {
2168
- continue;
2169
- }
2170
- for (const fromRdfType of objectType.$fromRdfTypes) {
2171
- for (const resource of this.resourceSet.instancesOf(fromRdfType)) {
2172
- if (!resources.some(({ resource: existingResource }) => existingResource.identifier.equals(resource.identifier))) {
2173
- resources.push({ objectType, resource });
2743
+ identifierSet.add(quad.subject);
2744
+ // Eagerly eliminate the majority of resources that won't match the object types
2745
+ const resource = resourceSet.resource(quad.subject);
2746
+ for (const objectType of objectTypes) {
2747
+ if (objectType
2748
+ .$fromRdf(resource, { graph, objectSet: this })
2749
+ .ifRight((object) => {
2750
+ resources.push({ object, objectType, resource });
2751
+ })
2752
+ .isRight()) {
2753
+ break;
2174
2754
  }
2175
2755
  }
2176
2756
  }
2177
2757
  }
2178
- // Sort resources by identifier so limit and offset are deterministic
2179
- resources.sort((left, right) => left.resource.identifier.value.localeCompare(right.resource.identifier.value));
2758
+ if (sortResources) {
2759
+ // Sort resources by identifier so limit and offset are deterministic
2760
+ resources.sort((left, right) => left.resource.identifier.value.localeCompare(right.resource.identifier.value));
2761
+ }
2180
2762
  let objectI = 0;
2181
2763
  const objects = [];
2182
- for (const { objectType, resource } of resources) {
2183
- const either = objectType.$fromRdf(resource, { objectSet: this });
2184
- if (either.isLeft()) {
2185
- return either;
2764
+ for (let { object, objectType, resource } of resources) {
2765
+ if (!object) {
2766
+ let objectEither;
2767
+ if (objectType) {
2768
+ objectEither = objectType.$fromRdf(resource, {
2769
+ graph,
2770
+ objectSet: this,
2771
+ });
2772
+ }
2773
+ else {
2774
+ objectEither = Left(new Error("no object types"));
2775
+ for (const tryObjectType of objectTypes) {
2776
+ objectEither = tryObjectType.$fromRdf(resource, {
2777
+ graph,
2778
+ objectSet: this,
2779
+ });
2780
+ if (objectEither.isRight()) {
2781
+ objectType = tryObjectType;
2782
+ break;
2783
+ }
2784
+ }
2785
+ }
2786
+ if (objectEither.isLeft()) {
2787
+ return objectEither;
2788
+ }
2789
+ object = objectEither.unsafeCoerce();
2790
+ }
2791
+ if (!objectType) {
2792
+ throw new Error("objectType should be set here");
2793
+ }
2794
+ if (query?.filter && !objectType.$filter(query.filter, object)) {
2795
+ continue;
2186
2796
  }
2187
2797
  if (objectI++ >= offset) {
2188
- objects.push(either.unsafeCoerce());
2798
+ objects.push(object);
2189
2799
  if (objects.length === limit) {
2190
- return purify.Either.of(objects);
2800
+ return Right(objects);
2191
2801
  }
2192
2802
  }
2193
2803
  }
2194
- return purify.Either.of(objects);
2195
- }
2196
- $objectUnionsCountSync(objectTypes, query) {
2197
- return this.$objectUnionIdentifiersSync(objectTypes, query).map((objects) => objects.length);
2804
+ return Right(objects);
2198
2805
  }
2199
2806
  }
2200
2807
  //# sourceMappingURL=generated.js.map