/
ParameterizedJob.ts
72 lines (66 loc) · 2.16 KB
/
ParameterizedJob.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { Job } from '..';
import { Command } from '../../Commands/exports/Command';
import { CustomParametersList } from '../../Parameters';
import { Parameterized } from '../../Parameters/exports/Parameterized';
import { JobParameterLiteral } from '../../Parameters/types/CustomParameterLiterals.types';
import {
AnyExecutor,
JobOptionalProperties,
ParameterizedJobContents,
} from '../types/Job.types';
/**
* Parameterized jobs are a type of Job which defines the parameters it can accept.
* This is the reusable alternative to the Job class, since parameters allow for
* more control and recyclability to the workflow.
*/
class ParameterizedJob
extends Job
implements Parameterized<JobParameterLiteral>
{
/**
* The list of parameters this job can accept.
*/
parameters: CustomParametersList<JobParameterLiteral>;
constructor(
name: string,
executor: AnyExecutor,
parameters?: CustomParametersList<JobParameterLiteral>,
steps?: Command[],
properties?: JobOptionalProperties,
) {
super(name, executor, steps, properties);
this.parameters = parameters || new CustomParametersList();
}
/**
* Generate the internal contents of this job.
* @returns The job contents in it's generated shape.
*/
generateContents(flatten?: boolean): ParameterizedJobContents {
return {
parameters: this.parameters.generate(),
...super.generateContents(flatten),
};
}
/**
* Define another parameter that this job will be able to accept.
* Chainable.
* @param name - The name of the parameter.
* @param type - The type of parameter being added to this job.
* @param defaultValue - The default value of the parameter.
* @param description - The description of the parameter.
* @param enumValues - The list of possible values for the parameter. type must be set to 'enum'.
*
* @returns this instance.
*/
defineParameter(
name: string,
type: JobParameterLiteral,
defaultValue?: unknown,
description?: string,
enumValues?: string[],
): ParameterizedJob {
this.parameters.define(name, type, defaultValue, description, enumValues);
return this;
}
}
export { ParameterizedJob };