2025-01-07 13:08:17 +01:00
|
|
|
import FieldFetch, { FieldDatasource } from "./FieldFetch"
|
2024-02-19 10:13:03 +01:00
|
|
|
import {
|
|
|
|
getJSONArrayDatasourceSchema,
|
|
|
|
generateQueryArraySchemas,
|
|
|
|
} from "../utils/json"
|
|
|
|
|
|
|
|
export default class QueryArrayFetch extends FieldFetch {
|
2025-01-07 13:08:17 +01:00
|
|
|
async getDefinition(datasource: FieldDatasource) {
|
2024-02-19 10:13:03 +01:00
|
|
|
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(
|
|
|
|
table?.schema,
|
|
|
|
table?.nestedSchemaFields
|
|
|
|
)
|
2025-01-07 13:08:17 +01:00
|
|
|
const result: {
|
|
|
|
schema: Record<string, any> | null
|
|
|
|
} = { schema: getJSONArrayDatasourceSchema(schema, datasource) }
|
|
|
|
|
|
|
|
return result
|
2024-02-19 10:13:03 +01:00
|
|
|
} catch (error) {
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|