import { AuthorAddress, DocBase, Path, ShareAddress,} from "../util/doc-types.ts";import { Replica } from "../replica/replica.ts";import { FormatArg, FormatDocType, FormatsArg,} from "../formats/format_types.ts";import { TransferManager } from "./transfer_manager.ts";import { SyncerManager } from "./syncer_manager.ts";import { NotSupportedError } from "../util/errors.ts";
export type DocThumbnail = string;
export type RangeMessage = | { type: "EMPTY_SET"; canRespond: boolean; } | { type: "LOWER_BOUND"; value: DocThumbnail; } | { type: "PAYLOAD"; payload: DocThumbnail; end?: { canRespond: boolean; upperBound: DocThumbnail }; } | { type: "EMPTY_PAYLOAD"; upperBound: DocThumbnail; } | { type: "FINGERPRINT"; fingerprint: string; upperBound: DocThumbnail; } | { type: "DONE"; upperBound: DocThumbnail } | { type: "TERMINAL" };
export type SyncAgentRangeMessageEvent = { kind: "RANGE_MSG"; message: RangeMessage;};
export type SyncAgentHaveEvent = { kind: "HAVE"; thumbnail: DocThumbnail;};
export type SyncAgentWantEvent = { kind: "WANT"; thumbnail: DocThumbnail;};
export type SyncAgentDocEvent = { kind: "DOC"; thumbnail: DocThumbnail; doc: DocBase<string>; attachmentHeld: boolean;};
export type SyncAgentWantAttachmentEvent = { kind: "WANT_ATTACHMENT"; doc: DocBase<string>; shareAddress: string; attachmentHash: string;};
export type SyncAgentFulfilledEvent = { kind: "FULFILLED";};
export type SyncAgentAbortEvent = { kind: "ABORT";};
export type SyncAgentPruneEvent = { kind: "PRUNE";};
export type SynceAgentNewAttachmentEvent = { kind: "NEW_ATTACHMENT"; path: Path; author: AuthorAddress; format: string; hash: string;};
export type SyncAgentEvent = | SyncAgentRangeMessageEvent | SyncAgentWantEvent | SyncAgentDocEvent | SyncAgentWantAttachmentEvent | SyncAgentAbortEvent | SyncAgentHaveEvent | SyncAgentPruneEvent | SynceAgentNewAttachmentEvent | SyncAgentFulfilledEvent;
export type SyncAgentStatus = { requestedCount: number; receivedCount: number; sentCount: number; status: "preparing" | "reconciling" | "gossiping" | "done" | "aborted"; };
export type SyncAgentOpts<F> = { replica: Replica; formats?: FormatsArg<F>; transferManager: TransferManager<F, unknown>; syncerManager: SyncerManager; syncAppetite: SyncAppetite; initiateMessaging: boolean; payloadThreshold: number; rangeDivision: number;};
export type SyncerDiscloseEvent = { kind: "DISCLOSE"; syncerId: string; salt: string; shares: string[]; formats: string[]; canRespond: boolean;};
export type SyncerFulfilledEvent = { kind: "SYNCER_FULFILLED";};
export type SyncerHeartbeat = { kind: "HEARTBEAT";};
export type SyncerSyncAgentEvent = SyncAgentEvent & { to: string;};
export type SyncerEvent = | SyncerSyncAgentEvent | SyncerDiscloseEvent | SyncerHeartbeat | SyncerFulfilledEvent;
export interface ISyncPartner<IncomingAttachmentSourceType> { syncAppetite: SyncAppetite;
concurrentTransfers: number;
payloadThreshold: number;
rangeDivision: number;
getEvents(): AsyncIterable<SyncerEvent>;
sendEvent(event: SyncerEvent): Promise<void>;
closeConnection(): Promise<void>;
getDownload( opts: GetTransferOpts, ): Promise<ReadableStream<Uint8Array> | undefined | NotSupportedError>;
handleUploadRequest( opts: GetTransferOpts, ): Promise<WritableStream<Uint8Array> | NotSupportedError>;
handleTransferRequest( source: IncomingAttachmentSourceType, kind: "upload" | "download", ): Promise< | ReadableStream<Uint8Array> | WritableStream<Uint8Array> | undefined | NotSupportedError >;}
export type GetTransferOpts = { syncerId: string; doc: DocBase<string>; shareAddress: string; attachmentHash: string;};
export type SyncAppetite = "once" | "continuous";
export interface SyncerOpts<F, I> { manager: SyncerManager; partner: ISyncPartner<I>; formats?: FormatsArg<F>;}
export type SyncerStatus = Record< ShareAddress, { docs: SyncAgentStatus; attachments: AttachmentTransferReport[]; }>;
export type AttachmentTransferStatus = | "ready" | "in_progress" | "complete" | "failed" | "missing_attachment";
export type AttachmentTransferOpts<F> = { stream: ReadableStream<Uint8Array> | WritableStream<Uint8Array>; replica: Replica; doc: FormatDocType<F>; format: FormatArg<F>; requester: "us" | "them"; counterpartId: "local" | string;};
export type AttachmentTransferReport = { author: string; path: string; format: string; hash: string; status: AttachmentTransferStatus; bytesLoaded: number; totalBytes: number; kind: "download" | "upload";};
export type AttachmentTransferProgressEvent = { status: AttachmentTransferStatus; bytesLoaded: number; totalBytes: number;};