import { DirectusBaseType, DirectusId, UpdateItem, WithoutIdAndSyncId, WithSyncId, WithSyncIdAndWithoutId } from './interfaces'; import { IdMap, IdMapperClient } from './id-mapper-client'; import { DataLoader } from './data-loader'; import { DataClient } from './data-client'; import { DataMapper } from './data-mapper'; import { Logger } from '../../logger'; export declare abstract class DataDiffer { protected readonly logger: Logger; protected readonly dataLoader: DataLoader; protected readonly dataClient: DataClient; protected readonly dataMapper: DataMapper; protected readonly idMapper: IdMapperClient; /** * The maximum number of ids to request at once. * This is used to avoid overwhelming the server with too many requests. */ protected maxIdsPerRequest: number; /** * These field will be ignored when comparing the data from the dump with the data from the target table. */ protected readonly fieldsToIgnore: [ 'id', '_syncId', ...(keyof WithSyncId)[] ]; constructor(logger: Logger, dataLoader: DataLoader, dataClient: DataClient, dataMapper: DataMapper, idMapper: IdMapperClient); /** * Returns the diff between the dump and the target table. */ getDiff(): Promise<{ toCreate: WithSyncIdAndWithoutId[]; toUpdate: UpdateItem[]; toDelete: IdMap[]; unchanged: WithSyncId[]; dangling: IdMap[]; }>; /** * Get the target item from the idMapper then from the target table */ protected getTargetItem(sourceItem: WithSyncIdAndWithoutId): Promise | undefined>; /** * This method will also test every item with the local id from the id mapper. * This should be used to find items that were deleted manually and clean up the sync id map. */ getDanglingIds(): Promise; /** * Get the existing ids from the target table. * This allows overriding the query to include more fields. */ protected getExistingIds(localIds: string[]): Promise<{ id: DirectusId; }[]>; /** * Denotes which items should be deleted excluding the ones that are to be updated or unchanged. * Refer to the list of all items provided by the id mapper. */ protected getIdsToDelete(unchanged: WithSyncId[], toUpdate: UpdateItem[], dangling: IdMap[]): Promise; /** * This method ensure there is no dangling ids that are also in the toDelete list. * Throws an error if there is. */ protected checkDanglingAndDeleteOverlap(dangling: IdMap[], toDelete: IdMap[]): void; /** * Get the diff between two items and returns the source item with only the diff fields. * This is non-destructive, and non-deep. */ protected getDiffBetweenItems(sourceItem: WithSyncIdAndWithoutId, targetItem: WithSyncId): { diffObject: Partial>; diffFields: Exclude[]; hasDiff: boolean; }; }