@xnestjs/ioredis 0.7.1 → 0.8.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/cjs/redis-core.module.js +15 -15
- package/cjs/redis.module.js +2 -2
- package/cjs/utils.js +1 -2
- package/esm/redis-core.module.js +15 -15
- package/esm/redis.module.js +2 -2
- package/package.json +8 -5
- package/types/redis.interface.d.ts +1 -1
package/cjs/redis-core.module.js
CHANGED
|
@@ -3,10 +3,10 @@ var RedisCoreModule_1;
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.RedisCoreModule = void 0;
|
|
5
5
|
const tslib_1 = require("tslib");
|
|
6
|
-
const crypto = tslib_1.__importStar(require("crypto"));
|
|
7
|
-
const ioredis_1 = tslib_1.__importStar(require("ioredis"));
|
|
8
6
|
const common_1 = require("@nestjs/common");
|
|
9
7
|
const core_1 = require("@nestjs/core");
|
|
8
|
+
const crypto = tslib_1.__importStar(require("crypto"));
|
|
9
|
+
const ioredis_1 = tslib_1.__importStar(require("ioredis"));
|
|
10
10
|
const redis_constants_js_1 = require("./redis.constants.js");
|
|
11
11
|
const redis_client_js_1 = require("./redis-client.js");
|
|
12
12
|
const utils_js_1 = require("./utils.js");
|
|
@@ -18,17 +18,17 @@ let RedisCoreModule = RedisCoreModule_1 = class RedisCoreModule {
|
|
|
18
18
|
static forRoot(options) {
|
|
19
19
|
const optionsProvider = {
|
|
20
20
|
provide: redis_constants_js_1.IOREDIS_MODULE_OPTIONS,
|
|
21
|
-
useValue: options
|
|
21
|
+
useValue: options,
|
|
22
22
|
};
|
|
23
23
|
const token = options.token || redis_client_js_1.RedisClient;
|
|
24
24
|
const connectionProvider = {
|
|
25
25
|
provide: token,
|
|
26
|
-
useFactory: () => this._createClient(options)
|
|
26
|
+
useFactory: () => this._createClient(options),
|
|
27
27
|
};
|
|
28
28
|
return {
|
|
29
29
|
module: RedisCoreModule_1,
|
|
30
30
|
providers: [connectionProvider, optionsProvider],
|
|
31
|
-
exports: [connectionProvider]
|
|
31
|
+
exports: [connectionProvider],
|
|
32
32
|
};
|
|
33
33
|
}
|
|
34
34
|
static forRootAsync(asyncOptions) {
|
|
@@ -38,9 +38,7 @@ let RedisCoreModule = RedisCoreModule_1 = class RedisCoreModule {
|
|
|
38
38
|
const connectionProvider = {
|
|
39
39
|
provide: token,
|
|
40
40
|
inject: [redis_constants_js_1.IOREDIS_MODULE_OPTIONS],
|
|
41
|
-
useFactory: async (moduleOptions) =>
|
|
42
|
-
return this._createClient(moduleOptions);
|
|
43
|
-
}
|
|
41
|
+
useFactory: async (moduleOptions) => this._createClient(moduleOptions),
|
|
44
42
|
};
|
|
45
43
|
return {
|
|
46
44
|
module: RedisCoreModule_1,
|
|
@@ -49,20 +47,21 @@ let RedisCoreModule = RedisCoreModule_1 = class RedisCoreModule {
|
|
|
49
47
|
{
|
|
50
48
|
provide: redis_constants_js_1.IOREDIS_MODULE_OPTIONS,
|
|
51
49
|
useFactory: asyncOptions.useFactory,
|
|
52
|
-
inject: asyncOptions.inject || []
|
|
50
|
+
inject: asyncOptions.inject || [],
|
|
53
51
|
},
|
|
54
52
|
{
|
|
55
53
|
provide: redis_constants_js_1.IOREDIS_MODULE_TOKEN,
|
|
56
|
-
useValue: crypto.randomUUID()
|
|
54
|
+
useValue: crypto.randomUUID(),
|
|
57
55
|
},
|
|
58
|
-
connectionProvider
|
|
56
|
+
connectionProvider,
|
|
59
57
|
],
|
|
60
|
-
exports: [connectionProvider]
|
|
58
|
+
exports: [connectionProvider],
|
|
61
59
|
};
|
|
62
60
|
}
|
|
63
61
|
static async _createClient(options) {
|
|
64
|
-
if (options.host && options.nodes)
|
|
62
|
+
if (options.host && options.nodes) {
|
|
65
63
|
throw new TypeError(`You should set either "host" or "nodes", not both`);
|
|
64
|
+
}
|
|
66
65
|
const opts = { ...options };
|
|
67
66
|
const isCluster = (0, utils_js_1.isClusterOptions)(opts);
|
|
68
67
|
let client;
|
|
@@ -82,7 +81,8 @@ let RedisCoreModule = RedisCoreModule_1 = class RedisCoreModule {
|
|
|
82
81
|
options.username = url.username;
|
|
83
82
|
if (url.password)
|
|
84
83
|
options.password = url.password;
|
|
85
|
-
if (url.protocol === 'rediss:') {
|
|
84
|
+
if (url.protocol === 'rediss:') {
|
|
85
|
+
// @ts-ignore
|
|
86
86
|
options.tls = true;
|
|
87
87
|
}
|
|
88
88
|
const db = parseInt(url.pathname.substring(1), 10);
|
|
@@ -98,7 +98,7 @@ let RedisCoreModule = RedisCoreModule_1 = class RedisCoreModule {
|
|
|
98
98
|
client.redis.removeListener('error', reject);
|
|
99
99
|
resolve();
|
|
100
100
|
});
|
|
101
|
-
client.redis.once('error',
|
|
101
|
+
client.redis.once('error', e => {
|
|
102
102
|
client.redis.removeListener('ready', resolve);
|
|
103
103
|
reject(e);
|
|
104
104
|
});
|
package/cjs/redis.module.js
CHANGED
|
@@ -9,13 +9,13 @@ let RedisModule = RedisModule_1 = class RedisModule {
|
|
|
9
9
|
static forRoot(options) {
|
|
10
10
|
return {
|
|
11
11
|
module: RedisModule_1,
|
|
12
|
-
imports: [redis_core_module_js_1.RedisCoreModule.forRoot(options)]
|
|
12
|
+
imports: [redis_core_module_js_1.RedisCoreModule.forRoot(options)],
|
|
13
13
|
};
|
|
14
14
|
}
|
|
15
15
|
static forRootAsync(options) {
|
|
16
16
|
return {
|
|
17
17
|
module: RedisModule_1,
|
|
18
|
-
imports: [redis_core_module_js_1.RedisCoreModule.forRootAsync(options)]
|
|
18
|
+
imports: [redis_core_module_js_1.RedisCoreModule.forRootAsync(options)],
|
|
19
19
|
};
|
|
20
20
|
}
|
|
21
21
|
};
|
package/cjs/utils.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isClusterOptions =
|
|
3
|
+
exports.isClusterOptions = isClusterOptions;
|
|
4
4
|
function isClusterOptions(options) {
|
|
5
5
|
return options && typeof options === 'object' && Array.isArray(options.nodes);
|
|
6
6
|
}
|
|
7
|
-
exports.isClusterOptions = isClusterOptions;
|
package/esm/redis-core.module.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
var RedisCoreModule_1;
|
|
2
2
|
import { __decorate, __metadata, __param } from "tslib";
|
|
3
|
+
import { Global, Inject, Module } from '@nestjs/common';
|
|
4
|
+
import { ModuleRef } from '@nestjs/core';
|
|
3
5
|
import * as crypto from 'crypto';
|
|
4
6
|
import Redis, { Cluster } from 'ioredis';
|
|
5
|
-
import { Global, Inject, Module, } from '@nestjs/common';
|
|
6
|
-
import { ModuleRef } from '@nestjs/core';
|
|
7
7
|
import { IOREDIS_MODULE_OPTIONS, IOREDIS_MODULE_TOKEN } from './redis.constants.js';
|
|
8
8
|
import { RedisClient } from './redis-client.js';
|
|
9
9
|
import { isClusterOptions } from './utils.js';
|
|
@@ -15,17 +15,17 @@ let RedisCoreModule = RedisCoreModule_1 = class RedisCoreModule {
|
|
|
15
15
|
static forRoot(options) {
|
|
16
16
|
const optionsProvider = {
|
|
17
17
|
provide: IOREDIS_MODULE_OPTIONS,
|
|
18
|
-
useValue: options
|
|
18
|
+
useValue: options,
|
|
19
19
|
};
|
|
20
20
|
const token = options.token || RedisClient;
|
|
21
21
|
const connectionProvider = {
|
|
22
22
|
provide: token,
|
|
23
|
-
useFactory: () => this._createClient(options)
|
|
23
|
+
useFactory: () => this._createClient(options),
|
|
24
24
|
};
|
|
25
25
|
return {
|
|
26
26
|
module: RedisCoreModule_1,
|
|
27
27
|
providers: [connectionProvider, optionsProvider],
|
|
28
|
-
exports: [connectionProvider]
|
|
28
|
+
exports: [connectionProvider],
|
|
29
29
|
};
|
|
30
30
|
}
|
|
31
31
|
static forRootAsync(asyncOptions) {
|
|
@@ -35,9 +35,7 @@ let RedisCoreModule = RedisCoreModule_1 = class RedisCoreModule {
|
|
|
35
35
|
const connectionProvider = {
|
|
36
36
|
provide: token,
|
|
37
37
|
inject: [IOREDIS_MODULE_OPTIONS],
|
|
38
|
-
useFactory: async (moduleOptions) =>
|
|
39
|
-
return this._createClient(moduleOptions);
|
|
40
|
-
}
|
|
38
|
+
useFactory: async (moduleOptions) => this._createClient(moduleOptions),
|
|
41
39
|
};
|
|
42
40
|
return {
|
|
43
41
|
module: RedisCoreModule_1,
|
|
@@ -46,20 +44,21 @@ let RedisCoreModule = RedisCoreModule_1 = class RedisCoreModule {
|
|
|
46
44
|
{
|
|
47
45
|
provide: IOREDIS_MODULE_OPTIONS,
|
|
48
46
|
useFactory: asyncOptions.useFactory,
|
|
49
|
-
inject: asyncOptions.inject || []
|
|
47
|
+
inject: asyncOptions.inject || [],
|
|
50
48
|
},
|
|
51
49
|
{
|
|
52
50
|
provide: IOREDIS_MODULE_TOKEN,
|
|
53
|
-
useValue: crypto.randomUUID()
|
|
51
|
+
useValue: crypto.randomUUID(),
|
|
54
52
|
},
|
|
55
|
-
connectionProvider
|
|
53
|
+
connectionProvider,
|
|
56
54
|
],
|
|
57
|
-
exports: [connectionProvider]
|
|
55
|
+
exports: [connectionProvider],
|
|
58
56
|
};
|
|
59
57
|
}
|
|
60
58
|
static async _createClient(options) {
|
|
61
|
-
if (options.host && options.nodes)
|
|
59
|
+
if (options.host && options.nodes) {
|
|
62
60
|
throw new TypeError(`You should set either "host" or "nodes", not both`);
|
|
61
|
+
}
|
|
63
62
|
const opts = { ...options };
|
|
64
63
|
const isCluster = isClusterOptions(opts);
|
|
65
64
|
let client;
|
|
@@ -79,7 +78,8 @@ let RedisCoreModule = RedisCoreModule_1 = class RedisCoreModule {
|
|
|
79
78
|
options.username = url.username;
|
|
80
79
|
if (url.password)
|
|
81
80
|
options.password = url.password;
|
|
82
|
-
if (url.protocol === 'rediss:') {
|
|
81
|
+
if (url.protocol === 'rediss:') {
|
|
82
|
+
// @ts-ignore
|
|
83
83
|
options.tls = true;
|
|
84
84
|
}
|
|
85
85
|
const db = parseInt(url.pathname.substring(1), 10);
|
|
@@ -95,7 +95,7 @@ let RedisCoreModule = RedisCoreModule_1 = class RedisCoreModule {
|
|
|
95
95
|
client.redis.removeListener('error', reject);
|
|
96
96
|
resolve();
|
|
97
97
|
});
|
|
98
|
-
client.redis.once('error',
|
|
98
|
+
client.redis.once('error', e => {
|
|
99
99
|
client.redis.removeListener('ready', resolve);
|
|
100
100
|
reject(e);
|
|
101
101
|
});
|
package/esm/redis.module.js
CHANGED
|
@@ -6,13 +6,13 @@ let RedisModule = RedisModule_1 = class RedisModule {
|
|
|
6
6
|
static forRoot(options) {
|
|
7
7
|
return {
|
|
8
8
|
module: RedisModule_1,
|
|
9
|
-
imports: [RedisCoreModule.forRoot(options)]
|
|
9
|
+
imports: [RedisCoreModule.forRoot(options)],
|
|
10
10
|
};
|
|
11
11
|
}
|
|
12
12
|
static forRootAsync(options) {
|
|
13
13
|
return {
|
|
14
14
|
module: RedisModule_1,
|
|
15
|
-
imports: [RedisCoreModule.forRootAsync(options)]
|
|
15
|
+
imports: [RedisCoreModule.forRootAsync(options)],
|
|
16
16
|
};
|
|
17
17
|
}
|
|
18
18
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xnestjs/ioredis",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "NestJS extension library for ioredis",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "MIT",
|
|
@@ -20,6 +20,8 @@
|
|
|
20
20
|
"build:esm": "tsc -b tsconfig-build-esm.json",
|
|
21
21
|
"postbuild": "cp package.json README.md ../../LICENSE ../../build/ioredis && cp ../../package.cjs.json ../../build/ioredis/cjs/package.json",
|
|
22
22
|
"lint": "eslint . --max-warnings=0",
|
|
23
|
+
"lint:fix": "eslint . --max-warnings=0 --fix",
|
|
24
|
+
"format": "prettier . --write --log-level=warn",
|
|
23
25
|
"check": "madge --circular src/**",
|
|
24
26
|
"test": "jest",
|
|
25
27
|
"cover": "jest --collect-coverage",
|
|
@@ -29,12 +31,13 @@
|
|
|
29
31
|
"clean:cover": "rimraf ../../coverage/ioredis"
|
|
30
32
|
},
|
|
31
33
|
"peerDependencies": {
|
|
32
|
-
"@nestjs/common": "^10.
|
|
33
|
-
"
|
|
34
|
+
"@nestjs/common": "^10.3.10",
|
|
35
|
+
"@nestjs/core": "^10.3.10",
|
|
36
|
+
"ioredis": "^5.4.1",
|
|
34
37
|
"redlock": "^5.0.0-beta.2"
|
|
35
38
|
},
|
|
36
39
|
"devDependencies": {
|
|
37
|
-
"@
|
|
40
|
+
"@nestjs/testing": "^10.3.10"
|
|
38
41
|
},
|
|
39
42
|
"engines": {
|
|
40
43
|
"node": ">=16.0",
|
|
@@ -53,4 +56,4 @@
|
|
|
53
56
|
"ioredis",
|
|
54
57
|
"redis"
|
|
55
58
|
]
|
|
56
|
-
}
|
|
59
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import type { ModuleMetadata } from '@nestjs/common/interfaces';
|
|
1
2
|
import type { RedisOptions } from 'ioredis';
|
|
2
3
|
import type { ClusterOptions } from 'ioredis/built/cluster/ClusterOptions';
|
|
3
4
|
import type { ClusterNode } from 'ioredis/built/cluster/index.js';
|
|
4
5
|
import type { Lock, Settings as RedlockSettings } from 'redlock';
|
|
5
|
-
import type { ModuleMetadata } from '@nestjs/common/interfaces';
|
|
6
6
|
export interface RedisClientOptions extends RedisOptions {
|
|
7
7
|
/**
|
|
8
8
|
* Injection token
|