Skip to content

Commit 2320a1d

Browse files
Update sailor version to 2.6.7 (#38)
1 parent 42aeb6b commit 2320a1d

File tree

8 files changed

+1109
-973
lines changed

8 files changed

+1109
-973
lines changed

.eslintrc.js

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,29 @@
11
module.exports = {
2-
"extends": "airbnb-base",
3-
"env": {
4-
"mocha": true,
5-
"node": true
2+
extends: 'airbnb-base',
3+
rules: {
4+
},
5+
env: {
6+
node: true,
7+
mocha: true,
8+
},
9+
overrides: [
10+
{
11+
files: [
12+
'*.test.js',
13+
'*.spec*',
14+
],
15+
rules: {
16+
'no-unused-expressions': 'off',
17+
},
618
},
7-
"overrides": [
8-
{
9-
"files": ["*.test.js", "*.spec.js"],
10-
"rules": {
11-
"no-unused-expressions": "off",
12-
}
13-
},
14-
{
15-
"files": ["*"],
16-
"rules": {
17-
"no-plusplus" : "off",
18-
"no-await-in-loop": "off",
19-
}
20-
}
21-
]
19+
{
20+
files: [
21+
'*',
22+
],
23+
rules: {
24+
'max-len': ['error', { code: 180 }],
25+
26+
},
27+
},
28+
],
2229
};

.jscsrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,4 @@
8888
"maximum": 5
8989
},
9090
"validateParameterSeparator": ", "
91-
}
91+
}

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 1.2.0 (May 19, 2020)
2+
3+
* Update sailor version to 2.6.7
4+
* Add support for more node global objects
5+
16
## 1.1.1 (January 30, 2020)
27

38
* Update sailor version to 2.6.1
@@ -14,4 +19,3 @@ Fixed bug:
1419
## 1.0.0 (August 2, 2019)
1520

1621
* Initial release which includes a bunch of previous unversioned releases.
17-

README.md

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,20 @@ However, don't let the simple look fool you - it has a full-fledged interface wi
2121

2222
## Available Variables and Libraries
2323
Here are the available variables and libraries that can be used within the context of execution. The most up-to-date list
24-
can always be found in be used within the context of execution. The most up-to-date list can always be found in code.js
25-
of the component. Below is a sample for the reference:
26-
27-
- `console` - more on [Node.js console](https://nodejs.org/dist/latest-v5.x/docs/api/console.html)
28-
- `process` - current Node.js process
29-
- `require` - module require
30-
- `setTimeout` - more on [setTimeout](https://nodejs.org/dist/latest-v5.x/docs/api/timers.html)
31-
- `clearTimeout` - more on [clearTimeout](https://nodejs.org/dist/latest-v5.x/docs/api/timers.html)
32-
- `setInterval` - more on setInterval
33-
- `clearInterval` - more on clearInterval
34-
- `msg` - incoming message containing the payload from the previous step
35-
- `cfg` - step's configuration. At the moment contains only one property: `code` (the code, being executed)
36-
- `snapshot` - step's snapshot
37-
- `exports` - just a plain object `{}`
38-
- `messages` - utility for convenient message creation
39-
- `request` - Http Client (wrapped in `co` - [this library](https://www.npmjs.com/package/co-request))
40-
- `wait` - wait
41-
- `emitter` user to emit messages and errors
24+
can always be found in be used within the context of execution or in `code.js` of the component. Below is a sample for the reference.
25+
Built-in Node.js global objects are also supported.
26+
27+
### Elastic.io Specific Functionality
28+
- `msg` - incoming message containing the payload from the previous step
29+
- `cfg` - step's configuration. At the moment contains only one property: `code` (the code, being executed)
30+
- `snapshot` - step's snapshot
31+
- `messages` - utility for convenient message creation
32+
- `emitter` user to emit messages and errors
33+
34+
### Other Libraries/functions
35+
- `wait(numberOfMilliscondsToSleep)` - Utility function for sleeping
36+
- [`request`](https://github.com/request/request) - Http Client (wrapped in `co` - [this library](https://www.npmjs.com/package/co-request) so that it is pre-promisified)
37+
- `_` - [Lodash](https://lodash.com/)
4238

4339
## Code component usage Examples
4440

@@ -98,3 +94,4 @@ async function run(msg, cfg, snapshot) {
9894
## Known issues and limitations
9995

10096
- Credentials are not supported
97+

actions/code.js

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,52 +8,63 @@ const request = require('co-request');
88
function wait(timeout) {
99
return new Promise((ok) => {
1010
setTimeout(() => {
11-
this.logger.info('Done wait');
11+
this.logger.debug('Done wait');
1212
ok();
1313
}, timeout);
14-
this.logger.info('Start wait sec=%s', timeout);
14+
this.logger.debug('Start wait sec=%s', timeout);
1515
});
1616
}
1717

1818
// eslint-disable-next-line consistent-return,func-names
1919
exports.process = async function (msg, conf, snapshot) {
20+
const vmExports = {};
2021
const ctx = vm.createContext({
21-
_,
22+
// Node Globals
23+
Buffer,
24+
clearInterval,
25+
clearTimeout,
2226
console,
27+
exports: vmExports,
28+
global: {},
29+
module: { exports: vmExports },
2330
process,
2431
require,
25-
setTimeout,
26-
clearTimeout,
2732
setInterval,
28-
clearInterval,
29-
msg,
30-
exports: {},
33+
setTimeout,
34+
URL,
35+
URLSearchParams,
36+
37+
// EIO Specific Functionality
38+
emitter: this,
3139
messages,
40+
msg,
41+
42+
// Other Libraries
43+
_,
3244
request,
3345
wait: wait.bind(this),
34-
emitter: this,
3546
});
36-
this.logger.info('Running the code %s', conf.code);
47+
this.logger.debug('Running the code %s', conf.code);
3748
vm.runInContext(conf.code, ctx, {
3849
displayErrors: true,
3950
});
40-
this.logger.info("No result, let's check the run object if it was created?");
51+
this.logger.debug("No result, let's check the run object if it was created?");
4152
if (ctx.run && typeof ctx.run.apply === 'function') {
4253
let result;
4354
if (ctx.run.constructor.name === 'GeneratorFunction') {
44-
this.logger.info('Run variable is a generator');
55+
this.logger.debug('Run variable is a generator');
4556
const fn = co.wrap(ctx.run);
4657
result = fn.apply(this, [msg, conf, snapshot]);
4758
} else {
48-
this.logger.info('Run variable is a function, calling it');
59+
this.logger.debug('Run variable is a function, calling it');
4960
result = ctx.run.apply(this, [msg, conf, snapshot]);
5061
}
5162
if (typeof result === 'object' && typeof result.then === 'function') {
52-
this.logger.info('Returned value is a promise, will evaluate it');
63+
this.logger.debug('Returned value is a promise, will evaluate it');
5364
let returnResult;
5465
try {
5566
returnResult = await result;
56-
this.logger.info('Promise resolved');
67+
this.logger.debug('Promise resolved');
5768
if (returnResult) {
5869
return messages.newMessageWithBody(returnResult);
5970
}
@@ -64,7 +75,7 @@ exports.process = async function (msg, conf, snapshot) {
6475
}
6576
}
6677
} else {
67-
this.logger.info("Run function was not found, it's over now");
78+
this.logger.debug("Run function was not found, it's over now");
6879
this.emit('end');
6980
}
7081
};

0 commit comments

Comments
 (0)