@atls/nestjs-redis 0.0.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/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/module/index.d.ts +4 -0
- package/dist/module/index.js +4 -0
- package/dist/module/redis.config-factory.d.ts +9 -0
- package/dist/module/redis.config-factory.js +47 -0
- package/dist/module/redis.factory.d.ts +8 -0
- package/dist/module/redis.factory.js +29 -0
- package/dist/module/redis.module.constants.d.ts +4 -0
- package/dist/module/redis.module.constants.js +4 -0
- package/dist/module/redis.module.d.ts +5 -0
- package/dist/module/redis.module.js +47 -0
- package/package.json +51 -0
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { RedisOptions } from 'ioredis';
|
|
2
|
+
export declare class RedisConfigFactory {
|
|
3
|
+
private readonly port;
|
|
4
|
+
private readonly host;
|
|
5
|
+
private readonly password;
|
|
6
|
+
private readonly username;
|
|
7
|
+
constructor(port: number, host: string, password: string, username: string);
|
|
8
|
+
createRedisOptions(): RedisOptions;
|
|
9
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
11
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
12
|
+
};
|
|
13
|
+
import { Inject } from '@nestjs/common';
|
|
14
|
+
import { Injectable } from '@nestjs/common';
|
|
15
|
+
import { REDIS_MODULE_OPTIONS_PORT } from './redis.module.constants.js';
|
|
16
|
+
import { REDIS_MODULE_OPTIONS_HOST } from './redis.module.constants.js';
|
|
17
|
+
import { REDIS_MODULE_OPTIONS_PASSWORD } from './redis.module.constants.js';
|
|
18
|
+
import { REDIS_MODULE_OPTIONS_USERNAME } from './redis.module.constants.js';
|
|
19
|
+
let RedisConfigFactory = class RedisConfigFactory {
|
|
20
|
+
port;
|
|
21
|
+
host;
|
|
22
|
+
password;
|
|
23
|
+
username;
|
|
24
|
+
constructor(port, host, password, username) {
|
|
25
|
+
this.port = port;
|
|
26
|
+
this.host = host;
|
|
27
|
+
this.password = password;
|
|
28
|
+
this.username = username;
|
|
29
|
+
}
|
|
30
|
+
createRedisOptions() {
|
|
31
|
+
return {
|
|
32
|
+
username: this.username || process.env.REDIS_USERNAME || 'default',
|
|
33
|
+
password: this.password || process.env.REDIS_PASSWORD || 'password',
|
|
34
|
+
host: this.host || process.env.REDIS_HOST || 'localhost',
|
|
35
|
+
port: this.port || 6379,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
RedisConfigFactory = __decorate([
|
|
40
|
+
Injectable(),
|
|
41
|
+
__param(0, Inject(REDIS_MODULE_OPTIONS_PORT)),
|
|
42
|
+
__param(1, Inject(REDIS_MODULE_OPTIONS_HOST)),
|
|
43
|
+
__param(2, Inject(REDIS_MODULE_OPTIONS_PASSWORD)),
|
|
44
|
+
__param(3, Inject(REDIS_MODULE_OPTIONS_USERNAME)),
|
|
45
|
+
__metadata("design:paramtypes", [Number, String, String, String])
|
|
46
|
+
], RedisConfigFactory);
|
|
47
|
+
export { RedisConfigFactory };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { RedisOptions } from 'ioredis';
|
|
2
|
+
import { Redis } from 'ioredis';
|
|
3
|
+
import { RedisConfigFactory } from './redis.config-factory.js';
|
|
4
|
+
export declare class RedisFactory {
|
|
5
|
+
private readonly configFactory;
|
|
6
|
+
constructor(configFactory: RedisConfigFactory);
|
|
7
|
+
create(options?: RedisOptions): Redis;
|
|
8
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
import { Injectable } from '@nestjs/common';
|
|
11
|
+
import { Redis } from 'ioredis';
|
|
12
|
+
import { RedisConfigFactory } from './redis.config-factory.js';
|
|
13
|
+
let RedisFactory = class RedisFactory {
|
|
14
|
+
configFactory;
|
|
15
|
+
constructor(configFactory) {
|
|
16
|
+
this.configFactory = configFactory;
|
|
17
|
+
}
|
|
18
|
+
create(options = {}) {
|
|
19
|
+
return new Redis({
|
|
20
|
+
...this.configFactory.createRedisOptions(),
|
|
21
|
+
...options,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
RedisFactory = __decorate([
|
|
26
|
+
Injectable(),
|
|
27
|
+
__metadata("design:paramtypes", [RedisConfigFactory])
|
|
28
|
+
], RedisFactory);
|
|
29
|
+
export { RedisFactory };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export const REDIS_MODULE_OPTIONS_HOST = Symbol('redis-module-options-host');
|
|
2
|
+
export const REDIS_MODULE_OPTIONS_PORT = Symbol('redis-module-options-port');
|
|
3
|
+
export const REDIS_MODULE_OPTIONS_USERNAME = Symbol('redis-module-options-username');
|
|
4
|
+
export const REDIS_MODULE_OPTIONS_PASSWORD = Symbol('redis-module-options-password');
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var RedisModule_1;
|
|
8
|
+
import { Module } from '@nestjs/common';
|
|
9
|
+
import { RedisConfigFactory } from './redis.config-factory.js';
|
|
10
|
+
import { RedisFactory } from './redis.factory.js';
|
|
11
|
+
import { REDIS_MODULE_OPTIONS_HOST } from './redis.module.constants.js';
|
|
12
|
+
import { REDIS_MODULE_OPTIONS_PORT } from './redis.module.constants.js';
|
|
13
|
+
import { REDIS_MODULE_OPTIONS_PASSWORD } from './redis.module.constants.js';
|
|
14
|
+
import { REDIS_MODULE_OPTIONS_USERNAME } from './redis.module.constants.js';
|
|
15
|
+
let RedisModule = RedisModule_1 = class RedisModule {
|
|
16
|
+
static register(options = {}, global = false) {
|
|
17
|
+
return {
|
|
18
|
+
global,
|
|
19
|
+
module: RedisModule_1,
|
|
20
|
+
providers: [
|
|
21
|
+
RedisConfigFactory,
|
|
22
|
+
RedisFactory,
|
|
23
|
+
{
|
|
24
|
+
provide: REDIS_MODULE_OPTIONS_HOST,
|
|
25
|
+
useValue: options.host,
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
provide: REDIS_MODULE_OPTIONS_PORT,
|
|
29
|
+
useValue: options.port,
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
provide: REDIS_MODULE_OPTIONS_USERNAME,
|
|
33
|
+
useValue: options.username,
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
provide: REDIS_MODULE_OPTIONS_PASSWORD,
|
|
37
|
+
useValue: options.password,
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
exports: [RedisConfigFactory, RedisFactory],
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
RedisModule = RedisModule_1 = __decorate([
|
|
45
|
+
Module({})
|
|
46
|
+
], RedisModule);
|
|
47
|
+
export { RedisModule };
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@atls/nestjs-redis",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"license": "BSD-3-Clause",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
"./package.json": "./package.json",
|
|
8
|
+
".": {
|
|
9
|
+
"import": "./dist/index.js",
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"main": "dist/index.js",
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "yarn library build",
|
|
20
|
+
"prepack": "yarn run build",
|
|
21
|
+
"postpack": "rm -rf dist"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"ioredis": "^5.3.2"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@nestjs/common": "^10.0.5",
|
|
28
|
+
"@nestjs/core": "^10.0.5",
|
|
29
|
+
"reflect-metadata": "^0.1.13",
|
|
30
|
+
"rxjs": "^7.8.1"
|
|
31
|
+
},
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"@nestjs/common": "^10",
|
|
34
|
+
"@nestjs/core": "^10",
|
|
35
|
+
"reflect-metadata": "^0.1",
|
|
36
|
+
"rxjs": "^7"
|
|
37
|
+
},
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"exports": {
|
|
40
|
+
"./package.json": "./package.json",
|
|
41
|
+
".": {
|
|
42
|
+
"import": "./dist/index.js",
|
|
43
|
+
"types": "./dist/index.d.ts",
|
|
44
|
+
"default": "./dist/index.js"
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
"main": "dist/index.js",
|
|
48
|
+
"typings": "dist/index.d.ts"
|
|
49
|
+
},
|
|
50
|
+
"typings": "dist/index.d.ts"
|
|
51
|
+
}
|