Skip to content

Commit cefbb1e

Browse files
Merge pull request #34 from elasticio/emit-all
emitAll feature
2 parents c0166d6 + 47ef1fc commit cefbb1e

File tree

7 files changed

+870
-766
lines changed

7 files changed

+870
-766
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,4 @@ build/Release
2828
# Dependency directory
2929
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
3030
node_modules
31+
package-lock.json

CHANGELOG.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
## 1.1.4 (June 27, 2019)
2+
3+
* Added emitAll feature for CSV Write action
4+
5+
## 1.1.3 (October 31, 2017)
6+
7+
* Make CSV Write dynamic configuration
8+
9+
## 1.1.2 (September 21, 2017)
10+
11+
* Supporting startRow option
12+
13+
## 1.1.1 (June 18, 2017)
14+
15+
* Updated sailor to 2.1.3
16+
17+
## 1.1.0 (June 8, 2017)
18+
19+
* Added new CSV Write action
20+
21+
## 1.0.1 (January 7, 2016)
22+
23+
* Updated sailor to 1.1.0
24+
25+
## 1.0.0 (November 3, 2015)
26+
27+
* Initial release

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,30 @@ This trigger will fetch the CSV file from a given URL. The address must be acces
2929
to the component. The fetched CSV file will be placed in the attachment part of the
3030
outgoing message.
3131

32+
![image](https://user-images.githubusercontent.com/40201204/60707311-190dae00-9f14-11e9-81a8-d48d9dcd1d03.png)
33+
34+
* `CSV URL` - the full URL to the file for retrieving data.
35+
* `Emit all messages` - this checkbox configures output behavior of the component. If the option is checked - the component emits an array of messages, otherwise - the component emits a message per row.
36+
* `CSV Header` - this is a required field. Input the names of headers separated with a comma.
37+
* `Separators` - Specify the separator type. Usually it is a comma (`,`) but values like Semicolon (`;`), Space (` `), Tab (`\t`) and Hash (`#`) are also supported.
38+
* `Skip rows` - if you know that the incoming CSV file has certain number of headers you can indicate to skip them. The supported values are `None`, `First row`, `First two`, `First three` and `First four`.
39+
* `Data columns` - here the values will be added dynamically based on the values in the `CSV Header` field. Here each data column will be listed with the name, Data Type and the Format to enable further configuration.
40+
3241
## Actions
3342

3443
### Read CSV attachment
3544

3645
This action will read the CSV attachment of the incoming message and output
3746
a `JSON` object. To configure this action the following fields can be used:
3847

48+
* `Emit all messages` - this checkbox configures output behavior of the component. If the option is checked - the component emits an array of messages, otherwise - the component emits a message per row.
3949
* `CSV Header` - this is a required field. Input the names of headers separated with a comma.
4050
* `Separators` - Specify the separator type. Usually it is a comma (`,`) but values like Semicolon (`;`), Space (` `), Tab (`\t`) and Hash (`#`) are also supported.
41-
* `Skip rows` - if you know that the incoming CSV file has certain number of headers you can indicate to skip them. The supported values are `None`, `First row`, `First two`, `Dirst three` and `First four`.
51+
* `Skip rows` - if you know that the incoming CSV file has certain number of headers you can indicate to skip them. The supported values are `None`, `First row`, `First two`, `First three` and `First four`.
4252
* `Data columns` - here the values will be added dynamically based on the values in the `CSV Header` field. Here each data column will be listed with the name, Data Type and the Format to enable further configuration.
4353

54+
![image](https://user-images.githubusercontent.com/40201204/60706373-fda1a380-9f11-11e9-8b5a-2acd2df33a87.png)
55+
4456

4557
### Write CSV attachment
4658

component.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929
"main": "./lib/read.js",
3030
"title": "Read CSV attachment",
3131
"fields": {
32+
"emitAll": {
33+
"label": "Emit all messages",
34+
"viewClass": "CheckBoxView"
35+
},
3236
"reader": {
3337
"viewClass": "CSVReadView",
3438
"required": true

lib/read.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,23 @@ async function ProcessRead(msg, cfg) {
8383

8484
let ended = false;
8585

86+
const outputMsg = {
87+
result: []
88+
};
89+
8690
class CsvWriter extends Writable {
8791
async write(chunk, encoding, callback) {
8892
parser.pause();
8993
debug('Processing %d row...', index);
9094
debug('Memory usage: %d Mb', process.memoryUsage().heapUsed / 1024 / 1024);
91-
9295
if (index >= startRow) {
9396
const msg = createRowMessage(chunk, cfg.reader.columns);
94-
await that.emit('data', msg);
97+
if (cfg.emitAll) {
98+
debug('Row #%s added to result array', index);
99+
outputMsg.result.push(msg.body);
100+
} else {
101+
await that.emit('data', msg);
102+
}
95103
} else {
96104
debug('Row #%s is skipped based on configuration', index);
97105
}
@@ -100,6 +108,9 @@ async function ProcessRead(msg, cfg) {
100108
}
101109

102110
async end(chunk, encoding, callback) {
111+
if (cfg.emitAll) {
112+
await that.emit('data', messages.newMessageWithBody(outputMsg));
113+
}
103114
debug('Processing csv writer end event...');
104115
debug('Memory usage: %d Mb', process.memoryUsage().heapUsed / 1024 / 1024);
105116

0 commit comments

Comments
 (0)