firmament-bash
Version:
Firmament module for interpreting commands in JSON files using bash
121 lines • 5.24 kB
JavaScript
;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); }
};
Object.defineProperty(exports, "__esModule", { value: true });
const inversify_1 = require("inversify");
const firmament_yargs_1 = require("firmament-yargs");
const path = require("path");
const nodeUrl = require("url");
const _ = require("lodash");
let ExecutionGraphResolverImpl = class ExecutionGraphResolverImpl extends firmament_yargs_1.ForceErrorImpl {
constructor(commandUtil, remoteCatalogGetter) {
super();
this.commandUtil = commandUtil;
this.remoteCatalogGetter = remoteCatalogGetter;
}
resolveExecutionGraph(url, cb) {
const me = this;
cb = me.checkCallback(cb);
if (me.checkForceError('ExecutionGraphResolverImpl.resolveExecutionGraph', cb)) {
return;
}
me.remoteCatalogGetter.resolveJsonObjectFromUrl(url, (err, jsonObject) => {
if (me.commandUtil.callbackIfError(cb, err)) {
return;
}
if (!jsonObject) {
cb(new Error(`Execution graph at '${url}' not found`));
return;
}
const executionGraph = jsonObject;
if (executionGraph.prerequisiteGraphUri) {
me.getFullResourcePath(executionGraph.prerequisiteGraphUri, url, (err, fullResourcePath) => {
me.resolveExecutionGraph(fullResourcePath, (err, subExecutionGraph) => {
if (me.commandUtil.callbackIfError(cb, err)) {
return;
}
executionGraph.prerequisiteGraph = subExecutionGraph;
cb(null, executionGraph);
});
});
}
else {
cb(null, executionGraph);
}
});
}
resolveExecutionGraphFromCatalogEntry(catalogEntry, cb) {
const me = this;
cb = me.checkCallback(cb);
if (me.checkForceError('ExecutionGraphResolverImpl.resolveExecutionGraphFromCatalogEntry', cb)) {
return;
}
try {
catalogEntry.resources.forEach(resource => {
const po = resource.parsedObject;
const preReqUri = po.prerequisiteGraphUri;
if (preReqUri) {
const preReq = _.find(catalogEntry.resources, r => {
return r.name === preReqUri;
});
po.prerequisiteGraph = preReq.parsedObject;
preReq.parsedObject.parent = resource;
}
});
const startGraph = (_.find(catalogEntry.resources, resource => {
return !resource.parsedObject.parent;
})).parsedObject;
cb(null, startGraph);
}
catch (err) {
cb(err);
}
}
getFullResourcePath(url, parentUrl, cb) {
const me = this;
cb = me.checkCallback(cb);
if (me.checkForceError('ExecutionGraphResolverImpl.getFullResourcePath', cb)) {
return;
}
try {
const parsedUrl = nodeUrl.parse(url);
if (parsedUrl.protocol || path.isAbsolute(url)) {
cb(null, url);
}
else {
const parsedParentUrl = nodeUrl.parse(parentUrl);
let fullResourcePath = '';
if (parsedParentUrl.protocol) {
fullResourcePath = `${parsedParentUrl.protocol}//${parsedParentUrl.hostname}`;
fullResourcePath = `${fullResourcePath}${path.dirname(parsedParentUrl.path)}`;
fullResourcePath = `${fullResourcePath}/${url}`;
}
else {
fullResourcePath = `${path.dirname(parentUrl)}/${url}`;
}
cb(null, fullResourcePath);
}
}
catch (err) {
cb(err);
}
}
};
ExecutionGraphResolverImpl = __decorate([
inversify_1.injectable(),
__param(0, inversify_1.inject('CommandUtil')),
__param(1, inversify_1.inject('RemoteCatalogGetter')),
__metadata("design:paramtypes", [Object, Object])
], ExecutionGraphResolverImpl);
exports.ExecutionGraphResolverImpl = ExecutionGraphResolverImpl;
//# sourceMappingURL=execution-graph-resolver-impl.js.map