Skip to content

update sailor version to 2.6.7 #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 26 additions & 19 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
module.exports = {
"extends": "airbnb-base",
"env": {
"mocha": true,
"node": true
extends: 'airbnb-base',
rules: {
},
env: {
node: true,
mocha: true,
},
overrides: [
{
files: [
'*.test.js',
'*.spec*',
],
rules: {
'no-unused-expressions': 'off',
},
},
"overrides": [
{
"files": ["*.test.js", "*.spec.js"],
"rules": {
"no-unused-expressions": "off",
}
},
{
"files": ["*"],
"rules": {
"no-plusplus" : "off",
"no-await-in-loop": "off",
}
}
]
{
files: [
'*',
],
rules: {
'max-len': ['error', { code: 180 }],

},
},
],
};
2 changes: 1 addition & 1 deletion .jscsrc
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,4 @@
"maximum": 5
},
"validateParameterSeparator": ", "
}
}
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 1.2.0 (May 19, 2020)

* Update sailor version to 2.6.7
* Add support for more node global objects

## 1.1.1 (January 30, 2020)

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

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

33 changes: 15 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,20 @@ However, don't let the simple look fool you - it has a full-fledged interface wi

## Available Variables and Libraries
Here are the available variables and libraries that can be used within the context of execution. The most up-to-date list
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
of the component. Below is a sample for the reference:

- `console` - more on [Node.js console](https://nodejs.org/dist/latest-v5.x/docs/api/console.html)
- `process` - current Node.js process
- `require` - module require
- `setTimeout` - more on [setTimeout](https://nodejs.org/dist/latest-v5.x/docs/api/timers.html)
- `clearTimeout` - more on [clearTimeout](https://nodejs.org/dist/latest-v5.x/docs/api/timers.html)
- `setInterval` - more on setInterval
- `clearInterval` - more on clearInterval
- `msg` - incoming message containing the payload from the previous step
- `cfg` - step's configuration. At the moment contains only one property: `code` (the code, being executed)
- `snapshot` - step's snapshot
- `exports` - just a plain object `{}`
- `messages` - utility for convenient message creation
- `request` - Http Client (wrapped in `co` - [this library](https://www.npmjs.com/package/co-request))
- `wait` - wait
- `emitter` user to emit messages and errors
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.
Built-in Node.js global objects are also supported.

### Elastic.io Specific Functionality
- `msg` - incoming message containing the payload from the previous step
- `cfg` - step's configuration. At the moment contains only one property: `code` (the code, being executed)
- `snapshot` - step's snapshot
- `messages` - utility for convenient message creation
- `emitter` user to emit messages and errors

### Other Libraries/functions
- `wait(numberOfMilliscondsToSleep)` - Utility function for sleeping
- [`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)
- `_` - [Lodash](https://lodash.com/)

## Code component usage Examples

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

- Credentials are not supported

43 changes: 27 additions & 16 deletions actions/code.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,52 +8,63 @@ const request = require('co-request');
function wait(timeout) {
return new Promise((ok) => {
setTimeout(() => {
this.logger.info('Done wait');
this.logger.debug('Done wait');
ok();
}, timeout);
this.logger.info('Start wait sec=%s', timeout);
this.logger.debug('Start wait sec=%s', timeout);
});
}

// eslint-disable-next-line consistent-return,func-names
exports.process = async function (msg, conf, snapshot) {
const vmExports = {};
const ctx = vm.createContext({
_,
// Node Globals
Buffer,
clearInterval,
clearTimeout,
console,
exports: vmExports,
global: {},
module: { exports: vmExports },
process,
require,
setTimeout,
clearTimeout,
setInterval,
clearInterval,
msg,
exports: {},
setTimeout,
URL,
URLSearchParams,

// EIO Specific Functionality
emitter: this,
messages,
msg,

// Other Libraries
_,
request,
wait: wait.bind(this),
emitter: this,
});
this.logger.info('Running the code %s', conf.code);
this.logger.debug('Running the code %s', conf.code);
vm.runInContext(conf.code, ctx, {
displayErrors: true,
});
this.logger.info("No result, let's check the run object if it was created?");
this.logger.debug("No result, let's check the run object if it was created?");
if (ctx.run && typeof ctx.run.apply === 'function') {
let result;
if (ctx.run.constructor.name === 'GeneratorFunction') {
this.logger.info('Run variable is a generator');
this.logger.debug('Run variable is a generator');
const fn = co.wrap(ctx.run);
result = fn.apply(this, [msg, conf, snapshot]);
} else {
this.logger.info('Run variable is a function, calling it');
this.logger.debug('Run variable is a function, calling it');
result = ctx.run.apply(this, [msg, conf, snapshot]);
}
if (typeof result === 'object' && typeof result.then === 'function') {
this.logger.info('Returned value is a promise, will evaluate it');
this.logger.debug('Returned value is a promise, will evaluate it');
let returnResult;
try {
returnResult = await result;
this.logger.info('Promise resolved');
this.logger.debug('Promise resolved');
if (returnResult) {
return messages.newMessageWithBody(returnResult);
}
Expand All @@ -64,7 +75,7 @@ exports.process = async function (msg, conf, snapshot) {
}
}
} else {
this.logger.info("Run function was not found, it's over now");
this.logger.debug("Run function was not found, it's over now");
this.emit('end');
}
};
Loading