1
0
mirror of https://github.com/sasjs/adapter.git synced 2026-01-08 21:10:05 +00:00

Compare commits

..

5 Commits

Author SHA1 Message Date
Allan Bowe
cc28dfe7f0 fix: tidying up logic and adding descriptive comments 2022-02-21 19:40:24 +00:00
2ec2147245 chore: add detailed comment 2022-02-21 23:22:57 +05:00
9ca4732f76 fix: call sasJsJobExecutor only from cli 2022-02-21 23:08:55 +05:00
Muhammad Saad
35f37ac796 Merge pull request #650 from sasjs/sasjs-server-webout
fix: no need to parse if webout is an object
2022-02-21 15:54:12 +04:00
Saad Jutt
d7ad0288b9 fix: no need to parse if webout is an object 2022-02-21 16:45:41 +05:00
3 changed files with 52 additions and 17 deletions

View File

@@ -79,7 +79,8 @@ export default class SASjs {
} }
/** /**
* Executes the sas code against SAS9 server * Executes code against a SAS 9 server. Requires a runner to be present in
* the users home directory in metadata.
* @param linesOfCode - lines of sas code from the file to run. * @param linesOfCode - lines of sas code from the file to run.
* @param username - a string representing the username. * @param username - a string representing the username.
* @param password - a string representing the password. * @param password - a string representing the password.
@@ -99,7 +100,7 @@ export default class SASjs {
} }
/** /**
* Executes the sas code against SASViya server * Executes sas code in a SAS Viya compute session.
* @param fileName - name of the file to run. It will be converted to path to the file being submitted for execution. * @param fileName - name of the file to run. It will be converted to path to the file being submitted for execution.
* @param linesOfCode - lines of sas code from the file to run. * @param linesOfCode - lines of sas code from the file to run.
* @param contextName - context name on which code will be run on the server. * @param contextName - context name on which code will be run on the server.
@@ -643,7 +644,8 @@ export default class SASjs {
} }
/** /**
* Makes a request to the SAS Service specified in `SASjob`. The response * Makes a request to program specified in `SASjob` (could be a Viya Job, a
* SAS 9 Stored Process, or a SASjs Server Stored Program). The response
* object will always contain table names in lowercase, and column names in * object will always contain table names in lowercase, and column names in
* uppercase. Values are returned formatted by default, unformatted * uppercase. Values are returned formatted by default, unformatted
* values can be configured as an option in the `%webout` macro. * values can be configured as an option in the `%webout` macro.
@@ -652,7 +654,8 @@ export default class SASjs {
* the SAS `_program` parameter to run a Job Definition or SAS 9 Stored * the SAS `_program` parameter to run a Job Definition or SAS 9 Stored
* Process). Is prepended at runtime with the value of `appLoc`. * Process). Is prepended at runtime with the value of `appLoc`.
* @param data - a JSON object containing one or more tables to be sent to * @param data - a JSON object containing one or more tables to be sent to
* SAS. Can be `null` if no inputs required. * SAS. For an example of the table structure, see the project README. This
* value can be `null` if no inputs are required.
* @param config - provide any changes to the config here, for instance to * @param config - provide any changes to the config here, for instance to
* enable/disable `debug`. Any change provided will override the global config, * enable/disable `debug`. Any change provided will override the global config,
* for that particular function call. * for that particular function call.
@@ -682,18 +685,40 @@ export default class SASjs {
const validationResult = this.validateInput(data) const validationResult = this.validateInput(data)
// status is true if the data passes validation checks above
if (validationResult.status) { if (validationResult.status) {
if (config.serverType === ServerType.Sasjs) { if (config.serverType === ServerType.Sasjs) {
return await this.sasJsJobExecutor!.execute( /**
sasJob, * When sending the JSON data object to SAS, it is first converted to
data, * a set of specially formatted CSVs. These are passed as multi-part
config, * form data (converted to input files in the backend SAS session by the
loginRequiredCallback, * API). When running outside of a browser, the FormData object is not
authConfig, * available. So in this case, a slightly different executor is invoked,
extraResponseAttributes * which is similar to the sas9JobExecutor.
) */
if (typeof FormData === 'undefined') {
// cli invocation
return await this.sasJsJobExecutor!.execute(
sasJob,
data,
config,
loginRequiredCallback,
authConfig,
extraResponseAttributes
)
} else {
// web invocation
return await this.webJobExecutor!.execute(
sasJob,
data,
config,
loginRequiredCallback,
authConfig,
extraResponseAttributes
)
}
} else if ( } else if (
config.serverType !== ServerType.Sas9 && config.serverType === ServerType.SasViya &&
config.useComputeApi !== undefined && config.useComputeApi !== undefined &&
config.useComputeApi !== null config.useComputeApi !== null
) { ) {

View File

@@ -65,8 +65,12 @@ export class SasJsJobExecutor extends BaseJobExecutor {
let jsonResponse = res.result let jsonResponse = res.result
if (config.debug) { if (config.debug) {
const webout = parseWeboutResponse(res.result._webout, apiUrl) if (typeof res.result._webout === 'object') {
jsonResponse = getValidJson(webout) jsonResponse = res.result._webout
} else {
const webout = parseWeboutResponse(res.result._webout, apiUrl)
jsonResponse = getValidJson(webout)
}
} else { } else {
jsonResponse = getValidJson(res.result._webout) jsonResponse = getValidJson(res.result._webout)
} }

View File

@@ -108,6 +108,8 @@ export class WebJobExecutor extends BaseJobExecutor {
...this.getRequestParams(config) ...this.getRequestParams(config)
} }
// FormData is only valid in browser
// FormData is a part of JS web API (not included in native NodeJS).
let formData = new FormData() let formData = new FormData()
if (data) { if (data) {
@@ -178,8 +180,12 @@ export class WebJobExecutor extends BaseJobExecutor {
: res.result : res.result
break break
case ServerType.Sasjs: case ServerType.Sasjs:
const webout = parseWeboutResponse(res.result._webout, apiUrl) if (typeof res.result._webout === 'object') {
jsonResponse = getValidJson(webout) jsonResponse = res.result._webout
} else {
const webout = parseWeboutResponse(res.result._webout, apiUrl)
jsonResponse = getValidJson(webout)
}
break break
} }
} else if (this.serverType === ServerType.Sasjs) { } else if (this.serverType === ServerType.Sasjs) {