blob: 3ce3e08141c584f1bd4b92adfee0461f4bf920a4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
import { Either, IEither } from '@emprespresso/pengueno';
import { isPipeline, Pipeline, PipelineStage } from './index.js';
export class PipelineImpl implements Pipeline {
constructor(public readonly serialJobs: Array<PipelineStage>) {}
public serialize() {
return JSON.stringify({ serialJobs: this.serialJobs });
}
public static from(s: string): IEither<Error, Pipeline> {
return Either.fromFailable<Error, unknown>(() => JSON.parse(s))
.flatMap<Pipeline>((eitherPipelineJson) =>
isPipeline(eitherPipelineJson)
? Either.right(eitherPipelineJson)
: Either.left(new Error('oh noes D: its a bad pipewine :((')),
)
.mapRight((pipeline) => new PipelineImpl(pipeline.serialJobs));
}
}
|