UNPKG

2.3 kBJavaScriptView Raw
1"use strict";
2var __importDefault = (this && this.__importDefault) || function (mod) {
3 return (mod && mod.__esModule) ? mod : { "default": mod };
4};
5Object.defineProperty(exports, "__esModule", { value: true });
6const convict_1 = __importDefault(require("convict"));
7const job_schemas_1 = require("./job-schemas");
8const validateOptions = {
9 // IMPORTANT: changing this will break things
10 // @ts-ignore because this is deprecated and will be removed in ^5.0.0
11 allowed: true,
12};
13/**
14 * Merges the provided inputSchema with commonSchema and then validates the
15 * provided opConfig against the resulting schema.
16 */
17function 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}
29exports.validateOpConfig = validateOpConfig;
30/**
31 * Merges the provided inputSchema with commonSchema and then validates the
32 * provided apiConfig against the resulting schema.
33 */
34function 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}
46exports.validateAPIConfig = validateAPIConfig;
47/**
48 * Merges the provided inputSchema with commonSchema and then validates the
49 * provided jobConfig against the resulting schema.
50 */
51function 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}
62exports.validateJobConfig = validateJobConfig;
63//# sourceMappingURL=config-validators.js.map
\No newline at end of file