refactor: create PeerConstructorOptions type

This commit is contained in:
Derrick Hammer 2023-08-31 18:00:59 -04:00
parent 3accd69ab0
commit 57e2c56d24
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
2 changed files with 6 additions and 4 deletions

View File

@ -1,4 +1,4 @@
import { Logger, Peer } from "#types.js"; import { Logger, Peer, PeerConstructorOptions } from "#types.js";
import { URL } from "url"; import { URL } from "url";
import NodeId from "#nodeId.js"; import NodeId from "#nodeId.js";
@ -8,8 +8,8 @@ export abstract class BasePeer implements Peer {
challenge: Uint8Array; challenge: Uint8Array;
protected _socket: any; protected _socket: any;
constructor({ socket, uri }: { socket: any; uri: URL[] }) { constructor({ socket, uris }: PeerConstructorOptions) {
this.connectionUris = uri.map((uri) => new URL(uri.toString())); this.connectionUris = uris.map((uri) => new URL(uri.toString()));
this.challenge = new Uint8Array(); this.challenge = new Uint8Array();
this._socket = socket; this._socket = socket;
} }

View File

@ -30,9 +30,11 @@ export interface Peer {
renderLocationUri(): string; renderLocationUri(): string;
} }
export type PeerConstructorOptions = { socket: any; uris: URL[] };
// Define the static side of the class // Define the static side of the class
export interface PeerStatic { export interface PeerStatic {
new ({ socket, uri }: { socket: any; uri: URL[] }): Peer; new ({ socket, uris }: PeerConstructorOptions): Peer;
connect(uri: URL): Promise<any>; connect(uri: URL): Promise<any>;
} }