import { IdMap, IdMapperClient } from './id-mapper-client'; import { DirectusBaseType, DirectusCollectionExtraConfig, UpdateItem, WithoutId, WithoutSyncId, WithSyncId, WithSyncIdAndWithoutId } from './interfaces'; import { DataClient } from './data-client'; import { DataLoader } from './data-loader'; import { DataDiffer } from './data-differ'; import { DataMapper } from './data-mapper'; import { CollectionHooks } from '../../config'; import { MigrationClient } from '../../migration-client'; import { debugOrInfoLogger } from '../../../helpers'; import { Logger } from '../../logger'; /** * This class is responsible for merging the data from a dump to a target table. * It creates new data, updates existing data and deletes data that is not present in the dump. */ export declare abstract class DirectusCollection { protected readonly logger: Logger; protected readonly dataDiffer: DataDiffer; protected readonly dataLoader: DataLoader; protected readonly dataClient: DataClient; protected readonly dataMapper: DataMapper; protected readonly idMapper: IdMapperClient; protected readonly migrationClient: MigrationClient; protected abstract readonly enableCreate: boolean; protected abstract readonly enableUpdate: boolean; protected abstract readonly enableDelete: boolean; protected readonly hooks: CollectionHooks; /** * If true, the ids of the items will be used as sync ids. * This allows to restore the same ids as the original table. */ protected readonly preserveIds: boolean; /** * Used to keep data in memory between the pull and the postProcessPull. */ protected tempData: WithSyncIdAndWithoutId[]; /** * Log message to debug or info, depending on the debug flag */ protected readonly debugOrInfo: ReturnType; constructor(logger: Logger, dataDiffer: DataDiffer, dataLoader: DataLoader, dataClient: DataClient, dataMapper: DataMapper, idMapper: IdMapperClient, migrationClient: MigrationClient, extraConfig: DirectusCollectionExtraConfig); /** * Pull data from a table to a JSON file */ pull(): Promise; /** * This methods will change ids to sync ids and add users placeholders. */ postProcessPull(): Promise; diff(): Promise; /** * Merge the data from the dump to the target table */ push(): Promise; /** * Clean collections and orphan sync id */ cleanUp(): Promise; /** * Temporary store the data in memory. */ protected setTempData(data: WithSyncIdAndWithoutId[]): Promise; /** * Returns the data stored in memory. */ protected getTempData(): WithSyncIdAndWithoutId[]; /** * For each item, try to get the mapped id if exists from the idMapper, or create it if not. */ protected mapIdsOfItems(items: T[]): Promise[]>; /** * Remove the id of the items */ protected removeIdsOfItems(items: T[]): WithoutId[]; /** * This method returns true if there are items to retry. */ protected create(toCreate: WithSyncIdAndWithoutId[]): Promise; /** * Handle the error when creating an item. * Returns the item if the error can be handled. * Re-throws the error otherwise. */ protected handleCreationError(error: Error, payload: WithoutSyncId, _syncId: string): Promise; /** * This method returns true if there are items to retry. */ protected update(toUpdate: UpdateItem[]): Promise; protected delete(toDelete: IdMap[]): Promise; protected removeDangling(dangling: IdMap[]): Promise; }