@socket-mesh/core 1.0.2 → 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.
- package/dist/index.d.ts +10 -10
- package/dist/index.js +10 -10
- package/dist/maps/handler-map.d.ts +4 -4
- package/dist/maps/index.d.ts +2 -3
- package/dist/maps/index.js +2 -3
- package/dist/maps/method-map.d.ts +8 -8
- package/dist/maps/method-map.js +1 -0
- package/dist/packet.d.ts +16 -17
- package/dist/packet.js +3 -1
- package/dist/plugins/index.d.ts +1 -1
- package/dist/plugins/index.js +1 -1
- package/dist/plugins/plugin.d.ts +40 -40
- package/dist/request-handler.d.ts +10 -10
- package/dist/request-handler.js +9 -2
- package/dist/request.d.ts +42 -43
- package/dist/request.js +13 -11
- package/dist/response.d.ts +14 -15
- package/dist/response.js +3 -1
- package/dist/socket-event.d.ts +24 -27
- package/dist/socket-transport.d.ts +56 -59
- package/dist/socket-transport.js +218 -195
- package/dist/socket.d.ts +38 -39
- package/dist/socket.js +21 -16
- package/dist/utils.d.ts +1 -1
- package/dist/utils.js +3 -3
- package/package.json +34 -31
- package/dist/maps/socket-map.d.ts +0 -15
- package/dist/maps/socket-map.js +0 -1
package/dist/socket.d.ts
CHANGED
|
@@ -1,39 +1,33 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
export type StreamCleanupMode = 'kill' | 'close' | 'none';
|
|
13
|
-
export interface SocketOptions<T extends SocketMap, TSocket extends Socket<T> = Socket<T>> {
|
|
1
|
+
import { AsyncStreamEmitter } from '@socket-mesh/async-stream-emitter';
|
|
2
|
+
import { AuthToken, SignedAuthToken } from '@socket-mesh/auth';
|
|
3
|
+
import { CodecEngine } from '@socket-mesh/formatter';
|
|
4
|
+
import { DemuxedConsumableStream, StreamEvent } from '@socket-mesh/stream-demux';
|
|
5
|
+
import { HandlerMap } from './maps/handler-map.js';
|
|
6
|
+
import { FunctionReturnType, MethodMap, PrivateMethodMap, PublicMethodMap, ServiceMap } from './maps/method-map.js';
|
|
7
|
+
import { AnyPacket } from './packet.js';
|
|
8
|
+
import { Plugin } from './plugins/plugin.js';
|
|
9
|
+
import { AuthenticateEvent, AuthStateChangeEvent, BadAuthTokenEvent, CloseEvent, ConnectEvent, ConnectingEvent, DeauthenticateEvent, DisconnectEvent, ErrorEvent, MessageEvent, PingEvent, PongEvent, RemoveAuthTokenEvent, RequestEvent, ResponseEvent, SocketEvent } from './socket-event.js';
|
|
10
|
+
import { CallIdGenerator, InvokeMethodOptions, InvokeServiceOptions, SocketTransport } from './socket-transport.js';
|
|
11
|
+
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
12
|
ackTimeoutMs?: number;
|
|
15
13
|
callIdGenerator?: CallIdGenerator;
|
|
16
14
|
codecEngine?: CodecEngine;
|
|
17
|
-
handlers?: HandlerMap<
|
|
15
|
+
handlers?: HandlerMap<TIncoming, TOutgoing, TPrivateOutgoing, TService, TState>;
|
|
18
16
|
isPingTimeoutDisabled?: boolean;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
state?:
|
|
17
|
+
onUnhandledRequest?: (socket: TSocket, packet: AnyPacket<TIncoming, TService>) => boolean;
|
|
18
|
+
plugins?: Plugin<TIncoming, TOutgoing, TPrivateOutgoing, TService, TState>[];
|
|
19
|
+
state?: Partial<TState>;
|
|
22
20
|
streamCleanupMode?: StreamCleanupMode;
|
|
23
21
|
}
|
|
24
|
-
export type SocketStatus = '
|
|
25
|
-
export
|
|
22
|
+
export type SocketStatus = 'closed' | 'closing' | 'connecting' | 'ready';
|
|
23
|
+
export type StreamCleanupMode = 'close' | 'kill' | 'none';
|
|
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> | undefined> {
|
|
26
25
|
private readonly _transport;
|
|
27
|
-
readonly state: Partial<
|
|
28
|
-
protected constructor(transport: SocketTransport<
|
|
29
|
-
get
|
|
30
|
-
get authToken(): AuthToken;
|
|
31
|
-
get signedAuthToken(): SignedAuthToken;
|
|
26
|
+
readonly state: Partial<TState>;
|
|
27
|
+
protected constructor(transport: SocketTransport<TIncoming, TOutgoing, TPrivateOutgoing, TService, TState>, options?: SocketOptions<TIncoming, TOutgoing, TPrivateOutgoing, TService, TState>);
|
|
28
|
+
get authToken(): AuthToken | null;
|
|
32
29
|
deauthenticate(): Promise<boolean>;
|
|
33
30
|
disconnect(code?: number, reason?: string): void;
|
|
34
|
-
getBackpressure(): number;
|
|
35
|
-
getInboundBackpressure(): number;
|
|
36
|
-
getOutboundBackpressure(): number;
|
|
37
31
|
emit(event: 'authStateChange', data: AuthStateChangeEvent): void;
|
|
38
32
|
emit(event: 'authenticate', data: AuthenticateEvent): void;
|
|
39
33
|
emit(event: 'badAuthToken', data: BadAuthTokenEvent): void;
|
|
@@ -49,9 +43,17 @@ export declare class Socket<T extends SocketMap> extends AsyncStreamEmitter<Sock
|
|
|
49
43
|
emit(event: 'ping', data: PingEvent): void;
|
|
50
44
|
emit(event: 'pong', data: PongEvent): void;
|
|
51
45
|
emit(event: 'removeAuthToken', data: RemoveAuthTokenEvent): void;
|
|
52
|
-
emit(event: 'request', data: RequestEvent<
|
|
53
|
-
emit(event: 'response', data: ResponseEvent<
|
|
54
|
-
|
|
46
|
+
emit(event: 'request', data: RequestEvent<TIncoming, TService>): void;
|
|
47
|
+
emit(event: 'response', data: ResponseEvent<TOutgoing, TPrivateOutgoing, TService>): void;
|
|
48
|
+
getBackpressure(): number;
|
|
49
|
+
getInboundBackpressure(): number;
|
|
50
|
+
getOutboundBackpressure(): number;
|
|
51
|
+
get id(): null | string;
|
|
52
|
+
invoke<TMethod extends keyof TOutgoing>(method: TMethod, arg?: Parameters<TOutgoing[TMethod]>[0]): Promise<FunctionReturnType<TOutgoing[TMethod]>>;
|
|
53
|
+
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]>>;
|
|
54
|
+
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]>>;
|
|
55
|
+
invoke<TMethod extends keyof TOutgoing>(options: InvokeMethodOptions<TOutgoing, TMethod>, arg?: Parameters<TOutgoing[TMethod]>[0]): Promise<FunctionReturnType<TOutgoing[TMethod]>>;
|
|
56
|
+
listen(): DemuxedConsumableStream<StreamEvent<SocketEvent<TIncoming, TOutgoing, TPrivateOutgoing, TService>>>;
|
|
55
57
|
listen(event: 'authStateChange'): DemuxedConsumableStream<AuthStateChangeEvent>;
|
|
56
58
|
listen(event: 'authenticate'): DemuxedConsumableStream<AuthenticateEvent>;
|
|
57
59
|
listen(event: 'badAuthToken'): DemuxedConsumableStream<BadAuthTokenEvent>;
|
|
@@ -67,15 +69,12 @@ export declare class Socket<T extends SocketMap> extends AsyncStreamEmitter<Sock
|
|
|
67
69
|
listen(event: 'ping'): DemuxedConsumableStream<PingEvent>;
|
|
68
70
|
listen(event: 'pong'): DemuxedConsumableStream<PongEvent>;
|
|
69
71
|
listen(event: 'removeAuthToken'): DemuxedConsumableStream<RemoveAuthTokenEvent>;
|
|
70
|
-
listen(event: 'request'): DemuxedConsumableStream<RequestEvent<
|
|
71
|
-
listen(event: 'response'): DemuxedConsumableStream<ResponseEvent<
|
|
72
|
-
listen<U extends SocketEvent<
|
|
72
|
+
listen(event: 'request'): DemuxedConsumableStream<RequestEvent<TIncoming, TService>>;
|
|
73
|
+
listen(event: 'response'): DemuxedConsumableStream<ResponseEvent<TOutgoing, TPrivateOutgoing, TService>>;
|
|
74
|
+
listen<U extends SocketEvent<TIncoming, TOutgoing, TPrivateOutgoing, TService>, V = U>(event: string): DemuxedConsumableStream<V>;
|
|
75
|
+
get signedAuthToken(): null | SignedAuthToken;
|
|
73
76
|
get status(): SocketStatus;
|
|
77
|
+
transmit<TMethod extends keyof TOutgoing>(method: TMethod, arg?: Parameters<TOutgoing[TMethod]>[0]): Promise<void>;
|
|
78
|
+
transmit<TServiceName extends keyof TService, TMethod extends keyof TService[TServiceName]>(options: [TServiceName, TMethod], arg?: Parameters<TService[TServiceName][TMethod]>[0]): Promise<void>;
|
|
74
79
|
get url(): string;
|
|
75
|
-
transmit<TMethod extends keyof T['Outgoing']>(method: TMethod, arg?: Parameters<T['Outgoing'][TMethod]>[0]): Promise<void>;
|
|
76
|
-
transmit<TService extends keyof T['Service'], TMethod extends keyof T['Service'][TService]>(options: [TService, TMethod], arg?: Parameters<T['Service'][TService][TMethod]>[0]): Promise<void>;
|
|
77
|
-
invoke<TMethod extends keyof T['Outgoing']>(method: TMethod, arg?: Parameters<T['Outgoing'][TMethod]>[0]): Promise<FunctionReturnType<T['Outgoing'][TMethod]>>;
|
|
78
|
-
invoke<TService extends keyof T['Service'], TMethod extends keyof T['Service'][TService]>(options: [TService, TMethod, (number | false)?], arg?: Parameters<T['Service'][TService][TMethod]>[0]): Promise<FunctionReturnType<T['Service'][TService][TMethod]>>;
|
|
79
|
-
invoke<TService extends keyof T['Service'], TMethod extends keyof T['Service'][TService]>(options: InvokeServiceOptions<T['Service'], TService, TMethod>, arg?: Parameters<T['Service'][TService][TMethod]>[0]): Promise<FunctionReturnType<T['Service'][TService][TMethod]>>;
|
|
80
|
-
invoke<TMethod extends keyof T['Outgoing']>(options: InvokeMethodOptions<T['Outgoing'], TMethod>, arg?: Parameters<T['Outgoing'][TMethod]>[0]): Promise<FunctionReturnType<T['Outgoing'][TMethod]>>;
|
|
81
80
|
}
|
package/dist/socket.js
CHANGED
|
@@ -1,28 +1,30 @@
|
|
|
1
|
-
import { AsyncStreamEmitter } from
|
|
1
|
+
import { AsyncStreamEmitter } from '@socket-mesh/async-stream-emitter';
|
|
2
2
|
export class Socket extends AsyncStreamEmitter {
|
|
3
|
+
_transport;
|
|
4
|
+
state;
|
|
3
5
|
constructor(transport, options) {
|
|
4
6
|
super();
|
|
5
7
|
this.state = options?.state || {};
|
|
6
8
|
transport.socket = this;
|
|
7
9
|
this._transport = transport;
|
|
8
10
|
}
|
|
9
|
-
get id() {
|
|
10
|
-
return this._transport.id;
|
|
11
|
-
}
|
|
12
11
|
get authToken() {
|
|
13
12
|
return this._transport.authToken;
|
|
14
13
|
}
|
|
15
|
-
get signedAuthToken() {
|
|
16
|
-
return this._transport.signedAuthToken;
|
|
17
|
-
}
|
|
18
14
|
deauthenticate() {
|
|
19
15
|
return this._transport.changeToUnauthenticatedState();
|
|
20
16
|
}
|
|
21
17
|
disconnect(code = 1000, reason) {
|
|
22
18
|
this._transport.disconnect(code, reason);
|
|
23
19
|
}
|
|
20
|
+
emit(event, data) {
|
|
21
|
+
super.emit(event, data);
|
|
22
|
+
}
|
|
24
23
|
getBackpressure() {
|
|
25
|
-
return Math.max(this._transport.getBackpressure(), this.getListenerBackpressure()
|
|
24
|
+
return Math.max(this._transport.getBackpressure(), this.getListenerBackpressure()
|
|
25
|
+
// this.receiver.getBackpressure(),
|
|
26
|
+
// this.procedure.getBackpressure()
|
|
27
|
+
);
|
|
26
28
|
}
|
|
27
29
|
getInboundBackpressure() {
|
|
28
30
|
return this._transport.getInboundBackpressure();
|
|
@@ -30,22 +32,25 @@ export class Socket extends AsyncStreamEmitter {
|
|
|
30
32
|
getOutboundBackpressure() {
|
|
31
33
|
return this._transport.getOutboundBackpressure();
|
|
32
34
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
+
get id() {
|
|
36
|
+
return this._transport.id;
|
|
37
|
+
}
|
|
38
|
+
invoke(methodOptions, arg) {
|
|
39
|
+
return this._transport.invoke(methodOptions, arg)[0];
|
|
35
40
|
}
|
|
36
41
|
listen(event) {
|
|
37
|
-
return super.listen(event);
|
|
42
|
+
return super.listen(event ?? '');
|
|
43
|
+
}
|
|
44
|
+
get signedAuthToken() {
|
|
45
|
+
return this._transport.signedAuthToken;
|
|
38
46
|
}
|
|
39
47
|
get status() {
|
|
40
48
|
return this._transport.status;
|
|
41
49
|
}
|
|
42
|
-
get url() {
|
|
43
|
-
return this._transport.url;
|
|
44
|
-
}
|
|
45
50
|
transmit(serviceAndMethod, arg) {
|
|
46
51
|
return this._transport.transmit(serviceAndMethod, arg);
|
|
47
52
|
}
|
|
48
|
-
|
|
49
|
-
return this._transport.
|
|
53
|
+
get url() {
|
|
54
|
+
return this._transport.url;
|
|
50
55
|
}
|
|
51
56
|
}
|
package/dist/utils.d.ts
CHANGED
package/dist/utils.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
export function toArray(arr) {
|
|
2
|
+
return Array.isArray(arr) ? arr : [arr];
|
|
3
|
+
}
|
|
1
4
|
export function wait(duration) {
|
|
2
5
|
return new Promise((resolve) => {
|
|
3
6
|
setTimeout(() => {
|
|
@@ -5,6 +8,3 @@ export function wait(duration) {
|
|
|
5
8
|
}, duration);
|
|
6
9
|
});
|
|
7
10
|
}
|
|
8
|
-
export function toArray(arr) {
|
|
9
|
-
return Array.isArray(arr) ? arr : [arr];
|
|
10
|
-
}
|
package/package.json
CHANGED
|
@@ -1,42 +1,45 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
"name": "@socket-mesh/core",
|
|
3
|
+
"version": "1.0.4",
|
|
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": "node ../../scripts/publish.mjs",
|
|
12
|
+
"lint": "eslint . --c ../../eslint.config.mjs",
|
|
13
|
+
"lint:fix": "eslint . --c ../../eslint.config.mjs --fix",
|
|
14
|
+
"test": "tsx --tsconfig ./tsconfig.build.json --test ./src/**/*.{spec,test}.ts ./test/**/*.{spec,test}.ts"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"auth",
|
|
18
|
+
"jwt",
|
|
19
|
+
"socketMesh"
|
|
20
|
+
],
|
|
21
|
+
"author": "Greg Kimmy",
|
|
20
22
|
"license": "MIT",
|
|
21
23
|
"homepage": "https://github.com/socket-mesh/main/tree/main/packages/core#README.md",
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "git+https://github.com/socket-mesh/client-server.git"
|
|
27
|
+
},
|
|
28
|
+
"bugs": {
|
|
27
29
|
"url": "https://github.com/socket-mesh/client-server/labels/core"
|
|
28
|
-
|
|
30
|
+
},
|
|
29
31
|
"devDependencies": {
|
|
30
|
-
"@
|
|
31
|
-
"@types/
|
|
32
|
+
"@socket-mesh/typescript-config": "workspace:^",
|
|
33
|
+
"@types/base64id": "catalog:base64id",
|
|
34
|
+
"@types/ws": "catalog:ws"
|
|
32
35
|
},
|
|
33
36
|
"dependencies": {
|
|
34
|
-
"@socket-mesh/async-stream-emitter": "
|
|
35
|
-
"@socket-mesh/auth": "
|
|
36
|
-
"@socket-mesh/errors": "
|
|
37
|
-
"@socket-mesh/formatter": "
|
|
38
|
-
"@socket-mesh/stream-demux": "
|
|
39
|
-
"isomorphic-ws": "
|
|
40
|
-
"ws": "
|
|
37
|
+
"@socket-mesh/async-stream-emitter": "workspace:^",
|
|
38
|
+
"@socket-mesh/auth": "workspace:^",
|
|
39
|
+
"@socket-mesh/errors": "workspace:^",
|
|
40
|
+
"@socket-mesh/formatter": "workspace:^",
|
|
41
|
+
"@socket-mesh/stream-demux": "workspace:^",
|
|
42
|
+
"isomorphic-ws": "catalog:ws",
|
|
43
|
+
"ws": "catalog:ws"
|
|
41
44
|
}
|
|
42
45
|
}
|
|
@@ -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 {};
|