Add api types
This commit is contained in:
parent
7d17717895
commit
21b9bf36fd
|
@ -14,16 +14,20 @@ import { events, HTTPError } from "@budibase/backend-core"
|
||||||
import {
|
import {
|
||||||
BulkImportRequest,
|
BulkImportRequest,
|
||||||
BulkImportResponse,
|
BulkImportResponse,
|
||||||
|
CsvToJsonRequest,
|
||||||
|
CsvToJsonResponse,
|
||||||
FetchTablesResponse,
|
FetchTablesResponse,
|
||||||
MigrateRequest,
|
MigrateRequest,
|
||||||
MigrateResponse,
|
MigrateResponse,
|
||||||
Row,
|
|
||||||
SaveTableRequest,
|
SaveTableRequest,
|
||||||
SaveTableResponse,
|
SaveTableResponse,
|
||||||
Table,
|
Table,
|
||||||
TableResponse,
|
TableResponse,
|
||||||
TableSourceType,
|
TableSourceType,
|
||||||
UserCtx,
|
UserCtx,
|
||||||
|
ValidateNewTableImportRequest,
|
||||||
|
ValidateTableImportRequest,
|
||||||
|
ValidateTableImportResponse,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import sdk from "../../../sdk"
|
import sdk from "../../../sdk"
|
||||||
import { jsonFromCsvString } from "../../../utilities/csv"
|
import { jsonFromCsvString } from "../../../utilities/csv"
|
||||||
|
@ -144,7 +148,9 @@ export async function bulkImport(
|
||||||
ctx.body = { message: `Bulk rows created.` }
|
ctx.body = { message: `Bulk rows created.` }
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function csvToJson(ctx: UserCtx) {
|
export async function csvToJson(
|
||||||
|
ctx: UserCtx<CsvToJsonRequest, CsvToJsonResponse>
|
||||||
|
) {
|
||||||
const { csvString } = ctx.request.body
|
const { csvString } = ctx.request.body
|
||||||
|
|
||||||
const result = await jsonFromCsvString(csvString)
|
const result = await jsonFromCsvString(csvString)
|
||||||
|
@ -153,8 +159,10 @@ export async function csvToJson(ctx: UserCtx) {
|
||||||
ctx.body = result
|
ctx.body = result
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function validateNewTableImport(ctx: UserCtx) {
|
export async function validateNewTableImport(
|
||||||
const { rows, schema }: { rows: unknown; schema: unknown } = ctx.request.body
|
ctx: UserCtx<ValidateNewTableImportRequest, ValidateTableImportResponse>
|
||||||
|
) {
|
||||||
|
const { rows, schema } = ctx.request.body
|
||||||
|
|
||||||
if (isRows(rows) && isSchema(schema)) {
|
if (isRows(rows) && isSchema(schema)) {
|
||||||
ctx.status = 200
|
ctx.status = 200
|
||||||
|
@ -164,8 +172,10 @@ export async function validateNewTableImport(ctx: UserCtx) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function validateExistingTableImport(ctx: UserCtx) {
|
export async function validateExistingTableImport(
|
||||||
const { rows, tableId }: { rows: Row[]; tableId?: string } = ctx.request.body
|
ctx: UserCtx<ValidateTableImportRequest, ValidateTableImportResponse>
|
||||||
|
) {
|
||||||
|
const { rows, tableId } = ctx.request.body
|
||||||
|
|
||||||
let schema = null
|
let schema = null
|
||||||
if (tableId) {
|
if (tableId) {
|
||||||
|
|
|
@ -37,7 +37,7 @@ export interface PaginatedSearchRowResponse
|
||||||
PaginationResponse {}
|
PaginationResponse {}
|
||||||
|
|
||||||
export interface ExportRowsRequest {
|
export interface ExportRowsRequest {
|
||||||
rows: string[]
|
rows?: string[]
|
||||||
columns?: string[]
|
columns?: string[]
|
||||||
query?: SearchFilters
|
query?: SearchFilters
|
||||||
sort?: string
|
sort?: string
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { Row, Table, TableRequest, View } from "../../../documents"
|
import { Row, Table, TableRequest, TableSchema, View } from "../../../documents"
|
||||||
import { ViewV2Enriched } from "../../../sdk"
|
import { ViewV2Enriched } from "../../../sdk"
|
||||||
|
|
||||||
export type TableViewsResponse = { [key: string]: View | ViewV2Enriched }
|
export type TableViewsResponse = { [key: string]: View | ViewV2Enriched }
|
||||||
|
@ -32,3 +32,28 @@ export interface MigrateRequest {
|
||||||
export interface MigrateResponse {
|
export interface MigrateResponse {
|
||||||
message: string
|
message: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ValidateNewTableImportRequest {
|
||||||
|
rows: Row[]
|
||||||
|
schema: TableSchema
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ValidateTableImportRequest {
|
||||||
|
tableId?: string
|
||||||
|
rows: Row[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ValidateTableImportResponse {
|
||||||
|
schemaValidation: {
|
||||||
|
[field: string]: boolean
|
||||||
|
}
|
||||||
|
allValid: boolean
|
||||||
|
invalidColumns: Array<string>
|
||||||
|
errors: Record<string, string>
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CsvToJsonRequest {
|
||||||
|
csvString: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export type CsvToJsonResponse = any[]
|
||||||
|
|
Loading…
Reference in New Issue