@eleven-am/pondsocket 0.1.90 → 0.1.92

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 (2) hide show
  1. package/nest.js +63 -32
  2. package/package.json +1 -1
package/nest.js CHANGED
@@ -23,6 +23,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
23
23
  exports.PondSocketModule = exports.Endpoint = exports.Channel = exports.EndpointInstance = exports.ChannelInstance = exports.OnConnectionRequest = exports.OnEvent = exports.OnLeaveEvent = 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 http_1 = require("http");
25
25
  const common_1 = require("@nestjs/common");
26
+ // eslint-disable-next-line import/no-unresolved
26
27
  const core_1 = require("@nestjs/core");
27
28
  require("reflect-metadata");
28
29
  const pondSocket_1 = require("./server/pondSocket");
@@ -220,6 +221,57 @@ function GetConnectionQuery() {
220
221
  return createParamDecorator(connectionQueryKey, 'ConnectionQuery decorator already applied');
221
222
  }
222
223
  exports.GetConnectionQuery = GetConnectionQuery;
224
+ function manageRejectedKeys(rejectedKeys, target, propertyKey) {
225
+ function symbolToString(symbol) {
226
+ switch (symbol) {
227
+ case joinRequestKey:
228
+ return 'GetJoinRequest';
229
+ case joinResponseKey:
230
+ return 'GetJoinResponse';
231
+ case joinParamsKey:
232
+ return 'GetJoinParams';
233
+ case userDataKey:
234
+ return 'GetUserData';
235
+ case internalChannelKey:
236
+ return 'GetInternalChannel';
237
+ case userPresenceKey:
238
+ return 'GetUserPresences';
239
+ case eventPayloadKey:
240
+ return 'GetEventPayload';
241
+ case eventParamsKey:
242
+ return 'GetEventParams';
243
+ case eventQueryKey:
244
+ return 'GetEventQuery';
245
+ case eventResponseKey:
246
+ return 'GetEventResponse';
247
+ case eventRequestKey:
248
+ return 'GetEventRequest';
249
+ case connectionRequestKey:
250
+ return 'GetConnectionRequest';
251
+ case connectionResponseKey:
252
+ return 'GetConnectionResponse';
253
+ case connectionRequestIdKey:
254
+ return 'GetConnectionRequestId';
255
+ case connectionParamsKey:
256
+ return 'GetConnectionParams';
257
+ case connectionQueryKey:
258
+ return 'GetConnectionQuery';
259
+ case connectionHeadersKey:
260
+ return 'GetConnectionHeaders';
261
+ default:
262
+ throw new Error('Invalid parameter decorator');
263
+ }
264
+ }
265
+ const rejected = rejectedKeys
266
+ .map((key) => ({
267
+ key,
268
+ name: symbolToString(key),
269
+ }))
270
+ .filter(({ key }) => resolveParamDecorator(key, target, propertyKey) !== null);
271
+ if (rejected.length) {
272
+ throw new Error(`Invalid parameter decorators: ${rejected.map(({ name }) => name).join(', ')}`);
273
+ }
274
+ }
223
275
  function resolveJoinParameters(request, response, target, propertyKey) {
224
276
  const joinRequestIndex = resolveParamDecorator(joinRequestKey, target, propertyKey);
225
277
  const joinParamsIndex = resolveParamDecorator(joinParamsKey, target, propertyKey);
@@ -237,7 +289,7 @@ function resolveJoinParameters(request, response, target, propertyKey) {
237
289
  eventQueryIndex,
238
290
  JoinResponseIndex,
239
291
  ].filter((index) => typeof index === 'number');
240
- const rejectedKeys = [
292
+ manageRejectedKeys([
241
293
  eventPayloadKey,
242
294
  eventRequestKey,
243
295
  eventResponseKey,
@@ -247,12 +299,7 @@ function resolveJoinParameters(request, response, target, propertyKey) {
247
299
  connectionRequestIdKey,
248
300
  connectionParamsKey,
249
301
  connectionQueryKey,
250
- ]
251
- .map((key) => resolveParamDecorator(key, target, propertyKey))
252
- .filter((index) => typeof index === 'number');
253
- if (rejectedKeys.length) {
254
- throw new Error(`Invalid parameter decorators: ${rejectedKeys.join(', ')}`);
255
- }
302
+ ], target, propertyKey);
256
303
  return array
257
304
  .sort((a, b) => a - b)
258
305
  .map((index) => {
@@ -295,7 +342,7 @@ function resolveEventParameters(request, response, target, propertyKey) {
295
342
  eventRequestIndex,
296
343
  userPresenceIndex,
297
344
  ].filter((index) => typeof index === 'number');
298
- const rejectedKeys = [
345
+ manageRejectedKeys([
299
346
  joinRequestKey,
300
347
  joinResponseKey,
301
348
  joinParamsKey,
@@ -304,12 +351,7 @@ function resolveEventParameters(request, response, target, propertyKey) {
304
351
  connectionRequestIdKey,
305
352
  connectionParamsKey,
306
353
  connectionQueryKey,
307
- ]
308
- .map((key) => resolveParamDecorator(key, target, propertyKey))
309
- .filter((index) => typeof index === 'number');
310
- if (rejectedKeys.length) {
311
- throw new Error(`Invalid parameter decorators: ${rejectedKeys.join(', ')}`);
312
- }
354
+ ], target, propertyKey);
313
355
  return array
314
356
  .sort((a, b) => a - b)
315
357
  .map((index) => {
@@ -337,7 +379,7 @@ function resolveEventParameters(request, response, target, propertyKey) {
337
379
  }
338
380
  function resolveLeaveParameters(event, target, propertyKey) {
339
381
  const userDataIndex = resolveParamDecorator(userDataKey, target, propertyKey);
340
- const rejectedKeys = [
382
+ manageRejectedKeys([
341
383
  joinRequestKey,
342
384
  joinResponseKey,
343
385
  joinParamsKey,
@@ -353,12 +395,7 @@ function resolveLeaveParameters(event, target, propertyKey) {
353
395
  eventRequestKey,
354
396
  userPresenceKey,
355
397
  internalChannelKey,
356
- ]
357
- .map((key) => resolveParamDecorator(key, target, propertyKey))
358
- .filter((index) => typeof index === 'number');
359
- if (rejectedKeys.length) {
360
- throw new Error(`Invalid parameter decorators: ${rejectedKeys.join(', ')}`);
361
- }
398
+ ], target, propertyKey);
362
399
  if (userDataIndex === null) {
363
400
  return [];
364
401
  }
@@ -379,7 +416,7 @@ function resolveConnectionParameters(request, response, target, propertyKey) {
379
416
  connectionQueryIndex,
380
417
  connectionHeadersIndex,
381
418
  ].filter((index) => typeof index === 'number');
382
- const rejectedKeys = [
419
+ manageRejectedKeys([
383
420
  joinRequestKey,
384
421
  joinResponseKey,
385
422
  joinParamsKey,
@@ -391,12 +428,7 @@ function resolveConnectionParameters(request, response, target, propertyKey) {
391
428
  eventResponseKey,
392
429
  userPresenceKey,
393
430
  eventRequestKey,
394
- ]
395
- .map((key) => resolveParamDecorator(key, target, propertyKey))
396
- .filter((index) => typeof index === 'number');
397
- if (rejectedKeys.length) {
398
- throw new Error(`Invalid parameter decorators: ${rejectedKeys.join(', ')}`);
399
- }
431
+ ], target, propertyKey);
400
432
  return array
401
433
  .sort((a, b) => a - b)
402
434
  .map((index) => {
@@ -558,14 +590,13 @@ function EndpointInstance() {
558
590
  exports.EndpointInstance = EndpointInstance;
559
591
  const Channel = (path = '*') => createClassDecorator(channelClassKey, path);
560
592
  exports.Channel = Channel;
561
- const SetEndpoint = (path = '*') => createClassDecorator(endpointClassKey, path);
562
- const SetChannels = (channels) => createClassDecorator(channelsClassKey, channels);
593
+ const setEndpoint = (path = '*') => createClassDecorator(endpointClassKey, path);
594
+ const setChannels = (channels) => createClassDecorator(channelsClassKey, channels);
563
595
  const getChannels = (target) => {
564
596
  var _a;
565
597
  return (_a = getClassMetadata(channelsClassKey, target)) !== null && _a !== void 0 ? _a : [];
566
598
  };
567
- // eslint-disable-next-line new-cap
568
- const Endpoint = (metadata) => (0, common_1.applyDecorators)(SetChannels(metadata.channels), SetEndpoint(metadata.path));
599
+ const Endpoint = (metadata) => (0, common_1.applyDecorators)(setChannels(metadata.channels), setEndpoint(metadata.path));
569
600
  exports.Endpoint = Endpoint;
570
601
  class PondSocketService {
571
602
  constructor(moduleRef, adapterHost, endpoints) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eleven-am/pondsocket",
3
- "version": "0.1.90",
3
+ "version": "0.1.92",
4
4
  "description": "PondSocket is a fast simple socket server",
5
5
  "keywords": [
6
6
  "socket",