diff --git a/packages/frontend-core/src/components/grid/stores/datasources/nonPlus.js b/packages/frontend-core/src/components/grid/stores/datasources/nonPlus.ts similarity index 76% rename from packages/frontend-core/src/components/grid/stores/datasources/nonPlus.js rename to packages/frontend-core/src/components/grid/stores/datasources/nonPlus.ts index ea558d6236..4796f5d071 100644 --- a/packages/frontend-core/src/components/grid/stores/datasources/nonPlus.js +++ b/packages/frontend-core/src/components/grid/stores/datasources/nonPlus.ts @@ -1,7 +1,28 @@ import { SortOrder } from "@budibase/types" import { get } from "svelte/store" +import { Store as StoreContext } from ".." -export const createActions = context => { +interface NonPlusActions { + nonPlus: { + actions: { + saveDefinition: () => Promise + addRow: () => Promise + updateRow: () => Promise + deleteRows: () => Promise + getRow: () => Promise + isDatasourceValid: (datasource: { + type: string + id: string + tableId: string + }) => boolean + canUseColumn: (name: string) => boolean + } + } +} + +export type Store = NonPlusActions + +export const createActions = (context: StoreContext): NonPlusActions => { const { columns, table, viewV2 } = context const saveDefinition = async () => { @@ -20,7 +41,11 @@ export const createActions = context => { throw "This datasource does not support fetching individual rows" } - const isDatasourceValid = datasource => { + const isDatasourceValid = (datasource: { + type: string + id: string + tableId: string + }) => { // There are many different types and shapes of datasource, so we only // check that we aren't null return ( @@ -30,7 +55,7 @@ export const createActions = context => { ) } - const canUseColumn = name => { + const canUseColumn = (name: string) => { return get(columns).some(col => col.name === name) } @@ -50,11 +75,11 @@ export const createActions = context => { } // Small util to compare datasource definitions -const isSameDatasource = (a, b) => { +const isSameDatasource = (a: any, b: any) => { return JSON.stringify(a) === JSON.stringify(b) } -export const initialise = context => { +export const initialise = (context: StoreContext) => { const { datasource, sort, @@ -69,7 +94,7 @@ export const initialise = context => { } = context // Keep a list of subscriptions so that we can clear them when the datasource // config changes - let unsubscribers = [] + let unsubscribers: any[] = [] // Observe datasource changes and apply logic for view V2 datasources datasource.subscribe($datasource => { diff --git a/packages/frontend-core/src/components/grid/stores/index.ts b/packages/frontend-core/src/components/grid/stores/index.ts index c8f26fa90a..1ef5da03b6 100644 --- a/packages/frontend-core/src/components/grid/stores/index.ts +++ b/packages/frontend-core/src/components/grid/stores/index.ts @@ -58,7 +58,8 @@ export interface BaseStore { export type Store = BaseStore & Columns.Store & Table.Store & - ViewV2.Store & { + ViewV2.Store & + NonPlus.Store & { // TODO while typing the rest of stores datasource: Writable & { actions: any } definition: Writable