import { type Maybe } from '@dereekb/util'; import { type SyncEntityCommonType, type SyncEntityCommonTypeIdPair } from './sync.entity'; import { type SyncEntityCommonTypeSynchronizationEntityResult, type SyncEntityCommonTypeSynchronizer, type SyncEntityCommonTypeSynchronizerSourceContextType, type SyncEntityCommonTypeSynchronizerSourceFlowType } from './sync.entity.synchronizer'; import { type SyncSourceClientContext, type SyncSourceId, type SyncSourceInfo } from './sync.source'; /** * BasicSyncEntityCommonTypeSynchronizerSourceSyncEntityFunction input */ export interface BasicSyncEntityCommonTypeSynchronizerSourceSyncEntityFunctionInput { /** * The entity to synchronize. */ readonly entityCommonTypeIdPair: SyncEntityCommonTypeIdPair; /** * The determined flow type of this source. */ readonly flowType: SyncEntityCommonTypeSynchronizerSourceFlowType; /** * The source for this entity. */ readonly source: BasicSyncEntityCommonTypeSynchronizerSource; /** * Additional context information. */ readonly context?: Maybe; } export interface BasicSyncEntityCommonTypeSynchronizerSourceSyncEntitySynchronizeContext { readonly deleted?: boolean; } /** * Creates a new BasicSyncEntityCommonTypeSynchronizerSourceSyncEntityInstance for the input. */ export type BasicSyncEntityCommonTypeSynchronizerSourceSyncEntityFunction = (input: BasicSyncEntityCommonTypeSynchronizerSourceSyncEntityFunctionInput) => Promise; export type BasicSyncEntityCommonTypeSynchronizerSourceSyncEntitySynchronizeFunction = () => Promise; export interface BasicSyncEntityCommonTypeSynchronizerSourceSyncEntityInstance { /** * Performs the create/update synchronization for the entity. * * The function should typically never throw an error. */ readonly synchronize: BasicSyncEntityCommonTypeSynchronizerSourceSyncEntitySynchronizeFunction; /** * Synchronizes the deletion of the entity. * * For a "primary" source, this is called only when another source suggests a delete. * * The function should typically never throw an error. */ readonly synchronizeDelete: BasicSyncEntityCommonTypeSynchronizerSourceSyncEntitySynchronizeFunction; } /** * A declaration of a source for an entity type. * * A BasicSyncEntityCommonTypeSynchronizerSource is considered to be a target for synchronization between the current system/server and the SyncSource. */ export interface BasicSyncEntityCommonTypeSynchronizerSource { readonly info: SyncSourceInfo; /** * The context type of the source. */ readonly contextType: SyncEntityCommonTypeSynchronizerSourceContextType; /** * The default flow type of the source. */ readonly defaultFlowType?: Maybe; readonly syncEntityInstance: BasicSyncEntityCommonTypeSynchronizerSourceSyncEntityFunction; } export type BasicSyncEntityCommonTypeSynchronizer = SyncEntityCommonTypeSynchronizer; export interface BasicSyncEntityCommonTypeSynchronizerEntitySourceContextLoaderResult { /** * List of global sources for this entity. */ readonly globalSources: (SyncSourceId | BasicSyncEntityCommonTypeSynchronizerEntitySourceGlobalContext)[]; /** * List of context sources for this entity. */ readonly contextSources: BasicSyncEntityCommonTypeSynchronizerEntitySourceContext[]; } export interface BasicSyncEntityCommonTypeSynchronizerEntitySourceGlobalContext { /** * The source id. */ readonly sourceId: SyncSourceId; /** * The flow type of the source. If not defined, will default to the source's default flow type. */ readonly flowType?: Maybe; } export interface BasicSyncEntityCommonTypeSynchronizerEntitySourceContext { readonly sourceId: SyncSourceId; readonly context: SyncSourceClientContext; /** * The flow type of the source. If not defined, will default to the source's default flow type. */ readonly flowType?: Maybe; } /** * Loads source contextual information for a specific entity. */ export type BasicSyncEntityCommonTypeSynchronizerEntitySourceContextLoader = (entity: SyncEntityCommonTypeIdPair) => Promise; export interface BasicSyncEntityCommonTypeSynchronizerConfig { readonly commonType: SyncEntityCommonType; /** * If true, the sources are considered to be dynamic and will be reloaded/configured each time the synchronizer is called. * * Defaults to false. */ readonly dynamicSources?: boolean; /** * All sources for this entity type for this synchronizer. */ readonly sources: BasicSyncEntityCommonTypeSynchronizerSource[]; /** * Loads source contextual information for any source that requires context. */ readonly entitySourceContextLoader: BasicSyncEntityCommonTypeSynchronizerEntitySourceContextLoader; } /** * Creates a {@link BasicSyncEntityCommonTypeSynchronizer} that orchestrates synchronization across multiple sources * for a specific entity common type. * * The synchronizer follows a primary/secondary/replica flow: * 1. The primary source is synchronized first (exactly one required). * 2. Secondary sources are synchronized sequentially; if a secondary reports deletion while primary did not, the sync restarts once. * 3. Replica sources are synchronized concurrently (up to 3 in parallel). * * @param config - Common type, sources, and context loader. * @returns A synchronizer for the configured common type. * @throws {NoPrimarySyncSourceError} When no primary source is found. * @throws {MultiplePrimarySyncSourceError} When more than one primary source is found. * @throws {SynchronizationFailedError} When primary or secondary sync returns failed/error. * * @__NO_SIDE_EFFECTS__ */ export declare function basicSyncEntityCommonTypeSynchronizerInstanceFactory(config: BasicSyncEntityCommonTypeSynchronizerConfig): BasicSyncEntityCommonTypeSynchronizer;