@tomsd/redis-client 1.0.2 → 1.1.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/dist/index.cjs +88 -0
- package/dist/index.d.cts +22 -0
- package/dist/{esm/index.d.ts → index.d.ts} +5 -3
- package/dist/index.js +53 -0
- package/package.json +22 -29
- package/.eslintrc-love-temp.cjs +0 -367
- package/.eslintrc.json +0 -17
- package/dist/cjs/index.js +0 -67
- package/dist/esm/index.js +0 -74
- package/tryit/addArticle.ts +0 -13
- package/tryit/addUser.ts +0 -12
- package/tryit/common.ts +0 -31
- package/tryit/delArticle.ts +0 -20
- package/tryit/delUser.ts +0 -19
- package/tryit/getArticles.ts +0 -13
- package/tryit/getUsers.ts +0 -14
- package/tryit/seed.ts +0 -35
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var src_exports = {};
|
|
32
|
+
__export(src_exports, {
|
|
33
|
+
Redis: () => Redis
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(src_exports);
|
|
36
|
+
var import_ioredis = __toESM(require("ioredis"), 1);
|
|
37
|
+
var import_uuid = require("uuid");
|
|
38
|
+
var Redis = class {
|
|
39
|
+
config;
|
|
40
|
+
redis;
|
|
41
|
+
constructor(config) {
|
|
42
|
+
this.config = config;
|
|
43
|
+
this.redis = void 0;
|
|
44
|
+
}
|
|
45
|
+
get keyProp() {
|
|
46
|
+
return this.config.keyProp ?? "_id";
|
|
47
|
+
}
|
|
48
|
+
get expireSeconds() {
|
|
49
|
+
return this.config.expireSeconds;
|
|
50
|
+
}
|
|
51
|
+
getRedis() {
|
|
52
|
+
this.redis = this.redis ?? new import_ioredis.default(this.config.options);
|
|
53
|
+
return this.redis;
|
|
54
|
+
}
|
|
55
|
+
async getKeys() {
|
|
56
|
+
const keyFilter = `${this.config?.options?.keyPrefix ?? ""}*`;
|
|
57
|
+
const sliceKey = (s) => s.slice(this.config?.options?.keyPrefix?.length ?? 0);
|
|
58
|
+
return await this.getRedis().keys(keyFilter).then((keys) => keys.map(sliceKey));
|
|
59
|
+
}
|
|
60
|
+
async get(key) {
|
|
61
|
+
return await this.getRedis().get(key).then((value) => {
|
|
62
|
+
if (value == null) {
|
|
63
|
+
return void 0;
|
|
64
|
+
}
|
|
65
|
+
return JSON.parse(value);
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
async set(value) {
|
|
69
|
+
const redis = this.getRedis();
|
|
70
|
+
const savingObj = {
|
|
71
|
+
[this.keyProp]: (0, import_uuid.v4)(),
|
|
72
|
+
...value
|
|
73
|
+
};
|
|
74
|
+
const key = savingObj[this.keyProp];
|
|
75
|
+
return this.expireSeconds !== void 0 ? await redis.set(key, JSON.stringify(savingObj), "EX", this.expireSeconds).then(() => savingObj) : await redis.set(key, JSON.stringify(savingObj)).then(() => savingObj);
|
|
76
|
+
}
|
|
77
|
+
async del(key) {
|
|
78
|
+
return await this.getRedis().del(key);
|
|
79
|
+
}
|
|
80
|
+
disconnect() {
|
|
81
|
+
this.getRedis().disconnect();
|
|
82
|
+
this.redis = void 0;
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
86
|
+
0 && (module.exports = {
|
|
87
|
+
Redis
|
|
88
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import IORedis, { RedisOptions } from 'ioredis';
|
|
2
|
+
|
|
3
|
+
interface EasyRedisConfig {
|
|
4
|
+
keyProp?: string;
|
|
5
|
+
expireSeconds?: number;
|
|
6
|
+
options: RedisOptions;
|
|
7
|
+
}
|
|
8
|
+
declare class Redis<T = any> {
|
|
9
|
+
config: EasyRedisConfig;
|
|
10
|
+
protected redis: IORedis | undefined;
|
|
11
|
+
constructor(config: EasyRedisConfig);
|
|
12
|
+
get keyProp(): string;
|
|
13
|
+
get expireSeconds(): number | undefined;
|
|
14
|
+
getRedis(): IORedis;
|
|
15
|
+
getKeys(): Promise<string[]>;
|
|
16
|
+
get(key: string): Promise<T>;
|
|
17
|
+
set(value: T | Partial<T>): Promise<T>;
|
|
18
|
+
del(key: string): Promise<number>;
|
|
19
|
+
disconnect(): void;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export { Redis };
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import IORedis, {
|
|
1
|
+
import IORedis, { RedisOptions } from 'ioredis';
|
|
2
|
+
|
|
2
3
|
interface EasyRedisConfig {
|
|
3
4
|
keyProp?: string;
|
|
4
5
|
expireSeconds?: number;
|
|
5
6
|
options: RedisOptions;
|
|
6
7
|
}
|
|
7
|
-
|
|
8
|
+
declare class Redis<T = any> {
|
|
8
9
|
config: EasyRedisConfig;
|
|
9
10
|
protected redis: IORedis | undefined;
|
|
10
11
|
constructor(config: EasyRedisConfig);
|
|
@@ -17,4 +18,5 @@ export declare class Redis<T = any> {
|
|
|
17
18
|
del(key: string): Promise<number>;
|
|
18
19
|
disconnect(): void;
|
|
19
20
|
}
|
|
20
|
-
|
|
21
|
+
|
|
22
|
+
export { Redis };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import IORedis from "ioredis";
|
|
3
|
+
import { v4 as uuid } from "uuid";
|
|
4
|
+
var Redis = class {
|
|
5
|
+
config;
|
|
6
|
+
redis;
|
|
7
|
+
constructor(config) {
|
|
8
|
+
this.config = config;
|
|
9
|
+
this.redis = void 0;
|
|
10
|
+
}
|
|
11
|
+
get keyProp() {
|
|
12
|
+
return this.config.keyProp ?? "_id";
|
|
13
|
+
}
|
|
14
|
+
get expireSeconds() {
|
|
15
|
+
return this.config.expireSeconds;
|
|
16
|
+
}
|
|
17
|
+
getRedis() {
|
|
18
|
+
this.redis = this.redis ?? new IORedis(this.config.options);
|
|
19
|
+
return this.redis;
|
|
20
|
+
}
|
|
21
|
+
async getKeys() {
|
|
22
|
+
const keyFilter = `${this.config?.options?.keyPrefix ?? ""}*`;
|
|
23
|
+
const sliceKey = (s) => s.slice(this.config?.options?.keyPrefix?.length ?? 0);
|
|
24
|
+
return await this.getRedis().keys(keyFilter).then((keys) => keys.map(sliceKey));
|
|
25
|
+
}
|
|
26
|
+
async get(key) {
|
|
27
|
+
return await this.getRedis().get(key).then((value) => {
|
|
28
|
+
if (value == null) {
|
|
29
|
+
return void 0;
|
|
30
|
+
}
|
|
31
|
+
return JSON.parse(value);
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
async set(value) {
|
|
35
|
+
const redis = this.getRedis();
|
|
36
|
+
const savingObj = {
|
|
37
|
+
[this.keyProp]: uuid(),
|
|
38
|
+
...value
|
|
39
|
+
};
|
|
40
|
+
const key = savingObj[this.keyProp];
|
|
41
|
+
return this.expireSeconds !== void 0 ? await redis.set(key, JSON.stringify(savingObj), "EX", this.expireSeconds).then(() => savingObj) : await redis.set(key, JSON.stringify(savingObj)).then(() => savingObj);
|
|
42
|
+
}
|
|
43
|
+
async del(key) {
|
|
44
|
+
return await this.getRedis().del(key);
|
|
45
|
+
}
|
|
46
|
+
disconnect() {
|
|
47
|
+
this.getRedis().disconnect();
|
|
48
|
+
this.redis = void 0;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
export {
|
|
52
|
+
Redis
|
|
53
|
+
};
|
package/package.json
CHANGED
|
@@ -1,32 +1,33 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tomsd/redis-client",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "It's a wrapper of ioredis.",
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"import": "./dist/index.js",
|
|
10
|
+
"require": "./dist/index.cjs"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"dist"
|
|
15
|
+
],
|
|
8
16
|
"scripts": {
|
|
9
|
-
"build": "
|
|
10
|
-
"
|
|
11
|
-
"format:src": "prettier --write src/",
|
|
12
|
-
"format:test": "prettier --write __test__/",
|
|
13
|
-
"lint": "npm run lint:src && npm run lint:test",
|
|
14
|
-
"lint:src": "eslint src/**/*.ts",
|
|
15
|
-
"lint:test": "eslint __test__/**/*.ts",
|
|
17
|
+
"build": "tsup",
|
|
18
|
+
"lint": "biome check",
|
|
16
19
|
"prepare": "husky",
|
|
17
20
|
"start-redis": "docker run --rm -d -p 6379:6379 --name redis-instance redis:alpine",
|
|
18
21
|
"stop-redis": "docker container stop redis-instance",
|
|
19
22
|
"serve:doc": "mdbook --serve --directory docs",
|
|
20
|
-
"test": "
|
|
23
|
+
"test": "vitest"
|
|
21
24
|
},
|
|
22
25
|
"lint-staged": {
|
|
23
26
|
"src/**/*.ts": [
|
|
24
|
-
"npm run lint
|
|
25
|
-
"npm run format:src"
|
|
27
|
+
"npm run lint"
|
|
26
28
|
],
|
|
27
29
|
"__test__/**/*.ts": [
|
|
28
|
-
"npm run lint
|
|
29
|
-
"npm run format:test"
|
|
30
|
+
"npm run lint"
|
|
30
31
|
]
|
|
31
32
|
},
|
|
32
33
|
"repository": {
|
|
@@ -43,24 +44,16 @@
|
|
|
43
44
|
},
|
|
44
45
|
"homepage": "https://github.com/tomsdoo/redis-client#readme",
|
|
45
46
|
"devDependencies": {
|
|
46
|
-
"@
|
|
47
|
-
"@babel/preset-env": "7.26.0",
|
|
48
|
-
"@babel/preset-typescript": "7.26.0",
|
|
47
|
+
"@biomejs/biome": "1.9.4",
|
|
49
48
|
"@tomsd/md-book": "1.3.3",
|
|
49
|
+
"@types/node": "22.10.1",
|
|
50
50
|
"@types/uuid": "10.0.0",
|
|
51
|
-
"@typescript-eslint/eslint-plugin": "8.16.0",
|
|
52
|
-
"babel-jest": "29.7.0",
|
|
53
|
-
"eslint": "8.57.1",
|
|
54
|
-
"eslint-config-prettier": "9.1.0",
|
|
55
|
-
"eslint-plugin-import": "2.31.0",
|
|
56
|
-
"eslint-plugin-n": "17.14.0",
|
|
57
|
-
"eslint-plugin-promise": "7.2.1",
|
|
58
51
|
"husky": "9.1.7",
|
|
59
|
-
"jest": "29.7.0",
|
|
60
52
|
"lint-staged": "15.2.10",
|
|
61
|
-
"prettier": "3.4.1",
|
|
62
53
|
"ts-node": "10.9.2",
|
|
63
|
-
"
|
|
54
|
+
"tsup": "8.3.5",
|
|
55
|
+
"typescript": "5.7.2",
|
|
56
|
+
"vitest": "2.1.6"
|
|
64
57
|
},
|
|
65
58
|
"dependencies": {
|
|
66
59
|
"ioredis": "5.4.1",
|
package/.eslintrc-love-temp.cjs
DELETED
|
@@ -1,367 +0,0 @@
|
|
|
1
|
-
// renaming standard-with-typescript -> eslint-config-love
|
|
2
|
-
|
|
3
|
-
const rules = {
|
|
4
|
-
'@typescript-eslint/adjacent-overload-signatures': ['error'],
|
|
5
|
-
'@typescript-eslint/array-type': ['error', { default: 'array-simple' }],
|
|
6
|
-
'@typescript-eslint/await-thenable': ['error'],
|
|
7
|
-
'@typescript-eslint/ban-ts-comment': ['error', {
|
|
8
|
-
'ts-expect-error': 'allow-with-description',
|
|
9
|
-
'ts-ignore': true,
|
|
10
|
-
'ts-nocheck': true,
|
|
11
|
-
'ts-check': false,
|
|
12
|
-
minimumDescriptionLength: 3
|
|
13
|
-
}],
|
|
14
|
-
'@typescript-eslint/ban-tslint-comment': ['error'],
|
|
15
|
-
'@typescript-eslint/no-empty-object-type': 'error',
|
|
16
|
-
'@typescript-eslint/no-unsafe-function-type': 'error',
|
|
17
|
-
'@typescript-eslint/no-wrapper-object-types': 'error',
|
|
18
|
-
'@typescript-eslint/block-spacing': ['error', 'always'],
|
|
19
|
-
'@typescript-eslint/brace-style': ['error', '1tbs', { allowSingleLine: true }],
|
|
20
|
-
'@typescript-eslint/class-literal-property-style': ['error', 'fields'],
|
|
21
|
-
'@typescript-eslint/comma-dangle': ['error', {
|
|
22
|
-
arrays: 'never',
|
|
23
|
-
objects: 'never',
|
|
24
|
-
imports: 'never',
|
|
25
|
-
exports: 'never',
|
|
26
|
-
functions: 'never',
|
|
27
|
-
enums: 'ignore',
|
|
28
|
-
generics: 'ignore',
|
|
29
|
-
tuples: 'ignore'
|
|
30
|
-
}],
|
|
31
|
-
'@typescript-eslint/comma-spacing': ['error', { before: false, after: true }],
|
|
32
|
-
'@typescript-eslint/consistent-generic-constructors': ['error', 'constructor'],
|
|
33
|
-
'@typescript-eslint/consistent-indexed-object-style': ['error', 'record'],
|
|
34
|
-
'@typescript-eslint/consistent-type-assertions': [
|
|
35
|
-
'error',
|
|
36
|
-
{
|
|
37
|
-
assertionStyle: 'as',
|
|
38
|
-
objectLiteralTypeAssertions: 'never'
|
|
39
|
-
}
|
|
40
|
-
],
|
|
41
|
-
'@typescript-eslint/consistent-type-definitions': ['error', 'interface'],
|
|
42
|
-
'@typescript-eslint/consistent-type-exports': ['error', {
|
|
43
|
-
fixMixedExportsWithInlineTypeSpecifier: true
|
|
44
|
-
}],
|
|
45
|
-
'@typescript-eslint/consistent-type-imports': ['error', {
|
|
46
|
-
prefer: 'type-imports',
|
|
47
|
-
disallowTypeAnnotations: true,
|
|
48
|
-
fixStyle: 'inline-type-imports'
|
|
49
|
-
}],
|
|
50
|
-
'@typescript-eslint/dot-notation': ['error',
|
|
51
|
-
{
|
|
52
|
-
allowIndexSignaturePropertyAccess: false,
|
|
53
|
-
allowKeywords: true,
|
|
54
|
-
allowPattern: '',
|
|
55
|
-
allowPrivateClassPropertyAccess: false,
|
|
56
|
-
allowProtectedClassPropertyAccess: false
|
|
57
|
-
}
|
|
58
|
-
],
|
|
59
|
-
'@typescript-eslint/explicit-function-return-type': ['error', {
|
|
60
|
-
allowExpressions: true,
|
|
61
|
-
allowHigherOrderFunctions: true,
|
|
62
|
-
allowTypedFunctionExpressions: true,
|
|
63
|
-
allowDirectConstAssertionInArrowFunctions: true
|
|
64
|
-
}],
|
|
65
|
-
'@typescript-eslint/func-call-spacing': ['error', 'never'],
|
|
66
|
-
'@typescript-eslint/indent': ['error', 2, {
|
|
67
|
-
SwitchCase: 1,
|
|
68
|
-
VariableDeclarator: 1,
|
|
69
|
-
outerIIFEBody: 1,
|
|
70
|
-
MemberExpression: 1,
|
|
71
|
-
FunctionDeclaration: { parameters: 1, body: 1 },
|
|
72
|
-
FunctionExpression: { parameters: 1, body: 1 },
|
|
73
|
-
CallExpression: { arguments: 1 },
|
|
74
|
-
ArrayExpression: 1,
|
|
75
|
-
ObjectExpression: 1,
|
|
76
|
-
ImportDeclaration: 1,
|
|
77
|
-
flatTernaryExpressions: false,
|
|
78
|
-
ignoreComments: false,
|
|
79
|
-
ignoredNodes: [
|
|
80
|
-
'TemplateLiteral *',
|
|
81
|
-
'JSXElement',
|
|
82
|
-
'JSXElement > *',
|
|
83
|
-
'JSXAttribute',
|
|
84
|
-
'JSXIdentifier',
|
|
85
|
-
'JSXNamespacedName',
|
|
86
|
-
'JSXMemberExpression',
|
|
87
|
-
'JSXSpreadAttribute',
|
|
88
|
-
'JSXExpressionContainer',
|
|
89
|
-
'JSXOpeningElement',
|
|
90
|
-
'JSXClosingElement',
|
|
91
|
-
'JSXFragment',
|
|
92
|
-
'JSXOpeningFragment',
|
|
93
|
-
'JSXClosingFragment',
|
|
94
|
-
'JSXText',
|
|
95
|
-
'JSXEmptyExpression',
|
|
96
|
-
'JSXSpreadChild'
|
|
97
|
-
],
|
|
98
|
-
offsetTernaryExpressions: true
|
|
99
|
-
}],
|
|
100
|
-
'@typescript-eslint/key-spacing': ['error', { beforeColon: false, afterColon: true }],
|
|
101
|
-
'@typescript-eslint/keyword-spacing': ['error', { before: true, after: true }],
|
|
102
|
-
'@typescript-eslint/member-delimiter-style': [
|
|
103
|
-
'error',
|
|
104
|
-
{
|
|
105
|
-
multiline: { delimiter: 'none' },
|
|
106
|
-
singleline: { delimiter: 'comma', requireLast: false }
|
|
107
|
-
}
|
|
108
|
-
],
|
|
109
|
-
'@typescript-eslint/method-signature-style': ['error'],
|
|
110
|
-
'@typescript-eslint/naming-convention': ['error', {
|
|
111
|
-
selector: 'variableLike',
|
|
112
|
-
leadingUnderscore: 'allow',
|
|
113
|
-
trailingUnderscore: 'allow',
|
|
114
|
-
format: ['camelCase', 'PascalCase', 'UPPER_CASE']
|
|
115
|
-
}],
|
|
116
|
-
'@typescript-eslint/no-array-constructor': ['error'],
|
|
117
|
-
'@typescript-eslint/no-base-to-string': ['error'],
|
|
118
|
-
'@typescript-eslint/no-confusing-void-expression': ['error', { ignoreArrowShorthand: false, ignoreVoidOperator: false }],
|
|
119
|
-
'@typescript-eslint/no-dupe-class-members': ['error'],
|
|
120
|
-
'@typescript-eslint/no-dynamic-delete': ['error'],
|
|
121
|
-
'@typescript-eslint/no-empty-interface': ['error', { allowSingleExtends: true }],
|
|
122
|
-
'@typescript-eslint/no-extra-non-null-assertion': ['error'],
|
|
123
|
-
'@typescript-eslint/no-extra-parens': ['error', 'functions'],
|
|
124
|
-
'@typescript-eslint/no-extraneous-class': ['error', { allowWithDecorator: true }],
|
|
125
|
-
'@typescript-eslint/no-floating-promises': ['error'],
|
|
126
|
-
'@typescript-eslint/no-for-in-array': ['error'],
|
|
127
|
-
'@typescript-eslint/no-implied-eval': ['error'],
|
|
128
|
-
'@typescript-eslint/no-invalid-void-type': ['error'],
|
|
129
|
-
'@typescript-eslint/no-loss-of-precision': ['error'],
|
|
130
|
-
'@typescript-eslint/no-misused-new': ['error'],
|
|
131
|
-
'@typescript-eslint/no-misused-promises': ['error'],
|
|
132
|
-
'@typescript-eslint/no-namespace': ['error'],
|
|
133
|
-
'@typescript-eslint/no-non-null-asserted-optional-chain': ['error'],
|
|
134
|
-
'@typescript-eslint/no-non-null-assertion': ['error'],
|
|
135
|
-
'@typescript-eslint/no-redeclare': ['error', { builtinGlobals: false }],
|
|
136
|
-
'@typescript-eslint/no-this-alias': ['error', { allowDestructuring: true }],
|
|
137
|
-
'@typescript-eslint/only-throw-error': ['error'],
|
|
138
|
-
'@typescript-eslint/no-unnecessary-boolean-literal-compare': ['error'],
|
|
139
|
-
'@typescript-eslint/no-unnecessary-type-assertion': ['error'],
|
|
140
|
-
'@typescript-eslint/no-unnecessary-type-constraint': ['error'],
|
|
141
|
-
'@typescript-eslint/no-unsafe-argument': ['error'],
|
|
142
|
-
'@typescript-eslint/no-unused-expressions': ['error', {
|
|
143
|
-
allowShortCircuit: true,
|
|
144
|
-
allowTernary: true,
|
|
145
|
-
allowTaggedTemplates: true,
|
|
146
|
-
enforceForJSX: false
|
|
147
|
-
}],
|
|
148
|
-
'@typescript-eslint/no-unused-vars': ['error', {
|
|
149
|
-
args: 'none',
|
|
150
|
-
caughtErrors: 'none',
|
|
151
|
-
ignoreRestSiblings: true,
|
|
152
|
-
vars: 'all'
|
|
153
|
-
}],
|
|
154
|
-
'@typescript-eslint/no-use-before-define': ['error', {
|
|
155
|
-
functions: false,
|
|
156
|
-
classes: false,
|
|
157
|
-
enums: false,
|
|
158
|
-
variables: false,
|
|
159
|
-
typedefs: false
|
|
160
|
-
}],
|
|
161
|
-
'@typescript-eslint/no-useless-constructor': ['error'],
|
|
162
|
-
'@typescript-eslint/no-var-requires': ['error'],
|
|
163
|
-
'@typescript-eslint/non-nullable-type-assertion-style': ['error'],
|
|
164
|
-
'@typescript-eslint/object-curly-spacing': ['error', 'always'],
|
|
165
|
-
'@typescript-eslint/prefer-function-type': ['error'],
|
|
166
|
-
'@typescript-eslint/prefer-includes': ['error'],
|
|
167
|
-
'@typescript-eslint/prefer-nullish-coalescing': ['error', { ignoreConditionalTests: false, ignoreMixedLogicalExpressions: false }],
|
|
168
|
-
'@typescript-eslint/prefer-optional-chain': ['error'],
|
|
169
|
-
'@typescript-eslint/prefer-promise-reject-errors': ['error'],
|
|
170
|
-
'@typescript-eslint/prefer-readonly': ['error'],
|
|
171
|
-
'@typescript-eslint/prefer-reduce-type-parameter': ['error'],
|
|
172
|
-
'@typescript-eslint/prefer-return-this-type': ['error'],
|
|
173
|
-
'@typescript-eslint/prefer-ts-expect-error': ['error'],
|
|
174
|
-
'@typescript-eslint/promise-function-async': ['error'],
|
|
175
|
-
'@typescript-eslint/quotes': ['error', 'single', { avoidEscape: true, allowTemplateLiterals: false }],
|
|
176
|
-
'@typescript-eslint/require-array-sort-compare': ['error', { ignoreStringArrays: true }],
|
|
177
|
-
'@typescript-eslint/restrict-plus-operands': ['error', { skipCompoundAssignments: false }],
|
|
178
|
-
'@typescript-eslint/restrict-template-expressions': ['error', { allowNumber: true }],
|
|
179
|
-
'@typescript-eslint/return-await': ['error', 'always'],
|
|
180
|
-
'@typescript-eslint/semi': ['error', 'never'],
|
|
181
|
-
'@typescript-eslint/space-before-blocks': ['error', 'always'],
|
|
182
|
-
'@typescript-eslint/space-before-function-paren': ['error', 'always'],
|
|
183
|
-
'@typescript-eslint/space-infix-ops': ['error'],
|
|
184
|
-
'@typescript-eslint/strict-boolean-expressions': ['error', {
|
|
185
|
-
allowString: false,
|
|
186
|
-
allowNumber: false,
|
|
187
|
-
allowNullableObject: false,
|
|
188
|
-
allowNullableBoolean: false,
|
|
189
|
-
allowNullableString: false,
|
|
190
|
-
allowNullableNumber: false,
|
|
191
|
-
allowAny: false
|
|
192
|
-
}],
|
|
193
|
-
'@typescript-eslint/triple-slash-reference': ['error', { lib: 'never', path: 'never', types: 'never' }],
|
|
194
|
-
'@typescript-eslint/type-annotation-spacing': ['error'],
|
|
195
|
-
'@typescript-eslint/unbound-method': ['error', { ignoreStatic: false }],
|
|
196
|
-
|
|
197
|
-
'accessor-pairs': ['error', { setWithoutGet: true, getWithoutSet: false, enforceForClassMembers: true }],
|
|
198
|
-
'array-bracket-spacing': ['error', 'never'],
|
|
199
|
-
'array-callback-return': ['error', {
|
|
200
|
-
allowImplicit: false,
|
|
201
|
-
allowVoid: false,
|
|
202
|
-
checkForEach: false
|
|
203
|
-
}],
|
|
204
|
-
'arrow-spacing': ['error', { before: true, after: true }],
|
|
205
|
-
'comma-style': ['error', 'last'],
|
|
206
|
-
'computed-property-spacing': ['error', 'never', { enforceForClassMembers: true }],
|
|
207
|
-
'constructor-super': ['error'],
|
|
208
|
-
curly: ['error', 'multi-line'],
|
|
209
|
-
'default-case-last': ['error'],
|
|
210
|
-
'dot-location': ['error', 'property'],
|
|
211
|
-
'eol-last': ['error'],
|
|
212
|
-
eqeqeq: ['error', 'always', { null: 'ignore' }],
|
|
213
|
-
'generator-star-spacing': ['error', { before: true, after: true }],
|
|
214
|
-
'multiline-ternary': ['error', 'always-multiline'],
|
|
215
|
-
'new-cap': ['error', { newIsCap: true, capIsNew: false, properties: true }],
|
|
216
|
-
'new-parens': ['error'],
|
|
217
|
-
'no-async-promise-executor': ['error'],
|
|
218
|
-
'no-caller': ['error'],
|
|
219
|
-
'no-case-declarations': ['error'],
|
|
220
|
-
'no-class-assign': ['error'],
|
|
221
|
-
'no-compare-neg-zero': ['error'],
|
|
222
|
-
'no-cond-assign': ['error'],
|
|
223
|
-
'no-const-assign': ['error'],
|
|
224
|
-
'no-constant-condition': ['error', { checkLoops: false }],
|
|
225
|
-
'no-control-regex': ['error'],
|
|
226
|
-
'no-debugger': ['error'],
|
|
227
|
-
'no-delete-var': ['error'],
|
|
228
|
-
'no-dupe-args': ['error'],
|
|
229
|
-
'no-dupe-keys': ['error'],
|
|
230
|
-
'no-duplicate-case': ['error'],
|
|
231
|
-
'no-useless-backreference': ['error'],
|
|
232
|
-
'no-empty': ['error', { allowEmptyCatch: true }],
|
|
233
|
-
'no-empty-character-class': ['error'],
|
|
234
|
-
'no-empty-pattern': ['error'],
|
|
235
|
-
'no-eval': ['error'],
|
|
236
|
-
'no-ex-assign': ['error'],
|
|
237
|
-
'no-extend-native': ['error'],
|
|
238
|
-
'no-extra-bind': ['error'],
|
|
239
|
-
'no-extra-boolean-cast': ['error'],
|
|
240
|
-
'no-fallthrough': ['error'],
|
|
241
|
-
'no-floating-decimal': ['error'],
|
|
242
|
-
'no-func-assign': ['error'],
|
|
243
|
-
'no-global-assign': ['error'],
|
|
244
|
-
'no-import-assign': ['error'],
|
|
245
|
-
'no-invalid-regexp': ['error'],
|
|
246
|
-
'no-irregular-whitespace': ['error'],
|
|
247
|
-
'no-iterator': ['error'],
|
|
248
|
-
'no-labels': ['error', { allowLoop: false, allowSwitch: false }],
|
|
249
|
-
'no-lone-blocks': ['error'],
|
|
250
|
-
'no-misleading-character-class': ['error'],
|
|
251
|
-
'no-prototype-builtins': ['error'],
|
|
252
|
-
'no-useless-catch': ['error'],
|
|
253
|
-
'no-mixed-operators': ['error', {
|
|
254
|
-
groups: [
|
|
255
|
-
['==', '!=', '===', '!==', '>', '>=', '<', '<='],
|
|
256
|
-
['&&', '||'],
|
|
257
|
-
['in', 'instanceof']
|
|
258
|
-
],
|
|
259
|
-
allowSamePrecedence: true
|
|
260
|
-
}],
|
|
261
|
-
'no-mixed-spaces-and-tabs': ['error'],
|
|
262
|
-
'no-multi-spaces': ['error'],
|
|
263
|
-
'no-multi-str': ['error'],
|
|
264
|
-
'no-multiple-empty-lines': ['error', { max: 1, maxBOF: 0, maxEOF: 0 }],
|
|
265
|
-
'no-new': ['error'],
|
|
266
|
-
'no-new-func': ['error'],
|
|
267
|
-
'no-new-object': ['error'],
|
|
268
|
-
'no-new-symbol': ['error'],
|
|
269
|
-
'no-new-wrappers': ['error'],
|
|
270
|
-
'no-obj-calls': ['error'],
|
|
271
|
-
'no-octal': ['error'],
|
|
272
|
-
'no-octal-escape': ['error'],
|
|
273
|
-
'no-proto': ['error'],
|
|
274
|
-
'no-regex-spaces': ['error'],
|
|
275
|
-
'no-return-assign': ['error', 'except-parens'],
|
|
276
|
-
'no-self-assign': ['error', { props: true }],
|
|
277
|
-
'no-self-compare': ['error'],
|
|
278
|
-
'no-sequences': ['error'],
|
|
279
|
-
'no-shadow-restricted-names': ['error'],
|
|
280
|
-
'no-sparse-arrays': ['error'],
|
|
281
|
-
'no-tabs': ['error'],
|
|
282
|
-
'no-template-curly-in-string': ['error'],
|
|
283
|
-
'no-this-before-super': ['error'],
|
|
284
|
-
'no-trailing-spaces': ['error'],
|
|
285
|
-
'no-undef-init': ['error'],
|
|
286
|
-
'no-unexpected-multiline': ['error'],
|
|
287
|
-
'no-unmodified-loop-condition': ['error'],
|
|
288
|
-
'no-unneeded-ternary': ['error', { defaultAssignment: false }],
|
|
289
|
-
'no-unreachable': ['error'],
|
|
290
|
-
'no-unreachable-loop': ['error'],
|
|
291
|
-
'no-unsafe-finally': ['error'],
|
|
292
|
-
'no-unsafe-negation': ['error'],
|
|
293
|
-
'no-useless-call': ['error'],
|
|
294
|
-
'no-useless-computed-key': ['error'],
|
|
295
|
-
'no-useless-escape': ['error'],
|
|
296
|
-
'no-useless-rename': ['error'],
|
|
297
|
-
'no-useless-return': ['error'],
|
|
298
|
-
'no-var': ['warn'],
|
|
299
|
-
'no-void': ['error', { allowAsStatement: true }],
|
|
300
|
-
'no-whitespace-before-property': ['error'],
|
|
301
|
-
'no-with': ['error'],
|
|
302
|
-
'object-curly-newline': ['error', { multiline: true, consistent: true }],
|
|
303
|
-
'object-property-newline': ['error', { allowMultiplePropertiesPerLine: true, allowAllPropertiesOnSameLine: false }],
|
|
304
|
-
'object-shorthand': ['warn', 'properties'],
|
|
305
|
-
'one-var': ['error', { initialized: 'never' }],
|
|
306
|
-
'operator-linebreak': ['error', 'after', { overrides: { '?': 'before', ':': 'before', '|>': 'before' } }],
|
|
307
|
-
'padded-blocks': ['error', { blocks: 'never', switches: 'never', classes: 'never' }],
|
|
308
|
-
'prefer-const': ['error', { destructuring: 'all', ignoreReadBeforeAssign: false }],
|
|
309
|
-
'prefer-regex-literals': ['error', { disallowRedundantWrapping: true }],
|
|
310
|
-
'quote-props': ['error', 'as-needed'],
|
|
311
|
-
'rest-spread-spacing': ['error', 'never'],
|
|
312
|
-
'semi-spacing': ['error', { before: false, after: true }],
|
|
313
|
-
'space-in-parens': ['error', 'never'],
|
|
314
|
-
'space-unary-ops': ['error', { words: true, nonwords: false }],
|
|
315
|
-
'spaced-comment': ['error', 'always', {
|
|
316
|
-
line: { markers: ['*package', '!', '/', ',', '='] },
|
|
317
|
-
block: { balanced: true, markers: ['*package', '!', ',', ':', '::', 'flow-include'], exceptions: ['*'] }
|
|
318
|
-
}],
|
|
319
|
-
'symbol-description': ['error'],
|
|
320
|
-
'template-curly-spacing': ['error', 'never'],
|
|
321
|
-
'template-tag-spacing': ['error', 'never'],
|
|
322
|
-
'unicode-bom': ['error', 'never'],
|
|
323
|
-
'use-isnan': ['error', {
|
|
324
|
-
enforceForSwitchCase: true,
|
|
325
|
-
enforceForIndexOf: true
|
|
326
|
-
}],
|
|
327
|
-
'valid-typeof': ['error', { requireStringLiterals: true }],
|
|
328
|
-
'wrap-iife': ['error', 'any', { functionPrototypeMethods: true }],
|
|
329
|
-
'yield-star-spacing': ['error', 'both'],
|
|
330
|
-
yoda: ['error', 'never'],
|
|
331
|
-
|
|
332
|
-
'import/export': ['error'],
|
|
333
|
-
'import/first': ['error'],
|
|
334
|
-
'import/no-absolute-path': ['error', { esmodule: true, commonjs: true, amd: false }],
|
|
335
|
-
'import/no-duplicates': ['error'],
|
|
336
|
-
'import/no-named-default': ['error'],
|
|
337
|
-
'import/no-webpack-loader-syntax': ['error'],
|
|
338
|
-
|
|
339
|
-
'n/handle-callback-err': ['error', '^(err|error)$'],
|
|
340
|
-
'n/no-callback-literal': ['error'],
|
|
341
|
-
'n/no-deprecated-api': ['error'],
|
|
342
|
-
'n/no-exports-assign': ['error'],
|
|
343
|
-
'n/no-new-require': ['error'],
|
|
344
|
-
'n/no-path-concat': ['error'],
|
|
345
|
-
'n/process-exit-as-throw': ['error'],
|
|
346
|
-
|
|
347
|
-
'promise/param-names': ['error']
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
const config = {
|
|
351
|
-
plugins: [
|
|
352
|
-
'@typescript-eslint',
|
|
353
|
-
'import',
|
|
354
|
-
'n',
|
|
355
|
-
'promise'
|
|
356
|
-
],
|
|
357
|
-
parser: '@typescript-eslint/parser',
|
|
358
|
-
parserOptions: {
|
|
359
|
-
project: true
|
|
360
|
-
},
|
|
361
|
-
rules: {
|
|
362
|
-
...rules
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
module.exports = config;
|
package/.eslintrc.json
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"env": {
|
|
3
|
-
"es2021": true,
|
|
4
|
-
"node": true
|
|
5
|
-
},
|
|
6
|
-
"extends": [
|
|
7
|
-
"./.eslintrc-love-temp.cjs",
|
|
8
|
-
"prettier"
|
|
9
|
-
],
|
|
10
|
-
"overrides": [],
|
|
11
|
-
"parserOptions": {
|
|
12
|
-
"ecmaVersion": "latest",
|
|
13
|
-
"sourceType": "module",
|
|
14
|
-
"project": "tsconfig.json"
|
|
15
|
-
},
|
|
16
|
-
"rules": {}
|
|
17
|
-
}
|
package/dist/cjs/index.js
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.Redis = void 0;
|
|
7
|
-
const ioredis_1 = __importDefault(require("ioredis"));
|
|
8
|
-
const uuid_1 = require("uuid");
|
|
9
|
-
class Redis {
|
|
10
|
-
constructor(config) {
|
|
11
|
-
this.config = config;
|
|
12
|
-
this.redis = undefined;
|
|
13
|
-
}
|
|
14
|
-
get keyProp() {
|
|
15
|
-
var _a;
|
|
16
|
-
return (_a = this.config.keyProp) !== null && _a !== void 0 ? _a : "_id";
|
|
17
|
-
}
|
|
18
|
-
get expireSeconds() {
|
|
19
|
-
return this.config.expireSeconds;
|
|
20
|
-
}
|
|
21
|
-
getRedis() {
|
|
22
|
-
var _a;
|
|
23
|
-
this.redis = (_a = this.redis) !== null && _a !== void 0 ? _a : new ioredis_1.default(this.config.options);
|
|
24
|
-
return this.redis;
|
|
25
|
-
}
|
|
26
|
-
async getKeys() {
|
|
27
|
-
var _a, _b, _c;
|
|
28
|
-
const keyFilter = `${(_c = (_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.options) === null || _b === void 0 ? void 0 : _b.keyPrefix) !== null && _c !== void 0 ? _c : ""}*`;
|
|
29
|
-
const sliceKey = (s) => { var _a, _b, _c, _d; return s.slice((_d = (_c = (_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.options) === null || _b === void 0 ? void 0 : _b.keyPrefix) === null || _c === void 0 ? void 0 : _c.length) !== null && _d !== void 0 ? _d : 0); };
|
|
30
|
-
return await this.getRedis()
|
|
31
|
-
.keys(keyFilter)
|
|
32
|
-
.then((keys) => keys.map(sliceKey));
|
|
33
|
-
}
|
|
34
|
-
async get(key) {
|
|
35
|
-
return await this.getRedis()
|
|
36
|
-
.get(key)
|
|
37
|
-
.then((value) => {
|
|
38
|
-
if (value == null) {
|
|
39
|
-
return undefined;
|
|
40
|
-
}
|
|
41
|
-
return JSON.parse(value);
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
async set(value) {
|
|
45
|
-
const redis = this.getRedis();
|
|
46
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
47
|
-
const savingObj = {
|
|
48
|
-
[this.keyProp]: (0, uuid_1.v4)(),
|
|
49
|
-
...value,
|
|
50
|
-
};
|
|
51
|
-
// @ts-expect-error prop name
|
|
52
|
-
const key = savingObj[this.keyProp];
|
|
53
|
-
return this.expireSeconds !== undefined
|
|
54
|
-
? await redis
|
|
55
|
-
.set(key, JSON.stringify(savingObj), "EX", this.expireSeconds)
|
|
56
|
-
.then(() => savingObj)
|
|
57
|
-
: await redis.set(key, JSON.stringify(savingObj)).then(() => savingObj);
|
|
58
|
-
}
|
|
59
|
-
async del(key) {
|
|
60
|
-
return await this.getRedis().del(key);
|
|
61
|
-
}
|
|
62
|
-
disconnect() {
|
|
63
|
-
this.getRedis().disconnect();
|
|
64
|
-
this.redis = undefined;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
exports.Redis = Redis;
|
package/dist/esm/index.js
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
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) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import IORedis from "ioredis";
|
|
11
|
-
import { v4 as uuid } from "uuid";
|
|
12
|
-
export class Redis {
|
|
13
|
-
constructor(config) {
|
|
14
|
-
this.config = config;
|
|
15
|
-
this.redis = undefined;
|
|
16
|
-
}
|
|
17
|
-
get keyProp() {
|
|
18
|
-
var _a;
|
|
19
|
-
return (_a = this.config.keyProp) !== null && _a !== void 0 ? _a : "_id";
|
|
20
|
-
}
|
|
21
|
-
get expireSeconds() {
|
|
22
|
-
return this.config.expireSeconds;
|
|
23
|
-
}
|
|
24
|
-
getRedis() {
|
|
25
|
-
var _a;
|
|
26
|
-
this.redis = (_a = this.redis) !== null && _a !== void 0 ? _a : new IORedis(this.config.options);
|
|
27
|
-
return this.redis;
|
|
28
|
-
}
|
|
29
|
-
getKeys() {
|
|
30
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
-
var _a, _b, _c;
|
|
32
|
-
const keyFilter = `${(_c = (_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.options) === null || _b === void 0 ? void 0 : _b.keyPrefix) !== null && _c !== void 0 ? _c : ""}*`;
|
|
33
|
-
const sliceKey = (s) => { var _a, _b, _c, _d; return s.slice((_d = (_c = (_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.options) === null || _b === void 0 ? void 0 : _b.keyPrefix) === null || _c === void 0 ? void 0 : _c.length) !== null && _d !== void 0 ? _d : 0); };
|
|
34
|
-
return yield this.getRedis()
|
|
35
|
-
.keys(keyFilter)
|
|
36
|
-
.then((keys) => keys.map(sliceKey));
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
get(key) {
|
|
40
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
-
return yield this.getRedis()
|
|
42
|
-
.get(key)
|
|
43
|
-
.then((value) => {
|
|
44
|
-
if (value == null) {
|
|
45
|
-
return undefined;
|
|
46
|
-
}
|
|
47
|
-
return JSON.parse(value);
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
set(value) {
|
|
52
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
53
|
-
const redis = this.getRedis();
|
|
54
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
55
|
-
const savingObj = Object.assign({ [this.keyProp]: uuid() }, value);
|
|
56
|
-
// @ts-expect-error prop name
|
|
57
|
-
const key = savingObj[this.keyProp];
|
|
58
|
-
return this.expireSeconds !== undefined
|
|
59
|
-
? yield redis
|
|
60
|
-
.set(key, JSON.stringify(savingObj), "EX", this.expireSeconds)
|
|
61
|
-
.then(() => savingObj)
|
|
62
|
-
: yield redis.set(key, JSON.stringify(savingObj)).then(() => savingObj);
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
del(key) {
|
|
66
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
67
|
-
return yield this.getRedis().del(key);
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
disconnect() {
|
|
71
|
-
this.getRedis().disconnect();
|
|
72
|
-
this.redis = undefined;
|
|
73
|
-
}
|
|
74
|
-
}
|
package/tryit/addArticle.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { clients } from "./common";
|
|
2
|
-
|
|
3
|
-
(async () => {
|
|
4
|
-
console.log(
|
|
5
|
-
await clients.articleRedis.set({
|
|
6
|
-
title: "john's article",
|
|
7
|
-
body: "body",
|
|
8
|
-
author: "john@test.test",
|
|
9
|
-
})
|
|
10
|
-
);
|
|
11
|
-
})()
|
|
12
|
-
.then(() => process.exit())
|
|
13
|
-
.catch(() => process.exit());
|
package/tryit/addUser.ts
DELETED
package/tryit/common.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { Redis } from "../src/";
|
|
2
|
-
|
|
3
|
-
interface User {
|
|
4
|
-
email: string;
|
|
5
|
-
name: string;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
interface Article {
|
|
9
|
-
_id: string;
|
|
10
|
-
author: string;
|
|
11
|
-
title: string;
|
|
12
|
-
body: string;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export const clients = {
|
|
16
|
-
userRedis: new Redis<User>({
|
|
17
|
-
keyProp: "email",
|
|
18
|
-
options: {
|
|
19
|
-
port: 6379,
|
|
20
|
-
host: "localhost",
|
|
21
|
-
keyPrefix: "user",
|
|
22
|
-
},
|
|
23
|
-
}),
|
|
24
|
-
articleRedis: new Redis<Article>({
|
|
25
|
-
options: {
|
|
26
|
-
port: 6379,
|
|
27
|
-
host: "localhost",
|
|
28
|
-
keyPrefix: "article",
|
|
29
|
-
},
|
|
30
|
-
}),
|
|
31
|
-
};
|
package/tryit/delArticle.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { clients } from "./common";
|
|
2
|
-
|
|
3
|
-
(async () => {
|
|
4
|
-
const beforeKeys = await clients.articleRedis.getKeys();
|
|
5
|
-
|
|
6
|
-
const [ key, ...rest ] = beforeKeys;
|
|
7
|
-
|
|
8
|
-
console.log(
|
|
9
|
-
await clients.articleRedis.del(key)
|
|
10
|
-
);
|
|
11
|
-
|
|
12
|
-
const afterKeys = await clients.articleRedis.getKeys();
|
|
13
|
-
console.log({
|
|
14
|
-
beforeKeyCount: beforeKeys.length,
|
|
15
|
-
afterKeyCount: afterKeys.length,
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
})()
|
|
19
|
-
.then(() => process.exit())
|
|
20
|
-
.catch(() => process.exit());
|
package/tryit/delUser.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { clients } from "./common";
|
|
2
|
-
|
|
3
|
-
(async () => {
|
|
4
|
-
const beforeKeys = await clients.userRedis.getKeys();
|
|
5
|
-
|
|
6
|
-
const [ key, ...rest ] = beforeKeys;
|
|
7
|
-
|
|
8
|
-
console.log(
|
|
9
|
-
await clients.userRedis.del(key)
|
|
10
|
-
);
|
|
11
|
-
|
|
12
|
-
const afterKeys = await clients.userRedis.getKeys();
|
|
13
|
-
console.log({
|
|
14
|
-
beforeKeyCount: beforeKeys.length,
|
|
15
|
-
afterKeyCount: afterKeys.length,
|
|
16
|
-
});
|
|
17
|
-
})()
|
|
18
|
-
.then(() => process.exit())
|
|
19
|
-
.catch(() => process.exit());
|
package/tryit/getArticles.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { clients } from "./common";
|
|
2
|
-
|
|
3
|
-
(async () => {
|
|
4
|
-
const keys = await clients.articleRedis.getKeys();
|
|
5
|
-
|
|
6
|
-
for(const key of keys) {
|
|
7
|
-
console.log(
|
|
8
|
-
await clients.articleRedis.get(key)
|
|
9
|
-
);
|
|
10
|
-
}
|
|
11
|
-
})()
|
|
12
|
-
.then(() => process.exit())
|
|
13
|
-
.catch(() => process.exit());
|
package/tryit/getUsers.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { clients } from "./common";
|
|
2
|
-
|
|
3
|
-
(async () => {
|
|
4
|
-
const keys = await clients.userRedis.getKeys();
|
|
5
|
-
|
|
6
|
-
for(const key of keys) {
|
|
7
|
-
console.log(
|
|
8
|
-
await clients.userRedis.get(key)
|
|
9
|
-
);
|
|
10
|
-
}
|
|
11
|
-
})()
|
|
12
|
-
.then(() => process.exit())
|
|
13
|
-
.catch(() => process.exit());
|
|
14
|
-
|
package/tryit/seed.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { clients } from "./common";
|
|
2
|
-
|
|
3
|
-
const users = [
|
|
4
|
-
"alice",
|
|
5
|
-
"bob",
|
|
6
|
-
"charlie",
|
|
7
|
-
]
|
|
8
|
-
.map(name => ({
|
|
9
|
-
name,
|
|
10
|
-
email: `${name}@test.test`,
|
|
11
|
-
}));
|
|
12
|
-
|
|
13
|
-
const articles = users.map(user => ({
|
|
14
|
-
title: `${user.name}'s article`,
|
|
15
|
-
body: "some body",
|
|
16
|
-
author: user.email,
|
|
17
|
-
}));
|
|
18
|
-
|
|
19
|
-
(async () => {
|
|
20
|
-
for(const user of users){
|
|
21
|
-
await clients.userRedis.set(user);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
for(const article of articles){
|
|
25
|
-
await clients.articleRedis.set(article);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
})()
|
|
29
|
-
.then(() => {
|
|
30
|
-
process.exit();
|
|
31
|
-
})
|
|
32
|
-
.catch((e) => {
|
|
33
|
-
console.log(e);
|
|
34
|
-
process.exit();
|
|
35
|
-
});
|