Adding in raw functionality.
This commit is contained in:
parent
a48d7966a6
commit
6df90803ad
|
@ -32,12 +32,11 @@
|
||||||
} from "constants/backend"
|
} from "constants/backend"
|
||||||
import JSONPreview from "components/integration/JSONPreview.svelte"
|
import JSONPreview from "components/integration/JSONPreview.svelte"
|
||||||
|
|
||||||
let query
|
let query, datasource
|
||||||
let breakQs = {}
|
let breakQs = {}
|
||||||
let url = ""
|
let url = ""
|
||||||
// test - { info: { code: 500, time: "455ms", size: "2.09KB" }}
|
let response, schema
|
||||||
let response
|
let datasourceType, integrationInfo, queryConfig, responseSuccess
|
||||||
let schema
|
|
||||||
|
|
||||||
$: datasource = $datasources.list.find(ds => ds._id === query?.datasourceId)
|
$: datasource = $datasources.list.find(ds => ds._id === query?.datasourceId)
|
||||||
$: datasourceType = datasource?.source
|
$: datasourceType = datasource?.source
|
||||||
|
@ -242,12 +241,11 @@
|
||||||
bind:object={response.schema}
|
bind:object={response.schema}
|
||||||
name="header"
|
name="header"
|
||||||
headings
|
headings
|
||||||
activity
|
|
||||||
options={SchemaTypeOptions}
|
options={SchemaTypeOptions}
|
||||||
/>
|
/>
|
||||||
</Tab>
|
</Tab>
|
||||||
<Tab title="Raw">
|
<Tab title="Raw">
|
||||||
<TextArea disabled value={response.text} height="300" />
|
<TextArea disabled value={response.raw} height="300" />
|
||||||
</Tab>
|
</Tab>
|
||||||
<Tab title="Preview">
|
<Tab title="Preview">
|
||||||
{#if response}
|
{#if response}
|
||||||
|
|
|
@ -109,7 +109,7 @@ exports.preview = async function (ctx) {
|
||||||
const enrichedQuery = await enrichQueryFields(fields, parameters)
|
const enrichedQuery = await enrichQueryFields(fields, parameters)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { rows, keys, info } = await Runner.run({
|
const { rows, keys, info, raw } = await Runner.run({
|
||||||
datasource,
|
datasource,
|
||||||
queryVerb,
|
queryVerb,
|
||||||
query: enrichedQuery,
|
query: enrichedQuery,
|
||||||
|
@ -120,6 +120,7 @@ exports.preview = async function (ctx) {
|
||||||
rows,
|
rows,
|
||||||
schemaFields: [...new Set(keys)],
|
schemaFields: [...new Set(keys)],
|
||||||
info,
|
info,
|
||||||
|
raw,
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
ctx.throw(400, err)
|
ctx.throw(400, err)
|
||||||
|
|
|
@ -118,12 +118,14 @@ module RestModule {
|
||||||
}
|
}
|
||||||
|
|
||||||
async parseResponse(response: any) {
|
async parseResponse(response: any) {
|
||||||
let data
|
let data, raw
|
||||||
const contentType = response.headers.get("content-type")
|
const contentType = response.headers.get("content-type")
|
||||||
if (contentType && contentType.indexOf("application/json") !== -1) {
|
if (contentType && contentType.indexOf("application/json") !== -1) {
|
||||||
data = await response.json()
|
data = await response.json()
|
||||||
|
raw = JSON.stringify(data)
|
||||||
} else {
|
} else {
|
||||||
data = await response.text()
|
data = await response.text()
|
||||||
|
raw = data
|
||||||
}
|
}
|
||||||
const size = formatBytes(response.headers.get("content-length") || 0)
|
const size = formatBytes(response.headers.get("content-length") || 0)
|
||||||
const time = `${Math.round(performance.now() - this.startTimeMs)}ms`
|
const time = `${Math.round(performance.now() - this.startTimeMs)}ms`
|
||||||
|
@ -134,6 +136,7 @@ module RestModule {
|
||||||
size,
|
size,
|
||||||
time,
|
time,
|
||||||
},
|
},
|
||||||
|
raw,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,10 +33,12 @@ async function runAndTransform(datasource, queryVerb, query, transformer) {
|
||||||
|
|
||||||
let output = formatResponse(await integration[queryVerb](query))
|
let output = formatResponse(await integration[queryVerb](query))
|
||||||
let rows = output,
|
let rows = output,
|
||||||
info = undefined
|
info = undefined,
|
||||||
|
raw = undefined
|
||||||
if (hasExtraData(output)) {
|
if (hasExtraData(output)) {
|
||||||
rows = output.data
|
rows = output.data
|
||||||
info = output.info
|
info = output.info
|
||||||
|
raw = output.raw
|
||||||
}
|
}
|
||||||
|
|
||||||
// transform as required
|
// transform as required
|
||||||
|
@ -62,7 +64,7 @@ async function runAndTransform(datasource, queryVerb, query, transformer) {
|
||||||
integration.end()
|
integration.end()
|
||||||
}
|
}
|
||||||
|
|
||||||
return { rows, keys, info }
|
return { rows, keys, info, raw }
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = (input, callback) => {
|
module.exports = (input, callback) => {
|
||||||
|
|
Loading…
Reference in New Issue