budibase/packages/frontend-core/src/fetch/QueryArrayFetch.ts

33 lines
897 B
TypeScript
Raw Normal View History

2025-01-08 14:27:13 +01:00
import FieldFetch from "./FieldFetch"
import {
getJSONArrayDatasourceSchema,
generateQueryArraySchemas,
} from "../utils/json"
2025-01-16 10:28:06 +01:00
import { QueryArrayFieldDatasource } from "@budibase/types"
2025-01-16 10:28:06 +01:00
export default class QueryArrayFetch extends FieldFetch<QueryArrayFieldDatasource> {
2025-01-08 14:27:13 +01:00
async getDefinition() {
const { datasource } = this.options
if (!datasource?.tableId) {
return null
}
// 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.fetchQueryDefinition(datasource.tableId)
const schema = generateQueryArraySchemas(
2025-01-08 13:48:45 +01:00
table.schema,
table.nestedSchemaFields
)
2025-01-08 13:48:45 +01:00
const result = {
schema: getJSONArrayDatasourceSchema(schema, datasource),
}
2025-01-07 13:08:17 +01:00
return result
} catch (error) {
return null
}
}
}