@twin.org/data-json-ld 0.0.2-next.4 → 0.0.3-next.1
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/es/dataTypes/jsonLdDataTypes.js +171 -0
- package/dist/es/dataTypes/jsonLdDataTypes.js.map +1 -0
- package/dist/es/index.js +33 -0
- package/dist/es/index.js.map +1 -0
- package/dist/es/models/IJsonLdContainerType.js +4 -0
- package/dist/es/models/IJsonLdContainerType.js.map +1 -0
- package/dist/es/models/IJsonLdContainerTypeArray.js +2 -0
- package/dist/es/models/IJsonLdContainerTypeArray.js.map +1 -0
- package/dist/es/models/IJsonLdContextDefinition.js +2 -0
- package/dist/es/models/IJsonLdContextDefinition.js.map +1 -0
- package/dist/es/models/IJsonLdContextDefinitionElement.js +2 -0
- package/dist/es/models/IJsonLdContextDefinitionElement.js.map +1 -0
- package/dist/es/models/IJsonLdContextDefinitionRoot.js +2 -0
- package/dist/es/models/IJsonLdContextDefinitionRoot.js.map +1 -0
- package/dist/es/models/IJsonLdDocument.js +2 -0
- package/dist/es/models/IJsonLdDocument.js.map +1 -0
- package/dist/es/models/IJsonLdExpandedTermDefinition.js +2 -0
- package/dist/es/models/IJsonLdExpandedTermDefinition.js.map +1 -0
- package/dist/es/models/IJsonLdGraphObject.js +2 -0
- package/dist/es/models/IJsonLdGraphObject.js.map +1 -0
- package/dist/es/models/IJsonLdIdMap.js +2 -0
- package/dist/es/models/IJsonLdIdMap.js.map +1 -0
- package/dist/es/models/IJsonLdIncludedBlock.js +2 -0
- package/dist/es/models/IJsonLdIncludedBlock.js.map +1 -0
- package/dist/es/models/IJsonLdIndexMap.js +2 -0
- package/dist/es/models/IJsonLdIndexMap.js.map +1 -0
- package/dist/es/models/IJsonLdIndexMapItem.js +2 -0
- package/dist/es/models/IJsonLdIndexMapItem.js.map +1 -0
- package/dist/es/models/IJsonLdJsonArray.js +2 -0
- package/dist/es/models/IJsonLdJsonArray.js.map +1 -0
- package/dist/es/models/IJsonLdJsonObject.js +2 -0
- package/dist/es/models/IJsonLdJsonObject.js.map +1 -0
- package/dist/es/models/IJsonLdJsonPrimitive.js +4 -0
- package/dist/es/models/IJsonLdJsonPrimitive.js.map +1 -0
- package/dist/es/models/IJsonLdJsonValue.js +2 -0
- package/dist/es/models/IJsonLdJsonValue.js.map +1 -0
- package/dist/es/models/IJsonLdLanguageMap.js +4 -0
- package/dist/es/models/IJsonLdLanguageMap.js.map +1 -0
- package/dist/es/models/IJsonLdListObject.js +2 -0
- package/dist/es/models/IJsonLdListObject.js.map +1 -0
- package/dist/es/models/IJsonLdListOrSetItem.js +2 -0
- package/dist/es/models/IJsonLdListOrSetItem.js.map +1 -0
- package/dist/es/models/IJsonLdNodeObject.js +2 -0
- package/dist/es/models/IJsonLdNodeObject.js.map +1 -0
- package/dist/es/models/IJsonLdNodePrimitive.js +2 -0
- package/dist/es/models/IJsonLdNodePrimitive.js.map +1 -0
- package/dist/es/models/IJsonLdObject.js +2 -0
- package/dist/es/models/IJsonLdObject.js.map +1 -0
- package/dist/es/models/IJsonLdSetObject.js +2 -0
- package/dist/es/models/IJsonLdSetObject.js.map +1 -0
- package/dist/es/models/IJsonLdTypeMap.js +2 -0
- package/dist/es/models/IJsonLdTypeMap.js.map +1 -0
- package/dist/es/models/IJsonLdValueObject.js +2 -0
- package/dist/es/models/IJsonLdValueObject.js.map +1 -0
- package/dist/es/models/jsonLdContexts.js +13 -0
- package/dist/es/models/jsonLdContexts.js.map +1 -0
- package/dist/es/models/jsonLdTypes.js +113 -0
- package/dist/es/models/jsonLdTypes.js.map +1 -0
- package/dist/es/schemas/JsonLdContainerType.json +13 -0
- package/dist/es/schemas/JsonLdContainerTypeArray.json +179 -0
- package/dist/es/schemas/JsonLdContextDefinition.json +76 -0
- package/dist/es/schemas/JsonLdContextDefinitionElement.json +16 -0
- package/dist/es/schemas/JsonLdContextDefinitionRoot.json +16 -0
- package/dist/es/schemas/JsonLdDocument.json +48 -0
- package/dist/es/schemas/JsonLdExpandedTermDefinition.json +136 -0
- package/dist/es/schemas/JsonLdGraphObject.json +44 -0
- package/dist/es/schemas/JsonLdIdMap.json +9 -0
- package/dist/es/schemas/JsonLdIncludedBlock.json +16 -0
- package/dist/es/schemas/JsonLdIndexMap.json +19 -0
- package/dist/es/schemas/JsonLdIndexMapItem.json +31 -0
- package/dist/es/schemas/JsonLdJsonArray.json +9 -0
- package/dist/es/schemas/JsonLdJsonObject.json +16 -0
- package/dist/es/schemas/JsonLdJsonPrimitive.json +11 -0
- package/dist/es/schemas/JsonLdJsonValue.json +16 -0
- package/dist/es/schemas/JsonLdLanguageMap.json +22 -0
- package/dist/es/schemas/JsonLdListObject.json +28 -0
- package/dist/es/schemas/JsonLdListOrSetItem.json +25 -0
- package/dist/es/schemas/JsonLdNodeObject.json +100 -0
- package/dist/es/schemas/JsonLdNodePrimitive.json +34 -0
- package/dist/es/schemas/JsonLdObject.json +76 -0
- package/dist/es/schemas/JsonLdSetObject.json +28 -0
- package/dist/es/schemas/JsonLdTypeMap.json +16 -0
- package/dist/es/schemas/JsonLdValueObject.json +113 -0
- package/dist/es/utils/jsonLdHelper.js +79 -0
- package/dist/es/utils/jsonLdHelper.js.map +1 -0
- package/dist/es/utils/jsonLdProcessor.js +375 -0
- package/dist/es/utils/jsonLdProcessor.js.map +1 -0
- package/dist/types/index.d.ts +30 -30
- package/dist/types/models/IJsonLdContainerTypeArray.d.ts +1 -1
- package/dist/types/models/IJsonLdContextDefinition.d.ts +1 -1
- package/dist/types/models/IJsonLdContextDefinitionElement.d.ts +1 -1
- package/dist/types/models/IJsonLdContextDefinitionRoot.d.ts +1 -1
- package/dist/types/models/IJsonLdDocument.d.ts +3 -3
- package/dist/types/models/IJsonLdExpandedTermDefinition.d.ts +3 -3
- package/dist/types/models/IJsonLdGraphObject.d.ts +2 -2
- package/dist/types/models/IJsonLdIdMap.d.ts +1 -1
- package/dist/types/models/IJsonLdIncludedBlock.d.ts +1 -1
- package/dist/types/models/IJsonLdIndexMap.d.ts +1 -1
- package/dist/types/models/IJsonLdIndexMapItem.d.ts +4 -4
- package/dist/types/models/IJsonLdJsonArray.d.ts +1 -1
- package/dist/types/models/IJsonLdJsonObject.d.ts +1 -1
- package/dist/types/models/IJsonLdJsonValue.d.ts +3 -3
- package/dist/types/models/IJsonLdListObject.d.ts +1 -1
- package/dist/types/models/IJsonLdListOrSetItem.d.ts +2 -2
- package/dist/types/models/IJsonLdNodeObject.d.ts +7 -7
- package/dist/types/models/IJsonLdNodePrimitive.d.ts +5 -5
- package/dist/types/models/IJsonLdObject.d.ts +4 -4
- package/dist/types/models/IJsonLdSetObject.d.ts +1 -1
- package/dist/types/models/IJsonLdTypeMap.d.ts +1 -1
- package/dist/types/models/IJsonLdValueObject.d.ts +3 -3
- package/dist/types/utils/jsonLdHelper.d.ts +8 -1
- package/dist/types/utils/jsonLdProcessor.d.ts +4 -4
- package/docs/changelog.md +31 -0
- package/docs/reference/classes/JsonLdHelper.md +28 -0
- package/docs/reference/classes/JsonLdProcessor.md +9 -9
- package/docs/reference/interfaces/IJsonLdContextDefinition.md +4 -4
- package/docs/reference/interfaces/IJsonLdJsonObject.md +1 -1
- package/docs/reference/interfaces/IJsonLdLanguageMap.md +1 -1
- package/docs/reference/interfaces/IJsonLdNodeObject.md +1 -1
- package/package.json +6 -8
- package/dist/cjs/index.cjs +0 -2018
- package/dist/esm/index.mjs +0 -2012
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
// Copyright 2024 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
import { BaseError, GeneralError, Is, ObjectHelper, SharedStore } from "@twin.org/core";
|
|
4
|
+
import { FetchHelper, HeaderTypes, HttpMethod, MimeTypes } from "@twin.org/web";
|
|
5
|
+
import jsonLd from "jsonld";
|
|
6
|
+
/**
|
|
7
|
+
* JSON-LD Processor.
|
|
8
|
+
*/
|
|
9
|
+
export class JsonLdProcessor {
|
|
10
|
+
/**
|
|
11
|
+
* The class name.
|
|
12
|
+
* @internal
|
|
13
|
+
*/
|
|
14
|
+
static CLASS_NAME = "JsonLdProcessor";
|
|
15
|
+
/**
|
|
16
|
+
* The document loader to use.
|
|
17
|
+
* @param documentLoader The document loader to use.
|
|
18
|
+
*/
|
|
19
|
+
static setDocumentLoader(documentLoader) {
|
|
20
|
+
SharedStore.set("jsonLdDocumentLoader", documentLoader);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The document loader to use for retrieving JSON-LD documents.
|
|
24
|
+
* @returns The document loader.
|
|
25
|
+
*/
|
|
26
|
+
static getDocumentLoader() {
|
|
27
|
+
let documentLoader = SharedStore.get("jsonLdDocumentLoader");
|
|
28
|
+
if (!Is.function(documentLoader)) {
|
|
29
|
+
documentLoader = async (url) => JsonLdProcessor.documentLoader(url);
|
|
30
|
+
}
|
|
31
|
+
return documentLoader;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Set the cache time limit for documents.
|
|
35
|
+
* @param cacheLimitMs The cache limit in milliseconds.
|
|
36
|
+
*/
|
|
37
|
+
static setCacheLimit(cacheLimitMs) {
|
|
38
|
+
SharedStore.set("jsonLdDocumentCacheLimit", cacheLimitMs);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Get the cache limit for documents.
|
|
42
|
+
* @returns The document loader.
|
|
43
|
+
*/
|
|
44
|
+
static getCacheLimit() {
|
|
45
|
+
let cacheLimitMs = SharedStore.get("jsonLdDocumentCacheLimit");
|
|
46
|
+
if (Is.empty(cacheLimitMs)) {
|
|
47
|
+
cacheLimitMs = 3600000;
|
|
48
|
+
SharedStore.set("jsonLdDocumentCacheLimit", cacheLimitMs);
|
|
49
|
+
}
|
|
50
|
+
return cacheLimitMs;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Set the global redirects for JSON-LD, use addRedirect for default handling.
|
|
54
|
+
* @param redirects The redirects to use.
|
|
55
|
+
*/
|
|
56
|
+
static setRedirects(redirects) {
|
|
57
|
+
SharedStore.set("jsonLdRedirects", redirects);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Get the global redirects for JSON-LD.
|
|
61
|
+
* @returns The registered redirects.
|
|
62
|
+
*/
|
|
63
|
+
static getRedirects() {
|
|
64
|
+
let redirects = SharedStore.get("jsonLdRedirects");
|
|
65
|
+
if (Is.empty(redirects)) {
|
|
66
|
+
redirects = [];
|
|
67
|
+
SharedStore.set("jsonLdRedirects", redirects);
|
|
68
|
+
}
|
|
69
|
+
return redirects;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Compact a document according to a particular context.
|
|
73
|
+
* @param document The JSON-LD document to compact.
|
|
74
|
+
* @param context The context to compact the document to, if not provided will use the one in the document.
|
|
75
|
+
* @param options The options for compacting the document.
|
|
76
|
+
* @param options.itemListOverride Whether to override the itemListElement context with a set, defaults to true.
|
|
77
|
+
* @returns The compacted JSON-LD document.
|
|
78
|
+
*/
|
|
79
|
+
static async compact(document, context, options) {
|
|
80
|
+
try {
|
|
81
|
+
if (Is.object(document)) {
|
|
82
|
+
// If the user didn't provide a context, use the one from the document
|
|
83
|
+
if (Is.empty(context) && !Is.empty(document["@context"])) {
|
|
84
|
+
context = document["@context"];
|
|
85
|
+
}
|
|
86
|
+
const overrideListElementOption = options?.itemListOverride ?? true;
|
|
87
|
+
let overrideContext;
|
|
88
|
+
if (overrideListElementOption) {
|
|
89
|
+
// The compactArrays flag doesn't work with the current version of jsonld.js
|
|
90
|
+
// For list results we standardise on ItemList and itemListElement
|
|
91
|
+
// so we modify the schema.org type for itemListElement to be a set which bypasses the issue
|
|
92
|
+
// https://github.com/digitalbazaar/jsonld.js/issues/247
|
|
93
|
+
overrideContext = {
|
|
94
|
+
itemListElement: {
|
|
95
|
+
"@id": "http://schema.org/itemListElement",
|
|
96
|
+
"@container": "@set",
|
|
97
|
+
"@protected": true
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
if (Is.object(context) && "@context" in context) {
|
|
101
|
+
// If the context is an object, we need to merge it with the override context
|
|
102
|
+
context = JsonLdProcessor.combineContexts(context["@context"], overrideContext);
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
// If the context is a string or an array, we need to merge it with the override context
|
|
106
|
+
context = JsonLdProcessor.combineContexts(context, overrideContext);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
const compacted = await jsonLd.compact(ObjectHelper.removeEmptyProperties(document), context, {
|
|
110
|
+
documentLoader: JsonLdProcessor.getDocumentLoader()
|
|
111
|
+
});
|
|
112
|
+
if (!Is.empty(overrideContext)) {
|
|
113
|
+
// Remove the override context from the compacted document
|
|
114
|
+
compacted["@context"] = JsonLdProcessor.removeContexts(compacted["@context"], [overrideContext]);
|
|
115
|
+
}
|
|
116
|
+
return compacted;
|
|
117
|
+
}
|
|
118
|
+
return document;
|
|
119
|
+
}
|
|
120
|
+
catch (err) {
|
|
121
|
+
JsonLdProcessor.handleCommonErrors(err);
|
|
122
|
+
throw new GeneralError(JsonLdProcessor.CLASS_NAME, "compact", undefined, err);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Expand a document, removing its context.
|
|
127
|
+
* @param compacted The compacted JSON-LD document to expand.
|
|
128
|
+
* @returns The expanded JSON-LD document.
|
|
129
|
+
*/
|
|
130
|
+
static async expand(compacted) {
|
|
131
|
+
try {
|
|
132
|
+
if (Is.object(compacted)) {
|
|
133
|
+
const expanded = await jsonLd.expand(ObjectHelper.removeEmptyProperties(compacted), {
|
|
134
|
+
documentLoader: JsonLdProcessor.getDocumentLoader()
|
|
135
|
+
});
|
|
136
|
+
return expanded;
|
|
137
|
+
}
|
|
138
|
+
return [];
|
|
139
|
+
}
|
|
140
|
+
catch (err) {
|
|
141
|
+
JsonLdProcessor.handleCommonErrors(err);
|
|
142
|
+
throw new GeneralError(JsonLdProcessor.CLASS_NAME, "expand", undefined, err);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Canonize a document.
|
|
147
|
+
* @param document The document to canonize.
|
|
148
|
+
* @param options The options for canonization.
|
|
149
|
+
* @param options.algorithm The algorithm to use for canonization, defaults to URDNA2015.
|
|
150
|
+
* @returns The canonized document.
|
|
151
|
+
*/
|
|
152
|
+
static async canonize(document, options) {
|
|
153
|
+
try {
|
|
154
|
+
const normalized = await jsonLd.canonize(ObjectHelper.removeEmptyProperties(document), {
|
|
155
|
+
algorithm: options?.algorithm ?? "URDNA2015",
|
|
156
|
+
format: "application/n-quads",
|
|
157
|
+
documentLoader: JsonLdProcessor.getDocumentLoader()
|
|
158
|
+
});
|
|
159
|
+
return normalized;
|
|
160
|
+
}
|
|
161
|
+
catch (err) {
|
|
162
|
+
JsonLdProcessor.handleCommonErrors(err);
|
|
163
|
+
throw new GeneralError(JsonLdProcessor.CLASS_NAME, "canonize", undefined, err);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Add a redirect to use during document resolution.
|
|
168
|
+
* @param from The URL to redirect from.
|
|
169
|
+
* @param to The URL to redirect to.
|
|
170
|
+
*/
|
|
171
|
+
static addRedirect(from, to) {
|
|
172
|
+
const redirects = JsonLdProcessor.getRedirects();
|
|
173
|
+
if (!redirects.some(r => r.from === from)) {
|
|
174
|
+
redirects.push({ from, to });
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Combine contexts.
|
|
179
|
+
* @param context1 The first JSON-LD context to combine.
|
|
180
|
+
* @param context2 The second JSON-LD context to combine.
|
|
181
|
+
* @returns The combined context.
|
|
182
|
+
*/
|
|
183
|
+
static combineContexts(context1, context2) {
|
|
184
|
+
const combinedContext = [];
|
|
185
|
+
if (Is.string(context1)) {
|
|
186
|
+
if (!combinedContext.includes(context1)) {
|
|
187
|
+
combinedContext.push(context1);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
else if (Is.array(context1)) {
|
|
191
|
+
for (const context of context1) {
|
|
192
|
+
const hasMatch = combinedContext.some(c => ObjectHelper.equal(c, context));
|
|
193
|
+
if (!hasMatch) {
|
|
194
|
+
combinedContext.push(context);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
else if (Is.object(context1)) {
|
|
199
|
+
const hasMatch = combinedContext.some(c => ObjectHelper.equal(c, context1));
|
|
200
|
+
if (!hasMatch) {
|
|
201
|
+
combinedContext.push(context1);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
if (Is.string(context2)) {
|
|
205
|
+
if (!combinedContext.includes(context2)) {
|
|
206
|
+
combinedContext.push(context2);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
else if (Is.array(context2)) {
|
|
210
|
+
for (const context of context2) {
|
|
211
|
+
const hasMatch = combinedContext.some(c => ObjectHelper.equal(c, context));
|
|
212
|
+
if (!hasMatch) {
|
|
213
|
+
combinedContext.push(context);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
else if (Is.object(context2)) {
|
|
218
|
+
const hasMatch = combinedContext.some(c => ObjectHelper.equal(c, context2));
|
|
219
|
+
if (!hasMatch) {
|
|
220
|
+
combinedContext.push(context2);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
if (combinedContext.length === 0) {
|
|
224
|
+
return null;
|
|
225
|
+
}
|
|
226
|
+
if (combinedContext.length === 1) {
|
|
227
|
+
return combinedContext[0];
|
|
228
|
+
}
|
|
229
|
+
return combinedContext;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Gather all the contexts from the element and it's children.
|
|
233
|
+
* @param element The element to gather the contexts from.
|
|
234
|
+
* @param initial The initial context.
|
|
235
|
+
* @returns The combined contexts.
|
|
236
|
+
*/
|
|
237
|
+
static gatherContexts(element, initial) {
|
|
238
|
+
let combinedContexts = initial;
|
|
239
|
+
if (Is.object(element)) {
|
|
240
|
+
if (!Is.empty(element["@context"])) {
|
|
241
|
+
combinedContexts = JsonLdProcessor.combineContexts(initial, element["@context"]);
|
|
242
|
+
}
|
|
243
|
+
for (const prop of Object.keys(element)) {
|
|
244
|
+
const value = element[prop];
|
|
245
|
+
if (Is.object(value)) {
|
|
246
|
+
combinedContexts = JsonLdProcessor.gatherContexts(value, combinedContexts);
|
|
247
|
+
}
|
|
248
|
+
else if (Is.array(value)) {
|
|
249
|
+
for (const item of value) {
|
|
250
|
+
if (Is.object(item)) {
|
|
251
|
+
combinedContexts = JsonLdProcessor.gatherContexts(item, combinedContexts);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
return combinedContexts;
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Remove all the contexts that match the pattern.
|
|
261
|
+
* @param context The context to remove the entries from.
|
|
262
|
+
* @param match The element to try and match.
|
|
263
|
+
* @returns The updated contexts.
|
|
264
|
+
*/
|
|
265
|
+
static removeContexts(context, match) {
|
|
266
|
+
if (!Is.arrayValue(match)) {
|
|
267
|
+
return context;
|
|
268
|
+
}
|
|
269
|
+
let finalContext;
|
|
270
|
+
if (Is.string(context)) {
|
|
271
|
+
for (const m of match) {
|
|
272
|
+
if (context === m) {
|
|
273
|
+
break;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
else if (Is.array(context)) {
|
|
278
|
+
for (const item of context) {
|
|
279
|
+
const hasMatch = match.some(m => ObjectHelper.equal(m, item));
|
|
280
|
+
if (!hasMatch) {
|
|
281
|
+
finalContext ??= [];
|
|
282
|
+
if (Is.array(finalContext)) {
|
|
283
|
+
finalContext.push(item);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
else if (Is.object(context)) {
|
|
289
|
+
const hasMatch = match.some(m => ObjectHelper.equal(m, context));
|
|
290
|
+
if (!hasMatch) {
|
|
291
|
+
finalContext = context;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
return Is.arrayValue(finalContext) && finalContext.length === 1
|
|
295
|
+
? finalContext[0]
|
|
296
|
+
: finalContext;
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Add a context directly to the document loader cache.
|
|
300
|
+
* @param url The url the ld context is for.
|
|
301
|
+
* @param ldContext The context to add.
|
|
302
|
+
* @returns Nothing.
|
|
303
|
+
*/
|
|
304
|
+
static async documentCacheAdd(url, ldContext) {
|
|
305
|
+
await FetchHelper.setCacheEntry(url, ldContext);
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Remove a context from the document loader cache.
|
|
309
|
+
* @param url The url the ld context is for.
|
|
310
|
+
* @returns Nothing.
|
|
311
|
+
*/
|
|
312
|
+
static async documentCacheRemove(url) {
|
|
313
|
+
FetchHelper.removeCacheEntry(url);
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Document loader which uses a caching mechanism.
|
|
317
|
+
* @param url The document url to load.
|
|
318
|
+
* @returns The document.
|
|
319
|
+
* @internal
|
|
320
|
+
*/
|
|
321
|
+
static async documentLoader(url) {
|
|
322
|
+
const redirects = JsonLdProcessor.getRedirects();
|
|
323
|
+
for (const redirect of redirects) {
|
|
324
|
+
if (redirect.from.test(url)) {
|
|
325
|
+
url = redirect.to;
|
|
326
|
+
break;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
try {
|
|
330
|
+
const response = await FetchHelper.fetchJson(JsonLdProcessor.CLASS_NAME, url, HttpMethod.GET, undefined, {
|
|
331
|
+
cacheTtlMs: JsonLdProcessor.getCacheLimit(),
|
|
332
|
+
headers: {
|
|
333
|
+
[HeaderTypes.Accept]: MimeTypes.JsonLd
|
|
334
|
+
}
|
|
335
|
+
});
|
|
336
|
+
return {
|
|
337
|
+
documentUrl: url,
|
|
338
|
+
document: response
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
catch (err) {
|
|
342
|
+
const error = BaseError.fromError(err);
|
|
343
|
+
if (error.message.includes("is not valid JSON")) {
|
|
344
|
+
const response = await FetchHelper.fetchJson(JsonLdProcessor.CLASS_NAME, url, HttpMethod.GET, undefined, {
|
|
345
|
+
cacheTtlMs: JsonLdProcessor.getCacheLimit(),
|
|
346
|
+
headers: {
|
|
347
|
+
[HeaderTypes.Accept]: MimeTypes.Json
|
|
348
|
+
}
|
|
349
|
+
});
|
|
350
|
+
return {
|
|
351
|
+
documentUrl: url,
|
|
352
|
+
document: response
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
throw err;
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* Handle common errors.
|
|
360
|
+
* @param err The error to handle.
|
|
361
|
+
* @internal
|
|
362
|
+
*/
|
|
363
|
+
static handleCommonErrors(err) {
|
|
364
|
+
if (Is.object(err) &&
|
|
365
|
+
err.name === "jsonld.InvalidUrl") {
|
|
366
|
+
throw new GeneralError(JsonLdProcessor.CLASS_NAME, "invalidUrl", { url: err.details?.url }, err);
|
|
367
|
+
}
|
|
368
|
+
else if (Is.object(err) &&
|
|
369
|
+
err.name.startsWith("jsonld.")) {
|
|
370
|
+
const { code, ...other } = err.details ?? {};
|
|
371
|
+
throw new GeneralError(JsonLdProcessor.CLASS_NAME, "jsonLdError", { code, ...other }, err);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
//# sourceMappingURL=jsonLdProcessor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsonLdProcessor.js","sourceRoot":"","sources":["../../../src/utils/jsonLdProcessor.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,EAAE,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAExF,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAChF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,IAAI,EAAE,CAAC;YAC7C,MAAM,IAAI,YAAY,CAAC,eAAe,CAAC,UAAU,EAAE,aAAa,EAAE,EAAE,IAAI,EAAE,GAAG,KAAK,EAAE,EAAE,GAAG,CAAC,CAAC;QAC5F,CAAC;IACF,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { BaseError, GeneralError, Is, ObjectHelper, SharedStore } from \"@twin.org/core\";\nimport { nameof } from \"@twin.org/nameof\";\nimport { FetchHelper, HeaderTypes, HttpMethod, MimeTypes } from \"@twin.org/web\";\nimport jsonLd from \"jsonld\";\nimport type { JsonLd, RemoteDocument, Url } from \"jsonld/jsonld-spec.js\";\nimport type { IJsonLdContextDefinition } from \"../models/IJsonLdContextDefinition.js\";\nimport type { IJsonLdContextDefinitionElement } from \"../models/IJsonLdContextDefinitionElement.js\";\nimport type { IJsonLdContextDefinitionRoot } from \"../models/IJsonLdContextDefinitionRoot.js\";\nimport type { IJsonLdNodeObject } from \"../models/IJsonLdNodeObject.js\";\n\n/**\n * JSON-LD Processor.\n */\nexport class JsonLdProcessor {\n\t/**\n\t * The class name.\n\t * @internal\n\t */\n\tpublic static readonly CLASS_NAME = nameof<JsonLdProcessor>();\n\n\t/**\n\t * The document loader to use.\n\t * @param documentLoader The document loader to use.\n\t */\n\tpublic static setDocumentLoader(documentLoader: (url: Url) => Promise<RemoteDocument>): void {\n\t\tSharedStore.set(\"jsonLdDocumentLoader\", documentLoader);\n\t}\n\n\t/**\n\t * The document loader to use for retrieving JSON-LD documents.\n\t * @returns The document loader.\n\t */\n\tpublic static getDocumentLoader(): (url: Url) => Promise<RemoteDocument> {\n\t\tlet documentLoader =\n\t\t\tSharedStore.get<(url: Url) => Promise<RemoteDocument>>(\"jsonLdDocumentLoader\");\n\t\tif (!Is.function(documentLoader)) {\n\t\t\tdocumentLoader = async (url: string) => JsonLdProcessor.documentLoader(url);\n\t\t}\n\t\treturn documentLoader;\n\t}\n\n\t/**\n\t * Set the cache time limit for documents.\n\t * @param cacheLimitMs The cache limit in milliseconds.\n\t */\n\tpublic static setCacheLimit(cacheLimitMs: number): void {\n\t\tSharedStore.set(\"jsonLdDocumentCacheLimit\", cacheLimitMs);\n\t}\n\n\t/**\n\t * Get the cache limit for documents.\n\t * @returns The document loader.\n\t */\n\tpublic static getCacheLimit(): number {\n\t\tlet cacheLimitMs = SharedStore.get<number>(\"jsonLdDocumentCacheLimit\");\n\t\tif (Is.empty(cacheLimitMs)) {\n\t\t\tcacheLimitMs = 3600000;\n\t\t\tSharedStore.set(\"jsonLdDocumentCacheLimit\", cacheLimitMs);\n\t\t}\n\t\treturn cacheLimitMs;\n\t}\n\n\t/**\n\t * Set the global redirects for JSON-LD, use addRedirect for default handling.\n\t * @param redirects The redirects to use.\n\t */\n\tpublic static setRedirects(\n\t\tredirects: {\n\t\t\tfrom: RegExp;\n\t\t\tto: string;\n\t\t}[]\n\t): void {\n\t\tSharedStore.set(\"jsonLdRedirects\", redirects);\n\t}\n\n\t/**\n\t * Get the global redirects for JSON-LD.\n\t * @returns The registered redirects.\n\t */\n\tpublic static getRedirects(): {\n\t\tfrom: RegExp;\n\t\tto: string;\n\t}[] {\n\t\tlet redirects = SharedStore.get<\n\t\t\t{\n\t\t\t\tfrom: RegExp;\n\t\t\t\tto: string;\n\t\t\t}[]\n\t\t>(\"jsonLdRedirects\");\n\t\tif (Is.empty(redirects)) {\n\t\t\tredirects = [];\n\t\t\tSharedStore.set(\"jsonLdRedirects\", redirects);\n\t\t}\n\t\treturn redirects;\n\t}\n\n\t/**\n\t * Compact a document according to a particular context.\n\t * @param document The JSON-LD document to compact.\n\t * @param context The context to compact the document to, if not provided will use the one in the document.\n\t * @param options The options for compacting the document.\n\t * @param options.itemListOverride Whether to override the itemListElement context with a set, defaults to true.\n\t * @returns The compacted JSON-LD document.\n\t */\n\tpublic static async compact<T>(\n\t\tdocument: T,\n\t\tcontext?: IJsonLdContextDefinitionRoot,\n\t\toptions?: { itemListOverride: boolean }\n\t): Promise<T> {\n\t\ttry {\n\t\t\tif (Is.object<IJsonLdNodeObject>(document)) {\n\t\t\t\t// If the user didn't provide a context, use the one from the document\n\t\t\t\tif (Is.empty(context) && !Is.empty(document[\"@context\"])) {\n\t\t\t\t\tcontext = document[\"@context\"];\n\t\t\t\t}\n\n\t\t\t\tconst overrideListElementOption = options?.itemListOverride ?? true;\n\t\t\t\tlet overrideContext: IJsonLdContextDefinitionElement | undefined;\n\n\t\t\t\tif (overrideListElementOption) {\n\t\t\t\t\t// The compactArrays flag doesn't work with the current version of jsonld.js\n\t\t\t\t\t// For list results we standardise on ItemList and itemListElement\n\t\t\t\t\t// so we modify the schema.org type for itemListElement to be a set which bypasses the issue\n\t\t\t\t\t// https://github.com/digitalbazaar/jsonld.js/issues/247\n\t\t\t\t\toverrideContext = {\n\t\t\t\t\t\titemListElement: {\n\t\t\t\t\t\t\t\"@id\": \"http://schema.org/itemListElement\",\n\t\t\t\t\t\t\t\"@container\": \"@set\",\n\t\t\t\t\t\t\t\"@protected\": true\n\t\t\t\t\t\t}\n\t\t\t\t\t};\n\n\t\t\t\t\tif (Is.object(context) && \"@context\" in context) {\n\t\t\t\t\t\t// If the context is an object, we need to merge it with the override context\n\t\t\t\t\t\tcontext = JsonLdProcessor.combineContexts(\n\t\t\t\t\t\t\tcontext[\"@context\"] as IJsonLdContextDefinitionRoot,\n\t\t\t\t\t\t\toverrideContext\n\t\t\t\t\t\t);\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// If the context is a string or an array, we need to merge it with the override context\n\t\t\t\t\t\tcontext = JsonLdProcessor.combineContexts(context, overrideContext);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst compacted = await jsonLd.compact(\n\t\t\t\t\tObjectHelper.removeEmptyProperties(document),\n\t\t\t\t\tcontext as IJsonLdContextDefinition,\n\t\t\t\t\t{\n\t\t\t\t\t\tdocumentLoader: JsonLdProcessor.getDocumentLoader()\n\t\t\t\t\t}\n\t\t\t\t);\n\n\t\t\t\tif (!Is.empty(overrideContext)) {\n\t\t\t\t\t// Remove the override context from the compacted document\n\t\t\t\t\tcompacted[\"@context\"] = JsonLdProcessor.removeContexts(\n\t\t\t\t\t\tcompacted[\"@context\"] as IJsonLdContextDefinitionRoot,\n\t\t\t\t\t\t[overrideContext]\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\treturn compacted as T;\n\t\t\t}\n\t\t\treturn document;\n\t\t} catch (err) {\n\t\t\tJsonLdProcessor.handleCommonErrors(err);\n\n\t\t\tthrow new GeneralError(JsonLdProcessor.CLASS_NAME, \"compact\", undefined, err);\n\t\t}\n\t}\n\n\t/**\n\t * Expand a document, removing its context.\n\t * @param compacted The compacted JSON-LD document to expand.\n\t * @returns The expanded JSON-LD document.\n\t */\n\tpublic static async expand<T>(compacted: T): Promise<IJsonLdNodeObject[]> {\n\t\ttry {\n\t\t\tif (Is.object<IJsonLdNodeObject>(compacted)) {\n\t\t\t\tconst expanded = await jsonLd.expand(ObjectHelper.removeEmptyProperties(compacted), {\n\t\t\t\t\tdocumentLoader: JsonLdProcessor.getDocumentLoader()\n\t\t\t\t});\n\t\t\t\treturn expanded;\n\t\t\t}\n\t\t\treturn [];\n\t\t} catch (err) {\n\t\t\tJsonLdProcessor.handleCommonErrors(err);\n\n\t\t\tthrow new GeneralError(JsonLdProcessor.CLASS_NAME, \"expand\", undefined, err);\n\t\t}\n\t}\n\n\t/**\n\t * Canonize a document.\n\t * @param document The document to canonize.\n\t * @param options The options for canonization.\n\t * @param options.algorithm The algorithm to use for canonization, defaults to URDNA2015.\n\t * @returns The canonized document.\n\t */\n\tpublic static async canonize<T extends IJsonLdNodeObject>(\n\t\tdocument: T,\n\t\toptions?: {\n\t\t\talgorithm?: \"URDNA2015\" | \"URGNA2012\" | undefined;\n\t\t}\n\t): Promise<string> {\n\t\ttry {\n\t\t\tconst normalized = await jsonLd.canonize(ObjectHelper.removeEmptyProperties(document), {\n\t\t\t\talgorithm: options?.algorithm ?? \"URDNA2015\",\n\t\t\t\tformat: \"application/n-quads\",\n\t\t\t\tdocumentLoader: JsonLdProcessor.getDocumentLoader()\n\t\t\t});\n\t\t\treturn normalized;\n\t\t} catch (err) {\n\t\t\tJsonLdProcessor.handleCommonErrors(err);\n\n\t\t\tthrow new GeneralError(JsonLdProcessor.CLASS_NAME, \"canonize\", undefined, err);\n\t\t}\n\t}\n\n\t/**\n\t * Add a redirect to use during document resolution.\n\t * @param from The URL to redirect from.\n\t * @param to The URL to redirect to.\n\t */\n\tpublic static addRedirect(from: RegExp, to: string): void {\n\t\tconst redirects = JsonLdProcessor.getRedirects();\n\t\tif (!redirects.some(r => r.from === from)) {\n\t\t\tredirects.push({ from, to });\n\t\t}\n\t}\n\n\t/**\n\t * Combine contexts.\n\t * @param context1 The first JSON-LD context to combine.\n\t * @param context2 The second JSON-LD context to combine.\n\t * @returns The combined context.\n\t */\n\tpublic static combineContexts(\n\t\tcontext1: IJsonLdContextDefinitionRoot | undefined,\n\t\tcontext2: IJsonLdContextDefinitionRoot | undefined\n\t): IJsonLdContextDefinitionRoot | undefined {\n\t\tconst combinedContext: IJsonLdContextDefinitionRoot = [];\n\n\t\tif (Is.string(context1)) {\n\t\t\tif (!combinedContext.includes(context1)) {\n\t\t\t\tcombinedContext.push(context1);\n\t\t\t}\n\t\t} else if (Is.array(context1)) {\n\t\t\tfor (const context of context1) {\n\t\t\t\tconst hasMatch = combinedContext.some(c => ObjectHelper.equal(c, context));\n\t\t\t\tif (!hasMatch) {\n\t\t\t\t\tcombinedContext.push(context);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (Is.object(context1)) {\n\t\t\tconst hasMatch = combinedContext.some(c => ObjectHelper.equal(c, context1));\n\t\t\tif (!hasMatch) {\n\t\t\t\tcombinedContext.push(context1);\n\t\t\t}\n\t\t}\n\n\t\tif (Is.string(context2)) {\n\t\t\tif (!combinedContext.includes(context2)) {\n\t\t\t\tcombinedContext.push(context2);\n\t\t\t}\n\t\t} else if (Is.array(context2)) {\n\t\t\tfor (const context of context2) {\n\t\t\t\tconst hasMatch = combinedContext.some(c => ObjectHelper.equal(c, context));\n\t\t\t\tif (!hasMatch) {\n\t\t\t\t\tcombinedContext.push(context);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (Is.object(context2)) {\n\t\t\tconst hasMatch = combinedContext.some(c => ObjectHelper.equal(c, context2));\n\t\t\tif (!hasMatch) {\n\t\t\t\tcombinedContext.push(context2);\n\t\t\t}\n\t\t}\n\n\t\tif (combinedContext.length === 0) {\n\t\t\treturn null;\n\t\t}\n\n\t\tif (combinedContext.length === 1) {\n\t\t\treturn combinedContext[0];\n\t\t}\n\n\t\treturn combinedContext;\n\t}\n\n\t/**\n\t * Gather all the contexts from the element and it's children.\n\t * @param element The element to gather the contexts from.\n\t * @param initial The initial context.\n\t * @returns The combined contexts.\n\t */\n\tpublic static gatherContexts<T>(\n\t\telement: T,\n\t\tinitial?: IJsonLdContextDefinitionRoot\n\t): IJsonLdContextDefinitionRoot | undefined {\n\t\tlet combinedContexts: IJsonLdContextDefinitionRoot | undefined = initial;\n\n\t\tif (Is.object<IJsonLdNodeObject>(element)) {\n\t\t\tif (!Is.empty(element[\"@context\"])) {\n\t\t\t\tcombinedContexts = JsonLdProcessor.combineContexts(\n\t\t\t\t\tinitial,\n\t\t\t\t\telement[\"@context\"] as IJsonLdContextDefinitionRoot\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tfor (const prop of Object.keys(element)) {\n\t\t\t\tconst value = element[prop];\n\t\t\t\tif (Is.object(value)) {\n\t\t\t\t\tcombinedContexts = JsonLdProcessor.gatherContexts(\n\t\t\t\t\t\tvalue as IJsonLdNodeObject,\n\t\t\t\t\t\tcombinedContexts\n\t\t\t\t\t);\n\t\t\t\t} else if (Is.array(value)) {\n\t\t\t\t\tfor (const item of value) {\n\t\t\t\t\t\tif (Is.object(item)) {\n\t\t\t\t\t\t\tcombinedContexts = JsonLdProcessor.gatherContexts(\n\t\t\t\t\t\t\t\titem as IJsonLdNodeObject,\n\t\t\t\t\t\t\t\tcombinedContexts\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn combinedContexts;\n\t}\n\n\t/**\n\t * Remove all the contexts that match the pattern.\n\t * @param context The context to remove the entries from.\n\t * @param match The element to try and match.\n\t * @returns The updated contexts.\n\t */\n\tpublic static removeContexts(\n\t\tcontext: IJsonLdContextDefinitionRoot | undefined,\n\t\tmatch?: IJsonLdContextDefinitionElement[]\n\t): IJsonLdContextDefinitionRoot | undefined {\n\t\tif (!Is.arrayValue(match)) {\n\t\t\treturn context;\n\t\t}\n\n\t\tlet finalContext: IJsonLdContextDefinitionRoot | undefined;\n\t\tif (Is.string(context)) {\n\t\t\tfor (const m of match) {\n\t\t\t\tif (context === m) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (Is.array(context)) {\n\t\t\tfor (const item of context) {\n\t\t\t\tconst hasMatch = match.some(m => ObjectHelper.equal(m, item));\n\t\t\t\tif (!hasMatch) {\n\t\t\t\t\tfinalContext ??= [];\n\t\t\t\t\tif (Is.array(finalContext)) {\n\t\t\t\t\t\tfinalContext.push(item);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (Is.object(context)) {\n\t\t\tconst hasMatch = match.some(m => ObjectHelper.equal(m, context));\n\t\t\tif (!hasMatch) {\n\t\t\t\tfinalContext = context;\n\t\t\t}\n\t\t}\n\n\t\treturn Is.arrayValue(finalContext) && finalContext.length === 1\n\t\t\t? finalContext[0]\n\t\t\t: finalContext;\n\t}\n\n\t/**\n\t * Add a context directly to the document loader cache.\n\t * @param url The url the ld context is for.\n\t * @param ldContext The context to add.\n\t * @returns Nothing.\n\t */\n\tpublic static async documentCacheAdd(url: string, ldContext: unknown): Promise<void> {\n\t\tawait FetchHelper.setCacheEntry(url, ldContext);\n\t}\n\n\t/**\n\t * Remove a context from the document loader cache.\n\t * @param url The url the ld context is for.\n\t * @returns Nothing.\n\t */\n\tpublic static async documentCacheRemove(url: string): Promise<void> {\n\t\tFetchHelper.removeCacheEntry(url);\n\t}\n\n\t/**\n\t * Document loader which uses a caching mechanism.\n\t * @param url The document url to load.\n\t * @returns The document.\n\t * @internal\n\t */\n\tprivate static async documentLoader(url: Url): Promise<RemoteDocument> {\n\t\tconst redirects = JsonLdProcessor.getRedirects();\n\t\tfor (const redirect of redirects) {\n\t\t\tif (redirect.from.test(url)) {\n\t\t\t\turl = redirect.to;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\ttry {\n\t\t\tconst response = await FetchHelper.fetchJson<never, JsonLd>(\n\t\t\t\tJsonLdProcessor.CLASS_NAME,\n\t\t\t\turl,\n\t\t\t\tHttpMethod.GET,\n\t\t\t\tundefined,\n\t\t\t\t{\n\t\t\t\t\tcacheTtlMs: JsonLdProcessor.getCacheLimit(),\n\t\t\t\t\theaders: {\n\t\t\t\t\t\t[HeaderTypes.Accept]: MimeTypes.JsonLd\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t);\n\n\t\t\treturn {\n\t\t\t\tdocumentUrl: url,\n\t\t\t\tdocument: response\n\t\t\t};\n\t\t} catch (err) {\n\t\t\tconst error = BaseError.fromError(err);\n\t\t\tif (error.message.includes(\"is not valid JSON\")) {\n\t\t\t\tconst response = await FetchHelper.fetchJson<never, JsonLd>(\n\t\t\t\t\tJsonLdProcessor.CLASS_NAME,\n\t\t\t\t\turl,\n\t\t\t\t\tHttpMethod.GET,\n\t\t\t\t\tundefined,\n\t\t\t\t\t{\n\t\t\t\t\t\tcacheTtlMs: JsonLdProcessor.getCacheLimit(),\n\t\t\t\t\t\theaders: {\n\t\t\t\t\t\t\t[HeaderTypes.Accept]: MimeTypes.Json\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t);\n\n\t\t\t\treturn {\n\t\t\t\t\tdocumentUrl: url,\n\t\t\t\t\tdocument: response\n\t\t\t\t};\n\t\t\t}\n\t\t\tthrow err;\n\t\t}\n\t}\n\n\t/**\n\t * Handle common errors.\n\t * @param err The error to handle.\n\t * @internal\n\t */\n\tprivate static handleCommonErrors(err: unknown): void {\n\t\tif (\n\t\t\tIs.object<{ name: string; details?: { url?: string } }>(err) &&\n\t\t\terr.name === \"jsonld.InvalidUrl\"\n\t\t) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tJsonLdProcessor.CLASS_NAME,\n\t\t\t\t\"invalidUrl\",\n\t\t\t\t{ url: err.details?.url },\n\t\t\t\terr\n\t\t\t);\n\t\t} else if (\n\t\t\tIs.object<{ name: string; details?: { code: string } & { [id: string]: unknown } }>(err) &&\n\t\t\terr.name.startsWith(\"jsonld.\")\n\t\t) {\n\t\t\tconst { code, ...other } = err.details ?? {};\n\t\t\tthrow new GeneralError(JsonLdProcessor.CLASS_NAME, \"jsonLdError\", { code, ...other }, err);\n\t\t}\n\t}\n}\n"]}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
export * from "./dataTypes/jsonLdDataTypes";
|
|
2
|
-
export * from "./models/IJsonLdContainerType";
|
|
3
|
-
export * from "./models/IJsonLdContainerTypeArray";
|
|
4
|
-
export * from "./models/IJsonLdContextDefinition";
|
|
5
|
-
export * from "./models/IJsonLdContextDefinitionElement";
|
|
6
|
-
export * from "./models/IJsonLdContextDefinitionRoot";
|
|
7
|
-
export * from "./models/IJsonLdDocument";
|
|
8
|
-
export * from "./models/IJsonLdExpandedTermDefinition";
|
|
9
|
-
export * from "./models/IJsonLdGraphObject";
|
|
10
|
-
export * from "./models/IJsonLdIdMap";
|
|
11
|
-
export * from "./models/IJsonLdIncludedBlock";
|
|
12
|
-
export * from "./models/IJsonLdIndexMap";
|
|
13
|
-
export * from "./models/IJsonLdIndexMapItem";
|
|
14
|
-
export * from "./models/IJsonLdJsonArray";
|
|
15
|
-
export * from "./models/IJsonLdJsonObject";
|
|
16
|
-
export * from "./models/IJsonLdJsonPrimitive";
|
|
17
|
-
export * from "./models/IJsonLdJsonValue";
|
|
18
|
-
export * from "./models/IJsonLdLanguageMap";
|
|
19
|
-
export * from "./models/IJsonLdListObject";
|
|
20
|
-
export * from "./models/IJsonLdListOrSetItem";
|
|
21
|
-
export * from "./models/IJsonLdNodeObject";
|
|
22
|
-
export * from "./models/IJsonLdNodePrimitive";
|
|
23
|
-
export * from "./models/IJsonLdObject";
|
|
24
|
-
export * from "./models/IJsonLdSetObject";
|
|
25
|
-
export * from "./models/IJsonLdTypeMap";
|
|
26
|
-
export * from "./models/IJsonLdValueObject";
|
|
27
|
-
export * from "./models/jsonLdContexts";
|
|
28
|
-
export * from "./models/jsonLdTypes";
|
|
29
|
-
export * from "./utils/jsonLdHelper";
|
|
30
|
-
export * from "./utils/jsonLdProcessor";
|
|
1
|
+
export * from "./dataTypes/jsonLdDataTypes.js";
|
|
2
|
+
export * from "./models/IJsonLdContainerType.js";
|
|
3
|
+
export * from "./models/IJsonLdContainerTypeArray.js";
|
|
4
|
+
export * from "./models/IJsonLdContextDefinition.js";
|
|
5
|
+
export * from "./models/IJsonLdContextDefinitionElement.js";
|
|
6
|
+
export * from "./models/IJsonLdContextDefinitionRoot.js";
|
|
7
|
+
export * from "./models/IJsonLdDocument.js";
|
|
8
|
+
export * from "./models/IJsonLdExpandedTermDefinition.js";
|
|
9
|
+
export * from "./models/IJsonLdGraphObject.js";
|
|
10
|
+
export * from "./models/IJsonLdIdMap.js";
|
|
11
|
+
export * from "./models/IJsonLdIncludedBlock.js";
|
|
12
|
+
export * from "./models/IJsonLdIndexMap.js";
|
|
13
|
+
export * from "./models/IJsonLdIndexMapItem.js";
|
|
14
|
+
export * from "./models/IJsonLdJsonArray.js";
|
|
15
|
+
export * from "./models/IJsonLdJsonObject.js";
|
|
16
|
+
export * from "./models/IJsonLdJsonPrimitive.js";
|
|
17
|
+
export * from "./models/IJsonLdJsonValue.js";
|
|
18
|
+
export * from "./models/IJsonLdLanguageMap.js";
|
|
19
|
+
export * from "./models/IJsonLdListObject.js";
|
|
20
|
+
export * from "./models/IJsonLdListOrSetItem.js";
|
|
21
|
+
export * from "./models/IJsonLdNodeObject.js";
|
|
22
|
+
export * from "./models/IJsonLdNodePrimitive.js";
|
|
23
|
+
export * from "./models/IJsonLdObject.js";
|
|
24
|
+
export * from "./models/IJsonLdSetObject.js";
|
|
25
|
+
export * from "./models/IJsonLdTypeMap.js";
|
|
26
|
+
export * from "./models/IJsonLdValueObject.js";
|
|
27
|
+
export * from "./models/jsonLdContexts.js";
|
|
28
|
+
export * from "./models/jsonLdTypes.js";
|
|
29
|
+
export * from "./utils/jsonLdHelper.js";
|
|
30
|
+
export * from "./utils/jsonLdProcessor.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { IJsonLdContainerType } from "./IJsonLdContainerType";
|
|
1
|
+
import type { IJsonLdContainerType } from "./IJsonLdContainerType.js";
|
|
2
2
|
/**
|
|
3
3
|
* This is a copy of the types from the npm jsonld package. This is necessary as the JSON schema generators
|
|
4
4
|
* that are used in other packages cannot understand some of the types e.g. OrArray
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { IJsonLdExpandedTermDefinition } from "./IJsonLdExpandedTermDefinition";
|
|
1
|
+
import type { IJsonLdExpandedTermDefinition } from "./IJsonLdExpandedTermDefinition.js";
|
|
2
2
|
/**
|
|
3
3
|
* This is a copy of the types from the npm jsonld package. This is necessary as the JSON schema generators
|
|
4
4
|
* that are used in other packages cannot understand some of the types e.g. OrArray
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { IJsonLdContextDefinition } from "./IJsonLdContextDefinition";
|
|
1
|
+
import type { IJsonLdContextDefinition } from "./IJsonLdContextDefinition.js";
|
|
2
2
|
/**
|
|
3
3
|
* This is a copy of the types from the npm jsonld package. This is necessary as the JSON schema generators
|
|
4
4
|
* that are used in other packages cannot understand some of the types e.g. OrArray
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { IJsonLdContextDefinitionElement } from "./IJsonLdContextDefinitionElement";
|
|
1
|
+
import type { IJsonLdContextDefinitionElement } from "./IJsonLdContextDefinitionElement.js";
|
|
2
2
|
/**
|
|
3
3
|
* This is a copy of the types from the npm jsonld package. This is necessary as the JSON schema generators
|
|
4
4
|
* that are used in other packages cannot understand some of the types e.g. OrArray
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { IJsonLdContextDefinitionRoot } from "./IJsonLdContextDefinitionRoot";
|
|
2
|
-
import type { IJsonLdNodeObject } from "./IJsonLdNodeObject";
|
|
3
|
-
import type { IJsonLdValueObject } from "./IJsonLdValueObject";
|
|
1
|
+
import type { IJsonLdContextDefinitionRoot } from "./IJsonLdContextDefinitionRoot.js";
|
|
2
|
+
import type { IJsonLdNodeObject } from "./IJsonLdNodeObject.js";
|
|
3
|
+
import type { IJsonLdValueObject } from "./IJsonLdValueObject.js";
|
|
4
4
|
/**
|
|
5
5
|
* This is a copy of the types from the npm jsonld package. This is necessary as the JSON schema generators
|
|
6
6
|
* that are used in other packages cannot understand some of the types e.g. OrArray
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { IJsonLdContainerType } from "./IJsonLdContainerType";
|
|
2
|
-
import type { IJsonLdContainerTypeArray } from "./IJsonLdContainerTypeArray";
|
|
3
|
-
import type { IJsonLdContextDefinition } from "./IJsonLdContextDefinition";
|
|
1
|
+
import type { IJsonLdContainerType } from "./IJsonLdContainerType.js";
|
|
2
|
+
import type { IJsonLdContainerTypeArray } from "./IJsonLdContainerTypeArray.js";
|
|
3
|
+
import type { IJsonLdContextDefinition } from "./IJsonLdContextDefinition.js";
|
|
4
4
|
/**
|
|
5
5
|
* This is a copy of the types from the npm jsonld package. This is necessary as the JSON schema generators
|
|
6
6
|
* that are used in other packages cannot understand some of the types e.g. OrArray
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { IJsonLdContextDefinitionRoot } from "./IJsonLdContextDefinitionRoot";
|
|
2
|
-
import type { IJsonLdNodeObject } from "./IJsonLdNodeObject";
|
|
1
|
+
import type { IJsonLdContextDefinitionRoot } from "./IJsonLdContextDefinitionRoot.js";
|
|
2
|
+
import type { IJsonLdNodeObject } from "./IJsonLdNodeObject.js";
|
|
3
3
|
/**
|
|
4
4
|
* This is a copy of the types from the npm jsonld package. This is necessary as the JSON schema generators
|
|
5
5
|
* that are used in other packages cannot understand some of the types e.g. OrArray
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { IJsonLdNodeObject } from "./IJsonLdNodeObject";
|
|
1
|
+
import type { IJsonLdNodeObject } from "./IJsonLdNodeObject.js";
|
|
2
2
|
/**
|
|
3
3
|
* This is a copy of the types from the npm jsonld package. This is necessary as the JSON schema generators
|
|
4
4
|
* that are used in other packages cannot understand some of the types e.g. OrArray
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { IJsonLdNodeObject } from "./IJsonLdNodeObject";
|
|
1
|
+
import type { IJsonLdNodeObject } from "./IJsonLdNodeObject.js";
|
|
2
2
|
/**
|
|
3
3
|
* This is a copy of the types from the npm jsonld package. This is necessary as the JSON schema generators
|
|
4
4
|
* that are used in other packages cannot understand some of the types e.g. OrArray
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { IJsonLdIndexMapItem } from "./IJsonLdIndexMapItem";
|
|
1
|
+
import type { IJsonLdIndexMapItem } from "./IJsonLdIndexMapItem.js";
|
|
2
2
|
/**
|
|
3
3
|
* This is a copy of the types from the npm jsonld package. This is necessary as the JSON schema generators
|
|
4
4
|
* that are used in other packages cannot understand some of the types e.g. OrArray
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { IJsonLdListObject } from "./IJsonLdListObject";
|
|
2
|
-
import type { IJsonLdNodeObject } from "./IJsonLdNodeObject";
|
|
3
|
-
import type { IJsonLdSetObject } from "./IJsonLdSetObject";
|
|
4
|
-
import type { IJsonLdValueObject } from "./IJsonLdValueObject";
|
|
1
|
+
import type { IJsonLdListObject } from "./IJsonLdListObject.js";
|
|
2
|
+
import type { IJsonLdNodeObject } from "./IJsonLdNodeObject.js";
|
|
3
|
+
import type { IJsonLdSetObject } from "./IJsonLdSetObject.js";
|
|
4
|
+
import type { IJsonLdValueObject } from "./IJsonLdValueObject.js";
|
|
5
5
|
/**
|
|
6
6
|
* This is a copy of the types from the npm jsonld package. This is necessary as the JSON schema generators
|
|
7
7
|
* that are used in other packages cannot understand some of the types e.g. OrArray
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { IJsonLdJsonValue } from "./IJsonLdJsonValue";
|
|
1
|
+
import type { IJsonLdJsonValue } from "./IJsonLdJsonValue.js";
|
|
2
2
|
/**
|
|
3
3
|
* This is a copy of the types from the npm jsonld package. This is necessary as the JSON schema generators
|
|
4
4
|
* that are used in other packages cannot understand some of the types e.g. OrArray
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { IJsonLdJsonValue } from "./IJsonLdJsonValue";
|
|
1
|
+
import type { IJsonLdJsonValue } from "./IJsonLdJsonValue.js";
|
|
2
2
|
/**
|
|
3
3
|
* This is a copy of the types from the npm jsonld package. This is necessary as the JSON schema generators
|
|
4
4
|
* that are used in other packages cannot understand some of the types e.g. OrArray
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { IJsonLdJsonArray } from "./IJsonLdJsonArray";
|
|
2
|
-
import type { IJsonLdJsonObject } from "./IJsonLdJsonObject";
|
|
3
|
-
import type { IJsonLdJsonPrimitive } from "./IJsonLdJsonPrimitive";
|
|
1
|
+
import type { IJsonLdJsonArray } from "./IJsonLdJsonArray.js";
|
|
2
|
+
import type { IJsonLdJsonObject } from "./IJsonLdJsonObject.js";
|
|
3
|
+
import type { IJsonLdJsonPrimitive } from "./IJsonLdJsonPrimitive.js";
|
|
4
4
|
/**
|
|
5
5
|
* This is a copy of the types from the npm jsonld package. This is necessary as the JSON schema generators
|
|
6
6
|
* that are used in other packages cannot understand some of the types e.g. OrArray
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { IJsonLdListOrSetItem } from "./IJsonLdListOrSetItem";
|
|
1
|
+
import type { IJsonLdListOrSetItem } from "./IJsonLdListOrSetItem.js";
|
|
2
2
|
/**
|
|
3
3
|
* This is a copy of the types from the npm jsonld package. This is necessary as the JSON schema generators
|
|
4
4
|
* that are used in other packages cannot understand some of the types e.g. OrArray
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { IJsonLdNodeObject } from "./IJsonLdNodeObject";
|
|
2
|
-
import type { IJsonLdValueObject } from "./IJsonLdValueObject";
|
|
1
|
+
import type { IJsonLdNodeObject } from "./IJsonLdNodeObject.js";
|
|
2
|
+
import type { IJsonLdValueObject } from "./IJsonLdValueObject.js";
|
|
3
3
|
/**
|
|
4
4
|
* This is a copy of the types from the npm jsonld package. This is necessary as the JSON schema generators
|
|
5
5
|
* that are used in other packages cannot understand some of the types e.g. OrArray
|