diff --git a/packages/server/src/integrations/base/sqlTable.ts b/packages/server/src/integrations/base/sqlTable.ts index 3c55d75b8b..087f068386 100644 --- a/packages/server/src/integrations/base/sqlTable.ts +++ b/packages/server/src/integrations/base/sqlTable.ts @@ -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) } } diff --git a/packages/server/src/integrations/googlesheets.ts b/packages/server/src/integrations/googlesheets.ts index 7215c337d7..8288a07846 100644 --- a/packages/server/src/integrations/googlesheets.ts +++ b/packages/server/src/integrations/googlesheets.ts @@ -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.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, diff --git a/packages/server/src/integrations/utils/utils.ts b/packages/server/src/integrations/utils/utils.ts index aac3f5f74a..581c9b6a22 100644 --- a/packages/server/src/integrations/utils/utils.ts +++ b/packages/server/src/integrations/utils/utils.ts @@ -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 diff --git a/packages/server/src/sdk/app/tables/internal/sqs.ts b/packages/server/src/sdk/app/tables/internal/sqs.ts index 0726c94962..391e186bc0 100644 --- a/packages/server/src/sdk/app/tables/internal/sqs.ts +++ b/packages/server/src/sdk/app/tables/internal/sqs.ts @@ -45,6 +45,7 @@ const FieldTypeMap: Record = { [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( diff --git a/packages/server/src/utilities/rowProcessor/index.ts b/packages/server/src/utilities/rowProcessor/index.ts index e69cfa471a..418b38bc38 100644 --- a/packages/server/src/utilities/rowProcessor/index.ts +++ b/packages/server/src/utilities/rowProcessor/index.ts @@ -244,7 +244,8 @@ export async function outputProcessing( } } 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( diff --git a/packages/server/src/utilities/schema.ts b/packages/server/src/utilities/schema.ts index 4c7f0b7423..156ea5ea7b 100644 --- a/packages/server/src/utilities/schema.ts +++ b/packages/server/src/utilities/schema.ts @@ -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 diff --git a/packages/shared-core/src/filters.ts b/packages/shared-core/src/filters.ts index 0554e0c1e4..849f22e991 100644 --- a/packages/shared-core/src/filters.ts +++ b/packages/shared-core/src/filters.ts @@ -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] diff --git a/packages/shared-core/src/table.ts b/packages/shared-core/src/table.ts index 26a7e77cd0..2b3586932a 100644 --- a/packages/shared-core/src/table.ts +++ b/packages/shared-core/src/table.ts @@ -18,6 +18,7 @@ const allowDisplayColumnByType: Record = { [FieldType.LINK]: false, [FieldType.JSON]: false, [FieldType.BB_REFERENCE]: false, + [FieldType.BB_REFERENCE_SINGLE]: false, } const allowSortColumnByType: Record = { @@ -39,6 +40,7 @@ const allowSortColumnByType: Record = { [FieldType.ARRAY]: false, [FieldType.LINK]: false, [FieldType.BB_REFERENCE]: false, + [FieldType.BB_REFERENCE_SINGLE]: false, } export function canBeDisplayColumn(type: FieldType): boolean { diff --git a/packages/types/src/documents/app/row.ts b/packages/types/src/documents/app/row.ts index 865ab4ba64..ca9b11ffe5 100644 --- a/packages/types/src/documents/app/row.ts +++ b/packages/types/src/documents/app/row.ts @@ -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 { diff --git a/packages/types/src/documents/app/table/schema.ts b/packages/types/src/documents/app/table/schema.ts index 63a5876bc0..22ad9f7bb5 100644 --- a/packages/types/src/documents/app/table/schema.ts +++ b/packages/types/src/documents/app/table/schema.ts @@ -112,6 +112,11 @@ export interface BBReferenceFieldMetadata subtype: FieldSubtype.USER | FieldSubtype.USERS relationshipType?: RelationshipType } +export interface BBReferenceSingleFieldMetadata + extends Omit { + 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