import { Observable, Subscription } from 'rxjs'; import type { ReplicationOptions, ReplicationPullOptions, ReplicationPushOptions, RxError, RxReplicationHandler, RxStorageDefaultCheckpoint, RxTypeError, StringKeys } from 'nxdb-old/src/types'; import { RxReplicationState } from 'nxdb-old/src/plugins/replication'; import { WebsocketMessageResponseType, WebsocketMessageType } from 'nxdb-old/src/plugins/replication-websocket'; export type P2PPeer = { id: string; }; export type P2PReplicationCheckpoint = RxStorageDefaultCheckpoint; export type P2PMessage = Omit & { method: StringKeys> | 'token'; }; export type P2PResponse = Omit; export type PeerWithMessage = { peer: P2PPeer; message: P2PMessage; }; export type PeerWithResponse = { peer: P2PPeer; response: P2PResponse; }; export type P2PConnectionHandler = { connect$: Observable; disconnect$: Observable; message$: Observable; response$: Observable; error$: Observable; send(peer: P2PPeer, message: P2PMessage | P2PResponse): Promise; destroy(): Promise; }; export type P2PConnectionHandlerCreator = ( opts: SyncOptionsP2P ) => P2PConnectionHandler; export type P2PSyncPushOptions = Omit< ReplicationPushOptions, 'handler' > & {}; export type P2PSyncPullOptions = Omit< ReplicationPullOptions, 'handler' | 'stream$' > & {}; export type SyncOptionsP2P = Omit< ReplicationOptions, 'pull' | 'push' | 'replicationIdentifier' | 'deletedField' | 'live' | 'autostart' | 'waitForLeadership' > & { /** * It will only replicate with other instances * that use the same topic and * are able to prove that they know the secret. */ topic: string; secret: string; connectionHandlerCreator: P2PConnectionHandlerCreator; pull?: P2PSyncPullOptions; push?: P2PSyncPushOptions; }; export type RxP2PReplicationState = RxReplicationState; export type P2PPeerState = { peer: P2PPeer; // only exists when the peer was picked as master and the own client was picked as fork. replicationState?: RxP2PReplicationState; // clean this up when removing the peer subs: Subscription[]; };