/
syncer-types.ts
84 lines (72 loc) · 1.86 KB
/
syncer-types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import { PeerId } from "../peer/peer-types.ts";
import { Doc, ShareAddress } from "../util/doc-types.ts";
import { ReplicaId } from "../replica/replica-types.ts";
import { Query } from "../query/query-types.ts";
import { SyncerBag } from "./_syncer-bag.ts";
import { type ITransport } from "../../deps.ts";
export interface ISyncer<TransportType extends ITransport<SyncerBag>> {
transport: TransportType;
close(): void;
}
export interface SyncSessionStatus {
ingestedCount: number;
pulledCount: number;
isCaughtUp: boolean;
partnerIsCaughtUp: boolean;
}
// Salted handshake types
export interface SaltedHandshakeResponse {
peerId: PeerId;
salt: string;
saltedShares: string[];
}
export interface SaltedHandshakeResult {
partnerPeerId: PeerId;
partnerLastSeenAt: number;
commonShares: ShareAddress[];
}
// Share state types
export interface ShareState {
share: ShareAddress;
partnerStorageId: ReplicaId;
partnerMaxLocalIndexOverall: number;
partnerMaxLocalIndexSoFar: number; // -1 if unknown
storageId: ReplicaId;
lastSeenAt: number;
}
export type ShareStateFromResponse = Pick<
ShareState,
"share" | "partnerStorageId" | "partnerMaxLocalIndexOverall"
>;
export interface AllShareStatesRequest {
commonShares: ShareAddress[];
}
export type AllShareStatesResponse = {
partnerPeerId: PeerId;
shareStates: Record<
ShareAddress,
ShareStateFromResponse
>;
};
export type AllShareStatesResult = Record<
ShareAddress,
ShareState
>;
// Share query types
export interface ShareQueryRequest {
share: ShareAddress;
storageId: ReplicaId;
query: Query;
}
export interface ShareQueryResponse {
share: ShareAddress;
storageId: ReplicaId;
partnerMaxLocalIndexOverall: number;
docs: Doc[];
}
export interface ShareQueryResult {
pulled: number;
ingested: number;
lastSeenAt: number;
shareStates: Record<ShareAddress, ShareState>;
}