Skip to content
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

Merged
merged 2 commits into from
Oct 4, 2017
Merged

[import] Allow importing from array #228

merged 2 commits into from
Oct 4, 2017

Conversation

rexxars
Copy link
Member

@rexxars rexxars commented Oct 3, 2017

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.

@rexxars rexxars requested a review from bjoerge October 3, 2017 14:23
Copy link
Member

@bjoerge bjoerge left a 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) {
Copy link
Member

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)) {
Copy link
Member

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call!

@rexxars rexxars requested a review from bjoerge October 4, 2017 07:20
@rexxars rexxars merged commit bfbe172 into next Oct 4, 2017
@rexxars rexxars deleted the import-from-array branch October 4, 2017 07:25
rexxars added a commit that referenced this pull request Oct 6, 2017
bjoerge pushed a commit that referenced this pull request Oct 11, 2017
bjoerge pushed a commit that referenced this pull request Oct 11, 2017
bjoerge pushed a commit that referenced this pull request Oct 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants