Skip to content

Commit

Permalink
[fix] labeling of class members to private and protected as required
Browse files Browse the repository at this point in the history
  • Loading branch information
rohittiwari-dev committed Feb 25, 2024
1 parent fdbe3c7 commit f686cd6
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 84 deletions.
98 changes: 39 additions & 59 deletions lib/client.d.ts
@@ -1,11 +1,7 @@
/// <reference types="node" />
/// <reference types="node" />
/// <reference types="node" />
import EventEmitter from "events";
import { Validator } from "./validator";
import Queue from "./queue";
import WebSocket from "ws";
import { ExponentialStrategy } from "backoff";
import EventBuffer from "./event-buffer";
export interface RPC_ClientOptions {
identity: string;
Expand Down Expand Up @@ -41,43 +37,32 @@ export interface IHandlersOption {
}
type IHandlers = ({ params, reply, method, signal, messageId, }: IHandlersOption) => Promise<Record<string, any>>;
declare class RPC_Client extends EventEmitter {
_identity?: string;
_wildcardHandler: IHandlers | null;
_handlers: Map<string, IHandlers>;
_state: number;
_callQueue: Queue;
_ws?: WebSocket;
_wsAbortController?: AbortController;
_keepAliveAbortController?: AbortController;
_pendingPingResponse: boolean;
_lastPingTime: number;
_closePromise?: Promise<{
code: number;
reason: string;
}>;
_protocolOptions: string[];
_protocol?: string;
_strictProtocols: string[];
_strictValidators?: Map<string, Validator>;
_pendingCalls: Map<string, Record<string, any>>;
_pendingResponses: Map<string, {
abort: {
(reason?: any): void;
(reason?: any): void;
};
promise: Promise<any>;
}>;
_outboundMsgBuffer: string[];
_connectedOnce: boolean;
_backoffStrategy?: ExponentialStrategy;
_badMessagesCount: number;
_reconnectAttempt: number;
_options: RPC_ClientOptions;
_connectionUrl: string;
_connectPromise: Promise<{
response: any;
}>;
_nextPingTimeout: NodeJS.Timeout;
protected _identity?: string;
private _wildcardHandler;
private _handlers;
protected _state: number;
private _callQueue;
protected _ws?: WebSocket;
private _wsAbortController?;
private _keepAliveAbortController?;
private _pendingPingResponse;
private _lastPingTime;
private _closePromise?;
private _protocolOptions;
protected _protocol?: string;
private _strictProtocols;
private _strictValidators?;
private _pendingCalls;
private _pendingResponses;
private _outboundMsgBuffer;
private _connectedOnce;
private _backoffStrategy?;
private _badMessagesCount;
private _reconnectAttempt;
protected _options: RPC_ClientOptions;
private _connectionUrl;
private _connectPromise;
private _nextPingTimeout;
static OPEN: number;
static CONNECTING: number;
static CLOSING: number;
Expand All @@ -92,22 +77,17 @@ declare class RPC_Client extends EventEmitter {
* @returns {Promise<undefined>} Resolves when connected, rejects on failure
*/
connect(): Promise<any>;
_keepAlive(): Promise<void>;
_tryReconnect(): Promise<void>;
_beginConnect(): Promise<{
response: any;
}>;
private _keepAlive;
private _tryReconnect;
private _beginConnect;
/**
* Start consuming from a WebSocket
* @param {WebSocket} ws - A WebSocket instance
* @param {EventBuffer} leadMsgBuffer - A buffer which traps all 'message' events
*/
_attachWebsocket(ws: WebSocket, leadMsgBuffer?: EventBuffer): void;
_handleDisconnect({ code, reason }: {
code: number;
reason: Buffer;
}): void;
_rejectPendingCalls(abortReason: string): void;
protected _attachWebsocket(ws: WebSocket, leadMsgBuffer?: EventBuffer): void;
private _handleDisconnect;
private _rejectPendingCalls;
/**
* Call a method on a remote RPCClient or RPCServerClient.
* @param {string} method - The RPC method to call.
Expand All @@ -119,7 +99,7 @@ declare class RPC_Client extends EventEmitter {
* @returns Promise<*> - Response value from the remote handler.
*/
call(method: any, params?: any, options?: Record<string, any>): Promise<unknown>;
_call(method: any, params: any, options?: Record<string, any>): Promise<any>;
private _call;
/**
* Closes the RPCClient.
* @param {Object} options - Close options
Expand All @@ -139,12 +119,12 @@ declare class RPC_Client extends EventEmitter {
code: number | undefined;
reason: string | undefined;
} | undefined>;
_awaitUntilPendingSettled(): Promise<PromiseSettledResult<any>[]>;
_deferNextPing(): void;
_onMessage(buffer: Buffer): void;
_onCall(msgId: string, method: string, params: any): Promise<void>;
_onCallResult(msgId: string, result: any): any;
_onCallError(msgId: string, errorCode: string, errorDescription: string, errorDetails: Record<string, any>): void;
private _awaitUntilPendingSettled;
private _deferNextPing;
private _onMessage;
private _onCall;
private _onCallResult;
private _onCallError;
/**
* Send a message to the RPCServer. While socket is connecting, the message is queued and send when open.
* @param {Buffer|String} message - String to send via websocket
Expand Down
8 changes: 4 additions & 4 deletions lib/event-buffer.d.ts
Expand Up @@ -2,10 +2,10 @@
/// <reference types="node" />
import { EventEmitter } from "stream";
declare class EventBuffer {
_emitter: EventEmitter;
_event: string | symbol;
_collector: (...args: any) => void;
_buffer: any;
private _emitter;
private _event;
private _collector;
private _buffer;
constructor(emitter: EventEmitter, event: string | symbol);
condense(): any;
}
Expand Down
8 changes: 4 additions & 4 deletions lib/queue.d.ts
@@ -1,10 +1,10 @@
declare class Queue {
_pending: number;
_concurrency: number;
_queue: any[];
private _pending;
private _concurrency;
private _queue;
constructor();
setConcurrency(concurrency: number): void;
push(fn: any): Promise<unknown>;
_next(): Promise<false | undefined>;
private _next;
}
export default Queue;
25 changes: 10 additions & 15 deletions lib/server.d.ts
Expand Up @@ -4,10 +4,10 @@
/// <reference types="node" />
/// <reference types="node" />
import { IncomingMessage, Server } from "http";
import { ServerOptions, WebSocket, WebSocketServer } from "ws";
import { ServerOptions } from "ws";
import { EventEmitter } from "stream";
import { Validator } from "./validator";
import RpcServerClient, { IHandshakeInterface } from "./serverClient";
import { IHandshakeInterface } from "./serverClient";
import { Socket } from "net";
interface IOccpServiceOptions {
wssOptions?: ServerOptions;
Expand All @@ -21,23 +21,18 @@ interface IOccpServiceOptions {
strictMode?: boolean | string[];
strictModeValidators?: Validator[];
}
interface TPendingUpgrades {
session: Record<string, any>;
protocol: string;
handshake: IHandshakeInterface;
}
declare class RPCServer extends EventEmitter {
_httpServerAbortControllers: Set<AbortController>;
_state: number;
_clients: Set<RpcServerClient>;
_pendingUpgrades: WeakMap<IncomingMessage, TPendingUpgrades>;
_options: IOccpServiceOptions;
_wss: WebSocketServer;
_strictValidators: Map<string, Validator>;
private _httpServerAbortControllers;
private _state;
private _clients;
private _pendingUpgrades;
private _options;
private _wss;
private _strictValidators;
authCallback: (accept: (session?: Record<string, any>, protocol?: string | false) => void, reject: (code: number, message: string) => void, handshake: IHandshakeInterface, signal: AbortSignal) => void;
constructor({ ...options }: IOccpServiceOptions, _callback?: () => void);
reconfigure(options: any): void;
_onConnection(websocket: WebSocket, request: IncomingMessage): Promise<void>;
private _onConnection;
get handleUpgrade(): (request: IncomingMessage, socket: Socket, head: Buffer) => Promise<void>;
auth(cb: (accept: (session?: Record<string, any>, protocol?: string | false) => void, reject: (code: number, message: string) => void, handshake: IHandshakeInterface, signal?: AbortSignal) => void): void;
listen(port: any, host?: any, options?: Record<string, any>): Promise<Server<typeof IncomingMessage, typeof import("http").ServerResponse>>;
Expand Down
4 changes: 2 additions & 2 deletions lib/serverClient.d.ts
Expand Up @@ -14,8 +14,8 @@ export interface IHandshakeInterface {
password: Buffer | undefined;
}
declare class RpcServerClient extends RPC_Client {
_session: Record<string, any>;
_handshake: IHandshakeInterface;
private _session;
private _handshake;
constructor({ ...options }: RPC_ClientOptions, { ws, handshake, session, }: {
ws: WebSocket;
session: Record<string, any>;
Expand Down

0 comments on commit f686cd6

Please sign in to comment.