@twin.org/data-json-ld 0.0.1-next.21 → 0.0.1-next.23
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
CHANGED
|
@@ -1539,28 +1539,29 @@ class JsonLdProcessor {
|
|
|
1539
1539
|
*/
|
|
1540
1540
|
static async compact(document, context) {
|
|
1541
1541
|
try {
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1542
|
+
if (core.Is.object(document)) {
|
|
1543
|
+
if (core.Is.empty(context)) {
|
|
1544
|
+
context = {};
|
|
1545
|
+
if (core.Is.array(document)) {
|
|
1546
|
+
for (const node of document) {
|
|
1547
|
+
context = JsonLdProcessor.gatherContexts(node, context);
|
|
1548
|
+
}
|
|
1549
1549
|
}
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1550
|
+
else if (core.Is.array(document["@graph"])) {
|
|
1551
|
+
for (const node of document["@graph"]) {
|
|
1552
|
+
context = JsonLdProcessor.gatherContexts(node, context);
|
|
1553
|
+
}
|
|
1554
|
+
}
|
|
1555
|
+
else if (core.Is.object(document)) {
|
|
1556
|
+
context = JsonLdProcessor.gatherContexts(document, context);
|
|
1554
1557
|
}
|
|
1555
1558
|
}
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
}
|
|
1559
|
+
const compacted = await jsonLd.compact(core.ObjectHelper.removeEmptyProperties(document), context, {
|
|
1560
|
+
documentLoader: JsonLdProcessor.DOCUMENT_LOADER
|
|
1561
|
+
});
|
|
1562
|
+
return compacted;
|
|
1559
1563
|
}
|
|
1560
|
-
|
|
1561
|
-
documentLoader: JsonLdProcessor.DOCUMENT_LOADER
|
|
1562
|
-
});
|
|
1563
|
-
return compacted;
|
|
1564
|
+
return document;
|
|
1564
1565
|
}
|
|
1565
1566
|
catch (err) {
|
|
1566
1567
|
if (core.Is.object(err) &&
|
|
@@ -1581,10 +1582,13 @@ class JsonLdProcessor {
|
|
|
1581
1582
|
*/
|
|
1582
1583
|
static async expand(compacted) {
|
|
1583
1584
|
try {
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1585
|
+
if (core.Is.object(compacted)) {
|
|
1586
|
+
const expanded = await jsonLd.expand(core.ObjectHelper.removeEmptyProperties(compacted), {
|
|
1587
|
+
documentLoader: JsonLdProcessor.DOCUMENT_LOADER
|
|
1588
|
+
});
|
|
1589
|
+
return expanded;
|
|
1590
|
+
}
|
|
1591
|
+
return [];
|
|
1588
1592
|
}
|
|
1589
1593
|
catch (err) {
|
|
1590
1594
|
if (core.Is.object(err) &&
|
|
@@ -1670,18 +1674,20 @@ class JsonLdProcessor {
|
|
|
1670
1674
|
*/
|
|
1671
1675
|
static gatherContexts(element, initial) {
|
|
1672
1676
|
let combinedContexts = initial;
|
|
1673
|
-
if (
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
for (const prop of Object.keys(element)) {
|
|
1677
|
-
const value = element[prop];
|
|
1678
|
-
if (core.Is.object(value)) {
|
|
1679
|
-
combinedContexts = this.gatherContexts(value, combinedContexts);
|
|
1677
|
+
if (core.Is.object(element)) {
|
|
1678
|
+
if (!core.Is.empty(element["@context"])) {
|
|
1679
|
+
combinedContexts = JsonLdProcessor.combineContexts(initial, element["@context"]);
|
|
1680
1680
|
}
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1681
|
+
for (const prop of Object.keys(element)) {
|
|
1682
|
+
const value = element[prop];
|
|
1683
|
+
if (core.Is.object(value)) {
|
|
1684
|
+
combinedContexts = this.gatherContexts(value, combinedContexts);
|
|
1685
|
+
}
|
|
1686
|
+
else if (core.Is.array(value)) {
|
|
1687
|
+
for (const item of value) {
|
|
1688
|
+
if (core.Is.object(item)) {
|
|
1689
|
+
combinedContexts = this.gatherContexts(item, combinedContexts);
|
|
1690
|
+
}
|
|
1685
1691
|
}
|
|
1686
1692
|
}
|
|
1687
1693
|
}
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1537,28 +1537,29 @@ class JsonLdProcessor {
|
|
|
1537
1537
|
*/
|
|
1538
1538
|
static async compact(document, context) {
|
|
1539
1539
|
try {
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1540
|
+
if (Is.object(document)) {
|
|
1541
|
+
if (Is.empty(context)) {
|
|
1542
|
+
context = {};
|
|
1543
|
+
if (Is.array(document)) {
|
|
1544
|
+
for (const node of document) {
|
|
1545
|
+
context = JsonLdProcessor.gatherContexts(node, context);
|
|
1546
|
+
}
|
|
1547
1547
|
}
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1548
|
+
else if (Is.array(document["@graph"])) {
|
|
1549
|
+
for (const node of document["@graph"]) {
|
|
1550
|
+
context = JsonLdProcessor.gatherContexts(node, context);
|
|
1551
|
+
}
|
|
1552
|
+
}
|
|
1553
|
+
else if (Is.object(document)) {
|
|
1554
|
+
context = JsonLdProcessor.gatherContexts(document, context);
|
|
1552
1555
|
}
|
|
1553
1556
|
}
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
}
|
|
1557
|
+
const compacted = await jsonLd.compact(ObjectHelper.removeEmptyProperties(document), context, {
|
|
1558
|
+
documentLoader: JsonLdProcessor.DOCUMENT_LOADER
|
|
1559
|
+
});
|
|
1560
|
+
return compacted;
|
|
1557
1561
|
}
|
|
1558
|
-
|
|
1559
|
-
documentLoader: JsonLdProcessor.DOCUMENT_LOADER
|
|
1560
|
-
});
|
|
1561
|
-
return compacted;
|
|
1562
|
+
return document;
|
|
1562
1563
|
}
|
|
1563
1564
|
catch (err) {
|
|
1564
1565
|
if (Is.object(err) &&
|
|
@@ -1579,10 +1580,13 @@ class JsonLdProcessor {
|
|
|
1579
1580
|
*/
|
|
1580
1581
|
static async expand(compacted) {
|
|
1581
1582
|
try {
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1583
|
+
if (Is.object(compacted)) {
|
|
1584
|
+
const expanded = await jsonLd.expand(ObjectHelper.removeEmptyProperties(compacted), {
|
|
1585
|
+
documentLoader: JsonLdProcessor.DOCUMENT_LOADER
|
|
1586
|
+
});
|
|
1587
|
+
return expanded;
|
|
1588
|
+
}
|
|
1589
|
+
return [];
|
|
1586
1590
|
}
|
|
1587
1591
|
catch (err) {
|
|
1588
1592
|
if (Is.object(err) &&
|
|
@@ -1668,18 +1672,20 @@ class JsonLdProcessor {
|
|
|
1668
1672
|
*/
|
|
1669
1673
|
static gatherContexts(element, initial) {
|
|
1670
1674
|
let combinedContexts = initial;
|
|
1671
|
-
if (
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
for (const prop of Object.keys(element)) {
|
|
1675
|
-
const value = element[prop];
|
|
1676
|
-
if (Is.object(value)) {
|
|
1677
|
-
combinedContexts = this.gatherContexts(value, combinedContexts);
|
|
1675
|
+
if (Is.object(element)) {
|
|
1676
|
+
if (!Is.empty(element["@context"])) {
|
|
1677
|
+
combinedContexts = JsonLdProcessor.combineContexts(initial, element["@context"]);
|
|
1678
1678
|
}
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1679
|
+
for (const prop of Object.keys(element)) {
|
|
1680
|
+
const value = element[prop];
|
|
1681
|
+
if (Is.object(value)) {
|
|
1682
|
+
combinedContexts = this.gatherContexts(value, combinedContexts);
|
|
1683
|
+
}
|
|
1684
|
+
else if (Is.array(value)) {
|
|
1685
|
+
for (const item of value) {
|
|
1686
|
+
if (Is.object(item)) {
|
|
1687
|
+
combinedContexts = this.gatherContexts(item, combinedContexts);
|
|
1688
|
+
}
|
|
1683
1689
|
}
|
|
1684
1690
|
}
|
|
1685
1691
|
}
|
|
@@ -20,13 +20,13 @@ export declare class JsonLdProcessor {
|
|
|
20
20
|
* @param context The context to compact the document to, if not provided will try and gather from the object.
|
|
21
21
|
* @returns The compacted JSON-LD document.
|
|
22
22
|
*/
|
|
23
|
-
static compact<T
|
|
23
|
+
static compact<T>(document: T, context?: IJsonLdContextDefinitionRoot): Promise<T>;
|
|
24
24
|
/**
|
|
25
25
|
* Expand a document, removing its context.
|
|
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
30
|
/**
|
|
31
31
|
* Add a redirect to use during document resolution.
|
|
32
32
|
* @param from The URL to redirect from.
|
|
@@ -46,7 +46,7 @@ export declare class JsonLdProcessor {
|
|
|
46
46
|
* @param initial The initial context.
|
|
47
47
|
* @returns The combined contexts.
|
|
48
48
|
*/
|
|
49
|
-
static gatherContexts<T
|
|
49
|
+
static gatherContexts<T>(element: T, initial?: IJsonLdContextDefinitionRoot): IJsonLdContextDefinitionRoot | undefined;
|
|
50
50
|
/**
|
|
51
51
|
* Remove all the contexts that match the pattern.
|
|
52
52
|
* @param context The context to remove the entries from.
|
package/docs/changelog.md
CHANGED
|
@@ -40,7 +40,7 @@ Compact a document according to a particular context.
|
|
|
40
40
|
|
|
41
41
|
#### Type Parameters
|
|
42
42
|
|
|
43
|
-
• **T**
|
|
43
|
+
• **T**
|
|
44
44
|
|
|
45
45
|
#### Parameters
|
|
46
46
|
|
|
@@ -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
|
|
|
@@ -152,7 +152,7 @@ Gather all the contexts from the element and it's children.
|
|
|
152
152
|
|
|
153
153
|
#### Type Parameters
|
|
154
154
|
|
|
155
|
-
• **T**
|
|
155
|
+
• **T**
|
|
156
156
|
|
|
157
157
|
#### Parameters
|
|
158
158
|
|
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.23",
|
|
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.23",
|
|
19
19
|
"@twin.org/entity": "next",
|
|
20
20
|
"@twin.org/nameof": "next",
|
|
21
21
|
"@twin.org/web": "next",
|