|
1
|
import { JobResourceData, ResourceEntry, ResourceTypeHandler } from "../types" |
|
2
|
|
|
3
|
export class JobHandler implements ResourceTypeHandler<JobResourceData> { |
|
4
|
readonly type = "job" |
|
5
|
|
|
6
|
validate(data: JobResourceData): void { |
|
7
|
if (!data.id) { |
|
8
|
throw new Error( |
|
9
|
`Job registration requires id. Received: ${JSON.stringify(data)}` |
|
10
|
) |
|
11
|
} |
|
12
|
|
|
13
|
if (!data.sourcePath) { |
|
14
|
throw new Error( |
|
15
|
`Job registration requires sourcePath. Received: ${JSON.stringify( |
|
16
|
data |
|
17
|
)}` |
|
18
|
) |
|
19
|
} |
|
20
|
|
|
21
|
if (!data.config?.name) { |
|
22
|
throw new Error( |
|
23
|
`Job registration requires config.name. Received: ${JSON.stringify( |
|
24
|
data |
|
25
|
)}` |
|
26
|
) |
|
27
|
} |
|
28
|
} |
|
29
|
|
|
30
|
resolveSourcePath(data: JobResourceData): string { |
|
31
|
return data.sourcePath |
|
32
|
} |
|
33
|
|
|
34
|
createEntry(data: JobResourceData): ResourceEntry { |
|
35
|
return { |
|
36
|
id: data.id, |
|
37
|
config: data.config, |
|
38
|
} |
|
39
|
} |
|
40
|
|
|
41
|
getInverseKey(data: JobResourceData): string { |
|
42
|
return `${this.type}:${data.config?.name}` |
|
43
|
} |
|
44
|
} |