Add BB_REFERENCE_SINGLE type
This commit is contained in:
parent
6166410d6e
commit
afdbf4cc42
|
@ -61,7 +61,8 @@ function generateSchema(
|
|||
case FieldType.BARCODEQR:
|
||||
schema.text(key)
|
||||
break
|
||||
case FieldType.BB_REFERENCE: {
|
||||
case FieldType.BB_REFERENCE:
|
||||
case FieldType.BB_REFERENCE_SINGLE: {
|
||||
const subtype = column.subtype
|
||||
switch (subtype) {
|
||||
case FieldSubtype.USER:
|
||||
|
@ -127,6 +128,8 @@ function generateSchema(
|
|||
.references(`${tableName}.${relatedPrimary}`)
|
||||
}
|
||||
break
|
||||
default:
|
||||
utils.unreachable(column.type)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -52,17 +52,30 @@ interface AuthTokenResponse {
|
|||
access_token: string
|
||||
}
|
||||
|
||||
const ALLOWED_TYPES = [
|
||||
FieldType.STRING,
|
||||
FieldType.FORMULA,
|
||||
FieldType.NUMBER,
|
||||
FieldType.LONGFORM,
|
||||
FieldType.DATETIME,
|
||||
FieldType.OPTIONS,
|
||||
FieldType.BOOLEAN,
|
||||
FieldType.BARCODEQR,
|
||||
FieldType.BB_REFERENCE,
|
||||
]
|
||||
const isTypeAllowed: Record<FieldType, boolean> = {
|
||||
[FieldType.STRING]: true,
|
||||
[FieldType.FORMULA]: true,
|
||||
[FieldType.NUMBER]: true,
|
||||
[FieldType.LONGFORM]: true,
|
||||
[FieldType.DATETIME]: true,
|
||||
[FieldType.OPTIONS]: true,
|
||||
[FieldType.BOOLEAN]: true,
|
||||
[FieldType.BARCODEQR]: true,
|
||||
[FieldType.BB_REFERENCE]: true,
|
||||
[FieldType.BB_REFERENCE_SINGLE]: true,
|
||||
[FieldType.ARRAY]: false,
|
||||
[FieldType.ATTACHMENTS]: false,
|
||||
[FieldType.ATTACHMENT_SINGLE]: false,
|
||||
[FieldType.LINK]: false,
|
||||
[FieldType.AUTO]: false,
|
||||
[FieldType.JSON]: false,
|
||||
[FieldType.INTERNAL]: false,
|
||||
[FieldType.BIGINT]: false,
|
||||
}
|
||||
|
||||
const ALLOWED_TYPES = Object.entries(isTypeAllowed)
|
||||
.filter(([_, allowed]) => allowed)
|
||||
.map(([type]) => type as FieldType)
|
||||
|
||||
const SCHEMA: Integration = {
|
||||
plus: true,
|
||||
|
|
|
@ -378,6 +378,7 @@ function copyExistingPropsOver(
|
|||
case FieldType.ATTACHMENT_SINGLE:
|
||||
case FieldType.JSON:
|
||||
case FieldType.BB_REFERENCE:
|
||||
case FieldType.BB_REFERENCE_SINGLE:
|
||||
shouldKeepSchema = keepIfType(FieldType.JSON, FieldType.STRING)
|
||||
break
|
||||
|
||||
|
|
|
@ -45,6 +45,7 @@ const FieldTypeMap: Record<FieldType, SQLiteType> = {
|
|||
[FieldType.BIGINT]: SQLiteType.TEXT,
|
||||
// TODO: consider the difference between multi-user and single user types (subtyping)
|
||||
[FieldType.BB_REFERENCE]: SQLiteType.TEXT,
|
||||
[FieldType.BB_REFERENCE_SINGLE]: SQLiteType.TEXT,
|
||||
}
|
||||
|
||||
function buildRelationshipDefinitions(
|
||||
|
|
|
@ -244,7 +244,8 @@ export async function outputProcessing<T extends Row[] | Row>(
|
|||
}
|
||||
} else if (
|
||||
!opts.skipBBReferences &&
|
||||
column.type == FieldType.BB_REFERENCE
|
||||
(column.type == FieldType.BB_REFERENCE ||
|
||||
column.type == FieldType.BB_REFERENCE_SINGLE)
|
||||
) {
|
||||
for (let row of enriched) {
|
||||
row[property] = await processOutputBBReferences(
|
||||
|
|
|
@ -92,7 +92,8 @@ export function validate(rows: Rows, schema: TableSchema): ValidationResults {
|
|||
) {
|
||||
results.schemaValidation[columnName] = false
|
||||
} else if (
|
||||
columnType === FieldType.BB_REFERENCE &&
|
||||
(columnType === FieldType.BB_REFERENCE ||
|
||||
columnType === FieldType.BB_REFERENCE_SINGLE) &&
|
||||
!isValidBBReference(columnData, columnSubtype)
|
||||
) {
|
||||
results.schemaValidation[columnName] = false
|
||||
|
|
|
@ -68,7 +68,11 @@ export const getValidOperatorsForType = (
|
|||
ops = numOps
|
||||
} else if (type === FieldType.FORMULA && formulaType === FormulaType.STATIC) {
|
||||
ops = stringOps.concat([Op.MoreThan, Op.LessThan])
|
||||
} else if (type === FieldType.BB_REFERENCE && subtype == FieldSubtype.USER) {
|
||||
} else if (
|
||||
(type === FieldType.BB_REFERENCE_SINGLE ||
|
||||
type === FieldType.BB_REFERENCE) &&
|
||||
subtype == FieldSubtype.USER
|
||||
) {
|
||||
ops = [Op.Equals, Op.NotEquals, Op.Empty, Op.NotEmpty, Op.In]
|
||||
} else if (type === FieldType.BB_REFERENCE && subtype == FieldSubtype.USERS) {
|
||||
ops = [Op.Contains, Op.NotContains, Op.ContainsAny, Op.Empty, Op.NotEmpty]
|
||||
|
|
|
@ -18,6 +18,7 @@ const allowDisplayColumnByType: Record<FieldType, boolean> = {
|
|||
[FieldType.LINK]: false,
|
||||
[FieldType.JSON]: false,
|
||||
[FieldType.BB_REFERENCE]: false,
|
||||
[FieldType.BB_REFERENCE_SINGLE]: false,
|
||||
}
|
||||
|
||||
const allowSortColumnByType: Record<FieldType, boolean> = {
|
||||
|
@ -39,6 +40,7 @@ const allowSortColumnByType: Record<FieldType, boolean> = {
|
|||
[FieldType.ARRAY]: false,
|
||||
[FieldType.LINK]: false,
|
||||
[FieldType.BB_REFERENCE]: false,
|
||||
[FieldType.BB_REFERENCE_SINGLE]: false,
|
||||
}
|
||||
|
||||
export function canBeDisplayColumn(type: FieldType): boolean {
|
||||
|
|
|
@ -107,6 +107,8 @@ export enum FieldType {
|
|||
* an array of resource IDs, the API will squash these down and validate them before saving the row.
|
||||
*/
|
||||
BB_REFERENCE = "bb_reference",
|
||||
// TODO
|
||||
BB_REFERENCE_SINGLE = "bb_reference_single",
|
||||
}
|
||||
|
||||
export interface RowAttachment {
|
||||
|
|
|
@ -112,6 +112,11 @@ export interface BBReferenceFieldMetadata
|
|||
subtype: FieldSubtype.USER | FieldSubtype.USERS
|
||||
relationshipType?: RelationshipType
|
||||
}
|
||||
export interface BBReferenceSingleFieldMetadata
|
||||
extends Omit<BaseFieldSchema, "subtype"> {
|
||||
type: FieldType.BB_REFERENCE_SINGLE
|
||||
subtype: FieldSubtype.USER | FieldSubtype.USERS
|
||||
}
|
||||
|
||||
export interface AttachmentFieldMetadata extends BaseFieldSchema {
|
||||
type: FieldType.ATTACHMENTS
|
||||
|
@ -163,6 +168,7 @@ interface OtherFieldMetadata extends BaseFieldSchema {
|
|||
| FieldType.NUMBER
|
||||
| FieldType.LONGFORM
|
||||
| FieldType.BB_REFERENCE
|
||||
| FieldType.BB_REFERENCE_SINGLE
|
||||
| FieldType.ATTACHMENTS
|
||||
>
|
||||
}
|
||||
|
@ -178,6 +184,7 @@ export type FieldSchema =
|
|||
| BBReferenceFieldMetadata
|
||||
| JsonFieldMetadata
|
||||
| AttachmentFieldMetadata
|
||||
| BBReferenceSingleFieldMetadata
|
||||
|
||||
export interface TableSchema {
|
||||
[key: string]: FieldSchema
|
||||
|
|
Loading…
Reference in New Issue