@eleven-am/pondsocket-nest 0.0.113 → 0.0.115

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.
@@ -10,48 +10,34 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
10
10
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
11
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
12
  };
13
- var _Context_data, _Context_request, _Context_response, _Context_instance, _Context_propertyKey;
13
+ var _Context_data, _Context_context, _Context_instance, _Context_propertyKey;
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.Context = void 0;
16
16
  class Context {
17
- constructor(request, response, instance, propertyKey) {
17
+ constructor(context, instance, propertyKey) {
18
18
  _Context_data.set(this, {});
19
- _Context_request.set(this, void 0);
20
- _Context_response.set(this, void 0);
19
+ _Context_context.set(this, void 0);
21
20
  _Context_instance.set(this, void 0);
22
21
  _Context_propertyKey.set(this, void 0);
23
- __classPrivateFieldSet(this, _Context_request, request, "f");
24
- __classPrivateFieldSet(this, _Context_response, response, "f");
22
+ __classPrivateFieldSet(this, _Context_context, context, "f");
25
23
  __classPrivateFieldSet(this, _Context_instance, instance, "f");
26
24
  __classPrivateFieldSet(this, _Context_propertyKey, propertyKey, "f");
27
25
  }
28
- get joinRequest() {
26
+ get joinContext() {
29
27
  var _a;
30
- return (_a = __classPrivateFieldGet(this, _Context_request, "f").joinRequest) !== null && _a !== void 0 ? _a : null;
28
+ return (_a = __classPrivateFieldGet(this, _Context_context, "f").join) !== null && _a !== void 0 ? _a : null;
31
29
  }
32
- get eventRequest() {
30
+ get eventContext() {
33
31
  var _a;
34
- return (_a = __classPrivateFieldGet(this, _Context_request, "f").eventRequest) !== null && _a !== void 0 ? _a : null;
32
+ return (_a = __classPrivateFieldGet(this, _Context_context, "f").event) !== null && _a !== void 0 ? _a : null;
35
33
  }
36
- get connection() {
34
+ get connectionContext() {
37
35
  var _a;
38
- return (_a = __classPrivateFieldGet(this, _Context_request, "f").connection) !== null && _a !== void 0 ? _a : null;
36
+ return (_a = __classPrivateFieldGet(this, _Context_context, "f").connection) !== null && _a !== void 0 ? _a : null;
39
37
  }
40
38
  get leaveEvent() {
41
39
  var _a;
42
- return (_a = __classPrivateFieldGet(this, _Context_request, "f").leveeEvent) !== null && _a !== void 0 ? _a : null;
43
- }
44
- get joinResponse() {
45
- var _a;
46
- return (_a = __classPrivateFieldGet(this, _Context_response, "f").joinResponse) !== null && _a !== void 0 ? _a : null;
47
- }
48
- get eventResponse() {
49
- var _a;
50
- return (_a = __classPrivateFieldGet(this, _Context_response, "f").eventResponse) !== null && _a !== void 0 ? _a : null;
51
- }
52
- get connectionResponse() {
53
- var _a;
54
- return (_a = __classPrivateFieldGet(this, _Context_response, "f").connection) !== null && _a !== void 0 ? _a : null;
40
+ return (_a = __classPrivateFieldGet(this, _Context_context, "f").leave) !== null && _a !== void 0 ? _a : null;
55
41
  }
56
42
  get presence() {
57
43
  return this.user.presence;
@@ -61,9 +47,9 @@ class Context {
61
47
  }
62
48
  get user() {
63
49
  var _a, _b;
64
- if (this.connection) {
50
+ if (this.connectionContext) {
65
51
  const user = {
66
- id: this.connection.id,
52
+ id: this.connectionContext.clientId,
67
53
  assigns: {},
68
54
  presence: {},
69
55
  };
@@ -72,24 +58,24 @@ class Context {
72
58
  else if (this.leaveEvent) {
73
59
  return this.leaveEvent.user;
74
60
  }
75
- return (_b = (_a = this.joinRequest) === null || _a === void 0 ? void 0 : _a.user) !== null && _b !== void 0 ? _b : this.eventRequest.user;
61
+ return (_b = (_a = this.joinContext) === null || _a === void 0 ? void 0 : _a.user) !== null && _b !== void 0 ? _b : this.eventContext.user;
76
62
  }
77
63
  get channel() {
78
64
  var _a, _b, _c, _d, _e, _f;
79
- return (_f = (_d = (_b = (_a = this.joinRequest) === null || _a === void 0 ? void 0 : _a.channel) !== null && _b !== void 0 ? _b : (_c = this.eventRequest) === null || _c === void 0 ? void 0 : _c.channel) !== null && _d !== void 0 ? _d : (_e = this.leaveEvent) === null || _e === void 0 ? void 0 : _e.channel) !== null && _f !== void 0 ? _f : null;
65
+ return (_f = (_d = (_b = (_a = this.joinContext) === null || _a === void 0 ? void 0 : _a.channel) !== null && _b !== void 0 ? _b : (_c = this.eventContext) === null || _c === void 0 ? void 0 : _c.channel) !== null && _d !== void 0 ? _d : (_e = this.leaveEvent) === null || _e === void 0 ? void 0 : _e.channel) !== null && _f !== void 0 ? _f : null;
80
66
  }
81
67
  get event() {
82
68
  var _a, _b, _c, _d;
83
- if (this.connection) {
69
+ if (this.connectionContext) {
84
70
  const event = {
85
- params: this.connection.params,
86
- query: this.connection.query,
71
+ params: this.connectionContext.params,
72
+ query: this.connectionContext.query,
87
73
  payload: {},
88
74
  event: 'CONNECTION',
89
75
  };
90
76
  return event;
91
77
  }
92
- return (_d = (_b = (_a = this.joinRequest) === null || _a === void 0 ? void 0 : _a.event) !== null && _b !== void 0 ? _b : (_c = this.eventRequest) === null || _c === void 0 ? void 0 : _c.event) !== null && _d !== void 0 ? _d : null;
78
+ return (_d = (_b = (_a = this.joinContext) === null || _a === void 0 ? void 0 : _a.event) !== null && _b !== void 0 ? _b : (_c = this.eventContext) === null || _c === void 0 ? void 0 : _c.event) !== null && _d !== void 0 ? _d : null;
93
79
  }
94
80
  getClass() {
95
81
  return __classPrivateFieldGet(this, _Context_instance, "f").constructor;
@@ -112,4 +98,4 @@ class Context {
112
98
  }
113
99
  }
114
100
  exports.Context = Context;
115
- _Context_data = new WeakMap(), _Context_request = new WeakMap(), _Context_response = new WeakMap(), _Context_instance = new WeakMap(), _Context_propertyKey = new WeakMap();
101
+ _Context_data = new WeakMap(), _Context_context = new WeakMap(), _Context_instance = new WeakMap(), _Context_propertyKey = new WeakMap();
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GetConnectionContext = void 0;
4
+ const createParamDecorator_1 = require("../helpers/createParamDecorator");
5
+ exports.GetConnectionContext = (0, createParamDecorator_1.createParamDecorator)((data, context) => {
6
+ const connection = context.connectionContext;
7
+ if (!connection) {
8
+ throw new Error('Invalid decorator usage: GetConnectionContext');
9
+ }
10
+ return connection;
11
+ });
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.GetConnectionHeaders = void 0;
4
4
  const createParamDecorator_1 = require("../helpers/createParamDecorator");
5
5
  exports.GetConnectionHeaders = (0, createParamDecorator_1.createParamDecorator)((data, context) => {
6
- const connection = context.connection;
6
+ const connection = context.connectionContext;
7
7
  if (!connection) {
8
8
  throw new Error('Invalid decorator usage: GetConnectionHeaders');
9
9
  }
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GetEventContext = void 0;
4
+ const createParamDecorator_1 = require("../helpers/createParamDecorator");
5
+ exports.GetEventContext = (0, createParamDecorator_1.createParamDecorator)((data, context) => {
6
+ const joinContext = context.joinContext;
7
+ if (!joinContext) {
8
+ throw new Error('Invalid decorator usage: GetEventContext');
9
+ }
10
+ return joinContext;
11
+ });
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GetJoinRequest = void 0;
3
+ exports.GetJoinContext = void 0;
4
4
  const createParamDecorator_1 = require("../helpers/createParamDecorator");
5
- exports.GetJoinRequest = (0, createParamDecorator_1.createParamDecorator)((data, context) => {
6
- const joinRequest = context.joinRequest;
5
+ exports.GetJoinContext = (0, createParamDecorator_1.createParamDecorator)((data, context) => {
6
+ const joinRequest = context.joinContext;
7
7
  if (!joinRequest) {
8
- throw new Error('Invalid decorator usage: GetJoinRequest');
8
+ throw new Error('Invalid decorator usage: GetJoinContext');
9
9
  }
10
10
  return joinRequest;
11
11
  });
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.GetJoinParams = void 0;
4
4
  const createParamDecorator_1 = require("../helpers/createParamDecorator");
5
5
  exports.GetJoinParams = (0, createParamDecorator_1.createParamDecorator)((data, context) => {
6
- const joinRequest = context.joinRequest;
6
+ const joinRequest = context.joinContext;
7
7
  if (!joinRequest) {
8
8
  throw new Error('Invalid decorator usage: GetJoinParams');
9
9
  }
@@ -20,17 +20,14 @@ __exportStar(require("./endpoint"), exports);
20
20
  __exportStar(require("./endpointInstance"), exports);
21
21
  __exportStar(require("./getChannel"), exports);
22
22
  __exportStar(require("./getConnectionHeaders"), exports);
23
- __exportStar(require("./getConnectionRequest"), exports);
24
- __exportStar(require("./getConnectionResponse"), exports);
23
+ __exportStar(require("./getConnectionContext"), exports);
25
24
  __exportStar(require("./getContext"), exports);
26
25
  __exportStar(require("./getEventParams"), exports);
27
26
  __exportStar(require("./getEventPayload"), exports);
28
27
  __exportStar(require("./getEventQuery"), exports);
29
- __exportStar(require("./getEventRequest"), exports);
30
- __exportStar(require("./getEventResponse"), exports);
28
+ __exportStar(require("./getEventContext"), exports);
31
29
  __exportStar(require("./getJoinParams"), exports);
32
- __exportStar(require("./getJoinRequest"), exports);
33
- __exportStar(require("./getJoinResponse"), exports);
30
+ __exportStar(require("./getJoinContext"), exports);
34
31
  __exportStar(require("./getLeaveEvent"), exports);
35
32
  __exportStar(require("./getUserAssigns"), exports);
36
33
  __exportStar(require("./getUserData"), exports);
@@ -17,12 +17,12 @@ function OnConnectionRequest() {
17
17
  return (target, propertyKey, descriptor) => {
18
18
  const originalMethod = descriptor.value;
19
19
  const { set } = (0, connection_1.manageConnection)(target);
20
- set('', (instance, moduleRef, globalGuards, globalPipes, request, response) => __awaiter(this, void 0, void 0, function* () {
20
+ set('', (instance, moduleRef, globalGuards, globalPipes, ctx) => __awaiter(this, void 0, void 0, function* () {
21
21
  try {
22
- yield (0, action_1.performAction)(instance, moduleRef, globalGuards, globalPipes, originalMethod, propertyKey, null, request, response);
22
+ yield (0, action_1.performAction)(instance, moduleRef, globalGuards, globalPipes, originalMethod, propertyKey, ctx);
23
23
  }
24
24
  catch (error) {
25
- (0, errors_1.performErrors)(error, response);
25
+ (0, errors_1.performErrors)(error, ctx);
26
26
  }
27
27
  }));
28
28
  };
@@ -17,12 +17,12 @@ function OnEvent(event = '*') {
17
17
  return (target, propertyKey, descriptor) => {
18
18
  const originalMethod = descriptor.value;
19
19
  const { set } = (0, event_1.manageEvent)(target);
20
- set(event, (instance, moduleRef, globalGuards, globalPipes, request, response) => __awaiter(this, void 0, void 0, function* () {
20
+ set(event, (instance, moduleRef, globalGuards, globalPipes, ctx) => __awaiter(this, void 0, void 0, function* () {
21
21
  try {
22
- yield (0, action_1.performAction)(instance, moduleRef, globalGuards, globalPipes, originalMethod, propertyKey, null, request, response);
22
+ yield (0, action_1.performAction)(instance, moduleRef, globalGuards, globalPipes, originalMethod, propertyKey, ctx);
23
23
  }
24
24
  catch (error) {
25
- (0, errors_1.performErrors)(error, response);
25
+ (0, errors_1.performErrors)(error, ctx);
26
26
  }
27
27
  }));
28
28
  };
@@ -17,12 +17,12 @@ function OnJoinRequest() {
17
17
  return (target, propertyKey, descriptor) => {
18
18
  const originalMethod = descriptor.value;
19
19
  const { set } = (0, join_1.manageJoin)(target);
20
- set('', (instance, moduleRef, globalGuards, globalPipes, request, response) => __awaiter(this, void 0, void 0, function* () {
20
+ set('', (instance, moduleRef, globalGuards, globalPipes, ctx) => __awaiter(this, void 0, void 0, function* () {
21
21
  try {
22
- yield (0, action_1.performAction)(instance, moduleRef, globalGuards, globalPipes, originalMethod, propertyKey, null, request, response);
22
+ yield (0, action_1.performAction)(instance, moduleRef, globalGuards, globalPipes, originalMethod, propertyKey, ctx);
23
23
  }
24
24
  catch (error) {
25
- (0, errors_1.performErrors)(error, response);
25
+ (0, errors_1.performErrors)(error, ctx);
26
26
  }
27
27
  }));
28
28
  };
@@ -17,7 +17,12 @@ function OnLeave() {
17
17
  const originalMethod = descriptor.value;
18
18
  const { set } = (0, leave_1.manageLeave)(target);
19
19
  set('', (instance, moduleRef, globalGuards, globalPipes, leaveEvent) => __awaiter(this, void 0, void 0, function* () {
20
- yield (0, action_1.performAction)(instance, moduleRef, globalGuards, globalPipes, originalMethod, propertyKey, leaveEvent);
20
+ try {
21
+ yield (0, action_1.performAction)(instance, moduleRef, globalGuards, globalPipes, originalMethod, propertyKey, leaveEvent);
22
+ }
23
+ catch (err) {
24
+ // no-op
25
+ }
21
26
  }));
22
27
  };
23
28
  }
package/index.d.ts CHANGED
@@ -1,18 +1,17 @@
1
1
  import type {
2
2
  Channel as PondChannel,
3
- ConnectionResponse,
4
- EventRequest,
5
- EventResponse,
6
- IncomingConnection,
7
- JoinRequest,
8
- JoinResponse,
9
3
  LeaveEvent,
4
+ ConnectionContext,
5
+ JoinContext,
6
+ EventContext,
10
7
  PondAssigns,
11
8
  PondEvent,
12
9
  PondEventMap,
13
10
  PondMessage,
14
11
  PondPresence,
15
12
  UserData,
13
+ Params,
14
+ JoinParams,
16
15
  } from '@eleven-am/pondsocket/types';
17
16
  import type { DynamicModule, ModuleMetadata, PipeTransform } from '@nestjs/common';
18
17
 
@@ -178,16 +177,10 @@ declare const GetChannel: () => ParameterDecorator;
178
177
  declare const GetConnectionHeaders: () => ParameterDecorator;
179
178
 
180
179
  /**
181
- * @desc Parameter decorator that retrieves the current connection request
182
- * @returns {IncomingConnection}
180
+ * @desc Parameter decorator that retrieves the current connection context
181
+ * @returns {ConnectionContext<string>}
183
182
  */
184
- declare const GetConnectionRequest: () => ParameterDecorator;
185
-
186
- /**
187
- * @desc Parameter decorator that retrieves the current connection response
188
- * @returns {ConnectionResponse}
189
- */
190
- declare const GetConnectionResponse: () => ParameterDecorator;
183
+ declare const GetConnectionContext: () => ParameterDecorator;
191
184
 
192
185
  /**
193
186
  * @desc Parameter decorator that retrieves the current context
@@ -214,16 +207,10 @@ declare const GetEventPayload: () => ParameterDecorator;
214
207
  declare const GetEventQuery: () => ParameterDecorator;
215
208
 
216
209
  /**
217
- * @desc Parameter decorator that retrieves the current event request
218
- * @returns {EventRequest}
210
+ * @desc Parameter decorator that retrieves the current event context
211
+ * @returns {EventContext<string>}
219
212
  */
220
- declare const GetEventRequest: () => ParameterDecorator;
221
-
222
- /**
223
- * @desc Parameter decorator that retrieves the current event response
224
- * @returns {EventResponse}
225
- */
226
- declare const GetEventResponse: () => ParameterDecorator;
213
+ declare const GetEventContext: () => ParameterDecorator;
227
214
 
228
215
  /**
229
216
  * @desc Parameter decorator that retrieves the current join params
@@ -232,16 +219,10 @@ declare const GetEventResponse: () => ParameterDecorator;
232
219
  declare const GetJoinParams: () => ParameterDecorator;
233
220
 
234
221
  /**
235
- * @desc Parameter decorator that retrieves the current join request
236
- * @returns {JoinRequest}
237
- */
238
- declare const GetJoinRequest: () => ParameterDecorator;
239
-
240
- /**
241
- * @desc Parameter decorator that retrieves the current join response
242
- * @returns {JoinResponse}
222
+ * @desc Parameter decorator that retrieves the current join context
223
+ * @returns {JoinContext<string>}
243
224
  */
244
- declare const GetJoinResponse: () => ParameterDecorator;
225
+ declare const GetJoinContext: () => ParameterDecorator;
245
226
 
246
227
  /**
247
228
  * @desc Parameter decorator that retrieves the current leave event
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eleven-am/pondsocket-nest",
3
- "version": "0.0.113",
3
+ "version": "0.0.115",
4
4
  "description": "PondSocket is a fast simple socket server",
5
5
  "keywords": [
6
6
  "socket",
@@ -28,19 +28,19 @@
28
28
  "pipeline": "npm run build && npm run push"
29
29
  },
30
30
  "dependencies": {
31
- "@eleven-am/pondsocket": "^0.1.198",
32
- "@golevelup/nestjs-discovery": "^4.0.3"
31
+ "@eleven-am/pondsocket": "^0.1.200",
32
+ "@golevelup/nestjs-discovery": "^5.0.0"
33
33
  },
34
34
  "devDependencies": {
35
- "@nestjs/common": "^11.1.0",
36
- "@nestjs/core": "^11.1.0",
35
+ "@nestjs/common": "^11.1.1",
36
+ "@nestjs/core": "^11.1.1",
37
37
  "@types/jest": "^29.5.14",
38
- "@typescript-eslint/eslint-plugin": "^8.31.1",
38
+ "@typescript-eslint/eslint-plugin": "^8.32.1",
39
39
  "eslint-plugin-file-progress": "^3.0.2",
40
40
  "eslint-plugin-import": "^2.31.0",
41
41
  "jest": "^29.7.0",
42
42
  "prettier": "^3.5.3",
43
- "ts-jest": "^29.3.2",
43
+ "ts-jest": "^29.3.3",
44
44
  "ts-loader": "^9.5.2",
45
45
  "ts-node": "^10.9.2",
46
46
  "typescript": "^5.8.3"
@@ -35,8 +35,10 @@ function retrieveParameters(context, globalPipes, moduleRef) {
35
35
  }
36
36
  function performGuards(moduleRef, globalGuards, context) {
37
37
  return __awaiter(this, void 0, void 0, function* () {
38
- const classGuards = (0, guards_1.manageGuards)(context.getClass()).get();
39
- const methodGuards = (0, guards_1.manageGuards)(context.getInstance(), context.getMethod()).get();
38
+ const classGuards = (0, guards_1.manageGuards)(context.getClass())
39
+ .get();
40
+ const methodGuards = (0, guards_1.manageGuards)(context.getInstance(), context.getMethod())
41
+ .get();
40
42
  const guards = globalGuards
41
43
  .concat(classGuards, methodGuards)
42
44
  .map((Guard) => (0, misc_1.retrieveInstance)(moduleRef, Guard));
@@ -45,37 +47,39 @@ function performGuards(moduleRef, globalGuards, context) {
45
47
  return results.every((result) => result);
46
48
  });
47
49
  }
48
- function performAction(instance, moduleRef, globalGuards, globalPipes, originalMethod, propertyKey, leaveEvent, request, response) {
50
+ function getNestContext(context) {
51
+ if ((0, narrow_1.isJoinContext)(context)) {
52
+ return {
53
+ join: context,
54
+ };
55
+ }
56
+ if ((0, narrow_1.isEventContext)(context)) {
57
+ return {
58
+ event: context,
59
+ };
60
+ }
61
+ if ((0, narrow_1.isConnectionContext)(context)) {
62
+ return {
63
+ connection: context,
64
+ };
65
+ }
66
+ return {
67
+ leave: context,
68
+ };
69
+ }
70
+ function performAction(instance, moduleRef, globalGuards, globalPipes, originalMethod, propertyKey, input) {
49
71
  return __awaiter(this, void 0, void 0, function* () {
50
- const req = {};
51
- const res = {};
52
- if (request && response) {
53
- if ((0, narrow_1.isJoinRequest)(request) && (0, narrow_1.isJoinResponse)(response)) {
54
- req.joinRequest = request;
55
- res.joinResponse = response;
56
- }
57
- else if ((0, narrow_1.isEventRequest)(request) && (0, narrow_1.isEventResponse)(response)) {
58
- req.eventRequest = request;
59
- res.eventResponse = response;
60
- }
61
- else if ((0, narrow_1.isConnectionRequest)(request) && (0, narrow_1.isConnectionResponse)(response)) {
62
- req.connection = request;
63
- res.connection = response;
64
- }
65
- }
66
- else if (leaveEvent) {
67
- req.leveeEvent = leaveEvent;
68
- }
69
- const context = new context_1.Context(req, res, instance, propertyKey);
72
+ const ctx = getNestContext(input);
73
+ const context = new context_1.Context(ctx, instance, propertyKey);
70
74
  const channel = context.channel;
71
75
  const socketId = context.user.id;
72
76
  const canProceed = yield performGuards(moduleRef, globalGuards, context);
73
77
  if (canProceed) {
74
78
  const data = yield originalMethod.apply(instance, yield retrieveParameters(context, globalPipes, moduleRef));
75
- (0, response_1.performResponse)(socketId, channel, data, response);
79
+ (0, response_1.performResponse)(socketId, channel, data, input);
76
80
  }
77
- else if (response && ((0, narrow_1.isJoinResponse)(response) || (0, narrow_1.isConnectionResponse)(response))) {
78
- response.decline('Unauthorized', 403);
81
+ else if ((0, narrow_1.isJoinContext)(input) || (0, narrow_1.isJoinContext)(input)) {
82
+ input.decline('Unauthorized', 403);
79
83
  }
80
84
  });
81
85
  }
@@ -22,7 +22,7 @@ function performErrors(error, response) {
22
22
  message = 'An unknown error occurred';
23
23
  status = 500;
24
24
  }
25
- if ((0, narrow_1.isEventResponse)(response)) {
25
+ if ((0, narrow_1.isEventContext)(response)) {
26
26
  return response.reply('UNKNOWN_ERROR', {
27
27
  message,
28
28
  data,
@@ -1,26 +1,21 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isEventRequest = isEventRequest;
4
- exports.isJoinRequest = isJoinRequest;
5
- exports.isConnectionRequest = isConnectionRequest;
6
- exports.isEventResponse = isEventResponse;
7
- exports.isJoinResponse = isJoinResponse;
8
- exports.isConnectionResponse = isConnectionResponse;
9
- function isEventRequest(request) {
10
- return 'channel' in request && !('joinParams' in request);
11
- }
12
- function isJoinRequest(request) {
13
- return 'joinParams' in request;
14
- }
15
- function isConnectionRequest(request) {
16
- return 'headers' in request;
17
- }
18
- function isEventResponse(response) {
3
+ exports.isEventContext = isEventContext;
4
+ exports.isJoinContext = isJoinContext;
5
+ exports.isConnectionContext = isConnectionContext;
6
+ exports.isLeaveEvent = isLeaveEvent;
7
+ function isEventContext(response) {
19
8
  return !('accept' in response);
20
9
  }
21
- function isJoinResponse(response) {
10
+ function isJoinContext(response) {
22
11
  return 'accept' in response && 'broadcast' in response;
23
12
  }
24
- function isConnectionResponse(response) {
13
+ function isConnectionContext(response) {
25
14
  return 'accept' in response && !('broadcast' in response);
26
15
  }
16
+ function isLeaveEvent(response) {
17
+ const isJoin = isJoinContext(response);
18
+ const isEvent = isEventContext(response);
19
+ const isConnection = isConnectionContext(response);
20
+ return !isJoin && !isEvent && !isConnection;
21
+ }
@@ -19,40 +19,40 @@ function isNotEmpty(value) {
19
19
  value !== '' &&
20
20
  Object.keys(value).length !== 0;
21
21
  }
22
- function performResponse(socketId, channel, data, response) {
23
- if (response && response.hasResponded || !isNotEmpty(data)) {
22
+ function performResponse(socketId, channel, data, context) {
23
+ if (((0, narrow_1.isLeaveEvent)(context) || !isNotEmpty(data)) || (!(0, narrow_1.isEventContext)(context) && context.hasResponded)) {
24
24
  return;
25
25
  }
26
26
  const { event, presence, assigns, broadcast, broadcastFrom, broadcastTo } = data, rest = __rest(data, ["event", "presence", "assigns", "broadcast", "broadcastFrom", "broadcastTo"]);
27
- if (response) {
28
- if ((0, narrow_1.isConnectionResponse)(response) || (0, narrow_1.isJoinResponse)(response)) {
29
- response
27
+ if (context) {
28
+ if ((0, narrow_1.isConnectionContext)(context) || (0, narrow_1.isJoinContext)(context)) {
29
+ context
30
30
  .assign(typeof assigns === 'object' ? assigns : {})
31
31
  .accept();
32
32
  }
33
33
  else {
34
- response
34
+ context
35
35
  .assign(typeof assigns === 'object' ? assigns : {});
36
36
  }
37
37
  if (isNotEmpty(rest)) {
38
38
  if (event) {
39
- response.reply(event, rest);
39
+ context.reply(event, rest);
40
40
  }
41
- if ((0, narrow_1.isJoinResponse)(response) || (0, narrow_1.isEventResponse)(response)) {
41
+ if ((0, narrow_1.isJoinContext)(context) || (0, narrow_1.isEventContext)(context)) {
42
42
  if (broadcast) {
43
- response.broadcast(broadcast, rest);
43
+ context.broadcast(broadcast, rest);
44
44
  }
45
45
  if (broadcastFrom) {
46
- response.broadcastFrom(broadcastFrom, rest);
46
+ context.broadcastFrom(broadcastFrom, rest);
47
47
  }
48
48
  if (broadcastTo) {
49
- response.broadcastTo(broadcastTo.event, rest, broadcastTo.users);
49
+ context.broadcastTo(broadcastTo.event, rest, broadcastTo.users);
50
50
  }
51
51
  }
52
52
  }
53
53
  }
54
54
  if (channel) {
55
- if (isNotEmpty(rest) && !response) {
55
+ if (isNotEmpty(rest) && !context) {
56
56
  if (broadcast || event) {
57
57
  const newEvent = (broadcast || event);
58
58
  channel.broadcast(newEvent, rest);
@@ -56,12 +56,12 @@ class PondSocketService {
56
56
  const { get } = (0, connection_1.manageConnection)(instance);
57
57
  const channels = [...new Set([...groupedInstance.channels.map((channel) => channel)])];
58
58
  const [handler] = get();
59
- const endpoint = socket.createEndpoint(metadata, (request, response) => __awaiter(this, void 0, void 0, function* () {
59
+ const endpoint = socket.createEndpoint(metadata, (context) => __awaiter(this, void 0, void 0, function* () {
60
60
  if (handler) {
61
- yield handler.value(instance, this.moduleRef, this.globalGuards, this.globalPipes, request, response);
61
+ yield handler.value(instance, this.moduleRef, this.globalGuards, this.globalPipes, context);
62
62
  }
63
63
  else {
64
- response.accept();
64
+ context.accept();
65
65
  }
66
66
  }));
67
67
  this.logger.log(`Mapped {${metadata}} endpoint`);
@@ -81,12 +81,12 @@ class PondSocketService {
81
81
  const { set: setChannel } = (0, channelInstance_1.manageChannelInstance)(instance);
82
82
  const { get } = (0, join_1.manageJoin)(instance);
83
83
  const [handler] = get();
84
- const channelInstance = endpoint.createChannel(path, (request, response) => __awaiter(this, void 0, void 0, function* () {
84
+ const channelInstance = endpoint.createChannel(path, (context) => __awaiter(this, void 0, void 0, function* () {
85
85
  if (handler) {
86
- yield handler.value(instance, this.moduleRef, this.globalGuards, this.globalPipes, request, response);
86
+ yield handler.value(instance, this.moduleRef, this.globalGuards, this.globalPipes, context);
87
87
  }
88
88
  else {
89
- response.accept();
89
+ context.accept();
90
90
  }
91
91
  }));
92
92
  this.logger.log(`Mapped {${endpointPath}${path}} channel`);
@@ -97,8 +97,8 @@ class PondSocketService {
97
97
  const { get: getEventHandlers } = (0, event_1.manageEvent)(instance);
98
98
  const { get: getLeaveHandlers } = (0, leave_1.manageLeave)(instance);
99
99
  getEventHandlers().forEach((handler) => {
100
- channelInstance.onEvent(handler.path, (request, response) => __awaiter(this, void 0, void 0, function* () {
101
- yield handler.value(instance, this.moduleRef, this.globalGuards, this.globalPipes, request, response);
100
+ channelInstance.onEvent(handler.path, (context) => __awaiter(this, void 0, void 0, function* () {
101
+ yield handler.value(instance, this.moduleRef, this.globalGuards, this.globalPipes, context);
102
102
  }));
103
103
  this.logger.log(`Mapped {${endpointPath}${path}} event {${handler.path}}`);
104
104
  });
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GetConnectionRequest = void 0;
4
- const createParamDecorator_1 = require("../helpers/createParamDecorator");
5
- exports.GetConnectionRequest = (0, createParamDecorator_1.createParamDecorator)((data, context) => {
6
- const connectionRequest = context.connection;
7
- if (!connectionRequest) {
8
- throw new Error('Invalid decorator usage: GetConnectionRequest');
9
- }
10
- return connectionRequest;
11
- });
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GetConnectionResponse = void 0;
4
- const createParamDecorator_1 = require("../helpers/createParamDecorator");
5
- exports.GetConnectionResponse = (0, createParamDecorator_1.createParamDecorator)((data, context) => {
6
- const connectionResponse = context.connectionResponse;
7
- if (!connectionResponse) {
8
- throw new Error('Invalid decorator usage: GetConnectionResponse');
9
- }
10
- return connectionResponse;
11
- });
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GetEventRequest = void 0;
4
- const createParamDecorator_1 = require("../helpers/createParamDecorator");
5
- exports.GetEventRequest = (0, createParamDecorator_1.createParamDecorator)((data, context) => {
6
- const joinRequest = context.joinRequest;
7
- if (!joinRequest) {
8
- throw new Error('Invalid decorator usage: GetJoinRequest');
9
- }
10
- return joinRequest;
11
- });
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GetEventResponse = void 0;
4
- const createParamDecorator_1 = require("../helpers/createParamDecorator");
5
- exports.GetEventResponse = (0, createParamDecorator_1.createParamDecorator)((data, context) => {
6
- const eventResponse = context.eventResponse;
7
- if (!eventResponse) {
8
- throw new Error('Invalid decorator usage: GetEventResponse');
9
- }
10
- return eventResponse;
11
- });
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GetJoinResponse = void 0;
4
- const createParamDecorator_1 = require("../helpers/createParamDecorator");
5
- exports.GetJoinResponse = (0, createParamDecorator_1.createParamDecorator)((data, context) => {
6
- const joinResponse = context.joinResponse;
7
- if (!joinResponse) {
8
- throw new Error('Invalid decorator usage: GetJoinResponse');
9
- }
10
- return joinResponse;
11
- });