1
0
Fork 0
mirror of synced 2024-09-20 11:27:56 +12:00

Merge branch 'test-oracle' of github.com:budibase/budibase into test-oracle

This commit is contained in:
Sam Rose 2024-07-31 12:00:59 +01:00
commit d4ddfb4de2
No known key found for this signature in database
12 changed files with 111 additions and 36 deletions

View file

@ -14,16 +14,20 @@ import { events, HTTPError } from "@budibase/backend-core"
import {
BulkImportRequest,
BulkImportResponse,
CsvToJsonRequest,
CsvToJsonResponse,
FetchTablesResponse,
MigrateRequest,
MigrateResponse,
Row,
SaveTableRequest,
SaveTableResponse,
Table,
TableResponse,
TableSourceType,
UserCtx,
ValidateNewTableImportRequest,
ValidateTableImportRequest,
ValidateTableImportResponse,
} from "@budibase/types"
import sdk from "../../../sdk"
import { jsonFromCsvString } from "../../../utilities/csv"
@ -144,7 +148,9 @@ export async function bulkImport(
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 result = await jsonFromCsvString(csvString)
@ -153,8 +159,10 @@ export async function csvToJson(ctx: UserCtx) {
ctx.body = result
}
export async function validateNewTableImport(ctx: UserCtx) {
const { rows, schema }: { rows: unknown; schema: unknown } = ctx.request.body
export async function validateNewTableImport(
ctx: UserCtx<ValidateNewTableImportRequest, ValidateTableImportResponse>
) {
const { rows, schema } = ctx.request.body
if (isRows(rows) && isSchema(schema)) {
ctx.status = 200
@ -164,8 +172,10 @@ export async function validateNewTableImport(ctx: UserCtx) {
}
}
export async function validateExistingTableImport(ctx: UserCtx) {
const { rows, tableId }: { rows: Row[]; tableId?: string } = ctx.request.body
export async function validateExistingTableImport(
ctx: UserCtx<ValidateTableImportRequest, ValidateTableImportResponse>
) {
const { rows, tableId } = ctx.request.body
let schema = null
if (tableId) {

View file

@ -15,6 +15,7 @@ import {
Table,
TableSchema,
SupportedSqlTypes,
JsonFieldSubType,
} from "@budibase/types"
import { DatabaseName, getDatasource } from "../../../integrations/tests/utils"
import { tableForDatasource } from "../../../tests/utilities/structures"
@ -288,7 +289,10 @@ describe("/datasources", () => {
name: "options",
type: FieldType.OPTIONS,
constraints: {
presence: { allowEmpty: false },
presence: {
allowEmpty: false,
},
inclusion: [],
},
},
[FieldType.NUMBER]: {
@ -302,6 +306,10 @@ describe("/datasources", () => {
[FieldType.ARRAY]: {
name: "array",
type: FieldType.ARRAY,
constraints: {
type: JsonFieldSubType.ARRAY,
inclusion: [],
},
},
[FieldType.DATETIME]: {
name: "datetime",

View file

@ -32,6 +32,7 @@ import {
TableSourceType,
UpdatedRowEventEmitter,
TableSchema,
JsonFieldSubType,
} from "@budibase/types"
import { generator, mocks } from "@budibase/backend-core/tests"
import _, { merge } from "lodash"
@ -104,7 +105,7 @@ describe.each([
): SaveTableRequest {
const defaultSchema: TableSchema = {
id: {
type: FieldType.AUTO,
type: FieldType.NUMBER,
name: "id",
autocolumn: true,
constraints: {
@ -387,7 +388,7 @@ describe.each([
const arrayField: FieldSchema = {
type: FieldType.ARRAY,
constraints: {
type: "array",
type: JsonFieldSubType.ARRAY,
presence: false,
inclusion: ["One", "Two", "Three"],
},

View file

@ -20,6 +20,7 @@ import {
Datasource,
EmptyFilterOption,
FieldType,
JsonFieldSubType,
RelationshipType,
Row,
RowSearchParams,
@ -1495,7 +1496,10 @@ describe.each([
numbers: {
name: "numbers",
type: FieldType.ARRAY,
constraints: { inclusion: ["one", "two", "three"] },
constraints: {
type: JsonFieldSubType.ARRAY,
inclusion: ["one", "two", "three"],
},
},
})
await createRows([{ numbers: ["one", "two"] }, { numbers: ["three"] }])

View file

@ -405,6 +405,7 @@ describe.each([
name: "auto",
autocolumn: true,
type: FieldType.AUTO,
subtype: AutoFieldSubType.AUTO_ID,
},
},
},

View file

@ -56,7 +56,7 @@ describe.each([
primary: ["id"],
schema: {
id: {
type: FieldType.AUTO,
type: FieldType.NUMBER,
name: "id",
autocolumn: true,
constraints: {
@ -241,7 +241,7 @@ describe.each([
schema: {
id: {
name: "id",
type: FieldType.AUTO,
type: FieldType.NUMBER,
autocolumn: true,
visible: true,
},
@ -1555,7 +1555,7 @@ describe.each([
schema: {
id: {
name: "id",
type: FieldType.AUTO,
type: FieldType.NUMBER,
autocolumn: true,
},
name: {

View file

@ -17,6 +17,7 @@ import {
AutoFieldSubType,
Datasource,
FieldType,
JsonFieldSubType,
RelationshipType,
Row,
SourceName,
@ -131,7 +132,7 @@ export const DEFAULT_INVENTORY_TABLE_SCHEMA: Table = {
"Item Tags": {
type: FieldType.ARRAY,
constraints: {
type: FieldType.ARRAY,
type: JsonFieldSubType.ARRAY,
presence: {
allowEmpty: false,
},
@ -153,7 +154,7 @@ export const DEFAULT_INVENTORY_TABLE_SCHEMA: Table = {
Status: {
type: FieldType.ARRAY,
constraints: {
type: FieldType.ARRAY,
type: JsonFieldSubType.ARRAY,
presence: {
allowEmpty: false,
},
@ -291,7 +292,7 @@ export const DEFAULT_EMPLOYEE_TABLE_SCHEMA: Table = {
"Employee Level": {
type: FieldType.ARRAY,
constraints: {
type: FieldType.ARRAY,
type: JsonFieldSubType.ARRAY,
presence: false,
inclusion: ["Manager", "Junior", "Senior", "Apprentice", "Contractor"],
},
@ -535,7 +536,7 @@ export const DEFAULT_EXPENSES_TABLE_SCHEMA: Table = {
"Expense Tags": {
type: FieldType.ARRAY,
constraints: {
type: FieldType.ARRAY,
type: JsonFieldSubType.ARRAY,
presence: {
allowEmpty: false,
},

View file

@ -150,22 +150,28 @@ export function generateColumnDefinition(config: {
}).internal
}
const constraints: {
presence: boolean
inclusion?: string[]
} = {
presence,
}
let schema: FieldSchema
if (foundType === FieldType.OPTIONS) {
constraints.inclusion = options
}
const schema: FieldSchema = {
type: foundType,
externalType,
autocolumn,
name,
constraints,
schema = {
type: foundType,
externalType,
autocolumn,
name,
constraints: {
presence,
inclusion: options!,
},
}
} else {
schema = {
type: foundType,
externalType,
autocolumn,
name,
constraints: {
presence,
},
}
}
if (schema.type === FieldType.DATETIME) {
schema.dateOnly = SQL_DATE_ONLY_TYPES.includes(lowerCaseType)

View file

@ -55,7 +55,7 @@ describe.each([
schema: {
id: {
name: "id",
type: FieldType.AUTO,
type: FieldType.NUMBER,
autocolumn: true,
},
name: {

View file

@ -37,7 +37,7 @@ export interface PaginatedSearchRowResponse
PaginationResponse {}
export interface ExportRowsRequest {
rows: string[]
rows?: string[]
columns?: string[]
query?: SearchFilters
sort?: string

View file

@ -1,4 +1,4 @@
import { Row, Table, TableRequest, View } from "../../../documents"
import { Row, Table, TableRequest, TableSchema, View } from "../../../documents"
import { ViewV2Enriched } from "../../../sdk"
export type TableViewsResponse = { [key: string]: View | ViewV2Enriched }
@ -32,3 +32,28 @@ export interface MigrateRequest {
export interface MigrateResponse {
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[]

View file

@ -64,7 +64,7 @@ export interface AutoColumnFieldMetadata
extends Omit<BaseFieldSchema, "subtype"> {
type: FieldType.AUTO
autocolumn: true
subtype?: AutoFieldSubType
subtype: AutoFieldSubType
lastID?: number
// if the column was turned to an auto-column for SQL, explains why (primary, foreign etc)
autoReason?: AutoReason
@ -157,6 +157,21 @@ export interface FieldConstraints {
}
}
export interface OptionsFieldMetadata extends BaseFieldSchema {
type: FieldType.OPTIONS
constraints: FieldConstraints & {
inclusion: string[]
}
}
export interface ArrayFieldMetadata extends BaseFieldSchema {
type: FieldType.ARRAY
constraints: FieldConstraints & {
type: JsonFieldSubType.ARRAY
inclusion: string[]
}
}
interface BaseFieldSchema extends UIFieldMetadata {
type: FieldType
name: string
@ -182,6 +197,8 @@ interface OtherFieldMetadata extends BaseFieldSchema {
| FieldType.BB_REFERENCE_SINGLE
| FieldType.ATTACHMENTS
| FieldType.STRING
| FieldType.ARRAY
| FieldType.OPTIONS
>
}
@ -198,6 +215,8 @@ export type FieldSchema =
| JsonFieldMetadata
| AttachmentFieldMetadata
| BBReferenceSingleFieldMetadata
| ArrayFieldMetadata
| OptionsFieldMetadata
export interface TableSchema {
[key: string]: FieldSchema