-
Notifications
You must be signed in to change notification settings - Fork 392
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[import] Allow importing from array #228
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few minor nits, otherwise 👏
@@ -14,17 +15,22 @@ const { | |||
strengthenReferences | |||
} = require('./references') | |||
|
|||
async function importFromStream(stream, opts) { | |||
const options = validateOptions(stream, opts) | |||
async function importFromStream(input, opts) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps this should be renamed to better reflect that it takes a mixed input?
throw new Error( | ||
'Stream does not seem to be a readable stream - no "pipe" method found' | ||
) | ||
if (typeof input.pipe !== 'function' && !Array.isArray(input)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe protect against undefined/null as input here too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call!
Currently the import module only accepts a stream. Having to wrap an array of documents in a stream feels weird and unnecessary. This PR ensures that you can call the import with either a stream or an array of documents.