chore: do not use `Partial` when not needed

This commit is contained in:
fryorcraken.eth 2022-12-02 19:48:55 +11:00
parent f80c3ded0f
commit a4ddb45af1
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
5 changed files with 8 additions and 15 deletions

View File

@ -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;

View File

@ -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 {

View File

@ -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");

View File

@ -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);

View File

@ -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);