@extrahorizon/exh-cli 1.12.0-dev-145-36d98c7 → 1.12.0-dev-146-310460f
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build/helpers/util.d.ts
CHANGED
|
@@ -3,4 +3,5 @@ export declare function epilogue(y: yargs.Argv): yargs.Argv;
|
|
|
3
3
|
export declare function asyncExec(cmd: string): Promise<string>;
|
|
4
4
|
export declare function loadAndAssertCredentials(): void;
|
|
5
5
|
export declare function getSwaggerDocumentationUrl(subPath: string): string;
|
|
6
|
+
export declare function ajvValidate<T>(schema: any, data: any): asserts data is T;
|
|
6
7
|
export declare function getAjvErrorStrings(errors: any[]): string[];
|
package/build/helpers/util.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getAjvErrorStrings = exports.getSwaggerDocumentationUrl = exports.loadAndAssertCredentials = exports.asyncExec = exports.epilogue = void 0;
|
|
3
|
+
exports.getAjvErrorStrings = exports.ajvValidate = exports.getSwaggerDocumentationUrl = exports.loadAndAssertCredentials = exports.asyncExec = exports.epilogue = void 0;
|
|
4
4
|
const child_process_1 = require("child_process");
|
|
5
5
|
const fs = require("fs");
|
|
6
6
|
const path = require("path");
|
|
7
|
+
const ajv_1 = require("ajv");
|
|
7
8
|
const chalk = require("chalk");
|
|
8
9
|
const constants_1 = require("../constants");
|
|
9
10
|
const error_1 = require("./error");
|
|
@@ -80,6 +81,15 @@ function getSwaggerDocumentationUrl(subPath) {
|
|
|
80
81
|
throw new Error(`Unknown CLI version format: ${packageVersion}`);
|
|
81
82
|
}
|
|
82
83
|
exports.getSwaggerDocumentationUrl = getSwaggerDocumentationUrl;
|
|
84
|
+
function ajvValidate(schema, data) {
|
|
85
|
+
const validate = new ajv_1.default().compile(schema);
|
|
86
|
+
const valid = validate(data);
|
|
87
|
+
if (!valid) {
|
|
88
|
+
const errors = getAjvErrorStrings(validate.errors);
|
|
89
|
+
throw new Error(errors[0] || 'Unknown config validation error');
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
exports.ajvValidate = ajvValidate;
|
|
83
93
|
function getAjvErrorStrings(errors) {
|
|
84
94
|
return errors.map(error => {
|
|
85
95
|
let message = '';
|
|
@@ -24,6 +24,6 @@ export interface TaskConfig {
|
|
|
24
24
|
};
|
|
25
25
|
}
|
|
26
26
|
export declare function assertExecutionPermission(mode: string): asserts mode is permissionModes | undefined;
|
|
27
|
-
export declare function validateConfig(config:
|
|
27
|
+
export declare function validateConfig(config: any): Promise<boolean>;
|
|
28
28
|
export declare function loadSingleConfigFile(path: string): Promise<TaskConfig>;
|
|
29
29
|
export declare function getValidatedConfigIterator({ path, name, code, entryPoint, runtime, description, timeLimit, memoryLimit, executionPermission, env, defaultPriority }: any): AsyncGenerator<TaskConfig>;
|
|
@@ -4,7 +4,6 @@ exports.getValidatedConfigIterator = exports.loadSingleConfigFile = exports.vali
|
|
|
4
4
|
const assert_1 = require("assert");
|
|
5
5
|
const fs = require("fs/promises");
|
|
6
6
|
const ospath = require("path");
|
|
7
|
-
const ajv_1 = require("ajv");
|
|
8
7
|
const taskConfigSchema = require("../../config-json-schemas/TaskConfig.json");
|
|
9
8
|
const util_1 = require("../../helpers/util");
|
|
10
9
|
var permissionModes;
|
|
@@ -52,12 +51,7 @@ function replaceConfigVariables(config) {
|
|
|
52
51
|
return result;
|
|
53
52
|
}
|
|
54
53
|
async function validateConfig(config) {
|
|
55
|
-
|
|
56
|
-
const valid = validate(config);
|
|
57
|
-
if (!valid) {
|
|
58
|
-
const errors = (0, util_1.getAjvErrorStrings)(validate.errors);
|
|
59
|
-
throw new Error(errors[0] || 'Unknown config validation error');
|
|
60
|
-
}
|
|
54
|
+
(0, util_1.ajvValidate)(taskConfigSchema, config);
|
|
61
55
|
try {
|
|
62
56
|
await fs.access(config.path);
|
|
63
57
|
}
|