Type schema object

This commit is contained in:
Adria Navarro 2025-01-17 10:33:01 +01:00
parent 2d4541a1af
commit 8cf7375202
1 changed files with 8 additions and 7 deletions

View File

@ -1,5 +1,6 @@
import { API } from "api" import { API } from "api"
import { DataFetchMap, DataFetchType } from "@budibase/frontend-core" import { DataFetchMap, DataFetchType } from "@budibase/frontend-core"
import { FieldType, TableSchema } from "@budibase/types"
/** /**
* Constructs a fetch instance for a given datasource. * Constructs a fetch instance for a given datasource.
@ -42,14 +43,14 @@ export const fetchDatasourceSchema = async <
} }
// Get the normal schema as long as we aren't wanting a form schema // Get the normal schema as long as we aren't wanting a form schema
let schema: any let schema: TableSchema | undefined
if (datasource?.type !== "query" || !options?.formSchema) { if (datasource?.type !== "query" || !options?.formSchema) {
schema = instance.getSchema(definition as any) schema = instance.getSchema(definition as any) as TableSchema
} else if ("parameters" in definition && definition.parameters?.length) { } else if ("parameters" in definition && definition.parameters?.length) {
schema = {} schema = {}
definition.parameters.forEach(param => { for (const param of definition.parameters) {
schema[param.name] = { ...param, type: "string" } schema[param.name] = { ...param, type: FieldType.STRING }
}) }
} }
if (!schema) { if (!schema) {
return null return null
@ -57,11 +58,11 @@ export const fetchDatasourceSchema = async <
// Strip hidden fields from views // Strip hidden fields from views
if (datasource.type === "viewV2") { if (datasource.type === "viewV2") {
Object.keys(schema).forEach(field => { for (const field of Object.keys(schema)) {
if (!schema[field].visible) { if (!schema[field].visible) {
delete schema[field] delete schema[field]
} }
}) }
} }
// Enrich schema with relationships if required // Enrich schema with relationships if required