mirror of
https://github.com/logos-messaging/logos-messaging-js.git
synced 2026-03-21 14:23:10 +00:00
setup a generic type (DRY)
This commit is contained in:
parent
dd7354462a
commit
b308d71cd4
@ -6,6 +6,7 @@ import {
|
||||
Libp2p,
|
||||
ProtocolCreateOptions,
|
||||
ProtocolError,
|
||||
ProtocolResult,
|
||||
SendResult
|
||||
} from "@waku/interfaces";
|
||||
import { PushResponse } from "@waku/proto";
|
||||
@ -28,15 +29,7 @@ const log = new Logger("light-push");
|
||||
export const LightPushCodec = "/vac/waku/lightpush/2.0.0-beta1";
|
||||
export { PushResponse };
|
||||
|
||||
type PreparePushMessageResult =
|
||||
| {
|
||||
query: PushRpc;
|
||||
error: null;
|
||||
}
|
||||
| {
|
||||
query: null;
|
||||
error: ProtocolError;
|
||||
};
|
||||
type PreparePushMessageResult = ProtocolResult<"query", PushRpc>;
|
||||
|
||||
/**
|
||||
* Implements the [Waku v2 Light Push protocol](https://rfc.vac.dev/spec/19/).
|
||||
|
||||
@ -3,19 +3,11 @@ import type { PeerId } from "@libp2p/interface";
|
||||
import type { ShardInfo } from "./enr.js";
|
||||
import type {
|
||||
IBaseProtocol,
|
||||
ProtocolError,
|
||||
ProtocolResult,
|
||||
ShardingParams
|
||||
} from "./protocols.js";
|
||||
|
||||
export type QueryResult =
|
||||
| {
|
||||
shardInfo: ShardInfo;
|
||||
error: null;
|
||||
}
|
||||
| {
|
||||
shardInfo: null;
|
||||
error: ProtocolError;
|
||||
};
|
||||
export type QueryResult = ProtocolResult<"shardInfo", ShardInfo>;
|
||||
|
||||
// IMetadata always has shardInfo defined while it is optionally undefined in IBaseProtocol
|
||||
export interface IMetadata extends Omit<IBaseProtocol, "shardInfo"> {
|
||||
|
||||
@ -97,6 +97,16 @@ export type Callback<T extends IDecodedMessage> = (
|
||||
msg: T
|
||||
) => void | Promise<void>;
|
||||
|
||||
// K = key name
|
||||
// T = value type
|
||||
export type ProtocolResult<K extends string, T> =
|
||||
| ({
|
||||
[key in K]: T;
|
||||
} & { error: null })
|
||||
| ({
|
||||
[key in K]: null;
|
||||
} & { error: ProtocolError });
|
||||
|
||||
export enum ProtocolError {
|
||||
/** Could not determine the origin of the fault. Best to check connectivity and try again */
|
||||
GENERIC_FAIL = "Generic error",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user