diff --git a/packages/server/src/api/controllers/row/index.ts b/packages/server/src/api/controllers/row/index.ts index cc5491e54f..0463c0a565 100644 --- a/packages/server/src/api/controllers/row/index.ts +++ b/packages/server/src/api/controllers/row/index.ts @@ -11,11 +11,14 @@ import { DeleteRow, DeleteRowRequest, DeleteRows, + DownloadAttachmentResponse, EventType, ExportRowsRequest, ExportRowsResponse, + FetchEnrichedRowResponse, + FetchRowsResponse, FieldType, - GetRowResponse, + FindRowResponse, isRelationshipField, PatchRowRequest, PatchRowResponse, @@ -23,12 +26,15 @@ import { Row, RowAttachment, RowSearchParams, + SaveRowRequest, + SaveRowResponse, SearchFilters, SearchRowRequest, SearchRowResponse, Table, UserCtx, - ValidateResponse, + ValidateRowRequest, + ValidateRowResponse, } from "@budibase/types" import * as utils from "./utils" import { gridSocket } from "../../../websockets" @@ -83,7 +89,7 @@ export async function patch( } } -export const save = async (ctx: UserCtx) => { +export const save = async (ctx: UserCtx) => { const { tableId, viewId } = utils.getSourceId(ctx) const sourceId = viewId || tableId @@ -131,12 +137,12 @@ export async function fetchLegacyView(ctx: any) { }) } -export async function fetch(ctx: any) { +export async function fetch(ctx: UserCtx) { const { tableId } = utils.getSourceId(ctx) ctx.body = await sdk.rows.fetch(tableId) } -export async function find(ctx: UserCtx) { +export async function find(ctx: UserCtx) { const { tableId, viewId } = utils.getSourceId(ctx) const sourceId = viewId || tableId const rowId = ctx.params.rowId @@ -314,7 +320,9 @@ function replaceTableNamesInFilters( }) } -export async function validate(ctx: Ctx) { +export async function validate( + ctx: Ctx +) { const source = await utils.getSource(ctx) const table = await utils.getTableFromSource(source) // external tables are hard to validate currently @@ -328,7 +336,9 @@ export async function validate(ctx: Ctx) { } } -export async function fetchEnrichedRow(ctx: UserCtx) { +export async function fetchEnrichedRow( + ctx: UserCtx +) { const { tableId } = utils.getSourceId(ctx) ctx.body = await pickApi(tableId).fetchEnrichedRow(ctx) } @@ -366,7 +376,9 @@ export const exportRows = async ( ctx.body = apiFileReturn(content) } -export async function downloadAttachment(ctx: UserCtx) { +export async function downloadAttachment( + ctx: UserCtx +) { const { columnName } = ctx.params const { tableId } = utils.getSourceId(ctx) diff --git a/packages/server/src/tests/utilities/api/row.ts b/packages/server/src/tests/utilities/api/row.ts index 52317e142a..f68b41aca9 100644 --- a/packages/server/src/tests/utilities/api/row.ts +++ b/packages/server/src/tests/utilities/api/row.ts @@ -2,7 +2,7 @@ import { PatchRowRequest, SaveRowRequest, Row, - ValidateResponse, + ValidateRowResponse, ExportRowsRequest, BulkImportRequest, BulkImportResponse, @@ -51,8 +51,8 @@ export class RowAPI extends TestAPI { sourceId: string, row: SaveRowRequest, expectations?: Expectations - ): Promise => { - return await this._post( + ): Promise => { + return await this._post( `/api/${sourceId}/rows/validate`, { body: row, diff --git a/packages/types/src/api/web/app/index.ts b/packages/types/src/api/web/app/index.ts index 15c9c8929d..d130d19a42 100644 --- a/packages/types/src/api/web/app/index.ts +++ b/packages/types/src/api/web/app/index.ts @@ -1,6 +1,5 @@ export * from "./backup" export * from "./datasource" -export * from "./row" export * from "./view" export * from "./rows" export * from "./table" diff --git a/packages/types/src/api/web/app/row.ts b/packages/types/src/api/web/app/row.ts deleted file mode 100644 index 4ab4090461..0000000000 --- a/packages/types/src/api/web/app/row.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { Row } from "../../../documents/app/row" - -export interface GetRowResponse extends Row {} - -export interface DeleteRows { - rows: (Row | string)[] -} - -export interface DeleteRow { - _id: string -} - -export type DeleteRowRequest = DeleteRows | DeleteRow - -export interface ValidateResponse { - valid: boolean - errors: Record -} diff --git a/packages/types/src/api/web/app/rows/index.ts b/packages/types/src/api/web/app/rows/index.ts index 2642a8b04e..7994f9736b 100644 --- a/packages/types/src/api/web/app/rows/index.ts +++ b/packages/types/src/api/web/app/rows/index.ts @@ -1,11 +1,17 @@ import { SearchFilters } from "../../../../sdk" import { Row } from "../../../../documents" -import { SortOrder } from "../../../../api/web/pagination" +import { SortOrder } from "../../pagination" import { ReadStream } from "fs" +import stream from "node:stream" export * from "./search" +export interface FetchEnrichedRowResponse extends Row {} + +export type FetchRowsResponse = Row[] + export interface SaveRowRequest extends Row {} +export interface SaveRowResponse extends Row {} export interface PatchRowRequest extends Row { _id: string @@ -26,3 +32,23 @@ export interface ExportRowsRequest { } export type ExportRowsResponse = ReadStream + +export type DownloadAttachmentResponse = stream.PassThrough | stream.Readable + +export interface FindRowResponse extends Row {} + +export interface DeleteRows { + rows: (Row | string)[] +} + +export interface DeleteRow { + _id: string +} + +export type DeleteRowRequest = DeleteRows | DeleteRow + +export interface ValidateRowRequest extends Row {} +export interface ValidateRowResponse { + valid: boolean + errors: Record +}