@ldo/subscribable-dataset 0.0.1-alpha.18 → 0.0.1-alpha.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/SubscribableDataset.d.ts +37 -0
- package/dist/SubscribableDataset.js +180 -0
- package/dist/SubscribableDataset.js.map +1 -0
- package/dist/SubscribableDatasetFactory.d.ts +9 -0
- package/dist/SubscribableDatasetFactory.js +15 -0
- package/dist/SubscribableDatasetFactory.js.map +1 -0
- package/dist/TransactionDataset.d.ts +25 -0
- package/dist/TransactionDataset.js +124 -0
- package/dist/TransactionDataset.js.map +1 -0
- package/dist/TransactionDatasetFactory.d.ts +9 -0
- package/dist/TransactionDatasetFactory.js +15 -0
- package/dist/TransactionDatasetFactory.js.map +1 -0
- package/dist/createSubscribableDataset.d.ts +5 -0
- package/dist/createSubscribableDataset.js +25 -0
- package/dist/createSubscribableDataset.js.map +1 -0
- package/dist/createSubscribableDatasetFromSerializedInput.d.ts +4 -0
- package/dist/createSubscribableDatasetFromSerializedInput.js +11 -0
- package/dist/createSubscribableDatasetFromSerializedInput.js.map +1 -0
- package/dist/index.d.ts +7 -5
- package/dist/index.js +9 -9
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +14 -9
- package/dist/util.d.ts +3 -0
- package/dist/util.js +20 -0
- package/dist/util.js.map +1 -0
- package/package.json +2 -2
- package/src/{WrapperSubscribableDataset.ts → SubscribableDataset.ts} +40 -231
- package/src/SubscribableDatasetFactory.ts +31 -0
- package/src/{ProxyTransactionalDataset.ts → TransactionDataset.ts} +10 -39
- package/src/TransactionDatasetFactory.ts +27 -0
- package/src/createSubscribableDataset.ts +46 -0
- package/src/{createWrapperSubscribableDatasetFromSerializedInput.ts → createSubscribableDatasetFromSerializedInput.ts} +5 -5
- package/src/index.ts +7 -8
- package/src/types.ts +35 -12
- package/src/util.ts +27 -0
- package/src/WrapperSubscribableDatasetFactory.ts +0 -27
- package/src/createWrapperSubscribableDataset.ts +0 -30
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ldo/subscribable-dataset",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.19",
|
|
4
4
|
"description": "An RDFJS dataset implementation that can be subscribed to for updates",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -43,5 +43,5 @@
|
|
|
43
43
|
"publishConfig": {
|
|
44
44
|
"access": "public"
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "c21144a5552978622d05c3f1db4a3b68d304813c"
|
|
47
47
|
}
|
|
@@ -8,40 +8,36 @@ import type {
|
|
|
8
8
|
ObjectNode,
|
|
9
9
|
GraphNode,
|
|
10
10
|
} from "@ldo/rdf-utils";
|
|
11
|
-
import type {
|
|
12
|
-
Dataset,
|
|
13
|
-
BaseQuad,
|
|
14
|
-
Stream,
|
|
15
|
-
Term,
|
|
16
|
-
DatasetFactory,
|
|
17
|
-
} from "@rdfjs/types";
|
|
11
|
+
import type { Dataset, BaseQuad, Term, DatasetFactory } from "@rdfjs/types";
|
|
18
12
|
import type {
|
|
19
13
|
nodeEventListener,
|
|
20
|
-
|
|
21
|
-
|
|
14
|
+
ISubscribableDataset,
|
|
15
|
+
ITransactionDataset,
|
|
16
|
+
ITransactionDatasetFactory,
|
|
22
17
|
} from "./types";
|
|
23
|
-
import {
|
|
18
|
+
import { ExtendedDataset } from "@ldo/dataset";
|
|
24
19
|
|
|
25
20
|
/**
|
|
26
21
|
* A wrapper for a dataset that allows subscriptions to be made on nodes to
|
|
27
22
|
* be triggered whenever a quad containing that added or removed.
|
|
28
23
|
*/
|
|
29
|
-
export class
|
|
30
|
-
|
|
31
|
-
|
|
24
|
+
export class SubscribableDataset<InAndOutQuad extends BaseQuad = BaseQuad>
|
|
25
|
+
extends ExtendedDataset<InAndOutQuad>
|
|
26
|
+
implements ISubscribableDataset<InAndOutQuad>
|
|
32
27
|
{
|
|
33
28
|
/**
|
|
34
|
-
*
|
|
29
|
+
* DatasetFactory for creating new datasets
|
|
35
30
|
*/
|
|
36
|
-
|
|
31
|
+
protected datasetFactory: DatasetFactory<InAndOutQuad>;
|
|
32
|
+
|
|
37
33
|
/**
|
|
38
|
-
* The underlying
|
|
34
|
+
* The underlying event emitter
|
|
39
35
|
*/
|
|
40
|
-
|
|
36
|
+
protected eventEmitter: EventEmitter;
|
|
41
37
|
/**
|
|
42
|
-
* The underlying
|
|
38
|
+
* The underlying dataset factory for creating transaction datasets
|
|
43
39
|
*/
|
|
44
|
-
|
|
40
|
+
protected transactionDatasetFactory: ITransactionDatasetFactory<InAndOutQuad>;
|
|
45
41
|
/**
|
|
46
42
|
* Helps find all the events for a given listener
|
|
47
43
|
*/
|
|
@@ -54,11 +50,13 @@ export class WrapperSubscribableDataset<
|
|
|
54
50
|
*/
|
|
55
51
|
constructor(
|
|
56
52
|
datasetFactory: DatasetFactory<InAndOutQuad, InAndOutQuad>,
|
|
53
|
+
transactionDatasetFactory: ITransactionDatasetFactory<InAndOutQuad>,
|
|
57
54
|
initialDataset?: Dataset<InAndOutQuad, InAndOutQuad>,
|
|
58
55
|
) {
|
|
59
|
-
|
|
60
|
-
this.
|
|
56
|
+
super(initialDataset || datasetFactory.dataset(), datasetFactory);
|
|
57
|
+
this.transactionDatasetFactory = transactionDatasetFactory;
|
|
61
58
|
this.eventEmitter = new EventEmitter();
|
|
59
|
+
this.datasetFactory = datasetFactory;
|
|
62
60
|
}
|
|
63
61
|
|
|
64
62
|
/**
|
|
@@ -67,6 +65,18 @@ export class WrapperSubscribableDataset<
|
|
|
67
65
|
* ==================================================================
|
|
68
66
|
*/
|
|
69
67
|
|
|
68
|
+
/**
|
|
69
|
+
* A helper method that mimics what the super of addAll would be
|
|
70
|
+
*/
|
|
71
|
+
private superAddAll(
|
|
72
|
+
quads: Dataset<InAndOutQuad, InAndOutQuad> | InAndOutQuad[],
|
|
73
|
+
): this {
|
|
74
|
+
for (const quad of quads) {
|
|
75
|
+
super.add(quad);
|
|
76
|
+
}
|
|
77
|
+
return this;
|
|
78
|
+
}
|
|
79
|
+
|
|
70
80
|
/**
|
|
71
81
|
* Imports the quads into this dataset.
|
|
72
82
|
* This method differs from Dataset.union in that it adds all quads to the current instance, rather than combining quads and the current instance to create a new instance.
|
|
@@ -76,7 +86,7 @@ export class WrapperSubscribableDataset<
|
|
|
76
86
|
public addAll(
|
|
77
87
|
quads: Dataset<InAndOutQuad, InAndOutQuad> | InAndOutQuad[],
|
|
78
88
|
): this {
|
|
79
|
-
this.
|
|
89
|
+
this.superAddAll(quads);
|
|
80
90
|
this.triggerSubscriptionForQuads({
|
|
81
91
|
added: this.datasetFactory.dataset(quads),
|
|
82
92
|
});
|
|
@@ -89,26 +99,17 @@ export class WrapperSubscribableDataset<
|
|
|
89
99
|
*/
|
|
90
100
|
public bulk(changed: DatasetChanges<InAndOutQuad>): this {
|
|
91
101
|
if (changed.added) {
|
|
92
|
-
this.
|
|
102
|
+
this.superAddAll(changed.added);
|
|
93
103
|
}
|
|
94
104
|
if (changed.removed) {
|
|
95
105
|
changed.removed.forEach((quad) => {
|
|
96
|
-
|
|
106
|
+
super.delete(quad);
|
|
97
107
|
});
|
|
98
108
|
}
|
|
99
109
|
this.triggerSubscriptionForQuads(changed);
|
|
100
110
|
return this;
|
|
101
111
|
}
|
|
102
112
|
|
|
103
|
-
/**
|
|
104
|
-
* Returns true if the current instance is a superset of the given dataset; differently put: if the given dataset is a subset of, is contained in the current dataset.
|
|
105
|
-
* Blank Nodes will be normalized.
|
|
106
|
-
* @param other
|
|
107
|
-
*/
|
|
108
|
-
public contains(other: Dataset<InAndOutQuad, InAndOutQuad>): boolean {
|
|
109
|
-
return this.dataset.contains(other);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
113
|
/**
|
|
113
114
|
* This method removes the quads in the current instance that match the given arguments. The logic described in Quad Matching is applied for each quad in this dataset to select the quads which will be deleted.
|
|
114
115
|
* @param subject
|
|
@@ -123,191 +124,14 @@ export class WrapperSubscribableDataset<
|
|
|
123
124
|
object?: Term,
|
|
124
125
|
graph?: Term,
|
|
125
126
|
): this {
|
|
126
|
-
const matching =
|
|
127
|
+
const matching = super.match(subject, predicate, object, graph);
|
|
127
128
|
for (const quad of matching) {
|
|
128
|
-
|
|
129
|
+
super.delete(quad);
|
|
129
130
|
}
|
|
130
131
|
this.triggerSubscriptionForQuads({ removed: matching });
|
|
131
132
|
return this;
|
|
132
133
|
}
|
|
133
134
|
|
|
134
|
-
/**
|
|
135
|
-
* Returns a new dataset that contains alls quads from the current dataset, not included in the given dataset.
|
|
136
|
-
* @param other
|
|
137
|
-
*/
|
|
138
|
-
public difference(
|
|
139
|
-
other: Dataset<InAndOutQuad, InAndOutQuad>,
|
|
140
|
-
): Dataset<InAndOutQuad, InAndOutQuad> {
|
|
141
|
-
return this.dataset.difference(other);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* Returns true if the current instance contains the same graph structure as the given dataset.
|
|
146
|
-
* @param other
|
|
147
|
-
*/
|
|
148
|
-
public equals(other: Dataset<InAndOutQuad, InAndOutQuad>): boolean {
|
|
149
|
-
return this.dataset.equals(other);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Universal quantification method, tests whether every quad in the dataset passes the test implemented by the provided iteratee.
|
|
154
|
-
* This method immediately returns boolean false once a quad that does not pass the test is found.
|
|
155
|
-
* This method always returns boolean true on an empty dataset.
|
|
156
|
-
* Note: This method is aligned with Array.prototype.every() in ECMAScript-262.
|
|
157
|
-
* @param iteratee
|
|
158
|
-
*/
|
|
159
|
-
public every(
|
|
160
|
-
iteratee: (quad: InAndOutQuad, dataset: this) => boolean,
|
|
161
|
-
): boolean {
|
|
162
|
-
return this.dataset.every((quad) => iteratee(quad, this));
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* Creates a new dataset with all the quads that pass the test implemented by the provided iteratee.
|
|
167
|
-
* Note: This method is aligned with Array.prototype.filter() in ECMAScript-262.
|
|
168
|
-
* @param iteratee
|
|
169
|
-
*/
|
|
170
|
-
public filter(
|
|
171
|
-
iteratee: (quad: InAndOutQuad, dataset: this) => boolean,
|
|
172
|
-
): Dataset<InAndOutQuad, InAndOutQuad> {
|
|
173
|
-
return this.dataset.filter((quad) => iteratee(quad, this));
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
/**
|
|
177
|
-
* Executes the provided iteratee once on each quad in the dataset.
|
|
178
|
-
* Note: This method is aligned with Array.prototype.forEach() in ECMAScript-262.
|
|
179
|
-
* @param iteratee
|
|
180
|
-
*/
|
|
181
|
-
public forEach(iteratee: (quad: InAndOutQuad, dataset: this) => void): void {
|
|
182
|
-
return this.dataset.forEach((quad) => iteratee(quad, this));
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
/**
|
|
186
|
-
* Imports all quads from the given stream into the dataset.
|
|
187
|
-
* The stream events end and error are wrapped in a Promise.
|
|
188
|
-
* @param stream
|
|
189
|
-
*/
|
|
190
|
-
public async import(stream: Stream<InAndOutQuad>): Promise<this> {
|
|
191
|
-
await this.dataset.import(stream);
|
|
192
|
-
return this;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* Returns a new dataset containing alls quads from the current dataset that are also included in the given dataset.
|
|
197
|
-
* @param other
|
|
198
|
-
*/
|
|
199
|
-
// Typescript disabled because rdf-js has incorrect typings
|
|
200
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
201
|
-
// @ts-ignore
|
|
202
|
-
public intersection(
|
|
203
|
-
other: Dataset<InAndOutQuad, InAndOutQuad>,
|
|
204
|
-
): Dataset<InAndOutQuad, InAndOutQuad> {
|
|
205
|
-
return this.dataset.intersection(other);
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
/**
|
|
209
|
-
* Returns a new dataset containing all quads returned by applying iteratee to each quad in the current dataset.
|
|
210
|
-
* @param iteratee
|
|
211
|
-
*/
|
|
212
|
-
public map(
|
|
213
|
-
iteratee: (quad: InAndOutQuad, dataset: this) => InAndOutQuad,
|
|
214
|
-
): Dataset<InAndOutQuad, InAndOutQuad> {
|
|
215
|
-
return this.dataset.map((quad) => iteratee(quad, this));
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
/**
|
|
219
|
-
* This method calls the iteratee on each quad of the DatasetCore. The first time the iteratee is called, the accumulator value is the initialValue or, if not given, equals to the first quad of the Dataset. The return value of the iteratee is used as accumulator value for the next calls.
|
|
220
|
-
* This method returns the return value of the last iteratee call.
|
|
221
|
-
* Note: This method is aligned with Array.prototype.reduce() in ECMAScript-262.
|
|
222
|
-
* @param iteratee
|
|
223
|
-
* @param initialValue
|
|
224
|
-
*/
|
|
225
|
-
public reduce<A = unknown>(
|
|
226
|
-
iteratee: (accumulator: A, quad: InAndOutQuad, dataset: this) => A,
|
|
227
|
-
initialValue?: A,
|
|
228
|
-
): A {
|
|
229
|
-
return this.dataset.reduce(
|
|
230
|
-
(acc, quad) => iteratee(acc, quad, this),
|
|
231
|
-
initialValue,
|
|
232
|
-
);
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
/**
|
|
236
|
-
* Existential quantification method, tests whether some quads in the dataset pass the test implemented by the provided iteratee.
|
|
237
|
-
* Note: This method is aligned with Array.prototype.some() in ECMAScript-262.
|
|
238
|
-
* @param iteratee
|
|
239
|
-
* @returns boolean true once a quad that passes the test is found.
|
|
240
|
-
*/
|
|
241
|
-
public some(
|
|
242
|
-
iteratee: (quad: InAndOutQuad, dataset: this) => boolean,
|
|
243
|
-
): boolean {
|
|
244
|
-
return this.dataset.some((quad) => iteratee(quad, this));
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
/**
|
|
248
|
-
* Returns the set of quads within the dataset as a host language native sequence, for example an Array in ECMAScript-262.
|
|
249
|
-
* Note: Since a DatasetCore is an unordered set, the order of the quads within the returned sequence is arbitrary.
|
|
250
|
-
*/
|
|
251
|
-
public toArray(): InAndOutQuad[] {
|
|
252
|
-
return this.dataset.toArray();
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
/**
|
|
256
|
-
* Returns an N-Quads string representation of the dataset, preprocessed with RDF Dataset Normalization algorithm.
|
|
257
|
-
*/
|
|
258
|
-
public toCanonical(): string {
|
|
259
|
-
return this.dataset.toCanonical();
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
/**
|
|
263
|
-
* Returns a stream that contains all quads of the dataset.
|
|
264
|
-
*/
|
|
265
|
-
public toStream(): Stream<InAndOutQuad> {
|
|
266
|
-
return this.dataset.toStream();
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
/**
|
|
270
|
-
* Returns an N-Quads string representation of the dataset.
|
|
271
|
-
* No prior normalization is required, therefore the results for the same quads may vary depending on the Dataset implementation.
|
|
272
|
-
*/
|
|
273
|
-
public toString(): string {
|
|
274
|
-
return this.dataset.toString();
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
/**
|
|
278
|
-
* Returns a new Dataset that is a concatenation of this dataset and the quads given as an argument.
|
|
279
|
-
* @param other
|
|
280
|
-
*/
|
|
281
|
-
public union(
|
|
282
|
-
quads: Dataset<InAndOutQuad, InAndOutQuad>,
|
|
283
|
-
): Dataset<InAndOutQuad, InAndOutQuad> {
|
|
284
|
-
return this.dataset.union(quads);
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
/**
|
|
288
|
-
* This method returns a new dataset that is comprised of all quads in the current instance matching the given arguments. The logic described in Quad Matching is applied for each quad in this dataset to check if it should be included in the output dataset.
|
|
289
|
-
* @param subject
|
|
290
|
-
* @param predicate
|
|
291
|
-
* @param object
|
|
292
|
-
* @param graph
|
|
293
|
-
* @returns a Dataset with matching triples
|
|
294
|
-
*/
|
|
295
|
-
public match(
|
|
296
|
-
subject?: Term | null,
|
|
297
|
-
predicate?: Term | null,
|
|
298
|
-
object?: Term | null,
|
|
299
|
-
graph?: Term | null,
|
|
300
|
-
): Dataset<InAndOutQuad, InAndOutQuad> {
|
|
301
|
-
return this.dataset.match(subject, predicate, object, graph);
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
/**
|
|
305
|
-
* A non-negative integer that specifies the number of quads in the set.
|
|
306
|
-
*/
|
|
307
|
-
public get size(): number {
|
|
308
|
-
return this.dataset.size;
|
|
309
|
-
}
|
|
310
|
-
|
|
311
135
|
/**
|
|
312
136
|
* Adds the specified quad to the dataset.
|
|
313
137
|
* Existing quads, as defined in Quad.equals, will be ignored.
|
|
@@ -315,7 +139,7 @@ export class WrapperSubscribableDataset<
|
|
|
315
139
|
* @returns the dataset instance it was called on.
|
|
316
140
|
*/
|
|
317
141
|
public add(quad: InAndOutQuad): this {
|
|
318
|
-
|
|
142
|
+
super.add(quad);
|
|
319
143
|
this.triggerSubscriptionForQuads({
|
|
320
144
|
added: this.datasetFactory.dataset([quad]),
|
|
321
145
|
});
|
|
@@ -328,28 +152,13 @@ export class WrapperSubscribableDataset<
|
|
|
328
152
|
* @param quad
|
|
329
153
|
*/
|
|
330
154
|
public delete(quad: InAndOutQuad): this {
|
|
331
|
-
|
|
155
|
+
super.delete(quad);
|
|
332
156
|
this.triggerSubscriptionForQuads({
|
|
333
157
|
removed: this.datasetFactory.dataset([quad]),
|
|
334
158
|
});
|
|
335
159
|
return this;
|
|
336
160
|
}
|
|
337
161
|
|
|
338
|
-
/**
|
|
339
|
-
* Determines whether a dataset includes a certain quad, returning true or false as appropriate.
|
|
340
|
-
* @param quad
|
|
341
|
-
*/
|
|
342
|
-
public has(quad: InAndOutQuad): boolean {
|
|
343
|
-
return this.dataset.has(quad);
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
/**
|
|
347
|
-
* Returns an iterator
|
|
348
|
-
*/
|
|
349
|
-
public [Symbol.iterator](): Iterator<InAndOutQuad, unknown, undefined> {
|
|
350
|
-
return this.dataset[Symbol.iterator]();
|
|
351
|
-
}
|
|
352
|
-
|
|
353
162
|
/**
|
|
354
163
|
* ==================================================================
|
|
355
164
|
* EVENTEMITTER METHODS
|
|
@@ -609,7 +418,7 @@ export class WrapperSubscribableDataset<
|
|
|
609
418
|
/**
|
|
610
419
|
* Returns a transactional dataset that will update this dataset when its transaction is committed.
|
|
611
420
|
*/
|
|
612
|
-
public startTransaction():
|
|
613
|
-
return
|
|
421
|
+
public startTransaction(): ITransactionDataset<InAndOutQuad> {
|
|
422
|
+
return this.transactionDatasetFactory.transactionDataset(this);
|
|
614
423
|
}
|
|
615
424
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { DatasetFactory, BaseQuad, Dataset } from "@rdfjs/types";
|
|
2
|
+
import type { ITransactionDatasetFactory } from "./types";
|
|
3
|
+
import { SubscribableDataset } from "./SubscribableDataset";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A DatasetFactory that returns a SubscribableDataset given a generic DatasetFactory.
|
|
7
|
+
*/
|
|
8
|
+
export class SubscribableDatasetFactory<
|
|
9
|
+
InAndOutQuad extends BaseQuad = BaseQuad,
|
|
10
|
+
> implements DatasetFactory<InAndOutQuad, InAndOutQuad>
|
|
11
|
+
{
|
|
12
|
+
protected datasetFactory: DatasetFactory<InAndOutQuad, InAndOutQuad>;
|
|
13
|
+
protected transactionDatasetFactory: ITransactionDatasetFactory<InAndOutQuad>;
|
|
14
|
+
constructor(
|
|
15
|
+
datasetFactory: DatasetFactory<InAndOutQuad, InAndOutQuad>,
|
|
16
|
+
transactionDatasetFactory: ITransactionDatasetFactory<InAndOutQuad>,
|
|
17
|
+
) {
|
|
18
|
+
this.datasetFactory = datasetFactory;
|
|
19
|
+
this.transactionDatasetFactory = transactionDatasetFactory;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
dataset(
|
|
23
|
+
quads?: Dataset<InAndOutQuad, InAndOutQuad> | InAndOutQuad[],
|
|
24
|
+
): SubscribableDataset<InAndOutQuad> {
|
|
25
|
+
return new SubscribableDataset(
|
|
26
|
+
this.datasetFactory,
|
|
27
|
+
this.transactionDatasetFactory,
|
|
28
|
+
quads ? this.datasetFactory.dataset(quads) : undefined,
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -1,27 +1,23 @@
|
|
|
1
1
|
import type { Dataset, BaseQuad, Term, DatasetFactory } from "@rdfjs/types";
|
|
2
2
|
import type { DatasetChanges } from "@ldo/rdf-utils";
|
|
3
|
-
import type {
|
|
4
|
-
import { ExtendedDataset } from "@ldo/dataset";
|
|
3
|
+
import type { ITransactionDataset, ITransactionDatasetFactory } from "./types";
|
|
5
4
|
import { mergeDatasetChanges } from "./mergeDatasetChanges";
|
|
5
|
+
import { SubscribableDataset } from "./SubscribableDataset";
|
|
6
|
+
import { updateDatasetInBulk } from "./util";
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Proxy Transactional Dataset is a transactional dataset that does not duplicate
|
|
9
10
|
* the parent dataset, it will dynamically determine the correct return value for
|
|
10
11
|
* methods in real time when the method is called.
|
|
11
12
|
*/
|
|
12
|
-
export class
|
|
13
|
-
extends
|
|
14
|
-
implements
|
|
13
|
+
export class TransactionDataset<InAndOutQuad extends BaseQuad = BaseQuad>
|
|
14
|
+
extends SubscribableDataset<InAndOutQuad>
|
|
15
|
+
implements ITransactionDataset<InAndOutQuad>
|
|
15
16
|
{
|
|
16
17
|
/**
|
|
17
18
|
* The parent dataset that will be updated upon commit
|
|
18
19
|
*/
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* A factory for creating new datasets to be added to the update method
|
|
23
|
-
*/
|
|
24
|
-
private datasetFactory: DatasetFactory<InAndOutQuad, InAndOutQuad>;
|
|
20
|
+
public readonly parentDataset: Dataset<InAndOutQuad, InAndOutQuad>;
|
|
25
21
|
|
|
26
22
|
/**
|
|
27
23
|
* The changes made that are ready to commit
|
|
@@ -44,10 +40,10 @@ export class ProxyTransactionalDataset<InAndOutQuad extends BaseQuad = BaseQuad>
|
|
|
44
40
|
constructor(
|
|
45
41
|
parentDataset: Dataset<InAndOutQuad, InAndOutQuad>,
|
|
46
42
|
datasetFactory: DatasetFactory<InAndOutQuad, InAndOutQuad>,
|
|
43
|
+
transactionDatasetFactory: ITransactionDatasetFactory<InAndOutQuad>,
|
|
47
44
|
) {
|
|
48
|
-
super(datasetFactory.dataset()
|
|
45
|
+
super(datasetFactory, transactionDatasetFactory, datasetFactory.dataset());
|
|
49
46
|
this.parentDataset = parentDataset;
|
|
50
|
-
this.datasetFactory = datasetFactory;
|
|
51
47
|
this.datasetChanges = {};
|
|
52
48
|
}
|
|
53
49
|
|
|
@@ -251,21 +247,7 @@ export class ProxyTransactionalDataset<InAndOutQuad extends BaseQuad = BaseQuad>
|
|
|
251
247
|
* Helper method to update the parent dataset or any other provided dataset
|
|
252
248
|
*/
|
|
253
249
|
private updateParentDataset(datasetChanges: DatasetChanges<InAndOutQuad>) {
|
|
254
|
-
|
|
255
|
-
if ((this.parentDataset as any).bulk) {
|
|
256
|
-
(this.parentDataset as BulkEditableDataset<InAndOutQuad>).bulk(
|
|
257
|
-
datasetChanges,
|
|
258
|
-
);
|
|
259
|
-
} else {
|
|
260
|
-
if (datasetChanges.added) {
|
|
261
|
-
this.parentDataset.addAll(datasetChanges.added);
|
|
262
|
-
}
|
|
263
|
-
if (datasetChanges.removed) {
|
|
264
|
-
datasetChanges.removed.forEach((curQuad) => {
|
|
265
|
-
this.parentDataset.delete(curQuad);
|
|
266
|
-
});
|
|
267
|
-
}
|
|
268
|
-
}
|
|
250
|
+
return updateDatasetInBulk(this.parentDataset, datasetChanges);
|
|
269
251
|
}
|
|
270
252
|
|
|
271
253
|
/**
|
|
@@ -296,17 +278,6 @@ export class ProxyTransactionalDataset<InAndOutQuad extends BaseQuad = BaseQuad>
|
|
|
296
278
|
this.committedDatasetChanges = undefined;
|
|
297
279
|
}
|
|
298
280
|
|
|
299
|
-
/**
|
|
300
|
-
* Starts a new transaction with this transactional dataset as the parent
|
|
301
|
-
* @returns
|
|
302
|
-
*/
|
|
303
|
-
public startTransaction(): TransactionalDataset<InAndOutQuad> {
|
|
304
|
-
// This is caused by the typings being incorrect for the intersect method
|
|
305
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
306
|
-
// @ts-ignore
|
|
307
|
-
return new ProxyTransactionalDataset(this, this.datasetFactory);
|
|
308
|
-
}
|
|
309
|
-
|
|
310
281
|
public getChanges(): DatasetChanges<InAndOutQuad> {
|
|
311
282
|
return this.datasetChanges;
|
|
312
283
|
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { BaseQuad, DatasetFactory } from "@rdfjs/types";
|
|
2
|
+
import type { ISubscribableDataset, ITransactionDatasetFactory } from "./types";
|
|
3
|
+
import { TransactionDataset } from "./TransactionDataset";
|
|
4
|
+
|
|
5
|
+
export class TransactionDatasetFactory<InAndOutQuad extends BaseQuad>
|
|
6
|
+
implements ITransactionDatasetFactory<InAndOutQuad>
|
|
7
|
+
{
|
|
8
|
+
private datasetFactory: DatasetFactory<InAndOutQuad, InAndOutQuad>;
|
|
9
|
+
private transactionDatasetFactory: ITransactionDatasetFactory<InAndOutQuad>;
|
|
10
|
+
constructor(
|
|
11
|
+
datasetFactory: DatasetFactory<InAndOutQuad, InAndOutQuad>,
|
|
12
|
+
transactionDatasetFactory?: ITransactionDatasetFactory<InAndOutQuad>,
|
|
13
|
+
) {
|
|
14
|
+
this.datasetFactory = datasetFactory;
|
|
15
|
+
this.transactionDatasetFactory = transactionDatasetFactory || this;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
transactionDataset(
|
|
19
|
+
parentDataset: ISubscribableDataset<InAndOutQuad>,
|
|
20
|
+
): TransactionDataset<InAndOutQuad> {
|
|
21
|
+
return new TransactionDataset<InAndOutQuad>(
|
|
22
|
+
parentDataset,
|
|
23
|
+
this.datasetFactory,
|
|
24
|
+
this.transactionDatasetFactory,
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { Dataset, DatasetFactory, Quad } from "@rdfjs/types";
|
|
2
|
+
import { createDataset } from "@ldo/dataset";
|
|
3
|
+
import { SubscribableDatasetFactory } from "./SubscribableDatasetFactory";
|
|
4
|
+
import type {
|
|
5
|
+
ISubscribableDataset,
|
|
6
|
+
ISubscribableDatasetFactory,
|
|
7
|
+
ITransactionDatasetFactory,
|
|
8
|
+
} from "./types";
|
|
9
|
+
import { TransactionDatasetFactory } from "./TransactionDatasetFactory";
|
|
10
|
+
|
|
11
|
+
const datasetFactory: DatasetFactory<Quad> = {
|
|
12
|
+
dataset: (quads?: Dataset<Quad> | Quad[]): Dataset<Quad> => {
|
|
13
|
+
return createDataset(quads);
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Creates a factory that generates TransactionDatasets
|
|
19
|
+
* @returns TransactionDatasetFactory
|
|
20
|
+
*/
|
|
21
|
+
export function createTransactionDatasetFactory(): ITransactionDatasetFactory<Quad> {
|
|
22
|
+
return new TransactionDatasetFactory(datasetFactory);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Creates a dataset factory that generates a SubscribableDataset
|
|
27
|
+
* @returns DatasetFactory for SubscribableDataset
|
|
28
|
+
*/
|
|
29
|
+
export function createSubscribableDatasetFactory(): ISubscribableDatasetFactory<Quad> {
|
|
30
|
+
return new SubscribableDatasetFactory(
|
|
31
|
+
datasetFactory,
|
|
32
|
+
createTransactionDatasetFactory(),
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Creates a SubscribableDataset
|
|
38
|
+
* @param quads: A dataset or array of Quads to initialize the dataset.
|
|
39
|
+
* @returns Dataset
|
|
40
|
+
*/
|
|
41
|
+
export function createSubscribableDataset(
|
|
42
|
+
quads?: Dataset<Quad> | Quad[],
|
|
43
|
+
): ISubscribableDataset<Quad> {
|
|
44
|
+
const subscribableDatasetFactory = createSubscribableDatasetFactory();
|
|
45
|
+
return subscribableDatasetFactory.dataset(quads);
|
|
46
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { Quad } from "@rdfjs/types";
|
|
2
2
|
import type { ParserOptions } from "@ldo/rdf-utils";
|
|
3
3
|
import { createDatasetFromSerializedInput } from "@ldo/dataset";
|
|
4
|
-
import {
|
|
5
|
-
import type {
|
|
4
|
+
import { createSubscribableDatasetFactory } from "./createSubscribableDataset";
|
|
5
|
+
import type { ISubscribableDataset } from "./types";
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Creates a SubscribableDataset with a string input that could be JSON-LD, Turtle, N-Triples, TriG, RDF*, or N3.
|
|
@@ -18,9 +18,9 @@ import type { WrapperSubscribableDataset } from "./WrapperSubscribableDataset";
|
|
|
18
18
|
export async function createWrapperSubscribableDatasetFromSerializedInput(
|
|
19
19
|
data: string,
|
|
20
20
|
options?: ParserOptions,
|
|
21
|
-
): Promise<
|
|
22
|
-
const datasetFactory =
|
|
23
|
-
return createDatasetFromSerializedInput<
|
|
21
|
+
): Promise<ISubscribableDataset<Quad>> {
|
|
22
|
+
const datasetFactory = createSubscribableDatasetFactory();
|
|
23
|
+
return createDatasetFromSerializedInput<ISubscribableDataset<Quad>>(
|
|
24
24
|
datasetFactory,
|
|
25
25
|
data,
|
|
26
26
|
options,
|
package/src/index.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export
|
|
6
|
-
export * from "./
|
|
7
|
-
export * from "./WrapperSubscribableDataset";
|
|
8
|
-
export * from "./WrapperSubscribableDatasetFactory";
|
|
1
|
+
export * from "./createSubscribableDataset";
|
|
2
|
+
export { createWrapperSubscribableDatasetFromSerializedInput as serializedToSubscribableDataset } from "./createSubscribableDatasetFromSerializedInput";
|
|
3
|
+
export * from "./TransactionDataset";
|
|
4
|
+
export * from "./TransactionDatasetFactory";
|
|
5
|
+
export * from "./SubscribableDataset";
|
|
6
|
+
export * from "./SubscribableDatasetFactory";
|
|
9
7
|
export * from "./types";
|
|
10
8
|
export * from "./mergeDatasetChanges";
|
|
9
|
+
export * from "./util";
|