@ldo/jsonld-dataset-proxy 0.0.1-alpha.24 → 1.0.0-alpha.1
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 +86 -71
- package/dist/ContextUtil.d.ts +12 -7
- package/dist/ContextUtil.js +69 -31
- package/dist/ContextUtil.js.map +1 -1
- package/dist/JsonldDatasetProxyBuilder.d.ts +4 -3
- package/dist/JsonldDatasetProxyBuilder.js +2 -2
- package/dist/JsonldDatasetProxyBuilder.js.map +1 -1
- package/dist/ProxyContext.d.ts +9 -9
- package/dist/ProxyContext.js +23 -25
- package/dist/ProxyContext.js.map +1 -1
- package/dist/arrayProxy/modifyArray.js +2 -2
- package/dist/arrayProxy/modifyArray.js.map +1 -1
- package/dist/graphOf.d.ts +2 -1
- package/dist/graphOf.js +4 -16
- package/dist/graphOf.js.map +1 -1
- package/dist/index.d.ts +7 -5
- package/dist/index.js +7 -5
- package/dist/index.js.map +1 -1
- package/dist/jsonldDatasetProxy.d.ts +2 -1
- package/dist/jsonldDatasetProxy.js.map +1 -1
- package/dist/language/languagesOf.d.ts +2 -1
- package/dist/language/languagesOf.js +3 -2
- package/dist/language/languagesOf.js.map +1 -1
- package/dist/setProxy/ObjectSetProxy.d.ts +17 -0
- package/dist/setProxy/ObjectSetProxy.js +31 -0
- package/dist/setProxy/ObjectSetProxy.js.map +1 -0
- package/dist/setProxy/SetProxy.d.ts +29 -0
- package/dist/setProxy/SetProxy.js +72 -0
- package/dist/setProxy/SetProxy.js.map +1 -0
- package/dist/setProxy/SubjectSetProxy.d.ts +15 -0
- package/dist/setProxy/SubjectSetProxy.js +38 -0
- package/dist/setProxy/SubjectSetProxy.js.map +1 -0
- package/dist/setProxy/WildcardObjectSetProxy.d.ts +20 -0
- package/dist/setProxy/WildcardObjectSetProxy.js +49 -0
- package/dist/setProxy/WildcardObjectSetProxy.js.map +1 -0
- package/dist/setProxy/WildcardSubjectSetProxy.d.ts +19 -0
- package/dist/setProxy/WildcardSubjectSetProxy.js +31 -0
- package/dist/setProxy/WildcardSubjectSetProxy.js.map +1 -0
- package/dist/setProxy/createNewSetProxy.d.ts +5 -0
- package/dist/setProxy/createNewSetProxy.js +27 -0
- package/dist/setProxy/createNewSetProxy.js.map +1 -0
- package/dist/setProxy/isSetProxy.d.ts +2 -0
- package/dist/setProxy/isSetProxy.js +13 -0
- package/dist/setProxy/isSetProxy.js.map +1 -0
- package/dist/setProxy/ldSet/BasicLdSet.d.ts +36 -0
- package/dist/setProxy/ldSet/BasicLdSet.js +193 -0
- package/dist/setProxy/ldSet/BasicLdSet.js.map +1 -0
- package/dist/setProxy/ldSet/LdSet.d.ts +30 -0
- package/dist/setProxy/ldSet/LdSet.js +3 -0
- package/dist/setProxy/ldSet/LdSet.js.map +1 -0
- package/dist/setProxy/set.d.ts +2 -0
- package/dist/setProxy/set.js +9 -0
- package/dist/setProxy/set.js.map +1 -0
- package/dist/subjectProxy/SubjectProxy.d.ts +1 -1
- package/dist/subjectProxy/createSubjectHandler.js +7 -5
- package/dist/subjectProxy/createSubjectHandler.js.map +1 -1
- package/dist/subjectProxy/deleteFromDataset.js +6 -25
- package/dist/subjectProxy/deleteFromDataset.js.map +1 -1
- package/dist/subjectProxy/getValueForKey.d.ts +2 -2
- package/dist/subjectProxy/getValueForKey.js +7 -9
- package/dist/subjectProxy/getValueForKey.js.map +1 -1
- package/dist/types.d.ts +2 -2
- package/dist/types.js +2 -3
- package/dist/types.js.map +1 -1
- package/dist/util/NodeSet.d.ts +0 -2
- package/dist/util/NodeSet.js +0 -10
- package/dist/util/NodeSet.js.map +1 -1
- package/dist/util/RawObject.d.ts +3 -2
- package/dist/util/addObjectToDataset.js +9 -9
- package/dist/util/addObjectToDataset.js.map +1 -1
- package/dist/util/getNodeFromRaw.d.ts +1 -1
- package/dist/util/getNodeFromRaw.js +10 -4
- package/dist/util/getNodeFromRaw.js.map +1 -1
- package/dist/util/isProxy.d.ts +4 -3
- package/dist/util/isProxy.js +2 -2
- package/dist/util/isProxy.js.map +1 -1
- package/dist/util/nodeToJsonldRepresentation.d.ts +3 -2
- package/dist/util/nodeToJsonldRepresentation.js.map +1 -1
- package/package.json +5 -5
- package/src/ContextUtil.ts +118 -35
- package/src/JsonldDatasetProxyBuilder.ts +14 -13
- package/src/LdoJsonldContext.ts +14 -0
- package/src/ProxyContext.ts +47 -39
- package/src/graphOf.ts +16 -27
- package/src/index.ts +7 -5
- package/src/jsonldDatasetProxy.ts +2 -1
- package/src/language/languagesOf.ts +7 -3
- package/src/setProxy/ObjectSetProxy.ts +66 -0
- package/src/setProxy/SetProxy.ts +141 -0
- package/src/setProxy/SubjectSetProxy.ts +85 -0
- package/src/setProxy/WildcardObjectSetProxy.ts +89 -0
- package/src/setProxy/WildcardSubjectSetProxy.ts +58 -0
- package/src/setProxy/createNewSetProxy.ts +47 -0
- package/src/setProxy/isSetProxy.ts +7 -0
- package/src/setProxy/ldSet/BasicLdSet.ts +266 -0
- package/src/setProxy/ldSet/LdSet.ts +189 -0
- package/src/setProxy/set.ts +14 -0
- package/src/subjectProxy/SubjectProxy.ts +1 -1
- package/src/subjectProxy/createSubjectHandler.ts +15 -6
- package/src/subjectProxy/deleteFromDataset.ts +12 -23
- package/src/subjectProxy/getValueForKey.ts +12 -12
- package/src/types.ts +2 -2
- package/src/util/NodeSet.ts +0 -12
- package/src/util/RawObject.ts +10 -2
- package/src/util/addObjectToDataset.ts +15 -9
- package/src/util/getNodeFromRaw.ts +14 -5
- package/src/util/isProxy.ts +7 -6
- package/src/util/nodeToJsonldRepresentation.ts +3 -2
- package/src/arrayProxy/ArrayProxy.ts +0 -20
- package/src/arrayProxy/arrayMethods.ts +0 -219
- package/src/arrayProxy/createArrayHandler.ts +0 -177
- package/src/arrayProxy/isArrayProxy.ts +0 -23
- package/src/arrayProxy/modifyArray.ts +0 -133
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
import { namedNode, quad } from "@rdfjs/data-model";
|
|
2
|
-
import type { Term } from "@rdfjs/types";
|
|
3
1
|
import type { SubjectProxyTarget } from "./createSubjectHandler";
|
|
4
2
|
import type { ProxyContext } from "../ProxyContext";
|
|
3
|
+
import { addObjectToDataset } from "../util/addObjectToDataset";
|
|
5
4
|
|
|
6
5
|
export function deleteValueFromDataset(
|
|
7
6
|
target: SubjectProxyTarget,
|
|
8
7
|
key: string | symbol,
|
|
9
8
|
proxyContext: ProxyContext,
|
|
10
9
|
) {
|
|
11
|
-
const nodesToRemove: Term[] = [];
|
|
12
10
|
if (key === "@context") {
|
|
13
11
|
return true;
|
|
14
12
|
}
|
|
@@ -18,27 +16,18 @@ export function deleteValueFromDataset(
|
|
|
18
16
|
if (typeof key === "symbol") {
|
|
19
17
|
return true;
|
|
20
18
|
}
|
|
21
|
-
|
|
22
|
-
const predicate = namedNode(proxyContext.contextUtil.keyToIri(key));
|
|
19
|
+
// Remove this node completely if delete on ID
|
|
23
20
|
if (key === "@id") {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return true;
|
|
29
|
-
} else {
|
|
30
|
-
nodesToRemove.push(...objectDataset.toArray().map((quad) => quad.object));
|
|
31
|
-
}
|
|
21
|
+
const thisNode = target["@id"];
|
|
22
|
+
proxyContext.dataset.deleteMatches(thisNode, undefined, undefined);
|
|
23
|
+
proxyContext.dataset.deleteMatches(undefined, undefined, thisNode);
|
|
24
|
+
return true;
|
|
32
25
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
proxyContext.dataset.deleteMatches(undefined, undefined, term);
|
|
40
|
-
return true;
|
|
41
|
-
}
|
|
42
|
-
});
|
|
26
|
+
// Otherwise, this is essentially treated like setting a key to undefined.
|
|
27
|
+
addObjectToDataset(
|
|
28
|
+
{ "@id": target["@id"], [key]: undefined },
|
|
29
|
+
true,
|
|
30
|
+
proxyContext,
|
|
31
|
+
);
|
|
43
32
|
return true;
|
|
44
33
|
}
|
|
@@ -2,7 +2,7 @@ import type { SubjectProxyTarget } from "./createSubjectHandler";
|
|
|
2
2
|
import { namedNode } from "@rdfjs/data-model";
|
|
3
3
|
import { nodeToJsonldRepresentation } from "../util/nodeToJsonldRepresentation";
|
|
4
4
|
import type { SubjectProxy } from "./SubjectProxy";
|
|
5
|
-
import type {
|
|
5
|
+
import type { SetProxy } from "../setProxy/SetProxy";
|
|
6
6
|
import type { ProxyContext } from "../ProxyContext";
|
|
7
7
|
import { filterQuadsByLanguageOrdering } from "../language/languageUtils";
|
|
8
8
|
|
|
@@ -13,13 +13,15 @@ export function getValueForKey(
|
|
|
13
13
|
target: SubjectProxyTarget,
|
|
14
14
|
key: string | symbol,
|
|
15
15
|
proxyContext: ProxyContext,
|
|
16
|
-
): SubjectProxy |
|
|
16
|
+
): SubjectProxy | SetProxy | string | number | boolean | undefined {
|
|
17
17
|
const { contextUtil, dataset } = proxyContext;
|
|
18
18
|
if (key === "@id") {
|
|
19
19
|
if (target["@id"].termType === "BlankNode") {
|
|
20
20
|
return undefined;
|
|
21
21
|
}
|
|
22
|
-
|
|
22
|
+
// Purposly don't provide a typeName because we don't want to use the nested
|
|
23
|
+
// context
|
|
24
|
+
return contextUtil.iriToKey(target["@id"].value, []);
|
|
23
25
|
}
|
|
24
26
|
if (key === "toString" || key === Symbol.toStringTag) {
|
|
25
27
|
// TODO: this toString method right now returns [object Object],
|
|
@@ -31,18 +33,18 @@ export function getValueForKey(
|
|
|
31
33
|
return;
|
|
32
34
|
}
|
|
33
35
|
const subject = target["@id"];
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
36
|
+
const rdfType = proxyContext.getRdfType(subject);
|
|
37
|
+
const predicate = namedNode(contextUtil.keyToIri(key, rdfType));
|
|
38
|
+
if (contextUtil.isSet(key, rdfType)) {
|
|
39
|
+
const arrayProxy = proxyContext.createSetProxy(
|
|
37
40
|
[subject, predicate, null, null],
|
|
38
41
|
false,
|
|
39
|
-
|
|
40
|
-
contextUtil.isLangString(key),
|
|
42
|
+
contextUtil.isLangString(key, rdfType),
|
|
41
43
|
);
|
|
42
44
|
return arrayProxy;
|
|
43
45
|
}
|
|
44
46
|
let objectDataset = dataset.match(subject, predicate);
|
|
45
|
-
if (contextUtil.isLangString(key)) {
|
|
47
|
+
if (contextUtil.isLangString(key, rdfType)) {
|
|
46
48
|
objectDataset = filterQuadsByLanguageOrdering(
|
|
47
49
|
objectDataset,
|
|
48
50
|
proxyContext.languageOrdering,
|
|
@@ -50,13 +52,11 @@ export function getValueForKey(
|
|
|
50
52
|
}
|
|
51
53
|
if (objectDataset.size === 0) {
|
|
52
54
|
return undefined;
|
|
53
|
-
} else
|
|
55
|
+
} else {
|
|
54
56
|
const thing = nodeToJsonldRepresentation(
|
|
55
57
|
objectDataset.toArray()[0].object,
|
|
56
58
|
proxyContext,
|
|
57
59
|
);
|
|
58
60
|
return thing;
|
|
59
|
-
} else {
|
|
60
|
-
return proxyContext.createArrayProxy([subject, predicate, null, null]);
|
|
61
61
|
}
|
|
62
62
|
}
|
package/src/types.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
export const _getUnderlyingNode = Symbol("_getUnderlyingNode");
|
|
2
2
|
export const _getUnderlyingMatch = Symbol("_getUnderlyingMatch");
|
|
3
3
|
export const _isSubjectOriented = Symbol("_isSubjectOriented");
|
|
4
|
-
export const
|
|
4
|
+
export const _isLangString = Symbol("_isLangString");
|
|
5
5
|
export const _getUnderlyingDataset = Symbol("_getUnderlyingDataset");
|
|
6
|
-
export const _getUnderlyingArrayTarget = Symbol("_getUnderlyingArrayTarget");
|
|
7
6
|
export const _proxyContext = Symbol("_proxyContext");
|
|
8
7
|
export const _writeGraphs = Symbol("_writeGraphs");
|
|
9
8
|
|
|
10
9
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
11
10
|
export type ObjectLike = Record<string | number | symbol, any>;
|
|
11
|
+
export type LiteralLike = string | number | boolean;
|
package/src/util/NodeSet.ts
CHANGED
|
@@ -32,16 +32,4 @@ export class NodeSet {
|
|
|
32
32
|
has(node: ObjectNode): boolean {
|
|
33
33
|
return this.set.has(nodeToString(node));
|
|
34
34
|
}
|
|
35
|
-
|
|
36
|
-
delete(node: ObjectNode) {
|
|
37
|
-
const key = nodeToString(node);
|
|
38
|
-
delete this.map[key];
|
|
39
|
-
return this.set.delete(nodeToString(node));
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
toArray() {
|
|
43
|
-
return Array.from(this.set).map((stringVal) => {
|
|
44
|
-
return this.map[stringVal];
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
35
|
}
|
package/src/util/RawObject.ts
CHANGED
|
@@ -1,13 +1,21 @@
|
|
|
1
1
|
import type { BlankNode, NamedNode } from "@rdfjs/types";
|
|
2
2
|
import { _getUnderlyingNode } from "../types";
|
|
3
|
+
import type { LdSet } from "../setProxy/ldSet/LdSet";
|
|
3
4
|
import type { SubjectProxy } from "../subjectProxy/SubjectProxy";
|
|
4
5
|
|
|
5
6
|
export type RawObject =
|
|
6
7
|
| ({
|
|
7
8
|
"@id"?: string | NamedNode | BlankNode;
|
|
8
9
|
} & {
|
|
9
|
-
[key: string | symbol | number]: RawValue | RawValue
|
|
10
|
+
[key: string | symbol | number]: RawValue | LdSet<RawValue>;
|
|
10
11
|
})
|
|
11
12
|
| SubjectProxy;
|
|
12
13
|
|
|
13
|
-
export type RawValue =
|
|
14
|
+
export type RawValue =
|
|
15
|
+
| string
|
|
16
|
+
| boolean
|
|
17
|
+
| number
|
|
18
|
+
| RawObject
|
|
19
|
+
| NamedNode
|
|
20
|
+
| BlankNode
|
|
21
|
+
| undefined;
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
languageDeleteMatch,
|
|
13
13
|
languageKeyToLiteralLanguage,
|
|
14
14
|
} from "../language/languageUtils";
|
|
15
|
+
import { BasicLdSet } from "../setProxy/ldSet/BasicLdSet";
|
|
15
16
|
|
|
16
17
|
export function addRawValueToDatasetRecursive(
|
|
17
18
|
subject: NamedNode | BlankNode,
|
|
@@ -22,15 +23,20 @@ export function addRawValueToDatasetRecursive(
|
|
|
22
23
|
proxyContext: ProxyContext,
|
|
23
24
|
): void {
|
|
24
25
|
const { dataset, contextUtil } = proxyContext;
|
|
25
|
-
const
|
|
26
|
+
const rdfType = proxyContext.getRdfType(subject);
|
|
27
|
+
const predicate = namedNode(contextUtil.keyToIri(key, rdfType));
|
|
26
28
|
// Get the Object Node
|
|
27
|
-
const object = getNodeFromRawValue(
|
|
29
|
+
const object = getNodeFromRawValue(
|
|
30
|
+
value,
|
|
31
|
+
proxyContext,
|
|
32
|
+
contextUtil.getDataType(key, rdfType),
|
|
33
|
+
);
|
|
28
34
|
if (object == undefined) {
|
|
29
35
|
dataset.deleteMatches(subject, predicate);
|
|
30
36
|
} else if (object.termType === "Literal") {
|
|
31
37
|
let languageAppliedObject = object;
|
|
32
38
|
// Handle language use case
|
|
33
|
-
if (contextUtil.isLangString(key)) {
|
|
39
|
+
if (contextUtil.isLangString(key, rdfType)) {
|
|
34
40
|
const languageKey = getLanguageKeyForWriteOperation(
|
|
35
41
|
proxyContext.languageOrdering,
|
|
36
42
|
);
|
|
@@ -76,11 +82,9 @@ export function addRawObjectToDatasetRecursive(
|
|
|
76
82
|
shouldDeleteOldTriples: boolean,
|
|
77
83
|
proxyContext: ProxyContext,
|
|
78
84
|
): SubjectProxy {
|
|
79
|
-
if (isSubjectProxy(item)) {
|
|
80
|
-
return item as SubjectProxy;
|
|
81
|
-
}
|
|
82
85
|
const { dataset } = proxyContext;
|
|
83
86
|
const subject = getNodeFromRawObject(item, proxyContext.contextUtil);
|
|
87
|
+
const rdfType = proxyContext.getRdfType(subject);
|
|
84
88
|
if (visitedObjects.has(subject)) {
|
|
85
89
|
return proxyContext.createSubjectProxy(subject);
|
|
86
90
|
}
|
|
@@ -89,9 +93,11 @@ export function addRawObjectToDatasetRecursive(
|
|
|
89
93
|
if (key === "@id") {
|
|
90
94
|
return;
|
|
91
95
|
}
|
|
92
|
-
const predicate = namedNode(
|
|
96
|
+
const predicate = namedNode(
|
|
97
|
+
proxyContext.contextUtil.keyToIri(key, rdfType),
|
|
98
|
+
);
|
|
93
99
|
if (shouldDeleteOldTriples) {
|
|
94
|
-
if (proxyContext.contextUtil.isLangString(key)) {
|
|
100
|
+
if (proxyContext.contextUtil.isLangString(key, rdfType)) {
|
|
95
101
|
const languageKey = getLanguageKeyForWriteOperation(
|
|
96
102
|
proxyContext.languageOrdering,
|
|
97
103
|
);
|
|
@@ -102,7 +108,7 @@ export function addRawObjectToDatasetRecursive(
|
|
|
102
108
|
dataset.deleteMatches(subject, predicate);
|
|
103
109
|
}
|
|
104
110
|
}
|
|
105
|
-
if (
|
|
111
|
+
if (value instanceof BasicLdSet) {
|
|
106
112
|
value.forEach((valueItem) => {
|
|
107
113
|
addRawValueToDatasetRecursive(
|
|
108
114
|
subject,
|
|
@@ -14,16 +14,19 @@ export function getNodeFromRawObject(
|
|
|
14
14
|
} else if (!item["@id"]) {
|
|
15
15
|
return blankNode();
|
|
16
16
|
} else if (typeof item["@id"] === "string") {
|
|
17
|
-
|
|
17
|
+
// Purposly do not include typeName because we don't want to reference
|
|
18
|
+
// nested context
|
|
19
|
+
return namedNode(contextUtil.keyToIri(item["@id"], []));
|
|
18
20
|
} else {
|
|
19
21
|
return item["@id"];
|
|
20
22
|
}
|
|
21
23
|
}
|
|
22
24
|
|
|
23
25
|
export function getNodeFromRawValue(
|
|
24
|
-
key: string,
|
|
25
26
|
value: RawValue,
|
|
26
27
|
proxyContext: ProxyContext,
|
|
28
|
+
// To get this run proxyContext.contextUtil.getDataType(key, proxyContext.getRdfType(subjectNode))
|
|
29
|
+
datatype?: string,
|
|
27
30
|
): BlankNode | NamedNode | Literal | undefined {
|
|
28
31
|
// Get the Object Node
|
|
29
32
|
if (value == undefined) {
|
|
@@ -33,13 +36,19 @@ export function getNodeFromRawValue(
|
|
|
33
36
|
typeof value === "boolean" ||
|
|
34
37
|
typeof value === "number"
|
|
35
38
|
) {
|
|
36
|
-
|
|
37
|
-
|
|
39
|
+
if (!datatype) {
|
|
40
|
+
return undefined;
|
|
41
|
+
} else if (datatype === "@id") {
|
|
38
42
|
return namedNode(value.toString());
|
|
39
43
|
} else {
|
|
40
44
|
return literal(value.toString(), datatype);
|
|
41
45
|
}
|
|
46
|
+
} else if (
|
|
47
|
+
typeof value.termType === "string" &&
|
|
48
|
+
(value.termType === "NamedNode" || value.termType === "BlankNode")
|
|
49
|
+
) {
|
|
50
|
+
return value as NamedNode | BlankNode;
|
|
42
51
|
} else {
|
|
43
|
-
return getNodeFromRawObject(value, proxyContext.contextUtil);
|
|
52
|
+
return getNodeFromRawObject(value as RawObject, proxyContext.contextUtil);
|
|
44
53
|
}
|
|
45
54
|
}
|
package/src/util/isProxy.ts
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import { isSetProxy } from "../setProxy/isSetProxy";
|
|
2
|
+
import type { LdSet } from "../setProxy/ldSet/LdSet";
|
|
3
|
+
import type { SetProxy } from "../setProxy/SetProxy";
|
|
3
4
|
import { isSubjectProxy } from "../subjectProxy/isSubjectProxy";
|
|
4
5
|
import type { SubjectProxy } from "../subjectProxy/SubjectProxy";
|
|
5
6
|
import type { ObjectLike } from "../types";
|
|
6
7
|
|
|
7
8
|
export function isProxy(
|
|
8
9
|
someObject?: unknown,
|
|
9
|
-
): someObject is
|
|
10
|
-
return isSubjectProxy(someObject) ||
|
|
10
|
+
): someObject is SetProxy | SubjectProxy {
|
|
11
|
+
return isSubjectProxy(someObject) || isSetProxy(someObject);
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
export function getProxyFromObject(
|
|
14
|
-
object: ObjectLike | ObjectLike
|
|
15
|
-
): SubjectProxy |
|
|
15
|
+
object: ObjectLike | LdSet<ObjectLike>,
|
|
16
|
+
): SubjectProxy | SetProxy {
|
|
16
17
|
if (!isProxy(object)) {
|
|
17
18
|
throw new Error(`${object} is not a Jsonld Dataset Proxy`);
|
|
18
19
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { Literal, Quad_Object } from "@rdfjs/types";
|
|
2
2
|
import type { ProxyContext } from "../ProxyContext";
|
|
3
3
|
import type { SubjectProxy } from "../subjectProxy/SubjectProxy";
|
|
4
|
+
import type { LiteralLike } from "../types";
|
|
4
5
|
|
|
5
|
-
export type ObjectJsonRepresentation =
|
|
6
|
+
export type ObjectJsonRepresentation = LiteralLike | SubjectProxy;
|
|
6
7
|
|
|
7
8
|
export function literalToJsonldRepresentation(literal: Literal) {
|
|
8
9
|
switch (literal.datatype.value) {
|
|
@@ -66,7 +67,7 @@ export function literalToJsonldRepresentation(literal: Literal) {
|
|
|
66
67
|
export function nodeToJsonldRepresentation(
|
|
67
68
|
node: Quad_Object,
|
|
68
69
|
proxyContext: ProxyContext,
|
|
69
|
-
):
|
|
70
|
+
): ObjectJsonRepresentation {
|
|
70
71
|
if (node.termType === "Literal") {
|
|
71
72
|
return literalToJsonldRepresentation(node);
|
|
72
73
|
} else if (node.termType === "NamedNode" || node.termType === "BlankNode") {
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { Dataset } from "@rdfjs/types";
|
|
2
|
-
import type { ObjectNode } from "@ldo/rdf-utils";
|
|
3
|
-
import type { ArrayProxyTarget } from "./createArrayHandler";
|
|
4
|
-
import type {
|
|
5
|
-
_getNodeAtIndex,
|
|
6
|
-
_getUnderlyingArrayTarget,
|
|
7
|
-
_getUnderlyingDataset,
|
|
8
|
-
_getUnderlyingMatch,
|
|
9
|
-
_proxyContext,
|
|
10
|
-
} from "../types";
|
|
11
|
-
import { _getUnderlyingNode } from "../types";
|
|
12
|
-
import type { ProxyContext } from "../ProxyContext";
|
|
13
|
-
|
|
14
|
-
export type ArrayProxy = Array<unknown> & {
|
|
15
|
-
readonly [_getUnderlyingDataset]: Dataset;
|
|
16
|
-
readonly [_getUnderlyingMatch]: ArrayProxyTarget[0];
|
|
17
|
-
readonly [_getNodeAtIndex]: (index: number) => ObjectNode | undefined;
|
|
18
|
-
readonly [_getUnderlyingArrayTarget]: ArrayProxyTarget;
|
|
19
|
-
[_proxyContext]: ProxyContext;
|
|
20
|
-
};
|
|
@@ -1,219 +0,0 @@
|
|
|
1
|
-
import type { ArrayProxyTarget } from "./createArrayHandler";
|
|
2
|
-
import type { ObjectJsonRepresentation } from "../util/nodeToJsonldRepresentation";
|
|
3
|
-
import { nodeToJsonldRepresentation } from "../util/nodeToJsonldRepresentation";
|
|
4
|
-
import { modifyArray } from "./modifyArray";
|
|
5
|
-
import type { ProxyContext } from "../ProxyContext";
|
|
6
|
-
|
|
7
|
-
export type methodBuilder<Return> = (
|
|
8
|
-
target: ArrayProxyTarget,
|
|
9
|
-
key: string,
|
|
10
|
-
proxyContext: ProxyContext,
|
|
11
|
-
) => Return;
|
|
12
|
-
|
|
13
|
-
export interface ArrayMethodBuildersType {
|
|
14
|
-
copyWithin: methodBuilder<Array<ObjectJsonRepresentation>["copyWithin"]>;
|
|
15
|
-
fill: methodBuilder<Array<ObjectJsonRepresentation>["fill"]>;
|
|
16
|
-
pop: methodBuilder<Array<ObjectJsonRepresentation>["pop"]>;
|
|
17
|
-
push: methodBuilder<Array<ObjectJsonRepresentation>["push"]>;
|
|
18
|
-
reverse: methodBuilder<Array<ObjectJsonRepresentation>["reverse"]>;
|
|
19
|
-
shift: methodBuilder<Array<ObjectJsonRepresentation>["shift"]>;
|
|
20
|
-
sort: methodBuilder<Array<ObjectJsonRepresentation>["sort"]>;
|
|
21
|
-
splice: methodBuilder<Array<ObjectJsonRepresentation>["splice"]>;
|
|
22
|
-
unshift: methodBuilder<Array<ObjectJsonRepresentation>["unshift"]>;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export const methodNames: Set<keyof ArrayMethodBuildersType> = new Set([
|
|
26
|
-
"copyWithin",
|
|
27
|
-
"fill",
|
|
28
|
-
"pop",
|
|
29
|
-
"push",
|
|
30
|
-
"reverse",
|
|
31
|
-
"shift",
|
|
32
|
-
"sort",
|
|
33
|
-
"splice",
|
|
34
|
-
"unshift",
|
|
35
|
-
]);
|
|
36
|
-
|
|
37
|
-
export const arrayMethodsBuilders: ArrayMethodBuildersType = {
|
|
38
|
-
copyWithin: (target, key, proxyContext) => {
|
|
39
|
-
return (targetIndex, start, end) => {
|
|
40
|
-
return modifyArray(
|
|
41
|
-
{
|
|
42
|
-
target,
|
|
43
|
-
key,
|
|
44
|
-
quadsToDelete: (quads) => {
|
|
45
|
-
const oldQuads = [...quads];
|
|
46
|
-
const newQuadSet = new Set(
|
|
47
|
-
quads.copyWithin(targetIndex, start, end),
|
|
48
|
-
);
|
|
49
|
-
return oldQuads.filter((oldQuad) => !newQuadSet.has(oldQuad));
|
|
50
|
-
},
|
|
51
|
-
modifyCoreArray: (coreArray) => {
|
|
52
|
-
coreArray.copyWithin(targetIndex, start, end);
|
|
53
|
-
return proxyContext.createArrayProxy(
|
|
54
|
-
target[0],
|
|
55
|
-
target[2],
|
|
56
|
-
) as ObjectJsonRepresentation[];
|
|
57
|
-
},
|
|
58
|
-
},
|
|
59
|
-
proxyContext,
|
|
60
|
-
);
|
|
61
|
-
};
|
|
62
|
-
},
|
|
63
|
-
fill: (target, key, proxyContext) => {
|
|
64
|
-
return (value, start, end) => {
|
|
65
|
-
return modifyArray(
|
|
66
|
-
{
|
|
67
|
-
target,
|
|
68
|
-
key,
|
|
69
|
-
toAdd: [value],
|
|
70
|
-
quadsToDelete: (quads) => {
|
|
71
|
-
return quads.slice(start, end);
|
|
72
|
-
},
|
|
73
|
-
modifyCoreArray: (coreArray, addedValues) => {
|
|
74
|
-
coreArray.fill(addedValues[0], start, end);
|
|
75
|
-
return proxyContext.createArrayProxy(
|
|
76
|
-
target[0],
|
|
77
|
-
target[2],
|
|
78
|
-
) as ObjectJsonRepresentation[];
|
|
79
|
-
},
|
|
80
|
-
},
|
|
81
|
-
proxyContext,
|
|
82
|
-
);
|
|
83
|
-
};
|
|
84
|
-
},
|
|
85
|
-
pop: (target, key, proxyContext) => {
|
|
86
|
-
return () => {
|
|
87
|
-
return modifyArray(
|
|
88
|
-
{
|
|
89
|
-
target,
|
|
90
|
-
key,
|
|
91
|
-
quadsToDelete: (quads) => {
|
|
92
|
-
return quads[quads.length - 1] ? [quads[quads.length - 1]] : [];
|
|
93
|
-
},
|
|
94
|
-
modifyCoreArray: (coreArray) => {
|
|
95
|
-
const popped = coreArray.pop();
|
|
96
|
-
return popped
|
|
97
|
-
? nodeToJsonldRepresentation(popped, proxyContext)
|
|
98
|
-
: undefined;
|
|
99
|
-
},
|
|
100
|
-
},
|
|
101
|
-
proxyContext,
|
|
102
|
-
);
|
|
103
|
-
};
|
|
104
|
-
},
|
|
105
|
-
push: (target, key, proxyContext) => {
|
|
106
|
-
return (...args) => {
|
|
107
|
-
return modifyArray(
|
|
108
|
-
{
|
|
109
|
-
target,
|
|
110
|
-
key,
|
|
111
|
-
toAdd: args,
|
|
112
|
-
modifyCoreArray: (coreArray, addedValues) => {
|
|
113
|
-
coreArray.push(...addedValues);
|
|
114
|
-
return proxyContext.createArrayProxy(target[0], target[2]).length;
|
|
115
|
-
},
|
|
116
|
-
},
|
|
117
|
-
proxyContext,
|
|
118
|
-
);
|
|
119
|
-
};
|
|
120
|
-
},
|
|
121
|
-
reverse: (target, _key, proxyContext) => {
|
|
122
|
-
return () => {
|
|
123
|
-
target[1].reverse();
|
|
124
|
-
return proxyContext.createArrayProxy(
|
|
125
|
-
target[0],
|
|
126
|
-
target[2],
|
|
127
|
-
) as ObjectJsonRepresentation[];
|
|
128
|
-
};
|
|
129
|
-
},
|
|
130
|
-
shift: (target, key, proxyContext) => {
|
|
131
|
-
return () => {
|
|
132
|
-
return modifyArray(
|
|
133
|
-
{
|
|
134
|
-
target,
|
|
135
|
-
key,
|
|
136
|
-
quadsToDelete: (quads) => {
|
|
137
|
-
return quads[0] ? [quads[0]] : [];
|
|
138
|
-
},
|
|
139
|
-
modifyCoreArray: (coreArray) => {
|
|
140
|
-
const shifted = coreArray.shift();
|
|
141
|
-
return shifted
|
|
142
|
-
? nodeToJsonldRepresentation(shifted, proxyContext)
|
|
143
|
-
: undefined;
|
|
144
|
-
},
|
|
145
|
-
},
|
|
146
|
-
proxyContext,
|
|
147
|
-
);
|
|
148
|
-
};
|
|
149
|
-
},
|
|
150
|
-
sort: (target, _key, proxyContext) => {
|
|
151
|
-
return (compareFunction) => {
|
|
152
|
-
if (compareFunction) {
|
|
153
|
-
target[1].sort((a, b) => {
|
|
154
|
-
return compareFunction(
|
|
155
|
-
nodeToJsonldRepresentation(a, proxyContext),
|
|
156
|
-
nodeToJsonldRepresentation(b, proxyContext),
|
|
157
|
-
);
|
|
158
|
-
});
|
|
159
|
-
} else if (target) {
|
|
160
|
-
target[1].sort((a, b) => {
|
|
161
|
-
const aReal = nodeToJsonldRepresentation(a, proxyContext);
|
|
162
|
-
const bReal = nodeToJsonldRepresentation(b, proxyContext);
|
|
163
|
-
if (aReal > bReal) {
|
|
164
|
-
return 1;
|
|
165
|
-
} else if (bReal > aReal) {
|
|
166
|
-
return -1;
|
|
167
|
-
} else {
|
|
168
|
-
return 0;
|
|
169
|
-
}
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
return proxyContext.createArrayProxy(
|
|
173
|
-
target[0],
|
|
174
|
-
target[2],
|
|
175
|
-
) as ObjectJsonRepresentation[];
|
|
176
|
-
};
|
|
177
|
-
},
|
|
178
|
-
splice: (target, key, proxyContext) => {
|
|
179
|
-
return (start, deleteCount, ...items: ObjectJsonRepresentation[]) => {
|
|
180
|
-
return modifyArray(
|
|
181
|
-
{
|
|
182
|
-
target,
|
|
183
|
-
key,
|
|
184
|
-
toAdd: items,
|
|
185
|
-
quadsToDelete: (quads) => {
|
|
186
|
-
return quads.splice(start, deleteCount);
|
|
187
|
-
},
|
|
188
|
-
modifyCoreArray: (coreArray, addedValues) => {
|
|
189
|
-
const spliced = coreArray.splice(
|
|
190
|
-
start,
|
|
191
|
-
deleteCount || 0,
|
|
192
|
-
...addedValues,
|
|
193
|
-
);
|
|
194
|
-
return spliced.map((node) => {
|
|
195
|
-
return nodeToJsonldRepresentation(node, proxyContext);
|
|
196
|
-
});
|
|
197
|
-
},
|
|
198
|
-
},
|
|
199
|
-
proxyContext,
|
|
200
|
-
);
|
|
201
|
-
};
|
|
202
|
-
},
|
|
203
|
-
unshift: (target, key, proxyContext) => {
|
|
204
|
-
return (...args) => {
|
|
205
|
-
return modifyArray(
|
|
206
|
-
{
|
|
207
|
-
target,
|
|
208
|
-
key,
|
|
209
|
-
toAdd: args,
|
|
210
|
-
modifyCoreArray: (coreArray, addedValues) => {
|
|
211
|
-
coreArray.unshift(...addedValues);
|
|
212
|
-
return proxyContext.createArrayProxy(target[0], target[2]).length;
|
|
213
|
-
},
|
|
214
|
-
},
|
|
215
|
-
proxyContext,
|
|
216
|
-
);
|
|
217
|
-
};
|
|
218
|
-
},
|
|
219
|
-
};
|