Type jsonArrayFetch
This commit is contained in:
parent
89485aa9d1
commit
364e997fc2
|
@ -5,7 +5,7 @@ import QueryFetch from "@budibase/frontend-core/src/fetch/QueryFetch"
|
|||
import RelationshipFetch from "@budibase/frontend-core/src/fetch/RelationshipFetch"
|
||||
import NestedProviderFetch from "@budibase/frontend-core/src/fetch/NestedProviderFetch.js"
|
||||
import FieldFetch from "@budibase/frontend-core/src/fetch/FieldFetch"
|
||||
import JSONArrayFetch from "@budibase/frontend-core/src/fetch/JSONArrayFetch.js"
|
||||
import JSONArrayFetch from "@budibase/frontend-core/src/fetch/JSONArrayFetch"
|
||||
import ViewV2Fetch from "@budibase/frontend-core/src/fetch/ViewV2Fetch"
|
||||
import QueryArrayFetch from "@budibase/frontend-core/src/fetch/QueryArrayFetch"
|
||||
|
||||
|
|
|
@ -7,13 +7,17 @@ export interface FieldDatasource {
|
|||
value: string[] | Row[]
|
||||
}
|
||||
|
||||
export interface FieldDefinition {
|
||||
schema?: Record<string, { type: string }> | null
|
||||
}
|
||||
|
||||
function isArrayOfStrings(value: string[] | Row[]): value is string[] {
|
||||
return Array.isArray(value) && !!value[0] && typeof value[0] !== "object"
|
||||
}
|
||||
|
||||
export default class FieldFetch extends DataFetch<
|
||||
FieldDatasource,
|
||||
{ schema?: Record<string, { type: string }> }
|
||||
FieldDefinition
|
||||
> {
|
||||
getSchema(
|
||||
_datasource: FieldDatasource,
|
||||
|
@ -22,9 +26,11 @@ export default class FieldFetch extends DataFetch<
|
|||
return definition?.schema
|
||||
}
|
||||
|
||||
async getDefinition(datasource: FieldDatasource) {
|
||||
async getDefinition(
|
||||
datasource: FieldDatasource
|
||||
): Promise<FieldDefinition | null> {
|
||||
// Field sources have their schema statically defined
|
||||
let schema: Record<string, { type: string }> | undefined
|
||||
let schema
|
||||
if (datasource.fieldType === "attachment") {
|
||||
schema = {
|
||||
url: {
|
||||
|
|
|
@ -1,13 +1,16 @@
|
|||
import FieldFetch from "./FieldFetch"
|
||||
import FieldFetch, { FieldDatasource } from "./FieldFetch"
|
||||
import { getJSONArrayDatasourceSchema } from "../utils/json"
|
||||
|
||||
export default class JSONArrayFetch extends FieldFetch {
|
||||
async getDefinition(datasource) {
|
||||
async getDefinition(datasource: FieldDatasource) {
|
||||
// JSON arrays need their table definitions fetched.
|
||||
// We can then extract their schema as a subset of the table schema.
|
||||
try {
|
||||
const table = await this.API.fetchTableDefinition(datasource.tableId)
|
||||
const schema = getJSONArrayDatasourceSchema(table?.schema, datasource)
|
||||
const schema: Record<string, any> | null = getJSONArrayDatasourceSchema(
|
||||
table?.schema,
|
||||
datasource
|
||||
)
|
||||
return { schema }
|
||||
} catch (error) {
|
||||
return null
|
|
@ -5,7 +5,7 @@ import QueryFetch from "./QueryFetch"
|
|||
import RelationshipFetch from "./RelationshipFetch"
|
||||
import NestedProviderFetch from "./NestedProviderFetch.js"
|
||||
import FieldFetch from "./FieldFetch"
|
||||
import JSONArrayFetch from "./JSONArrayFetch.js"
|
||||
import JSONArrayFetch from "./JSONArrayFetch"
|
||||
import UserFetch from "./UserFetch.js"
|
||||
import GroupUserFetch from "./GroupUserFetch"
|
||||
import CustomFetch from "./CustomFetch.js"
|
||||
|
|
Loading…
Reference in New Issue