1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const _ = require("lodash");
|
4 | const automationMetadata_1 = require("../metadata/automationMetadata");
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | function populateParameters(instanceToPopulate, hm, args) {
|
13 | args.forEach(arg => {
|
14 | if (arg.value !== undefined) {
|
15 | const parameter = hm.parameters.find(p => p.name === arg.name);
|
16 | if (parameter) {
|
17 | _.update(instanceToPopulate, parameter.name, () => computeValue(parameter, arg.value));
|
18 | }
|
19 | }
|
20 | });
|
21 | }
|
22 | exports.populateParameters = populateParameters;
|
23 | function populateValues(instanceToPopulate, am, configuration) {
|
24 | (am.values || []).forEach(v => {
|
25 | let configValue;
|
26 | if (!v.path || v.path.length === 0) {
|
27 | configValue = configuration;
|
28 | }
|
29 | else {
|
30 | configValue = _.get(configuration, v.path);
|
31 | }
|
32 | if (!configValue && v.required) {
|
33 | throw new Error(`Required @Value '${v.path}' in '${instanceToPopulate.constructor.name}' is not available in configuration`);
|
34 | }
|
35 | else {
|
36 | _.update(instanceToPopulate, v.name, () => computeValue({ name: v.name, type: v.type }, configValue));
|
37 | }
|
38 | });
|
39 | }
|
40 | exports.populateValues = populateValues;
|
41 | function computeValue(parameter, value) {
|
42 |
|
43 | switch (parameter.type) {
|
44 | case "string":
|
45 | case undefined:
|
46 |
|
47 | break;
|
48 | case automationMetadata_1.FreeChoices:
|
49 |
|
50 | break;
|
51 | case "boolean":
|
52 | if (typeof value !== "boolean") {
|
53 | value = value === "true" || value === "yes" || value === "1";
|
54 | }
|
55 | break;
|
56 | case "number":
|
57 | if (typeof value === "string") {
|
58 | value = parseInt(value, 10);
|
59 | }
|
60 | else {
|
61 | throw new Error(`Parameter '${parameter.name}' has array value, but is numeric`);
|
62 | }
|
63 | break;
|
64 | default:
|
65 |
|
66 | const chooser = parameter.type;
|
67 | if (chooser.pickOne) {
|
68 | if (typeof value !== "string") {
|
69 | throw new Error(`Parameter '${parameter.name}' has array value, but should be string`);
|
70 | }
|
71 | }
|
72 | else {
|
73 | if (typeof value.value === "string") {
|
74 | throw new Error(`Parameter '${parameter.name}' has string value, but should be array`);
|
75 | }
|
76 | }
|
77 | break;
|
78 | }
|
79 | return value;
|
80 | }
|
81 |
|
\ | No newline at end of file |