2023-05-09 20:15:37 +02:00
|
|
|
import type { IDecodedMessage } from "./message.js";
|
2024-05-09 16:51:08 +05:30
|
|
|
import { ProtocolError } from "./protocols.js";
|
2023-05-09 20:15:37 +02:00
|
|
|
|
|
|
|
|
export interface IAsyncIterator<T extends IDecodedMessage> {
|
|
|
|
|
iterator: AsyncIterator<T>;
|
|
|
|
|
stop: Unsubscribe;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export type Unsubscribe = () => void | Promise<void>;
|
|
|
|
|
|
2023-11-14 21:22:52 +05:30
|
|
|
export type PubsubTopic = string;
|
2023-05-09 20:15:37 +02:00
|
|
|
export type ContentTopic = string;
|
2023-05-23 16:06:46 +05:30
|
|
|
|
|
|
|
|
export type PeerIdStr = string;
|
2024-05-09 16:51:08 +05:30
|
|
|
|
|
|
|
|
// SK = success key name
|
|
|
|
|
// SV = success value type
|
|
|
|
|
// EK = error key name (default: "error")
|
|
|
|
|
// EV = error value type (default: ProtocolError)
|
|
|
|
|
export type ThisOrThat<
|
|
|
|
|
SK extends string,
|
|
|
|
|
SV,
|
|
|
|
|
EK extends string = "error",
|
|
|
|
|
EV = ProtocolError
|
|
|
|
|
> =
|
|
|
|
|
| ({ [key in SK]: SV } & { [key in EK]: null })
|
|
|
|
|
| ({ [key in SK]: null } & { [key in EK]: EV });
|
|
|
|
|
|
|
|
|
|
export type ThisAndThat<
|
|
|
|
|
SK extends string,
|
|
|
|
|
SV,
|
|
|
|
|
EK extends string = "error",
|
|
|
|
|
EV = ProtocolError
|
|
|
|
|
> = { [key in SK]: SV } & { [key in EK]: EV };
|