Adding in raw functionality.

This commit is contained in:
mike12345567 2021-12-06 18:35:44 +00:00
parent 99e2cd52e8
commit b31cd5b6f7
4 changed files with 14 additions and 10 deletions

View File

@ -32,12 +32,11 @@
} from "constants/backend"
import JSONPreview from "components/integration/JSONPreview.svelte"
let query
let query, datasource
let breakQs = {}
let url = ""
// test - { info: { code: 500, time: "455ms", size: "2.09KB" }}
let response
let schema
let response, schema
let datasourceType, integrationInfo, queryConfig, responseSuccess
$: datasource = $datasources.list.find(ds => ds._id === query?.datasourceId)
$: datasourceType = datasource?.source
@ -242,12 +241,11 @@
bind:object={response.schema}
name="header"
headings
activity
options={SchemaTypeOptions}
/>
</Tab>
<Tab title="Raw">
<TextArea disabled value={response.text} height="300" />
<TextArea disabled value={response.raw} height="300" />
</Tab>
<Tab title="Preview">
{#if response}

View File

@ -109,7 +109,7 @@ exports.preview = async function (ctx) {
const enrichedQuery = await enrichQueryFields(fields, parameters)
try {
const { rows, keys, info } = await Runner.run({
const { rows, keys, info, raw } = await Runner.run({
datasource,
queryVerb,
query: enrichedQuery,
@ -120,6 +120,7 @@ exports.preview = async function (ctx) {
rows,
schemaFields: [...new Set(keys)],
info,
raw,
}
} catch (err) {
ctx.throw(400, err)

View File

@ -118,12 +118,14 @@ module RestModule {
}
async parseResponse(response: any) {
let data
let data, raw
const contentType = response.headers.get("content-type")
if (contentType && contentType.indexOf("application/json") !== -1) {
data = await response.json()
raw = JSON.stringify(data)
} else {
data = await response.text()
raw = data
}
const size = formatBytes(response.headers.get("content-length") || 0)
const time = `${Math.round(performance.now() - this.startTimeMs)}ms`
@ -134,6 +136,7 @@ module RestModule {
size,
time,
},
raw,
}
}

View File

@ -33,10 +33,12 @@ async function runAndTransform(datasource, queryVerb, query, transformer) {
let output = formatResponse(await integration[queryVerb](query))
let rows = output,
info = undefined
info = undefined,
raw = undefined
if (hasExtraData(output)) {
rows = output.data
info = output.info
raw = output.raw
}
// transform as required
@ -62,7 +64,7 @@ async function runAndTransform(datasource, queryVerb, query, transformer) {
integration.end()
}
return { rows, keys, info }
return { rows, keys, info, raw }
}
module.exports = (input, callback) => {