Danish Arora 4eb06c64eb
feat(filter)!: return error codes instead of throwing errors (#1971)
* move protocol result type to interfaces

* chore: update type names for verbosity

* feat(filter-core): convert error throws to return types

* chore: update types & imports

* update Filter API

* chore: update createSubscription

* chore: update imports & rename

* chore: update all tests

* chore: resolve conflicts & merge (2/n)

* chore: resolve conflicts & merge (3/n)

* chore: resolve conflicts & merge (4/n)

* chore: resolve conflicts & merge (5/n)

* chore: resolve conflicts & merge (6/n)

* chore: use idiomatic approach

* chore: fix tests

* chore: address comments

* chore: fix test

* rm: only
2024-05-09 16:51:08 +05:30

35 lines
879 B
TypeScript

import type { IDecodedMessage } from "./message.js";
import { ProtocolError } from "./protocols.js";
export interface IAsyncIterator<T extends IDecodedMessage> {
iterator: AsyncIterator<T>;
stop: Unsubscribe;
}
export type Unsubscribe = () => void | Promise<void>;
export type PubsubTopic = string;
export type ContentTopic = string;
export type PeerIdStr = string;
// 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 };