Mercurial > code > home > repos > streamed-graph
annotate src/Patch.ts @ 141:27fad20dc101
rm logging
author | drewp@bigasterisk.com |
---|---|
date | Mon, 08 May 2023 13:05:59 -0700 |
parents | cf642d395be4 |
children |
rev | line source |
---|---|
128 | 1 import { Quad, Store } from "n3"; |
2 import { Stream } from "rdf-js"; | |
3 | |
139
cf642d395be4
new simpler Patch class; fancier 'hide' view config support
drewp@bigasterisk.com
parents:
128
diff
changeset
|
4 export enum PatchDirection { |
cf642d395be4
new simpler Patch class; fancier 'hide' view config support
drewp@bigasterisk.com
parents:
128
diff
changeset
|
5 ADD = "+", |
cf642d395be4
new simpler Patch class; fancier 'hide' view config support
drewp@bigasterisk.com
parents:
128
diff
changeset
|
6 DEL = "-", |
cf642d395be4
new simpler Patch class; fancier 'hide' view config support
drewp@bigasterisk.com
parents:
128
diff
changeset
|
7 } |
cf642d395be4
new simpler Patch class; fancier 'hide' view config support
drewp@bigasterisk.com
parents:
128
diff
changeset
|
8 |
128 | 9 export class Patch { |
139
cf642d395be4
new simpler Patch class; fancier 'hide' view config support
drewp@bigasterisk.com
parents:
128
diff
changeset
|
10 quads: Quad[] = []; |
cf642d395be4
new simpler Patch class; fancier 'hide' view config support
drewp@bigasterisk.com
parents:
128
diff
changeset
|
11 |
cf642d395be4
new simpler Patch class; fancier 'hide' view config support
drewp@bigasterisk.com
parents:
128
diff
changeset
|
12 constructor(public direction: PatchDirection) {} |
cf642d395be4
new simpler Patch class; fancier 'hide' view config support
drewp@bigasterisk.com
parents:
128
diff
changeset
|
13 |
128 | 14 toString(): string { |
139
cf642d395be4
new simpler Patch class; fancier 'hide' view config support
drewp@bigasterisk.com
parents:
128
diff
changeset
|
15 return `Patch ${this.direction} ${this.quads.length}`; |
128 | 16 } |
17 | |
18 public async streamImport(quadStream: Stream): Promise<void> { | |
19 return new Promise((resolve, reject) => { | |
20 quadStream.on("data", (quad) => { | |
139
cf642d395be4
new simpler Patch class; fancier 'hide' view config support
drewp@bigasterisk.com
parents:
128
diff
changeset
|
21 this.quads.push(quad); |
128 | 22 }); |
23 quadStream.on("error", reject); | |
24 quadStream.on("end", resolve); | |
25 }); | |
26 } | |
27 | |
28 public applyToStore(s: Store) { | |
139
cf642d395be4
new simpler Patch class; fancier 'hide' view config support
drewp@bigasterisk.com
parents:
128
diff
changeset
|
29 if (this.direction == PatchDirection.ADD) { |
cf642d395be4
new simpler Patch class; fancier 'hide' view config support
drewp@bigasterisk.com
parents:
128
diff
changeset
|
30 s.addQuads(this.quads); |
cf642d395be4
new simpler Patch class; fancier 'hide' view config support
drewp@bigasterisk.com
parents:
128
diff
changeset
|
31 } else { |
cf642d395be4
new simpler Patch class; fancier 'hide' view config support
drewp@bigasterisk.com
parents:
128
diff
changeset
|
32 s.removeQuads(this.quads); |
cf642d395be4
new simpler Patch class; fancier 'hide' view config support
drewp@bigasterisk.com
parents:
128
diff
changeset
|
33 } |
cf642d395be4
new simpler Patch class; fancier 'hide' view config support
drewp@bigasterisk.com
parents:
128
diff
changeset
|
34 } |
cf642d395be4
new simpler Patch class; fancier 'hide' view config support
drewp@bigasterisk.com
parents:
128
diff
changeset
|
35 public isEmpty(): boolean { |
cf642d395be4
new simpler Patch class; fancier 'hide' view config support
drewp@bigasterisk.com
parents:
128
diff
changeset
|
36 return this.quads.length == 0; |
128 | 37 } |
38 } |