From cfa02f88f6f05b2786e5b36404df7f221c1b5436 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Tue, 25 Jan 2022 16:54:55 +0000 Subject: [PATCH] Add missing API client documentation and fix S3 upload endpoints to make them consistent --- .../src/components/app/forms/S3Upload.svelte | 7 ++++++- packages/frontend-core/src/api/app.js | 1 + packages/frontend-core/src/api/attachments.js | 17 ++++++++++++----- packages/frontend-core/src/api/automations.js | 2 ++ packages/frontend-core/src/api/relationships.js | 3 +++ packages/frontend-core/src/api/routes.js | 3 +++ packages/frontend-core/src/api/rows.js | 8 +++++++- packages/frontend-core/src/api/tables.js | 10 ++++++++++ 8 files changed, 44 insertions(+), 7 deletions(-) diff --git a/packages/client/src/components/app/forms/S3Upload.svelte b/packages/client/src/components/app/forms/S3Upload.svelte index c35fd7f194..ab66755b6e 100644 --- a/packages/client/src/components/app/forms/S3Upload.svelte +++ b/packages/client/src/components/app/forms/S3Upload.svelte @@ -71,7 +71,12 @@ const upload = async () => { loading = true try { - const res = await API.externalUpload(datasourceId, bucket, key, data) + const res = await API.externalUpload({ + datasourceId, + bucket, + key, + data, + }) notificationStore.actions.success("File uploaded successfully") loading = false return res diff --git a/packages/frontend-core/src/api/app.js b/packages/frontend-core/src/api/app.js index f6f141ab80..897e735ea1 100644 --- a/packages/frontend-core/src/api/app.js +++ b/packages/frontend-core/src/api/app.js @@ -1,6 +1,7 @@ export const buildAppEndpoints = API => ({ /** * Fetches screen definition for an app. + * @param appId the ID of the app to fetch from */ fetchAppPackage: async appId => { return await API.get({ diff --git a/packages/frontend-core/src/api/attachments.js b/packages/frontend-core/src/api/attachments.js index f6bad39c04..2077c4f7ef 100644 --- a/packages/frontend-core/src/api/attachments.js +++ b/packages/frontend-core/src/api/attachments.js @@ -26,8 +26,11 @@ export const buildAttachmentEndpoints = API => ({ /** * Generates a signed URL to upload a file to an external datasource. + * @param datasourceId the ID of the datasource to upload to + * @param bucket the name of the bucket to upload to + * @param key the name of the file to upload to */ - getSignedDatasourceURL: async (datasourceId, bucket, key) => { + getSignedDatasourceURL: async ({ datasourceId, bucket, key }) => { return await API.post({ url: `/api/attachments/${datasourceId}/url`, body: { bucket, key }, @@ -36,13 +39,17 @@ export const buildAttachmentEndpoints = API => ({ /** * Uploads a file to an external datasource. + * @param datasourceId the ID of the datasource to upload to + * @param bucket the name of the bucket to upload to + * @param key the name of the file to upload to + * @param data the file to upload */ - externalUpload: async (datasourceId, bucket, key, data) => { - const { signedUrl, publicUrl } = await API.getSignedDatasourceURL( + externalUpload: async ({ datasourceId, bucket, key, data }) => { + const { signedUrl, publicUrl } = await API.getSignedDatasourceURL({ datasourceId, bucket, - key - ) + key, + }) await API.put({ url: signedUrl, body: data, diff --git a/packages/frontend-core/src/api/automations.js b/packages/frontend-core/src/api/automations.js index 2843599e78..3b60b6dbac 100644 --- a/packages/frontend-core/src/api/automations.js +++ b/packages/frontend-core/src/api/automations.js @@ -1,6 +1,8 @@ export const buildAutomationEndpoints = API => ({ /** * Executes an automation. Must have "App Action" trigger. + * @param automationId the ID of the automation to trigger + * @param fields the fields to trigger the automation with */ triggerAutomation: async ({ automationId, fields }) => { return await API.post({ diff --git a/packages/frontend-core/src/api/relationships.js b/packages/frontend-core/src/api/relationships.js index 5ea10be50a..fbc727f8e1 100644 --- a/packages/frontend-core/src/api/relationships.js +++ b/packages/frontend-core/src/api/relationships.js @@ -1,6 +1,9 @@ export const buildRelationshipEndpoints = API => ({ /** * Fetches related rows for a certain field of a certain row. + * @param tableId the ID of the table to fetch from + * @param rowId the ID of the row to fetch related rows for + * @param fieldName the name of the relationship field */ fetchRelationshipData: async ({ tableId, rowId, fieldName }) => { if (!tableId || !rowId) { diff --git a/packages/frontend-core/src/api/routes.js b/packages/frontend-core/src/api/routes.js index d87988103f..28e206debc 100644 --- a/packages/frontend-core/src/api/routes.js +++ b/packages/frontend-core/src/api/routes.js @@ -8,6 +8,9 @@ export const buildRouteEndpoints = API => ({ }) }, + /** + * Fetches all routes for the current app. + */ fetchAppRoutes: async () => { return await API.get({ url: "/api/routing", diff --git a/packages/frontend-core/src/api/rows.js b/packages/frontend-core/src/api/rows.js index a191089bd8..553cf8e0de 100644 --- a/packages/frontend-core/src/api/rows.js +++ b/packages/frontend-core/src/api/rows.js @@ -1,6 +1,8 @@ export const buildRowEndpoints = API => ({ /** * Fetches data about a certain row in a table. + * @param tableId the ID of the table to fetch from + * @param rowId the ID of the row to fetch */ fetchRow: async ({ tableId, rowId }) => { if (!tableId || !rowId) { @@ -13,7 +15,8 @@ export const buildRowEndpoints = API => ({ }, /** - * Creates a row in a table. + * Creates or updates a row in a table. + * @param row the row to save */ saveRow: async row => { if (!row?.tableId) { @@ -27,6 +30,9 @@ export const buildRowEndpoints = API => ({ /** * Deletes a row from a table. + * @param tableId the ID of the table to delete from + * @param rowId the ID of the row to delete + * @param revId the rev of the row to delete */ deleteRow: async ({ tableId, rowId, revId }) => { if (!tableId || !rowId || !revId) { diff --git a/packages/frontend-core/src/api/tables.js b/packages/frontend-core/src/api/tables.js index 1f8b450a2a..279d3ba6fb 100644 --- a/packages/frontend-core/src/api/tables.js +++ b/packages/frontend-core/src/api/tables.js @@ -2,6 +2,7 @@ export const buildTableEndpoints = API => ({ /** * Fetches a table definition. * Since definitions cannot change at runtime, the result is cached. + * @param tableId the ID of the table to fetch */ fetchTableDefinition: async tableId => { return await API.get({ @@ -12,6 +13,7 @@ export const buildTableEndpoints = API => ({ /** * Fetches all rows from a table. + * @param tableId the ID of the table for fetch */ fetchTableData: async tableId => { return await API.get({ url: `/api/${tableId}/rows` }) @@ -19,6 +21,14 @@ export const buildTableEndpoints = API => ({ /** * Searches a table using Lucene. + * @param tableId the ID of the table to search + * @param query the lucene search query + * @param bookmark the current pagination bookmark + * @param limit the number of rows to retrieve + * @param sort the field to sort by + * @param sortOrder the order to sort by + * @param sortType the type to sort by, either numerically or alphabetically + * @param paginate whether to paginate the data */ searchTable: async ({ tableId,