1 | "use strict";
|
2 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
3 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
4 | };
|
5 | Object.defineProperty(exports, "__esModule", { value: true });
|
6 | const convict_1 = __importDefault(require("convict"));
|
7 | const job_schemas_1 = require("./job-schemas");
|
8 | const validateOptions = {
|
9 |
|
10 |
|
11 | allowed: true,
|
12 | };
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | function validateOpConfig(inputSchema, inputConfig) {
|
18 | const schema = Object.assign({}, job_schemas_1.opSchema, inputSchema);
|
19 | const config = convict_1.default(schema);
|
20 | try {
|
21 | config.load(inputConfig);
|
22 | config.validate(validateOptions);
|
23 | }
|
24 | catch (err) {
|
25 | throw new Error(`Validation failed for operation config: ${inputConfig._op} - ${err.message}`);
|
26 | }
|
27 | return config.getProperties();
|
28 | }
|
29 | exports.validateOpConfig = validateOpConfig;
|
30 |
|
31 |
|
32 |
|
33 |
|
34 | function validateAPIConfig(inputSchema, inputConfig) {
|
35 | const schema = Object.assign({}, job_schemas_1.apiSchema, inputSchema);
|
36 | const config = convict_1.default(schema);
|
37 | try {
|
38 | config.load(inputConfig);
|
39 | config.validate(validateOptions);
|
40 | }
|
41 | catch (err) {
|
42 | throw new Error(`Validation failed for api config: ${inputConfig._name} - ${err.message}`);
|
43 | }
|
44 | return config.getProperties();
|
45 | }
|
46 | exports.validateAPIConfig = validateAPIConfig;
|
47 |
|
48 |
|
49 |
|
50 |
|
51 | function validateJobConfig(inputSchema, inputConfig) {
|
52 | const config = convict_1.default(inputSchema);
|
53 | try {
|
54 | config.load(inputConfig);
|
55 | config.validate(validateOptions);
|
56 | }
|
57 | catch (err) {
|
58 | throw new Error(`Validation failed for job config: ${inputConfig.name} - ${err.message}`);
|
59 | }
|
60 | return config.getProperties();
|
61 | }
|
62 | exports.validateJobConfig = validateJobConfig;
|
63 |
|
\ | No newline at end of file |