Types
This commit is contained in:
parent
21b9bf36fd
commit
9371f9913e
|
@ -15,6 +15,7 @@ import {
|
||||||
Table,
|
Table,
|
||||||
TableSchema,
|
TableSchema,
|
||||||
SupportedSqlTypes,
|
SupportedSqlTypes,
|
||||||
|
JsonFieldSubType,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import { DatabaseName, getDatasource } from "../../../integrations/tests/utils"
|
import { DatabaseName, getDatasource } from "../../../integrations/tests/utils"
|
||||||
import { tableForDatasource } from "../../../tests/utilities/structures"
|
import { tableForDatasource } from "../../../tests/utilities/structures"
|
||||||
|
@ -288,7 +289,10 @@ describe("/datasources", () => {
|
||||||
name: "options",
|
name: "options",
|
||||||
type: FieldType.OPTIONS,
|
type: FieldType.OPTIONS,
|
||||||
constraints: {
|
constraints: {
|
||||||
presence: { allowEmpty: false },
|
presence: {
|
||||||
|
allowEmpty: false,
|
||||||
|
},
|
||||||
|
inclusion: [],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
[FieldType.NUMBER]: {
|
[FieldType.NUMBER]: {
|
||||||
|
@ -302,6 +306,10 @@ describe("/datasources", () => {
|
||||||
[FieldType.ARRAY]: {
|
[FieldType.ARRAY]: {
|
||||||
name: "array",
|
name: "array",
|
||||||
type: FieldType.ARRAY,
|
type: FieldType.ARRAY,
|
||||||
|
constraints: {
|
||||||
|
type: JsonFieldSubType.ARRAY,
|
||||||
|
inclusion: [],
|
||||||
|
},
|
||||||
},
|
},
|
||||||
[FieldType.DATETIME]: {
|
[FieldType.DATETIME]: {
|
||||||
name: "datetime",
|
name: "datetime",
|
||||||
|
|
|
@ -32,6 +32,7 @@ import {
|
||||||
TableSourceType,
|
TableSourceType,
|
||||||
UpdatedRowEventEmitter,
|
UpdatedRowEventEmitter,
|
||||||
TableSchema,
|
TableSchema,
|
||||||
|
JsonFieldSubType,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import { generator, mocks } from "@budibase/backend-core/tests"
|
import { generator, mocks } from "@budibase/backend-core/tests"
|
||||||
import _, { merge } from "lodash"
|
import _, { merge } from "lodash"
|
||||||
|
@ -103,6 +104,7 @@ describe.each([
|
||||||
const defaultSchema: TableSchema = {
|
const defaultSchema: TableSchema = {
|
||||||
id: {
|
id: {
|
||||||
type: FieldType.AUTO,
|
type: FieldType.AUTO,
|
||||||
|
subtype: AutoFieldSubType.AUTO_ID,
|
||||||
name: "id",
|
name: "id",
|
||||||
autocolumn: true,
|
autocolumn: true,
|
||||||
constraints: {
|
constraints: {
|
||||||
|
@ -384,7 +386,7 @@ describe.each([
|
||||||
const arrayField: FieldSchema = {
|
const arrayField: FieldSchema = {
|
||||||
type: FieldType.ARRAY,
|
type: FieldType.ARRAY,
|
||||||
constraints: {
|
constraints: {
|
||||||
type: "array",
|
type: JsonFieldSubType.ARRAY,
|
||||||
presence: false,
|
presence: false,
|
||||||
inclusion: ["One", "Two", "Three"],
|
inclusion: ["One", "Two", "Three"],
|
||||||
},
|
},
|
||||||
|
|
|
@ -20,6 +20,7 @@ import {
|
||||||
Datasource,
|
Datasource,
|
||||||
EmptyFilterOption,
|
EmptyFilterOption,
|
||||||
FieldType,
|
FieldType,
|
||||||
|
JsonFieldSubType,
|
||||||
RelationshipType,
|
RelationshipType,
|
||||||
Row,
|
Row,
|
||||||
RowSearchParams,
|
RowSearchParams,
|
||||||
|
@ -1494,7 +1495,10 @@ describe.each([
|
||||||
numbers: {
|
numbers: {
|
||||||
name: "numbers",
|
name: "numbers",
|
||||||
type: FieldType.ARRAY,
|
type: FieldType.ARRAY,
|
||||||
constraints: { inclusion: ["one", "two", "three"] },
|
constraints: {
|
||||||
|
type: JsonFieldSubType.ARRAY,
|
||||||
|
inclusion: ["one", "two", "three"],
|
||||||
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
await createRows([{ numbers: ["one", "two"] }, { numbers: ["three"] }])
|
await createRows([{ numbers: ["one", "two"] }, { numbers: ["three"] }])
|
||||||
|
|
|
@ -398,6 +398,7 @@ describe.each([
|
||||||
name: "auto",
|
name: "auto",
|
||||||
autocolumn: true,
|
autocolumn: true,
|
||||||
type: FieldType.AUTO,
|
type: FieldType.AUTO,
|
||||||
|
subtype: AutoFieldSubType.AUTO_ID,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -19,6 +19,7 @@ import {
|
||||||
ViewV2,
|
ViewV2,
|
||||||
SearchResponse,
|
SearchResponse,
|
||||||
BasicOperator,
|
BasicOperator,
|
||||||
|
AutoFieldSubType,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import { generator, mocks } from "@budibase/backend-core/tests"
|
import { generator, mocks } from "@budibase/backend-core/tests"
|
||||||
import { DatabaseName, getDatasource } from "../../../integrations/tests/utils"
|
import { DatabaseName, getDatasource } from "../../../integrations/tests/utils"
|
||||||
|
@ -57,6 +58,7 @@ describe.each([
|
||||||
schema: {
|
schema: {
|
||||||
id: {
|
id: {
|
||||||
type: FieldType.AUTO,
|
type: FieldType.AUTO,
|
||||||
|
subtype: AutoFieldSubType.AUTO_ID,
|
||||||
name: "id",
|
name: "id",
|
||||||
autocolumn: true,
|
autocolumn: true,
|
||||||
constraints: {
|
constraints: {
|
||||||
|
@ -242,6 +244,7 @@ describe.each([
|
||||||
id: {
|
id: {
|
||||||
name: "id",
|
name: "id",
|
||||||
type: FieldType.AUTO,
|
type: FieldType.AUTO,
|
||||||
|
subtype: AutoFieldSubType.AUTO_ID,
|
||||||
autocolumn: true,
|
autocolumn: true,
|
||||||
visible: true,
|
visible: true,
|
||||||
},
|
},
|
||||||
|
@ -1556,6 +1559,7 @@ describe.each([
|
||||||
id: {
|
id: {
|
||||||
name: "id",
|
name: "id",
|
||||||
type: FieldType.AUTO,
|
type: FieldType.AUTO,
|
||||||
|
subtype: AutoFieldSubType.AUTO_ID,
|
||||||
autocolumn: true,
|
autocolumn: true,
|
||||||
},
|
},
|
||||||
name: {
|
name: {
|
||||||
|
|
|
@ -17,6 +17,7 @@ import {
|
||||||
AutoFieldSubType,
|
AutoFieldSubType,
|
||||||
Datasource,
|
Datasource,
|
||||||
FieldType,
|
FieldType,
|
||||||
|
JsonFieldSubType,
|
||||||
RelationshipType,
|
RelationshipType,
|
||||||
Row,
|
Row,
|
||||||
SourceName,
|
SourceName,
|
||||||
|
@ -131,7 +132,7 @@ export const DEFAULT_INVENTORY_TABLE_SCHEMA: Table = {
|
||||||
"Item Tags": {
|
"Item Tags": {
|
||||||
type: FieldType.ARRAY,
|
type: FieldType.ARRAY,
|
||||||
constraints: {
|
constraints: {
|
||||||
type: FieldType.ARRAY,
|
type: JsonFieldSubType.ARRAY,
|
||||||
presence: {
|
presence: {
|
||||||
allowEmpty: false,
|
allowEmpty: false,
|
||||||
},
|
},
|
||||||
|
@ -153,7 +154,7 @@ export const DEFAULT_INVENTORY_TABLE_SCHEMA: Table = {
|
||||||
Status: {
|
Status: {
|
||||||
type: FieldType.ARRAY,
|
type: FieldType.ARRAY,
|
||||||
constraints: {
|
constraints: {
|
||||||
type: FieldType.ARRAY,
|
type: JsonFieldSubType.ARRAY,
|
||||||
presence: {
|
presence: {
|
||||||
allowEmpty: false,
|
allowEmpty: false,
|
||||||
},
|
},
|
||||||
|
@ -291,7 +292,7 @@ export const DEFAULT_EMPLOYEE_TABLE_SCHEMA: Table = {
|
||||||
"Employee Level": {
|
"Employee Level": {
|
||||||
type: FieldType.ARRAY,
|
type: FieldType.ARRAY,
|
||||||
constraints: {
|
constraints: {
|
||||||
type: FieldType.ARRAY,
|
type: JsonFieldSubType.ARRAY,
|
||||||
presence: false,
|
presence: false,
|
||||||
inclusion: ["Manager", "Junior", "Senior", "Apprentice", "Contractor"],
|
inclusion: ["Manager", "Junior", "Senior", "Apprentice", "Contractor"],
|
||||||
},
|
},
|
||||||
|
@ -535,7 +536,7 @@ export const DEFAULT_EXPENSES_TABLE_SCHEMA: Table = {
|
||||||
"Expense Tags": {
|
"Expense Tags": {
|
||||||
type: FieldType.ARRAY,
|
type: FieldType.ARRAY,
|
||||||
constraints: {
|
constraints: {
|
||||||
type: FieldType.ARRAY,
|
type: JsonFieldSubType.ARRAY,
|
||||||
presence: {
|
presence: {
|
||||||
allowEmpty: false,
|
allowEmpty: false,
|
||||||
},
|
},
|
||||||
|
|
|
@ -150,22 +150,28 @@ export function generateColumnDefinition(config: {
|
||||||
}).internal
|
}).internal
|
||||||
}
|
}
|
||||||
|
|
||||||
const constraints: {
|
let schema: FieldSchema
|
||||||
presence: boolean
|
|
||||||
inclusion?: string[]
|
|
||||||
} = {
|
|
||||||
presence,
|
|
||||||
}
|
|
||||||
if (foundType === FieldType.OPTIONS) {
|
if (foundType === FieldType.OPTIONS) {
|
||||||
constraints.inclusion = options
|
schema = {
|
||||||
}
|
type: foundType,
|
||||||
|
externalType,
|
||||||
const schema: FieldSchema = {
|
autocolumn,
|
||||||
type: foundType,
|
name,
|
||||||
externalType,
|
constraints: {
|
||||||
autocolumn,
|
presence,
|
||||||
name,
|
inclusion: options!,
|
||||||
constraints,
|
},
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
schema = {
|
||||||
|
type: foundType,
|
||||||
|
externalType,
|
||||||
|
autocolumn,
|
||||||
|
name,
|
||||||
|
constraints: {
|
||||||
|
presence,
|
||||||
|
},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (schema.type === FieldType.DATETIME) {
|
if (schema.type === FieldType.DATETIME) {
|
||||||
schema.dateOnly = SQL_DATE_ONLY_TYPES.includes(lowerCaseType)
|
schema.dateOnly = SQL_DATE_ONLY_TYPES.includes(lowerCaseType)
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
import { Datasource, FieldType, Row, Table } from "@budibase/types"
|
import {
|
||||||
|
AutoFieldSubType,
|
||||||
|
Datasource,
|
||||||
|
FieldType,
|
||||||
|
Row,
|
||||||
|
Table,
|
||||||
|
} from "@budibase/types"
|
||||||
|
|
||||||
import TestConfiguration from "../../../../../tests/utilities/TestConfiguration"
|
import TestConfiguration from "../../../../../tests/utilities/TestConfiguration"
|
||||||
import { search } from "../../../../../sdk/app/rows/search"
|
import { search } from "../../../../../sdk/app/rows/search"
|
||||||
|
@ -56,6 +62,7 @@ describe.each([
|
||||||
id: {
|
id: {
|
||||||
name: "id",
|
name: "id",
|
||||||
type: FieldType.AUTO,
|
type: FieldType.AUTO,
|
||||||
|
subtype: AutoFieldSubType.AUTO_ID,
|
||||||
autocolumn: true,
|
autocolumn: true,
|
||||||
},
|
},
|
||||||
name: {
|
name: {
|
||||||
|
|
Loading…
Reference in New Issue