@startinblox/core 2.0.0-beta.14 → 2.0.0-beta.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/helpers-DEGtolur.js +2106 -0
- package/dist/helpers.js +9 -6
- package/dist/index.js +14 -9
- package/dist/{store-CVms1LLP.js → store-DiyQ_yIK.js} +45 -1278
- package/dist/store.js +1 -1
- package/package.json +2 -2
- package/dist/helpers-D3zLqB4z.js +0 -373
|
@@ -0,0 +1,2106 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __typeError = (msg) => {
|
|
3
|
+
throw TypeError(msg);
|
|
4
|
+
};
|
|
5
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
7
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
8
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
9
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
10
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
11
|
+
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
12
|
+
var _values, _resolve, _AsyncIterableBuilder_instances, createIterable_fn, next_fn, nextPromise_fn;
|
|
13
|
+
var jsonldContextParser = {};
|
|
14
|
+
var ContextParser = {};
|
|
15
|
+
var relativeToAbsoluteIri = {};
|
|
16
|
+
var Resolve = {};
|
|
17
|
+
var hasRequiredResolve;
|
|
18
|
+
function requireResolve() {
|
|
19
|
+
if (hasRequiredResolve) return Resolve;
|
|
20
|
+
hasRequiredResolve = 1;
|
|
21
|
+
Object.defineProperty(Resolve, "__esModule", { value: true });
|
|
22
|
+
Resolve.removeDotSegmentsOfPath = Resolve.removeDotSegments = Resolve.resolve = void 0;
|
|
23
|
+
function resolve(relativeIRI, baseIRI) {
|
|
24
|
+
baseIRI = baseIRI || "";
|
|
25
|
+
const baseFragmentPos = baseIRI.indexOf("#");
|
|
26
|
+
if (baseFragmentPos > 0) {
|
|
27
|
+
baseIRI = baseIRI.substr(0, baseFragmentPos);
|
|
28
|
+
}
|
|
29
|
+
if (!relativeIRI.length) {
|
|
30
|
+
if (baseIRI.indexOf(":") < 0) {
|
|
31
|
+
throw new Error(`Found invalid baseIRI '${baseIRI}' for value '${relativeIRI}'`);
|
|
32
|
+
}
|
|
33
|
+
return baseIRI;
|
|
34
|
+
}
|
|
35
|
+
if (relativeIRI.startsWith("?")) {
|
|
36
|
+
const baseQueryPos = baseIRI.indexOf("?");
|
|
37
|
+
if (baseQueryPos > 0) {
|
|
38
|
+
baseIRI = baseIRI.substr(0, baseQueryPos);
|
|
39
|
+
}
|
|
40
|
+
return baseIRI + relativeIRI;
|
|
41
|
+
}
|
|
42
|
+
if (relativeIRI.startsWith("#")) {
|
|
43
|
+
return baseIRI + relativeIRI;
|
|
44
|
+
}
|
|
45
|
+
if (!baseIRI.length) {
|
|
46
|
+
const relativeColonPos = relativeIRI.indexOf(":");
|
|
47
|
+
if (relativeColonPos < 0) {
|
|
48
|
+
throw new Error(`Found invalid relative IRI '${relativeIRI}' for a missing baseIRI`);
|
|
49
|
+
}
|
|
50
|
+
return removeDotSegmentsOfPath(relativeIRI, relativeColonPos);
|
|
51
|
+
}
|
|
52
|
+
const valueColonPos = relativeIRI.indexOf(":");
|
|
53
|
+
if (valueColonPos >= 0) {
|
|
54
|
+
return removeDotSegmentsOfPath(relativeIRI, valueColonPos);
|
|
55
|
+
}
|
|
56
|
+
const baseColonPos = baseIRI.indexOf(":");
|
|
57
|
+
if (baseColonPos < 0) {
|
|
58
|
+
throw new Error(`Found invalid baseIRI '${baseIRI}' for value '${relativeIRI}'`);
|
|
59
|
+
}
|
|
60
|
+
const baseIRIScheme = baseIRI.substr(0, baseColonPos + 1);
|
|
61
|
+
if (relativeIRI.indexOf("//") === 0) {
|
|
62
|
+
return baseIRIScheme + removeDotSegmentsOfPath(relativeIRI, valueColonPos);
|
|
63
|
+
}
|
|
64
|
+
let baseSlashAfterColonPos;
|
|
65
|
+
if (baseIRI.indexOf("//", baseColonPos) === baseColonPos + 1) {
|
|
66
|
+
baseSlashAfterColonPos = baseIRI.indexOf("/", baseColonPos + 3);
|
|
67
|
+
if (baseSlashAfterColonPos < 0) {
|
|
68
|
+
if (baseIRI.length > baseColonPos + 3) {
|
|
69
|
+
return baseIRI + "/" + removeDotSegmentsOfPath(relativeIRI, valueColonPos);
|
|
70
|
+
} else {
|
|
71
|
+
return baseIRIScheme + removeDotSegmentsOfPath(relativeIRI, valueColonPos);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
} else {
|
|
75
|
+
baseSlashAfterColonPos = baseIRI.indexOf("/", baseColonPos + 1);
|
|
76
|
+
if (baseSlashAfterColonPos < 0) {
|
|
77
|
+
return baseIRIScheme + removeDotSegmentsOfPath(relativeIRI, valueColonPos);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (relativeIRI.indexOf("/") === 0) {
|
|
81
|
+
return baseIRI.substr(0, baseSlashAfterColonPos) + removeDotSegments(relativeIRI);
|
|
82
|
+
}
|
|
83
|
+
let baseIRIPath = baseIRI.substr(baseSlashAfterColonPos);
|
|
84
|
+
const baseIRILastSlashPos = baseIRIPath.lastIndexOf("/");
|
|
85
|
+
if (baseIRILastSlashPos >= 0 && baseIRILastSlashPos < baseIRIPath.length - 1) {
|
|
86
|
+
baseIRIPath = baseIRIPath.substr(0, baseIRILastSlashPos + 1);
|
|
87
|
+
if (relativeIRI[0] === "." && relativeIRI[1] !== "." && relativeIRI[1] !== "/" && relativeIRI[2]) {
|
|
88
|
+
relativeIRI = relativeIRI.substr(1);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
relativeIRI = baseIRIPath + relativeIRI;
|
|
92
|
+
relativeIRI = removeDotSegments(relativeIRI);
|
|
93
|
+
return baseIRI.substr(0, baseSlashAfterColonPos) + relativeIRI;
|
|
94
|
+
}
|
|
95
|
+
Resolve.resolve = resolve;
|
|
96
|
+
function removeDotSegments(path) {
|
|
97
|
+
const segmentBuffers = [];
|
|
98
|
+
let i = 0;
|
|
99
|
+
while (i < path.length) {
|
|
100
|
+
switch (path[i]) {
|
|
101
|
+
case "/":
|
|
102
|
+
if (path[i + 1] === ".") {
|
|
103
|
+
if (path[i + 2] === ".") {
|
|
104
|
+
if (!isCharacterAllowedAfterRelativePathSegment(path[i + 3])) {
|
|
105
|
+
segmentBuffers.push([]);
|
|
106
|
+
i++;
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
segmentBuffers.pop();
|
|
110
|
+
if (!path[i + 3]) {
|
|
111
|
+
segmentBuffers.push([]);
|
|
112
|
+
}
|
|
113
|
+
i += 3;
|
|
114
|
+
} else {
|
|
115
|
+
if (!isCharacterAllowedAfterRelativePathSegment(path[i + 2])) {
|
|
116
|
+
segmentBuffers.push([]);
|
|
117
|
+
i++;
|
|
118
|
+
break;
|
|
119
|
+
}
|
|
120
|
+
if (!path[i + 2]) {
|
|
121
|
+
segmentBuffers.push([]);
|
|
122
|
+
}
|
|
123
|
+
i += 2;
|
|
124
|
+
}
|
|
125
|
+
} else {
|
|
126
|
+
segmentBuffers.push([]);
|
|
127
|
+
i++;
|
|
128
|
+
}
|
|
129
|
+
break;
|
|
130
|
+
case "#":
|
|
131
|
+
case "?":
|
|
132
|
+
if (!segmentBuffers.length) {
|
|
133
|
+
segmentBuffers.push([]);
|
|
134
|
+
}
|
|
135
|
+
segmentBuffers[segmentBuffers.length - 1].push(path.substr(i));
|
|
136
|
+
i = path.length;
|
|
137
|
+
break;
|
|
138
|
+
default:
|
|
139
|
+
if (!segmentBuffers.length) {
|
|
140
|
+
segmentBuffers.push([]);
|
|
141
|
+
}
|
|
142
|
+
segmentBuffers[segmentBuffers.length - 1].push(path[i]);
|
|
143
|
+
i++;
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return "/" + segmentBuffers.map((buffer) => buffer.join("")).join("/");
|
|
148
|
+
}
|
|
149
|
+
Resolve.removeDotSegments = removeDotSegments;
|
|
150
|
+
function removeDotSegmentsOfPath(iri, colonPosition) {
|
|
151
|
+
let searchOffset = colonPosition + 1;
|
|
152
|
+
if (colonPosition >= 0) {
|
|
153
|
+
if (iri[colonPosition + 1] === "/" && iri[colonPosition + 2] === "/") {
|
|
154
|
+
searchOffset = colonPosition + 3;
|
|
155
|
+
}
|
|
156
|
+
} else {
|
|
157
|
+
if (iri[0] === "/" && iri[1] === "/") {
|
|
158
|
+
searchOffset = 2;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
const pathSeparator = iri.indexOf("/", searchOffset);
|
|
162
|
+
if (pathSeparator < 0) {
|
|
163
|
+
return iri;
|
|
164
|
+
}
|
|
165
|
+
const base = iri.substr(0, pathSeparator);
|
|
166
|
+
const path = iri.substr(pathSeparator);
|
|
167
|
+
return base + removeDotSegments(path);
|
|
168
|
+
}
|
|
169
|
+
Resolve.removeDotSegmentsOfPath = removeDotSegmentsOfPath;
|
|
170
|
+
function isCharacterAllowedAfterRelativePathSegment(character) {
|
|
171
|
+
return !character || character === "#" || character === "?" || character === "/";
|
|
172
|
+
}
|
|
173
|
+
return Resolve;
|
|
174
|
+
}
|
|
175
|
+
var hasRequiredRelativeToAbsoluteIri;
|
|
176
|
+
function requireRelativeToAbsoluteIri() {
|
|
177
|
+
if (hasRequiredRelativeToAbsoluteIri) return relativeToAbsoluteIri;
|
|
178
|
+
hasRequiredRelativeToAbsoluteIri = 1;
|
|
179
|
+
(function(exports) {
|
|
180
|
+
var __createBinding = relativeToAbsoluteIri && relativeToAbsoluteIri.__createBinding || (Object.create ? function(o, m, k, k2) {
|
|
181
|
+
if (k2 === void 0) k2 = k;
|
|
182
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() {
|
|
183
|
+
return m[k];
|
|
184
|
+
} });
|
|
185
|
+
} : function(o, m, k, k2) {
|
|
186
|
+
if (k2 === void 0) k2 = k;
|
|
187
|
+
o[k2] = m[k];
|
|
188
|
+
});
|
|
189
|
+
var __exportStar = relativeToAbsoluteIri && relativeToAbsoluteIri.__exportStar || function(m, exports2) {
|
|
190
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports2, p)) __createBinding(exports2, m, p);
|
|
191
|
+
};
|
|
192
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
193
|
+
__exportStar(requireResolve(), exports);
|
|
194
|
+
})(relativeToAbsoluteIri);
|
|
195
|
+
return relativeToAbsoluteIri;
|
|
196
|
+
}
|
|
197
|
+
var ErrorCoded = {};
|
|
198
|
+
var hasRequiredErrorCoded;
|
|
199
|
+
function requireErrorCoded() {
|
|
200
|
+
if (hasRequiredErrorCoded) return ErrorCoded;
|
|
201
|
+
hasRequiredErrorCoded = 1;
|
|
202
|
+
(function(exports) {
|
|
203
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
204
|
+
exports.ERROR_CODES = exports.ErrorCoded = void 0;
|
|
205
|
+
class ErrorCoded2 extends Error {
|
|
206
|
+
/* istanbul ignore next */
|
|
207
|
+
constructor(message, code) {
|
|
208
|
+
super(message);
|
|
209
|
+
this.code = code;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
exports.ErrorCoded = ErrorCoded2;
|
|
213
|
+
(function(ERROR_CODES) {
|
|
214
|
+
ERROR_CODES["COLLIDING_KEYWORDS"] = "colliding keywords";
|
|
215
|
+
ERROR_CODES["CONFLICTING_INDEXES"] = "conflicting indexes";
|
|
216
|
+
ERROR_CODES["CYCLIC_IRI_MAPPING"] = "cyclic IRI mapping";
|
|
217
|
+
ERROR_CODES["INVALID_ID_VALUE"] = "invalid @id value";
|
|
218
|
+
ERROR_CODES["INVALID_INDEX_VALUE"] = "invalid @index value";
|
|
219
|
+
ERROR_CODES["INVALID_NEST_VALUE"] = "invalid @nest value";
|
|
220
|
+
ERROR_CODES["INVALID_PREFIX_VALUE"] = "invalid @prefix value";
|
|
221
|
+
ERROR_CODES["INVALID_PROPAGATE_VALUE"] = "invalid @propagate value";
|
|
222
|
+
ERROR_CODES["INVALID_REVERSE_VALUE"] = "invalid @reverse value";
|
|
223
|
+
ERROR_CODES["INVALID_IMPORT_VALUE"] = "invalid @import value";
|
|
224
|
+
ERROR_CODES["INVALID_VERSION_VALUE"] = "invalid @version value";
|
|
225
|
+
ERROR_CODES["INVALID_BASE_IRI"] = "invalid base IRI";
|
|
226
|
+
ERROR_CODES["INVALID_CONTAINER_MAPPING"] = "invalid container mapping";
|
|
227
|
+
ERROR_CODES["INVALID_CONTEXT_ENTRY"] = "invalid context entry";
|
|
228
|
+
ERROR_CODES["INVALID_CONTEXT_NULLIFICATION"] = "invalid context nullification";
|
|
229
|
+
ERROR_CODES["INVALID_DEFAULT_LANGUAGE"] = "invalid default language";
|
|
230
|
+
ERROR_CODES["INVALID_INCLUDED_VALUE"] = "invalid @included value";
|
|
231
|
+
ERROR_CODES["INVALID_IRI_MAPPING"] = "invalid IRI mapping";
|
|
232
|
+
ERROR_CODES["INVALID_JSON_LITERAL"] = "invalid JSON literal";
|
|
233
|
+
ERROR_CODES["INVALID_KEYWORD_ALIAS"] = "invalid keyword alias";
|
|
234
|
+
ERROR_CODES["INVALID_LANGUAGE_MAP_VALUE"] = "invalid language map value";
|
|
235
|
+
ERROR_CODES["INVALID_LANGUAGE_MAPPING"] = "invalid language mapping";
|
|
236
|
+
ERROR_CODES["INVALID_LANGUAGE_TAGGED_STRING"] = "invalid language-tagged string";
|
|
237
|
+
ERROR_CODES["INVALID_LANGUAGE_TAGGED_VALUE"] = "invalid language-tagged value";
|
|
238
|
+
ERROR_CODES["INVALID_LOCAL_CONTEXT"] = "invalid local context";
|
|
239
|
+
ERROR_CODES["INVALID_REMOTE_CONTEXT"] = "invalid remote context";
|
|
240
|
+
ERROR_CODES["INVALID_REVERSE_PROPERTY"] = "invalid reverse property";
|
|
241
|
+
ERROR_CODES["INVALID_REVERSE_PROPERTY_MAP"] = "invalid reverse property map";
|
|
242
|
+
ERROR_CODES["INVALID_REVERSE_PROPERTY_VALUE"] = "invalid reverse property value";
|
|
243
|
+
ERROR_CODES["INVALID_SCOPED_CONTEXT"] = "invalid scoped context";
|
|
244
|
+
ERROR_CODES["INVALID_SCRIPT_ELEMENT"] = "invalid script element";
|
|
245
|
+
ERROR_CODES["INVALID_SET_OR_LIST_OBJECT"] = "invalid set or list object";
|
|
246
|
+
ERROR_CODES["INVALID_TERM_DEFINITION"] = "invalid term definition";
|
|
247
|
+
ERROR_CODES["INVALID_TYPE_MAPPING"] = "invalid type mapping";
|
|
248
|
+
ERROR_CODES["INVALID_TYPE_VALUE"] = "invalid type value";
|
|
249
|
+
ERROR_CODES["INVALID_TYPED_VALUE"] = "invalid typed value";
|
|
250
|
+
ERROR_CODES["INVALID_VALUE_OBJECT"] = "invalid value object";
|
|
251
|
+
ERROR_CODES["INVALID_VALUE_OBJECT_VALUE"] = "invalid value object value";
|
|
252
|
+
ERROR_CODES["INVALID_VOCAB_MAPPING"] = "invalid vocab mapping";
|
|
253
|
+
ERROR_CODES["IRI_CONFUSED_WITH_PREFIX"] = "IRI confused with prefix";
|
|
254
|
+
ERROR_CODES["KEYWORD_REDEFINITION"] = "keyword redefinition";
|
|
255
|
+
ERROR_CODES["LOADING_DOCUMENT_FAILED"] = "loading document failed";
|
|
256
|
+
ERROR_CODES["LOADING_REMOTE_CONTEXT_FAILED"] = "loading remote context failed";
|
|
257
|
+
ERROR_CODES["MULTIPLE_CONTEXT_LINK_HEADERS"] = "multiple context link headers";
|
|
258
|
+
ERROR_CODES["PROCESSING_MODE_CONFLICT"] = "processing mode conflict";
|
|
259
|
+
ERROR_CODES["PROTECTED_TERM_REDEFINITION"] = "protected term redefinition";
|
|
260
|
+
ERROR_CODES["CONTEXT_OVERFLOW"] = "context overflow";
|
|
261
|
+
ERROR_CODES["INVALID_BASE_DIRECTION"] = "invalid base direction";
|
|
262
|
+
ERROR_CODES["RECURSIVE_CONTEXT_INCLUSION"] = "recursive context inclusion";
|
|
263
|
+
ERROR_CODES["INVALID_STREAMING_KEY_ORDER"] = "invalid streaming key order";
|
|
264
|
+
ERROR_CODES["INVALID_EMBEDDED_NODE"] = "invalid embedded node";
|
|
265
|
+
ERROR_CODES["INVALID_ANNOTATION"] = "invalid annotation";
|
|
266
|
+
})(exports.ERROR_CODES || (exports.ERROR_CODES = {}));
|
|
267
|
+
})(ErrorCoded);
|
|
268
|
+
return ErrorCoded;
|
|
269
|
+
}
|
|
270
|
+
var FetchDocumentLoader = {};
|
|
271
|
+
var link;
|
|
272
|
+
var hasRequiredLink;
|
|
273
|
+
function requireLink() {
|
|
274
|
+
if (hasRequiredLink) return link;
|
|
275
|
+
hasRequiredLink = 1;
|
|
276
|
+
var COMPATIBLE_ENCODING_PATTERN = /^utf-?8|ascii|utf-?16-?le|ucs-?2|base-?64|latin-?1$/i;
|
|
277
|
+
var WS_TRIM_PATTERN = /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g;
|
|
278
|
+
var WS_CHAR_PATTERN = /\s|\uFEFF|\xA0/;
|
|
279
|
+
var WS_FOLD_PATTERN = /\r?\n[\x20\x09]+/g;
|
|
280
|
+
var DELIMITER_PATTERN = /[;,"]/;
|
|
281
|
+
var WS_DELIMITER_PATTERN = /[;,"]|\s/;
|
|
282
|
+
var TOKEN_PATTERN = /^[!#$%&'*+\-\.^_`|~\da-zA-Z]+$/;
|
|
283
|
+
var STATE = {
|
|
284
|
+
IDLE: 1 << 0,
|
|
285
|
+
URI: 1 << 1,
|
|
286
|
+
ATTR: 1 << 2
|
|
287
|
+
};
|
|
288
|
+
function trim(value) {
|
|
289
|
+
return value.replace(WS_TRIM_PATTERN, "");
|
|
290
|
+
}
|
|
291
|
+
function hasWhitespace(value) {
|
|
292
|
+
return WS_CHAR_PATTERN.test(value);
|
|
293
|
+
}
|
|
294
|
+
function skipWhitespace(value, offset) {
|
|
295
|
+
while (hasWhitespace(value[offset])) {
|
|
296
|
+
offset++;
|
|
297
|
+
}
|
|
298
|
+
return offset;
|
|
299
|
+
}
|
|
300
|
+
function needsQuotes(value) {
|
|
301
|
+
return WS_DELIMITER_PATTERN.test(value) || !TOKEN_PATTERN.test(value);
|
|
302
|
+
}
|
|
303
|
+
function shallowCompareObjects(object1, object2) {
|
|
304
|
+
return Object.keys(object1).length === Object.keys(object2).length && Object.keys(object1).every(
|
|
305
|
+
(key) => key in object2 && object1[key] === object2[key]
|
|
306
|
+
);
|
|
307
|
+
}
|
|
308
|
+
class Link {
|
|
309
|
+
/**
|
|
310
|
+
* Link
|
|
311
|
+
* @constructor
|
|
312
|
+
* @param {String} [value]
|
|
313
|
+
* @returns {Link}
|
|
314
|
+
*/
|
|
315
|
+
constructor(value) {
|
|
316
|
+
this.refs = [];
|
|
317
|
+
if (value) {
|
|
318
|
+
this.parse(value);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* Get refs with given relation type
|
|
323
|
+
* @param {String} value
|
|
324
|
+
* @returns {Array<Object>}
|
|
325
|
+
*/
|
|
326
|
+
rel(value) {
|
|
327
|
+
var links = [];
|
|
328
|
+
var type = value.toLowerCase();
|
|
329
|
+
for (var i = 0; i < this.refs.length; i++) {
|
|
330
|
+
if (typeof this.refs[i].rel === "string" && this.refs[i].rel.toLowerCase() === type) {
|
|
331
|
+
links.push(this.refs[i]);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
return links;
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Get refs where given attribute has a given value
|
|
338
|
+
* @param {String} attr
|
|
339
|
+
* @param {String} value
|
|
340
|
+
* @returns {Array<Object>}
|
|
341
|
+
*/
|
|
342
|
+
get(attr, value) {
|
|
343
|
+
attr = attr.toLowerCase();
|
|
344
|
+
value = value.toLowerCase();
|
|
345
|
+
var links = [];
|
|
346
|
+
for (var i = 0; i < this.refs.length; i++) {
|
|
347
|
+
if (typeof this.refs[i][attr] === "string" && this.refs[i][attr].toLowerCase() === value) {
|
|
348
|
+
links.push(this.refs[i]);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
return links;
|
|
352
|
+
}
|
|
353
|
+
/** Sets a reference. */
|
|
354
|
+
set(link2) {
|
|
355
|
+
this.refs.push(link2);
|
|
356
|
+
return this;
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* Sets a reference if a reference with similar properties isn’t already set.
|
|
360
|
+
*/
|
|
361
|
+
setUnique(link2) {
|
|
362
|
+
if (!this.refs.some((ref) => shallowCompareObjects(ref, link2))) {
|
|
363
|
+
this.refs.push(link2);
|
|
364
|
+
}
|
|
365
|
+
return this;
|
|
366
|
+
}
|
|
367
|
+
has(attr, value) {
|
|
368
|
+
attr = attr.toLowerCase();
|
|
369
|
+
value = value.toLowerCase();
|
|
370
|
+
for (var i = 0; i < this.refs.length; i++) {
|
|
371
|
+
if (typeof this.refs[i][attr] === "string" && this.refs[i][attr].toLowerCase() === value) {
|
|
372
|
+
return true;
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
return false;
|
|
376
|
+
}
|
|
377
|
+
parse(value, offset) {
|
|
378
|
+
offset = offset || 0;
|
|
379
|
+
value = offset ? value.slice(offset) : value;
|
|
380
|
+
value = trim(value).replace(WS_FOLD_PATTERN, "");
|
|
381
|
+
var state = STATE.IDLE;
|
|
382
|
+
var length = value.length;
|
|
383
|
+
var offset = 0;
|
|
384
|
+
var ref = null;
|
|
385
|
+
while (offset < length) {
|
|
386
|
+
if (state === STATE.IDLE) {
|
|
387
|
+
if (hasWhitespace(value[offset])) {
|
|
388
|
+
offset++;
|
|
389
|
+
continue;
|
|
390
|
+
} else if (value[offset] === "<") {
|
|
391
|
+
if (ref != null) {
|
|
392
|
+
ref.rel != null ? this.refs.push(...Link.expandRelations(ref)) : this.refs.push(ref);
|
|
393
|
+
}
|
|
394
|
+
var end = value.indexOf(">", offset);
|
|
395
|
+
if (end === -1) throw new Error("Expected end of URI delimiter at offset " + offset);
|
|
396
|
+
ref = { uri: value.slice(offset + 1, end) };
|
|
397
|
+
offset = end;
|
|
398
|
+
state = STATE.URI;
|
|
399
|
+
} else {
|
|
400
|
+
throw new Error('Unexpected character "' + value[offset] + '" at offset ' + offset);
|
|
401
|
+
}
|
|
402
|
+
offset++;
|
|
403
|
+
} else if (state === STATE.URI) {
|
|
404
|
+
if (hasWhitespace(value[offset])) {
|
|
405
|
+
offset++;
|
|
406
|
+
continue;
|
|
407
|
+
} else if (value[offset] === ";") {
|
|
408
|
+
state = STATE.ATTR;
|
|
409
|
+
offset++;
|
|
410
|
+
} else if (value[offset] === ",") {
|
|
411
|
+
state = STATE.IDLE;
|
|
412
|
+
offset++;
|
|
413
|
+
} else {
|
|
414
|
+
throw new Error('Unexpected character "' + value[offset] + '" at offset ' + offset);
|
|
415
|
+
}
|
|
416
|
+
} else if (state === STATE.ATTR) {
|
|
417
|
+
if (value[offset] === ";" || hasWhitespace(value[offset])) {
|
|
418
|
+
offset++;
|
|
419
|
+
continue;
|
|
420
|
+
}
|
|
421
|
+
var end = value.indexOf("=", offset);
|
|
422
|
+
if (end === -1) end = value.indexOf(";", offset);
|
|
423
|
+
if (end === -1) end = value.length;
|
|
424
|
+
var attr = trim(value.slice(offset, end)).toLowerCase();
|
|
425
|
+
var attrValue = "";
|
|
426
|
+
offset = end + 1;
|
|
427
|
+
offset = skipWhitespace(value, offset);
|
|
428
|
+
if (value[offset] === '"') {
|
|
429
|
+
offset++;
|
|
430
|
+
while (offset < length) {
|
|
431
|
+
if (value[offset] === '"') {
|
|
432
|
+
offset++;
|
|
433
|
+
break;
|
|
434
|
+
}
|
|
435
|
+
if (value[offset] === "\\") {
|
|
436
|
+
offset++;
|
|
437
|
+
}
|
|
438
|
+
attrValue += value[offset];
|
|
439
|
+
offset++;
|
|
440
|
+
}
|
|
441
|
+
} else {
|
|
442
|
+
var end = offset + 1;
|
|
443
|
+
while (!DELIMITER_PATTERN.test(value[end]) && end < length) {
|
|
444
|
+
end++;
|
|
445
|
+
}
|
|
446
|
+
attrValue = value.slice(offset, end);
|
|
447
|
+
offset = end;
|
|
448
|
+
}
|
|
449
|
+
if (ref[attr] && Link.isSingleOccurenceAttr(attr)) ;
|
|
450
|
+
else if (attr[attr.length - 1] === "*") {
|
|
451
|
+
ref[attr] = Link.parseExtendedValue(attrValue);
|
|
452
|
+
} else {
|
|
453
|
+
attrValue = attr === "type" ? attrValue.toLowerCase() : attrValue;
|
|
454
|
+
if (ref[attr] != null) {
|
|
455
|
+
if (Array.isArray(ref[attr])) {
|
|
456
|
+
ref[attr].push(attrValue);
|
|
457
|
+
} else {
|
|
458
|
+
ref[attr] = [ref[attr], attrValue];
|
|
459
|
+
}
|
|
460
|
+
} else {
|
|
461
|
+
ref[attr] = attrValue;
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
switch (value[offset]) {
|
|
465
|
+
case ",":
|
|
466
|
+
state = STATE.IDLE;
|
|
467
|
+
break;
|
|
468
|
+
case ";":
|
|
469
|
+
state = STATE.ATTR;
|
|
470
|
+
break;
|
|
471
|
+
}
|
|
472
|
+
offset++;
|
|
473
|
+
} else {
|
|
474
|
+
throw new Error('Unknown parser state "' + state + '"');
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
if (ref != null) {
|
|
478
|
+
ref.rel != null ? this.refs.push(...Link.expandRelations(ref)) : this.refs.push(ref);
|
|
479
|
+
}
|
|
480
|
+
ref = null;
|
|
481
|
+
return this;
|
|
482
|
+
}
|
|
483
|
+
toString() {
|
|
484
|
+
var refs = [];
|
|
485
|
+
var link2 = "";
|
|
486
|
+
var ref = null;
|
|
487
|
+
for (var i = 0; i < this.refs.length; i++) {
|
|
488
|
+
ref = this.refs[i];
|
|
489
|
+
link2 = Object.keys(this.refs[i]).reduce(function(link3, attr) {
|
|
490
|
+
if (attr === "uri") return link3;
|
|
491
|
+
return link3 + "; " + Link.formatAttribute(attr, ref[attr]);
|
|
492
|
+
}, "<" + ref.uri + ">");
|
|
493
|
+
refs.push(link2);
|
|
494
|
+
}
|
|
495
|
+
return refs.join(", ");
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
Link.isCompatibleEncoding = function(value) {
|
|
499
|
+
return COMPATIBLE_ENCODING_PATTERN.test(value);
|
|
500
|
+
};
|
|
501
|
+
Link.parse = function(value, offset) {
|
|
502
|
+
return new Link().parse(value, offset);
|
|
503
|
+
};
|
|
504
|
+
Link.isSingleOccurenceAttr = function(attr) {
|
|
505
|
+
return attr === "rel" || attr === "type" || attr === "media" || attr === "title" || attr === "title*";
|
|
506
|
+
};
|
|
507
|
+
Link.isTokenAttr = function(attr) {
|
|
508
|
+
return attr === "rel" || attr === "type" || attr === "anchor";
|
|
509
|
+
};
|
|
510
|
+
Link.escapeQuotes = function(value) {
|
|
511
|
+
return value.replace(/"/g, '\\"');
|
|
512
|
+
};
|
|
513
|
+
Link.expandRelations = function(ref) {
|
|
514
|
+
var rels = ref.rel.split(" ");
|
|
515
|
+
return rels.map(function(rel) {
|
|
516
|
+
var value = Object.assign({}, ref);
|
|
517
|
+
value.rel = rel;
|
|
518
|
+
return value;
|
|
519
|
+
});
|
|
520
|
+
};
|
|
521
|
+
Link.parseExtendedValue = function(value) {
|
|
522
|
+
var parts = /([^']+)?(?:'([^']*)')?(.+)/.exec(value);
|
|
523
|
+
return {
|
|
524
|
+
language: parts[2].toLowerCase(),
|
|
525
|
+
encoding: Link.isCompatibleEncoding(parts[1]) ? null : parts[1].toLowerCase(),
|
|
526
|
+
value: Link.isCompatibleEncoding(parts[1]) ? decodeURIComponent(parts[3]) : parts[3]
|
|
527
|
+
};
|
|
528
|
+
};
|
|
529
|
+
Link.formatExtendedAttribute = function(attr, data) {
|
|
530
|
+
var encoding = (data.encoding || "utf-8").toUpperCase();
|
|
531
|
+
var language = data.language || "en";
|
|
532
|
+
var encodedValue = "";
|
|
533
|
+
if (Buffer.isBuffer(data.value) && Link.isCompatibleEncoding(encoding)) {
|
|
534
|
+
encodedValue = data.value.toString(encoding);
|
|
535
|
+
} else if (Buffer.isBuffer(data.value)) {
|
|
536
|
+
encodedValue = data.value.toString("hex").replace(/[0-9a-f]{2}/gi, "%$1");
|
|
537
|
+
} else {
|
|
538
|
+
encodedValue = encodeURIComponent(data.value);
|
|
539
|
+
}
|
|
540
|
+
return attr + "=" + encoding + "'" + language + "'" + encodedValue;
|
|
541
|
+
};
|
|
542
|
+
Link.formatAttribute = function(attr, value) {
|
|
543
|
+
if (Array.isArray(value)) {
|
|
544
|
+
return value.map((item) => {
|
|
545
|
+
return Link.formatAttribute(attr, item);
|
|
546
|
+
}).join("; ");
|
|
547
|
+
}
|
|
548
|
+
if (attr[attr.length - 1] === "*" || typeof value !== "string") {
|
|
549
|
+
return Link.formatExtendedAttribute(attr, value);
|
|
550
|
+
}
|
|
551
|
+
if (Link.isTokenAttr(attr)) {
|
|
552
|
+
value = needsQuotes(value) ? '"' + Link.escapeQuotes(value) + '"' : Link.escapeQuotes(value);
|
|
553
|
+
} else if (needsQuotes(value)) {
|
|
554
|
+
value = encodeURIComponent(value);
|
|
555
|
+
value = value.replace(/%20/g, " ").replace(/%2C/g, ",").replace(/%3B/g, ";");
|
|
556
|
+
value = '"' + value + '"';
|
|
557
|
+
}
|
|
558
|
+
return attr + "=" + value;
|
|
559
|
+
};
|
|
560
|
+
link = Link;
|
|
561
|
+
return link;
|
|
562
|
+
}
|
|
563
|
+
var hasRequiredFetchDocumentLoader;
|
|
564
|
+
function requireFetchDocumentLoader() {
|
|
565
|
+
if (hasRequiredFetchDocumentLoader) return FetchDocumentLoader;
|
|
566
|
+
hasRequiredFetchDocumentLoader = 1;
|
|
567
|
+
Object.defineProperty(FetchDocumentLoader, "__esModule", { value: true });
|
|
568
|
+
FetchDocumentLoader.FetchDocumentLoader = void 0;
|
|
569
|
+
const ErrorCoded_1 = /* @__PURE__ */ requireErrorCoded();
|
|
570
|
+
const http_link_header_1 = requireLink();
|
|
571
|
+
const relative_to_absolute_iri_1 = requireRelativeToAbsoluteIri();
|
|
572
|
+
let FetchDocumentLoader$1 = class FetchDocumentLoader {
|
|
573
|
+
constructor(fetcher) {
|
|
574
|
+
this.fetcher = fetcher;
|
|
575
|
+
}
|
|
576
|
+
async load(url) {
|
|
577
|
+
const response = await (this.fetcher || fetch)(url, { headers: new Headers({ accept: "application/ld+json" }) });
|
|
578
|
+
if (response.ok && response.headers) {
|
|
579
|
+
let mediaType = response.headers.get("Content-Type");
|
|
580
|
+
if (mediaType) {
|
|
581
|
+
const colonPos = mediaType.indexOf(";");
|
|
582
|
+
if (colonPos > 0) {
|
|
583
|
+
mediaType = mediaType.substr(0, colonPos);
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
if (mediaType === "application/ld+json") {
|
|
587
|
+
return await response.json();
|
|
588
|
+
} else {
|
|
589
|
+
if (response.headers.has("Link")) {
|
|
590
|
+
let alternateUrl;
|
|
591
|
+
response.headers.forEach((value, key) => {
|
|
592
|
+
if (key === "link") {
|
|
593
|
+
const linkHeader = (0, http_link_header_1.parse)(value);
|
|
594
|
+
for (const link2 of linkHeader.get("type", "application/ld+json")) {
|
|
595
|
+
if (link2.rel === "alternate") {
|
|
596
|
+
if (alternateUrl) {
|
|
597
|
+
throw new Error("Multiple JSON-LD alternate links were found on " + url);
|
|
598
|
+
}
|
|
599
|
+
alternateUrl = (0, relative_to_absolute_iri_1.resolve)(link2.uri, url);
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
});
|
|
604
|
+
if (alternateUrl) {
|
|
605
|
+
return this.load(alternateUrl);
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
throw new ErrorCoded_1.ErrorCoded(`Unsupported JSON-LD media type ${mediaType}`, ErrorCoded_1.ERROR_CODES.LOADING_DOCUMENT_FAILED);
|
|
609
|
+
}
|
|
610
|
+
} else {
|
|
611
|
+
throw new Error(response.statusText || `Status code: ${response.status}`);
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
};
|
|
615
|
+
FetchDocumentLoader.FetchDocumentLoader = FetchDocumentLoader$1;
|
|
616
|
+
return FetchDocumentLoader;
|
|
617
|
+
}
|
|
618
|
+
var JsonLdContextNormalized = {};
|
|
619
|
+
var Util = {};
|
|
620
|
+
var hasRequiredUtil;
|
|
621
|
+
function requireUtil() {
|
|
622
|
+
if (hasRequiredUtil) return Util;
|
|
623
|
+
hasRequiredUtil = 1;
|
|
624
|
+
Object.defineProperty(Util, "__esModule", { value: true });
|
|
625
|
+
Util.Util = void 0;
|
|
626
|
+
let Util$1 = class Util2 {
|
|
627
|
+
/**
|
|
628
|
+
* Check if the given term is a valid compact IRI.
|
|
629
|
+
* Otherwise, it may be an IRI.
|
|
630
|
+
* @param {string} term A term.
|
|
631
|
+
* @return {boolean} If it is a compact IRI.
|
|
632
|
+
*/
|
|
633
|
+
static isCompactIri(term) {
|
|
634
|
+
return term.indexOf(":") > 0 && !(term && term[0] === "#");
|
|
635
|
+
}
|
|
636
|
+
/**
|
|
637
|
+
* Get the prefix from the given term.
|
|
638
|
+
* @see https://json-ld.org/spec/latest/json-ld/#compact-iris
|
|
639
|
+
* @param {string} term A term that is an URL or a prefixed URL.
|
|
640
|
+
* @param {IJsonLdContextNormalizedRaw} context A context.
|
|
641
|
+
* @return {string} The prefix or null.
|
|
642
|
+
*/
|
|
643
|
+
static getPrefix(term, context) {
|
|
644
|
+
if (term && term[0] === "#") {
|
|
645
|
+
return null;
|
|
646
|
+
}
|
|
647
|
+
const separatorPos = term.indexOf(":");
|
|
648
|
+
if (separatorPos >= 0) {
|
|
649
|
+
if (term.length > separatorPos + 1 && term.charAt(separatorPos + 1) === "/" && term.charAt(separatorPos + 2) === "/") {
|
|
650
|
+
return null;
|
|
651
|
+
}
|
|
652
|
+
const prefix = term.substr(0, separatorPos);
|
|
653
|
+
if (prefix === "_") {
|
|
654
|
+
return null;
|
|
655
|
+
}
|
|
656
|
+
if (context[prefix]) {
|
|
657
|
+
return prefix;
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
return null;
|
|
661
|
+
}
|
|
662
|
+
/**
|
|
663
|
+
* From a given context entry value, get the string value, or the @id field.
|
|
664
|
+
* @param contextValue A value for a term in a context.
|
|
665
|
+
* @return {string} The id value, or null.
|
|
666
|
+
*/
|
|
667
|
+
static getContextValueId(contextValue) {
|
|
668
|
+
if (contextValue === null || typeof contextValue === "string") {
|
|
669
|
+
return contextValue;
|
|
670
|
+
}
|
|
671
|
+
const id = contextValue["@id"];
|
|
672
|
+
return id ? id : null;
|
|
673
|
+
}
|
|
674
|
+
/**
|
|
675
|
+
* Check if the given simple term definition (string-based value of a context term)
|
|
676
|
+
* should be considered a prefix.
|
|
677
|
+
* @param value A simple term definition value.
|
|
678
|
+
* @param options Options that define the way how expansion must be done.
|
|
679
|
+
*/
|
|
680
|
+
static isSimpleTermDefinitionPrefix(value, options) {
|
|
681
|
+
return !Util2.isPotentialKeyword(value) && (options.allowPrefixNonGenDelims || typeof value === "string" && (value[0] === "_" || Util2.isPrefixIriEndingWithGenDelim(value)));
|
|
682
|
+
}
|
|
683
|
+
/**
|
|
684
|
+
* Check if the given keyword is of the keyword format "@"1*ALPHA.
|
|
685
|
+
* @param {string} keyword A potential keyword.
|
|
686
|
+
* @return {boolean} If the given keyword is of the keyword format.
|
|
687
|
+
*/
|
|
688
|
+
static isPotentialKeyword(keyword) {
|
|
689
|
+
return typeof keyword === "string" && Util2.KEYWORD_REGEX.test(keyword);
|
|
690
|
+
}
|
|
691
|
+
/**
|
|
692
|
+
* Check if the given prefix ends with a gen-delim character.
|
|
693
|
+
* @param {string} prefixIri A prefix IRI.
|
|
694
|
+
* @return {boolean} If the given prefix IRI is valid.
|
|
695
|
+
*/
|
|
696
|
+
static isPrefixIriEndingWithGenDelim(prefixIri) {
|
|
697
|
+
return Util2.ENDS_WITH_GEN_DELIM.test(prefixIri);
|
|
698
|
+
}
|
|
699
|
+
/**
|
|
700
|
+
* Check if the given context value can be a prefix value.
|
|
701
|
+
* @param value A context value.
|
|
702
|
+
* @return {boolean} If it can be a prefix value.
|
|
703
|
+
*/
|
|
704
|
+
static isPrefixValue(value) {
|
|
705
|
+
return value && (typeof value === "string" || value && typeof value === "object");
|
|
706
|
+
}
|
|
707
|
+
/**
|
|
708
|
+
* Check if the given IRI is valid.
|
|
709
|
+
* @param {string} iri A potential IRI.
|
|
710
|
+
* @return {boolean} If the given IRI is valid.
|
|
711
|
+
*/
|
|
712
|
+
static isValidIri(iri) {
|
|
713
|
+
return Boolean(iri && Util2.IRI_REGEX.test(iri));
|
|
714
|
+
}
|
|
715
|
+
/**
|
|
716
|
+
* Check if the given IRI is valid, this includes the possibility of being a relative IRI.
|
|
717
|
+
* @param {string} iri A potential IRI.
|
|
718
|
+
* @return {boolean} If the given IRI is valid.
|
|
719
|
+
*/
|
|
720
|
+
static isValidIriWeak(iri) {
|
|
721
|
+
return !!iri && iri[0] !== ":" && Util2.IRI_REGEX_WEAK.test(iri);
|
|
722
|
+
}
|
|
723
|
+
/**
|
|
724
|
+
* Check if the given keyword is a defined according to the JSON-LD specification.
|
|
725
|
+
* @param {string} keyword A potential keyword.
|
|
726
|
+
* @return {boolean} If the given keyword is valid.
|
|
727
|
+
*/
|
|
728
|
+
static isValidKeyword(keyword) {
|
|
729
|
+
return Util2.VALID_KEYWORDS[keyword];
|
|
730
|
+
}
|
|
731
|
+
/**
|
|
732
|
+
* Check if the given term is protected in the context.
|
|
733
|
+
* @param {IJsonLdContextNormalizedRaw} context A context.
|
|
734
|
+
* @param {string} key A context term.
|
|
735
|
+
* @return {boolean} If the given term has an @protected flag.
|
|
736
|
+
*/
|
|
737
|
+
static isTermProtected(context, key) {
|
|
738
|
+
const value = context[key];
|
|
739
|
+
return !(typeof value === "string") && value && value["@protected"];
|
|
740
|
+
}
|
|
741
|
+
/**
|
|
742
|
+
* Check if the given context has at least one protected term.
|
|
743
|
+
* @param context A context.
|
|
744
|
+
* @return If the context has a protected term.
|
|
745
|
+
*/
|
|
746
|
+
static hasProtectedTerms(context) {
|
|
747
|
+
for (const key of Object.keys(context)) {
|
|
748
|
+
if (Util2.isTermProtected(context, key)) {
|
|
749
|
+
return true;
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
return false;
|
|
753
|
+
}
|
|
754
|
+
/**
|
|
755
|
+
* Check if the given key is an internal reserved keyword.
|
|
756
|
+
* @param key A context key.
|
|
757
|
+
*/
|
|
758
|
+
static isReservedInternalKeyword(key) {
|
|
759
|
+
return key.startsWith("@__");
|
|
760
|
+
}
|
|
761
|
+
/**
|
|
762
|
+
* Check if two objects are deepEqual to on another.
|
|
763
|
+
* @param object1 The first object to test.
|
|
764
|
+
* @param object2 The second object to test.
|
|
765
|
+
*/
|
|
766
|
+
static deepEqual(object1, object2) {
|
|
767
|
+
const objKeys1 = Object.keys(object1);
|
|
768
|
+
const objKeys2 = Object.keys(object2);
|
|
769
|
+
if (objKeys1.length !== objKeys2.length)
|
|
770
|
+
return false;
|
|
771
|
+
return objKeys1.every((key) => {
|
|
772
|
+
const value1 = object1[key];
|
|
773
|
+
const value2 = object2[key];
|
|
774
|
+
return value1 === value2 || value1 !== null && value2 !== null && typeof value1 === "object" && typeof value2 === "object" && this.deepEqual(value1, value2);
|
|
775
|
+
});
|
|
776
|
+
}
|
|
777
|
+
};
|
|
778
|
+
Util$1.IRI_REGEX = /^([A-Za-z][A-Za-z0-9+-.]*|_):[^ "<>{}|\\\[\]`#]*(#[^#]*)?$/;
|
|
779
|
+
Util$1.IRI_REGEX_WEAK = /(?::[^:])|\//;
|
|
780
|
+
Util$1.KEYWORD_REGEX = /^@[a-z]+$/i;
|
|
781
|
+
Util$1.ENDS_WITH_GEN_DELIM = /[:/?#\[\]@]$/;
|
|
782
|
+
Util$1.REGEX_LANGUAGE_TAG = /^[a-zA-Z]+(-[a-zA-Z0-9]+)*$/;
|
|
783
|
+
Util$1.REGEX_DIRECTION_TAG = /^(ltr)|(rtl)$/;
|
|
784
|
+
Util$1.VALID_KEYWORDS = {
|
|
785
|
+
"@annotation": true,
|
|
786
|
+
"@base": true,
|
|
787
|
+
"@container": true,
|
|
788
|
+
"@context": true,
|
|
789
|
+
"@direction": true,
|
|
790
|
+
"@graph": true,
|
|
791
|
+
"@id": true,
|
|
792
|
+
"@import": true,
|
|
793
|
+
"@included": true,
|
|
794
|
+
"@index": true,
|
|
795
|
+
"@json": true,
|
|
796
|
+
"@language": true,
|
|
797
|
+
"@list": true,
|
|
798
|
+
"@nest": true,
|
|
799
|
+
"@none": true,
|
|
800
|
+
"@prefix": true,
|
|
801
|
+
"@propagate": true,
|
|
802
|
+
"@protected": true,
|
|
803
|
+
"@reverse": true,
|
|
804
|
+
"@set": true,
|
|
805
|
+
"@type": true,
|
|
806
|
+
"@value": true,
|
|
807
|
+
"@version": true,
|
|
808
|
+
"@vocab": true
|
|
809
|
+
};
|
|
810
|
+
Util$1.EXPAND_KEYS_BLACKLIST = [
|
|
811
|
+
"@base",
|
|
812
|
+
"@vocab",
|
|
813
|
+
"@language",
|
|
814
|
+
"@version",
|
|
815
|
+
"@direction"
|
|
816
|
+
];
|
|
817
|
+
Util$1.ALIAS_DOMAIN_BLACKLIST = [
|
|
818
|
+
"@container",
|
|
819
|
+
"@graph",
|
|
820
|
+
"@id",
|
|
821
|
+
"@index",
|
|
822
|
+
"@list",
|
|
823
|
+
"@nest",
|
|
824
|
+
"@none",
|
|
825
|
+
"@prefix",
|
|
826
|
+
"@reverse",
|
|
827
|
+
"@set",
|
|
828
|
+
"@type",
|
|
829
|
+
"@value",
|
|
830
|
+
"@version"
|
|
831
|
+
];
|
|
832
|
+
Util$1.ALIAS_RANGE_BLACKLIST = [
|
|
833
|
+
"@context",
|
|
834
|
+
"@preserve"
|
|
835
|
+
];
|
|
836
|
+
Util$1.CONTAINERS = [
|
|
837
|
+
"@list",
|
|
838
|
+
"@set",
|
|
839
|
+
"@index",
|
|
840
|
+
"@language",
|
|
841
|
+
"@graph",
|
|
842
|
+
"@id",
|
|
843
|
+
"@type"
|
|
844
|
+
];
|
|
845
|
+
Util$1.CONTAINERS_1_0 = [
|
|
846
|
+
"@list",
|
|
847
|
+
"@set",
|
|
848
|
+
"@index"
|
|
849
|
+
];
|
|
850
|
+
Util.Util = Util$1;
|
|
851
|
+
return Util;
|
|
852
|
+
}
|
|
853
|
+
var hasRequiredJsonLdContextNormalized;
|
|
854
|
+
function requireJsonLdContextNormalized() {
|
|
855
|
+
if (hasRequiredJsonLdContextNormalized) return JsonLdContextNormalized;
|
|
856
|
+
hasRequiredJsonLdContextNormalized = 1;
|
|
857
|
+
(function(exports) {
|
|
858
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
859
|
+
exports.defaultExpandOptions = exports.JsonLdContextNormalized = void 0;
|
|
860
|
+
const relative_to_absolute_iri_1 = requireRelativeToAbsoluteIri();
|
|
861
|
+
const ErrorCoded_1 = /* @__PURE__ */ requireErrorCoded();
|
|
862
|
+
const Util_1 = /* @__PURE__ */ requireUtil();
|
|
863
|
+
class JsonLdContextNormalized2 {
|
|
864
|
+
constructor(contextRaw) {
|
|
865
|
+
this.contextRaw = contextRaw;
|
|
866
|
+
}
|
|
867
|
+
/**
|
|
868
|
+
* @return The raw inner context.
|
|
869
|
+
*/
|
|
870
|
+
getContextRaw() {
|
|
871
|
+
return this.contextRaw;
|
|
872
|
+
}
|
|
873
|
+
/**
|
|
874
|
+
* Expand the term or prefix of the given term if it has one,
|
|
875
|
+
* otherwise return the term as-is.
|
|
876
|
+
*
|
|
877
|
+
* This will try to expand the IRI as much as possible.
|
|
878
|
+
*
|
|
879
|
+
* Iff in vocab-mode, then other references to other terms in the context can be used,
|
|
880
|
+
* such as to `myTerm`:
|
|
881
|
+
* ```
|
|
882
|
+
* {
|
|
883
|
+
* "myTerm": "http://example.org/myLongTerm"
|
|
884
|
+
* }
|
|
885
|
+
* ```
|
|
886
|
+
*
|
|
887
|
+
* @param {string} term A term that is an URL or a prefixed URL.
|
|
888
|
+
* @param {boolean} expandVocab If the term is a predicate or type and should be expanded based on @vocab,
|
|
889
|
+
* otherwise it is considered a regular term that is expanded based on @base.
|
|
890
|
+
* @param {IExpandOptions} options Options that define the way how expansion must be done.
|
|
891
|
+
* @return {string} The expanded term, the term as-is, or null if it was explicitly disabled in the context.
|
|
892
|
+
* @throws If the term is aliased to an invalid value (not a string, IRI or keyword).
|
|
893
|
+
*/
|
|
894
|
+
expandTerm(term, expandVocab, options = exports.defaultExpandOptions) {
|
|
895
|
+
const contextValue = this.contextRaw[term];
|
|
896
|
+
if (contextValue === null || contextValue && contextValue["@id"] === null) {
|
|
897
|
+
return null;
|
|
898
|
+
}
|
|
899
|
+
let validIriMapping = true;
|
|
900
|
+
if (contextValue && expandVocab) {
|
|
901
|
+
const value = Util_1.Util.getContextValueId(contextValue);
|
|
902
|
+
if (value && value !== term) {
|
|
903
|
+
if (typeof value !== "string" || !Util_1.Util.isValidIri(value) && !Util_1.Util.isValidKeyword(value)) {
|
|
904
|
+
if (!Util_1.Util.isPotentialKeyword(value)) {
|
|
905
|
+
validIriMapping = false;
|
|
906
|
+
}
|
|
907
|
+
} else {
|
|
908
|
+
return value;
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
const prefix = Util_1.Util.getPrefix(term, this.contextRaw);
|
|
913
|
+
const vocab = this.contextRaw["@vocab"];
|
|
914
|
+
const vocabRelative = (!!vocab || vocab === "") && vocab.indexOf(":") < 0;
|
|
915
|
+
const base = this.contextRaw["@base"];
|
|
916
|
+
const potentialKeyword = Util_1.Util.isPotentialKeyword(term);
|
|
917
|
+
if (prefix) {
|
|
918
|
+
const contextPrefixValue = this.contextRaw[prefix];
|
|
919
|
+
const value = Util_1.Util.getContextValueId(contextPrefixValue);
|
|
920
|
+
if (value) {
|
|
921
|
+
if (typeof contextPrefixValue === "string" || !options.allowPrefixForcing) {
|
|
922
|
+
if (!Util_1.Util.isSimpleTermDefinitionPrefix(value, options)) {
|
|
923
|
+
return term;
|
|
924
|
+
}
|
|
925
|
+
} else {
|
|
926
|
+
if (value[0] !== "_" && !potentialKeyword && !contextPrefixValue["@prefix"] && !(term in this.contextRaw)) {
|
|
927
|
+
return term;
|
|
928
|
+
}
|
|
929
|
+
}
|
|
930
|
+
return value + term.substr(prefix.length + 1);
|
|
931
|
+
}
|
|
932
|
+
} else if (expandVocab && (vocab || vocab === "" || options.allowVocabRelativeToBase && (base && vocabRelative)) && !potentialKeyword && !Util_1.Util.isCompactIri(term)) {
|
|
933
|
+
if (vocabRelative) {
|
|
934
|
+
if (options.allowVocabRelativeToBase) {
|
|
935
|
+
return (vocab || base ? (0, relative_to_absolute_iri_1.resolve)(vocab, base) : "") + term;
|
|
936
|
+
} else {
|
|
937
|
+
throw new ErrorCoded_1.ErrorCoded(`Relative vocab expansion for term '${term}' with vocab '${vocab}' is not allowed.`, ErrorCoded_1.ERROR_CODES.INVALID_VOCAB_MAPPING);
|
|
938
|
+
}
|
|
939
|
+
} else {
|
|
940
|
+
return vocab + term;
|
|
941
|
+
}
|
|
942
|
+
} else if (!expandVocab && base && !potentialKeyword && !Util_1.Util.isCompactIri(term)) {
|
|
943
|
+
return (0, relative_to_absolute_iri_1.resolve)(term, base);
|
|
944
|
+
}
|
|
945
|
+
if (validIriMapping) {
|
|
946
|
+
return term;
|
|
947
|
+
} else {
|
|
948
|
+
throw new ErrorCoded_1.ErrorCoded(`Invalid IRI mapping found for context entry '${term}': '${JSON.stringify(contextValue)}'`, ErrorCoded_1.ERROR_CODES.INVALID_IRI_MAPPING);
|
|
949
|
+
}
|
|
950
|
+
}
|
|
951
|
+
/**
|
|
952
|
+
* Compact the given term using @base, @vocab, an aliased term, or a prefixed term.
|
|
953
|
+
*
|
|
954
|
+
* This will try to compact the IRI as much as possible.
|
|
955
|
+
*
|
|
956
|
+
* @param {string} iri An IRI to compact.
|
|
957
|
+
* @param {boolean} vocab If the term is a predicate or type and should be compacted based on @vocab,
|
|
958
|
+
* otherwise it is considered a regular term that is compacted based on @base.
|
|
959
|
+
* @return {string} The compacted term or the IRI as-is.
|
|
960
|
+
*/
|
|
961
|
+
compactIri(iri, vocab) {
|
|
962
|
+
if (vocab && this.contextRaw["@vocab"] && iri.startsWith(this.contextRaw["@vocab"])) {
|
|
963
|
+
return iri.substr(this.contextRaw["@vocab"].length);
|
|
964
|
+
}
|
|
965
|
+
if (!vocab && this.contextRaw["@base"] && iri.startsWith(this.contextRaw["@base"])) {
|
|
966
|
+
return iri.substr(this.contextRaw["@base"].length);
|
|
967
|
+
}
|
|
968
|
+
const shortestPrefixing = { prefix: "", suffix: iri };
|
|
969
|
+
for (const key in this.contextRaw) {
|
|
970
|
+
const value = this.contextRaw[key];
|
|
971
|
+
if (value && !Util_1.Util.isPotentialKeyword(key)) {
|
|
972
|
+
const contextIri = Util_1.Util.getContextValueId(value);
|
|
973
|
+
if (iri.startsWith(contextIri)) {
|
|
974
|
+
const suffix = iri.substr(contextIri.length);
|
|
975
|
+
if (!suffix) {
|
|
976
|
+
if (vocab) {
|
|
977
|
+
return key;
|
|
978
|
+
}
|
|
979
|
+
} else if (suffix.length < shortestPrefixing.suffix.length) {
|
|
980
|
+
shortestPrefixing.prefix = key;
|
|
981
|
+
shortestPrefixing.suffix = suffix;
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
if (shortestPrefixing.prefix) {
|
|
987
|
+
return shortestPrefixing.prefix + ":" + shortestPrefixing.suffix;
|
|
988
|
+
}
|
|
989
|
+
return iri;
|
|
990
|
+
}
|
|
991
|
+
}
|
|
992
|
+
exports.JsonLdContextNormalized = JsonLdContextNormalized2;
|
|
993
|
+
exports.defaultExpandOptions = {
|
|
994
|
+
allowPrefixForcing: true,
|
|
995
|
+
allowPrefixNonGenDelims: false,
|
|
996
|
+
allowVocabRelativeToBase: true
|
|
997
|
+
};
|
|
998
|
+
})(JsonLdContextNormalized);
|
|
999
|
+
return JsonLdContextNormalized;
|
|
1000
|
+
}
|
|
1001
|
+
var hasRequiredContextParser;
|
|
1002
|
+
function requireContextParser() {
|
|
1003
|
+
if (hasRequiredContextParser) return ContextParser;
|
|
1004
|
+
hasRequiredContextParser = 1;
|
|
1005
|
+
Object.defineProperty(ContextParser, "__esModule", { value: true });
|
|
1006
|
+
ContextParser.ContextParser = void 0;
|
|
1007
|
+
const relative_to_absolute_iri_1 = requireRelativeToAbsoluteIri();
|
|
1008
|
+
const ErrorCoded_1 = /* @__PURE__ */ requireErrorCoded();
|
|
1009
|
+
const FetchDocumentLoader_1 = /* @__PURE__ */ requireFetchDocumentLoader();
|
|
1010
|
+
const JsonLdContextNormalized_1 = /* @__PURE__ */ requireJsonLdContextNormalized();
|
|
1011
|
+
const Util_1 = /* @__PURE__ */ requireUtil();
|
|
1012
|
+
let ContextParser$1 = class ContextParser2 {
|
|
1013
|
+
constructor(options) {
|
|
1014
|
+
options = options || {};
|
|
1015
|
+
this.documentLoader = options.documentLoader || new FetchDocumentLoader_1.FetchDocumentLoader();
|
|
1016
|
+
this.documentCache = {};
|
|
1017
|
+
this.validateContext = !options.skipValidation;
|
|
1018
|
+
this.expandContentTypeToBase = !!options.expandContentTypeToBase;
|
|
1019
|
+
this.remoteContextsDepthLimit = options.remoteContextsDepthLimit || 32;
|
|
1020
|
+
this.redirectSchemaOrgHttps = "redirectSchemaOrgHttps" in options ? !!options.redirectSchemaOrgHttps : true;
|
|
1021
|
+
}
|
|
1022
|
+
/**
|
|
1023
|
+
* Validate the given @language value.
|
|
1024
|
+
* An error will be thrown if it is invalid.
|
|
1025
|
+
* @param value An @language value.
|
|
1026
|
+
* @param {boolean} strictRange If the string value should be strictly checked against a regex.
|
|
1027
|
+
* @param {string} errorCode The error code to emit on errors.
|
|
1028
|
+
* @return {boolean} If validation passed.
|
|
1029
|
+
* Can only be false if strictRange is false and the string value did not pass the regex.
|
|
1030
|
+
*/
|
|
1031
|
+
static validateLanguage(value, strictRange, errorCode) {
|
|
1032
|
+
if (typeof value !== "string") {
|
|
1033
|
+
throw new ErrorCoded_1.ErrorCoded(`The value of an '@language' must be a string, got '${JSON.stringify(value)}'`, errorCode);
|
|
1034
|
+
}
|
|
1035
|
+
if (!Util_1.Util.REGEX_LANGUAGE_TAG.test(value)) {
|
|
1036
|
+
if (strictRange) {
|
|
1037
|
+
throw new ErrorCoded_1.ErrorCoded(`The value of an '@language' must be a valid language tag, got '${JSON.stringify(value)}'`, errorCode);
|
|
1038
|
+
} else {
|
|
1039
|
+
return false;
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
return true;
|
|
1043
|
+
}
|
|
1044
|
+
/**
|
|
1045
|
+
* Validate the given @direction value.
|
|
1046
|
+
* An error will be thrown if it is invalid.
|
|
1047
|
+
* @param value An @direction value.
|
|
1048
|
+
* @param {boolean} strictValues If the string value should be strictly checked against a regex.
|
|
1049
|
+
* @return {boolean} If validation passed.
|
|
1050
|
+
* Can only be false if strictRange is false and the string value did not pass the regex.
|
|
1051
|
+
*/
|
|
1052
|
+
static validateDirection(value, strictValues) {
|
|
1053
|
+
if (typeof value !== "string") {
|
|
1054
|
+
throw new ErrorCoded_1.ErrorCoded(`The value of an '@direction' must be a string, got '${JSON.stringify(value)}'`, ErrorCoded_1.ERROR_CODES.INVALID_BASE_DIRECTION);
|
|
1055
|
+
}
|
|
1056
|
+
if (!Util_1.Util.REGEX_DIRECTION_TAG.test(value)) {
|
|
1057
|
+
if (strictValues) {
|
|
1058
|
+
throw new ErrorCoded_1.ErrorCoded(`The value of an '@direction' must be 'ltr' or 'rtl', got '${JSON.stringify(value)}'`, ErrorCoded_1.ERROR_CODES.INVALID_BASE_DIRECTION);
|
|
1059
|
+
} else {
|
|
1060
|
+
return false;
|
|
1061
|
+
}
|
|
1062
|
+
}
|
|
1063
|
+
return true;
|
|
1064
|
+
}
|
|
1065
|
+
/**
|
|
1066
|
+
* Add an @id term for all @reverse terms.
|
|
1067
|
+
* @param {IJsonLdContextNormalizedRaw} context A context.
|
|
1068
|
+
* @return {IJsonLdContextNormalizedRaw} The mutated input context.
|
|
1069
|
+
*/
|
|
1070
|
+
idifyReverseTerms(context) {
|
|
1071
|
+
for (const key of Object.keys(context)) {
|
|
1072
|
+
let value = context[key];
|
|
1073
|
+
if (value && typeof value === "object") {
|
|
1074
|
+
if (value["@reverse"] && !value["@id"]) {
|
|
1075
|
+
if (typeof value["@reverse"] !== "string" || Util_1.Util.isValidKeyword(value["@reverse"])) {
|
|
1076
|
+
throw new ErrorCoded_1.ErrorCoded(`Invalid @reverse value, must be absolute IRI or blank node: '${value["@reverse"]}'`, ErrorCoded_1.ERROR_CODES.INVALID_IRI_MAPPING);
|
|
1077
|
+
}
|
|
1078
|
+
value = context[key] = Object.assign(Object.assign({}, value), { "@id": value["@reverse"] });
|
|
1079
|
+
value["@id"] = value["@reverse"];
|
|
1080
|
+
if (Util_1.Util.isPotentialKeyword(value["@reverse"])) {
|
|
1081
|
+
delete value["@reverse"];
|
|
1082
|
+
} else {
|
|
1083
|
+
value["@reverse"] = true;
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1087
|
+
}
|
|
1088
|
+
return context;
|
|
1089
|
+
}
|
|
1090
|
+
/**
|
|
1091
|
+
* Expand all prefixed terms in the given context.
|
|
1092
|
+
* @param {IJsonLdContextNormalizedRaw} context A context.
|
|
1093
|
+
* @param {boolean} expandContentTypeToBase If @type inside the context may be expanded
|
|
1094
|
+
* via @base if @vocab is set to null.
|
|
1095
|
+
* @param {string[]} keys Optional set of keys from the context to expand. If left undefined, all
|
|
1096
|
+
* keys in the context will be expanded.
|
|
1097
|
+
*/
|
|
1098
|
+
expandPrefixedTerms(context, expandContentTypeToBase, keys) {
|
|
1099
|
+
const contextRaw = context.getContextRaw();
|
|
1100
|
+
for (const key of keys || Object.keys(contextRaw)) {
|
|
1101
|
+
if (Util_1.Util.EXPAND_KEYS_BLACKLIST.indexOf(key) < 0 && !Util_1.Util.isReservedInternalKeyword(key)) {
|
|
1102
|
+
const keyValue = contextRaw[key];
|
|
1103
|
+
if (Util_1.Util.isPotentialKeyword(key) && Util_1.Util.ALIAS_DOMAIN_BLACKLIST.indexOf(key) >= 0) {
|
|
1104
|
+
if (key !== "@type" || typeof contextRaw[key] === "object" && !(contextRaw[key]["@protected"] || contextRaw[key]["@container"] === "@set")) {
|
|
1105
|
+
throw new ErrorCoded_1.ErrorCoded(`Keywords can not be aliased to something else.
|
|
1106
|
+
Tried mapping ${key} to ${JSON.stringify(keyValue)}`, ErrorCoded_1.ERROR_CODES.KEYWORD_REDEFINITION);
|
|
1107
|
+
}
|
|
1108
|
+
}
|
|
1109
|
+
if (Util_1.Util.ALIAS_RANGE_BLACKLIST.indexOf(Util_1.Util.getContextValueId(keyValue)) >= 0) {
|
|
1110
|
+
throw new ErrorCoded_1.ErrorCoded(`Aliasing to certain keywords is not allowed.
|
|
1111
|
+
Tried mapping ${key} to ${JSON.stringify(keyValue)}`, ErrorCoded_1.ERROR_CODES.INVALID_KEYWORD_ALIAS);
|
|
1112
|
+
}
|
|
1113
|
+
if (keyValue && Util_1.Util.isPotentialKeyword(Util_1.Util.getContextValueId(keyValue)) && keyValue["@prefix"] === true) {
|
|
1114
|
+
throw new ErrorCoded_1.ErrorCoded(`Tried to use keyword aliases as prefix: '${key}': '${JSON.stringify(keyValue)}'`, ErrorCoded_1.ERROR_CODES.INVALID_TERM_DEFINITION);
|
|
1115
|
+
}
|
|
1116
|
+
while (Util_1.Util.isPrefixValue(contextRaw[key])) {
|
|
1117
|
+
const value = contextRaw[key];
|
|
1118
|
+
let changed = false;
|
|
1119
|
+
if (typeof value === "string") {
|
|
1120
|
+
contextRaw[key] = context.expandTerm(value, true);
|
|
1121
|
+
changed = changed || value !== contextRaw[key];
|
|
1122
|
+
} else {
|
|
1123
|
+
const id = value["@id"];
|
|
1124
|
+
const type = value["@type"];
|
|
1125
|
+
const canAddIdEntry = !("@prefix" in value) || Util_1.Util.isValidIri(key);
|
|
1126
|
+
if ("@id" in value) {
|
|
1127
|
+
if (id !== void 0 && id !== null && typeof id === "string") {
|
|
1128
|
+
contextRaw[key] = Object.assign(Object.assign({}, contextRaw[key]), { "@id": context.expandTerm(id, true) });
|
|
1129
|
+
changed = changed || id !== contextRaw[key]["@id"];
|
|
1130
|
+
}
|
|
1131
|
+
} else if (!Util_1.Util.isPotentialKeyword(key) && canAddIdEntry) {
|
|
1132
|
+
const newId = context.expandTerm(key, true);
|
|
1133
|
+
if (newId !== key) {
|
|
1134
|
+
contextRaw[key] = Object.assign(Object.assign({}, contextRaw[key]), { "@id": newId });
|
|
1135
|
+
changed = true;
|
|
1136
|
+
}
|
|
1137
|
+
}
|
|
1138
|
+
if (type && typeof type === "string" && type !== "@vocab" && (!value["@container"] || !value["@container"]["@type"]) && canAddIdEntry) {
|
|
1139
|
+
let expandedType = context.expandTerm(type, true);
|
|
1140
|
+
if (expandContentTypeToBase && type === expandedType) {
|
|
1141
|
+
expandedType = context.expandTerm(type, false);
|
|
1142
|
+
}
|
|
1143
|
+
if (expandedType !== type) {
|
|
1144
|
+
changed = true;
|
|
1145
|
+
contextRaw[key] = Object.assign(Object.assign({}, contextRaw[key]), { "@type": expandedType });
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
1148
|
+
}
|
|
1149
|
+
if (!changed) {
|
|
1150
|
+
break;
|
|
1151
|
+
}
|
|
1152
|
+
}
|
|
1153
|
+
}
|
|
1154
|
+
}
|
|
1155
|
+
}
|
|
1156
|
+
/**
|
|
1157
|
+
* Normalize the @language entries in the given context to lowercase.
|
|
1158
|
+
* @param {IJsonLdContextNormalizedRaw} context A context.
|
|
1159
|
+
* @param {IParseOptions} parseOptions The parsing options.
|
|
1160
|
+
*/
|
|
1161
|
+
normalize(context, { processingMode, normalizeLanguageTags }) {
|
|
1162
|
+
if (normalizeLanguageTags || processingMode === 1) {
|
|
1163
|
+
for (const key of Object.keys(context)) {
|
|
1164
|
+
if (key === "@language" && typeof context[key] === "string") {
|
|
1165
|
+
context[key] = context[key].toLowerCase();
|
|
1166
|
+
} else {
|
|
1167
|
+
const value = context[key];
|
|
1168
|
+
if (value && typeof value === "object") {
|
|
1169
|
+
if (typeof value["@language"] === "string") {
|
|
1170
|
+
const lowercase = value["@language"].toLowerCase();
|
|
1171
|
+
if (lowercase !== value["@language"]) {
|
|
1172
|
+
context[key] = Object.assign(Object.assign({}, value), { "@language": lowercase });
|
|
1173
|
+
}
|
|
1174
|
+
}
|
|
1175
|
+
}
|
|
1176
|
+
}
|
|
1177
|
+
}
|
|
1178
|
+
}
|
|
1179
|
+
}
|
|
1180
|
+
/**
|
|
1181
|
+
* Convert all @container strings and array values to hash-based values.
|
|
1182
|
+
* @param {IJsonLdContextNormalizedRaw} context A context.
|
|
1183
|
+
*/
|
|
1184
|
+
containersToHash(context) {
|
|
1185
|
+
for (const key of Object.keys(context)) {
|
|
1186
|
+
const value = context[key];
|
|
1187
|
+
if (value && typeof value === "object") {
|
|
1188
|
+
if (typeof value["@container"] === "string") {
|
|
1189
|
+
context[key] = Object.assign(Object.assign({}, value), { "@container": { [value["@container"]]: true } });
|
|
1190
|
+
} else if (Array.isArray(value["@container"])) {
|
|
1191
|
+
const newValue = {};
|
|
1192
|
+
for (const containerValue of value["@container"]) {
|
|
1193
|
+
newValue[containerValue] = true;
|
|
1194
|
+
}
|
|
1195
|
+
context[key] = Object.assign(Object.assign({}, value), { "@container": newValue });
|
|
1196
|
+
}
|
|
1197
|
+
}
|
|
1198
|
+
}
|
|
1199
|
+
}
|
|
1200
|
+
/**
|
|
1201
|
+
* Normalize and apply context-level @protected terms onto each term separately.
|
|
1202
|
+
* @param {IJsonLdContextNormalizedRaw} context A context.
|
|
1203
|
+
* @param {number} processingMode The processing mode.
|
|
1204
|
+
*/
|
|
1205
|
+
applyScopedProtected(context, { processingMode }, expandOptions) {
|
|
1206
|
+
if (processingMode && processingMode >= 1.1) {
|
|
1207
|
+
if (context["@protected"]) {
|
|
1208
|
+
for (const key of Object.keys(context)) {
|
|
1209
|
+
if (Util_1.Util.isReservedInternalKeyword(key)) {
|
|
1210
|
+
continue;
|
|
1211
|
+
}
|
|
1212
|
+
if (!Util_1.Util.isPotentialKeyword(key) && !Util_1.Util.isTermProtected(context, key)) {
|
|
1213
|
+
const value = context[key];
|
|
1214
|
+
if (value && typeof value === "object") {
|
|
1215
|
+
if (!("@protected" in context[key])) {
|
|
1216
|
+
context[key] = Object.assign(Object.assign({}, context[key]), { "@protected": true });
|
|
1217
|
+
}
|
|
1218
|
+
} else {
|
|
1219
|
+
context[key] = {
|
|
1220
|
+
"@id": value,
|
|
1221
|
+
"@protected": true
|
|
1222
|
+
};
|
|
1223
|
+
if (Util_1.Util.isSimpleTermDefinitionPrefix(value, expandOptions)) {
|
|
1224
|
+
context[key] = Object.assign(Object.assign({}, context[key]), { "@prefix": true });
|
|
1225
|
+
}
|
|
1226
|
+
}
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
1229
|
+
delete context["@protected"];
|
|
1230
|
+
}
|
|
1231
|
+
}
|
|
1232
|
+
}
|
|
1233
|
+
/**
|
|
1234
|
+
* Check if the given context inheritance does not contain any overrides of protected terms.
|
|
1235
|
+
* @param {IJsonLdContextNormalizedRaw} contextBefore The context that may contain some protected terms.
|
|
1236
|
+
* @param {IJsonLdContextNormalizedRaw} contextAfter A new context that is being applied on the first one.
|
|
1237
|
+
* @param {IExpandOptions} expandOptions Options that are needed for any expansions during this validation.
|
|
1238
|
+
* @param {string[]} keys Optional set of keys from the context to validate. If left undefined, all
|
|
1239
|
+
* keys defined in contextAfter will be checked.
|
|
1240
|
+
*/
|
|
1241
|
+
validateKeywordRedefinitions(contextBefore, contextAfter, expandOptions, keys) {
|
|
1242
|
+
for (const key of keys !== null && keys !== void 0 ? keys : Object.keys(contextAfter)) {
|
|
1243
|
+
if (Util_1.Util.isTermProtected(contextBefore, key)) {
|
|
1244
|
+
if (typeof contextAfter[key] === "string") {
|
|
1245
|
+
contextAfter[key] = { "@id": contextAfter[key], "@protected": true };
|
|
1246
|
+
} else {
|
|
1247
|
+
contextAfter[key] = Object.assign(Object.assign({}, contextAfter[key]), { "@protected": true });
|
|
1248
|
+
}
|
|
1249
|
+
if (!Util_1.Util.deepEqual(contextBefore[key], contextAfter[key])) {
|
|
1250
|
+
throw new ErrorCoded_1.ErrorCoded(`Attempted to override the protected keyword ${key} from ${JSON.stringify(Util_1.Util.getContextValueId(contextBefore[key]))} to ${JSON.stringify(Util_1.Util.getContextValueId(contextAfter[key]))}`, ErrorCoded_1.ERROR_CODES.PROTECTED_TERM_REDEFINITION);
|
|
1251
|
+
}
|
|
1252
|
+
}
|
|
1253
|
+
}
|
|
1254
|
+
}
|
|
1255
|
+
/**
|
|
1256
|
+
* Validate the entries of the given context.
|
|
1257
|
+
* @param {IJsonLdContextNormalizedRaw} context A context.
|
|
1258
|
+
* @param {IParseOptions} options The parse options.
|
|
1259
|
+
*/
|
|
1260
|
+
validate(context, { processingMode }) {
|
|
1261
|
+
for (const key of Object.keys(context)) {
|
|
1262
|
+
if (Util_1.Util.isReservedInternalKeyword(key)) {
|
|
1263
|
+
continue;
|
|
1264
|
+
}
|
|
1265
|
+
if (key === "") {
|
|
1266
|
+
throw new ErrorCoded_1.ErrorCoded(`The empty term is not allowed, got: '${key}': '${JSON.stringify(context[key])}'`, ErrorCoded_1.ERROR_CODES.INVALID_TERM_DEFINITION);
|
|
1267
|
+
}
|
|
1268
|
+
const value = context[key];
|
|
1269
|
+
const valueType = typeof value;
|
|
1270
|
+
if (Util_1.Util.isPotentialKeyword(key)) {
|
|
1271
|
+
switch (key.substr(1)) {
|
|
1272
|
+
case "vocab":
|
|
1273
|
+
if (value !== null && valueType !== "string") {
|
|
1274
|
+
throw new ErrorCoded_1.ErrorCoded(`Found an invalid @vocab IRI: ${value}`, ErrorCoded_1.ERROR_CODES.INVALID_VOCAB_MAPPING);
|
|
1275
|
+
}
|
|
1276
|
+
break;
|
|
1277
|
+
case "base":
|
|
1278
|
+
if (value !== null && valueType !== "string") {
|
|
1279
|
+
throw new ErrorCoded_1.ErrorCoded(`Found an invalid @base IRI: ${context[key]}`, ErrorCoded_1.ERROR_CODES.INVALID_BASE_IRI);
|
|
1280
|
+
}
|
|
1281
|
+
break;
|
|
1282
|
+
case "language":
|
|
1283
|
+
if (value !== null) {
|
|
1284
|
+
ContextParser2.validateLanguage(value, true, ErrorCoded_1.ERROR_CODES.INVALID_DEFAULT_LANGUAGE);
|
|
1285
|
+
}
|
|
1286
|
+
break;
|
|
1287
|
+
case "version":
|
|
1288
|
+
if (value !== null && valueType !== "number") {
|
|
1289
|
+
throw new ErrorCoded_1.ErrorCoded(`Found an invalid @version number: ${value}`, ErrorCoded_1.ERROR_CODES.INVALID_VERSION_VALUE);
|
|
1290
|
+
}
|
|
1291
|
+
break;
|
|
1292
|
+
case "direction":
|
|
1293
|
+
if (value !== null) {
|
|
1294
|
+
ContextParser2.validateDirection(value, true);
|
|
1295
|
+
}
|
|
1296
|
+
break;
|
|
1297
|
+
case "propagate":
|
|
1298
|
+
if (processingMode === 1) {
|
|
1299
|
+
throw new ErrorCoded_1.ErrorCoded(`Found an illegal @propagate keyword: ${value}`, ErrorCoded_1.ERROR_CODES.INVALID_CONTEXT_ENTRY);
|
|
1300
|
+
}
|
|
1301
|
+
if (value !== null && valueType !== "boolean") {
|
|
1302
|
+
throw new ErrorCoded_1.ErrorCoded(`Found an invalid @propagate value: ${value}`, ErrorCoded_1.ERROR_CODES.INVALID_PROPAGATE_VALUE);
|
|
1303
|
+
}
|
|
1304
|
+
break;
|
|
1305
|
+
}
|
|
1306
|
+
if (Util_1.Util.isValidKeyword(key) && Util_1.Util.isValidKeyword(Util_1.Util.getContextValueId(value))) {
|
|
1307
|
+
throw new ErrorCoded_1.ErrorCoded(`Illegal keyword alias in term value, found: '${key}': '${Util_1.Util.getContextValueId(value)}'`, ErrorCoded_1.ERROR_CODES.KEYWORD_REDEFINITION);
|
|
1308
|
+
}
|
|
1309
|
+
continue;
|
|
1310
|
+
}
|
|
1311
|
+
if (value !== null) {
|
|
1312
|
+
switch (valueType) {
|
|
1313
|
+
case "string":
|
|
1314
|
+
if (Util_1.Util.getPrefix(value, context) === key) {
|
|
1315
|
+
throw new ErrorCoded_1.ErrorCoded(`Detected cyclical IRI mapping in context entry: '${key}': '${JSON.stringify(value)}'`, ErrorCoded_1.ERROR_CODES.CYCLIC_IRI_MAPPING);
|
|
1316
|
+
}
|
|
1317
|
+
if (Util_1.Util.isValidIriWeak(key)) {
|
|
1318
|
+
if (value === "@type") {
|
|
1319
|
+
throw new ErrorCoded_1.ErrorCoded(`IRIs can not be mapped to @type, found: '${key}': '${value}'`, ErrorCoded_1.ERROR_CODES.INVALID_IRI_MAPPING);
|
|
1320
|
+
} else if (Util_1.Util.isValidIri(value) && value !== new JsonLdContextNormalized_1.JsonLdContextNormalized(context).expandTerm(key)) {
|
|
1321
|
+
throw new ErrorCoded_1.ErrorCoded(`IRIs can not be mapped to other IRIs, found: '${key}': '${value}'`, ErrorCoded_1.ERROR_CODES.INVALID_IRI_MAPPING);
|
|
1322
|
+
}
|
|
1323
|
+
}
|
|
1324
|
+
break;
|
|
1325
|
+
case "object":
|
|
1326
|
+
if (!Util_1.Util.isCompactIri(key) && !("@id" in value) && (value["@type"] === "@id" ? !context["@base"] : !context["@vocab"])) {
|
|
1327
|
+
throw new ErrorCoded_1.ErrorCoded(`Missing @id in context entry: '${key}': '${JSON.stringify(value)}'`, ErrorCoded_1.ERROR_CODES.INVALID_IRI_MAPPING);
|
|
1328
|
+
}
|
|
1329
|
+
for (const objectKey of Object.keys(value)) {
|
|
1330
|
+
const objectValue = value[objectKey];
|
|
1331
|
+
if (!objectValue) {
|
|
1332
|
+
continue;
|
|
1333
|
+
}
|
|
1334
|
+
switch (objectKey) {
|
|
1335
|
+
case "@id":
|
|
1336
|
+
if (Util_1.Util.isValidKeyword(objectValue) && objectValue !== "@type" && objectValue !== "@id" && objectValue !== "@graph" && objectValue !== "@nest") {
|
|
1337
|
+
throw new ErrorCoded_1.ErrorCoded(`Illegal keyword alias in term value, found: '${key}': '${JSON.stringify(value)}'`, ErrorCoded_1.ERROR_CODES.INVALID_IRI_MAPPING);
|
|
1338
|
+
}
|
|
1339
|
+
if (Util_1.Util.isValidIriWeak(key)) {
|
|
1340
|
+
if (objectValue === "@type") {
|
|
1341
|
+
throw new ErrorCoded_1.ErrorCoded(`IRIs can not be mapped to @type, found: '${key}': '${JSON.stringify(value)}'`, ErrorCoded_1.ERROR_CODES.INVALID_IRI_MAPPING);
|
|
1342
|
+
} else if (Util_1.Util.isValidIri(objectValue) && objectValue !== new JsonLdContextNormalized_1.JsonLdContextNormalized(context).expandTerm(key)) {
|
|
1343
|
+
throw new ErrorCoded_1.ErrorCoded(`IRIs can not be mapped to other IRIs, found: '${key}': '${JSON.stringify(value)}'`, ErrorCoded_1.ERROR_CODES.INVALID_IRI_MAPPING);
|
|
1344
|
+
}
|
|
1345
|
+
}
|
|
1346
|
+
if (typeof objectValue !== "string") {
|
|
1347
|
+
throw new ErrorCoded_1.ErrorCoded(`Detected non-string @id in context entry: '${key}': '${JSON.stringify(value)}'`, ErrorCoded_1.ERROR_CODES.INVALID_IRI_MAPPING);
|
|
1348
|
+
}
|
|
1349
|
+
if (Util_1.Util.getPrefix(objectValue, context) === key) {
|
|
1350
|
+
throw new ErrorCoded_1.ErrorCoded(`Detected cyclical IRI mapping in context entry: '${key}': '${JSON.stringify(value)}'`, ErrorCoded_1.ERROR_CODES.CYCLIC_IRI_MAPPING);
|
|
1351
|
+
}
|
|
1352
|
+
break;
|
|
1353
|
+
case "@type":
|
|
1354
|
+
if (value["@container"] === "@type" && objectValue !== "@id" && objectValue !== "@vocab") {
|
|
1355
|
+
throw new ErrorCoded_1.ErrorCoded(`@container: @type only allows @type: @id or @vocab, but got: '${key}': '${objectValue}'`, ErrorCoded_1.ERROR_CODES.INVALID_TYPE_MAPPING);
|
|
1356
|
+
}
|
|
1357
|
+
if (typeof objectValue !== "string") {
|
|
1358
|
+
throw new ErrorCoded_1.ErrorCoded(`The value of an '@type' must be a string, got '${JSON.stringify(valueType)}'`, ErrorCoded_1.ERROR_CODES.INVALID_TYPE_MAPPING);
|
|
1359
|
+
}
|
|
1360
|
+
if (objectValue !== "@id" && objectValue !== "@vocab" && (processingMode === 1 || objectValue !== "@json") && (processingMode === 1 || objectValue !== "@none") && (objectValue[0] === "_" || !Util_1.Util.isValidIri(objectValue))) {
|
|
1361
|
+
throw new ErrorCoded_1.ErrorCoded(`A context @type must be an absolute IRI, found: '${key}': '${objectValue}'`, ErrorCoded_1.ERROR_CODES.INVALID_TYPE_MAPPING);
|
|
1362
|
+
}
|
|
1363
|
+
break;
|
|
1364
|
+
case "@reverse":
|
|
1365
|
+
if (typeof objectValue === "string" && value["@id"] && value["@id"] !== objectValue) {
|
|
1366
|
+
throw new ErrorCoded_1.ErrorCoded(`Found non-matching @id and @reverse term values in '${key}':'${objectValue}' and '${value["@id"]}'`, ErrorCoded_1.ERROR_CODES.INVALID_REVERSE_PROPERTY);
|
|
1367
|
+
}
|
|
1368
|
+
if ("@nest" in value) {
|
|
1369
|
+
throw new ErrorCoded_1.ErrorCoded(`@nest is not allowed in the reverse property '${key}'`, ErrorCoded_1.ERROR_CODES.INVALID_REVERSE_PROPERTY);
|
|
1370
|
+
}
|
|
1371
|
+
break;
|
|
1372
|
+
case "@container":
|
|
1373
|
+
if (processingMode === 1) {
|
|
1374
|
+
if (Object.keys(objectValue).length > 1 || Util_1.Util.CONTAINERS_1_0.indexOf(Object.keys(objectValue)[0]) < 0) {
|
|
1375
|
+
throw new ErrorCoded_1.ErrorCoded(`Invalid term @container for '${key}' ('${Object.keys(objectValue)}') in 1.0, must be only one of ${Util_1.Util.CONTAINERS_1_0.join(", ")}`, ErrorCoded_1.ERROR_CODES.INVALID_CONTAINER_MAPPING);
|
|
1376
|
+
}
|
|
1377
|
+
}
|
|
1378
|
+
for (const containerValue of Object.keys(objectValue)) {
|
|
1379
|
+
if (containerValue === "@list" && value["@reverse"]) {
|
|
1380
|
+
throw new ErrorCoded_1.ErrorCoded(`Term value can not be @container: @list and @reverse at the same time on '${key}'`, ErrorCoded_1.ERROR_CODES.INVALID_REVERSE_PROPERTY);
|
|
1381
|
+
}
|
|
1382
|
+
if (Util_1.Util.CONTAINERS.indexOf(containerValue) < 0) {
|
|
1383
|
+
throw new ErrorCoded_1.ErrorCoded(`Invalid term @container for '${key}' ('${containerValue}'), must be one of ${Util_1.Util.CONTAINERS.join(", ")}`, ErrorCoded_1.ERROR_CODES.INVALID_CONTAINER_MAPPING);
|
|
1384
|
+
}
|
|
1385
|
+
}
|
|
1386
|
+
break;
|
|
1387
|
+
case "@language":
|
|
1388
|
+
ContextParser2.validateLanguage(objectValue, true, ErrorCoded_1.ERROR_CODES.INVALID_LANGUAGE_MAPPING);
|
|
1389
|
+
break;
|
|
1390
|
+
case "@direction":
|
|
1391
|
+
ContextParser2.validateDirection(objectValue, true);
|
|
1392
|
+
break;
|
|
1393
|
+
case "@prefix":
|
|
1394
|
+
if (objectValue !== null && typeof objectValue !== "boolean") {
|
|
1395
|
+
throw new ErrorCoded_1.ErrorCoded(`Found an invalid term @prefix boolean in: '${key}': '${JSON.stringify(value)}'`, ErrorCoded_1.ERROR_CODES.INVALID_PREFIX_VALUE);
|
|
1396
|
+
}
|
|
1397
|
+
if (!("@id" in value) && !Util_1.Util.isValidIri(key)) {
|
|
1398
|
+
throw new ErrorCoded_1.ErrorCoded(`Invalid @prefix definition for '${key}' ('${JSON.stringify(value)}'`, ErrorCoded_1.ERROR_CODES.INVALID_TERM_DEFINITION);
|
|
1399
|
+
}
|
|
1400
|
+
break;
|
|
1401
|
+
case "@index":
|
|
1402
|
+
if (processingMode === 1 || !value["@container"] || !value["@container"]["@index"]) {
|
|
1403
|
+
throw new ErrorCoded_1.ErrorCoded(`Attempt to add illegal key to value object: '${key}': '${JSON.stringify(value)}'`, ErrorCoded_1.ERROR_CODES.INVALID_TERM_DEFINITION);
|
|
1404
|
+
}
|
|
1405
|
+
break;
|
|
1406
|
+
case "@nest":
|
|
1407
|
+
if (Util_1.Util.isPotentialKeyword(objectValue) && objectValue !== "@nest") {
|
|
1408
|
+
throw new ErrorCoded_1.ErrorCoded(`Found an invalid term @nest value in: '${key}': '${JSON.stringify(value)}'`, ErrorCoded_1.ERROR_CODES.INVALID_NEST_VALUE);
|
|
1409
|
+
}
|
|
1410
|
+
}
|
|
1411
|
+
}
|
|
1412
|
+
break;
|
|
1413
|
+
default:
|
|
1414
|
+
throw new ErrorCoded_1.ErrorCoded(`Found an invalid term value: '${key}': '${value}'`, ErrorCoded_1.ERROR_CODES.INVALID_TERM_DEFINITION);
|
|
1415
|
+
}
|
|
1416
|
+
}
|
|
1417
|
+
}
|
|
1418
|
+
}
|
|
1419
|
+
/**
|
|
1420
|
+
* Apply the @base context entry to the given context under certain circumstances.
|
|
1421
|
+
* @param context A context.
|
|
1422
|
+
* @param options Parsing options.
|
|
1423
|
+
* @param inheritFromParent If the @base value from the parent context can be inherited.
|
|
1424
|
+
* @return The given context.
|
|
1425
|
+
*/
|
|
1426
|
+
applyBaseEntry(context, options, inheritFromParent) {
|
|
1427
|
+
if (typeof context === "string") {
|
|
1428
|
+
return context;
|
|
1429
|
+
}
|
|
1430
|
+
if (inheritFromParent && !("@base" in context) && options.parentContext && typeof options.parentContext === "object" && "@base" in options.parentContext) {
|
|
1431
|
+
context["@base"] = options.parentContext["@base"];
|
|
1432
|
+
if (options.parentContext["@__baseDocument"]) {
|
|
1433
|
+
context["@__baseDocument"] = true;
|
|
1434
|
+
}
|
|
1435
|
+
}
|
|
1436
|
+
if (options.baseIRI && !options.external) {
|
|
1437
|
+
if (!("@base" in context)) {
|
|
1438
|
+
context["@base"] = options.baseIRI;
|
|
1439
|
+
context["@__baseDocument"] = true;
|
|
1440
|
+
} else if (context["@base"] !== null && typeof context["@base"] === "string" && !Util_1.Util.isValidIri(context["@base"])) {
|
|
1441
|
+
context["@base"] = (0, relative_to_absolute_iri_1.resolve)(context["@base"], options.parentContext && options.parentContext["@base"] || options.baseIRI);
|
|
1442
|
+
}
|
|
1443
|
+
}
|
|
1444
|
+
return context;
|
|
1445
|
+
}
|
|
1446
|
+
/**
|
|
1447
|
+
* Resolve relative context IRIs, or return full IRIs as-is.
|
|
1448
|
+
* @param {string} contextIri A context IRI.
|
|
1449
|
+
* @param {string} baseIRI A base IRI.
|
|
1450
|
+
* @return {string} The normalized context IRI.
|
|
1451
|
+
*/
|
|
1452
|
+
normalizeContextIri(contextIri, baseIRI) {
|
|
1453
|
+
if (!Util_1.Util.isValidIri(contextIri)) {
|
|
1454
|
+
try {
|
|
1455
|
+
contextIri = (0, relative_to_absolute_iri_1.resolve)(contextIri, baseIRI);
|
|
1456
|
+
} catch (_a) {
|
|
1457
|
+
throw new Error(`Invalid context IRI: ${contextIri}`);
|
|
1458
|
+
}
|
|
1459
|
+
}
|
|
1460
|
+
if (this.redirectSchemaOrgHttps && contextIri.startsWith("http://schema.org")) {
|
|
1461
|
+
contextIri = "https://schema.org/";
|
|
1462
|
+
}
|
|
1463
|
+
return contextIri;
|
|
1464
|
+
}
|
|
1465
|
+
/**
|
|
1466
|
+
* Parse scoped contexts in the given context.
|
|
1467
|
+
* @param {IJsonLdContextNormalizedRaw} context A context.
|
|
1468
|
+
* @param {IParseOptions} options Parsing options.
|
|
1469
|
+
* @return {IJsonLdContextNormalizedRaw} The mutated input context.
|
|
1470
|
+
* @param {string[]} keys Optional set of keys from the context to parseInnerContexts of. If left undefined, all
|
|
1471
|
+
* keys in the context will be iterated over.
|
|
1472
|
+
*/
|
|
1473
|
+
async parseInnerContexts(context, options, keys) {
|
|
1474
|
+
for (const key of keys !== null && keys !== void 0 ? keys : Object.keys(context)) {
|
|
1475
|
+
const value = context[key];
|
|
1476
|
+
if (value && typeof value === "object") {
|
|
1477
|
+
if ("@context" in value && value["@context"] !== null && !options.ignoreScopedContexts) {
|
|
1478
|
+
if (this.validateContext) {
|
|
1479
|
+
try {
|
|
1480
|
+
const parentContext = Object.assign(Object.assign({}, context), { [key]: Object.assign({}, context[key]) });
|
|
1481
|
+
delete parentContext[key]["@context"];
|
|
1482
|
+
await this.parse(value["@context"], Object.assign(Object.assign({}, options), { external: false, parentContext, ignoreProtection: true, ignoreRemoteScopedContexts: true, ignoreScopedContexts: true }));
|
|
1483
|
+
} catch (e) {
|
|
1484
|
+
throw new ErrorCoded_1.ErrorCoded(e.message, ErrorCoded_1.ERROR_CODES.INVALID_SCOPED_CONTEXT);
|
|
1485
|
+
}
|
|
1486
|
+
}
|
|
1487
|
+
context[key] = Object.assign(Object.assign({}, value), { "@context": (await this.parse(value["@context"], Object.assign(Object.assign({}, options), { external: false, minimalProcessing: true, ignoreRemoteScopedContexts: true, parentContext: context }))).getContextRaw() });
|
|
1488
|
+
}
|
|
1489
|
+
}
|
|
1490
|
+
}
|
|
1491
|
+
return context;
|
|
1492
|
+
}
|
|
1493
|
+
async parse(context, options = {}, internalOptions = {}) {
|
|
1494
|
+
const { baseIRI, parentContext, external, processingMode = ContextParser2.DEFAULT_PROCESSING_MODE, normalizeLanguageTags, ignoreProtection, minimalProcessing } = options;
|
|
1495
|
+
const remoteContexts = options.remoteContexts || {};
|
|
1496
|
+
if (Object.keys(remoteContexts).length >= this.remoteContextsDepthLimit) {
|
|
1497
|
+
throw new ErrorCoded_1.ErrorCoded("Detected an overflow in remote context inclusions: " + Object.keys(remoteContexts), ErrorCoded_1.ERROR_CODES.CONTEXT_OVERFLOW);
|
|
1498
|
+
}
|
|
1499
|
+
if (context === null || context === void 0) {
|
|
1500
|
+
if (!ignoreProtection && parentContext && Util_1.Util.hasProtectedTerms(parentContext)) {
|
|
1501
|
+
throw new ErrorCoded_1.ErrorCoded("Illegal context nullification when terms are protected", ErrorCoded_1.ERROR_CODES.INVALID_CONTEXT_NULLIFICATION);
|
|
1502
|
+
}
|
|
1503
|
+
return new JsonLdContextNormalized_1.JsonLdContextNormalized(this.applyBaseEntry({}, options, false));
|
|
1504
|
+
} else if (typeof context === "string") {
|
|
1505
|
+
const contextIri = this.normalizeContextIri(context, baseIRI);
|
|
1506
|
+
const overriddenLoad = this.getOverriddenLoad(contextIri, options);
|
|
1507
|
+
if (overriddenLoad) {
|
|
1508
|
+
return new JsonLdContextNormalized_1.JsonLdContextNormalized(overriddenLoad);
|
|
1509
|
+
}
|
|
1510
|
+
const parsedStringContext = await this.parse(await this.load(contextIri), Object.assign(Object.assign({}, options), { baseIRI: contextIri, external: true, remoteContexts: Object.assign(Object.assign({}, remoteContexts), { [contextIri]: true }) }));
|
|
1511
|
+
this.applyBaseEntry(parsedStringContext.getContextRaw(), options, true);
|
|
1512
|
+
return parsedStringContext;
|
|
1513
|
+
} else if (Array.isArray(context)) {
|
|
1514
|
+
const contextIris = [];
|
|
1515
|
+
const contexts = await Promise.all(context.map((subContext, i) => {
|
|
1516
|
+
if (typeof subContext === "string") {
|
|
1517
|
+
const contextIri = this.normalizeContextIri(subContext, baseIRI);
|
|
1518
|
+
contextIris[i] = contextIri;
|
|
1519
|
+
const overriddenLoad = this.getOverriddenLoad(contextIri, options);
|
|
1520
|
+
if (overriddenLoad) {
|
|
1521
|
+
return overriddenLoad;
|
|
1522
|
+
}
|
|
1523
|
+
return this.load(contextIri);
|
|
1524
|
+
} else {
|
|
1525
|
+
return subContext;
|
|
1526
|
+
}
|
|
1527
|
+
}));
|
|
1528
|
+
if (minimalProcessing) {
|
|
1529
|
+
return new JsonLdContextNormalized_1.JsonLdContextNormalized(contexts);
|
|
1530
|
+
}
|
|
1531
|
+
const reducedContexts = await contexts.reduce((accContextPromise, contextEntry, i) => accContextPromise.then((accContext) => this.parse(
|
|
1532
|
+
contextEntry,
|
|
1533
|
+
Object.assign(Object.assign({}, options), { baseIRI: contextIris[i] || options.baseIRI, external: !!contextIris[i] || options.external, parentContext: accContext.getContextRaw(), remoteContexts: contextIris[i] ? Object.assign(Object.assign({}, remoteContexts), { [contextIris[i]]: true }) : remoteContexts }),
|
|
1534
|
+
// @ts-expect-error: This third argument causes a type error because we have hidden it from consumers
|
|
1535
|
+
{
|
|
1536
|
+
skipValidation: i < contexts.length - 1
|
|
1537
|
+
}
|
|
1538
|
+
)), Promise.resolve(new JsonLdContextNormalized_1.JsonLdContextNormalized(parentContext || {})));
|
|
1539
|
+
this.applyBaseEntry(reducedContexts.getContextRaw(), options, true);
|
|
1540
|
+
return reducedContexts;
|
|
1541
|
+
} else if (typeof context === "object") {
|
|
1542
|
+
if ("@context" in context) {
|
|
1543
|
+
return await this.parse(context["@context"], options);
|
|
1544
|
+
}
|
|
1545
|
+
context = Object.assign({}, context);
|
|
1546
|
+
if (external) {
|
|
1547
|
+
delete context["@base"];
|
|
1548
|
+
}
|
|
1549
|
+
this.applyBaseEntry(context, options, true);
|
|
1550
|
+
this.containersToHash(context);
|
|
1551
|
+
if (minimalProcessing) {
|
|
1552
|
+
return new JsonLdContextNormalized_1.JsonLdContextNormalized(context);
|
|
1553
|
+
}
|
|
1554
|
+
let importContext = {};
|
|
1555
|
+
if ("@import" in context) {
|
|
1556
|
+
if (processingMode >= 1.1) {
|
|
1557
|
+
if (typeof context["@import"] !== "string") {
|
|
1558
|
+
throw new ErrorCoded_1.ErrorCoded("An @import value must be a string, but got " + typeof context["@import"], ErrorCoded_1.ERROR_CODES.INVALID_IMPORT_VALUE);
|
|
1559
|
+
}
|
|
1560
|
+
importContext = await this.loadImportContext(this.normalizeContextIri(context["@import"], baseIRI));
|
|
1561
|
+
delete context["@import"];
|
|
1562
|
+
} else {
|
|
1563
|
+
throw new ErrorCoded_1.ErrorCoded("Context importing is not supported in JSON-LD 1.0", ErrorCoded_1.ERROR_CODES.INVALID_CONTEXT_ENTRY);
|
|
1564
|
+
}
|
|
1565
|
+
}
|
|
1566
|
+
this.applyScopedProtected(importContext, { processingMode }, JsonLdContextNormalized_1.defaultExpandOptions);
|
|
1567
|
+
const newContext = Object.assign(importContext, context);
|
|
1568
|
+
this.idifyReverseTerms(newContext);
|
|
1569
|
+
this.normalize(newContext, { processingMode, normalizeLanguageTags });
|
|
1570
|
+
this.applyScopedProtected(newContext, { processingMode }, JsonLdContextNormalized_1.defaultExpandOptions);
|
|
1571
|
+
const keys = Object.keys(newContext);
|
|
1572
|
+
const overlappingKeys = [];
|
|
1573
|
+
if (typeof parentContext === "object") {
|
|
1574
|
+
for (const key in parentContext) {
|
|
1575
|
+
if (key in newContext) {
|
|
1576
|
+
overlappingKeys.push(key);
|
|
1577
|
+
} else {
|
|
1578
|
+
newContext[key] = parentContext[key];
|
|
1579
|
+
}
|
|
1580
|
+
}
|
|
1581
|
+
}
|
|
1582
|
+
await this.parseInnerContexts(newContext, options, keys);
|
|
1583
|
+
const newContextWrapped = new JsonLdContextNormalized_1.JsonLdContextNormalized(newContext);
|
|
1584
|
+
if ((newContext && newContext["@version"] || ContextParser2.DEFAULT_PROCESSING_MODE) >= 1.1 && (context["@vocab"] && typeof context["@vocab"] === "string" || context["@vocab"] === "")) {
|
|
1585
|
+
if (parentContext && "@vocab" in parentContext && context["@vocab"].indexOf(":") < 0) {
|
|
1586
|
+
newContext["@vocab"] = parentContext["@vocab"] + context["@vocab"];
|
|
1587
|
+
} else if (Util_1.Util.isCompactIri(context["@vocab"]) || context["@vocab"] in newContext) {
|
|
1588
|
+
newContext["@vocab"] = newContextWrapped.expandTerm(context["@vocab"], true);
|
|
1589
|
+
}
|
|
1590
|
+
}
|
|
1591
|
+
this.expandPrefixedTerms(newContextWrapped, this.expandContentTypeToBase, keys);
|
|
1592
|
+
if (!ignoreProtection && parentContext && processingMode >= 1.1) {
|
|
1593
|
+
this.validateKeywordRedefinitions(parentContext, newContext, JsonLdContextNormalized_1.defaultExpandOptions, overlappingKeys);
|
|
1594
|
+
}
|
|
1595
|
+
if (this.validateContext && !internalOptions.skipValidation) {
|
|
1596
|
+
this.validate(newContext, { processingMode });
|
|
1597
|
+
}
|
|
1598
|
+
return newContextWrapped;
|
|
1599
|
+
} else {
|
|
1600
|
+
throw new ErrorCoded_1.ErrorCoded(`Tried parsing a context that is not a string, array or object, but got ${context}`, ErrorCoded_1.ERROR_CODES.INVALID_LOCAL_CONTEXT);
|
|
1601
|
+
}
|
|
1602
|
+
}
|
|
1603
|
+
/**
|
|
1604
|
+
* Fetch the given URL as a raw JSON-LD context.
|
|
1605
|
+
* @param url An URL.
|
|
1606
|
+
* @return A promise resolving to a raw JSON-LD context.
|
|
1607
|
+
*/
|
|
1608
|
+
async load(url) {
|
|
1609
|
+
const cached = this.documentCache[url];
|
|
1610
|
+
if (cached) {
|
|
1611
|
+
return cached;
|
|
1612
|
+
}
|
|
1613
|
+
let document2;
|
|
1614
|
+
try {
|
|
1615
|
+
document2 = await this.documentLoader.load(url);
|
|
1616
|
+
} catch (e) {
|
|
1617
|
+
throw new ErrorCoded_1.ErrorCoded(`Failed to load remote context ${url}: ${e.message}`, ErrorCoded_1.ERROR_CODES.LOADING_REMOTE_CONTEXT_FAILED);
|
|
1618
|
+
}
|
|
1619
|
+
if (!("@context" in document2)) {
|
|
1620
|
+
throw new ErrorCoded_1.ErrorCoded(`Missing @context in remote context at ${url}`, ErrorCoded_1.ERROR_CODES.INVALID_REMOTE_CONTEXT);
|
|
1621
|
+
}
|
|
1622
|
+
return this.documentCache[url] = document2["@context"];
|
|
1623
|
+
}
|
|
1624
|
+
/**
|
|
1625
|
+
* Override the given context that may be loaded.
|
|
1626
|
+
*
|
|
1627
|
+
* This will check whether or not the url is recursively being loaded.
|
|
1628
|
+
* @param url An URL.
|
|
1629
|
+
* @param options Parsing options.
|
|
1630
|
+
* @return An overridden context, or null.
|
|
1631
|
+
* Optionally an error can be thrown if a cyclic context is detected.
|
|
1632
|
+
*/
|
|
1633
|
+
getOverriddenLoad(url, options) {
|
|
1634
|
+
if (url in (options.remoteContexts || {})) {
|
|
1635
|
+
if (options.ignoreRemoteScopedContexts) {
|
|
1636
|
+
return url;
|
|
1637
|
+
} else {
|
|
1638
|
+
throw new ErrorCoded_1.ErrorCoded("Detected a cyclic context inclusion of " + url, ErrorCoded_1.ERROR_CODES.RECURSIVE_CONTEXT_INCLUSION);
|
|
1639
|
+
}
|
|
1640
|
+
}
|
|
1641
|
+
return null;
|
|
1642
|
+
}
|
|
1643
|
+
/**
|
|
1644
|
+
* Load an @import'ed context.
|
|
1645
|
+
* @param importContextIri The full URI of an @import value.
|
|
1646
|
+
*/
|
|
1647
|
+
async loadImportContext(importContextIri) {
|
|
1648
|
+
let importContext = await this.load(importContextIri);
|
|
1649
|
+
if (typeof importContext !== "object" || Array.isArray(importContext)) {
|
|
1650
|
+
throw new ErrorCoded_1.ErrorCoded("An imported context must be a single object: " + importContextIri, ErrorCoded_1.ERROR_CODES.INVALID_REMOTE_CONTEXT);
|
|
1651
|
+
}
|
|
1652
|
+
if ("@import" in importContext) {
|
|
1653
|
+
throw new ErrorCoded_1.ErrorCoded("An imported context can not import another context: " + importContextIri, ErrorCoded_1.ERROR_CODES.INVALID_CONTEXT_ENTRY);
|
|
1654
|
+
}
|
|
1655
|
+
importContext = Object.assign({}, importContext);
|
|
1656
|
+
this.containersToHash(importContext);
|
|
1657
|
+
return importContext;
|
|
1658
|
+
}
|
|
1659
|
+
};
|
|
1660
|
+
ContextParser$1.DEFAULT_PROCESSING_MODE = 1.1;
|
|
1661
|
+
ContextParser.ContextParser = ContextParser$1;
|
|
1662
|
+
return ContextParser;
|
|
1663
|
+
}
|
|
1664
|
+
var IDocumentLoader = {};
|
|
1665
|
+
var hasRequiredIDocumentLoader;
|
|
1666
|
+
function requireIDocumentLoader() {
|
|
1667
|
+
if (hasRequiredIDocumentLoader) return IDocumentLoader;
|
|
1668
|
+
hasRequiredIDocumentLoader = 1;
|
|
1669
|
+
Object.defineProperty(IDocumentLoader, "__esModule", { value: true });
|
|
1670
|
+
return IDocumentLoader;
|
|
1671
|
+
}
|
|
1672
|
+
var JsonLdContext = {};
|
|
1673
|
+
var hasRequiredJsonLdContext;
|
|
1674
|
+
function requireJsonLdContext() {
|
|
1675
|
+
if (hasRequiredJsonLdContext) return JsonLdContext;
|
|
1676
|
+
hasRequiredJsonLdContext = 1;
|
|
1677
|
+
Object.defineProperty(JsonLdContext, "__esModule", { value: true });
|
|
1678
|
+
return JsonLdContext;
|
|
1679
|
+
}
|
|
1680
|
+
var hasRequiredJsonldContextParser;
|
|
1681
|
+
function requireJsonldContextParser() {
|
|
1682
|
+
if (hasRequiredJsonldContextParser) return jsonldContextParser;
|
|
1683
|
+
hasRequiredJsonldContextParser = 1;
|
|
1684
|
+
(function(exports) {
|
|
1685
|
+
var __createBinding = jsonldContextParser && jsonldContextParser.__createBinding || (Object.create ? function(o, m, k, k2) {
|
|
1686
|
+
if (k2 === void 0) k2 = k;
|
|
1687
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
1688
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
1689
|
+
desc = { enumerable: true, get: function() {
|
|
1690
|
+
return m[k];
|
|
1691
|
+
} };
|
|
1692
|
+
}
|
|
1693
|
+
Object.defineProperty(o, k2, desc);
|
|
1694
|
+
} : function(o, m, k, k2) {
|
|
1695
|
+
if (k2 === void 0) k2 = k;
|
|
1696
|
+
o[k2] = m[k];
|
|
1697
|
+
});
|
|
1698
|
+
var __exportStar = jsonldContextParser && jsonldContextParser.__exportStar || function(m, exports2) {
|
|
1699
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports2, p)) __createBinding(exports2, m, p);
|
|
1700
|
+
};
|
|
1701
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1702
|
+
__exportStar(/* @__PURE__ */ requireContextParser(), exports);
|
|
1703
|
+
__exportStar(/* @__PURE__ */ requireErrorCoded(), exports);
|
|
1704
|
+
__exportStar(/* @__PURE__ */ requireFetchDocumentLoader(), exports);
|
|
1705
|
+
__exportStar(/* @__PURE__ */ requireIDocumentLoader(), exports);
|
|
1706
|
+
__exportStar(/* @__PURE__ */ requireJsonLdContext(), exports);
|
|
1707
|
+
__exportStar(/* @__PURE__ */ requireJsonLdContextNormalized(), exports);
|
|
1708
|
+
__exportStar(/* @__PURE__ */ requireUtil(), exports);
|
|
1709
|
+
})(jsonldContextParser);
|
|
1710
|
+
return jsonldContextParser;
|
|
1711
|
+
}
|
|
1712
|
+
var jsonldContextParserExports = /* @__PURE__ */ requireJsonldContextParser();
|
|
1713
|
+
function uniqID() {
|
|
1714
|
+
return `_${(Math.random() * 36 ** 20).toString(36).slice(0, 10)}`;
|
|
1715
|
+
}
|
|
1716
|
+
function stringToDom(html) {
|
|
1717
|
+
const template = document.createElement("template");
|
|
1718
|
+
template.innerHTML = html;
|
|
1719
|
+
return template.content;
|
|
1720
|
+
}
|
|
1721
|
+
const AsyncFunction = Object.getPrototypeOf(async () => {
|
|
1722
|
+
}).constructor;
|
|
1723
|
+
async function evalTemplateString(str, variables = {}) {
|
|
1724
|
+
const keys = Object.keys(variables);
|
|
1725
|
+
const values = keys.map((key) => variables[key]);
|
|
1726
|
+
try {
|
|
1727
|
+
const func = AsyncFunction.call(null, ...keys, `return \`${str}\``);
|
|
1728
|
+
return await func(...values);
|
|
1729
|
+
} catch (e) {
|
|
1730
|
+
console.log(e);
|
|
1731
|
+
throw new SyntaxError(`\`${str}\``);
|
|
1732
|
+
}
|
|
1733
|
+
}
|
|
1734
|
+
function importCSS(...stylesheets) {
|
|
1735
|
+
const linksElements = [];
|
|
1736
|
+
for (let url of stylesheets) {
|
|
1737
|
+
url = relativeSource(url);
|
|
1738
|
+
let link2 = Array.from(document.head.querySelectorAll("link")).find(
|
|
1739
|
+
(link22) => link22.href === url
|
|
1740
|
+
);
|
|
1741
|
+
if (link2) return link2;
|
|
1742
|
+
link2 = document.createElement("link");
|
|
1743
|
+
link2.rel = "stylesheet";
|
|
1744
|
+
link2.href = url;
|
|
1745
|
+
document.head.appendChild(link2);
|
|
1746
|
+
linksElements.push(link2);
|
|
1747
|
+
}
|
|
1748
|
+
return linksElements;
|
|
1749
|
+
}
|
|
1750
|
+
function importInlineCSS(id, importer) {
|
|
1751
|
+
id = `sib-inline-css-${id}`;
|
|
1752
|
+
let style = document.head.querySelector(`style#${id}`);
|
|
1753
|
+
if (style) return style;
|
|
1754
|
+
style = document.createElement("style");
|
|
1755
|
+
style.id = id;
|
|
1756
|
+
document.head.appendChild(style);
|
|
1757
|
+
(async () => {
|
|
1758
|
+
let textContent;
|
|
1759
|
+
if (typeof importer === "string") textContent = importer;
|
|
1760
|
+
else {
|
|
1761
|
+
const imported = await importer();
|
|
1762
|
+
if (typeof imported === "string") textContent = imported;
|
|
1763
|
+
else textContent = imported.default || "";
|
|
1764
|
+
}
|
|
1765
|
+
style.textContent = textContent;
|
|
1766
|
+
})();
|
|
1767
|
+
return style;
|
|
1768
|
+
}
|
|
1769
|
+
function importJS(...plugins) {
|
|
1770
|
+
return plugins.map((url) => {
|
|
1771
|
+
url = new URL(url, document.baseURI).href;
|
|
1772
|
+
let script = Array.from(document.querySelectorAll("script")).find(
|
|
1773
|
+
(script2) => script2.src === url
|
|
1774
|
+
);
|
|
1775
|
+
if (script) return script;
|
|
1776
|
+
script = document.createElement("script");
|
|
1777
|
+
script.src = url;
|
|
1778
|
+
document.head.appendChild(script);
|
|
1779
|
+
return script;
|
|
1780
|
+
});
|
|
1781
|
+
}
|
|
1782
|
+
function relativeSource(source) {
|
|
1783
|
+
if (!source.match(/^\..?\//)) return new URL(source, document.baseURI).href;
|
|
1784
|
+
const e = new Error();
|
|
1785
|
+
if (!e.stack) return source;
|
|
1786
|
+
const f2 = e.stack.split("\n").filter((l) => l.includes(":"))[2];
|
|
1787
|
+
const line = f2.match(/[a-z]+:.*$/);
|
|
1788
|
+
if (!line) return source;
|
|
1789
|
+
const calledFile = line[0].replace(/(\:[0-9]+){2}\)?$/, "");
|
|
1790
|
+
source = new URL(source, calledFile).href;
|
|
1791
|
+
return source;
|
|
1792
|
+
}
|
|
1793
|
+
function loadScript(source) {
|
|
1794
|
+
source = relativeSource(source);
|
|
1795
|
+
return new Promise((resolve) => {
|
|
1796
|
+
const script = document.createElement("script");
|
|
1797
|
+
const head = document.querySelector("head");
|
|
1798
|
+
script.async = true;
|
|
1799
|
+
script.onload = () => setTimeout(resolve, 0);
|
|
1800
|
+
script.src = source;
|
|
1801
|
+
if (head) head.appendChild(script);
|
|
1802
|
+
});
|
|
1803
|
+
}
|
|
1804
|
+
function domIsReady() {
|
|
1805
|
+
return new Promise((resolve) => {
|
|
1806
|
+
if (document.readyState === "complete") {
|
|
1807
|
+
resolve();
|
|
1808
|
+
} else {
|
|
1809
|
+
document.addEventListener("DOMContentLoaded", () => resolve());
|
|
1810
|
+
}
|
|
1811
|
+
});
|
|
1812
|
+
}
|
|
1813
|
+
function setDeepProperty(obj, path, value) {
|
|
1814
|
+
const name = path.shift();
|
|
1815
|
+
if (name) {
|
|
1816
|
+
if (!(name in obj)) obj[name] = {};
|
|
1817
|
+
if (path.length > 0) setDeepProperty(obj[name], path, value);
|
|
1818
|
+
else obj[name] = value;
|
|
1819
|
+
}
|
|
1820
|
+
}
|
|
1821
|
+
function parseFieldsString(fields) {
|
|
1822
|
+
if (!fields) return [];
|
|
1823
|
+
while (fields.indexOf("(") > 0) {
|
|
1824
|
+
const firstBracket = fields.indexOf("(");
|
|
1825
|
+
const noset = fields.substring(
|
|
1826
|
+
firstBracket,
|
|
1827
|
+
findClosingBracketMatchIndex(fields, firstBracket) + 1
|
|
1828
|
+
);
|
|
1829
|
+
fields = fields.replace(noset, "");
|
|
1830
|
+
}
|
|
1831
|
+
const re = /((^\s*|,)\s*)(("(\\"|[^"])*")|('(\\'|[^'])*')|[^,]*)/gm;
|
|
1832
|
+
const fieldsArray = fields.match(re) || [];
|
|
1833
|
+
if (!fieldsArray) return [];
|
|
1834
|
+
return fieldsArray.map((a) => a.replace(/^[\s,]+/, ""));
|
|
1835
|
+
}
|
|
1836
|
+
function findClosingBracketMatchIndex(str, pos) {
|
|
1837
|
+
if (str[pos] !== "(") throw new Error(`No '(' at index ${pos}`);
|
|
1838
|
+
let depth = 1;
|
|
1839
|
+
for (let i = pos + 1; i < str.length; i++) {
|
|
1840
|
+
switch (str[i]) {
|
|
1841
|
+
case "(":
|
|
1842
|
+
depth++;
|
|
1843
|
+
break;
|
|
1844
|
+
case ")":
|
|
1845
|
+
if (--depth === 0) return i;
|
|
1846
|
+
break;
|
|
1847
|
+
}
|
|
1848
|
+
}
|
|
1849
|
+
return -1;
|
|
1850
|
+
}
|
|
1851
|
+
function defineComponent(tagName, componentClass) {
|
|
1852
|
+
if (!customElements.get(tagName)) {
|
|
1853
|
+
customElements.define(tagName, componentClass);
|
|
1854
|
+
} else {
|
|
1855
|
+
console.warn(
|
|
1856
|
+
`Warning: the component "${tagName}" has already been loaded in another version of sib-core.`
|
|
1857
|
+
);
|
|
1858
|
+
}
|
|
1859
|
+
}
|
|
1860
|
+
function fuzzyCompare(subject, search) {
|
|
1861
|
+
return compareTransform(subject).includes(compareTransform(String(search)));
|
|
1862
|
+
}
|
|
1863
|
+
function compareTransform(str) {
|
|
1864
|
+
return str.normalize("NFD").replaceAll(new RegExp("\\p{Diacritic}", "gu"), "").toLowerCase().replaceAll("œ", "oe").replaceAll("æ", "ae").replaceAll(/[ ,.!?;:-`"]+/g, " ").trim();
|
|
1865
|
+
}
|
|
1866
|
+
const compare = {
|
|
1867
|
+
string(subject, query) {
|
|
1868
|
+
if (typeof subject !== "string" || typeof query !== "string")
|
|
1869
|
+
throw new TypeError("not a string");
|
|
1870
|
+
if (query === "") return true;
|
|
1871
|
+
return fuzzyCompare(subject, String(query));
|
|
1872
|
+
},
|
|
1873
|
+
boolean(subject, query) {
|
|
1874
|
+
if (!query) return true;
|
|
1875
|
+
return subject;
|
|
1876
|
+
},
|
|
1877
|
+
number(subject, query) {
|
|
1878
|
+
return subject === query;
|
|
1879
|
+
},
|
|
1880
|
+
list(subject, list) {
|
|
1881
|
+
return list.includes(subject);
|
|
1882
|
+
},
|
|
1883
|
+
range(subject, range) {
|
|
1884
|
+
return (range[0] == null || range[0] === "" || subject >= range[0]) && (range[1] == null || range[1] === "" || subject <= range[1]);
|
|
1885
|
+
},
|
|
1886
|
+
resource(subject, query) {
|
|
1887
|
+
if (query === "") return true;
|
|
1888
|
+
if (!query["@id"]) return false;
|
|
1889
|
+
const ret = subject["@id"] === query["@id"];
|
|
1890
|
+
return ret;
|
|
1891
|
+
}
|
|
1892
|
+
};
|
|
1893
|
+
function generalComparator(a, b, order = "asc") {
|
|
1894
|
+
if (order === "desc") return generalComparator(b, a);
|
|
1895
|
+
if (a == null && b == null) return 0;
|
|
1896
|
+
if (a === b || Object.is(a, b)) return 0;
|
|
1897
|
+
if (typeof a === "boolean" && typeof b === "boolean") {
|
|
1898
|
+
return a === b ? 0 : a ? 1 : -1;
|
|
1899
|
+
}
|
|
1900
|
+
if (!Number.isNaN(Number(a)) && !Number.isNaN(Number(b))) {
|
|
1901
|
+
return Number(a) - Number(b);
|
|
1902
|
+
}
|
|
1903
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
1904
|
+
return a.length - b.length;
|
|
1905
|
+
}
|
|
1906
|
+
const dateA = Date.parse(String(a));
|
|
1907
|
+
const dateB = Date.parse(String(b));
|
|
1908
|
+
if (!Number.isNaN(dateA) && !Number.isNaN(dateB)) {
|
|
1909
|
+
return dateA - dateB;
|
|
1910
|
+
}
|
|
1911
|
+
if (a && b && typeof a === "object" && typeof b === "object") {
|
|
1912
|
+
const aKeys = Object.keys(a);
|
|
1913
|
+
const bKeys = Object.keys(b);
|
|
1914
|
+
return aKeys.length - bKeys.length;
|
|
1915
|
+
}
|
|
1916
|
+
if (a == null) return -1;
|
|
1917
|
+
if (b == null) return 1;
|
|
1918
|
+
return String(a).localeCompare(String(b));
|
|
1919
|
+
}
|
|
1920
|
+
function transformArrayToContainer(resource) {
|
|
1921
|
+
const newValue = { ...resource };
|
|
1922
|
+
for (const predicate of Object.keys(newValue)) {
|
|
1923
|
+
const predicateValue = newValue[predicate];
|
|
1924
|
+
if (!predicateValue || typeof predicateValue !== "object") continue;
|
|
1925
|
+
if (["permissions", "@context"].includes(predicate)) continue;
|
|
1926
|
+
if (!Array.isArray(predicateValue) && predicateValue["@id"]) {
|
|
1927
|
+
newValue[predicate] = transformArrayToContainer(resource[predicate]);
|
|
1928
|
+
}
|
|
1929
|
+
if (Array.isArray(predicateValue) && predicateValue["@id"]) {
|
|
1930
|
+
newValue[predicate] = {
|
|
1931
|
+
"@id": predicateValue["@id"],
|
|
1932
|
+
"ldp:contains": [...predicateValue]
|
|
1933
|
+
// ???? why only ldp:contains?
|
|
1934
|
+
};
|
|
1935
|
+
newValue[predicate]["ldp:contains"].forEach(
|
|
1936
|
+
(childPredicate, index) => {
|
|
1937
|
+
newValue[predicate]["ldp:contains"][index] = transformArrayToContainer(childPredicate);
|
|
1938
|
+
}
|
|
1939
|
+
);
|
|
1940
|
+
}
|
|
1941
|
+
}
|
|
1942
|
+
return newValue;
|
|
1943
|
+
}
|
|
1944
|
+
function doesResourceContainList(resource) {
|
|
1945
|
+
const predicates = ["ldp:contains", "dcat:dataset"];
|
|
1946
|
+
return predicates.some(
|
|
1947
|
+
(predicate) => typeof resource === "object" ? predicate in resource : typeof resource === "string" && resource.includes(predicate)
|
|
1948
|
+
);
|
|
1949
|
+
}
|
|
1950
|
+
class AsyncIterableBuilder {
|
|
1951
|
+
constructor() {
|
|
1952
|
+
__privateAdd(this, _AsyncIterableBuilder_instances);
|
|
1953
|
+
__privateAdd(this, _values, []);
|
|
1954
|
+
__privateAdd(this, _resolve);
|
|
1955
|
+
__publicField(this, "iterable");
|
|
1956
|
+
__publicField(this, "next");
|
|
1957
|
+
__privateMethod(this, _AsyncIterableBuilder_instances, nextPromise_fn).call(this);
|
|
1958
|
+
this.iterable = __privateMethod(this, _AsyncIterableBuilder_instances, createIterable_fn).call(this);
|
|
1959
|
+
this.next = __privateMethod(this, _AsyncIterableBuilder_instances, next_fn).bind(this);
|
|
1960
|
+
}
|
|
1961
|
+
}
|
|
1962
|
+
_values = new WeakMap();
|
|
1963
|
+
_resolve = new WeakMap();
|
|
1964
|
+
_AsyncIterableBuilder_instances = new WeakSet();
|
|
1965
|
+
createIterable_fn = async function* () {
|
|
1966
|
+
for (let index = 0; ; index++) {
|
|
1967
|
+
const { value, done } = await __privateGet(this, _values)[index];
|
|
1968
|
+
delete __privateGet(this, _values)[index];
|
|
1969
|
+
yield value;
|
|
1970
|
+
if (done) return;
|
|
1971
|
+
}
|
|
1972
|
+
};
|
|
1973
|
+
next_fn = function(value, done = false) {
|
|
1974
|
+
__privateGet(this, _resolve).call(this, { value, done });
|
|
1975
|
+
__privateMethod(this, _AsyncIterableBuilder_instances, nextPromise_fn).call(this);
|
|
1976
|
+
};
|
|
1977
|
+
nextPromise_fn = function() {
|
|
1978
|
+
__privateGet(this, _values).push(
|
|
1979
|
+
new Promise((resolve) => {
|
|
1980
|
+
__privateSet(this, _resolve, resolve);
|
|
1981
|
+
})
|
|
1982
|
+
);
|
|
1983
|
+
};
|
|
1984
|
+
const asyncQuerySelector = (selector, parent = document) => new Promise((resolve) => {
|
|
1985
|
+
const element = parent.querySelector(selector);
|
|
1986
|
+
if (element) return resolve(element);
|
|
1987
|
+
const observer = new MutationObserver(() => {
|
|
1988
|
+
const element2 = parent.querySelector(selector);
|
|
1989
|
+
if (!element2) return;
|
|
1990
|
+
observer.disconnect();
|
|
1991
|
+
return resolve(element2);
|
|
1992
|
+
});
|
|
1993
|
+
observer.observe(parent, {
|
|
1994
|
+
subtree: true,
|
|
1995
|
+
childList: true,
|
|
1996
|
+
attributes: true
|
|
1997
|
+
});
|
|
1998
|
+
});
|
|
1999
|
+
function isUrlOrRelativePath(value) {
|
|
2000
|
+
if (typeof value !== "string") return false;
|
|
2001
|
+
if (value.startsWith("_:")) return false;
|
|
2002
|
+
if (/^[a-zA-Z][a-zA-Z0-9+.-]*:\/\//.test(value)) return true;
|
|
2003
|
+
if (value.startsWith("/")) return true;
|
|
2004
|
+
return false;
|
|
2005
|
+
}
|
|
2006
|
+
const asyncQuerySelectorAll = (selector, parent = document) => {
|
|
2007
|
+
const delivered = /* @__PURE__ */ new WeakSet();
|
|
2008
|
+
const { next, iterable } = new AsyncIterableBuilder();
|
|
2009
|
+
function checkNewElement() {
|
|
2010
|
+
for (const element of parent.querySelectorAll(selector)) {
|
|
2011
|
+
if (delivered.has(element)) continue;
|
|
2012
|
+
delivered.add(element);
|
|
2013
|
+
next(element);
|
|
2014
|
+
}
|
|
2015
|
+
}
|
|
2016
|
+
checkNewElement();
|
|
2017
|
+
const observer = new MutationObserver(checkNewElement);
|
|
2018
|
+
observer.observe(parent, {
|
|
2019
|
+
subtree: true,
|
|
2020
|
+
childList: true,
|
|
2021
|
+
attributes: true
|
|
2022
|
+
});
|
|
2023
|
+
return iterable;
|
|
2024
|
+
};
|
|
2025
|
+
const mergeContexts = (client, server) => ({
|
|
2026
|
+
...getRawContext(client),
|
|
2027
|
+
...getRawContext(server)
|
|
2028
|
+
});
|
|
2029
|
+
const normalizeContext = (ctx, fallbackCtx = null) => {
|
|
2030
|
+
if (ctx && !(ctx instanceof jsonldContextParserExports.JsonLdContextNormalized)) {
|
|
2031
|
+
return new jsonldContextParserExports.JsonLdContextNormalized(ctx);
|
|
2032
|
+
}
|
|
2033
|
+
if (!ctx && fallbackCtx) {
|
|
2034
|
+
return normalizeContext(fallbackCtx);
|
|
2035
|
+
}
|
|
2036
|
+
return ctx;
|
|
2037
|
+
};
|
|
2038
|
+
const getRawContext = (ctx) => {
|
|
2039
|
+
if (!ctx) return ctx;
|
|
2040
|
+
if (ctx instanceof jsonldContextParserExports.JsonLdContextNormalized) {
|
|
2041
|
+
return ctx.getContextRaw();
|
|
2042
|
+
}
|
|
2043
|
+
if (Array.isArray(ctx)) {
|
|
2044
|
+
return ctx.map(getRawContext);
|
|
2045
|
+
}
|
|
2046
|
+
if (ctx && typeof ctx === "object" && "contextRaw" in ctx) {
|
|
2047
|
+
return ctx.contextRaw;
|
|
2048
|
+
}
|
|
2049
|
+
return ctx;
|
|
2050
|
+
};
|
|
2051
|
+
const helpers = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
2052
|
+
__proto__: null,
|
|
2053
|
+
AsyncIterableBuilder,
|
|
2054
|
+
asyncQuerySelector,
|
|
2055
|
+
asyncQuerySelectorAll,
|
|
2056
|
+
compare,
|
|
2057
|
+
default: AsyncIterableBuilder,
|
|
2058
|
+
defineComponent,
|
|
2059
|
+
doesResourceContainList,
|
|
2060
|
+
domIsReady,
|
|
2061
|
+
evalTemplateString,
|
|
2062
|
+
findClosingBracketMatchIndex,
|
|
2063
|
+
fuzzyCompare,
|
|
2064
|
+
generalComparator,
|
|
2065
|
+
getRawContext,
|
|
2066
|
+
importCSS,
|
|
2067
|
+
importInlineCSS,
|
|
2068
|
+
importJS,
|
|
2069
|
+
isUrlOrRelativePath,
|
|
2070
|
+
loadScript,
|
|
2071
|
+
mergeContexts,
|
|
2072
|
+
normalizeContext,
|
|
2073
|
+
parseFieldsString,
|
|
2074
|
+
setDeepProperty,
|
|
2075
|
+
stringToDom,
|
|
2076
|
+
transformArrayToContainer,
|
|
2077
|
+
uniqID
|
|
2078
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
2079
|
+
export {
|
|
2080
|
+
AsyncIterableBuilder as A,
|
|
2081
|
+
doesResourceContainList as a,
|
|
2082
|
+
fuzzyCompare as b,
|
|
2083
|
+
compare as c,
|
|
2084
|
+
defineComponent as d,
|
|
2085
|
+
evalTemplateString as e,
|
|
2086
|
+
findClosingBracketMatchIndex as f,
|
|
2087
|
+
generalComparator as g,
|
|
2088
|
+
asyncQuerySelector as h,
|
|
2089
|
+
importInlineCSS as i,
|
|
2090
|
+
importCSS as j,
|
|
2091
|
+
helpers as k,
|
|
2092
|
+
isUrlOrRelativePath as l,
|
|
2093
|
+
mergeContexts as m,
|
|
2094
|
+
normalizeContext as n,
|
|
2095
|
+
jsonldContextParserExports as o,
|
|
2096
|
+
parseFieldsString as p,
|
|
2097
|
+
getRawContext as q,
|
|
2098
|
+
stringToDom as r,
|
|
2099
|
+
setDeepProperty as s,
|
|
2100
|
+
transformArrayToContainer as t,
|
|
2101
|
+
uniqID as u,
|
|
2102
|
+
importJS as v,
|
|
2103
|
+
loadScript as w,
|
|
2104
|
+
domIsReady as x,
|
|
2105
|
+
asyncQuerySelectorAll as y
|
|
2106
|
+
};
|