Row API typing.
This commit is contained in:
parent
efcdd360e3
commit
efb99c6446
|
@ -11,11 +11,14 @@ import {
|
||||||
DeleteRow,
|
DeleteRow,
|
||||||
DeleteRowRequest,
|
DeleteRowRequest,
|
||||||
DeleteRows,
|
DeleteRows,
|
||||||
|
DownloadAttachmentResponse,
|
||||||
EventType,
|
EventType,
|
||||||
ExportRowsRequest,
|
ExportRowsRequest,
|
||||||
ExportRowsResponse,
|
ExportRowsResponse,
|
||||||
|
FetchEnrichedRowResponse,
|
||||||
|
FetchRowsResponse,
|
||||||
FieldType,
|
FieldType,
|
||||||
GetRowResponse,
|
FindRowResponse,
|
||||||
isRelationshipField,
|
isRelationshipField,
|
||||||
PatchRowRequest,
|
PatchRowRequest,
|
||||||
PatchRowResponse,
|
PatchRowResponse,
|
||||||
|
@ -23,12 +26,15 @@ import {
|
||||||
Row,
|
Row,
|
||||||
RowAttachment,
|
RowAttachment,
|
||||||
RowSearchParams,
|
RowSearchParams,
|
||||||
|
SaveRowRequest,
|
||||||
|
SaveRowResponse,
|
||||||
SearchFilters,
|
SearchFilters,
|
||||||
SearchRowRequest,
|
SearchRowRequest,
|
||||||
SearchRowResponse,
|
SearchRowResponse,
|
||||||
Table,
|
Table,
|
||||||
UserCtx,
|
UserCtx,
|
||||||
ValidateResponse,
|
ValidateRowRequest,
|
||||||
|
ValidateRowResponse,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import * as utils from "./utils"
|
import * as utils from "./utils"
|
||||||
import { gridSocket } from "../../../websockets"
|
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 { tableId, viewId } = utils.getSourceId(ctx)
|
||||||
const sourceId = viewId || tableId
|
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)
|
const { tableId } = utils.getSourceId(ctx)
|
||||||
ctx.body = await sdk.rows.fetch(tableId)
|
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 { tableId, viewId } = utils.getSourceId(ctx)
|
||||||
const sourceId = viewId || tableId
|
const sourceId = viewId || tableId
|
||||||
const rowId = ctx.params.rowId
|
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 source = await utils.getSource(ctx)
|
||||||
const table = await utils.getTableFromSource(source)
|
const table = await utils.getTableFromSource(source)
|
||||||
// external tables are hard to validate currently
|
// 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)
|
const { tableId } = utils.getSourceId(ctx)
|
||||||
ctx.body = await pickApi(tableId).fetchEnrichedRow(ctx)
|
ctx.body = await pickApi(tableId).fetchEnrichedRow(ctx)
|
||||||
}
|
}
|
||||||
|
@ -366,7 +376,9 @@ export const exportRows = async (
|
||||||
ctx.body = apiFileReturn(content)
|
ctx.body = apiFileReturn(content)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function downloadAttachment(ctx: UserCtx) {
|
export async function downloadAttachment(
|
||||||
|
ctx: UserCtx<void, DownloadAttachmentResponse>
|
||||||
|
) {
|
||||||
const { columnName } = ctx.params
|
const { columnName } = ctx.params
|
||||||
|
|
||||||
const { tableId } = utils.getSourceId(ctx)
|
const { tableId } = utils.getSourceId(ctx)
|
||||||
|
|
|
@ -2,7 +2,7 @@ import {
|
||||||
PatchRowRequest,
|
PatchRowRequest,
|
||||||
SaveRowRequest,
|
SaveRowRequest,
|
||||||
Row,
|
Row,
|
||||||
ValidateResponse,
|
ValidateRowResponse,
|
||||||
ExportRowsRequest,
|
ExportRowsRequest,
|
||||||
BulkImportRequest,
|
BulkImportRequest,
|
||||||
BulkImportResponse,
|
BulkImportResponse,
|
||||||
|
@ -51,8 +51,8 @@ export class RowAPI extends TestAPI {
|
||||||
sourceId: string,
|
sourceId: string,
|
||||||
row: SaveRowRequest,
|
row: SaveRowRequest,
|
||||||
expectations?: Expectations
|
expectations?: Expectations
|
||||||
): Promise<ValidateResponse> => {
|
): Promise<ValidateRowResponse> => {
|
||||||
return await this._post<ValidateResponse>(
|
return await this._post<ValidateRowResponse>(
|
||||||
`/api/${sourceId}/rows/validate`,
|
`/api/${sourceId}/rows/validate`,
|
||||||
{
|
{
|
||||||
body: row,
|
body: row,
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
export * from "./backup"
|
export * from "./backup"
|
||||||
export * from "./datasource"
|
export * from "./datasource"
|
||||||
export * from "./row"
|
|
||||||
export * from "./view"
|
export * from "./view"
|
||||||
export * from "./rows"
|
export * from "./rows"
|
||||||
export * from "./table"
|
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 { SearchFilters } from "../../../../sdk"
|
||||||
import { Row } from "../../../../documents"
|
import { Row } from "../../../../documents"
|
||||||
import { SortOrder } from "../../../../api/web/pagination"
|
import { SortOrder } from "../../pagination"
|
||||||
import { ReadStream } from "fs"
|
import { ReadStream } from "fs"
|
||||||
|
import stream from "node:stream"
|
||||||
|
|
||||||
export * from "./search"
|
export * from "./search"
|
||||||
|
|
||||||
|
export interface FetchEnrichedRowResponse extends Row {}
|
||||||
|
|
||||||
|
export type FetchRowsResponse = Row[]
|
||||||
|
|
||||||
export interface SaveRowRequest extends Row {}
|
export interface SaveRowRequest extends Row {}
|
||||||
|
export interface SaveRowResponse extends Row {}
|
||||||
|
|
||||||
export interface PatchRowRequest extends Row {
|
export interface PatchRowRequest extends Row {
|
||||||
_id: string
|
_id: string
|
||||||
|
@ -26,3 +32,23 @@ export interface ExportRowsRequest {
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ExportRowsResponse = ReadStream
|
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