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