Row API typing.
This commit is contained in:
parent
efcdd360e3
commit
efb99c6446
|
@ -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<Row, Row>) => {
|
||||
export const save = async (ctx: UserCtx<SaveRowRequest, SaveRowResponse>) => {
|
||||
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<void, FetchRowsResponse>) {
|
||||
const { tableId } = utils.getSourceId(ctx)
|
||||
ctx.body = await sdk.rows.fetch(tableId)
|
||||
}
|
||||
|
||||
export async function find(ctx: UserCtx<void, GetRowResponse>) {
|
||||
export async function find(ctx: UserCtx<void, FindRowResponse>) {
|
||||
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<Row, ValidateResponse>) {
|
||||
export async function validate(
|
||||
ctx: Ctx<ValidateRowRequest, ValidateRowResponse>
|
||||
) {
|
||||
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<Row, ValidateResponse>) {
|
|||
}
|
||||
}
|
||||
|
||||
export async function fetchEnrichedRow(ctx: UserCtx<void, Row>) {
|
||||
export async function fetchEnrichedRow(
|
||||
ctx: UserCtx<void, FetchEnrichedRowResponse>
|
||||
) {
|
||||
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<void, DownloadAttachmentResponse>
|
||||
) {
|
||||
const { columnName } = ctx.params
|
||||
|
||||
const { tableId } = utils.getSourceId(ctx)
|
||||
|
|
|
@ -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<ValidateResponse> => {
|
||||
return await this._post<ValidateResponse>(
|
||||
): Promise<ValidateRowResponse> => {
|
||||
return await this._post<ValidateRowResponse>(
|
||||
`/api/${sourceId}/rows/validate`,
|
||||
{
|
||||
body: row,
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
export * from "./backup"
|
||||
export * from "./datasource"
|
||||
export * from "./row"
|
||||
export * from "./view"
|
||||
export * from "./rows"
|
||||
export * from "./table"
|
||||
|
|
|
@ -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<string, any>
|
||||
}
|
|
@ -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<string, any>
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue