2022-01-20 10:40:53 +01:00
|
|
|
export const buildTableEndpoints = API => ({
|
|
|
|
/**
|
|
|
|
* Fetches a table definition.
|
|
|
|
* Since definitions cannot change at runtime, the result is cached.
|
|
|
|
*/
|
|
|
|
fetchTableDefinition: async tableId => {
|
|
|
|
return await API.get({
|
|
|
|
url: `/api/tables/${tableId}`,
|
|
|
|
cache: true,
|
|
|
|
})
|
|
|
|
},
|
2020-11-12 10:07:09 +01:00
|
|
|
|
2022-01-20 10:40:53 +01:00
|
|
|
/**
|
|
|
|
* Fetches all rows from a table.
|
|
|
|
*/
|
|
|
|
fetchTableData: async tableId => {
|
|
|
|
return await API.get({ url: `/api/${tableId}/rows` })
|
|
|
|
},
|
2021-05-26 18:38:49 +02:00
|
|
|
|
2022-01-20 10:40:53 +01:00
|
|
|
/**
|
|
|
|
* Searches a table using Lucene.
|
|
|
|
*/
|
|
|
|
searchTable: async ({
|
|
|
|
tableId,
|
|
|
|
query,
|
|
|
|
bookmark,
|
|
|
|
limit,
|
|
|
|
sort,
|
|
|
|
sortOrder,
|
|
|
|
sortType,
|
|
|
|
paginate,
|
|
|
|
}) => {
|
|
|
|
if (!tableId || !query) {
|
|
|
|
return {
|
|
|
|
rows: [],
|
|
|
|
}
|
2021-05-26 18:38:49 +02:00
|
|
|
}
|
2022-01-20 10:40:53 +01:00
|
|
|
return await API.post({
|
|
|
|
url: `/api/${tableId}/search`,
|
|
|
|
body: {
|
|
|
|
query,
|
|
|
|
bookmark,
|
|
|
|
limit,
|
|
|
|
sort,
|
|
|
|
sortOrder,
|
|
|
|
sortType,
|
|
|
|
paginate,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
},
|
2022-01-24 11:44:37 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Imports data into an existing table
|
|
|
|
* @param tableId the table ID to import to
|
|
|
|
* @param data the data import object
|
|
|
|
*/
|
|
|
|
importTableData: async ({ tableId, data }) => {
|
|
|
|
return await API.post({
|
|
|
|
url: `/api/tables/${tableId}/import`,
|
|
|
|
body: {
|
|
|
|
dataImport: data,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Validates a candidate CSV to be imported for a certain table.
|
|
|
|
* @param tableId the table ID to import to
|
|
|
|
* @param csvString the CSV contents as a string
|
|
|
|
* @param schema the proposed schema
|
|
|
|
*/
|
|
|
|
validateTableCSV: async ({ tableId, csvString, schema }) => {
|
|
|
|
return await API.post({
|
|
|
|
url: "/api/tables/csv/validate",
|
|
|
|
body: {
|
|
|
|
csvString,
|
|
|
|
schema,
|
|
|
|
tableId,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
},
|
2022-01-24 13:37:22 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets a list o tables.
|
|
|
|
*/
|
|
|
|
getTables: async () => {
|
|
|
|
return await API.get({
|
|
|
|
url: "/api/tables",
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Saves a table.
|
|
|
|
* @param table the table to save
|
|
|
|
*/
|
|
|
|
saveTable: async table => {
|
|
|
|
return await API.post({
|
|
|
|
url: "/api/tables",
|
|
|
|
body: table,
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Deletes a table.
|
|
|
|
* @param tableId the ID of the table to delete
|
|
|
|
* @param tableRev the rev of the table to delete
|
|
|
|
*/
|
|
|
|
deleteTable: async ({ tableId, tableRev }) => {
|
|
|
|
return await API.delete({
|
|
|
|
url: `/api/tables/${tableId}/${tableRev}`,
|
|
|
|
})
|
|
|
|
},
|
2022-01-20 10:40:53 +01:00
|
|
|
})
|