Screens and some slightly changes to Table API typing.

This commit is contained in:
mike12345567 2024-12-03 18:06:09 +00:00
parent ce6e1c5c22
commit 6494962c1a
9 changed files with 55 additions and 46 deletions

View File

@ -592,7 +592,10 @@ export class AccessController {
) )
} }
async checkScreensAccess(screens: Screen[], userRoleId: string) { async checkScreensAccess(
screens: Screen[],
userRoleId: string
): Promise<Screen[]> {
let accessibleScreens = [] let accessibleScreens = []
// don't want to handle this with Promise.all as this would mean all custom roles would be // don't want to handle this with Promise.all as this would mean all custom roles would be
// retrieved at same time, it is likely a custom role will be re-used and therefore want // retrieved at same time, it is likely a custom role will be re-used and therefore want

View File

@ -10,13 +10,16 @@ import { updateAppPackage } from "./application"
import { import {
Plugin, Plugin,
ScreenProps, ScreenProps,
BBContext,
Screen, Screen,
UserCtx, UserCtx,
FetchScreenResponse,
SaveScreenRequest,
SaveScreenResponse,
DeleteScreenResponse,
} from "@budibase/types" } from "@budibase/types"
import { builderSocket } from "../../websockets" import { builderSocket } from "../../websockets"
export async function fetch(ctx: BBContext) { export async function fetch(ctx: UserCtx<void, FetchScreenResponse>) {
const db = context.getAppDB() const db = context.getAppDB()
const screens = ( const screens = (
@ -37,7 +40,9 @@ export async function fetch(ctx: BBContext) {
) )
} }
export async function save(ctx: UserCtx<Screen, Screen>) { export async function save(
ctx: UserCtx<SaveScreenRequest, SaveScreenResponse>
) {
const db = context.getAppDB() const db = context.getAppDB()
let screen = ctx.request.body let screen = ctx.request.body
@ -107,7 +112,7 @@ export async function save(ctx: UserCtx<Screen, Screen>) {
builderSocket?.emitScreenUpdate(ctx, savedScreen) builderSocket?.emitScreenUpdate(ctx, savedScreen)
} }
export async function destroy(ctx: BBContext) { export async function destroy(ctx: UserCtx<void, DeleteScreenResponse>) {
const db = context.getAppDB() const db = context.getAppDB()
const id = ctx.params.screenId const id = ctx.params.screenId
const screen = await db.get<Screen>(id) const screen = await db.get<Screen>(id)

View File

@ -14,7 +14,3 @@ export async function execute(ctx: Ctx) {
throw err throw err
} }
} }
export async function save(ctx: Ctx) {
ctx.throw(501, "Not currently implemented")
}

View File

@ -19,17 +19,18 @@ import {
EventType, EventType,
FetchTablesResponse, FetchTablesResponse,
FieldType, FieldType,
MigrateRequest, MigrateTableRequest,
MigrateResponse, MigrateTableResponse,
SaveTableRequest, SaveTableRequest,
SaveTableResponse, SaveTableResponse,
Table, Table,
TableResponse, FindTableResponse,
TableSourceType, TableSourceType,
UserCtx, UserCtx,
ValidateNewTableImportRequest, ValidateNewTableImportRequest,
ValidateTableImportRequest, ValidateTableImportRequest,
ValidateTableImportResponse, ValidateTableImportResponse,
DeleteTableResponse,
} from "@budibase/types" } from "@budibase/types"
import sdk from "../../../sdk" import sdk from "../../../sdk"
import { jsonFromCsvString } from "../../../utilities/csv" import { jsonFromCsvString } from "../../../utilities/csv"
@ -94,7 +95,7 @@ export async function fetch(ctx: UserCtx<void, FetchTablesResponse>) {
ctx.body = result ctx.body = result
} }
export async function find(ctx: UserCtx<void, TableResponse>) { export async function find(ctx: UserCtx<void, FindTableResponse>) {
const tableId = ctx.params.tableId const tableId = ctx.params.tableId
const table = await sdk.tables.getTable(tableId) const table = await sdk.tables.getTable(tableId)
@ -137,7 +138,7 @@ export async function save(ctx: UserCtx<SaveTableRequest, SaveTableResponse>) {
builderSocket?.emitTableUpdate(ctx, cloneDeep(savedTable)) builderSocket?.emitTableUpdate(ctx, cloneDeep(savedTable))
} }
export async function destroy(ctx: UserCtx) { export async function destroy(ctx: UserCtx<void, DeleteTableResponse>) {
const appId = ctx.appId const appId = ctx.appId
const tableId = ctx.params.tableId const tableId = ctx.params.tableId
await sdk.rowActions.deleteAll(tableId) await sdk.rowActions.deleteAll(tableId)
@ -223,7 +224,9 @@ export async function validateExistingTableImport(
} }
} }
export async function migrate(ctx: UserCtx<MigrateRequest, MigrateResponse>) { export async function migrate(
ctx: UserCtx<MigrateTableRequest, MigrateTableResponse>
) {
const { oldColumn, newColumn } = ctx.request.body const { oldColumn, newColumn } = ctx.request.body
let tableId = ctx.params.tableId as string let tableId = ctx.params.tableId as string
const table = await sdk.tables.getTable(tableId) const table = await sdk.tables.getTable(tableId)

View File

@ -1,10 +0,0 @@
import Router from "@koa/router"
import * as controller from "../controllers/script"
import authorized from "../../middleware/authorized"
import { permissions } from "@budibase/backend-core"
const router: Router = new Router()
router.post("/api/script", authorized(permissions.BUILDER), controller.save)
export default router

View File

@ -9,7 +9,7 @@ import {
Database, Database,
INTERNAL_TABLE_SOURCE_ID, INTERNAL_TABLE_SOURCE_ID,
Table, Table,
TableResponse, FindTableResponse,
TableSourceType, TableSourceType,
TableViewsResponse, TableViewsResponse,
} from "@budibase/types" } from "@budibase/types"
@ -173,7 +173,9 @@ export async function getTables(tableIds: string[]): Promise<Table[]> {
return await processTables(tables) return await processTables(tables)
} }
export async function enrichViewSchemas(table: Table): Promise<TableResponse> { export async function enrichViewSchemas(
table: Table
): Promise<FindTableResponse> {
const views = [] const views = []
for (const view of Object.values(table.views ?? [])) { for (const view of Object.values(table.views ?? [])) {
if (sdk.views.isV2(view)) { if (sdk.views.isV2(view)) {

View File

@ -3,8 +3,8 @@ import {
BulkImportResponse, BulkImportResponse,
CsvToJsonRequest, CsvToJsonRequest,
CsvToJsonResponse, CsvToJsonResponse,
MigrateRequest, MigrateTableRequest,
MigrateResponse, MigrateTableResponse,
SaveTableRequest, SaveTableRequest,
SaveTableResponse, SaveTableResponse,
Table, Table,
@ -38,13 +38,16 @@ export class TableAPI extends TestAPI {
migrate = async ( migrate = async (
tableId: string, tableId: string,
data: MigrateRequest, data: MigrateTableRequest,
expectations?: Expectations expectations?: Expectations
): Promise<MigrateResponse> => { ): Promise<MigrateTableResponse> => {
return await this._post<MigrateResponse>(`/api/tables/${tableId}/migrate`, { return await this._post<MigrateTableResponse>(
body: data, `/api/tables/${tableId}/migrate`,
expectations, {
}) body: data,
expectations,
}
)
} }
import = async ( import = async (

View File

@ -1,4 +1,4 @@
import { ScreenRoutingJson } from "../../../documents" import { ScreenRoutingJson, Screen } from "../../../documents"
export interface FetchScreenRoutingResponse { export interface FetchScreenRoutingResponse {
routes: ScreenRoutingJson routes: ScreenRoutingJson
@ -6,3 +6,12 @@ export interface FetchScreenRoutingResponse {
export interface FetchClientScreenRoutingResponse export interface FetchClientScreenRoutingResponse
extends FetchScreenRoutingResponse {} extends FetchScreenRoutingResponse {}
export type FetchScreenResponse = Screen[]
export interface SaveScreenRequest extends Screen {}
export interface SaveScreenResponse extends Screen {}
export interface DeleteScreenResponse {
message: string
}

View File

@ -3,33 +3,30 @@ import { ViewV2Enriched } from "../../../sdk"
export type TableViewsResponse = { [key: string]: View | ViewV2Enriched } export type TableViewsResponse = { [key: string]: View | ViewV2Enriched }
export interface TableResponse extends Table { export interface FindTableResponse extends Table {
views?: TableViewsResponse views?: TableViewsResponse
} }
export type FetchTablesResponse = TableResponse[] export type FetchTablesResponse = FindTableResponse[]
export interface SaveTableRequest extends TableRequest { export interface SaveTableRequest extends TableRequest {
rows?: Row[] rows?: Row[]
} }
export type SaveTableResponse = Table export type SaveTableResponse = Table
export interface BulkImportRequest { export interface BulkImportRequest {
rows: Row[] rows: Row[]
identifierFields?: Array<string> identifierFields?: Array<string>
} }
export interface BulkImportResponse { export interface BulkImportResponse {
message: string message: string
} }
export interface MigrateRequest { export interface MigrateTableRequest {
oldColumn: string oldColumn: string
newColumn: string newColumn: string
} }
export interface MigrateTableResponse {
export interface MigrateResponse {
message: string message: string
} }
@ -37,12 +34,10 @@ export interface ValidateNewTableImportRequest {
rows: Row[] rows: Row[]
schema: TableSchema schema: TableSchema
} }
export interface ValidateTableImportRequest { export interface ValidateTableImportRequest {
tableId?: string tableId?: string
rows: Row[] rows: Row[]
} }
export interface ValidateTableImportResponse { export interface ValidateTableImportResponse {
schemaValidation: { schemaValidation: {
[field: string]: boolean [field: string]: boolean
@ -55,5 +50,8 @@ export interface ValidateTableImportResponse {
export interface CsvToJsonRequest { export interface CsvToJsonRequest {
csvString: string csvString: string
} }
export type CsvToJsonResponse = any[] export type CsvToJsonResponse = any[]
export interface DeleteTableResponse {
message: string
}