@kitmi/jacaranda
Version:
JavaScript application framework
64 lines (63 loc) • 2.23 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, /**
* Enable a service group
* @module Feature_ServiceGroup
*/ "default", {
enumerable: true,
get: function() {
return _default;
}
});
const _utils = require("@kitmi/utils");
const _types = require("@kitmi/types");
const _Feature = /*#__PURE__*/ _interop_require_default(require("../Feature"));
function _interop_require_default(obj) {
return obj && obj.__esModule ? obj : {
default: obj
};
}
const _default = {
/**
* This feature is loaded at service stage
* @member {string}
*/ stage: _Feature.default.SERVICE,
/**
* Load the feature
* @param {App} app - The app module object
* @param {object} services - Map of services from service registration to service instance options
* @returns {Promise.<*>}
*
* @example
*
* // serviceName: s3DigitalOcean.instance1
* serviceGroup: { 's3DigitalOcean': { 'instance1': { } } }
*/ load_: async function(app, services) {
let features = [];
const instancesMap = {};
await (0, _utils.eachAsync_)(services, async (instances, serviceName)=>{
let feature = await app._loadFeature_(serviceName);
if (!feature.groupable) {
throw new _types.InvalidConfiguration(`Feature [${serviceName}] is not groupable.`, app, `serviceGroup.${serviceName}`);
}
features.push([
feature
]);
instancesMap[serviceName] = instances;
});
features = app._sortFeatures(features);
await (0, _utils.eachAsync_)(features, async ([feature])=>{
const instances = instancesMap[feature.name];
await (0, _utils.batchAsync_)(instances, async (serviceOptions, instanceName)=>{
const fullName = `${feature.name}.${instanceName}`;
const { load_, ...others } = feature;
await load_(app, serviceOptions, fullName);
others.enabled = true;
app.features[fullName] = others;
});
});
}
};
//# sourceMappingURL=serviceGroup.js.map