GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - openintegrationhub/code-component: The holy grail of the elastic.io platform adapted for Open Integration Hub

BranchesTags
Open more actions menu
 
 

Latest commit

 

History

127 Commits
127 Commits

Folders and files

NameName
Last commit message
Last commit date
.circleci
.circleci
 
 
.github/workflows
.github/workflows
 
 
actions
actions
 
 
spec
spec
 
 
.dockerignore
.dockerignore
 
 
.eslintrc.js
.eslintrc.js
 
 
.gitignore
.gitignore
 
 
.jscsrc
.jscsrc
 
 
Dockerfile
Dockerfile
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
component.json
component.json
 
 
logo.png
logo.png
 
 
package-lock.json
package-lock.json
 
 
package.json
package.json
 
 
start.sh
start.sh
 
 

Repository files navigation

code-component

A code component forked from the elastic.io code-component, runs a piece of a JavaScript code inside your flow.

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 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). May contain further attributes passed through the fields propery in the flow definition
  • 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 - Http Client (wrapped in co - this library so that it is pre-promisified)
  • _ - Lodash

Code component usage Examples

Use code is very simple, just do following:

async function run(msg, cfg, snapshot) {
  this.logger.info('Incoming message is %j', msg);
  const data = { result : 'Hello world!' };
  // You can emit as many data messages as required
  await this.emit('data', { data });
  this.logger.info('Execution finished');
}

Please note if you have a simple one-in-one-out function you can simply return a JSON object as a result of your function, it will be automatically emitted as data.

Common usage scenarios

Doing complex data transformation

JSONata is great however sometimes it's easier to do things in JavaScript, if you want to transform an incoming message with code, just use following sample:

async function run(msg, cfg, snapshot) {
  return {
      addition: 'You can use code',
      keys: Object.keys(msg)    
  };
}

Calling an external REST API

It's very simple to code a small REST API call out of the Code component, see following example:

async function run(msg, cfg, snapshot) {
  const res = await request.get({
    uri: 'https://postman-echo.com/get?foo1=bar1&foo2=bar2',
    json: true  
  });
  return {
    arguments: res.body.args
  }
}

About

The holy grail of the elastic.io platform adapted for Open Integration Hub

www.openintegrationhub.org

Resources

Readme
Apache-2.0 license
Activity
Custom properties

Stars

0 stars

Watchers

0 watching

Forks

3 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.