PR comments.
This commit is contained in:
parent
a44a92dcc2
commit
2011e1693e
|
@ -45,13 +45,16 @@ export async function findRow(ctx: UserCtx, tableId: string, rowId: string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getTableId(ctx: Ctx) {
|
export function getTableId(ctx: Ctx) {
|
||||||
if (ctx.request.body && ctx.request.body.tableId) {
|
if (ctx.request.body?.tableId) {
|
||||||
return ctx.request.body.tableId
|
return ctx.request.body.tableId
|
||||||
}
|
}
|
||||||
if (ctx.params && ctx.params.tableId) {
|
if (ctx.params?.sourceId) {
|
||||||
|
return ctx.params.sourceId
|
||||||
|
}
|
||||||
|
if (ctx.params?.tableId) {
|
||||||
return ctx.params.tableId
|
return ctx.params.tableId
|
||||||
}
|
}
|
||||||
if (ctx.params && ctx.params.viewName) {
|
if (ctx.params?.viewName) {
|
||||||
return ctx.params.viewName
|
return ctx.params.viewName
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ const router: Router = new Router()
|
||||||
|
|
||||||
router
|
router
|
||||||
/**
|
/**
|
||||||
* @api {get} /api/:tableId/:rowId/enrich Get an enriched row
|
* @api {get} /api/:sourceId/:rowId/enrich Get an enriched row
|
||||||
* @apiName Get an enriched row
|
* @apiName Get an enriched row
|
||||||
* @apiGroup rows
|
* @apiGroup rows
|
||||||
* @apiPermission table read access
|
* @apiPermission table read access
|
||||||
|
@ -25,13 +25,13 @@ router
|
||||||
* @apiSuccess {object} row The response body will be the enriched row.
|
* @apiSuccess {object} row The response body will be the enriched row.
|
||||||
*/
|
*/
|
||||||
.get(
|
.get(
|
||||||
"/api/:tableId/:rowId/enrich",
|
"/api/:sourceId/:rowId/enrich",
|
||||||
paramSubResource("tableId", "rowId"),
|
paramSubResource("sourceId", "rowId"),
|
||||||
authorized(PermissionType.TABLE, PermissionLevel.READ),
|
authorized(PermissionType.TABLE, PermissionLevel.READ),
|
||||||
rowController.fetchEnrichedRow
|
rowController.fetchEnrichedRow
|
||||||
)
|
)
|
||||||
/**
|
/**
|
||||||
* @api {get} /api/:tableId/rows Get all rows in a table
|
* @api {get} /api/:sourceId/rows Get all rows in a table
|
||||||
* @apiName Get all rows in a table
|
* @apiName Get all rows in a table
|
||||||
* @apiGroup rows
|
* @apiGroup rows
|
||||||
* @apiPermission table read access
|
* @apiPermission table read access
|
||||||
|
@ -40,37 +40,37 @@ router
|
||||||
* due to its lack of support for pagination. With SQL tables this will retrieve up to a limit and then
|
* due to its lack of support for pagination. With SQL tables this will retrieve up to a limit and then
|
||||||
* will simply stop.
|
* will simply stop.
|
||||||
*
|
*
|
||||||
* @apiParam {string} tableId The ID of the table to retrieve all rows within.
|
* @apiParam {string} sourceId The ID of the table to retrieve all rows within.
|
||||||
*
|
*
|
||||||
* @apiSuccess {object[]} rows The response body will be an array of all rows found.
|
* @apiSuccess {object[]} rows The response body will be an array of all rows found.
|
||||||
*/
|
*/
|
||||||
.get(
|
.get(
|
||||||
"/api/:tableId/rows",
|
"/api/:sourceId/rows",
|
||||||
paramResource("tableId"),
|
paramResource("sourceId"),
|
||||||
authorized(PermissionType.TABLE, PermissionLevel.READ),
|
authorized(PermissionType.TABLE, PermissionLevel.READ),
|
||||||
rowController.fetch
|
rowController.fetch
|
||||||
)
|
)
|
||||||
/**
|
/**
|
||||||
* @api {get} /api/:tableId/rows/:rowId Retrieve a single row
|
* @api {get} /api/:sourceId/rows/:rowId Retrieve a single row
|
||||||
* @apiName Retrieve a single row
|
* @apiName Retrieve a single row
|
||||||
* @apiGroup rows
|
* @apiGroup rows
|
||||||
* @apiPermission table read access
|
* @apiPermission table read access
|
||||||
* @apiDescription This endpoint retrieves only the specified row. If you wish to retrieve
|
* @apiDescription This endpoint retrieves only the specified row. If you wish to retrieve
|
||||||
* a row by anything other than its _id field, use the search endpoint.
|
* a row by anything other than its _id field, use the search endpoint.
|
||||||
*
|
*
|
||||||
* @apiParam {string} tableId The ID of the table to retrieve a row from.
|
* @apiParam {string} sourceId The ID of the table to retrieve a row from.
|
||||||
* @apiParam {string} rowId The ID of the row to retrieve.
|
* @apiParam {string} rowId The ID of the row to retrieve.
|
||||||
*
|
*
|
||||||
* @apiSuccess {object} body The response body will be the row that was found.
|
* @apiSuccess {object} body The response body will be the row that was found.
|
||||||
*/
|
*/
|
||||||
.get(
|
.get(
|
||||||
"/api/:tableId/rows/:rowId",
|
"/api/:sourceId/rows/:rowId",
|
||||||
paramSubResource("tableId", "rowId"),
|
paramSubResource("sourceId", "rowId"),
|
||||||
authorized(PermissionType.TABLE, PermissionLevel.READ),
|
authorized(PermissionType.TABLE, PermissionLevel.READ),
|
||||||
rowController.find
|
rowController.find
|
||||||
)
|
)
|
||||||
/**
|
/**
|
||||||
* @api {post} /api/:tableId/search Search for rows in a table
|
* @api {post} /api/:sourceId/search Search for rows in a table
|
||||||
* @apiName Search for rows in a table
|
* @apiName Search for rows in a table
|
||||||
* @apiGroup rows
|
* @apiGroup rows
|
||||||
* @apiPermission table read access
|
* @apiPermission table read access
|
||||||
|
@ -78,7 +78,7 @@ router
|
||||||
* and data UI in the builder are built atop this. All filtering, sorting and pagination is
|
* and data UI in the builder are built atop this. All filtering, sorting and pagination is
|
||||||
* handled through this, for internal and external (datasource plus, e.g. SQL) tables.
|
* handled through this, for internal and external (datasource plus, e.g. SQL) tables.
|
||||||
*
|
*
|
||||||
* @apiParam {string} tableId The ID of the table to retrieve rows from.
|
* @apiParam {string} sourceId The ID of the table to retrieve rows from.
|
||||||
*
|
*
|
||||||
* @apiParam (Body) {boolean} [paginate] If pagination is required then this should be set to true,
|
* @apiParam (Body) {boolean} [paginate] If pagination is required then this should be set to true,
|
||||||
* defaults to false.
|
* defaults to false.
|
||||||
|
@ -133,22 +133,22 @@ router
|
||||||
* page.
|
* page.
|
||||||
*/
|
*/
|
||||||
.post(
|
.post(
|
||||||
"/api/:tableId/search",
|
"/api/:sourceId/search",
|
||||||
internalSearchValidator(),
|
internalSearchValidator(),
|
||||||
paramResource("tableId"),
|
paramResource("sourceId"),
|
||||||
authorized(PermissionType.TABLE, PermissionLevel.READ),
|
authorized(PermissionType.TABLE, PermissionLevel.READ),
|
||||||
rowController.search
|
rowController.search
|
||||||
)
|
)
|
||||||
// DEPRECATED - this is an old API, but for backwards compat it needs to be
|
// DEPRECATED - this is an old API, but for backwards compat it needs to be
|
||||||
// supported still
|
// supported still
|
||||||
.post(
|
.post(
|
||||||
"/api/search/:tableId/rows",
|
"/api/search/:sourceId/rows",
|
||||||
paramResource("tableId"),
|
paramResource("sourceId"),
|
||||||
authorized(PermissionType.TABLE, PermissionLevel.READ),
|
authorized(PermissionType.TABLE, PermissionLevel.READ),
|
||||||
rowController.search
|
rowController.search
|
||||||
)
|
)
|
||||||
/**
|
/**
|
||||||
* @api {post} /api/:tableId/rows Creates a new row
|
* @api {post} /api/:sourceId/rows Creates a new row
|
||||||
* @apiName Creates a new row
|
* @apiName Creates a new row
|
||||||
* @apiGroup rows
|
* @apiGroup rows
|
||||||
* @apiPermission table write access
|
* @apiPermission table write access
|
||||||
|
@ -157,7 +157,7 @@ router
|
||||||
* links to one. Please note that "_id", "_rev" and "tableId" are fields that are
|
* links to one. Please note that "_id", "_rev" and "tableId" are fields that are
|
||||||
* already used by Budibase tables and cannot be used for columns.
|
* already used by Budibase tables and cannot be used for columns.
|
||||||
*
|
*
|
||||||
* @apiParam {string} tableId The ID of the table to save a row to.
|
* @apiParam {string} sourceId The ID of the table to save a row to.
|
||||||
*
|
*
|
||||||
* @apiParam (Body) {string} [_id] If the row exists already then an ID for the row must be provided.
|
* @apiParam (Body) {string} [_id] If the row exists already then an ID for the row must be provided.
|
||||||
* @apiParam (Body) {string} [_rev] If working with an existing row for an internal table its revision
|
* @apiParam (Body) {string} [_rev] If working with an existing row for an internal table its revision
|
||||||
|
@ -172,14 +172,14 @@ router
|
||||||
* @apiSuccess {object} body The contents of the row that was saved will be returned as well.
|
* @apiSuccess {object} body The contents of the row that was saved will be returned as well.
|
||||||
*/
|
*/
|
||||||
.post(
|
.post(
|
||||||
"/api/:tableId/rows",
|
"/api/:sourceId/rows",
|
||||||
paramResource("tableId"),
|
paramResource("sourceId"),
|
||||||
authorized(PermissionType.TABLE, PermissionLevel.WRITE),
|
authorized(PermissionType.TABLE, PermissionLevel.WRITE),
|
||||||
trimViewRowInfo,
|
trimViewRowInfo,
|
||||||
rowController.save
|
rowController.save
|
||||||
)
|
)
|
||||||
/**
|
/**
|
||||||
* @api {patch} /api/:tableId/rows Updates a row
|
* @api {patch} /api/:sourceId/rows Updates a row
|
||||||
* @apiName Update a row
|
* @apiName Update a row
|
||||||
* @apiGroup rows
|
* @apiGroup rows
|
||||||
* @apiPermission table write access
|
* @apiPermission table write access
|
||||||
|
@ -187,14 +187,14 @@ router
|
||||||
* error if an _id isn't provided, it will only function for existing rows.
|
* error if an _id isn't provided, it will only function for existing rows.
|
||||||
*/
|
*/
|
||||||
.patch(
|
.patch(
|
||||||
"/api/:tableId/rows",
|
"/api/:sourceId/rows",
|
||||||
paramResource("tableId"),
|
paramResource("sourceId"),
|
||||||
authorized(PermissionType.TABLE, PermissionLevel.WRITE),
|
authorized(PermissionType.TABLE, PermissionLevel.WRITE),
|
||||||
trimViewRowInfo,
|
trimViewRowInfo,
|
||||||
rowController.patch
|
rowController.patch
|
||||||
)
|
)
|
||||||
/**
|
/**
|
||||||
* @api {post} /api/:tableId/rows/validate Validate inputs for a row
|
* @api {post} /api/:sourceId/rows/validate Validate inputs for a row
|
||||||
* @apiName Validate inputs for a row
|
* @apiName Validate inputs for a row
|
||||||
* @apiGroup rows
|
* @apiGroup rows
|
||||||
* @apiPermission table write access
|
* @apiPermission table write access
|
||||||
|
@ -202,7 +202,7 @@ router
|
||||||
* given the table schema, this will iterate through all the constraints on the table and
|
* given the table schema, this will iterate through all the constraints on the table and
|
||||||
* check if the request body is valid.
|
* check if the request body is valid.
|
||||||
*
|
*
|
||||||
* @apiParam {string} tableId The ID of the table the row is to be validated for.
|
* @apiParam {string} sourceId The ID of the table the row is to be validated for.
|
||||||
*
|
*
|
||||||
* @apiParam (Body) {any} [any] Any fields provided in the request body will be tested
|
* @apiParam (Body) {any} [any] Any fields provided in the request body will be tested
|
||||||
* against the table schema and constraints.
|
* against the table schema and constraints.
|
||||||
|
@ -214,20 +214,20 @@ router
|
||||||
* the schema.
|
* the schema.
|
||||||
*/
|
*/
|
||||||
.post(
|
.post(
|
||||||
"/api/:tableId/rows/validate",
|
"/api/:sourceId/rows/validate",
|
||||||
paramResource("tableId"),
|
paramResource("sourceId"),
|
||||||
authorized(PermissionType.TABLE, PermissionLevel.WRITE),
|
authorized(PermissionType.TABLE, PermissionLevel.WRITE),
|
||||||
rowController.validate
|
rowController.validate
|
||||||
)
|
)
|
||||||
/**
|
/**
|
||||||
* @api {delete} /api/:tableId/rows Delete rows
|
* @api {delete} /api/:sourceId/rows Delete rows
|
||||||
* @apiName Delete rows
|
* @apiName Delete rows
|
||||||
* @apiGroup rows
|
* @apiGroup rows
|
||||||
* @apiPermission table write access
|
* @apiPermission table write access
|
||||||
* @apiDescription This endpoint can delete a single row, or delete them in a bulk
|
* @apiDescription This endpoint can delete a single row, or delete them in a bulk
|
||||||
* fashion.
|
* fashion.
|
||||||
*
|
*
|
||||||
* @apiParam {string} tableId The ID of the table the row is to be deleted from.
|
* @apiParam {string} sourceId The ID of the table the row is to be deleted from.
|
||||||
*
|
*
|
||||||
* @apiParam (Body) {object[]} [rows] If bulk deletion is desired then provide the rows in this
|
* @apiParam (Body) {object[]} [rows] If bulk deletion is desired then provide the rows in this
|
||||||
* key of the request body that are to be deleted.
|
* key of the request body that are to be deleted.
|
||||||
|
@ -240,29 +240,29 @@ router
|
||||||
* is the deleted row.
|
* is the deleted row.
|
||||||
*/
|
*/
|
||||||
.delete(
|
.delete(
|
||||||
"/api/:tableId/rows",
|
"/api/:sourceId/rows",
|
||||||
paramResource("tableId"),
|
paramResource("sourceId"),
|
||||||
authorized(PermissionType.TABLE, PermissionLevel.WRITE),
|
authorized(PermissionType.TABLE, PermissionLevel.WRITE),
|
||||||
trimViewRowInfo,
|
trimViewRowInfo,
|
||||||
rowController.destroy
|
rowController.destroy
|
||||||
)
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @api {post} /api/:tableId/rows/exportRows Export Rows
|
* @api {post} /api/:sourceId/rows/exportRows Export Rows
|
||||||
* @apiName Export rows
|
* @apiName Export rows
|
||||||
* @apiGroup rows
|
* @apiGroup rows
|
||||||
* @apiPermission table write access
|
* @apiPermission table write access
|
||||||
* @apiDescription This API can export a number of provided rows
|
* @apiDescription This API can export a number of provided rows
|
||||||
*
|
*
|
||||||
* @apiParam {string} tableId The ID of the table the row is to be deleted from.
|
* @apiParam {string} sourceId The ID of the table the row is to be deleted from.
|
||||||
*
|
*
|
||||||
* @apiParam (Body) {object[]} [rows] The row IDs which are to be exported
|
* @apiParam (Body) {object[]} [rows] The row IDs which are to be exported
|
||||||
*
|
*
|
||||||
* @apiSuccess {object[]|object}
|
* @apiSuccess {object[]|object}
|
||||||
*/
|
*/
|
||||||
.post(
|
.post(
|
||||||
"/api/:tableId/rows/exportRows",
|
"/api/:sourceId/rows/exportRows",
|
||||||
paramResource("tableId"),
|
paramResource("sourceId"),
|
||||||
authorized(PermissionType.TABLE, PermissionLevel.WRITE),
|
authorized(PermissionType.TABLE, PermissionLevel.WRITE),
|
||||||
rowController.exportRows
|
rowController.exportRows
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
import newid from "./newid"
|
import newid from "./newid"
|
||||||
import { db as dbCore } from "@budibase/backend-core"
|
import { db as dbCore } from "@budibase/backend-core"
|
||||||
|
import { DocumentType, VirtualDocumentType } from "@budibase/types"
|
||||||
|
export { DocumentType, VirtualDocumentType } from "@budibase/types"
|
||||||
|
|
||||||
type Optional = string | null
|
type Optional = string | null
|
||||||
|
|
||||||
|
@ -19,7 +21,6 @@ export const BudibaseInternalDB = {
|
||||||
|
|
||||||
export const SEPARATOR = dbCore.SEPARATOR
|
export const SEPARATOR = dbCore.SEPARATOR
|
||||||
export const StaticDatabases = dbCore.StaticDatabases
|
export const StaticDatabases = dbCore.StaticDatabases
|
||||||
export const DocumentType = dbCore.DocumentType
|
|
||||||
export const APP_PREFIX = dbCore.APP_PREFIX
|
export const APP_PREFIX = dbCore.APP_PREFIX
|
||||||
export const APP_DEV_PREFIX = dbCore.APP_DEV_PREFIX
|
export const APP_DEV_PREFIX = dbCore.APP_DEV_PREFIX
|
||||||
export const isDevAppID = dbCore.isDevAppID
|
export const isDevAppID = dbCore.isDevAppID
|
||||||
|
@ -284,11 +285,13 @@ export function getMultiIDParams(ids: string[]) {
|
||||||
* @returns {string} The new view ID which the view doc can be stored under.
|
* @returns {string} The new view ID which the view doc can be stored under.
|
||||||
*/
|
*/
|
||||||
export function generateViewID(tableId: string) {
|
export function generateViewID(tableId: string) {
|
||||||
return `${DocumentType.VIEW}${SEPARATOR}${tableId}${SEPARATOR}${newid()}`
|
return `${
|
||||||
|
VirtualDocumentType.VIEW
|
||||||
|
}${SEPARATOR}${tableId}${SEPARATOR}${newid()}`
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isViewID(viewId: string) {
|
export function isViewID(viewId: string) {
|
||||||
return viewId?.split(SEPARATOR)[0] === DocumentType.VIEW
|
return viewId?.split(SEPARATOR)[0] === VirtualDocumentType.VIEW
|
||||||
}
|
}
|
||||||
|
|
||||||
export function extractViewInfoFromID(viewId: string) {
|
export function extractViewInfoFromID(viewId: string) {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { permissions, roles } from "@budibase/backend-core"
|
import { permissions, roles } from "@budibase/backend-core"
|
||||||
import { DocumentType } from "../db/utils"
|
import { DocumentType, VirtualDocumentType } from "../db/utils"
|
||||||
|
|
||||||
export const CURRENTLY_SUPPORTED_LEVELS: string[] = [
|
export const CURRENTLY_SUPPORTED_LEVELS: string[] = [
|
||||||
permissions.PermissionLevel.WRITE,
|
permissions.PermissionLevel.WRITE,
|
||||||
|
@ -11,10 +11,10 @@ export function getPermissionType(resourceId: string) {
|
||||||
const docType = Object.values(DocumentType).filter(docType =>
|
const docType = Object.values(DocumentType).filter(docType =>
|
||||||
resourceId.startsWith(docType)
|
resourceId.startsWith(docType)
|
||||||
)[0]
|
)[0]
|
||||||
switch (docType) {
|
switch (docType as DocumentType | VirtualDocumentType) {
|
||||||
case DocumentType.TABLE:
|
case DocumentType.TABLE:
|
||||||
case DocumentType.ROW:
|
case DocumentType.ROW:
|
||||||
case DocumentType.VIEW:
|
case VirtualDocumentType.VIEW:
|
||||||
return permissions.PermissionType.TABLE
|
return permissions.PermissionType.TABLE
|
||||||
case DocumentType.AUTOMATION:
|
case DocumentType.AUTOMATION:
|
||||||
return permissions.PermissionType.AUTOMATION
|
return permissions.PermissionType.AUTOMATION
|
||||||
|
|
|
@ -37,6 +37,12 @@ export enum DocumentType {
|
||||||
USER_FLAG = "flag",
|
USER_FLAG = "flag",
|
||||||
AUTOMATION_METADATA = "meta_au",
|
AUTOMATION_METADATA = "meta_au",
|
||||||
AUDIT_LOG = "al",
|
AUDIT_LOG = "al",
|
||||||
|
VIEW = "awd",
|
||||||
|
}
|
||||||
|
|
||||||
|
// these documents don't really exist, they are part of other
|
||||||
|
// documents or enriched into existence as part of get requests
|
||||||
|
export enum VirtualDocumentType {
|
||||||
VIEW = "view",
|
VIEW = "view",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue