UNPKG

@gentrace/core

Version:
67 lines (64 loc) 1.98 kB
import { Configuration } from '../configuration.mjs'; import { globalGentraceConfig } from './init.mjs'; import { PipelineRun } from './pipeline-run.mjs'; 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 (!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({ apiKey, basePath, logger, }); } else { this.config = 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({ 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); } } export { Pipeline }; //# sourceMappingURL=pipeline.mjs.map