@socket-mesh/core 1.0.0 → 1.0.3
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.
- package/dist/maps/handler-map.d.ts +3 -3
- package/dist/maps/index.d.ts +0 -1
- package/dist/maps/index.js +0 -1
- package/dist/packet.d.ts +2 -3
- package/dist/plugins/plugin.d.ts +27 -27
- package/dist/request-handler.d.ts +5 -5
- package/dist/request.d.ts +8 -9
- package/dist/response.d.ts +3 -4
- package/dist/socket-event.d.ts +6 -16
- package/dist/socket-transport.d.ts +34 -33
- package/dist/socket-transport.js +44 -61
- package/dist/socket.d.ts +22 -28
- package/dist/socket.js +0 -3
- package/package.json +23 -23
- package/dist/maps/socket-map.d.ts +0 -15
- package/dist/maps/socket-map.js +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RequestHandler } from "../request-handler.js";
|
|
2
|
-
import {
|
|
3
|
-
export type HandlerMap<
|
|
4
|
-
[K in keyof
|
|
2
|
+
import { MethodMap, PrivateMethodMap, PublicMethodMap, ServiceMap } from "./method-map.js";
|
|
3
|
+
export type HandlerMap<TIncoming extends MethodMap, TOutgoing extends PublicMethodMap, TPrivateOutgoing extends PrivateMethodMap, TService extends ServiceMap, TState extends object> = Partial<{
|
|
4
|
+
[K in keyof TIncoming]: RequestHandler<Parameters<TIncoming[K]>[0], ReturnType<TIncoming[K]>, TIncoming, TOutgoing, TPrivateOutgoing, TService, TState>;
|
|
5
5
|
}>;
|
package/dist/maps/index.d.ts
CHANGED
package/dist/maps/index.js
CHANGED
package/dist/packet.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { MethodMap, ServiceMap } from "./maps/method-map.js";
|
|
2
|
-
|
|
3
|
-
export type AnyPacket<T extends SocketMap> = ServicePacket<T['Service']> | MethodPacket<T['Incoming']>;
|
|
2
|
+
export type AnyPacket<TIncoming extends MethodMap, TService extends ServiceMap> = ServicePacket<TService> | MethodPacket<TIncoming>;
|
|
4
3
|
export type ServicePacket<TServiceMap extends ServiceMap> = {
|
|
5
4
|
[TService in keyof TServiceMap]: {
|
|
6
5
|
[TMethod in keyof TServiceMap[TService]]: ServiceRequestPacket<TServiceMap, TService, TMethod>;
|
|
@@ -23,5 +22,5 @@ export interface MethodRequestPacket<TMethodMap extends MethodMap, TMethod exten
|
|
|
23
22
|
data: Parameters<TMethodMap[TMethod]>[0];
|
|
24
23
|
ackTimeoutMs?: number | boolean;
|
|
25
24
|
}
|
|
26
|
-
export declare function isRequestPacket<
|
|
25
|
+
export declare function isRequestPacket<TIncoming extends MethodMap, TService extends ServiceMap>(packet: unknown): packet is AnyPacket<TIncoming, TService>;
|
|
27
26
|
export {};
|
package/dist/plugins/plugin.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { EmptySocketMap, SocketMap } from "../maps/socket-map.js";
|
|
2
1
|
import { AnyPacket } from "../packet.js";
|
|
3
2
|
import { AnyRequest } from "../request.js";
|
|
4
3
|
import { AnyResponse } from "../response.js";
|
|
@@ -6,45 +5,46 @@ import { SocketTransport } from "../socket-transport.js";
|
|
|
6
5
|
import { Socket, SocketStatus } from "../socket.js";
|
|
7
6
|
import ws from "isomorphic-ws";
|
|
8
7
|
import { HandlerMap } from "../maps/handler-map.js";
|
|
8
|
+
import { MethodMap, PrivateMethodMap, PublicMethodMap, ServiceMap } from "../maps/method-map.js";
|
|
9
9
|
export type PluginType = 'request' | 'response' | 'handshake';
|
|
10
|
-
export interface PluginArgs<
|
|
11
|
-
socket: Socket<
|
|
12
|
-
transport: SocketTransport<
|
|
10
|
+
export interface PluginArgs<TIncoming extends MethodMap, TOutgoing extends PublicMethodMap, TPrivateOutgoing extends PrivateMethodMap, TService extends ServiceMap, TState extends object> {
|
|
11
|
+
socket: Socket<TIncoming, TOutgoing, TPrivateOutgoing, TService, TState>;
|
|
12
|
+
transport: SocketTransport<TIncoming, TOutgoing, TPrivateOutgoing, TService, TState>;
|
|
13
13
|
}
|
|
14
|
-
export interface DisconnectedPluginArgs<
|
|
14
|
+
export interface DisconnectedPluginArgs<TIncoming extends MethodMap, TOutgoing extends PublicMethodMap, TPrivateOutgoing extends PrivateMethodMap, TService extends ServiceMap, TState extends object> extends PluginArgs<TIncoming, TOutgoing, TPrivateOutgoing, TService, TState> {
|
|
15
15
|
status: SocketStatus;
|
|
16
16
|
code: number;
|
|
17
17
|
reason?: string;
|
|
18
18
|
}
|
|
19
|
-
export interface MessagePluginArgs<
|
|
19
|
+
export interface MessagePluginArgs<TIncoming extends MethodMap, TOutgoing extends PublicMethodMap, TPrivateOutgoing extends PrivateMethodMap, TService extends ServiceMap, TState extends object> extends PluginArgs<TIncoming, TOutgoing, TPrivateOutgoing, TService, TState> {
|
|
20
20
|
timestamp: Date;
|
|
21
|
-
packet: AnyPacket<
|
|
21
|
+
packet: AnyPacket<TIncoming, TService> | AnyResponse<TOutgoing, TPrivateOutgoing, TService>;
|
|
22
22
|
}
|
|
23
|
-
export interface MessageRawPluginArgs<
|
|
23
|
+
export interface MessageRawPluginArgs<TIncoming extends MethodMap, TOutgoing extends PublicMethodMap, TPrivateOutgoing extends PrivateMethodMap, TService extends ServiceMap, TState extends object> extends PluginArgs<TIncoming, TOutgoing, TPrivateOutgoing, TService, TState> {
|
|
24
24
|
timestamp: Date;
|
|
25
25
|
message: ws.RawData | string;
|
|
26
26
|
promise: Promise<void>;
|
|
27
27
|
}
|
|
28
|
-
export interface SendRequestPluginArgs<
|
|
29
|
-
requests: AnyRequest<
|
|
30
|
-
cont: (requests: AnyRequest<
|
|
28
|
+
export interface SendRequestPluginArgs<TIncoming extends MethodMap, TOutgoing extends PublicMethodMap, TPrivateOutgoing extends PrivateMethodMap, TService extends ServiceMap, TState extends object> extends PluginArgs<TIncoming, TOutgoing, TPrivateOutgoing, TService, TState> {
|
|
29
|
+
requests: AnyRequest<TOutgoing, TPrivateOutgoing, TService>[];
|
|
30
|
+
cont: (requests: AnyRequest<TOutgoing, TPrivateOutgoing, TService>[]) => void;
|
|
31
31
|
}
|
|
32
|
-
export interface SendResponsePluginArgs<
|
|
33
|
-
responses: AnyResponse<
|
|
34
|
-
cont: (requests: AnyResponse<
|
|
32
|
+
export interface SendResponsePluginArgs<TIncoming extends MethodMap, TOutgoing extends PublicMethodMap, TPrivateOutgoing extends PrivateMethodMap, TService extends ServiceMap, TState extends object> extends PluginArgs<TIncoming, TOutgoing, TPrivateOutgoing, TService, TState> {
|
|
33
|
+
responses: AnyResponse<TOutgoing, TPrivateOutgoing, TService>[];
|
|
34
|
+
cont: (requests: AnyResponse<TOutgoing, TPrivateOutgoing, TService>[]) => void;
|
|
35
35
|
}
|
|
36
|
-
export interface Plugin<
|
|
36
|
+
export interface Plugin<TIncoming extends MethodMap, TOutgoing extends PublicMethodMap, TPrivateOutgoing extends PrivateMethodMap, TService extends ServiceMap, TState extends object> {
|
|
37
37
|
type: string;
|
|
38
|
-
handlers?: HandlerMap<
|
|
39
|
-
onAuthenticated?(options: PluginArgs<
|
|
40
|
-
onClose?(options: PluginArgs<
|
|
41
|
-
onDeauthenticate?(options: PluginArgs<
|
|
42
|
-
onDisconnected?(options: DisconnectedPluginArgs<
|
|
43
|
-
onEnd?(options: PluginArgs<
|
|
44
|
-
onMessage?(options: MessagePluginArgs<
|
|
45
|
-
onMessageRaw?(options: MessageRawPluginArgs<
|
|
46
|
-
onOpen?(options: PluginArgs<
|
|
47
|
-
onReady?(options: PluginArgs<
|
|
48
|
-
sendRequest?(options: SendRequestPluginArgs<
|
|
49
|
-
sendResponse?(options: SendResponsePluginArgs<
|
|
38
|
+
handlers?: HandlerMap<TIncoming, TOutgoing, TPrivateOutgoing, TService, TState>;
|
|
39
|
+
onAuthenticated?(options: PluginArgs<TIncoming, TOutgoing, TPrivateOutgoing, TService, TState>): void;
|
|
40
|
+
onClose?(options: PluginArgs<TIncoming, TOutgoing, TPrivateOutgoing, TService, TState>): void;
|
|
41
|
+
onDeauthenticate?(options: PluginArgs<TIncoming, TOutgoing, TPrivateOutgoing, TService, TState>): void;
|
|
42
|
+
onDisconnected?(options: DisconnectedPluginArgs<TIncoming, TOutgoing, TPrivateOutgoing, TService, TState>): void;
|
|
43
|
+
onEnd?(options: PluginArgs<TIncoming, TOutgoing, TPrivateOutgoing, TService, TState>): void;
|
|
44
|
+
onMessage?(options: MessagePluginArgs<TIncoming, TOutgoing, TPrivateOutgoing, TService, TState>): Promise<AnyPacket<TIncoming, TService> | AnyResponse<TOutgoing, TPrivateOutgoing, TService>>;
|
|
45
|
+
onMessageRaw?(options: MessageRawPluginArgs<TIncoming, TOutgoing, TPrivateOutgoing, TService, TState>): Promise<ws.RawData | string>;
|
|
46
|
+
onOpen?(options: PluginArgs<TIncoming, TOutgoing, TPrivateOutgoing, TService, TState>): void;
|
|
47
|
+
onReady?(options: PluginArgs<TIncoming, TOutgoing, TPrivateOutgoing, TService, TState>): void;
|
|
48
|
+
sendRequest?(options: SendRequestPluginArgs<TIncoming, TOutgoing, TPrivateOutgoing, TService, TState>): void;
|
|
49
|
+
sendResponse?(options: SendResponsePluginArgs<TIncoming, TOutgoing, TPrivateOutgoing, TService, TState>): void;
|
|
50
50
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Socket } from "./socket.js";
|
|
2
2
|
import { SocketTransport } from "./socket-transport.js";
|
|
3
|
-
import {
|
|
4
|
-
export interface RequestHandlerArgsOptions<TOptions,
|
|
3
|
+
import { MethodMap, PrivateMethodMap, PublicMethodMap, ServiceMap } from "./maps/method-map.js";
|
|
4
|
+
export interface RequestHandlerArgsOptions<TOptions, TIncoming extends MethodMap, TOutgoing extends PublicMethodMap, TPrivateOutgoing extends PrivateMethodMap, TService extends ServiceMap, TState extends object, TSocket extends Socket<TIncoming, TOutgoing, TPrivateOutgoing, TService, TState> = Socket<TIncoming, TOutgoing, TPrivateOutgoing, TService, TState>, TTransport extends SocketTransport<TIncoming, TOutgoing, TPrivateOutgoing, TService, TState> = SocketTransport<TIncoming, TOutgoing, TPrivateOutgoing, TService, TState>> {
|
|
5
5
|
isRpc: boolean;
|
|
6
6
|
method: string;
|
|
7
7
|
socket: TSocket;
|
|
@@ -9,7 +9,7 @@ export interface RequestHandlerArgsOptions<TOptions, T extends SocketMap, TSocke
|
|
|
9
9
|
timeoutMs?: number | boolean;
|
|
10
10
|
options?: TOptions;
|
|
11
11
|
}
|
|
12
|
-
export declare class RequestHandlerArgs<TOptions,
|
|
12
|
+
export declare class RequestHandlerArgs<TOptions, TIncoming extends MethodMap = {}, TOutgoing extends PublicMethodMap = {}, TPrivateOutgoing extends PrivateMethodMap = {}, TService extends ServiceMap = {}, TState extends object = {}, TSocket extends Socket<TIncoming, TOutgoing, TPrivateOutgoing, TService, TState> = Socket<TIncoming, TOutgoing, TPrivateOutgoing, TService, TState>, TTransport extends SocketTransport<TIncoming, TOutgoing, TPrivateOutgoing, TService, TState> = SocketTransport<TIncoming, TOutgoing, TPrivateOutgoing, TService, TState>> {
|
|
13
13
|
isRpc: boolean;
|
|
14
14
|
method: string;
|
|
15
15
|
options: TOptions;
|
|
@@ -17,8 +17,8 @@ export declare class RequestHandlerArgs<TOptions, T extends SocketMap = EmptySoc
|
|
|
17
17
|
socket: TSocket;
|
|
18
18
|
timeoutMs?: number | boolean;
|
|
19
19
|
transport: TTransport;
|
|
20
|
-
constructor(options: RequestHandlerArgsOptions<TOptions,
|
|
20
|
+
constructor(options: RequestHandlerArgsOptions<TOptions, TIncoming, TOutgoing, TPrivateOutgoing, TService, TState, TSocket, TTransport>);
|
|
21
21
|
checkTimeout(timeLeftMs?: number): void;
|
|
22
22
|
getRemainingTimeMs(): number;
|
|
23
23
|
}
|
|
24
|
-
export type RequestHandler<TOptions, U,
|
|
24
|
+
export type RequestHandler<TOptions, U, TIncoming extends MethodMap, TOutgoing extends PublicMethodMap, TPrivateOutgoing extends PrivateMethodMap, TService extends ServiceMap, TState extends object, TSocket extends Socket<TIncoming, TOutgoing, TPrivateOutgoing, TService, TState> = Socket<TIncoming, TOutgoing, TPrivateOutgoing, TService, TState>, TTransport extends SocketTransport<TIncoming, TOutgoing, TPrivateOutgoing, TService, TState> = SocketTransport<TIncoming, TOutgoing, TPrivateOutgoing, TService, TState>> = (args: RequestHandlerArgs<TOptions, TIncoming, TOutgoing, TPrivateOutgoing, TService, TState, TSocket, TTransport>) => Promise<U>;
|
package/dist/request.d.ts
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
import { MethodMap, ServiceMap } from "./maps/method-map.js";
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
-
export declare
|
|
5
|
-
export declare class RequestCollection<T extends SocketMap> {
|
|
1
|
+
import { MethodMap, PrivateMethodMap, PublicMethodMap, ServiceMap } from "./maps/method-map.js";
|
|
2
|
+
export type AnyRequest<TOutgoing extends PublicMethodMap, TPrivateOutgoing extends PrivateMethodMap, TService extends ServiceMap> = ServiceRequest<TService> | MethodRequest<TPrivateOutgoing> | MethodRequest<TOutgoing>;
|
|
3
|
+
export declare function abortRequest<TOutgoing extends PublicMethodMap, TPrivateOutgoing extends PrivateMethodMap, TService extends ServiceMap>(request: AnyRequest<TOutgoing, TPrivateOutgoing, TService>, err: Error): void;
|
|
4
|
+
export declare class RequestCollection<TOutgoing extends PublicMethodMap, TPrivateOutgoing extends PrivateMethodMap, TService extends ServiceMap> {
|
|
6
5
|
private readonly _requests;
|
|
7
6
|
private readonly _callbacks;
|
|
8
|
-
constructor(requests: AnyRequest<
|
|
9
|
-
get items(): ReadonlyArray<AnyRequest<
|
|
7
|
+
constructor(requests: AnyRequest<TOutgoing, TPrivateOutgoing, TService> | AnyRequest<TOutgoing, TPrivateOutgoing, TService>[]);
|
|
8
|
+
get items(): ReadonlyArray<AnyRequest<TOutgoing, TPrivateOutgoing, TService>>;
|
|
10
9
|
listen(cb: () => void): void;
|
|
11
10
|
isDone(): boolean;
|
|
12
11
|
[Symbol.iterator](): {
|
|
13
12
|
next(): {
|
|
14
|
-
value: AnyRequest<
|
|
13
|
+
value: AnyRequest<TOutgoing, TPrivateOutgoing, TService>;
|
|
15
14
|
done: boolean;
|
|
16
15
|
} | {
|
|
17
16
|
done: boolean;
|
|
@@ -52,4 +51,4 @@ export interface InvokeMethodRequest<TMethodMap extends MethodMap, TMethod exten
|
|
|
52
51
|
timeoutId?: NodeJS.Timeout;
|
|
53
52
|
callback: (err: Error, result?: TMethodMap[TMethod]) => void | null;
|
|
54
53
|
}
|
|
55
|
-
export declare function isRequestDone<
|
|
54
|
+
export declare function isRequestDone<TOutgoing extends PublicMethodMap, TPrivateOutgoing extends PrivateMethodMap, TService extends ServiceMap>(request: AnyRequest<TOutgoing, TPrivateOutgoing, TService>): boolean;
|
package/dist/response.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { MethodMap, ServiceMap } from "./maps/method-map.js";
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
-
export declare function isResponsePacket<T extends SocketMap>(packet?: unknown): packet is AnyResponse<T>;
|
|
1
|
+
import { MethodMap, PrivateMethodMap, PublicMethodMap, ServiceMap } from "./maps/method-map.js";
|
|
2
|
+
export type AnyResponse<TOutgoing extends PublicMethodMap, TPrivateOutgoing extends PrivateMethodMap, TService extends ServiceMap> = Response | ErrorResponse | ServiceDataResponse<TService> | MethodDataResponse<TPrivateOutgoing> | MethodDataResponse<TOutgoing>;
|
|
3
|
+
export declare function isResponsePacket<TOutgoing extends PublicMethodMap, TPrivateOutgoing extends PrivateMethodMap, TService extends ServiceMap>(packet?: unknown): packet is AnyResponse<TOutgoing, TPrivateOutgoing, TService>;
|
|
5
4
|
export type ServiceDataResponse<TServiceMap extends ServiceMap> = {
|
|
6
5
|
[TService in keyof TServiceMap]: {
|
|
7
6
|
[TMethod in keyof TServiceMap[TService]]: DataResponse<ReturnType<TServiceMap[TService][TMethod]>>;
|
package/dist/socket-event.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import ws from "isomorphic-ws";
|
|
2
|
-
import { ClientRequest, IncomingMessage } from "http";
|
|
3
2
|
import { MethodPacket, ServicePacket } from "./packet.js";
|
|
4
3
|
import { AuthToken, SignedAuthToken } from "@socket-mesh/auth";
|
|
5
4
|
import { AnyResponse } from "./response.js";
|
|
6
|
-
import {
|
|
7
|
-
export type SocketEvent<
|
|
5
|
+
import { MethodMap, PrivateMethodMap, PublicMethodMap, ServiceMap } from "./maps/method-map.js";
|
|
6
|
+
export type SocketEvent<TIncoming extends MethodMap, TOutgoing extends PublicMethodMap, TPrivateOutgoing extends PrivateMethodMap, TService extends ServiceMap> = AuthStateChangeEvent | RemoveAuthTokenEvent | AuthenticateEvent | BadAuthTokenEvent | CloseEvent | ConnectEvent | ConnectingEvent | DeauthenticateEvent | DisconnectEvent | ErrorEvent | MessageEvent | PingEvent | PongEvent | RequestEvent<TIncoming, TService> | ResponseEvent<TOutgoing, TPrivateOutgoing, TService>;
|
|
8
7
|
export type AuthStateChangeEvent = AuthenticatedChangeEvent | DeauthenticatedChangeEvent;
|
|
9
8
|
export interface AuthenticatedChangeEvent {
|
|
10
9
|
isAuthenticated: true;
|
|
@@ -53,24 +52,15 @@ export interface MessageEvent {
|
|
|
53
52
|
isBinary: boolean;
|
|
54
53
|
}
|
|
55
54
|
export interface PingEvent {
|
|
56
|
-
data: Buffer;
|
|
57
55
|
}
|
|
58
56
|
export interface PongEvent {
|
|
59
|
-
data: Buffer;
|
|
60
57
|
}
|
|
61
58
|
export interface RemoveAuthTokenEvent {
|
|
62
59
|
oldAuthToken: SignedAuthToken;
|
|
63
60
|
}
|
|
64
|
-
export interface RequestEvent<
|
|
65
|
-
request: ServicePacket<
|
|
61
|
+
export interface RequestEvent<TIncoming extends MethodMap, TService extends ServiceMap> {
|
|
62
|
+
request: ServicePacket<TService> | MethodPacket<TIncoming>;
|
|
66
63
|
}
|
|
67
|
-
export interface ResponseEvent<
|
|
68
|
-
response: AnyResponse<
|
|
69
|
-
}
|
|
70
|
-
export interface UnexpectedResponseEvent {
|
|
71
|
-
request: ClientRequest;
|
|
72
|
-
response: IncomingMessage;
|
|
73
|
-
}
|
|
74
|
-
export interface UpgradeEvent {
|
|
75
|
-
request: IncomingMessage;
|
|
64
|
+
export interface ResponseEvent<TOutgoing extends PublicMethodMap, TPrivateOutgoing extends PrivateMethodMap, TService extends ServiceMap> {
|
|
65
|
+
response: AnyResponse<TOutgoing, TPrivateOutgoing, TService>;
|
|
76
66
|
}
|
|
@@ -3,12 +3,10 @@ import ws from "isomorphic-ws";
|
|
|
3
3
|
import { Plugin } from "./plugins/plugin.js";
|
|
4
4
|
import { AnyRequest, InvokeMethodRequest, InvokeServiceRequest, TransmitMethodRequest, TransmitServiceRequest } from "./request.js";
|
|
5
5
|
import { AnyPacket } from "./packet.js";
|
|
6
|
-
import {
|
|
7
|
-
import { FunctionReturnType, MethodMap, ServiceMap } from "./maps/method-map.js";
|
|
6
|
+
import { FunctionReturnType, MethodMap, PrivateMethodMap, PublicMethodMap, ServiceMap } from "./maps/method-map.js";
|
|
8
7
|
import { AnyResponse } from "./response.js";
|
|
9
8
|
import { AuthToken, SignedAuthToken } from "@socket-mesh/auth";
|
|
10
9
|
import { Socket, SocketOptions, SocketStatus, StreamCleanupMode } from "./socket.js";
|
|
11
|
-
import { SocketMap } from "./maps/socket-map.js";
|
|
12
10
|
export type CallIdGenerator = () => number;
|
|
13
11
|
export interface InvokeMethodOptions<TMethodMap extends MethodMap, TMethod extends keyof TMethodMap> {
|
|
14
12
|
method: TMethod;
|
|
@@ -19,7 +17,11 @@ export interface InvokeServiceOptions<TServiceMap extends ServiceMap, TService e
|
|
|
19
17
|
method: TMethod;
|
|
20
18
|
ackTimeoutMs?: number | false;
|
|
21
19
|
}
|
|
22
|
-
export
|
|
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>)[];
|
|
23
|
+
}
|
|
24
|
+
export declare class SocketTransport<TIncoming extends MethodMap, TOutgoing extends PublicMethodMap, TPrivateOutgoing extends PrivateMethodMap, TService extends ServiceMap, TState extends object> {
|
|
23
25
|
private _socket;
|
|
24
26
|
private _webSocket;
|
|
25
27
|
private _inboundProcessedMessageCount;
|
|
@@ -34,12 +36,12 @@ export declare class SocketTransport<T extends SocketMap> {
|
|
|
34
36
|
private readonly _handlers;
|
|
35
37
|
private _onUnhandledRequest;
|
|
36
38
|
readonly codecEngine: CodecEngine;
|
|
37
|
-
readonly plugins: Plugin<
|
|
39
|
+
readonly plugins: Plugin<TIncoming, TOutgoing, TPrivateOutgoing, TService, TState>[];
|
|
38
40
|
streamCleanupMode: StreamCleanupMode;
|
|
39
41
|
id: string | null;
|
|
40
42
|
ackTimeoutMs: number;
|
|
41
43
|
private _pingTimeoutRef;
|
|
42
|
-
protected constructor(options?: SocketOptions<
|
|
44
|
+
protected constructor(options?: SocketOptions<TIncoming, TOutgoing, TPrivateOutgoing, TService, TState>);
|
|
43
45
|
protected abortAllPendingCallbacksDueToBadConnection(status: SocketStatus): void;
|
|
44
46
|
get authToken(): AuthToken;
|
|
45
47
|
changeToUnauthenticatedState(): Promise<boolean>;
|
|
@@ -48,45 +50,44 @@ export declare class SocketTransport<T extends SocketMap> {
|
|
|
48
50
|
getBackpressure(): number;
|
|
49
51
|
getInboundBackpressure(): number;
|
|
50
52
|
getOutboundBackpressure(): number;
|
|
51
|
-
|
|
53
|
+
protected handleInboudMessage({ packet, timestamp }: InboundMessage<TIncoming, TOutgoing, TPrivateOutgoing, TService>): Promise<void>;
|
|
52
54
|
protected onClose(code: number, reason?: Buffer | string): void;
|
|
53
55
|
protected onDisconnect(status: SocketStatus, code: number, reason?: string): void;
|
|
54
56
|
onError(error: Error): void;
|
|
55
|
-
protected onInvoke<
|
|
56
|
-
protected onMessage(data: ws.
|
|
57
|
+
protected onInvoke<TServiceName extends keyof TService, TServiceMethod extends keyof TService[TServiceName], TMethod extends keyof TOutgoing, TPrivateMethod extends keyof TPrivateOutgoing>(request: InvokeMethodRequest<TOutgoing, TMethod> | InvokeMethodRequest<TPrivateOutgoing, TPrivateMethod> | InvokeServiceRequest<TService, TServiceName, TServiceMethod>): void;
|
|
58
|
+
protected onMessage(data: ws.Data, isBinary: boolean): void;
|
|
57
59
|
protected onOpen(): void;
|
|
58
|
-
protected
|
|
59
|
-
protected
|
|
60
|
-
protected
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
protected
|
|
65
|
-
protected
|
|
66
|
-
ping(): Promise<void>;
|
|
60
|
+
protected onPingPong(): void;
|
|
61
|
+
protected onRequest(packet: AnyPacket<TIncoming, TService>, timestamp: Date, pluginError?: Error): Promise<boolean>;
|
|
62
|
+
protected onResponse(response: AnyResponse<TOutgoing, TPrivateOutgoing, TService>, pluginError?: Error): void;
|
|
63
|
+
private onSocketClose;
|
|
64
|
+
private onSocketError;
|
|
65
|
+
private onSocketMessage;
|
|
66
|
+
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
|
+
protected onUnhandledRequest(packet: AnyPacket<TIncoming, TService>): boolean;
|
|
67
68
|
protected resetPingTimeout(timeoutMs: number | false, code: number): void;
|
|
68
69
|
send(data: Buffer | string): Promise<void>;
|
|
69
|
-
protected sendRequest(requests: (AnyRequest<
|
|
70
|
-
protected sendRequest(index: number, requests: (AnyRequest<
|
|
71
|
-
protected sendResponse(responses: (AnyResponse<
|
|
72
|
-
protected sendResponse(index: number, responses: (AnyResponse<
|
|
70
|
+
protected sendRequest(requests: (AnyRequest<TOutgoing, TPrivateOutgoing, TService>)[]): void;
|
|
71
|
+
protected sendRequest(index: number, requests: (AnyRequest<TOutgoing, TPrivateOutgoing, TService>)[]): void;
|
|
72
|
+
protected sendResponse(responses: (AnyResponse<TOutgoing, TPrivateOutgoing, TService>)[]): void;
|
|
73
|
+
protected sendResponse(index: number, responses: (AnyResponse<TOutgoing, TPrivateOutgoing, TService>)[]): void;
|
|
73
74
|
setAuthorization(authToken: AuthToken): Promise<boolean>;
|
|
74
75
|
setAuthorization(signedAuthToken: SignedAuthToken, authToken?: AuthToken): Promise<boolean>;
|
|
75
76
|
setReadyStatus(pingTimeoutMs: number, authError?: Error): void;
|
|
76
77
|
get signedAuthToken(): SignedAuthToken;
|
|
77
|
-
get socket(): Socket<
|
|
78
|
-
set socket(value: Socket<
|
|
78
|
+
get socket(): Socket<TIncoming, TOutgoing, TPrivateOutgoing, TService, TState>;
|
|
79
|
+
set socket(value: Socket<TIncoming, TOutgoing, TPrivateOutgoing, TService, TState>);
|
|
79
80
|
get status(): SocketStatus;
|
|
80
81
|
triggerAuthenticationEvents(wasSigned: boolean, wasAuthenticated: boolean): void;
|
|
81
|
-
transmit<TMethod extends keyof
|
|
82
|
-
transmit<
|
|
83
|
-
transmit<TMethod extends keyof
|
|
84
|
-
invoke<TMethod extends keyof
|
|
85
|
-
invoke<
|
|
86
|
-
invoke<
|
|
87
|
-
invoke<TMethod extends keyof
|
|
88
|
-
invoke<TMethod extends keyof
|
|
89
|
-
invoke<TMethod extends keyof
|
|
82
|
+
transmit<TMethod extends keyof TOutgoing>(method: TMethod, arg?: Parameters<TOutgoing[TMethod]>[0]): Promise<void>;
|
|
83
|
+
transmit<TServiceName extends keyof TService, TMethod extends keyof TService[TServiceName]>(options: [TServiceName, TMethod], arg?: Parameters<TService[TServiceName][TMethod]>[0]): Promise<void>;
|
|
84
|
+
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];
|
|
90
91
|
get url(): string;
|
|
91
92
|
protected get webSocket(): ws.WebSocket;
|
|
92
93
|
protected set webSocket(value: ws.WebSocket | null);
|
package/dist/socket-transport.js
CHANGED
|
@@ -82,8 +82,7 @@ export class SocketTransport {
|
|
|
82
82
|
getOutboundBackpressure() {
|
|
83
83
|
return this._outboundPreparedMessageCount - this._outboundSentMessageCount;
|
|
84
84
|
}
|
|
85
|
-
async handleInboudMessage({
|
|
86
|
-
let packet = this.decode(data);
|
|
85
|
+
async handleInboudMessage({ packet, timestamp }) {
|
|
87
86
|
if (packet === null) {
|
|
88
87
|
return;
|
|
89
88
|
}
|
|
@@ -157,8 +156,13 @@ export class SocketTransport {
|
|
|
157
156
|
this.sendRequest([request]);
|
|
158
157
|
}
|
|
159
158
|
onMessage(data, isBinary) {
|
|
159
|
+
data = isBinary ? data : data.toString();
|
|
160
|
+
if (data === '') {
|
|
161
|
+
this.onPingPong();
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
160
164
|
const timestamp = new Date();
|
|
161
|
-
let p = Promise.resolve(
|
|
165
|
+
let p = Promise.resolve(data);
|
|
162
166
|
let resolve;
|
|
163
167
|
let reject;
|
|
164
168
|
const promise = new Promise((res, rej) => {
|
|
@@ -175,8 +179,9 @@ export class SocketTransport {
|
|
|
175
179
|
}
|
|
176
180
|
}
|
|
177
181
|
p.then(data => {
|
|
182
|
+
const packet = this.decode(data);
|
|
178
183
|
this._socket.emit('message', { data, isBinary });
|
|
179
|
-
return this.handleInboudMessage({
|
|
184
|
+
return this.handleInboudMessage({ packet, timestamp });
|
|
180
185
|
})
|
|
181
186
|
.then(resolve)
|
|
182
187
|
.catch(err => {
|
|
@@ -196,12 +201,7 @@ export class SocketTransport {
|
|
|
196
201
|
}
|
|
197
202
|
}
|
|
198
203
|
}
|
|
199
|
-
|
|
200
|
-
this._socket.emit('ping', { data });
|
|
201
|
-
}
|
|
202
|
-
onPong(data) {
|
|
203
|
-
this._socket.emit('pong', { data });
|
|
204
|
-
}
|
|
204
|
+
onPingPong() { }
|
|
205
205
|
async onRequest(packet, timestamp, pluginError) {
|
|
206
206
|
this._socket.emit('request', { request: packet });
|
|
207
207
|
const timeoutAt = typeof packet.ackTimeoutMs === 'number' ? new Date(timestamp.valueOf() + packet.ackTimeoutMs) : null;
|
|
@@ -273,33 +273,24 @@ export class SocketTransport {
|
|
|
273
273
|
this._socket.emit('response', { response });
|
|
274
274
|
}
|
|
275
275
|
}
|
|
276
|
+
onSocketClose(event) {
|
|
277
|
+
this.onClose(event.code, event.reason);
|
|
278
|
+
}
|
|
279
|
+
onSocketError(event) {
|
|
280
|
+
this.onError(event.error);
|
|
281
|
+
}
|
|
282
|
+
onSocketMessage(event) {
|
|
283
|
+
this.onMessage(event.data, false);
|
|
284
|
+
}
|
|
276
285
|
onTransmit(request) {
|
|
277
286
|
this.sendRequest([request]);
|
|
278
287
|
}
|
|
279
|
-
onUnexpectedResponse(request, response) {
|
|
280
|
-
this._socket.emit('unexpectedResponse', { request, response });
|
|
281
|
-
}
|
|
282
288
|
onUnhandledRequest(packet) {
|
|
283
289
|
if (this._onUnhandledRequest) {
|
|
284
290
|
return this._onUnhandledRequest(this, packet);
|
|
285
291
|
}
|
|
286
292
|
return false;
|
|
287
293
|
}
|
|
288
|
-
onUpgrade(request) {
|
|
289
|
-
this._socket.emit('upgrade', { request });
|
|
290
|
-
}
|
|
291
|
-
ping() {
|
|
292
|
-
return new Promise((resolve, reject) => {
|
|
293
|
-
this.webSocket.ping(undefined, undefined, (err) => {
|
|
294
|
-
if (err) {
|
|
295
|
-
reject(err);
|
|
296
|
-
}
|
|
297
|
-
else {
|
|
298
|
-
resolve();
|
|
299
|
-
}
|
|
300
|
-
});
|
|
301
|
-
});
|
|
302
|
-
}
|
|
303
294
|
resetPingTimeout(timeoutMs, code) {
|
|
304
295
|
if (this._pingTimeoutRef) {
|
|
305
296
|
clearTimeout(this._pingTimeoutRef);
|
|
@@ -385,18 +376,24 @@ export class SocketTransport {
|
|
|
385
376
|
const { promise, ...rest } = req;
|
|
386
377
|
return rest;
|
|
387
378
|
});
|
|
388
|
-
|
|
379
|
+
let sendErr;
|
|
380
|
+
this.send(this.codecEngine.encode(encode.length === 1 ? encode[0] : encode)).catch(err => {
|
|
381
|
+
sendErr = err;
|
|
382
|
+
}).then(() => {
|
|
383
|
+
const errCode = sendErr?.code;
|
|
389
384
|
for (const req of requests) {
|
|
390
|
-
if (
|
|
391
|
-
|
|
385
|
+
if (errCode === 'ECONNRESET') {
|
|
386
|
+
sendErr = new BadConnectionError(`Socket ${'callback' in req ? 'invoke' : 'transmit'} ${String(req.method)} event was aborted due to a bad connection`, 'connectAbort');
|
|
392
387
|
}
|
|
393
388
|
if (req.sentCallback) {
|
|
394
|
-
req.sentCallback(
|
|
389
|
+
req.sentCallback(sendErr);
|
|
395
390
|
}
|
|
396
|
-
if (
|
|
397
|
-
req.callback(
|
|
391
|
+
if (sendErr && 'callback' in req) {
|
|
392
|
+
req.callback(sendErr);
|
|
398
393
|
}
|
|
399
394
|
}
|
|
395
|
+
}).catch(err => {
|
|
396
|
+
this.onError(err);
|
|
400
397
|
});
|
|
401
398
|
}
|
|
402
399
|
sendResponse(index, responses) {
|
|
@@ -441,10 +438,8 @@ export class SocketTransport {
|
|
|
441
438
|
}
|
|
442
439
|
//timeoutId?: NodeJS.Timeout;
|
|
443
440
|
//callback: (err: Error, result?: U) => void | null
|
|
444
|
-
this.
|
|
445
|
-
|
|
446
|
-
this.onError(err);
|
|
447
|
-
}
|
|
441
|
+
this.send(this.codecEngine.encode(responses.length === 1 ? responses[0] : responses)).catch(err => {
|
|
442
|
+
this.onError(err);
|
|
448
443
|
});
|
|
449
444
|
}
|
|
450
445
|
async setAuthorization(signedAuthToken, authToken) {
|
|
@@ -639,33 +634,21 @@ export class SocketTransport {
|
|
|
639
634
|
}
|
|
640
635
|
set webSocket(value) {
|
|
641
636
|
if (this._webSocket) {
|
|
642
|
-
this._webSocket.
|
|
643
|
-
this._webSocket.
|
|
644
|
-
this._webSocket.
|
|
645
|
-
this._webSocket.
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
this._webSocket.off('unexpectedResponse', this.onUnexpectedResponse);
|
|
637
|
+
this._webSocket.onclose = null;
|
|
638
|
+
this._webSocket.onerror = null;
|
|
639
|
+
this._webSocket.onmessage = null;
|
|
640
|
+
this._webSocket.onopen = null;
|
|
641
|
+
delete this.onSocketClose;
|
|
642
|
+
delete this.onSocketError;
|
|
643
|
+
delete this.onSocketMessage;
|
|
650
644
|
delete this.onOpen;
|
|
651
|
-
delete this.onClose;
|
|
652
|
-
delete this.onError;
|
|
653
|
-
delete this.onUpgrade;
|
|
654
|
-
delete this.onMessage;
|
|
655
|
-
delete this.onPing;
|
|
656
|
-
delete this.onPong;
|
|
657
|
-
delete this.onUnexpectedResponse;
|
|
658
645
|
}
|
|
659
646
|
this._webSocket = value;
|
|
660
647
|
if (value) {
|
|
661
|
-
this._webSocket.
|
|
662
|
-
this._webSocket.
|
|
663
|
-
this._webSocket.
|
|
664
|
-
this._webSocket.
|
|
665
|
-
this._webSocket.on('message', this.onMessage = this.onMessage.bind(this));
|
|
666
|
-
this._webSocket.on('ping', this.onPing = this.onPing.bind(this));
|
|
667
|
-
this._webSocket.on('pong', this.onPong = this.onPong.bind(this));
|
|
668
|
-
this._webSocket.on('unexpectedResponse', this.onUnexpectedResponse = this.onUnexpectedResponse.bind(this));
|
|
648
|
+
this._webSocket.onclose = this.onSocketClose = this.onSocketClose.bind(this);
|
|
649
|
+
this._webSocket.onopen = this.onOpen = this.onOpen.bind(this);
|
|
650
|
+
this._webSocket.onerror = this.onSocketError = this.onSocketError.bind(this);
|
|
651
|
+
this._webSocket.onmessage = this.onSocketMessage = this.onSocketMessage.bind(this);
|
|
669
652
|
}
|
|
670
653
|
}
|
|
671
654
|
}
|
package/dist/socket.d.ts
CHANGED
|
@@ -1,31 +1,30 @@
|
|
|
1
1
|
import { CodecEngine } from "@socket-mesh/formatter";
|
|
2
2
|
import { AnyPacket } from "./packet.js";
|
|
3
3
|
import { AsyncStreamEmitter } from "@socket-mesh/async-stream-emitter";
|
|
4
|
-
import { SocketEvent, AuthenticateEvent, BadAuthTokenEvent, CloseEvent, ConnectEvent, DisconnectEvent, ErrorEvent, MessageEvent, PingEvent, PongEvent, RequestEvent,
|
|
5
|
-
import { FunctionReturnType } from "./maps/method-map.js";
|
|
4
|
+
import { SocketEvent, AuthenticateEvent, BadAuthTokenEvent, CloseEvent, ConnectEvent, DisconnectEvent, ErrorEvent, MessageEvent, PingEvent, PongEvent, RequestEvent, ResponseEvent, AuthStateChangeEvent, RemoveAuthTokenEvent, ConnectingEvent, DeauthenticateEvent } from "./socket-event.js";
|
|
5
|
+
import { FunctionReturnType, MethodMap, PrivateMethodMap, PublicMethodMap, ServiceMap } from "./maps/method-map.js";
|
|
6
6
|
import { HandlerMap } from "./maps/handler-map.js";
|
|
7
7
|
import { CallIdGenerator, InvokeMethodOptions, InvokeServiceOptions, SocketTransport } from "./socket-transport.js";
|
|
8
8
|
import { DemuxedConsumableStream, StreamEvent } from "@socket-mesh/stream-demux";
|
|
9
9
|
import { AuthToken, SignedAuthToken } from "@socket-mesh/auth";
|
|
10
|
-
import { SocketMap } from "./maps/socket-map.js";
|
|
11
10
|
import { Plugin } from "./plugins/plugin.js";
|
|
12
11
|
export type StreamCleanupMode = 'kill' | 'close' | 'none';
|
|
13
|
-
export interface SocketOptions<
|
|
12
|
+
export interface SocketOptions<TIncoming extends MethodMap, TOutgoing extends PublicMethodMap, TPrivateOutgoing extends PrivateMethodMap, TService extends ServiceMap, TState extends object, TSocket extends Socket<TIncoming, TOutgoing, TPrivateOutgoing, TService, TState> = Socket<TIncoming, TOutgoing, TPrivateOutgoing, TService, TState>> {
|
|
14
13
|
ackTimeoutMs?: number;
|
|
15
14
|
callIdGenerator?: CallIdGenerator;
|
|
16
15
|
codecEngine?: CodecEngine;
|
|
17
|
-
handlers?: HandlerMap<
|
|
16
|
+
handlers?: HandlerMap<TIncoming, TOutgoing, TPrivateOutgoing, TService, TState>;
|
|
18
17
|
isPingTimeoutDisabled?: boolean;
|
|
19
|
-
plugins?: Plugin<
|
|
20
|
-
onUnhandledRequest?: (socket: TSocket, packet: AnyPacket<
|
|
21
|
-
state?:
|
|
18
|
+
plugins?: Plugin<TIncoming, TOutgoing, TPrivateOutgoing, TService, TState>[];
|
|
19
|
+
onUnhandledRequest?: (socket: TSocket, packet: AnyPacket<TIncoming, TService>) => boolean;
|
|
20
|
+
state?: Partial<TState>;
|
|
22
21
|
streamCleanupMode?: StreamCleanupMode;
|
|
23
22
|
}
|
|
24
23
|
export type SocketStatus = 'connecting' | 'ready' | 'closing' | 'closed';
|
|
25
|
-
export declare class Socket<
|
|
24
|
+
export declare class Socket<TIncoming extends MethodMap, TOutgoing extends PublicMethodMap, TPrivateOutgoing extends PrivateMethodMap, TService extends ServiceMap, TState extends object> extends AsyncStreamEmitter<SocketEvent<TIncoming, TOutgoing, TPrivateOutgoing, TService>> {
|
|
26
25
|
private readonly _transport;
|
|
27
|
-
readonly state: Partial<
|
|
28
|
-
protected constructor(transport: SocketTransport<
|
|
26
|
+
readonly state: Partial<TState>;
|
|
27
|
+
protected constructor(transport: SocketTransport<TIncoming, TOutgoing, TPrivateOutgoing, TService, TState>, options?: SocketOptions<TIncoming, TOutgoing, TPrivateOutgoing, TService, TState>);
|
|
29
28
|
get id(): string;
|
|
30
29
|
get authToken(): AuthToken;
|
|
31
30
|
get signedAuthToken(): SignedAuthToken;
|
|
@@ -49,11 +48,9 @@ export declare class Socket<T extends SocketMap> extends AsyncStreamEmitter<Sock
|
|
|
49
48
|
emit(event: 'ping', data: PingEvent): void;
|
|
50
49
|
emit(event: 'pong', data: PongEvent): void;
|
|
51
50
|
emit(event: 'removeAuthToken', data: RemoveAuthTokenEvent): void;
|
|
52
|
-
emit(event: 'request', data: RequestEvent<
|
|
53
|
-
emit(event: 'response', data: ResponseEvent<
|
|
54
|
-
|
|
55
|
-
emit(event: 'upgrade', data: UpgradeEvent): void;
|
|
56
|
-
listen(): DemuxedConsumableStream<StreamEvent<SocketEvent<T>>>;
|
|
51
|
+
emit(event: 'request', data: RequestEvent<TIncoming, TService>): void;
|
|
52
|
+
emit(event: 'response', data: ResponseEvent<TOutgoing, TPrivateOutgoing, TService>): void;
|
|
53
|
+
listen(): DemuxedConsumableStream<StreamEvent<SocketEvent<TIncoming, TOutgoing, TPrivateOutgoing, TService>>>;
|
|
57
54
|
listen(event: 'authStateChange'): DemuxedConsumableStream<AuthStateChangeEvent>;
|
|
58
55
|
listen(event: 'authenticate'): DemuxedConsumableStream<AuthenticateEvent>;
|
|
59
56
|
listen(event: 'badAuthToken'): DemuxedConsumableStream<BadAuthTokenEvent>;
|
|
@@ -69,18 +66,15 @@ export declare class Socket<T extends SocketMap> extends AsyncStreamEmitter<Sock
|
|
|
69
66
|
listen(event: 'ping'): DemuxedConsumableStream<PingEvent>;
|
|
70
67
|
listen(event: 'pong'): DemuxedConsumableStream<PongEvent>;
|
|
71
68
|
listen(event: 'removeAuthToken'): DemuxedConsumableStream<RemoveAuthTokenEvent>;
|
|
72
|
-
listen(event: 'request'): DemuxedConsumableStream<RequestEvent<
|
|
73
|
-
listen(event: 'response'): DemuxedConsumableStream<ResponseEvent<
|
|
74
|
-
listen(event:
|
|
75
|
-
listen(event: 'upgrade'): DemuxedConsumableStream<UpgradeEvent>;
|
|
76
|
-
listen<U extends SocketEvent<T>, V = U>(event: string): DemuxedConsumableStream<V>;
|
|
77
|
-
ping(): Promise<void>;
|
|
69
|
+
listen(event: 'request'): DemuxedConsumableStream<RequestEvent<TIncoming, TService>>;
|
|
70
|
+
listen(event: 'response'): DemuxedConsumableStream<ResponseEvent<TOutgoing, TPrivateOutgoing, TService>>;
|
|
71
|
+
listen<U extends SocketEvent<TIncoming, TOutgoing, TPrivateOutgoing, TService>, V = U>(event: string): DemuxedConsumableStream<V>;
|
|
78
72
|
get status(): SocketStatus;
|
|
79
73
|
get url(): string;
|
|
80
|
-
transmit<TMethod extends keyof
|
|
81
|
-
transmit<
|
|
82
|
-
invoke<TMethod extends keyof
|
|
83
|
-
invoke<
|
|
84
|
-
invoke<
|
|
85
|
-
invoke<TMethod extends keyof
|
|
74
|
+
transmit<TMethod extends keyof TOutgoing>(method: TMethod, arg?: Parameters<TOutgoing[TMethod]>[0]): Promise<void>;
|
|
75
|
+
transmit<TServiceName extends keyof TService, TMethod extends keyof TService[TServiceName]>(options: [TServiceName, TMethod], arg?: Parameters<TService[TServiceName][TMethod]>[0]): Promise<void>;
|
|
76
|
+
invoke<TMethod extends keyof TOutgoing>(method: TMethod, arg?: Parameters<TOutgoing[TMethod]>[0]): Promise<FunctionReturnType<TOutgoing[TMethod]>>;
|
|
77
|
+
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]>>;
|
|
78
|
+
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]>>;
|
|
79
|
+
invoke<TMethod extends keyof TOutgoing>(options: InvokeMethodOptions<TOutgoing, TMethod>, arg?: Parameters<TOutgoing[TMethod]>[0]): Promise<FunctionReturnType<TOutgoing[TMethod]>>;
|
|
86
80
|
}
|
package/dist/socket.js
CHANGED
package/package.json
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
"name": "@socket-mesh/core",
|
|
3
|
+
"version": "1.0.3",
|
|
4
|
+
"description": "Core module for SocketMesh Server",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
8
|
"files": ["./dist"],
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "node ../../scripts/build.mjs && tsc --project tsconfig.build.json",
|
|
11
|
+
"deploy": "npm run build && node ../../scripts/publish.mjs",
|
|
12
|
+
"test": "cross-env node --test --loader ts-node/esm test/index.spec.ts"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"auth",
|
|
16
|
+
"jwt",
|
|
17
|
+
"socketMesh"
|
|
18
|
+
],
|
|
19
|
+
"author": "Greg Kimmy",
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"homepage": "https://github.com/socket-mesh/main/tree/main/packages/core#README.md",
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
"url": "https://github.com/socket-mesh/
|
|
28
|
-
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "git+https://github.com/socket-mesh/client-server.git"
|
|
25
|
+
},
|
|
26
|
+
"bugs": {
|
|
27
|
+
"url": "https://github.com/socket-mesh/client-server/labels/core"
|
|
28
|
+
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@types/base64id": "^2.0.2",
|
|
31
31
|
"@types/ws": "^8.5.11"
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { MethodMap, PrivateMethodMap, PublicMethodMap, ServiceMap } from "./method-map.js";
|
|
2
|
-
export interface SocketMap {
|
|
3
|
-
Incoming: MethodMap;
|
|
4
|
-
Service: ServiceMap;
|
|
5
|
-
Outgoing: PublicMethodMap;
|
|
6
|
-
PrivateOutgoing: PrivateMethodMap;
|
|
7
|
-
State: object;
|
|
8
|
-
}
|
|
9
|
-
export interface EmptySocketMap {
|
|
10
|
-
Incoming: {};
|
|
11
|
-
Service: {};
|
|
12
|
-
Outgoing: {};
|
|
13
|
-
PrivateOutgoing: {};
|
|
14
|
-
State: {};
|
|
15
|
-
}
|
package/dist/maps/socket-map.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|