koatty_store 1.4.8 → 1.5.4

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/.eslintrc.js CHANGED
@@ -22,12 +22,13 @@ module.exports = {
22
22
  },
23
23
  rules: {
24
24
  "@typescript-eslint/no-explicit-any": "off",
25
- "@typescript-eslint/no-require-imports": "off",
25
+ // "@typescript-eslint/no-require-imports": "off",
26
26
  "@typescript-eslint/no-var-requires": "off",
27
27
  "@typescript-eslint/member-ordering": "off",
28
28
  "@typescript-eslint/consistent-type-assertions": "off",
29
29
  "@typescript-eslint/no-param-reassign": "off",
30
30
  "@typescript-eslint/no-empty-function": "off",
31
+ "@typescript-eslint/no-empty-interface": "off",
31
32
  "@typescript-eslint/explicit-module-boundary-types": "off",
32
33
  "@typescript-eslint/ban-types": ["error",
33
34
  {
@@ -0,0 +1,25 @@
1
+ {
2
+ // 使用 IntelliSense 了解相关属性。
3
+ // 悬停以查看现有属性的描述。
4
+ // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
5
+ "version": "0.2.0",
6
+ "configurations": [
7
+ {
8
+ "name": "Launch Typescript Project",
9
+ "type": "node",
10
+ "request": "launch",
11
+ "args": [
12
+ "${workspaceRoot}/test/test.ts"
13
+ ],
14
+ "runtimeArgs": [
15
+ "--nolazy",
16
+ "-r",
17
+ "ts-node/register"
18
+ ],
19
+ "sourceMaps": true,
20
+ "cwd": "${workspaceRoot}",
21
+ "protocol": "inspector",
22
+ "internalConsoleOptions": "neverOpen"
23
+ }
24
+ ]
25
+ }
package/CHANGELOG.md CHANGED
@@ -2,12 +2,8 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
- ### [1.4.8](https://github.com/koatty/koatty_store/compare/v1.4.6...v1.4.8) (2021-07-01)
5
+ ### [1.5.4](https://github.com/koatty/koatty_store/compare/v1.5.2...v1.5.4) (2021-12-02)
6
6
 
7
- ### [1.4.6](https://github.com/koatty/koatty_store/compare/v1.4.2...v1.4.6) (2021-06-30)
7
+ ### [1.5.2](https://github.com/koatty/koatty_store/compare/v1.4.10...v1.5.2) (2021-12-02)
8
8
 
9
- ### [1.4.2](https://github.com/koatty/koatty_store/compare/v1.3.3...v1.4.2) (2021-06-30)
10
-
11
- ### [1.3.3](https://github.com/koatty/koatty_store/compare/v1.3.2...v1.3.3) (2021-06-30)
12
-
13
- ### 1.3.2 (2021-06-23)
9
+ ### [1.4.10](https://github.com/koatty/koatty_store/compare/v1.4.8...v1.4.10) (2021-11-20)
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  BSD 3-Clause License
2
2
 
3
- Copyright (c) 2020, ThinkKoa
3
+ Copyright (c) 2020, Koatty
4
4
  All rights reserved.
5
5
 
6
6
  Redistribution and use in source and binary forms, with or without
package/babel.config.js CHANGED
@@ -1,11 +1,6 @@
1
1
  /*
2
2
  * @Description : babel配置
3
3
  * @usage : 用于jest执行用例
4
- * @Date : 2020-10-19 23:08:40
5
- * @Author : fankerwang<fankerwang@tencent.com>
6
- * @LastEditors : fankerwang<fankerwang@tencent.com>
7
- * @LastEditTime : 2021-05-21 20:27:11
8
- * @FilePath : /tkoatty/babel.config.js
9
4
  */
10
5
 
11
6
  module.exports = {
package/dist/index.d.ts CHANGED
@@ -1,7 +1,6 @@
1
- import { MemoryStore } from "./memory";
2
- import { RedisStore } from "./redis";
3
- export { RedisStore, RedisStoreOptions } from "./redis";
4
- export { MemoryStore, MemoryStoreOptions } from "./memory";
1
+ import { CacheStore } from "./store";
2
+ export { MemoryStore } from "./store/memory";
3
+ export { CacheStore } from "./store";
5
4
  /**
6
5
  *
7
6
  *
@@ -9,34 +8,27 @@ export { MemoryStore, MemoryStoreOptions } from "./memory";
9
8
  * @interface StoreOptions
10
9
  */
11
10
  export interface StoreOptions {
12
- type: string;
13
- key_prefix: string;
14
- host: string | Array<string>;
11
+ type?: string;
12
+ keyPrefix?: string;
13
+ host?: string | Array<string>;
15
14
  port?: number | Array<number>;
16
- name?: string;
17
15
  username?: string;
18
16
  password?: string;
19
17
  db?: number;
20
18
  timeout?: number;
21
- pool_size?: number;
22
- conn_timeout?: number;
23
- }
24
- /**
25
- * CacheStore interface
26
- *
27
- * @export
28
- * @interface CacheStore
29
- */
30
- export interface CacheStore {
31
- client: any;
32
- getConnection(): any;
33
- close(): Promise<void>;
34
- release(conn: any): Promise<void>;
35
- get(name: string): Promise<any>;
36
- set(name: string, value: string | number, timeout?: number): Promise<any>;
37
- del(name: string): Promise<any>;
38
- defineCommand(name: string, scripts: any): any;
39
- getCompare(name: string, value: string | number): Promise<any>;
19
+ poolSize?: number;
20
+ connectTimeout?: number;
21
+ name?: string;
22
+ sentinelUsername?: string;
23
+ sentinelPassword?: string;
24
+ sentinels?: Array<{
25
+ host: string;
26
+ port: number;
27
+ }>;
28
+ clusters?: Array<{
29
+ host: string;
30
+ port: number;
31
+ }>;
40
32
  }
41
33
  /**
42
34
  *
@@ -53,5 +45,5 @@ export declare class Store {
53
45
  * @returns
54
46
  * @memberof ValidateUtil
55
47
  */
56
- static getInstance(options: StoreOptions): MemoryStore | RedisStore;
48
+ static getInstance(options: StoreOptions): CacheStore;
57
49
  }
package/dist/index.js CHANGED
@@ -1,20 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Store = exports.MemoryStore = exports.RedisStore = void 0;
4
- /*
5
- * @Author: richen
6
- * @Date: 2020-11-30 11:48:12
7
- * @LastEditors: Please set LastEditors
8
- * @LastEditTime: 2021-07-01 11:03:36
9
- * @License: BSD (3-Clause)
10
- * @Copyright (c) - <richenlin(at)gmail.com>
11
- */
12
- const memory_1 = require("./memory");
13
- const redis_1 = require("./redis");
14
- var redis_2 = require("./redis");
15
- Object.defineProperty(exports, "RedisStore", { enumerable: true, get: function () { return redis_2.RedisStore; } });
16
- var memory_2 = require("./memory");
3
+ exports.Store = exports.CacheStore = exports.MemoryStore = void 0;
4
+ const memory_1 = require("./store/memory");
5
+ const redis_1 = require("./store/redis");
6
+ var memory_2 = require("./store/memory");
17
7
  Object.defineProperty(exports, "MemoryStore", { enumerable: true, get: function () { return memory_2.MemoryStore; } });
8
+ // export
9
+ var store_1 = require("./store");
10
+ Object.defineProperty(exports, "CacheStore", { enumerable: true, get: function () { return store_1.CacheStore; } });
18
11
  /**
19
12
  *
20
13
  *
@@ -36,12 +29,13 @@ class Store {
36
29
  options = {
37
30
  ...{
38
31
  type: 'memory',
39
- host: '127.0.0.1',
40
- port: 3306,
41
- key_prefix: 'Koatty',
42
- timeout: 21600,
43
- pool_size: 10,
44
- conn_timeout: 500,
32
+ host: '',
33
+ port: 0,
34
+ keyPrefix: 'Koatty',
35
+ timeout: 600,
36
+ poolSize: 10,
37
+ connectTimeout: 500,
38
+ db: 0
45
39
  }, ...options
46
40
  };
47
41
  switch (options.type) {
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA;;;;;;;GAOG;AACH,qCAAuC;AACvC,mCAAqC;AACrC,iCAAwD;AAA/C,mGAAA,UAAU,OAAA;AACnB,mCAA2D;AAAlD,qGAAA,WAAW,OAAA;AA0CpB;;;;;GAKG;AACH,MAAa,KAAK;IAGd;;;;;;OAMG;IACH,MAAM,CAAC,WAAW,CAAC,OAAqB;QACpC,IAAI,IAAI,CAAC,QAAQ,EAAE;YACf,OAAO,IAAI,CAAC,QAAQ,CAAC;SACxB;QACD,OAAO,GAAG;YACN,GAAG;gBACC,IAAI,EAAE,QAAQ;gBACd,IAAI,EAAE,WAAW;gBACjB,IAAI,EAAE,IAAI;gBACV,UAAU,EAAE,QAAQ;gBACpB,OAAO,EAAE,KAAK;gBACd,SAAS,EAAE,EAAE;gBACb,YAAY,EAAE,GAAG;aACpB,EAAE,GAAG,OAAO;SAChB,CAAC;QACF,QAAQ,OAAO,CAAC,IAAI,EAA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
@@ -1,17 +1,10 @@
1
- import { CacheStore, StoreOptions } from ".";
2
- /**
3
- * MemoryStore Options
4
- *
5
- * @export
6
- * @interface MemoryStoreOptions
7
- */
8
- export interface MemoryStoreOptions {
9
- timeout?: number;
10
- }
11
- export declare class MemoryStore implements CacheStore {
1
+ import { CacheStore } from "../store";
2
+ import { StoreOptions } from "../index";
3
+ import { MemoryCache } from "./memory_cache";
4
+ export declare class MemoryStore extends CacheStore {
12
5
  client: any;
13
- private options;
14
- private pool;
6
+ pool: any;
7
+ options: StoreOptions;
15
8
  /**
16
9
  * Creates an instance of MemoryStore.
17
10
  * @param {StoreOptions} options
@@ -24,7 +17,7 @@ export declare class MemoryStore implements CacheStore {
24
17
  * @returns {*}
25
18
  * @memberof MemoryStore
26
19
  */
27
- getConnection(): any;
20
+ getConnection(): MemoryCache;
28
21
  /**
29
22
  * close
30
23
  *
@@ -47,7 +40,7 @@ export declare class MemoryStore implements CacheStore {
47
40
  * @param {*} scripts
48
41
  * @memberof MemoryStore
49
42
  */
50
- defineCommand(name: string, scripts: any): Promise<any>;
43
+ defineCommand(name: string, scripts: any): Promise<void>;
51
44
  /**
52
45
  * get and compare value
53
46
  *
@@ -57,30 +50,4 @@ export declare class MemoryStore implements CacheStore {
57
50
  * @memberof MemoryStore
58
51
  */
59
52
  getCompare(name: string, value: string | number): Promise<any>;
60
- /**
61
- * get
62
- *
63
- * @param {string} name
64
- * @returns {*} {Promise<any>}
65
- * @memberof MemoryStore
66
- */
67
- get(name: string): Promise<any>;
68
- /**
69
- * set
70
- *
71
- * @param {string} name
72
- * @param {(string | number)} value
73
- * @param {number} [timeout]
74
- * @returns {*} {Promise<any>}
75
- * @memberof MemoryStore
76
- */
77
- set(name: string, value: string | number, timeout?: number): Promise<any>;
78
- /**
79
- * del
80
- *
81
- * @param {string} name
82
- * @returns {*}
83
- * @memberof MemoryStore
84
- */
85
- del(name: string): any;
86
53
  }
@@ -1,23 +1,24 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MemoryStore = void 0;
4
- const tslib_1 = require("tslib");
5
- const helper = tslib_1.__importStar(require("koatty_lib"));
6
- const MemoryCache = require('@outofsync/memory-cache');
4
+ const store_1 = require("../store");
5
+ const memory_cache_1 = require("./memory_cache");
6
+ // const MemoryCache = require('@outofsync/memory-cache');
7
7
  /*
8
8
  * @Description:
9
9
  * @Usage:
10
10
  * @Author: richen
11
11
  * @Date: 2021-06-29 19:07:57
12
- * @LastEditTime: 2021-06-29 19:45:25
12
+ * @LastEditTime: 2021-12-02 15:30:12
13
13
  */
14
- class MemoryStore {
14
+ class MemoryStore extends store_1.CacheStore {
15
15
  /**
16
16
  * Creates an instance of MemoryStore.
17
17
  * @param {StoreOptions} options
18
18
  * @memberof MemoryStore
19
19
  */
20
20
  constructor(options) {
21
+ super(options);
21
22
  this.options = options;
22
23
  this.client = null;
23
24
  }
@@ -29,7 +30,9 @@ class MemoryStore {
29
30
  */
30
31
  getConnection() {
31
32
  if (!this.pool) {
32
- this.pool = new MemoryCache({ bypassUnsupported: true });
33
+ this.pool = new memory_cache_1.MemoryCache({
34
+ database: this.options.db
35
+ });
33
36
  }
34
37
  if (!this.client) {
35
38
  this.client = this.pool.createClient();
@@ -65,16 +68,7 @@ class MemoryStore {
65
68
  * @memberof MemoryStore
66
69
  */
67
70
  async defineCommand(name, scripts) {
68
- const client = this.getConnection();
69
- Object.defineProperty(client, name, {
70
- value: async function () {
71
- return scripts;
72
- },
73
- writable: false,
74
- configurable: false,
75
- enumerable: true,
76
- });
77
- return client;
71
+ throw new Error(memory_cache_1.messages.unsupported);
78
72
  }
79
73
  /**
80
74
  * get and compare value
@@ -86,55 +80,17 @@ class MemoryStore {
86
80
  */
87
81
  async getCompare(name, value) {
88
82
  const client = this.getConnection();
89
- const val = client.get(name);
83
+ const val = client.get(`${this.options.keyPrefix}${name}`);
90
84
  if (!val) {
91
85
  return 0;
92
86
  }
93
87
  else if (val == value) {
94
- return client.del(name);
88
+ return client.del(`${this.options.keyPrefix}${name}`);
95
89
  }
96
90
  else {
97
91
  return -1;
98
92
  }
99
93
  }
100
- /**
101
- * get
102
- *
103
- * @param {string} name
104
- * @returns {*} {Promise<any>}
105
- * @memberof MemoryStore
106
- */
107
- get(name) {
108
- const client = this.getConnection();
109
- return client.getAsync(name);
110
- }
111
- /**
112
- * set
113
- *
114
- * @param {string} name
115
- * @param {(string | number)} value
116
- * @param {number} [timeout]
117
- * @returns {*} {Promise<any>}
118
- * @memberof MemoryStore
119
- */
120
- set(name, value, timeout) {
121
- const client = this.getConnection();
122
- if (helper.isTrueEmpty(timeout)) {
123
- timeout = this.options.timeout;
124
- }
125
- return client.setAsync(name, value, "ex", timeout);
126
- }
127
- /**
128
- * del
129
- *
130
- * @param {string} name
131
- * @returns {*}
132
- * @memberof MemoryStore
133
- */
134
- del(name) {
135
- const client = this.getConnection();
136
- return client.delAsync(name);
137
- }
138
94
  }
139
95
  exports.MemoryStore = MemoryStore;
140
96
  //# sourceMappingURL=memory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory.js","sourceRoot":"","sources":["../../src/store/memory.ts"],"names":[],"mappings":";;;AACA,oCAAsC;AAEtC,iDAAuD;AACvD,0DAA0D;AAE1D;;;;;;GAMG;AACH,MAAa,WAAY,SAAQ,kBAAU;IAKvC;;;;OAIG;IACH,YAAY,OAAqB;QAC7B,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;IACvB,CAAC;IAED;;;;;OAKG;IACH,aAAa;QACT,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE;YACZ,IAAI,CAAC,IAAI,GAAG,IAAI,0BAAW,CAAC;gBACxB,QAAQ,EAAE,IAAI,CAAC,OAAO,CAAC,EAAE;aAC5B,CAAC,CAAC;SACN;QACD,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE;YACd,IAAI,CAAC,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