n3 1.22.0 → 1.22.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/browser/n3.min.js +1 -1
- package/lib/N3Store.js +42 -0
- package/package.json +1 -1
- package/src/N3Store.js +44 -0
package/lib/N3Store.js
CHANGED
|
@@ -47,6 +47,37 @@ function intersect(s1, s2, depth = 4) {
|
|
|
47
47
|
return target;
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
+
/**
|
|
51
|
+
* Determines the difference of the `_graphs` index s1 and s2.
|
|
52
|
+
* s1 and s2 *must* belong to Stores that share an `_entityIndex`.
|
|
53
|
+
*
|
|
54
|
+
* False is returned when there is no difference; this should
|
|
55
|
+
* *not* be set as the value for an index.
|
|
56
|
+
*/
|
|
57
|
+
function difference(s1, s2, depth = 4) {
|
|
58
|
+
let target = false;
|
|
59
|
+
for (const key in s1) {
|
|
60
|
+
// When the key is not in the index, then none of the triples defined by s1[key] are
|
|
61
|
+
// in s2 and so we want to copy them over to the resultant store.
|
|
62
|
+
if (!(key in s2)) {
|
|
63
|
+
target = target || Object.create(null);
|
|
64
|
+
target[key] = depth === 0 ? null : merge({}, s1[key], depth - 1);
|
|
65
|
+
} else if (depth !== 0) {
|
|
66
|
+
const diff = difference(s1[key], s2[key], depth - 1);
|
|
67
|
+
if (diff !== false) {
|
|
68
|
+
target = target || Object.create(null);
|
|
69
|
+
target[key] = diff;
|
|
70
|
+
}
|
|
71
|
+
// Depth 3 is the 'subjects', 'predicates' and 'objects' keys.
|
|
72
|
+
// If the 'subjects' index is empty, so will the 'predicates' and 'objects' index.
|
|
73
|
+
else if (depth === 3) {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return target;
|
|
79
|
+
}
|
|
80
|
+
|
|
50
81
|
// ## Constructor
|
|
51
82
|
class N3EntityIndex {
|
|
52
83
|
constructor(options = {}) {
|
|
@@ -842,6 +873,17 @@ class N3Store {
|
|
|
842
873
|
if (other === this) return new N3Store({
|
|
843
874
|
entityIndex: this._entityIndex
|
|
844
875
|
});
|
|
876
|
+
if (other instanceof N3Store && other._entityIndex === this._entityIndex) {
|
|
877
|
+
const store = new N3Store({
|
|
878
|
+
entityIndex: this._entityIndex
|
|
879
|
+
});
|
|
880
|
+
const graphs = difference(this._graphs, other._graphs);
|
|
881
|
+
if (graphs) {
|
|
882
|
+
store._graphs = graphs;
|
|
883
|
+
store._size = null;
|
|
884
|
+
}
|
|
885
|
+
return store;
|
|
886
|
+
}
|
|
845
887
|
return this.filter(quad => !other.has(quad));
|
|
846
888
|
}
|
|
847
889
|
|
package/package.json
CHANGED
package/src/N3Store.js
CHANGED
|
@@ -45,6 +45,40 @@ function intersect(s1, s2, depth = 4) {
|
|
|
45
45
|
return target;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
+
/**
|
|
49
|
+
* Determines the difference of the `_graphs` index s1 and s2.
|
|
50
|
+
* s1 and s2 *must* belong to Stores that share an `_entityIndex`.
|
|
51
|
+
*
|
|
52
|
+
* False is returned when there is no difference; this should
|
|
53
|
+
* *not* be set as the value for an index.
|
|
54
|
+
*/
|
|
55
|
+
function difference(s1, s2, depth = 4) {
|
|
56
|
+
let target = false;
|
|
57
|
+
|
|
58
|
+
for (const key in s1) {
|
|
59
|
+
// When the key is not in the index, then none of the triples defined by s1[key] are
|
|
60
|
+
// in s2 and so we want to copy them over to the resultant store.
|
|
61
|
+
if (!(key in s2)) {
|
|
62
|
+
target = target || Object.create(null);
|
|
63
|
+
target[key] = depth === 0 ? null : merge({}, s1[key], depth - 1);
|
|
64
|
+
}
|
|
65
|
+
else if (depth !== 0) {
|
|
66
|
+
const diff = difference(s1[key], s2[key], depth - 1);
|
|
67
|
+
if (diff !== false) {
|
|
68
|
+
target = target || Object.create(null);
|
|
69
|
+
target[key] = diff;
|
|
70
|
+
}
|
|
71
|
+
// Depth 3 is the 'subjects', 'predicates' and 'objects' keys.
|
|
72
|
+
// If the 'subjects' index is empty, so will the 'predicates' and 'objects' index.
|
|
73
|
+
else if (depth === 3) {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return target;
|
|
80
|
+
}
|
|
81
|
+
|
|
48
82
|
// ## Constructor
|
|
49
83
|
export class N3EntityIndex {
|
|
50
84
|
constructor(options = {}) {
|
|
@@ -896,6 +930,16 @@ export default class N3Store {
|
|
|
896
930
|
if (other === this)
|
|
897
931
|
return new N3Store({ entityIndex: this._entityIndex });
|
|
898
932
|
|
|
933
|
+
if ((other instanceof N3Store) && other._entityIndex === this._entityIndex) {
|
|
934
|
+
const store = new N3Store({ entityIndex: this._entityIndex });
|
|
935
|
+
const graphs = difference(this._graphs, other._graphs);
|
|
936
|
+
if (graphs) {
|
|
937
|
+
store._graphs = graphs;
|
|
938
|
+
store._size = null;
|
|
939
|
+
}
|
|
940
|
+
return store;
|
|
941
|
+
}
|
|
942
|
+
|
|
899
943
|
return this.filter(quad => !other.has(quad));
|
|
900
944
|
}
|
|
901
945
|
|