Mercurial > code > home > repos > streamed-graph
view src/Patch.ts @ 128:5a1a79f54779
big rewrite
author | drewp@bigasterisk.com |
---|---|
date | Fri, 05 May 2023 21:26:36 -0700 |
parents | |
children | cf642d395be4 |
line wrap: on
line source
import { Quad, Store } from "n3"; import { Stream } from "rdf-js"; export class Patch { delQuads: Quad[] = []; addQuads: Quad[] = []; toString(): string { return `Patch -${this.delQuads.length} +${this.addQuads.length}`; } constructor() { } // fill `addQuads` with this stream public async streamImport(quadStream: Stream): Promise<void> { return new Promise((resolve, reject) => { quadStream.on("data", (quad) => { this.addQuads.push(quad); }); quadStream.on("error", reject); quadStream.on("end", resolve); }); } public applyToStore(s: Store) { s.removeQuads(this.delQuads); s.addQuads(this.addQuads); } }