mirror of https://github.com/waku-org/js-waku.git
chore: do not use `Partial` when not needed
This commit is contained in:
parent
f80c3ded0f
commit
a4ddb45af1
|
@ -60,7 +60,7 @@ class WakuLightPush implements LightPush {
|
||||||
|
|
||||||
async push(
|
async push(
|
||||||
encoder: Encoder,
|
encoder: Encoder,
|
||||||
message: Partial<Message>,
|
message: Message,
|
||||||
opts?: ProtocolOptions
|
opts?: ProtocolOptions
|
||||||
): Promise<SendResult> {
|
): Promise<SendResult> {
|
||||||
const pubSubTopic = opts?.pubSubTopic ? opts.pubSubTopic : this.pubSubTopic;
|
const pubSubTopic = opts?.pubSubTopic ? opts.pubSubTopic : this.pubSubTopic;
|
||||||
|
|
|
@ -74,11 +74,11 @@ export class DecodedMessage implements IDecodedMessage {
|
||||||
export class Encoder implements IEncoder {
|
export class Encoder implements IEncoder {
|
||||||
constructor(public contentTopic: string, public ephemeral: boolean = false) {}
|
constructor(public contentTopic: string, public ephemeral: boolean = false) {}
|
||||||
|
|
||||||
async toWire(message: Partial<Message>): Promise<Uint8Array> {
|
async toWire(message: Message): Promise<Uint8Array> {
|
||||||
return proto.WakuMessage.encode(await this.toProtoObj(message));
|
return proto.WakuMessage.encode(await this.toProtoObj(message));
|
||||||
}
|
}
|
||||||
|
|
||||||
async toProtoObj(message: Partial<Message>): Promise<ProtoMessage> {
|
async toProtoObj(message: Message): Promise<ProtoMessage> {
|
||||||
const timestamp = message.timestamp ?? new Date();
|
const timestamp = message.timestamp ?? new Date();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -99,10 +99,7 @@ class WakuRelay extends GossipSub implements Relay {
|
||||||
/**
|
/**
|
||||||
* Send Waku message.
|
* Send Waku message.
|
||||||
*/
|
*/
|
||||||
public async send(
|
public async send(encoder: Encoder, message: Message): Promise<SendResult> {
|
||||||
encoder: Encoder,
|
|
||||||
message: Partial<Message>
|
|
||||||
): Promise<SendResult> {
|
|
||||||
const msg = await encoder.toWire(message);
|
const msg = await encoder.toWire(message);
|
||||||
if (!msg) {
|
if (!msg) {
|
||||||
log("Failed to encode message, aborting publish");
|
log("Failed to encode message, aborting publish");
|
||||||
|
|
|
@ -37,16 +37,14 @@ class Encoder implements IEncoder {
|
||||||
public ephemeral: boolean = false
|
public ephemeral: boolean = false
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async toWire(message: Partial<Message>): Promise<Uint8Array | undefined> {
|
async toWire(message: Message): Promise<Uint8Array | undefined> {
|
||||||
const protoMessage = await this.toProtoObj(message);
|
const protoMessage = await this.toProtoObj(message);
|
||||||
if (!protoMessage) return;
|
if (!protoMessage) return;
|
||||||
|
|
||||||
return proto.WakuMessage.encode(protoMessage);
|
return proto.WakuMessage.encode(protoMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
async toProtoObj(
|
async toProtoObj(message: Message): Promise<ProtoMessage | undefined> {
|
||||||
message: Partial<Message>
|
|
||||||
): Promise<ProtoMessage | undefined> {
|
|
||||||
const timestamp = message.timestamp ?? new Date();
|
const timestamp = message.timestamp ?? new Date();
|
||||||
if (!message.payload) {
|
if (!message.payload) {
|
||||||
log("No payload to encrypt, skipping: ", message);
|
log("No payload to encrypt, skipping: ", message);
|
||||||
|
|
|
@ -36,16 +36,14 @@ class Encoder implements IEncoder {
|
||||||
public ephemeral: boolean = false
|
public ephemeral: boolean = false
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async toWire(message: Partial<Message>): Promise<Uint8Array | undefined> {
|
async toWire(message: Message): Promise<Uint8Array | undefined> {
|
||||||
const protoMessage = await this.toProtoObj(message);
|
const protoMessage = await this.toProtoObj(message);
|
||||||
if (!protoMessage) return;
|
if (!protoMessage) return;
|
||||||
|
|
||||||
return proto.WakuMessage.encode(protoMessage);
|
return proto.WakuMessage.encode(protoMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
async toProtoObj(
|
async toProtoObj(message: Message): Promise<ProtoMessage | undefined> {
|
||||||
message: Partial<Message>
|
|
||||||
): Promise<ProtoMessage | undefined> {
|
|
||||||
const timestamp = message.timestamp ?? new Date();
|
const timestamp = message.timestamp ?? new Date();
|
||||||
if (!message.payload) {
|
if (!message.payload) {
|
||||||
log("No payload to encrypt, skipping: ", message);
|
log("No payload to encrypt, skipping: ", message);
|
||||||
|
|
Loading…
Reference in New Issue