Unverified 提交 fb30456e authored 作者: ziyun.zhu's avatar ziyun.zhu 提交者: GitHub

Merge pull request #60 from wisekaa03/master

package version upgrade, tslint -> eslint, uuid v3 -> v8
module.exports = {
parser: '@typescript-eslint/parser',
plugins: [
'@typescript-eslint',
'import',
],
extends: [
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
'plugin:jest/recommended',
'prettier/@typescript-eslint',
'prettier/react',
'plugin:prettier/recommended',
],
settings: {
'import/resolver': {
typescript: {
project: ['tsconfig.json', 'tsconfig.spec.json'],
},
node: {
extensions: ['.ts', '.tsx', '.js', '.jsx'],
},
},
'import/ignore': ['\\.coffee$', '\\.(scss|less|css)$', '\\.(svg|png|jpe?g|webp|gif)(\\?.*)?$'],
},
globals: {
window: true,
document: true,
process: true,
__DEV__: true,
__SERVER__: true,
},
parserOptions: {
sourceType: 'module',
jsx: true,
useJSXTextNode: true,
ecmaVersion: 2020,
ecmaFeatures: {
jsx: true,
},
},
env: {
es6: true,
browser: true,
node: true,
jest: true,
},
rules: {
'jest/valid-title': 0,
'no-confusing-arrow': 0,
'@typescript-eslint/indent': 0,
'operator-linebreak': 0,
'function-paren-newline': 0,
'no-param-reassign': 0,
'comma-dangle': 0,
'object-curly-newline': 0,
'implicit-arrow-linebreak': 0,
'import/prefer-default-export': 0,
'class-methods-use-this': 0,
'lines-between-class-members': 0,
'quote-props': 0,
'indent': 0,
'no-nested-ternary': 0,
'spaced-comment': ['error', 'always', { markers: ['#region', '#endregion', '/'] }],
'max-len': ['error', { code: 140, ignoreUrls: true }],
'import/no-extraneous-dependencies': 0,
'no-unused-vars': [
'warn',
{
argsIgnorePattern: '^(_|[A-Z]+)',
varsIgnorePattern: '^(_|[A-Z]+)',
},
],
'import/extensions': [
'error',
'ignorePackages',
{
js: 'never',
jsx: 'never',
ts: 'never',
tsx: 'never',
},
],
'prettier/prettier': [
'error',
{
parser: 'typescript',
printWidth: 140,
singleQuote: true,
useTabs: false,
tabWidth: 2,
semi: true,
bracketSpacing: true,
trailingComma: 'all',
arrowParens: 'always',
insertPragma: true,
quoteProps: 'consistent',
jsxSingleQuote: false,
jsxBracketSameLine: false,
htmlWhitespaceSensivity: 'css',
proseWrap: 'never',
},
],
'no-empty-function': 0,
'no-shadow': 'off',
'@typescript-eslint/no-shadow': ['error'],
'@typescript-eslint/no-explicit-any': 'warn',
'@typescript-eslint/no-unused-vars': [
'warn',
{
argsIgnorePattern: '^(_|[A-Z]+)',
varsIgnorePattern: '^(_|[A-Z]+)',
},
],
'react/require-default-props': 0,
'react/jsx-curly-newline': 0,
'no-use-before-define': 0,
'jsx-a11y/anchor-is-valid': 0,
'no-useless-constructor': 0,
'react/jsx-one-expression-per-line': 0,
'react/jsx-wrap-multilines': 0,
'react/prop-types': 0,
'react/static-property-placement': 0,
'react/jsx-filename-extension': [1, { extensions: ['.js', '.jsx', '.tsx', '.ts'] }],
'react/jsx-props-no-spreading': 0,
// '@typescript-eslint/no-var-requires': 0,
},
};
\ No newline at end of file
### v1.3
tslint -> eslint
### v1.1 ### v1.1
add multi client add multi client
\ No newline at end of file
"use strict"; "use strict";
function __export(m) { var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; if (k2 === undefined) k2 = k;
} Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
__export(require("./redis.service")); __exportStar(require("./redis.service"), exports);
__export(require("./redis.module")); __exportStar(require("./redis.module"), exports);
__exportStar(require("./redis.interface"), exports);
...@@ -8,7 +8,7 @@ export interface RedisClient { ...@@ -8,7 +8,7 @@ export interface RedisClient {
clients: Map<string, Redis.Redis>; clients: Map<string, Redis.Redis>;
size: number; size: number;
} }
export declare const createClient: () => Provider<any>; export declare const createClient: () => Provider;
export declare const createAsyncClientOptions: (options: RedisModuleAsyncOptions) => { export declare const createAsyncClientOptions: (options: RedisModuleAsyncOptions) => {
provide: symbol; provide: symbol;
useFactory: (...args: any[]) => RedisModuleOptions | Promise<RedisModuleOptions> | RedisModuleOptions[] | Promise<RedisModuleOptions[]>; useFactory: (...args: any[]) => RedisModuleOptions | Promise<RedisModuleOptions> | RedisModuleOptions[] | Promise<RedisModuleOptions[]>;
......
"use strict"; "use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)
t[p[i]] = s[p[i]];
return t;
};
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
exports.createAsyncClientOptions = exports.createClient = exports.RedisClientError = void 0;
const Redis = require("ioredis"); const Redis = require("ioredis");
const uuid = require("uuid"); const uuid_1 = require("uuid");
const redis_constants_1 = require("./redis.constants"); const redis_constants_1 = require("./redis.constants");
class RedisClientError extends Error { class RedisClientError extends Error {
} }
exports.RedisClientError = RedisClientError; exports.RedisClientError = RedisClientError;
function getClient(options) { async function getClient(options) {
return __awaiter(this, void 0, void 0, function* () { const { onClientReady, url, ...opt } = options;
const { onClientReady, url } = options, opt = __rest(options, ["onClientReady", "url"]); const client = url ? new Redis(url) : new Redis(opt);
const client = url ? new Redis(url) : new Redis(opt); if (onClientReady) {
if (onClientReady) { onClientReady(client);
onClientReady(client); }
} return client;
return client;
});
} }
exports.createClient = () => ({ exports.createClient = () => ({
provide: redis_constants_1.REDIS_CLIENT, provide: redis_constants_1.REDIS_CLIENT,
useFactory: (options) => __awaiter(this, void 0, void 0, function* () { useFactory: async (options) => {
const clients = new Map(); const clients = new Map();
let defaultKey = uuid(); let defaultKey = uuid_1.v4();
if (Array.isArray(options)) { if (Array.isArray(options)) {
yield Promise.all(options.map((o) => __awaiter(this, void 0, void 0, function* () { await Promise.all(options.map(async (o) => {
const key = o.name || defaultKey; const key = o.name || defaultKey;
if (clients.has(key)) { if (clients.has(key)) {
throw new RedisClientError(`${o.name || 'default'} client is exists`); throw new RedisClientError(`${o.name || 'default'} client is exists`);
} }
clients.set(key, yield getClient(o)); clients.set(key, await getClient(o));
}))); }));
} }
else { else {
if (options.name && options.name.length !== 0) { if (options.name && options.name.length !== 0) {
defaultKey = options.name; defaultKey = options.name;
} }
clients.set(defaultKey, yield getClient(options)); clients.set(defaultKey, await getClient(options));
} }
return { return {
defaultKey, defaultKey,
clients, clients,
size: clients.size, size: clients.size,
}; };
}), },
inject: [redis_constants_1.REDIS_MODULE_OPTIONS], inject: [redis_constants_1.REDIS_MODULE_OPTIONS],
}); });
exports.createAsyncClientOptions = (options) => ({ exports.createAsyncClientOptions = (options) => ({
......
...@@ -11,8 +11,9 @@ var __metadata = (this && this.__metadata) || function (k, v) { ...@@ -11,8 +11,9 @@ var __metadata = (this && this.__metadata) || function (k, v) {
var __param = (this && this.__param) || function (paramIndex, decorator) { var __param = (this && this.__param) || function (paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); } return function (target, key) { decorator(target, key, paramIndex); }
}; };
Object.defineProperty(exports, "__esModule", { value: true });
var RedisCoreModule_1; var RedisCoreModule_1;
Object.defineProperty(exports, "__esModule", { value: true });
exports.RedisCoreModule = void 0;
const common_1 = require("@nestjs/common"); const common_1 = require("@nestjs/common");
const core_1 = require("@nestjs/core"); const core_1 = require("@nestjs/core");
const redis_client_provider_1 = require("./redis-client.provider"); const redis_client_provider_1 = require("./redis-client.provider");
......
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
exports.REDIS_CLIENT = exports.REDIS_MODULE_OPTIONS = void 0;
exports.REDIS_MODULE_OPTIONS = Symbol('REDIS_MODULE_OPTIONS'); exports.REDIS_MODULE_OPTIONS = Symbol('REDIS_MODULE_OPTIONS');
exports.REDIS_CLIENT = Symbol('REDIS_CLIENT'); exports.REDIS_CLIENT = Symbol('REDIS_CLIENT');
...@@ -5,8 +5,9 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key, ...@@ -5,8 +5,9 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
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; 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;
return c > 3 && r && Object.defineProperty(target, key, r), r; return c > 3 && r && Object.defineProperty(target, key, r), r;
}; };
Object.defineProperty(exports, "__esModule", { value: true });
var RedisModule_1; var RedisModule_1;
Object.defineProperty(exports, "__esModule", { value: true });
exports.RedisModule = void 0;
const common_1 = require("@nestjs/common"); const common_1 = require("@nestjs/common");
const redis_core_module_1 = require("./redis-core.module"); const redis_core_module_1 = require("./redis-core.module");
let RedisModule = RedisModule_1 = class RedisModule { let RedisModule = RedisModule_1 = class RedisModule {
......
import * as Redis from 'ioredis'; import { Redis } from 'ioredis';
import { RedisClient } from './redis-client.provider'; import { RedisClient } from './redis-client.provider';
export declare class RedisService { export declare class RedisService {
private readonly redisClient; private readonly redisClient;
constructor(redisClient: RedisClient); constructor(redisClient: RedisClient);
getClient(name?: string): Redis.Redis; getClient(name?: string): Redis;
getClients(): Map<string, Redis.Redis>; getClients(): Map<string, Redis>;
} }
...@@ -12,6 +12,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { ...@@ -12,6 +12,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); } return function (target, key) { decorator(target, key, paramIndex); }
}; };
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
exports.RedisService = void 0;
const common_1 = require("@nestjs/common"); const common_1 = require("@nestjs/common");
const redis_constants_1 = require("./redis.constants"); const redis_constants_1 = require("./redis.constants");
const redis_client_provider_1 = require("./redis-client.provider"); const redis_client_provider_1 = require("./redis-client.provider");
......
import * as Redis from 'ioredis'; import * as Redis from 'ioredis';
import * as uuid from 'uuid'; import { v4 as uuidv4 } from 'uuid';
import { Provider } from '@nestjs/common'; import { Provider } from '@nestjs/common';
import { REDIS_CLIENT, REDIS_MODULE_OPTIONS } from './redis.constants'; import { REDIS_CLIENT, REDIS_MODULE_OPTIONS } from './redis.constants';
...@@ -25,7 +25,7 @@ export const createClient = (): Provider => ({ ...@@ -25,7 +25,7 @@ export const createClient = (): Provider => ({
provide: REDIS_CLIENT, provide: REDIS_CLIENT,
useFactory: async (options: RedisModuleOptions | RedisModuleOptions[]): Promise<RedisClient> => { useFactory: async (options: RedisModuleOptions | RedisModuleOptions[]): Promise<RedisClient> => {
const clients = new Map<string, Redis.Redis>(); const clients = new Map<string, Redis.Redis>();
let defaultKey = uuid(); let defaultKey = uuidv4();
if (Array.isArray(options)) { if (Array.isArray(options)) {
await Promise.all( await Promise.all(
......
import { Injectable, Inject } from '@nestjs/common'; import { Injectable, Inject } from '@nestjs/common';
import { REDIS_CLIENT } from './redis.constants'; import { REDIS_CLIENT } from './redis.constants';
import * as Redis from 'ioredis'; import { Redis } from 'ioredis';
import { RedisClient, RedisClientError } from './redis-client.provider'; import { RedisClient, RedisClientError } from './redis-client.provider';
@Injectable() @Injectable()
...@@ -9,7 +9,7 @@ export class RedisService { ...@@ -9,7 +9,7 @@ export class RedisService {
@Inject(REDIS_CLIENT) private readonly redisClient: RedisClient, @Inject(REDIS_CLIENT) private readonly redisClient: RedisClient,
) {} ) {}
getClient(name?: string): Redis.Redis { getClient(name?: string): Redis {
if (!name) { if (!name) {
name = this.redisClient.defaultKey; name = this.redisClient.defaultKey;
} }
...@@ -19,7 +19,7 @@ export class RedisService { ...@@ -19,7 +19,7 @@ export class RedisService {
return this.redisClient.clients.get(name); return this.redisClient.clients.get(name);
} }
getClients(): Map<string, Redis.Redis> { getClients(): Map<string, Redis> {
return this.redisClient.clients; return this.redisClient.clients;
} }
} }
{ {
"name": "nestjs-redis", "name": "nest-redis",
"version": "1.2.7", "version": "1.3.2",
"description": "a nestjs redis module", "description": "a NestJS ioRedis module",
"author": "zzy", "author": "Stanislav V Vyaliy",
"license": "MIT", "license": "MIT",
"repository": { "repository": {
"type": "git", "type": "git",
"url": "https://github.com/kyknow/nestjs-redis" "url": "https://github.com/wisekaa03/nestjs-ioredis.git"
}, },
"scripts": { "scripts": {
"build": "rimraf dist && tsc -p tsconfig.json", "build": "rimraf dist && tsc -p tsconfig.json",
"precommit": "lint-staged", "precommit": "lint-staged",
"prepublish:npm": "yarn run build", "prepublish": "yarn run build",
"publish:npm": "yarn publish --access public", "publish-public": "yarn publish --access public",
"test": "jest", "test": "jest",
"test:watch": "jest --watch", "test:watch": "jest --watch",
"test:cov": "jest --coverage", "test:cov": "jest --coverage",
"test:e2e": "jest --config ./test/jest-e2e.json", "test:e2e": "jest --config ./test/jest-e2e.json",
"lint": "tslint -p tsconfig.json -c tslint.json" "lint": "eslint -c .eslintrc.js"
}, },
"dependencies": { "dependencies": {
"@nestjs/common": "6.3.1", "@nestjs/common": "^7",
"@nestjs/core": "^6.6.7", "@nestjs/core": "^7",
"@types/ioredis": "^4.0.4", "@types/ioredis": "*",
"@types/uuid": "^3.4.4", "@types/uuid": "*",
"ioredis": "^4.2.0", "ioredis": "^4",
"reflect-metadata": "^0.1.12", "reflect-metadata": "*",
"rxjs": "^6.2.2", "rxjs": "^6",
"uuid": "^3.3.2" "uuid": "^8"
}, },
"devDependencies": { "devDependencies": {
"@nestjs/testing": "6.3.1", "@nestjs/testing": "^7",
"@types/node": "^10.7.1", "@types/node": "*",
"cz-conventional-changelog": "^2.1.0", "@typescript-eslint/eslint-plugin": "^4",
"jest": "^23.6.0", "@typescript-eslint/parser": "^4",
"prettier": "^1.19.1", "cz-conventional-changelog": "^3",
"rimraf": "^2.6.3", "eslint": "*",
"ts-jest": "^23.10.5", "eslint-config-prettier": "^6",
"tslint": "^5.20.1", "eslint-plugin-jest": "^24",
"tslint-config-prettier": "^1.18.0", "eslint-plugin-prettier": "^3",
"tslint-plugin-prettier": "^2.0.1", "jest": "^26",
"typescript": "^2.4.2" "prettier": "^2",
"rimraf": "*",
"ts-jest": "^26",
"typescript": "^4"
}, },
"keywords": [ "keywords": [
"nestjs", "nestjs",
......
{ {
"compilerOptions": { "compilerOptions": {
"module": "commonjs", "module": "CommonJS",
"target": "ES2018",
"declaration": true, "declaration": true,
"noImplicitAny": false, "noImplicitAny": false,
"removeComments": true, "removeComments": true,
"noLib": false, "noLib": false,
"emitDecoratorMetadata": true, "emitDecoratorMetadata": true,
"experimentalDecorators": true, "experimentalDecorators": true,
"target": "es6",
"sourceMap": false, "sourceMap": false,
"outDir": "./dist", "outDir": "./dist",
"rootDir": "./lib", "rootDir": "./lib",
"skipLibCheck": true "skipLibCheck": true
}, },
"include": [ "include": ["lib/**/*", "../index.ts"],
"lib/**/*", "exclude": ["node_modules", "**/*.spec.ts"]
"../index.ts" }
],
"exclude": [
"node_modules",
"**/*.spec.ts"
]
}
\ No newline at end of file
{
"defaultSeverity": "error",
"extends": ["tslint:recommended", "tslint-config-prettier"],
"jsRules": {
"no-unused-expression": true
},
"rules": {
"eofline": false,
"quotemark": [true, "single"],
"indent": false,
"member-access": [false],
"ordered-imports": [false],
"max-line-length": [true, 150],
"member-ordering": [false],
"curly": false,
"interface-name": [false],
"array-type": [false],
"no-empty-interface": false,
"no-empty": false,
"arrow-parens": false,
"object-literal-sort-keys": false,
"no-unused-expression": false,
"max-classes-per-file": false,
"variable-name": [false],
"one-line": [false],
"one-variable-per-declaration": [false]
},
"rulesDirectory": ["tslint-plugin-prettier"]
}
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论