@twin.org/data-json-ld 0.0.1-next.4 → 0.0.1-next.6

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.
@@ -12,6 +12,10 @@ var jsonLd = require('jsonld');
12
12
  */
13
13
  // eslint-disable-next-line @typescript-eslint/naming-convention
14
14
  const JsonLdTypes = {
15
+ /**
16
+ * Context Root.
17
+ */
18
+ ContextRoot: "https://schema.twindev.org/json-ld/",
15
19
  /**
16
20
  * Represents JSON-LD Document.
17
21
  */
@@ -1403,6 +1407,96 @@ class JsonLdHelper {
1403
1407
  }
1404
1408
  return validationFailures.length === 0;
1405
1409
  }
1410
+ }
1411
+
1412
+ // Copyright 2024 IOTA Stiftung.
1413
+ // SPDX-License-Identifier: Apache-2.0.
1414
+ /**
1415
+ * JSON-LD Processor.
1416
+ */
1417
+ class JsonLdProcessor {
1418
+ /**
1419
+ * The class name.
1420
+ * @internal
1421
+ */
1422
+ static _CLASS_NAME = "JsonLdProcessor";
1423
+ /**
1424
+ * Redirects to use during document resolution.
1425
+ */
1426
+ static _redirects = [];
1427
+ /**
1428
+ * The document loader to use.
1429
+ */
1430
+ static DOCUMENT_LOADER = async (url) => JsonLdProcessor.documentLoader(url);
1431
+ /**
1432
+ * Compact a document according to a particular context.
1433
+ * @param document The JSON-LD document to compact.
1434
+ * @param context The context to compact the document to, if not provided will try and gather from the object.
1435
+ * @returns The compacted JSON-LD document.
1436
+ */
1437
+ static async compact(document, context) {
1438
+ try {
1439
+ // There is a cast here because the jsonld types are not correct.
1440
+ // A context definition can be an array or an object, but the types only allow an object.
1441
+ if (core.Is.empty(context)) {
1442
+ context = {};
1443
+ if (core.Is.array(document)) {
1444
+ for (const node of document) {
1445
+ context = JsonLdProcessor.gatherContexts(node, context);
1446
+ }
1447
+ }
1448
+ else if (core.Is.array(document["@graph"])) {
1449
+ for (const node of document["@graph"]) {
1450
+ context = JsonLdProcessor.gatherContexts(node, context);
1451
+ }
1452
+ }
1453
+ else if (core.Is.object(document)) {
1454
+ context = JsonLdProcessor.gatherContexts(document, context);
1455
+ }
1456
+ }
1457
+ const compacted = await jsonLd.compact(document, context, {
1458
+ documentLoader: JsonLdProcessor.DOCUMENT_LOADER
1459
+ });
1460
+ return compacted;
1461
+ }
1462
+ catch (err) {
1463
+ if (core.Is.object(err) &&
1464
+ err.name === "jsonld.InvalidUrl") {
1465
+ throw new core.GeneralError(JsonLdProcessor._CLASS_NAME, "invalidUrl", { url: err.details?.url }, err);
1466
+ }
1467
+ throw new core.GeneralError(JsonLdProcessor._CLASS_NAME, "compact", undefined, err);
1468
+ }
1469
+ }
1470
+ /**
1471
+ * Expand a document, removing its context.
1472
+ * @param compacted The compacted JSON-LD document to expand.
1473
+ * @returns The expanded JSON-LD document.
1474
+ */
1475
+ static async expand(compacted) {
1476
+ try {
1477
+ const expanded = await jsonLd.expand(compacted, {
1478
+ documentLoader: JsonLdProcessor.DOCUMENT_LOADER
1479
+ });
1480
+ return expanded;
1481
+ }
1482
+ catch (err) {
1483
+ if (core.Is.object(err) &&
1484
+ err.name === "jsonld.InvalidUrl") {
1485
+ throw new core.GeneralError(JsonLdProcessor._CLASS_NAME, "invalidUrl", { url: err.details?.url }, err);
1486
+ }
1487
+ throw new core.GeneralError(JsonLdProcessor._CLASS_NAME, "expand", undefined, err);
1488
+ }
1489
+ }
1490
+ /**
1491
+ * Add a redirect to use during document resolution.
1492
+ * @param from The URL to redirect from.
1493
+ * @param to The URL to redirect to.
1494
+ */
1495
+ static addRedirect(from, to) {
1496
+ if (!this._redirects.some(r => r.from === from)) {
1497
+ this._redirects.push({ from, to });
1498
+ }
1499
+ }
1406
1500
  /**
1407
1501
  * Extract a property from the JSON-LD.
1408
1502
  * @param nodeObject The JSON-LD node object to extract from.
@@ -1426,7 +1520,7 @@ class JsonLdHelper {
1426
1520
  * @param context2 The second JSON-LD context to combine.
1427
1521
  * @returns The combined context.
1428
1522
  */
1429
- static async combineContexts(context1, context2) {
1523
+ static combineContexts(context1, context2) {
1430
1524
  const combinedContext = [];
1431
1525
  if (core.Is.string(context1)) {
1432
1526
  if (!combinedContext.includes(context1)) {
@@ -1474,77 +1568,31 @@ class JsonLdHelper {
1474
1568
  }
1475
1569
  return combinedContext;
1476
1570
  }
1477
- }
1478
-
1479
- // Copyright 2024 IOTA Stiftung.
1480
- // SPDX-License-Identifier: Apache-2.0.
1481
- /**
1482
- * JSON-LD Processor.
1483
- */
1484
- class JsonLdProcessor {
1485
1571
  /**
1486
- * The class name.
1487
- * @internal
1572
+ * Gather all the contexts from the element and it's children.
1573
+ * @param element The element to gather the contexts from.
1574
+ * @param initial The initial context.
1575
+ * @returns The combined contexts.
1488
1576
  */
1489
- static _CLASS_NAME = "JsonLdProcessor";
1490
- /**
1491
- * Redirects to use during document resolution.
1492
- */
1493
- static _redirects = [];
1494
- /**
1495
- * The document loader to use.
1496
- */
1497
- static DOCUMENT_LOADER = async (url) => JsonLdProcessor.documentLoader(url);
1498
- /**
1499
- * Compact a document according to a particular context.
1500
- * @param document The JSON-LD document to compact.
1501
- * @param context The context to compact the document to.
1502
- * @returns The compacted JSON-LD document.
1503
- */
1504
- static async compact(document, context) {
1505
- try {
1506
- const compacted = await jsonLd.compact(document, context ?? {}, {
1507
- documentLoader: JsonLdProcessor.DOCUMENT_LOADER
1508
- });
1509
- return compacted;
1577
+ static gatherContexts(element, initial) {
1578
+ let combinedContexts = initial;
1579
+ if (!core.Is.empty(element["@context"])) {
1580
+ combinedContexts = JsonLdProcessor.combineContexts(initial, element["@context"]);
1510
1581
  }
1511
- catch (err) {
1512
- if (core.Is.object(err) &&
1513
- err.name === "jsonld.InvalidUrl") {
1514
- throw new core.GeneralError(JsonLdProcessor._CLASS_NAME, "invalidUrl", { url: err.details?.url }, err);
1582
+ for (const prop of Object.keys(element)) {
1583
+ const value = element[prop];
1584
+ if (core.Is.object(value)) {
1585
+ combinedContexts = this.gatherContexts(value, combinedContexts);
1515
1586
  }
1516
- throw new core.GeneralError(JsonLdProcessor._CLASS_NAME, "compact", undefined, err);
1517
- }
1518
- }
1519
- /**
1520
- * Expand a document, removing its context.
1521
- * @param compacted The compacted JSON-LD document to expand.
1522
- * @returns The expanded JSON-LD document.
1523
- */
1524
- static async expand(compacted) {
1525
- try {
1526
- const expanded = await jsonLd.expand(compacted, {
1527
- documentLoader: JsonLdProcessor.DOCUMENT_LOADER
1528
- });
1529
- return expanded;
1530
- }
1531
- catch (err) {
1532
- if (core.Is.object(err) &&
1533
- err.name === "jsonld.InvalidUrl") {
1534
- throw new core.GeneralError(JsonLdProcessor._CLASS_NAME, "invalidUrl", { url: err.details?.url }, err);
1587
+ else if (core.Is.array(value)) {
1588
+ for (const item of value) {
1589
+ if (core.Is.object(item)) {
1590
+ combinedContexts = this.gatherContexts(item, combinedContexts);
1591
+ }
1592
+ }
1535
1593
  }
1536
- throw new core.GeneralError(JsonLdProcessor._CLASS_NAME, "expand", undefined, err);
1537
- }
1538
- }
1539
- /**
1540
- * Add a redirect to use during document resolution.
1541
- * @param from The URL to redirect from.
1542
- * @param to The URL to redirect to.
1543
- */
1544
- static addRedirect(from, to) {
1545
- if (!this._redirects.some(r => r.from === from)) {
1546
- this._redirects.push({ from, to });
1547
1594
  }
1595
+ return combinedContexts;
1548
1596
  }
1549
1597
  /**
1550
1598
  * Document loader which uses a caching mechanism.
@@ -1,5 +1,5 @@
1
1
  import { DataTypeHandlerFactory, DataTypeHelper } from '@twin.org/data-core';
2
- import { Is, ObjectHelper, GeneralError } from '@twin.org/core';
2
+ import { Is, GeneralError, ObjectHelper } from '@twin.org/core';
3
3
  import { FetchHelper, HttpMethod, MimeTypes } from '@twin.org/web';
4
4
  import jsonLd from 'jsonld';
5
5
 
@@ -10,6 +10,10 @@ import jsonLd from 'jsonld';
10
10
  */
11
11
  // eslint-disable-next-line @typescript-eslint/naming-convention
12
12
  const JsonLdTypes = {
13
+ /**
14
+ * Context Root.
15
+ */
16
+ ContextRoot: "https://schema.twindev.org/json-ld/",
13
17
  /**
14
18
  * Represents JSON-LD Document.
15
19
  */
@@ -1401,6 +1405,96 @@ class JsonLdHelper {
1401
1405
  }
1402
1406
  return validationFailures.length === 0;
1403
1407
  }
1408
+ }
1409
+
1410
+ // Copyright 2024 IOTA Stiftung.
1411
+ // SPDX-License-Identifier: Apache-2.0.
1412
+ /**
1413
+ * JSON-LD Processor.
1414
+ */
1415
+ class JsonLdProcessor {
1416
+ /**
1417
+ * The class name.
1418
+ * @internal
1419
+ */
1420
+ static _CLASS_NAME = "JsonLdProcessor";
1421
+ /**
1422
+ * Redirects to use during document resolution.
1423
+ */
1424
+ static _redirects = [];
1425
+ /**
1426
+ * The document loader to use.
1427
+ */
1428
+ static DOCUMENT_LOADER = async (url) => JsonLdProcessor.documentLoader(url);
1429
+ /**
1430
+ * Compact a document according to a particular context.
1431
+ * @param document The JSON-LD document to compact.
1432
+ * @param context The context to compact the document to, if not provided will try and gather from the object.
1433
+ * @returns The compacted JSON-LD document.
1434
+ */
1435
+ static async compact(document, context) {
1436
+ try {
1437
+ // There is a cast here because the jsonld types are not correct.
1438
+ // A context definition can be an array or an object, but the types only allow an object.
1439
+ if (Is.empty(context)) {
1440
+ context = {};
1441
+ if (Is.array(document)) {
1442
+ for (const node of document) {
1443
+ context = JsonLdProcessor.gatherContexts(node, context);
1444
+ }
1445
+ }
1446
+ else if (Is.array(document["@graph"])) {
1447
+ for (const node of document["@graph"]) {
1448
+ context = JsonLdProcessor.gatherContexts(node, context);
1449
+ }
1450
+ }
1451
+ else if (Is.object(document)) {
1452
+ context = JsonLdProcessor.gatherContexts(document, context);
1453
+ }
1454
+ }
1455
+ const compacted = await jsonLd.compact(document, context, {
1456
+ documentLoader: JsonLdProcessor.DOCUMENT_LOADER
1457
+ });
1458
+ return compacted;
1459
+ }
1460
+ catch (err) {
1461
+ if (Is.object(err) &&
1462
+ err.name === "jsonld.InvalidUrl") {
1463
+ throw new GeneralError(JsonLdProcessor._CLASS_NAME, "invalidUrl", { url: err.details?.url }, err);
1464
+ }
1465
+ throw new GeneralError(JsonLdProcessor._CLASS_NAME, "compact", undefined, err);
1466
+ }
1467
+ }
1468
+ /**
1469
+ * Expand a document, removing its context.
1470
+ * @param compacted The compacted JSON-LD document to expand.
1471
+ * @returns The expanded JSON-LD document.
1472
+ */
1473
+ static async expand(compacted) {
1474
+ try {
1475
+ const expanded = await jsonLd.expand(compacted, {
1476
+ documentLoader: JsonLdProcessor.DOCUMENT_LOADER
1477
+ });
1478
+ return expanded;
1479
+ }
1480
+ catch (err) {
1481
+ if (Is.object(err) &&
1482
+ err.name === "jsonld.InvalidUrl") {
1483
+ throw new GeneralError(JsonLdProcessor._CLASS_NAME, "invalidUrl", { url: err.details?.url }, err);
1484
+ }
1485
+ throw new GeneralError(JsonLdProcessor._CLASS_NAME, "expand", undefined, err);
1486
+ }
1487
+ }
1488
+ /**
1489
+ * Add a redirect to use during document resolution.
1490
+ * @param from The URL to redirect from.
1491
+ * @param to The URL to redirect to.
1492
+ */
1493
+ static addRedirect(from, to) {
1494
+ if (!this._redirects.some(r => r.from === from)) {
1495
+ this._redirects.push({ from, to });
1496
+ }
1497
+ }
1404
1498
  /**
1405
1499
  * Extract a property from the JSON-LD.
1406
1500
  * @param nodeObject The JSON-LD node object to extract from.
@@ -1424,7 +1518,7 @@ class JsonLdHelper {
1424
1518
  * @param context2 The second JSON-LD context to combine.
1425
1519
  * @returns The combined context.
1426
1520
  */
1427
- static async combineContexts(context1, context2) {
1521
+ static combineContexts(context1, context2) {
1428
1522
  const combinedContext = [];
1429
1523
  if (Is.string(context1)) {
1430
1524
  if (!combinedContext.includes(context1)) {
@@ -1472,77 +1566,31 @@ class JsonLdHelper {
1472
1566
  }
1473
1567
  return combinedContext;
1474
1568
  }
1475
- }
1476
-
1477
- // Copyright 2024 IOTA Stiftung.
1478
- // SPDX-License-Identifier: Apache-2.0.
1479
- /**
1480
- * JSON-LD Processor.
1481
- */
1482
- class JsonLdProcessor {
1483
1569
  /**
1484
- * The class name.
1485
- * @internal
1570
+ * Gather all the contexts from the element and it's children.
1571
+ * @param element The element to gather the contexts from.
1572
+ * @param initial The initial context.
1573
+ * @returns The combined contexts.
1486
1574
  */
1487
- static _CLASS_NAME = "JsonLdProcessor";
1488
- /**
1489
- * Redirects to use during document resolution.
1490
- */
1491
- static _redirects = [];
1492
- /**
1493
- * The document loader to use.
1494
- */
1495
- static DOCUMENT_LOADER = async (url) => JsonLdProcessor.documentLoader(url);
1496
- /**
1497
- * Compact a document according to a particular context.
1498
- * @param document The JSON-LD document to compact.
1499
- * @param context The context to compact the document to.
1500
- * @returns The compacted JSON-LD document.
1501
- */
1502
- static async compact(document, context) {
1503
- try {
1504
- const compacted = await jsonLd.compact(document, context ?? {}, {
1505
- documentLoader: JsonLdProcessor.DOCUMENT_LOADER
1506
- });
1507
- return compacted;
1575
+ static gatherContexts(element, initial) {
1576
+ let combinedContexts = initial;
1577
+ if (!Is.empty(element["@context"])) {
1578
+ combinedContexts = JsonLdProcessor.combineContexts(initial, element["@context"]);
1508
1579
  }
1509
- catch (err) {
1510
- if (Is.object(err) &&
1511
- err.name === "jsonld.InvalidUrl") {
1512
- throw new GeneralError(JsonLdProcessor._CLASS_NAME, "invalidUrl", { url: err.details?.url }, err);
1580
+ for (const prop of Object.keys(element)) {
1581
+ const value = element[prop];
1582
+ if (Is.object(value)) {
1583
+ combinedContexts = this.gatherContexts(value, combinedContexts);
1513
1584
  }
1514
- throw new GeneralError(JsonLdProcessor._CLASS_NAME, "compact", undefined, err);
1515
- }
1516
- }
1517
- /**
1518
- * Expand a document, removing its context.
1519
- * @param compacted The compacted JSON-LD document to expand.
1520
- * @returns The expanded JSON-LD document.
1521
- */
1522
- static async expand(compacted) {
1523
- try {
1524
- const expanded = await jsonLd.expand(compacted, {
1525
- documentLoader: JsonLdProcessor.DOCUMENT_LOADER
1526
- });
1527
- return expanded;
1528
- }
1529
- catch (err) {
1530
- if (Is.object(err) &&
1531
- err.name === "jsonld.InvalidUrl") {
1532
- throw new GeneralError(JsonLdProcessor._CLASS_NAME, "invalidUrl", { url: err.details?.url }, err);
1585
+ else if (Is.array(value)) {
1586
+ for (const item of value) {
1587
+ if (Is.object(item)) {
1588
+ combinedContexts = this.gatherContexts(item, combinedContexts);
1589
+ }
1590
+ }
1533
1591
  }
1534
- throw new GeneralError(JsonLdProcessor._CLASS_NAME, "expand", undefined, err);
1535
- }
1536
- }
1537
- /**
1538
- * Add a redirect to use during document resolution.
1539
- * @param from The URL to redirect from.
1540
- * @param to The URL to redirect to.
1541
- */
1542
- static addRedirect(from, to) {
1543
- if (!this._redirects.some(r => r.from === from)) {
1544
- this._redirects.push({ from, to });
1545
1592
  }
1593
+ return combinedContexts;
1546
1594
  }
1547
1595
  /**
1548
1596
  * Document loader which uses a caching mechanism.
@@ -2,6 +2,10 @@
2
2
  * The types of JSON-LD data.
3
3
  */
4
4
  export declare const JsonLdTypes: {
5
+ /**
6
+ * Context Root.
7
+ */
8
+ readonly ContextRoot: "https://schema.twindev.org/json-ld/";
5
9
  /**
6
10
  * Represents JSON-LD Document.
7
11
  */
@@ -1,6 +1,6 @@
1
1
  import { type IValidationFailure } from "@twin.org/core";
2
2
  import { type ValidationMode } from "@twin.org/data-core";
3
- import type { IJsonLdContextDefinitionRoot, IJsonLdDocument, IJsonLdNodeObject } from "../models/IJsonLdDocument";
3
+ import type { IJsonLdDocument } from "../models/IJsonLdDocument";
4
4
  /**
5
5
  * Class to help with JSON LD.
6
6
  */
@@ -13,19 +13,4 @@ export declare class JsonLdHelper {
13
13
  * @returns True if the document was valid.
14
14
  */
15
15
  static validate<T extends IJsonLdDocument = IJsonLdDocument>(document: T, validationFailures: IValidationFailure[], validationMode?: ValidationMode): Promise<boolean>;
16
- /**
17
- * Extract a property from the JSON-LD.
18
- * @param nodeObject The JSON-LD node object to extract from.
19
- * @param propertyNames The possible names for the property.
20
- * @param deleteProperty Delete the property from the object, defaults to true.
21
- * @returns The properties if available.
22
- */
23
- static extractProperty<T>(nodeObject: IJsonLdNodeObject, propertyNames: string[], deleteProperty?: boolean): T | undefined;
24
- /**
25
- * Combine contexts.
26
- * @param context1 The first JSON-LD context to combine.
27
- * @param context2 The second JSON-LD context to combine.
28
- * @returns The combined context.
29
- */
30
- static combineContexts(context1: IJsonLdContextDefinitionRoot | undefined, context2: IJsonLdContextDefinitionRoot | undefined): Promise<IJsonLdContextDefinitionRoot | undefined>;
31
16
  }
@@ -1,5 +1,5 @@
1
1
  import type { RemoteDocument, Url } from "jsonld/jsonld-spec";
2
- import type { IJsonLdContextDefinition, IJsonLdDocument } from "../models/IJsonLdDocument";
2
+ import type { IJsonLdContextDefinitionRoot, IJsonLdDocument, IJsonLdNodeObject } from "../models/IJsonLdDocument";
3
3
  /**
4
4
  * JSON-LD Processor.
5
5
  */
@@ -15,10 +15,10 @@ export declare class JsonLdProcessor {
15
15
  /**
16
16
  * Compact a document according to a particular context.
17
17
  * @param document The JSON-LD document to compact.
18
- * @param context The context to compact the document to.
18
+ * @param context The context to compact the document to, if not provided will try and gather from the object.
19
19
  * @returns The compacted JSON-LD document.
20
20
  */
21
- static compact(document: IJsonLdDocument, context?: IJsonLdContextDefinition): Promise<IJsonLdDocument>;
21
+ static compact(document: IJsonLdDocument, context?: IJsonLdContextDefinitionRoot): Promise<IJsonLdDocument>;
22
22
  /**
23
23
  * Expand a document, removing its context.
24
24
  * @param compacted The compacted JSON-LD document to expand.
@@ -31,4 +31,28 @@ export declare class JsonLdProcessor {
31
31
  * @param to The URL to redirect to.
32
32
  */
33
33
  static addRedirect(from: RegExp, to: string): void;
34
+ /**
35
+ * Extract a property from the JSON-LD.
36
+ * @param nodeObject The JSON-LD node object to extract from.
37
+ * @param propertyNames The possible names for the property.
38
+ * @param deleteProperty Delete the property from the object, defaults to true.
39
+ * @returns The properties if available.
40
+ */
41
+ static extractProperty<T>(nodeObject: IJsonLdNodeObject, propertyNames: string[], deleteProperty?: boolean): T | undefined;
42
+ /**
43
+ * Combine contexts.
44
+ * @param context1 The first JSON-LD context to combine.
45
+ * @param context2 The second JSON-LD context to combine.
46
+ * @returns The combined context.
47
+ */
48
+ static combineContexts(context1: IJsonLdContextDefinitionRoot | undefined, context2: IJsonLdContextDefinitionRoot | undefined): IJsonLdContextDefinitionRoot | undefined;
49
+ /**
50
+ * Gather all the contexts from the element and it's children.
51
+ * @param element The element to gather the contexts from.
52
+ * @param initial The initial context.
53
+ * @returns The combined contexts.
54
+ */
55
+ static gatherContexts(element: {
56
+ [id: string]: unknown;
57
+ }, initial?: IJsonLdContextDefinitionRoot): IJsonLdContextDefinitionRoot | undefined;
34
58
  }
package/docs/changelog.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # @twin.org/data-json-ld - Changelog
2
2
 
3
- ## v0.0.1-next.4
3
+ ## v0.0.1-next.6
4
4
 
5
5
  - Initial Release
@@ -43,59 +43,3 @@ The validation mode to use, defaults to either.
43
43
  `Promise`\<`boolean`\>
44
44
 
45
45
  True if the document was valid.
46
-
47
- ***
48
-
49
- ### extractProperty()
50
-
51
- > `static` **extractProperty**\<`T`\>(`nodeObject`, `propertyNames`, `deleteProperty`): `undefined` \| `T`
52
-
53
- Extract a property from the JSON-LD.
54
-
55
- #### Type Parameters
56
-
57
- • **T**
58
-
59
- #### Parameters
60
-
61
- • **nodeObject**: [`IJsonLdNodeObject`](../interfaces/IJsonLdNodeObject.md)
62
-
63
- The JSON-LD node object to extract from.
64
-
65
- • **propertyNames**: `string`[]
66
-
67
- The possible names for the property.
68
-
69
- • **deleteProperty**: `boolean` = `true`
70
-
71
- Delete the property from the object, defaults to true.
72
-
73
- #### Returns
74
-
75
- `undefined` \| `T`
76
-
77
- The properties if available.
78
-
79
- ***
80
-
81
- ### combineContexts()
82
-
83
- > `static` **combineContexts**(`context1`, `context2`): `Promise`\<`undefined` \| [`IJsonLdContextDefinitionRoot`](../type-aliases/IJsonLdContextDefinitionRoot.md)\>
84
-
85
- Combine contexts.
86
-
87
- #### Parameters
88
-
89
- • **context1**: `undefined` \| [`IJsonLdContextDefinitionRoot`](../type-aliases/IJsonLdContextDefinitionRoot.md)
90
-
91
- The first JSON-LD context to combine.
92
-
93
- • **context2**: `undefined` \| [`IJsonLdContextDefinitionRoot`](../type-aliases/IJsonLdContextDefinitionRoot.md)
94
-
95
- The second JSON-LD context to combine.
96
-
97
- #### Returns
98
-
99
- `Promise`\<`undefined` \| [`IJsonLdContextDefinitionRoot`](../type-aliases/IJsonLdContextDefinitionRoot.md)\>
100
-
101
- The combined context.
@@ -42,9 +42,9 @@ Compact a document according to a particular context.
42
42
 
43
43
  The JSON-LD document to compact.
44
44
 
45
- • **context?**: [`IJsonLdContextDefinition`](../interfaces/IJsonLdContextDefinition.md)
45
+ • **context?**: [`IJsonLdContextDefinitionRoot`](../type-aliases/IJsonLdContextDefinitionRoot.md)
46
46
 
47
- The context to compact the document to.
47
+ The context to compact the document to, if not provided will try and gather from the object.
48
48
 
49
49
  #### Returns
50
50
 
@@ -93,3 +93,83 @@ The URL to redirect to.
93
93
  #### Returns
94
94
 
95
95
  `void`
96
+
97
+ ***
98
+
99
+ ### extractProperty()
100
+
101
+ > `static` **extractProperty**\<`T`\>(`nodeObject`, `propertyNames`, `deleteProperty`): `undefined` \| `T`
102
+
103
+ Extract a property from the JSON-LD.
104
+
105
+ #### Type Parameters
106
+
107
+ • **T**
108
+
109
+ #### Parameters
110
+
111
+ • **nodeObject**: [`IJsonLdNodeObject`](../interfaces/IJsonLdNodeObject.md)
112
+
113
+ The JSON-LD node object to extract from.
114
+
115
+ • **propertyNames**: `string`[]
116
+
117
+ The possible names for the property.
118
+
119
+ • **deleteProperty**: `boolean` = `true`
120
+
121
+ Delete the property from the object, defaults to true.
122
+
123
+ #### Returns
124
+
125
+ `undefined` \| `T`
126
+
127
+ The properties if available.
128
+
129
+ ***
130
+
131
+ ### combineContexts()
132
+
133
+ > `static` **combineContexts**(`context1`, `context2`): `undefined` \| [`IJsonLdContextDefinitionRoot`](../type-aliases/IJsonLdContextDefinitionRoot.md)
134
+
135
+ Combine contexts.
136
+
137
+ #### Parameters
138
+
139
+ • **context1**: `undefined` \| [`IJsonLdContextDefinitionRoot`](../type-aliases/IJsonLdContextDefinitionRoot.md)
140
+
141
+ The first JSON-LD context to combine.
142
+
143
+ • **context2**: `undefined` \| [`IJsonLdContextDefinitionRoot`](../type-aliases/IJsonLdContextDefinitionRoot.md)
144
+
145
+ The second JSON-LD context to combine.
146
+
147
+ #### Returns
148
+
149
+ `undefined` \| [`IJsonLdContextDefinitionRoot`](../type-aliases/IJsonLdContextDefinitionRoot.md)
150
+
151
+ The combined context.
152
+
153
+ ***
154
+
155
+ ### gatherContexts()
156
+
157
+ > `static` **gatherContexts**(`element`, `initial`?): `undefined` \| [`IJsonLdContextDefinitionRoot`](../type-aliases/IJsonLdContextDefinitionRoot.md)
158
+
159
+ Gather all the contexts from the element and it's children.
160
+
161
+ #### Parameters
162
+
163
+ • **element**
164
+
165
+ The element to gather the contexts from.
166
+
167
+ • **initial?**: [`IJsonLdContextDefinitionRoot`](../type-aliases/IJsonLdContextDefinitionRoot.md)
168
+
169
+ The initial context.
170
+
171
+ #### Returns
172
+
173
+ `undefined` \| [`IJsonLdContextDefinitionRoot`](../type-aliases/IJsonLdContextDefinitionRoot.md)
174
+
175
+ The combined contexts.
@@ -6,6 +6,12 @@ The types of JSON-LD data.
6
6
 
7
7
  ## Type declaration
8
8
 
9
+ ### ContextRoot
10
+
11
+ > `readonly` **ContextRoot**: `"https://schema.twindev.org/json-ld/"` = `"https://schema.twindev.org/json-ld/"`
12
+
13
+ Context Root.
14
+
9
15
  ### Document
10
16
 
11
17
  > `readonly` **Document**: `"https://schema.twindev.org/json-ld/JsonLdDocument"` = `"https://schema.twindev.org/json-ld/JsonLdDocument"`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/data-json-ld",
3
- "version": "0.0.1-next.4",
3
+ "version": "0.0.1-next.6",
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.4",
18
+ "@twin.org/data-core": "0.0.1-next.6",
19
19
  "@twin.org/entity": "next",
20
20
  "@twin.org/nameof": "next",
21
21
  "@twin.org/web": "next",