forked from heusalagroup/fi.hg.pipeline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PipelineRegistry.ts
42 lines (33 loc) · 1.44 KB
/
PipelineRegistry.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Copyright (c) 2022. Heusala Group Oy <info@heusalagroup.fi>. All rights reserved.
// Copyright (c) 2021. Sendanor <info@sendanor.fi>. All rights reserved.
import { Step } from "./types/Step";
import { ControllerFactory } from "./controllers/types/ControllerFactory";
import { find } from "../core/functions/find";
import { reduce } from "../core/functions/reduce";
export class PipelineRegistry {
private static _stepControllers : ControllerFactory[] = [];
public static hasControllers () : boolean {
return this._stepControllers.length !== 0;
}
public static registerController (controller : ControllerFactory) {
if (find(this._stepControllers, (item: ControllerFactory) : boolean => item === controller) === undefined) {
this._stepControllers.push(controller);
}
}
public static findController (model : Step) : ControllerFactory | undefined {
return find(this._stepControllers, (item: ControllerFactory): boolean => item.isControllerModel(model));
}
public static parseControllerModel (model : any) : Step | undefined {
return reduce(
this._stepControllers,
(prevResult: any, item: ControllerFactory) => {
if (prevResult !== undefined) {
return prevResult;
}
return item.parseControllerModel(model);
},
undefined
);
}
}
export default PipelineRegistry;