Update types
This commit is contained in:
parent
19c32299b1
commit
482f8aa820
|
@ -1,14 +1,7 @@
|
|||
<script lang="ts">
|
||||
import { getContext } from "svelte"
|
||||
import { Pagination, ProgressCircle } from "@budibase/bbui"
|
||||
import {
|
||||
fetchData,
|
||||
QueryUtils,
|
||||
DataFetchOptions,
|
||||
DataFetchDatasource,
|
||||
UserDatasource,
|
||||
GroupUserDatasource,
|
||||
} from "@budibase/frontend-core"
|
||||
import { fetchData, QueryUtils } from "@budibase/frontend-core"
|
||||
import {
|
||||
LogicalOperator,
|
||||
EmptyFilterOption,
|
||||
|
@ -16,6 +9,10 @@
|
|||
SortOrder,
|
||||
SearchFilters,
|
||||
UISearchFilter,
|
||||
DataFetchDatasource,
|
||||
UserDatasource,
|
||||
GroupUserDatasource,
|
||||
DataFetchOptions,
|
||||
} from "@budibase/types"
|
||||
import { SDK, Component } from "../../index"
|
||||
|
||||
|
@ -76,7 +73,7 @@
|
|||
column: string
|
||||
order: SortOrder | undefined
|
||||
}) => {
|
||||
let newOptions: Partial<DataFetchOptions<never>> = {}
|
||||
let newOptions: Partial<DataFetchOptions> = {}
|
||||
if (column) {
|
||||
newOptions.sortColumn = column
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ import {
|
|||
import { get } from "svelte/store"
|
||||
import { Store as StoreContext } from ".."
|
||||
import { DatasourceTableActions } from "."
|
||||
import { TableFetch } from "@budibase/frontend-core"
|
||||
import TableFetch from "../../../../fetch/TableFetch"
|
||||
|
||||
const SuppressErrors = true
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ import {
|
|||
} from "@budibase/types"
|
||||
import { Store as StoreContext } from ".."
|
||||
import { DatasourceViewActions } from "."
|
||||
import { ViewV2Fetch } from "@budibase/frontend-core"
|
||||
import ViewV2Fetch from "../../../../fetch/ViewV2Fetch"
|
||||
|
||||
const SuppressErrors = true
|
||||
|
||||
|
|
|
@ -1,10 +1,6 @@
|
|||
import { CustomDatasource } from "@budibase/types"
|
||||
import BaseDataFetch from "./DataFetch"
|
||||
|
||||
export interface CustomDatasource {
|
||||
type: "custom"
|
||||
data: any
|
||||
}
|
||||
|
||||
type CustomDefinition = Record<string, any>
|
||||
|
||||
export default class CustomFetch extends BaseDataFetch<
|
||||
|
|
|
@ -3,14 +3,13 @@ import { cloneDeep } from "lodash/fp"
|
|||
import { QueryUtils } from "../utils"
|
||||
import { convertJSONSchemaToTableSchema } from "../utils/json"
|
||||
import {
|
||||
DataFetchOptions,
|
||||
FieldType,
|
||||
LegacyFilter,
|
||||
Row,
|
||||
SearchFilters,
|
||||
SortOrder,
|
||||
SortType,
|
||||
TableSchema,
|
||||
UISearchFilter,
|
||||
} from "@budibase/types"
|
||||
import { APIClient } from "../api/types"
|
||||
import { DataFetchType } from "."
|
||||
|
@ -51,18 +50,6 @@ export interface DataFetchParams<TDatasource, TQuery = SearchFilters> {
|
|||
options?: Partial<DataFetchOptions<TQuery>>
|
||||
}
|
||||
|
||||
export interface DataFetchOptions<TQuery = SearchFilters> {
|
||||
// Search config
|
||||
filter: UISearchFilter | LegacyFilter[] | null
|
||||
query: TQuery
|
||||
// Sorting config
|
||||
sortColumn: string | null
|
||||
sortOrder: SortOrder
|
||||
// Pagination config
|
||||
limit: number
|
||||
paginate: boolean
|
||||
}
|
||||
|
||||
/**
|
||||
* Parent class which handles the implementation of fetching data from an
|
||||
* internal table or datasource plus.
|
||||
|
|
|
@ -1,15 +1,11 @@
|
|||
import { Row } from "@budibase/types"
|
||||
import {
|
||||
FieldDatasource,
|
||||
JSONArrayFieldDatasource,
|
||||
QueryArrayFieldDatasource,
|
||||
Row,
|
||||
} from "@budibase/types"
|
||||
import BaseDataFetch from "./DataFetch"
|
||||
|
||||
type Types = "field" | "queryarray" | "jsonarray"
|
||||
|
||||
export interface FieldDatasource<TType extends Types> {
|
||||
type: TType
|
||||
tableId: string
|
||||
fieldType: "attachment" | "array"
|
||||
value: string[] | Row[]
|
||||
}
|
||||
|
||||
export interface FieldDefinition {
|
||||
schema?: Record<string, { type: string }> | null
|
||||
}
|
||||
|
@ -18,10 +14,12 @@ function isArrayOfStrings(value: string[] | Row[]): value is string[] {
|
|||
return Array.isArray(value) && !!value[0] && typeof value[0] !== "object"
|
||||
}
|
||||
|
||||
export default class FieldFetch<TType extends Types> extends BaseDataFetch<
|
||||
FieldDatasource<TType>,
|
||||
FieldDefinition
|
||||
> {
|
||||
export default class FieldFetch<
|
||||
TDatasource extends
|
||||
| FieldDatasource
|
||||
| QueryArrayFieldDatasource
|
||||
| JSONArrayFieldDatasource = FieldDatasource
|
||||
> extends BaseDataFetch<TDatasource, FieldDefinition> {
|
||||
async getDefinition(): Promise<FieldDefinition | null> {
|
||||
const { datasource } = this.options
|
||||
|
||||
|
|
|
@ -1,17 +1,12 @@
|
|||
import { get } from "svelte/store"
|
||||
import BaseDataFetch, { DataFetchParams } from "./DataFetch"
|
||||
import { TableNames } from "../constants"
|
||||
import { GroupUserDatasource, InternalTable } from "@budibase/types"
|
||||
|
||||
interface GroupUserQuery {
|
||||
groupId: string
|
||||
emailSearch: string
|
||||
}
|
||||
|
||||
export interface GroupUserDatasource {
|
||||
type: "groupUser"
|
||||
tableId: TableNames.USERS
|
||||
}
|
||||
|
||||
interface GroupUserDefinition {
|
||||
schema?: Record<string, any> | null
|
||||
primaryDisplay?: string
|
||||
|
@ -27,7 +22,7 @@ export default class GroupUserFetch extends BaseDataFetch<
|
|||
...opts,
|
||||
datasource: {
|
||||
type: "groupUser",
|
||||
tableId: TableNames.USERS,
|
||||
tableId: InternalTable.USER_METADATA,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
import FieldFetch from "./FieldFetch"
|
||||
import { getJSONArrayDatasourceSchema } from "../utils/json"
|
||||
import { JSONArrayFieldDatasource } from "@budibase/types"
|
||||
|
||||
export default class JSONArrayFetch extends FieldFetch<"jsonarray"> {
|
||||
export default class JSONArrayFetch extends FieldFetch<JSONArrayFieldDatasource> {
|
||||
async getDefinition() {
|
||||
const { datasource } = this.options
|
||||
|
||||
|
|
|
@ -1,15 +1,6 @@
|
|||
import { Row, TableSchema } from "@budibase/types"
|
||||
import { NestedProviderDatasource, TableSchema } from "@budibase/types"
|
||||
import BaseDataFetch from "./DataFetch"
|
||||
|
||||
export interface NestedProviderDatasource {
|
||||
type: "provider"
|
||||
value?: {
|
||||
schema: TableSchema
|
||||
primaryDisplay: string
|
||||
rows: Row[]
|
||||
}
|
||||
}
|
||||
|
||||
interface NestedProviderDefinition {
|
||||
schema?: TableSchema
|
||||
primaryDisplay?: string
|
||||
|
|
|
@ -3,8 +3,9 @@ import {
|
|||
getJSONArrayDatasourceSchema,
|
||||
generateQueryArraySchemas,
|
||||
} from "../utils/json"
|
||||
import { QueryArrayFieldDatasource } from "@budibase/types"
|
||||
|
||||
export default class QueryArrayFetch extends FieldFetch<"queryarray"> {
|
||||
export default class QueryArrayFetch extends FieldFetch<QueryArrayFieldDatasource> {
|
||||
async getDefinition() {
|
||||
const { datasource } = this.options
|
||||
|
||||
|
|
|
@ -1,22 +1,8 @@
|
|||
import BaseDataFetch from "./DataFetch"
|
||||
import { Helpers } from "@budibase/bbui"
|
||||
import { ExecuteQueryRequest, Query } from "@budibase/types"
|
||||
import { ExecuteQueryRequest, Query, QueryDatasource } from "@budibase/types"
|
||||
import { get } from "svelte/store"
|
||||
|
||||
export interface QueryDatasource {
|
||||
type: "query"
|
||||
_id: string
|
||||
fields: Record<string, any> & {
|
||||
pagination?: {
|
||||
type: string
|
||||
location: string
|
||||
pageParam: string
|
||||
}
|
||||
}
|
||||
queryParams?: Record<string, string>
|
||||
parameters: { name: string; default: string }[]
|
||||
}
|
||||
|
||||
export default class QueryFetch extends BaseDataFetch<QueryDatasource, Query> {
|
||||
async determineFeatureFlags() {
|
||||
const definition = await this.getDefinition()
|
||||
|
|
|
@ -1,14 +1,6 @@
|
|||
import { Table } from "@budibase/types"
|
||||
import { RelationshipDatasource, Table } from "@budibase/types"
|
||||
import BaseDataFetch from "./DataFetch"
|
||||
|
||||
export interface RelationshipDatasource {
|
||||
type: "link"
|
||||
tableId: string
|
||||
rowId: string
|
||||
rowTableId: string
|
||||
fieldName: string
|
||||
}
|
||||
|
||||
export default class RelationshipFetch extends BaseDataFetch<
|
||||
RelationshipDatasource,
|
||||
Table
|
||||
|
|
|
@ -1,11 +1,6 @@
|
|||
import { get } from "svelte/store"
|
||||
import BaseDataFetch from "./DataFetch"
|
||||
import { SortOrder, Table } from "@budibase/types"
|
||||
|
||||
export interface TableDatasource {
|
||||
type: "table"
|
||||
tableId: string
|
||||
}
|
||||
import { SortOrder, Table, TableDatasource } from "@budibase/types"
|
||||
|
||||
export default class TableFetch extends BaseDataFetch<TableDatasource, Table> {
|
||||
async determineFeatureFlags() {
|
||||
|
|
|
@ -1,19 +1,18 @@
|
|||
import { get } from "svelte/store"
|
||||
import BaseDataFetch, { DataFetchParams } from "./DataFetch"
|
||||
import { TableNames } from "../constants"
|
||||
import { utils } from "@budibase/shared-core"
|
||||
import { SearchFilters, SearchUsersRequest } from "@budibase/types"
|
||||
import {
|
||||
InternalTable,
|
||||
SearchFilters,
|
||||
SearchUsersRequest,
|
||||
UserDatasource,
|
||||
} from "@budibase/types"
|
||||
|
||||
interface UserFetchQuery {
|
||||
appId: string
|
||||
paginated: boolean
|
||||
}
|
||||
|
||||
export interface UserDatasource {
|
||||
type: "user"
|
||||
tableId: TableNames.USERS
|
||||
}
|
||||
|
||||
interface UserDefinition {
|
||||
schema?: Record<string, any> | null
|
||||
primaryDisplay?: string
|
||||
|
@ -29,7 +28,7 @@ export default class UserFetch extends BaseDataFetch<
|
|||
...opts,
|
||||
datasource: {
|
||||
type: "user",
|
||||
tableId: TableNames.USERS,
|
||||
tableId: InternalTable.USER_METADATA,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
|
|
@ -1,15 +1,6 @@
|
|||
import { Table } from "@budibase/types"
|
||||
import { Table, ViewV1Datasource } from "@budibase/types"
|
||||
import BaseDataFetch from "./DataFetch"
|
||||
|
||||
export type ViewV1Datasource = {
|
||||
type: "view"
|
||||
name: string
|
||||
tableId: string
|
||||
calculation: string
|
||||
field: string
|
||||
groupBy: string
|
||||
}
|
||||
|
||||
export default class ViewFetch extends BaseDataFetch<ViewV1Datasource, Table> {
|
||||
async getDefinition() {
|
||||
const { datasource } = this.options
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
import { SortOrder, ViewV2Enriched, ViewV2Type } from "@budibase/types"
|
||||
import {
|
||||
SortOrder,
|
||||
ViewDatasource,
|
||||
ViewV2Enriched,
|
||||
ViewV2Type,
|
||||
} from "@budibase/types"
|
||||
import BaseDataFetch from "./DataFetch"
|
||||
import { get } from "svelte/store"
|
||||
import { helpers } from "@budibase/shared-core"
|
||||
|
||||
export interface ViewDatasource {
|
||||
type: "viewV2"
|
||||
id: string
|
||||
}
|
||||
|
||||
export default class ViewV2Fetch extends BaseDataFetch<
|
||||
ViewDatasource,
|
||||
ViewV2Enriched
|
||||
|
|
|
@ -1,30 +1,20 @@
|
|||
import TableFetch, { TableDatasource } from "./TableFetch"
|
||||
import ViewFetch, { ViewV1Datasource } from "./ViewFetch"
|
||||
import ViewV2Fetch, { ViewDatasource } from "./ViewV2Fetch"
|
||||
import QueryFetch, { QueryDatasource } from "./QueryFetch"
|
||||
import RelationshipFetch, { RelationshipDatasource } from "./RelationshipFetch"
|
||||
import NestedProviderFetch, {
|
||||
NestedProviderDatasource,
|
||||
} from "./NestedProviderFetch"
|
||||
import FieldFetch, { FieldDatasource } from "./FieldFetch"
|
||||
import TableFetch from "./TableFetch"
|
||||
import ViewFetch from "./ViewFetch"
|
||||
import ViewV2Fetch from "./ViewV2Fetch"
|
||||
import QueryFetch from "./QueryFetch"
|
||||
import RelationshipFetch from "./RelationshipFetch"
|
||||
import NestedProviderFetch from "./NestedProviderFetch"
|
||||
import FieldFetch from "./FieldFetch"
|
||||
import JSONArrayFetch from "./JSONArrayFetch"
|
||||
import UserFetch, { UserDatasource } from "./UserFetch"
|
||||
import GroupUserFetch, { GroupUserDatasource } from "./GroupUserFetch"
|
||||
import CustomFetch, { CustomDatasource } from "./CustomFetch"
|
||||
import UserFetch from "./UserFetch"
|
||||
import GroupUserFetch from "./GroupUserFetch"
|
||||
import CustomFetch from "./CustomFetch"
|
||||
import QueryArrayFetch from "./QueryArrayFetch"
|
||||
import { APIClient } from "../api/types"
|
||||
import { Table, ViewV2Enriched } from "@budibase/types"
|
||||
import { DataFetchDatasource, Table, ViewV2Enriched } from "@budibase/types"
|
||||
|
||||
export type DataFetchType = keyof typeof DataFetchMap
|
||||
|
||||
export type { default as TableFetch } from "./TableFetch"
|
||||
export type { default as ViewFetch } from "./ViewFetch"
|
||||
export type { default as ViewV2Fetch } from "./ViewV2Fetch"
|
||||
|
||||
export type { DataFetchOptions } from "./DataFetch"
|
||||
export type { UserDatasource } from "./UserFetch"
|
||||
export type { GroupUserDatasource } from "./GroupUserFetch"
|
||||
|
||||
export const DataFetchMap = {
|
||||
table: TableFetch,
|
||||
view: ViewFetch,
|
||||
|
@ -37,7 +27,7 @@ export const DataFetchMap = {
|
|||
|
||||
// Client specific datasource types
|
||||
provider: NestedProviderFetch,
|
||||
field: FieldFetch<"field">,
|
||||
field: FieldFetch,
|
||||
jsonarray: JSONArrayFetch,
|
||||
queryarray: QueryArrayFetch,
|
||||
}
|
||||
|
@ -54,7 +44,7 @@ export interface DataFetchClassMap {
|
|||
|
||||
// Client specific datasource types
|
||||
provider: NestedProviderFetch
|
||||
field: FieldFetch<"field">
|
||||
field: FieldFetch
|
||||
jsonarray: JSONArrayFetch
|
||||
queryarray: QueryArrayFetch
|
||||
}
|
||||
|
@ -69,22 +59,10 @@ export type DataFetch =
|
|||
| GroupUserFetch
|
||||
| CustomFetch
|
||||
| NestedProviderFetch
|
||||
| FieldFetch<"field">
|
||||
| FieldFetch
|
||||
| JSONArrayFetch
|
||||
| QueryArrayFetch
|
||||
|
||||
export type DataFetchDatasource =
|
||||
| TableDatasource
|
||||
| ViewV1Datasource
|
||||
| ViewDatasource
|
||||
| QueryDatasource
|
||||
| RelationshipDatasource
|
||||
| UserDatasource
|
||||
| GroupUserDatasource
|
||||
| CustomDatasource
|
||||
| NestedProviderDatasource
|
||||
| FieldDatasource<"field" | "queryarray" | "jsonarray">
|
||||
|
||||
export type DataFetchDefinition =
|
||||
| Table
|
||||
| ViewV2Enriched
|
||||
|
|
|
@ -1,16 +1,6 @@
|
|||
export { createAPIClient } from "./api"
|
||||
export type { APIClient } from "./api"
|
||||
export { fetchData, DataFetchMap } from "./fetch"
|
||||
export type {
|
||||
DataFetchType,
|
||||
TableFetch,
|
||||
ViewFetch,
|
||||
ViewV2Fetch,
|
||||
DataFetchOptions,
|
||||
DataFetchDatasource,
|
||||
UserDatasource,
|
||||
GroupUserDatasource,
|
||||
} from "./fetch"
|
||||
export * as Constants from "./constants"
|
||||
export * from "./stores"
|
||||
export * from "./utils"
|
||||
|
|
|
@ -0,0 +1,93 @@
|
|||
import { InternalTable, Row, TableSchema } from "../../documents"
|
||||
|
||||
export type DataFetchDatasource =
|
||||
| TableDatasource
|
||||
| ViewV1Datasource
|
||||
| ViewDatasource
|
||||
| QueryDatasource
|
||||
| RelationshipDatasource
|
||||
| UserDatasource
|
||||
| GroupUserDatasource
|
||||
| CustomDatasource
|
||||
| NestedProviderDatasource
|
||||
| FieldDatasource
|
||||
| QueryArrayFieldDatasource
|
||||
| JSONArrayFieldDatasource
|
||||
|
||||
export interface TableDatasource {
|
||||
type: "table"
|
||||
tableId: string
|
||||
}
|
||||
|
||||
export type ViewV1Datasource = {
|
||||
type: "view"
|
||||
name: string
|
||||
tableId: string
|
||||
calculation: string
|
||||
field: string
|
||||
groupBy: string
|
||||
}
|
||||
|
||||
export interface ViewDatasource {
|
||||
type: "viewV2"
|
||||
id: string
|
||||
}
|
||||
|
||||
export interface QueryDatasource {
|
||||
type: "query"
|
||||
_id: string
|
||||
fields: Record<string, any> & {
|
||||
pagination?: {
|
||||
type: string
|
||||
location: string
|
||||
pageParam: string
|
||||
}
|
||||
}
|
||||
queryParams?: Record<string, string>
|
||||
parameters: { name: string; default: string }[]
|
||||
}
|
||||
|
||||
export interface RelationshipDatasource {
|
||||
type: "link"
|
||||
tableId: string
|
||||
rowId: string
|
||||
rowTableId: string
|
||||
fieldName: string
|
||||
}
|
||||
|
||||
export interface UserDatasource {
|
||||
type: "user"
|
||||
tableId: InternalTable.USER_METADATA
|
||||
}
|
||||
|
||||
export interface GroupUserDatasource {
|
||||
type: "groupUser"
|
||||
tableId: InternalTable.USER_METADATA
|
||||
}
|
||||
|
||||
export interface CustomDatasource {
|
||||
type: "custom"
|
||||
data: any
|
||||
}
|
||||
|
||||
export interface NestedProviderDatasource {
|
||||
type: "provider"
|
||||
value?: {
|
||||
schema: TableSchema
|
||||
primaryDisplay: string
|
||||
rows: Row[]
|
||||
}
|
||||
}
|
||||
|
||||
interface BaseFieldDatasource<
|
||||
TType extends "field" | "queryarray" | "jsonarray"
|
||||
> {
|
||||
type: TType
|
||||
tableId: string
|
||||
fieldType: "attachment" | "array"
|
||||
value: string[] | Row[]
|
||||
}
|
||||
|
||||
export type FieldDatasource = BaseFieldDatasource<"field">
|
||||
export type QueryArrayFieldDatasource = BaseFieldDatasource<"queryarray">
|
||||
export type JSONArrayFieldDatasource = BaseFieldDatasource<"jsonarray">
|
|
@ -0,0 +1,16 @@
|
|||
import { LegacyFilter, SortOrder, UISearchFilter } from "../../api"
|
||||
import { SearchFilters } from "../../sdk"
|
||||
|
||||
export * from "./datasources"
|
||||
|
||||
export interface DataFetchOptions<TQuery = SearchFilters> {
|
||||
// Search config
|
||||
filter: UISearchFilter | LegacyFilter[] | null
|
||||
query: TQuery
|
||||
// Sorting config
|
||||
sortColumn: string | null
|
||||
sortOrder: SortOrder
|
||||
// Pagination config
|
||||
limit: number
|
||||
paginate: boolean
|
||||
}
|
|
@ -1 +1,2 @@
|
|||
export * from "./stores"
|
||||
export * from "./dataFetch"
|
||||
|
|
Loading…
Reference in New Issue