@gentrace/core
Version:
Core Gentrace Node.JS library
69 lines (65 loc) • 2.01 kB
JavaScript
;
var configuration = require('../configuration.js');
var init = require('./init.js');
var pipelineRun = require('./pipeline-run.js');
class Pipeline {
constructor({ slug, id, apiKey, basePath, logger, plugins, }) {
this.id = id;
this.slug = slug;
this.plugins = plugins;
if (!slug && !id) {
throw new Error("Please provide the Pipeline slug");
}
if (!init.globalGentraceConfig) {
throw new Error("Please call init() before instantiating a Pipeline");
}
if (apiKey) {
if (logger) {
logger.warn("The apiKey parameter is deprecated. Please declare the API key in the init() call instead.");
}
this.config = new configuration.Configuration({
apiKey,
basePath,
logger,
});
}
else {
this.config = init.globalGentraceConfig;
}
}
getLogger() {
return this.config.logger;
}
logInfo(message) {
const logger = this.getLogger();
if (logger) {
logger.info(message);
}
}
logWarn(e) {
const logger = this.getLogger();
if (logger) {
logger.warn(e);
}
else {
// By default, we print to STDERR.
console.warn(e);
}
}
start(context) {
var _a;
const newPipelineRun = new pipelineRun.PipelineRun({ pipeline: this, context });
const argList = Object.entries((_a = this.plugins) !== null && _a !== void 0 ? _a : {});
const argMap = Object.fromEntries(argList.map(([k, v]) => [
k,
v.advanced({
pipeline: this,
pipelineRun: newPipelineRun,
gentraceConfig: this.config,
}),
]));
return Object.assign(newPipelineRun, argMap);
}
}
exports.Pipeline = Pipeline;
//# sourceMappingURL=pipeline.js.map