Dry
This commit is contained in:
parent
dcf52b5dc9
commit
ed2e35dea0
|
@ -71,7 +71,7 @@ export const deriveStores = (context: StoreContext): DerivedDatasourceStore => {
|
|||
} = context
|
||||
|
||||
const schema = derived(definition, $definition => {
|
||||
let schema: Record<string, UIFieldSchema> = getDatasourceSchema({
|
||||
const schema: Record<string, any> | null | undefined = getDatasourceSchema({
|
||||
API,
|
||||
datasource: get(datasource),
|
||||
definition: $definition ?? undefined,
|
||||
|
@ -82,7 +82,7 @@ export const deriveStores = (context: StoreContext): DerivedDatasourceStore => {
|
|||
|
||||
// Ensure schema is configured as objects.
|
||||
// Certain datasources like queries use primitives.
|
||||
Object.keys(schema || {}).forEach(key => {
|
||||
Object.keys(schema).forEach(key => {
|
||||
if (typeof schema[key] !== "object") {
|
||||
schema[key] = { name: key, type: schema[key] }
|
||||
}
|
||||
|
|
|
@ -1,10 +1,6 @@
|
|||
import DataFetch from "./DataFetch"
|
||||
|
||||
export default class CustomFetch extends DataFetch<any, any> {
|
||||
getSchema(_datasource: any, definition: any) {
|
||||
return definition?.schema
|
||||
}
|
||||
|
||||
// Gets the correct Budibase type for a JS value
|
||||
getType(value: any) {
|
||||
if (value == null) {
|
||||
|
|
|
@ -60,7 +60,10 @@ export interface DataFetchParams<
|
|||
*/
|
||||
export default abstract class DataFetch<
|
||||
TDatasource extends {},
|
||||
TDefinition extends {},
|
||||
TDefinition extends {
|
||||
schema?: Record<string, any> | null
|
||||
primaryDisplay?: string
|
||||
},
|
||||
TQuery extends {} = SearchFilters
|
||||
> {
|
||||
API: APIClient
|
||||
|
@ -361,10 +364,9 @@ export default abstract class DataFetch<
|
|||
* @param definition the datasource definition
|
||||
* @return {object} the schema
|
||||
*/
|
||||
abstract getSchema(
|
||||
datasource: TDatasource | null,
|
||||
definition: TDefinition | null
|
||||
): any
|
||||
getSchema(_datasource: TDatasource | null, definition: TDefinition | null) {
|
||||
return definition?.schema
|
||||
}
|
||||
|
||||
/**
|
||||
* Enriches a datasource schema with nested fields and ensures the structure
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { Row, TableSchema } from "@budibase/types"
|
||||
import { Row } from "@budibase/types"
|
||||
import DataFetch from "./DataFetch"
|
||||
|
||||
export interface FieldDatasource {
|
||||
|
@ -19,13 +19,6 @@ export default class FieldFetch extends DataFetch<
|
|||
FieldDatasource,
|
||||
FieldDefinition
|
||||
> {
|
||||
getSchema(
|
||||
_datasource: FieldDatasource,
|
||||
definition: { schema?: TableSchema }
|
||||
) {
|
||||
return definition?.schema
|
||||
}
|
||||
|
||||
async getDefinition(
|
||||
datasource: FieldDatasource
|
||||
): Promise<FieldDefinition | null> {
|
||||
|
|
|
@ -26,10 +26,6 @@ export default class GroupUserFetch extends DataFetch<
|
|||
})
|
||||
}
|
||||
|
||||
getSchema(_datasource: any, definition: any) {
|
||||
return definition?.schema
|
||||
}
|
||||
|
||||
determineFeatureFlags() {
|
||||
return {
|
||||
supportsSearch: true,
|
||||
|
|
|
@ -1,10 +1,6 @@
|
|||
import DataFetch from "./DataFetch"
|
||||
|
||||
export default class NestedProviderFetch extends DataFetch<any, any> {
|
||||
getSchema(_datasource: any, definition: any) {
|
||||
return definition?.schema
|
||||
}
|
||||
|
||||
async getDefinition(datasource: any) {
|
||||
// Nested providers should already have exposed their own schema
|
||||
return {
|
||||
|
|
|
@ -11,10 +11,6 @@ interface QueryDatasource {
|
|||
}
|
||||
|
||||
export default class QueryFetch extends DataFetch<QueryDatasource, Query> {
|
||||
getSchema(_datasource: any, definition: any) {
|
||||
return definition?.schema
|
||||
}
|
||||
|
||||
determineFeatureFlags(definition: Query) {
|
||||
const supportsPagination =
|
||||
!!definition?.fields?.pagination?.type &&
|
||||
|
|
|
@ -12,10 +12,6 @@ export default class RelationshipFetch extends DataFetch<
|
|||
RelationshipDatasource,
|
||||
Table
|
||||
> {
|
||||
getSchema(_datasource: any, definition: any) {
|
||||
return definition?.schema
|
||||
}
|
||||
|
||||
async getDefinition(datasource: RelationshipDatasource) {
|
||||
if (!datasource?.tableId) {
|
||||
return null
|
||||
|
|
|
@ -26,10 +26,6 @@ export default class TableFetch extends DataFetch<UITable, Table> {
|
|||
}
|
||||
}
|
||||
|
||||
getSchema(_datasource: UITable | null, definition: Table | null) {
|
||||
return definition?.schema
|
||||
}
|
||||
|
||||
async getData() {
|
||||
const { datasource, limit, sortColumn, sortOrder, sortType, paginate } =
|
||||
this.options
|
||||
|
|
|
@ -48,10 +48,6 @@ export default class UserFetch extends DataFetch<
|
|||
}
|
||||
}
|
||||
|
||||
getSchema(_datasource: any, definition: Table | null) {
|
||||
return definition?.schema
|
||||
}
|
||||
|
||||
async getData() {
|
||||
const { limit, paginate } = this.options
|
||||
const { cursor, query } = get(this.store)
|
||||
|
|
|
@ -12,10 +12,6 @@ export default class ViewV2Fetch extends DataFetch<UIView, ViewV2> {
|
|||
}
|
||||
}
|
||||
|
||||
getSchema(_datasource: UIView, definition: ViewV2) {
|
||||
return definition?.schema
|
||||
}
|
||||
|
||||
async getDefinition(datasource: UIView | null): Promise<ViewV2 | null> {
|
||||
if (!datasource?.id) {
|
||||
return null
|
||||
|
|
Loading…
Reference in New Issue