Sha256: 6e96dbe2efc1b1b3d2cb08082d546ac67779c8e1d9c475cdcfc8c6df7d7087b7
Contents?: true
Size: 1.81 KB
Versions: 18
Compression:
Stored size: 1.81 KB
Contents
class VActionParameter { constructor(options) { this.value = options.value; this.response_index = options.response_index; } fetchValue(results) { const result = results[results.length - this.response_index - 1]; return this.resolve(this.value, JSON.parse(result.content)); } resolve(path, obj) { return this.value.reduce(function(prev, curr) { return prev ? prev[curr] : null; }, obj || self); } } function isObject(thing) { return thing && typeof thing === 'object'; } /** * expandParam resolves an parameter `value` to a primitive value * according to the given path for the parameter in `results`. * If the `value` is not an action_parameter, it is returned unaltered. * @param {Object} results An action's results * @param {*} value The value of the parameter * @return {*} A resolved primitive value */ export function expandParam(results, value) { if (isObject(value) && value.type === 'action_parameter') { return new VActionParameter(value).fetchValue(results); } return value; } /** * expandParams resolves all values in `params` to primitive values. * * Primitive values are passed through unaltered. * Values of action_parameter parameters are resolved to primitive values * via `results`. * @param {Object} results An action's results * @param {Object} params An action's parameters * @return {Object} */ export function expandParams(results, params) { const expandedParams = {}; for (const [key, value] of Object.entries(params)) { if (!isObject(value) || value.type === 'action_parameter') { expandedParams[key] = expandParam(results, value); } else { expandedParams[key] = expandParams(results, value); } } return expandedParams; }
Version data entries
18 entries across 18 versions & 2 rubygems