Automatically type getContext response

This commit is contained in:
Adria Navarro 2025-01-20 14:51:37 +01:00
parent fa930de15e
commit 0b73f53974
4 changed files with 14 additions and 10 deletions

View File

@ -14,7 +14,6 @@
GroupUserDatasource, GroupUserDatasource,
DataFetchOptions, DataFetchOptions,
} from "@budibase/types" } from "@budibase/types"
import { SDK, Component } from "../../index"
type ProviderDatasource = Exclude< type ProviderDatasource = Exclude<
DataFetchDatasource, DataFetchDatasource,
@ -29,8 +28,8 @@
export let paginate: boolean export let paginate: boolean
export let autoRefresh: number export let autoRefresh: number
const { styleable, Provider, ActionTypes, API } = getContext<SDK>("sdk") const { styleable, Provider, ActionTypes, API } = getContext("sdk")
const component = getContext<Component>("component") const component = getContext("component")
let interval: ReturnType<typeof setInterval> let interval: ReturnType<typeof setInterval>
let queryExtensions: Record<string, any> = {} let queryExtensions: Record<string, any> = {}

View File

@ -4,7 +4,6 @@
import { Utils } from "@budibase/frontend-core" import { Utils } from "@budibase/frontend-core"
import FormBlockWrapper from "./FormBlockWrapper.svelte" import FormBlockWrapper from "./FormBlockWrapper.svelte"
import { get } from "svelte/store" import { get } from "svelte/store"
import { Component, Context, SDK } from "../../../../index"
import { TableSchema, UIDatasource } from "@budibase/types" import { TableSchema, UIDatasource } from "@budibase/types"
type Field = { name: string; active: boolean } type Field = { name: string; active: boolean }
@ -34,9 +33,9 @@
export let saveButtonLabel: boolean export let saveButtonLabel: boolean
export let deleteButtonLabel: boolean export let deleteButtonLabel: boolean
const { fetchDatasourceSchema, generateGoldenSample } = getContext<SDK>("sdk") const { fetchDatasourceSchema, generateGoldenSample } = getContext("sdk")
const component = getContext<Component>("component") const component = getContext("component")
const context = getContext<Context>("context") const context = getContext("context")
let schema: TableSchema let schema: TableSchema

View File

@ -3,15 +3,14 @@
import { Icon } from "@budibase/bbui" import { Icon } from "@budibase/bbui"
import MissingRequiredSetting from "./MissingRequiredSetting.svelte" import MissingRequiredSetting from "./MissingRequiredSetting.svelte"
import MissingRequiredAncestor from "./MissingRequiredAncestor.svelte" import MissingRequiredAncestor from "./MissingRequiredAncestor.svelte"
import { Component, SDK } from "../../index"
export let missingRequiredSettings: export let missingRequiredSettings:
| { key: string; label: string }[] | { key: string; label: string }[]
| undefined | undefined
export let missingRequiredAncestors: string[] | undefined export let missingRequiredAncestors: string[] | undefined
const component = getContext<Component>("component") const component = getContext("component")
const { styleable, builderStore } = getContext<SDK>("sdk") const { styleable, builderStore } = getContext("sdk")
$: styles = { ...$component.styles, normal: {}, custom: null, empty: true } $: styles = { ...$component.styles, normal: {}, custom: null, empty: true }
$: requiredSetting = missingRequiredSettings?.[0] $: requiredSetting = missingRequiredSettings?.[0]

7
packages/client/src/context.d.ts vendored Normal file
View File

@ -0,0 +1,7 @@
import { Component, Context, SDK } from "."
declare module "svelte" {
function getContext(name: "sdk"): SDK
function getContext(name: "component"): Component
function getContext(name: "context"): Context
}