@socket-mesh/core 1.0.3 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,49 +1,48 @@
1
- import { CodecEngine } from "@socket-mesh/formatter";
2
- import ws from "isomorphic-ws";
3
- import { Plugin } from "./plugins/plugin.js";
4
- import { AnyRequest, InvokeMethodRequest, InvokeServiceRequest, TransmitMethodRequest, TransmitServiceRequest } from "./request.js";
5
- import { AnyPacket } from "./packet.js";
6
- import { FunctionReturnType, MethodMap, PrivateMethodMap, PublicMethodMap, ServiceMap } from "./maps/method-map.js";
7
- import { AnyResponse } from "./response.js";
8
- import { AuthToken, SignedAuthToken } from "@socket-mesh/auth";
9
- import { Socket, SocketOptions, SocketStatus, StreamCleanupMode } from "./socket.js";
1
+ import { AuthToken, SignedAuthToken } from '@socket-mesh/auth';
2
+ import { CodecEngine } from '@socket-mesh/formatter';
3
+ import ws from 'isomorphic-ws';
4
+ import { FunctionReturnType, MethodMap, PrivateMethodMap, PublicMethodMap, ServiceMap } from './maps/method-map.js';
5
+ import { AnyPacket } from './packet.js';
6
+ import { Plugin } from './plugins/plugin.js';
7
+ import { AnyRequest, InvokeMethodRequest, InvokeServiceRequest, TransmitMethodRequest, TransmitServiceRequest } from './request.js';
8
+ import { AnyResponse } from './response.js';
9
+ import { Socket, SocketOptions, SocketStatus, StreamCleanupMode } from './socket.js';
10
10
  export type CallIdGenerator = () => number;
11
+ export interface InboundMessage<TIncoming extends MethodMap, TOutgoing extends PublicMethodMap, TPrivateOutgoing extends PrivateMethodMap, TService extends ServiceMap> {
12
+ packet: (AnyPacket<TIncoming, TService> | AnyResponse<TOutgoing, TPrivateOutgoing, TService>)[] | (AnyPacket<TIncoming, TService> | AnyResponse<TOutgoing, TPrivateOutgoing, TService>) | null;
13
+ timestamp: Date;
14
+ }
11
15
  export interface InvokeMethodOptions<TMethodMap extends MethodMap, TMethod extends keyof TMethodMap> {
16
+ ackTimeoutMs?: false | number;
12
17
  method: TMethod;
13
- ackTimeoutMs?: number | false;
14
18
  }
15
19
  export interface InvokeServiceOptions<TServiceMap extends ServiceMap, TService extends keyof TServiceMap, TMethod extends keyof TServiceMap[TService]> {
16
- service: TService;
20
+ ackTimeoutMs?: false | number;
17
21
  method: TMethod;
18
- ackTimeoutMs?: number | false;
19
- }
20
- export interface InboundMessage<TIncoming extends MethodMap, TOutgoing extends PublicMethodMap, TPrivateOutgoing extends PrivateMethodMap, TService extends ServiceMap> {
21
- timestamp: Date;
22
- packet: (AnyPacket<TIncoming, TService> | AnyResponse<TOutgoing, TPrivateOutgoing, TService>) | (AnyPacket<TIncoming, TService> | AnyResponse<TOutgoing, TPrivateOutgoing, TService>)[];
22
+ service: TService;
23
23
  }
24
24
  export declare class SocketTransport<TIncoming extends MethodMap, TOutgoing extends PublicMethodMap, TPrivateOutgoing extends PrivateMethodMap, TService extends ServiceMap, TState extends object> {
25
- private _socket;
26
- private _webSocket;
25
+ private _authToken;
26
+ private readonly _callbackMap;
27
+ private readonly _callIdGenerator;
28
+ private readonly _handlers;
27
29
  private _inboundProcessedMessageCount;
28
30
  private _inboundReceivedMessageCount;
31
+ private _isReady;
29
32
  private _outboundPreparedMessageCount;
30
33
  private _outboundSentMessageCount;
31
- private _isReady;
32
- private _authToken?;
33
- private _signedAuthToken?;
34
- private readonly _callIdGenerator;
35
- private readonly _callbackMap;
36
- private readonly _handlers;
37
- private _onUnhandledRequest;
34
+ private _pingTimeoutRef;
35
+ private _signedAuthToken;
36
+ private _socket;
37
+ private _webSocket;
38
+ ackTimeoutMs: number;
38
39
  readonly codecEngine: CodecEngine;
40
+ id: null | string;
39
41
  readonly plugins: Plugin<TIncoming, TOutgoing, TPrivateOutgoing, TService, TState>[];
40
42
  streamCleanupMode: StreamCleanupMode;
41
- id: string | null;
42
- ackTimeoutMs: number;
43
- private _pingTimeoutRef;
44
43
  protected constructor(options?: SocketOptions<TIncoming, TOutgoing, TPrivateOutgoing, TService, TState>);
45
44
  protected abortAllPendingCallbacksDueToBadConnection(status: SocketStatus): void;
46
- get authToken(): AuthToken;
45
+ get authToken(): AuthToken | null;
47
46
  changeToUnauthenticatedState(): Promise<boolean>;
48
47
  protected decode(data: string | ws.RawData): any;
49
48
  disconnect(code?: number, reason?: string): void;
@@ -51,6 +50,12 @@ export declare class SocketTransport<TIncoming extends MethodMap, TOutgoing exte
51
50
  getInboundBackpressure(): number;
52
51
  getOutboundBackpressure(): number;
53
52
  protected handleInboudMessage({ packet, timestamp }: InboundMessage<TIncoming, TOutgoing, TPrivateOutgoing, TService>): Promise<void>;
53
+ invoke<TMethod extends keyof TOutgoing>(method: TMethod, arg?: Parameters<TOutgoing[TMethod]>[0]): [Promise<FunctionReturnType<TOutgoing[TMethod]>>, () => void];
54
+ invoke<TServiceName extends keyof TService, TMethod extends keyof TService[TServiceName]>(options: [TServiceName, TMethod, (false | number)?], arg?: Parameters<TService[TServiceName][TMethod]>[0]): [Promise<FunctionReturnType<TService[TServiceName][TMethod]>>, () => void];
55
+ invoke<TServiceName extends keyof TService, TMethod extends keyof TService[TServiceName]>(options: InvokeServiceOptions<TService, TServiceName, TMethod>, arg?: Parameters<TService[TServiceName][TMethod]>[0]): [Promise<FunctionReturnType<TService[TServiceName][TMethod]>>, () => void];
56
+ invoke<TMethod extends keyof TOutgoing>(options: InvokeMethodOptions<TOutgoing, TMethod>, arg?: Parameters<TOutgoing[TMethod]>[0]): [Promise<FunctionReturnType<TOutgoing[TMethod]>>, () => void];
57
+ invoke<TMethod extends keyof TPrivateOutgoing>(method: TMethod, arg: Parameters<TPrivateOutgoing[TMethod]>[0]): [Promise<FunctionReturnType<TPrivateOutgoing[TMethod]>>, () => void];
58
+ invoke<TMethod extends keyof TPrivateOutgoing>(options: InvokeMethodOptions<TPrivateOutgoing, TMethod>, arg?: Parameters<TPrivateOutgoing[TMethod]>[0]): [Promise<FunctionReturnType<TPrivateOutgoing[TMethod]>>, () => void];
54
59
  protected onClose(code: number, reason?: Buffer | string): void;
55
60
  protected onDisconnect(status: SocketStatus, code: number, reason?: string): void;
56
61
  onError(error: Error): void;
@@ -65,30 +70,23 @@ export declare class SocketTransport<TIncoming extends MethodMap, TOutgoing exte
65
70
  private onSocketMessage;
66
71
  protected onTransmit<TServiceName extends keyof TService, TServiceMethod extends keyof TService[TServiceName], TMethod extends keyof TOutgoing>(request: TransmitMethodRequest<TOutgoing, TMethod> | TransmitServiceRequest<TService, TServiceName, TServiceMethod>): void;
67
72
  protected onUnhandledRequest(packet: AnyPacket<TIncoming, TService>): boolean;
68
- protected resetPingTimeout(timeoutMs: number | false, code: number): void;
73
+ protected resetPingTimeout(timeoutMs: false | number, code: number): void;
69
74
  send(data: Buffer | string): Promise<void>;
70
75
  protected sendRequest(requests: (AnyRequest<TOutgoing, TPrivateOutgoing, TService>)[]): void;
71
76
  protected sendRequest(index: number, requests: (AnyRequest<TOutgoing, TPrivateOutgoing, TService>)[]): void;
72
77
  protected sendResponse(responses: (AnyResponse<TOutgoing, TPrivateOutgoing, TService>)[]): void;
73
78
  protected sendResponse(index: number, responses: (AnyResponse<TOutgoing, TPrivateOutgoing, TService>)[]): void;
74
- setAuthorization(authToken: AuthToken): Promise<boolean>;
75
79
  setAuthorization(signedAuthToken: SignedAuthToken, authToken?: AuthToken): Promise<boolean>;
76
80
  setReadyStatus(pingTimeoutMs: number, authError?: Error): void;
77
- get signedAuthToken(): SignedAuthToken;
81
+ get signedAuthToken(): null | SignedAuthToken;
78
82
  get socket(): Socket<TIncoming, TOutgoing, TPrivateOutgoing, TService, TState>;
79
83
  set socket(value: Socket<TIncoming, TOutgoing, TPrivateOutgoing, TService, TState>);
80
84
  get status(): SocketStatus;
81
- triggerAuthenticationEvents(wasSigned: boolean, wasAuthenticated: boolean): void;
82
85
  transmit<TMethod extends keyof TOutgoing>(method: TMethod, arg?: Parameters<TOutgoing[TMethod]>[0]): Promise<void>;
83
86
  transmit<TServiceName extends keyof TService, TMethod extends keyof TService[TServiceName]>(options: [TServiceName, TMethod], arg?: Parameters<TService[TServiceName][TMethod]>[0]): Promise<void>;
84
87
  transmit<TMethod extends keyof TPrivateOutgoing>(method: TMethod, arg?: Parameters<TPrivateOutgoing[TMethod]>[0]): Promise<void>;
85
- invoke<TMethod extends keyof TOutgoing>(method: TMethod, arg?: Parameters<TOutgoing[TMethod]>[0]): [Promise<FunctionReturnType<TOutgoing[TMethod]>>, () => void];
86
- invoke<TServiceName extends keyof TService, TMethod extends keyof TService[TServiceName]>(options: [TServiceName, TMethod, (number | false)?], arg?: Parameters<TService[TServiceName][TMethod]>[0]): [Promise<FunctionReturnType<TService[TServiceName][TMethod]>>, () => void];
87
- invoke<TServiceName extends keyof TService, TMethod extends keyof TService[TServiceName]>(options: InvokeServiceOptions<TService, TServiceName, TMethod>, arg?: Parameters<TService[TServiceName][TMethod]>[0]): [Promise<FunctionReturnType<TService[TServiceName][TMethod]>>, () => void];
88
- invoke<TMethod extends keyof TOutgoing>(options: InvokeMethodOptions<TOutgoing, TMethod>, arg?: Parameters<TOutgoing[TMethod]>[0]): [Promise<FunctionReturnType<TOutgoing[TMethod]>>, () => void];
89
- invoke<TMethod extends keyof TPrivateOutgoing>(method: TMethod, arg: Parameters<TPrivateOutgoing[TMethod]>[0]): [Promise<FunctionReturnType<TPrivateOutgoing[TMethod]>>, () => void];
90
- invoke<TMethod extends keyof TPrivateOutgoing>(options: InvokeMethodOptions<TPrivateOutgoing, TMethod>, arg?: Parameters<TPrivateOutgoing[TMethod]>[0]): [Promise<FunctionReturnType<TPrivateOutgoing[TMethod]>>, () => void];
88
+ triggerAuthenticationEvents(wasSigned: boolean, wasAuthenticated: boolean): void;
91
89
  get url(): string;
92
- protected get webSocket(): ws.WebSocket;
93
- protected set webSocket(value: ws.WebSocket | null);
90
+ protected get webSocket(): null | ws.WebSocket;
91
+ protected set webSocket(value: null | ws.WebSocket);
94
92
  }