@eleven-am/pondsocket 0.1.108 → 0.1.109

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 +13 -15
  2. package/package.json +1 -1
  3. package/types.d.ts +1 -0
package/nest.js CHANGED
@@ -37,7 +37,6 @@ const endpointClassKey = Symbol('endpoint');
37
37
  const channelsClassKey = Symbol('channels');
38
38
  const parametersKey = Symbol('generalParametersKey');
39
39
  const pondGuardsKey = Symbol('pondGuardsKey');
40
- const endpointGuardsKey = Symbol('endpointGuardsKey');
41
40
  function isNotEmpty(value) {
42
41
  return value !== null &&
43
42
  value !== undefined &&
@@ -612,7 +611,6 @@ exports.EndpointInstance = EndpointInstance;
612
611
  const Channel = (path = '*') => createClassDecorator(channelClassKey, path);
613
612
  exports.Channel = Channel;
614
613
  const setEndpoint = (path = '*') => createClassDecorator(endpointClassKey, path);
615
- const setGuards = (guards) => createClassDecorator(endpointGuardsKey, guards);
616
614
  const setChannels = (channels) => createClassDecorator(channelsClassKey, channels);
617
615
  const getChannels = (target) => {
618
616
  var _a;
@@ -628,15 +626,13 @@ const getGuards = (target) => {
628
626
  });
629
627
  return [...classGuards, ...methodGuards.flat()];
630
628
  };
631
- const Endpoint = (metadata) => {
632
- var _a;
633
- return (0, common_1.applyDecorators)(setChannels(metadata.channels), setEndpoint(metadata.path), setGuards((_a = metadata.guards) !== null && _a !== void 0 ? _a : []));
634
- };
629
+ const Endpoint = (metadata) => (0, common_1.applyDecorators)(setChannels(metadata.channels), setEndpoint(metadata.path));
635
630
  exports.Endpoint = Endpoint;
636
631
  class PondSocketService {
637
- constructor(moduleRef, adapterHost, endpoints) {
632
+ constructor(moduleRef, adapterHost, externalGuards, endpoints) {
638
633
  this.moduleRef = moduleRef;
639
634
  this.adapterHost = adapterHost;
635
+ this.externalGuards = externalGuards;
640
636
  this.endpoints = endpoints;
641
637
  const httpAdapter = this.adapterHost.httpAdapter;
642
638
  httpAdapter.listen = (...args) => {
@@ -653,7 +649,8 @@ class PondSocketService {
653
649
  if (!endpointMetadata) {
654
650
  return;
655
651
  }
656
- const endpointGuards = (_a = manageClassData(endpointGuardsKey, endpoint).get()) !== null && _a !== void 0 ? _a : [];
652
+ const { get, set: setGuards } = manageClassData(pondGuardsKey, endpoint);
653
+ setGuards([...this.externalGuards, ...((_a = get()) !== null && _a !== void 0 ? _a : [])]);
657
654
  const instance = this.moduleRef.get(endpoint, { strict: false });
658
655
  const { set } = manageEndpointInstance(instance);
659
656
  const pondEndpoint = socket.createEndpoint(endpointMetadata, (request, response) => __awaiter(this, void 0, void 0, function* () {
@@ -668,17 +665,17 @@ class PondSocketService {
668
665
  }));
669
666
  set(pondEndpoint);
670
667
  getChannels(endpoint).forEach((channel) => {
671
- this.manageChannel(channel, endpointGuards, pondEndpoint);
668
+ this.manageChannel(channel, pondEndpoint);
672
669
  });
673
670
  }
674
- manageChannel(channel, guards, endpoint) {
671
+ manageChannel(channel, endpoint) {
675
672
  var _a;
676
673
  const channelMetadata = manageClassData(channelClassKey, channel).get();
677
674
  if (!channelMetadata) {
678
675
  return;
679
676
  }
680
677
  const { get, set: setGuards } = manageClassData(pondGuardsKey, channel);
681
- setGuards([...guards, ...((_a = get()) !== null && _a !== void 0 ? _a : [])]);
678
+ setGuards([...this.externalGuards, ...((_a = get()) !== null && _a !== void 0 ? _a : [])]);
682
679
  const instance = this.moduleRef.get(channel, { strict: false });
683
680
  const channelInstance = endpoint.createChannel(channelMetadata, (request, response) => __awaiter(this, void 0, void 0, function* () {
684
681
  const { get } = manageJoinHandlers(instance);
@@ -708,15 +705,16 @@ class PondSocketService {
708
705
  }
709
706
  }
710
707
  class PondSocketModule {
711
- static forRoot({ endpoints, providers = [], imports = [], exports = [], isGlobal = false, }) {
708
+ static forRoot({ endpoints, guards = [], providers = [], imports = [], exports = [], isGlobal = false, }) {
712
709
  const endpointsSet = new Set(endpoints);
713
710
  const channels = Array.from(endpointsSet).flatMap((endpoint) => getChannels(endpoint));
714
711
  const channelsSet = new Set(channels);
715
- const guards = Array.from(new Set([...endpointsSet, ...channelsSet])).flatMap(((target) => getGuards(target)));
716
- const guardsSet = new Set(guards);
712
+ const uniqueGuards = new Set(guards);
713
+ const allGuards = Array.from(new Set([...endpointsSet, ...channelsSet])).flatMap(((target) => getGuards(target)));
714
+ const guardsSet = new Set([...uniqueGuards, ...allGuards]);
717
715
  const pondSocketProvider = {
718
716
  provide: PondSocketService,
719
- useFactory: (moduleRef, adapterHost) => new PondSocketService(moduleRef, adapterHost, endpoints),
717
+ useFactory: (moduleRef, adapterHost) => new PondSocketService(moduleRef, adapterHost, Array.from(uniqueGuards), endpoints),
720
718
  inject: [core_1.ModuleRef, core_1.HttpAdapterHost],
721
719
  };
722
720
  const providersSet = new Set([...providers, ...guardsSet, ...channelsSet, ...endpointsSet, pondSocketProvider]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eleven-am/pondsocket",
3
- "version": "0.1.108",
3
+ "version": "0.1.109",
4
4
  "description": "PondSocket is a fast simple socket server",
5
5
  "keywords": [
6
6
  "socket",
package/types.d.ts CHANGED
@@ -67,6 +67,7 @@ interface UserAssigns {
67
67
 
68
68
  interface Metadata extends Omit<ModuleMetadata, 'controllers'> {
69
69
  endpoints: Constructor<NonNullable<unknown>>[];
70
+ guards?: Constructor<CanActivate>[];
70
71
  isGlobal?: boolean;
71
72
  }
72
73