UNPKG

rdf-streaming-store

Version:

A read-only RDF/JS store that allows parallel data lookup and insertion.

47 lines (46 loc) 2.23 kB
/// <reference types="node" /> import type { EventEmitter } from 'events'; import type * as RDF from '@rdfjs/types'; import { Store } from 'n3'; import { Readable } from 'readable-stream'; import { PendingStreamsIndex } from './PendingStreamsIndex'; type ListenerCallback = () => void; interface ILocalStore<Q extends RDF.BaseQuad> extends RDF.Store<Q> { countQuads: (subject: RDF.Term | null, predicate: RDF.Term | null, object: RDF.Term | null, graph: RDF.Term | null) => number; } /** * A StreamingStore allows data lookup and insertion to happen in parallel. * Concretely, this means that `match()` calls happening before `import()` calls, will still consider those triples that * are inserted later, which is done by keeping the response streams of `match()` open. * Only when the `end()` method is invoked, all response streams will close, and the StreamingStore will be considered * immutable. * * WARNING: `end()` MUST be called at some point, otherwise all `match` streams will remain unended. */ export declare class StreamingStore<Q extends RDF.BaseQuad = RDF.Quad, S extends ILocalStore<Q> = Store<Q>> implements RDF.Source<Q>, RDF.Sink<RDF.Stream<Q>, EventEmitter> { protected readonly store: S; protected readonly pendingStreams: PendingStreamsIndex<Q>; protected ended: boolean; protected listeners: ListenerCallback[]; constructor(store?: RDF.Store<Q>); addEndListener(listener: ListenerCallback): void; private emitEndEvent; hasEnded(): boolean; /** * Mark this store as ended. * * This will make sure that all running and future `match` calls will end, * and all next `import` calls to this store will throw an error. * It will run all the listeners added with `addEndListener`. */ end(): void; protected importToListeners(stream: RDF.Stream<Q>): void; protected static concatStreams(readables: Readable[]): AsyncIterableIterator<any>; import(stream: RDF.Stream<Q>): EventEmitter; match(subject?: RDF.Term | null, predicate?: RDF.Term | null, object?: RDF.Term | null, graph?: RDF.Term | null): RDF.Stream<Q>; /** * The internal store with all imported quads. */ getStore(): S; } export {};