import { type FactoryWithRequiredInput, type Maybe, type UniqueModel } from '@dereekb/util'; import { type SyncSourceInfo } from './sync.source'; /** * A unique identifier for an entity on a specific server. * * @semanticType * @semanticTopic identifier * @semanticTopic string * @semanticTopic dereekb-model:sync */ export type SyncEntityId = string; /** * A common type for an entity that is shared/used between all systems for an entity that should be synchronized. * * @semanticType * @semanticTopic identifier * @semanticTopic string * @semanticTopic dereekb-model:sync */ export type SyncEntityCommonType = string; /** * A common identifier for an entity that is shared/used between all systems for an entity that should be synchronized. * * This identifier should be used for retrieving a similar entity from any server. * * @semanticType * @semanticTopic identifier * @semanticTopic string * @semanticTopic dereekb-model:sync */ export type SyncEntityCommonId = string; /** * A pair of common type and common id for an entity. */ export interface SyncEntityCommonTypeIdPair { readonly commonType: SyncEntityCommonType; readonly commonId: SyncEntityCommonId; } export type SyncEntityCommonTypeIdPairFactoryInput = SyncEntityCommonTypeIdPair | SyncEntityCommonId; export type SyncEntityCommonTypeIdPairFactory = (input: SyncEntityCommonTypeIdPairFactoryInput) => SyncEntityCommonTypeIdPair; /** * Creates a factory that normalizes a {@link SyncEntityCommonTypeIdPairFactoryInput} into a full {@link SyncEntityCommonTypeIdPair}. * * If the input is a string, it is treated as a commonId and paired with the given commonType. * If the input is already a pair, it is returned as-is. * * @param commonType - The default common type to use when input is a plain string. * @returns A factory function that produces SyncEntityCommonTypeIdPair instances. * * @example * ```typescript * const factory = syncEntityCommonTypeIdPairFactory('user'); * factory('abc123'); // { commonType: 'user', commonId: 'abc123' } * factory({ commonType: 'user', commonId: 'abc123' }); // passed through as-is * ``` * * @__NO_SIDE_EFFECTS__ */ export declare function syncEntityCommonTypeIdPairFactory(commonType: SyncEntityCommonType): SyncEntityCommonTypeIdPairFactory; /** * Represents a single entity that can be synchronized between different servers. */ export interface SyncEntity extends UniqueModel, SyncEntityCommonTypeIdPair { /** * The unique identifier for the entity on the server. */ readonly id: SyncEntityId; /** * The server information for the entity. */ readonly sourceInfo: SyncSourceInfo; } /** * Configuration for syncEntityFactory(). */ export interface SyncEntityFactoryConfig { /** * The source information to attach to the entity. */ readonly sourceInfo: SyncSourceInfo; /** * Optional factory for generating the entity's id from the common id. */ readonly idFactory?: Maybe<(commonId: SyncEntityCommonId) => SyncEntityId>; } /** * Factory for creating a SyncEntity. */ export type SyncEntityFactory = FactoryWithRequiredInput; /** * Creates a {@link SyncEntityFactory} that produces {@link SyncEntity} instances from a common type/id pair. * * The factory attaches the configured source info and optionally transforms the commonId into an entity id * using the provided idFactory (defaults to identity). * * @param config - Source info and optional id factory. * @returns A factory that creates SyncEntity instances. * * @example * ```typescript * const factory = syncEntityFactory({ * sourceInfo: { id: 'api', name: 'External API' } * }); * * const entity = factory({ commonType: 'user', commonId: 'abc123' }); * // entity.id === 'abc123', entity.sourceInfo.id === 'api' * ``` * * @__NO_SIDE_EFFECTS__ */ export declare function syncEntityFactory(config: SyncEntityFactoryConfig): SyncEntityFactory;