@eleven-am/pondsocket 0.1.110 → 0.1.112

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.
Files changed (3) hide show
  1. package/nest.js +38 -29
  2. package/package.json +1 -1
  3. package/types.d.ts +6 -7
package/nest.js CHANGED
@@ -26,6 +26,11 @@ const common_1 = require("@nestjs/common");
26
26
  // eslint-disable-next-line import/no-unresolved
27
27
  const core_1 = require("@nestjs/core");
28
28
  require("reflect-metadata");
29
+ const eventRequest_1 = require("./channel/eventRequest");
30
+ const eventResponse_1 = require("./channel/eventResponse");
31
+ const response_1 = require("./endpoint/response");
32
+ const joinRequest_1 = require("./lobby/joinRequest");
33
+ const joinResponse_1 = require("./lobby/joinResponse");
29
34
  const pondSocket_1 = require("./server/pondSocket");
30
35
  const onJoinHandlerKey = Symbol('onJoinHandlerKey');
31
36
  const onEventHandlerKey = Symbol('onEventHandlerKey');
@@ -43,10 +48,6 @@ function isNotEmpty(value) {
43
48
  value !== '' &&
44
49
  Object.keys(value).length !== 0;
45
50
  }
46
- function createClassDecorator(key, value) {
47
- // eslint-disable-next-line new-cap
48
- return (0, common_1.applyDecorators)((0, common_1.Injectable)(), (0, common_1.SetMetadata)(key, value));
49
- }
50
51
  function manageClassData(key, target) {
51
52
  return {
52
53
  get() {
@@ -58,6 +59,12 @@ function manageClassData(key, target) {
58
59
  },
59
60
  };
60
61
  }
62
+ function createClassDecorator(key, path) {
63
+ return (target) => {
64
+ const { set } = manageClassData(key, target);
65
+ set(path);
66
+ };
67
+ }
61
68
  function manageMethodData(key, target, propertyKey) {
62
69
  function getter() {
63
70
  var _a;
@@ -238,6 +245,12 @@ class Context {
238
245
  retrieveMethodData(key) {
239
246
  return manageMethodData(key, this.instance, this.propertyKey).get();
240
247
  }
248
+ getClass() {
249
+ return this.instance.constructor;
250
+ }
251
+ getHandler() {
252
+ return this.instance[this.propertyKey];
253
+ }
241
254
  addData(key, value) {
242
255
  this.data[key] = value;
243
256
  }
@@ -269,13 +282,13 @@ function manageResponse(data, response) {
269
282
  }
270
283
  function manageError(error, response) {
271
284
  if (response.hasResponded) {
272
- return;
285
+ return response;
273
286
  }
274
287
  if (error instanceof common_1.HttpException) {
275
- response.reject(error.message, error.getStatus());
288
+ return response.reject(error.message, error.getStatus());
276
289
  }
277
290
  if (error instanceof Error) {
278
- response.reject(error.message, 500);
291
+ return response.reject(error.message, 500);
279
292
  }
280
293
  }
281
294
  function manageConnectionHandlers(target) {
@@ -500,8 +513,22 @@ function GetLeaveEvent() {
500
513
  })(null);
501
514
  }
502
515
  exports.GetLeaveEvent = GetLeaveEvent;
503
- function manageAction(req, res, instance, moduleRef, originalMethod, propertyKey, response) {
516
+ function manageAction(instance, moduleRef, originalMethod, propertyKey, request, response) {
504
517
  return __awaiter(this, void 0, void 0, function* () {
518
+ const req = {};
519
+ const res = {};
520
+ if (request instanceof joinRequest_1.JoinRequest && response instanceof joinResponse_1.JoinResponse) {
521
+ req.joinRequest = request;
522
+ res.joinResponse = response;
523
+ }
524
+ else if (request instanceof eventRequest_1.EventRequest && response instanceof eventResponse_1.EventResponse) {
525
+ req.eventRequest = request;
526
+ res.eventResponse = response;
527
+ }
528
+ else if ('headers' in request && response instanceof response_1.ConnectionResponse) {
529
+ req.connection = request;
530
+ res.connection = response;
531
+ }
505
532
  const context = new Context(req, res, instance, propertyKey);
506
533
  const canProceed = yield resolveGuards(moduleRef, context);
507
534
  if (canProceed) {
@@ -519,13 +546,7 @@ function OnConnectionRequest() {
519
546
  const { set } = manageConnectionHandlers(target);
520
547
  set('', (instance, moduleRef, request, response) => __awaiter(this, void 0, void 0, function* () {
521
548
  try {
522
- const req = {
523
- connection: request,
524
- };
525
- const res = {
526
- connection: response,
527
- };
528
- yield manageAction(req, res, instance, moduleRef, originalMethod, propertyKey, response);
549
+ yield manageAction(instance, moduleRef, originalMethod, propertyKey, request, response);
529
550
  }
530
551
  catch (error) {
531
552
  manageError(error, response);
@@ -540,13 +561,7 @@ function OnJoinRequest() {
540
561
  const { set } = manageJoinHandlers(target);
541
562
  set('', (instance, moduleRef, request, response) => __awaiter(this, void 0, void 0, function* () {
542
563
  try {
543
- const req = {
544
- joinRequest: request,
545
- };
546
- const res = {
547
- joinResponse: response,
548
- };
549
- yield manageAction(req, res, instance, moduleRef, originalMethod, propertyKey, response);
564
+ yield manageAction(instance, moduleRef, originalMethod, propertyKey, request, response);
550
565
  }
551
566
  catch (error) {
552
567
  manageError(error, response);
@@ -561,13 +576,7 @@ function OnEvent(event = '*') {
561
576
  const { set } = manageEventHandlers(target);
562
577
  set(event, (instance, moduleRef, request, response) => __awaiter(this, void 0, void 0, function* () {
563
578
  try {
564
- const req = {
565
- eventRequest: request,
566
- };
567
- const res = {
568
- eventResponse: response,
569
- };
570
- yield manageAction(req, res, instance, moduleRef, originalMethod, propertyKey, response);
579
+ yield manageAction(instance, moduleRef, originalMethod, propertyKey, request, response);
571
580
  }
572
581
  catch (error) {
573
582
  manageError(error, response);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eleven-am/pondsocket",
3
- "version": "0.1.110",
3
+ "version": "0.1.112",
4
4
  "description": "PondSocket is a fast simple socket server",
5
5
  "keywords": [
6
6
  "socket",
package/types.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Server as HTTPServer, IncomingHttpHeaders } from 'http';
2
2
 
3
- import type { ModuleMetadata, DynamicModule } from '@nestjs/common';
3
+ import type { ModuleMetadata, DynamicModule, Type } from '@nestjs/common';
4
4
  import type { Express } from 'express';
5
5
  import { WebSocketServer } from 'ws';
6
6
 
@@ -170,16 +170,15 @@ declare class Context<Path extends string = string> {
170
170
  event: PondEvent<Path> | null;
171
171
 
172
172
  /**
173
- * @desc Retrieves metadata associated with the class
174
- * @param key - the key to retrieve
173
+ * @desc Returns the *type* of the controller class which the current handler belongs to.
175
174
  */
176
- public retrieveClassData<A = unknown>(key: symbol): A | null;
175
+ getClass<T = any>(): Type<T>;
177
176
 
178
177
  /**
179
- * @desc Retrieves metadata associated with the method
180
- * @param key - the key to retrieve
178
+ * @desc Returns a reference to the handler (method) that will be invoked next in the
179
+ * request pipeline.
181
180
  */
182
- public retrieveMethodData<A = unknown>(key: symbol): A | null;
181
+ getHandler(): Function;
183
182
 
184
183
  /**
185
184
  * @desc Adds request data to the context