Fix types

This commit is contained in:
Adria Navarro 2025-01-07 11:22:22 +01:00
parent c52dd56872
commit dedf2e5859
1 changed files with 8 additions and 15 deletions

View File

@ -10,7 +10,8 @@ import UserFetch from "./UserFetch.js"
import GroupUserFetch from "./GroupUserFetch" import GroupUserFetch from "./GroupUserFetch"
import CustomFetch from "./CustomFetch.js" import CustomFetch from "./CustomFetch.js"
import QueryArrayFetch from "./QueryArrayFetch.js" import QueryArrayFetch from "./QueryArrayFetch.js"
import { Table, UIDatasource, UIFetchAPI } from "@budibase/types" import { Table, UIDatasource } from "@budibase/types"
import { APIClient } from "../api/types.js"
const DataFetchMap = { const DataFetchMap = {
table: TableFetch, table: TableFetch,
@ -30,15 +31,7 @@ const DataFetchMap = {
} }
// Constructs a new fetch model for a certain datasource // Constructs a new fetch model for a certain datasource
export const fetchData = ({ export const fetchData = ({ API, datasource, options }: any) => {
API,
datasource,
options,
}: {
API: UIFetchAPI
datasource: UIDatasource
options: {}
}) => {
const Fetch = const Fetch =
DataFetchMap[datasource?.type as keyof typeof DataFetchMap] || TableFetch DataFetchMap[datasource?.type as keyof typeof DataFetchMap] || TableFetch
return new Fetch({ API, datasource, ...options }) return new Fetch({ API, datasource, ...options })
@ -50,14 +43,14 @@ const createEmptyFetchInstance = ({
API, API,
datasource, datasource,
}: { }: {
API: UIFetchAPI API: APIClient
datasource: UIDatasource datasource: any
}) => { }) => {
const handler = DataFetchMap[datasource?.type as keyof typeof DataFetchMap] const handler = DataFetchMap[datasource?.type as keyof typeof DataFetchMap]
if (!handler) { if (!handler) {
return null return null
} }
return new handler({ API }) return new handler({ API, datasource: null as any, query: null as any })
} }
// Fetches the definition of any type of datasource // Fetches the definition of any type of datasource
@ -65,7 +58,7 @@ export const getDatasourceDefinition = async ({
API, API,
datasource, datasource,
}: { }: {
API: UIFetchAPI API: APIClient
datasource: UIDatasource datasource: UIDatasource
}) => { }) => {
const instance = createEmptyFetchInstance({ API, datasource }) const instance = createEmptyFetchInstance({ API, datasource })
@ -78,7 +71,7 @@ export const getDatasourceSchema = ({
datasource, datasource,
definition, definition,
}: { }: {
API: UIFetchAPI API: APIClient
datasource: UIDatasource datasource: UIDatasource
definition: Table definition: Table
}) => { }) => {