@ldo/jsonld-dataset-proxy 1.0.0-alpha.38 → 1.0.0-alpha.44
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/README.md +134 -128
- package/dist/ContextUtil.cjs +1 -6
- package/dist/ContextUtil.d.cts +0 -2
- package/dist/ContextUtil.d.cts.map +1 -1
- package/dist/{ContextUtil.d.ts → ContextUtil.d.mts} +3 -5
- package/dist/ContextUtil.d.mts.map +1 -0
- package/dist/{ContextUtil.js → ContextUtil.mjs} +2 -5
- package/dist/ContextUtil.mjs.map +1 -0
- package/dist/JsonldDatasetProxyBuilder.cjs +3 -7
- package/dist/JsonldDatasetProxyBuilder.d.cts +0 -2
- package/dist/JsonldDatasetProxyBuilder.d.cts.map +1 -1
- package/dist/{JsonldDatasetProxyBuilder.d.ts → JsonldDatasetProxyBuilder.d.mts} +6 -8
- package/dist/JsonldDatasetProxyBuilder.d.mts.map +1 -0
- package/dist/{JsonldDatasetProxyBuilder.js → JsonldDatasetProxyBuilder.mjs} +2 -4
- package/dist/JsonldDatasetProxyBuilder.mjs.map +1 -0
- package/dist/LdoJsonldContext.d.cts +0 -2
- package/dist/LdoJsonldContext.d.cts.map +1 -1
- package/dist/{LdoJsonldContext.d.ts → LdoJsonldContext.d.mts} +1 -3
- package/dist/LdoJsonldContext.d.mts.map +1 -0
- package/dist/ProxyContext.cjs +10 -20
- package/dist/ProxyContext.d.cts +0 -2
- package/dist/ProxyContext.d.cts.map +1 -1
- package/dist/{ProxyContext.d.ts → ProxyContext.d.mts} +6 -8
- package/dist/ProxyContext.d.mts.map +1 -0
- package/dist/{ProxyContext.js → ProxyContext.mjs} +9 -16
- package/dist/ProxyContext.mjs.map +1 -0
- package/dist/graphOf.cjs +11 -18
- package/dist/graphOf.d.cts +0 -3
- package/dist/graphOf.d.cts.map +1 -1
- package/dist/{graphOf.d.ts → graphOf.d.mts} +4 -7
- package/dist/graphOf.d.mts.map +1 -0
- package/dist/{graphOf.js → graphOf.mjs} +7 -12
- package/dist/graphOf.mjs.map +1 -0
- package/dist/index.cjs +78 -76
- package/dist/index.d.mts +32 -0
- package/dist/{index.js → index.mjs} +29 -29
- package/dist/index.mjs.map +1 -0
- package/dist/jsonldDatasetProxy.cjs +9 -14
- package/dist/jsonldDatasetProxy.d.cts +0 -3
- package/dist/jsonldDatasetProxy.d.cts.map +1 -1
- package/dist/{jsonldDatasetProxy.d.ts → jsonldDatasetProxy.d.mts} +4 -7
- package/dist/jsonldDatasetProxy.d.mts.map +1 -0
- package/dist/{jsonldDatasetProxy.js → jsonldDatasetProxy.mjs} +8 -11
- package/dist/jsonldDatasetProxy.mjs.map +1 -0
- package/dist/language/languageMapProxy.cjs +23 -27
- package/dist/language/languageMapProxy.d.cts +0 -2
- package/dist/language/languageMapProxy.d.cts.map +1 -1
- package/dist/language/{languageMapProxy.d.ts → languageMapProxy.d.mts} +4 -6
- package/dist/language/languageMapProxy.d.mts.map +1 -0
- package/dist/language/{languageMapProxy.js → languageMapProxy.mjs} +18 -20
- package/dist/language/languageMapProxy.mjs.map +1 -0
- package/dist/language/languageSet.cjs +13 -17
- package/dist/language/languageSet.d.mts +1 -0
- package/dist/language/{languageSet.js → languageSet.mjs} +10 -12
- package/dist/language/languageSet.mjs.map +1 -0
- package/dist/language/languageTypes.d.cts +0 -2
- package/dist/language/languageTypes.d.cts.map +1 -1
- package/dist/language/{languageTypes.d.ts → languageTypes.d.mts} +1 -3
- package/dist/language/languageTypes.d.mts.map +1 -0
- package/dist/language/languageUtils.cjs +5 -9
- package/dist/language/languageUtils.d.cts +0 -3
- package/dist/language/languageUtils.d.cts.map +1 -1
- package/dist/language/{languageUtils.d.ts → languageUtils.d.mts} +3 -6
- package/dist/language/languageUtils.d.mts.map +1 -0
- package/dist/language/{languageUtils.js → languageUtils.mjs} +3 -5
- package/dist/language/languageUtils.mjs.map +1 -0
- package/dist/language/languagesOf.cjs +9 -13
- package/dist/language/languagesOf.d.cts +0 -3
- package/dist/language/languagesOf.d.cts.map +1 -1
- package/dist/language/{languagesOf.d.ts → languagesOf.d.mts} +4 -7
- package/dist/language/languagesOf.d.mts.map +1 -0
- package/dist/language/{languagesOf.js → languagesOf.mjs} +6 -8
- package/dist/language/languagesOf.mjs.map +1 -0
- package/dist/setLanguagePreferences.cjs +3 -5
- package/dist/setLanguagePreferences.d.cts +0 -3
- package/dist/setLanguagePreferences.d.cts.map +1 -1
- package/dist/setLanguagePreferences.d.mts +13 -0
- package/dist/setLanguagePreferences.d.mts.map +1 -0
- package/dist/{setLanguagePreferences.js → setLanguagePreferences.mjs} +3 -4
- package/dist/setLanguagePreferences.mjs.map +1 -0
- package/dist/setProxy/ObjectSetProxy.cjs +5 -8
- package/dist/setProxy/{ObjectSetProxy.js → ObjectSetProxy.mjs} +4 -6
- package/dist/setProxy/ObjectSetProxy.mjs.map +1 -0
- package/dist/setProxy/SetProxy.cjs +13 -20
- package/dist/setProxy/SetProxy.d.cts +0 -3
- package/dist/setProxy/SetProxy.d.cts.map +1 -1
- package/dist/setProxy/{SetProxy.d.ts → SetProxy.d.mts} +6 -9
- package/dist/setProxy/SetProxy.d.mts.map +1 -0
- package/dist/setProxy/{SetProxy.js → SetProxy.mjs} +8 -14
- package/dist/setProxy/SetProxy.mjs.map +1 -0
- package/dist/setProxy/SubjectSetProxy.cjs +15 -21
- package/dist/setProxy/{SubjectSetProxy.js → SubjectSetProxy.mjs} +9 -13
- package/dist/setProxy/SubjectSetProxy.mjs.map +1 -0
- package/dist/setProxy/WildcardObjectSetProxy.cjs +9 -13
- package/dist/setProxy/{WildcardObjectSetProxy.js → WildcardObjectSetProxy.mjs} +6 -9
- package/dist/setProxy/{WildcardObjectSetProxy.js.map → WildcardObjectSetProxy.mjs.map} +1 -1
- package/dist/setProxy/WildcardSubjectSetProxy.cjs +7 -10
- package/dist/setProxy/{WildcardSubjectSetProxy.js → WildcardSubjectSetProxy.mjs} +5 -7
- package/dist/setProxy/WildcardSubjectSetProxy.mjs.map +1 -0
- package/dist/setProxy/createNewSetProxy.cjs +9 -11
- package/dist/setProxy/createNewSetProxy.d.cts +0 -2
- package/dist/setProxy/createNewSetProxy.d.cts.map +1 -1
- package/dist/setProxy/createNewSetProxy.d.mts +10 -0
- package/dist/setProxy/createNewSetProxy.d.mts.map +1 -0
- package/dist/setProxy/{createNewSetProxy.js → createNewSetProxy.mjs} +6 -7
- package/dist/setProxy/createNewSetProxy.mjs.map +1 -0
- package/dist/setProxy/isSetProxy.cjs +3 -5
- package/dist/setProxy/isSetProxy.d.cts +0 -2
- package/dist/setProxy/isSetProxy.d.cts.map +1 -1
- package/dist/setProxy/isSetProxy.d.mts +7 -0
- package/dist/setProxy/isSetProxy.d.mts.map +1 -0
- package/dist/setProxy/{isSetProxy.js → isSetProxy.mjs} +3 -4
- package/dist/setProxy/isSetProxy.mjs.map +1 -0
- package/dist/setProxy/ldSet/BasicLdSet.cjs +6 -10
- package/dist/setProxy/ldSet/BasicLdSet.d.cts +0 -2
- package/dist/setProxy/ldSet/BasicLdSet.d.cts.map +1 -1
- package/dist/setProxy/ldSet/{BasicLdSet.d.ts → BasicLdSet.d.mts} +4 -6
- package/dist/setProxy/ldSet/BasicLdSet.d.mts.map +1 -0
- package/dist/setProxy/ldSet/{BasicLdSet.js → BasicLdSet.mjs} +4 -6
- package/dist/setProxy/ldSet/BasicLdSet.mjs.map +1 -0
- package/dist/setProxy/ldSet/LdSet.d.cts +0 -1
- package/dist/setProxy/ldSet/LdSet.d.cts.map +1 -1
- package/dist/setProxy/ldSet/{LdSet.d.ts → LdSet.d.mts} +1 -2
- package/dist/setProxy/ldSet/LdSet.d.mts.map +1 -0
- package/dist/setProxy/set.cjs +3 -5
- package/dist/setProxy/set.d.cts +0 -3
- package/dist/setProxy/set.d.cts.map +1 -1
- package/dist/setProxy/{set.d.ts → set.d.mts} +3 -6
- package/dist/setProxy/set.d.mts.map +1 -0
- package/dist/setProxy/{set.js → set.mjs} +3 -4
- package/dist/setProxy/set.mjs.map +1 -0
- package/dist/subjectProxy/SubjectProxy.d.cts +0 -1
- package/dist/subjectProxy/SubjectProxy.d.cts.map +1 -1
- package/dist/subjectProxy/{SubjectProxy.d.ts → SubjectProxy.d.mts} +1 -2
- package/dist/subjectProxy/SubjectProxy.d.mts.map +1 -0
- package/dist/subjectProxy/createSubjectHandler.cjs +20 -23
- package/dist/subjectProxy/createSubjectHandler.d.cts +0 -2
- package/dist/subjectProxy/createSubjectHandler.d.cts.map +1 -1
- package/dist/subjectProxy/{createSubjectHandler.d.ts → createSubjectHandler.d.mts} +3 -5
- package/dist/subjectProxy/createSubjectHandler.d.mts.map +1 -0
- package/dist/subjectProxy/{createSubjectHandler.js → createSubjectHandler.mjs} +8 -9
- package/dist/subjectProxy/createSubjectHandler.mjs.map +1 -0
- package/dist/subjectProxy/deleteFromDataset.cjs +3 -5
- package/dist/subjectProxy/deleteFromDataset.d.cts +0 -2
- package/dist/subjectProxy/deleteFromDataset.d.cts.map +1 -1
- package/dist/subjectProxy/deleteFromDataset.d.mts +8 -0
- package/dist/subjectProxy/deleteFromDataset.d.mts.map +1 -0
- package/dist/subjectProxy/{deleteFromDataset.js → deleteFromDataset.mjs} +3 -4
- package/dist/subjectProxy/deleteFromDataset.mjs.map +1 -0
- package/dist/subjectProxy/getValueForKey.cjs +15 -24
- package/dist/subjectProxy/getValueForKey.d.cts +0 -3
- package/dist/subjectProxy/getValueForKey.d.cts.map +1 -1
- package/dist/subjectProxy/getValueForKey.d.mts +13 -0
- package/dist/subjectProxy/getValueForKey.d.mts.map +1 -0
- package/dist/subjectProxy/{getValueForKey.js → getValueForKey.mjs} +13 -20
- package/dist/subjectProxy/getValueForKey.mjs.map +1 -0
- package/dist/subjectProxy/isSubjectProxy.cjs +3 -5
- package/dist/subjectProxy/isSubjectProxy.d.cts +0 -2
- package/dist/subjectProxy/isSubjectProxy.d.cts.map +1 -1
- package/dist/subjectProxy/isSubjectProxy.d.mts +9 -0
- package/dist/subjectProxy/isSubjectProxy.d.mts.map +1 -0
- package/dist/subjectProxy/{isSubjectProxy.js → isSubjectProxy.mjs} +3 -4
- package/dist/subjectProxy/isSubjectProxy.mjs.map +1 -0
- package/dist/types.cjs +1 -3
- package/dist/types.d.cts +0 -2
- package/dist/types.d.cts.map +1 -1
- package/dist/{types.d.ts → types.d.mts} +2 -4
- package/dist/types.d.mts.map +1 -0
- package/dist/{types.js → types.mjs} +2 -2
- package/dist/types.mjs.map +1 -0
- package/dist/util/NodeSet.cjs +5 -5
- package/dist/util/NodeSet.d.cts +0 -2
- package/dist/util/NodeSet.d.cts.map +1 -1
- package/dist/util/{NodeSet.d.ts → NodeSet.d.mts} +2 -4
- package/dist/util/NodeSet.d.mts.map +1 -0
- package/dist/util/{NodeSet.js → NodeSet.mjs} +6 -4
- package/dist/util/NodeSet.mjs.map +1 -0
- package/dist/util/RawObject.d.cts +0 -2
- package/dist/util/RawObject.d.cts.map +1 -1
- package/dist/util/{RawObject.d.ts → RawObject.d.mts} +3 -5
- package/dist/util/RawObject.d.mts.map +1 -0
- package/dist/util/addObjectToDataset.cjs +23 -29
- package/dist/util/addObjectToDataset.d.cts +0 -2
- package/dist/util/addObjectToDataset.d.cts.map +1 -1
- package/dist/util/{addObjectToDataset.d.ts → addObjectToDataset.d.mts} +6 -8
- package/dist/util/addObjectToDataset.d.mts.map +1 -0
- package/dist/util/{addObjectToDataset.js → addObjectToDataset.mjs} +11 -15
- package/dist/util/addObjectToDataset.mjs.map +1 -0
- package/dist/util/createInteractOptions.cjs +10 -13
- package/dist/util/createInteractOptions.d.cts +0 -1
- package/dist/util/createInteractOptions.d.cts.map +1 -1
- package/dist/util/{createInteractOptions.d.ts → createInteractOptions.d.mts} +3 -4
- package/dist/util/createInteractOptions.d.mts.map +1 -0
- package/dist/util/{createInteractOptions.js → createInteractOptions.mjs} +6 -8
- package/dist/util/createInteractOptions.mjs.map +1 -0
- package/dist/util/getNodeFromRaw.cjs +10 -13
- package/dist/util/getNodeFromRaw.d.cts +0 -2
- package/dist/util/getNodeFromRaw.d.cts.map +1 -1
- package/dist/util/getNodeFromRaw.d.mts +11 -0
- package/dist/util/getNodeFromRaw.d.mts.map +1 -0
- package/dist/util/{getNodeFromRaw.js → getNodeFromRaw.mjs} +5 -6
- package/dist/util/getNodeFromRaw.mjs.map +1 -0
- package/dist/util/isProxy.cjs +4 -6
- package/dist/util/isProxy.d.cts +0 -2
- package/dist/util/isProxy.d.cts.map +1 -1
- package/dist/util/isProxy.d.mts +11 -0
- package/dist/util/isProxy.d.mts.map +1 -0
- package/dist/util/{isProxy.js → isProxy.mjs} +4 -5
- package/dist/util/isProxy.mjs.map +1 -0
- package/dist/util/nodeToJsonldRepresentation.cjs +1 -3
- package/dist/util/nodeToJsonldRepresentation.d.cts +0 -2
- package/dist/util/nodeToJsonldRepresentation.d.cts.map +1 -1
- package/dist/util/{nodeToJsonldRepresentation.d.ts → nodeToJsonldRepresentation.d.mts} +5 -7
- package/dist/util/nodeToJsonldRepresentation.d.mts.map +1 -0
- package/dist/util/{nodeToJsonldRepresentation.js → nodeToJsonldRepresentation.mjs} +2 -2
- package/dist/util/nodeToJsonldRepresentation.mjs.map +1 -0
- package/dist/write.cjs +3 -5
- package/dist/write.d.cts +0 -3
- package/dist/write.d.cts.map +1 -1
- package/dist/{write.d.ts → write.d.mts} +3 -6
- package/dist/write.d.mts.map +1 -0
- package/dist/{write.js → write.mjs} +3 -4
- package/dist/write.mjs.map +1 -0
- package/package.json +11 -10
- package/dist/ContextUtil.d.ts.map +0 -1
- package/dist/ContextUtil.js.map +0 -1
- package/dist/JsonldDatasetProxyBuilder.d.ts.map +0 -1
- package/dist/JsonldDatasetProxyBuilder.js.map +0 -1
- package/dist/LdoJsonldContext.d.ts.map +0 -1
- package/dist/ProxyContext.d.ts.map +0 -1
- package/dist/ProxyContext.js.map +0 -1
- package/dist/_virtual/rolldown_runtime.cjs +0 -30
- package/dist/graphOf.d.ts.map +0 -1
- package/dist/graphOf.js.map +0 -1
- package/dist/index.d.ts +0 -32
- package/dist/index.js.map +0 -1
- package/dist/jsonldDatasetProxy.d.ts.map +0 -1
- package/dist/jsonldDatasetProxy.js.map +0 -1
- package/dist/language/languageMapProxy.d.ts.map +0 -1
- package/dist/language/languageMapProxy.js.map +0 -1
- package/dist/language/languageSet.js.map +0 -1
- package/dist/language/languageTypes.d.ts.map +0 -1
- package/dist/language/languageUtils.d.ts.map +0 -1
- package/dist/language/languageUtils.js.map +0 -1
- package/dist/language/languagesOf.d.ts.map +0 -1
- package/dist/language/languagesOf.js.map +0 -1
- package/dist/setLanguagePreferences.d.ts +0 -16
- package/dist/setLanguagePreferences.d.ts.map +0 -1
- package/dist/setLanguagePreferences.js.map +0 -1
- package/dist/setProxy/ObjectSetProxy.js.map +0 -1
- package/dist/setProxy/SetProxy.d.ts.map +0 -1
- package/dist/setProxy/SetProxy.js.map +0 -1
- package/dist/setProxy/SubjectSetProxy.js.map +0 -1
- package/dist/setProxy/WildcardSubjectSetProxy.js.map +0 -1
- package/dist/setProxy/createNewSetProxy.d.ts +0 -12
- package/dist/setProxy/createNewSetProxy.d.ts.map +0 -1
- package/dist/setProxy/createNewSetProxy.js.map +0 -1
- package/dist/setProxy/isSetProxy.d.ts +0 -9
- package/dist/setProxy/isSetProxy.d.ts.map +0 -1
- package/dist/setProxy/isSetProxy.js.map +0 -1
- package/dist/setProxy/ldSet/BasicLdSet.d.ts.map +0 -1
- package/dist/setProxy/ldSet/BasicLdSet.js.map +0 -1
- package/dist/setProxy/ldSet/LdSet.d.ts.map +0 -1
- package/dist/setProxy/set.d.ts.map +0 -1
- package/dist/setProxy/set.js.map +0 -1
- package/dist/subjectProxy/SubjectProxy.d.ts.map +0 -1
- package/dist/subjectProxy/createSubjectHandler.d.ts.map +0 -1
- package/dist/subjectProxy/createSubjectHandler.js.map +0 -1
- package/dist/subjectProxy/deleteFromDataset.d.ts +0 -10
- package/dist/subjectProxy/deleteFromDataset.d.ts.map +0 -1
- package/dist/subjectProxy/deleteFromDataset.js.map +0 -1
- package/dist/subjectProxy/getValueForKey.d.ts +0 -16
- package/dist/subjectProxy/getValueForKey.d.ts.map +0 -1
- package/dist/subjectProxy/getValueForKey.js.map +0 -1
- package/dist/subjectProxy/isSubjectProxy.d.ts +0 -11
- package/dist/subjectProxy/isSubjectProxy.d.ts.map +0 -1
- package/dist/subjectProxy/isSubjectProxy.js.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js.map +0 -1
- package/dist/util/NodeSet.d.ts.map +0 -1
- package/dist/util/NodeSet.js.map +0 -1
- package/dist/util/RawObject.d.ts.map +0 -1
- package/dist/util/addObjectToDataset.d.ts.map +0 -1
- package/dist/util/addObjectToDataset.js.map +0 -1
- package/dist/util/createInteractOptions.d.ts.map +0 -1
- package/dist/util/createInteractOptions.js.map +0 -1
- package/dist/util/getNodeFromRaw.d.ts +0 -13
- package/dist/util/getNodeFromRaw.d.ts.map +0 -1
- package/dist/util/getNodeFromRaw.js.map +0 -1
- package/dist/util/isProxy.d.ts +0 -13
- package/dist/util/isProxy.d.ts.map +0 -1
- package/dist/util/isProxy.js.map +0 -1
- package/dist/util/nodeToJsonldRepresentation.d.ts.map +0 -1
- package/dist/util/nodeToJsonldRepresentation.js.map +0 -1
- package/dist/write.d.ts.map +0 -1
- package/dist/write.js.map +0 -1
package/README.md
CHANGED
|
@@ -3,35 +3,36 @@
|
|
|
3
3
|
Edit RDFJS Dataset just like regular JavaScript Object Literals.
|
|
4
4
|
|
|
5
5
|
Just a few lines of familiar code:
|
|
6
|
+
|
|
6
7
|
```typescript
|
|
7
8
|
const personNode = namedNode("http://example.com/Person1");
|
|
8
|
-
const person = jsonldDatasetProxy(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
).fromSubject<IPerson>(namedNode("http://example.com/Person1"));
|
|
9
|
+
const person = jsonldDatasetProxy(dataset, PersonContext).fromSubject<IPerson>(
|
|
10
|
+
namedNode("http://example.com/Person1"),
|
|
11
|
+
);
|
|
12
12
|
person.age = 23;
|
|
13
13
|
person.name.add("John");
|
|
14
14
|
```
|
|
15
15
|
|
|
16
16
|
are equivalent to:
|
|
17
|
+
|
|
17
18
|
```typescript
|
|
18
19
|
dataset.deleteMatches(
|
|
19
20
|
namedNode("http://example.com/Person1"),
|
|
20
|
-
namedNode("http://xmlns.com/foaf/0.1/age")
|
|
21
|
+
namedNode("http://xmlns.com/foaf/0.1/age"),
|
|
21
22
|
);
|
|
22
23
|
dataset.add(
|
|
23
24
|
quad(
|
|
24
25
|
namedNode("http://example.com/Person1"),
|
|
25
26
|
namedNode("http://xmlns.com/foaf/0.1/age"),
|
|
26
|
-
literal("23", "http://www.w3.org/2001/XMLSchema#integer")
|
|
27
|
-
)
|
|
27
|
+
literal("23", "http://www.w3.org/2001/XMLSchema#integer"),
|
|
28
|
+
),
|
|
28
29
|
);
|
|
29
30
|
dataset.add(
|
|
30
31
|
quad(
|
|
31
32
|
namedNode("http://example.com/Person1"),
|
|
32
33
|
namedNode("http://xmlns.com/foaf/0.1/name"),
|
|
33
|
-
literal("John", "http://www.w3.org/2001/XMLSchema#string")
|
|
34
|
-
)
|
|
34
|
+
literal("John", "http://www.w3.org/2001/XMLSchema#string"),
|
|
35
|
+
),
|
|
35
36
|
);
|
|
36
37
|
```
|
|
37
38
|
|
|
@@ -39,13 +40,14 @@ Plus, you get IntelliSense typescript suggestions to help you write your code!
|
|
|
39
40
|
|
|
40
41
|

|
|
41
42
|
|
|
42
|
-
|
|
43
43
|
## Installation
|
|
44
|
+
|
|
44
45
|
```bash
|
|
45
46
|
npm install @ldo/jsonld-dataset-proxy
|
|
46
47
|
```
|
|
47
48
|
|
|
48
49
|
## Simple Example
|
|
50
|
+
|
|
49
51
|
```typescript
|
|
50
52
|
import jsonldDatasetProxy, { write, LdSet } from "jsonld-dataset-proxy";
|
|
51
53
|
import { ContextDefinition } from "jsonld";
|
|
@@ -68,7 +70,7 @@ async function start() {
|
|
|
68
70
|
// Make a JSONLD Dataset Proxy
|
|
69
71
|
const person = jsonldDatasetProxy(
|
|
70
72
|
dataset,
|
|
71
|
-
PersonContext
|
|
73
|
+
PersonContext,
|
|
72
74
|
).fromSubject<IPerson>(namedNode("http://example.com/Person1"));
|
|
73
75
|
// Make Modifications
|
|
74
76
|
person.age = 23;
|
|
@@ -108,30 +110,31 @@ start();
|
|
|
108
110
|
|
|
109
111
|
## Full Usage
|
|
110
112
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
113
|
+
- [Defining a Context and Type](#defining-a-context-and-type)
|
|
114
|
+
- [Getting a Jsonld DatasetProxy](#getting-a-jsonld-dataset-proxy)
|
|
115
|
+
- [`.fromSubject<T>(entryNode)`](#fromsubjecttentrynode)
|
|
116
|
+
- [`.matchSubject<T>(predicate?, object?, graph?)`](#matchsubjecttpredicate-object-graph)
|
|
117
|
+
- [`.matchObject<T>(subject?, predicate?, graph?)`](#matchobjecttsubject-predicate-object)
|
|
118
|
+
- [`.fromJson<T>(inputData)`](#fromjsontinputdata)
|
|
119
|
+
- [Getting Field Values and Traversing](#getting-field-values-and-traversing)
|
|
120
|
+
- [Setting a Primitive](#setting-a-primitive)
|
|
121
|
+
- [Setting an Object](#setting-an-object)
|
|
122
|
+
- [Set Methods](#set-methods)
|
|
123
|
+
- [Overwriting an Object](#overwriting-an-object)
|
|
124
|
+
- [Changing an Object's Id](#changing-an-objects-id)
|
|
125
|
+
- [Removing an Object Connection](#removing-an-object-connection)
|
|
126
|
+
- [Deleting an Entire Object](#deleting-an-entire-object)
|
|
127
|
+
- [Using Blank Nodes](#using-blank-nodes)
|
|
128
|
+
- [Writing Information to a Specific Graph](#writing-information-to-a-specific-graph)
|
|
129
|
+
- [`jsonldDatasetProxy(...).write(...graphs)`](#jsonlddatasetproxywritegraphs)
|
|
130
|
+
- [`write(...graphs).using(...jsonldDatasetProxies)`](#writegraphsusingjsonlddatasetproxies)
|
|
131
|
+
- [`write(...graphs).usingCopy(...jsonldDatasetProxies)`](#writegraphsusingcopyjsonlddatasetproxies)
|
|
132
|
+
- [Detecting a the graph of specific information](#detecting-a-the-graph-of-specific-information)
|
|
131
133
|
|
|
132
134
|
For the most part, you can think of a JSONLD Dataset Proxy as a JavaScript Object Literal with "Sets" instead of arrays.
|
|
133
135
|
|
|
134
136
|
### Defining a Context and Type
|
|
137
|
+
|
|
135
138
|
The first step to getting a JSONLD Dataset Proxy is defining the JSONLD Context and TypeScript Typings. This can either be done through a [generator](https://ldo.js.org/latest/api/cli/build/) or defining them manually.
|
|
136
139
|
|
|
137
140
|
In this example typescript typing `IPerson` is an interface that represents a person. Notice the `@id` and `@context` fields. Be sure to include them in your interfaces if you wish to use those properties.
|
|
@@ -177,13 +180,15 @@ const PersonContext: ContextDefinition = {
|
|
|
177
180
|
```
|
|
178
181
|
|
|
179
182
|
To do this, create an object that has corresponding fields to your type. Each field is an object that contains the following properties:
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
+
|
|
184
|
+
- `@id`: indicates the URI of the corresponding predicate
|
|
185
|
+
- `@type`: If the corresponding type is a pimitive (Like a number or string), use this field to list the RDF Literal type (Most often this is an XMLSchema type). If the corresponding type is an object, list `@id` here.
|
|
186
|
+
- `@container`: If the corresponding type is an array of items, set `@container` to `@set`, if not, do not include the `@container` property.
|
|
183
187
|
|
|
184
188
|
Note that only the features described here work with JSONLD Dataset Proxy. Other features of JSONLD Contexts are not yet supported.
|
|
185
189
|
|
|
186
190
|
### Getting a Jsonld Dataset Proxy
|
|
191
|
+
|
|
187
192
|
Once the Typescript Typings and Context have been defined, we can get the JSONLD Dataset Proxy for a specific dataset.
|
|
188
193
|
|
|
189
194
|
```typescript
|
|
@@ -192,38 +197,34 @@ import { createDataset } from "o-dataset-pack";
|
|
|
192
197
|
|
|
193
198
|
const dataset = await createDataset();
|
|
194
199
|
// Make a JSONLD Dataset Proxy
|
|
195
|
-
const person = jsonldDatasetProxy(
|
|
196
|
-
dataset,
|
|
197
|
-
PersonContext
|
|
198
|
-
) // ...
|
|
200
|
+
const person = jsonldDatasetProxy(dataset, PersonContext); // ...
|
|
199
201
|
```
|
|
200
202
|
|
|
201
203
|
The functon `jsonldDatasetProxy` takes in three parameters:
|
|
202
|
-
- `dataset`: The dataset you wish to traverse and manipulate. This can be any dataset that follows the [RDFJS Dataset Interface](https://rdf.js.org/dataset-spec/#dataset-interface). Note that this is not to be confused with the RDFJS Dataset ***Core*** interface. This example uses the "o-dataset-pack", but any implementation of the RDFJS Dataset Interface is acceptable.
|
|
203
|
-
- `context`: The JSONLD context.
|
|
204
204
|
|
|
205
|
-
|
|
205
|
+
- `dataset`: The dataset you wish to traverse and manipulate. This can be any dataset that follows the [RDFJS Dataset Interface](https://rdf.js.org/dataset-spec/#dataset-interface). Note that this is not to be confused with the RDFJS Dataset **_Core_** interface. This example uses the "o-dataset-pack", but any implementation of the RDFJS Dataset Interface is acceptable.
|
|
206
|
+
- `context`: The JSONLD context.
|
|
207
|
+
|
|
208
|
+
After defining the `dataset` and `context` there are a few ways to get Jsonld Dataset Proxies:
|
|
206
209
|
|
|
207
210
|
#### `.fromSubject<T>(entryNode)`
|
|
211
|
+
|
|
208
212
|
`fromSubject` lets you define a an `entryNode`, the place of entry for the graph. The object returned by `jsonldDatasetProxy` will represent the given node. This parameter accepts both `namedNode`s and `blankNode`s. `fromSubject` takes a generic type representing the typescript type of the given subject.
|
|
209
213
|
|
|
210
214
|
```typescript
|
|
211
|
-
const person = jsonldDatasetProxy(
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
).fromSubject<IPerson>(namedNode("http://example.com/Person1"));
|
|
215
|
+
const person = jsonldDatasetProxy(dataset, PersonContext).fromSubject<IPerson>(
|
|
216
|
+
namedNode("http://example.com/Person1"),
|
|
217
|
+
);
|
|
215
218
|
```
|
|
216
219
|
|
|
217
220
|
#### `.matchSubject<T>(predicate?, object?, graph?)`
|
|
221
|
+
|
|
218
222
|
`matchSubject` returns a Jsonld Dataset Proxy representing all subjects in the dataset matching the given predicate, object, and graph.
|
|
219
223
|
|
|
220
224
|
```typescript
|
|
221
|
-
const people = jsonldDatasetProxy(
|
|
222
|
-
dataset,
|
|
223
|
-
PersonContext
|
|
224
|
-
).matchSubject<IPerson>(
|
|
225
|
+
const people = jsonldDatasetProxy(dataset, PersonContext).matchSubject<IPerson>(
|
|
225
226
|
namedNode("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"),
|
|
226
|
-
namedNode("http://xmlns.com/foaf/0.1/Person")
|
|
227
|
+
namedNode("http://xmlns.com/foaf/0.1/Person"),
|
|
227
228
|
);
|
|
228
229
|
people.forEach((person) => {
|
|
229
230
|
console.log(person.name);
|
|
@@ -231,15 +232,16 @@ people.forEach((person) => {
|
|
|
231
232
|
```
|
|
232
233
|
|
|
233
234
|
#### `.matchObject<T>(subject?, predicate?, object?)`
|
|
235
|
+
|
|
234
236
|
`matchObject` returns a Jsonld Dataset Proxy representing all objects in the dataset matching the given subject, predicate, and graph.
|
|
235
237
|
|
|
236
238
|
```typescript
|
|
237
239
|
const friendsOfPerson1 = jsonldDatasetProxy(
|
|
238
240
|
dataset,
|
|
239
|
-
PersonContext
|
|
241
|
+
PersonContext,
|
|
240
242
|
).matchSubject<IPerson>(
|
|
241
243
|
namedNode("http://example.com/Person1"),
|
|
242
|
-
namedNode("http://xmlns.com/foaf/0.1/knows")
|
|
244
|
+
namedNode("http://xmlns.com/foaf/0.1/knows"),
|
|
243
245
|
);
|
|
244
246
|
friendsOfPerson1.forEach((person) => {
|
|
245
247
|
console.log(person.name);
|
|
@@ -247,15 +249,13 @@ friendsOfPerson1.forEach((person) => {
|
|
|
247
249
|
```
|
|
248
250
|
|
|
249
251
|
#### `.fromJson<T>(inputData)`
|
|
252
|
+
|
|
250
253
|
`fromJson` will take any regular Json, add the information to the dataset, and return a Jsonld Dataset Proxy representing the given data.
|
|
251
254
|
|
|
252
255
|
```typescript
|
|
253
256
|
import { jsonldDatasetProxy, set } from "@ldo/jsonld-dataset-proxy";
|
|
254
257
|
|
|
255
|
-
const person2 = jsonldDatasetProxy(
|
|
256
|
-
dataset,
|
|
257
|
-
PersonContext
|
|
258
|
-
).fromJson<IPerson>({
|
|
258
|
+
const person2 = jsonldDatasetProxy(dataset, PersonContext).fromJson<IPerson>({
|
|
259
259
|
"@id": "http://example.com/Person2",
|
|
260
260
|
name: set("Jane", "Doe"),
|
|
261
261
|
birthdate: "1990/11/03",
|
|
@@ -264,6 +264,7 @@ const person2 = jsonldDatasetProxy(
|
|
|
264
264
|
```
|
|
265
265
|
|
|
266
266
|
### Getting Field Values and Traversing
|
|
267
|
+
|
|
267
268
|
Getting a field and traversing the object is just as easy as getting data out of a standard JavaScript Object Literal.
|
|
268
269
|
|
|
269
270
|
In all the following example, we will use a dataset loaded with the following data:
|
|
@@ -288,10 +289,9 @@ const dataset = await serializedToDataset(`
|
|
|
288
289
|
foaf:name "Dave"^^xsd:string;
|
|
289
290
|
foaf:age "33"^^xsd:integer.
|
|
290
291
|
`);
|
|
291
|
-
const person = jsonldDatasetProxy(
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
).fromSubject<IPerson>(namedNode("http://example.com/Person1"));
|
|
292
|
+
const person = jsonldDatasetProxy(dataset, PersonContext).fromSubject<IPerson>(
|
|
293
|
+
namedNode("http://example.com/Person1"),
|
|
294
|
+
);
|
|
295
295
|
// Get primitives
|
|
296
296
|
console.log(person.age); // 22
|
|
297
297
|
// Get nested primitives
|
|
@@ -310,33 +310,31 @@ console.log(person.bestFriend?.["@id"]); // "http://example.com/Person2"
|
|
|
310
310
|
console.log(person["@context"]); // { "name": { "@id": ... }}
|
|
311
311
|
```
|
|
312
312
|
|
|
313
|
-
|
|
314
|
-
|
|
315
313
|
### Setting a Primitive
|
|
314
|
+
|
|
316
315
|
Setting a non-array primitive will remove the existing triple from the dataset and add a new triple.
|
|
317
316
|
|
|
318
317
|
```typescript
|
|
319
318
|
const dataset = createDataset();
|
|
320
|
-
const person = jsonldDatasetProxy(
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
).fromSubject<IPerson>(namedNode("http://example.com/Person1"))
|
|
319
|
+
const person = jsonldDatasetProxy(dataset, PersonContext).fromSubject<IPerson>(
|
|
320
|
+
namedNode("http://example.com/Person1"),
|
|
321
|
+
);
|
|
324
322
|
person.age = 23;
|
|
325
323
|
console.log(dataset.toString());
|
|
326
324
|
// <http://example.com/Person1> <http://xmlns.com/foaf/0.1/age> "23"^^<http://www.w3.org/2001/XMLSchema#integer> .
|
|
327
325
|
```
|
|
328
326
|
|
|
329
327
|
### Setting an Object
|
|
328
|
+
|
|
330
329
|
Setting a field to a JavaScript object literal will recursively add all parts of the object literal to the dataset.
|
|
331
330
|
|
|
332
331
|
```typescript
|
|
333
332
|
import { set } from "@ldo/jsonld-dataset-pack";
|
|
334
333
|
|
|
335
334
|
const dataset = createDataset();
|
|
336
|
-
const person = jsonldDatasetProxy(
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
).fromSubject<IPerson>(namedNode("http://example.com/Person1"));
|
|
335
|
+
const person = jsonldDatasetProxy(dataset, PersonContext).fromSubject<IPerson>(
|
|
336
|
+
namedNode("http://example.com/Person1"),
|
|
337
|
+
);
|
|
340
338
|
person.bestFriend = {
|
|
341
339
|
"@id": "http://example.com/Person2",
|
|
342
340
|
name: set("Alice"),
|
|
@@ -353,8 +351,8 @@ console.log(dataset.toString());
|
|
|
353
351
|
```
|
|
354
352
|
|
|
355
353
|
### Set Methods
|
|
356
|
-
Any methods that on a [JavaScript Set](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set) are available.
|
|
357
354
|
|
|
355
|
+
Any methods that on a [JavaScript Set](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set) are available.
|
|
358
356
|
|
|
359
357
|
```typescript
|
|
360
358
|
const dataset = await serializedToDataset(`
|
|
@@ -365,10 +363,9 @@ const dataset = await serializedToDataset(`
|
|
|
365
363
|
example:Person1
|
|
366
364
|
foaf:name "Garrett"^^xsd:string, "Bobby"^^xsd:string.
|
|
367
365
|
`);
|
|
368
|
-
const person = jsonldDatasetProxy(
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
).fromSubject<IPerson>(namedNode("http://example.com/Person1"));
|
|
366
|
+
const person = jsonldDatasetProxy(dataset, PersonContext).fromSubject<IPerson>(
|
|
367
|
+
namedNode("http://example.com/Person1"),
|
|
368
|
+
);
|
|
372
369
|
person.name?.add("Ferguson");
|
|
373
370
|
console.log(dataset.toString());
|
|
374
371
|
// <http://example.com/Person1> <http://xmlns.com/foaf/0.1/name> "Garrett" .
|
|
@@ -412,6 +409,7 @@ LdSet<T> {
|
|
|
412
409
|
```
|
|
413
410
|
|
|
414
411
|
### Overwriting an Object
|
|
412
|
+
|
|
415
413
|
If an object literal is set and the id is equivalent to an existing id, that node will be overwritten. All triples from the previous object are removed and replaced with triples from the new object.
|
|
416
414
|
|
|
417
415
|
```typescript
|
|
@@ -424,10 +422,9 @@ const dataset = await serializedToDataset(`
|
|
|
424
422
|
foaf:name "Alice"^^xsd:string;
|
|
425
423
|
foaf:age "28"^^xsd:integer.
|
|
426
424
|
`);
|
|
427
|
-
const person = jsonldDatasetProxy(
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
).fromSubject<IPerson>(namedNode("http://example.com/Person1"));
|
|
425
|
+
const person = jsonldDatasetProxy(dataset, PersonContext).fromSubject<IPerson>(
|
|
426
|
+
namedNode("http://example.com/Person1"),
|
|
427
|
+
);
|
|
431
428
|
person.bestFriend = {
|
|
432
429
|
"@id": "http://example.com/Person2",
|
|
433
430
|
name: set("Jane"),
|
|
@@ -438,6 +435,7 @@ console.log(dataset.toString());
|
|
|
438
435
|
```
|
|
439
436
|
|
|
440
437
|
### Changing an Object's Id
|
|
438
|
+
|
|
441
439
|
You can rename an object by setting its `@id` field. This will update all triples that reference the id to the new id. Setting the `@id` field to `undefined` will turn it into a blank node.
|
|
442
440
|
|
|
443
441
|
```typescript
|
|
@@ -453,10 +451,9 @@ const dataset = await serializedToDataset(`
|
|
|
453
451
|
example:Person2
|
|
454
452
|
foaf:bestFriend example:Person1.
|
|
455
453
|
`);
|
|
456
|
-
const person = jsonldDatasetProxy(
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
).fromSubject<IPerson>(namedNode("http://example.com/Person1"))
|
|
454
|
+
const person = jsonldDatasetProxy(dataset, PersonContext).fromSubject<IPerson>(
|
|
455
|
+
namedNode("http://example.com/Person1"),
|
|
456
|
+
);
|
|
460
457
|
person["@id"] = "http://example.com/NewPersonId";
|
|
461
458
|
console.log(dataset.toString());
|
|
462
459
|
// <http://example.com/Person2> <http://xmlns.com/foaf/0.1/bestFriend> <http://example.com/NewPersonId> .
|
|
@@ -465,6 +462,7 @@ console.log(dataset.toString());
|
|
|
465
462
|
```
|
|
466
463
|
|
|
467
464
|
### Removing an Object Connection
|
|
465
|
+
|
|
468
466
|
Removing a connection between nodes can be done by setting a field to `undefined` or using the `delete` operator. Values can be removed from a set by using the `delete` method or the `clear` method to remove all connections.
|
|
469
467
|
|
|
470
468
|
```typescript
|
|
@@ -481,10 +479,9 @@ const dataset = await serializedToDataset(`
|
|
|
481
479
|
foaf:name "Bob"^^xsd:string;
|
|
482
480
|
foaf:bestFriend example:Person1.
|
|
483
481
|
`);
|
|
484
|
-
const person = jsonldDatasetProxy(
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
).fromSubject<IPerson>(namedNode("http://example.com/Person1"));
|
|
482
|
+
const person = jsonldDatasetProxy(dataset, PersonContext).fromSubject<IPerson>(
|
|
483
|
+
namedNode("http://example.com/Person1"),
|
|
484
|
+
);
|
|
488
485
|
perons.bestFriend.name.delete("Bob");
|
|
489
486
|
person.bestFriend = undefined;
|
|
490
487
|
console.log(dataset.toString());
|
|
@@ -493,6 +490,7 @@ console.log(dataset.toString());
|
|
|
493
490
|
```
|
|
494
491
|
|
|
495
492
|
### Deleting an Entire Object
|
|
493
|
+
|
|
496
494
|
If you want to delete all triples represented by an object you can call `delete` on the `@id` property.
|
|
497
495
|
|
|
498
496
|
```typescript
|
|
@@ -509,23 +507,23 @@ const dataset = await serializedToDataset(`
|
|
|
509
507
|
foaf:name "Bob"^^xsd:string;
|
|
510
508
|
foaf:bestFriend example:Person1.
|
|
511
509
|
`);
|
|
512
|
-
const person = jsonldDatasetProxy(
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
).fromSubject<IPerson>(namedNode("http://example.com/Person1"));
|
|
510
|
+
const person = jsonldDatasetProxy(dataset, PersonContext).fromSubject<IPerson>(
|
|
511
|
+
namedNode("http://example.com/Person1"),
|
|
512
|
+
);
|
|
516
513
|
delete person["@id"];
|
|
517
514
|
console.log(dataset.toString());
|
|
518
515
|
// <http://example.com/Person2> <http://xmlns.com/foaf/0.1/name> "Bob" .
|
|
519
516
|
```
|
|
520
517
|
|
|
521
518
|
### Using Blank Nodes
|
|
519
|
+
|
|
522
520
|
If you want to create an object with a blankNode subject, simply omit the `@id` field when you're making the object.
|
|
521
|
+
|
|
523
522
|
```typescript
|
|
524
523
|
const dataset = await createDataset();
|
|
525
|
-
const person = jsonldDatasetProxy(
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
).fromSubject<IPerson>(namedNode("http://example.com/Person1"));
|
|
524
|
+
const person = jsonldDatasetProxy(dataset, PersonContext).fromSubject<IPerson>(
|
|
525
|
+
namedNode("http://example.com/Person1"),
|
|
526
|
+
);
|
|
529
527
|
person.bestFriend = {
|
|
530
528
|
name: set("Charlie"),
|
|
531
529
|
};
|
|
@@ -535,6 +533,7 @@ console.log(dataset.toString());
|
|
|
535
533
|
```
|
|
536
534
|
|
|
537
535
|
If your dataset has blank nodes and you want to assign that blank node as a triple's object, you can retrieve it from the JSONLD Dataset Proxy and assign it.
|
|
536
|
+
|
|
538
537
|
```typescript
|
|
539
538
|
const dataset = await serializedToDataset(`
|
|
540
539
|
@prefix example: <http://example.com/> .
|
|
@@ -546,10 +545,9 @@ const dataset = await serializedToDataset(`
|
|
|
546
545
|
foaf:name "Alice"^^xsd:string;
|
|
547
546
|
].
|
|
548
547
|
`);
|
|
549
|
-
const person = jsonldDatasetProxy(
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
).fromSubject<IPerson>(namedNode("http://example.com/Person1"));
|
|
548
|
+
const person = jsonldDatasetProxy(dataset, PersonContext).fromSubject<IPerson>(
|
|
549
|
+
namedNode("http://example.com/Person1"),
|
|
550
|
+
);
|
|
553
551
|
|
|
554
552
|
const alice = person.knows?.toArray()[0];
|
|
555
553
|
person.bestFriend = alice;
|
|
@@ -560,11 +558,13 @@ console.log(dataset.toString());
|
|
|
560
558
|
```
|
|
561
559
|
|
|
562
560
|
### Writing Information to a Specific Graph
|
|
561
|
+
|
|
563
562
|
By default, all new quads are added to the default graph, but you can change the graph to which new quads are added in a few different ways:
|
|
564
563
|
|
|
565
564
|
NOTE: These operations only dictate the graph for new triples. Any operations that delete triples will delete triples regardless of their graph.
|
|
566
565
|
|
|
567
566
|
#### `jsonldDatasetProxy(...).write(...graphs)`
|
|
567
|
+
|
|
568
568
|
The write graph can be set upon creating a jsonld dataset proxy by using the `write` method. This method takes in any number of graphs.
|
|
569
569
|
|
|
570
570
|
```typescript
|
|
@@ -578,15 +578,15 @@ console.log(dataset.toString());
|
|
|
578
578
|
```
|
|
579
579
|
|
|
580
580
|
#### `write(...graphs).using(...jsonldDatasetProxies)`
|
|
581
|
+
|
|
581
582
|
The `write(...).using(...)` function lets you define the graphs you wish to write to using specific jsonldDatasetProxies.
|
|
582
583
|
|
|
583
584
|
```typescript
|
|
584
585
|
import jsonldDatasetProxy, { write } from "jsonld-dataset-proxy";
|
|
585
586
|
|
|
586
|
-
const person1 = jsonldDatasetProxy(
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
).fromSubject<IPerson>(namedNode("http://example.com/Person1"));
|
|
587
|
+
const person1 = jsonldDatasetProxy(dataset, PersonContext).fromSubject<IPerson>(
|
|
588
|
+
namedNode("http://example.com/Person1"),
|
|
589
|
+
);
|
|
590
590
|
// Now all additions with person1 will be on ExampleGraph1
|
|
591
591
|
write(namedNode("http://example.com/ExampleGraph1")).using(person1);
|
|
592
592
|
person1.name.add("Jack");
|
|
@@ -603,10 +603,9 @@ console.log(dataset.toString());
|
|
|
603
603
|
The function also returns an `end` function that will reset the graph to what it was before. This is useful for nesting graph modifications.
|
|
604
604
|
|
|
605
605
|
```typescript
|
|
606
|
-
const person1 = jsonldDatasetProxy(
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
).fromSubject<IPerson>(namedNode("http://example.com/Person1"));
|
|
606
|
+
const person1 = jsonldDatasetProxy(dataset, PersonContext).fromSubject<IPerson>(
|
|
607
|
+
namedNode("http://example.com/Person1"),
|
|
608
|
+
);
|
|
610
609
|
person1.name.add("default");
|
|
611
610
|
const end1 = write(namedNode("http://example.com/Graph1")).using(person1);
|
|
612
611
|
person1.name.add("1");
|
|
@@ -632,15 +631,15 @@ console.log(dataset.toString());
|
|
|
632
631
|
```
|
|
633
632
|
|
|
634
633
|
#### `write(...graphs).usingCopy(...jsonldDatasetProxies)`
|
|
634
|
+
|
|
635
635
|
If you would like a new variable to write to without modifying the original Jsonld Dataset Proxy, you can use `write(...).usingCopy(...)`.
|
|
636
636
|
|
|
637
637
|
```typescript
|
|
638
|
-
const person1 = jsonldDatasetProxy(
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
).fromSubject<IPerson>(namedNode("http://example.com/Person1"));
|
|
638
|
+
const person1 = jsonldDatasetProxy(dataset, PersonContext).fromSubject<IPerson>(
|
|
639
|
+
namedNode("http://example.com/Person1"),
|
|
640
|
+
);
|
|
642
641
|
const [person1WritingToNewGraph] = write(
|
|
643
|
-
namedNode("http://example.com/NewGraph")
|
|
642
|
+
namedNode("http://example.com/NewGraph"),
|
|
644
643
|
).usingCopy(person1);
|
|
645
644
|
person1WritingToNewGraph.name.add("Brandon");
|
|
646
645
|
person1.name.add("Sanderson");
|
|
@@ -654,9 +653,9 @@ console.log(dataset.toString());
|
|
|
654
653
|
|
|
655
654
|
The graph of specific information can be detected using the `graphOf(subject, predicate, object)` function. The `graphOf` function takes in two to three arguments.
|
|
656
655
|
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
656
|
+
- `subject`: A Jsonld Dataset Proxy that represents the subject of a quad.
|
|
657
|
+
- `predicate`: A string key
|
|
658
|
+
- `object?`: A representation of the direct object of the triple in question. This could be a jsonld-dataset-proxy or simply and object with an `@id` field.
|
|
660
659
|
|
|
661
660
|
```typescript
|
|
662
661
|
graphOf(person, "name", "Bob"); // returns defaultGraph()
|
|
@@ -711,7 +710,8 @@ const PersonContext: ContextDefinition = {
|
|
|
711
710
|
```
|
|
712
711
|
|
|
713
712
|
### Language Preferences
|
|
714
|
-
|
|
713
|
+
|
|
714
|
+
A language preference is an ordered list telling the JSON-LD Dataset Proxy the language you prefer as well as callbacks.
|
|
715
715
|
|
|
716
716
|
Valid values for the language preferences includes any [IETF Language Tag](https://en.wikipedia.org/wiki/IETF_language_tag) as well as the special tags `@none` and `@other`. `@none` represents any language literal that doesn't have a language tag. `@other` represents any language literal that isn't listed among the language preferences.
|
|
717
717
|
|
|
@@ -720,11 +720,11 @@ For read operations, the JSON-LD Dataset Proxy will search for values in order o
|
|
|
720
720
|
```typescript
|
|
721
721
|
// Read Spansih first, then Korean, then language strings with no language
|
|
722
722
|
// New writes are in Spanish
|
|
723
|
-
["es", "ko", "@none"]
|
|
724
|
-
|
|
725
|
-
//
|
|
726
|
-
|
|
727
|
-
|
|
723
|
+
["es", "ko", "@none"][
|
|
724
|
+
// Read any language other than french, then french
|
|
725
|
+
// New writes are in French
|
|
726
|
+
("@other", "fr")
|
|
727
|
+
];
|
|
728
728
|
```
|
|
729
729
|
|
|
730
730
|
Language preferences can be set when a JSON-LD Dataset Proxy is created using the `setLanguagePreferences` method.
|
|
@@ -752,6 +752,7 @@ console.log(hospitalInfo.description.toArray()[0]); // Logs "Cura a las paciente
|
|
|
752
752
|
```
|
|
753
753
|
|
|
754
754
|
### `setLanguagePreferences(...languagePreferences).using(...jsonldDatasetProxies)`
|
|
755
|
+
|
|
755
756
|
The `setLanguagePreferences(...).using(...)` function sets the language preferences for a set of JSON-LD Dataset Proxies. It follows roughly the same paridigms as the `write(...).using(...)` function.
|
|
756
757
|
|
|
757
758
|
```typescript
|
|
@@ -764,6 +765,7 @@ console.log(hospitalInfo.label); // Logs "Hospital"
|
|
|
764
765
|
```
|
|
765
766
|
|
|
766
767
|
### `setLanguagePreferences(...languagePreferences).usingCopy(...jsonldDatasetProxies)`
|
|
768
|
+
|
|
767
769
|
The `setLanguagePreferences(...).usingCopy(...)` function returns a copy of the provided JSON-LD Dataset Proxies with the given language preferences. It follows roughly the same paridigms as the `write(...).usingCopy(...)` function.
|
|
768
770
|
|
|
769
771
|
```typescript
|
|
@@ -778,10 +780,11 @@ console.log(koreanPreference.label); // Logs "병원"
|
|
|
778
780
|
```
|
|
779
781
|
|
|
780
782
|
### `languageOf(jsonldDatasetProxy, key)`
|
|
783
|
+
|
|
781
784
|
The `languageOf` function lets you view and modify the languages more directly. `languageOf` takes two properties:
|
|
782
785
|
|
|
783
|
-
|
|
784
|
-
|
|
786
|
+
- `jsonldDatasetProxy`: A JSON-LD dataset proxy
|
|
787
|
+
- `key`: A key on the JSON-LD dataset proxy pointing to a language string.
|
|
785
788
|
|
|
786
789
|
It returns a mapping of languages to strings or sets of strings depending on the cardinality of the JSON-LD context.
|
|
787
790
|
|
|
@@ -815,16 +818,19 @@ descriptionLanguages["@none"]?.delete("Has Doctors");
|
|
|
815
818
|
```
|
|
816
819
|
|
|
817
820
|
## Limitations
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
821
|
+
|
|
822
|
+
- Currently this library only supports the following features of JSON-LD context:
|
|
823
|
+
- "@id",
|
|
824
|
+
- "@type",
|
|
825
|
+
- "@container": "@set"
|
|
822
826
|
|
|
823
827
|
## Sponsorship
|
|
828
|
+
|
|
824
829
|
This project was made possible by a grant from NGI Zero Entrust via nlnet. Learn more on the [NLnet project page](https://nlnet.nl/project/SolidUsableApps/).
|
|
825
830
|
|
|
826
831
|
[<img src="https://nlnet.nl/logo/banner.png" alt="nlnet foundation logo" width="300" />](https://nlnet.nl/)
|
|
827
832
|
[<img src="https://nlnet.nl/image/logos/NGI0Entrust_tag.svg" alt="NGI Zero Entrust Logo" width="300" />](https://nlnet.nl/)
|
|
828
833
|
|
|
829
834
|
## Liscense
|
|
830
|
-
|
|
835
|
+
|
|
836
|
+
MIT
|
package/dist/ContextUtil.cjs
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
1
|
//#region src/ContextUtil.ts
|
|
3
2
|
const shorthandToIriMap = { "@type": "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" };
|
|
4
3
|
/**
|
|
@@ -6,9 +5,6 @@ const shorthandToIriMap = { "@type": "http://www.w3.org/1999/02/22-rdf-syntax-ns
|
|
|
6
5
|
* Handles the JSON-LD context and allows conversion between IRIs and terms
|
|
7
6
|
*/
|
|
8
7
|
var ContextUtil = class {
|
|
9
|
-
context;
|
|
10
|
-
iriToKeyMap;
|
|
11
|
-
typeNameToIriToKeyMap;
|
|
12
8
|
constructor(context) {
|
|
13
9
|
this.context = context;
|
|
14
10
|
this.iriToKeyMap = {};
|
|
@@ -92,6 +88,5 @@ var ContextUtil = class {
|
|
|
92
88
|
return !!(relevantContext[key] && typeof relevantContext[key] === "object" && relevantContext[key]["@type"] && relevantContext[key]["@type"] === "http://www.w3.org/1999/02/22-rdf-syntax-ns#langString");
|
|
93
89
|
}
|
|
94
90
|
};
|
|
95
|
-
|
|
96
91
|
//#endregion
|
|
97
|
-
exports.ContextUtil = ContextUtil;
|
|
92
|
+
exports.ContextUtil = ContextUtil;
|
package/dist/ContextUtil.d.cts
CHANGED
|
@@ -3,7 +3,6 @@ import { NamedNode } from "@rdfjs/types";
|
|
|
3
3
|
import { ContextDefinition } from "jsonld";
|
|
4
4
|
|
|
5
5
|
//#region src/ContextUtil.d.ts
|
|
6
|
-
|
|
7
6
|
/**
|
|
8
7
|
* Context Util
|
|
9
8
|
* Handles the JSON-LD context and allows conversion between IRIs and terms
|
|
@@ -44,7 +43,6 @@ declare class ContextUtil {
|
|
|
44
43
|
*/
|
|
45
44
|
isLangString(key: string, typeName: NamedNode[]): boolean;
|
|
46
45
|
}
|
|
47
|
-
//# sourceMappingURL=ContextUtil.d.ts.map
|
|
48
46
|
//#endregion
|
|
49
47
|
export { ContextUtil };
|
|
50
48
|
//# sourceMappingURL=ContextUtil.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContextUtil.d.cts","names":[],"sources":["
|
|
1
|
+
{"version":3,"file":"ContextUtil.d.cts","names":[],"sources":["../src/ContextUtil.ts"],"mappings":";;;;;;;AAgBA;;cAAa,WAAA;EAAA,SACK,OAAA,EAAS,iBAAA,GAAoB,gBAAA;EAAA,QACrC,WAAA;EAAA,QACA,qBAAA;cAEI,OAAA,EAAS,iBAAA,GAAoB,gBAAA;EAAA,QAqBjC,iBAAA;EAuEgC;;;;EAAA,QAhDhC,kBAAA;EAiG4C;;;EAAA,QA7E5C,UAAA;EAnEA;;;EA8ED,QAAA,CAAS,GAAA,UAAa,QAAA,EAAU,SAAA;EA3EE;;;EA4FlC,QAAA,CAAS,GAAA,UAAa,SAAA,EAAW,SAAA;EA5BhC;;;EA6CD,WAAA,CAAY,GAAA,UAAa,QAAA,EAAU,SAAA;EAlCb;;;EAkDtB,KAAA,CAAM,GAAA,UAAa,QAAA,EAAU,SAAA;EAjCP;;;EAiDtB,YAAA,CAAa,GAAA,UAAa,QAAA,EAAU,SAAA;AAAA"}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { LdoJsonldContext } from "./LdoJsonldContext.
|
|
1
|
+
import { LdoJsonldContext } from "./LdoJsonldContext.mjs";
|
|
2
2
|
import { NamedNode } from "@rdfjs/types";
|
|
3
3
|
import { ContextDefinition } from "jsonld";
|
|
4
4
|
|
|
5
5
|
//#region src/ContextUtil.d.ts
|
|
6
|
-
|
|
7
6
|
/**
|
|
8
7
|
* Context Util
|
|
9
8
|
* Handles the JSON-LD context and allows conversion between IRIs and terms
|
|
@@ -44,7 +43,6 @@ declare class ContextUtil {
|
|
|
44
43
|
*/
|
|
45
44
|
isLangString(key: string, typeName: NamedNode[]): boolean;
|
|
46
45
|
}
|
|
47
|
-
//# sourceMappingURL=ContextUtil.d.ts.map
|
|
48
46
|
//#endregion
|
|
49
|
-
export { ContextUtil
|
|
50
|
-
//# sourceMappingURL=ContextUtil.d.
|
|
47
|
+
export { ContextUtil };
|
|
48
|
+
//# sourceMappingURL=ContextUtil.d.mts.map
|