Mercurial > code > home > repos > streamed-graph
comparison src/Patch.ts @ 128:5a1a79f54779
big rewrite
author | drewp@bigasterisk.com |
---|---|
date | Fri, 05 May 2023 21:26:36 -0700 |
parents | |
children | cf642d395be4 |
comparison
equal
deleted
inserted
replaced
127:d2580faef057 | 128:5a1a79f54779 |
---|---|
1 import { Quad, Store } from "n3"; | |
2 import { Stream } from "rdf-js"; | |
3 | |
4 export class Patch { | |
5 delQuads: Quad[] = []; | |
6 addQuads: Quad[] = []; | |
7 toString(): string { | |
8 return `Patch -${this.delQuads.length} +${this.addQuads.length}`; | |
9 } | |
10 constructor() { } | |
11 | |
12 // fill `addQuads` with this stream | |
13 public async streamImport(quadStream: Stream): Promise<void> { | |
14 return new Promise((resolve, reject) => { | |
15 quadStream.on("data", (quad) => { | |
16 this.addQuads.push(quad); | |
17 }); | |
18 quadStream.on("error", reject); | |
19 quadStream.on("end", resolve); | |
20 }); | |
21 } | |
22 | |
23 public applyToStore(s: Store) { | |
24 s.removeQuads(this.delQuads); | |
25 s.addQuads(this.addQuads); | |
26 } | |
27 } |