From 79039a1c30fe4a59a11fc8edaaf5f8aa1bfc5051 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 14 Jan 2025 10:52:08 +0100 Subject: [PATCH] Use union type --- .../src/components/grid/stores/rows.ts | 5 ++--- packages/frontend-core/src/fetch/index.ts | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/packages/frontend-core/src/components/grid/stores/rows.ts b/packages/frontend-core/src/components/grid/stores/rows.ts index 07fbf02134..159a01a86f 100644 --- a/packages/frontend-core/src/components/grid/stores/rows.ts +++ b/packages/frontend-core/src/components/grid/stores/rows.ts @@ -1,5 +1,5 @@ import { writable, derived, get, Writable, Readable } from "svelte/store" -import { fetchData } from "../../../fetch" +import { DataFetch, fetchData } from "../../../fetch" import { NewRowID, RowPageSize } from "../lib/constants" import { generateRowID, @@ -13,7 +13,6 @@ import { sleep } from "../../../utils/utils" import { FieldType, Row, UIRow } from "@budibase/types" import { getRelatedTableValues } from "../../../utils" import { Store as StoreContext } from "." -import DataFetch from "../../../fetch/DataFetch" interface IndexedUIRow extends UIRow { __idx: number @@ -21,7 +20,7 @@ interface IndexedUIRow extends UIRow { interface RowStore { rows: Writable - fetch: Writable | null> // TODO: type this properly, having a union of all the possible options + fetch: Writable loaded: Writable refreshing: Writable loading: Writable diff --git a/packages/frontend-core/src/fetch/index.ts b/packages/frontend-core/src/fetch/index.ts index 4b9de01dae..1c1d6671e6 100644 --- a/packages/frontend-core/src/fetch/index.ts +++ b/packages/frontend-core/src/fetch/index.ts @@ -31,6 +31,20 @@ export const DataFetchMap = { queryarray: QueryArrayFetch, } +export type DataFetch = + | TableFetch + | ViewFetch + | ViewV2Fetch + | QueryFetch + | RelationshipFetch + | UserFetch + | GroupUserFetch + | CustomFetch + | NestedProviderFetch + | FieldFetch<"field"> + | JSONArrayFetch + | QueryArrayFetch + // Constructs a new fetch model for a certain datasource export const fetchData = ({ API,