Skip to content

Commit c6a851a

Browse files
authored
Sprint 39 master (#68)
* Add the steward URL to the body of the outgoing message * Wrapping csv inputs in json objects
1 parent b56737a commit c6a851a

File tree

10 files changed

+72
-44
lines changed

10 files changed

+72
-44
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
## 2.1.0 (May 7, 2020)
1+
## 2.1.1 (May 7, 2020)
2+
3+
* Add input metadata for objects processing
4+
* Add the steward URL to the body of the outgoing message
5+
6+
## 2.1.0 (April 22, 2020)
27

38
* Add "Write CSV attachment from Array" action
49
* Add "Write CSV attachment from JSON" action

README.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ This action will convert an incoming array into a CSV file by following approach
117117

118118
Requirements:
119119

120-
* The inbound message is an JSON Object;
120+
* The inbound message is an JSON Object, wrapped by 'inputObject' object;
121121
* This JSON object has plain structure without nested levels (structured types `objects` and `arrays` are not supported as values). Only primitive types are supported: `strings`, `numbers`, `booleans` and `null`. Otherwise, the error message will be thrown: `Inbound message should be a plain Object. At least one of entries is not a primitive type`.
122122

123123
The keys of an input JSON will be published as the header in the first row. For each incoming
@@ -126,9 +126,9 @@ for that cell. All other properties will be ignored. For example, headers
126126
`foo,bar` along with the following JSON events:
127127

128128
```
129-
{"foo":"myfoo", "bar":"mybar"}
130-
{"foo":"myfoo", "bar":[1,2]}
131-
{"bar":"mybar", "baz":"mybaz"}
129+
{"inputObject": {"foo":"myfoo", "bar":"mybar"}}
130+
{"inputObject": {"foo":"myfoo", "bar":[1,2]}}
131+
{"inputObject": {"bar":"mybar", "baz":"mybaz"}}
132132
```
133133

134134
will produce the following `.csv` file:
@@ -158,7 +158,7 @@ This action will convert an incoming array into a CSV file by following approach
158158

159159
Requirements:
160160

161-
* The inbound message is an JSON Array of Objects with identical structure;
161+
* The inbound message is an JSON Array of Objects with identical structure, wrapped by 'inputArray' object;
162162
* Each JSON object has plain structure without nested levels (structured types `objects` and `arrays` are not supported as values). Only primitive types are supported: `strings`, `numbers`, `booleans` and `null`. Otherwise, the error message will be thrown: `Inbound message should be a plain Object. At least one of entries is not a primitive type`.
163163

164164
The keys of an input JSON will be published as the header in the first row. For each incoming
@@ -167,11 +167,13 @@ for that cell. All other properties will be ignored. For example, headers
167167
`foo,bar` along with the following JSON events:
168168

169169
```
170-
[
171-
{"foo":"myfoo", "bar":"mybar"}
172-
{"foo":"myfoo", "bar":[1,2]}
173-
{"bar":"mybar", "baz":"mybaz"}
174-
]
170+
{
171+
"inputArray": [
172+
{"foo":"myfoo", "bar":"mybar"}
173+
{"foo":"myfoo", "bar":[1,2]}
174+
{"bar":"mybar", "baz":"mybaz"}
175+
]
176+
}
175177
```
176178

177179
will produce the following `.csv` file:

component.json

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,12 @@
117117
"metadata": {
118118
"in": {
119119
"type": "object",
120-
"properties": {}
120+
"properties": {
121+
"inputObject": {
122+
"type": "object",
123+
"properties": {}
124+
}
125+
}
121126
},
122127
"out": {}
123128
}
@@ -156,11 +161,16 @@
156161
},
157162
"metadata": {
158163
"in": {
159-
"type": "array",
160-
"properties": {}
164+
"type": "object",
165+
"properties": {
166+
"inputArray": {
167+
"type": "array",
168+
"items": {}
169+
}
170+
}
161171
},
162172
"out": {}
163173
}
164174
}
165175
}
166-
}
176+
}

lib/actions/write.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ async function ProcessAction(msg, cfg) {
7777

7878
const messageToEmit = messages.newMessageWithBody({
7979
rowCount: finalRowCount,
80+
url: signedUrl.get_url,
8081
});
8182
const fileName = `${messageToEmit.id}.csv`;
8283
messageToEmit.attachments[fileName] = {

lib/actions/writeFromArray.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,17 @@ async function init(cfg) {
5959
async function ProcessAction(msg) {
6060
// eslint-disable-next-line consistent-this
6161
const self = this;
62+
const { inputArray } = msg.body;
6263
let isError = false;
6364
let errorValue = '';
6465

65-
const columns = Object.keys(msg.body[0]);
66-
rowCount = msg.body.length;
66+
const columns = Object.keys(inputArray[0]);
67+
rowCount = inputArray.length;
6768
logger.trace('Configured column names:', columns);
6869
let row = {};
6970

70-
await _.each(msg.body, async (item) => {
71-
const entries = Object.values(msg.body);
71+
await _.each(inputArray, async (item) => {
72+
const entries = Object.values(inputArray);
7273
// eslint-disable-next-line no-restricted-syntax
7374
for (const entry of entries) {
7475
if (isError) {
@@ -104,6 +105,7 @@ async function ProcessAction(msg) {
104105

105106
const messageToEmit = messages.newMessageWithBody({
106107
rowCount,
108+
url: signedUrl.get_url,
107109
});
108110
const fileName = `${messageToEmit.id}.csv`;
109111
messageToEmit.attachments[fileName] = {

lib/actions/writeFromJson.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,12 @@ async function init(cfg) {
6464
async function ProcessAction(msg) {
6565
// eslint-disable-next-line consistent-this
6666
const self = this;
67+
const { inputObject } = msg.body;
6768

68-
const columns = Object.keys(msg.body);
69+
const columns = Object.keys(inputObject);
6970
logger.trace('Configured column names:', columns);
7071

71-
const values = Object.values(msg.body);
72+
const values = Object.values(inputObject);
7273
// eslint-disable-next-line no-restricted-syntax
7374
for (const value of values) {
7475
if (value !== null && value !== undefined && (typeof value === 'object' || Array.isArray(value))) {
@@ -102,6 +103,7 @@ async function ProcessAction(msg) {
102103

103104
const messageToEmit = messages.newMessageWithBody({
104105
rowCount: finalRowCount,
106+
url: signedUrl.get_url,
105107
});
106108
const fileName = `${messageToEmit.id}.csv`;
107109
messageToEmit.attachments[fileName] = {
@@ -114,7 +116,7 @@ async function ProcessAction(msg) {
114116
await self.emit('data', messageToEmit);
115117
}, TIMEOUT_BETWEEN_EVENTS);
116118

117-
let row = msg.body;
119+
let row = inputObject;
118120
self.logger.trace(`Incoming data: ${JSON.stringify(row)}`);
119121
row = _.pick(row, columns);
120122

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "csv-component",
3-
"version": "2.1.0",
3+
"version": "2.1.1",
44
"description": "CSV Component for elastic.io platform",
55
"main": "index.js",
66
"scripts": {

spec/writeFromArray.spec.js

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -51,22 +51,24 @@ describe('CSV Write From Array component', function () {
5151
}, cfg);
5252

5353
const msg = {
54-
body: [
55-
{
56-
name: 'Bob',
57-
email: 'bob@email.domain',
58-
age: 30,
59-
key1: true,
60-
'not an age': null,
61-
'not an age at all': undefined,
62-
},
63-
{
64-
name: 'Joe',
65-
email: 'joe@email.domain',
66-
age: 11,
67-
'not an age at all': 322,
68-
},
69-
],
54+
body: {
55+
inputArray: [
56+
{
57+
name: 'Bob',
58+
email: 'bob@email.domain',
59+
age: 30,
60+
key1: true,
61+
'not an age': null,
62+
'not an age at all': undefined,
63+
},
64+
{
65+
name: 'Joe',
66+
email: 'joe@email.domain',
67+
age: 11,
68+
'not an age at all': 322,
69+
},
70+
],
71+
},
7072
};
7173

7274
await write.process.call({

spec/writeFromJson.spec.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,10 @@ describe('CSV Write From JSON component', function () {
5252

5353
const msg1 = {
5454
body: {
55-
ProductKey: 'text11',
56-
CategoryGroup_1: 'text12',
55+
inputObject: {
56+
ProductKey: 'text11',
57+
CategoryGroup_1: 'text12',
58+
},
5759
},
5860
};
5961

@@ -64,8 +66,10 @@ describe('CSV Write From JSON component', function () {
6466

6567
const msg2 = {
6668
body: {
67-
ProductKey: 'text21',
68-
CategoryGroup_1: 'text22',
69+
inputObject: {
70+
ProductKey: 'text21',
71+
CategoryGroup_1: 'text22',
72+
},
6973
},
7074
};
7175

0 commit comments

Comments
 (0)