@universis/janitor 1.2.0 → 1.3.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/RedisClientStore.js +31 -12
- package/dist/RedisClientStore.js.map +1 -1
- package/package.json +1 -1
- package/src/RedisClientStore.js +31 -12
package/dist/RedisClientStore.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.RedisClientStore = void 0;var _common = require("@themost/common");
|
|
2
2
|
var _rateLimitRedis = _interopRequireDefault(require("rate-limit-redis"));
|
|
3
|
-
var _redis = require("redis");
|
|
3
|
+
var _redis = require("redis");
|
|
4
|
+
require("@themost/promise-sequence");function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}function _defineProperty(obj, key, value) {key = _toPropertyKey(key);if (key in obj) {Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true });} else {obj[key] = value;}return obj;}function _toPropertyKey(arg) {var key = _toPrimitive(arg, "string");return typeof key === "symbol" ? key : String(key);}function _toPrimitive(input, hint) {if (typeof input !== "object" || input === null) return input;var prim = input[Symbol.toPrimitive];if (prim !== undefined) {var res = prim.call(input, hint || "default");if (typeof res !== "object") return res;throw new TypeError("@@toPrimitive must return a primitive value.");}return (hint === "string" ? String : Number)(input);}
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
let superLoadIncrementScript;
|
|
7
|
+
let superLoadGetScript;
|
|
7
8
|
|
|
8
9
|
function noLoadGetScript() {
|
|
9
10
|
|
|
@@ -13,11 +14,15 @@ function noLoadIncrementScript() {
|
|
|
13
14
|
|
|
14
15
|
//
|
|
15
16
|
}
|
|
16
|
-
if (
|
|
17
|
+
if (_rateLimitRedis.default.prototype.loadIncrementScript.name === 'loadIncrementScript') {
|
|
18
|
+
// get super method for future use
|
|
19
|
+
superLoadIncrementScript = _rateLimitRedis.default.prototype.loadIncrementScript;
|
|
17
20
|
_rateLimitRedis.default.prototype.loadIncrementScript = noLoadIncrementScript;
|
|
18
21
|
}
|
|
19
22
|
|
|
20
|
-
if (
|
|
23
|
+
if (_rateLimitRedis.default.prototype.loadGetScript.name === 'loadGetScript') {
|
|
24
|
+
// get super method
|
|
25
|
+
superLoadGetScript = _rateLimitRedis.default.prototype.loadGetScript;
|
|
21
26
|
_rateLimitRedis.default.prototype.loadGetScript = noLoadGetScript;
|
|
22
27
|
}
|
|
23
28
|
|
|
@@ -84,12 +89,12 @@ class RedisClientStore extends _rateLimitRedis.default {
|
|
|
84
89
|
_common.TraceUtils.debug('RedisClientStore: Opening redis store client for sending commands');
|
|
85
90
|
return self.client.connect().then(() => {
|
|
86
91
|
// send load script commands once
|
|
87
|
-
return
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
92
|
+
return (() => {
|
|
93
|
+
if (self.incrementScriptSha == null) {
|
|
94
|
+
return this.postInit();
|
|
95
|
+
}
|
|
96
|
+
return Promise.resolve();
|
|
97
|
+
})().then(() => {
|
|
93
98
|
// send command
|
|
94
99
|
args[1] = self.incrementScriptSha;
|
|
95
100
|
return self.client.sendCommand(args).catch((error) => {
|
|
@@ -103,7 +108,21 @@ class RedisClientStore extends _rateLimitRedis.default {
|
|
|
103
108
|
}
|
|
104
109
|
}); /**
|
|
105
110
|
* @type {import('redis').RedisClientType}
|
|
106
|
-
*/_defineProperty(this, "client", void 0);this.init(options);
|
|
111
|
+
*/_defineProperty(this, "client", void 0);this.init(options);_common.TraceUtils.debug('RedisClientStore: Starting up and loading increment and get scripts.');
|
|
112
|
+
void this.postInit().then(() => {
|
|
113
|
+
_common.TraceUtils.debug('RedisClientStore: Successfully loaded increment and get scripts.');
|
|
114
|
+
}).catch((err) => {
|
|
115
|
+
_common.TraceUtils.error('RedisClientStore: Failed to load increment and get scripts.');
|
|
116
|
+
_common.TraceUtils.error(err);
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
async postInit() {
|
|
120
|
+
const [incrementScriptSha, getScriptSha] = await Promise.sequence([
|
|
121
|
+
() => superLoadIncrementScript.call(this),
|
|
122
|
+
() => superLoadGetScript.call(this)]);
|
|
123
|
+
|
|
124
|
+
this.incrementScriptSha = incrementScriptSha;
|
|
125
|
+
this.getScriptSha = getScriptSha;
|
|
107
126
|
}
|
|
108
127
|
|
|
109
128
|
}exports.RedisClientStore = RedisClientStore;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RedisClientStore.js","names":["_common","require","_rateLimitRedis","_interopRequireDefault","_redis","obj","__esModule","default","_defineProperty","key","value","_toPropertyKey","Object","defineProperty","enumerable","configurable","writable","arg","_toPrimitive","String","input","hint","prim","Symbol","toPrimitive","undefined","res","call","TypeError","Number","superLoadIncrementScript","RedisStore","prototype","loadIncrementScript","superLoadGetScript","loadGetScript","noLoadGetScript","noLoadIncrementScript","RedisClientStore","constructor","service","options","sendCommand","args","Array","from","arguments","self","TraceUtils","debug","connectOptions","getApplication","getConfiguration","getSourceAt","host","port","client","createClient","connect","then","catch","error","message","warn","JSON","stringify","Promise","reject","finally","isOpen","disconnect","errDisconnect","all","results","incrementScriptSha","getScriptSha","init","exports"],"sources":["../src/RedisClientStore.js"],"sourcesContent":["import { TraceUtils } from '@themost/common';\nimport RedisStore from 'rate-limit-redis';\nimport { createClient } from 'redis';\n\nconst superLoadIncrementScript = RedisStore.prototype.loadIncrementScript;\nconst superLoadGetScript = RedisStore.prototype.loadGetScript;\n\nfunction noLoadGetScript() {\n //\n}\n\nfunction noLoadIncrementScript() {\n //\n}\n\nif (superLoadIncrementScript != noLoadIncrementScript) {\n RedisStore.prototype.loadIncrementScript = noLoadIncrementScript;\n}\n\nif (superLoadGetScript != noLoadGetScript) {\n RedisStore.prototype.loadGetScript = noLoadGetScript;\n}\n\nclass RedisClientStore extends RedisStore {\n\n /**\n * @type {import('redis').RedisClientType}\n */\n client;\n\n /**\n * \n * @param {import('@themost/common').ApplicationService} service\n * @param {{windowMs: number}} options\n */\n constructor(service, options) {\n super({\n /**\n * @param {...string} args\n * @returns {Promise<*>}\n */\n sendCommand: function () {\n const args = Array.from(arguments);\n const self = this;\n if (args[0] === 'SCRIPT') {\n TraceUtils.debug('RedisClientStore: Creating new client for sending script command');\n const connectOptions = service.getApplication().getConfiguration().getSourceAt('settings/redis/options') || {\n host: '127.0.0.1',\n port: 6379\n };\n const client = createClient(connectOptions);\n return client.connect().then(() => {\n return client.sendCommand(args);\n }).catch((error) => {\n if (error instanceof TypeError && error.message === 'Invalid argument type') {\n TraceUtils.warn('RedisClientStore: Invalid argument type: ' + JSON.stringify(args));\n }\n return Promise.reject(error);\n }).finally(() => {\n if (client.isOpen) {\n TraceUtils.debug('RedisClientStore: Closing client of sending script command');\n client.disconnect().catch((errDisconnect) => {\n TraceUtils.error(errDisconnect);\n });\n }\n });\n }\n if (self.client == null) {\n TraceUtils.debug('RedisClientStore: Creating store client for sending commands');\n const connectOptions = service.getApplication().getConfiguration().getSourceAt('settings/redis/options') || {\n host: '127.0.0.1',\n port: 6379\n };\n self.client = createClient(connectOptions);\n }\n if (self.client.isOpen) {\n return self.client.sendCommand(args).catch((error) => {\n if (error instanceof TypeError && error.message === 'Invalid argument type') {\n TraceUtils.warn('RedisClientStore: Invalid argument type: ' + JSON.stringify(args));\n }\n return Promise.reject(error);\n });\n }\n TraceUtils.debug('RedisClientStore: Opening redis store client for sending commands');\n return self.client.connect().then(() => {\n // send load script commands once\n return Promise.all([\n superLoadIncrementScript.call(self),\n superLoadGetScript.call(self)\n ]).then((results) => {\n self.incrementScriptSha = results[0];\n self.getScriptSha = results[1];\n // send command \n args[1] = self.incrementScriptSha;\n return self.client.sendCommand(args).catch((error) => {\n if (error instanceof TypeError && error.message === 'Invalid argument type') {\n TraceUtils.warn('RedisClientStore: Invalid argument type: ' + JSON.stringify(args));\n }\n return Promise.reject(error);\n });\n });\n });\n }\n });\n this.init(options)\n \n }\n\n}\n\nexport {\n RedisClientStore\n}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CAACc,OAAO,KAAK;YACjB1B,IAAI,CAAC2B,kBAAkB,GAAGD,OAAO,CAAC,CAAC,CAAC;YACpC1B,IAAI,CAAC4B,YAAY,GAAGF,OAAO,CAAC,CAAC,CAAC;YAC9B;YACA9B,IAAI,CAAC,CAAC,CAAC,GAAGI,IAAI,CAAC2B,kBAAkB;YACjC,OAAO3B,IAAI,CAACS,MAAM,CAACd,WAAW,CAACC,IAAI,CAAC,CAACiB,KAAK,CAAC,CAACC,KAAK,KAAK;cAClD,IAAIA,KAAK,YAAYjC,SAAS,IAAIiC,KAAK,CAACC,OAAO,KAAK,uBAAuB,EAAE;gBACzEd,kBAAU,CAACe,IAAI,CAAC,2CAA2C,GAAGC,IAAI,CAACC,SAAS,CAACtB,IAAI,CAAC,CAAC;cACvF;cACA,OAAOuB,OAAO,CAACC,MAAM,CAACN,KAAK,CAAC;YAChC,CAAC,CAAC;UACN,CAAC,CAAC;QACN,CAAC,CAAC;MACN;IACJ,CAAC,CAAC,CAAC,CA9EP;AACJ;AACA,OAFIrD,eAAA,yBA+EI,IAAI,CAACoE,IAAI,CAACnC,OAAO,CAAC;EAEtB;;AAEJ,CAACoC,OAAA,CAAAvC,gBAAA,GAAAA,gBAAA"}
|
|
1
|
+
{"version":3,"file":"RedisClientStore.js","names":["_common","require","_rateLimitRedis","_interopRequireDefault","_redis","obj","__esModule","default","_defineProperty","key","value","_toPropertyKey","Object","defineProperty","enumerable","configurable","writable","arg","_toPrimitive","String","input","hint","prim","Symbol","toPrimitive","undefined","res","call","TypeError","Number","superLoadIncrementScript","superLoadGetScript","noLoadGetScript","noLoadIncrementScript","RedisStore","prototype","loadIncrementScript","name","loadGetScript","RedisClientStore","constructor","service","options","sendCommand","args","Array","from","arguments","self","TraceUtils","debug","connectOptions","getApplication","getConfiguration","getSourceAt","host","port","client","createClient","connect","then","catch","error","message","warn","JSON","stringify","Promise","reject","finally","isOpen","disconnect","errDisconnect","incrementScriptSha","postInit","resolve","init","err","getScriptSha","sequence","exports"],"sources":["../src/RedisClientStore.js"],"sourcesContent":["import { TraceUtils } from '@themost/common';\nimport RedisStore from 'rate-limit-redis';\nimport { createClient } from 'redis';\nimport '@themost/promise-sequence';\n\nlet superLoadIncrementScript;\nlet superLoadGetScript;\n\nfunction noLoadGetScript() {\n //\n}\n\nfunction noLoadIncrementScript() {\n //\n}\n\nif (RedisStore.prototype.loadIncrementScript.name === 'loadIncrementScript') {\n // get super method for future use\n superLoadIncrementScript = RedisStore.prototype.loadIncrementScript;\n RedisStore.prototype.loadIncrementScript = noLoadIncrementScript;\n}\n\nif (RedisStore.prototype.loadGetScript.name === 'loadGetScript') {\n // get super method\n superLoadGetScript = RedisStore.prototype.loadGetScript;\n RedisStore.prototype.loadGetScript = noLoadGetScript;\n}\n\nclass RedisClientStore extends RedisStore {\n\n /**\n * @type {import('redis').RedisClientType}\n */\n client;\n\n /**\n * \n * @param {import('@themost/common').ApplicationService} service\n * @param {{windowMs: number}} options\n */\n constructor(service, options) {\n super({\n /**\n * @param {...string} args\n * @returns {Promise<*>}\n */\n sendCommand: function () {\n const args = Array.from(arguments);\n const self = this;\n if (args[0] === 'SCRIPT') {\n TraceUtils.debug('RedisClientStore: Creating new client for sending script command');\n const connectOptions = service.getApplication().getConfiguration().getSourceAt('settings/redis/options') || {\n host: '127.0.0.1',\n port: 6379\n };\n const client = createClient(connectOptions);\n return client.connect().then(() => {\n return client.sendCommand(args);\n }).catch((error) => {\n if (error instanceof TypeError && error.message === 'Invalid argument type') {\n TraceUtils.warn('RedisClientStore: Invalid argument type: ' + JSON.stringify(args));\n }\n return Promise.reject(error);\n }).finally(() => {\n if (client.isOpen) {\n TraceUtils.debug('RedisClientStore: Closing client of sending script command');\n client.disconnect().catch((errDisconnect) => {\n TraceUtils.error(errDisconnect);\n });\n }\n });\n }\n if (self.client == null) {\n TraceUtils.debug('RedisClientStore: Creating store client for sending commands');\n const connectOptions = service.getApplication().getConfiguration().getSourceAt('settings/redis/options') || {\n host: '127.0.0.1',\n port: 6379\n };\n self.client = createClient(connectOptions);\n }\n if (self.client.isOpen) {\n return self.client.sendCommand(args).catch((error) => {\n if (error instanceof TypeError && error.message === 'Invalid argument type') {\n TraceUtils.warn('RedisClientStore: Invalid argument type: ' + JSON.stringify(args));\n }\n return Promise.reject(error);\n });\n }\n TraceUtils.debug('RedisClientStore: Opening redis store client for sending commands');\n return self.client.connect().then(() => {\n // send load script commands once\n return (() => {\n if (self.incrementScriptSha == null) {\n return this.postInit();\n }\n return Promise.resolve();\n })().then(() => {\n // send command \n args[1] = self.incrementScriptSha;\n return self.client.sendCommand(args).catch((error) => {\n if (error instanceof TypeError && error.message === 'Invalid argument type') {\n TraceUtils.warn('RedisClientStore: Invalid argument type: ' + JSON.stringify(args));\n }\n return Promise.reject(error);\n });\n });\n });\n }\n });\n this.init(options);\n TraceUtils.debug('RedisClientStore: Starting up and loading increment and get scripts.');\n void this.postInit().then(() => {\n TraceUtils.debug('RedisClientStore: Successfully loaded increment and get scripts.');\n }).catch((err) => {\n TraceUtils.error('RedisClientStore: Failed to load increment and get scripts.');\n TraceUtils.error(err);\n });\n }\n async postInit() {\n const [incrementScriptSha, getScriptSha] = await Promise.sequence([\n () => superLoadIncrementScript.call(this),\n () => superLoadGetScript.call(this)\n ]);\n this.incrementScriptSha = incrementScriptSha;\n this.getScriptSha = getScriptSha;\n }\n\n}\n\nexport {\n RedisClientStore\n}"],"mappings":"6GAAA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,eAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AACAA,OAAA,8BAAmC,SAAAE,uBAAAE,GAAA,UAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA,aAAAG,gBAAAH,GAAA,EAAAI,GAAA,EAAAC,KAAA,GAAAD,GAAA,GAAAE,cAAA,CAAAF,GAAA,MAAAA,GAAA,IAAAJ,GAAA,GAAAO,MAAA,C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AIkC,KAAK,CAACC,OAAO,KAAK,uBAAuB,EAAE;gBACzEd,kBAAU,CAACe,IAAI,CAAC,2CAA2C,GAAGC,IAAI,CAACC,SAAS,CAACtB,IAAI,CAAC,CAAC;cACvF;cACA,OAAOuB,OAAO,CAACC,MAAM,CAACN,KAAK,CAAC;YAChC,CAAC,CAAC;UACN,CAAC,CAAC;QACN,CAAC,CAAC;MACN;IACJ,CAAC,CAAC,CAAC,CA9EP;AACJ;AACA,OAFItD,eAAA,yBA+EI,IAAI,CAACoE,IAAI,CAAClC,OAAO,CAAC,CAClBO,kBAAU,CAACC,KAAK,CAAC,sEAAsE,CAAC;IACxF,KAAK,IAAI,CAACwB,QAAQ,EAAE,CAACd,IAAI,CAAC,MAAM;MAC5BX,kBAAU,CAACC,KAAK,CAAC,kEAAkE,CAAC;IACxF,CAAC,CAAC,CAACW,KAAK,CAAC,CAACgB,GAAG,KAAK;MACd5B,kBAAU,CAACa,KAAK,CAAC,6DAA6D,CAAC;MAC/Eb,kBAAU,CAACa,KAAK,CAACe,GAAG,CAAC;IACzB,CAAC,CAAC;EACN;EACA,MAAMH,QAAQA,CAAA,EAAG;IACb,MAAM,CAACD,kBAAkB,EAAEK,YAAY,CAAC,GAAG,MAAMX,OAAO,CAACY,QAAQ,CAAC;IAC9D,MAAMjD,wBAAwB,CAACH,IAAI,CAAC,IAAI,CAAC;IACzC,MAAMI,kBAAkB,CAACJ,IAAI,CAAC,IAAI,CAAC,CACtC,CAAC;;IACF,IAAI,CAAC8C,kBAAkB,GAAGA,kBAAkB;IAC5C,IAAI,CAACK,YAAY,GAAGA,YAAY;EACpC;;AAEJ,CAACE,OAAA,CAAAzC,gBAAA,GAAAA,gBAAA"}
|
package/package.json
CHANGED
package/src/RedisClientStore.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { TraceUtils } from '@themost/common';
|
|
2
2
|
import RedisStore from 'rate-limit-redis';
|
|
3
3
|
import { createClient } from 'redis';
|
|
4
|
+
import '@themost/promise-sequence';
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
let superLoadIncrementScript;
|
|
7
|
+
let superLoadGetScript;
|
|
7
8
|
|
|
8
9
|
function noLoadGetScript() {
|
|
9
10
|
//
|
|
@@ -13,11 +14,15 @@ function noLoadIncrementScript() {
|
|
|
13
14
|
//
|
|
14
15
|
}
|
|
15
16
|
|
|
16
|
-
if (
|
|
17
|
+
if (RedisStore.prototype.loadIncrementScript.name === 'loadIncrementScript') {
|
|
18
|
+
// get super method for future use
|
|
19
|
+
superLoadIncrementScript = RedisStore.prototype.loadIncrementScript;
|
|
17
20
|
RedisStore.prototype.loadIncrementScript = noLoadIncrementScript;
|
|
18
21
|
}
|
|
19
22
|
|
|
20
|
-
if (
|
|
23
|
+
if (RedisStore.prototype.loadGetScript.name === 'loadGetScript') {
|
|
24
|
+
// get super method
|
|
25
|
+
superLoadGetScript = RedisStore.prototype.loadGetScript;
|
|
21
26
|
RedisStore.prototype.loadGetScript = noLoadGetScript;
|
|
22
27
|
}
|
|
23
28
|
|
|
@@ -84,12 +89,12 @@ class RedisClientStore extends RedisStore {
|
|
|
84
89
|
TraceUtils.debug('RedisClientStore: Opening redis store client for sending commands');
|
|
85
90
|
return self.client.connect().then(() => {
|
|
86
91
|
// send load script commands once
|
|
87
|
-
return
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
92
|
+
return (() => {
|
|
93
|
+
if (self.incrementScriptSha == null) {
|
|
94
|
+
return this.postInit();
|
|
95
|
+
}
|
|
96
|
+
return Promise.resolve();
|
|
97
|
+
})().then(() => {
|
|
93
98
|
// send command
|
|
94
99
|
args[1] = self.incrementScriptSha;
|
|
95
100
|
return self.client.sendCommand(args).catch((error) => {
|
|
@@ -102,8 +107,22 @@ class RedisClientStore extends RedisStore {
|
|
|
102
107
|
});
|
|
103
108
|
}
|
|
104
109
|
});
|
|
105
|
-
this.init(options)
|
|
106
|
-
|
|
110
|
+
this.init(options);
|
|
111
|
+
TraceUtils.debug('RedisClientStore: Starting up and loading increment and get scripts.');
|
|
112
|
+
void this.postInit().then(() => {
|
|
113
|
+
TraceUtils.debug('RedisClientStore: Successfully loaded increment and get scripts.');
|
|
114
|
+
}).catch((err) => {
|
|
115
|
+
TraceUtils.error('RedisClientStore: Failed to load increment and get scripts.');
|
|
116
|
+
TraceUtils.error(err);
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
async postInit() {
|
|
120
|
+
const [incrementScriptSha, getScriptSha] = await Promise.sequence([
|
|
121
|
+
() => superLoadIncrementScript.call(this),
|
|
122
|
+
() => superLoadGetScript.call(this)
|
|
123
|
+
]);
|
|
124
|
+
this.incrementScriptSha = incrementScriptSha;
|
|
125
|
+
this.getScriptSha = getScriptSha;
|
|
107
126
|
}
|
|
108
127
|
|
|
109
128
|
}
|