@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.
Files changed (113) hide show
  1. package/README.md +86 -71
  2. package/dist/ContextUtil.d.ts +12 -7
  3. package/dist/ContextUtil.js +69 -31
  4. package/dist/ContextUtil.js.map +1 -1
  5. package/dist/JsonldDatasetProxyBuilder.d.ts +4 -3
  6. package/dist/JsonldDatasetProxyBuilder.js +2 -2
  7. package/dist/JsonldDatasetProxyBuilder.js.map +1 -1
  8. package/dist/ProxyContext.d.ts +9 -9
  9. package/dist/ProxyContext.js +23 -25
  10. package/dist/ProxyContext.js.map +1 -1
  11. package/dist/arrayProxy/modifyArray.js +2 -2
  12. package/dist/arrayProxy/modifyArray.js.map +1 -1
  13. package/dist/graphOf.d.ts +2 -1
  14. package/dist/graphOf.js +4 -16
  15. package/dist/graphOf.js.map +1 -1
  16. package/dist/index.d.ts +7 -5
  17. package/dist/index.js +7 -5
  18. package/dist/index.js.map +1 -1
  19. package/dist/jsonldDatasetProxy.d.ts +2 -1
  20. package/dist/jsonldDatasetProxy.js.map +1 -1
  21. package/dist/language/languagesOf.d.ts +2 -1
  22. package/dist/language/languagesOf.js +3 -2
  23. package/dist/language/languagesOf.js.map +1 -1
  24. package/dist/setProxy/ObjectSetProxy.d.ts +17 -0
  25. package/dist/setProxy/ObjectSetProxy.js +31 -0
  26. package/dist/setProxy/ObjectSetProxy.js.map +1 -0
  27. package/dist/setProxy/SetProxy.d.ts +29 -0
  28. package/dist/setProxy/SetProxy.js +72 -0
  29. package/dist/setProxy/SetProxy.js.map +1 -0
  30. package/dist/setProxy/SubjectSetProxy.d.ts +15 -0
  31. package/dist/setProxy/SubjectSetProxy.js +38 -0
  32. package/dist/setProxy/SubjectSetProxy.js.map +1 -0
  33. package/dist/setProxy/WildcardObjectSetProxy.d.ts +20 -0
  34. package/dist/setProxy/WildcardObjectSetProxy.js +49 -0
  35. package/dist/setProxy/WildcardObjectSetProxy.js.map +1 -0
  36. package/dist/setProxy/WildcardSubjectSetProxy.d.ts +19 -0
  37. package/dist/setProxy/WildcardSubjectSetProxy.js +31 -0
  38. package/dist/setProxy/WildcardSubjectSetProxy.js.map +1 -0
  39. package/dist/setProxy/createNewSetProxy.d.ts +5 -0
  40. package/dist/setProxy/createNewSetProxy.js +27 -0
  41. package/dist/setProxy/createNewSetProxy.js.map +1 -0
  42. package/dist/setProxy/isSetProxy.d.ts +2 -0
  43. package/dist/setProxy/isSetProxy.js +13 -0
  44. package/dist/setProxy/isSetProxy.js.map +1 -0
  45. package/dist/setProxy/ldSet/BasicLdSet.d.ts +36 -0
  46. package/dist/setProxy/ldSet/BasicLdSet.js +193 -0
  47. package/dist/setProxy/ldSet/BasicLdSet.js.map +1 -0
  48. package/dist/setProxy/ldSet/LdSet.d.ts +30 -0
  49. package/dist/setProxy/ldSet/LdSet.js +3 -0
  50. package/dist/setProxy/ldSet/LdSet.js.map +1 -0
  51. package/dist/setProxy/set.d.ts +2 -0
  52. package/dist/setProxy/set.js +9 -0
  53. package/dist/setProxy/set.js.map +1 -0
  54. package/dist/subjectProxy/SubjectProxy.d.ts +1 -1
  55. package/dist/subjectProxy/createSubjectHandler.js +7 -5
  56. package/dist/subjectProxy/createSubjectHandler.js.map +1 -1
  57. package/dist/subjectProxy/deleteFromDataset.js +6 -25
  58. package/dist/subjectProxy/deleteFromDataset.js.map +1 -1
  59. package/dist/subjectProxy/getValueForKey.d.ts +2 -2
  60. package/dist/subjectProxy/getValueForKey.js +7 -9
  61. package/dist/subjectProxy/getValueForKey.js.map +1 -1
  62. package/dist/types.d.ts +2 -2
  63. package/dist/types.js +2 -3
  64. package/dist/types.js.map +1 -1
  65. package/dist/util/NodeSet.d.ts +0 -2
  66. package/dist/util/NodeSet.js +0 -10
  67. package/dist/util/NodeSet.js.map +1 -1
  68. package/dist/util/RawObject.d.ts +3 -2
  69. package/dist/util/addObjectToDataset.js +9 -9
  70. package/dist/util/addObjectToDataset.js.map +1 -1
  71. package/dist/util/getNodeFromRaw.d.ts +1 -1
  72. package/dist/util/getNodeFromRaw.js +10 -4
  73. package/dist/util/getNodeFromRaw.js.map +1 -1
  74. package/dist/util/isProxy.d.ts +4 -3
  75. package/dist/util/isProxy.js +2 -2
  76. package/dist/util/isProxy.js.map +1 -1
  77. package/dist/util/nodeToJsonldRepresentation.d.ts +3 -2
  78. package/dist/util/nodeToJsonldRepresentation.js.map +1 -1
  79. package/package.json +5 -5
  80. package/src/ContextUtil.ts +118 -35
  81. package/src/JsonldDatasetProxyBuilder.ts +14 -13
  82. package/src/LdoJsonldContext.ts +14 -0
  83. package/src/ProxyContext.ts +47 -39
  84. package/src/graphOf.ts +16 -27
  85. package/src/index.ts +7 -5
  86. package/src/jsonldDatasetProxy.ts +2 -1
  87. package/src/language/languagesOf.ts +7 -3
  88. package/src/setProxy/ObjectSetProxy.ts +66 -0
  89. package/src/setProxy/SetProxy.ts +141 -0
  90. package/src/setProxy/SubjectSetProxy.ts +85 -0
  91. package/src/setProxy/WildcardObjectSetProxy.ts +89 -0
  92. package/src/setProxy/WildcardSubjectSetProxy.ts +58 -0
  93. package/src/setProxy/createNewSetProxy.ts +47 -0
  94. package/src/setProxy/isSetProxy.ts +7 -0
  95. package/src/setProxy/ldSet/BasicLdSet.ts +266 -0
  96. package/src/setProxy/ldSet/LdSet.ts +189 -0
  97. package/src/setProxy/set.ts +14 -0
  98. package/src/subjectProxy/SubjectProxy.ts +1 -1
  99. package/src/subjectProxy/createSubjectHandler.ts +15 -6
  100. package/src/subjectProxy/deleteFromDataset.ts +12 -23
  101. package/src/subjectProxy/getValueForKey.ts +12 -12
  102. package/src/types.ts +2 -2
  103. package/src/util/NodeSet.ts +0 -12
  104. package/src/util/RawObject.ts +10 -2
  105. package/src/util/addObjectToDataset.ts +15 -9
  106. package/src/util/getNodeFromRaw.ts +14 -5
  107. package/src/util/isProxy.ts +7 -6
  108. package/src/util/nodeToJsonldRepresentation.ts +3 -2
  109. package/src/arrayProxy/ArrayProxy.ts +0 -20
  110. package/src/arrayProxy/arrayMethods.ts +0 -219
  111. package/src/arrayProxy/createArrayHandler.ts +0 -177
  112. package/src/arrayProxy/isArrayProxy.ts +0 -23
  113. package/src/arrayProxy/modifyArray.ts +0 -133
@@ -0,0 +1,58 @@
1
+ import type {
2
+ SubjectNode,
3
+ PredicateNode,
4
+ ObjectNode,
5
+ GraphNode,
6
+ } from "@ldo/rdf-utils";
7
+ import type { Dataset, Quad } from "@rdfjs/types";
8
+ import type { RawObject } from "../util/RawObject";
9
+ import { SetProxy } from "./SetProxy";
10
+ import type { ProxyContext } from "../ProxyContext";
11
+ import { getNodeFromRawObject } from "../util/getNodeFromRaw";
12
+ import { _isSubjectOriented } from "../types";
13
+
14
+ export type WildcardSubjectSetProxyQuadMatch = [
15
+ undefined | null,
16
+ PredicateNode | undefined | null,
17
+ ObjectNode | undefined | null,
18
+ GraphNode | undefined | null,
19
+ ];
20
+
21
+ /**
22
+ * A WildcardObjectProxy represents a set of nodes in a dataset that are all the
23
+ * object of a given subject and predicate. Because this is a wildcard, the
24
+ * subject and predicate don't necissarily need to be defined.
25
+ */
26
+ export class WildcardSubjectSetProxy<T extends RawObject> extends SetProxy<T> {
27
+ protected quadMatch: WildcardSubjectSetProxyQuadMatch;
28
+
29
+ constructor(
30
+ context: ProxyContext,
31
+ quadMatch: WildcardSubjectSetProxyQuadMatch,
32
+ ) {
33
+ super(context, quadMatch);
34
+ this.quadMatch = quadMatch;
35
+ }
36
+
37
+ protected getQuads(value?: T | undefined): Dataset<Quad, Quad> {
38
+ const { dataset } = this.context;
39
+ // Get the RDF Node that represents the value, skip is no value
40
+ const predicate = this.quadMatch[1];
41
+ const object = this.quadMatch[2];
42
+ const graph = this.quadMatch[3];
43
+ if (value) {
44
+ const valueNode = getNodeFromRawObject(value, this.context.contextUtil);
45
+ return dataset.match(valueNode, predicate, object, graph);
46
+ }
47
+ // SPO for no value
48
+ return dataset.match(undefined, predicate, object, graph);
49
+ }
50
+
51
+ protected getNodeOfFocus(quad: Quad): SubjectNode {
52
+ return quad.subject as SubjectNode;
53
+ }
54
+
55
+ get [_isSubjectOriented](): true {
56
+ return true;
57
+ }
58
+ }
@@ -0,0 +1,47 @@
1
+ import type { QuadMatch } from "@ldo/rdf-utils";
2
+ import type { ProxyContext } from "../ProxyContext";
3
+ import type { RawObject, RawValue } from "../util/RawObject";
4
+ import type { ObjectSetProxyQuadMatch } from "./ObjectSetProxy";
5
+ import { ObjectSetProxy } from "./ObjectSetProxy";
6
+ import type { SubjectSetProxyQuadMatch } from "./SubjectSetProxy";
7
+ import { SubjectSetProxy } from "./SubjectSetProxy";
8
+ import type { WildcardObjectSetProxyQuadMatch } from "./WildcardObjectSetProxy";
9
+ import { WildcardObjectSetProxy } from "./WildcardObjectSetProxy";
10
+ import type { WildcardSubjectSetProxyQuadMatch } from "./WildcardSubjectSetProxy";
11
+ import { WildcardSubjectSetProxy } from "./WildcardSubjectSetProxy";
12
+ import type { SetProxy } from "./SetProxy";
13
+
14
+ export function createNewSetProxy<T extends NonNullable<RawValue>>(
15
+ quadMatch: QuadMatch,
16
+ isSubjectOriented: boolean,
17
+ proxyContext: ProxyContext,
18
+ isLangSet?: boolean,
19
+ ): SetProxy<T> {
20
+ if (!isSubjectOriented) {
21
+ if (quadMatch[0] && quadMatch[1]) {
22
+ return new ObjectSetProxy<T>(
23
+ proxyContext,
24
+ quadMatch as ObjectSetProxyQuadMatch,
25
+ isLangSet,
26
+ );
27
+ } else {
28
+ return new WildcardObjectSetProxy<T>(
29
+ proxyContext,
30
+ quadMatch as WildcardObjectSetProxyQuadMatch,
31
+ isLangSet,
32
+ );
33
+ }
34
+ } else {
35
+ if (quadMatch[1] && quadMatch[2]) {
36
+ return new SubjectSetProxy<T & RawObject>(
37
+ proxyContext,
38
+ quadMatch as SubjectSetProxyQuadMatch,
39
+ );
40
+ } else {
41
+ return new WildcardSubjectSetProxy<T & RawObject>(
42
+ proxyContext,
43
+ quadMatch as WildcardSubjectSetProxyQuadMatch,
44
+ );
45
+ }
46
+ }
47
+ }
@@ -0,0 +1,7 @@
1
+ import { SetProxy } from "./SetProxy";
2
+
3
+ export function isSetProxy(someObject?: unknown): someObject is SetProxy {
4
+ if (!someObject) return false;
5
+ if (typeof someObject !== "object") return false;
6
+ return someObject instanceof SetProxy;
7
+ }
@@ -0,0 +1,266 @@
1
+ import type { BlankNode, NamedNode } from "@rdfjs/types";
2
+ import { _getUnderlyingNode } from "../../types";
3
+ import type { RawValue } from "../../util/RawObject";
4
+ import type { LdSet } from "./LdSet";
5
+ import { blankNode } from "@rdfjs/data-model";
6
+
7
+ /* eslint-disable @typescript-eslint/no-explicit-any */
8
+ export class BasicLdSet<T extends NonNullable<RawValue> = NonNullable<RawValue>>
9
+ implements LdSet<T>
10
+ {
11
+ private hashMap: Map<string, T>;
12
+
13
+ constructor(values?: Iterable<T> | null) {
14
+ this.hashMap = new Map();
15
+ if (values) {
16
+ for (const value of values) {
17
+ this.add(value);
18
+ }
19
+ }
20
+ }
21
+
22
+ private hashFn(value: T): string {
23
+ if (typeof value !== "object") return value.toString();
24
+ if (value[_getUnderlyingNode]) {
25
+ return (value[_getUnderlyingNode] as NamedNode | BlankNode).value;
26
+ } else if (!value["@id"]) {
27
+ return blankNode().value;
28
+ } else if (typeof value["@id"] === "string") {
29
+ return value["@id"];
30
+ } else {
31
+ return value["@id"].value;
32
+ }
33
+ }
34
+
35
+ /**
36
+ * ===========================================================================
37
+ * Base Set Functions
38
+ * ===========================================================================
39
+ */
40
+
41
+ add(value: T): this {
42
+ const key = this.hashFn(value);
43
+ if (!this.hashMap.has(key)) {
44
+ this.hashMap.set(key, value);
45
+ }
46
+ return this;
47
+ }
48
+
49
+ clear(): void {
50
+ this.hashMap.clear();
51
+ }
52
+
53
+ delete(value: T): boolean {
54
+ const key = this.hashFn(value);
55
+ return this.hashMap.delete(key);
56
+ }
57
+
58
+ has(value: T): boolean {
59
+ const key = this.hashFn(value);
60
+ return this.hashMap.has(key);
61
+ }
62
+
63
+ get size(): number {
64
+ return this.hashMap.size;
65
+ }
66
+
67
+ *entries(): IterableIterator<[T, T]> {
68
+ for (const [, value] of this.hashMap.entries()) {
69
+ yield [value, value];
70
+ }
71
+ }
72
+
73
+ keys(): IterableIterator<T> {
74
+ return this.hashMap.values();
75
+ }
76
+
77
+ values(): IterableIterator<T> {
78
+ return this.hashMap.values();
79
+ }
80
+ [Symbol.iterator](): IterableIterator<T> {
81
+ return this.hashMap.values();
82
+ }
83
+
84
+ get [Symbol.toStringTag]() {
85
+ // TODO: Change this to be human readable.
86
+ return "BasicLdSet";
87
+ }
88
+
89
+ /**
90
+ * ===========================================================================
91
+ * Array Functions
92
+ * ===========================================================================
93
+ */
94
+
95
+ every<S extends T>(
96
+ predicate: (value: T, set: LdSet<T>) => value is S,
97
+ thisArg?: any,
98
+ ): this is LdSet<S>;
99
+ every(
100
+ predicate: (value: T, set: LdSet<T>) => unknown,
101
+ thisArg?: any,
102
+ ): boolean;
103
+ every(predicate: (value: T, set: LdSet<T>) => any, thisArg?: any): boolean {
104
+ for (const value of this) {
105
+ if (!predicate.call(thisArg, value, this)) return false;
106
+ }
107
+ return true;
108
+ }
109
+
110
+ some(
111
+ predicate: (value: T, set: LdSet<T>) => unknown,
112
+ thisArg?: any,
113
+ ): boolean {
114
+ for (const value of this) {
115
+ if (predicate.call(thisArg, value, this)) return true;
116
+ }
117
+ return false;
118
+ }
119
+
120
+ forEach(
121
+ callbackfn: (value: T, value2: T, set: LdSet<T>) => void,
122
+ thisArg?: any,
123
+ ): void {
124
+ for (const value of this) {
125
+ callbackfn.call(thisArg, value, value, this);
126
+ }
127
+ }
128
+
129
+ map<U>(callbackfn: (value: T, set: LdSet<T>) => U, thisArg?: any): U[] {
130
+ const returnValues: U[] = [];
131
+ for (const value of this) {
132
+ returnValues.push(callbackfn.call(thisArg, value, this));
133
+ }
134
+ return returnValues;
135
+ }
136
+
137
+ filter<S extends T>(
138
+ predicate: (value: T, set: LdSet<T>) => value is S,
139
+ thisArg?: any,
140
+ ): LdSet<S>;
141
+ filter(
142
+ predicate: (value: T, set: LdSet<T>) => unknown,
143
+ thisArg?: any,
144
+ ): LdSet<T>;
145
+ filter(
146
+ predicate: (value: T, set: LdSet<T>) => any,
147
+ thisArg?: unknown,
148
+ ): LdSet<T> {
149
+ const newSet = new BasicLdSet<T>();
150
+ for (const value of this) {
151
+ if (predicate.call(thisArg, value, this)) newSet.add(value);
152
+ }
153
+ return newSet;
154
+ }
155
+
156
+ reduce(
157
+ callbackfn: (previousValue: T, currentValue: T, set: LdSet<T>) => T,
158
+ ): T;
159
+ reduce(
160
+ callbackfn: (previousValue: T, currentValue: T, set: LdSet<T>) => T,
161
+ initialValue: T,
162
+ ): T;
163
+ reduce<U>(
164
+ callbackfn: (previousValue: U, currentValue: T, set: LdSet<T>) => U,
165
+ initialValue: U,
166
+ ): U;
167
+ reduce(callbackfn: any, initialValue?: any): any {
168
+ const iterator = this[Symbol.iterator]();
169
+ let accumulator;
170
+
171
+ if (initialValue === undefined) {
172
+ const first = iterator.next();
173
+ if (first.done) {
174
+ throw new TypeError("Reduce of empty collection with no initial value");
175
+ }
176
+ accumulator = first.value;
177
+ } else {
178
+ accumulator = initialValue;
179
+ }
180
+
181
+ let result = iterator.next();
182
+ while (!result.done) {
183
+ accumulator = callbackfn(accumulator, result.value, this);
184
+ result = iterator.next();
185
+ }
186
+
187
+ return accumulator;
188
+ }
189
+
190
+ toArray(): T[] {
191
+ const arr: T[] = [];
192
+ this.forEach((value) => arr.push(value));
193
+ return arr;
194
+ }
195
+
196
+ toJSON(): T[] {
197
+ return this.toArray();
198
+ }
199
+
200
+ /**
201
+ * ===========================================================================
202
+ * Set Methods
203
+ * ===========================================================================
204
+ */
205
+
206
+ difference(other: Set<T>): LdSet<T> {
207
+ return this.filter((value) => !other.has(value));
208
+ }
209
+
210
+ intersection(other: Set<T>): LdSet<T> {
211
+ const newSet = new BasicLdSet<T>();
212
+ const iteratingSet = this.size < other.size ? this : other;
213
+ const comparingSet = this.size < other.size ? other : this;
214
+ for (const value of iteratingSet) {
215
+ if (comparingSet.has(value)) {
216
+ newSet.add(value);
217
+ }
218
+ }
219
+ return newSet;
220
+ }
221
+
222
+ isDisjointFrom(other: Set<T>): boolean {
223
+ const iteratingSet = this.size < other.size ? this : other;
224
+ const comparingSet = this.size < other.size ? other : this;
225
+ for (const value of iteratingSet) {
226
+ if (comparingSet.has(value)) return false;
227
+ }
228
+ return true;
229
+ }
230
+
231
+ isSubsetOf(other: Set<T>): boolean {
232
+ if (this.size > other.size) return false;
233
+ for (const value of this) {
234
+ if (!other.has(value)) return false;
235
+ }
236
+ return true;
237
+ }
238
+
239
+ isSupersetOf(other: Set<T>): boolean {
240
+ if (this.size < other.size) return false;
241
+ for (const value of other) {
242
+ if (!this.has(value)) return false;
243
+ }
244
+ return true;
245
+ }
246
+
247
+ symmetricDifference(other: Set<T>): LdSet<T> {
248
+ const newSet = new BasicLdSet<T>();
249
+ this.forEach((value) => newSet.add(value));
250
+ other.forEach((value) => {
251
+ if (newSet.has(value)) {
252
+ newSet.delete(value);
253
+ } else {
254
+ newSet.add(value);
255
+ }
256
+ });
257
+ return newSet;
258
+ }
259
+
260
+ union(other: Set<T>): LdSet<T> {
261
+ const newSet = new BasicLdSet<T>();
262
+ this.forEach((value) => newSet.add(value));
263
+ other.forEach((value) => newSet.add(value));
264
+ return newSet;
265
+ }
266
+ }
@@ -0,0 +1,189 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+
3
+ /**
4
+ * An abract representation for a set of Linked Data Objects
5
+ */
6
+ export interface LdSet<T> extends Set<T> {
7
+ /**
8
+ * ===========================================================================
9
+ * BASE METHODS
10
+ * ===========================================================================
11
+ */
12
+ /**
13
+ * Appends a new element with a specified value to the end of the Set.
14
+ */
15
+ add(value: T): this;
16
+ /**
17
+ * Clears this set of all values, but keeps the values in the datastore
18
+ */
19
+ clear(): void;
20
+ /**
21
+ * Removes a specified value from the Set.
22
+ * @returns Returns true if an element in the Set existed and has been removed, or false if the element does not exist.
23
+ */
24
+ delete(value: T): boolean;
25
+ /**
26
+ * @returns a boolean indicating whether an element with the specified value exists in the Set or not.
27
+ */
28
+ has(value: T): boolean;
29
+ /**
30
+ * @returns the number of (unique) elements in Set.
31
+ */
32
+ readonly size: number;
33
+ /** Iterates over values in the set. */
34
+ [Symbol.iterator](): IterableIterator<T>;
35
+ /**
36
+ * Returns an iterable of [v,v] pairs for every value `v` in the set.
37
+ */
38
+ entries(): IterableIterator<[T, T]>;
39
+ /**
40
+ * Despite its name, returns an iterable of the values in the set.
41
+ */
42
+ keys(): IterableIterator<T>;
43
+ /**
44
+ * Returns an iterable of values in the set.
45
+ */
46
+ values(): IterableIterator<T>;
47
+ /**
48
+ * ===========================================================================
49
+ * ITERATOR METHODS
50
+ * These methods mimic array methods
51
+ * ===========================================================================
52
+ */
53
+ /**
54
+ * Determines whether all the members of an set satisfy the specified test.
55
+ * @param predicate A function that accepts up to two arguments. The every method calls
56
+ * the predicate function for each element in the set until the predicate returns a value
57
+ * which is coercible to the Boolean value false, or until the end of the set.
58
+ * @param thisArg An object to which the this keyword can refer in the predicate function.
59
+ * If thisArg is omitted, undefined is used as the this value.
60
+ */
61
+ every<S extends T>(
62
+ predicate: (value: T, set: LdSet<T>) => value is S,
63
+ thisArg?: any,
64
+ ): this is LdSet<S>;
65
+ /**
66
+ * Determines whether all the members of an set satisfy the specified test.
67
+ * @param predicate A function that accepts up to two arguments. The every method calls
68
+ * the predicate function for each element in the set until the predicate returns a value
69
+ * which is coercible to the Boolean value false, or until the end of the set.
70
+ * @param thisArg An object to which the this keyword can refer in the predicate function.
71
+ * If thisArg is omitted, undefined is used as the this value.
72
+ */
73
+ every(
74
+ predicate: (value: T, set: LdSet<T>) => unknown,
75
+ thisArg?: any,
76
+ ): boolean;
77
+ /**
78
+ * Determines whether the specified callback function returns true for any element of a set.
79
+ * @param predicate A function that accepts up to two arguments. The some method calls
80
+ * the predicate function for each element in the set until the predicate returns a value
81
+ * which is coercible to the Boolean value true, or until the end of the set.
82
+ * @param thisArg An object to which the this keyword can refer in the predicate function.
83
+ * If thisArg is omitted, undefined is used as the this value.
84
+ */
85
+ some(predicate: (value: T, set: LdSet<T>) => unknown, thisArg?: any): boolean;
86
+ /**
87
+ * Performs the specified action for each element in an set.
88
+ * @param callbackfn A function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the set. A "value2" is provided for parity with the base set.
89
+ * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
90
+ */
91
+ forEach(
92
+ callbackfn: (value: T, value2: T, set: LdSet<T>) => void,
93
+ thisArg?: any,
94
+ ): void;
95
+ /**
96
+ * Calls a defined callback function on each element of an set, and returns a set that contains the results.
97
+ * @param callbackfn A function that accepts up to two arguments. The map method calls the callbackfn function one time for each element in the set.
98
+ * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
99
+ */
100
+ map<U>(callbackfn: (value: T, set: LdSet<T>) => U, thisArg?: any): U[];
101
+ /**
102
+ * Returns the elements of a set that meet the condition specified in a callback function.
103
+ * @param predicate A function that accepts up to two arguments. The filter method calls the predicate function one time for each element in the set.
104
+ * @param thisArg An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.
105
+ */
106
+ filter<S extends T>(
107
+ predicate: (value: T, set: LdSet<T>) => value is S,
108
+ thisArg?: any,
109
+ ): LdSet<S>;
110
+ /**
111
+ * Returns the elements of a set that meet the condition specified in a callback function.
112
+ * @param predicate A function that accepts up to two arguments. The filter method calls the predicate function one time for each element in the set.
113
+ * @param thisArg An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.
114
+ */
115
+ filter(
116
+ predicate: (value: T, set: LdSet<T>) => unknown,
117
+ thisArg?: any,
118
+ ): LdSet<T>;
119
+ /**
120
+ * Calls the specified callback function for all the elements in a set. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
121
+ * @param callbackfn A function that accepts up to three arguments. The reduce method calls the callbackfn function one time for each element in the set.
122
+ * @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.
123
+ */
124
+ reduce(
125
+ callbackfn: (previousValue: T, currentValue: T, set: LdSet<T>) => T,
126
+ ): T;
127
+ /**
128
+ * Calls the specified callback function for all the elements in a set. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
129
+ * @param callbackfn A function that accepts up to three arguments. The reduce method calls the callbackfn function one time for each element in the set.
130
+ * @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.
131
+ */
132
+ reduce(
133
+ callbackfn: (previousValue: T, currentValue: T, set: LdSet<T>) => T,
134
+ initialValue: T,
135
+ ): T;
136
+ /**
137
+ * Calls the specified callback function for all the elements in a set. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
138
+ * @param callbackfn A function that accepts up to three arguments. The reduce method calls the callbackfn function one time for each element in the set.
139
+ * @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.
140
+ */
141
+ reduce<U>(
142
+ callbackfn: (previousValue: U, currentValue: T, array: LdSet<T>) => U,
143
+ initialValue: U,
144
+ ): U;
145
+
146
+ /**
147
+ * Converts the current LdSet to an array.
148
+ */
149
+ toArray(): T[];
150
+
151
+ /**
152
+ * Converts to JSON
153
+ */
154
+ toJSON(): T[];
155
+
156
+ /**
157
+ * ===========================================================================
158
+ * EXTENDED SET METHODS
159
+ * ===========================================================================
160
+ */
161
+ /**
162
+ * Returns a new set containing elements in this set but not in the given set.
163
+ */
164
+ difference(other: Set<T>): LdSet<T>;
165
+ /**
166
+ * returns a new set containing elements in both this set and the given set.
167
+ */
168
+ intersection(other: Set<T>): LdSet<T>;
169
+ /**
170
+ * Returns a boolean indicating if this set has no elements in common with the given set.
171
+ */
172
+ isDisjointFrom(other: Set<T>): boolean;
173
+ /**
174
+ * Returns a boolean indicating if all elements of this set are in the given set.
175
+ */
176
+ isSubsetOf(other: Set<T>): boolean;
177
+ /**
178
+ * Returns a boolean indicating if all elements of the given set are in this set.
179
+ */
180
+ isSupersetOf(other: Set<T>): boolean;
181
+ /**
182
+ * Returns a new set containing elements which are in either this set or the given set, but not in both.
183
+ */
184
+ symmetricDifference(other: Set<T>): LdSet<T>;
185
+ /**
186
+ * Returns a new set containing elements which are in either or both of this set and the given set.
187
+ */
188
+ union(other: Set<T>): LdSet<T>;
189
+ }
@@ -0,0 +1,14 @@
1
+ import type { RawValue } from "../util/RawObject";
2
+ import { BasicLdSet } from "./ldSet/BasicLdSet";
3
+ import type { LdSet } from "./ldSet/LdSet";
4
+
5
+ /**
6
+ * Creates an LdSet used by LDO as a list of items.
7
+ * @param values The list of items in the set
8
+ * @returns An LdSet
9
+ */
10
+ export function set<T>(...values: T[]): LdSet<T> {
11
+ return new BasicLdSet(
12
+ values as Iterable<NonNullable<RawValue>>,
13
+ ) as unknown as LdSet<T>;
14
+ }
@@ -12,7 +12,7 @@ import type {
12
12
  export type SubjectProxy = {
13
13
  "@id"?: string;
14
14
  "@context": ContextDefinition;
15
- readonly [key: string | number | symbol]: unknown;
15
+ [key: string | number | symbol]: unknown;
16
16
  readonly [_getUnderlyingDataset]: Dataset;
17
17
  readonly [_getUnderlyingNode]: NamedNode | BlankNode;
18
18
  [_proxyContext]: ProxyContext;
@@ -1,4 +1,4 @@
1
- import { namedNode, quad } from "@rdfjs/data-model";
1
+ import { blankNode, namedNode, quad } from "@rdfjs/data-model";
2
2
  import type { BlankNode, NamedNode } from "@rdfjs/types";
3
3
  import { addObjectToDataset } from "../util/addObjectToDataset";
4
4
  import { deleteValueFromDataset } from "./deleteFromDataset";
@@ -48,7 +48,12 @@ export function createSubjectHandler(
48
48
  const tripleDataset = proxyContext.dataset.match(subject);
49
49
  const keys: Set<string> = new Set(["@id"]);
50
50
  tripleDataset.toArray().forEach((quad) => {
51
- keys.add(proxyContext.contextUtil.iriToKey(quad.predicate.value));
51
+ keys.add(
52
+ proxyContext.contextUtil.iriToKey(
53
+ quad.predicate.value,
54
+ proxyContext.getRdfType(subject),
55
+ ),
56
+ );
52
57
  });
53
58
  return Array.from(keys);
54
59
  },
@@ -57,14 +62,18 @@ export function createSubjectHandler(
57
62
  proxyContext = value;
58
63
  return true;
59
64
  }
60
- if (key === "@id" && typeof value === "string") {
65
+ if (
66
+ key === "@id" &&
67
+ (typeof value === "string" || typeof value == "undefined")
68
+ ) {
69
+ const newSubjectNode = value ? namedNode(value) : blankNode();
61
70
  // Replace Subject Quads
62
71
  const currentSubjectQuads = proxyContext.dataset
63
72
  .match(target["@id"])
64
73
  .toArray();
65
74
  const newSubjectQuads = currentSubjectQuads.map((curQuad) =>
66
75
  quad(
67
- namedNode(value),
76
+ newSubjectNode,
68
77
  curQuad.predicate,
69
78
  curQuad.object,
70
79
  curQuad.graph,
@@ -82,7 +91,7 @@ export function createSubjectHandler(
82
91
  quad(
83
92
  curQuad.subject,
84
93
  curQuad.predicate,
85
- namedNode(value),
94
+ newSubjectNode,
86
95
  curQuad.graph,
87
96
  ),
88
97
  );
@@ -90,7 +99,7 @@ export function createSubjectHandler(
90
99
  proxyContext.dataset.delete(curQuad),
91
100
  );
92
101
  proxyContext.dataset.addAll(newObjectQuads);
93
- target["@id"] = namedNode(value);
102
+ target["@id"] = newSubjectNode;
94
103
  }
95
104
  addObjectToDataset(
96
105
  { "@id": target["@id"], [key]: value },