@twin.org/data-json-ld 0.0.1-next.21 → 0.0.1-next.22

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.
@@ -1539,28 +1539,29 @@ class JsonLdProcessor {
1539
1539
  */
1540
1540
  static async compact(document, context) {
1541
1541
  try {
1542
- // There is a cast here because the jsonld types are not correct.
1543
- // A context definition can be an array or an object, but the types only allow an object.
1544
- if (core.Is.empty(context)) {
1545
- context = {};
1546
- if (core.Is.array(document)) {
1547
- for (const node of document) {
1548
- context = JsonLdProcessor.gatherContexts(node, context);
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
- else if (core.Is.array(document["@graph"])) {
1552
- for (const node of document["@graph"]) {
1553
- context = JsonLdProcessor.gatherContexts(node, context);
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
- else if (core.Is.object(document)) {
1557
- context = JsonLdProcessor.gatherContexts(document, context);
1558
- }
1559
+ const compacted = await jsonLd.compact(core.ObjectHelper.removeEmptyProperties(document), context, {
1560
+ documentLoader: JsonLdProcessor.DOCUMENT_LOADER
1561
+ });
1562
+ return compacted;
1559
1563
  }
1560
- const compacted = await jsonLd.compact(core.ObjectHelper.removeEmptyProperties(document), context, {
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) &&
@@ -1670,18 +1671,20 @@ class JsonLdProcessor {
1670
1671
  */
1671
1672
  static gatherContexts(element, initial) {
1672
1673
  let combinedContexts = initial;
1673
- if (!core.Is.empty(element["@context"])) {
1674
- combinedContexts = JsonLdProcessor.combineContexts(initial, element["@context"]);
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);
1674
+ if (core.Is.object(element)) {
1675
+ if (!core.Is.empty(element["@context"])) {
1676
+ combinedContexts = JsonLdProcessor.combineContexts(initial, element["@context"]);
1680
1677
  }
1681
- else if (core.Is.array(value)) {
1682
- for (const item of value) {
1683
- if (core.Is.object(item)) {
1684
- combinedContexts = this.gatherContexts(item, combinedContexts);
1678
+ for (const prop of Object.keys(element)) {
1679
+ const value = element[prop];
1680
+ if (core.Is.object(value)) {
1681
+ combinedContexts = this.gatherContexts(value, combinedContexts);
1682
+ }
1683
+ else if (core.Is.array(value)) {
1684
+ for (const item of value) {
1685
+ if (core.Is.object(item)) {
1686
+ combinedContexts = this.gatherContexts(item, combinedContexts);
1687
+ }
1685
1688
  }
1686
1689
  }
1687
1690
  }
@@ -1537,28 +1537,29 @@ class JsonLdProcessor {
1537
1537
  */
1538
1538
  static async compact(document, context) {
1539
1539
  try {
1540
- // There is a cast here because the jsonld types are not correct.
1541
- // A context definition can be an array or an object, but the types only allow an object.
1542
- if (Is.empty(context)) {
1543
- context = {};
1544
- if (Is.array(document)) {
1545
- for (const node of document) {
1546
- context = JsonLdProcessor.gatherContexts(node, context);
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
- else if (Is.array(document["@graph"])) {
1550
- for (const node of document["@graph"]) {
1551
- context = JsonLdProcessor.gatherContexts(node, context);
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
- else if (Is.object(document)) {
1555
- context = JsonLdProcessor.gatherContexts(document, context);
1556
- }
1557
+ const compacted = await jsonLd.compact(ObjectHelper.removeEmptyProperties(document), context, {
1558
+ documentLoader: JsonLdProcessor.DOCUMENT_LOADER
1559
+ });
1560
+ return compacted;
1557
1561
  }
1558
- const compacted = await jsonLd.compact(ObjectHelper.removeEmptyProperties(document), context, {
1559
- documentLoader: JsonLdProcessor.DOCUMENT_LOADER
1560
- });
1561
- return compacted;
1562
+ return document;
1562
1563
  }
1563
1564
  catch (err) {
1564
1565
  if (Is.object(err) &&
@@ -1668,18 +1669,20 @@ class JsonLdProcessor {
1668
1669
  */
1669
1670
  static gatherContexts(element, initial) {
1670
1671
  let combinedContexts = initial;
1671
- if (!Is.empty(element["@context"])) {
1672
- combinedContexts = JsonLdProcessor.combineContexts(initial, element["@context"]);
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);
1672
+ if (Is.object(element)) {
1673
+ if (!Is.empty(element["@context"])) {
1674
+ combinedContexts = JsonLdProcessor.combineContexts(initial, element["@context"]);
1678
1675
  }
1679
- else if (Is.array(value)) {
1680
- for (const item of value) {
1681
- if (Is.object(item)) {
1682
- combinedContexts = this.gatherContexts(item, combinedContexts);
1676
+ for (const prop of Object.keys(element)) {
1677
+ const value = element[prop];
1678
+ if (Is.object(value)) {
1679
+ combinedContexts = this.gatherContexts(value, combinedContexts);
1680
+ }
1681
+ else if (Is.array(value)) {
1682
+ for (const item of value) {
1683
+ if (Is.object(item)) {
1684
+ combinedContexts = this.gatherContexts(item, combinedContexts);
1685
+ }
1683
1686
  }
1684
1687
  }
1685
1688
  }
@@ -20,7 +20,7 @@ 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 extends IJsonLdNodeObject>(document: T, context?: IJsonLdContextDefinitionRoot): Promise<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.
@@ -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 extends IJsonLdNodeObject>(element: T, initial?: IJsonLdContextDefinitionRoot): IJsonLdContextDefinitionRoot | undefined;
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
@@ -1,5 +1,5 @@
1
1
  # @twin.org/data-json-ld - Changelog
2
2
 
3
- ## v0.0.1-next.21
3
+ ## v0.0.1-next.22
4
4
 
5
5
  - Initial Release
@@ -40,7 +40,7 @@ Compact a document according to a particular context.
40
40
 
41
41
  #### Type Parameters
42
42
 
43
- • **T** *extends* [`IJsonLdNodeObject`](../interfaces/IJsonLdNodeObject.md)
43
+ • **T**
44
44
 
45
45
  #### Parameters
46
46
 
@@ -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** *extends* [`IJsonLdNodeObject`](../interfaces/IJsonLdNodeObject.md)
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.21",
3
+ "version": "0.0.1-next.22",
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.21",
18
+ "@twin.org/data-core": "0.0.1-next.22",
19
19
  "@twin.org/entity": "next",
20
20
  "@twin.org/nameof": "next",
21
21
  "@twin.org/web": "next",