// import { ROOT_ADDR } from "@ibgib/ts-gib/dist/V1/constants.mjs"; export const SYNC_ATOM = "sync"; export const SYNC_MSG_REL8N_NAME = "syncmsg"; /** * payload addrs should be domain-only, i.e., we are not including the sync * saga ibgib, or its message stone. */ export const SYNC_SAGA_PAYLOAD_ADDRS_DOMAIN = "@payloadAddrsDomain"; // #region SyncStage export const SYNC_STAGE_INIT = "init"; export const SYNC_STAGE_ACK = "ack"; export const SYNC_STAGE_DELTA = "delta"; export const SYNC_STAGE_COMMIT = "commit"; export type SyncStage = | typeof SYNC_STAGE_INIT | typeof SYNC_STAGE_ACK | typeof SYNC_STAGE_DELTA | typeof SYNC_STAGE_COMMIT; export const SyncStage = { /** * first frame */ init: SYNC_STAGE_INIT, /** * 2nd frame, response to init */ ack: SYNC_STAGE_ACK, /** * exchanging/negotiating ibgibs */ delta: SYNC_STAGE_DELTA, /** * final phases of sync */ commit: SYNC_STAGE_COMMIT, } satisfies { [key: string]: SyncStage }; export const SYNC_STAGE_VALID_VALUES = Object.values(SyncStage); // #endregion SyncStage // #region SyncConflictStrategy export const SYNC_CONFLICT_STRATEGY_ABORT = 'abort'; export const SYNC_CONFLICT_STRATEGY_OPTIMISTIC_GRAFT_LCS = 'optimistic-graft-longest-common-subsequence'; // export const SYNC_CONFLICT_STRATEGY_MANUAL = 'manual'; // not implemented yet export type SyncConflictStrategy = | typeof SYNC_CONFLICT_STRATEGY_ABORT | typeof SYNC_CONFLICT_STRATEGY_OPTIMISTIC_GRAFT_LCS // | typeof SYNC_CONFLICT_STRATEGY_MANUAL // not implemented yet ; /** * @see {@link SyncOptions.conflictStrategy} */ export const SyncConflictStrategy = { /** * As soon as a conflict is detected, the sync aborts and fails completely. */ abort: SYNC_CONFLICT_STRATEGY_ABORT, /** * * Optimistic: do something even if its wrong * * LCS: Longest common subsequence algorithm used when encountering * data.text differences. * * ## notes * * If we are making changes to text, then we will try to merge that text * instead of last-one-wins. */ optimisticWithLCS: SYNC_CONFLICT_STRATEGY_OPTIMISTIC_GRAFT_LCS, // manual: SYNC_CONFLICT_STRATEGY_MANUAL, // not implemented yet } satisfies { [key: string]: SyncConflictStrategy }; export const SYNC_CONFLICT_STRATEGY_VALID_VALUES = Object.values(SyncConflictStrategy); export function isValidSyncConflictStrategy(strategy: string): strategy is SyncConflictStrategy { return SYNC_CONFLICT_STRATEGY_VALID_VALUES.includes(strategy as SyncConflictStrategy); } // #endregion SyncConflictStrategy