Skip to content

Commit fb30456

Browse files
authored
Merge pull request #60 from wisekaa03/master
package version upgrade, tslint -> eslint, uuid v3 -> v8
2 parents 1873b98 + dfdddd6 commit fb30456

16 files changed

+3408
-2175
lines changed

.eslintrc.js

+129
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
module.exports = {
2+
parser: '@typescript-eslint/parser',
3+
plugins: [
4+
'@typescript-eslint',
5+
'import',
6+
],
7+
extends: [
8+
'plugin:@typescript-eslint/eslint-recommended',
9+
'plugin:@typescript-eslint/recommended',
10+
'plugin:jest/recommended',
11+
'prettier/@typescript-eslint',
12+
'prettier/react',
13+
'plugin:prettier/recommended',
14+
],
15+
settings: {
16+
'import/resolver': {
17+
typescript: {
18+
project: ['tsconfig.json', 'tsconfig.spec.json'],
19+
},
20+
node: {
21+
extensions: ['.ts', '.tsx', '.js', '.jsx'],
22+
},
23+
},
24+
'import/ignore': ['\\.coffee$', '\\.(scss|less|css)$', '\\.(svg|png|jpe?g|webp|gif)(\\?.*)?$'],
25+
},
26+
globals: {
27+
window: true,
28+
document: true,
29+
process: true,
30+
__DEV__: true,
31+
__SERVER__: true,
32+
},
33+
parserOptions: {
34+
sourceType: 'module',
35+
jsx: true,
36+
useJSXTextNode: true,
37+
ecmaVersion: 2020,
38+
ecmaFeatures: {
39+
jsx: true,
40+
},
41+
},
42+
env: {
43+
es6: true,
44+
browser: true,
45+
node: true,
46+
jest: true,
47+
},
48+
rules: {
49+
'jest/valid-title': 0,
50+
'no-confusing-arrow': 0,
51+
'@typescript-eslint/indent': 0,
52+
'operator-linebreak': 0,
53+
'function-paren-newline': 0,
54+
'no-param-reassign': 0,
55+
'comma-dangle': 0,
56+
'object-curly-newline': 0,
57+
'implicit-arrow-linebreak': 0,
58+
'import/prefer-default-export': 0,
59+
'class-methods-use-this': 0,
60+
'lines-between-class-members': 0,
61+
'quote-props': 0,
62+
'indent': 0,
63+
'no-nested-ternary': 0,
64+
'spaced-comment': ['error', 'always', { markers: ['#region', '#endregion', '/'] }],
65+
'max-len': ['error', { code: 140, ignoreUrls: true }],
66+
'import/no-extraneous-dependencies': 0,
67+
'no-unused-vars': [
68+
'warn',
69+
{
70+
argsIgnorePattern: '^(_|[A-Z]+)',
71+
varsIgnorePattern: '^(_|[A-Z]+)',
72+
},
73+
],
74+
'import/extensions': [
75+
'error',
76+
'ignorePackages',
77+
{
78+
js: 'never',
79+
jsx: 'never',
80+
ts: 'never',
81+
tsx: 'never',
82+
},
83+
],
84+
'prettier/prettier': [
85+
'error',
86+
{
87+
parser: 'typescript',
88+
printWidth: 140,
89+
singleQuote: true,
90+
useTabs: false,
91+
tabWidth: 2,
92+
semi: true,
93+
bracketSpacing: true,
94+
trailingComma: 'all',
95+
arrowParens: 'always',
96+
insertPragma: true,
97+
quoteProps: 'consistent',
98+
jsxSingleQuote: false,
99+
jsxBracketSameLine: false,
100+
htmlWhitespaceSensivity: 'css',
101+
proseWrap: 'never',
102+
},
103+
],
104+
'no-empty-function': 0,
105+
'no-shadow': 'off',
106+
'@typescript-eslint/no-shadow': ['error'],
107+
'@typescript-eslint/no-explicit-any': 'warn',
108+
'@typescript-eslint/no-unused-vars': [
109+
'warn',
110+
{
111+
argsIgnorePattern: '^(_|[A-Z]+)',
112+
varsIgnorePattern: '^(_|[A-Z]+)',
113+
},
114+
],
115+
'react/require-default-props': 0,
116+
'react/jsx-curly-newline': 0,
117+
'no-use-before-define': 0,
118+
'jsx-a11y/anchor-is-valid': 0,
119+
'no-useless-constructor': 0,
120+
'react/jsx-one-expression-per-line': 0,
121+
'react/jsx-wrap-multilines': 0,
122+
'react/prop-types': 0,
123+
'react/static-property-placement': 0,
124+
'react/jsx-filename-extension': [1, { extensions: ['.js', '.jsx', '.tsx', '.ts'] }],
125+
'react/jsx-props-no-spreading': 0,
126+
// '@typescript-eslint/no-var-requires': 0,
127+
},
128+
};
129+

CHANGELOG.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1+
### v1.3
2+
tslint -> eslint
3+
14
### v1.1
2-
add multi client
5+
add multi client

dist/index.js

+13-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
"use strict";
2-
function __export(m) {
3-
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
4-
}
2+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3+
if (k2 === undefined) k2 = k;
4+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5+
}) : (function(o, m, k, k2) {
6+
if (k2 === undefined) k2 = k;
7+
o[k2] = m[k];
8+
}));
9+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
10+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11+
};
512
Object.defineProperty(exports, "__esModule", { value: true });
6-
__export(require("./redis.service"));
7-
__export(require("./redis.module"));
13+
__exportStar(require("./redis.service"), exports);
14+
__exportStar(require("./redis.module"), exports);
15+
__exportStar(require("./redis.interface"), exports);

dist/redis-client.provider.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export interface RedisClient {
88
clients: Map<string, Redis.Redis>;
99
size: number;
1010
}
11-
export declare const createClient: () => Provider<any>;
11+
export declare const createClient: () => Provider;
1212
export declare const createAsyncClientOptions: (options: RedisModuleAsyncOptions) => {
1313
provide: symbol;
1414
useFactory: (...args: any[]) => RedisModuleOptions | Promise<RedisModuleOptions> | RedisModuleOptions[] | Promise<RedisModuleOptions[]>;

dist/redis-client.provider.js

+16-34
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,46 @@
11
"use strict";
2-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3-
return new (P || (P = Promise))(function (resolve, reject) {
4-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6-
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
7-
step((generator = generator.apply(thisArg, _arguments || [])).next());
8-
});
9-
};
10-
var __rest = (this && this.__rest) || function (s, e) {
11-
var t = {};
12-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
13-
t[p] = s[p];
14-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
15-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)
16-
t[p[i]] = s[p[i]];
17-
return t;
18-
};
192
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.createAsyncClientOptions = exports.createClient = exports.RedisClientError = void 0;
204
const Redis = require("ioredis");
21-
const uuid = require("uuid");
5+
const uuid_1 = require("uuid");
226
const redis_constants_1 = require("./redis.constants");
237
class RedisClientError extends Error {
248
}
259
exports.RedisClientError = RedisClientError;
26-
function getClient(options) {
27-
return __awaiter(this, void 0, void 0, function* () {
28-
const { onClientReady, url } = options, opt = __rest(options, ["onClientReady", "url"]);
29-
const client = url ? new Redis(url) : new Redis(opt);
30-
if (onClientReady) {
31-
onClientReady(client);
32-
}
33-
return client;
34-
});
10+
async function getClient(options) {
11+
const { onClientReady, url, ...opt } = options;
12+
const client = url ? new Redis(url) : new Redis(opt);
13+
if (onClientReady) {
14+
onClientReady(client);
15+
}
16+
return client;
3517
}
3618
exports.createClient = () => ({
3719
provide: redis_constants_1.REDIS_CLIENT,
38-
useFactory: (options) => __awaiter(this, void 0, void 0, function* () {
20+
useFactory: async (options) => {
3921
const clients = new Map();
40-
let defaultKey = uuid();
22+
let defaultKey = uuid_1.v4();
4123
if (Array.isArray(options)) {
42-
yield Promise.all(options.map((o) => __awaiter(this, void 0, void 0, function* () {
24+
await Promise.all(options.map(async (o) => {
4325
const key = o.name || defaultKey;
4426
if (clients.has(key)) {
4527
throw new RedisClientError(`${o.name || 'default'} client is exists`);
4628
}
47-
clients.set(key, yield getClient(o));
48-
})));
29+
clients.set(key, await getClient(o));
30+
}));
4931
}
5032
else {
5133
if (options.name && options.name.length !== 0) {
5234
defaultKey = options.name;
5335
}
54-
clients.set(defaultKey, yield getClient(options));
36+
clients.set(defaultKey, await getClient(options));
5537
}
5638
return {
5739
defaultKey,
5840
clients,
5941
size: clients.size,
6042
};
61-
}),
43+
},
6244
inject: [redis_constants_1.REDIS_MODULE_OPTIONS],
6345
});
6446
exports.createAsyncClientOptions = (options) => ({

dist/redis-core.module.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ var __metadata = (this && this.__metadata) || function (k, v) {
1111
var __param = (this && this.__param) || function (paramIndex, decorator) {
1212
return function (target, key) { decorator(target, key, paramIndex); }
1313
};
14-
Object.defineProperty(exports, "__esModule", { value: true });
1514
var RedisCoreModule_1;
15+
Object.defineProperty(exports, "__esModule", { value: true });
16+
exports.RedisCoreModule = void 0;
1617
const common_1 = require("@nestjs/common");
1718
const core_1 = require("@nestjs/core");
1819
const redis_client_provider_1 = require("./redis-client.provider");

dist/redis.constants.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"use strict";
22
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.REDIS_CLIENT = exports.REDIS_MODULE_OPTIONS = void 0;
34
exports.REDIS_MODULE_OPTIONS = Symbol('REDIS_MODULE_OPTIONS');
45
exports.REDIS_CLIENT = Symbol('REDIS_CLIENT');

dist/redis.module.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
55
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;
66
return c > 3 && r && Object.defineProperty(target, key, r), r;
77
};
8-
Object.defineProperty(exports, "__esModule", { value: true });
98
var RedisModule_1;
9+
Object.defineProperty(exports, "__esModule", { value: true });
10+
exports.RedisModule = void 0;
1011
const common_1 = require("@nestjs/common");
1112
const redis_core_module_1 = require("./redis-core.module");
1213
let RedisModule = RedisModule_1 = class RedisModule {

dist/redis.service.d.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import * as Redis from 'ioredis';
1+
import { Redis } from 'ioredis';
22
import { RedisClient } from './redis-client.provider';
33
export declare class RedisService {
44
private readonly redisClient;
55
constructor(redisClient: RedisClient);
6-
getClient(name?: string): Redis.Redis;
7-
getClients(): Map<string, Redis.Redis>;
6+
getClient(name?: string): Redis;
7+
getClients(): Map<string, Redis>;
88
}

dist/redis.service.js

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
1212
return function (target, key) { decorator(target, key, paramIndex); }
1313
};
1414
Object.defineProperty(exports, "__esModule", { value: true });
15+
exports.RedisService = void 0;
1516
const common_1 = require("@nestjs/common");
1617
const redis_constants_1 = require("./redis.constants");
1718
const redis_client_provider_1 = require("./redis-client.provider");

lib/redis-client.provider.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as Redis from 'ioredis';
2-
import * as uuid from 'uuid';
2+
import { v4 as uuidv4 } from 'uuid';
33
import { Provider } from '@nestjs/common';
44

55
import { REDIS_CLIENT, REDIS_MODULE_OPTIONS } from './redis.constants';
@@ -25,7 +25,7 @@ export const createClient = (): Provider => ({
2525
provide: REDIS_CLIENT,
2626
useFactory: async (options: RedisModuleOptions | RedisModuleOptions[]): Promise<RedisClient> => {
2727
const clients = new Map<string, Redis.Redis>();
28-
let defaultKey = uuid();
28+
let defaultKey = uuidv4();
2929

3030
if (Array.isArray(options)) {
3131
await Promise.all(

lib/redis.service.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Injectable, Inject } from '@nestjs/common';
22
import { REDIS_CLIENT } from './redis.constants';
3-
import * as Redis from 'ioredis';
3+
import { Redis } from 'ioredis';
44
import { RedisClient, RedisClientError } from './redis-client.provider';
55

66
@Injectable()
@@ -9,7 +9,7 @@ export class RedisService {
99
@Inject(REDIS_CLIENT) private readonly redisClient: RedisClient,
1010
) {}
1111

12-
getClient(name?: string): Redis.Redis {
12+
getClient(name?: string): Redis {
1313
if (!name) {
1414
name = this.redisClient.defaultKey;
1515
}
@@ -19,7 +19,7 @@ export class RedisService {
1919
return this.redisClient.clients.get(name);
2020
}
2121

22-
getClients(): Map<string, Redis.Redis> {
22+
getClients(): Map<string, Redis> {
2323
return this.redisClient.clients;
2424
}
2525
}

0 commit comments

Comments
 (0)