datafire
Version:
[![Travis][travis-image]][travis-link] [![Downloads][downloads-image]][npm-link] [![NPM version][npm-image]][npm-link] [](https://www.npmjs.com/package/datafire) <!--[![Dependency status][deps-i
30 lines (28 loc) • 926 B
JavaScript
/**
* Creates a new context, which can be passed to actions.
* @class
* @param {Object} options
* @param {string} options.type - The context type (e.g. task or http)
* @param {Object} options.accounts - list of accounts, keyed by alias
* @param {Object} options.variables - list of variables, keyed by name
* @param {Object} options.request - HTTP request details
*/
class Context {
constructor(opts={}) {
this.results = {};
this.type = opts.type || 'unknown';
this.variables = opts.variables || {};
this.accounts = {};
for (let key in opts.accounts || {}) {
this.accounts[key] = opts.accounts[key];
}
for (let key in this.accounts) {
if (typeof this.accounts[key] === 'string') {
this.accounts[key] = this.accounts[this.accounts[key]];
}
}
this.startTime = new Date();
if (opts.request) this.request = opts.request;
}
}
module.exports = Context;