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