mirror of
https://github.com/sasjs/server.git
synced 2026-01-08 23:10:05 +00:00
feat(stp-execution): add returnLog option to execution query
This commit is contained in:
@@ -5,11 +5,15 @@ import { readFile, fileExists, createFile, moveFile } from '@sasjs/utils'
|
|||||||
import { PreProgramVars, TreeNode } from '../../types'
|
import { PreProgramVars, TreeNode } from '../../types'
|
||||||
import { generateFileUploadSasCode, getTmpFilesFolderPath } from '../../utils'
|
import { generateFileUploadSasCode, getTmpFilesFolderPath } from '../../utils'
|
||||||
|
|
||||||
|
export interface ExecutionVars {
|
||||||
|
[key: string]: string | number | undefined | boolean
|
||||||
|
}
|
||||||
|
|
||||||
export class ExecutionController {
|
export class ExecutionController {
|
||||||
async executeFile(
|
async executeFile(
|
||||||
programPath: string,
|
programPath: string,
|
||||||
preProgramVariables: PreProgramVars,
|
preProgramVariables: PreProgramVars,
|
||||||
vars: { [key: string]: string | number | undefined },
|
vars: ExecutionVars,
|
||||||
otherArgs?: any,
|
otherArgs?: any,
|
||||||
returnJson?: boolean
|
returnJson?: boolean
|
||||||
) {
|
) {
|
||||||
@@ -29,7 +33,7 @@ export class ExecutionController {
|
|||||||
async executeProgram(
|
async executeProgram(
|
||||||
program: string,
|
program: string,
|
||||||
preProgramVariables: PreProgramVars,
|
preProgramVariables: PreProgramVars,
|
||||||
vars: { [key: string]: string | number | undefined },
|
vars: ExecutionVars,
|
||||||
otherArgs?: any,
|
otherArgs?: any,
|
||||||
returnJson?: boolean
|
returnJson?: boolean
|
||||||
) {
|
) {
|
||||||
@@ -52,9 +56,10 @@ export class ExecutionController {
|
|||||||
|
|
||||||
const varStatments = Object.keys(vars).reduce(
|
const varStatments = Object.keys(vars).reduce(
|
||||||
(computed: string, key: string) =>
|
(computed: string, key: string) =>
|
||||||
`${computed}%let ${key}=${vars[key]};\n`,
|
key !== '_returnLog' ? `${computed}%let ${key}=${vars[key]};\n` : '',
|
||||||
''
|
''
|
||||||
)
|
)
|
||||||
|
|
||||||
const preProgramVarStatments = `
|
const preProgramVarStatments = `
|
||||||
%let _sasjs_tokenfile=${tokenFile};
|
%let _sasjs_tokenfile=${tokenFile};
|
||||||
%let _sasjs_username=${preProgramVariables?.username};
|
%let _sasjs_username=${preProgramVariables?.username};
|
||||||
@@ -130,7 +135,11 @@ ${program}`
|
|||||||
return {
|
return {
|
||||||
webout,
|
webout,
|
||||||
log:
|
log:
|
||||||
(debugValue && debugValue >= 131) || session.crashed ? log : undefined
|
(debugValue && debugValue >= 131) ||
|
||||||
|
session.crashed ||
|
||||||
|
Object.keys(vars).includes('_returnLog')
|
||||||
|
? log
|
||||||
|
: undefined
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,7 +148,7 @@ ${program}`
|
|||||||
: webout
|
: webout
|
||||||
}
|
}
|
||||||
|
|
||||||
buildDirectorytree() {
|
buildDirectoryTree() {
|
||||||
const root: TreeNode = {
|
const root: TreeNode = {
|
||||||
name: 'files',
|
name: 'files',
|
||||||
relativePath: '',
|
relativePath: '',
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import express from 'express'
|
import express from 'express'
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
import { Request, Security, Route, Tags, Post, Body, Get, Query } from 'tsoa'
|
import { Request, Security, Route, Tags, Post, Body, Get, Query } from 'tsoa'
|
||||||
import { ExecutionController } from './internal'
|
import { ExecutionController, ExecutionVars } from './internal'
|
||||||
import { PreProgramVars } from '../types'
|
import { PreProgramVars } from '../types'
|
||||||
import { getTmpFilesFolderPath, makeFilesNamesMap } from '../utils'
|
import { getTmpFilesFolderPath, makeFilesNamesMap } from '../utils'
|
||||||
|
|
||||||
@@ -66,7 +66,7 @@ const executeReturnRaw = async (
|
|||||||
req: express.Request,
|
req: express.Request,
|
||||||
_program: string
|
_program: string
|
||||||
): Promise<string> => {
|
): Promise<string> => {
|
||||||
const query = req.query as { [key: string]: string | number | undefined }
|
const query = req.query as ExecutionVars
|
||||||
const sasCodePath =
|
const sasCodePath =
|
||||||
path
|
path
|
||||||
.join(getTmpFilesFolderPath(), _program)
|
.join(getTmpFilesFolderPath(), _program)
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ export interface ExecutionQuery {
|
|||||||
_program: string
|
_program: string
|
||||||
macroVars?: MacroVars
|
macroVars?: MacroVars
|
||||||
_debug?: number
|
_debug?: number
|
||||||
|
_returnLog?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface FileQuery {
|
export interface FileQuery {
|
||||||
|
|||||||
@@ -86,5 +86,5 @@ export const executeProgramRawValidation = (data: any): Joi.ValidationResult =>
|
|||||||
Joi.object({
|
Joi.object({
|
||||||
_program: Joi.string().required()
|
_program: Joi.string().required()
|
||||||
})
|
})
|
||||||
.pattern(/^/, Joi.alternatives(Joi.string(), Joi.number()))
|
.pattern(/^/, Joi.alternatives(Joi.string(), Joi.number(), Joi.boolean()))
|
||||||
.validate(data)
|
.validate(data)
|
||||||
|
|||||||
Reference in New Issue
Block a user