@sasjs/cli 4.4.2 → 4.5.0

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.
@@ -1,5 +1,5 @@
1
- import { CompileTree, Configuration, Target } from '@sasjs/utils';
1
+ import { CompileTree, Target } from '@sasjs/utils';
2
2
  import { TestFlow } from '../../../types';
3
3
  export declare function compileTestFile(target: Target, filePath: string, testVar: string | undefined, saveToRoot: boolean | undefined, removeOriginalFile: boolean | undefined, compileTree: CompileTree, destinationPath?: string): Promise<void>;
4
4
  export declare function copyTestMacroFiles(folderAbsolutePath: string): Promise<void>;
5
- export declare const compileTestFlow: (target: Target, config?: Configuration) => Promise<TestFlow | undefined>;
5
+ export declare const compileTestFlow: (target: Target) => Promise<TestFlow | undefined>;
@@ -160,8 +160,8 @@ function copyTestMacroFiles(folderAbsolutePath) {
160
160
  });
161
161
  }
162
162
  exports.copyTestMacroFiles = copyTestMacroFiles;
163
- var compileTestFlow = function (target, config) { return __awaiter(void 0, void 0, void 0, function () {
164
- var _a, buildDestinationFolder, buildDestinationTestFolder, testFiles, config_2, testFlow, testSetUp, testTearDown, testSetUpFileName_1, testTearDownFileName_1;
163
+ var compileTestFlow = function (target) { return __awaiter(void 0, void 0, void 0, function () {
164
+ var _a, buildDestinationFolder, buildDestinationTestFolder, testFiles, config, testFlow, testSetUp, testTearDown, testSetUpFileName_1, testTearDownFileName_1;
165
165
  var _b, _c, _d, _e;
166
166
  return __generator(this, function (_f) {
167
167
  switch (_f.label) {
@@ -177,10 +177,10 @@ var compileTestFlow = function (target, config) { return __awaiter(void 0, void
177
177
  return [4 /*yield*/, (0, utils_1.listFilesAndSubFoldersInFolder)(buildDestinationTestFolder)];
178
178
  case 2:
179
179
  testFiles = (_f.sent()).map(function (file) { return path_1.default.join('tests', file); });
180
- config_2 = process.sasjsConfig;
180
+ config = process.sasjsConfig;
181
181
  testFlow = { tests: [] };
182
- testSetUp = ((_b = target.testConfig) === null || _b === void 0 ? void 0 : _b.testSetUp) || ((_c = config_2.testConfig) === null || _c === void 0 ? void 0 : _c.testSetUp);
183
- testTearDown = ((_d = target.testConfig) === null || _d === void 0 ? void 0 : _d.testTearDown) || ((_e = config_2.testConfig) === null || _e === void 0 ? void 0 : _e.testTearDown);
182
+ testSetUp = ((_b = target.testConfig) === null || _b === void 0 ? void 0 : _b.testSetUp) || ((_c = config.testConfig) === null || _c === void 0 ? void 0 : _c.testSetUp);
183
+ testTearDown = ((_d = target.testConfig) === null || _d === void 0 ? void 0 : _d.testTearDown) || ((_e = config.testConfig) === null || _e === void 0 ? void 0 : _e.testTearDown);
184
184
  if (testFiles.length) {
185
185
  if (testSetUp) {
186
186
  testSetUpFileName_1 = getFileName(testSetUp);
@@ -306,7 +306,7 @@ describe('compileTestFile', function () {
306
306
  jest.spyOn(process.logger, 'warn');
307
307
  (0, __1.compileTestFlow)(testTarget);
308
308
  expect(process.logger.warn).toHaveBeenCalledWith(expectedWarn);
309
- (0, __1.compileTestFlow)(testTarget, testConfig);
309
+ (0, __1.compileTestFlow)(testTarget);
310
310
  expect(process.logger.warn).toHaveBeenCalledWith(expectedWarn);
311
311
  return [2 /*return*/];
312
312
  });
@@ -267,14 +267,14 @@ function printHelpText() {
267
267
  description: [
268
268
  "performs operations on jobs.",
269
269
  "[2spaces]* ".concat(chalk_1.default.cyanBright('execute'), " - triggers job for execution."),
270
- "[2spaces]command example: sasjs job execute /Public/job -t targetName --output ./outputFolder/output.json --returnStatusOnly --ignoreWarnings",
271
- "[2spaces]command example: sasjs job execute /Public/job -t targetName --wait --log ./logFolder/log.json -r -i",
270
+ "[2spaces]command example: sasjs job execute /Public/job -t targetName --output ./outputFolder/output.json --ignoreWarnings --verbose",
271
+ "[2spaces]command example: sasjs job execute /Public/job -t targetName --wait --log ./logFolder/log.json -i -v",
272
272
  "",
273
273
  "[2spaces]NOTE: Providing wait flag (--wait or -w) is optional. If present, CLI will wait for job completion.",
274
274
  "[2spaces]NOTE: Providing output flag (--output or -o) is optional. If present, CLI will immediately print out the response JSON. If value is provided, it will be treated as file path to save the response JSON.",
275
275
  "[2spaces]NOTE: Providing log flag (--log or -l) is optional. If present, CLI will fetch and save job log to local file.",
276
- "[2spaces]NOTE: Providing return status only (--returnStatusOnly or -r) flag is optional. If present and wait flag is provided, CLI will job status only (0 = success, 1 = warning, 2 = error).",
277
- "[2spaces]NOTE: Providing ignore warnings (--ignoreWarnings or -i) flag is optional. If present and return status only is provided, CLI will return status '0', when the job state is warning."
276
+ "[2spaces]NOTE: Providing ignore warnings (--ignoreWarnings or -i) flag is optional. If present, CLI will return status '0', when the job state is warning.",
277
+ "[2spaces]NOTE: Providing verbose (--verbose or -v) flag is optional. If present, CLI will log summary of every HTTP response."
278
278
  ]
279
279
  },
280
280
  {
@@ -56,34 +56,44 @@ function executeJobSas9(sasjs, config, jobPath, logFile, output, source) {
56
56
  case 0:
57
57
  macroVars = null;
58
58
  if (!source) return [3 /*break*/, 2];
59
- return [4 /*yield*/, (0, parseSourceFile_1.parseSourceFile)(source)];
59
+ return [4 /*yield*/, (0, parseSourceFile_1.parseSourceFile)(source)
60
+ // timestamp of the execution start
61
+ ];
60
62
  case 1:
61
63
  macroVars = _a.sent();
62
64
  _a.label = 2;
63
65
  case 2:
64
66
  startTime = new Date().getTime();
65
- return [4 /*yield*/, sasjs.request(jobPath, macroVars, config)];
67
+ return [4 /*yield*/, sasjs.request(jobPath, macroVars, config)
68
+ // timestamp of the execution end
69
+ ];
66
70
  case 3:
67
71
  result = _a.sent();
68
72
  endTime = new Date().getTime();
69
- if (!result) return [3 /*break*/, 7];
70
- if (!(result.status === 200)) return [3 /*break*/, 6];
73
+ if (!result) return [3 /*break*/, 9];
74
+ if (!(result.status === 200)) return [3 /*break*/, 8];
75
+ // handle success
71
76
  process.logger.success("Job executed successfully! in ".concat((endTime - startTime) / 1000, " seconds"));
72
77
  if (!(!!logFile && result.log)) return [3 /*break*/, 5];
73
- return [4 /*yield*/, (0, utils_1.saveLog)(result.log, logFile, jobPath, false)];
78
+ return [4 /*yield*/, (0, utils_1.saveLog)(result.log, logFile, jobPath)
79
+ // save output if it is present
80
+ ];
74
81
  case 4:
75
82
  _a.sent();
76
83
  _a.label = 5;
77
84
  case 5:
78
- if (!!output && result.result) {
79
- (0, utils_1.saveOutput)(result.result, output, false);
80
- }
81
- return [3 /*break*/, 7];
85
+ if (!(!!output && result.result)) return [3 /*break*/, 7];
86
+ return [4 /*yield*/, (0, utils_1.saveOutput)(result.result, output)];
82
87
  case 6:
88
+ _a.sent();
89
+ _a.label = 7;
90
+ case 7: return [3 /*break*/, 9];
91
+ case 8:
92
+ // handle failure
83
93
  process.logger.error(result.message);
84
94
  process.logger.error(JSON.stringify(result.error, null, 2));
85
- _a.label = 7;
86
- case 7: return [2 /*return*/, result];
95
+ _a.label = 9;
96
+ case 9: return [2 /*return*/, result];
87
97
  }
88
98
  });
89
99
  });
@@ -1,4 +1,12 @@
1
1
  import { Target } from '@sasjs/utils';
2
+ /**
3
+ * Triggers existing job for execution on SASJS server.
4
+ * @param target - SASJS server configuration.
5
+ * @param jobPath - location of the job.
6
+ * @param logFile - flag indicating if CLI should fetch and save log to provided file path. If filepath wasn't provided, {job}.log file will be created in current folder.
7
+ * @param output - flag indicating if CLI should save output to provided file path.
8
+ * @returns - promise that resolves into an object with log and output.
9
+ */
2
10
  export declare function executeJobSasjs(target: Target, jobPath: string, logFile?: string, output?: string): Promise<{
3
11
  result: any;
4
12
  log: any;
@@ -40,6 +40,14 @@ exports.executeJobSasjs = void 0;
40
40
  var node_1 = require("@sasjs/adapter/node");
41
41
  var utils_1 = require("../../../../utils");
42
42
  var utils_2 = require("../utils");
43
+ /**
44
+ * Triggers existing job for execution on SASJS server.
45
+ * @param target - SASJS server configuration.
46
+ * @param jobPath - location of the job.
47
+ * @param logFile - flag indicating if CLI should fetch and save log to provided file path. If filepath wasn't provided, {job}.log file will be created in current folder.
48
+ * @param output - flag indicating if CLI should save output to provided file path.
49
+ * @returns - promise that resolves into an object with log and output.
50
+ */
43
51
  function executeJobSasjs(target, jobPath, logFile, output) {
44
52
  var _a;
45
53
  return __awaiter(this, void 0, void 0, function () {
@@ -65,15 +73,18 @@ function executeJobSasjs(target, jobPath, logFile, output) {
65
73
  case 5:
66
74
  response = _c.sent();
67
75
  if (!response) return [3 /*break*/, 9];
76
+ // handle success
68
77
  (_a = process.logger) === null || _a === void 0 ? void 0 : _a.success('Job executed successfully!');
69
78
  if (!(!!logFile && response.log)) return [3 /*break*/, 7];
70
- return [4 /*yield*/, (0, utils_2.saveLog)(response.log, logFile, jobPath, false)];
79
+ return [4 /*yield*/, (0, utils_2.saveLog)(response.log, logFile, jobPath)
80
+ // save output if it is present
81
+ ];
71
82
  case 6:
72
83
  _c.sent();
73
84
  _c.label = 7;
74
85
  case 7:
75
86
  if (!(!!output && response.result)) return [3 /*break*/, 9];
76
- return [4 /*yield*/, (0, utils_2.saveOutput)(response.result, output, false)];
87
+ return [4 /*yield*/, (0, utils_2.saveOutput)(response.result, output)];
77
88
  case 8:
78
89
  _c.sent();
79
90
  _c.label = 9;
@@ -1,7 +1,7 @@
1
1
  import SASjs from '@sasjs/adapter/node';
2
2
  import { Target, AuthConfig } from '@sasjs/utils';
3
3
  /**
4
- * Triggers existing job for execution.
4
+ * Triggers existing job for execution on Viya server.
5
5
  * @param {object} sasjs - configuration object of SAS adapter.
6
6
  * @param {string} accessToken - an access token for an authorized user.
7
7
  * @param {string} jobPath - location of the job on SAS Drive.
@@ -10,10 +10,15 @@ import { Target, AuthConfig } from '@sasjs/utils';
10
10
  * @param {boolean | string} output - flag indicating if CLI should print out job output. If string was provided, it will be treated as file path to store output. If filepath wasn't provided, output.json file will be created in current folder.
11
11
  * @param {string | undefined} logFile - flag indicating if CLI should fetch and save log to provided file path. If filepath wasn't provided, {job}.log file will be created in current folder.
12
12
  * @param {string | undefined} statusFile - flag indicating if CLI should fetch and save status to the local file. If filepath wasn't provided, it will only print on console.
13
- * @param {boolean} returnStatusOnly - flag indicating if CLI should return status only (0 = success, 1 = warning, 3 = error).
14
13
  * @param {boolean} ignoreWarnings - flag indicating if CLI should return status '0', when the job state is warning.
15
14
  * @param {string | undefined} source - an optional path to a JSON file containing macro variables.
16
15
  * @param {boolean} streamLog - a flag indicating if the logs should be streamed to the supplied log path during job execution. This is useful for getting feedback on long running jobs.
16
+ * @param {boolean} verbose - enables verbose mode that logs summary of every HTTP response.
17
17
  */
18
- export declare function executeJobViya(sasjs: SASjs, authConfig: AuthConfig, jobPath: string, target: Target, waitForJob: boolean, output: string | boolean, logFile: string | undefined, statusFile: string | undefined, returnStatusOnly: boolean, ignoreWarnings: boolean, source: string | undefined, streamLog: boolean): Promise<any>;
19
- export declare function getContextName(target: Target, returnStatusOnly?: boolean): string;
18
+ export declare function executeJobViya(sasjs: SASjs, authConfig: AuthConfig, jobPath: string, target: Target, waitForJob: boolean, output: string | boolean, logFile: string | undefined, statusFile: string | undefined, ignoreWarnings: boolean, source: string | undefined, streamLog: boolean, verbose: boolean): Promise<any>;
19
+ /**
20
+ * Gets job execution context name.
21
+ * @param target - SAS server configuration.
22
+ * @returns - job execution context name.
23
+ */
24
+ export declare function getContextName(target: Target): string;
@@ -50,7 +50,7 @@ var utils_2 = require("../../../../utils/");
50
50
  var command_1 = require("../../../../types/command");
51
51
  var utils_3 = require("../utils");
52
52
  /**
53
- * Triggers existing job for execution.
53
+ * Triggers existing job for execution on Viya server.
54
54
  * @param {object} sasjs - configuration object of SAS adapter.
55
55
  * @param {string} accessToken - an access token for an authorized user.
56
56
  * @param {string} jobPath - location of the job on SAS Drive.
@@ -59,15 +59,15 @@ var utils_3 = require("../utils");
59
59
  * @param {boolean | string} output - flag indicating if CLI should print out job output. If string was provided, it will be treated as file path to store output. If filepath wasn't provided, output.json file will be created in current folder.
60
60
  * @param {string | undefined} logFile - flag indicating if CLI should fetch and save log to provided file path. If filepath wasn't provided, {job}.log file will be created in current folder.
61
61
  * @param {string | undefined} statusFile - flag indicating if CLI should fetch and save status to the local file. If filepath wasn't provided, it will only print on console.
62
- * @param {boolean} returnStatusOnly - flag indicating if CLI should return status only (0 = success, 1 = warning, 3 = error).
63
62
  * @param {boolean} ignoreWarnings - flag indicating if CLI should return status '0', when the job state is warning.
64
63
  * @param {string | undefined} source - an optional path to a JSON file containing macro variables.
65
64
  * @param {boolean} streamLog - a flag indicating if the logs should be streamed to the supplied log path during job execution. This is useful for getting feedback on long running jobs.
65
+ * @param {boolean} verbose - enables verbose mode that logs summary of every HTTP response.
66
66
  */
67
- function executeJobViya(sasjs, authConfig, jobPath, target, waitForJob, output, logFile, statusFile, returnStatusOnly, ignoreWarnings, source, streamLog) {
67
+ function executeJobViya(sasjs, authConfig, jobPath, target, waitForJob, output, logFile, statusFile, ignoreWarnings, source, streamLog, verbose) {
68
68
  var _a, _b;
69
69
  return __awaiter(this, void 0, void 0, function () {
70
- var pollOptions, result, startTime, contextName, macroVars, submittedJob, endTime, sessionLink, outputJson, currentDirPath, outputPath, folderPath, parentFolderPath, logObj, logUrl, logCount, logData, error_1;
70
+ var pollOptions, result, startTime, contextName, macroVars, submittedJob, endTime, outputJson, currentDirPath, outputPath, folderPath, parentFolderPath, logObj, logUrl, logCount, logData, error_1;
71
71
  var _this = this;
72
72
  return __generator(this, function (_c) {
73
73
  switch (_c.label) {
@@ -79,16 +79,14 @@ function executeJobViya(sasjs, authConfig, jobPath, target, waitForJob, output,
79
79
  logFolderPath: logFile
80
80
  };
81
81
  startTime = new Date().getTime();
82
- if (!(statusFile && !returnStatusOnly)) return [3 /*break*/, 2];
82
+ if (!statusFile) return [3 /*break*/, 2];
83
83
  return [4 /*yield*/, displayStatus({ state: 'Initiating' }, statusFile)];
84
84
  case 1:
85
85
  _c.sent();
86
86
  _c.label = 2;
87
87
  case 2:
88
- if (!returnStatusOnly) {
89
- (_a = process.logger) === null || _a === void 0 ? void 0 : _a.success("Job located at ".concat(jobPath, " has been submitted for execution..."));
90
- }
91
- contextName = getContextName(target, returnStatusOnly);
88
+ (_a = process.logger) === null || _a === void 0 ? void 0 : _a.success("Job located at ".concat(jobPath, " has been submitted for execution..."));
89
+ contextName = getContextName(target);
92
90
  if (!source) return [3 /*break*/, 5];
93
91
  if (!(0, file_1.isJsonFile)(source))
94
92
  throw 'Source file has to be JSON.';
@@ -108,7 +106,7 @@ function executeJobViya(sasjs, authConfig, jobPath, target, waitForJob, output,
108
106
  }
109
107
  _c.label = 5;
110
108
  case 5: return [4 /*yield*/, sasjs
111
- .startComputeJob(jobPath, null, { contextName: contextName }, authConfig, waitForJob || !!logFile, pollOptions, true, macroVars === null || macroVars === void 0 ? void 0 : macroVars.macroVars)
109
+ .startComputeJob(jobPath, null, { contextName: contextName }, authConfig, waitForJob || !!logFile, pollOptions, true, macroVars === null || macroVars === void 0 ? void 0 : macroVars.macroVars, verbose || undefined)
112
110
  .catch(function (err) { return __awaiter(_this, void 0, void 0, function () {
113
111
  var logData;
114
112
  var _a;
@@ -117,32 +115,38 @@ function executeJobViya(sasjs, authConfig, jobPath, target, waitForJob, output,
117
115
  case 0:
118
116
  if (!(err instanceof node_1.NoSessionStateError)) return [3 /*break*/, 4];
119
117
  if (!(err === null || err === void 0 ? void 0 : err.logUrl)) return [3 /*break*/, 3];
120
- return [4 /*yield*/, (0, fetchLogFileContent_1.fetchLogFileContent)(sasjs, authConfig.access_token, err.logUrl, 100000)];
118
+ return [4 /*yield*/, (0, fetchLogFileContent_1.fetchLogFileContent)(sasjs, authConfig.access_token, err.logUrl, 100000)
119
+ // save log
120
+ ];
121
121
  case 1:
122
122
  logData = _b.sent();
123
- return [4 /*yield*/, (0, utils_3.saveLog)(logData, logFile, jobPath, returnStatusOnly)];
123
+ // save log
124
+ return [4 /*yield*/, (0, utils_3.saveLog)(logData, logFile, jobPath)];
124
125
  case 2:
126
+ // save log
125
127
  _b.sent();
126
128
  _b.label = 3;
127
129
  case 3:
128
130
  (0, displayResult_1.displayError)(err);
131
+ // terminate process with status code 2
129
132
  (0, utils_2.terminateProcess)(2);
130
133
  _b.label = 4;
131
134
  case 4:
132
135
  if (!(err === null || err === void 0 ? void 0 : err.log)) return [3 /*break*/, 6];
133
- return [4 /*yield*/, (0, utils_3.saveLog)(err.log, logFile, jobPath, returnStatusOnly)];
136
+ return [4 /*yield*/, (0, utils_3.saveLog)(err.log, logFile, jobPath)
137
+ // handle use case when job wasn't found
138
+ ];
134
139
  case 5:
135
140
  _b.sent();
136
141
  _b.label = 6;
137
142
  case 6:
138
- if (returnStatusOnly)
139
- (0, utils_2.terminateProcess)(2);
143
+ // handle use case when job wasn't found
140
144
  if ((err === null || err === void 0 ? void 0 : err.name) === 'NotFoundError') {
141
145
  throw new Error("Job located at '".concat(jobPath, "' was not found."));
142
146
  }
143
- result = returnStatusOnly
144
- ? command_1.ReturnCode.InternalError
145
- : typeof err === 'object' && Object.keys(err).length
147
+ // get additional information about error if it is present
148
+ result =
149
+ typeof err === 'object' && Object.keys(err).length
146
150
  ? JSON.stringify({ state: (_a = err.job) === null || _a === void 0 ? void 0 : _a.state })
147
151
  : "".concat(err);
148
152
  if (err.job) {
@@ -151,17 +155,21 @@ function executeJobViya(sasjs, authConfig, jobPath, target, waitForJob, output,
151
155
  return [2 /*return*/];
152
156
  }
153
157
  });
154
- }); })];
158
+ }); })
159
+ // job execution end time
160
+ ];
155
161
  case 6:
156
162
  submittedJob = _c.sent();
157
163
  endTime = new Date().getTime();
158
- if (result && !returnStatusOnly) {
164
+ if (result) {
159
165
  (0, displayResult_1.displayError)(result, 'An error has occurred when executing a job.');
160
166
  }
161
167
  if (submittedJob && submittedJob.job)
162
168
  submittedJob = submittedJob.job;
163
- if (!(statusFile && !returnStatusOnly)) return [3 /*break*/, 8];
164
- return [4 /*yield*/, displayStatus(submittedJob, statusFile, result, true)];
169
+ if (!statusFile) return [3 /*break*/, 8];
170
+ return [4 /*yield*/, displayStatus(submittedJob, statusFile, result, true)
171
+ // job execution completed successfully
172
+ ];
165
173
  case 7:
166
174
  _c.sent();
167
175
  _c.label = 8;
@@ -169,7 +177,6 @@ function executeJobViya(sasjs, authConfig, jobPath, target, waitForJob, output,
169
177
  if (!(submittedJob && submittedJob.links)) return [3 /*break*/, 21];
170
178
  if (!result)
171
179
  result = true;
172
- sessionLink = submittedJob.links.find(function (l) { return l.method === 'GET' && l.rel === 'self'; }).href;
173
180
  if (!(output || logFile)) return [3 /*break*/, 20];
174
181
  _c.label = 9;
175
182
  case 9:
@@ -195,13 +202,13 @@ function executeJobViya(sasjs, authConfig, jobPath, target, waitForJob, output,
195
202
  case 12: return [4 /*yield*/, (0, utils_1.createFile)(outputPath, outputJson)];
196
203
  case 13:
197
204
  _c.sent();
198
- if (!returnStatusOnly)
199
- (0, displayResult_1.displaySuccess)("Output saved to: ".concat(outputPath));
205
+ (0, displayResult_1.displaySuccess)("Output saved to: ".concat(outputPath));
200
206
  return [3 /*break*/, 15];
201
207
  case 14:
202
208
  if (output) {
203
- if (!returnStatusOnly)
204
- (process.logger || console).log(outputJson);
209
+ // log job object to the console
210
+ ;
211
+ (process.logger || console).log(outputJson);
205
212
  }
206
213
  _c.label = 15;
207
214
  case 15:
@@ -213,7 +220,7 @@ function executeJobViya(sasjs, authConfig, jobPath, target, waitForJob, output,
213
220
  return [4 /*yield*/, (0, fetchLogFileContent_1.fetchLogFileContent)(sasjs, authConfig.access_token, logUrl, logCount)];
214
221
  case 16:
215
222
  logData = _c.sent();
216
- return [4 /*yield*/, (0, utils_3.saveLog)(logData, logFile, jobPath, returnStatusOnly)];
223
+ return [4 /*yield*/, (0, utils_3.saveLog)(logData, logFile, jobPath)];
217
224
  case 17:
218
225
  _c.sent();
219
226
  _c.label = 18;
@@ -222,17 +229,19 @@ function executeJobViya(sasjs, authConfig, jobPath, target, waitForJob, output,
222
229
  return [3 /*break*/, 20];
223
230
  case 19:
224
231
  error_1 = _c.sent();
232
+ // handle use case when submitted job can't be parsed
225
233
  result = false;
226
- if (!returnStatusOnly) {
227
- (0, displayResult_1.displayError)(null, 'An error has occurred when parsing an output of the job.');
228
- }
234
+ (0, displayResult_1.displayError)(null, 'An error has occurred when parsing an output of the job.');
229
235
  return [3 /*break*/, 20];
230
236
  case 20:
231
- if (waitForJob && returnStatusOnly && submittedJob.state) {
237
+ // wait for job state and return status(0,1,2) based on it
238
+ if (waitForJob && submittedJob.state) {
232
239
  switch (submittedJob.state) {
233
240
  case 'completed':
234
241
  (0, utils_2.terminateProcess)(0);
235
242
  case 'warning':
243
+ // if ignoreWarnings flag is present, process will be terminated with
244
+ // status code 0, otherwise status code will be 1
236
245
  (0, utils_2.terminateProcess)(ignoreWarnings ? 0 : 1);
237
246
  case 'error':
238
247
  (0, utils_2.terminateProcess)(2);
@@ -242,14 +251,12 @@ function executeJobViya(sasjs, authConfig, jobPath, target, waitForJob, output,
242
251
  }
243
252
  return [3 /*break*/, 22];
244
253
  case 21:
245
- if (returnStatusOnly && result === 2) {
246
- (0, utils_2.terminateProcess)(2);
254
+ if (result) {
255
+ (0, utils_2.terminateProcess)(command_1.ReturnCode.InternalError);
247
256
  }
248
257
  _c.label = 22;
249
258
  case 22:
250
- if (!returnStatusOnly) {
251
- (_b = process.logger) === null || _b === void 0 ? void 0 : _b.info("This job was executed in ".concat((endTime - startTime) / 1000, " seconds"));
252
- }
259
+ (_b = process.logger) === null || _b === void 0 ? void 0 : _b.info("This job was executed in ".concat((endTime - startTime) / 1000, " seconds"));
253
260
  return [2 /*return*/, result];
254
261
  }
255
262
  });
@@ -257,18 +264,29 @@ function executeJobViya(sasjs, authConfig, jobPath, target, waitForJob, output,
257
264
  }
258
265
  exports.executeJobViya = executeJobViya;
259
266
  // REFACTOR: should be a utility
260
- function getContextName(target, returnStatusOnly) {
267
+ /**
268
+ * Gets job execution context name.
269
+ * @param target - SAS server configuration.
270
+ * @returns - job execution context name.
271
+ */
272
+ function getContextName(target) {
261
273
  var _a;
262
- if (returnStatusOnly === void 0) { returnStatusOnly = false; }
274
+ // default execution context of @sasjs/cli
263
275
  var defaultContextName = utils_2.contextName;
276
+ // get gontext name from target
264
277
  if (target === null || target === void 0 ? void 0 : target.contextName)
265
278
  return target.contextName;
266
- if (!returnStatusOnly) {
267
- (_a = process.logger) === null || _a === void 0 ? void 0 : _a.warn("`contextName` was not provided in your target configuration. Falling back to context ".concat(defaultContextName));
268
- }
279
+ (_a = process.logger) === null || _a === void 0 ? void 0 : _a.warn("`contextName` was not provided in your target configuration. Falling back to context ".concat(defaultContextName));
269
280
  return defaultContextName;
270
281
  }
271
282
  exports.getContextName = getContextName;
283
+ /**
284
+ * Logs to the console or writes job status to the file.
285
+ * @param submittedJob - job submitted fro execution.
286
+ * @param statusFile - file path to the status file.
287
+ * @param error - error generated during job execution.
288
+ * @param displayStatusFilePath - boolean indicating if file path to the status file should be logged.
289
+ */
272
290
  function displayStatus(submittedJob, statusFile, error, displayStatusFilePath) {
273
291
  if (error === void 0) { error = ''; }
274
292
  if (displayStatusFilePath === void 0) { displayStatusFilePath = false; }
@@ -283,10 +301,14 @@ function displayStatus(submittedJob, statusFile, error, displayStatusFilePath) {
283
301
  status = adapterStatus === 'Not Available'
284
302
  ? "Job Status: ".concat(adapterStatus, "\nDetails: ").concat(error, "\n")
285
303
  : "Job Status: ".concat(adapterStatus);
286
- if (adapterStatus === 'Initiating' || adapterStatus === 'completed')
304
+ // handle job states 'Initiating' and 'completed'
305
+ if (adapterStatus === 'Initiating' || adapterStatus === 'completed') {
287
306
  (0, displayResult_1.displaySuccess)(status);
288
- else
307
+ }
308
+ // display an job status as an error
309
+ else {
289
310
  (0, displayResult_1.displayError)({}, status);
311
+ }
290
312
  if (!statusFile) return [3 /*break*/, 5];
291
313
  folderPath = statusFile.split(path_1.default.sep);
292
314
  folderPath.pop();
@@ -298,9 +320,12 @@ function displayStatus(submittedJob, statusFile, error, displayStatusFilePath) {
298
320
  case 2:
299
321
  _a.sent();
300
322
  _a.label = 3;
301
- case 3: return [4 /*yield*/, (0, utils_1.createFile)(statusFile, status)];
323
+ case 3: return [4 /*yield*/, (0, utils_1.createFile)(statusFile, status)
324
+ // display file path to status file
325
+ ];
302
326
  case 4:
303
327
  _a.sent();
328
+ // display file path to status file
304
329
  if (displayStatusFilePath)
305
330
  (0, displayResult_1.displaySuccess)("Status saved to: ".concat(statusFile));
306
331
  _a.label = 5;
@@ -1,2 +1,13 @@
1
- export declare const saveLog: (logData: any, logFile: string | undefined, jobPath: string, returnStatusOnly: boolean) => Promise<void>;
2
- export declare const saveOutput: (outputData: any, outputFile: string, returnStatusOnly: boolean) => Promise<void>;
1
+ /**
2
+ * Saves log to a file.
3
+ * @param logData - log content.
4
+ * @param logFile - file path to log file.
5
+ * @param jobPath - file path to the job submitted for execution.
6
+ */
7
+ export declare const saveLog: (logData: any, logFile: string | undefined, jobPath: string) => Promise<void>;
8
+ /**
9
+ * Saves job output to the file.
10
+ * @param outputData - job output.
11
+ * @param outputFile - file path to output file.
12
+ */
13
+ export declare const saveOutput: (outputData: any, outputFile: string) => Promise<void>;
@@ -44,14 +44,23 @@ var path_1 = __importDefault(require("path"));
44
44
  var utils_1 = require("@sasjs/utils");
45
45
  var utils_2 = require("../../../utils/utils");
46
46
  var displayResult_1 = require("../../../utils/displayResult");
47
- var saveLog = function (logData, logFile, jobPath, returnStatusOnly) { return __awaiter(void 0, void 0, void 0, function () {
47
+ /**
48
+ * Saves log to a file.
49
+ * @param logData - log content.
50
+ * @param logFile - file path to log file.
51
+ * @param jobPath - file path to the job submitted for execution.
52
+ */
53
+ var saveLog = function (logData, logFile, jobPath) { return __awaiter(void 0, void 0, void 0, function () {
48
54
  var logPath, folderPath, parentFolderPath, logLines;
49
55
  return __generator(this, function (_a) {
50
56
  switch (_a.label) {
51
57
  case 0:
58
+ // use provide file path to log file
52
59
  if (logFile) {
53
60
  logPath = logFile;
54
61
  }
62
+ // use file path based on job file path
63
+ // the same file name will be used, but with *.log extension
55
64
  else {
56
65
  logPath = path_1.default.join(process.projectDir, "".concat(jobPath.split(path_1.default.sep).slice(-1).pop(), ".log"));
57
66
  }
@@ -70,18 +79,23 @@ var saveLog = function (logData, logFile, jobPath, returnStatusOnly) { return __
70
79
  return [4 /*yield*/, (0, utils_1.createFile)(logPath, logLines)];
71
80
  case 4:
72
81
  _a.sent();
73
- if (!returnStatusOnly)
74
- (0, displayResult_1.displaySuccess)("Log saved to ".concat(logPath));
82
+ (0, displayResult_1.displaySuccess)("Log saved to ".concat(logPath));
75
83
  return [2 /*return*/];
76
84
  }
77
85
  });
78
86
  }); };
79
87
  exports.saveLog = saveLog;
80
- var saveOutput = function (outputData, outputFile, returnStatusOnly) { return __awaiter(void 0, void 0, void 0, function () {
88
+ /**
89
+ * Saves job output to the file.
90
+ * @param outputData - job output.
91
+ * @param outputFile - file path to output file.
92
+ */
93
+ var saveOutput = function (outputData, outputFile) { return __awaiter(void 0, void 0, void 0, function () {
81
94
  var currentDirPath, outputPath, folderPath, parentFolderPath;
82
95
  return __generator(this, function (_a) {
83
96
  switch (_a.label) {
84
97
  case 0:
98
+ // try to convert job output into a string
85
99
  try {
86
100
  outputData = JSON.stringify(outputData, null, 2);
87
101
  }
@@ -105,8 +119,7 @@ var saveOutput = function (outputData, outputFile, returnStatusOnly) { return __
105
119
  case 3: return [4 /*yield*/, (0, utils_1.createFile)(outputPath, outputData)];
106
120
  case 4:
107
121
  _a.sent();
108
- if (!returnStatusOnly)
109
- (0, displayResult_1.displaySuccess)("Output saved to: ".concat(outputPath));
122
+ (0, displayResult_1.displaySuccess)("Output saved to: ".concat(outputPath));
110
123
  return [2 /*return*/];
111
124
  }
112
125
  });
@@ -4,8 +4,27 @@ import { TargetCommand } from '../../types/command/targetCommand';
4
4
  export declare class JobCommand extends TargetCommand {
5
5
  private jobSubCommands;
6
6
  constructor(args: string[]);
7
+ /**
8
+ * Method responsible for command execution.
9
+ * @returns - promise that resolves into return code.
10
+ */
7
11
  execute(): Promise<ReturnCode>;
12
+ /**
13
+ * Executes job on SASJS server.
14
+ * @param target - SASJS server configuration.
15
+ * @returns - promise that resolves into return code.
16
+ */
8
17
  executeJobSasjs(target: Target): Promise<ReturnCode>;
18
+ /**
19
+ * Executes job on SAS9 server.
20
+ * @param target - SAS9 server configuration.
21
+ * @returns - promise that resolves into return code.
22
+ */
9
23
  executeJobSas9(target: Target): Promise<ReturnCode>;
24
+ /**
25
+ * Executes job on Viya server.
26
+ * @param target - Viya server configuration.
27
+ * @returns - promise that resolves into return code.
28
+ */
10
29
  executeJobViya(target: Target): Promise<ReturnCode>;
11
30
  }