1
0
mirror of https://github.com/sasjs/server.git synced 2025-12-10 11:24:35 +00:00

feat(stp-execution): add returnLog option to execution query

This commit is contained in:
Yury Shkoda
2022-02-10 09:06:29 +03:00
parent e3f5206758
commit bf5767eadf
4 changed files with 18 additions and 8 deletions

View File

@@ -5,11 +5,15 @@ import { readFile, fileExists, createFile, moveFile } from '@sasjs/utils'
import { PreProgramVars, TreeNode } from '../../types'
import { generateFileUploadSasCode, getTmpFilesFolderPath } from '../../utils'
export interface ExecutionVars {
[key: string]: string | number | undefined | boolean
}
export class ExecutionController {
async executeFile(
programPath: string,
preProgramVariables: PreProgramVars,
vars: { [key: string]: string | number | undefined },
vars: ExecutionVars,
otherArgs?: any,
returnJson?: boolean
) {
@@ -29,7 +33,7 @@ export class ExecutionController {
async executeProgram(
program: string,
preProgramVariables: PreProgramVars,
vars: { [key: string]: string | number | undefined },
vars: ExecutionVars,
otherArgs?: any,
returnJson?: boolean
) {
@@ -52,9 +56,10 @@ export class ExecutionController {
const varStatments = Object.keys(vars).reduce(
(computed: string, key: string) =>
`${computed}%let ${key}=${vars[key]};\n`,
key !== '_returnLog' ? `${computed}%let ${key}=${vars[key]};\n` : '',
''
)
const preProgramVarStatments = `
%let _sasjs_tokenfile=${tokenFile};
%let _sasjs_username=${preProgramVariables?.username};
@@ -130,7 +135,11 @@ ${program}`
return {
webout,
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
}
buildDirectorytree() {
buildDirectoryTree() {
const root: TreeNode = {
name: 'files',
relativePath: '',

View File

@@ -1,7 +1,7 @@
import express from 'express'
import path from 'path'
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 { getTmpFilesFolderPath, makeFilesNamesMap } from '../utils'
@@ -66,7 +66,7 @@ const executeReturnRaw = async (
req: express.Request,
_program: string
): Promise<string> => {
const query = req.query as { [key: string]: string | number | undefined }
const query = req.query as ExecutionVars
const sasCodePath =
path
.join(getTmpFilesFolderPath(), _program)

View File

@@ -4,6 +4,7 @@ export interface ExecutionQuery {
_program: string
macroVars?: MacroVars
_debug?: number
_returnLog?: boolean
}
export interface FileQuery {

View File

@@ -86,5 +86,5 @@ export const executeProgramRawValidation = (data: any): Joi.ValidationResult =>
Joi.object({
_program: Joi.string().required()
})
.pattern(/^/, Joi.alternatives(Joi.string(), Joi.number()))
.pattern(/^/, Joi.alternatives(Joi.string(), Joi.number(), Joi.boolean()))
.validate(data)