mirror of
https://github.com/sasjs/adapter.git
synced 2026-01-18 17:40:06 +00:00
fix: merge executeScriptSAS9, executeScriptSASViya and executeScriptSASjs into single executeScript
BREAKING CHANGE
This commit is contained in:
@@ -71,13 +71,12 @@ export const computeTests = (adapter: SASjs, appLoc: string): TestSuite => ({
|
|||||||
test: () => {
|
test: () => {
|
||||||
const fileLines = [`data;`, `do x=1 to 100;`, `output;`, `end;`, `run;`]
|
const fileLines = [`data;`, `do x=1 to 100;`, `output;`, `end;`, `run;`]
|
||||||
|
|
||||||
return adapter.executeScriptSASViya(
|
return adapter.executeScript({
|
||||||
'sasCode.sas',
|
fileName: 'sasCode.sas',
|
||||||
fileLines,
|
linesOfCode: fileLines,
|
||||||
'SAS Studio compute context',
|
contextName: 'SAS Studio compute context',
|
||||||
undefined,
|
debug: true
|
||||||
true
|
})
|
||||||
)
|
|
||||||
},
|
},
|
||||||
assertion: (res: any) => {
|
assertion: (res: any) => {
|
||||||
const expectedLogContent = `1 data;\\n2 do x=1 to 100;\\n3 output;\\n4 end;\\n5 run;\\n\\n`
|
const expectedLogContent = `1 data;\\n2 do x=1 to 100;\\n3 output;\\n4 end;\\n5 run;\\n\\n`
|
||||||
@@ -92,13 +91,12 @@ export const computeTests = (adapter: SASjs, appLoc: string): TestSuite => ({
|
|||||||
const fileLines = [`%abort;`]
|
const fileLines = [`%abort;`]
|
||||||
|
|
||||||
return adapter
|
return adapter
|
||||||
.executeScriptSASViya(
|
.executeScript({
|
||||||
'sasCode.sas',
|
fileName: 'sasCode.sas',
|
||||||
fileLines,
|
linesOfCode: fileLines,
|
||||||
'SAS Studio compute context',
|
contextName: 'SAS Studio compute context',
|
||||||
undefined,
|
debug: true
|
||||||
true
|
})
|
||||||
)
|
|
||||||
.catch((err: any) => err)
|
.catch((err: any) => err)
|
||||||
},
|
},
|
||||||
assertion: (res: any) => {
|
assertion: (res: any) => {
|
||||||
|
|||||||
132
src/SASjs.ts
132
src/SASjs.ts
@@ -17,7 +17,8 @@ import {
|
|||||||
AuthConfig,
|
AuthConfig,
|
||||||
ExtraResponseAttributes,
|
ExtraResponseAttributes,
|
||||||
SasAuthResponse,
|
SasAuthResponse,
|
||||||
ServicePackSASjs
|
ServicePackSASjs,
|
||||||
|
AuthConfigSas9
|
||||||
} from '@sasjs/utils/types'
|
} from '@sasjs/utils/types'
|
||||||
import { RequestClient } from './request/RequestClient'
|
import { RequestClient } from './request/RequestClient'
|
||||||
import { SasjsRequestClient } from './request/SasjsRequestClient'
|
import { SasjsRequestClient } from './request/SasjsRequestClient'
|
||||||
@@ -33,6 +34,16 @@ import {
|
|||||||
import { ErrorResponse } from './types/errors'
|
import { ErrorResponse } from './types/errors'
|
||||||
import { LoginOptions, LoginResult } from './types/Login'
|
import { LoginOptions, LoginResult } from './types/Login'
|
||||||
|
|
||||||
|
interface ExecuteScriptParams {
|
||||||
|
linesOfCode: string[]
|
||||||
|
fileName?: string
|
||||||
|
contextName?: string
|
||||||
|
runTime?: string
|
||||||
|
authConfig?: AuthConfig
|
||||||
|
authConfigSas9?: AuthConfigSas9
|
||||||
|
debug?: boolean
|
||||||
|
}
|
||||||
|
|
||||||
const defaultConfig: SASjsConfig = {
|
const defaultConfig: SASjsConfig = {
|
||||||
serverUrl: '',
|
serverUrl: '',
|
||||||
pathSASJS: '/SASjsApi/stp/execute',
|
pathSASJS: '/SASjsApi/stp/execute',
|
||||||
@@ -79,74 +90,73 @@ export default class SASjs {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes SAS code on a SAS 9 server. Requires a runner to be present in
|
* Executes code on a SAS server.
|
||||||
* the users home directory in metadata.
|
* @param linesOfCode - lines of code to run.
|
||||||
* @param linesOfCode - lines of sas code from the file to run.
|
* @param fileName - (required for server type sas viya) name of the file to run. It will be converted to path to the file being submitted for execution.
|
||||||
* @param username - a string representing the username.
|
* @param contextName - (required for server type sas viya) context name on which code will be run on the server.
|
||||||
* @param password - a string representing the password.
|
* @param runTime - (required for server type sasjs) a string to represent runTime for code execution.
|
||||||
*/
|
|
||||||
public async executeScriptSAS9(
|
|
||||||
linesOfCode: string[],
|
|
||||||
userName: string,
|
|
||||||
password: string
|
|
||||||
) {
|
|
||||||
this.isMethodSupported('executeScriptSAS9', [ServerType.Sas9])
|
|
||||||
|
|
||||||
return await this.sas9ApiClient?.executeScript(
|
|
||||||
linesOfCode,
|
|
||||||
userName,
|
|
||||||
password
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Executes SAS code on a SASJS server
|
|
||||||
* @param code - a string of code from the file to run.
|
|
||||||
* @param authConfig - (optional) a valid client, secret, refresh and access tokens that are authorised to execute scripts.
|
* @param authConfig - (optional) a valid client, secret, refresh and access tokens that are authorised to execute scripts.
|
||||||
*/
|
* @param authConfigSas9 - (required for server type sas9) a valid username and password that are authorised to execute scripts.
|
||||||
public async executeScriptSASjs(
|
|
||||||
code: string,
|
|
||||||
runTime?: string,
|
|
||||||
authConfig?: AuthConfig
|
|
||||||
) {
|
|
||||||
this.isMethodSupported('executeScriptSASJS', [ServerType.Sasjs])
|
|
||||||
|
|
||||||
return await this.sasJSApiClient?.executeScript(code, runTime, authConfig)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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 linesOfCode - lines of sas code from the file to run.
|
|
||||||
* @param contextName - context name on which code will be run on the server.
|
|
||||||
* @param authConfig - (optional) the access token, refresh token, client and secret for authorizing the request.
|
|
||||||
* @param debug - (optional) if true, global debug config will be overriden
|
* @param debug - (optional) if true, global debug config will be overriden
|
||||||
*/
|
*/
|
||||||
public async executeScriptSASViya(
|
public async executeScript({
|
||||||
fileName: string,
|
linesOfCode,
|
||||||
linesOfCode: string[],
|
fileName,
|
||||||
contextName: string,
|
contextName,
|
||||||
authConfig?: AuthConfig,
|
runTime,
|
||||||
debug?: boolean
|
authConfig,
|
||||||
) {
|
authConfigSas9,
|
||||||
this.isMethodSupported('executeScriptSASViya', [ServerType.SasViya])
|
debug
|
||||||
|
}: ExecuteScriptParams) {
|
||||||
|
this.isMethodSupported('executeScript', [
|
||||||
|
ServerType.Sas9,
|
||||||
|
ServerType.Sasjs,
|
||||||
|
ServerType.SasViya
|
||||||
|
])
|
||||||
|
|
||||||
contextName = contextName || this.sasjsConfig.contextName
|
if (this.sasjsConfig.serverType === ServerType.Sas9) {
|
||||||
|
if (!authConfigSas9)
|
||||||
|
throw new Error('Auth config for sas9 is not provided')
|
||||||
|
|
||||||
if (!contextName) {
|
return await this.sas9ApiClient?.executeScript(
|
||||||
throw new Error(
|
linesOfCode,
|
||||||
'Context name is undefined. Please set a `contextName` in your SASjs or override config.'
|
authConfigSas9.userName,
|
||||||
|
authConfigSas9.password
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return await this.sasViyaApiClient!.executeScript(
|
if (this.sasjsConfig.serverType === ServerType.Sasjs) {
|
||||||
fileName,
|
return await this.sasJSApiClient?.executeScript(
|
||||||
linesOfCode,
|
linesOfCode.join('\n'),
|
||||||
contextName,
|
runTime,
|
||||||
authConfig,
|
authConfig
|
||||||
null,
|
)
|
||||||
debug ? debug : this.sasjsConfig.debug
|
}
|
||||||
)
|
|
||||||
|
if (this.sasjsConfig.serverType === ServerType.SasViya) {
|
||||||
|
contextName = contextName || this.sasjsConfig.contextName
|
||||||
|
|
||||||
|
if (!contextName) {
|
||||||
|
throw new Error(
|
||||||
|
'Context name is undefined. Please set a `contextName` in your SASjs or override config.'
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!fileName) {
|
||||||
|
throw new Error(
|
||||||
|
'File name is required in case of SAS VIYA. Please provide a `fileName`.'
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return await this.sasViyaApiClient!.executeScript(
|
||||||
|
fileName,
|
||||||
|
linesOfCode,
|
||||||
|
contextName,
|
||||||
|
authConfig,
|
||||||
|
null,
|
||||||
|
debug ? debug : this.sasjsConfig.debug
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user