Fix more types
This commit is contained in:
parent
6c328109b6
commit
1f1ebc82e5
|
@ -6,6 +6,8 @@ import * as setup from "./utilities"
|
||||||
import { context, InternalTable, roles, tenancy } from "@budibase/backend-core"
|
import { context, InternalTable, roles, tenancy } from "@budibase/backend-core"
|
||||||
import { quotas } from "@budibase/pro"
|
import { quotas } from "@budibase/pro"
|
||||||
import {
|
import {
|
||||||
|
AutoFieldSubTypes,
|
||||||
|
FieldSchema,
|
||||||
FieldType,
|
FieldType,
|
||||||
FieldTypeSubtypes,
|
FieldTypeSubtypes,
|
||||||
MonthlyQuotaName,
|
MonthlyQuotaName,
|
||||||
|
@ -171,7 +173,7 @@ describe.each([
|
||||||
"Row ID": {
|
"Row ID": {
|
||||||
name: "Row ID",
|
name: "Row ID",
|
||||||
type: FieldType.NUMBER,
|
type: FieldType.NUMBER,
|
||||||
subtype: "autoID",
|
subtype: AutoFieldSubTypes.AUTO_ID,
|
||||||
icon: "ri-magic-line",
|
icon: "ri-magic-line",
|
||||||
autocolumn: true,
|
autocolumn: true,
|
||||||
constraints: {
|
constraints: {
|
||||||
|
@ -272,27 +274,27 @@ describe.each([
|
||||||
|
|
||||||
isInternal &&
|
isInternal &&
|
||||||
it("row values are coerced", async () => {
|
it("row values are coerced", async () => {
|
||||||
const str = {
|
const str: FieldSchema = {
|
||||||
type: FieldType.STRING,
|
type: FieldType.STRING,
|
||||||
name: "str",
|
name: "str",
|
||||||
constraints: { type: "string", presence: false },
|
constraints: { type: "string", presence: false },
|
||||||
}
|
}
|
||||||
const attachment = {
|
const attachment: FieldSchema = {
|
||||||
type: FieldType.ATTACHMENT,
|
type: FieldType.ATTACHMENT,
|
||||||
name: "attachment",
|
name: "attachment",
|
||||||
constraints: { type: "array", presence: false },
|
constraints: { type: "array", presence: false },
|
||||||
}
|
}
|
||||||
const bool = {
|
const bool: FieldSchema = {
|
||||||
type: FieldType.BOOLEAN,
|
type: FieldType.BOOLEAN,
|
||||||
name: "boolean",
|
name: "boolean",
|
||||||
constraints: { type: "boolean", presence: false },
|
constraints: { type: "boolean", presence: false },
|
||||||
}
|
}
|
||||||
const number = {
|
const number: FieldSchema = {
|
||||||
type: FieldType.NUMBER,
|
type: FieldType.NUMBER,
|
||||||
name: "str",
|
name: "str",
|
||||||
constraints: { type: "number", presence: false },
|
constraints: { type: "number", presence: false },
|
||||||
}
|
}
|
||||||
const datetime = {
|
const datetime: FieldSchema = {
|
||||||
type: FieldType.DATETIME,
|
type: FieldType.DATETIME,
|
||||||
name: "datetime",
|
name: "datetime",
|
||||||
constraints: {
|
constraints: {
|
||||||
|
@ -301,7 +303,7 @@ describe.each([
|
||||||
datetime: { earliest: "", latest: "" },
|
datetime: { earliest: "", latest: "" },
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
const arrayField = {
|
const arrayField: FieldSchema = {
|
||||||
type: FieldType.ARRAY,
|
type: FieldType.ARRAY,
|
||||||
constraints: {
|
constraints: {
|
||||||
type: "array",
|
type: "array",
|
||||||
|
@ -311,8 +313,7 @@ describe.each([
|
||||||
name: "Sample Tags",
|
name: "Sample Tags",
|
||||||
sortable: false,
|
sortable: false,
|
||||||
}
|
}
|
||||||
const optsField = {
|
const optsField: FieldSchema = {
|
||||||
fieldName: "Sample Opts",
|
|
||||||
name: "Sample Opts",
|
name: "Sample Opts",
|
||||||
type: FieldType.OPTIONS,
|
type: FieldType.OPTIONS,
|
||||||
constraints: {
|
constraints: {
|
||||||
|
@ -1534,7 +1535,7 @@ describe.each([
|
||||||
describe.each([
|
describe.each([
|
||||||
[
|
[
|
||||||
"relationship fields",
|
"relationship fields",
|
||||||
() => ({
|
(): Record<string, FieldSchema> => ({
|
||||||
user: {
|
user: {
|
||||||
name: "user",
|
name: "user",
|
||||||
relationshipType: RelationshipType.ONE_TO_MANY,
|
relationshipType: RelationshipType.ONE_TO_MANY,
|
||||||
|
@ -1563,19 +1564,19 @@ describe.each([
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"bb reference fields",
|
"bb reference fields",
|
||||||
() => ({
|
(): Record<string, FieldSchema> => ({
|
||||||
user: {
|
user: {
|
||||||
name: "user",
|
name: "user",
|
||||||
relationshipType: RelationshipType.ONE_TO_MANY,
|
relationshipType: RelationshipType.ONE_TO_MANY,
|
||||||
type: FieldType.BB_REFERENCE,
|
type: FieldType.BB_REFERENCE,
|
||||||
subtype: FieldTypeSubtypes.BB_REFERENCE.USER,
|
subtype: FieldTypeSubtypes.BB_REFERENCE.USER,
|
||||||
},
|
} as any,
|
||||||
users: {
|
users: {
|
||||||
name: "users",
|
name: "users",
|
||||||
type: FieldType.BB_REFERENCE,
|
type: FieldType.BB_REFERENCE,
|
||||||
subtype: FieldTypeSubtypes.BB_REFERENCE.USER,
|
subtype: FieldTypeSubtypes.BB_REFERENCE.USER,
|
||||||
relationshipType: RelationshipType.MANY_TO_MANY,
|
relationshipType: RelationshipType.MANY_TO_MANY,
|
||||||
},
|
} as any,
|
||||||
}),
|
}),
|
||||||
() => config.createUser(),
|
() => config.createUser(),
|
||||||
(row: Row) => ({
|
(row: Row) => ({
|
||||||
|
|
|
@ -1,6 +1,11 @@
|
||||||
import { generator } from "@budibase/backend-core/tests"
|
import { generator } from "@budibase/backend-core/tests"
|
||||||
import { events, context } from "@budibase/backend-core"
|
import { events, context } from "@budibase/backend-core"
|
||||||
import { FieldType, Table, ViewCalculation } from "@budibase/types"
|
import {
|
||||||
|
FieldType,
|
||||||
|
RelationshipType,
|
||||||
|
Table,
|
||||||
|
ViewCalculation,
|
||||||
|
} from "@budibase/types"
|
||||||
import { checkBuilderEndpoint } from "./utilities/TestFunctions"
|
import { checkBuilderEndpoint } from "./utilities/TestFunctions"
|
||||||
import * as setup from "./utilities"
|
import * as setup from "./utilities"
|
||||||
const { basicTable } = setup.structures
|
const { basicTable } = setup.structures
|
||||||
|
@ -352,6 +357,7 @@ describe("/tables", () => {
|
||||||
},
|
},
|
||||||
TestTable: {
|
TestTable: {
|
||||||
type: FieldType.LINK,
|
type: FieldType.LINK,
|
||||||
|
relationshipType: RelationshipType.ONE_TO_MANY,
|
||||||
name: "TestTable",
|
name: "TestTable",
|
||||||
fieldName: "TestTable",
|
fieldName: "TestTable",
|
||||||
tableId: testTable._id!,
|
tableId: testTable._id!,
|
||||||
|
|
|
@ -111,7 +111,7 @@ describe("postgres integrations", () => {
|
||||||
fieldName: oneToManyRelationshipInfo.fieldName,
|
fieldName: oneToManyRelationshipInfo.fieldName,
|
||||||
name: "oneToManyRelation",
|
name: "oneToManyRelation",
|
||||||
relationshipType: RelationshipType.ONE_TO_MANY,
|
relationshipType: RelationshipType.ONE_TO_MANY,
|
||||||
tableId: oneToManyRelationshipInfo.table._id,
|
tableId: oneToManyRelationshipInfo.table._id!,
|
||||||
main: true,
|
main: true,
|
||||||
},
|
},
|
||||||
manyToOneRelation: {
|
manyToOneRelation: {
|
||||||
|
@ -122,7 +122,7 @@ describe("postgres integrations", () => {
|
||||||
fieldName: manyToOneRelationshipInfo.fieldName,
|
fieldName: manyToOneRelationshipInfo.fieldName,
|
||||||
name: "manyToOneRelation",
|
name: "manyToOneRelation",
|
||||||
relationshipType: RelationshipType.MANY_TO_ONE,
|
relationshipType: RelationshipType.MANY_TO_ONE,
|
||||||
tableId: manyToOneRelationshipInfo.table._id,
|
tableId: manyToOneRelationshipInfo.table._id!,
|
||||||
main: true,
|
main: true,
|
||||||
},
|
},
|
||||||
manyToManyRelation: {
|
manyToManyRelation: {
|
||||||
|
@ -133,7 +133,7 @@ describe("postgres integrations", () => {
|
||||||
fieldName: manyToManyRelationshipInfo.fieldName,
|
fieldName: manyToManyRelationshipInfo.fieldName,
|
||||||
name: "manyToManyRelation",
|
name: "manyToManyRelation",
|
||||||
relationshipType: RelationshipType.MANY_TO_MANY,
|
relationshipType: RelationshipType.MANY_TO_MANY,
|
||||||
tableId: manyToManyRelationshipInfo.table._id,
|
tableId: manyToManyRelationshipInfo.table._id!,
|
||||||
main: true,
|
main: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -250,6 +250,7 @@ describe("postgres integrations", () => {
|
||||||
id: {
|
id: {
|
||||||
name: "id",
|
name: "id",
|
||||||
type: FieldType.AUTO,
|
type: FieldType.AUTO,
|
||||||
|
autocolumn: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
sourceId: postgresDatasource._id,
|
sourceId: postgresDatasource._id,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { populateExternalTableSchemas } from "../validation"
|
import { populateExternalTableSchemas } from "../validation"
|
||||||
import { cloneDeep } from "lodash/fp"
|
import { cloneDeep } from "lodash/fp"
|
||||||
import { Datasource, Table } from "@budibase/types"
|
import { AutoReason, Datasource, Table } from "@budibase/types"
|
||||||
import { isEqual } from "lodash"
|
import { isEqual } from "lodash"
|
||||||
|
|
||||||
const SCHEMA = {
|
const SCHEMA = {
|
||||||
|
@ -109,7 +109,7 @@ describe("validation and update of external table schemas", () => {
|
||||||
const response = populateExternalTableSchemas(cloneDeep(SCHEMA) as any)
|
const response = populateExternalTableSchemas(cloneDeep(SCHEMA) as any)
|
||||||
const foreignKey = getForeignKeyColumn(response)
|
const foreignKey = getForeignKeyColumn(response)
|
||||||
expect(foreignKey.autocolumn).toBe(true)
|
expect(foreignKey.autocolumn).toBe(true)
|
||||||
expect(foreignKey.autoReason).toBe("foreign_key")
|
expect(foreignKey.autoReason).toBe(AutoReason.FOREIGN_KEY)
|
||||||
noOtherTableChanges(response)
|
noOtherTableChanges(response)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -24,14 +24,14 @@ interface BaseRelationshipFieldMetadata extends BaseFieldSchema {
|
||||||
export interface ManyToManyRelationshipFieldMetadata
|
export interface ManyToManyRelationshipFieldMetadata
|
||||||
extends BaseRelationshipFieldMetadata {
|
extends BaseRelationshipFieldMetadata {
|
||||||
relationshipType: RelationshipType.MANY_TO_MANY
|
relationshipType: RelationshipType.MANY_TO_MANY
|
||||||
through: string
|
through?: string
|
||||||
throughFrom: string
|
throughFrom?: string
|
||||||
throughTo: string
|
throughTo?: string
|
||||||
}
|
}
|
||||||
export interface OneToManyRelationshipFieldMetadata
|
export interface OneToManyRelationshipFieldMetadata
|
||||||
extends BaseRelationshipFieldMetadata {
|
extends BaseRelationshipFieldMetadata {
|
||||||
relationshipType: RelationshipType.ONE_TO_MANY
|
relationshipType: RelationshipType.ONE_TO_MANY
|
||||||
foreignKey: string
|
foreignKey?: string
|
||||||
}
|
}
|
||||||
export interface ManyToOneRelationshipFieldMetadata
|
export interface ManyToOneRelationshipFieldMetadata
|
||||||
extends BaseRelationshipFieldMetadata {
|
extends BaseRelationshipFieldMetadata {
|
||||||
|
@ -46,7 +46,7 @@ export type RelationshipFieldMetadata =
|
||||||
export interface AutoColumnFieldMetadata extends BaseFieldSchema {
|
export interface AutoColumnFieldMetadata extends BaseFieldSchema {
|
||||||
type: FieldType.AUTO
|
type: FieldType.AUTO
|
||||||
autocolumn: true
|
autocolumn: true
|
||||||
subtype: AutoFieldSubTypes
|
subtype?: AutoFieldSubTypes
|
||||||
lastID?: number
|
lastID?: number
|
||||||
// if the column was turned to an auto-column for SQL, explains why (primary, foreign etc)
|
// if the column was turned to an auto-column for SQL, explains why (primary, foreign etc)
|
||||||
autoReason?: AutoReason
|
autoReason?: AutoReason
|
||||||
|
@ -121,7 +121,7 @@ interface BaseFieldSchema extends UIFieldMetadata {
|
||||||
subtype?: string
|
subtype?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
interface OtherFieldMetadata extends BaseFieldSchema {
|
export interface OtherFieldMetadata extends BaseFieldSchema {
|
||||||
type: Exclude<
|
type: Exclude<
|
||||||
FieldType,
|
FieldType,
|
||||||
| FieldType.DATETIME
|
| FieldType.DATETIME
|
||||||
|
|
Loading…
Reference in New Issue