rdfjs/dataset-spec

`import` signature (in practice) incompatible with Sink

RubenVerborgh opened this issue · 1 comments

The Dataset signature is

Promise<Dataset> import (Stream stream);

In contrast, the Sink signature is

EventEmitter import (Stream stream);

which makes it hard for objects to implement both cleanly.

In theory, we could return Promise<Dataset> & EventEmitter or even be fancy and do Promise<Dataset & EventEmitter> & EventEmitter for full .then compatibility, but this gets messy.

Any chance we could either rename this method or change its return type?

It would be the same for the match method. I don't think it makes sense to prefix or postfix the methods to distinguish them. The stream and dataset interfaces are for different use cases. The import method of the Dataset is the only method that consumes a Stream and creates a bridge between both worlds. As the Stream is just consumed, using the Dataset interface doesn't require deeper knowledge about the Stream interface. The name import is the best match for this use case. For the rare case where you want to have both interfaces, it's probably better to use different objects for each interface. Like this:

const dataset = factory.dataset()
const store = new DatasetStore(dataset) 

// store.dataset implements the Dataset interface
await store.dataset.import(quadStream)

// store implements the Store interface
store.match().on('data', quad => console.log(quad))