cnabjs
Version:
A library for loading and working with CNAB (Cloud Native Application Bundle) manifests
44 lines • 1.73 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var Parameters;
(function (Parameters) {
/**
* Gets the parameters applicable to a specific action, such as 'install'.
* @param bundle The bundle from which to get parameters.
* @param actionName The action whose parameters you are requesting.
* @returns The names of the parameters which apply the specified action.
*/
function forAction(bundle, actionName) {
if (!bundle.parameters) {
return [];
}
const allParameters = Object.entries(bundle.parameters);
return allParameters.filter(([_, parameter]) => appliesTo(actionName, parameter))
.map(([name, _]) => name);
}
Parameters.forAction = forAction;
function appliesTo(actionName, parameter) {
if (!parameter.applyTo || parameter.applyTo.length === 0) {
return true;
}
return parameter.applyTo.includes(actionName);
}
/**
* Gets whether a particular parameter is required to be specified.
* @param bundle The bundle containg the parameters.
* @param parameterName The name of the parameter to check.
* @returns Whether the parameter is required.
*/
function isRequired(bundle, parameterName) {
if (!bundle.parameters) {
return false;
}
const parameter = bundle.parameters[parameterName];
if (!parameter) {
return false;
}
return parameter.required || false;
}
Parameters.isRequired = isRequired;
})(Parameters = exports.Parameters || (exports.Parameters = {}));
//# sourceMappingURL=parameters.js.map