@twin.org/data-json-ld 0.0.1-next.22 → 0.0.1-next.24
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/cjs/index.cjs +44 -19
- package/dist/esm/index.mjs +44 -19
- package/dist/types/utils/jsonLdProcessor.d.ts +11 -1
- package/docs/changelog.md +1 -1
- package/docs/reference/classes/JsonLdProcessor.md +37 -1
- package/locales/en.json +1 -0
- package/package.json +2 -2
package/dist/cjs/index.cjs
CHANGED
|
@@ -1564,14 +1564,7 @@ class JsonLdProcessor {
|
|
|
1564
1564
|
return document;
|
|
1565
1565
|
}
|
|
1566
1566
|
catch (err) {
|
|
1567
|
-
|
|
1568
|
-
err.name === "jsonld.InvalidUrl") {
|
|
1569
|
-
throw new core.GeneralError(JsonLdProcessor._CLASS_NAME, "invalidUrl", { url: err.details?.url }, err);
|
|
1570
|
-
}
|
|
1571
|
-
else if (core.Is.object(err) &&
|
|
1572
|
-
err.name.startsWith("jsonld.")) {
|
|
1573
|
-
throw new core.GeneralError(JsonLdProcessor._CLASS_NAME, "jsonldError", err.details, err);
|
|
1574
|
-
}
|
|
1567
|
+
JsonLdProcessor.handleCommonErrors(err);
|
|
1575
1568
|
throw new core.GeneralError(JsonLdProcessor._CLASS_NAME, "compact", undefined, err);
|
|
1576
1569
|
}
|
|
1577
1570
|
}
|
|
@@ -1582,21 +1575,38 @@ class JsonLdProcessor {
|
|
|
1582
1575
|
*/
|
|
1583
1576
|
static async expand(compacted) {
|
|
1584
1577
|
try {
|
|
1585
|
-
|
|
1578
|
+
if (core.Is.object(compacted)) {
|
|
1579
|
+
const expanded = await jsonLd.expand(core.ObjectHelper.removeEmptyProperties(compacted), {
|
|
1580
|
+
documentLoader: JsonLdProcessor.DOCUMENT_LOADER
|
|
1581
|
+
});
|
|
1582
|
+
return expanded;
|
|
1583
|
+
}
|
|
1584
|
+
return [];
|
|
1585
|
+
}
|
|
1586
|
+
catch (err) {
|
|
1587
|
+
JsonLdProcessor.handleCommonErrors(err);
|
|
1588
|
+
throw new core.GeneralError(JsonLdProcessor._CLASS_NAME, "expand", undefined, err);
|
|
1589
|
+
}
|
|
1590
|
+
}
|
|
1591
|
+
/**
|
|
1592
|
+
* Canonize a document.
|
|
1593
|
+
* @param document The document to canonize.
|
|
1594
|
+
* @param options The options for canonization.
|
|
1595
|
+
* @param options.algorithm The algorithm to use for canonization, defaults to URDNA2015.
|
|
1596
|
+
* @returns The canonized document.
|
|
1597
|
+
*/
|
|
1598
|
+
static async canonize(document, options) {
|
|
1599
|
+
try {
|
|
1600
|
+
const normalized = await jsonLd.canonize(core.ObjectHelper.removeEmptyProperties(document), {
|
|
1601
|
+
algorithm: options?.algorithm ?? "URDNA2015",
|
|
1602
|
+
format: "application/n-quads",
|
|
1586
1603
|
documentLoader: JsonLdProcessor.DOCUMENT_LOADER
|
|
1587
1604
|
});
|
|
1588
|
-
return
|
|
1605
|
+
return normalized;
|
|
1589
1606
|
}
|
|
1590
1607
|
catch (err) {
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
throw new core.GeneralError(JsonLdProcessor._CLASS_NAME, "invalidUrl", { url: err.details?.url }, err);
|
|
1594
|
-
}
|
|
1595
|
-
else if (core.Is.object(err) &&
|
|
1596
|
-
err.name.startsWith("jsonld.")) {
|
|
1597
|
-
throw new core.GeneralError(JsonLdProcessor._CLASS_NAME, "jsonldError", err.details, err);
|
|
1598
|
-
}
|
|
1599
|
-
throw new core.GeneralError(JsonLdProcessor._CLASS_NAME, "expand", undefined, err);
|
|
1608
|
+
JsonLdProcessor.handleCommonErrors(err);
|
|
1609
|
+
throw new core.GeneralError(JsonLdProcessor._CLASS_NAME, "canonize", undefined, err);
|
|
1600
1610
|
}
|
|
1601
1611
|
}
|
|
1602
1612
|
/**
|
|
@@ -1755,6 +1765,21 @@ class JsonLdProcessor {
|
|
|
1755
1765
|
document: response
|
|
1756
1766
|
};
|
|
1757
1767
|
}
|
|
1768
|
+
/**
|
|
1769
|
+
* Handle common errors.
|
|
1770
|
+
* @param err The error to handle.
|
|
1771
|
+
* @internal
|
|
1772
|
+
*/
|
|
1773
|
+
static handleCommonErrors(err) {
|
|
1774
|
+
if (core.Is.object(err) &&
|
|
1775
|
+
err.name === "jsonld.InvalidUrl") {
|
|
1776
|
+
throw new core.GeneralError(JsonLdProcessor._CLASS_NAME, "invalidUrl", { url: err.details?.url }, err);
|
|
1777
|
+
}
|
|
1778
|
+
else if (core.Is.object(err) &&
|
|
1779
|
+
err.name.startsWith("jsonld.")) {
|
|
1780
|
+
throw new core.GeneralError(JsonLdProcessor._CLASS_NAME, "jsonldError", err.details, err);
|
|
1781
|
+
}
|
|
1782
|
+
}
|
|
1758
1783
|
}
|
|
1759
1784
|
|
|
1760
1785
|
exports.JsonLdDataTypes = JsonLdDataTypes;
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1562,14 +1562,7 @@ class JsonLdProcessor {
|
|
|
1562
1562
|
return document;
|
|
1563
1563
|
}
|
|
1564
1564
|
catch (err) {
|
|
1565
|
-
|
|
1566
|
-
err.name === "jsonld.InvalidUrl") {
|
|
1567
|
-
throw new GeneralError(JsonLdProcessor._CLASS_NAME, "invalidUrl", { url: err.details?.url }, err);
|
|
1568
|
-
}
|
|
1569
|
-
else if (Is.object(err) &&
|
|
1570
|
-
err.name.startsWith("jsonld.")) {
|
|
1571
|
-
throw new GeneralError(JsonLdProcessor._CLASS_NAME, "jsonldError", err.details, err);
|
|
1572
|
-
}
|
|
1565
|
+
JsonLdProcessor.handleCommonErrors(err);
|
|
1573
1566
|
throw new GeneralError(JsonLdProcessor._CLASS_NAME, "compact", undefined, err);
|
|
1574
1567
|
}
|
|
1575
1568
|
}
|
|
@@ -1580,21 +1573,38 @@ class JsonLdProcessor {
|
|
|
1580
1573
|
*/
|
|
1581
1574
|
static async expand(compacted) {
|
|
1582
1575
|
try {
|
|
1583
|
-
|
|
1576
|
+
if (Is.object(compacted)) {
|
|
1577
|
+
const expanded = await jsonLd.expand(ObjectHelper.removeEmptyProperties(compacted), {
|
|
1578
|
+
documentLoader: JsonLdProcessor.DOCUMENT_LOADER
|
|
1579
|
+
});
|
|
1580
|
+
return expanded;
|
|
1581
|
+
}
|
|
1582
|
+
return [];
|
|
1583
|
+
}
|
|
1584
|
+
catch (err) {
|
|
1585
|
+
JsonLdProcessor.handleCommonErrors(err);
|
|
1586
|
+
throw new GeneralError(JsonLdProcessor._CLASS_NAME, "expand", undefined, err);
|
|
1587
|
+
}
|
|
1588
|
+
}
|
|
1589
|
+
/**
|
|
1590
|
+
* Canonize a document.
|
|
1591
|
+
* @param document The document to canonize.
|
|
1592
|
+
* @param options The options for canonization.
|
|
1593
|
+
* @param options.algorithm The algorithm to use for canonization, defaults to URDNA2015.
|
|
1594
|
+
* @returns The canonized document.
|
|
1595
|
+
*/
|
|
1596
|
+
static async canonize(document, options) {
|
|
1597
|
+
try {
|
|
1598
|
+
const normalized = await jsonLd.canonize(ObjectHelper.removeEmptyProperties(document), {
|
|
1599
|
+
algorithm: options?.algorithm ?? "URDNA2015",
|
|
1600
|
+
format: "application/n-quads",
|
|
1584
1601
|
documentLoader: JsonLdProcessor.DOCUMENT_LOADER
|
|
1585
1602
|
});
|
|
1586
|
-
return
|
|
1603
|
+
return normalized;
|
|
1587
1604
|
}
|
|
1588
1605
|
catch (err) {
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
throw new GeneralError(JsonLdProcessor._CLASS_NAME, "invalidUrl", { url: err.details?.url }, err);
|
|
1592
|
-
}
|
|
1593
|
-
else if (Is.object(err) &&
|
|
1594
|
-
err.name.startsWith("jsonld.")) {
|
|
1595
|
-
throw new GeneralError(JsonLdProcessor._CLASS_NAME, "jsonldError", err.details, err);
|
|
1596
|
-
}
|
|
1597
|
-
throw new GeneralError(JsonLdProcessor._CLASS_NAME, "expand", undefined, err);
|
|
1606
|
+
JsonLdProcessor.handleCommonErrors(err);
|
|
1607
|
+
throw new GeneralError(JsonLdProcessor._CLASS_NAME, "canonize", undefined, err);
|
|
1598
1608
|
}
|
|
1599
1609
|
}
|
|
1600
1610
|
/**
|
|
@@ -1753,6 +1763,21 @@ class JsonLdProcessor {
|
|
|
1753
1763
|
document: response
|
|
1754
1764
|
};
|
|
1755
1765
|
}
|
|
1766
|
+
/**
|
|
1767
|
+
* Handle common errors.
|
|
1768
|
+
* @param err The error to handle.
|
|
1769
|
+
* @internal
|
|
1770
|
+
*/
|
|
1771
|
+
static handleCommonErrors(err) {
|
|
1772
|
+
if (Is.object(err) &&
|
|
1773
|
+
err.name === "jsonld.InvalidUrl") {
|
|
1774
|
+
throw new GeneralError(JsonLdProcessor._CLASS_NAME, "invalidUrl", { url: err.details?.url }, err);
|
|
1775
|
+
}
|
|
1776
|
+
else if (Is.object(err) &&
|
|
1777
|
+
err.name.startsWith("jsonld.")) {
|
|
1778
|
+
throw new GeneralError(JsonLdProcessor._CLASS_NAME, "jsonldError", err.details, err);
|
|
1779
|
+
}
|
|
1780
|
+
}
|
|
1756
1781
|
}
|
|
1757
1782
|
|
|
1758
1783
|
export { JsonLdDataTypes, JsonLdHelper, JsonLdProcessor, JsonLdTypes };
|
|
@@ -26,7 +26,17 @@ export declare class JsonLdProcessor {
|
|
|
26
26
|
* @param compacted The compacted JSON-LD document to expand.
|
|
27
27
|
* @returns The expanded JSON-LD document.
|
|
28
28
|
*/
|
|
29
|
-
static expand<T
|
|
29
|
+
static expand<T>(compacted: T): Promise<IJsonLdNodeObject[]>;
|
|
30
|
+
/**
|
|
31
|
+
* Canonize a document.
|
|
32
|
+
* @param document The document to canonize.
|
|
33
|
+
* @param options The options for canonization.
|
|
34
|
+
* @param options.algorithm The algorithm to use for canonization, defaults to URDNA2015.
|
|
35
|
+
* @returns The canonized document.
|
|
36
|
+
*/
|
|
37
|
+
static canonize<T extends IJsonLdNodeObject>(document: T, options?: {
|
|
38
|
+
algorithm?: "URDNA2015" | "URGNA2012" | undefined;
|
|
39
|
+
}): Promise<string>;
|
|
30
40
|
/**
|
|
31
41
|
* Add a redirect to use during document resolution.
|
|
32
42
|
* @param from The URL to redirect from.
|
package/docs/changelog.md
CHANGED
|
@@ -72,7 +72,7 @@ Expand a document, removing its context.
|
|
|
72
72
|
|
|
73
73
|
#### Type Parameters
|
|
74
74
|
|
|
75
|
-
• **T**
|
|
75
|
+
• **T**
|
|
76
76
|
|
|
77
77
|
#### Parameters
|
|
78
78
|
|
|
@@ -90,6 +90,42 @@ The expanded JSON-LD document.
|
|
|
90
90
|
|
|
91
91
|
***
|
|
92
92
|
|
|
93
|
+
### canonize()
|
|
94
|
+
|
|
95
|
+
> `static` **canonize**\<`T`\>(`document`, `options`?): `Promise`\<`string`\>
|
|
96
|
+
|
|
97
|
+
Canonize a document.
|
|
98
|
+
|
|
99
|
+
#### Type Parameters
|
|
100
|
+
|
|
101
|
+
• **T** *extends* [`IJsonLdNodeObject`](../interfaces/IJsonLdNodeObject.md)
|
|
102
|
+
|
|
103
|
+
#### Parameters
|
|
104
|
+
|
|
105
|
+
##### document
|
|
106
|
+
|
|
107
|
+
`T`
|
|
108
|
+
|
|
109
|
+
The document to canonize.
|
|
110
|
+
|
|
111
|
+
##### options?
|
|
112
|
+
|
|
113
|
+
The options for canonization.
|
|
114
|
+
|
|
115
|
+
###### algorithm
|
|
116
|
+
|
|
117
|
+
`"URDNA2015"` \| `"URGNA2012"`
|
|
118
|
+
|
|
119
|
+
The algorithm to use for canonization, defaults to URDNA2015.
|
|
120
|
+
|
|
121
|
+
#### Returns
|
|
122
|
+
|
|
123
|
+
`Promise`\<`string`\>
|
|
124
|
+
|
|
125
|
+
The canonized document.
|
|
126
|
+
|
|
127
|
+
***
|
|
128
|
+
|
|
93
129
|
### addRedirect()
|
|
94
130
|
|
|
95
131
|
> `static` **addRedirect**(`from`, `to`): `void`
|
package/locales/en.json
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
"jsonLdProcessor": {
|
|
3
3
|
"compact": "The JSON-LD compaction failed",
|
|
4
4
|
"expand": "The JSON-LD expansion failed",
|
|
5
|
+
"canonize": "The JSON-LD canonization failed",
|
|
5
6
|
"invalidUrl": "The JSON-LD processing failed to retrieve from the following url \"{url}\"",
|
|
6
7
|
"jsonldError": "The JSON-LD processing failed due to the following error: \"{code}\""
|
|
7
8
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twin.org/data-json-ld",
|
|
3
|
-
"version": "0.0.1-next.
|
|
3
|
+
"version": "0.0.1-next.24",
|
|
4
4
|
"description": "Models which define the structure of JSON LD",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"@twin.org/core": "next",
|
|
18
|
-
"@twin.org/data-core": "0.0.1-next.
|
|
18
|
+
"@twin.org/data-core": "0.0.1-next.24",
|
|
19
19
|
"@twin.org/entity": "next",
|
|
20
20
|
"@twin.org/nameof": "next",
|
|
21
21
|
"@twin.org/web": "next",
|