Comments on PR - some small changes.

This commit is contained in:
mike12345567 2024-01-24 12:33:29 +00:00
parent 907e3396f9
commit 35a3d663ba
7 changed files with 658 additions and 46 deletions

View File

@ -97,9 +97,7 @@
$: schemaReadOnly = !responseSuccess $: schemaReadOnly = !responseSuccess
$: variablesReadOnly = !responseSuccess $: variablesReadOnly = !responseSuccess
$: showVariablesTab = shouldShowVariables(dynamicVariables, variablesReadOnly) $: showVariablesTab = shouldShowVariables(dynamicVariables, variablesReadOnly)
$: hasSchema = $: hasSchema = Object.keys(schema || {}).length !== 0
Object.keys(schema || {}).length !== 0 ||
Object.keys(query?.schema || {}).length !== 0
$: runtimeUrlQueries = readableToRuntimeMap(mergedBindings, breakQs) $: runtimeUrlQueries = readableToRuntimeMap(mergedBindings, breakQs)

View File

@ -7,7 +7,7 @@ import { invalidateDynamicVariables } from "../../../threads/utils"
import env from "../../../environment" import env from "../../../environment"
import { events, context, utils, constants } from "@budibase/backend-core" import { events, context, utils, constants } from "@budibase/backend-core"
import sdk from "../../../sdk" import sdk from "../../../sdk"
import { QueryEvent } from "../../../threads/definitions" import { QueryEvent, QueryResponse } from "../../../threads/definitions"
import { import {
ConfigType, ConfigType,
Query, Query,
@ -168,7 +168,7 @@ export async function preview(ctx: UserCtx) {
}, },
} }
const { rows, keys, info, extra } = (await Runner.run(inputs)) as any const { rows, keys, info, extra } = await Runner.run<QueryResponse>(inputs)
const previewSchema: Record<string, QuerySchema> = {} const previewSchema: Record<string, QuerySchema> = {}
const makeQuerySchema = (type: FieldType, name: string): QuerySchema => ({ const makeQuerySchema = (type: FieldType, name: string): QuerySchema => ({
type, type,
@ -203,8 +203,8 @@ export async function preview(ctx: UserCtx) {
// if existing schema, update to include any previous schema keys // if existing schema, update to include any previous schema keys
if (existingSchema) { if (existingSchema) {
for (let key of Object.keys(previewSchema)) { for (let key of Object.keys(previewSchema)) {
if (existingSchema[key]?.type) { if (existingSchema[key]) {
previewSchema[key] = existingSchema[key].type previewSchema[key] = existingSchema[key]
} }
} }
} }
@ -267,7 +267,9 @@ async function execute(
schema: query.schema, schema: query.schema,
} }
const { rows, pagination, extra, info } = (await Runner.run(inputs)) as any const { rows, pagination, extra, info } = await Runner.run<QueryResponse>(
inputs
)
// remove the raw from execution incase transformer being used to hide data // remove the raw from execution incase transformer being used to hide data
if (extra?.raw) { if (extra?.raw) {
delete extra.raw delete extra.raw

View File

@ -5,7 +5,7 @@ import { getQueryParams, isProdAppID } from "../../../db/utils"
import { BaseQueryVerbs } from "../../../constants" import { BaseQueryVerbs } from "../../../constants"
import { Query, QuerySchema } from "@budibase/types" import { Query, QuerySchema } from "@budibase/types"
function updateSchema(query: Query) { function updateSchema(query: Query): Query {
if (!query.schema) { if (!query.schema) {
return query return query
} }
@ -21,7 +21,7 @@ function updateSchema(query: Query) {
return query return query
} }
function updateSchemas(queries: Query[]) { function updateSchemas(queries: Query[]): Query[] {
return queries.map(query => updateSchema(query)) return queries.map(query => updateSchema(query))
} }

View File

@ -1,4 +1,4 @@
import { QuerySchema } from "@budibase/types" import { QuerySchema, Row } from "@budibase/types"
export type WorkerCallback = (error: any, response?: any) => void export type WorkerCallback = (error: any, response?: any) => void
@ -16,6 +16,14 @@ export interface QueryEvent {
schema?: Record<string, QuerySchema | string> schema?: Record<string, QuerySchema | string>
} }
export interface QueryResponse {
rows: Row[]
keys: string[]
info: any
extra: any
pagination: any
}
export interface QueryVariable { export interface QueryVariable {
queryId: string queryId: string
name: string name: string

View File

@ -74,7 +74,7 @@ export class Thread {
) )
} }
run(job: AutomationJob | QueryEvent) { run<T>(job: AutomationJob | QueryEvent): Promise<T> {
const timeout = this.timeoutMs const timeout = this.timeoutMs
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
function fire(worker: any) { function fire(worker: any) {

View File

@ -1,7 +1,12 @@
import { default as threadUtils } from "./utils" import { default as threadUtils } from "./utils"
threadUtils.threadSetup() threadUtils.threadSetup()
import { WorkerCallback, QueryEvent, QueryVariable } from "./definitions" import {
WorkerCallback,
QueryEvent,
QueryVariable,
QueryResponse,
} from "./definitions"
import ScriptRunner from "../utilities/scriptRunner" import ScriptRunner from "../utilities/scriptRunner"
import { getIntegration } from "../integrations" import { getIntegration } from "../integrations"
import { processStringSync } from "@budibase/string-templates" import { processStringSync } from "@budibase/string-templates"
@ -9,7 +14,7 @@ import { context, cache, auth } from "@budibase/backend-core"
import { getGlobalIDFromUserMetadataID } from "../db/utils" import { getGlobalIDFromUserMetadataID } from "../db/utils"
import sdk from "../sdk" import sdk from "../sdk"
import { cloneDeep } from "lodash/fp" import { cloneDeep } from "lodash/fp"
import { SourceName, Query } from "@budibase/types" import { Query } from "@budibase/types"
import { isSQL } from "../integrations/utils" import { isSQL } from "../integrations/utils"
import { interpolateSQL } from "../integrations/queries/sql" import { interpolateSQL } from "../integrations/queries/sql"
@ -53,7 +58,7 @@ class QueryRunner {
this.hasDynamicVariables = false this.hasDynamicVariables = false
} }
async execute(): Promise<any> { async execute(): Promise<QueryResponse> {
let { datasource, fields, queryVerb, transformer, schema } = this let { datasource, fields, queryVerb, transformer, schema } = this
let datasourceClone = cloneDeep(datasource) let datasourceClone = cloneDeep(datasource)
let fieldsClone = cloneDeep(fields) let fieldsClone = cloneDeep(fields)

661
yarn.lock

File diff suppressed because it is too large Load Diff