@twin.org/data-json-ld 0.0.1-next.5 → 0.0.1-next.7
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 +43 -0
- package/dist/esm/index.mjs +43 -0
- package/dist/types/models/jsonLdTypes.d.ts +4 -0
- package/dist/types/utils/jsonLdProcessor.d.ts +8 -1
- package/docs/changelog.md +1 -1
- package/docs/reference/classes/JsonLdProcessor.md +24 -0
- package/docs/reference/variables/JsonLdTypes.md +6 -0
- package/package.json +2 -2
package/dist/cjs/index.cjs
CHANGED
|
@@ -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
|
*/
|
|
@@ -1590,6 +1594,45 @@ class JsonLdProcessor {
|
|
|
1590
1594
|
}
|
|
1591
1595
|
return combinedContexts;
|
|
1592
1596
|
}
|
|
1597
|
+
/**
|
|
1598
|
+
* Remove all the contexts that match the pattern.
|
|
1599
|
+
* @param context The context to remove the entries from.
|
|
1600
|
+
* @param match The element to try and match.
|
|
1601
|
+
* @returns The updated contexts.
|
|
1602
|
+
*/
|
|
1603
|
+
static removeContexts(context, match) {
|
|
1604
|
+
if (!core.Is.arrayValue(match)) {
|
|
1605
|
+
return context;
|
|
1606
|
+
}
|
|
1607
|
+
let finalContext;
|
|
1608
|
+
if (core.Is.string(context)) {
|
|
1609
|
+
for (const m of match) {
|
|
1610
|
+
if (context === m) {
|
|
1611
|
+
break;
|
|
1612
|
+
}
|
|
1613
|
+
}
|
|
1614
|
+
}
|
|
1615
|
+
else if (core.Is.array(context)) {
|
|
1616
|
+
for (const item of context) {
|
|
1617
|
+
const hasMatch = match.some(m => core.ObjectHelper.equal(m, item));
|
|
1618
|
+
if (!hasMatch) {
|
|
1619
|
+
finalContext ??= [];
|
|
1620
|
+
if (core.Is.array(finalContext)) {
|
|
1621
|
+
finalContext.push(item);
|
|
1622
|
+
}
|
|
1623
|
+
}
|
|
1624
|
+
}
|
|
1625
|
+
}
|
|
1626
|
+
else if (core.Is.object(context)) {
|
|
1627
|
+
const hasMatch = match.some(m => core.ObjectHelper.equal(m, context));
|
|
1628
|
+
if (!hasMatch) {
|
|
1629
|
+
finalContext = context;
|
|
1630
|
+
}
|
|
1631
|
+
}
|
|
1632
|
+
return core.Is.arrayValue(finalContext) && finalContext.length === 1
|
|
1633
|
+
? finalContext[0]
|
|
1634
|
+
: finalContext;
|
|
1635
|
+
}
|
|
1593
1636
|
/**
|
|
1594
1637
|
* Document loader which uses a caching mechanism.
|
|
1595
1638
|
* @param url The document url to load.
|
package/dist/esm/index.mjs
CHANGED
|
@@ -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
|
*/
|
|
@@ -1588,6 +1592,45 @@ class JsonLdProcessor {
|
|
|
1588
1592
|
}
|
|
1589
1593
|
return combinedContexts;
|
|
1590
1594
|
}
|
|
1595
|
+
/**
|
|
1596
|
+
* Remove all the contexts that match the pattern.
|
|
1597
|
+
* @param context The context to remove the entries from.
|
|
1598
|
+
* @param match The element to try and match.
|
|
1599
|
+
* @returns The updated contexts.
|
|
1600
|
+
*/
|
|
1601
|
+
static removeContexts(context, match) {
|
|
1602
|
+
if (!Is.arrayValue(match)) {
|
|
1603
|
+
return context;
|
|
1604
|
+
}
|
|
1605
|
+
let finalContext;
|
|
1606
|
+
if (Is.string(context)) {
|
|
1607
|
+
for (const m of match) {
|
|
1608
|
+
if (context === m) {
|
|
1609
|
+
break;
|
|
1610
|
+
}
|
|
1611
|
+
}
|
|
1612
|
+
}
|
|
1613
|
+
else if (Is.array(context)) {
|
|
1614
|
+
for (const item of context) {
|
|
1615
|
+
const hasMatch = match.some(m => ObjectHelper.equal(m, item));
|
|
1616
|
+
if (!hasMatch) {
|
|
1617
|
+
finalContext ??= [];
|
|
1618
|
+
if (Is.array(finalContext)) {
|
|
1619
|
+
finalContext.push(item);
|
|
1620
|
+
}
|
|
1621
|
+
}
|
|
1622
|
+
}
|
|
1623
|
+
}
|
|
1624
|
+
else if (Is.object(context)) {
|
|
1625
|
+
const hasMatch = match.some(m => ObjectHelper.equal(m, context));
|
|
1626
|
+
if (!hasMatch) {
|
|
1627
|
+
finalContext = context;
|
|
1628
|
+
}
|
|
1629
|
+
}
|
|
1630
|
+
return Is.arrayValue(finalContext) && finalContext.length === 1
|
|
1631
|
+
? finalContext[0]
|
|
1632
|
+
: finalContext;
|
|
1633
|
+
}
|
|
1591
1634
|
/**
|
|
1592
1635
|
* Document loader which uses a caching mechanism.
|
|
1593
1636
|
* @param url The document url to load.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { RemoteDocument, Url } from "jsonld/jsonld-spec";
|
|
2
|
-
import type { IJsonLdContextDefinitionRoot, IJsonLdDocument, IJsonLdNodeObject } from "../models/IJsonLdDocument";
|
|
2
|
+
import type { IJsonLdContextDefinitionElement, IJsonLdContextDefinitionRoot, IJsonLdDocument, IJsonLdNodeObject } from "../models/IJsonLdDocument";
|
|
3
3
|
/**
|
|
4
4
|
* JSON-LD Processor.
|
|
5
5
|
*/
|
|
@@ -55,4 +55,11 @@ export declare class JsonLdProcessor {
|
|
|
55
55
|
static gatherContexts(element: {
|
|
56
56
|
[id: string]: unknown;
|
|
57
57
|
}, initial?: IJsonLdContextDefinitionRoot): IJsonLdContextDefinitionRoot | undefined;
|
|
58
|
+
/**
|
|
59
|
+
* Remove all the contexts that match the pattern.
|
|
60
|
+
* @param context The context to remove the entries from.
|
|
61
|
+
* @param match The element to try and match.
|
|
62
|
+
* @returns The updated contexts.
|
|
63
|
+
*/
|
|
64
|
+
static removeContexts(context: IJsonLdContextDefinitionRoot | undefined, match?: IJsonLdContextDefinitionElement[]): IJsonLdContextDefinitionRoot | undefined;
|
|
58
65
|
}
|
package/docs/changelog.md
CHANGED
|
@@ -173,3 +173,27 @@ The initial context.
|
|
|
173
173
|
`undefined` \| [`IJsonLdContextDefinitionRoot`](../type-aliases/IJsonLdContextDefinitionRoot.md)
|
|
174
174
|
|
|
175
175
|
The combined contexts.
|
|
176
|
+
|
|
177
|
+
***
|
|
178
|
+
|
|
179
|
+
### removeContexts()
|
|
180
|
+
|
|
181
|
+
> `static` **removeContexts**(`context`, `match`?): `undefined` \| [`IJsonLdContextDefinitionRoot`](../type-aliases/IJsonLdContextDefinitionRoot.md)
|
|
182
|
+
|
|
183
|
+
Remove all the contexts that match the pattern.
|
|
184
|
+
|
|
185
|
+
#### Parameters
|
|
186
|
+
|
|
187
|
+
• **context**: `undefined` \| [`IJsonLdContextDefinitionRoot`](../type-aliases/IJsonLdContextDefinitionRoot.md)
|
|
188
|
+
|
|
189
|
+
The context to remove the entries from.
|
|
190
|
+
|
|
191
|
+
• **match?**: [`IJsonLdContextDefinitionElement`](../type-aliases/IJsonLdContextDefinitionElement.md)[]
|
|
192
|
+
|
|
193
|
+
The element to try and match.
|
|
194
|
+
|
|
195
|
+
#### Returns
|
|
196
|
+
|
|
197
|
+
`undefined` \| [`IJsonLdContextDefinitionRoot`](../type-aliases/IJsonLdContextDefinitionRoot.md)
|
|
198
|
+
|
|
199
|
+
The updated 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.
|
|
3
|
+
"version": "0.0.1-next.7",
|
|
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.7",
|
|
19
19
|
"@twin.org/entity": "next",
|
|
20
20
|
"@twin.org/nameof": "next",
|
|
21
21
|
"@twin.org/web": "next",
|