@socket-mesh/core 1.0.2 → 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 -6
- package/dist/socket-transport.d.ts +27 -28
- package/dist/socket.d.ts +21 -22
- package/package.json +22 -22
- 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
|
@@ -2,8 +2,8 @@ import ws from "isomorphic-ws";
|
|
|
2
2
|
import { MethodPacket, ServicePacket } from "./packet.js";
|
|
3
3
|
import { AuthToken, SignedAuthToken } from "@socket-mesh/auth";
|
|
4
4
|
import { AnyResponse } from "./response.js";
|
|
5
|
-
import {
|
|
6
|
-
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>;
|
|
7
7
|
export type AuthStateChangeEvent = AuthenticatedChangeEvent | DeauthenticatedChangeEvent;
|
|
8
8
|
export interface AuthenticatedChangeEvent {
|
|
9
9
|
isAuthenticated: true;
|
|
@@ -58,9 +58,9 @@ export interface PongEvent {
|
|
|
58
58
|
export interface RemoveAuthTokenEvent {
|
|
59
59
|
oldAuthToken: SignedAuthToken;
|
|
60
60
|
}
|
|
61
|
-
export interface RequestEvent<
|
|
62
|
-
request: ServicePacket<
|
|
61
|
+
export interface RequestEvent<TIncoming extends MethodMap, TService extends ServiceMap> {
|
|
62
|
+
request: ServicePacket<TService> | MethodPacket<TIncoming>;
|
|
63
63
|
}
|
|
64
|
-
export interface ResponseEvent<
|
|
65
|
-
response: AnyResponse<
|
|
64
|
+
export interface ResponseEvent<TOutgoing extends PublicMethodMap, TPrivateOutgoing extends PrivateMethodMap, TService extends ServiceMap> {
|
|
65
|
+
response: AnyResponse<TOutgoing, TPrivateOutgoing, TService>;
|
|
66
66
|
}
|
|
@@ -3,11 +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 { FunctionReturnType, MethodMap, ServiceMap } from "./maps/method-map.js";
|
|
6
|
+
import { FunctionReturnType, MethodMap, PrivateMethodMap, PublicMethodMap, ServiceMap } from "./maps/method-map.js";
|
|
7
7
|
import { AnyResponse } from "./response.js";
|
|
8
8
|
import { AuthToken, SignedAuthToken } from "@socket-mesh/auth";
|
|
9
9
|
import { Socket, SocketOptions, SocketStatus, StreamCleanupMode } from "./socket.js";
|
|
10
|
-
import { SocketMap } from "./maps/socket-map.js";
|
|
11
10
|
export type CallIdGenerator = () => number;
|
|
12
11
|
export interface InvokeMethodOptions<TMethodMap extends MethodMap, TMethod extends keyof TMethodMap> {
|
|
13
12
|
method: TMethod;
|
|
@@ -18,11 +17,11 @@ export interface InvokeServiceOptions<TServiceMap extends ServiceMap, TService e
|
|
|
18
17
|
method: TMethod;
|
|
19
18
|
ackTimeoutMs?: number | false;
|
|
20
19
|
}
|
|
21
|
-
export interface InboundMessage<
|
|
20
|
+
export interface InboundMessage<TIncoming extends MethodMap, TOutgoing extends PublicMethodMap, TPrivateOutgoing extends PrivateMethodMap, TService extends ServiceMap> {
|
|
22
21
|
timestamp: Date;
|
|
23
|
-
packet: (AnyPacket<
|
|
22
|
+
packet: (AnyPacket<TIncoming, TService> | AnyResponse<TOutgoing, TPrivateOutgoing, TService>) | (AnyPacket<TIncoming, TService> | AnyResponse<TOutgoing, TPrivateOutgoing, TService>)[];
|
|
24
23
|
}
|
|
25
|
-
export declare class SocketTransport<
|
|
24
|
+
export declare class SocketTransport<TIncoming extends MethodMap, TOutgoing extends PublicMethodMap, TPrivateOutgoing extends PrivateMethodMap, TService extends ServiceMap, TState extends object> {
|
|
26
25
|
private _socket;
|
|
27
26
|
private _webSocket;
|
|
28
27
|
private _inboundProcessedMessageCount;
|
|
@@ -37,12 +36,12 @@ export declare class SocketTransport<T extends SocketMap> {
|
|
|
37
36
|
private readonly _handlers;
|
|
38
37
|
private _onUnhandledRequest;
|
|
39
38
|
readonly codecEngine: CodecEngine;
|
|
40
|
-
readonly plugins: Plugin<
|
|
39
|
+
readonly plugins: Plugin<TIncoming, TOutgoing, TPrivateOutgoing, TService, TState>[];
|
|
41
40
|
streamCleanupMode: StreamCleanupMode;
|
|
42
41
|
id: string | null;
|
|
43
42
|
ackTimeoutMs: number;
|
|
44
43
|
private _pingTimeoutRef;
|
|
45
|
-
protected constructor(options?: SocketOptions<
|
|
44
|
+
protected constructor(options?: SocketOptions<TIncoming, TOutgoing, TPrivateOutgoing, TService, TState>);
|
|
46
45
|
protected abortAllPendingCallbacksDueToBadConnection(status: SocketStatus): void;
|
|
47
46
|
get authToken(): AuthToken;
|
|
48
47
|
changeToUnauthenticatedState(): Promise<boolean>;
|
|
@@ -51,44 +50,44 @@ export declare class SocketTransport<T extends SocketMap> {
|
|
|
51
50
|
getBackpressure(): number;
|
|
52
51
|
getInboundBackpressure(): number;
|
|
53
52
|
getOutboundBackpressure(): number;
|
|
54
|
-
protected handleInboudMessage({ packet, timestamp }: InboundMessage<
|
|
53
|
+
protected handleInboudMessage({ packet, timestamp }: InboundMessage<TIncoming, TOutgoing, TPrivateOutgoing, TService>): Promise<void>;
|
|
55
54
|
protected onClose(code: number, reason?: Buffer | string): void;
|
|
56
55
|
protected onDisconnect(status: SocketStatus, code: number, reason?: string): void;
|
|
57
56
|
onError(error: Error): void;
|
|
58
|
-
protected onInvoke<
|
|
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;
|
|
59
58
|
protected onMessage(data: ws.Data, isBinary: boolean): void;
|
|
60
59
|
protected onOpen(): void;
|
|
61
60
|
protected onPingPong(): void;
|
|
62
|
-
protected onRequest(packet: AnyPacket<
|
|
63
|
-
protected onResponse(response: AnyResponse<
|
|
61
|
+
protected onRequest(packet: AnyPacket<TIncoming, TService>, timestamp: Date, pluginError?: Error): Promise<boolean>;
|
|
62
|
+
protected onResponse(response: AnyResponse<TOutgoing, TPrivateOutgoing, TService>, pluginError?: Error): void;
|
|
64
63
|
private onSocketClose;
|
|
65
64
|
private onSocketError;
|
|
66
65
|
private onSocketMessage;
|
|
67
|
-
protected onTransmit<
|
|
68
|
-
protected onUnhandledRequest(packet: AnyPacket<
|
|
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;
|
|
69
68
|
protected resetPingTimeout(timeoutMs: number | false, code: number): void;
|
|
70
69
|
send(data: Buffer | string): Promise<void>;
|
|
71
|
-
protected sendRequest(requests: (AnyRequest<
|
|
72
|
-
protected sendRequest(index: number, requests: (AnyRequest<
|
|
73
|
-
protected sendResponse(responses: (AnyResponse<
|
|
74
|
-
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;
|
|
75
74
|
setAuthorization(authToken: AuthToken): Promise<boolean>;
|
|
76
75
|
setAuthorization(signedAuthToken: SignedAuthToken, authToken?: AuthToken): Promise<boolean>;
|
|
77
76
|
setReadyStatus(pingTimeoutMs: number, authError?: Error): void;
|
|
78
77
|
get signedAuthToken(): SignedAuthToken;
|
|
79
|
-
get socket(): Socket<
|
|
80
|
-
set socket(value: Socket<
|
|
78
|
+
get socket(): Socket<TIncoming, TOutgoing, TPrivateOutgoing, TService, TState>;
|
|
79
|
+
set socket(value: Socket<TIncoming, TOutgoing, TPrivateOutgoing, TService, TState>);
|
|
81
80
|
get status(): SocketStatus;
|
|
82
81
|
triggerAuthenticationEvents(wasSigned: boolean, wasAuthenticated: boolean): void;
|
|
83
|
-
transmit<TMethod extends keyof
|
|
84
|
-
transmit<
|
|
85
|
-
transmit<TMethod extends keyof
|
|
86
|
-
invoke<TMethod extends keyof
|
|
87
|
-
invoke<
|
|
88
|
-
invoke<
|
|
89
|
-
invoke<TMethod extends keyof
|
|
90
|
-
invoke<TMethod extends keyof
|
|
91
|
-
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];
|
|
92
91
|
get url(): string;
|
|
93
92
|
protected get webSocket(): ws.WebSocket;
|
|
94
93
|
protected set webSocket(value: ws.WebSocket | null);
|
package/dist/socket.d.ts
CHANGED
|
@@ -2,30 +2,29 @@ import { CodecEngine } from "@socket-mesh/formatter";
|
|
|
2
2
|
import { AnyPacket } from "./packet.js";
|
|
3
3
|
import { AsyncStreamEmitter } from "@socket-mesh/async-stream-emitter";
|
|
4
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 } from "./maps/method-map.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,9 +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
|
-
listen(): DemuxedConsumableStream<StreamEvent<SocketEvent<
|
|
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>>>;
|
|
55
54
|
listen(event: 'authStateChange'): DemuxedConsumableStream<AuthStateChangeEvent>;
|
|
56
55
|
listen(event: 'authenticate'): DemuxedConsumableStream<AuthenticateEvent>;
|
|
57
56
|
listen(event: 'badAuthToken'): DemuxedConsumableStream<BadAuthTokenEvent>;
|
|
@@ -67,15 +66,15 @@ export declare class Socket<T extends SocketMap> extends AsyncStreamEmitter<Sock
|
|
|
67
66
|
listen(event: 'ping'): DemuxedConsumableStream<PingEvent>;
|
|
68
67
|
listen(event: 'pong'): DemuxedConsumableStream<PongEvent>;
|
|
69
68
|
listen(event: 'removeAuthToken'): DemuxedConsumableStream<RemoveAuthTokenEvent>;
|
|
70
|
-
listen(event: 'request'): DemuxedConsumableStream<RequestEvent<
|
|
71
|
-
listen(event: 'response'): DemuxedConsumableStream<ResponseEvent<
|
|
72
|
-
listen<U extends SocketEvent<
|
|
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>;
|
|
73
72
|
get status(): SocketStatus;
|
|
74
73
|
get url(): string;
|
|
75
|
-
transmit<TMethod extends keyof
|
|
76
|
-
transmit<
|
|
77
|
-
invoke<TMethod extends keyof
|
|
78
|
-
invoke<
|
|
79
|
-
invoke<
|
|
80
|
-
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]>>;
|
|
81
80
|
}
|
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
|
-
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "git+https://github.com/socket-mesh/client-server.git"
|
|
25
|
+
},
|
|
26
|
+
"bugs": {
|
|
27
27
|
"url": "https://github.com/socket-mesh/client-server/labels/core"
|
|
28
|
-
|
|
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 {};
|