Skip to content

Commit

Permalink
fix(analytics): 🐛 attemps to fix combine too
Browse files Browse the repository at this point in the history
  • Loading branch information
touv committed Jul 26, 2020
1 parent 66750ed commit ad42c98
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
27 changes: 17 additions & 10 deletions packages/analytics/src/combine.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,19 @@ import set from 'lodash.set';
import debug from 'debug';
import { createStore } from './store';

async function saveIn(data, feed) {
if (this.isLast()) {
return feed.close();
}
const store = this.getEnv();
const key = get(data, 'id');
const isKey = Boolean(key);
if (isKey) {
await store.put(key, data);
}
return feed.send(key);
}

/**
* Takes an `Object` and substitute a field with the corresponding value found in a external pipeline
* the internal pipeline must produce a stream of special object (id, value)
Expand Down Expand Up @@ -73,17 +86,11 @@ export default function combine(data, feed) {
statements = ezs.compileCommands(commands, this.getEnv());
}
const output = ezs.createPipeline(input, statements)
.pipe(ezs(saveIn, null, this.store))
.pipe(ezs.catch())
.on('data', async (item) => {
const key = get(item, 'id');
const isKey = Boolean(key);

if (isKey) {
await this.store.put(key, item);
}
})
.on('data', (d) => d)
.on('error', (e) => feed.stop(e));
whenReady = new Promise((resolve) => output.on('end', resolve));
whenReady = new Promise((resolve) => output.on('end', () => resolve));
input.write(primer);
input.end();
}
Expand All @@ -107,5 +114,5 @@ export default function combine(data, feed) {
}
return feed.send(data);
})
.catch(/* istanbul ignore next */(e) => feed.stop(e));
.catch((e) => feed.stop(e));
}
1 change: 1 addition & 0 deletions packages/analytics/test/combine.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ describe('combine', () => {

from(input)
.pipe(ezs('combine', { path: 'b', file }))
.pipe(ezs('debug', { text: 'after' }))
.pipe(ezs.catch())
.on('error', done)
.on('data', (chunk) => {
Expand Down

0 comments on commit ad42c98

Please sign in to comment.