@twin.org/data-json-ld 0.0.1-next.23 → 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 +38 -16
- package/dist/esm/index.mjs +38 -16
- package/dist/types/utils/jsonLdProcessor.d.ts +10 -0
- package/docs/changelog.md +1 -1
- package/docs/reference/classes/JsonLdProcessor.md +36 -0
- 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
|
}
|
|
@@ -1591,17 +1584,31 @@ class JsonLdProcessor {
|
|
|
1591
1584
|
return [];
|
|
1592
1585
|
}
|
|
1593
1586
|
catch (err) {
|
|
1594
|
-
|
|
1595
|
-
err.name === "jsonld.InvalidUrl") {
|
|
1596
|
-
throw new core.GeneralError(JsonLdProcessor._CLASS_NAME, "invalidUrl", { url: err.details?.url }, err);
|
|
1597
|
-
}
|
|
1598
|
-
else if (core.Is.object(err) &&
|
|
1599
|
-
err.name.startsWith("jsonld.")) {
|
|
1600
|
-
throw new core.GeneralError(JsonLdProcessor._CLASS_NAME, "jsonldError", err.details, err);
|
|
1601
|
-
}
|
|
1587
|
+
JsonLdProcessor.handleCommonErrors(err);
|
|
1602
1588
|
throw new core.GeneralError(JsonLdProcessor._CLASS_NAME, "expand", undefined, err);
|
|
1603
1589
|
}
|
|
1604
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",
|
|
1603
|
+
documentLoader: JsonLdProcessor.DOCUMENT_LOADER
|
|
1604
|
+
});
|
|
1605
|
+
return normalized;
|
|
1606
|
+
}
|
|
1607
|
+
catch (err) {
|
|
1608
|
+
JsonLdProcessor.handleCommonErrors(err);
|
|
1609
|
+
throw new core.GeneralError(JsonLdProcessor._CLASS_NAME, "canonize", undefined, err);
|
|
1610
|
+
}
|
|
1611
|
+
}
|
|
1605
1612
|
/**
|
|
1606
1613
|
* Add a redirect to use during document resolution.
|
|
1607
1614
|
* @param from The URL to redirect from.
|
|
@@ -1758,6 +1765,21 @@ class JsonLdProcessor {
|
|
|
1758
1765
|
document: response
|
|
1759
1766
|
};
|
|
1760
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
|
+
}
|
|
1761
1783
|
}
|
|
1762
1784
|
|
|
1763
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
|
}
|
|
@@ -1589,17 +1582,31 @@ class JsonLdProcessor {
|
|
|
1589
1582
|
return [];
|
|
1590
1583
|
}
|
|
1591
1584
|
catch (err) {
|
|
1592
|
-
|
|
1593
|
-
err.name === "jsonld.InvalidUrl") {
|
|
1594
|
-
throw new GeneralError(JsonLdProcessor._CLASS_NAME, "invalidUrl", { url: err.details?.url }, err);
|
|
1595
|
-
}
|
|
1596
|
-
else if (Is.object(err) &&
|
|
1597
|
-
err.name.startsWith("jsonld.")) {
|
|
1598
|
-
throw new GeneralError(JsonLdProcessor._CLASS_NAME, "jsonldError", err.details, err);
|
|
1599
|
-
}
|
|
1585
|
+
JsonLdProcessor.handleCommonErrors(err);
|
|
1600
1586
|
throw new GeneralError(JsonLdProcessor._CLASS_NAME, "expand", undefined, err);
|
|
1601
1587
|
}
|
|
1602
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",
|
|
1601
|
+
documentLoader: JsonLdProcessor.DOCUMENT_LOADER
|
|
1602
|
+
});
|
|
1603
|
+
return normalized;
|
|
1604
|
+
}
|
|
1605
|
+
catch (err) {
|
|
1606
|
+
JsonLdProcessor.handleCommonErrors(err);
|
|
1607
|
+
throw new GeneralError(JsonLdProcessor._CLASS_NAME, "canonize", undefined, err);
|
|
1608
|
+
}
|
|
1609
|
+
}
|
|
1603
1610
|
/**
|
|
1604
1611
|
* Add a redirect to use during document resolution.
|
|
1605
1612
|
* @param from The URL to redirect from.
|
|
@@ -1756,6 +1763,21 @@ class JsonLdProcessor {
|
|
|
1756
1763
|
document: response
|
|
1757
1764
|
};
|
|
1758
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
|
+
}
|
|
1759
1781
|
}
|
|
1760
1782
|
|
|
1761
1783
|
export { JsonLdDataTypes, JsonLdHelper, JsonLdProcessor, JsonLdTypes };
|
|
@@ -27,6 +27,16 @@ export declare class JsonLdProcessor {
|
|
|
27
27
|
* @returns The expanded JSON-LD document.
|
|
28
28
|
*/
|
|
29
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
|
@@ -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",
|