1
0
mirror of https://github.com/sasjs/adapter.git synced 2026-01-18 09:30:06 +00:00

Merge pull request #766 from sasjs/breaking-change

fix!: move methods from main sasjs class to respective api client class
This commit is contained in:
Allan Bowe
2022-10-20 14:02:06 +01:00
committed by GitHub
4 changed files with 92 additions and 102 deletions

View File

@@ -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) => {

View File

@@ -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,58 +90,50 @@ 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.
* @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.
* @param debug - (optional) if true, global debug config will be overriden
*/ */
public async executeScriptSAS9( public async executeScript({
linesOfCode: string[], linesOfCode,
userName: string, fileName,
password: string contextName,
) { runTime,
this.isMethodSupported('executeScriptSAS9', [ServerType.Sas9]) authConfig,
authConfigSas9,
debug
}: ExecuteScriptParams) {
this.isMethodSupported('executeScript', [
ServerType.Sas9,
ServerType.Sasjs,
ServerType.SasViya
])
if (this.sasjsConfig.serverType === ServerType.Sas9) {
if (!authConfigSas9)
throw new Error('Auth config for sas9 is not provided')
return await this.sas9ApiClient?.executeScript( return await this.sas9ApiClient?.executeScript(
linesOfCode, linesOfCode,
userName, authConfigSas9.userName,
password authConfigSas9.password
) )
} }
/** if (this.sasjsConfig.serverType === ServerType.Sasjs) {
* Executes SAS code on a SASJS server return await this.sasJSApiClient?.executeScript(
* @param code - a string of code from the file to run. linesOfCode.join('\n'),
* @param authConfig - (optional) a valid client, secret, refresh and access tokens that are authorised to execute scripts. runTime,
*/ authConfig
public async executeScriptSASjs( )
code: string,
runTime?: string,
authConfig?: AuthConfig
) {
this.isMethodSupported('executeScriptSASJS', [ServerType.Sasjs])
return await this.sasJSApiClient?.executeScript(code, runTime, authConfig)
} }
/** if (this.sasjsConfig.serverType === ServerType.SasViya) {
* 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
*/
public async executeScriptSASViya(
fileName: string,
linesOfCode: string[],
contextName: string,
authConfig?: AuthConfig,
debug?: boolean
) {
this.isMethodSupported('executeScriptSASViya', [ServerType.SasViya])
contextName = contextName || this.sasjsConfig.contextName contextName = contextName || this.sasjsConfig.contextName
if (!contextName) { if (!contextName) {
@@ -139,6 +142,12 @@ export default class SASjs {
) )
} }
if (!fileName) {
throw new Error(
'File name is required in case of SAS VIYA. Please provide a `fileName`.'
)
}
return await this.sasViyaApiClient!.executeScript( return await this.sasViyaApiClient!.executeScript(
fileName, fileName,
linesOfCode, linesOfCode,
@@ -148,6 +157,7 @@ export default class SASjs {
debug ? debug : this.sasjsConfig.debug debug ? debug : this.sasjsConfig.debug
) )
} }
}
/** /**
* Gets compute contexts. * Gets compute contexts.
@@ -826,33 +836,6 @@ export default class SASjs {
) )
} }
/**
* Creates the folders and services at the given location `appLoc` on the given server `serverUrl`.
* @param dataJson - the JSON specifying the folders and files to be created, can also includes
* appLoc, streamServiceName, streamWebFolder, streamLogo
* @param appLoc - (optional) the base folder in which to create the new folders and
* services. If not provided, is taken from SASjsConfig. Precedence will be of appLoc present in dataJson.
* @param authConfig - (optional) a valid client, secret, refresh and access tokens that are authorised to execute compute jobs.
*/
public async deployToSASjs(
dataJson: ServicePackSASjs,
appLoc?: string,
authConfig?: AuthConfig
) {
if (!appLoc) {
appLoc = this.sasjsConfig.appLoc
}
return await this.sasJSApiClient?.deploy(dataJson, appLoc, authConfig)
}
public async executeJobSASjs(query: ExecutionQuery, authConfig?: AuthConfig) {
return await this.sasJSApiClient?.executeJob(
query,
this.sasjsConfig.appLoc,
authConfig
)
}
/** /**
* Kicks off execution of the given job via the compute API. * Kicks off execution of the given job via the compute API.
* @returns an object representing the compute session created for the given job. * @returns an object representing the compute session created for the given job.

View File

@@ -8,6 +8,13 @@ import { getTokens } from './auth/getTokens'
export class SASjsApiClient { export class SASjsApiClient {
constructor(private requestClient: RequestClient) {} constructor(private requestClient: RequestClient) {}
/**
* Creates the folders and services at the given location `appLoc` on the given server `serverUrl`.
* @param dataJson - the JSON specifying the folders and files to be created, can also includes
* appLoc, streamServiceName, streamWebFolder, streamLogo
* @param appLoc - the base folder in which to create the new folders and services.
* @param authConfig - (optional) a valid client, secret, refresh and access tokens that are authorised to execute compute jobs.
*/
public async deploy( public async deploy(
dataJson: ServicePackSASjs, dataJson: ServicePackSASjs,
appLoc: string, appLoc: string,

View File

@@ -3,4 +3,6 @@ export * from './types'
export * from './types/errors' export * from './types/errors'
export * from './SASViyaApiClient' export * from './SASViyaApiClient'
export * from './SAS9ApiClient' export * from './SAS9ApiClient'
export * from './SASjsApiClient'
export * from './request/SasjsRequestClient'
export default SASjs export default SASjs