mirror of
https://github.com/sasjs/adapter.git
synced 2026-01-14 15:40:06 +00:00
fix: move SASjsRequest array from BaseJobExecutor class to RequestClient class
This commit is contained in:
@@ -51,6 +51,10 @@ export class SASViyaApiClient {
|
|||||||
)
|
)
|
||||||
private folderMap = new Map<string, Job[]>()
|
private folderMap = new Map<string, Job[]>()
|
||||||
|
|
||||||
|
public appendRequest(response: any, program: string, debug: boolean) {
|
||||||
|
this.requestClient!.appendRequest(response, program, debug)
|
||||||
|
}
|
||||||
|
|
||||||
public get debug() {
|
public get debug() {
|
||||||
return this._debug
|
return this._debug
|
||||||
}
|
}
|
||||||
|
|||||||
10
src/SASjs.ts
10
src/SASjs.ts
@@ -879,19 +879,13 @@ export default class SASjs {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public getSasRequests() {
|
public getSasRequests() {
|
||||||
const requests = [
|
const requests = [...this.requestClient!.getRequests()]
|
||||||
...this.webJobExecutor!.getRequests(),
|
|
||||||
...this.computeJobExecutor!.getRequests(),
|
|
||||||
...this.jesJobExecutor!.getRequests()
|
|
||||||
]
|
|
||||||
const sortedRequests = requests.sort(compareTimestamps)
|
const sortedRequests = requests.sort(compareTimestamps)
|
||||||
return sortedRequests
|
return sortedRequests
|
||||||
}
|
}
|
||||||
|
|
||||||
public clearSasRequests() {
|
public clearSasRequests() {
|
||||||
this.webJobExecutor!.clearRequests()
|
this.requestClient!.clearRequests()
|
||||||
this.computeJobExecutor!.clearRequests()
|
|
||||||
this.jesJobExecutor!.clearRequests()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private setupConfiguration() {
|
private setupConfiguration() {
|
||||||
|
|||||||
@@ -35,14 +35,12 @@ export class ComputeJobExecutor extends BaseJobExecutor {
|
|||||||
expectWebout
|
expectWebout
|
||||||
)
|
)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
this.appendRequest(response, sasJob, config.debug)
|
this.sasViyaApiClient.appendRequest(response, sasJob, config.debug)
|
||||||
|
|
||||||
resolve(response.result)
|
resolve(response.result)
|
||||||
})
|
})
|
||||||
.catch(async (e: Error) => {
|
.catch(async (e: Error) => {
|
||||||
if (e instanceof ComputeJobExecutionError) {
|
if (e instanceof ComputeJobExecutionError) {
|
||||||
this.appendRequest(e, sasJob, config.debug)
|
this.sasViyaApiClient.appendRequest(e, sasJob, config.debug)
|
||||||
|
|
||||||
reject(new ErrorResponse(e?.message, e))
|
reject(new ErrorResponse(e?.message, e))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ export class JesJobExecutor extends BaseJobExecutor {
|
|||||||
this.sasViyaApiClient
|
this.sasViyaApiClient
|
||||||
?.executeJob(sasJob, config.contextName, config.debug, data, authConfig)
|
?.executeJob(sasJob, config.contextName, config.debug, data, authConfig)
|
||||||
.then((response: any) => {
|
.then((response: any) => {
|
||||||
this.appendRequest(response, sasJob, config.debug)
|
this.sasViyaApiClient.appendRequest(response, sasJob, config.debug)
|
||||||
|
|
||||||
let responseObject = {}
|
let responseObject = {}
|
||||||
|
|
||||||
@@ -49,7 +49,7 @@ export class JesJobExecutor extends BaseJobExecutor {
|
|||||||
})
|
})
|
||||||
.catch(async (e: Error) => {
|
.catch(async (e: Error) => {
|
||||||
if (e instanceof JobExecutionError) {
|
if (e instanceof JobExecutionError) {
|
||||||
this.appendRequest(e, sasJob, config.debug)
|
this.sasViyaApiClient.appendRequest(e, sasJob, config.debug)
|
||||||
|
|
||||||
reject(new ErrorResponse(e?.message, e))
|
reject(new ErrorResponse(e?.message, e))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,8 +15,6 @@ export interface JobExecutor {
|
|||||||
extraResponseAttributes?: ExtraResponseAttributes[]
|
extraResponseAttributes?: ExtraResponseAttributes[]
|
||||||
) => Promise<any>
|
) => Promise<any>
|
||||||
resendWaitingRequests: () => Promise<void>
|
resendWaitingRequests: () => Promise<void>
|
||||||
getRequests: () => SASjsRequest[]
|
|
||||||
clearRequests: () => void
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export abstract class BaseJobExecutor implements JobExecutor {
|
export abstract class BaseJobExecutor implements JobExecutor {
|
||||||
@@ -46,54 +44,7 @@ export abstract class BaseJobExecutor implements JobExecutor {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
getRequests = () => this.requests
|
|
||||||
|
|
||||||
clearRequests = () => {
|
|
||||||
this.requests = []
|
|
||||||
}
|
|
||||||
|
|
||||||
protected appendWaitingRequest(request: ExecuteFunction) {
|
protected appendWaitingRequest(request: ExecuteFunction) {
|
||||||
this.waitingRequests.push(request)
|
this.waitingRequests.push(request)
|
||||||
}
|
}
|
||||||
|
|
||||||
protected appendRequest(response: any, program: string, debug: boolean) {
|
|
||||||
let sourceCode = ''
|
|
||||||
let generatedCode = ''
|
|
||||||
let sasWork = null
|
|
||||||
|
|
||||||
if (debug) {
|
|
||||||
if (response?.log) {
|
|
||||||
sourceCode = parseSourceCode(response.log)
|
|
||||||
generatedCode = parseGeneratedCode(response.log)
|
|
||||||
|
|
||||||
if (response?.result) {
|
|
||||||
sasWork = response.result.WORK
|
|
||||||
} else {
|
|
||||||
sasWork = response.log
|
|
||||||
}
|
|
||||||
} else if (response?.result) {
|
|
||||||
sourceCode = parseSourceCode(response.result)
|
|
||||||
generatedCode = parseGeneratedCode(response.result)
|
|
||||||
sasWork = response.result.WORK
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const stringifiedResult =
|
|
||||||
typeof response?.result === 'string'
|
|
||||||
? response?.result
|
|
||||||
: JSON.stringify(response?.result, null, 2)
|
|
||||||
|
|
||||||
this.requests.push({
|
|
||||||
logFile: response?.log || stringifiedResult || response,
|
|
||||||
serviceLink: program,
|
|
||||||
timestamp: new Date(),
|
|
||||||
sourceCode,
|
|
||||||
generatedCode,
|
|
||||||
SASWORK: sasWork
|
|
||||||
})
|
|
||||||
|
|
||||||
if (this.requests.length > 20) {
|
|
||||||
this.requests.splice(0, 1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -113,13 +113,13 @@ export class WebJobExecutor extends BaseJobExecutor {
|
|||||||
const requestPromise = new Promise((resolve, reject) => {
|
const requestPromise = new Promise((resolve, reject) => {
|
||||||
this.requestClient!.post(apiUrl, formData, undefined)
|
this.requestClient!.post(apiUrl, formData, undefined)
|
||||||
.then(async (res: any) => {
|
.then(async (res: any) => {
|
||||||
|
this.requestClient!.appendRequest(res, sasJob, config.debug)
|
||||||
if (this.serverType === ServerType.SasViya && config.debug) {
|
if (this.serverType === ServerType.SasViya && config.debug) {
|
||||||
const jsonResponse = await parseSasViyaDebugResponse(
|
const jsonResponse = await parseSasViyaDebugResponse(
|
||||||
res.result,
|
res.result,
|
||||||
this.requestClient,
|
this.requestClient,
|
||||||
this.serverUrl
|
this.serverUrl
|
||||||
)
|
)
|
||||||
this.appendRequest(res, sasJob, config.debug)
|
|
||||||
resolve(jsonResponse)
|
resolve(jsonResponse)
|
||||||
}
|
}
|
||||||
if (this.serverType === ServerType.Sas9 && config.debug) {
|
if (this.serverType === ServerType.Sas9 && config.debug) {
|
||||||
@@ -128,17 +128,14 @@ export class WebJobExecutor extends BaseJobExecutor {
|
|||||||
jsonResponse = parseWeboutResponse(res.result, apiUrl)
|
jsonResponse = parseWeboutResponse(res.result, apiUrl)
|
||||||
|
|
||||||
getValidJson(jsonResponse)
|
getValidJson(jsonResponse)
|
||||||
this.appendRequest(res, sasJob, config.debug)
|
|
||||||
resolve(res.result)
|
resolve(res.result)
|
||||||
}
|
}
|
||||||
this.appendRequest(res, sasJob, config.debug)
|
|
||||||
getValidJson(res.result as string)
|
getValidJson(res.result as string)
|
||||||
resolve(res.result)
|
resolve(res.result)
|
||||||
})
|
})
|
||||||
.catch(async (e: Error) => {
|
.catch(async (e: Error) => {
|
||||||
if (e instanceof JobExecutionError) {
|
if (e instanceof JobExecutionError) {
|
||||||
this.appendRequest(e, sasJob, config.debug)
|
this.requestClient!.appendRequest(e, sasJob, config.debug)
|
||||||
|
|
||||||
reject(new ErrorResponse(e?.message, e))
|
reject(new ErrorResponse(e?.message, e))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,10 +8,11 @@ import {
|
|||||||
InternalServerError,
|
InternalServerError,
|
||||||
JobExecutionError
|
JobExecutionError
|
||||||
} from '../types/errors'
|
} from '../types/errors'
|
||||||
|
import { SASjsRequest } from '../types'
|
||||||
import { parseWeboutResponse } from '../utils/parseWeboutResponse'
|
import { parseWeboutResponse } from '../utils/parseWeboutResponse'
|
||||||
import { prefixMessage } from '@sasjs/utils/error'
|
import { prefixMessage } from '@sasjs/utils/error'
|
||||||
import { SAS9AuthError } from '../types/errors/SAS9AuthError'
|
import { SAS9AuthError } from '../types/errors/SAS9AuthError'
|
||||||
import { getValidJson } from '../utils'
|
import { parseGeneratedCode, parseSourceCode } from '../utils'
|
||||||
|
|
||||||
export interface HttpClient {
|
export interface HttpClient {
|
||||||
get<T>(
|
get<T>(
|
||||||
@@ -47,6 +48,8 @@ export interface HttpClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class RequestClient implements HttpClient {
|
export class RequestClient implements HttpClient {
|
||||||
|
private requests: SASjsRequest[] = []
|
||||||
|
|
||||||
protected csrfToken: CsrfToken = { headerName: '', value: '' }
|
protected csrfToken: CsrfToken = { headerName: '', value: '' }
|
||||||
protected fileUploadCsrfToken: CsrfToken | undefined
|
protected fileUploadCsrfToken: CsrfToken | undefined
|
||||||
protected httpClient: AxiosInstance
|
protected httpClient: AxiosInstance
|
||||||
@@ -83,6 +86,53 @@ export class RequestClient implements HttpClient {
|
|||||||
return this.httpClient.defaults.baseURL || ''
|
return this.httpClient.defaults.baseURL || ''
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public getRequests = () => this.requests
|
||||||
|
|
||||||
|
public clearRequests = () => {
|
||||||
|
this.requests = []
|
||||||
|
}
|
||||||
|
|
||||||
|
public appendRequest(response: any, program: string, debug: boolean) {
|
||||||
|
let sourceCode = ''
|
||||||
|
let generatedCode = ''
|
||||||
|
let sasWork = null
|
||||||
|
|
||||||
|
if (debug) {
|
||||||
|
if (response?.log) {
|
||||||
|
sourceCode = parseSourceCode(response.log)
|
||||||
|
generatedCode = parseGeneratedCode(response.log)
|
||||||
|
|
||||||
|
if (response?.result) {
|
||||||
|
sasWork = response.result.WORK
|
||||||
|
} else {
|
||||||
|
sasWork = response.log
|
||||||
|
}
|
||||||
|
} else if (response?.result) {
|
||||||
|
sourceCode = parseSourceCode(response.result)
|
||||||
|
generatedCode = parseGeneratedCode(response.result)
|
||||||
|
sasWork = response.result.WORK
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const stringifiedResult =
|
||||||
|
typeof response?.result === 'string'
|
||||||
|
? response?.result
|
||||||
|
: JSON.stringify(response?.result, null, 2)
|
||||||
|
|
||||||
|
this.requests.push({
|
||||||
|
logFile: response?.log || stringifiedResult || response,
|
||||||
|
serviceLink: program,
|
||||||
|
timestamp: new Date(),
|
||||||
|
sourceCode,
|
||||||
|
generatedCode,
|
||||||
|
SASWORK: sasWork
|
||||||
|
})
|
||||||
|
|
||||||
|
if (this.requests.length > 20) {
|
||||||
|
this.requests.splice(0, 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public async get<T>(
|
public async get<T>(
|
||||||
url: string,
|
url: string,
|
||||||
accessToken: string | undefined,
|
accessToken: string | undefined,
|
||||||
|
|||||||
Reference in New Issue
Block a user