Type nonPlus

This commit is contained in:
Adria Navarro 2024-12-20 14:57:49 +01:00
parent b45b409041
commit 7b130c7bcd
2 changed files with 33 additions and 7 deletions

View File

@ -1,7 +1,28 @@
import { SortOrder } from "@budibase/types" import { SortOrder } from "@budibase/types"
import { get } from "svelte/store" import { get } from "svelte/store"
import { Store as StoreContext } from ".."
export const createActions = context => { interface NonPlusActions {
nonPlus: {
actions: {
saveDefinition: () => Promise<void>
addRow: () => Promise<void>
updateRow: () => Promise<void>
deleteRows: () => Promise<void>
getRow: () => Promise<void>
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 { columns, table, viewV2 } = context
const saveDefinition = async () => { const saveDefinition = async () => {
@ -20,7 +41,11 @@ export const createActions = context => {
throw "This datasource does not support fetching individual rows" 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 // There are many different types and shapes of datasource, so we only
// check that we aren't null // check that we aren't null
return ( return (
@ -30,7 +55,7 @@ export const createActions = context => {
) )
} }
const canUseColumn = name => { const canUseColumn = (name: string) => {
return get(columns).some(col => col.name === name) return get(columns).some(col => col.name === name)
} }
@ -50,11 +75,11 @@ export const createActions = context => {
} }
// Small util to compare datasource definitions // Small util to compare datasource definitions
const isSameDatasource = (a, b) => { const isSameDatasource = (a: any, b: any) => {
return JSON.stringify(a) === JSON.stringify(b) return JSON.stringify(a) === JSON.stringify(b)
} }
export const initialise = context => { export const initialise = (context: StoreContext) => {
const { const {
datasource, datasource,
sort, sort,
@ -69,7 +94,7 @@ export const initialise = context => {
} = context } = context
// Keep a list of subscriptions so that we can clear them when the datasource // Keep a list of subscriptions so that we can clear them when the datasource
// config changes // config changes
let unsubscribers = [] let unsubscribers: any[] = []
// Observe datasource changes and apply logic for view V2 datasources // Observe datasource changes and apply logic for view V2 datasources
datasource.subscribe($datasource => { datasource.subscribe($datasource => {

View File

@ -58,7 +58,8 @@ export interface BaseStore {
export type Store = BaseStore & export type Store = BaseStore &
Columns.Store & Columns.Store &
Table.Store & Table.Store &
ViewV2.Store & { ViewV2.Store &
NonPlus.Store & {
// TODO while typing the rest of stores // TODO while typing the rest of stores
datasource: Writable<any> & { actions: any } datasource: Writable<any> & { actions: any }
definition: Writable<any> definition: Writable<any>