@eleven-am/pondsocket 0.1.73 → 0.1.75

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/lobby/lobby.js CHANGED
@@ -64,7 +64,10 @@ class LobbyEngine {
64
64
  */
65
65
  broadcast(event, payload, channelName) {
66
66
  if (channelName) {
67
- const channel = this.getChannel(channelName) || this.createChannel(channelName);
67
+ const channel = this.getChannel(channelName);
68
+ if (!channel) {
69
+ throw new Error(`GatewayEngine: Channel ${channelName} does not exist`);
70
+ }
68
71
  channel.sendMessage(enums_1.SystemSender.CHANNEL, enums_1.ChannelReceiver.ALL_USERS, enums_1.ServerActions.SYSTEM, event, payload);
69
72
  }
70
73
  else {
package/nest.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import {
2
2
  OnJoinRequest,
3
+ ChannelInstance,
3
4
  DChannel as Channel,
4
5
  Channels, Endpoints,
5
6
  OnConnectionRequest,
@@ -17,6 +18,7 @@ import {
17
18
 
18
19
  export {
19
20
  OnJoinRequest,
21
+ ChannelInstance,
20
22
  Endpoint, PondSocketModule,
21
23
  OnConnectionRequest, OnEvent,
22
24
  Channel, Channels, Endpoints,
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.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.GetUserPresence = exports.GetInternalChannel = exports.GetUserData = exports.GetJoinParams = exports.GetJoinResponse = exports.GetJoinRequest = void 0;
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.GetUserPresence = exports.GetInternalChannel = exports.GetUserData = exports.GetJoinParams = exports.GetJoinResponse = exports.GetJoinRequest = void 0;
24
24
  require("reflect-metadata");
25
25
  const common_1 = require("@nestjs/common");
26
26
  const pondSocket_1 = require("./server/pondSocket");
@@ -409,6 +409,10 @@ function OnConnectionRequest() {
409
409
  exports.OnConnectionRequest = OnConnectionRequest;
410
410
  function Channel(path = '*') {
411
411
  return (constructor) => class extends constructor {
412
+ constructor() {
413
+ super(...arguments);
414
+ this._channel = null;
415
+ }
412
416
  _setEndpoint(endpoint) {
413
417
  const channel = endpoint.createChannel(path, (request, response) => __awaiter(this, void 0, void 0, function* () {
414
418
  const { get } = manageJoinHandlers(this);
@@ -427,28 +431,40 @@ function Channel(path = '*') {
427
431
  yield handler.value(request, response);
428
432
  }));
429
433
  });
434
+ this._channel = channel;
430
435
  }
431
436
  };
432
437
  }
433
438
  exports.Channel = Channel;
439
+ function ChannelInstance() {
440
+ return (target, propertyKey) => {
441
+ Object.defineProperty(target, propertyKey, {
442
+ get() {
443
+ if (!target._channel) {
444
+ throw new Error('Channel not initialized');
445
+ }
446
+ return target._channel;
447
+ },
448
+ set() {
449
+ throw new Error('Channel is read-only');
450
+ },
451
+ });
452
+ };
453
+ }
454
+ exports.ChannelInstance = ChannelInstance;
434
455
  function Channels(channels) {
435
456
  return (constructor) => {
436
457
  const { set } = manageChannels(constructor.prototype);
437
458
  set(channels);
438
- return class extends constructor {
439
- constructor() {
440
- super(...arguments);
441
- this._channels = channels;
442
- }
443
- };
459
+ return constructor;
444
460
  };
445
461
  }
446
462
  exports.Channels = Channels;
447
463
  function Endpoint(path = '*') {
448
464
  return (constructor) => class extends constructor {
449
465
  _setSocket(moduleRef, socket) {
450
- var _a;
451
466
  const { get } = manageConnectionHandlers(this);
467
+ const { get: getChannels } = manageChannels(this);
452
468
  const [handler] = get();
453
469
  const endpoint = socket.createEndpoint(path, (request, response) => __awaiter(this, void 0, void 0, function* () {
454
470
  if (handler) {
@@ -458,8 +474,7 @@ function Endpoint(path = '*') {
458
474
  response.accept();
459
475
  }
460
476
  }));
461
- const channels = (_a = this._channels) !== null && _a !== void 0 ? _a : [];
462
- channels.forEach((channel) => {
477
+ getChannels().forEach((channel) => {
463
478
  const chan = moduleRef.get(channel, {
464
479
  strict: false,
465
480
  });
@@ -496,9 +511,10 @@ class PondSocketModule {
496
511
  this.socket = new pondSocket_1.PondSocket(server);
497
512
  expressInstance.listen = (...args) => {
498
513
  const { get } = manageEndpoints(this);
499
- get().forEach((endpoint) => {
514
+ get().map((endpoint) => {
500
515
  const instance = this.moduleRef.get(endpoint, { strict: false });
501
516
  instance._setSocket(this.moduleRef, this.socket);
517
+ return instance;
502
518
  });
503
519
  this.socket.listen(...args);
504
520
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eleven-am/pondsocket",
3
- "version": "0.1.73",
3
+ "version": "0.1.75",
4
4
  "description": "PondSocket is a fast simple socket server",
5
5
  "keywords": [
6
6
  "socket",
package/types.d.ts CHANGED
@@ -7,7 +7,10 @@ import { WebSocketServer } from 'ws';
7
7
  type Unsubscribe = () => void;
8
8
 
9
9
  type Constructor<T> = new (...args: any[]) => T;
10
- type MethodDecorator = (target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<unknown>) => TypedPropertyDescriptor<unknown> | void;
10
+ declare type ClassDecorator = <TFunction extends Function>(target: TFunction) => TFunction | void;
11
+ declare type MethodDecorator = <T>(target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T> | void;
12
+ declare type ParameterDecorator = (target: Object, propertyKey: string | symbol | undefined, parameterIndex: number) => void;
13
+
11
14
  export type default_t<T = any> = Record<string, T>;
12
15
  type IsParam<Path> = Path extends `:${infer Param}` ? Param : never;
13
16
 
@@ -622,106 +625,107 @@ declare const pondSocket: (app: Express) => PondSocketExpressApp;
622
625
  * @desc The Decorator for retrieving the JoinRequest object from the request in a handler
623
626
  * @returns {JoinRequest}
624
627
  */
625
- declare function GetJoinRequest(): MethodDecorator;
628
+ declare function GetJoinRequest(): ParameterDecorator;
626
629
 
627
630
  /**
628
631
  * @desc The Decorator for retrieving the JoinResponse object from the response in a handler
629
632
  * @returns {JoinResponse}
630
633
  */
631
- declare function GetJoinResponse(): MethodDecorator;
634
+ declare function GetJoinResponse(): ParameterDecorator;
632
635
 
633
636
  /**
634
637
  * @desc The Decorator for retrieving the JoinParams object from the request in a handler
635
638
  * @returns {JoinParams}
636
639
  */
637
- declare function GetJoinParams(): MethodDecorator;
640
+ declare function GetJoinParams(): ParameterDecorator;
638
641
 
639
642
  /**
640
643
  * @desc The Decorator for retrieving the UserData object from the request in a handler
641
644
  * @returns {UserData}
642
645
  */
643
- declare function GetUserData(): MethodDecorator;
646
+ declare function GetUserData(): ParameterDecorator;
644
647
 
645
648
  /**
646
649
  * @desc The Decorator for retrieving the Channel object from the request in a handler
647
650
  * @returns {Channel}
648
651
  */
649
- declare function GetInternalChannel(): MethodDecorator;
652
+ declare function GetInternalChannel(): ParameterDecorator;
650
653
 
651
654
  /**
652
655
  * @desc The Decorator for retrieving the UserPresence object from the request in a handler
653
656
  * @returns {PondPresence}
654
657
  */
655
- declare function GetUserPresence(): MethodDecorator;
658
+ declare function GetUserPresence(): ParameterDecorator;
656
659
 
657
660
  /**
658
661
  * @desc The Decorator for retrieving the event payload from the request in a handler
659
662
  * @returns {PondMessage}
660
663
  */
661
- declare function GetEventPayload(): MethodDecorator;
664
+ declare function GetEventPayload(): ParameterDecorator;
662
665
 
663
666
  /**
664
667
  * @desc The Decorator for retrieving the EventRequest Params object from the request in a handler
665
668
  * @returns {EventParams}
666
669
  */
667
- declare function GetEventParams(): MethodDecorator;
670
+ declare function GetEventParams(): ParameterDecorator;
668
671
 
669
672
  /**
670
673
  * @desc The Decorator for retrieving the EventRequest Query object from the request in a handler
671
674
  * @returns {EventParams}
672
675
  */
673
- declare function GetEventQuery(): MethodDecorator;
676
+ declare function GetEventQuery(): ParameterDecorator;
674
677
 
675
678
  /**
676
679
  * @desc The Decorator for retrieving the EventResponse in a handler
677
680
  * @returns {EventResponse}
678
681
  */
679
- declare function GetEventResponse(): MethodDecorator;
682
+ declare function GetEventResponse(): ParameterDecorator;
680
683
 
681
684
  /**
682
685
  * @desc The Decorator for retrieving the EventRequest in a handler
683
686
  * @returns {EventRequest}
684
687
  */
685
- declare function GetEventRequest(): MethodDecorator;
688
+ declare function GetEventRequest(): ParameterDecorator;
686
689
 
687
690
  /**
688
691
  * @desc The Decorator for retrieving the ConnectionReQuest in a handler
689
692
  * @returns {IncomingConnection}
690
693
  */
691
- declare function GetConnectionRequest(): MethodDecorator;
694
+ declare function GetConnectionRequest(): ParameterDecorator;
692
695
 
693
696
  /**
694
697
  * @desc The Decorator for retrieving the ConnectionResponse in a handler
695
698
  * @returns {ConnectionResponse}
696
699
  */
697
- declare function GetConnectionResponse(): MethodDecorator;
700
+ declare function GetConnectionResponse(): ParameterDecorator;
698
701
 
699
702
  /**
700
703
  * @desc The Decorator for retrieving the ConnectionRequestId in a handler
701
704
  * @returns {string}
702
705
  */
703
- declare function GetConnectionRequestId(): MethodDecorator;
706
+ declare function GetConnectionRequestId(): ParameterDecorator;
704
707
 
705
708
  /**
706
709
  * @desc The Decorator for retrieving the ConnectionParams in a handler
707
710
  * @returns {EventParams}
708
711
  */
709
- declare function GetConnectionParams(): MethodDecorator;
712
+ declare function GetConnectionParams(): ParameterDecorator;
710
713
 
711
714
  /**
712
715
  * @desc The Decorator for retrieving the ConnectionHeaders from the request in a handler
713
716
  * @returns {EventParams}
714
717
  */
715
- declare function GetConnectionHeaders(): MethodDecorator;
718
+ declare function GetConnectionHeaders(): ParameterDecorator;
716
719
 
717
720
  /**
718
721
  * @desc The Decorator for retrieving the ConnectionQuery in a handler
719
722
  * @returns {EventParams}
720
723
  */
721
- declare function GetConnectionQuery(): MethodDecorator;
724
+ declare function GetConnectionQuery(): ParameterDecorator;
722
725
 
723
726
  /**
724
727
  * @desc Marks a method as a handler for JoinRequest events.
728
+ * @param - The path for the JoinRequest event.
725
729
  */
726
730
  declare function OnJoinRequest(): MethodDecorator;
727
731
 
@@ -740,33 +744,30 @@ declare function OnConnectionRequest(): MethodDecorator;
740
744
  * Decorator to mark a class as a channel.
741
745
  * @param path - The path for the channel (default is '*').
742
746
  */
743
- declare function DChannel<T extends Constructor<NonNullable<unknown>>>(
744
- path?: string
745
- ): (constructor: T) => void;
747
+ declare function DChannel(path?: string): ClassDecorator;
748
+
749
+ /**
750
+ * Decorator to retrieve the channel instance as a read-only property in a class.
751
+ */
752
+ declare function ChannelInstance(): PropertyDecorator;
746
753
 
747
754
  /**
748
755
  * Decorator to mark a class as having multiple channels.
749
756
  * @param channels - The array of channels.
750
757
  */
751
- declare function Channels<T extends Constructor<NonNullable<unknown>>>(
752
- channels: Constructor<NonNullable<unknown>>[]
753
- ): (constructor: T) => void;
758
+ declare function Channels(channels: Constructor<NonNullable<unknown>>[]): ClassDecorator;
754
759
 
755
760
  /**
756
761
  * Decorator to mark a class as an endpoint.
757
762
  * @param path - The path for the endpoint (default is '*').
758
763
  */
759
- declare function DEndpoint<T extends Constructor<NonNullable<unknown>>>(
760
- path?: string
761
- ): (constructor: T) => void;
764
+ declare function DEndpoint(path?: string): ClassDecorator;
762
765
 
763
766
  /**
764
767
  * Decorator to mark a class as having multiple endpoints.
765
768
  * @param endpoints - The array of endpoints.
766
769
  */
767
- declare function Endpoints<T extends Constructor<NonNullable<unknown>>>(
768
- endpoints: Constructor<NonNullable<unknown>>[]
769
- ): (constructor: T) => void;
770
+ declare function Endpoints(endpoints: Constructor<NonNullable<unknown>>[]): ClassDecorator;
770
771
 
771
772
  declare class PondSocketModule {
772
773
  /**