@eleven-am/pondsocket-nest 0.0.72 → 0.0.74

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/index.d.ts CHANGED
@@ -29,21 +29,10 @@ interface CanActivate {
29
29
  canActivate(context: Context): boolean | Promise<boolean>;
30
30
  }
31
31
 
32
- interface PubSubOptions {
33
- redisUrl: string;
34
- db: number;
35
- }
36
-
37
32
  interface Metadata extends Omit<ModuleMetadata, 'controllers'> {
38
33
  guards?: Constructor<CanActivate>[];
39
34
  appModuleName?: string;
40
35
  isGlobal?: boolean;
41
- options?: PubSubOptions;
42
- }
43
-
44
- interface AsyncMetadata extends Metadata {
45
- useFactory: (...args: unknown[]) => Promise<PubSubOptions> | PubSubOptions;
46
- inject: any[];
47
36
  }
48
37
 
49
38
  type NestFuncType<Event extends string, Payload extends PondMessage, Presence extends PondPresence, Assigns extends PondAssigns = PondAssigns> = {
@@ -313,7 +302,5 @@ declare function createParamDecorator<Input, ParamType> (callback: ParamDecorato
313
302
 
314
303
  declare class PondSocketModule {
315
304
  static forRoot({ guards, providers, imports, exports, isGlobal, appModuleName }: Metadata): DynamicModule;
316
-
317
- static forRootAsync({ guards, providers, imports, exports, isGlobal, useFactory, inject }: AsyncMetadata): DynamicModule;
318
305
  }
319
306
 
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.PondSocketModule = void 0;
13
4
  const nestjs_discovery_1 = require("@golevelup/nestjs-discovery");
@@ -16,11 +7,11 @@ const core_1 = require("@nestjs/core");
16
7
  const guards_1 = require("../managers/guards");
17
8
  const pondSocket_1 = require("../services/pondSocket");
18
9
  class PondSocketModule {
19
- static forRoot({ guards = [], providers = [], imports = [], exports = [], isGlobal = false, options, }) {
10
+ static forRoot({ guards = [], providers = [], imports = [], exports = [], isGlobal = false, }) {
20
11
  const localGuards = (0, guards_1.getLocalGuards)();
21
12
  const pondSocketProvider = {
22
13
  provide: pondSocket_1.PondSocketService,
23
- useFactory: (moduleRef, adapterHost, discovery) => new pondSocket_1.PondSocketService(moduleRef, discovery, adapterHost, guards, options !== null && options !== void 0 ? options : {}),
14
+ useFactory: (moduleRef, adapterHost, discovery) => new pondSocket_1.PondSocketService(moduleRef, discovery, adapterHost, guards),
24
15
  inject: [core_1.ModuleRef, core_1.HttpAdapterHost, nestjs_discovery_1.DiscoveryService],
25
16
  };
26
17
  guards = [...new Set([...localGuards, ...guards])];
@@ -36,28 +27,5 @@ class PondSocketModule {
36
27
  ],
37
28
  };
38
29
  }
39
- static forRootAsync({ guards = [], providers = [], imports = [], exports = [], isGlobal = false, useFactory, inject, }) {
40
- const provider = {
41
- provide: pondSocket_1.PondSocketService,
42
- useFactory: (moduleRef, adapterHost, discovery, ...args) => __awaiter(this, void 0, void 0, function* () {
43
- const options = yield useFactory(...args);
44
- const localGuards = (0, guards_1.getLocalGuards)();
45
- guards = [...new Set([...localGuards, ...guards])];
46
- return new pondSocket_1.PondSocketService(moduleRef, discovery, adapterHost, guards, options);
47
- }),
48
- inject: [core_1.ModuleRef, core_1.HttpAdapterHost, nestjs_discovery_1.DiscoveryService, ...(inject || [])],
49
- };
50
- return {
51
- exports,
52
- global: isGlobal,
53
- imports: [...imports, nestjs_discovery_1.DiscoveryModule],
54
- module: PondSocketModule,
55
- providers: [
56
- provider,
57
- ...providers,
58
- ...guards,
59
- ],
60
- };
61
- }
62
30
  }
63
31
  exports.PondSocketModule = PondSocketModule;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eleven-am/pondsocket-nest",
3
- "version": "0.0.72",
3
+ "version": "0.0.74",
4
4
  "description": "PondSocket is a fast simple socket server",
5
5
  "keywords": [
6
6
  "socket",
@@ -28,22 +28,22 @@
28
28
  "pipeline": "npm run lint && npm run build && npm run push"
29
29
  },
30
30
  "dependencies": {
31
- "@eleven-am/pondsocket": "^0.1.167",
31
+ "@eleven-am/pondsocket": "^0.1.169",
32
32
  "@golevelup/nestjs-discovery": "^4.0.1"
33
33
  },
34
34
  "devDependencies": {
35
- "@nestjs/common": "^10.3.10",
36
- "@nestjs/core": "^10.3.10",
37
- "@types/jest": "^29.5.12",
38
- "@typescript-eslint/eslint-plugin": "^7.16.1",
39
- "eslint-plugin-file-progress": "^1.4.0",
40
- "eslint-plugin-import": "^2.29.1",
35
+ "@nestjs/common": "^10.4.4",
36
+ "@nestjs/core": "^10.4.4",
37
+ "@types/jest": "^29.5.13",
38
+ "@typescript-eslint/eslint-plugin": "^7.18.0",
39
+ "eslint-plugin-file-progress": "^1.5.0",
40
+ "eslint-plugin-import": "^2.30.0",
41
41
  "jest": "^29.7.0",
42
42
  "prettier": "^3.3.3",
43
- "ts-jest": "^29.2.3",
43
+ "ts-jest": "^29.2.5",
44
44
  "ts-loader": "^9.5.1",
45
45
  "ts-node": "^10.9.2",
46
- "typescript": "^5.5.3"
46
+ "typescript": "^5.6.2"
47
47
  },
48
48
  "jest": {
49
49
  "moduleFileExtensions": [
@@ -39,9 +39,11 @@ function performResponse(socketId, channel, data, response) {
39
39
  response.reply(event, rest);
40
40
  }
41
41
  if ((0, narrow_1.isJoinResponse)(response) || (0, narrow_1.isEventResponse)(response)) {
42
- if (broadcast || broadcastFrom) {
43
- const event = broadcastFrom || broadcast || '';
44
- response.broadcast(event, rest);
42
+ if (broadcast) {
43
+ response.broadcast(broadcast, rest);
44
+ }
45
+ if (broadcastFrom) {
46
+ response.broadcastFrom(broadcastFrom, rest);
45
47
  }
46
48
  if (broadcastTo) {
47
49
  response.broadcastTo(broadcastTo.event, rest, broadcastTo.users);
@@ -60,8 +62,14 @@ function performResponse(socketId, channel, data, response) {
60
62
  }
61
63
  }
62
64
  if (channel) {
63
- if (isNotEmpty(rest) && broadcast && !response) {
64
- channel.broadcast(broadcast, rest);
65
+ if (isNotEmpty(rest) && !response) {
66
+ if (broadcast || event) {
67
+ const newEvent = (broadcast || event);
68
+ channel.broadcast(newEvent, rest);
69
+ }
70
+ if (broadcastTo) {
71
+ channel.broadcastTo(broadcastTo.users, broadcastTo.event, rest);
72
+ }
65
73
  }
66
74
  if (isNotEmpty(presence)) {
67
75
  channel.upsertPresence(socketId, presence);
@@ -28,21 +28,23 @@ const guards_1 = require("../managers/guards");
28
28
  const join_1 = require("../managers/join");
29
29
  const leave_1 = require("../managers/leave");
30
30
  class PondSocketService {
31
- constructor(moduleRef, discovery, adapterHost, externalGuards, pubSubOptions) {
31
+ constructor(moduleRef, discovery, adapterHost, externalGuards) {
32
32
  this.moduleRef = moduleRef;
33
33
  this.discovery = discovery;
34
34
  this.adapterHost = adapterHost;
35
35
  this.externalGuards = externalGuards;
36
36
  this.logger = new common_1.Logger(PondSocketService.name);
37
37
  const httpAdapter = this.adapterHost.httpAdapter;
38
- void this.init(httpAdapter, pubSubOptions);
38
+ void this.init(httpAdapter);
39
39
  }
40
- init(httpAdapter, options) {
40
+ init(httpAdapter) {
41
41
  return __awaiter(this, void 0, void 0, function* () {
42
42
  const groupedInstances = yield this.getGroupedInstances();
43
43
  const app = httpAdapter.getInstance();
44
44
  const server = (0, http_1.createServer)(app);
45
- const socket = new pondsocket_1.default(Object.assign(Object.assign({}, options), { server }));
45
+ const socket = new pondsocket_1.default({
46
+ server,
47
+ });
46
48
  groupedInstances.forEach((groupedInstance) => {
47
49
  this.manageEndpoint(socket, groupedInstance);
48
50
  });