mirror of
https://github.com/sasjs/server.git
synced 2025-12-11 11:44:34 +00:00
Merge pull request #70 from sasjs/parse-log-to-array
feat: parse log to array
This commit is contained in:
@@ -92,6 +92,14 @@ components:
|
|||||||
- clientSecret
|
- clientSecret
|
||||||
type: object
|
type: object
|
||||||
additionalProperties: false
|
additionalProperties: false
|
||||||
|
LogLine:
|
||||||
|
properties:
|
||||||
|
line:
|
||||||
|
type: string
|
||||||
|
required:
|
||||||
|
- line
|
||||||
|
type: object
|
||||||
|
additionalProperties: false
|
||||||
HTTPHeaders:
|
HTTPHeaders:
|
||||||
properties: {}
|
properties: {}
|
||||||
type: object
|
type: object
|
||||||
@@ -104,7 +112,9 @@ components:
|
|||||||
_webout:
|
_webout:
|
||||||
type: string
|
type: string
|
||||||
log:
|
log:
|
||||||
type: string
|
items:
|
||||||
|
$ref: '#/components/schemas/LogLine'
|
||||||
|
type: array
|
||||||
message:
|
message:
|
||||||
type: string
|
type: string
|
||||||
httpHeaders:
|
httpHeaders:
|
||||||
@@ -112,6 +122,7 @@ components:
|
|||||||
required:
|
required:
|
||||||
- status
|
- status
|
||||||
- _webout
|
- _webout
|
||||||
|
- log
|
||||||
- httpHeaders
|
- httpHeaders
|
||||||
type: object
|
type: object
|
||||||
additionalProperties: false
|
additionalProperties: false
|
||||||
@@ -1070,7 +1081,7 @@ paths:
|
|||||||
$ref: '#/components/schemas/ExecuteReturnJsonResponse'
|
$ref: '#/components/schemas/ExecuteReturnJsonResponse'
|
||||||
examples:
|
examples:
|
||||||
'Example 1':
|
'Example 1':
|
||||||
value: {status: success, _webout: 'webout content', httpHeaders: {Content-type: application/zip, Cache-Control: 'public, max-age=1000'}}
|
value: {status: success, _webout: 'webout content', log: [], httpHeaders: {Content-type: application/zip, Cache-Control: 'public, max-age=1000'}}
|
||||||
description: "Trigger a SAS program using it's location in the _program parameter.\nEnable debugging using the _debug parameter.\nAdditional URL parameters are turned into SAS macro variables.\nAny files provided are placed into the session and\ncorresponding _WEBIN_XXX variables are created."
|
description: "Trigger a SAS program using it's location in the _program parameter.\nEnable debugging using the _debug parameter.\nAdditional URL parameters are turned into SAS macro variables.\nAny files provided are placed into the session and\ncorresponding _WEBIN_XXX variables are created."
|
||||||
summary: 'Execute Stored Program, return JSON'
|
summary: 'Execute Stored Program, return JSON'
|
||||||
tags:
|
tags:
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { Request, Security, Route, Tags, Post, Body } from 'tsoa'
|
|||||||
import { ExecuteReturnJson, ExecutionController } from './internal'
|
import { ExecuteReturnJson, ExecutionController } from './internal'
|
||||||
import { PreProgramVars } from '../types'
|
import { PreProgramVars } from '../types'
|
||||||
import { ExecuteReturnJsonResponse } from '.'
|
import { ExecuteReturnJsonResponse } from '.'
|
||||||
|
import { parseLogToArray } from '../utils'
|
||||||
|
|
||||||
interface ExecuteSASCodePayload {
|
interface ExecuteSASCodePayload {
|
||||||
/**
|
/**
|
||||||
@@ -43,7 +44,7 @@ const executeSASCode = async (req: any, { code }: ExecuteSASCodePayload) => {
|
|||||||
return {
|
return {
|
||||||
status: 'success',
|
status: 'success',
|
||||||
_webout: webout,
|
_webout: webout,
|
||||||
log,
|
log: parseLogToArray(log),
|
||||||
httpHeaders
|
httpHeaders
|
||||||
}
|
}
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
|
|||||||
@@ -18,7 +18,13 @@ import {
|
|||||||
ExecutionVars
|
ExecutionVars
|
||||||
} from './internal'
|
} from './internal'
|
||||||
import { PreProgramVars } from '../types'
|
import { PreProgramVars } from '../types'
|
||||||
import { getTmpFilesFolderPath, HTTPHeaders, makeFilesNamesMap } from '../utils'
|
import {
|
||||||
|
getTmpFilesFolderPath,
|
||||||
|
HTTPHeaders,
|
||||||
|
LogLine,
|
||||||
|
makeFilesNamesMap,
|
||||||
|
parseLogToArray
|
||||||
|
} from '../utils'
|
||||||
|
|
||||||
interface ExecuteReturnJsonPayload {
|
interface ExecuteReturnJsonPayload {
|
||||||
/**
|
/**
|
||||||
@@ -30,7 +36,7 @@ interface ExecuteReturnJsonPayload {
|
|||||||
export interface ExecuteReturnJsonResponse {
|
export interface ExecuteReturnJsonResponse {
|
||||||
status: string
|
status: string
|
||||||
_webout: string
|
_webout: string
|
||||||
log?: string
|
log: LogLine[]
|
||||||
message?: string
|
message?: string
|
||||||
httpHeaders: HTTPHeaders
|
httpHeaders: HTTPHeaders
|
||||||
}
|
}
|
||||||
@@ -70,6 +76,7 @@ export class STPController {
|
|||||||
@Example<ExecuteReturnJsonResponse>({
|
@Example<ExecuteReturnJsonResponse>({
|
||||||
status: 'success',
|
status: 'success',
|
||||||
_webout: 'webout content',
|
_webout: 'webout content',
|
||||||
|
log: [],
|
||||||
httpHeaders: {
|
httpHeaders: {
|
||||||
'Content-type': 'application/zip',
|
'Content-type': 'application/zip',
|
||||||
'Cache-Control': 'public, max-age=1000'
|
'Cache-Control': 'public, max-age=1000'
|
||||||
@@ -141,7 +148,7 @@ const executeReturnJson = async (
|
|||||||
return {
|
return {
|
||||||
status: 'success',
|
status: 'success',
|
||||||
_webout: webout,
|
_webout: webout,
|
||||||
log,
|
log: parseLogToArray(log),
|
||||||
httpHeaders
|
httpHeaders
|
||||||
}
|
}
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ export * from './generateAuthCode'
|
|||||||
export * from './generateRefreshToken'
|
export * from './generateRefreshToken'
|
||||||
export * from './getCertificates'
|
export * from './getCertificates'
|
||||||
export * from './getDesktopFields'
|
export * from './getDesktopFields'
|
||||||
|
export * from './parseLogToArray'
|
||||||
export * from './removeTokensInDB'
|
export * from './removeTokensInDB'
|
||||||
export * from './saveTokensInDB'
|
export * from './saveTokensInDB'
|
||||||
export * from './sleep'
|
export * from './sleep'
|
||||||
|
|||||||
9
api/src/utils/parseLogToArray.ts
Normal file
9
api/src/utils/parseLogToArray.ts
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
export interface LogLine {
|
||||||
|
line: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export const parseLogToArray = (content?: string): LogLine[] => {
|
||||||
|
if (!content) return []
|
||||||
|
|
||||||
|
return content.split('\n').map((line) => ({ line: line }))
|
||||||
|
}
|
||||||
33
api/src/utils/specs/parseLogToArray.spec.ts
Normal file
33
api/src/utils/specs/parseLogToArray.spec.ts
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
import { parseLogToArray } from '..'
|
||||||
|
|
||||||
|
describe('parseLogToArray', () => {
|
||||||
|
it('should parse log to array type', () => {
|
||||||
|
const log = parseLogToArray(`
|
||||||
|
line 1 of log content
|
||||||
|
line 2 of log content
|
||||||
|
line 3 of log content
|
||||||
|
line 4 of log content
|
||||||
|
`)
|
||||||
|
|
||||||
|
expect(log).toEqual([
|
||||||
|
{ line: '' },
|
||||||
|
{ line: 'line 1 of log content' },
|
||||||
|
{ line: 'line 2 of log content' },
|
||||||
|
{ line: 'line 3 of log content' },
|
||||||
|
{ line: 'line 4 of log content' },
|
||||||
|
{ line: ' ' }
|
||||||
|
])
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should parse log to array type if empty', () => {
|
||||||
|
const log = parseLogToArray('')
|
||||||
|
|
||||||
|
expect(log).toEqual([])
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should parse log to array type if not provided', () => {
|
||||||
|
const log = parseLogToArray()
|
||||||
|
|
||||||
|
expect(log).toEqual([])
|
||||||
|
})
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user