@nestjs-redis/socket.io-adapter 1.0.0 → 1.1.1-0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nestjs-redis/socket.io-adapter",
3
- "version": "1.0.0",
3
+ "version": "1.1.1-0",
4
4
  "license": "MIT",
5
5
  "author": "Saba Pochkhua <saba.pochkhua@gmail.com> (https://github.com/CSenshi)",
6
6
  "description": "Redis-powered Socket.IO adapter for NestJS enabling scalable WebSocket connections",
@@ -32,7 +32,10 @@
32
32
  "!**/*.tsbuildinfo"
33
33
  ],
34
34
  "nx": {
35
- "name": "socket.io-adapter"
35
+ "name": "socket.io-adapter",
36
+ "tags": [
37
+ "type:lib"
38
+ ]
36
39
  },
37
40
  "dependencies": {
38
41
  "@nestjs/platform-socket.io": "^11.1.6",
package/dist/index.d.ts DELETED
@@ -1,4 +0,0 @@
1
- export * from './lib/exceptions';
2
- export * from './lib/redis-io.adapter';
3
- export * from './lib/setup-redis-adapter';
4
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,wBAAwB,CAAC;AACvC,cAAc,2BAA2B,CAAC"}
package/dist/index.js DELETED
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./lib/exceptions"), exports);
5
- tslib_1.__exportStar(require("./lib/redis-io.adapter"), exports);
6
- tslib_1.__exportStar(require("./lib/setup-redis-adapter"), exports);
@@ -1,7 +0,0 @@
1
- export declare class RedisClientNotFoundException extends Error {
2
- constructor(redisToken?: string);
3
- }
4
- export declare class RedisAdapterAlreadySetUpException extends Error {
5
- constructor();
6
- }
7
- //# sourceMappingURL=exceptions.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"exceptions.d.ts","sourceRoot":"","sources":["../../src/lib/exceptions.ts"],"names":[],"mappings":"AAAA,qBAAa,4BAA6B,SAAQ,KAAK;gBACzC,UAAU,CAAC,EAAE,MAAM;CA6BhC;AAED,qBAAa,iCAAkC,SAAQ,KAAK;;CAK3D"}
@@ -1,37 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RedisAdapterAlreadySetUpException = exports.RedisClientNotFoundException = void 0;
4
- class RedisClientNotFoundException extends Error {
5
- constructor(redisToken) {
6
- const baseMessage = `Redis client not found. Please ensure that the Redis client is properly configured and provided in the application context.
7
-
8
- Most common solution:
9
- Import and configure RedisModule in your app.module.ts:`;
10
- const configExample = redisToken
11
- ? ` RedisModule.forRoot({
12
- connectionName: '${redisToken}', // <-- connection name
13
- options: { url: process.env['REDIS_URL'] },
14
- }),`
15
- : ` RedisModule.forRoot({
16
- options: { url: process.env['REDIS_URL'] },
17
- }),`;
18
- const troubleshooting = `
19
-
20
- Make sure you have:
21
- 1. RedisModule imported in your module`;
22
- super(baseMessage + '\n\n' + configExample + troubleshooting);
23
- this.name = 'RedisClientNotFoundException';
24
- if (redisToken) {
25
- this.message += `\n\nRequired connection name: ${redisToken}`;
26
- }
27
- this.message += `\n`;
28
- }
29
- }
30
- exports.RedisClientNotFoundException = RedisClientNotFoundException;
31
- class RedisAdapterAlreadySetUpException extends Error {
32
- constructor() {
33
- super('Redis adapter is already set up for this application instance.');
34
- this.name = 'RedisAdapterAlreadySetUpException';
35
- }
36
- }
37
- exports.RedisAdapterAlreadySetUpException = RedisAdapterAlreadySetUpException;
@@ -1,9 +0,0 @@
1
- import type { INestApplication, WebSocketAdapter } from '@nestjs/common';
2
- import type { RedisClientType } from 'redis';
3
- export interface RedisIoAdapterInstance extends WebSocketAdapter {
4
- connectToRedis(redisClient: RedisClientType): Promise<void>;
5
- createIOServer(port: number, options?: unknown): unknown;
6
- }
7
- export type RedisIoAdapterConstructor = new (app: INestApplication) => RedisIoAdapterInstance;
8
- export declare function getIoAdapterCls(): Promise<RedisIoAdapterConstructor>;
9
- //# sourceMappingURL=redis-io.adapter.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"redis-io.adapter.d.ts","sourceRoot":"","sources":["../../src/lib/redis-io.adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AACzE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,OAAO,CAAC;AAE7C,MAAM,WAAW,sBAAuB,SAAQ,gBAAgB;IAC9D,cAAc,CAAC,WAAW,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5D,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC;CAC1D;AAED,MAAM,MAAM,yBAAyB,GAAG,KACtC,GAAG,EAAE,gBAAgB,KAClB,sBAAsB,CAAC;AAE5B,wBAAsB,eAAe,IAAI,OAAO,CAAC,yBAAyB,CAAC,CAmC1E"}
@@ -1,27 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getIoAdapterCls = getIoAdapterCls;
4
- async function getIoAdapterCls() {
5
- const { IoAdapter } = await import('@nestjs/platform-socket.io');
6
- const { createAdapter } = await import('@socket.io/redis-adapter');
7
- class RedisIoAdapter extends IoAdapter {
8
- async connectToRedis(redisClient) {
9
- this.pubClient = redisClient;
10
- this.subClient = this.pubClient.duplicate();
11
- await this.subClient.connect();
12
- this.adapterConstructor = createAdapter(this.pubClient, this.subClient);
13
- }
14
- createIOServer(port, options) {
15
- const server = super.createIOServer(port, options);
16
- server.adapter(this.adapterConstructor);
17
- return server;
18
- }
19
- async close(server) {
20
- super.close(server);
21
- if (this.subClient) {
22
- await this.subClient.quit();
23
- }
24
- }
25
- }
26
- return RedisIoAdapter;
27
- }
@@ -1,11 +0,0 @@
1
- import type { INestApplication } from '@nestjs/common';
2
- /**
3
- * Sets up the Redis adapter for a NestJS application.
4
- *
5
- * @param app - The NestJS application instance
6
- * @param redisToken - Optional Redis client token for named connections
7
- * @returns A promise that resolves when the adapter is set up
8
- * @throws RedisClientNotFoundException if the Redis client is not found
9
- */
10
- export declare function setupRedisAdapter(app: INestApplication, redisToken?: string): Promise<void>;
11
- //# sourceMappingURL=setup-redis-adapter.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"setup-redis-adapter.d.ts","sourceRoot":"","sources":["../../src/lib/setup-redis-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAWvD;;;;;;;GAOG;AACH,wBAAsB,iBAAiB,CACrC,GAAG,EAAE,gBAAgB,EACrB,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,IAAI,CAAC,CAuBf"}
@@ -1,51 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.setupRedisAdapter = setupRedisAdapter;
4
- const core_1 = require("@nestjs/core");
5
- const exceptions_1 = require("@nestjs/core/errors/exceptions");
6
- const exceptions_2 = require("./exceptions");
7
- const redis_io_adapter_1 = require("./redis-io.adapter");
8
- const appSet = new Set();
9
- /**
10
- * Sets up the Redis adapter for a NestJS application.
11
- *
12
- * @param app - The NestJS application instance
13
- * @param redisToken - Optional Redis client token for named connections
14
- * @returns A promise that resolves when the adapter is set up
15
- * @throws RedisClientNotFoundException if the Redis client is not found
16
- */
17
- async function setupRedisAdapter(app, redisToken) {
18
- if (appSet.has(app)) {
19
- throw new exceptions_2.RedisAdapterAlreadySetUpException();
20
- }
21
- appSet.add(app);
22
- const cls = await (0, redis_io_adapter_1.getIoAdapterCls)();
23
- const redisIoAdapter = new cls(app);
24
- try {
25
- const moduleRef = app.get(core_1.ModuleRef);
26
- const redisClient = moduleRef.get(RedisToken(redisToken), {
27
- strict: false,
28
- });
29
- await redisIoAdapter.connectToRedis(redisClient);
30
- app.useWebSocketAdapter(redisIoAdapter);
31
- }
32
- catch (error) {
33
- if (error instanceof exceptions_1.UnknownElementException) {
34
- throw new exceptions_2.RedisClientNotFoundException(redisToken);
35
- }
36
- throw error;
37
- }
38
- }
39
- /**
40
- * Creates a Redis client injection token.
41
- *
42
- * @param connectionName - Optional connection name
43
- * @returns Injection token for the Redis client
44
- * @publicApi
45
- */
46
- function RedisToken(connectionName) {
47
- if (connectionName) {
48
- return `REDIS_CLIENT_${connectionName.toUpperCase()}`;
49
- }
50
- return 'REDIS_CLIENT';
51
- }