import { ISubscribableDataset, ITransactionDataset, ITransactionDatasetFactory, nodeEventListener } from "./types.mjs"; import { ExtendedDataset } from "@ldo/dataset"; import { EventEmitter } from "events"; import { DatasetChanges, QuadMatch } from "@ldo/rdf-utils"; import { BaseQuad, Dataset, DatasetFactory, Term } from "@rdfjs/types"; //#region src/SubscribableDataset.d.ts /** * A wrapper for a dataset that allows subscriptions to be made on nodes to * be triggered whenever a quad containing that added or removed. */ declare class SubscribableDataset extends ExtendedDataset implements ISubscribableDataset { /** * DatasetFactory for creating new datasets */ protected datasetFactory: DatasetFactory; /** * The underlying event emitter */ protected eventEmitter: EventEmitter; /** * The underlying dataset factory for creating transaction datasets */ protected transactionDatasetFactory: ITransactionDatasetFactory; /** * Helps find all the events for a given listener */ protected listenerHashMap: Map, Set>; /** * @param datasetFactory A RDF/JS Dataset Factory * @param initialDataset An RDF/JS Dataset with initial Quads */ constructor(datasetFactory: DatasetFactory, transactionDatasetFactory: ITransactionDatasetFactory, initialDataset?: Dataset); /** * ================================================================== * DATASET METHODS * ================================================================== */ /** * A helper method that mimics what the super of addAll would be */ private superAddAll; /** * Imports the quads into this dataset. * 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. * @param quads * @returns the dataset instance it was called on. */ addAll(quads: Dataset | InAndOutQuad[]): this; /** * Bulk add and remove triples * @param changed */ bulk(changed: DatasetChanges): this; /** * 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. * @param subject * @param predicate * @param object * @param graph * @returns the dataset instance it was called on. */ deleteMatches(subject?: Term, predicate?: Term, object?: Term, graph?: Term): this; /** * Adds the specified quad to the dataset. * Existing quads, as defined in Quad.equals, will be ignored. * @param quad * @returns the dataset instance it was called on. */ add(quad: InAndOutQuad): this; /** * Removes the specified quad from the dataset. * This method returns the dataset instance it was called on. * @param quad */ delete(quad: InAndOutQuad): this; /** * ================================================================== * EVENTEMITTER METHODS * ================================================================== */ /** * Triggers all subscriptions based on an updated quads * @param changed The changed triples of the transaction */ protected triggerSubscriptionForQuads(changed: DatasetChanges): void; /** * Alias for emitter.on(eventName, listener). * @param eventName * @param listener * @returns */ addListener(eventName: QuadMatch, listener: nodeEventListener): this; /** * Synchronously calls each of the listeners registered for the event named eventName, in the order they were registered, passing the supplied arguments to each. * @param eventName * @param dataset * @param datasetChanges * @returns true if the event had listeners, false otherwise. */ emit(eventName: QuadMatch, changes: DatasetChanges): boolean; /** * Returns an array listing the events for which the emitter has registered listeners. The values in the array are strings or Symbols. */ eventNames(): QuadMatch[]; /** * Returns the current max listener value for the EventEmitter which is either set by emitter.setMaxListeners(n) or defaults to events.defaultMaxListeners. */ getMaxListeners(): number; /** * Returns the number of listeners listening to the event named eventName. */ listenerCount(eventName: QuadMatch): number; /** * Returns a copy of the array of listeners for the event named eventName. */ listeners(eventName: QuadMatch): nodeEventListener[]; /** * Alias for emitter.removeListener() */ off(eventName: QuadMatch, listener: nodeEventListener): void; /** * Adds the listener function to the end of the listeners array for the event named eventName. No checks are made to see if the listener has already been added. Multiple calls passing the same combination of eventName and listener will result in the listener being added, and called, multiple times. */ on(eventName: QuadMatch, listener: nodeEventListener): this; /** * Adds a one-time listener function for the event named eventName. The next time eventName is triggered, this listener is removed and then invoked. */ once(eventName: QuadMatch, listener: nodeEventListener): this; /** * Adds the listener function to the beginning of the listeners array for the event named eventName. No checks are made to see if the listener has already been added. Multiple calls passing the same combination of eventName and listener will result in the listener being added, and called, multiple times. */ prependListener(eventName: QuadMatch, listener: nodeEventListener): this; /** * Adds a one-time listener function for the event named eventName to the beginning of the listeners array. The next time eventName is triggered, this listener is removed, and then invoked. */ prependOnceListener(eventName: QuadMatch, listener: nodeEventListener): this; /** * Removes all listeners, or those of the specified eventName. */ removeAllListeners(eventName: QuadMatch): this; /** * Removes the specified listener from the listener array for the event named eventName. */ removeListener(eventName: QuadMatch, listener: nodeEventListener): this; /** * Removes the specified listener from the listener array for the event named eventName. */ removeListenerFromAllEvents(listener: nodeEventListener): this; /** * By default EventEmitters will print a warning if more than 10 listeners are added for a particular event. This is a useful default that helps finding memory leaks. The emitter.setMaxListeners() method allows the limit to be modified for this specific EventEmitter instance. The value can be set to Infinity (or 0) to indicate an unlimited number of listeners. */ setMaxListeners(n: number): this; /** * Returns a copy of the array of listeners for the event named eventName, including any wrappers (such as those created by .once()). */ rawListeners(eventName: QuadMatch): nodeEventListener[]; /** * ================================================================== * TRANSACTION METHODS * ================================================================== */ /** * Returns a transactional dataset that will update this dataset when its transaction is committed. */ startTransaction(): ITransactionDataset; } //#endregion export { SubscribableDataset }; //# sourceMappingURL=SubscribableDataset.d.mts.map