@eleven-am/pondsocket 0.1.79 → 0.1.81
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/nest.d.ts +2 -2
- package/nest.js +23 -7
- package/package.json +7 -7
- package/types.d.ts +15 -9
package/nest.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
GetConnectionRequest, GetConnectionResponse,
|
|
14
14
|
GetConnectionQuery, GetConnectionHeaders,
|
|
15
15
|
GetConnectionRequestId, GetEventPayload,
|
|
16
|
-
GetUserData,
|
|
16
|
+
GetUserData, GetUserPresences, GetInternalChannel,
|
|
17
17
|
} from './types';
|
|
18
18
|
|
|
19
19
|
export {
|
|
@@ -29,5 +29,5 @@ export {
|
|
|
29
29
|
GetConnectionRequestId, GetEventPayload,
|
|
30
30
|
GetConnectionParams, GetConnectionRequest,
|
|
31
31
|
GetConnectionResponse, GetConnectionHeaders,
|
|
32
|
-
GetUserData,
|
|
32
|
+
GetUserData, GetUserPresences, GetInternalChannel,
|
|
33
33
|
}
|
package/nest.js
CHANGED
|
@@ -20,7 +20,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
20
20
|
return t;
|
|
21
21
|
};
|
|
22
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
-
exports.PondSocketModule = exports.Endpoints = exports.Endpoint = exports.Channels = exports.ChannelInstance = exports.Channel = exports.OnConnectionRequest = exports.OnEvent = exports.OnJoinRequest = exports.GetConnectionQuery = exports.GetConnectionHeaders = exports.GetConnectionParams = exports.GetConnectionRequestId = exports.GetConnectionResponse = exports.GetConnectionRequest = exports.GetEventRequest = exports.GetEventResponse = exports.GetEventQuery = exports.GetEventParams = exports.GetEventPayload = exports.
|
|
23
|
+
exports.PondSocketModule = exports.Endpoints = exports.Endpoint = exports.Channels = exports.ChannelInstance = exports.Channel = exports.OnConnectionRequest = exports.OnEvent = exports.OnJoinRequest = exports.GetConnectionQuery = exports.GetConnectionHeaders = exports.GetConnectionParams = exports.GetConnectionRequestId = exports.GetConnectionResponse = exports.GetConnectionRequest = exports.GetEventRequest = exports.GetEventResponse = exports.GetEventQuery = exports.GetEventParams = exports.GetEventPayload = exports.GetUserPresences = exports.GetInternalChannel = exports.GetUserData = exports.GetJoinParams = exports.GetJoinResponse = exports.GetJoinRequest = void 0;
|
|
24
24
|
const common_1 = require("@nestjs/common");
|
|
25
25
|
require("reflect-metadata");
|
|
26
26
|
const pondSocket_1 = require("./server/pondSocket");
|
|
@@ -139,10 +139,10 @@ function GetInternalChannel() {
|
|
|
139
139
|
return createParamDecorator(internalChannelKey, 'InternalChannel decorator already applied');
|
|
140
140
|
}
|
|
141
141
|
exports.GetInternalChannel = GetInternalChannel;
|
|
142
|
-
function
|
|
142
|
+
function GetUserPresences() {
|
|
143
143
|
return createParamDecorator(userPresenceKey, 'UserPresence decorator already applied');
|
|
144
144
|
}
|
|
145
|
-
exports.
|
|
145
|
+
exports.GetUserPresences = GetUserPresences;
|
|
146
146
|
function GetEventPayload() {
|
|
147
147
|
return createParamDecorator(eventPayloadKey, 'EventPayload decorator already applied');
|
|
148
148
|
}
|
|
@@ -245,6 +245,7 @@ function resolveJoinParameters(request, response, target, propertyKey) {
|
|
|
245
245
|
}
|
|
246
246
|
function resolveEventParameters(request, response, target, propertyKey) {
|
|
247
247
|
const userDataIndex = resolveParamDecorator(userDataKey, target, propertyKey);
|
|
248
|
+
const userPresenceIndex = resolveParamDecorator(userPresenceKey, target, propertyKey);
|
|
248
249
|
const internalChannelIndex = resolveParamDecorator(internalChannelKey, target, propertyKey);
|
|
249
250
|
const eventParamsIndex = resolveParamDecorator(eventParamsKey, target, propertyKey);
|
|
250
251
|
const eventQueryIndex = resolveParamDecorator(eventQueryKey, target, propertyKey);
|
|
@@ -259,12 +260,12 @@ function resolveEventParameters(request, response, target, propertyKey) {
|
|
|
259
260
|
eventPayloadIndex,
|
|
260
261
|
eventResponseIndex,
|
|
261
262
|
eventRequestIndex,
|
|
263
|
+
userPresenceIndex,
|
|
262
264
|
].filter((index) => typeof index === 'number');
|
|
263
265
|
const rejectedKeys = [
|
|
264
266
|
joinRequestKey,
|
|
265
267
|
joinResponseKey,
|
|
266
268
|
joinParamsKey,
|
|
267
|
-
userPresenceKey,
|
|
268
269
|
connectionRequestKey,
|
|
269
270
|
connectionResponseKey,
|
|
270
271
|
connectionRequestIdKey,
|
|
@@ -294,6 +295,8 @@ function resolveEventParameters(request, response, target, propertyKey) {
|
|
|
294
295
|
return response;
|
|
295
296
|
case eventRequestIndex:
|
|
296
297
|
return request;
|
|
298
|
+
case userPresenceIndex:
|
|
299
|
+
return request.presence;
|
|
297
300
|
default:
|
|
298
301
|
throw new Error('Invalid parameter decorator');
|
|
299
302
|
}
|
|
@@ -496,7 +499,8 @@ function Endpoint(path = '*') {
|
|
|
496
499
|
};
|
|
497
500
|
}
|
|
498
501
|
exports.Endpoint = Endpoint;
|
|
499
|
-
function Endpoints(
|
|
502
|
+
function Endpoints(metadata) {
|
|
503
|
+
const { endpoints, imports, exports = [], providers = [], isGlobal = false } = metadata;
|
|
500
504
|
return (constructor) => {
|
|
501
505
|
const channels = endpoints.reduce((acc, endpoint) => {
|
|
502
506
|
const { get } = manageChannels(endpoint.prototype);
|
|
@@ -505,10 +509,22 @@ function Endpoints(endpoints) {
|
|
|
505
509
|
}, []);
|
|
506
510
|
const { set } = manageEndpoints(constructor.prototype);
|
|
507
511
|
set(endpoints);
|
|
512
|
+
if (isGlobal) {
|
|
513
|
+
return (0, common_1.applyDecorators)(
|
|
514
|
+
// eslint-disable-next-line new-cap
|
|
515
|
+
(0, common_1.Global)(),
|
|
516
|
+
// eslint-disable-next-line new-cap
|
|
517
|
+
(0, common_1.Module)({
|
|
518
|
+
imports,
|
|
519
|
+
exports: [...exports, ...channels],
|
|
520
|
+
providers: [...providers, ...endpoints, ...channels],
|
|
521
|
+
}))(constructor);
|
|
522
|
+
}
|
|
508
523
|
// eslint-disable-next-line new-cap
|
|
509
524
|
return (0, common_1.Module)({
|
|
510
|
-
|
|
511
|
-
exports: [...
|
|
525
|
+
imports,
|
|
526
|
+
exports: [...exports, ...channels],
|
|
527
|
+
providers: [...providers, ...endpoints, ...channels],
|
|
512
528
|
})(constructor);
|
|
513
529
|
};
|
|
514
530
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eleven-am/pondsocket",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.81",
|
|
4
4
|
"description": "PondSocket is a fast simple socket server",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"socket",
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
"url": "git+https://github.com/Eleven-am/pondSocket.git"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@nestjs/common": "^10.
|
|
33
|
-
"@nestjs/core": "^10.
|
|
32
|
+
"@nestjs/common": "^10.3.0",
|
|
33
|
+
"@nestjs/core": "^10.3.0",
|
|
34
34
|
"reflect-metadata": "^0.1.14",
|
|
35
35
|
"websocket": "^1.0.34",
|
|
36
36
|
"ws": "^8.15.1"
|
|
@@ -38,13 +38,13 @@
|
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@types/express": "^4.17.21",
|
|
40
40
|
"@types/jest": "^29.5.11",
|
|
41
|
-
"@types/node": "^20.10.
|
|
41
|
+
"@types/node": "^20.10.5",
|
|
42
42
|
"@types/websocket": "^1.0.10",
|
|
43
43
|
"@types/ws": "^8.5.10",
|
|
44
|
-
"@typescript-eslint/eslint-plugin": "^6.
|
|
45
|
-
"eslint": "^8.
|
|
44
|
+
"@typescript-eslint/eslint-plugin": "^6.15.0",
|
|
45
|
+
"eslint": "^8.56.0",
|
|
46
46
|
"eslint-plugin-file-progress": "^1.3.0",
|
|
47
|
-
"eslint-plugin-import": "^2.29.
|
|
47
|
+
"eslint-plugin-import": "^2.29.1",
|
|
48
48
|
"jest": "^29.7.0",
|
|
49
49
|
"superwstest": "^2.0.3",
|
|
50
50
|
"ts-jest": "^29.1.1",
|
package/types.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ModuleMetadata } from '@nestjs/common/interfaces/modules/module-metadata.interface';
|
|
1
2
|
import { Server as HTTPServer, IncomingHttpHeaders } from 'http';
|
|
2
3
|
|
|
3
4
|
import type { ModuleRef, HttpAdapterHost } from '@nestjs/core';
|
|
@@ -7,6 +8,7 @@ import { WebSocketServer } from 'ws';
|
|
|
7
8
|
type Unsubscribe = () => void;
|
|
8
9
|
|
|
9
10
|
type Constructor<T> = new (...args: any[]) => T;
|
|
11
|
+
declare type PropertyDecorator = (target: Object, propertyKey: string | symbol) => void;
|
|
10
12
|
declare type ClassDecorator = <TFunction extends Function>(target: TFunction) => TFunction | void;
|
|
11
13
|
declare type MethodDecorator = <T>(target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T> | void;
|
|
12
14
|
declare type ParameterDecorator = (target: Object, propertyKey: string | symbol | undefined, parameterIndex: number) => void;
|
|
@@ -48,6 +50,11 @@ interface UserAssigns {
|
|
|
48
50
|
[userId: string]: PondAssigns;
|
|
49
51
|
}
|
|
50
52
|
|
|
53
|
+
interface Metadata extends Omit<ModuleMetadata, 'controllers'> {
|
|
54
|
+
endpoints: Constructor<NonNullable<unknown>>[];
|
|
55
|
+
isGlobal?: boolean;
|
|
56
|
+
}
|
|
57
|
+
|
|
51
58
|
type PondEvent<Path> = EventParams<Path> & {
|
|
52
59
|
payload: PondMessage;
|
|
53
60
|
event: string;
|
|
@@ -652,10 +659,10 @@ declare function GetUserData(): ParameterDecorator;
|
|
|
652
659
|
declare function GetInternalChannel(): ParameterDecorator;
|
|
653
660
|
|
|
654
661
|
/**
|
|
655
|
-
* @desc The Decorator for retrieving the
|
|
656
|
-
* @returns {
|
|
662
|
+
* @desc The Decorator for retrieving the UserPresences object from the request in a handler
|
|
663
|
+
* @returns {UserPresences}
|
|
657
664
|
*/
|
|
658
|
-
declare function
|
|
665
|
+
declare function GetUserPresences(): ParameterDecorator;
|
|
659
666
|
|
|
660
667
|
/**
|
|
661
668
|
* @desc The Decorator for retrieving the event payload from the request in a handler
|
|
@@ -724,19 +731,18 @@ declare function GetConnectionHeaders(): ParameterDecorator;
|
|
|
724
731
|
declare function GetConnectionQuery(): ParameterDecorator;
|
|
725
732
|
|
|
726
733
|
/**
|
|
727
|
-
* @desc Marks a method as a handler for JoinRequest events.
|
|
728
|
-
* @param - The path for the JoinRequest event.
|
|
734
|
+
* @desc Marks a method as a handler for JoinRequest events. Throwing an error will reject the request with the error message.
|
|
729
735
|
*/
|
|
730
736
|
declare function OnJoinRequest(): MethodDecorator;
|
|
731
737
|
|
|
732
738
|
/**
|
|
733
|
-
* @desc Marks a method as a handler for events with the specified name.
|
|
739
|
+
* @desc Marks a method as a handler for events with the specified name. Throwing an error will reject the request with the error message
|
|
734
740
|
* @param event - The name of the event to handle.
|
|
735
741
|
*/
|
|
736
742
|
declare function OnEvent(event?: string): MethodDecorator;
|
|
737
743
|
|
|
738
744
|
/**
|
|
739
|
-
* @desc Marks a method as a handler for ConnectionRequest events.
|
|
745
|
+
* @desc Marks a method as a handler for ConnectionRequest events. Throwing an error will reject the request with the error message.
|
|
740
746
|
*/
|
|
741
747
|
declare function OnConnectionRequest(): MethodDecorator;
|
|
742
748
|
|
|
@@ -765,9 +771,9 @@ declare function DEndpoint(path?: string): ClassDecorator;
|
|
|
765
771
|
|
|
766
772
|
/**
|
|
767
773
|
* Decorator to mark a class as having multiple endpoints.
|
|
768
|
-
* @param
|
|
774
|
+
* @param metadata - The metadata for the endpoints.
|
|
769
775
|
*/
|
|
770
|
-
declare function Endpoints(
|
|
776
|
+
declare function Endpoints(metadata: Metadata): ClassDecorator;
|
|
771
777
|
|
|
772
778
|
declare class PondSocketModule {
|
|
773
779
|
/**
|