Skip to content

Commit cd8cd3d

Browse files
authored
Adding possibility to emit non-array objects (#51)
Fix jsonata object-array emit return
1 parent 005c220 commit cd8cd3d

File tree

7 files changed

+17
-7
lines changed

7 files changed

+17
-7
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 1.1.4 (August 20, 2020)
2+
* `Split on JSONata Expression` action update: add possibility to emit non-array objects.
3+
14
## 1.1.3 (August 11, 2020)
25
* Update Sailor and dependencies.
36
* Fix node version.

lib/actions/splitOnJsonata.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ async function processAction(msg, cfg) {
99
const split = JsonataTransform.jsonataTransform(msg, cfg, this);
1010

1111
if (!Array.isArray(split)) {
12-
await this.emit('error', new Error('The evaluated expression must be an array.'));
12+
this.logger.warn('The evaluated expression should be an array.');
13+
if (!_.isObject(split)) {
14+
await this.emit('error', new Error("Can't emit single primitive!"));
15+
return;
16+
}
17+
await this.emit('data', messages.newMessageWithBody(split));
1318
return;
1419
}
1520

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": "@elasticio/splitter",
3-
"version": "1.1.3",
3+
"version": "1.1.4",
44
"description": "elastic.io component for splitting incoming messages",
55
"scripts": {
66
"pretest": "eslint split.js lib spec --fix",

spec/splitOnJsonata/data/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ module.exports = {
1818
'should emit error for array of primitives usernames': arrayOfPrimitives,
1919
'should emit empty array': nothingToSplit,
2020
'should split array from an object constructor expression': objectConstructors,
21-
'should emit error for non-array object': objectValue,
21+
'should emit non-array object': objectValue,
2222
'should emit error for non-array primitive': primitiveValue,
2323
'should split array from a range query expression': rangeQuery,
2424
'should split root array': rootArray,

spec/splitOnJsonata/data/objectValue.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111
},
1212
"results": [
1313
[
14-
"error",
15-
"The evaluated expression must be an array."
14+
"data",
15+
{
16+
"name": "John"
17+
}
1618
]
1719
]
1820
}

spec/splitOnJsonata/data/primitiveValue.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"results": [
1111
[
1212
"error",
13-
"The evaluated expression must be an array."
13+
"Can't emit single primitive!"
1414
]
1515
]
1616
}

0 commit comments

Comments
 (0)