Something went wrong. Try again.
🔥 🔥 🔥 A Free & Self-hostable Airtable Alternative nocodb.com
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132import type { SyncConfig } from 'nocodb-sdk'import { IntegrationsType, OnDeleteAction, OnDeleteActionMeta, SYNC_SYSTEM_COLUMN_TITLES, SyncCategory, SyncTrigger, SyncTriggerMeta, SyncType, SyncTypeMeta, generateUniqueCopyName,} from 'nocodb-sdk'import { getI18n } from '~/plugins/a.i18n'
/** * Titles of the system columns that table-sync (and legacy SaaS/Airtable sync) * adds to every synced destination table — they hold sync bookkeeping (remote * id, remote timestamps, run/config ids, raw payload). They're noise in a * record's revision history, so the audit sidebar hides their changes on * synced tables. */const syncSystemColumnTitles = new Set<string>(SYNC_SYSTEM_COLUMN_TITLES)
const isSyncSystemColumnTitle = (title?: string | null): boolean => !!title && syncSystemColumnTitles.has(title)
const getSyncFrequency = (trigger: SyncTrigger, cron?: string) => { if (trigger === SyncTrigger.Manual) return 'Manual' if (trigger === SyncTrigger.Schedule && cron) { if (cron.includes('hourly')) return 'Hourly' if (cron.includes('daily')) return 'Daily' if (cron.includes('* * * *')) return 'Hourly' if (cron.includes('* * *')) return 'Daily' return cron } return 'Unknown'}
const getDefaultSyncConfig = () => { return { title: getI18n().global.t('labels.newSource'), sync_type: SyncType.Incremental, sync_trigger: SyncTrigger.Manual, sync_category: SyncCategory.TICKETING, on_delete_action: OnDeleteAction.MarkDeleted, sync_trigger_cron: '0 * * * *', meta: { sync_all_models: true, sync_excluded_models: [], }, } as Partial<SyncConfig> & Record<string, unknown>}
const defaultSyncConfig = (configs: SyncConfig[]) => { const newTitle = generateUniqueCopyName('New Sync Source', configs, { accessor: (c) => c.title, prefix: null, })
const isDefaultSyncCategoryAlreadyAdded = configs.some( (config) => config.sync_category === getDefaultSyncConfig().sync_category, )
return { ...getDefaultSyncConfig(), title: newTitle, sync_category: isDefaultSyncCategoryAlreadyAdded ? undefined : getDefaultSyncConfig().sync_category, }}
enum SyncFormStep { SyncSettings = 0, Integration = 1, DestinationSchema = 2, Create = 3,}
interface IntegrationConfig { id?: string title?: string type: IntegrationsType.Sync sub_type: string | null config: Record<string, any> syncConfigId?: string parentSyncConfigId?: string}
const defaultIntegrationConfig: Partial<IntegrationConfig> = { type: IntegrationsType.Sync, sub_type: null,}
const syncEntityToReadableMap = { [SyncType.Full]: SyncTypeMeta[SyncType.Full].label, [SyncType.Incremental]: SyncTypeMeta[SyncType.Incremental].label, [SyncTrigger.Manual]: SyncTriggerMeta[SyncTrigger.Manual].label, [SyncTrigger.Schedule]: SyncTriggerMeta[SyncTrigger.Schedule].label, [SyncTrigger.Webhook]: SyncTriggerMeta[SyncTrigger.Webhook].label, [OnDeleteAction.Delete]: OnDeleteActionMeta[OnDeleteAction.Delete].label, [OnDeleteAction.MarkDeleted]: OnDeleteActionMeta[OnDeleteAction.MarkDeleted].label,}
interface CustomSyncSchema { [key: string]: { title: string columns: { title: string uidt: string abstractType: string exclude?: boolean }[] relations: any[] systemFields?: { primaryKey: string[] createdAt?: string updatedAt?: string } }}
export { getSyncFrequency, defaultSyncConfig, SyncFormStep, defaultIntegrationConfig, syncEntityToReadableMap, getDefaultSyncConfig, isSyncSystemColumnTitle,}
export type { IntegrationConfig, CustomSyncSchema }