@tsed/ioredis 7.3.0 → 7.3.1
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/lib/cjs/domain/IORedisConfiguration.js.map +1 -1
- package/lib/cjs/domain/IORedisStore.js +2 -1
- package/lib/cjs/domain/IORedisStore.js.map +1 -1
- package/lib/esm/domain/IORedisConfiguration.js.map +1 -1
- package/lib/esm/domain/IORedisStore.js +2 -1
- package/lib/esm/domain/IORedisStore.js.map +1 -1
- package/lib/types/domain/IORedisConfiguration.d.ts +4 -2
- package/lib/types/domain/IORedisStore.d.ts +6 -3
- package/package.json +5 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IORedisConfiguration.js","sourceRoot":"","sources":["../../../src/domain/IORedisConfiguration.ts"],"names":[],"mappings":"","sourcesContent":["import {TokenProvider} from \"@tsed/di\";\nimport {ClusterOptions, RedisOptions} from \"ioredis\";\n\nexport type ClusterConfiguration = {nodes: string[]} & ClusterOptions;\n\nexport interface BaseIORedisConfiguration {\n name?: TokenProvider;\n cache?: boolean;\n}\n\nexport type IORedisConfiguration = BaseIORedisConfiguration & (RedisOptions | ClusterConfiguration);\n\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n namespace TsED {\n interface Configuration {\n ioredis?: IORedisConfiguration[];\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"IORedisConfiguration.js","sourceRoot":"","sources":["../../../src/domain/IORedisConfiguration.ts"],"names":[],"mappings":"","sourcesContent":["import {TokenProvider} from \"@tsed/di\";\nimport Redis, {Cluster, ClusterOptions, RedisOptions} from \"ioredis\";\n\nexport type ClusterConfiguration = {nodes: string[]} & ClusterOptions;\n\nexport interface BaseIORedisConfiguration {\n name?: TokenProvider;\n cache?: boolean;\n}\n\nexport type IORedisConfiguration = BaseIORedisConfiguration & (RedisOptions | ClusterConfiguration) & {redisInstance?: Redis | Cluster};\n\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n namespace TsED {\n interface Configuration {\n ioredis?: IORedisConfiguration[];\n }\n }\n}\n"]}
|
|
@@ -16,7 +16,8 @@ class IORedisStore {
|
|
|
16
16
|
constructor(options) {
|
|
17
17
|
options ||= {};
|
|
18
18
|
this.redisCache =
|
|
19
|
-
|
|
19
|
+
options.redisInstance ||
|
|
20
|
+
("clusterConfig" in options ? new ioredis_1.default.Cluster(options.clusterConfig.nodes, options.clusterConfig.options) : new ioredis_1.default(options));
|
|
20
21
|
this.storeArgs = this.redisCache.options;
|
|
21
22
|
this.isCacheable = this.isCacheableValue =
|
|
22
23
|
this.storeArgs.isCacheable || this.storeArgs.isCacheableValue || ((value) => value !== undefined && value !== null);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IORedisStore.js","sourceRoot":"","sources":["../../../src/domain/IORedisStore.ts"],"names":[],"mappings":";;;;AACA,8DAAkF;AAOlF,MAAM,MAAM,GAAG,CAAC,KAAc,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"IORedisStore.js","sourceRoot":"","sources":["../../../src/domain/IORedisStore.ts"],"names":[],"mappings":";;;;AACA,8DAAkF;AAOlF,MAAM,MAAM,GAAG,CAAC,KAAc,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,aAAa,CAAC;AAI1E,MAAa,YAAY;IAChB,IAAI,GAAG,OAAO,CAAC;IACtB;;OAEG;IACI,gBAAgB,CAAC;IACjB,WAAW,CAAC;IACX,UAAU,CAAkB;IAC5B,SAAS,CAAM;IAEvB,YAAY,OAAgC;QAC1C,OAAO,KAAK,EAAE,CAAC;QAEf,IAAI,CAAC,UAAU;YACb,OAAO,CAAC,aAAa;gBACrB,CAAC,eAAe,IAAI,OAAO,CAAC,CAAC,CAAC,IAAI,iBAAK,CAAC,OAAO,CAAC,OAAO,CAAC,aAAa,CAAC,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CAAC,CAAC;IAChG,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,GAAG,IAAc;QAC1B,MAAM,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAClC,CAAC;IAED,KAAK,CAAC,KAAK;QACT,MAAM,IAAI,CAAC,UAAU,CAAC,QAAQ,EAAE,CAAC;IACnC,CAAC;IAED,IAAI,CAAC,UAAkB,GAAG;QACxB,OAAO,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACvC,CAAC;IAED,GAAG,CAAC,GAAW;QACb,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAClC,CAAC;IAEO,MAAM,CAAC,GAAY;QACzB,OAAO,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC;IACtD,CAAC;IAEO,eAAe,CAAC,KAAU;QAChC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE;YAC5B,MAAM,IAAI,KAAK,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC,4BAA4B,CAAC,CAAC;SAChE;IACH,CAAC;CACF;AAjHD,oCAiHC;AAEM,MAAM,YAAY,GAAG,CAAC,MAA2B,EAAE,EAAE,CAAC,IAAI,YAAY,CAAC,MAAM,CAAC,CAAC;AAAzE,QAAA,YAAY,gBAA6D","sourcesContent":["import type {Config, FactoryConfig, Store} from \"cache-manager\";\nimport Redis, {Cluster, ClusterNode, ClusterOptions, RedisOptions} from \"ioredis\";\n\nexport interface RedisClusterConfig {\n nodes: ClusterNode[];\n options?: ClusterOptions;\n}\n\nconst getVal = (value: unknown) => JSON.stringify(value) || '\"undefined\"';\n\nexport type IORedisStoreCtrOptions = (RedisOptions | {clusterConfig: RedisClusterConfig}) & Config & {redisInstance?: Redis | Cluster};\n\nexport class IORedisStore implements Store {\n public name = \"redis\";\n /**\n * @deprecated\n */\n public isCacheableValue;\n public isCacheable;\n private redisCache: Redis | Cluster;\n private storeArgs: any;\n\n constructor(options?: IORedisStoreCtrOptions) {\n options ||= {};\n\n this.redisCache =\n options.redisInstance ||\n (\"clusterConfig\" in options ? new Redis.Cluster(options.clusterConfig.nodes, options.clusterConfig.options) : new Redis(options));\n\n this.storeArgs = this.redisCache.options;\n this.isCacheable = this.isCacheableValue =\n this.storeArgs.isCacheable || this.storeArgs.isCacheableValue || ((value: any) => value !== undefined && value !== null);\n }\n\n get client() {\n return this.redisCache;\n }\n\n getClient() {\n return this.redisCache;\n }\n\n async set(key: string, value: any, ttl?: number) {\n this.assertCacheable(value);\n\n ttl = this.getTtl(ttl);\n\n const val = getVal(value);\n\n if (ttl) {\n await this.redisCache.setex(key, ttl, val);\n return;\n }\n\n await this.redisCache.set(key, val);\n }\n\n async get<T = any>(key: string, options?: any) {\n const val = await this.redisCache.get(key);\n\n if (val === undefined || val === null) {\n return undefined;\n }\n\n return JSON.parse(val) as T;\n }\n\n async del(key: string) {\n await this.redisCache.del(key);\n }\n\n async mset(args: [string, unknown][], ttl?: number) {\n ttl = this.getTtl(ttl);\n\n if (ttl) {\n const multi = this.redisCache.multi();\n\n for (const [key, value] of args) {\n this.assertCacheable(value);\n\n multi.setex(key, ttl / 1000, getVal(value));\n }\n\n await multi.exec();\n } else\n await this.redisCache.mset(\n args.flatMap(([key, value]) => {\n this.assertCacheable(value);\n\n return [key, getVal(value)] as [string, string];\n })\n );\n }\n\n async mget(...args: string[]) {\n const x = await this.redisCache.mget(args);\n\n return x.map((x) => (x === null || x === undefined ? undefined : (JSON.parse(x) as unknown)));\n }\n\n async mdel(...args: string[]) {\n await this.redisCache.del(args);\n }\n\n async reset() {\n await this.redisCache.flushall();\n }\n\n keys(pattern: string = \"*\") {\n return this.redisCache.keys(pattern);\n }\n\n ttl(key: string) {\n return this.redisCache.ttl(key);\n }\n\n private getTtl(ttl?: number) {\n return ttl === undefined ? this.storeArgs.ttl : ttl;\n }\n\n private assertCacheable(value: any) {\n if (!this.isCacheable(value)) {\n throw new Error(`\"${getVal(value)}\" is not a cacheable value`);\n }\n }\n}\n\nexport const ioRedisStore = (config?: FactoryConfig<any>) => new IORedisStore(config);\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IORedisConfiguration.js","sourceRoot":"","sources":["../../../src/domain/IORedisConfiguration.ts"],"names":[],"mappings":"","sourcesContent":["import {TokenProvider} from \"@tsed/di\";\nimport {ClusterOptions, RedisOptions} from \"ioredis\";\n\nexport type ClusterConfiguration = {nodes: string[]} & ClusterOptions;\n\nexport interface BaseIORedisConfiguration {\n name?: TokenProvider;\n cache?: boolean;\n}\n\nexport type IORedisConfiguration = BaseIORedisConfiguration & (RedisOptions | ClusterConfiguration);\n\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n namespace TsED {\n interface Configuration {\n ioredis?: IORedisConfiguration[];\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"IORedisConfiguration.js","sourceRoot":"","sources":["../../../src/domain/IORedisConfiguration.ts"],"names":[],"mappings":"","sourcesContent":["import {TokenProvider} from \"@tsed/di\";\nimport Redis, {Cluster, ClusterOptions, RedisOptions} from \"ioredis\";\n\nexport type ClusterConfiguration = {nodes: string[]} & ClusterOptions;\n\nexport interface BaseIORedisConfiguration {\n name?: TokenProvider;\n cache?: boolean;\n}\n\nexport type IORedisConfiguration = BaseIORedisConfiguration & (RedisOptions | ClusterConfiguration) & {redisInstance?: Redis | Cluster};\n\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n namespace TsED {\n interface Configuration {\n ioredis?: IORedisConfiguration[];\n }\n }\n}\n"]}
|
|
@@ -12,7 +12,8 @@ export class IORedisStore {
|
|
|
12
12
|
constructor(options) {
|
|
13
13
|
options ||= {};
|
|
14
14
|
this.redisCache =
|
|
15
|
-
|
|
15
|
+
options.redisInstance ||
|
|
16
|
+
("clusterConfig" in options ? new Redis.Cluster(options.clusterConfig.nodes, options.clusterConfig.options) : new Redis(options));
|
|
16
17
|
this.storeArgs = this.redisCache.options;
|
|
17
18
|
this.isCacheable = this.isCacheableValue =
|
|
18
19
|
this.storeArgs.isCacheable || this.storeArgs.isCacheableValue || ((value) => value !== undefined && value !== null);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IORedisStore.js","sourceRoot":"","sources":["../../../src/domain/IORedisStore.ts"],"names":[],"mappings":"AACA,OAAO,KAA2D,MAAM,SAAS,CAAC;AAOlF,MAAM,MAAM,GAAG,CAAC,KAAc,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"IORedisStore.js","sourceRoot":"","sources":["../../../src/domain/IORedisStore.ts"],"names":[],"mappings":"AACA,OAAO,KAA2D,MAAM,SAAS,CAAC;AAOlF,MAAM,MAAM,GAAG,CAAC,KAAc,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,aAAa,CAAC;AAI1E,MAAM,OAAO,YAAY;IAChB,IAAI,GAAG,OAAO,CAAC;IACtB;;OAEG;IACI,gBAAgB,CAAC;IACjB,WAAW,CAAC;IACX,UAAU,CAAkB;IAC5B,SAAS,CAAM;IAEvB,YAAY,OAAgC;QAC1C,OAAO,KAAK,EAAE,CAAC;QAEf,IAAI,CAAC,UAAU;YACb,OAAO,CAAC,aAAa;gBACrB,CAAC,eAAe,IAAI,OAAO,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,aAAa,CAAC,KAAK,EAAE,OAAO,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;QAEpI,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC;QACzC,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC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AC;IACnC,CAAC;IAED,IAAI,CAAC,UAAkB,GAAG;QACxB,OAAO,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACvC,CAAC;IAED,GAAG,CAAC,GAAW;QACb,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAClC,CAAC;IAEO,MAAM,CAAC,GAAY;QACzB,OAAO,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC;IACtD,CAAC;IAEO,eAAe,CAAC,KAAU;QAChC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE;YAC5B,MAAM,IAAI,KAAK,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC,4BAA4B,CAAC,CAAC;SAChE;IACH,CAAC;CACF;AAED,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,MAA2B,EAAE,EAAE,CAAC,IAAI,YAAY,CAAC,MAAM,CAAC,CAAC","sourcesContent":["import type {Config, FactoryConfig, Store} from \"cache-manager\";\nimport Redis, {Cluster, ClusterNode, ClusterOptions, RedisOptions} from \"ioredis\";\n\nexport interface RedisClusterConfig {\n nodes: ClusterNode[];\n options?: ClusterOptions;\n}\n\nconst getVal = (value: unknown) => JSON.stringify(value) || '\"undefined\"';\n\nexport type IORedisStoreCtrOptions = (RedisOptions | {clusterConfig: RedisClusterConfig}) & Config & {redisInstance?: Redis | Cluster};\n\nexport class IORedisStore implements Store {\n public name = \"redis\";\n /**\n * @deprecated\n */\n public isCacheableValue;\n public isCacheable;\n private redisCache: Redis | Cluster;\n private storeArgs: any;\n\n constructor(options?: IORedisStoreCtrOptions) {\n options ||= {};\n\n this.redisCache =\n options.redisInstance ||\n (\"clusterConfig\" in options ? new Redis.Cluster(options.clusterConfig.nodes, options.clusterConfig.options) : new Redis(options));\n\n this.storeArgs = this.redisCache.options;\n this.isCacheable = this.isCacheableValue =\n this.storeArgs.isCacheable || this.storeArgs.isCacheableValue || ((value: any) => value !== undefined && value !== null);\n }\n\n get client() {\n return this.redisCache;\n }\n\n getClient() {\n return this.redisCache;\n }\n\n async set(key: string, value: any, ttl?: number) {\n this.assertCacheable(value);\n\n ttl = this.getTtl(ttl);\n\n const val = getVal(value);\n\n if (ttl) {\n await this.redisCache.setex(key, ttl, val);\n return;\n }\n\n await this.redisCache.set(key, val);\n }\n\n async get<T = any>(key: string, options?: any) {\n const val = await this.redisCache.get(key);\n\n if (val === undefined || val === null) {\n return undefined;\n }\n\n return JSON.parse(val) as T;\n }\n\n async del(key: string) {\n await this.redisCache.del(key);\n }\n\n async mset(args: [string, unknown][], ttl?: number) {\n ttl = this.getTtl(ttl);\n\n if (ttl) {\n const multi = this.redisCache.multi();\n\n for (const [key, value] of args) {\n this.assertCacheable(value);\n\n multi.setex(key, ttl / 1000, getVal(value));\n }\n\n await multi.exec();\n } else\n await this.redisCache.mset(\n args.flatMap(([key, value]) => {\n this.assertCacheable(value);\n\n return [key, getVal(value)] as [string, string];\n })\n );\n }\n\n async mget(...args: string[]) {\n const x = await this.redisCache.mget(args);\n\n return x.map((x) => (x === null || x === undefined ? undefined : (JSON.parse(x) as unknown)));\n }\n\n async mdel(...args: string[]) {\n await this.redisCache.del(args);\n }\n\n async reset() {\n await this.redisCache.flushall();\n }\n\n keys(pattern: string = \"*\") {\n return this.redisCache.keys(pattern);\n }\n\n ttl(key: string) {\n return this.redisCache.ttl(key);\n }\n\n private getTtl(ttl?: number) {\n return ttl === undefined ? this.storeArgs.ttl : ttl;\n }\n\n private assertCacheable(value: any) {\n if (!this.isCacheable(value)) {\n throw new Error(`\"${getVal(value)}\" is not a cacheable value`);\n }\n }\n}\n\nexport const ioRedisStore = (config?: FactoryConfig<any>) => new IORedisStore(config);\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TokenProvider } from "@tsed/di";
|
|
2
|
-
import { ClusterOptions, RedisOptions } from "ioredis";
|
|
2
|
+
import Redis, { Cluster, ClusterOptions, RedisOptions } from "ioredis";
|
|
3
3
|
export declare type ClusterConfiguration = {
|
|
4
4
|
nodes: string[];
|
|
5
5
|
} & ClusterOptions;
|
|
@@ -7,7 +7,9 @@ export interface BaseIORedisConfiguration {
|
|
|
7
7
|
name?: TokenProvider;
|
|
8
8
|
cache?: boolean;
|
|
9
9
|
}
|
|
10
|
-
export declare type IORedisConfiguration = BaseIORedisConfiguration & (RedisOptions | ClusterConfiguration)
|
|
10
|
+
export declare type IORedisConfiguration = BaseIORedisConfiguration & (RedisOptions | ClusterConfiguration) & {
|
|
11
|
+
redisInstance?: Redis | Cluster;
|
|
12
|
+
};
|
|
11
13
|
declare global {
|
|
12
14
|
namespace TsED {
|
|
13
15
|
interface Configuration {
|
|
@@ -4,6 +4,11 @@ export interface RedisClusterConfig {
|
|
|
4
4
|
nodes: ClusterNode[];
|
|
5
5
|
options?: ClusterOptions;
|
|
6
6
|
}
|
|
7
|
+
export declare type IORedisStoreCtrOptions = (RedisOptions | {
|
|
8
|
+
clusterConfig: RedisClusterConfig;
|
|
9
|
+
}) & Config & {
|
|
10
|
+
redisInstance?: Redis | Cluster;
|
|
11
|
+
};
|
|
7
12
|
export declare class IORedisStore implements Store {
|
|
8
13
|
name: string;
|
|
9
14
|
/**
|
|
@@ -13,9 +18,7 @@ export declare class IORedisStore implements Store {
|
|
|
13
18
|
isCacheable: any;
|
|
14
19
|
private redisCache;
|
|
15
20
|
private storeArgs;
|
|
16
|
-
constructor(options?:
|
|
17
|
-
clusterConfig: RedisClusterConfig;
|
|
18
|
-
}) & Config);
|
|
21
|
+
constructor(options?: IORedisStoreCtrOptions);
|
|
19
22
|
get client(): Redis | Cluster;
|
|
20
23
|
getClient(): Redis | Cluster;
|
|
21
24
|
set(key: string, value: any, ttl?: number): Promise<void>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/ioredis",
|
|
3
|
-
"version": "7.3.
|
|
3
|
+
"version": "7.3.1",
|
|
4
4
|
"description": "IO Redis connection for Ts.ED",
|
|
5
5
|
"private": false,
|
|
6
6
|
"source": "./src/index.ts",
|
|
@@ -24,15 +24,15 @@
|
|
|
24
24
|
"tslib": "2.4.0"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@tsed/core": "7.3.
|
|
28
|
-
"@tsed/di": "7.3.
|
|
27
|
+
"@tsed/core": "7.3.1",
|
|
28
|
+
"@tsed/di": "7.3.1",
|
|
29
29
|
"@types/ioredis-mock": "^5.6.0",
|
|
30
30
|
"ioredis": "5.2.3",
|
|
31
31
|
"ioredis-mock": "8.2.2"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
|
-
"@tsed/core": "^7.3.
|
|
35
|
-
"@tsed/di": "^7.3.
|
|
34
|
+
"@tsed/core": "^7.3.1",
|
|
35
|
+
"@tsed/di": "^7.3.1",
|
|
36
36
|
"ioredis": ">=5.2.3",
|
|
37
37
|
"ioredis-mock": ">=8.2.2"
|
|
38
38
|
},
|