@nest-boot/redis 7.0.1 → 7.0.3

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/dist/index.d.ts CHANGED
@@ -1,4 +1,2 @@
1
- import { type RedisOptions } from "ioredis";
2
- import { Redis } from "./redis";
3
1
  export * from "./redis.module";
4
- export { Redis, type RedisOptions };
2
+ export * from "./utils/load-config-from-env.util";
package/dist/index.js CHANGED
@@ -14,8 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.Redis = void 0;
18
- const redis_1 = require("./redis");
19
- Object.defineProperty(exports, "Redis", { enumerable: true, get: function () { return redis_1.Redis; } });
20
17
  __exportStar(require("./redis.module"), exports);
18
+ __exportStar(require("./utils/load-config-from-env.util"), exports);
21
19
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAEA,mCAAgC;AAIvB,sFAJA,aAAK,OAIA;AAFd,iDAA+B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iDAA+B;AAC/B,oEAAkD"}
@@ -1,7 +1,5 @@
1
1
  import { type RedisOptions } from "ioredis";
2
- export declare const ConfigurableModuleClass: import("@nestjs/common").ConfigurableModuleCls<RedisOptions, "register", "create", {
3
- isGlobal: boolean;
4
- }>, MODULE_OPTIONS_TOKEN: string | symbol, OPTIONS_TYPE: import("ioredis").CommonRedisOptions & import("ioredis").SentinelConnectionOptions & Partial<{
2
+ export declare const ConfigurableModuleClass: import("@nestjs/common").ConfigurableModuleCls<RedisOptions, "register", "create", {}>, MODULE_OPTIONS_TOKEN: string | symbol, OPTIONS_TYPE: import("ioredis").CommonRedisOptions & import("ioredis").SentinelConnectionOptions & Partial<{
5
3
  port: number;
6
4
  host?: string | undefined | undefined;
7
5
  family?: number | undefined | undefined;
@@ -10,8 +8,4 @@ export declare const ConfigurableModuleClass: import("@nestjs/common").Configura
10
8
  }> & {
11
9
  disconnectTimeout?: number;
12
10
  tls?: import("tls").ConnectionOptions;
13
- } & Partial<{
14
- isGlobal: boolean;
15
- }>, ASYNC_OPTIONS_TYPE: import("@nestjs/common").ConfigurableModuleAsyncOptions<RedisOptions, "create"> & Partial<{
16
- isGlobal: boolean;
17
- }>;
11
+ } & Partial<{}>, ASYNC_OPTIONS_TYPE: import("@nestjs/common").ConfigurableModuleAsyncOptions<RedisOptions, "create"> & Partial<{}>;
@@ -3,12 +3,5 @@ var _a;
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.ASYNC_OPTIONS_TYPE = exports.OPTIONS_TYPE = exports.MODULE_OPTIONS_TOKEN = exports.ConfigurableModuleClass = void 0;
5
5
  const common_1 = require("@nestjs/common");
6
- _a = new common_1.ConfigurableModuleBuilder()
7
- .setExtras({
8
- isGlobal: false,
9
- }, (definition, extras) => ({
10
- ...definition,
11
- global: extras.isGlobal,
12
- }))
13
- .build(), exports.ConfigurableModuleClass = _a.ConfigurableModuleClass, exports.MODULE_OPTIONS_TOKEN = _a.MODULE_OPTIONS_TOKEN, exports.OPTIONS_TYPE = _a.OPTIONS_TYPE, exports.ASYNC_OPTIONS_TYPE = _a.ASYNC_OPTIONS_TYPE;
6
+ _a = new common_1.ConfigurableModuleBuilder().build(), exports.ConfigurableModuleClass = _a.ConfigurableModuleClass, exports.MODULE_OPTIONS_TOKEN = _a.MODULE_OPTIONS_TOKEN, exports.OPTIONS_TYPE = _a.OPTIONS_TYPE, exports.ASYNC_OPTIONS_TYPE = _a.ASYNC_OPTIONS_TYPE;
14
7
  //# sourceMappingURL=redis.module-definition.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"redis.module-definition.js","sourceRoot":"","sources":["../src/redis.module-definition.ts"],"names":[],"mappings":";;;;AAAA,2CAA2D;AAG9C,KAKT,IAAI,kCAAyB,EAAgB;KAC9C,SAAS,CACR;IACE,QAAQ,EAAE,KAAK;CAChB,EACD,CAAC,UAAU,EAAE,MAAM,EAAE,EAAE,CAAC,CAAC;IACvB,GAAG,UAAU;IACb,MAAM,EAAE,MAAM,CAAC,QAAQ;CACxB,CAAC,CACH;KACA,KAAK,EAAE,EAdR,+BAAuB,+BACvB,4BAAoB,4BACpB,oBAAY,oBACZ,0BAAkB,yBAWT"}
1
+ {"version":3,"file":"redis.module-definition.js","sourceRoot":"","sources":["../src/redis.module-definition.ts"],"names":[],"mappings":";;;;AAAA,2CAA2D;AAG9C,KAKT,IAAI,kCAAyB,EAAgB,CAAC,KAAK,EAAE,EAJvD,+BAAuB,+BACvB,4BAAoB,4BACpB,oBAAY,oBACZ,0BAAkB,yBACsC"}
@@ -1,8 +1,69 @@
1
- import { type OnApplicationShutdown } from "@nestjs/common";
2
- import { Redis } from "./redis";
3
- import { ConfigurableModuleClass } from "./redis.module-definition";
1
+ import { type DynamicModule, type OnApplicationShutdown } from "@nestjs/common";
2
+ import Redis from "ioredis";
3
+ import { ASYNC_OPTIONS_TYPE, ConfigurableModuleClass, OPTIONS_TYPE } from "./redis.module-definition";
4
+ /**
5
+ * Module that provides Redis connection using ioredis.
6
+ *
7
+ * The module automatically loads configuration from environment variables if not provided:
8
+ * - `REDIS_URL`: Full Redis connection URL (e.g., `redis://user:pass@host:6379/0`)
9
+ * - `REDIS_HOST`: Redis server hostname
10
+ * - `REDIS_PORT`: Redis server port
11
+ * - `REDIS_DB` or `REDIS_DATABASE`: Redis database number
12
+ * - `REDIS_USER` or `REDIS_USERNAME`: Redis username
13
+ * - `REDIS_PASS` or `REDIS_PASSWORD`: Redis password
14
+ * - `REDIS_TLS`: Enable TLS connection
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * import { RedisModule } from '@nest-boot/redis';
19
+ *
20
+ * @Module({
21
+ * imports: [
22
+ * RedisModule.register({
23
+ * host: 'localhost',
24
+ * port: 6379,
25
+ * isGlobal: true,
26
+ * }),
27
+ * ],
28
+ * })
29
+ * export class AppModule {}
30
+ * ```
31
+ *
32
+ * @example
33
+ * ```typescript
34
+ * // Inject Redis client in your service
35
+ * import { Redis } from 'ioredis';
36
+ *
37
+ * @Injectable()
38
+ * export class CacheService {
39
+ * constructor(private readonly redis: Redis) {}
40
+ *
41
+ * async get(key: string): Promise<string | null> {
42
+ * return this.redis.get(key);
43
+ * }
44
+ * }
45
+ * ```
46
+ */
4
47
  export declare class RedisModule extends ConfigurableModuleClass implements OnApplicationShutdown {
5
48
  private readonly redis;
49
+ /**
50
+ * Registers the RedisModule with the given options.
51
+ * @param options - Redis connection options and isGlobal flag
52
+ * @returns Dynamic module configuration
53
+ */
54
+ static register(options: typeof OPTIONS_TYPE): DynamicModule;
55
+ /**
56
+ * Registers the RedisModule asynchronously with factory functions.
57
+ * @param options - Async configuration options
58
+ * @returns Dynamic module configuration
59
+ */
60
+ static registerAsync(options: typeof ASYNC_OPTIONS_TYPE): DynamicModule;
61
+ /** Creates a new RedisModule instance.
62
+ * @param redis - The ioredis client instance
63
+ */
6
64
  constructor(redis: Redis);
65
+ /**
66
+ * Gracefully closes the Redis connection when the application shuts down.
67
+ */
7
68
  onApplicationShutdown(): Promise<void>;
8
69
  }
@@ -8,36 +8,105 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
8
8
  var __metadata = (this && this.__metadata) || function (k, v) {
9
9
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
10
  };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
11
14
  Object.defineProperty(exports, "__esModule", { value: true });
12
15
  exports.RedisModule = void 0;
13
16
  const common_1 = require("@nestjs/common");
14
- const redis_1 = require("./redis");
17
+ const ioredis_1 = __importDefault(require("ioredis"));
15
18
  const redis_module_definition_1 = require("./redis.module-definition");
16
19
  const load_config_from_env_util_1 = require("./utils/load-config-from-env.util");
20
+ /**
21
+ * Module that provides Redis connection using ioredis.
22
+ *
23
+ * The module automatically loads configuration from environment variables if not provided:
24
+ * - `REDIS_URL`: Full Redis connection URL (e.g., `redis://user:pass@host:6379/0`)
25
+ * - `REDIS_HOST`: Redis server hostname
26
+ * - `REDIS_PORT`: Redis server port
27
+ * - `REDIS_DB` or `REDIS_DATABASE`: Redis database number
28
+ * - `REDIS_USER` or `REDIS_USERNAME`: Redis username
29
+ * - `REDIS_PASS` or `REDIS_PASSWORD`: Redis password
30
+ * - `REDIS_TLS`: Enable TLS connection
31
+ *
32
+ * @example
33
+ * ```typescript
34
+ * import { RedisModule } from '@nest-boot/redis';
35
+ *
36
+ * @Module({
37
+ * imports: [
38
+ * RedisModule.register({
39
+ * host: 'localhost',
40
+ * port: 6379,
41
+ * isGlobal: true,
42
+ * }),
43
+ * ],
44
+ * })
45
+ * export class AppModule {}
46
+ * ```
47
+ *
48
+ * @example
49
+ * ```typescript
50
+ * // Inject Redis client in your service
51
+ * import { Redis } from 'ioredis';
52
+ *
53
+ * @Injectable()
54
+ * export class CacheService {
55
+ * constructor(private readonly redis: Redis) {}
56
+ *
57
+ * async get(key: string): Promise<string | null> {
58
+ * return this.redis.get(key);
59
+ * }
60
+ * }
61
+ * ```
62
+ */
17
63
  let RedisModule = class RedisModule extends redis_module_definition_1.ConfigurableModuleClass {
64
+ /**
65
+ * Registers the RedisModule with the given options.
66
+ * @param options - Redis connection options and isGlobal flag
67
+ * @returns Dynamic module configuration
68
+ */
69
+ static register(options) {
70
+ return super.register(options);
71
+ }
72
+ /**
73
+ * Registers the RedisModule asynchronously with factory functions.
74
+ * @param options - Async configuration options
75
+ * @returns Dynamic module configuration
76
+ */
77
+ static registerAsync(options) {
78
+ return super.registerAsync(options);
79
+ }
80
+ /** Creates a new RedisModule instance.
81
+ * @param redis - The ioredis client instance
82
+ */
18
83
  constructor(redis) {
19
84
  super();
20
85
  this.redis = redis;
21
86
  }
87
+ /**
88
+ * Gracefully closes the Redis connection when the application shuts down.
89
+ */
22
90
  async onApplicationShutdown() {
23
91
  await this.redis.quit();
24
92
  }
25
93
  };
26
94
  exports.RedisModule = RedisModule;
27
95
  exports.RedisModule = RedisModule = __decorate([
96
+ (0, common_1.Global)(),
28
97
  (0, common_1.Module)({
29
98
  providers: [
30
99
  {
31
- provide: redis_1.Redis,
100
+ provide: ioredis_1.default,
32
101
  inject: [{ token: redis_module_definition_1.MODULE_OPTIONS_TOKEN, optional: true }],
33
- useFactory: (options = {}) => new redis_1.Redis({
102
+ useFactory: (options) => new ioredis_1.default({
34
103
  ...(0, load_config_from_env_util_1.loadConfigFromEnv)(),
35
104
  ...options,
36
105
  }),
37
106
  },
38
107
  ],
39
- exports: [redis_1.Redis],
108
+ exports: [ioredis_1.default],
40
109
  }),
41
- __metadata("design:paramtypes", [redis_1.Redis])
110
+ __metadata("design:paramtypes", [ioredis_1.default])
42
111
  ], RedisModule);
43
112
  //# sourceMappingURL=redis.module.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"redis.module.js","sourceRoot":"","sources":["../src/redis.module.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAoE;AAGpE,mCAAgC;AAChC,uEAGmC;AACnC,iFAAsE;AAgB/D,IAAM,WAAW,GAAjB,MAAM,WACX,SAAQ,iDAAuB;IAG/B,YAA6B,KAAY;QACvC,KAAK,EAAE,CAAC;QADmB,UAAK,GAAL,KAAK,CAAO;IAEzC,CAAC;IAED,KAAK,CAAC,qBAAqB;QACzB,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;IAC1B,CAAC;CACF,CAAA;AAXY,kCAAW;sBAAX,WAAW;IAdvB,IAAA,eAAM,EAAC;QACN,SAAS,EAAE;YACT;gBACE,OAAO,EAAE,aAAK;gBACd,MAAM,EAAE,CAAC,EA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